diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000000000000000000000000000000000000..9ac24be468540b38ab56843eff12f90e64ff5f56
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,14 @@
+root = true
+
+[*]
+charset = utf-8
+indent_size = 4
+indent_style = space
+insert_final_newline = true
+trim_trailing_whitespace = true
+
+[Makefile]
+indent_style = tab
+
+[*.{yml,yaml}]
+indent_size = 2
diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml
index 4785273b78b582fb166ad6280009db971e374a5a..b26006f2ffa35b9a318a7876680defc5beb9e803 100644
--- a/.github/workflows/build.yaml
+++ b/.github/workflows/build.yaml
@@ -179,7 +179,7 @@ jobs:
 
           # determine the viewer channel from the branch name
           branch=$AUTOBUILD_VCS_BRANCH
-          IFS='/' read -ra ba <<< $branch
+          IFS='/' read -ra ba <<< "$branch"
           prefix=${ba[0]}
           if [ "$prefix" == "project" ]; then
               IFS='_' read -ra prj <<< "${ba[1]}"
diff --git a/doc/contributions.txt b/doc/contributions.txt
index 8df75438604fcfadee7b82d2621a2d5e152a6c4d..024ca90d2fb830d85d69ee717c7b40355f42cf8b 100755
--- a/doc/contributions.txt
+++ b/doc/contributions.txt
@@ -246,7 +246,7 @@ Ansariel Hiller
 	SL-4126
 	SL-20224
 	SL-20524
-	https://github.com/secondlife/viewer/issues/1051
+	secondlife/viewer#1051
 Aralara Rajal
 Arare Chantilly
 	CHUIBUG-191
diff --git a/doc/testplans/pbr_terrain_appearance.md b/doc/testplans/pbr_terrain_appearance.md
index 4f0ee5c943cec584399f0afd2c5bc75edf5f33ff..f6d54029b5748d4479e7484534551915801d35e2 100644
--- a/doc/testplans/pbr_terrain_appearance.md
+++ b/doc/testplans/pbr_terrain_appearance.md
@@ -2,6 +2,8 @@
 
 ## Tiling
 
+The southwest corner of a region with PBR materials should exactly match up with the bottom left corner of the material texture(s).
+
 If two adjacent regions have the same PBR terrain settings, then:
 
 - There should not be seams between the two regions at their shared border
diff --git a/indra/llcommon/indra_constants.cpp b/indra/llcommon/indra_constants.cpp
index 39e232e480a18260813c8686f696f821aa27758d..329dfcbe37a1d09f4d01877cd5f53f92732c0386 100644
--- a/indra/llcommon/indra_constants.cpp
+++ b/indra/llcommon/indra_constants.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file indra_constants.cpp
  * @brief some useful short term constants for Indra
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -38,39 +38,39 @@ const LLUUID GOVERNOR_LINDEN_ID("3d6181b0-6a4b-97ef-18d8-722652995cf1");
 // Maintenance's group id.
 const LLUUID MAINTENANCE_GROUP_ID("dc7b21cd-3c89-fcaa-31c8-25f9ffd224cd");
 // Grass Images
-const LLUUID IMG_SMOKE			("b4ba225c-373f-446d-9f7e-6cb7b5cf9b3d");  // VIEWER
+const LLUUID IMG_SMOKE          ("b4ba225c-373f-446d-9f7e-6cb7b5cf9b3d");  // VIEWER
 
-const LLUUID IMG_DEFAULT		("d2114404-dd59-4a4d-8e6c-49359e91bbf0");  // VIEWER
+const LLUUID IMG_DEFAULT        ("d2114404-dd59-4a4d-8e6c-49359e91bbf0");  // VIEWER
 
-const LLUUID IMG_SUN			("cce0f112-878f-4586-a2e2-a8f104bba271"); // dataserver
-const LLUUID IMG_MOON			("d07f6eed-b96a-47cd-b51d-400ad4a1c428"); // dataserver
-const LLUUID IMG_SHOT			("35f217a3-f618-49cf-bbca-c86d486551a9"); // dataserver
-const LLUUID IMG_SPARK			("d2e75ac1-d0fb-4532-820e-a20034ac814d"); // dataserver
-const LLUUID IMG_FIRE			("aca40aa8-44cf-44ca-a0fa-93e1a2986f82"); // dataserver
+const LLUUID IMG_SUN            ("cce0f112-878f-4586-a2e2-a8f104bba271"); // dataserver
+const LLUUID IMG_MOON           ("d07f6eed-b96a-47cd-b51d-400ad4a1c428"); // dataserver
+const LLUUID IMG_SHOT           ("35f217a3-f618-49cf-bbca-c86d486551a9"); // dataserver
+const LLUUID IMG_SPARK          ("d2e75ac1-d0fb-4532-820e-a20034ac814d"); // dataserver
+const LLUUID IMG_FIRE           ("aca40aa8-44cf-44ca-a0fa-93e1a2986f82"); // dataserver
 const LLUUID IMG_FACE_SELECT    ("a85ac674-cb75-4af6-9499-df7c5aaf7a28"); // face selector
 const LLUUID IMG_DEFAULT_AVATAR ("c228d1cf-4b5d-4ba8-84f4-899a0796aa97"); // dataserver
-const LLUUID IMG_INVISIBLE		("3a367d1c-bef1-6d43-7595-e88c1e3aadb3"); // dataserver
+const LLUUID IMG_INVISIBLE      ("3a367d1c-bef1-6d43-7595-e88c1e3aadb3"); // dataserver
 const LLUUID IMG_WHITE          ("5748decc-f629-461c-9a36-a35a221fe21f"); // dataserver
 
-const LLUUID IMG_EXPLOSION				("68edcf47-ccd7-45b8-9f90-1649d7f12806"); // On dataserver
-const LLUUID IMG_EXPLOSION_2			("21ce046c-83fe-430a-b629-c7660ac78d7c"); // On dataserver
-const LLUUID IMG_EXPLOSION_3			("fedea30a-1be8-47a6-bc06-337a04a39c4b"); // On dataserver
-const LLUUID IMG_EXPLOSION_4			("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); // On dataserver
-const LLUUID IMG_SMOKE_POOF				("1e63e323-5fe0-452e-92f8-b98bd0f764e3"); // On dataserver
+const LLUUID IMG_EXPLOSION              ("68edcf47-ccd7-45b8-9f90-1649d7f12806"); // On dataserver
+const LLUUID IMG_EXPLOSION_2            ("21ce046c-83fe-430a-b629-c7660ac78d7c"); // On dataserver
+const LLUUID IMG_EXPLOSION_3            ("fedea30a-1be8-47a6-bc06-337a04a39c4b"); // On dataserver
+const LLUUID IMG_EXPLOSION_4            ("abf0d56b-82e5-47a2-a8ad-74741bb2c29e"); // On dataserver
+const LLUUID IMG_SMOKE_POOF             ("1e63e323-5fe0-452e-92f8-b98bd0f764e3"); // On dataserver
 
-const LLUUID IMG_BIG_EXPLOSION_1		("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); // On dataserver
-const LLUUID IMG_BIG_EXPLOSION_2		("9c8eca51-53d5-42a7-bb58-cef070395db8"); // On dataserver
+const LLUUID IMG_BIG_EXPLOSION_1        ("5e47a0dc-97bf-44e0-8b40-de06718cee9d"); // On dataserver
+const LLUUID IMG_BIG_EXPLOSION_2        ("9c8eca51-53d5-42a7-bb58-cef070395db8"); // On dataserver
 
-const LLUUID IMG_ALPHA_GRAD				("e97cf410-8e61-7005-ec06-629eba4cd1fb"); // VIEWER
-const LLUUID IMG_ALPHA_GRAD_2D			("38b86f85-2575-52a9-a531-23108d8da837"); // VIEWER
-const LLUUID IMG_TRANSPARENT			("8dcd4a48-2d37-4909-9f78-f7a9eb4ef903"); // VIEWER
+const LLUUID IMG_ALPHA_GRAD             ("e97cf410-8e61-7005-ec06-629eba4cd1fb"); // VIEWER
+const LLUUID IMG_ALPHA_GRAD_2D          ("38b86f85-2575-52a9-a531-23108d8da837"); // VIEWER
+const LLUUID IMG_TRANSPARENT            ("8dcd4a48-2d37-4909-9f78-f7a9eb4ef903"); // VIEWER
 
-const LLUUID TERRAIN_DIRT_DETAIL		("0bc58228-74a0-7e83-89bc-5c23464bcec5"); // VIEWER
-const LLUUID TERRAIN_GRASS_DETAIL		("63338ede-0037-c4fd-855b-015d77112fc8"); // VIEWER
-const LLUUID TERRAIN_MOUNTAIN_DETAIL	("303cd381-8560-7579-23f1-f0a880799740"); // VIEWER
-const LLUUID TERRAIN_ROCK_DETAIL		("53a2f406-4895-1d13-d541-d2e3b86bc19c"); // VIEWER
+const LLUUID TERRAIN_DIRT_DETAIL        ("0bc58228-74a0-7e83-89bc-5c23464bcec5"); // VIEWER
+const LLUUID TERRAIN_GRASS_DETAIL       ("63338ede-0037-c4fd-855b-015d77112fc8"); // VIEWER
+const LLUUID TERRAIN_MOUNTAIN_DETAIL    ("303cd381-8560-7579-23f1-f0a880799740"); // VIEWER
+const LLUUID TERRAIN_ROCK_DETAIL        ("53a2f406-4895-1d13-d541-d2e3b86bc19c"); // VIEWER
 
-const LLUUID DEFAULT_WATER_NORMAL		("822ded49-9a6c-f61c-cb89-6df54f42cdf4"); // VIEWER
+const LLUUID DEFAULT_WATER_NORMAL       ("822ded49-9a6c-f61c-cb89-6df54f42cdf4"); // VIEWER
 
 const LLUUID DEFAULT_OBJECT_TEXTURE     ("89556747-24cb-43ed-920b-47caed15465f"); // On dataserver
 const LLUUID DEFAULT_OBJECT_SPECULAR    ("87e0e8f7-8729-1ea8-cfc9-8915773009db"); // On dataserver
diff --git a/indra/llcommon/indra_constants.h b/indra/llcommon/indra_constants.h
index 49f6a6da630e23b1039b56cfd4e5a626516d8c8e..fbc6562fe26e7678d0c68e52c23f5069dcc112a5 100644
--- a/indra/llcommon/indra_constants.h
+++ b/indra/llcommon/indra_constants.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file indra_constants.h
  * @brief some useful short term constants for Indra
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -37,21 +37,21 @@ static const U32 REGION_WIDTH_U32 = 256;
 
 const F32 REGION_HEIGHT_METERS = 4096.f;
 
-const 	F32 	DEFAULT_AGENT_DEPTH 	= 0.45f;
-const 	F32 	DEFAULT_AGENT_WIDTH 	= 0.60f;
-const 	F32 	DEFAULT_AGENT_HEIGHT	= 1.9f;
+const   F32     DEFAULT_AGENT_DEPTH     = 0.45f;
+const   F32     DEFAULT_AGENT_WIDTH     = 0.60f;
+const   F32     DEFAULT_AGENT_HEIGHT    = 1.9f;
 
 enum ETerrainBrushType
 {
-	// the valid brush numbers cannot be reordered, because they 
-	// are used in the binary LSL format as arguments to llModifyLand()
-	E_LANDBRUSH_LEVEL	= 0,
-	E_LANDBRUSH_RAISE	= 1,
-	E_LANDBRUSH_LOWER	= 2,
-	E_LANDBRUSH_SMOOTH 	= 3,
-	E_LANDBRUSH_NOISE	= 4,
-	E_LANDBRUSH_REVERT 	= 5,
-	E_LANDBRUSH_INVALID = 6
+    // the valid brush numbers cannot be reordered, because they
+    // are used in the binary LSL format as arguments to llModifyLand()
+    E_LANDBRUSH_LEVEL   = 0,
+    E_LANDBRUSH_RAISE   = 1,
+    E_LANDBRUSH_LOWER   = 2,
+    E_LANDBRUSH_SMOOTH  = 3,
+    E_LANDBRUSH_NOISE   = 4,
+    E_LANDBRUSH_REVERT  = 5,
+    E_LANDBRUSH_INVALID = 6
 };
 
 enum EMouseClickType{
@@ -67,101 +67,101 @@ enum EMouseClickType{
 
 // keys
 // Bit masks for various keyboard modifier keys.
-const MASK MASK_NONE =			0x0000;
-const MASK MASK_CONTROL =		0x0001;		// Mapped to cmd on Macs
-const MASK MASK_ALT =			0x0002;
-const MASK MASK_SHIFT =			0x0004;
+const MASK MASK_NONE =          0x0000;
+const MASK MASK_CONTROL =       0x0001;     // Mapped to cmd on Macs
+const MASK MASK_ALT =           0x0002;
+const MASK MASK_SHIFT =         0x0004;
 const MASK MASK_NORMALKEYS =    0x0007;     // A real mask - only get the bits for normal modifier keys
-const MASK MASK_MAC_CONTROL =	0x0008;		// Un-mapped Ctrl key on Macs, not used on Windows
-const MASK MASK_MODIFIERS =		MASK_CONTROL|MASK_ALT|MASK_SHIFT|MASK_MAC_CONTROL;
+const MASK MASK_MAC_CONTROL =   0x0008;     // Un-mapped Ctrl key on Macs, not used on Windows
+const MASK MASK_MODIFIERS =     MASK_CONTROL|MASK_ALT|MASK_SHIFT|MASK_MAC_CONTROL;
 
 // Special keys go into >128
-const KEY KEY_SPECIAL = 0x80;	// special keys start here
-const KEY KEY_RETURN =	0x81;
-const KEY KEY_LEFT =	0x82;
-const KEY KEY_RIGHT =	0x83;
-const KEY KEY_UP =		0x84;
-const KEY KEY_DOWN =	0x85;
-const KEY KEY_ESCAPE =	0x86;
+const KEY KEY_SPECIAL = 0x80;   // special keys start here
+const KEY KEY_RETURN =  0x81;
+const KEY KEY_LEFT =    0x82;
+const KEY KEY_RIGHT =   0x83;
+const KEY KEY_UP =      0x84;
+const KEY KEY_DOWN =    0x85;
+const KEY KEY_ESCAPE =  0x86;
 const KEY KEY_BACKSPACE =0x87;
-const KEY KEY_DELETE =	0x88;
-const KEY KEY_SHIFT =	0x89;
-const KEY KEY_CONTROL =	0x8A;
-const KEY KEY_ALT =		0x8B;
-const KEY KEY_HOME =	0x8C;
-const KEY KEY_END =		0x8D;
+const KEY KEY_DELETE =  0x88;
+const KEY KEY_SHIFT =   0x89;
+const KEY KEY_CONTROL = 0x8A;
+const KEY KEY_ALT =     0x8B;
+const KEY KEY_HOME =    0x8C;
+const KEY KEY_END =     0x8D;
 const KEY KEY_PAGE_UP = 0x8E;
 const KEY KEY_PAGE_DOWN = 0x8F;
 const KEY KEY_HYPHEN = 0x90;
 const KEY KEY_EQUALS = 0x91;
 const KEY KEY_INSERT = 0x92;
 const KEY KEY_CAPSLOCK = 0x93;
-const KEY KEY_TAB =		0x94;
-const KEY KEY_ADD = 	0x95;
+const KEY KEY_TAB =     0x94;
+const KEY KEY_ADD =     0x95;
 const KEY KEY_SUBTRACT =0x96;
 const KEY KEY_MULTIPLY =0x97;
-const KEY KEY_DIVIDE =	0x98;
-const KEY KEY_F1		= 0xA1;
-const KEY KEY_F2		= 0xA2;
-const KEY KEY_F3		= 0xA3;
-const KEY KEY_F4		= 0xA4;
-const KEY KEY_F5		= 0xA5;
-const KEY KEY_F6		= 0xA6;
-const KEY KEY_F7		= 0xA7;
-const KEY KEY_F8		= 0xA8;
-const KEY KEY_F9		= 0xA9;
-const KEY KEY_F10		= 0xAA;
-const KEY KEY_F11		= 0xAB;
-const KEY KEY_F12		= 0xAC;
-
-const KEY KEY_PAD_UP		= 0xC0;
-const KEY KEY_PAD_DOWN		= 0xC1;
-const KEY KEY_PAD_LEFT		= 0xC2;
-const KEY KEY_PAD_RIGHT		= 0xC3;
-const KEY KEY_PAD_HOME		= 0xC4;
-const KEY KEY_PAD_END		= 0xC5;
-const KEY KEY_PAD_PGUP		= 0xC6;
-const KEY KEY_PAD_PGDN		= 0xC7;
-const KEY KEY_PAD_CENTER	= 0xC8; // the 5 in the middle
-const KEY KEY_PAD_INS		= 0xC9;
-const KEY KEY_PAD_DEL		= 0xCA;
-const KEY KEY_PAD_RETURN	= 0xCB;
-const KEY KEY_PAD_ADD		= 0xCC; // not used
-const KEY KEY_PAD_SUBTRACT	= 0xCD; // not used
+const KEY KEY_DIVIDE =  0x98;
+const KEY KEY_F1        = 0xA1;
+const KEY KEY_F2        = 0xA2;
+const KEY KEY_F3        = 0xA3;
+const KEY KEY_F4        = 0xA4;
+const KEY KEY_F5        = 0xA5;
+const KEY KEY_F6        = 0xA6;
+const KEY KEY_F7        = 0xA7;
+const KEY KEY_F8        = 0xA8;
+const KEY KEY_F9        = 0xA9;
+const KEY KEY_F10       = 0xAA;
+const KEY KEY_F11       = 0xAB;
+const KEY KEY_F12       = 0xAC;
+
+const KEY KEY_PAD_UP        = 0xC0;
+const KEY KEY_PAD_DOWN      = 0xC1;
+const KEY KEY_PAD_LEFT      = 0xC2;
+const KEY KEY_PAD_RIGHT     = 0xC3;
+const KEY KEY_PAD_HOME      = 0xC4;
+const KEY KEY_PAD_END       = 0xC5;
+const KEY KEY_PAD_PGUP      = 0xC6;
+const KEY KEY_PAD_PGDN      = 0xC7;
+const KEY KEY_PAD_CENTER    = 0xC8; // the 5 in the middle
+const KEY KEY_PAD_INS       = 0xC9;
+const KEY KEY_PAD_DEL       = 0xCA;
+const KEY KEY_PAD_RETURN    = 0xCB;
+const KEY KEY_PAD_ADD       = 0xCC; // not used
+const KEY KEY_PAD_SUBTRACT  = 0xCD; // not used
 const KEY KEY_PAD_MULTIPLY  = 0xCE; // not used
-const KEY KEY_PAD_DIVIDE	= 0xCF; // not used
-
-const KEY KEY_BUTTON0	= 0xD0;
-const KEY KEY_BUTTON1	= 0xD1;
-const KEY KEY_BUTTON2	= 0xD2;
-const KEY KEY_BUTTON3	= 0xD3;
-const KEY KEY_BUTTON4	= 0xD4;
-const KEY KEY_BUTTON5	= 0xD5;
-const KEY KEY_BUTTON6	= 0xD6;
-const KEY KEY_BUTTON7	= 0xD7;
-const KEY KEY_BUTTON8	= 0xD8;
-const KEY KEY_BUTTON9	= 0xD9;
-const KEY KEY_BUTTON10	= 0xDA;
-const KEY KEY_BUTTON11	= 0xDB;
-const KEY KEY_BUTTON12	= 0xDC;
-const KEY KEY_BUTTON13	= 0xDD;
-const KEY KEY_BUTTON14	= 0xDE;
-const KEY KEY_BUTTON15	= 0xDF;
-
-const KEY KEY_NONE =	0xFF; // not sent from keyboard.  For internal use only.
+const KEY KEY_PAD_DIVIDE    = 0xCF; // not used
+
+const KEY KEY_BUTTON0   = 0xD0;
+const KEY KEY_BUTTON1   = 0xD1;
+const KEY KEY_BUTTON2   = 0xD2;
+const KEY KEY_BUTTON3   = 0xD3;
+const KEY KEY_BUTTON4   = 0xD4;
+const KEY KEY_BUTTON5   = 0xD5;
+const KEY KEY_BUTTON6   = 0xD6;
+const KEY KEY_BUTTON7   = 0xD7;
+const KEY KEY_BUTTON8   = 0xD8;
+const KEY KEY_BUTTON9   = 0xD9;
+const KEY KEY_BUTTON10  = 0xDA;
+const KEY KEY_BUTTON11  = 0xDB;
+const KEY KEY_BUTTON12  = 0xDC;
+const KEY KEY_BUTTON13  = 0xDD;
+const KEY KEY_BUTTON14  = 0xDE;
+const KEY KEY_BUTTON15  = 0xDF;
+
+const KEY KEY_NONE =    0xFF; // not sent from keyboard.  For internal use only.
 
 const S32 KEY_COUNT = 256;
 
 
-const F32 DEFAULT_WATER_HEIGHT 	= 20.0f;
+const F32 DEFAULT_WATER_HEIGHT  = 20.0f;
 
 // Maturity ratings for simulators
-constexpr U8 SIM_ACCESS_MIN 	= 0;		// Treated as 'unknown', usually ends up being SIM_ACCESS_PG
-constexpr U8 SIM_ACCESS_PG		= 13;
-constexpr U8 SIM_ACCESS_MATURE	= 21;
-constexpr U8 SIM_ACCESS_ADULT	= 42;		// Seriously Adult Only
-constexpr U8 SIM_ACCESS_DOWN	= 254;
-constexpr U8 SIM_ACCESS_MAX 	= SIM_ACCESS_ADULT;
+constexpr U8 SIM_ACCESS_MIN     = 0;        // Treated as 'unknown', usually ends up being SIM_ACCESS_PG
+constexpr U8 SIM_ACCESS_PG      = 13;
+constexpr U8 SIM_ACCESS_MATURE  = 21;
+constexpr U8 SIM_ACCESS_ADULT   = 42;       // Seriously Adult Only
+constexpr U8 SIM_ACCESS_DOWN    = 254;
+constexpr U8 SIM_ACCESS_MAX     = SIM_ACCESS_ADULT;
 
 // attachment constants
 constexpr U8  ATTACHMENT_ADD = 0x80;
@@ -260,84 +260,84 @@ const U32 PARCEL_MEDIA_COMMAND_LOOP_SET = 13;
 const S32 CHAT_CHANNEL_DEBUG = S32_MAX;
 
 // agent constants
-const U32 CONTROL_AT_POS_INDEX				= 0;
-const U32 CONTROL_AT_NEG_INDEX				= 1;
-const U32 CONTROL_LEFT_POS_INDEX			= 2;
-const U32 CONTROL_LEFT_NEG_INDEX			= 3;
-const U32 CONTROL_UP_POS_INDEX				= 4;
-const U32 CONTROL_UP_NEG_INDEX				= 5;
-const U32 CONTROL_PITCH_POS_INDEX			= 6;
-const U32 CONTROL_PITCH_NEG_INDEX			= 7;
-const U32 CONTROL_YAW_POS_INDEX				= 8;
-const U32 CONTROL_YAW_NEG_INDEX				= 9;
-const U32 CONTROL_FAST_AT_INDEX				= 10;
-const U32 CONTROL_FAST_LEFT_INDEX			= 11;
-const U32 CONTROL_FAST_UP_INDEX				= 12;
-const U32 CONTROL_FLY_INDEX					= 13;
-const U32 CONTROL_STOP_INDEX				= 14;
-const U32 CONTROL_FINISH_ANIM_INDEX			= 15;
-const U32 CONTROL_STAND_UP_INDEX			= 16;
-const U32 CONTROL_SIT_ON_GROUND_INDEX		= 17;
-const U32 CONTROL_MOUSELOOK_INDEX			= 18;
-const U32 CONTROL_NUDGE_AT_POS_INDEX		= 19;
-const U32 CONTROL_NUDGE_AT_NEG_INDEX		= 20;
-const U32 CONTROL_NUDGE_LEFT_POS_INDEX		= 21;
-const U32 CONTROL_NUDGE_LEFT_NEG_INDEX		= 22;
-const U32 CONTROL_NUDGE_UP_POS_INDEX		= 23;
-const U32 CONTROL_NUDGE_UP_NEG_INDEX		= 24;
-const U32 CONTROL_TURN_LEFT_INDEX			= 25;
-const U32 CONTROL_TURN_RIGHT_INDEX			= 26;
-const U32 CONTROL_AWAY_INDEX				= 27;
-const U32 CONTROL_LBUTTON_DOWN_INDEX		= 28;
-const U32 CONTROL_LBUTTON_UP_INDEX			= 29;
-const U32 CONTROL_ML_LBUTTON_DOWN_INDEX		= 30;
-const U32 CONTROL_ML_LBUTTON_UP_INDEX		= 31;
-const U32 TOTAL_CONTROLS					= 32;
-
-const U32 AGENT_CONTROL_AT_POS              = 0x1 << CONTROL_AT_POS_INDEX;			// 0x00000001
-const U32 AGENT_CONTROL_AT_NEG              = 0x1 << CONTROL_AT_NEG_INDEX;			// 0x00000002
-const U32 AGENT_CONTROL_LEFT_POS            = 0x1 << CONTROL_LEFT_POS_INDEX;		// 0x00000004
-const U32 AGENT_CONTROL_LEFT_NEG            = 0x1 << CONTROL_LEFT_NEG_INDEX;		// 0x00000008
-const U32 AGENT_CONTROL_UP_POS              = 0x1 << CONTROL_UP_POS_INDEX;			// 0x00000010
-const U32 AGENT_CONTROL_UP_NEG              = 0x1 << CONTROL_UP_NEG_INDEX;			// 0x00000020
-const U32 AGENT_CONTROL_PITCH_POS           = 0x1 << CONTROL_PITCH_POS_INDEX;		// 0x00000040
-const U32 AGENT_CONTROL_PITCH_NEG           = 0x1 << CONTROL_PITCH_NEG_INDEX;		// 0x00000080
-const U32 AGENT_CONTROL_YAW_POS             = 0x1 << CONTROL_YAW_POS_INDEX;			// 0x00000100
-const U32 AGENT_CONTROL_YAW_NEG             = 0x1 << CONTROL_YAW_NEG_INDEX;			// 0x00000200
-
-const U32 AGENT_CONTROL_FAST_AT             = 0x1 << CONTROL_FAST_AT_INDEX;			// 0x00000400
-const U32 AGENT_CONTROL_FAST_LEFT           = 0x1 << CONTROL_FAST_LEFT_INDEX;		// 0x00000800
-const U32 AGENT_CONTROL_FAST_UP             = 0x1 << CONTROL_FAST_UP_INDEX;			// 0x00001000
-
-const U32 AGENT_CONTROL_FLY					= 0x1 << CONTROL_FLY_INDEX;				// 0x00002000
-const U32 AGENT_CONTROL_STOP				= 0x1 << CONTROL_STOP_INDEX;			// 0x00004000
-const U32 AGENT_CONTROL_FINISH_ANIM			= 0x1 << CONTROL_FINISH_ANIM_INDEX;		// 0x00008000
-const U32 AGENT_CONTROL_STAND_UP			= 0x1 << CONTROL_STAND_UP_INDEX;		// 0x00010000
-const U32 AGENT_CONTROL_SIT_ON_GROUND		= 0x1 << CONTROL_SIT_ON_GROUND_INDEX;	// 0x00020000
-const U32 AGENT_CONTROL_MOUSELOOK			= 0x1 << CONTROL_MOUSELOOK_INDEX;		// 0x00040000
-
-const U32 AGENT_CONTROL_NUDGE_AT_POS        = 0x1 << CONTROL_NUDGE_AT_POS_INDEX;	// 0x00080000
-const U32 AGENT_CONTROL_NUDGE_AT_NEG        = 0x1 << CONTROL_NUDGE_AT_NEG_INDEX;	// 0x00100000
-const U32 AGENT_CONTROL_NUDGE_LEFT_POS      = 0x1 << CONTROL_NUDGE_LEFT_POS_INDEX;	// 0x00200000
-const U32 AGENT_CONTROL_NUDGE_LEFT_NEG      = 0x1 << CONTROL_NUDGE_LEFT_NEG_INDEX;	// 0x00400000
-const U32 AGENT_CONTROL_NUDGE_UP_POS        = 0x1 << CONTROL_NUDGE_UP_POS_INDEX;	// 0x00800000
-const U32 AGENT_CONTROL_NUDGE_UP_NEG        = 0x1 << CONTROL_NUDGE_UP_NEG_INDEX;	// 0x01000000
-const U32 AGENT_CONTROL_TURN_LEFT	        = 0x1 << CONTROL_TURN_LEFT_INDEX;		// 0x02000000
-const U32 AGENT_CONTROL_TURN_RIGHT	        = 0x1 << CONTROL_TURN_RIGHT_INDEX;		// 0x04000000
-
-const U32 AGENT_CONTROL_AWAY				= 0x1 << CONTROL_AWAY_INDEX;			// 0x08000000
-
-const U32 AGENT_CONTROL_LBUTTON_DOWN		= 0x1 << CONTROL_LBUTTON_DOWN_INDEX;	// 0x10000000
-const U32 AGENT_CONTROL_LBUTTON_UP			= 0x1 << CONTROL_LBUTTON_UP_INDEX;		// 0x20000000
-const U32 AGENT_CONTROL_ML_LBUTTON_DOWN		= 0x1 << CONTROL_ML_LBUTTON_DOWN_INDEX;	// 0x40000000
-const U32 AGENT_CONTROL_ML_LBUTTON_UP		= ((U32)0x1) << CONTROL_ML_LBUTTON_UP_INDEX;	// 0x80000000
-
-// move these up so that we can hide them in "State" for object updates 
+const U32 CONTROL_AT_POS_INDEX              = 0;
+const U32 CONTROL_AT_NEG_INDEX              = 1;
+const U32 CONTROL_LEFT_POS_INDEX            = 2;
+const U32 CONTROL_LEFT_NEG_INDEX            = 3;
+const U32 CONTROL_UP_POS_INDEX              = 4;
+const U32 CONTROL_UP_NEG_INDEX              = 5;
+const U32 CONTROL_PITCH_POS_INDEX           = 6;
+const U32 CONTROL_PITCH_NEG_INDEX           = 7;
+const U32 CONTROL_YAW_POS_INDEX             = 8;
+const U32 CONTROL_YAW_NEG_INDEX             = 9;
+const U32 CONTROL_FAST_AT_INDEX             = 10;
+const U32 CONTROL_FAST_LEFT_INDEX           = 11;
+const U32 CONTROL_FAST_UP_INDEX             = 12;
+const U32 CONTROL_FLY_INDEX                 = 13;
+const U32 CONTROL_STOP_INDEX                = 14;
+const U32 CONTROL_FINISH_ANIM_INDEX         = 15;
+const U32 CONTROL_STAND_UP_INDEX            = 16;
+const U32 CONTROL_SIT_ON_GROUND_INDEX       = 17;
+const U32 CONTROL_MOUSELOOK_INDEX           = 18;
+const U32 CONTROL_NUDGE_AT_POS_INDEX        = 19;
+const U32 CONTROL_NUDGE_AT_NEG_INDEX        = 20;
+const U32 CONTROL_NUDGE_LEFT_POS_INDEX      = 21;
+const U32 CONTROL_NUDGE_LEFT_NEG_INDEX      = 22;
+const U32 CONTROL_NUDGE_UP_POS_INDEX        = 23;
+const U32 CONTROL_NUDGE_UP_NEG_INDEX        = 24;
+const U32 CONTROL_TURN_LEFT_INDEX           = 25;
+const U32 CONTROL_TURN_RIGHT_INDEX          = 26;
+const U32 CONTROL_AWAY_INDEX                = 27;
+const U32 CONTROL_LBUTTON_DOWN_INDEX        = 28;
+const U32 CONTROL_LBUTTON_UP_INDEX          = 29;
+const U32 CONTROL_ML_LBUTTON_DOWN_INDEX     = 30;
+const U32 CONTROL_ML_LBUTTON_UP_INDEX       = 31;
+const U32 TOTAL_CONTROLS                    = 32;
+
+const U32 AGENT_CONTROL_AT_POS              = 0x1 << CONTROL_AT_POS_INDEX;          // 0x00000001
+const U32 AGENT_CONTROL_AT_NEG              = 0x1 << CONTROL_AT_NEG_INDEX;          // 0x00000002
+const U32 AGENT_CONTROL_LEFT_POS            = 0x1 << CONTROL_LEFT_POS_INDEX;        // 0x00000004
+const U32 AGENT_CONTROL_LEFT_NEG            = 0x1 << CONTROL_LEFT_NEG_INDEX;        // 0x00000008
+const U32 AGENT_CONTROL_UP_POS              = 0x1 << CONTROL_UP_POS_INDEX;          // 0x00000010
+const U32 AGENT_CONTROL_UP_NEG              = 0x1 << CONTROL_UP_NEG_INDEX;          // 0x00000020
+const U32 AGENT_CONTROL_PITCH_POS           = 0x1 << CONTROL_PITCH_POS_INDEX;       // 0x00000040
+const U32 AGENT_CONTROL_PITCH_NEG           = 0x1 << CONTROL_PITCH_NEG_INDEX;       // 0x00000080
+const U32 AGENT_CONTROL_YAW_POS             = 0x1 << CONTROL_YAW_POS_INDEX;         // 0x00000100
+const U32 AGENT_CONTROL_YAW_NEG             = 0x1 << CONTROL_YAW_NEG_INDEX;         // 0x00000200
+
+const U32 AGENT_CONTROL_FAST_AT             = 0x1 << CONTROL_FAST_AT_INDEX;         // 0x00000400
+const U32 AGENT_CONTROL_FAST_LEFT           = 0x1 << CONTROL_FAST_LEFT_INDEX;       // 0x00000800
+const U32 AGENT_CONTROL_FAST_UP             = 0x1 << CONTROL_FAST_UP_INDEX;         // 0x00001000
+
+const U32 AGENT_CONTROL_FLY                 = 0x1 << CONTROL_FLY_INDEX;             // 0x00002000
+const U32 AGENT_CONTROL_STOP                = 0x1 << CONTROL_STOP_INDEX;            // 0x00004000
+const U32 AGENT_CONTROL_FINISH_ANIM         = 0x1 << CONTROL_FINISH_ANIM_INDEX;     // 0x00008000
+const U32 AGENT_CONTROL_STAND_UP            = 0x1 << CONTROL_STAND_UP_INDEX;        // 0x00010000
+const U32 AGENT_CONTROL_SIT_ON_GROUND       = 0x1 << CONTROL_SIT_ON_GROUND_INDEX;   // 0x00020000
+const U32 AGENT_CONTROL_MOUSELOOK           = 0x1 << CONTROL_MOUSELOOK_INDEX;       // 0x00040000
+
+const U32 AGENT_CONTROL_NUDGE_AT_POS        = 0x1 << CONTROL_NUDGE_AT_POS_INDEX;    // 0x00080000
+const U32 AGENT_CONTROL_NUDGE_AT_NEG        = 0x1 << CONTROL_NUDGE_AT_NEG_INDEX;    // 0x00100000
+const U32 AGENT_CONTROL_NUDGE_LEFT_POS      = 0x1 << CONTROL_NUDGE_LEFT_POS_INDEX;  // 0x00200000
+const U32 AGENT_CONTROL_NUDGE_LEFT_NEG      = 0x1 << CONTROL_NUDGE_LEFT_NEG_INDEX;  // 0x00400000
+const U32 AGENT_CONTROL_NUDGE_UP_POS        = 0x1 << CONTROL_NUDGE_UP_POS_INDEX;    // 0x00800000
+const U32 AGENT_CONTROL_NUDGE_UP_NEG        = 0x1 << CONTROL_NUDGE_UP_NEG_INDEX;    // 0x01000000
+const U32 AGENT_CONTROL_TURN_LEFT           = 0x1 << CONTROL_TURN_LEFT_INDEX;       // 0x02000000
+const U32 AGENT_CONTROL_TURN_RIGHT          = 0x1 << CONTROL_TURN_RIGHT_INDEX;      // 0x04000000
+
+const U32 AGENT_CONTROL_AWAY                = 0x1 << CONTROL_AWAY_INDEX;            // 0x08000000
+
+const U32 AGENT_CONTROL_LBUTTON_DOWN        = 0x1 << CONTROL_LBUTTON_DOWN_INDEX;    // 0x10000000
+const U32 AGENT_CONTROL_LBUTTON_UP          = 0x1 << CONTROL_LBUTTON_UP_INDEX;      // 0x20000000
+const U32 AGENT_CONTROL_ML_LBUTTON_DOWN     = 0x1 << CONTROL_ML_LBUTTON_DOWN_INDEX; // 0x40000000
+const U32 AGENT_CONTROL_ML_LBUTTON_UP       = ((U32)0x1) << CONTROL_ML_LBUTTON_UP_INDEX;    // 0x80000000
+
+// move these up so that we can hide them in "State" for object updates
 // (for now)
-const U32 AGENT_ATTACH_OFFSET				= 4;
-const U32 AGENT_ATTACH_MASK					= 0xf << AGENT_ATTACH_OFFSET;
+const U32 AGENT_ATTACH_OFFSET               = 4;
+const U32 AGENT_ATTACH_MASK                 = 0xf << AGENT_ATTACH_OFFSET;
 
-// RN: this method swaps the upper and lower nibbles to maintain backward 
+// RN: this method swaps the upper and lower nibbles to maintain backward
 // compatibility with old objects that only used the upper nibble
 #define ATTACHMENT_ID_FROM_STATE(state) ((S32)((((U8)state & AGENT_ATTACH_MASK) >> 4) | (((U8)state & ~AGENT_ATTACH_MASK) << 4)))
 
diff --git a/indra/llcommon/llrefcount.h b/indra/llcommon/llrefcount.h
index eef086d828fb67ab75e7c5dffa9eb24a644663bc..06a6821b982c2f282516e6ae6acd019b68d4008a 100644
--- a/indra/llcommon/llrefcount.h
+++ b/indra/llcommon/llrefcount.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llrefcount.h
  * @brief Base class for reference counted objects for use with LLPointer
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -44,52 +44,52 @@ extern const S32 gMaxRefCount;
 class LL_COMMON_API LLRefCount
 {
 protected:
-	LLRefCount(const LLRefCount& other);
-	LLRefCount& operator=(const LLRefCount&);
-	LLRefCount(LLRefCount&& other) noexcept
-	{
-		*this = std::move(other);
-	}
-	LLRefCount& operator=(LLRefCount&& other) noexcept
-	{
-		mRef = other.mRef;
-		return *this;
-	}
-
-	virtual ~LLRefCount(); // use unref()
-	
+    LLRefCount(const LLRefCount& other);
+    LLRefCount& operator=(const LLRefCount&);
+    LLRefCount(LLRefCount&& other) noexcept
+    {
+        *this = std::move(other);
+    }
+    LLRefCount& operator=(LLRefCount&& other) noexcept
+    {
+        mRef = other.mRef;
+        return *this;
+    }
+
+    virtual ~LLRefCount(); // use unref()
+
 public:
-	LLRefCount();
-
-	inline void ref() const
-	{
-		llassert(mRef != LL_REFCOUNT_FREE); // object is deleted
-		mRef++;
-		llassert(mRef < gMaxRefCount); // ref count excessive, likely memory leak
-	}
-
-	inline S32 unref() const
-	{
-		llassert(mRef != LL_REFCOUNT_FREE); // object is deleted
-		llassert(mRef > 0); // ref count below 1, likely corrupted
-		if (0 == --mRef)
-		{
-			mRef = LL_REFCOUNT_FREE; // set to nonsense yet recognizable value to aid in debugging
-			delete this;
-			return 0;
-		}
-		return mRef;
-	}
-
-	//NOTE: when passing around a const LLRefCount object, this can return different results
-	// at different types, since mRef is mutable
-	S32 getNumRefs() const
-	{
-		return mRef;
-	}
+    LLRefCount();
+
+    inline void ref() const
+    {
+        llassert(mRef != LL_REFCOUNT_FREE); // object is deleted
+        mRef++;
+        llassert(mRef < gMaxRefCount); // ref count excessive, likely memory leak
+    }
+
+    inline S32 unref() const
+    {
+        llassert(mRef != LL_REFCOUNT_FREE); // object is deleted
+        llassert(mRef > 0); // ref count below 1, likely corrupted
+        if (0 == --mRef)
+        {
+            mRef = LL_REFCOUNT_FREE; // set to nonsense yet recognizable value to aid in debugging
+            delete this;
+            return 0;
+        }
+        return mRef;
+    }
+
+    //NOTE: when passing around a const LLRefCount object, this can return different results
+    // at different types, since mRef is mutable
+    S32 getNumRefs() const
+    {
+        return mRef;
+    }
 
 private:
-	mutable S32	mRef;
+    mutable S32 mRef;
 };
 
 
@@ -100,43 +100,43 @@ class LL_COMMON_API LLRefCount
 class LL_COMMON_API LLThreadSafeRefCount
 {
 protected:
-	virtual ~LLThreadSafeRefCount(); // use unref()
+    virtual ~LLThreadSafeRefCount(); // use unref()
 
 public:
-	LLThreadSafeRefCount();
-	LLThreadSafeRefCount(const LLThreadSafeRefCount&);
-	LLThreadSafeRefCount& operator=(const LLThreadSafeRefCount& ref)
-	{
-		mRef = 0;
-		return *this;
-	}
-
-	void ref()
-	{
-		mRef++;
-	}
-
-	void unref()
-	{
-		llassert(mRef >= 1);
-		if ((--mRef) == 0)
-		{
-			// If we hit zero, the caller should be the only smart pointer owning the object and we can delete it.
-			// It is technically possible for a vanilla pointer to mess this up, or another thread to
-			// jump in, find this object, create another smart pointer and end up dangling, but if
-			// the code is that bad and not thread-safe, it's trouble already.
-			delete this;
-		}
-	}
-
-	S32 getNumRefs() const
-	{
-		const S32 currentVal = mRef.CurrentValue();
-		return currentVal;
-	}
+    LLThreadSafeRefCount();
+    LLThreadSafeRefCount(const LLThreadSafeRefCount&);
+    LLThreadSafeRefCount& operator=(const LLThreadSafeRefCount& ref)
+    {
+        mRef = 0;
+        return *this;
+    }
+
+    void ref()
+    {
+        mRef++;
+    }
+
+    void unref()
+    {
+        llassert(mRef >= 1);
+        if ((--mRef) == 0)
+        {
+            // If we hit zero, the caller should be the only smart pointer owning the object and we can delete it.
+            // It is technically possible for a vanilla pointer to mess this up, or another thread to
+            // jump in, find this object, create another smart pointer and end up dangling, but if
+            // the code is that bad and not thread-safe, it's trouble already.
+            delete this;
+        }
+    }
+
+    S32 getNumRefs() const
+    {
+        const S32 currentVal = mRef.CurrentValue();
+        return currentVal;
+    }
 
 private:
-	LLAtomicS32 mRef;
+    LLAtomicS32 mRef;
 };
 
 /**
@@ -145,12 +145,12 @@ class LL_COMMON_API LLThreadSafeRefCount
  */
 inline void intrusive_ptr_add_ref(LLThreadSafeRefCount* p)
 {
-	p->ref();
+    p->ref();
 }
 
 inline void intrusive_ptr_release(LLThreadSafeRefCount* p)
 {
-	p->unref();
+    p->unref();
 }
 
 /**
@@ -159,12 +159,12 @@ inline void intrusive_ptr_release(LLThreadSafeRefCount* p)
  */
 inline void intrusive_ptr_add_ref(LLRefCount* p)
 {
-	p->ref();
+    p->ref();
 }
 
 inline void intrusive_ptr_release(LLRefCount* p)
 {
-	p->unref();
+    p->unref();
 }
 
 #endif
diff --git a/indra/llcommon/llstrider.h b/indra/llcommon/llstrider.h
index 1b1d93024440c29cc03a1200d3811d1c129771c0..a42ac08b8e0eb5f28226c56988ad994d0a7b8bfd 100644
--- a/indra/llcommon/llstrider.h
+++ b/indra/llcommon/llstrider.h
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file llstrider.h
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -32,63 +32,63 @@
 template<typename T>
 inline void copyArray(T* dst, const T* src, const U32 bytes)
 {
-	memcpy(dst, src, bytes);
+    memcpy(dst, src, bytes);
 }
 template<>
 inline void copyArray<>(LLVector4a* dst, const LLVector4a* src, const U32 bytes)
 {
-	LLVector4a::memcpyNonAliased16(dst->getF32ptr(), src->getF32ptr(), bytes);
+    LLVector4a::memcpyNonAliased16(dst->getF32ptr(), src->getF32ptr(), bytes);
 }
 
 template <class Object> class LLStrider
 {
-	union
-	{
-		Object* mObjectp;
-		U8*		mBytep;
-	};
-	U32     mSkip;
+    union
+    {
+        Object* mObjectp;
+        U8*     mBytep;
+    };
+    U32     mSkip;
 public:
-	LLStrider()  { mObjectp = NULL; mSkip = sizeof(Object); } 
+    LLStrider()  { mObjectp = NULL; mSkip = sizeof(Object); }
     LLStrider(Object* first) { mObjectp = first; mSkip = sizeof(Object); }
-	~LLStrider() = default;
+    ~LLStrider() = default;
 
-	const LLStrider<Object>& operator =  (Object *first)    { mObjectp = first; return *this;}
-	void setStride (S32 skipBytes)	{ mSkip = (skipBytes ? skipBytes : sizeof(Object));}
+    const LLStrider<Object>& operator =  (Object *first)    { mObjectp = first; return *this;}
+    void setStride (S32 skipBytes)  { mSkip = (skipBytes ? skipBytes : sizeof(Object));}
 
-	LLStrider<Object> operator+(const S32& index) 
-	{
-		LLStrider<Object> ret;
-		ret.mBytep = mBytep + mSkip*index;
-		ret.mSkip = mSkip;
+    LLStrider<Object> operator+(const S32& index)
+    {
+        LLStrider<Object> ret;
+        ret.mBytep = mBytep + mSkip*index;
+        ret.mSkip = mSkip;
 
-		return ret;
-	}
+        return ret;
+    }
 
-	void skip(const U32 index)     { mBytep += mSkip*index;}
-	U32 getSkip() const			   { return mSkip; }
-	Object* get()                  { return mObjectp; }
-	Object* operator->()           { return mObjectp; }
-	Object& operator *()           { return *mObjectp; }
-	Object* operator ++(int)       { Object* old = mObjectp; mBytep += mSkip; return old; }
-	Object* operator +=(int i)     { mBytep += mSkip*i; return mObjectp; }
+    void skip(const U32 index)     { mBytep += mSkip*index;}
+    U32 getSkip() const            { return mSkip; }
+    Object* get()                  { return mObjectp; }
+    Object* operator->()           { return mObjectp; }
+    Object& operator *()           { return *mObjectp; }
+    Object* operator ++(int)       { Object* old = mObjectp; mBytep += mSkip; return old; }
+    Object* operator +=(int i)     { mBytep += mSkip*i; return mObjectp; }
 
-	Object& operator[](U32 index)  { return *(Object*)(mBytep + (mSkip * index)); }
+    Object& operator[](U32 index)  { return *(Object*)(mBytep + (mSkip * index)); }
 
-	void copyArray(const U32 offset, const Object* src, const U32 length)
-	{
-		if (mSkip == sizeof(Object))
-		{
-			::copyArray(mObjectp + offset, src, length * sizeof(Object));
-		}
-		else
-		{
-			for (U32 i = 0; i < length; i++)
-			{
-				(*this)[offset + i] = src[i];
-			}
-		}
-	}
+    void copyArray(const U32 offset, const Object* src, const U32 length)
+    {
+        if (mSkip == sizeof(Object))
+        {
+            ::copyArray(mObjectp + offset, src, length * sizeof(Object));
+        }
+        else
+        {
+            for (U32 i = 0; i < length; i++)
+            {
+                (*this)[offset + i] = src[i];
+            }
+        }
+    }
 };
 
 #endif // LL_LLSTRIDER_H
diff --git a/indra/llimage/llimage.cpp b/indra/llimage/llimage.cpp
index 4a772b08b12bc7f4fe8912ba725055571a8de7f0..21323ce86fb148011c4c24a913ff557a1b6ec780 100644
--- a/indra/llimage/llimage.cpp
+++ b/indra/llimage/llimage.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llimage.cpp
  * @brief Base class for images.
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -57,40 +57,40 @@
 #define _UNROL_GEN_TPL_comma_1 BOOST_PP_COMMA()
 //..................................................................................
 #define _UNROL_GEN_TPL_ARGS_macro(z,n,seq) \
-	BOOST_PP_CAT(_UNROL_GEN_TPL_arg_, BOOST_PP_MOD(n, 2))(BOOST_PP_SEQ_ELEM(n, seq)) BOOST_PP_CAT(_UNROL_GEN_TPL_comma_, BOOST_PP_AND(BOOST_PP_MOD(n, 2), BOOST_PP_NOT_EQUAL(BOOST_PP_INC(n), BOOST_PP_SEQ_SIZE(seq))))
+    BOOST_PP_CAT(_UNROL_GEN_TPL_arg_, BOOST_PP_MOD(n, 2))(BOOST_PP_SEQ_ELEM(n, seq)) BOOST_PP_CAT(_UNROL_GEN_TPL_comma_, BOOST_PP_AND(BOOST_PP_MOD(n, 2), BOOST_PP_NOT_EQUAL(BOOST_PP_INC(n), BOOST_PP_SEQ_SIZE(seq))))
 
 #define _UNROL_GEN_TPL_ARGS(seq) \
-	BOOST_PP_REPEAT(BOOST_PP_SEQ_SIZE(seq), _UNROL_GEN_TPL_ARGS_macro, seq)
+    BOOST_PP_REPEAT(BOOST_PP_SEQ_SIZE(seq), _UNROL_GEN_TPL_ARGS_macro, seq)
 //..................................................................................
 
 #define _UNROL_GEN_TPL_TYPE_ARGS_macro(z,n,seq) \
-	BOOST_PP_SEQ_ELEM(n, seq) BOOST_PP_CAT(_UNROL_GEN_TPL_comma_, BOOST_PP_AND(BOOST_PP_MOD(n, 2), BOOST_PP_NOT_EQUAL(BOOST_PP_INC(n), BOOST_PP_SEQ_SIZE(seq))))
+    BOOST_PP_SEQ_ELEM(n, seq) BOOST_PP_CAT(_UNROL_GEN_TPL_comma_, BOOST_PP_AND(BOOST_PP_MOD(n, 2), BOOST_PP_NOT_EQUAL(BOOST_PP_INC(n), BOOST_PP_SEQ_SIZE(seq))))
 
 #define _UNROL_GEN_TPL_TYPE_ARGS(seq) \
-	BOOST_PP_REPEAT(BOOST_PP_SEQ_SIZE(seq), _UNROL_GEN_TPL_TYPE_ARGS_macro, seq)
+    BOOST_PP_REPEAT(BOOST_PP_SEQ_SIZE(seq), _UNROL_GEN_TPL_TYPE_ARGS_macro, seq)
 //..................................................................................
 #define _UNROLL_GEN_TPL_foreach_ee(z, n, seq) \
-	executor<n>(_UNROL_GEN_TPL_ARGS(seq));
+    executor<n>(_UNROL_GEN_TPL_ARGS(seq));
 
 #define _UNROLL_GEN_TPL(name, args_seq, operation, spec) \
-	template<> struct name<spec> { \
-	private: \
-		template<S32 _idx> inline void executor(_UNROL_GEN_TPL_TYPE_ARGS(args_seq)) { \
-			BOOST_PP_SEQ_ENUM(operation) ; \
-		} \
-	public: \
-		inline void operator()(_UNROL_GEN_TPL_TYPE_ARGS(args_seq)) { \
-			BOOST_PP_REPEAT(spec, _UNROLL_GEN_TPL_foreach_ee, args_seq) \
-		} \
+    template<> struct name<spec> { \
+    private: \
+        template<S32 _idx> inline void executor(_UNROL_GEN_TPL_TYPE_ARGS(args_seq)) { \
+            BOOST_PP_SEQ_ENUM(operation) ; \
+        } \
+    public: \
+        inline void operator()(_UNROL_GEN_TPL_TYPE_ARGS(args_seq)) { \
+            BOOST_PP_REPEAT(spec, _UNROLL_GEN_TPL_foreach_ee, args_seq) \
+        } \
 };
 //..................................................................................
 #define _UNROLL_GEN_TPL_foreach_seq_macro(r, data, elem) \
-	_UNROLL_GEN_TPL(BOOST_PP_SEQ_ELEM(0, data), BOOST_PP_SEQ_ELEM(1, data), BOOST_PP_SEQ_ELEM(2, data), elem)
+    _UNROLL_GEN_TPL(BOOST_PP_SEQ_ELEM(0, data), BOOST_PP_SEQ_ELEM(1, data), BOOST_PP_SEQ_ELEM(2, data), elem)
 
 #define UNROLL_GEN_TPL(name, args_seq, operation, spec_seq) \
-	/*general specialization - should not be implemented!*/ \
-	template<U8> struct name { inline void operator()(_UNROL_GEN_TPL_TYPE_ARGS(args_seq)) { /*static_assert(!"Should not be instantiated.");*/  } }; \
-	BOOST_PP_SEQ_FOR_EACH(_UNROLL_GEN_TPL_foreach_seq_macro, (name)(args_seq)(operation), spec_seq)
+    /*general specialization - should not be implemented!*/ \
+    template<U8> struct name { inline void operator()(_UNROL_GEN_TPL_TYPE_ARGS(args_seq)) { /*static_assert(!"Should not be instantiated.");*/  } }; \
+    BOOST_PP_SEQ_FOR_EACH(_UNROLL_GEN_TPL_foreach_seq_macro, (name)(args_seq)(operation), spec_seq)
 //..................................................................................
 //..................................................................................
 
@@ -126,460 +126,460 @@ UNROLL_GEN_TPL(uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff, (U8 *&)(dptr)(S3
 
 
 template<U8 ch>
-struct scale_info 
+struct scale_info
 {
 public:
-	std::vector<S32> xpoints;
-	std::vector<const U8*> ystrides;
-	std::vector<S32> xapoints, yapoints;
-	S32 xup_yup;
+    std::vector<S32> xpoints;
+    std::vector<const U8*> ystrides;
+    std::vector<S32> xapoints, yapoints;
+    S32 xup_yup;
 
 public:
-	//unrolling loop types declaration
-	typedef uroll_zeroze_cx_comp<ch>														uroll_zeroze_cx_comp_t;
-	typedef uroll_comp_rshftasgn_constval<ch>												uroll_comp_rshftasgn_constval_t;
-	typedef uroll_comp_asgn_cx_rshft_cval_all_mul_val<ch>									uroll_comp_asgn_cx_rshft_cval_all_mul_val_t;
-	typedef uroll_comp_plusasgn_cx_rshft_cval_all_mul_val<ch>								uroll_comp_plusasgn_cx_rshft_cval_all_mul_val_t;
-	typedef uroll_inp_plusasgn_pix_mul_val<ch>												uroll_inp_plusasgn_pix_mul_val_t;
-	typedef uroll_inp_asgn_pix_mul_val<ch>													uroll_inp_asgn_pix_mul_val_t;
-	typedef uroll_comp_asgn_cx_mul_apoint_plus_comp_mul_inv_apoint_allshifted_16_r<ch>		uroll_comp_asgn_cx_mul_apoint_plus_comp_mul_inv_apoint_allshifted_16_r_t;
-	typedef uroll_comp_asgn_comp_plus_pix_mul_apoint_allshifted_8_r<ch>						uroll_comp_asgn_comp_plus_pix_mul_apoint_allshifted_8_r_t;
-	typedef uroll_comp_asgn_comp_mul_inv_apoint_plus_cx_mul_apoint_allshifted_12_r<ch>		uroll_comp_asgn_comp_mul_inv_apoint_plus_cx_mul_apoint_allshifted_12_r_t;
-	typedef uroll_uref_dptr_inc_asgn_comp_and_ff<ch>										uroll_uref_dptr_inc_asgn_comp_and_ff_t;
-	typedef uroll_uref_dptr_inc_asgn_sptr_apoint_plus_idx_alland_ff<ch>						uroll_uref_dptr_inc_asgn_sptr_apoint_plus_idx_alland_ff_t;
-	typedef uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff<ch>								uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff_t;
+    //unrolling loop types declaration
+    typedef uroll_zeroze_cx_comp<ch>                                                        uroll_zeroze_cx_comp_t;
+    typedef uroll_comp_rshftasgn_constval<ch>                                               uroll_comp_rshftasgn_constval_t;
+    typedef uroll_comp_asgn_cx_rshft_cval_all_mul_val<ch>                                   uroll_comp_asgn_cx_rshft_cval_all_mul_val_t;
+    typedef uroll_comp_plusasgn_cx_rshft_cval_all_mul_val<ch>                               uroll_comp_plusasgn_cx_rshft_cval_all_mul_val_t;
+    typedef uroll_inp_plusasgn_pix_mul_val<ch>                                              uroll_inp_plusasgn_pix_mul_val_t;
+    typedef uroll_inp_asgn_pix_mul_val<ch>                                                  uroll_inp_asgn_pix_mul_val_t;
+    typedef uroll_comp_asgn_cx_mul_apoint_plus_comp_mul_inv_apoint_allshifted_16_r<ch>      uroll_comp_asgn_cx_mul_apoint_plus_comp_mul_inv_apoint_allshifted_16_r_t;
+    typedef uroll_comp_asgn_comp_plus_pix_mul_apoint_allshifted_8_r<ch>                     uroll_comp_asgn_comp_plus_pix_mul_apoint_allshifted_8_r_t;
+    typedef uroll_comp_asgn_comp_mul_inv_apoint_plus_cx_mul_apoint_allshifted_12_r<ch>      uroll_comp_asgn_comp_mul_inv_apoint_plus_cx_mul_apoint_allshifted_12_r_t;
+    typedef uroll_uref_dptr_inc_asgn_comp_and_ff<ch>                                        uroll_uref_dptr_inc_asgn_comp_and_ff_t;
+    typedef uroll_uref_dptr_inc_asgn_sptr_apoint_plus_idx_alland_ff<ch>                     uroll_uref_dptr_inc_asgn_sptr_apoint_plus_idx_alland_ff_t;
+    typedef uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff<ch>                             uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff_t;
 
 public:
-	scale_info(const U8 *src, U32 srcW, U32 srcH, U32 dstW, U32 dstH, U32 srcStride)
-		: xup_yup((dstW >= srcW) + ((dstH >= srcH) << 1))
-	{
-		calc_x_points(srcW, dstW);
-		calc_y_strides(src, srcStride, srcH, dstH);
-		calc_aa_points(srcW, dstW, xup_yup&1, xapoints);
-		calc_aa_points(srcH, dstH, xup_yup&2, yapoints);
-	}
+    scale_info(const U8 *src, U32 srcW, U32 srcH, U32 dstW, U32 dstH, U32 srcStride)
+        : xup_yup((dstW >= srcW) + ((dstH >= srcH) << 1))
+    {
+        calc_x_points(srcW, dstW);
+        calc_y_strides(src, srcStride, srcH, dstH);
+        calc_aa_points(srcW, dstW, xup_yup&1, xapoints);
+        calc_aa_points(srcH, dstH, xup_yup&2, yapoints);
+    }
 
 private:
-	//...........................................................................................
-	void calc_x_points(U32 srcW, U32 dstW)
-	{
-		xpoints.resize(dstW+1);
-
-		S32 val = dstW >= srcW ? 0x8000 * srcW / dstW - 0x8000 : 0;
-		S32 inc = (srcW << 16) / dstW;
-
-		for(U32 i = 0, j = 0; i < dstW; ++i, ++j, val += inc)
-		{
-			xpoints[j] = llmax(0, val >> 16);
-		}
-	}
-	//...........................................................................................
-	void calc_y_strides(const U8 *src, U32 srcStride, U32 srcH, U32 dstH)
-	{
-		ystrides.resize(dstH+1);
-
-		S32 val = dstH >= srcH ? 0x8000 * srcH / dstH - 0x8000 : 0;
-		S32 inc = (srcH << 16) / dstH;
-
-		for(U32 i = 0, j = 0; i < dstH; ++i, ++j, val += inc)
-		{
-			ystrides[j] = src + llmax(0, val >> 16) * srcStride;
-		}
-	}
-	//...........................................................................................
-	void calc_aa_points(U32 srcSz, U32 dstSz, bool scale_up, std::vector<S32> &vp)
-	{
-		vp.resize(dstSz);
-
-		if(scale_up)
-		{
-			S32 val = 0x8000 * srcSz / dstSz - 0x8000;
-			S32 inc = (srcSz << 16) / dstSz;
-			U32 pos;
-
-			for(U32 i = 0, j = 0; i < dstSz; ++i, ++j, val += inc)
-			{
-				pos = val >> 16;
-
-				if (pos >= (srcSz - 1))
-					vp[j] = 0;
-				else
-					vp[j] = (val >> 8) - ((val >> 8) & 0xffffff00);
-			}
-		}
-		else
-		{ 
-			S32 inc = (srcSz << 16) / dstSz;
-			S32 Cp = ((dstSz << 14) / srcSz) + 1;
-			S32 ap;
-
-			for(U32 i = 0, j = 0, val = 0; i < dstSz; ++i, ++j, val += inc)
-			{
-				ap = ((0x100 - ((val >> 8) & 0xff)) * Cp) >> 8;
-				vp[j] = ap | (Cp << 16);
-			}
-		}
-	}
+    //...........................................................................................
+    void calc_x_points(U32 srcW, U32 dstW)
+    {
+        xpoints.resize(dstW+1);
+
+        S32 val = dstW >= srcW ? 0x8000 * srcW / dstW - 0x8000 : 0;
+        S32 inc = (srcW << 16) / dstW;
+
+        for(U32 i = 0, j = 0; i < dstW; ++i, ++j, val += inc)
+        {
+            xpoints[j] = llmax(0, val >> 16);
+        }
+    }
+    //...........................................................................................
+    void calc_y_strides(const U8 *src, U32 srcStride, U32 srcH, U32 dstH)
+    {
+        ystrides.resize(dstH+1);
+
+        S32 val = dstH >= srcH ? 0x8000 * srcH / dstH - 0x8000 : 0;
+        S32 inc = (srcH << 16) / dstH;
+
+        for(U32 i = 0, j = 0; i < dstH; ++i, ++j, val += inc)
+        {
+            ystrides[j] = src + llmax(0, val >> 16) * srcStride;
+        }
+    }
+    //...........................................................................................
+    void calc_aa_points(U32 srcSz, U32 dstSz, bool scale_up, std::vector<S32> &vp)
+    {
+        vp.resize(dstSz);
+
+        if(scale_up)
+        {
+            S32 val = 0x8000 * srcSz / dstSz - 0x8000;
+            S32 inc = (srcSz << 16) / dstSz;
+            U32 pos;
+
+            for(U32 i = 0, j = 0; i < dstSz; ++i, ++j, val += inc)
+            {
+                pos = val >> 16;
+
+                if (pos >= (srcSz - 1))
+                    vp[j] = 0;
+                else
+                    vp[j] = (val >> 8) - ((val >> 8) & 0xffffff00);
+            }
+        }
+        else
+        {
+            S32 inc = (srcSz << 16) / dstSz;
+            S32 Cp = ((dstSz << 14) / srcSz) + 1;
+            S32 ap;
+
+            for(U32 i = 0, j = 0, val = 0; i < dstSz; ++i, ++j, val += inc)
+            {
+                ap = ((0x100 - ((val >> 8) & 0xff)) * Cp) >> 8;
+                vp[j] = ap | (Cp << 16);
+            }
+        }
+    }
 };
 
 
 template<U8 ch>
 inline void bilinear_scale(
-	const U8 *src, U32 srcW, U32 srcH, U32 srcStride
-	, U8 *dst, U32 dstW, U32 dstH, U32 dstStride
-	)
-{
-	typedef scale_info<ch> scale_info_t;
-
-	scale_info_t info(src, srcW, srcH, dstW, dstH, srcStride);
-
-	const U8 *sptr;
-	U8 *dptr;
-	U32 x, y;
-	const U8 *pix;
-
-	S32 cx[ch], comp[ch];
-
-
-	if(3 == info.xup_yup)
-	{ //scale x/y - up
-		for(y = 0; y < dstH; ++y)
-		{
-			dptr = dst + (y * dstStride);
-			sptr = info.ystrides[y];
-
-			if(0 < info.yapoints[y])
-			{
-				for(x = 0; x < dstW; ++x)
-				{
-					//for(c = 0; c < ch; ++c) cx[c] = comp[c] = 0;
-					typename scale_info_t::uroll_zeroze_cx_comp_t()(cx, comp);
-
-					if(0 < info.xapoints[x])
-					{
-						pix = info.ystrides[y] + info.xpoints[x] * ch;
-
-						//for(c = 0; c < ch; ++c) comp[c] = pix[c] * (256 - info.xapoints[x]);
-						typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, 256 - info.xapoints[x]);
-
-						pix += ch;
-
-						//for(c = 0; c < ch; ++c) comp[c] += pix[c] * info.xapoints[x];
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, info.xapoints[x]);
-
-						pix += srcStride;
-
-						//for(c = 0; c < ch; ++c) cx[c] = pix[c] * info.xapoints[x];
-						typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, info.xapoints[x]);
-
-						pix -= ch;
-
-						//for(c = 0; c < ch; ++c) { 
-						//	cx[c] += pix[c] * (256 - info.xapoints[x]);
-						//	comp[c] = ((cx[c] * info.yapoints[y]) + (comp[c] * (256 - info.yapoints[y]))) >> 16;
-						//	*dptr++ = comp[c]&0xff;
-						//}
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, 256 - info.xapoints[x]);
-						typename scale_info_t::uroll_comp_asgn_cx_mul_apoint_plus_comp_mul_inv_apoint_allshifted_16_r_t()(comp, cx, info.yapoints[y]);
-						typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_and_ff_t()(dptr, comp);
-					}
-					else
-					{
-						pix = info.ystrides[y] + info.xpoints[x] * ch;
-
-						//for(c = 0; c < ch; ++c) comp[c] = pix[c] * (256 - info.yapoints[y]);
-						typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, 256-info.yapoints[y]);
-
-						pix += srcStride;
-
-						//for(c = 0; c < ch; ++c) { 
-						//	comp[c] = (comp[c] + pix[c] * info.yapoints[y]) >> 8;
-						//	*dptr++ = comp[c]&0xff;
-						//}
-						typename scale_info_t::uroll_comp_asgn_comp_plus_pix_mul_apoint_allshifted_8_r_t()(comp, pix, info.yapoints[y]);
-						typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_and_ff_t()(dptr, comp);
-					}
-				}
-			}
-			else
-			{
-				for(x = 0; x < dstW; ++x)
-				{
-					if(0 < info.xapoints[x])
-					{
-						pix = info.ystrides[y] + info.xpoints[x] * ch;
-
-						//for(c = 0; c < ch; ++c) {
-						//	comp[c] = pix[c] * (256 - info.xapoints[x]);
-						//	comp[c] = (comp[c] + pix[c] * info.xapoints[x]) >> 8;
-						//	*dptr++ = comp[c]&0xff;
-						//}
-						typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, 256 - info.xapoints[x]);
-						typename scale_info_t::uroll_comp_asgn_comp_plus_pix_mul_apoint_allshifted_8_r_t()(comp, pix, info.xapoints[x]);
-						typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_and_ff_t()(dptr, comp);
-					}
-					else 
-					{
-						//for(c = 0; c < ch; ++c) *dptr++ = (sptr[info.xpoints[x]*ch + c])&0xff;
-						typename scale_info_t::uroll_uref_dptr_inc_asgn_sptr_apoint_plus_idx_alland_ff_t()(dptr, sptr, info.xpoints[x]*ch);
-					}
-				}
-			}
-		}
-	}
-	else if(info.xup_yup == 1)
-	{ //scaling down vertically
-		S32 Cy, j;
-		S32 yap;
-
-		for(y = 0; y < dstH; y++)
-		{
-			Cy = info.yapoints[y] >> 16;
-			yap = info.yapoints[y] & 0xffff;
-
-			dptr = dst + (y * dstStride);
-
-			for(x = 0; x < dstW; x++)
-			{
-				pix = info.ystrides[y] + info.xpoints[x] * ch;
-
-				//for(c = 0; c < ch; ++c) comp[c] = pix[c] * yap;
-				typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, yap);
-
-				pix += srcStride;
-
-				for(j = (1 << 14) - yap; j > Cy; j -= Cy, pix += srcStride)
-				{
-					//for(c = 0; c < ch; ++c) comp[c] += pix[c] * Cy;
-					typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, Cy);
-				}
-
-				if(j > 0)
-				{
-					//for(c = 0; c < ch; ++c) comp[c] += pix[c] * j;
-					typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, j);
-				}
-
-				if(info.xapoints[x] > 0)
-				{
-					pix = info.ystrides[y] + info.xpoints[x]*ch + ch;
-					//for(c = 0; c < ch; ++c) cx[c] = pix[c] * yap;
-					typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, yap);
-
-					pix += srcStride;
-					for(j = (1 << 14) - yap; j > Cy; j -= Cy)
-					{
-						//for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cy;
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cy);
-						pix += srcStride;
-					}
-
-					if(j > 0)
-					{
-						//for(c = 0; c < ch; ++c) cx[c] += pix[c] * j;
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, j);
-					}
-
-					//for(c = 0; c < ch; ++c) comp[c] = ((comp[c]*(256 - info.xapoints[x])) + ((cx[c] * info.xapoints[x]))) >> 12;
-					typename scale_info_t::uroll_comp_asgn_comp_mul_inv_apoint_plus_cx_mul_apoint_allshifted_12_r_t()(comp, info.xapoints[x], cx);
-				}
-				else
-				{
-					//for(c = 0; c < ch; ++c) comp[c] >>= 4;
-					typename scale_info_t::uroll_comp_rshftasgn_constval_t()(comp, 4);
-				}
-
-				//for(c = 0; c < ch; ++c) *dptr++ = (comp[c]>>10)&0xff;
-				typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff_t()(dptr, comp, 10);
-			}
-		}
-	}
-	else if(info.xup_yup == 2)
-	{ // scaling down horizontally
-		S32 Cx, j;
-		S32 xap;
-
-		for(y = 0; y < dstH; y++)
-		{
-			dptr = dst + (y * dstStride);
-
-			for(x = 0; x < dstW; x++)
-			{
-				Cx = info.xapoints[x] >> 16;
-				xap = info.xapoints[x] & 0xffff;
-
-				pix = info.ystrides[y] + info.xpoints[x] * ch;
-
-				//for(c = 0; c < ch; ++c) comp[c] = pix[c] * xap;
-				typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, xap);
-
-				pix+=ch;
-				for(j = (1 << 14) - xap; j > Cx; j -= Cx)
-				{
-					//for(c = 0; c < ch; ++c) comp[c] += pix[c] * Cx;
-					typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, Cx);
-					pix+=ch;
-				}
-
-				if(j > 0)
-				{
-					//for(c = 0; c < ch; ++c) comp[c] += pix[c] * j;
-					typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, j);
-				}
-
-				if(info.yapoints[y] > 0)
-				{
-					pix = info.ystrides[y] + info.xpoints[x]*ch + srcStride;
-					//for(c = 0; c < ch; ++c) cx[c] = pix[c] * xap;
-					typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, xap);
-
-					pix+=ch;
-					for(j = (1 << 14) - xap; j > Cx; j -= Cx)
-					{
-						//for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cx;
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cx);
-						pix+=ch;
-					}
-
-					if(j > 0)
-					{
-						//for(c = 0; c < ch; ++c) cx[c] += pix[c] * j;
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, j);
-					}
-
-					//for(c = 0; c < ch; ++c) comp[c] = ((comp[c] * (256 - info.yapoints[y])) + ((cx[c] * info.yapoints[y]))) >> 12;
-					typename scale_info_t::uroll_comp_asgn_comp_mul_inv_apoint_plus_cx_mul_apoint_allshifted_12_r_t()(comp, info.yapoints[y], cx);
-				}
-				else
-				{
-					//for(c = 0; c < ch; ++c) comp[c] >>= 4;
-					typename scale_info_t::uroll_comp_rshftasgn_constval_t()(comp, 4);
-				}
-
-				//for(c = 0; c < ch; ++c) *dptr++ = (comp[c]>>10)&0xff;
-				typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff_t()(dptr, comp, 10);
-			}
-		}
-	}
-	else 
-	{ //scale x/y - down
-		S32 Cx, Cy, i, j;
-		S32 xap, yap;
-
-		for(y = 0; y < dstH; y++)
-		{
-			Cy = info.yapoints[y] >> 16;
-			yap = info.yapoints[y] & 0xffff;
-
-			dptr = dst + (y * dstStride);
-			for(x = 0; x < dstW; x++)
-			{
-				Cx = info.xapoints[x] >> 16;
-				xap = info.xapoints[x] & 0xffff;
-
-				sptr = info.ystrides[y] + info.xpoints[x] * ch;
-				pix = sptr;
-				sptr += srcStride;
-
-				//for(c = 0; c < ch; ++c) cx[c] = pix[c] * xap;
-				typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, xap);
-
-				pix+=ch;
-				for(i = (1 << 14) - xap; i > Cx; i -= Cx)
-				{
-					//for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cx;
-					typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cx);
-					pix+=ch;
-				}
-
-				if(i > 0)
-				{
-					//for(c = 0; c < ch; ++c) cx[c] += pix[c] * i;
-					typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, i);
-				}
-
-				//for(c = 0; c < ch; ++c) comp[c] = (cx[c] >> 5) * yap;
-				typename scale_info_t::uroll_comp_asgn_cx_rshft_cval_all_mul_val_t()(comp, cx, 5, yap);
-
-				for(j = (1 << 14) - yap; j > Cy; j -= Cy)
-				{
-					pix = sptr;
-					sptr += srcStride;
-
-					//for(c = 0; c < ch; ++c) cx[c] = pix[c] * xap;
-					typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, xap);
-
-					pix+=ch;
-					for(i = (1 << 14) - xap; i > Cx; i -= Cx)
-					{
-						//for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cx;
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cx);
-						pix+=ch;
-					}
-
-					if(i > 0)
-					{
-						//for(c = 0; c < ch; ++c) cx[c] += pix[c] * i;
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, i);
-					}
-
-					//for(c = 0; c < ch; ++c) comp[c] += (cx[c] >> 5) * Cy;
-					typename scale_info_t::uroll_comp_plusasgn_cx_rshft_cval_all_mul_val_t()(comp, cx, 5, Cy);
-				}
-
-				if(j > 0)
-				{
-					pix = sptr;
-					sptr += srcStride;
-
-					//for(c = 0; c < ch; ++c) cx[c] = pix[c] * xap;
-					typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, xap);
-
-					pix+=ch;
-					for(i = (1 << 14) - xap; i > Cx; i -= Cx)
-					{
-						//for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cx;
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cx);
-						pix+=ch;
-					}
-
-					if(i > 0)
-					{
-						//for(c = 0; c < ch; ++c) cx[c] += pix[c] * i;
-						typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, i);
-					}
-
-					//for(c = 0; c < ch; ++c) comp[c] += (cx[c] >> 5) * j;
-					typename scale_info_t::uroll_comp_plusasgn_cx_rshft_cval_all_mul_val_t()(comp, cx, 5, j);
-				}
-
-				//for(c = 0; c < ch; ++c) *dptr++ = (comp[c]>>23)&0xff;
-				typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff_t()(dptr, comp, 23);
-			}
-		}
-	} //else
+    const U8 *src, U32 srcW, U32 srcH, U32 srcStride
+    , U8 *dst, U32 dstW, U32 dstH, U32 dstStride
+    )
+{
+    typedef scale_info<ch> scale_info_t;
+
+    scale_info_t info(src, srcW, srcH, dstW, dstH, srcStride);
+
+    const U8 *sptr;
+    U8 *dptr;
+    U32 x, y;
+    const U8 *pix;
+
+    S32 cx[ch], comp[ch];
+
+
+    if(3 == info.xup_yup)
+    { //scale x/y - up
+        for(y = 0; y < dstH; ++y)
+        {
+            dptr = dst + (y * dstStride);
+            sptr = info.ystrides[y];
+
+            if(0 < info.yapoints[y])
+            {
+                for(x = 0; x < dstW; ++x)
+                {
+                    //for(c = 0; c < ch; ++c) cx[c] = comp[c] = 0;
+                    typename scale_info_t::uroll_zeroze_cx_comp_t()(cx, comp);
+
+                    if(0 < info.xapoints[x])
+                    {
+                        pix = info.ystrides[y] + info.xpoints[x] * ch;
+
+                        //for(c = 0; c < ch; ++c) comp[c] = pix[c] * (256 - info.xapoints[x]);
+                        typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, 256 - info.xapoints[x]);
+
+                        pix += ch;
+
+                        //for(c = 0; c < ch; ++c) comp[c] += pix[c] * info.xapoints[x];
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, info.xapoints[x]);
+
+                        pix += srcStride;
+
+                        //for(c = 0; c < ch; ++c) cx[c] = pix[c] * info.xapoints[x];
+                        typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, info.xapoints[x]);
+
+                        pix -= ch;
+
+                        //for(c = 0; c < ch; ++c) {
+                        //  cx[c] += pix[c] * (256 - info.xapoints[x]);
+                        //  comp[c] = ((cx[c] * info.yapoints[y]) + (comp[c] * (256 - info.yapoints[y]))) >> 16;
+                        //  *dptr++ = comp[c]&0xff;
+                        //}
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, 256 - info.xapoints[x]);
+                        typename scale_info_t::uroll_comp_asgn_cx_mul_apoint_plus_comp_mul_inv_apoint_allshifted_16_r_t()(comp, cx, info.yapoints[y]);
+                        typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_and_ff_t()(dptr, comp);
+                    }
+                    else
+                    {
+                        pix = info.ystrides[y] + info.xpoints[x] * ch;
+
+                        //for(c = 0; c < ch; ++c) comp[c] = pix[c] * (256 - info.yapoints[y]);
+                        typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, 256-info.yapoints[y]);
+
+                        pix += srcStride;
+
+                        //for(c = 0; c < ch; ++c) {
+                        //  comp[c] = (comp[c] + pix[c] * info.yapoints[y]) >> 8;
+                        //  *dptr++ = comp[c]&0xff;
+                        //}
+                        typename scale_info_t::uroll_comp_asgn_comp_plus_pix_mul_apoint_allshifted_8_r_t()(comp, pix, info.yapoints[y]);
+                        typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_and_ff_t()(dptr, comp);
+                    }
+                }
+            }
+            else
+            {
+                for(x = 0; x < dstW; ++x)
+                {
+                    if(0 < info.xapoints[x])
+                    {
+                        pix = info.ystrides[y] + info.xpoints[x] * ch;
+
+                        //for(c = 0; c < ch; ++c) {
+                        //  comp[c] = pix[c] * (256 - info.xapoints[x]);
+                        //  comp[c] = (comp[c] + pix[c] * info.xapoints[x]) >> 8;
+                        //  *dptr++ = comp[c]&0xff;
+                        //}
+                        typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, 256 - info.xapoints[x]);
+                        typename scale_info_t::uroll_comp_asgn_comp_plus_pix_mul_apoint_allshifted_8_r_t()(comp, pix, info.xapoints[x]);
+                        typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_and_ff_t()(dptr, comp);
+                    }
+                    else
+                    {
+                        //for(c = 0; c < ch; ++c) *dptr++ = (sptr[info.xpoints[x]*ch + c])&0xff;
+                        typename scale_info_t::uroll_uref_dptr_inc_asgn_sptr_apoint_plus_idx_alland_ff_t()(dptr, sptr, info.xpoints[x]*ch);
+                    }
+                }
+            }
+        }
+    }
+    else if(info.xup_yup == 1)
+    { //scaling down vertically
+        S32 Cy, j;
+        S32 yap;
+
+        for(y = 0; y < dstH; y++)
+        {
+            Cy = info.yapoints[y] >> 16;
+            yap = info.yapoints[y] & 0xffff;
+
+            dptr = dst + (y * dstStride);
+
+            for(x = 0; x < dstW; x++)
+            {
+                pix = info.ystrides[y] + info.xpoints[x] * ch;
+
+                //for(c = 0; c < ch; ++c) comp[c] = pix[c] * yap;
+                typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, yap);
+
+                pix += srcStride;
+
+                for(j = (1 << 14) - yap; j > Cy; j -= Cy, pix += srcStride)
+                {
+                    //for(c = 0; c < ch; ++c) comp[c] += pix[c] * Cy;
+                    typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, Cy);
+                }
+
+                if(j > 0)
+                {
+                    //for(c = 0; c < ch; ++c) comp[c] += pix[c] * j;
+                    typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, j);
+                }
+
+                if(info.xapoints[x] > 0)
+                {
+                    pix = info.ystrides[y] + info.xpoints[x]*ch + ch;
+                    //for(c = 0; c < ch; ++c) cx[c] = pix[c] * yap;
+                    typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, yap);
+
+                    pix += srcStride;
+                    for(j = (1 << 14) - yap; j > Cy; j -= Cy)
+                    {
+                        //for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cy;
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cy);
+                        pix += srcStride;
+                    }
+
+                    if(j > 0)
+                    {
+                        //for(c = 0; c < ch; ++c) cx[c] += pix[c] * j;
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, j);
+                    }
+
+                    //for(c = 0; c < ch; ++c) comp[c] = ((comp[c]*(256 - info.xapoints[x])) + ((cx[c] * info.xapoints[x]))) >> 12;
+                    typename scale_info_t::uroll_comp_asgn_comp_mul_inv_apoint_plus_cx_mul_apoint_allshifted_12_r_t()(comp, info.xapoints[x], cx);
+                }
+                else
+                {
+                    //for(c = 0; c < ch; ++c) comp[c] >>= 4;
+                    typename scale_info_t::uroll_comp_rshftasgn_constval_t()(comp, 4);
+                }
+
+                //for(c = 0; c < ch; ++c) *dptr++ = (comp[c]>>10)&0xff;
+                typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff_t()(dptr, comp, 10);
+            }
+        }
+    }
+    else if(info.xup_yup == 2)
+    { // scaling down horizontally
+        S32 Cx, j;
+        S32 xap;
+
+        for(y = 0; y < dstH; y++)
+        {
+            dptr = dst + (y * dstStride);
+
+            for(x = 0; x < dstW; x++)
+            {
+                Cx = info.xapoints[x] >> 16;
+                xap = info.xapoints[x] & 0xffff;
+
+                pix = info.ystrides[y] + info.xpoints[x] * ch;
+
+                //for(c = 0; c < ch; ++c) comp[c] = pix[c] * xap;
+                typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(comp, pix, xap);
+
+                pix+=ch;
+                for(j = (1 << 14) - xap; j > Cx; j -= Cx)
+                {
+                    //for(c = 0; c < ch; ++c) comp[c] += pix[c] * Cx;
+                    typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, Cx);
+                    pix+=ch;
+                }
+
+                if(j > 0)
+                {
+                    //for(c = 0; c < ch; ++c) comp[c] += pix[c] * j;
+                    typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(comp, pix, j);
+                }
+
+                if(info.yapoints[y] > 0)
+                {
+                    pix = info.ystrides[y] + info.xpoints[x]*ch + srcStride;
+                    //for(c = 0; c < ch; ++c) cx[c] = pix[c] * xap;
+                    typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, xap);
+
+                    pix+=ch;
+                    for(j = (1 << 14) - xap; j > Cx; j -= Cx)
+                    {
+                        //for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cx;
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cx);
+                        pix+=ch;
+                    }
+
+                    if(j > 0)
+                    {
+                        //for(c = 0; c < ch; ++c) cx[c] += pix[c] * j;
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, j);
+                    }
+
+                    //for(c = 0; c < ch; ++c) comp[c] = ((comp[c] * (256 - info.yapoints[y])) + ((cx[c] * info.yapoints[y]))) >> 12;
+                    typename scale_info_t::uroll_comp_asgn_comp_mul_inv_apoint_plus_cx_mul_apoint_allshifted_12_r_t()(comp, info.yapoints[y], cx);
+                }
+                else
+                {
+                    //for(c = 0; c < ch; ++c) comp[c] >>= 4;
+                    typename scale_info_t::uroll_comp_rshftasgn_constval_t()(comp, 4);
+                }
+
+                //for(c = 0; c < ch; ++c) *dptr++ = (comp[c]>>10)&0xff;
+                typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff_t()(dptr, comp, 10);
+            }
+        }
+    }
+    else
+    { //scale x/y - down
+        S32 Cx, Cy, i, j;
+        S32 xap, yap;
+
+        for(y = 0; y < dstH; y++)
+        {
+            Cy = info.yapoints[y] >> 16;
+            yap = info.yapoints[y] & 0xffff;
+
+            dptr = dst + (y * dstStride);
+            for(x = 0; x < dstW; x++)
+            {
+                Cx = info.xapoints[x] >> 16;
+                xap = info.xapoints[x] & 0xffff;
+
+                sptr = info.ystrides[y] + info.xpoints[x] * ch;
+                pix = sptr;
+                sptr += srcStride;
+
+                //for(c = 0; c < ch; ++c) cx[c] = pix[c] * xap;
+                typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, xap);
+
+                pix+=ch;
+                for(i = (1 << 14) - xap; i > Cx; i -= Cx)
+                {
+                    //for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cx;
+                    typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cx);
+                    pix+=ch;
+                }
+
+                if(i > 0)
+                {
+                    //for(c = 0; c < ch; ++c) cx[c] += pix[c] * i;
+                    typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, i);
+                }
+
+                //for(c = 0; c < ch; ++c) comp[c] = (cx[c] >> 5) * yap;
+                typename scale_info_t::uroll_comp_asgn_cx_rshft_cval_all_mul_val_t()(comp, cx, 5, yap);
+
+                for(j = (1 << 14) - yap; j > Cy; j -= Cy)
+                {
+                    pix = sptr;
+                    sptr += srcStride;
+
+                    //for(c = 0; c < ch; ++c) cx[c] = pix[c] * xap;
+                    typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, xap);
+
+                    pix+=ch;
+                    for(i = (1 << 14) - xap; i > Cx; i -= Cx)
+                    {
+                        //for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cx;
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cx);
+                        pix+=ch;
+                    }
+
+                    if(i > 0)
+                    {
+                        //for(c = 0; c < ch; ++c) cx[c] += pix[c] * i;
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, i);
+                    }
+
+                    //for(c = 0; c < ch; ++c) comp[c] += (cx[c] >> 5) * Cy;
+                    typename scale_info_t::uroll_comp_plusasgn_cx_rshft_cval_all_mul_val_t()(comp, cx, 5, Cy);
+                }
+
+                if(j > 0)
+                {
+                    pix = sptr;
+                    sptr += srcStride;
+
+                    //for(c = 0; c < ch; ++c) cx[c] = pix[c] * xap;
+                    typename scale_info_t::uroll_inp_asgn_pix_mul_val_t()(cx, pix, xap);
+
+                    pix+=ch;
+                    for(i = (1 << 14) - xap; i > Cx; i -= Cx)
+                    {
+                        //for(c = 0; c < ch; ++c) cx[c] += pix[c] * Cx;
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, Cx);
+                        pix+=ch;
+                    }
+
+                    if(i > 0)
+                    {
+                        //for(c = 0; c < ch; ++c) cx[c] += pix[c] * i;
+                        typename scale_info_t::uroll_inp_plusasgn_pix_mul_val_t()(cx, pix, i);
+                    }
+
+                    //for(c = 0; c < ch; ++c) comp[c] += (cx[c] >> 5) * j;
+                    typename scale_info_t::uroll_comp_plusasgn_cx_rshft_cval_all_mul_val_t()(comp, cx, 5, j);
+                }
+
+                //for(c = 0; c < ch; ++c) *dptr++ = (comp[c]>>23)&0xff;
+                typename scale_info_t::uroll_uref_dptr_inc_asgn_comp_rshft_cval_and_ff_t()(dptr, comp, 23);
+            }
+        }
+    } //else
 }
 
 //wrapper
 static void bilinear_scale(const U8 *src, U32 srcW, U32 srcH, U32 srcCh, U32 srcStride, U8 *dst, U32 dstW, U32 dstH, U32 dstCh, U32 dstStride)
 {
-	llassert(srcCh == dstCh);
+    llassert(srcCh == dstCh);
 
-	switch(srcCh)
-	{
-	case 1:
-		bilinear_scale<1>(src, srcW, srcH, srcStride, dst, dstW, dstH, dstStride);
-		break;
-	case 3:
-		bilinear_scale<3>(src, srcW, srcH, srcStride, dst, dstW, dstH, dstStride);
-		break;
-	case 4:
-		bilinear_scale<4>(src, srcW, srcH, srcStride, dst, dstW, dstH, dstStride);
-		break;
-	default:
-		llassert(!"Implement if need");
-		break;
-	}
+    switch(srcCh)
+    {
+    case 1:
+        bilinear_scale<1>(src, srcW, srcH, srcStride, dst, dstW, dstH, dstStride);
+        break;
+    case 3:
+        bilinear_scale<3>(src, srcW, srcH, srcStride, dst, dstW, dstH, dstStride);
+        break;
+    case 4:
+        bilinear_scale<4>(src, srcW, srcH, srcStride, dst, dstW, dstH, dstStride);
+        break;
+    default:
+        llassert(!"Implement if need");
+        break;
+    }
 
 }
 
@@ -595,7 +595,7 @@ S32  LLImage::sMinimalReverseByteRangePercent = 75;
 //static
 void LLImage::initClass(bool use_new_byte_range, S32 minimal_reverse_byte_range_percent)
 {
-	sUseNewByteRange = use_new_byte_range;
+    sUseNewByteRange = use_new_byte_range;
     sMinimalReverseByteRangePercent = minimal_reverse_byte_range_percent;
 }
 
@@ -607,7 +607,7 @@ void LLImage::cleanupClass()
 //static
 const std::string& LLImage::getLastThreadError()
 {
-	static const std::string noerr("No Error");
+    static const std::string noerr("No Error");
     return sLastThreadErrorMessage.empty() ? noerr : sLastThreadErrorMessage;
 }
 
@@ -622,175 +622,175 @@ void LLImage::setLastError(const std::string& message)
 //---------------------------------------------------------------------------
 
 LLImageBase::LLImageBase()
-:	mData(NULL),
-	mDataSize(0),
-	mWidth(0),
-	mHeight(0),
-	mComponents(0),
-	mBadBufferAllocation(false),
-	mAllowOverSize(false)
+:   mData(NULL),
+    mDataSize(0),
+    mWidth(0),
+    mHeight(0),
+    mComponents(0),
+    mBadBufferAllocation(false),
+    mAllowOverSize(false)
 {}
 
 // virtual
 LLImageBase::~LLImageBase()
 {
-	deleteData(); // virtual
+    deleteData(); // virtual
 }
 
 // virtual
 void LLImageBase::dump()
 {
-	LL_INFOS() << "LLImageBase mComponents " << mComponents
-		<< " mData " << mData
-		<< " mDataSize " << mDataSize
-		<< " mWidth " << mWidth
-		<< " mHeight " << mHeight
-		<< LL_ENDL;
+    LL_INFOS() << "LLImageBase mComponents " << mComponents
+        << " mData " << mData
+        << " mDataSize " << mDataSize
+        << " mWidth " << mWidth
+        << " mHeight " << mHeight
+        << LL_ENDL;
 }
 
 // virtual
 void LLImageBase::sanityCheck()
 {
-	if (mWidth > MAX_IMAGE_SIZE
-		|| mHeight > MAX_IMAGE_SIZE
-		|| mDataSize > (S32)MAX_IMAGE_DATA_SIZE
-		|| mComponents > (S8)MAX_IMAGE_COMPONENTS
-		)
-	{
-		LL_ERRS() << "Failed LLImageBase::sanityCheck "
-			   << "width " << mWidth
-			   << "height " << mHeight
-			   << "datasize " << mDataSize
-			   << "components " << mComponents
-			   << "data " << mData
-			   << LL_ENDL;
-	}
+    if (mWidth > MAX_IMAGE_SIZE
+        || mHeight > MAX_IMAGE_SIZE
+        || mDataSize > (S32)MAX_IMAGE_DATA_SIZE
+        || mComponents > (S8)MAX_IMAGE_COMPONENTS
+        )
+    {
+        LL_ERRS() << "Failed LLImageBase::sanityCheck "
+               << "width " << mWidth
+               << "height " << mHeight
+               << "datasize " << mDataSize
+               << "components " << mComponents
+               << "data " << mData
+               << LL_ENDL;
+    }
 }
 
 // virtual
 void LLImageBase::deleteData()
 {
-	ll_aligned_free_16(mData);
-	mDataSize = 0;
-	mData = NULL;
+    ll_aligned_free_16(mData);
+    mDataSize = 0;
+    mData = NULL;
 }
 
 // virtual
 U8* LLImageBase::allocateData(S32 size)
 {
-	//make this function thread-safe.
-	static const U32 MAX_BUFFER_SIZE = 4096 * 4096 * 16; //256 MB
-	mBadBufferAllocation = false;
-
-	if (size < 0)
-	{
-		size = mWidth * mHeight * mComponents;
-		if (size <= 0)
-		{
-			LL_WARNS() << llformat("LLImageBase::allocateData called with bad dimensions: %dx%dx%d",mWidth,mHeight,(S32)mComponents) << LL_ENDL;
-			mBadBufferAllocation = true;
-		}
-	}	
-
-	if (!mBadBufferAllocation && (size < 1 || size > MAX_BUFFER_SIZE))
-	{
-		LL_INFOS() << "width: " << mWidth << " height: " << mHeight << " components: " << mComponents << LL_ENDL ;
-		if(mAllowOverSize)
-		{
-			LL_INFOS() << "Oversize: " << size << LL_ENDL ;
-		}
-		else
-		{
-			LL_WARNS() << "LLImageBase::allocateData: bad size: " << size << LL_ENDL;
-			mBadBufferAllocation = true;
-		}
-	}
-
-	if (!mBadBufferAllocation && (!mData || size != mDataSize))
-	{
-		deleteData(); // virtual
-		mData = (U8*)ll_aligned_malloc_16(size);
-		if (!mData)
-		{
-			LL_WARNS() << "Failed to allocate image data size [" << size << "]" << LL_ENDL;
-			mBadBufferAllocation = true;
-		}
-	}
-
-	if (mBadBufferAllocation)
-	{
-		size = 0;
-		mWidth = mHeight = 0;
-		if (mData)
-		{
-			deleteData(); // virtual
-			mData = NULL;
-		}
-	}
-	mDataSize = size;
-
-	return mData;
+    //make this function thread-safe.
+    static const U32 MAX_BUFFER_SIZE = 4096 * 4096 * 16; //256 MB
+    mBadBufferAllocation = false;
+
+    if (size < 0)
+    {
+        size = mWidth * mHeight * mComponents;
+        if (size <= 0)
+        {
+            LL_WARNS() << llformat("LLImageBase::allocateData called with bad dimensions: %dx%dx%d",mWidth,mHeight,(S32)mComponents) << LL_ENDL;
+            mBadBufferAllocation = true;
+        }
+    }
+
+    if (!mBadBufferAllocation && (size < 1 || size > MAX_BUFFER_SIZE))
+    {
+        LL_INFOS() << "width: " << mWidth << " height: " << mHeight << " components: " << mComponents << LL_ENDL ;
+        if(mAllowOverSize)
+        {
+            LL_INFOS() << "Oversize: " << size << LL_ENDL ;
+        }
+        else
+        {
+            LL_WARNS() << "LLImageBase::allocateData: bad size: " << size << LL_ENDL;
+            mBadBufferAllocation = true;
+        }
+    }
+
+    if (!mBadBufferAllocation && (!mData || size != mDataSize))
+    {
+        deleteData(); // virtual
+        mData = (U8*)ll_aligned_malloc_16(size);
+        if (!mData)
+        {
+            LL_WARNS() << "Failed to allocate image data size [" << size << "]" << LL_ENDL;
+            mBadBufferAllocation = true;
+        }
+    }
+
+    if (mBadBufferAllocation)
+    {
+        size = 0;
+        mWidth = mHeight = 0;
+        if (mData)
+        {
+            deleteData(); // virtual
+            mData = NULL;
+        }
+    }
+    mDataSize = size;
+
+    return mData;
 }
 
 // virtual
 U8* LLImageBase::reallocateData(S32 size)
 {
-	U8 *new_datap = (U8*)ll_aligned_malloc_16(size);
-	if (!new_datap)
-	{
-		LL_WARNS() << "Out of memory in LLImageBase::reallocateData" << LL_ENDL;
-		return 0;
-	}
-	if (mData)
-	{
-		S32 bytes = llmin(mDataSize, size);
-		memcpy(new_datap, mData, bytes);	/* Flawfinder: ignore */
-		ll_aligned_free_16(mData) ;
-	}
-	mData = new_datap;
-	mDataSize = size;
-	mBadBufferAllocation = false;
-	return mData;
-}
-
-const U8* LLImageBase::getData() const	
-{ 
-	if(mBadBufferAllocation)
-	{
-		LL_WARNS() << "Bad memory allocation for the image buffer!" << LL_ENDL ;
-		return NULL;
-	}
-
-	return mData; 
+    U8 *new_datap = (U8*)ll_aligned_malloc_16(size);
+    if (!new_datap)
+    {
+        LL_WARNS() << "Out of memory in LLImageBase::reallocateData" << LL_ENDL;
+        return 0;
+    }
+    if (mData)
+    {
+        S32 bytes = llmin(mDataSize, size);
+        memcpy(new_datap, mData, bytes);    /* Flawfinder: ignore */
+        ll_aligned_free_16(mData) ;
+    }
+    mData = new_datap;
+    mDataSize = size;
+    mBadBufferAllocation = false;
+    return mData;
+}
+
+const U8* LLImageBase::getData() const
+{
+    if(mBadBufferAllocation)
+    {
+        LL_WARNS() << "Bad memory allocation for the image buffer!" << LL_ENDL ;
+        return NULL;
+    }
+
+    return mData;
 } // read only
 
-U8* LLImageBase::getData()				
-{ 
-	if(mBadBufferAllocation)
-	{
-		LL_WARNS() << "Bad memory allocation for the image buffer!" << LL_ENDL;
-		return NULL;
-	}
+U8* LLImageBase::getData()
+{
+    if(mBadBufferAllocation)
+    {
+        LL_WARNS() << "Bad memory allocation for the image buffer!" << LL_ENDL;
+        return NULL;
+    }
 
-	return mData; 
+    return mData;
 }
 
 bool LLImageBase::isBufferInvalid() const
 {
-	return mBadBufferAllocation || mData == NULL ;
+    return mBadBufferAllocation || mData == NULL ;
 }
 
 void LLImageBase::setSize(S32 width, S32 height, S32 ncomponents)
 {
-	mWidth = width;
-	mHeight = height;
-	mComponents = ncomponents;
+    mWidth = width;
+    mHeight = height;
+    mComponents = ncomponents;
 }
 
 U8* LLImageBase::allocateDataSize(S32 width, S32 height, S32 ncomponents, S32 size)
 {
-	setSize(width, height, ncomponents);
-	return allocateData(size); // virtual
+    setSize(width, height, ncomponents);
+    return allocateData(size); // virtual
 }
 
 //---------------------------------------------------------------------------
@@ -800,17 +800,17 @@ U8* LLImageBase::allocateDataSize(S32 width, S32 height, S32 ncomponents, S32 si
 S32 LLImageRaw::sRawImageCount = 0;
 
 LLImageRaw::LLImageRaw()
-	: LLImageBase()
+    : LLImageBase()
 {
-	++sRawImageCount;
+    ++sRawImageCount;
 }
 
 LLImageRaw::LLImageRaw(U16 width, U16 height, S8 components)
-	: LLImageBase()
+    : LLImageBase()
 {
-	//llassert( S32(width) * S32(height) * S32(components) <= MAX_IMAGE_DATA_SIZE );
-	allocateDataSize(width, height, components);
-	++sRawImageCount;
+    //llassert( S32(width) * S32(height) * S32(components) <= MAX_IMAGE_DATA_SIZE );
+    allocateDataSize(width, height, components);
+    ++sRawImageCount;
 }
 
 LLImageRaw::LLImageRaw(const U8* data, U16 width, U16 height, S8 components)
@@ -823,45 +823,45 @@ LLImageRaw::LLImageRaw(const U8* data, U16 width, U16 height, S8 components)
 }
 
 LLImageRaw::LLImageRaw(U8 *data, U16 width, U16 height, S8 components, bool no_copy)
-	: LLImageBase()
+    : LLImageBase()
 {
-	if(no_copy)
-	{
-		setDataAndSize(data, width, height, components);
-	}
-	else if(allocateDataSize(width, height, components))
-	{
-		memcpy(getData(), data, width*height*components);
-	}
-	++sRawImageCount;
+    if(no_copy)
+    {
+        setDataAndSize(data, width, height, components);
+    }
+    else if(allocateDataSize(width, height, components))
+    {
+        memcpy(getData(), data, width*height*components);
+    }
+    ++sRawImageCount;
 }
 
 //LLImageRaw::LLImageRaw(const std::string& filename, bool j2c_lowest_mip_only)
-//	: LLImageBase()
+//  : LLImageBase()
 //{
-//	createFromFile(filename, j2c_lowest_mip_only);
+//  createFromFile(filename, j2c_lowest_mip_only);
 //}
 
 LLImageRaw::~LLImageRaw()
 {
-	// NOTE: ~LLimageBase() call to deleteData() calls LLImageBase::deleteData()
-	//        NOT LLImageRaw::deleteData()
-	deleteData();
-	--sRawImageCount;
+    // NOTE: ~LLimageBase() call to deleteData() calls LLImageBase::deleteData()
+    //        NOT LLImageRaw::deleteData()
+    deleteData();
+    --sRawImageCount;
 }
 
 // virtual
 U8* LLImageRaw::allocateData(S32 size)
 {
-	U8* res = LLImageBase::allocateData(size);
-	return res;
+    U8* res = LLImageBase::allocateData(size);
+    return res;
 }
 
 // virtual
 U8* LLImageRaw::reallocateData(S32 size)
 {
-	U8* res = LLImageBase::reallocateData(size);
-	return res;
+    U8* res = LLImageBase::reallocateData(size);
+    return res;
 }
 
 void LLImageRaw::releaseData()
@@ -873,118 +873,118 @@ void LLImageRaw::releaseData()
 // virtual
 void LLImageRaw::deleteData()
 {
-	LLImageBase::deleteData();
+    LLImageBase::deleteData();
 }
 
-void LLImageRaw::setDataAndSize(U8 *data, S32 width, S32 height, S8 components) 
-{ 
-	if(data == getData())
-	{
-		return ;
-	}
+void LLImageRaw::setDataAndSize(U8 *data, S32 width, S32 height, S8 components)
+{
+    if(data == getData())
+    {
+        return ;
+    }
 
-	deleteData();
+    deleteData();
 
-	LLImageBase::setSize(width, height, components) ;
-	LLImageBase::setDataAndSize(data, width * height * components) ;
+    LLImageBase::setSize(width, height, components) ;
+    LLImageBase::setDataAndSize(data, width * height * components) ;
 }
 
 bool LLImageRaw::resize(U16 width, U16 height, S8 components)
 {
-	if ((getWidth() == width) && (getHeight() == height) && (getComponents() == components) && !isBufferInvalid())
-	{
-		return true;
-	}
-	// Reallocate the data buffer.
-	deleteData();
+    if ((getWidth() == width) && (getHeight() == height) && (getComponents() == components) && !isBufferInvalid())
+    {
+        return true;
+    }
+    // Reallocate the data buffer.
+    deleteData();
 
-	allocateDataSize(width,height,components);
+    allocateDataSize(width,height,components);
 
-	return !isBufferInvalid();
+    return !isBufferInvalid();
 }
 
 bool LLImageRaw::setSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height,
-							 const U8 *data, U32 stride, bool reverse_y)
+                             const U8 *data, U32 stride, bool reverse_y)
 {
-	if (!getData())
-	{
-		return false;
-	}
-	if (!data)
-	{
-		return false;
-	}
+    if (!getData())
+    {
+        return false;
+    }
+    if (!data)
+    {
+        return false;
+    }
 
-	// Should do some simple bounds checking
+    // Should do some simple bounds checking
 
-	U32 i;
-	for (i = 0; i < height; i++)
-	{
-		const U32 row = reverse_y ? height - 1 - i : i;
-		const U32 from_offset = row * ((stride == 0) ? width*getComponents() : stride);
-		const U32 to_offset = (y_pos + i)*getWidth() + x_pos;
-		memcpy(getData() + to_offset*getComponents(),		/* Flawfinder: ignore */
-				data + from_offset, getComponents()*width);
-	}
+    U32 i;
+    for (i = 0; i < height; i++)
+    {
+        const U32 row = reverse_y ? height - 1 - i : i;
+        const U32 from_offset = row * ((stride == 0) ? width*getComponents() : stride);
+        const U32 to_offset = (y_pos + i)*getWidth() + x_pos;
+        memcpy(getData() + to_offset*getComponents(),       /* Flawfinder: ignore */
+                data + from_offset, getComponents()*width);
+    }
 
-	return true;
+    return true;
 }
 
 void LLImageRaw::clear(U8 r, U8 g, U8 b, U8 a)
 {
-	llassert( getComponents() <= 4 );
-	// This is fairly bogus, but it'll do for now.
-	if (isBufferInvalid())
-	{
-		LL_WARNS() << "Invalid image buffer" << LL_ENDL;
-		return;
-	}
-
-	U8 *pos = getData();
-	U32 x, y;
-	for (x = 0; x < getWidth(); x++)
-	{
-		for (y = 0; y < getHeight(); y++)
-		{
-			*pos = r;
-			pos++;
-			if (getComponents() == 1)
-			{
-				continue;
-			}
-			*pos = g;
-			pos++;
-			if (getComponents() == 2)
-			{
-				continue;
-			}
-			*pos = b;
-			pos++;
-			if (getComponents() == 3)
-			{
-				continue;
-			}
-			*pos = a;
-			pos++;
-		}
-	}
+    llassert( getComponents() <= 4 );
+    // This is fairly bogus, but it'll do for now.
+    if (isBufferInvalid())
+    {
+        LL_WARNS() << "Invalid image buffer" << LL_ENDL;
+        return;
+    }
+
+    U8 *pos = getData();
+    U32 x, y;
+    for (x = 0; x < getWidth(); x++)
+    {
+        for (y = 0; y < getHeight(); y++)
+        {
+            *pos = r;
+            pos++;
+            if (getComponents() == 1)
+            {
+                continue;
+            }
+            *pos = g;
+            pos++;
+            if (getComponents() == 2)
+            {
+                continue;
+            }
+            *pos = b;
+            pos++;
+            if (getComponents() == 3)
+            {
+                continue;
+            }
+            *pos = a;
+            pos++;
+        }
+    }
 }
 
 // Reverses the order of the rows in the image
 void LLImageRaw::verticalFlip()
 {
-	S32 row_bytes = getWidth() * getComponents();
-	llassert(row_bytes > 0);
-	std::vector<U8> line_buffer(row_bytes);
-	S32 mid_row = getHeight() / 2;
-	for( S32 row = 0; row < mid_row; row++ )
-	{
-		U8* row_a_data = getData() + row * row_bytes;
-		U8* row_b_data = getData() + (getHeight() - 1 - row) * row_bytes;
-		memcpy( &line_buffer[0], row_a_data,  row_bytes );
-		memcpy( row_a_data,  row_b_data,  row_bytes );
-		memcpy( row_b_data,  &line_buffer[0], row_bytes );
-	}
+    S32 row_bytes = getWidth() * getComponents();
+    llassert(row_bytes > 0);
+    std::vector<U8> line_buffer(row_bytes);
+    S32 mid_row = getHeight() / 2;
+    for( S32 row = 0; row < mid_row; row++ )
+    {
+        U8* row_a_data = getData() + row * row_bytes;
+        U8* row_b_data = getData() + (getHeight() - 1 - row) * row_bytes;
+        memcpy( &line_buffer[0], row_a_data,  row_bytes );
+        memcpy( row_a_data,  row_b_data,  row_bytes );
+        memcpy( row_b_data,  &line_buffer[0], row_bytes );
+    }
 }
 
 
@@ -1077,275 +1077,275 @@ bool LLImageRaw::makeAlpha()
 
 void LLImageRaw::expandToPowerOfTwo(S32 max_dim, bool scale_image)
 {
-	// Find new sizes
-	S32 new_width  = expandDimToPowerOfTwo(getWidth(), max_dim);
-	S32 new_height = expandDimToPowerOfTwo(getHeight(), max_dim);
+    // Find new sizes
+    S32 new_width  = expandDimToPowerOfTwo(getWidth(), max_dim);
+    S32 new_height = expandDimToPowerOfTwo(getHeight(), max_dim);
 
-	scale( new_width, new_height, scale_image );
+    scale( new_width, new_height, scale_image );
 }
 
 void LLImageRaw::contractToPowerOfTwo(S32 max_dim, bool scale_image)
 {
-	// Find new sizes
-	S32 new_width  = contractDimToPowerOfTwo(getWidth(), MIN_IMAGE_SIZE);
-	S32 new_height = contractDimToPowerOfTwo(getHeight(), MIN_IMAGE_SIZE);
+    // Find new sizes
+    S32 new_width  = contractDimToPowerOfTwo(getWidth(), MIN_IMAGE_SIZE);
+    S32 new_height = contractDimToPowerOfTwo(getHeight(), MIN_IMAGE_SIZE);
 
-	scale( new_width, new_height, scale_image );
+    scale( new_width, new_height, scale_image );
 }
 
 // static
 S32 LLImageRaw::biasedDimToPowerOfTwo(S32 curr_dim, S32 max_dim)
 {
-	// Strong bias towards rounding down (to save bandwidth)
-	// No bias would mean THRESHOLD == 1.5f;
-	const F32 THRESHOLD = 1.75f;
-    
-	// Find new sizes
-	S32 larger_dim  = max_dim;	// 2^n >= curr_dim
-	S32 smaller_dim = max_dim;	// 2^(n-1) <= curr_dim
-	while( (smaller_dim > curr_dim) && (smaller_dim > MIN_IMAGE_SIZE) )
-	{
-		larger_dim = smaller_dim;
-		smaller_dim >>= 1;
-	}
-	return ( ((F32)curr_dim / (F32)smaller_dim) > THRESHOLD ) ? larger_dim : smaller_dim;
+    // Strong bias towards rounding down (to save bandwidth)
+    // No bias would mean THRESHOLD == 1.5f;
+    const F32 THRESHOLD = 1.75f;
+
+    // Find new sizes
+    S32 larger_dim  = max_dim;  // 2^n >= curr_dim
+    S32 smaller_dim = max_dim;  // 2^(n-1) <= curr_dim
+    while( (smaller_dim > curr_dim) && (smaller_dim > MIN_IMAGE_SIZE) )
+    {
+        larger_dim = smaller_dim;
+        smaller_dim >>= 1;
+    }
+    return ( ((F32)curr_dim / (F32)smaller_dim) > THRESHOLD ) ? larger_dim : smaller_dim;
 }
 
 // static
 S32 LLImageRaw::expandDimToPowerOfTwo(S32 curr_dim, S32 max_dim)
 {
-	S32 new_dim = MIN_IMAGE_SIZE;
-	while( (new_dim < curr_dim) && (new_dim < max_dim) )
-	{
-		new_dim <<= 1;
-	}
+    S32 new_dim = MIN_IMAGE_SIZE;
+    while( (new_dim < curr_dim) && (new_dim < max_dim) )
+    {
+        new_dim <<= 1;
+    }
     return new_dim;
 }
 
 // static
 S32 LLImageRaw::contractDimToPowerOfTwo(S32 curr_dim, S32 min_dim)
 {
-	S32 new_dim = MAX_IMAGE_SIZE;
-	while( (new_dim > curr_dim) && (new_dim > min_dim) )
-	{
-		new_dim >>= 1;
-	}
+    S32 new_dim = MAX_IMAGE_SIZE;
+    while( (new_dim > curr_dim) && (new_dim > min_dim) )
+    {
+        new_dim >>= 1;
+    }
     return new_dim;
 }
 
 void LLImageRaw::biasedScaleToPowerOfTwo(S32 max_dim)
 {
-	// Find new sizes
-	S32 new_width  = biasedDimToPowerOfTwo(getWidth(),max_dim);
-	S32 new_height = biasedDimToPowerOfTwo(getHeight(),max_dim);
+    // Find new sizes
+    S32 new_width  = biasedDimToPowerOfTwo(getWidth(),max_dim);
+    S32 new_height = biasedDimToPowerOfTwo(getHeight(),max_dim);
 
-	scale( new_width, new_height );
+    scale( new_width, new_height );
 }
 
 // Calculates (U8)(255*(a/255.f)*(b/255.f) + 0.5f).  Thanks, Jim Blinn!
 inline U8 LLImageRaw::fastFractionalMult( U8 a, U8 b )
 {
-	U32 i = a * b + 128;
-	return U8((i + (i>>8)) >> 8);
+    U32 i = a * b + 128;
+    return U8((i + (i>>8)) >> 8);
 }
 
 
 void LLImageRaw::composite( LLImageRaw* src )
 {
-	LLImageRaw* dst = this;  // Just for clarity.
-
-	if (!validateSrcAndDst("LLImageRaw::composite", src, dst))
-	{
-		return;
-	}
-
-	llassert((3 == src->getComponents()) || (4 == src->getComponents()));
-	llassert(3 == dst->getComponents());
-
-	if( 3 == dst->getComponents() )
-	{
-		if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) )
-		{
-			// No scaling needed
-			if( 3 == src->getComponents() )
-			{
-				copyUnscaled( src );  // alpha is one so just copy the data.
-			}
-			else
-			{
-				compositeUnscaled4onto3( src );
-			}
-		}
-		else
-		{
-			if( 3 == src->getComponents() )
-			{
-				copyScaled( src );  // alpha is one so just copy the data.
-			}
-			else
-			{
-				compositeScaled4onto3( src );
-			}
-		}
-	}
+    LLImageRaw* dst = this;  // Just for clarity.
+
+    if (!validateSrcAndDst("LLImageRaw::composite", src, dst))
+    {
+        return;
+    }
+
+    llassert((3 == src->getComponents()) || (4 == src->getComponents()));
+    llassert(3 == dst->getComponents());
+
+    if( 3 == dst->getComponents() )
+    {
+        if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) )
+        {
+            // No scaling needed
+            if( 3 == src->getComponents() )
+            {
+                copyUnscaled( src );  // alpha is one so just copy the data.
+            }
+            else
+            {
+                compositeUnscaled4onto3( src );
+            }
+        }
+        else
+        {
+            if( 3 == src->getComponents() )
+            {
+                copyScaled( src );  // alpha is one so just copy the data.
+            }
+            else
+            {
+                compositeScaled4onto3( src );
+            }
+        }
+    }
 }
 
 
 // Src and dst can be any size.  Src has 4 components.  Dst has 3 components.
 void LLImageRaw::compositeScaled4onto3(LLImageRaw* src)
 {
-	LL_INFOS() << "compositeScaled4onto3" << LL_ENDL;
+    LL_INFOS() << "compositeScaled4onto3" << LL_ENDL;
 
-	LLImageRaw* dst = this;  // Just for clarity.
+    LLImageRaw* dst = this;  // Just for clarity.
 
-	llassert( (4 == src->getComponents()) && (3 == dst->getComponents()) );
+    llassert( (4 == src->getComponents()) && (3 == dst->getComponents()) );
 
-	S32 temp_data_size = src->getWidth() * dst->getHeight() * src->getComponents();
-	llassert(temp_data_size > 0);
-	std::vector<U8> temp_buffer(temp_data_size);
+    S32 temp_data_size = src->getWidth() * dst->getHeight() * src->getComponents();
+    llassert(temp_data_size > 0);
+    std::vector<U8> temp_buffer(temp_data_size);
 
-	// Vertical: scale but no composite
-	for( S32 col = 0; col < src->getWidth(); col++ )
-	{
-		copyLineScaled( src->getData() + (src->getComponents() * col), &temp_buffer[0] + (src->getComponents() * col), src->getHeight(), dst->getHeight(), src->getWidth(), src->getWidth() );
-	}
+    // Vertical: scale but no composite
+    for( S32 col = 0; col < src->getWidth(); col++ )
+    {
+        copyLineScaled( src->getData() + (src->getComponents() * col), &temp_buffer[0] + (src->getComponents() * col), src->getHeight(), dst->getHeight(), src->getWidth(), src->getWidth() );
+    }
 
-	// Horizontal: scale and composite
-	for( S32 row = 0; row < dst->getHeight(); row++ )
-	{
-		compositeRowScaled4onto3( &temp_buffer[0] + (src->getComponents() * src->getWidth() * row), dst->getData() + (dst->getComponents() * dst->getWidth() * row), src->getWidth(), dst->getWidth() );
-	}
+    // Horizontal: scale and composite
+    for( S32 row = 0; row < dst->getHeight(); row++ )
+    {
+        compositeRowScaled4onto3( &temp_buffer[0] + (src->getComponents() * src->getWidth() * row), dst->getData() + (dst->getComponents() * dst->getWidth() * row), src->getWidth(), dst->getWidth() );
+    }
 }
 
 
 // Src and dst are same size.  Src has 4 components.  Dst has 3 components.
 void LLImageRaw::compositeUnscaled4onto3( LLImageRaw* src )
 {
-	LLImageRaw* dst = this;  // Just for clarity.
-
-	llassert( (4 == src->getComponents()) || (3 == dst->getComponents()) );
-	llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
-
-	U8* src_data = src->getData();
-	U8* dst_data = dst->getData();
-	S32 pixels = getWidth() * getHeight();
-
-	if(!src_data)
-	{
-		LL_WARNS() << "source is null!" << LL_ENDL;
-		return;
-	}
-	if(!dst_data)
-	{
-		LL_WARNS() << "destination is null!" << LL_ENDL;
-		return;
-	}
-	auto src_comps = src->getComponents();
-	if( src_comps != 4)
-	{
-		// This should never be reached, buit apparently it is.
-		LL_WARNS() << "src has incorrect number of layers (" << src_comps << ")" << LL_ENDL;
-		return;
-	}
-
-	while( pixels-- )
-	{
-		U8 alpha = src_data[3];
-		if( alpha )
-		{
-			if( 255 == alpha )
-			{
-				dst_data[0] = src_data[0];
-				dst_data[1] = src_data[1];
-				dst_data[2] = src_data[2];
-			}
-			else
-			{
-
-				U8 transparency = 255 - alpha;
-				dst_data[0] = fastFractionalMult( dst_data[0], transparency ) + fastFractionalMult( src_data[0], alpha );
-				dst_data[1] = fastFractionalMult( dst_data[1], transparency ) + fastFractionalMult( src_data[1], alpha );
-				dst_data[2] = fastFractionalMult( dst_data[2], transparency ) + fastFractionalMult( src_data[2], alpha );
-			}
-		}
-
-		src_data += 4;
-		dst_data += 3;
-	}
+    LLImageRaw* dst = this;  // Just for clarity.
+
+    llassert( (4 == src->getComponents()) || (3 == dst->getComponents()) );
+    llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
+
+    U8* src_data = src->getData();
+    U8* dst_data = dst->getData();
+    S32 pixels = getWidth() * getHeight();
+
+    if(!src_data)
+    {
+        LL_WARNS() << "source is null!" << LL_ENDL;
+        return;
+    }
+    if(!dst_data)
+    {
+        LL_WARNS() << "destination is null!" << LL_ENDL;
+        return;
+    }
+    auto src_comps = src->getComponents();
+    if( src_comps != 4)
+    {
+        // This should never be reached, buit apparently it is.
+        LL_WARNS() << "src has incorrect number of layers (" << src_comps << ")" << LL_ENDL;
+        return;
+    }
+
+    while( pixels-- )
+    {
+        U8 alpha = src_data[3];
+        if( alpha )
+        {
+            if( 255 == alpha )
+            {
+                dst_data[0] = src_data[0];
+                dst_data[1] = src_data[1];
+                dst_data[2] = src_data[2];
+            }
+            else
+            {
+
+                U8 transparency = 255 - alpha;
+                dst_data[0] = fastFractionalMult( dst_data[0], transparency ) + fastFractionalMult( src_data[0], alpha );
+                dst_data[1] = fastFractionalMult( dst_data[1], transparency ) + fastFractionalMult( src_data[1], alpha );
+                dst_data[2] = fastFractionalMult( dst_data[2], transparency ) + fastFractionalMult( src_data[2], alpha );
+            }
+        }
+
+        src_data += 4;
+        dst_data += 3;
+    }
 }
 
 
 void LLImageRaw::copyUnscaledAlphaMask( LLImageRaw* src, const LLColor4U& fill)
 {
-	LLImageRaw* dst = this;  // Just for clarity.
+    LLImageRaw* dst = this;  // Just for clarity.
 
-	if (!validateSrcAndDst("LLImageRaw::copyUnscaledAlphaMask", src, dst))
-	{
-		return;
-	}
+    if (!validateSrcAndDst("LLImageRaw::copyUnscaledAlphaMask", src, dst))
+    {
+        return;
+    }
 
-	llassert( 1 == src->getComponents() );
-	llassert( 4 == dst->getComponents() );
-	llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
+    llassert( 1 == src->getComponents() );
+    llassert( 4 == dst->getComponents() );
+    llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
 
-	S32 pixels = getWidth() * getHeight();
-	U8* src_data = src->getData();
-	U8* dst_data = dst->getData();
-	for ( S32 i = 0; i < pixels; i++ )
-	{
-		dst_data[0] = fill.mV[0];
-		dst_data[1] = fill.mV[1];
-		dst_data[2] = fill.mV[2];
-		dst_data[3] = src_data[0];
-		src_data += 1;
-		dst_data += 4;
-	}
+    S32 pixels = getWidth() * getHeight();
+    U8* src_data = src->getData();
+    U8* dst_data = dst->getData();
+    for ( S32 i = 0; i < pixels; i++ )
+    {
+        dst_data[0] = fill.mV[0];
+        dst_data[1] = fill.mV[1];
+        dst_data[2] = fill.mV[2];
+        dst_data[3] = src_data[0];
+        src_data += 1;
+        dst_data += 4;
+    }
 }
 
 
 // Fill the buffer with a constant color
 void LLImageRaw::fill( const LLColor4U& color )
 {
-	if (isBufferInvalid())
-	{
-		LL_WARNS() << "Invalid image buffer" << LL_ENDL;
-		return;
-	}
-
-	S32 pixels = getWidth() * getHeight();
-	if( 4 == getComponents() )
-	{
-		U32* data = (U32*) getData();
-		U32 rgbaColor = color.asRGBA();
-		for( S32 i = 0; i < pixels; i++ )
-		{
-			data[ i ] = rgbaColor;
-		}
-	}
-	else
-	if( 3 == getComponents() )
-	{
-		U8* data = getData();
-		for( S32 i = 0; i < pixels; i++ )
-		{
-			data[0] = color.mV[0];
-			data[1] = color.mV[1];
-			data[2] = color.mV[2];
-			data += 3;
-		}
-	}
+    if (isBufferInvalid())
+    {
+        LL_WARNS() << "Invalid image buffer" << LL_ENDL;
+        return;
+    }
+
+    S32 pixels = getWidth() * getHeight();
+    if( 4 == getComponents() )
+    {
+        U32* data = (U32*) getData();
+        U32 rgbaColor = color.asRGBA();
+        for( S32 i = 0; i < pixels; i++ )
+        {
+            data[ i ] = rgbaColor;
+        }
+    }
+    else
+    if( 3 == getComponents() )
+    {
+        U8* data = getData();
+        for( S32 i = 0; i < pixels; i++ )
+        {
+            data[0] = color.mV[0];
+            data[1] = color.mV[1];
+            data[2] = color.mV[2];
+            data += 3;
+        }
+    }
 }
 
 void LLImageRaw::tint( const LLColor3& color )
 {
-	llassert( (3 == getComponents()) || (4 == getComponents()) );
-	if (isBufferInvalid())
-	{
-		LL_WARNS() << "Invalid image buffer" << LL_ENDL;
-		return;
-	}
+    llassert( (3 == getComponents()) || (4 == getComponents()) );
+    if (isBufferInvalid())
+    {
+        LL_WARNS() << "Invalid image buffer" << LL_ENDL;
+        return;
+    }
 
-	S32 pixels = getWidth() * getHeight();
+    S32 pixels = getWidth() * getHeight();
     const S32 components = getComponents();
     U8* data = getData();
     for( S32 i = 0; i < pixels; i++ )
@@ -1362,188 +1362,188 @@ void LLImageRaw::tint( const LLColor3& color )
 
 LLPointer<LLImageRaw> LLImageRaw::duplicate()
 {
-	if(getNumRefs() < 2)
-	{
-		return this; //nobody else refences to this image, no need to duplicate.
-	}
+    if(getNumRefs() < 2)
+    {
+        return this; //nobody else refences to this image, no need to duplicate.
+    }
 
-	//make a duplicate
-	LLPointer<LLImageRaw> dup = new LLImageRaw(getData(), getWidth(), getHeight(), getComponents());
-	return dup; 
+    //make a duplicate
+    LLPointer<LLImageRaw> dup = new LLImageRaw(getData(), getWidth(), getHeight(), getComponents());
+    return dup;
 }
 
 // Src and dst can be any size.  Src and dst can each have 3 or 4 components.
 void LLImageRaw::copy(LLImageRaw* src)
 {
-	LLImageRaw* dst = this;  // Just for clarity.
-
-	if (!validateSrcAndDst("LLImageRaw::copy", src, dst))
-	{
-		return;
-	}
-
-	if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) )
-	{
-		// No scaling needed
-		if( src->getComponents() == dst->getComponents() )
-		{
-			copyUnscaled( src );
-		}
-		else
-		if( 3 == src->getComponents() )
-		{
-			copyUnscaled3onto4( src );
-		}
-		else
-		{
-			// 4 == src->getComponents()
-			copyUnscaled4onto3( src );
-		}
-	}
-	else
-	{
-		// Scaling needed
-		// No scaling needed
-		if( src->getComponents() == dst->getComponents() )
-		{
-			copyScaled( src );
-		}
-		else
-		if( 3 == src->getComponents() )
-		{
-			copyScaled3onto4( src );
-		}
-		else
-		{
-			// 4 == src->getComponents()
-			copyScaled4onto3( src );
-		}
-	}
+    LLImageRaw* dst = this;  // Just for clarity.
+
+    if (!validateSrcAndDst("LLImageRaw::copy", src, dst))
+    {
+        return;
+    }
+
+    if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) )
+    {
+        // No scaling needed
+        if( src->getComponents() == dst->getComponents() )
+        {
+            copyUnscaled( src );
+        }
+        else
+        if( 3 == src->getComponents() )
+        {
+            copyUnscaled3onto4( src );
+        }
+        else
+        {
+            // 4 == src->getComponents()
+            copyUnscaled4onto3( src );
+        }
+    }
+    else
+    {
+        // Scaling needed
+        // No scaling needed
+        if( src->getComponents() == dst->getComponents() )
+        {
+            copyScaled( src );
+        }
+        else
+        if( 3 == src->getComponents() )
+        {
+            copyScaled3onto4( src );
+        }
+        else
+        {
+            // 4 == src->getComponents()
+            copyScaled4onto3( src );
+        }
+    }
 }
 
 // Src and dst are same size.  Src and dst have same number of components.
 void LLImageRaw::copyUnscaled(LLImageRaw* src)
 {
-	LLImageRaw* dst = this;  // Just for clarity.
+    LLImageRaw* dst = this;  // Just for clarity.
 
-	llassert( (1 == src->getComponents()) || (3 == src->getComponents()) || (4 == src->getComponents()) );
-	llassert( src->getComponents() == dst->getComponents() );
-	llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
+    llassert( (1 == src->getComponents()) || (3 == src->getComponents()) || (4 == src->getComponents()) );
+    llassert( src->getComponents() == dst->getComponents() );
+    llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
 
-	memcpy( dst->getData(), src->getData(), getWidth() * getHeight() * getComponents() );	/* Flawfinder: ignore */
+    memcpy( dst->getData(), src->getData(), getWidth() * getHeight() * getComponents() );   /* Flawfinder: ignore */
 }
 
 
 // Src and dst can be any size.  Src has 3 components.  Dst has 4 components.
 void LLImageRaw::copyScaled3onto4(LLImageRaw* src)
 {
-	llassert( (3 == src->getComponents()) && (4 == getComponents()) );
+    llassert( (3 == src->getComponents()) && (4 == getComponents()) );
 
-	// Slow, but simple.  Optimize later if needed.
-	LLImageRaw temp( src->getWidth(), src->getHeight(), 4);
-	temp.copyUnscaled3onto4( src );
-	copyScaled( &temp );
+    // Slow, but simple.  Optimize later if needed.
+    LLImageRaw temp( src->getWidth(), src->getHeight(), 4);
+    temp.copyUnscaled3onto4( src );
+    copyScaled( &temp );
 }
 
 
 // Src and dst can be any size.  Src has 4 components.  Dst has 3 components.
 void LLImageRaw::copyScaled4onto3(LLImageRaw* src)
 {
-	llassert( (4 == src->getComponents()) && (3 == getComponents()) );
+    llassert( (4 == src->getComponents()) && (3 == getComponents()) );
 
-	// Slow, but simple.  Optimize later if needed.
-	LLImageRaw temp( src->getWidth(), src->getHeight(), 3);
-	temp.copyUnscaled4onto3( src );
-	copyScaled( &temp );
+    // Slow, but simple.  Optimize later if needed.
+    LLImageRaw temp( src->getWidth(), src->getHeight(), 3);
+    temp.copyUnscaled4onto3( src );
+    copyScaled( &temp );
 }
 
 
 // Src and dst are same size.  Src has 4 components.  Dst has 3 components.
 void LLImageRaw::copyUnscaled4onto3( LLImageRaw* src )
 {
-	LLImageRaw* dst = this;  // Just for clarity.
+    LLImageRaw* dst = this;  // Just for clarity.
 
-	llassert( (3 == dst->getComponents()) && (4 == src->getComponents()) );
-	llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
+    llassert( (3 == dst->getComponents()) && (4 == src->getComponents()) );
+    llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
 
-	S32 pixels = getWidth() * getHeight();
-	U8* src_data = src->getData();
-	U8* dst_data = dst->getData();
-	for( S32 i=0; i<pixels; i++ )
-	{
-		dst_data[0] = src_data[0];
-		dst_data[1] = src_data[1];
-		dst_data[2] = src_data[2];
-		src_data += 4;
-		dst_data += 3;
-	}
+    S32 pixels = getWidth() * getHeight();
+    U8* src_data = src->getData();
+    U8* dst_data = dst->getData();
+    for( S32 i=0; i<pixels; i++ )
+    {
+        dst_data[0] = src_data[0];
+        dst_data[1] = src_data[1];
+        dst_data[2] = src_data[2];
+        src_data += 4;
+        dst_data += 3;
+    }
 }
 
 
 // Src and dst are same size.  Src has 3 components.  Dst has 4 components.
 void LLImageRaw::copyUnscaled3onto4( LLImageRaw* src )
 {
-	LLImageRaw* dst = this;  // Just for clarity.
-	llassert( 3 == src->getComponents() );
-	llassert( 4 == dst->getComponents() );
-	llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
+    LLImageRaw* dst = this;  // Just for clarity.
+    llassert( 3 == src->getComponents() );
+    llassert( 4 == dst->getComponents() );
+    llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
 
-	S32 pixels = getWidth() * getHeight();
-	U8* src_data = src->getData();
-	U8* dst_data = dst->getData();
-	for( S32 i=0; i<pixels; i++ )
-	{
-		dst_data[0] = src_data[0];
-		dst_data[1] = src_data[1];
-		dst_data[2] = src_data[2];
-		dst_data[3] = 255;
-		src_data += 3;
-		dst_data += 4;
-	}
+    S32 pixels = getWidth() * getHeight();
+    U8* src_data = src->getData();
+    U8* dst_data = dst->getData();
+    for( S32 i=0; i<pixels; i++ )
+    {
+        dst_data[0] = src_data[0];
+        dst_data[1] = src_data[1];
+        dst_data[2] = src_data[2];
+        dst_data[3] = 255;
+        src_data += 3;
+        dst_data += 4;
+    }
 }
 
 
 // Src and dst can be any size.  Src and dst have same number of components.
 void LLImageRaw::copyScaled( LLImageRaw* src )
 {
-	LLImageRaw* dst = this;  // Just for clarity.
+    LLImageRaw* dst = this;  // Just for clarity.
 
-	if (!validateSrcAndDst("LLImageRaw::copyScaled", src, dst))
-	{
-		return;
-	}
+    if (!validateSrcAndDst("LLImageRaw::copyScaled", src, dst))
+    {
+        return;
+    }
 
-	llassert_always( (1 == src->getComponents()) || (3 == src->getComponents()) || (4 == src->getComponents()) );
-	llassert_always( src->getComponents() == dst->getComponents() );
+    llassert_always( (1 == src->getComponents()) || (3 == src->getComponents()) || (4 == src->getComponents()) );
+    llassert_always( src->getComponents() == dst->getComponents() );
 
-	if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) )
-	{
-		memcpy( dst->getData(), src->getData(), getWidth() * getHeight() * getComponents() );	/* Flawfinder: ignore */
-		return;
-	}
+    if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) )
+    {
+        memcpy( dst->getData(), src->getData(), getWidth() * getHeight() * getComponents() );   /* Flawfinder: ignore */
+        return;
+    }
 
-	bilinear_scale(
-			src->getData(), src->getWidth(), src->getHeight(), src->getComponents(), src->getWidth()*src->getComponents()
-		,	dst->getData(), dst->getWidth(), dst->getHeight(), dst->getComponents(), dst->getWidth()*dst->getComponents()
-	);
+    bilinear_scale(
+            src->getData(), src->getWidth(), src->getHeight(), src->getComponents(), src->getWidth()*src->getComponents()
+        ,   dst->getData(), dst->getWidth(), dst->getHeight(), dst->getComponents(), dst->getWidth()*dst->getComponents()
+    );
 
-	/*
-	S32 temp_data_size = src->getWidth() * dst->getHeight() * getComponents();
-	llassert_always(temp_data_size > 0);
-	std::vector<U8> temp_buffer(temp_data_size);
+    /*
+    S32 temp_data_size = src->getWidth() * dst->getHeight() * getComponents();
+    llassert_always(temp_data_size > 0);
+    std::vector<U8> temp_buffer(temp_data_size);
 
-	// Vertical
-	for( S32 col = 0; col < src->getWidth(); col++ )
-	{
-		copyLineScaled( src->getData() + (getComponents() * col), &temp_buffer[0] + (getComponents() * col), src->getHeight(), dst->getHeight(), src->getWidth(), src->getWidth() );
-	}
+    // Vertical
+    for( S32 col = 0; col < src->getWidth(); col++ )
+    {
+        copyLineScaled( src->getData() + (getComponents() * col), &temp_buffer[0] + (getComponents() * col), src->getHeight(), dst->getHeight(), src->getWidth(), src->getWidth() );
+    }
 
-	// Horizontal
-	for( S32 row = 0; row < dst->getHeight(); row++ )
-	{
-		copyLineScaled( &temp_buffer[0] + (getComponents() * src->getWidth() * row), dst->getData() + (getComponents() * dst->getWidth() * row), src->getWidth(), dst->getWidth(), 1, 1 );
-	}
-	*/
+    // Horizontal
+    for( S32 row = 0; row < dst->getHeight(); row++ )
+    {
+        copyLineScaled( &temp_buffer[0] + (getComponents() * src->getWidth() * row), dst->getData() + (getComponents() * dst->getWidth() * row), src->getWidth(), dst->getWidth(), 1, 1 );
+    }
+    */
 }
 
 
@@ -1556,82 +1556,82 @@ bool LLImageRaw::scale( S32 new_width, S32 new_height, bool scale_image_data )
         return false;
     }
 
-	if (isBufferInvalid())
-	{
-		LL_WARNS() << "Invalid image buffer" << LL_ENDL;
-		return false;
-	}
+    if (isBufferInvalid())
+    {
+        LL_WARNS() << "Invalid image buffer" << LL_ENDL;
+        return false;
+    }
 
-	S32 old_width = getWidth();
-	S32 old_height = getHeight();
-	
-	if( (old_width == new_width) && (old_height == new_height) )
-	{
-		return true;  // Nothing to do.
-	}
+    S32 old_width = getWidth();
+    S32 old_height = getHeight();
 
-	// Reallocate the data buffer.
+    if( (old_width == new_width) && (old_height == new_height) )
+    {
+        return true;  // Nothing to do.
+    }
 
-	if (scale_image_data)
-	{
-		S32 new_data_size = new_width * new_height * components;
+    // Reallocate the data buffer.
 
-		if (new_data_size > 0)
+    if (scale_image_data)
+    {
+        S32 new_data_size = new_width * new_height * components;
+
+        if (new_data_size > 0)
         {
-            U8 *new_data = (U8*)ll_aligned_malloc_16(new_data_size); 
-            if(NULL == new_data) 
+            U8 *new_data = (U8*)ll_aligned_malloc_16(new_data_size);
+            if(NULL == new_data)
             {
-                return false; 
+                return false;
             }
 
             bilinear_scale(getData(), old_width, old_height, components, old_width*components, new_data, new_width, new_height, components, new_width*components);
-            setDataAndSize(new_data, new_width, new_height, components); 
-		}
-	}
-	else 
-	{
-		try
-		{
-			// copy	out	existing image data
-			S32	temp_data_size = old_width * old_height * components;
-			std::vector<U8> temp_buffer(temp_data_size);
-			memcpy(&temp_buffer[0], getData(), temp_data_size);
-
-			// allocate	new	image data,	will delete	old	data
-			U8* new_buffer = allocateDataSize(new_width, new_height, components);
-
-			if (!new_buffer)
-			{
-				LL_WARNS() << "Failed to allocate new image data buffer" << LL_ENDL;
-				return false;
-			}
-
-			for (S32 row = 0; row < new_height; row++)
-			{
-				if (row < old_height)
-				{
-					memcpy(new_buffer + (new_width * row * components), &temp_buffer[0] + (old_width * row * components), components * llmin(old_width, new_width));
-					if (old_width < new_width)
-					{
-						// pad out rest	of row with	black
-						memset(new_buffer + (components * ((new_width * row) + old_width)), 0, components * (new_width - old_width));
-					}
-				}
-				else
-				{
-					// pad remaining rows with black
-					memset(new_buffer + (new_width * row * components), 0, new_width * components);
-				}
-			}
-		}
-		catch (const std::bad_alloc&) // for temp_buffer
-		{
-			LL_WARNS() << "Failed to allocate temporary image buffer" << LL_ENDL;
-			return false;
-		}
-	}
-
-	return true ;
+            setDataAndSize(new_data, new_width, new_height, components);
+        }
+    }
+    else
+    {
+        try
+        {
+            // copy out existing image data
+            S32 temp_data_size = old_width * old_height * components;
+            std::vector<U8> temp_buffer(temp_data_size);
+            memcpy(&temp_buffer[0], getData(), temp_data_size);
+
+            // allocate new image data, will delete old data
+            U8* new_buffer = allocateDataSize(new_width, new_height, components);
+
+            if (!new_buffer)
+            {
+                LL_WARNS() << "Failed to allocate new image data buffer" << LL_ENDL;
+                return false;
+            }
+
+            for (S32 row = 0; row < new_height; row++)
+            {
+                if (row < old_height)
+                {
+                    memcpy(new_buffer + (new_width * row * components), &temp_buffer[0] + (old_width * row * components), components * llmin(old_width, new_width));
+                    if (old_width < new_width)
+                    {
+                        // pad out rest of row with black
+                        memset(new_buffer + (components * ((new_width * row) + old_width)), 0, components * (new_width - old_width));
+                    }
+                }
+                else
+                {
+                    // pad remaining rows with black
+                    memset(new_buffer + (new_width * row * components), 0, new_width * components);
+                }
+            }
+        }
+        catch (const std::bad_alloc&) // for temp_buffer
+        {
+            LL_WARNS() << "Failed to allocate temporary image buffer" << LL_ENDL;
+            return false;
+        }
+    }
+
+    return true ;
 }
 
 LLPointer<LLImageRaw> LLImageRaw::scaled(S32 new_width, S32 new_height)
@@ -1685,253 +1685,253 @@ LLPointer<LLImageRaw> LLImageRaw::scaled(S32 new_width, S32 new_height)
 
 void LLImageRaw::copyLineScaled( U8* in, U8* out, S32 in_pixel_len, S32 out_pixel_len, S32 in_pixel_step, S32 out_pixel_step )
 {
-	const S32 components = getComponents();
-	llassert( components >= 1 && components <= 4 );
-
-	const F32 ratio = F32(in_pixel_len) / out_pixel_len; // ratio of old to new
-	const F32 norm_factor = 1.f / ratio;
-
-	S32 goff = components >= 2 ? 1 : 0;
-	S32 boff = components >= 3 ? 2 : 0;
-	for( S32 x = 0; x < out_pixel_len; x++ )
-	{
-		// Sample input pixels in range from sample0 to sample1.
-		// Avoid floating point accumulation error... don't just add ratio each time.  JC
-		const F32 sample0 = x * ratio;
-		const F32 sample1 = (x+1) * ratio;
-		const S32 index0 = llfloor(sample0);			// left integer (floor)
-		const S32 index1 = llfloor(sample1);			// right integer (floor)
-		const F32 fract0 = 1.f - (sample0 - F32(index0));	// spill over on left
-		const F32 fract1 = sample1 - F32(index1);			// spill-over on right
-
-		if( index0 == index1 )
-		{
-			// Interval is embedded in one input pixel
-			S32 t0 = x * out_pixel_step * components;
-			S32 t1 = index0 * in_pixel_step * components;
-			U8* outp = out + t0;
-			U8* inp = in + t1;
-			for (S32 i = 0; i < components; ++i)
-			{
-				*outp = *inp;
-				++outp;
-				++inp;
-			}
-		}
-		else
-		{
-			// Left straddle
-			S32 t1 = index0 * in_pixel_step * components;
-			F32 r = in[t1 + 0] * fract0;
-			F32 g = in[t1 + goff] * fract0;
-			F32 b = in[t1 + boff] * fract0;
-			F32 a = 0;
-			if( components == 4)
-			{
-				a = in[t1 + 3] * fract0;
-			}
-		
-			// Central interval
-			if (components < 4)
-			{
-				for( S32 u = index0 + 1; u < index1; u++ )
-				{
-					S32 t2 = u * in_pixel_step * components;
-					r += in[t2 + 0];
-					g += in[t2 + goff];
-					b += in[t2 + boff];
-				}
-			}
-			else
-			{
-				for( S32 u = index0 + 1; u < index1; u++ )
-				{
-					S32 t2 = u * in_pixel_step * components;
-					r += in[t2 + 0];
-					g += in[t2 + 1];
-					b += in[t2 + 2];
-					a += in[t2 + 3];
-				}
-			}
-
-			// right straddle
-			// Watch out for reading off of end of input array.
-			if( fract1 && index1 < in_pixel_len )
-			{
-				S32 t3 = index1 * in_pixel_step * components;
-				if (components < 4)
-				{
-					U8 in0 = in[t3 + 0];
-					U8 in1 = in[t3 + goff];
-					U8 in2 = in[t3 + boff];
-					r += in0 * fract1;
-					g += in1 * fract1;
-					b += in2 * fract1;
-				}
-				else
-				{
-					U8 in0 = in[t3 + 0];
-					U8 in1 = in[t3 + 1];
-					U8 in2 = in[t3 + 2];
-					U8 in3 = in[t3 + 3];
-					r += in0 * fract1;
-					g += in1 * fract1;
-					b += in2 * fract1;
-					a += in3 * fract1;
-				}
-			}
-
-			r *= norm_factor;
-			g *= norm_factor;
-			b *= norm_factor;
-			a *= norm_factor;  // skip conditional
-
-			S32 t4 = x * out_pixel_step * components;
-			out[t4 + 0] = U8(ll_round(r));
-			if (components >= 2)
-				out[t4 + 1] = U8(ll_round(g));
-			if (components >= 3)
-				out[t4 + 2] = U8(ll_round(b));
-			if( components == 4)
-				out[t4 + 3] = U8(ll_round(a));
-		}
-	}
+    const S32 components = getComponents();
+    llassert( components >= 1 && components <= 4 );
+
+    const F32 ratio = F32(in_pixel_len) / out_pixel_len; // ratio of old to new
+    const F32 norm_factor = 1.f / ratio;
+
+    S32 goff = components >= 2 ? 1 : 0;
+    S32 boff = components >= 3 ? 2 : 0;
+    for( S32 x = 0; x < out_pixel_len; x++ )
+    {
+        // Sample input pixels in range from sample0 to sample1.
+        // Avoid floating point accumulation error... don't just add ratio each time.  JC
+        const F32 sample0 = x * ratio;
+        const F32 sample1 = (x+1) * ratio;
+        const S32 index0 = llfloor(sample0);            // left integer (floor)
+        const S32 index1 = llfloor(sample1);            // right integer (floor)
+        const F32 fract0 = 1.f - (sample0 - F32(index0));   // spill over on left
+        const F32 fract1 = sample1 - F32(index1);           // spill-over on right
+
+        if( index0 == index1 )
+        {
+            // Interval is embedded in one input pixel
+            S32 t0 = x * out_pixel_step * components;
+            S32 t1 = index0 * in_pixel_step * components;
+            U8* outp = out + t0;
+            U8* inp = in + t1;
+            for (S32 i = 0; i < components; ++i)
+            {
+                *outp = *inp;
+                ++outp;
+                ++inp;
+            }
+        }
+        else
+        {
+            // Left straddle
+            S32 t1 = index0 * in_pixel_step * components;
+            F32 r = in[t1 + 0] * fract0;
+            F32 g = in[t1 + goff] * fract0;
+            F32 b = in[t1 + boff] * fract0;
+            F32 a = 0;
+            if( components == 4)
+            {
+                a = in[t1 + 3] * fract0;
+            }
+
+            // Central interval
+            if (components < 4)
+            {
+                for( S32 u = index0 + 1; u < index1; u++ )
+                {
+                    S32 t2 = u * in_pixel_step * components;
+                    r += in[t2 + 0];
+                    g += in[t2 + goff];
+                    b += in[t2 + boff];
+                }
+            }
+            else
+            {
+                for( S32 u = index0 + 1; u < index1; u++ )
+                {
+                    S32 t2 = u * in_pixel_step * components;
+                    r += in[t2 + 0];
+                    g += in[t2 + 1];
+                    b += in[t2 + 2];
+                    a += in[t2 + 3];
+                }
+            }
+
+            // right straddle
+            // Watch out for reading off of end of input array.
+            if( fract1 && index1 < in_pixel_len )
+            {
+                S32 t3 = index1 * in_pixel_step * components;
+                if (components < 4)
+                {
+                    U8 in0 = in[t3 + 0];
+                    U8 in1 = in[t3 + goff];
+                    U8 in2 = in[t3 + boff];
+                    r += in0 * fract1;
+                    g += in1 * fract1;
+                    b += in2 * fract1;
+                }
+                else
+                {
+                    U8 in0 = in[t3 + 0];
+                    U8 in1 = in[t3 + 1];
+                    U8 in2 = in[t3 + 2];
+                    U8 in3 = in[t3 + 3];
+                    r += in0 * fract1;
+                    g += in1 * fract1;
+                    b += in2 * fract1;
+                    a += in3 * fract1;
+                }
+            }
+
+            r *= norm_factor;
+            g *= norm_factor;
+            b *= norm_factor;
+            a *= norm_factor;  // skip conditional
+
+            S32 t4 = x * out_pixel_step * components;
+            out[t4 + 0] = U8(ll_round(r));
+            if (components >= 2)
+                out[t4 + 1] = U8(ll_round(g));
+            if (components >= 3)
+                out[t4 + 2] = U8(ll_round(b));
+            if( components == 4)
+                out[t4 + 3] = U8(ll_round(a));
+        }
+    }
 }
 
 void LLImageRaw::compositeRowScaled4onto3( U8* in, U8* out, S32 in_pixel_len, S32 out_pixel_len )
 {
-	llassert( getComponents() == 3 );
-
-	const S32 IN_COMPONENTS = 4;
-	const S32 OUT_COMPONENTS = 3;
-
-	const F32 ratio = F32(in_pixel_len) / out_pixel_len; // ratio of old to new
-	const F32 norm_factor = 1.f / ratio;
-
-	for( S32 x = 0; x < out_pixel_len; x++ )
-	{
-		// Sample input pixels in range from sample0 to sample1.
-		// Avoid floating point accumulation error... don't just add ratio each time.  JC
-		const F32 sample0 = x * ratio;
-		const F32 sample1 = (x+1) * ratio;
-		const S32 index0 = S32(sample0);			// left integer (floor)
-		const S32 index1 = S32(sample1);			// right integer (floor)
-		const F32 fract0 = 1.f - (sample0 - F32(index0));	// spill over on left
-		const F32 fract1 = sample1 - F32(index1);			// spill-over on right
-
-		U8 in_scaled_r;
-		U8 in_scaled_g;
-		U8 in_scaled_b;
-		U8 in_scaled_a;
-
-		if( index0 == index1 )
-		{
-			// Interval is embedded in one input pixel
-			S32 t1 = index0 * IN_COMPONENTS;
-			in_scaled_r = in[t1 + 0];
-			in_scaled_g = in[t1 + 0];
-			in_scaled_b = in[t1 + 0];
-			in_scaled_a = in[t1 + 0];
-		}
-		else
-		{
-			// Left straddle
-			S32 t1 = index0 * IN_COMPONENTS;
-			F32 r = in[t1 + 0] * fract0;
-			F32 g = in[t1 + 1] * fract0;
-			F32 b = in[t1 + 2] * fract0;
-			F32 a = in[t1 + 3] * fract0;
-		
-			// Central interval
-			for( S32 u = index0 + 1; u < index1; u++ )
-			{
-				S32 t2 = u * IN_COMPONENTS;
-				r += in[t2 + 0];
-				g += in[t2 + 1];
-				b += in[t2 + 2];
-				a += in[t2 + 3];
-			}
-
-			// right straddle
-			// Watch out for reading off of end of input array.
-			if( fract1 && index1 < in_pixel_len )
-			{
-				S32 t3 = index1 * IN_COMPONENTS;
-				r += in[t3 + 0] * fract1;
-				g += in[t3 + 1] * fract1;
-				b += in[t3 + 2] * fract1;
-				a += in[t3 + 3] * fract1;
-			}
-
-			r *= norm_factor;
-			g *= norm_factor;
-			b *= norm_factor;
-			a *= norm_factor;
-
-			in_scaled_r = U8(ll_round(r));
-			in_scaled_g = U8(ll_round(g));
-			in_scaled_b = U8(ll_round(b));
-			in_scaled_a = U8(ll_round(a));
-		}
-
-		if( in_scaled_a )
-		{
-			if( 255 == in_scaled_a )
-			{
-				out[0] = in_scaled_r;
-				out[1] = in_scaled_g;
-				out[2] = in_scaled_b;
-			}
-			else
-			{
-				U8 transparency = 255 - in_scaled_a;
-				out[0] = fastFractionalMult( out[0], transparency ) + fastFractionalMult( in_scaled_r, in_scaled_a );
-				out[1] = fastFractionalMult( out[1], transparency ) + fastFractionalMult( in_scaled_g, in_scaled_a );
-				out[2] = fastFractionalMult( out[2], transparency ) + fastFractionalMult( in_scaled_b, in_scaled_a );
-			}
-		}
-		out += OUT_COMPONENTS;
-	}
+    llassert( getComponents() == 3 );
+
+    const S32 IN_COMPONENTS = 4;
+    const S32 OUT_COMPONENTS = 3;
+
+    const F32 ratio = F32(in_pixel_len) / out_pixel_len; // ratio of old to new
+    const F32 norm_factor = 1.f / ratio;
+
+    for( S32 x = 0; x < out_pixel_len; x++ )
+    {
+        // Sample input pixels in range from sample0 to sample1.
+        // Avoid floating point accumulation error... don't just add ratio each time.  JC
+        const F32 sample0 = x * ratio;
+        const F32 sample1 = (x+1) * ratio;
+        const S32 index0 = S32(sample0);            // left integer (floor)
+        const S32 index1 = S32(sample1);            // right integer (floor)
+        const F32 fract0 = 1.f - (sample0 - F32(index0));   // spill over on left
+        const F32 fract1 = sample1 - F32(index1);           // spill-over on right
+
+        U8 in_scaled_r;
+        U8 in_scaled_g;
+        U8 in_scaled_b;
+        U8 in_scaled_a;
+
+        if( index0 == index1 )
+        {
+            // Interval is embedded in one input pixel
+            S32 t1 = index0 * IN_COMPONENTS;
+            in_scaled_r = in[t1 + 0];
+            in_scaled_g = in[t1 + 0];
+            in_scaled_b = in[t1 + 0];
+            in_scaled_a = in[t1 + 0];
+        }
+        else
+        {
+            // Left straddle
+            S32 t1 = index0 * IN_COMPONENTS;
+            F32 r = in[t1 + 0] * fract0;
+            F32 g = in[t1 + 1] * fract0;
+            F32 b = in[t1 + 2] * fract0;
+            F32 a = in[t1 + 3] * fract0;
+
+            // Central interval
+            for( S32 u = index0 + 1; u < index1; u++ )
+            {
+                S32 t2 = u * IN_COMPONENTS;
+                r += in[t2 + 0];
+                g += in[t2 + 1];
+                b += in[t2 + 2];
+                a += in[t2 + 3];
+            }
+
+            // right straddle
+            // Watch out for reading off of end of input array.
+            if( fract1 && index1 < in_pixel_len )
+            {
+                S32 t3 = index1 * IN_COMPONENTS;
+                r += in[t3 + 0] * fract1;
+                g += in[t3 + 1] * fract1;
+                b += in[t3 + 2] * fract1;
+                a += in[t3 + 3] * fract1;
+            }
+
+            r *= norm_factor;
+            g *= norm_factor;
+            b *= norm_factor;
+            a *= norm_factor;
+
+            in_scaled_r = U8(ll_round(r));
+            in_scaled_g = U8(ll_round(g));
+            in_scaled_b = U8(ll_round(b));
+            in_scaled_a = U8(ll_round(a));
+        }
+
+        if( in_scaled_a )
+        {
+            if( 255 == in_scaled_a )
+            {
+                out[0] = in_scaled_r;
+                out[1] = in_scaled_g;
+                out[2] = in_scaled_b;
+            }
+            else
+            {
+                U8 transparency = 255 - in_scaled_a;
+                out[0] = fastFractionalMult( out[0], transparency ) + fastFractionalMult( in_scaled_r, in_scaled_a );
+                out[1] = fastFractionalMult( out[1], transparency ) + fastFractionalMult( in_scaled_g, in_scaled_a );
+                out[2] = fastFractionalMult( out[2], transparency ) + fastFractionalMult( in_scaled_b, in_scaled_a );
+            }
+        }
+        out += OUT_COMPONENTS;
+    }
 }
 
 
 void LLImageRaw::addEmissive(LLImageRaw* src)
 {
-	LLImageRaw* dst = this;  // Just for clarity.
+    LLImageRaw* dst = this;  // Just for clarity.
 
-	if (!validateSrcAndDst(__FUNCTION__, src, dst))
-	{
-		return;
-	}
+    if (!validateSrcAndDst(__FUNCTION__, src, dst))
+    {
+        return;
+    }
 
-	llassert((3 == src->getComponents()) || (4 == src->getComponents()));
-	llassert(3 == dst->getComponents());
+    llassert((3 == src->getComponents()) || (4 == src->getComponents()));
+    llassert(3 == dst->getComponents());
 
-	if( 3 == dst->getComponents() )
-	{
-		if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) )
-		{
+    if( 3 == dst->getComponents() )
+    {
+        if( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) )
+        {
             addEmissiveUnscaled(src);
-		}
-		else
-		{
+        }
+        else
+        {
             addEmissiveScaled(src);
-		}
-	}
+        }
+    }
 }
 
 void LLImageRaw::addEmissiveUnscaled(LLImageRaw* src)
 {
-	LLImageRaw* dst = this;  // Just for clarity.
+    LLImageRaw* dst = this;  // Just for clarity.
 
-	llassert((3 == src->getComponents()) || (4 == src->getComponents()));
-	llassert((3 == dst->getComponents()) || (4 == dst->getComponents()));
-	llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
+    llassert((3 == src->getComponents()) || (4 == src->getComponents()));
+    llassert((3 == dst->getComponents()) || (4 == dst->getComponents()));
+    llassert( (src->getWidth() == dst->getWidth()) && (src->getHeight() == dst->getHeight()) );
 
     U8* const src_data = src->getData();
     U8* const dst_data = dst->getData();
-	for(S32 y = 0; y < dst->getHeight(); ++y)
-	{
+    for(S32 y = 0; y < dst->getHeight(); ++y)
+    {
         const S32 src_row_offset = src->getComponents() * src->getWidth() * y;
         const S32 dst_row_offset = dst->getComponents() * dst->getWidth() * y;
         for (S32 x = 0; x < dst->getWidth(); ++x)
@@ -1944,17 +1944,17 @@ void LLImageRaw::addEmissiveUnscaled(LLImageRaw* src)
             dst_pixel[1] = llmin(255, dst_pixel[1] + src_pixel[1]);
             dst_pixel[2] = llmin(255, dst_pixel[2] + src_pixel[2]);
         }
-	}
+    }
 }
 
 void LLImageRaw::addEmissiveScaled(LLImageRaw* src)
 {
-	LLImageRaw* dst = this;  // Just for clarity.
+    LLImageRaw* dst = this;  // Just for clarity.
 
-	llassert( (4 == src->getComponents()) && (3 == dst->getComponents()) );
+    llassert( (4 == src->getComponents()) && (3 == dst->getComponents()) );
 
     LLImageRaw temp(dst->getWidth(), dst->getHeight(), dst->getComponents());
-	llassert_always(temp.getDataSize() > 0);
+    llassert_always(temp.getDataSize() > 0);
     temp.copyScaled(src);
 
     dst->addEmissiveUnscaled(&temp);
@@ -1963,156 +1963,156 @@ void LLImageRaw::addEmissiveScaled(LLImageRaw* src)
 
 bool LLImageRaw::validateSrcAndDst(std::string func, LLImageRaw* src, LLImageRaw* dst)
 {
-	if (!src || !dst || src->isBufferInvalid() || dst->isBufferInvalid())
-	{
-		LL_WARNS() << func << ": Source: ";
-		if (!src) LL_CONT << "Null pointer";
-		else if (src->isBufferInvalid()) LL_CONT << "Invalid buffer";
-		else LL_CONT << "OK";
+    if (!src || !dst || src->isBufferInvalid() || dst->isBufferInvalid())
+    {
+        LL_WARNS() << func << ": Source: ";
+        if (!src) LL_CONT << "Null pointer";
+        else if (src->isBufferInvalid()) LL_CONT << "Invalid buffer";
+        else LL_CONT << "OK";
 
-		LL_CONT << "; Destination: ";
-		if (!dst) LL_CONT << "Null pointer";
-		else if (dst->isBufferInvalid()) LL_CONT << "Invalid buffer";
-		else LL_CONT << "OK";
-		LL_CONT << "." << LL_ENDL;
+        LL_CONT << "; Destination: ";
+        if (!dst) LL_CONT << "Null pointer";
+        else if (dst->isBufferInvalid()) LL_CONT << "Invalid buffer";
+        else LL_CONT << "OK";
+        LL_CONT << "." << LL_ENDL;
 
-		return false;
-	}
-	return true;
+        return false;
+    }
+    return true;
 }
 
 //----------------------------------------------------------------------------
 std::array<std::pair<const char*, EImageCodec>, 11> file_extensions =
 { {
-	{ "bmp", IMG_CODEC_BMP },
-	{ "tga", IMG_CODEC_TGA },
-	{ "j2c", IMG_CODEC_J2C },
-	{ "jp2", IMG_CODEC_J2C },
-	{ "texture", IMG_CODEC_J2C },
-	{ "jpg", IMG_CODEC_JPEG },
-	{ "jpeg", IMG_CODEC_JPEG },
-	{ "mip", IMG_CODEC_DXT },
-	{ "dxt", IMG_CODEC_DXT },
-	{ "png", IMG_CODEC_PNG },
-	{ "webp", IMG_CODEC_WEBP }
+    { "bmp", IMG_CODEC_BMP },
+    { "tga", IMG_CODEC_TGA },
+    { "j2c", IMG_CODEC_J2C },
+    { "jp2", IMG_CODEC_J2C },
+    { "texture", IMG_CODEC_J2C },
+    { "jpg", IMG_CODEC_JPEG },
+    { "jpeg", IMG_CODEC_JPEG },
+    { "mip", IMG_CODEC_DXT },
+    { "dxt", IMG_CODEC_DXT },
+    { "png", IMG_CODEC_PNG },
+    { "webp", IMG_CODEC_WEBP }
 } };
 
 #if 0
 static std::string find_file(std::string &name, S8 *codec)
 {
-	std::string tname;
-	for (int i=0; i<(int)(NUM_FILE_EXTENSIONS); i++)
-	{
-		tname = name + "." + std::string(file_extensions[i].exten);
-		llifstream ifs(tname.c_str(), llifstream::binary);
-		if (ifs.is_open())
-		{
-			ifs.close();
-			if (codec)
-				*codec = file_extensions[i].codec;
-			return std::string(file_extensions[i].exten);
-		}
-	}
-	return std::string("");
+    std::string tname;
+    for (int i=0; i<(int)(NUM_FILE_EXTENSIONS); i++)
+    {
+        tname = name + "." + std::string(file_extensions[i].exten);
+        llifstream ifs(tname.c_str(), llifstream::binary);
+        if (ifs.is_open())
+        {
+            ifs.close();
+            if (codec)
+                *codec = file_extensions[i].codec;
+            return std::string(file_extensions[i].exten);
+        }
+    }
+    return std::string("");
 }
 #endif
 EImageCodec LLImageBase::getCodecFromExtension(const std::string& exten)
 {
-	if (!exten.empty())
-	{
-		for (const auto& exten_pair : file_extensions)
-		{
-			if (exten == exten_pair.first)
-				return exten_pair.second;
-		}
-	}
-	return IMG_CODEC_INVALID;
+    if (!exten.empty())
+    {
+        for (const auto& exten_pair : file_extensions)
+        {
+            if (exten == exten_pair.first)
+                return exten_pair.second;
+        }
+    }
+    return IMG_CODEC_INVALID;
 }
 #if 0
 bool LLImageRaw::createFromFile(const std::string &filename, bool j2c_lowest_mip_only)
 {
-	std::string name = filename;
-	size_t dotidx = name.rfind('.');
-	S8 codec = IMG_CODEC_INVALID;
-	std::string exten;
-	
-	deleteData(); // delete any existing data
-
-	if (dotidx != std::string::npos)
-	{
-		exten = name.substr(dotidx+1);
-		LLStringUtil::toLower(exten);
-		codec = getCodecFromExtension(exten);
-	}
-	else
-	{
-		exten = find_file(name, &codec);
-		name = name + "." + exten;
-	}
-	if (codec == IMG_CODEC_INVALID)
-	{
-		return false; // format not recognized
-	}
-
-	llifstream ifs(name.c_str(), llifstream::binary);
-	if (!ifs.is_open())
-	{
-		// SJB: changed from LL_INFOS() to LL_DEBUGS() to reduce spam
-		LL_DEBUGS() << "Unable to open image file: " << name << LL_ENDL;
-		return false;
-	}
-	
-	ifs.seekg (0, std::ios::end);
-	int length = ifs.tellg();
-	if (j2c_lowest_mip_only && length > 2048)
-	{
-		length = 2048;
-	}
-	ifs.seekg (0, std::ios::beg);
-
-	if (!length)
-	{
-		LL_INFOS() << "Zero length file file: " << name << LL_ENDL;
-		return false;
-	}
-	
-	LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
-	llassert(image.notNull());
-
-	U8 *buffer = image->allocateData(length);
-	ifs.read ((char*)buffer, length);
-	ifs.close();
-	
-	bool success;
-
-	success = image->updateData();
-	if (success)
-	{
-		if (j2c_lowest_mip_only && codec == IMG_CODEC_J2C)
-		{
-			S32 width = image->getWidth();
-			S32 height = image->getHeight();
-			S32 discard_level = 0;
-			while (width > 1 && height > 1 && discard_level < MAX_DISCARD_LEVEL)
-			{
-				width >>= 1;
-				height >>= 1;
-				discard_level++;
-			}
-			((LLImageJ2C *)((LLImageFormatted*)image))->setDiscardLevel(discard_level);
-		}
-		success = image->decode(this, 100000.0f);
-	}
-
-	image = NULL; // deletes image
-	if (!success)
-	{
-		deleteData();
-		LL_WARNS() << "Unable to decode image" << name << LL_ENDL;
-		return false;
-	}
-
-	return true;
+    std::string name = filename;
+    size_t dotidx = name.rfind('.');
+    S8 codec = IMG_CODEC_INVALID;
+    std::string exten;
+
+    deleteData(); // delete any existing data
+
+    if (dotidx != std::string::npos)
+    {
+        exten = name.substr(dotidx+1);
+        LLStringUtil::toLower(exten);
+        codec = getCodecFromExtension(exten);
+    }
+    else
+    {
+        exten = find_file(name, &codec);
+        name = name + "." + exten;
+    }
+    if (codec == IMG_CODEC_INVALID)
+    {
+        return false; // format not recognized
+    }
+
+    llifstream ifs(name.c_str(), llifstream::binary);
+    if (!ifs.is_open())
+    {
+        // SJB: changed from LL_INFOS() to LL_DEBUGS() to reduce spam
+        LL_DEBUGS() << "Unable to open image file: " << name << LL_ENDL;
+        return false;
+    }
+
+    ifs.seekg (0, std::ios::end);
+    int length = ifs.tellg();
+    if (j2c_lowest_mip_only && length > 2048)
+    {
+        length = 2048;
+    }
+    ifs.seekg (0, std::ios::beg);
+
+    if (!length)
+    {
+        LL_INFOS() << "Zero length file file: " << name << LL_ENDL;
+        return false;
+    }
+
+    LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
+    llassert(image.notNull());
+
+    U8 *buffer = image->allocateData(length);
+    ifs.read ((char*)buffer, length);
+    ifs.close();
+
+    bool success;
+
+    success = image->updateData();
+    if (success)
+    {
+        if (j2c_lowest_mip_only && codec == IMG_CODEC_J2C)
+        {
+            S32 width = image->getWidth();
+            S32 height = image->getHeight();
+            S32 discard_level = 0;
+            while (width > 1 && height > 1 && discard_level < MAX_DISCARD_LEVEL)
+            {
+                width >>= 1;
+                height >>= 1;
+                discard_level++;
+            }
+            ((LLImageJ2C *)((LLImageFormatted*)image))->setDiscardLevel(discard_level);
+        }
+        success = image->decode(this, 100000.0f);
+    }
+
+    image = NULL; // deletes image
+    if (!success)
+    {
+        deleteData();
+        LL_WARNS() << "Unable to decode image" << name << LL_ENDL;
+        return false;
+    }
+
+    return true;
 }
 #endif
 //---------------------------------------------------------------------------
@@ -2123,21 +2123,21 @@ bool LLImageRaw::createFromFile(const std::string &filename, bool j2c_lowest_mip
 S64 LLImageFormatted::sGlobalFormattedMemory = 0;
 
 LLImageFormatted::LLImageFormatted(S8 codec)
-	: LLImageBase(),
-	  mCodec(codec),
-	  mDecoding(0),
-	  mDecoded(0),
-	  mDiscardLevel(-1),
-	  mLevels(0)
+    : LLImageBase(),
+      mCodec(codec),
+      mDecoding(0),
+      mDecoded(0),
+      mDiscardLevel(-1),
+      mLevels(0)
 {
 }
 
 // virtual
 LLImageFormatted::~LLImageFormatted()
 {
-	// NOTE: ~LLimageBase() call to deleteData() calls LLImageBase::deleteData()
-	//        NOT LLImageFormatted::deleteData()
-	deleteData();
+    // NOTE: ~LLimageBase() call to deleteData() calls LLImageBase::deleteData()
+    //        NOT LLImageFormatted::deleteData()
+    deleteData();
 }
 
 //----------------------------------------------------------------------------
@@ -2145,16 +2145,16 @@ LLImageFormatted::~LLImageFormatted()
 //virtual
 void LLImageFormatted::resetLastError()
 {
-	LLImage::setLastError("");
+    LLImage::setLastError("");
 }
 
 //virtual
 void LLImageFormatted::setLastError(const std::string& message, const std::string& filename)
 {
-	std::string error = message;
-	if (!filename.empty())
-		error += std::string(" FILE: ") + filename;
-	LLImage::setLastError(error);
+    std::string error = message;
+    if (!filename.empty())
+        error += std::string(" FILE: ") + filename;
+    LLImage::setLastError(error);
 }
 
 //----------------------------------------------------------------------------
@@ -2162,100 +2162,100 @@ void LLImageFormatted::setLastError(const std::string& message, const std::strin
 // static
 LLImageFormatted* LLImageFormatted::createFromType(S8 codec)
 {
-	LLImageFormatted* image;
-	switch(codec)
-	{
-	  case IMG_CODEC_BMP:
-		image = new LLImageBMP();
-		break;
-	  case IMG_CODEC_TGA:
-		image = new LLImageTGA();
-		break;
-	  case IMG_CODEC_JPEG:
-		image = new LLImageJPEG();
-		break;
-	  case IMG_CODEC_PNG:
-		image = new LLImagePNG();
-		break;
-	  case IMG_CODEC_WEBP:
-		image = new LLImageWebP();
-		break;
-	  case IMG_CODEC_J2C:
-		image = new LLImageJ2C();
-		break;
-	  case IMG_CODEC_DXT:
-		image = new LLImageDXT();
-		break;
-	  default:
-		image = NULL;
-		break;
-	}
-	return image;
+    LLImageFormatted* image;
+    switch(codec)
+    {
+      case IMG_CODEC_BMP:
+        image = new LLImageBMP();
+        break;
+      case IMG_CODEC_TGA:
+        image = new LLImageTGA();
+        break;
+      case IMG_CODEC_JPEG:
+        image = new LLImageJPEG();
+        break;
+      case IMG_CODEC_PNG:
+        image = new LLImagePNG();
+        break;
+      case IMG_CODEC_WEBP:
+        image = new LLImageWebP();
+        break;
+      case IMG_CODEC_J2C:
+        image = new LLImageJ2C();
+        break;
+      case IMG_CODEC_DXT:
+        image = new LLImageDXT();
+        break;
+      default:
+        image = NULL;
+        break;
+    }
+    return image;
 }
 
 // static
 LLImageFormatted* LLImageFormatted::createFromExtension(const std::string& instring)
 {
-	std::string exten;
-	size_t dotidx = instring.rfind('.');
-	if (dotidx != std::string::npos)
-	{
-		exten = instring.substr(dotidx+1);
-	}
-	else
-	{
-		exten = instring;
-	}
-	S8 codec = getCodecFromExtension(exten);
-	return createFromType(codec);
+    std::string exten;
+    size_t dotidx = instring.rfind('.');
+    if (dotidx != std::string::npos)
+    {
+        exten = instring.substr(dotidx+1);
+    }
+    else
+    {
+        exten = instring;
+    }
+    S8 codec = getCodecFromExtension(exten);
+    return createFromType(codec);
 }
 //----------------------------------------------------------------------------
 
 // virtual
 void LLImageFormatted::dump()
 {
-	LLImageBase::dump();
+    LLImageBase::dump();
 
-	LL_INFOS() << "LLImageFormatted"
-			<< " mDecoding " << mDecoding
-			<< " mCodec " << S32(mCodec)
-			<< " mDecoded " << mDecoded
-			<< LL_ENDL;
+    LL_INFOS() << "LLImageFormatted"
+            << " mDecoding " << mDecoding
+            << " mCodec " << S32(mCodec)
+            << " mDecoded " << mDecoded
+            << LL_ENDL;
 }
 
 //----------------------------------------------------------------------------
 
 S32 LLImageFormatted::calcDataSize(S32 discard_level)
 {
-	if (discard_level < 0)
-	{
-		discard_level = mDiscardLevel;
-	}
-	S32 w = getWidth() >> discard_level;
-	S32 h = getHeight() >> discard_level;
-	w = llmax(w, 1);
-	h = llmax(h, 1);
-	return w * h * getComponents();
+    if (discard_level < 0)
+    {
+        discard_level = mDiscardLevel;
+    }
+    S32 w = getWidth() >> discard_level;
+    S32 h = getHeight() >> discard_level;
+    w = llmax(w, 1);
+    h = llmax(h, 1);
+    return w * h * getComponents();
 }
 
 S32 LLImageFormatted::calcDiscardLevelBytes(S32 bytes)
 {
-	llassert(bytes >= 0);
-	S32 discard_level = 0;
-	while (1)
-	{
-		S32 bytes_needed = calcDataSize(discard_level); // virtual
-		if (bytes_needed <= bytes)
-		{
-			break;
-		}
-		discard_level++;
-		if (discard_level > MAX_IMAGE_MIP)
-		{
-			return -1;
-		}
-	}
-	return discard_level;
+    llassert(bytes >= 0);
+    S32 discard_level = 0;
+    while (1)
+    {
+        S32 bytes_needed = calcDataSize(discard_level); // virtual
+        if (bytes_needed <= bytes)
+        {
+            break;
+        }
+        discard_level++;
+        if (discard_level > MAX_IMAGE_MIP)
+        {
+            return -1;
+        }
+    }
+    return discard_level;
 }
 
 
@@ -2264,34 +2264,34 @@ S32 LLImageFormatted::calcDiscardLevelBytes(S32 bytes)
 // Subclasses that can handle more than 4 channels should override this function.
 bool LLImageFormatted::decodeChannels(LLImageRaw* raw_image,F32  decode_time, S32 first_channel, S32 max_channel)
 {
-	llassert( (first_channel == 0) && (max_channel == 4) );
-	return decode( raw_image, decode_time );  // Loads first 4 channels by default.
-} 
+    llassert( (first_channel == 0) && (max_channel == 4) );
+    return decode( raw_image, decode_time );  // Loads first 4 channels by default.
+}
 
 //----------------------------------------------------------------------------
 
 // virtual
 U8* LLImageFormatted::allocateData(S32 size)
 {
-	U8* res = LLImageBase::allocateData(size); // calls deleteData()
-	if(res) sGlobalFormattedMemory += getDataSize();
-	return res;
+    U8* res = LLImageBase::allocateData(size); // calls deleteData()
+    if(res) sGlobalFormattedMemory += getDataSize();
+    return res;
 }
 
 // virtual
 U8* LLImageFormatted::reallocateData(S32 size)
 {
-	sGlobalFormattedMemory -= getDataSize();
-	U8* res = LLImageBase::reallocateData(size);
-	if(res) sGlobalFormattedMemory += getDataSize();
-	return res;
+    sGlobalFormattedMemory -= getDataSize();
+    U8* res = LLImageBase::reallocateData(size);
+    if(res) sGlobalFormattedMemory += getDataSize();
+    return res;
 }
 
 // virtual
 void LLImageFormatted::deleteData()
 {
-	sGlobalFormattedMemory -= getDataSize();
-	LLImageBase::deleteData();
+    sGlobalFormattedMemory -= getDataSize();
+    LLImageBase::deleteData();
 }
 
 //----------------------------------------------------------------------------
@@ -2299,196 +2299,196 @@ void LLImageFormatted::deleteData()
 // virtual
 void LLImageFormatted::sanityCheck()
 {
-	LLImageBase::sanityCheck();
+    LLImageBase::sanityCheck();
 
-	if (mCodec >= IMG_CODEC_EOF)
-	{
-		LL_ERRS() << "Failed LLImageFormatted::sanityCheck "
-			   << "decoding " << S32(mDecoding)
-			   << "decoded " << S32(mDecoded)
-			   << "codec " << S32(mCodec)
-			   << LL_ENDL;
-	}
+    if (mCodec >= IMG_CODEC_EOF)
+    {
+        LL_ERRS() << "Failed LLImageFormatted::sanityCheck "
+               << "decoding " << S32(mDecoding)
+               << "decoded " << S32(mDecoded)
+               << "codec " << S32(mCodec)
+               << LL_ENDL;
+    }
 }
 
 //----------------------------------------------------------------------------
 
 bool LLImageFormatted::copyData(U8 *data, S32 size)
 {
-	if ( data && ((data != getData()) || (size != getDataSize())) )
-	{
-		deleteData();
-		allocateData(size);
-		memcpy(getData(), data, size);	/* Flawfinder: ignore */
-	}
-	return true;
+    if ( data && ((data != getData()) || (size != getDataSize())) )
+    {
+        deleteData();
+        allocateData(size);
+        memcpy(getData(), data, size);  /* Flawfinder: ignore */
+    }
+    return true;
 }
 
 // LLImageFormatted becomes the owner of data
 void LLImageFormatted::setData(U8 *data, S32 size)
 {
-	if (data && data != getData())
-	{
-		deleteData();
-		setDataAndSize(data, size); // Access private LLImageBase members
+    if (data && data != getData())
+    {
+        deleteData();
+        setDataAndSize(data, size); // Access private LLImageBase members
 
-		sGlobalFormattedMemory += getDataSize();
-	}
+        sGlobalFormattedMemory += getDataSize();
+    }
 }
 
 void LLImageFormatted::appendData(U8 *data, S32 size)
 {
-	if (data)
-	{
-		if (!getData())
-		{
-			setData(data, size);
-		}
-		else 
-		{
-			S32 cursize = getDataSize();
-			S32 newsize = cursize + size;
-			reallocateData(newsize);
-			memcpy(getData() + cursize, data, size);
-			ll_aligned_free_16(data);
-		}
-	}
+    if (data)
+    {
+        if (!getData())
+        {
+            setData(data, size);
+        }
+        else
+        {
+            S32 cursize = getDataSize();
+            S32 newsize = cursize + size;
+            reallocateData(newsize);
+            memcpy(getData() + cursize, data, size);
+            ll_aligned_free_16(data);
+        }
+    }
 }
 
 //----------------------------------------------------------------------------
 
 bool LLImageFormatted::load(const std::string &filename, int load_size)
 {
-	resetLastError();
-
-	S32 file_size = 0;
-	LLAPRFile infile ;
-	infile.open(filename, LL_APR_RB, NULL, &file_size);
-	apr_file_t* apr_file = infile.getFileHandle();
-	if (!apr_file)
-	{
-		setLastError("Unable to open file for reading", filename);
-		return false;
-	}
-	if (file_size == 0)
-	{
-		setLastError("File is empty",filename);
-		return false;
-	}
-
-	// Constrain the load size to acceptable values
-	if ((load_size == 0) || (load_size > file_size))
-	{
-		load_size = file_size;
-	}
-	bool res;
-	U8 *data = allocateData(load_size);
-	if (data)
-	{
-		apr_size_t bytes_read = load_size;
-		apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
-		if (s != APR_SUCCESS || (S32) bytes_read != load_size)
-		{
-			deleteData();
-			setLastError("Unable to read file",filename);
-			res = false;
-		}
-		else
-		{
-			res = updateData();
-		}
-	}
-	else
-	{
-		setLastError("Allocation failure", filename);
-		res = false;
-	}
-
-	return res;
+    resetLastError();
+
+    S32 file_size = 0;
+    LLAPRFile infile ;
+    infile.open(filename, LL_APR_RB, NULL, &file_size);
+    apr_file_t* apr_file = infile.getFileHandle();
+    if (!apr_file)
+    {
+        setLastError("Unable to open file for reading", filename);
+        return false;
+    }
+    if (file_size == 0)
+    {
+        setLastError("File is empty",filename);
+        return false;
+    }
+
+    // Constrain the load size to acceptable values
+    if ((load_size == 0) || (load_size > file_size))
+    {
+        load_size = file_size;
+    }
+    bool res;
+    U8 *data = allocateData(load_size);
+    if (data)
+    {
+        apr_size_t bytes_read = load_size;
+        apr_status_t s = apr_file_read(apr_file, data, &bytes_read); // modifies bytes_read
+        if (s != APR_SUCCESS || (S32) bytes_read != load_size)
+        {
+            deleteData();
+            setLastError("Unable to read file",filename);
+            res = false;
+        }
+        else
+        {
+            res = updateData();
+        }
+    }
+    else
+    {
+        setLastError("Allocation failure", filename);
+        res = false;
+    }
+
+    return res;
 }
 
 bool LLImageFormatted::save(const std::string &filename)
 {
-	resetLastError();
-
-	LLAPRFile outfile ;
-	outfile.open(filename, LL_APR_WB);
-	if (!outfile.getFileHandle())
-	{
-		setLastError("Unable to open file for writing", filename);
-		return false;
-	}
-	
-	S32 result = outfile.write(getData(), getDataSize());
-	outfile.close() ;
+    resetLastError();
+
+    LLAPRFile outfile ;
+    outfile.open(filename, LL_APR_WB);
+    if (!outfile.getFileHandle())
+    {
+        setLastError("Unable to open file for writing", filename);
+        return false;
+    }
+
+    S32 result = outfile.write(getData(), getDataSize());
+    outfile.close() ;
     return (result != 0);
 }
 
 S8 LLImageFormatted::getCodec() const
 {
-	return mCodec;
+    return mCodec;
 }
 
 static void avg4_colors4(const U8* a, const U8* b, const U8* c, const U8* d, U8* dst)
 {
-	dst[0] = (U8)(((U32)(a[0]) + b[0] + c[0] + d[0])>>2);
-	dst[1] = (U8)(((U32)(a[1]) + b[1] + c[1] + d[1])>>2);
-	dst[2] = (U8)(((U32)(a[2]) + b[2] + c[2] + d[2])>>2);
-	dst[3] = (U8)(((U32)(a[3]) + b[3] + c[3] + d[3])>>2);
+    dst[0] = (U8)(((U32)(a[0]) + b[0] + c[0] + d[0])>>2);
+    dst[1] = (U8)(((U32)(a[1]) + b[1] + c[1] + d[1])>>2);
+    dst[2] = (U8)(((U32)(a[2]) + b[2] + c[2] + d[2])>>2);
+    dst[3] = (U8)(((U32)(a[3]) + b[3] + c[3] + d[3])>>2);
 }
 
 static void avg4_colors3(const U8* a, const U8* b, const U8* c, const U8* d, U8* dst)
 {
-	dst[0] = (U8)(((U32)(a[0]) + b[0] + c[0] + d[0])>>2);
-	dst[1] = (U8)(((U32)(a[1]) + b[1] + c[1] + d[1])>>2);
-	dst[2] = (U8)(((U32)(a[2]) + b[2] + c[2] + d[2])>>2);
+    dst[0] = (U8)(((U32)(a[0]) + b[0] + c[0] + d[0])>>2);
+    dst[1] = (U8)(((U32)(a[1]) + b[1] + c[1] + d[1])>>2);
+    dst[2] = (U8)(((U32)(a[2]) + b[2] + c[2] + d[2])>>2);
 }
 
 static void avg4_colors2(const U8* a, const U8* b, const U8* c, const U8* d, U8* dst)
 {
-	dst[0] = (U8)(((U32)(a[0]) + b[0] + c[0] + d[0])>>2);
-	dst[1] = (U8)(((U32)(a[1]) + b[1] + c[1] + d[1])>>2);
+    dst[0] = (U8)(((U32)(a[0]) + b[0] + c[0] + d[0])>>2);
+    dst[1] = (U8)(((U32)(a[1]) + b[1] + c[1] + d[1])>>2);
 }
 
 void LLImageBase::setDataAndSize(U8 *data, S32 size)
-{ 
-	ll_assert_aligned(data, 16);
-	mData = data; 
-	mDataSize = size; 
-}	
+{
+    ll_assert_aligned(data, 16);
+    mData = data;
+    mDataSize = size;
+}
 
 //static
 void LLImageBase::generateMip(const U8* indata, U8* mipdata, S32 width, S32 height, S32 nchannels)
 {
-	llassert(width > 0 && height > 0);
-	U8* data = mipdata;
-	S32 in_width = width*2;
-	for (S32 h=0; h<height; h++)
-	{
-		for (S32 w=0; w<width; w++)
-		{
-			switch(nchannels)
-			{
-			  case 4:
-				avg4_colors4(indata, indata+4, indata+4*in_width, indata+4*in_width+4, data);
-				break;
-			  case 3:
-				avg4_colors3(indata, indata+3, indata+3*in_width, indata+3*in_width+3, data);
-				break;
-			  case 2:
-				avg4_colors2(indata, indata+2, indata+2*in_width, indata+2*in_width+2, data);
-				break;
-			  case 1:
-				*(U8*)data = (U8)(((U32)(indata[0]) + indata[1] + indata[in_width] + indata[in_width+1])>>2);
-				break;
-			  default:
-				LL_ERRS() << "generateMmip called with bad num channels" << LL_ENDL;
-			}
-			indata += nchannels*2;
-			data += nchannels;
-		}
-		indata += nchannels*in_width; // skip odd lines
-	}
+    llassert(width > 0 && height > 0);
+    U8* data = mipdata;
+    S32 in_width = width*2;
+    for (S32 h=0; h<height; h++)
+    {
+        for (S32 w=0; w<width; w++)
+        {
+            switch(nchannels)
+            {
+              case 4:
+                avg4_colors4(indata, indata+4, indata+4*in_width, indata+4*in_width+4, data);
+                break;
+              case 3:
+                avg4_colors3(indata, indata+3, indata+3*in_width, indata+3*in_width+3, data);
+                break;
+              case 2:
+                avg4_colors2(indata, indata+2, indata+2*in_width, indata+2*in_width+2, data);
+                break;
+              case 1:
+                *(U8*)data = (U8)(((U32)(indata[0]) + indata[1] + indata[in_width] + indata[in_width+1])>>2);
+                break;
+              default:
+                LL_ERRS() << "generateMmip called with bad num channels" << LL_ENDL;
+            }
+            indata += nchannels*2;
+            data += nchannels;
+        }
+        indata += nchannels*in_width; // skip odd lines
+    }
 }
 
 
@@ -2497,69 +2497,69 @@ void LLImageBase::generateMip(const U8* indata, U8* mipdata, S32 width, S32 heig
 //static
 F32 LLImageBase::calc_download_priority(F32 virtual_size, F32 visible_pixels, S32 bytes_sent)
 {
-	F32 w_priority;
-
-	F32 bytes_weight = 1.f;
-	if (!bytes_sent)
-	{
-		bytes_weight = 20.f;
-	}
-	else if (bytes_sent < 1000)
-	{
-		bytes_weight = 1.f;
-	}
-	else if (bytes_sent < 2000)
-	{
-		bytes_weight = 1.f/1.5f;
-	}
-	else if (bytes_sent < 4000)
-	{
-		bytes_weight = 1.f/3.f;
-	}
-	else if (bytes_sent < 8000)
-	{
-		bytes_weight = 1.f/6.f;
-	}
-	else if (bytes_sent < 16000)
-	{
-		bytes_weight = 1.f/12.f;
-	}
-	else if (bytes_sent < 32000)
-	{
-		bytes_weight = 1.f/20.f;
-	}
-	else if (bytes_sent < 64000)
-	{
-		bytes_weight = 1.f/32.f;
-	}
-	else
-	{
-		bytes_weight = 1.f/64.f;
-	}
-	bytes_weight *= bytes_weight;
-
-
-	//LL_INFOS() << "VS: " << virtual_size << LL_ENDL;
-	F32 virtual_size_factor = virtual_size / (10.f*10.f);
-
-	// The goal is for weighted priority to be <= 0 when we've reached a point where
-	// we've sent enough data.
-	//LL_INFOS() << "BytesSent: " << bytes_sent << LL_ENDL;
-	//LL_INFOS() << "BytesWeight: " << bytes_weight << LL_ENDL;
-	//LL_INFOS() << "PreLog: " << bytes_weight * virtual_size_factor << LL_ENDL;
-	w_priority = (F32)log10(bytes_weight * virtual_size_factor);
-
-	//LL_INFOS() << "PreScale: " << w_priority << LL_ENDL;
-
-	// We don't want to affect how MANY bytes we send based on the visible pixels, but the order
-	// in which they're sent.  We post-multiply so we don't change the zero point.
-	if (w_priority > 0.f)
-	{
-		F32 pixel_weight = (F32)log10(visible_pixels + 1)*3.0f;
-		w_priority *= pixel_weight;
-	}
-
-	return w_priority;
+    F32 w_priority;
+
+    F32 bytes_weight = 1.f;
+    if (!bytes_sent)
+    {
+        bytes_weight = 20.f;
+    }
+    else if (bytes_sent < 1000)
+    {
+        bytes_weight = 1.f;
+    }
+    else if (bytes_sent < 2000)
+    {
+        bytes_weight = 1.f/1.5f;
+    }
+    else if (bytes_sent < 4000)
+    {
+        bytes_weight = 1.f/3.f;
+    }
+    else if (bytes_sent < 8000)
+    {
+        bytes_weight = 1.f/6.f;
+    }
+    else if (bytes_sent < 16000)
+    {
+        bytes_weight = 1.f/12.f;
+    }
+    else if (bytes_sent < 32000)
+    {
+        bytes_weight = 1.f/20.f;
+    }
+    else if (bytes_sent < 64000)
+    {
+        bytes_weight = 1.f/32.f;
+    }
+    else
+    {
+        bytes_weight = 1.f/64.f;
+    }
+    bytes_weight *= bytes_weight;
+
+
+    //LL_INFOS() << "VS: " << virtual_size << LL_ENDL;
+    F32 virtual_size_factor = virtual_size / (10.f*10.f);
+
+    // The goal is for weighted priority to be <= 0 when we've reached a point where
+    // we've sent enough data.
+    //LL_INFOS() << "BytesSent: " << bytes_sent << LL_ENDL;
+    //LL_INFOS() << "BytesWeight: " << bytes_weight << LL_ENDL;
+    //LL_INFOS() << "PreLog: " << bytes_weight * virtual_size_factor << LL_ENDL;
+    w_priority = (F32)log10(bytes_weight * virtual_size_factor);
+
+    //LL_INFOS() << "PreScale: " << w_priority << LL_ENDL;
+
+    // We don't want to affect how MANY bytes we send based on the visible pixels, but the order
+    // in which they're sent.  We post-multiply so we don't change the zero point.
+    if (w_priority > 0.f)
+    {
+        F32 pixel_weight = (F32)log10(visible_pixels + 1)*3.0f;
+        w_priority *= pixel_weight;
+    }
+
+    return w_priority;
 }
 
 //============================================================================
diff --git a/indra/llimage/llimage.h b/indra/llimage/llimage.h
index f5925cdb57541963274f55836b4df59dcdbd68e7..bcfd0a27feb4043655e5e61ae53e4593ab9f9143 100644
--- a/indra/llimage/llimage.h
+++ b/indra/llimage/llimage.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llimage.h
  * @brief Object for managing images and their textures.
  *
  * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -35,21 +35,21 @@
 const S32 MIN_IMAGE_MIP =  2; // 4x4, only used for expand/contract power of 2
 const S32 MAX_IMAGE_MIP = 12; // 4096x4096
 
-// *TODO : Use MAX_IMAGE_MIP as max discard level and modify j2c management so that the number 
+// *TODO : Use MAX_IMAGE_MIP as max discard level and modify j2c management so that the number
 // of levels is read from the header's file, not inferred from its size.
 const S32 MAX_DISCARD_LEVEL = 5;
 
 // JPEG2000 size constraints
 // Those are declared here as they are germane to other image constraints used in the viewer
 // and declared right here. Some come from the JPEG2000 spec, some conventions specific to SL.
-const S32 MAX_DECOMPOSITION_LEVELS = 32;	// Number of decomposition levels cannot exceed 32 according to jpeg2000 spec
-const S32 MIN_DECOMPOSITION_LEVELS = 5;		// the SL viewer will *crash* trying to decode images with fewer than 5 decomposition levels (unless image is small that is)
-const S32 MAX_PRECINCT_SIZE = 4096;			// No reason to be bigger than MAX_IMAGE_SIZE 
-const S32 MIN_PRECINCT_SIZE = 4;			// Can't be smaller than MIN_BLOCK_SIZE
-const S32 MAX_BLOCK_SIZE = 64;				// Max total block size is 4096, hence 64x64 when using square blocks
-const S32 MIN_BLOCK_SIZE = 4;				// Min block dim is 4 according to jpeg2000 spec
-const S32 MIN_LAYER_SIZE = 2000;			// Size of the first quality layer (after header). Must be > to FIRST_PACKET_SIZE!!
-const S32 MAX_NB_LAYERS = 64;				// Max number of layers we'll entertain in SL (practical limit)
+const S32 MAX_DECOMPOSITION_LEVELS = 32;    // Number of decomposition levels cannot exceed 32 according to jpeg2000 spec
+const S32 MIN_DECOMPOSITION_LEVELS = 5;     // the SL viewer will *crash* trying to decode images with fewer than 5 decomposition levels (unless image is small that is)
+const S32 MAX_PRECINCT_SIZE = 4096;         // No reason to be bigger than MAX_IMAGE_SIZE
+const S32 MIN_PRECINCT_SIZE = 4;            // Can't be smaller than MIN_BLOCK_SIZE
+const S32 MAX_BLOCK_SIZE = 64;              // Max total block size is 4096, hence 64x64 when using square blocks
+const S32 MIN_BLOCK_SIZE = 4;               // Min block dim is 4 according to jpeg2000 spec
+const S32 MIN_LAYER_SIZE = 2000;            // Size of the first quality layer (after header). Must be > to FIRST_PACKET_SIZE!!
+const S32 MAX_NB_LAYERS = 64;               // Max number of layers we'll entertain in SL (practical limit)
 
 const S32 MIN_IMAGE_SIZE = (1<<MIN_IMAGE_MIP); // 4, only used for expand/contract power of 2
 const S32 MAX_IMAGE_SIZE = (1<<MAX_IMAGE_MIP); // 4096
@@ -75,16 +75,16 @@ class LLColor3;
 
 typedef enum e_image_codec
 {
-	IMG_CODEC_INVALID  = 0,
-	IMG_CODEC_RGB  = 1,
-	IMG_CODEC_J2C  = 2,
-	IMG_CODEC_BMP  = 3,
-	IMG_CODEC_TGA  = 4,
-	IMG_CODEC_JPEG = 5,
-	IMG_CODEC_DXT  = 6,
-	IMG_CODEC_PNG  = 7,
-	IMG_CODEC_WEBP = 8,
-	IMG_CODEC_EOF  = 9
+    IMG_CODEC_INVALID  = 0,
+    IMG_CODEC_RGB  = 1,
+    IMG_CODEC_J2C  = 2,
+    IMG_CODEC_BMP  = 3,
+    IMG_CODEC_TGA  = 4,
+    IMG_CODEC_JPEG = 5,
+    IMG_CODEC_DXT  = 6,
+    IMG_CODEC_PNG  = 7,
+    IMG_CODEC_WEBP = 8,
+    IMG_CODEC_EOF  = 9
 } EImageCodec;
 
 //============================================================================
@@ -94,120 +94,120 @@ typedef enum e_image_codec
 class LLImage
 {
 public:
-	static void initClass(bool use_new_byte_range = false, S32 minimal_reverse_byte_range_percent = 75);
-	static void cleanupClass();
+    static void initClass(bool use_new_byte_range = false, S32 minimal_reverse_byte_range_percent = 75);
+    static void cleanupClass();
 
     static const std::string& getLastThreadError();
-	static void setLastError(const std::string& message);
-	
-	static bool useNewByteRange() { return sUseNewByteRange; }
-	static S32  getReverseByteRangePercent() { return sMinimalReverseByteRangePercent; }
-	
+    static void setLastError(const std::string& message);
+
+    static bool useNewByteRange() { return sUseNewByteRange; }
+    static S32  getReverseByteRangePercent() { return sMinimalReverseByteRangePercent; }
+
 protected:
     static thread_local std::string sLastThreadErrorMessage;
-	static bool sUseNewByteRange;
+    static bool sUseNewByteRange;
     static S32  sMinimalReverseByteRangePercent;
 };
 
 //============================================================================
 // Image base class
 
-class LLImageBase 
-:	public LLThreadSafeRefCount
+class LLImageBase
+:   public LLThreadSafeRefCount
 {
 protected:
-	virtual ~LLImageBase();
-	
+    virtual ~LLImageBase();
+
 public:
-	LLImageBase();
+    LLImageBase();
 
-	enum
-	{
-		TYPE_NORMAL = 0,
-		TYPE_AVATAR_BAKE = 1,
-	};
+    enum
+    {
+        TYPE_NORMAL = 0,
+        TYPE_AVATAR_BAKE = 1,
+    };
 
-	virtual void deleteData();
-	virtual U8* allocateData(S32 size = -1);
-	virtual U8* reallocateData(S32 size = -1);
+    virtual void deleteData();
+    virtual U8* allocateData(S32 size = -1);
+    virtual U8* reallocateData(S32 size = -1);
 
-	virtual void dump();
-	virtual void sanityCheck();
+    virtual void dump();
+    virtual void sanityCheck();
 
-	U16 getWidth() const		{ return mWidth; }
-	U16 getHeight() const		{ return mHeight; }
-	S8	getComponents() const	{ return mComponents; }
-	S32 getDataSize() const		{ return mDataSize; }
+    U16 getWidth() const        { return mWidth; }
+    U16 getHeight() const       { return mHeight; }
+    S8  getComponents() const   { return mComponents; }
+    S32 getDataSize() const     { return mDataSize; }
 
-	const U8 *getData() const	;
-	U8 *getData()				;
-	bool isBufferInvalid() const;
+    const U8 *getData() const   ;
+    U8 *getData()               ;
+    bool isBufferInvalid() const;
 
-	void setSize(S32 width, S32 height, S32 ncomponents);
-	U8* allocateDataSize(S32 width, S32 height, S32 ncomponents, S32 size = -1); // setSize() + allocateData()
-	void enableOverSize() {mAllowOverSize = true ;}
-	void disableOverSize() {mAllowOverSize = false; }
+    void setSize(S32 width, S32 height, S32 ncomponents);
+    U8* allocateDataSize(S32 width, S32 height, S32 ncomponents, S32 size = -1); // setSize() + allocateData()
+    void enableOverSize() {mAllowOverSize = true ;}
+    void disableOverSize() {mAllowOverSize = false; }
 
 protected:
-	// special accessor to allow direct setting of mData and mDataSize by LLImageFormatted
-	void setDataAndSize(U8 *data, S32 size);
-	
+    // special accessor to allow direct setting of mData and mDataSize by LLImageFormatted
+    void setDataAndSize(U8 *data, S32 size);
+
 public:
-	static void generateMip(const U8 *indata, U8* mipdata, int width, int height, S32 nchannels);
-	
-	// Function for calculating the download priority for textures
-	// <= 0 priority means that there's no need for more data.
-	static F32 calc_download_priority(F32 virtual_size, F32 visible_area, S32 bytes_sent);
+    static void generateMip(const U8 *indata, U8* mipdata, int width, int height, S32 nchannels);
 
-	static EImageCodec getCodecFromExtension(const std::string& exten);
+    // Function for calculating the download priority for textures
+    // <= 0 priority means that there's no need for more data.
+    static F32 calc_download_priority(F32 virtual_size, F32 visible_area, S32 bytes_sent);
+
+    static EImageCodec getCodecFromExtension(const std::string& exten);
 
 private:
-	U8 *mData;
-	S32 mDataSize;
+    U8 *mData;
+    S32 mDataSize;
 
-	U16 mWidth;
-	U16 mHeight;
+    U16 mWidth;
+    U16 mHeight;
 
-	S8 mComponents;
+    S8 mComponents;
 
-	bool mBadBufferAllocation ;
-	bool mAllowOverSize ;
+    bool mBadBufferAllocation ;
+    bool mAllowOverSize ;
 };
 
 // Raw representation of an image (used for textures, and other uncompressed formats
 class LLImageRaw final : public LLImageBase
 {
 protected:
-	/*virtual*/ ~LLImageRaw();
-	
+    /*virtual*/ ~LLImageRaw();
+
 public:
-	LLImageRaw();
-	LLImageRaw(U16 width, U16 height, S8 components);
+    LLImageRaw();
+    LLImageRaw(U16 width, U16 height, S8 components);
     LLImageRaw(const U8* data, U16 width, U16 height, S8 components);
-	LLImageRaw(U8 *data, U16 width, U16 height, S8 components, bool no_copy = false);
-	// Construct using createFromFile (used by tools)
-	//LLImageRaw(const std::string& filename, bool j2c_lowest_mip_only = false);
+    LLImageRaw(U8 *data, U16 width, U16 height, S8 components, bool no_copy = false);
+    // Construct using createFromFile (used by tools)
+    //LLImageRaw(const std::string& filename, bool j2c_lowest_mip_only = false);
 
-	/*virtual*/ void deleteData();
-	/*virtual*/ U8* allocateData(S32 size = -1);
-	/*virtual*/ U8* reallocateData(S32 size);
+    /*virtual*/ void deleteData();
+    /*virtual*/ U8* allocateData(S32 size = -1);
+    /*virtual*/ U8* reallocateData(S32 size);
 
     // use in conjunction with "no_copy" constructor to release data pointer before deleting
-    // so that deletion of this LLImageRaw will not free the memory at the "data" parameter 
+    // so that deletion of this LLImageRaw will not free the memory at the "data" parameter
     // provided to "no_copy" constructor
     void releaseData();
 
-	
-	bool resize(U16 width, U16 height, S8 components);
 
-	//U8 * getSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height) const;
-	bool setSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height,
-					 const U8 *data, U32 stride = 0, bool reverse_y = false);
+    bool resize(U16 width, U16 height, S8 components);
 
-	void clear(U8 r=0, U8 g=0, U8 b=0, U8 a=255);
+    //U8 * getSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height) const;
+    bool setSubImage(U32 x_pos, U32 y_pos, U32 width, U32 height,
+                     const U8 *data, U32 stride = 0, bool reverse_y = false);
+
+    void clear(U8 r=0, U8 g=0, U8 b=0, U8 a=255);
+
+    void verticalFlip();
 
-	void verticalFlip();
-    
     // Returns true if the image is not fully opaque
     bool checkHasTransparentPixels();
     // if the alpha channel is all 100% opaque, delete it
@@ -219,63 +219,63 @@ class LLImageRaw final : public LLImageBase
     static S32 biasedDimToPowerOfTwo(S32 curr_dim, S32 max_dim = MAX_IMAGE_SIZE);
     static S32 expandDimToPowerOfTwo(S32 curr_dim, S32 max_dim = MAX_IMAGE_SIZE);
     static S32 contractDimToPowerOfTwo(S32 curr_dim, S32 min_dim = MIN_IMAGE_SIZE);
-	void expandToPowerOfTwo(S32 max_dim = MAX_IMAGE_SIZE, bool scale_image = true);
-	void contractToPowerOfTwo(S32 max_dim = MAX_IMAGE_SIZE, bool scale_image = true);
-	void biasedScaleToPowerOfTwo(S32 max_dim = MAX_IMAGE_SIZE);
-	bool scale(S32 new_width, S32 new_height, bool scale_image = true);
+    void expandToPowerOfTwo(S32 max_dim = MAX_IMAGE_SIZE, bool scale_image = true);
+    void contractToPowerOfTwo(S32 max_dim = MAX_IMAGE_SIZE, bool scale_image = true);
+    void biasedScaleToPowerOfTwo(S32 max_dim = MAX_IMAGE_SIZE);
+    bool scale(S32 new_width, S32 new_height, bool scale_image = true);
     LLPointer<LLImageRaw> scaled(S32 new_width, S32 new_height);
-	
-	// Fill the buffer with a constant color
-	void fill( const LLColor4U& color );
+
+    // Fill the buffer with a constant color
+    void fill( const LLColor4U& color );
 
     // Multiply this raw image by the given color
     void tint( const LLColor3& color );
 
-	// Copy operations
-	
-	//duplicate this raw image if refCount > 1.
-	LLPointer<LLImageRaw> duplicate();
+    // Copy operations
+
+    //duplicate this raw image if refCount > 1.
+    LLPointer<LLImageRaw> duplicate();
+
+    // Src and dst can be any size.  Src and dst can each have 3 or 4 components.
+    void copy( LLImageRaw* src );
 
-	// Src and dst can be any size.  Src and dst can each have 3 or 4 components.
-	void copy( LLImageRaw* src );
+    // Src and dst are same size.  Src and dst have same number of components.
+    void copyUnscaled( LLImageRaw* src );
 
-	// Src and dst are same size.  Src and dst have same number of components.
-	void copyUnscaled( LLImageRaw* src );
-	
-	// Src and dst are same size.  Src has 4 components.  Dst has 3 components.
-	void copyUnscaled4onto3( LLImageRaw* src );
+    // Src and dst are same size.  Src has 4 components.  Dst has 3 components.
+    void copyUnscaled4onto3( LLImageRaw* src );
 
-	// Src and dst are same size.  Src has 3 components.  Dst has 4 components.
-	void copyUnscaled3onto4( LLImageRaw* src );
+    // Src and dst are same size.  Src has 3 components.  Dst has 4 components.
+    void copyUnscaled3onto4( LLImageRaw* src );
 
-	// Src and dst are same size.  Src has 1 component.  Dst has 4 components.
-	// Alpha component is set to source alpha mask component.
-	// RGB components are set to fill color.
-	void copyUnscaledAlphaMask( LLImageRaw* src, const LLColor4U& fill);
+    // Src and dst are same size.  Src has 1 component.  Dst has 4 components.
+    // Alpha component is set to source alpha mask component.
+    // RGB components are set to fill color.
+    void copyUnscaledAlphaMask( LLImageRaw* src, const LLColor4U& fill);
 
-	// Src and dst can be any size.  Src and dst have same number of components.
-	void copyScaled( LLImageRaw* src );
+    // Src and dst can be any size.  Src and dst have same number of components.
+    void copyScaled( LLImageRaw* src );
 
-	// Src and dst can be any size.  Src has 3 components.  Dst has 4 components.
-	void copyScaled3onto4( LLImageRaw* src );
+    // Src and dst can be any size.  Src has 3 components.  Dst has 4 components.
+    void copyScaled3onto4( LLImageRaw* src );
 
-	// Src and dst can be any size.  Src has 4 components.  Dst has 3 components.
-	void copyScaled4onto3( LLImageRaw* src );
+    // Src and dst can be any size.  Src has 4 components.  Dst has 3 components.
+    void copyScaled4onto3( LLImageRaw* src );
 
 
-	// Composite operations
+    // Composite operations
 
-	// Src and dst can be any size.  Src and dst can each have 3 or 4 components.
-	void composite( LLImageRaw* src );
+    // Src and dst can be any size.  Src and dst can each have 3 or 4 components.
+    void composite( LLImageRaw* src );
 
-	// Src and dst can be any size.  Src has 4 components.  Dst has 3 components.
-	void compositeScaled4onto3( LLImageRaw* src );
+    // Src and dst can be any size.  Src has 4 components.  Dst has 3 components.
+    void compositeScaled4onto3( LLImageRaw* src );
 
-	// Src and dst are same size.  Src has 4 components.  Dst has 3 components.
-	void compositeUnscaled4onto3( LLImageRaw* src );
-	
-	std::string getComment() const { return mComment; }
-	std::string mComment;
+    // Src and dst are same size.  Src has 4 components.  Dst has 3 components.
+    void compositeUnscaled4onto3( LLImageRaw* src );
+
+    std::string getComment() const { return mComment; }
+    std::string mComment;
 
     // Emissive operations used by minimap
     // Roughly emulates GLTF emissive texture, but is not GLTF-compliant
@@ -284,21 +284,21 @@ class LLImageRaw final : public LLImageBase
     void addEmissiveScaled(LLImageRaw* src);
     void addEmissiveUnscaled(LLImageRaw* src);
 protected:
-	// Create an image from a local file (generally used in tools)
-	//bool createFromFile(const std::string& filename, bool j2c_lowest_mip_only = false);
+    // Create an image from a local file (generally used in tools)
+    //bool createFromFile(const std::string& filename, bool j2c_lowest_mip_only = false);
 
-	void copyLineScaled( U8* in, U8* out, S32 in_pixel_len, S32 out_pixel_len, S32 in_pixel_step, S32 out_pixel_step );
-	void compositeRowScaled4onto3( U8* in, U8* out, S32 in_pixel_len, S32 out_pixel_len );
+    void copyLineScaled( U8* in, U8* out, S32 in_pixel_len, S32 out_pixel_len, S32 in_pixel_step, S32 out_pixel_step );
+    void compositeRowScaled4onto3( U8* in, U8* out, S32 in_pixel_len, S32 out_pixel_len );
 
-	U8	fastFractionalMult(U8 a,U8 b);
+    U8  fastFractionalMult(U8 a,U8 b);
 
-	void setDataAndSize(U8 *data, S32 width, S32 height, S8 components) ;
+    void setDataAndSize(U8 *data, S32 width, S32 height, S8 components) ;
 
 public:
-	static S32 sRawImageCount;
+    static S32 sRawImageCount;
 
 private:
-	bool validateSrcAndDst(std::string func, LLImageRaw* src, LLImageRaw* dst);
+    bool validateSrcAndDst(std::string func, LLImageRaw* src, LLImageRaw* dst);
 };
 
 // Compressed representation of image.
@@ -306,74 +306,74 @@ class LLImageRaw final : public LLImageBase
 class LLImageFormatted : public LLImageBase
 {
 public:
-	static LLImageFormatted* createFromType(S8 codec);
-	static LLImageFormatted* createFromExtension(const std::string& instring);	
+    static LLImageFormatted* createFromType(S8 codec);
+    static LLImageFormatted* createFromExtension(const std::string& instring);
 
 protected:
-	/*virtual*/ ~LLImageFormatted();
-	
+    /*virtual*/ ~LLImageFormatted();
+
 public:
-	LLImageFormatted(S8 codec);
-
-	// LLImageBase
-	/*virtual*/ void deleteData();
-	/*virtual*/ U8* allocateData(S32 size = -1);
-	/*virtual*/ U8* reallocateData(S32 size);
-	
-	/*virtual*/ void dump();
-	/*virtual*/ void sanityCheck();
-
-	// New methods
-	// subclasses must return a prefered file extension (lowercase without a leading dot)
-	virtual std::string getExtension() = 0;
-	// calcHeaderSize() returns the maximum size of header;
-	//   0 indicates we don't have a header and have to read the entire file
-	virtual S32 calcHeaderSize() { return 0; };
-	// calcDataSize() returns how many bytes to read to load discard_level (including header)
-	virtual S32 calcDataSize(S32 discard_level);
-	// calcDiscardLevelBytes() returns the smallest valid discard level based on the number of input bytes
-	virtual S32 calcDiscardLevelBytes(S32 bytes);
-	// getRawDiscardLevel() by default returns mDiscardLevel, but may be overridden (LLImageJ2C)
-	virtual S8  getRawDiscardLevel() { return mDiscardLevel; }
-	
-	bool load(const std::string& filename, int load_size = 0);
-	bool save(const std::string& filename);
-
-	virtual bool updateData() = 0; // pure virtual
- 	void setData(U8 *data, S32 size);
- 	void appendData(U8 *data, S32 size);
-
-	// Loads first 4 channels.
-	virtual bool decode(LLImageRaw* raw_image, F32 decode_time) = 0;  
-	// Subclasses that can handle more than 4 channels should override this function.
-	virtual bool decodeChannels(LLImageRaw* raw_image, F32 decode_time, S32 first_channel, S32 max_channel);
-
-	virtual bool encode(const LLImageRaw* raw_image, F32 encode_time) = 0;
-
-	S8 getCodec() const;
-	bool isDecoding() const { return mDecoding; }
-	bool isDecoded()  const { return mDecoded; }
-	void setDiscardLevel(S8 discard_level) { mDiscardLevel = discard_level; }
-	S8 getDiscardLevel() const { return mDiscardLevel; }
-	S8 getLevels() const { return mLevels; }
-	void setLevels(S8 nlevels) { mLevels = nlevels; }
-
-	// setLastError needs to be deferred for J2C images since it may be called from a DLL
-	virtual void resetLastError();
-	virtual void setLastError(const std::string& message, const std::string& filename = std::string());
-	
+    LLImageFormatted(S8 codec);
+
+    // LLImageBase
+    /*virtual*/ void deleteData();
+    /*virtual*/ U8* allocateData(S32 size = -1);
+    /*virtual*/ U8* reallocateData(S32 size);
+
+    /*virtual*/ void dump();
+    /*virtual*/ void sanityCheck();
+
+    // New methods
+    // subclasses must return a prefered file extension (lowercase without a leading dot)
+    virtual std::string getExtension() = 0;
+    // calcHeaderSize() returns the maximum size of header;
+    //   0 indicates we don't have a header and have to read the entire file
+    virtual S32 calcHeaderSize() { return 0; };
+    // calcDataSize() returns how many bytes to read to load discard_level (including header)
+    virtual S32 calcDataSize(S32 discard_level);
+    // calcDiscardLevelBytes() returns the smallest valid discard level based on the number of input bytes
+    virtual S32 calcDiscardLevelBytes(S32 bytes);
+    // getRawDiscardLevel() by default returns mDiscardLevel, but may be overridden (LLImageJ2C)
+    virtual S8  getRawDiscardLevel() { return mDiscardLevel; }
+
+    bool load(const std::string& filename, int load_size = 0);
+    bool save(const std::string& filename);
+
+    virtual bool updateData() = 0; // pure virtual
+    void setData(U8 *data, S32 size);
+    void appendData(U8 *data, S32 size);
+
+    // Loads first 4 channels.
+    virtual bool decode(LLImageRaw* raw_image, F32 decode_time) = 0;
+    // Subclasses that can handle more than 4 channels should override this function.
+    virtual bool decodeChannels(LLImageRaw* raw_image, F32 decode_time, S32 first_channel, S32 max_channel);
+
+    virtual bool encode(const LLImageRaw* raw_image, F32 encode_time) = 0;
+
+    S8 getCodec() const;
+    bool isDecoding() const { return mDecoding; }
+    bool isDecoded()  const { return mDecoded; }
+    void setDiscardLevel(S8 discard_level) { mDiscardLevel = discard_level; }
+    S8 getDiscardLevel() const { return mDiscardLevel; }
+    S8 getLevels() const { return mLevels; }
+    void setLevels(S8 nlevels) { mLevels = nlevels; }
+
+    // setLastError needs to be deferred for J2C images since it may be called from a DLL
+    virtual void resetLastError();
+    virtual void setLastError(const std::string& message, const std::string& filename = std::string());
+
 protected:
-	bool copyData(U8 *data, S32 size); // calls updateData()
-	
+    bool copyData(U8 *data, S32 size); // calls updateData()
+
 protected:
-	S8 mCodec;
-	S8 mDecoding;
-	S8 mDecoded;  // unused, but changing LLImage layout requires recompiling static Mac/Linux libs. 2009-01-30 JC
-	S8 mDiscardLevel;	// Current resolution level worked on. 0 = full res, 1 = half res, 2 = quarter res, etc...
-	S8 mLevels;			// Number of resolution levels in that image. Min is 1. 0 means unknown.
-	
+    S8 mCodec;
+    S8 mDecoding;
+    S8 mDecoded;  // unused, but changing LLImage layout requires recompiling static Mac/Linux libs. 2009-01-30 JC
+    S8 mDiscardLevel;   // Current resolution level worked on. 0 = full res, 1 = half res, 2 = quarter res, etc...
+    S8 mLevels;         // Number of resolution levels in that image. Min is 1. 0 means unknown.
+
 public:
-	static S64 sGlobalFormattedMemory;
+    static S64 sGlobalFormattedMemory;
 };
 
 #endif
diff --git a/indra/llmath/llmatrix4a.h b/indra/llmath/llmatrix4a.h
index a1f8c9f679bf24edefc822e4bc30dba72e6c4449..97094b515e5b997b1920d0601231e2f7bcdb95ce 100644
--- a/indra/llmath/llmatrix4a.h
+++ b/indra/llmath/llmatrix4a.h
@@ -1,31 +1,31 @@
-/** 
+/**
  * @file llmatrix4a.h
  * @brief LLMatrix4a class header file - memory aligned and vectorized 4x4 matrix
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
 
-#ifndef	LL_LLMATRIX4A_H
-#define	LL_LLMATRIX4A_H
+#ifndef LL_LLMATRIX4A_H
+#define LL_LLMATRIX4A_H
 
 #include "llvector4a.h"
 #include "llmemory.h"
@@ -34,19 +34,19 @@
 
 class alignas(16) LLMatrix4a
 {
-	LL_ALIGN_NEW
+    LL_ALIGN_NEW
 public:
-	LL_ALIGN_PREFIX(16) LLVector4a mMatrix[4] LL_ALIGN_POSTFIX(16);
+    LL_ALIGN_PREFIX(16) LLVector4a mMatrix[4] LL_ALIGN_POSTFIX(16);
 public:
-	enum
-	{
-		ROW_FWD = 0,
-		ROW_LEFT,
-		ROW_UP,
-		ROW_TRANS
-	};
-    
-	LLMatrix4a() = default;
+    enum
+    {
+        ROW_FWD = 0,
+        ROW_LEFT,
+        ROW_UP,
+        ROW_TRANS
+    };
+
+    LLMatrix4a() = default;
     explicit LLMatrix4a(const LLMatrix4& val)
     {
         loadu(val);
@@ -57,46 +57,46 @@ class alignas(16) LLMatrix4a
         loadu(val);
     }
 
-	LLMatrix4a(const LLQuad& q1,const LLQuad& q2,const LLQuad& q3,const LLQuad& q4)
-	{
-		mMatrix[0] = q1;
-		mMatrix[1] = q2;
-		mMatrix[2] = q3;
-		mMatrix[3] = q4;
-	}
-	explicit LLMatrix4a(const LLQuaternion2& quat)
-	{
-		const LLVector4a& xyzw = quat.getVector4a(); 
-		LLVector4a nyxwz = _mm_shuffle_ps(xyzw, xyzw, _MM_SHUFFLE(2,3,0,1));
-		nyxwz.negate();
-	
-		const LLVector4a xnyynx = _mm_unpacklo_ps(xyzw,nyxwz);
-		const LLVector4a znwwnz = _mm_unpackhi_ps(xyzw,nyxwz);
-
-		LLMatrix4a mata;
-		mata.setRow<0>(_mm_shuffle_ps(xyzw, xnyynx, _MM_SHUFFLE(0,1,2,3)));
-		mata.setRow<1>(_mm_shuffle_ps(znwwnz, xyzw, _MM_SHUFFLE(1,0,2,3)));
-		mata.setRow<2>(_mm_shuffle_ps(xnyynx, xyzw, _MM_SHUFFLE(2,3,3,2)));
-		mata.setRow<3>(_mm_shuffle_ps(xnyynx, znwwnz, _MM_SHUFFLE(2,3,1,3)));
-
-		LLMatrix4a matb;
-		matb.setRow<0>(_mm_shuffle_ps(xyzw, xnyynx, _MM_SHUFFLE(3,1,2,3)));
-		matb.setRow<1>(_mm_shuffle_ps(znwwnz, xnyynx, _MM_SHUFFLE(1,0,2,3)));
-		matb.setRow<2>(_mm_shuffle_ps(xnyynx, znwwnz, _MM_SHUFFLE(3,2,3,2)));
-		matb.setRow<3>(xyzw);
-
-		setMul(matb,mata);
-	}
-
-	inline F32* getF32ptr()
-	{
-		return mMatrix[0].getF32ptr();
-	}
-	
-	inline const F32* getF32ptr() const
-	{
-		return mMatrix[0].getF32ptr();
-	}
+    LLMatrix4a(const LLQuad& q1,const LLQuad& q2,const LLQuad& q3,const LLQuad& q4)
+    {
+        mMatrix[0] = q1;
+        mMatrix[1] = q2;
+        mMatrix[2] = q3;
+        mMatrix[3] = q4;
+    }
+    explicit LLMatrix4a(const LLQuaternion2& quat)
+    {
+        const LLVector4a& xyzw = quat.getVector4a();
+        LLVector4a nyxwz = _mm_shuffle_ps(xyzw, xyzw, _MM_SHUFFLE(2,3,0,1));
+        nyxwz.negate();
+
+        const LLVector4a xnyynx = _mm_unpacklo_ps(xyzw,nyxwz);
+        const LLVector4a znwwnz = _mm_unpackhi_ps(xyzw,nyxwz);
+
+        LLMatrix4a mata;
+        mata.setRow<0>(_mm_shuffle_ps(xyzw, xnyynx, _MM_SHUFFLE(0,1,2,3)));
+        mata.setRow<1>(_mm_shuffle_ps(znwwnz, xyzw, _MM_SHUFFLE(1,0,2,3)));
+        mata.setRow<2>(_mm_shuffle_ps(xnyynx, xyzw, _MM_SHUFFLE(2,3,3,2)));
+        mata.setRow<3>(_mm_shuffle_ps(xnyynx, znwwnz, _MM_SHUFFLE(2,3,1,3)));
+
+        LLMatrix4a matb;
+        matb.setRow<0>(_mm_shuffle_ps(xyzw, xnyynx, _MM_SHUFFLE(3,1,2,3)));
+        matb.setRow<1>(_mm_shuffle_ps(znwwnz, xnyynx, _MM_SHUFFLE(1,0,2,3)));
+        matb.setRow<2>(_mm_shuffle_ps(xnyynx, znwwnz, _MM_SHUFFLE(3,2,3,2)));
+        matb.setRow<3>(xyzw);
+
+        setMul(matb,mata);
+    }
+
+    inline F32* getF32ptr()
+    {
+        return mMatrix[0].getF32ptr();
+    }
+
+    inline const F32* getF32ptr() const
+    {
+        return mMatrix[0].getF32ptr();
+    }
 
     inline LLMatrix4& asMatrix4()
     {
@@ -108,690 +108,690 @@ class alignas(16) LLMatrix4a
         return *(LLMatrix4*)this;
     }
 
-	inline void clear()
-	{
-		mMatrix[0].clear();
-		mMatrix[1].clear();
-		mMatrix[2].clear();
-		mMatrix[3].clear();
-	}
-
-	inline void setIdentity()
-	{
-		const LLQuad ones = _mm_set_ps(1.f,0.f,0.f,1.f);
-		const LLQuad zeroes = _mm_setzero_ps();
-		mMatrix[0] = _mm_movelh_ps(ones, zeroes);
-		mMatrix[1] = _mm_movehl_ps(zeroes,ones);
-		mMatrix[2] = _mm_movelh_ps(zeroes,ones);
-		mMatrix[3] = _mm_movehl_ps(ones, zeroes);
-	}
-
-	inline void load4a(const F32* src)
-	{
-		mMatrix[0].load4a(src+0);
-		mMatrix[1].load4a(src+4);
-		mMatrix[2].load4a(src+8);
-		mMatrix[3].load4a(src+12);
-	}
-
-	inline void loadu(const LLMatrix4& src)
-	{
-		mMatrix[0].loadua(src.mMatrix[0]);
-		mMatrix[1].loadua(src.mMatrix[1]);
-		mMatrix[2].loadua(src.mMatrix[2]);
-		mMatrix[3].loadua(src.mMatrix[3]);
-	}
-
-	inline void loadu(const F32* src)
-	{
-		mMatrix[0].loadua(src+0);
-		mMatrix[1].loadua(src+4);
-		mMatrix[2].loadua(src+8);
-		mMatrix[3].loadua(src+12);
-	}
-
-	inline void loadu(const LLMatrix3& src)
-	{
-		mMatrix[0].load3(src.mMatrix[0]);
-		mMatrix[1].load3(src.mMatrix[1]);
-		mMatrix[2].load3(src.mMatrix[2]);
-		mMatrix[3].set(0,0,0,1.f);
-	}
-
-	inline void store4a(F32* dst) const
-	{
-		mMatrix[0].store4a(dst+0);
-		mMatrix[1].store4a(dst+4);
-		mMatrix[2].store4a(dst+8);
-		mMatrix[3].store4a(dst+12);
-	}
-
-	inline void add(const LLMatrix4a& rhs)
-	{
-		mMatrix[0].add(rhs.mMatrix[0]);
-		mMatrix[1].add(rhs.mMatrix[1]);
-		mMatrix[2].add(rhs.mMatrix[2]);
-		mMatrix[3].add(rhs.mMatrix[3]);
-	}
-
-	inline void mul(const LLMatrix4a& rhs)
-	{
-		//Not using rotate4 to avoid extra copy of *this.
-		LLVector4a x0,y0,z0,w0;
-		LLVector4a x1,y1,z1,w1;
-		LLVector4a x2,y2,z2,w2;
-		LLVector4a x3,y3,z3,w3;
-
-		//16 shuffles
-		x0.splat<0>(rhs.mMatrix[0]);
-		x1.splat<0>(rhs.mMatrix[1]);
-		x2.splat<0>(rhs.mMatrix[2]);
-		x3.splat<0>(rhs.mMatrix[3]);
-
-		y0.splat<1>(rhs.mMatrix[0]);
-		y1.splat<1>(rhs.mMatrix[1]);
-		y2.splat<1>(rhs.mMatrix[2]);
-		y3.splat<1>(rhs.mMatrix[3]);
-
-		z0.splat<2>(rhs.mMatrix[0]);
-		z1.splat<2>(rhs.mMatrix[1]);
-		z2.splat<2>(rhs.mMatrix[2]);
-		z3.splat<2>(rhs.mMatrix[3]);
-
-		w0.splat<3>(rhs.mMatrix[0]);
-		w1.splat<3>(rhs.mMatrix[1]);
-		w2.splat<3>(rhs.mMatrix[2]);
-		w3.splat<3>(rhs.mMatrix[3]);
-
-		//16 muls
-		x0.mul(mMatrix[0]);
-		x1.mul(mMatrix[0]);
-		x2.mul(mMatrix[0]);
-		x3.mul(mMatrix[0]);
-
-		y0.mul(mMatrix[1]);
-		y1.mul(mMatrix[1]);
-		y2.mul(mMatrix[1]);
-		y3.mul(mMatrix[1]);
-
-		z0.mul(mMatrix[2]);
-		z1.mul(mMatrix[2]);
-		z2.mul(mMatrix[2]);
-		z3.mul(mMatrix[2]);
-
-		w0.mul(mMatrix[3]);
-		w1.mul(mMatrix[3]);
-		w2.mul(mMatrix[3]);
-		w3.mul(mMatrix[3]);
-
-		//12 adds
-		x0.add(y0);
-		z0.add(w0);
-
-		x1.add(y1);
-		z1.add(w1);
-
-		x2.add(y2);
-		z2.add(w2);
-
-		x3.add(y3);
-		z3.add(w3);
-
-		mMatrix[0].setAdd(x0,z0);
-		mMatrix[1].setAdd(x1,z1);
-		mMatrix[2].setAdd(x2,z2);
-		mMatrix[3].setAdd(x3,z3);
-	}
-
-	inline void setRows(const LLVector4a& r0, const LLVector4a& r1, const LLVector4a& r2)
-	{
-		mMatrix[0] = r0;
-		mMatrix[1] = r1;
-		mMatrix[2] = r2;
-	}
-
-	template<int N>
-	inline void setRow(const LLVector4a& row)
-	{
-		mMatrix[N] = row;
-	}
-
-	template<int N>
-	inline const LLVector4a& getRow() const
-	{
-		return mMatrix[N];
-	}
-
-	template<int N>
-	inline LLVector4a& getRow()
-	{
-		return mMatrix[N];
-	}
-
-	template<int N>
-	inline void setColumn(const LLVector4a& col)
-	{
-		mMatrix[0].copyComponent<N>(col.getScalarAt<0>());
-		mMatrix[1].copyComponent<N>(col.getScalarAt<1>());
-		mMatrix[2].copyComponent<N>(col.getScalarAt<2>());
-		mMatrix[3].copyComponent<N>(col.getScalarAt<3>());
-	}
-
-	template<int N>
-	inline LLVector4a getColumn() const
-	{
-		LLVector4a v;
-		v.clear();
-		v.copyComponent<0>(mMatrix[0].getScalarAt<N>());
-		v.copyComponent<1>(mMatrix[1].getScalarAt<N>());
-		v.copyComponent<2>(mMatrix[2].getScalarAt<N>());
-		v.copyComponent<3>(mMatrix[3].getScalarAt<N>());
-		return v;
-	}
-
-	// Set element-wise to mMatrix + (m*v)
-	inline void setMulAdd(const LLMatrix4a& m, const LLVector4a& v)
-	{
-		mMatrix[0] = _mm_add_ps(mMatrix[0], _mm_mul_ps(m.mMatrix[0], v));
-		mMatrix[1] = _mm_add_ps(mMatrix[1], _mm_mul_ps(m.mMatrix[1], v));
-		mMatrix[2] = _mm_add_ps(mMatrix[2], _mm_mul_ps(m.mMatrix[2], v));
-		mMatrix[3] = _mm_add_ps(mMatrix[3], _mm_mul_ps(m.mMatrix[3], v));
-	}
-
-	inline void setMul(const LLMatrix4a& m, const F32 s)
-	{
-		const LLVector4a ssss(s);
-		mMatrix[0].setMul(m.mMatrix[0], ssss);
-		mMatrix[1].setMul(m.mMatrix[1], ssss);
-		mMatrix[2].setMul(m.mMatrix[2], ssss);
-		mMatrix[3].setMul(m.mMatrix[3], ssss);
-	}
-
-	inline void setMul(const LLMatrix4a& m, const LLVector4a& v)
-	{
-		mMatrix[0].setMul(m.mMatrix[0], v);
-		mMatrix[1].setMul(m.mMatrix[1], v);
-		mMatrix[2].setMul(m.mMatrix[2], v);
-		mMatrix[3].setMul(m.mMatrix[3], v);
-	}
-
-	inline void setMul(const LLMatrix4a& m0, const LLMatrix4a& m1)
-	{
-		m0.rotate4(m1.mMatrix[0],mMatrix[0]);
-		m0.rotate4(m1.mMatrix[1],mMatrix[1]);
-		m0.rotate4(m1.mMatrix[2],mMatrix[2]);
-		m0.rotate4(m1.mMatrix[3],mMatrix[3]);
-	}
-
-	inline void setLerp(const LLMatrix4a& a, const LLMatrix4a& b, F32 w)
-	{
-		LLVector4a d0,d1,d2,d3;
-		d0.setSub(b.mMatrix[0], a.mMatrix[0]);
-		d1.setSub(b.mMatrix[1], a.mMatrix[1]);
-		d2.setSub(b.mMatrix[2], a.mMatrix[2]);
-		d3.setSub(b.mMatrix[3], a.mMatrix[3]);
-
-		// this = a + d*w
-		
-		const LLVector4a wwww(w);
-		d0.mul(wwww);
-		d1.mul(wwww);
-		d2.mul(wwww);
-		d3.mul(wwww);
-
-		mMatrix[0].setAdd(a.mMatrix[0],d0);
-		mMatrix[1].setAdd(a.mMatrix[1],d1);
-		mMatrix[2].setAdd(a.mMatrix[2],d2);
-		mMatrix[3].setAdd(a.mMatrix[3],d3);
-	}
-	
-	// Alchemy Note: Don't mess with this. It's intentionally different from LL's. 
-	// Note how res isn't manipulated until the very end.
-	//Fast(er). Treats v[VW] as 0.f
-	inline void rotate(const LLVector4a& v, LLVector4a& res) const
-	{
-		LLVector4a x,y,z;
-
-		x.splat<0>(v);
-		y.splat<1>(v);
-		z.splat<2>(v);
-
-		x.mul(mMatrix[0]);
-		y.mul(mMatrix[1]);
-		z.mul(mMatrix[2]);
-
-		x.add(y);
-		res.setAdd(x,z);
-	}
-
-	//Proper. v[VW] as v[VW]
-	inline void rotate4(const LLVector4a& v, LLVector4a& res) const
-	{
-		LLVector4a x,y,z,w;
-
-		x.splat<0>(v);
-		y.splat<1>(v);
-		z.splat<2>(v);
-		w.splat<3>(v);
-
-		x.mul(mMatrix[0]);
-		y.mul(mMatrix[1]);
-		z.mul(mMatrix[2]);
-		w.mul(mMatrix[3]);
-
-		x.add(y);
-		z.add(w);
-		res.setAdd(x,z);
-	}
-
-	//Fast(er). Treats v[VW] as 1.f
-	inline void affineTransform(const LLVector4a& v, LLVector4a& res) const
-	{
-		LLVector4a x,y,z;
-
-		x.splat<0>(v);
-		y.splat<1>(v);
-		z.splat<2>(v);
-
-		x.mul(mMatrix[0]);
-		y.mul(mMatrix[1]);
-		z.mul(mMatrix[2]);
-
-		x.add(y);
-		z.add(mMatrix[3]);
-		res.setAdd(x,z);
-	}
-
-	inline void perspectiveTransform(const LLVector4a& v, LLVector4a& res) const
-	{
-		LLVector4a x,y,z,s,t,p,q;
-
-		x.splat<0>(v);
-		y.splat<1>(v);
-		z.splat<2>(v);
-
-		s.splat<3>(mMatrix[0]);
-		t.splat<3>(mMatrix[1]);
-		p.splat<3>(mMatrix[2]);
-		q.splat<3>(mMatrix[3]);
-
-		s.mul(x);
-		t.mul(y);
-		p.mul(z);
-		q.add(s);
-		t.add(p);
-		q.add(t);
-
-		x.mul(mMatrix[0]);
-		y.mul(mMatrix[1]);
-		z.mul(mMatrix[2]);
-
-		x.add(y);
-		z.add(mMatrix[3]);
-		res.setAdd(x,z);
-		res.div(q);
-	}
-
-	inline void transpose()
-	{
-		__m128 q1 = _mm_unpackhi_ps(mMatrix[0],mMatrix[1]);
-		__m128 q2 = _mm_unpacklo_ps(mMatrix[0],mMatrix[1]);
-		__m128 q3 = _mm_unpacklo_ps(mMatrix[2],mMatrix[3]);
-		__m128 q4 = _mm_unpackhi_ps(mMatrix[2],mMatrix[3]);
-
-		mMatrix[0] = _mm_movelh_ps(q2,q3);
-		mMatrix[1] = _mm_movehl_ps(q3,q2);
-		mMatrix[2] = _mm_movelh_ps(q1,q4);
-		mMatrix[3] = _mm_movehl_ps(q4,q1);
-	}
+    inline void clear()
+    {
+        mMatrix[0].clear();
+        mMatrix[1].clear();
+        mMatrix[2].clear();
+        mMatrix[3].clear();
+    }
+
+    inline void setIdentity()
+    {
+        const LLQuad ones = _mm_set_ps(1.f,0.f,0.f,1.f);
+        const LLQuad zeroes = _mm_setzero_ps();
+        mMatrix[0] = _mm_movelh_ps(ones, zeroes);
+        mMatrix[1] = _mm_movehl_ps(zeroes,ones);
+        mMatrix[2] = _mm_movelh_ps(zeroes,ones);
+        mMatrix[3] = _mm_movehl_ps(ones, zeroes);
+    }
+
+    inline void load4a(const F32* src)
+    {
+        mMatrix[0].load4a(src+0);
+        mMatrix[1].load4a(src+4);
+        mMatrix[2].load4a(src+8);
+        mMatrix[3].load4a(src+12);
+    }
+
+    inline void loadu(const LLMatrix4& src)
+    {
+        mMatrix[0].loadua(src.mMatrix[0]);
+        mMatrix[1].loadua(src.mMatrix[1]);
+        mMatrix[2].loadua(src.mMatrix[2]);
+        mMatrix[3].loadua(src.mMatrix[3]);
+    }
+
+    inline void loadu(const F32* src)
+    {
+        mMatrix[0].loadua(src+0);
+        mMatrix[1].loadua(src+4);
+        mMatrix[2].loadua(src+8);
+        mMatrix[3].loadua(src+12);
+    }
+
+    inline void loadu(const LLMatrix3& src)
+    {
+        mMatrix[0].load3(src.mMatrix[0]);
+        mMatrix[1].load3(src.mMatrix[1]);
+        mMatrix[2].load3(src.mMatrix[2]);
+        mMatrix[3].set(0,0,0,1.f);
+    }
+
+    inline void store4a(F32* dst) const
+    {
+        mMatrix[0].store4a(dst+0);
+        mMatrix[1].store4a(dst+4);
+        mMatrix[2].store4a(dst+8);
+        mMatrix[3].store4a(dst+12);
+    }
+
+    inline void add(const LLMatrix4a& rhs)
+    {
+        mMatrix[0].add(rhs.mMatrix[0]);
+        mMatrix[1].add(rhs.mMatrix[1]);
+        mMatrix[2].add(rhs.mMatrix[2]);
+        mMatrix[3].add(rhs.mMatrix[3]);
+    }
+
+    inline void mul(const LLMatrix4a& rhs)
+    {
+        //Not using rotate4 to avoid extra copy of *this.
+        LLVector4a x0,y0,z0,w0;
+        LLVector4a x1,y1,z1,w1;
+        LLVector4a x2,y2,z2,w2;
+        LLVector4a x3,y3,z3,w3;
+
+        //16 shuffles
+        x0.splat<0>(rhs.mMatrix[0]);
+        x1.splat<0>(rhs.mMatrix[1]);
+        x2.splat<0>(rhs.mMatrix[2]);
+        x3.splat<0>(rhs.mMatrix[3]);
+
+        y0.splat<1>(rhs.mMatrix[0]);
+        y1.splat<1>(rhs.mMatrix[1]);
+        y2.splat<1>(rhs.mMatrix[2]);
+        y3.splat<1>(rhs.mMatrix[3]);
+
+        z0.splat<2>(rhs.mMatrix[0]);
+        z1.splat<2>(rhs.mMatrix[1]);
+        z2.splat<2>(rhs.mMatrix[2]);
+        z3.splat<2>(rhs.mMatrix[3]);
+
+        w0.splat<3>(rhs.mMatrix[0]);
+        w1.splat<3>(rhs.mMatrix[1]);
+        w2.splat<3>(rhs.mMatrix[2]);
+        w3.splat<3>(rhs.mMatrix[3]);
+
+        //16 muls
+        x0.mul(mMatrix[0]);
+        x1.mul(mMatrix[0]);
+        x2.mul(mMatrix[0]);
+        x3.mul(mMatrix[0]);
+
+        y0.mul(mMatrix[1]);
+        y1.mul(mMatrix[1]);
+        y2.mul(mMatrix[1]);
+        y3.mul(mMatrix[1]);
+
+        z0.mul(mMatrix[2]);
+        z1.mul(mMatrix[2]);
+        z2.mul(mMatrix[2]);
+        z3.mul(mMatrix[2]);
+
+        w0.mul(mMatrix[3]);
+        w1.mul(mMatrix[3]);
+        w2.mul(mMatrix[3]);
+        w3.mul(mMatrix[3]);
+
+        //12 adds
+        x0.add(y0);
+        z0.add(w0);
+
+        x1.add(y1);
+        z1.add(w1);
+
+        x2.add(y2);
+        z2.add(w2);
+
+        x3.add(y3);
+        z3.add(w3);
+
+        mMatrix[0].setAdd(x0,z0);
+        mMatrix[1].setAdd(x1,z1);
+        mMatrix[2].setAdd(x2,z2);
+        mMatrix[3].setAdd(x3,z3);
+    }
+
+    inline void setRows(const LLVector4a& r0, const LLVector4a& r1, const LLVector4a& r2)
+    {
+        mMatrix[0] = r0;
+        mMatrix[1] = r1;
+        mMatrix[2] = r2;
+    }
+
+    template<int N>
+    inline void setRow(const LLVector4a& row)
+    {
+        mMatrix[N] = row;
+    }
+
+    template<int N>
+    inline const LLVector4a& getRow() const
+    {
+        return mMatrix[N];
+    }
+
+    template<int N>
+    inline LLVector4a& getRow()
+    {
+        return mMatrix[N];
+    }
+
+    template<int N>
+    inline void setColumn(const LLVector4a& col)
+    {
+        mMatrix[0].copyComponent<N>(col.getScalarAt<0>());
+        mMatrix[1].copyComponent<N>(col.getScalarAt<1>());
+        mMatrix[2].copyComponent<N>(col.getScalarAt<2>());
+        mMatrix[3].copyComponent<N>(col.getScalarAt<3>());
+    }
+
+    template<int N>
+    inline LLVector4a getColumn() const
+    {
+        LLVector4a v;
+        v.clear();
+        v.copyComponent<0>(mMatrix[0].getScalarAt<N>());
+        v.copyComponent<1>(mMatrix[1].getScalarAt<N>());
+        v.copyComponent<2>(mMatrix[2].getScalarAt<N>());
+        v.copyComponent<3>(mMatrix[3].getScalarAt<N>());
+        return v;
+    }
+
+    // Set element-wise to mMatrix + (m*v)
+    inline void setMulAdd(const LLMatrix4a& m, const LLVector4a& v)
+    {
+        mMatrix[0] = _mm_add_ps(mMatrix[0], _mm_mul_ps(m.mMatrix[0], v));
+        mMatrix[1] = _mm_add_ps(mMatrix[1], _mm_mul_ps(m.mMatrix[1], v));
+        mMatrix[2] = _mm_add_ps(mMatrix[2], _mm_mul_ps(m.mMatrix[2], v));
+        mMatrix[3] = _mm_add_ps(mMatrix[3], _mm_mul_ps(m.mMatrix[3], v));
+    }
+
+    inline void setMul(const LLMatrix4a& m, const F32 s)
+    {
+        const LLVector4a ssss(s);
+        mMatrix[0].setMul(m.mMatrix[0], ssss);
+        mMatrix[1].setMul(m.mMatrix[1], ssss);
+        mMatrix[2].setMul(m.mMatrix[2], ssss);
+        mMatrix[3].setMul(m.mMatrix[3], ssss);
+    }
+
+    inline void setMul(const LLMatrix4a& m, const LLVector4a& v)
+    {
+        mMatrix[0].setMul(m.mMatrix[0], v);
+        mMatrix[1].setMul(m.mMatrix[1], v);
+        mMatrix[2].setMul(m.mMatrix[2], v);
+        mMatrix[3].setMul(m.mMatrix[3], v);
+    }
+
+    inline void setMul(const LLMatrix4a& m0, const LLMatrix4a& m1)
+    {
+        m0.rotate4(m1.mMatrix[0],mMatrix[0]);
+        m0.rotate4(m1.mMatrix[1],mMatrix[1]);
+        m0.rotate4(m1.mMatrix[2],mMatrix[2]);
+        m0.rotate4(m1.mMatrix[3],mMatrix[3]);
+    }
+
+    inline void setLerp(const LLMatrix4a& a, const LLMatrix4a& b, F32 w)
+    {
+        LLVector4a d0,d1,d2,d3;
+        d0.setSub(b.mMatrix[0], a.mMatrix[0]);
+        d1.setSub(b.mMatrix[1], a.mMatrix[1]);
+        d2.setSub(b.mMatrix[2], a.mMatrix[2]);
+        d3.setSub(b.mMatrix[3], a.mMatrix[3]);
+
+        // this = a + d*w
+
+        const LLVector4a wwww(w);
+        d0.mul(wwww);
+        d1.mul(wwww);
+        d2.mul(wwww);
+        d3.mul(wwww);
+
+        mMatrix[0].setAdd(a.mMatrix[0],d0);
+        mMatrix[1].setAdd(a.mMatrix[1],d1);
+        mMatrix[2].setAdd(a.mMatrix[2],d2);
+        mMatrix[3].setAdd(a.mMatrix[3],d3);
+    }
+
+    // Alchemy Note: Don't mess with this. It's intentionally different from LL's.
+    // Note how res isn't manipulated until the very end.
+    //Fast(er). Treats v[VW] as 0.f
+    inline void rotate(const LLVector4a& v, LLVector4a& res) const
+    {
+        LLVector4a x,y,z;
+
+        x.splat<0>(v);
+        y.splat<1>(v);
+        z.splat<2>(v);
+
+        x.mul(mMatrix[0]);
+        y.mul(mMatrix[1]);
+        z.mul(mMatrix[2]);
+
+        x.add(y);
+        res.setAdd(x,z);
+    }
+
+    //Proper. v[VW] as v[VW]
+    inline void rotate4(const LLVector4a& v, LLVector4a& res) const
+    {
+        LLVector4a x,y,z,w;
+
+        x.splat<0>(v);
+        y.splat<1>(v);
+        z.splat<2>(v);
+        w.splat<3>(v);
+
+        x.mul(mMatrix[0]);
+        y.mul(mMatrix[1]);
+        z.mul(mMatrix[2]);
+        w.mul(mMatrix[3]);
+
+        x.add(y);
+        z.add(w);
+        res.setAdd(x,z);
+    }
+
+    //Fast(er). Treats v[VW] as 1.f
+    inline void affineTransform(const LLVector4a& v, LLVector4a& res) const
+    {
+        LLVector4a x,y,z;
+
+        x.splat<0>(v);
+        y.splat<1>(v);
+        z.splat<2>(v);
+
+        x.mul(mMatrix[0]);
+        y.mul(mMatrix[1]);
+        z.mul(mMatrix[2]);
+
+        x.add(y);
+        z.add(mMatrix[3]);
+        res.setAdd(x,z);
+    }
+
+    inline void perspectiveTransform(const LLVector4a& v, LLVector4a& res) const
+    {
+        LLVector4a x,y,z,s,t,p,q;
+
+        x.splat<0>(v);
+        y.splat<1>(v);
+        z.splat<2>(v);
+
+        s.splat<3>(mMatrix[0]);
+        t.splat<3>(mMatrix[1]);
+        p.splat<3>(mMatrix[2]);
+        q.splat<3>(mMatrix[3]);
+
+        s.mul(x);
+        t.mul(y);
+        p.mul(z);
+        q.add(s);
+        t.add(p);
+        q.add(t);
+
+        x.mul(mMatrix[0]);
+        y.mul(mMatrix[1]);
+        z.mul(mMatrix[2]);
+
+        x.add(y);
+        z.add(mMatrix[3]);
+        res.setAdd(x,z);
+        res.div(q);
+    }
+
+    inline void transpose()
+    {
+        __m128 q1 = _mm_unpackhi_ps(mMatrix[0],mMatrix[1]);
+        __m128 q2 = _mm_unpacklo_ps(mMatrix[0],mMatrix[1]);
+        __m128 q3 = _mm_unpacklo_ps(mMatrix[2],mMatrix[3]);
+        __m128 q4 = _mm_unpackhi_ps(mMatrix[2],mMatrix[3]);
+
+        mMatrix[0] = _mm_movelh_ps(q2,q3);
+        mMatrix[1] = _mm_movehl_ps(q3,q2);
+        mMatrix[2] = _mm_movelh_ps(q1,q4);
+        mMatrix[3] = _mm_movehl_ps(q4,q1);
+    }
 
     const LLVector4a& getTranslation() const { return mMatrix[3]; }
 
 //  Following procedure adapted from:
-//		http://software.intel.com/en-us/articles/optimized-matrix-library-for-use-with-the-intel-pentiumr-4-processors-sse2-instructions/
+//      http://software.intel.com/en-us/articles/optimized-matrix-library-for-use-with-the-intel-pentiumr-4-processors-sse2-instructions/
 //
 //  License/Copyright Statement:
-//		
-//			Copyright (c) 2001 Intel Corporation.
 //
-//		Permition is granted to use, copy, distribute and prepare derivative works 
-//		of this library for any purpose and without fee, provided, that the above 
-//		copyright notice and this statement appear in all copies.  
-//		Intel makes no representations about the suitability of this library for 
-//		any purpose, and specifically disclaims all warranties. 
-//		See LEGAL-intel_matrixlib.TXT for all the legal information.
-	inline float invert()
-	{
-		LL_ALIGN_16(const unsigned int Sign_PNNP[4]) = { 0x00000000, 0x80000000, 0x80000000, 0x00000000 };
-
-		// The inverse is calculated using "Divide and Conquer" technique. The 
-		// original matrix is divide into four 2x2 sub-matrices. Since each 
-		// register holds four matrix element, the smaller matrices are 
-		// represented as a registers. Hence we get a better locality of the 
-		// calculations.
-
-		LLVector4a A = _mm_movelh_ps(mMatrix[0], mMatrix[1]),    // the four sub-matrices 
-				B = _mm_movehl_ps(mMatrix[1], mMatrix[0]),
-				C = _mm_movelh_ps(mMatrix[2], mMatrix[3]),
-				D = _mm_movehl_ps(mMatrix[3], mMatrix[2]);
-		LLVector4a iA, iB, iC, iD,					// partial inverse of the sub-matrices
-				DC, AB;
-		LLSimdScalar dA, dB, dC, dD;                 // determinant of the sub-matrices
-		LLSimdScalar det, d, d1, d2;
-		LLVector4a rd;
-
-		//  AB = A# * B
-		AB.setMul(_mm_shuffle_ps(A,A,0x0F), B);
-		AB.sub(_mm_mul_ps(_mm_shuffle_ps(A,A,0xA5), _mm_shuffle_ps(B,B,0x4E)));
-		//  DC = D# * C
-		DC.setMul(_mm_shuffle_ps(D,D,0x0F), C);
-		DC.sub(_mm_mul_ps(_mm_shuffle_ps(D,D,0xA5), _mm_shuffle_ps(C,C,0x4E)));
-
-		//  dA = |A|
-		dA = _mm_mul_ps(_mm_shuffle_ps(A, A, 0x5F),A);
-		dA -= _mm_movehl_ps(dA,dA);
-		//  dB = |B|
-		dB = _mm_mul_ps(_mm_shuffle_ps(B, B, 0x5F),B);
-		dB -= _mm_movehl_ps(dB,dB);
-
-		//  dC = |C|
-		dC = _mm_mul_ps(_mm_shuffle_ps(C, C, 0x5F),C);
-		dC -= _mm_movehl_ps(dC,dC);
-		//  dD = |D|
-		dD = _mm_mul_ps(_mm_shuffle_ps(D, D, 0x5F),D);
-		dD -= _mm_movehl_ps(dD,dD);
-
-		//  d = trace(AB*DC) = trace(A#*B*D#*C)
-		d = _mm_mul_ps(_mm_shuffle_ps(DC,DC,0xD8),AB);
-
-		//  iD = C*A#*B
-		iD.setMul(_mm_shuffle_ps(C,C,0xA0), _mm_movelh_ps(AB,AB));
-		iD.add(_mm_mul_ps(_mm_shuffle_ps(C,C,0xF5), _mm_movehl_ps(AB,AB)));
-		//  iA = B*D#*C
-		iA.setMul(_mm_shuffle_ps(B,B,0xA0), _mm_movelh_ps(DC,DC));
-		iA.add(_mm_mul_ps(_mm_shuffle_ps(B,B,0xF5), _mm_movehl_ps(DC,DC)));
-
-		//  d = trace(AB*DC) = trace(A#*B*D#*C) [continue]
-		d = _mm_add_ps(d, _mm_movehl_ps(d, d));
-		d += _mm_shuffle_ps(d, d, 1);
-		d1 = dA*dD;
-		d2 = dB*dC;
-
-		//  iD = D*|A| - C*A#*B
-		iD.setSub(_mm_mul_ps(D,_mm_shuffle_ps(dA,dA,0)), iD);
-
-		//  iA = A*|D| - B*D#*C;
-		iA.setSub(_mm_mul_ps(A,_mm_shuffle_ps(dD,dD,0)), iA);
-
-		//  det = |A|*|D| + |B|*|C| - trace(A#*B*D#*C)
-		det = d1+d2-d;
-
-		__m128 is_zero_mask = _mm_cmpeq_ps(det,_mm_setzero_ps());
-		rd = _mm_div_ss(_mm_set_ss(1.f),_mm_or_ps(_mm_andnot_ps(is_zero_mask, det), _mm_and_ps(is_zero_mask, _mm_set_ss(1.f))));
+//          Copyright (c) 2001 Intel Corporation.
+//
+//      Permition is granted to use, copy, distribute and prepare derivative works
+//      of this library for any purpose and without fee, provided, that the above
+//      copyright notice and this statement appear in all copies.
+//      Intel makes no representations about the suitability of this library for
+//      any purpose, and specifically disclaims all warranties.
+//      See LEGAL-intel_matrixlib.TXT for all the legal information.
+    inline float invert()
+    {
+        LL_ALIGN_16(const unsigned int Sign_PNNP[4]) = { 0x00000000, 0x80000000, 0x80000000, 0x00000000 };
+
+        // The inverse is calculated using "Divide and Conquer" technique. The
+        // original matrix is divide into four 2x2 sub-matrices. Since each
+        // register holds four matrix element, the smaller matrices are
+        // represented as a registers. Hence we get a better locality of the
+        // calculations.
+
+        LLVector4a A = _mm_movelh_ps(mMatrix[0], mMatrix[1]),    // the four sub-matrices
+                B = _mm_movehl_ps(mMatrix[1], mMatrix[0]),
+                C = _mm_movelh_ps(mMatrix[2], mMatrix[3]),
+                D = _mm_movehl_ps(mMatrix[3], mMatrix[2]);
+        LLVector4a iA, iB, iC, iD,                  // partial inverse of the sub-matrices
+                DC, AB;
+        LLSimdScalar dA, dB, dC, dD;                 // determinant of the sub-matrices
+        LLSimdScalar det, d, d1, d2;
+        LLVector4a rd;
+
+        //  AB = A# * B
+        AB.setMul(_mm_shuffle_ps(A,A,0x0F), B);
+        AB.sub(_mm_mul_ps(_mm_shuffle_ps(A,A,0xA5), _mm_shuffle_ps(B,B,0x4E)));
+        //  DC = D# * C
+        DC.setMul(_mm_shuffle_ps(D,D,0x0F), C);
+        DC.sub(_mm_mul_ps(_mm_shuffle_ps(D,D,0xA5), _mm_shuffle_ps(C,C,0x4E)));
+
+        //  dA = |A|
+        dA = _mm_mul_ps(_mm_shuffle_ps(A, A, 0x5F),A);
+        dA -= _mm_movehl_ps(dA,dA);
+        //  dB = |B|
+        dB = _mm_mul_ps(_mm_shuffle_ps(B, B, 0x5F),B);
+        dB -= _mm_movehl_ps(dB,dB);
+
+        //  dC = |C|
+        dC = _mm_mul_ps(_mm_shuffle_ps(C, C, 0x5F),C);
+        dC -= _mm_movehl_ps(dC,dC);
+        //  dD = |D|
+        dD = _mm_mul_ps(_mm_shuffle_ps(D, D, 0x5F),D);
+        dD -= _mm_movehl_ps(dD,dD);
+
+        //  d = trace(AB*DC) = trace(A#*B*D#*C)
+        d = _mm_mul_ps(_mm_shuffle_ps(DC,DC,0xD8),AB);
+
+        //  iD = C*A#*B
+        iD.setMul(_mm_shuffle_ps(C,C,0xA0), _mm_movelh_ps(AB,AB));
+        iD.add(_mm_mul_ps(_mm_shuffle_ps(C,C,0xF5), _mm_movehl_ps(AB,AB)));
+        //  iA = B*D#*C
+        iA.setMul(_mm_shuffle_ps(B,B,0xA0), _mm_movelh_ps(DC,DC));
+        iA.add(_mm_mul_ps(_mm_shuffle_ps(B,B,0xF5), _mm_movehl_ps(DC,DC)));
+
+        //  d = trace(AB*DC) = trace(A#*B*D#*C) [continue]
+        d = _mm_add_ps(d, _mm_movehl_ps(d, d));
+        d += _mm_shuffle_ps(d, d, 1);
+        d1 = dA*dD;
+        d2 = dB*dC;
+
+        //  iD = D*|A| - C*A#*B
+        iD.setSub(_mm_mul_ps(D,_mm_shuffle_ps(dA,dA,0)), iD);
+
+        //  iA = A*|D| - B*D#*C;
+        iA.setSub(_mm_mul_ps(A,_mm_shuffle_ps(dD,dD,0)), iA);
+
+        //  det = |A|*|D| + |B|*|C| - trace(A#*B*D#*C)
+        det = d1+d2-d;
+
+        __m128 is_zero_mask = _mm_cmpeq_ps(det,_mm_setzero_ps());
+        rd = _mm_div_ss(_mm_set_ss(1.f),_mm_or_ps(_mm_andnot_ps(is_zero_mask, det), _mm_and_ps(is_zero_mask, _mm_set_ss(1.f))));
 #ifdef ZERO_SINGULAR
-		rd = _mm_and_ps(_mm_cmpneq_ss(det,_mm_setzero_ps()), rd);
+        rd = _mm_and_ps(_mm_cmpneq_ss(det,_mm_setzero_ps()), rd);
 #endif
 
-		//  iB = D * (A#B)# = D*B#*A
-		iB.setMul(D, _mm_shuffle_ps(AB,AB,0x33));
-		iB.sub(_mm_mul_ps(_mm_shuffle_ps(D,D,0xB1), _mm_shuffle_ps(AB,AB,0x66)));
-		//  iC = A * (D#C)# = A*C#*D
-		iC.setMul(A, _mm_shuffle_ps(DC,DC,0x33));
-		iC.sub(_mm_mul_ps(_mm_shuffle_ps(A,A,0xB1), _mm_shuffle_ps(DC,DC,0x66)));
-
-		rd = _mm_shuffle_ps(rd,rd,0);
-		rd = _mm_xor_ps(rd, _mm_load_ps((const float*)Sign_PNNP));
-
-		//  iB = C*|B| - D*B#*A
-		iB.setSub(_mm_mul_ps(C,_mm_shuffle_ps(dB,dB,0)), iB);
-
-		//  iC = B*|C| - A*C#*D;
-		iC.setSub(_mm_mul_ps(B,_mm_shuffle_ps(dC,dC,0)), iC);
-
-
-		//  iX = iX / det
-		iA.mul(rd);
-		iB.mul(rd);
-		iC.mul(rd);
-		iD.mul(rd);
-
-		mMatrix[0] = _mm_shuffle_ps(iA,iB,0x77);
-		mMatrix[1] = _mm_shuffle_ps(iA,iB,0x22);
-		mMatrix[2] = _mm_shuffle_ps(iC,iD,0x77);
-		mMatrix[3] = _mm_shuffle_ps(iC,iD,0x22);
-		
-		F32 ret;
-		_mm_store_ss(&ret,det);
-		return ret;
-	}
-
-	void mulBoundBox(const LLVector4a *in_extents, LLVector4a *out_extents) const
-	{
-		//get 8 corners of bounding box
-		LLVector4Logical mask[6];
-
-		for (auto& i : mask)
+        //  iB = D * (A#B)# = D*B#*A
+        iB.setMul(D, _mm_shuffle_ps(AB,AB,0x33));
+        iB.sub(_mm_mul_ps(_mm_shuffle_ps(D,D,0xB1), _mm_shuffle_ps(AB,AB,0x66)));
+        //  iC = A * (D#C)# = A*C#*D
+        iC.setMul(A, _mm_shuffle_ps(DC,DC,0x33));
+        iC.sub(_mm_mul_ps(_mm_shuffle_ps(A,A,0xB1), _mm_shuffle_ps(DC,DC,0x66)));
+
+        rd = _mm_shuffle_ps(rd,rd,0);
+        rd = _mm_xor_ps(rd, _mm_load_ps((const float*)Sign_PNNP));
+
+        //  iB = C*|B| - D*B#*A
+        iB.setSub(_mm_mul_ps(C,_mm_shuffle_ps(dB,dB,0)), iB);
+
+        //  iC = B*|C| - A*C#*D;
+        iC.setSub(_mm_mul_ps(B,_mm_shuffle_ps(dC,dC,0)), iC);
+
+
+        //  iX = iX / det
+        iA.mul(rd);
+        iB.mul(rd);
+        iC.mul(rd);
+        iD.mul(rd);
+
+        mMatrix[0] = _mm_shuffle_ps(iA,iB,0x77);
+        mMatrix[1] = _mm_shuffle_ps(iA,iB,0x22);
+        mMatrix[2] = _mm_shuffle_ps(iC,iD,0x77);
+        mMatrix[3] = _mm_shuffle_ps(iC,iD,0x22);
+
+        F32 ret;
+        _mm_store_ss(&ret,det);
+        return ret;
+    }
+
+    void mulBoundBox(const LLVector4a *in_extents, LLVector4a *out_extents) const
+    {
+        //get 8 corners of bounding box
+        LLVector4Logical mask[6];
+
+        for (auto& i : mask)
         {
             i.clear();
-		}
-
-		mask[0].setElement<2>(); //001
-		mask[1].setElement<1>(); //010
-		mask[2].setElement<1>(); //011
-		mask[2].setElement<2>();
-		mask[3].setElement<0>(); //100
-		mask[4].setElement<0>(); //101
-		mask[4].setElement<2>();
-		mask[5].setElement<0>(); //110
-		mask[5].setElement<1>();
-
-		LLVector4a v[8];
-
-		v[6] = in_extents[0];
-		v[7] = in_extents[1];
-
-		for (U32 i = 0; i < 6; ++i)
-		{
-			v[i].setSelectWithMask(mask[i], in_extents[0], in_extents[1]);
-		}
-
-		LLVector4a tv[8];
-
-		//transform bounding box into drawable space
-		for (U32 i = 0; i < 8; ++i)
-		{
-			affineTransform(v[i], tv[i]);
-		}
-
-		//find bounding box
-		out_extents[0] = out_extents[1] = tv[0];
-
-		for (U32 i = 1; i < 8; ++i)
-		{
-			out_extents[0].setMin(out_extents[0], tv[i]);
-			out_extents[1].setMax(out_extents[1], tv[i]);
-		}
-	}
-	//=============Affine transformation matrix only=========================
-
-	//Multiply matrix with a pure translation matrix.
-	inline void applyTranslation_affine(const F32& x, const F32& y, const F32& z)
-	{
-		const LLVector4a xyz0(x,y,z,0);	//load
-		LLVector4a xxxx;
-		xxxx.splat<0>(xyz0);
-		LLVector4a yyyy;
-		yyyy.splat<1>(xyz0);
-		LLVector4a zzzz;
-		zzzz.splat<2>(xyz0);
-
-		LLVector4a sum1;
-		LLVector4a sum2;
-		LLVector4a sum3;
-
-		sum1.setMul(xxxx,mMatrix[0]);
-		sum2.setMul(yyyy,mMatrix[1]);
-		sum3.setMul(zzzz,mMatrix[2]);
-
-		mMatrix[3].add(sum1);
-		mMatrix[3].add(sum2);
-		mMatrix[3].add(sum3);
-	}
-
-	//Multiply matrix with a pure translation matrix.
-	inline void applyTranslation_affine(const LLVector3& trans)
-	{
-		applyTranslation_affine(trans.mV[VX],trans.mV[VY],trans.mV[VZ]);
-	}
-
-	//Multiply matrix with a pure scale matrix.
-	inline void applyScale_affine(const F32& x, const F32& y, const F32& z)
-	{
-		const LLVector4a xyz0(x,y,z,0);	//load
-		LLVector4a xxxx;
-		xxxx.splat<0>(xyz0);
-		LLVector4a yyyy;
-		yyyy.splat<1>(xyz0);
-		LLVector4a zzzz;
-		zzzz.splat<2>(xyz0);
-
-		mMatrix[0].mul(xxxx);
-		mMatrix[1].mul(yyyy);
-		mMatrix[2].mul(zzzz);
-	}
-
-	//Multiply matrix with a pure scale matrix.
-	inline void applyScale_affine(const LLVector3& scale)
-	{
-		applyScale_affine(scale.mV[VX],scale.mV[VY],scale.mV[VZ]);
-	}
-
-	//Multiply matrix with a pure scale matrix.
-	inline void applyScale_affine(const F32& s)
-	{
-		const LLVector4a scale(s);	//load
-		mMatrix[0].mul(scale);
-		mMatrix[1].mul(scale);
-		mMatrix[2].mul(scale);
-	}
-
-	//Direct addition to row3.
-	inline void translate_affine(const LLVector3& trans)
-	{
-		LLVector4a translation;
-		translation.load3(trans.mV);
-		mMatrix[3].add(translation);
-	}
-
-	//Direct assignment of row3.
-	inline void setTranslate_affine(const LLVector3& trans)
-	{
-		const LLVector4Logical mask = _mm_load_ps((F32*)&S_V4LOGICAL_MASK_TABLE[3*4]);
-
-		LLVector4a translation;
-		translation.load3(trans.mV);
-		
-		mMatrix[3].setSelectWithMask(mask,mMatrix[3],translation);
-	}
-
-	inline void mul_affine(const LLMatrix4a& rhs)
-	{
-		LLVector4a x0,y0,z0;
-		LLVector4a x1,y1,z1;
-		LLVector4a x2,y2,z2;
-		LLVector4a x3,y3,z3;
-
-		//12 shuffles
-		x0.splat<0>(rhs.mMatrix[0]);
-		x1.splat<0>(rhs.mMatrix[1]);
-		x2.splat<0>(rhs.mMatrix[2]);
-		x3.splat<0>(rhs.mMatrix[3]);
-
-		y0.splat<1>(rhs.mMatrix[0]);
-		y1.splat<1>(rhs.mMatrix[1]);
-		y2.splat<1>(rhs.mMatrix[2]);
-		y3.splat<1>(rhs.mMatrix[3]);
-
-		z0.splat<2>(rhs.mMatrix[0]);
-		z1.splat<2>(rhs.mMatrix[1]);
-		z2.splat<2>(rhs.mMatrix[2]);
-		z3.splat<2>(rhs.mMatrix[3]);
-
-		//12 muls
-		x0.mul(mMatrix[0]);
-		x1.mul(mMatrix[0]);
-		x2.mul(mMatrix[0]);
-		x3.mul(mMatrix[0]);
-
-		y0.mul(mMatrix[1]);
-		y1.mul(mMatrix[1]);
-		y2.mul(mMatrix[1]);
-		y3.mul(mMatrix[1]);
-
-		z0.mul(mMatrix[2]);
-		z1.mul(mMatrix[2]);
-		z2.mul(mMatrix[2]);
-		z3.mul(mMatrix[2]);
-
-		//9 adds
-		x0.add(y0);
-
-		x1.add(y1);
-
-		x2.add(y2);
-
-		x3.add(y3);
-		z3.add(mMatrix[3]);
-
-		mMatrix[0].setAdd(x0,z0);
-		mMatrix[1].setAdd(x1,z1);
-		mMatrix[2].setAdd(x2,z2);
-		mMatrix[3].setAdd(x3,z3);
-	}
-
-	inline void extractRotation_affine()
-	{
-		const LLVector4Logical mask = _mm_load_ps((F32*)&S_V4LOGICAL_MASK_TABLE[3*4]);
-		mMatrix[0].setSelectWithMask(mask,_mm_setzero_ps(),mMatrix[0]);
-		mMatrix[1].setSelectWithMask(mask,_mm_setzero_ps(),mMatrix[1]);
-		mMatrix[2].setSelectWithMask(mask,_mm_setzero_ps(),mMatrix[2]);
-		mMatrix[3].setSelectWithMask(mask,LLVector4a(1.f),_mm_setzero_ps());
-	}
-
-	//======================Logic====================
+        }
+
+        mask[0].setElement<2>(); //001
+        mask[1].setElement<1>(); //010
+        mask[2].setElement<1>(); //011
+        mask[2].setElement<2>();
+        mask[3].setElement<0>(); //100
+        mask[4].setElement<0>(); //101
+        mask[4].setElement<2>();
+        mask[5].setElement<0>(); //110
+        mask[5].setElement<1>();
+
+        LLVector4a v[8];
+
+        v[6] = in_extents[0];
+        v[7] = in_extents[1];
+
+        for (U32 i = 0; i < 6; ++i)
+        {
+            v[i].setSelectWithMask(mask[i], in_extents[0], in_extents[1]);
+        }
+
+        LLVector4a tv[8];
+
+        //transform bounding box into drawable space
+        for (U32 i = 0; i < 8; ++i)
+        {
+            affineTransform(v[i], tv[i]);
+        }
+
+        //find bounding box
+        out_extents[0] = out_extents[1] = tv[0];
+
+        for (U32 i = 1; i < 8; ++i)
+        {
+            out_extents[0].setMin(out_extents[0], tv[i]);
+            out_extents[1].setMax(out_extents[1], tv[i]);
+        }
+    }
+    //=============Affine transformation matrix only=========================
+
+    //Multiply matrix with a pure translation matrix.
+    inline void applyTranslation_affine(const F32& x, const F32& y, const F32& z)
+    {
+        const LLVector4a xyz0(x,y,z,0); //load
+        LLVector4a xxxx;
+        xxxx.splat<0>(xyz0);
+        LLVector4a yyyy;
+        yyyy.splat<1>(xyz0);
+        LLVector4a zzzz;
+        zzzz.splat<2>(xyz0);
+
+        LLVector4a sum1;
+        LLVector4a sum2;
+        LLVector4a sum3;
+
+        sum1.setMul(xxxx,mMatrix[0]);
+        sum2.setMul(yyyy,mMatrix[1]);
+        sum3.setMul(zzzz,mMatrix[2]);
+
+        mMatrix[3].add(sum1);
+        mMatrix[3].add(sum2);
+        mMatrix[3].add(sum3);
+    }
+
+    //Multiply matrix with a pure translation matrix.
+    inline void applyTranslation_affine(const LLVector3& trans)
+    {
+        applyTranslation_affine(trans.mV[VX],trans.mV[VY],trans.mV[VZ]);
+    }
+
+    //Multiply matrix with a pure scale matrix.
+    inline void applyScale_affine(const F32& x, const F32& y, const F32& z)
+    {
+        const LLVector4a xyz0(x,y,z,0); //load
+        LLVector4a xxxx;
+        xxxx.splat<0>(xyz0);
+        LLVector4a yyyy;
+        yyyy.splat<1>(xyz0);
+        LLVector4a zzzz;
+        zzzz.splat<2>(xyz0);
+
+        mMatrix[0].mul(xxxx);
+        mMatrix[1].mul(yyyy);
+        mMatrix[2].mul(zzzz);
+    }
+
+    //Multiply matrix with a pure scale matrix.
+    inline void applyScale_affine(const LLVector3& scale)
+    {
+        applyScale_affine(scale.mV[VX],scale.mV[VY],scale.mV[VZ]);
+    }
+
+    //Multiply matrix with a pure scale matrix.
+    inline void applyScale_affine(const F32& s)
+    {
+        const LLVector4a scale(s);  //load
+        mMatrix[0].mul(scale);
+        mMatrix[1].mul(scale);
+        mMatrix[2].mul(scale);
+    }
+
+    //Direct addition to row3.
+    inline void translate_affine(const LLVector3& trans)
+    {
+        LLVector4a translation;
+        translation.load3(trans.mV);
+        mMatrix[3].add(translation);
+    }
+
+    //Direct assignment of row3.
+    inline void setTranslate_affine(const LLVector3& trans)
+    {
+        const LLVector4Logical mask = _mm_load_ps((F32*)&S_V4LOGICAL_MASK_TABLE[3*4]);
+
+        LLVector4a translation;
+        translation.load3(trans.mV);
+
+        mMatrix[3].setSelectWithMask(mask,mMatrix[3],translation);
+    }
+
+    inline void mul_affine(const LLMatrix4a& rhs)
+    {
+        LLVector4a x0,y0,z0;
+        LLVector4a x1,y1,z1;
+        LLVector4a x2,y2,z2;
+        LLVector4a x3,y3,z3;
+
+        //12 shuffles
+        x0.splat<0>(rhs.mMatrix[0]);
+        x1.splat<0>(rhs.mMatrix[1]);
+        x2.splat<0>(rhs.mMatrix[2]);
+        x3.splat<0>(rhs.mMatrix[3]);
+
+        y0.splat<1>(rhs.mMatrix[0]);
+        y1.splat<1>(rhs.mMatrix[1]);
+        y2.splat<1>(rhs.mMatrix[2]);
+        y3.splat<1>(rhs.mMatrix[3]);
+
+        z0.splat<2>(rhs.mMatrix[0]);
+        z1.splat<2>(rhs.mMatrix[1]);
+        z2.splat<2>(rhs.mMatrix[2]);
+        z3.splat<2>(rhs.mMatrix[3]);
+
+        //12 muls
+        x0.mul(mMatrix[0]);
+        x1.mul(mMatrix[0]);
+        x2.mul(mMatrix[0]);
+        x3.mul(mMatrix[0]);
+
+        y0.mul(mMatrix[1]);
+        y1.mul(mMatrix[1]);
+        y2.mul(mMatrix[1]);
+        y3.mul(mMatrix[1]);
+
+        z0.mul(mMatrix[2]);
+        z1.mul(mMatrix[2]);
+        z2.mul(mMatrix[2]);
+        z3.mul(mMatrix[2]);
+
+        //9 adds
+        x0.add(y0);
+
+        x1.add(y1);
+
+        x2.add(y2);
+
+        x3.add(y3);
+        z3.add(mMatrix[3]);
+
+        mMatrix[0].setAdd(x0,z0);
+        mMatrix[1].setAdd(x1,z1);
+        mMatrix[2].setAdd(x2,z2);
+        mMatrix[3].setAdd(x3,z3);
+    }
+
+    inline void extractRotation_affine()
+    {
+        const LLVector4Logical mask = _mm_load_ps((F32*)&S_V4LOGICAL_MASK_TABLE[3*4]);
+        mMatrix[0].setSelectWithMask(mask,_mm_setzero_ps(),mMatrix[0]);
+        mMatrix[1].setSelectWithMask(mask,_mm_setzero_ps(),mMatrix[1]);
+        mMatrix[2].setSelectWithMask(mask,_mm_setzero_ps(),mMatrix[2]);
+        mMatrix[3].setSelectWithMask(mask,LLVector4a(1.f),_mm_setzero_ps());
+    }
+
+    //======================Logic====================
 private:
-	template<bool mins> inline void init_foos(LLMatrix4a& foos) const
-	{
-		thread_local bool done(false);
-		if (done) return;
-		const LLVector4a delta(0.0001f);
-		foos.setIdentity();
-		foos.getRow<0>().sub(delta);
-		foos.getRow<1>().sub(delta);
-		foos.getRow<2>().sub(delta);
-		foos.getRow<3>().sub(delta);
-		done = true;
-	}
+    template<bool mins> inline void init_foos(LLMatrix4a& foos) const
+    {
+        thread_local bool done(false);
+        if (done) return;
+        const LLVector4a delta(0.0001f);
+        foos.setIdentity();
+        foos.getRow<0>().sub(delta);
+        foos.getRow<1>().sub(delta);
+        foos.getRow<2>().sub(delta);
+        foos.getRow<3>().sub(delta);
+        done = true;
+    }
 
 public:
-	inline bool isIdentity() const
-	{
-		thread_local LLMatrix4a mins;
-		thread_local LLMatrix4a maxs;
+    inline bool isIdentity() const
+    {
+        thread_local LLMatrix4a mins;
+        thread_local LLMatrix4a maxs;
 
-		init_foos<false>(mins);
-		init_foos<true>(maxs);
+        init_foos<false>(mins);
+        init_foos<true>(maxs);
 
-		LLVector4a mask1 = _mm_and_ps(_mm_cmpgt_ps(mMatrix[0],mins.getRow<0>()), _mm_cmplt_ps(mMatrix[0],maxs.getRow<0>()));
-		LLVector4a mask2 = _mm_and_ps(_mm_cmpgt_ps(mMatrix[1],mins.getRow<1>()), _mm_cmplt_ps(mMatrix[1],maxs.getRow<1>()));
-		LLVector4a mask3 = _mm_and_ps(_mm_cmpgt_ps(mMatrix[2],mins.getRow<2>()), _mm_cmplt_ps(mMatrix[2],maxs.getRow<2>()));
-		LLVector4a mask4 = _mm_and_ps(_mm_cmpgt_ps(mMatrix[3],mins.getRow<3>()), _mm_cmplt_ps(mMatrix[3],maxs.getRow<3>()));
+        LLVector4a mask1 = _mm_and_ps(_mm_cmpgt_ps(mMatrix[0],mins.getRow<0>()), _mm_cmplt_ps(mMatrix[0],maxs.getRow<0>()));
+        LLVector4a mask2 = _mm_and_ps(_mm_cmpgt_ps(mMatrix[1],mins.getRow<1>()), _mm_cmplt_ps(mMatrix[1],maxs.getRow<1>()));
+        LLVector4a mask3 = _mm_and_ps(_mm_cmpgt_ps(mMatrix[2],mins.getRow<2>()), _mm_cmplt_ps(mMatrix[2],maxs.getRow<2>()));
+        LLVector4a mask4 = _mm_and_ps(_mm_cmpgt_ps(mMatrix[3],mins.getRow<3>()), _mm_cmplt_ps(mMatrix[3],maxs.getRow<3>()));
 
-		mask1 = _mm_and_ps(mask1,mask2);
-		mask2 = _mm_and_ps(mask3,mask4);
+        mask1 = _mm_and_ps(mask1,mask2);
+        mask2 = _mm_and_ps(mask3,mask4);
 
-		return _mm_movemask_epi8(_mm_castps_si128(_mm_and_ps(mask1, mask2))) == 0xFFFF;
-	}
+        return _mm_movemask_epi8(_mm_castps_si128(_mm_and_ps(mask1, mask2))) == 0xFFFF;
+    }
 };
 
 #ifndef SHOW_ASSERT
@@ -835,6 +835,6 @@ inline std::ostream& operator<<(std::ostream& s, const LLMatrix4a& m)
 {
     s << "[" << m.mMatrix[0] << ", " << m.mMatrix[1] << ", " << m.mMatrix[2] << ", " << m.mMatrix[3] << "]";
     return s;
-} 
+}
 
 #endif
diff --git a/indra/llmath/llvolume.cpp b/indra/llmath/llvolume.cpp
index ec357d24c9f276146b108e8b74bf2b165c2e32ac..8c15784a845f41505fb746570b1163c33a4fbf60 100644
--- a/indra/llmath/llvolume.cpp
+++ b/indra/llmath/llvolume.cpp
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file llvolume.cpp
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -65,7 +65,7 @@ const F32 MIN_CUT_DELTA = 0.02f;
 
 const F32 HOLLOW_MIN = 0.f;
 const F32 HOLLOW_MAX = 0.99f;
-const F32 HOLLOW_MAX_SQUARE	= 0.7f;
+const F32 HOLLOW_MAX_SQUARE = 0.7f;
 
 const F32 TWIST_MIN = -1.f;
 const F32 TWIST_MAX =  1.f;
@@ -88,8 +88,8 @@ const F32 REV_MAX = 4.f;
 const F32 TAPER_MIN = -1.f;
 const F32 TAPER_MAX =  1.f;
 
-const F32 SKEW_MIN	= -0.95f;
-const F32 SKEW_MAX	=  0.95f;
+const F32 SKEW_MIN  = -0.95f;
+const F32 SKEW_MAX  =  0.95f;
 
 const F32 SCULPT_MIN_AREA = 0.002f;
 const S32 SCULPT_MIN_AREA_DETAIL = 1;
@@ -97,283 +97,283 @@ const S32 SCULPT_MIN_AREA_DETAIL = 1;
 BOOL gDebugGL = FALSE; // See settings.xml "RenderDebugGL"
 
 BOOL check_same_clock_dir( const LLVector3& pt1, const LLVector3& pt2, const LLVector3& pt3, const LLVector3& norm)
-{    
-	LLVector3 test = (pt2-pt1)%(pt3-pt2);
-
-	//answer
-	if(test * norm < 0) 
-	{
-		return FALSE;
-	}
-	else 
-	{
-		return TRUE;
-	}
-} 
+{
+    LLVector3 test = (pt2-pt1)%(pt3-pt2);
+
+    //answer
+    if(test * norm < 0)
+    {
+        return FALSE;
+    }
+    else
+    {
+        return TRUE;
+    }
+}
 
 BOOL LLLineSegmentBoxIntersect(const LLVector3& start, const LLVector3& end, const LLVector3& center, const LLVector3& size)
 {
-	return LLLineSegmentBoxIntersect(start.mV, end.mV, center.mV, size.mV);
+    return LLLineSegmentBoxIntersect(start.mV, end.mV, center.mV, size.mV);
 }
 
 BOOL LLLineSegmentBoxIntersect(const F32* start, const F32* end, const F32* center, const F32* size)
 {
-	F32 fAWdU[3];
-	F32 dir[3];
-	F32 diff[3];
+    F32 fAWdU[3];
+    F32 dir[3];
+    F32 diff[3];
 
-	for (U32 i = 0; i < 3; i++)
-	{
-		dir[i] = 0.5f * (end[i] - start[i]);
-		diff[i] = (0.5f * (end[i] + start[i])) - center[i];
-		fAWdU[i] = fabsf(dir[i]);
-		if(fabsf(diff[i])>size[i] + fAWdU[i]) return false;
-	}
+    for (U32 i = 0; i < 3; i++)
+    {
+        dir[i] = 0.5f * (end[i] - start[i]);
+        diff[i] = (0.5f * (end[i] + start[i])) - center[i];
+        fAWdU[i] = fabsf(dir[i]);
+        if(fabsf(diff[i])>size[i] + fAWdU[i]) return false;
+    }
 
-	float f;
-	f = dir[1] * diff[2] - dir[2] * diff[1];    if(fabsf(f)>size[1]*fAWdU[2] + size[2]*fAWdU[1])  return false;
-	f = dir[2] * diff[0] - dir[0] * diff[2];    if(fabsf(f)>size[0]*fAWdU[2] + size[2]*fAWdU[0])  return false;
-	f = dir[0] * diff[1] - dir[1] * diff[0];    if(fabsf(f)>size[0]*fAWdU[1] + size[1]*fAWdU[0])  return false;
-	
-	return true;
+    float f;
+    f = dir[1] * diff[2] - dir[2] * diff[1];    if(fabsf(f)>size[1]*fAWdU[2] + size[2]*fAWdU[1])  return false;
+    f = dir[2] * diff[0] - dir[0] * diff[2];    if(fabsf(f)>size[0]*fAWdU[2] + size[2]*fAWdU[0])  return false;
+    f = dir[0] * diff[1] - dir[1] * diff[0];    if(fabsf(f)>size[0]*fAWdU[1] + size[1]*fAWdU[0])  return false;
+
+    return true;
 }
 
 // Finds tangent vec based on three vertices with texture coordinates.
 // Fills in dummy values if the triangle has degenerate texture coordinates.
 void calc_tangent_from_triangle(
-	LLVector4a&			normal,
-	LLVector4a&			tangent_out,
-	const LLVector4a& v1,
-	const LLVector2&  w1,
-	const LLVector4a& v2,
-	const LLVector2&  w2,
-	const LLVector4a& v3,
-	const LLVector2&  w3)
-{
-	const F32* v1ptr = v1.getF32ptr();
-	const F32* v2ptr = v2.getF32ptr();
-	const F32* v3ptr = v3.getF32ptr();
+    LLVector4a&         normal,
+    LLVector4a&         tangent_out,
+    const LLVector4a& v1,
+    const LLVector2&  w1,
+    const LLVector4a& v2,
+    const LLVector2&  w2,
+    const LLVector4a& v3,
+    const LLVector2&  w3)
+{
+    const F32* v1ptr = v1.getF32ptr();
+    const F32* v2ptr = v2.getF32ptr();
+    const F32* v3ptr = v3.getF32ptr();
+
+    float x1 = v2ptr[0] - v1ptr[0];
+    float x2 = v3ptr[0] - v1ptr[0];
+    float y1 = v2ptr[1] - v1ptr[1];
+    float y2 = v3ptr[1] - v1ptr[1];
+    float z1 = v2ptr[2] - v1ptr[2];
+    float z2 = v3ptr[2] - v1ptr[2];
+
+    float s1 = w2.mV[0] - w1.mV[0];
+    float s2 = w3.mV[0] - w1.mV[0];
+    float t1 = w2.mV[1] - w1.mV[1];
+    float t2 = w3.mV[1] - w1.mV[1];
+
+    F32 rd = s1*t2-s2*t1;
+
+    float r = ((rd*rd) > FLT_EPSILON) ? (1.0f / rd)
+                                                : ((rd > 0.0f) ? 1024.f : -1024.f); //some made up large ratio for division by zero
+
+    llassert(llfinite(r));
+    llassert(!llisnan(r));
+
+    LLVector4a sdir(
+        (t2 * x1 - t1 * x2) * r,
+        (t2 * y1 - t1 * y2) * r,
+        (t2 * z1 - t1 * z2) * r);
+
+    LLVector4a tdir(
+        (s1 * x2 - s2 * x1) * r,
+        (s1 * y2 - s2 * y1) * r,
+        (s1 * z2 - s2 * z1) * r);
+
+    LLVector4a  n = normal;
+    LLVector4a  t = sdir;
+
+    LLVector4a ncrosst;
+    ncrosst.setCross3(n,t);
+
+    // Gram-Schmidt orthogonalize
+    n.mul(n.dot3(t).getF32());
+
+    LLVector4a tsubn;
+    tsubn.setSub(t,n);
+
+    if (tsubn.dot3(tsubn).getF32() > F_APPROXIMATELY_ZERO)
+    {
+        tsubn.normalize3fast_checked();
 
-	float x1 = v2ptr[0] - v1ptr[0];
-	float x2 = v3ptr[0] - v1ptr[0];
-	float y1 = v2ptr[1] - v1ptr[1];
-	float y2 = v3ptr[1] - v1ptr[1];
-	float z1 = v2ptr[2] - v1ptr[2];
-	float z2 = v3ptr[2] - v1ptr[2];
+        // Calculate handedness
+        F32 handedness = ncrosst.dot3(tdir).getF32() < 0.f ? -1.f : 1.f;
 
-	float s1 = w2.mV[0] - w1.mV[0];
-	float s2 = w3.mV[0] - w1.mV[0];
-	float t1 = w2.mV[1] - w1.mV[1];
-	float t2 = w3.mV[1] - w1.mV[1];
+        tsubn.getF32ptr()[3] = handedness;
 
-	F32 rd = s1*t2-s2*t1;
+        tangent_out = tsubn;
+    }
+    else
+    {
+        // degenerate, make up a value
+        //
+        tangent_out.set(0,0,1,1);
+    }
 
-	float r = ((rd*rd) > FLT_EPSILON) ? (1.0f / rd)
-											    : ((rd > 0.0f) ? 1024.f : -1024.f); //some made up large ratio for division by zero
+}
 
-	llassert(llfinite(r));
-	llassert(!llisnan(r));
 
-	LLVector4a sdir(
-		(t2 * x1 - t1 * x2) * r,
-		(t2 * y1 - t1 * y2) * r,
-		(t2 * z1 - t1 * z2) * r);
+// intersect test between triangle vert0, vert1, vert2 and a ray from orig in direction dir.
+// returns TRUE if intersecting and returns barycentric coordinates in intersection_a, intersection_b,
+// and returns the intersection point along dir in intersection_t.
 
-	LLVector4a tdir(
-		(s1 * x2 - s2 * x1) * r,
-		(s1 * y2 - s2 * y1) * r,
-		(s1 * z2 - s2 * z1) * r);
+// Moller-Trumbore algorithm
+BOOL LLTriangleRayIntersect(const LLVector4a& vert0, const LLVector4a& vert1, const LLVector4a& vert2, const LLVector4a& orig, const LLVector4a& dir,
+                            F32& intersection_a, F32& intersection_b, F32& intersection_t)
+{
 
-	LLVector4a	n = normal;
-	LLVector4a	t = sdir;
+    /* find vectors for two edges sharing vert0 */
+    LLVector4a edge1;
+    edge1.setSub(vert1, vert0);
 
-	LLVector4a ncrosst;
-	ncrosst.setCross3(n,t);
+    LLVector4a edge2;
+    edge2.setSub(vert2, vert0);
 
-	// Gram-Schmidt orthogonalize
-	n.mul(n.dot3(t).getF32());
+    /* begin calculating determinant - also used to calculate U parameter */
+    LLVector4a pvec;
+    pvec.setCross3(dir, edge2);
 
-	LLVector4a tsubn;
-	tsubn.setSub(t,n);
+    /* if determinant is near zero, ray lies in plane of triangle */
+    LLVector4a det;
+    det.setAllDot3(edge1, pvec);
 
-	if (tsubn.dot3(tsubn).getF32() > F_APPROXIMATELY_ZERO)
-	{
-		tsubn.normalize3fast_checked();
+    if (det.greaterEqual(LLVector4a::getEpsilon()).getGatheredBits() & 0x7)
+    {
+        /* calculate distance from vert0 to ray origin */
+        LLVector4a tvec;
+        tvec.setSub(orig, vert0);
 
-		// Calculate handedness
-		F32 handedness = ncrosst.dot3(tdir).getF32() < 0.f ? -1.f : 1.f;
+        /* calculate U parameter and test bounds */
+        LLVector4a u;
+        u.setAllDot3(tvec,pvec);
 
-		tsubn.getF32ptr()[3] = handedness;
+        if ((u.greaterEqual(LLVector4a::getZero()).getGatheredBits() & 0x7) &&
+            (u.lessEqual(det).getGatheredBits() & 0x7))
+        {
+            /* prepare to test V parameter */
+            LLVector4a qvec;
+            qvec.setCross3(tvec, edge1);
 
-		tangent_out = tsubn;
-	}
-	else
-	{
-		// degenerate, make up a value
-		//
-		tangent_out.set(0,0,1,1);
-	}
+            /* calculate V parameter and test bounds */
+            LLVector4a v;
+            v.setAllDot3(dir, qvec);
 
-}
 
+            //if (!(v < 0.f || u + v > det))
 
-// intersect test between triangle vert0, vert1, vert2 and a ray from orig in direction dir.
-// returns TRUE if intersecting and returns barycentric coordinates in intersection_a, intersection_b,
-// and returns the intersection point along dir in intersection_t.
+            LLVector4a sum_uv;
+            sum_uv.setAdd(u, v);
 
-// Moller-Trumbore algorithm
-BOOL LLTriangleRayIntersect(const LLVector4a& vert0, const LLVector4a& vert1, const LLVector4a& vert2, const LLVector4a& orig, const LLVector4a& dir,
-							F32& intersection_a, F32& intersection_b, F32& intersection_t)
-{
-	
-	/* find vectors for two edges sharing vert0 */
-	LLVector4a edge1;
-	edge1.setSub(vert1, vert0);
-	
-	LLVector4a edge2;
-	edge2.setSub(vert2, vert0);
-
-	/* begin calculating determinant - also used to calculate U parameter */
-	LLVector4a pvec;
-	pvec.setCross3(dir, edge2);
-
-	/* if determinant is near zero, ray lies in plane of triangle */
-	LLVector4a det;
-	det.setAllDot3(edge1, pvec);
-	
-	if (det.greaterEqual(LLVector4a::getEpsilon()).getGatheredBits() & 0x7)
-	{
-		/* calculate distance from vert0 to ray origin */
-		LLVector4a tvec;
-		tvec.setSub(orig, vert0);
-
-		/* calculate U parameter and test bounds */
-		LLVector4a u;
-		u.setAllDot3(tvec,pvec);
-
-		if ((u.greaterEqual(LLVector4a::getZero()).getGatheredBits() & 0x7) &&
-			(u.lessEqual(det).getGatheredBits() & 0x7))
-		{
-			/* prepare to test V parameter */
-			LLVector4a qvec;
-			qvec.setCross3(tvec, edge1);
-			
-			/* calculate V parameter and test bounds */
-			LLVector4a v;
-			v.setAllDot3(dir, qvec);
-
-			
-			//if (!(v < 0.f || u + v > det))
-
-			LLVector4a sum_uv;
-			sum_uv.setAdd(u, v);
-
-			S32 v_gequal = v.greaterEqual(LLVector4a::getZero()).getGatheredBits() & 0x7;
-			S32 sum_lequal = sum_uv.lessEqual(det).getGatheredBits() & 0x7;
-
-			if (v_gequal  && sum_lequal)
-			{
-				/* calculate t, scale parameters, ray intersects triangle */
-				LLVector4a t;
-				t.setAllDot3(edge2,qvec);
-
-				t.div(det);
-				u.div(det);
-				v.div(det);
-				
-				intersection_a = u[0];
-				intersection_b = v[0];
-				intersection_t = t[0];
-				return TRUE;
-			}
-		}
-	}
-		
-	return FALSE;
-} 
+            S32 v_gequal = v.greaterEqual(LLVector4a::getZero()).getGatheredBits() & 0x7;
+            S32 sum_lequal = sum_uv.lessEqual(det).getGatheredBits() & 0x7;
+
+            if (v_gequal  && sum_lequal)
+            {
+                /* calculate t, scale parameters, ray intersects triangle */
+                LLVector4a t;
+                t.setAllDot3(edge2,qvec);
+
+                t.div(det);
+                u.div(det);
+                v.div(det);
+
+                intersection_a = u[0];
+                intersection_b = v[0];
+                intersection_t = t[0];
+                return TRUE;
+            }
+        }
+    }
+
+    return FALSE;
+}
 
 BOOL LLTriangleRayIntersectTwoSided(const LLVector4a& vert0, const LLVector4a& vert1, const LLVector4a& vert2, const LLVector4a& orig, const LLVector4a& dir,
-							F32& intersection_a, F32& intersection_b, F32& intersection_t)
-{
-	F32 u, v, t;
-	
-	/* find vectors for two edges sharing vert0 */
-	LLVector4a edge1;
-	edge1.setSub(vert1, vert0);
-	
-	
-	LLVector4a edge2;
-	edge2.setSub(vert2, vert0);
-
-	/* begin calculating determinant - also used to calculate U parameter */
-	LLVector4a pvec;
-	pvec.setCross3(dir, edge2);
-
-	/* if determinant is near zero, ray lies in plane of triangle */
-	F32 det = edge1.dot3(pvec).getF32();
-
-	
-	if (det > -F_APPROXIMATELY_ZERO && det < F_APPROXIMATELY_ZERO)
-	{
-		return FALSE;
-	}
-
-	F32 inv_det = 1.f / det;
-
-	/* calculate distance from vert0 to ray origin */
-	LLVector4a tvec;
-	tvec.setSub(orig, vert0);
-	
-	/* calculate U parameter and test bounds */
-	u = (tvec.dot3(pvec).getF32()) * inv_det;
-	if (u < 0.f || u > 1.f)
-	{
-		return FALSE;
-	}
-
-	/* prepare to test V parameter */
-	tvec.sub(edge1);
-		
-	/* calculate V parameter and test bounds */
-	v = (dir.dot3(tvec).getF32()) * inv_det;
-	
-	if (v < 0.f || u + v > 1.f)
-	{
-		return FALSE;
-	}
-
-	/* calculate t, ray intersects triangle */
-	t = (edge2.dot3(tvec).getF32()) * inv_det;
-	
-	intersection_a = u;
-	intersection_b = v;
-	intersection_t = t;
-	
-	
-	return TRUE;
-} 
+                            F32& intersection_a, F32& intersection_b, F32& intersection_t)
+{
+    F32 u, v, t;
+
+    /* find vectors for two edges sharing vert0 */
+    LLVector4a edge1;
+    edge1.setSub(vert1, vert0);
+
+
+    LLVector4a edge2;
+    edge2.setSub(vert2, vert0);
+
+    /* begin calculating determinant - also used to calculate U parameter */
+    LLVector4a pvec;
+    pvec.setCross3(dir, edge2);
+
+    /* if determinant is near zero, ray lies in plane of triangle */
+    F32 det = edge1.dot3(pvec).getF32();
+
+
+    if (det > -F_APPROXIMATELY_ZERO && det < F_APPROXIMATELY_ZERO)
+    {
+        return FALSE;
+    }
+
+    F32 inv_det = 1.f / det;
+
+    /* calculate distance from vert0 to ray origin */
+    LLVector4a tvec;
+    tvec.setSub(orig, vert0);
+
+    /* calculate U parameter and test bounds */
+    u = (tvec.dot3(pvec).getF32()) * inv_det;
+    if (u < 0.f || u > 1.f)
+    {
+        return FALSE;
+    }
+
+    /* prepare to test V parameter */
+    tvec.sub(edge1);
+
+    /* calculate V parameter and test bounds */
+    v = (dir.dot3(tvec).getF32()) * inv_det;
+
+    if (v < 0.f || u + v > 1.f)
+    {
+        return FALSE;
+    }
+
+    /* calculate t, ray intersects triangle */
+    t = (edge2.dot3(tvec).getF32()) * inv_det;
+
+    intersection_a = u;
+    intersection_b = v;
+    intersection_t = t;
+
+
+    return TRUE;
+}
 
 //helper for non-aligned vectors
 BOOL LLTriangleRayIntersect(const LLVector3& vert0, const LLVector3& vert1, const LLVector3& vert2, const LLVector3& orig, const LLVector3& dir,
-							F32& intersection_a, F32& intersection_b, F32& intersection_t, BOOL two_sided)
-{
-	LLVector4a vert0a, vert1a, vert2a, origa, dira;
-	vert0a.load3(vert0.mV);
-	vert1a.load3(vert1.mV);
-	vert2a.load3(vert2.mV);
-	origa.load3(orig.mV);
-	dira.load3(dir.mV);
-
-	if (two_sided)
-	{
-		return LLTriangleRayIntersectTwoSided(vert0a, vert1a, vert2a, origa, dira, 
-				intersection_a, intersection_b, intersection_t);
-	}
-	else
-	{
-		return LLTriangleRayIntersect(vert0a, vert1a, vert2a, origa, dira, 
-				intersection_a, intersection_b, intersection_t);
-	}
+                            F32& intersection_a, F32& intersection_b, F32& intersection_t, BOOL two_sided)
+{
+    LLVector4a vert0a, vert1a, vert2a, origa, dira;
+    vert0a.load3(vert0.mV);
+    vert1a.load3(vert1.mV);
+    vert2a.load3(vert2.mV);
+    origa.load3(orig.mV);
+    dira.load3(dir.mV);
+
+    if (two_sided)
+    {
+        return LLTriangleRayIntersectTwoSided(vert0a, vert1a, vert2a, origa, dira,
+                intersection_a, intersection_b, intersection_t);
+    }
+    else
+    {
+        return LLTriangleRayIntersect(vert0a, vert1a, vert2a, origa, dira,
+                intersection_a, intersection_b, intersection_t);
+    }
 }
 
 //-------------------------------------------------------------------
@@ -385,5156 +385,5156 @@ BOOL LLTriangleRayIntersect(const LLVector3& vert0, const LLVector3& vert1, cons
 
 LLProfile::Face* LLProfile::addCap(S16 faceID)
 {
-	Face *face   = vector_append(mFaces, 1);
-	
-	face->mIndex = 0;
-	face->mCount = mTotal;
-	face->mScaleU= 1.0f;
-	face->mCap   = TRUE;
-	face->mFaceID = faceID;
-	return face;
+    Face *face   = vector_append(mFaces, 1);
+
+    face->mIndex = 0;
+    face->mCount = mTotal;
+    face->mScaleU= 1.0f;
+    face->mCap   = TRUE;
+    face->mFaceID = faceID;
+    return face;
 }
 
 LLProfile::Face* LLProfile::addFace(S32 i, S32 count, F32 scaleU, S16 faceID, BOOL flat)
 {
-	Face *face   = vector_append(mFaces, 1);
-	
-	face->mIndex = i;
-	face->mCount = count;
-	face->mScaleU= scaleU;
+    Face *face   = vector_append(mFaces, 1);
 
-	face->mFlat = flat;
-	face->mCap   = FALSE;
-	face->mFaceID = faceID;
-	return face;
+    face->mIndex = i;
+    face->mCount = count;
+    face->mScaleU= scaleU;
+
+    face->mFlat = flat;
+    face->mCap   = FALSE;
+    face->mFaceID = faceID;
+    return face;
 }
 
 //static
 S32 LLProfile::getNumNGonPoints(const LLProfileParams& params, S32 sides, F32 offset, F32 bevel, F32 ang_scale, S32 split)
 { // this is basically LLProfile::genNGon stripped down to only the operations that influence the number of points
-	S32 np = 0;
-
-	// Generate an n-sided "circular" path.
-	// 0 is (1,0), and we go counter-clockwise along a circular path from there.
-	F32 t, t_step, t_first, t_fraction;
-	
-	F32 begin  = params.getBegin();
-	F32 end    = params.getEnd();
-
-	t_step = 1.0f / sides;
-	
-	t_first = floor(begin * sides) / (F32)sides;
-
-	// pt1 is the first point on the fractional face.
-	// Starting t and ang values for the first face
-	t = t_first;
-	
-	// Increment to the next point.
-	// pt2 is the end point on the fractional face
-	t += t_step;
-	
-	t_fraction = (begin - t_first)*sides;
-
-	// Only use if it's not almost exactly on an edge.
-	if (t_fraction < 0.9999f)
-	{
-		np++;
-	}
-
-	// There's lots of potential here for floating point error to generate unneeded extra points - DJS 04/05/02
-	while (t < end)
-	{
-		// Iterate through all the integer steps of t.
-		np++;
-
-		t += t_step;
-	}
-
-	// Find the fraction that we need to add to the end point.
-	t_fraction = (end - (t - t_step))*sides;
-	if (t_fraction > 0.0001f)
-	{
-		np++;
-	}
-
-	// If we're sliced, the profile is open.
-	if ((end - begin)*ang_scale < 0.99f)
-	{
-		if (params.getHollow() <= 0)
-		{
-			// put center point if not hollow.
-			np++;
-		}
-	}
-	
-	return np;
-}
+    S32 np = 0;
 
-// What is the bevel parameter used for? - DJS 04/05/02
-// Bevel parameter is currently unused but presumedly would support
-// filleted and chamfered corners
-void LLProfile::genNGon(const LLProfileParams& params, S32 sides, F32 offset, F32 bevel, F32 ang_scale, S32 split)
-{
-	// Generate an n-sided "circular" path.
-	// 0 is (1,0), and we go counter-clockwise along a circular path from there.
-	static const F32 tableScale[] = { 1, 1, 1, 0.5f, 0.707107f, 0.53f, 0.525f, 0.5f };
-	F32 scale = 0.5f;
-	F32 t, t_step, t_first, t_fraction, ang, ang_step;
-	LLVector4a pt1,pt2;
-
-	F32 begin  = params.getBegin();
-	F32 end    = params.getEnd();
-
-	t_step = 1.0f / sides;
-	ang_step = 2.0f*F_PI*t_step*ang_scale;
-
-	// Scale to have size "match" scale.  Compensates to get object to generally fill bounding box.
-
-	S32 total_sides = ll_round(sides / ang_scale);	// Total number of sides all around
-
-	if (total_sides < 8)
-	{
-		scale = tableScale[total_sides];
-	}
-
-	t_first = floor(begin * sides) / (F32)sides;
-
-	// pt1 is the first point on the fractional face.
-	// Starting t and ang values for the first face
-	t = t_first;
-	ang = 2.0f*F_PI*(t*ang_scale + offset);
-	pt1.set(cos(ang)*scale,sin(ang)*scale, t);
-
-	// Increment to the next point.
-	// pt2 is the end point on the fractional face
-	t += t_step;
-	ang += ang_step;
-	pt2.set(cos(ang)*scale,sin(ang)*scale,t);
-
-	t_fraction = (begin - t_first)*sides;
-
-	// Only use if it's not almost exactly on an edge.
-	if (t_fraction < 0.9999f)
-	{
-		LLVector4a new_pt;
-		new_pt.setLerp(pt1, pt2, t_fraction);
-		mProfile.push_back(new_pt);
-	}
-
-	// There's lots of potential here for floating point error to generate unneeded extra points - DJS 04/05/02
-	while (t < end)
-	{
-		// Iterate through all the integer steps of t.
-		pt1.set(cos(ang)*scale,sin(ang)*scale,t);
-
-		if (mProfile.size() > 0) {
-			LLVector4a p = mProfile[mProfile.size()-1];
-			for (S32 i = 0; i < split && mProfile.size() > 0; i++) {
-				//mProfile.push_back(p+(pt1-p) * 1.0f/(float)(split+1) * (float)(i+1));
-				LLVector4a new_pt;
-				new_pt.setSub(pt1, p);
-				new_pt.mul(1.0f/(float)(split+1) * (float)(i+1));
-				new_pt.add(p);
-				mProfile.push_back(new_pt);
-			}
-		}
-		mProfile.push_back(pt1);
-
-		t += t_step;
-		ang += ang_step;
-	}
-
-	t_fraction = (end - (t - t_step))*sides;
-
-	// pt1 is the first point on the fractional face
-	// pt2 is the end point on the fractional face
-	pt2.set(cos(ang)*scale,sin(ang)*scale,t);
-
-	// Find the fraction that we need to add to the end point.
-	t_fraction = (end - (t - t_step))*sides;
-	if (t_fraction > 0.0001f)
-	{
-		LLVector4a new_pt;
-		new_pt.setLerp(pt1, pt2, t_fraction);
-		
-		if (mProfile.size() > 0) {
-			LLVector4a p = mProfile[mProfile.size()-1];
-			for (S32 i = 0; i < split && mProfile.size() > 0; i++) {
-				//mProfile.push_back(p+(new_pt-p) * 1.0f/(float)(split+1) * (float)(i+1));
-
-				LLVector4a pt1;
-				pt1.setSub(new_pt, p);
-				pt1.mul(1.0f/(float)(split+1) * (float)(i+1));
-				pt1.add(p);
-				mProfile.push_back(pt1);
-			}
-		}
-		mProfile.push_back(new_pt);
-	}
-
-	// If we're sliced, the profile is open.
-	if ((end - begin)*ang_scale < 0.99f)
-	{
-		if ((end - begin)*ang_scale > 0.5f)
-		{
-			mConcave = TRUE;
-		}
-		else
-		{
-			mConcave = FALSE;
-		}
-		mOpen = TRUE;
-		if (params.getHollow() <= 0)
-		{
-			// put center point if not hollow.
-			mProfile.push_back(LLVector4a(0,0,0));
-		}
-	}
-	else
-	{
-		// The profile isn't open.
-		mOpen = FALSE;
-		mConcave = FALSE;
-	}
-
-	mTotal = mProfile.size();
-}
+    // Generate an n-sided "circular" path.
+    // 0 is (1,0), and we go counter-clockwise along a circular path from there.
+    F32 t, t_step, t_first, t_fraction;
 
-// Hollow is percent of the original bounding box, not of this particular
-// profile's geometry.  Thus, a swept triangle needs lower hollow values than
-// a swept square.
-LLProfile::Face* LLProfile::addHole(const LLProfileParams& params, BOOL flat, F32 sides, F32 offset, F32 box_hollow, F32 ang_scale, S32 split)
-{
-	// Note that addHole will NOT work for non-"circular" profiles, if we ever decide to use them.
+    F32 begin  = params.getBegin();
+    F32 end    = params.getEnd();
 
-	// Total add has number of vertices on outside.
-	mTotalOut = mTotal;
+    t_step = 1.0f / sides;
 
-	// Why is the "bevel" parameter -1? DJS 04/05/02
-	genNGon(params, llfloor(sides),offset,-1, ang_scale, split);
+    t_first = floor(begin * sides) / (F32)sides;
 
-	Face *face = addFace(mTotalOut, mTotal-mTotalOut,0,LL_FACE_INNER_SIDE, flat);
+    // pt1 is the first point on the fractional face.
+    // Starting t and ang values for the first face
+    t = t_first;
 
-	static thread_local LLAlignedArray<LLVector4a,64> pt;
-	pt.resize(mTotal) ;
+    // Increment to the next point.
+    // pt2 is the end point on the fractional face
+    t += t_step;
 
-	for (S32 i=mTotalOut;i<mTotal;i++)
-	{
-		pt[i] = mProfile[i];
-		pt[i].mul(box_hollow);
-	}
+    t_fraction = (begin - t_first)*sides;
 
-	S32 j=mTotal-1;
-	for (S32 i=mTotalOut;i<mTotal;i++)
-	{
-		mProfile[i] = pt[j--];
-	}
+    // Only use if it's not almost exactly on an edge.
+    if (t_fraction < 0.9999f)
+    {
+        np++;
+    }
 
-	for (S32 i=0;i<(S32)mFaces.size();i++) 
-	{
-		if (mFaces[i].mCap)
-		{
-			mFaces[i].mCount *= 2;
-		}
-	}
+    // There's lots of potential here for floating point error to generate unneeded extra points - DJS 04/05/02
+    while (t < end)
+    {
+        // Iterate through all the integer steps of t.
+        np++;
 
-	return face;
-}
+        t += t_step;
+    }
 
-//static
-S32 LLProfile::getNumPoints(const LLProfileParams& params, BOOL path_open,F32 detail, S32 split,
-						 BOOL is_sculpted, S32 sculpt_size)
-{ // this is basically LLProfile::generate stripped down to only operations that influence the number of points
-	if (detail < MIN_LOD)
-	{
-		detail = MIN_LOD;
-	}
-
-	// Generate the face data
-	F32 hollow = params.getHollow();
-
-	S32 np = 0;
-
-	switch (params.getCurveType() & LL_PCODE_PROFILE_MASK)
-	{
-	case LL_PCODE_PROFILE_SQUARE:
-		{
-			np = getNumNGonPoints(params, 4,-0.375, 0, 1, split);
-		
-			if (hollow)
-			{
-				np *= 2;
-			}
-		}
-		break;
-	case  LL_PCODE_PROFILE_ISOTRI:
-	case  LL_PCODE_PROFILE_RIGHTTRI:
-	case  LL_PCODE_PROFILE_EQUALTRI:
-		{
-			np = getNumNGonPoints(params, 3,0, 0, 1, split);
-						
-			if (hollow)
-			{
-				np *= 2;
-			}
-		}
-		break;
-	case LL_PCODE_PROFILE_CIRCLE:
-		{
-			// If this has a square hollow, we should adjust the
-			// number of faces a bit so that the geometry lines up.
-			U8 hole_type=0;
-			F32 circle_detail = MIN_DETAIL_FACES * detail;
-			if (hollow)
-			{
-				hole_type = params.getCurveType() & LL_PCODE_HOLE_MASK;
-				if (hole_type == LL_PCODE_HOLE_SQUARE)
-				{
-					// Snap to the next multiple of four sides,
-					// so that corners line up.
-					circle_detail = llceil(circle_detail / 4.0f) * 4.0f;
-				}
-			}
-
-			S32 sides = (S32)circle_detail;
-
-			if (is_sculpted)
-				sides = sculpt_size;
-			
-			np = getNumNGonPoints(params, sides);
-			
-			if (hollow)
-			{
-				np *= 2;
-			}
-		}
-		break;
-	case LL_PCODE_PROFILE_CIRCLE_HALF:
-		{
-			// If this has a square hollow, we should adjust the
-			// number of faces a bit so that the geometry lines up.
-			U8 hole_type=0;
-			// Number of faces is cut in half because it's only a half-circle.
-			F32 circle_detail = MIN_DETAIL_FACES * detail * 0.5f;
-			if (hollow)
-			{
-				hole_type = params.getCurveType() & LL_PCODE_HOLE_MASK;
-				if (hole_type == LL_PCODE_HOLE_SQUARE)
-				{
-					// Snap to the next multiple of four sides (div 2),
-					// so that corners line up.
-					circle_detail = llceil(circle_detail / 2.0f) * 2.0f;
-				}
-			}
-			np = getNumNGonPoints(params, llfloor(circle_detail), 0.5f, 0.f, 0.5f);
-			
-			if (hollow)
-			{
-				np *= 2;
-			}
-
-			// Special case for openness of sphere
-			if ((params.getEnd() - params.getBegin()) < 1.f)
-			{
-			}
-			else if (!hollow)
-			{
-				np++;
-			}
-		}
-		break;
-	default:
-	   break;
-	};
-
-	
-	return np;
-}
+    // Find the fraction that we need to add to the end point.
+    t_fraction = (end - (t - t_step))*sides;
+    if (t_fraction > 0.0001f)
+    {
+        np++;
+    }
 
+    // If we're sliced, the profile is open.
+    if ((end - begin)*ang_scale < 0.99f)
+    {
+        if (params.getHollow() <= 0)
+        {
+            // put center point if not hollow.
+            np++;
+        }
+    }
 
-BOOL LLProfile::generate(const LLProfileParams& params, BOOL path_open,F32 detail, S32 split,
-						 BOOL is_sculpted, S32 sculpt_size)
-{
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
-
-	if ((!mDirty) && (!is_sculpted))
-	{
-		return FALSE;
-	}
-	mDirty = FALSE;
-
-	if (detail < MIN_LOD)
-	{
-		LL_INFOS() << "Generating profile with LOD < MIN_LOD.  CLAMPING" << LL_ENDL;
-		detail = MIN_LOD;
-	}
-
-	mProfile.resize(0);
-	mFaces.resize(0);
-
-	// Generate the face data
-	S32 i;
-	F32 begin = params.getBegin();
-	F32 end = params.getEnd();
-	F32 hollow = params.getHollow();
-
-	// Quick validation to eliminate some server crashes.
-	if (begin > end - 0.01f)
-	{
-		LL_WARNS() << "LLProfile::generate() assertion failed (begin >= end)" << LL_ENDL;
-		return FALSE;
-	}
-
-	S32 face_num = 0;
-
-	switch (params.getCurveType() & LL_PCODE_PROFILE_MASK)
-	{
-	case LL_PCODE_PROFILE_SQUARE:
-		{
-			genNGon(params, 4,-0.375, 0, 1, split);
-			if (path_open)
-			{
-				addCap (LL_FACE_PATH_BEGIN);
-			}
-
-			for (i = llfloor(begin * 4.f); i < llfloor(end * 4.f + .999f); i++)
-			{
-				addFace((face_num++) * (split +1), split+2, 1, LL_FACE_OUTER_SIDE_0 << i, TRUE);
-			}
-
-			LLVector4a scale(1,1,4,1);
-
-			for (i = 0; i <(S32) mProfile.size(); i++)
-			{
-				// Scale by 4 to generate proper tex coords.
-				mProfile[i].mul(scale);
-				llassert(mProfile[i].isFinite3());
-			}
-
-			if (hollow)
-			{
-				switch (params.getCurveType() & LL_PCODE_HOLE_MASK)
-				{
-				case LL_PCODE_HOLE_TRIANGLE:
-					// This offset is not correct, but we can't change it now... DK 11/17/04
-				  	addHole(params, TRUE, 3, -0.375f, hollow, 1.f, split);
-					break;
-				case LL_PCODE_HOLE_CIRCLE:
-					// TODO: Compute actual detail levels for cubes
-				  	addHole(params, FALSE, MIN_DETAIL_FACES * detail, -0.375f, hollow, 1.f);
-					break;
-				case LL_PCODE_HOLE_SAME:
-				case LL_PCODE_HOLE_SQUARE:
-				default:
-					addHole(params, TRUE, 4, -0.375f, hollow, 1.f, split);
-					break;
-				}
-			}
-			
-			if (path_open) {
-				mFaces[0].mCount = mTotal;
-			}
-		}
-		break;
-	case  LL_PCODE_PROFILE_ISOTRI:
-	case  LL_PCODE_PROFILE_RIGHTTRI:
-	case  LL_PCODE_PROFILE_EQUALTRI:
-		{
-			genNGon(params, 3,0, 0, 1, split);
-			LLVector4a scale(1,1,3,1);
-			for (i = 0; i <(S32) mProfile.size(); i++)
-			{
-				// Scale by 3 to generate proper tex coords.
-				mProfile[i].mul(scale);
-				llassert(mProfile[i].isFinite3());
-			}
-
-			if (path_open)
-			{
-				addCap(LL_FACE_PATH_BEGIN);
-			}
-
-			for (i = llfloor(begin * 3.f); i < llfloor(end * 3.f + .999f); i++)
-			{
-				addFace((face_num++) * (split +1), split+2, 1, LL_FACE_OUTER_SIDE_0 << i, TRUE);
-			}
-			if (hollow)
-			{
-				// Swept triangles need smaller hollowness values,
-				// because the triangle doesn't fill the bounding box.
-				F32 triangle_hollow = hollow / 2.f;
-
-				switch (params.getCurveType() & LL_PCODE_HOLE_MASK)
-				{
-				case LL_PCODE_HOLE_CIRCLE:
-					// TODO: Actually generate level of detail for triangles
-					addHole(params, FALSE, MIN_DETAIL_FACES * detail, 0, triangle_hollow, 1.f);
-					break;
-				case LL_PCODE_HOLE_SQUARE:
-					addHole(params, TRUE, 4, 0, triangle_hollow, 1.f, split);
-					break;
-				case LL_PCODE_HOLE_SAME:
-				case LL_PCODE_HOLE_TRIANGLE:
-				default:
-					addHole(params, TRUE, 3, 0, triangle_hollow, 1.f, split);
-					break;
-				}
-			}
-		}
-		break;
-	case LL_PCODE_PROFILE_CIRCLE:
-		{
-			// If this has a square hollow, we should adjust the
-			// number of faces a bit so that the geometry lines up.
-			U8 hole_type=0;
-			F32 circle_detail = MIN_DETAIL_FACES * detail;
-			if (hollow)
-			{
-				hole_type = params.getCurveType() & LL_PCODE_HOLE_MASK;
-				if (hole_type == LL_PCODE_HOLE_SQUARE)
-				{
-					// Snap to the next multiple of four sides,
-					// so that corners line up.
-					circle_detail = llceil(circle_detail / 4.0f) * 4.0f;
-				}
-			}
-
-			S32 sides = (S32)circle_detail;
-
-			if (is_sculpted)
-				sides = sculpt_size;
-			
-			genNGon(params, sides);
-			
-			if (path_open)
-			{
-				addCap (LL_FACE_PATH_BEGIN);
-			}
-
-			if (mOpen && !hollow)
-			{
-				addFace(0,mTotal-1,0,LL_FACE_OUTER_SIDE_0, FALSE);
-			}
-			else
-			{
-				addFace(0,mTotal,0,LL_FACE_OUTER_SIDE_0, FALSE);
-			}
-
-			if (hollow)
-			{
-				switch (hole_type)
-				{
-				case LL_PCODE_HOLE_SQUARE:
-					addHole(params, TRUE, 4, 0, hollow, 1.f, split);
-					break;
-				case LL_PCODE_HOLE_TRIANGLE:
-					addHole(params, TRUE, 3, 0, hollow, 1.f, split);
-					break;
-				case LL_PCODE_HOLE_CIRCLE:
-				case LL_PCODE_HOLE_SAME:
-				default:
-					addHole(params, FALSE, circle_detail, 0, hollow, 1.f);
-					break;
-				}
-			}
-		}
-		break;
-	case LL_PCODE_PROFILE_CIRCLE_HALF:
-		{
-			// If this has a square hollow, we should adjust the
-			// number of faces a bit so that the geometry lines up.
-			U8 hole_type=0;
-			// Number of faces is cut in half because it's only a half-circle.
-			F32 circle_detail = MIN_DETAIL_FACES * detail * 0.5f;
-			if (hollow)
-			{
-				hole_type = params.getCurveType() & LL_PCODE_HOLE_MASK;
-				if (hole_type == LL_PCODE_HOLE_SQUARE)
-				{
-					// Snap to the next multiple of four sides (div 2),
-					// so that corners line up.
-					circle_detail = llceil(circle_detail / 2.0f) * 2.0f;
-				}
-			}
-			genNGon(params, llfloor(circle_detail), 0.5f, 0.f, 0.5f);
-			if (path_open)
-			{
-				addCap(LL_FACE_PATH_BEGIN);
-			}
-			if (mOpen && !params.getHollow())
-			{
-				addFace(0,mTotal-1,0,LL_FACE_OUTER_SIDE_0, FALSE);
-			}
-			else
-			{
-				addFace(0,mTotal,0,LL_FACE_OUTER_SIDE_0, FALSE);
-			}
-
-			if (hollow)
-			{
-				switch (hole_type)
-				{
-				case LL_PCODE_HOLE_SQUARE:
-					addHole(params, TRUE, 2, 0.5f, hollow, 0.5f, split);
-					break;
-				case LL_PCODE_HOLE_TRIANGLE:
-					addHole(params, TRUE, 3,  0.5f, hollow, 0.5f, split);
-					break;
-				case LL_PCODE_HOLE_CIRCLE:
-				case LL_PCODE_HOLE_SAME:
-				default:
-					addHole(params, FALSE, circle_detail,  0.5f, hollow, 0.5f);
-					break;
-				}
-			}
-
-			// Special case for openness of sphere
-			if ((params.getEnd() - params.getBegin()) < 1.f)
-			{
-				mOpen = TRUE;
-			}
-			else if (!hollow)
-			{
-				mOpen = FALSE;
-				mProfile.push_back(mProfile[0]);
-				mTotal++;
-			}
-		}
-		break;
-	default:
-	    LL_ERRS() << "Unknown profile: getCurveType()=" << params.getCurveType() << LL_ENDL;
-		break;
-	};
-
-	if (path_open)
-	{
-		addCap(LL_FACE_PATH_END); // bottom
-	}
-	
-	if ( mOpen) // interior edge caps
-	{
-		addFace(mTotal-1, 2,0.5,LL_FACE_PROFILE_BEGIN, TRUE); 
-
-		if (hollow)
-		{
-			addFace(mTotalOut-1, 2,0.5,LL_FACE_PROFILE_END, TRUE);
-		}
-		else
-		{
-			addFace(mTotal-2, 2,0.5,LL_FACE_PROFILE_END, TRUE);
-		}
-	}
-	
-	return TRUE;
+    return np;
 }
 
-
-
-BOOL LLProfileParams::importFile(LLFILE *fp)
+// What is the bevel parameter used for? - DJS 04/05/02
+// Bevel parameter is currently unused but presumedly would support
+// filleted and chamfered corners
+void LLProfile::genNGon(const LLProfileParams& params, S32 sides, F32 offset, F32 bevel, F32 ang_scale, S32 split)
 {
-	const S32 BUFSIZE = 16384;
-	char buffer[BUFSIZE];	/* Flawfinder: ignore */
-	// *NOTE: changing the size or type of these buffers will require
-	// changing the sscanf below.
-	char keyword[256];	/* Flawfinder: ignore */
-	char valuestr[256];	/* Flawfinder: ignore */
-	keyword[0] = 0;
-	valuestr[0] = 0;
-	F32 tempF32;
-	U32 tempU32;
-
-	while (!feof(fp))
-	{
-		if (fgets(buffer, BUFSIZE, fp) == NULL)
-		{
-			buffer[0] = '\0';
-		}
-		
-		sscanf(	/* Flawfinder: ignore */
-			buffer,
-			" %255s %255s",
-			keyword, valuestr);
-		if (!strcmp("{", keyword))
-		{
-			continue;
-		}
-		if (!strcmp("}",keyword))
-		{
-			break;
-		}
-		else if (!strcmp("curve", keyword))
-		{
-			sscanf(valuestr,"%d",&tempU32);
-			setCurveType((U8) tempU32);
-		}
-		else if (!strcmp("begin",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setBegin(tempF32);
-		}
-		else if (!strcmp("end",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setEnd(tempF32);
-		}
-		else if (!strcmp("hollow",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setHollow(tempF32);
-		}
-		else
-		{
-			LL_WARNS() << "unknown keyword " << keyword << " in profile import" << LL_ENDL;
-		}
-	}
-
-	return TRUE;
-}
-
+    // Generate an n-sided "circular" path.
+    // 0 is (1,0), and we go counter-clockwise along a circular path from there.
+    static const F32 tableScale[] = { 1, 1, 1, 0.5f, 0.707107f, 0.53f, 0.525f, 0.5f };
+    F32 scale = 0.5f;
+    F32 t, t_step, t_first, t_fraction, ang, ang_step;
+    LLVector4a pt1,pt2;
 
-BOOL LLProfileParams::exportFile(LLFILE *fp) const
-{
-	fprintf(fp,"\t\tprofile 0\n");
-	fprintf(fp,"\t\t{\n");
-	fprintf(fp,"\t\t\tcurve\t%d\n", getCurveType());
-	fprintf(fp,"\t\t\tbegin\t%g\n", getBegin());
-	fprintf(fp,"\t\t\tend\t%g\n", getEnd());
-	fprintf(fp,"\t\t\thollow\t%g\n", getHollow());
-	fprintf(fp, "\t\t}\n");
-	return TRUE;
-}
+    F32 begin  = params.getBegin();
+    F32 end    = params.getEnd();
 
+    t_step = 1.0f / sides;
+    ang_step = 2.0f*F_PI*t_step*ang_scale;
 
-BOOL LLProfileParams::importLegacyStream(std::istream& input_stream)
-{
-	const S32 BUFSIZE = 16384;
-	char buffer[BUFSIZE];	/* Flawfinder: ignore */
-	// *NOTE: changing the size or type of these buffers will require
-	// changing the sscanf below.
-	char keyword[256];	/* Flawfinder: ignore */
-	char valuestr[256];	/* Flawfinder: ignore */
-	keyword[0] = 0;
-	valuestr[0] = 0;
-	F32 tempF32;
-	U32 tempU32;
-
-	while (input_stream.good())
-	{
-		input_stream.getline(buffer, BUFSIZE);
-		sscanf(	/* Flawfinder: ignore */
-			buffer,
-			" %255s %255s",
-			keyword,
-			valuestr);
-		if (!strcmp("{", keyword))
-		{
-			continue;
-		}
-		if (!strcmp("}",keyword))
-		{
-			break;
-		}
-		else if (!strcmp("curve", keyword))
-		{
-			sscanf(valuestr,"%d",&tempU32);
-			setCurveType((U8) tempU32);
-		}
-		else if (!strcmp("begin",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setBegin(tempF32);
-		}
-		else if (!strcmp("end",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setEnd(tempF32);
-		}
-		else if (!strcmp("hollow",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setHollow(tempF32);
-		}
-		else
-		{
- 		LL_WARNS() << "unknown keyword " << keyword << " in profile import" << LL_ENDL;
-		}
-	}
-
-	return TRUE;
-}
+    // Scale to have size "match" scale.  Compensates to get object to generally fill bounding box.
 
+    S32 total_sides = ll_round(sides / ang_scale);  // Total number of sides all around
 
-BOOL LLProfileParams::exportLegacyStream(std::ostream& output_stream) const
-{
-	output_stream <<"\t\tprofile 0\n";
-	output_stream <<"\t\t{\n";
-	output_stream <<"\t\t\tcurve\t" << (S32) getCurveType() << "\n";
-	output_stream <<"\t\t\tbegin\t" << getBegin() << "\n";
-	output_stream <<"\t\t\tend\t" << getEnd() << "\n";
-	output_stream <<"\t\t\thollow\t" << getHollow() << "\n";
-	output_stream << "\t\t}\n";
-	return TRUE;
-}
+    if (total_sides < 8)
+    {
+        scale = tableScale[total_sides];
+    }
 
-LLSD LLProfileParams::asLLSD() const
-{
-	LLSD sd;
+    t_first = floor(begin * sides) / (F32)sides;
 
-	sd["curve"] = getCurveType();
-	sd["begin"] = getBegin();
-	sd["end"] = getEnd();
-	sd["hollow"] = getHollow();
-	return sd;
-}
+    // pt1 is the first point on the fractional face.
+    // Starting t and ang values for the first face
+    t = t_first;
+    ang = 2.0f*F_PI*(t*ang_scale + offset);
+    pt1.set(cos(ang)*scale,sin(ang)*scale, t);
 
-bool LLProfileParams::fromLLSD(LLSD& sd)
-{
-	setCurveType(sd["curve"].asInteger());
-	setBegin((F32)sd["begin"].asReal());
-	setEnd((F32)sd["end"].asReal());
-	setHollow((F32)sd["hollow"].asReal());
-	return true;
-}
+    // Increment to the next point.
+    // pt2 is the end point on the fractional face
+    t += t_step;
+    ang += ang_step;
+    pt2.set(cos(ang)*scale,sin(ang)*scale,t);
 
-void LLProfileParams::copyParams(const LLProfileParams &params)
-{
-	setCurveType(params.getCurveType());
-	setBegin(params.getBegin());
-	setEnd(params.getEnd());
-	setHollow(params.getHollow());
-}
+    t_fraction = (begin - t_first)*sides;
 
+    // Only use if it's not almost exactly on an edge.
+    if (t_fraction < 0.9999f)
+    {
+        LLVector4a new_pt;
+        new_pt.setLerp(pt1, pt2, t_fraction);
+        mProfile.push_back(new_pt);
+    }
 
-S32 LLPath::getNumNGonPoints(const LLPathParams& params, S32 sides, F32 startOff, F32 end_scale, F32 twist_scale)
-{ //this is basically LLPath::genNGon stripped down to only operations that influence the number of points added
-	S32 ret = 0;
+    // There's lots of potential here for floating point error to generate unneeded extra points - DJS 04/05/02
+    while (t < end)
+    {
+        // Iterate through all the integer steps of t.
+        pt1.set(cos(ang)*scale,sin(ang)*scale,t);
+
+        if (mProfile.size() > 0) {
+            LLVector4a p = mProfile[mProfile.size()-1];
+            for (S32 i = 0; i < split && mProfile.size() > 0; i++) {
+                //mProfile.push_back(p+(pt1-p) * 1.0f/(float)(split+1) * (float)(i+1));
+                LLVector4a new_pt;
+                new_pt.setSub(pt1, p);
+                new_pt.mul(1.0f/(float)(split+1) * (float)(i+1));
+                new_pt.add(p);
+                mProfile.push_back(new_pt);
+            }
+        }
+        mProfile.push_back(pt1);
 
-	F32 step= 1.0f / sides;
-	F32 t	= params.getBegin();
-	ret = 1;
-	
-	t+=step;
+        t += t_step;
+        ang += ang_step;
+    }
 
-	// Snap to a quantized parameter, so that cut does not
-	// affect most sample points.
-	t = ((S32)(t * sides)) / (F32)sides;
+    t_fraction = (end - (t - t_step))*sides;
 
-	// Run through the non-cut dependent points.
-	while (t < params.getEnd())
-	{
-		ret++;
-		t+=step;
-	}
+    // pt1 is the first point on the fractional face
+    // pt2 is the end point on the fractional face
+    pt2.set(cos(ang)*scale,sin(ang)*scale,t);
 
-	ret++;
+    // Find the fraction that we need to add to the end point.
+    t_fraction = (end - (t - t_step))*sides;
+    if (t_fraction > 0.0001f)
+    {
+        LLVector4a new_pt;
+        new_pt.setLerp(pt1, pt2, t_fraction);
+
+        if (mProfile.size() > 0) {
+            LLVector4a p = mProfile[mProfile.size()-1];
+            for (S32 i = 0; i < split && mProfile.size() > 0; i++) {
+                //mProfile.push_back(p+(new_pt-p) * 1.0f/(float)(split+1) * (float)(i+1));
+
+                LLVector4a pt1;
+                pt1.setSub(new_pt, p);
+                pt1.mul(1.0f/(float)(split+1) * (float)(i+1));
+                pt1.add(p);
+                mProfile.push_back(pt1);
+            }
+        }
+        mProfile.push_back(new_pt);
+    }
 
-	return ret;
-}
+    // If we're sliced, the profile is open.
+    if ((end - begin)*ang_scale < 0.99f)
+    {
+        if ((end - begin)*ang_scale > 0.5f)
+        {
+            mConcave = TRUE;
+        }
+        else
+        {
+            mConcave = FALSE;
+        }
+        mOpen = TRUE;
+        if (params.getHollow() <= 0)
+        {
+            // put center point if not hollow.
+            mProfile.push_back(LLVector4a(0,0,0));
+        }
+    }
+    else
+    {
+        // The profile isn't open.
+        mOpen = FALSE;
+        mConcave = FALSE;
+    }
 
-void LLPath::genNGon(const LLPathParams& params, S32 sides, F32 startOff, F32 end_scale, F32 twist_scale)
-{
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
-
-	// Generates a circular path, starting at (1, 0, 0), counterclockwise along the xz plane.
-	static const F32 tableScale[] = { 1, 1, 1, 0.5f, 0.707107f, 0.53f, 0.525f, 0.5f };
-
-	F32 revolutions = params.getRevolutions();
-	F32 skew		= params.getSkew();
-	F32 skew_mag	= fabs(skew);
-	F32 hole_x		= params.getScaleX() * (1.0f - skew_mag);
-	F32 hole_y		= params.getScaleY();
-
-	// Calculate taper begin/end for x,y (Negative means taper the beginning)
-	F32 taper_x_begin	= 1.0f;
-	F32 taper_x_end		= 1.0f - params.getTaperX();
-	F32	taper_y_begin	= 1.0f;
-	F32	taper_y_end		= 1.0f - params.getTaperY();
-
-	if ( taper_x_end > 1.0f )
-	{
-		// Flip tapering.
-		taper_x_begin	= 2.0f - taper_x_end;
-		taper_x_end		= 1.0f;
-	}
-	if ( taper_y_end > 1.0f )
-	{
-		// Flip tapering.
-		taper_y_begin	= 2.0f - taper_y_end;
-		taper_y_end		= 1.0f;
-	}
-
-	// For spheres, the radius is usually zero.
-	F32 radius_start = 0.5f;
-	if (sides < 8)
-	{
-		radius_start = tableScale[sides];
-	}
-
-	// Scale the radius to take the hole size into account.
-	radius_start *= 1.0f - hole_y;
-	
-	// Now check the radius offset to calculate the start,end radius.  (Negative means
-	// decrease the start radius instead).
-	F32 radius_end    = radius_start;
-	F32 radius_offset = params.getRadiusOffset();
-	if (radius_offset < 0.f)
-	{
-		radius_start *= 1.f + radius_offset;
-	}
-	else
-	{
-		radius_end   *= 1.f - radius_offset;
-	}	
-
-	// Is the path NOT a closed loop?
-	mOpen = ( (params.getEnd()*end_scale - params.getBegin() < 1.0f) ||
-		      (skew_mag > 0.001f) ||
-			  (fabs(taper_x_end - taper_x_begin) > 0.001f) ||
-			  (fabs(taper_y_end - taper_y_begin) > 0.001f) ||
-			  (fabs(radius_end - radius_start) > 0.001f) );
-
-	F32 ang, c, s;
-	LLQuaternion twist, qang;
-	PathPt *pt;
-	LLVector3 path_axis (1.f, 0.f, 0.f);
-	//LLVector3 twist_axis(0.f, 0.f, 1.f);
-	F32 twist_begin = params.getTwistBegin() * twist_scale;
-	F32 twist_end	= params.getTwist() * twist_scale;
-
-	// We run through this once before the main loop, to make sure
-	// the path begins at the correct cut.
-	F32 step= 1.0f / sides;
-	F32 t	= params.getBegin();
-	pt		= mPath.append(1);
-	ang		= 2.0f*F_PI*revolutions * t;
-	s		= sin(ang)*ll_lerp(radius_start, radius_end, t);
-	c		= cos(ang)*ll_lerp(radius_start, radius_end, t);
-
-
-	const LLVector2& shearval = params.getShear();
-	pt->mPos.set(0 + ll_lerp(0,shearval.mV[0],s)
-					  + ll_lerp(-skew ,skew, t) * 0.5f,
-					c + ll_lerp(0,shearval.mV[1],s),
-					s);
-	pt->mScale.set(hole_x * ll_lerp(taper_x_begin, taper_x_end, t),
-		hole_y * ll_lerp(taper_y_begin, taper_y_end, t),
-		0,1);
-	pt->mTexT  = t;
-
-	// Twist rotates the path along the x,y plane (I think) - DJS 04/05/02
-	twist.setQuat  (ll_lerp(twist_begin,twist_end,t) * 2.f * F_PI - F_PI,0,0,1);
-	// Rotate the point around the circle's center.
-	qang.setQuat   (ang,path_axis);
-
-	LLMatrix3 rot(twist * qang);
-
-	pt->mRot.loadu(rot);
-
-	t+=step;
-
-	// Snap to a quantized parameter, so that cut does not
-	// affect most sample points.
-	t = ((S32)(t * sides)) / (F32)sides;
-
-	// Run through the non-cut dependent points.
-	while (t < params.getEnd())
-	{
-		pt		= mPath.append(1);
-
-		ang = 2.0f*F_PI*revolutions * t;
-		c   = cos(ang)*ll_lerp(radius_start, radius_end, t);
-		s   = sin(ang)*ll_lerp(radius_start, radius_end, t);
-
-		pt->mPos.set(0 + ll_lerp(0,params.getShear().mV[0],s)
-					      + ll_lerp(-skew ,skew, t) * 0.5f,
-						c + ll_lerp(0,params.getShear().mV[1],s),
-						s);
-
-		pt->mScale.set(hole_x * ll_lerp(taper_x_begin, taper_x_end, t),
-					hole_y * ll_lerp(taper_y_begin, taper_y_end, t),
-					0,1);
-		pt->mTexT  = t;
-
-		// Twist rotates the path along the x,y plane (I think) - DJS 04/05/02
-		twist.setQuat  (ll_lerp(twist_begin,twist_end,t) * 2.f * F_PI - F_PI,0,0,1);
-		// Rotate the point around the circle's center.
-		qang.setQuat   (ang,path_axis);
-		LLMatrix3 tmp(twist*qang);
-		pt->mRot.loadu(tmp);
-
-		t+=step;
-	}
-
-	// Make one final pass for the end cut.
-	t = params.getEnd();
-	pt		= mPath.append(1);
-	ang = 2.0f*F_PI*revolutions * t;
-	c   = cos(ang)*ll_lerp(radius_start, radius_end, t);
-	s   = sin(ang)*ll_lerp(radius_start, radius_end, t);
-
-	pt->mPos.set(0 + ll_lerp(0,params.getShear().mV[0],s)
-					  + ll_lerp(-skew ,skew, t) * 0.5f,
-					c + ll_lerp(0,params.getShear().mV[1],s),
-					s);
-	pt->mScale.set(hole_x * ll_lerp(taper_x_begin, taper_x_end, t),
-				   hole_y * ll_lerp(taper_y_begin, taper_y_end, t),
-				   0,1);
-	pt->mTexT  = t;
-
-	// Twist rotates the path along the x,y plane (I think) - DJS 04/05/02
-	twist.setQuat  (ll_lerp(twist_begin,twist_end,t) * 2.f * F_PI - F_PI,0,0,1);
-	// Rotate the point around the circle's center.
-	qang.setQuat   (ang,path_axis);
-	LLMatrix3 tmp(twist*qang);
-	pt->mRot.loadu(tmp);
-
-	mTotal = mPath.size();
+    mTotal = mProfile.size();
 }
 
-const LLVector2 LLPathParams::getBeginScale() const
+// Hollow is percent of the original bounding box, not of this particular
+// profile's geometry.  Thus, a swept triangle needs lower hollow values than
+// a swept square.
+LLProfile::Face* LLProfile::addHole(const LLProfileParams& params, BOOL flat, F32 sides, F32 offset, F32 box_hollow, F32 ang_scale, S32 split)
 {
-	LLVector2 begin_scale(1.f, 1.f);
-	if (getScaleX() > 1)
-	{
-		begin_scale.mV[0] = 2-getScaleX();
-	}
-	if (getScaleY() > 1)
-	{
-		begin_scale.mV[1] = 2-getScaleY();
-	}
-	return begin_scale;
-}
+    // Note that addHole will NOT work for non-"circular" profiles, if we ever decide to use them.
 
-const LLVector2 LLPathParams::getEndScale() const
-{
-	LLVector2 end_scale(1.f, 1.f);
-	if (getScaleX() < 1)
-	{
-		end_scale.mV[0] = getScaleX();
-	}
-	if (getScaleY() < 1)
-	{
-		end_scale.mV[1] = getScaleY();
-	}
-	return end_scale;
-}
+    // Total add has number of vertices on outside.
+    mTotalOut = mTotal;
 
-S32 LLPath::getNumPoints(const LLPathParams& params, F32 detail)
-{ // this is basically LLPath::generate stripped down to only the operations that influence the number of points
-	if (detail < MIN_LOD)
-	{
-		detail = MIN_LOD;
-	}
+    // Why is the "bevel" parameter -1? DJS 04/05/02
+    genNGon(params, llfloor(sides),offset,-1, ang_scale, split);
 
-	S32 np = 2; // hardcode for line
+    Face *face = addFace(mTotalOut, mTotal-mTotalOut,0,LL_FACE_INNER_SIDE, flat);
 
-	// Is this 0xf0 mask really necessary?  DK 03/02/05
+    static thread_local LLAlignedArray<LLVector4a,64> pt;
+    pt.resize(mTotal) ;
 
-	switch (params.getCurveType() & 0xf0)
-	{
-	default:
-	case LL_PCODE_PATH_LINE:
-		{
-			// Take the begin/end twist into account for detail.
-			np    = llfloor(fabs(params.getTwistBegin() - params.getTwist()) * 3.5f * (detail-0.5f)) + 2;
-		}
-		break;
+    for (S32 i=mTotalOut;i<mTotal;i++)
+    {
+        pt[i] = mProfile[i];
+        pt[i].mul(box_hollow);
+    }
 
-	case LL_PCODE_PATH_CIRCLE:
-		{
-			// Increase the detail as the revolutions and twist increase.
-			F32 twist_mag = fabs(params.getTwistBegin() - params.getTwist());
+    S32 j=mTotal-1;
+    for (S32 i=mTotalOut;i<mTotal;i++)
+    {
+        mProfile[i] = pt[j--];
+    }
 
-			S32 sides = (S32)llfloor(llfloor((MIN_DETAIL_FACES * detail + twist_mag * 3.5f * (detail-0.5f))) * params.getRevolutions());
+    for (S32 i=0;i<(S32)mFaces.size();i++)
+    {
+        if (mFaces[i].mCap)
+        {
+            mFaces[i].mCount *= 2;
+        }
+    }
 
-			np = sides;
-		}
-		break;
+    return face;
+}
 
-	case LL_PCODE_PATH_CIRCLE2:
-		{
-			//genNGon(params, llfloor(MIN_DETAIL_FACES * detail), 4.f, 0.f);
-			np = getNumNGonPoints(params, llfloor(MIN_DETAIL_FACES * detail));
-		}
-		break;
+//static
+S32 LLProfile::getNumPoints(const LLProfileParams& params, BOOL path_open,F32 detail, S32 split,
+                         BOOL is_sculpted, S32 sculpt_size)
+{ // this is basically LLProfile::generate stripped down to only operations that influence the number of points
+    if (detail < MIN_LOD)
+    {
+        detail = MIN_LOD;
+    }
 
-	case LL_PCODE_PATH_TEST:
+    // Generate the face data
+    F32 hollow = params.getHollow();
 
-		np     = 5;
-		break;
-	};
+    S32 np = 0;
 
-	return np;
-}
+    switch (params.getCurveType() & LL_PCODE_PROFILE_MASK)
+    {
+    case LL_PCODE_PROFILE_SQUARE:
+        {
+            np = getNumNGonPoints(params, 4,-0.375, 0, 1, split);
 
-BOOL LLPath::generate(const LLPathParams& params, F32 detail, S32 split,
-					  BOOL is_sculpted, S32 sculpt_size)
-{
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
-
-	if ((!mDirty) && (!is_sculpted))
-	{
-		return FALSE;
-	}
-
-	if (detail < MIN_LOD)
-	{
-		LL_INFOS() << "Generating path with LOD < MIN!  Clamping to 1" << LL_ENDL;
-		detail = MIN_LOD;
-	}
-
-	mDirty = FALSE;
-	S32 np = 2; // hardcode for line
-
-	mPath.resize(0);
-	mOpen = TRUE;
-
-	// Is this 0xf0 mask really necessary?  DK 03/02/05
-	switch (params.getCurveType() & 0xf0)
-	{
-	default:
-	case LL_PCODE_PATH_LINE:
-		{
-			// Take the begin/end twist into account for detail.
-			np    = llfloor(fabs(params.getTwistBegin() - params.getTwist()) * 3.5f * (detail-0.5f)) + 2;
-			if (np < split+2)
-			{
-				np = split+2;
-			}
-
-			mStep = 1.0f / (np-1);
-			
-			mPath.resize(np);
-
-			LLVector2 start_scale = params.getBeginScale();
-			LLVector2 end_scale = params.getEndScale();
-
-			for (S32 i=0;i<np;i++)
-			{
-				F32 t = ll_lerp(params.getBegin(),params.getEnd(),(F32)i * mStep);
-				mPath[i].mPos.set(ll_lerp(0,params.getShear().mV[0],t),
-									 ll_lerp(0,params.getShear().mV[1],t),
-									 t - 0.5f);
-				LLQuaternion quat;
-				quat.setQuat(ll_lerp(F_PI * params.getTwistBegin(),F_PI * params.getTwist(),t),0,0,1);
-				LLMatrix3 tmp(quat);
-				mPath[i].mRot.loadu(tmp);
-				mPath[i].mScale.set(ll_lerp(start_scale.mV[0],end_scale.mV[0],t),
-									ll_lerp(start_scale.mV[1],end_scale.mV[1],t),
-									0,1);
-				mPath[i].mTexT        = t;
-			}
-		}
-		break;
-
-	case LL_PCODE_PATH_CIRCLE:
-		{
-			// Increase the detail as the revolutions and twist increase.
-			F32 twist_mag = fabs(params.getTwistBegin() - params.getTwist());
-
-			S32 sides = (S32)llfloor(llfloor((MIN_DETAIL_FACES * detail + twist_mag * 3.5f * (detail-0.5f))) * params.getRevolutions());
-
-			if (is_sculpted)
-				sides = llmax(sculpt_size, 1);
-			
-			if (0 < sides)
-				genNGon(params, sides);
-		}
-		break;
-
-	case LL_PCODE_PATH_CIRCLE2:
-		{
-			if (params.getEnd() - params.getBegin() >= 0.99f &&
-				params.getScaleX() >= .99f)
-			{
-				mOpen = FALSE;
-			}
-
-			//genNGon(params, llfloor(MIN_DETAIL_FACES * detail), 4.f, 0.f);
-			genNGon(params, llfloor(MIN_DETAIL_FACES * detail));
-
-			F32 toggle = 0.5f;
-			for (S32 i=0;i<(S32)mPath.size();i++)
-			{
-				mPath[i].mPos.getF32ptr()[0] = toggle;
-				if (toggle == 0.5f)
-					toggle = -0.5f;
-				else
-					toggle = 0.5f;
-			}
-		}
-
-		break;
-
-	case LL_PCODE_PATH_TEST:
-
-		np     = 5;
-		mStep = 1.0f / (np-1);
-		
-		mPath.resize(np);
-
-		for (S32 i=0;i<np;i++)
-		{
-			F32 t = (F32)i * mStep;
-			mPath[i].mPos.set(0,
-								ll_lerp(0,   -sin(F_PI*params.getTwist()*t)*0.5f,t),
-								ll_lerp(-0.5f, cos(F_PI*params.getTwist()*t)*0.5f,t));
-			mPath[i].mScale.set(ll_lerp(1,params.getScale().mV[0],t),
-								ll_lerp(1,params.getScale().mV[1],t), 0,1);
-			mPath[i].mTexT  = t;
-			LLQuaternion quat;
-			quat.setQuat(F_PI * params.getTwist() * t,1,0,0);
-			LLMatrix3 tmp(quat);
-			mPath[i].mRot.loadu(tmp);
-		}
-
-		break;
-	};
-
-	if (params.getTwist() != params.getTwistBegin()) mOpen = TRUE;
-
-	//if ((int(fabsf(params.getTwist() - params.getTwistBegin())*100))%100 != 0) {
-	//	mOpen = TRUE;
-	//}
-	
-	return TRUE;
-}
+            if (hollow)
+            {
+                np *= 2;
+            }
+        }
+        break;
+    case  LL_PCODE_PROFILE_ISOTRI:
+    case  LL_PCODE_PROFILE_RIGHTTRI:
+    case  LL_PCODE_PROFILE_EQUALTRI:
+        {
+            np = getNumNGonPoints(params, 3,0, 0, 1, split);
 
-BOOL LLDynamicPath::generate(const LLPathParams& params, F32 detail, S32 split,
-							 BOOL is_sculpted, S32 sculpt_size)
-{
-	mOpen = TRUE; // Draw end caps
-	if (getPathLength() == 0)
-	{
-		// Path hasn't been generated yet.
-		// Some algorithms later assume at least TWO path points.
-		resizePath(2);
-		LLQuaternion quat;
-		quat.setQuat(0,0,0);
-		LLMatrix3 tmp(quat);
+            if (hollow)
+            {
+                np *= 2;
+            }
+        }
+        break;
+    case LL_PCODE_PROFILE_CIRCLE:
+        {
+            // If this has a square hollow, we should adjust the
+            // number of faces a bit so that the geometry lines up.
+            U8 hole_type=0;
+            F32 circle_detail = MIN_DETAIL_FACES * detail;
+            if (hollow)
+            {
+                hole_type = params.getCurveType() & LL_PCODE_HOLE_MASK;
+                if (hole_type == LL_PCODE_HOLE_SQUARE)
+                {
+                    // Snap to the next multiple of four sides,
+                    // so that corners line up.
+                    circle_detail = llceil(circle_detail / 4.0f) * 4.0f;
+                }
+            }
 
-		for (U32 i = 0; i < 2; i++)
-		{
-			mPath[i].mPos.set(0, 0, 0);
-			mPath[i].mRot.loadu(tmp);
-			mPath[i].mScale.set(1, 1, 0, 1);
-			mPath[i].mTexT = 0;
-		}
-	}
+            S32 sides = (S32)circle_detail;
 
-	return TRUE;
-}
+            if (is_sculpted)
+                sides = sculpt_size;
 
+            np = getNumNGonPoints(params, sides);
 
-BOOL LLPathParams::importFile(LLFILE *fp)
-{
-	const S32 BUFSIZE = 16384;
-	char buffer[BUFSIZE];	/* Flawfinder: ignore */
-	// *NOTE: changing the size or type of these buffers will require
-	// changing the sscanf below.
-	char keyword[256];	/* Flawfinder: ignore */
-	char valuestr[256];	/* Flawfinder: ignore */
-	keyword[0] = 0;
-	valuestr[0] = 0;
-
-	F32 tempF32;
-	F32 x, y;
-	U32 tempU32;
-
-	while (!feof(fp))
-	{
-		if (fgets(buffer, BUFSIZE, fp) == NULL)
-		{
-			buffer[0] = '\0';
-		}
-		
-		sscanf(	/* Flawfinder: ignore */
-			buffer,
-			" %255s %255s",
-			keyword, valuestr);
-		if (!strcmp("{", keyword))
-		{
-			continue;
-		}
-		if (!strcmp("}",keyword))
-		{
-			break;
-		}
-		else if (!strcmp("curve", keyword))
-		{
-			sscanf(valuestr,"%d",&tempU32);
-			setCurveType((U8) tempU32);
-		}
-		else if (!strcmp("begin",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setBegin(tempF32);
-		}
-		else if (!strcmp("end",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setEnd(tempF32);
-		}
-		else if (!strcmp("scale",keyword))
-		{
-			// Legacy for one dimensional scale per path
-			sscanf(valuestr,"%g",&tempF32);
-			setScale(tempF32, tempF32);
-		}
-		else if (!strcmp("scale_x", keyword))
-		{
-			sscanf(valuestr, "%g", &x);
-			setScaleX(x);
-		}
-		else if (!strcmp("scale_y", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setScaleY(y);
-		}
-		else if (!strcmp("shear_x", keyword))
-		{
-			sscanf(valuestr, "%g", &x);
-			setShearX(x);
-		}
-		else if (!strcmp("shear_y", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setShearY(y);
-		}
-		else if (!strcmp("twist",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setTwist(tempF32);
-		}
-		else if (!strcmp("twist_begin", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setTwistBegin(y);
-		}
-		else if (!strcmp("radius_offset", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setRadiusOffset(y);
-		}
-		else if (!strcmp("taper_x", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setTaperX(y);
-		}
-		else if (!strcmp("taper_y", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setTaperY(y);
-		}
-		else if (!strcmp("revolutions", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setRevolutions(y);
-		}
-		else if (!strcmp("skew", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setSkew(y);
-		}
-		else
-		{
-			LL_WARNS() << "unknown keyword " << " in path import" << LL_ENDL;
-		}
-	}
-	return TRUE;
-}
+            if (hollow)
+            {
+                np *= 2;
+            }
+        }
+        break;
+    case LL_PCODE_PROFILE_CIRCLE_HALF:
+        {
+            // If this has a square hollow, we should adjust the
+            // number of faces a bit so that the geometry lines up.
+            U8 hole_type=0;
+            // Number of faces is cut in half because it's only a half-circle.
+            F32 circle_detail = MIN_DETAIL_FACES * detail * 0.5f;
+            if (hollow)
+            {
+                hole_type = params.getCurveType() & LL_PCODE_HOLE_MASK;
+                if (hole_type == LL_PCODE_HOLE_SQUARE)
+                {
+                    // Snap to the next multiple of four sides (div 2),
+                    // so that corners line up.
+                    circle_detail = llceil(circle_detail / 2.0f) * 2.0f;
+                }
+            }
+            np = getNumNGonPoints(params, llfloor(circle_detail), 0.5f, 0.f, 0.5f);
 
+            if (hollow)
+            {
+                np *= 2;
+            }
 
-BOOL LLPathParams::exportFile(LLFILE *fp) const
-{
-	fprintf(fp, "\t\tpath 0\n");
-	fprintf(fp, "\t\t{\n");
-	fprintf(fp, "\t\t\tcurve\t%d\n", getCurveType());
-	fprintf(fp, "\t\t\tbegin\t%g\n", getBegin());
-	fprintf(fp, "\t\t\tend\t%g\n", getEnd());
-	fprintf(fp, "\t\t\tscale_x\t%g\n", getScaleX() );
-	fprintf(fp, "\t\t\tscale_y\t%g\n", getScaleY() );
-	fprintf(fp, "\t\t\tshear_x\t%g\n", getShearX() );
-	fprintf(fp, "\t\t\tshear_y\t%g\n", getShearY() );
-	fprintf(fp,"\t\t\ttwist\t%g\n", getTwist());
-	
-	fprintf(fp,"\t\t\ttwist_begin\t%g\n", getTwistBegin());
-	fprintf(fp,"\t\t\tradius_offset\t%g\n", getRadiusOffset());
-	fprintf(fp,"\t\t\ttaper_x\t%g\n", getTaperX());
-	fprintf(fp,"\t\t\ttaper_y\t%g\n", getTaperY());
-	fprintf(fp,"\t\t\trevolutions\t%g\n", getRevolutions());
-	fprintf(fp,"\t\t\tskew\t%g\n", getSkew());
-
-	fprintf(fp, "\t\t}\n");
-	return TRUE;
-}
+            // Special case for openness of sphere
+            if ((params.getEnd() - params.getBegin()) < 1.f)
+            {
+            }
+            else if (!hollow)
+            {
+                np++;
+            }
+        }
+        break;
+    default:
+       break;
+    };
 
 
-BOOL LLPathParams::importLegacyStream(std::istream& input_stream)
-{
-	const S32 BUFSIZE = 16384;
-	char buffer[BUFSIZE];	/* Flawfinder: ignore */
-	// *NOTE: changing the size or type of these buffers will require
-	// changing the sscanf below.
-	char keyword[256];	/* Flawfinder: ignore */
-	char valuestr[256];	/* Flawfinder: ignore */
-	keyword[0] = 0;
-	valuestr[0] = 0;
-
-	F32 tempF32;
-	F32 x, y;
-	U32 tempU32;
-
-	while (input_stream.good())
-	{
-		input_stream.getline(buffer, BUFSIZE);
-		sscanf(	/* Flawfinder: ignore */
-			buffer,
-			" %255s %255s",
-			keyword, valuestr);
-		if (!strcmp("{", keyword))
-		{
-			continue;
-		}
-		if (!strcmp("}",keyword))
-		{
-			break;
-		}
-		else if (!strcmp("curve", keyword))
-		{
-			sscanf(valuestr,"%d",&tempU32);
-			setCurveType((U8) tempU32);
-		}
-		else if (!strcmp("begin",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setBegin(tempF32);
-		}
-		else if (!strcmp("end",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setEnd(tempF32);
-		}
-		else if (!strcmp("scale",keyword))
-		{
-			// Legacy for one dimensional scale per path
-			sscanf(valuestr,"%g",&tempF32);
-			setScale(tempF32, tempF32);
-		}
-		else if (!strcmp("scale_x", keyword))
-		{
-			sscanf(valuestr, "%g", &x);
-			setScaleX(x);
-		}
-		else if (!strcmp("scale_y", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setScaleY(y);
-		}
-		else if (!strcmp("shear_x", keyword))
-		{
-			sscanf(valuestr, "%g", &x);
-			setShearX(x);
-		}
-		else if (!strcmp("shear_y", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setShearY(y);
-		}
-		else if (!strcmp("twist",keyword))
-		{
-			sscanf(valuestr,"%g",&tempF32);
-			setTwist(tempF32);
-		}
-		else if (!strcmp("twist_begin", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setTwistBegin(y);
-		}
-		else if (!strcmp("radius_offset", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setRadiusOffset(y);
-		}
-		else if (!strcmp("taper_x", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setTaperX(y);
-		}
-		else if (!strcmp("taper_y", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setTaperY(y);
-		}
-		else if (!strcmp("revolutions", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setRevolutions(y);
-		}
-		else if (!strcmp("skew", keyword))
-		{
-			sscanf(valuestr, "%g", &y);
-			setSkew(y);
-		}
-		else
-		{
-			LL_WARNS() << "unknown keyword " << " in path import" << LL_ENDL;
-		}
-	}
-	return TRUE;
+    return np;
 }
 
 
-BOOL LLPathParams::exportLegacyStream(std::ostream& output_stream) const
+BOOL LLProfile::generate(const LLProfileParams& params, BOOL path_open,F32 detail, S32 split,
+                         BOOL is_sculpted, S32 sculpt_size)
 {
-	output_stream << "\t\tpath 0\n";
-	output_stream << "\t\t{\n";
-	output_stream << "\t\t\tcurve\t" << (S32) getCurveType() << "\n";
-	output_stream << "\t\t\tbegin\t" << getBegin() << "\n";
-	output_stream << "\t\t\tend\t" << getEnd() << "\n";
-	output_stream << "\t\t\tscale_x\t" << getScaleX()  << "\n";
-	output_stream << "\t\t\tscale_y\t" << getScaleY()  << "\n";
-	output_stream << "\t\t\tshear_x\t" << getShearX()  << "\n";
-	output_stream << "\t\t\tshear_y\t" << getShearY()  << "\n";
-	output_stream <<"\t\t\ttwist\t" << getTwist() << "\n";
-	
-	output_stream <<"\t\t\ttwist_begin\t" << getTwistBegin() << "\n";
-	output_stream <<"\t\t\tradius_offset\t" << getRadiusOffset() << "\n";
-	output_stream <<"\t\t\ttaper_x\t" << getTaperX() << "\n";
-	output_stream <<"\t\t\ttaper_y\t" << getTaperY() << "\n";
-	output_stream <<"\t\t\trevolutions\t" << getRevolutions() << "\n";
-	output_stream <<"\t\t\tskew\t" << getSkew() << "\n";
-
-	output_stream << "\t\t}\n";
-	return TRUE;
-}
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
 
-LLSD LLPathParams::asLLSD() const
-{
-	LLSD sd = LLSD();
-	sd["curve"] = getCurveType();
-	sd["begin"] = getBegin();
-	sd["end"] = getEnd();
-	sd["scale_x"] = getScaleX();
-	sd["scale_y"] = getScaleY();
-	sd["shear_x"] = getShearX();
-	sd["shear_y"] = getShearY();
-	sd["twist"] = getTwist();
-	sd["twist_begin"] = getTwistBegin();
-	sd["radius_offset"] = getRadiusOffset();
-	sd["taper_x"] = getTaperX();
-	sd["taper_y"] = getTaperY();
-	sd["revolutions"] = getRevolutions();
-	sd["skew"] = getSkew();
-
-	return sd;
-}
+    if ((!mDirty) && (!is_sculpted))
+    {
+        return FALSE;
+    }
+    mDirty = FALSE;
 
-bool LLPathParams::fromLLSD(LLSD& sd)
-{
-	setCurveType(sd["curve"].asInteger());
-	setBegin((F32)sd["begin"].asReal());
-	setEnd((F32)sd["end"].asReal());
-	setScaleX((F32)sd["scale_x"].asReal());
-	setScaleY((F32)sd["scale_y"].asReal());
-	setShearX((F32)sd["shear_x"].asReal());
-	setShearY((F32)sd["shear_y"].asReal());
-	setTwist((F32)sd["twist"].asReal());
-	setTwistBegin((F32)sd["twist_begin"].asReal());
-	setRadiusOffset((F32)sd["radius_offset"].asReal());
-	setTaperX((F32)sd["taper_x"].asReal());
-	setTaperY((F32)sd["taper_y"].asReal());
-	setRevolutions((F32)sd["revolutions"].asReal());
-	setSkew((F32)sd["skew"].asReal());
-	return true;
-}
+    if (detail < MIN_LOD)
+    {
+        LL_INFOS() << "Generating profile with LOD < MIN_LOD.  CLAMPING" << LL_ENDL;
+        detail = MIN_LOD;
+    }
 
-void LLPathParams::copyParams(const LLPathParams &params)
-{
-	setCurveType(params.getCurveType());
-	setBegin(params.getBegin());
-	setEnd(params.getEnd());
-	setScale(params.getScaleX(), params.getScaleY() );
-	setShear(params.getShearX(), params.getShearY() );
-	setTwist(params.getTwist());
-	setTwistBegin(params.getTwistBegin());
-	setRadiusOffset(params.getRadiusOffset());
-	setTaper( params.getTaperX(), params.getTaperY() );
-	setRevolutions(params.getRevolutions());
-	setSkew(params.getSkew());
-}
+    mProfile.resize(0);
+    mFaces.resize(0);
 
-S32 LLVolume::sNumMeshPoints = 0;
+    // Generate the face data
+    S32 i;
+    F32 begin = params.getBegin();
+    F32 end = params.getEnd();
+    F32 hollow = params.getHollow();
 
-LLVolume::LLVolume(const LLVolumeParams &params, const F32 detail, const BOOL generate_single_face, const BOOL is_unique)
-	: mParams(params)
-{
-	mUnique = is_unique;
-	mFaceMask = 0x0;
-	mDetail = detail;
-	mSculptLevel = -2;
-	mSurfaceArea = 1.f; //only calculated for sculpts, defaults to 1 for all other prims
-	mIsMeshAssetLoaded = false;
-    mIsMeshAssetUnavaliable = false;
-	mLODScaleBias.setVec(1,1,1);
-	mHullPoints = NULL;
-	mHullIndices = NULL;
-	mNumHullPoints = 0;
-	mNumHullIndices = 0;
-
-	// set defaults
-	if (mParams.getPathParams().getCurveType() == LL_PCODE_PATH_FLEXIBLE)
-	{
-		mPathp = new LLDynamicPath();
-	}
-	else
-	{
-		mPathp = new LLPath();
-	}
-	mProfilep = new LLProfile();
-
-	mGenerateSingleFace = generate_single_face;
-
-	generate();
-	
-	if ((mParams.getSculptID().isNull() && mParams.getSculptType() == LL_SCULPT_TYPE_NONE) || mParams.getSculptType() == LL_SCULPT_TYPE_MESH)
-	{
-		createVolumeFaces();
-	}
-}
+    // Quick validation to eliminate some server crashes.
+    if (begin > end - 0.01f)
+    {
+        LL_WARNS() << "LLProfile::generate() assertion failed (begin >= end)" << LL_ENDL;
+        return FALSE;
+    }
 
-void LLVolume::resizePath(S32 length)
-{
-	mPathp->resizePath(length);
-	mVolumeFaces.clear();
-	setDirty();
-}
+    S32 face_num = 0;
 
-void LLVolume::regen()
-{
-	generate();
-	createVolumeFaces();
-}
+    switch (params.getCurveType() & LL_PCODE_PROFILE_MASK)
+    {
+    case LL_PCODE_PROFILE_SQUARE:
+        {
+            genNGon(params, 4,-0.375, 0, 1, split);
+            if (path_open)
+            {
+                addCap (LL_FACE_PATH_BEGIN);
+            }
 
-void LLVolume::genTangents(S32 face)
-{
-    // generate legacy tangents for the specified face
-    llassert(!isMeshAssetLoaded() || mVolumeFaces[face].mTangents != nullptr); // if this is a complete mesh asset, we should already have tangents
-    mVolumeFaces[face].createTangents();
-}
+            for (i = llfloor(begin * 4.f); i < llfloor(end * 4.f + .999f); i++)
+            {
+                addFace((face_num++) * (split +1), split+2, 1, LL_FACE_OUTER_SIDE_0 << i, TRUE);
+            }
 
-LLVolume::~LLVolume()
-{
-	sNumMeshPoints -= mMesh.size();
-	delete mPathp;
+            LLVector4a scale(1,1,4,1);
 
-	delete mProfilep;
+            for (i = 0; i <(S32) mProfile.size(); i++)
+            {
+                // Scale by 4 to generate proper tex coords.
+                mProfile[i].mul(scale);
+                llassert(mProfile[i].isFinite3());
+            }
 
-	mPathp = NULL;
-	mProfilep = NULL;
-	mVolumeFaces.clear();
+            if (hollow)
+            {
+                switch (params.getCurveType() & LL_PCODE_HOLE_MASK)
+                {
+                case LL_PCODE_HOLE_TRIANGLE:
+                    // This offset is not correct, but we can't change it now... DK 11/17/04
+                    addHole(params, TRUE, 3, -0.375f, hollow, 1.f, split);
+                    break;
+                case LL_PCODE_HOLE_CIRCLE:
+                    // TODO: Compute actual detail levels for cubes
+                    addHole(params, FALSE, MIN_DETAIL_FACES * detail, -0.375f, hollow, 1.f);
+                    break;
+                case LL_PCODE_HOLE_SAME:
+                case LL_PCODE_HOLE_SQUARE:
+                default:
+                    addHole(params, TRUE, 4, -0.375f, hollow, 1.f, split);
+                    break;
+                }
+            }
 
-	ll_aligned_free_16(mHullPoints);
-	mHullPoints = NULL;
-	ll_aligned_free_16(mHullIndices);
-	mHullIndices = NULL;
-}
+            if (path_open) {
+                mFaces[0].mCount = mTotal;
+            }
+        }
+        break;
+    case  LL_PCODE_PROFILE_ISOTRI:
+    case  LL_PCODE_PROFILE_RIGHTTRI:
+    case  LL_PCODE_PROFILE_EQUALTRI:
+        {
+            genNGon(params, 3,0, 0, 1, split);
+            LLVector4a scale(1,1,3,1);
+            for (i = 0; i <(S32) mProfile.size(); i++)
+            {
+                // Scale by 3 to generate proper tex coords.
+                mProfile[i].mul(scale);
+                llassert(mProfile[i].isFinite3());
+            }
 
-BOOL LLVolume::generate()
-{
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
-
-	LL_CHECK_MEMORY
-	llassert_always(mProfilep);
-	
-	//Added 10.03.05 Dave Parks
-	// Split is a parameter to LLProfile::generate that tesselates edges on the profile 
-	// to prevent lighting and texture interpolation errors on triangles that are 
-	// stretched due to twisting or scaling on the path.  
-	S32 split = (S32) ((mDetail)*0.66f);
-	
-	const auto& path_params = mParams.getPathParams();
-	const auto& profile_params = mParams.getProfileParams();
-
-	if (path_params.getCurveType() == LL_PCODE_PATH_LINE &&
-		(path_params.getScale().mV[0] != 1.0f ||
-		 path_params.getScale().mV[1] != 1.0f) &&
-		(profile_params.getCurveType() == LL_PCODE_PROFILE_SQUARE ||
-		 profile_params.getCurveType() == LL_PCODE_PROFILE_ISOTRI ||
-		 profile_params.getCurveType() == LL_PCODE_PROFILE_EQUALTRI ||
-		 profile_params.getCurveType() == LL_PCODE_PROFILE_RIGHTTRI))
-	{
-		split = 0;
-	}
-		 
-	mLODScaleBias.setVec(0.5f, 0.5f, 0.5f);
-	
-	F32 profile_detail = mDetail;
-	F32 path_detail = mDetail;
-
-	if ((mParams.getSculptType() & LL_SCULPT_TYPE_MASK) != LL_SCULPT_TYPE_MESH)
-	{
-		U8 path_type = path_params.getCurveType();
-		U8 profile_type = profile_params.getCurveType();
-		if (path_type == LL_PCODE_PATH_LINE && profile_type == LL_PCODE_PROFILE_CIRCLE)
-		{
-			//cylinders don't care about Z-Axis
-			mLODScaleBias.setVec(0.6f, 0.6f, 0.0f);
-		}
-		else if (path_type == LL_PCODE_PATH_CIRCLE)
-		{
-			mLODScaleBias.setVec(0.6f, 0.6f, 0.6f);
-		}
-	}
-
-	BOOL regenPath = mPathp->generate(path_params, path_detail, split);
-	BOOL regenProf = mProfilep->generate(profile_params, mPathp->isOpen(),profile_detail, split);
-
-	if (regenPath || regenProf ) 
-	{
-		S32 sizeS = mPathp->mPath.size();
-		S32 sizeT = mProfilep->mProfile.size();
-
-		sNumMeshPoints -= mMesh.size();
-		mMesh.resize(sizeT * sizeS);
-		sNumMeshPoints += mMesh.size();		
-
-		//generate vertex positions
-
-		// Run along the path.
-		LLVector4a* dst = mMesh.mArray;
-
-		for (S32 s = 0; s < sizeS; ++s)
-		{
-			F32* scale = mPathp->mPath[s].mScale.getF32ptr();
-			
-			F32 sc [] = 
-			{ scale[0], 0, 0, 0,
-				0, scale[1], 0, 0,
-				0, 0, scale[2], 0,
-					0, 0, 0, 1 };
-			
-			LLMatrix4 rot((F32*) mPathp->mPath[s].mRot.mMatrix);
-			LLMatrix4 scale_mat(sc);
-			
-			scale_mat *= rot;
-			
-			LLMatrix4a rot_mat;
-			rot_mat.loadu(scale_mat);
-			
-			LLVector4a* profile = mProfilep->mProfile.mArray;
-			LLVector4a* end_profile = profile+sizeT;
-			LLVector4a offset = mPathp->mPath[s].mPos;
+            if (path_open)
+            {
+                addCap(LL_FACE_PATH_BEGIN);
+            }
 
-            // hack to work around MAINT-5660 for debug until we can suss out
-            // what is wrong with the path generated that inserts NaNs...
-            if (!offset.isFinite3())
+            for (i = llfloor(begin * 3.f); i < llfloor(end * 3.f + .999f); i++)
             {
-                offset.clear();
+                addFace((face_num++) * (split +1), split+2, 1, LL_FACE_OUTER_SIDE_0 << i, TRUE);
             }
+            if (hollow)
+            {
+                // Swept triangles need smaller hollowness values,
+                // because the triangle doesn't fill the bounding box.
+                F32 triangle_hollow = hollow / 2.f;
 
-			LLVector4a tmp;
+                switch (params.getCurveType() & LL_PCODE_HOLE_MASK)
+                {
+                case LL_PCODE_HOLE_CIRCLE:
+                    // TODO: Actually generate level of detail for triangles
+                    addHole(params, FALSE, MIN_DETAIL_FACES * detail, 0, triangle_hollow, 1.f);
+                    break;
+                case LL_PCODE_HOLE_SQUARE:
+                    addHole(params, TRUE, 4, 0, triangle_hollow, 1.f, split);
+                    break;
+                case LL_PCODE_HOLE_SAME:
+                case LL_PCODE_HOLE_TRIANGLE:
+                default:
+                    addHole(params, TRUE, 3, 0, triangle_hollow, 1.f, split);
+                    break;
+                }
+            }
+        }
+        break;
+    case LL_PCODE_PROFILE_CIRCLE:
+        {
+            // If this has a square hollow, we should adjust the
+            // number of faces a bit so that the geometry lines up.
+            U8 hole_type=0;
+            F32 circle_detail = MIN_DETAIL_FACES * detail;
+            if (hollow)
+            {
+                hole_type = params.getCurveType() & LL_PCODE_HOLE_MASK;
+                if (hole_type == LL_PCODE_HOLE_SQUARE)
+                {
+                    // Snap to the next multiple of four sides,
+                    // so that corners line up.
+                    circle_detail = llceil(circle_detail / 4.0f) * 4.0f;
+                }
+            }
 
-			// Run along the profile.
-			while (profile < end_profile)
-			{
-				rot_mat.rotate(*profile++, tmp);
-				dst->setAdd(tmp,offset);
-				++dst;
-			}
-		}
+            S32 sides = (S32)circle_detail;
 
-		for (std::vector<LLProfile::Face>::iterator iter = mProfilep->mFaces.begin();
-			 iter != mProfilep->mFaces.end(); ++iter)
-		{
-			LLFaceID id = iter->mFaceID;
-			mFaceMask |= id;
-		}
-		LL_CHECK_MEMORY
-		return TRUE;
-	}
+            if (is_sculpted)
+                sides = sculpt_size;
 
-	LL_CHECK_MEMORY
-	return FALSE;
-}
+            genNGon(params, sides);
 
-void LLVolumeFace::VertexData::init()
-{
-	if (!mData)
-	{
-		mData = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*2);
-	}
-}
+            if (path_open)
+            {
+                addCap (LL_FACE_PATH_BEGIN);
+            }
 
-LLVolumeFace::VertexData::VertexData()
-{
-	mData = NULL;
-	init();
+            if (mOpen && !hollow)
+            {
+                addFace(0,mTotal-1,0,LL_FACE_OUTER_SIDE_0, FALSE);
+            }
+            else
+            {
+                addFace(0,mTotal,0,LL_FACE_OUTER_SIDE_0, FALSE);
+            }
+
+            if (hollow)
+            {
+                switch (hole_type)
+                {
+                case LL_PCODE_HOLE_SQUARE:
+                    addHole(params, TRUE, 4, 0, hollow, 1.f, split);
+                    break;
+                case LL_PCODE_HOLE_TRIANGLE:
+                    addHole(params, TRUE, 3, 0, hollow, 1.f, split);
+                    break;
+                case LL_PCODE_HOLE_CIRCLE:
+                case LL_PCODE_HOLE_SAME:
+                default:
+                    addHole(params, FALSE, circle_detail, 0, hollow, 1.f);
+                    break;
+                }
+            }
+        }
+        break;
+    case LL_PCODE_PROFILE_CIRCLE_HALF:
+        {
+            // If this has a square hollow, we should adjust the
+            // number of faces a bit so that the geometry lines up.
+            U8 hole_type=0;
+            // Number of faces is cut in half because it's only a half-circle.
+            F32 circle_detail = MIN_DETAIL_FACES * detail * 0.5f;
+            if (hollow)
+            {
+                hole_type = params.getCurveType() & LL_PCODE_HOLE_MASK;
+                if (hole_type == LL_PCODE_HOLE_SQUARE)
+                {
+                    // Snap to the next multiple of four sides (div 2),
+                    // so that corners line up.
+                    circle_detail = llceil(circle_detail / 2.0f) * 2.0f;
+                }
+            }
+            genNGon(params, llfloor(circle_detail), 0.5f, 0.f, 0.5f);
+            if (path_open)
+            {
+                addCap(LL_FACE_PATH_BEGIN);
+            }
+            if (mOpen && !params.getHollow())
+            {
+                addFace(0,mTotal-1,0,LL_FACE_OUTER_SIDE_0, FALSE);
+            }
+            else
+            {
+                addFace(0,mTotal,0,LL_FACE_OUTER_SIDE_0, FALSE);
+            }
+
+            if (hollow)
+            {
+                switch (hole_type)
+                {
+                case LL_PCODE_HOLE_SQUARE:
+                    addHole(params, TRUE, 2, 0.5f, hollow, 0.5f, split);
+                    break;
+                case LL_PCODE_HOLE_TRIANGLE:
+                    addHole(params, TRUE, 3,  0.5f, hollow, 0.5f, split);
+                    break;
+                case LL_PCODE_HOLE_CIRCLE:
+                case LL_PCODE_HOLE_SAME:
+                default:
+                    addHole(params, FALSE, circle_detail,  0.5f, hollow, 0.5f);
+                    break;
+                }
+            }
+
+            // Special case for openness of sphere
+            if ((params.getEnd() - params.getBegin()) < 1.f)
+            {
+                mOpen = TRUE;
+            }
+            else if (!hollow)
+            {
+                mOpen = FALSE;
+                mProfile.push_back(mProfile[0]);
+                mTotal++;
+            }
+        }
+        break;
+    default:
+        LL_ERRS() << "Unknown profile: getCurveType()=" << params.getCurveType() << LL_ENDL;
+        break;
+    };
+
+    if (path_open)
+    {
+        addCap(LL_FACE_PATH_END); // bottom
+    }
+
+    if ( mOpen) // interior edge caps
+    {
+        addFace(mTotal-1, 2,0.5,LL_FACE_PROFILE_BEGIN, TRUE);
+
+        if (hollow)
+        {
+            addFace(mTotalOut-1, 2,0.5,LL_FACE_PROFILE_END, TRUE);
+        }
+        else
+        {
+            addFace(mTotal-2, 2,0.5,LL_FACE_PROFILE_END, TRUE);
+        }
+    }
+
+    return TRUE;
 }
-	
-LLVolumeFace::VertexData::VertexData(const VertexData& rhs)
+
+
+
+BOOL LLProfileParams::importFile(LLFILE *fp)
 {
-	mData = NULL;
-	*this = rhs;
+    const S32 BUFSIZE = 16384;
+    char buffer[BUFSIZE];   /* Flawfinder: ignore */
+    // *NOTE: changing the size or type of these buffers will require
+    // changing the sscanf below.
+    char keyword[256];  /* Flawfinder: ignore */
+    char valuestr[256]; /* Flawfinder: ignore */
+    keyword[0] = 0;
+    valuestr[0] = 0;
+    F32 tempF32;
+    U32 tempU32;
+
+    while (!feof(fp))
+    {
+        if (fgets(buffer, BUFSIZE, fp) == NULL)
+        {
+            buffer[0] = '\0';
+        }
+
+        sscanf( /* Flawfinder: ignore */
+            buffer,
+            " %255s %255s",
+            keyword, valuestr);
+        if (!strcmp("{", keyword))
+        {
+            continue;
+        }
+        if (!strcmp("}",keyword))
+        {
+            break;
+        }
+        else if (!strcmp("curve", keyword))
+        {
+            sscanf(valuestr,"%d",&tempU32);
+            setCurveType((U8) tempU32);
+        }
+        else if (!strcmp("begin",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setBegin(tempF32);
+        }
+        else if (!strcmp("end",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setEnd(tempF32);
+        }
+        else if (!strcmp("hollow",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setHollow(tempF32);
+        }
+        else
+        {
+            LL_WARNS() << "unknown keyword " << keyword << " in profile import" << LL_ENDL;
+        }
+    }
+
+    return TRUE;
 }
 
-const LLVolumeFace::VertexData& LLVolumeFace::VertexData::operator=(const LLVolumeFace::VertexData& rhs)
+
+BOOL LLProfileParams::exportFile(LLFILE *fp) const
 {
-	if (this != &rhs)
-	{
-		init();
-		LLVector4a::memcpyNonAliased16((F32*) mData, (F32*) rhs.mData, 2*sizeof(LLVector4a));
-		mTexCoord = rhs.mTexCoord;
-	}
-	return *this;
+    fprintf(fp,"\t\tprofile 0\n");
+    fprintf(fp,"\t\t{\n");
+    fprintf(fp,"\t\t\tcurve\t%d\n", getCurveType());
+    fprintf(fp,"\t\t\tbegin\t%g\n", getBegin());
+    fprintf(fp,"\t\t\tend\t%g\n", getEnd());
+    fprintf(fp,"\t\t\thollow\t%g\n", getHollow());
+    fprintf(fp, "\t\t}\n");
+    return TRUE;
 }
 
-LLVolumeFace::VertexData::~VertexData()
+
+BOOL LLProfileParams::importLegacyStream(std::istream& input_stream)
 {
-	ll_aligned_free_16(mData);
-	mData = NULL;
+    const S32 BUFSIZE = 16384;
+    char buffer[BUFSIZE];   /* Flawfinder: ignore */
+    // *NOTE: changing the size or type of these buffers will require
+    // changing the sscanf below.
+    char keyword[256];  /* Flawfinder: ignore */
+    char valuestr[256]; /* Flawfinder: ignore */
+    keyword[0] = 0;
+    valuestr[0] = 0;
+    F32 tempF32;
+    U32 tempU32;
+
+    while (input_stream.good())
+    {
+        input_stream.getline(buffer, BUFSIZE);
+        sscanf( /* Flawfinder: ignore */
+            buffer,
+            " %255s %255s",
+            keyword,
+            valuestr);
+        if (!strcmp("{", keyword))
+        {
+            continue;
+        }
+        if (!strcmp("}",keyword))
+        {
+            break;
+        }
+        else if (!strcmp("curve", keyword))
+        {
+            sscanf(valuestr,"%d",&tempU32);
+            setCurveType((U8) tempU32);
+        }
+        else if (!strcmp("begin",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setBegin(tempF32);
+        }
+        else if (!strcmp("end",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setEnd(tempF32);
+        }
+        else if (!strcmp("hollow",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setHollow(tempF32);
+        }
+        else
+        {
+        LL_WARNS() << "unknown keyword " << keyword << " in profile import" << LL_ENDL;
+        }
+    }
+
+    return TRUE;
 }
 
-LLVector4a& LLVolumeFace::VertexData::getPosition()
+
+BOOL LLProfileParams::exportLegacyStream(std::ostream& output_stream) const
 {
-	return mData[POSITION];
+    output_stream <<"\t\tprofile 0\n";
+    output_stream <<"\t\t{\n";
+    output_stream <<"\t\t\tcurve\t" << (S32) getCurveType() << "\n";
+    output_stream <<"\t\t\tbegin\t" << getBegin() << "\n";
+    output_stream <<"\t\t\tend\t" << getEnd() << "\n";
+    output_stream <<"\t\t\thollow\t" << getHollow() << "\n";
+    output_stream << "\t\t}\n";
+    return TRUE;
 }
 
-LLVector4a& LLVolumeFace::VertexData::getNormal()
+LLSD LLProfileParams::asLLSD() const
 {
-	return mData[NORMAL];
+    LLSD sd;
+
+    sd["curve"] = getCurveType();
+    sd["begin"] = getBegin();
+    sd["end"] = getEnd();
+    sd["hollow"] = getHollow();
+    return sd;
 }
 
-const LLVector4a& LLVolumeFace::VertexData::getPosition() const
+bool LLProfileParams::fromLLSD(LLSD& sd)
 {
-	return mData[POSITION];
+    setCurveType(sd["curve"].asInteger());
+    setBegin((F32)sd["begin"].asReal());
+    setEnd((F32)sd["end"].asReal());
+    setHollow((F32)sd["hollow"].asReal());
+    return true;
 }
 
-const LLVector4a& LLVolumeFace::VertexData::getNormal() const
+void LLProfileParams::copyParams(const LLProfileParams &params)
 {
-	return mData[NORMAL];
+    setCurveType(params.getCurveType());
+    setBegin(params.getBegin());
+    setEnd(params.getEnd());
+    setHollow(params.getHollow());
 }
 
 
-void LLVolumeFace::VertexData::setPosition(const LLVector4a& pos)
-{
-	mData[POSITION] = pos;
-}
+S32 LLPath::getNumNGonPoints(const LLPathParams& params, S32 sides, F32 startOff, F32 end_scale, F32 twist_scale)
+{ //this is basically LLPath::genNGon stripped down to only operations that influence the number of points added
+    S32 ret = 0;
 
-void LLVolumeFace::VertexData::setNormal(const LLVector4a& norm)
-{
-	mData[NORMAL] = norm;
+    F32 step= 1.0f / sides;
+    F32 t   = params.getBegin();
+    ret = 1;
+
+    t+=step;
+
+    // Snap to a quantized parameter, so that cut does not
+    // affect most sample points.
+    t = ((S32)(t * sides)) / (F32)sides;
+
+    // Run through the non-cut dependent points.
+    while (t < params.getEnd())
+    {
+        ret++;
+        t+=step;
+    }
+
+    ret++;
+
+    return ret;
 }
 
-bool LLVolumeFace::VertexData::operator<(const LLVolumeFace::VertexData& rhs)const
+void LLPath::genNGon(const LLPathParams& params, S32 sides, F32 startOff, F32 end_scale, F32 twist_scale)
 {
-	const F32* lp = this->getPosition().getF32ptr();
-	const F32* rp = rhs.getPosition().getF32ptr();
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
 
-	if (lp[0] != rp[0])
-	{
-		return lp[0] < rp[0];
-	}
+    // Generates a circular path, starting at (1, 0, 0), counterclockwise along the xz plane.
+    static const F32 tableScale[] = { 1, 1, 1, 0.5f, 0.707107f, 0.53f, 0.525f, 0.5f };
 
-	if (rp[1] != lp[1])
-	{
-		return lp[1] < rp[1];
-	}
+    F32 revolutions = params.getRevolutions();
+    F32 skew        = params.getSkew();
+    F32 skew_mag    = fabs(skew);
+    F32 hole_x      = params.getScaleX() * (1.0f - skew_mag);
+    F32 hole_y      = params.getScaleY();
 
-	if (rp[2] != lp[2])
-	{
-		return lp[2] < rp[2];
-	}
+    // Calculate taper begin/end for x,y (Negative means taper the beginning)
+    F32 taper_x_begin   = 1.0f;
+    F32 taper_x_end     = 1.0f - params.getTaperX();
+    F32 taper_y_begin   = 1.0f;
+    F32 taper_y_end     = 1.0f - params.getTaperY();
 
-	lp = getNormal().getF32ptr();
-	rp = rhs.getNormal().getF32ptr();
+    if ( taper_x_end > 1.0f )
+    {
+        // Flip tapering.
+        taper_x_begin   = 2.0f - taper_x_end;
+        taper_x_end     = 1.0f;
+    }
+    if ( taper_y_end > 1.0f )
+    {
+        // Flip tapering.
+        taper_y_begin   = 2.0f - taper_y_end;
+        taper_y_end     = 1.0f;
+    }
+
+    // For spheres, the radius is usually zero.
+    F32 radius_start = 0.5f;
+    if (sides < 8)
+    {
+        radius_start = tableScale[sides];
+    }
+
+    // Scale the radius to take the hole size into account.
+    radius_start *= 1.0f - hole_y;
 
-	if (lp[0] != rp[0])
-	{
-		return lp[0] < rp[0];
-	}
+    // Now check the radius offset to calculate the start,end radius.  (Negative means
+    // decrease the start radius instead).
+    F32 radius_end    = radius_start;
+    F32 radius_offset = params.getRadiusOffset();
+    if (radius_offset < 0.f)
+    {
+        radius_start *= 1.f + radius_offset;
+    }
+    else
+    {
+        radius_end   *= 1.f - radius_offset;
+    }
+
+    // Is the path NOT a closed loop?
+    mOpen = ( (params.getEnd()*end_scale - params.getBegin() < 1.0f) ||
+              (skew_mag > 0.001f) ||
+              (fabs(taper_x_end - taper_x_begin) > 0.001f) ||
+              (fabs(taper_y_end - taper_y_begin) > 0.001f) ||
+              (fabs(radius_end - radius_start) > 0.001f) );
+
+    F32 ang, c, s;
+    LLQuaternion twist, qang;
+    PathPt *pt;
+    LLVector3 path_axis (1.f, 0.f, 0.f);
+    //LLVector3 twist_axis(0.f, 0.f, 1.f);
+    F32 twist_begin = params.getTwistBegin() * twist_scale;
+    F32 twist_end   = params.getTwist() * twist_scale;
+
+    // We run through this once before the main loop, to make sure
+    // the path begins at the correct cut.
+    F32 step= 1.0f / sides;
+    F32 t   = params.getBegin();
+    pt      = mPath.append(1);
+    ang     = 2.0f*F_PI*revolutions * t;
+    s       = sin(ang)*ll_lerp(radius_start, radius_end, t);
+    c       = cos(ang)*ll_lerp(radius_start, radius_end, t);
+
+
+    const LLVector2& shearval = params.getShear();
+    pt->mPos.set(0 + ll_lerp(0,shearval.mV[0],s)
+                      + ll_lerp(-skew ,skew, t) * 0.5f,
+                    c + ll_lerp(0,shearval.mV[1],s),
+                    s);
+    pt->mScale.set(hole_x * ll_lerp(taper_x_begin, taper_x_end, t),
+        hole_y * ll_lerp(taper_y_begin, taper_y_end, t),
+        0,1);
+    pt->mTexT  = t;
+
+    // Twist rotates the path along the x,y plane (I think) - DJS 04/05/02
+    twist.setQuat  (ll_lerp(twist_begin,twist_end,t) * 2.f * F_PI - F_PI,0,0,1);
+    // Rotate the point around the circle's center.
+    qang.setQuat   (ang,path_axis);
+
+    LLMatrix3 rot(twist * qang);
+
+    pt->mRot.loadu(rot);
+
+    t+=step;
+
+    // Snap to a quantized parameter, so that cut does not
+    // affect most sample points.
+    t = ((S32)(t * sides)) / (F32)sides;
+
+    // Run through the non-cut dependent points.
+    while (t < params.getEnd())
+    {
+        pt      = mPath.append(1);
+
+        ang = 2.0f*F_PI*revolutions * t;
+        c   = cos(ang)*ll_lerp(radius_start, radius_end, t);
+        s   = sin(ang)*ll_lerp(radius_start, radius_end, t);
+
+        pt->mPos.set(0 + ll_lerp(0,params.getShear().mV[0],s)
+                          + ll_lerp(-skew ,skew, t) * 0.5f,
+                        c + ll_lerp(0,params.getShear().mV[1],s),
+                        s);
+
+        pt->mScale.set(hole_x * ll_lerp(taper_x_begin, taper_x_end, t),
+                    hole_y * ll_lerp(taper_y_begin, taper_y_end, t),
+                    0,1);
+        pt->mTexT  = t;
+
+        // Twist rotates the path along the x,y plane (I think) - DJS 04/05/02
+        twist.setQuat  (ll_lerp(twist_begin,twist_end,t) * 2.f * F_PI - F_PI,0,0,1);
+        // Rotate the point around the circle's center.
+        qang.setQuat   (ang,path_axis);
+        LLMatrix3 tmp(twist*qang);
+        pt->mRot.loadu(tmp);
+
+        t+=step;
+    }
 
-	if (rp[1] != lp[1])
-	{
-		return lp[1] < rp[1];
-	}
+    // Make one final pass for the end cut.
+    t = params.getEnd();
+    pt      = mPath.append(1);
+    ang = 2.0f*F_PI*revolutions * t;
+    c   = cos(ang)*ll_lerp(radius_start, radius_end, t);
+    s   = sin(ang)*ll_lerp(radius_start, radius_end, t);
 
-	if (rp[2] != lp[2])
-	{
-		return lp[2] < rp[2];
-	}
+    pt->mPos.set(0 + ll_lerp(0,params.getShear().mV[0],s)
+                      + ll_lerp(-skew ,skew, t) * 0.5f,
+                    c + ll_lerp(0,params.getShear().mV[1],s),
+                    s);
+    pt->mScale.set(hole_x * ll_lerp(taper_x_begin, taper_x_end, t),
+                   hole_y * ll_lerp(taper_y_begin, taper_y_end, t),
+                   0,1);
+    pt->mTexT  = t;
 
-	if (mTexCoord.mV[0] != rhs.mTexCoord.mV[0])
-	{
-		return mTexCoord.mV[0] < rhs.mTexCoord.mV[0];
-	}
+    // Twist rotates the path along the x,y plane (I think) - DJS 04/05/02
+    twist.setQuat  (ll_lerp(twist_begin,twist_end,t) * 2.f * F_PI - F_PI,0,0,1);
+    // Rotate the point around the circle's center.
+    qang.setQuat   (ang,path_axis);
+    LLMatrix3 tmp(twist*qang);
+    pt->mRot.loadu(tmp);
 
-	return mTexCoord.mV[1] < rhs.mTexCoord.mV[1];
+    mTotal = mPath.size();
 }
 
-bool LLVolumeFace::VertexData::operator==(const LLVolumeFace::VertexData& rhs)const
+const LLVector2 LLPathParams::getBeginScale() const
 {
-	return mData[POSITION].equals3(rhs.getPosition()) &&
-			mData[NORMAL].equals3(rhs.getNormal()) &&
-			mTexCoord == rhs.mTexCoord;
+    LLVector2 begin_scale(1.f, 1.f);
+    if (getScaleX() > 1)
+    {
+        begin_scale.mV[0] = 2-getScaleX();
+    }
+    if (getScaleY() > 1)
+    {
+        begin_scale.mV[1] = 2-getScaleY();
+    }
+    return begin_scale;
 }
 
-bool LLVolumeFace::VertexData::compareNormal(const LLVolumeFace::VertexData& rhs, F32 angle_cutoff) const
+const LLVector2 LLPathParams::getEndScale() const
 {
-	bool retval = false;
+    LLVector2 end_scale(1.f, 1.f);
+    if (getScaleX() < 1)
+    {
+        end_scale.mV[0] = getScaleX();
+    }
+    if (getScaleY() < 1)
+    {
+        end_scale.mV[1] = getScaleY();
+    }
+    return end_scale;
+}
 
-	const F32 epsilon = 0.00001f;
+S32 LLPath::getNumPoints(const LLPathParams& params, F32 detail)
+{ // this is basically LLPath::generate stripped down to only the operations that influence the number of points
+    if (detail < MIN_LOD)
+    {
+        detail = MIN_LOD;
+    }
 
-	if (rhs.mData[POSITION].equals3(mData[POSITION], epsilon) && 
-		fabs(rhs.mTexCoord[0]-mTexCoord[0]) < epsilon &&
-		fabs(rhs.mTexCoord[1]-mTexCoord[1]) < epsilon)
-	{
-		if (angle_cutoff > 1.f)
-		{
-			retval = (mData[NORMAL].equals3(rhs.mData[NORMAL], epsilon));
-		}
-		else
-		{
-			F32 cur_angle = rhs.mData[NORMAL].dot3(mData[NORMAL]).getF32();
-			retval = cur_angle > angle_cutoff;
-		}
-	}
+    S32 np = 2; // hardcode for line
 
-	return retval;
-}
+    // Is this 0xf0 mask really necessary?  DK 03/02/05
 
-bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
-{
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
+    switch (params.getCurveType() & 0xf0)
+    {
+    default:
+    case LL_PCODE_PATH_LINE:
+        {
+            // Take the begin/end twist into account for detail.
+            np    = llfloor(fabs(params.getTwistBegin() - params.getTwist()) * 3.5f * (detail-0.5f)) + 2;
+        }
+        break;
 
-	//input stream is now pointing at a zlib compressed block of LLSD
-	//decompress block
-	LLSD mdl;
-	U32 uzip_result = LLUZipHelper::unzip_llsd(mdl, is, size);
-	if (uzip_result != LLUZipHelper::ZR_OK)
-	{
-		LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD with code " << uzip_result << " , will probably fetch from sim again." << LL_ENDL;
-		return false;
-	}
-	return unpackVolumeFacesInternal(mdl);
-}
+    case LL_PCODE_PATH_CIRCLE:
+        {
+            // Increase the detail as the revolutions and twist increase.
+            F32 twist_mag = fabs(params.getTwistBegin() - params.getTwist());
 
-bool LLVolume::unpackVolumeFaces(U8* in_data, S32 size)
-{
-	//input data is now pointing at a zlib compressed block of LLSD
-	//decompress block
-	LLSD mdl;
-	U32 uzip_result = LLUZipHelper::unzip_llsd(mdl, in_data, size);
-	if (uzip_result != LLUZipHelper::ZR_OK)
-	{
-		LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD with code " << uzip_result << " , will probably fetch from sim again." << LL_ENDL;
-		return false;
-	}
-	return unpackVolumeFacesInternal(mdl);
-}
+            S32 sides = (S32)llfloor(llfloor((MIN_DETAIL_FACES * detail + twist_mag * 3.5f * (detail-0.5f))) * params.getRevolutions());
 
-bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl)
-{
-	{
-		U32 face_count = mdl.size();
+            np = sides;
+        }
+        break;
 
-		if (face_count == 0)
-		{ //no faces unpacked, treat as failed decode
-			LL_WARNS() << "found no faces!" << LL_ENDL;
-			return false;
-		}
+    case LL_PCODE_PATH_CIRCLE2:
+        {
+            //genNGon(params, llfloor(MIN_DETAIL_FACES * detail), 4.f, 0.f);
+            np = getNumNGonPoints(params, llfloor(MIN_DETAIL_FACES * detail));
+        }
+        break;
 
-		mVolumeFaces.resize(face_count);
+    case LL_PCODE_PATH_TEST:
 
-		for (size_t i = 0; i < face_count; ++i)
-		{
-			LLVolumeFace& face = mVolumeFaces[i];
+        np     = 5;
+        break;
+    };
 
-			const auto& mdl_face = mdl[i];
+    return np;
+}
 
-			if (mdl_face.has("NoGeometry"))
-			{ //face has no geometry, continue
-				face.resizeIndices(3);
-				face.resizeVertices(1);
-				face.mPositions->clear();
-				face.mNormals->clear();
-				face.mTexCoords->setZero();
-				memset(face.mIndices, 0, sizeof(U16)*3);
-				continue;
-			}
+BOOL LLPath::generate(const LLPathParams& params, F32 detail, S32 split,
+                      BOOL is_sculpted, S32 sculpt_size)
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
 
-			const LLSD::Binary& pos = mdl_face["Position"].asBinary();
-			const LLSD::Binary& norm = mdl_face["Normal"].asBinary();
-#if 0 // keep this code for now in case we decide to add support for on-the-wire tangents
-			const LLSD::Binary& tangent = mdl_face["Tangent"].asBinary();
-#endif
-			const LLSD::Binary& tc = mdl_face["TexCoord0"].asBinary();
-			const LLSD::Binary& idx = mdl_face["TriangleList"].asBinary();
+    if ((!mDirty) && (!is_sculpted))
+    {
+        return FALSE;
+    }
 
-			//copy out indices
-            S32 num_indices = idx.size() / 2;
-            const S32 indices_to_discard = num_indices % 3;
-            if (indices_to_discard > 0)
-            {
-                // Invalid number of triangle indices
-                LL_WARNS() << "Incomplete triangle discarded from face! Indices count " << num_indices << " was not divisible by 3. face index: " << i << " Total: " << face_count << LL_ENDL;
-                num_indices -= indices_to_discard;
-            }
-            face.resizeIndices(num_indices);
+    if (detail < MIN_LOD)
+    {
+        LL_INFOS() << "Generating path with LOD < MIN!  Clamping to 1" << LL_ENDL;
+        detail = MIN_LOD;
+    }
 
-            if (num_indices > 2 && !face.mIndices)
-            {
-                LL_WARNS() << "Failed to allocate " << num_indices << " indices for face index: " << i << " Total: " << face_count << LL_ENDL;
-                continue;
-            }
-			
-			if (idx.empty() || face.mNumIndices < 3)
-			{ //why is there an empty index list?
-				LL_WARNS() << "Empty face present! Face index: " << i << " Total: " << face_count << LL_ENDL;
-				continue;
-			}
-
-			U16* indices = (U16*) &(idx[0]);
-            for (U32 j = 0; j < num_indices; ++j)
-			{
-				face.mIndices[j] = indices[j];
-			}
+    mDirty = FALSE;
+    S32 np = 2; // hardcode for line
 
-			//copy out vertices
-			U32 num_verts = pos.size()/(3*2);
-			face.resizeVertices(num_verts);
+    mPath.resize(0);
+    mOpen = TRUE;
 
-            if (num_verts > 0 && !face.mPositions)
+    // Is this 0xf0 mask really necessary?  DK 03/02/05
+    switch (params.getCurveType() & 0xf0)
+    {
+    default:
+    case LL_PCODE_PATH_LINE:
+        {
+            // Take the begin/end twist into account for detail.
+            np    = llfloor(fabs(params.getTwistBegin() - params.getTwist()) * 3.5f * (detail-0.5f)) + 2;
+            if (np < split+2)
             {
-                LL_WARNS() << "Failed to allocate " << num_verts << " vertices for face index: " << i << " Total: " << face_count << LL_ENDL;
-                face.resizeIndices(0);
-                continue;
+                np = split+2;
             }
 
-			LLVector3 minp;
-			LLVector3 maxp;
-			LLVector2 min_tc; 
-			LLVector2 max_tc; 
-		
-			minp.setValue(mdl_face["PositionDomain"]["Min"]);
-			maxp.setValue(mdl_face["PositionDomain"]["Max"]);
-			LLVector4a min_pos, max_pos;
-			min_pos.load3(minp.mV);
-			max_pos.load3(maxp.mV);
+            mStep = 1.0f / (np-1);
 
-			min_tc.setValue(mdl_face["TexCoord0Domain"]["Min"]);
-			max_tc.setValue(mdl_face["TexCoord0Domain"]["Max"]);
+            mPath.resize(np);
 
-            //unpack normalized scale/translation
-            if (mdl_face.has("NormalizedScale"))
-            {
-                face.mNormalizedScale.setValue(mdl_face["NormalizedScale"]);
-            }
-            else
+            LLVector2 start_scale = params.getBeginScale();
+            LLVector2 end_scale = params.getEndScale();
+
+            for (S32 i=0;i<np;i++)
             {
-                face.mNormalizedScale.set(1, 1, 1);
+                F32 t = ll_lerp(params.getBegin(),params.getEnd(),(F32)i * mStep);
+                mPath[i].mPos.set(ll_lerp(0,params.getShear().mV[0],t),
+                                     ll_lerp(0,params.getShear().mV[1],t),
+                                     t - 0.5f);
+                LLQuaternion quat;
+                quat.setQuat(ll_lerp(F_PI * params.getTwistBegin(),F_PI * params.getTwist(),t),0,0,1);
+                LLMatrix3 tmp(quat);
+                mPath[i].mRot.loadu(tmp);
+                mPath[i].mScale.set(ll_lerp(start_scale.mV[0],end_scale.mV[0],t),
+                                    ll_lerp(start_scale.mV[1],end_scale.mV[1],t),
+                                    0,1);
+                mPath[i].mTexT        = t;
             }
-            
-			LLVector4a pos_range;
-			pos_range.setSub(max_pos, min_pos);
-			LLVector2 tc_range2 = max_tc - min_tc;
-
-			LLVector4a tc_range;
-			tc_range.set(tc_range2[0], tc_range2[1], tc_range2[0], tc_range2[1]);
-			LLVector4a min_tc4(min_tc[0], min_tc[1], min_tc[0], min_tc[1]);
-
-			LLVector4a* pos_out = face.mPositions;
-			LLVector4a* norm_out = face.mNormals;
-			LLVector4a* tc_out = (LLVector4a*) face.mTexCoords;
-
-			{
-				U16* v = (U16*) &(pos[0]);
-				for (U32 j = 0; j < num_verts; ++j)
-				{
-					pos_out->set((F32) v[0], (F32) v[1], (F32) v[2]);
-					pos_out->div(65535.f);
-					pos_out->mul(pos_range);
-					pos_out->add(min_pos);
-					pos_out++;
-					v += 3;
-				}
-
-			}
-
-			{
-				if (!norm.empty())
-				{
-					U16* n = (U16*) &(norm[0]);
-					for (U32 j = 0; j < num_verts; ++j)
-					{
-						norm_out->set((F32) n[0], (F32) n[1], (F32) n[2]);
-						norm_out->div(65535.f);
-						norm_out->mul(2.f);
-						norm_out->sub(1.f);
-						norm_out++;
-						n += 3;
-					}
-				}
-				else
-				{
-					for (U32 j = 0; j < num_verts; ++j)
-					{
-						norm_out->clear();
-						norm_out++; // or just norm_out[j].clear();
-					}
-				}
-			}
+        }
+        break;
 
-#if 0 // keep this code for now in case we decide to add support for on-the-wire tangents
-            {
-                if (!tangent.empty())
-                {
-                    face.allocateTangents(face.mNumVertices);
-                    U16* t = (U16*)&(tangent[0]);
+    case LL_PCODE_PATH_CIRCLE:
+        {
+            // Increase the detail as the revolutions and twist increase.
+            F32 twist_mag = fabs(params.getTwistBegin() - params.getTwist());
 
-                    // NOTE: tangents coming from the asset may not be mikkt space, but they should always be used by the GLTF shaders to 
-                    // maintain compliance with the GLTF spec
-                    LLVector4a* t_out = face.mTangents; 
+            S32 sides = (S32)llfloor(llfloor((MIN_DETAIL_FACES * detail + twist_mag * 3.5f * (detail-0.5f))) * params.getRevolutions());
 
-                    for (U32 j = 0; j < num_verts; ++j)
-                    {
-                        t_out->set((F32)t[0], (F32)t[1], (F32)t[2], (F32) t[3]);
-                        t_out->div(65535.f);
-                        t_out->mul(2.f);
-                        t_out->sub(1.f);
+            if (is_sculpted)
+                sides = llmax(sculpt_size, 1);
 
-                        F32* tp = t_out->getF32ptr();
-                        tp[3] = tp[3] < 0.f ? -1.f : 1.f;
+            if (0 < sides)
+                genNGon(params, sides);
+        }
+        break;
 
-                        t_out++;
-                        t += 4;
-                    }
-                }
+    case LL_PCODE_PATH_CIRCLE2:
+        {
+            if (params.getEnd() - params.getBegin() >= 0.99f &&
+                params.getScaleX() >= .99f)
+            {
+                mOpen = FALSE;
             }
-#endif
 
-			{
-				if (!tc.empty())
-				{
-					U16* t = (U16*) &(tc[0]);
-					for (U32 j = 0; j < num_verts; j+=2)
-					{
-						if (j < num_verts-1)
-						{
-							tc_out->set((F32) t[0], (F32) t[1], (F32) t[2], (F32) t[3]);
-						}
-						else
-						{
-							tc_out->set((F32) t[0], (F32) t[1], 0.f, 0.f);
-						}
-
-						t += 4;
-
-						tc_out->div(65535.f);
-						tc_out->mul(tc_range);
-						tc_out->add(min_tc4);
-
-						tc_out++;
-					}
-				}
-				else
-				{
-					for (U32 j = 0; j < num_verts; j += 2)
-					{
-						tc_out->clear();
-						tc_out++;
-					}
-				}
-			}
-
-			if (mdl_face.has("Weights"))
-			{
-				face.allocateWeights(num_verts);
-                if (!face.mWeights && num_verts)
-                {
-                    LL_WARNS() << "Failed to allocate " << num_verts << " weights for face index: " << i << " Total: " << face_count << LL_ENDL;
-                    face.resizeIndices(0);
-                    face.resizeVertices(0);
-                    continue;
-                }
+            //genNGon(params, llfloor(MIN_DETAIL_FACES * detail), 4.f, 0.f);
+            genNGon(params, llfloor(MIN_DETAIL_FACES * detail));
 
-				const LLSD::Binary& weights = mdl_face["Weights"].asBinary();
+            F32 toggle = 0.5f;
+            for (S32 i=0;i<(S32)mPath.size();i++)
+            {
+                mPath[i].mPos.getF32ptr()[0] = toggle;
+                if (toggle == 0.5f)
+                    toggle = -0.5f;
+                else
+                    toggle = 0.5f;
+            }
+        }
 
-				U32 idx = 0;
+        break;
 
-				U32 cur_vertex = 0;
-				size_t weight_size = weights.size();
-				while (idx < weight_size && cur_vertex < num_verts)
-				{
-					const U8 END_INFLUENCES = 0xFF;
-					U8 joint = weights[idx++];
+    case LL_PCODE_PATH_TEST:
 
-					U32 cur_influence = 0;
-					LLVector4 wght(0,0,0,0);
-                    U32 joints[4] = {0,0,0,0};
-					LLVector4 joints_with_weights(0,0,0,0);
-
-					while (joint != END_INFLUENCES && idx < weight_size)
-					{
-						U16 influence = weights[idx++];
-						influence |= ((U16) weights[idx++] << 8);
-
-						F32 w = llclamp((F32) influence / 65535.f, 0.001f, 0.999f);
-						wght.mV[cur_influence] = w;
-						joints[cur_influence] = joint;
-						cur_influence++;
-
-						if (cur_influence >= 4)
-						{
-							joint = END_INFLUENCES;
-						}
-						else
-						{
-							joint = weights[idx++];
-						}
-					}
-                    F32 wsum = wght.mV[VX] + wght.mV[VY] + wght.mV[VZ] + wght.mV[VW];
-                    if (wsum <= 0.f)
-                    {
-                        wght = LLVector4(0.999f,0.f,0.f,0.f);
-                    }
-                    for (U32 k=0; k<4; k++)
-                    {
-                        F32 f_combined = (F32) joints[k] + wght[k];
-                        joints_with_weights[k] = f_combined;
-                        // Any weights we added above should wind up non-zero and applied to a specific bone.
-                        // A failure here would indicate a floating point precision error in the math.
-                        llassert((k >= cur_influence) || (f_combined - S32(f_combined) > 0.0f));
-                    }
-					face.mWeights[cur_vertex].loadua(joints_with_weights.mV);
-
-					cur_vertex++;
-				}
-
-				if (cur_vertex != num_verts || idx != weights.size())
-				{
-					LL_WARNS() << "Vertex weight count does not match vertex count!" << LL_ENDL;
-				}
-					
-			}
-
-			// modifier flags?
-			bool do_mirror = (mParams.getSculptType() & LL_SCULPT_FLAG_MIRROR);
-			bool do_invert = (mParams.getSculptType() &LL_SCULPT_FLAG_INVERT);
-			
-			
-			// translate to actions:
-			bool do_reflect_x = false;
-			bool do_reverse_triangles = false;
-			bool do_invert_normals = false;
-			
-			if (do_mirror)
-			{
-				do_reflect_x = true;
-				do_reverse_triangles = !do_reverse_triangles;
-			}
-			
-			if (do_invert)
-			{
-				do_invert_normals = true;
-				do_reverse_triangles = !do_reverse_triangles;
-			}
-			
-			// now do the work
-
-			if (do_reflect_x)
-			{
-				LLVector4a* p = (LLVector4a*) face.mPositions;
-				LLVector4a* n = (LLVector4a*) face.mNormals;
-				
-				for (S32 i = 0; i < face.mNumVertices; i++)
-				{
-					p[i].mul(-1.0f);
-					n[i].mul(-1.0f);
-				}
-			}
-
-			if (do_invert_normals)
-			{
-				LLVector4a* n = (LLVector4a*) face.mNormals;
-				
-				for (S32 i = 0; i < face.mNumVertices; i++)
-				{
-					n[i].mul(-1.0f);
-				}
-			}
-
-			if (do_reverse_triangles)
-			{
-				for (U32 j = 0; j < face.mNumIndices; j += 3)
-				{
-					// swap the 2nd and 3rd index
-					S32 swap = face.mIndices[j+1];
-					face.mIndices[j+1] = face.mIndices[j+2];
-					face.mIndices[j+2] = swap;
-				}
-			}
-
-			//calculate bounding box
-			// VFExtents change
-			LLVector4a& min = face.mExtents[0];
-			LLVector4a& max = face.mExtents[1];
-
-			if (face.mNumVertices < 3)
-			{ //empty face, use a dummy 1cm (at 1m scale) bounding box
-				min.splat(-0.005f);
-				max.splat(0.005f);
-			}
-			else
-			{
-				min = max = face.mPositions[0];
-
-				for (S32 i = 1; i < face.mNumVertices; ++i)
-				{
-					min.setMin(min, face.mPositions[i]);
-					max.setMax(max, face.mPositions[i]);
-				}
-
-				if (face.mTexCoords)
-				{
-					LLVector2& min_tc = face.mTexCoordExtents[0];
-					LLVector2& max_tc = face.mTexCoordExtents[1];
-
-					min_tc = face.mTexCoords[0];
-					max_tc = face.mTexCoords[0];
-
-					for (U32 j = 1; j < face.mNumVertices; ++j)
-					{
-						update_min_max(min_tc, max_tc, face.mTexCoords[j]);
-					}
-				}
-				else
-				{
-					face.mTexCoordExtents[0].set(0,0);
-					face.mTexCoordExtents[1].set(1,1);
-				}
-			}
-		}
-	}
-
-	if (!cacheOptimize(true))
-	{
-		// Out of memory?
-		LL_WARNS() << "Failed to optimize!" << LL_ENDL;
-		mVolumeFaces.clear();
-		return false;
-	}
-	
-	mSculptLevel = 0;  // success!
-
-	return true;
-}
+        np     = 5;
+        mStep = 1.0f / (np-1);
 
+        mPath.resize(np);
 
-bool LLVolume::isMeshAssetLoaded()
-{
-	return mIsMeshAssetLoaded;
+        for (S32 i=0;i<np;i++)
+        {
+            F32 t = (F32)i * mStep;
+            mPath[i].mPos.set(0,
+                                ll_lerp(0,   -sin(F_PI*params.getTwist()*t)*0.5f,t),
+                                ll_lerp(-0.5f, cos(F_PI*params.getTwist()*t)*0.5f,t));
+            mPath[i].mScale.set(ll_lerp(1,params.getScale().mV[0],t),
+                                ll_lerp(1,params.getScale().mV[1],t), 0,1);
+            mPath[i].mTexT  = t;
+            LLQuaternion quat;
+            quat.setQuat(F_PI * params.getTwist() * t,1,0,0);
+            LLMatrix3 tmp(quat);
+            mPath[i].mRot.loadu(tmp);
+        }
+
+        break;
+    };
+
+    if (params.getTwist() != params.getTwistBegin()) mOpen = TRUE;
+
+    //if ((int(fabsf(params.getTwist() - params.getTwistBegin())*100))%100 != 0) {
+    //  mOpen = TRUE;
+    //}
+
+    return TRUE;
 }
 
-void LLVolume::setMeshAssetLoaded(bool loaded)
+BOOL LLDynamicPath::generate(const LLPathParams& params, F32 detail, S32 split,
+                             BOOL is_sculpted, S32 sculpt_size)
 {
-	mIsMeshAssetLoaded = loaded;
-    if (loaded)
+    mOpen = TRUE; // Draw end caps
+    if (getPathLength() == 0)
     {
-        mIsMeshAssetUnavaliable = false;
+        // Path hasn't been generated yet.
+        // Some algorithms later assume at least TWO path points.
+        resizePath(2);
+        LLQuaternion quat;
+        quat.setQuat(0,0,0);
+        LLMatrix3 tmp(quat);
+
+        for (U32 i = 0; i < 2; i++)
+        {
+            mPath[i].mPos.set(0, 0, 0);
+            mPath[i].mRot.loadu(tmp);
+            mPath[i].mScale.set(1, 1, 0, 1);
+            mPath[i].mTexT = 0;
+        }
     }
+
+    return TRUE;
 }
 
-void LLVolume::setMeshAssetUnavaliable(bool unavaliable)
+
+BOOL LLPathParams::importFile(LLFILE *fp)
 {
-    // Don't set it if at least one lod loaded
-    if (!mIsMeshAssetLoaded)
+    const S32 BUFSIZE = 16384;
+    char buffer[BUFSIZE];   /* Flawfinder: ignore */
+    // *NOTE: changing the size or type of these buffers will require
+    // changing the sscanf below.
+    char keyword[256];  /* Flawfinder: ignore */
+    char valuestr[256]; /* Flawfinder: ignore */
+    keyword[0] = 0;
+    valuestr[0] = 0;
+
+    F32 tempF32;
+    F32 x, y;
+    U32 tempU32;
+
+    while (!feof(fp))
     {
-        mIsMeshAssetUnavaliable = unavaliable;
+        if (fgets(buffer, BUFSIZE, fp) == NULL)
+        {
+            buffer[0] = '\0';
+        }
+
+        sscanf( /* Flawfinder: ignore */
+            buffer,
+            " %255s %255s",
+            keyword, valuestr);
+        if (!strcmp("{", keyword))
+        {
+            continue;
+        }
+        if (!strcmp("}",keyword))
+        {
+            break;
+        }
+        else if (!strcmp("curve", keyword))
+        {
+            sscanf(valuestr,"%d",&tempU32);
+            setCurveType((U8) tempU32);
+        }
+        else if (!strcmp("begin",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setBegin(tempF32);
+        }
+        else if (!strcmp("end",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setEnd(tempF32);
+        }
+        else if (!strcmp("scale",keyword))
+        {
+            // Legacy for one dimensional scale per path
+            sscanf(valuestr,"%g",&tempF32);
+            setScale(tempF32, tempF32);
+        }
+        else if (!strcmp("scale_x", keyword))
+        {
+            sscanf(valuestr, "%g", &x);
+            setScaleX(x);
+        }
+        else if (!strcmp("scale_y", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setScaleY(y);
+        }
+        else if (!strcmp("shear_x", keyword))
+        {
+            sscanf(valuestr, "%g", &x);
+            setShearX(x);
+        }
+        else if (!strcmp("shear_y", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setShearY(y);
+        }
+        else if (!strcmp("twist",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setTwist(tempF32);
+        }
+        else if (!strcmp("twist_begin", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setTwistBegin(y);
+        }
+        else if (!strcmp("radius_offset", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setRadiusOffset(y);
+        }
+        else if (!strcmp("taper_x", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setTaperX(y);
+        }
+        else if (!strcmp("taper_y", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setTaperY(y);
+        }
+        else if (!strcmp("revolutions", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setRevolutions(y);
+        }
+        else if (!strcmp("skew", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setSkew(y);
+        }
+        else
+        {
+            LL_WARNS() << "unknown keyword " << " in path import" << LL_ENDL;
+        }
     }
+    return TRUE;
 }
 
-bool LLVolume::isMeshAssetUnavaliable()
-{
-    return mIsMeshAssetUnavaliable;
-}
 
-void LLVolume::copyFacesTo(std::vector<LLVolumeFace> &faces) const 
+BOOL LLPathParams::exportFile(LLFILE *fp) const
 {
-	faces = mVolumeFaces;
+    fprintf(fp, "\t\tpath 0\n");
+    fprintf(fp, "\t\t{\n");
+    fprintf(fp, "\t\t\tcurve\t%d\n", getCurveType());
+    fprintf(fp, "\t\t\tbegin\t%g\n", getBegin());
+    fprintf(fp, "\t\t\tend\t%g\n", getEnd());
+    fprintf(fp, "\t\t\tscale_x\t%g\n", getScaleX() );
+    fprintf(fp, "\t\t\tscale_y\t%g\n", getScaleY() );
+    fprintf(fp, "\t\t\tshear_x\t%g\n", getShearX() );
+    fprintf(fp, "\t\t\tshear_y\t%g\n", getShearY() );
+    fprintf(fp,"\t\t\ttwist\t%g\n", getTwist());
+
+    fprintf(fp,"\t\t\ttwist_begin\t%g\n", getTwistBegin());
+    fprintf(fp,"\t\t\tradius_offset\t%g\n", getRadiusOffset());
+    fprintf(fp,"\t\t\ttaper_x\t%g\n", getTaperX());
+    fprintf(fp,"\t\t\ttaper_y\t%g\n", getTaperY());
+    fprintf(fp,"\t\t\trevolutions\t%g\n", getRevolutions());
+    fprintf(fp,"\t\t\tskew\t%g\n", getSkew());
+
+    fprintf(fp, "\t\t}\n");
+    return TRUE;
 }
 
-void LLVolume::copyFacesFrom(const std::vector<LLVolumeFace> &faces)
+
+BOOL LLPathParams::importLegacyStream(std::istream& input_stream)
 {
-	mVolumeFaces = faces;
-	mSculptLevel = 0;
+    const S32 BUFSIZE = 16384;
+    char buffer[BUFSIZE];   /* Flawfinder: ignore */
+    // *NOTE: changing the size or type of these buffers will require
+    // changing the sscanf below.
+    char keyword[256];  /* Flawfinder: ignore */
+    char valuestr[256]; /* Flawfinder: ignore */
+    keyword[0] = 0;
+    valuestr[0] = 0;
+
+    F32 tempF32;
+    F32 x, y;
+    U32 tempU32;
+
+    while (input_stream.good())
+    {
+        input_stream.getline(buffer, BUFSIZE);
+        sscanf( /* Flawfinder: ignore */
+            buffer,
+            " %255s %255s",
+            keyword, valuestr);
+        if (!strcmp("{", keyword))
+        {
+            continue;
+        }
+        if (!strcmp("}",keyword))
+        {
+            break;
+        }
+        else if (!strcmp("curve", keyword))
+        {
+            sscanf(valuestr,"%d",&tempU32);
+            setCurveType((U8) tempU32);
+        }
+        else if (!strcmp("begin",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setBegin(tempF32);
+        }
+        else if (!strcmp("end",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setEnd(tempF32);
+        }
+        else if (!strcmp("scale",keyword))
+        {
+            // Legacy for one dimensional scale per path
+            sscanf(valuestr,"%g",&tempF32);
+            setScale(tempF32, tempF32);
+        }
+        else if (!strcmp("scale_x", keyword))
+        {
+            sscanf(valuestr, "%g", &x);
+            setScaleX(x);
+        }
+        else if (!strcmp("scale_y", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setScaleY(y);
+        }
+        else if (!strcmp("shear_x", keyword))
+        {
+            sscanf(valuestr, "%g", &x);
+            setShearX(x);
+        }
+        else if (!strcmp("shear_y", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setShearY(y);
+        }
+        else if (!strcmp("twist",keyword))
+        {
+            sscanf(valuestr,"%g",&tempF32);
+            setTwist(tempF32);
+        }
+        else if (!strcmp("twist_begin", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setTwistBegin(y);
+        }
+        else if (!strcmp("radius_offset", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setRadiusOffset(y);
+        }
+        else if (!strcmp("taper_x", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setTaperX(y);
+        }
+        else if (!strcmp("taper_y", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setTaperY(y);
+        }
+        else if (!strcmp("revolutions", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setRevolutions(y);
+        }
+        else if (!strcmp("skew", keyword))
+        {
+            sscanf(valuestr, "%g", &y);
+            setSkew(y);
+        }
+        else
+        {
+            LL_WARNS() << "unknown keyword " << " in path import" << LL_ENDL;
+        }
+    }
+    return TRUE;
 }
 
-void LLVolume::copyVolumeFaces(const LLVolume* volume)
+
+BOOL LLPathParams::exportLegacyStream(std::ostream& output_stream) const
 {
-	mVolumeFaces = volume->mVolumeFaces;
-	mSculptLevel = 0;
+    output_stream << "\t\tpath 0\n";
+    output_stream << "\t\t{\n";
+    output_stream << "\t\t\tcurve\t" << (S32) getCurveType() << "\n";
+    output_stream << "\t\t\tbegin\t" << getBegin() << "\n";
+    output_stream << "\t\t\tend\t" << getEnd() << "\n";
+    output_stream << "\t\t\tscale_x\t" << getScaleX()  << "\n";
+    output_stream << "\t\t\tscale_y\t" << getScaleY()  << "\n";
+    output_stream << "\t\t\tshear_x\t" << getShearX()  << "\n";
+    output_stream << "\t\t\tshear_y\t" << getShearY()  << "\n";
+    output_stream <<"\t\t\ttwist\t" << getTwist() << "\n";
+
+    output_stream <<"\t\t\ttwist_begin\t" << getTwistBegin() << "\n";
+    output_stream <<"\t\t\tradius_offset\t" << getRadiusOffset() << "\n";
+    output_stream <<"\t\t\ttaper_x\t" << getTaperX() << "\n";
+    output_stream <<"\t\t\ttaper_y\t" << getTaperY() << "\n";
+    output_stream <<"\t\t\trevolutions\t" << getRevolutions() << "\n";
+    output_stream <<"\t\t\tskew\t" << getSkew() << "\n";
+
+    output_stream << "\t\t}\n";
+    return TRUE;
 }
 
-bool LLVolume::cacheOptimize(bool gen_tangents)
+LLSD LLPathParams::asLLSD() const
 {
-	for (S32 i = 0; i < mVolumeFaces.size(); ++i)
-	{
-		if (!mVolumeFaces[i].cacheOptimize(gen_tangents))
-		{
-			return false;
-		}
-	}
-	return true;
+    LLSD sd = LLSD();
+    sd["curve"] = getCurveType();
+    sd["begin"] = getBegin();
+    sd["end"] = getEnd();
+    sd["scale_x"] = getScaleX();
+    sd["scale_y"] = getScaleY();
+    sd["shear_x"] = getShearX();
+    sd["shear_y"] = getShearY();
+    sd["twist"] = getTwist();
+    sd["twist_begin"] = getTwistBegin();
+    sd["radius_offset"] = getRadiusOffset();
+    sd["taper_x"] = getTaperX();
+    sd["taper_y"] = getTaperY();
+    sd["revolutions"] = getRevolutions();
+    sd["skew"] = getSkew();
+
+    return sd;
 }
 
-
-S32	LLVolume::getNumFaces() const
+bool LLPathParams::fromLLSD(LLSD& sd)
 {
-	return mIsMeshAssetLoaded ? getNumVolumeFaces() : (S32)mProfilep->mFaces.size();
+    setCurveType(sd["curve"].asInteger());
+    setBegin((F32)sd["begin"].asReal());
+    setEnd((F32)sd["end"].asReal());
+    setScaleX((F32)sd["scale_x"].asReal());
+    setScaleY((F32)sd["scale_y"].asReal());
+    setShearX((F32)sd["shear_x"].asReal());
+    setShearY((F32)sd["shear_y"].asReal());
+    setTwist((F32)sd["twist"].asReal());
+    setTwistBegin((F32)sd["twist_begin"].asReal());
+    setRadiusOffset((F32)sd["radius_offset"].asReal());
+    setTaperX((F32)sd["taper_x"].asReal());
+    setTaperY((F32)sd["taper_y"].asReal());
+    setRevolutions((F32)sd["revolutions"].asReal());
+    setSkew((F32)sd["skew"].asReal());
+    return true;
 }
 
-
-void LLVolume::createVolumeFaces()
+void LLPathParams::copyParams(const LLPathParams &params)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
-
-	if (mGenerateSingleFace)
-	{
-		// do nothing
-	}
-	else
-	{
-		S32 num_faces = getNumFaces();
-		BOOL partial_build = TRUE;
-		if (num_faces != mVolumeFaces.size())
-		{
-			partial_build = FALSE;
-			mVolumeFaces.resize(num_faces);
-		}
-		// Initialize volume faces with parameter data
-		for (S32 i = 0; i < (S32)mVolumeFaces.size(); i++)
-		{
-			LLVolumeFace& vf = mVolumeFaces[i];
-			LLProfile::Face& face = mProfilep->mFaces[i];
-			vf.mBeginS = face.mIndex;
-			vf.mNumS = face.mCount;
-			if (vf.mNumS < 0)
-			{
-				LL_ERRS() << "Volume face corruption detected." << LL_ENDL;
-			}
-
-			vf.mBeginT = 0;
-			vf.mNumT= getPath().mPath.size();
-			vf.mID = i;
-
-			// Set the type mask bits correctly
-			if (mParams.getProfileParams().getHollow() > 0)
-			{
-				vf.mTypeMask |= LLVolumeFace::HOLLOW_MASK;
-			}
-			if (mProfilep->isOpen())
-			{
-				vf.mTypeMask |= LLVolumeFace::OPEN_MASK;
-			}
-			if (face.mCap)
-			{
-				vf.mTypeMask |= LLVolumeFace::CAP_MASK;
-				if (face.mFaceID == LL_FACE_PATH_BEGIN)
-				{
-					vf.mTypeMask |= LLVolumeFace::TOP_MASK;
-				}
-				else
-				{
-					llassert(face.mFaceID == LL_FACE_PATH_END);
-					vf.mTypeMask |= LLVolumeFace::BOTTOM_MASK;
-				}
-			}
-			else if (face.mFaceID & (LL_FACE_PROFILE_BEGIN | LL_FACE_PROFILE_END))
-			{
-				vf.mTypeMask |= LLVolumeFace::FLAT_MASK | LLVolumeFace::END_MASK;
-			}
-			else
-			{
-				vf.mTypeMask |= LLVolumeFace::SIDE_MASK;
-				if (face.mFlat)
-				{
-					vf.mTypeMask |= LLVolumeFace::FLAT_MASK;
-				}
-				if (face.mFaceID & LL_FACE_INNER_SIDE)
-				{
-					vf.mTypeMask |= LLVolumeFace::INNER_MASK;
-					if (face.mFlat && vf.mNumS > 2)
-					{ //flat inner faces have to copy vert normals
-						vf.mNumS = vf.mNumS*2;
-						if (vf.mNumS < 0)
-						{
-							LL_ERRS() << "Volume face corruption detected." << LL_ENDL;
-						}
-					}
-				}
-				else
-				{
-					vf.mTypeMask |= LLVolumeFace::OUTER_MASK;
-				}
-			}
-		}
-
-		for (face_list_t::iterator iter = mVolumeFaces.begin();
-			 iter != mVolumeFaces.end(); ++iter)
-		{
-			(*iter).create(this, partial_build);
-		}
-	}
+    setCurveType(params.getCurveType());
+    setBegin(params.getBegin());
+    setEnd(params.getEnd());
+    setScale(params.getScaleX(), params.getScaleY() );
+    setShear(params.getShearX(), params.getShearY() );
+    setTwist(params.getTwist());
+    setTwistBegin(params.getTwistBegin());
+    setRadiusOffset(params.getRadiusOffset());
+    setTaper( params.getTaperX(), params.getTaperY() );
+    setRevolutions(params.getRevolutions());
+    setSkew(params.getSkew());
 }
 
+S32 LLVolume::sNumMeshPoints = 0;
 
-inline LLVector4a sculpt_rgb_to_vector(U8 r, U8 g, U8 b)
-{
-	// maps RGB values to vector values [0..255] -> [-0.5..0.5]
-	LLVector4a value;
-	LLVector4a sub(0.5f, 0.5f, 0.5f);
+LLVolume::LLVolume(const LLVolumeParams &params, const F32 detail, const BOOL generate_single_face, const BOOL is_unique)
+    : mParams(params)
+{
+    mUnique = is_unique;
+    mFaceMask = 0x0;
+    mDetail = detail;
+    mSculptLevel = -2;
+    mSurfaceArea = 1.f; //only calculated for sculpts, defaults to 1 for all other prims
+    mIsMeshAssetLoaded = false;
+    mIsMeshAssetUnavaliable = false;
+    mLODScaleBias.setVec(1,1,1);
+    mHullPoints = NULL;
+    mHullIndices = NULL;
+    mNumHullPoints = 0;
+    mNumHullIndices = 0;
+
+    // set defaults
+    if (mParams.getPathParams().getCurveType() == LL_PCODE_PATH_FLEXIBLE)
+    {
+        mPathp = new LLDynamicPath();
+    }
+    else
+    {
+        mPathp = new LLPath();
+    }
+    mProfilep = new LLProfile();
+
+    mGenerateSingleFace = generate_single_face;
 
-	value.set(r,g,b);
-	value.mul(1.f/255.f);
-	value.sub(sub);
+    generate();
 
-	return value;
+    if ((mParams.getSculptID().isNull() && mParams.getSculptType() == LL_SCULPT_TYPE_NONE) || mParams.getSculptType() == LL_SCULPT_TYPE_MESH)
+    {
+        createVolumeFaces();
+    }
 }
 
-inline U32 sculpt_xy_to_index(U32 x, U32 y, U16 sculpt_width, U16 sculpt_height, S8 sculpt_components)
+void LLVolume::resizePath(S32 length)
 {
-	U32 index = (x + y * sculpt_width) * sculpt_components;
-	return index;
+    mPathp->resizePath(length);
+    mVolumeFaces.clear();
+    setDirty();
 }
 
-
-inline U32 sculpt_st_to_index(S32 s, S32 t, S32 size_s, S32 size_t, U16 sculpt_width, U16 sculpt_height, S8 sculpt_components)
+void LLVolume::regen()
 {
-	U32 x = (U32) ((F32)s/(size_s) * (F32) sculpt_width);
-	U32 y = (U32) ((F32)t/(size_t) * (F32) sculpt_height);
-
-	return sculpt_xy_to_index(x, y, sculpt_width, sculpt_height, sculpt_components);
+    generate();
+    createVolumeFaces();
 }
 
-
-inline LLVector4a sculpt_index_to_vector(U32 index, const U8* sculpt_data)
+void LLVolume::genTangents(S32 face)
 {
-	LLVector4a v = sculpt_rgb_to_vector(sculpt_data[index], sculpt_data[index+1], sculpt_data[index+2]);
-
-	return v;
+    // generate legacy tangents for the specified face
+    llassert(!isMeshAssetLoaded() || mVolumeFaces[face].mTangents != nullptr); // if this is a complete mesh asset, we should already have tangents
+    mVolumeFaces[face].createTangents();
 }
 
-inline LLVector4a sculpt_st_to_vector(S32 s, S32 t, S32 size_s, S32 size_t, U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data)
+LLVolume::~LLVolume()
 {
-	U32 index = sculpt_st_to_index(s, t, size_s, size_t, sculpt_width, sculpt_height, sculpt_components);
+    sNumMeshPoints -= mMesh.size();
+    delete mPathp;
+
+    delete mProfilep;
 
-	return sculpt_index_to_vector(index, sculpt_data);
+    mPathp = NULL;
+    mProfilep = NULL;
+    mVolumeFaces.clear();
+
+    ll_aligned_free_16(mHullPoints);
+    mHullPoints = NULL;
+    ll_aligned_free_16(mHullIndices);
+    mHullIndices = NULL;
 }
 
-inline LLVector4a sculpt_xy_to_vector(U32 x, U32 y, U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data)
+BOOL LLVolume::generate()
 {
-	U32 index = sculpt_xy_to_index(x, y, sculpt_width, sculpt_height, sculpt_components);
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
 
-	return sculpt_index_to_vector(index, sculpt_data);
-}
+    LL_CHECK_MEMORY
+    llassert_always(mProfilep);
 
+    //Added 10.03.05 Dave Parks
+    // Split is a parameter to LLProfile::generate that tesselates edges on the profile
+    // to prevent lighting and texture interpolation errors on triangles that are
+    // stretched due to twisting or scaling on the path.
+    S32 split = (S32) ((mDetail)*0.66f);
 
-F32 LLVolume::sculptGetSurfaceArea()
-{
-	// test to see if image has enough variation to create non-degenerate geometry
+    const auto& path_params = mParams.getPathParams();
+    const auto& profile_params = mParams.getProfileParams();
 
-	F32 area = 0;
+    if (path_params.getCurveType() == LL_PCODE_PATH_LINE &&
+        (path_params.getScale().mV[0] != 1.0f ||
+         path_params.getScale().mV[1] != 1.0f) &&
+        (profile_params.getCurveType() == LL_PCODE_PROFILE_SQUARE ||
+         profile_params.getCurveType() == LL_PCODE_PROFILE_ISOTRI ||
+         profile_params.getCurveType() == LL_PCODE_PROFILE_EQUALTRI ||
+         profile_params.getCurveType() == LL_PCODE_PROFILE_RIGHTTRI))
+    {
+        split = 0;
+    }
 
-	S32 sizeS = mPathp->mPath.size();
-	S32 sizeT = mProfilep->mProfile.size();
-			
-	for (S32 s = 0; s < sizeS-1; s++)
-	{
-		for (S32 t = 0; t < sizeT-1; t++)
-		{
-			// get four corners of quad
-			LLVector4a& p1 = mMesh[(s  )*sizeT + (t  )];
-			LLVector4a& p2 = mMesh[(s+1)*sizeT + (t  )];
-			LLVector4a& p3 = mMesh[(s  )*sizeT + (t+1)];
-			LLVector4a& p4 = mMesh[(s+1)*sizeT + (t+1)];
+    mLODScaleBias.setVec(0.5f, 0.5f, 0.5f);
 
-			// compute the area of the quad by taking the length of the cross product of the two triangles
-			LLVector4a v0,v1,v2,v3;
-			v0.setSub(p1,p2);
-			v1.setSub(p1,p3);
-			v2.setSub(p4,p2);
-			v3.setSub(p4,p3);
+    F32 profile_detail = mDetail;
+    F32 path_detail = mDetail;
 
-			LLVector4a cross1, cross2;
-			cross1.setCross3(v0,v1);
-			cross2.setCross3(v2,v3);
+    if ((mParams.getSculptType() & LL_SCULPT_TYPE_MASK) != LL_SCULPT_TYPE_MESH)
+    {
+        U8 path_type = path_params.getCurveType();
+        U8 profile_type = profile_params.getCurveType();
+        if (path_type == LL_PCODE_PATH_LINE && profile_type == LL_PCODE_PROFILE_CIRCLE)
+        {
+            //cylinders don't care about Z-Axis
+            mLODScaleBias.setVec(0.6f, 0.6f, 0.0f);
+        }
+        else if (path_type == LL_PCODE_PATH_CIRCLE)
+        {
+            mLODScaleBias.setVec(0.6f, 0.6f, 0.6f);
+        }
+    }
 
-			//LLVector3 cross1 = (p1 - p2) % (p1 - p3);
-			//LLVector3 cross2 = (p4 - p2) % (p4 - p3);
-			
-			area += (cross1.getLength3() + cross2.getLength3()).getF32() / 2.f;
-		}
-	}
+    BOOL regenPath = mPathp->generate(path_params, path_detail, split);
+    BOOL regenProf = mProfilep->generate(profile_params, mPathp->isOpen(),profile_detail, split);
 
-	return area;
-}
+    if (regenPath || regenProf )
+    {
+        S32 sizeS = mPathp->mPath.size();
+        S32 sizeT = mProfilep->mProfile.size();
 
-// create empty placeholder shape
-void LLVolume::sculptGenerateEmptyPlaceholder()
-{
-	S32 sizeS = mPathp->mPath.size();
-	S32 sizeT = mProfilep->mProfile.size();
+        sNumMeshPoints -= mMesh.size();
+        mMesh.resize(sizeT * sizeS);
+        sNumMeshPoints += mMesh.size();
 
-	S32 line = 0;
+        //generate vertex positions
 
-	for (S32 s = 0; s < sizeS; s++)
-	{
-		for (S32 t = 0; t < sizeT; t++)
-		{
-			S32 i = t + line;
-			LLVector4a& pt = mMesh[i];
-					
-			F32* p = pt.getF32ptr();
+        // Run along the path.
+        LLVector4a* dst = mMesh.mArray;
 
-			p[0] = 0;
-			p[1] = 0;
-			p[2] = 0;
+        for (S32 s = 0; s < sizeS; ++s)
+        {
+            F32* scale = mPathp->mPath[s].mScale.getF32ptr();
 
-			llassert(pt.isFinite3());
-		}
-		line += sizeT;
-	}
-}
+            F32 sc [] =
+            { scale[0], 0, 0, 0,
+                0, scale[1], 0, 0,
+                0, 0, scale[2], 0,
+                    0, 0, 0, 1 };
 
-// create sphere placeholder shape
-void LLVolume::sculptGenerateSpherePlaceholder()
-{
-	S32 sizeS = mPathp->mPath.size();
-	S32 sizeT = mProfilep->mProfile.size();
+            LLMatrix4 rot((F32*) mPathp->mPath[s].mRot.mMatrix);
+            LLMatrix4 scale_mat(sc);
 
-	S32 line = 0;
+            scale_mat *= rot;
 
-	for (S32 s = 0; s < sizeS; s++)
-	{
-		for (S32 t = 0; t < sizeT; t++)
-		{
-			S32 i = t + line;
-			LLVector4a& pt = mMesh[i];
+            LLMatrix4a rot_mat;
+            rot_mat.loadu(scale_mat);
 
+            LLVector4a* profile = mProfilep->mProfile.mArray;
+            LLVector4a* end_profile = profile+sizeT;
+            LLVector4a offset = mPathp->mPath[s].mPos;
 
-			F32 u = (F32)s / (sizeS - 1);
-			F32 v = (F32)t / (sizeT - 1);
+            // hack to work around MAINT-5660 for debug until we can suss out
+            // what is wrong with the path generated that inserts NaNs...
+            if (!offset.isFinite3())
+            {
+                offset.clear();
+            }
 
-			const F32 RADIUS = (F32) 0.3;
+            LLVector4a tmp;
 
-			F32* p = pt.getF32ptr();
+            // Run along the profile.
+            while (profile < end_profile)
+            {
+                rot_mat.rotate(*profile++, tmp);
+                dst->setAdd(tmp,offset);
+                ++dst;
+            }
+        }
 
-			p[0] = (F32)(sin(F_PI * v) * cos(2.0 * F_PI * u) * RADIUS);
-			p[1] = (F32)(sin(F_PI * v) * sin(2.0 * F_PI * u) * RADIUS);
-			p[2] = (F32)(cos(F_PI * v) * RADIUS);
+        for (std::vector<LLProfile::Face>::iterator iter = mProfilep->mFaces.begin();
+             iter != mProfilep->mFaces.end(); ++iter)
+        {
+            LLFaceID id = iter->mFaceID;
+            mFaceMask |= id;
+        }
+        LL_CHECK_MEMORY
+        return TRUE;
+    }
 
-			llassert(pt.isFinite3());
-		}
-		line += sizeT;
-	}
+    LL_CHECK_MEMORY
+    return FALSE;
 }
 
-// create the vertices from the map
-void LLVolume::sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type)
+void LLVolumeFace::VertexData::init()
 {
-	U8 sculpt_stitching = sculpt_type & LL_SCULPT_TYPE_MASK;
-	BOOL sculpt_invert = sculpt_type & LL_SCULPT_FLAG_INVERT;
-	BOOL sculpt_mirror = sculpt_type & LL_SCULPT_FLAG_MIRROR;
-	BOOL reverse_horizontal = (sculpt_invert ? !sculpt_mirror : sculpt_mirror);  // XOR
-	
-	S32 sizeS = mPathp->mPath.size();
-	S32 sizeT = mProfilep->mProfile.size();
-	
-	S32 line = 0;
-	for (S32 s = 0; s < sizeS; s++)
-	{
-		// Run along the profile.
-		for (S32 t = 0; t < sizeT; t++)
-		{
-			S32 i = t + line;
-			LLVector4a& pt = mMesh[i];
-
-			S32 reversed_t = t;
-
-			if (reverse_horizontal)
-			{
-				reversed_t = sizeT - t - 1;
-			}
-			
-			U32 x = (U32) ((F32)reversed_t/(sizeT-1) * (F32) sculpt_width);
-			U32 y = (U32) ((F32)s/(sizeS-1) * (F32) sculpt_height);
-
-			
-			if (y == 0)  // top row stitching
-			{
-				// pinch?
-				if (sculpt_stitching == LL_SCULPT_TYPE_SPHERE)
-				{
-					x = sculpt_width / 2;
-				}
-			}
-
-			if (y == sculpt_height)  // bottom row stitching
-			{
-				// wrap?
-				if (sculpt_stitching == LL_SCULPT_TYPE_TORUS)
-				{
-					y = 0;
-				}
-				else
-				{
-					y = sculpt_height - 1;
-				}
-
-				// pinch?
-				if (sculpt_stitching == LL_SCULPT_TYPE_SPHERE)
-				{
-					x = sculpt_width / 2;
-				}
-			}
-
-			if (x == sculpt_width)   // side stitching
-			{
-				// wrap?
-				if ((sculpt_stitching == LL_SCULPT_TYPE_SPHERE) ||
-					(sculpt_stitching == LL_SCULPT_TYPE_TORUS) ||
-					(sculpt_stitching == LL_SCULPT_TYPE_CYLINDER))
-				{
-					x = 0;
-				}
-					
-				else
-				{
-					x = sculpt_width - 1;
-				}
-			}
-
-			pt = sculpt_xy_to_vector(x, y, sculpt_width, sculpt_height, sculpt_components, sculpt_data);
-
-			if (sculpt_mirror)
-			{
-				LLVector4a scale(-1.f,1,1,1);
-				pt.mul(scale);
-			}
-
-			llassert(pt.isFinite3());
-		}
-		
-		line += sizeT;
-	}
+    if (!mData)
+    {
+        mData = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*2);
+    }
 }
 
+LLVolumeFace::VertexData::VertexData()
+{
+    mData = NULL;
+    init();
+}
 
-const S32 SCULPT_REZ_1 = 6;  // changed from 4 to 6 - 6 looks round whereas 4 looks square
-const S32 SCULPT_REZ_2 = 8;
-const S32 SCULPT_REZ_3 = 16;
-const S32 SCULPT_REZ_4 = 32;
-
-S32 sculpt_sides(F32 detail)
-{
-
-	// detail is usually one of: 1, 1.5, 2.5, 4.0.
-	
-	if (detail <= 1.0)
-	{
-		return SCULPT_REZ_1;
-	}
-	if (detail <= 2.0)
-	{
-		return SCULPT_REZ_2;
-	}
-	if (detail <= 3.0)
-	{
-		return SCULPT_REZ_3;
-	}
-	else
-	{
-		return SCULPT_REZ_4;
-	}
-}
-
-
-
-// determine the number of vertices in both s and t direction for this sculpt
-void sculpt_calc_mesh_resolution(U16 width, U16 height, U8 type, F32 detail, S32& s, S32& t)
-{
-	// this code has the following properties:
-	// 1) the aspect ratio of the mesh is as close as possible to the ratio of the map
-	//    while still using all available verts
-	// 2) the mesh cannot have more verts than is allowed by LOD
-	// 3) the mesh cannot have more verts than is allowed by the map
-	
-	S32 max_vertices_lod = (S32)pow((double)sculpt_sides(detail), 2.0);
-	S32 max_vertices_map = width * height / 4;
-	
-	S32 vertices;
-	if (max_vertices_map > 0)
-		vertices = llmin(max_vertices_lod, max_vertices_map);
-	else
-		vertices = max_vertices_lod;
-	
-
-	F32 ratio;
-	if ((width == 0) || (height == 0))
-		ratio = 1.f;
-	else
-		ratio = (F32) width / (F32) height;
-
-	
-	s = (S32)(F32) sqrt(((F32)vertices / ratio));
-
-	s = llmax(s, 4);              // no degenerate sizes, please
-	t = vertices / s;
-
-	t = llmax(t, 4);              // no degenerate sizes, please
-	s = vertices / t;
-}
-
-// sculpt replaces generate() for sculpted surfaces
-void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level, bool visible_placeholder)
-{
-	U8 sculpt_type = mParams.getSculptType();
-
-	BOOL data_is_empty = FALSE;
-
-	if (sculpt_width == 0 || sculpt_height == 0 || sculpt_components < 3 || sculpt_data == NULL)
-	{
-		sculpt_level = -1;
-		data_is_empty = TRUE;
-	}
-
-	S32 requested_sizeS = 0;
-	S32 requested_sizeT = 0;
-
-	sculpt_calc_mesh_resolution(sculpt_width, sculpt_height, sculpt_type, mDetail, requested_sizeS, requested_sizeT);
-
-	mPathp->generate(mParams.getPathParams(), mDetail, 0, TRUE, requested_sizeS);
-	mProfilep->generate(mParams.getProfileParams(), mPathp->isOpen(), mDetail, 0, TRUE, requested_sizeT);
-
-	S32 sizeS = mPathp->mPath.size();         // we requested a specific size, now see what we really got
-	S32 sizeT = mProfilep->mProfile.size();   // we requested a specific size, now see what we really got
-
-	// weird crash bug - DEV-11158 - trying to collect more data:
-	if ((sizeS == 0) || (sizeT == 0))
-	{
-		LL_WARNS() << "sculpt bad mesh size " << sizeS << " " << sizeT << LL_ENDL;
-	}
-	
-	sNumMeshPoints -= mMesh.size();
-	mMesh.resize(sizeS * sizeT);
-	sNumMeshPoints += mMesh.size();
-
-	//generate vertex positions
-	if (!data_is_empty)
-	{
-		sculptGenerateMapVertices(sculpt_width, sculpt_height, sculpt_components, sculpt_data, sculpt_type);
-
-		// don't test lowest LOD to support legacy content DEV-33670
-		if (mDetail > SCULPT_MIN_AREA_DETAIL)
-		{
-			F32 area = sculptGetSurfaceArea();
-
-			mSurfaceArea = area;
-
-			const F32 SCULPT_MAX_AREA = 384.f;
-
-			if (area < SCULPT_MIN_AREA || area > SCULPT_MAX_AREA)
-			{
-				data_is_empty = TRUE;
-				visible_placeholder = true;
-			}
-		}
-	}
-
-	if (data_is_empty)
-	{
-		if (visible_placeholder)
-		{
-			// Object should be visible since there will be nothing else to display
-			sculptGenerateSpherePlaceholder();
-		}
-		else
-		{
-			sculptGenerateEmptyPlaceholder();
-		}
-	}
-
-
-	
-	for (S32 i = 0; i < (S32)mProfilep->mFaces.size(); i++)
-	{
-		mFaceMask |= mProfilep->mFaces[i].mFaceID;
-	}
-
-	mSculptLevel = sculpt_level;
-
-	// Delete any existing faces so that they get regenerated
-	mVolumeFaces.clear();
-	
-	createVolumeFaces();
-}
-
-
-
-
-BOOL LLVolume::isCap(S32 face)
+LLVolumeFace::VertexData::VertexData(const VertexData& rhs)
 {
-	return mProfilep->mFaces[face].mCap; 
+    mData = NULL;
+    *this = rhs;
 }
 
-BOOL LLVolume::isFlat(S32 face)
+const LLVolumeFace::VertexData& LLVolumeFace::VertexData::operator=(const LLVolumeFace::VertexData& rhs)
 {
-	return mProfilep->mFaces[face].mFlat;
+    if (this != &rhs)
+    {
+        init();
+        LLVector4a::memcpyNonAliased16((F32*) mData, (F32*) rhs.mData, 2*sizeof(LLVector4a));
+        mTexCoord = rhs.mTexCoord;
+    }
+    return *this;
 }
 
-
-bool LLVolumeParams::isSculpt() const
+LLVolumeFace::VertexData::~VertexData()
 {
-    return (mSculptType & LL_SCULPT_TYPE_MASK) != LL_SCULPT_TYPE_NONE;
+    ll_aligned_free_16(mData);
+    mData = NULL;
 }
 
-bool LLVolumeParams::isMeshSculpt() const
+LLVector4a& LLVolumeFace::VertexData::getPosition()
 {
-	return (mSculptType & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH;
+    return mData[POSITION];
 }
 
-bool LLVolumeParams::operator==(const LLVolumeParams &params) const
+LLVector4a& LLVolumeFace::VertexData::getNormal()
 {
-	return ( (getPathParams() == params.getPathParams()) &&
-			 (getProfileParams() == params.getProfileParams()) &&
-			 (mSculptID == params.mSculptID) &&
-			 (mSculptType == params.mSculptType) );
+    return mData[NORMAL];
 }
 
-bool LLVolumeParams::operator!=(const LLVolumeParams &params) const
+const LLVector4a& LLVolumeFace::VertexData::getPosition() const
 {
-	return ( (getPathParams() != params.getPathParams()) ||
-			 (getProfileParams() != params.getProfileParams()) ||
-			 (mSculptID != params.mSculptID) ||
-			 (mSculptType != params.mSculptType) );
+    return mData[POSITION];
 }
 
-bool LLVolumeParams::operator<(const LLVolumeParams &params) const
+const LLVector4a& LLVolumeFace::VertexData::getNormal() const
 {
-	if( getPathParams() != params.getPathParams() )
-	{
-		return getPathParams() < params.getPathParams();
-	}
-	
-	if (getProfileParams() != params.getProfileParams())
-	{
-		return getProfileParams() < params.getProfileParams();
-	}
-	
-	if (mSculptID != params.mSculptID)
-	{
-		return mSculptID < params.mSculptID;
-	}
-
-	return mSculptType < params.mSculptType;
-
-
+    return mData[NORMAL];
 }
 
-void LLVolumeParams::copyParams(const LLVolumeParams &params)
-{
-	mProfileParams.copyParams(params.mProfileParams);
-	mPathParams.copyParams(params.mPathParams);
-	mSculptID = params.getSculptID();
-	mSculptType = params.getSculptType();
-}
 
-// Less restricitve approx 0 for volumes
-const F32 APPROXIMATELY_ZERO = 0.001f;
-bool approx_zero( F32 f, F32 tolerance = APPROXIMATELY_ZERO)
+void LLVolumeFace::VertexData::setPosition(const LLVector4a& pos)
 {
-	return (f >= -tolerance) && (f <= tolerance);
+    mData[POSITION] = pos;
 }
 
-// return true if in range (or nearly so)
-static bool limit_range(F32& v, F32 min, F32 max, F32 tolerance = APPROXIMATELY_ZERO)
+void LLVolumeFace::VertexData::setNormal(const LLVector4a& norm)
 {
-	F32 min_delta = v - min;
-	if (min_delta < 0.f)
-	{
-		v = min;
-		if (!approx_zero(min_delta, tolerance))
-			return false;
-	}
-	F32 max_delta = max - v;
-	if (max_delta < 0.f)
-	{
-		v = max;
-		if (!approx_zero(max_delta, tolerance))
-			return false;
-	}
-	return true;
+    mData[NORMAL] = norm;
 }
 
-bool LLVolumeParams::setBeginAndEndS(const F32 b, const F32 e)
+bool LLVolumeFace::VertexData::operator<(const LLVolumeFace::VertexData& rhs)const
 {
-	bool valid = true;
-
-	// First, clamp to valid ranges.
-	F32 begin = b;
-	valid &= limit_range(begin, 0.f, 1.f - MIN_CUT_DELTA);
-
-	F32 end = e;
-	if (end >= .0149f && end < MIN_CUT_DELTA) end = MIN_CUT_DELTA; // eliminate warning for common rounding error
-	valid &= limit_range(end, MIN_CUT_DELTA, 1.f);
-
-	valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f);
-
-	// Now set them.
-	mProfileParams.setBegin(begin);
-	mProfileParams.setEnd(end);
-
-	return valid;
-}
+    const F32* lp = this->getPosition().getF32ptr();
+    const F32* rp = rhs.getPosition().getF32ptr();
 
-bool LLVolumeParams::setBeginAndEndT(const F32 b, const F32 e)
-{
-	bool valid = true;
+    if (lp[0] != rp[0])
+    {
+        return lp[0] < rp[0];
+    }
 
-	// First, clamp to valid ranges.
-	F32 begin = b;
-	valid &= limit_range(begin, 0.f, 1.f - MIN_CUT_DELTA);
+    if (rp[1] != lp[1])
+    {
+        return lp[1] < rp[1];
+    }
 
-	F32 end = e;
-	valid &= limit_range(end, MIN_CUT_DELTA, 1.f);
+    if (rp[2] != lp[2])
+    {
+        return lp[2] < rp[2];
+    }
 
-	valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f);
+    lp = getNormal().getF32ptr();
+    rp = rhs.getNormal().getF32ptr();
 
-	// Now set them.
-	mPathParams.setBegin(begin);
-	mPathParams.setEnd(end);
+    if (lp[0] != rp[0])
+    {
+        return lp[0] < rp[0];
+    }
 
-	return valid;
-}			
+    if (rp[1] != lp[1])
+    {
+        return lp[1] < rp[1];
+    }
 
-bool LLVolumeParams::setHollow(const F32 h)
-{
-	// Validate the hollow based on path and profile.
-	U8 profile 	= mProfileParams.getCurveType() & LL_PCODE_PROFILE_MASK;
-	U8 hole_type 	= mProfileParams.getCurveType() & LL_PCODE_HOLE_MASK;
-	
-	F32 max_hollow = HOLLOW_MAX;
-
-	// Only square holes have trouble.
-	if (LL_PCODE_HOLE_SQUARE == hole_type)
-	{
-		switch(profile)
-		{
-		case LL_PCODE_PROFILE_CIRCLE:
-		case LL_PCODE_PROFILE_CIRCLE_HALF:
-		case LL_PCODE_PROFILE_EQUALTRI:
-			max_hollow = HOLLOW_MAX_SQUARE;
-		}
-	}
-
-	F32 hollow = h;
-	bool valid = limit_range(hollow, HOLLOW_MIN, max_hollow);
-	mProfileParams.setHollow(hollow); 
-
-	return valid;
-}	
+    if (rp[2] != lp[2])
+    {
+        return lp[2] < rp[2];
+    }
 
-bool LLVolumeParams::setTwistBegin(const F32 b)
-{
-	F32 twist_begin = b;
-	bool valid = limit_range(twist_begin, TWIST_MIN, TWIST_MAX);
-	mPathParams.setTwistBegin(twist_begin);
-	return valid;
-}
+    if (mTexCoord.mV[0] != rhs.mTexCoord.mV[0])
+    {
+        return mTexCoord.mV[0] < rhs.mTexCoord.mV[0];
+    }
 
-bool LLVolumeParams::setTwistEnd(const F32 e)
-{	
-	F32 twist_end = e;
-	bool valid = limit_range(twist_end, TWIST_MIN, TWIST_MAX);
-	mPathParams.setTwistEnd(twist_end);
-	return valid;
+    return mTexCoord.mV[1] < rhs.mTexCoord.mV[1];
 }
 
-bool LLVolumeParams::setRatio(const F32 x, const F32 y)
+bool LLVolumeFace::VertexData::operator==(const LLVolumeFace::VertexData& rhs)const
 {
-	F32 min_x = RATIO_MIN;
-	F32 max_x = RATIO_MAX;
-	F32 min_y = RATIO_MIN;
-	F32 max_y = RATIO_MAX;
-	// If this is a circular path (and not a sphere) then 'ratio' is actually hole size.
-	U8 path_type 	= mPathParams.getCurveType();
-	U8 profile_type = mProfileParams.getCurveType() & LL_PCODE_PROFILE_MASK;
-	if ( LL_PCODE_PATH_CIRCLE == path_type &&
-		 LL_PCODE_PROFILE_CIRCLE_HALF != profile_type)
-	{
-		// Holes are more restricted...
-		min_x = HOLE_X_MIN;
-		max_x = HOLE_X_MAX;
-		min_y = HOLE_Y_MIN;
-		max_y = HOLE_Y_MAX;
-	}
-
-	F32 ratio_x = x;
-	bool valid = limit_range(ratio_x, min_x, max_x);
-	F32 ratio_y = y;
-	valid &= limit_range(ratio_y, min_y, max_y);
-
-	mPathParams.setScale(ratio_x, ratio_y);
-
-	return valid;
+    return mData[POSITION].equals3(rhs.getPosition()) &&
+            mData[NORMAL].equals3(rhs.getNormal()) &&
+            mTexCoord == rhs.mTexCoord;
 }
 
-bool LLVolumeParams::setShear(const F32 x, const F32 y)
+bool LLVolumeFace::VertexData::compareNormal(const LLVolumeFace::VertexData& rhs, F32 angle_cutoff) const
 {
-	F32 shear_x = x;
-	bool valid = limit_range(shear_x, SHEAR_MIN, SHEAR_MAX);
-	F32 shear_y = y;
-	valid &= limit_range(shear_y, SHEAR_MIN, SHEAR_MAX);
-	mPathParams.setShear(shear_x, shear_y);
-	return valid;
-}
+    bool retval = false;
 
-bool LLVolumeParams::setTaperX(const F32 v)
-{
-	F32 taper = v;
-	bool valid = limit_range(taper, TAPER_MIN, TAPER_MAX);
-	mPathParams.setTaperX(taper);
-	return valid;
-}
+    const F32 epsilon = 0.00001f;
 
-bool LLVolumeParams::setTaperY(const F32 v)
-{
-	F32 taper = v;
-	bool valid = limit_range(taper, TAPER_MIN, TAPER_MAX);
-	mPathParams.setTaperY(taper);
-	return valid;
-}
+    if (rhs.mData[POSITION].equals3(mData[POSITION], epsilon) &&
+        fabs(rhs.mTexCoord[0]-mTexCoord[0]) < epsilon &&
+        fabs(rhs.mTexCoord[1]-mTexCoord[1]) < epsilon)
+    {
+        if (angle_cutoff > 1.f)
+        {
+            retval = (mData[NORMAL].equals3(rhs.mData[NORMAL], epsilon));
+        }
+        else
+        {
+            F32 cur_angle = rhs.mData[NORMAL].dot3(mData[NORMAL]).getF32();
+            retval = cur_angle > angle_cutoff;
+        }
+    }
 
-bool LLVolumeParams::setRevolutions(const F32 r)
-{
-	F32 revolutions = r;
-	bool valid = limit_range(revolutions, REV_MIN, REV_MAX);
-	mPathParams.setRevolutions(revolutions);
-	return valid;
+    return retval;
 }
 
-bool LLVolumeParams::setRadiusOffset(const F32 offset)
+bool LLVolume::unpackVolumeFaces(std::istream& is, S32 size)
 {
-	bool valid = true;
-
-	// If this is a sphere, just set it to 0 and get out.
-	U8 path_type 	= mPathParams.getCurveType();
-	U8 profile_type = mProfileParams.getCurveType() & LL_PCODE_PROFILE_MASK;
-	if ( LL_PCODE_PROFILE_CIRCLE_HALF == profile_type ||
-		LL_PCODE_PATH_CIRCLE != path_type )
-	{
-		mPathParams.setRadiusOffset(0.f);
-		return true;
-	}
-
-	// Limit radius offset, based on taper and hole size y.
-	F32 radius_offset	= offset;
-	F32 taper_y    		= getTaperY();
-	F32 radius_mag		= fabs(radius_offset);
-	F32 hole_y_mag 		= fabs(getRatioY());
-	F32 taper_y_mag		= fabs(taper_y);
-	// Check to see if the taper effects us.
-	if ( (radius_offset > 0.f && taper_y < 0.f) ||
-			(radius_offset < 0.f && taper_y > 0.f) )
-	{
-		// The taper does not help increase the radius offset range.
-		taper_y_mag = 0.f;
-	}
-	F32 max_radius_mag = 1.f - hole_y_mag * (1.f - taper_y_mag) / (1.f - hole_y_mag);
-
-	// Enforce the maximum magnitude.
-	F32 delta = max_radius_mag - radius_mag;
-	if (delta < 0.f)
-	{
-		// Check radius offset sign.
-		if (radius_offset < 0.f)
-		{
-			radius_offset = -max_radius_mag;
-		}
-		else
-		{
-			radius_offset = max_radius_mag;
-		}
-		valid = approx_zero(delta, .1f);
-	}
-
-	mPathParams.setRadiusOffset(radius_offset);
-	return valid;
-}
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
 
-bool LLVolumeParams::setSkew(const F32 skew_value)
-{
-	bool valid = true;
-
-	// Check the skew value against the revolutions.
-	F32 skew		= llclamp(skew_value, SKEW_MIN, SKEW_MAX);
-	F32 skew_mag	= fabs(skew);
-	F32 revolutions = getRevolutions();
-	F32 scale_x		= getRatioX();
-	F32 min_skew_mag = 1.0f - 1.0f / (revolutions * scale_x + 1.0f);
-	// Discontinuity; A revolution of 1 allows skews below 0.5.
-	if ( fabs(revolutions - 1.0f) < 0.001)
-		min_skew_mag = 0.0f;
-
-	// Clip skew.
-	F32 delta = skew_mag - min_skew_mag;
-	if (delta < 0.f)
-	{
-		// Check skew sign.
-		if (skew < 0.0f)
-		{
-			skew = -min_skew_mag;
-		}
-		else 
-		{
-			skew = min_skew_mag;
-		}
-		valid = approx_zero(delta, .01f);
-	}
-
-	mPathParams.setSkew(skew);
-	return valid;
+    //input stream is now pointing at a zlib compressed block of LLSD
+    //decompress block
+    LLSD mdl;
+    U32 uzip_result = LLUZipHelper::unzip_llsd(mdl, is, size);
+    if (uzip_result != LLUZipHelper::ZR_OK)
+    {
+        LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD with code " << uzip_result << " , will probably fetch from sim again." << LL_ENDL;
+        return false;
+    }
+    return unpackVolumeFacesInternal(mdl);
 }
 
-bool LLVolumeParams::setSculptID(LLUUID sculpt_id, U8 sculpt_type)
+bool LLVolume::unpackVolumeFaces(U8* in_data, S32 size)
 {
-	mSculptID = std::move(sculpt_id);
-	mSculptType = sculpt_type;
-	return true;
+    //input data is now pointing at a zlib compressed block of LLSD
+    //decompress block
+    LLSD mdl;
+    U32 uzip_result = LLUZipHelper::unzip_llsd(mdl, in_data, size);
+    if (uzip_result != LLUZipHelper::ZR_OK)
+    {
+        LL_DEBUGS("MeshStreaming") << "Failed to unzip LLSD blob for LoD with code " << uzip_result << " , will probably fetch from sim again." << LL_ENDL;
+        return false;
+    }
+    return unpackVolumeFacesInternal(mdl);
 }
 
-bool LLVolumeParams::setType(U8 profile, U8 path)
+bool LLVolume::unpackVolumeFacesInternal(const LLSD& mdl)
 {
-	bool result = true;
-	// First, check profile and path for validity.
-	U8 profile_type	= profile & LL_PCODE_PROFILE_MASK;
-	U8 hole_type 	= (profile & LL_PCODE_HOLE_MASK) >> 4;
-	U8 path_type	= path >> 4;
-
-	if (profile_type > LL_PCODE_PROFILE_MAX)
-	{
-		// Bad profile.  Make it square.
-		profile = LL_PCODE_PROFILE_SQUARE;
-		result = false;
-		LL_WARNS() << "LLVolumeParams::setType changing bad profile type (" << profile_type
-			 	<< ") to be LL_PCODE_PROFILE_SQUARE" << LL_ENDL;
-	}
-	else if (hole_type > LL_PCODE_HOLE_MAX)
-	{
-		// Bad hole.  Make it the same.
-		profile = profile_type;
-		result = false;
-		LL_WARNS() << "LLVolumeParams::setType changing bad hole type (" << hole_type
-			 	<< ") to be LL_PCODE_HOLE_SAME" << LL_ENDL;
-	}
-
-	if (path_type < LL_PCODE_PATH_MIN ||
-		path_type > LL_PCODE_PATH_MAX)
-	{
-		// Bad path.  Make it linear.
-		result = false;
-		LL_WARNS() << "LLVolumeParams::setType changing bad path (" << path
-			 	<< ") to be LL_PCODE_PATH_LINE" << LL_ENDL;
-		path = LL_PCODE_PATH_LINE;
-	}
-
-	mProfileParams.setCurveType(profile);
-	mPathParams.setCurveType(path);
-	return result;
-}
-
-// static 
-bool LLVolumeParams::validate(U8 prof_curve, F32 prof_begin, F32 prof_end, F32 hollow,
-		U8 path_curve, F32 path_begin, F32 path_end,
-		F32 scx, F32 scy, F32 shx, F32 shy,
-		F32 twistend, F32 twistbegin, F32 radiusoffset,
-		F32 tx, F32 ty, F32 revolutions, F32 skew)
-{
-	LLVolumeParams test_params;
-	if (!test_params.setType		(prof_curve, path_curve))
-	{
-	    	return false;
-	}
-	if (!test_params.setBeginAndEndS	(prof_begin, prof_end))
-	{
-	    	return false;
-	}
-	if (!test_params.setBeginAndEndT	(path_begin, path_end))
-	{
-	    	return false;
-	}
-	if (!test_params.setHollow		(hollow))
-	{
-	    	return false;
-	}
-	if (!test_params.setTwistBegin		(twistbegin))
-	{
-	    	return false;
-	}
-	if (!test_params.setTwistEnd		(twistend))
-	{
-	    	return false;
-	}
-	if (!test_params.setRatio		(scx, scy))
-	{
-	    	return false;
-	}
-	if (!test_params.setShear		(shx, shy))
-	{
-	    	return false;
-	}
-	if (!test_params.setTaper		(tx, ty))
-	{
-	    	return false;
-	}
-	if (!test_params.setRevolutions		(revolutions))
-	{
-	    	return false;
-	}
-	if (!test_params.setRadiusOffset	(radiusoffset))
-	{
-	    	return false;
-	}
-	if (!test_params.setSkew		(skew))
-	{
-	    	return false;
-	}
-	return true;
-}
+    {
+        U32 face_count = mdl.size();
 
-void LLVolume::getLoDTriangleCounts(S32* counts)
-{ //attempt to approximate the number of triangles that will result from generating a volume LoD set for the 
-	//supplied LLVolumeParams -- inaccurate, but a close enough approximation for determining streaming cost
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	const LLVolumeParams& params = getParams();
-	const LLPathParams& path_params = params.getPathParams();
-	const LLProfileParams& profile_params = params.getProfileParams();
+        if (face_count == 0)
+        { //no faces unpacked, treat as failed decode
+            LL_WARNS() << "found no faces!" << LL_ENDL;
+            return false;
+        }
 
-	// Check the cached data first
-	if (mTrianglesCache && mTrianglesCache->mPathParams == path_params && mTrianglesCache->mProfileParams == profile_params)
-	{
-		counts[ 0 ] = mTrianglesCache->mTriangles[0];
-		counts[ 1 ] = mTrianglesCache->mTriangles[1];
-		counts[ 2 ] = mTrianglesCache->mTriangles[2];
-		counts[ 3 ] = mTrianglesCache->mTriangles[3];
-		return;
-	}
+        mVolumeFaces.resize(face_count);
 
-	if(!mTrianglesCache)
-		mTrianglesCache = std::make_unique<TrianglesPerLODCache>();
+        for (size_t i = 0; i < face_count; ++i)
+        {
+            LLVolumeFace& face = mVolumeFaces[i];
+
+            const auto& mdl_face = mdl[i];
+
+            if (mdl_face.has("NoGeometry"))
+            { //face has no geometry, continue
+                face.resizeIndices(3);
+                face.resizeVertices(1);
+                face.mPositions->clear();
+                face.mNormals->clear();
+                face.mTexCoords->setZero();
+                memset(face.mIndices, 0, sizeof(U16)*3);
+                continue;
+            }
 
-	mTrianglesCache->mPathParams = params.getPathParams();
-	mTrianglesCache->mProfileParams = params.getProfileParams();
+            const LLSD::Binary& pos = mdl_face["Position"].asBinary();
+            const LLSD::Binary& norm = mdl_face["Normal"].asBinary();
+#if 0 // keep this code for now in case we decide to add support for on-the-wire tangents
+            const LLSD::Binary& tangent = mdl_face["Tangent"].asBinary();
+#endif
+            const LLSD::Binary& tc = mdl_face["TexCoord0"].asBinary();
+            const LLSD::Binary& idx = mdl_face["TriangleList"].asBinary();
 
-	F32 detail[] = {1.f, 1.5f, 2.5f, 4.f};	
-	for (S32 i = 0; i < 4; i++)
-	{
-		S32 count = 0;
-		S32 path_points = LLPath::getNumPoints(path_params, detail[i]);
-		S32 profile_points = LLProfile::getNumPoints(profile_params, false, detail[i]);
+            //copy out indices
+            S32 num_indices = idx.size() / 2;
+            const S32 indices_to_discard = num_indices % 3;
+            if (indices_to_discard > 0)
+            {
+                // Invalid number of triangle indices
+                LL_WARNS() << "Incomplete triangle discarded from face! Indices count " << num_indices << " was not divisible by 3. face index: " << i << " Total: " << face_count << LL_ENDL;
+                num_indices -= indices_to_discard;
+            }
+            face.resizeIndices(num_indices);
 
-		count = (profile_points-1)*2*(path_points-1);
-		count += profile_points*2;
+            if (num_indices > 2 && !face.mIndices)
+            {
+                LL_WARNS() << "Failed to allocate " << num_indices << " indices for face index: " << i << " Total: " << face_count << LL_ENDL;
+                continue;
+            }
 
-		counts[i] = count;
-		mTrianglesCache->mTriangles[i] = count;
-	}
-}
+            if (idx.empty() || face.mNumIndices < 3)
+            { //why is there an empty index list?
+                LL_WARNS() << "Empty face present! Face index: " << i << " Total: " << face_count << LL_ENDL;
+                continue;
+            }
 
+            U16* indices = (U16*) &(idx[0]);
+            for (U32 j = 0; j < num_indices; ++j)
+            {
+                face.mIndices[j] = indices[j];
+            }
 
-S32 LLVolume::getNumTriangles(S32* vcount) const
-{
-	U32 triangle_count = 0;
-	U32 vertex_count = 0;
+            //copy out vertices
+            U32 num_verts = pos.size()/(3*2);
+            face.resizeVertices(num_verts);
 
-	for (S32 i = 0, end = getNumVolumeFaces(); i < end; ++i)
-	{
-		const LLVolumeFace& face = getVolumeFace(i);
-		triangle_count += face.mNumIndices/3;
+            if (num_verts > 0 && !face.mPositions)
+            {
+                LL_WARNS() << "Failed to allocate " << num_verts << " vertices for face index: " << i << " Total: " << face_count << LL_ENDL;
+                face.resizeIndices(0);
+                continue;
+            }
 
-		vertex_count += face.mNumVertices;
-	}
+            LLVector3 minp;
+            LLVector3 maxp;
+            LLVector2 min_tc;
+            LLVector2 max_tc;
 
+            minp.setValue(mdl_face["PositionDomain"]["Min"]);
+            maxp.setValue(mdl_face["PositionDomain"]["Max"]);
+            LLVector4a min_pos, max_pos;
+            min_pos.load3(minp.mV);
+            max_pos.load3(maxp.mV);
 
-	if (vcount)
-	{
-		*vcount = vertex_count;
-	}
-	
-	return triangle_count;
-}
+            min_tc.setValue(mdl_face["TexCoord0Domain"]["Min"]);
+            max_tc.setValue(mdl_face["TexCoord0Domain"]["Max"]);
 
+            //unpack normalized scale/translation
+            if (mdl_face.has("NormalizedScale"))
+            {
+                face.mNormalizedScale.setValue(mdl_face["NormalizedScale"]);
+            }
+            else
+            {
+                face.mNormalizedScale.set(1, 1, 1);
+            }
 
-//-----------------------------------------------------------------------------
-// generateSilhouetteVertices()
-//-----------------------------------------------------------------------------
-void LLVolume::generateSilhouetteVertices(std::vector<LLVector3> &vertices,
-										  std::vector<LLVector3> &normals,
-										  const LLVector3& obj_cam_vec_in,
-										  const LLMatrix4a& mat,
-										  const LLMatrix4a& norm_mat,
-										  S32 face_mask)
-{
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
-
-	LLVector4a obj_cam_vec;
-	obj_cam_vec.load3(obj_cam_vec_in.mV);
-
-	vertices.clear();
-	normals.clear();
-
-	if ((mParams.getSculptType() & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
-	{
-		return;
-	}
-	
-	S32 cur_index = 0;
-	//for each face
-	for (face_list_t::iterator iter = mVolumeFaces.begin();
-		 iter != mVolumeFaces.end(); ++iter)
-	{
-		LLVolumeFace& face = *iter;
-	
-		if (!(face_mask & (0x1 << cur_index++)) ||
-		     face.mNumIndices == 0 || face.mEdge.empty())
-		{
-			continue;
-		}
-
-		if (face.mTypeMask & (LLVolumeFace::CAP_MASK))
-		{
-			LLVector4a* v = (LLVector4a*)face.mPositions;
-			LLVector4a* n = (LLVector4a*)face.mNormals;
-
-			for (U32 j = 0; j < face.mNumIndices / 3; j++)
-			{
-				for (S32 k = 0; k < 3; k++)
-				{
-					S32 index = face.mEdge[j * 3 + k];
-
-					if (index == -1)
-					{
-						// silhouette edge, currently only cubes, so no other conditions
-
-						S32 v1 = face.mIndices[j * 3 + k];
-						S32 v2 = face.mIndices[j * 3 + ((k + 1) % 3)];
-
-						LLVector4a t;
-						mat.affineTransform(v[v1], t);
-						vertices.emplace_back(t[0], t[1], t[2]);
-
-						norm_mat.rotate(n[v1], t);
-
-						t.normalize3fast();
-						normals.emplace_back(t[0], t[1], t[2]);
-
-						mat.affineTransform(v[v2], t);
-						vertices.emplace_back(t[0], t[1], t[2]);
-
-						norm_mat.rotate(n[v2], t);
-						t.normalize3fast();
-						normals.emplace_back(t[0], t[1], t[2]);
-					}
-				}
-			}
-	
-		}
-		else
-		{
-
-			//==============================================
-			//DEBUG draw edge map instead of silhouette edge
-			//==============================================
+            LLVector4a pos_range;
+            pos_range.setSub(max_pos, min_pos);
+            LLVector2 tc_range2 = max_tc - min_tc;
 
-#if DEBUG_SILHOUETTE_EDGE_MAP
+            LLVector4a tc_range;
+            tc_range.set(tc_range2[0], tc_range2[1], tc_range2[0], tc_range2[1]);
+            LLVector4a min_tc4(min_tc[0], min_tc[1], min_tc[0], min_tc[1]);
 
-			//for each triangle
-            U32 tri_count = face.mNumIndices / 3;
-            for (U32 j = 0; j < tri_count; j++) {
-				//get vertices
-				S32 v1 = face.mIndices[j*3+0];
-				S32 v2 = face.mIndices[j*3+1];
-				S32 v3 = face.mIndices[j*3+2];
-
-				//get current face center
-				LLVector3 cCenter = (face.mVertices[v1].getPosition() + 
-									face.mVertices[v2].getPosition() + 
-									face.mVertices[v3].getPosition()) / 3.0f;
-
-				//for each edge
-				for (S32 k = 0; k < 3; k++) {
-                    S32 nIndex = face.mEdge[j*3+k];
-					if (nIndex <= -1) {
-						continue;
-					}
+            LLVector4a* pos_out = face.mPositions;
+            LLVector4a* norm_out = face.mNormals;
+            LLVector4a* tc_out = (LLVector4a*) face.mTexCoords;
 
-                    if (nIndex >= (S32)tri_count) {
-						continue;
-					}
-					//get neighbor vertices
-					v1 = face.mIndices[nIndex*3+0];
-					v2 = face.mIndices[nIndex*3+1];
-					v3 = face.mIndices[nIndex*3+2];
-
-					//get neighbor face center
-					LLVector3 nCenter = (face.mVertices[v1].getPosition() + 
-									face.mVertices[v2].getPosition() + 
-									face.mVertices[v3].getPosition()) / 3.0f;
-
-					//draw line
-					vertices.push_back(cCenter);
-					vertices.push_back(nCenter);
-					normals.push_back(LLVector3(1,1,1));
-					normals.push_back(LLVector3(1,1,1));
-					segments.push_back(vertices.size());
-				}
-			}
-		
-			continue;
-
-			//==============================================
-			//DEBUG
-			//==============================================
-
-			//==============================================
-			//DEBUG draw normals instead of silhouette edge
-			//==============================================
-#elif DEBUG_SILHOUETTE_NORMALS
+            {
+                U16* v = (U16*) &(pos[0]);
+                for (U32 j = 0; j < num_verts; ++j)
+                {
+                    pos_out->set((F32) v[0], (F32) v[1], (F32) v[2]);
+                    pos_out->div(65535.f);
+                    pos_out->mul(pos_range);
+                    pos_out->add(min_pos);
+                    pos_out++;
+                    v += 3;
+                }
 
-			//for each vertex
-			for (U32 j = 0; j < face.mNumVertices; j++) {
-				vertices.push_back(face.mVertices[j].getPosition());
-				vertices.push_back(face.mVertices[j].getPosition() + face.mVertices[j].getNormal()*0.1f);
-				normals.push_back(LLVector3(0,0,1));
-				normals.push_back(LLVector3(0,0,1));
-				segments.push_back(vertices.size());
-#if DEBUG_SILHOUETTE_BINORMALS
-				vertices.push_back(face.mVertices[j].getPosition());
-				vertices.push_back(face.mVertices[j].getPosition() + face.mVertices[j].mTangent*0.1f);
-				normals.push_back(LLVector3(0,0,1));
-				normals.push_back(LLVector3(0,0,1));
-				segments.push_back(vertices.size());
-#endif
-			}
-						
-			continue;
-#else
-			//==============================================
-			//DEBUG
-			//==============================================
-
-			static const U8 AWAY = 0x01,
-							TOWARDS = 0x02;
-
-			//for each triangle
-			std::vector<U8> fFacing;
-			vector_append(fFacing, face.mNumIndices/3);
-
-			LLVector4a* v = (LLVector4a*) face.mPositions;
-			LLVector4a* n = (LLVector4a*) face.mNormals;
-
-			for (U32 j = 0; j < face.mNumIndices/3; j++) 
-			{
-				//approximate normal
-				S32 v1 = face.mIndices[j*3+0];
-				S32 v2 = face.mIndices[j*3+1];
-				S32 v3 = face.mIndices[j*3+2];
-
-				LLVector4a c1,c2;
-				c1.setSub(v[v1], v[v2]);
-				c2.setSub(v[v2], v[v3]);
-
-				LLVector4a norm;
-
-				norm.setCross3(c1, c2);
-
-				if (norm.dot3(norm) < 0.00000001f) 
-				{
-					fFacing[j] = AWAY | TOWARDS;
-				}
-				else 
-				{
-					//get view vector
-					LLVector4a view;
-					view.setSub(obj_cam_vec, v[v1]);
-					bool away = view.dot3(norm) > 0.0f; 
-					if (away) 
-					{
-						fFacing[j] = AWAY;
-					}
-					else 
-					{
-						fFacing[j] = TOWARDS;
-					}
-				}
-			}
-			
-			//for each triangle
-			for (U32 j = 0; j < face.mNumIndices/3; j++) 
-			{
-				if (fFacing[j] == (AWAY | TOWARDS)) 
-				{ //this is a degenerate triangle
-					//take neighbor facing (degenerate faces get facing of one of their neighbors)
-					// *FIX IF NEEDED:  this does not deal with neighboring degenerate faces
-					for (S32 k = 0; k < 3; k++) 
-					{
-						S32 index = face.mEdge[j*3+k];
-						if (index != -1) 
-						{
-							fFacing[j] = fFacing[index];
-							break;
-						}
-					}
-					continue; //skip degenerate face
-				}
-
-				//for each edge
-				for (S32 k = 0; k < 3; k++) {
-					S32 index = face.mEdge[j*3+k];
-					if (index != -1 && fFacing[index] == (AWAY | TOWARDS)) {
-						//our neighbor is degenerate, make him face our direction
-						fFacing[face.mEdge[j*3+k]] = fFacing[j];
-						continue;
-					}
-
-					if (index == -1 ||		//edge has no neighbor, MUST be a silhouette edge
-						(fFacing[index] & fFacing[j]) == 0) { 	//we found a silhouette edge
-
-						S32 v1 = face.mIndices[j*3+k];
-						S32 v2 = face.mIndices[j*3+((k+1)%3)];
-						
-						LLVector4a t;
-						mat.affineTransform(v[v1], t);
-						vertices.emplace_back(t[0], t[1], t[2]);
-
-						norm_mat.rotate(n[v1], t);
-
-						t.normalize3fast();
-						normals.emplace_back(t[0], t[1], t[2]);
-
-						mat.affineTransform(v[v2], t);
-						vertices.emplace_back(t[0], t[1], t[2]);
-						
-						norm_mat.rotate(n[v2], t);
-						t.normalize3fast();
-						normals.emplace_back(t[0], t[1], t[2]);
-					}
-				}		
-			}
-#endif
-		}
-	}
-}
-
-S32 LLVolume::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end, 
-								   S32 face_idx,
-								   LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent_out)
-{
-	S32 hit_face = -1;
-	
-	S32 start_face;
-	S32 end_face;
-	
-	if (face_idx == -1)  // ALL_SIDES
-	{
-		start_face = 0;
-		end_face = getNumVolumeFaces() - 1;
-	}
-	else
-	{
-        start_face = face_idx;
-        end_face   = face_idx;
-	}
+            }
 
-	LLVector4a dir;
-	dir.setSub(end, start);
+            {
+                if (!norm.empty())
+                {
+                    U16* n = (U16*) &(norm[0]);
+                    for (U32 j = 0; j < num_verts; ++j)
+                    {
+                        norm_out->set((F32) n[0], (F32) n[1], (F32) n[2]);
+                        norm_out->div(65535.f);
+                        norm_out->mul(2.f);
+                        norm_out->sub(1.f);
+                        norm_out++;
+                        n += 3;
+                    }
+                }
+                else
+                {
+                    for (U32 j = 0; j < num_verts; ++j)
+                    {
+                        norm_out->clear();
+                        norm_out++; // or just norm_out[j].clear();
+                    }
+                }
+            }
 
-	F32 closest_t = 2.f; // must be larger than 1
-	
-	end_face = llmin(end_face, getNumVolumeFaces()-1);
+#if 0 // keep this code for now in case we decide to add support for on-the-wire tangents
+            {
+                if (!tangent.empty())
+                {
+                    face.allocateTangents(face.mNumVertices);
+                    U16* t = (U16*)&(tangent[0]);
 
-	for (S32 i = start_face; i <= end_face; i++)
-	{
-		LLVolumeFace &face = mVolumeFaces[i];
+                    // NOTE: tangents coming from the asset may not be mikkt space, but they should always be used by the GLTF shaders to
+                    // maintain compliance with the GLTF spec
+                    LLVector4a* t_out = face.mTangents;
 
-		LLVector4a box_center;
-		box_center.setAdd(face.mExtents[0], face.mExtents[1]);
-		box_center.mul(0.5f);
+                    for (U32 j = 0; j < num_verts; ++j)
+                    {
+                        t_out->set((F32)t[0], (F32)t[1], (F32)t[2], (F32) t[3]);
+                        t_out->div(65535.f);
+                        t_out->mul(2.f);
+                        t_out->sub(1.f);
 
-		LLVector4a box_size;
-		box_size.setSub(face.mExtents[1], face.mExtents[0]);
+                        F32* tp = t_out->getF32ptr();
+                        tp[3] = tp[3] < 0.f ? -1.f : 1.f;
 
-        if (LLLineSegmentBoxIntersect(start, end, box_center, box_size))
-		{
-			if (tangent_out != NULL) // if the caller wants tangents, we may need to generate them
-			{
-                genTangents(i);
-			}
-
-			if (isUnique())
-			{ //don't bother with an octree for flexi volumes
-				U32 tri_count = face.mNumIndices/3;
-
-				for (U32 j = 0; j < tri_count; ++j)
-				{
-					U16 idx0 = face.mIndices[j*3+0];
-					U16 idx1 = face.mIndices[j*3+1];
-					U16 idx2 = face.mIndices[j*3+2];
-
-					const LLVector4a& v0 = face.mPositions[idx0];
-					const LLVector4a& v1 = face.mPositions[idx1];
-					const LLVector4a& v2 = face.mPositions[idx2];
-				
-					F32 a,b,t;
-
-					if (LLTriangleRayIntersect(v0, v1, v2,
-							start, dir, a, b, t))
-					{
-						if ((t >= 0.f) &&      // if hit is after start
-							(t <= 1.f) &&      // and before end
-							(t < closest_t))   // and this hit is closer
-						{
-							closest_t = t;
-							hit_face = i;
-
-							if (intersection != NULL)
-							{
-								LLVector4a intersect = dir;
-								intersect.mul(closest_t);
-								intersect.add(start);
-								*intersection = intersect;
-							}
-
-
-							if (tex_coord != NULL)
-							{
-								LLVector2* tc = (LLVector2*) face.mTexCoords;
-								*tex_coord = ((1.f - a - b)  * tc[idx0] +
-									a              * tc[idx1] +
-									b              * tc[idx2]);
-
-							}
-
-							if (normal!= NULL)
-							{
-								LLVector4a* norm = face.mNormals;
-								
-								LLVector4a n1,n2,n3;
-								n1 = norm[idx0];
-								n1.mul(1.f-a-b);
-								
-								n2 = norm[idx1];
-								n2.mul(a);
-								
-								n3 = norm[idx2];
-								n3.mul(b);
-
-								n1.add(n2);
-								n1.add(n3);
-								
-								*normal		= n1; 
-							}
-
-							if (tangent_out != NULL)
-							{
-								LLVector4a* tangents = face.mTangents;
-								
-								LLVector4a t1,t2,t3;
-								t1 = tangents[idx0];
-								t1.mul(1.f-a-b);
-								
-								t2 = tangents[idx1];
-								t2.mul(a);
-								
-								t3 = tangents[idx2];
-								t3.mul(b);
-
-								t1.add(t2);
-								t1.add(t3);
-								
-								*tangent_out = t1; 
-							}
-						}
-					}
-				}
-			}
-			else
-			{
-                if (!face.getOctree())
-				{
-					face.createOctree();
-				}
-			
-				LLOctreeTriangleRayIntersect intersect(start, dir, &face, &closest_t, intersection, tex_coord, normal, tangent_out);
-                intersect.traverse(face.getOctree());
-				if (intersect.mHitFace)
-				{
-					hit_face = i;
-				}
-			}
-		}		
-	}
-	
-	
-	return hit_face;
-}
+                        t_out++;
+                        t += 4;
+                    }
+                }
+            }
+#endif
 
-class LLVertexIndexPair
-{
-public:
-	LLVertexIndexPair(const LLVector3 &vertex, const S32 index);
+            {
+                if (!tc.empty())
+                {
+                    U16* t = (U16*) &(tc[0]);
+                    for (U32 j = 0; j < num_verts; j+=2)
+                    {
+                        if (j < num_verts-1)
+                        {
+                            tc_out->set((F32) t[0], (F32) t[1], (F32) t[2], (F32) t[3]);
+                        }
+                        else
+                        {
+                            tc_out->set((F32) t[0], (F32) t[1], 0.f, 0.f);
+                        }
 
-	LLVector3 mVertex;
-	S32	mIndex;
-};
+                        t += 4;
 
-LLVertexIndexPair::LLVertexIndexPair(const LLVector3 &vertex, const S32 index)
-	: mVertex(vertex), mIndex(index)
-{ }
+                        tc_out->div(65535.f);
+                        tc_out->mul(tc_range);
+                        tc_out->add(min_tc4);
 
-const F32 VERTEX_SLOP = 0.00001f;
+                        tc_out++;
+                    }
+                }
+                else
+                {
+                    for (U32 j = 0; j < num_verts; j += 2)
+                    {
+                        tc_out->clear();
+                        tc_out++;
+                    }
+                }
+            }
 
-struct lessVertex
-{
-	bool operator()(const LLVertexIndexPair *a, const LLVertexIndexPair *b)
-	{
-		const F32 slop = VERTEX_SLOP;
-
-		if (a->mVertex.mV[0] + slop < b->mVertex.mV[0])
-		{
-			return TRUE;
-		}
-		else if (a->mVertex.mV[0] - slop > b->mVertex.mV[0])
-		{
-			return FALSE;
-		}
-		
-		if (a->mVertex.mV[1] + slop < b->mVertex.mV[1])
-		{
-			return TRUE;
-		}
-		else if (a->mVertex.mV[1] - slop > b->mVertex.mV[1])
-		{
-			return FALSE;
-		}
-		
-		if (a->mVertex.mV[2] + slop < b->mVertex.mV[2])
-		{
-			return TRUE;
-		}
-		else if (a->mVertex.mV[2] - slop > b->mVertex.mV[2])
-		{
-			return FALSE;
-		}
-		
-		return FALSE;
-	}
-};
+            if (mdl_face.has("Weights"))
+            {
+                face.allocateWeights(num_verts);
+                if (!face.mWeights && num_verts)
+                {
+                    LL_WARNS() << "Failed to allocate " << num_verts << " weights for face index: " << i << " Total: " << face_count << LL_ENDL;
+                    face.resizeIndices(0);
+                    face.resizeVertices(0);
+                    continue;
+                }
 
-struct lessTriangle
-{
-	bool operator()(const S32 *a, const S32 *b)
-	{
-		if (*a < *b)
-		{
-			return TRUE;
-		}
-		else if (*a > *b)
-		{
-			return FALSE;
-		}
-
-		if (*(a+1) < *(b+1))
-		{
-			return TRUE;
-		}
-		else if (*(a+1) > *(b+1))
-		{
-			return FALSE;
-		}
-
-		if (*(a+2) < *(b+2))
-		{
-			return TRUE;
-		}
-		else if (*(a+2) > *(b+2))
-		{
-			return FALSE;
-		}
-
-		return FALSE;
-	}
-};
+                const LLSD::Binary& weights = mdl_face["Weights"].asBinary();
 
-BOOL equalTriangle(const S32 *a, const S32 *b)
-{
-	if ((*a == *b) && (*(a+1) == *(b+1)) && (*(a+2) == *(b+2)))
-	{
-		return TRUE;
-	}
-	return FALSE;
-}
+                U32 idx = 0;
 
-BOOL LLVolumeParams::importFile(LLFILE *fp)
-{
-	//LL_INFOS() << "importing volume" << LL_ENDL;
-	const S32 BUFSIZE = 16384;
-	char buffer[BUFSIZE];	/* Flawfinder: ignore */
-	// *NOTE: changing the size or type of this buffer will require
-	// changing the sscanf below.
-	char keyword[256];	/* Flawfinder: ignore */
-	keyword[0] = 0;
-
-	while (!feof(fp))
-	{
-		if (fgets(buffer, BUFSIZE, fp) == NULL)
-		{
-			buffer[0] = '\0';
-		}
-		
-		sscanf(buffer, " %255s", keyword);	/* Flawfinder: ignore */
-		if (!strcmp("{", keyword))
-		{
-			continue;
-		}
-		if (!strcmp("}",keyword))
-		{
-			break;
-		}
-		else if (!strcmp("profile", keyword))
-		{
-			mProfileParams.importFile(fp);
-		}
-		else if (!strcmp("path",keyword))
-		{
-			mPathParams.importFile(fp);
-		}
-		else
-		{
-			LL_WARNS() << "unknown keyword " << keyword << " in volume import" << LL_ENDL;
-		}
-	}
-
-	return TRUE;
-}
+                U32 cur_vertex = 0;
+                size_t weight_size = weights.size();
+                while (idx < weight_size && cur_vertex < num_verts)
+                {
+                    const U8 END_INFLUENCES = 0xFF;
+                    U8 joint = weights[idx++];
 
-BOOL LLVolumeParams::exportFile(LLFILE *fp) const
-{
-	fprintf(fp,"\tshape 0\n");
-	fprintf(fp,"\t{\n");
-	mPathParams.exportFile(fp);
-	mProfileParams.exportFile(fp);
-	fprintf(fp, "\t}\n");
-	return TRUE;
+                    U32 cur_influence = 0;
+                    LLVector4 wght(0,0,0,0);
+                    U32 joints[4] = {0,0,0,0};
+                    LLVector4 joints_with_weights(0,0,0,0);
+
+                    while (joint != END_INFLUENCES && idx < weight_size)
+                    {
+                        U16 influence = weights[idx++];
+                        influence |= ((U16) weights[idx++] << 8);
+
+                        F32 w = llclamp((F32) influence / 65535.f, 0.001f, 0.999f);
+                        wght.mV[cur_influence] = w;
+                        joints[cur_influence] = joint;
+                        cur_influence++;
+
+                        if (cur_influence >= 4)
+                        {
+                            joint = END_INFLUENCES;
+                        }
+                        else
+                        {
+                            joint = weights[idx++];
+                        }
+                    }
+                    F32 wsum = wght.mV[VX] + wght.mV[VY] + wght.mV[VZ] + wght.mV[VW];
+                    if (wsum <= 0.f)
+                    {
+                        wght = LLVector4(0.999f,0.f,0.f,0.f);
+                    }
+                    for (U32 k=0; k<4; k++)
+                    {
+                        F32 f_combined = (F32) joints[k] + wght[k];
+                        joints_with_weights[k] = f_combined;
+                        // Any weights we added above should wind up non-zero and applied to a specific bone.
+                        // A failure here would indicate a floating point precision error in the math.
+                        llassert((k >= cur_influence) || (f_combined - S32(f_combined) > 0.0f));
+                    }
+                    face.mWeights[cur_vertex].loadua(joints_with_weights.mV);
+
+                    cur_vertex++;
+                }
+
+                if (cur_vertex != num_verts || idx != weights.size())
+                {
+                    LL_WARNS() << "Vertex weight count does not match vertex count!" << LL_ENDL;
+                }
+
+            }
+
+            // modifier flags?
+            bool do_mirror = (mParams.getSculptType() & LL_SCULPT_FLAG_MIRROR);
+            bool do_invert = (mParams.getSculptType() &LL_SCULPT_FLAG_INVERT);
+
+
+            // translate to actions:
+            bool do_reflect_x = false;
+            bool do_reverse_triangles = false;
+            bool do_invert_normals = false;
+
+            if (do_mirror)
+            {
+                do_reflect_x = true;
+                do_reverse_triangles = !do_reverse_triangles;
+            }
+
+            if (do_invert)
+            {
+                do_invert_normals = true;
+                do_reverse_triangles = !do_reverse_triangles;
+            }
+
+            // now do the work
+
+            if (do_reflect_x)
+            {
+                LLVector4a* p = (LLVector4a*) face.mPositions;
+                LLVector4a* n = (LLVector4a*) face.mNormals;
+
+                for (S32 i = 0; i < face.mNumVertices; i++)
+                {
+                    p[i].mul(-1.0f);
+                    n[i].mul(-1.0f);
+                }
+            }
+
+            if (do_invert_normals)
+            {
+                LLVector4a* n = (LLVector4a*) face.mNormals;
+
+                for (S32 i = 0; i < face.mNumVertices; i++)
+                {
+                    n[i].mul(-1.0f);
+                }
+            }
+
+            if (do_reverse_triangles)
+            {
+                for (U32 j = 0; j < face.mNumIndices; j += 3)
+                {
+                    // swap the 2nd and 3rd index
+                    S32 swap = face.mIndices[j+1];
+                    face.mIndices[j+1] = face.mIndices[j+2];
+                    face.mIndices[j+2] = swap;
+                }
+            }
+
+            //calculate bounding box
+            // VFExtents change
+            LLVector4a& min = face.mExtents[0];
+            LLVector4a& max = face.mExtents[1];
+
+            if (face.mNumVertices < 3)
+            { //empty face, use a dummy 1cm (at 1m scale) bounding box
+                min.splat(-0.005f);
+                max.splat(0.005f);
+            }
+            else
+            {
+                min = max = face.mPositions[0];
+
+                for (S32 i = 1; i < face.mNumVertices; ++i)
+                {
+                    min.setMin(min, face.mPositions[i]);
+                    max.setMax(max, face.mPositions[i]);
+                }
+
+                if (face.mTexCoords)
+                {
+                    LLVector2& min_tc = face.mTexCoordExtents[0];
+                    LLVector2& max_tc = face.mTexCoordExtents[1];
+
+                    min_tc = face.mTexCoords[0];
+                    max_tc = face.mTexCoords[0];
+
+                    for (U32 j = 1; j < face.mNumVertices; ++j)
+                    {
+                        update_min_max(min_tc, max_tc, face.mTexCoords[j]);
+                    }
+                }
+                else
+                {
+                    face.mTexCoordExtents[0].set(0,0);
+                    face.mTexCoordExtents[1].set(1,1);
+                }
+            }
+        }
+    }
+
+    if (!cacheOptimize(true))
+    {
+        // Out of memory?
+        LL_WARNS() << "Failed to optimize!" << LL_ENDL;
+        mVolumeFaces.clear();
+        return false;
+    }
+
+    mSculptLevel = 0;  // success!
+
+    return true;
 }
 
 
-BOOL LLVolumeParams::importLegacyStream(std::istream& input_stream)
+bool LLVolume::isMeshAssetLoaded()
 {
-	//LL_INFOS() << "importing volume" << LL_ENDL;
-	const S32 BUFSIZE = 16384;
-	// *NOTE: changing the size or type of this buffer will require
-	// changing the sscanf below.
-	char buffer[BUFSIZE];		/* Flawfinder: ignore */
-	char keyword[256];		/* Flawfinder: ignore */
-	keyword[0] = 0;
-
-	while (input_stream.good())
-	{
-		input_stream.getline(buffer, BUFSIZE);
-		sscanf(buffer, " %255s", keyword);
-		if (!strcmp("{", keyword))
-		{
-			continue;
-		}
-		if (!strcmp("}",keyword))
-		{
-			break;
-		}
-		else if (!strcmp("profile", keyword))
-		{
-			mProfileParams.importLegacyStream(input_stream);
-		}
-		else if (!strcmp("path",keyword))
-		{
-			mPathParams.importLegacyStream(input_stream);
-		}
-		else
-		{
-			LL_WARNS() << "unknown keyword " << keyword << " in volume import" << LL_ENDL;
-		}
-	}
-
-	return TRUE;
+    return mIsMeshAssetLoaded;
 }
 
-BOOL LLVolumeParams::exportLegacyStream(std::ostream& output_stream) const
+void LLVolume::setMeshAssetLoaded(bool loaded)
 {
-	output_stream <<"\tshape 0\n";
-	output_stream <<"\t{\n";
-	mPathParams.exportLegacyStream(output_stream);
-	mProfileParams.exportLegacyStream(output_stream);
-	output_stream << "\t}\n";
-	return TRUE;
+    mIsMeshAssetLoaded = loaded;
+    if (loaded)
+    {
+        mIsMeshAssetUnavaliable = false;
+    }
 }
 
-LLSD LLVolumeParams::sculptAsLLSD() const
+void LLVolume::setMeshAssetUnavaliable(bool unavaliable)
 {
-	LLSD sd = LLSD();
-	sd["id"] = getSculptID();
-	sd["type"] = getSculptType();
-
-	return sd;
+    // Don't set it if at least one lod loaded
+    if (!mIsMeshAssetLoaded)
+    {
+        mIsMeshAssetUnavaliable = unavaliable;
+    }
 }
 
-bool LLVolumeParams::sculptFromLLSD(LLSD& sd)
+bool LLVolume::isMeshAssetUnavaliable()
 {
-	setSculptID(sd["id"].asUUID(), (U8)sd["type"].asInteger());
-	return true;
+    return mIsMeshAssetUnavaliable;
 }
 
-LLSD LLVolumeParams::asLLSD() const
+void LLVolume::copyFacesTo(std::vector<LLVolumeFace> &faces) const
 {
-	LLSD sd = LLSD();
-	sd["path"] = mPathParams;
-	sd["profile"] = mProfileParams;
-	sd["sculpt"] = sculptAsLLSD();
-	
-	return sd;
+    faces = mVolumeFaces;
 }
 
-bool LLVolumeParams::fromLLSD(LLSD& sd)
+void LLVolume::copyFacesFrom(const std::vector<LLVolumeFace> &faces)
 {
-	mPathParams.fromLLSD(sd["path"]);
-	mProfileParams.fromLLSD(sd["profile"]);
-	sculptFromLLSD(sd["sculpt"]);
-		
-	return true;
+    mVolumeFaces = faces;
+    mSculptLevel = 0;
 }
 
-void LLVolumeParams::reduceS(F32 begin, F32 end)
+void LLVolume::copyVolumeFaces(const LLVolume* volume)
 {
-	begin = llclampf(begin);
-	end = llclampf(end);
-	if (begin > end)
-	{
-		F32 temp = begin;
-		begin = end;
-		end = temp;
-	}
-	F32 a = mProfileParams.getBegin();
-	F32 b = mProfileParams.getEnd();
-	mProfileParams.setBegin(a + begin * (b - a));
-	mProfileParams.setEnd(a + end * (b - a));
+    mVolumeFaces = volume->mVolumeFaces;
+    mSculptLevel = 0;
 }
 
-void LLVolumeParams::reduceT(F32 begin, F32 end)
+bool LLVolume::cacheOptimize(bool gen_tangents)
 {
-	begin = llclampf(begin);
-	end = llclampf(end);
-	if (begin > end)
-	{
-		F32 temp = begin;
-		begin = end;
-		end = temp;
-	}
-	F32 a = mPathParams.getBegin();
-	F32 b = mPathParams.getEnd();
-	mPathParams.setBegin(a + begin * (b - a));
-	mPathParams.setEnd(a + end * (b - a));
+    for (S32 i = 0; i < mVolumeFaces.size(); ++i)
+    {
+        if (!mVolumeFaces[i].cacheOptimize(gen_tangents))
+        {
+            return false;
+        }
+    }
+    return true;
 }
 
-const F32 MIN_CONCAVE_PROFILE_WEDGE = 0.125f;	// 1/8 unity
-const F32 MIN_CONCAVE_PATH_WEDGE = 0.111111f;	// 1/9 unity
 
-// returns TRUE if the shape can be approximated with a convex shape 
-// for collison purposes
-BOOL LLVolumeParams::isConvex() const
+S32 LLVolume::getNumFaces() const
 {
-	if (!getSculptID().isNull())
-	{
-		// can't determine, be safe and say no:
-		return FALSE;
-	}
-	
-	F32 path_length = mPathParams.getEnd() - mPathParams.getBegin();
-	F32 hollow = mProfileParams.getHollow();
-	 
-	U8 path_type = mPathParams.getCurveType();
-	if ( path_length > MIN_CONCAVE_PATH_WEDGE
-		&& ( mPathParams.getTwist() != mPathParams.getTwistBegin()
-		     || (hollow > 0.f 
-				 && LL_PCODE_PATH_LINE != path_type) ) )
-	{
-		// twist along a "not too short" path is concave
-		return FALSE;
-	}
-
-	F32 profile_length = mProfileParams.getEnd() - mProfileParams.getBegin();
-	BOOL same_hole = hollow == 0.f 
-					 || (mProfileParams.getCurveType() & LL_PCODE_HOLE_MASK) == LL_PCODE_HOLE_SAME;
-
-	F32 min_profile_wedge = MIN_CONCAVE_PROFILE_WEDGE;
-	U8 profile_type = mProfileParams.getCurveType() & LL_PCODE_PROFILE_MASK;
-	if ( LL_PCODE_PROFILE_CIRCLE_HALF == profile_type )
-	{
-		// it is a sphere and spheres get twice the minimum profile wedge
-		min_profile_wedge = 2.f * MIN_CONCAVE_PROFILE_WEDGE;
-	}
-
-	BOOL convex_profile = ( ( profile_length == 1.f
-						     || profile_length <= 0.5f )
-						   && hollow == 0.f )						// trivially convex
-						  || ( profile_length <= min_profile_wedge
-							  && same_hole );						// effectvely convex (even when hollow)
-
-	if (!convex_profile)
-	{
-		// profile is concave
-		return FALSE;
-	}
-
-	if ( LL_PCODE_PATH_LINE == path_type )
-	{
-		// straight paths with convex profile
-		return TRUE;
-	}
-
-	BOOL concave_path = (path_length < 1.0f) && (path_length > 0.5f);
-	if (concave_path)
-	{
-		return FALSE;
-	}
-
-	// we're left with spheres, toroids and tubes
-	if ( LL_PCODE_PROFILE_CIRCLE_HALF == profile_type )
-	{
-		// at this stage all spheres must be convex
-		return TRUE;
-	}
-
-	// it's a toroid or tube		
-	if ( path_length <= MIN_CONCAVE_PATH_WEDGE )
-	{
-		// effectively convex
-		return TRUE;
-	}
-
-	return FALSE;
+    return mIsMeshAssetLoaded ? getNumVolumeFaces() : (S32)mProfilep->mFaces.size();
 }
 
-// debug
-void LLVolumeParams::setCube()
+
+void LLVolume::createVolumeFaces()
 {
-	mProfileParams.setCurveType(LL_PCODE_PROFILE_SQUARE);
-	mProfileParams.setBegin(0.f);
-	mProfileParams.setEnd(1.f);
-	mProfileParams.setHollow(0.f);
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
 
-	mPathParams.setBegin(0.f);
-	mPathParams.setEnd(1.f);
-	mPathParams.setScale(1.f, 1.f);
-	mPathParams.setShear(0.f, 0.f);
-	mPathParams.setCurveType(LL_PCODE_PATH_LINE);
-	mPathParams.setTwistBegin(0.f);
-	mPathParams.setTwistEnd(0.f);
-	mPathParams.setRadiusOffset(0.f);
-	mPathParams.setTaper(0.f, 0.f);
-	mPathParams.setRevolutions(0.f);
-	mPathParams.setSkew(0.f);
-}
+    if (mGenerateSingleFace)
+    {
+        // do nothing
+    }
+    else
+    {
+        S32 num_faces = getNumFaces();
+        BOOL partial_build = TRUE;
+        if (num_faces != mVolumeFaces.size())
+        {
+            partial_build = FALSE;
+            mVolumeFaces.resize(num_faces);
+        }
+        // Initialize volume faces with parameter data
+        for (S32 i = 0; i < (S32)mVolumeFaces.size(); i++)
+        {
+            LLVolumeFace& vf = mVolumeFaces[i];
+            LLProfile::Face& face = mProfilep->mFaces[i];
+            vf.mBeginS = face.mIndex;
+            vf.mNumS = face.mCount;
+            if (vf.mNumS < 0)
+            {
+                LL_ERRS() << "Volume face corruption detected." << LL_ENDL;
+            }
 
-LLFaceID LLVolume::generateFaceMask()
-{
-	LLFaceID new_mask = 0x0000;
-
-	switch(mParams.getProfileParams().getCurveType() & LL_PCODE_PROFILE_MASK)
-	{
-	case LL_PCODE_PROFILE_CIRCLE:
-	case LL_PCODE_PROFILE_CIRCLE_HALF:
-		new_mask |= LL_FACE_OUTER_SIDE_0;
-		break;
-	case LL_PCODE_PROFILE_SQUARE:
-		{
-			for(S32 side = (S32)(mParams.getProfileParams().getBegin() * 4.f); side < llceil(mParams.getProfileParams().getEnd() * 4.f); side++)
-			{
-				new_mask |= LL_FACE_OUTER_SIDE_0 << side;
-			}
-		}
-		break;
-	case LL_PCODE_PROFILE_ISOTRI:
-	case LL_PCODE_PROFILE_EQUALTRI:
-	case LL_PCODE_PROFILE_RIGHTTRI:
-		{
-			for(S32 side = (S32)(mParams.getProfileParams().getBegin() * 3.f); side < llceil(mParams.getProfileParams().getEnd() * 3.f); side++)
-			{
-				new_mask |= LL_FACE_OUTER_SIDE_0 << side;
-			}
-		}
-		break;
-	default:
-		LL_ERRS() << "Unknown profile!" << LL_ENDL;
-		break;
-	}
-
-	// handle hollow objects
-	if (mParams.getProfileParams().getHollow() > 0)
-	{
-		new_mask |= LL_FACE_INNER_SIDE;
-	}
-
-	// handle open profile curves
-	if (mProfilep->isOpen())
-	{
-		new_mask |= LL_FACE_PROFILE_BEGIN | LL_FACE_PROFILE_END;
-	}
-
-	// handle open path curves
-	if (mPathp->isOpen())
-	{
-		new_mask |= LL_FACE_PATH_BEGIN | LL_FACE_PATH_END;
-	}
-
-	return new_mask;
-}
+            vf.mBeginT = 0;
+            vf.mNumT= getPath().mPath.size();
+            vf.mID = i;
 
-BOOL LLVolume::isFaceMaskValid(LLFaceID face_mask)
-{
-	LLFaceID test_mask = 0;
-	for(S32 i = 0, i_end = getNumFaces(); i < i_end; i++)
-	{
-		test_mask |= mProfilep->mFaces[i].mFaceID;
-	}
+            // Set the type mask bits correctly
+            if (mParams.getProfileParams().getHollow() > 0)
+            {
+                vf.mTypeMask |= LLVolumeFace::HOLLOW_MASK;
+            }
+            if (mProfilep->isOpen())
+            {
+                vf.mTypeMask |= LLVolumeFace::OPEN_MASK;
+            }
+            if (face.mCap)
+            {
+                vf.mTypeMask |= LLVolumeFace::CAP_MASK;
+                if (face.mFaceID == LL_FACE_PATH_BEGIN)
+                {
+                    vf.mTypeMask |= LLVolumeFace::TOP_MASK;
+                }
+                else
+                {
+                    llassert(face.mFaceID == LL_FACE_PATH_END);
+                    vf.mTypeMask |= LLVolumeFace::BOTTOM_MASK;
+                }
+            }
+            else if (face.mFaceID & (LL_FACE_PROFILE_BEGIN | LL_FACE_PROFILE_END))
+            {
+                vf.mTypeMask |= LLVolumeFace::FLAT_MASK | LLVolumeFace::END_MASK;
+            }
+            else
+            {
+                vf.mTypeMask |= LLVolumeFace::SIDE_MASK;
+                if (face.mFlat)
+                {
+                    vf.mTypeMask |= LLVolumeFace::FLAT_MASK;
+                }
+                if (face.mFaceID & LL_FACE_INNER_SIDE)
+                {
+                    vf.mTypeMask |= LLVolumeFace::INNER_MASK;
+                    if (face.mFlat && vf.mNumS > 2)
+                    { //flat inner faces have to copy vert normals
+                        vf.mNumS = vf.mNumS*2;
+                        if (vf.mNumS < 0)
+                        {
+                            LL_ERRS() << "Volume face corruption detected." << LL_ENDL;
+                        }
+                    }
+                }
+                else
+                {
+                    vf.mTypeMask |= LLVolumeFace::OUTER_MASK;
+                }
+            }
+        }
 
-	return test_mask == face_mask;
+        for (face_list_t::iterator iter = mVolumeFaces.begin();
+             iter != mVolumeFaces.end(); ++iter)
+        {
+            (*iter).create(this, partial_build);
+        }
+    }
 }
 
-BOOL LLVolume::isConvex() const
+
+inline LLVector4a sculpt_rgb_to_vector(U8 r, U8 g, U8 b)
 {
-	// mParams.isConvex() may return FALSE even though the final
-	// geometry is actually convex due to LOD approximations.
-	// TODO -- provide LLPath and LLProfile with isConvex() methods
-	// that correctly determine convexity. -- Leviathan
-	return mParams.isConvex();
-}
+    // maps RGB values to vector values [0..255] -> [-0.5..0.5]
+    LLVector4a value;
+    LLVector4a sub(0.5f, 0.5f, 0.5f);
 
+    value.set(r,g,b);
+    value.mul(1.f/255.f);
+    value.sub(sub);
 
-std::ostream& operator<<(std::ostream &s, const LLProfileParams &profile_params)
-{
-	s << "{type=" << (U32) profile_params.mCurveType;
-	s << ", begin=" << profile_params.mBegin;
-	s << ", end=" << profile_params.mEnd;
-	s << ", hollow=" << profile_params.mHollow;
-	s << "}";
-	return s;
+    return value;
 }
 
-
-std::ostream& operator<<(std::ostream &s, const LLPathParams &path_params)
+inline U32 sculpt_xy_to_index(U32 x, U32 y, U16 sculpt_width, U16 sculpt_height, S8 sculpt_components)
 {
-	s << "{type=" << (U32) path_params.mCurveType;
-	s << ", begin=" << path_params.mBegin;
-	s << ", end=" << path_params.mEnd;
-	s << ", twist=" << path_params.mTwistEnd;
-	s << ", scale=" << path_params.mScale;
-	s << ", shear=" << path_params.mShear;
-	s << ", twist_begin=" << path_params.mTwistBegin;
-	s << ", radius_offset=" << path_params.mRadiusOffset;
-	s << ", taper=" << path_params.mTaper;
-	s << ", revolutions=" << path_params.mRevolutions;
-	s << ", skew=" << path_params.mSkew;
-	s << "}";
-	return s;
+    U32 index = (x + y * sculpt_width) * sculpt_components;
+    return index;
 }
 
 
-std::ostream& operator<<(std::ostream &s, const LLVolumeParams &volume_params)
+inline U32 sculpt_st_to_index(S32 s, S32 t, S32 size_s, S32 size_t, U16 sculpt_width, U16 sculpt_height, S8 sculpt_components)
 {
-	s << "{profileparams = " << volume_params.mProfileParams;
-	s << ", pathparams = " << volume_params.mPathParams;
-	s << "}";
-	return s;
+    U32 x = (U32) ((F32)s/(size_s) * (F32) sculpt_width);
+    U32 y = (U32) ((F32)t/(size_t) * (F32) sculpt_height);
+
+    return sculpt_xy_to_index(x, y, sculpt_width, sculpt_height, sculpt_components);
 }
 
 
-std::ostream& operator<<(std::ostream &s, const LLProfile &profile)
+inline LLVector4a sculpt_index_to_vector(U32 index, const U8* sculpt_data)
 {
-	s << " {open=" << (U32) profile.mOpen;
-	s << ", dirty=" << profile.mDirty;
-	s << ", totalout=" << profile.mTotalOut;
-	s << ", total=" << profile.mTotal;
-	s << "}";
-	return s;
-}
+    LLVector4a v = sculpt_rgb_to_vector(sculpt_data[index], sculpt_data[index+1], sculpt_data[index+2]);
 
+    return v;
+}
 
-std::ostream& operator<<(std::ostream &s, const LLPath &path)
+inline LLVector4a sculpt_st_to_vector(S32 s, S32 t, S32 size_s, S32 size_t, U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data)
 {
-	s << "{open=" << (U32) path.mOpen;
-	s << ", dirty=" << path.mDirty;
-	s << ", step=" << path.mStep;
-	s << ", total=" << path.mTotal;
-	s << "}";
-	return s;
+    U32 index = sculpt_st_to_index(s, t, size_s, size_t, sculpt_width, sculpt_height, sculpt_components);
+
+    return sculpt_index_to_vector(index, sculpt_data);
 }
 
-std::ostream& operator<<(std::ostream &s, const LLVolume &volume)
+inline LLVector4a sculpt_xy_to_vector(U32 x, U32 y, U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data)
 {
-	s << "{params = " << volume.getParams();
-	s << ", path = " << *volume.mPathp;
-	s << ", profile = " << *volume.mProfilep;
-	s << "}";
-	return s;
+    U32 index = sculpt_xy_to_index(x, y, sculpt_width, sculpt_height, sculpt_components);
+
+    return sculpt_index_to_vector(index, sculpt_data);
 }
 
 
-std::ostream& operator<<(std::ostream &s, const LLVolume *volumep)
-{
-	s << "{params = " << volumep->getParams();
-	s << ", path = " << *(volumep->mPathp);
-	s << ", profile = " << *(volumep->mProfilep);
-	s << "}";
-	return s;
-}
-
-LLVolumeFace::LLVolumeFace() : 
-	mID(0),
-	mTypeMask(0),
-	mBeginS(0),
-	mBeginT(0),
-	mNumS(0),
-	mNumT(0),
-	mNumVertices(0),
-	mNumAllocatedVertices(0),
-	mNumIndices(0),
-	mPositions(NULL),
-	mNormals(NULL),
-	mTangents(NULL),
-	mTexCoords(NULL),
-	mIndices(NULL),
-	mWeights(NULL),
-    mWeightsScrubbed(FALSE),
-	mOctree(NULL),
-    mOctreeTriangles(NULL),
-	mOptimized(FALSE)
+F32 LLVolume::sculptGetSurfaceArea()
 {
-	mExtents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*3);
-	mExtents[0].splat(-0.5f);
-	mExtents[1].splat(0.5f);
-	mCenter = mExtents+2;
-}
+    // test to see if image has enough variation to create non-degenerate geometry
 
-LLVolumeFace::LLVolumeFace(const LLVolumeFace& src)
-:	mID(0),
-	mTypeMask(0),
-	mBeginS(0),
-	mBeginT(0),
-	mNumS(0),
-	mNumT(0),
-	mNumVertices(0),
-	mNumAllocatedVertices(0),
-	mNumIndices(0),
-	mPositions(NULL),
-	mNormals(NULL),
-	mTangents(NULL),
-	mTexCoords(NULL),
-	mIndices(NULL),
-	mWeights(NULL),
-    mWeightsScrubbed(FALSE),
-    mOctree(NULL),
-    mOctreeTriangles(NULL),
-	mOptimized(FALSE)
-{
-	mExtents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*3);
-	mCenter = mExtents+2;
-	*this = src;
-}
+    F32 area = 0;
 
-LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src)
-{
-	if (&src == this)
-	{ //self assignment, do nothing
-		return *this;
-	}
-
-	mID = src.mID;
-	mTypeMask = src.mTypeMask;
-	mBeginS = src.mBeginS;
-	mBeginT = src.mBeginT;
-	mNumS = src.mNumS;
-	mNumT = src.mNumT;
-
-	mExtents[0] = src.mExtents[0];
-	mExtents[1] = src.mExtents[1];
-	*mCenter = *src.mCenter;
-
-	mNumVertices = 0;
-	mNumIndices = 0;
-
-	freeData();
-	
-	resizeVertices(src.mNumVertices);
-	resizeIndices(src.mNumIndices);
-
-	if (mNumVertices)
-	{
-		S32 vert_size = mNumVertices*sizeof(LLVector4a);
-		S32 tc_size = (mNumVertices*sizeof(LLVector2)+0xF) & ~0xF;
-			
-		LLVector4a::memcpyNonAliased16((F32*) mPositions, (F32*) src.mPositions, vert_size);
-
-		if (src.mNormals)
-		{
-		LLVector4a::memcpyNonAliased16((F32*) mNormals, (F32*) src.mNormals, vert_size);
-		}
-
-		if(src.mTexCoords)
-		{
-			LLVector4a::memcpyNonAliased16((F32*) mTexCoords, (F32*) src.mTexCoords, tc_size);
-		}
-
-		if (src.mTangents)
-		{
-			allocateTangents(src.mNumVertices);
-			LLVector4a::memcpyNonAliased16((F32*) mTangents, (F32*) src.mTangents, vert_size);
-		}
-		else
-		{
-			ll_aligned_free_16(mTangents);
-			mTangents = NULL;
-		}
-
-		if (src.mWeights)
-		{
-            llassert(!mWeights); // don't orphan an old alloc here accidentally
-			allocateWeights(src.mNumVertices);
-			LLVector4a::memcpyNonAliased16((F32*) mWeights, (F32*) src.mWeights, vert_size);            
-            mWeightsScrubbed = src.mWeightsScrubbed;
-		}
-		else
-		{
-			ll_aligned_free_16(mWeights);            
-			mWeights = NULL;            
-            mWeightsScrubbed = FALSE;
-		}   
+    S32 sizeS = mPathp->mPath.size();
+    S32 sizeT = mProfilep->mProfile.size();
 
-    #if USE_SEPARATE_JOINT_INDICES_AND_WEIGHTS
-        if (src.mJointIndices)
+    for (S32 s = 0; s < sizeS-1; s++)
+    {
+        for (S32 t = 0; t < sizeT-1; t++)
         {
-            llassert(!mJointIndices); // don't orphan an old alloc here accidentally
-            allocateJointIndices(src.mNumVertices);
-            LLVector4a::memcpyNonAliased16((F32*) mJointIndices, (F32*) src.mJointIndices, src.mNumVertices * sizeof(U8) * 4);
+            // get four corners of quad
+            LLVector4a& p1 = mMesh[(s  )*sizeT + (t  )];
+            LLVector4a& p2 = mMesh[(s+1)*sizeT + (t  )];
+            LLVector4a& p3 = mMesh[(s  )*sizeT + (t+1)];
+            LLVector4a& p4 = mMesh[(s+1)*sizeT + (t+1)];
+
+            // compute the area of the quad by taking the length of the cross product of the two triangles
+            LLVector4a v0,v1,v2,v3;
+            v0.setSub(p1,p2);
+            v1.setSub(p1,p3);
+            v2.setSub(p4,p2);
+            v3.setSub(p4,p3);
+
+            LLVector4a cross1, cross2;
+            cross1.setCross3(v0,v1);
+            cross2.setCross3(v2,v3);
+
+            //LLVector3 cross1 = (p1 - p2) % (p1 - p3);
+            //LLVector3 cross2 = (p4 - p2) % (p4 - p3);
+
+            area += (cross1.getLength3() + cross2.getLength3()).getF32() / 2.f;
         }
-        else*/
-        {
-            ll_aligned_free_16(mJointIndices);
-            mJointIndices = NULL;
-        }     
-    #endif
-
-	}
-    
-	if (mNumIndices)
-	{
-		S32 idx_size = (mNumIndices*sizeof(U16)+0xF) & ~0xF;
-		
-		LLVector4a::memcpyNonAliased16((F32*) mIndices, (F32*) src.mIndices, idx_size);
-	}
-	else
-    {
-        ll_aligned_free_16(mIndices);
-        mIndices = NULL;
     }
 
-	mOptimized = src.mOptimized;
-    mNormalizedScale = src.mNormalizedScale;
-
-	//delete 
-	return *this;
+    return area;
 }
 
-LLVolumeFace::~LLVolumeFace()
+// create empty placeholder shape
+void LLVolume::sculptGenerateEmptyPlaceholder()
 {
-	ll_aligned_free_16(mExtents);
-	mExtents = NULL;
-	mCenter = NULL;
-
-	freeData();
-}
+    S32 sizeS = mPathp->mPath.size();
+    S32 sizeT = mProfilep->mProfile.size();
 
-void LLVolumeFace::freeData()
-{
-	ll_aligned_free<64>(mPositions);
-	mPositions = NULL;
+    S32 line = 0;
 
-	//normals and texture coordinates are part of the same buffer as mPositions, do not free them separately
-	mNormals = NULL;
-	mTexCoords = NULL;
+    for (S32 s = 0; s < sizeS; s++)
+    {
+        for (S32 t = 0; t < sizeT; t++)
+        {
+            S32 i = t + line;
+            LLVector4a& pt = mMesh[i];
 
-	ll_aligned_free_16(mIndices);
-	mIndices = NULL;
-	ll_aligned_free_16(mTangents);
-	mTangents = NULL;
-	ll_aligned_free_16(mWeights);
-	mWeights = NULL;
+            F32* p = pt.getF32ptr();
 
-#if USE_SEPARATE_JOINT_INDICES_AND_WEIGHTS
-    ll_aligned_free_16(mJointIndices);
-	mJointIndices = NULL;
-    ll_aligned_free_16(mJustWeights);
-	mJustWeights = NULL;
-#endif
+            p[0] = 0;
+            p[1] = 0;
+            p[2] = 0;
 
-    destroyOctree();
+            llassert(pt.isFinite3());
+        }
+        line += sizeT;
+    }
 }
 
-BOOL LLVolumeFace::create(LLVolume* volume, BOOL partial_build)
+// create sphere placeholder shape
+void LLVolume::sculptGenerateSpherePlaceholder()
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
+    S32 sizeS = mPathp->mPath.size();
+    S32 sizeT = mProfilep->mProfile.size();
 
-	//tree for this face is no longer valid
-    destroyOctree();
+    S32 line = 0;
 
-	LL_CHECK_MEMORY
-	BOOL ret = FALSE ;
-	if (mTypeMask & CAP_MASK)
-	{
-		ret = createCap(volume, partial_build);
-		LL_CHECK_MEMORY
-	}
-	else if ((mTypeMask & END_MASK) || (mTypeMask & SIDE_MASK))
-	{
-		ret = createSide(volume, partial_build);
-		LL_CHECK_MEMORY
-	}
-	else
-	{
-		LL_ERRS() << "Unknown/uninitialized face type!" << LL_ENDL;
-	}
-
-	return ret ;
-}
+    for (S32 s = 0; s < sizeS; s++)
+    {
+        for (S32 t = 0; t < sizeT; t++)
+        {
+            S32 i = t + line;
+            LLVector4a& pt = mMesh[i];
 
-void LLVolumeFace::getVertexData(U16 index, LLVolumeFace::VertexData& cv)
-{
-	cv.setPosition(mPositions[index]);
-	if (mNormals)
-	{
-		cv.setNormal(mNormals[index]);
-	}
-	else
-	{
-		cv.getNormal().clear();
-	}
-
-	if (mTexCoords)
-	{
-		cv.mTexCoord = mTexCoords[index];
-	}
-	else
-	{
-		cv.mTexCoord.clear();
-	}
-}
 
-bool LLVolumeFace::VertexMapData::operator==(const LLVolumeFace::VertexData& rhs) const
-{
-	return getPosition().equals3(rhs.getPosition()) &&
-		mTexCoord == rhs.mTexCoord &&
-		getNormal().equals3(rhs.getNormal());
-}
+            F32 u = (F32)s / (sizeS - 1);
+            F32 v = (F32)t / (sizeT - 1);
 
-bool LLVolumeFace::VertexMapData::ComparePosition::operator()(const LLVector3& a, const LLVector3& b) const
-{
-	if (a.mV[0] != b.mV[0])
-	{
-		return a.mV[0] < b.mV[0];
-	}
-	
-	if (a.mV[1] != b.mV[1])
-	{
-		return a.mV[1] < b.mV[1];
-	}
-	
-	return a.mV[2] < b.mV[2];
+            const F32 RADIUS = (F32) 0.3;
+
+            F32* p = pt.getF32ptr();
+
+            p[0] = (F32)(sin(F_PI * v) * cos(2.0 * F_PI * u) * RADIUS);
+            p[1] = (F32)(sin(F_PI * v) * sin(2.0 * F_PI * u) * RADIUS);
+            p[2] = (F32)(cos(F_PI * v) * RADIUS);
+
+            llassert(pt.isFinite3());
+        }
+        line += sizeT;
+    }
 }
 
-void LLVolumeFace::remap()
+// create the vertices from the map
+void LLVolume::sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type)
 {
-    // Generate a remap buffer
-    std::vector<unsigned int> remap(mNumVertices);
-    S32 remap_vertices_count = LLMeshOptimizer::generateRemapMultiU16(&remap[0],
-        mIndices,
-        mNumIndices,
-        mPositions,
-        mNormals,
-        mTexCoords,
-        mNumVertices);
+    U8 sculpt_stitching = sculpt_type & LL_SCULPT_TYPE_MASK;
+    BOOL sculpt_invert = sculpt_type & LL_SCULPT_FLAG_INVERT;
+    BOOL sculpt_mirror = sculpt_type & LL_SCULPT_FLAG_MIRROR;
+    BOOL reverse_horizontal = (sculpt_invert ? !sculpt_mirror : sculpt_mirror);  // XOR
 
-    // Allocate new buffers
-    S32 size = ((mNumIndices * sizeof(U16)) + 0xF) & ~0xF;
-    U16* remap_indices = (U16*)ll_aligned_malloc_16(size);
+    S32 sizeS = mPathp->mPath.size();
+    S32 sizeT = mProfilep->mProfile.size();
 
-    S32 tc_bytes_size = ((remap_vertices_count * sizeof(LLVector2)) + 0xF) & ~0xF;
-    LLVector4a* remap_positions = (LLVector4a*)ll_aligned_malloc<64>(sizeof(LLVector4a) * 2 * remap_vertices_count + tc_bytes_size);
-    LLVector4a* remap_normals = remap_positions + remap_vertices_count;
-    LLVector2* remap_tex_coords = (LLVector2*)(remap_normals + remap_vertices_count);
+    S32 line = 0;
+    for (S32 s = 0; s < sizeS; s++)
+    {
+        // Run along the profile.
+        for (S32 t = 0; t < sizeT; t++)
+        {
+            S32 i = t + line;
+            LLVector4a& pt = mMesh[i];
 
-    // Fill the buffers
-    LLMeshOptimizer::remapIndexBufferU16(remap_indices, mIndices, mNumIndices, &remap[0]);
-    LLMeshOptimizer::remapPositionsBuffer(remap_positions, mPositions, mNumVertices, &remap[0]);
-    LLMeshOptimizer::remapNormalsBuffer(remap_normals, mNormals, mNumVertices, &remap[0]);
-    LLMeshOptimizer::remapUVBuffer(remap_tex_coords, mTexCoords, mNumVertices, &remap[0]);
+            S32 reversed_t = t;
 
-    // Free unused buffers
-    ll_aligned_free_16(mIndices);
-    ll_aligned_free<64>(mPositions);
+            if (reverse_horizontal)
+            {
+                reversed_t = sizeT - t - 1;
+            }
 
-    // Tangets are now invalid
-    ll_aligned_free_16(mTangents);
-    mTangents = NULL;
+            U32 x = (U32) ((F32)reversed_t/(sizeT-1) * (F32) sculpt_width);
+            U32 y = (U32) ((F32)s/(sizeS-1) * (F32) sculpt_height);
 
-    // Assign new values
-    mIndices = remap_indices;
-    mPositions = remap_positions;
-    mNormals = remap_normals;
-    mTexCoords = remap_tex_coords;
-    mNumVertices = remap_vertices_count;
-    mNumAllocatedVertices = remap_vertices_count;
-}
 
-void LLVolumeFace::optimize(F32 angle_cutoff)
-{
-	LLVolumeFace new_face;
+            if (y == 0)  // top row stitching
+            {
+                // pinch?
+                if (sculpt_stitching == LL_SCULPT_TYPE_SPHERE)
+                {
+                    x = sculpt_width / 2;
+                }
+            }
 
-	//map of points to vector of vertices at that point
-	std::map<U64, std::vector<VertexMapData> > point_map;
+            if (y == sculpt_height)  // bottom row stitching
+            {
+                // wrap?
+                if (sculpt_stitching == LL_SCULPT_TYPE_TORUS)
+                {
+                    y = 0;
+                }
+                else
+                {
+                    y = sculpt_height - 1;
+                }
 
-	LLVector4a range;
-	range.setSub(mExtents[1],mExtents[0]);
+                // pinch?
+                if (sculpt_stitching == LL_SCULPT_TYPE_SPHERE)
+                {
+                    x = sculpt_width / 2;
+                }
+            }
 
-	//remove redundant vertices
-	for (U32 i = 0; i < mNumIndices; ++i)
-	{
-		U16 index = mIndices[i];
+            if (x == sculpt_width)   // side stitching
+            {
+                // wrap?
+                if ((sculpt_stitching == LL_SCULPT_TYPE_SPHERE) ||
+                    (sculpt_stitching == LL_SCULPT_TYPE_TORUS) ||
+                    (sculpt_stitching == LL_SCULPT_TYPE_CYLINDER))
+                {
+                    x = 0;
+                }
 
-        if (index >= mNumVertices)
-        {
-            // invalid index
-            // replace with a valid index to avoid crashes
-            index = mNumVertices - 1;
-            mIndices[i] = index;
+                else
+                {
+                    x = sculpt_width - 1;
+                }
+            }
 
-            // Needs better logging
-            LL_DEBUGS_ONCE("LLVOLUME") << "Invalid index, substituting" << LL_ENDL;
-        }
+            pt = sculpt_xy_to_vector(x, y, sculpt_width, sculpt_height, sculpt_components, sculpt_data);
 
-		LLVolumeFace::VertexData cv;
-		getVertexData(index, cv);
-		
-		BOOL found = FALSE;
-
-		LLVector4a pos;
-		pos.setSub(mPositions[index], mExtents[0]);
-		pos.div(range);
-
-		U64 pos64 = 0;
-
-		pos64 = (U16) (pos[0]*65535);
-		pos64 = pos64 | (((U64) (pos[1]*65535)) << 16);
-		pos64 = pos64 | (((U64) (pos[2]*65535)) << 32);
-
-		std::map<U64, std::vector<VertexMapData> >::iterator point_iter = point_map.find(pos64);
-		
-		if (point_iter != point_map.end())
-		{ //duplicate point might exist
-			for (U32 j = 0; j < point_iter->second.size(); ++j)
-			{
-				LLVolumeFace::VertexData& tv = (point_iter->second)[j];
-				if (tv.compareNormal(cv, angle_cutoff))
-				{
-					found = TRUE;
-					new_face.pushIndex((point_iter->second)[j].mIndex);
-					break;
-				}
-			}
-		}
-
-		if (!found)
-		{
-			new_face.pushVertex(cv);
-			U16 index = (U16) new_face.mNumVertices-1;
-			new_face.pushIndex(index);
-
-			VertexMapData d;
-			d.setPosition(cv.getPosition());
-			d.mTexCoord = cv.mTexCoord;
-			d.setNormal(cv.getNormal());
-			d.mIndex = index;
-			if (point_iter != point_map.end())
-			{
-				point_iter->second.push_back(d);
-			}
-			else
-			{
-				point_map[pos64].push_back(d);
-			}
-		}
-	}
-
-
-	if (angle_cutoff > 1.f && !mNormals)
-	{
-		// Now alloc'd with positions
-		//ll_aligned_free_16(new_face.mNormals);
-		new_face.mNormals = NULL;
-	}
-
-	if (!mTexCoords)
-	{
-		// Now alloc'd with positions
-		//ll_aligned_free_16(new_face.mTexCoords);
-		new_face.mTexCoords = NULL;
-	}
-
-	// Only swap data if we've actually optimized the mesh
-	//
-	if (new_face.mNumVertices <= mNumVertices)
-	{
-        llassert(new_face.mNumIndices == mNumIndices);
-		swapData(new_face);
-	}
+            if (sculpt_mirror)
+            {
+                LLVector4a scale(-1.f,1,1,1);
+                pt.mul(scale);
+            }
+
+            llassert(pt.isFinite3());
+        }
 
+        line += sizeT;
+    }
 }
 
-class LLVCacheTriangleData;
 
-class LLVCacheVertexData
-{
-public:
-	S32 mIdx;
-	S32 mCacheTag;
-	F64 mScore;
-	U32 mActiveTriangles;
-	std::vector<LLVCacheTriangleData*> mTriangles;
-
-	LLVCacheVertexData()
-	{
-		mCacheTag = -1;
-		mScore = 0.0;
-		mActiveTriangles = 0;
-		mIdx = -1;
-	}
-};
+const S32 SCULPT_REZ_1 = 6;  // changed from 4 to 6 - 6 looks round whereas 4 looks square
+const S32 SCULPT_REZ_2 = 8;
+const S32 SCULPT_REZ_3 = 16;
+const S32 SCULPT_REZ_4 = 32;
 
-class LLVCacheTriangleData
+S32 sculpt_sides(F32 detail)
 {
-public:
-	bool mActive;
-	F64 mScore;
-	LLVCacheVertexData* mVertex[3];
-
-	LLVCacheTriangleData()
-	{
-		mActive = true;
-		mScore = 0.0;
-		mVertex[0] = mVertex[1] = mVertex[2] = NULL;
-	}
-
-	void complete()
-	{
-		mActive = false;
-		for (S32 i = 0; i < 3; ++i)
-		{
-			if (mVertex[i])
-			{
-				llassert(mVertex[i]->mActiveTriangles > 0);
-				mVertex[i]->mActiveTriangles--;
-			}
-		}
-	}
-
-	bool operator<(const LLVCacheTriangleData& rhs) const
-	{ //highest score first
-		return rhs.mScore < mScore;
-	}
-};
 
-const F64 FindVertexScore_CacheDecayPower = 1.5;
-const F64 FindVertexScore_LastTriScore = 0.75;
-const F64 FindVertexScore_ValenceBoostScale = 2.0;
-const F64 FindVertexScore_ValenceBoostPower = 0.5;
-const U32 MaxSizeVertexCache = 32;
-const F64 FindVertexScore_Scaler = 1.0/(MaxSizeVertexCache-3);
+    // detail is usually one of: 1, 1.5, 2.5, 4.0.
 
-F64 find_vertex_score(LLVCacheVertexData& data)
+    if (detail <= 1.0)
+    {
+        return SCULPT_REZ_1;
+    }
+    if (detail <= 2.0)
+    {
+        return SCULPT_REZ_2;
+    }
+    if (detail <= 3.0)
+    {
+        return SCULPT_REZ_3;
+    }
+    else
+    {
+        return SCULPT_REZ_4;
+    }
+}
+
+
+
+// determine the number of vertices in both s and t direction for this sculpt
+void sculpt_calc_mesh_resolution(U16 width, U16 height, U8 type, F32 detail, S32& s, S32& t)
 {
-	F64 score = -1.0;
+    // this code has the following properties:
+    // 1) the aspect ratio of the mesh is as close as possible to the ratio of the map
+    //    while still using all available verts
+    // 2) the mesh cannot have more verts than is allowed by LOD
+    // 3) the mesh cannot have more verts than is allowed by the map
 
-	score = 0.0;
+    S32 max_vertices_lod = (S32)pow((double)sculpt_sides(detail), 2.0);
+    S32 max_vertices_map = width * height / 4;
 
-	S32 cache_idx = data.mCacheTag;
+    S32 vertices;
+    if (max_vertices_map > 0)
+        vertices = llmin(max_vertices_lod, max_vertices_map);
+    else
+        vertices = max_vertices_lod;
 
-	if (cache_idx < 0)
-	{
-		//not in cache
-	}
-	else
-	{
-		if (cache_idx < 3)
-		{ //vertex was in the last triangle
-			score = FindVertexScore_LastTriScore;
-		}
-		else
-		{ //more points for being higher in the cache
-				score = 1.0-((cache_idx-3)*FindVertexScore_Scaler);
-				score = pow(score, FindVertexScore_CacheDecayPower);
-		}
-	}
 
-	//bonus points for having low valence
-	F64 valence_boost = pow((F64)data.mActiveTriangles, -FindVertexScore_ValenceBoostPower);
-	score += FindVertexScore_ValenceBoostScale * valence_boost;
+    F32 ratio;
+    if ((width == 0) || (height == 0))
+        ratio = 1.f;
+    else
+        ratio = (F32) width / (F32) height;
 
-	return score;
-}
 
-class LLVCacheFIFO
-{
-public:
-	LLVCacheVertexData* mCache[MaxSizeVertexCache];
-	U32 mMisses;
-
-	LLVCacheFIFO()
-	{
-		mMisses = 0;
-		for (U32 i = 0; i < MaxSizeVertexCache; ++i)
-		{
-			mCache[i] = NULL;
-		}
-	}
-
-	void addVertex(LLVCacheVertexData* data)
-	{
-		if (data->mCacheTag == -1)
-		{
-			mMisses++;
-
-			S32 end = MaxSizeVertexCache-1;
-
-			if (mCache[end])
-			{
-				mCache[end]->mCacheTag = -1;
-			}
-
-			for (S32 i = end; i > 0; --i)
-			{
-				mCache[i] = mCache[i-1];
-				if (mCache[i])
-				{
-					mCache[i]->mCacheTag = i;
-				}
-			}
-
-			mCache[0] = data;
-			data->mCacheTag = 0;
-		}
-	}
-};
+    s = (S32)(F32) sqrt(((F32)vertices / ratio));
 
-class LLVCacheLRU
-{
-public:
-	LLVCacheVertexData* mCache[MaxSizeVertexCache+3];
-
-	LLVCacheTriangleData* mBestTriangle;
-	
-	U32 mMisses;
-
-	LLVCacheLRU()
-	{
-		for (U32 i = 0; i < MaxSizeVertexCache+3; ++i)
-		{
-			mCache[i] = NULL;
-		}
-
-		mBestTriangle = NULL;
-		mMisses = 0;
-	}
-
-	void addVertex(LLVCacheVertexData* data)
-	{
-		S32 end = MaxSizeVertexCache+2;
-		if (data->mCacheTag != -1)
-		{ //just moving a vertex to the front of the cache
-			end = data->mCacheTag;
-		}
-		else
-		{
-			mMisses++;
-			if (mCache[end])
-			{ //adding a new vertex, vertex at end of cache falls off
-				mCache[end]->mCacheTag = -1;
-			}
-		}
-
-		for (S32 i = end; i > 0; --i)
-		{ //adjust cache pointers and tags
-			mCache[i] = mCache[i-1];
-
-			if (mCache[i])
-			{
-				mCache[i]->mCacheTag = i;			
-			}
-		}
-
-		mCache[0] = data;
-		mCache[0]->mCacheTag = 0;
-	}
-
-	void addTriangle(LLVCacheTriangleData* data)
-	{
-		addVertex(data->mVertex[0]);
-		addVertex(data->mVertex[1]);
-		addVertex(data->mVertex[2]);
-	}
-
-	void updateScores()
-	{
-		LLVCacheVertexData** data_iter = mCache+MaxSizeVertexCache;
-		LLVCacheVertexData** end_data = mCache+MaxSizeVertexCache+3;
-
-		while(data_iter != end_data)
-		{
-			LLVCacheVertexData* data = *data_iter++;
-			//trailing 3 vertices aren't actually in the cache for scoring purposes
-			if (data)
-			{
-				data->mCacheTag = -1;
-			}
-		}
-
-		data_iter = mCache;
-		end_data = mCache+MaxSizeVertexCache;
-
-		while (data_iter != end_data)
-		{ //update scores of vertices in cache
-			LLVCacheVertexData* data = *data_iter++;
-			if (data)
-			{
-				data->mScore = find_vertex_score(*data);
-			}
-		}
-
-		mBestTriangle = NULL;
-		//update triangle scores
-		data_iter = mCache;
-		end_data = mCache+MaxSizeVertexCache+3;
-
-		while (data_iter != end_data)
-		{
-			LLVCacheVertexData* data = *data_iter++;
-			if (data)
-			{
-				for (std::vector<LLVCacheTriangleData*>::iterator iter = data->mTriangles.begin(), end_iter = data->mTriangles.end(); iter != end_iter; ++iter)
-				{
-					LLVCacheTriangleData* tri = *iter;
-					if (tri->mActive)
-					{
-						tri->mScore = tri->mVertex[0] ? tri->mVertex[0]->mScore : 0;
-						tri->mScore += tri->mVertex[1] ? tri->mVertex[1]->mScore : 0;
-						tri->mScore += tri->mVertex[2] ? tri->mVertex[2]->mScore : 0;
-
-						if (!mBestTriangle || mBestTriangle->mScore < tri->mScore)
-						{
-							mBestTriangle = tri;
-						}
-					}
-				}
-			}
-		}
-
-		//knock trailing 3 vertices off the cache
-		data_iter = mCache+MaxSizeVertexCache;
-		end_data = mCache+MaxSizeVertexCache+3;
-		while (data_iter != end_data)
-		{
-			LLVCacheVertexData* data = *data_iter;
-			if (data)
-			{
-				llassert(data->mCacheTag == -1);
-				*data_iter = NULL;
-			}
-			++data_iter;
-		}
-	}
-};
+    s = llmax(s, 4);              // no degenerate sizes, please
+    t = vertices / s;
 
-// data structures for tangent generation
+    t = llmax(t, 4);              // no degenerate sizes, please
+    s = vertices / t;
+}
 
-struct MikktData
+// sculpt replaces generate() for sculpted surfaces
+void LLVolume::sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level, bool visible_placeholder)
 {
-    LLVolumeFace* face;
-    std::vector<LLVector3> p;
-    std::vector<LLVector3> n;
-    std::vector<LLVector2> tc;
-    std::vector<LLVector4> w;
-    std::vector<LLVector4> t;
+    U8 sculpt_type = mParams.getSculptType();
 
-    MikktData(LLVolumeFace* f)
-        : face(f)
+    BOOL data_is_empty = FALSE;
+
+    if (sculpt_width == 0 || sculpt_height == 0 || sculpt_components < 3 || sculpt_data == NULL)
     {
-        U32 count = face->mNumIndices;
+        sculpt_level = -1;
+        data_is_empty = TRUE;
+    }
 
-        p.resize(count);
-        n.resize(count);
-        tc.resize(count);
-        t.resize(count);
+    S32 requested_sizeS = 0;
+    S32 requested_sizeT = 0;
 
-        if (face->mWeights)
-        {
-            w.resize(count);
-        }
+    sculpt_calc_mesh_resolution(sculpt_width, sculpt_height, sculpt_type, mDetail, requested_sizeS, requested_sizeT);
 
+    mPathp->generate(mParams.getPathParams(), mDetail, 0, TRUE, requested_sizeS);
+    mProfilep->generate(mParams.getProfileParams(), mPathp->isOpen(), mDetail, 0, TRUE, requested_sizeT);
 
-        LLVector3 inv_scale(1.f / face->mNormalizedScale.mV[0], 1.f / face->mNormalizedScale.mV[1], 1.f / face->mNormalizedScale.mV[2]);
-        
+    S32 sizeS = mPathp->mPath.size();         // we requested a specific size, now see what we really got
+    S32 sizeT = mProfilep->mProfile.size();   // we requested a specific size, now see what we really got
 
-        for (int i = 0; i < face->mNumIndices; ++i)
-        {
-            U32 idx = face->mIndices[i];
+    // weird crash bug - DEV-11158 - trying to collect more data:
+    if ((sizeS == 0) || (sizeT == 0))
+    {
+        LL_WARNS() << "sculpt bad mesh size " << sizeS << " " << sizeT << LL_ENDL;
+    }
 
-            p[i].set(face->mPositions[idx].getF32ptr());
-            p[i].scaleVec(face->mNormalizedScale); //put mesh in original coordinate frame when reconstructing tangents
-            n[i].set(face->mNormals[idx].getF32ptr());
-            n[i].scaleVec(inv_scale);
-            n[i].normalize();
-            tc[i].set(face->mTexCoords[idx]);
+    sNumMeshPoints -= mMesh.size();
+    mMesh.resize(sizeS * sizeT);
+    sNumMeshPoints += mMesh.size();
 
-            if (idx >= face->mNumVertices)
-            {
-                // invalid index
-                // replace with a valid index to avoid crashes
-                idx = face->mNumVertices - 1;
-                face->mIndices[i] = idx;
+    //generate vertex positions
+    if (!data_is_empty)
+    {
+        sculptGenerateMapVertices(sculpt_width, sculpt_height, sculpt_components, sculpt_data, sculpt_type);
 
-                // Needs better logging
-                LL_DEBUGS_ONCE("LLVOLUME") << "Invalid index, substituting" << LL_ENDL;
-            }
+        // don't test lowest LOD to support legacy content DEV-33670
+        if (mDetail > SCULPT_MIN_AREA_DETAIL)
+        {
+            F32 area = sculptGetSurfaceArea();
 
-            if (face->mWeights)
+            mSurfaceArea = area;
+
+            const F32 SCULPT_MAX_AREA = 384.f;
+
+            if (area < SCULPT_MIN_AREA || area > SCULPT_MAX_AREA)
             {
-                w[i].set(face->mWeights[idx].getF32ptr());
+                data_is_empty = TRUE;
+                visible_placeholder = true;
             }
         }
     }
 
-	uint32_t GetNumFaces()
-	{
-		return uint32_t(face->mNumIndices / 3);
-	}
-
-	uint32_t GetNumVerticesOfFace(const uint32_t face_num)
-	{
-		return 3;
-	}
-
-	mikk::float3 GetPosition(const uint32_t face_num, const uint32_t vert_num)
-	{
-		F32* v = p[face_num * 3 + vert_num].mV;
-		return mikk::float3(v);
-	}
-
-	mikk::float3 GetTexCoord(const uint32_t face_num, const uint32_t vert_num)
-	{
-		F32* uv = tc[face_num * 3 + vert_num].mV;
-		return mikk::float3(uv[0], uv[1], 1.0f);
-	}
-
-	mikk::float3 GetNormal(const uint32_t face_num, const uint32_t vert_num)
-	{
-		F32* normal = n[face_num * 3 + vert_num].mV;
-		return mikk::float3(normal);
-	}
-
-	void SetTangentSpace(const uint32_t face_num, const uint32_t vert_num, mikk::float3 T, bool orientation)
-	{
-		S32 i = face_num * 3 + vert_num;
-		t[i].set(T.x, T.y, T.z, orientation ? 1.0f : -1.0f);
-	}
-};
-bool LLVolumeFace::cacheOptimize(bool gen_tangents)
-{ //optimize for vertex cache according to Forsyth method: 
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	llassert(!mOptimized);
-	mOptimized = TRUE;
+    if (data_is_empty)
+    {
+        if (visible_placeholder)
+        {
+            // Object should be visible since there will be nothing else to display
+            sculptGenerateSpherePlaceholder();
+        }
+        else
+        {
+            sculptGenerateEmptyPlaceholder();
+        }
+    }
 
-    if (gen_tangents && mNormals && mTexCoords)
-    { // generate mikkt space tangents before cache optimizing since the index buffer may change
-        // a bit of a hack to do this here, but this function gets called exactly once for the lifetime of a mesh
-        // and is executed on a background thread
-        MikktData data(this);
-		mikk::Mikktspace ctx(data);
-		ctx.genTangSpace();
 
-        //re-weld
-        meshopt_Stream mos[] =
-        {
-            { &data.p[0], sizeof(LLVector3), sizeof(LLVector3) },
-            { &data.n[0], sizeof(LLVector3), sizeof(LLVector3) },
-            { &data.t[0], sizeof(LLVector4), sizeof(LLVector4) },
-            { &data.tc[0], sizeof(LLVector2), sizeof(LLVector2) },
-            { data.w.empty() ? nullptr : &data.w[0], sizeof(LLVector4), sizeof(LLVector4) }
-        };
 
-        std::vector<U32> remap;
-        remap.resize(data.p.size());
+    for (S32 i = 0; i < (S32)mProfilep->mFaces.size(); i++)
+    {
+        mFaceMask |= mProfilep->mFaces[i].mFaceID;
+    }
 
-        U32 stream_count = data.w.empty() ? 4 : 5;
+    mSculptLevel = sculpt_level;
 
-        size_t vert_count = meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count);
+    // Delete any existing faces so that they get regenerated
+    mVolumeFaces.clear();
 
-        if (vert_count < 65535 && vert_count != 0)
-        {
-            //copy results back into volume
-            resizeVertices(vert_count);
+    createVolumeFaces();
+}
 
-            if (!data.w.empty())
-            {
-                allocateWeights(vert_count);
-            }
 
-            allocateTangents(mNumVertices);
 
-            for (int i = 0; i < mNumIndices; ++i)
-            {
-                U32 src_idx = i;
-                U32 dst_idx = remap[i];
-                if (dst_idx >= mNumVertices)
-                {
-                    dst_idx = mNumVertices - 1;
-                    // Shouldn't happen, figure out what gets returned in remap and why.
-                    llassert(false);
-                    LL_DEBUGS_ONCE("LLVOLUME") << "Invalid destination index, substituting" << LL_ENDL;
-                }
-                mIndices[i] = dst_idx;
 
-                mPositions[dst_idx].load3(data.p[src_idx].mV);
-                mNormals[dst_idx].load3(data.n[src_idx].mV);
-                mTexCoords[dst_idx] = data.tc[src_idx];
+BOOL LLVolume::isCap(S32 face)
+{
+    return mProfilep->mFaces[face].mCap;
+}
 
-                mTangents[dst_idx].loadua(data.t[src_idx].mV);
+BOOL LLVolume::isFlat(S32 face)
+{
+    return mProfilep->mFaces[face].mFlat;
+}
+
+
+bool LLVolumeParams::isSculpt() const
+{
+    return (mSculptType & LL_SCULPT_TYPE_MASK) != LL_SCULPT_TYPE_NONE;
+}
+
+bool LLVolumeParams::isMeshSculpt() const
+{
+    return (mSculptType & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH;
+}
+
+bool LLVolumeParams::operator==(const LLVolumeParams &params) const
+{
+    return ( (getPathParams() == params.getPathParams()) &&
+             (getProfileParams() == params.getProfileParams()) &&
+             (mSculptID == params.mSculptID) &&
+             (mSculptType == params.mSculptType) );
+}
+
+bool LLVolumeParams::operator!=(const LLVolumeParams &params) const
+{
+    return ( (getPathParams() != params.getPathParams()) ||
+             (getProfileParams() != params.getProfileParams()) ||
+             (mSculptID != params.mSculptID) ||
+             (mSculptType != params.mSculptType) );
+}
+
+bool LLVolumeParams::operator<(const LLVolumeParams &params) const
+{
+    if( getPathParams() != params.getPathParams() )
+    {
+        return getPathParams() < params.getPathParams();
+    }
+
+    if (getProfileParams() != params.getProfileParams())
+    {
+        return getProfileParams() < params.getProfileParams();
+    }
+
+    if (mSculptID != params.mSculptID)
+    {
+        return mSculptID < params.mSculptID;
+    }
+
+    return mSculptType < params.mSculptType;
+
+
+}
+
+void LLVolumeParams::copyParams(const LLVolumeParams &params)
+{
+    mProfileParams.copyParams(params.mProfileParams);
+    mPathParams.copyParams(params.mPathParams);
+    mSculptID = params.getSculptID();
+    mSculptType = params.getSculptType();
+}
+
+// Less restricitve approx 0 for volumes
+const F32 APPROXIMATELY_ZERO = 0.001f;
+bool approx_zero( F32 f, F32 tolerance = APPROXIMATELY_ZERO)
+{
+    return (f >= -tolerance) && (f <= tolerance);
+}
+
+// return true if in range (or nearly so)
+static bool limit_range(F32& v, F32 min, F32 max, F32 tolerance = APPROXIMATELY_ZERO)
+{
+    F32 min_delta = v - min;
+    if (min_delta < 0.f)
+    {
+        v = min;
+        if (!approx_zero(min_delta, tolerance))
+            return false;
+    }
+    F32 max_delta = max - v;
+    if (max_delta < 0.f)
+    {
+        v = max;
+        if (!approx_zero(max_delta, tolerance))
+            return false;
+    }
+    return true;
+}
+
+bool LLVolumeParams::setBeginAndEndS(const F32 b, const F32 e)
+{
+    bool valid = true;
+
+    // First, clamp to valid ranges.
+    F32 begin = b;
+    valid &= limit_range(begin, 0.f, 1.f - MIN_CUT_DELTA);
+
+    F32 end = e;
+    if (end >= .0149f && end < MIN_CUT_DELTA) end = MIN_CUT_DELTA; // eliminate warning for common rounding error
+    valid &= limit_range(end, MIN_CUT_DELTA, 1.f);
+
+    valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f);
+
+    // Now set them.
+    mProfileParams.setBegin(begin);
+    mProfileParams.setEnd(end);
+
+    return valid;
+}
+
+bool LLVolumeParams::setBeginAndEndT(const F32 b, const F32 e)
+{
+    bool valid = true;
+
+    // First, clamp to valid ranges.
+    F32 begin = b;
+    valid &= limit_range(begin, 0.f, 1.f - MIN_CUT_DELTA);
+
+    F32 end = e;
+    valid &= limit_range(end, MIN_CUT_DELTA, 1.f);
+
+    valid &= limit_range(begin, 0.f, end - MIN_CUT_DELTA, .01f);
+
+    // Now set them.
+    mPathParams.setBegin(begin);
+    mPathParams.setEnd(end);
+
+    return valid;
+}
+
+bool LLVolumeParams::setHollow(const F32 h)
+{
+    // Validate the hollow based on path and profile.
+    U8 profile  = mProfileParams.getCurveType() & LL_PCODE_PROFILE_MASK;
+    U8 hole_type    = mProfileParams.getCurveType() & LL_PCODE_HOLE_MASK;
+
+    F32 max_hollow = HOLLOW_MAX;
+
+    // Only square holes have trouble.
+    if (LL_PCODE_HOLE_SQUARE == hole_type)
+    {
+        switch(profile)
+        {
+        case LL_PCODE_PROFILE_CIRCLE:
+        case LL_PCODE_PROFILE_CIRCLE_HALF:
+        case LL_PCODE_PROFILE_EQUALTRI:
+            max_hollow = HOLLOW_MAX_SQUARE;
+        }
+    }
+
+    F32 hollow = h;
+    bool valid = limit_range(hollow, HOLLOW_MIN, max_hollow);
+    mProfileParams.setHollow(hollow);
+
+    return valid;
+}
+
+bool LLVolumeParams::setTwistBegin(const F32 b)
+{
+    F32 twist_begin = b;
+    bool valid = limit_range(twist_begin, TWIST_MIN, TWIST_MAX);
+    mPathParams.setTwistBegin(twist_begin);
+    return valid;
+}
+
+bool LLVolumeParams::setTwistEnd(const F32 e)
+{
+    F32 twist_end = e;
+    bool valid = limit_range(twist_end, TWIST_MIN, TWIST_MAX);
+    mPathParams.setTwistEnd(twist_end);
+    return valid;
+}
+
+bool LLVolumeParams::setRatio(const F32 x, const F32 y)
+{
+    F32 min_x = RATIO_MIN;
+    F32 max_x = RATIO_MAX;
+    F32 min_y = RATIO_MIN;
+    F32 max_y = RATIO_MAX;
+    // If this is a circular path (and not a sphere) then 'ratio' is actually hole size.
+    U8 path_type    = mPathParams.getCurveType();
+    U8 profile_type = mProfileParams.getCurveType() & LL_PCODE_PROFILE_MASK;
+    if ( LL_PCODE_PATH_CIRCLE == path_type &&
+         LL_PCODE_PROFILE_CIRCLE_HALF != profile_type)
+    {
+        // Holes are more restricted...
+        min_x = HOLE_X_MIN;
+        max_x = HOLE_X_MAX;
+        min_y = HOLE_Y_MIN;
+        max_y = HOLE_Y_MAX;
+    }
+
+    F32 ratio_x = x;
+    bool valid = limit_range(ratio_x, min_x, max_x);
+    F32 ratio_y = y;
+    valid &= limit_range(ratio_y, min_y, max_y);
+
+    mPathParams.setScale(ratio_x, ratio_y);
+
+    return valid;
+}
+
+bool LLVolumeParams::setShear(const F32 x, const F32 y)
+{
+    F32 shear_x = x;
+    bool valid = limit_range(shear_x, SHEAR_MIN, SHEAR_MAX);
+    F32 shear_y = y;
+    valid &= limit_range(shear_y, SHEAR_MIN, SHEAR_MAX);
+    mPathParams.setShear(shear_x, shear_y);
+    return valid;
+}
+
+bool LLVolumeParams::setTaperX(const F32 v)
+{
+    F32 taper = v;
+    bool valid = limit_range(taper, TAPER_MIN, TAPER_MAX);
+    mPathParams.setTaperX(taper);
+    return valid;
+}
+
+bool LLVolumeParams::setTaperY(const F32 v)
+{
+    F32 taper = v;
+    bool valid = limit_range(taper, TAPER_MIN, TAPER_MAX);
+    mPathParams.setTaperY(taper);
+    return valid;
+}
+
+bool LLVolumeParams::setRevolutions(const F32 r)
+{
+    F32 revolutions = r;
+    bool valid = limit_range(revolutions, REV_MIN, REV_MAX);
+    mPathParams.setRevolutions(revolutions);
+    return valid;
+}
+
+bool LLVolumeParams::setRadiusOffset(const F32 offset)
+{
+    bool valid = true;
+
+    // If this is a sphere, just set it to 0 and get out.
+    U8 path_type    = mPathParams.getCurveType();
+    U8 profile_type = mProfileParams.getCurveType() & LL_PCODE_PROFILE_MASK;
+    if ( LL_PCODE_PROFILE_CIRCLE_HALF == profile_type ||
+        LL_PCODE_PATH_CIRCLE != path_type )
+    {
+        mPathParams.setRadiusOffset(0.f);
+        return true;
+    }
+
+    // Limit radius offset, based on taper and hole size y.
+    F32 radius_offset   = offset;
+    F32 taper_y         = getTaperY();
+    F32 radius_mag      = fabs(radius_offset);
+    F32 hole_y_mag      = fabs(getRatioY());
+    F32 taper_y_mag     = fabs(taper_y);
+    // Check to see if the taper effects us.
+    if ( (radius_offset > 0.f && taper_y < 0.f) ||
+            (radius_offset < 0.f && taper_y > 0.f) )
+    {
+        // The taper does not help increase the radius offset range.
+        taper_y_mag = 0.f;
+    }
+    F32 max_radius_mag = 1.f - hole_y_mag * (1.f - taper_y_mag) / (1.f - hole_y_mag);
+
+    // Enforce the maximum magnitude.
+    F32 delta = max_radius_mag - radius_mag;
+    if (delta < 0.f)
+    {
+        // Check radius offset sign.
+        if (radius_offset < 0.f)
+        {
+            radius_offset = -max_radius_mag;
+        }
+        else
+        {
+            radius_offset = max_radius_mag;
+        }
+        valid = approx_zero(delta, .1f);
+    }
+
+    mPathParams.setRadiusOffset(radius_offset);
+    return valid;
+}
+
+bool LLVolumeParams::setSkew(const F32 skew_value)
+{
+    bool valid = true;
+
+    // Check the skew value against the revolutions.
+    F32 skew        = llclamp(skew_value, SKEW_MIN, SKEW_MAX);
+    F32 skew_mag    = fabs(skew);
+    F32 revolutions = getRevolutions();
+    F32 scale_x     = getRatioX();
+    F32 min_skew_mag = 1.0f - 1.0f / (revolutions * scale_x + 1.0f);
+    // Discontinuity; A revolution of 1 allows skews below 0.5.
+    if ( fabs(revolutions - 1.0f) < 0.001)
+        min_skew_mag = 0.0f;
+
+    // Clip skew.
+    F32 delta = skew_mag - min_skew_mag;
+    if (delta < 0.f)
+    {
+        // Check skew sign.
+        if (skew < 0.0f)
+        {
+            skew = -min_skew_mag;
+        }
+        else
+        {
+            skew = min_skew_mag;
+        }
+        valid = approx_zero(delta, .01f);
+    }
+
+    mPathParams.setSkew(skew);
+    return valid;
+}
+
+bool LLVolumeParams::setSculptID(LLUUID sculpt_id, U8 sculpt_type)
+{
+    mSculptID = std::move(sculpt_id);
+    mSculptType = sculpt_type;
+    return true;
+}
+
+bool LLVolumeParams::setType(U8 profile, U8 path)
+{
+    bool result = true;
+    // First, check profile and path for validity.
+    U8 profile_type = profile & LL_PCODE_PROFILE_MASK;
+    U8 hole_type    = (profile & LL_PCODE_HOLE_MASK) >> 4;
+    U8 path_type    = path >> 4;
+
+    if (profile_type > LL_PCODE_PROFILE_MAX)
+    {
+        // Bad profile.  Make it square.
+        profile = LL_PCODE_PROFILE_SQUARE;
+        result = false;
+        LL_WARNS() << "LLVolumeParams::setType changing bad profile type (" << profile_type
+                << ") to be LL_PCODE_PROFILE_SQUARE" << LL_ENDL;
+    }
+    else if (hole_type > LL_PCODE_HOLE_MAX)
+    {
+        // Bad hole.  Make it the same.
+        profile = profile_type;
+        result = false;
+        LL_WARNS() << "LLVolumeParams::setType changing bad hole type (" << hole_type
+                << ") to be LL_PCODE_HOLE_SAME" << LL_ENDL;
+    }
+
+    if (path_type < LL_PCODE_PATH_MIN ||
+        path_type > LL_PCODE_PATH_MAX)
+    {
+        // Bad path.  Make it linear.
+        result = false;
+        LL_WARNS() << "LLVolumeParams::setType changing bad path (" << path
+                << ") to be LL_PCODE_PATH_LINE" << LL_ENDL;
+        path = LL_PCODE_PATH_LINE;
+    }
+
+    mProfileParams.setCurveType(profile);
+    mPathParams.setCurveType(path);
+    return result;
+}
+
+// static
+bool LLVolumeParams::validate(U8 prof_curve, F32 prof_begin, F32 prof_end, F32 hollow,
+        U8 path_curve, F32 path_begin, F32 path_end,
+        F32 scx, F32 scy, F32 shx, F32 shy,
+        F32 twistend, F32 twistbegin, F32 radiusoffset,
+        F32 tx, F32 ty, F32 revolutions, F32 skew)
+{
+    LLVolumeParams test_params;
+    if (!test_params.setType        (prof_curve, path_curve))
+    {
+            return false;
+    }
+    if (!test_params.setBeginAndEndS    (prof_begin, prof_end))
+    {
+            return false;
+    }
+    if (!test_params.setBeginAndEndT    (path_begin, path_end))
+    {
+            return false;
+    }
+    if (!test_params.setHollow      (hollow))
+    {
+            return false;
+    }
+    if (!test_params.setTwistBegin      (twistbegin))
+    {
+            return false;
+    }
+    if (!test_params.setTwistEnd        (twistend))
+    {
+            return false;
+    }
+    if (!test_params.setRatio       (scx, scy))
+    {
+            return false;
+    }
+    if (!test_params.setShear       (shx, shy))
+    {
+            return false;
+    }
+    if (!test_params.setTaper       (tx, ty))
+    {
+            return false;
+    }
+    if (!test_params.setRevolutions     (revolutions))
+    {
+            return false;
+    }
+    if (!test_params.setRadiusOffset    (radiusoffset))
+    {
+            return false;
+    }
+    if (!test_params.setSkew        (skew))
+    {
+            return false;
+    }
+    return true;
+}
+
+void LLVolume::getLoDTriangleCounts(S32* counts)
+{ //attempt to approximate the number of triangles that will result from generating a volume LoD set for the
+    //supplied LLVolumeParams -- inaccurate, but a close enough approximation for determining streaming cost
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
+    const LLVolumeParams& params = getParams();
+    const LLPathParams& path_params = params.getPathParams();
+    const LLProfileParams& profile_params = params.getProfileParams();
+
+    // Check the cached data first
+    if (mTrianglesCache && mTrianglesCache->mPathParams == path_params && mTrianglesCache->mProfileParams == profile_params)
+    {
+        counts[ 0 ] = mTrianglesCache->mTriangles[0];
+        counts[ 1 ] = mTrianglesCache->mTriangles[1];
+        counts[ 2 ] = mTrianglesCache->mTriangles[2];
+        counts[ 3 ] = mTrianglesCache->mTriangles[3];
+        return;
+    }
+
+    if(!mTrianglesCache)
+        mTrianglesCache = std::make_unique<TrianglesPerLODCache>();
+
+    mTrianglesCache->mPathParams = params.getPathParams();
+    mTrianglesCache->mProfileParams = params.getProfileParams();
+
+    F32 detail[] = {1.f, 1.5f, 2.5f, 4.f};
+    for (S32 i = 0; i < 4; i++)
+    {
+        S32 count = 0;
+        S32 path_points = LLPath::getNumPoints(path_params, detail[i]);
+        S32 profile_points = LLProfile::getNumPoints(profile_params, false, detail[i]);
+
+        count = (profile_points-1)*2*(path_points-1);
+        count += profile_points*2;
+
+        counts[i] = count;
+        mTrianglesCache->mTriangles[i] = count;
+    }
+}
+
+
+S32 LLVolume::getNumTriangles(S32* vcount) const
+{
+    U32 triangle_count = 0;
+    U32 vertex_count = 0;
+
+    for (S32 i = 0, end = getNumVolumeFaces(); i < end; ++i)
+    {
+        const LLVolumeFace& face = getVolumeFace(i);
+        triangle_count += face.mNumIndices/3;
+
+        vertex_count += face.mNumVertices;
+    }
+
+
+    if (vcount)
+    {
+        *vcount = vertex_count;
+    }
+
+    return triangle_count;
+}
+
+
+//-----------------------------------------------------------------------------
+// generateSilhouetteVertices()
+//-----------------------------------------------------------------------------
+void LLVolume::generateSilhouetteVertices(std::vector<LLVector3> &vertices,
+                                          std::vector<LLVector3> &normals,
+                                          const LLVector3& obj_cam_vec_in,
+                                          const LLMatrix4a& mat,
+                                          const LLMatrix4a& norm_mat,
+                                          S32 face_mask)
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
+
+    LLVector4a obj_cam_vec;
+    obj_cam_vec.load3(obj_cam_vec_in.mV);
+
+    vertices.clear();
+    normals.clear();
+
+    if ((mParams.getSculptType() & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
+    {
+        return;
+    }
+
+    S32 cur_index = 0;
+    //for each face
+    for (face_list_t::iterator iter = mVolumeFaces.begin();
+         iter != mVolumeFaces.end(); ++iter)
+    {
+        LLVolumeFace& face = *iter;
+
+        if (!(face_mask & (0x1 << cur_index++)) ||
+             face.mNumIndices == 0 || face.mEdge.empty())
+        {
+            continue;
+        }
+
+        if (face.mTypeMask & (LLVolumeFace::CAP_MASK))
+        {
+            LLVector4a* v = (LLVector4a*)face.mPositions;
+            LLVector4a* n = (LLVector4a*)face.mNormals;
+
+            for (U32 j = 0; j < face.mNumIndices / 3; j++)
+            {
+                for (S32 k = 0; k < 3; k++)
+                {
+                    S32 index = face.mEdge[j * 3 + k];
+
+                    if (index == -1)
+                    {
+                        // silhouette edge, currently only cubes, so no other conditions
+
+                        S32 v1 = face.mIndices[j * 3 + k];
+                        S32 v2 = face.mIndices[j * 3 + ((k + 1) % 3)];
+
+                        LLVector4a t;
+                        mat.affineTransform(v[v1], t);
+                        vertices.emplace_back(t[0], t[1], t[2]);
+
+                        norm_mat.rotate(n[v1], t);
+
+                        t.normalize3fast();
+                        normals.emplace_back(t[0], t[1], t[2]);
+
+                        mat.affineTransform(v[v2], t);
+                        vertices.emplace_back(t[0], t[1], t[2]);
+
+                        norm_mat.rotate(n[v2], t);
+                        t.normalize3fast();
+                        normals.emplace_back(t[0], t[1], t[2]);
+                    }
+                }
+            }
+
+        }
+        else
+        {
+
+            //==============================================
+            //DEBUG draw edge map instead of silhouette edge
+            //==============================================
+
+#if DEBUG_SILHOUETTE_EDGE_MAP
+
+            //for each triangle
+            U32 tri_count = face.mNumIndices / 3;
+            for (U32 j = 0; j < tri_count; j++) {
+                //get vertices
+                S32 v1 = face.mIndices[j*3+0];
+                S32 v2 = face.mIndices[j*3+1];
+                S32 v3 = face.mIndices[j*3+2];
+
+                //get current face center
+                LLVector3 cCenter = (face.mVertices[v1].getPosition() +
+                                    face.mVertices[v2].getPosition() +
+                                    face.mVertices[v3].getPosition()) / 3.0f;
+
+                //for each edge
+                for (S32 k = 0; k < 3; k++) {
+                    S32 nIndex = face.mEdge[j*3+k];
+                    if (nIndex <= -1) {
+                        continue;
+                    }
+
+                    if (nIndex >= (S32)tri_count) {
+                        continue;
+                    }
+                    //get neighbor vertices
+                    v1 = face.mIndices[nIndex*3+0];
+                    v2 = face.mIndices[nIndex*3+1];
+                    v3 = face.mIndices[nIndex*3+2];
+
+                    //get neighbor face center
+                    LLVector3 nCenter = (face.mVertices[v1].getPosition() +
+                                    face.mVertices[v2].getPosition() +
+                                    face.mVertices[v3].getPosition()) / 3.0f;
+
+                    //draw line
+                    vertices.push_back(cCenter);
+                    vertices.push_back(nCenter);
+                    normals.push_back(LLVector3(1,1,1));
+                    normals.push_back(LLVector3(1,1,1));
+                    segments.push_back(vertices.size());
+                }
+            }
+
+            continue;
+
+            //==============================================
+            //DEBUG
+            //==============================================
+
+            //==============================================
+            //DEBUG draw normals instead of silhouette edge
+            //==============================================
+#elif DEBUG_SILHOUETTE_NORMALS
+
+            //for each vertex
+            for (U32 j = 0; j < face.mNumVertices; j++) {
+                vertices.push_back(face.mVertices[j].getPosition());
+                vertices.push_back(face.mVertices[j].getPosition() + face.mVertices[j].getNormal()*0.1f);
+                normals.push_back(LLVector3(0,0,1));
+                normals.push_back(LLVector3(0,0,1));
+                segments.push_back(vertices.size());
+#if DEBUG_SILHOUETTE_BINORMALS
+                vertices.push_back(face.mVertices[j].getPosition());
+                vertices.push_back(face.mVertices[j].getPosition() + face.mVertices[j].mTangent*0.1f);
+                normals.push_back(LLVector3(0,0,1));
+                normals.push_back(LLVector3(0,0,1));
+                segments.push_back(vertices.size());
+#endif
+            }
+
+            continue;
+#else
+            //==============================================
+            //DEBUG
+            //==============================================
+
+            static const U8 AWAY = 0x01,
+                            TOWARDS = 0x02;
+
+            //for each triangle
+            std::vector<U8> fFacing;
+            vector_append(fFacing, face.mNumIndices/3);
+
+            LLVector4a* v = (LLVector4a*) face.mPositions;
+            LLVector4a* n = (LLVector4a*) face.mNormals;
+
+            for (U32 j = 0; j < face.mNumIndices/3; j++)
+            {
+                //approximate normal
+                S32 v1 = face.mIndices[j*3+0];
+                S32 v2 = face.mIndices[j*3+1];
+                S32 v3 = face.mIndices[j*3+2];
+
+                LLVector4a c1,c2;
+                c1.setSub(v[v1], v[v2]);
+                c2.setSub(v[v2], v[v3]);
+
+                LLVector4a norm;
+
+                norm.setCross3(c1, c2);
+
+                if (norm.dot3(norm) < 0.00000001f)
+                {
+                    fFacing[j] = AWAY | TOWARDS;
+                }
+                else
+                {
+                    //get view vector
+                    LLVector4a view;
+                    view.setSub(obj_cam_vec, v[v1]);
+                    bool away = view.dot3(norm) > 0.0f;
+                    if (away)
+                    {
+                        fFacing[j] = AWAY;
+                    }
+                    else
+                    {
+                        fFacing[j] = TOWARDS;
+                    }
+                }
+            }
+
+            //for each triangle
+            for (U32 j = 0; j < face.mNumIndices/3; j++)
+            {
+                if (fFacing[j] == (AWAY | TOWARDS))
+                { //this is a degenerate triangle
+                    //take neighbor facing (degenerate faces get facing of one of their neighbors)
+                    // *FIX IF NEEDED:  this does not deal with neighboring degenerate faces
+                    for (S32 k = 0; k < 3; k++)
+                    {
+                        S32 index = face.mEdge[j*3+k];
+                        if (index != -1)
+                        {
+                            fFacing[j] = fFacing[index];
+                            break;
+                        }
+                    }
+                    continue; //skip degenerate face
+                }
+
+                //for each edge
+                for (S32 k = 0; k < 3; k++) {
+                    S32 index = face.mEdge[j*3+k];
+                    if (index != -1 && fFacing[index] == (AWAY | TOWARDS)) {
+                        //our neighbor is degenerate, make him face our direction
+                        fFacing[face.mEdge[j*3+k]] = fFacing[j];
+                        continue;
+                    }
+
+                    if (index == -1 ||      //edge has no neighbor, MUST be a silhouette edge
+                        (fFacing[index] & fFacing[j]) == 0) {   //we found a silhouette edge
+
+                        S32 v1 = face.mIndices[j*3+k];
+                        S32 v2 = face.mIndices[j*3+((k+1)%3)];
+
+                        LLVector4a t;
+                        mat.affineTransform(v[v1], t);
+                        vertices.emplace_back(t[0], t[1], t[2]);
+
+                        norm_mat.rotate(n[v1], t);
+
+                        t.normalize3fast();
+                        normals.emplace_back(t[0], t[1], t[2]);
+
+                        mat.affineTransform(v[v2], t);
+                        vertices.emplace_back(t[0], t[1], t[2]);
+
+                        norm_mat.rotate(n[v2], t);
+                        t.normalize3fast();
+                        normals.emplace_back(t[0], t[1], t[2]);
+                    }
+                }
+            }
+#endif
+        }
+    }
+}
+
+S32 LLVolume::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
+                                   S32 face_idx,
+                                   LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent_out)
+{
+    S32 hit_face = -1;
+
+    S32 start_face;
+    S32 end_face;
+
+    if (face_idx == -1)  // ALL_SIDES
+    {
+        start_face = 0;
+        end_face = getNumVolumeFaces() - 1;
+    }
+    else
+    {
+        start_face = face_idx;
+        end_face   = face_idx;
+    }
+
+    LLVector4a dir;
+    dir.setSub(end, start);
+
+    F32 closest_t = 2.f; // must be larger than 1
+
+    end_face = llmin(end_face, getNumVolumeFaces()-1);
+
+    for (S32 i = start_face; i <= end_face; i++)
+    {
+        LLVolumeFace &face = mVolumeFaces[i];
+
+        LLVector4a box_center;
+        box_center.setAdd(face.mExtents[0], face.mExtents[1]);
+        box_center.mul(0.5f);
+
+        LLVector4a box_size;
+        box_size.setSub(face.mExtents[1], face.mExtents[0]);
+
+        if (LLLineSegmentBoxIntersect(start, end, box_center, box_size))
+        {
+            if (tangent_out != NULL) // if the caller wants tangents, we may need to generate them
+            {
+                genTangents(i);
+            }
+
+            if (isUnique())
+            { //don't bother with an octree for flexi volumes
+                U32 tri_count = face.mNumIndices/3;
+
+                for (U32 j = 0; j < tri_count; ++j)
+                {
+                    U16 idx0 = face.mIndices[j*3+0];
+                    U16 idx1 = face.mIndices[j*3+1];
+                    U16 idx2 = face.mIndices[j*3+2];
+
+                    const LLVector4a& v0 = face.mPositions[idx0];
+                    const LLVector4a& v1 = face.mPositions[idx1];
+                    const LLVector4a& v2 = face.mPositions[idx2];
+
+                    F32 a,b,t;
+
+                    if (LLTriangleRayIntersect(v0, v1, v2,
+                            start, dir, a, b, t))
+                    {
+                        if ((t >= 0.f) &&      // if hit is after start
+                            (t <= 1.f) &&      // and before end
+                            (t < closest_t))   // and this hit is closer
+                        {
+                            closest_t = t;
+                            hit_face = i;
+
+                            if (intersection != NULL)
+                            {
+                                LLVector4a intersect = dir;
+                                intersect.mul(closest_t);
+                                intersect.add(start);
+                                *intersection = intersect;
+                            }
+
+
+                            if (tex_coord != NULL)
+                            {
+                                LLVector2* tc = (LLVector2*) face.mTexCoords;
+                                *tex_coord = ((1.f - a - b)  * tc[idx0] +
+                                    a              * tc[idx1] +
+                                    b              * tc[idx2]);
+
+                            }
+
+                            if (normal!= NULL)
+                            {
+                                LLVector4a* norm = face.mNormals;
+
+                                LLVector4a n1,n2,n3;
+                                n1 = norm[idx0];
+                                n1.mul(1.f-a-b);
+
+                                n2 = norm[idx1];
+                                n2.mul(a);
+
+                                n3 = norm[idx2];
+                                n3.mul(b);
+
+                                n1.add(n2);
+                                n1.add(n3);
+
+                                *normal     = n1;
+                            }
+
+                            if (tangent_out != NULL)
+                            {
+                                LLVector4a* tangents = face.mTangents;
+
+                                LLVector4a t1,t2,t3;
+                                t1 = tangents[idx0];
+                                t1.mul(1.f-a-b);
+
+                                t2 = tangents[idx1];
+                                t2.mul(a);
+
+                                t3 = tangents[idx2];
+                                t3.mul(b);
+
+                                t1.add(t2);
+                                t1.add(t3);
+
+                                *tangent_out = t1;
+                            }
+                        }
+                    }
+                }
+            }
+            else
+            {
+                if (!face.getOctree())
+                {
+                    face.createOctree();
+                }
+
+                LLOctreeTriangleRayIntersect intersect(start, dir, &face, &closest_t, intersection, tex_coord, normal, tangent_out);
+                intersect.traverse(face.getOctree());
+                if (intersect.mHitFace)
+                {
+                    hit_face = i;
+                }
+            }
+        }
+    }
+
+
+    return hit_face;
+}
+
+class LLVertexIndexPair
+{
+public:
+    LLVertexIndexPair(const LLVector3 &vertex, const S32 index);
+
+    LLVector3 mVertex;
+    S32 mIndex;
+};
+
+LLVertexIndexPair::LLVertexIndexPair(const LLVector3 &vertex, const S32 index)
+    : mVertex(vertex), mIndex(index)
+{ }
+
+const F32 VERTEX_SLOP = 0.00001f;
+
+struct lessVertex
+{
+    bool operator()(const LLVertexIndexPair *a, const LLVertexIndexPair *b)
+    {
+        const F32 slop = VERTEX_SLOP;
+
+        if (a->mVertex.mV[0] + slop < b->mVertex.mV[0])
+        {
+            return TRUE;
+        }
+        else if (a->mVertex.mV[0] - slop > b->mVertex.mV[0])
+        {
+            return FALSE;
+        }
+
+        if (a->mVertex.mV[1] + slop < b->mVertex.mV[1])
+        {
+            return TRUE;
+        }
+        else if (a->mVertex.mV[1] - slop > b->mVertex.mV[1])
+        {
+            return FALSE;
+        }
+
+        if (a->mVertex.mV[2] + slop < b->mVertex.mV[2])
+        {
+            return TRUE;
+        }
+        else if (a->mVertex.mV[2] - slop > b->mVertex.mV[2])
+        {
+            return FALSE;
+        }
+
+        return FALSE;
+    }
+};
+
+struct lessTriangle
+{
+    bool operator()(const S32 *a, const S32 *b)
+    {
+        if (*a < *b)
+        {
+            return TRUE;
+        }
+        else if (*a > *b)
+        {
+            return FALSE;
+        }
+
+        if (*(a+1) < *(b+1))
+        {
+            return TRUE;
+        }
+        else if (*(a+1) > *(b+1))
+        {
+            return FALSE;
+        }
+
+        if (*(a+2) < *(b+2))
+        {
+            return TRUE;
+        }
+        else if (*(a+2) > *(b+2))
+        {
+            return FALSE;
+        }
+
+        return FALSE;
+    }
+};
+
+BOOL equalTriangle(const S32 *a, const S32 *b)
+{
+    if ((*a == *b) && (*(a+1) == *(b+1)) && (*(a+2) == *(b+2)))
+    {
+        return TRUE;
+    }
+    return FALSE;
+}
+
+BOOL LLVolumeParams::importFile(LLFILE *fp)
+{
+    //LL_INFOS() << "importing volume" << LL_ENDL;
+    const S32 BUFSIZE = 16384;
+    char buffer[BUFSIZE];   /* Flawfinder: ignore */
+    // *NOTE: changing the size or type of this buffer will require
+    // changing the sscanf below.
+    char keyword[256];  /* Flawfinder: ignore */
+    keyword[0] = 0;
+
+    while (!feof(fp))
+    {
+        if (fgets(buffer, BUFSIZE, fp) == NULL)
+        {
+            buffer[0] = '\0';
+        }
+
+        sscanf(buffer, " %255s", keyword);  /* Flawfinder: ignore */
+        if (!strcmp("{", keyword))
+        {
+            continue;
+        }
+        if (!strcmp("}",keyword))
+        {
+            break;
+        }
+        else if (!strcmp("profile", keyword))
+        {
+            mProfileParams.importFile(fp);
+        }
+        else if (!strcmp("path",keyword))
+        {
+            mPathParams.importFile(fp);
+        }
+        else
+        {
+            LL_WARNS() << "unknown keyword " << keyword << " in volume import" << LL_ENDL;
+        }
+    }
+
+    return TRUE;
+}
+
+BOOL LLVolumeParams::exportFile(LLFILE *fp) const
+{
+    fprintf(fp,"\tshape 0\n");
+    fprintf(fp,"\t{\n");
+    mPathParams.exportFile(fp);
+    mProfileParams.exportFile(fp);
+    fprintf(fp, "\t}\n");
+    return TRUE;
+}
+
+
+BOOL LLVolumeParams::importLegacyStream(std::istream& input_stream)
+{
+    //LL_INFOS() << "importing volume" << LL_ENDL;
+    const S32 BUFSIZE = 16384;
+    // *NOTE: changing the size or type of this buffer will require
+    // changing the sscanf below.
+    char buffer[BUFSIZE];       /* Flawfinder: ignore */
+    char keyword[256];      /* Flawfinder: ignore */
+    keyword[0] = 0;
+
+    while (input_stream.good())
+    {
+        input_stream.getline(buffer, BUFSIZE);
+        sscanf(buffer, " %255s", keyword);
+        if (!strcmp("{", keyword))
+        {
+            continue;
+        }
+        if (!strcmp("}",keyword))
+        {
+            break;
+        }
+        else if (!strcmp("profile", keyword))
+        {
+            mProfileParams.importLegacyStream(input_stream);
+        }
+        else if (!strcmp("path",keyword))
+        {
+            mPathParams.importLegacyStream(input_stream);
+        }
+        else
+        {
+            LL_WARNS() << "unknown keyword " << keyword << " in volume import" << LL_ENDL;
+        }
+    }
+
+    return TRUE;
+}
+
+BOOL LLVolumeParams::exportLegacyStream(std::ostream& output_stream) const
+{
+    output_stream <<"\tshape 0\n";
+    output_stream <<"\t{\n";
+    mPathParams.exportLegacyStream(output_stream);
+    mProfileParams.exportLegacyStream(output_stream);
+    output_stream << "\t}\n";
+    return TRUE;
+}
+
+LLSD LLVolumeParams::sculptAsLLSD() const
+{
+    LLSD sd = LLSD();
+    sd["id"] = getSculptID();
+    sd["type"] = getSculptType();
+
+    return sd;
+}
+
+bool LLVolumeParams::sculptFromLLSD(LLSD& sd)
+{
+    setSculptID(sd["id"].asUUID(), (U8)sd["type"].asInteger());
+    return true;
+}
+
+LLSD LLVolumeParams::asLLSD() const
+{
+    LLSD sd = LLSD();
+    sd["path"] = mPathParams;
+    sd["profile"] = mProfileParams;
+    sd["sculpt"] = sculptAsLLSD();
+
+    return sd;
+}
+
+bool LLVolumeParams::fromLLSD(LLSD& sd)
+{
+    mPathParams.fromLLSD(sd["path"]);
+    mProfileParams.fromLLSD(sd["profile"]);
+    sculptFromLLSD(sd["sculpt"]);
+
+    return true;
+}
+
+void LLVolumeParams::reduceS(F32 begin, F32 end)
+{
+    begin = llclampf(begin);
+    end = llclampf(end);
+    if (begin > end)
+    {
+        F32 temp = begin;
+        begin = end;
+        end = temp;
+    }
+    F32 a = mProfileParams.getBegin();
+    F32 b = mProfileParams.getEnd();
+    mProfileParams.setBegin(a + begin * (b - a));
+    mProfileParams.setEnd(a + end * (b - a));
+}
+
+void LLVolumeParams::reduceT(F32 begin, F32 end)
+{
+    begin = llclampf(begin);
+    end = llclampf(end);
+    if (begin > end)
+    {
+        F32 temp = begin;
+        begin = end;
+        end = temp;
+    }
+    F32 a = mPathParams.getBegin();
+    F32 b = mPathParams.getEnd();
+    mPathParams.setBegin(a + begin * (b - a));
+    mPathParams.setEnd(a + end * (b - a));
+}
+
+const F32 MIN_CONCAVE_PROFILE_WEDGE = 0.125f;   // 1/8 unity
+const F32 MIN_CONCAVE_PATH_WEDGE = 0.111111f;   // 1/9 unity
+
+// returns TRUE if the shape can be approximated with a convex shape
+// for collison purposes
+BOOL LLVolumeParams::isConvex() const
+{
+    if (!getSculptID().isNull())
+    {
+        // can't determine, be safe and say no:
+        return FALSE;
+    }
+
+    F32 path_length = mPathParams.getEnd() - mPathParams.getBegin();
+    F32 hollow = mProfileParams.getHollow();
+
+    U8 path_type = mPathParams.getCurveType();
+    if ( path_length > MIN_CONCAVE_PATH_WEDGE
+        && ( mPathParams.getTwist() != mPathParams.getTwistBegin()
+             || (hollow > 0.f
+                 && LL_PCODE_PATH_LINE != path_type) ) )
+    {
+        // twist along a "not too short" path is concave
+        return FALSE;
+    }
+
+    F32 profile_length = mProfileParams.getEnd() - mProfileParams.getBegin();
+    BOOL same_hole = hollow == 0.f
+                     || (mProfileParams.getCurveType() & LL_PCODE_HOLE_MASK) == LL_PCODE_HOLE_SAME;
+
+    F32 min_profile_wedge = MIN_CONCAVE_PROFILE_WEDGE;
+    U8 profile_type = mProfileParams.getCurveType() & LL_PCODE_PROFILE_MASK;
+    if ( LL_PCODE_PROFILE_CIRCLE_HALF == profile_type )
+    {
+        // it is a sphere and spheres get twice the minimum profile wedge
+        min_profile_wedge = 2.f * MIN_CONCAVE_PROFILE_WEDGE;
+    }
+
+    BOOL convex_profile = ( ( profile_length == 1.f
+                             || profile_length <= 0.5f )
+                           && hollow == 0.f )                       // trivially convex
+                          || ( profile_length <= min_profile_wedge
+                              && same_hole );                       // effectvely convex (even when hollow)
+
+    if (!convex_profile)
+    {
+        // profile is concave
+        return FALSE;
+    }
+
+    if ( LL_PCODE_PATH_LINE == path_type )
+    {
+        // straight paths with convex profile
+        return TRUE;
+    }
+
+    BOOL concave_path = (path_length < 1.0f) && (path_length > 0.5f);
+    if (concave_path)
+    {
+        return FALSE;
+    }
+
+    // we're left with spheres, toroids and tubes
+    if ( LL_PCODE_PROFILE_CIRCLE_HALF == profile_type )
+    {
+        // at this stage all spheres must be convex
+        return TRUE;
+    }
+
+    // it's a toroid or tube
+    if ( path_length <= MIN_CONCAVE_PATH_WEDGE )
+    {
+        // effectively convex
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
+// debug
+void LLVolumeParams::setCube()
+{
+    mProfileParams.setCurveType(LL_PCODE_PROFILE_SQUARE);
+    mProfileParams.setBegin(0.f);
+    mProfileParams.setEnd(1.f);
+    mProfileParams.setHollow(0.f);
+
+    mPathParams.setBegin(0.f);
+    mPathParams.setEnd(1.f);
+    mPathParams.setScale(1.f, 1.f);
+    mPathParams.setShear(0.f, 0.f);
+    mPathParams.setCurveType(LL_PCODE_PATH_LINE);
+    mPathParams.setTwistBegin(0.f);
+    mPathParams.setTwistEnd(0.f);
+    mPathParams.setRadiusOffset(0.f);
+    mPathParams.setTaper(0.f, 0.f);
+    mPathParams.setRevolutions(0.f);
+    mPathParams.setSkew(0.f);
+}
+
+LLFaceID LLVolume::generateFaceMask()
+{
+    LLFaceID new_mask = 0x0000;
+
+    switch(mParams.getProfileParams().getCurveType() & LL_PCODE_PROFILE_MASK)
+    {
+    case LL_PCODE_PROFILE_CIRCLE:
+    case LL_PCODE_PROFILE_CIRCLE_HALF:
+        new_mask |= LL_FACE_OUTER_SIDE_0;
+        break;
+    case LL_PCODE_PROFILE_SQUARE:
+        {
+            for(S32 side = (S32)(mParams.getProfileParams().getBegin() * 4.f); side < llceil(mParams.getProfileParams().getEnd() * 4.f); side++)
+            {
+                new_mask |= LL_FACE_OUTER_SIDE_0 << side;
+            }
+        }
+        break;
+    case LL_PCODE_PROFILE_ISOTRI:
+    case LL_PCODE_PROFILE_EQUALTRI:
+    case LL_PCODE_PROFILE_RIGHTTRI:
+        {
+            for(S32 side = (S32)(mParams.getProfileParams().getBegin() * 3.f); side < llceil(mParams.getProfileParams().getEnd() * 3.f); side++)
+            {
+                new_mask |= LL_FACE_OUTER_SIDE_0 << side;
+            }
+        }
+        break;
+    default:
+        LL_ERRS() << "Unknown profile!" << LL_ENDL;
+        break;
+    }
+
+    // handle hollow objects
+    if (mParams.getProfileParams().getHollow() > 0)
+    {
+        new_mask |= LL_FACE_INNER_SIDE;
+    }
+
+    // handle open profile curves
+    if (mProfilep->isOpen())
+    {
+        new_mask |= LL_FACE_PROFILE_BEGIN | LL_FACE_PROFILE_END;
+    }
+
+    // handle open path curves
+    if (mPathp->isOpen())
+    {
+        new_mask |= LL_FACE_PATH_BEGIN | LL_FACE_PATH_END;
+    }
+
+    return new_mask;
+}
+
+BOOL LLVolume::isFaceMaskValid(LLFaceID face_mask)
+{
+    LLFaceID test_mask = 0;
+    for(S32 i = 0, i_end = getNumFaces(); i < i_end; i++)
+    {
+        test_mask |= mProfilep->mFaces[i].mFaceID;
+    }
+
+    return test_mask == face_mask;
+}
+
+BOOL LLVolume::isConvex() const
+{
+    // mParams.isConvex() may return FALSE even though the final
+    // geometry is actually convex due to LOD approximations.
+    // TODO -- provide LLPath and LLProfile with isConvex() methods
+    // that correctly determine convexity. -- Leviathan
+    return mParams.isConvex();
+}
+
+
+std::ostream& operator<<(std::ostream &s, const LLProfileParams &profile_params)
+{
+    s << "{type=" << (U32) profile_params.mCurveType;
+    s << ", begin=" << profile_params.mBegin;
+    s << ", end=" << profile_params.mEnd;
+    s << ", hollow=" << profile_params.mHollow;
+    s << "}";
+    return s;
+}
+
+
+std::ostream& operator<<(std::ostream &s, const LLPathParams &path_params)
+{
+    s << "{type=" << (U32) path_params.mCurveType;
+    s << ", begin=" << path_params.mBegin;
+    s << ", end=" << path_params.mEnd;
+    s << ", twist=" << path_params.mTwistEnd;
+    s << ", scale=" << path_params.mScale;
+    s << ", shear=" << path_params.mShear;
+    s << ", twist_begin=" << path_params.mTwistBegin;
+    s << ", radius_offset=" << path_params.mRadiusOffset;
+    s << ", taper=" << path_params.mTaper;
+    s << ", revolutions=" << path_params.mRevolutions;
+    s << ", skew=" << path_params.mSkew;
+    s << "}";
+    return s;
+}
+
+
+std::ostream& operator<<(std::ostream &s, const LLVolumeParams &volume_params)
+{
+    s << "{profileparams = " << volume_params.mProfileParams;
+    s << ", pathparams = " << volume_params.mPathParams;
+    s << "}";
+    return s;
+}
+
+
+std::ostream& operator<<(std::ostream &s, const LLProfile &profile)
+{
+    s << " {open=" << (U32) profile.mOpen;
+    s << ", dirty=" << profile.mDirty;
+    s << ", totalout=" << profile.mTotalOut;
+    s << ", total=" << profile.mTotal;
+    s << "}";
+    return s;
+}
+
+
+std::ostream& operator<<(std::ostream &s, const LLPath &path)
+{
+    s << "{open=" << (U32) path.mOpen;
+    s << ", dirty=" << path.mDirty;
+    s << ", step=" << path.mStep;
+    s << ", total=" << path.mTotal;
+    s << "}";
+    return s;
+}
+
+std::ostream& operator<<(std::ostream &s, const LLVolume &volume)
+{
+    s << "{params = " << volume.getParams();
+    s << ", path = " << *volume.mPathp;
+    s << ", profile = " << *volume.mProfilep;
+    s << "}";
+    return s;
+}
+
+
+std::ostream& operator<<(std::ostream &s, const LLVolume *volumep)
+{
+    s << "{params = " << volumep->getParams();
+    s << ", path = " << *(volumep->mPathp);
+    s << ", profile = " << *(volumep->mProfilep);
+    s << "}";
+    return s;
+}
+
+LLVolumeFace::LLVolumeFace() :
+    mID(0),
+    mTypeMask(0),
+    mBeginS(0),
+    mBeginT(0),
+    mNumS(0),
+    mNumT(0),
+    mNumVertices(0),
+    mNumAllocatedVertices(0),
+    mNumIndices(0),
+    mPositions(NULL),
+    mNormals(NULL),
+    mTangents(NULL),
+    mTexCoords(NULL),
+    mIndices(NULL),
+    mWeights(NULL),
+    mWeightsScrubbed(FALSE),
+    mOctree(NULL),
+    mOctreeTriangles(NULL),
+    mOptimized(FALSE)
+{
+    mExtents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*3);
+    mExtents[0].splat(-0.5f);
+    mExtents[1].splat(0.5f);
+    mCenter = mExtents+2;
+}
+
+LLVolumeFace::LLVolumeFace(const LLVolumeFace& src)
+:   mID(0),
+    mTypeMask(0),
+    mBeginS(0),
+    mBeginT(0),
+    mNumS(0),
+    mNumT(0),
+    mNumVertices(0),
+    mNumAllocatedVertices(0),
+    mNumIndices(0),
+    mPositions(NULL),
+    mNormals(NULL),
+    mTangents(NULL),
+    mTexCoords(NULL),
+    mIndices(NULL),
+    mWeights(NULL),
+    mWeightsScrubbed(FALSE),
+    mOctree(NULL),
+    mOctreeTriangles(NULL),
+    mOptimized(FALSE)
+{
+    mExtents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*3);
+    mCenter = mExtents+2;
+    *this = src;
+}
+
+LLVolumeFace& LLVolumeFace::operator=(const LLVolumeFace& src)
+{
+    if (&src == this)
+    { //self assignment, do nothing
+        return *this;
+    }
+
+    mID = src.mID;
+    mTypeMask = src.mTypeMask;
+    mBeginS = src.mBeginS;
+    mBeginT = src.mBeginT;
+    mNumS = src.mNumS;
+    mNumT = src.mNumT;
+
+    mExtents[0] = src.mExtents[0];
+    mExtents[1] = src.mExtents[1];
+    *mCenter = *src.mCenter;
+
+    mNumVertices = 0;
+    mNumIndices = 0;
+
+    freeData();
+
+    resizeVertices(src.mNumVertices);
+    resizeIndices(src.mNumIndices);
+
+    if (mNumVertices)
+    {
+        S32 vert_size = mNumVertices*sizeof(LLVector4a);
+        S32 tc_size = (mNumVertices*sizeof(LLVector2)+0xF) & ~0xF;
+
+        LLVector4a::memcpyNonAliased16((F32*) mPositions, (F32*) src.mPositions, vert_size);
+
+        if (src.mNormals)
+        {
+        LLVector4a::memcpyNonAliased16((F32*) mNormals, (F32*) src.mNormals, vert_size);
+        }
+
+        if(src.mTexCoords)
+        {
+            LLVector4a::memcpyNonAliased16((F32*) mTexCoords, (F32*) src.mTexCoords, tc_size);
+        }
+
+        if (src.mTangents)
+        {
+            allocateTangents(src.mNumVertices);
+            LLVector4a::memcpyNonAliased16((F32*) mTangents, (F32*) src.mTangents, vert_size);
+        }
+        else
+        {
+            ll_aligned_free_16(mTangents);
+            mTangents = NULL;
+        }
+
+        if (src.mWeights)
+        {
+            llassert(!mWeights); // don't orphan an old alloc here accidentally
+            allocateWeights(src.mNumVertices);
+            LLVector4a::memcpyNonAliased16((F32*) mWeights, (F32*) src.mWeights, vert_size);
+            mWeightsScrubbed = src.mWeightsScrubbed;
+        }
+        else
+        {
+            ll_aligned_free_16(mWeights);
+            mWeights = NULL;
+            mWeightsScrubbed = FALSE;
+        }
+
+    #if USE_SEPARATE_JOINT_INDICES_AND_WEIGHTS
+        if (src.mJointIndices)
+        {
+            llassert(!mJointIndices); // don't orphan an old alloc here accidentally
+            allocateJointIndices(src.mNumVertices);
+            LLVector4a::memcpyNonAliased16((F32*) mJointIndices, (F32*) src.mJointIndices, src.mNumVertices * sizeof(U8) * 4);
+        }
+        else*/
+        {
+            ll_aligned_free_16(mJointIndices);
+            mJointIndices = NULL;
+        }
+    #endif
+
+    }
+
+    if (mNumIndices)
+    {
+        S32 idx_size = (mNumIndices*sizeof(U16)+0xF) & ~0xF;
+
+        LLVector4a::memcpyNonAliased16((F32*) mIndices, (F32*) src.mIndices, idx_size);
+    }
+    else
+    {
+        ll_aligned_free_16(mIndices);
+        mIndices = NULL;
+    }
+
+    mOptimized = src.mOptimized;
+    mNormalizedScale = src.mNormalizedScale;
+
+    //delete
+    return *this;
+}
+
+LLVolumeFace::~LLVolumeFace()
+{
+    ll_aligned_free_16(mExtents);
+    mExtents = NULL;
+    mCenter = NULL;
+
+    freeData();
+}
+
+void LLVolumeFace::freeData()
+{
+    ll_aligned_free<64>(mPositions);
+    mPositions = NULL;
+
+    //normals and texture coordinates are part of the same buffer as mPositions, do not free them separately
+    mNormals = NULL;
+    mTexCoords = NULL;
+
+    ll_aligned_free_16(mIndices);
+    mIndices = NULL;
+    ll_aligned_free_16(mTangents);
+    mTangents = NULL;
+    ll_aligned_free_16(mWeights);
+    mWeights = NULL;
+
+#if USE_SEPARATE_JOINT_INDICES_AND_WEIGHTS
+    ll_aligned_free_16(mJointIndices);
+    mJointIndices = NULL;
+    ll_aligned_free_16(mJustWeights);
+    mJustWeights = NULL;
+#endif
+
+    destroyOctree();
+}
+
+BOOL LLVolumeFace::create(LLVolume* volume, BOOL partial_build)
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
+
+    //tree for this face is no longer valid
+    destroyOctree();
+
+    LL_CHECK_MEMORY
+    BOOL ret = FALSE ;
+    if (mTypeMask & CAP_MASK)
+    {
+        ret = createCap(volume, partial_build);
+        LL_CHECK_MEMORY
+    }
+    else if ((mTypeMask & END_MASK) || (mTypeMask & SIDE_MASK))
+    {
+        ret = createSide(volume, partial_build);
+        LL_CHECK_MEMORY
+    }
+    else
+    {
+        LL_ERRS() << "Unknown/uninitialized face type!" << LL_ENDL;
+    }
+
+    return ret ;
+}
+
+void LLVolumeFace::getVertexData(U16 index, LLVolumeFace::VertexData& cv)
+{
+    cv.setPosition(mPositions[index]);
+    if (mNormals)
+    {
+        cv.setNormal(mNormals[index]);
+    }
+    else
+    {
+        cv.getNormal().clear();
+    }
+
+    if (mTexCoords)
+    {
+        cv.mTexCoord = mTexCoords[index];
+    }
+    else
+    {
+        cv.mTexCoord.clear();
+    }
+}
+
+bool LLVolumeFace::VertexMapData::operator==(const LLVolumeFace::VertexData& rhs) const
+{
+    return getPosition().equals3(rhs.getPosition()) &&
+        mTexCoord == rhs.mTexCoord &&
+        getNormal().equals3(rhs.getNormal());
+}
+
+bool LLVolumeFace::VertexMapData::ComparePosition::operator()(const LLVector3& a, const LLVector3& b) const
+{
+    if (a.mV[0] != b.mV[0])
+    {
+        return a.mV[0] < b.mV[0];
+    }
+
+    if (a.mV[1] != b.mV[1])
+    {
+        return a.mV[1] < b.mV[1];
+    }
+
+    return a.mV[2] < b.mV[2];
+}
+
+void LLVolumeFace::remap()
+{
+    // Generate a remap buffer
+    std::vector<unsigned int> remap(mNumVertices);
+    S32 remap_vertices_count = LLMeshOptimizer::generateRemapMultiU16(&remap[0],
+        mIndices,
+        mNumIndices,
+        mPositions,
+        mNormals,
+        mTexCoords,
+        mNumVertices);
+
+    // Allocate new buffers
+    S32 size = ((mNumIndices * sizeof(U16)) + 0xF) & ~0xF;
+    U16* remap_indices = (U16*)ll_aligned_malloc_16(size);
+
+    S32 tc_bytes_size = ((remap_vertices_count * sizeof(LLVector2)) + 0xF) & ~0xF;
+    LLVector4a* remap_positions = (LLVector4a*)ll_aligned_malloc<64>(sizeof(LLVector4a) * 2 * remap_vertices_count + tc_bytes_size);
+    LLVector4a* remap_normals = remap_positions + remap_vertices_count;
+    LLVector2* remap_tex_coords = (LLVector2*)(remap_normals + remap_vertices_count);
+
+    // Fill the buffers
+    LLMeshOptimizer::remapIndexBufferU16(remap_indices, mIndices, mNumIndices, &remap[0]);
+    LLMeshOptimizer::remapPositionsBuffer(remap_positions, mPositions, mNumVertices, &remap[0]);
+    LLMeshOptimizer::remapNormalsBuffer(remap_normals, mNormals, mNumVertices, &remap[0]);
+    LLMeshOptimizer::remapUVBuffer(remap_tex_coords, mTexCoords, mNumVertices, &remap[0]);
+
+    // Free unused buffers
+    ll_aligned_free_16(mIndices);
+    ll_aligned_free<64>(mPositions);
+
+    // Tangets are now invalid
+    ll_aligned_free_16(mTangents);
+    mTangents = NULL;
+
+    // Assign new values
+    mIndices = remap_indices;
+    mPositions = remap_positions;
+    mNormals = remap_normals;
+    mTexCoords = remap_tex_coords;
+    mNumVertices = remap_vertices_count;
+    mNumAllocatedVertices = remap_vertices_count;
+}
+
+void LLVolumeFace::optimize(F32 angle_cutoff)
+{
+    LLVolumeFace new_face;
+
+    //map of points to vector of vertices at that point
+    std::map<U64, std::vector<VertexMapData> > point_map;
+
+    LLVector4a range;
+    range.setSub(mExtents[1],mExtents[0]);
+
+    //remove redundant vertices
+    for (U32 i = 0; i < mNumIndices; ++i)
+    {
+        U16 index = mIndices[i];
+
+        if (index >= mNumVertices)
+        {
+            // invalid index
+            // replace with a valid index to avoid crashes
+            index = mNumVertices - 1;
+            mIndices[i] = index;
+
+            // Needs better logging
+            LL_DEBUGS_ONCE("LLVOLUME") << "Invalid index, substituting" << LL_ENDL;
+        }
+
+        LLVolumeFace::VertexData cv;
+        getVertexData(index, cv);
+
+        BOOL found = FALSE;
+
+        LLVector4a pos;
+        pos.setSub(mPositions[index], mExtents[0]);
+        pos.div(range);
+
+        U64 pos64 = 0;
+
+        pos64 = (U16) (pos[0]*65535);
+        pos64 = pos64 | (((U64) (pos[1]*65535)) << 16);
+        pos64 = pos64 | (((U64) (pos[2]*65535)) << 32);
+
+        std::map<U64, std::vector<VertexMapData> >::iterator point_iter = point_map.find(pos64);
+
+        if (point_iter != point_map.end())
+        { //duplicate point might exist
+            for (U32 j = 0; j < point_iter->second.size(); ++j)
+            {
+                LLVolumeFace::VertexData& tv = (point_iter->second)[j];
+                if (tv.compareNormal(cv, angle_cutoff))
+                {
+                    found = TRUE;
+                    new_face.pushIndex((point_iter->second)[j].mIndex);
+                    break;
+                }
+            }
+        }
+
+        if (!found)
+        {
+            new_face.pushVertex(cv);
+            U16 index = (U16) new_face.mNumVertices-1;
+            new_face.pushIndex(index);
+
+            VertexMapData d;
+            d.setPosition(cv.getPosition());
+            d.mTexCoord = cv.mTexCoord;
+            d.setNormal(cv.getNormal());
+            d.mIndex = index;
+            if (point_iter != point_map.end())
+            {
+                point_iter->second.push_back(d);
+            }
+            else
+            {
+                point_map[pos64].push_back(d);
+            }
+        }
+    }
+
+
+    if (angle_cutoff > 1.f && !mNormals)
+    {
+        // Now alloc'd with positions
+        //ll_aligned_free_16(new_face.mNormals);
+        new_face.mNormals = NULL;
+    }
+
+    if (!mTexCoords)
+    {
+        // Now alloc'd with positions
+        //ll_aligned_free_16(new_face.mTexCoords);
+        new_face.mTexCoords = NULL;
+    }
+
+    // Only swap data if we've actually optimized the mesh
+    //
+    if (new_face.mNumVertices <= mNumVertices)
+    {
+        llassert(new_face.mNumIndices == mNumIndices);
+        swapData(new_face);
+    }
+
+}
+
+class LLVCacheTriangleData;
+
+class LLVCacheVertexData
+{
+public:
+    S32 mIdx;
+    S32 mCacheTag;
+    F64 mScore;
+    U32 mActiveTriangles;
+    std::vector<LLVCacheTriangleData*> mTriangles;
+
+    LLVCacheVertexData()
+    {
+        mCacheTag = -1;
+        mScore = 0.0;
+        mActiveTriangles = 0;
+        mIdx = -1;
+    }
+};
+
+class LLVCacheTriangleData
+{
+public:
+    bool mActive;
+    F64 mScore;
+    LLVCacheVertexData* mVertex[3];
+
+    LLVCacheTriangleData()
+    {
+        mActive = true;
+        mScore = 0.0;
+        mVertex[0] = mVertex[1] = mVertex[2] = NULL;
+    }
+
+    void complete()
+    {
+        mActive = false;
+        for (S32 i = 0; i < 3; ++i)
+        {
+            if (mVertex[i])
+            {
+                llassert(mVertex[i]->mActiveTriangles > 0);
+                mVertex[i]->mActiveTriangles--;
+            }
+        }
+    }
+
+    bool operator<(const LLVCacheTriangleData& rhs) const
+    { //highest score first
+        return rhs.mScore < mScore;
+    }
+};
+
+const F64 FindVertexScore_CacheDecayPower = 1.5;
+const F64 FindVertexScore_LastTriScore = 0.75;
+const F64 FindVertexScore_ValenceBoostScale = 2.0;
+const F64 FindVertexScore_ValenceBoostPower = 0.5;
+const U32 MaxSizeVertexCache = 32;
+const F64 FindVertexScore_Scaler = 1.0/(MaxSizeVertexCache-3);
+
+F64 find_vertex_score(LLVCacheVertexData& data)
+{
+    F64 score = -1.0;
+
+    score = 0.0;
+
+    S32 cache_idx = data.mCacheTag;
+
+    if (cache_idx < 0)
+    {
+        //not in cache
+    }
+    else
+    {
+        if (cache_idx < 3)
+        { //vertex was in the last triangle
+            score = FindVertexScore_LastTriScore;
+        }
+        else
+        { //more points for being higher in the cache
+                score = 1.0-((cache_idx-3)*FindVertexScore_Scaler);
+                score = pow(score, FindVertexScore_CacheDecayPower);
+        }
+    }
+
+    //bonus points for having low valence
+    F64 valence_boost = pow((F64)data.mActiveTriangles, -FindVertexScore_ValenceBoostPower);
+    score += FindVertexScore_ValenceBoostScale * valence_boost;
+
+    return score;
+}
+
+class LLVCacheFIFO
+{
+public:
+    LLVCacheVertexData* mCache[MaxSizeVertexCache];
+    U32 mMisses;
+
+    LLVCacheFIFO()
+    {
+        mMisses = 0;
+        for (U32 i = 0; i < MaxSizeVertexCache; ++i)
+        {
+            mCache[i] = NULL;
+        }
+    }
+
+    void addVertex(LLVCacheVertexData* data)
+    {
+        if (data->mCacheTag == -1)
+        {
+            mMisses++;
+
+            S32 end = MaxSizeVertexCache-1;
+
+            if (mCache[end])
+            {
+                mCache[end]->mCacheTag = -1;
+            }
+
+            for (S32 i = end; i > 0; --i)
+            {
+                mCache[i] = mCache[i-1];
+                if (mCache[i])
+                {
+                    mCache[i]->mCacheTag = i;
+                }
+            }
+
+            mCache[0] = data;
+            data->mCacheTag = 0;
+        }
+    }
+};
+
+class LLVCacheLRU
+{
+public:
+    LLVCacheVertexData* mCache[MaxSizeVertexCache+3];
+
+    LLVCacheTriangleData* mBestTriangle;
+
+    U32 mMisses;
+
+    LLVCacheLRU()
+    {
+        for (U32 i = 0; i < MaxSizeVertexCache+3; ++i)
+        {
+            mCache[i] = NULL;
+        }
+
+        mBestTriangle = NULL;
+        mMisses = 0;
+    }
+
+    void addVertex(LLVCacheVertexData* data)
+    {
+        S32 end = MaxSizeVertexCache+2;
+        if (data->mCacheTag != -1)
+        { //just moving a vertex to the front of the cache
+            end = data->mCacheTag;
+        }
+        else
+        {
+            mMisses++;
+            if (mCache[end])
+            { //adding a new vertex, vertex at end of cache falls off
+                mCache[end]->mCacheTag = -1;
+            }
+        }
+
+        for (S32 i = end; i > 0; --i)
+        { //adjust cache pointers and tags
+            mCache[i] = mCache[i-1];
+
+            if (mCache[i])
+            {
+                mCache[i]->mCacheTag = i;
+            }
+        }
+
+        mCache[0] = data;
+        mCache[0]->mCacheTag = 0;
+    }
+
+    void addTriangle(LLVCacheTriangleData* data)
+    {
+        addVertex(data->mVertex[0]);
+        addVertex(data->mVertex[1]);
+        addVertex(data->mVertex[2]);
+    }
+
+    void updateScores()
+    {
+        LLVCacheVertexData** data_iter = mCache+MaxSizeVertexCache;
+        LLVCacheVertexData** end_data = mCache+MaxSizeVertexCache+3;
+
+        while(data_iter != end_data)
+        {
+            LLVCacheVertexData* data = *data_iter++;
+            //trailing 3 vertices aren't actually in the cache for scoring purposes
+            if (data)
+            {
+                data->mCacheTag = -1;
+            }
+        }
+
+        data_iter = mCache;
+        end_data = mCache+MaxSizeVertexCache;
+
+        while (data_iter != end_data)
+        { //update scores of vertices in cache
+            LLVCacheVertexData* data = *data_iter++;
+            if (data)
+            {
+                data->mScore = find_vertex_score(*data);
+            }
+        }
+
+        mBestTriangle = NULL;
+        //update triangle scores
+        data_iter = mCache;
+        end_data = mCache+MaxSizeVertexCache+3;
+
+        while (data_iter != end_data)
+        {
+            LLVCacheVertexData* data = *data_iter++;
+            if (data)
+            {
+                for (std::vector<LLVCacheTriangleData*>::iterator iter = data->mTriangles.begin(), end_iter = data->mTriangles.end(); iter != end_iter; ++iter)
+                {
+                    LLVCacheTriangleData* tri = *iter;
+                    if (tri->mActive)
+                    {
+                        tri->mScore = tri->mVertex[0] ? tri->mVertex[0]->mScore : 0;
+                        tri->mScore += tri->mVertex[1] ? tri->mVertex[1]->mScore : 0;
+                        tri->mScore += tri->mVertex[2] ? tri->mVertex[2]->mScore : 0;
+
+                        if (!mBestTriangle || mBestTriangle->mScore < tri->mScore)
+                        {
+                            mBestTriangle = tri;
+                        }
+                    }
+                }
+            }
+        }
+
+        //knock trailing 3 vertices off the cache
+        data_iter = mCache+MaxSizeVertexCache;
+        end_data = mCache+MaxSizeVertexCache+3;
+        while (data_iter != end_data)
+        {
+            LLVCacheVertexData* data = *data_iter;
+            if (data)
+            {
+                llassert(data->mCacheTag == -1);
+                *data_iter = NULL;
+            }
+            ++data_iter;
+        }
+    }
+};
+
+// data structures for tangent generation
+
+struct MikktData
+{
+    LLVolumeFace* face;
+    std::vector<LLVector3> p;
+    std::vector<LLVector3> n;
+    std::vector<LLVector2> tc;
+    std::vector<LLVector4> w;
+    std::vector<LLVector4> t;
+
+    MikktData(LLVolumeFace* f)
+        : face(f)
+    {
+        U32 count = face->mNumIndices;
+
+        p.resize(count);
+        n.resize(count);
+        tc.resize(count);
+        t.resize(count);
+
+        if (face->mWeights)
+        {
+            w.resize(count);
+        }
+
+
+        LLVector3 inv_scale(1.f / face->mNormalizedScale.mV[0], 1.f / face->mNormalizedScale.mV[1], 1.f / face->mNormalizedScale.mV[2]);
+
+
+        for (int i = 0; i < face->mNumIndices; ++i)
+        {
+            U32 idx = face->mIndices[i];
+
+            p[i].set(face->mPositions[idx].getF32ptr());
+            p[i].scaleVec(face->mNormalizedScale); //put mesh in original coordinate frame when reconstructing tangents
+            n[i].set(face->mNormals[idx].getF32ptr());
+            n[i].scaleVec(inv_scale);
+            n[i].normalize();
+            tc[i].set(face->mTexCoords[idx]);
+
+            if (idx >= face->mNumVertices)
+            {
+                // invalid index
+                // replace with a valid index to avoid crashes
+                idx = face->mNumVertices - 1;
+                face->mIndices[i] = idx;
+
+                // Needs better logging
+                LL_DEBUGS_ONCE("LLVOLUME") << "Invalid index, substituting" << LL_ENDL;
+            }
+
+            if (face->mWeights)
+            {
+                w[i].set(face->mWeights[idx].getF32ptr());
+            }
+        }
+    }
+
+    uint32_t GetNumFaces()
+    {
+        return uint32_t(face->mNumIndices / 3);
+    }
+
+    uint32_t GetNumVerticesOfFace(const uint32_t face_num)
+    {
+        return 3;
+    }
+
+    mikk::float3 GetPosition(const uint32_t face_num, const uint32_t vert_num)
+    {
+        F32* v = p[face_num * 3 + vert_num].mV;
+        return mikk::float3(v);
+    }
+
+    mikk::float3 GetTexCoord(const uint32_t face_num, const uint32_t vert_num)
+    {
+        F32* uv = tc[face_num * 3 + vert_num].mV;
+        return mikk::float3(uv[0], uv[1], 1.0f);
+    }
+
+    mikk::float3 GetNormal(const uint32_t face_num, const uint32_t vert_num)
+    {
+        F32* normal = n[face_num * 3 + vert_num].mV;
+        return mikk::float3(normal);
+    }
+
+    void SetTangentSpace(const uint32_t face_num, const uint32_t vert_num, mikk::float3 T, bool orientation)
+    {
+        S32 i = face_num * 3 + vert_num;
+        t[i].set(T.x, T.y, T.z, orientation ? 1.0f : -1.0f);
+    }
+};
+bool LLVolumeFace::cacheOptimize(bool gen_tangents)
+{ //optimize for vertex cache according to Forsyth method:
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
+    llassert(!mOptimized);
+    mOptimized = TRUE;
+
+    if (gen_tangents && mNormals && mTexCoords)
+    { // generate mikkt space tangents before cache optimizing since the index buffer may change
+        // a bit of a hack to do this here, but this function gets called exactly once for the lifetime of a mesh
+        // and is executed on a background thread
+        MikktData data(this);
+        mikk::Mikktspace ctx(data);
+        ctx.genTangSpace();
+
+        //re-weld
+        meshopt_Stream mos[] =
+        {
+            { &data.p[0], sizeof(LLVector3), sizeof(LLVector3) },
+            { &data.n[0], sizeof(LLVector3), sizeof(LLVector3) },
+            { &data.t[0], sizeof(LLVector4), sizeof(LLVector4) },
+            { &data.tc[0], sizeof(LLVector2), sizeof(LLVector2) },
+            { data.w.empty() ? nullptr : &data.w[0], sizeof(LLVector4), sizeof(LLVector4) }
+        };
+
+        std::vector<U32> remap;
+        remap.resize(data.p.size());
+
+        U32 stream_count = data.w.empty() ? 4 : 5;
+
+        size_t vert_count = meshopt_generateVertexRemapMulti(&remap[0], nullptr, data.p.size(), data.p.size(), mos, stream_count);
+
+        if (vert_count < 65535 && vert_count != 0)
+        {
+            //copy results back into volume
+            resizeVertices(vert_count);
+
+            if (!data.w.empty())
+            {
+                allocateWeights(vert_count);
+            }
+
+            allocateTangents(mNumVertices);
+
+            for (int i = 0; i < mNumIndices; ++i)
+            {
+                U32 src_idx = i;
+                U32 dst_idx = remap[i];
+                if (dst_idx >= mNumVertices)
+                {
+                    dst_idx = mNumVertices - 1;
+                    // Shouldn't happen, figure out what gets returned in remap and why.
+                    llassert(false);
+                    LL_DEBUGS_ONCE("LLVOLUME") << "Invalid destination index, substituting" << LL_ENDL;
+                }
+                mIndices[i] = dst_idx;
+
+                mPositions[dst_idx].load3(data.p[src_idx].mV);
+                mNormals[dst_idx].load3(data.n[src_idx].mV);
+                mTexCoords[dst_idx] = data.tc[src_idx];
+
+                mTangents[dst_idx].loadua(data.t[src_idx].mV);
 
                 if (mWeights)
                 {
@@ -5578,20 +5578,20 @@ bool LLVolumeFace::cacheOptimize(bool gen_tangents)
     resizeIndices(mNumIndices);
 
     meshopt_optimizeVertexCache<U16>(mIndices, src_indices, mNumIndices, mNumVertices);
-    
+
     ll_aligned_free_16(src_indices);
 
-	return true;
+    return true;
 }
 
 void LLVolumeFace::createOctree(F32 scaler, const LLVector4a& center, const LLVector4a& size)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
 
     if (getOctree())
-	{
-		return;
-	}
+    {
+        return;
+    }
 
     llassert(mNumIndices % 3 == 0);
 
@@ -5601,63 +5601,63 @@ void LLVolumeFace::createOctree(F32 scaler, const LLVector4a& center, const LLVe
     mOctreeTriangles = new LLVolumeTriangle[num_triangles];
 
     for (U32 triangle_index = 0; triangle_index < num_triangles; ++triangle_index)
-	{ //for each triangle
+    { //for each triangle
         const U32 index = triangle_index * 3;
         LLVolumeTriangle* tri = &mOctreeTriangles[triangle_index];
-				
-		const LLVector4a& v0 = mPositions[mIndices[index]];
-		const LLVector4a& v1 = mPositions[mIndices[index + 1]];
-		const LLVector4a& v2 = mPositions[mIndices[index + 2]];
-
-		//store pointers to vertex data
-		tri->mV[0] = &v0;
-		tri->mV[1] = &v1;
-		tri->mV[2] = &v2;
-
-		//store indices
-		tri->mIndex[0] = mIndices[index];
-		tri->mIndex[1] = mIndices[index + 1];
-		tri->mIndex[2] = mIndices[index + 2];
-
-		//get minimum point
-		LLVector4a min = v0;
-		min.setMin(min, v1);
-		min.setMin(min, v2);
-
-		//get maximum point
-		LLVector4a max = v0;
-		max.setMax(max, v1);
-		max.setMax(max, v2);
-
-		//compute center
-		LLVector4a center;
-		center.setAdd(min, max);
-		center.mul(0.5f);
-
-		tri->mPositionGroup = center;
-
-		//compute "radius"
-		LLVector4a size;
-		size.setSub(max,min);
-		
-		tri->mRadius = size.getLength3().getF32() * scaler;
-		
-		//insert
-		mOctree->insert(tri);
-	}
-
-	//remove unneeded octree layers
-	while (!mOctree->balance())	{ }
-
-	//calculate AABB for each node
-	LLVolumeOctreeRebound rebound;
-	rebound.traverse(mOctree);
-
-	if (gDebugGL)
-	{
-		LLVolumeOctreeValidate validate;
-		validate.traverse(mOctree);
-	}
+
+        const LLVector4a& v0 = mPositions[mIndices[index]];
+        const LLVector4a& v1 = mPositions[mIndices[index + 1]];
+        const LLVector4a& v2 = mPositions[mIndices[index + 2]];
+
+        //store pointers to vertex data
+        tri->mV[0] = &v0;
+        tri->mV[1] = &v1;
+        tri->mV[2] = &v2;
+
+        //store indices
+        tri->mIndex[0] = mIndices[index];
+        tri->mIndex[1] = mIndices[index + 1];
+        tri->mIndex[2] = mIndices[index + 2];
+
+        //get minimum point
+        LLVector4a min = v0;
+        min.setMin(min, v1);
+        min.setMin(min, v2);
+
+        //get maximum point
+        LLVector4a max = v0;
+        max.setMax(max, v1);
+        max.setMax(max, v2);
+
+        //compute center
+        LLVector4a center;
+        center.setAdd(min, max);
+        center.mul(0.5f);
+
+        tri->mPositionGroup = center;
+
+        //compute "radius"
+        LLVector4a size;
+        size.setSub(max,min);
+
+        tri->mRadius = size.getLength3().getF32() * scaler;
+
+        //insert
+        mOctree->insert(tri);
+    }
+
+    //remove unneeded octree layers
+    while (!mOctree->balance()) { }
+
+    //calculate AABB for each node
+    LLVolumeOctreeRebound rebound;
+    rebound.traverse(mOctree);
+
+    if (gDebugGL)
+    {
+        LLVolumeOctreeValidate validate;
+        validate.traverse(mOctree);
+    }
 }
 
 void LLVolumeFace::destroyOctree()
@@ -5676,145 +5676,145 @@ const LLVolumeOctree* LLVolumeFace::getOctree() const
 
 void LLVolumeFace::swapData(LLVolumeFace& rhs)
 {
-	llswap(rhs.mPositions, mPositions);
-	llswap(rhs.mNormals, mNormals);
-	llswap(rhs.mTangents, mTangents);
-	llswap(rhs.mTexCoords, mTexCoords);
-	llswap(rhs.mIndices,mIndices);
-	llswap(rhs.mNumVertices, mNumVertices);
-	llswap(rhs.mNumIndices, mNumIndices);
+    llswap(rhs.mPositions, mPositions);
+    llswap(rhs.mNormals, mNormals);
+    llswap(rhs.mTangents, mTangents);
+    llswap(rhs.mTexCoords, mTexCoords);
+    llswap(rhs.mIndices,mIndices);
+    llswap(rhs.mNumVertices, mNumVertices);
+    llswap(rhs.mNumIndices, mNumIndices);
 }
 
-void	LerpPlanarVertex(LLVolumeFace::VertexData& v0,
-				   LLVolumeFace::VertexData& v1,
-				   LLVolumeFace::VertexData& v2,
-				   LLVolumeFace::VertexData& vout,
-				   F32	coef01,
-				   F32	coef02)
+void    LerpPlanarVertex(LLVolumeFace::VertexData& v0,
+                   LLVolumeFace::VertexData& v1,
+                   LLVolumeFace::VertexData& v2,
+                   LLVolumeFace::VertexData& vout,
+                   F32  coef01,
+                   F32  coef02)
 {
 
-	LLVector4a lhs;
-	lhs.setSub(v1.getPosition(), v0.getPosition());
-	lhs.mul(coef01);
-	LLVector4a rhs;
-	rhs.setSub(v2.getPosition(), v0.getPosition());
-	rhs.mul(coef02);
+    LLVector4a lhs;
+    lhs.setSub(v1.getPosition(), v0.getPosition());
+    lhs.mul(coef01);
+    LLVector4a rhs;
+    rhs.setSub(v2.getPosition(), v0.getPosition());
+    rhs.mul(coef02);
 
-	rhs.add(lhs);
-	rhs.add(v0.getPosition());
+    rhs.add(lhs);
+    rhs.add(v0.getPosition());
 
-	vout.setPosition(rhs);
-		
-	vout.mTexCoord = v0.mTexCoord + ((v1.mTexCoord-v0.mTexCoord)*coef01)+((v2.mTexCoord-v0.mTexCoord)*coef02);
-	vout.setNormal(v0.getNormal());
+    vout.setPosition(rhs);
+
+    vout.mTexCoord = v0.mTexCoord + ((v1.mTexCoord-v0.mTexCoord)*coef01)+((v2.mTexCoord-v0.mTexCoord)*coef02);
+    vout.setNormal(v0.getNormal());
 }
 
 BOOL LLVolumeFace::createUnCutCubeCap(LLVolume* volume, BOOL partial_build)
 {
-	LL_CHECK_MEMORY		
-
-	const LLAlignedArray<LLVector4a,64>& mesh = volume->getMesh();
-	const LLAlignedArray<LLVector4a,64>& profile = volume->getProfile().mProfile;
-	S32 max_s = volume->getProfile().getTotal();
-	S32 max_t = volume->getPath().mPath.size();
-
-	// S32 i;
-	S32	grid_size = (profile.size()-1)/4;
-	// VFExtents change
-	LLVector4a& min = mExtents[0];
-	LLVector4a& max = mExtents[1];
-
-	S32 offset = 0;
-	if (mTypeMask & TOP_MASK)
-	{
-		offset = (max_t-1) * max_s;
-	}
-	else
-	{
-		offset = mBeginS;
-	}
-
-	{
-		VertexData	corners[4];
-		VertexData baseVert;
-		for(S32 t = 0; t < 4; t++)
-		{
-			corners[t].getPosition().load4a(mesh[offset + (grid_size*t)].getF32ptr());
-			corners[t].mTexCoord.mV[0] = profile[grid_size*t][0]+0.5f;
-			corners[t].mTexCoord.mV[1] = 0.5f - profile[grid_size*t][1];
-		}
-
-		{
-			LLVector4a lhs;
-			lhs.setSub(corners[1].getPosition(), corners[0].getPosition());
-			LLVector4a rhs;
-			rhs.setSub(corners[2].getPosition(), corners[1].getPosition());
-			baseVert.getNormal().setCross3(lhs, rhs); 
-			baseVert.getNormal().normalize3fast();
-		}
-
-		if(!(mTypeMask & TOP_MASK))
-		{
-			baseVert.getNormal().mul(-1.0f);
-		}
-		else
-		{
-			//Swap the UVs on the U(X) axis for top face
-			LLVector2 swap;
-			swap = corners[0].mTexCoord;
-			corners[0].mTexCoord=corners[3].mTexCoord;
-			corners[3].mTexCoord=swap;
-			swap = corners[1].mTexCoord;
-			corners[1].mTexCoord=corners[2].mTexCoord;
-			corners[2].mTexCoord=swap;
-		}
-
-		S32 size = (grid_size+1)*(grid_size+1);
-		resizeVertices(size);
-		
-		LLVector4a* pos = (LLVector4a*) mPositions;
-		LLVector4a* norm = (LLVector4a*) mNormals;
-		LLVector2* tc = (LLVector2*) mTexCoords;
-
-		for(int gx = 0;gx<grid_size+1;gx++)
-		{
-			for(int gy = 0;gy<grid_size+1;gy++)
-			{
-				VertexData newVert;
-				LerpPlanarVertex(
-					corners[0],
-					corners[1],
-					corners[3],
-					newVert,
-					(F32)gx/(F32)grid_size,
-					(F32)gy/(F32)grid_size);
-
-				*pos++ = newVert.getPosition();
-				*norm++ = baseVert.getNormal();
-				*tc++ = newVert.mTexCoord;
-				
-				if (gx == 0 && gy == 0)
-				{
-					min = newVert.getPosition();
-					max = min;
-				}
-				else
-				{
-					min.setMin(min, newVert.getPosition());
-					max.setMax(max, newVert.getPosition());
-				}
-			}
-		}
-	
-		mCenter->setAdd(min, max);
-		mCenter->mul(0.5f); 
-	}
-
-	if (!partial_build)
-	{
-		resizeIndices(grid_size*grid_size*6);
-		if (!volume->isMeshAssetLoaded())
-		{
+    LL_CHECK_MEMORY
+
+    const LLAlignedArray<LLVector4a,64>& mesh = volume->getMesh();
+    const LLAlignedArray<LLVector4a,64>& profile = volume->getProfile().mProfile;
+    S32 max_s = volume->getProfile().getTotal();
+    S32 max_t = volume->getPath().mPath.size();
+
+    // S32 i;
+    S32 grid_size = (profile.size()-1)/4;
+    // VFExtents change
+    LLVector4a& min = mExtents[0];
+    LLVector4a& max = mExtents[1];
+
+    S32 offset = 0;
+    if (mTypeMask & TOP_MASK)
+    {
+        offset = (max_t-1) * max_s;
+    }
+    else
+    {
+        offset = mBeginS;
+    }
+
+    {
+        VertexData  corners[4];
+        VertexData baseVert;
+        for(S32 t = 0; t < 4; t++)
+        {
+            corners[t].getPosition().load4a(mesh[offset + (grid_size*t)].getF32ptr());
+            corners[t].mTexCoord.mV[0] = profile[grid_size*t][0]+0.5f;
+            corners[t].mTexCoord.mV[1] = 0.5f - profile[grid_size*t][1];
+        }
+
+        {
+            LLVector4a lhs;
+            lhs.setSub(corners[1].getPosition(), corners[0].getPosition());
+            LLVector4a rhs;
+            rhs.setSub(corners[2].getPosition(), corners[1].getPosition());
+            baseVert.getNormal().setCross3(lhs, rhs);
+            baseVert.getNormal().normalize3fast();
+        }
+
+        if(!(mTypeMask & TOP_MASK))
+        {
+            baseVert.getNormal().mul(-1.0f);
+        }
+        else
+        {
+            //Swap the UVs on the U(X) axis for top face
+            LLVector2 swap;
+            swap = corners[0].mTexCoord;
+            corners[0].mTexCoord=corners[3].mTexCoord;
+            corners[3].mTexCoord=swap;
+            swap = corners[1].mTexCoord;
+            corners[1].mTexCoord=corners[2].mTexCoord;
+            corners[2].mTexCoord=swap;
+        }
+
+        S32 size = (grid_size+1)*(grid_size+1);
+        resizeVertices(size);
+
+        LLVector4a* pos = (LLVector4a*) mPositions;
+        LLVector4a* norm = (LLVector4a*) mNormals;
+        LLVector2* tc = (LLVector2*) mTexCoords;
+
+        for(int gx = 0;gx<grid_size+1;gx++)
+        {
+            for(int gy = 0;gy<grid_size+1;gy++)
+            {
+                VertexData newVert;
+                LerpPlanarVertex(
+                    corners[0],
+                    corners[1],
+                    corners[3],
+                    newVert,
+                    (F32)gx/(F32)grid_size,
+                    (F32)gy/(F32)grid_size);
+
+                *pos++ = newVert.getPosition();
+                *norm++ = baseVert.getNormal();
+                *tc++ = newVert.mTexCoord;
+
+                if (gx == 0 && gy == 0)
+                {
+                    min = newVert.getPosition();
+                    max = min;
+                }
+                else
+                {
+                    min.setMin(min, newVert.getPosition());
+                    max.setMax(max, newVert.getPosition());
+                }
+            }
+        }
+
+        mCenter->setAdd(min, max);
+        mCenter->mul(0.5f);
+    }
+
+    if (!partial_build)
+    {
+        resizeIndices(grid_size*grid_size*6);
+        if (!volume->isMeshAssetLoaded())
+        {
             S32 size = grid_size * grid_size * 6;
             try
             {
@@ -5825,563 +5825,563 @@ BOOL LLVolumeFace::createUnCutCubeCap(LLVolume* volume, BOOL partial_build)
                 LL_WARNS("LLVOLUME") << "Resize of mEdge to " << size << " failed" << LL_ENDL;
                 return false;
             }
-		}
-
-		U16* out = mIndices;
-
-		S32 idxs[] = {0,1,(grid_size+1)+1,(grid_size+1)+1,(grid_size+1),0};
-
-		int cur_edge = 0;
-
-		for(S32 gx = 0;gx<grid_size;gx++)
-		{
-			
-			for(S32 gy = 0;gy<grid_size;gy++)
-			{
-				if (mTypeMask & TOP_MASK)
-				{
-					for(S32 i=5;i>=0;i--)
-					{
-						*out++ = ((gy*(grid_size+1))+gx+idxs[i]);
-					}
-
-					S32 edge_value = grid_size * 2 * gy + gx * 2;
-
-					if (gx > 0)
-					{
-						mEdge[cur_edge++] = edge_value;
-					}
-					else
-					{
-						mEdge[cur_edge++] = -1; // Mark face to higlight it
-					}
-
-					if (gy < grid_size - 1)
-					{
-						mEdge[cur_edge++] = edge_value;
-					}
-					else
-					{
-						mEdge[cur_edge++] = -1;
-					}
-
-					mEdge[cur_edge++] = edge_value;
-
-					if (gx < grid_size - 1)
-					{
-						mEdge[cur_edge++] = edge_value;
-					}
-					else
-					{
-						mEdge[cur_edge++] = -1;
-					}
-
-					if (gy > 0)
-					{
-						mEdge[cur_edge++] = edge_value;
-					}
-					else
-					{
-						mEdge[cur_edge++] = -1;
-					}
-
-					mEdge[cur_edge++] = edge_value;
-				}
-				else
-				{
-					for(S32 i=0;i<6;i++)
-					{
-						*out++ = ((gy*(grid_size+1))+gx+idxs[i]);
-					}
-
-					S32 edge_value = grid_size * 2 * gy + gx * 2;
-
-					if (gy > 0)
-					{
-						mEdge[cur_edge++] = edge_value;
-					}
-					else
-					{
-						mEdge[cur_edge++] = -1;
-					}
-
-					if (gx < grid_size - 1)
-					{
-						mEdge[cur_edge++] = edge_value;
-					}
-					else
-					{
-						mEdge[cur_edge++] = -1;
-					}
-
-					mEdge[cur_edge++] = edge_value;
-
-					if (gy < grid_size - 1)
-					{
-						mEdge[cur_edge++] = edge_value;
-					}
-					else
-					{
-						mEdge[cur_edge++] = -1;
-					}
-
-					if (gx > 0)
-					{
-						mEdge[cur_edge++] = edge_value;
-					}
-					else
-					{
-						mEdge[cur_edge++] = -1;
-					}
-
-					mEdge[cur_edge++] = edge_value;
-				}
-			}
-		}
-	}
-		
-	LL_CHECK_MEMORY
-	return TRUE;
+        }
+
+        U16* out = mIndices;
+
+        S32 idxs[] = {0,1,(grid_size+1)+1,(grid_size+1)+1,(grid_size+1),0};
+
+        int cur_edge = 0;
+
+        for(S32 gx = 0;gx<grid_size;gx++)
+        {
+
+            for(S32 gy = 0;gy<grid_size;gy++)
+            {
+                if (mTypeMask & TOP_MASK)
+                {
+                    for(S32 i=5;i>=0;i--)
+                    {
+                        *out++ = ((gy*(grid_size+1))+gx+idxs[i]);
+                    }
+
+                    S32 edge_value = grid_size * 2 * gy + gx * 2;
+
+                    if (gx > 0)
+                    {
+                        mEdge[cur_edge++] = edge_value;
+                    }
+                    else
+                    {
+                        mEdge[cur_edge++] = -1; // Mark face to higlight it
+                    }
+
+                    if (gy < grid_size - 1)
+                    {
+                        mEdge[cur_edge++] = edge_value;
+                    }
+                    else
+                    {
+                        mEdge[cur_edge++] = -1;
+                    }
+
+                    mEdge[cur_edge++] = edge_value;
+
+                    if (gx < grid_size - 1)
+                    {
+                        mEdge[cur_edge++] = edge_value;
+                    }
+                    else
+                    {
+                        mEdge[cur_edge++] = -1;
+                    }
+
+                    if (gy > 0)
+                    {
+                        mEdge[cur_edge++] = edge_value;
+                    }
+                    else
+                    {
+                        mEdge[cur_edge++] = -1;
+                    }
+
+                    mEdge[cur_edge++] = edge_value;
+                }
+                else
+                {
+                    for(S32 i=0;i<6;i++)
+                    {
+                        *out++ = ((gy*(grid_size+1))+gx+idxs[i]);
+                    }
+
+                    S32 edge_value = grid_size * 2 * gy + gx * 2;
+
+                    if (gy > 0)
+                    {
+                        mEdge[cur_edge++] = edge_value;
+                    }
+                    else
+                    {
+                        mEdge[cur_edge++] = -1;
+                    }
+
+                    if (gx < grid_size - 1)
+                    {
+                        mEdge[cur_edge++] = edge_value;
+                    }
+                    else
+                    {
+                        mEdge[cur_edge++] = -1;
+                    }
+
+                    mEdge[cur_edge++] = edge_value;
+
+                    if (gy < grid_size - 1)
+                    {
+                        mEdge[cur_edge++] = edge_value;
+                    }
+                    else
+                    {
+                        mEdge[cur_edge++] = -1;
+                    }
+
+                    if (gx > 0)
+                    {
+                        mEdge[cur_edge++] = edge_value;
+                    }
+                    else
+                    {
+                        mEdge[cur_edge++] = -1;
+                    }
+
+                    mEdge[cur_edge++] = edge_value;
+                }
+            }
+        }
+    }
+
+    LL_CHECK_MEMORY
+    return TRUE;
 }
 
 
-BOOL LLVolumeFace::createCap(LLVolume* volume, BOOL partial_build)
-{
-	const LLPathParams& path_params = volume->getParams().getPathParams();
-	if (!(mTypeMask & HOLLOW_MASK) && 
-		!(mTypeMask & OPEN_MASK) && 
-		((path_params.getBegin()==0.0f)&&
-		(path_params.getEnd()==1.0f))&&
-		(volume->getParams().getProfileParams().getCurveType()==LL_PCODE_PROFILE_SQUARE &&
-		 path_params.getCurveType()==LL_PCODE_PATH_LINE)	
-		){
-		return createUnCutCubeCap(volume, partial_build);
-	}
-
-	S32 num_vertices = 0, num_indices = 0;
-
-	const LLAlignedArray<LLVector4a,64>& mesh = volume->getMesh();
-	const LLAlignedArray<LLVector4a,64>& profile = volume->getProfile().mProfile;
-
-	// All types of caps have the same number of vertices and indices
-	num_vertices = profile.size();
-	num_indices = (profile.size() - 2)*3;
-
-	if (!(mTypeMask & HOLLOW_MASK) && !(mTypeMask & OPEN_MASK))
-	{
-		resizeVertices(num_vertices+1);
-		
-		//if (!partial_build)
-		{
-			resizeIndices(num_indices+3);
-		}
-	}
-	else
-	{
-		resizeVertices(num_vertices);
-		//if (!partial_build)
-		{
-			resizeIndices(num_indices);
-		}
-	}
-
-	LL_CHECK_MEMORY;
-
-	S32 max_s = volume->getProfile().getTotal();
-	S32 max_t = volume->getPath().mPath.size();
-
-	mCenter->clear();
-
-	S32 offset = 0;
-	if (mTypeMask & TOP_MASK)
-	{
-		offset = (max_t-1) * max_s;
-	}
-	else
-	{
-		offset = mBeginS;
-	}
-
-	// Figure out the normal, assume all caps are flat faces.
-	// Cross product to get normals.
-	
-	LLVector2 cuv;
-	LLVector2 min_uv, max_uv;
-	// VFExtents change
-	LLVector4a& min = mExtents[0];
-	LLVector4a& max = mExtents[1];
-
-	LLVector2* tc = (LLVector2*) mTexCoords;
-	LLVector4a* pos = (LLVector4a*) mPositions;
-	LLVector4a* norm = (LLVector4a*) mNormals;
-	
-	// Copy the vertices into the array
-
-	const LLVector4a* src = mesh.mArray+offset;
-	const LLVector4a* end = src+num_vertices;
-	
-	min = *src;
-	max = min;
-	
-	
-	const LLVector4a* p = profile.mArray;
-
-	if (mTypeMask & TOP_MASK)
-	{
-		min_uv.set((*p)[0]+0.5f,
-					(*p)[1]+0.5f);
-
-		max_uv = min_uv;
-
-		while(src < end)
-		{
-			tc->mV[0] = (*p)[0]+0.5f;
-			tc->mV[1] = (*p)[1]+0.5f;
-
-			llassert(src->isFinite3()); // MAINT-5660; don't know why this happens, does not affect Release builds
-			update_min_max(min,max,*src);
-			update_min_max(min_uv, max_uv, *tc);
-		
-			*pos = *src;
-		
-			llassert(pos->isFinite3());
-
-			++p;
-			++tc;
-			++src;
-			++pos;
-		}
-		}
-		else
-		{
-
-		min_uv.set((*p)[0]+0.5f,
-				   0.5f - (*p)[1]);
-		max_uv = min_uv;
-
-		while(src < end)
-		{
-			// Mirror for underside.
-			tc->mV[0] = (*p)[0]+0.5f;
-			tc->mV[1] = 0.5f - (*p)[1];
-		
-			llassert(src->isFinite3());
-			update_min_max(min,max,*src);
-			update_min_max(min_uv, max_uv, *tc);
-
-			*pos = *src;
-		
-			llassert(pos->isFinite3());
-		
-			++p;
-			++tc;
-			++src;
-			++pos;
-		}
-	}
-
-	LL_CHECK_MEMORY
-
-	mCenter->setAdd(min, max);
-	mCenter->mul(0.5f); 
-
-	cuv = (min_uv + max_uv)*0.5f;
-
-
-	VertexData vd;
-	vd.setPosition(*mCenter);
-	vd.mTexCoord = cuv;
-	
-	if (!(mTypeMask & HOLLOW_MASK) && !(mTypeMask & OPEN_MASK))
-	{
-		*pos++ = *mCenter;
-		*tc++ = cuv;
-		num_vertices++;
-	}
-		
-	LL_CHECK_MEMORY
-		
-	//if (partial_build)
-	//{
-	//	return TRUE;
-	//}
-
-	if (mTypeMask & HOLLOW_MASK)
-	{
-		if (mTypeMask & TOP_MASK)
-		{
-			// HOLLOW TOP
-			// Does it matter if it's open or closed? - djs
-
-			S32 pt1 = 0, pt2 = num_vertices - 1;
-			S32 i = 0;
-			while (pt2 - pt1 > 1)
-			{
-				// Use the profile points instead of the mesh, since you want
-				// the un-transformed profile distances.
-				const LLVector4a& p1 = profile[pt1];
-				const LLVector4a& p2 = profile[pt2];
-				const LLVector4a& pa = profile[pt1+1];
-				const LLVector4a& pb = profile[pt2-1];
-
-				const F32* p1V = p1.getF32ptr();
-				const F32* p2V = p2.getF32ptr();
-				const F32* paV = pa.getF32ptr();
-				const F32* pbV = pb.getF32ptr();
-
-				//p1.mV[VZ] = 0.f;
-				//p2.mV[VZ] = 0.f;
-				//pa.mV[VZ] = 0.f;
-				//pb.mV[VZ] = 0.f;
-
-				// Use area of triangle to determine backfacing
-				F32 area_1a2, area_1ba, area_21b, area_2ab;
-				area_1a2 =  (p1V[0]*paV[1] - paV[0]*p1V[1]) +
-							(paV[0]*p2V[1] - p2V[0]*paV[1]) +
-							(p2V[0]*p1V[1] - p1V[0]*p2V[1]);
-
-				area_1ba =  (p1V[0]*pbV[1] - pbV[0]*p1V[1]) +
-							(pbV[0]*paV[1] - paV[0]*pbV[1]) +
-							(paV[0]*p1V[1] - p1V[0]*paV[1]);
-
-				area_21b =  (p2V[0]*p1V[1] - p1V[0]*p2V[1]) +
-							(p1V[0]*pbV[1] - pbV[0]*p1V[1]) +
-							(pbV[0]*p2V[1] - p2V[0]*pbV[1]);
-
-				area_2ab =  (p2V[0]*paV[1] - paV[0]*p2V[1]) +
-							(paV[0]*pbV[1] - pbV[0]*paV[1]) +
-							(pbV[0]*p2V[1] - p2V[0]*pbV[1]);
-
-				BOOL use_tri1a2 = TRUE;
-				BOOL tri_1a2 = TRUE;
-				BOOL tri_21b = TRUE;
-
-				if (area_1a2 < 0)
-				{
-					tri_1a2 = FALSE;
-				}
-				if (area_2ab < 0)
-				{
-					// Can't use, because it contains point b
-					tri_1a2 = FALSE;
-				}
-				if (area_21b < 0)
-				{
-					tri_21b = FALSE;
-				}
-				if (area_1ba < 0)
-				{
-					// Can't use, because it contains point b
-					tri_21b = FALSE;
-				}
-
-				if (!tri_1a2)
-				{
-					use_tri1a2 = FALSE;
-				}
-				else if (!tri_21b)
-				{
-					use_tri1a2 = TRUE;
-				}
-				else
-				{
-					LLVector4a d1;
-					d1.setSub(p1, pa);
-					
-					LLVector4a d2; 
-					d2.setSub(p2, pb);
-
-					if (d1.dot3(d1) < d2.dot3(d2))
-					{
-						use_tri1a2 = TRUE;
-					}
-					else
-					{
-						use_tri1a2 = FALSE;
-					}
-				}
-
-				if (use_tri1a2)
-				{
-					mIndices[i++] = pt1;
-					mIndices[i++] = pt1 + 1;
-					mIndices[i++] = pt2;
-					pt1++;
-				}
-				else
-				{
-					mIndices[i++] = pt1;
-					mIndices[i++] = pt2 - 1;
-					mIndices[i++] = pt2;
-					pt2--;
-				}
-			}
-		}
-		else
-		{
-			// HOLLOW BOTTOM
-			// Does it matter if it's open or closed? - djs
-
-			llassert(mTypeMask & BOTTOM_MASK);
-			S32 pt1 = 0, pt2 = num_vertices - 1;
-
-			S32 i = 0;
-			while (pt2 - pt1 > 1)
-			{
-				// Use the profile points instead of the mesh, since you want
-				// the un-transformed profile distances.
-				const LLVector4a& p1 = profile[pt1];
-				const LLVector4a& p2 = profile[pt2];
-				const LLVector4a& pa = profile[pt1+1];
-				const LLVector4a& pb = profile[pt2-1];
-
-				const F32* p1V = p1.getF32ptr();
-				const F32* p2V = p2.getF32ptr();
-				const F32* paV = pa.getF32ptr();
-				const F32* pbV = pb.getF32ptr();
-
-				// Use area of triangle to determine backfacing
-				F32 area_1a2, area_1ba, area_21b, area_2ab;
-				area_1a2 =  (p1V[0]*paV[1] - paV[0]*p1V[1]) +
-							(paV[0]*p2V[1] - p2V[0]*paV[1]) +
-							(p2V[0]*p1V[1] - p1V[0]*p2V[1]);
-
-				area_1ba =  (p1V[0]*pbV[1] - pbV[0]*p1V[1]) +
-							(pbV[0]*paV[1] - paV[0]*pbV[1]) +
-							(paV[0]*p1V[1] - p1V[0]*paV[1]);
-
-				area_21b =  (p2V[0]*p1V[1] - p1V[0]*p2V[1]) +
-							(p1V[0]*pbV[1] - pbV[0]*p1V[1]) +
-							(pbV[0]*p2V[1] - p2V[0]*pbV[1]);
-
-				area_2ab =  (p2V[0]*paV[1] - paV[0]*p2V[1]) +
-							(paV[0]*pbV[1] - pbV[0]*paV[1]) +
-							(pbV[0]*p2V[1] - p2V[0]*pbV[1]);
-
-				BOOL use_tri1a2 = TRUE;
-				BOOL tri_1a2 = TRUE;
-				BOOL tri_21b = TRUE;
-
-				if (area_1a2 < 0)
-				{
-					tri_1a2 = FALSE;
-				}
-				if (area_2ab < 0)
-				{
-					// Can't use, because it contains point b
-					tri_1a2 = FALSE;
-				}
-				if (area_21b < 0)
-				{
-					tri_21b = FALSE;
-				}
-				if (area_1ba < 0)
-				{
-					// Can't use, because it contains point b
-					tri_21b = FALSE;
-				}
-
-				if (!tri_1a2)
-				{
-					use_tri1a2 = FALSE;
-				}
-				else if (!tri_21b)
-				{
-					use_tri1a2 = TRUE;
-				}
-				else
-				{
-					LLVector4a d1;
-					d1.setSub(p1,pa);
-					LLVector4a d2;
-					d2.setSub(p2,pb);
-
-					if (d1.dot3(d1) < d2.dot3(d2))
-					{
-						use_tri1a2 = TRUE;
-					}
-					else
-					{
-						use_tri1a2 = FALSE;
-					}
-				}
-
-				// Flipped backfacing from top
-				if (use_tri1a2)
-				{
-					mIndices[i++] = pt1;
-					mIndices[i++] = pt2;
-					mIndices[i++] = pt1 + 1;
-					pt1++;
-				}
-				else
-				{
-					mIndices[i++] = pt1;
-					mIndices[i++] = pt2;
-					mIndices[i++] = pt2 - 1;
-					pt2--;
-				}
-			}
-		}
-	}
-	else
-	{
-		// Not hollow, generate the triangle fan.
-		U16 v1 = 2;
-		U16 v2 = 1;
-
-		if (mTypeMask & TOP_MASK)
-		{
-			v1 = 1;
-			v2 = 2;
-		}
-
-		for (S32 i = 0; i < (num_vertices - 2); i++)
-		{
-			mIndices[3*i] = num_vertices - 1;
-			mIndices[3*i+v1] = i;
-			mIndices[3*i+v2] = i + 1;
-		}
-
-
-	}
-
-	LLVector4a d0,d1;
-	LL_CHECK_MEMORY
-		
-
-	d0.setSub(mPositions[mIndices[1]], mPositions[mIndices[0]]);
-	d1.setSub(mPositions[mIndices[2]], mPositions[mIndices[0]]);
-
-	LLVector4a normal;
-	normal.setCross3(d0,d1);
-
-	if (normal.dot3(normal).getF32() > F_APPROXIMATELY_ZERO)
-	{
-		normal.normalize3fast();
-	}
-	else
-	{ //degenerate, make up a value
-		if(normal.getF32ptr()[2] >= 0)
-			normal.set(0.f,0.f,1.f);
-		else
-			normal.set(0.f,0.f,-1.f);
-	}
-
-	llassert(llfinite(normal.getF32ptr()[0]));
-	llassert(llfinite(normal.getF32ptr()[1]));
-	llassert(llfinite(normal.getF32ptr()[2]));
-
-	llassert(!llisnan(normal.getF32ptr()[0]));
-	llassert(!llisnan(normal.getF32ptr()[1]));
-	llassert(!llisnan(normal.getF32ptr()[2]));
-	
-	for (S32 i = 0; i < num_vertices; i++)
-	{
-		norm[i].load4a(normal.getF32ptr());
-	}
-
-	return TRUE;
+BOOL LLVolumeFace::createCap(LLVolume* volume, BOOL partial_build)
+{
+    const LLPathParams& path_params = volume->getParams().getPathParams();
+    if (!(mTypeMask & HOLLOW_MASK) &&
+        !(mTypeMask & OPEN_MASK) &&
+        ((path_params.getBegin()==0.0f)&&
+        (path_params.getEnd()==1.0f))&&
+        (volume->getParams().getProfileParams().getCurveType()==LL_PCODE_PROFILE_SQUARE &&
+         path_params.getCurveType()==LL_PCODE_PATH_LINE)
+        ){
+        return createUnCutCubeCap(volume, partial_build);
+    }
+
+    S32 num_vertices = 0, num_indices = 0;
+
+    const LLAlignedArray<LLVector4a,64>& mesh = volume->getMesh();
+    const LLAlignedArray<LLVector4a,64>& profile = volume->getProfile().mProfile;
+
+    // All types of caps have the same number of vertices and indices
+    num_vertices = profile.size();
+    num_indices = (profile.size() - 2)*3;
+
+    if (!(mTypeMask & HOLLOW_MASK) && !(mTypeMask & OPEN_MASK))
+    {
+        resizeVertices(num_vertices+1);
+
+        //if (!partial_build)
+        {
+            resizeIndices(num_indices+3);
+        }
+    }
+    else
+    {
+        resizeVertices(num_vertices);
+        //if (!partial_build)
+        {
+            resizeIndices(num_indices);
+        }
+    }
+
+    LL_CHECK_MEMORY;
+
+    S32 max_s = volume->getProfile().getTotal();
+    S32 max_t = volume->getPath().mPath.size();
+
+    mCenter->clear();
+
+    S32 offset = 0;
+    if (mTypeMask & TOP_MASK)
+    {
+        offset = (max_t-1) * max_s;
+    }
+    else
+    {
+        offset = mBeginS;
+    }
+
+    // Figure out the normal, assume all caps are flat faces.
+    // Cross product to get normals.
+
+    LLVector2 cuv;
+    LLVector2 min_uv, max_uv;
+    // VFExtents change
+    LLVector4a& min = mExtents[0];
+    LLVector4a& max = mExtents[1];
+
+    LLVector2* tc = (LLVector2*) mTexCoords;
+    LLVector4a* pos = (LLVector4a*) mPositions;
+    LLVector4a* norm = (LLVector4a*) mNormals;
+
+    // Copy the vertices into the array
+
+    const LLVector4a* src = mesh.mArray+offset;
+    const LLVector4a* end = src+num_vertices;
+
+    min = *src;
+    max = min;
+
+
+    const LLVector4a* p = profile.mArray;
+
+    if (mTypeMask & TOP_MASK)
+    {
+        min_uv.set((*p)[0]+0.5f,
+                    (*p)[1]+0.5f);
+
+        max_uv = min_uv;
+
+        while(src < end)
+        {
+            tc->mV[0] = (*p)[0]+0.5f;
+            tc->mV[1] = (*p)[1]+0.5f;
+
+            llassert(src->isFinite3()); // MAINT-5660; don't know why this happens, does not affect Release builds
+            update_min_max(min,max,*src);
+            update_min_max(min_uv, max_uv, *tc);
+
+            *pos = *src;
+
+            llassert(pos->isFinite3());
+
+            ++p;
+            ++tc;
+            ++src;
+            ++pos;
+        }
+        }
+        else
+        {
+
+        min_uv.set((*p)[0]+0.5f,
+                   0.5f - (*p)[1]);
+        max_uv = min_uv;
+
+        while(src < end)
+        {
+            // Mirror for underside.
+            tc->mV[0] = (*p)[0]+0.5f;
+            tc->mV[1] = 0.5f - (*p)[1];
+
+            llassert(src->isFinite3());
+            update_min_max(min,max,*src);
+            update_min_max(min_uv, max_uv, *tc);
+
+            *pos = *src;
+
+            llassert(pos->isFinite3());
+
+            ++p;
+            ++tc;
+            ++src;
+            ++pos;
+        }
+    }
+
+    LL_CHECK_MEMORY
+
+    mCenter->setAdd(min, max);
+    mCenter->mul(0.5f);
+
+    cuv = (min_uv + max_uv)*0.5f;
+
+
+    VertexData vd;
+    vd.setPosition(*mCenter);
+    vd.mTexCoord = cuv;
+
+    if (!(mTypeMask & HOLLOW_MASK) && !(mTypeMask & OPEN_MASK))
+    {
+        *pos++ = *mCenter;
+        *tc++ = cuv;
+        num_vertices++;
+    }
+
+    LL_CHECK_MEMORY
+
+    //if (partial_build)
+    //{
+    //  return TRUE;
+    //}
+
+    if (mTypeMask & HOLLOW_MASK)
+    {
+        if (mTypeMask & TOP_MASK)
+        {
+            // HOLLOW TOP
+            // Does it matter if it's open or closed? - djs
+
+            S32 pt1 = 0, pt2 = num_vertices - 1;
+            S32 i = 0;
+            while (pt2 - pt1 > 1)
+            {
+                // Use the profile points instead of the mesh, since you want
+                // the un-transformed profile distances.
+                const LLVector4a& p1 = profile[pt1];
+                const LLVector4a& p2 = profile[pt2];
+                const LLVector4a& pa = profile[pt1+1];
+                const LLVector4a& pb = profile[pt2-1];
+
+                const F32* p1V = p1.getF32ptr();
+                const F32* p2V = p2.getF32ptr();
+                const F32* paV = pa.getF32ptr();
+                const F32* pbV = pb.getF32ptr();
+
+                //p1.mV[VZ] = 0.f;
+                //p2.mV[VZ] = 0.f;
+                //pa.mV[VZ] = 0.f;
+                //pb.mV[VZ] = 0.f;
+
+                // Use area of triangle to determine backfacing
+                F32 area_1a2, area_1ba, area_21b, area_2ab;
+                area_1a2 =  (p1V[0]*paV[1] - paV[0]*p1V[1]) +
+                            (paV[0]*p2V[1] - p2V[0]*paV[1]) +
+                            (p2V[0]*p1V[1] - p1V[0]*p2V[1]);
+
+                area_1ba =  (p1V[0]*pbV[1] - pbV[0]*p1V[1]) +
+                            (pbV[0]*paV[1] - paV[0]*pbV[1]) +
+                            (paV[0]*p1V[1] - p1V[0]*paV[1]);
+
+                area_21b =  (p2V[0]*p1V[1] - p1V[0]*p2V[1]) +
+                            (p1V[0]*pbV[1] - pbV[0]*p1V[1]) +
+                            (pbV[0]*p2V[1] - p2V[0]*pbV[1]);
+
+                area_2ab =  (p2V[0]*paV[1] - paV[0]*p2V[1]) +
+                            (paV[0]*pbV[1] - pbV[0]*paV[1]) +
+                            (pbV[0]*p2V[1] - p2V[0]*pbV[1]);
+
+                BOOL use_tri1a2 = TRUE;
+                BOOL tri_1a2 = TRUE;
+                BOOL tri_21b = TRUE;
+
+                if (area_1a2 < 0)
+                {
+                    tri_1a2 = FALSE;
+                }
+                if (area_2ab < 0)
+                {
+                    // Can't use, because it contains point b
+                    tri_1a2 = FALSE;
+                }
+                if (area_21b < 0)
+                {
+                    tri_21b = FALSE;
+                }
+                if (area_1ba < 0)
+                {
+                    // Can't use, because it contains point b
+                    tri_21b = FALSE;
+                }
+
+                if (!tri_1a2)
+                {
+                    use_tri1a2 = FALSE;
+                }
+                else if (!tri_21b)
+                {
+                    use_tri1a2 = TRUE;
+                }
+                else
+                {
+                    LLVector4a d1;
+                    d1.setSub(p1, pa);
+
+                    LLVector4a d2;
+                    d2.setSub(p2, pb);
+
+                    if (d1.dot3(d1) < d2.dot3(d2))
+                    {
+                        use_tri1a2 = TRUE;
+                    }
+                    else
+                    {
+                        use_tri1a2 = FALSE;
+                    }
+                }
+
+                if (use_tri1a2)
+                {
+                    mIndices[i++] = pt1;
+                    mIndices[i++] = pt1 + 1;
+                    mIndices[i++] = pt2;
+                    pt1++;
+                }
+                else
+                {
+                    mIndices[i++] = pt1;
+                    mIndices[i++] = pt2 - 1;
+                    mIndices[i++] = pt2;
+                    pt2--;
+                }
+            }
+        }
+        else
+        {
+            // HOLLOW BOTTOM
+            // Does it matter if it's open or closed? - djs
+
+            llassert(mTypeMask & BOTTOM_MASK);
+            S32 pt1 = 0, pt2 = num_vertices - 1;
+
+            S32 i = 0;
+            while (pt2 - pt1 > 1)
+            {
+                // Use the profile points instead of the mesh, since you want
+                // the un-transformed profile distances.
+                const LLVector4a& p1 = profile[pt1];
+                const LLVector4a& p2 = profile[pt2];
+                const LLVector4a& pa = profile[pt1+1];
+                const LLVector4a& pb = profile[pt2-1];
+
+                const F32* p1V = p1.getF32ptr();
+                const F32* p2V = p2.getF32ptr();
+                const F32* paV = pa.getF32ptr();
+                const F32* pbV = pb.getF32ptr();
+
+                // Use area of triangle to determine backfacing
+                F32 area_1a2, area_1ba, area_21b, area_2ab;
+                area_1a2 =  (p1V[0]*paV[1] - paV[0]*p1V[1]) +
+                            (paV[0]*p2V[1] - p2V[0]*paV[1]) +
+                            (p2V[0]*p1V[1] - p1V[0]*p2V[1]);
+
+                area_1ba =  (p1V[0]*pbV[1] - pbV[0]*p1V[1]) +
+                            (pbV[0]*paV[1] - paV[0]*pbV[1]) +
+                            (paV[0]*p1V[1] - p1V[0]*paV[1]);
+
+                area_21b =  (p2V[0]*p1V[1] - p1V[0]*p2V[1]) +
+                            (p1V[0]*pbV[1] - pbV[0]*p1V[1]) +
+                            (pbV[0]*p2V[1] - p2V[0]*pbV[1]);
+
+                area_2ab =  (p2V[0]*paV[1] - paV[0]*p2V[1]) +
+                            (paV[0]*pbV[1] - pbV[0]*paV[1]) +
+                            (pbV[0]*p2V[1] - p2V[0]*pbV[1]);
+
+                BOOL use_tri1a2 = TRUE;
+                BOOL tri_1a2 = TRUE;
+                BOOL tri_21b = TRUE;
+
+                if (area_1a2 < 0)
+                {
+                    tri_1a2 = FALSE;
+                }
+                if (area_2ab < 0)
+                {
+                    // Can't use, because it contains point b
+                    tri_1a2 = FALSE;
+                }
+                if (area_21b < 0)
+                {
+                    tri_21b = FALSE;
+                }
+                if (area_1ba < 0)
+                {
+                    // Can't use, because it contains point b
+                    tri_21b = FALSE;
+                }
+
+                if (!tri_1a2)
+                {
+                    use_tri1a2 = FALSE;
+                }
+                else if (!tri_21b)
+                {
+                    use_tri1a2 = TRUE;
+                }
+                else
+                {
+                    LLVector4a d1;
+                    d1.setSub(p1,pa);
+                    LLVector4a d2;
+                    d2.setSub(p2,pb);
+
+                    if (d1.dot3(d1) < d2.dot3(d2))
+                    {
+                        use_tri1a2 = TRUE;
+                    }
+                    else
+                    {
+                        use_tri1a2 = FALSE;
+                    }
+                }
+
+                // Flipped backfacing from top
+                if (use_tri1a2)
+                {
+                    mIndices[i++] = pt1;
+                    mIndices[i++] = pt2;
+                    mIndices[i++] = pt1 + 1;
+                    pt1++;
+                }
+                else
+                {
+                    mIndices[i++] = pt1;
+                    mIndices[i++] = pt2;
+                    mIndices[i++] = pt2 - 1;
+                    pt2--;
+                }
+            }
+        }
+    }
+    else
+    {
+        // Not hollow, generate the triangle fan.
+        U16 v1 = 2;
+        U16 v2 = 1;
+
+        if (mTypeMask & TOP_MASK)
+        {
+            v1 = 1;
+            v2 = 2;
+        }
+
+        for (S32 i = 0; i < (num_vertices - 2); i++)
+        {
+            mIndices[3*i] = num_vertices - 1;
+            mIndices[3*i+v1] = i;
+            mIndices[3*i+v2] = i + 1;
+        }
+
+
+    }
+
+    LLVector4a d0,d1;
+    LL_CHECK_MEMORY
+
+
+    d0.setSub(mPositions[mIndices[1]], mPositions[mIndices[0]]);
+    d1.setSub(mPositions[mIndices[2]], mPositions[mIndices[0]]);
+
+    LLVector4a normal;
+    normal.setCross3(d0,d1);
+
+    if (normal.dot3(normal).getF32() > F_APPROXIMATELY_ZERO)
+    {
+        normal.normalize3fast();
+    }
+    else
+    { //degenerate, make up a value
+        if(normal.getF32ptr()[2] >= 0)
+            normal.set(0.f,0.f,1.f);
+        else
+            normal.set(0.f,0.f,-1.f);
+    }
+
+    llassert(llfinite(normal.getF32ptr()[0]));
+    llassert(llfinite(normal.getF32ptr()[1]));
+    llassert(llfinite(normal.getF32ptr()[2]));
+
+    llassert(!llisnan(normal.getF32ptr()[0]));
+    llassert(!llisnan(normal.getF32ptr()[1]));
+    llassert(!llisnan(normal.getF32ptr()[2]));
+
+    for (S32 i = 0; i < num_vertices; i++)
+    {
+        norm[i].load4a(normal.getF32ptr());
+    }
+
+    return TRUE;
 }
 
 void LLVolumeFace::createTangents()
@@ -6391,7 +6391,7 @@ void LLVolumeFace::createTangents()
     if (!mTangents)
     {
         allocateTangents(mNumVertices);
-        
+
         //generate tangents
         LLVector4a* ptr = (LLVector4a*)mTangents;
 
@@ -6415,29 +6415,29 @@ void LLVolumeFace::createTangents()
 
 void LLVolumeFace::resizeVertices(S32 num_verts)
 {
-	ll_aligned_free<64>(mPositions);
-	//DO NOT free mNormals and mTexCoords as they are part of mPositions buffer
-	ll_aligned_free_16(mTangents);
+    ll_aligned_free<64>(mPositions);
+    //DO NOT free mNormals and mTexCoords as they are part of mPositions buffer
+    ll_aligned_free_16(mTangents);
 
-	mTangents = NULL;
+    mTangents = NULL;
 
-	if (num_verts)
-	{
-		//pad texture coordinate block end to allow for QWORD reads
-		S32 tc_size = ((num_verts*sizeof(LLVector2)) + 0xF) & ~0xF;
+    if (num_verts)
+    {
+        //pad texture coordinate block end to allow for QWORD reads
+        S32 tc_size = ((num_verts*sizeof(LLVector2)) + 0xF) & ~0xF;
 
-		mPositions = (LLVector4a*) ll_aligned_malloc<64>(sizeof(LLVector4a)*2*num_verts+tc_size);
-		mNormals = mPositions+num_verts;
-		mTexCoords = (LLVector2*) (mNormals+num_verts);
+        mPositions = (LLVector4a*) ll_aligned_malloc<64>(sizeof(LLVector4a)*2*num_verts+tc_size);
+        mNormals = mPositions+num_verts;
+        mTexCoords = (LLVector2*) (mNormals+num_verts);
 
-		ll_assert_aligned(mPositions, 64);
-	}
-	else
-	{
-		mPositions = NULL;
-		mNormals = NULL;
-		mTexCoords = NULL;
-	}
+        ll_assert_aligned(mPositions, 64);
+    }
+    else
+    {
+        mPositions = NULL;
+        mNormals = NULL;
+        mTexCoords = NULL;
+    }
 
 
     if (mPositions)
@@ -6458,70 +6458,70 @@ void LLVolumeFace::resizeVertices(S32 num_verts)
 
 void LLVolumeFace::pushVertex(const LLVolumeFace::VertexData& cv)
 {
-	pushVertex(cv.getPosition(), cv.getNormal(), cv.mTexCoord);
+    pushVertex(cv.getPosition(), cv.getNormal(), cv.mTexCoord);
 }
 
 void LLVolumeFace::pushVertex(const LLVector4a& pos, const LLVector4a& norm, const LLVector2& tc)
 {
-	S32 new_verts = mNumVertices+1;
+    S32 new_verts = mNumVertices+1;
+
+    if (new_verts > mNumAllocatedVertices)
+    {
+        // double buffer size on expansion
+        new_verts *= 2;
 
-	if (new_verts > mNumAllocatedVertices)
-	{ 
-		// double buffer size on expansion
-		new_verts *= 2;
+        S32 new_tc_size = ((new_verts*8)+0xF) & ~0xF;
+        S32 old_tc_size = ((mNumVertices*8)+0xF) & ~0xF;
 
-		S32 new_tc_size = ((new_verts*8)+0xF) & ~0xF;
-		S32 old_tc_size = ((mNumVertices*8)+0xF) & ~0xF;
+        S32 old_vsize = mNumVertices*16;
 
-		S32 old_vsize = mNumVertices*16;
-		
-		S32 new_size = new_verts*16*2+new_tc_size;
+        S32 new_size = new_verts*16*2+new_tc_size;
 
-		LLVector4a* old_buf = mPositions;
+        LLVector4a* old_buf = mPositions;
 
-		mPositions = (LLVector4a*) ll_aligned_malloc<64>(new_size);
-		mNormals = mPositions+new_verts;
-		mTexCoords = (LLVector2*) (mNormals+new_verts);
+        mPositions = (LLVector4a*) ll_aligned_malloc<64>(new_size);
+        mNormals = mPositions+new_verts;
+        mTexCoords = (LLVector2*) (mNormals+new_verts);
 
-		if (old_buf != NULL)
-		{
-			// copy old positions into new buffer
-			LLVector4a::memcpyNonAliased16((F32*)mPositions, (F32*)old_buf, old_vsize);
+        if (old_buf != NULL)
+        {
+            // copy old positions into new buffer
+            LLVector4a::memcpyNonAliased16((F32*)mPositions, (F32*)old_buf, old_vsize);
 
-			// normals
-			LLVector4a::memcpyNonAliased16((F32*)mNormals, (F32*)(old_buf + mNumVertices), old_vsize);
+            // normals
+            LLVector4a::memcpyNonAliased16((F32*)mNormals, (F32*)(old_buf + mNumVertices), old_vsize);
 
-			// tex coords
-			LLVector4a::memcpyNonAliased16((F32*)mTexCoords, (F32*)(old_buf + mNumVertices * 2), old_tc_size);
-		}
+            // tex coords
+            LLVector4a::memcpyNonAliased16((F32*)mTexCoords, (F32*)(old_buf + mNumVertices * 2), old_tc_size);
+        }
 
-		// just clear tangents
-		ll_aligned_free_16(mTangents);
-		mTangents = NULL;
-		ll_aligned_free<64>(old_buf);
+        // just clear tangents
+        ll_aligned_free_16(mTangents);
+        mTangents = NULL;
+        ll_aligned_free<64>(old_buf);
 
-		mNumAllocatedVertices = new_verts;
+        mNumAllocatedVertices = new_verts;
 
-	}
+    }
 
-	mPositions[mNumVertices] = pos;
-	mNormals[mNumVertices] = norm;
-	mTexCoords[mNumVertices] = tc;
+    mPositions[mNumVertices] = pos;
+    mNormals[mNumVertices] = norm;
+    mTexCoords[mNumVertices] = tc;
 
-	mNumVertices++;	
+    mNumVertices++;
 }
 
 void LLVolumeFace::allocateTangents(S32 num_verts)
 {
-	ll_aligned_free_16(mTangents);
-	mTangents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
+    ll_aligned_free_16(mTangents);
+    mTangents = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
 }
 
 void LLVolumeFace::allocateWeights(S32 num_verts)
 {
-	ll_aligned_free_16(mWeights);
-	mWeights = (LLVector4a*)ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
-    
+    ll_aligned_free_16(mWeights);
+    mWeights = (LLVector4a*)ll_aligned_malloc_16(sizeof(LLVector4a)*num_verts);
+
 }
 
 void LLVolumeFace::allocateJointIndices(S32 num_verts)
@@ -6530,27 +6530,27 @@ void LLVolumeFace::allocateJointIndices(S32 num_verts)
     ll_aligned_free_16(mJointIndices);
     ll_aligned_free_16(mJustWeights);
 
-    mJointIndices = (U8*)ll_aligned_malloc_16(sizeof(U8) * 4 * num_verts);    
-    mJustWeights = (LLVector4a*)ll_aligned_malloc_16(sizeof(LLVector4a) * num_verts);    
+    mJointIndices = (U8*)ll_aligned_malloc_16(sizeof(U8) * 4 * num_verts);
+    mJustWeights = (LLVector4a*)ll_aligned_malloc_16(sizeof(LLVector4a) * num_verts);
 #endif
 }
 
 void LLVolumeFace::resizeIndices(S32 num_indices)
 {
-	ll_aligned_free_16(mIndices);
+    ll_aligned_free_16(mIndices);
     llassert(num_indices % 3 == 0);
-	
-	if (num_indices)
-	{
-		//pad index block end to allow for QWORD reads
-		S32 size = ((num_indices*sizeof(U16)) + 0xF) & ~0xF;
-		
-		mIndices = (U16*) ll_aligned_malloc_16(size);
-	}
-	else
-	{
-		mIndices = NULL;
-	}
+
+    if (num_indices)
+    {
+        //pad index block end to allow for QWORD reads
+        S32 size = ((num_indices*sizeof(U16)) + 0xF) & ~0xF;
+
+        mIndices = (U16*) ll_aligned_malloc_16(size);
+    }
+    else
+    {
+        mIndices = NULL;
+    }
 
     if (mIndices)
     {
@@ -6565,73 +6565,73 @@ void LLVolumeFace::resizeIndices(S32 num_indices)
 
 void LLVolumeFace::pushIndex(const U16& idx)
 {
-	S32 new_count = mNumIndices + 1;
-	S32 new_size = ((new_count*2)+0xF) & ~0xF;
+    S32 new_count = mNumIndices + 1;
+    S32 new_size = ((new_count*2)+0xF) & ~0xF;
+
+    S32 old_size = ((mNumIndices*2)+0xF) & ~0xF;
+    if (new_size != old_size)
+    {
+        mIndices = (U16*) ll_aligned_realloc_16(mIndices, new_size, old_size);
+        ll_assert_aligned(mIndices,16);
+    }
 
-	S32 old_size = ((mNumIndices*2)+0xF) & ~0xF;
-	if (new_size != old_size)
-	{
-		mIndices = (U16*) ll_aligned_realloc_16(mIndices, new_size, old_size);
-		ll_assert_aligned(mIndices,16);
-	}
-	
-	mIndices[mNumIndices++] = idx;
+    mIndices[mNumIndices++] = idx;
 }
 
 void LLVolumeFace::fillFromLegacyData(std::vector<LLVolumeFace::VertexData>& v, std::vector<U16>& idx)
 {
-	resizeVertices(v.size());
-	resizeIndices(idx.size());
+    resizeVertices(v.size());
+    resizeIndices(idx.size());
 
-	for (U32 i = 0; i < v.size(); ++i)
-	{
-		mPositions[i] = v[i].getPosition();
-		mNormals[i] = v[i].getNormal();
-		mTexCoords[i] = v[i].mTexCoord;
-	}
+    for (U32 i = 0; i < v.size(); ++i)
+    {
+        mPositions[i] = v[i].getPosition();
+        mNormals[i] = v[i].getNormal();
+        mTexCoords[i] = v[i].mTexCoord;
+    }
 
-	for (U32 i = 0; i < idx.size(); ++i)
-	{
-		mIndices[i] = idx[i];
-	}
+    for (U32 i = 0; i < idx.size(); ++i)
+    {
+        mIndices[i] = idx[i];
+    }
 }
 
 BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
+
+    LL_CHECK_MEMORY
+    BOOL flat = mTypeMask & FLAT_MASK;
 
-	LL_CHECK_MEMORY
-	BOOL flat = mTypeMask & FLAT_MASK;
+    U8 sculpt_type = volume->getParams().getSculptType();
+    U8 sculpt_stitching = sculpt_type & LL_SCULPT_TYPE_MASK;
+    BOOL sculpt_invert = sculpt_type & LL_SCULPT_FLAG_INVERT;
+    BOOL sculpt_mirror = sculpt_type & LL_SCULPT_FLAG_MIRROR;
+    BOOL sculpt_reverse_horizontal = (sculpt_invert ? !sculpt_mirror : sculpt_mirror);  // XOR
 
-	U8 sculpt_type = volume->getParams().getSculptType();
-	U8 sculpt_stitching = sculpt_type & LL_SCULPT_TYPE_MASK;
-	BOOL sculpt_invert = sculpt_type & LL_SCULPT_FLAG_INVERT;
-	BOOL sculpt_mirror = sculpt_type & LL_SCULPT_FLAG_MIRROR;
-	BOOL sculpt_reverse_horizontal = (sculpt_invert ? !sculpt_mirror : sculpt_mirror);  // XOR
-	
-	S32 num_vertices, num_indices;
+    S32 num_vertices, num_indices;
 
-	const LLAlignedArray<LLVector4a,64>& mesh = volume->getMesh();
-	const LLAlignedArray<LLVector4a,64>& profile = volume->getProfile().mProfile;
-	const LLAlignedArray<LLPath::PathPt,64>& path_data = volume->getPath().mPath;
+    const LLAlignedArray<LLVector4a,64>& mesh = volume->getMesh();
+    const LLAlignedArray<LLVector4a,64>& profile = volume->getProfile().mProfile;
+    const LLAlignedArray<LLPath::PathPt,64>& path_data = volume->getPath().mPath;
 
-	S32 max_s = volume->getProfile().getTotal();
+    S32 max_s = volume->getProfile().getTotal();
 
-	S32 s, t, i;
-	F32 ss, tt;
+    S32 s, t, i;
+    F32 ss, tt;
 
-	num_vertices = mNumS*mNumT;
-	num_indices = (mNumS-1)*(mNumT-1)*6;
+    num_vertices = mNumS*mNumT;
+    num_indices = (mNumS-1)*(mNumT-1)*6;
 
-	partial_build = (num_vertices > mNumVertices || num_indices > mNumIndices) ? FALSE : partial_build;
+    partial_build = (num_vertices > mNumVertices || num_indices > mNumIndices) ? FALSE : partial_build;
 
-	if (!partial_build)
-	{
-		resizeVertices(num_vertices);
-		resizeIndices(num_indices);
+    if (!partial_build)
+    {
+        resizeVertices(num_vertices);
+        resizeIndices(num_indices);
 
-		if (!volume->isMeshAssetLoaded())
-		{
+        if (!volume->isMeshAssetLoaded())
+        {
             try
             {
                 mEdge.resize(num_indices);
@@ -6641,237 +6641,237 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build)
                 LL_WARNS("LLVOLUME") << "Resize of mEdge to " << num_indices << " failed" << LL_ENDL;
                 return false;
             }
-		}
-	}
-
-	LL_CHECK_MEMORY
-
-	LLVector4a* pos = (LLVector4a*) mPositions;
-	LLVector2* tc = (LLVector2*) mTexCoords;
-	F32 begin_stex = floorf(profile[mBeginS][2]);
-	S32 num_s = ((mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2) ? mNumS/2 : mNumS;
-
-	S32 cur_vertex = 0;
-	S32 end_t = mBeginT+mNumT;
-	bool test = (mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2;
-
-	// Copy the vertices into the array
-	for (t = mBeginT; t < end_t; t++)
-	{
-		tt = path_data[t].mTexT;
-		for (s = 0; s < num_s; s++)
-		{
-			if (mTypeMask & END_MASK)
-			{
-				if (s)
-				{
-					ss = 1.f;
-				}
-				else
-				{
-					ss = 0.f;
-				}
-			}
-			else
-			{
-				// Get s value for tex-coord.
+        }
+    }
+
+    LL_CHECK_MEMORY
+
+    LLVector4a* pos = (LLVector4a*) mPositions;
+    LLVector2* tc = (LLVector2*) mTexCoords;
+    F32 begin_stex = floorf(profile[mBeginS][2]);
+    S32 num_s = ((mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2) ? mNumS/2 : mNumS;
+
+    S32 cur_vertex = 0;
+    S32 end_t = mBeginT+mNumT;
+    bool test = (mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2;
+
+    // Copy the vertices into the array
+    for (t = mBeginT; t < end_t; t++)
+    {
+        tt = path_data[t].mTexT;
+        for (s = 0; s < num_s; s++)
+        {
+            if (mTypeMask & END_MASK)
+            {
+                if (s)
+                {
+                    ss = 1.f;
+                }
+                else
+                {
+                    ss = 0.f;
+                }
+            }
+            else
+            {
+                // Get s value for tex-coord.
                 S32 index = mBeginS + s;
                 if (index >= profile.size())
                 {
                     // edge?
                     ss = flat ? 1.f - begin_stex : 1.f;
                 }
-				else if (!flat)
-				{
-					ss = profile[index][2];
-				}
-				else
-				{
-					ss = profile[index][2] - begin_stex;
-				}
-			}
-
-			if (sculpt_reverse_horizontal)
-			{
-				ss = 1.f - ss;
-			}
-			
-			// Check to see if this triangle wraps around the array.
-			if (mBeginS + s >= max_s)
-			{
-				// We're wrapping
-				i = mBeginS + s + max_s*(t-1);
-			}
-			else
-			{
-				i = mBeginS + s + max_s*t;
-			}
-
-			mesh[i].store4a((F32*)(pos+cur_vertex));
-			tc[cur_vertex].set(ss,tt);
-		
-			cur_vertex++;
-
-			if (test && s > 0)
-			{
-				mesh[i].store4a((F32*)(pos+cur_vertex));
-				tc[cur_vertex].set(ss,tt);
-				cur_vertex++;
-			}
-		}
-		
-		if ((mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2)
-		{
-			if (mTypeMask & OPEN_MASK)
-			{
-				s = num_s-1;
-			}
-			else
-			{
-				s = 0;
-			}
-
-			i = mBeginS + s + max_s*t;
-			ss = profile[mBeginS + s][2] - begin_stex;
-
-			mesh[i].store4a((F32*)(pos+cur_vertex));
-			tc[cur_vertex].set(ss,tt);
-			
-			cur_vertex++;
-		}
-	}	
-	LL_CHECK_MEMORY
-	
-	mCenter->clear();
-
-	LLVector4a* cur_pos = pos;
-	LLVector4a* end_pos = pos + mNumVertices;
-
-	//get bounding box for this side
-	LLVector4a face_min;
-	LLVector4a face_max;
-	
-	face_min = face_max = *cur_pos++;
-		
-	while (cur_pos < end_pos)
-	{
-		update_min_max(face_min, face_max, *cur_pos++);
-	}
-	// VFExtents change
-	mExtents[0] = face_min;
-	mExtents[1] = face_max;
-
-	U32 tc_count = mNumVertices;
-	if (tc_count%2 == 1)
-	{ //odd number of texture coordinates, duplicate last entry to padded end of array
-		tc_count++;
-		mTexCoords[mNumVertices] = mTexCoords[mNumVertices-1];
-	}
-
-	LLVector4a* cur_tc = (LLVector4a*) mTexCoords;
-	LLVector4a* end_tc = (LLVector4a*) (mTexCoords+tc_count);
-
-	LLVector4a tc_min; 
-	LLVector4a tc_max; 
-
-	tc_min = tc_max = *cur_tc++;
-
-	while (cur_tc < end_tc)
-	{
-		update_min_max(tc_min, tc_max, *cur_tc++);
-	}
-
-	F32* minp = tc_min.getF32ptr();
-	F32* maxp = tc_max.getF32ptr();
-
-	mTexCoordExtents[0].mV[0] = llmin(minp[0], minp[2]);
-	mTexCoordExtents[0].mV[1] = llmin(minp[1], minp[3]);
-	mTexCoordExtents[1].mV[0] = llmax(maxp[0], maxp[2]);
-	mTexCoordExtents[1].mV[1] = llmax(maxp[1], maxp[3]);
-
-	mCenter->setAdd(face_min, face_max);
-	mCenter->mul(0.5f);
-
-	S32 cur_index = 0;
-	S32 cur_edge = 0;
-	BOOL flat_face = mTypeMask & FLAT_MASK;
-
-	if (!partial_build)
-	{
-		// Now we generate the indices.
-		for (t = 0; t < (mNumT-1); t++)
-		{
-			for (s = 0; s < (mNumS-1); s++)
-			{	
-				mIndices[cur_index++] = s   + mNumS*t;			//bottom left
-				mIndices[cur_index++] = s+1 + mNumS*(t+1);		//top right
-				mIndices[cur_index++] = s   + mNumS*(t+1);		//top left
-				mIndices[cur_index++] = s   + mNumS*t;			//bottom left
-				mIndices[cur_index++] = s+1 + mNumS*t;			//bottom right
-				mIndices[cur_index++] = s+1 + mNumS*(t+1);		//top right
-
-				mEdge[cur_edge++] = (mNumS-1)*2*t+s*2+1;						//bottom left/top right neighbor face 
-				if (t < mNumT-2) {												//top right/top left neighbor face 
-					mEdge[cur_edge++] = (mNumS-1)*2*(t+1)+s*2+1;
-				}
-				else if (mNumT <= 3 || volume->getPath().isOpen() == TRUE) { //no neighbor
-					mEdge[cur_edge++] = -1;
-				}
-				else { //wrap on T
-					mEdge[cur_edge++] = s*2+1;
-				}
-				if (s > 0) {													//top left/bottom left neighbor face
-					mEdge[cur_edge++] = (mNumS-1)*2*t+s*2-1;
-				}
-				else if (flat_face ||  volume->getProfile().isOpen() == TRUE) { //no neighbor
-					mEdge[cur_edge++] = -1;
-				}
-				else {	//wrap on S
-					mEdge[cur_edge++] = (mNumS-1)*2*t+(mNumS-2)*2+1;
-				}
-				
-				if (t > 0) {													//bottom left/bottom right neighbor face
-					mEdge[cur_edge++] = (mNumS-1)*2*(t-1)+s*2;
-				}
-				else if (mNumT <= 3 || volume->getPath().isOpen() == TRUE) { //no neighbor
-					mEdge[cur_edge++] = -1;
-				}
-				else { //wrap on T
-					mEdge[cur_edge++] = (mNumS-1)*2*(mNumT-2)+s*2;
-				}
-				if (s < mNumS-2) {												//bottom right/top right neighbor face
-					mEdge[cur_edge++] = (mNumS-1)*2*t+(s+1)*2;
-				}
-				else if (flat_face || volume->getProfile().isOpen() == TRUE) { //no neighbor
-					mEdge[cur_edge++] = -1;
-				}
-				else { //wrap on S
-					mEdge[cur_edge++] = (mNumS-1)*2*t;
-				}
-				mEdge[cur_edge++] = (mNumS-1)*2*t+s*2;							//top right/bottom left neighbor face	
-			}
-		}
-	}
-
-	LL_CHECK_MEMORY
-
-	//clear normals
-	F32* dst = (F32*) mNormals;
-	F32* end = (F32*) (mNormals+mNumVertices);
-	LLVector4a zero = LLVector4a::getZero();
-
-	while (dst < end)
-	{
-		zero.store4a(dst);
-		dst += 4;
-	}
-
-	LL_CHECK_MEMORY
-
-	//generate normals 
-	U32 count = mNumIndices/3;
-
-	LLVector4a* norm = mNormals;
+                else if (!flat)
+                {
+                    ss = profile[index][2];
+                }
+                else
+                {
+                    ss = profile[index][2] - begin_stex;
+                }
+            }
+
+            if (sculpt_reverse_horizontal)
+            {
+                ss = 1.f - ss;
+            }
+
+            // Check to see if this triangle wraps around the array.
+            if (mBeginS + s >= max_s)
+            {
+                // We're wrapping
+                i = mBeginS + s + max_s*(t-1);
+            }
+            else
+            {
+                i = mBeginS + s + max_s*t;
+            }
+
+            mesh[i].store4a((F32*)(pos+cur_vertex));
+            tc[cur_vertex].set(ss,tt);
+
+            cur_vertex++;
+
+            if (test && s > 0)
+            {
+                mesh[i].store4a((F32*)(pos+cur_vertex));
+                tc[cur_vertex].set(ss,tt);
+                cur_vertex++;
+            }
+        }
+
+        if ((mTypeMask & INNER_MASK) && (mTypeMask & FLAT_MASK) && mNumS > 2)
+        {
+            if (mTypeMask & OPEN_MASK)
+            {
+                s = num_s-1;
+            }
+            else
+            {
+                s = 0;
+            }
+
+            i = mBeginS + s + max_s*t;
+            ss = profile[mBeginS + s][2] - begin_stex;
+
+            mesh[i].store4a((F32*)(pos+cur_vertex));
+            tc[cur_vertex].set(ss,tt);
+
+            cur_vertex++;
+        }
+    }
+    LL_CHECK_MEMORY
+
+    mCenter->clear();
+
+    LLVector4a* cur_pos = pos;
+    LLVector4a* end_pos = pos + mNumVertices;
+
+    //get bounding box for this side
+    LLVector4a face_min;
+    LLVector4a face_max;
+
+    face_min = face_max = *cur_pos++;
+
+    while (cur_pos < end_pos)
+    {
+        update_min_max(face_min, face_max, *cur_pos++);
+    }
+    // VFExtents change
+    mExtents[0] = face_min;
+    mExtents[1] = face_max;
+
+    U32 tc_count = mNumVertices;
+    if (tc_count%2 == 1)
+    { //odd number of texture coordinates, duplicate last entry to padded end of array
+        tc_count++;
+        mTexCoords[mNumVertices] = mTexCoords[mNumVertices-1];
+    }
+
+    LLVector4a* cur_tc = (LLVector4a*) mTexCoords;
+    LLVector4a* end_tc = (LLVector4a*) (mTexCoords+tc_count);
+
+    LLVector4a tc_min;
+    LLVector4a tc_max;
+
+    tc_min = tc_max = *cur_tc++;
+
+    while (cur_tc < end_tc)
+    {
+        update_min_max(tc_min, tc_max, *cur_tc++);
+    }
+
+    F32* minp = tc_min.getF32ptr();
+    F32* maxp = tc_max.getF32ptr();
+
+    mTexCoordExtents[0].mV[0] = llmin(minp[0], minp[2]);
+    mTexCoordExtents[0].mV[1] = llmin(minp[1], minp[3]);
+    mTexCoordExtents[1].mV[0] = llmax(maxp[0], maxp[2]);
+    mTexCoordExtents[1].mV[1] = llmax(maxp[1], maxp[3]);
+
+    mCenter->setAdd(face_min, face_max);
+    mCenter->mul(0.5f);
+
+    S32 cur_index = 0;
+    S32 cur_edge = 0;
+    BOOL flat_face = mTypeMask & FLAT_MASK;
+
+    if (!partial_build)
+    {
+        // Now we generate the indices.
+        for (t = 0; t < (mNumT-1); t++)
+        {
+            for (s = 0; s < (mNumS-1); s++)
+            {
+                mIndices[cur_index++] = s   + mNumS*t;          //bottom left
+                mIndices[cur_index++] = s+1 + mNumS*(t+1);      //top right
+                mIndices[cur_index++] = s   + mNumS*(t+1);      //top left
+                mIndices[cur_index++] = s   + mNumS*t;          //bottom left
+                mIndices[cur_index++] = s+1 + mNumS*t;          //bottom right
+                mIndices[cur_index++] = s+1 + mNumS*(t+1);      //top right
+
+                mEdge[cur_edge++] = (mNumS-1)*2*t+s*2+1;                        //bottom left/top right neighbor face
+                if (t < mNumT-2) {                                              //top right/top left neighbor face
+                    mEdge[cur_edge++] = (mNumS-1)*2*(t+1)+s*2+1;
+                }
+                else if (mNumT <= 3 || volume->getPath().isOpen() == TRUE) { //no neighbor
+                    mEdge[cur_edge++] = -1;
+                }
+                else { //wrap on T
+                    mEdge[cur_edge++] = s*2+1;
+                }
+                if (s > 0) {                                                    //top left/bottom left neighbor face
+                    mEdge[cur_edge++] = (mNumS-1)*2*t+s*2-1;
+                }
+                else if (flat_face ||  volume->getProfile().isOpen() == TRUE) { //no neighbor
+                    mEdge[cur_edge++] = -1;
+                }
+                else {  //wrap on S
+                    mEdge[cur_edge++] = (mNumS-1)*2*t+(mNumS-2)*2+1;
+                }
+
+                if (t > 0) {                                                    //bottom left/bottom right neighbor face
+                    mEdge[cur_edge++] = (mNumS-1)*2*(t-1)+s*2;
+                }
+                else if (mNumT <= 3 || volume->getPath().isOpen() == TRUE) { //no neighbor
+                    mEdge[cur_edge++] = -1;
+                }
+                else { //wrap on T
+                    mEdge[cur_edge++] = (mNumS-1)*2*(mNumT-2)+s*2;
+                }
+                if (s < mNumS-2) {                                              //bottom right/top right neighbor face
+                    mEdge[cur_edge++] = (mNumS-1)*2*t+(s+1)*2;
+                }
+                else if (flat_face || volume->getProfile().isOpen() == TRUE) { //no neighbor
+                    mEdge[cur_edge++] = -1;
+                }
+                else { //wrap on S
+                    mEdge[cur_edge++] = (mNumS-1)*2*t;
+                }
+                mEdge[cur_edge++] = (mNumS-1)*2*t+s*2;                          //top right/bottom left neighbor face
+            }
+        }
+    }
+
+    LL_CHECK_MEMORY
+
+    //clear normals
+    F32* dst = (F32*) mNormals;
+    F32* end = (F32*) (mNormals+mNumVertices);
+    LLVector4a zero = LLVector4a::getZero();
+
+    while (dst < end)
+    {
+        zero.store4a(dst);
+        dst += 4;
+    }
+
+    LL_CHECK_MEMORY
+
+    //generate normals
+    U32 count = mNumIndices/3;
+
+    LLVector4a* norm = mNormals;
 
     static thread_local LLAlignedArray<LLVector4a, 64> triangle_normals;
     try
@@ -6883,242 +6883,242 @@ BOOL LLVolumeFace::createSide(LLVolume* volume, BOOL partial_build)
         LL_WARNS("LLVOLUME") << "Resize of triangle_normals to " << count << " failed" << LL_ENDL;
         return false;
     }
-	LLVector4a* output = triangle_normals.mArray;
-	LLVector4a* end_output = output+count;
-
-	U16* idx = mIndices;
-
-	while (output < end_output)
-	{
-		LLVector4a b,v1,v2;
-		b.load4a((F32*) (pos+idx[0]));
-		v1.load4a((F32*) (pos+idx[1]));
-		v2.load4a((F32*) (pos+idx[2]));
-		
-		//calculate triangle normal
-		LLVector4a a;
-		
-		a.setSub(b, v1);
-		b.sub(v2);
-
-
-		LLQuad& vector1 = *((LLQuad*) &v1);
-		LLQuad& vector2 = *((LLQuad*) &v2);
-		
-		LLQuad& amQ = *((LLQuad*) &a);
-		LLQuad& bmQ = *((LLQuad*) &b);
-
-		//v1.setCross3(t,v0);
-		//setCross3(const LLVector4a& a, const LLVector4a& b)
-		// Vectors are stored in memory in w, z, y, x order from high to low
-		// Set vector1 = { a[W], a[X], a[Z], a[Y] }
-		vector1 = _mm_shuffle_ps( amQ, amQ, _MM_SHUFFLE( 3, 0, 2, 1 ));
-		// Set vector2 = { b[W], b[Y], b[X], b[Z] }
-		vector2 = _mm_shuffle_ps( bmQ, bmQ, _MM_SHUFFLE( 3, 1, 0, 2 ));
-		// mQ = { a[W]*b[W], a[X]*b[Y], a[Z]*b[X], a[Y]*b[Z] }
-		vector2 = _mm_mul_ps( vector1, vector2 );
-		// vector3 = { a[W], a[Y], a[X], a[Z] }
-		amQ = _mm_shuffle_ps( amQ, amQ, _MM_SHUFFLE( 3, 1, 0, 2 ));
-		// vector4 = { b[W], b[X], b[Z], b[Y] }
-		bmQ = _mm_shuffle_ps( bmQ, bmQ, _MM_SHUFFLE( 3, 0, 2, 1 ));
-		// mQ = { 0, a[X]*b[Y] - a[Y]*b[X], a[Z]*b[X] - a[X]*b[Z], a[Y]*b[Z] - a[Z]*b[Y] }
-		vector1 = _mm_sub_ps( vector2, _mm_mul_ps( amQ, bmQ ));
-
-		llassert(v1.isFinite3());
-
-		v1.store4a((F32*) output);
-		
-		
-		output++;
-		idx += 3;
-	}
-
-	idx = mIndices;
-
-	LLVector4a* src = triangle_normals.mArray;
-	
-	for (U32 i = 0; i < count; i++) //for each triangle
-	{
-		LLVector4a c;
-		c.load4a((F32*) (src++));
-
-		LLVector4a* n0p = norm+idx[0];
-		LLVector4a* n1p = norm+idx[1];
-		LLVector4a* n2p = norm+idx[2];
-		
-		idx += 3;
-
-		LLVector4a n0,n1,n2;
-		n0.load4a((F32*) n0p);
-		n1.load4a((F32*) n1p);
-		n2.load4a((F32*) n2p);
-		
-		n0.add(c);
-		n1.add(c);
-		n2.add(c);
-
-		llassert(c.isFinite3());
-
-		//even out quad contributions
-		switch (i%2+1)
-		{
-			case 0: n0.add(c); break;
-			case 1: n1.add(c); break;
-			case 2: n2.add(c); break;
-		};
-
-		n0.store4a((F32*) n0p);
-		n1.store4a((F32*) n1p);
-		n2.store4a((F32*) n2p);
-	}
-	
-	LL_CHECK_MEMORY
-
-	// adjust normals based on wrapping and stitching
-	
-	LLVector4a top;
-	top.setSub(pos[0], pos[mNumS*(mNumT-2)]);
-	BOOL s_bottom_converges = (top.dot3(top) < 0.000001f);
-
-	top.setSub(pos[mNumS-1], pos[mNumS*(mNumT-2)+mNumS-1]);
-	BOOL s_top_converges = (top.dot3(top) < 0.000001f);
-
-	if (sculpt_stitching == LL_SCULPT_TYPE_NONE)  // logic for non-sculpt volumes
-	{
-		if (volume->getPath().isOpen() == FALSE)
-		{ //wrap normals on T
-			for (S32 i = 0; i < mNumS; i++)
-			{
-				LLVector4a n;
-				n.setAdd(norm[i], norm[mNumS*(mNumT-1)+i]);
-				norm[i] = n;
-				norm[mNumS*(mNumT-1)+i] = n;
-			}
-		}
-
-		if ((volume->getProfile().isOpen() == FALSE) && !(s_bottom_converges))
-		{ //wrap normals on S
-			for (S32 i = 0; i < mNumT; i++)
-			{
-				LLVector4a n;
-				n.setAdd(norm[mNumS*i], norm[mNumS*i+mNumS-1]);
-				norm[mNumS * i] = n;
-				norm[mNumS * i+mNumS-1] = n;
-			}
-		}
-	
-		if (volume->getPathType() == LL_PCODE_PATH_CIRCLE &&
-			((volume->getProfileType() & LL_PCODE_PROFILE_MASK) == LL_PCODE_PROFILE_CIRCLE_HALF))
-		{
-			if (s_bottom_converges)
-			{ //all lower S have same normal
-				for (S32 i = 0; i < mNumT; i++)
-				{
-					norm[mNumS*i].set(1,0,0);
-				}
-			}
-
-			if (s_top_converges)
-			{ //all upper S have same normal
-				for (S32 i = 0; i < mNumT; i++)
-				{
-					norm[mNumS*i+mNumS-1].set(-1,0,0);
-				}
-			}
-		}
-	}
-	else  // logic for sculpt volumes
-	{
-		BOOL average_poles = FALSE;
-		BOOL wrap_s = FALSE;
-		BOOL wrap_t = FALSE;
-
-		if (sculpt_stitching == LL_SCULPT_TYPE_SPHERE)
-			average_poles = TRUE;
-
-		if ((sculpt_stitching == LL_SCULPT_TYPE_SPHERE) ||
-			(sculpt_stitching == LL_SCULPT_TYPE_TORUS) ||
-			(sculpt_stitching == LL_SCULPT_TYPE_CYLINDER))
-			wrap_s = TRUE;
-
-		if (sculpt_stitching == LL_SCULPT_TYPE_TORUS)
-			wrap_t = TRUE;
-			
-		
-		if (average_poles)
-		{
-			// average normals for north pole
-		
-			LLVector4a average;
-			average.clear();
-
-			for (S32 i = 0; i < mNumS; i++)
-			{
-				average.add(norm[i]);
-			}
-
-			// set average
-			for (S32 i = 0; i < mNumS; i++)
-			{
-				norm[i] = average;
-			}
-
-			// average normals for south pole
-		
-			average.clear();
-
-			for (S32 i = 0; i < mNumS; i++)
-			{
-				average.add(norm[i + mNumS * (mNumT - 1)]);
-			}
-
-			// set average
-			for (S32 i = 0; i < mNumS; i++)
-			{
-				norm[i + mNumS * (mNumT - 1)] = average;
-			}
-
-		}
-
-		
-		if (wrap_s)
-		{
-			for (S32 i = 0; i < mNumT; i++)
-			{
-				LLVector4a n;
-				n.setAdd(norm[mNumS*i], norm[mNumS*i+mNumS-1]);
-				norm[mNumS * i] = n;
-				norm[mNumS * i+mNumS-1] = n;
-			}
-		}
-
-		if (wrap_t)
-		{
-			for (S32 i = 0; i < mNumS; i++)
-			{
-				LLVector4a n;
-				n.setAdd(norm[i], norm[mNumS*(mNumT-1)+i]);
-				norm[i] = n;
-				norm[mNumS*(mNumT-1)+i] = n;
-			}
-		}
-
-	}
-
-	LL_CHECK_MEMORY
-
-	return TRUE;
+    LLVector4a* output = triangle_normals.mArray;
+    LLVector4a* end_output = output+count;
+
+    U16* idx = mIndices;
+
+    while (output < end_output)
+    {
+        LLVector4a b,v1,v2;
+        b.load4a((F32*) (pos+idx[0]));
+        v1.load4a((F32*) (pos+idx[1]));
+        v2.load4a((F32*) (pos+idx[2]));
+
+        //calculate triangle normal
+        LLVector4a a;
+
+        a.setSub(b, v1);
+        b.sub(v2);
+
+
+        LLQuad& vector1 = *((LLQuad*) &v1);
+        LLQuad& vector2 = *((LLQuad*) &v2);
+
+        LLQuad& amQ = *((LLQuad*) &a);
+        LLQuad& bmQ = *((LLQuad*) &b);
+
+        //v1.setCross3(t,v0);
+        //setCross3(const LLVector4a& a, const LLVector4a& b)
+        // Vectors are stored in memory in w, z, y, x order from high to low
+        // Set vector1 = { a[W], a[X], a[Z], a[Y] }
+        vector1 = _mm_shuffle_ps( amQ, amQ, _MM_SHUFFLE( 3, 0, 2, 1 ));
+        // Set vector2 = { b[W], b[Y], b[X], b[Z] }
+        vector2 = _mm_shuffle_ps( bmQ, bmQ, _MM_SHUFFLE( 3, 1, 0, 2 ));
+        // mQ = { a[W]*b[W], a[X]*b[Y], a[Z]*b[X], a[Y]*b[Z] }
+        vector2 = _mm_mul_ps( vector1, vector2 );
+        // vector3 = { a[W], a[Y], a[X], a[Z] }
+        amQ = _mm_shuffle_ps( amQ, amQ, _MM_SHUFFLE( 3, 1, 0, 2 ));
+        // vector4 = { b[W], b[X], b[Z], b[Y] }
+        bmQ = _mm_shuffle_ps( bmQ, bmQ, _MM_SHUFFLE( 3, 0, 2, 1 ));
+        // mQ = { 0, a[X]*b[Y] - a[Y]*b[X], a[Z]*b[X] - a[X]*b[Z], a[Y]*b[Z] - a[Z]*b[Y] }
+        vector1 = _mm_sub_ps( vector2, _mm_mul_ps( amQ, bmQ ));
+
+        llassert(v1.isFinite3());
+
+        v1.store4a((F32*) output);
+
+
+        output++;
+        idx += 3;
+    }
+
+    idx = mIndices;
+
+    LLVector4a* src = triangle_normals.mArray;
+
+    for (U32 i = 0; i < count; i++) //for each triangle
+    {
+        LLVector4a c;
+        c.load4a((F32*) (src++));
+
+        LLVector4a* n0p = norm+idx[0];
+        LLVector4a* n1p = norm+idx[1];
+        LLVector4a* n2p = norm+idx[2];
+
+        idx += 3;
+
+        LLVector4a n0,n1,n2;
+        n0.load4a((F32*) n0p);
+        n1.load4a((F32*) n1p);
+        n2.load4a((F32*) n2p);
+
+        n0.add(c);
+        n1.add(c);
+        n2.add(c);
+
+        llassert(c.isFinite3());
+
+        //even out quad contributions
+        switch (i%2+1)
+        {
+            case 0: n0.add(c); break;
+            case 1: n1.add(c); break;
+            case 2: n2.add(c); break;
+        };
+
+        n0.store4a((F32*) n0p);
+        n1.store4a((F32*) n1p);
+        n2.store4a((F32*) n2p);
+    }
+
+    LL_CHECK_MEMORY
+
+    // adjust normals based on wrapping and stitching
+
+    LLVector4a top;
+    top.setSub(pos[0], pos[mNumS*(mNumT-2)]);
+    BOOL s_bottom_converges = (top.dot3(top) < 0.000001f);
+
+    top.setSub(pos[mNumS-1], pos[mNumS*(mNumT-2)+mNumS-1]);
+    BOOL s_top_converges = (top.dot3(top) < 0.000001f);
+
+    if (sculpt_stitching == LL_SCULPT_TYPE_NONE)  // logic for non-sculpt volumes
+    {
+        if (volume->getPath().isOpen() == FALSE)
+        { //wrap normals on T
+            for (S32 i = 0; i < mNumS; i++)
+            {
+                LLVector4a n;
+                n.setAdd(norm[i], norm[mNumS*(mNumT-1)+i]);
+                norm[i] = n;
+                norm[mNumS*(mNumT-1)+i] = n;
+            }
+        }
+
+        if ((volume->getProfile().isOpen() == FALSE) && !(s_bottom_converges))
+        { //wrap normals on S
+            for (S32 i = 0; i < mNumT; i++)
+            {
+                LLVector4a n;
+                n.setAdd(norm[mNumS*i], norm[mNumS*i+mNumS-1]);
+                norm[mNumS * i] = n;
+                norm[mNumS * i+mNumS-1] = n;
+            }
+        }
+
+        if (volume->getPathType() == LL_PCODE_PATH_CIRCLE &&
+            ((volume->getProfileType() & LL_PCODE_PROFILE_MASK) == LL_PCODE_PROFILE_CIRCLE_HALF))
+        {
+            if (s_bottom_converges)
+            { //all lower S have same normal
+                for (S32 i = 0; i < mNumT; i++)
+                {
+                    norm[mNumS*i].set(1,0,0);
+                }
+            }
+
+            if (s_top_converges)
+            { //all upper S have same normal
+                for (S32 i = 0; i < mNumT; i++)
+                {
+                    norm[mNumS*i+mNumS-1].set(-1,0,0);
+                }
+            }
+        }
+    }
+    else  // logic for sculpt volumes
+    {
+        BOOL average_poles = FALSE;
+        BOOL wrap_s = FALSE;
+        BOOL wrap_t = FALSE;
+
+        if (sculpt_stitching == LL_SCULPT_TYPE_SPHERE)
+            average_poles = TRUE;
+
+        if ((sculpt_stitching == LL_SCULPT_TYPE_SPHERE) ||
+            (sculpt_stitching == LL_SCULPT_TYPE_TORUS) ||
+            (sculpt_stitching == LL_SCULPT_TYPE_CYLINDER))
+            wrap_s = TRUE;
+
+        if (sculpt_stitching == LL_SCULPT_TYPE_TORUS)
+            wrap_t = TRUE;
+
+
+        if (average_poles)
+        {
+            // average normals for north pole
+
+            LLVector4a average;
+            average.clear();
+
+            for (S32 i = 0; i < mNumS; i++)
+            {
+                average.add(norm[i]);
+            }
+
+            // set average
+            for (S32 i = 0; i < mNumS; i++)
+            {
+                norm[i] = average;
+            }
+
+            // average normals for south pole
+
+            average.clear();
+
+            for (S32 i = 0; i < mNumS; i++)
+            {
+                average.add(norm[i + mNumS * (mNumT - 1)]);
+            }
+
+            // set average
+            for (S32 i = 0; i < mNumS; i++)
+            {
+                norm[i + mNumS * (mNumT - 1)] = average;
+            }
+
+        }
+
+
+        if (wrap_s)
+        {
+            for (S32 i = 0; i < mNumT; i++)
+            {
+                LLVector4a n;
+                n.setAdd(norm[mNumS*i], norm[mNumS*i+mNumS-1]);
+                norm[mNumS * i] = n;
+                norm[mNumS * i+mNumS-1] = n;
+            }
+        }
+
+        if (wrap_t)
+        {
+            for (S32 i = 0; i < mNumS; i++)
+            {
+                LLVector4a n;
+                n.setAdd(norm[i], norm[mNumS*(mNumT-1)+i]);
+                norm[i] = n;
+                norm[mNumS*(mNumT-1)+i] = n;
+            }
+        }
+
+    }
+
+    LL_CHECK_MEMORY
+
+    return TRUE;
 }
 
 //adapted from Lengyel, Eric. "Computing Tangent Space Basis Vectors for an Arbitrary Mesh". Terathon Software 3D Graphics Library, 2001. http://www.terathon.com/code/tangent.html
 void LLCalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LLVector4a *normal,
         const LLVector2 *texcoord, U32 triangleCount, const U16* index_array, LLVector4a *tangent)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME
 
     //LLVector4a *tan1 = new LLVector4a[vertexCount * 2];
-	LLVector4a* tan1 = (LLVector4a*) ll_aligned_malloc_16(vertexCount*2*sizeof(LLVector4a));
-	// new(tan1) LLVector4a;
+    LLVector4a* tan1 = (LLVector4a*) ll_aligned_malloc_16(vertexCount*2*sizeof(LLVector4a));
+    // new(tan1) LLVector4a;
 
     LLVector4a* tan2 = tan1 + vertexCount;
 
@@ -7133,86 +7133,86 @@ void LLCalculateTangentArray(U32 vertexCount, const LLVector4a *vertex, const LL
         U32 i1 = *index_array++;
         U32 i2 = *index_array++;
         U32 i3 = *index_array++;
-        
+
         const LLVector4a& v1 = vertex[i1];
         const LLVector4a& v2 = vertex[i2];
         const LLVector4a& v3 = vertex[i3];
-        
+
         const LLVector2& w1 = texcoord[i1];
         const LLVector2& w2 = texcoord[i2];
         const LLVector2& w3 = texcoord[i3];
-        
-		const F32* v1ptr = v1.getF32ptr();
-		const F32* v2ptr = v2.getF32ptr();
-		const F32* v3ptr = v3.getF32ptr();
-		
+
+        const F32* v1ptr = v1.getF32ptr();
+        const F32* v2ptr = v2.getF32ptr();
+        const F32* v3ptr = v3.getF32ptr();
+
         float x1 = v2ptr[0] - v1ptr[0];
         float x2 = v3ptr[0] - v1ptr[0];
         float y1 = v2ptr[1] - v1ptr[1];
         float y2 = v3ptr[1] - v1ptr[1];
         float z1 = v2ptr[2] - v1ptr[2];
         float z2 = v3ptr[2] - v1ptr[2];
-        
+
         float s1 = w2.mV[0] - w1.mV[0];
         float s2 = w3.mV[0] - w1.mV[0];
         float t1 = w2.mV[1] - w1.mV[1];
         float t2 = w3.mV[1] - w1.mV[1];
-        
-		F32 rd = s1*t2-s2*t1;
-
-		float r = ((rd*rd) > FLT_EPSILON) ? (1.0f / rd)
-													 : ((rd > 0.0f) ? 1024.f : -1024.f); //some made up large ratio for division by zero
-
-		llassert(llfinite(r));
-		llassert(!llisnan(r));
-
-		LLVector4a sdir((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r,
-				(t2 * z1 - t1 * z2) * r);
-		LLVector4a tdir((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r,
-				(s1 * z2 - s2 * z1) * r);
-        
-		tan1[i1].add(sdir);
-		tan1[i2].add(sdir);
-		tan1[i3].add(sdir);
-        
-		tan2[i1].add(tdir);
-		tan2[i2].add(tdir);
-		tan2[i3].add(tdir);
-    }
-    
+
+        F32 rd = s1*t2-s2*t1;
+
+        float r = ((rd*rd) > FLT_EPSILON) ? (1.0f / rd)
+                                                     : ((rd > 0.0f) ? 1024.f : -1024.f); //some made up large ratio for division by zero
+
+        llassert(llfinite(r));
+        llassert(!llisnan(r));
+
+        LLVector4a sdir((t2 * x1 - t1 * x2) * r, (t2 * y1 - t1 * y2) * r,
+                (t2 * z1 - t1 * z2) * r);
+        LLVector4a tdir((s1 * x2 - s2 * x1) * r, (s1 * y2 - s2 * y1) * r,
+                (s1 * z2 - s2 * z1) * r);
+
+        tan1[i1].add(sdir);
+        tan1[i2].add(sdir);
+        tan1[i3].add(sdir);
+
+        tan2[i1].add(tdir);
+        tan2[i2].add(tdir);
+        tan2[i3].add(tdir);
+    }
+
     for (U32 a = 0; a < vertexCount; a++)
     {
         LLVector4a n = normal[a];
 
-		const LLVector4a& t = tan1[a];
+        const LLVector4a& t = tan1[a];
 
-		LLVector4a ncrosst;
-		ncrosst.setCross3(n,t);
+        LLVector4a ncrosst;
+        ncrosst.setCross3(n,t);
 
         // Gram-Schmidt orthogonalize
         n.mul(n.dot3(t).getF32());
 
-		LLVector4a tsubn;
-		tsubn.setSub(t,n);
-
-		if (tsubn.dot3(tsubn).getF32() > F_APPROXIMATELY_ZERO)
-		{
-			tsubn.normalize3fast();
-		
-			// Calculate handedness
-			F32 handedness = ncrosst.dot3(tan2[a]).getF32() < 0.f ? -1.f : 1.f;
-		
-			tsubn.getF32ptr()[3] = handedness;
-
-			tangent[a] = tsubn;
-		}
-		else
-		{ //degenerate, make up a value
-			tangent[a].set(0,0,1,1);
-		}
-    }
-    
-	ll_aligned_free_16(tan1);
+        LLVector4a tsubn;
+        tsubn.setSub(t,n);
+
+        if (tsubn.dot3(tsubn).getF32() > F_APPROXIMATELY_ZERO)
+        {
+            tsubn.normalize3fast();
+
+            // Calculate handedness
+            F32 handedness = ncrosst.dot3(tan2[a]).getF32() < 0.f ? -1.f : 1.f;
+
+            tsubn.getF32ptr()[3] = handedness;
+
+            tangent[a] = tsubn;
+        }
+        else
+        { //degenerate, make up a value
+            tangent[a].set(0,0,1,1);
+        }
+    }
+
+    ll_aligned_free_16(tan1);
 }
 
 
diff --git a/indra/llmath/llvolume.h b/indra/llmath/llvolume.h
index adbf70f0601b5c67f155930938c0677446a8dc12..60b4714c83d218833c03c1508e32d89cc01b1bed 100644
--- a/indra/llmath/llvolume.h
+++ b/indra/llmath/llvolume.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvolume.h
  * @brief LLVolume base class.
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -70,8 +70,8 @@ const S32 MAX_LOD = 3;
 // These are defined here but are not enforced at this level,
 // rather they are here for the convenience of code that uses
 // the LLVolume class.
-const F32 MIN_VOLUME_PROFILE_WIDTH 	= 0.05f;
-const F32 MIN_VOLUME_PATH_WIDTH 	= 0.05f;
+const F32 MIN_VOLUME_PROFILE_WIDTH  = 0.05f;
+const F32 MIN_VOLUME_PATH_WIDTH     = 0.05f;
 
 const F32 CUT_QUANTA    = 0.00002f;
 const F32 SCALE_QUANTA  = 0.01f;
@@ -85,101 +85,101 @@ const S32 MAX_VOLUME_TRIANGLE_INDICES = 10000;
 //============================================================================
 
 // useful masks
-const LLPCode LL_PCODE_HOLLOW_MASK 	= 0x80;		// has a thickness
-const LLPCode LL_PCODE_SEGMENT_MASK = 0x40;		// segments (1 angle)
-const LLPCode LL_PCODE_PATCH_MASK 	= 0x20;		// segmented segments (2 angles)
-const LLPCode LL_PCODE_HEMI_MASK 	= 0x10;		// half-primitives get their own type per PR's dictum
-const LLPCode LL_PCODE_BASE_MASK 	= 0x0F;
-
-	// primitive shapes
-const LLPCode	LL_PCODE_CUBE 			= 1;
-const LLPCode	LL_PCODE_PRISM 			= 2;
-const LLPCode	LL_PCODE_TETRAHEDRON 	= 3;
-const LLPCode	LL_PCODE_PYRAMID 		= 4;
-const LLPCode	LL_PCODE_CYLINDER 		= 5;
-const LLPCode	LL_PCODE_CONE 			= 6;
-const LLPCode	LL_PCODE_SPHERE 		= 7;
-const LLPCode	LL_PCODE_TORUS 			= 8;
-const LLPCode	LL_PCODE_VOLUME			= 9;
-
-	// surfaces
-//const LLPCode	LL_PCODE_SURFACE_TRIANGLE 	= 10;
-//const LLPCode	LL_PCODE_SURFACE_SQUARE 	= 11;
-//const LLPCode	LL_PCODE_SURFACE_DISC 		= 12;
-
-const LLPCode	LL_PCODE_APP				= 14; // App specific pcode (for viewer/sim side only objects)
-const LLPCode	LL_PCODE_LEGACY				= 15;
+const LLPCode LL_PCODE_HOLLOW_MASK  = 0x80;     // has a thickness
+const LLPCode LL_PCODE_SEGMENT_MASK = 0x40;     // segments (1 angle)
+const LLPCode LL_PCODE_PATCH_MASK   = 0x20;     // segmented segments (2 angles)
+const LLPCode LL_PCODE_HEMI_MASK    = 0x10;     // half-primitives get their own type per PR's dictum
+const LLPCode LL_PCODE_BASE_MASK    = 0x0F;
+
+    // primitive shapes
+const LLPCode   LL_PCODE_CUBE           = 1;
+const LLPCode   LL_PCODE_PRISM          = 2;
+const LLPCode   LL_PCODE_TETRAHEDRON    = 3;
+const LLPCode   LL_PCODE_PYRAMID        = 4;
+const LLPCode   LL_PCODE_CYLINDER       = 5;
+const LLPCode   LL_PCODE_CONE           = 6;
+const LLPCode   LL_PCODE_SPHERE         = 7;
+const LLPCode   LL_PCODE_TORUS          = 8;
+const LLPCode   LL_PCODE_VOLUME         = 9;
+
+    // surfaces
+//const LLPCode LL_PCODE_SURFACE_TRIANGLE   = 10;
+//const LLPCode LL_PCODE_SURFACE_SQUARE     = 11;
+//const LLPCode LL_PCODE_SURFACE_DISC       = 12;
+
+const LLPCode   LL_PCODE_APP                = 14; // App specific pcode (for viewer/sim side only objects)
+const LLPCode   LL_PCODE_LEGACY             = 15;
 
 // Pcodes for legacy objects
-//const LLPCode	LL_PCODE_LEGACY_ATOR =				0x10 | LL_PCODE_LEGACY; // ATOR
-const LLPCode	LL_PCODE_LEGACY_AVATAR =			0x20 | LL_PCODE_LEGACY; // PLAYER
-//const LLPCode	LL_PCODE_LEGACY_BIRD =				0x30 | LL_PCODE_LEGACY; // BIRD
-//const LLPCode	LL_PCODE_LEGACY_DEMON =				0x40 | LL_PCODE_LEGACY; // DEMON
-const LLPCode	LL_PCODE_LEGACY_GRASS =				0x50 | LL_PCODE_LEGACY; // GRASS
-const LLPCode	LL_PCODE_TREE_NEW =					0x60 | LL_PCODE_LEGACY; // new trees
-//const LLPCode	LL_PCODE_LEGACY_ORACLE =			0x70 | LL_PCODE_LEGACY; // ORACLE
-const LLPCode	LL_PCODE_LEGACY_PART_SYS =			0x80 | LL_PCODE_LEGACY; // PART_SYS
-const LLPCode	LL_PCODE_LEGACY_ROCK =				0x90 | LL_PCODE_LEGACY; // ROCK
-//const LLPCode	LL_PCODE_LEGACY_SHOT =				0xA0 | LL_PCODE_LEGACY; // BASIC_SHOT
-//const LLPCode	LL_PCODE_LEGACY_SHOT_BIG =			0xB0 | LL_PCODE_LEGACY;
-//const LLPCode	LL_PCODE_LEGACY_SMOKE =				0xC0 | LL_PCODE_LEGACY; // SMOKE
-//const LLPCode	LL_PCODE_LEGACY_SPARK =				0xD0 | LL_PCODE_LEGACY;// SPARK
-const LLPCode	LL_PCODE_LEGACY_TEXT_BUBBLE =		0xE0 | LL_PCODE_LEGACY; // TEXTBUBBLE
-const LLPCode	LL_PCODE_LEGACY_TREE =				0xF0 | LL_PCODE_LEGACY; // TREE
-
-	// hemis
-const LLPCode	LL_PCODE_CYLINDER_HEMI =		LL_PCODE_CYLINDER	| LL_PCODE_HEMI_MASK;
-const LLPCode	LL_PCODE_CONE_HEMI =			LL_PCODE_CONE		| LL_PCODE_HEMI_MASK;
-const LLPCode	LL_PCODE_SPHERE_HEMI =			LL_PCODE_SPHERE		| LL_PCODE_HEMI_MASK;
-const LLPCode	LL_PCODE_TORUS_HEMI =			LL_PCODE_TORUS		| LL_PCODE_HEMI_MASK;
+//const LLPCode LL_PCODE_LEGACY_ATOR =              0x10 | LL_PCODE_LEGACY; // ATOR
+const LLPCode   LL_PCODE_LEGACY_AVATAR =            0x20 | LL_PCODE_LEGACY; // PLAYER
+//const LLPCode LL_PCODE_LEGACY_BIRD =              0x30 | LL_PCODE_LEGACY; // BIRD
+//const LLPCode LL_PCODE_LEGACY_DEMON =             0x40 | LL_PCODE_LEGACY; // DEMON
+const LLPCode   LL_PCODE_LEGACY_GRASS =             0x50 | LL_PCODE_LEGACY; // GRASS
+const LLPCode   LL_PCODE_TREE_NEW =                 0x60 | LL_PCODE_LEGACY; // new trees
+//const LLPCode LL_PCODE_LEGACY_ORACLE =            0x70 | LL_PCODE_LEGACY; // ORACLE
+const LLPCode   LL_PCODE_LEGACY_PART_SYS =          0x80 | LL_PCODE_LEGACY; // PART_SYS
+const LLPCode   LL_PCODE_LEGACY_ROCK =              0x90 | LL_PCODE_LEGACY; // ROCK
+//const LLPCode LL_PCODE_LEGACY_SHOT =              0xA0 | LL_PCODE_LEGACY; // BASIC_SHOT
+//const LLPCode LL_PCODE_LEGACY_SHOT_BIG =          0xB0 | LL_PCODE_LEGACY;
+//const LLPCode LL_PCODE_LEGACY_SMOKE =             0xC0 | LL_PCODE_LEGACY; // SMOKE
+//const LLPCode LL_PCODE_LEGACY_SPARK =             0xD0 | LL_PCODE_LEGACY;// SPARK
+const LLPCode   LL_PCODE_LEGACY_TEXT_BUBBLE =       0xE0 | LL_PCODE_LEGACY; // TEXTBUBBLE
+const LLPCode   LL_PCODE_LEGACY_TREE =              0xF0 | LL_PCODE_LEGACY; // TREE
+
+    // hemis
+const LLPCode   LL_PCODE_CYLINDER_HEMI =        LL_PCODE_CYLINDER   | LL_PCODE_HEMI_MASK;
+const LLPCode   LL_PCODE_CONE_HEMI =            LL_PCODE_CONE       | LL_PCODE_HEMI_MASK;
+const LLPCode   LL_PCODE_SPHERE_HEMI =          LL_PCODE_SPHERE     | LL_PCODE_HEMI_MASK;
+const LLPCode   LL_PCODE_TORUS_HEMI =           LL_PCODE_TORUS      | LL_PCODE_HEMI_MASK;
 
 
 // Volumes consist of a profile at the base that is swept around
 // a path to make a volume.
 // The profile code
-const U8	LL_PCODE_PROFILE_MASK		= 0x0f;
-const U8	LL_PCODE_PROFILE_MIN		= 0x00;
-const U8    LL_PCODE_PROFILE_CIRCLE		= 0x00;
-const U8    LL_PCODE_PROFILE_SQUARE		= 0x01;
-const U8	LL_PCODE_PROFILE_ISOTRI		= 0x02;
-const U8    LL_PCODE_PROFILE_EQUALTRI	= 0x03;
-const U8    LL_PCODE_PROFILE_RIGHTTRI	= 0x04;
-const U8	LL_PCODE_PROFILE_CIRCLE_HALF = 0x05;
-const U8	LL_PCODE_PROFILE_MAX		= 0x05;
+const U8    LL_PCODE_PROFILE_MASK       = 0x0f;
+const U8    LL_PCODE_PROFILE_MIN        = 0x00;
+const U8    LL_PCODE_PROFILE_CIRCLE     = 0x00;
+const U8    LL_PCODE_PROFILE_SQUARE     = 0x01;
+const U8    LL_PCODE_PROFILE_ISOTRI     = 0x02;
+const U8    LL_PCODE_PROFILE_EQUALTRI   = 0x03;
+const U8    LL_PCODE_PROFILE_RIGHTTRI   = 0x04;
+const U8    LL_PCODE_PROFILE_CIRCLE_HALF = 0x05;
+const U8    LL_PCODE_PROFILE_MAX        = 0x05;
 
 // Stored in the profile byte
-const U8	LL_PCODE_HOLE_MASK		= 0xf0;
-const U8	LL_PCODE_HOLE_MIN		= 0x00;	  
-const U8	LL_PCODE_HOLE_SAME		= 0x00;		// same as outside profile
-const U8	LL_PCODE_HOLE_CIRCLE	= 0x10;
-const U8	LL_PCODE_HOLE_SQUARE	= 0x20;
-const U8	LL_PCODE_HOLE_TRIANGLE	= 0x30;
-const U8	LL_PCODE_HOLE_MAX		= 0x03;		// min/max needs to be >> 4 of real min/max
+const U8    LL_PCODE_HOLE_MASK      = 0xf0;
+const U8    LL_PCODE_HOLE_MIN       = 0x00;
+const U8    LL_PCODE_HOLE_SAME      = 0x00;     // same as outside profile
+const U8    LL_PCODE_HOLE_CIRCLE    = 0x10;
+const U8    LL_PCODE_HOLE_SQUARE    = 0x20;
+const U8    LL_PCODE_HOLE_TRIANGLE  = 0x30;
+const U8    LL_PCODE_HOLE_MAX       = 0x03;     // min/max needs to be >> 4 of real min/max
 
 const U8    LL_PCODE_PATH_IGNORE    = 0x00;
-const U8	LL_PCODE_PATH_MIN		= 0x01;		// min/max needs to be >> 4 of real min/max
+const U8    LL_PCODE_PATH_MIN       = 0x01;     // min/max needs to be >> 4 of real min/max
 const U8    LL_PCODE_PATH_LINE      = 0x10;
 const U8    LL_PCODE_PATH_CIRCLE    = 0x20;
 const U8    LL_PCODE_PATH_CIRCLE_33 = 0x21;
 const U8    LL_PCODE_PATH_CIRCLE2   = 0x30;
 const U8    LL_PCODE_PATH_TEST      = 0x40;
 const U8    LL_PCODE_PATH_FLEXIBLE  = 0x80;
-const U8	LL_PCODE_PATH_MAX		= 0x08;
+const U8    LL_PCODE_PATH_MAX       = 0x08;
 
 //============================================================================
 
 // face identifiers
 typedef U16 LLFaceID;
 
-const LLFaceID	LL_FACE_PATH_BEGIN		= 0x1 << 0;
-const LLFaceID	LL_FACE_PATH_END		= 0x1 << 1;
-const LLFaceID	LL_FACE_INNER_SIDE		= 0x1 << 2;
-const LLFaceID	LL_FACE_PROFILE_BEGIN	= 0x1 << 3;
-const LLFaceID	LL_FACE_PROFILE_END		= 0x1 << 4;
-const LLFaceID	LL_FACE_OUTER_SIDE_0	= 0x1 << 5;
-const LLFaceID	LL_FACE_OUTER_SIDE_1	= 0x1 << 6;
-const LLFaceID	LL_FACE_OUTER_SIDE_2	= 0x1 << 7;
-const LLFaceID	LL_FACE_OUTER_SIDE_3	= 0x1 << 8;
+const LLFaceID  LL_FACE_PATH_BEGIN      = 0x1 << 0;
+const LLFaceID  LL_FACE_PATH_END        = 0x1 << 1;
+const LLFaceID  LL_FACE_INNER_SIDE      = 0x1 << 2;
+const LLFaceID  LL_FACE_PROFILE_BEGIN   = 0x1 << 3;
+const LLFaceID  LL_FACE_PROFILE_END     = 0x1 << 4;
+const LLFaceID  LL_FACE_OUTER_SIDE_0    = 0x1 << 5;
+const LLFaceID  LL_FACE_OUTER_SIDE_1    = 0x1 << 6;
+const LLFaceID  LL_FACE_OUTER_SIDE_2    = 0x1 << 7;
+const LLFaceID  LL_FACE_OUTER_SIDE_3    = 0x1 << 8;
 
 //============================================================================
 
@@ -192,7 +192,7 @@ const U8 LL_SCULPT_TYPE_PLANE     = 3;
 const U8 LL_SCULPT_TYPE_CYLINDER  = 4;
 const U8 LL_SCULPT_TYPE_MESH      = 5;
 const U8 LL_SCULPT_TYPE_MASK      = LL_SCULPT_TYPE_SPHERE | LL_SCULPT_TYPE_TORUS | LL_SCULPT_TYPE_PLANE |
-	LL_SCULPT_TYPE_CYLINDER | LL_SCULPT_TYPE_MESH;
+    LL_SCULPT_TYPE_CYLINDER | LL_SCULPT_TYPE_MESH;
 
 // for value checks, assign new value after adding new types
 const U8 LL_SCULPT_TYPE_MAX = LL_SCULPT_TYPE_MESH;
@@ -208,125 +208,125 @@ extern BOOL gDebugGL;
 class LLProfileParams
 {
 public:
-	LLProfileParams()
-		: mCurveType(LL_PCODE_PROFILE_SQUARE),
-		  mBegin(0.f),
-		  mEnd(1.f),
-		  mHollow(0.f),
-		  mCRC(0)
-	{
-	}
-
-	LLProfileParams(U8 curve, F32 begin, F32 end, F32 hollow)
-		: mCurveType(curve),
-		  mBegin(begin),
-		  mEnd(end),
-		  mHollow(hollow),
-		  mCRC(0)
-	{
-	}
-
-	LLProfileParams(U8 curve, U16 begin, U16 end, U16 hollow)
-	{
-		mCurveType = curve;
-		F32 temp_f32 = begin * CUT_QUANTA;
-		if (temp_f32 > 1.f)
-		{
-			temp_f32 = 1.f;
-		}
-		mBegin = temp_f32;
-		temp_f32 = end * CUT_QUANTA;
-		if (temp_f32 > 1.f)
-		{
-			temp_f32 = 1.f;
-		}
-		mEnd = 1.f - temp_f32;
-		temp_f32 = hollow * HOLLOW_QUANTA;
-		if (temp_f32 > 1.f)
-		{
-			temp_f32 = 1.f;
-		}
-		mHollow = temp_f32;
-		mCRC = 0;
-	}
-
-	bool operator==(const LLProfileParams &params) const;
-	bool operator!=(const LLProfileParams &params) const;
-	bool operator<(const LLProfileParams &params) const;
-	
-	void copyParams(const LLProfileParams &params);
-
-	BOOL importFile(LLFILE *fp);
-	BOOL exportFile(LLFILE *fp) const;
-
-	BOOL importLegacyStream(std::istream& input_stream);
-	BOOL exportLegacyStream(std::ostream& output_stream) const;
-
-	LLSD asLLSD() const;
-	operator LLSD() const { return asLLSD(); }
-	bool fromLLSD(LLSD& sd);
-
-	const F32&  getBegin () const				{ return mBegin; }
-	const F32&  getEnd   () const				{ return mEnd;   }
-	const F32&  getHollow() const				{ return mHollow; }
-	const U8&   getCurveType () const			{ return mCurveType; }
-
-	void setCurveType(const U32 type)			{ mCurveType = type;}
-	void setBegin(const F32 begin)				{ mBegin = (begin >= 1.0f) ? 0.0f : ((int) (begin * 100000))/100000.0f;}
-	void setEnd(const F32 end)					{ mEnd   = (end   <= 0.0f) ? 1.0f : ((int) (end * 100000))/100000.0f;}
-	void setHollow(const F32 hollow)			{ mHollow = ((int) (hollow * 100000))/100000.0f;}
-
-	friend std::ostream& operator<<(std::ostream &s, const LLProfileParams &profile_params);
+    LLProfileParams()
+        : mCurveType(LL_PCODE_PROFILE_SQUARE),
+          mBegin(0.f),
+          mEnd(1.f),
+          mHollow(0.f),
+          mCRC(0)
+    {
+    }
+
+    LLProfileParams(U8 curve, F32 begin, F32 end, F32 hollow)
+        : mCurveType(curve),
+          mBegin(begin),
+          mEnd(end),
+          mHollow(hollow),
+          mCRC(0)
+    {
+    }
+
+    LLProfileParams(U8 curve, U16 begin, U16 end, U16 hollow)
+    {
+        mCurveType = curve;
+        F32 temp_f32 = begin * CUT_QUANTA;
+        if (temp_f32 > 1.f)
+        {
+            temp_f32 = 1.f;
+        }
+        mBegin = temp_f32;
+        temp_f32 = end * CUT_QUANTA;
+        if (temp_f32 > 1.f)
+        {
+            temp_f32 = 1.f;
+        }
+        mEnd = 1.f - temp_f32;
+        temp_f32 = hollow * HOLLOW_QUANTA;
+        if (temp_f32 > 1.f)
+        {
+            temp_f32 = 1.f;
+        }
+        mHollow = temp_f32;
+        mCRC = 0;
+    }
+
+    bool operator==(const LLProfileParams &params) const;
+    bool operator!=(const LLProfileParams &params) const;
+    bool operator<(const LLProfileParams &params) const;
+
+    void copyParams(const LLProfileParams &params);
+
+    BOOL importFile(LLFILE *fp);
+    BOOL exportFile(LLFILE *fp) const;
+
+    BOOL importLegacyStream(std::istream& input_stream);
+    BOOL exportLegacyStream(std::ostream& output_stream) const;
+
+    LLSD asLLSD() const;
+    operator LLSD() const { return asLLSD(); }
+    bool fromLLSD(LLSD& sd);
+
+    const F32&  getBegin () const               { return mBegin; }
+    const F32&  getEnd   () const               { return mEnd;   }
+    const F32&  getHollow() const               { return mHollow; }
+    const U8&   getCurveType () const           { return mCurveType; }
+
+    void setCurveType(const U32 type)           { mCurveType = type;}
+    void setBegin(const F32 begin)              { mBegin = (begin >= 1.0f) ? 0.0f : ((int) (begin * 100000))/100000.0f;}
+    void setEnd(const F32 end)                  { mEnd   = (end   <= 0.0f) ? 1.0f : ((int) (end * 100000))/100000.0f;}
+    void setHollow(const F32 hollow)            { mHollow = ((int) (hollow * 100000))/100000.0f;}
+
+    friend std::ostream& operator<<(std::ostream &s, const LLProfileParams &profile_params);
 
 protected:
-	// Profile params
-	U8			  mCurveType;
-	F32           mBegin;
-	F32           mEnd;
-	F32			  mHollow;
+    // Profile params
+    U8            mCurveType;
+    F32           mBegin;
+    F32           mEnd;
+    F32           mHollow;
 
-	U32           mCRC;
+    U32           mCRC;
 };
 
 inline bool LLProfileParams::operator==(const LLProfileParams &params) const
 {
-	return 
-		(getCurveType() == params.getCurveType()) &&
-		(getBegin() == params.getBegin()) &&
-		(getEnd() == params.getEnd()) &&
-		(getHollow() == params.getHollow());
+    return
+        (getCurveType() == params.getCurveType()) &&
+        (getBegin() == params.getBegin()) &&
+        (getEnd() == params.getEnd()) &&
+        (getHollow() == params.getHollow());
 }
 
 inline bool LLProfileParams::operator!=(const LLProfileParams &params) const
 {
-	return 
-		(getCurveType() != params.getCurveType()) ||
-		(getBegin() != params.getBegin()) ||
-		(getEnd() != params.getEnd()) ||
-		(getHollow() != params.getHollow());
+    return
+        (getCurveType() != params.getCurveType()) ||
+        (getBegin() != params.getBegin()) ||
+        (getEnd() != params.getEnd()) ||
+        (getHollow() != params.getHollow());
 }
 
 
 inline bool LLProfileParams::operator<(const LLProfileParams &params) const
 {
-	if (getCurveType() != params.getCurveType())
-	{
-		return getCurveType() < params.getCurveType();
-	}
-	else
-	if (getBegin() != params.getBegin())
-	{
-		return getBegin() < params.getBegin();
-	}
-	else
-	if (getEnd() != params.getEnd())
-	{
-		return getEnd() < params.getEnd();
-	}
-	else
-	{
-		return getHollow() < params.getHollow();
-	}
+    if (getCurveType() != params.getCurveType())
+    {
+        return getCurveType() < params.getCurveType();
+    }
+    else
+    if (getBegin() != params.getBegin())
+    {
+        return getBegin() < params.getBegin();
+    }
+    else
+    if (getEnd() != params.getEnd())
+    {
+        return getEnd() < params.getEnd();
+    }
+    else
+    {
+        return getHollow() < params.getHollow();
+    }
 }
 
 #define U8_TO_F32(x) (F32)(*((S8 *)&x))
@@ -334,225 +334,225 @@ inline bool LLProfileParams::operator<(const LLProfileParams &params) const
 class LLPathParams
 {
 public:
-	LLPathParams()
-		:
-		mCurveType(LL_PCODE_PATH_LINE),
-		mBegin(0.f),
-		mEnd(1.f),
-		mScale(1.f,1.f),
-		mShear(0.f,0.f),
-		mTwistBegin(0.f),
-		mTwistEnd(0.f),
-		mRadiusOffset(0.f),
-		mTaper(0.f,0.f),
-		mRevolutions(1.f),
-		mSkew(0.f),
-		mCRC(0)
-	{
-	}
-
-	LLPathParams(U8 curve, F32 begin, F32 end, F32 scx, F32 scy, F32 shx, F32 shy, F32 twistend, F32 twistbegin, F32 radiusoffset, F32 tx, F32 ty, F32 revolutions, F32 skew)
-		: mCurveType(curve),
-		  mBegin(begin),
-		  mEnd(end),
-		  mScale(scx,scy),
-		  mShear(shx,shy),
-		  mTwistBegin(twistbegin),
-		  mTwistEnd(twistend), 
-		  mRadiusOffset(radiusoffset),
-		  mTaper(tx,ty),
-		  mRevolutions(revolutions),
-		  mSkew(skew),
-		  mCRC(0)
-	{
-	}
-
-	LLPathParams(U8 curve, U16 begin, U16 end, U8 scx, U8 scy, U8 shx, U8 shy, U8 twistend, U8 twistbegin, U8 radiusoffset, U8 tx, U8 ty, U8 revolutions, U8 skew)
-	{
-		mCurveType = curve;
-		mBegin = (F32)(begin * CUT_QUANTA);
-		mEnd = (F32)(100.f - end) * CUT_QUANTA;
-		if (mEnd > 1.f)
-			mEnd = 1.f;
-		mScale.setVec((F32) (200 - scx) * SCALE_QUANTA,(F32) (200 - scy) * SCALE_QUANTA);
-		mShear.setVec(U8_TO_F32(shx) * SHEAR_QUANTA,U8_TO_F32(shy) * SHEAR_QUANTA);
-		mTwistBegin = U8_TO_F32(twistbegin) * SCALE_QUANTA;
-		mTwistEnd = U8_TO_F32(twistend) * SCALE_QUANTA;
-		mRadiusOffset = U8_TO_F32(radiusoffset) * SCALE_QUANTA;
-		mTaper.setVec(U8_TO_F32(tx) * TAPER_QUANTA,U8_TO_F32(ty) * TAPER_QUANTA);
-		mRevolutions = ((F32)revolutions) * REV_QUANTA + 1.0f;
-		mSkew = U8_TO_F32(skew) * SCALE_QUANTA;
-
-		mCRC = 0;
-	}
-
-	bool operator==(const LLPathParams &params) const;
-	bool operator!=(const LLPathParams &params) const;
-	bool operator<(const LLPathParams &params) const;
-
-	void copyParams(const LLPathParams &params);
-
-	BOOL importFile(LLFILE *fp);
-	BOOL exportFile(LLFILE *fp) const;
-
-	BOOL importLegacyStream(std::istream& input_stream);
-	BOOL exportLegacyStream(std::ostream& output_stream) const;
-
-	LLSD asLLSD() const;
-	operator LLSD() const { return asLLSD(); }
-	bool fromLLSD(LLSD& sd);
-
-	const F32& getBegin() const			{ return mBegin; }
-	const F32& getEnd() const			{ return mEnd; }
-	const LLVector2 &getScale() const	{ return mScale; }
-	const F32& getScaleX() const		{ return mScale.mV[0]; }
-	const F32& getScaleY() const		{ return mScale.mV[1]; }
-	const LLVector2 getBeginScale() const;
-	const LLVector2 getEndScale() const;
-	const LLVector2 &getShear() const	{ return mShear; }
-	const F32& getShearX() const		{ return mShear.mV[0]; }
-	const F32& getShearY() const		{ return mShear.mV[1]; }
-	const U8& getCurveType () const		{ return mCurveType; }
-
-	const F32& getTwistBegin() const	{ return mTwistBegin;	}
-	const F32& getTwistEnd() const		{ return mTwistEnd;	}
-	const F32& getTwist() const			{ return mTwistEnd; }	// deprecated
-	const F32& getRadiusOffset() const	{ return mRadiusOffset; }
-	const LLVector2 &getTaper() const	{ return mTaper;		}
-	const F32& getTaperX() const		{ return mTaper.mV[0];	}
-	const F32& getTaperY() const		{ return mTaper.mV[1];	}
-	const F32& getRevolutions() const	{ return mRevolutions;	}
-	const F32& getSkew() const			{ return mSkew;			}
-
-	void setCurveType(const U8 type)	{ mCurveType = type;	}
-	void setBegin(const F32 begin)		{ mBegin     = begin;	}
-	void setEnd(const F32 end)			{ mEnd       = end;	}
-
-	void setScale(const F32 x, const F32 y)		{ mScale.setVec(x,y); }
-	void setScaleX(const F32 v)					{ mScale.mV[VX] = v; }
-	void setScaleY(const F32 v)					{ mScale.mV[VY] = v; }
-	void setShear(const F32 x, const F32 y)		{ mShear.setVec(x,y); }
-	void setShearX(const F32 v)					{ mShear.mV[VX] = v; }
-	void setShearY(const F32 v)					{ mShear.mV[VY] = v; }
-
-	void setTwistBegin(const F32 twist_begin)	{ mTwistBegin	= twist_begin;	}
-	void setTwistEnd(const F32 twist_end)		{ mTwistEnd		= twist_end;	}
-	void setTwist(const F32 twist)				{ setTwistEnd(twist); }	// deprecated
-	void setRadiusOffset(const F32 radius_offset){ mRadiusOffset	= radius_offset; }
-	void setTaper(const F32 x, const F32 y)		{ mTaper.setVec(x,y);			}
-	void setTaperX(const F32 v)					{ mTaper.mV[VX]	= v;			}
-	void setTaperY(const F32 v)					{ mTaper.mV[VY]	= v;			}
-	void setRevolutions(const F32 revolutions)	{ mRevolutions	= revolutions;	}
-	void setSkew(const F32 skew)				{ mSkew			= skew;			}
-
-	friend std::ostream& operator<<(std::ostream &s, const LLPathParams &path_params);
+    LLPathParams()
+        :
+        mCurveType(LL_PCODE_PATH_LINE),
+        mBegin(0.f),
+        mEnd(1.f),
+        mScale(1.f,1.f),
+        mShear(0.f,0.f),
+        mTwistBegin(0.f),
+        mTwistEnd(0.f),
+        mRadiusOffset(0.f),
+        mTaper(0.f,0.f),
+        mRevolutions(1.f),
+        mSkew(0.f),
+        mCRC(0)
+    {
+    }
+
+    LLPathParams(U8 curve, F32 begin, F32 end, F32 scx, F32 scy, F32 shx, F32 shy, F32 twistend, F32 twistbegin, F32 radiusoffset, F32 tx, F32 ty, F32 revolutions, F32 skew)
+        : mCurveType(curve),
+          mBegin(begin),
+          mEnd(end),
+          mScale(scx,scy),
+          mShear(shx,shy),
+          mTwistBegin(twistbegin),
+          mTwistEnd(twistend),
+          mRadiusOffset(radiusoffset),
+          mTaper(tx,ty),
+          mRevolutions(revolutions),
+          mSkew(skew),
+          mCRC(0)
+    {
+    }
+
+    LLPathParams(U8 curve, U16 begin, U16 end, U8 scx, U8 scy, U8 shx, U8 shy, U8 twistend, U8 twistbegin, U8 radiusoffset, U8 tx, U8 ty, U8 revolutions, U8 skew)
+    {
+        mCurveType = curve;
+        mBegin = (F32)(begin * CUT_QUANTA);
+        mEnd = (F32)(100.f - end) * CUT_QUANTA;
+        if (mEnd > 1.f)
+            mEnd = 1.f;
+        mScale.setVec((F32) (200 - scx) * SCALE_QUANTA,(F32) (200 - scy) * SCALE_QUANTA);
+        mShear.setVec(U8_TO_F32(shx) * SHEAR_QUANTA,U8_TO_F32(shy) * SHEAR_QUANTA);
+        mTwistBegin = U8_TO_F32(twistbegin) * SCALE_QUANTA;
+        mTwistEnd = U8_TO_F32(twistend) * SCALE_QUANTA;
+        mRadiusOffset = U8_TO_F32(radiusoffset) * SCALE_QUANTA;
+        mTaper.setVec(U8_TO_F32(tx) * TAPER_QUANTA,U8_TO_F32(ty) * TAPER_QUANTA);
+        mRevolutions = ((F32)revolutions) * REV_QUANTA + 1.0f;
+        mSkew = U8_TO_F32(skew) * SCALE_QUANTA;
+
+        mCRC = 0;
+    }
+
+    bool operator==(const LLPathParams &params) const;
+    bool operator!=(const LLPathParams &params) const;
+    bool operator<(const LLPathParams &params) const;
+
+    void copyParams(const LLPathParams &params);
+
+    BOOL importFile(LLFILE *fp);
+    BOOL exportFile(LLFILE *fp) const;
+
+    BOOL importLegacyStream(std::istream& input_stream);
+    BOOL exportLegacyStream(std::ostream& output_stream) const;
+
+    LLSD asLLSD() const;
+    operator LLSD() const { return asLLSD(); }
+    bool fromLLSD(LLSD& sd);
+
+    const F32& getBegin() const         { return mBegin; }
+    const F32& getEnd() const           { return mEnd; }
+    const LLVector2 &getScale() const   { return mScale; }
+    const F32& getScaleX() const        { return mScale.mV[0]; }
+    const F32& getScaleY() const        { return mScale.mV[1]; }
+    const LLVector2 getBeginScale() const;
+    const LLVector2 getEndScale() const;
+    const LLVector2 &getShear() const   { return mShear; }
+    const F32& getShearX() const        { return mShear.mV[0]; }
+    const F32& getShearY() const        { return mShear.mV[1]; }
+    const U8& getCurveType () const     { return mCurveType; }
+
+    const F32& getTwistBegin() const    { return mTwistBegin;   }
+    const F32& getTwistEnd() const      { return mTwistEnd; }
+    const F32& getTwist() const         { return mTwistEnd; }   // deprecated
+    const F32& getRadiusOffset() const  { return mRadiusOffset; }
+    const LLVector2 &getTaper() const   { return mTaper;        }
+    const F32& getTaperX() const        { return mTaper.mV[0];  }
+    const F32& getTaperY() const        { return mTaper.mV[1];  }
+    const F32& getRevolutions() const   { return mRevolutions;  }
+    const F32& getSkew() const          { return mSkew;         }
+
+    void setCurveType(const U8 type)    { mCurveType = type;    }
+    void setBegin(const F32 begin)      { mBegin     = begin;   }
+    void setEnd(const F32 end)          { mEnd       = end; }
+
+    void setScale(const F32 x, const F32 y)     { mScale.setVec(x,y); }
+    void setScaleX(const F32 v)                 { mScale.mV[VX] = v; }
+    void setScaleY(const F32 v)                 { mScale.mV[VY] = v; }
+    void setShear(const F32 x, const F32 y)     { mShear.setVec(x,y); }
+    void setShearX(const F32 v)                 { mShear.mV[VX] = v; }
+    void setShearY(const F32 v)                 { mShear.mV[VY] = v; }
+
+    void setTwistBegin(const F32 twist_begin)   { mTwistBegin   = twist_begin;  }
+    void setTwistEnd(const F32 twist_end)       { mTwistEnd     = twist_end;    }
+    void setTwist(const F32 twist)              { setTwistEnd(twist); } // deprecated
+    void setRadiusOffset(const F32 radius_offset){ mRadiusOffset    = radius_offset; }
+    void setTaper(const F32 x, const F32 y)     { mTaper.setVec(x,y);           }
+    void setTaperX(const F32 v)                 { mTaper.mV[VX] = v;            }
+    void setTaperY(const F32 v)                 { mTaper.mV[VY] = v;            }
+    void setRevolutions(const F32 revolutions)  { mRevolutions  = revolutions;  }
+    void setSkew(const F32 skew)                { mSkew         = skew;         }
+
+    friend std::ostream& operator<<(std::ostream &s, const LLPathParams &path_params);
 
 protected:
-	// Path params
-	U8			  mCurveType;
-	F32           mBegin;
-	F32           mEnd;
-	LLVector2	  mScale;
-	LLVector2     mShear;
-
-	F32			  mTwistBegin;
-	F32			  mTwistEnd;
-	F32			  mRadiusOffset;
-	LLVector2	  mTaper;
-	F32			  mRevolutions;
-	F32			  mSkew;
-
-	U32           mCRC;
+    // Path params
+    U8            mCurveType;
+    F32           mBegin;
+    F32           mEnd;
+    LLVector2     mScale;
+    LLVector2     mShear;
+
+    F32           mTwistBegin;
+    F32           mTwistEnd;
+    F32           mRadiusOffset;
+    LLVector2     mTaper;
+    F32           mRevolutions;
+    F32           mSkew;
+
+    U32           mCRC;
 };
 
 inline bool LLPathParams::operator==(const LLPathParams &params) const
 {
-	return
-		(getCurveType() == params.getCurveType()) && 
-		(getScale() == params.getScale()) &&
-		(getBegin() == params.getBegin()) && 
-		(getEnd() == params.getEnd()) && 
-		(getShear() == params.getShear()) &&
-		(getTwist() == params.getTwist()) &&
-		(getTwistBegin() == params.getTwistBegin()) &&
-		(getRadiusOffset() == params.getRadiusOffset()) &&
-		(getTaper() == params.getTaper()) &&
-		(getRevolutions() == params.getRevolutions()) &&
-		(getSkew() == params.getSkew());
+    return
+        (getCurveType() == params.getCurveType()) &&
+        (getScale() == params.getScale()) &&
+        (getBegin() == params.getBegin()) &&
+        (getEnd() == params.getEnd()) &&
+        (getShear() == params.getShear()) &&
+        (getTwist() == params.getTwist()) &&
+        (getTwistBegin() == params.getTwistBegin()) &&
+        (getRadiusOffset() == params.getRadiusOffset()) &&
+        (getTaper() == params.getTaper()) &&
+        (getRevolutions() == params.getRevolutions()) &&
+        (getSkew() == params.getSkew());
 }
 
 inline bool LLPathParams::operator!=(const LLPathParams &params) const
 {
-	return
-		(getCurveType() != params.getCurveType()) ||
-		(getScale() != params.getScale()) ||
-		(getBegin() != params.getBegin()) || 
-		(getEnd() != params.getEnd()) || 
-		(getShear() != params.getShear()) ||
-		(getTwist() != params.getTwist()) ||
-		(getTwistBegin() !=params.getTwistBegin()) ||
-		(getRadiusOffset() != params.getRadiusOffset()) ||
-		(getTaper() != params.getTaper()) ||
-		(getRevolutions() != params.getRevolutions()) ||
-		(getSkew() != params.getSkew());
+    return
+        (getCurveType() != params.getCurveType()) ||
+        (getScale() != params.getScale()) ||
+        (getBegin() != params.getBegin()) ||
+        (getEnd() != params.getEnd()) ||
+        (getShear() != params.getShear()) ||
+        (getTwist() != params.getTwist()) ||
+        (getTwistBegin() !=params.getTwistBegin()) ||
+        (getRadiusOffset() != params.getRadiusOffset()) ||
+        (getTaper() != params.getTaper()) ||
+        (getRevolutions() != params.getRevolutions()) ||
+        (getSkew() != params.getSkew());
 }
 
 
 inline bool LLPathParams::operator<(const LLPathParams &params) const
 {
-	if( getCurveType() != params.getCurveType()) 
-	{
-		return getCurveType() < params.getCurveType();
-	}
-	else
-	if( getScale() != params.getScale()) 
-	{
-		return getScale() < params.getScale();
-	}
-	else
-	if( getBegin() != params.getBegin()) 
-	{
-		return getBegin() < params.getBegin();
-	}
-	else
-	if( getEnd() != params.getEnd()) 
-	{
-		return getEnd() < params.getEnd();
-	}
-	else
-	if( getShear() != params.getShear()) 
-	{
-		return getShear() < params.getShear();
-	}
-	else
-	if( getTwist() != params.getTwist())
-	{
-		return getTwist() < params.getTwist();
-	}
-	else
-	if( getTwistBegin() != params.getTwistBegin())
-	{
-		return getTwistBegin() < params.getTwistBegin();
-	}
-	else
-	if( getRadiusOffset() != params.getRadiusOffset())
-	{
-		return getRadiusOffset() < params.getRadiusOffset();
-	}
-	else
-	if( getTaper() != params.getTaper())
-	{
-		return getTaper() < params.getTaper();
-	}
-	else
-	if( getRevolutions() != params.getRevolutions())
-	{
-		return getRevolutions() < params.getRevolutions();
-	}
-	else
-	{
-		return getSkew() < params.getSkew();
-	}
+    if( getCurveType() != params.getCurveType())
+    {
+        return getCurveType() < params.getCurveType();
+    }
+    else
+    if( getScale() != params.getScale())
+    {
+        return getScale() < params.getScale();
+    }
+    else
+    if( getBegin() != params.getBegin())
+    {
+        return getBegin() < params.getBegin();
+    }
+    else
+    if( getEnd() != params.getEnd())
+    {
+        return getEnd() < params.getEnd();
+    }
+    else
+    if( getShear() != params.getShear())
+    {
+        return getShear() < params.getShear();
+    }
+    else
+    if( getTwist() != params.getTwist())
+    {
+        return getTwist() < params.getTwist();
+    }
+    else
+    if( getTwistBegin() != params.getTwistBegin())
+    {
+        return getTwistBegin() < params.getTwistBegin();
+    }
+    else
+    if( getRadiusOffset() != params.getRadiusOffset())
+    {
+        return getRadiusOffset() < params.getRadiusOffset();
+    }
+    else
+    if( getTaper() != params.getTaper())
+    {
+        return getTaper() < params.getTaper();
+    }
+    else
+    if( getRevolutions() != params.getRevolutions())
+    {
+        return getRevolutions() < params.getRevolutions();
+    }
+    else
+    {
+        return getSkew() < params.getSkew();
+    }
 }
 
 typedef LLVolumeParams* LLVolumeParamsPtr;
@@ -561,190 +561,190 @@ typedef const LLVolumeParams* const_LLVolumeParamsPtr;
 class LLVolumeParams
 {
 public:
-	LLVolumeParams()
-		: mSculptType(LL_SCULPT_TYPE_NONE)
-	{
-	}
-
-	LLVolumeParams(LLProfileParams &profile, LLPathParams &path,
-				   LLUUID sculpt_id = LLUUID::null, U8 sculpt_type = LL_SCULPT_TYPE_NONE)
-		: mProfileParams(profile), mPathParams(path), mSculptID(sculpt_id), mSculptType(sculpt_type)
-	{
-	}
-
-	bool operator==(const LLVolumeParams &params) const;
-	bool operator!=(const LLVolumeParams &params) const;
-	bool operator<(const LLVolumeParams &params) const;
-
-
-	void copyParams(const LLVolumeParams &params);
-	
-	const LLProfileParams &getProfileParams() const {return mProfileParams;}
-	LLProfileParams &getProfileParams() {return mProfileParams;}
-	const LLPathParams &getPathParams() const {return mPathParams;}
-	LLPathParams &getPathParams() {return mPathParams;}
-
-	BOOL importFile(LLFILE *fp);
-	BOOL exportFile(LLFILE *fp) const;
-
-	BOOL importLegacyStream(std::istream& input_stream);
-	BOOL exportLegacyStream(std::ostream& output_stream) const;
-
-	LLSD sculptAsLLSD() const;
-	bool sculptFromLLSD(LLSD& sd);
-	
-	LLSD asLLSD() const;
-	operator LLSD() const { return asLLSD(); }
-	bool fromLLSD(LLSD& sd);
-
-	bool setType(U8 profile, U8 path);
-
-	//void setBeginS(const F32 beginS)			{ mProfileParams.setBegin(beginS); }	// range 0 to 1
-	//void setBeginT(const F32 beginT)			{ mPathParams.setBegin(beginT); }		// range 0 to 1
-	//void setEndS(const F32 endS)				{ mProfileParams.setEnd(endS); }		// range 0 to 1, must be greater than begin
-	//void setEndT(const F32 endT)				{ mPathParams.setEnd(endT); }			// range 0 to 1, must be greater than begin
-
-	bool setBeginAndEndS(const F32 begin, const F32 end);			// both range from 0 to 1, begin must be less than end
-	bool setBeginAndEndT(const F32 begin, const F32 end);			// both range from 0 to 1, begin must be less than end
-
-	bool setHollow(const F32 hollow);	// range 0 to 1
-	bool setRatio(const F32 x)					{ return setRatio(x,x); }			// 0 = point, 1 = same as base
-	bool setShear(const F32 x)					{ return setShear(x,x); }			// 0 = no movement, 
-	bool setRatio(const F32 x, const F32 y);			// 0 = point, 1 = same as base
-	bool setShear(const F32 x, const F32 y);			// 0 = no movement
-
-	bool setTwistBegin(const F32 twist_begin);	// range -1 to 1
-	bool setTwistEnd(const F32 twist_end);		// range -1 to 1
-	bool setTwist(const F32 twist)				{ return setTwistEnd(twist); }		// deprecated
-	bool setTaper(const F32 x, const F32 y)		{ bool pass_x = setTaperX(x); bool pass_y = setTaperY(y); return pass_x && pass_y; }
-	bool setTaperX(const F32 v);				// -1 to 1
-	bool setTaperY(const F32 v);				// -1 to 1
-	bool setRevolutions(const F32 revolutions);	// 1 to 4
-	bool setRadiusOffset(const F32 radius_offset);
-	bool setSkew(const F32 skew);
-	bool setSculptID(LLUUID sculpt_id, U8 sculpt_type);
-
-	static bool validate(U8 prof_curve, F32 prof_begin, F32 prof_end, F32 hollow,
-		U8 path_curve, F32 path_begin, F32 path_end,
-		F32 scx, F32 scy, F32 shx, F32 shy,
-		F32 twistend, F32 twistbegin, F32 radiusoffset,
-		F32 tx, F32 ty, F32 revolutions, F32 skew);
-	
-	const F32&  getBeginS() 	const	{ return mProfileParams.getBegin(); }
- 	const F32&  getBeginT() 	const	{ return mPathParams.getBegin(); }
- 	const F32&  getEndS() 		const	{ return mProfileParams.getEnd(); }
- 	const F32&  getEndT() 		const	{ return mPathParams.getEnd(); }
- 
- 	const F32&  getHollow() 	const   { return mProfileParams.getHollow(); }
- 	const F32&  getTwist() 	const   	{ return mPathParams.getTwist(); }
- 	const F32&  getRatio() 	const		{ return mPathParams.getScaleX(); }
- 	const F32&  getRatioX() 	const   { return mPathParams.getScaleX(); }
- 	const F32&  getRatioY() 	const   { return mPathParams.getScaleY(); }
- 	const F32&  getShearX() 	const   { return mPathParams.getShearX(); }
- 	const F32&  getShearY() 	const   { return mPathParams.getShearY(); }
-
-	const F32&	getTwistBegin()const	{ return mPathParams.getTwistBegin();	}
-	const F32&  getRadiusOffset() const	{ return mPathParams.getRadiusOffset();	}
-	const F32&  getTaper() const		{ return mPathParams.getTaperX();		}
-	const F32&	getTaperX() const		{ return mPathParams.getTaperX();		}
-	const F32&  getTaperY() const		{ return mPathParams.getTaperY();		}
-	const F32&  getRevolutions() const	{ return mPathParams.getRevolutions();	}
-	const F32&  getSkew() const			{ return mPathParams.getSkew();			}
-	const LLUUID& getSculptID() const	{ return mSculptID;						}
-	const U8& getSculptType() const     { return mSculptType;                   }
-	bool isSculpt() const;
-	bool isMeshSculpt() const;
-	BOOL isConvex() const;
-
-	// 'begin' and 'end' should be in range [0, 1] (they will be clamped)
-	// (begin, end) = (0, 1) will not change the volume
-	// (begin, end) = (0, 0.5) will reduce the volume to the first half of its profile/path (S/T)
-	void reduceS(F32 begin, F32 end);
-	void reduceT(F32 begin, F32 end);
-
-	struct compare
-	{
-		bool operator()( const const_LLVolumeParamsPtr& first, const const_LLVolumeParamsPtr& second) const
-		{
-			return (*first < *second);
-		}
-	};
-	
-	friend std::ostream& operator<<(std::ostream &s, const LLVolumeParams &volume_params);
-
-	// debug helper functions
-	void setCube();
+    LLVolumeParams()
+        : mSculptType(LL_SCULPT_TYPE_NONE)
+    {
+    }
+
+    LLVolumeParams(LLProfileParams &profile, LLPathParams &path,
+                   LLUUID sculpt_id = LLUUID::null, U8 sculpt_type = LL_SCULPT_TYPE_NONE)
+        : mProfileParams(profile), mPathParams(path), mSculptID(sculpt_id), mSculptType(sculpt_type)
+    {
+    }
+
+    bool operator==(const LLVolumeParams &params) const;
+    bool operator!=(const LLVolumeParams &params) const;
+    bool operator<(const LLVolumeParams &params) const;
+
+
+    void copyParams(const LLVolumeParams &params);
+
+    const LLProfileParams &getProfileParams() const {return mProfileParams;}
+    LLProfileParams &getProfileParams() {return mProfileParams;}
+    const LLPathParams &getPathParams() const {return mPathParams;}
+    LLPathParams &getPathParams() {return mPathParams;}
+
+    BOOL importFile(LLFILE *fp);
+    BOOL exportFile(LLFILE *fp) const;
+
+    BOOL importLegacyStream(std::istream& input_stream);
+    BOOL exportLegacyStream(std::ostream& output_stream) const;
+
+    LLSD sculptAsLLSD() const;
+    bool sculptFromLLSD(LLSD& sd);
+
+    LLSD asLLSD() const;
+    operator LLSD() const { return asLLSD(); }
+    bool fromLLSD(LLSD& sd);
+
+    bool setType(U8 profile, U8 path);
+
+    //void setBeginS(const F32 beginS)          { mProfileParams.setBegin(beginS); }    // range 0 to 1
+    //void setBeginT(const F32 beginT)          { mPathParams.setBegin(beginT); }       // range 0 to 1
+    //void setEndS(const F32 endS)              { mProfileParams.setEnd(endS); }        // range 0 to 1, must be greater than begin
+    //void setEndT(const F32 endT)              { mPathParams.setEnd(endT); }           // range 0 to 1, must be greater than begin
+
+    bool setBeginAndEndS(const F32 begin, const F32 end);           // both range from 0 to 1, begin must be less than end
+    bool setBeginAndEndT(const F32 begin, const F32 end);           // both range from 0 to 1, begin must be less than end
+
+    bool setHollow(const F32 hollow);   // range 0 to 1
+    bool setRatio(const F32 x)                  { return setRatio(x,x); }           // 0 = point, 1 = same as base
+    bool setShear(const F32 x)                  { return setShear(x,x); }           // 0 = no movement,
+    bool setRatio(const F32 x, const F32 y);            // 0 = point, 1 = same as base
+    bool setShear(const F32 x, const F32 y);            // 0 = no movement
+
+    bool setTwistBegin(const F32 twist_begin);  // range -1 to 1
+    bool setTwistEnd(const F32 twist_end);      // range -1 to 1
+    bool setTwist(const F32 twist)              { return setTwistEnd(twist); }      // deprecated
+    bool setTaper(const F32 x, const F32 y)     { bool pass_x = setTaperX(x); bool pass_y = setTaperY(y); return pass_x && pass_y; }
+    bool setTaperX(const F32 v);                // -1 to 1
+    bool setTaperY(const F32 v);                // -1 to 1
+    bool setRevolutions(const F32 revolutions); // 1 to 4
+    bool setRadiusOffset(const F32 radius_offset);
+    bool setSkew(const F32 skew);
+    bool setSculptID(LLUUID sculpt_id, U8 sculpt_type);
+
+    static bool validate(U8 prof_curve, F32 prof_begin, F32 prof_end, F32 hollow,
+        U8 path_curve, F32 path_begin, F32 path_end,
+        F32 scx, F32 scy, F32 shx, F32 shy,
+        F32 twistend, F32 twistbegin, F32 radiusoffset,
+        F32 tx, F32 ty, F32 revolutions, F32 skew);
+
+    const F32&  getBeginS()     const   { return mProfileParams.getBegin(); }
+    const F32&  getBeginT()     const   { return mPathParams.getBegin(); }
+    const F32&  getEndS()       const   { return mProfileParams.getEnd(); }
+    const F32&  getEndT()       const   { return mPathParams.getEnd(); }
+
+    const F32&  getHollow()     const   { return mProfileParams.getHollow(); }
+    const F32&  getTwist()  const       { return mPathParams.getTwist(); }
+    const F32&  getRatio()  const       { return mPathParams.getScaleX(); }
+    const F32&  getRatioX()     const   { return mPathParams.getScaleX(); }
+    const F32&  getRatioY()     const   { return mPathParams.getScaleY(); }
+    const F32&  getShearX()     const   { return mPathParams.getShearX(); }
+    const F32&  getShearY()     const   { return mPathParams.getShearY(); }
+
+    const F32&  getTwistBegin()const    { return mPathParams.getTwistBegin();   }
+    const F32&  getRadiusOffset() const { return mPathParams.getRadiusOffset(); }
+    const F32&  getTaper() const        { return mPathParams.getTaperX();       }
+    const F32&  getTaperX() const       { return mPathParams.getTaperX();       }
+    const F32&  getTaperY() const       { return mPathParams.getTaperY();       }
+    const F32&  getRevolutions() const  { return mPathParams.getRevolutions();  }
+    const F32&  getSkew() const         { return mPathParams.getSkew();         }
+    const LLUUID& getSculptID() const   { return mSculptID;                     }
+    const U8& getSculptType() const     { return mSculptType;                   }
+    bool isSculpt() const;
+    bool isMeshSculpt() const;
+    BOOL isConvex() const;
+
+    // 'begin' and 'end' should be in range [0, 1] (they will be clamped)
+    // (begin, end) = (0, 1) will not change the volume
+    // (begin, end) = (0, 0.5) will reduce the volume to the first half of its profile/path (S/T)
+    void reduceS(F32 begin, F32 end);
+    void reduceT(F32 begin, F32 end);
+
+    struct compare
+    {
+        bool operator()( const const_LLVolumeParamsPtr& first, const const_LLVolumeParamsPtr& second) const
+        {
+            return (*first < *second);
+        }
+    };
+
+    friend std::ostream& operator<<(std::ostream &s, const LLVolumeParams &volume_params);
+
+    // debug helper functions
+    void setCube();
 
 protected:
-	LLProfileParams mProfileParams;
-	LLPathParams	mPathParams;
-	LLUUID mSculptID;
-	U8 mSculptType;
+    LLProfileParams mProfileParams;
+    LLPathParams    mPathParams;
+    LLUUID mSculptID;
+    U8 mSculptType;
 };
 
 
 class LLProfile
 {
-	friend class LLVolume;
+    friend class LLVolume;
 
 public:
-	LLProfile()
-		: mOpen(FALSE),
-		  mConcave(FALSE),
-		  mDirty(TRUE),
-		  mTotalOut(0),
-		  mTotal(2)
-	{
-	}
-
-	S32	 getTotal() const								{ return mTotal; }
-	S32	 getTotalOut() const							{ return mTotalOut; }	// Total number of outside points
-	BOOL isFlat(S32 face) const							{ return (mFaces[face].mCount == 2); }
-	BOOL isOpen() const									{ return mOpen; }
-	void setDirty()										{ mDirty     = TRUE; }
-
-	static S32 getNumPoints(const LLProfileParams& params, BOOL path_open, F32 detail = 1.0f, S32 split = 0,
-				  BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
-	BOOL generate(const LLProfileParams& params, BOOL path_open, F32 detail = 1.0f, S32 split = 0,
-				  BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
-	BOOL isConcave() const								{ return mConcave; }
+    LLProfile()
+        : mOpen(FALSE),
+          mConcave(FALSE),
+          mDirty(TRUE),
+          mTotalOut(0),
+          mTotal(2)
+    {
+    }
+
+    S32  getTotal() const                               { return mTotal; }
+    S32  getTotalOut() const                            { return mTotalOut; }   // Total number of outside points
+    BOOL isFlat(S32 face) const                         { return (mFaces[face].mCount == 2); }
+    BOOL isOpen() const                                 { return mOpen; }
+    void setDirty()                                     { mDirty     = TRUE; }
+
+    static S32 getNumPoints(const LLProfileParams& params, BOOL path_open, F32 detail = 1.0f, S32 split = 0,
+                  BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
+    BOOL generate(const LLProfileParams& params, BOOL path_open, F32 detail = 1.0f, S32 split = 0,
+                  BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
+    BOOL isConcave() const                              { return mConcave; }
 public:
-	struct Face
-	{
-		S32       mIndex;
-		S32       mCount;
-		F32       mScaleU;
-		BOOL      mCap;
-		BOOL      mFlat;
-		LLFaceID  mFaceID;
-	};
-	
-	LLAlignedArray<LLVector4a, 64> mProfile;	
-	//LLAlignedArray<LLVector4a, 64> mNormals;
-	std::vector<Face>      mFaces;
-
-	//LLAlignedArray<LLVector4a, 64> mEdgeNormals;
-	//LLAlignedArray<LLVector4a, 64> mEdgeCenters;
-
-	friend std::ostream& operator<<(std::ostream &s, const LLProfile &profile);
+    struct Face
+    {
+        S32       mIndex;
+        S32       mCount;
+        F32       mScaleU;
+        BOOL      mCap;
+        BOOL      mFlat;
+        LLFaceID  mFaceID;
+    };
+
+    LLAlignedArray<LLVector4a, 64> mProfile;
+    //LLAlignedArray<LLVector4a, 64> mNormals;
+    std::vector<Face>      mFaces;
+
+    //LLAlignedArray<LLVector4a, 64> mEdgeNormals;
+    //LLAlignedArray<LLVector4a, 64> mEdgeCenters;
+
+    friend std::ostream& operator<<(std::ostream &s, const LLProfile &profile);
 
 protected:
-	~LLProfile() = default;
+    ~LLProfile() = default;
 
-	static S32 getNumNGonPoints(const LLProfileParams& params, S32 sides, F32 offset=0.0f, F32 bevel = 0.0f, F32 ang_scale = 1.f, S32 split = 0);
-	void genNGon(const LLProfileParams& params, S32 sides, F32 offset=0.0f, F32 bevel = 0.0f, F32 ang_scale = 1.f, S32 split = 0);
+    static S32 getNumNGonPoints(const LLProfileParams& params, S32 sides, F32 offset=0.0f, F32 bevel = 0.0f, F32 ang_scale = 1.f, S32 split = 0);
+    void genNGon(const LLProfileParams& params, S32 sides, F32 offset=0.0f, F32 bevel = 0.0f, F32 ang_scale = 1.f, S32 split = 0);
 
-	Face* addHole(const LLProfileParams& params, BOOL flat, F32 sides, F32 offset, F32 box_hollow, F32 ang_scale, S32 split = 0);
-	Face* addCap (S16 faceID);
-	Face* addFace(S32 index, S32 count, F32 scaleU, S16 faceID, BOOL flat);
+    Face* addHole(const LLProfileParams& params, BOOL flat, F32 sides, F32 offset, F32 box_hollow, F32 ang_scale, S32 split = 0);
+    Face* addCap (S16 faceID);
+    Face* addFace(S32 index, S32 count, F32 scaleU, S16 faceID, BOOL flat);
 
 protected:
-	BOOL		  mOpen;
-	BOOL		  mConcave;
-	BOOL          mDirty;
+    BOOL          mOpen;
+    BOOL          mConcave;
+    BOOL          mDirty;
 
-	S32			  mTotalOut;
-	S32			  mTotal;
+    S32           mTotalOut;
+    S32           mTotal;
 };
 
 //-------------------------------------------------------------------
@@ -754,222 +754,222 @@ class LLProfile
 class LLPath
 {
 public:
-	class PathPt
-	{
-	public:
-		LLMatrix4a   mRot;
-		LLVector4a	 mPos;
-		
-		LLVector4a   mScale;
-		F32			 mTexT;
-		F32 pad[3]; //for alignment
-		PathPt() 
-		{ 
-			mPos.clear(); 
-			mTexT = 0; 
-			mScale.clear(); 
-			mRot.setRows(LLVector4a(1,0,0,0),
-						LLVector4a(0,1,0,0),
-						LLVector4a(0,0,1,0));
-
-			//distinguished data in the pad for debugging
-			pad[0] = 3.14159f;
-			pad[1] = -3.14159f;
-			pad[2] = 0.585f;
-		}
-	};
+    class PathPt
+    {
+    public:
+        LLMatrix4a   mRot;
+        LLVector4a   mPos;
+
+        LLVector4a   mScale;
+        F32          mTexT;
+        F32 pad[3]; //for alignment
+        PathPt()
+        {
+            mPos.clear();
+            mTexT = 0;
+            mScale.clear();
+            mRot.setRows(LLVector4a(1,0,0,0),
+                        LLVector4a(0,1,0,0),
+                        LLVector4a(0,0,1,0));
+
+            //distinguished data in the pad for debugging
+            pad[0] = 3.14159f;
+            pad[1] = -3.14159f;
+            pad[2] = 0.585f;
+        }
+    };
 
 public:
-	LLPath()
-		: mOpen(FALSE),
-		  mTotal(0),
-		  mDirty(TRUE),
-		  mStep(1)
-	{
-	}
+    LLPath()
+        : mOpen(FALSE),
+          mTotal(0),
+          mDirty(TRUE),
+          mStep(1)
+    {
+    }
 
-	virtual ~LLPath() = default;
+    virtual ~LLPath() = default;
 
-	static S32 getNumPoints(const LLPathParams& params, F32 detail);
-	static S32 getNumNGonPoints(const LLPathParams& params, S32 sides, F32 offset=0.0f, F32 end_scale = 1.f, F32 twist_scale = 1.f);
+    static S32 getNumPoints(const LLPathParams& params, F32 detail);
+    static S32 getNumNGonPoints(const LLPathParams& params, S32 sides, F32 offset=0.0f, F32 end_scale = 1.f, F32 twist_scale = 1.f);
 
-	void genNGon(const LLPathParams& params, S32 sides, F32 offset=0.0f, F32 end_scale = 1.f, F32 twist_scale = 1.f);
-	virtual BOOL generate(const LLPathParams& params, F32 detail=1.0f, S32 split = 0,
-						  BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
+    void genNGon(const LLPathParams& params, S32 sides, F32 offset=0.0f, F32 end_scale = 1.f, F32 twist_scale = 1.f);
+    virtual BOOL generate(const LLPathParams& params, F32 detail=1.0f, S32 split = 0,
+                          BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
 
-	BOOL isOpen() const						{ return mOpen; }
-	F32 getStep() const						{ return mStep; }
-	void setDirty()							{ mDirty     = TRUE; }
+    BOOL isOpen() const                     { return mOpen; }
+    F32 getStep() const                     { return mStep; }
+    void setDirty()                         { mDirty     = TRUE; }
 
-	S32 getPathLength() const				{ return (S32)mPath.size(); }
+    S32 getPathLength() const               { return (S32)mPath.size(); }
 
-	void resizePath(S32 length) { mPath.resize(length); }
+    void resizePath(S32 length) { mPath.resize(length); }
 
-	friend std::ostream& operator<<(std::ostream &s, const LLPath &path);
+    friend std::ostream& operator<<(std::ostream &s, const LLPath &path);
 
 public:
-	LLAlignedArray<PathPt, 64> mPath;
+    LLAlignedArray<PathPt, 64> mPath;
 
 protected:
-	BOOL		  mOpen;
-	S32			  mTotal;
-	BOOL          mDirty;
-	F32           mStep;
+    BOOL          mOpen;
+    S32           mTotal;
+    BOOL          mDirty;
+    F32           mStep;
 };
 
 class LLDynamicPath final : public LLPath
 {
 public:
-	LLDynamicPath() : LLPath() { }
-	/*virtual*/ BOOL generate(const LLPathParams& params, F32 detail=1.0f, S32 split = 0,
-							  BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
+    LLDynamicPath() : LLPath() { }
+    /*virtual*/ BOOL generate(const LLPathParams& params, F32 detail=1.0f, S32 split = 0,
+                              BOOL is_sculpted = FALSE, S32 sculpt_size = 0);
 };
 
 // Yet another "face" class - caches volume-specific, but not instance-specific data for faces)
 class LLVolumeFace
 {
 public:
-	class VertexData
-	{
-		enum 
-		{
-			POSITION = 0,
-			NORMAL = 1
-		};
-
-	private:
-		void init();
-	public:
-		VertexData();
-		VertexData(const VertexData& rhs);
-		const VertexData& operator=(const VertexData& rhs);
-
-		~VertexData();
-		LLVector4a& getPosition();
-		LLVector4a& getNormal();
-		const LLVector4a& getPosition() const;
-		const LLVector4a& getNormal() const;
-		void setPosition(const LLVector4a& pos);
-		void setNormal(const LLVector4a& norm);
-		
-
-		LLVector2 mTexCoord;
-
-		bool operator<(const VertexData& rhs) const;
-		bool operator==(const VertexData& rhs) const;
-		bool compareNormal(const VertexData& rhs, F32 angle_cutoff) const;
-
-	private:
-		LLVector4a* mData;
-	};
-
-	LLVolumeFace();
-	LLVolumeFace(const LLVolumeFace& src);
-	LLVolumeFace& operator=(const LLVolumeFace& rhs);
-
-	~LLVolumeFace();
+    class VertexData
+    {
+        enum
+        {
+            POSITION = 0,
+            NORMAL = 1
+        };
+
+    private:
+        void init();
+    public:
+        VertexData();
+        VertexData(const VertexData& rhs);
+        const VertexData& operator=(const VertexData& rhs);
+
+        ~VertexData();
+        LLVector4a& getPosition();
+        LLVector4a& getNormal();
+        const LLVector4a& getPosition() const;
+        const LLVector4a& getNormal() const;
+        void setPosition(const LLVector4a& pos);
+        void setNormal(const LLVector4a& norm);
+
+
+        LLVector2 mTexCoord;
+
+        bool operator<(const VertexData& rhs) const;
+        bool operator==(const VertexData& rhs) const;
+        bool compareNormal(const VertexData& rhs, F32 angle_cutoff) const;
+
+    private:
+        LLVector4a* mData;
+    };
+
+    LLVolumeFace();
+    LLVolumeFace(const LLVolumeFace& src);
+    LLVolumeFace& operator=(const LLVolumeFace& rhs);
+
+    ~LLVolumeFace();
 private:
-	void freeData();
+    void freeData();
 public:
 
-	BOOL create(LLVolume* volume, BOOL partial_build = FALSE);
-	void createTangents();
-	
-	void resizeVertices(S32 num_verts);
-	void allocateTangents(S32 num_verts);
-	void allocateWeights(S32 num_verts);
+    BOOL create(LLVolume* volume, BOOL partial_build = FALSE);
+    void createTangents();
+
+    void resizeVertices(S32 num_verts);
+    void allocateTangents(S32 num_verts);
+    void allocateWeights(S32 num_verts);
     void allocateJointIndices(S32 num_verts);
-	void resizeIndices(S32 num_indices);
-	void fillFromLegacyData(std::vector<LLVolumeFace::VertexData>& v, std::vector<U16>& idx);
+    void resizeIndices(S32 num_indices);
+    void fillFromLegacyData(std::vector<LLVolumeFace::VertexData>& v, std::vector<U16>& idx);
 
-	void pushVertex(const VertexData& cv);
-	void pushVertex(const LLVector4a& pos, const LLVector4a& norm, const LLVector2& tc);
-	void pushIndex(const U16& idx);
+    void pushVertex(const VertexData& cv);
+    void pushVertex(const LLVector4a& pos, const LLVector4a& norm, const LLVector2& tc);
+    void pushIndex(const U16& idx);
 
-	void swapData(LLVolumeFace& rhs);
+    void swapData(LLVolumeFace& rhs);
 
-	void getVertexData(U16 indx, LLVolumeFace::VertexData& cv);
+    void getVertexData(U16 indx, LLVolumeFace::VertexData& cv);
 
-	class VertexMapData : public LLVolumeFace::VertexData
-	{
-	public:
+    class VertexMapData : public LLVolumeFace::VertexData
+    {
+    public:
         VertexMapData() : mIndex(0) { }
 
-		U16 mIndex;
+        U16 mIndex;
 
-		bool operator==(const LLVolumeFace::VertexData& rhs) const;
+        bool operator==(const LLVolumeFace::VertexData& rhs) const;
 
-		struct ComparePosition
-		{
-			bool operator()(const LLVector3& a, const LLVector3& b) const;
-		};
+        struct ComparePosition
+        {
+            bool operator()(const LLVector3& a, const LLVector3& b) const;
+        };
 
-		typedef std::map<LLVector3, std::vector<VertexMapData>, VertexMapData::ComparePosition > PointMap;
-	};
+        typedef std::map<LLVector3, std::vector<VertexMapData>, VertexMapData::ComparePosition > PointMap;
+    };
 
     // Eliminates non unique triangles, takes positions,
     // normals and texture coordinates into account.
     void remap();
 
-	void optimize(F32 angle_cutoff = 2.f);
-	bool cacheOptimize(bool gen_tangents = false);
+    void optimize(F32 angle_cutoff = 2.f);
+    bool cacheOptimize(bool gen_tangents = false);
 
-	void createOctree(F32 scaler = 0.25f, const LLVector4a& center = LLVector4a(0,0,0), const LLVector4a& size = LLVector4a(0.5f,0.5f,0.5f));
+    void createOctree(F32 scaler = 0.25f, const LLVector4a& center = LLVector4a(0,0,0), const LLVector4a& size = LLVector4a(0.5f,0.5f,0.5f));
     void destroyOctree();
     // Get a reference to the octree, which may be null
     const LLVolumeOctree* getOctree() const;
 
-	enum
-	{
-		SINGLE_MASK =	0x0001,
-		CAP_MASK =		0x0002,
-		END_MASK =		0x0004,
-		SIDE_MASK =		0x0008,
-		INNER_MASK =	0x0010,
-		OUTER_MASK =	0x0020,
-		HOLLOW_MASK =	0x0040,
-		OPEN_MASK =		0x0080,
-		FLAT_MASK =		0x0100,
-		TOP_MASK =		0x0200,
-		BOTTOM_MASK =	0x0400
-	};
-	
+    enum
+    {
+        SINGLE_MASK =   0x0001,
+        CAP_MASK =      0x0002,
+        END_MASK =      0x0004,
+        SIDE_MASK =     0x0008,
+        INNER_MASK =    0x0010,
+        OUTER_MASK =    0x0020,
+        HOLLOW_MASK =   0x0040,
+        OPEN_MASK =     0x0080,
+        FLAT_MASK =     0x0100,
+        TOP_MASK =      0x0200,
+        BOTTOM_MASK =   0x0400
+    };
+
 public:
-	S32 mID;
-	U32 mTypeMask;
-	
-	// Only used for INNER/OUTER faces
-	S32 mBeginS;
-	S32 mBeginT;
-	S32 mNumS;
-	S32 mNumT;
-
-	LLVector4a* mExtents; //minimum and maximum point of face
-	LLVector4a* mCenter;
-	LLVector2   mTexCoordExtents[2]; //minimum and maximum of texture coordinates of the face.
-
-	S32 mNumVertices; // num vertices == num normals == num texcoords
-	S32 mNumAllocatedVertices;
-	S32 mNumIndices;
-
-	LLVector4a* mPositions; // Contains vertices, nortmals and texcoords
-	LLVector4a* mNormals; // pointer into mPositions
-	LLVector4a* mTangents;
-	LLVector2*  mTexCoords; // pointer into mPositions
-
-	// mIndices contains mNumIndices amount of elements.
-	// It contains triangles, each 3 indices describe one triangle.
+    S32 mID;
+    U32 mTypeMask;
+
+    // Only used for INNER/OUTER faces
+    S32 mBeginS;
+    S32 mBeginT;
+    S32 mNumS;
+    S32 mNumT;
+
+    LLVector4a* mExtents; //minimum and maximum point of face
+    LLVector4a* mCenter;
+    LLVector2   mTexCoordExtents[2]; //minimum and maximum of texture coordinates of the face.
+
+    S32 mNumVertices; // num vertices == num normals == num texcoords
+    S32 mNumAllocatedVertices;
+    S32 mNumIndices;
+
+    LLVector4a* mPositions; // Contains vertices, nortmals and texcoords
+    LLVector4a* mNormals; // pointer into mPositions
+    LLVector4a* mTangents;
+    LLVector2*  mTexCoords; // pointer into mPositions
+
+    // mIndices contains mNumIndices amount of elements.
+    // It contains triangles, each 3 indices describe one triangle.
     // If mIndices contains {0, 2, 3, 1, 2, 4}, it means there
     // are two triangles {0, 2, 3} and {1, 2, 4} with values being
     // indexes for mPositions/mNormals/mTexCoords
-	U16* mIndices;
+    U16* mIndices;
 
-	std::vector<S32>	mEdge;
+    std::vector<S32>    mEdge;
 
-	//list of skin weights for rigged volumes
-	// format is mWeights[vertex_index].mV[influence] = <joint_index>.<weight>
-	// mWeights.size() should be empty or match mVertices.size()  
-	LLVector4a* mWeights;
+    //list of skin weights for rigged volumes
+    // format is mWeights[vertex_index].mV[influence] = <joint_index>.<weight>
+    // mWeights.size() should be empty or match mVertices.size()
+    LLVector4a* mWeights;
 
     mutable BOOL mWeightsScrubbed;
 
@@ -977,8 +977,8 @@ class LLVolumeFace
     // vertices per joint.
     LLJointRiggingInfoTab mJointRiggingInfoTab;
 
-	//whether or not face has been cache optimized
-	BOOL mOptimized;
+    //whether or not face has been cache optimized
+    BOOL mOptimized;
 
     // if this is a mesh asset, scale and translation that were applied
     // when encoding the source mesh into a unit cube
@@ -989,163 +989,163 @@ class LLVolumeFace
     LLVolumeOctree* mOctree;
     LLVolumeTriangle* mOctreeTriangles;
 
-	BOOL createUnCutCubeCap(LLVolume* volume, BOOL partial_build = FALSE);
-	BOOL createCap(LLVolume* volume, BOOL partial_build = FALSE);
-	BOOL createSide(LLVolume* volume, BOOL partial_build = FALSE);
+    BOOL createUnCutCubeCap(LLVolume* volume, BOOL partial_build = FALSE);
+    BOOL createCap(LLVolume* volume, BOOL partial_build = FALSE);
+    BOOL createSide(LLVolume* volume, BOOL partial_build = FALSE);
 };
 
 class LLVolume : public LLRefCount
 {
-	friend class LLVolumeLODGroup;
+    friend class LLVolumeLODGroup;
 
 protected:
-	~LLVolume() override; // use unref
+    ~LLVolume() override; // use unref
 
 public:
-	typedef std::vector<LLVolumeFace> face_list_t;
-		
-	struct FaceParams
-	{
-		LLFaceID mFaceID;
-		S32 mBeginS;
-		S32 mCountS;
-		S32 mBeginT;
-		S32 mCountT;
-	};
-
-	LLVolume(const LLVolumeParams &params, const F32 detail, const BOOL generate_single_face = FALSE, const BOOL is_unique = FALSE);
-	
-	U8 getProfileType()	const								{ return mParams.getProfileParams().getCurveType(); }
-	U8 getPathType() const									{ return mParams.getPathParams().getCurveType(); }
-	S32	getNumFaces() const;
-	S32 getNumVolumeFaces() const							{ return mVolumeFaces.size(); }
-	F32 getDetail() const									{ return mDetail; }
-	F32 getSurfaceArea() const								{ return mSurfaceArea; }
-	const LLVolumeParams& getParams() const					{ return mParams; }
-	LLVolumeParams getCopyOfParams() const					{ return mParams; }
-	const LLProfile& getProfile() const						{ return *mProfilep; }
-	LLPath& getPath() const									{ return *mPathp; }
-	void resizePath(S32 length);
-	const LLAlignedArray<LLVector4a,64>&	getMesh() const				{ return mMesh; }
-	const LLVector4a& getMeshPt(const U32 i) const			{ return mMesh[i]; }
-	
-
-	void setDirty() { mPathp->setDirty(); mProfilep->setDirty(); }
-
-	void regen();
+    typedef std::vector<LLVolumeFace> face_list_t;
+
+    struct FaceParams
+    {
+        LLFaceID mFaceID;
+        S32 mBeginS;
+        S32 mCountS;
+        S32 mBeginT;
+        S32 mCountT;
+    };
+
+    LLVolume(const LLVolumeParams &params, const F32 detail, const BOOL generate_single_face = FALSE, const BOOL is_unique = FALSE);
+
+    U8 getProfileType() const                               { return mParams.getProfileParams().getCurveType(); }
+    U8 getPathType() const                                  { return mParams.getPathParams().getCurveType(); }
+    S32 getNumFaces() const;
+    S32 getNumVolumeFaces() const                           { return mVolumeFaces.size(); }
+    F32 getDetail() const                                   { return mDetail; }
+    F32 getSurfaceArea() const                              { return mSurfaceArea; }
+    const LLVolumeParams& getParams() const                 { return mParams; }
+    LLVolumeParams getCopyOfParams() const                  { return mParams; }
+    const LLProfile& getProfile() const                     { return *mProfilep; }
+    LLPath& getPath() const                                 { return *mPathp; }
+    void resizePath(S32 length);
+    const LLAlignedArray<LLVector4a,64>&    getMesh() const             { return mMesh; }
+    const LLVector4a& getMeshPt(const U32 i) const          { return mMesh[i]; }
+
+
+    void setDirty() { mPathp->setDirty(); mProfilep->setDirty(); }
+
+    void regen();
     void genTangents(S32 face);
 
-	BOOL isConvex() const;
-	BOOL isCap(S32 face);
-	BOOL isFlat(S32 face);
-	BOOL isUnique() const									{ return mUnique; }
-
-	S32 getSculptLevel() const                              { return mSculptLevel; }
-	void setSculptLevel(S32 level)							{ mSculptLevel = level; }
-
-	
-	void getLoDTriangleCounts(S32* counts);
-
-	S32 getNumTriangles(S32* vcount = NULL) const;
-
-	void generateSilhouetteVertices(std::vector<LLVector3> &vertices, 
-									std::vector<LLVector3> &normals, 
-									const LLVector3& view_vec,
-									const LLMatrix4a& mat,
-									const LLMatrix4a& norm_mat,
-									S32 face_index);
-
-	//get the face index of the face that intersects with the given line segment at the point 
-	//closest to start.  Moves end to the point of intersection.  Returns -1 if no intersection.
-	//Line segment must be in volume space.
-	S32 lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
-							 S32 face = -1,                          // which face to check, -1 = ALL_SIDES
-							 LLVector4a* intersection = NULL,         // return the intersection point
-							 LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
-							 LLVector4a* normal = NULL,               // return the surface normal at the intersection point
-							 LLVector4a* tangent = NULL             // return the surface tangent at the intersection point
-		);
-
-	LLFaceID generateFaceMask();
-
-	BOOL isFaceMaskValid(LLFaceID face_mask);
-	static S32 sNumMeshPoints;
-
-	friend std::ostream& operator<<(std::ostream &s, const LLVolume &volume);
-	friend std::ostream& operator<<(std::ostream &s, const LLVolume *volumep);		// HACK to bypass Windoze confusion over 
-																				// conversion if *(LLVolume*) to LLVolume&
-	const LLVolumeFace &getVolumeFace(const S32 f) const {return mVolumeFaces[f];} // DO NOT DELETE VOLUME WHILE USING THIS REFERENCE, OR HOLD A POINTER TO THIS VOLUMEFACE
-	
-	LLVolumeFace &getVolumeFace(const S32 f) {return mVolumeFaces[f];} // DO NOT DELETE VOLUME WHILE USING THIS REFERENCE, OR HOLD A POINTER TO THIS VOLUMEFACE
-
-	face_list_t& getVolumeFaces() { return mVolumeFaces; }
-
-	U32					mFaceMask;			// bit array of which faces exist in this volume
-	LLVector3			mLODScaleBias;		// vector for biasing LOD based on scale
-	
-	void sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level, bool visible_placeholder);
-	void copyVolumeFaces(const LLVolume* volume);
-	void copyFacesTo(std::vector<LLVolumeFace> &faces) const;
-	void copyFacesFrom(const std::vector<LLVolumeFace> &faces);
+    BOOL isConvex() const;
+    BOOL isCap(S32 face);
+    BOOL isFlat(S32 face);
+    BOOL isUnique() const                                   { return mUnique; }
+
+    S32 getSculptLevel() const                              { return mSculptLevel; }
+    void setSculptLevel(S32 level)                          { mSculptLevel = level; }
+
+
+    void getLoDTriangleCounts(S32* counts);
+
+    S32 getNumTriangles(S32* vcount = NULL) const;
+
+    void generateSilhouetteVertices(std::vector<LLVector3> &vertices,
+                                    std::vector<LLVector3> &normals,
+                                    const LLVector3& view_vec,
+                                    const LLMatrix4a& mat,
+                                    const LLMatrix4a& norm_mat,
+                                    S32 face_index);
+
+    //get the face index of the face that intersects with the given line segment at the point
+    //closest to start.  Moves end to the point of intersection.  Returns -1 if no intersection.
+    //Line segment must be in volume space.
+    S32 lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
+                             S32 face = -1,                          // which face to check, -1 = ALL_SIDES
+                             LLVector4a* intersection = NULL,         // return the intersection point
+                             LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
+                             LLVector4a* normal = NULL,               // return the surface normal at the intersection point
+                             LLVector4a* tangent = NULL             // return the surface tangent at the intersection point
+        );
+
+    LLFaceID generateFaceMask();
+
+    BOOL isFaceMaskValid(LLFaceID face_mask);
+    static S32 sNumMeshPoints;
+
+    friend std::ostream& operator<<(std::ostream &s, const LLVolume &volume);
+    friend std::ostream& operator<<(std::ostream &s, const LLVolume *volumep);      // HACK to bypass Windoze confusion over
+                                                                                // conversion if *(LLVolume*) to LLVolume&
+    const LLVolumeFace &getVolumeFace(const S32 f) const {return mVolumeFaces[f];} // DO NOT DELETE VOLUME WHILE USING THIS REFERENCE, OR HOLD A POINTER TO THIS VOLUMEFACE
+
+    LLVolumeFace &getVolumeFace(const S32 f) {return mVolumeFaces[f];} // DO NOT DELETE VOLUME WHILE USING THIS REFERENCE, OR HOLD A POINTER TO THIS VOLUMEFACE
+
+    face_list_t& getVolumeFaces() { return mVolumeFaces; }
+
+    U32                 mFaceMask;          // bit array of which faces exist in this volume
+    LLVector3           mLODScaleBias;      // vector for biasing LOD based on scale
+
+    void sculpt(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, S32 sculpt_level, bool visible_placeholder);
+    void copyVolumeFaces(const LLVolume* volume);
+    void copyFacesTo(std::vector<LLVolumeFace> &faces) const;
+    void copyFacesFrom(const std::vector<LLVolumeFace> &faces);
 
     // use meshoptimizer to optimize index buffer for vertex shader cache
     //  gen_tangents - if true, generate MikkTSpace tangents if needed before optimizing index buffer
-	bool cacheOptimize(bool gen_tangents = false);
+    bool cacheOptimize(bool gen_tangents = false);
 
 private:
-	void sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type);
-	F32 sculptGetSurfaceArea();
-	void sculptGenerateEmptyPlaceholder();
-	void sculptGenerateSpherePlaceholder();
-	void sculptCalcMeshResolution(U16 width, U16 height, U8 type, S32& s, S32& t);
+    void sculptGenerateMapVertices(U16 sculpt_width, U16 sculpt_height, S8 sculpt_components, const U8* sculpt_data, U8 sculpt_type);
+    F32 sculptGetSurfaceArea();
+    void sculptGenerateEmptyPlaceholder();
+    void sculptGenerateSpherePlaceholder();
+    void sculptCalcMeshResolution(U16 width, U16 height, U8 type, S32& s, S32& t);
+
 
-	
 protected:
-	BOOL generate();
-	void createVolumeFaces();
+    BOOL generate();
+    void createVolumeFaces();
 public:
-	bool unpackVolumeFaces(std::istream& is, S32 size);
-	bool unpackVolumeFaces(U8* in_data, S32 size);
+    bool unpackVolumeFaces(std::istream& is, S32 size);
+    bool unpackVolumeFaces(U8* in_data, S32 size);
 private:
-	bool unpackVolumeFacesInternal(const LLSD& mdl);
+    bool unpackVolumeFacesInternal(const LLSD& mdl);
 
 public:
-	virtual void setMeshAssetLoaded(bool loaded);
-	virtual bool isMeshAssetLoaded();
+    virtual void setMeshAssetLoaded(bool loaded);
+    virtual bool isMeshAssetLoaded();
     virtual void setMeshAssetUnavaliable(bool unavaliable);
     virtual bool isMeshAssetUnavaliable();
 
  protected:
-	BOOL mUnique;
-	F32 mDetail;
-	S32 mSculptLevel;
-	F32 mSurfaceArea; //unscaled surface area
-	bool mIsMeshAssetLoaded;
+    BOOL mUnique;
+    F32 mDetail;
+    S32 mSculptLevel;
+    F32 mSurfaceArea; //unscaled surface area
+    bool mIsMeshAssetLoaded;
     bool mIsMeshAssetUnavaliable;
-	
-	const LLVolumeParams mParams;
-	LLPath *mPathp;
-	LLProfile *mProfilep;
-	LLAlignedArray<LLVector4a,64> mMesh;
-	
-	
-	BOOL mGenerateSingleFace;
-	face_list_t mVolumeFaces;
+
+    const LLVolumeParams mParams;
+    LLPath *mPathp;
+    LLProfile *mProfilep;
+    LLAlignedArray<LLVector4a,64> mMesh;
+
+
+    BOOL mGenerateSingleFace;
+    face_list_t mVolumeFaces;
 
 public:
-	LLVector4a* mHullPoints;
-	U16* mHullIndices;
-	S32 mNumHullPoints;
-	S32 mNumHullIndices;
+    LLVector4a* mHullPoints;
+    U16* mHullIndices;
+    S32 mNumHullPoints;
+    S32 mNumHullIndices;
 private:
-	struct TrianglesPerLODCache
-	{
-		LLProfileParams mProfileParams;
-		LLPathParams mPathParams;
-		S32 mTriangles[4];
-	};
-
-	std::unique_ptr<TrianglesPerLODCache> mTrianglesCache;
+    struct TrianglesPerLODCache
+    {
+        LLProfileParams mProfileParams;
+        LLPathParams mPathParams;
+        S32 mTriangles[4];
+    };
+
+    std::unique_ptr<TrianglesPerLODCache> mTrianglesCache;
 };
 
 std::ostream& operator<<(std::ostream &s, const LLVolumeParams &volume_params);
@@ -1157,13 +1157,13 @@ BOOL LLLineSegmentBoxIntersect(const LLVector3& start, const LLVector3& end, con
 BOOL LLLineSegmentBoxIntersect(const LLVector4a& start, const LLVector4a& end, const LLVector4a& center, const LLVector4a& size);
 
 //BOOL LLTriangleRayIntersect(const LLVector3& vert0, const LLVector3& vert1, const LLVector3& vert2, const LLVector3& orig, const LLVector3& dir,
-//							F32& intersection_a, F32& intersection_b, F32& intersection_t, BOOL two_sided);
+//                          F32& intersection_a, F32& intersection_b, F32& intersection_t, BOOL two_sided);
 
 BOOL LLTriangleRayIntersect(const LLVector4a& vert0, const LLVector4a& vert1, const LLVector4a& vert2, const LLVector4a& orig, const LLVector4a& dir,
-							F32& intersection_a, F32& intersection_b, F32& intersection_t);
+                            F32& intersection_a, F32& intersection_b, F32& intersection_t);
 BOOL LLTriangleRayIntersectTwoSided(const LLVector4a& vert0, const LLVector4a& vert1, const LLVector4a& vert2, const LLVector4a& orig, const LLVector4a& dir,
-							F32& intersection_a, F32& intersection_b, F32& intersection_t);
-	
-	
+                            F32& intersection_a, F32& intersection_b, F32& intersection_t);
+
+
 
 #endif
diff --git a/indra/llmath/llvolumeoctree.cpp b/indra/llmath/llvolumeoctree.cpp
index 93857803a76b7e955899f58f3c765f121b2b66c3..23570238fb159044d8bdf95bcd1b1b9c7d686d72 100644
--- a/indra/llmath/llvolumeoctree.cpp
+++ b/indra/llmath/llvolumeoctree.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
 
  * @file llvolumeoctree.cpp
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -29,185 +29,185 @@
 
 BOOL LLLineSegmentBoxIntersect(const LLVector4a& start, const LLVector4a& end, const LLVector4a& center, const LLVector4a& size)
 {
-	LLVector4a fAWdU;
-	LLVector4a dir;
-	LLVector4a diff;
+    LLVector4a fAWdU;
+    LLVector4a dir;
+    LLVector4a diff;
+
+    dir.setSub(end, start);
+    dir.mul(0.5f);
+
+    diff.setAdd(end,start);
+    diff.mul(0.5f);
+    diff.sub(center);
+    fAWdU.setAbs(dir);
 
-	dir.setSub(end, start);
-	dir.mul(0.5f);
+    LLVector4a rhs;
+    rhs.setAdd(size, fAWdU);
 
-	diff.setAdd(end,start);
-	diff.mul(0.5f);
-	diff.sub(center);
-	fAWdU.setAbs(dir); 
+    LLVector4a lhs;
+    lhs.setAbs(diff);
 
-	LLVector4a rhs;
-	rhs.setAdd(size, fAWdU);
+    U32 grt = lhs.greaterThan(rhs).getGatheredBits();
 
-	LLVector4a lhs;
-	lhs.setAbs(diff);
+    if (grt & 0x7)
+    {
+        return false;
+    }
 
-	U32 grt = lhs.greaterThan(rhs).getGatheredBits();
+    LLVector4a f;
+    f.setCross3(dir, diff);
+    f.setAbs(f);
 
-	if (grt & 0x7)
-	{
-		return false;
-	}
-	
-	LLVector4a f;
-	f.setCross3(dir, diff);
-	f.setAbs(f);
+    LLVector4a v0, v1;
 
-	LLVector4a v0, v1;
+    v0 = _mm_shuffle_ps(size, size,_MM_SHUFFLE(3,0,0,1));
+    v1 = _mm_shuffle_ps(fAWdU, fAWdU, _MM_SHUFFLE(3,1,2,2));
+    lhs.setMul(v0, v1);
 
-	v0 = _mm_shuffle_ps(size, size,_MM_SHUFFLE(3,0,0,1));
-	v1 = _mm_shuffle_ps(fAWdU, fAWdU, _MM_SHUFFLE(3,1,2,2));
-	lhs.setMul(v0, v1);
+    v0 = _mm_shuffle_ps(size, size, _MM_SHUFFLE(3,1,2,2));
+    v1 = _mm_shuffle_ps(fAWdU, fAWdU, _MM_SHUFFLE(3,0,0,1));
+    rhs.setMul(v0, v1);
+    rhs.add(lhs);
 
-	v0 = _mm_shuffle_ps(size, size, _MM_SHUFFLE(3,1,2,2));
-	v1 = _mm_shuffle_ps(fAWdU, fAWdU, _MM_SHUFFLE(3,0,0,1));
-	rhs.setMul(v0, v1);
-	rhs.add(lhs);
-	
-	grt = f.greaterThan(rhs).getGatheredBits();
+    grt = f.greaterThan(rhs).getGatheredBits();
 
-	return (grt & 0x7) ? false : true;
+    return (grt & 0x7) ? false : true;
 }
 
 
 LLVolumeOctreeListener::LLVolumeOctreeListener(LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* node)
 {
-	node->addListener(this);
+    node->addListener(this);
 }
 
-void LLVolumeOctreeListener::handleChildAddition(const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* parent, 
+void LLVolumeOctreeListener::handleChildAddition(const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* parent,
     LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* child)
 {
-	new LLVolumeOctreeListener(child);
+    new LLVolumeOctreeListener(child);
 }
 
-LLOctreeTriangleRayIntersect::LLOctreeTriangleRayIntersect(const LLVector4a& start, const LLVector4a& dir, 
+LLOctreeTriangleRayIntersect::LLOctreeTriangleRayIntersect(const LLVector4a& start, const LLVector4a& dir,
                                 LLVolumeFace* face, F32* closest_t,
-							   LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent)
+                               LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent)
    : mStart(start),
-	 mDir(dir),
-	 mIntersection(intersection),
-	 mTexCoord(tex_coord),
-	 mNormal(normal),
-	 mTangent(tangent),
+     mDir(dir),
+     mIntersection(intersection),
+     mTexCoord(tex_coord),
+     mNormal(normal),
+     mTangent(tangent),
      mFace(face),
-	 mClosestT(closest_t),
-	 mHitFace(false)
+     mClosestT(closest_t),
+     mHitFace(false)
 {
-	mEnd.setAdd(mStart, mDir);
+    mEnd.setAdd(mStart, mDir);
 }
 
 void LLOctreeTriangleRayIntersect::traverse(const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* node)
 {
-	LLVolumeOctreeListener* vl = (LLVolumeOctreeListener*) node->getListener(0);
-
-	if (LLLineSegmentBoxIntersect(mStart, mEnd, vl->mBounds[0], vl->mBounds[1]))
-	{
-		node->accept(this);
-		for (S32 i = 0; i < node->getChildCount(); ++i)
-		{
-			traverse(node->getChild(i));
-		}
-	}
+    LLVolumeOctreeListener* vl = (LLVolumeOctreeListener*) node->getListener(0);
+
+    if (LLLineSegmentBoxIntersect(mStart, mEnd, vl->mBounds[0], vl->mBounds[1]))
+    {
+        node->accept(this);
+        for (S32 i = 0; i < node->getChildCount(); ++i)
+        {
+            traverse(node->getChild(i));
+        }
+    }
 }
 
 void LLOctreeTriangleRayIntersect::visit(const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* node)
 {
     for (typename LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>::const_element_iter iter =
-			node->getDataBegin(), iter_end = node->getDataEnd(); iter != iter_end; ++iter)
-	{
-		const LLVolumeTriangle* tri = *iter;
-
-		F32 a, b, t;
-		
-		if (LLTriangleRayIntersect(*tri->mV[0], *tri->mV[1], *tri->mV[2],
-				mStart, mDir, a, b, t))
-		{
-			if ((t >= 0.f) &&      // if hit is after start
-				(t <= 1.f) &&      // and before end
-				(t < *mClosestT))   // and this hit is closer
-			{
-				*mClosestT = t;
-				mHitFace = true;
+            node->getDataBegin(), iter_end = node->getDataEnd(); iter != iter_end; ++iter)
+    {
+        const LLVolumeTriangle* tri = *iter;
+
+        F32 a, b, t;
+
+        if (LLTriangleRayIntersect(*tri->mV[0], *tri->mV[1], *tri->mV[2],
+                mStart, mDir, a, b, t))
+        {
+            if ((t >= 0.f) &&      // if hit is after start
+                (t <= 1.f) &&      // and before end
+                (t < *mClosestT))   // and this hit is closer
+            {
+                *mClosestT = t;
+                mHitFace = true;
                 mHitTriangle = tri;
-				if (mIntersection != NULL)
-				{
-					LLVector4a intersect = mDir;
-					intersect.mul(*mClosestT);
-					intersect.add(mStart);
-					*mIntersection = intersect;
-				}
-
-				U32 idx0 = tri->mIndex[0];
-				U32 idx1 = tri->mIndex[1];
-				U32 idx2 = tri->mIndex[2];
-
-				if (mTexCoord != NULL)
-				{
-					LLVector2* tc = (LLVector2*) mFace->mTexCoords;
-					*mTexCoord = ((1.f - a - b)  * tc[idx0] +
-						a              * tc[idx1] +
-						b              * tc[idx2]);
-
-				}
-
-				if (mNormal != NULL)
-				{
-					LLVector4a* norm = mFace->mNormals;
-								
-					LLVector4a n1,n2,n3;
-					n1 = norm[idx0];
-					n1.mul(1.f-a-b);
-								
-					n2 = norm[idx1];
-					n2.mul(a);
-								
-					n3 = norm[idx2];
-					n3.mul(b);
-
-					n1.add(n2);
-					n1.add(n3);
-								
-					*mNormal		= n1; 
-				}
-
-				if (mTangent != NULL)
-				{
-					LLVector4a* tangents = mFace->mTangents;
-								
-					LLVector4a t1,t2,t3;
-					t1 = tangents[idx0];
-					t1.mul(1.f-a-b);
-								
-					t2 = tangents[idx1];
-					t2.mul(a);
-								
-					t3 = tangents[idx2];
-					t3.mul(b);
-
-					t1.add(t2);
-					t1.add(t3);
-								
-					*mTangent = t1; 
-				}
-			}
-		}
-	}
+                if (mIntersection != NULL)
+                {
+                    LLVector4a intersect = mDir;
+                    intersect.mul(*mClosestT);
+                    intersect.add(mStart);
+                    *mIntersection = intersect;
+                }
+
+                U32 idx0 = tri->mIndex[0];
+                U32 idx1 = tri->mIndex[1];
+                U32 idx2 = tri->mIndex[2];
+
+                if (mTexCoord != NULL)
+                {
+                    LLVector2* tc = (LLVector2*) mFace->mTexCoords;
+                    *mTexCoord = ((1.f - a - b)  * tc[idx0] +
+                        a              * tc[idx1] +
+                        b              * tc[idx2]);
+
+                }
+
+                if (mNormal != NULL)
+                {
+                    LLVector4a* norm = mFace->mNormals;
+
+                    LLVector4a n1,n2,n3;
+                    n1 = norm[idx0];
+                    n1.mul(1.f-a-b);
+
+                    n2 = norm[idx1];
+                    n2.mul(a);
+
+                    n3 = norm[idx2];
+                    n3.mul(b);
+
+                    n1.add(n2);
+                    n1.add(n3);
+
+                    *mNormal        = n1;
+                }
+
+                if (mTangent != NULL)
+                {
+                    LLVector4a* tangents = mFace->mTangents;
+
+                    LLVector4a t1,t2,t3;
+                    t1 = tangents[idx0];
+                    t1.mul(1.f-a-b);
+
+                    t2 = tangents[idx1];
+                    t2.mul(a);
+
+                    t3 = tangents[idx2];
+                    t3.mul(b);
+
+                    t1.add(t2);
+                    t1.add(t3);
+
+                    *mTangent = t1;
+                }
+            }
+        }
+    }
 }
 
 const LLVector4a& LLVolumeTriangle::getPositionGroup() const
 {
-	return mPositionGroup;
+    return mPositionGroup;
 }
 
 const F32& LLVolumeTriangle::getBinRadius() const
 {
-	return mRadius;
+    return mRadius;
 }
 
 
@@ -215,55 +215,55 @@ const F32& LLVolumeTriangle::getBinRadius() const
 
 void LLVolumeOctreeValidate::visit(const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* branch)
 {
-	LLVolumeOctreeListener* node = (LLVolumeOctreeListener*) branch->getListener(0);
+    LLVolumeOctreeListener* node = (LLVolumeOctreeListener*) branch->getListener(0);
 
-	//make sure bounds matches extents
-	LLVector4a& min = node->mExtents[0];
-	LLVector4a& max = node->mExtents[1];
+    //make sure bounds matches extents
+    LLVector4a& min = node->mExtents[0];
+    LLVector4a& max = node->mExtents[1];
 
-	LLVector4a& center = node->mBounds[0];
-	LLVector4a& size = node->mBounds[1];
+    LLVector4a& center = node->mBounds[0];
+    LLVector4a& size = node->mBounds[1];
 
-	LLVector4a test_min, test_max;
-	test_min.setSub(center, size);
-	test_max.setAdd(center, size);
+    LLVector4a test_min, test_max;
+    test_min.setSub(center, size);
+    test_max.setAdd(center, size);
 
-	if (!test_min.equals3(min, 0.001f) ||
-		!test_max.equals3(max, 0.001f))
-	{
-		LL_ERRS() << "Bad bounding box data found." << LL_ENDL;
-	}
+    if (!test_min.equals3(min, 0.001f) ||
+        !test_max.equals3(max, 0.001f))
+    {
+        LL_ERRS() << "Bad bounding box data found." << LL_ENDL;
+    }
 
-	test_min.sub(LLVector4a(0.001f));
-	test_max.add(LLVector4a(0.001f));
+    test_min.sub(LLVector4a(0.001f));
+    test_max.add(LLVector4a(0.001f));
 
-	for (U32 i = 0; i < branch->getChildCount(); ++i)
-	{
-		LLVolumeOctreeListener* child = (LLVolumeOctreeListener*) branch->getChild(i)->getListener(0);
+    for (U32 i = 0; i < branch->getChildCount(); ++i)
+    {
+        LLVolumeOctreeListener* child = (LLVolumeOctreeListener*) branch->getChild(i)->getListener(0);
 
-		//make sure all children fit inside this node
-		if (child->mExtents[0].lessThan(test_min).areAnySet(LLVector4Logical::MASK_XYZ) ||
-			child->mExtents[1].greaterThan(test_max).areAnySet(LLVector4Logical::MASK_XYZ))
-		{
-			LL_ERRS() << "Child protrudes from bounding box." << LL_ENDL;
-		}
-	}
+        //make sure all children fit inside this node
+        if (child->mExtents[0].lessThan(test_min).areAnySet(LLVector4Logical::MASK_XYZ) ||
+            child->mExtents[1].greaterThan(test_max).areAnySet(LLVector4Logical::MASK_XYZ))
+        {
+            LL_ERRS() << "Child protrudes from bounding box." << LL_ENDL;
+        }
+    }
 
-	//children fit, check data
+    //children fit, check data
     for (typename LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>::const_element_iter iter = branch->getDataBegin(), iter_end = branch->getDataEnd();
-			iter != iter_end; ++iter)
-	{
-		const LLVolumeTriangle* tri = *iter;
-
-		//validate triangle
-		for (U32 i = 0; i < 3; i++)
-		{
-			if (tri->mV[i]->greaterThan(test_max).areAnySet(LLVector4Logical::MASK_XYZ) ||
-				tri->mV[i]->lessThan(test_min).areAnySet(LLVector4Logical::MASK_XYZ))
-			{
-				LL_ERRS() << "Triangle protrudes from node." << LL_ENDL;
-			}
-		}
-	}
+            iter != iter_end; ++iter)
+    {
+        const LLVolumeTriangle* tri = *iter;
+
+        //validate triangle
+        for (U32 i = 0; i < 3; i++)
+        {
+            if (tri->mV[i]->greaterThan(test_max).areAnySet(LLVector4Logical::MASK_XYZ) ||
+                tri->mV[i]->lessThan(test_min).areAnySet(LLVector4Logical::MASK_XYZ))
+            {
+                LL_ERRS() << "Triangle protrudes from node." << LL_ENDL;
+            }
+        }
+    }
 }
 
diff --git a/indra/llmath/llvolumeoctree.h b/indra/llmath/llvolumeoctree.h
index 2d0e96d0dbf586e91becb54cc46847a366340b29..9c436dc2a25473706e1b6c6637cf997aff2376df 100644
--- a/indra/llmath/llvolumeoctree.h
+++ b/indra/llmath/llvolumeoctree.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvolumeoctree.h
  * @brief LLVolume octree classes.
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -38,16 +38,16 @@ class alignas(16) LLVolumeTriangle final : public LLRefCount
 {
     LL_ALIGN_NEW
 public:
-	LLVolumeTriangle()
-	{
-		mBinIndex = -1;	
-	}
+    LLVolumeTriangle()
+    {
+        mBinIndex = -1;
+    }
 
-	LLVolumeTriangle(const LLVolumeTriangle& rhs)
+    LLVolumeTriangle(const LLVolumeTriangle& rhs)
     {
         *this = rhs;
     }
-	LLVolumeTriangle& operator=(const LLVolumeTriangle& rhs)
+    LLVolumeTriangle& operator=(const LLVolumeTriangle& rhs)
     {
         LL_ERRS() << "Illegal operation!" << LL_ENDL;
         return *this;
@@ -75,22 +75,22 @@ class alignas(16) LLVolumeTriangle final : public LLRefCount
         return *this;
     }
 
-	~LLVolumeTriangle() = default;
+    ~LLVolumeTriangle() = default;
+
+    LL_ALIGN_16(LLVector4a mPositionGroup);
 
-	LL_ALIGN_16(LLVector4a mPositionGroup);
+    const LLVector4a* mV[3];
+    U32 mIndex[3];
 
-	const LLVector4a* mV[3];
-	U32 mIndex[3];
+    F32 mRadius;
+    mutable S32 mBinIndex;
 
-	F32 mRadius;
-	mutable S32 mBinIndex;
 
+    virtual const LLVector4a& getPositionGroup() const;
+    virtual const F32& getBinRadius() const;
 
-	virtual const LLVector4a& getPositionGroup() const;
-	virtual const F32& getBinRadius() const;
-	
-	S32 getBinIndex() const { return mBinIndex; }
-	void setBinIndex(S32 idx) const { mBinIndex = idx; }
+    S32 getBinIndex() const { return mBinIndex; }
+    void setBinIndex(S32 idx) const { mBinIndex = idx; }
 
 
 };
@@ -100,44 +100,44 @@ class alignas(16) LLVolumeOctreeListener final : public LLOctreeListener<LLVolum
     LL_ALIGN_NEW
 public:
     LLVolumeOctreeListener(LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* node);
-	~LLVolumeOctreeListener() = default;
-	
-	LLVolumeOctreeListener(const LLVolumeOctreeListener& rhs) = delete;
+    ~LLVolumeOctreeListener() = default;
+
+    LLVolumeOctreeListener(const LLVolumeOctreeListener& rhs) = delete;
     LLVolumeOctreeListener& operator=(const LLVolumeOctreeListener& rhs) = delete;
 
-	 //LISTENER FUNCTIONS
+     //LISTENER FUNCTIONS
     virtual void handleChildAddition(const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* parent, LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* child);
-	virtual void handleStateChange(const LLTreeNode<LLVolumeTriangle>* node) { }
+    virtual void handleStateChange(const LLTreeNode<LLVolumeTriangle>* node) { }
     virtual void handleChildRemoval(const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* parent, const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* child) { }
-	virtual void handleInsertion(const LLTreeNode<LLVolumeTriangle>* node, LLVolumeTriangle* tri) { }
-	virtual void handleRemoval(const LLTreeNode<LLVolumeTriangle>* node, LLVolumeTriangle* tri) { }
-	virtual void handleDestruction(const LLTreeNode<LLVolumeTriangle>* node) { }
-	
+    virtual void handleInsertion(const LLTreeNode<LLVolumeTriangle>* node, LLVolumeTriangle* tri) { }
+    virtual void handleRemoval(const LLTreeNode<LLVolumeTriangle>* node, LLVolumeTriangle* tri) { }
+    virtual void handleDestruction(const LLTreeNode<LLVolumeTriangle>* node) { }
+
 
 public:
-	LL_ALIGN_16(LLVector4a mBounds[2]); // bounding box (center, size) of this node and all its children (tight fit to objects)
-	LL_ALIGN_16(LLVector4a mExtents[2]); // extents (min, max) of this node and all its children
+    LL_ALIGN_16(LLVector4a mBounds[2]); // bounding box (center, size) of this node and all its children (tight fit to objects)
+    LL_ALIGN_16(LLVector4a mExtents[2]); // extents (min, max) of this node and all its children
 };
 
 class LLOctreeTriangleRayIntersect : public LLOctreeTraveler<LLVolumeTriangle, LLVolumeTriangle*>
 {
 public:
-	LLVector4a mStart;
-	LLVector4a mDir;
-	LLVector4a mEnd;
-	LLVector4a* mIntersection;
-	LLVector2* mTexCoord;
-	LLVector4a* mNormal;
-	LLVector4a* mTangent;
-	F32* mClosestT;
+    LLVector4a mStart;
+    LLVector4a mDir;
+    LLVector4a mEnd;
+    LLVector4a* mIntersection;
+    LLVector2* mTexCoord;
+    LLVector4a* mNormal;
+    LLVector4a* mTangent;
+    F32* mClosestT;
     LLVolumeFace* mFace;
-	bool mHitFace;
+    bool mHitFace;
     const LLVolumeTriangle* mHitTriangle = nullptr;
 
-	LLOctreeTriangleRayIntersect(const LLVector4a& start, const LLVector4a& dir,
+    LLOctreeTriangleRayIntersect(const LLVector4a& start, const LLVector4a& dir,
                                     LLVolumeFace* face,
-								   F32* closest_t,
-								   LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent);
+                                   F32* closest_t,
+                                   LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent);
 
     void traverse(const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* node);
 
@@ -227,7 +227,7 @@ class LLVolumeOctree : public LLOctreeRoot<LLVolumeTriangle, LLVolumeTriangle*>,
     {
         new LLVolumeOctreeListener(this);
     }
-    
+
     LLVolumeOctree()
         : LLOctreeRoot<LLVolumeTriangle, LLVolumeTriangle*>(LLVector4a::getZero(), LLVector4a(1.f,1.f,1.f), nullptr),
         LLRefCount()
diff --git a/indra/llplugin/llpluginprocessparent.cpp b/indra/llplugin/llpluginprocessparent.cpp
index 91dd885bc6ad4f5a488c8117f112e8de773311d9..b810c497ee5e27ed213f59cd8c9387f0b6439416 100644
--- a/indra/llplugin/llpluginprocessparent.cpp
+++ b/indra/llplugin/llpluginprocessparent.cpp
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file llpluginprocessparent.cpp
  * @brief LLPluginProcessParent handles the parent side of the external-process plugin API.
  *
@@ -6,21 +6,21 @@
  * $LicenseInfo:firstyear=2008&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  * @endcond
@@ -51,80 +51,80 @@ LLThread *LLPluginProcessParent::sReadThread = NULL;
 class LLPluginProcessParentPollThread final : public LLThread
 {
 public:
-	LLPluginProcessParentPollThread() :
-		LLThread("LLPluginProcessParentPollThread", gAPRPoolp)
-	{
-	}
+    LLPluginProcessParentPollThread() :
+        LLThread("LLPluginProcessParentPollThread", gAPRPoolp)
+    {
+    }
 protected:
-	// Inherited from LLThread
-	/*virtual*/ void run(void)
-	{
-		while(!isQuitting() && LLPluginProcessParent::getUseReadThread())
-		{
-			bool active = LLPluginProcessParent::poll(0.1f);
-			checkPause();
-			ms_sleep(active ? 1 : 10); // Do not eat-up a full CPU core !!!
-		}
-		
-		// Final poll to clean up the pollset, etc.
-		LLPluginProcessParent::poll(0.0f);
-	} 
-
-	// Inherited from LLThread
-	/*virtual*/ bool runCondition(void)
-	{
-		return(LLPluginProcessParent::canPollThreadRun());
-	}
+    // Inherited from LLThread
+    /*virtual*/ void run(void)
+    {
+        while(!isQuitting() && LLPluginProcessParent::getUseReadThread())
+        {
+            bool active = LLPluginProcessParent::poll(0.1f);
+            checkPause();
+            ms_sleep(active ? 1 : 10); // Do not eat-up a full CPU core !!!
+        }
+
+        // Final poll to clean up the pollset, etc.
+        LLPluginProcessParent::poll(0.0f);
+    }
+
+    // Inherited from LLThread
+    /*virtual*/ bool runCondition(void)
+    {
+        return(LLPluginProcessParent::canPollThreadRun());
+    }
 
 };
 
 LLPluginProcessParent::LLPluginProcessParent(LLPluginProcessParentOwner *owner):
-	mIncomingQueueMutex()
+    mIncomingQueueMutex()
 {
-	if(!sInstancesMutex)
-	{
-		sInstancesMutex = new LLMutex();
-	}
-	
-	mOwner = owner;
-	mBoundPort = 0;
-	mState = STATE_UNINITIALIZED;
-	mSleepTime = 0.0;
-	mCPUUsage = 0.0;
-	mDisableTimeout = false;
-	mDebug = false;
-	mBlocked = false;
-	mPolledInput = false;
-	mPollFD.client_data = NULL;
-
-	mPluginLaunchTimeout = 60.0f;
-	mPluginLockupTimeout = 15.0f;
-	
-	// Don't start the timer here -- start it when we actually launch the plugin process.
-	mHeartbeat.stop();
-	
+    if(!sInstancesMutex)
+    {
+        sInstancesMutex = new LLMutex();
+    }
+
+    mOwner = owner;
+    mBoundPort = 0;
+    mState = STATE_UNINITIALIZED;
+    mSleepTime = 0.0;
+    mCPUUsage = 0.0;
+    mDisableTimeout = false;
+    mDebug = false;
+    mBlocked = false;
+    mPolledInput = false;
+    mPollFD.client_data = NULL;
+
+    mPluginLaunchTimeout = 60.0f;
+    mPluginLockupTimeout = 15.0f;
+
+    // Don't start the timer here -- start it when we actually launch the plugin process.
+    mHeartbeat.stop();
+
 }
 
 LLPluginProcessParent::~LLPluginProcessParent()
 {
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Plugin") << "destructor" << LL_ENDL;
+    LL_DEBUGS("Plugin") << "destructor" << LL_ENDL;
 #endif
 
-	// Destroy any remaining shared memory regions
-	sharedMemoryRegionsType::iterator iter;
-	while((iter = mSharedMemoryRegions.begin()) != mSharedMemoryRegions.end())
-	{
-		// destroy the shared memory region
-		iter->second->destroy();
-		delete iter->second;
-		iter->second = NULL;
-		
-		// and remove it from our map
-		mSharedMemoryRegions.erase(iter);
-	}
-
-	LLProcess::kill(mProcess);
+    // Destroy any remaining shared memory regions
+    sharedMemoryRegionsType::iterator iter;
+    while((iter = mSharedMemoryRegions.begin()) != mSharedMemoryRegions.end())
+    {
+        // destroy the shared memory region
+        iter->second->destroy();
+        delete iter->second;
+        iter->second = NULL;
+
+        // and remove it from our map
+        mSharedMemoryRegions.erase(iter);
+    }
+
+    LLProcess::kill(mProcess);
     if (!LLApp::isQuitting())
     {   // If we are quitting, the network sockets will already have been destroyed.
         killSockets();
@@ -194,7 +194,7 @@ void LLPluginProcessParent::requestShutdown()
     namestream << "LLPluginProcessParentListener" << ++count;
 
     //*HACK!*//
-    // After requestShutdown has been called our previous owner will no longer call 
+    // After requestShutdown has been called our previous owner will no longer call
     // our idle() method.  Tie into the event loop here to do that until we are good
     // and finished.
     LL_DEBUGS("LLPluginProcessParent") << "listening on \"mainloop\"" << LL_ENDL;
@@ -246,729 +246,729 @@ bool LLPluginProcessParent::wantsPolling() const
 
 void LLPluginProcessParent::killSockets(void)
 {
-	{
-		LLMutexLock lock(&mIncomingQueueMutex);
-		killMessagePipe();
-	}
+    {
+        LLMutexLock lock(&mIncomingQueueMutex);
+        killMessagePipe();
+    }
 
-	mListenSocket.reset();
-	mSocket.reset();
+    mListenSocket.reset();
+    mSocket.reset();
 }
 
 void LLPluginProcessParent::errorState(void)
 {
-	if(mState < STATE_RUNNING)
-		setState(STATE_LAUNCH_FAILURE);
-	else
-		setState(STATE_ERROR);
+    if(mState < STATE_RUNNING)
+        setState(STATE_LAUNCH_FAILURE);
+    else
+        setState(STATE_ERROR);
 }
 
 void LLPluginProcessParent::init(const std::string &launcher_filename, const std::string &plugin_dir, const std::string &plugin_filename, bool debug)
-{	
-	mProcessParams.executable = launcher_filename;
-	mProcessParams.cwd = plugin_dir;
-	mPluginFile = plugin_filename;
-	mPluginDir = plugin_dir;
-	mCPUUsage = 0.0f;
-	mDebug = debug;	
-	setState(STATE_INITIALIZED);
+{
+    mProcessParams.executable = launcher_filename;
+    mProcessParams.cwd = plugin_dir;
+    mPluginFile = plugin_filename;
+    mPluginDir = plugin_dir;
+    mCPUUsage = 0.0f;
+    mDebug = debug;
+    setState(STATE_INITIALIZED);
 }
 
 bool LLPluginProcessParent::accept()
 {
-	bool result = false;
-	
-	apr_status_t status = APR_EGENERAL;
-	apr_socket_t *new_socket = NULL;
-	
-	status = apr_socket_accept(
-		&new_socket,
-		mListenSocket->getSocket(),
-		gAPRPoolp);
-
-	
-	if(status == APR_SUCCESS)
-	{
-//		LL_INFOS() << "SUCCESS" << LL_ENDL;
-		// Success.  Create a message pipe on the new socket
-
-		// we MUST create a new pool for the LLSocket, since it will take ownership of it and delete it in its destructor!
-		apr_pool_t* new_pool = NULL;
-		status = apr_pool_create(&new_pool, gAPRPoolp);
-
-		mSocket = LLSocket::create(new_socket, new_pool);
-		new LLPluginMessagePipe(this, mSocket);
-
-		result = true;
-	}
-	else if(APR_STATUS_IS_EAGAIN(status))
-	{
-//		LL_INFOS() << "EAGAIN" << LL_ENDL;
-
-		// No incoming connections.  This is not an error.
-		status = APR_SUCCESS;
-	}
-	else
-	{
-//		LL_INFOS() << "Error:" << LL_ENDL;
-		ll_apr_warn_status(status);
-		
-		// Some other error.
-		errorState();
-	}
-	
-	return result;	
+    bool result = false;
+
+    apr_status_t status = APR_EGENERAL;
+    apr_socket_t *new_socket = NULL;
+
+    status = apr_socket_accept(
+        &new_socket,
+        mListenSocket->getSocket(),
+        gAPRPoolp);
+
+
+    if(status == APR_SUCCESS)
+    {
+//      LL_INFOS() << "SUCCESS" << LL_ENDL;
+        // Success.  Create a message pipe on the new socket
+
+        // we MUST create a new pool for the LLSocket, since it will take ownership of it and delete it in its destructor!
+        apr_pool_t* new_pool = NULL;
+        status = apr_pool_create(&new_pool, gAPRPoolp);
+
+        mSocket = LLSocket::create(new_socket, new_pool);
+        new LLPluginMessagePipe(this, mSocket);
+
+        result = true;
+    }
+    else if(APR_STATUS_IS_EAGAIN(status))
+    {
+//      LL_INFOS() << "EAGAIN" << LL_ENDL;
+
+        // No incoming connections.  This is not an error.
+        status = APR_SUCCESS;
+    }
+    else
+    {
+//      LL_INFOS() << "Error:" << LL_ENDL;
+        ll_apr_warn_status(status);
+
+        // Some other error.
+        errorState();
+    }
+
+    return result;
 }
 
 void LLPluginProcessParent::idle(void)
 {
-	bool idle_again;
-
-	do
-	{
-		// process queued messages
-		if (!mIncomingQueue.empty())
-		{
-			// Inside main thread, it is preferable not to block it on mutex.
-			LLMutexTrylock locked_mtx(&mIncomingQueueMutex);
-			if (locked_mtx.isLocked())
-			{
-				if (!mIncomingQueue.empty())
-				{
-					std::deque<LLPluginMessage> local_queue;
-					local_queue.swap(mIncomingQueue);
-
-					for(const auto& message : local_queue)
-					{
-						receiveMessage(message);
-					}
-				}
-			}
-
-		}
-		
-		// Give time to network processing
-		if(mMessagePipe)
-		{
-			// Drain any queued outgoing messages
-			mMessagePipe->pumpOutput();
-			
-			// Only do input processing here if this instance isn't in a pollset.
-			// If viewer and plugin are both shutting down, don't process further
-			// input, viewer won't be able to handle it.
-			if(!mPolledInput
-			   && !(mState >= STATE_GOODBYE && LLApp::isExiting()))
-			{
-				mMessagePipe->pumpInput();
-			}
-		}
-		
-		if(mState <= STATE_RUNNING)
-		{
-			if(APR_STATUS_IS_EOF(mSocketError))
-			{
-				// Plugin socket was closed.  This covers both normal plugin termination and plugin crashes.
-				errorState();
-			}
-			else if(mSocketError != APR_SUCCESS)
-			{
-				// The socket is in an error state -- the plugin is gone.
-				LL_WARNS("Plugin") << "Socket hit an error state (" << mSocketError << ")" << LL_ENDL;
-				errorState();
-			}
-		}	
-		
-		// If a state needs to go directly to another state (as a performance enhancement), it can set idle_again to true after calling setState().
-		// USE THIS CAREFULLY, since it can starve other code.  Specifically make sure there's no way to get into a closed cycle and never return.
-		// When in doubt, don't do it.
-		idle_again = false;
-		switch(mState)
-		{
-			case STATE_UNINITIALIZED:
-			break;
-
-			case STATE_INITIALIZED:
-			{
-	
-				apr_status_t status = APR_SUCCESS;
-				apr_sockaddr_t* addr = NULL;
-				mListenSocket = LLSocket::create(gAPRPoolp, LLSocket::STREAM_TCP);
-				mBoundPort = 0;
-				if (!mListenSocket)
-				{
-					killSockets();
-					errorState();
-					break;
-				}
-				
-				// This code is based on parts of LLSocket::create() in lliosocket.cpp.
-				
-				status = apr_sockaddr_info_get(
-					&addr,
-					"127.0.0.1",
-					APR_INET,
-					0,	// port 0 = ephemeral ("find me a port")
-					0,
-					gAPRPoolp);
-					
-				if(ll_apr_warn_status(status))
-				{
-					killSockets();
-					errorState();
-					break;
-				}
-
-				// This allows us to reuse the address on quick down/up. This is unlikely to create problems.
-				ll_apr_warn_status(apr_socket_opt_set(mListenSocket->getSocket(), APR_SO_REUSEADDR, 1));
-				
-				status = apr_socket_bind(mListenSocket->getSocket(), addr);
-				if(ll_apr_warn_status(status))
-				{
-					killSockets();
-					errorState();
-					break;
-				}
-
-				// Get the actual port the socket was bound to
-				{
-					apr_sockaddr_t* bound_addr = NULL;
-					if(ll_apr_warn_status(apr_socket_addr_get(&bound_addr, APR_LOCAL, mListenSocket->getSocket())))
-					{
-						killSockets();
-						errorState();
-						break;
-					}
-					mBoundPort = bound_addr->port;	
-
-					if(mBoundPort == 0)
-					{
-						LL_WARNS("Plugin") << "Bound port number unknown, bailing out." << LL_ENDL;
-						
-						killSockets();
-						errorState();
-						break;
-					}
-				}
-				
-				LL_DEBUGS("Plugin") << "Bound tcp socket to port: " << addr->port << LL_ENDL;
-
-				// Make the listen socket non-blocking
-				status = apr_socket_opt_set(mListenSocket->getSocket(), APR_SO_NONBLOCK, 1);
-				if(ll_apr_warn_status(status))
-				{
-					killSockets();
-					errorState();
-					break;
-				}
-
-				apr_socket_timeout_set(mListenSocket->getSocket(), 0);
-				if(ll_apr_warn_status(status))
-				{
-					killSockets();
-					errorState();
-					break;
-				}
-				
-				// If it's a stream based socket, we need to tell the OS
-				// to keep a queue of incoming connections for ACCEPT.
-				status = apr_socket_listen(
-					mListenSocket->getSocket(),
-					10); // FIXME: Magic number for queue size
-					
-				if(ll_apr_warn_status(status))
-				{
-					killSockets();
-					errorState();
-					break;
-				}
-				
-				// If we got here, we're listening.
-				setState(STATE_LISTENING);
-				break;
-			}
-			
-			case STATE_LISTENING:
-			    {
-				    // Launch the plugin process.
-				    // Only argument to the launcher is the port number we're listening on
-				    mProcessParams.args.add(stringize(mBoundPort));
-
-				    // Launch the plugin process.
+    bool idle_again;
+
+    do
+    {
+        // process queued messages
+        if (!mIncomingQueue.empty())
+        {
+            // Inside main thread, it is preferable not to block it on mutex.
+            LLMutexTrylock locked_mtx(&mIncomingQueueMutex);
+            if (locked_mtx.isLocked())
+            {
+                if (!mIncomingQueue.empty())
+                {
+                    std::deque<LLPluginMessage> local_queue;
+                    local_queue.swap(mIncomingQueue);
+
+                    for(const auto& message : local_queue)
+                    {
+                        receiveMessage(message);
+                    }
+                }
+            }
+
+        }
+
+        // Give time to network processing
+        if(mMessagePipe)
+        {
+            // Drain any queued outgoing messages
+            mMessagePipe->pumpOutput();
+
+            // Only do input processing here if this instance isn't in a pollset.
+            // If viewer and plugin are both shutting down, don't process further
+            // input, viewer won't be able to handle it.
+            if(!mPolledInput
+               && !(mState >= STATE_GOODBYE && LLApp::isExiting()))
+            {
+                mMessagePipe->pumpInput();
+            }
+        }
+
+        if(mState <= STATE_RUNNING)
+        {
+            if(APR_STATUS_IS_EOF(mSocketError))
+            {
+                // Plugin socket was closed.  This covers both normal plugin termination and plugin crashes.
+                errorState();
+            }
+            else if(mSocketError != APR_SUCCESS)
+            {
+                // The socket is in an error state -- the plugin is gone.
+                LL_WARNS("Plugin") << "Socket hit an error state (" << mSocketError << ")" << LL_ENDL;
+                errorState();
+            }
+        }
+
+        // If a state needs to go directly to another state (as a performance enhancement), it can set idle_again to true after calling setState().
+        // USE THIS CAREFULLY, since it can starve other code.  Specifically make sure there's no way to get into a closed cycle and never return.
+        // When in doubt, don't do it.
+        idle_again = false;
+        switch(mState)
+        {
+            case STATE_UNINITIALIZED:
+            break;
+
+            case STATE_INITIALIZED:
+            {
+
+                apr_status_t status = APR_SUCCESS;
+                apr_sockaddr_t* addr = NULL;
+                mListenSocket = LLSocket::create(gAPRPoolp, LLSocket::STREAM_TCP);
+                mBoundPort = 0;
+                if (!mListenSocket)
+                {
+                    killSockets();
+                    errorState();
+                    break;
+                }
+
+                // This code is based on parts of LLSocket::create() in lliosocket.cpp.
+
+                status = apr_sockaddr_info_get(
+                    &addr,
+                    "127.0.0.1",
+                    APR_INET,
+                    0,  // port 0 = ephemeral ("find me a port")
+                    0,
+                    gAPRPoolp);
+
+                if(ll_apr_warn_status(status))
+                {
+                    killSockets();
+                    errorState();
+                    break;
+                }
+
+                // This allows us to reuse the address on quick down/up. This is unlikely to create problems.
+                ll_apr_warn_status(apr_socket_opt_set(mListenSocket->getSocket(), APR_SO_REUSEADDR, 1));
+
+                status = apr_socket_bind(mListenSocket->getSocket(), addr);
+                if(ll_apr_warn_status(status))
+                {
+                    killSockets();
+                    errorState();
+                    break;
+                }
+
+                // Get the actual port the socket was bound to
+                {
+                    apr_sockaddr_t* bound_addr = NULL;
+                    if(ll_apr_warn_status(apr_socket_addr_get(&bound_addr, APR_LOCAL, mListenSocket->getSocket())))
+                    {
+                        killSockets();
+                        errorState();
+                        break;
+                    }
+                    mBoundPort = bound_addr->port;
+
+                    if(mBoundPort == 0)
+                    {
+                        LL_WARNS("Plugin") << "Bound port number unknown, bailing out." << LL_ENDL;
+
+                        killSockets();
+                        errorState();
+                        break;
+                    }
+                }
+
+                LL_DEBUGS("Plugin") << "Bound tcp socket to port: " << addr->port << LL_ENDL;
+
+                // Make the listen socket non-blocking
+                status = apr_socket_opt_set(mListenSocket->getSocket(), APR_SO_NONBLOCK, 1);
+                if(ll_apr_warn_status(status))
+                {
+                    killSockets();
+                    errorState();
+                    break;
+                }
+
+                apr_socket_timeout_set(mListenSocket->getSocket(), 0);
+                if(ll_apr_warn_status(status))
+                {
+                    killSockets();
+                    errorState();
+                    break;
+                }
+
+                // If it's a stream based socket, we need to tell the OS
+                // to keep a queue of incoming connections for ACCEPT.
+                status = apr_socket_listen(
+                    mListenSocket->getSocket(),
+                    10); // FIXME: Magic number for queue size
+
+                if(ll_apr_warn_status(status))
+                {
+                    killSockets();
+                    errorState();
+                    break;
+                }
+
+                // If we got here, we're listening.
+                setState(STATE_LISTENING);
+                break;
+            }
+
+            case STATE_LISTENING:
+                {
+                    // Launch the plugin process.
+                    // Only argument to the launcher is the port number we're listening on
+                    mProcessParams.args.add(stringize(mBoundPort));
+
+                    // Launch the plugin process.
                     if (mDebug && !mProcess)
                     {
-						if (!(mProcess = LLProcess::create(mProcessParams)))
-						{
-							errorState();
-						}
+                        if (!(mProcess = LLProcess::create(mProcessParams)))
+                        {
+                            errorState();
+                        }
+                    }
+                    else if (!mProcess && !mProcessCreationRequested)
+                    {
+                        mProcessCreationRequested = true;
+                        LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop");
+                        // *NOTE: main_queue->postTo casts this refcounted smart pointer to a weak
+                        // pointer
+                        LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General");
+                        const LL::ThreadPool::ptr_t general_thread_pool = LL::ThreadPool::getInstance("General");
+                        llassert_always(main_queue);
+                        llassert_always(general_queue);
+                        llassert_always(general_thread_pool);
+
+                        auto process_params = mProcessParams;
+
+                        bool posted = main_queue->postTo(
+                            general_queue,
+                            [process_params]() // Work done on general queue
+                            {
+                                return LLProcess::create(process_params);
+                            },
+                            [this](LLProcessPtr new_process) // Callback to main thread
+                                mutable {
+                                ptr_t that;
+                                {
+                                    // this grabs a copy of the smart pointer to ourselves to ensure that we do not
+                                    // get destroyed until after this method returns.
+                                    LLMutexLock lock(sInstancesMutex);
+                                    mapInstances_t::iterator it = sInstances.find(this);
+                                    if (it != sInstances.end())
+                                        that = (*it).second;
+                                }
+
+                                if (that)
+                                {
+                                    if (new_process)
+                                    {
+                                        that->mProcess = new_process;
+                                    }
+                                    else
+                                    {
+                                        that->errorState();
+                                    }
+                                }
+
+                            });
+                        if (!posted)
+                        {
+                            // Shutdown
+                            // Consider making processQueue() do a cleanup instead
+                            // of starting more decodes
+                            LL_WARNS("Plugin") << "Failed to dispath process creation to threadpool" << LL_ENDL;
+                            if (!(mProcess = LLProcess::create(mProcessParams)))
+                            {
+                                errorState();
+                            }
+                        }
                     }
-					else if (!mProcess && !mProcessCreationRequested)
-					{
-						mProcessCreationRequested = true;
-						LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop");
-						// *NOTE: main_queue->postTo casts this refcounted smart pointer to a weak
-						// pointer
-						LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General");
-						const LL::ThreadPool::ptr_t general_thread_pool = LL::ThreadPool::getInstance("General");
-						llassert_always(main_queue);
-						llassert_always(general_queue);
-						llassert_always(general_thread_pool);
-
-						auto process_params = mProcessParams;
-
-						bool posted = main_queue->postTo(
-							general_queue,
-							[process_params]() // Work done on general queue
-							{
-								return LLProcess::create(process_params);
-							},
-							[this](LLProcessPtr new_process) // Callback to main thread
-								mutable {
-								ptr_t that;
-								{
-									// this grabs a copy of the smart pointer to ourselves to ensure that we do not
-									// get destroyed until after this method returns.
-									LLMutexLock lock(sInstancesMutex);
-									mapInstances_t::iterator it = sInstances.find(this);
-									if (it != sInstances.end())
-										that = (*it).second;
-								}
-
-								if (that)
-								{
-									if (new_process)
-									{
-										that->mProcess = new_process;
-									}
-									else
-									{
-										that->errorState();
-									}
-								}
-
-							});
-						if (!posted)
-						{
-							// Shutdown
-							// Consider making processQueue() do a cleanup instead
-							// of starting more decodes
-							LL_WARNS("Plugin") << "Failed to dispath process creation to threadpool" << LL_ENDL;
-							if (!(mProcess = LLProcess::create(mProcessParams)))
-							{
-								errorState();
-							}
-						}
-					}
-
-					if (mProcess)
-				    {
-					    if(mDebug)
-					    {
+
+                    if (mProcess)
+                    {
+                        if(mDebug)
+                        {
 #if LL_DARWIN
-						    // If we're set to debug, start up a gdb instance in a new terminal window and have it attach to the plugin process and continue.
-						
-						    // The command we're constructing would look like this on the command line:
-						    // osascript -e 'tell application "Terminal"' -e 'set win to do script "gdb -pid 12345"' -e 'do script "continue" in win' -e 'end tell'
-
-						    LLProcess::Params params;
-						    params.executable = "/usr/bin/osascript";
-						    params.args.add("-e");
-						    params.args.add("tell application \"Terminal\"");
-						    params.args.add("-e");
-						    params.args.add(STRINGIZE("set win to do script \"lldb -pid "
-												      << mProcess->getProcessID() << "\""));
-						    params.args.add("-e");
-						    params.args.add("do script \"continue\" in win");
-						    params.args.add("-e");
-						    params.args.add("end tell");
-						    mDebugger = LLProcess::create(params);
+                            // If we're set to debug, start up a gdb instance in a new terminal window and have it attach to the plugin process and continue.
+
+                            // The command we're constructing would look like this on the command line:
+                            // osascript -e 'tell application "Terminal"' -e 'set win to do script "gdb -pid 12345"' -e 'do script "continue" in win' -e 'end tell'
+
+                            LLProcess::Params params;
+                            params.executable = "/usr/bin/osascript";
+                            params.args.add("-e");
+                            params.args.add("tell application \"Terminal\"");
+                            params.args.add("-e");
+                            params.args.add(STRINGIZE("set win to do script \"lldb -pid "
+                                                      << mProcess->getProcessID() << "\""));
+                            params.args.add("-e");
+                            params.args.add("do script \"continue\" in win");
+                            params.args.add("-e");
+                            params.args.add("end tell");
+                            mDebugger = LLProcess::create(params);
 
 #endif
-					    }
-					
-					    // This will allow us to time out if the process never starts.
-					    mHeartbeat.start();
-					    mHeartbeat.setTimerExpirySec(mPluginLaunchTimeout);
-					    setState(STATE_LAUNCHED);
-				    }
-				break;
-			    }
-
-			case STATE_LAUNCHED:
-			{
-				// waiting for the plugin to connect
-				if(pluginLockedUpOrQuit())
-				{
-					errorState();
-				}
-				// Check for the incoming connection.
-				else if (accept())
-				{
-					// Stop listening on the server port
-					mListenSocket.reset();
-					setState(STATE_CONNECTED);
-				}
-			    break;
-			}
-			
-			case STATE_CONNECTED:
-			{
-				// waiting for hello message from the plugin
-
-				if(pluginLockedUpOrQuit())
-				{
-					errorState();
-				}
-			    break;
-			}
-
-			case STATE_HELLO:
-			{
-				LL_DEBUGS("Plugin") << "received hello message" << LL_ENDL;
-				
-				// Send the message to load the plugin
-				{
-					LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "load_plugin");
-					message.setValue("file", mPluginFile);
-					message.setValue("dir", mPluginDir);
-					sendMessage(message);
-				}
-
-				setState(STATE_LOADING);
-			    break;
-			}
-			
-			case STATE_LOADING:
-			{
-				// The load_plugin_response message will kick us from here into STATE_RUNNING
-				if(pluginLockedUpOrQuit())
-				{
-					errorState();
-				}
-			    break;
-			}
-			
-			case STATE_RUNNING:
-			{
-				if(pluginLockedUpOrQuit())
-				{
-					errorState();
-				}
-			    break;
-			}
-			
+                        }
+
+                        // This will allow us to time out if the process never starts.
+                        mHeartbeat.start();
+                        mHeartbeat.setTimerExpirySec(mPluginLaunchTimeout);
+                        setState(STATE_LAUNCHED);
+                    }
+                break;
+                }
+
+            case STATE_LAUNCHED:
+            {
+                // waiting for the plugin to connect
+                if(pluginLockedUpOrQuit())
+                {
+                    errorState();
+                }
+                // Check for the incoming connection.
+                else if (accept())
+                {
+                    // Stop listening on the server port
+                    mListenSocket.reset();
+                    setState(STATE_CONNECTED);
+                }
+                break;
+            }
+
+            case STATE_CONNECTED:
+            {
+                // waiting for hello message from the plugin
+
+                if(pluginLockedUpOrQuit())
+                {
+                    errorState();
+                }
+                break;
+            }
+
+            case STATE_HELLO:
+            {
+                LL_DEBUGS("Plugin") << "received hello message" << LL_ENDL;
+
+                // Send the message to load the plugin
+                {
+                    LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "load_plugin");
+                    message.setValue("file", mPluginFile);
+                    message.setValue("dir", mPluginDir);
+                    sendMessage(message);
+                }
+
+                setState(STATE_LOADING);
+                break;
+            }
+
+            case STATE_LOADING:
+            {
+                // The load_plugin_response message will kick us from here into STATE_RUNNING
+                if(pluginLockedUpOrQuit())
+                {
+                    errorState();
+                }
+                break;
+            }
+
+            case STATE_RUNNING:
+            {
+                if(pluginLockedUpOrQuit())
+                {
+                    errorState();
+                }
+                break;
+            }
+
             case STATE_GOODBYE:
             {
-				{
+                {
                     LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "shutdown_plugin");
                     sendMessage(message);
                 }
                 setState(STATE_EXITING);
                 break;
-			}
-
-			case STATE_EXITING:
-			{
-				if (!LLProcess::isRunning(mProcess))
-				{
-					setState(STATE_CLEANUP);
-				}
-				else if(pluginLockedUp())
-				{
-					LL_WARNS("Plugin") << "timeout in exiting state, bailing out" << LL_ENDL;
-					errorState();
-				}
-    			break;
-			}
-
-			case STATE_LAUNCH_FAILURE:
-			{
-				if(mOwner != NULL)
-				{
-					mOwner->pluginLaunchFailed();
-				}
-				setState(STATE_CLEANUP);
-    			break;
-			}
-
-			case STATE_ERROR:
-			{
-				if(mOwner != NULL)
-				{
-					mOwner->pluginDied();
-				}
-				setState(STATE_CLEANUP);
-			    break;
-			}
-			
-			case STATE_CLEANUP:
-			{
-				LLProcess::kill(mProcess);
-				killSockets();
-				setState(STATE_DONE);
+            }
+
+            case STATE_EXITING:
+            {
+                if (!LLProcess::isRunning(mProcess))
+                {
+                    setState(STATE_CLEANUP);
+                }
+                else if(pluginLockedUp())
+                {
+                    LL_WARNS("Plugin") << "timeout in exiting state, bailing out" << LL_ENDL;
+                    errorState();
+                }
+                break;
+            }
+
+            case STATE_LAUNCH_FAILURE:
+            {
+                if(mOwner != NULL)
+                {
+                    mOwner->pluginLaunchFailed();
+                }
+                setState(STATE_CLEANUP);
+                break;
+            }
+
+            case STATE_ERROR:
+            {
+                if(mOwner != NULL)
+                {
+                    mOwner->pluginDied();
+                }
+                setState(STATE_CLEANUP);
+                break;
+            }
+
+            case STATE_CLEANUP:
+            {
+                LLProcess::kill(mProcess);
+                killSockets();
+                setState(STATE_DONE);
                 dirtyPollSet();
-			    break;
-			}
-			
-			case STATE_DONE:
-				// just sit here.
-    			break;
-		}
-
-	} 
-	while (idle_again);
+                break;
+            }
+
+            case STATE_DONE:
+                // just sit here.
+                break;
+        }
+
+    }
+    while (idle_again);
 }
 
 bool LLPluginProcessParent::isLoading(void)
 {
-	bool result = false;
-	
-	if(mState <= STATE_LOADING)
-		result = true;
-		
-	return result;
+    bool result = false;
+
+    if(mState <= STATE_LOADING)
+        result = true;
+
+    return result;
 }
 
 bool LLPluginProcessParent::isRunning(void)
 {
-	bool result = false;
-	
-	if(mState == STATE_RUNNING)
-		result = true;
-		
-	return result;
+    bool result = false;
+
+    if(mState == STATE_RUNNING)
+        result = true;
+
+    return result;
 }
 
 bool LLPluginProcessParent::isDone(void)
 {
-	bool result = false;
-	
-	if(mState == STATE_DONE)
-		result = true;
-		
-	return result;
+    bool result = false;
+
+    if(mState == STATE_DONE)
+        result = true;
+
+    return result;
 }
 
 void LLPluginProcessParent::setSleepTime(F64 sleep_time, bool force_send)
 {
-	if(force_send || (sleep_time != mSleepTime))
-	{
-		// Cache the time locally
-		mSleepTime = sleep_time;
-		
-		if(canSendMessage())
-		{
-			// and send to the plugin.
-			LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "sleep_time");
-			message.setValueReal("time", mSleepTime);
-			sendMessage(message);
-		}
-		else
-		{
-			// Too early to send -- the load_plugin_response message will trigger us to send mSleepTime later.
-		}
-	}
+    if(force_send || (sleep_time != mSleepTime))
+    {
+        // Cache the time locally
+        mSleepTime = sleep_time;
+
+        if(canSendMessage())
+        {
+            // and send to the plugin.
+            LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "sleep_time");
+            message.setValueReal("time", mSleepTime);
+            sendMessage(message);
+        }
+        else
+        {
+            // Too early to send -- the load_plugin_response message will trigger us to send mSleepTime later.
+        }
+    }
 }
 
 void LLPluginProcessParent::sendMessage(const LLPluginMessage &message)
 {
-	if(message.hasValue("blocking_response"))
-	{
-		mBlocked = false;
-
-		// reset the heartbeat timer, since there will have been no heartbeats while the plugin was blocked.
-		mHeartbeat.setTimerExpirySec(mPluginLockupTimeout);
-	}
-	
-	std::string buffer = message.generate();
+    if(message.hasValue("blocking_response"))
+    {
+        mBlocked = false;
+
+        // reset the heartbeat timer, since there will have been no heartbeats while the plugin was blocked.
+        mHeartbeat.setTimerExpirySec(mPluginLockupTimeout);
+    }
+
+    std::string buffer = message.generate();
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Plugin") << "Sending: " << buffer << LL_ENDL;	
+    LL_DEBUGS("Plugin") << "Sending: " << buffer << LL_ENDL;
 #endif
-	writeMessageRaw(buffer);
-	
-	// Try to send message immediately.
-	if(mMessagePipe)
-	{
-		mMessagePipe->pumpOutput();
-	}
+    writeMessageRaw(buffer);
+
+    // Try to send message immediately.
+    if(mMessagePipe)
+    {
+        mMessagePipe->pumpOutput();
+    }
 }
 
-//virtual 
+//virtual
 void LLPluginProcessParent::setMessagePipe(LLPluginMessagePipe *message_pipe)
 {
-	bool update_pollset = false;
-	
-	if(mMessagePipe)
-	{
-		// Unsetting an existing message pipe -- remove from the pollset		
-		mPollFD.client_data = NULL;
-
-		// pollset needs an update
-		update_pollset = true;
-	}
-	if(message_pipe != NULL)
-	{
-		// Set up the apr_pollfd_t
-		mPollFD.p = gAPRPoolp;
-		mPollFD.desc_type = APR_POLL_SOCKET;
-		mPollFD.reqevents = APR_POLLIN|APR_POLLERR|APR_POLLHUP;
-		mPollFD.rtnevents = 0;
-		mPollFD.desc.s = mSocket->getSocket();
-		mPollFD.client_data = (void*)this;	
-		
-		// pollset needs an update
-		update_pollset = true;
-	}
-
-	mMessagePipe = message_pipe;
-	
-	if(update_pollset)
-	{
-		dirtyPollSet();
-	}
+    bool update_pollset = false;
+
+    if(mMessagePipe)
+    {
+        // Unsetting an existing message pipe -- remove from the pollset
+        mPollFD.client_data = NULL;
+
+        // pollset needs an update
+        update_pollset = true;
+    }
+    if(message_pipe != NULL)
+    {
+        // Set up the apr_pollfd_t
+        mPollFD.p = gAPRPoolp;
+        mPollFD.desc_type = APR_POLL_SOCKET;
+        mPollFD.reqevents = APR_POLLIN|APR_POLLERR|APR_POLLHUP;
+        mPollFD.rtnevents = 0;
+        mPollFD.desc.s = mSocket->getSocket();
+        mPollFD.client_data = (void*)this;
+
+        // pollset needs an update
+        update_pollset = true;
+    }
+
+    mMessagePipe = message_pipe;
+
+    if(update_pollset)
+    {
+        dirtyPollSet();
+    }
 }
 
-//static 
+//static
 void LLPluginProcessParent::dirtyPollSet()
 {
-	sPollsetNeedsRebuild = true;
-	
-	if(sReadThread)
-	{
-		LL_DEBUGS("PluginPoll") << "unpausing read thread " << LL_ENDL;
-		sReadThread->unpause();
-	}
+    sPollsetNeedsRebuild = true;
+
+    if(sReadThread)
+    {
+        LL_DEBUGS("PluginPoll") << "unpausing read thread " << LL_ENDL;
+        sReadThread->unpause();
+    }
 }
 
 void LLPluginProcessParent::updatePollset()
 {
-	LLMutexLock lock(sInstancesMutex);
-	if (sInstances.empty())
-	{
-		// No instances have been created yet.  There's no work to do.
-		return;
-	}
-
-	if(sPollSet)
-	{
-		LL_DEBUGS("PluginPoll") << "destroying pollset " << sPollSet << LL_ENDL;
-		// delete the existing pollset.
-		apr_pollset_destroy(sPollSet);
-		sPollSet = NULL;
-	}
-	
-	// Count the number of instances that want to be in the pollset
-	S32 count = 0;
-	for(auto iter = sInstances.begin(); iter != sInstances.end(); iter++)
-	{
-		(*iter).second->mPolledInput = false;
+    LLMutexLock lock(sInstancesMutex);
+    if (sInstances.empty())
+    {
+        // No instances have been created yet.  There's no work to do.
+        return;
+    }
+
+    if(sPollSet)
+    {
+        LL_DEBUGS("PluginPoll") << "destroying pollset " << sPollSet << LL_ENDL;
+        // delete the existing pollset.
+        apr_pollset_destroy(sPollSet);
+        sPollSet = NULL;
+    }
+
+    // Count the number of instances that want to be in the pollset
+    S32 count = 0;
+    for(auto iter = sInstances.begin(); iter != sInstances.end(); iter++)
+    {
+        (*iter).second->mPolledInput = false;
         if ((*iter).second->wantsPolling())
-		{
-			// This instance has a socket that needs to be polled.
-			++count;
-		}
-	}
-
-	if(sUseReadThread && sReadThread && !sReadThread->isQuitting())
-	{
-		if(!sPollSet && (count > 0))
-		{
+        {
+            // This instance has a socket that needs to be polled.
+            ++count;
+        }
+    }
+
+    if(sUseReadThread && sReadThread && !sReadThread->isQuitting())
+    {
+        if(!sPollSet && (count > 0))
+        {
 #ifdef APR_POLLSET_NOCOPY
-			// The pollset doesn't exist yet.  Create it now.
-			apr_status_t status = apr_pollset_create(&sPollSet, count, gAPRPoolp, APR_POLLSET_NOCOPY);
-			if(status != APR_SUCCESS)
-			{
+            // The pollset doesn't exist yet.  Create it now.
+            apr_status_t status = apr_pollset_create(&sPollSet, count, gAPRPoolp, APR_POLLSET_NOCOPY);
+            if(status != APR_SUCCESS)
+            {
 #endif // APR_POLLSET_NOCOPY
-				LL_WARNS("PluginPoll") << "Couldn't create pollset.  Falling back to non-pollset mode." << LL_ENDL;
-				sPollSet = NULL;
+                LL_WARNS("PluginPoll") << "Couldn't create pollset.  Falling back to non-pollset mode." << LL_ENDL;
+                sPollSet = NULL;
 #ifdef APR_POLLSET_NOCOPY
-			}
-			else
-			{
-				LL_DEBUGS("PluginPoll") << "created pollset " << sPollSet << LL_ENDL;
-				
-				// Pollset was created, add all instances to it.
-				for(auto iter = sInstances.begin(); iter != sInstances.end(); iter++)
-				{
+            }
+            else
+            {
+                LL_DEBUGS("PluginPoll") << "created pollset " << sPollSet << LL_ENDL;
+
+                // Pollset was created, add all instances to it.
+                for(auto iter = sInstances.begin(); iter != sInstances.end(); iter++)
+                {
                     if (iter->second->wantsPolling())
-					{
-						status = apr_pollset_add(sPollSet, &((*iter).second->mPollFD));
-						if(status == APR_SUCCESS)
-						{
-							(*iter).second->mPolledInput = true;
-						}
-						else
-						{
-							LL_WARNS("PluginPoll") << "apr_pollset_add failed with status " << status << LL_ENDL;
-						}
-					}
-				}
-			}
+                    {
+                        status = apr_pollset_add(sPollSet, &((*iter).second->mPollFD));
+                        if(status == APR_SUCCESS)
+                        {
+                            (*iter).second->mPolledInput = true;
+                        }
+                        else
+                        {
+                            LL_WARNS("PluginPoll") << "apr_pollset_add failed with status " << status << LL_ENDL;
+                        }
+                    }
+                }
+            }
 #endif // APR_POLLSET_NOCOPY
-		}
-	}
+        }
+    }
 }
 
 void LLPluginProcessParent::setUseReadThread(bool use_read_thread)
 {
-	if(sUseReadThread != use_read_thread)
-	{
-		sUseReadThread = use_read_thread;
-		
-		if(sUseReadThread)
-		{
-			if(!sReadThread)
-			{
-				// start up the read thread
-				LL_INFOS("PluginPoll") << "creating read thread " << LL_ENDL;
-
-				// make sure the pollset gets rebuilt.
-				sPollsetNeedsRebuild = true;
-				
-				sReadThread = new LLPluginProcessParentPollThread;
-				sReadThread->start();
-			}
-		}
-		else
-		{
-			if(sReadThread)
-			{
-				// shut down the read thread
-				LL_INFOS("PluginPoll") << "destroying read thread " << LL_ENDL;
-				delete sReadThread;
-				sReadThread = NULL;
-			}
-		}
-
-	}
+    if(sUseReadThread != use_read_thread)
+    {
+        sUseReadThread = use_read_thread;
+
+        if(sUseReadThread)
+        {
+            if(!sReadThread)
+            {
+                // start up the read thread
+                LL_INFOS("PluginPoll") << "creating read thread " << LL_ENDL;
+
+                // make sure the pollset gets rebuilt.
+                sPollsetNeedsRebuild = true;
+
+                sReadThread = new LLPluginProcessParentPollThread;
+                sReadThread->start();
+            }
+        }
+        else
+        {
+            if(sReadThread)
+            {
+                // shut down the read thread
+                LL_INFOS("PluginPoll") << "destroying read thread " << LL_ENDL;
+                delete sReadThread;
+                sReadThread = NULL;
+            }
+        }
+
+    }
 }
 
 bool LLPluginProcessParent::poll(F64 timeout)
 {
-	{	
-		LLMutexLock mtxLock(sInstancesMutex);
-		if (sInstances.empty())
-		{
-			return false;
-		}
-	}
-
-	bool active = false;
-
-	if(sPollsetNeedsRebuild || !sUseReadThread)
-	{
-		sPollsetNeedsRebuild = false;
-		updatePollset();
-	}
-	
-	if(sPollSet)
-	{
-		apr_status_t status;
-		apr_int32_t count;
-		const apr_pollfd_t *descriptors;
-		status = apr_pollset_poll(sPollSet, (apr_interval_time_t)(timeout * 1000000), &count, &descriptors);
-		if(status == APR_SUCCESS)
-		{
-			// One or more of the descriptors signalled.  Call them.
+    {
+        LLMutexLock mtxLock(sInstancesMutex);
+        if (sInstances.empty())
+        {
+            return false;
+        }
+    }
+
+    bool active = false;
+
+    if(sPollsetNeedsRebuild || !sUseReadThread)
+    {
+        sPollsetNeedsRebuild = false;
+        updatePollset();
+    }
+
+    if(sPollSet)
+    {
+        apr_status_t status;
+        apr_int32_t count;
+        const apr_pollfd_t *descriptors;
+        status = apr_pollset_poll(sPollSet, (apr_interval_time_t)(timeout * 1000000), &count, &descriptors);
+        if(status == APR_SUCCESS)
+        {
+            // One or more of the descriptors signalled.  Call them.
             for (int i = 0; i < count; i++)
             {
                 void *thatId = descriptors[i].client_data;
@@ -985,338 +985,338 @@ bool LLPluginProcessParent::poll(F64 timeout)
 
                 if (that)
                 {
-					LLMutexLock incoming_lock(&that->mIncomingQueueMutex);
+                    LLMutexLock incoming_lock(&that->mIncomingQueueMutex);
                     that->servicePoll();
                  }
 
-			}
-			active = true;	// Plugin is active
-		}
-		else if(APR_STATUS_IS_TIMEUP(status))
-		{
-			// timed out with no incoming data.  Just return.
-		}
-		else if(status == EBADF)
-		{
-			// This happens when one of the file descriptors in the pollset is destroyed, which happens whenever a plugin's socket is closed.
-			// The pollset has been or will be recreated, so just return.
-			LL_DEBUGS("PluginPoll") << "apr_pollset_poll returned EBADF" << LL_ENDL;
-		}
-		else if(status != APR_SUCCESS)
-		{
-			LL_WARNS("PluginPoll") << "apr_pollset_poll failed with status " << status << LL_ENDL;
-		}
-	}
+            }
+            active = true;  // Plugin is active
+        }
+        else if(APR_STATUS_IS_TIMEUP(status))
+        {
+            // timed out with no incoming data.  Just return.
+        }
+        else if(status == EBADF)
+        {
+            // This happens when one of the file descriptors in the pollset is destroyed, which happens whenever a plugin's socket is closed.
+            // The pollset has been or will be recreated, so just return.
+            LL_DEBUGS("PluginPoll") << "apr_pollset_poll returned EBADF" << LL_ENDL;
+        }
+        else if(status != APR_SUCCESS)
+        {
+            LL_WARNS("PluginPoll") << "apr_pollset_poll failed with status " << status << LL_ENDL;
+        }
+    }
 
     // Remove instances in the done state from the sInstances map.
-	{
-		LLMutexLock inst_lock(sInstancesMutex);
-		mapInstances_t::iterator itClean = sInstances.begin();
-		while (itClean != sInstances.end())
-		{
-			if (itClean->second->isDone())
-            	itClean = sInstances.erase(itClean);
-			else
-				++itClean;
-		}
-	}
-	return active;
+    {
+        LLMutexLock inst_lock(sInstancesMutex);
+        mapInstances_t::iterator itClean = sInstances.begin();
+        while (itClean != sInstances.end())
+        {
+            if (itClean->second->isDone())
+                itClean = sInstances.erase(itClean);
+            else
+                ++itClean;
+        }
+    }
+    return active;
 }
 
 void LLPluginProcessParent::servicePoll()
 {
-	bool result = true;
-	
-	// poll signalled on this object's socket.  Try to process incoming messages.
-	if(mMessagePipe)
-	{
-		result = mMessagePipe->pumpInput(0.0f);
-	}
-
-	if(!result)
-	{
-		// If we got a read error on input, remove this pipe from the pollset
-		apr_pollset_remove(sPollSet, &mPollFD);
-
-		// and tell the code not to re-add it
-		mPollFD.client_data = NULL;
-	}
+    bool result = true;
+
+    // poll signalled on this object's socket.  Try to process incoming messages.
+    if(mMessagePipe)
+    {
+        result = mMessagePipe->pumpInput(0.0f);
+    }
+
+    if(!result)
+    {
+        // If we got a read error on input, remove this pipe from the pollset
+        apr_pollset_remove(sPollSet, &mPollFD);
+
+        // and tell the code not to re-add it
+        mPollFD.client_data = NULL;
+    }
 }
 
 void LLPluginProcessParent::receiveMessageRaw(const std::string &message)
 {
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Plugin") << "Received: " << message << LL_ENDL;
+    LL_DEBUGS("Plugin") << "Received: " << message << LL_ENDL;
 #endif
-	
-	LLPluginMessage parsed;
-	if(LLSDParser::PARSE_FAILURE != parsed.parse(message))
-	{
-		if(parsed.hasValue("blocking_request"))
-		{
-			mBlocked = true;
-		}
-
-		if(mPolledInput)
-		{
-			// This is being called on the polling thread -- only do minimal processing/queueing.
-			receiveMessageEarly(parsed);
-		}
-		else
-		{
-			// This is not being called on the polling thread -- do full message processing at this time.
-			receiveMessage(parsed);
-		}
-	}
+
+    LLPluginMessage parsed;
+    if(LLSDParser::PARSE_FAILURE != parsed.parse(message))
+    {
+        if(parsed.hasValue("blocking_request"))
+        {
+            mBlocked = true;
+        }
+
+        if(mPolledInput)
+        {
+            // This is being called on the polling thread -- only do minimal processing/queueing.
+            receiveMessageEarly(parsed);
+        }
+        else
+        {
+            // This is not being called on the polling thread -- do full message processing at this time.
+            receiveMessage(parsed);
+        }
+    }
 }
 
 void LLPluginProcessParent::receiveMessageEarly(const LLPluginMessage &message)
 {
-	// NOTE: this function will be called from the polling thread.  It will be called with mIncomingQueueMutex _already locked_. 
-
-	bool handled = false;
-	
-	std::string message_class = message.getClass();
-	if(message_class == LLPLUGIN_MESSAGE_CLASS_INTERNAL)
-	{
-		// no internal messages need to be handled early.
-	}
-	else
-	{
-		// Call out to the owner and see if they to reply
-		// TODO: Should this only happen when blocked?
-		if(mOwner != NULL)
-		{
-			handled = mOwner->receivePluginMessageEarly(message);
-		}
-	}
-	
-	if(!handled)
-	{
-		// any message that wasn't handled early needs to be queued.
-		mIncomingQueue.push_back(message);
-	}
+    // NOTE: this function will be called from the polling thread.  It will be called with mIncomingQueueMutex _already locked_.
+
+    bool handled = false;
+
+    std::string message_class = message.getClass();
+    if(message_class == LLPLUGIN_MESSAGE_CLASS_INTERNAL)
+    {
+        // no internal messages need to be handled early.
+    }
+    else
+    {
+        // Call out to the owner and see if they to reply
+        // TODO: Should this only happen when blocked?
+        if(mOwner != NULL)
+        {
+            handled = mOwner->receivePluginMessageEarly(message);
+        }
+    }
+
+    if(!handled)
+    {
+        // any message that wasn't handled early needs to be queued.
+        mIncomingQueue.push_back(message);
+    }
 }
 
 void LLPluginProcessParent::receiveMessage(const LLPluginMessage &message)
 {
-	std::string message_class = message.getClass();
-	if(message_class == LLPLUGIN_MESSAGE_CLASS_INTERNAL)
-	{
-		// internal messages should be handled here
-		std::string message_name = message.getName();
-		if(message_name == "hello")
-		{
-			if(mState == STATE_CONNECTED)
-			{
-				// Plugin host has launched.  Tell it which plugin to load.
-				setState(STATE_HELLO);
-			}
-			else
-			{
-				LL_WARNS("Plugin") << "received hello message in wrong state -- bailing out" << LL_ENDL;
-				errorState();
-			}
-			
-		}
-		else if(message_name == "load_plugin_response")
-		{
-			if(mState == STATE_LOADING)
-			{
-				// Plugin has been loaded. 
-				
-				mPluginVersionString = message.getValue("plugin_version");
-				LL_INFOS("Plugin") << "plugin version string: " << mPluginVersionString << LL_ENDL;
-
-				// Check which message classes/versions the plugin supports.
-				// TODO: check against current versions
-				// TODO: kill plugin on major mismatches?
-				mMessageClassVersions = message.getValueLLSD("versions");
-				LLSD::map_iterator iter;
-				for(iter = mMessageClassVersions.beginMap(); iter != mMessageClassVersions.endMap(); iter++)
-				{
-					LL_INFOS("Plugin") << "message class: " << iter->first << " -> version: " << iter->second.asString() << LL_ENDL;
-				}
-				
-				// Send initial sleep time
-				llassert_always(mSleepTime != 0.f);
-				setSleepTime(mSleepTime, true);			
-
-				setState(STATE_RUNNING);
-			}
-			else
-			{
-				LL_WARNS("Plugin") << "received load_plugin_response message in wrong state -- bailing out" << LL_ENDL;
-				errorState();
-			}
-		}
-		else if(message_name == "heartbeat")
-		{
-			// this resets our timer.
-			mHeartbeat.setTimerExpirySec(mPluginLockupTimeout);
-
-			mCPUUsage = message.getValueReal("cpu_usage");
+    std::string message_class = message.getClass();
+    if(message_class == LLPLUGIN_MESSAGE_CLASS_INTERNAL)
+    {
+        // internal messages should be handled here
+        std::string message_name = message.getName();
+        if(message_name == "hello")
+        {
+            if(mState == STATE_CONNECTED)
+            {
+                // Plugin host has launched.  Tell it which plugin to load.
+                setState(STATE_HELLO);
+            }
+            else
+            {
+                LL_WARNS("Plugin") << "received hello message in wrong state -- bailing out" << LL_ENDL;
+                errorState();
+            }
+
+        }
+        else if(message_name == "load_plugin_response")
+        {
+            if(mState == STATE_LOADING)
+            {
+                // Plugin has been loaded.
+
+                mPluginVersionString = message.getValue("plugin_version");
+                LL_INFOS("Plugin") << "plugin version string: " << mPluginVersionString << LL_ENDL;
+
+                // Check which message classes/versions the plugin supports.
+                // TODO: check against current versions
+                // TODO: kill plugin on major mismatches?
+                mMessageClassVersions = message.getValueLLSD("versions");
+                LLSD::map_iterator iter;
+                for(iter = mMessageClassVersions.beginMap(); iter != mMessageClassVersions.endMap(); iter++)
+                {
+                    LL_INFOS("Plugin") << "message class: " << iter->first << " -> version: " << iter->second.asString() << LL_ENDL;
+                }
+
+                // Send initial sleep time
+                llassert_always(mSleepTime != 0.f);
+                setSleepTime(mSleepTime, true);
+
+                setState(STATE_RUNNING);
+            }
+            else
+            {
+                LL_WARNS("Plugin") << "received load_plugin_response message in wrong state -- bailing out" << LL_ENDL;
+                errorState();
+            }
+        }
+        else if(message_name == "heartbeat")
+        {
+            // this resets our timer.
+            mHeartbeat.setTimerExpirySec(mPluginLockupTimeout);
+
+            mCPUUsage = message.getValueReal("cpu_usage");
 #ifdef SHOW_DEBUG
-			LL_DEBUGS("Plugin") << "cpu usage reported as " << mCPUUsage << LL_ENDL;
+            LL_DEBUGS("Plugin") << "cpu usage reported as " << mCPUUsage << LL_ENDL;
 #endif
-			
-		}
-		else if(message_name == "shm_add_response")
-		{
-			// Nothing to do here.
-		}
-		else if(message_name == "shm_remove_response")
-		{
-			std::string name = message.getValue("name");
-			sharedMemoryRegionsType::iterator iter = mSharedMemoryRegions.find(name);
-			
-			if(iter != mSharedMemoryRegions.end())
-			{
-				// destroy the shared memory region
-				iter->second->destroy();
-				delete iter->second;
-				iter->second = NULL;
-				
-				// and remove it from our map
-				mSharedMemoryRegions.erase(iter);
-			}
-		}
-		else
-		{
-			LL_WARNS("Plugin") << "Unknown internal message from child: " << message_name << LL_ENDL;
-		}
-	}
-	else
-	{
-		if(mOwner != NULL)
-		{
-			mOwner->receivePluginMessage(message);
-		}
-	}
+
+        }
+        else if(message_name == "shm_add_response")
+        {
+            // Nothing to do here.
+        }
+        else if(message_name == "shm_remove_response")
+        {
+            std::string name = message.getValue("name");
+            sharedMemoryRegionsType::iterator iter = mSharedMemoryRegions.find(name);
+
+            if(iter != mSharedMemoryRegions.end())
+            {
+                // destroy the shared memory region
+                iter->second->destroy();
+                delete iter->second;
+                iter->second = NULL;
+
+                // and remove it from our map
+                mSharedMemoryRegions.erase(iter);
+            }
+        }
+        else
+        {
+            LL_WARNS("Plugin") << "Unknown internal message from child: " << message_name << LL_ENDL;
+        }
+    }
+    else
+    {
+        if(mOwner != NULL)
+        {
+            mOwner->receivePluginMessage(message);
+        }
+    }
 }
 
 std::string LLPluginProcessParent::addSharedMemory(size_t size)
 {
-	std::string name;
-	
-	LLPluginSharedMemory *region = new LLPluginSharedMemory;
-
-	// This is a new region
-	if(region->create(size))
-	{
-		name = region->getName();
-		
-		mSharedMemoryRegions.insert(sharedMemoryRegionsType::value_type(name, region));
-		
-		LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "shm_add");
-		message.setValue("name", name);
-		message.setValueS32("size", (S32)size);
-		sendMessage(message);
-	}
-	else
-	{
-		LL_WARNS("Plugin") << "Couldn't create a shared memory segment!" << LL_ENDL;
-
-		// Don't leak
-		delete region;
-	}
-
-	return name;
+    std::string name;
+
+    LLPluginSharedMemory *region = new LLPluginSharedMemory;
+
+    // This is a new region
+    if(region->create(size))
+    {
+        name = region->getName();
+
+        mSharedMemoryRegions.insert(sharedMemoryRegionsType::value_type(name, region));
+
+        LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "shm_add");
+        message.setValue("name", name);
+        message.setValueS32("size", (S32)size);
+        sendMessage(message);
+    }
+    else
+    {
+        LL_WARNS("Plugin") << "Couldn't create a shared memory segment!" << LL_ENDL;
+
+        // Don't leak
+        delete region;
+    }
+
+    return name;
 }
 
 void LLPluginProcessParent::removeSharedMemory(const std::string &name)
 {
-	sharedMemoryRegionsType::iterator iter = mSharedMemoryRegions.find(name);
-	
-	if(iter != mSharedMemoryRegions.end())
-	{
-		// This segment exists.  Send the message to the child to unmap it.  The response will cause the parent to unmap our end.
-		LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "shm_remove");
-		message.setValue("name", name);
-		sendMessage(message);
-	}
-	else
-	{
-		LL_WARNS("Plugin") << "Request to remove an unknown shared memory segment." << LL_ENDL;
-	}
+    sharedMemoryRegionsType::iterator iter = mSharedMemoryRegions.find(name);
+
+    if(iter != mSharedMemoryRegions.end())
+    {
+        // This segment exists.  Send the message to the child to unmap it.  The response will cause the parent to unmap our end.
+        LLPluginMessage message(LLPLUGIN_MESSAGE_CLASS_INTERNAL, "shm_remove");
+        message.setValue("name", name);
+        sendMessage(message);
+    }
+    else
+    {
+        LL_WARNS("Plugin") << "Request to remove an unknown shared memory segment." << LL_ENDL;
+    }
 }
 size_t LLPluginProcessParent::getSharedMemorySize(const std::string &name)
 {
-	size_t result = 0;
-	
-	sharedMemoryRegionsType::iterator iter = mSharedMemoryRegions.find(name);
-	if(iter != mSharedMemoryRegions.end())
-	{
-		result = iter->second->getSize();
-	}
-	
-	return result;
+    size_t result = 0;
+
+    sharedMemoryRegionsType::iterator iter = mSharedMemoryRegions.find(name);
+    if(iter != mSharedMemoryRegions.end())
+    {
+        result = iter->second->getSize();
+    }
+
+    return result;
 }
 void *LLPluginProcessParent::getSharedMemoryAddress(const std::string &name)
 {
-	void *result = NULL;
-	
-	sharedMemoryRegionsType::iterator iter = mSharedMemoryRegions.find(name);
-	if(iter != mSharedMemoryRegions.end())
-	{
-		result = iter->second->getMappedAddress();
-	}
-	
-	return result;
+    void *result = NULL;
+
+    sharedMemoryRegionsType::iterator iter = mSharedMemoryRegions.find(name);
+    if(iter != mSharedMemoryRegions.end())
+    {
+        result = iter->second->getMappedAddress();
+    }
+
+    return result;
 }
 
 std::string LLPluginProcessParent::getMessageClassVersion(const std::string &message_class)
 {
-	std::string result;
-	
-	if(mMessageClassVersions.has(message_class))
-	{
-		result = mMessageClassVersions[message_class].asString();
-	}
-	
-	return result;
+    std::string result;
+
+    if(mMessageClassVersions.has(message_class))
+    {
+        result = mMessageClassVersions[message_class].asString();
+    }
+
+    return result;
 }
 
 std::string LLPluginProcessParent::getPluginVersion(void)
 {
-	return mPluginVersionString;
+    return mPluginVersionString;
 }
 
 void LLPluginProcessParent::setState(EState state)
 {
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Plugin") << "setting state to " << state << LL_ENDL;
+    LL_DEBUGS("Plugin") << "setting state to " << state << LL_ENDL;
 #endif
-	mState = state; 
+    mState = state;
 };
 
 bool LLPluginProcessParent::pluginLockedUpOrQuit()
 {
-	bool result = false;
-	
-	if (! LLProcess::isRunning(mProcess))
-	{
-		LL_WARNS("Plugin") << "child exited" << LL_ENDL;
-		result = true;
-	}
-	else if(pluginLockedUp())
-	{
-		LL_WARNS("Plugin") << "timeout" << LL_ENDL;
-		result = true;
-	}
-	
-	return result;
+    bool result = false;
+
+    if (! LLProcess::isRunning(mProcess))
+    {
+        LL_WARNS("Plugin") << "child exited" << LL_ENDL;
+        result = true;
+    }
+    else if(pluginLockedUp())
+    {
+        LL_WARNS("Plugin") << "timeout" << LL_ENDL;
+        result = true;
+    }
+
+    return result;
 }
 
 bool LLPluginProcessParent::pluginLockedUp()
 {
-	if(mDisableTimeout || mDebug || mBlocked)
-	{
-		// Never time out a plugin process in these cases.
-		return false;
-	}
-	
-	// If the timer is running and has expired, the plugin has locked up.
-	return (mHeartbeat.getStarted() && mHeartbeat.hasExpired());
+    if(mDisableTimeout || mDebug || mBlocked)
+    {
+        // Never time out a plugin process in these cases.
+        return false;
+    }
+
+    // If the timer is running and has expired, the plugin has locked up.
+    return (mHeartbeat.getStarted() && mHeartbeat.hasExpired());
 }
 
diff --git a/indra/llprimitive/llprimitive.cpp b/indra/llprimitive/llprimitive.cpp
index f2d2f06bc819fb315f7ad2d634f4de8fcdaf42da..401771784115a03df322c9f2961885f092d44d18 100644
--- a/indra/llprimitive/llprimitive.cpp
+++ b/indra/llprimitive/llprimitive.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llprimitive.cpp
  * @brief LLPrimitive base class
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -57,9 +57,9 @@ const F32 OBJECT_TWIST_INC =   18.f;
 
 // This is used for linear paths,
 // since twist is used in a slightly different manner.
-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_TWIST_LINEAR_MIN   = -180.f;
+const F32 OBJECT_TWIST_LINEAR_MAX   =  180.f;
+const F32 OBJECT_TWIST_LINEAR_INC   =    9.f;
 
 const F32 SL_OBJECT_MIN_HOLE_SIZE = 0.05f;
 const F32 OS_OBJECT_MIN_HOLE_SIZE = 0.01f;
@@ -98,7 +98,7 @@ const F32 REFLECTION_PROBE_DEFAULT_CLIP_DISTANCE = 0.f;
 // "Tension" => [0,10], increments of 0.1
 const F32 FLEXIBLE_OBJECT_MIN_TENSION = 0.0f;
 const F32 FLEXIBLE_OBJECT_DEFAULT_TENSION = 1.0f;
-const F32 FLEXIBLE_OBJECT_MAX_TENSION = 10.0f; 
+const F32 FLEXIBLE_OBJECT_MAX_TENSION = 10.0f;
 
 // "Drag" => [0,10], increments of 0.1
 const F32 FLEXIBLE_OBJECT_MIN_AIR_FRICTION = 0.0f;
@@ -116,7 +116,7 @@ const F32 FLEXIBLE_OBJECT_DEFAULT_WIND_SENSITIVITY = 0.0f;
 const F32 FLEXIBLE_OBJECT_MAX_WIND_SENSITIVITY = 10.0f;
 
 // I'll explain later...
-const F32 FLEXIBLE_OBJECT_MAX_INTERNAL_TENSION_FORCE = 0.99f; 
+const F32 FLEXIBLE_OBJECT_MAX_INTERNAL_TENSION_FORCE = 0.99f;
 
 const F32 FLEXIBLE_OBJECT_DEFAULT_LENGTH = 1.0f;
 const BOOL FLEXIBLE_OBJECT_DEFAULT_USING_COLLISION_SPHERE = FALSE;
@@ -125,9 +125,9 @@ const BOOL FLEXIBLE_OBJECT_DEFAULT_RENDERING_COLLISION_SPHERE = FALSE;
 const LLUUID SCULPT_DEFAULT_TEXTURE("be293869-d0d9-0a69-5989-ad27f1946fd4"); // old inverted texture: "7595d345-a24c-e7ef-f0bd-78793792133e";
 
 // Texture rotations are sent over the wire as a S16.  This is used to scale the actual float
-// value to a S16.   Don't use 7FFF as it introduces some odd rounding with 180 since it 
+// value to a S16.   Don't use 7FFF as it introduces some odd rounding with 180 since it
 // can't be divided by 2.   See DEV-19108
-const F32	TEXTURE_ROTATION_PACK_FACTOR = ((F32) 0x08000);
+const F32   TEXTURE_ROTATION_PACK_FACTOR = ((F32) 0x08000);
 
 struct material_id_type // originally from llrendermaterialtable
 {
@@ -158,7 +158,7 @@ struct material_id_type // originally from llrendermaterialtable
 
 const U8 material_id_type::s_null_id[] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
 
-//static 
+//static
 // LEGACY: by default we use the LLVolumeMgr::gVolumeMgr global
 // TODO -- eliminate this global from the codebase!
 LLVolumeMgr* LLPrimitive::sVolumeManager = NULL;
@@ -166,61 +166,61 @@ LLVolumeMgr* LLPrimitive::sVolumeManager = NULL;
 // static
 void LLPrimitive::setVolumeManager( LLVolumeMgr* volume_manager )
 {
-	if ( !volume_manager || sVolumeManager )
-	{
-		LL_ERRS() << "LLPrimitive::sVolumeManager attempting to be set to NULL or it already has been set." << LL_ENDL;
-	}
-	sVolumeManager = volume_manager;
+    if ( !volume_manager || sVolumeManager )
+    {
+        LL_ERRS() << "LLPrimitive::sVolumeManager attempting to be set to NULL or it already has been set." << LL_ENDL;
+    }
+    sVolumeManager = volume_manager;
 }
 
 // static
 bool LLPrimitive::cleanupVolumeManager()
 {
-	BOOL res = FALSE;
-	if (sVolumeManager) 
-	{
-		res = sVolumeManager->cleanup();
-		delete sVolumeManager;
-		sVolumeManager = NULL;
-	}
-	return res;
+    BOOL res = FALSE;
+    if (sVolumeManager)
+    {
+        res = sVolumeManager->cleanup();
+        delete sVolumeManager;
+        sVolumeManager = NULL;
+    }
+    return res;
 }
 
 
 //===============================================================
 LLPrimitive::LLPrimitive()
-:	mTextureList(),
-	mNumTEs(0),
-	mMiscFlags(0),
-	mNumBumpmapTEs(0)
+:   mTextureList(),
+    mNumTEs(0),
+    mMiscFlags(0),
+    mNumBumpmapTEs(0)
 {
-	mPrimitiveCode = 0;
+    mPrimitiveCode = 0;
 
-	mMaterial = LL_MCODE_STONE;
-	mVolumep  = NULL;
+    mMaterial = LL_MCODE_STONE;
+    mVolumep  = NULL;
 
-	mChanged  = UNCHANGED;
+    mChanged  = UNCHANGED;
 
-	mPosition.setVec(0.f,0.f,0.f);
-	mVelocity.setVec(0.f,0.f,0.f);
-	mAcceleration.setVec(0.f,0.f,0.f);
+    mPosition.setVec(0.f,0.f,0.f);
+    mVelocity.setVec(0.f,0.f,0.f);
+    mAcceleration.setVec(0.f,0.f,0.f);
 
-	mRotation.loadIdentity();
-	mAngularVelocity.setVec(0.f,0.f,0.f);
-	
-	mScale.setVec(1.f,1.f,1.f);
+    mRotation.loadIdentity();
+    mAngularVelocity.setVec(0.f,0.f,0.f);
+
+    mScale.setVec(1.f,1.f,1.f);
 }
 
 //===============================================================
 LLPrimitive::~LLPrimitive()
 {
-	clearTextureList();
-	// Cleanup handled by volume manager
-	if (mVolumep && sVolumeManager)
-	{
-		sVolumeManager->unrefVolume(mVolumep);
-	}
-	mVolumep = NULL;
+    clearTextureList();
+    // Cleanup handled by volume manager
+    if (mVolumep && sVolumeManager)
+    {
+        sVolumeManager->unrefVolume(mVolumep);
+    }
+    mVolumep = NULL;
 }
 
 void LLPrimitive::clearTextureList()
@@ -231,83 +231,83 @@ void LLPrimitive::clearTextureList()
 // static
 LLPrimitive *LLPrimitive::createPrimitive(LLPCode p_code)
 {
-	LLPrimitive *retval = new LLPrimitive();
-	
-	if (retval)
-	{
-		retval->init_primitive(p_code);
-	}
-	else
-	{
-		LL_ERRS() << "primitive allocation failed" << LL_ENDL;
-	}
+    LLPrimitive *retval = new LLPrimitive();
 
-	return retval;
+    if (retval)
+    {
+        retval->init_primitive(p_code);
+    }
+    else
+    {
+        LL_ERRS() << "primitive allocation failed" << LL_ENDL;
+    }
+
+    return retval;
 }
 
 //===============================================================
 void LLPrimitive::init_primitive(LLPCode p_code)
 {
-	clearTextureList();
-	mPrimitiveCode = p_code;
+    clearTextureList();
+    mPrimitiveCode = p_code;
 }
 
 void LLPrimitive::setPCode(const U8 p_code)
 {
-	mPrimitiveCode = p_code;
+    mPrimitiveCode = p_code;
 }
 
 //===============================================================
 LLTextureEntry* LLPrimitive::getTE(const U8 index) const
 {
-	return mTextureList.getTexture(index);
+    return mTextureList.getTexture(index);
 }
 
 //===============================================================
 void LLPrimitive::setNumTEs(const U8 num_tes)
 {
-	mTextureList.setSize(num_tes);
+    mTextureList.setSize(num_tes);
 }
 
 //===============================================================
 void  LLPrimitive::setAllTETextures(const LLUUID &tex_id)
 {
-	mTextureList.setAllIDs(tex_id);
+    mTextureList.setAllIDs(tex_id);
 }
 
 //===============================================================
 void LLPrimitive::setTE(const U8 index, const LLTextureEntry& te)
 {
-	if(mTextureList.copyTexture(index, te) != TEM_CHANGE_NONE && te.getBumpmap() > 0)
-	{
-		mNumBumpmapTEs++;
-	}
+    if(mTextureList.copyTexture(index, te) != TEM_CHANGE_NONE && te.getBumpmap() > 0)
+    {
+        mNumBumpmapTEs++;
+    }
 }
 
 S32  LLPrimitive::setTETexture(const U8 index, const LLUUID &id)
 {
-	return mTextureList.setID(index, id);
+    return mTextureList.setID(index, id);
 }
 
 S32  LLPrimitive::setTEColor(const U8 index, const LLColor4 &color)
 {
-	return mTextureList.setColor(index, color);
+    return mTextureList.setColor(index, color);
 }
 
 S32  LLPrimitive::setTEColor(const U8 index, const LLColor3 &color)
 {
-	return mTextureList.setColor(index, color);
+    return mTextureList.setColor(index, color);
 }
 
 S32  LLPrimitive::setTEAlpha(const U8 index, const F32 alpha)
 {
-	return mTextureList.setAlpha(index, alpha);
+    return mTextureList.setAlpha(index, alpha);
 }
 
 //===============================================================
 S32  LLPrimitive::setTEScale(const U8 index, const F32 s, const F32 t)
 {
-	return mTextureList.setScale(index, s, t);
+    return mTextureList.setScale(index, s, t);
 }
 
 
@@ -315,7 +315,7 @@ S32  LLPrimitive::setTEScale(const U8 index, const F32 s, const F32 t)
 // voodoo related to texture coords
 S32 LLPrimitive::setTEScaleS(const U8 index, const F32 s)
 {
-	return mTextureList.setScaleS(index, s);
+    return mTextureList.setScaleS(index, s);
 }
 
 
@@ -323,14 +323,14 @@ S32 LLPrimitive::setTEScaleS(const U8 index, const F32 s)
 // voodoo related to texture coords
 S32 LLPrimitive::setTEScaleT(const U8 index, const F32 t)
 {
-	return mTextureList.setScaleT(index, t);
+    return mTextureList.setScaleT(index, t);
 }
 
 
 //===============================================================
 S32  LLPrimitive::setTEOffset(const U8 index, const F32 s, const F32 t)
 {
-	return mTextureList.setOffset(index, s, t);
+    return mTextureList.setOffset(index, s, t);
 }
 
 
@@ -338,7 +338,7 @@ S32  LLPrimitive::setTEOffset(const U8 index, const F32 s, const F32 t)
 // voodoo related to texture coords
 S32 LLPrimitive::setTEOffsetS(const U8 index, const F32 s)
 {
-	return mTextureList.setOffsetS(index, s);
+    return mTextureList.setOffsetS(index, s);
 }
 
 
@@ -346,289 +346,289 @@ S32 LLPrimitive::setTEOffsetS(const U8 index, const F32 s)
 // voodoo related to texture coords
 S32 LLPrimitive::setTEOffsetT(const U8 index, const F32 t)
 {
-	return mTextureList.setOffsetT(index, t);
+    return mTextureList.setOffsetT(index, t);
 }
 
 
 //===============================================================
 S32  LLPrimitive::setTERotation(const U8 index, const F32 r)
 {
-	return mTextureList.setRotation(index, r);
+    return mTextureList.setRotation(index, r);
 }
 
 S32 LLPrimitive::setTEMaterialID(const U8 index, const LLMaterialID& pMaterialID)
 {
-	return mTextureList.setMaterialID(index, pMaterialID);
+    return mTextureList.setMaterialID(index, pMaterialID);
 }
 
 S32 LLPrimitive::setTEMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams)
 {
-	return mTextureList.setMaterialParams(index, pMaterialParams);
+    return mTextureList.setMaterialParams(index, pMaterialParams);
 }
 
 LLMaterialPtr LLPrimitive::getTEMaterialParams(const U8 index)
 {
-	return mTextureList.getMaterialParams(index);
+    return mTextureList.getMaterialParams(index);
 }
 
 //===============================================================
 S32  LLPrimitive::setTEBumpShinyFullbright(const U8 index, const U8 bump)
 {
-	updateNumBumpmap(index, bump);
-	return mTextureList.setBumpShinyFullbright(index, bump);
+    updateNumBumpmap(index, bump);
+    return mTextureList.setBumpShinyFullbright(index, bump);
 }
 
 S32  LLPrimitive::setTEMediaTexGen(const U8 index, const U8 media)
 {
-	return mTextureList.setMediaTexGen(index, media);
+    return mTextureList.setMediaTexGen(index, media);
 }
 
 S32  LLPrimitive::setTEBumpmap(const U8 index, const U8 bump)
 {
-	updateNumBumpmap(index, bump);
-	return mTextureList.setBumpMap(index, bump);
+    updateNumBumpmap(index, bump);
+    return mTextureList.setBumpMap(index, bump);
 }
 
 S32  LLPrimitive::setTEBumpShiny(const U8 index, const U8 bump_shiny)
 {
-	updateNumBumpmap(index, bump_shiny);
-	return mTextureList.setBumpShiny(index, bump_shiny);
+    updateNumBumpmap(index, bump_shiny);
+    return mTextureList.setBumpShiny(index, bump_shiny);
 }
 
 S32  LLPrimitive::setTETexGen(const U8 index, const U8 texgen)
 {
-	return mTextureList.setTexGen(index, texgen);
+    return mTextureList.setTexGen(index, texgen);
 }
 
 S32  LLPrimitive::setTEShiny(const U8 index, const U8 shiny)
 {
-	return mTextureList.setShiny(index, shiny);
+    return mTextureList.setShiny(index, shiny);
 }
 
 S32  LLPrimitive::setTEFullbright(const U8 index, const U8 fullbright)
 {
-	return mTextureList.setFullbright(index, fullbright);
+    return mTextureList.setFullbright(index, fullbright);
 }
 
 S32  LLPrimitive::setTEMediaFlags(const U8 index, const U8 media_flags)
 {
-	return mTextureList.setMediaFlags(index, media_flags);
+    return mTextureList.setMediaFlags(index, media_flags);
 }
 
 S32 LLPrimitive::setTEGlow(const U8 index, const F32 glow)
 {
-	return mTextureList.setGlow(index, glow);
+    return mTextureList.setGlow(index, glow);
 }
 
 void LLPrimitive::setAllTESelected(bool sel)
 {
-	for (int i = 0, cnt = getNumTEs(); i < cnt; i++)
-	{
-		setTESelected(i, sel);
-	}
+    for (int i = 0, cnt = getNumTEs(); i < cnt; i++)
+    {
+        setTESelected(i, sel);
+    }
 }
-	
+
 void LLPrimitive::setTESelected(const U8 te, bool sel)
 {
-	LLTextureEntry* tep = getTE(te);
-	if ( (tep) && (tep->setSelected(sel)) && (!sel) && (tep->hasPendingMaterialUpdate()) )
-	{
-		LLMaterialID material_id = tep->getMaterialID();
-		setTEMaterialID(te, material_id);
-	}
+    LLTextureEntry* tep = getTE(te);
+    if ( (tep) && (tep->setSelected(sel)) && (!sel) && (tep->hasPendingMaterialUpdate()) )
+    {
+        LLMaterialID material_id = tep->getMaterialID();
+        setTEMaterialID(te, material_id);
+    }
 }
 
 LLPCode LLPrimitive::legacyToPCode(const U8 legacy)
 {
-	// TODO: Should this default to something valid?
-	// Maybe volume?
-	LLPCode pcode = 0;
-
-	switch (legacy)
-	{
-		/*
-	case BOX:
-		pcode = LL_PCODE_CUBE;
-		break;
-	case CYLINDER:
-		pcode = LL_PCODE_CYLINDER;
-		break;
-	case CONE:
-		pcode = LL_PCODE_CONE;
-		break;
-	case HALF_CONE:
-		pcode = LL_PCODE_CONE_HEMI;
-		break;
-	case HALF_CYLINDER:
-		pcode = LL_PCODE_CYLINDER_HEMI;
-		break;
-	case HALF_SPHERE:
-		pcode = LL_PCODE_SPHERE_HEMI;
-		break;
-	case PRISM:
-		pcode = LL_PCODE_PRISM;
-		break;
-	case PYRAMID:
-		pcode = LL_PCODE_PYRAMID;
-		break;
-	case SPHERE:
-		pcode = LL_PCODE_SPHERE;
-		break;
-	case TETRAHEDRON:
-		pcode = LL_PCODE_TETRAHEDRON;
-		break;
-	case DEMON:
-		pcode = LL_PCODE_LEGACY_DEMON;
-		break;
-	case LSL_TEST:
-		pcode = LL_PCODE_LEGACY_LSL_TEST;
-		break;
-	case ORACLE:
-		pcode = LL_PCODE_LEGACY_ORACLE;
-		break;
-	case TEXTBUBBLE:
-		pcode = LL_PCODE_LEGACY_TEXT_BUBBLE;
-		break;
-	case ATOR:
-		pcode = LL_PCODE_LEGACY_ATOR;
-		break;
-	case BASIC_SHOT:
-		pcode = LL_PCODE_LEGACY_SHOT;
-		break;
-	case BIG_SHOT:
-		pcode = LL_PCODE_LEGACY_SHOT_BIG;
-		break;
-	case BIRD:
-		pcode = LL_PCODE_LEGACY_BIRD;
-		break;
-	case ROCK:
-		pcode = LL_PCODE_LEGACY_ROCK;
-		break;
-	case SMOKE:
-		pcode = LL_PCODE_LEGACY_SMOKE;
-		break;
-	case SPARK:
-		pcode = LL_PCODE_LEGACY_SPARK;
-		break;
-		*/
-	case PRIMITIVE_VOLUME:
-		pcode = LL_PCODE_VOLUME;
-		break;
-	case GRASS:
-		pcode = LL_PCODE_LEGACY_GRASS;
-		break;
-	case PART_SYS:
-		pcode = LL_PCODE_LEGACY_PART_SYS;
-		break;
-	case PLAYER:
-		pcode = LL_PCODE_LEGACY_AVATAR;
-		break;
-	case TREE:
-		pcode = LL_PCODE_LEGACY_TREE;
-		break;
-	case TREE_NEW:
-		pcode = LL_PCODE_TREE_NEW;
-		break;
-	default:
-		LL_WARNS() << "Unknown legacy code " << legacy << " [" << (S32)legacy << "]!" << LL_ENDL;
-	}
-
-	return pcode;
+    // TODO: Should this default to something valid?
+    // Maybe volume?
+    LLPCode pcode = 0;
+
+    switch (legacy)
+    {
+        /*
+    case BOX:
+        pcode = LL_PCODE_CUBE;
+        break;
+    case CYLINDER:
+        pcode = LL_PCODE_CYLINDER;
+        break;
+    case CONE:
+        pcode = LL_PCODE_CONE;
+        break;
+    case HALF_CONE:
+        pcode = LL_PCODE_CONE_HEMI;
+        break;
+    case HALF_CYLINDER:
+        pcode = LL_PCODE_CYLINDER_HEMI;
+        break;
+    case HALF_SPHERE:
+        pcode = LL_PCODE_SPHERE_HEMI;
+        break;
+    case PRISM:
+        pcode = LL_PCODE_PRISM;
+        break;
+    case PYRAMID:
+        pcode = LL_PCODE_PYRAMID;
+        break;
+    case SPHERE:
+        pcode = LL_PCODE_SPHERE;
+        break;
+    case TETRAHEDRON:
+        pcode = LL_PCODE_TETRAHEDRON;
+        break;
+    case DEMON:
+        pcode = LL_PCODE_LEGACY_DEMON;
+        break;
+    case LSL_TEST:
+        pcode = LL_PCODE_LEGACY_LSL_TEST;
+        break;
+    case ORACLE:
+        pcode = LL_PCODE_LEGACY_ORACLE;
+        break;
+    case TEXTBUBBLE:
+        pcode = LL_PCODE_LEGACY_TEXT_BUBBLE;
+        break;
+    case ATOR:
+        pcode = LL_PCODE_LEGACY_ATOR;
+        break;
+    case BASIC_SHOT:
+        pcode = LL_PCODE_LEGACY_SHOT;
+        break;
+    case BIG_SHOT:
+        pcode = LL_PCODE_LEGACY_SHOT_BIG;
+        break;
+    case BIRD:
+        pcode = LL_PCODE_LEGACY_BIRD;
+        break;
+    case ROCK:
+        pcode = LL_PCODE_LEGACY_ROCK;
+        break;
+    case SMOKE:
+        pcode = LL_PCODE_LEGACY_SMOKE;
+        break;
+    case SPARK:
+        pcode = LL_PCODE_LEGACY_SPARK;
+        break;
+        */
+    case PRIMITIVE_VOLUME:
+        pcode = LL_PCODE_VOLUME;
+        break;
+    case GRASS:
+        pcode = LL_PCODE_LEGACY_GRASS;
+        break;
+    case PART_SYS:
+        pcode = LL_PCODE_LEGACY_PART_SYS;
+        break;
+    case PLAYER:
+        pcode = LL_PCODE_LEGACY_AVATAR;
+        break;
+    case TREE:
+        pcode = LL_PCODE_LEGACY_TREE;
+        break;
+    case TREE_NEW:
+        pcode = LL_PCODE_TREE_NEW;
+        break;
+    default:
+        LL_WARNS() << "Unknown legacy code " << legacy << " [" << (S32)legacy << "]!" << LL_ENDL;
+    }
+
+    return pcode;
 }
 
 U8 LLPrimitive::pCodeToLegacy(const LLPCode pcode)
 {
-	U8 legacy;
-	switch (pcode)
-	{
+    U8 legacy;
+    switch (pcode)
+    {
 /*
-	case LL_PCODE_CUBE:
-		legacy = BOX;
-		break;
-	case LL_PCODE_CYLINDER:
-		legacy = CYLINDER;
-		break;
-	case LL_PCODE_CONE:
-		legacy = CONE;
-		break;
-	case LL_PCODE_CONE_HEMI:
-		legacy = HALF_CONE;
-		break;
-	case LL_PCODE_CYLINDER_HEMI:
-		legacy = HALF_CYLINDER;
-		break;
-	case LL_PCODE_SPHERE_HEMI:
-		legacy = HALF_SPHERE;
-		break;
-	case LL_PCODE_PRISM:
-		legacy = PRISM;
-		break;
-	case LL_PCODE_PYRAMID:
-		legacy = PYRAMID;
-		break;
-	case LL_PCODE_SPHERE:
-		legacy = SPHERE;
-		break;
-	case LL_PCODE_TETRAHEDRON:
-		legacy = TETRAHEDRON;
-		break;
-	case LL_PCODE_LEGACY_ATOR:
-		legacy = ATOR;
-		break;
-	case LL_PCODE_LEGACY_SHOT:
-		legacy = BASIC_SHOT;
-		break;
-	case LL_PCODE_LEGACY_SHOT_BIG:
-		legacy = BIG_SHOT;
-		break;
-	case LL_PCODE_LEGACY_BIRD:
-		legacy = BIRD;
-		break;		
-	case LL_PCODE_LEGACY_DEMON:
-		legacy = DEMON;
-		break;
-	case LL_PCODE_LEGACY_LSL_TEST:
-		legacy = LSL_TEST;
-		break;
-	case LL_PCODE_LEGACY_ORACLE:
-		legacy = ORACLE;
-		break;
-	case LL_PCODE_LEGACY_ROCK:
-		legacy = ROCK;
-		break;
-	case LL_PCODE_LEGACY_TEXT_BUBBLE:
-		legacy = TEXTBUBBLE;
-		break;
-	case LL_PCODE_LEGACY_SMOKE:
-		legacy = SMOKE;
-		break;
-	case LL_PCODE_LEGACY_SPARK:
-		legacy = SPARK;
-		break;
+    case LL_PCODE_CUBE:
+        legacy = BOX;
+        break;
+    case LL_PCODE_CYLINDER:
+        legacy = CYLINDER;
+        break;
+    case LL_PCODE_CONE:
+        legacy = CONE;
+        break;
+    case LL_PCODE_CONE_HEMI:
+        legacy = HALF_CONE;
+        break;
+    case LL_PCODE_CYLINDER_HEMI:
+        legacy = HALF_CYLINDER;
+        break;
+    case LL_PCODE_SPHERE_HEMI:
+        legacy = HALF_SPHERE;
+        break;
+    case LL_PCODE_PRISM:
+        legacy = PRISM;
+        break;
+    case LL_PCODE_PYRAMID:
+        legacy = PYRAMID;
+        break;
+    case LL_PCODE_SPHERE:
+        legacy = SPHERE;
+        break;
+    case LL_PCODE_TETRAHEDRON:
+        legacy = TETRAHEDRON;
+        break;
+    case LL_PCODE_LEGACY_ATOR:
+        legacy = ATOR;
+        break;
+    case LL_PCODE_LEGACY_SHOT:
+        legacy = BASIC_SHOT;
+        break;
+    case LL_PCODE_LEGACY_SHOT_BIG:
+        legacy = BIG_SHOT;
+        break;
+    case LL_PCODE_LEGACY_BIRD:
+        legacy = BIRD;
+        break;
+    case LL_PCODE_LEGACY_DEMON:
+        legacy = DEMON;
+        break;
+    case LL_PCODE_LEGACY_LSL_TEST:
+        legacy = LSL_TEST;
+        break;
+    case LL_PCODE_LEGACY_ORACLE:
+        legacy = ORACLE;
+        break;
+    case LL_PCODE_LEGACY_ROCK:
+        legacy = ROCK;
+        break;
+    case LL_PCODE_LEGACY_TEXT_BUBBLE:
+        legacy = TEXTBUBBLE;
+        break;
+    case LL_PCODE_LEGACY_SMOKE:
+        legacy = SMOKE;
+        break;
+    case LL_PCODE_LEGACY_SPARK:
+        legacy = SPARK;
+        break;
 */
-	case LL_PCODE_VOLUME:
-		legacy = PRIMITIVE_VOLUME;
-		break;
-	case LL_PCODE_LEGACY_GRASS:
-		legacy = GRASS;
-		break;
-	case LL_PCODE_LEGACY_PART_SYS:
-		legacy = PART_SYS;
-		break;
-	case LL_PCODE_LEGACY_AVATAR:
-		legacy = PLAYER;
-		break;
-	case LL_PCODE_LEGACY_TREE:
-		legacy = TREE;
-		break;
-	case LL_PCODE_TREE_NEW:
-		legacy = TREE_NEW;
-		break;
-	default:
-		LL_WARNS() << "Unknown pcode " << (S32)pcode << ":" << pcode << "!" << LL_ENDL;
-		return 0;
-	}
-	return legacy;
+    case LL_PCODE_VOLUME:
+        legacy = PRIMITIVE_VOLUME;
+        break;
+    case LL_PCODE_LEGACY_GRASS:
+        legacy = GRASS;
+        break;
+    case LL_PCODE_LEGACY_PART_SYS:
+        legacy = PART_SYS;
+        break;
+    case LL_PCODE_LEGACY_AVATAR:
+        legacy = PLAYER;
+        break;
+    case LL_PCODE_LEGACY_TREE:
+        legacy = TREE;
+        break;
+    case LL_PCODE_TREE_NEW:
+        legacy = TREE_NEW;
+        break;
+    default:
+        LL_WARNS() << "Unknown pcode " << (S32)pcode << ":" << pcode << "!" << LL_ENDL;
+        return 0;
+    }
+    return legacy;
 }
 
 
@@ -636,491 +636,491 @@ U8 LLPrimitive::pCodeToLegacy(const LLPCode pcode)
 // Don't crash or LL_ERRS() here!  This function is used for debug strings.
 std::string LLPrimitive::pCodeToString(const LLPCode pcode)
 {
-	std::string pcode_string;
-
-	U8 base_code = pcode & LL_PCODE_BASE_MASK;
-	if (!pcode)
-	{
-		pcode_string = "null";
-	}
-	else if ((base_code) == LL_PCODE_LEGACY)
-	{
-		// It's a legacy object
-		switch (pcode)
-		{
-		case LL_PCODE_LEGACY_GRASS:
-		  pcode_string = "grass";
-			break;
-		case LL_PCODE_LEGACY_PART_SYS:
-		  pcode_string = "particle system";
-			break;
-		case LL_PCODE_LEGACY_AVATAR:
-		  pcode_string = "avatar";
-			break;
-		case LL_PCODE_LEGACY_TEXT_BUBBLE:
-		  pcode_string = "text bubble";
-			break;
-		case LL_PCODE_LEGACY_TREE:
-		  pcode_string = "tree";
-			break;
-		case LL_PCODE_TREE_NEW:
-		  pcode_string = "tree_new";
-			break;
-		default:
-		  pcode_string = llformat( "unknown legacy pcode %i",(U32)pcode);
-		}
-	}
-	else
-	{
-		std::string shape;
-		std::string mask;
-		if (base_code == LL_PCODE_CUBE)
-		{
-			shape = "cube";
-		}
-		else if (base_code == LL_PCODE_CYLINDER)
-		{
-			shape = "cylinder";
-		}
-		else if (base_code == LL_PCODE_CONE)
-		{
-			shape = "cone";
-		}
-		else if (base_code == LL_PCODE_PRISM)
-		{
-			shape = "prism";
-		}
-		else if (base_code == LL_PCODE_PYRAMID)
-		{
-			shape = "pyramid";
-		}
-		else if (base_code == LL_PCODE_SPHERE)
-		{
-			shape = "sphere";
-		}
-		else if (base_code == LL_PCODE_TETRAHEDRON)
-		{
-			shape = "tetrahedron";
-		}
-		else if (base_code == LL_PCODE_VOLUME)
-		{
-			shape = "volume";
-		}
-		else if (base_code == LL_PCODE_APP)
-		{
-			shape = "app";
-		}
-		else
-		{
-			LL_WARNS() << "Unknown base mask for pcode: " << base_code << LL_ENDL;
-		}
-
-		U8 mask_code = pcode & (~LL_PCODE_BASE_MASK);
-		if (base_code == LL_PCODE_APP)
-		{
-			mask = llformat( "%x", mask_code);
-		}
-		else if (mask_code & LL_PCODE_HEMI_MASK)
-		{
-			mask = "hemi";
-		}
-		else 
-		{
-			mask = llformat( "%x", mask_code);
-		}
-
-		if (mask[0])
-		{
-			pcode_string = llformat( "%s-%s", shape.c_str(), mask.c_str());
-		}
-		else
-		{
-			pcode_string = llformat( "%s", shape.c_str());
-		}
-	}
-
-	return pcode_string;
+    std::string pcode_string;
+
+    U8 base_code = pcode & LL_PCODE_BASE_MASK;
+    if (!pcode)
+    {
+        pcode_string = "null";
+    }
+    else if ((base_code) == LL_PCODE_LEGACY)
+    {
+        // It's a legacy object
+        switch (pcode)
+        {
+        case LL_PCODE_LEGACY_GRASS:
+          pcode_string = "grass";
+            break;
+        case LL_PCODE_LEGACY_PART_SYS:
+          pcode_string = "particle system";
+            break;
+        case LL_PCODE_LEGACY_AVATAR:
+          pcode_string = "avatar";
+            break;
+        case LL_PCODE_LEGACY_TEXT_BUBBLE:
+          pcode_string = "text bubble";
+            break;
+        case LL_PCODE_LEGACY_TREE:
+          pcode_string = "tree";
+            break;
+        case LL_PCODE_TREE_NEW:
+          pcode_string = "tree_new";
+            break;
+        default:
+          pcode_string = llformat( "unknown legacy pcode %i",(U32)pcode);
+        }
+    }
+    else
+    {
+        std::string shape;
+        std::string mask;
+        if (base_code == LL_PCODE_CUBE)
+        {
+            shape = "cube";
+        }
+        else if (base_code == LL_PCODE_CYLINDER)
+        {
+            shape = "cylinder";
+        }
+        else if (base_code == LL_PCODE_CONE)
+        {
+            shape = "cone";
+        }
+        else if (base_code == LL_PCODE_PRISM)
+        {
+            shape = "prism";
+        }
+        else if (base_code == LL_PCODE_PYRAMID)
+        {
+            shape = "pyramid";
+        }
+        else if (base_code == LL_PCODE_SPHERE)
+        {
+            shape = "sphere";
+        }
+        else if (base_code == LL_PCODE_TETRAHEDRON)
+        {
+            shape = "tetrahedron";
+        }
+        else if (base_code == LL_PCODE_VOLUME)
+        {
+            shape = "volume";
+        }
+        else if (base_code == LL_PCODE_APP)
+        {
+            shape = "app";
+        }
+        else
+        {
+            LL_WARNS() << "Unknown base mask for pcode: " << base_code << LL_ENDL;
+        }
+
+        U8 mask_code = pcode & (~LL_PCODE_BASE_MASK);
+        if (base_code == LL_PCODE_APP)
+        {
+            mask = llformat( "%x", mask_code);
+        }
+        else if (mask_code & LL_PCODE_HEMI_MASK)
+        {
+            mask = "hemi";
+        }
+        else
+        {
+            mask = llformat( "%x", mask_code);
+        }
+
+        if (mask[0])
+        {
+            pcode_string = llformat( "%s-%s", shape.c_str(), mask.c_str());
+        }
+        else
+        {
+            pcode_string = llformat( "%s", shape.c_str());
+        }
+    }
+
+    return pcode_string;
 }
 
 
 void LLPrimitive::copyTEs(const LLPrimitive *primitivep)
 {
-	U32 i;
-	if (primitivep->getExpectedNumTEs() != getExpectedNumTEs())
-	{
-		LL_WARNS() << "Primitives don't have same expected number of TE's" << LL_ENDL;
-	}
-	U32 num_tes = llmin(primitivep->getExpectedNumTEs(), getExpectedNumTEs());
-	if (mTextureList.size() < getExpectedNumTEs())
-	{
-		mTextureList.setSize(getExpectedNumTEs());
-	}
-	for (i = 0; i < num_tes; i++)
-	{
-		mTextureList.copyTexture(i, *(primitivep->getTE(i)));
-	}
-}
-
-S32	face_index_from_id(LLFaceID face_ID, const std::vector<LLProfile::Face>& faceArray)
-{
-	S32 i;
-	for (i = 0; i < (S32)faceArray.size(); i++)
-	{
-		if (faceArray[i].mFaceID == face_ID)
-		{
-			return i;
-		}
-	}
-	return -1;
+    U32 i;
+    if (primitivep->getExpectedNumTEs() != getExpectedNumTEs())
+    {
+        LL_WARNS() << "Primitives don't have same expected number of TE's" << LL_ENDL;
+    }
+    U32 num_tes = llmin(primitivep->getExpectedNumTEs(), getExpectedNumTEs());
+    if (mTextureList.size() < getExpectedNumTEs())
+    {
+        mTextureList.setSize(getExpectedNumTEs());
+    }
+    for (i = 0; i < num_tes; i++)
+    {
+        mTextureList.copyTexture(i, *(primitivep->getTE(i)));
+    }
+}
+
+S32 face_index_from_id(LLFaceID face_ID, const std::vector<LLProfile::Face>& faceArray)
+{
+    S32 i;
+    for (i = 0; i < (S32)faceArray.size(); i++)
+    {
+        if (faceArray[i].mFaceID == face_ID)
+        {
+            return i;
+        }
+    }
+    return -1;
 }
 
 BOOL LLPrimitive::setVolume(const LLVolumeParams &volume_params, const S32 detail, bool unique_volume)
 {
-	if (NO_LOD == detail)
-	{
-		// build the new object
-		setChanged(GEOMETRY);
-		sVolumeManager->unrefVolume(mVolumep);
-		mVolumep = new LLVolume(volume_params, 1, TRUE, TRUE);
-		setNumTEs(mVolumep->getNumFaces());
-		return FALSE;
-	}
-
-	LLVolume *volumep;
-	if (unique_volume)
-	{
-		F32 volume_detail = LLVolumeLODGroup::getVolumeScaleFromDetail(detail);
-		if (mVolumep.notNull() && volume_params == mVolumep->getParams() && (volume_detail == mVolumep->getDetail()))
-		{
-			return FALSE;
-		}
-		volumep = new LLVolume(volume_params, volume_detail, FALSE, TRUE);
-	}
-	else
-	{
-		if (mVolumep.notNull())
-		{
-			F32 volume_detail = LLVolumeLODGroup::getVolumeScaleFromDetail(detail);
-			if (volume_params == mVolumep->getParams() && (volume_detail == mVolumep->getDetail()))
-			{
-				return FALSE;
-			}
-		}
-
-		volumep = sVolumeManager->refVolume(volume_params, detail);
-		if (volumep == mVolumep.get())
-		{
-			sVolumeManager->unrefVolume( volumep );  // LLVolumeMgr::refVolume() creates a reference, but we don't need a second one.
-			return TRUE;
-		}
-	}
-
-	setChanged(GEOMETRY);
-
-	
-	if (!mVolumep)
-	{
-		mVolumep = volumep;
-		//mFaceMask = mVolumep->generateFaceMask();
-		setNumTEs(mVolumep->getNumFaces());
-		return TRUE;
-	}
-	
-#if 0 
-	// #if 0'd out by davep
-	// this is a lot of cruft to set texture entry values that just stay the same for LOD switch 
-	// or immediately get overridden by an object update message, also crashes occasionally
-	U32 old_face_mask = mVolumep->mFaceMask;
-
-	S32 face_bit = 0;
-	S32 cur_mask = 0;
-
-	// Grab copies of the old faces from the original shape, ordered by type.
-	// We will use these to figure out what old texture info gets mapped to new
-	// faces in the new shape.
-	std::vector<LLProfile::Face> old_faces; 
-	for (S32 face = 0; face < mVolumep->getNumFaces(); face++)
-	{
-		old_faces.push_back(mVolumep->getProfile().mFaces[face]);
-	}
-
-	// Copy the old texture info off to the side, but not in the order in which
-	// they live in the mTextureList, rather in order of ther "face id" which
-	// is the corresponding value of LLVolueParams::LLProfile::mFaces::mIndex.
-	//
-	// Hence, some elements of old_tes::mEntryList will be invalid.  It is
-	// initialized to a size of 9 (max number of possible faces on a volume?)
-	// and only the ones with valid types are filled in.
-	LLPrimTextureList old_tes;
-	old_tes.setSize(9);
-	for (face_bit = 0; face_bit < 9; face_bit++)
-	{
-		cur_mask = 0x1 << face_bit;
-		if (old_face_mask & cur_mask)
-		{
-			S32 te_index = face_index_from_id(cur_mask, old_faces);
-			old_tes.copyTexture(face_bit, *(getTE(te_index)));
-			//LL_INFOS() << face_bit << ":" << te_index << ":" << old_tes[face_bit].getID() << LL_ENDL;
-		}
-	}
-
-
-	// build the new object
-	sVolumeManager->unrefVolume(mVolumep);
-	mVolumep = volumep;
-	
-	U32 new_face_mask = mVolumep->mFaceMask;
-	S32 i;
-
-	if (old_face_mask == new_face_mask) 
-	{
-		// nothing to do
-		return TRUE;
-	}
-
-	if (mVolumep->getNumFaces() == 0 && new_face_mask != 0)
-	{
-		LL_WARNS() << "Object with 0 faces found...INCORRECT!" << LL_ENDL;
-		setNumTEs(mVolumep->getNumFaces());
-		return TRUE;
-	}
-
-	// initialize face_mapping
-	S32 face_mapping[9];
-	for (face_bit = 0; face_bit < 9; face_bit++)
-	{
-		face_mapping[face_bit] = face_bit;
-	}
-
-	// The new shape may have more faces than the original, but we can't just
-	// add them to the end -- the ordering matters and it may be that we must
-	// insert the new faces in the middle of the list.  When we add a face it
-	// will pick up the texture/color info of one of the old faces an so we
-	// now figure out which old face info gets mapped to each new face, and 
-	// store in the face_mapping lookup table.
-	for (face_bit = 0; face_bit < 9; face_bit++)
-	{
-		cur_mask = 0x1 << face_bit;
-		if (!(new_face_mask & cur_mask))
-		{
-			// Face doesn't exist in new map.
-			face_mapping[face_bit] = -1;
-			continue;
-		}
-		else if (old_face_mask & cur_mask)
-		{
-			// Face exists in new and old map.
-			face_mapping[face_bit] = face_bit;
-			continue;
-		}
-
-		// OK, how we've got a mismatch, where we have to fill a new face with one from
-		// the old face.
-		if (cur_mask & (LL_FACE_PATH_BEGIN | LL_FACE_PATH_END | LL_FACE_INNER_SIDE))
-		{
-			// It's a top/bottom/hollow interior face.
-			if (old_face_mask & LL_FACE_PATH_END)
-			{
-				face_mapping[face_bit] = 1;
-				continue;
-			}
-			else
-			{
-				S32 cur_outer_mask = LL_FACE_OUTER_SIDE_0;
-				for (i = 0; i < 4; i++)
-				{
-					if (old_face_mask & cur_outer_mask)
-					{
-						face_mapping[face_bit] = 5 + i;
-						break;
-					}
-					cur_outer_mask <<= 1;
-				}
-				if (i == 4)
-				{
-					LL_WARNS() << "No path end or outer face in volume!" << LL_ENDL;
-				}
-				continue;
-			}
-		}
-
-		if (cur_mask & (LL_FACE_PROFILE_BEGIN | LL_FACE_PROFILE_END))
-		{
-			// A cut slice.  Use the hollow interior if we have it.
-			if (old_face_mask & LL_FACE_INNER_SIDE)
-			{
-				face_mapping[face_bit] = 2;
-				continue;
-			}
-
-			// No interior, use the bottom face.
-			// Could figure out which of the outer faces was nearest, but that would be harder.
-			if (old_face_mask & LL_FACE_PATH_END)
-			{
-				face_mapping[face_bit] = 1;
-				continue;
-			}
-			else
-			{
-				S32 cur_outer_mask = LL_FACE_OUTER_SIDE_0;
-				for (i = 0; i < 4; i++)
-				{
-					if (old_face_mask & cur_outer_mask)
-					{
-						face_mapping[face_bit] = 5 + i;
-						break;
-					}
-					cur_outer_mask <<= 1;
-				}
-				if (i == 4)
-				{
-					LL_WARNS() << "No path end or outer face in volume!" << LL_ENDL;
-				}
-				continue;
-			}
-		}
-
-		// OK, the face that's missing is an outer face...
-		// Pull from the nearest adjacent outer face (there's always guaranteed to be one...
-		S32 cur_outer = face_bit - 5;
-		S32 min_dist = 5;
-		S32 min_outer_bit = -1;
-		S32 i;
-		for (i = 0; i < 4; i++)
-		{
-			if (old_face_mask & (LL_FACE_OUTER_SIDE_0 << i))
-			{
-				S32 dist = abs(i - cur_outer);
-				if (dist < min_dist)
-				{
-					min_dist = dist;
-					min_outer_bit = i + 5;
-				}
-			}
-		}
-		if (-1 == min_outer_bit)
-		{
-			LL_INFOS() << (LLVolume *)mVolumep << LL_ENDL;
-			LL_WARNS() << "Bad!  No outer faces, impossible!" << LL_ENDL;
-		}
-		face_mapping[face_bit] = min_outer_bit;
-	}
-	
-
-	setNumTEs(mVolumep->getNumFaces());
-	for (face_bit = 0; face_bit < 9; face_bit++)
-	{
-		// For each possible face type on the new shape we check to see if that
-		// face exists and if it does we create a texture entry that is a copy
-		// of one of the originals.  Since the originals might not have a
-		// matching face, we use the face_mapping lookup table to figure out
-		// which face information to copy.
-		cur_mask = 0x1 << face_bit;
-		if (new_face_mask & cur_mask)
-		{
-			if (-1 == face_mapping[face_bit])
-			{
-				LL_WARNS() << "No mapping from old face to new face!" << LL_ENDL;
-			}
-
-			S32 te_num = face_index_from_id(cur_mask, mVolumep->getProfile().mFaces);
-			setTE(te_num, *(old_tes.getTexture(face_mapping[face_bit])));
-		}
-	}
+    if (NO_LOD == detail)
+    {
+        // build the new object
+        setChanged(GEOMETRY);
+        sVolumeManager->unrefVolume(mVolumep);
+        mVolumep = new LLVolume(volume_params, 1, TRUE, TRUE);
+        setNumTEs(mVolumep->getNumFaces());
+        return FALSE;
+    }
+
+    LLVolume *volumep;
+    if (unique_volume)
+    {
+        F32 volume_detail = LLVolumeLODGroup::getVolumeScaleFromDetail(detail);
+        if (mVolumep.notNull() && volume_params == mVolumep->getParams() && (volume_detail == mVolumep->getDetail()))
+        {
+            return FALSE;
+        }
+        volumep = new LLVolume(volume_params, volume_detail, FALSE, TRUE);
+    }
+    else
+    {
+        if (mVolumep.notNull())
+        {
+            F32 volume_detail = LLVolumeLODGroup::getVolumeScaleFromDetail(detail);
+            if (volume_params == mVolumep->getParams() && (volume_detail == mVolumep->getDetail()))
+            {
+                return FALSE;
+            }
+        }
+
+        volumep = sVolumeManager->refVolume(volume_params, detail);
+        if (volumep == mVolumep.get())
+        {
+            sVolumeManager->unrefVolume( volumep );  // LLVolumeMgr::refVolume() creates a reference, but we don't need a second one.
+            return TRUE;
+        }
+    }
+
+    setChanged(GEOMETRY);
+
+
+    if (!mVolumep)
+    {
+        mVolumep = volumep;
+        //mFaceMask = mVolumep->generateFaceMask();
+        setNumTEs(mVolumep->getNumFaces());
+        return TRUE;
+    }
+
+#if 0
+    // #if 0'd out by davep
+    // this is a lot of cruft to set texture entry values that just stay the same for LOD switch
+    // or immediately get overridden by an object update message, also crashes occasionally
+    U32 old_face_mask = mVolumep->mFaceMask;
+
+    S32 face_bit = 0;
+    S32 cur_mask = 0;
+
+    // Grab copies of the old faces from the original shape, ordered by type.
+    // We will use these to figure out what old texture info gets mapped to new
+    // faces in the new shape.
+    std::vector<LLProfile::Face> old_faces;
+    for (S32 face = 0; face < mVolumep->getNumFaces(); face++)
+    {
+        old_faces.push_back(mVolumep->getProfile().mFaces[face]);
+    }
+
+    // Copy the old texture info off to the side, but not in the order in which
+    // they live in the mTextureList, rather in order of ther "face id" which
+    // is the corresponding value of LLVolueParams::LLProfile::mFaces::mIndex.
+    //
+    // Hence, some elements of old_tes::mEntryList will be invalid.  It is
+    // initialized to a size of 9 (max number of possible faces on a volume?)
+    // and only the ones with valid types are filled in.
+    LLPrimTextureList old_tes;
+    old_tes.setSize(9);
+    for (face_bit = 0; face_bit < 9; face_bit++)
+    {
+        cur_mask = 0x1 << face_bit;
+        if (old_face_mask & cur_mask)
+        {
+            S32 te_index = face_index_from_id(cur_mask, old_faces);
+            old_tes.copyTexture(face_bit, *(getTE(te_index)));
+            //LL_INFOS() << face_bit << ":" << te_index << ":" << old_tes[face_bit].getID() << LL_ENDL;
+        }
+    }
+
+
+    // build the new object
+    sVolumeManager->unrefVolume(mVolumep);
+    mVolumep = volumep;
+
+    U32 new_face_mask = mVolumep->mFaceMask;
+    S32 i;
+
+    if (old_face_mask == new_face_mask)
+    {
+        // nothing to do
+        return TRUE;
+    }
+
+    if (mVolumep->getNumFaces() == 0 && new_face_mask != 0)
+    {
+        LL_WARNS() << "Object with 0 faces found...INCORRECT!" << LL_ENDL;
+        setNumTEs(mVolumep->getNumFaces());
+        return TRUE;
+    }
+
+    // initialize face_mapping
+    S32 face_mapping[9];
+    for (face_bit = 0; face_bit < 9; face_bit++)
+    {
+        face_mapping[face_bit] = face_bit;
+    }
+
+    // The new shape may have more faces than the original, but we can't just
+    // add them to the end -- the ordering matters and it may be that we must
+    // insert the new faces in the middle of the list.  When we add a face it
+    // will pick up the texture/color info of one of the old faces an so we
+    // now figure out which old face info gets mapped to each new face, and
+    // store in the face_mapping lookup table.
+    for (face_bit = 0; face_bit < 9; face_bit++)
+    {
+        cur_mask = 0x1 << face_bit;
+        if (!(new_face_mask & cur_mask))
+        {
+            // Face doesn't exist in new map.
+            face_mapping[face_bit] = -1;
+            continue;
+        }
+        else if (old_face_mask & cur_mask)
+        {
+            // Face exists in new and old map.
+            face_mapping[face_bit] = face_bit;
+            continue;
+        }
+
+        // OK, how we've got a mismatch, where we have to fill a new face with one from
+        // the old face.
+        if (cur_mask & (LL_FACE_PATH_BEGIN | LL_FACE_PATH_END | LL_FACE_INNER_SIDE))
+        {
+            // It's a top/bottom/hollow interior face.
+            if (old_face_mask & LL_FACE_PATH_END)
+            {
+                face_mapping[face_bit] = 1;
+                continue;
+            }
+            else
+            {
+                S32 cur_outer_mask = LL_FACE_OUTER_SIDE_0;
+                for (i = 0; i < 4; i++)
+                {
+                    if (old_face_mask & cur_outer_mask)
+                    {
+                        face_mapping[face_bit] = 5 + i;
+                        break;
+                    }
+                    cur_outer_mask <<= 1;
+                }
+                if (i == 4)
+                {
+                    LL_WARNS() << "No path end or outer face in volume!" << LL_ENDL;
+                }
+                continue;
+            }
+        }
+
+        if (cur_mask & (LL_FACE_PROFILE_BEGIN | LL_FACE_PROFILE_END))
+        {
+            // A cut slice.  Use the hollow interior if we have it.
+            if (old_face_mask & LL_FACE_INNER_SIDE)
+            {
+                face_mapping[face_bit] = 2;
+                continue;
+            }
+
+            // No interior, use the bottom face.
+            // Could figure out which of the outer faces was nearest, but that would be harder.
+            if (old_face_mask & LL_FACE_PATH_END)
+            {
+                face_mapping[face_bit] = 1;
+                continue;
+            }
+            else
+            {
+                S32 cur_outer_mask = LL_FACE_OUTER_SIDE_0;
+                for (i = 0; i < 4; i++)
+                {
+                    if (old_face_mask & cur_outer_mask)
+                    {
+                        face_mapping[face_bit] = 5 + i;
+                        break;
+                    }
+                    cur_outer_mask <<= 1;
+                }
+                if (i == 4)
+                {
+                    LL_WARNS() << "No path end or outer face in volume!" << LL_ENDL;
+                }
+                continue;
+            }
+        }
+
+        // OK, the face that's missing is an outer face...
+        // Pull from the nearest adjacent outer face (there's always guaranteed to be one...
+        S32 cur_outer = face_bit - 5;
+        S32 min_dist = 5;
+        S32 min_outer_bit = -1;
+        S32 i;
+        for (i = 0; i < 4; i++)
+        {
+            if (old_face_mask & (LL_FACE_OUTER_SIDE_0 << i))
+            {
+                S32 dist = abs(i - cur_outer);
+                if (dist < min_dist)
+                {
+                    min_dist = dist;
+                    min_outer_bit = i + 5;
+                }
+            }
+        }
+        if (-1 == min_outer_bit)
+        {
+            LL_INFOS() << (LLVolume *)mVolumep << LL_ENDL;
+            LL_WARNS() << "Bad!  No outer faces, impossible!" << LL_ENDL;
+        }
+        face_mapping[face_bit] = min_outer_bit;
+    }
+
+
+    setNumTEs(mVolumep->getNumFaces());
+    for (face_bit = 0; face_bit < 9; face_bit++)
+    {
+        // For each possible face type on the new shape we check to see if that
+        // face exists and if it does we create a texture entry that is a copy
+        // of one of the originals.  Since the originals might not have a
+        // matching face, we use the face_mapping lookup table to figure out
+        // which face information to copy.
+        cur_mask = 0x1 << face_bit;
+        if (new_face_mask & cur_mask)
+        {
+            if (-1 == face_mapping[face_bit])
+            {
+                LL_WARNS() << "No mapping from old face to new face!" << LL_ENDL;
+            }
+
+            S32 te_num = face_index_from_id(cur_mask, mVolumep->getProfile().mFaces);
+            setTE(te_num, *(old_tes.getTexture(face_mapping[face_bit])));
+        }
+    }
 #else
-	// build the new object
-	sVolumeManager->unrefVolume(mVolumep);
-	mVolumep = volumep; 
+    // build the new object
+    sVolumeManager->unrefVolume(mVolumep);
+    mVolumep = volumep;
 
-	setNumTEs(mVolumep->getNumFaces());
+    setNumTEs(mVolumep->getNumFaces());
 #endif
-	return TRUE;
+    return TRUE;
 }
 
 BOOL LLPrimitive::setMaterial(U8 material)
 {
-	if (material != mMaterial)
-	{
-		mMaterial = material;
-		return TRUE;
-	}
-	else
-	{
-		return FALSE;
-	}
+    if (material != mMaterial)
+    {
+        mMaterial = material;
+        return TRUE;
+    }
+    else
+    {
+        return FALSE;
+    }
 }
 
 S32 LLPrimitive::packTEField(U8 *cur_ptr, U8 *data_ptr, U8 data_size, U8 last_face_index, EMsgVariableType type) const
 {
-	S32 face_index;
-	S32 i;
-	U64 exception_faces;
-	U8 *start_loc = cur_ptr;
-
-	htolememcpy(cur_ptr,data_ptr + (last_face_index * data_size), type, data_size);
-	cur_ptr += data_size;
-	
-	for (face_index = last_face_index-1; face_index >= 0; face_index--)
-	{
-		BOOL already_sent = FALSE;
-		for (i = face_index+1; i <= last_face_index; i++)
-		{ 
-			if (!memcmp(data_ptr+(data_size *face_index), data_ptr+(data_size *i), data_size))
-			{
-				already_sent = TRUE;
-				break;
-			}
-		}
-
-		if (!already_sent)
-		{
-			exception_faces = 0;
-			for (i = face_index; i >= 0; i--)
-			{ 
-				if (!memcmp(data_ptr+(data_size *face_index), data_ptr+(data_size *i), data_size))
-				{
-					exception_faces |= ((U64)1 << i); 
-				}
-			}
-			
-			//assign exception faces to cur_ptr
-			if (exception_faces >= ((U64)0x1 << 7))
-			{
-				if (exception_faces >= ((U64)0x1 << 14))
-				{
-					if (exception_faces >= ((U64)0x1 << 21))
-					{
-						if (exception_faces >= ((U64)0x1 << 28))
-						{
-							if (exception_faces >= ((U64)0x1 << 35))
-							{
-								if (exception_faces >= ((U64)0x1 << 42))
-								{
-									if (exception_faces >= ((U64)0x1 << 49))
-									{
-										*cur_ptr++ = (U8)(((exception_faces >> 49) & 0x7F) | 0x80);
-									}
-									*cur_ptr++ = (U8)(((exception_faces >> 42) & 0x7F) | 0x80);
-								}
-								*cur_ptr++ = (U8)(((exception_faces >> 35) & 0x7F) | 0x80);
-							}
-							*cur_ptr++ = (U8)(((exception_faces >> 28) & 0x7F) | 0x80);
-						}
-						*cur_ptr++ = (U8)(((exception_faces >> 21) & 0x7F) | 0x80);
-					}
-					*cur_ptr++ = (U8)(((exception_faces >> 14) & 0x7F) | 0x80);
-				}
-				*cur_ptr++ = (U8)(((exception_faces >> 7) & 0x7F) | 0x80);
-			}
-
-			
-			*cur_ptr++ = (U8)(exception_faces & 0x7F);
-			
-			htolememcpy(cur_ptr,data_ptr + (face_index * data_size), type, data_size);
-			cur_ptr += data_size;
-   		}
-	}
-	return (S32)(cur_ptr - start_loc);
+    S32 face_index;
+    S32 i;
+    U64 exception_faces;
+    U8 *start_loc = cur_ptr;
+
+    htolememcpy(cur_ptr,data_ptr + (last_face_index * data_size), type, data_size);
+    cur_ptr += data_size;
+
+    for (face_index = last_face_index-1; face_index >= 0; face_index--)
+    {
+        BOOL already_sent = FALSE;
+        for (i = face_index+1; i <= last_face_index; i++)
+        {
+            if (!memcmp(data_ptr+(data_size *face_index), data_ptr+(data_size *i), data_size))
+            {
+                already_sent = TRUE;
+                break;
+            }
+        }
+
+        if (!already_sent)
+        {
+            exception_faces = 0;
+            for (i = face_index; i >= 0; i--)
+            {
+                if (!memcmp(data_ptr+(data_size *face_index), data_ptr+(data_size *i), data_size))
+                {
+                    exception_faces |= ((U64)1 << i);
+                }
+            }
+
+            //assign exception faces to cur_ptr
+            if (exception_faces >= ((U64)0x1 << 7))
+            {
+                if (exception_faces >= ((U64)0x1 << 14))
+                {
+                    if (exception_faces >= ((U64)0x1 << 21))
+                    {
+                        if (exception_faces >= ((U64)0x1 << 28))
+                        {
+                            if (exception_faces >= ((U64)0x1 << 35))
+                            {
+                                if (exception_faces >= ((U64)0x1 << 42))
+                                {
+                                    if (exception_faces >= ((U64)0x1 << 49))
+                                    {
+                                        *cur_ptr++ = (U8)(((exception_faces >> 49) & 0x7F) | 0x80);
+                                    }
+                                    *cur_ptr++ = (U8)(((exception_faces >> 42) & 0x7F) | 0x80);
+                                }
+                                *cur_ptr++ = (U8)(((exception_faces >> 35) & 0x7F) | 0x80);
+                            }
+                            *cur_ptr++ = (U8)(((exception_faces >> 28) & 0x7F) | 0x80);
+                        }
+                        *cur_ptr++ = (U8)(((exception_faces >> 21) & 0x7F) | 0x80);
+                    }
+                    *cur_ptr++ = (U8)(((exception_faces >> 14) & 0x7F) | 0x80);
+                }
+                *cur_ptr++ = (U8)(((exception_faces >> 7) & 0x7F) | 0x80);
+            }
+
+
+            *cur_ptr++ = (U8)(exception_faces & 0x7F);
+
+            htolememcpy(cur_ptr,data_ptr + (face_index * data_size), type, data_size);
+            cur_ptr += data_size;
+        }
+    }
+    return (S32)(cur_ptr - start_loc);
 }
 
 namespace
@@ -1142,7 +1142,7 @@ namespace
             return false;
         }
 
-        // Extract the default value and fill the array. 
+        // Extract the default value and fill the array.
         htolememcpy(dest, source, type, size);
         source += size;
         for (S32 idx = 1; idx < dest_count; ++idx)
@@ -1155,7 +1155,7 @@ namespace
             U64 index_flags(0);
             U8  sbit(0);
 
-            // Unpack the variable length bitfield. Each bit represents whether the following 
+            // Unpack the variable length bitfield. Each bit represents whether the following
             // value will be placed at the corresponding array index.
             do
             {
@@ -1209,194 +1209,194 @@ namespace
 // Includes information about image ID, color, scale S,T, offset S,T and rotation
 BOOL LLPrimitive::packTEMessage(LLMessageSystem *mesgsys) const
 {
-	const U32 MAX_TES = 45;
-
-	U8     image_ids[MAX_TES*16];
-	U8     colors[MAX_TES*4];
-	F32    scale_s[MAX_TES];
-	F32    scale_t[MAX_TES];
-	S16    offset_s[MAX_TES];
-	S16    offset_t[MAX_TES];
-	S16    image_rot[MAX_TES];
-	U8	   bump[MAX_TES];
-	U8	   media_flags[MAX_TES];
+    const U32 MAX_TES = 45;
+
+    U8     image_ids[MAX_TES*16];
+    U8     colors[MAX_TES*4];
+    F32    scale_s[MAX_TES];
+    F32    scale_t[MAX_TES];
+    S16    offset_s[MAX_TES];
+    S16    offset_t[MAX_TES];
+    S16    image_rot[MAX_TES];
+    U8     bump[MAX_TES];
+    U8     media_flags[MAX_TES];
     U8     glow[MAX_TES];
-	U8     material_data[MAX_TES*16];
-	
-	const U32 MAX_TE_BUFFER = 4096;
-	U8 packed_buffer[MAX_TE_BUFFER];
-	U8 *cur_ptr = packed_buffer;
-	
-	S32 last_face_index = llmin((U32) getNumTEs(), MAX_TES) - 1;
-	
-	if (last_face_index > -1)
-	{
-		// ...if we hit the front, send one image id
-		S8 face_index;
-		LLColor4U coloru;
-		for (face_index = 0; face_index <= last_face_index; face_index++)
-		{
-			// Directly sending image_ids is not safe!
-			memcpy(&image_ids[face_index*16],getTE(face_index)->getID().mData,16);	/* Flawfinder: ignore */ 
-
-			// Cast LLColor4 to LLColor4U
-			coloru.setVec( getTE(face_index)->getColor() );
-
-			// Note:  This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f)
-			// as all zeros.  However, the subtraction and addition must be done in unsigned
-			// byte space, not in float space, otherwise off-by-one errors occur. JC
-			colors[4*face_index]     = 255 - coloru.mV[0];
-			colors[4*face_index + 1] = 255 - coloru.mV[1];
-			colors[4*face_index + 2] = 255 - coloru.mV[2];
-			colors[4*face_index + 3] = 255 - coloru.mV[3];
-
-			const LLTextureEntry* te = getTE(face_index);
-			scale_s[face_index] = (F32) te->mScaleS;
-			scale_t[face_index] = (F32) te->mScaleT;
-			offset_s[face_index] = (S16) ll_round((llclamp(te->mOffsetS,-1.0f,1.0f) * (F32)0x7FFF)) ;
-			offset_t[face_index] = (S16) ll_round((llclamp(te->mOffsetT,-1.0f,1.0f) * (F32)0x7FFF)) ;
-			image_rot[face_index] = (S16) ll_round(((fmod(te->mRotation, F_TWO_PI)/F_TWO_PI) * TEXTURE_ROTATION_PACK_FACTOR));
-			bump[face_index] = te->getBumpShinyFullbright();
-			media_flags[face_index] = te->getMediaTexGen();
-			glow[face_index] = (U8) ll_round((llclamp(te->getGlow(), 0.0f, 1.0f) * (F32)0xFF));
-
-			// Directly sending material_ids is not safe!
-			memcpy(&material_data[face_index*16],getTE(face_index)->getMaterialID().get(),16);	/* Flawfinder: ignore */ 
-		}
-
-		cur_ptr += packTEField(cur_ptr, (U8 *)image_ids, sizeof(LLUUID),last_face_index, MVT_LLUUID);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)colors, 4 ,last_face_index, MVT_U8);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)scale_s, 4 ,last_face_index, MVT_F32);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)scale_t, 4 ,last_face_index, MVT_F32);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)offset_s, 2 ,last_face_index, MVT_S16Array);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)offset_t, 2 ,last_face_index, MVT_S16Array);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)image_rot, 2 ,last_face_index, MVT_S16Array);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)bump, 1 ,last_face_index, MVT_U8);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)media_flags, 1 ,last_face_index, MVT_U8);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)glow, 1 ,last_face_index, MVT_U8);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)material_data, 16, last_face_index, MVT_LLUUID);
-	}
-   	mesgsys->addBinaryDataFast(_PREHASH_TextureEntry, packed_buffer, (S32)(cur_ptr - packed_buffer));
-
-	return FALSE;
+    U8     material_data[MAX_TES*16];
+
+    const U32 MAX_TE_BUFFER = 4096;
+    U8 packed_buffer[MAX_TE_BUFFER];
+    U8 *cur_ptr = packed_buffer;
+
+    S32 last_face_index = llmin((U32) getNumTEs(), MAX_TES) - 1;
+
+    if (last_face_index > -1)
+    {
+        // ...if we hit the front, send one image id
+        S8 face_index;
+        LLColor4U coloru;
+        for (face_index = 0; face_index <= last_face_index; face_index++)
+        {
+            // Directly sending image_ids is not safe!
+            memcpy(&image_ids[face_index*16],getTE(face_index)->getID().mData,16);  /* Flawfinder: ignore */
+
+            // Cast LLColor4 to LLColor4U
+            coloru.setVec( getTE(face_index)->getColor() );
+
+            // Note:  This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f)
+            // as all zeros.  However, the subtraction and addition must be done in unsigned
+            // byte space, not in float space, otherwise off-by-one errors occur. JC
+            colors[4*face_index]     = 255 - coloru.mV[0];
+            colors[4*face_index + 1] = 255 - coloru.mV[1];
+            colors[4*face_index + 2] = 255 - coloru.mV[2];
+            colors[4*face_index + 3] = 255 - coloru.mV[3];
+
+            const LLTextureEntry* te = getTE(face_index);
+            scale_s[face_index] = (F32) te->mScaleS;
+            scale_t[face_index] = (F32) te->mScaleT;
+            offset_s[face_index] = (S16) ll_round((llclamp(te->mOffsetS,-1.0f,1.0f) * (F32)0x7FFF)) ;
+            offset_t[face_index] = (S16) ll_round((llclamp(te->mOffsetT,-1.0f,1.0f) * (F32)0x7FFF)) ;
+            image_rot[face_index] = (S16) ll_round(((fmod(te->mRotation, F_TWO_PI)/F_TWO_PI) * TEXTURE_ROTATION_PACK_FACTOR));
+            bump[face_index] = te->getBumpShinyFullbright();
+            media_flags[face_index] = te->getMediaTexGen();
+            glow[face_index] = (U8) ll_round((llclamp(te->getGlow(), 0.0f, 1.0f) * (F32)0xFF));
+
+            // Directly sending material_ids is not safe!
+            memcpy(&material_data[face_index*16],getTE(face_index)->getMaterialID().get(),16);  /* Flawfinder: ignore */
+        }
+
+        cur_ptr += packTEField(cur_ptr, (U8 *)image_ids, sizeof(LLUUID),last_face_index, MVT_LLUUID);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)colors, 4 ,last_face_index, MVT_U8);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)scale_s, 4 ,last_face_index, MVT_F32);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)scale_t, 4 ,last_face_index, MVT_F32);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)offset_s, 2 ,last_face_index, MVT_S16Array);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)offset_t, 2 ,last_face_index, MVT_S16Array);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)image_rot, 2 ,last_face_index, MVT_S16Array);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)bump, 1 ,last_face_index, MVT_U8);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)media_flags, 1 ,last_face_index, MVT_U8);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)glow, 1 ,last_face_index, MVT_U8);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)material_data, 16, last_face_index, MVT_LLUUID);
+    }
+    mesgsys->addBinaryDataFast(_PREHASH_TextureEntry, packed_buffer, (S32)(cur_ptr - packed_buffer));
+
+    return FALSE;
 }
 
 
 BOOL LLPrimitive::packTEMessage(LLDataPacker &dp) const
 {
-	const U32 MAX_TES = 45;
-
-	U8     image_ids[MAX_TES*16];
-	U8     colors[MAX_TES*4];
-	F32    scale_s[MAX_TES];
-	F32    scale_t[MAX_TES];
-	S16    offset_s[MAX_TES];
-	S16    offset_t[MAX_TES];
-	S16    image_rot[MAX_TES];
-	U8	   bump[MAX_TES];
-	U8	   media_flags[MAX_TES];
+    const U32 MAX_TES = 45;
+
+    U8     image_ids[MAX_TES*16];
+    U8     colors[MAX_TES*4];
+    F32    scale_s[MAX_TES];
+    F32    scale_t[MAX_TES];
+    S16    offset_s[MAX_TES];
+    S16    offset_t[MAX_TES];
+    S16    image_rot[MAX_TES];
+    U8     bump[MAX_TES];
+    U8     media_flags[MAX_TES];
     U8     glow[MAX_TES];
-	U8     material_data[MAX_TES*16];
-	
-	const U32 MAX_TE_BUFFER = 4096;
-	U8 packed_buffer[MAX_TE_BUFFER];
-	U8 *cur_ptr = packed_buffer;
-	
-	S32 last_face_index = getNumTEs() - 1;
-	
-	if (last_face_index > -1)
-	{
-		// ...if we hit the front, send one image id
-		S8 face_index;
-		LLColor4U coloru;
-		for (face_index = 0; face_index <= last_face_index; face_index++)
-		{
-			// Directly sending image_ids is not safe!
-			memcpy(&image_ids[face_index*16],getTE(face_index)->getID().mData,16);	/* Flawfinder: ignore */ 
-
-			// Cast LLColor4 to LLColor4U
-			coloru.setVec( getTE(face_index)->getColor() );
-
-			// Note:  This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f)
-			// as all zeros.  However, the subtraction and addition must be done in unsigned
-			// byte space, not in float space, otherwise off-by-one errors occur. JC
-			colors[4*face_index]     = 255 - coloru.mV[0];
-			colors[4*face_index + 1] = 255 - coloru.mV[1];
-			colors[4*face_index + 2] = 255 - coloru.mV[2];
-			colors[4*face_index + 3] = 255 - coloru.mV[3];
-
-			const LLTextureEntry* te = getTE(face_index);
-			scale_s[face_index] = (F32) te->mScaleS;
-			scale_t[face_index] = (F32) te->mScaleT;
-			offset_s[face_index] = (S16) ll_round((llclamp(te->mOffsetS,-1.0f,1.0f) * (F32)0x7FFF)) ;
-			offset_t[face_index] = (S16) ll_round((llclamp(te->mOffsetT,-1.0f,1.0f) * (F32)0x7FFF)) ;
-			image_rot[face_index] = (S16) ll_round(((fmod(te->mRotation, F_TWO_PI)/F_TWO_PI) * TEXTURE_ROTATION_PACK_FACTOR));
-			bump[face_index] = te->getBumpShinyFullbright();
-			media_flags[face_index] = te->getMediaTexGen();
+    U8     material_data[MAX_TES*16];
+
+    const U32 MAX_TE_BUFFER = 4096;
+    U8 packed_buffer[MAX_TE_BUFFER];
+    U8 *cur_ptr = packed_buffer;
+
+    S32 last_face_index = getNumTEs() - 1;
+
+    if (last_face_index > -1)
+    {
+        // ...if we hit the front, send one image id
+        S8 face_index;
+        LLColor4U coloru;
+        for (face_index = 0; face_index <= last_face_index; face_index++)
+        {
+            // Directly sending image_ids is not safe!
+            memcpy(&image_ids[face_index*16],getTE(face_index)->getID().mData,16);  /* Flawfinder: ignore */
+
+            // Cast LLColor4 to LLColor4U
+            coloru.setVec( getTE(face_index)->getColor() );
+
+            // Note:  This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f)
+            // as all zeros.  However, the subtraction and addition must be done in unsigned
+            // byte space, not in float space, otherwise off-by-one errors occur. JC
+            colors[4*face_index]     = 255 - coloru.mV[0];
+            colors[4*face_index + 1] = 255 - coloru.mV[1];
+            colors[4*face_index + 2] = 255 - coloru.mV[2];
+            colors[4*face_index + 3] = 255 - coloru.mV[3];
+
+            const LLTextureEntry* te = getTE(face_index);
+            scale_s[face_index] = (F32) te->mScaleS;
+            scale_t[face_index] = (F32) te->mScaleT;
+            offset_s[face_index] = (S16) ll_round((llclamp(te->mOffsetS,-1.0f,1.0f) * (F32)0x7FFF)) ;
+            offset_t[face_index] = (S16) ll_round((llclamp(te->mOffsetT,-1.0f,1.0f) * (F32)0x7FFF)) ;
+            image_rot[face_index] = (S16) ll_round(((fmod(te->mRotation, F_TWO_PI)/F_TWO_PI) * TEXTURE_ROTATION_PACK_FACTOR));
+            bump[face_index] = te->getBumpShinyFullbright();
+            media_flags[face_index] = te->getMediaTexGen();
             glow[face_index] = (U8) ll_round((llclamp(te->getGlow(), 0.0f, 1.0f) * (F32)0xFF));
 
-			// Directly sending material_ids is not safe!
-			memcpy(&material_data[face_index*16],getTE(face_index)->getMaterialID().get(),16);	/* Flawfinder: ignore */ 
-		}
-
-		cur_ptr += packTEField(cur_ptr, (U8 *)image_ids, sizeof(LLUUID),last_face_index, MVT_LLUUID);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)colors, 4 ,last_face_index, MVT_U8);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)scale_s, 4 ,last_face_index, MVT_F32);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)scale_t, 4 ,last_face_index, MVT_F32);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)offset_s, 2 ,last_face_index, MVT_S16Array);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)offset_t, 2 ,last_face_index, MVT_S16Array);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)image_rot, 2 ,last_face_index, MVT_S16Array);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)bump, 1 ,last_face_index, MVT_U8);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)media_flags, 1 ,last_face_index, MVT_U8);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)glow, 1 ,last_face_index, MVT_U8);
-		*cur_ptr++ = 0;
-		cur_ptr += packTEField(cur_ptr, (U8 *)material_data, 16, last_face_index, MVT_LLUUID);
-	}
-
-	dp.packBinaryData(packed_buffer, (S32)(cur_ptr - packed_buffer), "TextureEntry");
-	return FALSE;
+            // Directly sending material_ids is not safe!
+            memcpy(&material_data[face_index*16],getTE(face_index)->getMaterialID().get(),16);  /* Flawfinder: ignore */
+        }
+
+        cur_ptr += packTEField(cur_ptr, (U8 *)image_ids, sizeof(LLUUID),last_face_index, MVT_LLUUID);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)colors, 4 ,last_face_index, MVT_U8);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)scale_s, 4 ,last_face_index, MVT_F32);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)scale_t, 4 ,last_face_index, MVT_F32);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)offset_s, 2 ,last_face_index, MVT_S16Array);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)offset_t, 2 ,last_face_index, MVT_S16Array);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)image_rot, 2 ,last_face_index, MVT_S16Array);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)bump, 1 ,last_face_index, MVT_U8);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)media_flags, 1 ,last_face_index, MVT_U8);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)glow, 1 ,last_face_index, MVT_U8);
+        *cur_ptr++ = 0;
+        cur_ptr += packTEField(cur_ptr, (U8 *)material_data, 16, last_face_index, MVT_LLUUID);
+    }
+
+    dp.packBinaryData(packed_buffer, (S32)(cur_ptr - packed_buffer), "TextureEntry");
+    return FALSE;
 }
 
 S32 LLPrimitive::parseTEMessage(LLMessageSystem* mesgsys, char const* block_name, const S32 block_num, LLTEContents& tec)
 {
-	S32 retval = 0;
+    S32 retval = 0;
     // temp buffer for material ID processing
-    // data will end up in tec.material_id[]	
+    // data will end up in tec.material_id[]
     material_id_type material_data[LLTEContents::MAX_TES];
 
-	if (block_num < 0)
-	{
-		tec.size = mesgsys->getSizeFast(block_name, _PREHASH_TextureEntry);
-	}
-	else
-	{
-		tec.size = mesgsys->getSizeFast(block_name, block_num, _PREHASH_TextureEntry);
-	}
-
-	if (tec.size == 0)
-	{
-		tec.face_count = 0;
-		return retval;
-	}
+    if (block_num < 0)
+    {
+        tec.size = mesgsys->getSizeFast(block_name, _PREHASH_TextureEntry);
+    }
+    else
+    {
+        tec.size = mesgsys->getSizeFast(block_name, block_num, _PREHASH_TextureEntry);
+    }
+
+    if (tec.size == 0)
+    {
+        tec.face_count = 0;
+        return retval;
+    }
     else if (tec.size >= LLTEContents::MAX_TE_BUFFER)
     {
         LL_WARNS("TEXTUREENTRY") << "Excessive buffer size detected in Texture Entry! Truncating." << LL_ENDL;
@@ -1406,14 +1406,14 @@ S32 LLPrimitive::parseTEMessage(LLMessageSystem* mesgsys, char const* block_name
     // if block_num < 0 ask for block 0
     mesgsys->getBinaryDataFast(block_name, _PREHASH_TextureEntry, tec.packed_buffer, 0, std::max(block_num, 0), LLTEContents::MAX_TE_BUFFER - 1);
 
-    // The last field is not zero terminated.  
+    // The last field is not zero terminated.
     // Rather than special case the upack functions.  Just make it 0x00 terminated.
     tec.packed_buffer[tec.size] = 0x00;
     ++tec.size;
 
-	tec.face_count = llmin((U32)getNumTEs(),(U32)LLTEContents::MAX_TES);
+    tec.face_count = llmin((U32)getNumTEs(),(U32)LLTEContents::MAX_TES);
 
-	U8 *cur_ptr = tec.packed_buffer;
+    U8 *cur_ptr = tec.packed_buffer;
 #ifdef SHOW_DEBUG
     LL_DEBUGS("TEXTUREENTRY") << "Texture Entry with buffere sized: " << tec.size << LL_ENDL;
 #endif
@@ -1434,68 +1434,68 @@ S32 LLPrimitive::parseTEMessage(LLMessageSystem* mesgsys, char const* block_name
         return 0;
     }
 
-	if (cur_ptr >= buffer_end || !unpack_TEField<material_id_type>(material_data, tec.face_count, cur_ptr, buffer_end, MVT_LLUUID))
-	{
-		memset((void*)material_data, 0, sizeof(material_data));
-	}
-	
-	for (U32 i = 0; i < tec.face_count; i++)
-	{
-		tec.material_ids[i].set(&(material_data[i]));
-	}
-	
-	retval = 1;
-	return retval;
-	}
-	
+    if (cur_ptr >= buffer_end || !unpack_TEField<material_id_type>(material_data, tec.face_count, cur_ptr, buffer_end, MVT_LLUUID))
+    {
+        memset((void*)material_data, 0, sizeof(material_data));
+    }
+
+    for (U32 i = 0; i < tec.face_count; i++)
+    {
+        tec.material_ids[i].set(&(material_data[i]));
+    }
+
+    retval = 1;
+    return retval;
+    }
+
 S32 LLPrimitive::applyParsedTEMessage(LLTEContents& tec)
 {
-	S32 retval = 0;
-	
-	LLColor4 color;
-	for (U32 i = 0; i < tec.face_count; i++)
-	{
-		LLUUID& req_id = ((LLUUID*)tec.image_data)[i];
-		retval |= setTETexture(i, req_id);
-		retval |= setTEScale(i, tec.scale_s[i], tec.scale_t[i]);
-		retval |= setTEOffset(i, (F32)tec.offset_s[i] / (F32)0x7FFF, (F32) tec.offset_t[i] / (F32) 0x7FFF);
-		retval |= setTERotation(i, ((F32)tec.image_rot[i] / TEXTURE_ROTATION_PACK_FACTOR) * F_TWO_PI);
-		retval |= setTEBumpShinyFullbright(i, tec.bump[i]);
-		retval |= setTEMediaTexGen(i, tec.media_flags[i]);
-		retval |= setTEGlow(i, (F32)tec.glow[i] / (F32)0xFF);
-		retval |= setTEMaterialID(i, tec.material_ids[i]);
-
-		// Note:  This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f)
-		// as all zeros.  However, the subtraction and addition must be done in unsigned
-		// byte space, not in float space, otherwise off-by-one errors occur. JC
-		color.mV[VRED]		= F32(255 - tec.colors[i].mV[VRED])   / 255.f;
-		color.mV[VGREEN]	= F32(255 - tec.colors[i].mV[VGREEN]) / 255.f;
-		color.mV[VBLUE]		= F32(255 - tec.colors[i].mV[VBLUE])  / 255.f;
-		color.mV[VALPHA]	= F32(255 - tec.colors[i].mV[VALPHA]) / 255.f;
-
-		retval |= setTEColor(i, color);
-	}
-
-	return retval;
+    S32 retval = 0;
+
+    LLColor4 color;
+    for (U32 i = 0; i < tec.face_count; i++)
+    {
+        LLUUID& req_id = ((LLUUID*)tec.image_data)[i];
+        retval |= setTETexture(i, req_id);
+        retval |= setTEScale(i, tec.scale_s[i], tec.scale_t[i]);
+        retval |= setTEOffset(i, (F32)tec.offset_s[i] / (F32)0x7FFF, (F32) tec.offset_t[i] / (F32) 0x7FFF);
+        retval |= setTERotation(i, ((F32)tec.image_rot[i] / TEXTURE_ROTATION_PACK_FACTOR) * F_TWO_PI);
+        retval |= setTEBumpShinyFullbright(i, tec.bump[i]);
+        retval |= setTEMediaTexGen(i, tec.media_flags[i]);
+        retval |= setTEGlow(i, (F32)tec.glow[i] / (F32)0xFF);
+        retval |= setTEMaterialID(i, tec.material_ids[i]);
+
+        // Note:  This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f)
+        // as all zeros.  However, the subtraction and addition must be done in unsigned
+        // byte space, not in float space, otherwise off-by-one errors occur. JC
+        color.mV[VRED]      = F32(255 - tec.colors[i].mV[VRED])   / 255.f;
+        color.mV[VGREEN]    = F32(255 - tec.colors[i].mV[VGREEN]) / 255.f;
+        color.mV[VBLUE]     = F32(255 - tec.colors[i].mV[VBLUE])  / 255.f;
+        color.mV[VALPHA]    = F32(255 - tec.colors[i].mV[VALPHA]) / 255.f;
+
+        retval |= setTEColor(i, color);
+    }
+
+    return retval;
 }
 
 S32 LLPrimitive::unpackTEMessage(LLMessageSystem* mesgsys, char const* block_name, const S32 block_num)
 {
-	LLTEContents tec;
-	S32 retval = parseTEMessage(mesgsys, block_name, block_num, tec);
-	if (!retval)
-		return retval;
-	return applyParsedTEMessage(tec);
+    LLTEContents tec;
+    S32 retval = parseTEMessage(mesgsys, block_name, block_num, tec);
+    if (!retval)
+        return retval;
+    return applyParsedTEMessage(tec);
 }
 
 S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp)
 {
-	// use a negative block_num to indicate a single-block read (a non-variable block)
-	S32 retval = 0;
-	const U32 MAX_TES = 45;
+    // use a negative block_num to indicate a single-block read (a non-variable block)
+    S32 retval = 0;
+    const U32 MAX_TES = 45;
 
-	// Avoid construction of 32 UUIDs per call
-	static LLMaterialID material_ids[MAX_TES];
+    // Avoid construction of 32 UUIDs per call
+    static LLMaterialID material_ids[MAX_TES];
 
     const U32 MAX_TE_BUFFER = 4096;
     U8 packed_buffer[MAX_TE_BUFFER];
@@ -1512,7 +1512,7 @@ S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp)
     U8          media_flags[MAX_TES];
     U8          glow[MAX_TES];
     material_id_type material_data[MAX_TES];
-    
+
     memset((void*)scale_s, 0, sizeof(scale_s));
     memset((void*)scale_t, 0, sizeof(scale_t));
     memset((void*)offset_s, 0, sizeof(offset_s));
@@ -1522,32 +1522,32 @@ S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp)
     memset((void*)media_flags, 0, sizeof(media_flags));
     memset((void*)glow, 0, sizeof(glow));
 
-	S32 size;
-	U32 face_count = 0;
+    S32 size;
+    U32 face_count = 0;
 
-	if (!dp.unpackBinaryData(packed_buffer, size, "TextureEntry"))
-	{
-		retval = TEM_INVALID;
-		LL_WARNS() << "Bad texture entry block!  Abort!" << LL_ENDL;
-		return retval;
-	}
+    if (!dp.unpackBinaryData(packed_buffer, size, "TextureEntry"))
+    {
+        retval = TEM_INVALID;
+        LL_WARNS() << "Bad texture entry block!  Abort!" << LL_ENDL;
+        return retval;
+    }
 
-	if (size == 0)
-	{
-		return retval;
-	}
+    if (size == 0)
+    {
+        return retval;
+    }
     else if (size >= MAX_TE_BUFFER)
     {
         LL_WARNS("TEXTUREENTRY") << "Excessive buffer size detected in Texture Entry! Truncating." << LL_ENDL;
         size = MAX_TE_BUFFER - 1;
     }
 
-    // The last field is not zero terminated.  
+    // The last field is not zero terminated.
     // Rather than special case the upack functions.  Just make it 0x00 terminated.
     packed_buffer[size] = 0x00;
     ++size;
-	face_count = llmin((U32) getNumTEs(), MAX_TES);
-	U32 i;
+    face_count = llmin((U32) getNumTEs(), MAX_TES);
+    U32 i;
 
     U8 *cur_ptr = packed_buffer;
 #ifdef SHOW_DEBUG
@@ -1570,81 +1570,81 @@ S32 LLPrimitive::unpackTEMessage(LLDataPacker &dp)
         return 0;
     }
 
-	if (cur_ptr >= buffer_end || !unpack_TEField<material_id_type>(material_data, face_count, cur_ptr, buffer_end, MVT_LLUUID))
-	{
-		memset((void*)material_data, 0, sizeof(material_data));
-	}
-
-	for (i = 0; i < face_count; i++)
-	{
-		material_ids[i].set(&(material_data[i]));
-	}
-	
-	LLColor4 color;
-	for (i = 0; i < face_count; i++)
-	{
-        retval |= setTETexture(i, ((LLUUID*)image_data)[i]);
-		retval |= setTEScale(i, scale_s[i], scale_t[i]);
-		retval |= setTEOffset(i, (F32)offset_s[i] / (F32)0x7FFF, (F32) offset_t[i] / (F32) 0x7FFF);
-		retval |= setTERotation(i, ((F32)image_rot[i] / TEXTURE_ROTATION_PACK_FACTOR) * F_TWO_PI);
-		retval |= setTEBumpShinyFullbright(i, bump[i]);
-		retval |= setTEMediaTexGen(i, media_flags[i]);
-		retval |= setTEGlow(i, (F32)glow[i] / (F32)0xFF);
-		retval |= setTEMaterialID(i, material_ids[i]);
+    if (cur_ptr >= buffer_end || !unpack_TEField<material_id_type>(material_data, face_count, cur_ptr, buffer_end, MVT_LLUUID))
+    {
+        memset((void*)material_data, 0, sizeof(material_data));
+    }
 
-		// Note:  This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f)
-		// as all zeros.  However, the subtraction and addition must be done in unsigned
-		// byte space, not in float space, otherwise off-by-one errors occur. JC
-		color.mV[VRED]		= F32(255 - colors[i].mV[VRED])   / 255.f;
- 		color.mV[VGREEN]	= F32(255 - colors[i].mV[VGREEN]) / 255.f;
- 		color.mV[VBLUE]		= F32(255 - colors[i].mV[VBLUE])  / 255.f;
- 		color.mV[VALPHA]	= F32(255 - colors[i].mV[VALPHA]) / 255.f;
+    for (i = 0; i < face_count; i++)
+    {
+        material_ids[i].set(&(material_data[i]));
+    }
 
-		retval |= setTEColor(i, color);
-	}
+    LLColor4 color;
+    for (i = 0; i < face_count; i++)
+    {
+        retval |= setTETexture(i, ((LLUUID*)image_data)[i]);
+        retval |= setTEScale(i, scale_s[i], scale_t[i]);
+        retval |= setTEOffset(i, (F32)offset_s[i] / (F32)0x7FFF, (F32) offset_t[i] / (F32) 0x7FFF);
+        retval |= setTERotation(i, ((F32)image_rot[i] / TEXTURE_ROTATION_PACK_FACTOR) * F_TWO_PI);
+        retval |= setTEBumpShinyFullbright(i, bump[i]);
+        retval |= setTEMediaTexGen(i, media_flags[i]);
+        retval |= setTEGlow(i, (F32)glow[i] / (F32)0xFF);
+        retval |= setTEMaterialID(i, material_ids[i]);
+
+        // Note:  This is an optimization to send common colors (1.f, 1.f, 1.f, 1.f)
+        // as all zeros.  However, the subtraction and addition must be done in unsigned
+        // byte space, not in float space, otherwise off-by-one errors occur. JC
+        color.mV[VRED]      = F32(255 - colors[i].mV[VRED])   / 255.f;
+        color.mV[VGREEN]    = F32(255 - colors[i].mV[VGREEN]) / 255.f;
+        color.mV[VBLUE]     = F32(255 - colors[i].mV[VBLUE])  / 255.f;
+        color.mV[VALPHA]    = F32(255 - colors[i].mV[VALPHA]) / 255.f;
+
+        retval |= setTEColor(i, color);
+    }
 
-	return retval;
+    return retval;
 }
 
-U8	LLPrimitive::getExpectedNumTEs() const
+U8  LLPrimitive::getExpectedNumTEs() const
 {
-	U8 expected_face_count = 0;
-	if (mVolumep)
-	{
-		expected_face_count = mVolumep->getNumFaces();
-	}
-	return expected_face_count;
+    U8 expected_face_count = 0;
+    if (mVolumep)
+    {
+        expected_face_count = mVolumep->getNumFaces();
+    }
+    return expected_face_count;
 }
 
 void LLPrimitive::copyTextureList(const LLPrimTextureList& other_list)
 {
-	mTextureList.copy(other_list);
+    mTextureList.copy(other_list);
 }
 
 void LLPrimitive::takeTextureList(LLPrimTextureList& other_list)
 {
-	mTextureList.take(other_list);
+    mTextureList.take(other_list);
 }
 
 void LLPrimitive::updateNumBumpmap(const U8 index, const U8 bump)
 {
-	LLTextureEntry* te = getTE(index);
-	if(!te)
-	{
-		return;
-	}
+    LLTextureEntry* te = getTE(index);
+    if(!te)
+    {
+        return;
+    }
 
-	U8 old_bump = te->getBumpmap();	
-	if(old_bump > 0)
-	{
-		mNumBumpmapTEs--;
-	}
-	if((bump & TEM_BUMP_MASK) > 0)
-	{
-		mNumBumpmapTEs++;
-	}
+    U8 old_bump = te->getBumpmap();
+    if(old_bump > 0)
+    {
+        mNumBumpmapTEs--;
+    }
+    if((bump & TEM_BUMP_MASK) > 0)
+    {
+        mNumBumpmapTEs++;
+    }
 
-	return;
+    return;
 }
 //============================================================================
 
@@ -1655,180 +1655,180 @@ void LLPrimitive::updateNumBumpmap(const U8 index, const U8 bump)
 // static
 bool LLPrimitive::getTESTAxes(const U8 face, U32* s_axis, U32* t_axis)
 {
-	if (face == 0)
-	{
-		*s_axis = VX; *t_axis = VY;
-		return true;
-	}
-	else if (face == 1)
-	{
-		*s_axis = VX; *t_axis = VZ;
-		return true;
-	}
-	else if (face == 2)
-	{
-		*s_axis = VY; *t_axis = VZ;
-		return true;
-	}
-	else if (face == 3)
-	{
-		*s_axis = VX; *t_axis = VZ;
-		return true;
-	}
-	else if (face == 4)
-	{
-		*s_axis = VY; *t_axis = VZ;
-		return true;
-	}
-	else if (face >= 5)
-	{
-		*s_axis = VX; *t_axis = VY;
-		return true;
-	}
-	else
-	{
-		// unknown face
-		return false;
-	}
+    if (face == 0)
+    {
+        *s_axis = VX; *t_axis = VY;
+        return true;
+    }
+    else if (face == 1)
+    {
+        *s_axis = VX; *t_axis = VZ;
+        return true;
+    }
+    else if (face == 2)
+    {
+        *s_axis = VY; *t_axis = VZ;
+        return true;
+    }
+    else if (face == 3)
+    {
+        *s_axis = VX; *t_axis = VZ;
+        return true;
+    }
+    else if (face == 4)
+    {
+        *s_axis = VY; *t_axis = VZ;
+        return true;
+    }
+    else if (face >= 5)
+    {
+        *s_axis = VX; *t_axis = VY;
+        return true;
+    }
+    else
+    {
+        // unknown face
+        return false;
+    }
 }
 
 //============================================================================
 
-//static 
+//static
 BOOL LLNetworkData::isValid(U16 param_type, U32 size)
 {
-	// ew - better mechanism needed
-	
-	switch(param_type)
-	{
-	case PARAMS_FLEXIBLE:
-		return (size == 16);
-	case PARAMS_LIGHT:
-		return (size == 16);
-	case PARAMS_SCULPT:
-		return (size == 17);
-	case PARAMS_LIGHT_IMAGE:
-		return (size == 28);
+    // ew - better mechanism needed
+
+    switch(param_type)
+    {
+    case PARAMS_FLEXIBLE:
+        return (size == 16);
+    case PARAMS_LIGHT:
+        return (size == 16);
+    case PARAMS_SCULPT:
+        return (size == 17);
+    case PARAMS_LIGHT_IMAGE:
+        return (size == 28);
     case PARAMS_EXTENDED_MESH:
         return (size == 4);
     case PARAMS_RENDER_MATERIAL:
         return (size > 1);
     case PARAMS_REFLECTION_PROBE:
         return (size == 9);
-	}
-	
-	return FALSE;
+    }
+
+    return FALSE;
 }
 
 //============================================================================
 
 LLLightParams::LLLightParams()
 {
-	mColor.setToWhite();
-	mRadius = 10.f;
-	mCutoff = 0.0f;
-	mFalloff = 0.75f;
+    mColor.setToWhite();
+    mRadius = 10.f;
+    mCutoff = 0.0f;
+    mFalloff = 0.75f;
 
-	mType = PARAMS_LIGHT;
+    mType = PARAMS_LIGHT;
 }
 
 BOOL LLLightParams::pack(LLDataPacker &dp) const
 {
-	LLColor4U color4u(mColor);
-	dp.packColor4U(color4u, "color");
-	dp.packF32(mRadius, "radius");
-	dp.packF32(mCutoff, "cutoff");
-	dp.packF32(mFalloff, "falloff");
-	return TRUE;
+    LLColor4U color4u(mColor);
+    dp.packColor4U(color4u, "color");
+    dp.packF32(mRadius, "radius");
+    dp.packF32(mCutoff, "cutoff");
+    dp.packF32(mFalloff, "falloff");
+    return TRUE;
 }
 
 BOOL LLLightParams::unpack(LLDataPacker &dp)
 {
-	LLColor4U color;
-	dp.unpackColor4U(color, "color");
-	setLinearColor(LLColor4(color));
+    LLColor4U color;
+    dp.unpackColor4U(color, "color");
+    setLinearColor(LLColor4(color));
 
-	F32 radius;
-	dp.unpackF32(radius, "radius");
-	setRadius(radius);
+    F32 radius;
+    dp.unpackF32(radius, "radius");
+    setRadius(radius);
 
-	F32 cutoff;
-	dp.unpackF32(cutoff, "cutoff");
-	setCutoff(cutoff);
+    F32 cutoff;
+    dp.unpackF32(cutoff, "cutoff");
+    setCutoff(cutoff);
 
-	F32 falloff;
-	dp.unpackF32(falloff, "falloff");
-	setFalloff(falloff);
-	
-	return TRUE;
+    F32 falloff;
+    dp.unpackF32(falloff, "falloff");
+    setFalloff(falloff);
+
+    return TRUE;
 }
 
 bool LLLightParams::operator==(const LLNetworkData& data) const
 {
-	if (data.mType != PARAMS_LIGHT)
-	{
-		return false;
-	}
-	const LLLightParams *param = (const LLLightParams*)&data;
-	if (param->mColor != mColor ||
-		param->mRadius != mRadius ||
-		param->mCutoff != mCutoff ||
-		param->mFalloff != mFalloff)
-	{
-		return false;
-	}
-	return true;
+    if (data.mType != PARAMS_LIGHT)
+    {
+        return false;
+    }
+    const LLLightParams *param = (const LLLightParams*)&data;
+    if (param->mColor != mColor ||
+        param->mRadius != mRadius ||
+        param->mCutoff != mCutoff ||
+        param->mFalloff != mFalloff)
+    {
+        return false;
+    }
+    return true;
 }
 
 void LLLightParams::copy(const LLNetworkData& data)
 {
-	const LLLightParams *param = (LLLightParams*)&data;
-	mType = param->mType;
-	mColor = param->mColor;
-	mRadius = param->mRadius;
-	mCutoff = param->mCutoff;
-	mFalloff = param->mFalloff;
+    const LLLightParams *param = (LLLightParams*)&data;
+    mType = param->mType;
+    mColor = param->mColor;
+    mRadius = param->mRadius;
+    mCutoff = param->mCutoff;
+    mFalloff = param->mFalloff;
 }
 
 LLSD LLLightParams::asLLSD() const
 {
-	LLSD sd;
-	
-	sd["color"] = ll_sd_from_color4(getLinearColor());
-	sd["radius"] = getRadius();
-	sd["falloff"] = getFalloff();
-	sd["cutoff"] = getCutoff();
-		
-	return sd;
+    LLSD sd;
+
+    sd["color"] = ll_sd_from_color4(getLinearColor());
+    sd["radius"] = getRadius();
+    sd["falloff"] = getFalloff();
+    sd["cutoff"] = getCutoff();
+
+    return sd;
 }
 
 bool LLLightParams::fromLLSD(LLSD& sd)
 {
-	const char *w;
-	w = "color";
-	if (sd.has(w))
-	{
-		setLinearColor( ll_color4_from_sd(sd["color"]) );
-	} else goto fail;
-	w = "radius";
-	if (sd.has(w))
-	{
-		setRadius( (F32)sd[w].asReal() );
-	} else goto fail;
-	w = "falloff";
-	if (sd.has(w))
-	{
-		setFalloff( (F32)sd[w].asReal() );
-	} else goto fail;
-	w = "cutoff";
-	if (sd.has(w))
-	{
-		setCutoff( (F32)sd[w].asReal() );
-	} else goto fail;
-	
-	return true;
+    const char *w;
+    w = "color";
+    if (sd.has(w))
+    {
+        setLinearColor( ll_color4_from_sd(sd["color"]) );
+    } else goto fail;
+    w = "radius";
+    if (sd.has(w))
+    {
+        setRadius( (F32)sd[w].asReal() );
+    } else goto fail;
+    w = "falloff";
+    if (sd.has(w))
+    {
+        setFalloff( (F32)sd[w].asReal() );
+    } else goto fail;
+    w = "cutoff";
+    if (sd.has(w))
+    {
+        setCutoff( (F32)sd[w].asReal() );
+    } else goto fail;
+
+    return true;
  fail:
-	return false;
+    return false;
 }
 
 //============================================================================
@@ -1842,39 +1842,39 @@ LLReflectionProbeParams::LLReflectionProbeParams()
 
 BOOL LLReflectionProbeParams::pack(LLDataPacker &dp) const
 {
-	dp.packF32(mAmbiance, "ambiance");
+    dp.packF32(mAmbiance, "ambiance");
     dp.packF32(mClipDistance, "clip_distance");
     dp.packU8(mFlags, "flags");
-	return TRUE;
+    return TRUE;
 }
 
 BOOL LLReflectionProbeParams::unpack(LLDataPacker &dp)
 {
-	F32 ambiance;
+    F32 ambiance;
     F32 clip_distance;
 
-	dp.unpackF32(ambiance, "ambiance");
-	setAmbiance(ambiance);
-	
+    dp.unpackF32(ambiance, "ambiance");
+    setAmbiance(ambiance);
+
     dp.unpackF32(clip_distance, "clip_distance");
-	setClipDistance(clip_distance);
-	
+    setClipDistance(clip_distance);
+
     dp.unpackU8(mFlags, "flags");
-	
-	return TRUE;
+
+    return TRUE;
 }
 
 bool LLReflectionProbeParams::operator==(const LLNetworkData& data) const
 {
-	if (data.mType != PARAMS_REFLECTION_PROBE)
-	{
-		return false;
-	}
-	const LLReflectionProbeParams *param = (const LLReflectionProbeParams*)&data;
-	if (param->mAmbiance != mAmbiance)
-	{
-		return false;
-	}
+    if (data.mType != PARAMS_REFLECTION_PROBE)
+    {
+        return false;
+    }
+    const LLReflectionProbeParams *param = (const LLReflectionProbeParams*)&data;
+    if (param->mAmbiance != mAmbiance)
+    {
+        return false;
+    }
     if (param->mClipDistance != mClipDistance)
     {
         return false;
@@ -1883,25 +1883,25 @@ bool LLReflectionProbeParams::operator==(const LLNetworkData& data) const
     {
         return false;
     }
-	return true;
+    return true;
 }
 
 void LLReflectionProbeParams::copy(const LLNetworkData& data)
 {
-	const LLReflectionProbeParams *param = (LLReflectionProbeParams*)&data;
-	mType = param->mType;
-	mAmbiance = param->mAmbiance;
+    const LLReflectionProbeParams *param = (LLReflectionProbeParams*)&data;
+    mType = param->mType;
+    mAmbiance = param->mAmbiance;
     mClipDistance = param->mClipDistance;
     mFlags = param->mFlags;
 }
 
 LLSD LLReflectionProbeParams::asLLSD() const
 {
-	LLSD sd;
-	sd["ambiance"] = getAmbiance();
+    LLSD sd;
+    sd["ambiance"] = getAmbiance();
     sd["clip_distance"] = getClipDistance();
     sd["flags"] = mFlags;
-	return sd;
+    return sd;
 }
 
 bool LLReflectionProbeParams::fromLLSD(LLSD& sd)
@@ -1913,10 +1913,10 @@ bool LLReflectionProbeParams::fromLLSD(LLSD& sd)
         return false;
     }
 
-	setAmbiance((F32)sd["ambiance"].asReal());
+    setAmbiance((F32)sd["ambiance"].asReal());
     setClipDistance((F32)sd["clip_distance"].asReal());
     mFlags = (U8) sd["flags"].asInteger();
-	
+
     return true;
 }
 
@@ -1960,312 +1960,312 @@ void LLReflectionProbeParams::setIsMirror(bool is_mirror)
 //============================================================================
 LLFlexibleObjectData::LLFlexibleObjectData()
 {
-	mSimulateLOD				= FLEXIBLE_OBJECT_DEFAULT_NUM_SECTIONS;
-	mGravity					= FLEXIBLE_OBJECT_DEFAULT_GRAVITY;
-	mAirFriction				= FLEXIBLE_OBJECT_DEFAULT_AIR_FRICTION;
-	mWindSensitivity			= FLEXIBLE_OBJECT_DEFAULT_WIND_SENSITIVITY;
-	mTension					= FLEXIBLE_OBJECT_DEFAULT_TENSION;
-	//mUsingCollisionSphere		= FLEXIBLE_OBJECT_DEFAULT_USING_COLLISION_SPHERE;
-	//mRenderingCollisionSphere	= FLEXIBLE_OBJECT_DEFAULT_RENDERING_COLLISION_SPHERE;
-	mUserForce					= LLVector3(0.f, 0.f, 0.f);
+    mSimulateLOD                = FLEXIBLE_OBJECT_DEFAULT_NUM_SECTIONS;
+    mGravity                    = FLEXIBLE_OBJECT_DEFAULT_GRAVITY;
+    mAirFriction                = FLEXIBLE_OBJECT_DEFAULT_AIR_FRICTION;
+    mWindSensitivity            = FLEXIBLE_OBJECT_DEFAULT_WIND_SENSITIVITY;
+    mTension                    = FLEXIBLE_OBJECT_DEFAULT_TENSION;
+    //mUsingCollisionSphere     = FLEXIBLE_OBJECT_DEFAULT_USING_COLLISION_SPHERE;
+    //mRenderingCollisionSphere = FLEXIBLE_OBJECT_DEFAULT_RENDERING_COLLISION_SPHERE;
+    mUserForce                  = LLVector3(0.f, 0.f, 0.f);
 
-	mType = PARAMS_FLEXIBLE;
+    mType = PARAMS_FLEXIBLE;
 }
 
 BOOL LLFlexibleObjectData::pack(LLDataPacker &dp) const
 {
-	// Custom, uber-svelte pack "softness" in upper bits of tension & drag
-	U8 bit1 = (mSimulateLOD & 2) << 6;
-	U8 bit2 = (mSimulateLOD & 1) << 7;
-	dp.packU8((U8)(mTension*10.01f) + bit1, "tension");
-	dp.packU8((U8)(mAirFriction*10.01f) + bit2, "drag");
-	dp.packU8((U8)((mGravity+10.f)*10.01f), "gravity");
-	dp.packU8((U8)(mWindSensitivity*10.01f), "wind");
-	dp.packVector3(mUserForce, "userforce");
-	return TRUE;
+    // Custom, uber-svelte pack "softness" in upper bits of tension & drag
+    U8 bit1 = (mSimulateLOD & 2) << 6;
+    U8 bit2 = (mSimulateLOD & 1) << 7;
+    dp.packU8((U8)(mTension*10.01f) + bit1, "tension");
+    dp.packU8((U8)(mAirFriction*10.01f) + bit2, "drag");
+    dp.packU8((U8)((mGravity+10.f)*10.01f), "gravity");
+    dp.packU8((U8)(mWindSensitivity*10.01f), "wind");
+    dp.packVector3(mUserForce, "userforce");
+    return TRUE;
 }
 
 BOOL LLFlexibleObjectData::unpack(LLDataPacker &dp)
 {
-	U8 tension, friction, gravity, wind;
-	U8 bit1, bit2;
-	dp.unpackU8(tension, "tension");	bit1 = (tension >> 6) & 2;
-										mTension = ((F32)(tension&0x7f))/10.f;
-	dp.unpackU8(friction, "drag");		bit2 = (friction >> 7) & 1;
-										mAirFriction = ((F32)(friction&0x7f))/10.f;
-										mSimulateLOD = bit1 | bit2;
-	dp.unpackU8(gravity, "gravity");	mGravity = ((F32)gravity)/10.f - 10.f;
-	dp.unpackU8(wind, "wind");			mWindSensitivity = ((F32)wind)/10.f;
-	if (dp.hasNext())
-	{
-		dp.unpackVector3(mUserForce, "userforce");
-	}
-	else
-	{
-		mUserForce.setVec(0.f, 0.f, 0.f);
-	}
-	return TRUE;
+    U8 tension, friction, gravity, wind;
+    U8 bit1, bit2;
+    dp.unpackU8(tension, "tension");    bit1 = (tension >> 6) & 2;
+                                        mTension = ((F32)(tension&0x7f))/10.f;
+    dp.unpackU8(friction, "drag");      bit2 = (friction >> 7) & 1;
+                                        mAirFriction = ((F32)(friction&0x7f))/10.f;
+                                        mSimulateLOD = bit1 | bit2;
+    dp.unpackU8(gravity, "gravity");    mGravity = ((F32)gravity)/10.f - 10.f;
+    dp.unpackU8(wind, "wind");          mWindSensitivity = ((F32)wind)/10.f;
+    if (dp.hasNext())
+    {
+        dp.unpackVector3(mUserForce, "userforce");
+    }
+    else
+    {
+        mUserForce.setVec(0.f, 0.f, 0.f);
+    }
+    return TRUE;
 }
 
 bool LLFlexibleObjectData::operator==(const LLNetworkData& data) const
 {
-	if (data.mType != PARAMS_FLEXIBLE)
-	{
-		return false;
-	}
-	LLFlexibleObjectData *flex_data = (LLFlexibleObjectData*)&data;
-	return (mSimulateLOD == flex_data->mSimulateLOD &&
-			mGravity == flex_data->mGravity &&
-			mAirFriction == flex_data->mAirFriction &&
-			mWindSensitivity == flex_data->mWindSensitivity &&
-			mTension == flex_data->mTension &&
-			mUserForce == flex_data->mUserForce);
-			//mUsingCollisionSphere == flex_data->mUsingCollisionSphere &&
-			//mRenderingCollisionSphere == flex_data->mRenderingCollisionSphere
+    if (data.mType != PARAMS_FLEXIBLE)
+    {
+        return false;
+    }
+    LLFlexibleObjectData *flex_data = (LLFlexibleObjectData*)&data;
+    return (mSimulateLOD == flex_data->mSimulateLOD &&
+            mGravity == flex_data->mGravity &&
+            mAirFriction == flex_data->mAirFriction &&
+            mWindSensitivity == flex_data->mWindSensitivity &&
+            mTension == flex_data->mTension &&
+            mUserForce == flex_data->mUserForce);
+            //mUsingCollisionSphere == flex_data->mUsingCollisionSphere &&
+            //mRenderingCollisionSphere == flex_data->mRenderingCollisionSphere
 }
 
 void LLFlexibleObjectData::copy(const LLNetworkData& data)
 {
-	const LLFlexibleObjectData *flex_data = (LLFlexibleObjectData*)&data;
-	mSimulateLOD = flex_data->mSimulateLOD;
-	mGravity = flex_data->mGravity;
-	mAirFriction = flex_data->mAirFriction;
-	mWindSensitivity = flex_data->mWindSensitivity;
-	mTension = flex_data->mTension;
-	mUserForce = flex_data->mUserForce;
-	//mUsingCollisionSphere = flex_data->mUsingCollisionSphere;
-	//mRenderingCollisionSphere = flex_data->mRenderingCollisionSphere;
+    const LLFlexibleObjectData *flex_data = (LLFlexibleObjectData*)&data;
+    mSimulateLOD = flex_data->mSimulateLOD;
+    mGravity = flex_data->mGravity;
+    mAirFriction = flex_data->mAirFriction;
+    mWindSensitivity = flex_data->mWindSensitivity;
+    mTension = flex_data->mTension;
+    mUserForce = flex_data->mUserForce;
+    //mUsingCollisionSphere = flex_data->mUsingCollisionSphere;
+    //mRenderingCollisionSphere = flex_data->mRenderingCollisionSphere;
 }
 
 LLSD LLFlexibleObjectData::asLLSD() const
 {
-	LLSD sd;
+    LLSD sd;
 
-	sd["air_friction"] = getAirFriction();
-	sd["gravity"] = getGravity();
-	sd["simulate_lod"] = getSimulateLOD();
-	sd["tension"] = getTension();
-	sd["user_force"] = getUserForce().getValue();
-	sd["wind_sensitivity"] = getWindSensitivity();
-	
-	return sd;
+    sd["air_friction"] = getAirFriction();
+    sd["gravity"] = getGravity();
+    sd["simulate_lod"] = getSimulateLOD();
+    sd["tension"] = getTension();
+    sd["user_force"] = getUserForce().getValue();
+    sd["wind_sensitivity"] = getWindSensitivity();
+
+    return sd;
 }
 
 bool LLFlexibleObjectData::fromLLSD(LLSD& sd)
 {
-	const char *w;
-	w = "air_friction";
-	if (sd.has(w))
-	{
-		setAirFriction( (F32)sd[w].asReal() );
-	} else goto fail;
-	w = "gravity";
-	if (sd.has(w))
-	{
-		setGravity( (F32)sd[w].asReal() );
-	} else goto fail;
-	w = "simulate_lod";
-	if (sd.has(w))
-	{
-		setSimulateLOD( sd[w].asInteger() );
-	} else goto fail;
-	w = "tension";
-	if (sd.has(w))
-	{
-		setTension( (F32)sd[w].asReal() );
-	} else goto fail;
-	w = "user_force";
-	if (sd.has(w))
-	{
-		LLVector3 user_force = ll_vector3_from_sd(sd[w], 0);
-		setUserForce( user_force );
-	} else goto fail;
-	w = "wind_sensitivity";
-	if (sd.has(w))
-	{
-		setWindSensitivity( (F32)sd[w].asReal() );
-	} else goto fail;
-	
-	return true;
+    const char *w;
+    w = "air_friction";
+    if (sd.has(w))
+    {
+        setAirFriction( (F32)sd[w].asReal() );
+    } else goto fail;
+    w = "gravity";
+    if (sd.has(w))
+    {
+        setGravity( (F32)sd[w].asReal() );
+    } else goto fail;
+    w = "simulate_lod";
+    if (sd.has(w))
+    {
+        setSimulateLOD( sd[w].asInteger() );
+    } else goto fail;
+    w = "tension";
+    if (sd.has(w))
+    {
+        setTension( (F32)sd[w].asReal() );
+    } else goto fail;
+    w = "user_force";
+    if (sd.has(w))
+    {
+        LLVector3 user_force = ll_vector3_from_sd(sd[w], 0);
+        setUserForce( user_force );
+    } else goto fail;
+    w = "wind_sensitivity";
+    if (sd.has(w))
+    {
+        setWindSensitivity( (F32)sd[w].asReal() );
+    } else goto fail;
+
+    return true;
  fail:
-	return false;
+    return false;
 }
 
 //============================================================================
 
 LLSculptParams::LLSculptParams()
 {
-	mType = PARAMS_SCULPT;
+    mType = PARAMS_SCULPT;
     mSculptTexture = SCULPT_DEFAULT_TEXTURE;
-	mSculptType = LL_SCULPT_TYPE_SPHERE;
+    mSculptType = LL_SCULPT_TYPE_SPHERE;
 }
 
 BOOL LLSculptParams::pack(LLDataPacker &dp) const
 {
-	dp.packUUID(mSculptTexture, "texture");
-	dp.packU8(mSculptType, "type");
-	
-	return TRUE;
+    dp.packUUID(mSculptTexture, "texture");
+    dp.packU8(mSculptType, "type");
+
+    return TRUE;
 }
 
 BOOL LLSculptParams::unpack(LLDataPacker &dp)
 {
-	U8 type;
-	LLUUID id;
-	dp.unpackUUID(id, "texture");
-	dp.unpackU8(type, "type");
+    U8 type;
+    LLUUID id;
+    dp.unpackUUID(id, "texture");
+    dp.unpackU8(type, "type");
 
-	setSculptTexture(id, type);
-	return TRUE;
+    setSculptTexture(id, type);
+    return TRUE;
 }
 
 bool LLSculptParams::operator==(const LLNetworkData& data) const
 {
-	if (data.mType != PARAMS_SCULPT)
-	{
-		return false;
-	}
-	
-	const LLSculptParams *param = (const LLSculptParams*)&data;
-	if ( (param->mSculptTexture != mSculptTexture) ||
-		 (param->mSculptType != mSculptType) )
-		 
-	{
-		return false;
-	}
-	
-	return true;
+    if (data.mType != PARAMS_SCULPT)
+    {
+        return false;
+    }
+
+    const LLSculptParams *param = (const LLSculptParams*)&data;
+    if ( (param->mSculptTexture != mSculptTexture) ||
+         (param->mSculptType != mSculptType) )
+
+    {
+        return false;
+    }
+
+    return true;
 }
 
 void LLSculptParams::copy(const LLNetworkData& data)
 {
-	const LLSculptParams *param = (LLSculptParams*)&data;
-	setSculptTexture(param->mSculptTexture, param->mSculptType);
+    const LLSculptParams *param = (LLSculptParams*)&data;
+    setSculptTexture(param->mSculptTexture, param->mSculptType);
 }
 
 
 
 LLSD LLSculptParams::asLLSD() const
 {
-	LLSD sd;
-	
-	sd["texture"] = mSculptTexture;
-	sd["type"] = mSculptType;
-		
-	return sd;
+    LLSD sd;
+
+    sd["texture"] = mSculptTexture;
+    sd["type"] = mSculptType;
+
+    return sd;
 }
 
 bool LLSculptParams::fromLLSD(LLSD& sd)
 {
-	const char *w;
-	U8 type;
-	w = "type";
-	if (sd.has(w))
-	{
-		type = sd[w].asInteger();
-	}
-	else return false;
+    const char *w;
+    U8 type;
+    w = "type";
+    if (sd.has(w))
+    {
+        type = sd[w].asInteger();
+    }
+    else return false;
 
-	w = "texture";
-	if (sd.has(w))
-	{
-		setSculptTexture(sd[w], type);
-	}
-	else return false;
+    w = "texture";
+    if (sd.has(w))
+    {
+        setSculptTexture(sd[w], type);
+    }
+    else return false;
 
-	return true;
+    return true;
 }
 
 void LLSculptParams::setSculptTexture(const LLUUID& texture_id, U8 sculpt_type)
 {
-	U8 type = sculpt_type & LL_SCULPT_TYPE_MASK;
-	U8 flags = sculpt_type & LL_SCULPT_FLAG_MASK;
-	if (sculpt_type != (type | flags) || type > LL_SCULPT_TYPE_MAX)
-	{
+    U8 type = sculpt_type & LL_SCULPT_TYPE_MASK;
+    U8 flags = sculpt_type & LL_SCULPT_FLAG_MASK;
+    if (sculpt_type != (type | flags) || type > LL_SCULPT_TYPE_MAX)
+    {
         mSculptTexture = SCULPT_DEFAULT_TEXTURE;
-		mSculptType = LL_SCULPT_TYPE_SPHERE;
-	}
-	else
-	{
-		mSculptTexture = texture_id;
-		mSculptType = sculpt_type;
-	}
+        mSculptType = LL_SCULPT_TYPE_SPHERE;
+    }
+    else
+    {
+        mSculptTexture = texture_id;
+        mSculptType = sculpt_type;
+    }
 }
 
 //============================================================================
 
 LLLightImageParams::LLLightImageParams()
 {
-	mType = PARAMS_LIGHT_IMAGE;
-	mParams.setVec(F_PI*0.5f, 0.f, 0.f);
+    mType = PARAMS_LIGHT_IMAGE;
+    mParams.setVec(F_PI*0.5f, 0.f, 0.f);
 }
 
 BOOL LLLightImageParams::pack(LLDataPacker &dp) const
 {
-	dp.packUUID(mLightTexture, "texture");
-	dp.packVector3(mParams, "params");
+    dp.packUUID(mLightTexture, "texture");
+    dp.packVector3(mParams, "params");
 
-	return TRUE;
+    return TRUE;
 }
 
 BOOL LLLightImageParams::unpack(LLDataPacker &dp)
 {
-	dp.unpackUUID(mLightTexture, "texture");
-	dp.unpackVector3(mParams, "params");
-	
-	return TRUE;
+    dp.unpackUUID(mLightTexture, "texture");
+    dp.unpackVector3(mParams, "params");
+
+    return TRUE;
 }
 
 bool LLLightImageParams::operator==(const LLNetworkData& data) const
 {
-	if (data.mType != PARAMS_LIGHT_IMAGE)
-	{
-		return false;
-	}
-	
-	const LLLightImageParams *param = (const LLLightImageParams*)&data;
-	if ( (param->mLightTexture != mLightTexture) )
-	{
-		return false;
-	}
-
-	if ( (param->mParams != mParams ) )
-	{
-		return false;
-	}
-	
-	return true;
+    if (data.mType != PARAMS_LIGHT_IMAGE)
+    {
+        return false;
+    }
+
+    const LLLightImageParams *param = (const LLLightImageParams*)&data;
+    if ( (param->mLightTexture != mLightTexture) )
+    {
+        return false;
+    }
+
+    if ( (param->mParams != mParams ) )
+    {
+        return false;
+    }
+
+    return true;
 }
 
 void LLLightImageParams::copy(const LLNetworkData& data)
 {
-	const LLLightImageParams *param = (LLLightImageParams*)&data;
-	mLightTexture = param->mLightTexture;
-	mParams = param->mParams;
+    const LLLightImageParams *param = (LLLightImageParams*)&data;
+    mLightTexture = param->mLightTexture;
+    mParams = param->mParams;
 }
 
 
 
 LLSD LLLightImageParams::asLLSD() const
 {
-	LLSD sd;
-	
-	sd["texture"] = mLightTexture;
-	sd["params"] = mParams.getValue();
-		
-	return sd;
+    LLSD sd;
+
+    sd["texture"] = mLightTexture;
+    sd["params"] = mParams.getValue();
+
+    return sd;
 }
 
 bool LLLightImageParams::fromLLSD(LLSD& sd)
 {
-	if (sd.has("texture"))
-	{
-		setLightTexture( sd["texture"] );
-		setParams( LLVector3( sd["params"] ) );
-		return true;
-	} 
-	
-	return false;
+    if (sd.has("texture"))
+    {
+        setLightTexture( sd["texture"] );
+        setParams( LLVector3( sd["params"] ) );
+        return true;
+    }
+
+    return false;
 }
 
 //============================================================================
@@ -2273,63 +2273,63 @@ bool LLLightImageParams::fromLLSD(LLSD& sd)
 LLExtendedMeshParams::LLExtendedMeshParams()
 {
     mType = PARAMS_EXTENDED_MESH;
-	mFlags = 0;
+    mFlags = 0;
 }
 
 BOOL LLExtendedMeshParams::pack(LLDataPacker &dp) const
 {
-	dp.packU32(mFlags, "flags");
+    dp.packU32(mFlags, "flags");
 
-	return TRUE;
+    return TRUE;
 }
 
 BOOL LLExtendedMeshParams::unpack(LLDataPacker &dp)
 {
-	dp.unpackU32(mFlags, "flags");
-	
-	return TRUE;
+    dp.unpackU32(mFlags, "flags");
+
+    return TRUE;
 }
 
 bool LLExtendedMeshParams::operator==(const LLNetworkData& data) const
 {
-	if (data.mType != PARAMS_EXTENDED_MESH)
-	{
-		return false;
-	}
-	
-	const LLExtendedMeshParams *param = (const LLExtendedMeshParams*)&data;
-	if ( (param->mFlags != mFlags) )
-	{
-		return false;
-	}
+    if (data.mType != PARAMS_EXTENDED_MESH)
+    {
+        return false;
+    }
 
-	return true;
+    const LLExtendedMeshParams *param = (const LLExtendedMeshParams*)&data;
+    if ( (param->mFlags != mFlags) )
+    {
+        return false;
+    }
+
+    return true;
 }
 
 void LLExtendedMeshParams::copy(const LLNetworkData& data)
 {
-	const LLExtendedMeshParams *param = (LLExtendedMeshParams*)&data;
-	mFlags = param->mFlags;
+    const LLExtendedMeshParams *param = (LLExtendedMeshParams*)&data;
+    mFlags = param->mFlags;
 }
 
 LLSD LLExtendedMeshParams::asLLSD() const
 {
-	LLSD sd;
-	
-	sd["flags"] = LLSD::Integer(mFlags);
-		
-	return sd;
+    LLSD sd;
+
+    sd["flags"] = LLSD::Integer(mFlags);
+
+    return sd;
 }
 
 bool LLExtendedMeshParams::fromLLSD(LLSD& sd)
 {
-	if (sd.has("flags"))
-	{
-		setFlags( sd["flags"].asInteger());
-		return true;
-	} 
-	
-	return false;
+    if (sd.has("flags"))
+    {
+        setFlags( sd["flags"].asInteger());
+        return true;
+    }
+
+    return false;
 }
 
 //============================================================================
diff --git a/indra/llprimitive/llprimitive.h b/indra/llprimitive/llprimitive.h
index 7944a16357cff0c3fb002cc37ed5800d0f66811f..55940a001964a34c0b23968051144bdca51f3b54 100644
--- a/indra/llprimitive/llprimitive.h
+++ b/indra/llprimitive/llprimitive.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llprimitive.h
  * @brief LLPrimitive base class
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -49,14 +49,14 @@ class LLVolumeMgr;
 
 enum LLGeomType // NOTE: same vals as GL Ids
 {
-	LLInvalid   = 0,
-	LLLineLoop  = 2,
-	LLLineStrip = 3,
-	LLTriangles = 4,
-	LLTriStrip  = 5,
-	LLTriFan    = 6,
-	LLQuads     = 7, 
-	LLQuadStrip = 8
+    LLInvalid   = 0,
+    LLLineLoop  = 2,
+    LLLineStrip = 3,
+    LLTriangles = 4,
+    LLTriStrip  = 5,
+    LLTriFan    = 6,
+    LLQuads     = 7,
+    LLQuadStrip = 8
 };
 
 class LLVolume;
@@ -101,29 +101,29 @@ extern const LLUUID SCULPT_DEFAULT_TEXTURE;
 class LLNetworkData
 {
 public:
-	// Extra parameter IDs
-	enum
-	{
-		PARAMS_FLEXIBLE = 0x10,
-		PARAMS_LIGHT    = 0x20,
-		PARAMS_SCULPT   = 0x30,
-		PARAMS_LIGHT_IMAGE = 0x40,
-		PARAMS_RESERVED = 0x50, // Used on server-side
-		PARAMS_MESH     = 0x60,
+    // Extra parameter IDs
+    enum
+    {
+        PARAMS_FLEXIBLE = 0x10,
+        PARAMS_LIGHT    = 0x20,
+        PARAMS_SCULPT   = 0x30,
+        PARAMS_LIGHT_IMAGE = 0x40,
+        PARAMS_RESERVED = 0x50, // Used on server-side
+        PARAMS_MESH     = 0x60,
         PARAMS_EXTENDED_MESH = 0x70,
         PARAMS_RENDER_MATERIAL = 0x80,
         PARAMS_REFLECTION_PROBE = 0x90,
-		PARAMS_MAX = PARAMS_REFLECTION_PROBE
-	};
-	
+        PARAMS_MAX = PARAMS_REFLECTION_PROBE
+    };
+
 public:
-	U16 mType;
-	virtual ~LLNetworkData() = default;
-	virtual BOOL pack(LLDataPacker &dp) const = 0;
-	virtual BOOL unpack(LLDataPacker &dp) = 0;
-	virtual bool operator==(const LLNetworkData& data) const = 0;
-	virtual void copy(const LLNetworkData& data) = 0;
-	static BOOL isValid(U16 param_type, U32 size);
+    U16 mType;
+    virtual ~LLNetworkData() = default;
+    virtual BOOL pack(LLDataPacker &dp) const = 0;
+    virtual BOOL unpack(LLDataPacker &dp) = 0;
+    virtual bool operator==(const LLNetworkData& data) const = 0;
+    virtual void copy(const LLNetworkData& data) = 0;
+    static BOOL isValid(U16 param_type, U32 size);
 };
 
 extern const F32 LIGHT_MIN_RADIUS;
@@ -139,22 +139,22 @@ extern const F32 LIGHT_MAX_CUTOFF;
 class LLLightParams final : public LLNetworkData
 {
 private:
-	LLColor4 mColor; // linear color (not gamma corrected), alpha = intensity
-	F32 mRadius;
-	F32 mFalloff;
-	F32 mCutoff;
+    LLColor4 mColor; // linear color (not gamma corrected), alpha = intensity
+    F32 mRadius;
+    F32 mFalloff;
+    F32 mCutoff;
 
 public:
-	LLLightParams();
-	/*virtual*/ BOOL pack(LLDataPacker &dp) const override;
-	/*virtual*/ BOOL unpack(LLDataPacker &dp) override;
-	/*virtual*/ bool operator==(const LLNetworkData& data) const override;
-	/*virtual*/ void copy(const LLNetworkData& data) override;
-	// LLSD implementations here are provided by Eddy Stryker.
-	// NOTE: there are currently unused in protocols
-	LLSD asLLSD() const;
-	operator LLSD() const { return asLLSD(); }
-	bool fromLLSD(LLSD& sd);
+    LLLightParams();
+    /*virtual*/ BOOL pack(LLDataPacker &dp) const override;
+    /*virtual*/ BOOL unpack(LLDataPacker &dp) override;
+    /*virtual*/ bool operator==(const LLNetworkData& data) const override;
+    /*virtual*/ void copy(const LLNetworkData& data) override;
+    // LLSD implementations here are provided by Eddy Stryker.
+    // NOTE: there are currently unused in protocols
+    LLSD asLLSD() const;
+    operator LLSD() const { return asLLSD(); }
+    bool fromLLSD(LLSD& sd);
 
     // set the color by gamma corrected color value
     //  color - gamma corrected color value (directly taken from an on-screen color swatch)
@@ -162,19 +162,19 @@ class LLLightParams final : public LLNetworkData
 
     // set the color by linear color value
     //  color - linear color value (value as it appears in shaders)
-    void setLinearColor(const LLColor4& color)	{ mColor = color; mColor.clamp(); }
-	void setRadius(F32 radius)				{ mRadius = llclamp(radius, LIGHT_MIN_RADIUS, LIGHT_MAX_RADIUS); }
-	void setFalloff(F32 falloff)			{ mFalloff = llclamp(falloff, LIGHT_MIN_FALLOFF, LIGHT_MAX_FALLOFF); }
-	void setCutoff(F32 cutoff)				{ mCutoff = llclamp(cutoff, LIGHT_MIN_CUTOFF, LIGHT_MAX_CUTOFF); }
+    void setLinearColor(const LLColor4& color)  { mColor = color; mColor.clamp(); }
+    void setRadius(F32 radius)              { mRadius = llclamp(radius, LIGHT_MIN_RADIUS, LIGHT_MAX_RADIUS); }
+    void setFalloff(F32 falloff)            { mFalloff = llclamp(falloff, LIGHT_MIN_FALLOFF, LIGHT_MAX_FALLOFF); }
+    void setCutoff(F32 cutoff)              { mCutoff = llclamp(cutoff, LIGHT_MIN_CUTOFF, LIGHT_MAX_CUTOFF); }
 
     // get the linear space color of this light.  This value can be fed directly to shaders
-    LLColor4 getLinearColor() const				{ return mColor; }
+    LLColor4 getLinearColor() const             { return mColor; }
     // get the sRGB (gamma corrected) color of this light, this is the value that should be displayed in the UI
-    LLColor4 getSRGBColor() const			{ return srgbColor4(mColor); }
-    
-	F32 getRadius() const					{ return mRadius; }
-	F32 getFalloff() const					{ return mFalloff; }
-	F32 getCutoff() const					{ return mCutoff; }
+    LLColor4 getSRGBColor() const           { return srgbColor4(mColor); }
+
+    F32 getRadius() const                   { return mRadius; }
+    F32 getFalloff() const                  { return mFalloff; }
+    F32 getCutoff() const                   { return mCutoff; }
 };
 
 extern const F32 REFLECTION_PROBE_MIN_AMBIANCE;
@@ -191,7 +191,7 @@ class LLReflectionProbeParams : public LLNetworkData
     {
         FLAG_BOX_VOLUME     = 0x01, // use a box influence volume
         FLAG_DYNAMIC        = 0x02, // render dynamic objects (avatars) into this Reflection Probe
-		FLAG_MIRROR			= 0x04, // This probe is used for reflections on realtime mirrors.
+        FLAG_MIRROR         = 0x04, // This probe is used for reflections on realtime mirrors.
     };
 
 protected:
@@ -225,7 +225,7 @@ class LLReflectionProbeParams : public LLNetworkData
 };
 
 //-------------------------------------------------
-// This structure is also used in the part of the 
+// This structure is also used in the part of the
 // code that creates new flexible objects.
 //-------------------------------------------------
 
@@ -233,11 +233,11 @@ class LLReflectionProbeParams : public LLNetworkData
 // array bounds.
 enum EFlexibleObjectConst
 {
-	// "Softness" => [0,3], increments of 1
-	// Represents powers of 2: 0 -> 1, 3 -> 8
-	FLEXIBLE_OBJECT_MIN_SECTIONS = 0,
-	FLEXIBLE_OBJECT_DEFAULT_NUM_SECTIONS = 2,
-	FLEXIBLE_OBJECT_MAX_SECTIONS = 3
+    // "Softness" => [0,3], increments of 1
+    // Represents powers of 2: 0 -> 1, 3 -> 8
+    FLEXIBLE_OBJECT_MIN_SECTIONS = 0,
+    FLEXIBLE_OBJECT_DEFAULT_NUM_SECTIONS = 2,
+    FLEXIBLE_OBJECT_MAX_SECTIONS = 3
 };
 
 // "Tension" => [0,10], increments of 0.1
@@ -270,39 +270,39 @@ extern const BOOL FLEXIBLE_OBJECT_DEFAULT_RENDERING_COLLISION_SPHERE;
 class LLFlexibleObjectData final : public LLNetworkData
 {
 protected:
-	S32			mSimulateLOD;		// 2^n = number of simulated sections
-	F32			mGravity;
-	F32			mAirFriction;		// higher is more stable, but too much looks like it's underwater
-	F32			mWindSensitivity;	// interacts with tension, air friction, and gravity
-	F32			mTension;			//interacts in complex ways with other parameters
-	LLVector3	mUserForce;			// custom user-defined force vector
-	//BOOL		mUsingCollisionSphere;
-	//BOOL		mRenderingCollisionSphere;
+    S32         mSimulateLOD;       // 2^n = number of simulated sections
+    F32         mGravity;
+    F32         mAirFriction;       // higher is more stable, but too much looks like it's underwater
+    F32         mWindSensitivity;   // interacts with tension, air friction, and gravity
+    F32         mTension;           //interacts in complex ways with other parameters
+    LLVector3   mUserForce;         // custom user-defined force vector
+    //BOOL      mUsingCollisionSphere;
+    //BOOL      mRenderingCollisionSphere;
 
 public:
-	void		setSimulateLOD(S32 lod)			{ mSimulateLOD = llclamp(lod, (S32)FLEXIBLE_OBJECT_MIN_SECTIONS, (S32)FLEXIBLE_OBJECT_MAX_SECTIONS); }
-	void		setGravity(F32 gravity)			{ mGravity = llclamp(gravity, FLEXIBLE_OBJECT_MIN_GRAVITY, FLEXIBLE_OBJECT_MAX_GRAVITY); }
-	void		setAirFriction(F32 friction)	{ mAirFriction = llclamp(friction, FLEXIBLE_OBJECT_MIN_AIR_FRICTION, FLEXIBLE_OBJECT_MAX_AIR_FRICTION); }
-	void		setWindSensitivity(F32 wind)	{ mWindSensitivity = llclamp(wind, FLEXIBLE_OBJECT_MIN_WIND_SENSITIVITY, FLEXIBLE_OBJECT_MAX_WIND_SENSITIVITY); }
-	void		setTension(F32 tension)			{ mTension = llclamp(tension, FLEXIBLE_OBJECT_MIN_TENSION, FLEXIBLE_OBJECT_MAX_TENSION); }
-	void		setUserForce(LLVector3 &force)	{ mUserForce = force; }
-
-	S32			getSimulateLOD() const			{ return mSimulateLOD; }
-	F32			getGravity() const				{ return mGravity; }
-	F32			getAirFriction() const			{ return mAirFriction; }
-	F32			getWindSensitivity() const		{ return mWindSensitivity; }
-	F32			getTension() const				{ return mTension; }
-	LLVector3	getUserForce() const			{ return mUserForce; }
-
-	//------ the constructor for the structure ------------
-	LLFlexibleObjectData();
-	BOOL pack(LLDataPacker &dp) const override;
-	BOOL unpack(LLDataPacker &dp) override;
-	bool operator==(const LLNetworkData& data) const override;
-	void copy(const LLNetworkData& data) override;
-	LLSD asLLSD() const;
-	operator LLSD() const { return asLLSD(); }
-	bool fromLLSD(LLSD& sd);
+    void        setSimulateLOD(S32 lod)         { mSimulateLOD = llclamp(lod, (S32)FLEXIBLE_OBJECT_MIN_SECTIONS, (S32)FLEXIBLE_OBJECT_MAX_SECTIONS); }
+    void        setGravity(F32 gravity)         { mGravity = llclamp(gravity, FLEXIBLE_OBJECT_MIN_GRAVITY, FLEXIBLE_OBJECT_MAX_GRAVITY); }
+    void        setAirFriction(F32 friction)    { mAirFriction = llclamp(friction, FLEXIBLE_OBJECT_MIN_AIR_FRICTION, FLEXIBLE_OBJECT_MAX_AIR_FRICTION); }
+    void        setWindSensitivity(F32 wind)    { mWindSensitivity = llclamp(wind, FLEXIBLE_OBJECT_MIN_WIND_SENSITIVITY, FLEXIBLE_OBJECT_MAX_WIND_SENSITIVITY); }
+    void        setTension(F32 tension)         { mTension = llclamp(tension, FLEXIBLE_OBJECT_MIN_TENSION, FLEXIBLE_OBJECT_MAX_TENSION); }
+    void        setUserForce(LLVector3 &force)  { mUserForce = force; }
+
+    S32         getSimulateLOD() const          { return mSimulateLOD; }
+    F32         getGravity() const              { return mGravity; }
+    F32         getAirFriction() const          { return mAirFriction; }
+    F32         getWindSensitivity() const      { return mWindSensitivity; }
+    F32         getTension() const              { return mTension; }
+    LLVector3   getUserForce() const            { return mUserForce; }
+
+    //------ the constructor for the structure ------------
+    LLFlexibleObjectData();
+    BOOL pack(LLDataPacker &dp) const override;
+    BOOL unpack(LLDataPacker &dp) override;
+    bool operator==(const LLNetworkData& data) const override;
+    void copy(const LLNetworkData& data) override;
+    LLSD asLLSD() const;
+    operator LLSD() const { return asLLSD(); }
+    bool fromLLSD(LLSD& sd);
 };// end of attributes structure
 
 
@@ -310,68 +310,68 @@ class LLFlexibleObjectData final : public LLNetworkData
 class LLSculptParams final : public LLNetworkData
 {
 protected:
-	LLUUID mSculptTexture;
-	U8 mSculptType;
-	
+    LLUUID mSculptTexture;
+    U8 mSculptType;
+
 public:
-	LLSculptParams();
-	/*virtual*/ BOOL pack(LLDataPacker &dp) const override;
-	/*virtual*/ BOOL unpack(LLDataPacker &dp) override;
-	/*virtual*/ bool operator==(const LLNetworkData& data) const override;
-	/*virtual*/ void copy(const LLNetworkData& data) override;
-	LLSD asLLSD() const;
-	operator LLSD() const { return asLLSD(); }
-	bool fromLLSD(LLSD& sd);
-
-	void setSculptTexture(const LLUUID& texture_id, U8 sculpt_type);
-	LLUUID getSculptTexture() const         { return mSculptTexture; }
-	U8 getSculptType() const                { return mSculptType; }
+    LLSculptParams();
+    /*virtual*/ BOOL pack(LLDataPacker &dp) const override;
+    /*virtual*/ BOOL unpack(LLDataPacker &dp) override;
+    /*virtual*/ bool operator==(const LLNetworkData& data) const override;
+    /*virtual*/ void copy(const LLNetworkData& data) override;
+    LLSD asLLSD() const;
+    operator LLSD() const { return asLLSD(); }
+    bool fromLLSD(LLSD& sd);
+
+    void setSculptTexture(const LLUUID& texture_id, U8 sculpt_type);
+    LLUUID getSculptTexture() const         { return mSculptTexture; }
+    U8 getSculptType() const                { return mSculptType; }
 };
 
 class LLLightImageParams final : public LLNetworkData
 {
 protected:
-	LLUUID mLightTexture;
-	LLVector3 mParams;
-	
+    LLUUID mLightTexture;
+    LLVector3 mParams;
+
 public:
-	LLLightImageParams();
-	/*virtual*/ BOOL pack(LLDataPacker &dp) const override;
-	/*virtual*/ BOOL unpack(LLDataPacker &dp) override;
-	/*virtual*/ bool operator==(const LLNetworkData& data) const override;
-	/*virtual*/ void copy(const LLNetworkData& data) override;
-	LLSD asLLSD() const;
-	operator LLSD() const { return asLLSD(); }
-	bool fromLLSD(LLSD& sd);
-
-	void setLightTexture(const LLUUID& id) { mLightTexture = id; }
-	LLUUID getLightTexture() const         { return mLightTexture; }
-	bool isLightSpotlight() const         { return mLightTexture.notNull(); }
-	void setParams(const LLVector3& params) { mParams = params; }
-	LLVector3 getParams() const			   { return mParams; }
-	
+    LLLightImageParams();
+    /*virtual*/ BOOL pack(LLDataPacker &dp) const override;
+    /*virtual*/ BOOL unpack(LLDataPacker &dp) override;
+    /*virtual*/ bool operator==(const LLNetworkData& data) const override;
+    /*virtual*/ void copy(const LLNetworkData& data) override;
+    LLSD asLLSD() const;
+    operator LLSD() const { return asLLSD(); }
+    bool fromLLSD(LLSD& sd);
+
+    void setLightTexture(const LLUUID& id) { mLightTexture = id; }
+    LLUUID getLightTexture() const         { return mLightTexture; }
+    bool isLightSpotlight() const         { return mLightTexture.notNull(); }
+    void setParams(const LLVector3& params) { mParams = params; }
+    LLVector3 getParams() const            { return mParams; }
+
 };
 
 class LLExtendedMeshParams final : public LLNetworkData
 {
 protected:
-	U32 mFlags;
-	
+    U32 mFlags;
+
 public:
-	static const U32 ANIMATED_MESH_ENABLED_FLAG = 0x1 << 0;
-
-	LLExtendedMeshParams();
-	/*virtual*/ BOOL pack(LLDataPacker &dp) const;
-	/*virtual*/ BOOL unpack(LLDataPacker &dp);
-	/*virtual*/ bool operator==(const LLNetworkData& data) const;
-	/*virtual*/ void copy(const LLNetworkData& data);
-	LLSD asLLSD() const;
-	operator LLSD() const { return asLLSD(); }
-	bool fromLLSD(LLSD& sd);
-
-	void setFlags(const U32& flags) { mFlags = flags; }
+    static const U32 ANIMATED_MESH_ENABLED_FLAG = 0x1 << 0;
+
+    LLExtendedMeshParams();
+    /*virtual*/ BOOL pack(LLDataPacker &dp) const;
+    /*virtual*/ BOOL unpack(LLDataPacker &dp);
+    /*virtual*/ bool operator==(const LLNetworkData& data) const;
+    /*virtual*/ void copy(const LLNetworkData& data);
+    LLSD asLLSD() const;
+    operator LLSD() const { return asLLSD(); }
+    bool fromLLSD(LLSD& sd);
+
+    void setFlags(const U32& flags) { mFlags = flags; }
     U32 getFlags() const { return mFlags; }
-	
+
 };
 
 class LLRenderMaterialParams : public LLNetworkData
@@ -390,7 +390,7 @@ class LLRenderMaterialParams : public LLNetworkData
     BOOL unpack(LLDataPacker& dp) override;
     bool operator==(const LLNetworkData& data) const override;
     void copy(const LLNetworkData& data) override;
-    
+
     void setMaterial(U8 te_idx, const LLUUID& id);
     const LLUUID& getMaterial(U8 te_idx) const;
 
@@ -400,249 +400,249 @@ class LLRenderMaterialParams : public LLNetworkData
 
 // This code is not naming-standards compliant. Leaving it like this for
 // now to make the connection to code in
-// 	BOOL packTEMessage(LLDataPacker &dp) const;
+//  BOOL packTEMessage(LLDataPacker &dp) const;
 // more obvious. This should be refactored to remove the duplication, at which
 // point we can fix the names as well.
 // - Vir
 struct LLTEContents
 {
-	static const U32 MAX_TES = 45;
+    static const U32 MAX_TES = 45;
 
     LLUUID      image_data[MAX_TES];
     LLColor4U   colors[MAX_TES];
-	F32    scale_s[MAX_TES];
-	F32    scale_t[MAX_TES];
-	S16    offset_s[MAX_TES];
-	S16    offset_t[MAX_TES];
-	S16    image_rot[MAX_TES];
-	U8	   bump[MAX_TES];
-	U8	   media_flags[MAX_TES];
+    F32    scale_s[MAX_TES];
+    F32    scale_t[MAX_TES];
+    S16    offset_s[MAX_TES];
+    S16    offset_t[MAX_TES];
+    S16    image_rot[MAX_TES];
+    U8     bump[MAX_TES];
+    U8     media_flags[MAX_TES];
     U8     glow[MAX_TES];
-	LLMaterialID material_ids[MAX_TES];
+    LLMaterialID material_ids[MAX_TES];
 
-	static const U32 MAX_TE_BUFFER = 4096;
-	U8 packed_buffer[MAX_TE_BUFFER];
+    static const U32 MAX_TE_BUFFER = 4096;
+    U8 packed_buffer[MAX_TE_BUFFER];
 
-	U32 size;
-	U32 face_count;
+    U32 size;
+    U32 face_count;
 };
 
 class LLPrimitive : public LLXform
 {
 public:
 
-	// HACK for removing LLPrimitive's dependency on gVolumeMgr global.
-	// If a different LLVolumeManager is instantiated and set early enough
-	// then the LLPrimitive class will use it instead of gVolumeMgr.
-	static LLVolumeMgr* getVolumeManager() { return sVolumeManager; }
-	static void setVolumeManager( LLVolumeMgr* volume_manager);
-	static bool cleanupVolumeManager();
-
-	// these flags influence how the RigidBody representation is built
-	static const U32 PRIM_FLAG_PHANTOM 				= 0x1 << 0;
-	static const U32 PRIM_FLAG_VOLUME_DETECT 		= 0x1 << 1;
-	static const U32 PRIM_FLAG_DYNAMIC 				= 0x1 << 2;
-	static const U32 PRIM_FLAG_AVATAR 				= 0x1 << 3;
-	static const U32 PRIM_FLAG_SCULPT 				= 0x1 << 4;
-	// not used yet, but soon
-	static const U32 PRIM_FLAG_COLLISION_CALLBACK 	= 0x1 << 5;
-	static const U32 PRIM_FLAG_CONVEX 				= 0x1 << 6;
-	static const U32 PRIM_FLAG_DEFAULT_VOLUME		= 0x1 << 7;
-	static const U32 PRIM_FLAG_SITTING				= 0x1 << 8;
-	static const U32 PRIM_FLAG_SITTING_ON_GROUND	= 0x1 << 9;		// Set along with PRIM_FLAG_SITTING
-
-	LLPrimitive();
-	virtual ~LLPrimitive();
-
-	void clearTextureList();
-
-	static LLPrimitive *createPrimitive(LLPCode p_code);
-	void init_primitive(LLPCode p_code);
-
-	void setPCode(const LLPCode pcode);
-	const LLVolume *getVolumeConst() const { return mVolumep; }		// HACK for Windoze confusion about ostream operator in LLVolume
-	LLVolume *getVolume() const { return mVolumep; }
-	virtual BOOL setVolume(const LLVolumeParams &volume_params, const S32 detail, bool unique_volume = false);
-	
-	// Modify texture entry properties
-	inline BOOL validTE(const U8 te_num) const;
-	LLTextureEntry* getTE(const U8 te_num) const;
-
-	virtual void setNumTEs(const U8 num_tes);
-	virtual void setAllTESelected(bool sel);
-	virtual void setAllTETextures(const LLUUID &tex_id);
-	virtual void setTE(const U8 index, const LLTextureEntry& te);
-	virtual S32 setTEColor(const U8 te, const LLColor4 &color);
-	virtual S32 setTEColor(const U8 te, const LLColor3 &color);
-	virtual S32 setTEAlpha(const U8 te, const F32 alpha);
-	virtual S32 setTETexture(const U8 te, const LLUUID &tex_id);
-	virtual S32 setTEScale (const U8 te, const F32 s, const F32 t);
-	virtual S32 setTEScaleS(const U8 te, const F32 s);
-	virtual S32 setTEScaleT(const U8 te, const F32 t);
-	virtual S32 setTEOffset (const U8 te, const F32 s, const F32 t);
-	virtual S32 setTEOffsetS(const U8 te, const F32 s);
-	virtual S32 setTEOffsetT(const U8 te, const F32 t);
-	virtual S32 setTERotation(const U8 te, const F32 r);
-	virtual S32 setTEBumpShinyFullbright(const U8 te, const U8 bump);
-	virtual S32 setTEBumpShiny(const U8 te, const U8 bump);
-	virtual S32 setTEMediaTexGen(const U8 te, const U8 media);
-	virtual S32 setTEBumpmap(const U8 te, const U8 bump);
-	virtual S32 setTETexGen(const U8 te, const U8 texgen);
-	virtual S32 setTEShiny(const U8 te, const U8 shiny);
-	virtual S32 setTEFullbright(const U8 te, const U8 fullbright);
-	virtual S32 setTEMediaFlags(const U8 te, const U8 flags);
-	virtual S32 setTEGlow(const U8 te, const F32 glow);
-	virtual S32 setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID);
+    // HACK for removing LLPrimitive's dependency on gVolumeMgr global.
+    // If a different LLVolumeManager is instantiated and set early enough
+    // then the LLPrimitive class will use it instead of gVolumeMgr.
+    static LLVolumeMgr* getVolumeManager() { return sVolumeManager; }
+    static void setVolumeManager( LLVolumeMgr* volume_manager);
+    static bool cleanupVolumeManager();
+
+    // these flags influence how the RigidBody representation is built
+    static const U32 PRIM_FLAG_PHANTOM              = 0x1 << 0;
+    static const U32 PRIM_FLAG_VOLUME_DETECT        = 0x1 << 1;
+    static const U32 PRIM_FLAG_DYNAMIC              = 0x1 << 2;
+    static const U32 PRIM_FLAG_AVATAR               = 0x1 << 3;
+    static const U32 PRIM_FLAG_SCULPT               = 0x1 << 4;
+    // not used yet, but soon
+    static const U32 PRIM_FLAG_COLLISION_CALLBACK   = 0x1 << 5;
+    static const U32 PRIM_FLAG_CONVEX               = 0x1 << 6;
+    static const U32 PRIM_FLAG_DEFAULT_VOLUME       = 0x1 << 7;
+    static const U32 PRIM_FLAG_SITTING              = 0x1 << 8;
+    static const U32 PRIM_FLAG_SITTING_ON_GROUND    = 0x1 << 9;     // Set along with PRIM_FLAG_SITTING
+
+    LLPrimitive();
+    virtual ~LLPrimitive();
+
+    void clearTextureList();
+
+    static LLPrimitive *createPrimitive(LLPCode p_code);
+    void init_primitive(LLPCode p_code);
+
+    void setPCode(const LLPCode pcode);
+    const LLVolume *getVolumeConst() const { return mVolumep; }     // HACK for Windoze confusion about ostream operator in LLVolume
+    LLVolume *getVolume() const { return mVolumep; }
+    virtual BOOL setVolume(const LLVolumeParams &volume_params, const S32 detail, bool unique_volume = false);
+
+    // Modify texture entry properties
+    inline BOOL validTE(const U8 te_num) const;
+    LLTextureEntry* getTE(const U8 te_num) const;
+
+    virtual void setNumTEs(const U8 num_tes);
+    virtual void setAllTESelected(bool sel);
+    virtual void setAllTETextures(const LLUUID &tex_id);
+    virtual void setTE(const U8 index, const LLTextureEntry& te);
+    virtual S32 setTEColor(const U8 te, const LLColor4 &color);
+    virtual S32 setTEColor(const U8 te, const LLColor3 &color);
+    virtual S32 setTEAlpha(const U8 te, const F32 alpha);
+    virtual S32 setTETexture(const U8 te, const LLUUID &tex_id);
+    virtual S32 setTEScale (const U8 te, const F32 s, const F32 t);
+    virtual S32 setTEScaleS(const U8 te, const F32 s);
+    virtual S32 setTEScaleT(const U8 te, const F32 t);
+    virtual S32 setTEOffset (const U8 te, const F32 s, const F32 t);
+    virtual S32 setTEOffsetS(const U8 te, const F32 s);
+    virtual S32 setTEOffsetT(const U8 te, const F32 t);
+    virtual S32 setTERotation(const U8 te, const F32 r);
+    virtual S32 setTEBumpShinyFullbright(const U8 te, const U8 bump);
+    virtual S32 setTEBumpShiny(const U8 te, const U8 bump);
+    virtual S32 setTEMediaTexGen(const U8 te, const U8 media);
+    virtual S32 setTEBumpmap(const U8 te, const U8 bump);
+    virtual S32 setTETexGen(const U8 te, const U8 texgen);
+    virtual S32 setTEShiny(const U8 te, const U8 shiny);
+    virtual S32 setTEFullbright(const U8 te, const U8 fullbright);
+    virtual S32 setTEMediaFlags(const U8 te, const U8 flags);
+    virtual S32 setTEGlow(const U8 te, const F32 glow);
+    virtual S32 setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID);
     virtual S32 setTEMaterialParams(const U8 index, const LLMaterialPtr pMaterialParams);
-	virtual BOOL setMaterial(const U8 material); // returns TRUE if material changed
-	virtual void setTESelected(const U8 te, bool sel);
-
-	LLMaterialPtr getTEMaterialParams(const U8 index);
-    
-	void copyTEs(const LLPrimitive *primitive);
-	S32 packTEField(U8 *cur_ptr, U8 *data_ptr, U8 data_size, U8 last_face_index, EMsgVariableType type) const;
-	BOOL packTEMessage(LLMessageSystem *mesgsys) const;
-	BOOL packTEMessage(LLDataPacker &dp) const;
-	S32 unpackTEMessage(LLMessageSystem* mesgsys, char const* block_name, const S32 block_num); // Variable num of blocks
-	BOOL unpackTEMessage(LLDataPacker &dp);
-	S32 parseTEMessage(LLMessageSystem* mesgsys, char const* block_name, const S32 block_num, LLTEContents& tec);
-	S32 applyParsedTEMessage(LLTEContents& tec);
-	
+    virtual BOOL setMaterial(const U8 material); // returns TRUE if material changed
+    virtual void setTESelected(const U8 te, bool sel);
+
+    LLMaterialPtr getTEMaterialParams(const U8 index);
+
+    void copyTEs(const LLPrimitive *primitive);
+    S32 packTEField(U8 *cur_ptr, U8 *data_ptr, U8 data_size, U8 last_face_index, EMsgVariableType type) const;
+    BOOL packTEMessage(LLMessageSystem *mesgsys) const;
+    BOOL packTEMessage(LLDataPacker &dp) const;
+    S32 unpackTEMessage(LLMessageSystem* mesgsys, char const* block_name, const S32 block_num); // Variable num of blocks
+    BOOL unpackTEMessage(LLDataPacker &dp);
+    S32 parseTEMessage(LLMessageSystem* mesgsys, char const* block_name, const S32 block_num, LLTEContents& tec);
+    S32 applyParsedTEMessage(LLTEContents& tec);
+
 #ifdef CHECK_FOR_FINITE
-	inline void setPosition(const LLVector3& pos);
-	inline void setPosition(const F32 x, const F32 y, const F32 z);
-	inline void addPosition(const LLVector3& pos);
-
-	inline void setAngularVelocity(const LLVector3& avel);
-	inline void setAngularVelocity(const F32 x, const F32 y, const F32 z);
-	inline void setVelocity(const LLVector3& vel);
-	inline void setVelocity(const F32 x, const F32 y, const F32 z);
-	inline void setVelocityX(const F32 x);
-	inline void setVelocityY(const F32 y);
-	inline void setVelocityZ(const F32 z);
-	inline void addVelocity(const LLVector3& vel);
-	inline void setAcceleration(const LLVector3& accel);
-	inline void setAcceleration(const F32 x, const F32 y, const F32 z);
+    inline void setPosition(const LLVector3& pos);
+    inline void setPosition(const F32 x, const F32 y, const F32 z);
+    inline void addPosition(const LLVector3& pos);
+
+    inline void setAngularVelocity(const LLVector3& avel);
+    inline void setAngularVelocity(const F32 x, const F32 y, const F32 z);
+    inline void setVelocity(const LLVector3& vel);
+    inline void setVelocity(const F32 x, const F32 y, const F32 z);
+    inline void setVelocityX(const F32 x);
+    inline void setVelocityY(const F32 y);
+    inline void setVelocityZ(const F32 z);
+    inline void addVelocity(const LLVector3& vel);
+    inline void setAcceleration(const LLVector3& accel);
+    inline void setAcceleration(const F32 x, const F32 y, const F32 z);
 #else
-	// Don't override the base LLXForm operators.
-	// Special case for setPosition.  If not check-for-finite, fall through to LLXform method.
-	// void		setPosition(F32 x, F32 y, F32 z)
-	// void		setPosition(LLVector3)
-
-	void 		setAngularVelocity(const LLVector3& avel)	{ mAngularVelocity = avel; }
-	void 		setAngularVelocity(const F32 x, const F32 y, const F32 z)	{ mAngularVelocity.setVec(x,y,z); }
-	void 		setVelocity(const LLVector3& vel)			{ mVelocity = vel; }
-	void 		setVelocity(const F32 x, const F32 y, const F32 z)			{ mVelocity.setVec(x,y,z); }
-	void 		setVelocityX(const F32 x)					{ mVelocity.mV[VX] = x; }
-	void 		setVelocityY(const F32 y)					{ mVelocity.mV[VY] = y; }
-	void 		setVelocityZ(const F32 z)					{ mVelocity.mV[VZ] = z; }
-	void 		addVelocity(const LLVector3& vel)			{ mVelocity += vel; }
-	void 		setAcceleration(const LLVector3& accel)		{ mAcceleration = accel; }
-	void 		setAcceleration(const F32 x, const F32 y, const F32 z)		{ mAcceleration.setVec(x,y,z); }
+    // Don't override the base LLXForm operators.
+    // Special case for setPosition.  If not check-for-finite, fall through to LLXform method.
+    // void     setPosition(F32 x, F32 y, F32 z)
+    // void     setPosition(LLVector3)
+
+    void        setAngularVelocity(const LLVector3& avel)   { mAngularVelocity = avel; }
+    void        setAngularVelocity(const F32 x, const F32 y, const F32 z)   { mAngularVelocity.setVec(x,y,z); }
+    void        setVelocity(const LLVector3& vel)           { mVelocity = vel; }
+    void        setVelocity(const F32 x, const F32 y, const F32 z)          { mVelocity.setVec(x,y,z); }
+    void        setVelocityX(const F32 x)                   { mVelocity.mV[VX] = x; }
+    void        setVelocityY(const F32 y)                   { mVelocity.mV[VY] = y; }
+    void        setVelocityZ(const F32 z)                   { mVelocity.mV[VZ] = z; }
+    void        addVelocity(const LLVector3& vel)           { mVelocity += vel; }
+    void        setAcceleration(const LLVector3& accel)     { mAcceleration = accel; }
+    void        setAcceleration(const F32 x, const F32 y, const F32 z)      { mAcceleration.setVec(x,y,z); }
 #endif
-	
-	LLPCode				getPCode() const			{ return mPrimitiveCode; }
-	std::string			getPCodeString() const		{ return pCodeToString(mPrimitiveCode); }
-	const LLVector3&	getAngularVelocity() const	{ return mAngularVelocity; }
-	const LLVector3&	getVelocity() const			{ return mVelocity; }
-	const LLVector3&	getAcceleration() const		{ return mAcceleration; }
-	U8					getNumTEs() const			{ return mTextureList.size(); }
-	U8					getExpectedNumTEs() const;
-
-	U8					getMaterial() const			{ return mMaterial; }
-	
-	void				setVolumeType(const U8 code);
-	U8					getVolumeType();
-
-	// clears existing textures
-	// copies the contents of other_list into mEntryList
-	void copyTextureList(const LLPrimTextureList& other_list);
-
-	// clears existing textures
-	// takes the contents of other_list and clears other_list
-	void takeTextureList(LLPrimTextureList& other_list);
-
-	inline BOOL	isAvatar() const;
-	inline BOOL	isSittingAvatar() const;
-	inline BOOL	isSittingAvatarOnGround() const;
-	inline bool hasBumpmap() const  { return mNumBumpmapTEs > 0;}
-	
-	void setFlags(U32 flags) { mMiscFlags = flags; }
-	void addFlags(U32 flags) { mMiscFlags |= flags; }
-	void removeFlags(U32 flags) { mMiscFlags &= ~flags; }
-	U32 getFlags() const { return mMiscFlags; }
-
-	static std::string pCodeToString(const LLPCode pcode);
-	static LLPCode legacyToPCode(const U8 legacy);
-	static U8 pCodeToLegacy(const LLPCode pcode);
-	static bool getTESTAxes(const U8 face, U32* s_axis, U32* t_axis);
+
+    LLPCode             getPCode() const            { return mPrimitiveCode; }
+    std::string         getPCodeString() const      { return pCodeToString(mPrimitiveCode); }
+    const LLVector3&    getAngularVelocity() const  { return mAngularVelocity; }
+    const LLVector3&    getVelocity() const         { return mVelocity; }
+    const LLVector3&    getAcceleration() const     { return mAcceleration; }
+    U8                  getNumTEs() const           { return mTextureList.size(); }
+    U8                  getExpectedNumTEs() const;
+
+    U8                  getMaterial() const         { return mMaterial; }
+
+    void                setVolumeType(const U8 code);
+    U8                  getVolumeType();
+
+    // clears existing textures
+    // copies the contents of other_list into mEntryList
+    void copyTextureList(const LLPrimTextureList& other_list);
+
+    // clears existing textures
+    // takes the contents of other_list and clears other_list
+    void takeTextureList(LLPrimTextureList& other_list);
+
+    inline BOOL isAvatar() const;
+    inline BOOL isSittingAvatar() const;
+    inline BOOL isSittingAvatarOnGround() const;
+    inline bool hasBumpmap() const  { return mNumBumpmapTEs > 0;}
+
+    void setFlags(U32 flags) { mMiscFlags = flags; }
+    void addFlags(U32 flags) { mMiscFlags |= flags; }
+    void removeFlags(U32 flags) { mMiscFlags &= ~flags; }
+    U32 getFlags() const { return mMiscFlags; }
+
+    static std::string pCodeToString(const LLPCode pcode);
+    static LLPCode legacyToPCode(const U8 legacy);
+    static U8 pCodeToLegacy(const LLPCode pcode);
+    static bool getTESTAxes(const U8 face, U32* s_axis, U32* t_axis);
 
     BOOL hasRenderMaterialParams() const;
-	
-	inline static BOOL isPrimitive(const LLPCode pcode);
-	inline static BOOL isApp(const LLPCode pcode);
+
+    inline static BOOL isPrimitive(const LLPCode pcode);
+    inline static BOOL isApp(const LLPCode pcode);
 
 private:
-	void updateNumBumpmap(const U8 index, const U8 bump);
+    void updateNumBumpmap(const U8 index, const U8 bump);
 
 protected:
-	LLPCode				mPrimitiveCode;		// Primitive code
-	LLVector3			mVelocity;			// how fast are we moving?
-	LLVector3			mAcceleration;		// are we under constant acceleration?
-	LLVector3			mAngularVelocity;	// angular velocity
-	LLPointer<LLVolume> mVolumep;
-	LLPrimTextureList	mTextureList;		// list of texture GUIDs, scales, offsets
-	U8					mMaterial;			// Material code
-	U8					mNumTEs;			// # of faces on the primitve	
-	U8                  mNumBumpmapTEs;     // number of bumpmap TEs.
-	U32 				mMiscFlags;			// home for misc bools
+    LLPCode             mPrimitiveCode;     // Primitive code
+    LLVector3           mVelocity;          // how fast are we moving?
+    LLVector3           mAcceleration;      // are we under constant acceleration?
+    LLVector3           mAngularVelocity;   // angular velocity
+    LLPointer<LLVolume> mVolumep;
+    LLPrimTextureList   mTextureList;       // list of texture GUIDs, scales, offsets
+    U8                  mMaterial;          // Material code
+    U8                  mNumTEs;            // # of faces on the primitve
+    U8                  mNumBumpmapTEs;     // number of bumpmap TEs.
+    U32                 mMiscFlags;         // home for misc bools
 
 public:
-	static LLVolumeMgr* sVolumeManager;
+    static LLVolumeMgr* sVolumeManager;
 
-	enum
-	{
-		NO_LOD = -1
-	};
+    enum
+    {
+        NO_LOD = -1
+    };
 };
 
 inline BOOL LLPrimitive::isAvatar() const
 {
-	return ( LL_PCODE_LEGACY_AVATAR == mPrimitiveCode ) ? TRUE : FALSE;
+    return ( LL_PCODE_LEGACY_AVATAR == mPrimitiveCode ) ? TRUE : FALSE;
 }
 
 inline BOOL LLPrimitive::isSittingAvatar() const
 {
-	// this is only used server-side
-	return ( LL_PCODE_LEGACY_AVATAR == mPrimitiveCode 
-			 &&	 ((getFlags() & (PRIM_FLAG_SITTING | PRIM_FLAG_SITTING_ON_GROUND)) != 0) ) ? TRUE : FALSE;
+    // this is only used server-side
+    return ( LL_PCODE_LEGACY_AVATAR == mPrimitiveCode
+             &&  ((getFlags() & (PRIM_FLAG_SITTING | PRIM_FLAG_SITTING_ON_GROUND)) != 0) ) ? TRUE : FALSE;
 }
 
 inline BOOL LLPrimitive::isSittingAvatarOnGround() const
 {
-	// this is only used server-side
-	return ( LL_PCODE_LEGACY_AVATAR == mPrimitiveCode 
-			 &&	 ((getFlags() & PRIM_FLAG_SITTING_ON_GROUND) != 0) ) ? TRUE : FALSE;
+    // this is only used server-side
+    return ( LL_PCODE_LEGACY_AVATAR == mPrimitiveCode
+             &&  ((getFlags() & PRIM_FLAG_SITTING_ON_GROUND) != 0) ) ? TRUE : FALSE;
 }
 
 // static
 inline BOOL LLPrimitive::isPrimitive(const LLPCode pcode)
 {
-	LLPCode base_type = pcode & LL_PCODE_BASE_MASK;
+    LLPCode base_type = pcode & LL_PCODE_BASE_MASK;
 
-	if (base_type && (base_type < LL_PCODE_APP))
-	{
-		return TRUE;
-	}
-	return FALSE;
+    if (base_type && (base_type < LL_PCODE_APP))
+    {
+        return TRUE;
+    }
+    return FALSE;
 }
 
 // static
 inline BOOL LLPrimitive::isApp(const LLPCode pcode)
 {
-	LLPCode base_type = pcode & LL_PCODE_BASE_MASK;
+    LLPCode base_type = pcode & LL_PCODE_BASE_MASK;
 
-	return (base_type == LL_PCODE_APP);
+    return (base_type == LL_PCODE_APP);
 }
 
 
@@ -650,153 +650,153 @@ inline BOOL LLPrimitive::isApp(const LLPCode pcode)
 // Special case for setPosition.  If not check-for-finite, fall through to LLXform method.
 void LLPrimitive::setPosition(const F32 x, const F32 y, const F32 z)
 {
-	if (llfinite(x) && llfinite(y) && llfinite(z))
-	{
-		LLXform::setPosition(x, y, z);
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setPosition(x,y,z) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
-	}
+    if (llfinite(x) && llfinite(y) && llfinite(z))
+    {
+        LLXform::setPosition(x, y, z);
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setPosition(x,y,z) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
+    }
 }
 
 // Special case for setPosition.  If not check-for-finite, fall through to LLXform method.
 void LLPrimitive::setPosition(const LLVector3& pos)
 {
-	if (pos.isFinite())
-	{
-		LLXform::setPosition(pos);
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setPosition(LLVector3) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
-	}
+    if (pos.isFinite())
+    {
+        LLXform::setPosition(pos);
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setPosition(LLVector3) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
+    }
 }
 
 void LLPrimitive::setAngularVelocity(const LLVector3& avel)
-{ 
-	if (avel.isFinite())
-	{
-		mAngularVelocity = avel;
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setAngularVelocity" << LL_ENDL;
-	}
+{
+    if (avel.isFinite())
+    {
+        mAngularVelocity = avel;
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setAngularVelocity" << LL_ENDL;
+    }
 }
 
-void LLPrimitive::setAngularVelocity(const F32 x, const F32 y, const F32 z)		
-{ 
-	if (llfinite(x) && llfinite(y) && llfinite(z))
-	{
-		mAngularVelocity.setVec(x,y,z);
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setAngularVelocity" << LL_ENDL;
-	}
+void LLPrimitive::setAngularVelocity(const F32 x, const F32 y, const F32 z)
+{
+    if (llfinite(x) && llfinite(y) && llfinite(z))
+    {
+        mAngularVelocity.setVec(x,y,z);
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setAngularVelocity" << LL_ENDL;
+    }
 }
 
-void LLPrimitive::setVelocity(const LLVector3& vel)			
-{ 
-	if (vel.isFinite())
-	{
-		mVelocity = vel; 
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setVelocity(LLVector3) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
-	}
+void LLPrimitive::setVelocity(const LLVector3& vel)
+{
+    if (vel.isFinite())
+    {
+        mVelocity = vel;
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setVelocity(LLVector3) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
+    }
 }
 
-void LLPrimitive::setVelocity(const F32 x, const F32 y, const F32 z)			
-{ 
-	if (llfinite(x) && llfinite(y) && llfinite(z))
-	{
-		mVelocity.setVec(x,y,z); 
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setVelocity(F32,F32,F32) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
-	}
+void LLPrimitive::setVelocity(const F32 x, const F32 y, const F32 z)
+{
+    if (llfinite(x) && llfinite(y) && llfinite(z))
+    {
+        mVelocity.setVec(x,y,z);
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setVelocity(F32,F32,F32) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
+    }
 }
 
-void LLPrimitive::setVelocityX(const F32 x)							
-{ 
-	if (llfinite(x))
-	{
-		mVelocity.mV[VX] = x;
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setVelocityX" << LL_ENDL;
-	}
+void LLPrimitive::setVelocityX(const F32 x)
+{
+    if (llfinite(x))
+    {
+        mVelocity.mV[VX] = x;
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setVelocityX" << LL_ENDL;
+    }
 }
 
-void LLPrimitive::setVelocityY(const F32 y)							
-{ 
-	if (llfinite(y))
-	{
-		mVelocity.mV[VY] = y;
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setVelocityY" << LL_ENDL;
-	}
+void LLPrimitive::setVelocityY(const F32 y)
+{
+    if (llfinite(y))
+    {
+        mVelocity.mV[VY] = y;
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setVelocityY" << LL_ENDL;
+    }
 }
 
-void LLPrimitive::setVelocityZ(const F32 z)							
-{ 
-	if (llfinite(z))
-	{
-		mVelocity.mV[VZ] = z;
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setVelocityZ" << LL_ENDL;
-	}
+void LLPrimitive::setVelocityZ(const F32 z)
+{
+    if (llfinite(z))
+    {
+        mVelocity.mV[VZ] = z;
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setVelocityZ" << LL_ENDL;
+    }
 }
 
-void LLPrimitive::addVelocity(const LLVector3& vel)			
-{ 
-	if (vel.isFinite())
-	{
-		mVelocity += vel;
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::addVelocity" << LL_ENDL;
-	}
+void LLPrimitive::addVelocity(const LLVector3& vel)
+{
+    if (vel.isFinite())
+    {
+        mVelocity += vel;
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::addVelocity" << LL_ENDL;
+    }
 }
 
-void LLPrimitive::setAcceleration(const LLVector3& accel)		
-{ 
-	if (accel.isFinite())
-	{
-		mAcceleration = accel; 
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setAcceleration(LLVector3) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
-	}
+void LLPrimitive::setAcceleration(const LLVector3& accel)
+{
+    if (accel.isFinite())
+    {
+        mAcceleration = accel;
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setAcceleration(LLVector3) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
+    }
 }
 
-void LLPrimitive::setAcceleration(const F32 x, const F32 y, const F32 z)		
-{ 
-	if (llfinite(x) && llfinite(y) && llfinite(z))
-	{
-		mAcceleration.setVec(x,y,z); 
-	}
-	else
-	{
-		LL_ERRS() << "Non Finite in LLPrimitive::setAcceleration(F32,F32,F32) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
-	}
+void LLPrimitive::setAcceleration(const F32 x, const F32 y, const F32 z)
+{
+    if (llfinite(x) && llfinite(y) && llfinite(z))
+    {
+        mAcceleration.setVec(x,y,z);
+    }
+    else
+    {
+        LL_ERRS() << "Non Finite in LLPrimitive::setAcceleration(F32,F32,F32) for " << pCodeToString(mPrimitiveCode) << LL_ENDL;
+    }
 }
 #endif // CHECK_FOR_FINITE
 
 inline BOOL LLPrimitive::validTE(const U8 te_num) const
 {
-	return (mNumTEs && te_num < mNumTEs);
+    return (mNumTEs && te_num < mNumTEs);
 }
 
 #endif
diff --git a/indra/llprimitive/lltextureentry.cpp b/indra/llprimitive/lltextureentry.cpp
index 4a20dea0d280c723f59dc06d7d1a15f608102785..6e3f93038688c6ab3e606925badeb2a3f994baaa 100644
--- a/indra/llprimitive/lltextureentry.cpp
+++ b/indra/llprimitive/lltextureentry.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lltextureentry.cpp
  * @brief LLTextureEntry base class
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -52,10 +52,10 @@ const LLTextureEntry LLTextureEntry::null;
 
 static const std::string MEDIA_VERSION_STRING_PREFIX = "x-mv:";
 
-// static 
+// static
 LLTextureEntry* LLTextureEntry::newTextureEntry()
 {
-	return new LLTextureEntry();
+    return new LLTextureEntry();
 }
 
 //===============================================================
@@ -64,7 +64,7 @@ LLTextureEntry::LLTextureEntry()
   , mSelected(false)
   , mMaterialUpdatePending(false)
 {
-	init(LLUUID::null,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
+    init(LLUUID::null,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
 }
 
 LLTextureEntry::LLTextureEntry(const LLUUID& tex_id)
@@ -72,7 +72,7 @@ LLTextureEntry::LLTextureEntry(const LLUUID& tex_id)
   , mSelected(false)
   , mMaterialUpdatePending(false)
 {
-	init(tex_id,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
+    init(tex_id,1.f,1.f,0.f,0.f,0.f,DEFAULT_BUMP_CODE);
 }
 
 LLTextureEntry::LLTextureEntry(const LLTextureEntry &rhs)
@@ -85,30 +85,30 @@ LLTextureEntry::LLTextureEntry(const LLTextureEntry &rhs)
 
 LLTextureEntry &LLTextureEntry::operator=(const LLTextureEntry &rhs)
 {
-	if (this != &rhs)
-	{
-		mID = rhs.mID;
-		mScaleS = rhs.mScaleS;
-		mScaleT = rhs.mScaleT;
-		mOffsetS = rhs.mOffsetS;
-		mOffsetT = rhs.mOffsetT;
-		mRotation = rhs.mRotation;
-		mColor = rhs.mColor;
-		mBump = rhs.mBump;
-		mMediaFlags = rhs.mMediaFlags;
-		mGlow = rhs.mGlow;
-		mMaterialID = rhs.mMaterialID;
-		mMaterial = rhs.mMaterial;
-		if (mMediaEntry != NULL) {
-			delete mMediaEntry;
-		}
-		if (rhs.mMediaEntry != NULL) {
-			// Make a copy
-			mMediaEntry = new LLMediaEntry(*rhs.mMediaEntry);
-		}
-		else {
-			mMediaEntry = NULL;
-		}
+    if (this != &rhs)
+    {
+        mID = rhs.mID;
+        mScaleS = rhs.mScaleS;
+        mScaleT = rhs.mScaleT;
+        mOffsetS = rhs.mOffsetS;
+        mOffsetT = rhs.mOffsetT;
+        mRotation = rhs.mRotation;
+        mColor = rhs.mColor;
+        mBump = rhs.mBump;
+        mMediaFlags = rhs.mMediaFlags;
+        mGlow = rhs.mGlow;
+        mMaterialID = rhs.mMaterialID;
+        mMaterial = rhs.mMaterial;
+        if (mMediaEntry != NULL) {
+            delete mMediaEntry;
+        }
+        if (rhs.mMediaEntry != NULL) {
+            // Make a copy
+            mMediaEntry = new LLMediaEntry(*rhs.mMediaEntry);
+        }
+        else {
+            mMediaEntry = NULL;
+        }
 
         mMaterialID = rhs.mMaterialID;
 
@@ -121,7 +121,7 @@ LLTextureEntry &LLTextureEntry::operator=(const LLTextureEntry &rhs)
         {
             mGLTFMaterial->addTextureEntry(this);
         }
-        
+
         if (rhs.mGLTFMaterialOverrides.notNull())
         {
             mGLTFMaterialOverrides = new LLGLTFMaterial(*rhs.mGLTFMaterialOverrides);
@@ -130,39 +130,39 @@ LLTextureEntry &LLTextureEntry::operator=(const LLTextureEntry &rhs)
         {
             mGLTFMaterialOverrides = nullptr;
         }
-	}
+    }
 
-	return *this;
+    return *this;
 }
 
 void LLTextureEntry::init(const LLUUID& tex_id, F32 scale_s, F32 scale_t, F32 offset_s, F32 offset_t, F32 rotation, U8 bump)
 {
-	setID(tex_id);
+    setID(tex_id);
 
-	mScaleS = scale_s;
-	mScaleT = scale_t;
-	mOffsetS = offset_s;
-	mOffsetT = offset_t;
-	mRotation = rotation;
-	mBump = bump;
-	mMediaFlags = 0x0;
+    mScaleS = scale_s;
+    mScaleT = scale_t;
+    mOffsetS = offset_s;
+    mOffsetT = offset_t;
+    mRotation = rotation;
+    mBump = bump;
+    mMediaFlags = 0x0;
     mGlow = 0;
-	mMaterialID.clear();
-	
-	setColor(LLColor4(1.f, 1.f, 1.f, 1.f));
-	if (mMediaEntry != NULL) {
-	    delete mMediaEntry;
-	}
-	mMediaEntry = NULL;
+    mMaterialID.clear();
+
+    setColor(LLColor4(1.f, 1.f, 1.f, 1.f));
+    if (mMediaEntry != NULL) {
+        delete mMediaEntry;
+    }
+    mMediaEntry = NULL;
 }
 
 LLTextureEntry::~LLTextureEntry()
 {
-	if(mMediaEntry)
-	{
-		delete mMediaEntry;
-		mMediaEntry = NULL;
-	}
+    if(mMediaEntry)
+    {
+        delete mMediaEntry;
+        mMediaEntry = NULL;
+    }
 
     if (mGLTFMaterial)
     {
@@ -173,64 +173,64 @@ LLTextureEntry::~LLTextureEntry()
 
 bool LLTextureEntry::operator!=(const LLTextureEntry &rhs) const
 {
-	if (mID != rhs.mID) return(true);
-	if (mScaleS != rhs.mScaleS) return(true);
-	if (mScaleT != rhs.mScaleT) return(true);
-	if (mOffsetS != rhs.mOffsetS) return(true);
-	if (mOffsetT != rhs.mOffsetT) return(true);
-	if (mRotation != rhs.mRotation) return(true);
-	if (mColor != rhs.mColor) return (true);
-	if (mBump != rhs.mBump) return (true);
-	if (mMediaFlags != rhs.mMediaFlags) return (true);
-	if (mGlow != rhs.mGlow) return (true);
-	if (mMaterialID != rhs.mMaterialID) return (true);
-	return(false);
+    if (mID != rhs.mID) return(true);
+    if (mScaleS != rhs.mScaleS) return(true);
+    if (mScaleT != rhs.mScaleT) return(true);
+    if (mOffsetS != rhs.mOffsetS) return(true);
+    if (mOffsetT != rhs.mOffsetT) return(true);
+    if (mRotation != rhs.mRotation) return(true);
+    if (mColor != rhs.mColor) return (true);
+    if (mBump != rhs.mBump) return (true);
+    if (mMediaFlags != rhs.mMediaFlags) return (true);
+    if (mGlow != rhs.mGlow) return (true);
+    if (mMaterialID != rhs.mMaterialID) return (true);
+    return(false);
 }
 
 bool LLTextureEntry::operator==(const LLTextureEntry &rhs) const
 {
-	if (mID != rhs.mID) return(false);
-	if (mScaleS != rhs.mScaleS) return(false);
-	if (mScaleT != rhs.mScaleT) return(false);
-	if (mOffsetS != rhs.mOffsetS) return(false);
-	if (mOffsetT != rhs.mOffsetT) return(false);
-	if (mRotation != rhs.mRotation) return(false);
-	if (mColor != rhs.mColor) return (false);
-	if (mBump != rhs.mBump) return (false);
-	if (mMediaFlags != rhs.mMediaFlags) return false;
-	if (mGlow != rhs.mGlow) return false;
-	if (mMaterialID != rhs.mMaterialID) return (false);
-	return(true);
+    if (mID != rhs.mID) return(false);
+    if (mScaleS != rhs.mScaleS) return(false);
+    if (mScaleT != rhs.mScaleT) return(false);
+    if (mOffsetS != rhs.mOffsetS) return(false);
+    if (mOffsetT != rhs.mOffsetT) return(false);
+    if (mRotation != rhs.mRotation) return(false);
+    if (mColor != rhs.mColor) return (false);
+    if (mBump != rhs.mBump) return (false);
+    if (mMediaFlags != rhs.mMediaFlags) return false;
+    if (mGlow != rhs.mGlow) return false;
+    if (mMaterialID != rhs.mMaterialID) return (false);
+    return(true);
 }
 
 LLSD LLTextureEntry::asLLSD() const
 {
-	LLSD sd;
-	asLLSD(sd);
-	return sd;
+    LLSD sd;
+    asLLSD(sd);
+    return sd;
 }
 
 void LLTextureEntry::asLLSD(LLSD& sd) const
 {
     LL_PROFILE_ZONE_SCOPED;
-	sd["imageid"] = mID;
-	sd["colors"] = ll_sd_from_color4(mColor);
-	sd["scales"] = mScaleS;
-	sd["scalet"] = mScaleT;
-	sd["offsets"] = mOffsetS;
-	sd["offsett"] = mOffsetT;
-	sd["imagerot"] = mRotation;
-	sd["bump"] = getBumpShiny();
-	sd["fullbright"] = getFullbright();
-	sd["media_flags"] = mMediaFlags;
-	if (hasMedia()) {
-		LLSD mediaData;
+    sd["imageid"] = mID;
+    sd["colors"] = ll_sd_from_color4(mColor);
+    sd["scales"] = mScaleS;
+    sd["scalet"] = mScaleT;
+    sd["offsets"] = mOffsetS;
+    sd["offsett"] = mOffsetT;
+    sd["imagerot"] = mRotation;
+    sd["bump"] = getBumpShiny();
+    sd["fullbright"] = getFullbright();
+    sd["media_flags"] = mMediaFlags;
+    if (hasMedia()) {
+        LLSD mediaData;
         if (NULL != getMediaData()) {
             getMediaData()->asLLSD(mediaData);
         }
-		sd[TEXTURE_MEDIA_DATA_KEY] = mediaData;
-	}
-	sd["glow"] = mGlow;
+        sd[TEXTURE_MEDIA_DATA_KEY] = mediaData;
+    }
+    sd["glow"] = mGlow;
 
     if (mGLTFMaterialOverrides.notNull())
     {
@@ -241,65 +241,65 @@ void LLTextureEntry::asLLSD(LLSD& sd) const
 bool LLTextureEntry::fromLLSD(const LLSD& sd)
 {
     LL_PROFILE_ZONE_SCOPED;
-	const char *w, *x;
-	w = "imageid";
-	if (sd.has(w))
-	{
-		setID( sd[w] );
-	} else goto fail;
-	w = "colors";
-	if (sd.has(w))
-	{
-		setColor( ll_color4_from_sd(sd["colors"]) );
-	} else goto fail;
-	w = "scales";
-	x = "scalet";
-	if (sd.has(w) && sd.has(x))
-	{
-		setScale( (F32)sd[w].asReal(), (F32)sd[x].asReal() );
-	} else goto fail;
-	w = "offsets";
-	x = "offsett";
-	if (sd.has(w) && sd.has(x))
-	{
-		setOffset( (F32)sd[w].asReal(), (F32)sd[x].asReal() );
-	} else goto fail;
-	w = "imagerot";
-	if (sd.has(w))
-	{
-		setRotation( (F32)sd[w].asReal() );
-	} else goto fail;
-	w = "bump";
-	if (sd.has(w))
-	{
-		setBumpShiny( sd[w].asInteger() );
-	} else goto fail;
-	w = "fullbright";
-	if (sd.has(w))
-	{
-		setFullbright( sd[w].asInteger() );
-	} else goto fail;
-	w = "media_flags";
-	if (sd.has(w))
-	{
-		setMediaTexGen( sd[w].asInteger() );
-	} else goto fail;
-	// If the "has media" flag doesn't match the fact that 
-	// media data exists, updateMediaData will "fix" it
-	// by either clearing or setting the flag
-	w = TEXTURE_MEDIA_DATA_KEY;
-	if (hasMedia() != sd.has(w))
-	{
-		LL_WARNS() << "LLTextureEntry::fromLLSD: media_flags (" << hasMedia() <<
-			") does not match presence of media_data (" << sd.has(w) << ").  Fixing." << LL_ENDL;
-	}
-	updateMediaData(sd[w]);
-
-	w = "glow";
-	if (sd.has(w))
-	{
-		setGlow((F32)sd[w].asReal() );
-	}
+    const char *w, *x;
+    w = "imageid";
+    if (sd.has(w))
+    {
+        setID( sd[w] );
+    } else goto fail;
+    w = "colors";
+    if (sd.has(w))
+    {
+        setColor( ll_color4_from_sd(sd["colors"]) );
+    } else goto fail;
+    w = "scales";
+    x = "scalet";
+    if (sd.has(w) && sd.has(x))
+    {
+        setScale( (F32)sd[w].asReal(), (F32)sd[x].asReal() );
+    } else goto fail;
+    w = "offsets";
+    x = "offsett";
+    if (sd.has(w) && sd.has(x))
+    {
+        setOffset( (F32)sd[w].asReal(), (F32)sd[x].asReal() );
+    } else goto fail;
+    w = "imagerot";
+    if (sd.has(w))
+    {
+        setRotation( (F32)sd[w].asReal() );
+    } else goto fail;
+    w = "bump";
+    if (sd.has(w))
+    {
+        setBumpShiny( sd[w].asInteger() );
+    } else goto fail;
+    w = "fullbright";
+    if (sd.has(w))
+    {
+        setFullbright( sd[w].asInteger() );
+    } else goto fail;
+    w = "media_flags";
+    if (sd.has(w))
+    {
+        setMediaTexGen( sd[w].asInteger() );
+    } else goto fail;
+    // If the "has media" flag doesn't match the fact that
+    // media data exists, updateMediaData will "fix" it
+    // by either clearing or setting the flag
+    w = TEXTURE_MEDIA_DATA_KEY;
+    if (hasMedia() != sd.has(w))
+    {
+        LL_WARNS() << "LLTextureEntry::fromLLSD: media_flags (" << hasMedia() <<
+            ") does not match presence of media_data (" << sd.has(w) << ").  Fixing." << LL_ENDL;
+    }
+    updateMediaData(sd[w]);
+
+    w = "glow";
+    if (sd.has(w))
+    {
+        setGlow((F32)sd[w].asReal() );
+    }
 
     w = "gltf_override";
     if (sd.has(w))
@@ -319,217 +319,217 @@ bool LLTextureEntry::fromLLSD(const LLSD& sd)
         }
     }
 
-	return true;
+    return true;
 fail:
-	return false;
+    return false;
 }
 
-// virtual 
+// virtual
 // override this method for each derived class
 LLTextureEntry* LLTextureEntry::newBlank() const
 {
-	return new LLTextureEntry();
+    return new LLTextureEntry();
 }
 
-// virtual 
+// virtual
 LLTextureEntry* LLTextureEntry::newCopy() const
 {
-	return new LLTextureEntry(*this);
+    return new LLTextureEntry(*this);
 }
 
 S32 LLTextureEntry::setID(const LLUUID &tex_id)
 {
-	if (mID != tex_id)
-	{
-		mID = tex_id;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+    if (mID != tex_id)
+    {
+        mID = tex_id;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setScale(F32 s, F32 t)
 {
-	S32 retval = 0;
+    S32 retval = 0;
 
-	if (  (mScaleS != s)
-		||(mScaleT != t))
-	{
-		mScaleS = s;
-		mScaleT = t;
+    if (  (mScaleS != s)
+        ||(mScaleT != t))
+    {
+        mScaleS = s;
+        mScaleT = t;
 
-		retval = TEM_CHANGE_TEXTURE;
-	}
-	return retval;
+        retval = TEM_CHANGE_TEXTURE;
+    }
+    return retval;
 }
 
 S32 LLTextureEntry::setScaleS(F32 s)
 {
-	S32 retval = TEM_CHANGE_NONE;
-	if (mScaleS != s)
-	{
-		mScaleS = s;
-		retval = TEM_CHANGE_TEXTURE;
-	}
-	return retval;
+    S32 retval = TEM_CHANGE_NONE;
+    if (mScaleS != s)
+    {
+        mScaleS = s;
+        retval = TEM_CHANGE_TEXTURE;
+    }
+    return retval;
 }
 
 S32 LLTextureEntry::setScaleT(F32 t)
 {
-	S32 retval = TEM_CHANGE_NONE;
-	if (mScaleT != t)
-	{
-		mScaleT = t;
-		retval = TEM_CHANGE_TEXTURE;
-	}
-	return retval;
+    S32 retval = TEM_CHANGE_NONE;
+    if (mScaleT != t)
+    {
+        mScaleT = t;
+        retval = TEM_CHANGE_TEXTURE;
+    }
+    return retval;
 }
 
 S32 LLTextureEntry::setColor(const LLColor4 &color)
 {
-	if (mColor != color)
-	{
-		mColor = color;
-		return TEM_CHANGE_COLOR;
-	}
-	return TEM_CHANGE_NONE;
+    if (mColor != color)
+    {
+        mColor = color;
+        return TEM_CHANGE_COLOR;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setColor(const LLColor3 &color)
 {
-	if (mColor != color)
-	{
-		// This preserves alpha.
-		mColor.setVec(color);
-		return TEM_CHANGE_COLOR;
-	}
-	return TEM_CHANGE_NONE;
+    if (mColor != color)
+    {
+        // This preserves alpha.
+        mColor.setVec(color);
+        return TEM_CHANGE_COLOR;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setAlpha(const F32 alpha)
 {
-	if (mColor.mV[VW] != alpha)
-	{
-		mColor.mV[VW] = alpha;
-		return TEM_CHANGE_COLOR;
-	}
-	return TEM_CHANGE_NONE;
+    if (mColor.mV[VW] != alpha)
+    {
+        mColor.mV[VW] = alpha;
+        return TEM_CHANGE_COLOR;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setOffset(F32 s, F32 t)
 {
-	S32 retval = 0;
+    S32 retval = 0;
 
-	if (  (mOffsetS != s)
-		||(mOffsetT != t))
-	{
-		mOffsetS = s;
-		mOffsetT = t;
+    if (  (mOffsetS != s)
+        ||(mOffsetT != t))
+    {
+        mOffsetS = s;
+        mOffsetT = t;
 
-		retval = TEM_CHANGE_TEXTURE;
-	}
-	return retval;
+        retval = TEM_CHANGE_TEXTURE;
+    }
+    return retval;
 }
 
 S32 LLTextureEntry::setOffsetS(F32 s)
 {
-	S32 retval = 0;
-	if (mOffsetS != s)
-	{
-		mOffsetS = s;
-		retval = TEM_CHANGE_TEXTURE;
-	}
-	return retval;
+    S32 retval = 0;
+    if (mOffsetS != s)
+    {
+        mOffsetS = s;
+        retval = TEM_CHANGE_TEXTURE;
+    }
+    return retval;
 }
 
 S32 LLTextureEntry::setOffsetT(F32 t)
 {
-	S32 retval = 0;
-	if (mOffsetT != t)
-	{
-		mOffsetT = t;
-		retval = TEM_CHANGE_TEXTURE;
-	}
-	return retval;
+    S32 retval = 0;
+    if (mOffsetT != t)
+    {
+        mOffsetT = t;
+        retval = TEM_CHANGE_TEXTURE;
+    }
+    return retval;
 }
 
 S32 LLTextureEntry::setRotation(F32 theta)
 {
-	if (mRotation != theta && llfinite(theta))
-	{
-		mRotation = theta;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+    if (mRotation != theta && llfinite(theta))
+    {
+        mRotation = theta;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setBumpShinyFullbright(U8 bump)
 {
-	if (mBump != bump)
-	{
-		mBump = bump;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+    if (mBump != bump)
+    {
+        mBump = bump;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setMediaTexGen(U8 media)
 {
-	S32 result = TEM_CHANGE_NONE;
-	result |= setTexGen(media & TEM_TEX_GEN_MASK);
-	result |= setMediaFlags(media & TEM_MEDIA_MASK);
-	return result;
+    S32 result = TEM_CHANGE_NONE;
+    result |= setTexGen(media & TEM_TEX_GEN_MASK);
+    result |= setMediaFlags(media & TEM_MEDIA_MASK);
+    return result;
 }
 
 S32 LLTextureEntry::setBumpmap(U8 bump)
 {
-	bump &= TEM_BUMP_MASK;
-	if (getBumpmap() != bump)
-	{
-		mBump &= ~TEM_BUMP_MASK;
-		mBump |= bump;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+    bump &= TEM_BUMP_MASK;
+    if (getBumpmap() != bump)
+    {
+        mBump &= ~TEM_BUMP_MASK;
+        mBump |= bump;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setFullbright(U8 fullbright)
 {
-	fullbright &= TEM_FULLBRIGHT_MASK;
-	if (getFullbright() != fullbright)
-	{
-		mBump &= ~(TEM_FULLBRIGHT_MASK<<TEM_FULLBRIGHT_SHIFT);
-		mBump |= fullbright << TEM_FULLBRIGHT_SHIFT;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+    fullbright &= TEM_FULLBRIGHT_MASK;
+    if (getFullbright() != fullbright)
+    {
+        mBump &= ~(TEM_FULLBRIGHT_MASK<<TEM_FULLBRIGHT_SHIFT);
+        mBump |= fullbright << TEM_FULLBRIGHT_SHIFT;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setShiny(U8 shiny)
 {
-	shiny &= TEM_SHINY_MASK;
-	if (getShiny() != shiny)
-	{
-		mBump &= ~(TEM_SHINY_MASK<<TEM_SHINY_SHIFT);
-		mBump |= shiny << TEM_SHINY_SHIFT;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+    shiny &= TEM_SHINY_MASK;
+    if (getShiny() != shiny)
+    {
+        mBump &= ~(TEM_SHINY_MASK<<TEM_SHINY_SHIFT);
+        mBump |= shiny << TEM_SHINY_SHIFT;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setBumpShiny(U8 bump_shiny)
 {
-	bump_shiny &= TEM_BUMP_SHINY_MASK;
-	if (getBumpShiny() != bump_shiny)
-	{
-		mBump &= ~TEM_BUMP_SHINY_MASK;
-		mBump |= bump_shiny;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+    bump_shiny &= TEM_BUMP_SHINY_MASK;
+    if (getBumpShiny() != bump_shiny)
+    {
+        mBump &= ~TEM_BUMP_SHINY_MASK;
+        mBump |= bump_shiny;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 void LLTextureEntry::setGLTFMaterial(LLGLTFMaterial* material, bool local_origin)
-{ 
+{
     if (material != getGLTFMaterial())
     {
         // assert on precondtion:
@@ -560,7 +560,7 @@ void LLTextureEntry::setGLTFMaterial(LLGLTFMaterial* material, bool local_origin
 }
 
 S32 LLTextureEntry::setGLTFMaterialOverride(LLGLTFMaterial* mat)
-{ 
+{
     llassert(mat == nullptr || getGLTFMaterial() != nullptr); // if override is not null, base material must not be null
     if (mat == mGLTFMaterialOverrides.get())
     {
@@ -594,12 +594,12 @@ S32 LLTextureEntry::setBaseMaterial()
 }
 
 LLGLTFMaterial* LLTextureEntry::getGLTFRenderMaterial() const
-{ 
+{
     if (mGLTFRenderMaterial.notNull())
     {
         return mGLTFRenderMaterial;
     }
-    
+
     llassert(getGLTFMaterialOverride() == nullptr || getGLTFMaterialOverride()->isClearedForBaseMaterial());
     return getGLTFMaterial();
 }
@@ -616,77 +616,77 @@ S32 LLTextureEntry::setGLTFRenderMaterial(LLGLTFMaterial* mat)
 
 S32 LLTextureEntry::setMediaFlags(U8 media_flags)
 {
-	media_flags &= TEM_MEDIA_MASK;
-	if (getMediaFlags() != media_flags)
-	{
-		mMediaFlags &= ~TEM_MEDIA_MASK;
-		mMediaFlags |= media_flags;
-        
-		// Special code for media handling
-		if( hasMedia() && mMediaEntry == NULL)
-		{
-			mMediaEntry = new LLMediaEntry;
-		}
+    media_flags &= TEM_MEDIA_MASK;
+    if (getMediaFlags() != media_flags)
+    {
+        mMediaFlags &= ~TEM_MEDIA_MASK;
+        mMediaFlags |= media_flags;
+
+        // Special code for media handling
+        if( hasMedia() && mMediaEntry == NULL)
+        {
+            mMediaEntry = new LLMediaEntry;
+        }
         else if ( ! hasMedia() && mMediaEntry != NULL)
         {
             delete mMediaEntry;
             mMediaEntry = NULL;
         }
-        
-		return TEM_CHANGE_MEDIA;
-	}
-	return TEM_CHANGE_NONE;
+
+        return TEM_CHANGE_MEDIA;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setTexGen(U8 tex_gen)
 {
-	tex_gen &= TEM_TEX_GEN_MASK;
-	if (getTexGen() != tex_gen)
-	{
-		mMediaFlags &= ~TEM_TEX_GEN_MASK;
-		mMediaFlags |= tex_gen;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+    tex_gen &= TEM_TEX_GEN_MASK;
+    if (getTexGen() != tex_gen)
+    {
+        mMediaFlags &= ~TEM_TEX_GEN_MASK;
+        mMediaFlags |= tex_gen;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setGlow(F32 glow)
 {
-	if (mGlow != glow)
-	{
-		mGlow = glow;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+    if (mGlow != glow)
+    {
+        mGlow = glow;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setMaterialID(const LLMaterialID& pMaterialID)
 {
-	if ( (mMaterialID != pMaterialID) || (mMaterialUpdatePending && !mSelected) )
-	{
-		if (mSelected)
-		{
-			mMaterialUpdatePending = true;
-			mMaterialID = pMaterialID;
-			return TEM_CHANGE_TEXTURE;
-		}
+    if ( (mMaterialID != pMaterialID) || (mMaterialUpdatePending && !mSelected) )
+    {
+        if (mSelected)
+        {
+            mMaterialUpdatePending = true;
+            mMaterialID = pMaterialID;
+            return TEM_CHANGE_TEXTURE;
+        }
 
-		mMaterialUpdatePending = false;
-		mMaterialID = pMaterialID;
-		return TEM_CHANGE_TEXTURE;
-	}
-	return TEM_CHANGE_NONE;
+        mMaterialUpdatePending = false;
+        mMaterialID = pMaterialID;
+        return TEM_CHANGE_TEXTURE;
+    }
+    return TEM_CHANGE_NONE;
 }
 
 S32 LLTextureEntry::setMaterialParams(const LLMaterialPtr pMaterialParams)
 {
-	if (mSelected)
-	{
-		mMaterialUpdatePending = true;
-	}
-	mMaterial = pMaterialParams;
-    
-	return TEM_CHANGE_TEXTURE;
+    if (mSelected)
+    {
+        mMaterialUpdatePending = true;
+    }
+    mMaterial = pMaterialParams;
+
+    return TEM_CHANGE_TEXTURE;
 }
 
 void LLTextureEntry::setMediaData(const LLMediaEntry &media_entry)
@@ -701,23 +701,23 @@ void LLTextureEntry::setMediaData(const LLMediaEntry &media_entry)
 
 bool LLTextureEntry::updateMediaData(const LLSD& media_data)
 {
-	if (media_data.isUndefined())
-	{
-		// clear the media data
+    if (media_data.isUndefined())
+    {
+        // clear the media data
         clearMediaData();
-		return false;
-	}
-	else {
-		mMediaFlags |= MF_HAS_MEDIA;
-		if (mMediaEntry == NULL)
-		{
-			mMediaEntry = new LLMediaEntry;
-		}
-        // *NOTE: this will *clobber* all of the fields in mMediaEntry 
+        return false;
+    }
+    else {
+        mMediaFlags |= MF_HAS_MEDIA;
+        if (mMediaEntry == NULL)
+        {
+            mMediaEntry = new LLMediaEntry;
+        }
+        // *NOTE: this will *clobber* all of the fields in mMediaEntry
         // with whatever fields are present (or not present) in media_data!
- 		mMediaEntry->fromLLSD(media_data);
-		return true;
-	}
+        mMediaEntry->fromLLSD(media_data);
+        return true;
+    }
 }
 
 void LLTextureEntry::clearMediaData()
@@ -727,7 +727,7 @@ void LLTextureEntry::clearMediaData()
         delete mMediaEntry;
     }
     mMediaEntry = NULL;
-}    
+}
 
 void LLTextureEntry::mergeIntoMediaData(const LLSD& media_fields)
 {
@@ -760,10 +760,10 @@ std::string LLTextureEntry::touchMediaVersionString(const std::string &in_versio
 U32 LLTextureEntry::getVersionFromMediaVersionString(const std::string &version_string)
 {
     U32 version = 0;
-    if (!version_string.empty()) 
+    if (!version_string.empty())
     {
         size_t found = version_string.find(MEDIA_VERSION_STRING_PREFIX);
-        if (found != std::string::npos) 
+        if (found != std::string::npos)
         {
             found = version_string.find_first_of("/", found);
             std::string v = version_string.substr(MEDIA_VERSION_STRING_PREFIX.length(), found);
@@ -777,13 +777,13 @@ U32 LLTextureEntry::getVersionFromMediaVersionString(const std::string &version_
 LLUUID LLTextureEntry::getAgentIDFromMediaVersionString(const std::string &version_string)
 {
     LLUUID id;
-    if (!version_string.empty()) 
+    if (!version_string.empty())
     {
         size_t found = version_string.find(MEDIA_VERSION_STRING_PREFIX);
-        if (found != std::string::npos) 
+        if (found != std::string::npos)
         {
             found = version_string.find_first_of("/", found);
-            if (found != std::string::npos) 
+            if (found != std::string::npos)
             {
                 std::string v = version_string.substr(found + 1);
                 id.set(v);
@@ -796,5 +796,5 @@ LLUUID LLTextureEntry::getAgentIDFromMediaVersionString(const std::string &versi
 //static
 bool LLTextureEntry::isMediaVersionString(const std::string &version_string)
 {
-	return std::string::npos != version_string.find(MEDIA_VERSION_STRING_PREFIX);
+    return std::string::npos != version_string.find(MEDIA_VERSION_STRING_PREFIX);
 }
diff --git a/indra/llrender/llglslshader.cpp b/indra/llrender/llglslshader.cpp
index 8bfd8f488087ba038db903cb6af049572c8fd75c..756b63ce39cf2da0bf0d49e9782359f9ab25d556 100644
--- a/indra/llrender/llglslshader.cpp
+++ b/indra/llrender/llglslshader.cpp
@@ -419,27 +419,27 @@ BOOL LLGLSLShader::createShader(std::vector<LLStaticHashedString>* attributes,
 
     mUsingBinaryProgram =  LLShaderMgr::instance()->loadCachedProgramBinary(this);
 
-	if (!mUsingBinaryProgram)
-	{
+    if (!mUsingBinaryProgram)
+    {
 #if DEBUG_SHADER_INCLUDES
-	    fprintf(stderr, "--- %s ---\n", mName.c_str());
+        fprintf(stderr, "--- %s ---\n", mName.c_str());
 #endif // DEBUG_SHADER_INCLUDES
 
         //compile new source
-		vector< pair<string, GLenum> >::iterator fileIter = mShaderFiles.begin();
-		for (; fileIter != mShaderFiles.end(); fileIter++)
-		{
-			GLuint shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels);
-			LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL;
-			if (shaderhandle)
-			{
-				attachObject(shaderhandle);
-			}
-			else
-			{
-				success = FALSE;
-			}
-		}
+        vector< pair<string, GLenum> >::iterator fileIter = mShaderFiles.begin();
+        for (; fileIter != mShaderFiles.end(); fileIter++)
+        {
+            GLuint shaderhandle = LLShaderMgr::instance()->loadShaderFile((*fileIter).first, mShaderLevel, (*fileIter).second, &mDefines, mFeatures.mIndexedTextureChannels);
+            LL_DEBUGS("ShaderLoading") << "SHADER FILE: " << (*fileIter).first << " mShaderLevel=" << mShaderLevel << LL_ENDL;
+            if (shaderhandle)
+            {
+                attachObject(shaderhandle);
+            }
+            else
+            {
+                success = FALSE;
+            }
+        }
     }
 
     // Attach existing objects
@@ -605,19 +605,19 @@ BOOL LLGLSLShader::mapAttributes(const std::vector<LLStaticHashedString>* attrib
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER;
 
-	BOOL res = TRUE;
-	if (!mUsingBinaryProgram)
-	{
-		//before linking, make sure reserved attributes always have consistent locations
-		for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++)
-		{
-			const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str();
-			glBindAttribLocation(mProgramObject, i, (const GLchar*)name);
-		}
+    BOOL res = TRUE;
+    if (!mUsingBinaryProgram)
+    {
+        //before linking, make sure reserved attributes always have consistent locations
+        for (U32 i = 0; i < LLShaderMgr::instance()->mReservedAttribs.size(); i++)
+        {
+            const char* name = LLShaderMgr::instance()->mReservedAttribs[i].c_str();
+            glBindAttribLocation(mProgramObject, i, (const GLchar*)name);
+        }
 
-		//link the program
-		res = link();
-	}
+        //link the program
+        res = link();
+    }
 
     mAttribute.clear();
     U32 numAttributes = (attributes == NULL) ? 0 : attributes->size();
@@ -1182,14 +1182,14 @@ S32 LLGLSLShader::getTextureChannel(S32 uniform) const
 S32 LLGLSLShader::enableTexture(S32 uniform, LLTexUnit::eTextureType mode)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER;
-    
+
     if (uniform < 0 || uniform >= (S32)mTexture.size())
     {
         LL_SHADER_UNIFORM_ERRS() << "Uniform out of range: " << uniform << LL_ENDL;
         return -1;
     }
 
-    
+
     S32 index = mTexture[uniform];
     if (index != -1)
     {
diff --git a/indra/llrender/llglslshader.h b/indra/llrender/llglslshader.h
index 6905d9caff010274c5d080fc4d8ff4b5ecd16cbe..e1ff18852d31a07f274990c9f3abeba2fa9a7911 100644
--- a/indra/llrender/llglslshader.h
+++ b/indra/llrender/llglslshader.h
@@ -230,14 +230,14 @@ class LLGLSLShader
     GLint mapUniformTextureChannel(GLint location, GLenum type, GLint size);
 
     void clearPermutations();
-	void addPermutations(std::map<std::string, std::string>& map)
-	{
-		mDefines.insert(map.begin(), map.end());
-	}
+    void addPermutations(std::map<std::string, std::string>& map)
+    {
+        mDefines.insert(map.begin(), map.end());
+    }
     void addPermutation(std::string name, std::string value);
     void removePermutations(std::map<std::string, std::string>& map)
     {
-		for (const auto& entry : map)
+        for (const auto& entry : map)
         {
             mDefines.erase(entry.first);
         }
@@ -247,7 +247,7 @@ class LLGLSLShader
     void addConstant(const LLGLSLShader::eShaderConsts shader_const);
 
     //enable/disable texture channel for specified uniform
-    //if given texture uniform is active in the shader, 
+    //if given texture uniform is active in the shader,
     //the corresponding channel will be active upon return
     //returns channel texture is enabled in from [0-MAX)
     S32 enableTexture(S32 uniform, LLTexUnit::eTextureType mode = LLTexUnit::TT_TEXTURE);
@@ -269,7 +269,7 @@ class LLGLSLShader
     void bind();
     //helper to conditionally bind mRiggedVariant instead of this
     void bind(bool rigged);
-    
+
     bool isComplete() const { return mProgramObject != 0; }
 
     LLUUID hash();
@@ -343,11 +343,11 @@ class LLGLSLShader
 };
 
 //UI shader (declared here so llui_libtest will link properly)
-extern LLGLSLShader			gUIProgram;
+extern LLGLSLShader         gUIProgram;
 //output vec4(color.rgb,color.a*tex0[tc0].a)
-extern LLGLSLShader			gSolidColorProgram;
+extern LLGLSLShader         gSolidColorProgram;
 //Alpha mask shader (declared here so llappearance can access properly)
-extern LLGLSLShader			gAlphaMaskProgram;
+extern LLGLSLShader         gAlphaMaskProgram;
 
 #ifdef LL_PROFILER_ENABLE_RENDER_DOC
 #define LL_SET_SHADER_LABEL(shader) shader.setLabel(#shader)
diff --git a/indra/llrender/llgltexture.cpp b/indra/llrender/llgltexture.cpp
index b1a06f4113cc0eb10cce3485daacc73ad5c5ea36..845e970527b943b3fdeb0eea3df4ce6128e7552e 100644
--- a/indra/llrender/llgltexture.cpp
+++ b/indra/llrender/llgltexture.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llgltexture.cpp
  * @brief Opengl texture implementation
  *
  * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -29,289 +29,289 @@
 
 LLGLTexture::LLGLTexture(BOOL usemipmaps)
 {
-	init();
-	mUseMipMaps = usemipmaps;
+    init();
+    mUseMipMaps = usemipmaps;
 }
 
 LLGLTexture::LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps)
 {
-	init();
-	mFullWidth = width ;
-	mFullHeight = height ;
-	mUseMipMaps = usemipmaps;
-	mComponents = components ;
-	setTexelsPerImage();
+    init();
+    mFullWidth = width ;
+    mFullHeight = height ;
+    mUseMipMaps = usemipmaps;
+    mComponents = components ;
+    setTexelsPerImage();
 }
 
 LLGLTexture::LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps)
 {
-	init();
-	mUseMipMaps = usemipmaps ;
-	// Create an empty image of the specified size and width
-	mGLTexturep = new LLImageGL(raw, usemipmaps) ;
+    init();
+    mUseMipMaps = usemipmaps ;
+    // Create an empty image of the specified size and width
+    mGLTexturep = new LLImageGL(raw, usemipmaps) ;
 }
 
 LLGLTexture::~LLGLTexture()
 {
-	cleanup();
+    cleanup();
 }
 
 void LLGLTexture::init()
 {
-	mBoostLevel = LLGLTexture::BOOST_NONE;
+    mBoostLevel = LLGLTexture::BOOST_NONE;
 
-	mFullWidth = 0;
-	mFullHeight = 0;
-	mTexelsPerImage = 0 ;
-	mUseMipMaps = FALSE ;
-	mComponents = 0 ;
+    mFullWidth = 0;
+    mFullHeight = 0;
+    mTexelsPerImage = 0 ;
+    mUseMipMaps = FALSE ;
+    mComponents = 0 ;
 
-	mTextureState = NO_DELETE ;
-	mDontDiscard = FALSE;
-	mNeedsGLTexture = FALSE ;
+    mTextureState = NO_DELETE ;
+    mDontDiscard = FALSE;
+    mNeedsGLTexture = FALSE ;
 }
 
 void LLGLTexture::cleanup()
 {
-	if(mGLTexturep)
-	{
-		mGLTexturep->cleanup();
-	}
+    if(mGLTexturep)
+    {
+        mGLTexturep->cleanup();
+    }
 }
 
 // virtual
 void LLGLTexture::dump()
 {
-	if(mGLTexturep)
-	{
-		mGLTexturep->dump();
-	}
+    if(mGLTexturep)
+    {
+        mGLTexturep->dump();
+    }
 }
 
 void LLGLTexture::setBoostLevel(S32 level)
 {
-	if(mBoostLevel != level)
-	{
-		mBoostLevel = level ;
-		if(mBoostLevel != LLGLTexture::BOOST_NONE && 
-			mBoostLevel != LLGLTexture::BOOST_SELECTED
-		   && mBoostLevel != LLGLTexture::BOOST_ICON
+    if(mBoostLevel != level)
+    {
+        mBoostLevel = level ;
+        if(mBoostLevel != LLGLTexture::BOOST_NONE &&
+            mBoostLevel != LLGLTexture::BOOST_SELECTED
+           && mBoostLevel != LLGLTexture::BOOST_ICON
            && mBoostLevel != LLGLTexture::BOOST_THUMBNAIL
            && mBoostLevel != LLGLTexture::BOOST_TERRAIN)
-		{
-			setNoDelete() ;		
-		}
-	}
+        {
+            setNoDelete() ;
+        }
+    }
 }
 
 void LLGLTexture::forceActive()
 {
-	mTextureState = ACTIVE ; 
+    mTextureState = ACTIVE ;
 }
 
-void LLGLTexture::setActive() 
-{ 
-	if(mTextureState != NO_DELETE)
-	{
-		mTextureState = ACTIVE ; 
-	}
+void LLGLTexture::setActive()
+{
+    if(mTextureState != NO_DELETE)
+    {
+        mTextureState = ACTIVE ;
+    }
 }
 
 //set the texture to stay in memory
-void LLGLTexture::setNoDelete() 
-{ 
-	mTextureState = NO_DELETE ;
+void LLGLTexture::setNoDelete()
+{
+    mTextureState = NO_DELETE ;
 }
 
-void LLGLTexture::generateGLTexture() 
-{	
-	if(mGLTexturep.isNull())
-	{
-		mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps) ;
-	}
+void LLGLTexture::generateGLTexture()
+{
+    if(mGLTexturep.isNull())
+    {
+        mGLTexturep = new LLImageGL(mFullWidth, mFullHeight, mComponents, mUseMipMaps) ;
+    }
 }
 
 LLImageGL* LLGLTexture::getGLTexture() const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep ;
+    return mGLTexturep ;
 }
 
-BOOL LLGLTexture::createGLTexture() 
+BOOL LLGLTexture::createGLTexture()
 {
-	if(mGLTexturep.isNull())
-	{
-		generateGLTexture() ;
-	}
+    if(mGLTexturep.isNull())
+    {
+        generateGLTexture() ;
+    }
 
-	return mGLTexturep->createGLTexture() ;
+    return mGLTexturep->createGLTexture() ;
 }
 
 BOOL LLGLTexture::createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename, BOOL to_create, S32 category, bool defer_copy, LLGLuint* tex_name)
 {
-	llassert(mGLTexturep.notNull());
+    llassert(mGLTexturep.notNull());
 
-	BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category, defer_copy, tex_name) ;
+    BOOL ret = mGLTexturep->createGLTexture(discard_level, imageraw, usename, to_create, category, defer_copy, tex_name) ;
 
-	if(ret)
-	{
-		mFullWidth = mGLTexturep->getCurrentWidth() ;
-		mFullHeight = mGLTexturep->getCurrentHeight() ; 
-		mComponents = mGLTexturep->getComponents() ;	
-		setTexelsPerImage();
-	}
+    if(ret)
+    {
+        mFullWidth = mGLTexturep->getCurrentWidth() ;
+        mFullHeight = mGLTexturep->getCurrentHeight() ;
+        mComponents = mGLTexturep->getComponents() ;
+        setTexelsPerImage();
+    }
 
-	return ret ;
+    return ret ;
 }
 
 void LLGLTexture::setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format, BOOL swap_bytes)
 {
-	llassert(mGLTexturep.notNull()) ;
-	
-	mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes) ;
+    llassert(mGLTexturep.notNull()) ;
+
+    mGLTexturep->setExplicitFormat(internal_format, primary_format, type_format, swap_bytes) ;
 }
 void LLGLTexture::setAddressMode(LLTexUnit::eTextureAddressMode mode)
 {
-	llassert(mGLTexturep.notNull()) ;
-	mGLTexturep->setAddressMode(mode) ;
+    llassert(mGLTexturep.notNull()) ;
+    mGLTexturep->setAddressMode(mode) ;
 }
 void LLGLTexture::setFilteringOption(LLTexUnit::eTextureFilterOptions option)
 {
-	llassert(mGLTexturep.notNull()) ;
-	mGLTexturep->setFilteringOption(option) ;
+    llassert(mGLTexturep.notNull()) ;
+    mGLTexturep->setFilteringOption(option) ;
 }
 
 //virtual
-S32	LLGLTexture::getWidth(S32 discard_level) const
+S32 LLGLTexture::getWidth(S32 discard_level) const
 {
-	llassert(mGLTexturep.notNull()) ;
-	return mGLTexturep->getWidth(discard_level) ;
+    llassert(mGLTexturep.notNull()) ;
+    return mGLTexturep->getWidth(discard_level) ;
 }
 
 //virtual
-S32	LLGLTexture::getHeight(S32 discard_level) const
+S32 LLGLTexture::getHeight(S32 discard_level) const
 {
-	llassert(mGLTexturep.notNull()) ;
-	return mGLTexturep->getHeight(discard_level) ;
+    llassert(mGLTexturep.notNull()) ;
+    return mGLTexturep->getHeight(discard_level) ;
 }
 
 S32 LLGLTexture::getMaxDiscardLevel() const
 {
-	llassert(mGLTexturep.notNull()) ;
-	return mGLTexturep->getMaxDiscardLevel() ;
+    llassert(mGLTexturep.notNull()) ;
+    return mGLTexturep->getMaxDiscardLevel() ;
 }
 S32 LLGLTexture::getDiscardLevel() const
 {
-	llassert(mGLTexturep.notNull()) ;
-	return mGLTexturep->getDiscardLevel() ;
+    llassert(mGLTexturep.notNull()) ;
+    return mGLTexturep->getDiscardLevel() ;
 }
-S8  LLGLTexture::getComponents() const 
-{ 
-	llassert(mGLTexturep.notNull()) ;
-	
-	return mGLTexturep->getComponents() ;
+S8  LLGLTexture::getComponents() const
+{
+    llassert(mGLTexturep.notNull()) ;
+
+    return mGLTexturep->getComponents() ;
 }
 
-LLGLuint LLGLTexture::getTexName() const 
-{ 
-	llassert(mGLTexturep.notNull()) ;
+LLGLuint LLGLTexture::getTexName() const
+{
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getTexName() ; 
+    return mGLTexturep->getTexName() ;
 }
 
-BOOL LLGLTexture::hasGLTexture() const 
+BOOL LLGLTexture::hasGLTexture() const
 {
-	if(mGLTexturep.notNull())
-	{
-		return mGLTexturep->getHasGLTexture() ;
-	}
-	return FALSE ;
+    if(mGLTexturep.notNull())
+    {
+        return mGLTexturep->getHasGLTexture() ;
+    }
+    return FALSE ;
 }
 
 BOOL LLGLTexture::getBoundRecently() const
 {
-	if(mGLTexturep.notNull())
-	{
-		return mGLTexturep->getBoundRecently() ;
-	}
-	return FALSE ;
+    if(mGLTexturep.notNull())
+    {
+        return mGLTexturep->getBoundRecently() ;
+    }
+    return FALSE ;
 }
 
 LLTexUnit::eTextureType LLGLTexture::getTarget(void) const
 {
-	llassert(mGLTexturep.notNull()) ;
-	return mGLTexturep->getTarget() ;
+    llassert(mGLTexturep.notNull()) ;
+    return mGLTexturep->getTarget() ;
 }
 
 BOOL LLGLTexture::setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, LLGLuint use_name)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height, 0, use_name) ;
+    return mGLTexturep->setSubImage(imageraw, x_pos, y_pos, width, height, 0, use_name) ;
 }
 
 BOOL LLGLTexture::setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height, LLGLuint use_name)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height, 0, use_name) ;
+    return mGLTexturep->setSubImage(datap, data_width, data_height, x_pos, y_pos, width, height, 0, use_name) ;
 }
 
 void LLGLTexture::setGLTextureCreated (bool initialized)
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	mGLTexturep->setGLTextureCreated (initialized) ;
+    mGLTexturep->setGLTextureCreated (initialized) ;
 }
 
-void  LLGLTexture::setCategory(S32 category) 
+void  LLGLTexture::setCategory(S32 category)
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	mGLTexturep->setCategory(category) ;
+    mGLTexturep->setCategory(category) ;
 }
 
 void LLGLTexture::setTexName(LLGLuint texName)
 {
     llassert(mGLTexturep.notNull());
-    return mGLTexturep->setTexName(texName); 
+    return mGLTexturep->setTexName(texName);
 }
 
 void LLGLTexture::setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target)
 {
     llassert(mGLTexturep.notNull());
-    return mGLTexturep->setTarget(target, bind_target); 
+    return mGLTexturep->setTarget(target, bind_target);
 }
 
 LLTexUnit::eTextureAddressMode LLGLTexture::getAddressMode(void) const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getAddressMode() ;
+    return mGLTexturep->getAddressMode() ;
 }
 
 S64Bytes LLGLTexture::getTextureMemory() const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->mTextureMemory ;
+    return mGLTexturep->mTextureMemory ;
 }
 
 LLGLenum LLGLTexture::getPrimaryFormat() const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getPrimaryFormat() ;
+    return mGLTexturep->getPrimaryFormat() ;
 }
 
 BOOL LLGLTexture::getIsAlphaMask(const F32 max_rmse, const F32 max_mid) const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getIsAlphaMask(max_rmse, max_mid) ;
+    return mGLTexturep->getIsAlphaMask(max_rmse, max_mid) ;
 }
 
 //BOOL LLGLTexture::getMask(const LLVector2 &tc)
@@ -319,80 +319,80 @@ BOOL LLGLTexture::getIsAlphaMask(const F32 max_rmse, const F32 max_mid) const
 bool LLGLTexture::getMask(const LLVector2 &tc) const
 // [/RLVa:KB]
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getMask(tc) ;
+    return mGLTexturep->getMask(tc) ;
 }
 
 F32 LLGLTexture::getTimePassedSinceLastBound()
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getTimePassedSinceLastBound() ;
+    return mGLTexturep->getTimePassedSinceLastBound() ;
 }
-BOOL LLGLTexture::getMissed() const 
+BOOL LLGLTexture::getMissed() const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getMissed() ;
+    return mGLTexturep->getMissed() ;
 }
 
 BOOL LLGLTexture::isJustBound() const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->isJustBound() ;
+    return mGLTexturep->isJustBound() ;
 }
 
 void LLGLTexture::forceUpdateBindStats(void) const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->forceUpdateBindStats() ;
+    return mGLTexturep->forceUpdateBindStats() ;
 }
 
 U32 LLGLTexture::getTexelsInAtlas() const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getTexelsInAtlas() ;
+    return mGLTexturep->getTexelsInAtlas() ;
 }
 
 U32 LLGLTexture::getTexelsInGLTexture() const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getTexelsInGLTexture() ;
+    return mGLTexturep->getTexelsInGLTexture() ;
 }
 
 BOOL LLGLTexture::isGLTextureCreated() const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->isGLTextureCreated() ;
+    return mGLTexturep->isGLTextureCreated() ;
 }
 
 S32  LLGLTexture::getDiscardLevelInAtlas() const
 {
-	llassert(mGLTexturep.notNull()) ;
+    llassert(mGLTexturep.notNull()) ;
 
-	return mGLTexturep->getDiscardLevelInAtlas() ;
+    return mGLTexturep->getDiscardLevelInAtlas() ;
 }
 
-void LLGLTexture::destroyGLTexture() 
+void LLGLTexture::destroyGLTexture()
 {
-	if(mGLTexturep.notNull() && mGLTexturep->getHasGLTexture())
-	{
-		mGLTexturep->destroyGLTexture() ;
-		mTextureState = DELETED ;
-	}
+    if(mGLTexturep.notNull() && mGLTexturep->getHasGLTexture())
+    {
+        mGLTexturep->destroyGLTexture() ;
+        mTextureState = DELETED ;
+    }
 }
 
 void LLGLTexture::setTexelsPerImage()
 {
-	U32 fullwidth = llmin(mFullWidth,U32(MAX_IMAGE_SIZE));
-	U32 fullheight = llmin(mFullHeight,U32(MAX_IMAGE_SIZE));
-	mTexelsPerImage = (U32)fullwidth * fullheight;
+    U32 fullwidth = llmin(mFullWidth,U32(MAX_IMAGE_SIZE));
+    U32 fullheight = llmin(mFullHeight,U32(MAX_IMAGE_SIZE));
+    mTexelsPerImage = (U32)fullwidth * fullheight;
 }
 
 static LLUUID sStubUUID;
diff --git a/indra/llrender/llgltexture.h b/indra/llrender/llgltexture.h
index 975d8c84e4f240f16d06a620e9b5d86c0580a436..4a5488ebb35b7d321bece94271653aed3c49cc8c 100644
--- a/indra/llrender/llgltexture.h
+++ b/indra/llrender/llgltexture.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llgltexture.h
  * @brief Object for managing opengl textures
  *
  * $LicenseInfo:firstyear=2012&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -40,87 +40,87 @@ class LLImageRaw;
 class LLGLTexture : public LLTexture
 {
 public:
-	enum
-	{
-		MAX_IMAGE_SIZE_DEFAULT = 2048,
-		INVALID_DISCARD_LEVEL = 0x7fff
-	};
-
-	enum EBoostLevel
-	{
-		BOOST_NONE 			= 0,
-		BOOST_AVATAR		,
+    enum
+    {
+        MAX_IMAGE_SIZE_DEFAULT = 2048,
+        INVALID_DISCARD_LEVEL = 0x7fff
+    };
+
+    enum EBoostLevel
+    {
+        BOOST_NONE          = 0,
+        BOOST_AVATAR        ,
         BOOST_AVATAR_BAKED  ,
-		BOOST_SCULPTED      ,
+        BOOST_SCULPTED      ,
         BOOST_TERRAIN       , // Needed for minimap generation for now. Lower than BOOST_HIGH so the texture stats don't get forced, i.e. texture stats are manually managed by minimap/terrain instead.
-		
-		BOOST_HIGH 			= 10,
-		BOOST_BUMP          ,
+
+        BOOST_HIGH          = 10,
+        BOOST_BUMP          ,
         BOOST_UNUSED_1      , // Placeholder to avoid disrupting habits around texture debug
-		BOOST_SELECTED		,		
-		BOOST_AVATAR_BAKED_SELF	,
-		BOOST_AVATAR_SELF	, // needed for baking avatar
-		BOOST_SUPER_HIGH    , //textures higher than this need to be downloaded at the required resolution without delay.
-		BOOST_HUD			,
-		BOOST_ICON			,
-        BOOST_THUMBNAIL		,
-		BOOST_UI			,
-		BOOST_PREVIEW		,
-		BOOST_MAP			,
-		BOOST_MAP_VISIBLE	,		
-		BOOST_MAX_LEVEL,
-
-		//other texture Categories
-		LOCAL = BOOST_MAX_LEVEL,
-		AVATAR_SCRATCH_TEX,
-		DYNAMIC_TEX,
-		MEDIA,
-		ATLAS,
-		OTHER,
-		MAX_GL_IMAGE_CATEGORY
-	};
-
-	typedef enum 
-	{
-		DELETED = 0,         //removed from memory
-		DELETION_CANDIDATE,  //ready to be removed from memory
-		INACTIVE,            //not be used for the last certain period (i.e., 30 seconds).
-		ACTIVE,              //just being used, can become inactive if not being used for a certain time (10 seconds).
-		NO_DELETE = 99       //stay in memory, can not be removed.
-	} LLGLTextureState;
+        BOOST_SELECTED      ,
+        BOOST_AVATAR_BAKED_SELF ,
+        BOOST_AVATAR_SELF   , // needed for baking avatar
+        BOOST_SUPER_HIGH    , //textures higher than this need to be downloaded at the required resolution without delay.
+        BOOST_HUD           ,
+        BOOST_ICON          ,
+        BOOST_THUMBNAIL     ,
+        BOOST_UI            ,
+        BOOST_PREVIEW       ,
+        BOOST_MAP           ,
+        BOOST_MAP_VISIBLE   ,
+        BOOST_MAX_LEVEL,
+
+        //other texture Categories
+        LOCAL = BOOST_MAX_LEVEL,
+        AVATAR_SCRATCH_TEX,
+        DYNAMIC_TEX,
+        MEDIA,
+        ATLAS,
+        OTHER,
+        MAX_GL_IMAGE_CATEGORY
+    };
+
+    typedef enum
+    {
+        DELETED = 0,         //removed from memory
+        DELETION_CANDIDATE,  //ready to be removed from memory
+        INACTIVE,            //not be used for the last certain period (i.e., 30 seconds).
+        ACTIVE,              //just being used, can become inactive if not being used for a certain time (10 seconds).
+        NO_DELETE = 99       //stay in memory, can not be removed.
+    } LLGLTextureState;
 
 protected:
-	virtual ~LLGLTexture();
-	LOG_CLASS(LLGLTexture);
+    virtual ~LLGLTexture();
+    LOG_CLASS(LLGLTexture);
 
 public:
-	LLGLTexture(BOOL usemipmaps = TRUE);
-	LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
-	LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) ;
+    LLGLTexture(BOOL usemipmaps = TRUE);
+    LLGLTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
+    LLGLTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) ;
+
+    virtual void dump();    // debug info to LL_INFOS()
 
-	virtual void dump();	// debug info to LL_INFOS()
+    virtual const LLUUID& getID() const;
 
-	virtual const LLUUID& getID() const;
+    void setBoostLevel(S32 level);
+    S32  getBoostLevel() { return mBoostLevel; }
 
-	void setBoostLevel(S32 level);
-	S32  getBoostLevel() { return mBoostLevel; }
+    S32 getFullWidth() const { return mFullWidth; }
+    S32 getFullHeight() const { return mFullHeight; }
 
-	S32 getFullWidth() const { return mFullWidth; }
-	S32 getFullHeight() const { return mFullHeight; }	
+    void generateGLTexture() ;
+    void destroyGLTexture() ;
 
-	void generateGLTexture() ;
-	void destroyGLTexture() ;
+    //---------------------------------------------------------------------------------------------
+    //functions to access LLImageGL
+    //---------------------------------------------------------------------------------------------
+    /*virtual*/S32         getWidth(S32 discard_level = -1) const;
+    /*virtual*/S32         getHeight(S32 discard_level = -1) const;
 
-	//---------------------------------------------------------------------------------------------
-	//functions to access LLImageGL
-	//---------------------------------------------------------------------------------------------
-	/*virtual*/S32	       getWidth(S32 discard_level = -1) const;
-	/*virtual*/S32	       getHeight(S32 discard_level = -1) const;
+    BOOL       hasGLTexture() const ;
+    LLGLuint   getTexName() const ;
+    BOOL       createGLTexture() ;
 
-	BOOL       hasGLTexture() const ;
-	LLGLuint   getTexName() const ;		
-	BOOL       createGLTexture() ;
-	
     // Create a GL Texture from an image raw
     // discard_level - mip level, 0 for highest resultion mip
     // imageraw - the image to copy from
@@ -131,83 +131,83 @@ class LLGLTexture : public LLTexture
     // tex_name - if not null, will be set to the GL name of the texture created
     BOOL       createGLTexture(S32 discard_level, const LLImageRaw* imageraw, S32 usename = 0, BOOL to_create = TRUE, S32 category = LLGLTexture::OTHER, bool defer_copy = false, LLGLuint* tex_name = nullptr);
 
-	void       setFilteringOption(LLTexUnit::eTextureFilterOptions option);
-	void       setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE);
-	void       setAddressMode(LLTexUnit::eTextureAddressMode mode);
-	BOOL       setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, LLGLuint use_name = 0);
-	BOOL       setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height, LLGLuint use_name = 0);
-	void       setGLTextureCreated (bool initialized);
-	void       setCategory(S32 category) ;
+    void       setFilteringOption(LLTexUnit::eTextureFilterOptions option);
+    void       setExplicitFormat(LLGLint internal_format, LLGLenum primary_format, LLGLenum type_format = 0, BOOL swap_bytes = FALSE);
+    void       setAddressMode(LLTexUnit::eTextureAddressMode mode);
+    BOOL       setSubImage(const LLImageRaw* imageraw, S32 x_pos, S32 y_pos, S32 width, S32 height, LLGLuint use_name = 0);
+    BOOL       setSubImage(const U8* datap, S32 data_width, S32 data_height, S32 x_pos, S32 y_pos, S32 width, S32 height, LLGLuint use_name = 0);
+    void       setGLTextureCreated (bool initialized);
+    void       setCategory(S32 category) ;
     void       setTexName(LLGLuint); // for forcing w/ externally created textures only
     void       setTarget(const LLGLenum target, const LLTexUnit::eTextureType bind_target);
 
-	LLTexUnit::eTextureAddressMode getAddressMode(void) const ;
-	S32        getMaxDiscardLevel() const;
-	S32        getDiscardLevel() const;
-	S8         getComponents() const;
-	BOOL       getBoundRecently() const;
-	S64Bytes   getTextureMemory() const ;
-	LLGLenum   getPrimaryFormat() const;
-	BOOL       getIsAlphaMask(const F32 max_rmse, const F32 max_mid) const ;
-	LLTexUnit::eTextureType getTarget(void) const ;
+    LLTexUnit::eTextureAddressMode getAddressMode(void) const ;
+    S32        getMaxDiscardLevel() const;
+    S32        getDiscardLevel() const;
+    S8         getComponents() const;
+    BOOL       getBoundRecently() const;
+    S64Bytes   getTextureMemory() const ;
+    LLGLenum   getPrimaryFormat() const;
+    BOOL       getIsAlphaMask(const F32 max_rmse, const F32 max_mid) const ;
+    LLTexUnit::eTextureType getTarget(void) const ;
 // [RLVa:KB] - Checked: RLVa-2.2 (@setoverlay)
-	bool       getMask(const LLVector2 &tc) const;
+    bool       getMask(const LLVector2 &tc) const;
 // [/RLVa:KB]
-//	BOOL       getMask(const LLVector2 &tc);
-	F32        getTimePassedSinceLastBound();
-	BOOL       getMissed() const ;
-	BOOL       isJustBound()const ;
-	void       forceUpdateBindStats(void) const;
-
-	U32        getTexelsInAtlas() const ;
-	U32        getTexelsInGLTexture() const ;
-	BOOL       isGLTextureCreated() const ;
-	S32        getDiscardLevelInAtlas() const ;
-	LLGLTextureState getTextureState() const { return mTextureState; }
-	
-	//---------------------------------------------------------------------------------------------
-	//end of functions to access LLImageGL
-	//---------------------------------------------------------------------------------------------
-
-	//-----------------
-	/*virtual*/ void setActive() ;
-	void forceActive() ;
-	void setNoDelete() ;
-	void dontDiscard() { mDontDiscard = 1; mTextureState = NO_DELETE; }
-	BOOL getDontDiscard() const { return mDontDiscard; }
-	//-----------------	
-
-	void setNeedsAlphaAndPickMask(BOOL need_mask) 
-	{ 
-		if (mGLTexturep.notNull())
-			mGLTexturep->setNeedsAlphaAndPickMask(need_mask);
-	}
+//  BOOL       getMask(const LLVector2 &tc);
+    F32        getTimePassedSinceLastBound();
+    BOOL       getMissed() const ;
+    BOOL       isJustBound()const ;
+    void       forceUpdateBindStats(void) const;
+
+    U32        getTexelsInAtlas() const ;
+    U32        getTexelsInGLTexture() const ;
+    BOOL       isGLTextureCreated() const ;
+    S32        getDiscardLevelInAtlas() const ;
+    LLGLTextureState getTextureState() const { return mTextureState; }
+
+    //---------------------------------------------------------------------------------------------
+    //end of functions to access LLImageGL
+    //---------------------------------------------------------------------------------------------
+
+    //-----------------
+    /*virtual*/ void setActive() ;
+    void forceActive() ;
+    void setNoDelete() ;
+    void dontDiscard() { mDontDiscard = 1; mTextureState = NO_DELETE; }
+    BOOL getDontDiscard() const { return mDontDiscard; }
+    //-----------------
+
+    void setNeedsAlphaAndPickMask(BOOL need_mask)
+    {
+        if (mGLTexturep.notNull())
+            mGLTexturep->setNeedsAlphaAndPickMask(need_mask);
+    }
 
 private:
-	void cleanup();
-	void init();
+    void cleanup();
+    void init();
 
 protected:
-	void setTexelsPerImage();
+    void setTexelsPerImage();
 
 public:
-	/*virtual*/ LLImageGL* getGLTexture() const ;
+    /*virtual*/ LLImageGL* getGLTexture() const ;
 
 protected:
-	S32 mBoostLevel;				// enum describing priority level
-	U32 mFullWidth;
-	U32 mFullHeight;
-	BOOL mUseMipMaps;
-	S8  mComponents;
-	U32 mTexelsPerImage;			// Texels per image.
-	mutable S8  mNeedsGLTexture;
-
-	//GL texture
-	LLPointer<LLImageGL> mGLTexturep ;
-	S8 mDontDiscard;			// Keep full res version of this image (for UI, etc)
+    S32 mBoostLevel;                // enum describing priority level
+    U32 mFullWidth;
+    U32 mFullHeight;
+    BOOL mUseMipMaps;
+    S8  mComponents;
+    U32 mTexelsPerImage;            // Texels per image.
+    mutable S8  mNeedsGLTexture;
+
+    //GL texture
+    LLPointer<LLImageGL> mGLTexturep ;
+    S8 mDontDiscard;            // Keep full res version of this image (for UI, etc)
 
 protected:
-	LLGLTextureState  mTextureState ;
+    LLGLTextureState  mTextureState ;
 
 
 };
diff --git a/indra/llrender/llrender.cpp b/indra/llrender/llrender.cpp
index 9f8aa23f59b6a4907dc7ed189f49d4a59f1764da..ee26de5ae04b80aec60c87d5e0b87fe689abfad8 100644
--- a/indra/llrender/llrender.cpp
+++ b/indra/llrender/llrender.cpp
@@ -1,25 +1,25 @@
- /** 
+ /**
  * @file llrender.cpp
  * @brief LLRender implementation
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -57,16 +57,16 @@ extern void APIENTRY gl_debug_callback(GLenum source,
 thread_local LLRender gGL;
 
 // Handy copies of last good GL matrices
-LLMatrix4a	gGLModelView;
-LLMatrix4a	gGLLastModelView;
-LLMatrix4a	gGLLastProjection;
-LLMatrix4a	gGLProjection;
+LLMatrix4a  gGLModelView;
+LLMatrix4a  gGLLastModelView;
+LLMatrix4a  gGLLastProjection;
+LLMatrix4a  gGLProjection;
 
 // transform from last frame's camera space to this frame's camera space (and inverse)
 LLMatrix4a gGLDeltaModelView;
 LLMatrix4a gGLInverseDeltaModelView;
 
-S32			gGLViewport[4];
+S32         gGLViewport[4];
 
 
 U32 LLRender::sUICalls = 0;
@@ -87,111 +87,111 @@ static boost::unordered_map<U64, LLVBCache> sVBCache;
 
 static const GLenum sGLTextureType[] =
 {
-	GL_TEXTURE_2D,
-	GL_TEXTURE_RECTANGLE,
-	GL_TEXTURE_CUBE_MAP,
+    GL_TEXTURE_2D,
+    GL_TEXTURE_RECTANGLE,
+    GL_TEXTURE_CUBE_MAP,
     GL_TEXTURE_CUBE_MAP_ARRAY,
-	GL_TEXTURE_2D_MULTISAMPLE,
+    GL_TEXTURE_2D_MULTISAMPLE,
     GL_TEXTURE_3D
 };
 
 static const GLint sGLAddressMode[] =
-{	
-	GL_REPEAT,
-	GL_MIRRORED_REPEAT,
-	GL_CLAMP_TO_EDGE
+{
+    GL_REPEAT,
+    GL_MIRRORED_REPEAT,
+    GL_CLAMP_TO_EDGE
 };
 
 const U32 immediate_mask = LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TEXCOORD0;
 
 static const GLenum sGLBlendFactor[] =
 {
-	GL_ONE,
-	GL_ZERO,
-	GL_DST_COLOR,
-	GL_SRC_COLOR,
-	GL_ONE_MINUS_DST_COLOR,
-	GL_ONE_MINUS_SRC_COLOR,
-	GL_DST_ALPHA,
-	GL_SRC_ALPHA,
-	GL_ONE_MINUS_DST_ALPHA,
-	GL_ONE_MINUS_SRC_ALPHA,
-
-	GL_ZERO // 'BF_UNDEF'
+    GL_ONE,
+    GL_ZERO,
+    GL_DST_COLOR,
+    GL_SRC_COLOR,
+    GL_ONE_MINUS_DST_COLOR,
+    GL_ONE_MINUS_SRC_COLOR,
+    GL_DST_ALPHA,
+    GL_SRC_ALPHA,
+    GL_ONE_MINUS_DST_ALPHA,
+    GL_ONE_MINUS_SRC_ALPHA,
+
+    GL_ZERO // 'BF_UNDEF'
 };
 
 LLTexUnit::LLTexUnit(S32 index)
-	: mCurrTexType(TT_NONE),
+    : mCurrTexType(TT_NONE),
     mCurrColorScale(1), mCurrAlphaScale(1), mCurrTexture(0),
-	mHasMipMaps(false),
-	mIndex(index)
+    mHasMipMaps(false),
+    mIndex(index)
 {
-	llassert_always(index < (S32)LL_NUM_TEXTURE_LAYERS);
+    llassert_always(index < (S32)LL_NUM_TEXTURE_LAYERS);
 }
 
 //static
 U32 LLTexUnit::getInternalType(eTextureType type)
 {
-	return sGLTextureType[type];
+    return sGLTextureType[type];
 }
 
 void LLTexUnit::refreshState(void)
 {
-	// We set dirty to true so that the tex unit knows to ignore caching
-	// and we reset the cached tex unit state
+    // We set dirty to true so that the tex unit knows to ignore caching
+    // and we reset the cached tex unit state
+
+    gGL.flush();
 
-	gGL.flush();
-	
-	glActiveTexture(GL_TEXTURE0 + mIndex);
+    glActiveTexture(GL_TEXTURE0 + mIndex);
 
-	if (mCurrTexType != TT_NONE)
-	{
-		glBindTexture(sGLTextureType[mCurrTexType], mCurrTexture);
-	}
-	else
-	{
-		glBindTexture(GL_TEXTURE_2D, 0);	
-	}
+    if (mCurrTexType != TT_NONE)
+    {
+        glBindTexture(sGLTextureType[mCurrTexType], mCurrTexture);
+    }
+    else
+    {
+        glBindTexture(GL_TEXTURE_2D, 0);
+    }
 }
 
 void LLTexUnit::activate(void)
 {
-	if (mIndex < 0) return;
+    if (mIndex < 0) return;
 
-	if ((S32)gGL.mCurrTextureUnitIndex != mIndex || gGL.mDirty)
-	{
-		gGL.flush();
-		glActiveTexture(GL_TEXTURE0 + mIndex);
-		gGL.mCurrTextureUnitIndex = mIndex;
-	}
+    if ((S32)gGL.mCurrTextureUnitIndex != mIndex || gGL.mDirty)
+    {
+        gGL.flush();
+        glActiveTexture(GL_TEXTURE0 + mIndex);
+        gGL.mCurrTextureUnitIndex = mIndex;
+    }
 }
 
 void LLTexUnit::enable(eTextureType type)
 {
-	if (mIndex < 0) return;
+    if (mIndex < 0) return;
 
-	if ( (mCurrTexType != type || gGL.mDirty) && (type != TT_NONE) )
-	{
-		activate();
-		if (mCurrTexType != TT_NONE && !gGL.mDirty)
-		{
-			disable(); // Force a disable of a previous texture type if it's enabled.
-		}
-		mCurrTexType = type;
+    if ( (mCurrTexType != type || gGL.mDirty) && (type != TT_NONE) )
+    {
+        activate();
+        if (mCurrTexType != TT_NONE && !gGL.mDirty)
+        {
+            disable(); // Force a disable of a previous texture type if it's enabled.
+        }
+        mCurrTexType = type;
 
-		gGL.flush();
-	}
+        gGL.flush();
+    }
 }
 
 void LLTexUnit::disable(void)
 {
-	if (mIndex < 0) return;
+    if (mIndex < 0) return;
 
-	if (mCurrTexType != TT_NONE)
-	{
-		unbind(mCurrTexType);
-		mCurrTexType = TT_NONE;
-	}
+    if (mCurrTexType != TT_NONE)
+    {
+        unbind(mCurrTexType);
+        mCurrTexType = TT_NONE;
+    }
 }
 
 void LLTexUnit::bindFast(LLTexture* texture)
@@ -216,229 +216,229 @@ void LLTexUnit::bindFast(LLTexture* texture)
 bool LLTexUnit::bind(LLTexture* texture, bool for_rendering, bool forceBind)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	stop_glerror();
-	if (mIndex >= 0)
-	{
-		gGL.flush();
-
-		LLImageGL* gl_tex = NULL ;
-
-		if (texture != NULL && (gl_tex = texture->getGLTexture()))
-		{
-			if (gl_tex->getTexName()) //if texture exists
-			{
-				//in audit, replace the selected texture by the default one.
-				if ((mCurrTexture != gl_tex->getTexName()) || forceBind)
-				{
-					activate();
-					enable(gl_tex->getTarget());
-					mCurrTexture = gl_tex->getTexName();
-					glBindTexture(sGLTextureType[gl_tex->getTarget()], mCurrTexture);
-					if(gl_tex->updateBindStats())
-					{
-						texture->setActive() ;
-						texture->updateBindStatsForTester() ;
-					}
-					mHasMipMaps = gl_tex->mHasMipMaps;
-					if (gl_tex->mTexOptionsDirty)
-					{
-						gl_tex->mTexOptionsDirty = false;
-						setTextureAddressMode(gl_tex->mAddressMode);
-						setTextureFilteringOption(gl_tex->mFilterOption);
+    stop_glerror();
+    if (mIndex >= 0)
+    {
+        gGL.flush();
+
+        LLImageGL* gl_tex = NULL ;
+
+        if (texture != NULL && (gl_tex = texture->getGLTexture()))
+        {
+            if (gl_tex->getTexName()) //if texture exists
+            {
+                //in audit, replace the selected texture by the default one.
+                if ((mCurrTexture != gl_tex->getTexName()) || forceBind)
+                {
+                    activate();
+                    enable(gl_tex->getTarget());
+                    mCurrTexture = gl_tex->getTexName();
+                    glBindTexture(sGLTextureType[gl_tex->getTarget()], mCurrTexture);
+                    if(gl_tex->updateBindStats())
+                    {
+                        texture->setActive() ;
+                        texture->updateBindStatsForTester() ;
+                    }
+                    mHasMipMaps = gl_tex->mHasMipMaps;
+                    if (gl_tex->mTexOptionsDirty)
+                    {
+                        gl_tex->mTexOptionsDirty = false;
+                        setTextureAddressMode(gl_tex->mAddressMode);
+                        setTextureFilteringOption(gl_tex->mFilterOption);
                     }
-				}
-			}
-			else
-			{
-				//if deleted, will re-generate it immediately
-				texture->forceImmediateUpdate() ;
-
-				gl_tex->forceUpdateBindStats() ;
-				return texture->bindDefaultImage(mIndex);
-			}
-		}
-		else
-		{
+                }
+            }
+            else
+            {
+                //if deleted, will re-generate it immediately
+                texture->forceImmediateUpdate() ;
+
+                gl_tex->forceUpdateBindStats() ;
+                return texture->bindDefaultImage(mIndex);
+            }
+        }
+        else
+        {
 #ifdef SHOW_DEBUG
-			if (texture)
-			{
-				LL_DEBUGS() << "NULL LLTexUnit::bind GL image" << LL_ENDL;
-			}
-			else
-			{
-				LL_DEBUGS() << "NULL LLTexUnit::bind texture" << LL_ENDL;
-			}
+            if (texture)
+            {
+                LL_DEBUGS() << "NULL LLTexUnit::bind GL image" << LL_ENDL;
+            }
+            else
+            {
+                LL_DEBUGS() << "NULL LLTexUnit::bind texture" << LL_ENDL;
+            }
 #endif
-			return false;
-		}
-	}
-	else
-	{ // mIndex < 0
-		return false;
-	}
+            return false;
+        }
+    }
+    else
+    { // mIndex < 0
+        return false;
+    }
 
-	return true;
+    return true;
 }
 
 bool LLTexUnit::bind(LLImageGL* texture, bool for_rendering, bool forceBind, S32 usename)
 {
-	stop_glerror();
-	if (mIndex < 0) return false;
+    stop_glerror();
+    if (mIndex < 0) return false;
 
     U32 texname = usename ? usename : texture->getTexName();
 
-	if(!texture)
-	{
+    if(!texture)
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS() << "NULL LLTexUnit::bind texture" << LL_ENDL;
+        LL_DEBUGS() << "NULL LLTexUnit::bind texture" << LL_ENDL;
 #endif
-		return false;
-	}
-
-	if(!texname)
-	{
-		if(LLImageGL::sDefaultGLTexture && LLImageGL::sDefaultGLTexture->getTexName())
-		{
-			return bind(LLImageGL::sDefaultGLTexture) ;
-		}
-		stop_glerror();
-		return false ;
-	}
-
-	if ((mCurrTexture != texname) || forceBind)
-	{
-		gGL.flush();
-		stop_glerror();
-		activate();
-		stop_glerror();
-		enable(texture->getTarget());
-		stop_glerror();
-		mCurrTexture = texname;
-		glBindTexture(sGLTextureType[texture->getTarget()], mCurrTexture);
-		stop_glerror();
+        return false;
+    }
+
+    if(!texname)
+    {
+        if(LLImageGL::sDefaultGLTexture && LLImageGL::sDefaultGLTexture->getTexName())
+        {
+            return bind(LLImageGL::sDefaultGLTexture) ;
+        }
+        stop_glerror();
+        return false ;
+    }
+
+    if ((mCurrTexture != texname) || forceBind)
+    {
+        gGL.flush();
+        stop_glerror();
+        activate();
+        stop_glerror();
+        enable(texture->getTarget());
+        stop_glerror();
+        mCurrTexture = texname;
+        glBindTexture(sGLTextureType[texture->getTarget()], mCurrTexture);
+        stop_glerror();
         texture->updateBindStats();
-		mHasMipMaps = texture->mHasMipMaps;
-		if (texture->mTexOptionsDirty)
-		{
-			stop_glerror();
-			texture->mTexOptionsDirty = false;
-			setTextureAddressMode(texture->mAddressMode);
-			setTextureFilteringOption(texture->mFilterOption);
-			stop_glerror();
-		}
-	}
+        mHasMipMaps = texture->mHasMipMaps;
+        if (texture->mTexOptionsDirty)
+        {
+            stop_glerror();
+            texture->mTexOptionsDirty = false;
+            setTextureAddressMode(texture->mAddressMode);
+            setTextureFilteringOption(texture->mFilterOption);
+            stop_glerror();
+        }
+    }
 
-	stop_glerror();
+    stop_glerror();
 
-	return true;
+    return true;
 }
 
 bool LLTexUnit::bind(LLCubeMap* cubeMap)
 {
-	if (mIndex < 0) return false;
+    if (mIndex < 0) return false;
 
-	gGL.flush();
+    gGL.flush();
 
-	if (cubeMap == NULL)
-	{
-		LL_WARNS() << "NULL LLTexUnit::bind cubemap" << LL_ENDL;
-		return false;
-	}
+    if (cubeMap == NULL)
+    {
+        LL_WARNS() << "NULL LLTexUnit::bind cubemap" << LL_ENDL;
+        return false;
+    }
 
-	if (mCurrTexture != cubeMap->mImages[0]->getTexName())
-	{
-		if (LLCubeMap::sUseCubeMaps)
-		{
-			activate();
-			enable(LLTexUnit::TT_CUBE_MAP);
+    if (mCurrTexture != cubeMap->mImages[0]->getTexName())
+    {
+        if (LLCubeMap::sUseCubeMaps)
+        {
+            activate();
+            enable(LLTexUnit::TT_CUBE_MAP);
             mCurrTexture = cubeMap->mImages[0]->getTexName();
-			glBindTexture(GL_TEXTURE_CUBE_MAP, mCurrTexture);
-			mHasMipMaps = cubeMap->mImages[0]->mHasMipMaps;
-			cubeMap->mImages[0]->updateBindStats();
-			if (cubeMap->mImages[0]->mTexOptionsDirty)
-			{
-				cubeMap->mImages[0]->mTexOptionsDirty = false;
-				setTextureAddressMode(cubeMap->mImages[0]->mAddressMode);
-				setTextureFilteringOption(cubeMap->mImages[0]->mFilterOption);
+            glBindTexture(GL_TEXTURE_CUBE_MAP, mCurrTexture);
+            mHasMipMaps = cubeMap->mImages[0]->mHasMipMaps;
+            cubeMap->mImages[0]->updateBindStats();
+            if (cubeMap->mImages[0]->mTexOptionsDirty)
+            {
+                cubeMap->mImages[0]->mTexOptionsDirty = false;
+                setTextureAddressMode(cubeMap->mImages[0]->mAddressMode);
+                setTextureFilteringOption(cubeMap->mImages[0]->mFilterOption);
             }
-			return true;
-		}
-		else
-		{
-			LL_WARNS() << "Using cube map without extension!" << LL_ENDL;
-			return false;
-		}
-	}
-	return true;
+            return true;
+        }
+        else
+        {
+            LL_WARNS() << "Using cube map without extension!" << LL_ENDL;
+            return false;
+        }
+    }
+    return true;
 }
 
 // LLRenderTarget is unavailible on the mapserver since it uses FBOs.
 bool LLTexUnit::bind(LLRenderTarget* renderTarget, bool bindDepth)
 {
-	if (mIndex < 0) return false;
+    if (mIndex < 0) return false;
 
-	gGL.flush();
+    gGL.flush();
 
-	if (bindDepth)
-	{
+    if (bindDepth)
+    {
         llassert(renderTarget->getDepth()); // target MUST have a depth buffer attachment
 
-		bindManual(renderTarget->getUsage(), renderTarget->getDepth());
-	}
-	else
-	{
-		bindManual(renderTarget->getUsage(), renderTarget->getTexture());
-	}
+        bindManual(renderTarget->getUsage(), renderTarget->getDepth());
+    }
+    else
+    {
+        bindManual(renderTarget->getUsage(), renderTarget->getTexture());
+    }
 
-	return true;
+    return true;
 }
 
 bool LLTexUnit::bindManual(eTextureType type, U32 texture, bool hasMips)
 {
-	if (mIndex < 0)  
-	{
-		return false;
-	}
-	
-	if(mCurrTexture != texture)
-	{
-		gGL.flush();
-		
-		activate();
-		enable(type);
-		mCurrTexture = texture;
-		glBindTexture(sGLTextureType[type], texture);
+    if (mIndex < 0)
+    {
+        return false;
+    }
+
+    if(mCurrTexture != texture)
+    {
+        gGL.flush();
+
+        activate();
+        enable(type);
+        mCurrTexture = texture;
+        glBindTexture(sGLTextureType[type], texture);
         mHasMipMaps = hasMips;
-	}
-	return true;
+    }
+    return true;
 }
 
 void LLTexUnit::unbind(eTextureType type)
 {
-	stop_glerror();
+    stop_glerror();
 
-	if (mIndex < 0) return;
+    if (mIndex < 0) return;
 
-	//always flush and activate for consistency 
-	//   some code paths assume unbind always flushes and sets the active texture
-	gGL.flush();
-	activate();
+    //always flush and activate for consistency
+    //   some code paths assume unbind always flushes and sets the active texture
+    gGL.flush();
+    activate();
 
-	// Disabled caching of binding state.
-	if (mCurrTexType == type)
-	{
-		mCurrTexture = 0;
+    // Disabled caching of binding state.
+    if (mCurrTexType == type)
+    {
+        mCurrTexture = 0;
 
-		if (type == LLTexUnit::TT_TEXTURE)
-		{
-			glBindTexture(sGLTextureType[type], sWhiteTexture);
-		}
-		else
-		{
-			glBindTexture(sGLTextureType[type], 0);
-		}
-		stop_glerror();
-	}
+        if (type == LLTexUnit::TT_TEXTURE)
+        {
+            glBindTexture(sGLTextureType[type], sWhiteTexture);
+        }
+        else
+        {
+            glBindTexture(sGLTextureType[type], 0);
+        }
+        stop_glerror();
+    }
 }
 
 void LLTexUnit::unbindFast(eTextureType type)
@@ -463,185 +463,185 @@ void LLTexUnit::unbindFast(eTextureType type)
 
 void LLTexUnit::setTextureAddressMode(eTextureAddressMode mode)
 {
-	if (mIndex < 0 || mCurrTexture == 0) return;
+    if (mIndex < 0 || mCurrTexture == 0) return;
 
-	gGL.flush();
+    gGL.flush();
 
-	activate();
+    activate();
 
-	glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_S, sGLAddressMode[mode]);
-	glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_T, sGLAddressMode[mode]);
-	if (mCurrTexType == TT_CUBE_MAP || mCurrTexType == TT_TEXTURE_3D)
-	{
-		glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_R, sGLAddressMode[mode]);
-	}
+    glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_S, sGLAddressMode[mode]);
+    glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_T, sGLAddressMode[mode]);
+    if (mCurrTexType == TT_CUBE_MAP || mCurrTexType == TT_TEXTURE_3D)
+    {
+        glTexParameteri (sGLTextureType[mCurrTexType], GL_TEXTURE_WRAP_R, sGLAddressMode[mode]);
+    }
 }
 
 void LLTexUnit::setTextureFilteringOption(LLTexUnit::eTextureFilterOptions option)
 {
-	if (mIndex < 0 || mCurrTexture == 0 || mCurrTexType == LLTexUnit::TT_MULTISAMPLE_TEXTURE) return;
-
-	gGL.flush();
-
-	if (option == TFO_POINT)
-	{
-		glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
-	}
-	else
-	{
-		glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-	}
-
-	if (option >= TFO_TRILINEAR && mHasMipMaps)
-	{
-		glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
-	} 
-	else if (option >= TFO_BILINEAR)
-	{
-		if (mHasMipMaps)
-		{
-			glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
-		}
-		else
-		{
-			glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-		}
-	}
-	else
-	{
-		if (mHasMipMaps)
-		{
-			glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
-		}
-		else
-		{
-			glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-		}
-	}
-
-	if (gGLManager.mHasTextureFilterAnisotropic)
-	{
-		if (option == TFO_ANISOTROPIC && LLRender::sAnisotropicFilteringLevel > 1.f)
-		{
-			F32 aniso_level = llclamp(LLRender::sAnisotropicFilteringLevel, 1.f, gGLManager.mMaxAnisotropy);
-			glTexParameterf(sGLTextureType[mCurrTexType], GL_TEXTURE_MAX_ANISOTROPY, aniso_level);
-		}
-		else
-		{
-			glTexParameterf(sGLTextureType[mCurrTexType], GL_TEXTURE_MAX_ANISOTROPY, 1.f);
-		}
-	}
+    if (mIndex < 0 || mCurrTexture == 0 || mCurrTexType == LLTexUnit::TT_MULTISAMPLE_TEXTURE) return;
+
+    gGL.flush();
+
+    if (option == TFO_POINT)
+    {
+        glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+    }
+    else
+    {
+        glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+    }
+
+    if (option >= TFO_TRILINEAR && mHasMipMaps)
+    {
+        glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
+    }
+    else if (option >= TFO_BILINEAR)
+    {
+        if (mHasMipMaps)
+        {
+            glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);
+        }
+        else
+        {
+            glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+        }
+    }
+    else
+    {
+        if (mHasMipMaps)
+        {
+            glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
+        }
+        else
+        {
+            glTexParameteri(sGLTextureType[mCurrTexType], GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+        }
+    }
+
+    if (gGLManager.mHasTextureFilterAnisotropic)
+    {
+        if (option == TFO_ANISOTROPIC && LLRender::sAnisotropicFilteringLevel > 1.f)
+        {
+            F32 aniso_level = llclamp(LLRender::sAnisotropicFilteringLevel, 1.f, gGLManager.mMaxAnisotropy);
+            glTexParameterf(sGLTextureType[mCurrTexType], GL_TEXTURE_MAX_ANISOTROPY, aniso_level);
+        }
+        else
+        {
+            glTexParameterf(sGLTextureType[mCurrTexType], GL_TEXTURE_MAX_ANISOTROPY, 1.f);
+        }
+    }
 }
 
 GLint LLTexUnit::getTextureSource(eTextureBlendSrc src)
 {
-	switch(src)
-	{
-		// All four cases should return the same value.
-		case TBS_PREV_COLOR:
-		case TBS_PREV_ALPHA:
-		case TBS_ONE_MINUS_PREV_COLOR:
-		case TBS_ONE_MINUS_PREV_ALPHA:
-			return GL_PREVIOUS;
-
-		// All four cases should return the same value.
-		case TBS_TEX_COLOR:
-		case TBS_TEX_ALPHA:
-		case TBS_ONE_MINUS_TEX_COLOR:
-		case TBS_ONE_MINUS_TEX_ALPHA:
-			return GL_TEXTURE;
-
-		// All four cases should return the same value.
-		case TBS_VERT_COLOR:
-		case TBS_VERT_ALPHA:
-		case TBS_ONE_MINUS_VERT_COLOR:
-		case TBS_ONE_MINUS_VERT_ALPHA:
-			return GL_PRIMARY_COLOR;
-
-		// All four cases should return the same value.
-		case TBS_CONST_COLOR:
-		case TBS_CONST_ALPHA:
-		case TBS_ONE_MINUS_CONST_COLOR:
-		case TBS_ONE_MINUS_CONST_ALPHA:
-			return GL_CONSTANT;
-
-		default:
-			LL_WARNS() << "Unknown eTextureBlendSrc: " << src << ".  Using Vertex Color instead." << LL_ENDL;
-			return GL_PRIMARY_COLOR;
-	}
+    switch(src)
+    {
+        // All four cases should return the same value.
+        case TBS_PREV_COLOR:
+        case TBS_PREV_ALPHA:
+        case TBS_ONE_MINUS_PREV_COLOR:
+        case TBS_ONE_MINUS_PREV_ALPHA:
+            return GL_PREVIOUS;
+
+        // All four cases should return the same value.
+        case TBS_TEX_COLOR:
+        case TBS_TEX_ALPHA:
+        case TBS_ONE_MINUS_TEX_COLOR:
+        case TBS_ONE_MINUS_TEX_ALPHA:
+            return GL_TEXTURE;
+
+        // All four cases should return the same value.
+        case TBS_VERT_COLOR:
+        case TBS_VERT_ALPHA:
+        case TBS_ONE_MINUS_VERT_COLOR:
+        case TBS_ONE_MINUS_VERT_ALPHA:
+            return GL_PRIMARY_COLOR;
+
+        // All four cases should return the same value.
+        case TBS_CONST_COLOR:
+        case TBS_CONST_ALPHA:
+        case TBS_ONE_MINUS_CONST_COLOR:
+        case TBS_ONE_MINUS_CONST_ALPHA:
+            return GL_CONSTANT;
+
+        default:
+            LL_WARNS() << "Unknown eTextureBlendSrc: " << src << ".  Using Vertex Color instead." << LL_ENDL;
+            return GL_PRIMARY_COLOR;
+    }
 }
 
 GLint LLTexUnit::getTextureSourceType(eTextureBlendSrc src, bool isAlpha)
 {
-	switch(src)
-	{
-		// All four cases should return the same value.
-		case TBS_PREV_COLOR:
-		case TBS_TEX_COLOR:
-		case TBS_VERT_COLOR:
-		case TBS_CONST_COLOR:
-			return (isAlpha) ? GL_SRC_ALPHA: GL_SRC_COLOR;
-
-		// All four cases should return the same value.
-		case TBS_PREV_ALPHA:
-		case TBS_TEX_ALPHA:
-		case TBS_VERT_ALPHA:
-		case TBS_CONST_ALPHA:
-			return GL_SRC_ALPHA;
-
-		// All four cases should return the same value.
-		case TBS_ONE_MINUS_PREV_COLOR:
-		case TBS_ONE_MINUS_TEX_COLOR:
-		case TBS_ONE_MINUS_VERT_COLOR:
-		case TBS_ONE_MINUS_CONST_COLOR:
-			return (isAlpha) ? GL_ONE_MINUS_SRC_ALPHA : GL_ONE_MINUS_SRC_COLOR;
-
-		// All four cases should return the same value.
-		case TBS_ONE_MINUS_PREV_ALPHA:
-		case TBS_ONE_MINUS_TEX_ALPHA:
-		case TBS_ONE_MINUS_VERT_ALPHA:
-		case TBS_ONE_MINUS_CONST_ALPHA:
-			return GL_ONE_MINUS_SRC_ALPHA;
-
-		default:
-			LL_WARNS() << "Unknown eTextureBlendSrc: " << src << ".  Using Source Color or Alpha instead." << LL_ENDL;
-			return (isAlpha) ? GL_SRC_ALPHA: GL_SRC_COLOR;
-	}
+    switch(src)
+    {
+        // All four cases should return the same value.
+        case TBS_PREV_COLOR:
+        case TBS_TEX_COLOR:
+        case TBS_VERT_COLOR:
+        case TBS_CONST_COLOR:
+            return (isAlpha) ? GL_SRC_ALPHA: GL_SRC_COLOR;
+
+        // All four cases should return the same value.
+        case TBS_PREV_ALPHA:
+        case TBS_TEX_ALPHA:
+        case TBS_VERT_ALPHA:
+        case TBS_CONST_ALPHA:
+            return GL_SRC_ALPHA;
+
+        // All four cases should return the same value.
+        case TBS_ONE_MINUS_PREV_COLOR:
+        case TBS_ONE_MINUS_TEX_COLOR:
+        case TBS_ONE_MINUS_VERT_COLOR:
+        case TBS_ONE_MINUS_CONST_COLOR:
+            return (isAlpha) ? GL_ONE_MINUS_SRC_ALPHA : GL_ONE_MINUS_SRC_COLOR;
+
+        // All four cases should return the same value.
+        case TBS_ONE_MINUS_PREV_ALPHA:
+        case TBS_ONE_MINUS_TEX_ALPHA:
+        case TBS_ONE_MINUS_VERT_ALPHA:
+        case TBS_ONE_MINUS_CONST_ALPHA:
+            return GL_ONE_MINUS_SRC_ALPHA;
+
+        default:
+            LL_WARNS() << "Unknown eTextureBlendSrc: " << src << ".  Using Source Color or Alpha instead." << LL_ENDL;
+            return (isAlpha) ? GL_SRC_ALPHA: GL_SRC_COLOR;
+    }
 }
 
 void LLTexUnit::setColorScale(S32 scale)
 {
-	if (mCurrColorScale != scale || gGL.mDirty)
-	{
-		mCurrColorScale = scale;
-		gGL.flush();
-		glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE, scale );
-	}
+    if (mCurrColorScale != scale || gGL.mDirty)
+    {
+        mCurrColorScale = scale;
+        gGL.flush();
+        glTexEnvi( GL_TEXTURE_ENV, GL_RGB_SCALE, scale );
+    }
 }
 
 void LLTexUnit::setAlphaScale(S32 scale)
 {
-	if (mCurrAlphaScale != scale || gGL.mDirty)
-	{
-		mCurrAlphaScale = scale;
-		gGL.flush();
-		glTexEnvi( GL_TEXTURE_ENV, GL_ALPHA_SCALE, scale );
-	}
+    if (mCurrAlphaScale != scale || gGL.mDirty)
+    {
+        mCurrAlphaScale = scale;
+        gGL.flush();
+        glTexEnvi( GL_TEXTURE_ENV, GL_ALPHA_SCALE, scale );
+    }
 }
 
-// Useful for debugging that you've manually assigned a texture operation to the correct 
+// Useful for debugging that you've manually assigned a texture operation to the correct
 // texture unit based on the currently set active texture in opengl.
 void LLTexUnit::debugTextureUnit(void)
 {
-	if (mIndex < 0) return;
+    if (mIndex < 0) return;
 
-	GLint activeTexture;
-	glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexture);
-	if ((GL_TEXTURE0 + mIndex) != activeTexture)
-	{
-		U32 set_unit = (activeTexture - GL_TEXTURE0);
-		LL_WARNS() << "Incorrect Texture Unit!  Expected: " << set_unit << " Actual: " << mIndex << LL_ENDL;
-	}
+    GLint activeTexture;
+    glGetIntegerv(GL_ACTIVE_TEXTURE, &activeTexture);
+    if ((GL_TEXTURE0 + mIndex) != activeTexture)
+    {
+        U32 set_unit = (activeTexture - GL_TEXTURE0);
+        LL_WARNS() << "Incorrect Texture Unit!  Expected: " << set_unit << " Actual: " << mIndex << LL_ENDL;
+    }
 }
 
 LLLightState::LLLightState(S32 index)
@@ -653,46 +653,46 @@ LLLightState::LLLightState(S32 index)
   mSpotExponent(0.f),
   mSpotCutoff(180.f)
 {
-	if (mIndex == 0)
-	{
-		mDiffuse.set(1,1,1,1);
+    if (mIndex == 0)
+    {
+        mDiffuse.set(1,1,1,1);
         mDiffuseB.set(0,0,0,0);
-		mSpecular.set(1,1,1,1);
-	}
+        mSpecular.set(1,1,1,1);
+    }
 
     mSunIsPrimary = true;
 
-	mAmbient.set(0,0,0,1);
-	mPosition.set(0,0,1,0);
-	mSpotDirection.set(0,0,-1);
+    mAmbient.set(0,0,0,1);
+    mPosition.set(0,0,1,0);
+    mSpotDirection.set(0,0,-1);
 }
 
 void LLLightState::enable()
 {
-	mEnabled = true;
+    mEnabled = true;
 }
 
 void LLLightState::disable()
 {
-	mEnabled = false;
+    mEnabled = false;
 }
 
 void LLLightState::setDiffuse(const LLColor4& diffuse)
 {
-	if (mDiffuse != diffuse)
-	{
-		++gGL.mLightHash;
-		mDiffuse = diffuse;
-	}
+    if (mDiffuse != diffuse)
+    {
+        ++gGL.mLightHash;
+        mDiffuse = diffuse;
+    }
 }
 
 void LLLightState::setDiffuseB(const LLColor4& diffuse)
 {
     if (mDiffuseB != diffuse)
-	{
-		++gGL.mLightHash;
-		mDiffuseB = diffuse;
-	}
+    {
+        ++gGL.mLightHash;
+        mDiffuseB = diffuse;
+    }
 }
 
 void LLLightState::setSunPrimary(bool v)
@@ -700,7 +700,7 @@ void LLLightState::setSunPrimary(bool v)
     if (mSunIsPrimary != v)
     {
         ++gGL.mLightHash;
-		mSunIsPrimary = v;
+        mSunIsPrimary = v;
     }
 }
 
@@ -724,90 +724,90 @@ void LLLightState::setFalloff(F32 v)
 
 void LLLightState::setAmbient(const LLColor4& ambient)
 {
-	if (mAmbient != ambient)
-	{
-		++gGL.mLightHash;
-		mAmbient = ambient;
-	}
+    if (mAmbient != ambient)
+    {
+        ++gGL.mLightHash;
+        mAmbient = ambient;
+    }
 }
 
 void LLLightState::setSpecular(const LLColor4& specular)
 {
-	if (mSpecular != specular)
-	{
-		++gGL.mLightHash;
-		mSpecular = specular;
-	}
+    if (mSpecular != specular)
+    {
+        ++gGL.mLightHash;
+        mSpecular = specular;
+    }
 }
 
 void LLLightState::setPosition(const LLVector4& position)
 {
-	//always set position because modelview matrix may have changed
-	++gGL.mLightHash;
-	mPosition = position;
-	//transform position by current modelview matrix
-	LLVector4a pos;
-	pos.loadua(position.mV);
-	gGL.getModelviewMatrix().rotate4(pos,pos);
-	mPosition.set(pos.getF32ptr());
+    //always set position because modelview matrix may have changed
+    ++gGL.mLightHash;
+    mPosition = position;
+    //transform position by current modelview matrix
+    LLVector4a pos;
+    pos.loadua(position.mV);
+    gGL.getModelviewMatrix().rotate4(pos,pos);
+    mPosition.set(pos.getF32ptr());
 }
 
 void LLLightState::setConstantAttenuation(const F32& atten)
 {
-	if (mConstantAtten != atten)
-	{
-		mConstantAtten = atten;
-		++gGL.mLightHash;
-	}
+    if (mConstantAtten != atten)
+    {
+        mConstantAtten = atten;
+        ++gGL.mLightHash;
+    }
 }
 
 void LLLightState::setLinearAttenuation(const F32& atten)
 {
-	if (mLinearAtten != atten)
-	{
-		++gGL.mLightHash;
-		mLinearAtten = atten;
-	}
+    if (mLinearAtten != atten)
+    {
+        ++gGL.mLightHash;
+        mLinearAtten = atten;
+    }
 }
 
 void LLLightState::setQuadraticAttenuation(const F32& atten)
 {
-	if (mQuadraticAtten != atten)
-	{
-		++gGL.mLightHash;
-		mQuadraticAtten = atten;
-	}
+    if (mQuadraticAtten != atten)
+    {
+        ++gGL.mLightHash;
+        mQuadraticAtten = atten;
+    }
 }
 
 void LLLightState::setSpotExponent(const F32& exponent)
 {
-	if (mSpotExponent != exponent)
-	{
-		++gGL.mLightHash;
-		mSpotExponent = exponent;
-	}
+    if (mSpotExponent != exponent)
+    {
+        ++gGL.mLightHash;
+        mSpotExponent = exponent;
+    }
 }
 
 void LLLightState::setSpotCutoff(const F32& cutoff)
 {
-	if (mSpotCutoff != cutoff)
-	{
-		++gGL.mLightHash;
-		mSpotCutoff = cutoff;
-	}
+    if (mSpotCutoff != cutoff)
+    {
+        ++gGL.mLightHash;
+        mSpotCutoff = cutoff;
+    }
 }
 
 void LLLightState::setSpotDirection(const LLVector3& direction)
 {
-	//always set direction because modelview matrix may have changed
-	++gGL.mLightHash;
-	mSpotDirection = direction;
-	//transform direction by current modelview matrix
-	LLVector4a dir;
-	dir.load3(direction.mV);
-	gGL.getModelviewMatrix().rotate(dir,dir);
+    //always set direction because modelview matrix may have changed
+    ++gGL.mLightHash;
+    mSpotDirection = direction;
+    //transform direction by current modelview matrix
+    LLVector4a dir;
+    dir.load3(direction.mV);
+    gGL.getModelviewMatrix().rotate(dir,dir);
 
-	mSpotDirection.set(dir.getF32ptr());
+    mSpotDirection.set(dir.getF32ptr());
 }
 
 LLRender::LLRender()
@@ -816,50 +816,50 @@ LLRender::LLRender()
     mMode(LLRender::TRIANGLES),
     mCurrTextureUnitIndex(0),
     mLineWidth(1.f),
-	mPrimitiveReset(false)
-{	
-	for (U32 i = 0; i < LL_NUM_TEXTURE_LAYERS; i++)
-	{
+    mPrimitiveReset(false)
+{
+    for (U32 i = 0; i < LL_NUM_TEXTURE_LAYERS; i++)
+    {
         mTexUnits[i].mIndex = i;
-	}
+    }
 
-	for (U32 i = 0; i < LL_NUM_LIGHT_UNITS; ++i)
-	{
+    for (U32 i = 0; i < LL_NUM_LIGHT_UNITS; ++i)
+    {
         mLightState[i].mIndex = i;
-	}
+    }
+
+    for (U32 i = 0; i < 4; i++)
+    {
+        mCurrColorMask[i] = true;
+    }
 
-	for (U32 i = 0; i < 4; i++)
-	{
-		mCurrColorMask[i] = true;
-	}
+    mCurrBlendColorSFactor = BF_UNDEF;
+    mCurrBlendAlphaSFactor = BF_UNDEF;
+    mCurrBlendColorDFactor = BF_UNDEF;
+    mCurrBlendAlphaDFactor = BF_UNDEF;
 
-	mCurrBlendColorSFactor = BF_UNDEF;
-	mCurrBlendAlphaSFactor = BF_UNDEF;
-	mCurrBlendColorDFactor = BF_UNDEF;
-	mCurrBlendAlphaDFactor = BF_UNDEF;
+    mMatrixMode = LLRender::MM_MODELVIEW;
 
-	mMatrixMode = LLRender::MM_MODELVIEW;
-	
-	for (U32 i = 0; i < NUM_MATRIX_MODES; ++i)
-	{
-		mMatIdx[i] = 0;
-		mMatHash[i] = 0;
-		mCurMatHash[i] = 0xFFFFFFFF;
-	}
+    for (U32 i = 0; i < NUM_MATRIX_MODES; ++i)
+    {
+        mMatIdx[i] = 0;
+        mMatHash[i] = 0;
+        mCurMatHash[i] = 0xFFFFFFFF;
+    }
 
-	mLightHash = 0;
-	
-	//Init base matrix for each mode
-	for(U32 i = 0; i < NUM_MATRIX_MODES; ++i)
-	{
-		mMatrix[i][0].setIdentity();
-	}
+    mLightHash = 0;
+
+    //Init base matrix for each mode
+    for(U32 i = 0; i < NUM_MATRIX_MODES; ++i)
+    {
+        mMatrix[i][0].setIdentity();
+    }
 
 }
 
 LLRender::~LLRender()
 {
-	shutdown();
+    shutdown();
 }
 
 bool LLRender::init(bool needs_vertex_buffer)
@@ -900,18 +900,18 @@ bool LLRender::init(bool needs_vertex_buffer)
 
 void LLRender::initVertexBuffer()
 {
-	llassert_always(mBuffer.isNull());
-	stop_glerror();
+    llassert_always(mBuffer.isNull());
+    stop_glerror();
     mBuffer = new LLVertexBuffer(immediate_mask);
-	stop_glerror();
+    stop_glerror();
     mBuffer->allocateBuffer(4096, 0);
-	stop_glerror();
-	mBuffer->getVertexStrider(mVerticesp);
-	stop_glerror();
-	mBuffer->getTexCoord0Strider(mTexcoordsp);
-	stop_glerror();
-	mBuffer->getColorStrider(mColorsp);
-	stop_glerror();
+    stop_glerror();
+    mBuffer->getVertexStrider(mVerticesp);
+    stop_glerror();
+    mBuffer->getTexCoord0Strider(mTexcoordsp);
+    stop_glerror();
+    mBuffer->getColorStrider(mColorsp);
+    stop_glerror();
 }
 
 void LLRender::resetVertexBuffer()
@@ -926,22 +926,22 @@ void LLRender::shutdown()
 
 void LLRender::refreshState(void)
 {
-	mDirty = true;
+    mDirty = true;
+
+    U32 active_unit = mCurrTextureUnitIndex;
 
-	U32 active_unit = mCurrTextureUnitIndex;
+    for (U32 i = 0; i < mTexUnits.size(); i++)
+    {
+        mTexUnits[i].refreshState();
+    }
 
-	for (U32 i = 0; i < mTexUnits.size(); i++)
-	{
-		mTexUnits[i].refreshState();
-	}
-	
-	mTexUnits[active_unit].activate();
+    mTexUnits[active_unit].activate();
+
+    setColorMask(mCurrColorMask[0], mCurrColorMask[1], mCurrColorMask[2], mCurrColorMask[3]);
 
-	setColorMask(mCurrColorMask[0], mCurrColorMask[1], mCurrColorMask[2], mCurrColorMask[3]);
-	
     flush();
 
-	mDirty = false;
+    mDirty = false;
 }
 
 void LLRender::syncLightState()
@@ -993,287 +993,287 @@ void LLRender::syncLightState()
 
 void LLRender::syncMatrices()
 {
-    static const U32 name[] = 
-	{
-		LLShaderMgr::MODELVIEW_MATRIX,
-		LLShaderMgr::PROJECTION_MATRIX,
-		LLShaderMgr::TEXTURE_MATRIX0,
-		LLShaderMgr::TEXTURE_MATRIX1,
-		LLShaderMgr::TEXTURE_MATRIX2,
-		LLShaderMgr::TEXTURE_MATRIX3,
-	};
+    static const U32 name[] =
+    {
+        LLShaderMgr::MODELVIEW_MATRIX,
+        LLShaderMgr::PROJECTION_MATRIX,
+        LLShaderMgr::TEXTURE_MATRIX0,
+        LLShaderMgr::TEXTURE_MATRIX1,
+        LLShaderMgr::TEXTURE_MATRIX2,
+        LLShaderMgr::TEXTURE_MATRIX3,
+    };
 
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
 
-	static LLMatrix4a cached_mvp;
+    static LLMatrix4a cached_mvp;
     static LLMatrix4a cached_inv_mdv;
-	static U32 cached_mvp_mdv_hash = 0xFFFFFFFF;
-	static U32 cached_mvp_proj_hash = 0xFFFFFFFF;
-	
-	static LLMatrix4a cached_normal;
-	static U32 cached_normal_hash = 0xFFFFFFFF;
+    static U32 cached_mvp_mdv_hash = 0xFFFFFFFF;
+    static U32 cached_mvp_proj_hash = 0xFFFFFFFF;
 
-	if (shader)
-	{
-		//llassert(shader);
+    static LLMatrix4a cached_normal;
+    static U32 cached_normal_hash = 0xFFFFFFFF;
+
+    if (shader)
+    {
+        //llassert(shader);
 
-		bool mvp_done = false;
+        bool mvp_done = false;
 
-		U32 i = MM_MODELVIEW;
-		if (mMatHash[MM_MODELVIEW] != shader->mMatHash[MM_MODELVIEW])
-		{ //update modelview, normal, and MVP
-			const LLMatrix4a& mat = mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]];
+        U32 i = MM_MODELVIEW;
+        if (mMatHash[MM_MODELVIEW] != shader->mMatHash[MM_MODELVIEW])
+        { //update modelview, normal, and MVP
+            const LLMatrix4a& mat = mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]];
 
             // if MDV has changed, update the cached inverse as well
             if (cached_mvp_mdv_hash != mMatHash[MM_MODELVIEW])
             {
                 cached_inv_mdv = mat;
-				cached_inv_mdv.invert();
+                cached_inv_mdv.invert();
             }
 
-			shader->uniformMatrix4fv(name[MM_MODELVIEW], 1, GL_FALSE, mat.getF32ptr());
-			shader->mMatHash[MM_MODELVIEW] = mMatHash[MM_MODELVIEW];
+            shader->uniformMatrix4fv(name[MM_MODELVIEW], 1, GL_FALSE, mat.getF32ptr());
+            shader->mMatHash[MM_MODELVIEW] = mMatHash[MM_MODELVIEW];
 
-			//update normal matrix
-			S32 loc = shader->getUniformLocation(LLShaderMgr::NORMAL_MATRIX);
-			if (loc > -1)
-			{
-				if (cached_normal_hash != mMatHash[i])
-				{
-					cached_normal = cached_inv_mdv;
-					cached_normal.transpose();
-					cached_normal_hash = mMatHash[i];
-				}
+            //update normal matrix
+            S32 loc = shader->getUniformLocation(LLShaderMgr::NORMAL_MATRIX);
+            if (loc > -1)
+            {
+                if (cached_normal_hash != mMatHash[i])
+                {
+                    cached_normal = cached_inv_mdv;
+                    cached_normal.transpose();
+                    cached_normal_hash = mMatHash[i];
+                }
 
-				const LLMatrix4a& norm = cached_normal;
+                const LLMatrix4a& norm = cached_normal;
 
-				LLVector3 norms[3];
-				norms[0].set(norm.getRow<0>().getF32ptr());
-				norms[1].set(norm.getRow<1>().getF32ptr());
-				norms[2].set(norm.getRow<2>().getF32ptr());
+                LLVector3 norms[3];
+                norms[0].set(norm.getRow<0>().getF32ptr());
+                norms[1].set(norm.getRow<1>().getF32ptr());
+                norms[2].set(norm.getRow<2>().getF32ptr());
 
-				shader->uniformMatrix3fv(LLShaderMgr::NORMAL_MATRIX, 1, GL_FALSE, norms[0].mV);
-			}
+                shader->uniformMatrix3fv(LLShaderMgr::NORMAL_MATRIX, 1, GL_FALSE, norms[0].mV);
+            }
 
             if (shader->getUniformLocation(LLShaderMgr::INVERSE_MODELVIEW_MATRIX))
-            {                
-	            shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, GL_FALSE, cached_inv_mdv.getF32ptr()); 
+            {
+                shader->uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_MATRIX, 1, GL_FALSE, cached_inv_mdv.getF32ptr());
             }
 
-			//update MVP matrix
-			mvp_done = true;
-			loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX);
-			if (loc > -1)
-			{
-				if (cached_mvp_mdv_hash != mMatHash[i] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION])
-				{
-					cached_mvp.setMul(mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]], mat);
-					cached_mvp_mdv_hash = mMatHash[i];
-					cached_mvp_proj_hash = mMatHash[MM_PROJECTION];
-				}
-
-				shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.getF32ptr());
-			}
-		}
-
-		i = MM_PROJECTION;
-		if (mMatHash[MM_PROJECTION] != shader->mMatHash[MM_PROJECTION])
-		{ //update projection matrix, normal, and MVP
-			const LLMatrix4a& mat = mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]];
+            //update MVP matrix
+            mvp_done = true;
+            loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX);
+            if (loc > -1)
+            {
+                if (cached_mvp_mdv_hash != mMatHash[i] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION])
+                {
+                    cached_mvp.setMul(mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]], mat);
+                    cached_mvp_mdv_hash = mMatHash[i];
+                    cached_mvp_proj_hash = mMatHash[MM_PROJECTION];
+                }
+
+                shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.getF32ptr());
+            }
+        }
+
+        i = MM_PROJECTION;
+        if (mMatHash[MM_PROJECTION] != shader->mMatHash[MM_PROJECTION])
+        { //update projection matrix, normal, and MVP
+            const LLMatrix4a& mat = mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]];
 
             // GZ: This was previously disabled seemingly due to a bug involving the deferred renderer's regular pushing and popping of mats.
-			// We're reenabling this and cleaning up the code around that - that would've been the appropriate course initially.
-			// Anything beyond the standard proj and inv proj mats are special cases.  Please setup special uniforms accordingly in the future.
+            // We're reenabling this and cleaning up the code around that - that would've been the appropriate course initially.
+            // Anything beyond the standard proj and inv proj mats are special cases.  Please setup special uniforms accordingly in the future.
             if (shader->getUniformLocation(LLShaderMgr::INVERSE_PROJECTION_MATRIX))
             {
-	            LLMatrix4a inv_proj = mat;
-	            inv_proj.invert();
-	            shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.getF32ptr());
+                LLMatrix4a inv_proj = mat;
+                inv_proj.invert();
+                shader->uniformMatrix4fv(LLShaderMgr::INVERSE_PROJECTION_MATRIX, 1, FALSE, inv_proj.getF32ptr());
             }
 
-			// Used by some full screen effects - such as full screen lights, glow, etc.
+            // Used by some full screen effects - such as full screen lights, glow, etc.
             if (shader->getUniformLocation(LLShaderMgr::IDENTITY_MATRIX))
             {
-				LLMatrix4a identity;
-				identity.setIdentity();
+                LLMatrix4a identity;
+                identity.setIdentity();
                 shader->uniformMatrix4fv(LLShaderMgr::IDENTITY_MATRIX, 1, GL_FALSE, identity.getF32ptr());
             }
 
-			shader->uniformMatrix4fv(name[MM_PROJECTION], 1, GL_FALSE, mat.getF32ptr());
-			shader->mMatHash[MM_PROJECTION] = mMatHash[MM_PROJECTION];
-
-			if (!mvp_done)
-			{
-				//update MVP matrix
-				S32 loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX);
-				if (loc > -1)
-				{
-					if (cached_mvp_mdv_hash != mMatHash[MM_PROJECTION] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION])
-					{
-						cached_mvp.setMul(mat, mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]]);
-						cached_mvp_mdv_hash = mMatHash[MM_MODELVIEW];
-						cached_mvp_proj_hash = mMatHash[MM_PROJECTION];
-					}
-									
-					shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.getF32ptr());
-				}
-			}
-		}
-
-		for (i = MM_TEXTURE0; i < NUM_MATRIX_MODES; ++i)
-		{
-			if (mMatHash[i] != shader->mMatHash[i])
-			{
-				shader->uniformMatrix4fv(name[i], 1, GL_FALSE, mMatrix[i][mMatIdx[i]].getF32ptr());
-				shader->mMatHash[i] = mMatHash[i];
-			}
-		}
-
-
-		if (shader->mFeatures.hasLighting || shader->mFeatures.calculatesLighting || shader->mFeatures.calculatesAtmospherics)
-		{ //also sync light state
-			syncLightState();
-		}
-	}
+            shader->uniformMatrix4fv(name[MM_PROJECTION], 1, GL_FALSE, mat.getF32ptr());
+            shader->mMatHash[MM_PROJECTION] = mMatHash[MM_PROJECTION];
+
+            if (!mvp_done)
+            {
+                //update MVP matrix
+                S32 loc = shader->getUniformLocation(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX);
+                if (loc > -1)
+                {
+                    if (cached_mvp_mdv_hash != mMatHash[MM_PROJECTION] || cached_mvp_proj_hash != mMatHash[MM_PROJECTION])
+                    {
+                        cached_mvp.setMul(mat, mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]]);
+                        cached_mvp_mdv_hash = mMatHash[MM_MODELVIEW];
+                        cached_mvp_proj_hash = mMatHash[MM_PROJECTION];
+                    }
+
+                    shader->uniformMatrix4fv(LLShaderMgr::MODELVIEW_PROJECTION_MATRIX, 1, GL_FALSE, cached_mvp.getF32ptr());
+                }
+            }
+        }
+
+        for (i = MM_TEXTURE0; i < NUM_MATRIX_MODES; ++i)
+        {
+            if (mMatHash[i] != shader->mMatHash[i])
+            {
+                shader->uniformMatrix4fv(name[i], 1, GL_FALSE, mMatrix[i][mMatIdx[i]].getF32ptr());
+                shader->mMatHash[i] = mMatHash[i];
+            }
+        }
+
+
+        if (shader->mFeatures.hasLighting || shader->mFeatures.calculatesLighting || shader->mFeatures.calculatesAtmospherics)
+        { //also sync light state
+            syncLightState();
+        }
+    }
 }
 
 void LLRender::translatef(const GLfloat& x, const GLfloat& y, const GLfloat& z)
 {
-	if(	llabs(x) < F_APPROXIMATELY_ZERO &&
-		llabs(y) < F_APPROXIMATELY_ZERO &&
-		llabs(z) < F_APPROXIMATELY_ZERO)
-	{
-		return;
-	}
+    if( llabs(x) < F_APPROXIMATELY_ZERO &&
+        llabs(y) < F_APPROXIMATELY_ZERO &&
+        llabs(z) < F_APPROXIMATELY_ZERO)
+    {
+        return;
+    }
 
-	flush();
+    flush();
 
-	mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].applyTranslation_affine(x,y,z);
-	mMatHash[mMatrixMode]++;
+    mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].applyTranslation_affine(x,y,z);
+    mMatHash[mMatrixMode]++;
 
 }
 
 void LLRender::scalef(const GLfloat& x, const GLfloat& y, const GLfloat& z)
 {
-	if(	(llabs(x-1.f)) < F_APPROXIMATELY_ZERO &&
-		(llabs(y-1.f)) < F_APPROXIMATELY_ZERO &&
-		(llabs(z-1.f)) < F_APPROXIMATELY_ZERO)
-	{
-		return;
-	}
-	flush();
-	
-	{
-		mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].applyScale_affine(x,y,z);
-		mMatHash[mMatrixMode]++;
-	}
+    if( (llabs(x-1.f)) < F_APPROXIMATELY_ZERO &&
+        (llabs(y-1.f)) < F_APPROXIMATELY_ZERO &&
+        (llabs(z-1.f)) < F_APPROXIMATELY_ZERO)
+    {
+        return;
+    }
+    flush();
+
+    {
+        mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].applyScale_affine(x,y,z);
+        mMatHash[mMatrixMode]++;
+    }
 }
 
 void LLRender::ortho(F32 left, F32 right, F32 bottom, F32 top, F32 zNear, F32 zFar)
 {
-	flush();
-
-	{
-		LLMatrix4a ortho_mat;
-		ortho_mat.setRow<0>(LLVector4a(2.f/(right-left),0,0));
-		ortho_mat.setRow<1>(LLVector4a(0,2.f/(top-bottom),0));
-		ortho_mat.setRow<2>(LLVector4a(0,0,-2.f/(zFar-zNear)));
-		ortho_mat.setRow<3>(LLVector4a(-(right+left)/(right-left),-(top+bottom)/(top-bottom),-(zFar+zNear)/(zFar-zNear),1));	
+    flush();
 
-		mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mul_affine(ortho_mat);
-		mMatHash[mMatrixMode]++;
-	}
+    {
+        LLMatrix4a ortho_mat;
+        ortho_mat.setRow<0>(LLVector4a(2.f/(right-left),0,0));
+        ortho_mat.setRow<1>(LLVector4a(0,2.f/(top-bottom),0));
+        ortho_mat.setRow<2>(LLVector4a(0,0,-2.f/(zFar-zNear)));
+        ortho_mat.setRow<3>(LLVector4a(-(right+left)/(right-left),-(top+bottom)/(top-bottom),-(zFar+zNear)/(zFar-zNear),1));
+
+        mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mul_affine(ortho_mat);
+        mMatHash[mMatrixMode]++;
+    }
 }
 
 void LLRender::rotatef(const LLMatrix4a& rot)
 {
-	flush();
+    flush();
 
-	mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mul_affine(rot);
-	mMatHash[mMatrixMode]++;
+    mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mul_affine(rot);
+    mMatHash[mMatrixMode]++;
 }
 
 void LLRender::rotatef(const GLfloat& a, const GLfloat& x, const GLfloat& y, const GLfloat& z)
 {
-	if(	llabs(a) < F_APPROXIMATELY_ZERO ||
-		llabs(a-360.f) < F_APPROXIMATELY_ZERO)
-	{
-		return;
-	}
-	
-	flush();
+    if( llabs(a) < F_APPROXIMATELY_ZERO ||
+        llabs(a-360.f) < F_APPROXIMATELY_ZERO)
+    {
+        return;
+    }
+
+    flush();
 
-	rotatef(ALGLMath::genRot(a,x,y,z));
+    rotatef(ALGLMath::genRot(a,x,y,z));
 }
 
 void LLRender::pushMatrix()
 {
-	flush();
-	
-	{
-		if (mMatIdx[mMatrixMode] < LL_MATRIX_STACK_DEPTH-1)
-		{
-			mMatrix[mMatrixMode][mMatIdx[mMatrixMode]+1] = mMatrix[mMatrixMode][mMatIdx[mMatrixMode]];
-			++mMatIdx[mMatrixMode];
-		}
-		else
-		{
-			LL_WARNS() << "Matrix stack overflow." << LL_ENDL;
-		}
-	}
+    flush();
+
+    {
+        if (mMatIdx[mMatrixMode] < LL_MATRIX_STACK_DEPTH-1)
+        {
+            mMatrix[mMatrixMode][mMatIdx[mMatrixMode]+1] = mMatrix[mMatrixMode][mMatIdx[mMatrixMode]];
+            ++mMatIdx[mMatrixMode];
+        }
+        else
+        {
+            LL_WARNS() << "Matrix stack overflow." << LL_ENDL;
+        }
+    }
 }
 
 void LLRender::popMatrix()
 {
-	{
-		if (mMatIdx[mMatrixMode] > 0)
-		{
-			if ( memcmp(mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].getF32ptr(), mMatrix[mMatrixMode][mMatIdx[mMatrixMode] - 1].getF32ptr(), sizeof(LLMatrix4a)) )
-			{
-				flush();
-			}
-			--mMatIdx[mMatrixMode];
-			mMatHash[mMatrixMode]++;
-		}
-		else
-		{
-			flush();
-			LL_WARNS() << "Matrix stack underflow." << LL_ENDL;
-		}
-	}
+    {
+        if (mMatIdx[mMatrixMode] > 0)
+        {
+            if ( memcmp(mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].getF32ptr(), mMatrix[mMatrixMode][mMatIdx[mMatrixMode] - 1].getF32ptr(), sizeof(LLMatrix4a)) )
+            {
+                flush();
+            }
+            --mMatIdx[mMatrixMode];
+            mMatHash[mMatrixMode]++;
+        }
+        else
+        {
+            flush();
+            LL_WARNS() << "Matrix stack underflow." << LL_ENDL;
+        }
+    }
 }
 
 void LLRender::loadMatrix(const LLMatrix4a& mat)
 {
-	flush();
-	{
-		mMatrix[mMatrixMode][mMatIdx[mMatrixMode]] = mat;
-		mMatHash[mMatrixMode]++;
-	}
+    flush();
+    {
+        mMatrix[mMatrixMode][mMatIdx[mMatrixMode]] = mat;
+        mMatHash[mMatrixMode]++;
+    }
 }
 
 void LLRender::loadMatrix(const F32* mat)
 {
-	flush();
-	{
-		mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].loadu(mat);
-		mMatHash[mMatrixMode]++;
-	}
+    flush();
+    {
+        mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].loadu(mat);
+        mMatHash[mMatrixMode]++;
+    }
 }
 
 void LLRender::multMatrix(const LLMatrix4a& mat)
 {
-	flush();
-	{
-		mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mul_affine(mat); 
-		mMatHash[mMatrixMode]++;
-	}
+    flush();
+    {
+        mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].mul_affine(mat);
+        mMatHash[mMatrixMode]++;
+    }
 }
 
 void LLRender::matrixMode(eMatrixMode mode)
 {
-	if (mode == MM_TEXTURE)
-	{
+    if (mode == MM_TEXTURE)
+    {
         U32 tex_index = gGL.getCurrentTexUnitIndex();
         // the shaders don't actually reference anything beyond texture_matrix0/1 outside of terrain rendering
         llassert(tex_index <= 3);
@@ -1285,392 +1285,392 @@ void LLRender::matrixMode(eMatrixMode mode)
             LL_WARNS_ONCE() << "Attempted to assign matrix mode out of bounds: " << mode << LL_ENDL;
             mode = MM_TEXTURE0;
         }
-	}
+    }
 
-	mMatrixMode = mode;
+    mMatrixMode = mode;
 }
 
 LLRender::eMatrixMode LLRender::getMatrixMode()
 {
-	if (mMatrixMode >= MM_TEXTURE0 && mMatrixMode <= MM_TEXTURE3)
-	{ //always return MM_TEXTURE if current matrix mode points at any texture matrix
-		return MM_TEXTURE;
-	}
+    if (mMatrixMode >= MM_TEXTURE0 && mMatrixMode <= MM_TEXTURE3)
+    { //always return MM_TEXTURE if current matrix mode points at any texture matrix
+        return MM_TEXTURE;
+    }
 
-	return mMatrixMode;
+    return mMatrixMode;
 }
 
 
 void LLRender::loadIdentity()
 {
-	flush();
+    flush();
 
-	{
-		llassert_always(mMatrixMode < NUM_MATRIX_MODES) ;
+    {
+        llassert_always(mMatrixMode < NUM_MATRIX_MODES) ;
 
-		mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].setIdentity();
-		mMatHash[mMatrixMode]++;
-	}
+        mMatrix[mMatrixMode][mMatIdx[mMatrixMode]].setIdentity();
+        mMatHash[mMatrixMode]++;
+    }
 }
 
 const LLMatrix4a& LLRender::getModelviewMatrix()
 {
-	return mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]];
+    return mMatrix[MM_MODELVIEW][mMatIdx[MM_MODELVIEW]];
 }
 
 const LLMatrix4a& LLRender::getProjectionMatrix()
 {
-	return mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]];
+    return mMatrix[MM_PROJECTION][mMatIdx[MM_PROJECTION]];
 }
 
 void LLRender::translateUI(F32 x, F32 y, F32 z)
 {
-	if (mUIOffset.empty())
-	{
-		LL_ERRS() << "Need to push a UI translation frame before offsetting" << LL_ENDL;
-	}
+    if (mUIOffset.empty())
+    {
+        LL_ERRS() << "Need to push a UI translation frame before offsetting" << LL_ENDL;
+    }
 
-	LLVector4a add(x,y,z);
-	mUIOffset.back().add(add);
+    LLVector4a add(x,y,z);
+    mUIOffset.back().add(add);
 }
 
 void LLRender::scaleUI(F32 x, F32 y, F32 z)
 {
-	if (mUIScale.empty())
-	{
-		LL_ERRS() << "Need to push a UI transformation frame before scaling." << LL_ENDL;
-	}
+    if (mUIScale.empty())
+    {
+        LL_ERRS() << "Need to push a UI transformation frame before scaling." << LL_ENDL;
+    }
 
-	LLVector4a scale(x,y,z);
-	mUIScale.back().mul(scale);
+    LLVector4a scale(x,y,z);
+    mUIScale.back().mul(scale);
 }
 
 void LLRender::rotateUI(LLQuaternion& rot)
 {
-	if (mUIRotation.empty())
-	{
-		mUIRotation.push_back(rot);
-	}
-	else
-	{
-		mUIRotation.push_back(mUIRotation.back()*rot);
-	}
+    if (mUIRotation.empty())
+    {
+        mUIRotation.push_back(rot);
+    }
+    else
+    {
+        mUIRotation.push_back(mUIRotation.back()*rot);
+    }
 }
 
 void LLRender::pushUIMatrix()
 {
-	if (mUIOffset.empty())
-	{
-		mUIOffset.emplace_back(LLVector4a::getZero());
-	}
-	else
-	{
-		mUIOffset.push_back(mUIOffset.back());
-	}
-	
-	if (mUIScale.empty())
-	{
-		mUIScale.emplace_back(LLVector4a(1.f));
-	}
-	else
-	{
-		mUIScale.push_back(mUIScale.back());
-	}
-	if (!mUIRotation.empty())
-	{
-		mUIRotation.push_back(mUIRotation.back());
-	}
+    if (mUIOffset.empty())
+    {
+        mUIOffset.emplace_back(LLVector4a::getZero());
+    }
+    else
+    {
+        mUIOffset.push_back(mUIOffset.back());
+    }
+
+    if (mUIScale.empty())
+    {
+        mUIScale.emplace_back(LLVector4a(1.f));
+    }
+    else
+    {
+        mUIScale.push_back(mUIScale.back());
+    }
+    if (!mUIRotation.empty())
+    {
+        mUIRotation.push_back(mUIRotation.back());
+    }
 }
 
 void LLRender::popUIMatrix()
 {
-	if (mUIOffset.empty() || mUIScale.empty())
-	{
-		LL_ERRS() << "UI offset or scale stack blown." << LL_ENDL;
-	}
+    if (mUIOffset.empty() || mUIScale.empty())
+    {
+        LL_ERRS() << "UI offset or scale stack blown." << LL_ENDL;
+    }
 
-	mUIOffset.pop_back();
-	mUIScale.pop_back();
-	if (!mUIRotation.empty())
-	{
-		mUIRotation.pop_back();
-	}
+    mUIOffset.pop_back();
+    mUIScale.pop_back();
+    if (!mUIRotation.empty())
+    {
+        mUIRotation.pop_back();
+    }
 }
 
 LLVector3 LLRender::getUITranslation()
 {
-	if (mUIOffset.empty())
-	{
-		return LLVector3(0,0,0);
-	}
-	return LLVector3(mUIOffset.back().getF32ptr());
+    if (mUIOffset.empty())
+    {
+        return LLVector3(0,0,0);
+    }
+    return LLVector3(mUIOffset.back().getF32ptr());
 }
 
 LLVector3 LLRender::getUIScale()
 {
-	if (mUIScale.empty())
-	{
-		return LLVector3(1,1,1);
-	}
-	return LLVector3(mUIScale.back().getF32ptr());
+    if (mUIScale.empty())
+    {
+        return LLVector3(1,1,1);
+    }
+    return LLVector3(mUIScale.back().getF32ptr());
 }
 
 
 void LLRender::loadUIIdentity()
 {
-	if (mUIOffset.empty() || mUIScale.empty())
-	{
-		LL_ERRS() << "Need to push UI translation frame before clearing offset." << LL_ENDL;
-	}
-	mUIOffset.back().splat(0.f);
-	mUIScale.back().splat(1.f);
-	if (!mUIRotation.empty())
-		mUIRotation.push_back(LLQuaternion());
+    if (mUIOffset.empty() || mUIScale.empty())
+    {
+        LL_ERRS() << "Need to push UI translation frame before clearing offset." << LL_ENDL;
+    }
+    mUIOffset.back().splat(0.f);
+    mUIScale.back().splat(1.f);
+    if (!mUIRotation.empty())
+        mUIRotation.push_back(LLQuaternion());
 }
 
 void LLRender::setColorMask(bool writeColor, bool writeAlpha)
 {
-	setColorMask(writeColor, writeColor, writeColor, writeAlpha);
+    setColorMask(writeColor, writeColor, writeColor, writeAlpha);
 }
 
 void LLRender::setColorMask(bool writeColorR, bool writeColorG, bool writeColorB, bool writeAlpha)
 {
-	flush();
-
-	if (mCurrColorMask[0] != writeColorR ||
-		mCurrColorMask[1] != writeColorG ||
-		mCurrColorMask[2] != writeColorB ||
-		mCurrColorMask[3] != writeAlpha)
-	{
-		mCurrColorMask[0] = writeColorR;
-		mCurrColorMask[1] = writeColorG;
-		mCurrColorMask[2] = writeColorB;
-		mCurrColorMask[3] = writeAlpha;
+    flush();
 
-		glColorMask(writeColorR ? GL_TRUE : GL_FALSE, 
-					writeColorG ? GL_TRUE : GL_FALSE,
-					writeColorB ? GL_TRUE : GL_FALSE,
-					writeAlpha ? GL_TRUE : GL_FALSE);
-	}
+    if (mCurrColorMask[0] != writeColorR ||
+        mCurrColorMask[1] != writeColorG ||
+        mCurrColorMask[2] != writeColorB ||
+        mCurrColorMask[3] != writeAlpha)
+    {
+        mCurrColorMask[0] = writeColorR;
+        mCurrColorMask[1] = writeColorG;
+        mCurrColorMask[2] = writeColorB;
+        mCurrColorMask[3] = writeAlpha;
+
+        glColorMask(writeColorR ? GL_TRUE : GL_FALSE,
+                    writeColorG ? GL_TRUE : GL_FALSE,
+                    writeColorB ? GL_TRUE : GL_FALSE,
+                    writeAlpha ? GL_TRUE : GL_FALSE);
+    }
 }
 
 void LLRender::setSceneBlendType(eBlendType type)
 {
-	switch (type) 
-	{
-		case BT_ALPHA:
-			blendFunc(BF_SOURCE_ALPHA, BF_ONE_MINUS_SOURCE_ALPHA);
-			break;
-		case BT_ADD:
-			blendFunc(BF_ONE, BF_ONE);
-			break;
-		case BT_ADD_WITH_ALPHA:
-			blendFunc(BF_SOURCE_ALPHA, BF_ONE);
-			break;
-		case BT_MULT:
-			blendFunc(BF_DEST_COLOR, BF_ZERO);
-			break;
-		case BT_MULT_ALPHA:
-			blendFunc(BF_DEST_ALPHA, BF_ZERO);
-			break;
-		case BT_MULT_X2:
-			blendFunc(BF_DEST_COLOR, BF_SOURCE_COLOR);
-			break;
-		case BT_REPLACE:
-			blendFunc(BF_ONE, BF_ZERO);
-			break;
-		default:
-			LL_ERRS() << "Unknown Scene Blend Type: " << type << LL_ENDL;
-			break;
-	}
+    switch (type)
+    {
+        case BT_ALPHA:
+            blendFunc(BF_SOURCE_ALPHA, BF_ONE_MINUS_SOURCE_ALPHA);
+            break;
+        case BT_ADD:
+            blendFunc(BF_ONE, BF_ONE);
+            break;
+        case BT_ADD_WITH_ALPHA:
+            blendFunc(BF_SOURCE_ALPHA, BF_ONE);
+            break;
+        case BT_MULT:
+            blendFunc(BF_DEST_COLOR, BF_ZERO);
+            break;
+        case BT_MULT_ALPHA:
+            blendFunc(BF_DEST_ALPHA, BF_ZERO);
+            break;
+        case BT_MULT_X2:
+            blendFunc(BF_DEST_COLOR, BF_SOURCE_COLOR);
+            break;
+        case BT_REPLACE:
+            blendFunc(BF_ONE, BF_ZERO);
+            break;
+        default:
+            LL_ERRS() << "Unknown Scene Blend Type: " << type << LL_ENDL;
+            break;
+    }
 }
 
 void LLRender::blendFunc(eBlendFactor sfactor, eBlendFactor dfactor)
 {
-	llassert(sfactor < BF_UNDEF);
-	llassert(dfactor < BF_UNDEF);
-	if (mCurrBlendColorSFactor != sfactor || mCurrBlendColorDFactor != dfactor ||
-	    mCurrBlendAlphaSFactor != sfactor || mCurrBlendAlphaDFactor != dfactor)
-	{
-		mCurrBlendColorSFactor = sfactor;
-		mCurrBlendAlphaSFactor = sfactor;
-		mCurrBlendColorDFactor = dfactor;
-		mCurrBlendAlphaDFactor = dfactor;
-		flush();
-		glBlendFunc(sGLBlendFactor[sfactor], sGLBlendFactor[dfactor]);
-	}
+    llassert(sfactor < BF_UNDEF);
+    llassert(dfactor < BF_UNDEF);
+    if (mCurrBlendColorSFactor != sfactor || mCurrBlendColorDFactor != dfactor ||
+        mCurrBlendAlphaSFactor != sfactor || mCurrBlendAlphaDFactor != dfactor)
+    {
+        mCurrBlendColorSFactor = sfactor;
+        mCurrBlendAlphaSFactor = sfactor;
+        mCurrBlendColorDFactor = dfactor;
+        mCurrBlendAlphaDFactor = dfactor;
+        flush();
+        glBlendFunc(sGLBlendFactor[sfactor], sGLBlendFactor[dfactor]);
+    }
 }
 
 void LLRender::blendFunc(eBlendFactor color_sfactor, eBlendFactor color_dfactor,
-			 eBlendFactor alpha_sfactor, eBlendFactor alpha_dfactor)
-{
-	llassert(color_sfactor < BF_UNDEF);
-	llassert(color_dfactor < BF_UNDEF);
-	llassert(alpha_sfactor < BF_UNDEF);
-	llassert(alpha_dfactor < BF_UNDEF);
-	
-	if (mCurrBlendColorSFactor != color_sfactor || mCurrBlendColorDFactor != color_dfactor ||
-	    mCurrBlendAlphaSFactor != alpha_sfactor || mCurrBlendAlphaDFactor != alpha_dfactor)
-	{
-		mCurrBlendColorSFactor = color_sfactor;
-		mCurrBlendAlphaSFactor = alpha_sfactor;
-		mCurrBlendColorDFactor = color_dfactor;
-		mCurrBlendAlphaDFactor = alpha_dfactor;
-		flush();
-        
+             eBlendFactor alpha_sfactor, eBlendFactor alpha_dfactor)
+{
+    llassert(color_sfactor < BF_UNDEF);
+    llassert(color_dfactor < BF_UNDEF);
+    llassert(alpha_sfactor < BF_UNDEF);
+    llassert(alpha_dfactor < BF_UNDEF);
+
+    if (mCurrBlendColorSFactor != color_sfactor || mCurrBlendColorDFactor != color_dfactor ||
+        mCurrBlendAlphaSFactor != alpha_sfactor || mCurrBlendAlphaDFactor != alpha_dfactor)
+    {
+        mCurrBlendColorSFactor = color_sfactor;
+        mCurrBlendAlphaSFactor = alpha_sfactor;
+        mCurrBlendColorDFactor = color_dfactor;
+        mCurrBlendAlphaDFactor = alpha_dfactor;
+        flush();
+
         glBlendFuncSeparate(sGLBlendFactor[color_sfactor], sGLBlendFactor[color_dfactor],
                            sGLBlendFactor[alpha_sfactor], sGLBlendFactor[alpha_dfactor]);
-	}
+    }
 }
 
 LLTexUnit* LLRender::getTexUnit(U32 index)
 {
-	if (index < mTexUnits.size())
-	{
-		return &mTexUnits[index];
-	}
-	else 
-	{
+    if (index < mTexUnits.size())
+    {
+        return &mTexUnits[index];
+    }
+    else
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS() << "Non-existing texture unit layer requested: " << index << LL_ENDL;
+        LL_DEBUGS() << "Non-existing texture unit layer requested: " << index << LL_ENDL;
 #endif
-		return &mDummyTexUnit;
-	}
+        return &mDummyTexUnit;
+    }
 }
 
 LLLightState* LLRender::getLight(U32 index)
 {
-	if (index < mLightState.size())
-	{
-		return &mLightState[index];
-	}
-	
-	return NULL;
+    if (index < mLightState.size())
+    {
+        return &mLightState[index];
+    }
+
+    return NULL;
 }
 
 void LLRender::setAmbientLightColor(const LLColor4& color)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE
-	if (color != mAmbientLightColor)
-	{
-		++mLightHash;
-		mAmbientLightColor = color;
-	}
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE
+    if (color != mAmbientLightColor)
+    {
+        ++mLightHash;
+        mAmbientLightColor = color;
+    }
 }
 void LLRender::setLineWidth(F32 line_width)
 {
-	if (LLRender::sGLCoreProfile)
-	{
-		line_width = 1.f;
-	}
-	if (mLineWidth != line_width || mDirty)
-	{
-		if (mMode == LLRender::LINES || mMode == LLRender::LINE_STRIP)
-		{
-			flush();
-		}
-		mLineWidth = line_width;
-		glLineWidth(line_width);
-	}
+    if (LLRender::sGLCoreProfile)
+    {
+        line_width = 1.f;
+    }
+    if (mLineWidth != line_width || mDirty)
+    {
+        if (mMode == LLRender::LINES || mMode == LLRender::LINE_STRIP)
+        {
+            flush();
+        }
+        mLineWidth = line_width;
+        glLineWidth(line_width);
+    }
 }
 
 bool LLRender::verifyTexUnitActive(U32 unitToVerify)
 {
-	if (mCurrTextureUnitIndex == unitToVerify)
-	{
-		return true;
-	}
-	else 
-	{
-		LL_WARNS() << "TexUnit currently active: " << mCurrTextureUnitIndex << " (expecting " << unitToVerify << ")" << LL_ENDL;
-		return false;
-	}
+    if (mCurrTextureUnitIndex == unitToVerify)
+    {
+        return true;
+    }
+    else
+    {
+        LL_WARNS() << "TexUnit currently active: " << mCurrTextureUnitIndex << " (expecting " << unitToVerify << ")" << LL_ENDL;
+        return false;
+    }
 }
 
 void LLRender::clearErrors()
 {
-	while (glGetError())
-	{
-		//loop until no more error flags left
-	}
+    while (glGetError())
+    {
+        //loop until no more error flags left
+    }
 }
 
 void LLRender::begin(const GLuint& mode)
 {
-	if (mode != mMode)
-	{
-		if (mMode == LLRender::LINES ||
-			mMode == LLRender::TRIANGLES ||
-			mMode == LLRender::POINTS ||
-			mMode == LLRender::TRIANGLE_STRIP )
-		{
-			flush();
-		}
-		else if (mCount != 0)
-		{
-			LL_ERRS() << "gGL.begin() called redundantly." << LL_ENDL;
-		}
-		
-		mMode = mode;
-	}
+    if (mode != mMode)
+    {
+        if (mMode == LLRender::LINES ||
+            mMode == LLRender::TRIANGLES ||
+            mMode == LLRender::POINTS ||
+            mMode == LLRender::TRIANGLE_STRIP )
+        {
+            flush();
+        }
+        else if (mCount != 0)
+        {
+            LL_ERRS() << "gGL.begin() called redundantly." << LL_ENDL;
+        }
+
+        mMode = mode;
+    }
 }
 
 void LLRender::end()
-{ 
-	if (mCount == 0)
-	{
-		return;
-		//IMM_ERRS << "GL begin and end called with no vertices specified." << LL_ENDL;
-	}
-
-	if ((mMode != LLRender::LINES &&
-		mMode != LLRender::TRIANGLES &&
-		mMode != LLRender::POINTS &&
-		mMode != LLRender::TRIANGLE_STRIP) ||
-		mCount > 2048)
-	{
-		flush();
-	}
-	else if (mMode == LLRender::TRIANGLE_STRIP)
-	{
-		mPrimitiveReset = true;
-	}
+{
+    if (mCount == 0)
+    {
+        return;
+        //IMM_ERRS << "GL begin and end called with no vertices specified." << LL_ENDL;
+    }
+
+    if ((mMode != LLRender::LINES &&
+        mMode != LLRender::TRIANGLES &&
+        mMode != LLRender::POINTS &&
+        mMode != LLRender::TRIANGLE_STRIP) ||
+        mCount > 2048)
+    {
+        flush();
+    }
+    else if (mMode == LLRender::TRIANGLE_STRIP)
+    {
+        mPrimitiveReset = true;
+    }
 }
 
 void LLRender::flush()
 {
-	if (mCount > 0)
-	{
+    if (mCount > 0)
+    {
         LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
         llassert(LLGLSLShader::sCurBoundShaderPtr != nullptr);
-		if (!mUIOffset.empty())
-		{
-			sUICalls++;
-			sUIVerts += mCount;
-		}
-		
-		//store mCount in a local variable to avoid re-entrance (drawArrays may call flush)
-		U32 count = mCount;
-
-			if (mMode == LLRender::TRIANGLES)
-			{
-				if (mCount%3 != 0)
-				{
-				count -= (mCount % 3);
-				LL_WARNS() << "Incomplete triangle requested." << LL_ENDL;
-				}
-			}
-			
-			if (mMode == LLRender::LINES)
-			{
-				if (mCount%2 != 0)
-				{
-				count -= (mCount % 2);
-				LL_WARNS() << "Incomplete line requested." << LL_ENDL;
-			}
-		}
-
-		mCount = 0;
+        if (!mUIOffset.empty())
+        {
+            sUICalls++;
+            sUIVerts += mCount;
+        }
+
+        //store mCount in a local variable to avoid re-entrance (drawArrays may call flush)
+        U32 count = mCount;
+
+            if (mMode == LLRender::TRIANGLES)
+            {
+                if (mCount%3 != 0)
+                {
+                count -= (mCount % 3);
+                LL_WARNS() << "Incomplete triangle requested." << LL_ENDL;
+                }
+            }
+
+            if (mMode == LLRender::LINES)
+            {
+                if (mCount%2 != 0)
+                {
+                count -= (mCount % 2);
+                LL_WARNS() << "Incomplete line requested." << LL_ENDL;
+            }
+        }
+
+        mCount = 0;
 
         if (mBuffer)
         {
@@ -1694,8 +1694,8 @@ void LLRender::flush()
 
                 hash.finalize();
             }
-            
-            
+
+
             U64 vhash = hash.digest();
 
             // check the VB cache before making a new vertex buffer
@@ -1705,7 +1705,7 @@ void LLRender::flush()
             // Most of our usage of the "immediate mode" style draw calls is actually
             // sending the same geometry over and over again.
             // To leverage this, we maintain a running hash of the vertex stream being
-            // built up before a flush, and then check that hash against a VB 
+            // built up before a flush, and then check that hash against a VB
             // cache just before creating a vertex buffer in VRAM
             auto cache = sVBCache.find(vhash);
 
@@ -1756,7 +1756,7 @@ void LLRender::flush()
                     {
                         if (now - iter->second.touched > 1s)
                         {
-							auto old_iter = iter++;
+                            auto old_iter = iter++;
                             sVBCache.erase(old_iter);
                         }
                         else
@@ -1768,7 +1768,7 @@ void LLRender::flush()
             }
 
             vb->setBuffer();
-			vb->drawArrays(mMode, 0, count);
+            vb->drawArrays(mMode, 0, count);
         }
         else
         {
@@ -1776,423 +1776,423 @@ void LLRender::flush()
             LL_ERRS() << "A flush call from outside main rendering thread" << LL_ENDL;
         }
 
-		
-		mVerticesp[0] = mVerticesp[count];
-		mTexcoordsp[0] = mTexcoordsp[count];
-		mColorsp[0] = mColorsp[count];
-		
-		mCount = 0;
-		mPrimitiveReset = false;
-	}
+
+        mVerticesp[0] = mVerticesp[count];
+        mTexcoordsp[0] = mTexcoordsp[count];
+        mColorsp[0] = mColorsp[count];
+
+        mCount = 0;
+        mPrimitiveReset = false;
+    }
 }
 
 void LLRender::vertex4a(const LLVector4a& vertex)
-{ 
-	//the range of mVerticesp, mColorsp and mTexcoordsp is [0, 4095]
-	if (mCount > 2048)
-	{ //break when buffer gets reasonably full to keep GL command buffers happy and avoid overflow below
-		switch (mMode)
-		{
-			case LLRender::POINTS: flush(); break;
-			case LLRender::TRIANGLES: if (mCount%3==0) flush(); break;
-			case LLRender::LINES: if (mCount%2 == 0) flush(); break;
-			case LLRender::TRIANGLE_STRIP:
-			{
-				LLVector4a vert[] = { mVerticesp[mCount - 2], mVerticesp[mCount - 1], mVerticesp[mCount] };
-				LLColor4U col[] = { mColorsp[mCount - 2], mColorsp[mCount - 1], mColorsp[mCount] };
-				LLVector2 tc[] = { mTexcoordsp[mCount - 2], mTexcoordsp[mCount - 1], mTexcoordsp[mCount] };
-				flush();
-				for (int i = 0; i < LL_ARRAY_SIZE(vert); ++i)
-				{
-					mVerticesp[i] = vert[i];
-					mColorsp[i] = col[i];
-					mTexcoordsp[i] = tc[i];
-				}
-				mCount = 2;
-				break;
-			}
-		}
-	}
-			
-	if (mCount > 4094)
-	{
-	//	LL_WARNS() << "GL immediate mode overflow.  Some geometry not drawn." << LL_ENDL;
-		return;
-	}
-
-	if (mPrimitiveReset && mCount)
-	{
-		// Insert degenerate
-		++mCount;
-		mVerticesp[mCount] = mVerticesp[mCount - 1];
-		mColorsp[mCount] = mColorsp[mCount - 1];
-		mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
-		mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
-		mColorsp[mCount - 1] = mColorsp[mCount - 2];
-		mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
-	}
-
-	if (mUIOffset.empty())
-	{
-		if (!mUIRotation.empty() && mUIRotation.back().isNotIdentity())
-		{
-			LLVector4 vert(vertex.getF32ptr());
-			mVerticesp[mCount].loadua((vert*mUIRotation.back()).mV);
-		}
-		else
-		{
-		mVerticesp[mCount] = vertex;
-		}
-	}
-	else
-	{
-		if (!mUIRotation.empty() && mUIRotation.back().isNotIdentity())
-		{
-			LLVector4 vert(vertex.getF32ptr());
-			vert = vert * mUIRotation.back();
-			LLVector4a postrot_vert;
-			postrot_vert.loadua(vert.mV);
-			mVerticesp[mCount].setAdd(postrot_vert, mUIOffset.back());
-			mVerticesp[mCount].mul(mUIScale.back());
-		}
-		else
-		{
-			mVerticesp[mCount].setAdd(vertex, mUIOffset.back());
-			mVerticesp[mCount].mul(mUIScale.back());
-		}
-	}
-
-	mCount++;
-	mVerticesp[mCount] = mVerticesp[mCount-1];
-	mColorsp[mCount] = mColorsp[mCount-1];
-	mTexcoordsp[mCount] = mTexcoordsp[mCount-1];	
-
-	if (mPrimitiveReset && mCount)
-	{
-		mCount++;
-		mVerticesp[mCount] = mVerticesp[mCount - 1];
-		mColorsp[mCount] = mColorsp[mCount - 1];
-		mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
-	}
-
-	mPrimitiveReset = false;
+{
+    //the range of mVerticesp, mColorsp and mTexcoordsp is [0, 4095]
+    if (mCount > 2048)
+    { //break when buffer gets reasonably full to keep GL command buffers happy and avoid overflow below
+        switch (mMode)
+        {
+            case LLRender::POINTS: flush(); break;
+            case LLRender::TRIANGLES: if (mCount%3==0) flush(); break;
+            case LLRender::LINES: if (mCount%2 == 0) flush(); break;
+            case LLRender::TRIANGLE_STRIP:
+            {
+                LLVector4a vert[] = { mVerticesp[mCount - 2], mVerticesp[mCount - 1], mVerticesp[mCount] };
+                LLColor4U col[] = { mColorsp[mCount - 2], mColorsp[mCount - 1], mColorsp[mCount] };
+                LLVector2 tc[] = { mTexcoordsp[mCount - 2], mTexcoordsp[mCount - 1], mTexcoordsp[mCount] };
+                flush();
+                for (int i = 0; i < LL_ARRAY_SIZE(vert); ++i)
+                {
+                    mVerticesp[i] = vert[i];
+                    mColorsp[i] = col[i];
+                    mTexcoordsp[i] = tc[i];
+                }
+                mCount = 2;
+                break;
+            }
+        }
+    }
+
+    if (mCount > 4094)
+    {
+    //  LL_WARNS() << "GL immediate mode overflow.  Some geometry not drawn." << LL_ENDL;
+        return;
+    }
+
+    if (mPrimitiveReset && mCount)
+    {
+        // Insert degenerate
+        ++mCount;
+        mVerticesp[mCount] = mVerticesp[mCount - 1];
+        mColorsp[mCount] = mColorsp[mCount - 1];
+        mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
+        mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
+        mColorsp[mCount - 1] = mColorsp[mCount - 2];
+        mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
+    }
+
+    if (mUIOffset.empty())
+    {
+        if (!mUIRotation.empty() && mUIRotation.back().isNotIdentity())
+        {
+            LLVector4 vert(vertex.getF32ptr());
+            mVerticesp[mCount].loadua((vert*mUIRotation.back()).mV);
+        }
+        else
+        {
+        mVerticesp[mCount] = vertex;
+        }
+    }
+    else
+    {
+        if (!mUIRotation.empty() && mUIRotation.back().isNotIdentity())
+        {
+            LLVector4 vert(vertex.getF32ptr());
+            vert = vert * mUIRotation.back();
+            LLVector4a postrot_vert;
+            postrot_vert.loadua(vert.mV);
+            mVerticesp[mCount].setAdd(postrot_vert, mUIOffset.back());
+            mVerticesp[mCount].mul(mUIScale.back());
+        }
+        else
+        {
+            mVerticesp[mCount].setAdd(vertex, mUIOffset.back());
+            mVerticesp[mCount].mul(mUIScale.back());
+        }
+    }
+
+    mCount++;
+    mVerticesp[mCount] = mVerticesp[mCount-1];
+    mColorsp[mCount] = mColorsp[mCount-1];
+    mTexcoordsp[mCount] = mTexcoordsp[mCount-1];
+
+    if (mPrimitiveReset && mCount)
+    {
+        mCount++;
+        mVerticesp[mCount] = mVerticesp[mCount - 1];
+        mColorsp[mCount] = mColorsp[mCount - 1];
+        mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
+    }
+
+    mPrimitiveReset = false;
 }
 
 void LLRender::vertexBatchPreTransformed(LLVector4a* verts, S32 vert_count)
 {
-	if (mCount + vert_count > 4094)
-	{
-		//	LL_WARNS() << "GL immediate mode overflow.  Some geometry not drawn." << LL_ENDL;
-		return;
-	}
-
-	{
-		if (mPrimitiveReset && mCount)
-		{
-			// Insert degenerate
-			++mCount;
-			mVerticesp[mCount] = verts[0];
-			mColorsp[mCount] = mColorsp[mCount - 1];
-			mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
-			mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
-			mColorsp[mCount - 1] = mColorsp[mCount - 2];
-			mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
-			++mCount;
-			mColorsp[mCount] = mColorsp[mCount - 1];
-			mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
-		}
-	
-		mVerticesp.copyArray(mCount, verts, vert_count);
-		for (S32 i = 0; i < vert_count; i++)
-		{
-
-			mCount++;
-			mTexcoordsp[mCount] = mTexcoordsp[mCount-1];
-			mColorsp[mCount] = mColorsp[mCount-1];
-		}
-	}
-
-	if( mCount > 0 ) // ND: Guard against crashes if mCount is zero, yes it can happen
-		mVerticesp[mCount] = mVerticesp[mCount-1];
-	mPrimitiveReset = false;
+    if (mCount + vert_count > 4094)
+    {
+        //  LL_WARNS() << "GL immediate mode overflow.  Some geometry not drawn." << LL_ENDL;
+        return;
+    }
+
+    {
+        if (mPrimitiveReset && mCount)
+        {
+            // Insert degenerate
+            ++mCount;
+            mVerticesp[mCount] = verts[0];
+            mColorsp[mCount] = mColorsp[mCount - 1];
+            mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
+            mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
+            mColorsp[mCount - 1] = mColorsp[mCount - 2];
+            mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
+            ++mCount;
+            mColorsp[mCount] = mColorsp[mCount - 1];
+            mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
+        }
+
+        mVerticesp.copyArray(mCount, verts, vert_count);
+        for (S32 i = 0; i < vert_count; i++)
+        {
+
+            mCount++;
+            mTexcoordsp[mCount] = mTexcoordsp[mCount-1];
+            mColorsp[mCount] = mColorsp[mCount-1];
+        }
+    }
+
+    if( mCount > 0 ) // ND: Guard against crashes if mCount is zero, yes it can happen
+        mVerticesp[mCount] = mVerticesp[mCount-1];
+    mPrimitiveReset = false;
 }
 
 void LLRender::vertexBatchPreTransformed(LLVector4a* verts, LLVector2* uvs, S32 vert_count)
 {
-	if (mCount + vert_count > 4094)
-	{
-		//	LL_WARNS() << "GL immediate mode overflow.  Some geometry not drawn." << LL_ENDL;
-		return;
-	}
-
-	{
-		if (mPrimitiveReset && mCount)
-		{
-			// Insert degenerate
-			++mCount;
-			mVerticesp[mCount] = verts[0];
-			mColorsp[mCount] = mColorsp[mCount - 1];
-			mTexcoordsp[mCount] = uvs[0];
-			mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
-			mColorsp[mCount - 1] = mColorsp[mCount - 2];
-			mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
-			++mCount;
-			mColorsp[mCount] = mColorsp[mCount - 1];
-			mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
-		}
-	
-		mVerticesp.copyArray(mCount, verts, vert_count);
-		mTexcoordsp.copyArray(mCount, uvs, vert_count);
-	
-		for (S32 i = 0; i < vert_count; i++)
-		{
-			mCount++;
-			mColorsp[mCount] = mColorsp[mCount-1];
-		}
-	}
-
-	if (mCount > 0)
-	{
-		mVerticesp[mCount] = mVerticesp[mCount - 1];
-		mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
-	}
-
-	mPrimitiveReset = false;
+    if (mCount + vert_count > 4094)
+    {
+        //  LL_WARNS() << "GL immediate mode overflow.  Some geometry not drawn." << LL_ENDL;
+        return;
+    }
+
+    {
+        if (mPrimitiveReset && mCount)
+        {
+            // Insert degenerate
+            ++mCount;
+            mVerticesp[mCount] = verts[0];
+            mColorsp[mCount] = mColorsp[mCount - 1];
+            mTexcoordsp[mCount] = uvs[0];
+            mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
+            mColorsp[mCount - 1] = mColorsp[mCount - 2];
+            mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
+            ++mCount;
+            mColorsp[mCount] = mColorsp[mCount - 1];
+            mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
+        }
+
+        mVerticesp.copyArray(mCount, verts, vert_count);
+        mTexcoordsp.copyArray(mCount, uvs, vert_count);
+
+        for (S32 i = 0; i < vert_count; i++)
+        {
+            mCount++;
+            mColorsp[mCount] = mColorsp[mCount-1];
+        }
+    }
+
+    if (mCount > 0)
+    {
+        mVerticesp[mCount] = mVerticesp[mCount - 1];
+        mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
+    }
+
+    mPrimitiveReset = false;
 }
 
 void LLRender::vertexBatchPreTransformed(LLVector4a* verts, LLVector2* uvs, LLColor4U* colors, S32 vert_count)
 {
-	if (mCount + vert_count > 4094)
-	{
-		//	LL_WARNS() << "GL immediate mode overflow.  Some geometry not drawn." << LL_ENDL;
-		return;
-	}
-
-	{
-		if (mPrimitiveReset && mCount)
-		{
-			// Insert degenerate
-			++mCount;
-			mVerticesp[mCount] = verts[0];
-			mColorsp[mCount] = colors[mCount - 1];
-			mTexcoordsp[mCount] = uvs[0];
-			mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
-			mColorsp[mCount - 1] = mColorsp[mCount - 2];
-			mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
-			++mCount;
-			mColorsp[mCount] = mColorsp[mCount - 1];
-			mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
-		}
-	
-		// Note: Batch copies instead of iterating.
-		mVerticesp.copyArray(mCount, verts, vert_count);
-		mTexcoordsp.copyArray(mCount, uvs, vert_count);
-		mColorsp.copyArray(mCount, colors, vert_count);
-		mCount += vert_count;
-	}
-
-	if (mCount > 0)
-	{
-		mVerticesp[mCount] = mVerticesp[mCount - 1];
-		mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
-		mColorsp[mCount] = mColorsp[mCount - 1];
-	}
-
-	mPrimitiveReset = false;
+    if (mCount + vert_count > 4094)
+    {
+        //  LL_WARNS() << "GL immediate mode overflow.  Some geometry not drawn." << LL_ENDL;
+        return;
+    }
+
+    {
+        if (mPrimitiveReset && mCount)
+        {
+            // Insert degenerate
+            ++mCount;
+            mVerticesp[mCount] = verts[0];
+            mColorsp[mCount] = colors[mCount - 1];
+            mTexcoordsp[mCount] = uvs[0];
+            mVerticesp[mCount - 1] = mVerticesp[mCount - 2];
+            mColorsp[mCount - 1] = mColorsp[mCount - 2];
+            mTexcoordsp[mCount - 1] = mTexcoordsp[mCount - 2];
+            ++mCount;
+            mColorsp[mCount] = mColorsp[mCount - 1];
+            mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
+        }
+
+        // Note: Batch copies instead of iterating.
+        mVerticesp.copyArray(mCount, verts, vert_count);
+        mTexcoordsp.copyArray(mCount, uvs, vert_count);
+        mColorsp.copyArray(mCount, colors, vert_count);
+        mCount += vert_count;
+    }
+
+    if (mCount > 0)
+    {
+        mVerticesp[mCount] = mVerticesp[mCount - 1];
+        mTexcoordsp[mCount] = mTexcoordsp[mCount - 1];
+        mColorsp[mCount] = mColorsp[mCount - 1];
+    }
+
+    mPrimitiveReset = false;
 }
 
 void LLRender::texCoord2f(const GLfloat& x, const GLfloat& y)
-{ 
-	mTexcoordsp[mCount] = LLVector2(x,y);
+{
+    mTexcoordsp[mCount] = LLVector2(x,y);
 }
 
 void LLRender::texCoord2i(const GLint& x, const GLint& y)
-{ 
-	texCoord2f((GLfloat) x, (GLfloat) y);
+{
+    texCoord2f((GLfloat) x, (GLfloat) y);
 }
 
 void LLRender::texCoord2fv(const GLfloat* tc)
-{ 
-	texCoord2f(tc[0], tc[1]);
+{
+    texCoord2f(tc[0], tc[1]);
 }
 
 void LLRender::color4ub(const GLubyte& r, const GLubyte& g, const GLubyte& b, const GLubyte& a)
 {
-	if (!LLGLSLShader::sCurBoundShaderPtr || LLGLSLShader::sCurBoundShaderPtr->mAttributeMask & LLVertexBuffer::MAP_COLOR)
-	{
-		mColorsp[mCount] = LLColor4U(r,g,b,a);
-	}
-	else
-	{ //not using shaders or shader reads color from a uniform
-		diffuseColor4ub(r,g,b,a);
-	}
+    if (!LLGLSLShader::sCurBoundShaderPtr || LLGLSLShader::sCurBoundShaderPtr->mAttributeMask & LLVertexBuffer::MAP_COLOR)
+    {
+        mColorsp[mCount] = LLColor4U(r,g,b,a);
+    }
+    else
+    { //not using shaders or shader reads color from a uniform
+        diffuseColor4ub(r,g,b,a);
+    }
 }
 void LLRender::color4ubv(const GLubyte* c)
 {
-	color4ub(c[0], c[1], c[2], c[3]);
+    color4ub(c[0], c[1], c[2], c[3]);
 }
 
 void LLRender::color4f(const GLfloat& r, const GLfloat& g, const GLfloat& b, const GLfloat& a)
 {
-	color4ub((GLubyte) (llclamp(r, 0.f, 1.f)*255),
-		(GLubyte) (llclamp(g, 0.f, 1.f)*255),
-		(GLubyte) (llclamp(b, 0.f, 1.f)*255),
-		(GLubyte) (llclamp(a, 0.f, 1.f)*255));
+    color4ub((GLubyte) (llclamp(r, 0.f, 1.f)*255),
+        (GLubyte) (llclamp(g, 0.f, 1.f)*255),
+        (GLubyte) (llclamp(b, 0.f, 1.f)*255),
+        (GLubyte) (llclamp(a, 0.f, 1.f)*255));
 }
 
 void LLRender::color4fv(const GLfloat* c)
-{ 
-	color4f(c[0],c[1],c[2],c[3]);
+{
+    color4f(c[0],c[1],c[2],c[3]);
 }
 
 void LLRender::color3f(const GLfloat& r, const GLfloat& g, const GLfloat& b)
-{ 
-	color4f(r,g,b,1);
+{
+    color4f(r,g,b,1);
 }
 
 void LLRender::color3fv(const GLfloat* c)
-{ 
-	color4f(c[0],c[1],c[2],1);
+{
+    color4f(c[0],c[1],c[2],1);
 }
 
 void LLRender::diffuseColor3f(F32 r, F32 g, F32 b)
 {
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-	llassert(shader != NULL);
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+    llassert(shader != NULL);
 
-	if (shader)
-	{
-		shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r,g,b,1.f);
-	}
+    if (shader)
+    {
+        shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r,g,b,1.f);
+    }
 }
 
 void LLRender::diffuseColor3fv(const F32* c)
 {
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-	llassert(shader != NULL);
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+    llassert(shader != NULL);
 
-	if (shader)
-	{
-		shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, c[0], c[1], c[2], 1.f);
-	}
+    if (shader)
+    {
+        shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, c[0], c[1], c[2], 1.f);
+    }
 }
 
 void LLRender::diffuseColor4f(F32 r, F32 g, F32 b, F32 a)
 {
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-	llassert(shader != NULL);
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+    llassert(shader != NULL);
 
-	if (shader)
-	{
-		shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r,g,b,a);
-	}
+    if (shader)
+    {
+        shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r,g,b,a);
+    }
 }
 
 void LLRender::diffuseColor4fv(const F32* c)
 {
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-	llassert(shader != NULL);
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+    llassert(shader != NULL);
 
-	if (shader)
-	{
-		shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, c);
-	}
+    if (shader)
+    {
+        shader->uniform4fv(LLShaderMgr::DIFFUSE_COLOR, 1, c);
+    }
 }
 
 void LLRender::diffuseColor4ubv(const U8* c)
 {
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-	llassert(shader != NULL);
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+    llassert(shader != NULL);
 
-	if (shader)
-	{
-		shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, c[0]/255.f, c[1]/255.f, c[2]/255.f, c[3]/255.f);
-	}
+    if (shader)
+    {
+        shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, c[0]/255.f, c[1]/255.f, c[2]/255.f, c[3]/255.f);
+    }
 }
 
 void LLRender::diffuseColor4ub(U8 r, U8 g, U8 b, U8 a)
 {
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-	llassert(shader != NULL);
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+    llassert(shader != NULL);
 
-	if (shader)
-	{
-		shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r/255.f, g/255.f, b/255.f, a/255.f);
-	}
+    if (shader)
+    {
+        shader->uniform4f(LLShaderMgr::DIFFUSE_COLOR, r/255.f, g/255.f, b/255.f, a/255.f);
+    }
 }
 
 
 void LLRender::debugTexUnits(void)
 {
-	LL_INFOS("TextureUnit") << "Active TexUnit: " << mCurrTextureUnitIndex << LL_ENDL;
-	std::string active_enabled = "false";
-	for (U32 i = 0; i < mTexUnits.size(); i++)
-	{
-		if (getTexUnit(i)->mCurrTexType != LLTexUnit::TT_NONE)
-		{
-			if (i == mCurrTextureUnitIndex) active_enabled = "true";
-			LL_INFOS("TextureUnit") << "TexUnit: " << i << " Enabled" << LL_ENDL;
-			LL_INFOS("TextureUnit") << "Enabled As: " ;
-			switch (getTexUnit(i)->mCurrTexType)
-			{
-				case LLTexUnit::TT_TEXTURE:
-					LL_CONT << "Texture 2D";
-					break;
-				case LLTexUnit::TT_RECT_TEXTURE:
-					LL_CONT << "Texture Rectangle";
-					break;
-				case LLTexUnit::TT_CUBE_MAP:
-					LL_CONT << "Cube Map";
-					break;
-				case LLTexUnit::TT_TEXTURE_3D:
-					LL_CONT << "Texture 3D";
-					break;
-				default:
-					LL_CONT << "ARGH!!! NONE!";
-					break;
-			}
-			LL_CONT << ", Texture Bound: " << getTexUnit(i)->mCurrTexture << LL_ENDL;
-		}
-	}
-	LL_INFOS("TextureUnit") << "Active TexUnit Enabled : " << active_enabled << LL_ENDL;
+    LL_INFOS("TextureUnit") << "Active TexUnit: " << mCurrTextureUnitIndex << LL_ENDL;
+    std::string active_enabled = "false";
+    for (U32 i = 0; i < mTexUnits.size(); i++)
+    {
+        if (getTexUnit(i)->mCurrTexType != LLTexUnit::TT_NONE)
+        {
+            if (i == mCurrTextureUnitIndex) active_enabled = "true";
+            LL_INFOS("TextureUnit") << "TexUnit: " << i << " Enabled" << LL_ENDL;
+            LL_INFOS("TextureUnit") << "Enabled As: " ;
+            switch (getTexUnit(i)->mCurrTexType)
+            {
+                case LLTexUnit::TT_TEXTURE:
+                    LL_CONT << "Texture 2D";
+                    break;
+                case LLTexUnit::TT_RECT_TEXTURE:
+                    LL_CONT << "Texture Rectangle";
+                    break;
+                case LLTexUnit::TT_CUBE_MAP:
+                    LL_CONT << "Cube Map";
+                    break;
+                case LLTexUnit::TT_TEXTURE_3D:
+                    LL_CONT << "Texture 3D";
+                    break;
+                default:
+                    LL_CONT << "ARGH!!! NONE!";
+                    break;
+            }
+            LL_CONT << ", Texture Bound: " << getTexUnit(i)->mCurrTexture << LL_ENDL;
+        }
+    }
+    LL_INFOS("TextureUnit") << "Active TexUnit Enabled : " << active_enabled << LL_ENDL;
 }
 
 const LLMatrix4a& get_current_modelview()
 {
-	return gGLModelView;
+    return gGLModelView;
 }
 
 const LLMatrix4a& get_current_projection()
 {
-	return gGLProjection;
+    return gGLProjection;
 }
 
 const LLMatrix4a& get_last_modelview()
 {
-	return gGLLastModelView;
+    return gGLLastModelView;
 }
 
 const LLMatrix4a& get_last_projection()
 {
-	return gGLLastProjection;
+    return gGLLastProjection;
 }
 
 void set_current_modelview(const LLMatrix4a& mat)
 {
-	gGLModelView = mat;
+    gGLModelView = mat;
 }
 
 void set_current_projection(const LLMatrix4a& mat)
 {
-	gGLProjection = mat;
+    gGLProjection = mat;
 }
 
 void set_last_modelview(const LLMatrix4a& mat)
 {
-	gGLLastModelView = mat;
+    gGLLastModelView = mat;
 }
 
 void set_last_projection(const LLMatrix4a& mat)
 {
-	gGLLastProjection = mat;
+    gGLLastProjection = mat;
 }
diff --git a/indra/llrender/llshadermgr.cpp b/indra/llrender/llshadermgr.cpp
index 1159f35e51cad2c8bf038c1f7b1a1b5977d30d28..b53ab6502efc3cc76176341b9fee8eed0c3944ce 100644
--- a/indra/llrender/llshadermgr.cpp
+++ b/indra/llrender/llshadermgr.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llshadermgr.cpp
  * @brief Shader manager implementation.
  *
  * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -44,90 +44,90 @@ bool LLShaderMgr::sMirrorsEnabled = false;
 // static
 LLShaderMgr * LLShaderMgr::instance()
 {
-	if(NULL == sInstance)
-	{
-		LL_ERRS("Shaders") << "LLShaderMgr should already have been instantiated by the application!" << LL_ENDL;
-	}
+    if(NULL == sInstance)
+    {
+        LL_ERRS("Shaders") << "LLShaderMgr should already have been instantiated by the application!" << LL_ENDL;
+    }
 
-	return sInstance;
+    return sInstance;
 }
 
 BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
 {
-	llassert_always(shader != NULL);
-	LLShaderFeatures *features = & shader->mFeatures;
-
-	if (features->attachNothing)
-	{
-		return TRUE;
-	}
-	//////////////////////////////////////
-	// Attach Vertex Shader Features First
-	//////////////////////////////////////
-	
-	// NOTE order of shader object attaching is VERY IMPORTANT!!!
-	if (features->calculatesAtmospherics)
-	{
-		if (!shader->attachVertexObject("windlight/atmosphericsVarsV.glsl"))
-		{
-			return FALSE;
-		}
-	}
-
-	if (features->calculatesLighting || features->calculatesAtmospherics)
-	{
-		if (!shader->attachVertexObject("windlight/atmosphericsHelpersV.glsl"))
-		{
-			return FALSE;
-		}
-	}
-		
-	if (features->calculatesLighting)
-	{
-		if (features->isSpecular)
-		{
+    llassert_always(shader != NULL);
+    LLShaderFeatures *features = & shader->mFeatures;
+
+    if (features->attachNothing)
+    {
+        return TRUE;
+    }
+    //////////////////////////////////////
+    // Attach Vertex Shader Features First
+    //////////////////////////////////////
+
+    // NOTE order of shader object attaching is VERY IMPORTANT!!!
+    if (features->calculatesAtmospherics)
+    {
+        if (!shader->attachVertexObject("windlight/atmosphericsVarsV.glsl"))
+        {
+            return FALSE;
+        }
+    }
+
+    if (features->calculatesLighting || features->calculatesAtmospherics)
+    {
+        if (!shader->attachVertexObject("windlight/atmosphericsHelpersV.glsl"))
+        {
+            return FALSE;
+        }
+    }
+
+    if (features->calculatesLighting)
+    {
+        if (features->isSpecular)
+        {
             if (!shader->attachVertexObject("lighting/lightFuncSpecularV.glsl"))
-			{
-				return FALSE;
-			}
-		
-			if (!features->isAlphaLighting)
-			{
+            {
+                return FALSE;
+            }
+
+            if (!features->isAlphaLighting)
+            {
                 if (!shader->attachVertexObject("lighting/sumLightsSpecularV.glsl"))
-				{
-					return FALSE;
-				}
-			}
-			
+                {
+                    return FALSE;
+                }
+            }
+
             if (!shader->attachVertexObject("lighting/lightSpecularV.glsl"))
-			{
-				return FALSE;
-			}
-		}
-		else 
-		{
+            {
+                return FALSE;
+            }
+        }
+        else
+        {
             if (!shader->attachVertexObject("lighting/lightFuncV.glsl"))
-			{
-				return FALSE;
-			}
-			
-			if (!features->isAlphaLighting)
-			{
+            {
+                return FALSE;
+            }
+
+            if (!features->isAlphaLighting)
+            {
                 if (!shader->attachVertexObject("lighting/sumLightsV.glsl"))
-				{
-					return FALSE;
-				}
-			}
-			
+                {
+                    return FALSE;
+                }
+            }
+
             if (!shader->attachVertexObject("lighting/lightV.glsl"))
-			{
-				return FALSE;
-			}
-		}
-	}
-	
-	// NOTE order of shader object attaching is VERY IMPORTANT!!!
-	if (features->calculatesAtmospherics)
+            {
+                return FALSE;
+            }
+        }
+    }
+
+    // NOTE order of shader object attaching is VERY IMPORTANT!!!
+    if (features->calculatesAtmospherics)
     {
         if (!shader->attachVertexObject("environment/srgbF.glsl")) // NOTE -- "F" suffix is superfluous here, there is nothing fragment specific in srgbF
         {
@@ -139,39 +139,39 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
         }
 
         if (!shader->attachVertexObject("windlight/atmosphericsV.glsl"))
-		{
-			return FALSE;
-		}
-	}
+        {
+            return FALSE;
+        }
+    }
 
-	if (features->hasSkinning)
-	{
+    if (features->hasSkinning)
+    {
         if (!shader->attachVertexObject("avatar/avatarSkinV.glsl"))
-		{
-			return FALSE;
-		}
-	}
+        {
+            return FALSE;
+        }
+    }
 
-	if (features->hasObjectSkinning)
-	{
+    if (features->hasObjectSkinning)
+    {
         shader->mRiggedVariant = shader;
         if (!shader->attachVertexObject("avatar/objectSkinV.glsl"))
-		{
-			return FALSE;
-		}
-	}
+        {
+            return FALSE;
+        }
+    }
 
     if (!shader->attachVertexObject("deferred/textureUtilV.glsl"))
     {
         return FALSE;
     }
-	
-	///////////////////////////////////////
-	// Attach Fragment Shader Features Next
-	///////////////////////////////////////
+
+    ///////////////////////////////////////
+    // Attach Fragment Shader Features Next
+    ///////////////////////////////////////
 
     // NOTE order of shader object attaching is VERY IMPORTANT!!!
-    
+
     if (!shader->attachFragmentObject("deferred/globalF.glsl"))
     {
         return FALSE;
@@ -185,46 +185,46 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
         }
     }
 
-	if(features->calculatesAtmospherics || features->hasGamma || features->isDeferred)
-	{
-		if (!shader->attachFragmentObject("windlight/atmosphericsVarsF.glsl"))
-		{
-			return FALSE;
-		}
-	}
+    if(features->calculatesAtmospherics || features->hasGamma || features->isDeferred)
+    {
+        if (!shader->attachFragmentObject("windlight/atmosphericsVarsF.glsl"))
+        {
+            return FALSE;
+        }
+    }
 
     if (features->calculatesLighting || features->calculatesAtmospherics)
-	{
+    {
         if (!shader->attachFragmentObject("windlight/atmosphericsHelpersF.glsl"))
-		{
-			return FALSE;
-		}
-	}
+        {
+            return FALSE;
+        }
+    }
 
     // we want this BEFORE shadows and AO because those facilities use pos/norm access
     if (features->isDeferred || features->hasReflectionProbes)
-	{
+    {
         if (!shader->attachFragmentObject("deferred/deferredUtil.glsl"))
-		{
-			return FALSE;
-		}
-	}
+        {
+            return FALSE;
+        }
+    }
 
-	if (features->hasScreenSpaceReflections || features->hasReflectionProbes)
-	{
+    if (features->hasScreenSpaceReflections || features->hasReflectionProbes)
+    {
         if (!shader->attachFragmentObject("deferred/screenSpaceReflUtil.glsl"))
         {
             return FALSE;
         }
-	}
+    }
 
     if (features->hasShadows)
-	{
+    {
         if (!shader->attachFragmentObject("deferred/shadowUtil.glsl"))
-		{
-			return FALSE;
-		}
-	}
+        {
+            return FALSE;
+        }
+    }
 
     if (features->hasReflectionProbes)
     {
@@ -235,33 +235,33 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
     }
 
     if (features->hasAmbientOcclusion)
-	{
+    {
         if (!shader->attachFragmentObject("deferred/aoUtil.glsl"))
-		{
-			return FALSE;
-		}
-	}
+        {
+            return FALSE;
+        }
+    }
 
-	if (features->hasGamma || features->isDeferred)
-	{
+    if (features->hasGamma || features->isDeferred)
+    {
         if (!shader->attachFragmentObject("windlight/gammaF.glsl"))
-		{
-			return FALSE;
-		}
-	}
+        {
+            return FALSE;
+        }
+    }
 
-	if (features->hasAtmospherics || features->isDeferred)
+    if (features->hasAtmospherics || features->isDeferred)
     {
         if (!shader->attachFragmentObject("windlight/atmosphericsFuncs.glsl")) {
             return FALSE;
         }
 
         if (!shader->attachFragmentObject("windlight/atmosphericsF.glsl"))
-		{
-			return FALSE;
-		}
-	}
-	
+        {
+            return FALSE;
+        }
+    }
+
     if (features->isPBRTerrain)
     {
         if (!shader->attachFragmentObject("deferred/pbrterrainUtilF.glsl"))
@@ -269,71 +269,71 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
             return FALSE;
         }
     }
-	
-	// NOTE order of shader object attaching is VERY IMPORTANT!!!
-	if (features->hasAtmospherics)
-	{
+
+    // NOTE order of shader object attaching is VERY IMPORTANT!!!
+    if (features->hasAtmospherics)
+    {
         if (!shader->attachFragmentObject("environment/waterFogF.glsl"))
-		{
-			return FALSE;
-		}
-	}
-	
-	if (features->hasLighting)
-	{
-		if (features->disableTextureIndex)
-		{
-			if (features->hasAlphaMask)
-			{
+        {
+            return FALSE;
+        }
+    }
+
+    if (features->hasLighting)
+    {
+        if (features->disableTextureIndex)
+        {
+            if (features->hasAlphaMask)
+            {
                 if (!shader->attachFragmentObject("lighting/lightAlphaMaskNonIndexedF.glsl"))
-				{
-					return FALSE;
-				}
-			}
-			else
-			{
+                {
+                    return FALSE;
+                }
+            }
+            else
+            {
                 if (!shader->attachFragmentObject("lighting/lightNonIndexedF.glsl"))
-				{
-					return FALSE;
-				}
-			}
-		}
-		else 
-		{
-			if (features->hasAlphaMask)
-			{
+                {
+                    return FALSE;
+                }
+            }
+        }
+        else
+        {
+            if (features->hasAlphaMask)
+            {
                 if (!shader->attachFragmentObject("lighting/lightAlphaMaskF.glsl"))
-				{
-					return FALSE;
-				}
-			}
-			else
-			{
+                {
+                    return FALSE;
+                }
+            }
+            else
+            {
                 if (!shader->attachFragmentObject("lighting/lightF.glsl"))
-				{
-					return FALSE;
-				}
-			}
-			shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels, 1);
-		}
-	}
-	
-	if (features->mIndexedTextureChannels <= 1)
-	{
-		if (!shader->attachVertexObject("objects/nonindexedTextureV.glsl"))
-		{
-			return FALSE;
-		}
-	}
-	else
-	{
+                {
+                    return FALSE;
+                }
+            }
+            shader->mFeatures.mIndexedTextureChannels = llmax(LLGLSLShader::sIndexedTextureChannels, 1);
+        }
+    }
+
+    if (features->mIndexedTextureChannels <= 1)
+    {
+        if (!shader->attachVertexObject("objects/nonindexedTextureV.glsl"))
+        {
+            return FALSE;
+        }
+    }
+    else
+    {
         if (!shader->attachVertexObject("objects/indexedTextureV.glsl"))
-		{
-			return FALSE;
-		}
-	}
+        {
+            return FALSE;
+        }
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 //============================================================================
@@ -341,20 +341,20 @@ BOOL LLShaderMgr::attachShaderFeatures(LLGLSLShader * shader)
 
 static std::string get_shader_log(GLuint ret)
 {
-	std::string res;
-	
-	//get log length 
-	GLint length;
+    std::string res;
+
+    //get log length
+    GLint length;
     glGetShaderiv(ret, GL_INFO_LOG_LENGTH, &length);
-	if (length > 0)
-	{
-		//the log could be any size, so allocate appropriately
-		GLchar* log = new GLchar[length];
+    if (length > 0)
+    {
+        //the log could be any size, so allocate appropriately
+        GLchar* log = new GLchar[length];
         glGetShaderInfoLog(ret, length, &length, log);
-		res = std::string((char *)log);
-		delete[] log;
-	}
-	return res;
+        res = std::string((char *)log);
+        delete[] log;
+    }
+    return res;
 }
 
 static std::string get_program_log(GLuint ret)
@@ -362,7 +362,7 @@ static std::string get_program_log(GLuint ret)
     LL_PROFILE_ZONE_SCOPED_CATEGORY_SHADER;
     std::string res;
 
-    //get log length 
+    //get log length
     GLint length;
     glGetProgramiv(ret, GL_INFO_LOG_LENGTH, &length);
     if (length > 0)
@@ -394,16 +394,16 @@ static std::string get_object_log(GLuint ret)
 //dump shader source for debugging
 void LLShaderMgr::dumpShaderSource(U32 shader_code_count, GLchar** shader_code_text)
 {
-	char num_str[16]; // U32 = max 10 digits
+    char num_str[16]; // U32 = max 10 digits
 
-	LL_SHADER_LOADING_WARNS() << "\n";
+    LL_SHADER_LOADING_WARNS() << "\n";
 
-	for (U32 i = 0; i < shader_code_count; i++)
-	{
-		snprintf(num_str, sizeof(num_str), "%4d: ", i+1);
-		std::string line_number(num_str);
-		LL_CONT << line_number << shader_code_text[i];
-	}
+    for (U32 i = 0; i < shader_code_count; i++)
+    {
+        snprintf(num_str, sizeof(num_str), "%4d: ", i+1);
+        std::string line_number(num_str);
+        LL_CONT << line_number << shader_code_text[i];
+    }
     LL_CONT << LL_ENDL;
 }
 
@@ -417,34 +417,34 @@ void LLShaderMgr::dumpObjectLog(GLuint ret, BOOL warns, const std::string& filen
         fname = "unknown shader file";
     }
 
-	if (log.length() > 0)
-	{
+    if (log.length() > 0)
+    {
         LL_SHADER_LOADING_WARNS() << "Shader loading from " << fname << LL_ENDL;
         LL_SHADER_LOADING_WARNS() << "\n" << log << LL_ENDL;
-	}
+    }
  }
 
 GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, std::map<std::string, std::string>* defines, S32 texture_index_channels)
 {
-	GLenum error = GL_NO_ERROR;
+    GLenum error = GL_NO_ERROR;
 
-	error = glGetError();
-	if (error != GL_NO_ERROR)
-	{
-		LL_SHADER_LOADING_WARNS() << "GL ERROR entering loadShaderFile(): " << error << " for file: " << filename << LL_ENDL;
-	}
-	
-	if (filename.empty()) 
-	{
-		return 0;
-	}
+    error = glGetError();
+    if (error != GL_NO_ERROR)
+    {
+        LL_SHADER_LOADING_WARNS() << "GL ERROR entering loadShaderFile(): " << error << " for file: " << filename << LL_ENDL;
+    }
+
+    if (filename.empty())
+    {
+        return 0;
+    }
 
 
-	//read in from file
-	LLFILE* file = NULL;
+    //read in from file
+    LLFILE* file = NULL;
 
-	S32 try_gpu_class = shader_level;
-	S32 gpu_class;
+    S32 try_gpu_class = shader_level;
+    S32 gpu_class;
 
     std::string open_file_name;
 
@@ -469,7 +469,7 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
     {
         //find the most relevant file
         for (gpu_class = try_gpu_class; gpu_class > 0; gpu_class--)
-        {	//search from the current gpu class down to class 1 to find the most relevant shader
+        {   //search from the current gpu class down to class 1 to find the most relevant shader
             std::stringstream fname;
             fname << getShaderDirPrefix();
             fname << gpu_class << "/" << filename;
@@ -490,7 +490,7 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
             */
 
             LL_DEBUGS("ShaderLoading") << "Looking in " << open_file_name << LL_ENDL;
-            file = LLFile::fopen(open_file_name, "r");		/* Flawfinder: ignore */
+            file = LLFile::fopen(open_file_name, "r");      /* Flawfinder: ignore */
             if (file)
             {
                 LL_DEBUGS("ShaderLoading") << "Loading file: " << open_file_name << " (Want class " << gpu_class << ")" << LL_ENDL;
@@ -498,31 +498,31 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
             }
         }
     }
-	
-	if (file == NULL)
-	{
-		LL_WARNS("ShaderLoading") << "GLSL Shader file not found: " << open_file_name << LL_ENDL;
-		return 0;
-	}
 
-	//we can't have any lines longer than 1024 characters 
-	//or any shaders longer than 4096 lines... deal - DaveP
+    if (file == NULL)
+    {
+        LL_WARNS("ShaderLoading") << "GLSL Shader file not found: " << open_file_name << LL_ENDL;
+        return 0;
+    }
+
+    //we can't have any lines longer than 1024 characters
+    //or any shaders longer than 4096 lines... deal - DaveP
     GLchar buff[1024];
     GLchar *extra_code_text[1024];
     GLchar *shader_code_text[4096 + LL_ARRAY_SIZE(extra_code_text)] = { NULL };
     GLuint extra_code_count = 0, shader_code_count = 0;
     BOOST_STATIC_ASSERT(LL_ARRAY_SIZE(extra_code_text) < LL_ARRAY_SIZE(shader_code_text));
-    
-    
-	S32 major_version = gGLManager.mGLSLVersionMajor;
-	S32 minor_version = gGLManager.mGLSLVersionMinor;
-	
-	if (major_version == 1 && minor_version < 30)
-	{
+
+
+    S32 major_version = gGLManager.mGLSLVersionMajor;
+    S32 minor_version = gGLManager.mGLSLVersionMinor;
+
+    if (major_version == 1 && minor_version < 30)
+    {
         llassert(false); // GL 3.1 or later required
-	}
-	else
-	{  
+    }
+    else
+    {
         if (major_version >= 4)
         {
             //set versions 400 through 460
@@ -558,24 +558,24 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
         else if (major_version == 3)
         {
             if (minor_version < 10)
-		    {
-			    shader_code_text[shader_code_count++] = strdup("#version 300\n");
-		    }
-		    else if (minor_version <= 19)
-		    {
-			    shader_code_text[shader_code_count++] = strdup("#version 310\n");
-		    }
-		    else if (minor_version <= 29)
-		    {
-			    shader_code_text[shader_code_count++] = strdup("#version 320\n");
-		    }
+            {
+                shader_code_text[shader_code_count++] = strdup("#version 300\n");
+            }
+            else if (minor_version <= 19)
+            {
+                shader_code_text[shader_code_count++] = strdup("#version 310\n");
+            }
+            else if (minor_version <= 29)
+            {
+                shader_code_text[shader_code_count++] = strdup("#version 320\n");
+            }
             else
             {
                 shader_code_text[shader_code_count++] = strdup("#version 330\n");
             }
         }
-		else
-		{
+        else
+        {
             if (type == GL_GEOMETRY_SHADER)
             {
                 //set version to 1.50
@@ -592,10 +592,10 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
                 extra_code_text[extra_code_count++] = strdup("precision mediump int;\n");
                 extra_code_text[extra_code_count++] = strdup("precision highp float;\n");
             }
-		}
-	}
+        }
+    }
 
-	if (type == GL_FRAGMENT_SHADER)
+    if (type == GL_FRAGMENT_SHADER)
     {
         extra_code_text[extra_code_count++] = strdup("#define FRAGMENT_SHADER 1\n");
     }
@@ -617,120 +617,120 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
     extra_code_text[extra_code_count++] = strdup("#define GBUFFER_FLAG_HAS_HDRI      1.0\n");  // bit 2
     extra_code_text[extra_code_count++] = strdup("#define GET_GBUFFER_FLAG(flag)    (abs(norm.w-flag)< 0.1)\n");
 
-	if (defines)
-	{
-		for (auto iter = defines->begin(); iter != defines->end(); ++iter)
-		{
-			std::string define = "#define " + iter->first + " " + iter->second + "\n";
-			extra_code_text[extra_code_count++] = (GLchar *) strdup(define.c_str());
-		}
-	}
-
-	if (texture_index_channels > 0 && type == GL_FRAGMENT_SHADER)
-	{
-		//use specified number of texture channels for indexed texture rendering
-
-		/* prepend shader code that looks like this:
-
-		uniform sampler2D tex0;
-		uniform sampler2D tex1;
-		uniform sampler2D tex2;
-		.
-		.
-		.
-		uniform sampler2D texN;
-		
-		flat in int vary_texture_index;
-
-		vec4 ret = vec4(1,0,1,1);
-
-		vec4 diffuseLookup(vec2 texcoord)
-		{
-			switch (vary_texture_index)
-			{
-				case 0: ret = texture(tex0, texcoord); break;
-				case 1: ret = texture(tex1, texcoord); break;
-				case 2: ret = texture(tex2, texcoord); break;
-				.
-				.
-				.
-				case N: return texture(texN, texcoord); break;
-			}
-
-			return ret;
-		}
-		*/
-
-		extra_code_text[extra_code_count++] = strdup("#define HAS_DIFFUSE_LOOKUP\n");
-
-		//uniform declartion
-		for (S32 i = 0; i < texture_index_channels; ++i)
-		{
-			std::string decl = llformat("uniform sampler2D tex%d;\n", i);
-			extra_code_text[extra_code_count++] = strdup(decl.c_str());
-		}
-
-		if (texture_index_channels > 1)
-		{
-			extra_code_text[extra_code_count++] = strdup("flat in int vary_texture_index;\n");
-		}
-
-		extra_code_text[extra_code_count++] = strdup("vec4 diffuseLookup(vec2 texcoord)\n");
-		extra_code_text[extra_code_count++] = strdup("{\n");
-		
-		
-		if (texture_index_channels == 1)
-		{ //don't use flow control, that's silly
-			extra_code_text[extra_code_count++] = strdup("return texture(tex0, texcoord);\n");
-			extra_code_text[extra_code_count++] = strdup("}\n");
-		}
-		else if (major_version > 1 || minor_version >= 30)
-		{  //switches are supported in GLSL 1.30 and later
-			if (gGLManager.mIsNVIDIA)
-			{ //switches are unreliable on some NVIDIA drivers
-				for (U32 i = 0; i < texture_index_channels; ++i)
-				{
-					std::string if_string = llformat("\t%sif (vary_texture_index == %d) { return texture(tex%d, texcoord); }\n", i > 0 ? "else " : "", i, i); 
-					extra_code_text[extra_code_count++] = strdup(if_string.c_str());
-				}
-				extra_code_text[extra_code_count++] = strdup("\treturn vec4(1,0,1,1);\n");
-				extra_code_text[extra_code_count++] = strdup("}\n");
-			}
-			else
-			{
-				extra_code_text[extra_code_count++] = strdup("\tvec4 ret = vec4(1,0,1,1);\n");
-				extra_code_text[extra_code_count++] = strdup("\tswitch (vary_texture_index)\n");
-				extra_code_text[extra_code_count++] = strdup("\t{\n");
-		
-				//switch body
-				for (S32 i = 0; i < texture_index_channels; ++i)
-				{
-					std::string case_str = llformat("\t\tcase %d: return texture(tex%d, texcoord);\n", i, i);
-					extra_code_text[extra_code_count++] = strdup(case_str.c_str());
-				}
-
-				extra_code_text[extra_code_count++] = strdup("\t}\n");
-				extra_code_text[extra_code_count++] = strdup("\treturn ret;\n");
-				extra_code_text[extra_code_count++] = strdup("}\n");
-			}
-		}
-		else
-		{ //should never get here.  Indexed texture rendering requires GLSL 1.30 or later 
-			// (for passing integers between vertex and fragment shaders)
-			LL_ERRS() << "Indexed texture rendering requires GLSL 1.30 or later." << LL_ENDL;
-		}
-	}
-    
-	//copy file into memory
-	enum {
-		  flag_write_to_out_of_extra_block_area = 0x01
-		, flag_extra_block_marker_was_found = 0x02
-	};
-	
-	unsigned char flags = flag_write_to_out_of_extra_block_area;
-	
-	GLuint out_of_extra_block_counter = 0, start_shader_code = shader_code_count, file_lines_count = 0;
-	
+    if (defines)
+    {
+        for (auto iter = defines->begin(); iter != defines->end(); ++iter)
+        {
+            std::string define = "#define " + iter->first + " " + iter->second + "\n";
+            extra_code_text[extra_code_count++] = (GLchar *) strdup(define.c_str());
+        }
+    }
+
+    if (texture_index_channels > 0 && type == GL_FRAGMENT_SHADER)
+    {
+        //use specified number of texture channels for indexed texture rendering
+
+        /* prepend shader code that looks like this:
+
+        uniform sampler2D tex0;
+        uniform sampler2D tex1;
+        uniform sampler2D tex2;
+        .
+        .
+        .
+        uniform sampler2D texN;
+
+        flat in int vary_texture_index;
+
+        vec4 ret = vec4(1,0,1,1);
+
+        vec4 diffuseLookup(vec2 texcoord)
+        {
+            switch (vary_texture_index)
+            {
+                case 0: ret = texture(tex0, texcoord); break;
+                case 1: ret = texture(tex1, texcoord); break;
+                case 2: ret = texture(tex2, texcoord); break;
+                .
+                .
+                .
+                case N: return texture(texN, texcoord); break;
+            }
+
+            return ret;
+        }
+        */
+
+        extra_code_text[extra_code_count++] = strdup("#define HAS_DIFFUSE_LOOKUP\n");
+
+        //uniform declartion
+        for (S32 i = 0; i < texture_index_channels; ++i)
+        {
+            std::string decl = llformat("uniform sampler2D tex%d;\n", i);
+            extra_code_text[extra_code_count++] = strdup(decl.c_str());
+        }
+
+        if (texture_index_channels > 1)
+        {
+            extra_code_text[extra_code_count++] = strdup("flat in int vary_texture_index;\n");
+        }
+
+        extra_code_text[extra_code_count++] = strdup("vec4 diffuseLookup(vec2 texcoord)\n");
+        extra_code_text[extra_code_count++] = strdup("{\n");
+
+
+        if (texture_index_channels == 1)
+        { //don't use flow control, that's silly
+            extra_code_text[extra_code_count++] = strdup("return texture(tex0, texcoord);\n");
+            extra_code_text[extra_code_count++] = strdup("}\n");
+        }
+        else if (major_version > 1 || minor_version >= 30)
+        {  //switches are supported in GLSL 1.30 and later
+            if (gGLManager.mIsNVIDIA)
+            { //switches are unreliable on some NVIDIA drivers
+                for (U32 i = 0; i < texture_index_channels; ++i)
+                {
+                    std::string if_string = llformat("\t%sif (vary_texture_index == %d) { return texture(tex%d, texcoord); }\n", i > 0 ? "else " : "", i, i);
+                    extra_code_text[extra_code_count++] = strdup(if_string.c_str());
+                }
+                extra_code_text[extra_code_count++] = strdup("\treturn vec4(1,0,1,1);\n");
+                extra_code_text[extra_code_count++] = strdup("}\n");
+            }
+            else
+            {
+                extra_code_text[extra_code_count++] = strdup("\tvec4 ret = vec4(1,0,1,1);\n");
+                extra_code_text[extra_code_count++] = strdup("\tswitch (vary_texture_index)\n");
+                extra_code_text[extra_code_count++] = strdup("\t{\n");
+
+                //switch body
+                for (S32 i = 0; i < texture_index_channels; ++i)
+                {
+                    std::string case_str = llformat("\t\tcase %d: return texture(tex%d, texcoord);\n", i, i);
+                    extra_code_text[extra_code_count++] = strdup(case_str.c_str());
+                }
+
+                extra_code_text[extra_code_count++] = strdup("\t}\n");
+                extra_code_text[extra_code_count++] = strdup("\treturn ret;\n");
+                extra_code_text[extra_code_count++] = strdup("}\n");
+            }
+        }
+        else
+        { //should never get here.  Indexed texture rendering requires GLSL 1.30 or later
+            // (for passing integers between vertex and fragment shaders)
+            LL_ERRS() << "Indexed texture rendering requires GLSL 1.30 or later." << LL_ENDL;
+        }
+    }
+
+    //copy file into memory
+    enum {
+          flag_write_to_out_of_extra_block_area = 0x01
+        , flag_extra_block_marker_was_found = 0x02
+    };
+
+    unsigned char flags = flag_write_to_out_of_extra_block_area;
+
+    GLuint out_of_extra_block_counter = 0, start_shader_code = shader_code_count, file_lines_count = 0;
+
 #define TOUCH_SHADERS 0
 
 #if TOUCH_SHADERS
@@ -738,13 +738,13 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
     bool touched = false;
 #endif
 
-	while(NULL != fgets((char *)buff, 1024, file)
-		  && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text)))
-	{
-		file_lines_count++;
+    while(NULL != fgets((char *)buff, 1024, file)
+          && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text)))
+    {
+        file_lines_count++;
+
+        bool extra_block_area_found = NULL != strstr((const char*)buff, "[EXTRA_CODE_HERE]");
 
-		bool extra_block_area_found = NULL != strstr((const char*)buff, "[EXTRA_CODE_HERE]");
-		
 #if TOUCH_SHADERS
         if (NULL != strstr((const char*)buff, marker))
         {
@@ -752,67 +752,67 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
         }
 #endif
 
-		if(extra_block_area_found && !(flag_extra_block_marker_was_found & flags))
-		{
-			if(!(flag_write_to_out_of_extra_block_area & flags))
-			{
-				//shift
-				for(GLuint to = start_shader_code, from = extra_code_count + start_shader_code;
-					from < shader_code_count; ++to, ++from)
-				{
-					shader_code_text[to] = shader_code_text[from];
-				}
-				
-				shader_code_count -= extra_code_count;
-			}
-		  
-			//copy extra code
-			for(GLuint n = 0; n < extra_code_count
-				&& shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text)); ++n)
-			{
-				shader_code_text[shader_code_count++] = extra_code_text[n];
-			}
-			
-			extra_code_count = 0;
-			
-			flags &= ~flag_write_to_out_of_extra_block_area;
-			flags |= flag_extra_block_marker_was_found;
-		}
+        if(extra_block_area_found && !(flag_extra_block_marker_was_found & flags))
+        {
+            if(!(flag_write_to_out_of_extra_block_area & flags))
+            {
+                //shift
+                for(GLuint to = start_shader_code, from = extra_code_count + start_shader_code;
+                    from < shader_code_count; ++to, ++from)
+                {
+                    shader_code_text[to] = shader_code_text[from];
+                }
+
+                shader_code_count -= extra_code_count;
+            }
+
+            //copy extra code
+            for(GLuint n = 0; n < extra_code_count
+                && shader_code_count < (LL_ARRAY_SIZE(shader_code_text) - LL_ARRAY_SIZE(extra_code_text)); ++n)
+            {
+                shader_code_text[shader_code_count++] = extra_code_text[n];
+            }
+
+            extra_code_count = 0;
+
+            flags &= ~flag_write_to_out_of_extra_block_area;
+            flags |= flag_extra_block_marker_was_found;
+        }
         else
         {
             shader_code_text[shader_code_count] = (GLchar *)strdup((char *)buff);
-		
+
             if(flag_write_to_out_of_extra_block_area & flags)
             {
                 shader_code_text[extra_code_count + start_shader_code + out_of_extra_block_counter]
                     = shader_code_text[shader_code_count];
                 out_of_extra_block_counter++;
-			
+
                 if(out_of_extra_block_counter == extra_code_count)
                 {
                     shader_code_count += extra_code_count;
                     flags &= ~flag_write_to_out_of_extra_block_area;
                 }
             }
-		
+
             ++shader_code_count;
-		}
-	} //while
-	
-	if(!(flag_extra_block_marker_was_found & flags))
-	{
-		for(GLuint n = start_shader_code; n < extra_code_count + start_shader_code; ++n)
-		{
-			shader_code_text[n] = extra_code_text[n - start_shader_code];
-		}
-		
-		if (file_lines_count < extra_code_count)
-		{
-			shader_code_count += extra_code_count;
-		}
-
-		extra_code_count = 0;
-	}
+        }
+    } //while
+
+    if(!(flag_extra_block_marker_was_found & flags))
+    {
+        for(GLuint n = start_shader_code; n < extra_code_count + start_shader_code; ++n)
+        {
+            shader_code_text[n] = extra_code_text[n - start_shader_code];
+        }
+
+        if (file_lines_count < extra_code_count)
+        {
+            shader_code_count += extra_code_count;
+        }
+
+        extra_code_count = 0;
+    }
 
 #if TOUCH_SHADERS
     if (!touched)
@@ -821,106 +821,106 @@ GLuint LLShaderMgr::loadShaderFile(const std::string& filename, S32 & shader_lev
     }
 #endif
 
-	fclose(file);
+    fclose(file);
 
-	//create shader object
+    //create shader object
     GLuint ret = glCreateShader(type);
 
-	error = glGetError();
-	if (error != GL_NO_ERROR)
-	{
-		LL_WARNS("ShaderLoading") << "GL ERROR in glCreateShader: " << error << " for file: " << open_file_name << LL_ENDL;
-		if (ret)
-		{
-			glDeleteShader(ret); //no longer need handle
-			ret = 0;
-		}
-	}
-
-	//load source
-	if (ret)
-	{
-		glShaderSource(ret, shader_code_count, (const GLchar**)shader_code_text, NULL);
-
-		error = glGetError();
-		if (error != GL_NO_ERROR)
-		{
-			LL_WARNS("ShaderLoading") << "GL ERROR in glShaderSource: " << error << " for file: " << open_file_name << LL_ENDL;
-			glDeleteShader(ret); //no longer need handle
-			ret = 0;
-		}
-	}
-
-	//compile source
-	if (ret)
-	{
-		glCompileShader(ret);
-
-		error = glGetError();
-		if (error != GL_NO_ERROR)
-		{
-			LL_WARNS("ShaderLoading") << "GL ERROR in glCompileShader: " << error << " for file: " << open_file_name << LL_ENDL;
-			glDeleteShader(ret); //no longer need handle
-			ret = 0;
-		}
-	}
-
-	if (error == GL_NO_ERROR)
-	{
-		//check for errors
-		GLint success = GL_TRUE;
+    error = glGetError();
+    if (error != GL_NO_ERROR)
+    {
+        LL_WARNS("ShaderLoading") << "GL ERROR in glCreateShader: " << error << " for file: " << open_file_name << LL_ENDL;
+        if (ret)
+        {
+            glDeleteShader(ret); //no longer need handle
+            ret = 0;
+        }
+    }
+
+    //load source
+    if (ret)
+    {
+        glShaderSource(ret, shader_code_count, (const GLchar**)shader_code_text, NULL);
+
+        error = glGetError();
+        if (error != GL_NO_ERROR)
+        {
+            LL_WARNS("ShaderLoading") << "GL ERROR in glShaderSource: " << error << " for file: " << open_file_name << LL_ENDL;
+            glDeleteShader(ret); //no longer need handle
+            ret = 0;
+        }
+    }
+
+    //compile source
+    if (ret)
+    {
+        glCompileShader(ret);
+
+        error = glGetError();
+        if (error != GL_NO_ERROR)
+        {
+            LL_WARNS("ShaderLoading") << "GL ERROR in glCompileShader: " << error << " for file: " << open_file_name << LL_ENDL;
+            glDeleteShader(ret); //no longer need handle
+            ret = 0;
+        }
+    }
+
+    if (error == GL_NO_ERROR)
+    {
+        //check for errors
+        GLint success = GL_TRUE;
         glGetShaderiv(ret, GL_COMPILE_STATUS, &success);
 
-		error = glGetError();
-		if (error != GL_NO_ERROR || success == GL_FALSE)
-		{
-			//an error occured, print log
-			LL_WARNS("ShaderLoading") << "GLSL Compilation Error:" << LL_ENDL;
-			dumpObjectLog(ret, TRUE, open_file_name);
-			dumpShaderSource(shader_code_count, shader_code_text);
-			glDeleteShader(ret); //no longer need handle
-			ret = 0;
-		}
-	}
-	else
-	{
-		ret = 0;
-	}
-	stop_glerror();
-
-	//free memory
-	for (GLuint i = 0; i < shader_code_count; i++)
-	{
-		free(shader_code_text[i]);
-	}
-
-	//successfully loaded, save results
-	if (ret)
-	{
-		// Add shader file to map
+        error = glGetError();
+        if (error != GL_NO_ERROR || success == GL_FALSE)
+        {
+            //an error occured, print log
+            LL_WARNS("ShaderLoading") << "GLSL Compilation Error:" << LL_ENDL;
+            dumpObjectLog(ret, TRUE, open_file_name);
+            dumpShaderSource(shader_code_count, shader_code_text);
+            glDeleteShader(ret); //no longer need handle
+            ret = 0;
+        }
+    }
+    else
+    {
+        ret = 0;
+    }
+    stop_glerror();
+
+    //free memory
+    for (GLuint i = 0; i < shader_code_count; i++)
+    {
+        free(shader_code_text[i]);
+    }
+
+    //successfully loaded, save results
+    if (ret)
+    {
+        // Add shader file to map
         if (type == GL_VERTEX_SHADER) {
             mVertexShaderObjects[filename] = ret;
         }
         else if (type == GL_FRAGMENT_SHADER) {
             mFragmentShaderObjects[filename] = ret;
         }
-		shader_level = try_gpu_class;
-	}
-	else
-	{
-		if (shader_level > 1)
-		{
-			shader_level--;
-			return loadShaderFile(filename, shader_level, type, defines, texture_index_channels);
-		}
-		LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL;	
-	}
-	return ret;
+        shader_level = try_gpu_class;
+    }
+    else
+    {
+        if (shader_level > 1)
+        {
+            shader_level--;
+            return loadShaderFile(filename, shader_level, type, defines, texture_index_channels);
+        }
+        LL_WARNS("ShaderLoading") << "Failed to load " << filename << LL_ENDL;
+    }
+    return ret;
 }
 
 BOOL LLShaderMgr::linkProgramObject(GLuint obj, BOOL suppress_errors)
 {
-	//check for errors
+    //check for errors
     {
         LL_PROFILE_ZONE_NAMED_CATEGORY_SHADER("glLinkProgram");
         glLinkProgram(obj);
@@ -940,238 +940,238 @@ BOOL LLShaderMgr::linkProgramObject(GLuint obj, BOOL suppress_errors)
         }
     }
 
-	std::string log = get_program_log(obj);
-	LLStringUtil::toLower(log);
-	if (log.find("software") != std::string::npos)
-	{
-		LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL;
-		success = GL_FALSE;
-		suppress_errors = FALSE;
-	}
-	return success;
+    std::string log = get_program_log(obj);
+    LLStringUtil::toLower(log);
+    if (log.find("software") != std::string::npos)
+    {
+        LL_SHADER_LOADING_WARNS() << "GLSL Linker: Running in Software:" << LL_ENDL;
+        success = GL_FALSE;
+        suppress_errors = FALSE;
+    }
+    return success;
 }
 
 BOOL LLShaderMgr::validateProgramObject(GLuint obj)
 {
-	//check program validity against current GL
-	glValidateProgram(obj);
-	GLint success = GL_TRUE;
+    //check program validity against current GL
+    glValidateProgram(obj);
+    GLint success = GL_TRUE;
     glGetProgramiv(obj, GL_LINK_STATUS, &success);
-	if (success == GL_FALSE)
-	{
-		LL_SHADER_LOADING_WARNS() << "GLSL program not valid: " << LL_ENDL;
-		dumpObjectLog(obj);
-	}
-	else
-	{
-		dumpObjectLog(obj, FALSE);
-	}
-
-	return success;
+    if (success == GL_FALSE)
+    {
+        LL_SHADER_LOADING_WARNS() << "GLSL program not valid: " << LL_ENDL;
+        dumpObjectLog(obj);
+    }
+    else
+    {
+        dumpObjectLog(obj, FALSE);
+    }
+
+    return success;
 }
 
 void LLShaderMgr::initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version)
 {
-	LL_INFOS() << "Initializing shader cache" << LL_ENDL;
-
-	mShaderCacheEnabled = gGLManager.mGLVersion >= 4.09 && enabled;
-
-	if(!mShaderCacheEnabled || mShaderCacheInitialized)
-		return;
-
-	mShaderCacheInitialized = true;
-
-	mShaderCacheDir = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "shader_cache");
-	LLFile::mkdir(mShaderCacheDir);
-
-	{
-		std::string meta_out_path = gDirUtilp->add(mShaderCacheDir, "shaderdata.llsd");
-		if (gDirUtilp->fileExists(meta_out_path))
-		{
-			LL_INFOS() << "Loading shader cache metadata" << LL_ENDL;
-
-			llifstream instream(meta_out_path);
-			LLSD in_data;
-			LLSDSerialize::fromNotation(in_data, instream, LLSDSerialize::SIZE_UNLIMITED);
-			instream.close();
-
-			if (old_cache_version == current_cache_version)
-			{
-				for (const auto& data_pair : in_data.asMap())
-				{
-					ProgramBinaryData binary_info = ProgramBinaryData();
-					binary_info.mBinaryFormat = data_pair.second["binary_format"].asInteger();
-					binary_info.mBinaryLength = data_pair.second["binary_size"].asInteger();
-					binary_info.mLastUsedTime = data_pair.second["last_used"].asReal();
-					mShaderBinaryCache.insert_or_assign(LLUUID(data_pair.first), binary_info);
-				}
-			}
-			else
-			{
-				LL_INFOS() << "Shader cache version mismatch detected. Purging." << LL_ENDL;
-				clearShaderCache();
-			}
-		}
-	}
+    LL_INFOS() << "Initializing shader cache" << LL_ENDL;
+
+    mShaderCacheEnabled = gGLManager.mGLVersion >= 4.09 && enabled;
+
+    if(!mShaderCacheEnabled || mShaderCacheInitialized)
+        return;
+
+    mShaderCacheInitialized = true;
+
+    mShaderCacheDir = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "shader_cache");
+    LLFile::mkdir(mShaderCacheDir);
+
+    {
+        std::string meta_out_path = gDirUtilp->add(mShaderCacheDir, "shaderdata.llsd");
+        if (gDirUtilp->fileExists(meta_out_path))
+        {
+            LL_INFOS() << "Loading shader cache metadata" << LL_ENDL;
+
+            llifstream instream(meta_out_path);
+            LLSD in_data;
+            LLSDSerialize::fromNotation(in_data, instream, LLSDSerialize::SIZE_UNLIMITED);
+            instream.close();
+
+            if (old_cache_version == current_cache_version)
+            {
+                for (const auto& data_pair : in_data.asMap())
+                {
+                    ProgramBinaryData binary_info = ProgramBinaryData();
+                    binary_info.mBinaryFormat = data_pair.second["binary_format"].asInteger();
+                    binary_info.mBinaryLength = data_pair.second["binary_size"].asInteger();
+                    binary_info.mLastUsedTime = data_pair.second["last_used"].asReal();
+                    mShaderBinaryCache.insert_or_assign(LLUUID(data_pair.first), binary_info);
+                }
+            }
+            else
+            {
+                LL_INFOS() << "Shader cache version mismatch detected. Purging." << LL_ENDL;
+                clearShaderCache();
+            }
+        }
+    }
 }
 
 void LLShaderMgr::clearShaderCache()
 {
-	std::string shader_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "shader_cache");
-	LL_INFOS() << "Removing shader cache at " << shader_cache << LL_ENDL;
-	const std::string mask = "*";
-	gDirUtilp->deleteFilesInDir(shader_cache, mask);
-	mShaderBinaryCache.clear();
+    std::string shader_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "shader_cache");
+    LL_INFOS() << "Removing shader cache at " << shader_cache << LL_ENDL;
+    const std::string mask = "*";
+    gDirUtilp->deleteFilesInDir(shader_cache, mask);
+    mShaderBinaryCache.clear();
 }
 
 void LLShaderMgr::persistShaderCacheMetadata()
 {
-	if(!mShaderCacheEnabled) return;
-
-	LL_INFOS() << "Persisting shader cache metadata to disk" << LL_ENDL;
-
-	LLSD out = LLSD::emptyMap();
-
-	static const F32 LRU_TIME = (60.f * 60.f) * 24.f * 7.f; // 14 days
-	const F32 current_time = LLTimer::getTotalSeconds();
-	for (auto it = mShaderBinaryCache.begin(); it != mShaderBinaryCache.end();)
-	{
-		const ProgramBinaryData& shader_metadata = it->second;
-		if ((shader_metadata.mLastUsedTime + LRU_TIME) < current_time)
-		{
-			std::string shader_path = gDirUtilp->add(mShaderCacheDir, it->first.asString() + ".shaderbin");
-			LLFile::remove(shader_path);
-			it = mShaderBinaryCache.erase(it);
-		}
-		else
-		{
-			LLSD data = LLSD::emptyMap();
-			data["binary_format"] = LLSD::Integer(shader_metadata.mBinaryFormat);
-			data["binary_size"] = LLSD::Integer(shader_metadata.mBinaryLength);
-			data["last_used"] = LLSD::Real(shader_metadata.mLastUsedTime);
-			out[it->first.asString()] = data;
-			++it;
-		}
-	}
-
-	std::string meta_out_path = gDirUtilp->add(mShaderCacheDir, "shaderdata.llsd");
-	llofstream outstream(meta_out_path);
-	LLSDSerialize::toNotation(out, outstream);
-	outstream.close();
+    if(!mShaderCacheEnabled) return;
+
+    LL_INFOS() << "Persisting shader cache metadata to disk" << LL_ENDL;
+
+    LLSD out = LLSD::emptyMap();
+
+    static const F32 LRU_TIME = (60.f * 60.f) * 24.f * 7.f; // 14 days
+    const F32 current_time = LLTimer::getTotalSeconds();
+    for (auto it = mShaderBinaryCache.begin(); it != mShaderBinaryCache.end();)
+    {
+        const ProgramBinaryData& shader_metadata = it->second;
+        if ((shader_metadata.mLastUsedTime + LRU_TIME) < current_time)
+        {
+            std::string shader_path = gDirUtilp->add(mShaderCacheDir, it->first.asString() + ".shaderbin");
+            LLFile::remove(shader_path);
+            it = mShaderBinaryCache.erase(it);
+        }
+        else
+        {
+            LLSD data = LLSD::emptyMap();
+            data["binary_format"] = LLSD::Integer(shader_metadata.mBinaryFormat);
+            data["binary_size"] = LLSD::Integer(shader_metadata.mBinaryLength);
+            data["last_used"] = LLSD::Real(shader_metadata.mLastUsedTime);
+            out[it->first.asString()] = data;
+            ++it;
+        }
+    }
+
+    std::string meta_out_path = gDirUtilp->add(mShaderCacheDir, "shaderdata.llsd");
+    llofstream outstream(meta_out_path);
+    LLSDSerialize::toNotation(out, outstream);
+    outstream.close();
 }
 
 bool LLShaderMgr::loadCachedProgramBinary(LLGLSLShader* shader)
 {
-	if (!mShaderCacheEnabled) return false;
-
-	glProgramParameteri(shader->mProgramObject, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
-
-	auto binary_iter = mShaderBinaryCache.find(shader->mShaderHash);
-	if (binary_iter != mShaderBinaryCache.end())
-	{
-		std::string in_path = gDirUtilp->add(mShaderCacheDir, shader->mShaderHash.asString() + ".shaderbin");
-		auto& shader_info = binary_iter->second;
-		if (shader_info.mBinaryLength > 0)
-		{
-			std::vector<U8> in_data;
-			in_data.resize(shader_info.mBinaryLength);
-
-			LLUniqueFile filep = LLFile::fopen(in_path, "rb");
-			if (filep)
-			{
-				size_t result = fread(in_data.data(), sizeof(U8), in_data.size(), filep);
-				filep.close();
-
-				if (result == in_data.size())
-				{
-					GLenum error = glGetError(); // Clear current error
-					glProgramBinary(shader->mProgramObject, shader_info.mBinaryFormat, in_data.data(), shader_info.mBinaryLength);
-
-					error = glGetError();
-					GLint success = GL_TRUE;
-					glGetProgramiv(shader->mProgramObject, GL_LINK_STATUS, &success);
-					if (error == GL_NO_ERROR && success == GL_TRUE)
-					{
-						binary_iter->second.mLastUsedTime = LLTimer::getTotalSeconds();
-						LL_INFOS() << "Loaded cached binary for shader: " << shader->mName << LL_ENDL;
-						return true;
-					}
-				}
-			}
-		}
-		//an error occured, normally we would print log but in this case it means the shader needs recompiling.
-		LL_INFOS() << "Failed to load cached binary for shader: " << shader->mName << " falling back to compilation" << LL_ENDL;
-		LLFile::remove(in_path);
-		mShaderBinaryCache.erase(binary_iter);
-	}
-	return false;
+    if (!mShaderCacheEnabled) return false;
+
+    glProgramParameteri(shader->mProgramObject, GL_PROGRAM_BINARY_RETRIEVABLE_HINT, GL_TRUE);
+
+    auto binary_iter = mShaderBinaryCache.find(shader->mShaderHash);
+    if (binary_iter != mShaderBinaryCache.end())
+    {
+        std::string in_path = gDirUtilp->add(mShaderCacheDir, shader->mShaderHash.asString() + ".shaderbin");
+        auto& shader_info = binary_iter->second;
+        if (shader_info.mBinaryLength > 0)
+        {
+            std::vector<U8> in_data;
+            in_data.resize(shader_info.mBinaryLength);
+
+            LLUniqueFile filep = LLFile::fopen(in_path, "rb");
+            if (filep)
+            {
+                size_t result = fread(in_data.data(), sizeof(U8), in_data.size(), filep);
+                filep.close();
+
+                if (result == in_data.size())
+                {
+                    GLenum error = glGetError(); // Clear current error
+                    glProgramBinary(shader->mProgramObject, shader_info.mBinaryFormat, in_data.data(), shader_info.mBinaryLength);
+
+                    error = glGetError();
+                    GLint success = GL_TRUE;
+                    glGetProgramiv(shader->mProgramObject, GL_LINK_STATUS, &success);
+                    if (error == GL_NO_ERROR && success == GL_TRUE)
+                    {
+                        binary_iter->second.mLastUsedTime = LLTimer::getTotalSeconds();
+                        LL_INFOS() << "Loaded cached binary for shader: " << shader->mName << LL_ENDL;
+                        return true;
+                    }
+                }
+            }
+        }
+        //an error occured, normally we would print log but in this case it means the shader needs recompiling.
+        LL_INFOS() << "Failed to load cached binary for shader: " << shader->mName << " falling back to compilation" << LL_ENDL;
+        LLFile::remove(in_path);
+        mShaderBinaryCache.erase(binary_iter);
+    }
+    return false;
 }
 
 bool LLShaderMgr::saveCachedProgramBinary(LLGLSLShader* shader)
 {
-	if (!mShaderCacheEnabled) return true;
-
-	ProgramBinaryData binary_info = ProgramBinaryData();
-	glGetProgramiv(shader->mProgramObject, GL_PROGRAM_BINARY_LENGTH, &binary_info.mBinaryLength);
-	if (binary_info.mBinaryLength > 0)
-	{
-		std::vector<U8> program_binary;
-		program_binary.resize(binary_info.mBinaryLength);
-
-		GLenum error = glGetError(); // Clear current error
-		glGetProgramBinary(shader->mProgramObject, program_binary.size() * sizeof(U8), nullptr, &binary_info.mBinaryFormat, program_binary.data());
-		error = glGetError();
-		if (error == GL_NO_ERROR)
-		{
-			std::string out_path = gDirUtilp->add(mShaderCacheDir, shader->mShaderHash.asString() + ".shaderbin");
-			LLUniqueFile outfile = LLFile::fopen(out_path, "wb");
-			if (outfile)
-			{
-				fwrite(program_binary.data(), sizeof(U8), program_binary.size(), outfile);
-				outfile.close();
-
-				binary_info.mLastUsedTime = LLTimer::getTotalSeconds();
-
-				mShaderBinaryCache.insert_or_assign(shader->mShaderHash, binary_info);
-				return true;
-			}
-		}
-	}
-	return false;
+    if (!mShaderCacheEnabled) return true;
+
+    ProgramBinaryData binary_info = ProgramBinaryData();
+    glGetProgramiv(shader->mProgramObject, GL_PROGRAM_BINARY_LENGTH, &binary_info.mBinaryLength);
+    if (binary_info.mBinaryLength > 0)
+    {
+        std::vector<U8> program_binary;
+        program_binary.resize(binary_info.mBinaryLength);
+
+        GLenum error = glGetError(); // Clear current error
+        glGetProgramBinary(shader->mProgramObject, program_binary.size() * sizeof(U8), nullptr, &binary_info.mBinaryFormat, program_binary.data());
+        error = glGetError();
+        if (error == GL_NO_ERROR)
+        {
+            std::string out_path = gDirUtilp->add(mShaderCacheDir, shader->mShaderHash.asString() + ".shaderbin");
+            LLUniqueFile outfile = LLFile::fopen(out_path, "wb");
+            if (outfile)
+            {
+                fwrite(program_binary.data(), sizeof(U8), program_binary.size(), outfile);
+                outfile.close();
+
+                binary_info.mLastUsedTime = LLTimer::getTotalSeconds();
+
+                mShaderBinaryCache.insert_or_assign(shader->mShaderHash, binary_info);
+                return true;
+            }
+        }
+    }
+    return false;
 }
 
 //virtual
 void LLShaderMgr::initAttribsAndUniforms()
 {
-	//MUST match order of enum in LLVertexBuffer.h
-	mReservedAttribs.push_back("position");
-	mReservedAttribs.push_back("normal");
-	mReservedAttribs.push_back("texcoord0");
-	mReservedAttribs.push_back("texcoord1");
-	mReservedAttribs.push_back("texcoord2");
-	mReservedAttribs.push_back("texcoord3");
-	mReservedAttribs.push_back("diffuse_color");
-	mReservedAttribs.push_back("emissive");
-	mReservedAttribs.push_back("tangent");
-	mReservedAttribs.push_back("weight");
-	mReservedAttribs.push_back("weight4");
-	mReservedAttribs.push_back("clothing");
-	mReservedAttribs.push_back("texture_index");
-	
-	//matrix state
-	mReservedUniforms.push_back("modelview_matrix");
-	mReservedUniforms.push_back("projection_matrix");
-	mReservedUniforms.push_back("inv_proj");
-	mReservedUniforms.push_back("modelview_projection_matrix");
+    //MUST match order of enum in LLVertexBuffer.h
+    mReservedAttribs.push_back("position");
+    mReservedAttribs.push_back("normal");
+    mReservedAttribs.push_back("texcoord0");
+    mReservedAttribs.push_back("texcoord1");
+    mReservedAttribs.push_back("texcoord2");
+    mReservedAttribs.push_back("texcoord3");
+    mReservedAttribs.push_back("diffuse_color");
+    mReservedAttribs.push_back("emissive");
+    mReservedAttribs.push_back("tangent");
+    mReservedAttribs.push_back("weight");
+    mReservedAttribs.push_back("weight4");
+    mReservedAttribs.push_back("clothing");
+    mReservedAttribs.push_back("texture_index");
+
+    //matrix state
+    mReservedUniforms.push_back("modelview_matrix");
+    mReservedUniforms.push_back("projection_matrix");
+    mReservedUniforms.push_back("inv_proj");
+    mReservedUniforms.push_back("modelview_projection_matrix");
     mReservedUniforms.push_back("inv_modelview");
     mReservedUniforms.push_back("identity_matrix");
-	mReservedUniforms.push_back("normal_matrix");
-	mReservedUniforms.push_back("texture_matrix0");
-	mReservedUniforms.push_back("texture_matrix1");
-	mReservedUniforms.push_back("texture_matrix2");
-	mReservedUniforms.push_back("texture_matrix3");
-	mReservedUniforms.push_back("object_plane_s");
-	mReservedUniforms.push_back("object_plane_t");
+    mReservedUniforms.push_back("normal_matrix");
+    mReservedUniforms.push_back("texture_matrix0");
+    mReservedUniforms.push_back("texture_matrix1");
+    mReservedUniforms.push_back("texture_matrix2");
+    mReservedUniforms.push_back("texture_matrix3");
+    mReservedUniforms.push_back("object_plane_s");
+    mReservedUniforms.push_back("object_plane_t");
 
     mReservedUniforms.push_back("texture_base_color_transform"); // (GLTF)
     mReservedUniforms.push_back("texture_normal_transform"); // (GLTF)
@@ -1180,38 +1180,38 @@ void LLShaderMgr::initAttribsAndUniforms()
 
     llassert(mReservedUniforms.size() == LLShaderMgr::TEXTURE_EMISSIVE_TRANSFORM+1);
 
-	mReservedUniforms.push_back("viewport");
+    mReservedUniforms.push_back("viewport");
 
-	mReservedUniforms.push_back("light_position");
-	mReservedUniforms.push_back("light_direction");
-	mReservedUniforms.push_back("light_attenuation");
+    mReservedUniforms.push_back("light_position");
+    mReservedUniforms.push_back("light_direction");
+    mReservedUniforms.push_back("light_attenuation");
     mReservedUniforms.push_back("light_deferred_attenuation");
-	mReservedUniforms.push_back("light_diffuse");
-	mReservedUniforms.push_back("light_ambient");
-	mReservedUniforms.push_back("light_count");
-	mReservedUniforms.push_back("light");
-	mReservedUniforms.push_back("light_col");
-	mReservedUniforms.push_back("far_z");
+    mReservedUniforms.push_back("light_diffuse");
+    mReservedUniforms.push_back("light_ambient");
+    mReservedUniforms.push_back("light_count");
+    mReservedUniforms.push_back("light");
+    mReservedUniforms.push_back("light_col");
+    mReservedUniforms.push_back("far_z");
 
-	llassert(mReservedUniforms.size() == LLShaderMgr::MULTI_LIGHT_FAR_Z+1);
+    llassert(mReservedUniforms.size() == LLShaderMgr::MULTI_LIGHT_FAR_Z+1);
 
     //NOTE: MUST match order in eGLSLReservedUniforms
-	mReservedUniforms.push_back("proj_mat");
-	mReservedUniforms.push_back("proj_near");
-	mReservedUniforms.push_back("proj_p");
-	mReservedUniforms.push_back("proj_n");
-	mReservedUniforms.push_back("proj_origin");
-	mReservedUniforms.push_back("proj_range");
-	mReservedUniforms.push_back("proj_ambiance");
-	mReservedUniforms.push_back("proj_shadow_idx");
-	mReservedUniforms.push_back("shadow_fade");
-	mReservedUniforms.push_back("proj_focus");
-	mReservedUniforms.push_back("proj_lod");
-	mReservedUniforms.push_back("proj_ambient_lod");
-
-	llassert(mReservedUniforms.size() == LLShaderMgr::PROJECTOR_AMBIENT_LOD+1);
-
-	mReservedUniforms.push_back("color");
+    mReservedUniforms.push_back("proj_mat");
+    mReservedUniforms.push_back("proj_near");
+    mReservedUniforms.push_back("proj_p");
+    mReservedUniforms.push_back("proj_n");
+    mReservedUniforms.push_back("proj_origin");
+    mReservedUniforms.push_back("proj_range");
+    mReservedUniforms.push_back("proj_ambiance");
+    mReservedUniforms.push_back("proj_shadow_idx");
+    mReservedUniforms.push_back("shadow_fade");
+    mReservedUniforms.push_back("proj_focus");
+    mReservedUniforms.push_back("proj_lod");
+    mReservedUniforms.push_back("proj_ambient_lod");
+
+    llassert(mReservedUniforms.size() == LLShaderMgr::PROJECTOR_AMBIENT_LOD+1);
+
+    mReservedUniforms.push_back("color");
     mReservedUniforms.push_back("emissiveColor");
     mReservedUniforms.push_back("metallicFactor");
     mReservedUniforms.push_back("roughnessFactor");
@@ -1219,95 +1219,95 @@ void LLShaderMgr::initAttribsAndUniforms()
     mReservedUniforms.push_back("clipPlane");
     mReservedUniforms.push_back("clipSign");
 
-	mReservedUniforms.push_back("diffuseMap");
+    mReservedUniforms.push_back("diffuseMap");
     mReservedUniforms.push_back("altDiffuseMap");
-	mReservedUniforms.push_back("specularMap");
+    mReservedUniforms.push_back("specularMap");
     mReservedUniforms.push_back("emissiveMap");
-	mReservedUniforms.push_back("bumpMap");
+    mReservedUniforms.push_back("bumpMap");
     mReservedUniforms.push_back("bumpMap2");
-	mReservedUniforms.push_back("environmentMap");
+    mReservedUniforms.push_back("environmentMap");
     mReservedUniforms.push_back("sceneMap");
     mReservedUniforms.push_back("sceneDepth");
     mReservedUniforms.push_back("reflectionProbes");
     mReservedUniforms.push_back("irradianceProbes");
     mReservedUniforms.push_back("heroProbes");
-	mReservedUniforms.push_back("cloud_noise_texture");
+    mReservedUniforms.push_back("cloud_noise_texture");
     mReservedUniforms.push_back("cloud_noise_texture_next");
-	mReservedUniforms.push_back("fullbright");
-	mReservedUniforms.push_back("lightnorm");
-	mReservedUniforms.push_back("sunlight_color");
-	mReservedUniforms.push_back("ambient_color");
+    mReservedUniforms.push_back("fullbright");
+    mReservedUniforms.push_back("lightnorm");
+    mReservedUniforms.push_back("sunlight_color");
+    mReservedUniforms.push_back("ambient_color");
     mReservedUniforms.push_back("sky_hdr_scale");
     mReservedUniforms.push_back("sky_sunlight_scale");
     mReservedUniforms.push_back("sky_ambient_scale");
-	mReservedUniforms.push_back("blue_horizon");
+    mReservedUniforms.push_back("blue_horizon");
     mReservedUniforms.push_back("blue_density");
     mReservedUniforms.push_back("haze_horizon");
-	mReservedUniforms.push_back("haze_density");
-	mReservedUniforms.push_back("cloud_shadow");
-	mReservedUniforms.push_back("density_multiplier");
-	mReservedUniforms.push_back("distance_multiplier");
-	mReservedUniforms.push_back("max_y");
-	mReservedUniforms.push_back("glow");
-	mReservedUniforms.push_back("cloud_color");
-	mReservedUniforms.push_back("cloud_pos_density1");
-	mReservedUniforms.push_back("cloud_pos_density2");
-	mReservedUniforms.push_back("cloud_scale");
-	mReservedUniforms.push_back("gamma");
-	mReservedUniforms.push_back("scene_light_strength");
+    mReservedUniforms.push_back("haze_density");
+    mReservedUniforms.push_back("cloud_shadow");
+    mReservedUniforms.push_back("density_multiplier");
+    mReservedUniforms.push_back("distance_multiplier");
+    mReservedUniforms.push_back("max_y");
+    mReservedUniforms.push_back("glow");
+    mReservedUniforms.push_back("cloud_color");
+    mReservedUniforms.push_back("cloud_pos_density1");
+    mReservedUniforms.push_back("cloud_pos_density2");
+    mReservedUniforms.push_back("cloud_scale");
+    mReservedUniforms.push_back("gamma");
+    mReservedUniforms.push_back("scene_light_strength");
 
-	llassert(mReservedUniforms.size() == LLShaderMgr::SCENE_LIGHT_STRENGTH+1);
+    llassert(mReservedUniforms.size() == LLShaderMgr::SCENE_LIGHT_STRENGTH+1);
 
-	mReservedUniforms.push_back("center");
-	mReservedUniforms.push_back("size");
-	mReservedUniforms.push_back("falloff");
+    mReservedUniforms.push_back("center");
+    mReservedUniforms.push_back("size");
+    mReservedUniforms.push_back("falloff");
 
-	mReservedUniforms.push_back("box_center");
-	mReservedUniforms.push_back("box_size");
+    mReservedUniforms.push_back("box_center");
+    mReservedUniforms.push_back("box_size");
 
 
-	mReservedUniforms.push_back("minLuminance");
-	mReservedUniforms.push_back("maxExtractAlpha");
-	mReservedUniforms.push_back("lumWeights");
-	mReservedUniforms.push_back("warmthWeights");
-	mReservedUniforms.push_back("warmthAmount");
-	mReservedUniforms.push_back("glowStrength");
-	mReservedUniforms.push_back("glowDelta");
-	mReservedUniforms.push_back("glowNoiseMap");
+    mReservedUniforms.push_back("minLuminance");
+    mReservedUniforms.push_back("maxExtractAlpha");
+    mReservedUniforms.push_back("lumWeights");
+    mReservedUniforms.push_back("warmthWeights");
+    mReservedUniforms.push_back("warmthAmount");
+    mReservedUniforms.push_back("glowStrength");
+    mReservedUniforms.push_back("glowDelta");
+    mReservedUniforms.push_back("glowNoiseMap");
 
-	llassert(mReservedUniforms.size() == LLShaderMgr::GLOW_NOISE_MAP+1);
+    llassert(mReservedUniforms.size() == LLShaderMgr::GLOW_NOISE_MAP+1);
 
 
-	mReservedUniforms.push_back("minimum_alpha");
-	mReservedUniforms.push_back("emissive_brightness");
+    mReservedUniforms.push_back("minimum_alpha");
+    mReservedUniforms.push_back("emissive_brightness");
 
     // Deferred
-	mReservedUniforms.push_back("shadow_matrix");
-	mReservedUniforms.push_back("env_mat");
-	mReservedUniforms.push_back("shadow_clip");
-	mReservedUniforms.push_back("sun_wash");
-	mReservedUniforms.push_back("shadow_noise");
-	mReservedUniforms.push_back("blur_size");
-	mReservedUniforms.push_back("ssao_radius");
-	mReservedUniforms.push_back("ssao_max_radius");
-	mReservedUniforms.push_back("ssao_factor");
-	mReservedUniforms.push_back("ssao_factor_inv");
-	mReservedUniforms.push_back("ssao_effect_mat");
-	mReservedUniforms.push_back("screen_res");
-	mReservedUniforms.push_back("near_clip");
-	mReservedUniforms.push_back("shadow_offset");
-	mReservedUniforms.push_back("shadow_bias");
-	mReservedUniforms.push_back("spot_shadow_bias");
-	mReservedUniforms.push_back("spot_shadow_offset");
-	mReservedUniforms.push_back("sun_dir");
+    mReservedUniforms.push_back("shadow_matrix");
+    mReservedUniforms.push_back("env_mat");
+    mReservedUniforms.push_back("shadow_clip");
+    mReservedUniforms.push_back("sun_wash");
+    mReservedUniforms.push_back("shadow_noise");
+    mReservedUniforms.push_back("blur_size");
+    mReservedUniforms.push_back("ssao_radius");
+    mReservedUniforms.push_back("ssao_max_radius");
+    mReservedUniforms.push_back("ssao_factor");
+    mReservedUniforms.push_back("ssao_factor_inv");
+    mReservedUniforms.push_back("ssao_effect_mat");
+    mReservedUniforms.push_back("screen_res");
+    mReservedUniforms.push_back("near_clip");
+    mReservedUniforms.push_back("shadow_offset");
+    mReservedUniforms.push_back("shadow_bias");
+    mReservedUniforms.push_back("spot_shadow_bias");
+    mReservedUniforms.push_back("spot_shadow_offset");
+    mReservedUniforms.push_back("sun_dir");
     mReservedUniforms.push_back("moon_dir");
-	mReservedUniforms.push_back("shadow_res");
-	mReservedUniforms.push_back("proj_shadow_res");
-	mReservedUniforms.push_back("depth_cutoff");
-	mReservedUniforms.push_back("norm_cutoff");
-	mReservedUniforms.push_back("shadow_target_width");
-	
-	llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH + 1);
+    mReservedUniforms.push_back("shadow_res");
+    mReservedUniforms.push_back("proj_shadow_res");
+    mReservedUniforms.push_back("depth_cutoff");
+    mReservedUniforms.push_back("norm_cutoff");
+    mReservedUniforms.push_back("shadow_target_width");
+
+    llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH + 1);
 
     mReservedUniforms.push_back("iterationCount");
     mReservedUniforms.push_back("rayStep");
@@ -1321,113 +1321,113 @@ void LLShaderMgr::initAttribsAndUniforms()
     mReservedUniforms.push_back("inv_modelview_delta");
     mReservedUniforms.push_back("cube_snapshot");
 
-	mReservedUniforms.push_back("tc_scale");
-	mReservedUniforms.push_back("rcp_screen_res");
-	mReservedUniforms.push_back("rcp_frame_opt");
-	mReservedUniforms.push_back("rcp_frame_opt2");
-	
-	mReservedUniforms.push_back("focal_distance");
-	mReservedUniforms.push_back("blur_constant");
-	mReservedUniforms.push_back("tan_pixel_angle");
-	mReservedUniforms.push_back("magnification");
-	mReservedUniforms.push_back("max_cof");
-	mReservedUniforms.push_back("res_scale");
-	mReservedUniforms.push_back("dof_width");
-	mReservedUniforms.push_back("dof_height");
-
-	mReservedUniforms.push_back("depthMap");
-	mReservedUniforms.push_back("shadowMap0");
-	mReservedUniforms.push_back("shadowMap1");
-	mReservedUniforms.push_back("shadowMap2");
-	mReservedUniforms.push_back("shadowMap3");
-	mReservedUniforms.push_back("shadowMap4");
-	mReservedUniforms.push_back("shadowMap5");
-
-	llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW5+1);
-
-	mReservedUniforms.push_back("normalMap");
-	mReservedUniforms.push_back("positionMap");
-	mReservedUniforms.push_back("diffuseRect");
-	mReservedUniforms.push_back("specularRect");
+    mReservedUniforms.push_back("tc_scale");
+    mReservedUniforms.push_back("rcp_screen_res");
+    mReservedUniforms.push_back("rcp_frame_opt");
+    mReservedUniforms.push_back("rcp_frame_opt2");
+
+    mReservedUniforms.push_back("focal_distance");
+    mReservedUniforms.push_back("blur_constant");
+    mReservedUniforms.push_back("tan_pixel_angle");
+    mReservedUniforms.push_back("magnification");
+    mReservedUniforms.push_back("max_cof");
+    mReservedUniforms.push_back("res_scale");
+    mReservedUniforms.push_back("dof_width");
+    mReservedUniforms.push_back("dof_height");
+
+    mReservedUniforms.push_back("depthMap");
+    mReservedUniforms.push_back("shadowMap0");
+    mReservedUniforms.push_back("shadowMap1");
+    mReservedUniforms.push_back("shadowMap2");
+    mReservedUniforms.push_back("shadowMap3");
+    mReservedUniforms.push_back("shadowMap4");
+    mReservedUniforms.push_back("shadowMap5");
+
+    llassert(mReservedUniforms.size() == LLShaderMgr::DEFERRED_SHADOW5+1);
+
+    mReservedUniforms.push_back("normalMap");
+    mReservedUniforms.push_back("positionMap");
+    mReservedUniforms.push_back("diffuseRect");
+    mReservedUniforms.push_back("specularRect");
     mReservedUniforms.push_back("emissiveRect");
     mReservedUniforms.push_back("exposureMap");
     mReservedUniforms.push_back("brdfLut");
-	mReservedUniforms.push_back("noiseMap");
-	mReservedUniforms.push_back("lightFunc");
-	mReservedUniforms.push_back("lightMap");
-	mReservedUniforms.push_back("bloomMap");
-	mReservedUniforms.push_back("projectionMap");
-	mReservedUniforms.push_back("norm_mat");
-	mReservedUniforms.push_back("texture_gamma");
-	
-	mReservedUniforms.push_back("specular_color");
-	mReservedUniforms.push_back("env_intensity");
-
-	mReservedUniforms.push_back("matrixPalette");
-	mReservedUniforms.push_back("translationPalette");
-	
-	mReservedUniforms.push_back("screenTex");
-	mReservedUniforms.push_back("screenDepth");
-	mReservedUniforms.push_back("refTex");
-	mReservedUniforms.push_back("eyeVec");
-	mReservedUniforms.push_back("time");
-	mReservedUniforms.push_back("waveDir1");
-	mReservedUniforms.push_back("waveDir2");
-	mReservedUniforms.push_back("lightDir");
-	mReservedUniforms.push_back("specular");
-	mReservedUniforms.push_back("lightExp");
-	mReservedUniforms.push_back("waterFogColor");
+    mReservedUniforms.push_back("noiseMap");
+    mReservedUniforms.push_back("lightFunc");
+    mReservedUniforms.push_back("lightMap");
+    mReservedUniforms.push_back("bloomMap");
+    mReservedUniforms.push_back("projectionMap");
+    mReservedUniforms.push_back("norm_mat");
+    mReservedUniforms.push_back("texture_gamma");
+
+    mReservedUniforms.push_back("specular_color");
+    mReservedUniforms.push_back("env_intensity");
+
+    mReservedUniforms.push_back("matrixPalette");
+    mReservedUniforms.push_back("translationPalette");
+
+    mReservedUniforms.push_back("screenTex");
+    mReservedUniforms.push_back("screenDepth");
+    mReservedUniforms.push_back("refTex");
+    mReservedUniforms.push_back("eyeVec");
+    mReservedUniforms.push_back("time");
+    mReservedUniforms.push_back("waveDir1");
+    mReservedUniforms.push_back("waveDir2");
+    mReservedUniforms.push_back("lightDir");
+    mReservedUniforms.push_back("specular");
+    mReservedUniforms.push_back("lightExp");
+    mReservedUniforms.push_back("waterFogColor");
     mReservedUniforms.push_back("waterFogColorLinear");
-	mReservedUniforms.push_back("waterFogDensity");
-	mReservedUniforms.push_back("waterFogKS");
-	mReservedUniforms.push_back("refScale");
-	mReservedUniforms.push_back("waterHeight");
-	mReservedUniforms.push_back("waterPlane");
-	mReservedUniforms.push_back("normScale");
-	mReservedUniforms.push_back("fresnelScale");
-	mReservedUniforms.push_back("fresnelOffset");
-	mReservedUniforms.push_back("blurMultiplier");
-	mReservedUniforms.push_back("sunAngle");
-	mReservedUniforms.push_back("scaledAngle");
-	mReservedUniforms.push_back("sunAngle2");
-	
-	mReservedUniforms.push_back("camPosLocal");
+    mReservedUniforms.push_back("waterFogDensity");
+    mReservedUniforms.push_back("waterFogKS");
+    mReservedUniforms.push_back("refScale");
+    mReservedUniforms.push_back("waterHeight");
+    mReservedUniforms.push_back("waterPlane");
+    mReservedUniforms.push_back("normScale");
+    mReservedUniforms.push_back("fresnelScale");
+    mReservedUniforms.push_back("fresnelOffset");
+    mReservedUniforms.push_back("blurMultiplier");
+    mReservedUniforms.push_back("sunAngle");
+    mReservedUniforms.push_back("scaledAngle");
+    mReservedUniforms.push_back("sunAngle2");
+
+    mReservedUniforms.push_back("camPosLocal");
 // [RLVa:KB] - @setsphere
-	mReservedUniforms.push_back("rlvEffectMode");
-	mReservedUniforms.push_back("rlvEffectParam1");
-	mReservedUniforms.push_back("rlvEffectParam2");
-	mReservedUniforms.push_back("rlvEffectParam3");
-	mReservedUniforms.push_back("rlvEffectParam4");
-	mReservedUniforms.push_back("rlvEffectParam5");
+    mReservedUniforms.push_back("rlvEffectMode");
+    mReservedUniforms.push_back("rlvEffectParam1");
+    mReservedUniforms.push_back("rlvEffectParam2");
+    mReservedUniforms.push_back("rlvEffectParam3");
+    mReservedUniforms.push_back("rlvEffectParam4");
+    mReservedUniforms.push_back("rlvEffectParam5");
 // [/RLV:KB]
 
-	mReservedUniforms.push_back("gWindDir");
-	mReservedUniforms.push_back("gSinWaveParams");
-	mReservedUniforms.push_back("gGravity");
-
-	mReservedUniforms.push_back("detail_0");
-	mReservedUniforms.push_back("detail_1");
-	mReservedUniforms.push_back("detail_2");
-	mReservedUniforms.push_back("detail_3");
-
-	mReservedUniforms.push_back("alpha_ramp");
-
-	mReservedUniforms.push_back("detail_0_base_color");
-	mReservedUniforms.push_back("detail_1_base_color");
-	mReservedUniforms.push_back("detail_2_base_color");
-	mReservedUniforms.push_back("detail_3_base_color");
-	mReservedUniforms.push_back("detail_0_normal");
-	mReservedUniforms.push_back("detail_1_normal");
-	mReservedUniforms.push_back("detail_2_normal");
-	mReservedUniforms.push_back("detail_3_normal");
-	mReservedUniforms.push_back("detail_0_metallic_roughness");
-	mReservedUniforms.push_back("detail_1_metallic_roughness");
-	mReservedUniforms.push_back("detail_2_metallic_roughness");
-	mReservedUniforms.push_back("detail_3_metallic_roughness");
-	mReservedUniforms.push_back("detail_0_emissive");
-	mReservedUniforms.push_back("detail_1_emissive");
-	mReservedUniforms.push_back("detail_2_emissive");
-	mReservedUniforms.push_back("detail_3_emissive");
+    mReservedUniforms.push_back("gWindDir");
+    mReservedUniforms.push_back("gSinWaveParams");
+    mReservedUniforms.push_back("gGravity");
+
+    mReservedUniforms.push_back("detail_0");
+    mReservedUniforms.push_back("detail_1");
+    mReservedUniforms.push_back("detail_2");
+    mReservedUniforms.push_back("detail_3");
+
+    mReservedUniforms.push_back("alpha_ramp");
+
+    mReservedUniforms.push_back("detail_0_base_color");
+    mReservedUniforms.push_back("detail_1_base_color");
+    mReservedUniforms.push_back("detail_2_base_color");
+    mReservedUniforms.push_back("detail_3_base_color");
+    mReservedUniforms.push_back("detail_0_normal");
+    mReservedUniforms.push_back("detail_1_normal");
+    mReservedUniforms.push_back("detail_2_normal");
+    mReservedUniforms.push_back("detail_3_normal");
+    mReservedUniforms.push_back("detail_0_metallic_roughness");
+    mReservedUniforms.push_back("detail_1_metallic_roughness");
+    mReservedUniforms.push_back("detail_2_metallic_roughness");
+    mReservedUniforms.push_back("detail_3_metallic_roughness");
+    mReservedUniforms.push_back("detail_0_emissive");
+    mReservedUniforms.push_back("detail_1_emissive");
+    mReservedUniforms.push_back("detail_2_emissive");
+    mReservedUniforms.push_back("detail_3_emissive");
 
     mReservedUniforms.push_back("baseColorFactors");
     mReservedUniforms.push_back("metallicFactors");
@@ -1435,8 +1435,8 @@ void LLShaderMgr::initAttribsAndUniforms()
     mReservedUniforms.push_back("emissiveColors");
     mReservedUniforms.push_back("minimum_alphas");
 
-	mReservedUniforms.push_back("origin");
-	mReservedUniforms.push_back("display_gamma");
+    mReservedUniforms.push_back("origin");
+    mReservedUniforms.push_back("display_gamma");
 
     mReservedUniforms.push_back("inscatter");
     mReservedUniforms.push_back("sun_size");
@@ -1469,21 +1469,21 @@ void LLShaderMgr::initAttribsAndUniforms()
 
     mReservedUniforms.push_back("debug_normal_draw_length");
 
-	// Alchemy
-	mReservedUniforms.push_back("colorgrade_lut");
-	mReservedUniforms.push_back("colorgrade_lut_size");
+    // Alchemy
+    mReservedUniforms.push_back("colorgrade_lut");
+    mReservedUniforms.push_back("colorgrade_lut_size");
 
-	llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS);
+    llassert(mReservedUniforms.size() == END_RESERVED_UNIFORMS);
 
-	std::set<std::string> dupe_check;
+    std::set<std::string> dupe_check;
 
-	for (U32 i = 0; i < mReservedUniforms.size(); ++i)
-	{
-		if (dupe_check.find(mReservedUniforms[i]) != dupe_check.end())
-		{
-			LL_ERRS() << "Duplicate reserved uniform name found: " << mReservedUniforms[i] << LL_ENDL;
-		}
-		dupe_check.insert(mReservedUniforms[i]);
-	}
+    for (U32 i = 0; i < mReservedUniforms.size(); ++i)
+    {
+        if (dupe_check.find(mReservedUniforms[i]) != dupe_check.end())
+        {
+            LL_ERRS() << "Duplicate reserved uniform name found: " << mReservedUniforms[i] << LL_ENDL;
+        }
+        dupe_check.insert(mReservedUniforms[i]);
+    }
 }
 
diff --git a/indra/llrender/llshadermgr.h b/indra/llrender/llshadermgr.h
index ab9529d0d9c59015cee5ca029e89d072189eb42a..bb0623f58c3a452f074c98c8dd1556cba554d43d 100644
--- a/indra/llrender/llshadermgr.h
+++ b/indra/llrender/llshadermgr.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llshadermgr.h
  * @brief Shader Manager
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -33,8 +33,8 @@
 class LLShaderMgr
 {
 public:
-	LLShaderMgr() = default;
-	virtual ~LLShaderMgr() = default;
+    LLShaderMgr() = default;
+    virtual ~LLShaderMgr() = default;
 
     // clang-format off
     typedef enum
@@ -247,12 +247,12 @@ class LLShaderMgr
 
         WL_CAMPOSLOCAL,                     //  "camPosLocal"
 // [RLVa:KB] - @setsphere
-		RLV_EFFECT_MODE,
-		RLV_EFFECT_PARAM1,
-		RLV_EFFECT_PARAM2,
-		RLV_EFFECT_PARAM3,
-		RLV_EFFECT_PARAM4,
-		RLV_EFFECT_PARAM5,
+        RLV_EFFECT_MODE,
+        RLV_EFFECT_PARAM1,
+        RLV_EFFECT_PARAM2,
+        RLV_EFFECT_PARAM3,
+        RLV_EFFECT_PARAM4,
+        RLV_EFFECT_PARAM5,
 // [/RLVa:KB]
 
         AVATAR_WIND,                        //  "gWindDir"
@@ -333,23 +333,23 @@ class LLShaderMgr
     } eGLSLReservedUniforms;
     // clang-format on
 
-	// singleton pattern implementation
-	static LLShaderMgr * instance();
+    // singleton pattern implementation
+    static LLShaderMgr * instance();
 
-	virtual void initAttribsAndUniforms(void);
+    virtual void initAttribsAndUniforms(void);
 
-	BOOL attachShaderFeatures(LLGLSLShader * shader);
-	void dumpObjectLog(GLuint ret, BOOL warns = TRUE, const std::string& filename = "");
+    BOOL attachShaderFeatures(LLGLSLShader * shader);
+    void dumpObjectLog(GLuint ret, BOOL warns = TRUE, const std::string& filename = "");
     void dumpShaderSource(U32 shader_code_count, GLchar** shader_code_text);
-	BOOL	linkProgramObject(GLuint obj, BOOL suppress_errors = FALSE);
-	BOOL	validateProgramObject(GLuint obj);
-	GLuint loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, std::map<std::string, std::string>* defines = NULL, S32 texture_index_channels = -1);
+    BOOL    linkProgramObject(GLuint obj, BOOL suppress_errors = FALSE);
+    BOOL    validateProgramObject(GLuint obj);
+    GLuint loadShaderFile(const std::string& filename, S32 & shader_level, GLenum type, std::map<std::string, std::string>* defines = NULL, S32 texture_index_channels = -1);
 
-	// Implemented in the application to actually point to the shader directory.
-	virtual std::string getShaderDirPrefix(void) = 0; // Pure Virtual
+    // Implemented in the application to actually point to the shader directory.
+    virtual std::string getShaderDirPrefix(void) = 0; // Pure Virtual
 
-	// Implemented in the application to actually update out of date uniforms for a particular shader
-	virtual void updateShaderUniforms(LLGLSLShader * shader) = 0; // Pure Virtual
+    // Implemented in the application to actually update out of date uniforms for a particular shader
+    virtual void updateShaderUniforms(LLGLSLShader * shader) = 0; // Pure Virtual
 
     void initShaderCache(bool enabled, const LLUUID& old_cache_version, const LLUUID& current_cache_version);
     void clearShaderCache();
@@ -362,10 +362,10 @@ class LLShaderMgr
     boost::unordered_map<std::string, GLuint, al::string_hash, std::equal_to<>> mVertexShaderObjects;
     boost::unordered_map<std::string, GLuint, al::string_hash, std::equal_to<>> mFragmentShaderObjects;
 
-	//global (reserved slot) shader parameters
-	std::vector<std::string> mReservedAttribs;
+    //global (reserved slot) shader parameters
+    std::vector<std::string> mReservedAttribs;
 
-	std::vector<std::string> mReservedUniforms;
+    std::vector<std::string> mReservedUniforms;
 
     struct ProgramBinaryData
     {
@@ -381,8 +381,8 @@ class LLShaderMgr
 
 protected:
 
-	// our parameter manager singleton instance
-	static LLShaderMgr * sInstance;
+    // our parameter manager singleton instance
+    static LLShaderMgr * sInstance;
 
 }; //LLShaderMgr
 
diff --git a/indra/llrender/llvertexbuffer.cpp b/indra/llrender/llvertexbuffer.cpp
index 66409cf148487980138a2195d2b1c22dd5cb2752..4738daad5ba3621d4f98c5827900e9645414cddf 100644
--- a/indra/llrender/llvertexbuffer.cpp
+++ b/indra/llrender/llvertexbuffer.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvertexbuffer.cpp
  * @brief LLVertexBuffer implementation
  *
  * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -41,25 +41,25 @@
 //helper function, returns first number > v that is a power of 2, or v if v is already a power of 2
 U32 nhpo2(U32 v)
 {
-	U32 r = 1;
-	while (r < v) {
-		r *= 2;
-	}
-	return r;
+    U32 r = 1;
+    while (r < v) {
+        r *= 2;
+    }
+    return r;
 }
 
 //which power of 2 is i?
 //assumes i is a power of 2 > 0
 U32 wpo2(U32 i)
 {
-	llassert(i > 0);
-	llassert(nhpo2(i) == i);
+    llassert(i > 0);
+    llassert(nhpo2(i) == i);
 
-	U32 r = 0;
+    U32 r = 0;
 
-	while (i >>= 1) ++r;
+    while (i >>= 1) ++r;
 
-	return r;
+    return r;
 }
 
 struct CompareMappedRegion
@@ -386,7 +386,7 @@ class LLVBOPool
             Entry& entry = entries.back();
             name = entry.mGLName;
             data = entry.mData;
-            
+
             entries.pop_back();
             if (entries.empty())
             {
@@ -481,9 +481,9 @@ class LLVBOPool
         if(!names_to_free.empty()) glDeleteBuffers(names_to_free.size(), names_to_free.data());
 
 #if 0
-        LL_INFOS() << llformat("(%d/%d)/%d MB (distributed/allocated)/total in VBO Pool. Overhead: %d percent. Hit rate: %d percent", 
-            mDistributed / 1000000, 
-            mAllocated / 1000000, 
+        LL_INFOS() << llformat("(%d/%d)/%d MB (distributed/allocated)/total in VBO Pool. Overhead: %d percent. Hit rate: %d percent",
+            mDistributed / 1000000,
+            mAllocated / 1000000,
             (mAllocated + mReserved) / 1000000, // total bytes
             ((mAllocated+mReserved-mDistributed)*100)/llmax(mDistributed, (U64) 1), // overhead percent
             (mHits*100)/llmax(mMisses+mHits, (U32)1)) // hit rate percent
@@ -531,7 +531,7 @@ U64 LLVertexBuffer::getBytesAllocated()
 }
 
 //============================================================================
-// 
+//
 //static
 U32 LLVertexBuffer::sGLRenderBuffer = 0;
 U32 LLVertexBuffer::sGLRenderIndices = 0;
@@ -543,49 +543,49 @@ GLuint LLVertexBuffer::sDummyVAO = 0;
 //NOTE: each component must be AT LEAST 4 bytes in size to avoid a performance penalty on AMD hardware
 const U32 LLVertexBuffer::sTypeSize[LLVertexBuffer::TYPE_MAX] =
 {
-	sizeof(LLVector4), // TYPE_VERTEX,
-	sizeof(LLVector4), // TYPE_NORMAL,
-	sizeof(LLVector2), // TYPE_TEXCOORD0,
-	sizeof(LLVector2), // TYPE_TEXCOORD1,
-	sizeof(LLVector2), // TYPE_TEXCOORD2,
-	sizeof(LLVector2), // TYPE_TEXCOORD3,
-	sizeof(LLColor4U), // TYPE_COLOR,
-	sizeof(LLColor4U), // TYPE_EMISSIVE, only alpha is used currently
-	sizeof(LLVector4), // TYPE_TANGENT,
-	sizeof(F32),	   // TYPE_WEIGHT,
-	sizeof(LLVector4), // TYPE_WEIGHT4,
-	sizeof(LLVector4), // TYPE_CLOTHWEIGHT,
-	sizeof(LLVector4), // TYPE_TEXTURE_INDEX (actually exists as position.w), no extra data, but stride is 16 bytes
+    sizeof(LLVector4), // TYPE_VERTEX,
+    sizeof(LLVector4), // TYPE_NORMAL,
+    sizeof(LLVector2), // TYPE_TEXCOORD0,
+    sizeof(LLVector2), // TYPE_TEXCOORD1,
+    sizeof(LLVector2), // TYPE_TEXCOORD2,
+    sizeof(LLVector2), // TYPE_TEXCOORD3,
+    sizeof(LLColor4U), // TYPE_COLOR,
+    sizeof(LLColor4U), // TYPE_EMISSIVE, only alpha is used currently
+    sizeof(LLVector4), // TYPE_TANGENT,
+    sizeof(F32),       // TYPE_WEIGHT,
+    sizeof(LLVector4), // TYPE_WEIGHT4,
+    sizeof(LLVector4), // TYPE_CLOTHWEIGHT,
+    sizeof(LLVector4), // TYPE_TEXTURE_INDEX (actually exists as position.w), no extra data, but stride is 16 bytes
 };
 
 static const std::string vb_type_name[] =
 {
-	"TYPE_VERTEX",
-	"TYPE_NORMAL",
-	"TYPE_TEXCOORD0",
-	"TYPE_TEXCOORD1",
-	"TYPE_TEXCOORD2",
-	"TYPE_TEXCOORD3",
-	"TYPE_COLOR",
-	"TYPE_EMISSIVE",
-	"TYPE_TANGENT",
-	"TYPE_WEIGHT",
-	"TYPE_WEIGHT4",
-	"TYPE_CLOTHWEIGHT",
-	"TYPE_TEXTURE_INDEX",
-	"TYPE_MAX",
-	"TYPE_INDEX",	
+    "TYPE_VERTEX",
+    "TYPE_NORMAL",
+    "TYPE_TEXCOORD0",
+    "TYPE_TEXCOORD1",
+    "TYPE_TEXCOORD2",
+    "TYPE_TEXCOORD3",
+    "TYPE_COLOR",
+    "TYPE_EMISSIVE",
+    "TYPE_TANGENT",
+    "TYPE_WEIGHT",
+    "TYPE_WEIGHT4",
+    "TYPE_CLOTHWEIGHT",
+    "TYPE_TEXTURE_INDEX",
+    "TYPE_MAX",
+    "TYPE_INDEX",
 };
 
 const U32 LLVertexBuffer::sGLMode[LLRender::NUM_MODES] =
 {
-	GL_TRIANGLES,
-	GL_TRIANGLE_STRIP,
-	GL_TRIANGLE_FAN,
-	GL_POINTS,
-	GL_LINES,
-	GL_LINE_STRIP,
-	GL_LINE_LOOP,
+    GL_TRIANGLES,
+    GL_TRIANGLE_STRIP,
+    GL_TRIANGLE_FAN,
+    GL_POINTS,
+    GL_LINES,
+    GL_LINE_STRIP,
+    GL_LINE_LOOP,
 };
 
 //static
@@ -607,7 +607,7 @@ void LLVertexBuffer::setupClientArrays(U32 data_mask)
                 }
             }
             else
-            {	//was disabled
+            {   //was disabled
                 if (data_mask & mask)
                 { //needs to be enabled
                     glEnableVertexAttribArray(loc);
@@ -636,18 +636,18 @@ void LLVertexBuffer::drawArrays(U32 mode, const std::vector<LLVector3>& pos)
 void LLVertexBuffer::drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, U32 num_indices, const U16* indicesp)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX;
-	llassert(LLGLSLShader::sCurBoundShaderPtr != NULL);
+    llassert(LLGLSLShader::sCurBoundShaderPtr != NULL);
 
-	gGL.syncMatrices();
+    gGL.syncMatrices();
 
-	U32 mask = LLVertexBuffer::MAP_VERTEX;
-	if (tc)
-	{
-		mask = mask | LLVertexBuffer::MAP_TEXCOORD0;
-	}
+    U32 mask = LLVertexBuffer::MAP_VERTEX;
+    if (tc)
+    {
+        mask = mask | LLVertexBuffer::MAP_TEXCOORD0;
+    }
+
+    unbind();
 
-	unbind();
-	
     gGL.begin(mode);
 
     if (tc != nullptr)
@@ -681,32 +681,32 @@ bool LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of
     llassert(start < (U32)mNumVerts);
     llassert(end < (U32)mNumVerts);
 
-	if (start >= (U32) mNumVerts ||
-	    end >= (U32) mNumVerts)
-	{
-		LL_ERRS() << "Bad vertex buffer draw range: [" << start << ", " << end << "] vs " << mNumVerts << LL_ENDL;
-	}
+    if (start >= (U32) mNumVerts ||
+        end >= (U32) mNumVerts)
+    {
+        LL_ERRS() << "Bad vertex buffer draw range: [" << start << ", " << end << "] vs " << mNumVerts << LL_ENDL;
+    }
 
-	llassert(mNumIndices >= 0);
+    llassert(mNumIndices >= 0);
 
-	if (indices_offset >= (U32) mNumIndices ||
-	    indices_offset + count > (U32) mNumIndices)
-	{
-		LL_ERRS() << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << LL_ENDL;
-	}
+    if (indices_offset >= (U32) mNumIndices ||
+        indices_offset + count > (U32) mNumIndices)
+    {
+        LL_ERRS() << "Bad index buffer draw range: [" << indices_offset << ", " << indices_offset+count << "]" << LL_ENDL;
+    }
 
-	{
-		U16* idx = (U16*) mMappedIndexData+indices_offset;
-		for (U32 i = 0; i < count; ++i)
-		{
+    {
+        U16* idx = (U16*) mMappedIndexData+indices_offset;
+        for (U32 i = 0; i < count; ++i)
+        {
             llassert(idx[i] >= start);
             llassert(idx[i] <= end);
 
-			if (idx[i] < start || idx[i] > end)
-			{
-				LL_ERRS() << "Index out of range: " << idx[i] << " not in [" << start << ", " << end << "]" << LL_ENDL;
-			}
-		}
+            if (idx[i] < start || idx[i] > end)
+            {
+                LL_ERRS() << "Index out of range: " << idx[i] << " not in [" << start << ", " << end << "]" << LL_ENDL;
+            }
+        }
 
         LLVector4a* v = (LLVector4a*)mMappedData;
 
@@ -718,29 +718,29 @@ bool LLVertexBuffer::validateRange(U32 start, U32 end, U32 count, U32 indices_of
             }
         }
 
-		LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+        LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+
+        if (shader && shader->mFeatures.mIndexedTextureChannels > 1)
+        {
+            LLVector4a* v = (LLVector4a*) mMappedData;
 
-		if (shader && shader->mFeatures.mIndexedTextureChannels > 1)
-		{
-			LLVector4a* v = (LLVector4a*) mMappedData;
-			
-			for (U32 i = start; i < end; i++)
-			{
+            for (U32 i = start; i < end; i++)
+            {
                 U32 idx = (U32) (v[i][3]+0.25f);
-				if (idx >= shader->mFeatures.mIndexedTextureChannels)
-				{
-					LL_ERRS() << "Bad texture index found in vertex data stream." << LL_ENDL;
-				}
-			}
-		}
-	}
+                if (idx >= shader->mFeatures.mIndexedTextureChannels)
+                {
+                    LL_ERRS() << "Bad texture index found in vertex data stream." << LL_ENDL;
+                }
+            }
+        }
+    }
 
     return true;
 }
 
 #ifdef LL_PROFILER_ENABLE_RENDER_DOC
 void LLVertexBuffer::setLabel(const char* label) {
-	LL_LABEL_OBJECT_GL(GL_BUFFER, mGLBuffer, strlen(label), label);
+    LL_LABEL_OBJECT_GL(GL_BUFFER, mGLBuffer, strlen(label), label);
 }
 #endif
 
@@ -765,7 +765,7 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const
     llassert(first + count <= mNumVerts);
     llassert(mGLBuffer == sGLRenderBuffer);
     llassert(mGLIndices == sGLRenderIndices);
-    
+
     gGL.syncMatrices();
     glDrawArrays(sGLMode[mode], first, count);
 }
@@ -774,21 +774,21 @@ void LLVertexBuffer::drawArrays(U32 mode, U32 first, U32 count) const
 void LLVertexBuffer::initClass(LLWindow* window)
 {
 #ifdef GL_ARB_vertex_array_object
-	if (LLRender::sGLCoreProfile)
-	{
-		if (sDummyVAO != 0)
-		{
-			glBindVertexArray(0);
-			glDeleteVertexArrays(1, &sDummyVAO);
-			sDummyVAO = 0;
-		}
-
-		{ //bind a dummy vertex array object so we're core profile compliant
-			glGenVertexArrays(1, &sDummyVAO);
-			glBindVertexArray(sDummyVAO);
-		}
-		stop_glerror();
-	}
+    if (LLRender::sGLCoreProfile)
+    {
+        if (sDummyVAO != 0)
+        {
+            glBindVertexArray(0);
+            glDeleteVertexArrays(1, &sDummyVAO);
+            sDummyVAO = 0;
+        }
+
+        { //bind a dummy vertex array object so we're core profile compliant
+            glGenVertexArrays(1, &sDummyVAO);
+            glBindVertexArray(sDummyVAO);
+        }
+        stop_glerror();
+    }
 #endif
 
     llassert(sVBOPool == nullptr);
@@ -805,32 +805,32 @@ void LLVertexBuffer::initClass(LLWindow* window)
 #endif
 }
 
-//static 
+//static
 void LLVertexBuffer::unbind()
 {
     glBindBuffer(GL_ARRAY_BUFFER, 0);
-	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
 
-	sGLRenderBuffer = 0;
-	sGLRenderIndices = 0;
+    sGLRenderBuffer = 0;
+    sGLRenderIndices = 0;
 }
 
 //static
 void LLVertexBuffer::cleanupClass()
 {
-	unbind();
-	
+    unbind();
+
     delete sVBOPool;
     sVBOPool = nullptr;
 
-	if (sDummyVAO != 0)
-	{
+    if (sDummyVAO != 0)
+    {
 #ifdef GL_ARB_vertex_array_object
-		glBindVertexArray(0);
-		glDeleteVertexArrays(1, &sDummyVAO);
+        glBindVertexArray(0);
+        glDeleteVertexArrays(1, &sDummyVAO);
 #endif
-		sDummyVAO = 0;
-	}
+        sDummyVAO = 0;
+    }
 
 #if ENABLE_GL_WORK_QUEUE
     sQueue->close();
@@ -848,71 +848,71 @@ void LLVertexBuffer::cleanupClass()
 
 //----------------------------------------------------------------------------
 
-LLVertexBuffer::LLVertexBuffer(U32 typemask) 
-:	LLRefCount(),
-	mTypeMask(typemask)
+LLVertexBuffer::LLVertexBuffer(U32 typemask)
+:   LLRefCount(),
+    mTypeMask(typemask)
 {
-	//zero out offsets
-	for (U32 i = 0; i < TYPE_MAX; i++)
-	{
-		mOffsets[i] = 0;
-	}
+    //zero out offsets
+    for (U32 i = 0; i < TYPE_MAX; i++)
+    {
+        mOffsets[i] = 0;
+    }
 }
 
 //static
 U32 LLVertexBuffer::calcOffsets(const U32& typemask, U32* offsets, U32 num_vertices)
 {
     U32 offset = 0;
-	for (U32 i=0; i<TYPE_TEXTURE_INDEX; i++)
-	{
-		U32 mask = 1<<i;
-		if (typemask & mask)
-		{
-			if (offsets && LLVertexBuffer::sTypeSize[i])
-			{
-				offsets[i] = offset;
-				offset += LLVertexBuffer::sTypeSize[i]*num_vertices;
-				offset = (offset + 0xF) & ~0xF;
-			}
-		}
-	}
-
-	offsets[TYPE_TEXTURE_INDEX] = offsets[TYPE_VERTEX] + 12;
-	
-	return offset;
-}
-
-//static 
+    for (U32 i=0; i<TYPE_TEXTURE_INDEX; i++)
+    {
+        U32 mask = 1<<i;
+        if (typemask & mask)
+        {
+            if (offsets && LLVertexBuffer::sTypeSize[i])
+            {
+                offsets[i] = offset;
+                offset += LLVertexBuffer::sTypeSize[i]*num_vertices;
+                offset = (offset + 0xF) & ~0xF;
+            }
+        }
+    }
+
+    offsets[TYPE_TEXTURE_INDEX] = offsets[TYPE_VERTEX] + 12;
+
+    return offset;
+}
+
+//static
 U32 LLVertexBuffer::calcVertexSize(const U32& typemask)
 {
     U32 size = 0;
-	for (U32 i = 0; i < TYPE_TEXTURE_INDEX; i++)
-	{
-		U32 mask = 1<<i;
-		if (typemask & mask)
-		{
-			size += LLVertexBuffer::sTypeSize[i];
-		}
-	}
+    for (U32 i = 0; i < TYPE_TEXTURE_INDEX; i++)
+    {
+        U32 mask = 1<<i;
+        if (typemask & mask)
+        {
+            size += LLVertexBuffer::sTypeSize[i];
+        }
+    }
 
-	return size;
+    return size;
 }
 
 // protected, use unref()
 //virtual
 LLVertexBuffer::~LLVertexBuffer()
 {
-	destroyGLBuffer();
-	destroyGLIndices();
-
-	if (mMappedData)
-	{
-		LL_ERRS() << "Failed to clear vertex buffer's vertices" << LL_ENDL;
-	}
-	if (mMappedIndexData)
-	{
-		LL_ERRS() << "Failed to clear vertex buffer's indices" << LL_ENDL;
-	}
+    destroyGLBuffer();
+    destroyGLIndices();
+
+    if (mMappedData)
+    {
+        LL_ERRS() << "Failed to clear vertex buffer's vertices" << LL_ENDL;
+    }
+    if (mMappedIndexData)
+    {
+        LL_ERRS() << "Failed to clear vertex buffer's indices" << LL_ENDL;
+    }
 };
 
 //----------------------------------------------------------------------------
@@ -950,54 +950,54 @@ void LLVertexBuffer::genIndices(U32 size)
 
 bool LLVertexBuffer::createGLBuffer(U32 size)
 {
-	if (mGLBuffer || mMappedData)
-	{
-		destroyGLBuffer();
-	}
+    if (mGLBuffer || mMappedData)
+    {
+        destroyGLBuffer();
+    }
+
+    if (size == 0)
+    {
+        return true;
+    }
 
-	if (size == 0)
-	{
-		return true;
-	}
+    bool success = true;
 
-	bool success = true;
+    genBuffer(size);
 
-	genBuffer(size);
-	
-	if (!mMappedData)
-	{
-		success = false;
-	}
-	return success;
+    if (!mMappedData)
+    {
+        success = false;
+    }
+    return success;
 }
 
 bool LLVertexBuffer::createGLIndices(U32 size)
 {
-	if (mGLIndices)
-	{
-		destroyGLIndices();
-	}
-	
-	if (size == 0)
-	{
-		return true;
-	}
+    if (mGLIndices)
+    {
+        destroyGLIndices();
+    }
+
+    if (size == 0)
+    {
+        return true;
+    }
+
+    bool success = true;
 
-	bool success = true;
+    genIndices(size);
 
-	genIndices(size);
-	
-	if (!mMappedIndexData)
-	{
-		success = false;
-	}
-	return success;
+    if (!mMappedIndexData)
+    {
+        success = false;
+    }
+    return success;
 }
 
 void LLVertexBuffer::destroyGLBuffer()
 {
-	if (mGLBuffer || mMappedData)
-	{
+    if (mGLBuffer || mMappedData)
+    {
         LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX;
         //llassert(sVBOPool);
         if (sVBOPool)
@@ -1008,13 +1008,13 @@ void LLVertexBuffer::destroyGLBuffer()
         mSize = 0;
         mGLBuffer = 0;
         mMappedData = nullptr;
-	}
+    }
 }
 
 void LLVertexBuffer::destroyGLIndices()
 {
-	if (mGLIndices || mMappedIndexData)
-	{
+    if (mGLIndices || mMappedIndexData)
+    {
         LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX;
         //llassert(sVBOPool);
         if (sVBOPool)
@@ -1025,22 +1025,22 @@ void LLVertexBuffer::destroyGLIndices()
         mIndicesSize = 0;
         mGLIndices = 0;
         mMappedIndexData = nullptr;
-	}
+    }
 }
 
 bool LLVertexBuffer::updateNumVerts(U32 nverts)
 {
-	llassert(nverts >= 0);
+    llassert(nverts >= 0);
 
-	bool success = true;
+    bool success = true;
 
-	if (nverts > 65536)
-	{
-		LL_WARNS() << "Vertex buffer overflow!" << LL_ENDL;
-		nverts = 65536;
-	}
+    if (nverts > 65536)
+    {
+        LL_WARNS() << "Vertex buffer overflow!" << LL_ENDL;
+        nverts = 65536;
+    }
 
-	U32 needed_size = calcOffsets(mTypeMask, mOffsets, nverts);
+    U32 needed_size = calcOffsets(mTypeMask, mOffsets, nverts);
 
     if (needed_size != mSize)
     {
@@ -1048,42 +1048,42 @@ bool LLVertexBuffer::updateNumVerts(U32 nverts)
     }
 
     llassert(mSize == needed_size);
-	mNumVerts = nverts;
-	return success;
+    mNumVerts = nverts;
+    return success;
 }
 
 bool LLVertexBuffer::updateNumIndices(U32 nindices)
 {
-	llassert(nindices >= 0);
+    llassert(nindices >= 0);
 
-	bool success = true;
+    bool success = true;
 
-	U32 needed_size = sizeof(U16) * nindices;
+    U32 needed_size = sizeof(U16) * nindices;
 
-	if (needed_size != mIndicesSize)
-	{
-		success &= createGLIndices(needed_size);
-	}
+    if (needed_size != mIndicesSize)
+    {
+        success &= createGLIndices(needed_size);
+    }
 
     llassert(mIndicesSize == needed_size);
-	mNumIndices = nindices;
-	return success;
+    mNumIndices = nindices;
+    return success;
 }
 
 bool LLVertexBuffer::allocateBuffer(U32 nverts, U32 nindices)
 {
-	if (nverts < 0 || nindices < 0 ||
-		nverts > 65536)
-	{
-		LL_ERRS() << "Bad vertex buffer allocation: " << nverts << " : " << nindices << LL_ENDL;
-	}
+    if (nverts < 0 || nindices < 0 ||
+        nverts > 65536)
+    {
+        LL_ERRS() << "Bad vertex buffer allocation: " << nverts << " : " << nindices << LL_ENDL;
+    }
 
-	bool success = true;
+    bool success = true;
 
-	success &= updateNumVerts(nverts);
-	success &= updateNumIndices(nindices);
-	
-	return success;
+    success &= updateNumVerts(nverts);
+    success &= updateNumIndices(nindices);
+
+    return success;
 }
 
 //----------------------------------------------------------------------------
@@ -1092,17 +1092,17 @@ bool LLVertexBuffer::allocateBuffer(U32 nverts, U32 nindices)
 // otherwise return false
 bool expand_region(LLVertexBuffer::MappedRegion& region, U32 start, U32 end)
 {
-	
-	if (end < region.mStart ||
-		start > region.mEnd)
-	{ //gap exists, do not merge
-		return false;
-	}
+
+    if (end < region.mStart ||
+        start > region.mEnd)
+    { //gap exists, do not merge
+        return false;
+    }
 
     region.mStart = llmin(region.mStart, start);
     region.mEnd = llmax(region.mEnd, end);
 
-	return true;
+    return true;
 }
 
 
@@ -1110,7 +1110,7 @@ bool expand_region(LLVertexBuffer::MappedRegion& region, U32 start, U32 end)
 U8* LLVertexBuffer::mapVertexBuffer(LLVertexBuffer::AttributeType type, U32 index, S32 count)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX;
-	
+
     if (count == -1)
     {
         count = mNumVerts - index;
@@ -1119,24 +1119,24 @@ U8* LLVertexBuffer::mapVertexBuffer(LLVertexBuffer::AttributeType type, U32 inde
     U32 start = mOffsets[type] + sTypeSize[type] * index;
     U32 end = start + sTypeSize[type] * count-1;
 
-	bool flagged = false;
-	// flag region as mapped
-	for (U32 i = 0; i < mMappedVertexRegions.size(); ++i)
-	{
-		MappedRegion& region = mMappedVertexRegions[i];
+    bool flagged = false;
+    // flag region as mapped
+    for (U32 i = 0; i < mMappedVertexRegions.size(); ++i)
+    {
+        MappedRegion& region = mMappedVertexRegions[i];
         if (expand_region(region, start, end))
         {
             flagged = true;
             break;
         }
-	}
+    }
 
-	if (!flagged)
-	{
-		//didn't expand an existing region, make a new one
+    if (!flagged)
+    {
+        //didn't expand an existing region, make a new one
         mMappedVertexRegions.push_back({ start, end });
-	}
-	
+    }
+
     return mMappedData+mOffsets[type]+sTypeSize[type]*index;
 }
 
@@ -1144,11 +1144,11 @@ U8* LLVertexBuffer::mapVertexBuffer(LLVertexBuffer::AttributeType type, U32 inde
 U8* LLVertexBuffer::mapIndexBuffer(U32 index, S32 count)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VERTEX;
-	
-	if (count == -1)
-	{
-		count = mNumIndices-index;
-	}
+
+    if (count == -1)
+    {
+        count = mNumIndices-index;
+    }
 
     U32 start = sizeof(U16) * index;
     U32 end = start + sizeof(U16) * count-1;
@@ -1211,23 +1211,23 @@ void LLVertexBuffer::unmapBuffer()
         }
     };
 
-	if (!mMappedVertexRegions.empty())
-	{
+    if (!mMappedVertexRegions.empty())
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - vertex");
         if (sGLRenderBuffer != mGLBuffer)
         {
             glBindBuffer(GL_ARRAY_BUFFER, mGLBuffer);
             sGLRenderBuffer = mGLBuffer;
         }
-            
+
         U32 start = 0;
         U32 end = 0;
 
         std::sort(mMappedVertexRegions.begin(), mMappedVertexRegions.end(), SortMappedRegion());
 
-		for (U32 i = 0; i < mMappedVertexRegions.size(); ++i)
-		{
-			const MappedRegion& region = mMappedVertexRegions[i];
+        for (U32 i = 0; i < mMappedVertexRegions.size(); ++i)
+        {
+            const MappedRegion& region = mMappedVertexRegions[i];
             if (region.mStart == end + 1)
             {
                 end = region.mEnd;
@@ -1238,15 +1238,15 @@ void LLVertexBuffer::unmapBuffer()
                 start = region.mStart;
                 end = region.mEnd;
             }
-		}
+        }
 
         flush_vbo(GL_ARRAY_BUFFER, start, end, (U8*)mMappedData + start);
 
-		mMappedVertexRegions.clear();
-	}
-	
-	if (!mMappedIndexRegions.empty())
-	{
+        mMappedVertexRegions.clear();
+    }
+
+    if (!mMappedIndexRegions.empty())
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_VERTEX("unmapBuffer - index");
 
         if (mGLIndices != sGLRenderIndices)
@@ -1276,120 +1276,120 @@ void LLVertexBuffer::unmapBuffer()
 
         flush_vbo(GL_ELEMENT_ARRAY_BUFFER, start, end, (U8*)mMappedIndexData + start);
 
-		mMappedIndexRegions.clear();
-	}
+        mMappedIndexRegions.clear();
+    }
 }
 
 //----------------------------------------------------------------------------
 
 template <class T,LLVertexBuffer::AttributeType type> struct VertexBufferStrider
 {
-	typedef LLStrider<T> strider_t;
-	static bool get(LLVertexBuffer& vbo, 
-					strider_t& strider, 
-					S32 index, S32 count)
-	{
-		if (type == LLVertexBuffer::TYPE_INDEX)
-		{
-			U8* ptr = vbo.mapIndexBuffer(index, count);
-
-			if (ptr == NULL)
-			{
-				LL_WARNS() << "mapIndexBuffer failed!" << LL_ENDL;
-				return false;
-			}
-
-			strider = (T*)ptr;
-			strider.setStride(0);
-			return true;
-		}
-		else if (vbo.hasDataType(type))
-		{
+    typedef LLStrider<T> strider_t;
+    static bool get(LLVertexBuffer& vbo,
+                    strider_t& strider,
+                    S32 index, S32 count)
+    {
+        if (type == LLVertexBuffer::TYPE_INDEX)
+        {
+            U8* ptr = vbo.mapIndexBuffer(index, count);
+
+            if (ptr == NULL)
+            {
+                LL_WARNS() << "mapIndexBuffer failed!" << LL_ENDL;
+                return false;
+            }
+
+            strider = (T*)ptr;
+            strider.setStride(0);
+            return true;
+        }
+        else if (vbo.hasDataType(type))
+        {
             U32 stride = LLVertexBuffer::sTypeSize[type];
 
-			U8* ptr = vbo.mapVertexBuffer(type, index, count);
-
-			if (ptr == NULL)
-			{
-				LL_WARNS() << "mapVertexBuffer failed!" << LL_ENDL;
-				return false;
-			}
-
-			strider = (T*)ptr;
-			strider.setStride(stride);
-			return true;
-		}
-		else
-		{
-			LL_ERRS() << "VertexBufferStrider could not find valid vertex data." << LL_ENDL;
-		}
-		return false;
-	}
+            U8* ptr = vbo.mapVertexBuffer(type, index, count);
+
+            if (ptr == NULL)
+            {
+                LL_WARNS() << "mapVertexBuffer failed!" << LL_ENDL;
+                return false;
+            }
+
+            strider = (T*)ptr;
+            strider.setStride(stride);
+            return true;
+        }
+        else
+        {
+            LL_ERRS() << "VertexBufferStrider could not find valid vertex data." << LL_ENDL;
+        }
+        return false;
+    }
 };
 
 bool LLVertexBuffer::getVertexStrider(LLStrider<LLVector3>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector3,TYPE_VERTEX>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector3,TYPE_VERTEX>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getVertexStrider(LLStrider<LLVector4a>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector4a,TYPE_VERTEX>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector4a,TYPE_VERTEX>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getIndexStrider(LLStrider<U16>& strider, U32 index, S32 count)
 {
     llassert(mIndicesStride == 2); // cannot access 32-bit indices with U16 strider
     llassert(mIndicesType == GL_UNSIGNED_SHORT);
-	return VertexBufferStrider<U16,TYPE_INDEX>::get(*this, strider, index, count);
+    return VertexBufferStrider<U16,TYPE_INDEX>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getTexCoord0Strider(LLStrider<LLVector2>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector2,TYPE_TEXCOORD0>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector2,TYPE_TEXCOORD0>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getTexCoord1Strider(LLStrider<LLVector2>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector2,TYPE_TEXCOORD1>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector2,TYPE_TEXCOORD1>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getTexCoord2Strider(LLStrider<LLVector2>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector2,TYPE_TEXCOORD2>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector2,TYPE_TEXCOORD2>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getNormalStrider(LLStrider<LLVector3>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector3,TYPE_NORMAL>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector3,TYPE_NORMAL>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getNormalStrider(LLStrider<LLVector4a>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector4a,TYPE_NORMAL>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector4a,TYPE_NORMAL>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getTangentStrider(LLStrider<LLVector3>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector3,TYPE_TANGENT>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector3,TYPE_TANGENT>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getTangentStrider(LLStrider<LLVector4a>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector4a,TYPE_TANGENT>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector4a,TYPE_TANGENT>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getColorStrider(LLStrider<LLColor4U>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLColor4U,TYPE_COLOR>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLColor4U,TYPE_COLOR>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getEmissiveStrider(LLStrider<LLColor4U>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLColor4U,TYPE_EMISSIVE>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLColor4U,TYPE_EMISSIVE>::get(*this, strider, index, count);
 }
 bool LLVertexBuffer::getWeightStrider(LLStrider<F32>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<F32,TYPE_WEIGHT>::get(*this, strider, index, count);
+    return VertexBufferStrider<F32,TYPE_WEIGHT>::get(*this, strider, index, count);
 }
 
 bool LLVertexBuffer::getWeight4Strider(LLStrider<LLVector4a>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector4a,TYPE_WEIGHT4>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector4a,TYPE_WEIGHT4>::get(*this, strider, index, count);
 }
 
 bool LLVertexBuffer::getClothWeightStrider(LLStrider<LLVector4a>& strider, U32 index, S32 count)
 {
-	return VertexBufferStrider<LLVector4a,TYPE_CLOTHWEIGHT>::get(*this, strider, index, count);
+    return VertexBufferStrider<LLVector4a,TYPE_CLOTHWEIGHT>::get(*this, strider, index, count);
 }
 
 //----------------------------------------------------------------------------
@@ -1409,7 +1409,7 @@ void LLVertexBuffer::setBuffer()
 
     // this Vertex Buffer must provide all necessary attributes for currently bound shader
     llassert_msg((data_mask & mTypeMask) == data_mask,
-        "Attribute mask mismatch! mTypeMask should be a superset of data_mask.  data_mask: 0x" 
+        "Attribute mask mismatch! mTypeMask should be a superset of data_mask.  data_mask: 0x"
                 << std::hex << data_mask << " mTypeMask: 0x" << mTypeMask << " Missing: 0x" << (data_mask & ~mTypeMask) <<  std::dec);
 
     if (sGLRenderBuffer != mGLBuffer)
@@ -1424,7 +1424,7 @@ void LLVertexBuffer::setBuffer()
         setupVertexBuffer();
         sLastMask = data_mask;
     }
-    
+
     if (mGLIndices != sGLRenderIndices)
     {
         glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mGLIndices);
diff --git a/indra/llrender/llvertexbuffer.h b/indra/llrender/llvertexbuffer.h
index e82a1dd7779e672db83793983f1b4cf323b62c20..ae0637fbaefb0be3cc1eb63ebbfc2f12dc695619 100644
--- a/indra/llrender/llvertexbuffer.h
+++ b/indra/llrender/llvertexbuffer.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvertexbuffer.h
  * @brief LLVertexBuffer wrapper for OpengGL vertex buffer objects
  *
  * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -51,51 +51,51 @@
 
 
 //============================================================================
-// base class 
+// base class
 class LLPrivateMemoryPool;
 class LLVertexBuffer final : public LLRefCount
 {
 public:
-	struct MappedRegion
-	{
+    struct MappedRegion
+    {
         U32 mStart;
         U32 mEnd;
-	};
+    };
 
-	LLVertexBuffer(const LLVertexBuffer& rhs)
-	{
-		*this = rhs;
-	}
+    LLVertexBuffer(const LLVertexBuffer& rhs)
+    {
+        *this = rhs;
+    }
 
-	const LLVertexBuffer& operator=(const LLVertexBuffer& rhs)
-	{
-		LL_ERRS() << "Illegal operation!" << LL_ENDL;
-		return *this;
-	}
+    const LLVertexBuffer& operator=(const LLVertexBuffer& rhs)
+    {
+        LL_ERRS() << "Illegal operation!" << LL_ENDL;
+        return *this;
+    }
 
-	static void initClass(LLWindow* window);
-	static void cleanupClass();
-	static void setupClientArrays(U32 data_mask);
-	static void drawArrays(U32 mode, const std::vector<LLVector3>& pos);
-	static void drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, U32 num_indices, const U16* indicesp);
+    static void initClass(LLWindow* window);
+    static void cleanupClass();
+    static void setupClientArrays(U32 data_mask);
+    static void drawArrays(U32 mode, const std::vector<LLVector3>& pos);
+    static void drawElements(U32 mode, const LLVector4a* pos, const LLVector2* tc, U32 num_indices, const U16* indicesp);
 
- 	static void unbind(); //unbind any bound vertex buffer
+    static void unbind(); //unbind any bound vertex buffer
 
-	//get the size of a vertex with the given typemask
-	static U32 calcVertexSize(const U32& typemask);
+    //get the size of a vertex with the given typemask
+    static U32 calcVertexSize(const U32& typemask);
 
-	//get the size of a buffer with the given typemask and vertex count
-	//fill offsets with the offset of each vertex component array into the buffer
-	// indexed by the following enum
-	static U32 calcOffsets(const U32& typemask, U32* offsets, U32 num_vertices);
+    //get the size of a buffer with the given typemask and vertex count
+    //fill offsets with the offset of each vertex component array into the buffer
+    // indexed by the following enum
+    static U32 calcOffsets(const U32& typemask, U32* offsets, U32 num_vertices);
 
-	//WARNING -- when updating these enums you MUST 
-	// 1 - update LLVertexBuffer::sTypeSize
+    //WARNING -- when updating these enums you MUST
+    // 1 - update LLVertexBuffer::sTypeSize
     // 2 - update LLVertexBuffer::vb_type_name
-	// 3 - add a strider accessor
-	// 4 - modify LLVertexBuffer::setupVertexBuffer
-	// 6 - modify LLViewerShaderMgr::mReservedAttribs
-	
+    // 3 - add a strider accessor
+    // 4 - modify LLVertexBuffer::setupVertexBuffer
+    // 6 - modify LLViewerShaderMgr::mReservedAttribs
+
     // clang-format off
     enum AttributeType {                      // Shader attribute name, set in LLShaderMgr::initAttribsAndUniforms()
         TYPE_VERTEX = 0,        //  "position"
@@ -112,83 +112,83 @@ class LLVertexBuffer final : public LLRefCount
         TYPE_CLOTHWEIGHT,       //  "clothing"
         TYPE_TEXTURE_INDEX,     //  "texture_index"
         TYPE_MAX,   // TYPE_MAX is the size/boundary marker for attributes that go in the vertex buffer
-        TYPE_INDEX,	// TYPE_INDEX is beyond _MAX because it lives in a separate (index) buffer	
+        TYPE_INDEX, // TYPE_INDEX is beyond _MAX because it lives in a separate (index) buffer
     };
     // clang-format on
 
     enum {
-		MAP_VERTEX = (1<<TYPE_VERTEX),
-		MAP_NORMAL = (1<<TYPE_NORMAL),
-		MAP_TEXCOORD0 = (1<<TYPE_TEXCOORD0),
-		MAP_TEXCOORD1 = (1<<TYPE_TEXCOORD1),
-		MAP_TEXCOORD2 = (1<<TYPE_TEXCOORD2),
-		MAP_TEXCOORD3 = (1<<TYPE_TEXCOORD3),
-		MAP_COLOR = (1<<TYPE_COLOR),
-		MAP_EMISSIVE = (1<<TYPE_EMISSIVE),
-		MAP_TANGENT = (1<<TYPE_TANGENT),
-		MAP_WEIGHT = (1<<TYPE_WEIGHT),
-		MAP_WEIGHT4 = (1<<TYPE_WEIGHT4),
-		MAP_CLOTHWEIGHT = (1<<TYPE_CLOTHWEIGHT),
-		MAP_TEXTURE_INDEX = (1<<TYPE_TEXTURE_INDEX),
-	};
-	
+        MAP_VERTEX = (1<<TYPE_VERTEX),
+        MAP_NORMAL = (1<<TYPE_NORMAL),
+        MAP_TEXCOORD0 = (1<<TYPE_TEXCOORD0),
+        MAP_TEXCOORD1 = (1<<TYPE_TEXCOORD1),
+        MAP_TEXCOORD2 = (1<<TYPE_TEXCOORD2),
+        MAP_TEXCOORD3 = (1<<TYPE_TEXCOORD3),
+        MAP_COLOR = (1<<TYPE_COLOR),
+        MAP_EMISSIVE = (1<<TYPE_EMISSIVE),
+        MAP_TANGENT = (1<<TYPE_TANGENT),
+        MAP_WEIGHT = (1<<TYPE_WEIGHT),
+        MAP_WEIGHT4 = (1<<TYPE_WEIGHT4),
+        MAP_CLOTHWEIGHT = (1<<TYPE_CLOTHWEIGHT),
+        MAP_TEXTURE_INDEX = (1<<TYPE_TEXTURE_INDEX),
+    };
+
 protected:
-	friend class LLRender;
+    friend class LLRender;
 
-	~LLVertexBuffer(); // use unref()
+    ~LLVertexBuffer(); // use unref()
 
-	void setupVertexBuffer();
+    void setupVertexBuffer();
 
-	void	genBuffer(U32 size);
-	void	genIndices(U32 size);
-	bool	createGLBuffer(U32 size);
-	bool	createGLIndices(U32 size);
-	void 	destroyGLBuffer();
-	void 	destroyGLIndices();
-	bool	updateNumVerts(U32 nverts);
-	bool	updateNumIndices(U32 nindices); 
+    void    genBuffer(U32 size);
+    void    genIndices(U32 size);
+    bool    createGLBuffer(U32 size);
+    bool    createGLIndices(U32 size);
+    void    destroyGLBuffer();
+    void    destroyGLIndices();
+    bool    updateNumVerts(U32 nverts);
+    bool    updateNumIndices(U32 nindices);
 
 public:
-	LLVertexBuffer(U32 typemask);
-	
+    LLVertexBuffer(U32 typemask);
+
     // allocate buffer
-    bool	allocateBuffer(U32 nverts, U32 nindices);
+    bool    allocateBuffer(U32 nverts, U32 nindices);
 
-	// map for data access (see also getFooStrider below)
-	U8*		mapVertexBuffer(AttributeType type, U32 index, S32 count = -1);
-	U8*		mapIndexBuffer(U32 index, S32 count = -1);
-    void	unmapBuffer();
+    // map for data access (see also getFooStrider below)
+    U8*     mapVertexBuffer(AttributeType type, U32 index, S32 count = -1);
+    U8*     mapIndexBuffer(U32 index, S32 count = -1);
+    void    unmapBuffer();
 
-	// set for rendering
+    // set for rendering
     // assumes (and will assert on) the following:
     //      - this buffer has no pending unampBuffer call
     //      - a shader is currently bound
     //      - This buffer has sufficient attributes within it to satisfy the needs of the currently bound shader
-	void	setBuffer();
-    		
-	// Only call each getVertexPointer, etc, once before calling unmapBuffer()
-	// call unmapBuffer() after calls to getXXXStrider() before any cals to setBuffer()
-	// example:
-	//   vb->getVertexBuffer(verts);
-	//   vb->getNormalStrider(norms);
-	//   setVertsNorms(verts, norms);
-	//   vb->unmapBuffer();
-	bool getVertexStrider(LLStrider<LLVector3>& strider, U32 index=0, S32 count = -1);
-	bool getVertexStrider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
-	bool getIndexStrider(LLStrider<U16>& strider, U32 index=0, S32 count = -1);
-	bool getTexCoord0Strider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
-	bool getTexCoord1Strider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
-	bool getTexCoord2Strider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
-	bool getNormalStrider(LLStrider<LLVector3>& strider, U32 index=0, S32 count = -1);
-	bool getNormalStrider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
-	bool getTangentStrider(LLStrider<LLVector3>& strider, U32 index=0, S32 count = -1);
-	bool getTangentStrider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
-	bool getColorStrider(LLStrider<LLColor4U>& strider, U32 index=0, S32 count = -1);
-	bool getEmissiveStrider(LLStrider<LLColor4U>& strider, U32 index=0, S32 count = -1);
-	bool getWeightStrider(LLStrider<F32>& strider, U32 index=0, S32 count = -1);
-	bool getWeight4Strider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
-	bool getClothWeightStrider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
-	
+    void    setBuffer();
+
+    // Only call each getVertexPointer, etc, once before calling unmapBuffer()
+    // call unmapBuffer() after calls to getXXXStrider() before any cals to setBuffer()
+    // example:
+    //   vb->getVertexBuffer(verts);
+    //   vb->getNormalStrider(norms);
+    //   setVertsNorms(verts, norms);
+    //   vb->unmapBuffer();
+    bool getVertexStrider(LLStrider<LLVector3>& strider, U32 index=0, S32 count = -1);
+    bool getVertexStrider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
+    bool getIndexStrider(LLStrider<U16>& strider, U32 index=0, S32 count = -1);
+    bool getTexCoord0Strider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
+    bool getTexCoord1Strider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
+    bool getTexCoord2Strider(LLStrider<LLVector2>& strider, U32 index=0, S32 count = -1);
+    bool getNormalStrider(LLStrider<LLVector3>& strider, U32 index=0, S32 count = -1);
+    bool getNormalStrider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
+    bool getTangentStrider(LLStrider<LLVector3>& strider, U32 index=0, S32 count = -1);
+    bool getTangentStrider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
+    bool getColorStrider(LLStrider<LLColor4U>& strider, U32 index=0, S32 count = -1);
+    bool getEmissiveStrider(LLStrider<LLColor4U>& strider, U32 index=0, S32 count = -1);
+    bool getWeightStrider(LLStrider<F32>& strider, U32 index=0, S32 count = -1);
+    bool getWeight4Strider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
+    bool getClothWeightStrider(LLStrider<LLVector4a>& strider, U32 index=0, S32 count = -1);
+
     void setPositionData(const LLVector4a* data);
     void setNormalData(const LLVector4a* data);
     void setTangentData(const LLVector4a* data);
@@ -198,76 +198,76 @@ class LLVertexBuffer final : public LLRefCount
     void setIndexData(const U16* data);
     void setIndexData(const U32* data);
 
-	U32 getNumVerts() const					{ return mNumVerts; }
-	U32 getNumIndices() const				{ return mNumIndices; }
-	
-	U32 getTypeMask() const					{ return mTypeMask; }
-	bool hasDataType(AttributeType type) const		{ return ((1 << type) & getTypeMask()); }
+    U32 getNumVerts() const                 { return mNumVerts; }
+    U32 getNumIndices() const               { return mNumIndices; }
+
+    U32 getTypeMask() const                 { return mTypeMask; }
+    bool hasDataType(AttributeType type) const      { return ((1 << type) & getTypeMask()); }
     U32 getSize() const                     { return mSize; }
-	U32 getIndicesSize() const				{ return mIndicesSize; }
-	U8* getMappedData() const				{ return mMappedData; }
-	U8* getMappedIndices() const			{ return mMappedIndexData; }
-	U32 getOffset(AttributeType type) const			{ return mOffsets[type]; }
-	
+    U32 getIndicesSize() const              { return mIndicesSize; }
+    U8* getMappedData() const               { return mMappedData; }
+    U8* getMappedIndices() const            { return mMappedIndexData; }
+    U32 getOffset(AttributeType type) const         { return mOffsets[type]; }
+
     // these functions assume (and assert on) the current VBO being bound
     // Detailed error checking can be enabled by setting gDebugGL to true
-	void draw(U32 mode, U32 count, U32 indices_offset) const;
-	void drawArrays(U32 mode, U32 offset, U32 count) const;
+    void draw(U32 mode, U32 count, U32 indices_offset) const;
+    void drawArrays(U32 mode, U32 offset, U32 count) const;
     void drawRange(U32 mode, U32 start, U32 end, U32 count, U32 indices_offset) const;
 
-	//for debugging, validate data in given range is valid
-	bool validateRange(U32 start, U32 end, U32 count, U32 offset) const;
+    //for debugging, validate data in given range is valid
+    bool validateRange(U32 start, U32 end, U32 count, U32 offset) const;
+
+    #ifdef LL_PROFILER_ENABLE_RENDER_DOC
+    void setLabel(const char* label);
+    #endif
 
-	#ifdef LL_PROFILER_ENABLE_RENDER_DOC
-	void setLabel(const char* label);
-	#endif
-	
 
-protected:	
-    U32		mGLBuffer = 0;		// GL VBO handle
-    U32		mGLIndices = 0;		// GL IBO handle
-    U32		mNumVerts = 0;		// Number of vertices allocated
-    U32		mNumIndices = 0;	// Number of indices allocated
+protected:
+    U32     mGLBuffer = 0;      // GL VBO handle
+    U32     mGLIndices = 0;     // GL IBO handle
+    U32     mNumVerts = 0;      // Number of vertices allocated
+    U32     mNumIndices = 0;    // Number of indices allocated
     U32     mIndicesType = GL_UNSIGNED_SHORT; // type of indices in index buffer
     U32     mIndicesStride = 2;     // size of each index in bytes
-    U32		mOffsets[TYPE_MAX]; // byte offsets into mMappedData of each attribute
+    U32     mOffsets[TYPE_MAX]; // byte offsets into mMappedData of each attribute
+
+    U8* mMappedData = nullptr;  // pointer to currently mapped data (NULL if unmapped)
+    U8* mMappedIndexData = nullptr; // pointer to currently mapped indices (NULL if unmapped)
 
-    U8* mMappedData = nullptr;	// pointer to currently mapped data (NULL if unmapped)
-    U8* mMappedIndexData = nullptr;	// pointer to currently mapped indices (NULL if unmapped)
+    U32     mTypeMask = 0;      // bitmask of present vertex attributes
 
-    U32		mTypeMask = 0;      // bitmask of present vertex attributes
-	
-	U32		mSize = 0;          // size in bytes of mMappedData
-	U32		mIndicesSize = 0;   // size in bytes of mMappedIndexData
+    U32     mSize = 0;          // size in bytes of mMappedData
+    U32     mIndicesSize = 0;   // size in bytes of mMappedIndexData
 
-	std::vector<MappedRegion> mMappedVertexRegions;  // list of mMappedData byte ranges that must be sent to GL
-	std::vector<MappedRegion> mMappedIndexRegions;   // list of mMappedIndexData byte ranges that must be sent to GL
+    std::vector<MappedRegion> mMappedVertexRegions;  // list of mMappedData byte ranges that must be sent to GL
+    std::vector<MappedRegion> mMappedIndexRegions;   // list of mMappedIndexData byte ranges that must be sent to GL
 
 private:
     // DEPRECATED
-    // These function signatures are deprecated, but for some reason 
+    // These function signatures are deprecated, but for some reason
     // there are classes in an external package that depend on LLVertexBuffer
-    
+
     // TODO: move these classes into viewer repository
     friend class LLNavShapeVBOManager;
     friend class LLNavMeshVBOManager;
-    
+
     LLVertexBuffer(U32 typemask, U32 usage)
         : LLVertexBuffer(typemask)
     {}
 
-    bool	allocateBuffer(S32 nverts, S32 nindices, BOOL create) { return allocateBuffer(nverts, nindices); }
+    bool    allocateBuffer(S32 nverts, S32 nindices, BOOL create) { return allocateBuffer(nverts, nindices); }
 
 public:
 
     static U64 getBytesAllocated();
-	static const U32 sTypeSize[TYPE_MAX];
-	static const U32 sGLMode[LLRender::NUM_MODES];
-	static U32 sGLRenderBuffer;
-	static U32 sGLRenderIndices;
-	static U32 sLastMask;
-	static U32 sVertexCount;
-	static GLuint sDummyVAO;
+    static const U32 sTypeSize[TYPE_MAX];
+    static const U32 sGLMode[LLRender::NUM_MODES];
+    static U32 sGLRenderBuffer;
+    static U32 sGLRenderIndices;
+    static U32 sLastMask;
+    static U32 sVertexCount;
+    static GLuint sDummyVAO;
 };
 
 #ifdef LL_PROFILER_ENABLE_RENDER_DOC
diff --git a/indra/llui/llslider.cpp b/indra/llui/llslider.cpp
index 9f39c500117592758fd36c2059129e40e5da8a1c..4556b02aff8bd5e330920618dec0dade6ecc5ce6 100644
--- a/indra/llui/llslider.cpp
+++ b/indra/llui/llslider.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llslider.cpp
  * @brief LLSlider base class
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -32,7 +32,7 @@
 #include "llgl.h"
 #include "llwindow.h"
 #include "llfocusmgr.h"
-#include "llkeyboard.h"			// for the MASK constants
+#include "llkeyboard.h"         // for the MASK constants
 #include "llcontrol.h"
 #include "lluictrlfactory.h"
 
@@ -41,343 +41,343 @@ static LLDefaultChildRegistry::Register<LLSlider> r1("slider_bar");
 // have ambigious template lookup problem
 
 LLSlider::Params::Params()
-:	orientation ("orientation", std::string ("horizontal")),
-	thumb_outline_color("thumb_outline_color"),
-	thumb_center_color("thumb_center_color"),
-	thumb_image("thumb_image"),
-	thumb_image_pressed("thumb_image_pressed"),
-	thumb_image_disabled("thumb_image_disabled"),
-	track_image_horizontal("track_image_horizontal"),
-	track_image_vertical("track_image_vertical"),
-	track_highlight_horizontal_image("track_highlight_horizontal_image"),
-	track_highlight_vertical_image("track_highlight_vertical_image"),
-	mouse_down_callback("mouse_down_callback"),
-	mouse_up_callback("mouse_up_callback")
+:   orientation ("orientation", std::string ("horizontal")),
+    thumb_outline_color("thumb_outline_color"),
+    thumb_center_color("thumb_center_color"),
+    thumb_image("thumb_image"),
+    thumb_image_pressed("thumb_image_pressed"),
+    thumb_image_disabled("thumb_image_disabled"),
+    track_image_horizontal("track_image_horizontal"),
+    track_image_vertical("track_image_vertical"),
+    track_highlight_horizontal_image("track_highlight_horizontal_image"),
+    track_highlight_vertical_image("track_highlight_vertical_image"),
+    mouse_down_callback("mouse_down_callback"),
+    mouse_up_callback("mouse_up_callback")
 {}
 
 LLSlider::LLSlider(const LLSlider::Params& p)
-:	LLF32UICtrl(p),
-	mMouseOffset( 0 ),
-	mOrientation ((p.orientation() == "horizontal") ? HORIZONTAL : VERTICAL),
-	mThumbOutlineColor(p.thumb_outline_color()),
-	mThumbCenterColor(p.thumb_center_color()),
-	mThumbImage(p.thumb_image),
-	mThumbImagePressed(p.thumb_image_pressed),
-	mThumbImageDisabled(p.thumb_image_disabled),
-	mTrackImageHorizontal(p.track_image_horizontal),
-	mTrackImageVertical(p.track_image_vertical),
-	mTrackHighlightHorizontalImage(p.track_highlight_horizontal_image),
-	mTrackHighlightVerticalImage(p.track_highlight_vertical_image),
-	mMouseDownSignal(NULL),
-	mMouseUpSignal(NULL)
+:   LLF32UICtrl(p),
+    mMouseOffset( 0 ),
+    mOrientation ((p.orientation() == "horizontal") ? HORIZONTAL : VERTICAL),
+    mThumbOutlineColor(p.thumb_outline_color()),
+    mThumbCenterColor(p.thumb_center_color()),
+    mThumbImage(p.thumb_image),
+    mThumbImagePressed(p.thumb_image_pressed),
+    mThumbImageDisabled(p.thumb_image_disabled),
+    mTrackImageHorizontal(p.track_image_horizontal),
+    mTrackImageVertical(p.track_image_vertical),
+    mTrackHighlightHorizontalImage(p.track_highlight_horizontal_image),
+    mTrackHighlightVerticalImage(p.track_highlight_vertical_image),
+    mMouseDownSignal(NULL),
+    mMouseUpSignal(NULL)
 {
     mViewModel->setValue(p.initial_value);
-	updateThumbRect();
-	mDragStartThumbRect = mThumbRect;
-	setControlName(p.control_name(), NULL);
-	setValue(getValueF32());
-	
-	if (p.mouse_down_callback.isProvided())
-	{
-		setMouseDownCallback(initCommitCallback(p.mouse_down_callback));
-	}
-	if (p.mouse_up_callback.isProvided())
-	{
-		setMouseUpCallback(initCommitCallback(p.mouse_up_callback));
-	}
+    updateThumbRect();
+    mDragStartThumbRect = mThumbRect;
+    setControlName(p.control_name(), NULL);
+    setValue(getValueF32());
+
+    if (p.mouse_down_callback.isProvided())
+    {
+        setMouseDownCallback(initCommitCallback(p.mouse_down_callback));
+    }
+    if (p.mouse_up_callback.isProvided())
+    {
+        setMouseUpCallback(initCommitCallback(p.mouse_up_callback));
+    }
 }
 
 LLSlider::~LLSlider()
 {
-	delete mMouseDownSignal;
-	delete mMouseUpSignal;
+    delete mMouseDownSignal;
+    delete mMouseUpSignal;
 }
 
 void LLSlider::setValue(F32 value, BOOL from_event)
 {
-	value = llclamp( value, mMinValue, mMaxValue );
+    value = llclamp( value, mMinValue, mMaxValue );
 
-	// Round to nearest increment (bias towards rounding down)
-	value -= mMinValue;
-	value += mIncrement/2.0001f;
-	value -= fmod(value, mIncrement);
-	value += mMinValue;
+    // Round to nearest increment (bias towards rounding down)
+    value -= mMinValue;
+    value += mIncrement/2.0001f;
+    value -= fmod(value, mIncrement);
+    value += mMinValue;
 
-	if (!from_event && getValueF32() != value)
-	{
-		setControlValue(value);
-	}
+    if (!from_event && getValueF32() != value)
+    {
+        setControlValue(value);
+    }
 
     LLF32UICtrl::setValue(value);
-	updateThumbRect();
+    updateThumbRect();
 }
 
 void LLSlider::updateThumbRect()
 {
-	const S32 DEFAULT_THUMB_SIZE = 16;
-	F32 t = (getValueF32() - mMinValue) / (mMaxValue - mMinValue);
-
-	S32 thumb_width = mThumbImage ? mThumbImage->getWidth() : DEFAULT_THUMB_SIZE;
-	S32 thumb_height = mThumbImage ? mThumbImage->getHeight() : DEFAULT_THUMB_SIZE;
-
-	if ( mOrientation == HORIZONTAL )
-	{
-		S32 left_edge = (thumb_width / 2);
-		S32 right_edge = getRect().getWidth() - (thumb_width / 2);
-
-		S32 x = left_edge + S32( t * (right_edge - left_edge) );
-		mThumbRect.mLeft = x - (thumb_width / 2);
-		mThumbRect.mRight = mThumbRect.mLeft + thumb_width;
-		mThumbRect.mBottom = getLocalRect().getCenterY() - (thumb_height / 2);
-		mThumbRect.mTop = mThumbRect.mBottom + thumb_height;
-	}
-	else
-	{
-		S32 top_edge = (thumb_height / 2);
-		S32 bottom_edge = getRect().getHeight() - (thumb_height / 2);
-
-		S32 y = top_edge + S32( t * (bottom_edge - top_edge) );
-		mThumbRect.mLeft = getLocalRect().getCenterX() - (thumb_width / 2);
-		mThumbRect.mRight = mThumbRect.mLeft + thumb_width;
-		mThumbRect.mBottom = y  - (thumb_height / 2);
-		mThumbRect.mTop = mThumbRect.mBottom + thumb_height;
-	}
+    const S32 DEFAULT_THUMB_SIZE = 16;
+    F32 t = (getValueF32() - mMinValue) / (mMaxValue - mMinValue);
+
+    S32 thumb_width = mThumbImage ? mThumbImage->getWidth() : DEFAULT_THUMB_SIZE;
+    S32 thumb_height = mThumbImage ? mThumbImage->getHeight() : DEFAULT_THUMB_SIZE;
+
+    if ( mOrientation == HORIZONTAL )
+    {
+        S32 left_edge = (thumb_width / 2);
+        S32 right_edge = getRect().getWidth() - (thumb_width / 2);
+
+        S32 x = left_edge + S32( t * (right_edge - left_edge) );
+        mThumbRect.mLeft = x - (thumb_width / 2);
+        mThumbRect.mRight = mThumbRect.mLeft + thumb_width;
+        mThumbRect.mBottom = getLocalRect().getCenterY() - (thumb_height / 2);
+        mThumbRect.mTop = mThumbRect.mBottom + thumb_height;
+    }
+    else
+    {
+        S32 top_edge = (thumb_height / 2);
+        S32 bottom_edge = getRect().getHeight() - (thumb_height / 2);
+
+        S32 y = top_edge + S32( t * (bottom_edge - top_edge) );
+        mThumbRect.mLeft = getLocalRect().getCenterX() - (thumb_width / 2);
+        mThumbRect.mRight = mThumbRect.mLeft + thumb_width;
+        mThumbRect.mBottom = y  - (thumb_height / 2);
+        mThumbRect.mTop = mThumbRect.mBottom + thumb_height;
+    }
 }
 
 
 void LLSlider::setValueAndCommit(F32 value)
 {
-	F32 old_value = getValueF32();
-	setValue(value);
+    F32 old_value = getValueF32();
+    setValue(value);
 
-	if (getValueF32() != old_value)
-	{
-		onCommit();
-	}
+    if (getValueF32() != old_value)
+    {
+        onCommit();
+    }
 }
 
 
 BOOL LLSlider::handleHover(S32 x, S32 y, MASK mask)
 {
-	if( hasMouseCapture() )
-	{
-		if ( mOrientation == HORIZONTAL )
-		{
-			S32 thumb_half_width = mThumbImage->getWidth()/2;
-			S32 left_edge = thumb_half_width;
-			S32 right_edge = getRect().getWidth() - (thumb_half_width);
-
-			x += mMouseOffset;
-			x = llclamp( x, left_edge, right_edge );
-
-			F32 t = F32(x - left_edge) / (right_edge - left_edge);
-			setValueAndCommit(t * (mMaxValue - mMinValue) + mMinValue );
-		}
-		else // mOrientation == VERTICAL
-		{
-			S32 thumb_half_height = mThumbImage->getHeight()/2;
-			S32 top_edge = thumb_half_height;
-			S32 bottom_edge = getRect().getHeight() - (thumb_half_height);
-
-			y += mMouseOffset;
-			y = llclamp(y, top_edge, bottom_edge);
-
-			F32 t = F32(y - top_edge) / (bottom_edge - top_edge);
-			setValueAndCommit(t * (mMaxValue - mMinValue) + mMinValue );
-		}
-		getWindow()->setCursor(UI_CURSOR_ARROW);
+    if( hasMouseCapture() )
+    {
+        if ( mOrientation == HORIZONTAL )
+        {
+            S32 thumb_half_width = mThumbImage->getWidth()/2;
+            S32 left_edge = thumb_half_width;
+            S32 right_edge = getRect().getWidth() - (thumb_half_width);
+
+            x += mMouseOffset;
+            x = llclamp( x, left_edge, right_edge );
+
+            F32 t = F32(x - left_edge) / (right_edge - left_edge);
+            setValueAndCommit(t * (mMaxValue - mMinValue) + mMinValue );
+        }
+        else // mOrientation == VERTICAL
+        {
+            S32 thumb_half_height = mThumbImage->getHeight()/2;
+            S32 top_edge = thumb_half_height;
+            S32 bottom_edge = getRect().getHeight() - (thumb_half_height);
+
+            y += mMouseOffset;
+            y = llclamp(y, top_edge, bottom_edge);
+
+            F32 t = F32(y - top_edge) / (bottom_edge - top_edge);
+            setValueAndCommit(t * (mMaxValue - mMinValue) + mMinValue );
+        }
+        getWindow()->setCursor(UI_CURSOR_ARROW);
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("UserInput") << "hover handled by " << getName() << " (active)" << LL_ENDL;
+        LL_DEBUGS("UserInput") << "hover handled by " << getName() << " (active)" << LL_ENDL;
 #endif
-	}
-	else
-	{
-		getWindow()->setCursor(UI_CURSOR_ARROW);
+    }
+    else
+    {
+        getWindow()->setCursor(UI_CURSOR_ARROW);
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("UserInput") << "hover handled by " << getName() << " (inactive)" << LL_ENDL;	
+        LL_DEBUGS("UserInput") << "hover handled by " << getName() << " (inactive)" << LL_ENDL;
 #endif
-	}
-	return TRUE;
+    }
+    return TRUE;
 }
 
 BOOL LLSlider::handleMouseUp(S32 x, S32 y, MASK mask)
 {
-	BOOL handled = FALSE;
+    BOOL handled = FALSE;
 
-	if( hasMouseCapture() )
-	{
-		gFocusMgr.setMouseCapture( NULL );
+    if( hasMouseCapture() )
+    {
+        gFocusMgr.setMouseCapture( NULL );
 
-		if (mMouseUpSignal)
-			(*mMouseUpSignal)( this, getValueF32() );
+        if (mMouseUpSignal)
+            (*mMouseUpSignal)( this, getValueF32() );
 
-		handled = TRUE;
-		make_ui_sound("UISndClickRelease");
-	}
-	else
-	{
-		handled = TRUE;
-	}
+        handled = TRUE;
+        make_ui_sound("UISndClickRelease");
+    }
+    else
+    {
+        handled = TRUE;
+    }
 
-	return handled;
+    return handled;
 }
 
 BOOL LLSlider::handleMouseDown(S32 x, S32 y, MASK mask)
 {
-	// only do sticky-focus on non-chrome widgets
-	if (!getIsChrome())
-	{
-		setFocus(TRUE);
-	}
-	if (mMouseDownSignal)
-		(*mMouseDownSignal)( this, getValueF32() );
-
-	if (MASK_CONTROL & mask) // if CTRL is modifying
-	{
-		setValueAndCommit(mInitialValue);
-	}
-	else
-	{
-		// Find the offset of the actual mouse location from the center of the thumb.
-		if (mThumbRect.pointInRect(x,y))
-		{
-			mMouseOffset = (mOrientation == HORIZONTAL)
-				? (mThumbRect.mLeft + mThumbImage->getWidth()/2) - x
-				: (mThumbRect.mBottom + mThumbImage->getHeight()/2) - y;
-		}
-		else
-		{
-			mMouseOffset = 0;
-		}
-
-		// Start dragging the thumb
-		// No handler needed for focus lost since this class has no state that depends on it.
-		gFocusMgr.setMouseCapture( this );  
-		mDragStartThumbRect = mThumbRect;				
-	}
-	make_ui_sound("UISndClick");
-
-	return TRUE;
+    // only do sticky-focus on non-chrome widgets
+    if (!getIsChrome())
+    {
+        setFocus(TRUE);
+    }
+    if (mMouseDownSignal)
+        (*mMouseDownSignal)( this, getValueF32() );
+
+    if (MASK_CONTROL & mask) // if CTRL is modifying
+    {
+        setValueAndCommit(mInitialValue);
+    }
+    else
+    {
+        // Find the offset of the actual mouse location from the center of the thumb.
+        if (mThumbRect.pointInRect(x,y))
+        {
+            mMouseOffset = (mOrientation == HORIZONTAL)
+                ? (mThumbRect.mLeft + mThumbImage->getWidth()/2) - x
+                : (mThumbRect.mBottom + mThumbImage->getHeight()/2) - y;
+        }
+        else
+        {
+            mMouseOffset = 0;
+        }
+
+        // Start dragging the thumb
+        // No handler needed for focus lost since this class has no state that depends on it.
+        gFocusMgr.setMouseCapture( this );
+        mDragStartThumbRect = mThumbRect;
+    }
+    make_ui_sound("UISndClick");
+
+    return TRUE;
 }
 
 BOOL LLSlider::handleKeyHere(KEY key, MASK mask)
 {
-	BOOL handled = FALSE;
-	switch(key)
-	{
-	case KEY_DOWN:
-	case KEY_LEFT:
-		setValueAndCommit(getValueF32() - getIncrement());
-		handled = TRUE;
-		break;
-	case KEY_UP:
-	case KEY_RIGHT:
-		setValueAndCommit(getValueF32() + getIncrement());
-		handled = TRUE;
-		break;
-	default:
-		break;
-	}
-	return handled;
+    BOOL handled = FALSE;
+    switch(key)
+    {
+    case KEY_DOWN:
+    case KEY_LEFT:
+        setValueAndCommit(getValueF32() - getIncrement());
+        handled = TRUE;
+        break;
+    case KEY_UP:
+    case KEY_RIGHT:
+        setValueAndCommit(getValueF32() + getIncrement());
+        handled = TRUE;
+        break;
+    default:
+        break;
+    }
+    return handled;
 }
 
 BOOL LLSlider::handleScrollWheel(S32 x, S32 y, S32 clicks)
 {
-	F32 new_val = getValueF32() - clicks * getIncrement();
-	setValueAndCommit(new_val);
-	return TRUE;
+    F32 new_val = getValueF32() - clicks * getIncrement();
+    setValueAndCommit(new_val);
+    return TRUE;
 }
 
 void LLSlider::draw()
 {
-	F32 alpha = getDrawContext().mAlpha;
-
-	// since thumb image might still be decoding, need thumb to accomodate image size
-	updateThumbRect();
-
-	// Draw background and thumb.
-
-	// drawing solids requires texturing be disabled
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-	// Track
-	LLPointer<LLUIImage>& trackImage = ( mOrientation == HORIZONTAL )
-		? mTrackImageHorizontal
-		: mTrackImageVertical;
-
-	LLPointer<LLUIImage>& trackHighlightImage = ( mOrientation == HORIZONTAL )
-		? mTrackHighlightHorizontalImage
-		: mTrackHighlightVerticalImage;
-
-	LLRect track_rect;
-	LLRect highlight_rect;
-
-	if ( mOrientation == HORIZONTAL )
-	{
-		track_rect.set(mThumbImage->getWidth() / 2,
-					   getLocalRect().getCenterY() + (trackImage->getHeight() / 2), 
-					   getRect().getWidth() - mThumbImage->getWidth() / 2,
-					   getLocalRect().getCenterY() - (trackImage->getHeight() / 2) );
-		highlight_rect.set(track_rect.mLeft, track_rect.mTop, mThumbRect.getCenterX(), track_rect.mBottom);
-	}
-	else
-	{
-		track_rect.set(getLocalRect().getCenterX() - (trackImage->getWidth() / 2),
-					   getRect().getHeight(),
-					   getLocalRect().getCenterX() + (trackImage->getWidth() / 2),
-					   0);
-		highlight_rect.set(track_rect.mLeft, track_rect.mTop, track_rect.mRight, track_rect.mBottom);
-	}
-
-	LLColor4 color = isInEnabledChain() ? LLColor4::white % alpha : LLColor4::white % (0.6f * alpha);
-	trackImage->draw(track_rect, color);
-	trackHighlightImage->draw(highlight_rect, color);
-
-	// Thumb
-	if (hasFocus())
-	{
-		// Draw focus highlighting.
-		mThumbImage->drawBorder(mThumbRect, gFocusMgr.getFocusColor() % alpha, gFocusMgr.getFocusFlashWidth());
-	}
-
-	if( hasMouseCapture() ) // currently clicking on slider
-	{
-		// Show ghost where thumb was before dragging began.
-		if (mThumbImage.notNull())
-		{
-			mThumbImage->draw(mDragStartThumbRect, mThumbCenterColor.get() % (0.3f * alpha));
-		}
-		if (mThumbImagePressed.notNull())
-		{
-			mThumbImagePressed->draw(mThumbRect, mThumbOutlineColor % alpha);
-		}
-	}
-	else if (!isInEnabledChain())
-	{
-		if (mThumbImageDisabled.notNull())
-		{
-			mThumbImageDisabled->draw(mThumbRect, mThumbCenterColor % alpha);
-		}
-	}
-	else
-	{
-		if (mThumbImage.notNull())
-		{
-			mThumbImage->draw(mThumbRect, mThumbCenterColor % alpha);
-		}
-	}
-	
-	LLUICtrl::draw();
+    F32 alpha = getDrawContext().mAlpha;
+
+    // since thumb image might still be decoding, need thumb to accomodate image size
+    updateThumbRect();
+
+    // Draw background and thumb.
+
+    // drawing solids requires texturing be disabled
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+
+    // Track
+    LLPointer<LLUIImage>& trackImage = ( mOrientation == HORIZONTAL )
+        ? mTrackImageHorizontal
+        : mTrackImageVertical;
+
+    LLPointer<LLUIImage>& trackHighlightImage = ( mOrientation == HORIZONTAL )
+        ? mTrackHighlightHorizontalImage
+        : mTrackHighlightVerticalImage;
+
+    LLRect track_rect;
+    LLRect highlight_rect;
+
+    if ( mOrientation == HORIZONTAL )
+    {
+        track_rect.set(mThumbImage->getWidth() / 2,
+                       getLocalRect().getCenterY() + (trackImage->getHeight() / 2),
+                       getRect().getWidth() - mThumbImage->getWidth() / 2,
+                       getLocalRect().getCenterY() - (trackImage->getHeight() / 2) );
+        highlight_rect.set(track_rect.mLeft, track_rect.mTop, mThumbRect.getCenterX(), track_rect.mBottom);
+    }
+    else
+    {
+        track_rect.set(getLocalRect().getCenterX() - (trackImage->getWidth() / 2),
+                       getRect().getHeight(),
+                       getLocalRect().getCenterX() + (trackImage->getWidth() / 2),
+                       0);
+        highlight_rect.set(track_rect.mLeft, track_rect.mTop, track_rect.mRight, track_rect.mBottom);
+    }
+
+    LLColor4 color = isInEnabledChain() ? LLColor4::white % alpha : LLColor4::white % (0.6f * alpha);
+    trackImage->draw(track_rect, color);
+    trackHighlightImage->draw(highlight_rect, color);
+
+    // Thumb
+    if (hasFocus())
+    {
+        // Draw focus highlighting.
+        mThumbImage->drawBorder(mThumbRect, gFocusMgr.getFocusColor() % alpha, gFocusMgr.getFocusFlashWidth());
+    }
+
+    if( hasMouseCapture() ) // currently clicking on slider
+    {
+        // Show ghost where thumb was before dragging began.
+        if (mThumbImage.notNull())
+        {
+            mThumbImage->draw(mDragStartThumbRect, mThumbCenterColor.get() % (0.3f * alpha));
+        }
+        if (mThumbImagePressed.notNull())
+        {
+            mThumbImagePressed->draw(mThumbRect, mThumbOutlineColor % alpha);
+        }
+    }
+    else if (!isInEnabledChain())
+    {
+        if (mThumbImageDisabled.notNull())
+        {
+            mThumbImageDisabled->draw(mThumbRect, mThumbCenterColor % alpha);
+        }
+    }
+    else
+    {
+        if (mThumbImage.notNull())
+        {
+            mThumbImage->draw(mThumbRect, mThumbCenterColor % alpha);
+        }
+    }
+
+    LLUICtrl::draw();
 }
 
-boost::signals2::connection LLSlider::setMouseDownCallback( const commit_signal_t::slot_type& cb ) 
-{ 
-	if (!mMouseDownSignal) mMouseDownSignal = new commit_signal_t();
-	return mMouseDownSignal->connect(cb); 
+boost::signals2::connection LLSlider::setMouseDownCallback( const commit_signal_t::slot_type& cb )
+{
+    if (!mMouseDownSignal) mMouseDownSignal = new commit_signal_t();
+    return mMouseDownSignal->connect(cb);
 }
 
-boost::signals2::connection LLSlider::setMouseUpCallback(	const commit_signal_t::slot_type& cb )   
-{ 
-	if (!mMouseUpSignal) mMouseUpSignal = new commit_signal_t();
-	return mMouseUpSignal->connect(cb); 
+boost::signals2::connection LLSlider::setMouseUpCallback(   const commit_signal_t::slot_type& cb )
+{
+    if (!mMouseUpSignal) mMouseUpSignal = new commit_signal_t();
+    return mMouseUpSignal->connect(cb);
 }
diff --git a/indra/newview/alassetblocklist.h b/indra/newview/alassetblocklist.h
index 006034489359a5a8af8ab00e0f4f8b7a90fcaf4e..2fe3e8b21f610e973040f74c1e14cf2b2e66de1d 100644
--- a/indra/newview/alassetblocklist.h
+++ b/indra/newview/alassetblocklist.h
@@ -41,45 +41,45 @@
 class ALBlockedAsset
 {
 public:
-	ALBlockedAsset() = default;
-	ALBlockedAsset(const LLSD& sd) { fromLLSD(sd); }
+    ALBlockedAsset() = default;
+    ALBlockedAsset(const LLSD& sd) { fromLLSD(sd); }
 
-	LLSD toLLSD() const;
-	void fromLLSD(const LLSD& sd);
+    LLSD toLLSD() const;
+    void fromLLSD(const LLSD& sd);
 
-	std::string			mLocation;
-	LLUUID				mOwnerID;
-	LLDate				mDate;
-	LLAssetType::EType  mAssetType = LLAssetType::AT_NONE;
-	bool				mPersist = true;
+    std::string         mLocation;
+    LLUUID              mOwnerID;
+    LLDate              mDate;
+    LLAssetType::EType  mAssetType = LLAssetType::AT_NONE;
+    bool                mPersist = true;
 };
 
 class ALAssetBlocklist : public LLSingleton<ALAssetBlocklist>
 {
-	LLSINGLETON(ALAssetBlocklist);
+    LLSINGLETON(ALAssetBlocklist);
 protected:
-	/*virtual*/ ~ALAssetBlocklist();
+    /*virtual*/ ~ALAssetBlocklist();
 
-	void load();
-	void save() const;
+    void load();
+    void save() const;
 
 public:
-	using entry_list_t = boost::unordered_map<LLUUID, ALBlockedAsset>;
-	using change_signal_t = boost::signals2::signal<void()>;
+    using entry_list_t = boost::unordered_map<LLUUID, ALBlockedAsset>;
+    using change_signal_t = boost::signals2::signal<void()>;
 
-	const entry_list_t& getEntries() const { return mEntries; }
-	
-	void addEntry(const LLUUID& asset_id, const LLUUID& avatar_id, const std::string& region, LLAssetType::EType type, bool persist = true);
-	void removeEntry(const LLUUID& asset_id);
-	void removeEntries(const uuid_vec_t& asset_ids);
+    const entry_list_t& getEntries() const { return mEntries; }
 
-	bool isBlocked(const LLUUID& asset_id);
+    void addEntry(const LLUUID& asset_id, const LLUUID& avatar_id, const std::string& region, LLAssetType::EType type, bool persist = true);
+    void removeEntry(const LLUUID& asset_id);
+    void removeEntries(const uuid_vec_t& asset_ids);
 
-	boost::signals2::connection setChangeCallback(const change_signal_t::slot_type& cb) { return mChangedSignal.connect(cb); }
+    bool isBlocked(const LLUUID& asset_id);
+
+    boost::signals2::connection setChangeCallback(const change_signal_t::slot_type& cb) { return mChangedSignal.connect(cb); }
 
 protected:
-	entry_list_t mEntries;
-	change_signal_t	mChangedSignal;
+    entry_list_t mEntries;
+    change_signal_t mChangedSignal;
 };
 
 // ============================================================================
diff --git a/indra/newview/alfloaterexploresounds.cpp b/indra/newview/alfloaterexploresounds.cpp
index d28dcef12e95ea857246c8942b0150cd7eeec68a..99efb277f770b04bbcdaafbcdce5d29f63b3821b 100644
--- a/indra/newview/alfloaterexploresounds.cpp
+++ b/indra/newview/alfloaterexploresounds.cpp
@@ -1,6 +1,6 @@
-/** 
+/**
  * @file ALFloaterExploreSounds.cpp
- */ 
+ */
 
 #include "llviewerprecompiledheaders.h"
 
@@ -22,502 +22,502 @@
 static const size_t num_collision_sounds = 28;
 const LLUUID collision_sounds[num_collision_sounds] =
 {
-	LLUUID("dce5fdd4-afe4-4ea1-822f-dd52cac46b08"),
-	LLUUID("51011582-fbca-4580-ae9e-1a5593f094ec"),
-	LLUUID("68d62208-e257-4d0c-bbe2-20c9ea9760bb"),
-	LLUUID("75872e8c-bc39-451b-9b0b-042d7ba36cba"),
-	LLUUID("6a45ba0b-5775-4ea8-8513-26008a17f873"),
-	LLUUID("992a6d1b-8c77-40e0-9495-4098ce539694"),
-	LLUUID("2de4da5a-faf8-46be-bac6-c4d74f1e5767"),
-	LLUUID("6e3fb0f7-6d9c-42ca-b86b-1122ff562d7d"),
-	LLUUID("14209133-4961-4acc-9649-53fc38ee1667"),
-	LLUUID("bc4a4348-cfcc-4e5e-908e-8a52a8915fe6"),
-	LLUUID("9e5c1297-6eed-40c0-825a-d9bcd86e3193"),
-	LLUUID("e534761c-1894-4b61-b20c-658a6fb68157"),
-	LLUUID("8761f73f-6cf9-4186-8aaa-0948ed002db1"),
-	LLUUID("874a26fd-142f-4173-8c5b-890cd846c74d"),
-	LLUUID("0e24a717-b97e-4b77-9c94-b59a5a88b2da"),
-	LLUUID("75cf3ade-9a5b-4c4d-bb35-f9799bda7fb2"),
-	LLUUID("153c8bf7-fb89-4d89-b263-47e58b1b4774"),
-	LLUUID("55c3e0ce-275a-46fa-82ff-e0465f5e8703"),
-	LLUUID("24babf58-7156-4841-9a3f-761bdbb8e237"),
-	LLUUID("aca261d8-e145-4610-9e20-9eff990f2c12"),
-	LLUUID("0642fba6-5dcf-4d62-8e7b-94dbb529d117"),
-	LLUUID("25a863e8-dc42-4e8a-a357-e76422ace9b5"),
-	LLUUID("9538f37c-456e-4047-81be-6435045608d4"),
-	LLUUID("8c0f84c3-9afd-4396-b5f5-9bca2c911c20"),
-	LLUUID("be582e5d-b123-41a2-a150-454c39e961c8"),
-	LLUUID("c70141d4-ba06-41ea-bcbc-35ea81cb8335"),
-	LLUUID("7d1826f4-24c4-4aac-8c2e-eff45df37783"),
-	LLUUID("063c97d3-033a-4e9b-98d8-05c8074922cb")
+    LLUUID("dce5fdd4-afe4-4ea1-822f-dd52cac46b08"),
+    LLUUID("51011582-fbca-4580-ae9e-1a5593f094ec"),
+    LLUUID("68d62208-e257-4d0c-bbe2-20c9ea9760bb"),
+    LLUUID("75872e8c-bc39-451b-9b0b-042d7ba36cba"),
+    LLUUID("6a45ba0b-5775-4ea8-8513-26008a17f873"),
+    LLUUID("992a6d1b-8c77-40e0-9495-4098ce539694"),
+    LLUUID("2de4da5a-faf8-46be-bac6-c4d74f1e5767"),
+    LLUUID("6e3fb0f7-6d9c-42ca-b86b-1122ff562d7d"),
+    LLUUID("14209133-4961-4acc-9649-53fc38ee1667"),
+    LLUUID("bc4a4348-cfcc-4e5e-908e-8a52a8915fe6"),
+    LLUUID("9e5c1297-6eed-40c0-825a-d9bcd86e3193"),
+    LLUUID("e534761c-1894-4b61-b20c-658a6fb68157"),
+    LLUUID("8761f73f-6cf9-4186-8aaa-0948ed002db1"),
+    LLUUID("874a26fd-142f-4173-8c5b-890cd846c74d"),
+    LLUUID("0e24a717-b97e-4b77-9c94-b59a5a88b2da"),
+    LLUUID("75cf3ade-9a5b-4c4d-bb35-f9799bda7fb2"),
+    LLUUID("153c8bf7-fb89-4d89-b263-47e58b1b4774"),
+    LLUUID("55c3e0ce-275a-46fa-82ff-e0465f5e8703"),
+    LLUUID("24babf58-7156-4841-9a3f-761bdbb8e237"),
+    LLUUID("aca261d8-e145-4610-9e20-9eff990f2c12"),
+    LLUUID("0642fba6-5dcf-4d62-8e7b-94dbb529d117"),
+    LLUUID("25a863e8-dc42-4e8a-a357-e76422ace9b5"),
+    LLUUID("9538f37c-456e-4047-81be-6435045608d4"),
+    LLUUID("8c0f84c3-9afd-4396-b5f5-9bca2c911c20"),
+    LLUUID("be582e5d-b123-41a2-a150-454c39e961c8"),
+    LLUUID("c70141d4-ba06-41ea-bcbc-35ea81cb8335"),
+    LLUUID("7d1826f4-24c4-4aac-8c2e-eff45df37783"),
+    LLUUID("063c97d3-033a-4e9b-98d8-05c8074922cb")
 };
 
 ALFloaterExploreSounds::ALFloaterExploreSounds(const LLSD& key)
-:	LLFloater(key), LLEventTimer(0.25f)
+:   LLFloater(key), LLEventTimer(0.25f)
 {
 }
 
 ALFloaterExploreSounds::~ALFloaterExploreSounds()
 {
-	for (blacklist_avatar_name_cache_connection_map_t::iterator it = mBlacklistAvatarNameCacheConnections.begin(); it != mBlacklistAvatarNameCacheConnections.end(); ++it)
-	{
-		if (it->second.connected())
-		{
-			it->second.disconnect();
-		}
-	}
-	mBlacklistAvatarNameCacheConnections.clear();
-
-	mLocalPlayingAudioSourceIDs.clear();
+    for (blacklist_avatar_name_cache_connection_map_t::iterator it = mBlacklistAvatarNameCacheConnections.begin(); it != mBlacklistAvatarNameCacheConnections.end(); ++it)
+    {
+        if (it->second.connected())
+        {
+            it->second.disconnect();
+        }
+    }
+    mBlacklistAvatarNameCacheConnections.clear();
+
+    mLocalPlayingAudioSourceIDs.clear();
 }
 
 BOOL ALFloaterExploreSounds::postBuild()
 {
-	getChild<LLButton>("play_locally_btn")->setClickedCallback(boost::bind(&ALFloaterExploreSounds::handlePlayLocally, this));
-	getChild<LLButton>("look_at_btn")->setClickedCallback(boost::bind(&ALFloaterExploreSounds::handleLookAt, this));
-	getChild<LLButton>("stop_btn")->setClickedCallback(boost::bind(&ALFloaterExploreSounds::handleStop, this));
-	getChild<LLButton>("block_btn")->setClickedCallback(boost::bind(&ALFloaterExploreSounds::blacklistSound, this));
-	
-	mStopLocalButton = getChild<LLButton>("stop_locally_btn");
-	mStopLocalButton->setClickedCallback(boost::bind(&ALFloaterExploreSounds::handleStopLocally, this));
-
-	mHistoryScroller = getChild<LLScrollListCtrl>("sound_list");
-	mHistoryScroller->setCommitCallback(boost::bind(&ALFloaterExploreSounds::handleSelection, this));
-	mHistoryScroller->setDoubleClickCallback(boost::bind(&ALFloaterExploreSounds::handlePlayLocally, this));
-	mHistoryScroller->sortByColumn("playing", TRUE);
-
-	mCollisionSounds = getChild<LLCheckBoxCtrl>("collision_chk");
-	mRepeatedAssets = getChild<LLCheckBoxCtrl>("repeated_asset_chk");
-	mAvatarSounds = getChild<LLCheckBoxCtrl>("avatars_chk");
-	mObjectSounds = getChild<LLCheckBoxCtrl>("objects_chk");
-	mPaused = getChild<LLCheckBoxCtrl>("pause_chk");
-
-	return LLFloater::postBuild();
+    getChild<LLButton>("play_locally_btn")->setClickedCallback(boost::bind(&ALFloaterExploreSounds::handlePlayLocally, this));
+    getChild<LLButton>("look_at_btn")->setClickedCallback(boost::bind(&ALFloaterExploreSounds::handleLookAt, this));
+    getChild<LLButton>("stop_btn")->setClickedCallback(boost::bind(&ALFloaterExploreSounds::handleStop, this));
+    getChild<LLButton>("block_btn")->setClickedCallback(boost::bind(&ALFloaterExploreSounds::blacklistSound, this));
+
+    mStopLocalButton = getChild<LLButton>("stop_locally_btn");
+    mStopLocalButton->setClickedCallback(boost::bind(&ALFloaterExploreSounds::handleStopLocally, this));
+
+    mHistoryScroller = getChild<LLScrollListCtrl>("sound_list");
+    mHistoryScroller->setCommitCallback(boost::bind(&ALFloaterExploreSounds::handleSelection, this));
+    mHistoryScroller->setDoubleClickCallback(boost::bind(&ALFloaterExploreSounds::handlePlayLocally, this));
+    mHistoryScroller->sortByColumn("playing", TRUE);
+
+    mCollisionSounds = getChild<LLCheckBoxCtrl>("collision_chk");
+    mRepeatedAssets = getChild<LLCheckBoxCtrl>("repeated_asset_chk");
+    mAvatarSounds = getChild<LLCheckBoxCtrl>("avatars_chk");
+    mObjectSounds = getChild<LLCheckBoxCtrl>("objects_chk");
+    mPaused = getChild<LLCheckBoxCtrl>("pause_chk");
+
+    return LLFloater::postBuild();
 }
 
 void ALFloaterExploreSounds::handleSelection()
 {
-	size_t num_selected = mHistoryScroller->getAllSelected().size();
-	bool multiple = (num_selected > 1);
-	childSetEnabled("look_at_btn", (num_selected && !multiple));
-	childSetEnabled("play_locally_btn", num_selected);
-	childSetEnabled("stop_btn", num_selected);
-	childSetEnabled("block_btn", num_selected);
+    size_t num_selected = mHistoryScroller->getAllSelected().size();
+    bool multiple = (num_selected > 1);
+    childSetEnabled("look_at_btn", (num_selected && !multiple));
+    childSetEnabled("play_locally_btn", num_selected);
+    childSetEnabled("stop_btn", num_selected);
+    childSetEnabled("block_btn", num_selected);
 }
 
 LLSoundHistoryItem ALFloaterExploreSounds::getItem(const LLUUID& itemID)
 {
-	if (!gAudiop)
-	{
-		LLSoundHistoryItem item;
-		item.mID = LLUUID::null;
-		return item;
-	}
-
-	const auto& sound_log = gAudiop->getSoundLog();
-	auto found = sound_log.find(itemID);
-	if (found != sound_log.end())
-	{
-		return *found->second;
-	}
-	else
-	{
-		// If log is paused, hopefully we can find it in mLastHistory
-		std::list<LLSoundHistoryItem>::iterator iter = mLastHistory.begin();
-		std::list<LLSoundHistoryItem>::iterator end = mLastHistory.end();
-		for ( ; iter != end; ++iter)
-		{
-			if ((*iter).mID == itemID)
-			{
-				return (*iter);
-			}
-		}
-	}
-	LLSoundHistoryItem item;
-	item.mID = LLUUID::null;
-	return item;
+    if (!gAudiop)
+    {
+        LLSoundHistoryItem item;
+        item.mID = LLUUID::null;
+        return item;
+    }
+
+    const auto& sound_log = gAudiop->getSoundLog();
+    auto found = sound_log.find(itemID);
+    if (found != sound_log.end())
+    {
+        return *found->second;
+    }
+    else
+    {
+        // If log is paused, hopefully we can find it in mLastHistory
+        std::list<LLSoundHistoryItem>::iterator iter = mLastHistory.begin();
+        std::list<LLSoundHistoryItem>::iterator end = mLastHistory.end();
+        for ( ; iter != end; ++iter)
+        {
+            if ((*iter).mID == itemID)
+            {
+                return (*iter);
+            }
+        }
+    }
+    LLSoundHistoryItem item;
+    item.mID = LLUUID::null;
+    return item;
 }
 
 class LLSoundHistoryItemCompare
 {
 public:
-	bool operator() (LLSoundHistoryItem first, LLSoundHistoryItem second)
-	{
-		if (first.mPlaying)
-		{
-			if (second.mPlaying)
-			{
-				return (first.mTimeStarted > second.mTimeStarted);
-			}
-			else
-			{
-				return true;
-			}
-		}
-		else if (second.mPlaying)
-		{
-			return false;
-		}
-		else
-		{
-			return (first.mTimeStopped > second.mTimeStopped);
-		}
-	}
+    bool operator() (LLSoundHistoryItem first, LLSoundHistoryItem second)
+    {
+        if (first.mPlaying)
+        {
+            if (second.mPlaying)
+            {
+                return (first.mTimeStarted > second.mTimeStarted);
+            }
+            else
+            {
+                return true;
+            }
+        }
+        else if (second.mPlaying)
+        {
+            return false;
+        }
+        else
+        {
+            return (first.mTimeStopped > second.mTimeStopped);
+        }
+    }
 };
 
 BOOL ALFloaterExploreSounds::tick()
 {
-	static const std::string str_playing =  getString("Playing");
-	static LLUIString str_not_playing = getString("NotPlaying");
-	static const std::string str_type_ui =  getString("Type_UI");
-	static const std::string str_type_avatar = getString("Type_Avatar");
-	static const std::string str_type_trigger_sound = getString("Type_llTriggerSound");
-	static const std::string str_type_loop_sound = getString("Type_llLoopSound");
-	static const std::string str_type_play_sound = getString("Type_llPlaySound");
-	static const std::string str_unknown_name = LLTrans::getString("AvatarNameWaiting");
-
-	bool show_collision_sounds = mCollisionSounds->get();
-	bool show_repeated_assets = mRepeatedAssets->get();
-	bool show_avatars = mAvatarSounds->get();
-	bool show_objects = mObjectSounds->get();
-
-	std::list<LLSoundHistoryItem> history;
-	if (mPaused->get())
-	{
-		history = mLastHistory;
-	}
-	else
-	{
-		if (gAudiop)
-		{
-			for (const auto& sound_pair : gAudiop->getSoundLog())
-			{
-				history.push_back(*sound_pair.second);
-			}
-			LLSoundHistoryItemCompare c;
-			history.sort(c);
-		}
-		mLastHistory = history;
-	}
-
-	// Save scroll pos and selection so they can be restored
-	S32 scroll_pos = mHistoryScroller->getScrollPos();
-	uuid_vec_t selected_ids;
-	std::vector<LLScrollListItem*> selected_items = mHistoryScroller->getAllSelected();
-	std::vector<LLScrollListItem*>::iterator selection_iter = selected_items.begin();
-	std::vector<LLScrollListItem*>::iterator selection_end = selected_items.end();
-	for (; selection_iter != selection_end; ++selection_iter)
-	{
-		selected_ids.push_back((*selection_iter)->getUUID());
-	}
-
-	mHistoryScroller->clearRows();
-
-	std::list<LLUUID> unique_asset_list;
-
-	std::list<LLSoundHistoryItem>::iterator iter = history.begin();
-	std::list<LLSoundHistoryItem>::iterator end = history.end();
-	for ( ; iter != end; ++iter)
-	{
-		LLSoundHistoryItem item = (*iter);
-
-		bool is_avatar = item.mOwnerID == item.mSourceID;
-		if (is_avatar && !show_avatars)
-		{
-			continue;
-		}
-
-		bool is_object = !is_avatar;
-		if (is_object && !show_objects)
-		{
-			continue;
-		}
-
-		bool is_repeated_asset = std::find(unique_asset_list.begin(), unique_asset_list.end(), item.mAssetID) != unique_asset_list.end();
-		if (is_repeated_asset && !show_repeated_assets)
-		{
-			continue;
-		}
-
-		if (!item.mReviewed)
-		{
-			item.mReviewedCollision = std::find(&collision_sounds[0], &collision_sounds[num_collision_sounds], item.mAssetID) != &collision_sounds[num_collision_sounds];
-			item.mReviewed = true;
-		}
-
-		bool is_collision_sound = item.mReviewedCollision;
-		if (is_collision_sound && !show_collision_sounds)
-		{
-			continue;
-		}
-
-		unique_asset_list.push_back(item.mAssetID);
-
-		LLSD element;
-		element["id"] = item.mID;
-
-		LLSD& playing_column = element["columns"][0];
-		playing_column["column"] = "playing";
-		if (item.mPlaying)
-		{
-			playing_column["value"] = " " + str_playing;
-		}
-		else
-		{
-			LLStringUtil::format_map_t format_args;
-			format_args["TIME"] = llformat("%.1f", static_cast<F32>((LLTimer::getElapsedSeconds() - item.mTimeStopped) / 60.0));
-			str_not_playing.setArgs(format_args);
-			playing_column["value"] = str_not_playing.getString();
-		}
-
-		LLSD& type_column = element["columns"][1];
-		type_column["column"] = "type";
-		if (item.mType == LLAudioEngine::AUDIO_TYPE_UI)
-		{
-			// this shouldn't happen for now, as UI is forbidden in the log
-			type_column["value"] = str_type_ui;
-		}
-		else
-		{
-			std::string type;
-
-			if (is_avatar)
-			{
-				type = str_type_avatar;
-			}
-			else
-			{
-				if (item.mIsTrigger)
-				{
-					type = str_type_trigger_sound;
-				}
-				else
-				{
-					if (item.mIsLooped)
-					{
-						type = str_type_loop_sound;
-					}
-					else
-					{
-						type = str_type_play_sound;
-					}
-				}
-			}
-
-			type_column["value"] = type;
-		}
-
-		LLSD& owner_column = element["columns"][2];
-		owner_column["column"] = "owner";
-		LLAvatarName av_name;
-		if (LLAvatarNameCache::get(item.mOwnerID, &av_name))
-		{
-			owner_column["value"] = !gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMES) ? av_name.getCompleteName() : RlvStrings::getAnonym(av_name);
-		}
-		else
-		{
-			owner_column["value"] = str_unknown_name;
-		}
-
-		LLSD& sound_column = element["columns"][3];
-		sound_column["column"] = "sound";
-		sound_column["value"] = item.mAssetID.asString().substr(0,16);
-
-		mHistoryScroller->addElement(element, ADD_BOTTOM);
-	}
-
-	mHistoryScroller->selectMultiple(selected_ids);
-	mHistoryScroller->setScrollPos(scroll_pos);
-
-	// Clean up stopped local audio source IDs
-	uuid_vec_t stopped_audio_src_ids;
-	uuid_vec_t::iterator audio_src_id_iter = mLocalPlayingAudioSourceIDs.begin();
-	uuid_vec_t::iterator audio_src_id_end = mLocalPlayingAudioSourceIDs.end();
-	for (; audio_src_id_iter != audio_src_id_end; ++audio_src_id_iter)
-	{
-		LLUUID audio_src_id = *audio_src_id_iter;
-		LLAudioSource* audio_source = gAudiop->findAudioSource(audio_src_id);
-		if (!audio_source || audio_source->isDone())
-		{
-			stopped_audio_src_ids.push_back(audio_src_id);
-		}
-	}
-
-	for (uuid_vec_t::iterator stopped_audio_src_ids_iter = stopped_audio_src_ids.begin();
-		 stopped_audio_src_ids_iter != stopped_audio_src_ids.end(); ++stopped_audio_src_ids_iter)
-	{
-		uuid_vec_t::iterator find_iter = std::find(mLocalPlayingAudioSourceIDs.begin(), mLocalPlayingAudioSourceIDs.end(), *stopped_audio_src_ids_iter);
-		if (find_iter != mLocalPlayingAudioSourceIDs.end())
-		{
-			mLocalPlayingAudioSourceIDs.erase(find_iter);
-		}
-	}
-
-	mStopLocalButton->setEnabled(mLocalPlayingAudioSourceIDs.size() > 0);
-
-	return FALSE;
+    static const std::string str_playing =  getString("Playing");
+    static LLUIString str_not_playing = getString("NotPlaying");
+    static const std::string str_type_ui =  getString("Type_UI");
+    static const std::string str_type_avatar = getString("Type_Avatar");
+    static const std::string str_type_trigger_sound = getString("Type_llTriggerSound");
+    static const std::string str_type_loop_sound = getString("Type_llLoopSound");
+    static const std::string str_type_play_sound = getString("Type_llPlaySound");
+    static const std::string str_unknown_name = LLTrans::getString("AvatarNameWaiting");
+
+    bool show_collision_sounds = mCollisionSounds->get();
+    bool show_repeated_assets = mRepeatedAssets->get();
+    bool show_avatars = mAvatarSounds->get();
+    bool show_objects = mObjectSounds->get();
+
+    std::list<LLSoundHistoryItem> history;
+    if (mPaused->get())
+    {
+        history = mLastHistory;
+    }
+    else
+    {
+        if (gAudiop)
+        {
+            for (const auto& sound_pair : gAudiop->getSoundLog())
+            {
+                history.push_back(*sound_pair.second);
+            }
+            LLSoundHistoryItemCompare c;
+            history.sort(c);
+        }
+        mLastHistory = history;
+    }
+
+    // Save scroll pos and selection so they can be restored
+    S32 scroll_pos = mHistoryScroller->getScrollPos();
+    uuid_vec_t selected_ids;
+    std::vector<LLScrollListItem*> selected_items = mHistoryScroller->getAllSelected();
+    std::vector<LLScrollListItem*>::iterator selection_iter = selected_items.begin();
+    std::vector<LLScrollListItem*>::iterator selection_end = selected_items.end();
+    for (; selection_iter != selection_end; ++selection_iter)
+    {
+        selected_ids.push_back((*selection_iter)->getUUID());
+    }
+
+    mHistoryScroller->clearRows();
+
+    std::list<LLUUID> unique_asset_list;
+
+    std::list<LLSoundHistoryItem>::iterator iter = history.begin();
+    std::list<LLSoundHistoryItem>::iterator end = history.end();
+    for ( ; iter != end; ++iter)
+    {
+        LLSoundHistoryItem item = (*iter);
+
+        bool is_avatar = item.mOwnerID == item.mSourceID;
+        if (is_avatar && !show_avatars)
+        {
+            continue;
+        }
+
+        bool is_object = !is_avatar;
+        if (is_object && !show_objects)
+        {
+            continue;
+        }
+
+        bool is_repeated_asset = std::find(unique_asset_list.begin(), unique_asset_list.end(), item.mAssetID) != unique_asset_list.end();
+        if (is_repeated_asset && !show_repeated_assets)
+        {
+            continue;
+        }
+
+        if (!item.mReviewed)
+        {
+            item.mReviewedCollision = std::find(&collision_sounds[0], &collision_sounds[num_collision_sounds], item.mAssetID) != &collision_sounds[num_collision_sounds];
+            item.mReviewed = true;
+        }
+
+        bool is_collision_sound = item.mReviewedCollision;
+        if (is_collision_sound && !show_collision_sounds)
+        {
+            continue;
+        }
+
+        unique_asset_list.push_back(item.mAssetID);
+
+        LLSD element;
+        element["id"] = item.mID;
+
+        LLSD& playing_column = element["columns"][0];
+        playing_column["column"] = "playing";
+        if (item.mPlaying)
+        {
+            playing_column["value"] = " " + str_playing;
+        }
+        else
+        {
+            LLStringUtil::format_map_t format_args;
+            format_args["TIME"] = llformat("%.1f", static_cast<F32>((LLTimer::getElapsedSeconds() - item.mTimeStopped) / 60.0));
+            str_not_playing.setArgs(format_args);
+            playing_column["value"] = str_not_playing.getString();
+        }
+
+        LLSD& type_column = element["columns"][1];
+        type_column["column"] = "type";
+        if (item.mType == LLAudioEngine::AUDIO_TYPE_UI)
+        {
+            // this shouldn't happen for now, as UI is forbidden in the log
+            type_column["value"] = str_type_ui;
+        }
+        else
+        {
+            std::string type;
+
+            if (is_avatar)
+            {
+                type = str_type_avatar;
+            }
+            else
+            {
+                if (item.mIsTrigger)
+                {
+                    type = str_type_trigger_sound;
+                }
+                else
+                {
+                    if (item.mIsLooped)
+                    {
+                        type = str_type_loop_sound;
+                    }
+                    else
+                    {
+                        type = str_type_play_sound;
+                    }
+                }
+            }
+
+            type_column["value"] = type;
+        }
+
+        LLSD& owner_column = element["columns"][2];
+        owner_column["column"] = "owner";
+        LLAvatarName av_name;
+        if (LLAvatarNameCache::get(item.mOwnerID, &av_name))
+        {
+            owner_column["value"] = !gRlvHandler.hasBehaviour(RLV_BHVR_SHOWNAMES) ? av_name.getCompleteName() : RlvStrings::getAnonym(av_name);
+        }
+        else
+        {
+            owner_column["value"] = str_unknown_name;
+        }
+
+        LLSD& sound_column = element["columns"][3];
+        sound_column["column"] = "sound";
+        sound_column["value"] = item.mAssetID.asString().substr(0,16);
+
+        mHistoryScroller->addElement(element, ADD_BOTTOM);
+    }
+
+    mHistoryScroller->selectMultiple(selected_ids);
+    mHistoryScroller->setScrollPos(scroll_pos);
+
+    // Clean up stopped local audio source IDs
+    uuid_vec_t stopped_audio_src_ids;
+    uuid_vec_t::iterator audio_src_id_iter = mLocalPlayingAudioSourceIDs.begin();
+    uuid_vec_t::iterator audio_src_id_end = mLocalPlayingAudioSourceIDs.end();
+    for (; audio_src_id_iter != audio_src_id_end; ++audio_src_id_iter)
+    {
+        LLUUID audio_src_id = *audio_src_id_iter;
+        LLAudioSource* audio_source = gAudiop->findAudioSource(audio_src_id);
+        if (!audio_source || audio_source->isDone())
+        {
+            stopped_audio_src_ids.push_back(audio_src_id);
+        }
+    }
+
+    for (uuid_vec_t::iterator stopped_audio_src_ids_iter = stopped_audio_src_ids.begin();
+         stopped_audio_src_ids_iter != stopped_audio_src_ids.end(); ++stopped_audio_src_ids_iter)
+    {
+        uuid_vec_t::iterator find_iter = std::find(mLocalPlayingAudioSourceIDs.begin(), mLocalPlayingAudioSourceIDs.end(), *stopped_audio_src_ids_iter);
+        if (find_iter != mLocalPlayingAudioSourceIDs.end())
+        {
+            mLocalPlayingAudioSourceIDs.erase(find_iter);
+        }
+    }
+
+    mStopLocalButton->setEnabled(mLocalPlayingAudioSourceIDs.size() > 0);
+
+    return FALSE;
 }
 
 void ALFloaterExploreSounds::handlePlayLocally()
 {
-	std::vector<LLScrollListItem*> selection = mHistoryScroller->getAllSelected();
-	std::vector<LLScrollListItem*>::iterator selection_iter = selection.begin();
-	std::vector<LLScrollListItem*>::iterator selection_end = selection.end();
-	uuid_vec_t asset_list;
-	for ( ; selection_iter != selection_end; ++selection_iter)
-	{
-		LLSoundHistoryItem item = getItem((*selection_iter)->getValue());
-		if (item.mID.isNull())
-		{
-			continue;
-		}
-
-		// Unique assets only
-		if (std::find(asset_list.begin(), asset_list.end(), item.mAssetID) == asset_list.end())
-		{
-			asset_list.push_back(item.mAssetID);
-			LLUUID audio_source_id = LLUUID::generateNewID();
-			gAudiop->triggerSound(item.mAssetID, gAgent.getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_UI, LLVector3d::zero, LLUUID::null, audio_source_id);
-			mLocalPlayingAudioSourceIDs.push_back(audio_source_id);
-		}
-	}
-
-	mStopLocalButton->setEnabled(mLocalPlayingAudioSourceIDs.size() > 0);
+    std::vector<LLScrollListItem*> selection = mHistoryScroller->getAllSelected();
+    std::vector<LLScrollListItem*>::iterator selection_iter = selection.begin();
+    std::vector<LLScrollListItem*>::iterator selection_end = selection.end();
+    uuid_vec_t asset_list;
+    for ( ; selection_iter != selection_end; ++selection_iter)
+    {
+        LLSoundHistoryItem item = getItem((*selection_iter)->getValue());
+        if (item.mID.isNull())
+        {
+            continue;
+        }
+
+        // Unique assets only
+        if (std::find(asset_list.begin(), asset_list.end(), item.mAssetID) == asset_list.end())
+        {
+            asset_list.push_back(item.mAssetID);
+            LLUUID audio_source_id = LLUUID::generateNewID();
+            gAudiop->triggerSound(item.mAssetID, gAgent.getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_UI, LLVector3d::zero, LLUUID::null, audio_source_id);
+            mLocalPlayingAudioSourceIDs.push_back(audio_source_id);
+        }
+    }
+
+    mStopLocalButton->setEnabled(mLocalPlayingAudioSourceIDs.size() > 0);
 }
 
 void ALFloaterExploreSounds::handleLookAt()
 {
-	LLUUID selection = mHistoryScroller->getSelectedValue().asUUID();
-	LLSoundHistoryItem item = getItem(selection); // Single item only
-	if (item.mID.isNull())
-	{
-		return;
-	}
-
-	LLVector3d pos_global = item.mPosition;
-
-	// Try to find object position
-	if (item.mSourceID.notNull())
-	{
-		LLViewerObject* object = gObjectList.findObject(item.mSourceID);
-		if (object)
-		{
-			pos_global = object->getPositionGlobal();
-		}
-	}
-
-	// Move the camera
-	// Find direction to self (reverse)
-	LLVector3d cam = gAgent.getPositionGlobal() - pos_global;
-	cam.normalize();
-	// Go 4 meters back and 3 meters up
-	cam *= 4.0;
-	cam += pos_global;
-	cam += LLVector3d(0.0, 0.0, 3.0);
-
-	gAgentCamera.setFocusOnAvatar(FALSE, FALSE);
-	gAgentCamera.setCameraPosAndFocusGlobal(cam, pos_global, item.mSourceID);
-	gAgentCamera.setCameraAnimating(FALSE);
+    LLUUID selection = mHistoryScroller->getSelectedValue().asUUID();
+    LLSoundHistoryItem item = getItem(selection); // Single item only
+    if (item.mID.isNull())
+    {
+        return;
+    }
+
+    LLVector3d pos_global = item.mPosition;
+
+    // Try to find object position
+    if (item.mSourceID.notNull())
+    {
+        LLViewerObject* object = gObjectList.findObject(item.mSourceID);
+        if (object)
+        {
+            pos_global = object->getPositionGlobal();
+        }
+    }
+
+    // Move the camera
+    // Find direction to self (reverse)
+    LLVector3d cam = gAgent.getPositionGlobal() - pos_global;
+    cam.normalize();
+    // Go 4 meters back and 3 meters up
+    cam *= 4.0;
+    cam += pos_global;
+    cam += LLVector3d(0.0, 0.0, 3.0);
+
+    gAgentCamera.setFocusOnAvatar(FALSE, FALSE);
+    gAgentCamera.setCameraPosAndFocusGlobal(cam, pos_global, item.mSourceID);
+    gAgentCamera.setCameraAnimating(FALSE);
 }
 
 void ALFloaterExploreSounds::handleStop()
 {
-	if (!gAudiop)
-		return;
-
-	auto& sound_log = gAudiop->getSoundLog();
-
-	std::vector<LLScrollListItem*> selection = mHistoryScroller->getAllSelected();
-	for (const auto& selection_item : selection)
-	{
-		LLSoundHistoryItem item = getItem(selection_item->getValue());
-		if (item.mID.notNull() && item.mPlaying)
-		{
-			LLAudioSource* audio_source = gAudiop->findAudioSource(item.mSourceID);
-			if (audio_source)
-			{
-				S32 type = item.mType;
-				audio_source->setType(LLAudioEngine::AUDIO_TYPE_UI);
-				audio_source->play(LLUUID::null);
-				audio_source->setType(type);
-			}
-			else
-			{
-				LL_WARNS("SoundExplorer") << "audio source for source ID " << item.mSourceID << " already gone but still marked as playing. Fixing ..." << LL_ENDL;
-				auto iter = sound_log.find(item.mID);
-				if (iter != sound_log.end())
-				{
-					iter->second->mPlaying = false;
-					iter->second->mTimeStopped = LLTimer::getElapsedSeconds();
-				}
-				else
-				{
-					for (auto& histItem : mLastHistory)
-					{
-						if (histItem.mID == item.mID)
-						{
-							histItem.mPlaying = false;
-							histItem.mTimeStopped = LLTimer::getElapsedSeconds();
-							break;
-						}
-					}
-				}
-				continue;
-			}
-		}
-	}
+    if (!gAudiop)
+        return;
+
+    auto& sound_log = gAudiop->getSoundLog();
+
+    std::vector<LLScrollListItem*> selection = mHistoryScroller->getAllSelected();
+    for (const auto& selection_item : selection)
+    {
+        LLSoundHistoryItem item = getItem(selection_item->getValue());
+        if (item.mID.notNull() && item.mPlaying)
+        {
+            LLAudioSource* audio_source = gAudiop->findAudioSource(item.mSourceID);
+            if (audio_source)
+            {
+                S32 type = item.mType;
+                audio_source->setType(LLAudioEngine::AUDIO_TYPE_UI);
+                audio_source->play(LLUUID::null);
+                audio_source->setType(type);
+            }
+            else
+            {
+                LL_WARNS("SoundExplorer") << "audio source for source ID " << item.mSourceID << " already gone but still marked as playing. Fixing ..." << LL_ENDL;
+                auto iter = sound_log.find(item.mID);
+                if (iter != sound_log.end())
+                {
+                    iter->second->mPlaying = false;
+                    iter->second->mTimeStopped = LLTimer::getElapsedSeconds();
+                }
+                else
+                {
+                    for (auto& histItem : mLastHistory)
+                    {
+                        if (histItem.mID == item.mID)
+                        {
+                            histItem.mPlaying = false;
+                            histItem.mTimeStopped = LLTimer::getElapsedSeconds();
+                            break;
+                        }
+                    }
+                }
+                continue;
+            }
+        }
+    }
 }
 
 void ALFloaterExploreSounds::handleStopLocally()
 {
-	uuid_vec_t::iterator audio_source_id_iter = mLocalPlayingAudioSourceIDs.begin();
-	uuid_vec_t::iterator audio_source_id_end = mLocalPlayingAudioSourceIDs.end();
-	for (; audio_source_id_iter != audio_source_id_end; ++audio_source_id_iter)
-	{
-		LLUUID audio_source_id = *audio_source_id_iter;
-		LLAudioSource* audio_source = gAudiop->findAudioSource(audio_source_id);
-		if (audio_source && !audio_source->isDone())
-		{
-			audio_source->play(LLUUID::null);
-		}
-	}
-
-	mLocalPlayingAudioSourceIDs.clear();
+    uuid_vec_t::iterator audio_source_id_iter = mLocalPlayingAudioSourceIDs.begin();
+    uuid_vec_t::iterator audio_source_id_end = mLocalPlayingAudioSourceIDs.end();
+    for (; audio_source_id_iter != audio_source_id_end; ++audio_source_id_iter)
+    {
+        LLUUID audio_source_id = *audio_source_id_iter;
+        LLAudioSource* audio_source = gAudiop->findAudioSource(audio_source_id);
+        if (audio_source && !audio_source->isDone())
+        {
+            audio_source->play(LLUUID::null);
+        }
+    }
+
+    mLocalPlayingAudioSourceIDs.clear();
 }
 
 //add sound to blacklist
 void ALFloaterExploreSounds::blacklistSound()
 {
-	std::vector<LLScrollListItem*> selection = mHistoryScroller->getAllSelected();
-	std::vector<LLScrollListItem*>::iterator selection_iter = selection.begin();
-	std::vector<LLScrollListItem*>::iterator selection_end = selection.end();
-
-	for ( ; selection_iter != selection_end; ++selection_iter)
-	{
-		LLSoundHistoryItem item = getItem((*selection_iter)->getValue());
-		if (item.mID.isNull())
-		{
-			continue;
-		}
-
-		std::string location = "Unknown";
-		LLViewerRegion* cur_region = gAgent.getRegion();
-		if (cur_region)
-		{
-			location = cur_region->getName();
-			//if(!item.mPosition.isNull())
-			//{
-			//	LLVector3 cur_pos(item.mPosition - cur_region->getOriginGlobal());
-			//	location = fmt::format(FMT_STRING("{:s} ({:d}, {:d}, {:d})"), cur_region->getName(), ll_round(cur_pos.mV[VX]), ll_round(cur_pos.mV[VY]), ll_round(cur_pos.mV[VZ]));
-			//}
-			//else
-			//{
-			//	location = cur_region->getName();
-			//}
-		}
-
-		ALAssetBlocklist::instance().addEntry(item.mAssetID, item.mOwnerID, location, LLAssetType::AT_SOUND);
-	}
-
-	handleStop();
+    std::vector<LLScrollListItem*> selection = mHistoryScroller->getAllSelected();
+    std::vector<LLScrollListItem*>::iterator selection_iter = selection.begin();
+    std::vector<LLScrollListItem*>::iterator selection_end = selection.end();
+
+    for ( ; selection_iter != selection_end; ++selection_iter)
+    {
+        LLSoundHistoryItem item = getItem((*selection_iter)->getValue());
+        if (item.mID.isNull())
+        {
+            continue;
+        }
+
+        std::string location = "Unknown";
+        LLViewerRegion* cur_region = gAgent.getRegion();
+        if (cur_region)
+        {
+            location = cur_region->getName();
+            //if(!item.mPosition.isNull())
+            //{
+            //  LLVector3 cur_pos(item.mPosition - cur_region->getOriginGlobal());
+            //  location = fmt::format(FMT_STRING("{:s} ({:d}, {:d}, {:d})"), cur_region->getName(), ll_round(cur_pos.mV[VX]), ll_round(cur_pos.mV[VY]), ll_round(cur_pos.mV[VZ]));
+            //}
+            //else
+            //{
+            //  location = cur_region->getName();
+            //}
+        }
+
+        ALAssetBlocklist::instance().addEntry(item.mAssetID, item.mOwnerID, location, LLAssetType::AT_SOUND);
+    }
+
+    handleStop();
 }
diff --git a/indra/newview/alrenderutils.cpp b/indra/newview/alrenderutils.cpp
index a8878898df1a2f9521fac80a53fbd4763f1758b4..baec2c8936f80c1f620eff055cf9624066cf5d55 100644
--- a/indra/newview/alrenderutils.cpp
+++ b/indra/newview/alrenderutils.cpp
@@ -110,711 +110,711 @@ freely, subject to the following restrictions:
 class LutCube
 {
 public:
-	std::vector<unsigned char> colorCube;
-	int                        size = 0;
+    std::vector<unsigned char> colorCube;
+    int                        size = 0;
 
-	LutCube(const std::string& file);
-	LutCube() = default;
+    LutCube(const std::string& file);
+    LutCube() = default;
 
 private:
-	float minX = 0.0f;
-	float minY = 0.0f;
-	float minZ = 0.0f;
+    float minX = 0.0f;
+    float minY = 0.0f;
+    float minZ = 0.0f;
 
-	float maxX = 1.0f;
-	float maxY = 1.0f;
-	float maxZ = 1.0f;
+    float maxX = 1.0f;
+    float maxY = 1.0f;
+    float maxZ = 1.0f;
 
-	int currentX = 0;
-	int currentY = 0;
-	int currentZ = 0;
+    int currentX = 0;
+    int currentY = 0;
+    int currentZ = 0;
 
-	void writeColor(int x, int y, int z, unsigned char r, unsigned char g, unsigned char b);
+    void writeColor(int x, int y, int z, unsigned char r, unsigned char g, unsigned char b);
 
-	void parseLine(std::string line);
+    void parseLine(std::string line);
 
-	// splits a tripel of floats
-	void splitTripel(std::string tripel, float& x, float& y, float& z);
+    // splits a tripel of floats
+    void splitTripel(std::string tripel, float& x, float& y, float& z);
 
-	void clampTripel(float x, float y, float z, unsigned char& outX, unsigned char& outY, unsigned char& outZ);
+    void clampTripel(float x, float y, float z, unsigned char& outX, unsigned char& outY, unsigned char& outZ);
 
-	// returns the text without leading whitespace
-	std::string skipWhiteSpace(std::string text);
+    // returns the text without leading whitespace
+    std::string skipWhiteSpace(std::string text);
 };
 
 LutCube::LutCube(const std::string& file)
 {
-	llifstream cubeStream(file);
-	if (!cubeStream.good())
-	{
-		LL_WARNS() << "lut cube file does not exist" << LL_ENDL;
-		return;
-	}
-
-	std::string line;
-
-	while (std::getline(cubeStream, line))
-	{
-		parseLine(line);
-	}
+    llifstream cubeStream(file);
+    if (!cubeStream.good())
+    {
+        LL_WARNS() << "lut cube file does not exist" << LL_ENDL;
+        return;
+    }
+
+    std::string line;
+
+    while (std::getline(cubeStream, line))
+    {
+        parseLine(line);
+    }
 }
 void LutCube::parseLine(std::string line)
 {
-	if (line.length() == 0)
-	{
-		return;
-	}
-	if (line[0] == '#')
-	{
-		return;
-	}
-	if (line.find("LUT_3D_SIZE") != std::string::npos)
-	{
-		line = line.substr(line.find("LUT_3D_SIZE") + 11);
-		line = skipWhiteSpace(line);
-		size = std::stoi(line);
-
-		colorCube = std::vector<unsigned char>(size * size * size * 4, 255);
-		return;
-	}
-	if (line.find("DOMAIN_MIN") != std::string::npos)
-	{
-		line = line.substr(line.find("DOMAIN_MIN") + 10);
-		splitTripel(line, minX, minY, minZ);
-		return;
-	}
-	if (line.find("DOMAIN_MAX") != std::string::npos)
-	{
-		line = line.substr(line.find("DOMAIN_MAX") + 10);
-		splitTripel(line, maxX, maxY, maxZ);
-		return;
-	}
-	if (line.find_first_of("0123456789") == 0)
-	{
-		float         x, y, z;
-		unsigned char outX, outY, outZ;
-		splitTripel(line, x, y, z);
-		clampTripel(x, y, z, outX, outY, outZ);
-		writeColor(currentX, currentY, currentZ, outX, outY, outZ);
-		if (currentX != size - 1)
-		{
-			currentX++;
-		}
-		else if (currentY != size - 1)
-		{
-			currentY++;
-			currentX = 0;
-		}
-		else if (currentZ != size - 1)
-		{
-			currentZ++;
-			currentX = 0;
-			currentY = 0;
-		}
-		return;
-	}
+    if (line.length() == 0)
+    {
+        return;
+    }
+    if (line[0] == '#')
+    {
+        return;
+    }
+    if (line.find("LUT_3D_SIZE") != std::string::npos)
+    {
+        line = line.substr(line.find("LUT_3D_SIZE") + 11);
+        line = skipWhiteSpace(line);
+        size = std::stoi(line);
+
+        colorCube = std::vector<unsigned char>(size * size * size * 4, 255);
+        return;
+    }
+    if (line.find("DOMAIN_MIN") != std::string::npos)
+    {
+        line = line.substr(line.find("DOMAIN_MIN") + 10);
+        splitTripel(line, minX, minY, minZ);
+        return;
+    }
+    if (line.find("DOMAIN_MAX") != std::string::npos)
+    {
+        line = line.substr(line.find("DOMAIN_MAX") + 10);
+        splitTripel(line, maxX, maxY, maxZ);
+        return;
+    }
+    if (line.find_first_of("0123456789") == 0)
+    {
+        float         x, y, z;
+        unsigned char outX, outY, outZ;
+        splitTripel(line, x, y, z);
+        clampTripel(x, y, z, outX, outY, outZ);
+        writeColor(currentX, currentY, currentZ, outX, outY, outZ);
+        if (currentX != size - 1)
+        {
+            currentX++;
+        }
+        else if (currentY != size - 1)
+        {
+            currentY++;
+            currentX = 0;
+        }
+        else if (currentZ != size - 1)
+        {
+            currentZ++;
+            currentX = 0;
+            currentY = 0;
+        }
+        return;
+    }
 }
 
 std::string LutCube::skipWhiteSpace(std::string text)
 {
-	while (text.size() > 0 && (text[0] == ' ' || text[0] == '\t'))
-	{
-		text = text.substr(1);
-	}
-	return text;
+    while (text.size() > 0 && (text[0] == ' ' || text[0] == '\t'))
+    {
+        text = text.substr(1);
+    }
+    return text;
 }
 
 void LutCube::splitTripel(std::string tripel, float& x, float& y, float& z)
 {
-	tripel = skipWhiteSpace(tripel);
-	size_t after = tripel.find_first_of(" \n");
-	x = std::stof(tripel.substr(0, after));
-	tripel = tripel.substr(after);
-
-	tripel = skipWhiteSpace(tripel);
-	after = tripel.find_first_of(" \n");
-	y = std::stof(tripel.substr(0, after));
-	tripel = tripel.substr(after);
-
-	tripel = skipWhiteSpace(tripel);
-	z = std::stof(tripel);
+    tripel = skipWhiteSpace(tripel);
+    size_t after = tripel.find_first_of(" \n");
+    x = std::stof(tripel.substr(0, after));
+    tripel = tripel.substr(after);
+
+    tripel = skipWhiteSpace(tripel);
+    after = tripel.find_first_of(" \n");
+    y = std::stof(tripel.substr(0, after));
+    tripel = tripel.substr(after);
+
+    tripel = skipWhiteSpace(tripel);
+    z = std::stof(tripel);
 }
 
 void LutCube::clampTripel(float x, float y, float z, unsigned char& outX, unsigned char& outY, unsigned char& outZ)
 {
-	outX = (unsigned char)255 * (x / (maxX - minX));
-	outY = (unsigned char)255 * (y / (maxY - minY));
-	outZ = (unsigned char)255 * (z / (maxZ - minZ));
+    outX = (unsigned char)255 * (x / (maxX - minX));
+    outY = (unsigned char)255 * (y / (maxY - minY));
+    outZ = (unsigned char)255 * (z / (maxZ - minZ));
 }
 
 void LutCube::writeColor(int x, int y, int z, unsigned char r, unsigned char g, unsigned char b)
 {
-	static const int colorSize = 4; // 4 bytes per point in the cube, rgba
+    static const int colorSize = 4; // 4 bytes per point in the cube, rgba
 
-	int locationR = (((z * size) + y) * size + x) * colorSize;
+    int locationR = (((z * size) + y) * size + x) * colorSize;
 
-	colorCube[locationR + 0] = r;
-	colorCube[locationR + 1] = g;
-	colorCube[locationR + 2] = b;
+    colorCube[locationR + 0] = r;
+    colorCube[locationR + 1] = g;
+    colorCube[locationR + 2] = b;
 }
 
 // END ZLIB LICENSE
 
 ALRenderUtil::ALRenderUtil()
 {
-	// Connect settings
-	mSettingConnections.push_back(gSavedSettings.getControl("RenderColorGradeLUT")->getSignal()->connect(boost::bind(&ALRenderUtil::setupColorGrade, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("RenderToneMapType")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("RenderExposure")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDHDRMax")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDExposure")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDContrast")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDSaturationR")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDSaturationG")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDSaturationB")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDCrosstalkR")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDCrosstalkG")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDCrosstalkB")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDShoulderContrast")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDShoulderContrastRange")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraMaxBrightness")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraContrast")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraLinearStart")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraLinearLength")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraBlackLevel")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicToeStr")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicToeLen")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicShoulderStr")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicShoulderLen")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicShoulderAngle")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicGamma")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicWhitePoint")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("RenderSharpenMethod")->getSignal()->connect(boost::bind(&ALRenderUtil::setupSharpen, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("RenderSharpenDLSSharpness")->getSignal()->connect(boost::bind(&ALRenderUtil::setupSharpen, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("RenderSharpenDLSDenoise")->getSignal()->connect(boost::bind(&ALRenderUtil::setupSharpen, this)));
-	mSettingConnections.push_back(gSavedSettings.getControl("RenderSharpenCASSharpness")->getSignal()->connect(boost::bind(&ALRenderUtil::setupSharpen, this)));
+    // Connect settings
+    mSettingConnections.push_back(gSavedSettings.getControl("RenderColorGradeLUT")->getSignal()->connect(boost::bind(&ALRenderUtil::setupColorGrade, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("RenderToneMapType")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("RenderExposure")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDHDRMax")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDExposure")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDContrast")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDSaturationR")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDSaturationG")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDSaturationB")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDCrosstalkR")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDCrosstalkG")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDCrosstalkB")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDShoulderContrast")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapAMDShoulderContrastRange")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraMaxBrightness")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraContrast")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraLinearStart")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraLinearLength")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapUchimuraBlackLevel")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicToeStr")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicToeLen")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicShoulderStr")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicShoulderLen")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicShoulderAngle")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicGamma")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("AlchemyToneMapFilmicWhitePoint")->getSignal()->connect(boost::bind(&ALRenderUtil::setupTonemap, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("RenderSharpenMethod")->getSignal()->connect(boost::bind(&ALRenderUtil::setupSharpen, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("RenderSharpenDLSSharpness")->getSignal()->connect(boost::bind(&ALRenderUtil::setupSharpen, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("RenderSharpenDLSDenoise")->getSignal()->connect(boost::bind(&ALRenderUtil::setupSharpen, this)));
+    mSettingConnections.push_back(gSavedSettings.getControl("RenderSharpenCASSharpness")->getSignal()->connect(boost::bind(&ALRenderUtil::setupSharpen, this)));
 }
 
 ALRenderUtil::~ALRenderUtil()
 {
-	mSettingConnections.clear();
+    mSettingConnections.clear();
 }
 
 void ALRenderUtil::releaseGLBuffers()
 {
-	if (mCGLut)
-	{
-		LLImageGL::deleteTextures(1, &mCGLut);
-		mCGLut = 0;
-	}
+    if (mCGLut)
+    {
+        LLImageGL::deleteTextures(1, &mCGLut);
+        mCGLut = 0;
+    }
 }
 
 void ALRenderUtil::refreshState()
 {
-	setupTonemap();
-	setupColorGrade();
-	setupSharpen();
+    setupTonemap();
+    setupColorGrade();
+    setupSharpen();
 }
 
 bool ALRenderUtil::setupTonemap()
 {
-	mTonemapType = gSavedSettings.getU32("RenderToneMapType");
-	if (mTonemapType >= TONEMAP_COUNT || (mTonemapType == ALTonemap::TONEMAP_AMD &&  !gDeferredPostTonemapLPMProgram.isComplete()))
-	{
-		mTonemapType = ALTonemap::TONEMAP_ACES_HILL;
-	}
-
-	LLGLSLShader* tone_shader = nullptr;
-	switch (mTonemapType)
-	{
-	default:
-	case ALTonemap::TONEMAP_ACES_HILL:
-	{
-		tone_shader = &gDeferredPostTonemapACESProgram;
-		break;
-	}
-	case ALTonemap::TONEMAP_UCHIMURA:
-	{
-		tone_shader = &gDeferredPostTonemapUchiProgram;
-		break;
-	}
-	case ALTonemap::TONEMAP_AMD:
-	{
-		tone_shader = &gDeferredPostTonemapLPMProgram;
-		break;
-	}
-	case ALTonemap::TONEMAP_UNCHARTED:
-	{
-		tone_shader = &gDeferredPostTonemapHableProgram;
-		break;
-	}
-	}
-	tone_shader->bind();
-
-	F32 tone_exposure = llclamp(gSavedSettings.getF32("RenderExposure"), 0.5f, 4.f);
-	tone_shader->uniform1f(al_exposure, tone_exposure);
-
-	switch (mTonemapType)
-	{
-	default:
-		break;
-	case ALTonemap::TONEMAP_UCHIMURA:
-	{
-		auto uchi_1 = LLVector3(gSavedSettings.getF32("AlchemyToneMapUchimuraMaxBrightness"), gSavedSettings.getF32("AlchemyToneMapUchimuraContrast"), gSavedSettings.getF32("AlchemyToneMapUchimuraLinearStart"));
-		auto uchi_2 = LLVector3(gSavedSettings.getF32("AlchemyToneMapUchimuraLinearLength"), gSavedSettings.getF32("AlchemyToneMapUchimuraBlackLevel"), 0.0);
-		tone_shader->uniform3fv(tone_uchimura_a, 1, uchi_1.mV);
-		tone_shader->uniform3fv(tone_uchimura_b, 1, uchi_2.mV);
-		break;
-	}
-	case ALTonemap::TONEMAP_AMD:
-	{
-		const F32 sh_contrast_range = gSavedSettings.getF32("AlchemyToneMapAMDShoulderContrastRange");
-
-		varAF3(saturation) = initAF3(gSavedSettings.getF32("AlchemyToneMapAMDSaturationR"), gSavedSettings.getF32("AlchemyToneMapAMDSaturationG"), gSavedSettings.getF32("AlchemyToneMapAMDSaturationB"));
-		varAF3(crosstalk) = initAF3(gSavedSettings.getF32("AlchemyToneMapAMDCrosstalkR"), gSavedSettings.getF32("AlchemyToneMapAMDCrosstalkG"), gSavedSettings.getF32("AlchemyToneMapAMDCrosstalkB"));
-		LpmSetup(
-			sh_contrast_range != 1.0, LPM_CONFIG_709_709, LPM_COLORS_709_709, // <-- Using the LPM_ prefabs to make inputs easier.
-			0.0, // softGap
-			gSavedSettings.getF32("AlchemyToneMapAMDHDRMax"), // hdrMax
-			gSavedSettings.getF32("AlchemyToneMapAMDExposure"), // exposure
-			gSavedSettings.getF32("AlchemyToneMapAMDContrast"), // contrast
-			sh_contrast_range, // shoulder contrast
-			saturation, crosstalk);
-
-		tone_shader->uniform4uiv(tonemap_amd_params, 24, LPM_CONTROL_BLOCK);
-		tone_shader->uniform1i(tonemap_amd_params_shoulder, sh_contrast_range != 1.0);
-		break;
-	}
-	case ALTonemap::TONEMAP_UNCHARTED:
-	{
-		auto uncharted_params_1 = LLVector3(gSavedSettings.getF32("AlchemyToneMapFilmicToeStr"), gSavedSettings.getF32("AlchemyToneMapFilmicToeLen"), gSavedSettings.getF32("AlchemyToneMapFilmicShoulderStr"));
-		auto uncharted_params_2 = LLVector3(gSavedSettings.getF32("AlchemyToneMapFilmicShoulderLen"), gSavedSettings.getF32("AlchemyToneMapFilmicShoulderAngle"), gSavedSettings.getF32("AlchemyToneMapFilmicGamma"));
-		auto uncharted_params_3 = LLVector3(gSavedSettings.getF32("AlchemyToneMapFilmicWhitePoint"), 2.0, 0.0);
-
-		tone_shader->uniform3fv(tone_uncharted_a, 1, uncharted_params_1.mV);
-		tone_shader->uniform3fv(tone_uncharted_b, 1, uncharted_params_2.mV);
-		tone_shader->uniform3fv(tone_uncharted_c, 1, uncharted_params_3.mV);
-		break;
-	}
-	}
-	tone_shader->unbind();
-	return true;
+    mTonemapType = gSavedSettings.getU32("RenderToneMapType");
+    if (mTonemapType >= TONEMAP_COUNT || (mTonemapType == ALTonemap::TONEMAP_AMD &&  !gDeferredPostTonemapLPMProgram.isComplete()))
+    {
+        mTonemapType = ALTonemap::TONEMAP_ACES_HILL;
+    }
+
+    LLGLSLShader* tone_shader = nullptr;
+    switch (mTonemapType)
+    {
+    default:
+    case ALTonemap::TONEMAP_ACES_HILL:
+    {
+        tone_shader = &gDeferredPostTonemapACESProgram;
+        break;
+    }
+    case ALTonemap::TONEMAP_UCHIMURA:
+    {
+        tone_shader = &gDeferredPostTonemapUchiProgram;
+        break;
+    }
+    case ALTonemap::TONEMAP_AMD:
+    {
+        tone_shader = &gDeferredPostTonemapLPMProgram;
+        break;
+    }
+    case ALTonemap::TONEMAP_UNCHARTED:
+    {
+        tone_shader = &gDeferredPostTonemapHableProgram;
+        break;
+    }
+    }
+    tone_shader->bind();
+
+    F32 tone_exposure = llclamp(gSavedSettings.getF32("RenderExposure"), 0.5f, 4.f);
+    tone_shader->uniform1f(al_exposure, tone_exposure);
+
+    switch (mTonemapType)
+    {
+    default:
+        break;
+    case ALTonemap::TONEMAP_UCHIMURA:
+    {
+        auto uchi_1 = LLVector3(gSavedSettings.getF32("AlchemyToneMapUchimuraMaxBrightness"), gSavedSettings.getF32("AlchemyToneMapUchimuraContrast"), gSavedSettings.getF32("AlchemyToneMapUchimuraLinearStart"));
+        auto uchi_2 = LLVector3(gSavedSettings.getF32("AlchemyToneMapUchimuraLinearLength"), gSavedSettings.getF32("AlchemyToneMapUchimuraBlackLevel"), 0.0);
+        tone_shader->uniform3fv(tone_uchimura_a, 1, uchi_1.mV);
+        tone_shader->uniform3fv(tone_uchimura_b, 1, uchi_2.mV);
+        break;
+    }
+    case ALTonemap::TONEMAP_AMD:
+    {
+        const F32 sh_contrast_range = gSavedSettings.getF32("AlchemyToneMapAMDShoulderContrastRange");
+
+        varAF3(saturation) = initAF3(gSavedSettings.getF32("AlchemyToneMapAMDSaturationR"), gSavedSettings.getF32("AlchemyToneMapAMDSaturationG"), gSavedSettings.getF32("AlchemyToneMapAMDSaturationB"));
+        varAF3(crosstalk) = initAF3(gSavedSettings.getF32("AlchemyToneMapAMDCrosstalkR"), gSavedSettings.getF32("AlchemyToneMapAMDCrosstalkG"), gSavedSettings.getF32("AlchemyToneMapAMDCrosstalkB"));
+        LpmSetup(
+            sh_contrast_range != 1.0, LPM_CONFIG_709_709, LPM_COLORS_709_709, // <-- Using the LPM_ prefabs to make inputs easier.
+            0.0, // softGap
+            gSavedSettings.getF32("AlchemyToneMapAMDHDRMax"), // hdrMax
+            gSavedSettings.getF32("AlchemyToneMapAMDExposure"), // exposure
+            gSavedSettings.getF32("AlchemyToneMapAMDContrast"), // contrast
+            sh_contrast_range, // shoulder contrast
+            saturation, crosstalk);
+
+        tone_shader->uniform4uiv(tonemap_amd_params, 24, LPM_CONTROL_BLOCK);
+        tone_shader->uniform1i(tonemap_amd_params_shoulder, sh_contrast_range != 1.0);
+        break;
+    }
+    case ALTonemap::TONEMAP_UNCHARTED:
+    {
+        auto uncharted_params_1 = LLVector3(gSavedSettings.getF32("AlchemyToneMapFilmicToeStr"), gSavedSettings.getF32("AlchemyToneMapFilmicToeLen"), gSavedSettings.getF32("AlchemyToneMapFilmicShoulderStr"));
+        auto uncharted_params_2 = LLVector3(gSavedSettings.getF32("AlchemyToneMapFilmicShoulderLen"), gSavedSettings.getF32("AlchemyToneMapFilmicShoulderAngle"), gSavedSettings.getF32("AlchemyToneMapFilmicGamma"));
+        auto uncharted_params_3 = LLVector3(gSavedSettings.getF32("AlchemyToneMapFilmicWhitePoint"), 2.0, 0.0);
+
+        tone_shader->uniform3fv(tone_uncharted_a, 1, uncharted_params_1.mV);
+        tone_shader->uniform3fv(tone_uncharted_b, 1, uncharted_params_2.mV);
+        tone_shader->uniform3fv(tone_uncharted_c, 1, uncharted_params_3.mV);
+        break;
+    }
+    }
+    tone_shader->unbind();
+    return true;
 }
 
 void ALRenderUtil::renderTonemap(LLRenderTarget* src, LLRenderTarget* exposure, LLRenderTarget* dst)
 {
-	dst->bindTarget();
-
-	static LLCachedControl<bool> no_post(gSavedSettings, "RenderDisablePostProcessing", false);
-	static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
-	LLGLSLShader* tone_shader = nullptr;
-	if ((no_post && gFloaterTools->isAvailable()) || LLEnvironment::instance().getCurrentSky()->getReflectionProbeAmbiance(should_auto_adjust) == 0.f)
-	{
-		tone_shader = &gDeferredPostTonemapProgram;
-	}
-	else
-	{
-		switch (mTonemapType)
-		{
-		default:
-		case ALTonemap::TONEMAP_ACES_HILL:
-		{
-			tone_shader = &gDeferredPostTonemapACESProgram;
-			break;
-		}
-		case ALTonemap::TONEMAP_UCHIMURA:
-		{
-			tone_shader = &gDeferredPostTonemapUchiProgram;
-			break;
-		}
-		case ALTonemap::TONEMAP_AMD:
-		{
-			tone_shader = &gDeferredPostTonemapLPMProgram;
-			break;
-		}
-		case ALTonemap::TONEMAP_UNCHARTED:
-		{
-			tone_shader = &gDeferredPostTonemapHableProgram;
-			break;
-		}
-		}
-	}
-
-	tone_shader->bind();
-
-	tone_shader->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
-	tone_shader->bindTexture(LLShaderMgr::EXPOSURE_MAP, exposure, false, LLTexUnit::TFO_BILINEAR);
-
-	tone_shader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, src->getWidth(), src->getHeight());
-
-	static LLStaticHashedString aces_mix("aces_mix");
-	tone_shader->uniform1f(aces_mix, gEXRImage.notNull() ? 0.f : 0.3f);
-
-	gPipeline.mScreenTriangleVB->setBuffer();
-	gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-	stop_glerror();
-
-	tone_shader->unbindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src->getUsage());
-	tone_shader->unbindTexture(LLShaderMgr::EXPOSURE_MAP, exposure->getUsage());
-	tone_shader->unbind();
-
-	dst->flush();
+    dst->bindTarget();
+
+    static LLCachedControl<bool> no_post(gSavedSettings, "RenderDisablePostProcessing", false);
+    static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
+    LLGLSLShader* tone_shader = nullptr;
+    if ((no_post && gFloaterTools->isAvailable()) || LLEnvironment::instance().getCurrentSky()->getReflectionProbeAmbiance(should_auto_adjust) == 0.f)
+    {
+        tone_shader = &gDeferredPostTonemapProgram;
+    }
+    else
+    {
+        switch (mTonemapType)
+        {
+        default:
+        case ALTonemap::TONEMAP_ACES_HILL:
+        {
+            tone_shader = &gDeferredPostTonemapACESProgram;
+            break;
+        }
+        case ALTonemap::TONEMAP_UCHIMURA:
+        {
+            tone_shader = &gDeferredPostTonemapUchiProgram;
+            break;
+        }
+        case ALTonemap::TONEMAP_AMD:
+        {
+            tone_shader = &gDeferredPostTonemapLPMProgram;
+            break;
+        }
+        case ALTonemap::TONEMAP_UNCHARTED:
+        {
+            tone_shader = &gDeferredPostTonemapHableProgram;
+            break;
+        }
+        }
+    }
+
+    tone_shader->bind();
+
+    tone_shader->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
+    tone_shader->bindTexture(LLShaderMgr::EXPOSURE_MAP, exposure, false, LLTexUnit::TFO_BILINEAR);
+
+    tone_shader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, src->getWidth(), src->getHeight());
+
+    static LLStaticHashedString aces_mix("aces_mix");
+    tone_shader->uniform1f(aces_mix, gEXRImage.notNull() ? 0.f : 0.3f);
+
+    gPipeline.mScreenTriangleVB->setBuffer();
+    gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    stop_glerror();
+
+    tone_shader->unbindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src->getUsage());
+    tone_shader->unbindTexture(LLShaderMgr::EXPOSURE_MAP, exposure->getUsage());
+    tone_shader->unbind();
+
+    dst->flush();
 }
 
 bool ALRenderUtil::setupColorGrade()
 {
-	if (mCGLut)
-	{
-		LLImageGL::deleteTextures(1, &mCGLut);
-		mCGLut = 0;
-	}
-
-	if (LLPipeline::sRenderDeferred)
-	{
-		std::string lut_name = gSavedSettings.getString("RenderColorGradeLUT");
-		if (!lut_name.empty())
-		{
-			std::string lut_path = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "colorlut", lut_name);
-
-			if(!LLFile::isfile(lut_path))
-			{
-				lut_path = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "colorlut", lut_name);
-			}
-
-			if (LLFile::isfile(lut_path))
-			{
-				std::string temp_exten = gDirUtilp->getExtension(lut_path);
-				bool decode_success = false;
-				LLPointer<LLImageRaw> raw_image;
-				bool flip_green = true;
-				bool swap_bluegreen = true;
-				if (temp_exten == "cube")
-				{
-					LutCube  lutCube(lut_path);
-					if (!lutCube.colorCube.empty())
-					{
-						try
-						{
-							raw_image = new LLImageRaw(lutCube.colorCube.data(), lutCube.size * lutCube.size, lutCube.size, 4);
-						}
-						catch (const std::bad_alloc&)
-						{
-							return true;
-						}
-						flip_green = false;
-						swap_bluegreen = false;
-						decode_success = true;
-					}
-				}
-				else
-				{
-					enum class ELutExt
-					{
-						EXT_IMG_TGA = 0,
-						EXT_IMG_PNG,
-						EXT_IMG_JPEG,
-						EXT_IMG_BMP,
-						EXT_IMG_WEBP,
-						EXT_NONE
-					};
-
-					ELutExt extension = ELutExt::EXT_NONE;
-					if (temp_exten == "tga")
-					{
-						extension = ELutExt::EXT_IMG_TGA;
-					}
-					else if (temp_exten == "png")
-					{
-						extension = ELutExt::EXT_IMG_PNG;
-					}
-					else if (temp_exten == "jpg" || temp_exten == "jpeg")
-					{
-						extension = ELutExt::EXT_IMG_JPEG;
-					}
-					else if (temp_exten == "bmp")
-					{
-						extension = ELutExt::EXT_IMG_BMP;
-					}
-					else if (temp_exten == "webp")
-					{
-						extension = ELutExt::EXT_IMG_WEBP;
-					}
-
-					raw_image = new LLImageRaw;
-
-					switch (extension)
-					{
-					default:
-						break;
-					case ELutExt::EXT_IMG_TGA:
-					{
-						LLPointer<LLImageTGA> tga_image = new LLImageTGA;
-						if (tga_image->load(lut_path) && tga_image->decode(raw_image, 0.0f))
-						{
-							decode_success = true;
-						}
-						break;
-					}
-					case ELutExt::EXT_IMG_PNG:
-					{
-						LLPointer<LLImagePNG> png_image = new LLImagePNG;
-						if (png_image->load(lut_path) && png_image->decode(raw_image, 0.0f))
-						{
-							decode_success = true;
-						}
-						break;
-					}
-					case ELutExt::EXT_IMG_JPEG:
-					{
-						LLPointer<LLImageJPEG> jpg_image = new LLImageJPEG;
-						if (jpg_image->load(lut_path) && jpg_image->decode(raw_image, 0.0f))
-						{
-							decode_success = true;
-						}
-						break;
-					}
-					case ELutExt::EXT_IMG_BMP:
-					{
-						LLPointer<LLImageBMP> bmp_image = new LLImageBMP;
-						if (bmp_image->load(lut_path) && bmp_image->decode(raw_image, 0.0f))
-						{
-							decode_success = true;
-						}
-						break;
-					}
-					case ELutExt::EXT_IMG_WEBP:
-					{
-						LLPointer<LLImageWebP> webp_image = new LLImageWebP;
-						if (webp_image->load(lut_path) && webp_image->decode(raw_image, 0.0f))
-						{
-							decode_success = true;
-						}
-						break;
-					}
-					}
-				}
-
-				if (decode_success && raw_image)
-				{
-					U32 primary_format = 0;
-					U32 int_format = 0;
-					switch (raw_image->getComponents())
-					{
-					case 3:
-					{
-						primary_format = GL_RGB;
-						int_format = GL_RGB8;
-						break;
-					}
-					case 4:
-					{
-						primary_format = GL_RGBA;
-						int_format = GL_RGBA8;
-						break;
-					}
-					default:
-					{
-						LL_WARNS() << "Color LUT has invalid number of color components: " << raw_image->getComponents() << LL_ENDL;
-						return true;
-					}
-					};
-
-					S32 image_height = raw_image->getHeight();
-					S32 image_width = raw_image->getWidth();
-					if ((image_height > 0 && image_height <= gGLManager.mGLMaxTextureSize)		   // within dimension limit
-						&& ((image_height * image_height) == image_width)) // width is height * height
-					{
-						mCGLutSize = LLVector4(image_height, (float)flip_green, (float)swap_bluegreen);
-
-						LLImageGL::generateTextures(1, &mCGLut);
-						gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE_3D, mCGLut);
-						{
-							stop_glerror();
-							glTexImage3D(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE_3D), 0, int_format, image_height, image_height, image_height, 0, primary_format, GL_UNSIGNED_BYTE, raw_image->getData());
-							stop_glerror();
-						}
-						gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
-						gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
-						gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE_3D);
-					}
-					else
-					{
-						LL_WARNS() << "Color LUT is invalid width or height: " << image_height << " x " << image_width << " at path " << lut_path << LL_ENDL;
-					}
-				}
-				else
-				{
-					LL_WARNS() << "Failed to decode color grading LUT: " << lut_path << LL_ENDL;
-				}
-			}
-		}
-	}
-	return true;
+    if (mCGLut)
+    {
+        LLImageGL::deleteTextures(1, &mCGLut);
+        mCGLut = 0;
+    }
+
+    if (LLPipeline::sRenderDeferred)
+    {
+        std::string lut_name = gSavedSettings.getString("RenderColorGradeLUT");
+        if (!lut_name.empty())
+        {
+            std::string lut_path = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "colorlut", lut_name);
+
+            if(!LLFile::isfile(lut_path))
+            {
+                lut_path = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "colorlut", lut_name);
+            }
+
+            if (LLFile::isfile(lut_path))
+            {
+                std::string temp_exten = gDirUtilp->getExtension(lut_path);
+                bool decode_success = false;
+                LLPointer<LLImageRaw> raw_image;
+                bool flip_green = true;
+                bool swap_bluegreen = true;
+                if (temp_exten == "cube")
+                {
+                    LutCube  lutCube(lut_path);
+                    if (!lutCube.colorCube.empty())
+                    {
+                        try
+                        {
+                            raw_image = new LLImageRaw(lutCube.colorCube.data(), lutCube.size * lutCube.size, lutCube.size, 4);
+                        }
+                        catch (const std::bad_alloc&)
+                        {
+                            return true;
+                        }
+                        flip_green = false;
+                        swap_bluegreen = false;
+                        decode_success = true;
+                    }
+                }
+                else
+                {
+                    enum class ELutExt
+                    {
+                        EXT_IMG_TGA = 0,
+                        EXT_IMG_PNG,
+                        EXT_IMG_JPEG,
+                        EXT_IMG_BMP,
+                        EXT_IMG_WEBP,
+                        EXT_NONE
+                    };
+
+                    ELutExt extension = ELutExt::EXT_NONE;
+                    if (temp_exten == "tga")
+                    {
+                        extension = ELutExt::EXT_IMG_TGA;
+                    }
+                    else if (temp_exten == "png")
+                    {
+                        extension = ELutExt::EXT_IMG_PNG;
+                    }
+                    else if (temp_exten == "jpg" || temp_exten == "jpeg")
+                    {
+                        extension = ELutExt::EXT_IMG_JPEG;
+                    }
+                    else if (temp_exten == "bmp")
+                    {
+                        extension = ELutExt::EXT_IMG_BMP;
+                    }
+                    else if (temp_exten == "webp")
+                    {
+                        extension = ELutExt::EXT_IMG_WEBP;
+                    }
+
+                    raw_image = new LLImageRaw;
+
+                    switch (extension)
+                    {
+                    default:
+                        break;
+                    case ELutExt::EXT_IMG_TGA:
+                    {
+                        LLPointer<LLImageTGA> tga_image = new LLImageTGA;
+                        if (tga_image->load(lut_path) && tga_image->decode(raw_image, 0.0f))
+                        {
+                            decode_success = true;
+                        }
+                        break;
+                    }
+                    case ELutExt::EXT_IMG_PNG:
+                    {
+                        LLPointer<LLImagePNG> png_image = new LLImagePNG;
+                        if (png_image->load(lut_path) && png_image->decode(raw_image, 0.0f))
+                        {
+                            decode_success = true;
+                        }
+                        break;
+                    }
+                    case ELutExt::EXT_IMG_JPEG:
+                    {
+                        LLPointer<LLImageJPEG> jpg_image = new LLImageJPEG;
+                        if (jpg_image->load(lut_path) && jpg_image->decode(raw_image, 0.0f))
+                        {
+                            decode_success = true;
+                        }
+                        break;
+                    }
+                    case ELutExt::EXT_IMG_BMP:
+                    {
+                        LLPointer<LLImageBMP> bmp_image = new LLImageBMP;
+                        if (bmp_image->load(lut_path) && bmp_image->decode(raw_image, 0.0f))
+                        {
+                            decode_success = true;
+                        }
+                        break;
+                    }
+                    case ELutExt::EXT_IMG_WEBP:
+                    {
+                        LLPointer<LLImageWebP> webp_image = new LLImageWebP;
+                        if (webp_image->load(lut_path) && webp_image->decode(raw_image, 0.0f))
+                        {
+                            decode_success = true;
+                        }
+                        break;
+                    }
+                    }
+                }
+
+                if (decode_success && raw_image)
+                {
+                    U32 primary_format = 0;
+                    U32 int_format = 0;
+                    switch (raw_image->getComponents())
+                    {
+                    case 3:
+                    {
+                        primary_format = GL_RGB;
+                        int_format = GL_RGB8;
+                        break;
+                    }
+                    case 4:
+                    {
+                        primary_format = GL_RGBA;
+                        int_format = GL_RGBA8;
+                        break;
+                    }
+                    default:
+                    {
+                        LL_WARNS() << "Color LUT has invalid number of color components: " << raw_image->getComponents() << LL_ENDL;
+                        return true;
+                    }
+                    };
+
+                    S32 image_height = raw_image->getHeight();
+                    S32 image_width = raw_image->getWidth();
+                    if ((image_height > 0 && image_height <= gGLManager.mGLMaxTextureSize)         // within dimension limit
+                        && ((image_height * image_height) == image_width)) // width is height * height
+                    {
+                        mCGLutSize = LLVector4(image_height, (float)flip_green, (float)swap_bluegreen);
+
+                        LLImageGL::generateTextures(1, &mCGLut);
+                        gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE_3D, mCGLut);
+                        {
+                            stop_glerror();
+                            glTexImage3D(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE_3D), 0, int_format, image_height, image_height, image_height, 0, primary_format, GL_UNSIGNED_BYTE, raw_image->getData());
+                            stop_glerror();
+                        }
+                        gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
+                        gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
+                        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE_3D);
+                    }
+                    else
+                    {
+                        LL_WARNS() << "Color LUT is invalid width or height: " << image_height << " x " << image_width << " at path " << lut_path << LL_ENDL;
+                    }
+                }
+                else
+                {
+                    LL_WARNS() << "Failed to decode color grading LUT: " << lut_path << LL_ENDL;
+                }
+            }
+        }
+    }
+    return true;
 }
 
 void ALRenderUtil::renderColorGrade(LLRenderTarget* src, LLRenderTarget* dst)
 {
-	dst->bindTarget();
-
-	static LLCachedControl<bool> buildNoPost(gSavedSettings, "RenderDisablePostProcessing", false);
-	static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
-	bool no_post = gSnapshotNoPost || (buildNoPost && gFloaterTools->isAvailable());
-	LLGLSLShader* tone_shader = nullptr;
-	if (mCGLut != 0)
-	{
-		tone_shader = no_post && gFloaterTools->isAvailable() ? &gDeferredPostColorCorrectLUTProgram[2] : // no post (no gamma, no exposure, no tonemapping)
-			LLEnvironment::instance().getCurrentSky()->getReflectionProbeAmbiance(should_auto_adjust) == 0.f ? &gDeferredPostColorCorrectLUTProgram[1] :
-			&gDeferredPostColorCorrectLUTProgram[0];
-	}
-	else
-	{
-		tone_shader = no_post && gFloaterTools->isAvailable() ? &gDeferredPostColorCorrectProgram[2] : // no post (no gamma, no exposure, no tonemapping)
-			LLEnvironment::instance().getCurrentSky()->getReflectionProbeAmbiance(should_auto_adjust) == 0.f ? &gDeferredPostColorCorrectProgram[1] :
-			&gDeferredPostColorCorrectProgram[0];
-	}
-
-	tone_shader->bind();
-
-	tone_shader->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
-
-	tone_shader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, src->getWidth(), src->getHeight());
-
-
-	S32 channel = -1;
-	if (mCGLut != 0)
-	{
-		channel = tone_shader->enableTexture(LLShaderMgr::COLORGRADE_LUT, LLTexUnit::TT_TEXTURE_3D);
-		if (channel > -1)
-		{
-			gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE_3D, mCGLut);
-			gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
-			gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
-		}
-
-		tone_shader->uniform4fv(LLShaderMgr::COLORGRADE_LUT_SIZE, 1, mCGLutSize.mV);
-	}
-
-	gPipeline.mScreenTriangleVB->setBuffer();
-	gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-	stop_glerror();
-
-	if (channel > -1)
-	{
-		gGL.getTexUnit(channel)->unbind(LLTexUnit::TT_TEXTURE_3D);
-	}
-
-	tone_shader->unbindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src->getUsage());
-	tone_shader->unbind();
-
-	dst->flush();
+    dst->bindTarget();
+
+    static LLCachedControl<bool> buildNoPost(gSavedSettings, "RenderDisablePostProcessing", false);
+    static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
+    bool no_post = gSnapshotNoPost || (buildNoPost && gFloaterTools->isAvailable());
+    LLGLSLShader* tone_shader = nullptr;
+    if (mCGLut != 0)
+    {
+        tone_shader = no_post && gFloaterTools->isAvailable() ? &gDeferredPostColorCorrectLUTProgram[2] : // no post (no gamma, no exposure, no tonemapping)
+            LLEnvironment::instance().getCurrentSky()->getReflectionProbeAmbiance(should_auto_adjust) == 0.f ? &gDeferredPostColorCorrectLUTProgram[1] :
+            &gDeferredPostColorCorrectLUTProgram[0];
+    }
+    else
+    {
+        tone_shader = no_post && gFloaterTools->isAvailable() ? &gDeferredPostColorCorrectProgram[2] : // no post (no gamma, no exposure, no tonemapping)
+            LLEnvironment::instance().getCurrentSky()->getReflectionProbeAmbiance(should_auto_adjust) == 0.f ? &gDeferredPostColorCorrectProgram[1] :
+            &gDeferredPostColorCorrectProgram[0];
+    }
+
+    tone_shader->bind();
+
+    tone_shader->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
+
+    tone_shader->uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, src->getWidth(), src->getHeight());
+
+
+    S32 channel = -1;
+    if (mCGLut != 0)
+    {
+        channel = tone_shader->enableTexture(LLShaderMgr::COLORGRADE_LUT, LLTexUnit::TT_TEXTURE_3D);
+        if (channel > -1)
+        {
+            gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE_3D, mCGLut);
+            gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
+            gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
+        }
+
+        tone_shader->uniform4fv(LLShaderMgr::COLORGRADE_LUT_SIZE, 1, mCGLutSize.mV);
+    }
+
+    gPipeline.mScreenTriangleVB->setBuffer();
+    gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    stop_glerror();
+
+    if (channel > -1)
+    {
+        gGL.getTexUnit(channel)->unbind(LLTexUnit::TT_TEXTURE_3D);
+    }
+
+    tone_shader->unbindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src->getUsage());
+    tone_shader->unbind();
+
+    dst->flush();
 }
 
 bool ALRenderUtil::setupSharpen()
 {
-	if (LLPipeline::sRenderDeferred)
-	{
-		mSharpenMethod = gSavedSettings.getU32("RenderSharpenMethod");
-		if (mSharpenMethod >= SHARPEN_COUNT)
-		{
-			mSharpenMethod = ALSharpen::SHARPEN_CAS;
-		}
-
-		if (mSharpenMethod == ALSharpen::SHARPEN_CAS && !gDeferredPostCASProgram.isComplete())
-		{
-			mSharpenMethod = ALSharpen::SHARPEN_DLS;
-		}
-
-		if (mSharpenMethod == ALSharpen::SHARPEN_DLS && !gDeferredPostDLSProgram.isComplete())
-		{
-			mSharpenMethod = ALSharpen::SHARPEN_NONE;
-		}
-
-		LLGLSLShader* sharpen_shader = nullptr;
-		switch (mSharpenMethod)
-		{
-		case ALSharpen::SHARPEN_DLS:
-		{
-			sharpen_shader = &gDeferredPostDLSProgram;
-			sharpen_shader->bind();
-			LLVector3 params = LLVector3(gSavedSettings.getF32("RenderSharpenDLSSharpness"), gSavedSettings.getF32("RenderSharpenDLSDenoise"), 0.f);
-			params.clamp(LLVector3::zero, LLVector3::all_one);
-			sharpen_shader->uniform3fv(sharpen_params, 1, params.mV);
-			sharpen_shader->unbind();
-			break;
-		}
-		default:
-		case ALSharpen::SHARPEN_NONE:
-			break;
-		}
-	}
-	else
-	{
-		mSharpenMethod = ALSharpen::SHARPEN_NONE;
-	}
-	return true;
+    if (LLPipeline::sRenderDeferred)
+    {
+        mSharpenMethod = gSavedSettings.getU32("RenderSharpenMethod");
+        if (mSharpenMethod >= SHARPEN_COUNT)
+        {
+            mSharpenMethod = ALSharpen::SHARPEN_CAS;
+        }
+
+        if (mSharpenMethod == ALSharpen::SHARPEN_CAS && !gDeferredPostCASProgram.isComplete())
+        {
+            mSharpenMethod = ALSharpen::SHARPEN_DLS;
+        }
+
+        if (mSharpenMethod == ALSharpen::SHARPEN_DLS && !gDeferredPostDLSProgram.isComplete())
+        {
+            mSharpenMethod = ALSharpen::SHARPEN_NONE;
+        }
+
+        LLGLSLShader* sharpen_shader = nullptr;
+        switch (mSharpenMethod)
+        {
+        case ALSharpen::SHARPEN_DLS:
+        {
+            sharpen_shader = &gDeferredPostDLSProgram;
+            sharpen_shader->bind();
+            LLVector3 params = LLVector3(gSavedSettings.getF32("RenderSharpenDLSSharpness"), gSavedSettings.getF32("RenderSharpenDLSDenoise"), 0.f);
+            params.clamp(LLVector3::zero, LLVector3::all_one);
+            sharpen_shader->uniform3fv(sharpen_params, 1, params.mV);
+            sharpen_shader->unbind();
+            break;
+        }
+        default:
+        case ALSharpen::SHARPEN_NONE:
+            break;
+        }
+    }
+    else
+    {
+        mSharpenMethod = ALSharpen::SHARPEN_NONE;
+    }
+    return true;
 }
 
 void ALRenderUtil::renderSharpen(LLRenderTarget* src, LLRenderTarget* dst)
 {
-	if (mSharpenMethod == ALSharpen::SHARPEN_NONE)
-	{
-		gPipeline.copyRenderTarget(src, dst);
-		return;
-	}
-
-	LLGLSLShader* sharpen_shader = nullptr;
-	switch (mSharpenMethod)
-	{
-	case ALSharpen::SHARPEN_CAS:
-	{
-		sharpen_shader = &gDeferredPostCASProgram;
-		break;
-	}
-	case ALSharpen::SHARPEN_DLS:
-	{
-		sharpen_shader = &gDeferredPostDLSProgram;
-		break;
-	}
-	default:
-	case ALSharpen::SHARPEN_NONE:
-	{
-		gPipeline.copyRenderTarget(src, dst);
-		return;
-	}
-	}
-
-	// Bind setup:
-	dst->bindTarget();
-
-	sharpen_shader->bind();
-
-	if (mSharpenMethod == ALSharpen::SHARPEN_CAS)
-	{
-		static LLCachedControl<F32> cas_sharpness(gSavedSettings, "RenderSharpenCASSharpness", 0.6f);
-		static LLStaticHashedString cas_param_0("cas_param_0");
-		static LLStaticHashedString cas_param_1("cas_param_1");
-		static LLStaticHashedString out_screen_res("out_screen_res");
-
-		varAU4(const0);
-		varAU4(const1);
-		CasSetup(const0, const1,
-			cas_sharpness,             // Sharpness tuning knob (0.0 to 1.0).
-			src->getWidth(), src->getHeight(),  // Example input size.
-			dst->getWidth(), dst->getHeight()); // Example output size.
-
-		sharpen_shader->uniform4uiv(cas_param_0, 1, const0);
-		sharpen_shader->uniform4uiv(cas_param_1, 1, const1);
-
-		sharpen_shader->uniform2f(out_screen_res, dst->getWidth(), dst->getHeight());
-	}
-
-	sharpen_shader->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
-
-	// Draw
-	gPipeline.mScreenTriangleVB->setBuffer();
-	gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-
-	sharpen_shader->unbind();
-
-	dst->flush();
+    if (mSharpenMethod == ALSharpen::SHARPEN_NONE)
+    {
+        gPipeline.copyRenderTarget(src, dst);
+        return;
+    }
+
+    LLGLSLShader* sharpen_shader = nullptr;
+    switch (mSharpenMethod)
+    {
+    case ALSharpen::SHARPEN_CAS:
+    {
+        sharpen_shader = &gDeferredPostCASProgram;
+        break;
+    }
+    case ALSharpen::SHARPEN_DLS:
+    {
+        sharpen_shader = &gDeferredPostDLSProgram;
+        break;
+    }
+    default:
+    case ALSharpen::SHARPEN_NONE:
+    {
+        gPipeline.copyRenderTarget(src, dst);
+        return;
+    }
+    }
+
+    // Bind setup:
+    dst->bindTarget();
+
+    sharpen_shader->bind();
+
+    if (mSharpenMethod == ALSharpen::SHARPEN_CAS)
+    {
+        static LLCachedControl<F32> cas_sharpness(gSavedSettings, "RenderSharpenCASSharpness", 0.6f);
+        static LLStaticHashedString cas_param_0("cas_param_0");
+        static LLStaticHashedString cas_param_1("cas_param_1");
+        static LLStaticHashedString out_screen_res("out_screen_res");
+
+        varAU4(const0);
+        varAU4(const1);
+        CasSetup(const0, const1,
+            cas_sharpness,             // Sharpness tuning knob (0.0 to 1.0).
+            src->getWidth(), src->getHeight(),  // Example input size.
+            dst->getWidth(), dst->getHeight()); // Example output size.
+
+        sharpen_shader->uniform4uiv(cas_param_0, 1, const0);
+        sharpen_shader->uniform4uiv(cas_param_1, 1, const1);
+
+        sharpen_shader->uniform2f(out_screen_res, dst->getWidth(), dst->getHeight());
+    }
+
+    sharpen_shader->bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
+
+    // Draw
+    gPipeline.mScreenTriangleVB->setBuffer();
+    gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+    sharpen_shader->unbind();
+
+    dst->flush();
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl
index 43863dd37aeac2500849d3e4bb4ee129f8bf1f9e..d3ca3ec8c133ccd23a352b6d2ab08fa1187e8daf 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarEyesV.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file avatarEyesV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -40,12 +40,12 @@ out vec3 vary_position;
 
 void main()
 {
-	//transform vertex
-	vary_position = (modelview_matrix * vec4(position.xyz, 1.0)).xyz;
-	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
-	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
-	
-	vary_normal = normalize(normal_matrix * normal);
+    //transform vertex
+    vary_position = (modelview_matrix * vec4(position.xyz, 1.0)).xyz;
+    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
+
+    vary_normal = normalize(normal_matrix * normal);
 
-	vertex_color = diffuse_color;
+    vertex_color = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl
index db7597dd7414e5aa074c3fdc83b252983a084e02..b904df3a1be1b82cf119488583567ff1bb418b68 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarF.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file avatarF.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -37,21 +37,21 @@ in vec3 vary_position;
 
 void mirrorClip(vec3 pos);
 
-void main() 
+void main()
 {
     mirrorClip(vary_position);
 
-	vec4 diff = texture(diffuseMap, vary_texcoord0.xy);
-	
-	if (diff.a < minimum_alpha)
-	{
-		discard;
-	}
-	
-	frag_data[0] = vec4(diff.rgb, 0.0);
-	frag_data[1] = vec4(0,0,0,0);
-	vec3 nvn = normalize(vary_normal);
-	frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
+    vec4 diff = texture(diffuseMap, vary_texcoord0.xy);
+
+    if (diff.a < minimum_alpha)
+    {
+        discard;
+    }
+
+    frag_data[0] = vec4(diff.rgb, 0.0);
+    frag_data[1] = vec4(0,0,0,0);
+    vec3 nvn = normalize(vary_normal);
+    frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
     frag_data[3] = vec4(0);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl
index 5cc2846156721a4f7a843104475655d82a0a6213..aabbbac12a55df2ed2ad5ca9ea36360b883c93db 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/avatarV.glsl
@@ -1,28 +1,28 @@
-/** 
+/**
  * @file avatarV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
 uniform mat4 projection_matrix;
 
 in vec3 position;
@@ -39,27 +39,27 @@ out vec3 vary_position;
 
 void main()
 {
-	vary_texcoord0 = texcoord0;
-				
-	vec4 pos;
-	vec3 norm;
-	
-	vec4 pos_in = vec4(position.xyz, 1.0);
-	mat4 trans = getSkinnedTransform();
-	pos.x = dot(trans[0], pos_in);
-	pos.y = dot(trans[1], pos_in);
-	pos.z = dot(trans[2], pos_in);
-	pos.w = 1.0;
-	
-	norm.x = dot(trans[0].xyz, normal);
-	norm.y = dot(trans[1].xyz, normal);
-	norm.z = dot(trans[2].xyz, normal);
-	norm = normalize(norm);
-	
-	vary_normal = norm;
-	
+    vary_texcoord0 = texcoord0;
+
+    vec4 pos;
+    vec3 norm;
+
+    vec4 pos_in = vec4(position.xyz, 1.0);
+    mat4 trans = getSkinnedTransform();
+    pos.x = dot(trans[0], pos_in);
+    pos.y = dot(trans[1], pos_in);
+    pos.z = dot(trans[2], pos_in);
+    pos.w = 1.0;
+
+    norm.x = dot(trans[0].xyz, normal);
+    norm.y = dot(trans[1].xyz, normal);
+    norm.z = dot(trans[2].xyz, normal);
+    norm = normalize(norm);
+
+    vary_normal = norm;
+
     vary_position = pos.xyz;
-	gl_Position = projection_matrix * pos;
+    gl_Position = projection_matrix * pos;
 }
 
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl
index 8483f257fa1e0dd202844d7159edee972078a10f..2cc3085cd0047a69c7e1b676c9fc3145829eb32d 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/bumpF.glsl
@@ -1,30 +1,30 @@
-/** 
+/**
  * @file bumpF.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
 
 /*[EXTRA_CODE_HERE]*/
- 
+
 out vec4 frag_data[4];
 
 uniform float minimum_alpha;
@@ -40,28 +40,28 @@ in vec2 vary_texcoord0;
 in vec3 vary_position;
 
 void mirrorClip(vec3 pos);
-void main() 
+void main()
 {
     mirrorClip(vary_position);
 
-	vec4 col = texture(diffuseMap, vary_texcoord0.xy);
-	
-	if(col.a < minimum_alpha)
-	{
-		discard;
-    }		
-		col *= vertex_color;
-		
-		vec3 norm = texture(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0;
+    vec4 col = texture(diffuseMap, vary_texcoord0.xy);
+
+    if(col.a < minimum_alpha)
+    {
+        discard;
+    }
+        col *= vertex_color;
+
+        vec3 norm = texture(bumpMap, vary_texcoord0.xy).rgb * 2.0 - 1.0;
+
+        vec3 tnorm = vec3(dot(norm,vary_mat0),
+              dot(norm,vary_mat1),
+              dot(norm,vary_mat2));
 
-		vec3 tnorm = vec3(dot(norm,vary_mat0),
-			  dot(norm,vary_mat1),
-			  dot(norm,vary_mat2));
-						
-		frag_data[0] = vec4(col.rgb, 0.0);
-		frag_data[1] = vertex_color.aaaa; // spec
-		//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested
-		vec3 nvn = normalize(tnorm);
-		frag_data[2] = vec4(nvn, GBUFFER_FLAG_HAS_ATMOS);
+        frag_data[0] = vec4(col.rgb, 0.0);
+        frag_data[1] = vertex_color.aaaa; // spec
+        //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested
+        vec3 nvn = normalize(tnorm);
+        frag_data[2] = vec4(nvn, GBUFFER_FLAG_HAS_ATMOS);
         frag_data[3] = vec4(vertex_color.a, 0, 0, 0);
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl
index 74319349f65b9051420da109ae1656cc7cda3cf6..a381392f6c89bf0f24f8d0533317f41180a3c412 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/bumpV.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file bumpV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -48,29 +48,29 @@ uniform mat4 projection_matrix;
 
 void main()
 {
-	//transform vertex
+    //transform vertex
 #ifdef HAS_SKIN
     mat4 mat = getObjectSkinnedTransform();
-	mat = modelview_matrix * mat;
-	vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
+    mat = modelview_matrix * mat;
+    vec3 pos = (mat*vec4(position.xyz, 1.0)).xyz;
     vary_position = pos;
-	gl_Position = projection_matrix*vec4(pos, 1.0);
+    gl_Position = projection_matrix*vec4(pos, 1.0);
 
-	vec3 n = normalize((mat * vec4(normal.xyz+position.xyz, 1.0)).xyz-pos.xyz);
-	vec3 t = normalize((mat * vec4(tangent.xyz+position.xyz, 1.0)).xyz-pos.xyz);
+    vec3 n = normalize((mat * vec4(normal.xyz+position.xyz, 1.0)).xyz-pos.xyz);
+    vec3 t = normalize((mat * vec4(tangent.xyz+position.xyz, 1.0)).xyz-pos.xyz);
 #else
     vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
-	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
-	vec3 n = normalize(normal_matrix * normal);
-	vec3 t = normalize(normal_matrix * tangent.xyz);
+    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
+    vec3 n = normalize(normal_matrix * normal);
+    vec3 t = normalize(normal_matrix * tangent.xyz);
 #endif
 
-	vec3 b = cross(n, t) * tangent.w;
-	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
+    vec3 b = cross(n, t) * tangent.w;
+    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
+
+    vary_mat0 = vec3(t.x, b.x, n.x);
+    vary_mat1 = vec3(t.y, b.y, n.y);
+    vary_mat2 = vec3(t.z, b.z, n.z);
 
-	vary_mat0 = vec3(t.x, b.x, n.x);
-	vary_mat1 = vec3(t.y, b.y, n.y);
-	vary_mat2 = vec3(t.z, b.z, n.z);
-	
-	vertex_color = diffuse_color;
+    vertex_color = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
index 77a8aa3d49ef5f9fff14cf57a6c035a9ac04b282..15147c8728192b4d7b143fe41a743441215a51dc 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/deferredUtil.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file class1/deferred/deferredUtil.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -347,7 +347,7 @@ vec2 BRDF(float NoV, float roughness)
 }
 
 // Lagarde and de Rousiers 2014, "Moving Frostbite to PBR"
-float computeSpecularAO(float NoV, float ao, float roughness) 
+float computeSpecularAO(float NoV, float ao, float roughness)
 {
     return clamp(pow(NoV + ao, exp2(-16.0 * roughness - 1.0)) - 1.0 + ao, 0.0, 1.0);
 }
@@ -362,15 +362,15 @@ vec3 pbrIbl(vec3 diffuseColor,
             float perceptualRough)
 {
     // retrieve a scale and bias to F0. See [1], Figure 3
-	vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRough);
-	vec3 diffuseLight = irradiance;
-	vec3 specularLight = radiance;
-    
-	vec3 diffuse = diffuseLight * diffuseColor;
-	vec3 specular = specularLight * (specularColor * brdf.x + brdf.y);
+    vec2 brdf = BRDF(clamp(nv, 0, 1), 1.0-perceptualRough);
+    vec3 diffuseLight = irradiance;
+    vec3 specularLight = radiance;
 
-	specular *= computeSpecularAO(nv, ao, perceptualRough * perceptualRough);
-	return (diffuse * ao) + specular;
+    vec3 diffuse = diffuseLight * diffuseColor;
+    vec3 specular = specularLight * (specularColor * brdf.x + brdf.y);
+
+    specular *= computeSpecularAO(nv, ao, perceptualRough * perceptualRough);
+    return (diffuse * ao) + specular;
 }
 
 
@@ -379,18 +379,18 @@ vec3 pbrIbl(vec3 diffuseColor,
 // of the shading terms, outlined in the Readme.MD Appendix.
 struct PBRInfo
 {
-	float NdotL;                  // cos angle between normal and light direction
-	float NdotV;                  // cos angle between normal and view direction
-	float NdotH;                  // cos angle between normal and half vector
-	float LdotH;                  // cos angle between light direction and half vector
-	float VdotH;                  // cos angle between view direction and half vector
-	float perceptualRoughness;    // roughness value, as authored by the model creator (input to shader)
-	float metalness;              // metallic value at the surface
-	vec3 reflectance0;            // full reflectance color (normal incidence angle)
-	vec3 reflectance90;           // reflectance color at grazing angle
-	float alphaRoughness;         // roughness mapped to a more linear change in the roughness (proposed by [2])
-	vec3 diffuseColor;            // color contribution from diffuse lighting
-	vec3 specularColor;           // color contribution from specular lighting
+    float NdotL;                  // cos angle between normal and light direction
+    float NdotV;                  // cos angle between normal and view direction
+    float NdotH;                  // cos angle between normal and half vector
+    float LdotH;                  // cos angle between light direction and half vector
+    float VdotH;                  // cos angle between view direction and half vector
+    float perceptualRoughness;    // roughness value, as authored by the model creator (input to shader)
+    float metalness;              // metallic value at the surface
+    vec3 reflectance0;            // full reflectance color (normal incidence angle)
+    vec3 reflectance90;           // reflectance color at grazing angle
+    float alphaRoughness;         // roughness mapped to a more linear change in the roughness (proposed by [2])
+    vec3 diffuseColor;            // color contribution from diffuse lighting
+    vec3 specularColor;           // color contribution from specular lighting
 };
 
 // Basic Lambertian diffuse
@@ -398,14 +398,14 @@ struct PBRInfo
 // See also [1], Equation 1
 vec3 diffuse(PBRInfo pbrInputs)
 {
-	return pbrInputs.diffuseColor / M_PI;
+    return pbrInputs.diffuseColor / M_PI;
 }
 
 // The following equation models the Fresnel reflectance term of the spec equation (aka F())
 // Implementation of fresnel from [4], Equation 15
 vec3 specularReflection(PBRInfo pbrInputs)
 {
-	return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
+    return pbrInputs.reflectance0 + (pbrInputs.reflectance90 - pbrInputs.reflectance0) * pow(clamp(1.0 - pbrInputs.VdotH, 0.0, 1.0), 5.0);
 }
 
 // This calculates the specular geometric attenuation (aka G()),
@@ -414,13 +414,13 @@ vec3 specularReflection(PBRInfo pbrInputs)
 // alphaRoughness as input as originally proposed in [2].
 float geometricOcclusion(PBRInfo pbrInputs)
 {
-	float NdotL = pbrInputs.NdotL;
-	float NdotV = pbrInputs.NdotV;
-	float r = pbrInputs.alphaRoughness;
+    float NdotL = pbrInputs.NdotL;
+    float NdotV = pbrInputs.NdotV;
+    float r = pbrInputs.alphaRoughness;
 
-	float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
-	float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
-	return attenuationL * attenuationV;
+    float attenuationL = 2.0 * NdotL / (NdotL + sqrt(r * r + (1.0 - r * r) * (NdotL * NdotL)));
+    float attenuationV = 2.0 * NdotV / (NdotV + sqrt(r * r + (1.0 - r * r) * (NdotV * NdotV)));
+    return attenuationL * attenuationV;
 }
 
 // The following equation(s) model the distribution of microfacet normals across the area being drawn (aka D())
@@ -428,13 +428,13 @@ float geometricOcclusion(PBRInfo pbrInputs)
 // Follows the distribution function recommended in the SIGGRAPH 2013 course notes from EPIC Games [1], Equation 3.
 float microfacetDistribution(PBRInfo pbrInputs)
 {
-	float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
-	float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
-	return roughnessSq / (M_PI * f * f);
+    float roughnessSq = pbrInputs.alphaRoughness * pbrInputs.alphaRoughness;
+    float f = (pbrInputs.NdotH * roughnessSq - pbrInputs.NdotH) * pbrInputs.NdotH + 1.0;
+    return roughnessSq / (M_PI * f * f);
 }
 
-vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor, 
-                    float perceptualRoughness, 
+vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
+                    float perceptualRoughness,
                     float metallic,
                     vec3 n, // normal
                     vec3 v, // surface point to camera
@@ -442,53 +442,53 @@ vec3 pbrPunctual(vec3 diffuseColor, vec3 specularColor,
 {
     // make sure specular highlights from punctual lights don't fall off of polished surfaces
     perceptualRoughness = max(perceptualRoughness, MIN_PBR_ROUGHNESS);
-    
-	float alphaRoughness = perceptualRoughness * perceptualRoughness;
-
-	// Compute reflectance.
-	float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
-
-	// For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect.
-	// For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%.
-	float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
-	vec3 specularEnvironmentR0 = specularColor.rgb;
-	vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
-
-	vec3 h = normalize(l+v);                        // Half vector between both l and v
-	vec3 reflection = -normalize(reflect(v, n));
-	reflection.y *= -1.0f;
-
-	float NdotL = clamp(dot(n, l), 0.001, 1.0);
-	float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
-	float NdotH = clamp(dot(n, h), 0.0, 1.0);
-	float LdotH = clamp(dot(l, h), 0.0, 1.0);
-	float VdotH = clamp(dot(v, h), 0.0, 1.0);
-
-	PBRInfo pbrInputs = PBRInfo(
-		NdotL,
-		NdotV,
-		NdotH,
-		LdotH,
-		VdotH,
-		perceptualRoughness,
-		metallic,
-		specularEnvironmentR0,
-		specularEnvironmentR90,
-		alphaRoughness,
-		diffuseColor,
-		specularColor
-	);
-
-	// Calculate the shading terms for the microfacet specular shading model
-	vec3 F = specularReflection(pbrInputs);
-	float G = geometricOcclusion(pbrInputs);
-	float D = microfacetDistribution(pbrInputs);
-
-	// Calculation of analytical lighting contribution
-	vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
-	vec3 specContrib = F * G * D / (4.0 * NdotL * NdotV);
-	// Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
-	vec3 color = NdotL * (diffuseContrib + specContrib);
+
+    float alphaRoughness = perceptualRoughness * perceptualRoughness;
+
+    // Compute reflectance.
+    float reflectance = max(max(specularColor.r, specularColor.g), specularColor.b);
+
+    // For typical incident reflectance range (between 4% to 100%) set the grazing reflectance to 100% for typical fresnel effect.
+    // For very low reflectance range on highly diffuse objects (below 4%), incrementally reduce grazing reflecance to 0%.
+    float reflectance90 = clamp(reflectance * 25.0, 0.0, 1.0);
+    vec3 specularEnvironmentR0 = specularColor.rgb;
+    vec3 specularEnvironmentR90 = vec3(1.0, 1.0, 1.0) * reflectance90;
+
+    vec3 h = normalize(l+v);                        // Half vector between both l and v
+    vec3 reflection = -normalize(reflect(v, n));
+    reflection.y *= -1.0f;
+
+    float NdotL = clamp(dot(n, l), 0.001, 1.0);
+    float NdotV = clamp(abs(dot(n, v)), 0.001, 1.0);
+    float NdotH = clamp(dot(n, h), 0.0, 1.0);
+    float LdotH = clamp(dot(l, h), 0.0, 1.0);
+    float VdotH = clamp(dot(v, h), 0.0, 1.0);
+
+    PBRInfo pbrInputs = PBRInfo(
+        NdotL,
+        NdotV,
+        NdotH,
+        LdotH,
+        VdotH,
+        perceptualRoughness,
+        metallic,
+        specularEnvironmentR0,
+        specularEnvironmentR90,
+        alphaRoughness,
+        diffuseColor,
+        specularColor
+    );
+
+    // Calculate the shading terms for the microfacet specular shading model
+    vec3 F = specularReflection(pbrInputs);
+    float G = geometricOcclusion(pbrInputs);
+    float D = microfacetDistribution(pbrInputs);
+
+    // Calculation of analytical lighting contribution
+    vec3 diffuseContrib = (1.0 - F) * diffuse(pbrInputs);
+    vec3 specContrib = F * G * D / (4.0 * NdotL * NdotV);
+    // Obtain final intensity as reflectance (BRDF) scaled by the energy of the light (cosine law)
+    vec3 color = NdotL * (diffuseContrib + specContrib);
 
     return clamp(color, vec3(0), vec3(10));
 }
@@ -507,9 +507,9 @@ vec3 pbrBaseLight(vec3 diffuseColor, vec3 specularColor, float metallic, vec3 v,
     vec3 color = vec3(0);
 
     float NdotV = clamp(abs(dot(norm, v)), 0.001, 1.0);
-    
+
     color += pbrIbl(diffuseColor, specularColor, radiance, irradiance, ao, NdotV, perceptualRoughness);
-    
+
     color += pbrPunctual(diffuseColor, specularColor, perceptualRoughness, metallic, norm, v, normalize(light_dir)) * sunlit * 3.0 * scol; //magic number to balance with legacy materials
 
     color += colorEmissive;
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl
index 82d5d363d264a05dae48e36a8fc4a6a1db93368a..1751e1781425910ef30455ac8cdc3e624b1d8880 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskF.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file diffuseAlphaMaskF.glsl
  *
  * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2011, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -39,21 +39,21 @@ in vec2 vary_texcoord0;
 
 void mirrorClip(vec3 pos);
 
-void main() 
+void main()
 {
     mirrorClip(vary_position);
 
-	vec4 col = texture(diffuseMap, vary_texcoord0.xy) * vertex_color;
-	
-	if (col.a < minimum_alpha)
-	{
-		discard;
-	}
-
-	frag_data[0] = vec4(col.rgb, 0.0);
-	frag_data[1] = vec4(0,0,0,0); // spec
-	vec3 nvn = normalize(vary_normal);
-	frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
+    vec4 col = texture(diffuseMap, vary_texcoord0.xy) * vertex_color;
+
+    if (col.a < minimum_alpha)
+    {
+        discard;
+    }
+
+    frag_data[0] = vec4(col.rgb, 0.0);
+    frag_data[1] = vec4(0,0,0,0); // spec
+    vec3 nvn = normalize(vary_normal);
+    frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
     frag_data[3] = vec4(0);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl
index 788ea633fc46d3c61cdfa329afa1ecc021c8cf26..f5b517a8ea5893ceb1f199e71f3c28a8cb19e9d0 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskIndexedF.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file diffuseAlphaMaskIndexedF.glsl
  *
  * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2011, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -37,20 +37,20 @@ in vec2 vary_texcoord0;
 
 void mirrorClip(vec3 pos);
 
-void main() 
+void main()
 {
     mirrorClip(vary_position);
 
-	vec4 col = diffuseLookup(vary_texcoord0.xy) * vertex_color;
-	
-	if (col.a < minimum_alpha)
-	{
-		discard;
-	}
-	
-	frag_data[0] = vec4(col.rgb, 0.0);
-	frag_data[1] = vec4(0,0,0,0);
-	vec3 nvn = normalize(vary_normal);
-	frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
+    vec4 col = diffuseLookup(vary_texcoord0.xy) * vertex_color;
+
+    if (col.a < minimum_alpha)
+    {
+        discard;
+    }
+
+    frag_data[0] = vec4(col.rgb, 0.0);
+    frag_data[1] = vec4(0,0,0,0);
+    vec3 nvn = normalize(vary_normal);
+    frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
     frag_data[3] = vec4(0);
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl
index 22e6d6041919505570c22a68a36110a49bb534cb..89ea0c17104bcd176b7984c43a2c12f43c1ac2ce 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseAlphaMaskNoColorF.glsl
@@ -1,28 +1,28 @@
-/** 
+/**
  * @file diffuseAlphaMaskNoColorF.glsl
  *
  * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2005, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
 /*[EXTRA_CODE_HERE]*/
 
 out vec4 frag_data[4];
@@ -34,19 +34,19 @@ uniform sampler2D diffuseMap;
 in vec3 vary_normal;
 in vec2 vary_texcoord0;
 
-void main() 
+void main()
 {
-	vec4 col = texture(diffuseMap, vary_texcoord0.xy);
-	
-	if (col.a < minimum_alpha)
-	{
-		discard;
-	}
-
-	frag_data[0] = vec4(col.rgb, 0.0);
-	frag_data[1] = vec4(0,0,0,0); // spec
-	vec3 nvn = normalize(vary_normal);
-	frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
+    vec4 col = texture(diffuseMap, vary_texcoord0.xy);
+
+    if (col.a < minimum_alpha)
+    {
+        discard;
+    }
+
+    frag_data[0] = vec4(col.rgb, 0.0);
+    frag_data[1] = vec4(0,0,0,0); // spec
+    vec3 nvn = normalize(vary_normal);
+    frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
     frag_data[3] = vec4(0);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl
index 799fc62a420490958453b354c5c8797d99e0043f..7f056a51e824f8779479c20185f326bb18ccd184 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseF.glsl
@@ -1,30 +1,30 @@
-/** 
+/**
  * @file diffuseF.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
 
 /*[EXTRA_CODE_HERE]*/
- 
+
 out vec4 frag_data[4];
 
 uniform sampler2D diffuseMap;
@@ -36,15 +36,15 @@ in vec3 vary_position;
 
 void mirrorClip(vec3 pos);
 
-void main() 
+void main()
 {
     mirrorClip(vary_position);
-	vec3 col = vertex_color.rgb * texture(diffuseMap, vary_texcoord0.xy).rgb;
-	frag_data[0] = vec4(col, 0.0);
-	frag_data[1] = vertex_color.aaaa; // spec
-	//frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested
-	vec3 nvn = normalize(vary_normal);
-	frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
+    vec3 col = vertex_color.rgb * texture(diffuseMap, vary_texcoord0.xy).rgb;
+    frag_data[0] = vec4(col, 0.0);
+    frag_data[1] = vertex_color.aaaa; // spec
+    //frag_data[1] = vec4(vec3(vertex_color.a), vertex_color.a+(1.0-vertex_color.a)*vertex_color.a); // spec - from former class3 - maybe better, but not so well tested
+    vec3 nvn = normalize(vary_normal);
+    frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
     frag_data[3] = vec4(vertex_color.a, 0, 0, 0);
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl
index 3362a180c6e22a99da9fda7cd0bec990d1f70d2f..5c73878ba9abcbfbaa203c44b73c0cece91746dc 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseIndexedF.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file diffuseIndexedF.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -35,17 +35,17 @@ in vec3 vary_position;
 void mirrorClip(vec3 pos);
 vec3 linear_to_srgb(vec3 c);
 
-void main() 
+void main()
 {
     mirrorClip(vary_position);
-	vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb;
+    vec3 col = vertex_color.rgb * diffuseLookup(vary_texcoord0.xy).rgb;
 
-	vec3 spec;
-	spec.rgb = vec3(vertex_color.a);
+    vec3 spec;
+    spec.rgb = vec3(vertex_color.a);
 
-	frag_data[0] = vec4(col, 0.0);
-	frag_data[1] = vec4(spec, vertex_color.a); // spec
-	vec3 nvn = normalize(vary_normal);
-	frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
+    frag_data[0] = vec4(col, 0.0);
+    frag_data[1] = vec4(spec, vertex_color.a); // spec
+    vec3 nvn = normalize(vary_normal);
+    frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
     frag_data[3] = vec4(vertex_color.a, 0, 0, 0);
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl
index 64230dc680454728724816c5841b6c96a4ad326f..4bd31cef9e9e2012e23c4a597dc82c1e2058d180 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/diffuseV.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file diffuseV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -59,13 +59,13 @@ void main()
     vary_normal = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz);
 #else
     vary_position = (modelview_matrix * vec4(position.xyz, 1.0)).xyz;
-	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
     vary_normal = normalize(normal_matrix * normal);
 #endif
-	
-	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
-	
-	passTextureIndex();
 
-	vertex_color = diffuse_color;
+    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
+
+    passTextureIndex();
+
+    vertex_color = diffuse_color;
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl
index c64f65e32c4e807b3863152077ecf5fcd5639dc5..99cb23839a7f79e7a3e153439e8dab3558ea19bd 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/impostorF.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file impostorF.glsl
  *
  * $LicenseInfo:firstyear=2011&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -38,20 +38,20 @@ in vec2 vary_texcoord0;
 
 vec3 linear_to_srgb(vec3 c);
 
-void main() 
+void main()
 {
-	vec4 col = texture(diffuseMap, vary_texcoord0.xy);
+    vec4 col = texture(diffuseMap, vary_texcoord0.xy);
 
-	if (col.a < minimum_alpha)
-	{
-		discard;
-	}
+    if (col.a < minimum_alpha)
+    {
+        discard;
+    }
 
-	vec4 norm = texture(normalMap,   vary_texcoord0.xy);
-	vec4 spec = texture(specularMap, vary_texcoord0.xy);
+    vec4 norm = texture(normalMap,   vary_texcoord0.xy);
+    vec4 spec = texture(specularMap, vary_texcoord0.xy);
 
-	frag_data[0] = vec4(col.rgb, 0.0);
-	frag_data[1] = spec;
-	frag_data[2] = vec4(norm.xyz, GBUFFER_FLAG_HAS_ATMOS);
+    frag_data[0] = vec4(col.rgb, 0.0);
+    frag_data[1] = spec;
+    frag_data[2] = vec4(norm.xyz, GBUFFER_FLAG_HAS_ATMOS);
     frag_data[3] = vec4(0);
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl
index ddf878ae607d60ac59a9ce522fa26c5eed237f51..b6528dfcf8022c3f63e44185280bd640a5519f2e 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/materialV.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file materialV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -65,67 +65,67 @@ out vec3 vary_normal;
 in vec2 texcoord2;
 out vec2 vary_texcoord2;
 #endif
- 
+
 out vec4 vertex_color;
 out vec2 vary_texcoord0;
 
 void main()
 {
 #ifdef HAS_SKIN
-	mat4 mat = getObjectSkinnedTransform();
+    mat4 mat = getObjectSkinnedTransform();
 
-	mat = modelview_matrix * mat;
+    mat = modelview_matrix * mat;
 
-	vec3 pos = (mat*vec4(position.xyz,1.0)).xyz;
+    vec3 pos = (mat*vec4(position.xyz,1.0)).xyz;
 
-	vary_position = pos;
+    vary_position = pos;
 
-	gl_Position = projection_matrix*vec4(pos,1.0);
+    gl_Position = projection_matrix*vec4(pos,1.0);
 
 #else
-	//transform vertex
-	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+    //transform vertex
+    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 
 #endif
-	
-	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
-	
+
+    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
+
 #ifdef HAS_NORMAL_MAP
-	vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy;
+    vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy;
 #endif
 
 #ifdef HAS_SPECULAR_MAP
-	vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy;
+    vary_texcoord2 = (texture_matrix0 * vec4(texcoord2,0,1)).xy;
 #endif
 
 #ifdef HAS_SKIN
-	vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz);
+    vec3 n = normalize((mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz);
 #ifdef HAS_NORMAL_MAP
-	vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz);
+    vec3 t = normalize((mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz);
 
     vary_tangent = t;
     vary_sign = tangent.w;
     vary_normal = n;
 #else //HAS_NORMAL_MAP
-	vary_normal  = n;
+    vary_normal  = n;
 #endif //HAS_NORMAL_MAP
 #else //HAS_SKIN
-	vec3 n = normalize(normal_matrix * normal);
+    vec3 n = normalize(normal_matrix * normal);
 #ifdef HAS_NORMAL_MAP
-	vec3 t = normalize(normal_matrix * tangent.xyz);
+    vec3 t = normalize(normal_matrix * tangent.xyz);
 
     vary_tangent = t;
     vary_sign = tangent.w;
     vary_normal = n;
 #else //HAS_NORMAL_MAP
-	vary_normal = n;
+    vary_normal = n;
 #endif //HAS_NORMAL_MAP
 #endif //HAS_SKIN
-	
-	vertex_color = diffuse_color;
+
+    vertex_color = diffuse_color;
 
 #if !defined(HAS_SKIN)
-	vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
+    vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
 #endif
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl
index c1fb9f5d842a4dd4403595881725ff4613cd4a12..35b7602569399b9b879ffb564d0ce71cbb501b88 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrShadowAlphaMaskF.glsl
@@ -1,24 +1,24 @@
-/**
+/** 
  * @file pbrShadowAlphaMaskF.glsl
  *
  * $LicenseInfo:firstyear=2023&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2023, Linden Research, Inc.
- *
+ * 
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- *
+ * 
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- *
+ * 
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- *
+ * 
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -33,9 +33,9 @@ in vec4 vertex_color;
 in vec2 vary_texcoord0;
 uniform float minimum_alpha;
 
-void main()
+void main() 
 {
-    float alpha = texture(diffuseMap,vary_texcoord0.xy).a;
+    float alpha = texture(diffuseMap,vary_texcoord0.xy).a * vertex_color.a;
 
     if (alpha < minimum_alpha)
     {
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
index 1d5f810cf3a61b31a6b6914acd51857d86a5edd3..380d49363692135e96dd66c7839c0d0a691cae65 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueF.glsl
@@ -69,12 +69,16 @@ void main()
     mirrorClip(vary_position);
 
     vec4 basecolor = texture(diffuseMap, base_color_texcoord.xy).rgba;
+    basecolor.rgb = srgb_to_linear(basecolor.rgb);
+
+    basecolor *= vertex_color;
+
     if (basecolor.a < minimum_alpha)
     {
         discard;
     }
 
-    vec3 col = vertex_color.rgb * srgb_to_linear(basecolor.rgb);
+    vec3 col = basecolor.rgb;
 
     // from mikktspace.com
     vec3 vNt = texture(bumpMap, normal_texcoord.xy).xyz*2.0-1.0;
@@ -108,7 +112,7 @@ void main()
     //emissive = tnorm*0.5+0.5;
     // See: C++: addDeferredAttachments(), GLSL: softenLightF
     frag_data[0] = max(vec4(col, 0.0), vec4(0));                                                   // Diffuse
-    frag_data[1] = max(vec4(spec.rgb,vertex_color.a), vec4(0));                                    // PBR linear packed Occlusion, Roughness, Metal.
+    frag_data[1] = max(vec4(spec.rgb,0.0), vec4(0));                                    // PBR linear packed Occlusion, Roughness, Metal.
     frag_data[2] = vec4(tnorm, GBUFFER_FLAG_HAS_PBR); // normal, environment intensity, flags
     frag_data[3] = max(vec4(emissive,0), vec4(0));                                                // PBR sRGB Emissive
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
index 5e0141910b16d84d5fd07a5aba8aa3740a2ad4e3..fd020afd577acd63cb364a8913ce4a651447aa4b 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbropaqueV.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file pbropaqueV.glsl
  *
  * $LicenseInfo:firstyear=2022&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2022, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -54,7 +54,7 @@ out vec2 base_color_texcoord;
 out vec2 normal_texcoord;
 out vec2 metallic_roughness_texcoord;
 out vec2 emissive_texcoord;
- 
+
 out vec4 vertex_color;
 
 out vec3 vary_tangent;
@@ -68,18 +68,18 @@ vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] kh
 void main()
 {
 #ifdef HAS_SKIN
-	mat4 mat = getObjectSkinnedTransform();
+    mat4 mat = getObjectSkinnedTransform();
 
-	mat = modelview_matrix * mat;
+    mat = modelview_matrix * mat;
 
-	vec3 pos = (mat*vec4(position.xyz,1.0)).xyz;
+    vec3 pos = (mat*vec4(position.xyz,1.0)).xyz;
     vary_position = pos;
-	gl_Position = projection_matrix*vec4(pos,1.0);
+    gl_Position = projection_matrix*vec4(pos,1.0);
 
 #else
     vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
-	//transform vertex
-	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+    //transform vertex
+    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 #endif
 
     base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0);
@@ -88,11 +88,11 @@ void main()
     emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0);
 
 #ifdef HAS_SKIN
-	vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz;
-	vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz;
+    vec3 n = (mat*vec4(normal.xyz+position.xyz,1.0)).xyz-pos.xyz;
+    vec3 t = (mat*vec4(tangent.xyz+position.xyz,1.0)).xyz-pos.xyz;
 #else //HAS_SKIN
-	vec3 n = normal_matrix * normal;
-	vec3 t = normal_matrix * tangent.xyz;
+    vec3 n = normal_matrix * normal;
+    vec3 t = normal_matrix * tangent.xyz;
 #endif
 
     n = normalize(n);
@@ -100,11 +100,11 @@ void main()
     vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_normal_transform, texture_matrix0));
     vary_sign = tangent.w;
     vary_normal = n;
-	
-	vertex_color = diffuse_color;
+
+    vertex_color = diffuse_color;
 }
 
-#else 
+#else
 
 // fullbright HUD implementation
 
@@ -121,7 +121,7 @@ in vec2 texcoord0;
 
 out vec2 base_color_texcoord;
 out vec2 emissive_texcoord;
- 
+
 out vec4 vertex_color;
 
 vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
@@ -129,7 +129,7 @@ vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl
 void main()
 {
     //transform vertex
-    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
 
     base_color_texcoord = texture_transform(texcoord0, texture_base_color_transform, texture_matrix0);
     emissive_texcoord = texture_transform(texcoord0, texture_emissive_transform, texture_matrix0);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
index 489fc26e3f52084d4fdbb4e6e06674a2fa256a7d..ed5229731468c91aae6663f8d86abf201ff65859 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/pbrterrainV.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file class1\environment\pbrterrainV.glsl
  *
  * $LicenseInfo:firstyear=2023&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2023, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -50,18 +50,18 @@ out vec3 vary_position;
 // tangent_space_transform below.
 uniform vec4[2] texture_base_color_transform;
 
-vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
-vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform, mat4 sl_animation_transform);
+vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform);
+vec3 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform);
 
 void main()
 {
     //transform vertex
-	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
     vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
 
-	vec3 n = normal_matrix * normal;
+    vec3 n = normal_matrix * normal;
     vary_vertex_normal = normal;
-	vec3 t = normal_matrix * tangent.xyz;
+    vec3 t = normal_matrix * tangent.xyz;
 
     vary_tangent = normalize(t);
     // *TODO: Decide if we want this. It may be better to just calculate the
@@ -70,7 +70,7 @@ void main()
     // *HACK: Should be using texture_normal_transform here. The KHR texture
     // transform spec requires handling texture transforms separately for each
     // individual texture.
-    vary_tangent = normalize(tangent_space_transform(vec4(t, tangent.w), n, texture_base_color_transform, texture_matrix0));
+    vary_tangent = normalize(terrain_tangent_space_transform(vec4(t, tangent.w), n, texture_base_color_transform));
     vary_sign = tangent.w;
     vary_normal = normalize(n);
 
@@ -80,15 +80,15 @@ void main()
     // separately for each individual texture.
 #if TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 3
     // xy
-    vary_coords[0].xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0);
+    vary_coords[0].xy = terrain_texture_transform(position.xy, texture_base_color_transform);
     // yz
-    vary_coords[0].zw = texture_transform(position.yz, texture_base_color_transform, texture_matrix0);
+    vary_coords[0].zw = terrain_texture_transform(position.yz, texture_base_color_transform);
     // (-x)z
-    vary_coords[1].xy = texture_transform(position.xz * vec2(-1, 1), texture_base_color_transform, texture_matrix0);
+    vary_coords[1].xy = terrain_texture_transform(position.xz * vec2(-1, 1), texture_base_color_transform);
 #elif TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT == 1
-    vary_texcoord0.xy = texture_transform(position.xy, texture_base_color_transform, texture_matrix0);
+    vary_texcoord0.xy = terrain_texture_transform(position.xy, texture_base_color_transform);
 #endif
-    
+
     vec4 tc = vec4(texcoord1,0,1);
     vary_texcoord0.zw = tc.xy;
     vary_texcoord1.xy = tc.xy-vec2(2.0, 0.0);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
index 1629ed91c8a25969d86f9bc5bdcbee61963e1947..a0eb6cfbb8c18bc942e4d2eb01fe18662451014d 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/postDeferredGammaCorrect.glsl
@@ -1,28 +1,28 @@
-/** 
+/**
  * @file postDeferredGammaCorrect.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
 /*[EXTRA_CODE_HERE]*/
 
 out vec4 frag_color;
@@ -79,7 +79,7 @@ vec3 RRTAndODTFit(vec3 color)
 }
 
 
-// tone mapping 
+// tone mapping
 vec3 toneMapACES_Hill(vec3 color)
 {
     color = ACESInputMat * color;
@@ -103,7 +103,7 @@ vec3 toneMap(vec3 color)
 {
 #ifndef NO_POST
     float exp_scale = texture(exposureMap, vec2(0.5,0.5)).r;
-    
+
     color *= exposure * exp_scale;
 
     // mix ACES and Linear here as a compromise to avoid over-darkening legacy content
@@ -117,38 +117,38 @@ vec3 toneMap(vec3 color)
 
 //=================================
 // borrowed noise from:
-//	<https://www.shadertoy.com/view/4dS3Wd>
-//	By Morgan McGuire @morgan3d, http://graphicscodex.com
+//  <https://www.shadertoy.com/view/4dS3Wd>
+//  By Morgan McGuire @morgan3d, http://graphicscodex.com
 //
 float hash(float n) { return fract(sin(n) * 1e4); }
 float hash(vec2 p) { return fract(1e4 * sin(17.0 * p.x + p.y * 0.1) * (0.1 + abs(sin(p.y * 13.0 + p.x)))); }
 
 float noise(float x) {
-	float i = floor(x);
-	float f = fract(x);
-	float u = f * f * (3.0 - 2.0 * f);
-	return mix(hash(i), hash(i + 1.0), u);
+    float i = floor(x);
+    float f = fract(x);
+    float u = f * f * (3.0 - 2.0 * f);
+    return mix(hash(i), hash(i + 1.0), u);
 }
 
 float noise(vec2 x) {
-	vec2 i = floor(x);
-	vec2 f = fract(x);
-
-	// Four corners in 2D of a tile
-	float a = hash(i);
-	float b = hash(i + vec2(1.0, 0.0));
-	float c = hash(i + vec2(0.0, 1.0));
-	float d = hash(i + vec2(1.0, 1.0));
-
-	// Simple 2D lerp using smoothstep envelope between the values.
-	// return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)),
-	//			mix(c, d, smoothstep(0.0, 1.0, f.x)),
-	//			smoothstep(0.0, 1.0, f.y)));
-
-	// Same code, with the clamps in smoothstep and common subexpressions
-	// optimized away.
-	vec2 u = f * f * (3.0 - 2.0 * f);
-	return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
+    vec2 i = floor(x);
+    vec2 f = fract(x);
+
+    // Four corners in 2D of a tile
+    float a = hash(i);
+    float b = hash(i + vec2(1.0, 0.0));
+    float c = hash(i + vec2(0.0, 1.0));
+    float d = hash(i + vec2(1.0, 1.0));
+
+    // Simple 2D lerp using smoothstep envelope between the values.
+    // return vec3(mix(mix(a, b, smoothstep(0.0, 1.0, f.x)),
+    //          mix(c, d, smoothstep(0.0, 1.0, f.x)),
+    //          smoothstep(0.0, 1.0, f.y)));
+
+    // Same code, with the clamps in smoothstep and common subexpressions
+    // optimized away.
+    vec2 u = f * f * (3.0 - 2.0 * f);
+    return mix(a, b, u.x) + (c - a) * u.y * (1.0 - u.x) + (d - b) * u.x * u.y;
 }
 
 //=============================
@@ -171,7 +171,7 @@ vec3 legacyGamma(vec3 color)
     return c;
 }
 
-void main() 
+void main()
 {
     //this is the one of the rare spots where diffuseRect contains linear color values (not sRGB)
     vec4 diff = texture(diffuseRect, vary_fragcoord);
diff --git a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
index 732333311cc6e611194a1a8c1239e3eb82954562..7c02cb9d4aaddb4c9e9aa9b08d7372841ae6ddf2 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/textureUtilV.glsl
@@ -77,6 +77,19 @@ vec2 texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform, mat4 sl
     return texcoord;
 }
 
+// Similar to texture_transform but no offset during coordinate system
+// conversion, and no texture animation support.
+vec2 terrain_texture_transform(vec2 vertex_texcoord, vec4[2] khr_gltf_transform)
+{
+    vec2 texcoord = vertex_texcoord;
+
+    texcoord.y = -texcoord.y;
+    texcoord = khr_texture_transform(texcoord, khr_gltf_transform[0].xy, khr_gltf_transform[0].z, khr_gltf_transform[1].xy);
+    texcoord.y = -texcoord.y;
+
+    return texcoord;
+}
+
 // Take the rotation only from both transforms and apply to the tangent. This
 // accounts for the change of the topology of the normal texture when a texture
 // rotation is applied to it.
@@ -120,3 +133,25 @@ vec3 tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] kh
 
     return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz);
 }
+
+// Similar to tangent_space_transform but no no texture animation support.
+vec3 terrain_tangent_space_transform(vec4 vertex_tangent, vec3 vertex_normal, vec4[2] khr_gltf_transform)
+{
+    // Immediately convert to left-handed coordinate system ((0,1) -> (0, -1))
+    vec2 weights = vec2(0, -1);
+
+    // Apply KHR_texture_transform (rotation only)
+    float khr_rotation = khr_gltf_transform[0].z;
+    mat2 khr_rotation_mat = mat2(
+        cos(khr_rotation),-sin(khr_rotation),
+        sin(khr_rotation), cos(khr_rotation)
+    );
+    weights = khr_rotation_mat * weights;
+
+    // Convert back to right-handed coordinate system
+    weights.y = -weights.y;
+
+    vec3 vertex_binormal = vertex_tangent.w * cross(vertex_normal, vertex_tangent.xyz);
+
+    return (weights.x * vertex_binormal.xyz) + (weights.y * vertex_tangent.xyz);
+}
diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl
index 708acd0194a17cb0795d9cdb627d353c20b9880a..05922ecb1afca1e52a8c3d588ca7d8b85bc8cb80 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/treeF.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file treeF.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -37,18 +37,18 @@ in vec3 vary_position;
 uniform float minimum_alpha;
 
 void mirrorClip(vec3 pos);
-void main() 
+void main()
 {
     mirrorClip(vary_position);
-	vec4 col = texture(diffuseMap, vary_texcoord0.xy);
-	if (col.a < minimum_alpha)
-	{
-		discard;
-	}
+    vec4 col = texture(diffuseMap, vary_texcoord0.xy);
+    if (col.a < minimum_alpha)
+    {
+        discard;
+    }
 
-	frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0);
-	frag_data[1] = vec4(0,0,0,0);
-	vec3 nvn = normalize(vary_normal);
-	frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
+    frag_data[0] = vec4(vertex_color.rgb*col.rgb, 0.0);
+    frag_data[1] = vec4(0,0,0,0);
+    vec3 nvn = normalize(vary_normal);
+    frag_data[2] = vec4(nvn.xyz, GBUFFER_FLAG_HAS_ATMOS);
     frag_data[3] = vec4(0);
 }
diff --git a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl
index c84fccd4c61cdc75b8f004cacfbd8216d64c9a35..ef5602f1e56fa1c923958ac1268ea5f2ff496225 100644
--- a/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl
+++ b/indra/newview/app_settings/shaders/class1/deferred/treeV.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file treeV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -39,13 +39,13 @@ out vec3 vary_position;
 
 void main()
 {
-	//transform vertex
-	gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0); 
+    //transform vertex
+    gl_Position = modelview_projection_matrix * vec4(position.xyz, 1.0);
     vary_position = (modelview_matrix*vec4(position.xyz, 1.0)).xyz;
 
-	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
-	
-	vary_normal = normalize(normal_matrix * normal);
+    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
+
+    vary_normal = normalize(normal_matrix * normal);
 
-	vertex_color = vec4(1,1,1,1);
+    vertex_color = vec4(1,1,1,1);
 }
diff --git a/indra/newview/app_settings/shaders/class1/interface/normaldebugF.glsl b/indra/newview/app_settings/shaders/class1/interface/normaldebugF.glsl
index 388042e7e0944bed8c21d9e300ba91d2d210619a..2bfd45f3b0f8cae864ebad7a2c74283587f0efdc 100644
--- a/indra/newview/app_settings/shaders/class1/interface/normaldebugF.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/normaldebugF.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file normaldebugF.glsl
  *
  * $LicenseInfo:firstyear=2023&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2023, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -27,7 +27,7 @@ out vec4 frag_color;
 
 in vec4 vertex_color;
 
-void main() 
+void main()
 {
-	frag_color = max(vertex_color, vec4(0));
+    frag_color = max(vertex_color, vec4(0));
 }
diff --git a/indra/newview/app_settings/shaders/class1/interface/normaldebugV.glsl b/indra/newview/app_settings/shaders/class1/interface/normaldebugV.glsl
index b198bc248547e0a8e2709eeb643f81f7dbb66732..ae726190c729929e7d35d1e9a06437d9be272e8f 100644
--- a/indra/newview/app_settings/shaders/class1/interface/normaldebugV.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/normaldebugV.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file normaldebugV.glsl
  *
  * $LicenseInfo:firstyear=2023&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2023, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -65,10 +65,10 @@ void main()
 
     vec4 world_pos = mat * vec4(position.xyz,1.0);
 
-	gl_Position = projection_matrix * world_pos;
-	normal_g = get_screen_normal(position.xyz, world_pos, normal.xyz, mat);
+    gl_Position = projection_matrix * world_pos;
+    normal_g = get_screen_normal(position.xyz, world_pos, normal.xyz, mat);
 #ifdef HAS_ATTRIBUTE_TANGENT
-	tangent_g = get_screen_normal(position.xyz, world_pos, tangent.xyz, mat);
+    tangent_g = get_screen_normal(position.xyz, world_pos, tangent.xyz, mat);
 #endif
 }
 
diff --git a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl
index c1ed1bfe6e9ec1577e96a7dc14b3547494af5ab6..feb0947649b35d0a1f2c89b5670553da77588779 100644
--- a/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl
+++ b/indra/newview/app_settings/shaders/class1/interface/radianceGenF.glsl
@@ -1,28 +1,28 @@
-/** 
+/**
  * @file radianceGenF.glsl
  *
  * $LicenseInfo:firstyear=2022&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2022, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
 
 /*[EXTRA_CODE_HERE]*/
 
@@ -36,7 +36,7 @@ in vec3 vary_dir;
 //uniform float roughness;
 
 uniform float mipLevel;
-uniform int u_width; 
+uniform int u_width;
 uniform float max_probe_lod;
 uniform float probe_strength;
 
@@ -74,96 +74,96 @@ const float PI = 3.1415926536;
 // Based omn http://byteblacksmith.com/improvements-to-the-canonical-one-liner-glsl-rand-for-opengl-es-2-0/
 float random(vec2 co)
 {
-	float a = 12.9898;
-	float b = 78.233;
-	float c = 43758.5453;
-	float dt= dot(co.xy ,vec2(a,b));
-	float sn= mod(dt,3.14);
-	return fract(sin(sn) * c);
+    float a = 12.9898;
+    float b = 78.233;
+    float c = 43758.5453;
+    float dt= dot(co.xy ,vec2(a,b));
+    float sn= mod(dt,3.14);
+    return fract(sin(sn) * c);
 }
 
-vec2 hammersley2d(uint i, uint N) 
+vec2 hammersley2d(uint i, uint N)
 {
-	// Radical inverse based on http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
-	uint bits = (i << 16u) | (i >> 16u);
-	bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
-	bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
-	bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
-	bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
-	float rdi = float(bits) * 2.3283064365386963e-10;
-	return vec2(float(i) /float(N), rdi);
+    // Radical inverse based on http://holger.dammertz.org/stuff/notes_HammersleyOnHemisphere.html
+    uint bits = (i << 16u) | (i >> 16u);
+    bits = ((bits & 0x55555555u) << 1u) | ((bits & 0xAAAAAAAAu) >> 1u);
+    bits = ((bits & 0x33333333u) << 2u) | ((bits & 0xCCCCCCCCu) >> 2u);
+    bits = ((bits & 0x0F0F0F0Fu) << 4u) | ((bits & 0xF0F0F0F0u) >> 4u);
+    bits = ((bits & 0x00FF00FFu) << 8u) | ((bits & 0xFF00FF00u) >> 8u);
+    float rdi = float(bits) * 2.3283064365386963e-10;
+    return vec2(float(i) /float(N), rdi);
 }
 
 // Based on http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_slides.pdf
-vec3 importanceSample_GGX(vec2 Xi, float roughness, vec3 normal) 
+vec3 importanceSample_GGX(vec2 Xi, float roughness, vec3 normal)
 {
-	// Maps a 2D point to a hemisphere with spread based on roughness
-	float alpha = roughness * roughness;
-	float phi = 2.0 * PI * Xi.x + random(normal.xz) * 0.1;
-	float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (alpha*alpha - 1.0) * Xi.y));
-	float sinTheta = sqrt(1.0 - cosTheta * cosTheta);
-	vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);
-
-	// Tangent space
-	vec3 up = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
-	vec3 tangentX = normalize(cross(up, normal));
-	vec3 tangentY = normalize(cross(normal, tangentX));
-
-	// Convert to world Space
-	return normalize(tangentX * H.x + tangentY * H.y + normal * H.z);
+    // Maps a 2D point to a hemisphere with spread based on roughness
+    float alpha = roughness * roughness;
+    float phi = 2.0 * PI * Xi.x + random(normal.xz) * 0.1;
+    float cosTheta = sqrt((1.0 - Xi.y) / (1.0 + (alpha*alpha - 1.0) * Xi.y));
+    float sinTheta = sqrt(1.0 - cosTheta * cosTheta);
+    vec3 H = vec3(sinTheta * cos(phi), sinTheta * sin(phi), cosTheta);
+
+    // Tangent space
+    vec3 up = abs(normal.z) < 0.999 ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
+    vec3 tangentX = normalize(cross(up, normal));
+    vec3 tangentY = normalize(cross(normal, tangentX));
+
+    // Convert to world Space
+    return normalize(tangentX * H.x + tangentY * H.y + normal * H.z);
 }
 
 // Normal Distribution function
 float D_GGX(float dotNH, float roughness)
 {
-	float alpha = roughness * roughness;
-	float alpha2 = alpha * alpha;
-	float denom = dotNH * dotNH * (alpha2 - 1.0) + 1.0;
-	return (alpha2)/(PI * denom*denom); 
+    float alpha = roughness * roughness;
+    float alpha2 = alpha * alpha;
+    float denom = dotNH * dotNH * (alpha2 - 1.0) + 1.0;
+    return (alpha2)/(PI * denom*denom);
 }
 
 vec4 prefilterEnvMap(vec3 R)
 {
-	vec3 N = R;
-	vec3 V = R;
-	vec4 color = vec4(0.0);
-	float totalWeight = 0.0;
-	float envMapDim = float(textureSize(reflectionProbes, 0).s);
+    vec3 N = R;
+    vec3 V = R;
+    vec4 color = vec4(0.0);
+    float totalWeight = 0.0;
+    float envMapDim = float(textureSize(reflectionProbes, 0).s);
     float roughness = mipLevel/max_probe_lod;
     int numSamples = max(int(PROBE_FILTER_SAMPLES*roughness), 1);
 
     float numMips = max_probe_lod+1;
 
-	for(uint i = 0u; i < numSamples; i++) {
-		vec2 Xi = hammersley2d(i, numSamples);
-		vec3 H = importanceSample_GGX(Xi, roughness, N);
-		vec3 L = 2.0 * dot(V, H) * H - V;
-		float dotNL = clamp(dot(N, L), 0.0, 1.0);
-		if(dotNL > 0.0) {
-			// Filtering based on https://placeholderart.wordpress.com/2015/07/28/implementation-notes-runtime-environment-map-filtering-for-image-based-lighting/
-
-			float dotNH = clamp(dot(N, H), 0.0, 1.0);
-			float dotVH = clamp(dot(V, H), 0.0, 1.0);
-
-			// Probability Distribution Function
-			float pdf = D_GGX(dotNH, roughness) * dotNH / (4.0 * dotVH) + 0.0001;
-			// Slid angle of current smple
-			float omegaS = 1.0 / (float(numSamples) * pdf);
-			// Solid angle of 1 pixel across all cube faces
-			float omegaP = 4.0 * PI / (6.0 * envMapDim * envMapDim);
-			// Biased (+1.0) mip level for better result
-			float mipLevel = roughness == 0.0 ? 0.0 : clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, max_probe_lod);
-			color += textureLod(reflectionProbes, vec4(L, sourceIdx), mipLevel) * dotNL;
-			totalWeight += dotNL;
-		}
-	}
-	return (color / totalWeight);
+    for(uint i = 0u; i < numSamples; i++) {
+        vec2 Xi = hammersley2d(i, numSamples);
+        vec3 H = importanceSample_GGX(Xi, roughness, N);
+        vec3 L = 2.0 * dot(V, H) * H - V;
+        float dotNL = clamp(dot(N, L), 0.0, 1.0);
+        if(dotNL > 0.0) {
+            // Filtering based on https://placeholderart.wordpress.com/2015/07/28/implementation-notes-runtime-environment-map-filtering-for-image-based-lighting/
+
+            float dotNH = clamp(dot(N, H), 0.0, 1.0);
+            float dotVH = clamp(dot(V, H), 0.0, 1.0);
+
+            // Probability Distribution Function
+            float pdf = D_GGX(dotNH, roughness) * dotNH / (4.0 * dotVH) + 0.0001;
+            // Slid angle of current smple
+            float omegaS = 1.0 / (float(numSamples) * pdf);
+            // Solid angle of 1 pixel across all cube faces
+            float omegaP = 4.0 * PI / (6.0 * envMapDim * envMapDim);
+            // Biased (+1.0) mip level for better result
+            float mipLevel = roughness == 0.0 ? 0.0 : clamp(0.5 * log2(omegaS / omegaP) + 1.0, 0.0f, max_probe_lod);
+            color += textureLod(reflectionProbes, vec4(L, sourceIdx), mipLevel) * dotNL;
+            totalWeight += dotNL;
+        }
+    }
+    return (color / totalWeight);
 }
 
 void main()
-{		
-	vec3 N = normalize(vary_dir);
-	frag_color = max(prefilterEnvMap(N), vec4(0));
+{
+    vec3 N = normalize(vary_dir);
+    frag_color = max(prefilterEnvMap(N), vec4(0));
     frag_color.a *= probe_strength;
 }
 // =============================================================================================================
diff --git a/indra/newview/app_settings/shaders/class1/objects/bumpF.glsl b/indra/newview/app_settings/shaders/class1/objects/bumpF.glsl
index 142f2a5d71fcc5bf70f612aaab34da405daf4d2e..09a505d69d2276ecb3b162af67ebb79a90c44dba 100644
--- a/indra/newview/app_settings/shaders/class1/objects/bumpF.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/bumpF.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file bumpF.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -34,11 +34,11 @@ in vec3 vary_position;
 
 void mirrorClip(vec3 pos);
 
-void main() 
+void main()
 {
     mirrorClip(vary_position);
-	float tex0 = texture(texture0, vary_texcoord0.xy).a;
-	float tex1 = texture(texture1, vary_texcoord1.xy).a;
+    float tex0 = texture(texture0, vary_texcoord0.xy).a;
+    float tex1 = texture(texture1, vary_texcoord1.xy).a;
 
-	frag_color = max(vec4(tex0+(1.0-tex1)-0.5), vec4(0));
+    frag_color = max(vec4(tex0+(1.0-tex1)-0.5), vec4(0));
 }
diff --git a/indra/newview/app_settings/shaders/class1/objects/bumpV.glsl b/indra/newview/app_settings/shaders/class1/objects/bumpV.glsl
index b8a02fbdec418e36fbbb6e9bbc9d33c15d8ac13d..95cdfb6faec7cbd511cd3c3ae474b555095c8d11 100644
--- a/indra/newview/app_settings/shaders/class1/objects/bumpV.glsl
+++ b/indra/newview/app_settings/shaders/class1/objects/bumpV.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file bumpV.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -42,7 +42,7 @@ uniform mat4 projection_matrix;
 
 void main()
 {
-	//transform vertex
+    //transform vertex
 #ifdef HAS_SKIN
     mat4 mat = getObjectSkinnedTransform();
     mat = modelview_matrix * mat;
@@ -51,8 +51,8 @@ void main()
     gl_Position = projection_matrix * pos;
 #else
     vary_position = (modelview_matrix * vec4(position.xyz, 1.0)).xyz;
-	gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
+    gl_Position = modelview_projection_matrix*vec4(position.xyz, 1.0);
 #endif
-	vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
-	vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy;
+    vary_texcoord0 = (texture_matrix0 * vec4(texcoord0,0,1)).xy;
+    vary_texcoord1 = (texture_matrix0 * vec4(texcoord1,0,1)).xy;
 }
diff --git a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl
index 40b7f9cf0ebdf6d8f6e72e6464101bc5bd846498..d077670c96379b367150b7d3ba34736fb2dbf56c 100644
--- a/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl
+++ b/indra/newview/app_settings/shaders/class1/windlight/atmosphericsFuncs.glsl
@@ -98,7 +98,7 @@ void calcAtmosphericVars(vec3 inPositionEye, vec3 light_dir, float ambFactor, ou
     haze_glow = max(haze_glow, .001);  // set a minimum "angle" (smaller glow.y allows tighter, brighter hotspot)
     haze_glow *= glow.x;
     // higher glow.x gives dimmer glow (because next step is 1 / "angle")
-    haze_glow = clamp(pow(haze_glow, glow.z), -10, 10);
+    haze_glow = clamp(pow(haze_glow, glow.z), -100000, 100000);
     // glow.z should be negative, so we're doing a sort of (1 / "angle") function
 
     // add "minimum anti-solar illumination"
diff --git a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl
index 12ae17ae1f545eb6bd35d826e5eea748e6cc7028..b248d6ad41767356a464485a13c3c8a858f75e21 100644
--- a/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl
+++ b/indra/newview/app_settings/shaders/class2/deferred/alphaF.glsl
@@ -1,24 +1,24 @@
-/** 
+/**
  * @file alphaF.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -60,7 +60,7 @@ uniform vec2 screen_res;
 uniform int sun_up_factor;
 uniform vec4 light_position[8];
 uniform vec3 light_direction[8];
-uniform vec4 light_attenuation[8]; 
+uniform vec4 light_attenuation[8];
 uniform vec3 light_diffuse[8];
 
 void waterClip(vec3 pos);
@@ -91,15 +91,15 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec
     float falloff_factor = (12.0 * fa) - 9.0;
     float inverted_la = falloff_factor / la;
     // Yes, it makes me want to cry as well. DJH
-    
+
     vec3 col = vec3(0);
 
-	//get light vector
-	vec3 lv = lp.xyz-v;
+    //get light vector
+    vec3 lv = lp.xyz-v;
 
-	//get distance
-	float dist = length(lv);
-	float da = 1.0;
+    //get distance
+    float dist = length(lv);
+    float da = 1.0;
 
     /*if (dist > inverted_la)
     {
@@ -112,23 +112,23 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec
     if (proj_tc.z < 0
      || proj_tc.z > 1
      || proj_tc.x < 0
-     || proj_tc.x > 1 
+     || proj_tc.x > 1
      || proj_tc.y < 0
      || proj_tc.y > 1)
     {
         return col;
     }*/
 
-	if (dist > 0.0 && inverted_la > 0.0)
-	{
+    if (dist > 0.0 && inverted_la > 0.0)
+    {
         dist /= inverted_la;
 
-		//normalize light vector
-		lv = normalize(lv);
-	
-		//distance attenuation
-		float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);
-		dist_atten *= dist_atten;
+        //normalize light vector
+        lv = normalize(lv);
+
+        //distance attenuation
+        float dist_atten = clamp(1.0-(dist-1.0*(1.0-fa))/fa, 0.0, 1.0);
+        dist_atten *= dist_atten;
         dist_atten *= 2.0f;
 
         if (dist_atten <= 0.0)
@@ -136,20 +136,20 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec
            return col;
         }
 
-		// spotlight coefficient.
-		float spot = max(dot(-ln, lv), is_pointlight);
-		da *= spot*spot; // GL_SPOT_EXPONENT=2
+        // spotlight coefficient.
+        float spot = max(dot(-ln, lv), is_pointlight);
+        da *= spot*spot; // GL_SPOT_EXPONENT=2
 
-		//angular attenuation
-		da *= dot(n, lv);
+        //angular attenuation
+        da *= dot(n, lv);
         da = max(0.0, da);
 
-		float lit = 0.0f;
+        float lit = 0.0f;
 
         float amb_da = 0.0;//ambiance;
         if (da > 0)
         {
-		    lit = max(da * dist_atten,0.0);
+            lit = max(da * dist_atten,0.0);
             col = lit * light_col * diffuse;
             amb_da += (da*0.5+0.5) * ambiance;
         }
@@ -166,12 +166,12 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 diffuse, vec3 v, vec3 n, vec
     return col;
 }
 
-void main() 
+void main()
 {
     mirrorClip(vary_position);
 
     vec2 frag = vary_fragcoord.xy/vary_fragcoord.z*0.5+0.5;
-    
+
     vec4 pos = vec4(vary_position, 1.0);
 #ifndef IS_AVATAR_SKIN
     // clip against water plane unless this is a legacy avatar skin
@@ -202,7 +202,7 @@ void main()
 
     float final_alpha = diffuse_srgb.a * vertex_color.a;
     diffuse_srgb.rgb *= vertex_color.rgb;
-    
+
     // Insure we don't pollute depth with invis pixels in impostor rendering
     //
     if (final_alpha < minimum_alpha)
@@ -225,7 +225,7 @@ void main()
     final_alpha *= vertex_color.a;
 
     if (final_alpha < minimum_alpha)
-    { // TODO: figure out how to get invisible faces out of 
+    { // TODO: figure out how to get invisible faces out of
         // render batches without breaking glow
         discard;
     }
@@ -248,7 +248,7 @@ void main()
     vec3 glossenv;
     vec3 legacyenv;
     sampleReflectionProbesLegacy(irradiance, glossenv, legacyenv, frag, pos.xyz, norm.xyz, 0.0, 0.0, true, amblit_linear);
-    
+
 
     float final_da = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0);
 
@@ -265,7 +265,7 @@ void main()
     color.rgb *= diffuse_linear.rgb;
 
     vec4 light = vec4(0,0,0,0);
-    
+
    #define LIGHT_LOOP(i) light.rgb += calcPointLightOrSpotLight(light_diffuse[i].rgb, diffuse_linear.rgb, pos.xyz, norm, light_position[i], light_direction[i].xyz, light_attenuation[i].x, light_attenuation[i].y, light_attenuation[i].z, light_attenuation[i].w);
 
     LIGHT_LOOP(1)
diff --git a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl
index c382a9fbc000b9adfaeec38dac1c79812a1f8881..03dc3d711376b53120805b9c6e0c8aeecc8b9c4b 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/fullbrightShinyF.glsl
@@ -1,28 +1,28 @@
-/** 
+/**
  * @file fullbrightShinyF.glsl
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
 /*[EXTRA_CODE_HERE]*/
 
 out vec4 frag_color;
@@ -59,16 +59,16 @@ void main()
 {
     mirrorClip(vary_position);
 #ifdef HAS_DIFFUSE_LOOKUP
-	vec4 color = diffuseLookup(vary_texcoord0.xy);
+    vec4 color = diffuseLookup(vary_texcoord0.xy);
 #else
-	vec4 color = texture(diffuseMap, vary_texcoord0.xy);
+    vec4 color = texture(diffuseMap, vary_texcoord0.xy);
 #endif
-	
-	color.rgb *= vertex_color.rgb;
 
-	// SL-9632 HUDs are affected by Atmosphere
+    color.rgb *= vertex_color.rgb;
+
+    // SL-9632 HUDs are affected by Atmosphere
 #ifndef IS_HUD
-	
+
     vec3 sunlit;
     vec3 amblit;
     vec3 additive;
@@ -90,8 +90,8 @@ void main()
     applyLegacyEnv(color.rgb, legacyenv, spec, pos, norm, env_intensity);
 #endif
 
-	color.a = 1.0;
+    color.a = 1.0;
 
-	frag_color = max(color, vec4(0));
+    frag_color = max(color, vec4(0));
 }
 
diff --git a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
index 5986913263c6b572fd9310d1805fd33caf9c6dd2..2d015bb372b403d5eaf301b22603cef4d969cba7 100644
--- a/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
+++ b/indra/newview/app_settings/shaders/class3/deferred/materialF.glsl
@@ -100,7 +100,7 @@ vec3 calcPointLightOrSpotLight(vec3 light_col, vec3 npos, vec3 diffuse, vec4 spe
     float falloff_factor = (12.0 * fa) - 9.0;
     float inverted_la = falloff_factor / la;
     // Yes, it makes me want to cry as well. DJH
-    
+
     vec3 col = vec3(0);
 
     //get light vector
@@ -220,19 +220,19 @@ in vec2 vary_texcoord0;
 vec3 getNormal(inout float glossiness)
 {
 #ifdef HAS_NORMAL_MAP
-	vec4 vNt = texture(bumpMap, vary_texcoord1.xy);
+    vec4 vNt = texture(bumpMap, vary_texcoord1.xy);
     glossiness *= vNt.a;
-	vNt.xyz = vNt.xyz * 2 - 1;
+    vNt.xyz = vNt.xyz * 2 - 1;
     float sign = vary_sign;
     vec3 vN = vary_normal;
     vec3 vT = vary_tangent.xyz;
-    
+
     vec3 vB = sign * cross(vN, vT);
     vec3 tnorm = normalize( vNt.x * vT + vNt.y * vB + vNt.z * vN );
 
-	return tnorm;
+    return tnorm;
 #else
-	return normalize(vary_normal);
+    return normalize(vary_normal);
 #endif
 }
 
@@ -269,9 +269,9 @@ void waterClip()
 float getEmissive(vec4 diffcol)
 {
 #if (DIFFUSE_ALPHA_MODE != DIFFUSE_ALPHA_MODE_EMISSIVE)
-	return emissive_brightness;
+    return emissive_brightness;
 #else
-	return max(diffcol.a, emissive_brightness);
+    return max(diffcol.a, emissive_brightness);
 #endif
 }
 
@@ -295,7 +295,7 @@ void main()
 
     // diffcol == diffuse map combined with vertex color
     vec4 diffcol = texture(diffuseMap, vary_texcoord0.xy);
-	diffcol.rgb *= vertex_color.rgb;
+    diffcol.rgb *= vertex_color.rgb;
     alphaMask(diffcol.a);
 
     // spec == specular map combined with specular color
@@ -328,7 +328,7 @@ void main()
     vec3 additive;
     vec3 atten;
     calcAtmosphericVarsLinear(pos.xyz, norm.xyz, light_dir, sunlit, amblit, additive, atten);
-    
+
     vec3 sunlit_linear = srgb_to_linear(sunlit);
     vec3 amblit_linear = amblit;
 
@@ -336,7 +336,7 @@ void main()
     vec3 glossenv;
     vec3 legacyenv;
     sampleReflectionProbesLegacy(ambenv, glossenv, legacyenv, pos.xy*0.5+0.5, pos.xyz, norm.xyz, glossiness, env, true, amblit_linear);
-    
+
     color = ambenv;
 
     float da          = clamp(dot(norm.xyz, light_dir.xyz), 0.0, 1.0);
@@ -406,7 +406,7 @@ void main()
 
     frag_color = max(vec4(color, al), vec4(0));
 
-#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer 
+#else // mode is not DIFFUSE_ALPHA_MODE_BLEND, encode to gbuffer
     // deferred path               // See: C++: addDeferredAttachment(), shader: softenLightF.glsl
 
     float flag = GBUFFER_FLAG_HAS_ATMOS;
diff --git a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl
index ef086fc3be45bc68b99375037d5cbbc797eec6ea..728d70ebb2098bf6113079901a8d4780f5f93b3a 100644
--- a/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl
+++ b/indra/newview/app_settings/shaders/class3/environment/underWaterF.glsl
@@ -4,25 +4,25 @@
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2007, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
 out vec4 frag_color;
 
 uniform sampler2D diffuseMap;
@@ -57,27 +57,27 @@ in vec3 vary_position;
 vec4 applyWaterFogViewLinearNoClip(vec3 pos, vec4 color);
 void mirrorClip(vec3 position);
 
-void main() 
+void main()
 {
-	mirrorClip(vary_position);
-	vec4 color;
+    mirrorClip(vary_position);
+    vec4 color;
 
     //get detail normals
-	vec3 wave1 = texture(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
-	vec3 wave2 = texture(bumpMap, littleWave.xy).xyz*2.0-1.0;
-	vec3 wave3 = texture(bumpMap, littleWave.zw).xyz*2.0-1.0;    
-	vec3 wavef = normalize(wave1+wave2+wave3);
-	
-	//figure out distortion vector (ripply)   
-	vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
-	distort = distort+wavef.xy*refScale;
+    vec3 wave1 = texture(bumpMap, vec2(refCoord.w, view.w)).xyz*2.0-1.0;
+    vec3 wave2 = texture(bumpMap, littleWave.xy).xyz*2.0-1.0;
+    vec3 wave3 = texture(bumpMap, littleWave.zw).xyz*2.0-1.0;
+    vec3 wavef = normalize(wave1+wave2+wave3);
+
+    //figure out distortion vector (ripply)
+    vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
+    distort = distort+wavef.xy*refScale;
 
 #ifdef TRANSPARENT_WATER
-	vec4 fb = texture(screenTex, distort);
+    vec4 fb = texture(screenTex, distort);
 #else
     vec4 fb = vec4(waterFogColorLinear, 0.0);
 #endif
-    
+
     fb = applyWaterFogViewLinearNoClip(vary_position, fb);
 
     frag_color = max(fb, vec4(0));
diff --git a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl
index b2a81aa02537d1b1ee98204bae8c5b788073f1c7..a5592188a92f881bf5f5e4e8f63f8631863a94c0 100644
--- a/indra/newview/app_settings/shaders/class3/environment/waterF.glsl
+++ b/indra/newview/app_settings/shaders/class3/environment/waterF.glsl
@@ -1,28 +1,28 @@
-/** 
+/**
  * @file waterF.glsl
  *
  * $LicenseInfo:firstyear=2022&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2022, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
 // class3/environment/waterF.glsl
 
 out vec4 frag_color;
@@ -129,7 +129,7 @@ void sampleReflectionProbesWater(inout vec3 ambenv, inout vec3 glossenv,
 
 vec3 getPositionWithNDC(vec3 ndc);
 
-void main() 
+void main()
 {
     mirrorClip(vary_position);
     vN = vary_normal;
@@ -160,7 +160,7 @@ void main()
     vec3 wave3 = BlendNormal(wave3_a, wave3_b);
 
     vec2 distort = (refCoord.xy/refCoord.z) * 0.5 + 0.5;
-     
+
     //wave1 = transform_normal(wave1);
     //wave2 = transform_normal(wave2);
     //wave3 = transform_normal(wave3);
@@ -171,7 +171,7 @@ void main()
 
     vec3 up = transform_normal(vec3(0,0,1));
     float vdu = -dot(viewVec, up)*2;
-    
+
     vec3 wave_ibl = wavef;
     wave_ibl.z *= 2.0;
     wave_ibl = transform_normal(normalize(wave_ibl));
@@ -185,13 +185,13 @@ void main()
 
     //wavef = vec3(0, 0, 1);
     wavef = transform_normal(wavef);
-    
-	float dist2 = dist;
-	dist = max(dist, 5.0);
-	
-	float dmod = sqrt(dist);
-	
-	//figure out distortion vector (ripply)   
+
+    float dist2 = dist;
+    dist = max(dist, 5.0);
+
+    float dmod = sqrt(dist);
+
+    //figure out distortion vector (ripply)
     vec2 distort2 = distort + waver.xy * refScale / max(dmod, 1.0);
 
     distort2 = clamp(distort2, vec2(0), vec2(0.999));
@@ -235,7 +235,7 @@ void main()
     float metallic = 0.0;
     float perceptualRoughness = 0.05;
     float gloss      = 1.0 - perceptualRoughness;
-    
+
     vec3  irradiance = vec3(0);
     vec3  radiance  = vec3(0);
     sampleReflectionProbesWater(irradiance, radiance, distort2, pos.xyz, wave_ibl.xyz, gloss, amblit);
@@ -251,7 +251,7 @@ void main()
     vec3 colorEmissive = vec3(0);
     float ao = 1.0;
     vec3 light_dir = transform_normal(lightDir);
-    
+
     perceptualRoughness = 0.0;
     metallic = 1.0;
 
@@ -284,7 +284,7 @@ void main()
     color = ((1.0 - f) * color) + fb.rgb;
 
     float spec = min(max(max(punctual.r, punctual.g), punctual.b), 0.05);
-    
+
     frag_color = max(vec4(color, spec), vec4(0));
 }
 
diff --git a/indra/newview/gltf/asset.h b/indra/newview/gltf/asset.h
index 0e2d180c1891e923827a15bad1b8bf015275004e..cbe46f564bc8462c45479fe42eadb89f77747c0e 100644
--- a/indra/newview/gltf/asset.h
+++ b/indra/newview/gltf/asset.h
@@ -35,7 +35,7 @@
 
 #include "glh/glh_linear.h"
 
-extern F32SecondsImplicit		gFrameTimeSeconds;
+extern F32SecondsImplicit       gFrameTimeSeconds;
 
 // LL GLTF Implementation
 namespace LL
@@ -54,7 +54,7 @@ namespace LL
             std::string mName;
 
             const Material& operator=(const tinygltf::Material& src);
-            
+
             void allocateGLResources(Asset& asset);
         };
 
@@ -66,7 +66,7 @@ namespace LL
             std::string mName;
 
             const Mesh& operator=(const tinygltf::Mesh& src);
-            
+
             void allocateGLResources(Asset& asset);
         };
 
@@ -87,7 +87,7 @@ namespace LL
 
             // if true, translation/rotation/scale are valid and up to date
             bool mTRSValid = false;
-            
+
             bool mNeedsApplyMatrix = false;
 
             std::vector<S32> mChildren;
@@ -148,7 +148,7 @@ namespace LL
             std::string mName;
 
             const Scene& operator=(const tinygltf::Scene& src);
-            
+
             void updateTransforms(Asset& asset);
             void updateRenderTransforms(Asset& asset, const LLMatrix4a& modelview);
         };
@@ -231,7 +231,7 @@ namespace LL
 
             // prepare the asset for rendering
             void allocateGLResources(const std::string& filename, const tinygltf::Model& model);
-            
+
             // Called periodically (typically once per frame)
             // Any ongoing work (such as animations) should be handled here
             // NOT guaranteed to be called every frame
@@ -244,7 +244,7 @@ namespace LL
 
             // update node render transforms
             void updateRenderTransforms(const LLMatrix4a& modelview);
-            
+
             void render(bool opaque, bool rigged = false);
             void renderOpaque();
             void renderTransparent();
@@ -258,9 +258,9 @@ namespace LL
                 LLVector4a* tangent = nullptr,             // return the surface tangent at the intersection point
                 S32* primitive_hitp = nullptr           // return the index of the primitive that was hit
             );
-            
+
             const Asset& operator=(const tinygltf::Model& src);
-            
+
         };
     }
 }
diff --git a/indra/newview/gltfscenemanager.cpp b/indra/newview/gltfscenemanager.cpp
index f48d30aad090510625c3c71b059f8dc1e854ee55..346f7c756343a358f02f9d756fe0a2f31a4ca9c9 100644
--- a/indra/newview/gltfscenemanager.cpp
+++ b/indra/newview/gltfscenemanager.cpp
@@ -129,7 +129,7 @@ void GLTFSceneManager::update()
         Asset* asset = mObjects[i]->mGLTFAsset;
 
         asset->update();
-     
+
     }
 }
 
@@ -137,9 +137,9 @@ void GLTFSceneManager::render(bool opaque, bool rigged)
 {
     // for debugging, just render the whole scene as opaque
     // by traversing the whole scenegraph
-    // Assumes camera transform is already set and 
+    // Assumes camera transform is already set and
     // appropriate shader is already bound
-    
+
     gGL.matrixMode(LLRender::MM_MODELVIEW);
 
     for (U32 i = 0; i < mObjects.size(); ++i)
@@ -280,10 +280,10 @@ LLDrawable* GLTFSceneManager::lineSegmentIntersect(const LLVector4a& start, cons
     LLVector4a* intersection,         // return the intersection point
     LLVector2* tex_coord,            // return the texture coordinates of the intersection point
     LLVector4a* normal,               // return the surface normal at the intersection point
-    LLVector4a* tangent)			// return the surface tangent at the intersection point
+    LLVector4a* tangent)            // return the surface tangent at the intersection point
 {
     LLDrawable* drawable = nullptr;
-    
+
     LLVector4a local_end = end;
     LLVector4a position;
 
@@ -313,8 +313,8 @@ LLDrawable* GLTFSceneManager::lineSegmentIntersect(const LLVector4a& start, cons
 
 void drawBoxOutline(const LLVector4a& pos, const LLVector4a& size);
 
-extern LLVector4a		gDebugRaycastStart;
-extern LLVector4a		gDebugRaycastEnd;
+extern LLVector4a       gDebugRaycastStart;
+extern LLVector4a       gDebugRaycastEnd;
 
 void renderOctreeRaycast(const LLVector4a& start, const LLVector4a& end, const LLVolumeOctree* octree);
 
@@ -335,7 +335,7 @@ void renderAssetDebug(LLViewerObject* obj, Asset* asset)
     agent_to_asset.affineTransform(gDebugRaycastStart, start);
     agent_to_asset.affineTransform(gDebugRaycastEnd, end);
 
-    
+
     for (auto& node : asset->mNodes)
     {
         Mesh& mesh = asset->mMeshes[node.mMesh];
@@ -343,7 +343,7 @@ void renderAssetDebug(LLViewerObject* obj, Asset* asset)
         if (node.mMesh != INVALID_INDEX)
         {
             gGL.loadMatrix((F32*)node.mRenderMatrix.mMatrix);
-            
+
             // draw bounding box of mesh primitives
             if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_BBOXES))
             {
@@ -545,7 +545,7 @@ void GLTFSceneManager::renderDebug()
 
             gGL.loadMatrix((F32*) node->mRenderMatrix.mMatrix);
 
-            
+
 
             auto* listener = (LLVolumeOctreeListener*) primitive->mOctree->getListener(0);
             drawBoxOutline(listener->mBounds[0], listener->mBounds[1]);
diff --git a/indra/newview/gltfscenemanager.h b/indra/newview/gltfscenemanager.h
index d286f335e4aa2bcc13157849caa5d7aa497ae2b0..7966606dfa34222142abf5e394ee71ea5ea76a41 100644
--- a/indra/newview/gltfscenemanager.h
+++ b/indra/newview/gltfscenemanager.h
@@ -36,7 +36,7 @@ namespace LL
     public:
         ~GLTFSceneManager();
         // load GLTF file from disk
-        
+
         void load(); // open filepicker to choose asset
         void load(const std::string& filename); // load asset from filename
 
@@ -55,7 +55,7 @@ namespace LL
             LLVector4a* intersection,         // return the intersection point
             LLVector2* tex_coord,            // return the texture coordinates of the intersection point
             LLVector4a* normal,               // return the surface normal at the intersection point
-            LLVector4a* tangent);			// return the surface tangent at the intersection point
+            LLVector4a* tangent);           // return the surface tangent at the intersection point
 
         bool lineSegmentIntersect(LLVOVolume* obj, GLTF::Asset* asset, const LLVector4a& start, const LLVector4a& end, S32 face, BOOL pick_transparent, BOOL pick_rigged, BOOL pick_unselectable, S32* face_hitp, S32* primitive_hitp,
             LLVector4a* intersection, LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent);
diff --git a/indra/newview/llagent.cpp b/indra/newview/llagent.cpp
index 257a8993d9a6fcc16189817e38aaf8a05d1a779f..4e0236b9e54c9dcca20a9685fed52b364bfbc797 100644
--- a/indra/newview/llagent.cpp
+++ b/indra/newview/llagent.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llagent.cpp
  * @brief LLAgent class implementation
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -27,7 +27,7 @@
 
 #include "llviewerprecompiledheaders.h"
 
-#include "llagent.h" 
+#include "llagent.h"
 
 #include "pipeline.h"
 
@@ -113,14 +113,14 @@ using namespace LLAvatarAppearanceDefines;
 extern LLMenuBarGL* gMenuBarView;
 
 const BOOL ANIMATE = TRUE;
-const U8 AGENT_STATE_TYPING =	0x04;
+const U8 AGENT_STATE_TYPING =   0x04;
 const U8 AGENT_STATE_EDITING =  0x10;
 
 // Autopilot constants
-const F32 AUTOPILOT_HEIGHT_ADJUST_DISTANCE = 8.f;			// meters
-const F32 AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND = 1.f;	// meters
-const F32 AUTOPILOT_MAX_TIME_NO_PROGRESS_WALK = 1.5f;		// seconds
-const F32 AUTOPILOT_MAX_TIME_NO_PROGRESS_FLY = 2.5f;		// seconds. Flying is less presize, needs a bit more time
+const F32 AUTOPILOT_HEIGHT_ADJUST_DISTANCE = 8.f;           // meters
+const F32 AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND = 1.f; // meters
+const F32 AUTOPILOT_MAX_TIME_NO_PROGRESS_WALK = 1.5f;       // seconds
+const F32 AUTOPILOT_MAX_TIME_NO_PROGRESS_FLY = 2.5f;        // seconds. Flying is less presize, needs a bit more time
 
 const F32 MAX_VELOCITY_AUTO_LAND_SQUARED = 4.f * 4.f;
 const F64 CHAT_AGE_FAST_RATE = 3.0;
@@ -139,97 +139,97 @@ LLAgent gAgent;
 class LLTeleportRequest
 {
 public:
-	enum EStatus
-	{
-		kPending,
-		kStarted,
-		kFailed,
-		kRestartPending
-	};
+    enum EStatus
+    {
+        kPending,
+        kStarted,
+        kFailed,
+        kRestartPending
+    };
 
-	LLTeleportRequest();
-	virtual ~LLTeleportRequest();
+    LLTeleportRequest();
+    virtual ~LLTeleportRequest();
 
-	EStatus getStatus() const          {return mStatus;};
-	void    setStatus(EStatus pStatus) {mStatus = pStatus;};
+    EStatus getStatus() const          {return mStatus;};
+    void    setStatus(EStatus pStatus) {mStatus = pStatus;};
 
-	static std::map<S32, std::string> sTeleportStatusName;
-	static const std::string& statusName(EStatus status);
-	virtual void toOstream(std::ostream& os) const;
+    static std::map<S32, std::string> sTeleportStatusName;
+    static const std::string& statusName(EStatus status);
+    virtual void toOstream(std::ostream& os) const;
 
-	virtual bool canRestartTeleport();
+    virtual bool canRestartTeleport();
 
-	virtual void startTeleport() = 0;
-	virtual void restartTeleport();
+    virtual void startTeleport() = 0;
+    virtual void restartTeleport();
 
 protected:
 
 private:
-	EStatus mStatus;
+    EStatus mStatus;
 };
 
 std::map<S32, std::string> LLTeleportRequest::sTeleportStatusName = { { kPending, "kPending" },
-																	  { kStarted, "kStarted" },
-																	  { kFailed, "kFailed" },
-																	  { kRestartPending, "kRestartPending"} };
+                                                                      { kStarted, "kStarted" },
+                                                                      { kFailed, "kFailed" },
+                                                                      { kRestartPending, "kRestartPending"} };
 
 class LLTeleportRequestViaLandmark : public LLTeleportRequest
 {
 public:
-	LLTeleportRequestViaLandmark(const LLUUID &pLandmarkId);
-	virtual ~LLTeleportRequestViaLandmark();
+    LLTeleportRequestViaLandmark(const LLUUID &pLandmarkId);
+    virtual ~LLTeleportRequestViaLandmark();
 
-	virtual void toOstream(std::ostream& os) const;
+    virtual void toOstream(std::ostream& os) const;
 
-	virtual bool canRestartTeleport();
+    virtual bool canRestartTeleport();
 
-	virtual void startTeleport();
-	virtual void restartTeleport();
+    virtual void startTeleport();
+    virtual void restartTeleport();
 
 protected:
-	inline const LLUUID &getLandmarkId() const {return mLandmarkId;};
+    inline const LLUUID &getLandmarkId() const {return mLandmarkId;};
 
 private:
-	LLUUID mLandmarkId;
+    LLUUID mLandmarkId;
 };
 
 class LLTeleportRequestViaLure : public LLTeleportRequestViaLandmark
 {
 public:
-	LLTeleportRequestViaLure(const LLUUID &pLureId, BOOL pIsLureGodLike);
-	virtual ~LLTeleportRequestViaLure();
+    LLTeleportRequestViaLure(const LLUUID &pLureId, BOOL pIsLureGodLike);
+    virtual ~LLTeleportRequestViaLure();
 
-	virtual void toOstream(std::ostream& os) const;
+    virtual void toOstream(std::ostream& os) const;
 
-	virtual bool canRestartTeleport();
+    virtual bool canRestartTeleport();
 
-	virtual void startTeleport();
+    virtual void startTeleport();
 
 protected:
-	inline BOOL isLureGodLike() const {return mIsLureGodLike;};
+    inline BOOL isLureGodLike() const {return mIsLureGodLike;};
 
 private:
-	BOOL mIsLureGodLike;
+    BOOL mIsLureGodLike;
 };
 
 class LLTeleportRequestViaLocation : public LLTeleportRequest
 {
 public:
-	LLTeleportRequestViaLocation(const LLVector3d &pPosGlobal);
-	virtual ~LLTeleportRequestViaLocation();
+    LLTeleportRequestViaLocation(const LLVector3d &pPosGlobal);
+    virtual ~LLTeleportRequestViaLocation();
 
-	virtual void toOstream(std::ostream& os) const;
+    virtual void toOstream(std::ostream& os) const;
 
-	virtual bool canRestartTeleport();
+    virtual bool canRestartTeleport();
 
-	virtual void startTeleport();
-	virtual void restartTeleport();
+    virtual void startTeleport();
+    virtual void restartTeleport();
 
 protected:
-	inline const LLVector3d &getPosGlobal() const {return mPosGlobal;};
+    inline const LLVector3d &getPosGlobal() const {return mPosGlobal;};
 
 private:
-	LLVector3d mPosGlobal;
+    LLVector3d mPosGlobal;
 };
 
 
@@ -237,26 +237,26 @@ class LLTeleportRequestViaLocationLookAt : public LLTeleportRequestViaLocation
 {
 public:
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	LLTeleportRequestViaLocationLookAt(const LLVector3d &pPosGlobal, const LLVector3& look_at);
+    LLTeleportRequestViaLocationLookAt(const LLVector3d &pPosGlobal, const LLVector3& look_at);
 // [/RLVa:KB]
-//	LLTeleportRequestViaLocationLookAt(const LLVector3d &pPosGlobal);
-	virtual ~LLTeleportRequestViaLocationLookAt();
+//  LLTeleportRequestViaLocationLookAt(const LLVector3d &pPosGlobal);
+    virtual ~LLTeleportRequestViaLocationLookAt();
 
-	virtual void toOstream(std::ostream& os) const;
+    virtual void toOstream(std::ostream& os) const;
 
-	virtual bool canRestartTeleport();
+    virtual bool canRestartTeleport();
 
-	virtual void startTeleport();
-	virtual void restartTeleport();
+    virtual void startTeleport();
+    virtual void restartTeleport();
 
 protected:
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	const LLVector3& getLookAt() const { return mLookAt; }
+    const LLVector3& getLookAt() const { return mLookAt; }
 // [/RLVa:KB]
 
 private:
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	LLVector3 mLookAt;
+    LLVector3 mLookAt;
 // [/RLVa:KB]
 
 };
@@ -276,48 +276,48 @@ std::map<std::string, std::string> LLAgent::sTeleportProgressMessages;
 class LLAgentFriendObserver : public LLFriendObserver
 {
 public:
-	LLAgentFriendObserver() {}
-	virtual ~LLAgentFriendObserver() {}
-	virtual void changed(U32 mask);
+    LLAgentFriendObserver() {}
+    virtual ~LLAgentFriendObserver() {}
+    virtual void changed(U32 mask);
 };
 
 void LLAgentFriendObserver::changed(U32 mask)
 {
-	// if there's a change we're interested in.
-	if((mask & (LLFriendObserver::POWERS)) != 0)
-	{
-		gAgent.friendsChanged();
-	}
+    // if there's a change we're interested in.
+    if((mask & (LLFriendObserver::POWERS)) != 0)
+    {
+        gAgent.friendsChanged();
+    }
 }
 
 bool handleSlowMotionAnimation(const LLSD& newvalue)
 {
-	if (newvalue.asBoolean())
-	{
-		gAgentAvatarp->setAnimTimeFactor(0.2f);
-	}
-	else
-	{
-		gAgentAvatarp->setAnimTimeFactor(1.0f);
-	}
-	return true;
+    if (newvalue.asBoolean())
+    {
+        gAgentAvatarp->setAnimTimeFactor(0.2f);
+    }
+    else
+    {
+        gAgentAvatarp->setAnimTimeFactor(1.0f);
+    }
+    return true;
 }
 
 void LLAgent::setCanEditParcel() // called via mParcelChangedSignal
 {
-	bool can_edit = LLToolMgr::getInstance()->canEdit();
-	gAgent.mCanEditParcel = can_edit;
+    bool can_edit = LLToolMgr::getInstance()->canEdit();
+    gAgent.mCanEditParcel = can_edit;
 }
 
 // static
 bool LLAgent::isActionAllowed(const LLSD& sdname)
 {
-	bool retval = false;
+    bool retval = false;
 
-	const std::string& param = sdname.asString();
+    const std::string& param = sdname.asString();
 
-	if (param == "speak")
-	{
+    if (param == "speak")
+    {
         bool allow_agent_voice = false;
         LLVoiceChannel* channel = LLVoiceChannel::getCurrentVoiceChannel();
         if (channel != NULL)
@@ -336,42 +336,42 @@ bool LLAgent::isActionAllowed(const LLSD& sdname)
         if (gAgent.isVoiceConnected() &&
             allow_agent_voice &&
             !LLVoiceClient::getInstance()->inTuningMode())
-		{
-			retval = true;
-		}
-		else
-		{
-			retval = false;
-		}
-	}
+        {
+            retval = true;
+        }
+        else
+        {
+            retval = false;
+        }
+    }
 
-	return retval;
+    return retval;
 }
 
-// static 
+// static
 void LLAgent::pressMicrophone(const LLSD& name)
 {
-	LLFirstUse::speak(false);
+    LLFirstUse::speak(false);
 
-	 LLVoiceClient::getInstance()->inputUserControlState(true);
+     LLVoiceClient::getInstance()->inputUserControlState(true);
 }
 
-// static 
+// static
 void LLAgent::releaseMicrophone(const LLSD& name)
 {
-	LLVoiceClient::getInstance()->inputUserControlState(false);
+    LLVoiceClient::getInstance()->inputUserControlState(false);
 }
 
 // static
 void LLAgent::toggleMicrophone(const LLSD& name)
 {
-	LLVoiceClient::getInstance()->toggleUserPTTState();
+    LLVoiceClient::getInstance()->toggleUserPTTState();
 }
 
 // static
 bool LLAgent::isMicrophoneOn(const LLSD& sdname)
 {
-	return LLVoiceClient::getInstance()->getUserPTTState();
+    return LLVoiceClient::getInstance()->getUserPTTState();
 }
 
 // ************************************************************
@@ -390,112 +390,112 @@ bool LLAgent::isMicrophoneOn(const LLSD& sdname)
 // LLAgent()
 //-----------------------------------------------------------------------------
 LLAgent::LLAgent() :
-	mGroupPowers(0),
-	mHideGroupTitle(FALSE),
-	mGroupID(),
+    mGroupPowers(0),
+    mHideGroupTitle(FALSE),
+    mGroupID(),
 
-	mInitialized(false),
-	mListener(),
+    mInitialized(false),
+    mListener(),
 
-	mDoubleTapRunTimer(),
-	mDoubleTapRunMode(DOUBLETAP_NONE),
+    mDoubleTapRunTimer(),
+    mDoubleTapRunMode(DOUBLETAP_NONE),
 
-	mbAlwaysRun(false),
-//	mbRunning(false),
+    mbAlwaysRun(false),
+//  mbRunning(false),
 // [RLVa:KB] - Checked: 2011-05-11 (RLVa-1.3.0i) | Added: RLVa-1.3.0i
-	mbTempRun(false),
+    mbTempRun(false),
 // [/RLVa:KB]
-	mbTeleportKeepsLookAt(false),
-
-	mAgentAccess(new LLAgentAccess(gSavedSettings)),
-	mGodLevelChangeSignal(),
-	mCanEditParcel(false),
-	mTeleportSourceSLURL(new LLSLURL),
-	mTeleportRequest(),
-	mTeleportFinishedSlot(),
-	mTeleportFailedSlot(),
-	mIsMaturityRatingChangingDuringTeleport(false),
-	mTPNeedsNeabyChatSeparator(false),
-	mMaturityRatingChange(0U),
-	mIsDoSendMaturityPreferenceToServer(false),
-	mMaturityPreferenceRequestId(0U),
-	mMaturityPreferenceResponseId(0U),
-	mMaturityPreferenceNumRetries(0U),
-	mLastKnownRequestMaturity(SIM_ACCESS_MIN),
-	mLastKnownResponseMaturity(SIM_ACCESS_MIN),
-	mHttpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID),
-	mTeleportState(TELEPORT_NONE),
-	mRegionp(NULL),
+    mbTeleportKeepsLookAt(false),
+
+    mAgentAccess(new LLAgentAccess(gSavedSettings)),
+    mGodLevelChangeSignal(),
+    mCanEditParcel(false),
+    mTeleportSourceSLURL(new LLSLURL),
+    mTeleportRequest(),
+    mTeleportFinishedSlot(),
+    mTeleportFailedSlot(),
+    mIsMaturityRatingChangingDuringTeleport(false),
+    mTPNeedsNeabyChatSeparator(false),
+    mMaturityRatingChange(0U),
+    mIsDoSendMaturityPreferenceToServer(false),
+    mMaturityPreferenceRequestId(0U),
+    mMaturityPreferenceResponseId(0U),
+    mMaturityPreferenceNumRetries(0U),
+    mLastKnownRequestMaturity(SIM_ACCESS_MIN),
+    mLastKnownResponseMaturity(SIM_ACCESS_MIN),
+    mHttpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID),
+    mTeleportState(TELEPORT_NONE),
+    mRegionp(NULL),
     mInterestListMode(LLViewerRegion::IL_MODE_DEFAULT),
 
-	mAgentOriginGlobal(),
-	mPositionGlobal(),
+    mAgentOriginGlobal(),
+    mPositionGlobal(),
     mLastTestGlobal(),
 
-	mDistanceTraveled(0.F),
-	mLastPositionGlobal(LLVector3d::zero),
-
-	mRenderState(0),
-	mTypingTimer(),
-
-	mViewsPushed(FALSE),
-
-	mCustomAnim(FALSE),
-	mShowAvatar(TRUE),
-	mFrameAgent(),
-
-	mIsDoNotDisturb(false),
-	mIsRejectTeleportOffers(false), 
-	mIgnorePrejump(FALSE),
-
-	mControlFlags(0x00000000),
-	mbFlagsDirty(FALSE),
-	mbFlagsNeedReset(FALSE),
-
-	mAutoPilot(FALSE),
-	mAutoPilotFlyOnStop(FALSE),
-	mAutoPilotAllowFlying(TRUE),
-	mAutoPilotTargetGlobal(),
-	mAutoPilotStopDistance(1.f),
-	mAutoPilotUseRotation(FALSE),
-	mAutoPilotTargetFacing(LLVector3::zero),
-	mAutoPilotTargetDist(0.f),
-	mAutoPilotNoProgressFrameCount(0),
-	mAutoPilotRotationThreshold(0.f),
-	mAutoPilotFinishedCallback(NULL),
-	mAutoPilotCallbackData(NULL),
-	
-	mMovementKeysLocked(FALSE),
-
-	mMovementResetCamera(true),
-
-	mEffectColor(new LLUIColor(LLColor4(0.f, 1.f, 1.f, 1.f))),
-
-	mHaveHomePosition(FALSE),
-	mHomeRegionHandle( 0 ),
-	mNearChatRadius(CHAT_NORMAL_RADIUS / 2.f),
-
-	mNextFidgetTime(0.f),
-	mCurrentFidget(0),
-	mFirstLogin(false),
-	mOutfitChosen(FALSE),
+    mDistanceTraveled(0.F),
+    mLastPositionGlobal(LLVector3d::zero),
+
+    mRenderState(0),
+    mTypingTimer(),
+
+    mViewsPushed(FALSE),
+
+    mCustomAnim(FALSE),
+    mShowAvatar(TRUE),
+    mFrameAgent(),
+
+    mIsDoNotDisturb(false),
+    mIsRejectTeleportOffers(false),
+    mIgnorePrejump(FALSE),
+
+    mControlFlags(0x00000000),
+    mbFlagsDirty(FALSE),
+    mbFlagsNeedReset(FALSE),
+
+    mAutoPilot(FALSE),
+    mAutoPilotFlyOnStop(FALSE),
+    mAutoPilotAllowFlying(TRUE),
+    mAutoPilotTargetGlobal(),
+    mAutoPilotStopDistance(1.f),
+    mAutoPilotUseRotation(FALSE),
+    mAutoPilotTargetFacing(LLVector3::zero),
+    mAutoPilotTargetDist(0.f),
+    mAutoPilotNoProgressFrameCount(0),
+    mAutoPilotRotationThreshold(0.f),
+    mAutoPilotFinishedCallback(NULL),
+    mAutoPilotCallbackData(NULL),
+
+    mMovementKeysLocked(FALSE),
+
+    mMovementResetCamera(true),
+
+    mEffectColor(new LLUIColor(LLColor4(0.f, 1.f, 1.f, 1.f))),
+
+    mHaveHomePosition(FALSE),
+    mHomeRegionHandle( 0 ),
+    mNearChatRadius(CHAT_NORMAL_RADIUS / 2.f),
+
+    mNextFidgetTime(0.f),
+    mCurrentFidget(0),
+    mFirstLogin(false),
+    mOutfitChosen(FALSE),
     mCrouch(false),
-	mVoiceConnected(false),
+    mVoiceConnected(false),
 
-	mMouselookModeInSignal(NULL),
-	mMouselookModeOutSignal(NULL)
+    mMouselookModeInSignal(NULL),
+    mMouselookModeOutSignal(NULL)
 {
-	for (U32 i = 0; i < TOTAL_CONTROLS; i++)
-	{
-		mControlsTakenCount[i] = 0;
-		mControlsTakenPassedOnCount[i] = 0;
-	}
+    for (U32 i = 0; i < TOTAL_CONTROLS; i++)
+    {
+        mControlsTakenCount[i] = 0;
+        mControlsTakenPassedOnCount[i] = 0;
+    }
 
-	mListener.reset(new LLAgentListener(*this));
+    mListener.reset(new LLAgentListener(*this));
 
-	addParcelChangedCallback(&setCanEditParcel);
+    addParcelChangedCallback(&setCanEditParcel);
 
-	mMoveTimer.stop();
+    mMoveTimer.stop();
 }
 
 // Requires gSavedSettings to be initialized.
@@ -504,12 +504,12 @@ LLAgent::LLAgent() :
 //-----------------------------------------------------------------------------
 void LLAgent::init()
 {
-	mMoveTimer.start();
+    mMoveTimer.start();
+
+    gSavedSettings.declareBOOL("SlowMotionAnimation", FALSE, "Declared in code", LLControlVariable::PERSIST_NO);
+    gSavedSettings.getControl("SlowMotionAnimation")->getSignal()->connect(boost::bind(&handleSlowMotionAnimation, _2));
 
-	gSavedSettings.declareBOOL("SlowMotionAnimation", FALSE, "Declared in code", LLControlVariable::PERSIST_NO);
-	gSavedSettings.getControl("SlowMotionAnimation")->getSignal()->connect(boost::bind(&handleSlowMotionAnimation, _2));
-	
-	// *Note: this is where LLViewerCamera::getInstance() used to be constructed.
+    // *Note: this is where LLViewerCamera::getInstance() used to be constructed.
 
     bool is_flying = gSavedSettings.getBOOL("FlyingAtExit");
     if(is_flying)
@@ -517,39 +517,39 @@ void LLAgent::init()
         setFlying(is_flying);
     }
 
-	*mEffectColor = LLUIColorTable::instance().getColor("EffectColor");
+    *mEffectColor = LLUIColorTable::instance().getColor("EffectColor");
 
-	gSavedSettings.getControl("PreferredMaturity")->getValidateSignal()->connect(boost::bind(&LLAgent::validateMaturity, this, _2));
-	gSavedSettings.getControl("PreferredMaturity")->getSignal()->connect(boost::bind(&LLAgent::handleMaturity, this, _2));
-	mLastKnownResponseMaturity = static_cast<U8>(gSavedSettings.getU32("PreferredMaturity"));
-	mLastKnownRequestMaturity = mLastKnownResponseMaturity;
-	mIsDoSendMaturityPreferenceToServer = true;
+    gSavedSettings.getControl("PreferredMaturity")->getValidateSignal()->connect(boost::bind(&LLAgent::validateMaturity, this, _2));
+    gSavedSettings.getControl("PreferredMaturity")->getSignal()->connect(boost::bind(&LLAgent::handleMaturity, this, _2));
+    mLastKnownResponseMaturity = static_cast<U8>(gSavedSettings.getU32("PreferredMaturity"));
+    mLastKnownRequestMaturity = mLastKnownResponseMaturity;
+    mIsDoSendMaturityPreferenceToServer = true;
 
-	mIgnorePrejump = gSavedSettings.getBOOL("AlchemyNimble");
-	gSavedSettings.getControl("AlchemyNimble")->getSignal()->connect([this](LLControlVariable* control, const LLSD& new_val, const LLSD&) { mIgnorePrejump = new_val.asBoolean(); });
+    mIgnorePrejump = gSavedSettings.getBOOL("AlchemyNimble");
+    gSavedSettings.getControl("AlchemyNimble")->getSignal()->connect([this](LLControlVariable* control, const LLSD& new_val, const LLSD&) { mIgnorePrejump = new_val.asBoolean(); });
 
-	auto controlp = gSavedSettings.getControl("AlchemyMotionResetsCamera");
-	controlp->getSignal()->connect([&](LLControlVariable* control, const LLSD& new_val, const LLSD&) { mMovementResetCamera = new_val.asBoolean(); });
-	mMovementResetCamera = controlp->getValue().asBoolean();
+    auto controlp = gSavedSettings.getControl("AlchemyMotionResetsCamera");
+    controlp->getSignal()->connect([&](LLControlVariable* control, const LLSD& new_val, const LLSD&) { mMovementResetCamera = new_val.asBoolean(); });
+    mMovementResetCamera = controlp->getValue().asBoolean();
 
-	selectRejectFriendshipRequests(gSavedPerAccountSettings.getBOOL("ALRejectFriendshipRequestsMode"));
-	setRejectTeleportOffers(gSavedPerAccountSettings.getBOOL("ALRejectTeleportOffersMode")); 
+    selectRejectFriendshipRequests(gSavedPerAccountSettings.getBOOL("ALRejectFriendshipRequestsMode"));
+    setRejectTeleportOffers(gSavedPerAccountSettings.getBOOL("ALRejectTeleportOffersMode"));
 
 
-	if (!mTeleportFinishedSlot.connected())
-	{
-		mTeleportFinishedSlot = LLViewerParcelMgr::getInstance()->setTeleportFinishedCallback(boost::bind(&LLAgent::handleTeleportFinished, this));
-	}
-	if (!mTeleportFailedSlot.connected())
-	{
-		mTeleportFailedSlot = LLViewerParcelMgr::getInstance()->setTeleportFailedCallback(boost::bind(&LLAgent::handleTeleportFailed, this));
-	}
+    if (!mTeleportFinishedSlot.connected())
+    {
+        mTeleportFinishedSlot = LLViewerParcelMgr::getInstance()->setTeleportFinishedCallback(boost::bind(&LLAgent::handleTeleportFinished, this));
+    }
+    if (!mTeleportFailedSlot.connected())
+    {
+        mTeleportFailedSlot = LLViewerParcelMgr::getInstance()->setTeleportFailedCallback(boost::bind(&LLAgent::handleTeleportFailed, this));
+    }
 
-	LLAppCoreHttp & app_core_http(LLAppViewer::instance()->getAppCoreHttp());
+    LLAppCoreHttp & app_core_http(LLAppViewer::instance()->getAppCoreHttp());
 
-	mHttpPolicy = app_core_http.getPolicy(LLAppCoreHttp::AP_AGENT);
+    mHttpPolicy = app_core_http.getPolicy(LLAppCoreHttp::AP_AGENT);
 
-	mInitialized = true;
+    mInitialized = true;
 }
 
 //-----------------------------------------------------------------------------
@@ -557,17 +557,17 @@ void LLAgent::init()
 //-----------------------------------------------------------------------------
 void LLAgent::cleanup()
 {
-	mRegionp = NULL;
+    mRegionp = NULL;
     mTeleportRequest = NULL;
     mTeleportCanceled = NULL;
-	if (mTeleportFinishedSlot.connected())
-	{
-		mTeleportFinishedSlot.disconnect();
-	}
-	if (mTeleportFailedSlot.connected())
-	{
-		mTeleportFailedSlot.disconnect();
-	}
+    if (mTeleportFinishedSlot.connected())
+    {
+        mTeleportFinishedSlot.disconnect();
+    }
+    if (mTeleportFailedSlot.connected())
+    {
+        mTeleportFailedSlot.disconnect();
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -575,19 +575,19 @@ void LLAgent::cleanup()
 //-----------------------------------------------------------------------------
 LLAgent::~LLAgent()
 {
-	cleanup();
+    cleanup();
 
-	delete mMouselookModeInSignal;
-	mMouselookModeInSignal = NULL;
-	delete mMouselookModeOutSignal;
-	mMouselookModeOutSignal = NULL;
+    delete mMouselookModeInSignal;
+    mMouselookModeInSignal = NULL;
+    delete mMouselookModeOutSignal;
+    mMouselookModeOutSignal = NULL;
 
-	delete mAgentAccess;
-	mAgentAccess = NULL;
-	delete mEffectColor;
-	mEffectColor = NULL;
-	delete mTeleportSourceSLURL;
-	mTeleportSourceSLURL = NULL;
+    delete mAgentAccess;
+    mAgentAccess = NULL;
+    delete mEffectColor;
+    mEffectColor = NULL;
+    delete mTeleportSourceSLURL;
+    mTeleportSourceSLURL = NULL;
 }
 
 // Handle any actions that need to be performed when the main app gains focus
@@ -597,11 +597,11 @@ LLAgent::~LLAgent()
 //-----------------------------------------------------------------------------
 void LLAgent::onAppFocusGained()
 {
-//	if (CAMERA_MODE_MOUSELOOK == gAgentCamera.getCameraMode())
-//	{
-//		gAgentCamera.changeCameraToDefault();
-//		LLToolMgr::getInstance()->clearSavedTool();
-//	}
+//  if (CAMERA_MODE_MOUSELOOK == gAgentCamera.getCameraMode())
+//  {
+//      gAgentCamera.changeCameraToDefault();
+//      LLToolMgr::getInstance()->clearSavedTool();
+//  }
 }
 
 void LLAgent::setFirstLogin(bool b)
@@ -694,13 +694,13 @@ void LLAgent::showLatestFeatureNotification(const std::string key)
 
 void LLAgent::ageChat()
 {
-	if (isAgentAvatarValid())
-	{
-		// get amount of time since I last chatted
-		F64 elapsed_time = (F64)gAgentAvatarp->mChatTimer.getElapsedTimeF32();
-		// add in frame time * 3 (so it ages 4x)
-		gAgentAvatarp->mChatTimer.setAge(elapsed_time + (F64)gFrameDTClamped * (CHAT_AGE_FAST_RATE - 1.0));
-	}
+    if (isAgentAvatarValid())
+    {
+        // get amount of time since I last chatted
+        F64 elapsed_time = (F64)gAgentAvatarp->mChatTimer.getElapsedTimeF32();
+        // add in frame time * 3 (so it ages 4x)
+        gAgentAvatarp->mChatTimer.setAge(elapsed_time + (F64)gFrameDTClamped * (CHAT_AGE_FAST_RATE - 1.0));
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -708,27 +708,27 @@ void LLAgent::ageChat()
 //-----------------------------------------------------------------------------
 void LLAgent::moveAt(S32 direction, bool reset)
 {
-	mMoveTimer.reset();
-	LLFirstUse::notMoving(false);
+    mMoveTimer.reset();
+    LLFirstUse::notMoving(false);
 
-	// age chat timer so it fades more quickly when you are intentionally moving
-	ageChat();
+    // age chat timer so it fades more quickly when you are intentionally moving
+    ageChat();
 
-	gAgentCamera.setAtKey(LLAgentCamera::directionToKey(direction));
+    gAgentCamera.setAtKey(LLAgentCamera::directionToKey(direction));
 
-	if (direction > 0)
-	{
-		setControlFlags(AGENT_CONTROL_AT_POS | AGENT_CONTROL_FAST_AT);
-	}
-	else if (direction < 0)
-	{
-		setControlFlags(AGENT_CONTROL_AT_NEG | AGENT_CONTROL_FAST_AT);
-	}
+    if (direction > 0)
+    {
+        setControlFlags(AGENT_CONTROL_AT_POS | AGENT_CONTROL_FAST_AT);
+    }
+    else if (direction < 0)
+    {
+        setControlFlags(AGENT_CONTROL_AT_NEG | AGENT_CONTROL_FAST_AT);
+    }
 
-	if (reset)
-	{
-		gAgentCamera.resetView(mMovementResetCamera);
-	}
+    if (reset)
+    {
+        gAgentCamera.resetView(mMovementResetCamera);
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -736,24 +736,24 @@ void LLAgent::moveAt(S32 direction, bool reset)
 //-----------------------------------------------------------------------------
 void LLAgent::moveAtNudge(S32 direction)
 {
-	mMoveTimer.reset();
-	LLFirstUse::notMoving(false);
+    mMoveTimer.reset();
+    LLFirstUse::notMoving(false);
 
-	// age chat timer so it fades more quickly when you are intentionally moving
-	ageChat();
+    // age chat timer so it fades more quickly when you are intentionally moving
+    ageChat();
 
-	gAgentCamera.setWalkKey(LLAgentCamera::directionToKey(direction));
+    gAgentCamera.setWalkKey(LLAgentCamera::directionToKey(direction));
 
-	if (direction > 0)
-	{
-		setControlFlags(AGENT_CONTROL_NUDGE_AT_POS);
-	}
-	else if (direction < 0)
-	{
-		setControlFlags(AGENT_CONTROL_NUDGE_AT_NEG);
-	}
+    if (direction > 0)
+    {
+        setControlFlags(AGENT_CONTROL_NUDGE_AT_POS);
+    }
+    else if (direction < 0)
+    {
+        setControlFlags(AGENT_CONTROL_NUDGE_AT_NEG);
+    }
 
-	gAgentCamera.resetView(mMovementResetCamera);
+    gAgentCamera.resetView(mMovementResetCamera);
 }
 
 //-----------------------------------------------------------------------------
@@ -761,24 +761,24 @@ void LLAgent::moveAtNudge(S32 direction)
 //-----------------------------------------------------------------------------
 void LLAgent::moveLeft(S32 direction)
 {
-	mMoveTimer.reset();
-	LLFirstUse::notMoving(false);
+    mMoveTimer.reset();
+    LLFirstUse::notMoving(false);
 
-	// age chat timer so it fades more quickly when you are intentionally moving
-	ageChat();
+    // age chat timer so it fades more quickly when you are intentionally moving
+    ageChat();
 
-	gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction));
+    gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction));
 
-	if (direction > 0)
-	{
-		setControlFlags(AGENT_CONTROL_LEFT_POS | AGENT_CONTROL_FAST_LEFT);
-	}
-	else if (direction < 0)
-	{
-		setControlFlags(AGENT_CONTROL_LEFT_NEG | AGENT_CONTROL_FAST_LEFT);
-	}
+    if (direction > 0)
+    {
+        setControlFlags(AGENT_CONTROL_LEFT_POS | AGENT_CONTROL_FAST_LEFT);
+    }
+    else if (direction < 0)
+    {
+        setControlFlags(AGENT_CONTROL_LEFT_NEG | AGENT_CONTROL_FAST_LEFT);
+    }
 
-	gAgentCamera.resetView(mMovementResetCamera);
+    gAgentCamera.resetView(mMovementResetCamera);
 }
 
 //-----------------------------------------------------------------------------
@@ -786,24 +786,24 @@ void LLAgent::moveLeft(S32 direction)
 //-----------------------------------------------------------------------------
 void LLAgent::moveLeftNudge(S32 direction)
 {
-	mMoveTimer.reset();
-	LLFirstUse::notMoving(false);
+    mMoveTimer.reset();
+    LLFirstUse::notMoving(false);
 
-	// age chat timer so it fades more quickly when you are intentionally moving
-	ageChat();
+    // age chat timer so it fades more quickly when you are intentionally moving
+    ageChat();
 
-	gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction));
+    gAgentCamera.setLeftKey(LLAgentCamera::directionToKey(direction));
 
-	if (direction > 0)
-	{
-		setControlFlags(AGENT_CONTROL_NUDGE_LEFT_POS);
-	}
-	else if (direction < 0)
-	{
-		setControlFlags(AGENT_CONTROL_NUDGE_LEFT_NEG);
-	}
+    if (direction > 0)
+    {
+        setControlFlags(AGENT_CONTROL_NUDGE_LEFT_POS);
+    }
+    else if (direction < 0)
+    {
+        setControlFlags(AGENT_CONTROL_NUDGE_LEFT_NEG);
+    }
 
-	gAgentCamera.resetView(mMovementResetCamera);
+    gAgentCamera.resetView(mMovementResetCamera);
 }
 
 //-----------------------------------------------------------------------------
@@ -812,29 +812,29 @@ void LLAgent::moveLeftNudge(S32 direction)
 void LLAgent::moveUp(S32 direction)
 {
 // [RLVa:KB] - Checked: RLVa-2.2 (@jump)
-	if ( (!RlvActions::canJump()) && (direction > 0) && (!getFlying()) )
-	{
-		return;
-	}
+    if ( (!RlvActions::canJump()) && (direction > 0) && (!getFlying()) )
+    {
+        return;
+    }
 // [/Sl:KB]
 
-	mMoveTimer.reset();
-	LLFirstUse::notMoving(false);
+    mMoveTimer.reset();
+    LLFirstUse::notMoving(false);
 
-	// age chat timer so it fades more quickly when you are intentionally moving
-	ageChat();
+    // age chat timer so it fades more quickly when you are intentionally moving
+    ageChat();
 
-	gAgentCamera.setUpKey(LLAgentCamera::directionToKey(direction));
+    gAgentCamera.setUpKey(LLAgentCamera::directionToKey(direction));
 
-	if (direction > 0)
-	{
-		setControlFlags(AGENT_CONTROL_UP_POS | AGENT_CONTROL_FAST_UP);
+    if (direction > 0)
+    {
+        setControlFlags(AGENT_CONTROL_UP_POS | AGENT_CONTROL_FAST_UP);
         mCrouch = false;
-	}
-	else if (direction < 0)
-	{
-		setControlFlags(AGENT_CONTROL_UP_NEG | AGENT_CONTROL_FAST_UP);
-	}
+    }
+    else if (direction < 0)
+    {
+        setControlFlags(AGENT_CONTROL_UP_NEG | AGENT_CONTROL_FAST_UP);
+    }
 
     if (!mCrouch)
         gAgentCamera.resetView(mMovementResetCamera);
@@ -845,16 +845,16 @@ void LLAgent::moveUp(S32 direction)
 //-----------------------------------------------------------------------------
 void LLAgent::moveYaw(F32 mag, bool reset_view)
 {
-	gAgentCamera.setYawKey(mag);
+    gAgentCamera.setYawKey(mag);
 
-	if (mag > 0)
-	{
-		setControlFlags(AGENT_CONTROL_YAW_POS);
-	}
-	else if (mag < 0)
-	{
-		setControlFlags(AGENT_CONTROL_YAW_NEG);
-	}
+    if (mag > 0)
+    {
+        setControlFlags(AGENT_CONTROL_YAW_POS);
+    }
+    else if (mag < 0)
+    {
+        setControlFlags(AGENT_CONTROL_YAW_NEG);
+    }
 
     U32 mask = AGENT_CONTROL_YAW_POS | AGENT_CONTROL_YAW_NEG;
     if ((getControlFlags() & mask) == mask)
@@ -866,9 +866,9 @@ void LLAgent::moveYaw(F32 mag, bool reset_view)
     }
 
     if (reset_view)
-	{
+    {
         gAgentCamera.resetView(mMovementResetCamera);
-	}
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -876,16 +876,16 @@ void LLAgent::moveYaw(F32 mag, bool reset_view)
 //-----------------------------------------------------------------------------
 void LLAgent::movePitch(F32 mag)
 {
-	gAgentCamera.setPitchKey(mag);
+    gAgentCamera.setPitchKey(mag);
 
-	if (mag > 0)
-	{
-		setControlFlags(AGENT_CONTROL_PITCH_POS);
-	}
-	else if (mag < 0)
-	{
-		setControlFlags(AGENT_CONTROL_PITCH_NEG);
-	}
+    if (mag > 0)
+    {
+        setControlFlags(AGENT_CONTROL_PITCH_POS);
+    }
+    else if (mag < 0)
+    {
+        setControlFlags(AGENT_CONTROL_PITCH_NEG);
+    }
 }
 
 bool LLAgent::isCrouching() const
@@ -897,33 +897,33 @@ bool LLAgent::isCrouching() const
 BOOL LLAgent::canFly()
 {
 // [RLVa:KB] - Checked: RLVa-1.0
-	if (!RlvActions::canFly())
-	{
-		return FALSE;
-	}
+    if (!RlvActions::canFly())
+    {
+        return FALSE;
+    }
 // [/RLVa:KB]
 
-	// Allow gods and estate managers to always fly
-	if (isGodlike() || canManageEstate()) return TRUE;
+    // Allow gods and estate managers to always fly
+    if (isGodlike() || canManageEstate()) return TRUE;
+
+    LLViewerRegion* regionp = getRegion();
+    if (regionp && regionp->getBlockFly()) return FALSE;
 
-	LLViewerRegion* regionp = getRegion();
-	if (regionp && regionp->getBlockFly()) return FALSE;
-	
-	LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
-	if (!parcel) return FALSE;
+    LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
+    if (!parcel) return FALSE;
 
-	// Allow owners to fly on their own land.
-	if (LLViewerParcelMgr::isParcelOwnedByAgent(parcel, GP_LAND_ALLOW_FLY))
-	{
-		return TRUE;
-	}
+    // Allow owners to fly on their own land.
+    if (LLViewerParcelMgr::isParcelOwnedByAgent(parcel, GP_LAND_ALLOW_FLY))
+    {
+        return TRUE;
+    }
 
-	return parcel->getAllowFly();
+    return parcel->getAllowFly();
 }
 
 BOOL LLAgent::getFlying() const
-{ 
-	return mControlFlags & AGENT_CONTROL_FLY; 
+{
+    return mControlFlags & AGENT_CONTROL_FLY;
 }
 
 //-----------------------------------------------------------------------------
@@ -931,63 +931,63 @@ BOOL LLAgent::getFlying() const
 //-----------------------------------------------------------------------------
 void LLAgent::setFlying(BOOL fly, BOOL fail_sound)
 {
-	if (isAgentAvatarValid())
-	{
-		// *HACK: Don't allow to start the flying mode if we got ANIM_AGENT_STANDUP signal
-		// because in this case we won't get a signal to start avatar flying animation and
-		// it will be walking with flying mode "ON" indication. However we allow to switch
-		// the flying mode off if we get ANIM_AGENT_STANDUP signal. See process_avatar_animation().
-		// See EXT-2781.
-		if(fly && gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_STANDUP) != gAgentAvatarp->mSignaledAnimations.end())
-		{
-			return;
-		}
-
-		// don't allow taking off while sitting
-		if (fly && gAgentAvatarp->isSitting())
-		{
-			return;
-		}
-	}
-
-	if (fly)
-	{
+    if (isAgentAvatarValid())
+    {
+        // *HACK: Don't allow to start the flying mode if we got ANIM_AGENT_STANDUP signal
+        // because in this case we won't get a signal to start avatar flying animation and
+        // it will be walking with flying mode "ON" indication. However we allow to switch
+        // the flying mode off if we get ANIM_AGENT_STANDUP signal. See process_avatar_animation().
+        // See EXT-2781.
+        if(fly && gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_STANDUP) != gAgentAvatarp->mSignaledAnimations.end())
+        {
+            return;
+        }
+
+        // don't allow taking off while sitting
+        if (fly && gAgentAvatarp->isSitting())
+        {
+            return;
+        }
+    }
+
+    if (fly)
+    {
 // [RLVa:KB] - Checked: RLVa-1.0
-		if (!RlvActions::canFly())
-		{
-			return;
-		}
+        if (!RlvActions::canFly())
+        {
+            return;
+        }
 // [/RLVa:KB]
 
-		BOOL was_flying = getFlying();
-		if (!canFly() && !was_flying)
-		{
-			// parcel doesn't let you start fly
-			// gods can always fly
-			// and it's OK if you're already flying
-			if (fail_sound)
-			{
-			make_ui_sound("UISndBadKeystroke");
-			}
-			return;
-		}
-		if( !was_flying )
-		{
-			add(LLStatViewer::FLY, 1);
-		}
+        BOOL was_flying = getFlying();
+        if (!canFly() && !was_flying)
+        {
+            // parcel doesn't let you start fly
+            // gods can always fly
+            // and it's OK if you're already flying
+            if (fail_sound)
+            {
+            make_ui_sound("UISndBadKeystroke");
+            }
+            return;
+        }
+        if( !was_flying )
+        {
+            add(LLStatViewer::FLY, 1);
+        }
         mCrouch = false;
-		setControlFlags(AGENT_CONTROL_FLY);
-	}
-	else
-	{
-		clearControlFlags(AGENT_CONTROL_FLY);
-	}
+        setControlFlags(AGENT_CONTROL_FLY);
+    }
+    else
+    {
+        clearControlFlags(AGENT_CONTROL_FLY);
+    }
 
 
-	// Update Movement Controls according to Fly mode
-	LLFloaterMove::setFlyingMode(fly);
+    // Update Movement Controls according to Fly mode
+    LLFloaterMove::setFlyingMode(fly);
 
-	mbFlagsDirty = TRUE;
+    mbFlagsDirty = TRUE;
 }
 
 
@@ -998,29 +998,29 @@ void LLAgent::setFlying(BOOL fly, BOOL fail_sound)
 // static
 void LLAgent::toggleFlying()
 {
-	if ( gAgent.mAutoPilot )
-	{
-		LLToolPie::instance().stopClickToWalk();
-	}
+    if ( gAgent.mAutoPilot )
+    {
+        LLToolPie::instance().stopClickToWalk();
+    }
 
-	BOOL fly = !gAgent.getFlying();
+    BOOL fly = !gAgent.getFlying();
 
-	gAgent.mMoveTimer.reset();
-	LLFirstUse::notMoving(false);
+    gAgent.mMoveTimer.reset();
+    LLFirstUse::notMoving(false);
 
-	gAgent.setFlying( fly );
-	gAgentCamera.resetView(gAgent.mMovementResetCamera);
+    gAgent.setFlying( fly );
+    gAgentCamera.resetView(gAgent.mMovementResetCamera);
 }
 
 // static
 bool LLAgent::enableFlying()
 {
-	BOOL sitting = FALSE;
-	if (isAgentAvatarValid())
-	{
-		sitting = gAgentAvatarp->isSitting();
-	}
-	return !sitting;
+    BOOL sitting = FALSE;
+    if (isAgentAvatarValid())
+    {
+        sitting = gAgentAvatarp->isSitting();
+    }
+    return !sitting;
 }
 
 // static
@@ -1036,31 +1036,31 @@ bool LLAgent::isSitting()
 
 void LLAgent::standUp()
 {
-//	setControlFlags(AGENT_CONTROL_STAND_UP);
+//  setControlFlags(AGENT_CONTROL_STAND_UP);
 // [RLVa:KB] - Checked: 2010-03-07 (RLVa-1.2.0c) | Added: RLVa-1.2.0a
-	// RELEASE-RLVa: [SL-2.0.0] Check this function's callers since usually they require explicit blocking
-	if ( (!rlv_handler_t::isEnabled()) || (RlvActions::canStand()) )
-	{
-		setControlFlags(AGENT_CONTROL_STAND_UP);
-	}
+    // RELEASE-RLVa: [SL-2.0.0] Check this function's callers since usually they require explicit blocking
+    if ( (!rlv_handler_t::isEnabled()) || (RlvActions::canStand()) )
+    {
+        setControlFlags(AGENT_CONTROL_STAND_UP);
+    }
 // [/RLVa:KB]
 }
 
 void LLAgent::changeParcels()
 {
-	LL_DEBUGS("AgentLocation") << "Calling ParcelChanged callbacks" << LL_ENDL;
-	// Notify anything that wants to know about parcel changes
-	mParcelChangedSignal();
+    LL_DEBUGS("AgentLocation") << "Calling ParcelChanged callbacks" << LL_ENDL;
+    // Notify anything that wants to know about parcel changes
+    mParcelChangedSignal();
 }
 
 boost::signals2::connection LLAgent::addParcelChangedCallback(parcel_changed_callback_t cb)
 {
-	return mParcelChangedSignal.connect(cb);
+    return mParcelChangedSignal.connect(cb);
 }
 
 // static
 void LLAgent::capabilityReceivedCallback(const LLUUID &region_id, LLViewerRegion *regionp)
-{	// Changed regions and now have the region capabilities
+{   // Changed regions and now have the region capabilities
     if (regionp)
     {
         if (regionp->getRegionID() == region_id)
@@ -1082,40 +1082,40 @@ void LLAgent::capabilityReceivedCallback(const LLUUID &region_id, LLViewerRegion
 //-----------------------------------------------------------------------------
 void LLAgent::setRegion(LLViewerRegion *regionp)
 {
-	llassert(regionp);
-	if (mRegionp != regionp)
-	{
-
-		LL_INFOS("AgentLocation","Teleport") << "Moving agent into region: handle " << regionp->getHandle() 
-											 << " id " << regionp->getRegionID()
-											 << " name " << regionp->getName()
-											 << " previous region "
-											 << (mRegionp ? mRegionp->getRegionID() : LLUUID::null)
-											 << LL_ENDL;
-		if (mRegionp)
-		{
-			// We've changed regions, we're now going to change our agent coordinate frame.
-			mAgentOriginGlobal = regionp->getOriginGlobal();
-			LLVector3d agent_offset_global = mRegionp->getOriginGlobal();
-
-			LLVector3 delta;
-			delta.setVec(regionp->getOriginGlobal() - mRegionp->getOriginGlobal());
-
-			setPositionAgent(getPositionAgent() - delta);
-
-			LLVector3 camera_position_agent = LLViewerCamera::getInstance()->getOrigin();
-			LLViewerCamera::getInstance()->setOrigin(camera_position_agent - delta);
-
-			// Update all of the regions.
-			LLWorld::getInstance()->updateAgentOffset(agent_offset_global);
-
-			// Hack to keep sky in the agent's region, otherwise it may get deleted - DJS 08/02/02
-			// *TODO: possibly refactor into gSky->setAgentRegion(regionp)? -Brad
-			if (gSky.mVOSkyp)
-			{
-				gSky.mVOSkyp->setRegion(regionp);
-			}
-			
+    llassert(regionp);
+    if (mRegionp != regionp)
+    {
+
+        LL_INFOS("AgentLocation","Teleport") << "Moving agent into region: handle " << regionp->getHandle()
+                                             << " id " << regionp->getRegionID()
+                                             << " name " << regionp->getName()
+                                             << " previous region "
+                                             << (mRegionp ? mRegionp->getRegionID() : LLUUID::null)
+                                             << LL_ENDL;
+        if (mRegionp)
+        {
+            // We've changed regions, we're now going to change our agent coordinate frame.
+            mAgentOriginGlobal = regionp->getOriginGlobal();
+            LLVector3d agent_offset_global = mRegionp->getOriginGlobal();
+
+            LLVector3 delta;
+            delta.setVec(regionp->getOriginGlobal() - mRegionp->getOriginGlobal());
+
+            setPositionAgent(getPositionAgent() - delta);
+
+            LLVector3 camera_position_agent = LLViewerCamera::getInstance()->getOrigin();
+            LLViewerCamera::getInstance()->setOrigin(camera_position_agent - delta);
+
+            // Update all of the regions.
+            LLWorld::getInstance()->updateAgentOffset(agent_offset_global);
+
+            // Hack to keep sky in the agent's region, otherwise it may get deleted - DJS 08/02/02
+            // *TODO: possibly refactor into gSky->setAgentRegion(regionp)? -Brad
+            if (gSky.mVOSkyp)
+            {
+                gSky.mVOSkyp->setRegion(regionp);
+            }
+
             if (regionp->capabilitiesReceived())
             {
                 regionp->requestSimulatorFeatures();
@@ -1126,22 +1126,22 @@ void LLAgent::setRegion(LLViewerRegion *regionp)
                 regionp->setCapabilitiesReceivedCallback(LLAgent::capabilityReceivedCallback);
             }
 
-		}
-		else
-		{
-			// First time initialization.
-			// We've changed regions, we're now going to change our agent coordinate frame.
-			mAgentOriginGlobal = regionp->getOriginGlobal();
+        }
+        else
+        {
+            // First time initialization.
+            // We've changed regions, we're now going to change our agent coordinate frame.
+            mAgentOriginGlobal = regionp->getOriginGlobal();
 
-			LLVector3 delta;
-			delta.setVec(regionp->getOriginGlobal());
+            LLVector3 delta;
+            delta.setVec(regionp->getOriginGlobal());
 
-			setPositionAgent(getPositionAgent() - delta);
-			LLVector3 camera_position_agent = LLViewerCamera::getInstance()->getOrigin();
-			LLViewerCamera::getInstance()->setOrigin(camera_position_agent - delta);
+            setPositionAgent(getPositionAgent() - delta);
+            LLVector3 camera_position_agent = LLViewerCamera::getInstance()->getOrigin();
+            LLViewerCamera::getInstance()->setOrigin(camera_position_agent - delta);
 
-			// Update all of the regions.
-			LLWorld::getInstance()->updateAgentOffset(mAgentOriginGlobal);
+            // Update all of the regions.
+            LLWorld::getInstance()->updateAgentOffset(mAgentOriginGlobal);
 
             if (regionp->capabilitiesReceived())
             {
@@ -1151,39 +1151,39 @@ void LLAgent::setRegion(LLViewerRegion *regionp)
             {
                 regionp->setCapabilitiesReceivedCallback([](const LLUUID &region_id, LLViewerRegion* regionp) {LLAppViewer::instance()->updateNameLookupUrl(regionp); });
             }
-		}
+        }
 
-		// Pass new region along to metrics components that care about this level of detail.
-		LLAppViewer::metricsUpdateRegion(regionp->getHandle());
-	}
+        // Pass new region along to metrics components that care about this level of detail.
+        LLAppViewer::metricsUpdateRegion(regionp->getHandle());
+    }
 
-	mRegionp = regionp;
+    mRegionp = regionp;
 
-	// TODO - most of what follows probably should be moved into callbacks
+    // TODO - most of what follows probably should be moved into callbacks
 
-	// Pass the region host to LLUrlEntryParcel to resolve parcel name
-	// with a server request.
-	LLUrlEntryParcel::setRegionHost(getRegionHost());
+    // Pass the region host to LLUrlEntryParcel to resolve parcel name
+    // with a server request.
+    LLUrlEntryParcel::setRegionHost(getRegionHost());
 
-	// Must shift hole-covering water object locations because local
-	// coordinate frame changed.
-	LLWorld::getInstance()->updateWaterObjects();
+    // Must shift hole-covering water object locations because local
+    // coordinate frame changed.
+    LLWorld::getInstance()->updateWaterObjects();
 
-	// keep a list of regions we've been too
-	// this is just an interesting stat, logged at the dataserver
-	// we could trake this at the dataserver side, but that's harder
-	U64 handle = regionp->getHandle();
-	mRegionsVisited.insert(handle);
+    // keep a list of regions we've been too
+    // this is just an interesting stat, logged at the dataserver
+    // we could trake this at the dataserver side, but that's harder
+    U64 handle = regionp->getHandle();
+    mRegionsVisited.insert(handle);
 
-	LLSelectMgr::getInstance()->updateSelectionCenter();
+    LLSelectMgr::getInstance()->updateSelectionCenter();
 
-//	LLFloaterMove::sUpdateFlyingStatus();
+//  LLFloaterMove::sUpdateFlyingStatus();
 // [RLVa:KB] - Checked: 2011-05-27 (RLVa-1.4.0a) | Added: RLVa-1.4.0a
-	LLFloaterMove::sUpdateMovementStatus();
+    LLFloaterMove::sUpdateMovementStatus();
 // [/RLVa:KB]
 
-	LL_DEBUGS("AgentLocation") << "Calling RegionChanged callbacks" << LL_ENDL;
-	mRegionChangedSignal();
+    LL_DEBUGS("AgentLocation") << "Calling RegionChanged callbacks" << LL_ENDL;
+    mRegionChangedSignal();
 }
 
 
@@ -1192,30 +1192,30 @@ void LLAgent::setRegion(LLViewerRegion *regionp)
 //-----------------------------------------------------------------------------
 LLViewerRegion *LLAgent::getRegion() const
 {
-	return mRegionp;
+    return mRegionp;
 }
 
 
 LLHost LLAgent::getRegionHost() const
 {
-	if (mRegionp)
-	{
-		return mRegionp->getHost();
-	}
-	else
-	{
-		return LLHost();
-	}
+    if (mRegionp)
+    {
+        return mRegionp->getHost();
+    }
+    else
+    {
+        return LLHost();
+    }
 }
 
 boost::signals2::connection LLAgent::addRegionChangedCallback(const region_changed_signal_t::slot_type& cb)
 {
-	return mRegionChangedSignal.connect(cb);
+    return mRegionChangedSignal.connect(cb);
 }
 
 void LLAgent::removeRegionChangedCallback(boost::signals2::connection callback)
 {
-	mRegionChangedSignal.disconnect(callback);
+    mRegionChangedSignal.disconnect(callback);
 }
 
 //-----------------------------------------------------------------------------
@@ -1223,7 +1223,7 @@ void LLAgent::removeRegionChangedCallback(boost::signals2::connection callback)
 //-----------------------------------------------------------------------------
 BOOL LLAgent::inPrelude()
 {
-	return mRegionp && mRegionp->isPrelude();
+    return mRegionp && mRegionp->isPrelude();
 }
 
 
@@ -1231,7 +1231,7 @@ const std::string& LLAgent::getRegionCapability(std::string_view name) const
 {
     if (!mRegionp)
         return LLStringUtil::null;
-    
+
     return mRegionp->getCapability(name);
 }
 
@@ -1242,7 +1242,7 @@ const std::string& LLAgent::getRegionCapability(std::string_view name) const
 
 BOOL LLAgent::canManageEstate() const
 {
-	return mRegionp && mRegionp->canManageEstate();
+    return mRegionp && mRegionp->canManageEstate();
 }
 
 //-----------------------------------------------------------------------------
@@ -1250,17 +1250,17 @@ BOOL LLAgent::canManageEstate() const
 //-----------------------------------------------------------------------------
 void LLAgent::sendMessage()
 {
-	if (gDisconnected)
-	{
-		LL_WARNS() << "Trying to send message when disconnected!" << LL_ENDL;
-		return;
-	}
-	if (!mRegionp)
-	{
-		LL_ERRS() << "No region for agent yet!" << LL_ENDL;
-		return;
-	}
-	gMessageSystem->sendMessage(mRegionp->getHost());
+    if (gDisconnected)
+    {
+        LL_WARNS() << "Trying to send message when disconnected!" << LL_ENDL;
+        return;
+    }
+    if (!mRegionp)
+    {
+        LL_ERRS() << "No region for agent yet!" << LL_ENDL;
+        return;
+    }
+    gMessageSystem->sendMessage(mRegionp->getHost());
 }
 
 
@@ -1269,17 +1269,17 @@ void LLAgent::sendMessage()
 //-----------------------------------------------------------------------------
 void LLAgent::sendReliableMessage()
 {
-	if (gDisconnected)
-	{
-		LL_DEBUGS() << "Trying to send message when disconnected!" << LL_ENDL;
-		return;
-	}
-	if (!mRegionp)
-	{
-		LL_DEBUGS() << "LLAgent::sendReliableMessage No region for agent yet, not sending message!" << LL_ENDL;
-		return;
-	}
-	gMessageSystem->sendReliable(mRegionp->getHost());
+    if (gDisconnected)
+    {
+        LL_DEBUGS() << "Trying to send message when disconnected!" << LL_ENDL;
+        return;
+    }
+    if (!mRegionp)
+    {
+        LL_DEBUGS() << "LLAgent::sendReliableMessage No region for agent yet, not sending message!" << LL_ENDL;
+        return;
+    }
+    gMessageSystem->sendReliable(mRegionp->getHost());
 }
 
 //-----------------------------------------------------------------------------
@@ -1287,14 +1287,14 @@ void LLAgent::sendReliableMessage()
 //-----------------------------------------------------------------------------
 LLVector3 LLAgent::getVelocity() const
 {
-	if (isAgentAvatarValid())
-	{
-		return gAgentAvatarp->getVelocity();
-	}
-	else
-	{
-		return LLVector3::zero;
-	}
+    if (isAgentAvatarValid())
+    {
+        return gAgentAvatarp->getVelocity();
+    }
+    else
+    {
+        return LLVector3::zero;
+    }
 }
 
 
@@ -1303,35 +1303,35 @@ LLVector3 LLAgent::getVelocity() const
 //-----------------------------------------------------------------------------
 void LLAgent::setPositionAgent(const LLVector3 &pos_agent)
 {
-	if (!pos_agent.isFinite())
-	{
-		LL_ERRS() << "setPositionAgent is not a number" << LL_ENDL;
-	}
+    if (!pos_agent.isFinite())
+    {
+        LL_ERRS() << "setPositionAgent is not a number" << LL_ENDL;
+    }
 
-	if (isAgentAvatarValid() && gAgentAvatarp->getParent())
-	{
-		LLVector3 pos_agent_sitting;
-		LLVector3d pos_agent_d;
-		LLViewerObject *parent = (LLViewerObject*)gAgentAvatarp->getParent();
+    if (isAgentAvatarValid() && gAgentAvatarp->getParent())
+    {
+        LLVector3 pos_agent_sitting;
+        LLVector3d pos_agent_d;
+        LLViewerObject *parent = (LLViewerObject*)gAgentAvatarp->getParent();
 
-		pos_agent_sitting = gAgentAvatarp->getPosition() * parent->getRotation() + parent->getPositionAgent();
-		pos_agent_d.setVec(pos_agent_sitting);
+        pos_agent_sitting = gAgentAvatarp->getPosition() * parent->getRotation() + parent->getPositionAgent();
+        pos_agent_d.setVec(pos_agent_sitting);
 
-		mFrameAgent.setOrigin(pos_agent_sitting);
-		mPositionGlobal = pos_agent_d + mAgentOriginGlobal;
-	}
-	else
-	{
-		mFrameAgent.setOrigin(pos_agent);
+        mFrameAgent.setOrigin(pos_agent_sitting);
+        mPositionGlobal = pos_agent_d + mAgentOriginGlobal;
+    }
+    else
+    {
+        mFrameAgent.setOrigin(pos_agent);
 
-		LLVector3d pos_agent_d;
-		pos_agent_d.setVec(pos_agent);
-		mPositionGlobal = pos_agent_d + mAgentOriginGlobal;
-	}
+        LLVector3d pos_agent_d;
+        pos_agent_d.setVec(pos_agent);
+        mPositionGlobal = pos_agent_d + mAgentOriginGlobal;
+    }
 
     if (((mLastTestGlobal - mPositionGlobal).lengthSquared() > 1.0) && !mOnPositionChanged.empty())
     {   // If the position has changed my more than 1 meter since the last time we triggered.
-        // filters out some noise. 
+        // filters out some noise.
         mLastTestGlobal = mPositionGlobal;
         mOnPositionChanged(mFrameAgent.getOrigin(), mPositionGlobal);
     }
@@ -1342,16 +1342,16 @@ void LLAgent::setPositionAgent(const LLVector3 &pos_agent)
 //-----------------------------------------------------------------------------
 const LLVector3d &LLAgent::getPositionGlobal() const
 {
-	if (isAgentAvatarValid() && !gAgentAvatarp->mDrawable.isNull())
-	{
-		mPositionGlobal = getPosGlobalFromAgent(gAgentAvatarp->getRenderPosition());
-	}
-	else
-	{
-		mPositionGlobal = getPosGlobalFromAgent(mFrameAgent.getOrigin());
-	}
+    if (isAgentAvatarValid() && !gAgentAvatarp->mDrawable.isNull())
+    {
+        mPositionGlobal = getPosGlobalFromAgent(gAgentAvatarp->getRenderPosition());
+    }
+    else
+    {
+        mPositionGlobal = getPosGlobalFromAgent(mFrameAgent.getOrigin());
+    }
 
-	return mPositionGlobal;
+    return mPositionGlobal;
 }
 
 //-----------------------------------------------------------------------------
@@ -1359,20 +1359,20 @@ const LLVector3d &LLAgent::getPositionGlobal() const
 //-----------------------------------------------------------------------------
 const LLVector3 &LLAgent::getPositionAgent()
 {
-	if (isAgentAvatarValid())
-	{
-		if(gAgentAvatarp->mDrawable.isNull())
-		{
-			mFrameAgent.setOrigin(gAgentAvatarp->getPositionAgent());
-		}
-		else
-	{
-		mFrameAgent.setOrigin(gAgentAvatarp->getRenderPosition());	
-	}
-	}
+    if (isAgentAvatarValid())
+    {
+        if(gAgentAvatarp->mDrawable.isNull())
+        {
+            mFrameAgent.setOrigin(gAgentAvatarp->getPositionAgent());
+        }
+        else
+    {
+        mFrameAgent.setOrigin(gAgentAvatarp->getRenderPosition());
+    }
+    }
 
 
-	return mFrameAgent.getOrigin();
+    return mFrameAgent.getOrigin();
 }
 
 boost::signals2::connection LLAgent::whenPositionChanged(position_signal_t::slot_type fn)
@@ -1386,7 +1386,7 @@ boost::signals2::connection LLAgent::whenPositionChanged(position_signal_t::slot
 //-----------------------------------------------------------------------------
 S32 LLAgent::getRegionsVisited() const
 {
-	return mRegionsVisited.size();
+    return mRegionsVisited.size();
 }
 
 //-----------------------------------------------------------------------------
@@ -1394,7 +1394,7 @@ S32 LLAgent::getRegionsVisited() const
 //-----------------------------------------------------------------------------
 F64 LLAgent::getDistanceTraveled() const
 {
-	return mDistanceTraveled;
+    return mDistanceTraveled;
 }
 
 
@@ -1403,9 +1403,9 @@ F64 LLAgent::getDistanceTraveled() const
 //-----------------------------------------------------------------------------
 LLVector3 LLAgent::getPosAgentFromGlobal(const LLVector3d &pos_global) const
 {
-	LLVector3 pos_agent;
-	pos_agent.setVec(pos_global - mAgentOriginGlobal);
-	return pos_agent;
+    LLVector3 pos_agent;
+    pos_agent.setVec(pos_global - mAgentOriginGlobal);
+    return pos_agent;
 }
 
 
@@ -1414,19 +1414,19 @@ LLVector3 LLAgent::getPosAgentFromGlobal(const LLVector3d &pos_global) const
 //-----------------------------------------------------------------------------
 LLVector3d LLAgent::getPosGlobalFromAgent(const LLVector3 &pos_agent) const
 {
-	LLVector3d pos_agent_d;
-	pos_agent_d.setVec(pos_agent);
-	return pos_agent_d + mAgentOriginGlobal;
+    LLVector3d pos_agent_d;
+    pos_agent_d.setVec(pos_agent);
+    return pos_agent_d + mAgentOriginGlobal;
 }
 
 void LLAgent::sitDown()
 {
 // [RLVa:KB] - Checked: RLVa-1.2.1
-	if (!RlvActions::canGroundSit())
-		return;
+    if (!RlvActions::canGroundSit())
+        return;
 // [/RLVa:KB]
 
-	setControlFlags(AGENT_CONTROL_SIT_ON_GROUND);
+    setControlFlags(AGENT_CONTROL_SIT_ON_GROUND);
 }
 
 
@@ -1435,7 +1435,7 @@ void LLAgent::sitDown()
 //-----------------------------------------------------------------------------
 void LLAgent::resetAxes()
 {
-	mFrameAgent.resetAxes();
+    mFrameAgent.resetAxes();
 }
 
 
@@ -1446,61 +1446,61 @@ void LLAgent::resetAxes()
 //-----------------------------------------------------------------------------
 void LLAgent::resetAxes(const LLVector3 &look_at)
 {
-	LLVector3	skyward = getReferenceUpVector();
+    LLVector3   skyward = getReferenceUpVector();
 
-	// if look_at has zero length, fail
-	// if look_at and skyward are parallel, fail
-	//
-	// Test both of these conditions with a cross product.
-	LLVector3 cross(look_at % skyward);
-	if (cross.isNull())
-	{
-		LL_INFOS() << "LLAgent::resetAxes cross-product is zero" << LL_ENDL;
-		return;
-	}
+    // if look_at has zero length, fail
+    // if look_at and skyward are parallel, fail
+    //
+    // Test both of these conditions with a cross product.
+    LLVector3 cross(look_at % skyward);
+    if (cross.isNull())
+    {
+        LL_INFOS() << "LLAgent::resetAxes cross-product is zero" << LL_ENDL;
+        return;
+    }
 
-	// Make sure look_at and skyward are not parallel
-	// and neither are zero length
-	LLVector3 left(skyward % look_at);
-	LLVector3 up(look_at % left);
+    // Make sure look_at and skyward are not parallel
+    // and neither are zero length
+    LLVector3 left(skyward % look_at);
+    LLVector3 up(look_at % left);
 
-	mFrameAgent.setAxes(look_at, left, up);
+    mFrameAgent.setAxes(look_at, left, up);
 }
 
 
 //-----------------------------------------------------------------------------
 // rotate()
 //-----------------------------------------------------------------------------
-void LLAgent::rotate(F32 angle, const LLVector3 &axis) 
-{ 
-	mFrameAgent.rotate(angle, axis); 
+void LLAgent::rotate(F32 angle, const LLVector3 &axis)
+{
+    mFrameAgent.rotate(angle, axis);
 }
 
 
 //-----------------------------------------------------------------------------
 // rotate()
 //-----------------------------------------------------------------------------
-void LLAgent::rotate(F32 angle, F32 x, F32 y, F32 z) 
-{ 
-	mFrameAgent.rotate(angle, x, y, z); 
+void LLAgent::rotate(F32 angle, F32 x, F32 y, F32 z)
+{
+    mFrameAgent.rotate(angle, x, y, z);
 }
 
 
 //-----------------------------------------------------------------------------
 // rotate()
 //-----------------------------------------------------------------------------
-void LLAgent::rotate(const LLMatrix3 &matrix) 
-{ 
-	mFrameAgent.rotate(matrix); 
+void LLAgent::rotate(const LLMatrix3 &matrix)
+{
+    mFrameAgent.rotate(matrix);
 }
 
 
 //-----------------------------------------------------------------------------
 // rotate()
 //-----------------------------------------------------------------------------
-void LLAgent::rotate(const LLQuaternion &quaternion) 
-{ 
-	mFrameAgent.rotate(quaternion); 
+void LLAgent::rotate(const LLQuaternion &quaternion)
+{
+    mFrameAgent.rotate(quaternion);
 }
 
 
@@ -1509,27 +1509,27 @@ void LLAgent::rotate(const LLQuaternion &quaternion)
 //-----------------------------------------------------------------------------
 LLVector3 LLAgent::getReferenceUpVector()
 {
-	// this vector is in the coordinate frame of the avatar's parent object, or the world if none
-	LLVector3 up_vector = LLVector3::z_axis;
-	if (isAgentAvatarValid() && 
-		gAgentAvatarp->getParent() &&
-		gAgentAvatarp->mDrawable.notNull())
-	{
-		U32 camera_mode = gAgentCamera.getCameraAnimating() ? gAgentCamera.getLastCameraMode() : gAgentCamera.getCameraMode();
-		// and in third person...
-		if (camera_mode == CAMERA_MODE_THIRD_PERSON)
-		{
-			// make the up vector point to the absolute +z axis
-			up_vector = up_vector * ~((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation();
-		}
-		else if (camera_mode == CAMERA_MODE_MOUSELOOK)
-		{
-			// make the up vector point to the avatar's +z axis
-			up_vector = up_vector * gAgentAvatarp->mDrawable->getRotation();
-		}
-	}
-
-	return up_vector;
+    // this vector is in the coordinate frame of the avatar's parent object, or the world if none
+    LLVector3 up_vector = LLVector3::z_axis;
+    if (isAgentAvatarValid() &&
+        gAgentAvatarp->getParent() &&
+        gAgentAvatarp->mDrawable.notNull())
+    {
+        U32 camera_mode = gAgentCamera.getCameraAnimating() ? gAgentCamera.getLastCameraMode() : gAgentCamera.getCameraMode();
+        // and in third person...
+        if (camera_mode == CAMERA_MODE_THIRD_PERSON)
+        {
+            // make the up vector point to the absolute +z axis
+            up_vector = up_vector * ~((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation();
+        }
+        else if (camera_mode == CAMERA_MODE_MOUSELOOK)
+        {
+            // make the up vector point to the avatar's +z axis
+            up_vector = up_vector * gAgentAvatarp->mDrawable->getRotation();
+        }
+    }
+
+    return up_vector;
 }
 
 
@@ -1539,44 +1539,44 @@ LLVector3 LLAgent::getReferenceUpVector()
 //-----------------------------------------------------------------------------
 void LLAgent::pitch(F32 angle)
 {
-	// don't let user pitch if pointed almost all the way down or up
+    // don't let user pitch if pointed almost all the way down or up
 
-	// A dot B = mag(A) * mag(B) * cos(angle between A and B)
-	// so... cos(angle between A and B) = A dot B / mag(A) / mag(B)
-	//                                  = A dot B for unit vectors
+    // A dot B = mag(A) * mag(B) * cos(angle between A and B)
+    // so... cos(angle between A and B) = A dot B / mag(A) / mag(B)
+    //                                  = A dot B for unit vectors
 
-	LLVector3 skyward = getReferenceUpVector();
+    LLVector3 skyward = getReferenceUpVector();
 
-	static LLCachedControl<bool> useRealisticMouselook(gSavedSettings, "AlchemyRealisticMouselook", false);
-	const bool in_mouselook = gAgentCamera.cameraMouselook();
+    static LLCachedControl<bool> useRealisticMouselook(gSavedSettings, "AlchemyRealisticMouselook", false);
+    const bool in_mouselook = gAgentCamera.cameraMouselook();
 
-	// clamp pitch to limits
-	if (angle >= 0.f)
-	{
-		const F32 look_down_limit = (in_mouselook && useRealisticMouselook ? 160.f : 179.f) * DEG_TO_RAD;
-		F32 angle_from_skyward = acos(mFrameAgent.getAtAxis() * skyward);
-		if (angle_from_skyward + angle > look_down_limit)
-		{
-			angle = look_down_limit - angle_from_skyward;
-		}
-	}
-	else if (angle < 0.f)
-	{
-		const F32 look_up_limit = (in_mouselook && useRealisticMouselook ? 20.f : 5.f) * DEG_TO_RAD;
-		const LLVector3& viewer_camera_pos = LLViewerCamera::getInstance()->getOrigin();
-		LLVector3 agent_focus_pos = getPosAgentFromGlobal(gAgentCamera.calcFocusPositionTargetGlobal());
-		LLVector3 look_dir = agent_focus_pos - viewer_camera_pos;
-		F32 angle_from_skyward = angle_between(look_dir, skyward);
-		if (angle_from_skyward + angle < look_up_limit)
-		{
-			angle = look_up_limit - angle_from_skyward;
-		}
-	}
+    // clamp pitch to limits
+    if (angle >= 0.f)
+    {
+        const F32 look_down_limit = (in_mouselook && useRealisticMouselook ? 160.f : 179.f) * DEG_TO_RAD;
+        F32 angle_from_skyward = acos(mFrameAgent.getAtAxis() * skyward);
+        if (angle_from_skyward + angle > look_down_limit)
+        {
+            angle = look_down_limit - angle_from_skyward;
+        }
+    }
+    else if (angle < 0.f)
+    {
+        const F32 look_up_limit = (in_mouselook && useRealisticMouselook ? 20.f : 5.f) * DEG_TO_RAD;
+        const LLVector3& viewer_camera_pos = LLViewerCamera::getInstance()->getOrigin();
+        LLVector3 agent_focus_pos = getPosAgentFromGlobal(gAgentCamera.calcFocusPositionTargetGlobal());
+        LLVector3 look_dir = agent_focus_pos - viewer_camera_pos;
+        F32 angle_from_skyward = angle_between(look_dir, skyward);
+        if (angle_from_skyward + angle < look_up_limit)
+        {
+            angle = look_up_limit - angle_from_skyward;
+        }
+    }
 
-	if (fabs(angle) > 1e-4)
-	{
-		mFrameAgent.pitch(angle);
-	}
+    if (fabs(angle) > 1e-4)
+    {
+        mFrameAgent.pitch(angle);
+    }
 }
 
 
@@ -1585,7 +1585,7 @@ void LLAgent::pitch(F32 angle)
 //-----------------------------------------------------------------------------
 void LLAgent::roll(F32 angle)
 {
-	mFrameAgent.roll(angle);
+    mFrameAgent.roll(angle);
 }
 
 
@@ -1594,10 +1594,10 @@ void LLAgent::roll(F32 angle)
 //-----------------------------------------------------------------------------
 void LLAgent::yaw(F32 angle)
 {
-	if (!rotateGrabbed())
-	{
-		mFrameAgent.rotate(angle, getReferenceUpVector());
-	}
+    if (!rotateGrabbed())
+    {
+        mFrameAgent.rotate(angle, getReferenceUpVector());
+    }
 }
 
 
@@ -1607,7 +1607,7 @@ void LLAgent::yaw(F32 angle)
 //-----------------------------------------------------------------------------
 LLQuaternion LLAgent::getQuat() const
 {
-	return mFrameAgent.getQuaternion();
+    return mFrameAgent.getQuaternion();
 }
 
 //-----------------------------------------------------------------------------
@@ -1615,14 +1615,14 @@ LLQuaternion LLAgent::getQuat() const
 //-----------------------------------------------------------------------------
 U32 LLAgent::getControlFlags()
 {
-	if (LLAgent::mIgnorePrejump)
-	{
-		return mControlFlags | AGENT_CONTROL_FINISH_ANIM;
-	}
-	else
-	{
-		return mControlFlags;
-	}
+    if (LLAgent::mIgnorePrejump)
+    {
+        return mControlFlags | AGENT_CONTROL_FINISH_ANIM;
+    }
+    else
+    {
+        return mControlFlags;
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1630,8 +1630,8 @@ U32 LLAgent::getControlFlags()
 //-----------------------------------------------------------------------------
 void LLAgent::setControlFlags(U32 mask)
 {
-	mControlFlags |= mask;
-	mbFlagsDirty = TRUE;
+    mControlFlags |= mask;
+    mbFlagsDirty = TRUE;
 }
 
 
@@ -1640,12 +1640,12 @@ void LLAgent::setControlFlags(U32 mask)
 //-----------------------------------------------------------------------------
 void LLAgent::clearControlFlags(U32 mask)
 {
-	U32 old_flags = mControlFlags;
-	mControlFlags &= ~mask;
-	if (old_flags != mControlFlags)
-	{
-		mbFlagsDirty = TRUE;
-	}
+    U32 old_flags = mControlFlags;
+    mControlFlags &= ~mask;
+    if (old_flags != mControlFlags)
+    {
+        mbFlagsDirty = TRUE;
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1653,7 +1653,7 @@ void LLAgent::clearControlFlags(U32 mask)
 //-----------------------------------------------------------------------------
 BOOL LLAgent::controlFlagsDirty() const
 {
-	return mbFlagsDirty;
+    return mbFlagsDirty;
 }
 
 //-----------------------------------------------------------------------------
@@ -1661,7 +1661,7 @@ BOOL LLAgent::controlFlagsDirty() const
 //-----------------------------------------------------------------------------
 void LLAgent::enableControlFlagReset()
 {
-	mbFlagsNeedReset = TRUE;
+    mbFlagsNeedReset = TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -1669,14 +1669,14 @@ void LLAgent::enableControlFlagReset()
 //-----------------------------------------------------------------------------
 void LLAgent::resetControlFlags()
 {
-	if (mbFlagsNeedReset)
-	{
-		mbFlagsNeedReset = FALSE;
-		mbFlagsDirty = FALSE;
-		// reset all of the ephemeral flags
-		// some flags are managed elsewhere
-		mControlFlags &= AGENT_CONTROL_AWAY | AGENT_CONTROL_FLY | AGENT_CONTROL_MOUSELOOK;
-	}
+    if (mbFlagsNeedReset)
+    {
+        mbFlagsNeedReset = FALSE;
+        mbFlagsDirty = FALSE;
+        // reset all of the ephemeral flags
+        // some flags are managed elsewhere
+        mControlFlags &= AGENT_CONTROL_AWAY | AGENT_CONTROL_FLY | AGENT_CONTROL_MOUSELOOK;
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1684,18 +1684,18 @@ void LLAgent::resetControlFlags()
 //-----------------------------------------------------------------------------
 void LLAgent::setAFK()
 {
-	if (gNonInteractive || !gAgent.getRegion())
-	{
-		// Don't set AFK if we're not talking to a region yet.
-		return;
-	}
+    if (gNonInteractive || !gAgent.getRegion())
+    {
+        // Don't set AFK if we're not talking to a region yet.
+        return;
+    }
 
-	if (!(mControlFlags & AGENT_CONTROL_AWAY))
-	{
-		sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_START);
-		setControlFlags(AGENT_CONTROL_AWAY | AGENT_CONTROL_STOP);
-		gAwayTimer.start();
-	}
+    if (!(mControlFlags & AGENT_CONTROL_AWAY))
+    {
+        sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_START);
+        setControlFlags(AGENT_CONTROL_AWAY | AGENT_CONTROL_STOP);
+        gAwayTimer.start();
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1703,17 +1703,17 @@ void LLAgent::setAFK()
 //-----------------------------------------------------------------------------
 void LLAgent::clearAFK()
 {
-	gAwayTriggerTimer.reset();
+    gAwayTriggerTimer.reset();
 
-	// Gods can sometimes get into away state (via gestures)
-	// without setting the appropriate control flag. JC
-	if (mControlFlags & AGENT_CONTROL_AWAY
-		|| (isAgentAvatarValid()
-			&& (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AWAY) != gAgentAvatarp->mSignaledAnimations.end())))
-	{
-		sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_STOP);
-		clearControlFlags(AGENT_CONTROL_AWAY);
-	}
+    // Gods can sometimes get into away state (via gestures)
+    // without setting the appropriate control flag. JC
+    if (mControlFlags & AGENT_CONTROL_AWAY
+        || (isAgentAvatarValid()
+            && (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AWAY) != gAgentAvatarp->mSignaledAnimations.end())))
+    {
+        sendAnimationRequest(ANIM_AGENT_AWAY, ANIM_REQUEST_STOP);
+        clearControlFlags(AGENT_CONTROL_AWAY);
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1721,7 +1721,7 @@ void LLAgent::clearAFK()
 //-----------------------------------------------------------------------------
 BOOL LLAgent::getAFK() const
 {
-	return (mControlFlags & AGENT_CONTROL_AWAY) != 0;
+    return (mControlFlags & AGENT_CONTROL_AWAY) != 0;
 }
 
 //-----------------------------------------------------------------------------
@@ -1729,15 +1729,15 @@ BOOL LLAgent::getAFK() const
 //-----------------------------------------------------------------------------
 void LLAgent::setDoNotDisturb(bool pIsDoNotDisturb)
 {
-	bool isDoNotDisturbSwitchedOff = (mIsDoNotDisturb && !pIsDoNotDisturb);
-	mIsDoNotDisturb = pIsDoNotDisturb;
-	sendAnimationRequest(ANIM_AGENT_DO_NOT_DISTURB, (pIsDoNotDisturb ? ANIM_REQUEST_START : ANIM_REQUEST_STOP));
-	LLNotificationsUI::LLChannelManager::getInstance()->muteAllChannels(pIsDoNotDisturb);
-	if (isDoNotDisturbSwitchedOff)
-	{
-		LLDoNotDisturbNotificationStorage::getInstance()->updateNotifications();
-	}
-	gIMMgr->updateDNDMessageStatus();
+    bool isDoNotDisturbSwitchedOff = (mIsDoNotDisturb && !pIsDoNotDisturb);
+    mIsDoNotDisturb = pIsDoNotDisturb;
+    sendAnimationRequest(ANIM_AGENT_DO_NOT_DISTURB, (pIsDoNotDisturb ? ANIM_REQUEST_START : ANIM_REQUEST_STOP));
+    LLNotificationsUI::LLChannelManager::getInstance()->muteAllChannels(pIsDoNotDisturb);
+    if (isDoNotDisturbSwitchedOff)
+    {
+        LLDoNotDisturbNotificationStorage::getInstance()->updateNotifications();
+    }
+    gIMMgr->updateDNDMessageStatus();
 }
 
 //-----------------------------------------------------------------------------
@@ -1745,7 +1745,7 @@ void LLAgent::setDoNotDisturb(bool pIsDoNotDisturb)
 //-----------------------------------------------------------------------------
 bool LLAgent::isDoNotDisturb() const
 {
-	return mIsDoNotDisturb;
+    return mIsDoNotDisturb;
 }
 
 //-----------------------------------------------------------------------------
@@ -1753,9 +1753,9 @@ bool LLAgent::isDoNotDisturb() const
 //-----------------------------------------------------------------------------
 void LLAgent::setRejectTeleportOffers(bool pIsRejectTeleportOffers)
 {
-	LL_INFOS() << "Setting rejecting teleport offers mode to " << pIsRejectTeleportOffers << LL_ENDL;
-	mIsRejectTeleportOffers = pIsRejectTeleportOffers;
-	gSavedPerAccountSettings.setBOOL("ALRejectTeleportOffersMode", pIsRejectTeleportOffers);
+    LL_INFOS() << "Setting rejecting teleport offers mode to " << pIsRejectTeleportOffers << LL_ENDL;
+    mIsRejectTeleportOffers = pIsRejectTeleportOffers;
+    gSavedPerAccountSettings.setBOOL("ALRejectTeleportOffersMode", pIsRejectTeleportOffers);
 }
 
 //-----------------------------------------------------------------------------
@@ -1763,7 +1763,7 @@ void LLAgent::setRejectTeleportOffers(bool pIsRejectTeleportOffers)
 //-----------------------------------------------------------------------------
 bool LLAgent::isRejectTeleportOffers() const
 {
-	return mIsRejectTeleportOffers;
+    return mIsRejectTeleportOffers;
 }
 
 //-----------------------------------------------------------------------------
@@ -1804,160 +1804,160 @@ BOOL LLAgent::getRejectFriendshipRequests() const
 // startAutoPilotGlobal()
 //-----------------------------------------------------------------------------
 void LLAgent::startAutoPilotGlobal(
-	const LLVector3d &target_global,
-	const std::string& behavior_name,
-	const LLQuaternion *target_rotation,
-	void (*finish_callback)(BOOL, void *),
-	void *callback_data,
-	F32 stop_distance,
-	F32 rot_threshold,
-	BOOL allow_flying)
-{
-	if (!isAgentAvatarValid())
-	{
-		return;
-	}
+    const LLVector3d &target_global,
+    const std::string& behavior_name,
+    const LLQuaternion *target_rotation,
+    void (*finish_callback)(BOOL, void *),
+    void *callback_data,
+    F32 stop_distance,
+    F32 rot_threshold,
+    BOOL allow_flying)
+{
+    if (!isAgentAvatarValid())
+    {
+        return;
+    }
 
     if (target_global.isExactlyZero())
     {
         LL_WARNS() << "Canceling attempt to start autopilot towards invalid position" << LL_ENDL;
         return;
     }
-	
-	// Are there any pending callbacks from previous auto pilot requests?
-	if (mAutoPilotFinishedCallback)
-	{
-		mAutoPilotFinishedCallback(dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance, mAutoPilotCallbackData);
-	}
-
-	mAutoPilotFinishedCallback = finish_callback;
-	mAutoPilotCallbackData = callback_data;
-	mAutoPilotRotationThreshold = rot_threshold;
-	mAutoPilotBehaviorName = behavior_name;
-	mAutoPilotAllowFlying = allow_flying;
-
-	LLVector3d delta_pos( target_global );
-	delta_pos -= getPositionGlobal();
-	F64 distance = delta_pos.magVec();
-	LLVector3d trace_target = target_global;
-
-	trace_target.mdV[VZ] -= 10.f;
-
-	LLVector3d intersection;
-	LLVector3 normal;
-	LLViewerObject *hit_obj;
-	F32 heightDelta = LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, trace_target, intersection, normal, &hit_obj);
-
-	if (stop_distance > 0.f)
-	{
-		mAutoPilotStopDistance = stop_distance;
-	}
-	else
-	{
-		// Guess at a reasonable stop distance.
-		mAutoPilotStopDistance = (F32) sqrt( distance );
-		if (mAutoPilotStopDistance < 0.5f) 
-		{
-			mAutoPilotStopDistance = 0.5f;
-		}
-	}
-
-	if (mAutoPilotAllowFlying)
-	{
-		mAutoPilotFlyOnStop = getFlying();
-	}
-	else
-	{
-		mAutoPilotFlyOnStop = FALSE;
-	}
-
-	if (distance > 30.0 && mAutoPilotAllowFlying)
-	{
-		setFlying(TRUE);
-	}
-
-	if ( distance > 1.f && 
-		mAutoPilotAllowFlying &&
-		heightDelta > (sqrtf(mAutoPilotStopDistance) + 1.f))
-	{
-		setFlying(TRUE);
-		// Do not force flying for "Sit" behavior to prevent flying after pressing "Stand"
-		// from an object. See EXT-1655.
-		if ("Sit" != mAutoPilotBehaviorName)
-			mAutoPilotFlyOnStop = TRUE;
-	}
-
-	mAutoPilot = TRUE;
-	setAutoPilotTargetGlobal(target_global);
-
-	if (target_rotation)
-	{
-		mAutoPilotUseRotation = TRUE;
-		mAutoPilotTargetFacing = LLVector3::x_axis * *target_rotation;
-		mAutoPilotTargetFacing.mV[VZ] = 0.f;
-		mAutoPilotTargetFacing.normalize();
-	}
-	else
-	{
-		mAutoPilotUseRotation = FALSE;
-	}
-
-	mAutoPilotNoProgressFrameCount = 0;
-}
-
-
-//-----------------------------------------------------------------------------
-// setAutoPilotTargetGlobal
-//-----------------------------------------------------------------------------
-void LLAgent::setAutoPilotTargetGlobal(const LLVector3d &target_global)
-{
-	if (mAutoPilot)
-	{
-		mAutoPilotTargetGlobal = target_global;
-
-		// trace ray down to find height of destination from ground
-		LLVector3d traceEndPt = target_global;
-		traceEndPt.mdV[VZ] -= 20.f;
 
-		LLVector3d targetOnGround;
-		LLVector3 groundNorm;
-		LLViewerObject *obj;
+    // Are there any pending callbacks from previous auto pilot requests?
+    if (mAutoPilotFinishedCallback)
+    {
+        mAutoPilotFinishedCallback(dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance, mAutoPilotCallbackData);
+    }
 
-		LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, traceEndPt, targetOnGround, groundNorm, &obj);
-		// Note: this might malfunction for sitting agent, since pelvis stays same, but agent's position becomes lower
-		// But for autopilot to work we assume that agent is standing and ready to go.
-		F64 target_height = llmax((F64)gAgentAvatarp->getPelvisToFoot(), target_global.mdV[VZ] - targetOnGround.mdV[VZ]);
+    mAutoPilotFinishedCallback = finish_callback;
+    mAutoPilotCallbackData = callback_data;
+    mAutoPilotRotationThreshold = rot_threshold;
+    mAutoPilotBehaviorName = behavior_name;
+    mAutoPilotAllowFlying = allow_flying;
 
-		// clamp z value of target to minimum height above ground
-		mAutoPilotTargetGlobal.mdV[VZ] = targetOnGround.mdV[VZ] + target_height;
-		mAutoPilotTargetDist = (F32)dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal);
-	}
-}
+    LLVector3d delta_pos( target_global );
+    delta_pos -= getPositionGlobal();
+    F64 distance = delta_pos.magVec();
+    LLVector3d trace_target = target_global;
 
-//-----------------------------------------------------------------------------
-// startFollowPilot()
-//-----------------------------------------------------------------------------
-void LLAgent::startFollowPilot(const LLUUID &leader_id, BOOL allow_flying, F32 stop_distance)
-{
-	mLeaderID = leader_id;
-	if ( mLeaderID.isNull() ) return;
+    trace_target.mdV[VZ] -= 10.f;
 
-	LLViewerObject* object = gObjectList.findObject(mLeaderID);
-	if (!object) 
-	{
-		mLeaderID = LLUUID::null;
-		return;
-	}
+    LLVector3d intersection;
+    LLVector3 normal;
+    LLViewerObject *hit_obj;
+    F32 heightDelta = LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, trace_target, intersection, normal, &hit_obj);
 
-	startAutoPilotGlobal(object->getPositionGlobal(), 
-						 std::string(),	// behavior_name
-						 NULL,			// target_rotation
-						 NULL,			// finish_callback
-						 NULL,			// callback_data
-						 stop_distance,
-						 0.03f,			// rotation_threshold
-						 allow_flying);
-}
+    if (stop_distance > 0.f)
+    {
+        mAutoPilotStopDistance = stop_distance;
+    }
+    else
+    {
+        // Guess at a reasonable stop distance.
+        mAutoPilotStopDistance = (F32) sqrt( distance );
+        if (mAutoPilotStopDistance < 0.5f)
+        {
+            mAutoPilotStopDistance = 0.5f;
+        }
+    }
+
+    if (mAutoPilotAllowFlying)
+    {
+        mAutoPilotFlyOnStop = getFlying();
+    }
+    else
+    {
+        mAutoPilotFlyOnStop = FALSE;
+    }
+
+    if (distance > 30.0 && mAutoPilotAllowFlying)
+    {
+        setFlying(TRUE);
+    }
+
+    if ( distance > 1.f &&
+        mAutoPilotAllowFlying &&
+        heightDelta > (sqrtf(mAutoPilotStopDistance) + 1.f))
+    {
+        setFlying(TRUE);
+        // Do not force flying for "Sit" behavior to prevent flying after pressing "Stand"
+        // from an object. See EXT-1655.
+        if ("Sit" != mAutoPilotBehaviorName)
+            mAutoPilotFlyOnStop = TRUE;
+    }
+
+    mAutoPilot = TRUE;
+    setAutoPilotTargetGlobal(target_global);
+
+    if (target_rotation)
+    {
+        mAutoPilotUseRotation = TRUE;
+        mAutoPilotTargetFacing = LLVector3::x_axis * *target_rotation;
+        mAutoPilotTargetFacing.mV[VZ] = 0.f;
+        mAutoPilotTargetFacing.normalize();
+    }
+    else
+    {
+        mAutoPilotUseRotation = FALSE;
+    }
+
+    mAutoPilotNoProgressFrameCount = 0;
+}
+
+
+//-----------------------------------------------------------------------------
+// setAutoPilotTargetGlobal
+//-----------------------------------------------------------------------------
+void LLAgent::setAutoPilotTargetGlobal(const LLVector3d &target_global)
+{
+    if (mAutoPilot)
+    {
+        mAutoPilotTargetGlobal = target_global;
+
+        // trace ray down to find height of destination from ground
+        LLVector3d traceEndPt = target_global;
+        traceEndPt.mdV[VZ] -= 20.f;
+
+        LLVector3d targetOnGround;
+        LLVector3 groundNorm;
+        LLViewerObject *obj;
+
+        LLWorld::getInstance()->resolveStepHeightGlobal(NULL, target_global, traceEndPt, targetOnGround, groundNorm, &obj);
+        // Note: this might malfunction for sitting agent, since pelvis stays same, but agent's position becomes lower
+        // But for autopilot to work we assume that agent is standing and ready to go.
+        F64 target_height = llmax((F64)gAgentAvatarp->getPelvisToFoot(), target_global.mdV[VZ] - targetOnGround.mdV[VZ]);
+
+        // clamp z value of target to minimum height above ground
+        mAutoPilotTargetGlobal.mdV[VZ] = targetOnGround.mdV[VZ] + target_height;
+        mAutoPilotTargetDist = (F32)dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal);
+    }
+}
+
+//-----------------------------------------------------------------------------
+// startFollowPilot()
+//-----------------------------------------------------------------------------
+void LLAgent::startFollowPilot(const LLUUID &leader_id, BOOL allow_flying, F32 stop_distance)
+{
+    mLeaderID = leader_id;
+    if ( mLeaderID.isNull() ) return;
+
+    LLViewerObject* object = gObjectList.findObject(mLeaderID);
+    if (!object)
+    {
+        mLeaderID = LLUUID::null;
+        return;
+    }
+
+    startAutoPilotGlobal(object->getPositionGlobal(),
+                         std::string(), // behavior_name
+                         NULL,          // target_rotation
+                         NULL,          // finish_callback
+                         NULL,          // callback_data
+                         stop_distance,
+                         0.03f,         // rotation_threshold
+                         allow_flying);
+}
 
 
 //-----------------------------------------------------------------------------
@@ -1965,40 +1965,40 @@ void LLAgent::startFollowPilot(const LLUUID &leader_id, BOOL allow_flying, F32 s
 //-----------------------------------------------------------------------------
 void LLAgent::stopAutoPilot(BOOL user_cancel)
 {
-	if (mAutoPilot)
-	{
-		mAutoPilot = FALSE;
-		if (mAutoPilotUseRotation && !user_cancel)
-		{
-			resetAxes(mAutoPilotTargetFacing);
-		}
-		// Restore previous flying state before invoking mAutoPilotFinishedCallback to allow
-		// callback function to change the flying state (like in near_sit_down_point()).
-		// If the user cancelled, don't change the fly state
-		if (!user_cancel)
-		{
-			setFlying(mAutoPilotFlyOnStop);
-		}
-		//NB: auto pilot can terminate for a reason other than reaching the destination
-		if (mAutoPilotFinishedCallback)
-		{
-			mAutoPilotFinishedCallback(!user_cancel && dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance, mAutoPilotCallbackData);
-			mAutoPilotFinishedCallback = NULL;
-		}
-		mLeaderID = LLUUID::null;
-
-		setControlFlags(AGENT_CONTROL_STOP);
-
-		if (user_cancel && !mAutoPilotBehaviorName.empty())
-		{
-			if (mAutoPilotBehaviorName == "Sit")
-				LL_INFOS("Agent") << "Autopilot-Sit was canceled by user action" << LL_ENDL;
-			else if (mAutoPilotBehaviorName == "Attach")
-				LLNotificationsUtil::add("CancelledAttach");
-			else
-				LLNotificationsUtil::add("Cancelled");
-		}
-	}
+    if (mAutoPilot)
+    {
+        mAutoPilot = FALSE;
+        if (mAutoPilotUseRotation && !user_cancel)
+        {
+            resetAxes(mAutoPilotTargetFacing);
+        }
+        // Restore previous flying state before invoking mAutoPilotFinishedCallback to allow
+        // callback function to change the flying state (like in near_sit_down_point()).
+        // If the user cancelled, don't change the fly state
+        if (!user_cancel)
+        {
+            setFlying(mAutoPilotFlyOnStop);
+        }
+        //NB: auto pilot can terminate for a reason other than reaching the destination
+        if (mAutoPilotFinishedCallback)
+        {
+            mAutoPilotFinishedCallback(!user_cancel && dist_vec(gAgent.getPositionGlobal(), mAutoPilotTargetGlobal) < mAutoPilotStopDistance, mAutoPilotCallbackData);
+            mAutoPilotFinishedCallback = NULL;
+        }
+        mLeaderID = LLUUID::null;
+
+        setControlFlags(AGENT_CONTROL_STOP);
+
+        if (user_cancel && !mAutoPilotBehaviorName.empty())
+        {
+            if (mAutoPilotBehaviorName == "Sit")
+                LL_INFOS("Agent") << "Autopilot-Sit was canceled by user action" << LL_ENDL;
+            else if (mAutoPilotBehaviorName == "Attach")
+                LLNotificationsUtil::add("CancelledAttach");
+            else
+                LLNotificationsUtil::add("Cancelled");
+        }
+    }
 }
 
 
@@ -2008,36 +2008,36 @@ void LLAgent::stopAutoPilot(BOOL user_cancel)
 //-----------------------------------------------------------------------------
 void LLAgent::autoPilot(F32 *delta_yaw)
 {
-	if (mAutoPilot)
-	{
-		if (!mLeaderID.isNull())
-		{
-			LLViewerObject* object = gObjectList.findObject(mLeaderID);
-			if (!object) 
-			{
-				stopAutoPilot();
-				return;
-			}
-			mAutoPilotTargetGlobal = object->getPositionGlobal();
-		}
-		
-		if (!isAgentAvatarValid()) return;
-
-		if (gAgentAvatarp->mInAir && mAutoPilotAllowFlying)
-		{
-			setFlying(TRUE);
-		}
-	
-		LLVector3 at;
-		at.setVec(mFrameAgent.getAtAxis());
-		LLVector3 target_agent = getPosAgentFromGlobal(mAutoPilotTargetGlobal);
-		LLVector3 direction = target_agent - getPositionAgent();
-
-		F32 target_dist = direction.magVec();
-
-		if (target_dist >= mAutoPilotTargetDist)
-		{
-			mAutoPilotNoProgressFrameCount++;
+    if (mAutoPilot)
+    {
+        if (!mLeaderID.isNull())
+        {
+            LLViewerObject* object = gObjectList.findObject(mLeaderID);
+            if (!object)
+            {
+                stopAutoPilot();
+                return;
+            }
+            mAutoPilotTargetGlobal = object->getPositionGlobal();
+        }
+
+        if (!isAgentAvatarValid()) return;
+
+        if (gAgentAvatarp->mInAir && mAutoPilotAllowFlying)
+        {
+            setFlying(TRUE);
+        }
+
+        LLVector3 at;
+        at.setVec(mFrameAgent.getAtAxis());
+        LLVector3 target_agent = getPosAgentFromGlobal(mAutoPilotTargetGlobal);
+        LLVector3 direction = target_agent - getPositionAgent();
+
+        F32 target_dist = direction.magVec();
+
+        if (target_dist >= mAutoPilotTargetDist)
+        {
+            mAutoPilotNoProgressFrameCount++;
             bool out_of_time = false;
             if (getFlying())
             {
@@ -2047,104 +2047,104 @@ void LLAgent::autoPilot(F32 *delta_yaw)
             {
                 out_of_time = mAutoPilotNoProgressFrameCount > AUTOPILOT_MAX_TIME_NO_PROGRESS_WALK * gFPSClamped;
             }
-			if (out_of_time)
-			{
-				stopAutoPilot();
-				return;
-			}
-		}
-
-		mAutoPilotTargetDist = target_dist;
-
-		// Make this a two-dimensional solution
-		at.mV[VZ] = 0.f;
-		direction.mV[VZ] = 0.f;
-
-		at.normalize();
-		F32 xy_distance = direction.normalize();
-
-		F32 yaw = 0.f;
-		if (mAutoPilotTargetDist > mAutoPilotStopDistance)
-		{
-			yaw = angle_between(mFrameAgent.getAtAxis(), direction);
-		}
-		else if (mAutoPilotUseRotation)
-		{
-			// we're close now just aim at target facing
-			yaw = angle_between(at, mAutoPilotTargetFacing);
-			direction = mAutoPilotTargetFacing;
-		}
-
-		yaw = 4.f * yaw / gFPSClamped;
-
-		// figure out which direction to turn
-		LLVector3 scratch(at % direction);
-
-		if (scratch.mV[VZ] > 0.f)
-		{
-			setControlFlags(AGENT_CONTROL_YAW_POS);
-		}
-		else
-		{
-			yaw = -yaw;
-			setControlFlags(AGENT_CONTROL_YAW_NEG);
-		}
-
-		*delta_yaw = yaw;
-
-		// Compute when to start slowing down
-		F32 slow_distance;
-		if (getFlying())
-		{
-			slow_distance = llmax(8.f, mAutoPilotStopDistance + 5.f);
-		}
-		else
-		{
-			slow_distance = llmax(3.f, mAutoPilotStopDistance + 2.f);
-		}
-
-		// If we're flying, handle autopilot points above or below you.
-		if (getFlying() && xy_distance < AUTOPILOT_HEIGHT_ADJUST_DISTANCE)
-		{
-			if (isAgentAvatarValid())
-			{
-				F64 current_height = gAgentAvatarp->getPositionGlobal().mdV[VZ];
-				F32 delta_z = (F32)(mAutoPilotTargetGlobal.mdV[VZ] - current_height);
-				F32 slope = delta_z / xy_distance;
-				if (slope > 0.45f && delta_z > 6.f)
-				{
-					setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_POS);
-				}
-				else if (slope > 0.002f && delta_z > 0.5f)
-				{
-					setControlFlags(AGENT_CONTROL_UP_POS);
-				}
-				else if (slope < -0.45f && delta_z < -6.f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND)
-				{
-					setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_NEG);
-				}
-				else if (slope < -0.002f && delta_z < -0.5f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND)
-				{
-					setControlFlags(AGENT_CONTROL_UP_NEG);
-				}
-			}
-		}
-
-		//  calculate delta rotation to target heading
-		F32 delta_target_heading = angle_between(mFrameAgent.getAtAxis(), mAutoPilotTargetFacing);
-
-		if (xy_distance > slow_distance && yaw < (F_PI / 10.f))
-		{
-			// walking/flying fast
-			setControlFlags(AGENT_CONTROL_FAST_AT | AGENT_CONTROL_AT_POS);
-		}
-		else if (mAutoPilotTargetDist > mAutoPilotStopDistance)
-		{
+            if (out_of_time)
+            {
+                stopAutoPilot();
+                return;
+            }
+        }
+
+        mAutoPilotTargetDist = target_dist;
+
+        // Make this a two-dimensional solution
+        at.mV[VZ] = 0.f;
+        direction.mV[VZ] = 0.f;
+
+        at.normalize();
+        F32 xy_distance = direction.normalize();
+
+        F32 yaw = 0.f;
+        if (mAutoPilotTargetDist > mAutoPilotStopDistance)
+        {
+            yaw = angle_between(mFrameAgent.getAtAxis(), direction);
+        }
+        else if (mAutoPilotUseRotation)
+        {
+            // we're close now just aim at target facing
+            yaw = angle_between(at, mAutoPilotTargetFacing);
+            direction = mAutoPilotTargetFacing;
+        }
+
+        yaw = 4.f * yaw / gFPSClamped;
+
+        // figure out which direction to turn
+        LLVector3 scratch(at % direction);
+
+        if (scratch.mV[VZ] > 0.f)
+        {
+            setControlFlags(AGENT_CONTROL_YAW_POS);
+        }
+        else
+        {
+            yaw = -yaw;
+            setControlFlags(AGENT_CONTROL_YAW_NEG);
+        }
+
+        *delta_yaw = yaw;
+
+        // Compute when to start slowing down
+        F32 slow_distance;
+        if (getFlying())
+        {
+            slow_distance = llmax(8.f, mAutoPilotStopDistance + 5.f);
+        }
+        else
+        {
+            slow_distance = llmax(3.f, mAutoPilotStopDistance + 2.f);
+        }
+
+        // If we're flying, handle autopilot points above or below you.
+        if (getFlying() && xy_distance < AUTOPILOT_HEIGHT_ADJUST_DISTANCE)
+        {
+            if (isAgentAvatarValid())
+            {
+                F64 current_height = gAgentAvatarp->getPositionGlobal().mdV[VZ];
+                F32 delta_z = (F32)(mAutoPilotTargetGlobal.mdV[VZ] - current_height);
+                F32 slope = delta_z / xy_distance;
+                if (slope > 0.45f && delta_z > 6.f)
+                {
+                    setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_POS);
+                }
+                else if (slope > 0.002f && delta_z > 0.5f)
+                {
+                    setControlFlags(AGENT_CONTROL_UP_POS);
+                }
+                else if (slope < -0.45f && delta_z < -6.f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND)
+                {
+                    setControlFlags(AGENT_CONTROL_FAST_UP | AGENT_CONTROL_UP_NEG);
+                }
+                else if (slope < -0.002f && delta_z < -0.5f && current_height > AUTOPILOT_MIN_TARGET_HEIGHT_OFF_GROUND)
+                {
+                    setControlFlags(AGENT_CONTROL_UP_NEG);
+                }
+            }
+        }
+
+        //  calculate delta rotation to target heading
+        F32 delta_target_heading = angle_between(mFrameAgent.getAtAxis(), mAutoPilotTargetFacing);
+
+        if (xy_distance > slow_distance && yaw < (F_PI / 10.f))
+        {
+            // walking/flying fast
+            setControlFlags(AGENT_CONTROL_FAST_AT | AGENT_CONTROL_AT_POS);
+        }
+        else if (mAutoPilotTargetDist > mAutoPilotStopDistance)
+        {
             // walking/flying slow
             U32 movement_flag = 0;
 
-			if (at * direction > 0.9f)
-			{
+            if (at * direction > 0.9f)
+            {
                 movement_flag = AGENT_CONTROL_AT_POS;
             }
             else if (at * direction < -0.9f)
@@ -2175,19 +2175,19 @@ void LLAgent::autoPilot(F32 *delta_yaw)
             if (movement_flag)
             {
                 setControlFlags(movement_flag);
-			}
-		}
+            }
+        }
 
-		// check to see if we need to keep rotating to target orientation
-		if (mAutoPilotTargetDist < mAutoPilotStopDistance)
-		{
-			setControlFlags(AGENT_CONTROL_STOP);
-			if(!mAutoPilotUseRotation || (delta_target_heading < mAutoPilotRotationThreshold))
-			{
-				stopAutoPilot();
-			}
-		}
-	}
+        // check to see if we need to keep rotating to target orientation
+        if (mAutoPilotTargetDist < mAutoPilotStopDistance)
+        {
+            setControlFlags(AGENT_CONTROL_STOP);
+            if(!mAutoPilotUseRotation || (delta_target_heading < mAutoPilotRotationThreshold))
+            {
+                stopAutoPilot();
+            }
+        }
+    }
 }
 
 
@@ -2196,45 +2196,45 @@ void LLAgent::autoPilot(F32 *delta_yaw)
 //-----------------------------------------------------------------------------
 void LLAgent::propagate(const F32 dt)
 {
-	// Update UI based on agent motion
-	LLFloaterMove *floater_move = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
-	if (floater_move)
-	{
-		floater_move->mForwardButton   ->setToggleState( gAgentCamera.getAtKey() > 0 || gAgentCamera.getWalkKey() > 0 );
-		floater_move->mBackwardButton  ->setToggleState( gAgentCamera.getAtKey() < 0 || gAgentCamera.getWalkKey() < 0 );
-		floater_move->mTurnLeftButton  ->setToggleState( gAgentCamera.getYawKey() > 0.f );
-		floater_move->mTurnRightButton ->setToggleState( gAgentCamera.getYawKey() < 0.f );
-		floater_move->mSlideLeftButton  ->setToggleState( gAgentCamera.getLeftKey() > 0.f );
-		floater_move->mSlideRightButton ->setToggleState( gAgentCamera.getLeftKey() < 0.f );
-		floater_move->mMoveUpButton    ->setToggleState( gAgentCamera.getUpKey() > 0 );
-		floater_move->mMoveDownButton  ->setToggleState( gAgentCamera.getUpKey() < 0 );
-	}
-
-	// handle rotation based on keyboard levels
-	const F32 YAW_RATE = 90.f * DEG_TO_RAD;				// radians per second
-	yaw(YAW_RATE * gAgentCamera.getYawKey() * dt);
-
-	const F32 PITCH_RATE = 90.f * DEG_TO_RAD;			// radians per second
-	pitch(PITCH_RATE * gAgentCamera.getPitchKey() * dt);
-	
-	// handle auto-land behavior
-	if (isAgentAvatarValid())
-	{
-		BOOL in_air = gAgentAvatarp->mInAir;
-		LLVector3 land_vel = getVelocity();
-		land_vel.mV[VZ] = 0.f;
-
-		if (!in_air 
-			&& gAgentCamera.getUpKey() < 0 
-			&& land_vel.magVecSquared() < MAX_VELOCITY_AUTO_LAND_SQUARED
-			&& ALControlCache::AutomaticFly)
-		{
-			// land automatically
-			setFlying(FALSE);
-		}
-	}
-
-	gAgentCamera.clearGeneralKeys();
+    // Update UI based on agent motion
+    LLFloaterMove *floater_move = LLFloaterReg::findTypedInstance<LLFloaterMove>("moveview");
+    if (floater_move)
+    {
+        floater_move->mForwardButton   ->setToggleState( gAgentCamera.getAtKey() > 0 || gAgentCamera.getWalkKey() > 0 );
+        floater_move->mBackwardButton  ->setToggleState( gAgentCamera.getAtKey() < 0 || gAgentCamera.getWalkKey() < 0 );
+        floater_move->mTurnLeftButton  ->setToggleState( gAgentCamera.getYawKey() > 0.f );
+        floater_move->mTurnRightButton ->setToggleState( gAgentCamera.getYawKey() < 0.f );
+        floater_move->mSlideLeftButton  ->setToggleState( gAgentCamera.getLeftKey() > 0.f );
+        floater_move->mSlideRightButton ->setToggleState( gAgentCamera.getLeftKey() < 0.f );
+        floater_move->mMoveUpButton    ->setToggleState( gAgentCamera.getUpKey() > 0 );
+        floater_move->mMoveDownButton  ->setToggleState( gAgentCamera.getUpKey() < 0 );
+    }
+
+    // handle rotation based on keyboard levels
+    const F32 YAW_RATE = 90.f * DEG_TO_RAD;             // radians per second
+    yaw(YAW_RATE * gAgentCamera.getYawKey() * dt);
+
+    const F32 PITCH_RATE = 90.f * DEG_TO_RAD;           // radians per second
+    pitch(PITCH_RATE * gAgentCamera.getPitchKey() * dt);
+
+    // handle auto-land behavior
+    if (isAgentAvatarValid())
+    {
+        BOOL in_air = gAgentAvatarp->mInAir;
+        LLVector3 land_vel = getVelocity();
+        land_vel.mV[VZ] = 0.f;
+
+        if (!in_air
+            && gAgentCamera.getUpKey() < 0
+            && land_vel.magVecSquared() < MAX_VELOCITY_AUTO_LAND_SQUARED
+            && ALControlCache::AutomaticFly)
+        {
+            // land automatically
+            setFlying(FALSE);
+        }
+    }
+
+    gAgentCamera.clearGeneralKeys();
 }
 
 //-----------------------------------------------------------------------------
@@ -2243,22 +2243,22 @@ void LLAgent::propagate(const F32 dt)
 void LLAgent::updateAgentPosition(const F32 dt, const F32 yaw_radians, const S32 mouse_x, const S32 mouse_y)
 {
     static const LLCachedControl<F32> hint_timeout(gSavedSettings, "NotMovingHintTimeout");
-	if (mMoveTimer.getStarted() && mMoveTimer.getElapsedTimeF32() > hint_timeout)
-	{
-		LLFirstUse::notMoving();
-	}
+    if (mMoveTimer.getStarted() && mMoveTimer.getElapsedTimeF32() > hint_timeout)
+    {
+        LLFirstUse::notMoving();
+    }
 
-	propagate(dt);
+    propagate(dt);
 
-	// static S32 cameraUpdateCount = 0;
+    // static S32 cameraUpdateCount = 0;
 
-	rotate(yaw_radians, 0, 0, 1);
-	
-	//
-	// Check for water and land collision, set underwater flag
-	//
+    rotate(yaw_radians, 0, 0, 1);
 
-	gAgentCamera.updateLookAt(mouse_x, mouse_y);
+    //
+    // Check for water and land collision, set underwater flag
+    //
+
+    gAgentCamera.updateLookAt(mouse_x, mouse_y);
 
     // When agent has no parents, position updates come from setPositionAgent()
     // But when agent has a parent (ex: is seated), position remains unchanged
@@ -2275,7 +2275,7 @@ void LLAgent::updateAgentPosition(const F32 dt, const F32 yaw_radians, const S32
         if ((mLastTestGlobal - new_position).lengthSquared() > 1.0)
         {
             // If the position has changed by more than 1 meter since the last time we triggered.
-            // filters out some noise. 
+            // filters out some noise.
             mLastTestGlobal = new_position;
             mOnPositionChanged(mFrameAgent.getOrigin(), new_position);
         }
@@ -2286,12 +2286,12 @@ void LLAgent::updateAgentPosition(const F32 dt, const F32 yaw_radians, const S32
 
 std::ostream& operator<<(std::ostream &s, const LLAgent &agent)
 {
-	// This is unfinished, but might never be used. 
-	// We'll just leave it for now; we can always delete it.
-	s << " { "
-	  << "  Frame = " << agent.mFrameAgent << "\n"
-	  << " }";
-	return s;
+    // This is unfinished, but might never be used.
+    // We'll just leave it for now; we can always delete it.
+    s << " { "
+      << "  Frame = " << agent.mFrameAgent << "\n"
+      << " }";
+    return s;
 }
 
 // TRUE if your own avatar needs to be rendered.  Usually only
@@ -2301,24 +2301,24 @@ std::ostream& operator<<(std::ostream &s, const LLAgent &agent)
 //-----------------------------------------------------------------------------
 BOOL LLAgent::needsRenderAvatar()
 {
-//	if (gAgentCamera.cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson)
+//  if (gAgentCamera.cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson)
 // [RLVa:KB] - Checked: RLVa-2.0.2
-	if ( (gAgentCamera.cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson) || (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWSELF)) )
+    if ( (gAgentCamera.cameraMouselook() && !LLVOAvatar::sVisibleInFirstPerson) || (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWSELF)) )
 // [/RLVa:KB]
-	{
-		return FALSE;
-	}
+    {
+        return FALSE;
+    }
 
-	return mShowAvatar && mOutfitChosen;
+    return mShowAvatar && mOutfitChosen;
 }
 
 // TRUE if we need to render your own avatar's head.
 BOOL LLAgent::needsRenderHead()
 {
 // [RLVa:KB] - Checked: RLVa-2.0.2
-	return ((LLVOAvatar::sVisibleInFirstPerson && LLPipeline::sReflectionRender) || (mShowAvatar && !gAgentCamera.cameraMouselook())) && (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWSELFHEAD));
+    return ((LLVOAvatar::sVisibleInFirstPerson && LLPipeline::sReflectionRender) || (mShowAvatar && !gAgentCamera.cameraMouselook())) && (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWSELFHEAD));
 // [/RLVa:KB]
-//	return (LLVOAvatar::sVisibleInFirstPerson && LLPipeline::sReflectionRender) || (mShowAvatar && !gAgentCamera.cameraMouselook());
+//  return (LLVOAvatar::sVisibleInFirstPerson && LLPipeline::sReflectionRender) || (mShowAvatar && !gAgentCamera.cameraMouselook());
 }
 
 //-----------------------------------------------------------------------------
@@ -2327,35 +2327,35 @@ BOOL LLAgent::needsRenderHead()
 void LLAgent::startTyping()
 {
 // [RLVa:KB] - @redirchat
-	if (!RlvActions::canSendTypingStart())
-	{
-		return;
-	}
+    if (!RlvActions::canSendTypingStart())
+    {
+        return;
+    }
 // [/RLVa:KB]
 
-	mTypingTimer.reset();
+    mTypingTimer.reset();
 
-	if (getRenderState() & AGENT_STATE_TYPING)
-	{
-		// already typing, don't trigger a different animation
-		return;
-	}
-	setRenderState(AGENT_STATE_TYPING);
+    if (getRenderState() & AGENT_STATE_TYPING)
+    {
+        // already typing, don't trigger a different animation
+        return;
+    }
+    setRenderState(AGENT_STATE_TYPING);
 
-	if (mChatTimer.getElapsedTimeF32() < 2.f)
-	{
-		LLViewerObject* chatter = gObjectList.findObject(mLastChatterID);
-		if (chatter && chatter->isAvatar())
-		{
-			gAgentCamera.setLookAt(LOOKAT_TARGET_RESPOND, chatter, LLVector3::zero);
-		}
-	}
+    if (mChatTimer.getElapsedTimeF32() < 2.f)
+    {
+        LLViewerObject* chatter = gObjectList.findObject(mLastChatterID);
+        if (chatter && chatter->isAvatar())
+        {
+            gAgentCamera.setLookAt(LOOKAT_TARGET_RESPOND, chatter, LLVector3::zero);
+        }
+    }
 
-	if (gSavedSettings.getBOOL("PlayTypingAnim"))
-	{
-		sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_START);
-	}
-	LLFloaterIMNearbyChat::sendChatFromViewer("", CHAT_TYPE_START, FALSE);
+    if (gSavedSettings.getBOOL("PlayTypingAnim"))
+    {
+        sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_START);
+    }
+    LLFloaterIMNearbyChat::sendChatFromViewer("", CHAT_TYPE_START, FALSE);
 }
 
 //-----------------------------------------------------------------------------
@@ -2363,12 +2363,12 @@ void LLAgent::startTyping()
 //-----------------------------------------------------------------------------
 void LLAgent::stopTyping()
 {
-	if (mRenderState & AGENT_STATE_TYPING)
-	{
-		clearRenderState(AGENT_STATE_TYPING);
-		sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_STOP);
-		LLFloaterIMNearbyChat::sendChatFromViewer("", CHAT_TYPE_STOP, FALSE);
-	}
+    if (mRenderState & AGENT_STATE_TYPING)
+    {
+        clearRenderState(AGENT_STATE_TYPING);
+        sendAnimationRequest(ANIM_AGENT_TYPE, ANIM_REQUEST_STOP);
+        LLFloaterIMNearbyChat::sendChatFromViewer("", CHAT_TYPE_STOP, FALSE);
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -2376,7 +2376,7 @@ void LLAgent::stopTyping()
 //-----------------------------------------------------------------------------
 void LLAgent::setRenderState(U8 newstate)
 {
-	mRenderState |= newstate;
+    mRenderState |= newstate;
 }
 
 //-----------------------------------------------------------------------------
@@ -2384,7 +2384,7 @@ void LLAgent::setRenderState(U8 newstate)
 //-----------------------------------------------------------------------------
 void LLAgent::clearRenderState(U8 clearstate)
 {
-	mRenderState &= ~clearstate;
+    mRenderState &= ~clearstate;
 }
 
 
@@ -2393,24 +2393,24 @@ void LLAgent::clearRenderState(U8 clearstate)
 //-----------------------------------------------------------------------------
 U8 LLAgent::getRenderState()
 {
-	// *FIX: don't do stuff in a getter!  This is infinite loop city!
-	if ((mTypingTimer.getElapsedTimeF32() > TYPING_TIMEOUT_SECS) 
-		&& (mRenderState & AGENT_STATE_TYPING))
-	{
-		stopTyping();
-	}
-	
-	if ((!LLSelectMgr::getInstance()->getSelection()->isEmpty() && LLSelectMgr::getInstance()->shouldShowSelection())
-		|| LLToolMgr::getInstance()->getCurrentTool()->isEditing() )
-	{
-		setRenderState(AGENT_STATE_EDITING);
-	}
-	else
-	{
-		clearRenderState(AGENT_STATE_EDITING);
-	}
+    // *FIX: don't do stuff in a getter!  This is infinite loop city!
+    if ((mTypingTimer.getElapsedTimeF32() > TYPING_TIMEOUT_SECS)
+        && (mRenderState & AGENT_STATE_TYPING))
+    {
+        stopTyping();
+    }
 
-	return mRenderState;
+    if ((!LLSelectMgr::getInstance()->getSelection()->isEmpty() && LLSelectMgr::getInstance()->shouldShowSelection())
+        || LLToolMgr::getInstance()->getCurrentTool()->isEditing() )
+    {
+        setRenderState(AGENT_STATE_EDITING);
+    }
+    else
+    {
+        clearRenderState(AGENT_STATE_EDITING);
+    }
+
+    return mRenderState;
 }
 
 //-----------------------------------------------------------------------------
@@ -2421,293 +2421,293 @@ U8 LLAgent::getRenderState()
 //-----------------------------------------------------------------------------
 void LLAgent::endAnimationUpdateUI()
 {
-	if (LLApp::isExiting()
-		|| !gViewerWindow
-		|| !gMenuBarView
-		|| !gToolBarView
-		|| !gStatusBar)
-	{
-		return;
-	}
-	if (gAgentCamera.getCameraMode() == gAgentCamera.getLastCameraMode())
-	{
-		// We're already done endAnimationUpdateUI for this transition.
-		return;
-	}
-
-	// clean up UI from mode we're leaving
-	if (gAgentCamera.getLastCameraMode() == CAMERA_MODE_MOUSELOOK )
-	{
-		gToolBarView->setToolBarsVisible(true);
-		// show mouse cursor
-		gViewerWindow->showCursor();
-		// show menus
-		gMenuBarView->setVisible(TRUE);
-		LLNavigationBar::getInstance()->setVisible(TRUE && gSavedSettings.getBOOL("ShowNavbarNavigationPanel"));
-		gStatusBar->setVisibleForMouselook(true);
+    if (LLApp::isExiting()
+        || !gViewerWindow
+        || !gMenuBarView
+        || !gToolBarView
+        || !gStatusBar)
+    {
+        return;
+    }
+    if (gAgentCamera.getCameraMode() == gAgentCamera.getLastCameraMode())
+    {
+        // We're already done endAnimationUpdateUI for this transition.
+        return;
+    }
+
+    // clean up UI from mode we're leaving
+    if (gAgentCamera.getLastCameraMode() == CAMERA_MODE_MOUSELOOK )
+    {
+        gToolBarView->setToolBarsVisible(true);
+        // show mouse cursor
+        gViewerWindow->showCursor();
+        // show menus
+        gMenuBarView->setVisible(TRUE);
+        LLNavigationBar::getInstance()->setVisible(TRUE && gSavedSettings.getBOOL("ShowNavbarNavigationPanel"));
+        gStatusBar->setVisibleForMouselook(true);
 
         static LLCachedControl<bool> show_mini_location_panel(gSavedSettings, "ShowMiniLocationPanel");
-		if (show_mini_location_panel)
-		{
-			LLPanelTopInfoBar::getInstance()->setVisible(TRUE);
-		}
+        if (show_mini_location_panel)
+        {
+            LLPanelTopInfoBar::getInstance()->setVisible(TRUE);
+        }
 
-		LLChicletBar::getInstance()->setVisible(!ALCinematicMode::isEnabled());
+        LLChicletBar::getInstance()->setVisible(!ALCinematicMode::isEnabled());
 
-		LLPanelStandStopFlying::getInstance()->setVisible(TRUE);
+        LLPanelStandStopFlying::getInstance()->setVisible(TRUE);
 
-		LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
+        LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
 
-		LLFloaterCamera::onLeavingMouseLook();
+        LLFloaterCamera::onLeavingMouseLook();
 
-		if (mMouselookModeOutSignal)
-		{
-			(*mMouselookModeOutSignal)();
-		}
+        if (mMouselookModeOutSignal)
+        {
+            (*mMouselookModeOutSignal)();
+        }
 
-		// Only pop if we have pushed...
-		if (TRUE == mViewsPushed)
-		{
+        // Only pop if we have pushed...
+        if (TRUE == mViewsPushed)
+        {
 #if 0 // Use this once all floaters are registered
-			LLFloaterReg::restoreVisibleInstances();
+            LLFloaterReg::restoreVisibleInstances();
 #else // Use this for now
-			LLFloaterView::skip_list_t skip_list;
-			if (LLFloaterReg::findInstance("mini_map"))
-			{
-				skip_list.insert(LLFloaterReg::findInstance("mini_map"));
-			}
-			if (LLFloaterReg::findInstance("beacons"))
-			{
-				skip_list.insert(LLFloaterReg::findInstance("beacons"));
-			}
-			if (LLFloaterReg::findInstance("nearby_chat"))
-			{
-				skip_list.insert(LLFloaterReg::findInstance("nearby_chat"));
-			}
-			if (LLFloaterReg::findInstance("stats"))
-			{
-				skip_list.insert(LLFloaterReg::findInstance("stats"));
-			}
-			if (LLFloaterReg::findInstance("chatbar"))
-			{
-				skip_list.insert(LLFloaterReg::findInstance("chatbar"));
-			}
-			LLFloaterIMContainer* im_box = LLFloaterReg::getTypedInstance<LLFloaterIMContainer>("im_container");
-			LLFloaterIMContainer::floater_list_t conversations;
-			im_box->getDetachedConversationFloaters(conversations);
-			for (LLFloater* conversation : conversations)
-			{
-				LL_INFOS() << "skip_list.insert(session_floater): " << conversation->getTitle() << LL_ENDL;
-				skip_list.insert(conversation);
-			}
-
-			gFloaterView->popVisibleAll(skip_list);
+            LLFloaterView::skip_list_t skip_list;
+            if (LLFloaterReg::findInstance("mini_map"))
+            {
+                skip_list.insert(LLFloaterReg::findInstance("mini_map"));
+            }
+            if (LLFloaterReg::findInstance("beacons"))
+            {
+                skip_list.insert(LLFloaterReg::findInstance("beacons"));
+            }
+            if (LLFloaterReg::findInstance("nearby_chat"))
+            {
+                skip_list.insert(LLFloaterReg::findInstance("nearby_chat"));
+            }
+            if (LLFloaterReg::findInstance("stats"))
+            {
+                skip_list.insert(LLFloaterReg::findInstance("stats"));
+            }
+            if (LLFloaterReg::findInstance("chatbar"))
+            {
+                skip_list.insert(LLFloaterReg::findInstance("chatbar"));
+            }
+            LLFloaterIMContainer* im_box = LLFloaterReg::getTypedInstance<LLFloaterIMContainer>("im_container");
+            LLFloaterIMContainer::floater_list_t conversations;
+            im_box->getDetachedConversationFloaters(conversations);
+            for (LLFloater* conversation : conversations)
+            {
+                LL_INFOS() << "skip_list.insert(session_floater): " << conversation->getTitle() << LL_ENDL;
+                skip_list.insert(conversation);
+            }
+
+            gFloaterView->popVisibleAll(skip_list);
 #endif
-			mViewsPushed = FALSE;
-		}
-
-		
-		gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
-		if( gMorphView )
-		{
-			gMorphView->setVisible( FALSE );
-		}
-
-		// Disable mouselook-specific animations
-		if (isAgentAvatarValid())
-		{
-			if( gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) )
-			{
-				if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != gAgentAvatarp->mSignaledAnimations.end())
-				{
-					sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_STOP);
-					sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_START);
-				}
-				if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_HANDGUN_R) != gAgentAvatarp->mSignaledAnimations.end())
-				{
-					sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_STOP);
-					sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_START);
-				}
-				if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_BAZOOKA_R) != gAgentAvatarp->mSignaledAnimations.end())
-				{
-					sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_STOP);
-					sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_START);
-				}
-				if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_BOW_L) != gAgentAvatarp->mSignaledAnimations.end())
-				{
-					sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_STOP);
-					sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_START);
-				}
-			}
-		}
-	}
-	else if (gAgentCamera.getLastCameraMode() == CAMERA_MODE_CUSTOMIZE_AVATAR)
-	{
-		// make sure we ask to save changes
-
-		LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
-
-		if( gMorphView )
-		{
-			gMorphView->setVisible( FALSE );
-		}
-
-		if (isAgentAvatarValid())
-		{
-			if(mCustomAnim)
-			{
-				sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_STOP);
-				sendAnimationRequest(ANIM_AGENT_CUSTOMIZE_DONE, ANIM_REQUEST_START);
-
-				mCustomAnim = FALSE ;
-			}
-			
-		}
-		gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
-
-		LLFloaterCamera::onAvatarEditingAppearance(false);
-	}
-
-	//---------------------------------------------------------------------
-	// Set up UI for mode we're entering
-	//---------------------------------------------------------------------
-	if (gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK)
-	{
-		// clean up UI
-		// first show anything hidden by UI toggle
-		gViewerWindow->setUIVisibility(TRUE);
-
-		// then hide stuff we want hidden for mouselook 
-		gToolBarView->setToolBarsVisible(false);
-		gMenuBarView->setVisible(FALSE);
-		LLNavigationBar::getInstance()->setVisible(FALSE);
-		gStatusBar->setVisibleForMouselook(false);
-
-		LLPanelTopInfoBar::getInstance()->setVisible(FALSE);
-
-		LLChicletBar::getInstance()->setVisible(FALSE);
-
-		LLPanelStandStopFlying::getInstance()->setVisible(FALSE);
-
-		// clear out camera lag effect
-		gAgentCamera.clearCameraLag();
-
-		// JC - Added for always chat in third person option
-		gFocusMgr.setKeyboardFocus(NULL);
-
-		LLToolMgr::getInstance()->setCurrentToolset(gMouselookToolset);
-
-		mViewsPushed = TRUE;
-
-		if (mMouselookModeInSignal)
-		{
-			(*mMouselookModeInSignal)();
-		}
-
-		// hide all floaters except the mini map
+            mViewsPushed = FALSE;
+        }
+
+
+        gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
+        if( gMorphView )
+        {
+            gMorphView->setVisible( FALSE );
+        }
+
+        // Disable mouselook-specific animations
+        if (isAgentAvatarValid())
+        {
+            if( gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) )
+            {
+                if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_RIFLE_R) != gAgentAvatarp->mSignaledAnimations.end())
+                {
+                    sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_STOP);
+                    sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_START);
+                }
+                if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_HANDGUN_R) != gAgentAvatarp->mSignaledAnimations.end())
+                {
+                    sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_STOP);
+                    sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_START);
+                }
+                if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_BAZOOKA_R) != gAgentAvatarp->mSignaledAnimations.end())
+                {
+                    sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_STOP);
+                    sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_START);
+                }
+                if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_AIM_BOW_L) != gAgentAvatarp->mSignaledAnimations.end())
+                {
+                    sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_STOP);
+                    sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_START);
+                }
+            }
+        }
+    }
+    else if (gAgentCamera.getLastCameraMode() == CAMERA_MODE_CUSTOMIZE_AVATAR)
+    {
+        // make sure we ask to save changes
+
+        LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
+
+        if( gMorphView )
+        {
+            gMorphView->setVisible( FALSE );
+        }
+
+        if (isAgentAvatarValid())
+        {
+            if(mCustomAnim)
+            {
+                sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_STOP);
+                sendAnimationRequest(ANIM_AGENT_CUSTOMIZE_DONE, ANIM_REQUEST_START);
+
+                mCustomAnim = FALSE ;
+            }
+
+        }
+        gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
+
+        LLFloaterCamera::onAvatarEditingAppearance(false);
+    }
+
+    //---------------------------------------------------------------------
+    // Set up UI for mode we're entering
+    //---------------------------------------------------------------------
+    if (gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK)
+    {
+        // clean up UI
+        // first show anything hidden by UI toggle
+        gViewerWindow->setUIVisibility(TRUE);
+
+        // then hide stuff we want hidden for mouselook
+        gToolBarView->setToolBarsVisible(false);
+        gMenuBarView->setVisible(FALSE);
+        LLNavigationBar::getInstance()->setVisible(FALSE);
+        gStatusBar->setVisibleForMouselook(false);
+
+        LLPanelTopInfoBar::getInstance()->setVisible(FALSE);
+
+        LLChicletBar::getInstance()->setVisible(FALSE);
+
+        LLPanelStandStopFlying::getInstance()->setVisible(FALSE);
+
+        // clear out camera lag effect
+        gAgentCamera.clearCameraLag();
+
+        // JC - Added for always chat in third person option
+        gFocusMgr.setKeyboardFocus(NULL);
+
+        LLToolMgr::getInstance()->setCurrentToolset(gMouselookToolset);
+
+        mViewsPushed = TRUE;
+
+        if (mMouselookModeInSignal)
+        {
+            (*mMouselookModeInSignal)();
+        }
+
+        // hide all floaters except the mini map
 
 #if 0 // Use this once all floaters are registered
-		std::set<std::string> exceptions;
-		exceptions.insert("mini_map");
-		LLFloaterReg::hideVisibleInstances(exceptions);
+        std::set<std::string> exceptions;
+        exceptions.insert("mini_map");
+        LLFloaterReg::hideVisibleInstances(exceptions);
 #else // Use this for now
-		LLFloaterView::skip_list_t skip_list;
-		skip_list.insert(LLFloaterReg::findInstance("beacons")); // <alchemy/>
-		skip_list.insert(LLFloaterReg::findInstance("mini_map"));
-		skip_list.insert(LLFloaterReg::findInstance("nearby_chat"));
-		skip_list.insert(LLFloaterReg::findInstance("stats")); // <alchemy/>
-		skip_list.insert(LLFloaterReg::findInstance("chatbar")); // <alchemy/>
-		gFloaterView->pushVisibleAll(FALSE, skip_list);
+        LLFloaterView::skip_list_t skip_list;
+        skip_list.insert(LLFloaterReg::findInstance("beacons")); // <alchemy/>
+        skip_list.insert(LLFloaterReg::findInstance("mini_map"));
+        skip_list.insert(LLFloaterReg::findInstance("nearby_chat"));
+        skip_list.insert(LLFloaterReg::findInstance("stats")); // <alchemy/>
+        skip_list.insert(LLFloaterReg::findInstance("chatbar")); // <alchemy/>
+        gFloaterView->pushVisibleAll(FALSE, skip_list);
 #endif
 
-		if( gMorphView )
-		{
-			gMorphView->setVisible(FALSE);
-		}
-
-		gConsole->setVisible( TRUE );
-
-		if (isAgentAvatarValid())
-		{
-			// Trigger mouselook-specific animations
-			if( gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS, NUM_AGENT_GUN_HOLD_ANIMS) )
-			{
-				if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_RIFLE_R) != gAgentAvatarp->mSignaledAnimations.end())
-				{
-					sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_STOP);
-					sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_START);
-				}
-				if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_HANDGUN_R) != gAgentAvatarp->mSignaledAnimations.end())
-				{
-					sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_STOP);
-					sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_START);
-				}
-				if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_BAZOOKA_R) != gAgentAvatarp->mSignaledAnimations.end())
-				{
-					sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_STOP);
-					sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_START);
-				}
-				if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_BOW_L) != gAgentAvatarp->mSignaledAnimations.end())
-				{
-					sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_STOP);
-					sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_START);
-				}
-			}
-			if (gAgentAvatarp->getParent())
-			{
-				LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis();
-				LLViewerObject* root_object = (LLViewerObject*)gAgentAvatarp->getRoot();
-				if (root_object->flagCameraDecoupled())
-				{
-					resetAxes(at_axis);
-				}
-				else
-				{
-					resetAxes(at_axis * ~((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation());
-				}
-			}
-		}
-	}
-	else if (gAgentCamera.getCameraMode() == CAMERA_MODE_CUSTOMIZE_AVATAR)
-	{
-		LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset);
-
-		if( gMorphView )
-		{
-			gMorphView->setVisible( TRUE );
-		}
-
-		// freeze avatar
-		if (isAgentAvatarValid())
-		{
-			mPauseRequest = gAgentAvatarp->requestPause();
-		}
-
-		LLFloaterCamera::onAvatarEditingAppearance(true);
-	}
-
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode());
-	}
-
-	gFloaterTools->dirty();
-
-	// Don't let this be called more than once if the camera
-	// mode hasn't changed.  --JC
-	gAgentCamera.updateLastCamera();
+        if( gMorphView )
+        {
+            gMorphView->setVisible(FALSE);
+        }
+
+        gConsole->setVisible( TRUE );
+
+        if (isAgentAvatarValid())
+        {
+            // Trigger mouselook-specific animations
+            if( gAgentAvatarp->isAnyAnimationSignaled(AGENT_GUN_HOLD_ANIMS, NUM_AGENT_GUN_HOLD_ANIMS) )
+            {
+                if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_RIFLE_R) != gAgentAvatarp->mSignaledAnimations.end())
+                {
+                    sendAnimationRequest(ANIM_AGENT_HOLD_RIFLE_R, ANIM_REQUEST_STOP);
+                    sendAnimationRequest(ANIM_AGENT_AIM_RIFLE_R, ANIM_REQUEST_START);
+                }
+                if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_HANDGUN_R) != gAgentAvatarp->mSignaledAnimations.end())
+                {
+                    sendAnimationRequest(ANIM_AGENT_HOLD_HANDGUN_R, ANIM_REQUEST_STOP);
+                    sendAnimationRequest(ANIM_AGENT_AIM_HANDGUN_R, ANIM_REQUEST_START);
+                }
+                if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_BAZOOKA_R) != gAgentAvatarp->mSignaledAnimations.end())
+                {
+                    sendAnimationRequest(ANIM_AGENT_HOLD_BAZOOKA_R, ANIM_REQUEST_STOP);
+                    sendAnimationRequest(ANIM_AGENT_AIM_BAZOOKA_R, ANIM_REQUEST_START);
+                }
+                if (gAgentAvatarp->mSignaledAnimations.find(ANIM_AGENT_HOLD_BOW_L) != gAgentAvatarp->mSignaledAnimations.end())
+                {
+                    sendAnimationRequest(ANIM_AGENT_HOLD_BOW_L, ANIM_REQUEST_STOP);
+                    sendAnimationRequest(ANIM_AGENT_AIM_BOW_L, ANIM_REQUEST_START);
+                }
+            }
+            if (gAgentAvatarp->getParent())
+            {
+                LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis();
+                LLViewerObject* root_object = (LLViewerObject*)gAgentAvatarp->getRoot();
+                if (root_object->flagCameraDecoupled())
+                {
+                    resetAxes(at_axis);
+                }
+                else
+                {
+                    resetAxes(at_axis * ~((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation());
+                }
+            }
+        }
+    }
+    else if (gAgentCamera.getCameraMode() == CAMERA_MODE_CUSTOMIZE_AVATAR)
+    {
+        LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset);
+
+        if( gMorphView )
+        {
+            gMorphView->setVisible( TRUE );
+        }
+
+        // freeze avatar
+        if (isAgentAvatarValid())
+        {
+            mPauseRequest = gAgentAvatarp->requestPause();
+        }
+
+        LLFloaterCamera::onAvatarEditingAppearance(true);
+    }
+
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode());
+    }
+
+    gFloaterTools->dirty();
+
+    // Don't let this be called more than once if the camera
+    // mode hasn't changed.  --JC
+    gAgentCamera.updateLastCamera();
 }
 
 boost::signals2::connection LLAgent::setMouselookModeInCallback( const camera_signal_t::slot_type& cb )
 {
-	if (!mMouselookModeInSignal) mMouselookModeInSignal = new camera_signal_t();
-	return mMouselookModeInSignal->connect(cb);
+    if (!mMouselookModeInSignal) mMouselookModeInSignal = new camera_signal_t();
+    return mMouselookModeInSignal->connect(cb);
 }
 
 boost::signals2::connection LLAgent::setMouselookModeOutCallback( const camera_signal_t::slot_type& cb )
 {
-	if (!mMouselookModeOutSignal) mMouselookModeOutSignal = new camera_signal_t();
-	return mMouselookModeOutSignal->connect(cb);
+    if (!mMouselookModeOutSignal) mMouselookModeOutSignal = new camera_signal_t();
+    return mMouselookModeOutSignal->connect(cb);
 }
 
 //-----------------------------------------------------------------------------
@@ -2715,24 +2715,24 @@ boost::signals2::connection LLAgent::setMouselookModeOutCallback( const camera_s
 //-----------------------------------------------------------------------------
 void LLAgent::heardChat(const LLUUID& id)
 {
-	// log text and voice chat to speaker mgr
-	// for keeping track of active speakers, etc.
-	LLLocalSpeakerMgr::getInstance()->speakerChatted(id);
+    // log text and voice chat to speaker mgr
+    // for keeping track of active speakers, etc.
+    LLLocalSpeakerMgr::getInstance()->speakerChatted(id);
 
-	// don't respond to your own voice
-	if (id == getID()) return;
-	
-	if (ll_rand(2) == 0) 
-	{
-		LLViewerObject *chatter = gObjectList.findObject(mLastChatterID);
-		if (chatter)
-		{
-			gAgentCamera.setLookAt(LOOKAT_TARGET_AUTO_LISTEN, chatter, LLVector3::zero);
-		}
-	}			
+    // don't respond to your own voice
+    if (id == getID()) return;
 
-	mLastChatterID = id;
-	mChatTimer.reset();
+    if (ll_rand(2) == 0)
+    {
+        LLViewerObject *chatter = gObjectList.findObject(mLastChatterID);
+        if (chatter)
+        {
+            gAgentCamera.setLookAt(LOOKAT_TARGET_AUTO_LISTEN, chatter, LLVector3::zero);
+        }
+    }
+
+    mLastChatterID = id;
+    mChatTimer.reset();
 }
 
 LLSD ll_sdmap_from_vector3(const LLVector3& vec)
@@ -2801,31 +2801,31 @@ void LLAgent::setStartPosition( U32 location_id )
 
     body["HomeLocation"] = homeLocation;
 
-    if (!requestPostCapability("HomeLocation", body, 
+    if (!requestPostCapability("HomeLocation", body,
             boost::bind(&LLAgent::setStartPositionSuccess, this, _1)))
-	{
-		if(LLGridManager::instance().isInSecondlife())
-		{
-			LL_WARNS() << "Unable to post to HomeLocation capability." << LL_ENDL;
-		}
-		else
-		{
-			LLMessageSystem* msg = gMessageSystem;
-			msg->newMessageFast(_PREHASH_SetStartLocationRequest);
-			msg->nextBlockFast(_PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
-			msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
-			msg->nextBlockFast(_PREHASH_StartLocationData);
-			// corrected by sim
-			msg->addStringFast(_PREHASH_SimName, "");
-			msg->addU32Fast(_PREHASH_LocationID, homeLocation["LocationId"].asInteger());
-			msg->addVector3Fast(_PREHASH_LocationPos,
-				ll_vector3_from_sdmap(homeLocation["LocationPos"]));
-			msg->addVector3Fast(_PREHASH_LocationLookAt,
-				ll_vector3_from_sdmap(homeLocation["LocationLookAt"]));
-			gAgent.sendReliableMessage();
-		}
-	}
+    {
+        if(LLGridManager::instance().isInSecondlife())
+        {
+            LL_WARNS() << "Unable to post to HomeLocation capability." << LL_ENDL;
+        }
+        else
+        {
+            LLMessageSystem* msg = gMessageSystem;
+            msg->newMessageFast(_PREHASH_SetStartLocationRequest);
+            msg->nextBlockFast(_PREHASH_AgentData);
+            msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
+            msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
+            msg->nextBlockFast(_PREHASH_StartLocationData);
+            // corrected by sim
+            msg->addStringFast(_PREHASH_SimName, "");
+            msg->addU32Fast(_PREHASH_LocationID, homeLocation["LocationId"].asInteger());
+            msg->addVector3Fast(_PREHASH_LocationPos,
+                ll_vector3_from_sdmap(homeLocation["LocationPos"]));
+            msg->addVector3Fast(_PREHASH_LocationLookAt,
+                ll_vector3_from_sdmap(homeLocation["LocationLookAt"]));
+            gAgent.sendReliableMessage();
+        }
+    }
 }
 
 void LLAgent::setStartPositionSuccess(const LLSD &result)
@@ -2876,286 +2876,286 @@ void LLAgent::setStartPositionSuccess(const LLSD &result)
 
 void LLAgent::requestStopMotion( LLMotion* motion )
 {
-	// Notify all avatars that a motion has stopped.
-	// This is needed to clear the animation state bits
-	LLUUID anim_state = motion->getID();
-	onAnimStop(motion->getID());
+    // Notify all avatars that a motion has stopped.
+    // This is needed to clear the animation state bits
+    LLUUID anim_state = motion->getID();
+    onAnimStop(motion->getID());
 
-	// if motion is not looping, it could have stopped by running out of time
-	// so we need to tell the server this
-//	LL_INFOS() << "Sending stop for motion " << motion->getName() << LL_ENDL;
-	sendAnimationRequest( anim_state, ANIM_REQUEST_STOP );
+    // if motion is not looping, it could have stopped by running out of time
+    // so we need to tell the server this
+//  LL_INFOS() << "Sending stop for motion " << motion->getName() << LL_ENDL;
+    sendAnimationRequest( anim_state, ANIM_REQUEST_STOP );
 }
 
 void LLAgent::onAnimStop(const LLUUID& id)
 {
-	// handle automatic state transitions (based on completion of animation playback)
-	if (id == ANIM_AGENT_STAND)
-	{
-		stopFidget();
-	}
-	else if (id == ANIM_AGENT_AWAY)
-	{
+    // handle automatic state transitions (based on completion of animation playback)
+    if (id == ANIM_AGENT_STAND)
+    {
+        stopFidget();
+    }
+    else if (id == ANIM_AGENT_AWAY)
+    {
 // [RLVa:KB] - Checked: 2010-05-03 (RLVa-1.2.0g) | Added: RLVa-1.1.0g
-		if (!gRlvHandler.hasBehaviour(RLV_BHVR_ALLOWIDLE))
-			clearAFK();
+        if (!gRlvHandler.hasBehaviour(RLV_BHVR_ALLOWIDLE))
+            clearAFK();
 // [/RLVa:KB]
-//		clearAFK();
-	}
-	else if (id == ANIM_AGENT_STANDUP)
-	{
-		// send stand up command
-		setControlFlags(AGENT_CONTROL_FINISH_ANIM);
-
-		// now trigger dusting self off animation
-		if (isAgentAvatarValid() && !gAgentAvatarp->mBelowWater && rand() % 3 == 0)
-			sendAnimationRequest( ANIM_AGENT_BRUSH, ANIM_REQUEST_START );
-	}
-	else if (id == ANIM_AGENT_PRE_JUMP || id == ANIM_AGENT_LAND || id == ANIM_AGENT_MEDIUM_LAND)
-	{
-		setControlFlags(AGENT_CONTROL_FINISH_ANIM);
-	}
+//      clearAFK();
+    }
+    else if (id == ANIM_AGENT_STANDUP)
+    {
+        // send stand up command
+        setControlFlags(AGENT_CONTROL_FINISH_ANIM);
+
+        // now trigger dusting self off animation
+        if (isAgentAvatarValid() && !gAgentAvatarp->mBelowWater && rand() % 3 == 0)
+            sendAnimationRequest( ANIM_AGENT_BRUSH, ANIM_REQUEST_START );
+    }
+    else if (id == ANIM_AGENT_PRE_JUMP || id == ANIM_AGENT_LAND || id == ANIM_AGENT_MEDIUM_LAND)
+    {
+        setControlFlags(AGENT_CONTROL_FINISH_ANIM);
+    }
 }
 
 bool LLAgent::isGodlike() const
 {
-	return mAgentAccess->isGodlike();
+    return mAgentAccess->isGodlike();
 }
 
 bool LLAgent::isGodlikeWithoutAdminMenuFakery() const
 {
-	return mAgentAccess->isGodlikeWithoutAdminMenuFakery();
+    return mAgentAccess->isGodlikeWithoutAdminMenuFakery();
 }
 
 U8 LLAgent::getGodLevel() const
 {
-	return mAgentAccess->getGodLevel();
+    return mAgentAccess->getGodLevel();
 }
 
 bool LLAgent::wantsPGOnly() const
 {
-	return mAgentAccess->wantsPGOnly();
+    return mAgentAccess->wantsPGOnly();
 }
 
 bool LLAgent::canAccessMature() const
 {
-	return mAgentAccess->canAccessMature();
+    return mAgentAccess->canAccessMature();
 }
 
 bool LLAgent::canAccessAdult() const
 {
-	return mAgentAccess->canAccessAdult();
+    return mAgentAccess->canAccessAdult();
 }
 
 bool LLAgent::canAccessMaturityInRegion( U64 region_handle ) const
 {
-	LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromHandle( region_handle );
-	if( regionp )
-	{
-		switch( regionp->getSimAccess() )
-		{
-			case SIM_ACCESS_MATURE:
-				if( !canAccessMature() )
-					return false;
-				break;
-			case SIM_ACCESS_ADULT:
-				if( !canAccessAdult() )
-					return false;
-				break;
-			default:
-				// Oh, go on and hear the silly noises.
-				break;
-		}
-	}
-	
-	return true;
+    LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromHandle( region_handle );
+    if( regionp )
+    {
+        switch( regionp->getSimAccess() )
+        {
+            case SIM_ACCESS_MATURE:
+                if( !canAccessMature() )
+                    return false;
+                break;
+            case SIM_ACCESS_ADULT:
+                if( !canAccessAdult() )
+                    return false;
+                break;
+            default:
+                // Oh, go on and hear the silly noises.
+                break;
+        }
+    }
+
+    return true;
 }
 
 bool LLAgent::canAccessMaturityAtGlobal( LLVector3d pos_global ) const
 {
-	U64 region_handle = to_region_handle_global( pos_global.mdV[0], pos_global.mdV[1] );
-	return canAccessMaturityInRegion( region_handle );
+    U64 region_handle = to_region_handle_global( pos_global.mdV[0], pos_global.mdV[1] );
+    return canAccessMaturityInRegion( region_handle );
 }
 
 bool LLAgent::prefersPG() const
 {
-	return mAgentAccess->prefersPG();
+    return mAgentAccess->prefersPG();
 }
 
 bool LLAgent::prefersMature() const
 {
-	return mAgentAccess->prefersMature();
+    return mAgentAccess->prefersMature();
 }
-	
+
 bool LLAgent::prefersAdult() const
 {
-	return mAgentAccess->prefersAdult();
+    return mAgentAccess->prefersAdult();
 }
 
 bool LLAgent::isTeen() const
 {
-	return mAgentAccess->isTeen();
+    return mAgentAccess->isTeen();
 }
 
 bool LLAgent::isMature() const
 {
-	return mAgentAccess->isMature();
+    return mAgentAccess->isMature();
 }
 
 bool LLAgent::isAdult() const
 {
-	return mAgentAccess->isAdult();
+    return mAgentAccess->isAdult();
 }
 
-//static 
+//static
 int LLAgent::convertTextToMaturity(char text)
 {
-	return LLAgentAccess::convertTextToMaturity(text);
+    return LLAgentAccess::convertTextToMaturity(text);
 }
 
 void LLAgent::handlePreferredMaturityResult(U8 pServerMaturity)
 {
-	// Update the number of responses received
-	++mMaturityPreferenceResponseId;
-	llassert(mMaturityPreferenceResponseId <= mMaturityPreferenceRequestId);
-
-	// Update the last known server maturity response
-	mLastKnownResponseMaturity = pServerMaturity;
-
-	// Ignore all responses if we know there are more unanswered requests that are expected
-	if (mMaturityPreferenceResponseId == mMaturityPreferenceRequestId)
-	{
-		// If we received a response that matches the last known request, then we are good
-		if (mLastKnownRequestMaturity == mLastKnownResponseMaturity)
-		{
-			mMaturityPreferenceNumRetries = 0;
-			reportPreferredMaturitySuccess();
-			llassert(static_cast<U8>(ALControlCache::PreferredMaturity) == mLastKnownResponseMaturity);
-		}
-		// Else, the viewer is out of sync with the server, so let's try to re-sync with the
-		// server by re-sending our last known request.  Cap the re-tries at 3 just to be safe.
-		else if (++mMaturityPreferenceNumRetries <= 3)
-		{
-			LL_INFOS() << "Retrying attempt #" << mMaturityPreferenceNumRetries << " to set viewer preferred maturity to '"
-				<< LLViewerRegion::accessToString(mLastKnownRequestMaturity) << "'" << LL_ENDL;
-			sendMaturityPreferenceToServer(mLastKnownRequestMaturity);
-		}
-		// Else, the viewer is style out of sync with the server after 3 retries, so inform the user
-		else
-		{
-			mMaturityPreferenceNumRetries = 0;
-			LL_WARNS() << "Too many retries for maturity preference" << LL_ENDL;
-			reportPreferredMaturityError();
-		}
-	}
+    // Update the number of responses received
+    ++mMaturityPreferenceResponseId;
+    llassert(mMaturityPreferenceResponseId <= mMaturityPreferenceRequestId);
+
+    // Update the last known server maturity response
+    mLastKnownResponseMaturity = pServerMaturity;
+
+    // Ignore all responses if we know there are more unanswered requests that are expected
+    if (mMaturityPreferenceResponseId == mMaturityPreferenceRequestId)
+    {
+        // If we received a response that matches the last known request, then we are good
+        if (mLastKnownRequestMaturity == mLastKnownResponseMaturity)
+        {
+            mMaturityPreferenceNumRetries = 0;
+            reportPreferredMaturitySuccess();
+            llassert(static_cast<U8>(ALControlCache::PreferredMaturity) == mLastKnownResponseMaturity);
+        }
+        // Else, the viewer is out of sync with the server, so let's try to re-sync with the
+        // server by re-sending our last known request.  Cap the re-tries at 3 just to be safe.
+        else if (++mMaturityPreferenceNumRetries <= 3)
+        {
+            LL_INFOS() << "Retrying attempt #" << mMaturityPreferenceNumRetries << " to set viewer preferred maturity to '"
+                << LLViewerRegion::accessToString(mLastKnownRequestMaturity) << "'" << LL_ENDL;
+            sendMaturityPreferenceToServer(mLastKnownRequestMaturity);
+        }
+        // Else, the viewer is style out of sync with the server after 3 retries, so inform the user
+        else
+        {
+            mMaturityPreferenceNumRetries = 0;
+            LL_WARNS() << "Too many retries for maturity preference" << LL_ENDL;
+            reportPreferredMaturityError();
+        }
+    }
 }
 
 void LLAgent::handlePreferredMaturityError()
 {
-	// Update the number of responses received
-	++mMaturityPreferenceResponseId;
-	llassert(mMaturityPreferenceResponseId <= mMaturityPreferenceRequestId);
-
-	// Ignore all responses if we know there are more unanswered requests that are expected
-	if (mMaturityPreferenceResponseId == mMaturityPreferenceRequestId)
-	{
-		mMaturityPreferenceNumRetries = 0;
-
-		// If we received a response that matches the last known request, then we are synced with
-		// the server, but not quite sure why we are
-		if (mLastKnownRequestMaturity == mLastKnownResponseMaturity)
-		{
-			LL_WARNS() << "Got an error but maturity preference '" << LLViewerRegion::accessToString(mLastKnownRequestMaturity)
-				<< "' seems to be in sync with the server" << LL_ENDL;
-			reportPreferredMaturitySuccess();
-		}
-		// Else, the more likely case is that the last request does not match the last response,
-		// so inform the user
-		else
-		{
-			reportPreferredMaturityError();
-		}
-	}
+    // Update the number of responses received
+    ++mMaturityPreferenceResponseId;
+    llassert(mMaturityPreferenceResponseId <= mMaturityPreferenceRequestId);
+
+    // Ignore all responses if we know there are more unanswered requests that are expected
+    if (mMaturityPreferenceResponseId == mMaturityPreferenceRequestId)
+    {
+        mMaturityPreferenceNumRetries = 0;
+
+        // If we received a response that matches the last known request, then we are synced with
+        // the server, but not quite sure why we are
+        if (mLastKnownRequestMaturity == mLastKnownResponseMaturity)
+        {
+            LL_WARNS() << "Got an error but maturity preference '" << LLViewerRegion::accessToString(mLastKnownRequestMaturity)
+                << "' seems to be in sync with the server" << LL_ENDL;
+            reportPreferredMaturitySuccess();
+        }
+        // Else, the more likely case is that the last request does not match the last response,
+        // so inform the user
+        else
+        {
+            reportPreferredMaturityError();
+        }
+    }
 }
 
 void LLAgent::reportPreferredMaturitySuccess()
 {
-	// If there is a pending teleport request waiting for the maturity preference to be synced with
-	// the server, let's start the pending request
-	if (hasPendingTeleportRequest())
-	{
-		startTeleportRequest();
-	}
+    // If there is a pending teleport request waiting for the maturity preference to be synced with
+    // the server, let's start the pending request
+    if (hasPendingTeleportRequest())
+    {
+        startTeleportRequest();
+    }
 }
 
 void LLAgent::reportPreferredMaturityError()
 {
-	// If there is a pending teleport request waiting for the maturity preference to be synced with
-	// the server, we were unable to successfully sync with the server on maturity preference, so let's
-	// just raise the screen.
-	mIsMaturityRatingChangingDuringTeleport = false;
-	if (hasPendingTeleportRequest())
-	{
-		LL_WARNS("Teleport") << "Teleport failing due to preferred maturity error" << LL_ENDL;
-		setTeleportState(LLAgent::TELEPORT_NONE);
-	}
-
-	// Get the last known maturity request from the user activity
-	std::string preferredMaturity = LLViewerRegion::accessToString(mLastKnownRequestMaturity);
-	LLStringUtil::toLower(preferredMaturity);
-
-	// Get the last known maturity response from the server
-	std::string actualMaturity = LLViewerRegion::accessToString(mLastKnownResponseMaturity);
-	LLStringUtil::toLower(actualMaturity);
-
-	// Notify the user
-	LLSD args = LLSD::emptyMap();
-	args["PREFERRED_MATURITY"] = preferredMaturity;
-	args["ACTUAL_MATURITY"] = actualMaturity;
-	LLNotificationsUtil::add("MaturityChangeError", args);
-
-	// Check the saved settings to ensure that we are consistent.  If we are not consistent, update
-	// the viewer, but do not send anything to server
-	U8 localMaturity = static_cast<U8>(ALControlCache::PreferredMaturity);
-	if (localMaturity != mLastKnownResponseMaturity)
-	{
-		bool tmpIsDoSendMaturityPreferenceToServer = mIsDoSendMaturityPreferenceToServer;
-		mIsDoSendMaturityPreferenceToServer = false;
-		LL_INFOS() << "Setting viewer preferred maturity to '" << LLViewerRegion::accessToString(mLastKnownResponseMaturity) << "'" << LL_ENDL;
-		gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(mLastKnownResponseMaturity));
-		mIsDoSendMaturityPreferenceToServer = tmpIsDoSendMaturityPreferenceToServer;
-	}
+    // If there is a pending teleport request waiting for the maturity preference to be synced with
+    // the server, we were unable to successfully sync with the server on maturity preference, so let's
+    // just raise the screen.
+    mIsMaturityRatingChangingDuringTeleport = false;
+    if (hasPendingTeleportRequest())
+    {
+        LL_WARNS("Teleport") << "Teleport failing due to preferred maturity error" << LL_ENDL;
+        setTeleportState(LLAgent::TELEPORT_NONE);
+    }
+
+    // Get the last known maturity request from the user activity
+    std::string preferredMaturity = LLViewerRegion::accessToString(mLastKnownRequestMaturity);
+    LLStringUtil::toLower(preferredMaturity);
+
+    // Get the last known maturity response from the server
+    std::string actualMaturity = LLViewerRegion::accessToString(mLastKnownResponseMaturity);
+    LLStringUtil::toLower(actualMaturity);
+
+    // Notify the user
+    LLSD args = LLSD::emptyMap();
+    args["PREFERRED_MATURITY"] = preferredMaturity;
+    args["ACTUAL_MATURITY"] = actualMaturity;
+    LLNotificationsUtil::add("MaturityChangeError", args);
+
+    // Check the saved settings to ensure that we are consistent.  If we are not consistent, update
+    // the viewer, but do not send anything to server
+    U8 localMaturity = static_cast<U8>(ALControlCache::PreferredMaturity);
+    if (localMaturity != mLastKnownResponseMaturity)
+    {
+        bool tmpIsDoSendMaturityPreferenceToServer = mIsDoSendMaturityPreferenceToServer;
+        mIsDoSendMaturityPreferenceToServer = false;
+        LL_INFOS() << "Setting viewer preferred maturity to '" << LLViewerRegion::accessToString(mLastKnownResponseMaturity) << "'" << LL_ENDL;
+        gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(mLastKnownResponseMaturity));
+        mIsDoSendMaturityPreferenceToServer = tmpIsDoSendMaturityPreferenceToServer;
+    }
 }
 
 bool LLAgent::isMaturityPreferenceSyncedWithServer() const
 {
-	return (mMaturityPreferenceRequestId == mMaturityPreferenceResponseId);
+    return (mMaturityPreferenceRequestId == mMaturityPreferenceResponseId);
 }
 
 void LLAgent::sendMaturityPreferenceToServer(U8 pPreferredMaturity)
 {
-	// Only send maturity preference to the server if enabled
-	if (mIsDoSendMaturityPreferenceToServer)
-	{
-		// Increment the number of requests.  The handlers manage a separate count of responses.
-		++mMaturityPreferenceRequestId;
+    // Only send maturity preference to the server if enabled
+    if (mIsDoSendMaturityPreferenceToServer)
+    {
+        // Increment the number of requests.  The handlers manage a separate count of responses.
+        ++mMaturityPreferenceRequestId;
 
-		// Update the last know maturity request
-		mLastKnownRequestMaturity = pPreferredMaturity;
+        // Update the last know maturity request
+        mLastKnownRequestMaturity = pPreferredMaturity;
 
-		// If we don't have a region, report it as an error
-		if (getRegion() == NULL)
-		{
-			LL_WARNS("Agent") << "Region is not defined, can not change Maturity setting." << LL_ENDL;
-			return;
-		}
+        // If we don't have a region, report it as an error
+        if (getRegion() == NULL)
+        {
+            LL_WARNS("Agent") << "Region is not defined, can not change Maturity setting." << LL_ENDL;
+            return;
+        }
 
-		LLSD access_prefs = LLSD::emptyMap();
-		access_prefs["max"] = LLViewerRegion::accessToShortString(pPreferredMaturity);
+        LLSD access_prefs = LLSD::emptyMap();
+        access_prefs["max"] = LLViewerRegion::accessToShortString(pPreferredMaturity);
 
-		LLSD postData = LLSD::emptyMap();
-		postData["access_prefs"] = access_prefs;
-		LL_INFOS() << "Sending viewer preferred maturity to '" << LLViewerRegion::accessToString(pPreferredMaturity) << LL_ENDL;
+        LLSD postData = LLSD::emptyMap();
+        postData["access_prefs"] = access_prefs;
+        LL_INFOS() << "Sending viewer preferred maturity to '" << LLViewerRegion::accessToString(pPreferredMaturity) << LL_ENDL;
 
         if (!requestPostCapability("UpdateAgentInformation", postData,
             static_cast<httpCallback_t>(boost::bind(&LLAgent::processMaturityPreferenceFromServer, this, _1, pPreferredMaturity)),
@@ -3164,7 +3164,7 @@ void LLAgent::sendMaturityPreferenceToServer(U8 pPreferredMaturity)
         {
             LL_WARNS("Agent") << "Maturity request post failed." << LL_ENDL;
         }
-	}
+    }
 }
 
 
@@ -3231,10 +3231,10 @@ void LLAgent::changeInterestListMode(const std::string &new_mode)
             }
         }
     }
-	else
-	{
-		LL_DEBUGS("360Capture") << "Agent interest list mode is already set to " << mInterestListMode << LL_ENDL;
-	}
+    else
+    {
+        LL_DEBUGS("360Capture") << "Agent interest list mode is already set to " << mInterestListMode << LL_ENDL;
+    }
 }
 
 
@@ -3244,7 +3244,7 @@ bool LLAgent::requestPostCapability(const std::string &capName, LLSD &postData,
     {
         return getRegion()->requestPostCapability(capName, postData, cbSuccess, cbFailure);
     }
-	return false;
+    return false;
 }
 
 bool LLAgent::requestGetCapability(const std::string &capName, httpCallback_t cbSuccess, httpCallback_t cbFailure)
@@ -3256,45 +3256,45 @@ bool LLAgent::requestGetCapability(const std::string &capName, httpCallback_t cb
     return false;
 }
 
-BOOL LLAgent::getAdminOverride() const	
-{ 
-	return mAgentAccess->getAdminOverride(); 
+BOOL LLAgent::getAdminOverride() const
+{
+    return mAgentAccess->getAdminOverride();
 }
 
 void LLAgent::setMaturity(char text)
 {
-	mAgentAccess->setMaturity(text);
+    mAgentAccess->setMaturity(text);
 }
 
-void LLAgent::setAdminOverride(BOOL b)	
-{ 
-	mAgentAccess->setAdminOverride(b);
+void LLAgent::setAdminOverride(BOOL b)
+{
+    mAgentAccess->setAdminOverride(b);
 }
 
-void LLAgent::setGodLevel(U8 god_level)	
-{ 
-	mAgentAccess->setGodLevel(god_level);
-	mGodLevelChangeSignal(god_level);
+void LLAgent::setGodLevel(U8 god_level)
+{
+    mAgentAccess->setGodLevel(god_level);
+    mGodLevelChangeSignal(god_level);
 }
 
 LLAgent::god_level_change_slot_t LLAgent::registerGodLevelChanageListener(god_level_change_callback_t pGodLevelChangeCallback)
 {
-	return mGodLevelChangeSignal.connect(pGodLevelChangeCallback);
+    return mGodLevelChangeSignal.connect(pGodLevelChangeCallback);
 }
 
 const LLAgentAccess& LLAgent::getAgentAccess()
 {
-	return *mAgentAccess;
+    return *mAgentAccess;
 }
 
 bool LLAgent::validateMaturity(const LLSD& newvalue)
 {
-	return mAgentAccess->canSetMaturity(newvalue.asInteger());
+    return mAgentAccess->canSetMaturity(newvalue.asInteger());
 }
 
 void LLAgent::handleMaturity(const LLSD &pNewValue)
 {
-	sendMaturityPreferenceToServer(static_cast<U8>(pNewValue.asInteger()));
+    sendMaturityPreferenceToServer(static_cast<U8>(pNewValue.asInteger()));
 }
 
 //----------------------------------------------------------------------------
@@ -3302,270 +3302,270 @@ void LLAgent::handleMaturity(const LLSD &pNewValue)
 //*TODO remove, is not used anywhere as of August 20, 2009
 void LLAgent::buildFullnameAndTitle(std::string& name) const
 {
-	if (isGroupMember())
-	{
-		name = mGroupTitle;
-		name += ' ';
-	}
-	else
-	{
-		name.erase(0, name.length());
-	}
+    if (isGroupMember())
+    {
+        name = mGroupTitle;
+        name += ' ';
+    }
+    else
+    {
+        name.erase(0, name.length());
+    }
 
-	if (isAgentAvatarValid())
-	{
-		name += gAgentAvatarp->getFullname();
-	}
+    if (isAgentAvatarValid())
+    {
+        name += gAgentAvatarp->getFullname();
+    }
 }
 
 BOOL LLAgent::isInGroup(const LLUUID& group_id, BOOL ignore_god_mode /* FALSE */) const
 {
-	if (!ignore_god_mode && isGodlike())
-		return true;
+    if (!ignore_god_mode && isGodlike())
+        return true;
 
-	U32 count = mGroups.size();
-	for(U32 i = 0; i < count; ++i)
-	{
-		if(mGroups[i].mID == group_id)
-		{
-			return TRUE;
-		}
-	}
-	return FALSE;
+    U32 count = mGroups.size();
+    for(U32 i = 0; i < count; ++i)
+    {
+        if(mGroups[i].mID == group_id)
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 // This implementation should mirror LLAgentInfo::hasPowerInGroup
 BOOL LLAgent::hasPowerInGroup(const LLUUID& group_id, U64 power) const
 {
-	if (isGodlikeWithoutAdminMenuFakery())
-		return true;
+    if (isGodlikeWithoutAdminMenuFakery())
+        return true;
 
-	// GP_NO_POWERS can also mean no power is enough to grant an ability.
-	if (GP_NO_POWERS == power) return FALSE;
+    // GP_NO_POWERS can also mean no power is enough to grant an ability.
+    if (GP_NO_POWERS == power) return FALSE;
 
-	U32 count = mGroups.size();
-	for(U32 i = 0; i < count; ++i)
-	{
-		if(mGroups[i].mID == group_id)
-		{
-			return (BOOL)((mGroups[i].mPowers & power) > 0);
-		}
-	}
-	return FALSE;
+    U32 count = mGroups.size();
+    for(U32 i = 0; i < count; ++i)
+    {
+        if(mGroups[i].mID == group_id)
+        {
+            return (BOOL)((mGroups[i].mPowers & power) > 0);
+        }
+    }
+    return FALSE;
 }
 
 BOOL LLAgent::hasPowerInActiveGroup(U64 power) const
 {
-	return (mGroupID.notNull() && (hasPowerInGroup(mGroupID, power)));
+    return (mGroupID.notNull() && (hasPowerInGroup(mGroupID, power)));
 }
 
 U64 LLAgent::getPowerInGroup(const LLUUID& group_id) const
 {
-	if (isGodlike())
-		return GP_ALL_POWERS;
-	
-	U32 count = mGroups.size();
-	for(U32 i = 0; i < count; ++i)
-	{
-		if(mGroups[i].mID == group_id)
-		{
-			return (mGroups[i].mPowers);
-		}
-	}
+    if (isGodlike())
+        return GP_ALL_POWERS;
+
+    U32 count = mGroups.size();
+    for(U32 i = 0; i < count; ++i)
+    {
+        if(mGroups[i].mID == group_id)
+        {
+            return (mGroups[i].mPowers);
+        }
+    }
 
-	return GP_NO_POWERS;
+    return GP_NO_POWERS;
 }
 
 BOOL LLAgent::getGroupData(const LLUUID& group_id, LLGroupData& data) const
 {
-	S32 count = mGroups.size();
-	for(S32 i = 0; i < count; ++i)
-	{
-		if(mGroups[i].mID == group_id)
-		{
-			data = mGroups[i];
-			return TRUE;
-		}
-	}
-	return FALSE;
+    S32 count = mGroups.size();
+    for(S32 i = 0; i < count; ++i)
+    {
+        if(mGroups[i].mID == group_id)
+        {
+            data = mGroups[i];
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 S32 LLAgent::getGroupContribution(const LLUUID& group_id) const
 {
-	S32 count = mGroups.size();
-	for(S32 i = 0; i < count; ++i)
-	{
-		if(mGroups[i].mID == group_id)
-		{
-			S32 contribution = mGroups[i].mContribution;
-			return contribution;
-		}
-	}
-	return 0;
+    S32 count = mGroups.size();
+    for(S32 i = 0; i < count; ++i)
+    {
+        if(mGroups[i].mID == group_id)
+        {
+            S32 contribution = mGroups[i].mContribution;
+            return contribution;
+        }
+    }
+    return 0;
 }
 
 BOOL LLAgent::setGroupContribution(const LLUUID& group_id, S32 contribution)
 {
-	S32 count = mGroups.size();
-	for(S32 i = 0; i < count; ++i)
-	{
-		if(mGroups[i].mID == group_id)
-		{
-			mGroups[i].mContribution = contribution;
-			LLMessageSystem* msg = gMessageSystem;
-			msg->newMessageFast(_PREHASH_SetGroupContribution);
-			msg->nextBlockFast(_PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
-			msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
-			msg->nextBlockFast(_PREHASH_Data);
-			msg->addUUIDFast(_PREHASH_GroupID, group_id);
-			msg->addS32Fast(_PREHASH_Contribution, contribution);
-			sendReliableMessage();
-			return TRUE;
-		}
-	}
-	return FALSE;
+    S32 count = mGroups.size();
+    for(S32 i = 0; i < count; ++i)
+    {
+        if(mGroups[i].mID == group_id)
+        {
+            mGroups[i].mContribution = contribution;
+            LLMessageSystem* msg = gMessageSystem;
+            msg->newMessageFast(_PREHASH_SetGroupContribution);
+            msg->nextBlockFast(_PREHASH_AgentData);
+            msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
+            msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
+            msg->nextBlockFast(_PREHASH_Data);
+            msg->addUUIDFast(_PREHASH_GroupID, group_id);
+            msg->addS32Fast(_PREHASH_Contribution, contribution);
+            sendReliableMessage();
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 BOOL LLAgent::setUserGroupFlags(const LLUUID& group_id, BOOL accept_notices, BOOL list_in_profile)
 {
-	S32 count = mGroups.size();
-	for(S32 i = 0; i < count; ++i)
-	{
-		if(mGroups[i].mID == group_id)
-		{
-			mGroups[i].mAcceptNotices = accept_notices;
-			mGroups[i].mListInProfile = list_in_profile;
-			LLMessageSystem* msg = gMessageSystem;
-			msg->newMessageFast(_PREHASH_SetGroupAcceptNotices);
-			msg->nextBlockFast(_PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
-			msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
-			msg->nextBlockFast(_PREHASH_Data);
-			msg->addUUIDFast(_PREHASH_GroupID, group_id);
-			msg->addBOOLFast(_PREHASH_AcceptNotices, accept_notices);
-			msg->nextBlockFast(_PREHASH_NewData);
-			msg->addBOOLFast(_PREHASH_ListInProfile, list_in_profile);
-			sendReliableMessage();
-			return TRUE;
-		}
-	}
-	return FALSE;
+    S32 count = mGroups.size();
+    for(S32 i = 0; i < count; ++i)
+    {
+        if(mGroups[i].mID == group_id)
+        {
+            mGroups[i].mAcceptNotices = accept_notices;
+            mGroups[i].mListInProfile = list_in_profile;
+            LLMessageSystem* msg = gMessageSystem;
+            msg->newMessageFast(_PREHASH_SetGroupAcceptNotices);
+            msg->nextBlockFast(_PREHASH_AgentData);
+            msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
+            msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
+            msg->nextBlockFast(_PREHASH_Data);
+            msg->addUUIDFast(_PREHASH_GroupID, group_id);
+            msg->addBOOLFast(_PREHASH_AcceptNotices, accept_notices);
+            msg->nextBlockFast(_PREHASH_NewData);
+            msg->addBOOLFast(_PREHASH_ListInProfile, list_in_profile);
+            sendReliableMessage();
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 BOOL LLAgent::canJoinGroups() const
 {
-	return (S32)mGroups.size() < LLAgentBenefitsMgr::current().getGroupMembershipLimit();
+    return (S32)mGroups.size() < LLAgentBenefitsMgr::current().getGroupMembershipLimit();
 }
 
 LLQuaternion LLAgent::getHeadRotation()
 {
-	if (!isAgentAvatarValid() || !gAgentAvatarp->mPelvisp || !gAgentAvatarp->mHeadp)
-	{
-		return LLQuaternion::DEFAULT;
-	}
+    if (!isAgentAvatarValid() || !gAgentAvatarp->mPelvisp || !gAgentAvatarp->mHeadp)
+    {
+        return LLQuaternion::DEFAULT;
+    }
 
-	if (!gAgentCamera.cameraMouselook())
-	{
-		return gAgentAvatarp->getRotation();
-	}
+    if (!gAgentCamera.cameraMouselook())
+    {
+        return gAgentAvatarp->getRotation();
+    }
 
-	// We must be in mouselook
-	LLVector3 look_dir( LLViewerCamera::getInstance()->getAtAxis() );
-	LLVector3 up = look_dir % mFrameAgent.getLeftAxis();
-	LLVector3 left = up % look_dir;
+    // We must be in mouselook
+    LLVector3 look_dir( LLViewerCamera::getInstance()->getAtAxis() );
+    LLVector3 up = look_dir % mFrameAgent.getLeftAxis();
+    LLVector3 left = up % look_dir;
 
-	LLQuaternion rot(look_dir, left, up);
-	if (gAgentAvatarp->getParent())
-	{
-		rot = rot * ~gAgentAvatarp->getParent()->getRotation();
-	}
+    LLQuaternion rot(look_dir, left, up);
+    if (gAgentAvatarp->getParent())
+    {
+        rot = rot * ~gAgentAvatarp->getParent()->getRotation();
+    }
 
-	return rot;
+    return rot;
 }
 
 void LLAgent::sendAnimationRequests(const std::vector<LLUUID> &anim_ids, EAnimRequest request)
 {
-	if (gAgentID.isNull())
-	{
-		return;
-	}
-
-	S32 num_valid_anims = 0;
-
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_AgentAnimation);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, getID());
-	msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
-
-	for (S32 i = 0; i < anim_ids.size(); i++)
-	{
-		if (anim_ids[i].isNull())
-		{
-			continue;
-		}
-		msg->nextBlockFast(_PREHASH_AnimationList);
-		msg->addUUIDFast(_PREHASH_AnimID, (anim_ids[i]) );
-		msg->addBOOLFast(_PREHASH_StartAnim, (request == ANIM_REQUEST_START) ? TRUE : FALSE);
-		num_valid_anims++;
-	}
-	if (!num_valid_anims)
-	{
-		msg->clearMessage();
-		return;
-	}
-	
-	msg->nextBlockFast(_PREHASH_PhysicalAvatarEventList);
-	msg->addBinaryDataFast(_PREHASH_TypeData, NULL, 0);
-
-	sendReliableMessage();
+    if (gAgentID.isNull())
+    {
+        return;
+    }
+
+    S32 num_valid_anims = 0;
+
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_AgentAnimation);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, getID());
+    msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+
+    for (S32 i = 0; i < anim_ids.size(); i++)
+    {
+        if (anim_ids[i].isNull())
+        {
+            continue;
+        }
+        msg->nextBlockFast(_PREHASH_AnimationList);
+        msg->addUUIDFast(_PREHASH_AnimID, (anim_ids[i]) );
+        msg->addBOOLFast(_PREHASH_StartAnim, (request == ANIM_REQUEST_START) ? TRUE : FALSE);
+        num_valid_anims++;
+    }
+    if (!num_valid_anims)
+    {
+        msg->clearMessage();
+        return;
+    }
+
+    msg->nextBlockFast(_PREHASH_PhysicalAvatarEventList);
+    msg->addBinaryDataFast(_PREHASH_TypeData, NULL, 0);
+
+    sendReliableMessage();
 }
 
 void LLAgent::sendAnimationRequest(const LLUUID &anim_id, EAnimRequest request)
 {
-	if (gAgentID.isNull() || anim_id.isNull() || !mRegionp)
-	{
-		return;
-	}
+    if (gAgentID.isNull() || anim_id.isNull() || !mRegionp)
+    {
+        return;
+    }
 
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_AgentAnimation);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, getID());
-	msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_AgentAnimation);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, getID());
+    msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
 
-	msg->nextBlockFast(_PREHASH_AnimationList);
-	msg->addUUIDFast(_PREHASH_AnimID, (anim_id) );
-	msg->addBOOLFast(_PREHASH_StartAnim, (request == ANIM_REQUEST_START) ? TRUE : FALSE);
+    msg->nextBlockFast(_PREHASH_AnimationList);
+    msg->addUUIDFast(_PREHASH_AnimID, (anim_id) );
+    msg->addBOOLFast(_PREHASH_StartAnim, (request == ANIM_REQUEST_START) ? TRUE : FALSE);
 
-	msg->nextBlockFast(_PREHASH_PhysicalAvatarEventList);
-	msg->addBinaryDataFast(_PREHASH_TypeData, NULL, 0);
-	sendReliableMessage();
+    msg->nextBlockFast(_PREHASH_PhysicalAvatarEventList);
+    msg->addBinaryDataFast(_PREHASH_TypeData, NULL, 0);
+    sendReliableMessage();
 }
 
 // Send a message to the region to stop the NULL animation state
 // This will reset animation state overrides for the agent.
 void LLAgent::sendAnimationStateReset()
 {
-	if (gAgentID.isNull() || !mRegionp)
-	{
-		return;
-	}
+    if (gAgentID.isNull() || !mRegionp)
+    {
+        return;
+    }
 
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_AgentAnimation);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, getID());
-	msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_AgentAnimation);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, getID());
+    msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
 
-	msg->nextBlockFast(_PREHASH_AnimationList);
-	msg->addUUIDFast(_PREHASH_AnimID, LLUUID::null );
-	msg->addBOOLFast(_PREHASH_StartAnim, FALSE);
+    msg->nextBlockFast(_PREHASH_AnimationList);
+    msg->addUUIDFast(_PREHASH_AnimID, LLUUID::null );
+    msg->addBOOLFast(_PREHASH_StartAnim, FALSE);
 
-	msg->nextBlockFast(_PREHASH_PhysicalAvatarEventList);
-	msg->addBinaryDataFast(_PREHASH_TypeData, NULL, 0);
-	sendReliableMessage();
+    msg->nextBlockFast(_PREHASH_PhysicalAvatarEventList);
+    msg->addBinaryDataFast(_PREHASH_TypeData, NULL, 0);
+    sendReliableMessage();
 }
 
 
@@ -3574,48 +3574,48 @@ void LLAgent::sendAnimationStateReset()
 // If it is the region ID, all scripts clear the permissions for this agent
 void LLAgent::sendRevokePermissions(const LLUUID & target, U32 permissions)
 {
-	// Currently only the bits for SCRIPT_PERMISSION_TRIGGER_ANIMATION and SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS
-	// are supported by the server.  Sending any other bits will cause the message to be dropped without changing permissions
+    // Currently only the bits for SCRIPT_PERMISSION_TRIGGER_ANIMATION and SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS
+    // are supported by the server.  Sending any other bits will cause the message to be dropped without changing permissions
 
-	if (gAgentID.notNull() && gMessageSystem)
-	{
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_RevokePermissions);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, getID());		// Must be our ID
-		msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+    if (gAgentID.notNull() && gMessageSystem)
+    {
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_RevokePermissions);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, getID());        // Must be our ID
+        msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
 
-		msg->nextBlockFast(_PREHASH_Data);
-		msg->addUUIDFast(_PREHASH_ObjectID, target);		// Must be in the region
-		msg->addU32Fast(_PREHASH_ObjectPermissions, permissions);
+        msg->nextBlockFast(_PREHASH_Data);
+        msg->addUUIDFast(_PREHASH_ObjectID, target);        // Must be in the region
+        msg->addU32Fast(_PREHASH_ObjectPermissions, permissions);
 
-		sendReliableMessage();
-	}
+        sendReliableMessage();
+    }
 }
 
 // [RLVa:KB] - Checked: 2011-05-11 (RLVa-1.3.0i) | Added: RLVa-1.3.0i
 void LLAgent::setAlwaysRun()
 {
-	mbAlwaysRun = (!rlv_handler_t::isEnabled()) || (!gRlvHandler.hasBehaviour(RLV_BHVR_ALWAYSRUN));
-	sendWalkRun();
+    mbAlwaysRun = (!rlv_handler_t::isEnabled()) || (!gRlvHandler.hasBehaviour(RLV_BHVR_ALWAYSRUN));
+    sendWalkRun();
 }
 
 void LLAgent::setTempRun()
 {
-	mbTempRun = (!rlv_handler_t::isEnabled()) || (!gRlvHandler.hasBehaviour(RLV_BHVR_TEMPRUN));
-	sendWalkRun();
+    mbTempRun = (!rlv_handler_t::isEnabled()) || (!gRlvHandler.hasBehaviour(RLV_BHVR_TEMPRUN));
+    sendWalkRun();
 }
 
 void LLAgent::clearAlwaysRun()
 {
-	mbAlwaysRun = false;
-	sendWalkRun();
+    mbAlwaysRun = false;
+    sendWalkRun();
 }
 
 void LLAgent::clearTempRun()
 {
-	mbTempRun = false;
-	sendWalkRun();
+    mbTempRun = false;
+    sendWalkRun();
 }
 // [/RLVa:KB]
 
@@ -3624,636 +3624,636 @@ void LLAgent::clearTempRun()
 void LLAgent::sendWalkRun()
 // [/RLVa:KB]
 {
-	LLMessageSystem* msgsys = gMessageSystem;
-	if (msgsys)
-	{
-		msgsys->newMessageFast(_PREHASH_SetAlwaysRun);
-		msgsys->nextBlockFast(_PREHASH_AgentData);
-		msgsys->addUUIDFast(_PREHASH_AgentID, getID());
-		msgsys->addUUIDFast(_PREHASH_SessionID, getSessionID());
-//		msgsys->addBOOLFast(_PREHASH_AlwaysRun, BOOL(running) );
+    LLMessageSystem* msgsys = gMessageSystem;
+    if (msgsys)
+    {
+        msgsys->newMessageFast(_PREHASH_SetAlwaysRun);
+        msgsys->nextBlockFast(_PREHASH_AgentData);
+        msgsys->addUUIDFast(_PREHASH_AgentID, getID());
+        msgsys->addUUIDFast(_PREHASH_SessionID, getSessionID());
+//      msgsys->addBOOLFast(_PREHASH_AlwaysRun, BOOL(running) );
 // [RLVa:KB] - Checked: 2011-05-11 (RLVa-1.3.0i) | Added: RLVa-1.3.0i
-		msgsys->addBOOLFast(_PREHASH_AlwaysRun, BOOL(getRunning()) );
+        msgsys->addBOOLFast(_PREHASH_AlwaysRun, BOOL(getRunning()) );
 // [/RLVa:KB]
-		sendReliableMessage();
-	}
+        sendReliableMessage();
+    }
 }
 
 void LLAgent::friendsChanged()
 {
-	LLCollectProxyBuddies collector;
-	LLAvatarTracker::instance().applyFunctor(collector);
-	mProxyForAgents = collector.mProxy;
+    LLCollectProxyBuddies collector;
+    LLAvatarTracker::instance().applyFunctor(collector);
+    mProxyForAgents = collector.mProxy;
 }
 
 BOOL LLAgent::isGrantedProxy(const LLPermissions& perm)
 {
-	return (mProxyForAgents.count(perm.getOwner()) > 0);
+    return (mProxyForAgents.count(perm.getOwner()) > 0);
 }
 
 BOOL LLAgent::allowOperation(PermissionBit op,
-							 const LLPermissions& perm,
-							 U64 group_proxy_power,
-							 U8 god_minimum)
-{
-	// Check god level.
-	if (getGodLevel() >= god_minimum) return TRUE;
-
-	if (!perm.isOwned()) return FALSE;
-
-	// A group member with group_proxy_power can act as owner.
-	BOOL is_group_owned;
-	LLUUID owner_id;
-	perm.getOwnership(owner_id, is_group_owned);
-	LLUUID group_id(perm.getGroup());
-	LLUUID agent_proxy(getID());
-
-	if (is_group_owned)
-	{
-		if (hasPowerInGroup(group_id, group_proxy_power))
-		{
-			// Let the member assume the group's id for permission requests.
-			agent_proxy = owner_id;
-		}
-	}
-	else
-	{
-		// Check for granted mod permissions.
-		if ((PERM_OWNER != op) && isGrantedProxy(perm))
-		{
-			agent_proxy = owner_id;
-		}
-	}
-
-	// This is the group id to use for permission requests.
-	// Only group members may use this field.
-	LLUUID group_proxy = LLUUID::null;
-	if (group_id.notNull() && isInGroup(group_id))
-	{
-		group_proxy = group_id;
-	}
-
-	// We now have max ownership information.
-	if (PERM_OWNER == op)
-	{
-		// This this was just a check for ownership, we can now return the answer.
-		return (agent_proxy == owner_id);
-	}
-
-	return perm.allowOperationBy(op, agent_proxy, group_proxy);
+                             const LLPermissions& perm,
+                             U64 group_proxy_power,
+                             U8 god_minimum)
+{
+    // Check god level.
+    if (getGodLevel() >= god_minimum) return TRUE;
+
+    if (!perm.isOwned()) return FALSE;
+
+    // A group member with group_proxy_power can act as owner.
+    BOOL is_group_owned;
+    LLUUID owner_id;
+    perm.getOwnership(owner_id, is_group_owned);
+    LLUUID group_id(perm.getGroup());
+    LLUUID agent_proxy(getID());
+
+    if (is_group_owned)
+    {
+        if (hasPowerInGroup(group_id, group_proxy_power))
+        {
+            // Let the member assume the group's id for permission requests.
+            agent_proxy = owner_id;
+        }
+    }
+    else
+    {
+        // Check for granted mod permissions.
+        if ((PERM_OWNER != op) && isGrantedProxy(perm))
+        {
+            agent_proxy = owner_id;
+        }
+    }
+
+    // This is the group id to use for permission requests.
+    // Only group members may use this field.
+    LLUUID group_proxy = LLUUID::null;
+    if (group_id.notNull() && isInGroup(group_id))
+    {
+        group_proxy = group_id;
+    }
+
+    // We now have max ownership information.
+    if (PERM_OWNER == op)
+    {
+        // This this was just a check for ownership, we can now return the answer.
+        return (agent_proxy == owner_id);
+    }
+
+    return perm.allowOperationBy(op, agent_proxy, group_proxy);
 }
 
 const LLColor4 LLAgent::getEffectColor()
 {
-	LLColor4 effect_color = *mEffectColor;
+    LLColor4 effect_color = *mEffectColor;
 
-	//<alchemy> Rainbow Particle Effects
-	static LLCachedControl<bool> AlchemyRainbowEffects(gSavedSettings, "AlchemyRainbowEffects");
-	if(AlchemyRainbowEffects)
-	{
-		LLColor3 rainbow;
-		rainbow.setHSL(fmodf((F32)LLFrameTimer::getElapsedSeconds()/4.f, 1.f), 1.f, 0.5f);
-		effect_color.set(rainbow, 1.0f);
-	}
-	return effect_color;
+    //<alchemy> Rainbow Particle Effects
+    static LLCachedControl<bool> AlchemyRainbowEffects(gSavedSettings, "AlchemyRainbowEffects");
+    if(AlchemyRainbowEffects)
+    {
+        LLColor3 rainbow;
+        rainbow.setHSL(fmodf((F32)LLFrameTimer::getElapsedSeconds()/4.f, 1.f), 1.f, 0.5f);
+        effect_color.set(rainbow, 1.0f);
+    }
+    return effect_color;
 }
 
 void LLAgent::setEffectColor(const LLColor4 &color)
 {
-	*mEffectColor = color;
+    *mEffectColor = color;
 }
 
 void LLAgent::initOriginGlobal(const LLVector3d &origin_global)
 {
-	mAgentOriginGlobal = origin_global;
+    mAgentOriginGlobal = origin_global;
 }
 
-BOOL LLAgent::leftButtonGrabbed() const	
-{ 
-	const BOOL camera_mouse_look = gAgentCamera.cameraMouselook();
-	return (!camera_mouse_look && mControlsTakenCount[CONTROL_LBUTTON_DOWN_INDEX] > 0) 
-		|| (camera_mouse_look && mControlsTakenCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0)
-		|| (!camera_mouse_look && mControlsTakenPassedOnCount[CONTROL_LBUTTON_DOWN_INDEX] > 0)
-		|| (camera_mouse_look && mControlsTakenPassedOnCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0);
+BOOL LLAgent::leftButtonGrabbed() const
+{
+    const BOOL camera_mouse_look = gAgentCamera.cameraMouselook();
+    return (!camera_mouse_look && mControlsTakenCount[CONTROL_LBUTTON_DOWN_INDEX] > 0)
+        || (camera_mouse_look && mControlsTakenCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0)
+        || (!camera_mouse_look && mControlsTakenPassedOnCount[CONTROL_LBUTTON_DOWN_INDEX] > 0)
+        || (camera_mouse_look && mControlsTakenPassedOnCount[CONTROL_ML_LBUTTON_DOWN_INDEX] > 0);
 }
 
-BOOL LLAgent::rotateGrabbed() const		
-{ 
-	return (mControlsTakenCount[CONTROL_YAW_POS_INDEX] > 0)
-		|| (mControlsTakenCount[CONTROL_YAW_NEG_INDEX] > 0); 
+BOOL LLAgent::rotateGrabbed() const
+{
+    return (mControlsTakenCount[CONTROL_YAW_POS_INDEX] > 0)
+        || (mControlsTakenCount[CONTROL_YAW_NEG_INDEX] > 0);
 }
 
 BOOL LLAgent::forwardGrabbed() const
-{ 
-	return (mControlsTakenCount[CONTROL_AT_POS_INDEX] > 0); 
+{
+    return (mControlsTakenCount[CONTROL_AT_POS_INDEX] > 0);
 }
 
 BOOL LLAgent::backwardGrabbed() const
-{ 
-	return (mControlsTakenCount[CONTROL_AT_NEG_INDEX] > 0); 
+{
+    return (mControlsTakenCount[CONTROL_AT_NEG_INDEX] > 0);
 }
 
-BOOL LLAgent::upGrabbed() const		
-{ 
-	return (mControlsTakenCount[CONTROL_UP_POS_INDEX] > 0); 
+BOOL LLAgent::upGrabbed() const
+{
+    return (mControlsTakenCount[CONTROL_UP_POS_INDEX] > 0);
 }
 
-BOOL LLAgent::downGrabbed() const	
-{ 
-	return (mControlsTakenCount[CONTROL_UP_NEG_INDEX] > 0); 
+BOOL LLAgent::downGrabbed() const
+{
+    return (mControlsTakenCount[CONTROL_UP_NEG_INDEX] > 0);
 }
 
 void update_group_floaters(const LLUUID& group_id)
 {
-	
-	LLGroupActions::refresh(group_id);
-	//*TODO Implement group update for Profile View 
-	// still actual as of July 31, 2009 (DZ)
 
-	gAgent.fireEvent(new LLOldEvents::LLEvent(&gAgent, "new group"), "");
+    LLGroupActions::refresh(group_id);
+    //*TODO Implement group update for Profile View
+    // still actual as of July 31, 2009 (DZ)
+
+    gAgent.fireEvent(new LLOldEvents::LLEvent(&gAgent, "new group"), "");
 }
 
 // static
 void LLAgent::processAgentDropGroup(LLMessageSystem *msg, void **)
 {
-	LLUUID	agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id );
-
-	if (agent_id != gAgentID)
-	{
-		LL_WARNS() << "processAgentDropGroup for agent other than me" << LL_ENDL;
-		return;
-	}
-
-	LLUUID	group_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_GroupID, group_id );
-
-	// Remove the group if it already exists remove it and add the new data to pick up changes.
-	LLGroupData gd;
-	gd.mID = group_id;
-	std::vector<LLGroupData>::iterator found_it = std::find(gAgent.mGroups.begin(), gAgent.mGroups.end(), gd);
-	if (found_it != gAgent.mGroups.end())
-	{
-		gAgent.mGroups.erase(found_it);
+    LLUUID  agent_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id );
+
+    if (agent_id != gAgentID)
+    {
+        LL_WARNS() << "processAgentDropGroup for agent other than me" << LL_ENDL;
+        return;
+    }
+
+    LLUUID  group_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_GroupID, group_id );
+
+    // Remove the group if it already exists remove it and add the new data to pick up changes.
+    LLGroupData gd;
+    gd.mID = group_id;
+    std::vector<LLGroupData>::iterator found_it = std::find(gAgent.mGroups.begin(), gAgent.mGroups.end(), gd);
+    if (found_it != gAgent.mGroups.end())
+    {
+        gAgent.mGroups.erase(found_it);
 // [SL:KB] - Patch: Chat-GroupOptions | Checked: 2012-06-21 (Catznip-3.3)
-		LLGroupOptionsMgr::instance().clearOptions(group_id);
+        LLGroupOptionsMgr::instance().clearOptions(group_id);
 // [/SL:KB]
-		if (gAgent.getGroupID() == group_id)
-		{
-			gAgent.mGroupID.setNull();
-			gAgent.mGroupPowers = 0;
-			gAgent.mGroupName.clear();
-			gAgent.mGroupTitle.clear();
-		}
-		
-		// refresh all group information
-		gAgent.sendAgentDataUpdateRequest();
-
-		LLGroupMgr::getInstance()->clearGroupData(group_id);
-		// close the floater for this group, if any.
-		LLGroupActions::closeGroup(group_id);
-	}
-	else
-	{
-		LL_WARNS() << "processAgentDropGroup, agent is not part of group " << group_id << LL_ENDL;
-	}
+        if (gAgent.getGroupID() == group_id)
+        {
+            gAgent.mGroupID.setNull();
+            gAgent.mGroupPowers = 0;
+            gAgent.mGroupName.clear();
+            gAgent.mGroupTitle.clear();
+        }
+
+        // refresh all group information
+        gAgent.sendAgentDataUpdateRequest();
+
+        LLGroupMgr::getInstance()->clearGroupData(group_id);
+        // close the floater for this group, if any.
+        LLGroupActions::closeGroup(group_id);
+    }
+    else
+    {
+        LL_WARNS() << "processAgentDropGroup, agent is not part of group " << group_id << LL_ENDL;
+    }
 }
 
 class LLAgentDropGroupViewerNode : public LLHTTPNode
 {
-	virtual void post(
-		LLHTTPNode::ResponsePtr response,
-		const LLSD& context,
-		const LLSD& input) const
-	{
-
-		if (
-			!input.isMap() ||
-			!input.has("body") )
-		{
-			//what to do with badly formed message?
-			response->extendedResult(HTTP_BAD_REQUEST, LLSD("Invalid message parameters"));
-		}
-
-		LLSD body = input["body"];
-		if ( body.has("body") ) 
-		{
-			//stupid message system doubles up the "body"s
-			body = body["body"];
-		}
-
-		if (
-			body.has("AgentData") &&
-			body["AgentData"].isArray() &&
-			body["AgentData"][0].isMap() )
-		{
-			LL_INFOS() << "VALID DROP GROUP" << LL_ENDL;
-
-			//there is only one set of data in the AgentData block
-			LLSD agent_data = body["AgentData"][0];
-			LLUUID agent_id;
-			LLUUID group_id;
-
-			agent_id = agent_data["AgentID"].asUUID();
-			group_id = agent_data["GroupID"].asUUID();
-
-			if (agent_id != gAgentID)
-			{
-				LL_WARNS()
-					<< "AgentDropGroup for agent other than me" << LL_ENDL;
-
-				response->notFound();
-				return;
-			}
-
-			// Remove the group if it already exists remove it
-			// and add the new data to pick up changes.
-			LLGroupData gd;
-			gd.mID = group_id;
-			std::vector<LLGroupData>::iterator found_it = std::find(gAgent.mGroups.begin(), gAgent.mGroups.end(), gd);
-			if (found_it != gAgent.mGroups.end())
-			{
-				gAgent.mGroups.erase(found_it);
+    virtual void post(
+        LLHTTPNode::ResponsePtr response,
+        const LLSD& context,
+        const LLSD& input) const
+    {
+
+        if (
+            !input.isMap() ||
+            !input.has("body") )
+        {
+            //what to do with badly formed message?
+            response->extendedResult(HTTP_BAD_REQUEST, LLSD("Invalid message parameters"));
+        }
+
+        LLSD body = input["body"];
+        if ( body.has("body") )
+        {
+            //stupid message system doubles up the "body"s
+            body = body["body"];
+        }
+
+        if (
+            body.has("AgentData") &&
+            body["AgentData"].isArray() &&
+            body["AgentData"][0].isMap() )
+        {
+            LL_INFOS() << "VALID DROP GROUP" << LL_ENDL;
+
+            //there is only one set of data in the AgentData block
+            LLSD agent_data = body["AgentData"][0];
+            LLUUID agent_id;
+            LLUUID group_id;
+
+            agent_id = agent_data["AgentID"].asUUID();
+            group_id = agent_data["GroupID"].asUUID();
+
+            if (agent_id != gAgentID)
+            {
+                LL_WARNS()
+                    << "AgentDropGroup for agent other than me" << LL_ENDL;
+
+                response->notFound();
+                return;
+            }
+
+            // Remove the group if it already exists remove it
+            // and add the new data to pick up changes.
+            LLGroupData gd;
+            gd.mID = group_id;
+            std::vector<LLGroupData>::iterator found_it = std::find(gAgent.mGroups.begin(), gAgent.mGroups.end(), gd);
+            if (found_it != gAgent.mGroups.end())
+            {
+                gAgent.mGroups.erase(found_it);
 // [SL:KB] - Patch: Chat-GroupOptions | Checked: 2012-06-21 (Catznip-3.3)
-				LLGroupOptionsMgr::instance().clearOptions(group_id);
+                LLGroupOptionsMgr::instance().clearOptions(group_id);
 // [/SL:KB]
-				if (gAgent.getGroupID() == group_id)
-				{
-					gAgent.mGroupID.setNull();
-					gAgent.mGroupPowers = 0;
-					gAgent.mGroupName.clear();
-					gAgent.mGroupTitle.clear();
-				}
-		
-				// refresh all group information
-				gAgent.sendAgentDataUpdateRequest();
-
-				LLGroupMgr::getInstance()->clearGroupData(group_id);
-				// close the floater for this group, if any.
-				LLGroupActions::closeGroup(group_id);
-			}
-			else
-			{
-				LL_WARNS()
-					<< "AgentDropGroup, agent is not part of group "
-					<< group_id << LL_ENDL;
-			}
-
-			response->result(LLSD());
-		}
-		else
-		{
-			//what to do with badly formed message?
-			response->extendedResult(HTTP_BAD_REQUEST, LLSD("Invalid message parameters"));
-		}
-	}
+                if (gAgent.getGroupID() == group_id)
+                {
+                    gAgent.mGroupID.setNull();
+                    gAgent.mGroupPowers = 0;
+                    gAgent.mGroupName.clear();
+                    gAgent.mGroupTitle.clear();
+                }
+
+                // refresh all group information
+                gAgent.sendAgentDataUpdateRequest();
+
+                LLGroupMgr::getInstance()->clearGroupData(group_id);
+                // close the floater for this group, if any.
+                LLGroupActions::closeGroup(group_id);
+            }
+            else
+            {
+                LL_WARNS()
+                    << "AgentDropGroup, agent is not part of group "
+                    << group_id << LL_ENDL;
+            }
+
+            response->result(LLSD());
+        }
+        else
+        {
+            //what to do with badly formed message?
+            response->extendedResult(HTTP_BAD_REQUEST, LLSD("Invalid message parameters"));
+        }
+    }
 };
 
 LLHTTPRegistration<LLAgentDropGroupViewerNode>
-	gHTTPRegistrationAgentDropGroupViewerNode(
-		"/message/AgentDropGroup");
+    gHTTPRegistrationAgentDropGroupViewerNode(
+        "/message/AgentDropGroup");
 
 // static
 void LLAgent::processAgentGroupDataUpdate(LLMessageSystem *msg, void **)
 {
-	LLUUID	agent_id;
-
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id );
-
-	if (agent_id != gAgentID)
-	{
-		LL_WARNS() << "processAgentGroupDataUpdate for agent other than me" << LL_ENDL;
-		return;
-	}	
-	
-	S32 count = msg->getNumberOfBlocksFast(_PREHASH_GroupData);
-	LLGroupData group;
-	bool need_floater_update = false;
-	for(S32 i = 0; i < count; ++i)
-	{
-		msg->getUUIDFast(_PREHASH_GroupData, _PREHASH_GroupID, group.mID, i);
-		msg->getUUIDFast(_PREHASH_GroupData, _PREHASH_GroupInsigniaID, group.mInsigniaID, i);
-		msg->getU64Fast(_PREHASH_GroupData, _PREHASH_GroupPowers, group.mPowers, i);
-		msg->getBOOLFast(_PREHASH_GroupData, _PREHASH_AcceptNotices, group.mAcceptNotices, i);
-		msg->getS32Fast(_PREHASH_GroupData, _PREHASH_Contribution, group.mContribution, i);
-		msg->getStringFast(_PREHASH_GroupData, _PREHASH_GroupName, group.mName, i);
-		
-		if(group.mID.notNull())
-		{
-			need_floater_update = true;
-			// Remove the group if it already exists remove it and add the new data to pick up changes.
-			std::vector<LLGroupData>::iterator found_it = std::find(gAgent.mGroups.begin(), gAgent.mGroups.end(), group);
-			if (found_it != gAgent.mGroups.end())
-			{
-				gAgent.mGroups.erase(found_it);
-			}
-			gAgent.mGroups.push_back(group);
-		}
-		if (need_floater_update)
-		{
-			update_group_floaters(group.mID);
-		}
-	}
+    LLUUID  agent_id;
+
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id );
+
+    if (agent_id != gAgentID)
+    {
+        LL_WARNS() << "processAgentGroupDataUpdate for agent other than me" << LL_ENDL;
+        return;
+    }
+
+    S32 count = msg->getNumberOfBlocksFast(_PREHASH_GroupData);
+    LLGroupData group;
+    bool need_floater_update = false;
+    for(S32 i = 0; i < count; ++i)
+    {
+        msg->getUUIDFast(_PREHASH_GroupData, _PREHASH_GroupID, group.mID, i);
+        msg->getUUIDFast(_PREHASH_GroupData, _PREHASH_GroupInsigniaID, group.mInsigniaID, i);
+        msg->getU64Fast(_PREHASH_GroupData, _PREHASH_GroupPowers, group.mPowers, i);
+        msg->getBOOLFast(_PREHASH_GroupData, _PREHASH_AcceptNotices, group.mAcceptNotices, i);
+        msg->getS32Fast(_PREHASH_GroupData, _PREHASH_Contribution, group.mContribution, i);
+        msg->getStringFast(_PREHASH_GroupData, _PREHASH_GroupName, group.mName, i);
+
+        if(group.mID.notNull())
+        {
+            need_floater_update = true;
+            // Remove the group if it already exists remove it and add the new data to pick up changes.
+            std::vector<LLGroupData>::iterator found_it = std::find(gAgent.mGroups.begin(), gAgent.mGroups.end(), group);
+            if (found_it != gAgent.mGroups.end())
+            {
+                gAgent.mGroups.erase(found_it);
+            }
+            gAgent.mGroups.push_back(group);
+        }
+        if (need_floater_update)
+        {
+            update_group_floaters(group.mID);
+        }
+    }
 
 }
 
 class LLAgentGroupDataUpdateViewerNode : public LLHTTPNode
 {
-	virtual void post(
-		LLHTTPNode::ResponsePtr response,
-		const LLSD& context,
-		const LLSD& input) const
-	{
-		LLSD body = input["body"];
-		if(body.has("body"))
-			body = body["body"];
-		LLUUID agent_id = body["AgentData"][0]["AgentID"].asUUID();
-
-		if (agent_id != gAgentID)
-		{
-			LL_WARNS() << "processAgentGroupDataUpdate for agent other than me" << LL_ENDL;
-			return;
-		}	
-
-		LLSD group_data = body["GroupData"];
-
-		LLSD::array_iterator iter_group =
-			group_data.beginArray();
-		LLSD::array_iterator end_group =
-			group_data.endArray();
-		int group_index = 0;
-		for(; iter_group != end_group; ++iter_group)
-		{
-
-			LLGroupData group;
-			bool need_floater_update = false;
-
-			group.mID = (*iter_group)["GroupID"].asUUID();
-			group.mPowers = ll_U64_from_sd((*iter_group)["GroupPowers"]);
-			group.mAcceptNotices = (*iter_group)["AcceptNotices"].asBoolean();
-			group.mListInProfile = body["NewGroupData"][group_index]["ListInProfile"].asBoolean();
-			group.mInsigniaID = (*iter_group)["GroupInsigniaID"].asUUID();
-			group.mName = (*iter_group)["GroupName"].asString();
-			group.mContribution = (*iter_group)["Contribution"].asInteger();
-
-			group_index++;
-
-			if(group.mID.notNull())
-			{
-				need_floater_update = true;
-				// Remove the group if it already exists remove it and add the new data to pick up changes.
-				std::vector<LLGroupData>::iterator found_it = std::find(gAgent.mGroups.begin(), gAgent.mGroups.end(), group);
-				if (found_it != gAgent.mGroups.end())
-				{
-					gAgent.mGroups.erase(found_it);
-				}
-				gAgent.mGroups.push_back(group);
-			}
-			if (need_floater_update)
-			{
-				update_group_floaters(group.mID);
-			}
-		}
-	}
+    virtual void post(
+        LLHTTPNode::ResponsePtr response,
+        const LLSD& context,
+        const LLSD& input) const
+    {
+        LLSD body = input["body"];
+        if(body.has("body"))
+            body = body["body"];
+        LLUUID agent_id = body["AgentData"][0]["AgentID"].asUUID();
+
+        if (agent_id != gAgentID)
+        {
+            LL_WARNS() << "processAgentGroupDataUpdate for agent other than me" << LL_ENDL;
+            return;
+        }
+
+        LLSD group_data = body["GroupData"];
+
+        LLSD::array_iterator iter_group =
+            group_data.beginArray();
+        LLSD::array_iterator end_group =
+            group_data.endArray();
+        int group_index = 0;
+        for(; iter_group != end_group; ++iter_group)
+        {
+
+            LLGroupData group;
+            bool need_floater_update = false;
+
+            group.mID = (*iter_group)["GroupID"].asUUID();
+            group.mPowers = ll_U64_from_sd((*iter_group)["GroupPowers"]);
+            group.mAcceptNotices = (*iter_group)["AcceptNotices"].asBoolean();
+            group.mListInProfile = body["NewGroupData"][group_index]["ListInProfile"].asBoolean();
+            group.mInsigniaID = (*iter_group)["GroupInsigniaID"].asUUID();
+            group.mName = (*iter_group)["GroupName"].asString();
+            group.mContribution = (*iter_group)["Contribution"].asInteger();
+
+            group_index++;
+
+            if(group.mID.notNull())
+            {
+                need_floater_update = true;
+                // Remove the group if it already exists remove it and add the new data to pick up changes.
+                std::vector<LLGroupData>::iterator found_it = std::find(gAgent.mGroups.begin(), gAgent.mGroups.end(), group);
+                if (found_it != gAgent.mGroups.end())
+                {
+                    gAgent.mGroups.erase(found_it);
+                }
+                gAgent.mGroups.push_back(group);
+            }
+            if (need_floater_update)
+            {
+                update_group_floaters(group.mID);
+            }
+        }
+    }
 };
 
 LLHTTPRegistration<LLAgentGroupDataUpdateViewerNode >
-	gHTTPRegistrationAgentGroupDataUpdateViewerNode ("/message/AgentGroupDataUpdate"); 
+    gHTTPRegistrationAgentGroupDataUpdateViewerNode ("/message/AgentGroupDataUpdate");
 
 // static
 void LLAgent::processAgentDataUpdate(LLMessageSystem *msg, void **)
 {
-	LLUUID	agent_id;
+    LLUUID  agent_id;
 
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id );
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id );
 
-	if (agent_id != gAgentID)
-	{
-		LL_WARNS() << "processAgentDataUpdate for agent other than me" << LL_ENDL;
-		return;
-	}
+    if (agent_id != gAgentID)
+    {
+        LL_WARNS() << "processAgentDataUpdate for agent other than me" << LL_ENDL;
+        return;
+    }
 
-	msg->getStringFast(_PREHASH_AgentData, _PREHASH_GroupTitle, gAgent.mGroupTitle);
-	LLUUID active_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_ActiveGroupID, active_id);
+    msg->getStringFast(_PREHASH_AgentData, _PREHASH_GroupTitle, gAgent.mGroupTitle);
+    LLUUID active_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_ActiveGroupID, active_id);
 
 
-	if(active_id.notNull())
-	{
-		gAgent.mGroupID = active_id;
-		msg->getU64Fast(_PREHASH_AgentData, _PREHASH_GroupPowers, gAgent.mGroupPowers);
-		msg->getStringFast(_PREHASH_AgentData, _PREHASH_GroupName, gAgent.mGroupName);
-	}
-	else
-	{
-		gAgent.mGroupID.setNull();
-		gAgent.mGroupPowers = 0;
-		gAgent.mGroupName.clear();
-	}		
+    if(active_id.notNull())
+    {
+        gAgent.mGroupID = active_id;
+        msg->getU64Fast(_PREHASH_AgentData, _PREHASH_GroupPowers, gAgent.mGroupPowers);
+        msg->getStringFast(_PREHASH_AgentData, _PREHASH_GroupName, gAgent.mGroupName);
+    }
+    else
+    {
+        gAgent.mGroupID.setNull();
+        gAgent.mGroupPowers = 0;
+        gAgent.mGroupName.clear();
+    }
 
-	update_group_floaters(active_id);
+    update_group_floaters(active_id);
 }
 
 // static
 void LLAgent::processScriptControlChange(LLMessageSystem *msg, void **)
 {
-	S32 block_count = msg->getNumberOfBlocksFast(_PREHASH_Data);
-	for (S32 block_index = 0; block_index < block_count; block_index++)
-	{
-		BOOL take_controls;
-		U32	controls;
-		BOOL passon;
-		U32 i;
-		msg->getBOOLFast(_PREHASH_Data, _PREHASH_TakeControls, take_controls, block_index);
-		if (take_controls)
-		{
-			// take controls
-			msg->getU32Fast(_PREHASH_Data, _PREHASH_Controls, controls, block_index );
-			msg->getBOOLFast(_PREHASH_Data, _PREHASH_PassToAgent, passon, block_index );
-			for (i = 0; i < TOTAL_CONTROLS; i++)
-			{
-				if (controls & ( 1 << i))
-				{
-					if (passon)
-					{
-						gAgent.mControlsTakenPassedOnCount[i]++;
-					}
-					else
-					{
-						gAgent.mControlsTakenCount[i]++;
-					}
-				}
-			}
-		}
-		else
-		{
-			// release controls
-			msg->getU32Fast(_PREHASH_Data, _PREHASH_Controls, controls, block_index );
-			msg->getBOOLFast(_PREHASH_Data, _PREHASH_PassToAgent, passon, block_index );
-			for (i = 0; i < TOTAL_CONTROLS; i++)
-			{
-				if (controls & ( 1 << i))
-				{
-					if (passon)
-					{
-						gAgent.mControlsTakenPassedOnCount[i]--;
-						if (gAgent.mControlsTakenPassedOnCount[i] < 0)
-						{
-							gAgent.mControlsTakenPassedOnCount[i] = 0;
-						}
-					}
-					else
-					{
-						gAgent.mControlsTakenCount[i]--;
-						if (gAgent.mControlsTakenCount[i] < 0)
-						{
-							gAgent.mControlsTakenCount[i] = 0;
-						}
-					}
-				}
-			}
-		}
-	}
+    S32 block_count = msg->getNumberOfBlocksFast(_PREHASH_Data);
+    for (S32 block_index = 0; block_index < block_count; block_index++)
+    {
+        BOOL take_controls;
+        U32 controls;
+        BOOL passon;
+        U32 i;
+        msg->getBOOLFast(_PREHASH_Data, _PREHASH_TakeControls, take_controls, block_index);
+        if (take_controls)
+        {
+            // take controls
+            msg->getU32Fast(_PREHASH_Data, _PREHASH_Controls, controls, block_index );
+            msg->getBOOLFast(_PREHASH_Data, _PREHASH_PassToAgent, passon, block_index );
+            for (i = 0; i < TOTAL_CONTROLS; i++)
+            {
+                if (controls & ( 1 << i))
+                {
+                    if (passon)
+                    {
+                        gAgent.mControlsTakenPassedOnCount[i]++;
+                    }
+                    else
+                    {
+                        gAgent.mControlsTakenCount[i]++;
+                    }
+                }
+            }
+        }
+        else
+        {
+            // release controls
+            msg->getU32Fast(_PREHASH_Data, _PREHASH_Controls, controls, block_index );
+            msg->getBOOLFast(_PREHASH_Data, _PREHASH_PassToAgent, passon, block_index );
+            for (i = 0; i < TOTAL_CONTROLS; i++)
+            {
+                if (controls & ( 1 << i))
+                {
+                    if (passon)
+                    {
+                        gAgent.mControlsTakenPassedOnCount[i]--;
+                        if (gAgent.mControlsTakenPassedOnCount[i] < 0)
+                        {
+                            gAgent.mControlsTakenPassedOnCount[i] = 0;
+                        }
+                    }
+                    else
+                    {
+                        gAgent.mControlsTakenCount[i]--;
+                        if (gAgent.mControlsTakenCount[i] < 0)
+                        {
+                            gAgent.mControlsTakenCount[i] = 0;
+                        }
+                    }
+                }
+            }
+        }
+    }
 }
 
-/*
-// static
-void LLAgent::processControlTake(LLMessageSystem *msg, void **)
-{
-	U32	controls;
-	msg->getU32("Data", "Controls", controls );
-	U32 passon;
-	msg->getBOOL("Data", "PassToAgent", passon );
-
-	S32 i;
-	S32 total_count = 0;
-	for (i = 0; i < TOTAL_CONTROLS; i++)
-	{
-		if (controls & ( 1 << i))
-		{
-			if (passon)
-			{
-				gAgent.mControlsTakenPassedOnCount[i]++;
-			}
-			else
-			{
-				gAgent.mControlsTakenCount[i]++;
-			}
-			total_count++;
-		}
-	}
-
-	// Any control taken?  If so, might be first time.
-	if (total_count > 0)
-	{
-		LLFirstUse::useOverrideKeys();
-	}
+/*
+// static
+void LLAgent::processControlTake(LLMessageSystem *msg, void **)
+{
+    U32 controls;
+    msg->getU32("Data", "Controls", controls );
+    U32 passon;
+    msg->getBOOL("Data", "PassToAgent", passon );
+
+    S32 i;
+    S32 total_count = 0;
+    for (i = 0; i < TOTAL_CONTROLS; i++)
+    {
+        if (controls & ( 1 << i))
+        {
+            if (passon)
+            {
+                gAgent.mControlsTakenPassedOnCount[i]++;
+            }
+            else
+            {
+                gAgent.mControlsTakenCount[i]++;
+            }
+            total_count++;
+        }
+    }
+
+    // Any control taken?  If so, might be first time.
+    if (total_count > 0)
+    {
+        LLFirstUse::useOverrideKeys();
+    }
 }
 
 // static
 void LLAgent::processControlRelease(LLMessageSystem *msg, void **)
 {
-	U32	controls;
-	msg->getU32("Data", "Controls", controls );
-	U32 passon;
-	msg->getBOOL("Data", "PassToAgent", passon );
-
-	S32 i;
-	for (i = 0; i < TOTAL_CONTROLS; i++)
-	{
-		if (controls & ( 1 << i))
-		{
-			if (passon)
-			{
-				gAgent.mControlsTakenPassedOnCount[i]--;
-				if (gAgent.mControlsTakenPassedOnCount[i] < 0)
-				{
-					gAgent.mControlsTakenPassedOnCount[i] = 0;
-				}
-			}
-			else
-			{
-				gAgent.mControlsTakenCount[i]--;
-				if (gAgent.mControlsTakenCount[i] < 0)
-				{
-					gAgent.mControlsTakenCount[i] = 0;
-				}
-			}
-		}
-	}
+    U32 controls;
+    msg->getU32("Data", "Controls", controls );
+    U32 passon;
+    msg->getBOOL("Data", "PassToAgent", passon );
+
+    S32 i;
+    for (i = 0; i < TOTAL_CONTROLS; i++)
+    {
+        if (controls & ( 1 << i))
+        {
+            if (passon)
+            {
+                gAgent.mControlsTakenPassedOnCount[i]--;
+                if (gAgent.mControlsTakenPassedOnCount[i] < 0)
+                {
+                    gAgent.mControlsTakenPassedOnCount[i] = 0;
+                }
+            }
+            else
+            {
+                gAgent.mControlsTakenCount[i]--;
+                if (gAgent.mControlsTakenCount[i] < 0)
+                {
+                    gAgent.mControlsTakenCount[i] = 0;
+                }
+            }
+        }
+    }
 }
 */
 
 BOOL LLAgent::anyControlGrabbed() const
 {
-	for (U32 i = 0; i < TOTAL_CONTROLS; i++)
-	{
-		if (gAgent.mControlsTakenCount[i] > 0)
-			return TRUE;
-		if (gAgent.mControlsTakenPassedOnCount[i] > 0)
-			return TRUE;
-	}
-	return FALSE;
+    for (U32 i = 0; i < TOTAL_CONTROLS; i++)
+    {
+        if (gAgent.mControlsTakenCount[i] > 0)
+            return TRUE;
+        if (gAgent.mControlsTakenPassedOnCount[i] > 0)
+            return TRUE;
+    }
+    return FALSE;
 }
 
 BOOL LLAgent::isControlGrabbed(S32 control_index) const
 {
-	return mControlsTakenCount[control_index] > 0;
+    return mControlsTakenCount[control_index] > 0;
 }
 
 void LLAgent::forceReleaseControls()
 {
-	gMessageSystem->newMessageFast(_PREHASH_ForceScriptControlRelease);
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, getID());
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, getSessionID());
-	sendReliableMessage();
+    gMessageSystem->newMessageFast(_PREHASH_ForceScriptControlRelease);
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, getID());
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, getSessionID());
+    sendReliableMessage();
 }
 
 void LLAgent::setHomePosRegion( const U64& region_handle, const LLVector3& pos_region)
 {
-	mHaveHomePosition = TRUE;
-	mHomeRegionHandle = region_handle;
-	mHomePosRegion = pos_region;
+    mHaveHomePosition = TRUE;
+    mHomeRegionHandle = region_handle;
+    mHomePosRegion = pos_region;
 }
 
 BOOL LLAgent::getHomePosGlobal( LLVector3d* pos_global )
 {
-	if(!mHaveHomePosition)
-	{
-		return FALSE;
-	}
-	F32 x = 0;
-	F32 y = 0;
-	from_region_handle( mHomeRegionHandle, &x, &y);
-	pos_global->setVec( x + mHomePosRegion.mV[VX], y + mHomePosRegion.mV[VY], mHomePosRegion.mV[VZ] );
-	return TRUE;
+    if(!mHaveHomePosition)
+    {
+        return FALSE;
+    }
+    F32 x = 0;
+    F32 y = 0;
+    from_region_handle( mHomeRegionHandle, &x, &y);
+    pos_global->setVec( x + mHomePosRegion.mV[VX], y + mHomePosRegion.mV[VY], mHomePosRegion.mV[VZ] );
+    return TRUE;
 }
 
 bool LLAgent::isInHomeRegion()
 {
-	if(!mHaveHomePosition)
-	{
-		return false;
-	}
-	if (!getRegion())
-	{
-		return false;
-	}
-	if (getRegion()->getHandle() != mHomeRegionHandle)
-	{
-		return false;
-	}
-	return true;
+    if(!mHaveHomePosition)
+    {
+        return false;
+    }
+    if (!getRegion())
+    {
+        return false;
+    }
+    if (getRegion()->getHandle() != mHomeRegionHandle)
+    {
+        return false;
+    }
+    return true;
 }
 
 void LLAgent::clearVisualParams(void *data)
 {
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->clearVisualParamWeights();
-		gAgentAvatarp->updateVisualParams();
-	}
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->clearVisualParamWeights();
+        gAgentAvatarp->updateVisualParams();
+    }
 }
 
 //---------------------------------------------------------------------------
@@ -4265,29 +4265,29 @@ void LLAgent::clearVisualParams(void *data)
 bool LLAgent::teleportCore(bool is_local)
 {
     LL_DEBUGS("Teleport") << "In teleport core" << LL_ENDL;
-	if ((TELEPORT_NONE != mTeleportState) && (mTeleportState != TELEPORT_PENDING))
-	{
-		LL_WARNS() << "Attempt to teleport when already teleporting." << LL_ENDL;
-		return false;
-	}
-
-	// force stand up and stop a sitting animation (if any), see MAINT-3969
-	if (isAgentAvatarValid() && gAgentAvatarp->getParent() && gAgentAvatarp->isSitting())
-	{
-		gAgentAvatarp->getOffObject();
-	}
+    if ((TELEPORT_NONE != mTeleportState) && (mTeleportState != TELEPORT_PENDING))
+    {
+        LL_WARNS() << "Attempt to teleport when already teleporting." << LL_ENDL;
+        return false;
+    }
+
+    // force stand up and stop a sitting animation (if any), see MAINT-3969
+    if (isAgentAvatarValid() && gAgentAvatarp->getParent() && gAgentAvatarp->isSitting())
+    {
+        gAgentAvatarp->getOffObject();
+    }
 
 #if 0
-	// This should not exist. It has been added, removed, added, and now removed again.
-	// This change needs to come from the simulator. Otherwise, the agent ends up out of
-	// sync with other viewers. Discuss in DEV-14145/VWR-6744 before reenabling.
+    // This should not exist. It has been added, removed, added, and now removed again.
+    // This change needs to come from the simulator. Otherwise, the agent ends up out of
+    // sync with other viewers. Discuss in DEV-14145/VWR-6744 before reenabling.
 
-	// Stop all animation before actual teleporting 
+    // Stop all animation before actual teleporting
         if (isAgentAvatarValid())
-	{
-		for ( LLVOAvatar::AnimIterator anim_it= gAgentAvatarp->mPlayingAnimations.begin();
-		      anim_it != gAgentAvatarp->mPlayingAnimations.end();
-		      ++anim_it)
+    {
+        for ( LLVOAvatar::AnimIterator anim_it= gAgentAvatarp->mPlayingAnimations.begin();
+              anim_it != gAgentAvatarp->mPlayingAnimations.end();
+              ++anim_it)
                {
                        gAgentAvatarp->stopMotion(anim_it->first);
                }
@@ -4295,59 +4295,59 @@ bool LLAgent::teleportCore(bool is_local)
        }
 #endif
 
-	// Don't call LLFirstUse::useTeleport because we don't know
-	// yet if the teleport will succeed.  Look in 
-	// process_teleport_location_reply
-
-	// hide land floater too - it'll be out of date
-	LLFloaterReg::hideInstance("about_land");
-
-	// hide the Region/Estate floater
-	LLFloaterReg::hideInstance("region_info");
-
-	LLViewerParcelMgr::getInstance()->deselectLand();
-	LLViewerMediaFocus::getInstance()->clearFocus();
-
-	// Close all pie menus, deselect land, etc.
-	// Don't change the camera until we know teleport succeeded. JC
-	gAgentCamera.resetView(FALSE);
-
-	// local logic
-	add(LLStatViewer::TELEPORT, 1);
-	if (is_local)
-	{
-		LL_INFOS("Teleport") << "Setting teleport state to TELEPORT_LOCAL" << LL_ENDL;
-		gAgent.setTeleportState( LLAgent::TELEPORT_LOCAL );
-	}
-	else
-	{
-		gTeleportDisplay = TRUE;
-		LL_INFOS("Teleport") << "Non-local, setting teleport state to TELEPORT_START" << LL_ENDL;
-		gAgent.setTeleportState( LLAgent::TELEPORT_START );
-	}
-	make_ui_sound("UISndTeleportOut");
-	
-	// MBW -- Let the voice client know a teleport has begun so it can leave the existing channel.
-	// This was breaking the case of teleporting within a single sim.  Backing it out for now.
-//	LLVoiceClient::getInstance()->leaveChannel();
-	
-	return true;
+    // Don't call LLFirstUse::useTeleport because we don't know
+    // yet if the teleport will succeed.  Look in
+    // process_teleport_location_reply
+
+    // hide land floater too - it'll be out of date
+    LLFloaterReg::hideInstance("about_land");
+
+    // hide the Region/Estate floater
+    LLFloaterReg::hideInstance("region_info");
+
+    LLViewerParcelMgr::getInstance()->deselectLand();
+    LLViewerMediaFocus::getInstance()->clearFocus();
+
+    // Close all pie menus, deselect land, etc.
+    // Don't change the camera until we know teleport succeeded. JC
+    gAgentCamera.resetView(FALSE);
+
+    // local logic
+    add(LLStatViewer::TELEPORT, 1);
+    if (is_local)
+    {
+        LL_INFOS("Teleport") << "Setting teleport state to TELEPORT_LOCAL" << LL_ENDL;
+        gAgent.setTeleportState( LLAgent::TELEPORT_LOCAL );
+    }
+    else
+    {
+        gTeleportDisplay = TRUE;
+        LL_INFOS("Teleport") << "Non-local, setting teleport state to TELEPORT_START" << LL_ENDL;
+        gAgent.setTeleportState( LLAgent::TELEPORT_START );
+    }
+    make_ui_sound("UISndTeleportOut");
+
+    // MBW -- Let the voice client know a teleport has begun so it can leave the existing channel.
+    // This was breaking the case of teleporting within a single sim.  Backing it out for now.
+//  LLVoiceClient::getInstance()->leaveChannel();
+
+    return true;
 }
 
 bool LLAgent::hasRestartableFailedTeleportRequest()
 {
-	return ((mTeleportRequest != NULL) && (mTeleportRequest->getStatus() == LLTeleportRequest::kFailed) &&
-		mTeleportRequest->canRestartTeleport());
+    return ((mTeleportRequest != NULL) && (mTeleportRequest->getStatus() == LLTeleportRequest::kFailed) &&
+        mTeleportRequest->canRestartTeleport());
 }
 
 void LLAgent::restartFailedTeleportRequest()
 {
     LL_INFOS("Teleport") << "Agent wishes to restart failed teleport." << LL_ENDL;
-	if (hasRestartableFailedTeleportRequest())
-	{
-		mTeleportRequest->setStatus(LLTeleportRequest::kRestartPending);
-		startTeleportRequest();
-	}
+    if (hasRestartableFailedTeleportRequest())
+    {
+        mTeleportRequest->setStatus(LLTeleportRequest::kRestartPending);
+        startTeleportRequest();
+    }
 }
 
 void LLAgent::clearTeleportRequest()
@@ -4356,14 +4356,14 @@ void LLAgent::clearTeleportRequest()
     {
         LLVoiceClient::getInstance()->setHidden(FALSE);
     }
-	mTeleportRequest.reset();
+    mTeleportRequest.reset();
     mTPNeedsNeabyChatSeparator = false;
 }
 
 void LLAgent::setMaturityRatingChangeDuringTeleport(U8 pMaturityRatingChange)
 {
-	mIsMaturityRatingChangingDuringTeleport = true;
-	mMaturityRatingChange = pMaturityRatingChange;
+    mIsMaturityRatingChangingDuringTeleport = true;
+    mMaturityRatingChange = pMaturityRatingChange;
 }
 
 void LLAgent::sheduleTeleportIM()
@@ -4374,9 +4374,9 @@ void LLAgent::sheduleTeleportIM()
 
 bool LLAgent::hasPendingTeleportRequest()
 {
-	return ((mTeleportRequest != NULL) &&
-		((mTeleportRequest->getStatus() == LLTeleportRequest::kPending) ||
-		(mTeleportRequest->getStatus() == LLTeleportRequest::kRestartPending)));
+    return ((mTeleportRequest != NULL) &&
+        ((mTeleportRequest->getStatus() == LLTeleportRequest::kPending) ||
+        (mTeleportRequest->getStatus() == LLTeleportRequest::kRestartPending)));
 }
 
 void LLAgent::startTeleportRequest()
@@ -4386,34 +4386,34 @@ void LLAgent::startTeleportRequest()
     {
         LLVoiceClient::getInstance()->setHidden(TRUE);
     }
-	if (hasPendingTeleportRequest())
-	{
+    if (hasPendingTeleportRequest())
+    {
         mTeleportCanceled.reset();
-		if  (!isMaturityPreferenceSyncedWithServer())
-		{
-			gTeleportDisplay = TRUE;
-			LL_INFOS("Teleport") << "Maturity preference not synced yet, setting teleport state to TELEPORT_PENDING" << LL_ENDL;
-			setTeleportState(TELEPORT_PENDING);
-		}
-		else
-		{
-			switch (mTeleportRequest->getStatus())
-			{
-			case LLTeleportRequest::kPending :
-				mTeleportRequest->setStatus(LLTeleportRequest::kStarted);
-				mTeleportRequest->startTeleport();
-				break;
-			case LLTeleportRequest::kRestartPending :
-				llassert(mTeleportRequest->canRestartTeleport());
-				mTeleportRequest->setStatus(LLTeleportRequest::kStarted);
-				mTeleportRequest->restartTeleport();
-				break;
-			default :
-				llassert(0);
-				break;
-			}
-		}
-	}
+        if  (!isMaturityPreferenceSyncedWithServer())
+        {
+            gTeleportDisplay = TRUE;
+            LL_INFOS("Teleport") << "Maturity preference not synced yet, setting teleport state to TELEPORT_PENDING" << LL_ENDL;
+            setTeleportState(TELEPORT_PENDING);
+        }
+        else
+        {
+            switch (mTeleportRequest->getStatus())
+            {
+            case LLTeleportRequest::kPending :
+                mTeleportRequest->setStatus(LLTeleportRequest::kStarted);
+                mTeleportRequest->startTeleport();
+                break;
+            case LLTeleportRequest::kRestartPending :
+                llassert(mTeleportRequest->canRestartTeleport());
+                mTeleportRequest->setStatus(LLTeleportRequest::kStarted);
+                mTeleportRequest->restartTeleport();
+                break;
+            default :
+                llassert(0);
+                break;
+            }
+        }
+    }
 }
 
 void LLAgent::handleTeleportFinished()
@@ -4425,36 +4425,36 @@ void LLAgent::handleTeleportFinished()
         addTPNearbyChatSeparator();
         mTPNeedsNeabyChatSeparator = false;
     }
-	clearTeleportRequest();
+    clearTeleportRequest();
     mTeleportCanceled.reset();
-	if (mIsMaturityRatingChangingDuringTeleport)
-	{
-		// notify user that the maturity preference has been changed
-		std::string maturityRating = LLViewerRegion::accessToString(mMaturityRatingChange);
-		LLStringUtil::toLower(maturityRating);
-		LLSD args;
-		args["RATING"] = maturityRating;
-		LLNotificationsUtil::add("PreferredMaturityChanged", args);
-		mIsMaturityRatingChangingDuringTeleport = false;
-	}
-    
+    if (mIsMaturityRatingChangingDuringTeleport)
+    {
+        // notify user that the maturity preference has been changed
+        std::string maturityRating = LLViewerRegion::accessToString(mMaturityRatingChange);
+        LLStringUtil::toLower(maturityRating);
+        LLSD args;
+        args["RATING"] = maturityRating;
+        LLNotificationsUtil::add("PreferredMaturityChanged", args);
+        mIsMaturityRatingChangingDuringTeleport = false;
+    }
+
     if (mRegionp)
     {
         if (mRegionp->capabilitiesReceived())
         {
-			LL_DEBUGS("Teleport") << "capabilities have been received for region handle "
-								  << mRegionp->getHandle()
-								  << " id " << mRegionp->getRegionID()
-								  << ", calling onCapabilitiesReceivedAfterTeleport()"
-								  << LL_ENDL;
+            LL_DEBUGS("Teleport") << "capabilities have been received for region handle "
+                                  << mRegionp->getHandle()
+                                  << " id " << mRegionp->getRegionID()
+                                  << ", calling onCapabilitiesReceivedAfterTeleport()"
+                                  << LL_ENDL;
             onCapabilitiesReceivedAfterTeleport();
         }
         else
         {
-			LL_DEBUGS("Teleport") << "Capabilities not yet received for region handle "
-								  << mRegionp->getHandle()
-								  << " id " << mRegionp->getRegionID()
-								  << LL_ENDL;
+            LL_DEBUGS("Teleport") << "Capabilities not yet received for region handle "
+                                  << mRegionp->getHandle()
+                                  << " id " << mRegionp->getRegionID()
+                                  << LL_ENDL;
             mRegionp->setCapabilitiesReceivedCallback(boost::bind(&LLAgent::onCapabilitiesReceivedAfterTeleport));
         }
     }
@@ -4475,19 +4475,19 @@ void LLAgent::handleTeleportFailed()
 //     gTeleportDisplay = FALSE;
 
     if (mTeleportRequest)
-	{
-		mTeleportRequest->setStatus(LLTeleportRequest::kFailed);
-	}
-	if (mIsMaturityRatingChangingDuringTeleport)
-	{
-		// notify user that the maturity preference has been changed
-		std::string maturityRating = LLViewerRegion::accessToString(mMaturityRatingChange);
-		LLStringUtil::toLower(maturityRating);
-		LLSD args;
-		args["RATING"] = maturityRating;
-		LLNotificationsUtil::add("PreferredMaturityChanged", args);
-		mIsMaturityRatingChangingDuringTeleport = false;
-	}
+    {
+        mTeleportRequest->setStatus(LLTeleportRequest::kFailed);
+    }
+    if (mIsMaturityRatingChangingDuringTeleport)
+    {
+        // notify user that the maturity preference has been changed
+        std::string maturityRating = LLViewerRegion::accessToString(mMaturityRatingChange);
+        LLStringUtil::toLower(maturityRating);
+        LLSD args;
+        args["RATING"] = maturityRating;
+        LLNotificationsUtil::add("PreferredMaturityChanged", args);
+        mIsMaturityRatingChangingDuringTeleport = false;
+    }
 
     mTPNeedsNeabyChatSeparator = false;
 
@@ -4533,98 +4533,98 @@ void LLAgent::addTPNearbyChatSeparator()
 /*static*/
 void LLAgent::onCapabilitiesReceivedAfterTeleport()
 {
-	if (gAgent.getRegion())
-	{
-		LL_DEBUGS("Teleport") << "running after capabilities received callback has been triggered, agent region "
-							  << gAgent.getRegion()->getHandle()
-							  << " id " << gAgent.getRegion()->getRegionID()
-							  << " name " << gAgent.getRegion()->getName()
-							  << LL_ENDL;
-	}
-	else
-	{
-		LL_WARNS("Teleport") << "called when agent region is null!" << LL_ENDL;
-	}
+    if (gAgent.getRegion())
+    {
+        LL_DEBUGS("Teleport") << "running after capabilities received callback has been triggered, agent region "
+                              << gAgent.getRegion()->getHandle()
+                              << " id " << gAgent.getRegion()->getRegionID()
+                              << " name " << gAgent.getRegion()->getName()
+                              << LL_ENDL;
+    }
+    else
+    {
+        LL_WARNS("Teleport") << "called when agent region is null!" << LL_ENDL;
+    }
 
     check_merchant_status();
 }
 
 
 //void LLAgent::teleportRequest(
-//	const U64& region_handle,
-//	const LLVector3& pos_local,
-//	bool look_at_from_camera)
+//  const U64& region_handle,
+//  const LLVector3& pos_local,
+//  bool look_at_from_camera)
 // [RLVa:KB] - Checked: RLVa-2.0.0
 void LLAgent::teleportRequest(const LLVector3d& pos_global, const LLVector3& look_at)
 // [/RLVa:KB]
 {
-	LLViewerRegion* regionp = getRegion();
-	if (!regionp) return;
-
-	LLVector3 pos_local;
-	U64 region_handle;
-	if (regionp->pointInRegionGlobal(pos_global))
-	{
-		pos_local = regionp->getPosRegionFromGlobal(pos_global);
-		region_handle = regionp->getHandle();
-	}
-	else if (LLViewerRegion* other_regionp = LLWorld::instance().getRegionFromPosGlobal(pos_global))
-	{
-		pos_local = LLVector3(pos_global - other_regionp->getOriginGlobal());
-		region_handle = other_regionp->getHandle();
-	}
-	else if (LLSimInfo* sim_info = LLWorldMap::getInstance()->simInfoFromPosGlobal(pos_global))
-	{
-		pos_local = sim_info->getLocalPos(pos_global);
-		region_handle = sim_info->getHandle();
-	}
-	else
-	{
-		region_handle = to_region_handle(pos_global);
-		// determine non-local region location as best we can using global coords
-		// In SL we have uniform region size. This is normal.
-		// In opensim the handle will resolve to a 256m quantised world tile which the server maps back to a region
-		// it "should" also compensate for the local coords. Handle has been "correctly" determined already so we use global % 256
-		pos_local.set(fmod((F32)pos_global.mdV[VX], REGION_WIDTH_METERS),
-			fmod((F32)pos_global.mdV[VY], REGION_WIDTH_METERS),
-			(F32)pos_global.mdV[VZ]);
-	}
-
-	if (teleportCore(region_handle == regionp->getHandle()))
-	{
-		LL_INFOS("Teleport") << "Sending TeleportLocationRequest: '" << region_handle << "':"
-							 << pos_local << LL_ENDL;
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_TeleportLocationRequest);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, getID());
-		msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
-		msg->nextBlockFast(_PREHASH_Info);
-		msg->addU64Fast(_PREHASH_RegionHandle, region_handle);
-		msg->addVector3Fast(_PREHASH_Position, pos_local);
-//		LLVector3 look_at(0,1,0);
-//		if (look_at_from_camera)
-//		{
-//			look_at = LLViewerCamera::getInstance()->getAtAxis();
-//		}
-		msg->addVector3Fast(_PREHASH_LookAt, look_at);
-		sendReliableMessage();
-	}
+    LLViewerRegion* regionp = getRegion();
+    if (!regionp) return;
+
+    LLVector3 pos_local;
+    U64 region_handle;
+    if (regionp->pointInRegionGlobal(pos_global))
+    {
+        pos_local = regionp->getPosRegionFromGlobal(pos_global);
+        region_handle = regionp->getHandle();
+    }
+    else if (LLViewerRegion* other_regionp = LLWorld::instance().getRegionFromPosGlobal(pos_global))
+    {
+        pos_local = LLVector3(pos_global - other_regionp->getOriginGlobal());
+        region_handle = other_regionp->getHandle();
+    }
+    else if (LLSimInfo* sim_info = LLWorldMap::getInstance()->simInfoFromPosGlobal(pos_global))
+    {
+        pos_local = sim_info->getLocalPos(pos_global);
+        region_handle = sim_info->getHandle();
+    }
+    else
+    {
+        region_handle = to_region_handle(pos_global);
+        // determine non-local region location as best we can using global coords
+        // In SL we have uniform region size. This is normal.
+        // In opensim the handle will resolve to a 256m quantised world tile which the server maps back to a region
+        // it "should" also compensate for the local coords. Handle has been "correctly" determined already so we use global % 256
+        pos_local.set(fmod((F32)pos_global.mdV[VX], REGION_WIDTH_METERS),
+            fmod((F32)pos_global.mdV[VY], REGION_WIDTH_METERS),
+            (F32)pos_global.mdV[VZ]);
+    }
+
+    if (teleportCore(region_handle == regionp->getHandle()))
+    {
+        LL_INFOS("Teleport") << "Sending TeleportLocationRequest: '" << region_handle << "':"
+                             << pos_local << LL_ENDL;
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_TeleportLocationRequest);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, getID());
+        msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+        msg->nextBlockFast(_PREHASH_Info);
+        msg->addU64Fast(_PREHASH_RegionHandle, region_handle);
+        msg->addVector3Fast(_PREHASH_Position, pos_local);
+//      LLVector3 look_at(0,1,0);
+//      if (look_at_from_camera)
+//      {
+//          look_at = LLViewerCamera::getInstance()->getAtAxis();
+//      }
+        msg->addVector3Fast(_PREHASH_LookAt, look_at);
+        sendReliableMessage();
+    }
 }
 
 // Landmark ID = LLUUID::null means teleport home
 void LLAgent::teleportViaLandmark(const LLUUID& landmark_asset_id)
 {
 // [RLVa:KB] - Checked: 2010-08-22 (RLVa-1.2.1a) | Modified: RLVa-1.2.1a
-	// NOTE: we'll allow teleporting home unless both @tplm=n *and* @tploc=n restricted
-	if ( (rlv_handler_t::isEnabled()) &&
-		 ( ( (landmark_asset_id.notNull()) ? gRlvHandler.hasBehaviour(RLV_BHVR_TPLM)
-		                                   : gRlvHandler.hasBehaviour(RLV_BHVR_TPLM) && gRlvHandler.hasBehaviour(RLV_BHVR_TPLOC) ) ||
-		   ((gRlvHandler.hasBehaviour(RLV_BHVR_UNSIT)) && (isAgentAvatarValid()) && (gAgentAvatarp->isSitting())) ))
-	{
-		RlvUtil::notifyBlocked(RlvStringKeys::Blocked::Teleport);
-		return;
-	}
+    // NOTE: we'll allow teleporting home unless both @tplm=n *and* @tploc=n restricted
+    if ( (rlv_handler_t::isEnabled()) &&
+         ( ( (landmark_asset_id.notNull()) ? gRlvHandler.hasBehaviour(RLV_BHVR_TPLM)
+                                           : gRlvHandler.hasBehaviour(RLV_BHVR_TPLM) && gRlvHandler.hasBehaviour(RLV_BHVR_TPLOC) ) ||
+           ((gRlvHandler.hasBehaviour(RLV_BHVR_UNSIT)) && (isAgentAvatarValid()) && (gAgentAvatarp->isSitting())) ))
+    {
+        RlvUtil::notifyBlocked(RlvStringKeys::Blocked::Teleport);
+        return;
+    }
 // [/RLVa:KB]
 
     if (landmark_asset_id.isNull())
@@ -4632,100 +4632,100 @@ void LLAgent::teleportViaLandmark(const LLUUID& landmark_asset_id)
         gAgentCamera.resetView();
     }
 
-	mTeleportRequest = std::make_shared<LLTeleportRequestViaLandmark>(landmark_asset_id);
-	startTeleportRequest();
+    mTeleportRequest = std::make_shared<LLTeleportRequestViaLandmark>(landmark_asset_id);
+    startTeleportRequest();
 }
 
 void LLAgent::doTeleportViaLandmark(const LLUUID& landmark_asset_id)
 {
-	LLViewerRegion *regionp = getRegion();
-	if(regionp && teleportCore())
-	{
-		LL_INFOS("Teleport") << "Sending TeleportLandmarkRequest. Current region handle " << regionp->getHandle()
-							 << " region id " << regionp->getRegionID()
-							 << " requested landmark id " << landmark_asset_id
-							 << LL_ENDL;
-
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_TeleportLandmarkRequest);
-		msg->nextBlockFast(_PREHASH_Info);
-		msg->addUUIDFast(_PREHASH_AgentID, getID());
-		msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
-		msg->addUUIDFast(_PREHASH_LandmarkID, landmark_asset_id);
-		sendReliableMessage();
-	}
+    LLViewerRegion *regionp = getRegion();
+    if(regionp && teleportCore())
+    {
+        LL_INFOS("Teleport") << "Sending TeleportLandmarkRequest. Current region handle " << regionp->getHandle()
+                             << " region id " << regionp->getRegionID()
+                             << " requested landmark id " << landmark_asset_id
+                             << LL_ENDL;
+
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_TeleportLandmarkRequest);
+        msg->nextBlockFast(_PREHASH_Info);
+        msg->addUUIDFast(_PREHASH_AgentID, getID());
+        msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+        msg->addUUIDFast(_PREHASH_LandmarkID, landmark_asset_id);
+        sendReliableMessage();
+    }
 }
 
 void LLAgent::teleportViaLure(const LLUUID& lure_id, BOOL godlike)
 {
-	mTeleportRequest = std::make_shared<LLTeleportRequestViaLure>(lure_id, godlike);
-	startTeleportRequest();
+    mTeleportRequest = std::make_shared<LLTeleportRequestViaLure>(lure_id, godlike);
+    startTeleportRequest();
 }
 
 void LLAgent::doTeleportViaLure(const LLUUID& lure_id, BOOL godlike)
 {
-	LLViewerRegion* regionp = getRegion();
-	if(regionp && teleportCore())
-	{
-		U32 teleport_flags = 0x0;
-		if (godlike)
-		{
-			teleport_flags |= TELEPORT_FLAGS_VIA_GODLIKE_LURE;
-			teleport_flags |= TELEPORT_FLAGS_DISABLE_CANCEL;
-		}
-		else
-		{
-			teleport_flags |= TELEPORT_FLAGS_VIA_LURE;
-		}
-
-		LL_INFOS("Teleport") << "Sending TeleportLureRequest."
-							 << " Current region handle " << regionp->getHandle()
-							 << " region id " << regionp->getRegionID()
-							 << " lure id " << lure_id
-							 << LL_ENDL;
-		// send the message
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_TeleportLureRequest);
-		msg->nextBlockFast(_PREHASH_Info);
-		msg->addUUIDFast(_PREHASH_AgentID, getID());
-		msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
-		msg->addUUIDFast(_PREHASH_LureID, lure_id);
-		// teleport_flags is a legacy field, now derived sim-side:
-		msg->addU32Fast(_PREHASH_TeleportFlags, teleport_flags);
-		sendReliableMessage();
-	}	
+    LLViewerRegion* regionp = getRegion();
+    if(regionp && teleportCore())
+    {
+        U32 teleport_flags = 0x0;
+        if (godlike)
+        {
+            teleport_flags |= TELEPORT_FLAGS_VIA_GODLIKE_LURE;
+            teleport_flags |= TELEPORT_FLAGS_DISABLE_CANCEL;
+        }
+        else
+        {
+            teleport_flags |= TELEPORT_FLAGS_VIA_LURE;
+        }
+
+        LL_INFOS("Teleport") << "Sending TeleportLureRequest."
+                             << " Current region handle " << regionp->getHandle()
+                             << " region id " << regionp->getRegionID()
+                             << " lure id " << lure_id
+                             << LL_ENDL;
+        // send the message
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_TeleportLureRequest);
+        msg->nextBlockFast(_PREHASH_Info);
+        msg->addUUIDFast(_PREHASH_AgentID, getID());
+        msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+        msg->addUUIDFast(_PREHASH_LureID, lure_id);
+        // teleport_flags is a legacy field, now derived sim-side:
+        msg->addU32Fast(_PREHASH_TeleportFlags, teleport_flags);
+        sendReliableMessage();
+    }
 }
 
 
 // James Cook, July 28, 2005
 void LLAgent::teleportCancel()
 {
-	if (!hasPendingTeleportRequest())
-	{
-		LLViewerRegion* regionp = getRegion();
-		if(regionp)
-		{
-			LL_INFOS("Teleport") << "Sending TeleportCancel" << LL_ENDL;
-			
-			// send the message
-			LLMessageSystem* msg = gMessageSystem;
-			msg->newMessageFast(_PREHASH_TeleportCancel);
-			msg->nextBlockFast(_PREHASH_Info);
-			msg->addUUIDFast(_PREHASH_AgentID, getID());
-			msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
-			sendReliableMessage();
-		}
-		mTeleportCanceled = mTeleportRequest;
-	}
-	clearTeleportRequest();
-	gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
+    if (!hasPendingTeleportRequest())
+    {
+        LLViewerRegion* regionp = getRegion();
+        if(regionp)
+        {
+            LL_INFOS("Teleport") << "Sending TeleportCancel" << LL_ENDL;
+
+            // send the message
+            LLMessageSystem* msg = gMessageSystem;
+            msg->newMessageFast(_PREHASH_TeleportCancel);
+            msg->nextBlockFast(_PREHASH_Info);
+            msg->addUUIDFast(_PREHASH_AgentID, getID());
+            msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+            sendReliableMessage();
+        }
+        mTeleportCanceled = mTeleportRequest;
+    }
+    clearTeleportRequest();
+    gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
 }
 
 void LLAgent::restoreCanceledTeleportRequest()
 {
     if (mTeleportCanceled != NULL)
     {
-		LL_INFOS() << "Restoring canceled teleport request, setting state to TELEPORT_REQUESTED" << LL_ENDL;
+        LL_INFOS() << "Restoring canceled teleport request, setting state to TELEPORT_REQUESTED" << LL_ENDL;
         gAgent.setTeleportState( LLAgent::TELEPORT_REQUESTED );
         mTeleportRequest = mTeleportCanceled;
         mTeleportCanceled.reset();
@@ -4737,156 +4737,156 @@ void LLAgent::restoreCanceledTeleportRequest()
 void LLAgent::teleportViaLocation(const LLVector3d& pos_global)
 {
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	if ( (RlvActions::isRlvEnabled()) && (!RlvUtil::isForceTp()) )
-	{
-		if (LLStartUp::getStartupState() < STATE_STARTED)
-		{
-			return;
-		}
-
-		if ( (RlvActions::isLocalTp(pos_global)) ? !RlvActions::canTeleportToLocal(pos_global) : !RlvActions::canTeleportToLocation() )
-		{
-			RlvUtil::notifyBlocked(RlvStringKeys::Blocked::Teleport);
-			return;
-		}
-
-		if ( (gRlvHandler.getCurrentCommand()) && (RLV_BHVR_TPTO == gRlvHandler.getCurrentCommand()->getBehaviourType()) )
-		{
-			gRlvHandler.setCanCancelTp(false);
-		}
-	}
+    if ( (RlvActions::isRlvEnabled()) && (!RlvUtil::isForceTp()) )
+    {
+        if (LLStartUp::getStartupState() < STATE_STARTED)
+        {
+            return;
+        }
+
+        if ( (RlvActions::isLocalTp(pos_global)) ? !RlvActions::canTeleportToLocal(pos_global) : !RlvActions::canTeleportToLocation() )
+        {
+            RlvUtil::notifyBlocked(RlvStringKeys::Blocked::Teleport);
+            return;
+        }
+
+        if ( (gRlvHandler.getCurrentCommand()) && (RLV_BHVR_TPTO == gRlvHandler.getCurrentCommand()->getBehaviourType()) )
+        {
+            gRlvHandler.setCanCancelTp(false);
+        }
+    }
 // [/RLVa:KB]
 
-	mTeleportRequest = std::make_shared<LLTeleportRequestViaLocation>(pos_global);
-	startTeleportRequest();
+    mTeleportRequest = std::make_shared<LLTeleportRequestViaLocation>(pos_global);
+    startTeleportRequest();
 }
 
 void LLAgent::doTeleportViaLocation(const LLVector3d& pos_global)
 {
-	LLViewerRegion* regionp = getRegion();
-
-	if (!regionp)
-	{
-		return;
-	}
-
-	LLVector3 pos_local;
-	U64 handle;
-	bool is_local = false;
-	if (regionp->pointInRegionGlobal(pos_global))
-	{
-		pos_local = regionp->getPosRegionFromGlobal(pos_global);
-		handle = regionp->getHandle();
-		is_local = true;
-	}
-	else if (LLViewerRegion* other_regionp = LLWorld::instance().getRegionFromPosGlobal(pos_global))
-	{
-		pos_local = LLVector3(pos_global - other_regionp->getOriginGlobal());
-		handle = other_regionp->getHandle();
-	}
-	else if (LLSimInfo* sim_info = LLWorldMap::getInstance()->simInfoFromPosGlobal(pos_global))
-	{
-		pos_local = sim_info->getLocalPos(pos_global);
-		handle = sim_info->getHandle();
-	}
-	else
-	{
-		handle = to_region_handle(pos_global);
-		// determine non-local region location as best we can using global coords
-		// In SL we have uniform region size. This is normal.
-		// In opensim the handle will resolve to a 256m quantised world tile which the server maps back to a region
-		// it "should" also compensate for the local coords. Handle has been "correctly" determined already so we use global % 256
-		pos_local.set(fmod((F32)pos_global.mdV[VX], REGION_WIDTH_METERS),
-			fmod((F32)pos_global.mdV[VY], REGION_WIDTH_METERS),
-			(F32)pos_global.mdV[VZ]);
-	}
-
-	if(teleportCore(is_local)) // Rather a pointless if as teleportCore currently always returns true
-	{
-		// send the message
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_TeleportLocationRequest);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, getID());
-		msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
-
-		msg->nextBlockFast(_PREHASH_Info);
-		msg->addU64Fast(_PREHASH_RegionHandle, handle);
-		msg->addVector3Fast(_PREHASH_Position, pos_local);
-		pos_local.mV[VX] += 1;
-		msg->addVector3Fast(_PREHASH_LookAt, pos_local);
-
-		sendReliableMessage();
-		LL_INFOS("Teleport") << "Sending deprecated TeleportLocationRequest."
-							 << " pos_global " << pos_global
-							 << " region coord (" << (pos_global.mdV[VX] - pos_local.mV[VX])
-							 << "," << (pos_global.mdV[VY] - pos_local.mV[VY])
-							 << " pos_local " << pos_local
-							 << ") region_handle " << handle
-							 << LL_ENDL; 
-
-	}
-}
-
-// Teleport to global position, but keep facing in the same direction 
+    LLViewerRegion* regionp = getRegion();
+
+    if (!regionp)
+    {
+        return;
+    }
+
+    LLVector3 pos_local;
+    U64 handle;
+    bool is_local = false;
+    if (regionp->pointInRegionGlobal(pos_global))
+    {
+        pos_local = regionp->getPosRegionFromGlobal(pos_global);
+        handle = regionp->getHandle();
+        is_local = true;
+    }
+    else if (LLViewerRegion* other_regionp = LLWorld::instance().getRegionFromPosGlobal(pos_global))
+    {
+        pos_local = LLVector3(pos_global - other_regionp->getOriginGlobal());
+        handle = other_regionp->getHandle();
+    }
+    else if (LLSimInfo* sim_info = LLWorldMap::getInstance()->simInfoFromPosGlobal(pos_global))
+    {
+        pos_local = sim_info->getLocalPos(pos_global);
+        handle = sim_info->getHandle();
+    }
+    else
+    {
+        handle = to_region_handle(pos_global);
+        // determine non-local region location as best we can using global coords
+        // In SL we have uniform region size. This is normal.
+        // In opensim the handle will resolve to a 256m quantised world tile which the server maps back to a region
+        // it "should" also compensate for the local coords. Handle has been "correctly" determined already so we use global % 256
+        pos_local.set(fmod((F32)pos_global.mdV[VX], REGION_WIDTH_METERS),
+            fmod((F32)pos_global.mdV[VY], REGION_WIDTH_METERS),
+            (F32)pos_global.mdV[VZ]);
+    }
+
+    if(teleportCore(is_local)) // Rather a pointless if as teleportCore currently always returns true
+    {
+        // send the message
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_TeleportLocationRequest);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, getID());
+        msg->addUUIDFast(_PREHASH_SessionID, getSessionID());
+
+        msg->nextBlockFast(_PREHASH_Info);
+        msg->addU64Fast(_PREHASH_RegionHandle, handle);
+        msg->addVector3Fast(_PREHASH_Position, pos_local);
+        pos_local.mV[VX] += 1;
+        msg->addVector3Fast(_PREHASH_LookAt, pos_local);
+
+        sendReliableMessage();
+        LL_INFOS("Teleport") << "Sending deprecated TeleportLocationRequest."
+                             << " pos_global " << pos_global
+                             << " region coord (" << (pos_global.mdV[VX] - pos_local.mV[VX])
+                             << "," << (pos_global.mdV[VY] - pos_local.mV[VY])
+                             << " pos_local " << pos_local
+                             << ") region_handle " << handle
+                             << LL_ENDL;
+
+    }
+}
+
+// Teleport to global position, but keep facing in the same direction
 // [RLVa:KB] - Checked: RLVa-2.0.0
 void LLAgent::teleportViaLocationLookAt(const LLVector3d& pos_global, const LLVector3& look_at)
 {
-	if ( (RlvActions::isRlvEnabled()) && (!RlvUtil::isForceTp()) )
-	{
-		if ( (RlvActions::isLocalTp(pos_global)) ? !RlvActions::canTeleportToLocal(pos_global) : !RlvActions::canTeleportToLocation() )
-		{
-			RlvUtil::notifyBlocked(RlvStringKeys::Blocked::Teleport);
-			return;
-		}
+    if ( (RlvActions::isRlvEnabled()) && (!RlvUtil::isForceTp()) )
+    {
+        if ( (RlvActions::isLocalTp(pos_global)) ? !RlvActions::canTeleportToLocal(pos_global) : !RlvActions::canTeleportToLocation() )
+        {
+            RlvUtil::notifyBlocked(RlvStringKeys::Blocked::Teleport);
+            return;
+        }
 
-		if ( (gRlvHandler.getCurrentCommand()) && (RLV_BHVR_TPTO == gRlvHandler.getCurrentCommand()->getBehaviourType()) )
-		{
-			gRlvHandler.setCanCancelTp(false);
-		}
-	}
+        if ( (gRlvHandler.getCurrentCommand()) && (RLV_BHVR_TPTO == gRlvHandler.getCurrentCommand()->getBehaviourType()) )
+        {
+            gRlvHandler.setCanCancelTp(false);
+        }
+    }
 
-	mTeleportRequest = std::make_shared<LLTeleportRequestViaLocationLookAt>(pos_global, (look_at.isExactlyZero()) ? LLViewerCamera::getInstance()->getAtAxis() : look_at);
-	startTeleportRequest();
+    mTeleportRequest = std::make_shared<LLTeleportRequestViaLocationLookAt>(pos_global, (look_at.isExactlyZero()) ? LLViewerCamera::getInstance()->getAtAxis() : look_at);
+    startTeleportRequest();
 }
 // [/RLVa:KB]
 //void LLAgent::teleportViaLocationLookAt(const LLVector3d& pos_global)
 //{
-//	mTeleportRequest = LLTeleportRequestPtr(new LLTeleportRequestViaLocationLookAt(pos_global));
-//	startTeleportRequest();
+//  mTeleportRequest = LLTeleportRequestPtr(new LLTeleportRequestViaLocationLookAt(pos_global));
+//  startTeleportRequest();
 //}
 
 // [RLVa:KB] - Checked: RLVa-2.0.0
 void LLAgent::doTeleportViaLocationLookAt(const LLVector3d& pos_global, const LLVector3& look_at)
 {
-	mbTeleportKeepsLookAt = look_at.isExactlyZero();
+    mbTeleportKeepsLookAt = look_at.isExactlyZero();
 
-	if(!gAgentCamera.isfollowCamLocked())
-	{
-		gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);	// detach camera form avatar, so it keeps direction
-	}
+    if(!gAgentCamera.isfollowCamLocked())
+    {
+        gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);  // detach camera form avatar, so it keeps direction
+    }
 
-	teleportRequest(pos_global, look_at);
+    teleportRequest(pos_global, look_at);
 }
 // [/RLVa:KB]
 //void LLAgent::doTeleportViaLocationLookAt(const LLVector3d& pos_global, const LLVector3& look_at)
 //{
-//	mbTeleportKeepsLookAt = true;
+//  mbTeleportKeepsLookAt = true;
 //
-//	if(!gAgentCamera.isfollowCamLocked())
-//	{
-//		gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);	// detach camera form avatar, so it keeps direction
-//	}
+//  if(!gAgentCamera.isfollowCamLocked())
+//  {
+//      gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);  // detach camera form avatar, so it keeps direction
+//  }
 //
-//	U64 region_handle = to_region_handle(pos_global);
-//	LLVector3 pos_local = (LLVector3)(pos_global - from_region_handle(region_handle));
-//	teleportRequest(region_handle, pos_local, look_at);
-//	teleportRequest(region_handle, pos_local, getTeleportKeepsLookAt());
+//  U64 region_handle = to_region_handle(pos_global);
+//  LLVector3 pos_local = (LLVector3)(pos_global - from_region_handle(region_handle));
+//  teleportRequest(region_handle, pos_local, look_at);
+//  teleportRequest(region_handle, pos_local, getTeleportKeepsLookAt());
 //}
 
-LLAgent::ETeleportState	LLAgent::getTeleportState() const
+LLAgent::ETeleportState LLAgent::getTeleportState() const
 {
-    return (mTeleportRequest && (mTeleportRequest->getStatus() == LLTeleportRequest::kFailed)) ? 
+    return (mTeleportRequest && (mTeleportRequest->getStatus() == LLTeleportRequest::kFailed)) ?
         TELEPORT_NONE : mTeleportState;
 }
 
@@ -4894,45 +4894,45 @@ LLAgent::ETeleportState	LLAgent::getTeleportState() const
 void LLAgent::setTeleportState(ETeleportState state)
 {
     if (mTeleportRequest && (state != TELEPORT_NONE) && (mTeleportRequest->getStatus() == LLTeleportRequest::kFailed))
-    {   // A late message has come in regarding a failed teleport.  
+    {   // A late message has come in regarding a failed teleport.
         // We have already decided that it failed so should not reinitiate the teleport sequence in the viewer.
         LL_WARNS("Teleport") << "Attempt to set teleport state to " << state <<
             " for previously failed teleport.  Ignore!" << LL_ENDL;
         return;
     }
     LL_DEBUGS("Teleport") << "Setting teleport state to "
-						  << LLAgent::teleportStateName(state) << "(" << state << ")"
-						  << " Previous state: "
-						  << teleportStateName(mTeleportState) << "(" << mTeleportState << ")"
-						  << LL_ENDL;
-	mTeleportState = state;
-	if (mTeleportState > TELEPORT_NONE && LLPipeline::FreezeTime)
-	{
-		LLFloaterReg::hideInstance("snapshot");
-	}
+                          << LLAgent::teleportStateName(state) << "(" << state << ")"
+                          << " Previous state: "
+                          << teleportStateName(mTeleportState) << "(" << mTeleportState << ")"
+                          << LL_ENDL;
+    mTeleportState = state;
+    if (mTeleportState > TELEPORT_NONE && LLPipeline::FreezeTime)
+    {
+        LLFloaterReg::hideInstance("snapshot");
+    }
 
-	switch (mTeleportState)
-	{
-		case TELEPORT_NONE:
-			mbTeleportKeepsLookAt = false;
-			break;
+    switch (mTeleportState)
+    {
+        case TELEPORT_NONE:
+            mbTeleportKeepsLookAt = false;
+            break;
 
-		case TELEPORT_MOVING:
-		// We're outa here. Save "back" slurl.
-		LLAgentUI::buildSLURL(*mTeleportSourceSLURL);
-			break;
+        case TELEPORT_MOVING:
+        // We're outa here. Save "back" slurl.
+        LLAgentUI::buildSLURL(*mTeleportSourceSLURL);
+            break;
 
-		case TELEPORT_ARRIVING:
-		// First two position updates after a teleport tend to be weird
-		//LLViewerStats::getInstance()->mAgentPositionSnaps.mCountOfNextUpdatesToIgnore = 2;
+        case TELEPORT_ARRIVING:
+        // First two position updates after a teleport tend to be weird
+        //LLViewerStats::getInstance()->mAgentPositionSnaps.mCountOfNextUpdatesToIgnore = 2;
 
-		// Let the interested parties know we've teleported.
-		LLViewerParcelMgr::getInstance()->onTeleportFinished(false, getPositionGlobal());
-			break;
+        // Let the interested parties know we've teleported.
+        LLViewerParcelMgr::getInstance()->onTeleportFinished(false, getPositionGlobal());
+            break;
 
-		default:
-			break;
-	}
+        default:
+            break;
+    }
 }
 
 
@@ -4940,163 +4940,163 @@ void LLAgent::stopCurrentAnimations()
 {
     LL_DEBUGS("Avatar") << "Stopping current animations" << LL_ENDL;
 
-	// This function stops all current overriding animations on this
-	// avatar, propagating this change back to the server.
-	if (isAgentAvatarValid())
-	{
-		std::vector<LLUUID> anim_ids;
-
-		bool restore_stand_animation = true;
-		for ( LLVOAvatar::AnimIterator anim_it =
-			      gAgentAvatarp->mPlayingAnimations.begin();
-		      anim_it != gAgentAvatarp->mPlayingAnimations.end();
-		      anim_it++)
-		{
-			if (anim_it->first == ANIM_AGENT_SIT_GROUND_CONSTRAINED)
-			{
-				restore_stand_animation = false;
-			}
-
-			if ((anim_it->first == ANIM_AGENT_DO_NOT_DISTURB)||
-				(anim_it->first == ANIM_AGENT_SIT_GROUND_CONSTRAINED))
-			{
-				// don't cancel a ground-sit anim, as viewers
-				// use this animation's status in
-				// determining whether we're sitting. ick.
+    // This function stops all current overriding animations on this
+    // avatar, propagating this change back to the server.
+    if (isAgentAvatarValid())
+    {
+        std::vector<LLUUID> anim_ids;
+
+        bool restore_stand_animation = true;
+        for ( LLVOAvatar::AnimIterator anim_it =
+                  gAgentAvatarp->mPlayingAnimations.begin();
+              anim_it != gAgentAvatarp->mPlayingAnimations.end();
+              anim_it++)
+        {
+            if (anim_it->first == ANIM_AGENT_SIT_GROUND_CONSTRAINED)
+            {
+                restore_stand_animation = false;
+            }
+
+            if ((anim_it->first == ANIM_AGENT_DO_NOT_DISTURB)||
+                (anim_it->first == ANIM_AGENT_SIT_GROUND_CONSTRAINED))
+            {
+                // don't cancel a ground-sit anim, as viewers
+                // use this animation's status in
+                // determining whether we're sitting. ick.
                 LL_DEBUGS("Avatar") << "sit or do-not-disturb animation will not be stopped" << LL_ENDL;
-			}
-			else
-			{
-				// stop this animation locally
-				gAgentAvatarp->stopMotion(anim_it->first, TRUE);
-				// ...and tell the server to tell everyone.
-				anim_ids.push_back(anim_it->first);
-			}
-		}
-
-		sendAnimationRequests(anim_ids, ANIM_REQUEST_STOP);
-
-		// Tell the region to clear any animation state overrides
-		sendAnimationStateReset();
-
-		// Revoke all animation permissions
-		if (mRegionp &&
-			gSavedSettings.getBOOL("RevokePermsOnStopAnimation"))
-		{
-			U32 permissions = SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_TRIGGER_ANIMATION].permbit | SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS].permbit;
-			sendRevokePermissions(mRegionp->getRegionID(), permissions);
-			if (gAgentAvatarp->isSitting())
-			{	// Also stand up, since auto-granted sit animation permission has been revoked
-				gAgent.standUp();
-			}
-		}
-
-		// re-assert at least the default standing animation, because
-		// viewers get confused by avs with no associated anims.
-		if (restore_stand_animation)
-		{
-			sendAnimationRequest(ANIM_AGENT_STAND, ANIM_REQUEST_START);
-		}
-	}
+            }
+            else
+            {
+                // stop this animation locally
+                gAgentAvatarp->stopMotion(anim_it->first, TRUE);
+                // ...and tell the server to tell everyone.
+                anim_ids.push_back(anim_it->first);
+            }
+        }
+
+        sendAnimationRequests(anim_ids, ANIM_REQUEST_STOP);
+
+        // Tell the region to clear any animation state overrides
+        sendAnimationStateReset();
+
+        // Revoke all animation permissions
+        if (mRegionp &&
+            gSavedSettings.getBOOL("RevokePermsOnStopAnimation"))
+        {
+            U32 permissions = SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_TRIGGER_ANIMATION].permbit | SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS].permbit;
+            sendRevokePermissions(mRegionp->getRegionID(), permissions);
+            if (gAgentAvatarp->isSitting())
+            {   // Also stand up, since auto-granted sit animation permission has been revoked
+                gAgent.standUp();
+            }
+        }
+
+        // re-assert at least the default standing animation, because
+        // viewers get confused by avs with no associated anims.
+        if (restore_stand_animation)
+        {
+            sendAnimationRequest(ANIM_AGENT_STAND, ANIM_REQUEST_START);
+        }
+    }
 }
 
 void LLAgent::fidget()
 {
-	if (!getAFK())
-	{
-		F32 curTime = mFidgetTimer.getElapsedTimeF32();
-		if (curTime > mNextFidgetTime)
-		{
-			// pick a random fidget anim here
-			S32 oldFidget = mCurrentFidget;
-
-			mCurrentFidget = ll_rand(NUM_AGENT_STAND_ANIMS);
-
-			if (mCurrentFidget != oldFidget)
-			{
-				LLAgent::stopFidget();
-
-				
-				switch(mCurrentFidget)
-				{
-				case 0:
-					mCurrentFidget = 0;
-					break;
-				case 1:
-					sendAnimationRequest(ANIM_AGENT_STAND_1, ANIM_REQUEST_START);
-					mCurrentFidget = 1;
-					break;
-				case 2:
-					sendAnimationRequest(ANIM_AGENT_STAND_2, ANIM_REQUEST_START);
-					mCurrentFidget = 2;
-					break;
-				case 3:
-					sendAnimationRequest(ANIM_AGENT_STAND_3, ANIM_REQUEST_START);
-					mCurrentFidget = 3;
-					break;
-				case 4:
-					sendAnimationRequest(ANIM_AGENT_STAND_4, ANIM_REQUEST_START);
-					mCurrentFidget = 4;
-					break;
-				}
-			}
-
-			// calculate next fidget time
-			mNextFidgetTime = curTime + ll_frand(MAX_FIDGET_TIME - MIN_FIDGET_TIME) + MIN_FIDGET_TIME;
-		}
-	}
+    if (!getAFK())
+    {
+        F32 curTime = mFidgetTimer.getElapsedTimeF32();
+        if (curTime > mNextFidgetTime)
+        {
+            // pick a random fidget anim here
+            S32 oldFidget = mCurrentFidget;
+
+            mCurrentFidget = ll_rand(NUM_AGENT_STAND_ANIMS);
+
+            if (mCurrentFidget != oldFidget)
+            {
+                LLAgent::stopFidget();
+
+
+                switch(mCurrentFidget)
+                {
+                case 0:
+                    mCurrentFidget = 0;
+                    break;
+                case 1:
+                    sendAnimationRequest(ANIM_AGENT_STAND_1, ANIM_REQUEST_START);
+                    mCurrentFidget = 1;
+                    break;
+                case 2:
+                    sendAnimationRequest(ANIM_AGENT_STAND_2, ANIM_REQUEST_START);
+                    mCurrentFidget = 2;
+                    break;
+                case 3:
+                    sendAnimationRequest(ANIM_AGENT_STAND_3, ANIM_REQUEST_START);
+                    mCurrentFidget = 3;
+                    break;
+                case 4:
+                    sendAnimationRequest(ANIM_AGENT_STAND_4, ANIM_REQUEST_START);
+                    mCurrentFidget = 4;
+                    break;
+                }
+            }
+
+            // calculate next fidget time
+            mNextFidgetTime = curTime + ll_frand(MAX_FIDGET_TIME - MIN_FIDGET_TIME) + MIN_FIDGET_TIME;
+        }
+    }
 }
 
 void LLAgent::stopFidget()
 {
-	std::vector<LLUUID> anims;
-	anims.reserve(4);
-	anims.push_back(ANIM_AGENT_STAND_1);
-	anims.push_back(ANIM_AGENT_STAND_2);
-	anims.push_back(ANIM_AGENT_STAND_3);
-	anims.push_back(ANIM_AGENT_STAND_4);
+    std::vector<LLUUID> anims;
+    anims.reserve(4);
+    anims.push_back(ANIM_AGENT_STAND_1);
+    anims.push_back(ANIM_AGENT_STAND_2);
+    anims.push_back(ANIM_AGENT_STAND_3);
+    anims.push_back(ANIM_AGENT_STAND_4);
 
-	gAgent.sendAnimationRequests(anims, ANIM_REQUEST_STOP);
+    gAgent.sendAnimationRequests(anims, ANIM_REQUEST_STOP);
 }
 
 
 void LLAgent::requestEnterGodMode()
 {
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_RequestGodlikePowers);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_RequestBlock);
-	msg->addBOOLFast(_PREHASH_Godlike, TRUE);
-	msg->addUUIDFast(_PREHASH_Token, LLUUID::null);
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_RequestGodlikePowers);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_RequestBlock);
+    msg->addBOOLFast(_PREHASH_Godlike, TRUE);
+    msg->addUUIDFast(_PREHASH_Token, LLUUID::null);
 
-	// simulators need to know about your request
-	sendReliableMessage();
+    // simulators need to know about your request
+    sendReliableMessage();
 }
 
 void LLAgent::requestLeaveGodMode()
 {
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_RequestGodlikePowers);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_RequestBlock);
-	msg->addBOOLFast(_PREHASH_Godlike, FALSE);
-	msg->addUUIDFast(_PREHASH_Token, LLUUID::null);
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_RequestGodlikePowers);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_RequestBlock);
+    msg->addBOOLFast(_PREHASH_Godlike, FALSE);
+    msg->addUUIDFast(_PREHASH_Token, LLUUID::null);
 
-	// simulator needs to know about your request
-	sendReliableMessage();
+    // simulator needs to know about your request
+    sendReliableMessage();
 }
 
 void LLAgent::sendAgentDataUpdateRequest()
 {
-	gMessageSystem->newMessageFast(_PREHASH_AgentDataUpdateRequest);
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	sendReliableMessage();
+    gMessageSystem->newMessageFast(_PREHASH_AgentDataUpdateRequest);
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    sendReliableMessage();
 }
 
 void LLAgent::sendAgentUserInfoRequest()
@@ -5115,7 +5115,7 @@ void LLAgent::sendAgentUserInfoRequest()
             boost::bind(&LLAgent::requestAgentUserInfoCoro, this, cap));
     }
     else
-    { 
+    {
         sendAgentUserInfoRequestMessage();
     }
 }
@@ -5146,29 +5146,29 @@ void LLAgent::requestAgentUserInfoCoro(std::string capurl)
         return;
     }
 
-	if (result.size() == 0 || !result.isMap())
-	{
-		LL_WARNS("UserInfo") << "Failed to get user information." << LL_ENDL;
-		return;
-	}
+    if (result.size() == 0 || !result.isMap())
+    {
+        LL_WARNS("UserInfo") << "Failed to get user information." << LL_ENDL;
+        return;
+    }
 
     bool im_via_email = false;
     bool is_verified_email = false;
     std::string email;
     std::string dir_visibility;
 
-	if(result.has("im_via_email"))
-		im_via_email = result["im_via_email"].asBoolean();
+    if(result.has("im_via_email"))
+        im_via_email = result["im_via_email"].asBoolean();
 
-	if (result.has("is_verified"))
-		is_verified_email = result["is_verified"].asBoolean();
+    if (result.has("is_verified"))
+        is_verified_email = result["is_verified"].asBoolean();
 
-	if (result.has("email"))
-    	email = result["email"].asString();
+    if (result.has("email"))
+        email = result["email"].asString();
 
     dir_visibility = result["directory_visibility"].asString();
 
-    // TODO: This should probably be changed.  I'm not entirely comfortable 
+    // TODO: This should probably be changed.  I'm not entirely comfortable
     // having LLAgent interact directly with the UI in this way.
     LLFloaterPreference::updateUserInfo(dir_visibility, im_via_email, is_verified_email, email);
     LLFloaterSnapshot::setAgentEmail(email);
@@ -5206,18 +5206,18 @@ void LLAgent::updateAgentUserInfoCoro(std::string capurl, bool im_via_email, std
     LLCore::HttpHeaders::ptr_t httpHeaders;
 
     httpOpts->setFollowRedirects(true);
-	LLSD body;
-	if (LLGridManager::instance().isInSecondlife())
-	{
-		body = LLSDMap
-		("dir_visibility", LLSD::String(directory_visibility));
-	}
-	else
-	{
-		body = LLSDMap
-		("dir_visibility", LLSD::String(directory_visibility))
-			("im_via_email", LLSD::Boolean(im_via_email));
-	}
+    LLSD body;
+    if (LLGridManager::instance().isInSecondlife())
+    {
+        body = LLSDMap
+        ("dir_visibility", LLSD::String(directory_visibility));
+    }
+    else
+    {
+        body = LLSDMap
+        ("dir_visibility", LLSD::String(directory_visibility))
+            ("im_via_email", LLSD::Boolean(im_via_email));
+    }
 
     LLSD result = httpAdapter->postAndSuspend(httpRequest, capurl, body, httpOpts, httpHeaders);
 
@@ -5262,138 +5262,138 @@ void LLAgent::sendAgentUpdateUserInfoMessage(bool im_via_email, const std::strin
 
 void LLAgent::observeFriends()
 {
-	if(!mFriendObserver)
-	{
-		mFriendObserver = new LLAgentFriendObserver;
-		LLAvatarTracker::instance().addObserver(mFriendObserver);
-		friendsChanged();
-	}
+    if(!mFriendObserver)
+    {
+        mFriendObserver = new LLAgentFriendObserver;
+        LLAvatarTracker::instance().addObserver(mFriendObserver);
+        friendsChanged();
+    }
 }
 
 std::map<S32, std::string> LLAgent::sTeleportStateName = { { TELEPORT_NONE, "TELEPORT_NONE" },
-														   { TELEPORT_START, "TELEPORT_START" },
-														   { TELEPORT_REQUESTED, "TELEPORT_REQUESTED" },
-														   { TELEPORT_MOVING, "TELEPORT_MOVING" },
-														   { TELEPORT_START_ARRIVAL, "TELEPORT_START_ARRIVAL" },
-														   { TELEPORT_ARRIVING, "TELEPORT_ARRIVING" },
-														   { TELEPORT_LOCAL, "TELEPORT_LOCAL" },
-														   { TELEPORT_PENDING, "TELEPORT_PENDING" } };
+                                                           { TELEPORT_START, "TELEPORT_START" },
+                                                           { TELEPORT_REQUESTED, "TELEPORT_REQUESTED" },
+                                                           { TELEPORT_MOVING, "TELEPORT_MOVING" },
+                                                           { TELEPORT_START_ARRIVAL, "TELEPORT_START_ARRIVAL" },
+                                                           { TELEPORT_ARRIVING, "TELEPORT_ARRIVING" },
+                                                           { TELEPORT_LOCAL, "TELEPORT_LOCAL" },
+                                                           { TELEPORT_PENDING, "TELEPORT_PENDING" } };
 
 const std::string& LLAgent::teleportStateName(S32 state)
 {
-	static std::string invalid_state_str("INVALID");
-	auto iter = LLAgent::sTeleportStateName.find(state);
-	if (iter != LLAgent::sTeleportStateName.end())
-	{
-		return iter->second;
-	}
-	else
-	{
-		return invalid_state_str;
-	}
+    static std::string invalid_state_str("INVALID");
+    auto iter = LLAgent::sTeleportStateName.find(state);
+    if (iter != LLAgent::sTeleportStateName.end())
+    {
+        return iter->second;
+    }
+    else
+    {
+        return invalid_state_str;
+    }
 }
 
 const std::string& LLAgent::getTeleportStateName() const
 {
-	return teleportStateName(getTeleportState());
+    return teleportStateName(getTeleportState());
 }
 
 void LLAgent::parseTeleportMessages(const std::string& xml_filename)
 {
-	LLXMLNodePtr root;
-	BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root);
-
-	if (!success || !root || !root->hasName( "teleport_messages" ))
-	{
-		LL_ERRS() << "Problem reading teleport string XML file: " 
-			   << xml_filename << LL_ENDL;
-		return;
-	}
-
-	for (LLXMLNode* message_set = root->getFirstChild();
-		 message_set != NULL;
-		 message_set = message_set->getNextSibling())
-	{
-		if ( !message_set->hasName("message_set") ) continue;
-
-		std::map<std::string, std::string> *teleport_msg_map = NULL;
-		std::string message_set_name;
-
-		if ( message_set->getAttributeString("name", message_set_name) )
-		{
-			//now we loop over all the string in the set and add them
-			//to the appropriate set
-			if ( message_set_name == "errors" )
-			{
-				teleport_msg_map = &sTeleportErrorMessages;
-			}
-			else if ( message_set_name == "progress" )
-			{
-				teleport_msg_map = &sTeleportProgressMessages;
-			}
-		}
-
-		if ( !teleport_msg_map ) continue;
-
-		std::string message_name;
-		for (LLXMLNode* message_node = message_set->getFirstChild();
-			 message_node != NULL;
-			 message_node = message_node->getNextSibling())
-		{
-			if ( message_node->hasName("message") && 
-				 message_node->getAttributeString("name", message_name) )
-			{
-				(*teleport_msg_map)[message_name] =
-					message_node->getTextContents();
-			} //end if ( message exists and has a name)
-		} //end for (all message in set)
-	}//end for (all message sets in xml file)
+    LLXMLNodePtr root;
+    BOOL success = LLUICtrlFactory::getLayeredXMLNode(xml_filename, root);
+
+    if (!success || !root || !root->hasName( "teleport_messages" ))
+    {
+        LL_ERRS() << "Problem reading teleport string XML file: "
+               << xml_filename << LL_ENDL;
+        return;
+    }
+
+    for (LLXMLNode* message_set = root->getFirstChild();
+         message_set != NULL;
+         message_set = message_set->getNextSibling())
+    {
+        if ( !message_set->hasName("message_set") ) continue;
+
+        std::map<std::string, std::string> *teleport_msg_map = NULL;
+        std::string message_set_name;
+
+        if ( message_set->getAttributeString("name", message_set_name) )
+        {
+            //now we loop over all the string in the set and add them
+            //to the appropriate set
+            if ( message_set_name == "errors" )
+            {
+                teleport_msg_map = &sTeleportErrorMessages;
+            }
+            else if ( message_set_name == "progress" )
+            {
+                teleport_msg_map = &sTeleportProgressMessages;
+            }
+        }
+
+        if ( !teleport_msg_map ) continue;
+
+        std::string message_name;
+        for (LLXMLNode* message_node = message_set->getFirstChild();
+             message_node != NULL;
+             message_node = message_node->getNextSibling())
+        {
+            if ( message_node->hasName("message") &&
+                 message_node->getAttributeString("name", message_name) )
+            {
+                (*teleport_msg_map)[message_name] =
+                    message_node->getTextContents();
+            } //end if ( message exists and has a name)
+        } //end for (all message in set)
+    }//end for (all message sets in xml file)
 }
 
 const void LLAgent::getTeleportSourceSLURL(LLSLURL& slurl) const
 {
-	slurl = *mTeleportSourceSLURL;
+    slurl = *mTeleportSourceSLURL;
 }
 
 // static
 void LLAgent::dumpGroupInfo()
 {
-	LL_INFOS() << "group   " << gAgent.mGroupName << LL_ENDL;
-	LL_INFOS() << "ID      " << gAgent.mGroupID << LL_ENDL;
-	LL_INFOS() << "powers " << gAgent.mGroupPowers << LL_ENDL;
-	LL_INFOS() << "title   " << gAgent.mGroupTitle << LL_ENDL;
-	//LL_INFOS() << "insig   " << gAgent.mGroupInsigniaID << LL_ENDL;
+    LL_INFOS() << "group   " << gAgent.mGroupName << LL_ENDL;
+    LL_INFOS() << "ID      " << gAgent.mGroupID << LL_ENDL;
+    LL_INFOS() << "powers " << gAgent.mGroupPowers << LL_ENDL;
+    LL_INFOS() << "title   " << gAgent.mGroupTitle << LL_ENDL;
+    //LL_INFOS() << "insig   " << gAgent.mGroupInsigniaID << LL_ENDL;
 }
 
 // Draw a representation of current autopilot target
 void LLAgent::renderAutoPilotTarget()
 {
-	if (mAutoPilot)
-	{
-		F32 height_meters;
-		LLVector3d target_global;
+    if (mAutoPilot)
+    {
+        F32 height_meters;
+        LLVector3d target_global;
 
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-		gGL.pushMatrix();
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+        gGL.pushMatrix();
 
-		// not textured
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+        // not textured
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
 
-		// lovely green
-		gGL.color4f(0.f, 1.f, 1.f, 1.f);
+        // lovely green
+        gGL.color4f(0.f, 1.f, 1.f, 1.f);
 
-		target_global = mAutoPilotTargetGlobal;
+        target_global = mAutoPilotTargetGlobal;
 
-		gGL.translatef((F32)(target_global.mdV[VX]), (F32)(target_global.mdV[VY]), (F32)(target_global.mdV[VZ]));
+        gGL.translatef((F32)(target_global.mdV[VX]), (F32)(target_global.mdV[VY]), (F32)(target_global.mdV[VZ]));
 
-		height_meters = 1.f;
+        height_meters = 1.f;
 
-		gGL.scalef(height_meters, height_meters, height_meters);
+        gGL.scalef(height_meters, height_meters, height_meters);
 
-		gSphere.render();
+        gSphere.render();
 
-		gGL.popMatrix();
-	}
+        gGL.popMatrix();
+    }
 }
 
 /********************************************************************************/
@@ -5403,7 +5403,7 @@ void LLAgent::renderAutoPilotTarget()
 //-----------------------------------------------------------------------------
 
 LLTeleportRequest::LLTeleportRequest()
-	: mStatus(kPending)
+    : mStatus(kPending)
 {
 }
 
@@ -5413,46 +5413,46 @@ LLTeleportRequest::~LLTeleportRequest()
 
 bool LLTeleportRequest::canRestartTeleport()
 {
-	return false;
+    return false;
 }
 
 void LLTeleportRequest::restartTeleport()
 {
-	llassert(0);
+    llassert(0);
 }
 
 // TODO this enum -> name idiom should be in a common class rather than repeated various places.
 const std::string& LLTeleportRequest::statusName(EStatus status)
 {
-	static std::string invalid_status_str("INVALID");
-	auto iter = LLTeleportRequest::sTeleportStatusName.find(status);
-	if (iter != LLTeleportRequest::sTeleportStatusName.end())
-	{
-		return iter->second;
-	}
-	else
-	{
-		return invalid_status_str;
-	}
+    static std::string invalid_status_str("INVALID");
+    auto iter = LLTeleportRequest::sTeleportStatusName.find(status);
+    if (iter != LLTeleportRequest::sTeleportStatusName.end())
+    {
+        return iter->second;
+    }
+    else
+    {
+        return invalid_status_str;
+    }
 }
 
 std::ostream& operator<<(std::ostream& os, const LLTeleportRequest& req)
 {
-	req.toOstream(os);
-	return os;
+    req.toOstream(os);
+    return os;
 }
 
 void LLTeleportRequest::toOstream(std::ostream& os) const
 {
-	os << "status " << statusName(mStatus) << "(" << mStatus << ")";
+    os << "status " << statusName(mStatus) << "(" << mStatus << ")";
 }
 
 //-----------------------------------------------------------------------------
 // LLTeleportRequestViaLandmark
 //-----------------------------------------------------------------------------
 LLTeleportRequestViaLandmark::LLTeleportRequestViaLandmark(const LLUUID &pLandmarkId)
-	: LLTeleportRequest(),
-	mLandmarkId(pLandmarkId)
+    : LLTeleportRequest(),
+    mLandmarkId(pLandmarkId)
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLandmark created, " << *this << LL_ENDL;
 }
@@ -5463,34 +5463,34 @@ LLTeleportRequestViaLandmark::~LLTeleportRequestViaLandmark()
 
 void LLTeleportRequestViaLandmark::toOstream(std::ostream& os) const
 {
-	os << "landmark " << mLandmarkId << " ";
-	LLTeleportRequest::toOstream(os);
+    os << "landmark " << mLandmarkId << " ";
+    LLTeleportRequest::toOstream(os);
 }
 
 bool LLTeleportRequestViaLandmark::canRestartTeleport()
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLandmark::canRestartTeleport? -> true, " << *this << LL_ENDL;
-	return true;
+    return true;
 }
 
 void LLTeleportRequestViaLandmark::startTeleport()
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLandmark::startTeleport, " << *this << LL_ENDL;
-	gAgent.doTeleportViaLandmark(getLandmarkId());
+    gAgent.doTeleportViaLandmark(getLandmarkId());
 }
 
 void LLTeleportRequestViaLandmark::restartTeleport()
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLandmark::restartTeleport, " << *this << LL_ENDL;
-	gAgent.doTeleportViaLandmark(getLandmarkId());
+    gAgent.doTeleportViaLandmark(getLandmarkId());
 }
 //-----------------------------------------------------------------------------
 // LLTeleportRequestViaLure
 //-----------------------------------------------------------------------------
 
 LLTeleportRequestViaLure::LLTeleportRequestViaLure(const LLUUID &pLureId, BOOL pIsLureGodLike)
-	: LLTeleportRequestViaLandmark(pLureId),
-	mIsLureGodLike(pIsLureGodLike)
+    : LLTeleportRequestViaLandmark(pLureId),
+    mIsLureGodLike(pIsLureGodLike)
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLure created" << LL_ENDL;
 }
@@ -5501,23 +5501,23 @@ LLTeleportRequestViaLure::~LLTeleportRequestViaLure()
 
 void LLTeleportRequestViaLure::toOstream(std::ostream& os) const
 {
-	os << "mIsLureGodLike " << (S32) mIsLureGodLike << " ";
-	LLTeleportRequestViaLandmark::toOstream(os);
+    os << "mIsLureGodLike " << (S32) mIsLureGodLike << " ";
+    LLTeleportRequestViaLandmark::toOstream(os);
 }
 
 bool LLTeleportRequestViaLure::canRestartTeleport()
 {
-	// stinson 05/17/2012 : cannot restart a teleport via lure because of server-side restrictions
-	// The current scenario is as follows:
-	//    1. User A initializes a request for User B to teleport via lure
-	//    2. User B accepts the teleport via lure request
-	//    3. The server sees the init request from User A and the accept request from User B and matches them up
-	//    4. The server then removes the paired requests up from the "queue"
-	//    5. The server then fails User B's teleport for reason of maturity level (for example)
-	//    6. User B's viewer prompts user to increase their maturity level profile value.
-	//    7. User B confirms and accepts increase in maturity level
-	//    8. User B's viewer then attempts to teleport via lure again
-	//    9. This request will time-out on the viewer-side because User A's initial request has been removed from the "queue" in step 4
+    // stinson 05/17/2012 : cannot restart a teleport via lure because of server-side restrictions
+    // The current scenario is as follows:
+    //    1. User A initializes a request for User B to teleport via lure
+    //    2. User B accepts the teleport via lure request
+    //    3. The server sees the init request from User A and the accept request from User B and matches them up
+    //    4. The server then removes the paired requests up from the "queue"
+    //    5. The server then fails User B's teleport for reason of maturity level (for example)
+    //    6. User B's viewer prompts user to increase their maturity level profile value.
+    //    7. User B confirms and accepts increase in maturity level
+    //    8. User B's viewer then attempts to teleport via lure again
+    //    9. This request will time-out on the viewer-side because User A's initial request has been removed from the "queue" in step 4
 
     LL_INFOS("Teleport") << "LLTeleportRequestViaLure::canRestartTeleport? -> false" << LL_ENDL;
     return false;
@@ -5526,7 +5526,7 @@ bool LLTeleportRequestViaLure::canRestartTeleport()
 void LLTeleportRequestViaLure::startTeleport()
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLure::startTeleport" << LL_ENDL;
-	gAgent.doTeleportViaLure(getLandmarkId(), isLureGodLike());
+    gAgent.doTeleportViaLure(getLandmarkId(), isLureGodLike());
 }
 
 //-----------------------------------------------------------------------------
@@ -5534,8 +5534,8 @@ void LLTeleportRequestViaLure::startTeleport()
 //-----------------------------------------------------------------------------
 
 LLTeleportRequestViaLocation::LLTeleportRequestViaLocation(const LLVector3d &pPosGlobal)
-	: LLTeleportRequest(),
-	mPosGlobal(pPosGlobal)
+    : LLTeleportRequest(),
+    mPosGlobal(pPosGlobal)
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLocation created" << LL_ENDL;
 }
@@ -5546,20 +5546,20 @@ LLTeleportRequestViaLocation::~LLTeleportRequestViaLocation()
 
 void LLTeleportRequestViaLocation::toOstream(std::ostream& os) const
 {
-	os << "mPosGlobal " << mPosGlobal << " ";
-	LLTeleportRequest::toOstream(os);
+    os << "mPosGlobal " << mPosGlobal << " ";
+    LLTeleportRequest::toOstream(os);
 }
 
 bool LLTeleportRequestViaLocation::canRestartTeleport()
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLocation::canRestartTeleport -> true" << LL_ENDL;
-	return true;
+    return true;
 }
 
 void LLTeleportRequestViaLocation::startTeleport()
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLocation::startTeleport" << LL_ENDL;
-	gAgent.doTeleportViaLocation(getPosGlobal());
+    gAgent.doTeleportViaLocation(getPosGlobal());
 }
 
 void LLTeleportRequestViaLocation::restartTeleport()
@@ -5574,14 +5574,14 @@ void LLTeleportRequestViaLocation::restartTeleport()
 
 // [RLVa:KB] - Checked: RLVa-2.0.0
 LLTeleportRequestViaLocationLookAt::LLTeleportRequestViaLocationLookAt(const LLVector3d &pPosGlobal, const LLVector3& look_at)
-	: LLTeleportRequestViaLocation(pPosGlobal), mLookAt(look_at)
+    : LLTeleportRequestViaLocation(pPosGlobal), mLookAt(look_at)
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLocationLookAt created" << LL_ENDL;
 }
 // [/RLVa:KB]
 
 //LLTeleportRequestViaLocationLookAt::LLTeleportRequestViaLocationLookAt(const LLVector3d &pPosGlobal)
-//	: LLTeleportRequestViaLocation(pPosGlobal)
+//  : LLTeleportRequestViaLocation(pPosGlobal)
 //{
 //}
 
@@ -5591,7 +5591,7 @@ LLTeleportRequestViaLocationLookAt::~LLTeleportRequestViaLocationLookAt()
 
 void LLTeleportRequestViaLocationLookAt::toOstream(std::ostream& os) const
 {
-	LLTeleportRequestViaLocation::toOstream(os);
+    LLTeleportRequestViaLocation::toOstream(os);
 }
 
 bool LLTeleportRequestViaLocationLookAt::canRestartTeleport()
@@ -5604,7 +5604,7 @@ void LLTeleportRequestViaLocationLookAt::startTeleport()
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLocationLookAt::startTeleport" << LL_ENDL;
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	gAgent.doTeleportViaLocationLookAt(getPosGlobal(), getLookAt());
+    gAgent.doTeleportViaLocationLookAt(getPosGlobal(), getLookAt());
 // [/RLVa:KB]
 //    gAgent.doTeleportViaLocationLookAt(getPosGlobal());
 }
@@ -5613,27 +5613,27 @@ void LLTeleportRequestViaLocationLookAt::restartTeleport()
 {
     LL_INFOS("Teleport") << "LLTeleportRequestViaLocationLookAt::restartTeleport" << LL_ENDL;
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	gAgent.doTeleportViaLocationLookAt(getPosGlobal(), getLookAt());
+    gAgent.doTeleportViaLocationLookAt(getPosGlobal(), getLookAt());
 // [/RLVa:KB]
 //    gAgent.doTeleportViaLocationLookAt(getPosGlobal());
 }
 
 LLUUID LLAgent::getGroupForRezzing()
 {
-	if (gSavedSettings.getBOOL("AlchemyRezUnderLandGroup"))
-	{
-		LLParcel* land_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
-		if (land_parcel)
-		{
-			// Is the agent in the land group
-			if (isInGroup(land_parcel->getGroupID()))
-				return land_parcel->getGroupID();
-			// Is the agent in the land group (the group owns the land)
-			else if (isInGroup(land_parcel->getOwnerID()))
-				return land_parcel->getOwnerID();
-		}
-	}
-	return getGroupID();
+    if (gSavedSettings.getBOOL("AlchemyRezUnderLandGroup"))
+    {
+        LLParcel* land_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
+        if (land_parcel)
+        {
+            // Is the agent in the land group
+            if (isInGroup(land_parcel->getGroupID()))
+                return land_parcel->getGroupID();
+            // Is the agent in the land group (the group owns the land)
+            else if (isInGroup(land_parcel->getOwnerID()))
+                return land_parcel->getOwnerID();
+        }
+    }
+    return getGroupID();
 }
 
 // EOF
diff --git a/indra/newview/llagent.h b/indra/newview/llagent.h
index 3dcf1274c0a9af9a6fcee22ec2feaa10689f24eb..38727207afb1a0e63a15db594aa54d387b634d01 100644
--- a/indra/newview/llagent.h
+++ b/indra/newview/llagent.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llagent.h
  * @brief LLAgent class header file
  *
  * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -28,10 +28,10 @@
 #define LL_LLAGENT_H
 
 #include "indra_constants.h"
-#include "llevent.h" 				// LLObservable base class
-#include "llagentdata.h" 			// gAgentID, gAgentSessionID
+#include "llevent.h"                // LLObservable base class
+#include "llagentdata.h"            // gAgentID, gAgentSessionID
 #include "llcharacter.h"
-#include "llcoordframe.h"			// for mFrameAgent
+#include "llcoordframe.h"           // for mFrameAgent
 #include "llavatarappearancedefines.h"
 #include "llpermissionsflags.h"
 #include "llevents.h"
@@ -43,9 +43,9 @@
 #include <boost/shared_ptr.hpp>
 #include <boost/signals2.hpp>
 
-extern const BOOL 	ANIMATE;
-extern const U8 	AGENT_STATE_TYPING;  // Typing indication
-extern const U8 	AGENT_STATE_EDITING; // Set when agent has objects selected
+extern const BOOL   ANIMATE;
+extern const U8     AGENT_STATE_TYPING;  // Typing indication
+extern const U8     AGENT_STATE_EDITING; // Set when agent has objects selected
 
 class LLViewerRegion;
 class LLMotion;
@@ -69,19 +69,19 @@ typedef std::shared_ptr<LLTeleportRequest> LLTeleportRequestPtr;
 
 enum EAnimRequest
 {
-	ANIM_REQUEST_START,
-	ANIM_REQUEST_STOP
+    ANIM_REQUEST_START,
+    ANIM_REQUEST_STOP
 };
 
 struct LLGroupData
 {
-	LLUUID mID;
-	LLUUID mInsigniaID;
-	U64 mPowers;
-	BOOL mAcceptNotices;
-	BOOL mListInProfile;
-	S32 mContribution;
-	std::string mName;
+    LLUUID mID;
+    LLUUID mInsigniaID;
+    U64 mPowers;
+    BOOL mAcceptNotices;
+    BOOL mListInProfile;
+    S32 mContribution;
+    std::string mName;
 };
 
 class LLAgentListener;
@@ -91,61 +91,61 @@ class LLAgentListener;
 //------------------------------------------------------------------------
 class LLAgent final : public LLOldEvents::LLObservable
 {
-	LOG_CLASS(LLAgent);
+    LOG_CLASS(LLAgent);
 
 public:
-	friend class LLAgentDropGroupViewerNode;
+    friend class LLAgentDropGroupViewerNode;
 
 /********************************************************************************
  **                                                                            **
  **                    INITIALIZATION
  **/
 
-	//--------------------------------------------------------------------
-	// Constructors / Destructors
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Constructors / Destructors
+    //--------------------------------------------------------------------
 public:
-	LLAgent();
-	virtual 		~LLAgent();
-	void			init();
-	void			cleanup();
+    LLAgent();
+    virtual         ~LLAgent();
+    void            init();
+    void            cleanup();
 
 private:
 
-	//--------------------------------------------------------------------
-	// Login
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Login
+    //--------------------------------------------------------------------
 public:
-	void			onAppFocusGained();
-	void			setFirstLogin(bool b);
-	// Return TRUE if the database reported this login as the first for this particular user.
-	bool 			isFirstLogin() const 	{ return mFirstLogin; }
-	bool 			isInitialized() const 	{ return mInitialized; }
+    void            onAppFocusGained();
+    void            setFirstLogin(bool b);
+    // Return TRUE if the database reported this login as the first for this particular user.
+    bool            isFirstLogin() const    { return mFirstLogin; }
+    bool            isInitialized() const   { return mInitialized; }
 
     void            setFeatureVersion(S32 version, S32 flags);
     S32             getFeatureVersion();
     void            getFeatureVersionAndFlags(S32 &version, S32 &flags);
     void            showLatestFeatureNotification(const std::string key);
 public:
-	std::string		mMOTD; 					// Message of the day
+    std::string     mMOTD;                  // Message of the day
 private:
-	bool			mInitialized;
-	bool			mFirstLogin;
-	std::shared_ptr<LLAgentListener> mListener;
+    bool            mInitialized;
+    bool            mFirstLogin;
+    std::shared_ptr<LLAgentListener> mListener;
 
-	//--------------------------------------------------------------------
-	// Session
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Session
+    //--------------------------------------------------------------------
 public:
-	const LLUUID&	getID() const				{ return gAgentID; }
-	const LLUUID&	getSessionID() const		{ return gAgentSessionID; }
-	// Note: NEVER send this value in the clear or over any weakly
-	// encrypted channel (such as simple XOR masking).  If you are unsure
-	// ask Aaron or MarkL.
-	const LLUUID&	getSecureSessionID() const	{ return mSecureSessionID; }
+    const LLUUID&   getID() const               { return gAgentID; }
+    const LLUUID&   getSessionID() const        { return gAgentSessionID; }
+    // Note: NEVER send this value in the clear or over any weakly
+    // encrypted channel (such as simple XOR masking).  If you are unsure
+    // ask Aaron or MarkL.
+    const LLUUID&   getSecureSessionID() const  { return mSecureSessionID; }
 public:
-	LLUUID			mSecureSessionID; 			// Secure token for this login session
-	
+    LLUUID          mSecureSessionID;           // Secure token for this login session
+
 /**                    Initialization
  **                                                                            **
  *******************************************************************************/
@@ -155,24 +155,24 @@ class LLAgent final : public LLOldEvents::LLObservable
  **                    IDENTITY
  **/
 
-	//--------------------------------------------------------------------
-	// Name
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Name
+    //--------------------------------------------------------------------
 public:
-	//*TODO remove, is not used as of August 20, 2009
-	void			buildFullnameAndTitle(std::string &name) const;
+    //*TODO remove, is not used as of August 20, 2009
+    void            buildFullnameAndTitle(std::string &name) const;
 
-	//--------------------------------------------------------------------
-	// Gender
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Gender
+    //--------------------------------------------------------------------
 public:
-	// On the very first login, outfit needs to be chosen by some
-	// mechanism, usually by loading the requested initial outfit.  We
-	// don't render the avatar until the choice is made.
-	BOOL 			isOutfitChosen() const 	{ return mOutfitChosen; }
-	void			setOutfitChosen(BOOL b)	{ mOutfitChosen = b; }
+    // On the very first login, outfit needs to be chosen by some
+    // mechanism, usually by loading the requested initial outfit.  We
+    // don't render the avatar until the choice is made.
+    BOOL            isOutfitChosen() const  { return mOutfitChosen; }
+    void            setOutfitChosen(BOOL b) { mOutfitChosen = b; }
 private:
-	BOOL			mOutfitChosen;
+    BOOL            mOutfitChosen;
 
 /**                    Identity
  **                                                                            **
@@ -183,148 +183,148 @@ class LLAgent final : public LLOldEvents::LLObservable
  **                    POSITION
  **/
 
-  	//--------------------------------------------------------------------
- 	// Position
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Position
+    //--------------------------------------------------------------------
 public:
     typedef boost::signals2::signal<void(const LLVector3 &position_local, const LLVector3d &position_global)> position_signal_t;
 
-	LLVector3		getPosAgentFromGlobal(const LLVector3d &pos_global) const;
-	LLVector3d		getPosGlobalFromAgent(const LLVector3 &pos_agent) const;	
-	const LLVector3d &getPositionGlobal() const;
-	const LLVector3	&getPositionAgent();
-	// Call once per frame to update position, angles (radians).
-	void			updateAgentPosition(const F32 dt, const F32 yaw, const S32 mouse_x, const S32 mouse_y);	
-	void			setPositionAgent(const LLVector3 &center);
+    LLVector3       getPosAgentFromGlobal(const LLVector3d &pos_global) const;
+    LLVector3d      getPosGlobalFromAgent(const LLVector3 &pos_agent) const;
+    const LLVector3d &getPositionGlobal() const;
+    const LLVector3 &getPositionAgent();
+    // Call once per frame to update position, angles (radians).
+    void            updateAgentPosition(const F32 dt, const F32 yaw, const S32 mouse_x, const S32 mouse_y);
+    void            setPositionAgent(const LLVector3 &center);
 
     boost::signals2::connection whenPositionChanged(position_signal_t::slot_type fn);
 
 protected:
-	void			propagate(const F32 dt); // ! BUG ! Should roll into updateAgentPosition
+    void            propagate(const F32 dt); // ! BUG ! Should roll into updateAgentPosition
 private:
-	mutable LLVector3d mPositionGlobal;
+    mutable LLVector3d mPositionGlobal;
 
     position_signal_t   mOnPositionChanged;
     LLVector3d          mLastTestGlobal;
 
-  	//--------------------------------------------------------------------
- 	// Velocity
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Velocity
+    //--------------------------------------------------------------------
 public:
-	LLVector3		getVelocity() const;
-	F32				getVelocityZ() const 	{ return getVelocity().mV[VZ]; } // ! HACK !
-	
-  	//--------------------------------------------------------------------
-	// Coordinate System
-	//--------------------------------------------------------------------
+    LLVector3       getVelocity() const;
+    F32             getVelocityZ() const    { return getVelocity().mV[VZ]; } // ! HACK !
+
+    //--------------------------------------------------------------------
+    // Coordinate System
+    //--------------------------------------------------------------------
 public:
-	const LLCoordFrame&	getFrameAgent()	const	{ return mFrameAgent; }
-	void 			initOriginGlobal(const LLVector3d &origin_global); // Only to be used in ONE place
-	void			resetAxes();
-	void			resetAxes(const LLVector3 &look_at); // Makes reasonable left and up
-	// The following three get*Axis functions return direction avatar is looking, not camera.
-	const LLVector3& getAtAxis() const		{ return mFrameAgent.getAtAxis(); }
-	const LLVector3& getUpAxis() const		{ return mFrameAgent.getUpAxis(); }
-	const LLVector3& getLeftAxis() const	{ return mFrameAgent.getLeftAxis(); }
-	LLQuaternion	getQuat() const; 		// Returns the quat that represents the rotation of the agent in the absolute frame
+    const LLCoordFrame& getFrameAgent() const   { return mFrameAgent; }
+    void            initOriginGlobal(const LLVector3d &origin_global); // Only to be used in ONE place
+    void            resetAxes();
+    void            resetAxes(const LLVector3 &look_at); // Makes reasonable left and up
+    // The following three get*Axis functions return direction avatar is looking, not camera.
+    const LLVector3& getAtAxis() const      { return mFrameAgent.getAtAxis(); }
+    const LLVector3& getUpAxis() const      { return mFrameAgent.getUpAxis(); }
+    const LLVector3& getLeftAxis() const    { return mFrameAgent.getLeftAxis(); }
+    LLQuaternion    getQuat() const;        // Returns the quat that represents the rotation of the agent in the absolute frame
 private:
-	LLVector3d		mAgentOriginGlobal;		// Origin of agent coords from global coords
-	LLCoordFrame	mFrameAgent; 			// Agent position and view, agent-region coordinates
+    LLVector3d      mAgentOriginGlobal;     // Origin of agent coords from global coords
+    LLCoordFrame    mFrameAgent;            // Agent position and view, agent-region coordinates
 
 
-	//--------------------------------------------------------------------
-	// Home
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Home
+    //--------------------------------------------------------------------
 public:
-	void			setStartPosition(U32 location_id); // Marks current location as start, sends information to servers
-	void			setHomePosRegion(const U64& region_handle, const LLVector3& pos_region);
-	BOOL			getHomePosGlobal(LLVector3d* pos_global);
-	bool			isInHomeRegion();
+    void            setStartPosition(U32 location_id); // Marks current location as start, sends information to servers
+    void            setHomePosRegion(const U64& region_handle, const LLVector3& pos_region);
+    BOOL            getHomePosGlobal(LLVector3d* pos_global);
+    bool            isInHomeRegion();
 
 private:
     void            setStartPositionSuccess(const LLSD &result);
 
-	BOOL 			mHaveHomePosition;
-	U64				mHomeRegionHandle;
-	LLVector3		mHomePosRegion;
+    BOOL            mHaveHomePosition;
+    U64             mHomeRegionHandle;
+    LLVector3       mHomePosRegion;
 
-	//--------------------------------------------------------------------
-	// Parcel
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Parcel
+    //--------------------------------------------------------------------
 public:
-	void changeParcels(); // called by LLViewerParcelMgr when we cross a parcel boundary
-	
-	// Register a boost callback to be called when the agent changes parcels
-	typedef boost::function<void()> parcel_changed_callback_t;
-	boost::signals2::connection     addParcelChangedCallback(parcel_changed_callback_t);
+    void changeParcels(); // called by LLViewerParcelMgr when we cross a parcel boundary
+
+    // Register a boost callback to be called when the agent changes parcels
+    typedef boost::function<void()> parcel_changed_callback_t;
+    boost::signals2::connection     addParcelChangedCallback(parcel_changed_callback_t);
 
 private:
-	static void capabilityReceivedCallback(const LLUUID &region_id, LLViewerRegion *regionp);
+    static void capabilityReceivedCallback(const LLUUID &region_id, LLViewerRegion *regionp);
 
-	typedef boost::signals2::signal<void()> parcel_changed_signal_t;
-	parcel_changed_signal_t		mParcelChangedSignal;
+    typedef boost::signals2::signal<void()> parcel_changed_signal_t;
+    parcel_changed_signal_t     mParcelChangedSignal;
 
-	//--------------------------------------------------------------------
-	// Region
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Region
+    //--------------------------------------------------------------------
 public:
-	void			setRegion(LLViewerRegion *regionp);
-	LLViewerRegion	*getRegion() const;
-	LLHost			getRegionHost() const;
-	BOOL			inPrelude();
+    void            setRegion(LLViewerRegion *regionp);
+    LLViewerRegion  *getRegion() const;
+    LLHost          getRegionHost() const;
+    BOOL            inPrelude();
 
-    // Capability 
+    // Capability
     const std::string&     getRegionCapability(std::string_view name) const; // short hand for if (getRegion()) { getRegion()->getCapability(name) }
 
-	/**
-	 * Register a boost callback to be called when the agent changes regions
-	 * Note that if you need to access a capability for the region, you may need to wait
-	 * for the capabilities to be received, since in some cases your region changed
-	 * callback will be called before the capabilities have been received.  Your callback
-	 * may need to look something like:
-	 *
-	 * 	 LLViewerRegion* region = gAgent.getRegion();
-	 * 	 if (region->capabilitiesReceived())
-	 * 	 {
-	 *       useCapability(region);
-	 * 	 }
-	 * 	 else // Need to handle via callback after caps arrive.
-	 * 	 {
-	 *       region->setCapabilitiesReceivedCallback(boost::bind(&useCapability,region,_1));
-	 *       // you may or may not want to remove that callback
-	 * 	 }
-	 */
-	typedef boost::signals2::signal<void()> region_changed_signal_t;
-
-	boost::signals2::connection     addRegionChangedCallback(const region_changed_signal_t::slot_type& cb);
-	void                            removeRegionChangedCallback(boost::signals2::connection callback);
-
-
-	void changeInterestListMode(const std::string & new_mode);
+    /**
+     * Register a boost callback to be called when the agent changes regions
+     * Note that if you need to access a capability for the region, you may need to wait
+     * for the capabilities to be received, since in some cases your region changed
+     * callback will be called before the capabilities have been received.  Your callback
+     * may need to look something like:
+     *
+     *   LLViewerRegion* region = gAgent.getRegion();
+     *   if (region->capabilitiesReceived())
+     *   {
+     *       useCapability(region);
+     *   }
+     *   else // Need to handle via callback after caps arrive.
+     *   {
+     *       region->setCapabilitiesReceivedCallback(boost::bind(&useCapability,region,_1));
+     *       // you may or may not want to remove that callback
+     *   }
+     */
+    typedef boost::signals2::signal<void()> region_changed_signal_t;
+
+    boost::signals2::connection     addRegionChangedCallback(const region_changed_signal_t::slot_type& cb);
+    void                            removeRegionChangedCallback(boost::signals2::connection callback);
+
+
+    void changeInterestListMode(const std::string & new_mode);
     const std::string & getInterestListMode() const { return mInterestListMode; }
 
 private:
-	LLViewerRegion	*mRegionp;
-	region_changed_signal_t		            mRegionChangedSignal;
+    LLViewerRegion  *mRegionp;
+    region_changed_signal_t                 mRegionChangedSignal;
 
-    std::string								mInterestListMode;	// How agent wants regions to send updates
+    std::string                             mInterestListMode;  // How agent wants regions to send updates
 
-	//--------------------------------------------------------------------
-	// History
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // History
+    //--------------------------------------------------------------------
 public:
-	S32				getRegionsVisited() const;
-	F64				getDistanceTraveled() const;	
-	void			setDistanceTraveled(F64 dist) { mDistanceTraveled = dist; }
-	
-	const LLVector3d &getLastPositionGlobal() const { return mLastPositionGlobal; }
-	void			setLastPositionGlobal(const LLVector3d &pos) { mLastPositionGlobal = pos; }
+    S32             getRegionsVisited() const;
+    F64             getDistanceTraveled() const;
+    void            setDistanceTraveled(F64 dist) { mDistanceTraveled = dist; }
+
+    const LLVector3d &getLastPositionGlobal() const { return mLastPositionGlobal; }
+    void            setLastPositionGlobal(const LLVector3d &pos) { mLastPositionGlobal = pos; }
 
 private:
-	std::set<U64>	mRegionsVisited;		// Stat - what distinct regions has the avatar been to?
-	F64				mDistanceTraveled;		// Stat - how far has the avatar moved?
-	LLVector3d		mLastPositionGlobal;	// Used to calculate travel distance
-	
+    std::set<U64>   mRegionsVisited;        // Stat - what distinct regions has the avatar been to?
+    F64             mDistanceTraveled;      // Stat - how far has the avatar moved?
+    LLVector3d      mLastPositionGlobal;    // Used to calculate travel distance
+
 /**                    Position
  **                                                                            **
  *******************************************************************************/
@@ -334,164 +334,164 @@ class LLAgent final : public LLOldEvents::LLObservable
  **                    ACTIONS
  **/
 
-	//--------------------------------------------------------------------
-	// Fidget
-	//--------------------------------------------------------------------
-	// Trigger random fidget animations
+    //--------------------------------------------------------------------
+    // Fidget
+    //--------------------------------------------------------------------
+    // Trigger random fidget animations
 public:
-	void			fidget();
-	static void		stopFidget();
+    void            fidget();
+    static void     stopFidget();
 private:
-	LLFrameTimer	mFidgetTimer;
-	LLFrameTimer	mFocusObjectFadeTimer;
-	LLFrameTimer	mMoveTimer;
-	F32				mNextFidgetTime;
-	S32				mCurrentFidget;
-
-	//--------------------------------------------------------------------
-	// Crouch
-	//--------------------------------------------------------------------
+    LLFrameTimer    mFidgetTimer;
+    LLFrameTimer    mFocusObjectFadeTimer;
+    LLFrameTimer    mMoveTimer;
+    F32             mNextFidgetTime;
+    S32             mCurrentFidget;
+
+    //--------------------------------------------------------------------
+    // Crouch
+    //--------------------------------------------------------------------
 public:
-	bool isCrouching() const;
-	void toggleCrouch() { mCrouch = !mCrouch; }
+    bool isCrouching() const;
+    void toggleCrouch() { mCrouch = !mCrouch; }
 private:
-	bool mCrouch;
+    bool mCrouch;
 
-	//--------------------------------------------------------------------
-	// Fly
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Fly
+    //--------------------------------------------------------------------
 public:
-	BOOL			getFlying() const;
-	void			setFlying(BOOL fly, BOOL fail_sound = FALSE);
-	static void		toggleFlying();
-	static bool		enableFlying();
-	BOOL			canFly(); 			// Does this parcel allow you to fly?
-	static bool		isSitting();
-
-	//--------------------------------------------------------------------
-	// Voice
-	//--------------------------------------------------------------------
+    BOOL            getFlying() const;
+    void            setFlying(BOOL fly, BOOL fail_sound = FALSE);
+    static void     toggleFlying();
+    static bool     enableFlying();
+    BOOL            canFly();           // Does this parcel allow you to fly?
+    static bool     isSitting();
+
+    //--------------------------------------------------------------------
+    // Voice
+    //--------------------------------------------------------------------
 public:
-	bool 			isVoiceConnected() const { return mVoiceConnected; }
-	void			setVoiceConnected(const bool b)	{ mVoiceConnected = b; }
+    bool            isVoiceConnected() const { return mVoiceConnected; }
+    void            setVoiceConnected(const bool b) { mVoiceConnected = b; }
 
-	static void		pressMicrophone(const LLSD& name);
-	static void		releaseMicrophone(const LLSD& name);
-	static void		toggleMicrophone(const LLSD& name);
-	static bool		isMicrophoneOn(const LLSD& sdname);
-	static bool		isActionAllowed(const LLSD& sdname);
+    static void     pressMicrophone(const LLSD& name);
+    static void     releaseMicrophone(const LLSD& name);
+    static void     toggleMicrophone(const LLSD& name);
+    static bool     isMicrophoneOn(const LLSD& sdname);
+    static bool     isActionAllowed(const LLSD& sdname);
 
 private:
-	bool			mVoiceConnected;
+    bool            mVoiceConnected;
 
-	//--------------------------------------------------------------------
-	// Chat
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Chat
+    //--------------------------------------------------------------------
 public:
-	void			heardChat(const LLUUID& id);
-	F32				getTypingTime() 		{ return mTypingTimer.getElapsedTimeF32(); }
-	LLUUID			getLastChatter() const 	{ return mLastChatterID; }
-	F32				getNearChatRadius() 	{ return mNearChatRadius; }
+    void            heardChat(const LLUUID& id);
+    F32             getTypingTime()         { return mTypingTimer.getElapsedTimeF32(); }
+    LLUUID          getLastChatter() const  { return mLastChatterID; }
+    F32             getNearChatRadius()     { return mNearChatRadius; }
 protected:
-	void 			ageChat(); 				// Helper function to prematurely age chat when agent is moving
+    void            ageChat();              // Helper function to prematurely age chat when agent is moving
 private:
-	LLFrameTimer	mChatTimer;
-	LLUUID			mLastChatterID;
-	F32				mNearChatRadius;
-	
-	//--------------------------------------------------------------------
-	// Typing
-	//--------------------------------------------------------------------
+    LLFrameTimer    mChatTimer;
+    LLUUID          mLastChatterID;
+    F32             mNearChatRadius;
+
+    //--------------------------------------------------------------------
+    // Typing
+    //--------------------------------------------------------------------
 public:
-	void			startTyping();
-	void			stopTyping();
+    void            startTyping();
+    void            stopTyping();
 public:
-	// When the agent hasn't typed anything for this duration, it leaves the 
-	// typing state (for both chat and IM).
-	static const F32 TYPING_TIMEOUT_SECS;
+    // When the agent hasn't typed anything for this duration, it leaves the
+    // typing state (for both chat and IM).
+    static const F32 TYPING_TIMEOUT_SECS;
 private:
-	LLFrameTimer	mTypingTimer;
+    LLFrameTimer    mTypingTimer;
 
-	//--------------------------------------------------------------------
-	//BD - Custom Posing
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    //BD - Custom Posing
+    //--------------------------------------------------------------------
 public:
-	void			setPosing()				{ mIsPosing = true; }
-	void			clearPosing()			{ mIsPosing = false; }
-	bool			getPosing() const		{ return mIsPosing; }
+    void            setPosing()             { mIsPosing = true; }
+    void            clearPosing()           { mIsPosing = false; }
+    bool            getPosing() const       { return mIsPosing; }
 
-	bool			mIsPosing;
+    bool            mIsPosing;
 
-	//--------------------------------------------------------------------
-	// AFK
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // AFK
+    //--------------------------------------------------------------------
 public:
-	void			setAFK();
-	void			clearAFK();
-	BOOL			getAFK() const;
-	static const F32 MIN_AFK_TIME;
-	
-	//--------------------------------------------------------------------
-	// Run
-	//--------------------------------------------------------------------
+    void            setAFK();
+    void            clearAFK();
+    BOOL            getAFK() const;
+    static const F32 MIN_AFK_TIME;
+
+    //--------------------------------------------------------------------
+    // Run
+    //--------------------------------------------------------------------
 public:
-	enum EDoubleTapRunMode
-	{
-		DOUBLETAP_NONE,
-		DOUBLETAP_FORWARD,
-		DOUBLETAP_BACKWARD,
-		DOUBLETAP_SLIDELEFT,
-		DOUBLETAP_SLIDERIGHT
-	};
+    enum EDoubleTapRunMode
+    {
+        DOUBLETAP_NONE,
+        DOUBLETAP_FORWARD,
+        DOUBLETAP_BACKWARD,
+        DOUBLETAP_SLIDELEFT,
+        DOUBLETAP_SLIDERIGHT
+    };
 
 // [RLVa:KB] - Checked: 2011-05-11 (RLVa-1.3.0i) | Added: RLVa-1.3.0i
-	void			setAlwaysRun();
-	void			setTempRun();
-	void			clearAlwaysRun();
-	void			clearTempRun();
-	void 			sendWalkRun();
-	bool			getTempRun()			{ return mbTempRun; }
-	bool			getRunning() const 		{ return (mbAlwaysRun) || (mbTempRun); }
+    void            setAlwaysRun();
+    void            setTempRun();
+    void            clearAlwaysRun();
+    void            clearTempRun();
+    void            sendWalkRun();
+    bool            getTempRun()            { return mbTempRun; }
+    bool            getRunning() const      { return (mbAlwaysRun) || (mbTempRun); }
 // [/RLVa:KB]
-//	void			setAlwaysRun() 			{ mbAlwaysRun = true; }
-//	void			clearAlwaysRun() 		{ mbAlwaysRun = false; }
-//	void			setRunning() 			{ mbRunning = true; }
-//	void			clearRunning() 			{ mbRunning = false; }
-//	void 			sendWalkRun(bool running);
-	bool			getAlwaysRun() const 	{ return mbAlwaysRun; }
-//	bool			getRunning() const 		{ return mbRunning; }
+//  void            setAlwaysRun()          { mbAlwaysRun = true; }
+//  void            clearAlwaysRun()        { mbAlwaysRun = false; }
+//  void            setRunning()            { mbRunning = true; }
+//  void            clearRunning()          { mbRunning = false; }
+//  void            sendWalkRun(bool running);
+    bool            getAlwaysRun() const    { return mbAlwaysRun; }
+//  bool            getRunning() const      { return mbRunning; }
 public:
-	LLFrameTimer 	mDoubleTapRunTimer;
-	EDoubleTapRunMode mDoubleTapRunMode;
+    LLFrameTimer    mDoubleTapRunTimer;
+    EDoubleTapRunMode mDoubleTapRunMode;
 private:
-	bool 			mbAlwaysRun; 			// Should the avatar run by default rather than walk?
+    bool            mbAlwaysRun;            // Should the avatar run by default rather than walk?
 // [RLVa:KB] - Checked: 2011-05-11 (RLVa-1.3.0i) | Added: RLVa-1.3.0i
-	bool 			mbTempRun;
+    bool            mbTempRun;
 // [/RLVa:KB]
-//	bool 			mbRunning;				// Is the avatar trying to run right now?
-	bool			mbTeleportKeepsLookAt;	// Try to keep look-at after teleport is complete
+//  bool            mbRunning;              // Is the avatar trying to run right now?
+    bool            mbTeleportKeepsLookAt;  // Try to keep look-at after teleport is complete
 
-	//--------------------------------------------------------------------
-	// Sit and stand
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Sit and stand
+    //--------------------------------------------------------------------
 public:
-	void			standUp();
-	/// @brief ground-sit at agent's current position
-	void			sitDown();
+    void            standUp();
+    /// @brief ground-sit at agent's current position
+    void            sitDown();
 
-	//--------------------------------------------------------------------
-	// Do Not Disturb
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Do Not Disturb
+    //--------------------------------------------------------------------
 public:
-	void			setDoNotDisturb(bool pIsDoNotDisturb);
-	bool			isDoNotDisturb() const;
+    void            setDoNotDisturb(bool pIsDoNotDisturb);
+    bool            isDoNotDisturb() const;
 
 public:
-	void			setRejectTeleportOffers(bool pIsRejectTeleportOffers);
-	bool 			isRejectTeleportOffers() const;
+    void            setRejectTeleportOffers(bool pIsRejectTeleportOffers);
+    bool            isRejectTeleportOffers() const;
 private:
-	bool			mIsDoNotDisturb;
-	bool			mIsRejectTeleportOffers;
+    bool            mIsDoNotDisturb;
+    bool            mIsRejectTeleportOffers;
 
 public:
     void            setRejectFriendshipRequests();
@@ -501,70 +501,70 @@ class LLAgent final : public LLOldEvents::LLObservable
 private:
     BOOL            mIsRejectFriendshipRequests;
 
-	//--------------------------------------------------------------------
-	// Grab
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Grab
+    //--------------------------------------------------------------------
 public:
-	BOOL 			leftButtonGrabbed() const;
-	BOOL 			rotateGrabbed() const;
-	BOOL 			forwardGrabbed() const;
-	BOOL 			backwardGrabbed() const;
-	BOOL 			upGrabbed() const;
-	BOOL 			downGrabbed() const;
-
-	//--------------------------------------------------------------------
-	// Controls
-	//--------------------------------------------------------------------
+    BOOL            leftButtonGrabbed() const;
+    BOOL            rotateGrabbed() const;
+    BOOL            forwardGrabbed() const;
+    BOOL            backwardGrabbed() const;
+    BOOL            upGrabbed() const;
+    BOOL            downGrabbed() const;
+
+    //--------------------------------------------------------------------
+    // Controls
+    //--------------------------------------------------------------------
 public:
-	U32 			getControlFlags(); 
-	void 			setControlFlags(U32 mask); 		// Performs bitwise mControlFlags |= mask
-	void 			clearControlFlags(U32 mask); 	// Performs bitwise mControlFlags &= ~mask
-	BOOL			controlFlagsDirty() const;
-	void			enableControlFlagReset();
-	void 			resetControlFlags();
-	BOOL			anyControlGrabbed() const; 		// True iff a script has taken over a control
-	BOOL			isControlGrabbed(S32 control_index) const;
-	// Send message to simulator to force grabbed controls to be
-	// released, in case of a poorly written script.
-	void			forceReleaseControls();
-	void			setFlagsDirty() { mbFlagsDirty = TRUE; }
+    U32             getControlFlags();
+    void            setControlFlags(U32 mask);      // Performs bitwise mControlFlags |= mask
+    void            clearControlFlags(U32 mask);    // Performs bitwise mControlFlags &= ~mask
+    BOOL            controlFlagsDirty() const;
+    void            enableControlFlagReset();
+    void            resetControlFlags();
+    BOOL            anyControlGrabbed() const;      // True iff a script has taken over a control
+    BOOL            isControlGrabbed(S32 control_index) const;
+    // Send message to simulator to force grabbed controls to be
+    // released, in case of a poorly written script.
+    void            forceReleaseControls();
+    void            setFlagsDirty() { mbFlagsDirty = TRUE; }
 
 private:
-	S32				mControlsTakenCount[TOTAL_CONTROLS];
-	S32				mControlsTakenPassedOnCount[TOTAL_CONTROLS];
-	U32				mControlFlags;					// Replacement for the mFooKey's
-	BOOL 			mbFlagsDirty;
-	BOOL 			mbFlagsNeedReset;				// ! HACK ! For preventing incorrect flags sent when crossing region boundaries
-	
-	BOOL			mIgnorePrejump;
-	//--------------------------------------------------------------------
-	// Animations
-	//--------------------------------------------------------------------
+    S32             mControlsTakenCount[TOTAL_CONTROLS];
+    S32             mControlsTakenPassedOnCount[TOTAL_CONTROLS];
+    U32             mControlFlags;                  // Replacement for the mFooKey's
+    BOOL            mbFlagsDirty;
+    BOOL            mbFlagsNeedReset;               // ! HACK ! For preventing incorrect flags sent when crossing region boundaries
+
+    BOOL            mIgnorePrejump;
+    //--------------------------------------------------------------------
+    // Animations
+    //--------------------------------------------------------------------
 public:
-	void            stopCurrentAnimations();
-	void			requestStopMotion(LLMotion* motion);
-	void			onAnimStop(const LLUUID& id);
-	void			sendAnimationRequests(const std::vector<LLUUID> &anim_ids, EAnimRequest request);
-	void			sendAnimationRequest(const LLUUID &anim_id, EAnimRequest request);
-	void			sendAnimationStateReset();
-	void			sendRevokePermissions(const LLUUID & target, U32 permissions);
-
-	void			endAnimationUpdateUI();
-	void			unpauseAnimation() { mPauseRequest = NULL; }
-	BOOL			getCustomAnim() const { return mCustomAnim; }
-	void			setCustomAnim(BOOL anim) { mCustomAnim = anim; }
-	
-	typedef boost::signals2::signal<void ()> camera_signal_t;
-	boost::signals2::connection setMouselookModeInCallback( const camera_signal_t::slot_type& cb );
-	boost::signals2::connection setMouselookModeOutCallback( const camera_signal_t::slot_type& cb );
+    void            stopCurrentAnimations();
+    void            requestStopMotion(LLMotion* motion);
+    void            onAnimStop(const LLUUID& id);
+    void            sendAnimationRequests(const std::vector<LLUUID> &anim_ids, EAnimRequest request);
+    void            sendAnimationRequest(const LLUUID &anim_id, EAnimRequest request);
+    void            sendAnimationStateReset();
+    void            sendRevokePermissions(const LLUUID & target, U32 permissions);
+
+    void            endAnimationUpdateUI();
+    void            unpauseAnimation() { mPauseRequest = NULL; }
+    BOOL            getCustomAnim() const { return mCustomAnim; }
+    void            setCustomAnim(BOOL anim) { mCustomAnim = anim; }
+
+    typedef boost::signals2::signal<void ()> camera_signal_t;
+    boost::signals2::connection setMouselookModeInCallback( const camera_signal_t::slot_type& cb );
+    boost::signals2::connection setMouselookModeOutCallback( const camera_signal_t::slot_type& cb );
 
 private:
-	camera_signal_t* mMouselookModeInSignal;
-	camera_signal_t* mMouselookModeOutSignal;
-	BOOL            mCustomAnim; 		// Current animation is ANIM_AGENT_CUSTOMIZE ?
-	LLPointer<LLPauseRequestHandle> mPauseRequest;
-	BOOL			mViewsPushed; 		// Keep track of whether or not we have pushed views
-	
+    camera_signal_t* mMouselookModeInSignal;
+    camera_signal_t* mMouselookModeOutSignal;
+    BOOL            mCustomAnim;        // Current animation is ANIM_AGENT_CUSTOMIZE ?
+    LLPointer<LLPauseRequestHandle> mPauseRequest;
+    BOOL            mViewsPushed;       // Keep track of whether or not we have pushed views
+
 /**                    Animation
  **                                                                            **
  *******************************************************************************/
@@ -574,80 +574,80 @@ class LLAgent final : public LLOldEvents::LLObservable
  **                    MOVEMENT
  **/
 
-	//--------------------------------------------------------------------
-	// Movement from user input
-	//--------------------------------------------------------------------
-	// All set the appropriate animation flags.
-	// All turn off autopilot and make sure the camera is behind the avatar.
-	// Direction is either positive, zero, or negative
+    //--------------------------------------------------------------------
+    // Movement from user input
+    //--------------------------------------------------------------------
+    // All set the appropriate animation flags.
+    // All turn off autopilot and make sure the camera is behind the avatar.
+    // Direction is either positive, zero, or negative
 public:
-	void			moveAt(S32 direction, bool reset_view = true);
-	void			moveAtNudge(S32 direction);
-	void			moveLeft(S32 direction);
-	void			moveLeftNudge(S32 direction);
-	void			moveUp(S32 direction);
-	void			moveYaw(F32 mag, bool reset_view = true);
-	void			movePitch(F32 mag);
-
-	BOOL			isMovementLocked() const				{ return mMovementKeysLocked; }
-	void			setMovementLocked(BOOL set_locked)	{ mMovementKeysLocked = set_locked; }
-
-	//--------------------------------------------------------------------
- 	// Move the avatar's frame
-	//--------------------------------------------------------------------
+    void            moveAt(S32 direction, bool reset_view = true);
+    void            moveAtNudge(S32 direction);
+    void            moveLeft(S32 direction);
+    void            moveLeftNudge(S32 direction);
+    void            moveUp(S32 direction);
+    void            moveYaw(F32 mag, bool reset_view = true);
+    void            movePitch(F32 mag);
+
+    BOOL            isMovementLocked() const                { return mMovementKeysLocked; }
+    void            setMovementLocked(BOOL set_locked)  { mMovementKeysLocked = set_locked; }
+
+    //--------------------------------------------------------------------
+    // Move the avatar's frame
+    //--------------------------------------------------------------------
 public:
-	void			rotate(F32 angle, const LLVector3 &axis);
-	void			rotate(F32 angle, F32 x, F32 y, F32 z);
-	void			rotate(const LLMatrix3 &matrix);
-	void			rotate(const LLQuaternion &quaternion);
-	void			pitch(F32 angle);
-	void			roll(F32 angle);
-	void			yaw(F32 angle);
-	LLVector3		getReferenceUpVector();
-
-	//--------------------------------------------------------------------
-	// Autopilot
-	//--------------------------------------------------------------------
+    void            rotate(F32 angle, const LLVector3 &axis);
+    void            rotate(F32 angle, F32 x, F32 y, F32 z);
+    void            rotate(const LLMatrix3 &matrix);
+    void            rotate(const LLQuaternion &quaternion);
+    void            pitch(F32 angle);
+    void            roll(F32 angle);
+    void            yaw(F32 angle);
+    LLVector3       getReferenceUpVector();
+
+    //--------------------------------------------------------------------
+    // Autopilot
+    //--------------------------------------------------------------------
 public:
-	BOOL			getAutoPilot() const				{ return mAutoPilot; }
-	LLVector3d		getAutoPilotTargetGlobal() const 	{ return mAutoPilotTargetGlobal; }
-	LLUUID			getAutoPilotLeaderID() const		{ return mLeaderID; }
-	F32				getAutoPilotStopDistance() const	{ return mAutoPilotStopDistance; }
-	F32				getAutoPilotTargetDist() const		{ return mAutoPilotTargetDist; }
-	BOOL			getAutoPilotUseRotation() const		{ return mAutoPilotUseRotation; }
-	LLVector3		getAutoPilotTargetFacing() const	{ return mAutoPilotTargetFacing; }
-	F32				getAutoPilotRotationThreshold() const	{ return mAutoPilotRotationThreshold; }
-	std::string		getAutoPilotBehaviorName() const	{ return mAutoPilotBehaviorName; }
-
-	void			startAutoPilotGlobal(const LLVector3d &pos_global, 
-										 const std::string& behavior_name = std::string(), 
-										 const LLQuaternion *target_rotation = NULL, 
-										 void (*finish_callback)(BOOL, void *) = NULL, void *callback_data = NULL, 
-										 F32 stop_distance = 0.f, F32 rotation_threshold = 0.03f,
-										 BOOL allow_flying = TRUE);
-	void 			startFollowPilot(const LLUUID &leader_id, BOOL allow_flying = TRUE, F32 stop_distance = 0.5f);
-	void			stopAutoPilot(BOOL user_cancel = FALSE);
-	void 			setAutoPilotTargetGlobal(const LLVector3d &target_global);
-	void			autoPilot(F32 *delta_yaw); 			// Autopilot walking action, angles in radians
-	void			renderAutoPilotTarget();
+    BOOL            getAutoPilot() const                { return mAutoPilot; }
+    LLVector3d      getAutoPilotTargetGlobal() const    { return mAutoPilotTargetGlobal; }
+    LLUUID          getAutoPilotLeaderID() const        { return mLeaderID; }
+    F32             getAutoPilotStopDistance() const    { return mAutoPilotStopDistance; }
+    F32             getAutoPilotTargetDist() const      { return mAutoPilotTargetDist; }
+    BOOL            getAutoPilotUseRotation() const     { return mAutoPilotUseRotation; }
+    LLVector3       getAutoPilotTargetFacing() const    { return mAutoPilotTargetFacing; }
+    F32             getAutoPilotRotationThreshold() const   { return mAutoPilotRotationThreshold; }
+    std::string     getAutoPilotBehaviorName() const    { return mAutoPilotBehaviorName; }
+
+    void            startAutoPilotGlobal(const LLVector3d &pos_global,
+                                         const std::string& behavior_name = std::string(),
+                                         const LLQuaternion *target_rotation = NULL,
+                                         void (*finish_callback)(BOOL, void *) = NULL, void *callback_data = NULL,
+                                         F32 stop_distance = 0.f, F32 rotation_threshold = 0.03f,
+                                         BOOL allow_flying = TRUE);
+    void            startFollowPilot(const LLUUID &leader_id, BOOL allow_flying = TRUE, F32 stop_distance = 0.5f);
+    void            stopAutoPilot(BOOL user_cancel = FALSE);
+    void            setAutoPilotTargetGlobal(const LLVector3d &target_global);
+    void            autoPilot(F32 *delta_yaw);          // Autopilot walking action, angles in radians
+    void            renderAutoPilotTarget();
 private:
-	BOOL			mAutoPilot;
-	BOOL			mAutoPilotFlyOnStop;
-	BOOL			mAutoPilotAllowFlying;
-	LLVector3d		mAutoPilotTargetGlobal;
-	F32				mAutoPilotStopDistance;
-	BOOL			mAutoPilotUseRotation;
-	LLVector3		mAutoPilotTargetFacing;
-	F32				mAutoPilotTargetDist;
-	S32				mAutoPilotNoProgressFrameCount;
-	F32				mAutoPilotRotationThreshold;
-	std::string		mAutoPilotBehaviorName;
-	void			(*mAutoPilotFinishedCallback)(BOOL, void *);
-	void*			mAutoPilotCallbackData;
-	LLUUID			mLeaderID;
-	BOOL			mMovementKeysLocked;
-	bool			mMovementResetCamera;
-	
+    BOOL            mAutoPilot;
+    BOOL            mAutoPilotFlyOnStop;
+    BOOL            mAutoPilotAllowFlying;
+    LLVector3d      mAutoPilotTargetGlobal;
+    F32             mAutoPilotStopDistance;
+    BOOL            mAutoPilotUseRotation;
+    LLVector3       mAutoPilotTargetFacing;
+    F32             mAutoPilotTargetDist;
+    S32             mAutoPilotNoProgressFrameCount;
+    F32             mAutoPilotRotationThreshold;
+    std::string     mAutoPilotBehaviorName;
+    void            (*mAutoPilotFinishedCallback)(BOOL, void *);
+    void*           mAutoPilotCallbackData;
+    LLUUID          mLeaderID;
+    BOOL            mMovementKeysLocked;
+    bool            mMovementResetCamera;
+
 /**                    Movement
  **                                                                            **
  *******************************************************************************/
@@ -658,131 +658,131 @@ class LLAgent final : public LLOldEvents::LLObservable
  **/
 
 public:
-	enum ETeleportState
-	{
-		TELEPORT_NONE = 0,			// No teleport in progress
-		TELEPORT_START = 1,			// Transition to REQUESTED.  Viewer has sent a TeleportRequest to the source simulator
-		TELEPORT_REQUESTED = 2,		// Waiting for source simulator to respond
-		TELEPORT_MOVING = 3,		// Viewer has received destination location from source simulator
-		TELEPORT_START_ARRIVAL = 4,	// Transition to ARRIVING.  Viewer has received avatar update, etc., from destination simulator
-		TELEPORT_ARRIVING = 5,		// Make the user wait while content "pre-caches"
-		TELEPORT_LOCAL = 6,			// Teleporting in-sim without showing the progress screen
-		TELEPORT_PENDING = 7
-	};
-
-	static std::map<S32, std::string> sTeleportStateName;
-	static const std::string& teleportStateName(S32);
-	const std::string& getTeleportStateName() const;
+    enum ETeleportState
+    {
+        TELEPORT_NONE = 0,          // No teleport in progress
+        TELEPORT_START = 1,         // Transition to REQUESTED.  Viewer has sent a TeleportRequest to the source simulator
+        TELEPORT_REQUESTED = 2,     // Waiting for source simulator to respond
+        TELEPORT_MOVING = 3,        // Viewer has received destination location from source simulator
+        TELEPORT_START_ARRIVAL = 4, // Transition to ARRIVING.  Viewer has received avatar update, etc., from destination simulator
+        TELEPORT_ARRIVING = 5,      // Make the user wait while content "pre-caches"
+        TELEPORT_LOCAL = 6,         // Teleporting in-sim without showing the progress screen
+        TELEPORT_PENDING = 7
+    };
+
+    static std::map<S32, std::string> sTeleportStateName;
+    static const std::string& teleportStateName(S32);
+    const std::string& getTeleportStateName() const;
 
 public:
-	static void 	parseTeleportMessages(const std::string& xml_filename);
-	const void getTeleportSourceSLURL(LLSLURL& slurl) const;
+    static void     parseTeleportMessages(const std::string& xml_filename);
+    const void getTeleportSourceSLURL(LLSLURL& slurl) const;
 public:
-	// ! TODO ! Define ERROR and PROGRESS enums here instead of exposing the mappings.
-	static std::map<std::string, std::string> sTeleportErrorMessages;
-	static std::map<std::string, std::string> sTeleportProgressMessages;
+    // ! TODO ! Define ERROR and PROGRESS enums here instead of exposing the mappings.
+    static std::map<std::string, std::string> sTeleportErrorMessages;
+    static std::map<std::string, std::string> sTeleportProgressMessages;
 private:
-	LLSLURL * mTeleportSourceSLURL; 			// SLURL where last TP began
+    LLSLURL * mTeleportSourceSLURL;             // SLURL where last TP began
 
-	//--------------------------------------------------------------------
-	// Teleport Actions
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Teleport Actions
+    //--------------------------------------------------------------------
 public:
-	void 			teleportViaLandmark(const LLUUID& landmark_id);			// Teleport to a landmark
-	void 			teleportHome()	{ teleportViaLandmark(LLUUID::null); }	// Go home
-	void 			teleportViaLure(const LLUUID& lure_id, BOOL godlike);	// To an invited location
-	void 			teleportViaLocation(const LLVector3d& pos_global);		// To a global location - this will probably need to be deprecated
+    void            teleportViaLandmark(const LLUUID& landmark_id);         // Teleport to a landmark
+    void            teleportHome()  { teleportViaLandmark(LLUUID::null); }  // Go home
+    void            teleportViaLure(const LLUUID& lure_id, BOOL godlike);   // To an invited location
+    void            teleportViaLocation(const LLVector3d& pos_global);      // To a global location - this will probably need to be deprecated
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	void			teleportViaLocationLookAt(const LLVector3d& pos_global, const LLVector3& look_at = LLVector3::zero);// To a global location, preserving camera rotation
+    void            teleportViaLocationLookAt(const LLVector3d& pos_global, const LLVector3& look_at = LLVector3::zero);// To a global location, preserving camera rotation
 // [/RLVa:KB]
-//	void			teleportViaLocationLookAt(const LLVector3d& pos_global);// To a global location, preserving camera rotation
-	void 			teleportCancel();										// May or may not be allowed by server
+//  void            teleportViaLocationLookAt(const LLVector3d& pos_global);// To a global location, preserving camera rotation
+    void            teleportCancel();                                       // May or may not be allowed by server
     void            restoreCanceledTeleportRequest();
-    bool			canRestoreCanceledTeleport() { return mTeleportCanceled != NULL; }
-	bool			getTeleportKeepsLookAt() { return mbTeleportKeepsLookAt; } // Whether look-at reset after teleport
+    bool            canRestoreCanceledTeleport() { return mTeleportCanceled != NULL; }
+    bool            getTeleportKeepsLookAt() { return mbTeleportKeepsLookAt; } // Whether look-at reset after teleport
 protected:
-	bool 			teleportCore(bool is_local = false); 					// Stuff for all teleports; returns true if the teleport can proceed
+    bool            teleportCore(bool is_local = false);                    // Stuff for all teleports; returns true if the teleport can proceed
 
-	//--------------------------------------------------------------------
-	// Teleport State
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Teleport State
+    //--------------------------------------------------------------------
 
 public:
-	bool            hasRestartableFailedTeleportRequest();
-	void            restartFailedTeleportRequest();
-	void            clearTeleportRequest();
-	void            setMaturityRatingChangeDuringTeleport(U8 pMaturityRatingChange);
-	void            sheduleTeleportIM();
+    bool            hasRestartableFailedTeleportRequest();
+    void            restartFailedTeleportRequest();
+    void            clearTeleportRequest();
+    void            setMaturityRatingChangeDuringTeleport(U8 pMaturityRatingChange);
+    void            sheduleTeleportIM();
 
 private:
 
 
-	friend class LLTeleportRequest;
-	friend class LLTeleportRequestViaLandmark;
-	friend class LLTeleportRequestViaLure;
-	friend class LLTeleportRequestViaLocation;
-	friend class LLTeleportRequestViaLocationLookAt;
+    friend class LLTeleportRequest;
+    friend class LLTeleportRequestViaLandmark;
+    friend class LLTeleportRequestViaLure;
+    friend class LLTeleportRequestViaLocation;
+    friend class LLTeleportRequestViaLocationLookAt;
 
-	LLTeleportRequestPtr        mTeleportRequest;
-	LLTeleportRequestPtr        mTeleportCanceled;
-	boost::signals2::connection mTeleportFinishedSlot;
-	boost::signals2::connection mTeleportFailedSlot;
+    LLTeleportRequestPtr        mTeleportRequest;
+    LLTeleportRequestPtr        mTeleportCanceled;
+    boost::signals2::connection mTeleportFinishedSlot;
+    boost::signals2::connection mTeleportFailedSlot;
 
-	bool            mIsMaturityRatingChangingDuringTeleport;
-	bool            mTPNeedsNeabyChatSeparator;
-	U8              mMaturityRatingChange;
+    bool            mIsMaturityRatingChangingDuringTeleport;
+    bool            mTPNeedsNeabyChatSeparator;
+    U8              mMaturityRatingChange;
 
-	bool            hasPendingTeleportRequest();
-	void            startTeleportRequest();
+    bool            hasPendingTeleportRequest();
+    void            startTeleportRequest();
 
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	void 			teleportRequest(const LLVector3d& pos_global, const LLVector3& look_at = LLVector3(0, 1, 0));
+    void            teleportRequest(const LLVector3d& pos_global, const LLVector3& look_at = LLVector3(0, 1, 0));
 // [/RLVa:KB]
-//	void 			teleportRequest(const U64& region_handle,
-//									const LLVector3& pos_local,				// Go to a named location home
-//									bool look_at_from_camera = false);
-	void 			doTeleportViaLandmark(const LLUUID& landmark_id);			// Teleport to a landmark
-	void 			doTeleportViaLure(const LLUUID& lure_id, BOOL godlike);	// To an invited location
-	void 			doTeleportViaLocation(const LLVector3d& pos_global);		// To a global location - this will probably need to be deprecated
+//  void            teleportRequest(const U64& region_handle,
+//                                  const LLVector3& pos_local,             // Go to a named location home
+//                                  bool look_at_from_camera = false);
+    void            doTeleportViaLandmark(const LLUUID& landmark_id);           // Teleport to a landmark
+    void            doTeleportViaLure(const LLUUID& lure_id, BOOL godlike); // To an invited location
+    void            doTeleportViaLocation(const LLVector3d& pos_global);        // To a global location - this will probably need to be deprecated
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	void			doTeleportViaLocationLookAt(const LLVector3d& pos_global, const LLVector3& look_at);// To a global location, preserving camera rotation
+    void            doTeleportViaLocationLookAt(const LLVector3d& pos_global, const LLVector3& look_at);// To a global location, preserving camera rotation
 // [/RLVa:KB]
-//	void			doTeleportViaLocationLookAt(const LLVector3d& pos_global);// To a global location, preserving camera rotation
+//  void            doTeleportViaLocationLookAt(const LLVector3d& pos_global);// To a global location, preserving camera rotation
 
-	void            handleTeleportFinished();
-	void            handleTeleportFailed();
+    void            handleTeleportFinished();
+    void            handleTeleportFailed();
 
     static void     addTPNearbyChatSeparator();
     static void     onCapabilitiesReceivedAfterTeleport();
 
-	//--------------------------------------------------------------------
-	// Teleport State
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Teleport State
+    //--------------------------------------------------------------------
 public:
-    ETeleportState	getTeleportState() const;
-	void			setTeleportState(ETeleportState state);
+    ETeleportState  getTeleportState() const;
+    void            setTeleportState(ETeleportState state);
 private:
-	ETeleportState	mTeleportState;
+    ETeleportState  mTeleportState;
 
-	//--------------------------------------------------------------------
-	// Teleport Message
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Teleport Message
+    //--------------------------------------------------------------------
 public:
-	const std::string& getTeleportMessage() const 					{ return mTeleportMessage; }
-	void 			setTeleportMessage(const std::string& message) 	{ mTeleportMessage = message; }
+    const std::string& getTeleportMessage() const                   { return mTeleportMessage; }
+    void            setTeleportMessage(const std::string& message)  { mTeleportMessage = message; }
 private:
-	std::string		mTeleportMessage;
-	
+    std::string     mTeleportMessage;
+
 /**                    Teleport
  **                                                                            **
  *******************************************************************************/
 
-	// Build
+    // Build
 public:
-	bool			canEditParcel() const { return mCanEditParcel; }
+    bool            canEditParcel() const { return mCanEditParcel; }
 private:
-	static void     setCanEditParcel();
-	bool			mCanEditParcel;
+    static void     setCanEditParcel();
+    bool            mCanEditParcel;
 
 
 
@@ -792,83 +792,83 @@ class LLAgent final : public LLOldEvents::LLObservable
  **/
 
 public:
-	// Checks if agent can modify an object based on the permissions and the agent's proxy status.
-	BOOL			isGrantedProxy(const LLPermissions& perm);
-	BOOL			allowOperation(PermissionBit op,
-								   const LLPermissions& perm,
-								   U64 group_proxy_power = 0,
-								   U8 god_minimum = GOD_MAINTENANCE);
-	const LLAgentAccess& getAgentAccess();
-	BOOL			canManageEstate() const;
-	BOOL			getAdminOverride() const;
+    // Checks if agent can modify an object based on the permissions and the agent's proxy status.
+    BOOL            isGrantedProxy(const LLPermissions& perm);
+    BOOL            allowOperation(PermissionBit op,
+                                   const LLPermissions& perm,
+                                   U64 group_proxy_power = 0,
+                                   U8 god_minimum = GOD_MAINTENANCE);
+    const LLAgentAccess& getAgentAccess();
+    BOOL            canManageEstate() const;
+    BOOL            getAdminOverride() const;
 private:
-	LLAgentAccess * mAgentAccess;
-	
-	//--------------------------------------------------------------------
-	// God
-	//--------------------------------------------------------------------
+    LLAgentAccess * mAgentAccess;
+
+    //--------------------------------------------------------------------
+    // God
+    //--------------------------------------------------------------------
 public:
-	bool			isGodlike() const;
-	bool			isGodlikeWithoutAdminMenuFakery() const;
-	U8				getGodLevel() const;
-	void			setAdminOverride(BOOL b);
-	void			setGodLevel(U8 god_level);
-	void			requestEnterGodMode();
-	void			requestLeaveGodMode();
+    bool            isGodlike() const;
+    bool            isGodlikeWithoutAdminMenuFakery() const;
+    U8              getGodLevel() const;
+    void            setAdminOverride(BOOL b);
+    void            setGodLevel(U8 god_level);
+    void            requestEnterGodMode();
+    void            requestLeaveGodMode();
 
-	typedef boost::function<void (U8)>         god_level_change_callback_t;
-	typedef boost::signals2::signal<void (U8)> god_level_change_signal_t;
-	typedef boost::signals2::connection        god_level_change_slot_t;
+    typedef boost::function<void (U8)>         god_level_change_callback_t;
+    typedef boost::signals2::signal<void (U8)> god_level_change_signal_t;
+    typedef boost::signals2::connection        god_level_change_slot_t;
 
-	god_level_change_slot_t registerGodLevelChanageListener(god_level_change_callback_t pGodLevelChangeCallback);
+    god_level_change_slot_t registerGodLevelChanageListener(god_level_change_callback_t pGodLevelChangeCallback);
 
 private:
-	god_level_change_signal_t mGodLevelChangeSignal;
-	
+    god_level_change_signal_t mGodLevelChangeSignal;
+
 
-	//--------------------------------------------------------------------
-	// Maturity
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Maturity
+    //--------------------------------------------------------------------
 public:
-	// Note: this is a prime candidate for pulling out into a Maturity class.
-	// Rather than just expose the preference setting, we're going to actually
-	// expose what the client code cares about -- what the user should see
-	// based on a combination of the is* and prefers* flags, combined with god bit.
-	bool 			wantsPGOnly() const;
-	bool 			canAccessMature() const;
-	bool 			canAccessAdult() const;
-	bool 			canAccessMaturityInRegion( U64 region_handle ) const;
-	bool 			canAccessMaturityAtGlobal( LLVector3d pos_global ) const;
-	bool 			prefersPG() const;
-	bool 			prefersMature() const;
-	bool 			prefersAdult() const;
-	bool 			isTeen() const;
-	bool 			isMature() const;
-	bool 			isAdult() const;
-	void 			setMaturity(char text);
-	static int 		convertTextToMaturity(char text);
+    // Note: this is a prime candidate for pulling out into a Maturity class.
+    // Rather than just expose the preference setting, we're going to actually
+    // expose what the client code cares about -- what the user should see
+    // based on a combination of the is* and prefers* flags, combined with god bit.
+    bool            wantsPGOnly() const;
+    bool            canAccessMature() const;
+    bool            canAccessAdult() const;
+    bool            canAccessMaturityInRegion( U64 region_handle ) const;
+    bool            canAccessMaturityAtGlobal( LLVector3d pos_global ) const;
+    bool            prefersPG() const;
+    bool            prefersMature() const;
+    bool            prefersAdult() const;
+    bool            isTeen() const;
+    bool            isMature() const;
+    bool            isAdult() const;
+    void            setMaturity(char text);
+    static int      convertTextToMaturity(char text);
 
 private:
-	bool                            mIsDoSendMaturityPreferenceToServer;
-	unsigned int                    mMaturityPreferenceRequestId;
-	unsigned int                    mMaturityPreferenceResponseId;
-	unsigned int                    mMaturityPreferenceNumRetries;
-	U8                              mLastKnownRequestMaturity;
-	U8                              mLastKnownResponseMaturity;
-	LLCore::HttpRequest::policy_t	mHttpPolicy;
-
-	bool            isMaturityPreferenceSyncedWithServer() const;
-	void 			sendMaturityPreferenceToServer(U8 pPreferredMaturity);
+    bool                            mIsDoSendMaturityPreferenceToServer;
+    unsigned int                    mMaturityPreferenceRequestId;
+    unsigned int                    mMaturityPreferenceResponseId;
+    unsigned int                    mMaturityPreferenceNumRetries;
+    U8                              mLastKnownRequestMaturity;
+    U8                              mLastKnownResponseMaturity;
+    LLCore::HttpRequest::policy_t   mHttpPolicy;
+
+    bool            isMaturityPreferenceSyncedWithServer() const;
+    void            sendMaturityPreferenceToServer(U8 pPreferredMaturity);
     void            processMaturityPreferenceFromServer(const LLSD &result, U8 perferredMaturity);
 
-	void            handlePreferredMaturityResult(U8 pServerMaturity);
-	void            handlePreferredMaturityError();
-	void            reportPreferredMaturitySuccess();
-	void            reportPreferredMaturityError();
+    void            handlePreferredMaturityResult(U8 pServerMaturity);
+    void            handlePreferredMaturityError();
+    void            reportPreferredMaturitySuccess();
+    void            reportPreferredMaturityError();
 
-	// Maturity callbacks for PreferredMaturity control variable
-	void 			handleMaturity(const LLSD &pNewValue);
-	bool 			validateMaturity(const LLSD& newvalue);
+    // Maturity callbacks for PreferredMaturity control variable
+    void            handleMaturity(const LLSD &pNewValue);
+    bool            validateMaturity(const LLSD& newvalue);
 
 
 /**                    Access
@@ -881,33 +881,33 @@ class LLAgent final : public LLOldEvents::LLObservable
  **/
 
 public:
-	LLQuaternion	getHeadRotation();
-	BOOL			needsRenderAvatar(); // TRUE when camera mode is such that your own avatar should draw
-	BOOL			needsRenderHead();
-	void			setShowAvatar(BOOL show) { mShowAvatar = show; }
-	BOOL			getShowAvatar() const { return mShowAvatar; }
-	
+    LLQuaternion    getHeadRotation();
+    BOOL            needsRenderAvatar(); // TRUE when camera mode is such that your own avatar should draw
+    BOOL            needsRenderHead();
+    void            setShowAvatar(BOOL show) { mShowAvatar = show; }
+    BOOL            getShowAvatar() const { return mShowAvatar; }
+
 private:
-	BOOL			mShowAvatar; 		// Should we render the avatar?
+    BOOL            mShowAvatar;        // Should we render the avatar?
 
-	//--------------------------------------------------------------------
-	// Rendering state bitmap helpers
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Rendering state bitmap helpers
+    //--------------------------------------------------------------------
 public:
-	void			setRenderState(U8 newstate);
-	void			clearRenderState(U8 clearstate);
-	U8				getRenderState();
+    void            setRenderState(U8 newstate);
+    void            clearRenderState(U8 clearstate);
+    U8              getRenderState();
 private:
-	U8				mRenderState; // Current behavior state of agent
+    U8              mRenderState; // Current behavior state of agent
 
-	//--------------------------------------------------------------------
-	// HUD
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // HUD
+    //--------------------------------------------------------------------
 public:
-	const LLColor4	getEffectColor();
-	void			setEffectColor(const LLColor4 &color);
+    const LLColor4  getEffectColor();
+    void            setEffectColor(const LLColor4 &color);
 private:
-	LLUIColor * mEffectColor;
+    LLUIColor * mEffectColor;
 
 /**                    Rendering
  **                                                                            **
@@ -919,61 +919,61 @@ class LLAgent final : public LLOldEvents::LLObservable
  **/
 
 public:
-	const LLUUID	&getGroupID() const			{ return mGroupID; }
-	// Get group information by group_id, or FALSE if not in group.
-	BOOL 			getGroupData(const LLUUID& group_id, LLGroupData& data) const;
-	// Get just the agent's contribution to the given group.
-	S32 			getGroupContribution(const LLUUID& group_id) const;
-	// Update internal datastructures and update the server.
-	BOOL 			setGroupContribution(const LLUUID& group_id, S32 contribution);
-	BOOL 			setUserGroupFlags(const LLUUID& group_id, BOOL accept_notices, BOOL list_in_profile);
-	const std::string &getGroupName() const 	{ return mGroupName; }
-	BOOL			canJoinGroups() const;
+    const LLUUID    &getGroupID() const         { return mGroupID; }
+    // Get group information by group_id, or FALSE if not in group.
+    BOOL            getGroupData(const LLUUID& group_id, LLGroupData& data) const;
+    // Get just the agent's contribution to the given group.
+    S32             getGroupContribution(const LLUUID& group_id) const;
+    // Update internal datastructures and update the server.
+    BOOL            setGroupContribution(const LLUUID& group_id, S32 contribution);
+    BOOL            setUserGroupFlags(const LLUUID& group_id, BOOL accept_notices, BOOL list_in_profile);
+    const std::string &getGroupName() const     { return mGroupName; }
+    BOOL            canJoinGroups() const;
 private:
-	std::string		mGroupName;
-	LLUUID			mGroupID;
+    std::string     mGroupName;
+    LLUUID          mGroupID;
 
-	//--------------------------------------------------------------------
-	// Group Membership
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Group Membership
+    //--------------------------------------------------------------------
 public:
-	// Checks against all groups in the entire agent group list.
-	BOOL 			isInGroup(const LLUUID& group_id, BOOL ingnore_God_mod = FALSE) const;
+    // Checks against all groups in the entire agent group list.
+    BOOL            isInGroup(const LLUUID& group_id, BOOL ingnore_God_mod = FALSE) const;
 protected:
-	// Only used for building titles.
-	BOOL			isGroupMember() const 		{ return !mGroupID.isNull(); } 
+    // Only used for building titles.
+    BOOL            isGroupMember() const       { return !mGroupID.isNull(); }
 public:
-	std::vector<LLGroupData> mGroups;
+    std::vector<LLGroupData> mGroups;
 
-	//--------------------------------------------------------------------
-	// Group Title
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Group Title
+    //--------------------------------------------------------------------
 public:
-	void			setHideGroupTitle(BOOL hide)	{ mHideGroupTitle = hide; }
-	BOOL			isGroupTitleHidden() const 		{ return mHideGroupTitle; }
-	LLUUID			getGroupForRezzing();
+    void            setHideGroupTitle(BOOL hide)    { mHideGroupTitle = hide; }
+    BOOL            isGroupTitleHidden() const      { return mHideGroupTitle; }
+    LLUUID          getGroupForRezzing();
 private:
-	std::string		mGroupTitle; 					// Honorific, like "Sir"
-	BOOL			mHideGroupTitle;
+    std::string     mGroupTitle;                    // Honorific, like "Sir"
+    BOOL            mHideGroupTitle;
 
-	//--------------------------------------------------------------------
-	// Group Powers
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Group Powers
+    //--------------------------------------------------------------------
 public:
-	BOOL 			hasPowerInGroup(const LLUUID& group_id, U64 power) const;
-	BOOL 			hasPowerInActiveGroup(const U64 power) const;
-	U64  			getPowerInGroup(const LLUUID& group_id) const;
- 	U64				mGroupPowers;
-
-	//--------------------------------------------------------------------
-	// Friends
-	//--------------------------------------------------------------------
+    BOOL            hasPowerInGroup(const LLUUID& group_id, U64 power) const;
+    BOOL            hasPowerInActiveGroup(const U64 power) const;
+    U64             getPowerInGroup(const LLUUID& group_id) const;
+    U64             mGroupPowers;
+
+    //--------------------------------------------------------------------
+    // Friends
+    //--------------------------------------------------------------------
 public:
-	void 			observeFriends();
-	void 			friendsChanged();
+    void            observeFriends();
+    void            friendsChanged();
 private:
-	LLFriendObserver* mFriendObserver;
-	std::set<LLUUID> mProxyForAgents;
+    LLFriendObserver* mFriendObserver;
+    std::set<LLUUID> mProxyForAgents;
 
 /**                    Groups
  **                                                                            **
@@ -984,34 +984,34 @@ class LLAgent final : public LLOldEvents::LLObservable
  **                    MESSAGING
  **/
 
-	//--------------------------------------------------------------------
-	// Send
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Send
+    //--------------------------------------------------------------------
 public:
-	void			sendMessage(); // Send message to this agent's region
-	void			sendReliableMessage();
-	void 			sendAgentDataUpdateRequest();
-	void 			sendAgentUserInfoRequest();
+    void            sendMessage(); // Send message to this agent's region
+    void            sendReliableMessage();
+    void            sendAgentDataUpdateRequest();
+    void            sendAgentUserInfoRequest();
 
 // IM to Email and Online visibility
-	void			sendAgentUpdateUserInfo(bool im_to_email, const std::string& directory_visibility);
+    void            sendAgentUpdateUserInfo(bool im_to_email, const std::string& directory_visibility);
 
 private:
     void            requestAgentUserInfoCoro(std::string capurl);
     void            updateAgentUserInfoCoro(std::string capurl, bool im_via_email, std::string directory_visibility);
-    // DEPRECATED: may be removed when User Info cap propagates 
-    void 			sendAgentUserInfoRequestMessage();
+    // DEPRECATED: may be removed when User Info cap propagates
+    void            sendAgentUserInfoRequestMessage();
     void            sendAgentUpdateUserInfoMessage(bool im_via_email, const std::string& directory_visibility);
 
-	//--------------------------------------------------------------------
-	// Receive
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // Receive
+    //--------------------------------------------------------------------
 public:
-	static void		processAgentDataUpdate(LLMessageSystem *msg, void **);
-	static void		processAgentGroupDataUpdate(LLMessageSystem *msg, void **);
-	static void		processAgentDropGroup(LLMessageSystem *msg, void **);
-	static void		processScriptControlChange(LLMessageSystem *msg, void **);
-	
+    static void     processAgentDataUpdate(LLMessageSystem *msg, void **);
+    static void     processAgentGroupDataUpdate(LLMessageSystem *msg, void **);
+    static void     processAgentDropGroup(LLMessageSystem *msg, void **);
+    static void     processScriptControlChange(LLMessageSystem *msg, void **);
+
 /**                    Messaging
  **                                                                            **
  *******************************************************************************/
@@ -1023,8 +1023,8 @@ class LLAgent final : public LLOldEvents::LLObservable
 public:
     typedef LLCoreHttpUtil::HttpCoroutineAdapter::completionCallback_t httpCallback_t;
 
-	/// Utilities for allowing the the agent sub managers to post and get via
-	/// HTTP using the agent's policy settings and headers.  
+    /// Utilities for allowing the the agent sub managers to post and get via
+    /// HTTP using the agent's policy settings and headers.
     bool requestPostCapability(const std::string &capName, LLSD &postData, httpCallback_t cbSuccess = NULL, httpCallback_t cbFailure = NULL);
     bool requestGetCapability(const std::string &capName, httpCallback_t cbSuccess = NULL, httpCallback_t cbFailure = NULL);
 
@@ -1040,9 +1040,9 @@ class LLAgent final : public LLOldEvents::LLObservable
  **/
 
 public:
-	static void		dumpGroupInfo();
-	static void		clearVisualParams(void *);
-	friend std::ostream& operator<<(std::ostream &s, const LLAgent &sphere);
+    static void     dumpGroupInfo();
+    static void     clearVisualParams(void *);
+    friend std::ostream& operator<<(std::ostream &s, const LLAgent &sphere);
 
 /**                    Debugging
  **                                                                            **
@@ -1054,7 +1054,7 @@ extern LLAgent gAgent;
 
 inline bool operator==(const LLGroupData &a, const LLGroupData &b)
 {
-	return (a.mID == b.mID);
+    return (a.mID == b.mID);
 }
 
 #endif
diff --git a/indra/newview/llagentbenefits.cpp b/indra/newview/llagentbenefits.cpp
index 85387e3eae814f6969587ac66e6b3fc8ea2040a3..b0bdd48cb5bd26308db233a83f58ba4d87c535c5 100644
--- a/indra/newview/llagentbenefits.cpp
+++ b/indra/newview/llagentbenefits.cpp
@@ -36,15 +36,15 @@
 #include "llviewerregion.h"
 
 LLAgentBenefits::LLAgentBenefits():
-	m_initalized(false),
-	m_animated_object_limit(-1),
-	m_animation_upload_cost(-1),
-	m_attachment_limit(-1),
-	m_group_membership_limit(-1),
-	m_picks_limit(-1),
-	m_sound_upload_cost(-1),
-	m_texture_upload_cost(-1),
-	m_create_group_cost(-1)
+    m_initalized(false),
+    m_animated_object_limit(-1),
+    m_animation_upload_cost(-1),
+    m_attachment_limit(-1),
+    m_group_membership_limit(-1),
+    m_picks_limit(-1),
+    m_sound_upload_cost(-1),
+    m_texture_upload_cost(-1),
+    m_create_group_cost(-1)
 {
 }
 
@@ -57,53 +57,53 @@ LLAgentBenefits::~LLAgentBenefits()
 // the viewer cares about are integer.
 bool get_required_S32(const LLSD& sd, const LLSD::String& key, S32& value)
 {
-	value = -1;
-	if (sd.has(key))
-	{
-		value = sd[key].asInteger();
-		return true;
-	}
-
-	LL_WARNS("Benefits") << "Missing required benefit field " << key << LL_ENDL;
-	return false;
+    value = -1;
+    if (sd.has(key))
+    {
+        value = sd[key].asInteger();
+        return true;
+    }
+
+    LL_WARNS("Benefits") << "Missing required benefit field " << key << LL_ENDL;
+    return false;
 }
 
 bool LLAgentBenefits::init(const LLSD& benefits_sd)
 {
-	LL_DEBUGS("Benefits") << "initializing benefits from " << benefits_sd << LL_ENDL;
-
-	if (!get_required_S32(benefits_sd, "animated_object_limit", m_animated_object_limit))
-	{
-		return false;
-	}
-	if (!get_required_S32(benefits_sd, "animation_upload_cost", m_animation_upload_cost))
-	{
-		return false;
-	}
-	if (!get_required_S32(benefits_sd, "attachment_limit", m_attachment_limit))
-	{
-		return false;
-	}
-	if (!get_required_S32(benefits_sd, "create_group_cost", m_create_group_cost))
-	{
-		return false;
-	}
-	if (!get_required_S32(benefits_sd, "group_membership_limit", m_group_membership_limit))
-	{
-		return false;
-	}
-	if (!get_required_S32(benefits_sd, "picks_limit", m_picks_limit))
-	{
-		return false;
-	}
-	if (!get_required_S32(benefits_sd, "sound_upload_cost", m_sound_upload_cost))
-	{
-		return false;
-	}
-	if (!get_required_S32(benefits_sd, "texture_upload_cost", m_texture_upload_cost))
-	{
-		return false;
-	}
+    LL_DEBUGS("Benefits") << "initializing benefits from " << benefits_sd << LL_ENDL;
+
+    if (!get_required_S32(benefits_sd, "animated_object_limit", m_animated_object_limit))
+    {
+        return false;
+    }
+    if (!get_required_S32(benefits_sd, "animation_upload_cost", m_animation_upload_cost))
+    {
+        return false;
+    }
+    if (!get_required_S32(benefits_sd, "attachment_limit", m_attachment_limit))
+    {
+        return false;
+    }
+    if (!get_required_S32(benefits_sd, "create_group_cost", m_create_group_cost))
+    {
+        return false;
+    }
+    if (!get_required_S32(benefits_sd, "group_membership_limit", m_group_membership_limit))
+    {
+        return false;
+    }
+    if (!get_required_S32(benefits_sd, "picks_limit", m_picks_limit))
+    {
+        return false;
+    }
+    if (!get_required_S32(benefits_sd, "sound_upload_cost", m_sound_upload_cost))
+    {
+        return false;
+    }
+    if (!get_required_S32(benefits_sd, "texture_upload_cost", m_texture_upload_cost))
+    {
+        return false;
+    }
 
     if (benefits_sd.has("large_texture_upload_cost"))
     {
@@ -125,93 +125,93 @@ bool LLAgentBenefits::init(const LLSD& benefits_sd)
         m_2k_texture_upload_cost.push_back(m_texture_upload_cost);
     }
 
-	// FIXME PREMIUM - either use this field or get rid of it
-	m_initalized = true;
-	return true;
+    // FIXME PREMIUM - either use this field or get rid of it
+    m_initalized = true;
+    return true;
 }
 
 S32 LLAgentBenefits::getAnimatedObjectLimit() const
 {
-	if (LLGridManager::instance().isInSecondlife())
-	{
-		return m_animated_object_limit;
-	}
-	else
-	{
-		S32 max_attach = 0;
-		if (gSavedSettings.getBOOL("AnimatedObjectsIgnoreLimits"))
-		{
-			max_attach = getAttachmentLimit();
-		}
-		else
-		{
-			if (gAgent.getRegion())
-			{
-				LLSD features;
-				gAgent.getRegion()->getSimulatorFeatures(features);
-				if (features.has("AnimatedObjects"))
-				{
-					max_attach = features["AnimatedObjects"]["MaxAgentAnimatedObjectAttachments"].asInteger();
-				}
-			}
-		}
-		return max_attach;
-	}
+    if (LLGridManager::instance().isInSecondlife())
+    {
+        return m_animated_object_limit;
+    }
+    else
+    {
+        S32 max_attach = 0;
+        if (gSavedSettings.getBOOL("AnimatedObjectsIgnoreLimits"))
+        {
+            max_attach = getAttachmentLimit();
+        }
+        else
+        {
+            if (gAgent.getRegion())
+            {
+                LLSD features;
+                gAgent.getRegion()->getSimulatorFeatures(features);
+                if (features.has("AnimatedObjects"))
+                {
+                    max_attach = features["AnimatedObjects"]["MaxAgentAnimatedObjectAttachments"].asInteger();
+                }
+            }
+        }
+        return max_attach;
+    }
 }
 
 S32 LLAgentBenefits::getAnimationUploadCost() const
 {
-	return LLGridManager::instance().isInSecondlife() ? m_animation_upload_cost : LLGlobalEconomy::instance().getPriceUpload();
+    return LLGridManager::instance().isInSecondlife() ? m_animation_upload_cost : LLGlobalEconomy::instance().getPriceUpload();
 }
 
 S32 LLAgentBenefits::getAttachmentLimit() const
 {
-	if (LLGridManager::instance().isInSecondlife())
-	{
-		return m_attachment_limit;
-	}
-	else
-	{
-		const S32 MAX_AGENT_ATTACHMENTS = 38;
-
-		S32 max_attach = MAX_AGENT_ATTACHMENTS;
-
-		if (gAgent.getRegion())
-		{
-			LLSD features;
-			gAgent.getRegion()->getSimulatorFeatures(features);
-			if (features.has("MaxAgentAttachments"))
-			{
-				max_attach = features["MaxAgentAttachments"].asInteger();
-			}
-		}
-		return max_attach;
-	}
+    if (LLGridManager::instance().isInSecondlife())
+    {
+        return m_attachment_limit;
+    }
+    else
+    {
+        const S32 MAX_AGENT_ATTACHMENTS = 38;
+
+        S32 max_attach = MAX_AGENT_ATTACHMENTS;
+
+        if (gAgent.getRegion())
+        {
+            LLSD features;
+            gAgent.getRegion()->getSimulatorFeatures(features);
+            if (features.has("MaxAgentAttachments"))
+            {
+                max_attach = features["MaxAgentAttachments"].asInteger();
+            }
+        }
+        return max_attach;
+    }
 }
 
 S32 LLAgentBenefits::getCreateGroupCost() const
 {
-	return LLGridManager::instance().isInSecondlife() ? m_create_group_cost : 0;
+    return LLGridManager::instance().isInSecondlife() ? m_create_group_cost : 0;
 }
 
 S32 LLAgentBenefits::getGroupMembershipLimit() const
 {
-	return LLGridManager::instance().isInSecondlife() ? m_group_membership_limit : gMaxAgentGroups;
+    return LLGridManager::instance().isInSecondlife() ? m_group_membership_limit : gMaxAgentGroups;
 }
 
 S32 LLAgentBenefits::getPicksLimit() const
 {
-	return LLGridManager::instance().isInSecondlife() ? m_picks_limit : LLAgentPicksInfo::instance().getMaxNumberOfPicks();
+    return LLGridManager::instance().isInSecondlife() ? m_picks_limit : LLAgentPicksInfo::instance().getMaxNumberOfPicks();
 }
 
 S32 LLAgentBenefits::getSoundUploadCost() const
 {
-	return LLGridManager::instance().isInSecondlife() ? m_sound_upload_cost : LLGlobalEconomy::instance().getPriceUpload();
+    return LLGridManager::instance().isInSecondlife() ? m_sound_upload_cost : LLGlobalEconomy::instance().getPriceUpload();
 }
 
 S32 LLAgentBenefits::getTextureUploadCost() const
 {
-	return LLGridManager::instance().isInSecondlife() ? m_texture_upload_cost : LLGlobalEconomy::instance().getPriceUpload();
+    return LLGridManager::instance().isInSecondlife() ? m_texture_upload_cost : LLGlobalEconomy::instance().getPriceUpload();
 }
 
 S32 LLAgentBenefits::getTextureUploadCost(const LLViewerTexture* tex) const
@@ -259,23 +259,23 @@ S32 LLAgentBenefits::get2KTextureUploadCost(S32 area) const
 
 bool LLAgentBenefits::findUploadCost(LLAssetType::EType& asset_type, S32& cost) const
 {
-	bool succ = false;
-	if (asset_type == LLAssetType::AT_TEXTURE)
-	{
+    bool succ = false;
+    if (asset_type == LLAssetType::AT_TEXTURE)
+    {
         cost = getTextureUploadCost();
-		succ = true;
-	}
-	else if (asset_type == LLAssetType::AT_SOUND)
-	{
-		cost = getSoundUploadCost();
-		succ = true;
-	}
-	else if (asset_type == LLAssetType::AT_ANIMATION)
-	{
-		cost = getAnimationUploadCost();
-		succ = true;
-	}
-	return succ;
+        succ = true;
+    }
+    else if (asset_type == LLAssetType::AT_SOUND)
+    {
+        cost = getSoundUploadCost();
+        succ = true;
+    }
+    else if (asset_type == LLAssetType::AT_ANIMATION)
+    {
+        cost = getAnimationUploadCost();
+        succ = true;
+    }
+    return succ;
 }
 
 LLAgentBenefitsMgr::LLAgentBenefitsMgr()
@@ -289,65 +289,65 @@ LLAgentBenefitsMgr::~LLAgentBenefitsMgr()
 // static
 const LLAgentBenefits& LLAgentBenefitsMgr::current()
 {
-	return instance().mCurrent;
+    return instance().mCurrent;
 }
 
 // static
 const LLAgentBenefits& LLAgentBenefitsMgr::get(const std::string& package)
 {
-	if (instance().mPackageMap.find(package) != instance().mPackageMap.end())
-	{
-		return instance().mPackageMap[package];
-	}
-	else
-	{
-		return instance().mDefault;
-	}
+    if (instance().mPackageMap.find(package) != instance().mPackageMap.end())
+    {
+        return instance().mPackageMap[package];
+    }
+    else
+    {
+        return instance().mDefault;
+    }
 }
 
 // static
 bool LLAgentBenefitsMgr::init(const std::string& package, const LLSD& benefits_sd)
 {
-	LLAgentBenefits benefits;
-	if (!benefits.init(benefits_sd))
-	{
-		LL_WARNS("Benefits") << "Unable to initialize package " << package << " from sd " << benefits_sd << LL_ENDL;
-		return false;
-	}
-	else
-	{
-		instance().mPackageMap[package] = benefits;
-	}
-	return true;
+    LLAgentBenefits benefits;
+    if (!benefits.init(benefits_sd))
+    {
+        LL_WARNS("Benefits") << "Unable to initialize package " << package << " from sd " << benefits_sd << LL_ENDL;
+        return false;
+    }
+    else
+    {
+        instance().mPackageMap[package] = benefits;
+    }
+    return true;
 
 }
 
 // static
 bool LLAgentBenefitsMgr::initCurrent(const std::string& package, const LLSD& benefits_sd)
 {
-	LLAgentBenefits benefits;
-	if (!benefits.init(benefits_sd))
-	{
-		LL_WARNS("Benefits") << "Unable to initialize package " << package << " from sd " << benefits_sd << LL_ENDL;
-		return false;
-	}
-	else
-	{
-		instance().mCurrent = benefits;
-		instance().mCurrentName = package;
-	}
-	return true;
+    LLAgentBenefits benefits;
+    if (!benefits.init(benefits_sd))
+    {
+        LL_WARNS("Benefits") << "Unable to initialize package " << package << " from sd " << benefits_sd << LL_ENDL;
+        return false;
+    }
+    else
+    {
+        instance().mCurrent = benefits;
+        instance().mCurrentName = package;
+    }
+    return true;
 
 }
 
 // static
 bool LLAgentBenefitsMgr::has(const std::string& package)
 {
-	return instance().mPackageMap.find(package) != instance().mPackageMap.end();
+    return instance().mPackageMap.find(package) != instance().mPackageMap.end();
 }
 
 //static
 bool LLAgentBenefitsMgr::isCurrent(const std::string& package)
 {
-	return instance().mCurrentName == package;
+    return instance().mCurrentName == package;
 }
diff --git a/indra/newview/llagentbenefits.h b/indra/newview/llagentbenefits.h
index de86f5087942831404b89f687c689866f7b49a15..d90dcb244aef0b121d741877bb822ee8bce988bc 100644
--- a/indra/newview/llagentbenefits.h
+++ b/indra/newview/llagentbenefits.h
@@ -38,59 +38,59 @@ class LLAgentBenefits
 public:
     static constexpr S32 MIN_2K_TEXTURE_AREA = 1024 * 1024 + 1;
 
-	LLAgentBenefits();
-	~LLAgentBenefits();
-	LOG_CLASS(LLAgentBenefits);
+    LLAgentBenefits();
+    ~LLAgentBenefits();
+    LOG_CLASS(LLAgentBenefits);
 
-	bool init(const LLSD& benefits_sd);
+    bool init(const LLSD& benefits_sd);
 
-	S32 getAnimatedObjectLimit() const;
-	S32 getAnimationUploadCost() const;
-	S32 getAttachmentLimit() const;
-	S32 getCreateGroupCost() const;
-	S32 getGroupMembershipLimit() const;
-	S32 getPicksLimit() const;
-	S32 getSoundUploadCost() const;
-	S32 getTextureUploadCost() const;
+    S32 getAnimatedObjectLimit() const;
+    S32 getAnimationUploadCost() const;
+    S32 getAttachmentLimit() const;
+    S32 getCreateGroupCost() const;
+    S32 getGroupMembershipLimit() const;
+    S32 getPicksLimit() const;
+    S32 getSoundUploadCost() const;
+    S32 getTextureUploadCost() const;
     S32 getTextureUploadCost(const LLViewerTexture* tex) const;
     S32 getTextureUploadCost(const LLImageBase* tex) const;
     S32 get2KTextureUploadCost(S32 area) const;
 
-	bool findUploadCost(LLAssetType::EType& asset_type, S32& cost) const;
-	
+    bool findUploadCost(LLAssetType::EType& asset_type, S32& cost) const;
+
 private:
-	S32 m_animated_object_limit;
-	S32 m_animation_upload_cost;
-	S32 m_attachment_limit;
-	S32 m_create_group_cost;
-	S32 m_group_membership_limit;
-	S32 m_picks_limit;
-	S32 m_sound_upload_cost;
-	S32 m_texture_upload_cost;
+    S32 m_animated_object_limit;
+    S32 m_animation_upload_cost;
+    S32 m_attachment_limit;
+    S32 m_create_group_cost;
+    S32 m_group_membership_limit;
+    S32 m_picks_limit;
+    S32 m_sound_upload_cost;
+    S32 m_texture_upload_cost;
     std::vector<S32> m_2k_texture_upload_cost;
 
-	bool m_initalized;
+    bool m_initalized;
 };
 
 class LLAgentBenefitsMgr final : public LLSingleton<LLAgentBenefitsMgr>
 {
-	LLSINGLETON(LLAgentBenefitsMgr);
-	~LLAgentBenefitsMgr();
-	LOG_CLASS(LLAgentBenefitsMgr);
+    LLSINGLETON(LLAgentBenefitsMgr);
+    ~LLAgentBenefitsMgr();
+    LOG_CLASS(LLAgentBenefitsMgr);
 
 public:
-	static const LLAgentBenefits& current();
-	static const LLAgentBenefits& get(const std::string& package);
-	static bool init(const std::string& package, const LLSD& benefits_sd);
-	static bool initCurrent(const std::string& package, const LLSD& benefits_sd);
-	static bool has(const std::string& package);
-	static bool isCurrent(const std::string& package);
+    static const LLAgentBenefits& current();
+    static const LLAgentBenefits& get(const std::string& package);
+    static bool init(const std::string& package, const LLSD& benefits_sd);
+    static bool initCurrent(const std::string& package, const LLSD& benefits_sd);
+    static bool has(const std::string& package);
+    static bool isCurrent(const std::string& package);
 
 private:
-	std::string     mCurrentName;
-	LLAgentBenefits mCurrent;
-	LLAgentBenefits mDefault;
-	std::map<std::string, LLAgentBenefits> mPackageMap;
+    std::string     mCurrentName;
+    LLAgentBenefits mCurrent;
+    LLAgentBenefits mDefault;
+    std::map<std::string, LLAgentBenefits> mPackageMap;
 };
 
 
diff --git a/indra/newview/llagentcamera.cpp b/indra/newview/llagentcamera.cpp
index 5d2f14084339b6738190e95d25a720af6233cb5f..a81f3657085bff9b2d4578f52b93de30eee2c226 100644
--- a/indra/newview/llagentcamera.cpp
+++ b/indra/newview/llagentcamera.cpp
@@ -1,31 +1,31 @@
-/** 
+/**
  * @file llagentcamera.cpp
  * @brief LLAgent class implementation
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
 
 #include "llviewerprecompiledheaders.h"
-#include "llagentcamera.h" 
+#include "llagentcamera.h"
 
 #include "pipeline.h"
 
@@ -68,8 +68,8 @@ const F32 MIN_ZOOM_FRACTION = 0.25f;
 const F32 INITIAL_ZOOM_FRACTION = 1.f;
 const F32 MAX_ZOOM_FRACTION = 8.f;
 
-const F32 CAMERA_ZOOM_HALF_LIFE = 0.07f;	// seconds
-const F32 FOV_ZOOM_HALF_LIFE = 0.07f;	// seconds
+const F32 CAMERA_ZOOM_HALF_LIFE = 0.07f;    // seconds
+const F32 FOV_ZOOM_HALF_LIFE = 0.07f;   // seconds
 
 const F32 CAMERA_FOCUS_HALF_LIFE = 0.f;//0.02f;
 const F32 CAMERA_LAG_HALF_LIFE = 0.25f;
@@ -110,8 +110,8 @@ const F32 OBJECT_EXTENTS_PADDING = 0.5f;
 
 static bool isDisableCameraConstraints()
 {
-	static LLCachedControl<bool> sDisableCameraConstraints(gSavedSettings, "DisableCameraConstraints", false);
-	return sDisableCameraConstraints;
+    static LLCachedControl<bool> sDisableCameraConstraints(gSavedSettings, "DisableCameraConstraints", false);
+    return sDisableCameraConstraints;
 }
 
 // The agent instance.
@@ -121,87 +121,87 @@ LLAgentCamera gAgentCamera;
 // LLAgentCamera()
 //-----------------------------------------------------------------------------
 LLAgentCamera::LLAgentCamera() :
-	mInitialized(false),
-
-	mDrawDistance( DEFAULT_FAR_PLANE ),
-
-	mLookAt(NULL),
-	mPointAt(NULL),
-
-	mHUDTargetZoom(1.f),
-	mHUDCurZoom(1.f),
-
-	mForceMouselook(FALSE),
-
-	mCameraMode( CAMERA_MODE_THIRD_PERSON ),
-	mLastCameraMode( CAMERA_MODE_THIRD_PERSON ),
-
-	mCameraPreset(CAMERA_PRESET_REAR_VIEW),
-
-	mCameraAnimating( FALSE ),
-	mAnimationCameraStartGlobal(),
-	mAnimationFocusStartGlobal(),
-	mAnimationTimer(),
-	mAnimationDuration(0.33f),
-	
-	mCameraFOVZoomFactor(0.f),
-	mCameraCurrentFOVZoomFactor(0.f),
-	mCameraFocusOffset(),
-
-	mCameraCollidePlane(),
-
-	mCurrentCameraDistance(2.f),		// meters, set in init()
-	mTargetCameraDistance(2.f),
-	mCameraZoomFraction(1.f),			// deprecated
-	mThirdPersonHeadOffset(0.f, 0.f, 1.f),
-	mSitCameraEnabled(FALSE),
-	mCameraSmoothingLastPositionGlobal(),
-	mCameraSmoothingLastPositionAgent(),
-	mCameraSmoothingStop(false),
-
-	mCameraUpVector(LLVector3::z_axis), // default is straight up
-
-	mFocusOnAvatar(TRUE),
-	mAllowChangeToFollow(FALSE),
-	mFocusGlobal(),
-	mFocusTargetGlobal(),
-	mFocusObject(NULL),
-	mFocusObjectDist(0.f),
-	mFocusObjectOffset(),
-	mTrackFocusObject(TRUE),
-
-	mAtKey(0), // Either 1, 0, or -1... indicates that movement-key is pressed
-	mWalkKey(0), // like AtKey, but causes less forward thrust
-	mLeftKey(0),
-	mUpKey(0),
-	mYawKey(0.f),
-	mPitchKey(0.f),
-
-	mOrbitLeftKey(0.f),
-	mOrbitRightKey(0.f),
-	mOrbitUpKey(0.f),
-	mOrbitDownKey(0.f),
-	mOrbitInKey(0.f),
-	mOrbitOutKey(0.f),
-
-	mPanUpKey(0.f),
-	mPanDownKey(0.f),
-	mPanLeftKey(0.f),
-	mPanRightKey(0.f),
-	mPanInKey(0.f),
-	mPanOutKey(0.f),
-	mRollLeftKey(0.f),
-	mRollRightKey(0.f)
-{
-	mFollowCam.setMaxCameraDistantFromSubject( MAX_CAMERA_DISTANCE_FROM_AGENT );
-
-	clearGeneralKeys();
-	clearOrbitKeys();
-	clearPanKeys();
-
-	resetPanDiff();
-	resetOrbitDiff();
-	resetCameraRoll();
+    mInitialized(false),
+
+    mDrawDistance( DEFAULT_FAR_PLANE ),
+
+    mLookAt(NULL),
+    mPointAt(NULL),
+
+    mHUDTargetZoom(1.f),
+    mHUDCurZoom(1.f),
+
+    mForceMouselook(FALSE),
+
+    mCameraMode( CAMERA_MODE_THIRD_PERSON ),
+    mLastCameraMode( CAMERA_MODE_THIRD_PERSON ),
+
+    mCameraPreset(CAMERA_PRESET_REAR_VIEW),
+
+    mCameraAnimating( FALSE ),
+    mAnimationCameraStartGlobal(),
+    mAnimationFocusStartGlobal(),
+    mAnimationTimer(),
+    mAnimationDuration(0.33f),
+
+    mCameraFOVZoomFactor(0.f),
+    mCameraCurrentFOVZoomFactor(0.f),
+    mCameraFocusOffset(),
+
+    mCameraCollidePlane(),
+
+    mCurrentCameraDistance(2.f),        // meters, set in init()
+    mTargetCameraDistance(2.f),
+    mCameraZoomFraction(1.f),           // deprecated
+    mThirdPersonHeadOffset(0.f, 0.f, 1.f),
+    mSitCameraEnabled(FALSE),
+    mCameraSmoothingLastPositionGlobal(),
+    mCameraSmoothingLastPositionAgent(),
+    mCameraSmoothingStop(false),
+
+    mCameraUpVector(LLVector3::z_axis), // default is straight up
+
+    mFocusOnAvatar(TRUE),
+    mAllowChangeToFollow(FALSE),
+    mFocusGlobal(),
+    mFocusTargetGlobal(),
+    mFocusObject(NULL),
+    mFocusObjectDist(0.f),
+    mFocusObjectOffset(),
+    mTrackFocusObject(TRUE),
+
+    mAtKey(0), // Either 1, 0, or -1... indicates that movement-key is pressed
+    mWalkKey(0), // like AtKey, but causes less forward thrust
+    mLeftKey(0),
+    mUpKey(0),
+    mYawKey(0.f),
+    mPitchKey(0.f),
+
+    mOrbitLeftKey(0.f),
+    mOrbitRightKey(0.f),
+    mOrbitUpKey(0.f),
+    mOrbitDownKey(0.f),
+    mOrbitInKey(0.f),
+    mOrbitOutKey(0.f),
+
+    mPanUpKey(0.f),
+    mPanDownKey(0.f),
+    mPanLeftKey(0.f),
+    mPanRightKey(0.f),
+    mPanInKey(0.f),
+    mPanOutKey(0.f),
+    mRollLeftKey(0.f),
+    mRollRightKey(0.f)
+{
+    mFollowCam.setMaxCameraDistantFromSubject( MAX_CAMERA_DISTANCE_FROM_AGENT );
+
+    clearGeneralKeys();
+    clearOrbitKeys();
+    clearPanKeys();
+
+    resetPanDiff();
+    resetOrbitDiff();
+    resetCameraRoll();
 }
 
 // Requires gSavedSettings to be initialized.
@@ -210,28 +210,28 @@ LLAgentCamera::LLAgentCamera() :
 //-----------------------------------------------------------------------------
 void LLAgentCamera::init()
 {
-	// *Note: this is where LLViewerCamera::getInstance() used to be constructed.
+    // *Note: this is where LLViewerCamera::getInstance() used to be constructed.
 
-	mDrawDistance = gSavedSettings.getF32("RenderFarClip");
+    mDrawDistance = gSavedSettings.getF32("RenderFarClip");
 
-	LLViewerCamera::getInstance()->setView(DEFAULT_FIELD_OF_VIEW);
-	// Leave at 0.1 meters until we have real near clip management
-	LLViewerCamera::getInstance()->setNear(0.1f);
-	LLViewerCamera::getInstance()->setFar(mDrawDistance);			// if you want to change camera settings, do so in camera.h
-	LLViewerCamera::getInstance()->setAspect( gViewerWindow->getWorldViewAspectRatio() );		// default, overridden in LLViewerWindow::reshape
-	LLViewerCamera::getInstance()->setViewHeightInPixels(768);			// default, overridden in LLViewerWindow::reshape
+    LLViewerCamera::getInstance()->setView(DEFAULT_FIELD_OF_VIEW);
+    // Leave at 0.1 meters until we have real near clip management
+    LLViewerCamera::getInstance()->setNear(0.1f);
+    LLViewerCamera::getInstance()->setFar(mDrawDistance);           // if you want to change camera settings, do so in camera.h
+    LLViewerCamera::getInstance()->setAspect( gViewerWindow->getWorldViewAspectRatio() );       // default, overridden in LLViewerWindow::reshape
+    LLViewerCamera::getInstance()->setViewHeightInPixels(768);          // default, overridden in LLViewerWindow::reshape
 
-	mCameraFocusOffsetTarget = LLVector4(gSavedSettings.getVector3("CameraOffsetBuild"));
-	
-	mCameraPreset = (ECameraPreset) gSavedSettings.getU32("CameraPresetType");
+    mCameraFocusOffsetTarget = LLVector4(gSavedSettings.getVector3("CameraOffsetBuild"));
 
-	mCameraCollidePlane.clearVec();
-	mCurrentCameraDistance = getCameraOffsetInitial().magVec() * gSavedSettings.getF32("CameraOffsetScale");
-	mTargetCameraDistance = mCurrentCameraDistance;
-	mCameraZoomFraction = 1.f;
-	mTrackFocusObject = gSavedSettings.getBOOL("TrackFocusObject");
+    mCameraPreset = (ECameraPreset) gSavedSettings.getU32("CameraPresetType");
 
-	mInitialized = true;
+    mCameraCollidePlane.clearVec();
+    mCurrentCameraDistance = getCameraOffsetInitial().magVec() * gSavedSettings.getF32("CameraOffsetScale");
+    mTargetCameraDistance = mCurrentCameraDistance;
+    mCameraZoomFraction = 1.f;
+    mTrackFocusObject = gSavedSettings.getBOOL("TrackFocusObject");
+
+    mInitialized = true;
 }
 
 //-----------------------------------------------------------------------------
@@ -239,40 +239,40 @@ void LLAgentCamera::init()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::cleanup()
 {
-	setSitCamera(LLUUID::null);
+    setSitCamera(LLUUID::null);
 
-	if(mLookAt)
-	{
-		mLookAt->markDead() ;
-		mLookAt = NULL;
-	}
-	if(mPointAt)
-	{
-		mPointAt->markDead() ;
-		mPointAt = NULL;
-	}
-	setFocusObject(NULL);
+    if(mLookAt)
+    {
+        mLookAt->markDead() ;
+        mLookAt = NULL;
+    }
+    if(mPointAt)
+    {
+        mPointAt->markDead() ;
+        mPointAt = NULL;
+    }
+    setFocusObject(NULL);
 }
 
 void LLAgentCamera::setAvatarObject(LLVOAvatarSelf* avatar)
 {
-	if (!mLookAt)
-	{
-		mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT);
-	}
-	if (!mPointAt)
-	{
-		mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT);
-	}
-	
-	if (!mLookAt.isNull())
-	{
-		mLookAt->setSourceObject(avatar);
-	}
-	if (!mPointAt.isNull())
-	{
-		mPointAt->setSourceObject(avatar);
-	}	
+    if (!mLookAt)
+    {
+        mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT);
+    }
+    if (!mPointAt)
+    {
+        mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT);
+    }
+
+    if (!mLookAt.isNull())
+    {
+        mLookAt->setSourceObject(avatar);
+    }
+    if (!mPointAt.isNull())
+    {
+        mPointAt->setSourceObject(avatar);
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -280,9 +280,9 @@ void LLAgentCamera::setAvatarObject(LLVOAvatarSelf* avatar)
 //-----------------------------------------------------------------------------
 LLAgentCamera::~LLAgentCamera()
 {
-	cleanup();
+    cleanup();
 
-	// *Note: this is where LLViewerCamera::getInstance() used to be deleted.
+    // *Note: this is where LLViewerCamera::getInstance() used to be deleted.
 }
 
 // Change camera back to third person, stop the autopilot,
@@ -292,84 +292,84 @@ LLAgentCamera::~LLAgentCamera()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::resetView(BOOL reset_camera, BOOL change_camera)
 {
-	if (gDisconnected)
-	{
-		return;
-	}
-
-	if (gAgent.getAutoPilot())
-	{
-		gAgent.stopAutoPilot(TRUE);
-	}
-
-	LLSelectMgr::getInstance()->unhighlightAll();
-
-	// By popular request, keep land selection while walking around. JC
-	// LLViewerParcelMgr::getInstance()->deselectLand();
-
-	// force deselect when walking and attachment is selected
-	// this is so people don't wig out when their avatar moves without animating
-	if (LLSelectMgr::getInstance()->getSelection()->isAttachment())
-	{
-		LLSelectMgr::getInstance()->deselectAll();
-	}
-
-	if (gMenuHolder != NULL)
-	{
-		// Hide all popup menus
-		gMenuHolder->hideMenus();
-	}
-
-	if (change_camera && !LLPipeline::FreezeTime)
-	{
-		changeCameraToDefault();
-		
-		if (LLViewerJoystick::getInstance()->getOverrideCamera())
-		{
-			handle_toggle_flycam();
-		}
-
-		// reset avatar mode from eventual residual motion
-		if (LLToolMgr::getInstance()->inBuildMode())
-		{
-			LLViewerJoystick::getInstance()->moveAvatar(true);
-		}
-
-		//Camera Tool is needed for Free Camera Control Mode
-		if (!LLFloaterCamera::inFreeCameraMode())
-		{
-			
-			if (LLFloaterReg::instanceVisible("build"))
-				LLFloaterReg::hideInstance("build");
-
-			// Switch back to basic toolset
-			LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
-		}
-		
-		gViewerWindow->showCursor();
-	}
-
-
-	if (reset_camera && !LLPipeline::FreezeTime)
-	{
-		if (!gViewerWindow->getLeftMouseDown() && cameraThirdPerson())
-		{
-			// leaving mouse-steer mode
-			LLVector3 agent_at_axis = gAgent.getAtAxis();
-			agent_at_axis -= projected_vec(agent_at_axis, gAgent.getReferenceUpVector());
-			agent_at_axis.normalize();
-			gAgent.resetAxes(lerp(gAgent.getAtAxis(), agent_at_axis, LLSmoothInterpolation::getInterpolant(0.3f)));
-		}
-
-		setFocusOnAvatar(TRUE, ANIMATE);
-
-		mCameraFOVZoomFactor = 0.f;
-
-		resetCameraRoll();
-	}
-	resetPanDiff();
-	resetOrbitDiff();
-	mHUDTargetZoom = 1.f;
+    if (gDisconnected)
+    {
+        return;
+    }
+
+    if (gAgent.getAutoPilot())
+    {
+        gAgent.stopAutoPilot(TRUE);
+    }
+
+    LLSelectMgr::getInstance()->unhighlightAll();
+
+    // By popular request, keep land selection while walking around. JC
+    // LLViewerParcelMgr::getInstance()->deselectLand();
+
+    // force deselect when walking and attachment is selected
+    // this is so people don't wig out when their avatar moves without animating
+    if (LLSelectMgr::getInstance()->getSelection()->isAttachment())
+    {
+        LLSelectMgr::getInstance()->deselectAll();
+    }
+
+    if (gMenuHolder != NULL)
+    {
+        // Hide all popup menus
+        gMenuHolder->hideMenus();
+    }
+
+    if (change_camera && !LLPipeline::FreezeTime)
+    {
+        changeCameraToDefault();
+
+        if (LLViewerJoystick::getInstance()->getOverrideCamera())
+        {
+            handle_toggle_flycam();
+        }
+
+        // reset avatar mode from eventual residual motion
+        if (LLToolMgr::getInstance()->inBuildMode())
+        {
+            LLViewerJoystick::getInstance()->moveAvatar(true);
+        }
+
+        //Camera Tool is needed for Free Camera Control Mode
+        if (!LLFloaterCamera::inFreeCameraMode())
+        {
+
+            if (LLFloaterReg::instanceVisible("build"))
+                LLFloaterReg::hideInstance("build");
+
+            // Switch back to basic toolset
+            LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
+        }
+
+        gViewerWindow->showCursor();
+    }
+
+
+    if (reset_camera && !LLPipeline::FreezeTime)
+    {
+        if (!gViewerWindow->getLeftMouseDown() && cameraThirdPerson())
+        {
+            // leaving mouse-steer mode
+            LLVector3 agent_at_axis = gAgent.getAtAxis();
+            agent_at_axis -= projected_vec(agent_at_axis, gAgent.getReferenceUpVector());
+            agent_at_axis.normalize();
+            gAgent.resetAxes(lerp(gAgent.getAtAxis(), agent_at_axis, LLSmoothInterpolation::getInterpolant(0.3f)));
+        }
+
+        setFocusOnAvatar(TRUE, ANIMATE);
+
+        mCameraFOVZoomFactor = 0.f;
+
+        resetCameraRoll();
+    }
+    resetPanDiff();
+    resetOrbitDiff();
+    mHUDTargetZoom = 1.f;
 
     if (LLSelectMgr::getInstance()->mAllowSelectAvatar)
     {
@@ -390,14 +390,14 @@ void LLAgentCamera::resetView(BOOL reset_camera, BOOL change_camera)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::unlockView()
 {
-	if (getFocusOnAvatar())
-	{
-		if (isAgentAvatarValid())
-		{
-			setFocusGlobal(LLVector3d::zero, gAgentAvatarp->mID);
-		}
-		setFocusOnAvatar(FALSE, FALSE);	// no animation
-	}
+    if (getFocusOnAvatar())
+    {
+        if (isAgentAvatarValid())
+        {
+            setFocusGlobal(LLVector3d::zero, gAgentAvatarp->mID);
+        }
+        setFocusOnAvatar(FALSE, FALSE); // no animation
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -405,10 +405,10 @@ void LLAgentCamera::unlockView()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::slamLookAt(const LLVector3 &look_at)
 {
-	LLVector3 look_at_norm = look_at;
-	look_at_norm.mV[VZ] = 0.f;
-	look_at_norm.normalize();
-	gAgent.resetAxes(look_at_norm);
+    LLVector3 look_at_norm = look_at;
+    look_at_norm.mV[VZ] = 0.f;
+    look_at_norm.normalize();
+    gAgent.resetAxes(look_at_norm);
 }
 
 //-----------------------------------------------------------------------------
@@ -416,174 +416,174 @@ void LLAgentCamera::slamLookAt(const LLVector3 &look_at)
 //-----------------------------------------------------------------------------
 LLVector3 LLAgentCamera::calcFocusOffset(LLViewerObject *object, LLVector3 original_focus_point, S32 x, S32 y)
 {
-	const LLMatrix4a& obj_matrix = object->getRenderMatrix();
-	const LLQuaternion obj_rot = object->getRenderRotation();
-	const LLVector3 obj_pos = object->getRenderPosition();
+    const LLMatrix4a& obj_matrix = object->getRenderMatrix();
+    const LLQuaternion obj_rot = object->getRenderRotation();
+    const LLVector3 obj_pos = object->getRenderPosition();
 
-	// if is avatar - don't do any funk heuristics to position the focal point
-	// see DEV-30589
-	if ((object->isAvatar() && !object->isRoot()) || (object->isAnimatedObject() && object->getControlAvatar()))
-	{
-		return original_focus_point - obj_pos;
-	}
+    // if is avatar - don't do any funk heuristics to position the focal point
+    // see DEV-30589
+    if ((object->isAvatar() && !object->isRoot()) || (object->isAnimatedObject() && object->getControlAvatar()))
+    {
+        return original_focus_point - obj_pos;
+    }
     if (object->isAvatar())
     {
         LLVOAvatar* av = object->asAvatar();
         return original_focus_point - av->getCharacterPosition();
     }
-	
-	LLQuaternion inv_obj_rot = ~obj_rot; // get inverse of rotation
-	LLVector3 object_extents = object->getScale();	
-	
-	// make sure they object extents are non-zero
-	object_extents.clamp(0.001f, F32_MAX);
-
-	auto& viewerCamera = LLViewerCamera::instance();
-	const auto& viewer_camera_origin = viewerCamera.getOrigin();
-
-	// obj_to_cam_ray is unit vector pointing from object center to camera, in the coordinate frame of the object
-	LLVector3 obj_to_cam_ray = obj_pos - viewer_camera_origin;
-	obj_to_cam_ray.rotVec(inv_obj_rot);
-	obj_to_cam_ray.normalize();
-
-	// obj_to_cam_ray_proportions are the (positive) ratios of 
-	// the obj_to_cam_ray x,y,z components with the x,y,z object dimensions.
-	LLVector3 obj_to_cam_ray_proportions;
-	obj_to_cam_ray_proportions.mV[VX] = llabs(obj_to_cam_ray.mV[VX] / object_extents.mV[VX]);
-	obj_to_cam_ray_proportions.mV[VY] = llabs(obj_to_cam_ray.mV[VY] / object_extents.mV[VY]);
-	obj_to_cam_ray_proportions.mV[VZ] = llabs(obj_to_cam_ray.mV[VZ] / object_extents.mV[VZ]);
-
-	// find the largest ratio stored in obj_to_cam_ray_proportions
-	// this corresponds to the object's local axial plane (XY, YZ, XZ) that is *most* facing the camera
-	LLVector4a focus_plane_normal;
-	// is x-axis longest?
-	if (obj_to_cam_ray_proportions.mV[VX] > obj_to_cam_ray_proportions.mV[VY] 
-		&& obj_to_cam_ray_proportions.mV[VX] > obj_to_cam_ray_proportions.mV[VZ])
-	{
-		// then grab it
-		focus_plane_normal = obj_matrix.getRow<LLMatrix4a::ROW_FWD>();
-	}
-	// is y-axis longest?
-	else if (obj_to_cam_ray_proportions.mV[VY] > obj_to_cam_ray_proportions.mV[VZ])
-	{
-		// then grab it
-		focus_plane_normal = obj_matrix.getRow<LLMatrix4a::ROW_LEFT>();
-	}
-	// otherwise, use z axis
-	else
-	{
-		focus_plane_normal = obj_matrix.getRow<LLMatrix4a::ROW_UP>();
-	}
-
-	// Use this axis as the normal to project mouse click on to plane with that normal, at the object center.
-	// This generates a point behind the mouse cursor that is approximately in the middle of the object in
-	// terms of depth.  
-	// We do this to allow the camera rotation tool to "tumble" the object by rotating the camera.
-	// If the focus point were the object surface under the mouse, camera rotation would introduce an undesirable
-	// eccentricity to the object orientation
-	focus_plane_normal.normalize3fast();
-
-	LLVector3d focus_pt_global;
-	gViewerWindow->mousePointOnPlaneGlobal(focus_pt_global, x, y, gAgent.getPosGlobalFromAgent(obj_pos), LLVector3(focus_plane_normal.getF32ptr()));
-	LLVector3 focus_pt = gAgent.getPosAgentFromGlobal(focus_pt_global);
-
-	// find vector from camera to focus point in object space
-	LLVector3 camera_to_focus_vec = focus_pt - viewer_camera_origin;
-	camera_to_focus_vec.rotVec(inv_obj_rot);
-
-	// find vector from object origin to focus point in object coordinates
-	LLVector3 focus_offset_from_object_center = focus_pt - obj_pos;
-	// convert to object-local space
-	focus_offset_from_object_center.rotVec(inv_obj_rot);
-
-	// We need to project the focus point back into the bounding box of the focused object.
-	// Do this by calculating the XYZ scale factors needed to get focus offset back in bounds along the camera_focus axis
-	LLVector3 clip_fraction;
-
-	// for each axis...
-	for (U32 axis = VX; axis <= VZ; axis++)
-	{
-		//...calculate distance that focus offset sits outside of bounding box along that axis...
-		//NOTE: dist_out_of_bounds keeps the sign of focus_offset_from_object_center 
-		F32 dist_out_of_bounds;
-		if (focus_offset_from_object_center.mV[axis] > 0.f)
-		{
-			dist_out_of_bounds = llmax(0.f, focus_offset_from_object_center.mV[axis] - (object_extents.mV[axis] * 0.5f));
-		}
-		else
-		{
-			dist_out_of_bounds = llmin(0.f, focus_offset_from_object_center.mV[axis] + (object_extents.mV[axis] * 0.5f));
-		}
-
-		//...then calculate the scale factor needed to push camera_to_focus_vec back in bounds along current axis
-		if (llabs(camera_to_focus_vec.mV[axis]) < 0.0001f)
-		{
-			// don't divide by very small number
-			clip_fraction.mV[axis] = 0.f;
-		}
-		else
-		{
-			clip_fraction.mV[axis] = dist_out_of_bounds / camera_to_focus_vec.mV[axis];
-		}
-	}
-
-	LLVector3 abs_clip_fraction = clip_fraction;
-	abs_clip_fraction.abs();
-
-	// find axis of focus offset that is *most* outside the bounding box and use that to
-	// rescale focus offset to inside object extents
-	if (abs_clip_fraction.mV[VX] > abs_clip_fraction.mV[VY]
-		&& abs_clip_fraction.mV[VX] > abs_clip_fraction.mV[VZ])
-	{
-		focus_offset_from_object_center -= clip_fraction.mV[VX] * camera_to_focus_vec;
-	}
-	else if (abs_clip_fraction.mV[VY] > abs_clip_fraction.mV[VZ])
-	{
-		focus_offset_from_object_center -= clip_fraction.mV[VY] * camera_to_focus_vec;
-	}
-	else
-	{
-		focus_offset_from_object_center -= clip_fraction.mV[VZ] * camera_to_focus_vec;
-	}
-
-	// convert back to world space
-	focus_offset_from_object_center.rotVec(obj_rot);
-	
-	// now, based on distance of camera from object relative to object size
-	// push the focus point towards the near surface of the object when (relatively) close to the objcet
-	// or keep the focus point in the object middle when (relatively) far
-	// NOTE: leave focus point in middle of avatars, since the behavior you want when alt-zooming on avatars
-	// is almost always "tumble about middle" and not "spin around surface point"
-	{
-		LLVector3 obj_rel = original_focus_point - obj_pos;
-		
-		//now that we have the object relative position, we should bias toward the center of the object 
-		//based on the distance of the camera to the focus point vs. the distance of the camera to the focus
-
-		F32 relDist = llabs(obj_rel * viewerCamera.getAtAxis());
-		F32 viewDist = dist_vec(obj_pos + obj_rel, viewer_camera_origin);
-
-
-		LLBBox obj_bbox = object->getBoundingBoxAgent();
-		F32 bias = 0.f;
-
-		// virtual_camera_pos is the camera position we are simulating by backing the camera off
-		// and adjusting the FOV
-		LLVector3 virtual_camera_pos = gAgent.getPosAgentFromGlobal(mFocusTargetGlobal + (getCameraPositionGlobal() - mFocusTargetGlobal) / (1.f + mCameraFOVZoomFactor));
-
-		// if the camera is inside the object (large, hollow objects, for example)
-		// leave focus point all the way to destination depth, away from object center
-		if(!obj_bbox.containsPointAgent(virtual_camera_pos))
-		{
-			// perform magic number biasing of focus point towards surface vs. planar center
-			bias = clamp_rescale(relDist/viewDist, 0.1f, 0.7f, 0.0f, 1.0f);
-			obj_rel = lerp(focus_offset_from_object_center, obj_rel, bias);
-		}
-			
-		focus_offset_from_object_center = obj_rel;
-	}
-
-	return focus_offset_from_object_center;
+
+    LLQuaternion inv_obj_rot = ~obj_rot; // get inverse of rotation
+    LLVector3 object_extents = object->getScale();
+
+    // make sure they object extents are non-zero
+    object_extents.clamp(0.001f, F32_MAX);
+
+    auto& viewerCamera = LLViewerCamera::instance();
+    const auto& viewer_camera_origin = viewerCamera.getOrigin();
+
+    // obj_to_cam_ray is unit vector pointing from object center to camera, in the coordinate frame of the object
+    LLVector3 obj_to_cam_ray = obj_pos - viewer_camera_origin;
+    obj_to_cam_ray.rotVec(inv_obj_rot);
+    obj_to_cam_ray.normalize();
+
+    // obj_to_cam_ray_proportions are the (positive) ratios of
+    // the obj_to_cam_ray x,y,z components with the x,y,z object dimensions.
+    LLVector3 obj_to_cam_ray_proportions;
+    obj_to_cam_ray_proportions.mV[VX] = llabs(obj_to_cam_ray.mV[VX] / object_extents.mV[VX]);
+    obj_to_cam_ray_proportions.mV[VY] = llabs(obj_to_cam_ray.mV[VY] / object_extents.mV[VY]);
+    obj_to_cam_ray_proportions.mV[VZ] = llabs(obj_to_cam_ray.mV[VZ] / object_extents.mV[VZ]);
+
+    // find the largest ratio stored in obj_to_cam_ray_proportions
+    // this corresponds to the object's local axial plane (XY, YZ, XZ) that is *most* facing the camera
+    LLVector4a focus_plane_normal;
+    // is x-axis longest?
+    if (obj_to_cam_ray_proportions.mV[VX] > obj_to_cam_ray_proportions.mV[VY]
+        && obj_to_cam_ray_proportions.mV[VX] > obj_to_cam_ray_proportions.mV[VZ])
+    {
+        // then grab it
+        focus_plane_normal = obj_matrix.getRow<LLMatrix4a::ROW_FWD>();
+    }
+    // is y-axis longest?
+    else if (obj_to_cam_ray_proportions.mV[VY] > obj_to_cam_ray_proportions.mV[VZ])
+    {
+        // then grab it
+        focus_plane_normal = obj_matrix.getRow<LLMatrix4a::ROW_LEFT>();
+    }
+    // otherwise, use z axis
+    else
+    {
+        focus_plane_normal = obj_matrix.getRow<LLMatrix4a::ROW_UP>();
+    }
+
+    // Use this axis as the normal to project mouse click on to plane with that normal, at the object center.
+    // This generates a point behind the mouse cursor that is approximately in the middle of the object in
+    // terms of depth.
+    // We do this to allow the camera rotation tool to "tumble" the object by rotating the camera.
+    // If the focus point were the object surface under the mouse, camera rotation would introduce an undesirable
+    // eccentricity to the object orientation
+    focus_plane_normal.normalize3fast();
+
+    LLVector3d focus_pt_global;
+    gViewerWindow->mousePointOnPlaneGlobal(focus_pt_global, x, y, gAgent.getPosGlobalFromAgent(obj_pos), LLVector3(focus_plane_normal.getF32ptr()));
+    LLVector3 focus_pt = gAgent.getPosAgentFromGlobal(focus_pt_global);
+
+    // find vector from camera to focus point in object space
+    LLVector3 camera_to_focus_vec = focus_pt - viewer_camera_origin;
+    camera_to_focus_vec.rotVec(inv_obj_rot);
+
+    // find vector from object origin to focus point in object coordinates
+    LLVector3 focus_offset_from_object_center = focus_pt - obj_pos;
+    // convert to object-local space
+    focus_offset_from_object_center.rotVec(inv_obj_rot);
+
+    // We need to project the focus point back into the bounding box of the focused object.
+    // Do this by calculating the XYZ scale factors needed to get focus offset back in bounds along the camera_focus axis
+    LLVector3 clip_fraction;
+
+    // for each axis...
+    for (U32 axis = VX; axis <= VZ; axis++)
+    {
+        //...calculate distance that focus offset sits outside of bounding box along that axis...
+        //NOTE: dist_out_of_bounds keeps the sign of focus_offset_from_object_center
+        F32 dist_out_of_bounds;
+        if (focus_offset_from_object_center.mV[axis] > 0.f)
+        {
+            dist_out_of_bounds = llmax(0.f, focus_offset_from_object_center.mV[axis] - (object_extents.mV[axis] * 0.5f));
+        }
+        else
+        {
+            dist_out_of_bounds = llmin(0.f, focus_offset_from_object_center.mV[axis] + (object_extents.mV[axis] * 0.5f));
+        }
+
+        //...then calculate the scale factor needed to push camera_to_focus_vec back in bounds along current axis
+        if (llabs(camera_to_focus_vec.mV[axis]) < 0.0001f)
+        {
+            // don't divide by very small number
+            clip_fraction.mV[axis] = 0.f;
+        }
+        else
+        {
+            clip_fraction.mV[axis] = dist_out_of_bounds / camera_to_focus_vec.mV[axis];
+        }
+    }
+
+    LLVector3 abs_clip_fraction = clip_fraction;
+    abs_clip_fraction.abs();
+
+    // find axis of focus offset that is *most* outside the bounding box and use that to
+    // rescale focus offset to inside object extents
+    if (abs_clip_fraction.mV[VX] > abs_clip_fraction.mV[VY]
+        && abs_clip_fraction.mV[VX] > abs_clip_fraction.mV[VZ])
+    {
+        focus_offset_from_object_center -= clip_fraction.mV[VX] * camera_to_focus_vec;
+    }
+    else if (abs_clip_fraction.mV[VY] > abs_clip_fraction.mV[VZ])
+    {
+        focus_offset_from_object_center -= clip_fraction.mV[VY] * camera_to_focus_vec;
+    }
+    else
+    {
+        focus_offset_from_object_center -= clip_fraction.mV[VZ] * camera_to_focus_vec;
+    }
+
+    // convert back to world space
+    focus_offset_from_object_center.rotVec(obj_rot);
+
+    // now, based on distance of camera from object relative to object size
+    // push the focus point towards the near surface of the object when (relatively) close to the objcet
+    // or keep the focus point in the object middle when (relatively) far
+    // NOTE: leave focus point in middle of avatars, since the behavior you want when alt-zooming on avatars
+    // is almost always "tumble about middle" and not "spin around surface point"
+    {
+        LLVector3 obj_rel = original_focus_point - obj_pos;
+
+        //now that we have the object relative position, we should bias toward the center of the object
+        //based on the distance of the camera to the focus point vs. the distance of the camera to the focus
+
+        F32 relDist = llabs(obj_rel * viewerCamera.getAtAxis());
+        F32 viewDist = dist_vec(obj_pos + obj_rel, viewer_camera_origin);
+
+
+        LLBBox obj_bbox = object->getBoundingBoxAgent();
+        F32 bias = 0.f;
+
+        // virtual_camera_pos is the camera position we are simulating by backing the camera off
+        // and adjusting the FOV
+        LLVector3 virtual_camera_pos = gAgent.getPosAgentFromGlobal(mFocusTargetGlobal + (getCameraPositionGlobal() - mFocusTargetGlobal) / (1.f + mCameraFOVZoomFactor));
+
+        // if the camera is inside the object (large, hollow objects, for example)
+        // leave focus point all the way to destination depth, away from object center
+        if(!obj_bbox.containsPointAgent(virtual_camera_pos))
+        {
+            // perform magic number biasing of focus point towards surface vs. planar center
+            bias = clamp_rescale(relDist/viewDist, 0.1f, 0.7f, 0.0f, 1.0f);
+            obj_rel = lerp(focus_offset_from_object_center, obj_rel, bias);
+        }
+
+        focus_offset_from_object_center = obj_rel;
+    }
+
+    return focus_offset_from_object_center;
 }
 
 //-----------------------------------------------------------------------------
@@ -591,250 +591,250 @@ LLVector3 LLAgentCamera::calcFocusOffset(LLViewerObject *object, LLVector3 origi
 //-----------------------------------------------------------------------------
 BOOL LLAgentCamera::calcCameraMinDistance(F32 &obj_min_distance)
 {
-	BOOL soft_limit = FALSE; // is the bounding box to be treated literally (volumes) or as an approximation (avatars)
+    BOOL soft_limit = FALSE; // is the bounding box to be treated literally (volumes) or as an approximation (avatars)
 
-	if (!mFocusObject || mFocusObject->isDead() ||
-		mFocusObject->isMesh() ||
-		isDisableCameraConstraints())
-	{
-		obj_min_distance = 0.f;
-		return TRUE;
-	}
+    if (!mFocusObject || mFocusObject->isDead() ||
+        mFocusObject->isMesh() ||
+        isDisableCameraConstraints())
+    {
+        obj_min_distance = 0.f;
+        return TRUE;
+    }
 
-	if (mFocusObject->mDrawable.isNull())
-	{
+    if (mFocusObject->mDrawable.isNull())
+    {
 #ifdef LL_RELEASE_FOR_DOWNLOAD
-		LL_WARNS() << "Focus object with no drawable!" << LL_ENDL;
+        LL_WARNS() << "Focus object with no drawable!" << LL_ENDL;
 #else
-		mFocusObject->dump();
-		LL_ERRS() << "Focus object with no drawable!" << LL_ENDL;
+        mFocusObject->dump();
+        LL_ERRS() << "Focus object with no drawable!" << LL_ENDL;
 #endif
-		obj_min_distance = 0.f;
-		return TRUE;
-	}
-	
-	LLQuaternion inv_object_rot = ~mFocusObject->getRenderRotation();
-	LLVector3 target_offset_origin = mFocusObjectOffset;
-	LLVector3 camera_offset_target(getCameraPositionAgent() - gAgent.getPosAgentFromGlobal(mFocusTargetGlobal));
-
-	// convert offsets into object local space
-	camera_offset_target.rotVec(inv_object_rot);
-	target_offset_origin.rotVec(inv_object_rot);
-
-	// push around object extents based on target offset
-	LLVector3 object_extents = mFocusObject->getScale();
-	if (mFocusObject->isAvatar())
-	{
-		// fudge factors that lets you zoom in on avatars a bit more (which don't do FOV zoom)
-		object_extents.mV[VX] *= AVATAR_ZOOM_MIN_X_FACTOR;
-		object_extents.mV[VY] *= AVATAR_ZOOM_MIN_Y_FACTOR;
-		object_extents.mV[VZ] *= AVATAR_ZOOM_MIN_Z_FACTOR;
-		soft_limit = TRUE;
-	}
-	LLVector3 abs_target_offset = target_offset_origin;
-	abs_target_offset.abs();
-
-	LLVector3 target_offset_dir = target_offset_origin;
-
-	BOOL target_outside_object_extents = FALSE;
-
-	for (U32 i = VX; i <= VZ; i++)
-	{
-		if (abs_target_offset.mV[i] * 2.f > object_extents.mV[i] + OBJECT_EXTENTS_PADDING)
-		{
-			target_outside_object_extents = TRUE;
-		}
-		if (camera_offset_target.mV[i] > 0.f)
-		{
-			object_extents.mV[i] -= target_offset_origin.mV[i] * 2.f;
-		}
-		else
-		{
-			object_extents.mV[i] += target_offset_origin.mV[i] * 2.f;
-		}
-	}
-
-	// don't shrink the object extents so far that the object inverts
-	object_extents.clamp(0.001f, F32_MAX);
-
-	// move into first octant
-	LLVector3 camera_offset_target_abs_norm = camera_offset_target;
-	camera_offset_target_abs_norm.abs();
-	// make sure offset is non-zero
-	camera_offset_target_abs_norm.clamp(0.001f, F32_MAX);
-	camera_offset_target_abs_norm.normalize();
-
-	// find camera position relative to normalized object extents
-	LLVector3 camera_offset_target_scaled = camera_offset_target_abs_norm;
-	camera_offset_target_scaled.mV[VX] /= object_extents.mV[VX];
-	camera_offset_target_scaled.mV[VY] /= object_extents.mV[VY];
-	camera_offset_target_scaled.mV[VZ] /= object_extents.mV[VZ];
-
-	if (camera_offset_target_scaled.mV[VX] > camera_offset_target_scaled.mV[VY] && 
-		camera_offset_target_scaled.mV[VX] > camera_offset_target_scaled.mV[VZ])
-	{
-		if (camera_offset_target_abs_norm.mV[VX] < 0.001f)
-		{
-			obj_min_distance = object_extents.mV[VX] * 0.5f;
-		}
-		else
-		{
-			obj_min_distance = object_extents.mV[VX] * 0.5f / camera_offset_target_abs_norm.mV[VX];
-		}
-	}
-	else if (camera_offset_target_scaled.mV[VY] > camera_offset_target_scaled.mV[VZ])
-	{
-		if (camera_offset_target_abs_norm.mV[VY] < 0.001f)
-		{
-			obj_min_distance = object_extents.mV[VY] * 0.5f;
-		}
-		else
-		{
-			obj_min_distance = object_extents.mV[VY] * 0.5f / camera_offset_target_abs_norm.mV[VY];
-		}
-	}
-	else
-	{
-		if (camera_offset_target_abs_norm.mV[VZ] < 0.001f)
-		{
-			obj_min_distance = object_extents.mV[VZ] * 0.5f;
-		}
-		else
-		{
-			obj_min_distance = object_extents.mV[VZ] * 0.5f / camera_offset_target_abs_norm.mV[VZ];
-		}
-	}
-
-	LLVector3 object_split_axis;
-	LLVector3 target_offset_scaled = target_offset_origin;
-	target_offset_scaled.abs();
-	target_offset_scaled.normalize();
-	target_offset_scaled.mV[VX] /= object_extents.mV[VX];
-	target_offset_scaled.mV[VY] /= object_extents.mV[VY];
-	target_offset_scaled.mV[VZ] /= object_extents.mV[VZ];
-
-	if (target_offset_scaled.mV[VX] > target_offset_scaled.mV[VY] && 
-		target_offset_scaled.mV[VX] > target_offset_scaled.mV[VZ])
-	{
-		object_split_axis = LLVector3::x_axis;
-	}
-	else if (target_offset_scaled.mV[VY] > target_offset_scaled.mV[VZ])
-	{
-		object_split_axis = LLVector3::y_axis;
-	}
-	else
-	{
-		object_split_axis = LLVector3::z_axis;
-	}
-
-	LLVector3 camera_offset_object(getCameraPositionAgent() - mFocusObject->getPositionAgent());
-
-
-	F32 camera_offset_clip = camera_offset_object * object_split_axis;
-	F32 target_offset_clip = target_offset_dir * object_split_axis;
-
-	// target has moved outside of object extents
-	// check to see if camera and target are on same side 
-	if (target_outside_object_extents)
-	{
-		if (camera_offset_clip > 0.f && target_offset_clip > 0.f)
-		{
-			return FALSE;
-		}
-		else if (camera_offset_clip < 0.f && target_offset_clip < 0.f)
-		{
-			return FALSE;
-		}
-	}
-
-	// clamp obj distance to diagonal of 10 by 10 cube
-	obj_min_distance = llmin(obj_min_distance, 10.f * F_SQRT3);
-
-	obj_min_distance += LLViewerCamera::getInstance()->getNear() + (soft_limit ? 0.1f : 0.2f);
-	
-	return TRUE;
+        obj_min_distance = 0.f;
+        return TRUE;
+    }
+
+    LLQuaternion inv_object_rot = ~mFocusObject->getRenderRotation();
+    LLVector3 target_offset_origin = mFocusObjectOffset;
+    LLVector3 camera_offset_target(getCameraPositionAgent() - gAgent.getPosAgentFromGlobal(mFocusTargetGlobal));
+
+    // convert offsets into object local space
+    camera_offset_target.rotVec(inv_object_rot);
+    target_offset_origin.rotVec(inv_object_rot);
+
+    // push around object extents based on target offset
+    LLVector3 object_extents = mFocusObject->getScale();
+    if (mFocusObject->isAvatar())
+    {
+        // fudge factors that lets you zoom in on avatars a bit more (which don't do FOV zoom)
+        object_extents.mV[VX] *= AVATAR_ZOOM_MIN_X_FACTOR;
+        object_extents.mV[VY] *= AVATAR_ZOOM_MIN_Y_FACTOR;
+        object_extents.mV[VZ] *= AVATAR_ZOOM_MIN_Z_FACTOR;
+        soft_limit = TRUE;
+    }
+    LLVector3 abs_target_offset = target_offset_origin;
+    abs_target_offset.abs();
+
+    LLVector3 target_offset_dir = target_offset_origin;
+
+    BOOL target_outside_object_extents = FALSE;
+
+    for (U32 i = VX; i <= VZ; i++)
+    {
+        if (abs_target_offset.mV[i] * 2.f > object_extents.mV[i] + OBJECT_EXTENTS_PADDING)
+        {
+            target_outside_object_extents = TRUE;
+        }
+        if (camera_offset_target.mV[i] > 0.f)
+        {
+            object_extents.mV[i] -= target_offset_origin.mV[i] * 2.f;
+        }
+        else
+        {
+            object_extents.mV[i] += target_offset_origin.mV[i] * 2.f;
+        }
+    }
+
+    // don't shrink the object extents so far that the object inverts
+    object_extents.clamp(0.001f, F32_MAX);
+
+    // move into first octant
+    LLVector3 camera_offset_target_abs_norm = camera_offset_target;
+    camera_offset_target_abs_norm.abs();
+    // make sure offset is non-zero
+    camera_offset_target_abs_norm.clamp(0.001f, F32_MAX);
+    camera_offset_target_abs_norm.normalize();
+
+    // find camera position relative to normalized object extents
+    LLVector3 camera_offset_target_scaled = camera_offset_target_abs_norm;
+    camera_offset_target_scaled.mV[VX] /= object_extents.mV[VX];
+    camera_offset_target_scaled.mV[VY] /= object_extents.mV[VY];
+    camera_offset_target_scaled.mV[VZ] /= object_extents.mV[VZ];
+
+    if (camera_offset_target_scaled.mV[VX] > camera_offset_target_scaled.mV[VY] &&
+        camera_offset_target_scaled.mV[VX] > camera_offset_target_scaled.mV[VZ])
+    {
+        if (camera_offset_target_abs_norm.mV[VX] < 0.001f)
+        {
+            obj_min_distance = object_extents.mV[VX] * 0.5f;
+        }
+        else
+        {
+            obj_min_distance = object_extents.mV[VX] * 0.5f / camera_offset_target_abs_norm.mV[VX];
+        }
+    }
+    else if (camera_offset_target_scaled.mV[VY] > camera_offset_target_scaled.mV[VZ])
+    {
+        if (camera_offset_target_abs_norm.mV[VY] < 0.001f)
+        {
+            obj_min_distance = object_extents.mV[VY] * 0.5f;
+        }
+        else
+        {
+            obj_min_distance = object_extents.mV[VY] * 0.5f / camera_offset_target_abs_norm.mV[VY];
+        }
+    }
+    else
+    {
+        if (camera_offset_target_abs_norm.mV[VZ] < 0.001f)
+        {
+            obj_min_distance = object_extents.mV[VZ] * 0.5f;
+        }
+        else
+        {
+            obj_min_distance = object_extents.mV[VZ] * 0.5f / camera_offset_target_abs_norm.mV[VZ];
+        }
+    }
+
+    LLVector3 object_split_axis;
+    LLVector3 target_offset_scaled = target_offset_origin;
+    target_offset_scaled.abs();
+    target_offset_scaled.normalize();
+    target_offset_scaled.mV[VX] /= object_extents.mV[VX];
+    target_offset_scaled.mV[VY] /= object_extents.mV[VY];
+    target_offset_scaled.mV[VZ] /= object_extents.mV[VZ];
+
+    if (target_offset_scaled.mV[VX] > target_offset_scaled.mV[VY] &&
+        target_offset_scaled.mV[VX] > target_offset_scaled.mV[VZ])
+    {
+        object_split_axis = LLVector3::x_axis;
+    }
+    else if (target_offset_scaled.mV[VY] > target_offset_scaled.mV[VZ])
+    {
+        object_split_axis = LLVector3::y_axis;
+    }
+    else
+    {
+        object_split_axis = LLVector3::z_axis;
+    }
+
+    LLVector3 camera_offset_object(getCameraPositionAgent() - mFocusObject->getPositionAgent());
+
+
+    F32 camera_offset_clip = camera_offset_object * object_split_axis;
+    F32 target_offset_clip = target_offset_dir * object_split_axis;
+
+    // target has moved outside of object extents
+    // check to see if camera and target are on same side
+    if (target_outside_object_extents)
+    {
+        if (camera_offset_clip > 0.f && target_offset_clip > 0.f)
+        {
+            return FALSE;
+        }
+        else if (camera_offset_clip < 0.f && target_offset_clip < 0.f)
+        {
+            return FALSE;
+        }
+    }
+
+    // clamp obj distance to diagonal of 10 by 10 cube
+    obj_min_distance = llmin(obj_min_distance, 10.f * F_SQRT3);
+
+    obj_min_distance += LLViewerCamera::getInstance()->getNear() + (soft_limit ? 0.1f : 0.2f);
+
+    return TRUE;
 }
 
 F32 LLAgentCamera::getCameraZoomFraction(bool get_third_person)
 {
-	// 0.f -> camera zoomed all the way out
-	// 1.f -> camera zoomed all the way in
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		// already [0,1]
-		return mHUDTargetZoom;
-	}
-
-	if (isDisableCameraConstraints())
-	{
-		return mCameraZoomFraction;
-	}
-
-	if (get_third_person || (mFocusOnAvatar && cameraThirdPerson()))
-	{
-		return clamp_rescale(mCameraZoomFraction, MIN_ZOOM_FRACTION, MAX_ZOOM_FRACTION, 1.f, 0.f);
-	}
-
-	if (cameraCustomizeAvatar())
-	{
-		F32 distance = (F32)mCameraFocusOffsetTarget.magVec();
-		return clamp_rescale(distance, APPEARANCE_MIN_ZOOM, APPEARANCE_MAX_ZOOM, 1.f, 0.f );
-	}
-
-	F32 min_zoom;
-	F32 max_zoom = getCameraMaxZoomDistance();
-
-	F32 distance = (F32)mCameraFocusOffsetTarget.magVec();
-	if (mFocusObject.notNull())
-	{
-		if (mFocusObject->isAvatar())
-		{
-			min_zoom = AVATAR_MIN_ZOOM;
-		}
-		else
-		{
-			min_zoom = OBJECT_MIN_ZOOM;
-		}
-	}
-	else
-	{
-		min_zoom = LAND_MIN_ZOOM;
-	}
-
-	return clamp_rescale(distance, min_zoom, max_zoom, 1.f, 0.f);
+    // 0.f -> camera zoomed all the way out
+    // 1.f -> camera zoomed all the way in
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        // already [0,1]
+        return mHUDTargetZoom;
+    }
+
+    if (isDisableCameraConstraints())
+    {
+        return mCameraZoomFraction;
+    }
+
+    if (get_third_person || (mFocusOnAvatar && cameraThirdPerson()))
+    {
+        return clamp_rescale(mCameraZoomFraction, MIN_ZOOM_FRACTION, MAX_ZOOM_FRACTION, 1.f, 0.f);
+    }
+
+    if (cameraCustomizeAvatar())
+    {
+        F32 distance = (F32)mCameraFocusOffsetTarget.magVec();
+        return clamp_rescale(distance, APPEARANCE_MIN_ZOOM, APPEARANCE_MAX_ZOOM, 1.f, 0.f );
+    }
+
+    F32 min_zoom;
+    F32 max_zoom = getCameraMaxZoomDistance();
+
+    F32 distance = (F32)mCameraFocusOffsetTarget.magVec();
+    if (mFocusObject.notNull())
+    {
+        if (mFocusObject->isAvatar())
+        {
+            min_zoom = AVATAR_MIN_ZOOM;
+        }
+        else
+        {
+            min_zoom = OBJECT_MIN_ZOOM;
+        }
+    }
+    else
+    {
+        min_zoom = LAND_MIN_ZOOM;
+    }
+
+    return clamp_rescale(distance, min_zoom, max_zoom, 1.f, 0.f);
 }
 
 void LLAgentCamera::setCameraZoomFraction(F32 fraction)
 {
-	// 0.f -> camera zoomed all the way out
-	// 1.f -> camera zoomed all the way in
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-
-	if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		mHUDTargetZoom = fraction;
-	}
-	else if (isDisableCameraConstraints())
-	{
-		mCameraZoomFraction = fraction;
-	}
-	else if (mFocusOnAvatar && cameraThirdPerson())
-	{
-		mCameraZoomFraction = rescale(fraction, 0.f, 1.f, MAX_ZOOM_FRACTION, MIN_ZOOM_FRACTION);
-	}
-	else if (cameraCustomizeAvatar())
-	{
-		LLVector3d camera_offset_dir = mCameraFocusOffsetTarget;
-		camera_offset_dir.normalize();
-		mCameraFocusOffsetTarget = camera_offset_dir * rescale(fraction, 0.f, 1.f, APPEARANCE_MAX_ZOOM, APPEARANCE_MIN_ZOOM);
-	}
-	else
-	{
-		F32 min_zoom = LAND_MIN_ZOOM;
-		F32 max_zoom = getCameraMaxZoomDistance();
-
-		if (mFocusObject.notNull())
+    // 0.f -> camera zoomed all the way out
+    // 1.f -> camera zoomed all the way in
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+
+    if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        mHUDTargetZoom = fraction;
+    }
+    else if (isDisableCameraConstraints())
+    {
+        mCameraZoomFraction = fraction;
+    }
+    else if (mFocusOnAvatar && cameraThirdPerson())
+    {
+        mCameraZoomFraction = rescale(fraction, 0.f, 1.f, MAX_ZOOM_FRACTION, MIN_ZOOM_FRACTION);
+    }
+    else if (cameraCustomizeAvatar())
+    {
+        LLVector3d camera_offset_dir = mCameraFocusOffsetTarget;
+        camera_offset_dir.normalize();
+        mCameraFocusOffsetTarget = camera_offset_dir * rescale(fraction, 0.f, 1.f, APPEARANCE_MAX_ZOOM, APPEARANCE_MIN_ZOOM);
+    }
+    else
+    {
+        F32 min_zoom = LAND_MIN_ZOOM;
+        F32 max_zoom = getCameraMaxZoomDistance();
+
+        if (mFocusObject.notNull())
         {
             if (mFocusObject->isAvatar())
             {
@@ -846,25 +846,25 @@ void LLAgentCamera::setCameraZoomFraction(F32 fraction)
             }
         }
 
-		LLVector3d camera_offset_dir = mCameraFocusOffsetTarget;
-		camera_offset_dir.normalize();
+        LLVector3d camera_offset_dir = mCameraFocusOffsetTarget;
+        camera_offset_dir.normalize();
 // [RLVa:KB] - Checked: 2.0.0
-		const LLVector3d focus_offset_target = camera_offset_dir * rescale(fraction, 0.f, 1.f, max_zoom, min_zoom);
-		if ( (RlvActions::isRlvEnabled()) && (!allowFocusOffsetChange(focus_offset_target)) )
-			return;
-		mCameraFocusOffsetTarget = focus_offset_target;
+        const LLVector3d focus_offset_target = camera_offset_dir * rescale(fraction, 0.f, 1.f, max_zoom, min_zoom);
+        if ( (RlvActions::isRlvEnabled()) && (!allowFocusOffsetChange(focus_offset_target)) )
+            return;
+        mCameraFocusOffsetTarget = focus_offset_target;
 // [/RLVa:KB]
-//		mCameraFocusOffsetTarget = camera_offset_dir * rescale(fraction, 0.f, 1.f, max_zoom, min_zoom);
-	}
+//      mCameraFocusOffsetTarget = camera_offset_dir * rescale(fraction, 0.f, 1.f, max_zoom, min_zoom);
+    }
 
-	startCameraAnimation();
+    startCameraAnimation();
 }
 
 F32 LLAgentCamera::getAgentHUDTargetZoom()
 {
-	static LLCachedControl<F32> hud_scale_factor(gSavedSettings, "HUDScaleFactor");
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	return (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD) ? hud_scale_factor*gAgentCamera.mHUDTargetZoom : hud_scale_factor;
+    static LLCachedControl<F32> hud_scale_factor(gSavedSettings, "HUDScaleFactor");
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    return (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD) ? hud_scale_factor*gAgentCamera.mHUDTargetZoom : hud_scale_factor;
 }
 
 //-----------------------------------------------------------------------------
@@ -872,22 +872,22 @@ F32 LLAgentCamera::getAgentHUDTargetZoom()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::cameraOrbitAround(const F32 radians)
 {
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		// do nothing for hud selection
-	}
-	else if (mFocusOnAvatar && (mCameraMode == CAMERA_MODE_THIRD_PERSON || mCameraMode == CAMERA_MODE_FOLLOW))
-	{
-		gAgent.yaw(radians);
-	}
-	else
-	{
-		mOrbitAroundRadians += radians;
-		mCameraFocusOffsetTarget.rotVec(radians, 0.f, 0.f, 1.f);
-		
-		cameraZoomIn(1.f);
-	}
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        // do nothing for hud selection
+    }
+    else if (mFocusOnAvatar && (mCameraMode == CAMERA_MODE_THIRD_PERSON || mCameraMode == CAMERA_MODE_FOLLOW))
+    {
+        gAgent.yaw(radians);
+    }
+    else
+    {
+        mOrbitAroundRadians += radians;
+        mCameraFocusOffsetTarget.rotVec(radians, 0.f, 0.f, 1.f);
+
+        cameraZoomIn(1.f);
+    }
 }
 
 
@@ -896,30 +896,30 @@ void LLAgentCamera::cameraOrbitAround(const F32 radians)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::cameraOrbitOver(const F32 angle)
 {
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		// do nothing for hud selection
-	}
-	else if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON)
-	{
-		gAgent.pitch(angle);
-	}
-	else
-	{
-		LLVector3 camera_offset_unit(mCameraFocusOffsetTarget);
-		camera_offset_unit.normalize();
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        // do nothing for hud selection
+    }
+    else if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON)
+    {
+        gAgent.pitch(angle);
+    }
+    else
+    {
+        LLVector3 camera_offset_unit(mCameraFocusOffsetTarget);
+        camera_offset_unit.normalize();
 
-		F32 angle_from_up = acos( camera_offset_unit * gAgent.getReferenceUpVector() );
+        F32 angle_from_up = acos( camera_offset_unit * gAgent.getReferenceUpVector() );
 
-		LLVector3d left_axis;
-		left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis());
-		F32 new_angle = llclamp(angle_from_up - angle, 1.f * DEG_TO_RAD, 179.f * DEG_TO_RAD);
-		mOrbitOverAngle += angle_from_up - new_angle;
-		mCameraFocusOffsetTarget.rotVec(angle_from_up - new_angle, left_axis);
+        LLVector3d left_axis;
+        left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis());
+        F32 new_angle = llclamp(angle_from_up - angle, 1.f * DEG_TO_RAD, 179.f * DEG_TO_RAD);
+        mOrbitOverAngle += angle_from_up - new_angle;
+        mCameraFocusOffsetTarget.rotVec(angle_from_up - new_angle, left_axis);
 
-		cameraZoomIn(1.f);
-	}
+        cameraZoomIn(1.f);
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -927,34 +927,34 @@ void LLAgentCamera::cameraOrbitOver(const F32 angle)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::cameraRollOver(const F32 angle)
 {
-	mRollAngle += fmod(angle, F_TWO_PI);
+    mRollAngle += fmod(angle, F_TWO_PI);
 }
 
 void LLAgentCamera::resetCameraRoll()
 {
-	mRollAngle = 0.f;
+    mRollAngle = 0.f;
 }
 
 void LLAgentCamera::resetCameraOrbit()
 {
-	LLVector3 camera_offset_unit(mCameraFocusOffsetTarget);
-	camera_offset_unit.normalize();
+    LLVector3 camera_offset_unit(mCameraFocusOffsetTarget);
+    camera_offset_unit.normalize();
+
+    LLVector3d left_axis;
+    left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis());
+    mCameraFocusOffsetTarget.rotVec(-mOrbitOverAngle, left_axis);
 
-	LLVector3d left_axis;
-	left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis());
-	mCameraFocusOffsetTarget.rotVec(-mOrbitOverAngle, left_axis);
-	
-	mCameraFocusOffsetTarget.rotVec(-mOrbitAroundRadians, 0.f, 0.f, 1.f);
+    mCameraFocusOffsetTarget.rotVec(-mOrbitAroundRadians, 0.f, 0.f, 1.f);
 
-	cameraZoomIn(1.f);
-	resetOrbitDiff();
-	resetCameraRoll();
+    cameraZoomIn(1.f);
+    resetOrbitDiff();
+    resetCameraRoll();
 }
 
 void LLAgentCamera::resetOrbitDiff()
 {
-	mOrbitAroundRadians = 0;
-	mOrbitOverAngle = 0;
+    mOrbitAroundRadians = 0;
+    mOrbitOverAngle = 0;
 }
 
 //-----------------------------------------------------------------------------
@@ -962,150 +962,150 @@ void LLAgentCamera::resetOrbitDiff()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::cameraZoomIn(const F32 fraction)
 {
-	if (gDisconnected)
-	{
-		return;
-	}
-
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	if (LLToolMgr::getInstance()->inBuildMode() && selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		// just update hud zoom level
-		mHUDTargetZoom /= fraction;
-		return;
-	}
-
-	LLVector3d camera_offset_unit(mCameraFocusOffsetTarget);
-	F32 current_distance = (F32)camera_offset_unit.normalize();
-	F32 new_distance = current_distance * fraction;
-
-	// Unless camera is unlocked
-	if (!isDisableCameraConstraints())
-	{
-		F32 min_zoom = LAND_MIN_ZOOM;
-
-		// Don't move through focus point
-		if (mFocusObject)
-		{
-			LLVector3 camera_offset_dir((F32)camera_offset_unit.mdV[VX], (F32)camera_offset_unit.mdV[VY], (F32)camera_offset_unit.mdV[VZ]);
-
-			if (mFocusObject->isAvatar())
-			{
-				calcCameraMinDistance(min_zoom);
-			}
-			else
-			{
-				min_zoom = OBJECT_MIN_ZOOM;
-			}
-		}
-
-		new_distance = llmax(new_distance, min_zoom);
-
-		F32 max_distance = getCameraMaxZoomDistance();
-		max_distance = llmin(max_distance, current_distance * 4.f); //Scaled max relative to current distance.  MAINT-3154
-		new_distance = llmin(new_distance, max_distance);
-
-		if (cameraCustomizeAvatar())
-		{
-			new_distance = llclamp(new_distance, APPEARANCE_MIN_ZOOM, APPEARANCE_MAX_ZOOM);
-		}
-	}
-
-// [RLVa:KB] - Checked: 2.0.0
-	if ( (RlvActions::isRlvEnabled()) && (!allowFocusOffsetChange(new_distance * camera_offset_unit)) )
-		return;
-// [/RLVa:KB]
+    if (gDisconnected)
+    {
+        return;
+    }
 
-	mCameraFocusOffsetTarget = new_distance * camera_offset_unit;
-}
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    if (LLToolMgr::getInstance()->inBuildMode() && selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        // just update hud zoom level
+        mHUDTargetZoom /= fraction;
+        return;
+    }
 
-//-----------------------------------------------------------------------------
-// cameraOrbitIn()
-//-----------------------------------------------------------------------------
-void LLAgentCamera::cameraOrbitIn(const F32 meters)
-{
-	if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON)
-	{
-// [RLVa:KB] - @setcam_eyeoffsetscale
-		F32 camera_offset_dist = llmax(0.001f, getCameraOffsetInitial().magVec() * getCameraOffsetScale());
-// [/RLVa:KB]
-//		F32 camera_offset_dist = llmax(0.001f, getCameraOffsetInitial().magVec() * gSavedSettings.getF32("CameraOffsetScale"));
-		
-		mCameraZoomFraction = (mTargetCameraDistance - meters) / camera_offset_dist;
-
-		if (!LLPipeline::FreezeTime && mCameraZoomFraction < MIN_ZOOM_FRACTION && meters > 0.f)
-		{
-			// No need to animate, camera is already there.
-			changeCameraToMouselook(FALSE);
-		}
-
-		if (!isDisableCameraConstraints())
-		{
-			mCameraZoomFraction = llclamp(mCameraZoomFraction, MIN_ZOOM_FRACTION, MAX_ZOOM_FRACTION);
-		}
-	}
-	else
-	{
-		LLVector3d	camera_offset_unit(mCameraFocusOffsetTarget);
-		F32 current_distance = (F32)camera_offset_unit.normalize();
-		F32 new_distance = current_distance - meters;
-
-		// Unless camera is unlocked
-		if (!isDisableCameraConstraints())
-		{
-			F32 min_zoom = LAND_MIN_ZOOM;
-
-			// Don't move through focus point
-			if (mFocusObject.notNull())
-			{
-				if (mFocusObject->isAvatar())
-				{
-					min_zoom = AVATAR_MIN_ZOOM;
-				}
-				else
-				{
-					min_zoom = OBJECT_MIN_ZOOM;
-				}
-			}
-
-			new_distance = llmax(new_distance, min_zoom);
-
-			F32 max_distance = getCameraMaxZoomDistance();
-			new_distance = llmin(new_distance, max_distance);
-
-			if (CAMERA_MODE_CUSTOMIZE_AVATAR == getCameraMode())
-			{
-				new_distance = llclamp(new_distance, APPEARANCE_MIN_ZOOM, APPEARANCE_MAX_ZOOM);
-			}
-		}
+    LLVector3d camera_offset_unit(mCameraFocusOffsetTarget);
+    F32 current_distance = (F32)camera_offset_unit.normalize();
+    F32 new_distance = current_distance * fraction;
 
-// [RLVa:KB] - Checked: 2.0.0
-		if ( (RlvActions::isRlvEnabled()) && (!allowFocusOffsetChange(new_distance * camera_offset_unit)) )
-			return;
-// [/RLVa:KB]
+    // Unless camera is unlocked
+    if (!isDisableCameraConstraints())
+    {
+        F32 min_zoom = LAND_MIN_ZOOM;
 
-		// Compute new camera offset
-		mCameraFocusOffsetTarget = new_distance * camera_offset_unit;
-		cameraZoomIn(1.f);
-	}
-}
+        // Don't move through focus point
+        if (mFocusObject)
+        {
+            LLVector3 camera_offset_dir((F32)camera_offset_unit.mdV[VX], (F32)camera_offset_unit.mdV[VY], (F32)camera_offset_unit.mdV[VZ]);
+
+            if (mFocusObject->isAvatar())
+            {
+                calcCameraMinDistance(min_zoom);
+            }
+            else
+            {
+                min_zoom = OBJECT_MIN_ZOOM;
+            }
+        }
+
+        new_distance = llmax(new_distance, min_zoom);
+
+        F32 max_distance = getCameraMaxZoomDistance();
+        max_distance = llmin(max_distance, current_distance * 4.f); //Scaled max relative to current distance.  MAINT-3154
+        new_distance = llmin(new_distance, max_distance);
+
+        if (cameraCustomizeAvatar())
+        {
+            new_distance = llclamp(new_distance, APPEARANCE_MIN_ZOOM, APPEARANCE_MAX_ZOOM);
+        }
+    }
+
+// [RLVa:KB] - Checked: 2.0.0
+    if ( (RlvActions::isRlvEnabled()) && (!allowFocusOffsetChange(new_distance * camera_offset_unit)) )
+        return;
+// [/RLVa:KB]
+
+    mCameraFocusOffsetTarget = new_distance * camera_offset_unit;
+}
+
+//-----------------------------------------------------------------------------
+// cameraOrbitIn()
+//-----------------------------------------------------------------------------
+void LLAgentCamera::cameraOrbitIn(const F32 meters)
+{
+    if (mFocusOnAvatar && mCameraMode == CAMERA_MODE_THIRD_PERSON)
+    {
+// [RLVa:KB] - @setcam_eyeoffsetscale
+        F32 camera_offset_dist = llmax(0.001f, getCameraOffsetInitial().magVec() * getCameraOffsetScale());
+// [/RLVa:KB]
+//      F32 camera_offset_dist = llmax(0.001f, getCameraOffsetInitial().magVec() * gSavedSettings.getF32("CameraOffsetScale"));
+
+        mCameraZoomFraction = (mTargetCameraDistance - meters) / camera_offset_dist;
+
+        if (!LLPipeline::FreezeTime && mCameraZoomFraction < MIN_ZOOM_FRACTION && meters > 0.f)
+        {
+            // No need to animate, camera is already there.
+            changeCameraToMouselook(FALSE);
+        }
+
+        if (!isDisableCameraConstraints())
+        {
+            mCameraZoomFraction = llclamp(mCameraZoomFraction, MIN_ZOOM_FRACTION, MAX_ZOOM_FRACTION);
+        }
+    }
+    else
+    {
+        LLVector3d  camera_offset_unit(mCameraFocusOffsetTarget);
+        F32 current_distance = (F32)camera_offset_unit.normalize();
+        F32 new_distance = current_distance - meters;
+
+        // Unless camera is unlocked
+        if (!isDisableCameraConstraints())
+        {
+            F32 min_zoom = LAND_MIN_ZOOM;
+
+            // Don't move through focus point
+            if (mFocusObject.notNull())
+            {
+                if (mFocusObject->isAvatar())
+                {
+                    min_zoom = AVATAR_MIN_ZOOM;
+                }
+                else
+                {
+                    min_zoom = OBJECT_MIN_ZOOM;
+                }
+            }
+
+            new_distance = llmax(new_distance, min_zoom);
+
+            F32 max_distance = getCameraMaxZoomDistance();
+            new_distance = llmin(new_distance, max_distance);
+
+            if (CAMERA_MODE_CUSTOMIZE_AVATAR == getCameraMode())
+            {
+                new_distance = llclamp(new_distance, APPEARANCE_MIN_ZOOM, APPEARANCE_MAX_ZOOM);
+            }
+        }
+
+// [RLVa:KB] - Checked: 2.0.0
+        if ( (RlvActions::isRlvEnabled()) && (!allowFocusOffsetChange(new_distance * camera_offset_unit)) )
+            return;
+// [/RLVa:KB]
+
+        // Compute new camera offset
+        mCameraFocusOffsetTarget = new_distance * camera_offset_unit;
+        cameraZoomIn(1.f);
+    }
+}
 
 //-----------------------------------------------------------------------------
 // cameraPanIn()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::cameraPanIn(F32 meters)
 {
-	LLVector3d at_axis;
-	at_axis.setVec(LLViewerCamera::getInstance()->getAtAxis());
+    LLVector3d at_axis;
+    at_axis.setVec(LLViewerCamera::getInstance()->getAtAxis());
 
-	mPanFocusDiff += meters * at_axis;
+    mPanFocusDiff += meters * at_axis;
 
-	mFocusTargetGlobal += meters * at_axis;
-	mFocusGlobal = mFocusTargetGlobal;
-	// don't enforce zoom constraints as this is the only way for users to get past them easily
-	updateFocusOffset();
-	// NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind -Nyx
-	mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
+    mFocusTargetGlobal += meters * at_axis;
+    mFocusGlobal = mFocusTargetGlobal;
+    // don't enforce zoom constraints as this is the only way for users to get past them easily
+    updateFocusOffset();
+    // NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind -Nyx
+    mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
 }
 
 //-----------------------------------------------------------------------------
@@ -1113,21 +1113,21 @@ void LLAgentCamera::cameraPanIn(F32 meters)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::cameraPanLeft(F32 meters)
 {
-	LLVector3d left_axis;
-	left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis());
+    LLVector3d left_axis;
+    left_axis.setVec(LLViewerCamera::getInstance()->getLeftAxis());
+
+    mPanFocusDiff += meters * left_axis;
 
-	mPanFocusDiff += meters * left_axis;
+    mFocusTargetGlobal += meters * left_axis;
+    mFocusGlobal = mFocusTargetGlobal;
 
-	mFocusTargetGlobal += meters * left_axis;
-	mFocusGlobal = mFocusTargetGlobal;
+    // disable smoothing for camera pan, which causes some residents unhappiness
+    mCameraSmoothingStop = true;
 
-	// disable smoothing for camera pan, which causes some residents unhappiness
-	mCameraSmoothingStop = true;
-	
-	cameraZoomIn(1.f);
-	updateFocusOffset();
-	// NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind - Nyx
-	mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
+    cameraZoomIn(1.f);
+    updateFocusOffset();
+    // NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind - Nyx
+    mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
 }
 
 //-----------------------------------------------------------------------------
@@ -1135,41 +1135,41 @@ void LLAgentCamera::cameraPanLeft(F32 meters)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::cameraPanUp(F32 meters)
 {
-	LLVector3d up_axis;
-	up_axis.setVec(LLViewerCamera::getInstance()->getUpAxis());
+    LLVector3d up_axis;
+    up_axis.setVec(LLViewerCamera::getInstance()->getUpAxis());
 
-	mPanFocusDiff += meters * up_axis;
+    mPanFocusDiff += meters * up_axis;
 
-	mFocusTargetGlobal += meters * up_axis;
-	mFocusGlobal = mFocusTargetGlobal;
+    mFocusTargetGlobal += meters * up_axis;
+    mFocusGlobal = mFocusTargetGlobal;
 
-	// disable smoothing for camera pan, which causes some residents unhappiness
-	mCameraSmoothingStop = true;
+    // disable smoothing for camera pan, which causes some residents unhappiness
+    mCameraSmoothingStop = true;
 
-	cameraZoomIn(1.f);
-	updateFocusOffset();
-	// NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind -Nyx
-	mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
+    cameraZoomIn(1.f);
+    updateFocusOffset();
+    // NOTE: panning movements expect the camera to move exactly with the focus target, not animated behind -Nyx
+    mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
 }
 
 void LLAgentCamera::resetCameraPan()
 {
-	mFocusTargetGlobal -= mPanFocusDiff;
+    mFocusTargetGlobal -= mPanFocusDiff;
 
-	mFocusGlobal = mFocusTargetGlobal;
-	mCameraSmoothingStop = true;
+    mFocusGlobal = mFocusTargetGlobal;
+    mCameraSmoothingStop = true;
 
-	cameraZoomIn(1.f);
-	updateFocusOffset();
+    cameraZoomIn(1.f);
+    updateFocusOffset();
 
-	mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
+    mCameraSmoothingLastPositionGlobal = calcCameraPositionTargetGlobal();
 
-	resetPanDiff();
+    resetPanDiff();
 }
 
 void LLAgentCamera::resetPanDiff()
 {
-	mPanFocusDiff.clear();
+    mPanFocusDiff.clear();
 }
 
 //-----------------------------------------------------------------------------
@@ -1177,67 +1177,67 @@ void LLAgentCamera::resetPanDiff()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::updateLookAt(const S32 mouse_x, const S32 mouse_y)
 {
-	static LLVector3 last_at_axis;
-
-	if (!isAgentAvatarValid()) return;
-
-	LLQuaternion av_inv_rot = ~gAgentAvatarp->mRoot->getWorldRotation();
-	LLVector3 root_at = LLVector3::x_axis * gAgentAvatarp->mRoot->getWorldRotation();
-
-	if 	(LLTrace::get_frame_recording().getLastRecording().getLastValue(*gViewerWindow->getMouseVelocityStat()) < 0.01f
-		&& (root_at * last_at_axis > 0.95f))
-	{
-		LLVector3 vel = gAgentAvatarp->getVelocity();
-		if (vel.magVecSquared() > 4.f)
-		{
-			setLookAt(LOOKAT_TARGET_IDLE, gAgentAvatarp, vel * av_inv_rot);
-		}
-		else
-		{
-			// *FIX: rotate mframeagent by sit object's rotation?
-			LLQuaternion look_rotation = gAgentAvatarp->isSitting() ? gAgentAvatarp->getRenderRotation() : gAgent.getFrameAgent().getQuaternion(); // use camera's current rotation
-			LLVector3 look_offset = LLVector3(2.f, 0.f, 0.f) * look_rotation * av_inv_rot;
-			setLookAt(LOOKAT_TARGET_IDLE, gAgentAvatarp, look_offset);
-		}
-		last_at_axis = root_at;
-		return;
-	}
-
-	last_at_axis = root_at;
-	
-	if (CAMERA_MODE_CUSTOMIZE_AVATAR == getCameraMode())
-	{
-		setLookAt(LOOKAT_TARGET_NONE, gAgentAvatarp, LLVector3(-2.f, 0.f, 0.f));	
-	}
-	else
-	{
-		// Move head based on cursor position
-		ELookAtType lookAtType = LOOKAT_TARGET_NONE;
-		LLVector3 headLookAxis;
-		LLCoordFrame frameCamera = *((LLCoordFrame*)LLViewerCamera::getInstance());
-
-		if (cameraMouselook())
-		{
-			lookAtType = LOOKAT_TARGET_MOUSELOOK;
-		}
-		else if (cameraThirdPerson())
-		{
-			// range from -.5 to .5
-			F32 x_from_center = 
-				((F32) mouse_x / (F32) gViewerWindow->getWorldViewWidthScaled() ) - 0.5f;
-			F32 y_from_center = 
-				((F32) mouse_y / (F32) gViewerWindow->getWorldViewHeightScaled() ) - 0.5f;
-
-			frameCamera.yaw( - x_from_center * ALControlCache::YawFromMousePosition * DEG_TO_RAD);
-			frameCamera.pitch( - y_from_center * ALControlCache::PitchFromMousePosition * DEG_TO_RAD);
-			lookAtType = LOOKAT_TARGET_FREELOOK;
-		}
-
-		headLookAxis = frameCamera.getAtAxis();
-		// RN: we use world-space offset for mouselook and freelook
-		//headLookAxis = headLookAxis * av_inv_rot;
-		setLookAt(lookAtType, gAgentAvatarp, headLookAxis);
-	}
+    static LLVector3 last_at_axis;
+
+    if (!isAgentAvatarValid()) return;
+
+    LLQuaternion av_inv_rot = ~gAgentAvatarp->mRoot->getWorldRotation();
+    LLVector3 root_at = LLVector3::x_axis * gAgentAvatarp->mRoot->getWorldRotation();
+
+    if  (LLTrace::get_frame_recording().getLastRecording().getLastValue(*gViewerWindow->getMouseVelocityStat()) < 0.01f
+        && (root_at * last_at_axis > 0.95f))
+    {
+        LLVector3 vel = gAgentAvatarp->getVelocity();
+        if (vel.magVecSquared() > 4.f)
+        {
+            setLookAt(LOOKAT_TARGET_IDLE, gAgentAvatarp, vel * av_inv_rot);
+        }
+        else
+        {
+            // *FIX: rotate mframeagent by sit object's rotation?
+            LLQuaternion look_rotation = gAgentAvatarp->isSitting() ? gAgentAvatarp->getRenderRotation() : gAgent.getFrameAgent().getQuaternion(); // use camera's current rotation
+            LLVector3 look_offset = LLVector3(2.f, 0.f, 0.f) * look_rotation * av_inv_rot;
+            setLookAt(LOOKAT_TARGET_IDLE, gAgentAvatarp, look_offset);
+        }
+        last_at_axis = root_at;
+        return;
+    }
+
+    last_at_axis = root_at;
+
+    if (CAMERA_MODE_CUSTOMIZE_AVATAR == getCameraMode())
+    {
+        setLookAt(LOOKAT_TARGET_NONE, gAgentAvatarp, LLVector3(-2.f, 0.f, 0.f));
+    }
+    else
+    {
+        // Move head based on cursor position
+        ELookAtType lookAtType = LOOKAT_TARGET_NONE;
+        LLVector3 headLookAxis;
+        LLCoordFrame frameCamera = *((LLCoordFrame*)LLViewerCamera::getInstance());
+
+        if (cameraMouselook())
+        {
+            lookAtType = LOOKAT_TARGET_MOUSELOOK;
+        }
+        else if (cameraThirdPerson())
+        {
+            // range from -.5 to .5
+            F32 x_from_center =
+                ((F32) mouse_x / (F32) gViewerWindow->getWorldViewWidthScaled() ) - 0.5f;
+            F32 y_from_center =
+                ((F32) mouse_y / (F32) gViewerWindow->getWorldViewHeightScaled() ) - 0.5f;
+
+            frameCamera.yaw( - x_from_center * ALControlCache::YawFromMousePosition * DEG_TO_RAD);
+            frameCamera.pitch( - y_from_center * ALControlCache::PitchFromMousePosition * DEG_TO_RAD);
+            lookAtType = LOOKAT_TARGET_FREELOOK;
+        }
+
+        headLookAxis = frameCamera.getAtAxis();
+        // RN: we use world-space offset for mouselook and freelook
+        //headLookAxis = headLookAxis * av_inv_rot;
+        setLookAt(lookAtType, gAgentAvatarp, headLookAxis);
+    }
 }
 
 static LLTrace::BlockTimerStatHandle FTM_UPDATE_CAMERA("Camera");
@@ -1249,429 +1249,429 @@ extern BOOL gCubeSnapshot;
 //-----------------------------------------------------------------------------
 void LLAgentCamera::updateCamera()
 {
-	LL_RECORD_BLOCK_TIME(FTM_UPDATE_CAMERA);
+    LL_RECORD_BLOCK_TIME(FTM_UPDATE_CAMERA);
     if (gCubeSnapshot)
     {
         return;
     }
 
-	//BD - Camera Rolling
-	//     Make sure we always start with a neutral camera roll.
-	// - changed camera_skyward to the new global "mCameraUpVector"
-	mCameraUpVector = LLVector3::z_axis;
-	//LLVector3	camera_skyward(0.f, 0.f, 1.f);
+    //BD - Camera Rolling
+    //     Make sure we always start with a neutral camera roll.
+    // - changed camera_skyward to the new global "mCameraUpVector"
+    mCameraUpVector = LLVector3::z_axis;
+    //LLVector3 camera_skyward(0.f, 0.f, 1.f);
 
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	// Set focus back on our avie if something changed it
-	if ( (gRlvHandler.hasBehaviour(RLV_BHVR_SETCAM_UNLOCK)) && ((cameraThirdPerson()) || (cameraFollow())) && (!getFocusOnAvatar()) )
-	{
-		setFocusOnAvatar(TRUE, FALSE);
-	}
+    // Set focus back on our avie if something changed it
+    if ( (gRlvHandler.hasBehaviour(RLV_BHVR_SETCAM_UNLOCK)) && ((cameraThirdPerson()) || (cameraFollow())) && (!getFocusOnAvatar()) )
+    {
+        setFocusOnAvatar(TRUE, FALSE);
+    }
 // [/RLVa:KB]
 
-	U32 camera_mode = mCameraAnimating ? mLastCameraMode : mCameraMode;
-
-	validateFocusObject();
-	static LLCachedControl<bool> useRealisticMouselook(gSavedSettings, "AlchemyRealisticMouselook", false);
-	if (isAgentAvatarValid() && 
-		gAgentAvatarp->isSitting() &&
-		camera_mode == CAMERA_MODE_MOUSELOOK)
-	{
-		//changed camera_skyward to the new global "mCameraUpVector"
-		mCameraUpVector = mCameraUpVector * gAgentAvatarp->getRenderRotation();
-	}
-
-	if (cameraThirdPerson() && (mFocusOnAvatar || mAllowChangeToFollow) && LLFollowCamMgr::getInstance()->getActiveFollowCamParams())
-	{
-		mAllowChangeToFollow = FALSE;
-		mFocusOnAvatar = TRUE;
-		changeCameraToFollow();
-	}
-
-	//NOTE - this needs to be integrated into a general upVector system here within llAgent. 
-	if ( camera_mode == CAMERA_MODE_FOLLOW && mFocusOnAvatar )
-	{
-		mCameraUpVector = mFollowCam.getUpVector();
-	}
-
-	if (mSitCameraEnabled)
-	{
-		if (mSitCameraReferenceObject->isDead())
-		{
-			setSitCamera(LLUUID::null);
-		}
-	}
-
-	// Update UI with our camera inputs
-	LLFloaterCamera* camera_floater = LLFloaterReg::findTypedInstance<LLFloaterCamera>("camera");
-	if (camera_floater)
-	{
-		camera_floater->mRotate->setToggleState(gAgentCamera.getOrbitRightKey() > 0.f,	// left
-												gAgentCamera.getOrbitUpKey() > 0.f,		// top
-												gAgentCamera.getOrbitLeftKey() > 0.f,	// right
-												gAgentCamera.getOrbitDownKey() > 0.f);	// bottom
-		
-		camera_floater->mTrack->setToggleState(gAgentCamera.getPanLeftKey() > 0.f,		// left
-											   gAgentCamera.getPanUpKey() > 0.f,			// top
-											   gAgentCamera.getPanRightKey() > 0.f,		// right
-											   gAgentCamera.getPanDownKey() > 0.f);		// bottom
-	}
-
-	auto& vwr_camera = LLViewerCamera::instance();
-
-	// Handle camera movement based on keyboard.
-	const F32 ORBIT_OVER_RATE = 90.f * DEG_TO_RAD;			// radians per second
-	const F32 ORBIT_AROUND_RATE = 90.f * DEG_TO_RAD;		// radians per second
-	const F32 PAN_RATE = 5.f;								// meters per second
-	const F32 ROLL_RATE = 45.f * DEG_TO_RAD;				// radians per second
-
-	if (gAgentCamera.getOrbitUpKey() || gAgentCamera.getOrbitDownKey())
-	{
-		F32 input_rate = gAgentCamera.getOrbitUpKey() - gAgentCamera.getOrbitDownKey();
-		cameraOrbitOver( input_rate * ORBIT_OVER_RATE / gFPSClamped );
-	}
-
-	if (gAgentCamera.getOrbitLeftKey() || gAgentCamera.getOrbitRightKey())
-	{
-		F32 input_rate = gAgentCamera.getOrbitLeftKey() - gAgentCamera.getOrbitRightKey();
-		cameraOrbitAround(input_rate * ORBIT_AROUND_RATE / gFPSClamped);
-	}
-
-	if (gAgentCamera.getOrbitInKey() || gAgentCamera.getOrbitOutKey())
-	{
-		F32 input_rate = gAgentCamera.getOrbitInKey() - gAgentCamera.getOrbitOutKey();
-		
-		LLVector3d to_focus = gAgent.getPosGlobalFromAgent(vwr_camera.getOrigin()) - calcFocusPositionTargetGlobal();
-		F32 distance_to_focus = (F32)to_focus.magVec();
-		// Move at distance (in meters) meters per second
-		cameraOrbitIn( input_rate * distance_to_focus / gFPSClamped );
-	}
-
-	if (gAgentCamera.getPanInKey() || gAgentCamera.getPanOutKey())
-	{
-		F32 input_rate = gAgentCamera.getPanInKey() - gAgentCamera.getPanOutKey();
-		cameraPanIn(input_rate * PAN_RATE / gFPSClamped);
-	}
-
-	if (gAgentCamera.getPanRightKey() || gAgentCamera.getPanLeftKey())
-	{
-		F32 input_rate = gAgentCamera.getPanRightKey() - gAgentCamera.getPanLeftKey();
-		cameraPanLeft(input_rate * -PAN_RATE / gFPSClamped );
-	}
-
-	if (gAgentCamera.getPanUpKey() || gAgentCamera.getPanDownKey())
-	{
-		F32 input_rate = gAgentCamera.getPanUpKey() - gAgentCamera.getPanDownKey();
-		cameraPanUp(input_rate * PAN_RATE / gFPSClamped );
-	}
-
-	if (getRollLeftKey() || getRollRightKey())
-	{
-		F32 input_rate = getRollRightKey() - getRollLeftKey();
-		cameraRollOver(input_rate * ROLL_RATE / gFPSClamped);
-	}
-
-	// Clear camera keyboard keys.
-	gAgentCamera.clearOrbitKeys();
-	gAgentCamera.clearPanKeys();
-
-	// lerp camera focus offset
-	mCameraFocusOffset = lerp(mCameraFocusOffset, mCameraFocusOffsetTarget, LLSmoothInterpolation::getInterpolant(CAMERA_FOCUS_HALF_LIFE));
-
-	if ( mCameraMode == CAMERA_MODE_FOLLOW )
-	{
-		if (isAgentAvatarValid())
-		{
-			//--------------------------------------------------------------------------------
-			// this is where the avatar's position and rotation are given to followCam, and 
-			// where it is updated. All three of its attributes are updated: (1) position, 
-			// (2) focus, and (3) upvector. They can then be queried elsewhere in llAgent.
-			//--------------------------------------------------------------------------------
-			// *TODO: use combined rotation of frameagent and sit object
-			LLQuaternion avatarRotationForFollowCam = gAgentAvatarp->isSitting() ? gAgentAvatarp->getRenderRotation() : gAgent.getFrameAgent().getQuaternion();
-
-			LLFollowCamParams* current_cam = LLFollowCamMgr::getInstance()->getActiveFollowCamParams();
-			if (current_cam)
-			{
-				mFollowCam.copyParams(*current_cam);
-				mFollowCam.setSubjectPositionAndRotation( gAgentAvatarp->getRenderPosition(), avatarRotationForFollowCam );
-				mFollowCam.update();
-				LLViewerJoystick::getInstance()->setCameraNeedsUpdate(true);
-			}
-			else
-			{
-				changeCameraToThirdPerson(TRUE);
-			}
-		}
-	}
-
-	BOOL hit_limit;
-	LLVector3d camera_pos_global;
-	LLVector3d camera_target_global = calcCameraPositionTargetGlobal(&hit_limit);
-	mCameraVirtualPositionAgent = gAgent.getPosAgentFromGlobal(camera_target_global);
-	LLVector3d focus_target_global = calcFocusPositionTargetGlobal();
-
-	// perform field of view correction
-	mCameraFOVZoomFactor = calcCameraFOVZoomFactor();
-	camera_target_global = focus_target_global + (camera_target_global - focus_target_global) * (1.f + mCameraFOVZoomFactor);
-
-	gAgent.setShowAvatar(TRUE); // can see avatar by default
-
-	// Adjust position for animation
-	if (mCameraAnimating)
-	{
-		F32 time = mAnimationTimer.getElapsedTimeF32();
-
-		// yet another instance of critically damped motion, hooray!
-		// F32 fraction_of_animation = 1.f - pow(2.f, -time / CAMERA_ZOOM_HALF_LIFE);
-
-		// linear interpolation
-		F32 fraction_of_animation = time / mAnimationDuration;
-
-		BOOL isfirstPerson = mCameraMode == CAMERA_MODE_MOUSELOOK;
-		BOOL wasfirstPerson = mLastCameraMode == CAMERA_MODE_MOUSELOOK;
-		F32 fraction_animation_to_skip;
-
-		if (mAnimationCameraStartGlobal == camera_target_global)
-		{
-			fraction_animation_to_skip = 0.f;
-		}
-		else
-		{
-			LLVector3d cam_delta = mAnimationCameraStartGlobal - camera_target_global;
-			fraction_animation_to_skip = HEAD_BUFFER_SIZE / (F32)cam_delta.magVec();
-		}
-		F32 animation_start_fraction = (wasfirstPerson) ? fraction_animation_to_skip : 0.f;
-		F32 animation_finish_fraction =  (isfirstPerson) ? (1.f - fraction_animation_to_skip) : 1.f;
-	
-		if (fraction_of_animation < animation_finish_fraction)
-		{
-			if (fraction_of_animation < animation_start_fraction || fraction_of_animation > animation_finish_fraction )
-			{
-				gAgent.setShowAvatar(FALSE);
-			}
-
-			// ...adjust position for animation
-			F32 smooth_fraction_of_animation = llsmoothstep(0.0f, 1.0f, fraction_of_animation);
-			camera_pos_global = lerp(mAnimationCameraStartGlobal, camera_target_global, smooth_fraction_of_animation);
-			mFocusGlobal = lerp(mAnimationFocusStartGlobal, focus_target_global, smooth_fraction_of_animation);
-		}
-		else
-		{
-			// ...animation complete
-			mCameraAnimating = FALSE;
-
-			camera_pos_global = camera_target_global;
-			mFocusGlobal = focus_target_global;
-
-			gAgent.endAnimationUpdateUI();
-			gAgent.setShowAvatar(TRUE);
-		}
-
-		if (isAgentAvatarValid() && (mCameraMode != CAMERA_MODE_MOUSELOOK))
-		{
-			gAgentAvatarp->updateAttachmentVisibility(mCameraMode);
-		}
-	}
-	else 
-	{
-		camera_pos_global = camera_target_global;
-		mFocusGlobal = focus_target_global;
-		gAgent.setShowAvatar(TRUE);
-	}
-
-	// smoothing
-	if (TRUE)
-	{
-		LLVector3d agent_pos = gAgent.getPositionGlobal();
-		LLVector3d camera_pos_agent = camera_pos_global - agent_pos;
-		// Sitting on what you're manipulating can cause camera jitter with smoothing. 
-		// This turns off smoothing while editing. -MG
-		bool in_build_mode = LLToolMgr::getInstance()->inBuildMode();
-		mCameraSmoothingStop = mCameraSmoothingStop || in_build_mode;
-		
-		if (cameraThirdPerson() && !mCameraSmoothingStop)
-		{
-			const F32 SMOOTHING_HALF_LIFE = 0.02f;
-			
-			static const LLCachedControl<F32> cam_pos_smoothing(gSavedSettings, "CameraPositionSmoothing");
-			F32 smoothing = LLSmoothInterpolation::getInterpolant(cam_pos_smoothing * SMOOTHING_HALF_LIFE, FALSE);
-					
-			if (mFocusOnAvatar && !mFocusObject) // we differentiate on avatar mode 
-			{
-				// for avatar-relative focus, we smooth in avatar space -
-				// the avatar moves too jerkily w/r/t global space to smooth there.
-
-				LLVector3d delta = camera_pos_agent - mCameraSmoothingLastPositionAgent;
-				if (delta.magVec() < MAX_CAMERA_SMOOTH_DISTANCE)  // only smooth over short distances please
-				{
-					camera_pos_agent = lerp(mCameraSmoothingLastPositionAgent, camera_pos_agent, smoothing);
-					camera_pos_global = camera_pos_agent + agent_pos;
-				}
-			}
-			else
-			{
-				LLVector3d delta = camera_pos_global - mCameraSmoothingLastPositionGlobal;
-				if (delta.magVec() < MAX_CAMERA_SMOOTH_DISTANCE) // only smooth over short distances please
-				{
-					camera_pos_global = lerp(mCameraSmoothingLastPositionGlobal, camera_pos_global, smoothing);
-				}
-			}
-		}
-								 
-		mCameraSmoothingLastPositionGlobal = camera_pos_global;
-		mCameraSmoothingLastPositionAgent = camera_pos_agent;
-		mCameraSmoothingStop = false;
-	}
-
-	
-	mCameraCurrentFOVZoomFactor = ll_lerp(mCameraCurrentFOVZoomFactor, mCameraFOVZoomFactor, LLSmoothInterpolation::getInterpolant(FOV_ZOOM_HALF_LIFE));
-
-//	LL_INFOS() << "Current FOV Zoom: " << mCameraCurrentFOVZoomFactor << " Target FOV Zoom: " << mCameraFOVZoomFactor << " Object penetration: " << mFocusObjectDist << LL_ENDL;
-
-	LLVector3 focus_agent = gAgent.getPosAgentFromGlobal(mFocusGlobal);
-	
-	mCameraPositionAgent = gAgent.getPosAgentFromGlobal(camera_pos_global);
-
-	// Move the camera
-	vwr_camera.updateCameraLocation(mCameraPositionAgent, mCameraUpVector, focus_agent);
-	//LLViewerCamera::getInstance()->updateCameraLocation(mCameraPositionAgent, camera_skyward, focus_agent);
-	
-	// Change FOV
-	vwr_camera.setView(vwr_camera.getDefaultFOV() / (1.f + mCameraCurrentFOVZoomFactor));
-
-	// follow camera when in customize mode
-	if (cameraCustomizeAvatar())	
-	{
-		setLookAt(LOOKAT_TARGET_FOCUS, NULL, mCameraPositionAgent);
-	}
-
-	// update the travel distance stat
-	// this isn't directly related to the camera
-	// but this seemed like the best place to do this
-	LLVector3d global_pos = gAgent.getPositionGlobal(); 
-	if (!gAgent.getLastPositionGlobal().isExactlyZero())
-	{
-		LLVector3d delta = global_pos - gAgent.getLastPositionGlobal();
-		gAgent.setDistanceTraveled(gAgent.getDistanceTraveled() + delta.magVec());
-	}
-	gAgent.setLastPositionGlobal(global_pos);
-	
-	if (LLVOAvatar::sVisibleInFirstPerson && isAgentAvatarValid() && !gAgentAvatarp->isSitting() && cameraMouselook())
-	{
-		LLVector3 head_pos = gAgentAvatarp->mHeadp->getWorldPosition() + 
-			LLVector3(0.08f, 0.f, 0.05f) * gAgentAvatarp->mHeadp->getWorldRotation() + 
-			LLVector3(0.1f, 0.f, 0.f) * gAgentAvatarp->mPelvisp->getWorldRotation();
-		LLVector3 diff = mCameraPositionAgent - head_pos;
-		diff = diff * ~gAgentAvatarp->mRoot->getWorldRotation();
-
-		LLJoint* torso_joint = gAgentAvatarp->mTorsop;
-		LLJoint* chest_joint = gAgentAvatarp->mChestp;
-		LLVector3 torso_scale = torso_joint->getScale();
-		LLVector3 chest_scale = chest_joint->getScale();
-
-		// shorten avatar skeleton to avoid foot interpenetration
+    U32 camera_mode = mCameraAnimating ? mLastCameraMode : mCameraMode;
+
+    validateFocusObject();
+    static LLCachedControl<bool> useRealisticMouselook(gSavedSettings, "AlchemyRealisticMouselook", false);
+    if (isAgentAvatarValid() &&
+        gAgentAvatarp->isSitting() &&
+        camera_mode == CAMERA_MODE_MOUSELOOK)
+    {
+        //changed camera_skyward to the new global "mCameraUpVector"
+        mCameraUpVector = mCameraUpVector * gAgentAvatarp->getRenderRotation();
+    }
+
+    if (cameraThirdPerson() && (mFocusOnAvatar || mAllowChangeToFollow) && LLFollowCamMgr::getInstance()->getActiveFollowCamParams())
+    {
+        mAllowChangeToFollow = FALSE;
+        mFocusOnAvatar = TRUE;
+        changeCameraToFollow();
+    }
+
+    //NOTE - this needs to be integrated into a general upVector system here within llAgent.
+    if ( camera_mode == CAMERA_MODE_FOLLOW && mFocusOnAvatar )
+    {
+        mCameraUpVector = mFollowCam.getUpVector();
+    }
+
+    if (mSitCameraEnabled)
+    {
+        if (mSitCameraReferenceObject->isDead())
+        {
+            setSitCamera(LLUUID::null);
+        }
+    }
+
+    // Update UI with our camera inputs
+    LLFloaterCamera* camera_floater = LLFloaterReg::findTypedInstance<LLFloaterCamera>("camera");
+    if (camera_floater)
+    {
+        camera_floater->mRotate->setToggleState(gAgentCamera.getOrbitRightKey() > 0.f,  // left
+                                                gAgentCamera.getOrbitUpKey() > 0.f,     // top
+                                                gAgentCamera.getOrbitLeftKey() > 0.f,   // right
+                                                gAgentCamera.getOrbitDownKey() > 0.f);  // bottom
+
+        camera_floater->mTrack->setToggleState(gAgentCamera.getPanLeftKey() > 0.f,      // left
+                                               gAgentCamera.getPanUpKey() > 0.f,            // top
+                                               gAgentCamera.getPanRightKey() > 0.f,     // right
+                                               gAgentCamera.getPanDownKey() > 0.f);     // bottom
+    }
+
+    auto& vwr_camera = LLViewerCamera::instance();
+
+    // Handle camera movement based on keyboard.
+    const F32 ORBIT_OVER_RATE = 90.f * DEG_TO_RAD;          // radians per second
+    const F32 ORBIT_AROUND_RATE = 90.f * DEG_TO_RAD;        // radians per second
+    const F32 PAN_RATE = 5.f;                               // meters per second
+    const F32 ROLL_RATE = 45.f * DEG_TO_RAD;                // radians per second
+
+    if (gAgentCamera.getOrbitUpKey() || gAgentCamera.getOrbitDownKey())
+    {
+        F32 input_rate = gAgentCamera.getOrbitUpKey() - gAgentCamera.getOrbitDownKey();
+        cameraOrbitOver( input_rate * ORBIT_OVER_RATE / gFPSClamped );
+    }
+
+    if (gAgentCamera.getOrbitLeftKey() || gAgentCamera.getOrbitRightKey())
+    {
+        F32 input_rate = gAgentCamera.getOrbitLeftKey() - gAgentCamera.getOrbitRightKey();
+        cameraOrbitAround(input_rate * ORBIT_AROUND_RATE / gFPSClamped);
+    }
+
+    if (gAgentCamera.getOrbitInKey() || gAgentCamera.getOrbitOutKey())
+    {
+        F32 input_rate = gAgentCamera.getOrbitInKey() - gAgentCamera.getOrbitOutKey();
+
+        LLVector3d to_focus = gAgent.getPosGlobalFromAgent(vwr_camera.getOrigin()) - calcFocusPositionTargetGlobal();
+        F32 distance_to_focus = (F32)to_focus.magVec();
+        // Move at distance (in meters) meters per second
+        cameraOrbitIn( input_rate * distance_to_focus / gFPSClamped );
+    }
+
+    if (gAgentCamera.getPanInKey() || gAgentCamera.getPanOutKey())
+    {
+        F32 input_rate = gAgentCamera.getPanInKey() - gAgentCamera.getPanOutKey();
+        cameraPanIn(input_rate * PAN_RATE / gFPSClamped);
+    }
+
+    if (gAgentCamera.getPanRightKey() || gAgentCamera.getPanLeftKey())
+    {
+        F32 input_rate = gAgentCamera.getPanRightKey() - gAgentCamera.getPanLeftKey();
+        cameraPanLeft(input_rate * -PAN_RATE / gFPSClamped );
+    }
+
+    if (gAgentCamera.getPanUpKey() || gAgentCamera.getPanDownKey())
+    {
+        F32 input_rate = gAgentCamera.getPanUpKey() - gAgentCamera.getPanDownKey();
+        cameraPanUp(input_rate * PAN_RATE / gFPSClamped );
+    }
+
+    if (getRollLeftKey() || getRollRightKey())
+    {
+        F32 input_rate = getRollRightKey() - getRollLeftKey();
+        cameraRollOver(input_rate * ROLL_RATE / gFPSClamped);
+    }
+
+    // Clear camera keyboard keys.
+    gAgentCamera.clearOrbitKeys();
+    gAgentCamera.clearPanKeys();
+
+    // lerp camera focus offset
+    mCameraFocusOffset = lerp(mCameraFocusOffset, mCameraFocusOffsetTarget, LLSmoothInterpolation::getInterpolant(CAMERA_FOCUS_HALF_LIFE));
+
+    if ( mCameraMode == CAMERA_MODE_FOLLOW )
+    {
+        if (isAgentAvatarValid())
+        {
+            //--------------------------------------------------------------------------------
+            // this is where the avatar's position and rotation are given to followCam, and
+            // where it is updated. All three of its attributes are updated: (1) position,
+            // (2) focus, and (3) upvector. They can then be queried elsewhere in llAgent.
+            //--------------------------------------------------------------------------------
+            // *TODO: use combined rotation of frameagent and sit object
+            LLQuaternion avatarRotationForFollowCam = gAgentAvatarp->isSitting() ? gAgentAvatarp->getRenderRotation() : gAgent.getFrameAgent().getQuaternion();
+
+            LLFollowCamParams* current_cam = LLFollowCamMgr::getInstance()->getActiveFollowCamParams();
+            if (current_cam)
+            {
+                mFollowCam.copyParams(*current_cam);
+                mFollowCam.setSubjectPositionAndRotation( gAgentAvatarp->getRenderPosition(), avatarRotationForFollowCam );
+                mFollowCam.update();
+                LLViewerJoystick::getInstance()->setCameraNeedsUpdate(true);
+            }
+            else
+            {
+                changeCameraToThirdPerson(TRUE);
+            }
+        }
+    }
+
+    BOOL hit_limit;
+    LLVector3d camera_pos_global;
+    LLVector3d camera_target_global = calcCameraPositionTargetGlobal(&hit_limit);
+    mCameraVirtualPositionAgent = gAgent.getPosAgentFromGlobal(camera_target_global);
+    LLVector3d focus_target_global = calcFocusPositionTargetGlobal();
+
+    // perform field of view correction
+    mCameraFOVZoomFactor = calcCameraFOVZoomFactor();
+    camera_target_global = focus_target_global + (camera_target_global - focus_target_global) * (1.f + mCameraFOVZoomFactor);
+
+    gAgent.setShowAvatar(TRUE); // can see avatar by default
+
+    // Adjust position for animation
+    if (mCameraAnimating)
+    {
+        F32 time = mAnimationTimer.getElapsedTimeF32();
+
+        // yet another instance of critically damped motion, hooray!
+        // F32 fraction_of_animation = 1.f - pow(2.f, -time / CAMERA_ZOOM_HALF_LIFE);
+
+        // linear interpolation
+        F32 fraction_of_animation = time / mAnimationDuration;
+
+        BOOL isfirstPerson = mCameraMode == CAMERA_MODE_MOUSELOOK;
+        BOOL wasfirstPerson = mLastCameraMode == CAMERA_MODE_MOUSELOOK;
+        F32 fraction_animation_to_skip;
+
+        if (mAnimationCameraStartGlobal == camera_target_global)
+        {
+            fraction_animation_to_skip = 0.f;
+        }
+        else
+        {
+            LLVector3d cam_delta = mAnimationCameraStartGlobal - camera_target_global;
+            fraction_animation_to_skip = HEAD_BUFFER_SIZE / (F32)cam_delta.magVec();
+        }
+        F32 animation_start_fraction = (wasfirstPerson) ? fraction_animation_to_skip : 0.f;
+        F32 animation_finish_fraction =  (isfirstPerson) ? (1.f - fraction_animation_to_skip) : 1.f;
+
+        if (fraction_of_animation < animation_finish_fraction)
+        {
+            if (fraction_of_animation < animation_start_fraction || fraction_of_animation > animation_finish_fraction )
+            {
+                gAgent.setShowAvatar(FALSE);
+            }
+
+            // ...adjust position for animation
+            F32 smooth_fraction_of_animation = llsmoothstep(0.0f, 1.0f, fraction_of_animation);
+            camera_pos_global = lerp(mAnimationCameraStartGlobal, camera_target_global, smooth_fraction_of_animation);
+            mFocusGlobal = lerp(mAnimationFocusStartGlobal, focus_target_global, smooth_fraction_of_animation);
+        }
+        else
+        {
+            // ...animation complete
+            mCameraAnimating = FALSE;
+
+            camera_pos_global = camera_target_global;
+            mFocusGlobal = focus_target_global;
+
+            gAgent.endAnimationUpdateUI();
+            gAgent.setShowAvatar(TRUE);
+        }
+
+        if (isAgentAvatarValid() && (mCameraMode != CAMERA_MODE_MOUSELOOK))
+        {
+            gAgentAvatarp->updateAttachmentVisibility(mCameraMode);
+        }
+    }
+    else
+    {
+        camera_pos_global = camera_target_global;
+        mFocusGlobal = focus_target_global;
+        gAgent.setShowAvatar(TRUE);
+    }
+
+    // smoothing
+    if (TRUE)
+    {
+        LLVector3d agent_pos = gAgent.getPositionGlobal();
+        LLVector3d camera_pos_agent = camera_pos_global - agent_pos;
+        // Sitting on what you're manipulating can cause camera jitter with smoothing.
+        // This turns off smoothing while editing. -MG
+        bool in_build_mode = LLToolMgr::getInstance()->inBuildMode();
+        mCameraSmoothingStop = mCameraSmoothingStop || in_build_mode;
+
+        if (cameraThirdPerson() && !mCameraSmoothingStop)
+        {
+            const F32 SMOOTHING_HALF_LIFE = 0.02f;
+
+            static const LLCachedControl<F32> cam_pos_smoothing(gSavedSettings, "CameraPositionSmoothing");
+            F32 smoothing = LLSmoothInterpolation::getInterpolant(cam_pos_smoothing * SMOOTHING_HALF_LIFE, FALSE);
+
+            if (mFocusOnAvatar && !mFocusObject) // we differentiate on avatar mode
+            {
+                // for avatar-relative focus, we smooth in avatar space -
+                // the avatar moves too jerkily w/r/t global space to smooth there.
+
+                LLVector3d delta = camera_pos_agent - mCameraSmoothingLastPositionAgent;
+                if (delta.magVec() < MAX_CAMERA_SMOOTH_DISTANCE)  // only smooth over short distances please
+                {
+                    camera_pos_agent = lerp(mCameraSmoothingLastPositionAgent, camera_pos_agent, smoothing);
+                    camera_pos_global = camera_pos_agent + agent_pos;
+                }
+            }
+            else
+            {
+                LLVector3d delta = camera_pos_global - mCameraSmoothingLastPositionGlobal;
+                if (delta.magVec() < MAX_CAMERA_SMOOTH_DISTANCE) // only smooth over short distances please
+                {
+                    camera_pos_global = lerp(mCameraSmoothingLastPositionGlobal, camera_pos_global, smoothing);
+                }
+            }
+        }
+
+        mCameraSmoothingLastPositionGlobal = camera_pos_global;
+        mCameraSmoothingLastPositionAgent = camera_pos_agent;
+        mCameraSmoothingStop = false;
+    }
+
+
+    mCameraCurrentFOVZoomFactor = ll_lerp(mCameraCurrentFOVZoomFactor, mCameraFOVZoomFactor, LLSmoothInterpolation::getInterpolant(FOV_ZOOM_HALF_LIFE));
+
+//  LL_INFOS() << "Current FOV Zoom: " << mCameraCurrentFOVZoomFactor << " Target FOV Zoom: " << mCameraFOVZoomFactor << " Object penetration: " << mFocusObjectDist << LL_ENDL;
+
+    LLVector3 focus_agent = gAgent.getPosAgentFromGlobal(mFocusGlobal);
+
+    mCameraPositionAgent = gAgent.getPosAgentFromGlobal(camera_pos_global);
+
+    // Move the camera
+    vwr_camera.updateCameraLocation(mCameraPositionAgent, mCameraUpVector, focus_agent);
+    //LLViewerCamera::getInstance()->updateCameraLocation(mCameraPositionAgent, camera_skyward, focus_agent);
+
+    // Change FOV
+    vwr_camera.setView(vwr_camera.getDefaultFOV() / (1.f + mCameraCurrentFOVZoomFactor));
+
+    // follow camera when in customize mode
+    if (cameraCustomizeAvatar())
+    {
+        setLookAt(LOOKAT_TARGET_FOCUS, NULL, mCameraPositionAgent);
+    }
+
+    // update the travel distance stat
+    // this isn't directly related to the camera
+    // but this seemed like the best place to do this
+    LLVector3d global_pos = gAgent.getPositionGlobal();
+    if (!gAgent.getLastPositionGlobal().isExactlyZero())
+    {
+        LLVector3d delta = global_pos - gAgent.getLastPositionGlobal();
+        gAgent.setDistanceTraveled(gAgent.getDistanceTraveled() + delta.magVec());
+    }
+    gAgent.setLastPositionGlobal(global_pos);
+
+    if (LLVOAvatar::sVisibleInFirstPerson && isAgentAvatarValid() && !gAgentAvatarp->isSitting() && cameraMouselook())
+    {
+        LLVector3 head_pos = gAgentAvatarp->mHeadp->getWorldPosition() +
+            LLVector3(0.08f, 0.f, 0.05f) * gAgentAvatarp->mHeadp->getWorldRotation() +
+            LLVector3(0.1f, 0.f, 0.f) * gAgentAvatarp->mPelvisp->getWorldRotation();
+        LLVector3 diff = mCameraPositionAgent - head_pos;
+        diff = diff * ~gAgentAvatarp->mRoot->getWorldRotation();
+
+        LLJoint* torso_joint = gAgentAvatarp->mTorsop;
+        LLJoint* chest_joint = gAgentAvatarp->mChestp;
+        LLVector3 torso_scale = torso_joint->getScale();
+        LLVector3 chest_scale = chest_joint->getScale();
+
+        // shorten avatar skeleton to avoid foot interpenetration
 #if 0 // This screws up mouselook attachments
-		if (!gAgentAvatarp->mInAir)
-		{
-			LLVector3 chest_offset = LLVector3(0.f, 0.f, chest_joint->getPosition().mV[VZ]) * torso_joint->getWorldRotation();
-			F32 z_compensate = llclamp(-diff.mV[VZ], -0.2f, 1.f);
-			F32 scale_factor = llclamp(1.f - ((z_compensate * 0.5f) / chest_offset.mV[VZ]), 0.5f, 1.2f);
-			torso_joint->setScale(LLVector3(1.f, 1.f, scale_factor));
-
-			LLJoint* neck_joint = gAgentAvatarp->mNeckp;
-			LLVector3 neck_offset = LLVector3(0.f, 0.f, neck_joint->getPosition().mV[VZ]) * chest_joint->getWorldRotation();
-			scale_factor = llclamp(1.f - ((z_compensate * 0.5f) / neck_offset.mV[VZ]), 0.5f, 1.2f);
-			chest_joint->setScale(LLVector3(1.f, 1.f, scale_factor));
-			diff.mV[VZ] = 0.f;
-		}
+        if (!gAgentAvatarp->mInAir)
+        {
+            LLVector3 chest_offset = LLVector3(0.f, 0.f, chest_joint->getPosition().mV[VZ]) * torso_joint->getWorldRotation();
+            F32 z_compensate = llclamp(-diff.mV[VZ], -0.2f, 1.f);
+            F32 scale_factor = llclamp(1.f - ((z_compensate * 0.5f) / chest_offset.mV[VZ]), 0.5f, 1.2f);
+            torso_joint->setScale(LLVector3(1.f, 1.f, scale_factor));
+
+            LLJoint* neck_joint = gAgentAvatarp->mNeckp;
+            LLVector3 neck_offset = LLVector3(0.f, 0.f, neck_joint->getPosition().mV[VZ]) * chest_joint->getWorldRotation();
+            scale_factor = llclamp(1.f - ((z_compensate * 0.5f) / neck_offset.mV[VZ]), 0.5f, 1.2f);
+            chest_joint->setScale(LLVector3(1.f, 1.f, scale_factor));
+            diff.mV[VZ] = 0.f;
+        }
 #endif
 
-		if (useRealisticMouselook)
-		{
-			auto frame_agent = gAgent.getFrameAgent();
-			LLQuaternion agent_rot(frame_agent.getQuaternion());
-			auto avatarp_parent = (LLViewerObject*)gAgentAvatarp->getParent();
-			if(avatarp_parent)
-			{
-				auto avatarp_root = (LLViewerObject*)gAgentAvatarp->getRoot();
-				if(avatarp_root)
-				{
-					auto decoupled = avatarp_root->flagCameraDecoupled();
-					if(decoupled)
-					{
-						agent_rot *= avatarp_parent->getRenderRotation();
-					}
-					
-				}
-			}
-
-			vwr_camera.updateCameraLocation(head_pos, mCameraUpVector, gAgentAvatarp->mHeadp->getWorldPosition() + LLVector3(1.0, 0.0, 0.0) * agent_rot);
-		}
-		else
-		{
-			// SL-315
-			gAgentAvatarp->mPelvisp->setPosition(gAgentAvatarp->mPelvisp->getPosition() + diff);
-		}
-
-		gAgentAvatarp->mRoot->updateWorldMatrixChildren();
-
-		for (auto& attach_point_pair : gAgentAvatarp->mAttachmentPoints)
-		{
+        if (useRealisticMouselook)
+        {
+            auto frame_agent = gAgent.getFrameAgent();
+            LLQuaternion agent_rot(frame_agent.getQuaternion());
+            auto avatarp_parent = (LLViewerObject*)gAgentAvatarp->getParent();
+            if(avatarp_parent)
+            {
+                auto avatarp_root = (LLViewerObject*)gAgentAvatarp->getRoot();
+                if(avatarp_root)
+                {
+                    auto decoupled = avatarp_root->flagCameraDecoupled();
+                    if(decoupled)
+                    {
+                        agent_rot *= avatarp_parent->getRenderRotation();
+                    }
+
+                }
+            }
+
+            vwr_camera.updateCameraLocation(head_pos, mCameraUpVector, gAgentAvatarp->mHeadp->getWorldPosition() + LLVector3(1.0, 0.0, 0.0) * agent_rot);
+        }
+        else
+        {
+            // SL-315
+            gAgentAvatarp->mPelvisp->setPosition(gAgentAvatarp->mPelvisp->getPosition() + diff);
+        }
+
+        gAgentAvatarp->mRoot->updateWorldMatrixChildren();
+
+        for (auto& attach_point_pair : gAgentAvatarp->mAttachmentPoints)
+        {
             LLViewerJointAttachment* attachment = attach_point_pair.second;
             for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-			{
-				if (attached_object && !attached_object->isDead() && attached_object->mDrawable.notNull())
-				{
-					// clear any existing "early" movements of attachment
-					attached_object->mDrawable->clearState(LLDrawable::EARLY_MOVE);
-					gPipeline.updateMoveNormalAsync(attached_object->mDrawable);
-					attached_object->updateText();
-				}
-			}
-		}
-
-		torso_joint->setScale(torso_scale);
-		chest_joint->setScale(chest_scale);
-	}
-
-	//     We have do this at the very end to make sure it takes all previous calculations into
-	//     account and then applies our roll on top of it, besides it wouldn't even work otherwise.
-	LLQuaternion rot_quat = vwr_camera.getQuaternion();
-	LLMatrix3 rot_mat(mRollAngle, 0.f, 0.f);
-	rot_quat = LLQuaternion(rot_mat)*rot_quat;
-	
-	LLMatrix3 mat(rot_quat);
-	
-	vwr_camera.mXAxis = LLVector3(mat.mMatrix[0]);
-	vwr_camera.mYAxis = LLVector3(mat.mMatrix[1]);
-	vwr_camera.mZAxis = LLVector3(mat.mMatrix[2]);
+            {
+                if (attached_object && !attached_object->isDead() && attached_object->mDrawable.notNull())
+                {
+                    // clear any existing "early" movements of attachment
+                    attached_object->mDrawable->clearState(LLDrawable::EARLY_MOVE);
+                    gPipeline.updateMoveNormalAsync(attached_object->mDrawable);
+                    attached_object->updateText();
+                }
+            }
+        }
+
+        torso_joint->setScale(torso_scale);
+        chest_joint->setScale(chest_scale);
+    }
+
+    //     We have do this at the very end to make sure it takes all previous calculations into
+    //     account and then applies our roll on top of it, besides it wouldn't even work otherwise.
+    LLQuaternion rot_quat = vwr_camera.getQuaternion();
+    LLMatrix3 rot_mat(mRollAngle, 0.f, 0.f);
+    rot_quat = LLQuaternion(rot_mat)*rot_quat;
+
+    LLMatrix3 mat(rot_quat);
+
+    vwr_camera.mXAxis = LLVector3(mat.mMatrix[0]);
+    vwr_camera.mYAxis = LLVector3(mat.mMatrix[1]);
+    vwr_camera.mZAxis = LLVector3(mat.mMatrix[2]);
 }
 
 void LLAgentCamera::updateLastCamera()
 {
-	mLastCameraMode = mCameraMode;
+    mLastCameraMode = mCameraMode;
 }
 
 void LLAgentCamera::updateFocusOffset()
 {
-	validateFocusObject();
-	if (mFocusObject.notNull())
-	{
-		LLVector3d obj_pos = gAgent.getPosGlobalFromAgent(mFocusObject->getRenderPosition());
-		mFocusObjectOffset.setVec(mFocusTargetGlobal - obj_pos);
-	}
+    validateFocusObject();
+    if (mFocusObject.notNull())
+    {
+        LLVector3d obj_pos = gAgent.getPosGlobalFromAgent(mFocusObject->getRenderPosition());
+        mFocusObjectOffset.setVec(mFocusTargetGlobal - obj_pos);
+    }
 }
 
 void LLAgentCamera::validateFocusObject()
 {
-	if (mFocusObject.notNull() && 
-		mFocusObject->isDead())
-	{
-		mFocusObjectOffset.clearVec();
-		clearFocusObject();
-		mCameraFOVZoomFactor = 0.f;
-	}
+    if (mFocusObject.notNull() &&
+        mFocusObject->isDead())
+    {
+        mFocusObjectOffset.clearVec();
+        clearFocusObject();
+        mCameraFOVZoomFactor = 0.f;
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1679,127 +1679,127 @@ void LLAgentCamera::validateFocusObject()
 //-----------------------------------------------------------------------------
 LLVector3d LLAgentCamera::calcFocusPositionTargetGlobal()
 {
-	if (mFocusObject.notNull() && mFocusObject->isDead())
-	{
-		clearFocusObject();
-	}
-
-	if (mCameraMode == CAMERA_MODE_FOLLOW && mFocusOnAvatar)
-	{
-		mFocusTargetGlobal = gAgent.getPosGlobalFromAgent(mFollowCam.getSimulatedFocus());
-		return mFocusTargetGlobal;
-	}
-	else if (mCameraMode == CAMERA_MODE_MOUSELOOK)
-	{
-		LLVector3d at_axis(1.0, 0.0, 0.0);
-		LLQuaternion agent_rot = gAgent.getFrameAgent().getQuaternion();
-		if (isAgentAvatarValid() && gAgentAvatarp->getParent())
-		{
-			LLViewerObject* root_object = (LLViewerObject*)gAgentAvatarp->getRoot();
-			if (!root_object->flagCameraDecoupled())
-			{
-				agent_rot *= ((LLViewerObject*)(gAgentAvatarp->getParent()))->getRenderRotation();
-			}
-		}
-		at_axis = at_axis * agent_rot;
-		mFocusTargetGlobal = calcCameraPositionTargetGlobal() + at_axis;
-		return mFocusTargetGlobal;
-	}
-	else if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR)
-	{
-		if (mFocusOnAvatar)
-		{
-			LLVector3 focus_target = isAgentAvatarValid()
-				? gAgentAvatarp->mHeadp->getWorldPosition()
-				: gAgent.getPositionAgent();
-			LLVector3d focus_target_global = gAgent.getPosGlobalFromAgent(focus_target);
-			mFocusTargetGlobal = focus_target_global;
-		}
-		return mFocusTargetGlobal;
-	}
-	else if (!mFocusOnAvatar)
-	{
-		if (mFocusObject.notNull() && !mFocusObject->isDead() && mFocusObject->mDrawable.notNull())
-		{
-			LLDrawable* drawablep = mFocusObject->mDrawable;
-			
-			if (mTrackFocusObject &&
-				drawablep && 
-				drawablep->isActive())
-			{
-				if (!mFocusObject->isAvatar())
-				{
-					if (mFocusObject->isSelected())
-					{
-						gPipeline.updateMoveNormalAsync(drawablep);
-					}
-					else
-					{
-						if (drawablep->isState(LLDrawable::MOVE_UNDAMPED))
-						{
-							gPipeline.updateMoveNormalAsync(drawablep);
-						}
-						else
-						{
-							gPipeline.updateMoveDampedAsync(drawablep);
-						}
-					}
-				}
-			}
-			// if not tracking object, update offset based on new object position
-			else
-			{
-				updateFocusOffset();
-			}
-			LLVector3 focus_agent = mFocusObject->getRenderPosition() + mFocusObjectOffset;
-			mFocusTargetGlobal.setVec(gAgent.getPosGlobalFromAgent(focus_agent));
-		}
-		return mFocusTargetGlobal;
-	}
-	else if (mSitCameraEnabled && isAgentAvatarValid() && gAgentAvatarp->isSitting() && mSitCameraReferenceObject.notNull())
-	{
-		// sit camera
-		LLVector3 object_pos = mSitCameraReferenceObject->getRenderPosition();
-		LLQuaternion object_rot = mSitCameraReferenceObject->getRenderRotation();
-
-		LLVector3 target_pos = object_pos + (mSitCameraFocus * object_rot);
-		return gAgent.getPosGlobalFromAgent(target_pos);
-	}
-	else
-	{
-		return gAgent.getPositionGlobal() + calcThirdPersonFocusOffset();
-	}
+    if (mFocusObject.notNull() && mFocusObject->isDead())
+    {
+        clearFocusObject();
+    }
+
+    if (mCameraMode == CAMERA_MODE_FOLLOW && mFocusOnAvatar)
+    {
+        mFocusTargetGlobal = gAgent.getPosGlobalFromAgent(mFollowCam.getSimulatedFocus());
+        return mFocusTargetGlobal;
+    }
+    else if (mCameraMode == CAMERA_MODE_MOUSELOOK)
+    {
+        LLVector3d at_axis(1.0, 0.0, 0.0);
+        LLQuaternion agent_rot = gAgent.getFrameAgent().getQuaternion();
+        if (isAgentAvatarValid() && gAgentAvatarp->getParent())
+        {
+            LLViewerObject* root_object = (LLViewerObject*)gAgentAvatarp->getRoot();
+            if (!root_object->flagCameraDecoupled())
+            {
+                agent_rot *= ((LLViewerObject*)(gAgentAvatarp->getParent()))->getRenderRotation();
+            }
+        }
+        at_axis = at_axis * agent_rot;
+        mFocusTargetGlobal = calcCameraPositionTargetGlobal() + at_axis;
+        return mFocusTargetGlobal;
+    }
+    else if (mCameraMode == CAMERA_MODE_CUSTOMIZE_AVATAR)
+    {
+        if (mFocusOnAvatar)
+        {
+            LLVector3 focus_target = isAgentAvatarValid()
+                ? gAgentAvatarp->mHeadp->getWorldPosition()
+                : gAgent.getPositionAgent();
+            LLVector3d focus_target_global = gAgent.getPosGlobalFromAgent(focus_target);
+            mFocusTargetGlobal = focus_target_global;
+        }
+        return mFocusTargetGlobal;
+    }
+    else if (!mFocusOnAvatar)
+    {
+        if (mFocusObject.notNull() && !mFocusObject->isDead() && mFocusObject->mDrawable.notNull())
+        {
+            LLDrawable* drawablep = mFocusObject->mDrawable;
+
+            if (mTrackFocusObject &&
+                drawablep &&
+                drawablep->isActive())
+            {
+                if (!mFocusObject->isAvatar())
+                {
+                    if (mFocusObject->isSelected())
+                    {
+                        gPipeline.updateMoveNormalAsync(drawablep);
+                    }
+                    else
+                    {
+                        if (drawablep->isState(LLDrawable::MOVE_UNDAMPED))
+                        {
+                            gPipeline.updateMoveNormalAsync(drawablep);
+                        }
+                        else
+                        {
+                            gPipeline.updateMoveDampedAsync(drawablep);
+                        }
+                    }
+                }
+            }
+            // if not tracking object, update offset based on new object position
+            else
+            {
+                updateFocusOffset();
+            }
+            LLVector3 focus_agent = mFocusObject->getRenderPosition() + mFocusObjectOffset;
+            mFocusTargetGlobal.setVec(gAgent.getPosGlobalFromAgent(focus_agent));
+        }
+        return mFocusTargetGlobal;
+    }
+    else if (mSitCameraEnabled && isAgentAvatarValid() && gAgentAvatarp->isSitting() && mSitCameraReferenceObject.notNull())
+    {
+        // sit camera
+        LLVector3 object_pos = mSitCameraReferenceObject->getRenderPosition();
+        LLQuaternion object_rot = mSitCameraReferenceObject->getRenderRotation();
+
+        LLVector3 target_pos = object_pos + (mSitCameraFocus * object_rot);
+        return gAgent.getPosGlobalFromAgent(target_pos);
+    }
+    else
+    {
+        return gAgent.getPositionGlobal() + calcThirdPersonFocusOffset();
+    }
 }
 
 LLVector3d LLAgentCamera::calcThirdPersonFocusOffset()
 {
-	// ...offset from avatar
-	LLVector3d focus_offset_initial;
-	LLQuaternion agent_rot = gAgent.getFrameAgent().getQuaternion();
-	if (isAgentAvatarValid() && gAgentAvatarp->getParent())
-	{
-		agent_rot *= ((LLViewerObject*)(gAgentAvatarp->getParent()))->getRenderRotation();
-	}
+    // ...offset from avatar
+    LLVector3d focus_offset_initial;
+    LLQuaternion agent_rot = gAgent.getFrameAgent().getQuaternion();
+    if (isAgentAvatarValid() && gAgentAvatarp->getParent())
+    {
+        agent_rot *= ((LLViewerObject*)(gAgentAvatarp->getParent()))->getRenderRotation();
+    }
 
 // [RLVa:KB] - @setcam_focusoffset
     return getFocusOffsetInitial() * agent_rot;
 // [/RLVa:KB]
 //    static LLCachedControl<LLVector3d> focus_offset_initial(gSavedSettings, "FocusOffsetRearView", LLVector3d());
-//	return focus_offset_initial * agent_rot;
+//  return focus_offset_initial * agent_rot;
 }
 
 void LLAgentCamera::setupSitCamera()
 {
-	// agent frame entering this function is in world coordinates
-	if (isAgentAvatarValid() && gAgentAvatarp->getParent())
-	{
-		LLQuaternion parent_rot = ((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation();
-		// slam agent coordinate frame to proper parent local version
-		LLVector3 at_axis = gAgent.getFrameAgent().getAtAxis();
-		at_axis.mV[VZ] = 0.f;
-		at_axis.normalize();
-		gAgent.resetAxes(at_axis * ~parent_rot);
-	}
+    // agent frame entering this function is in world coordinates
+    if (isAgentAvatarValid() && gAgentAvatarp->getParent())
+    {
+        LLQuaternion parent_rot = ((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation();
+        // slam agent coordinate frame to proper parent local version
+        LLVector3 at_axis = gAgent.getFrameAgent().getAtAxis();
+        at_axis.mV[VZ] = 0.f;
+        at_axis.normalize();
+        gAgent.resetAxes(at_axis * ~parent_rot);
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1807,7 +1807,7 @@ void LLAgentCamera::setupSitCamera()
 //-----------------------------------------------------------------------------
 const LLVector3 &LLAgentCamera::getCameraPositionAgent() const
 {
-	return LLViewerCamera::getInstance()->getOrigin();
+    return LLViewerCamera::getInstance()->getOrigin();
 }
 
 //-----------------------------------------------------------------------------
@@ -1815,43 +1815,43 @@ const LLVector3 &LLAgentCamera::getCameraPositionAgent() const
 //-----------------------------------------------------------------------------
 LLVector3d LLAgentCamera::getCameraPositionGlobal() const
 {
-	return gAgent.getPosGlobalFromAgent(LLViewerCamera::getInstance()->getOrigin());
+    return gAgent.getPosGlobalFromAgent(LLViewerCamera::getInstance()->getOrigin());
 }
 
 //-----------------------------------------------------------------------------
 // calcCameraFOVZoomFactor()
 //-----------------------------------------------------------------------------
-F32	LLAgentCamera::calcCameraFOVZoomFactor()
+F32 LLAgentCamera::calcCameraFOVZoomFactor()
 {
-	LLVector3 camera_offset_dir;
-	camera_offset_dir.setVec(mCameraFocusOffset);
+    LLVector3 camera_offset_dir;
+    camera_offset_dir.setVec(mCameraFocusOffset);
 
-	if (mCameraMode == CAMERA_MODE_MOUSELOOK)
-	{
-		return 0.f;
-	}
-	else if (mFocusObject.notNull() && !mFocusObject->isAvatar() && !mFocusOnAvatar)
-	{
-		// don't FOV zoom on mostly transparent objects
-		F32 obj_min_dist = 0.f;
-		static LLCachedControl<bool> disable_camera_limits(gSavedSettings, "AlchemyCameraNoZoomLimit", false);
-		if (!disable_camera_limits)
-		{
-			calcCameraMinDistance(obj_min_dist);
-		}
-		F32 current_distance = llmax(0.001f, camera_offset_dir.magVec());
+    if (mCameraMode == CAMERA_MODE_MOUSELOOK)
+    {
+        return 0.f;
+    }
+    else if (mFocusObject.notNull() && !mFocusObject->isAvatar() && !mFocusOnAvatar)
+    {
+        // don't FOV zoom on mostly transparent objects
+        F32 obj_min_dist = 0.f;
+        static LLCachedControl<bool> disable_camera_limits(gSavedSettings, "AlchemyCameraNoZoomLimit", false);
+        if (!disable_camera_limits)
+        {
+            calcCameraMinDistance(obj_min_dist);
+        }
+        F32 current_distance = llmax(0.001f, camera_offset_dir.magVec());
 
-		mFocusObjectDist = obj_min_dist - current_distance;
+        mFocusObjectDist = obj_min_dist - current_distance;
 
-		F32 new_fov_zoom = llclamp(mFocusObjectDist / current_distance, 0.f, 1000.f);
-		return new_fov_zoom;
-	}
-	else // focusing on land or avatar
-	{
-		// keep old field of view until user changes focus explicitly
-		return mCameraFOVZoomFactor;
-		//return 0.f;
-	}
+        F32 new_fov_zoom = llclamp(mFocusObjectDist / current_distance, 0.f, 1000.f);
+        return new_fov_zoom;
+    }
+    else // focusing on land or avatar
+    {
+        // keep old field of view until user changes focus explicitly
+        return mCameraFOVZoomFactor;
+        //return 0.f;
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1859,384 +1859,384 @@ F32	LLAgentCamera::calcCameraFOVZoomFactor()
 //-----------------------------------------------------------------------------
 LLVector3d LLAgentCamera::calcCameraPositionTargetGlobal(BOOL *hit_limit)
 {
-	// Compute base camera position and look-at points.
-	F32			camera_land_height;
-	LLVector3d	frame_center_global = !isAgentAvatarValid() ? 
-		gAgent.getPositionGlobal() :
-		gAgent.getPosGlobalFromAgent(getAvatarRootPosition());
-	
-	BOOL		isConstrained = FALSE;
-	LLVector3d	head_offset;
-	head_offset.setVec(mThirdPersonHeadOffset);
-
-	LLVector3d camera_position_global;
-
-	if (mCameraMode == CAMERA_MODE_FOLLOW && mFocusOnAvatar)
-	{
-		camera_position_global = gAgent.getPosGlobalFromAgent(mFollowCam.getSimulatedPosition());
-	}
-	else if (mCameraMode == CAMERA_MODE_MOUSELOOK)
-	{
-		if (!isAgentAvatarValid() || gAgentAvatarp->mDrawable.isNull())
-		{
-			LL_WARNS() << "Null avatar drawable!" << LL_ENDL;
-			return LLVector3d::zero;
-		}
-
-		head_offset.clearVec();
-		F32 fixup;
+    // Compute base camera position and look-at points.
+    F32         camera_land_height;
+    LLVector3d  frame_center_global = !isAgentAvatarValid() ?
+        gAgent.getPositionGlobal() :
+        gAgent.getPosGlobalFromAgent(getAvatarRootPosition());
+
+    BOOL        isConstrained = FALSE;
+    LLVector3d  head_offset;
+    head_offset.setVec(mThirdPersonHeadOffset);
+
+    LLVector3d camera_position_global;
+
+    if (mCameraMode == CAMERA_MODE_FOLLOW && mFocusOnAvatar)
+    {
+        camera_position_global = gAgent.getPosGlobalFromAgent(mFollowCam.getSimulatedPosition());
+    }
+    else if (mCameraMode == CAMERA_MODE_MOUSELOOK)
+    {
+        if (!isAgentAvatarValid() || gAgentAvatarp->mDrawable.isNull())
+        {
+            LL_WARNS() << "Null avatar drawable!" << LL_ENDL;
+            return LLVector3d::zero;
+        }
+
+        head_offset.clearVec();
+        F32 fixup;
         if (gAgentAvatarp->hasPelvisFixup(fixup) && !gAgentAvatarp->isSitting())
-		{
-			head_offset[VZ] -= fixup;
-		}
-		if (gAgentAvatarp->isSitting())
-		{
-			head_offset.mdV[VZ] += 0.1;
-		}
-
-		if (gAgentAvatarp->isSitting() && gAgentAvatarp->getParent())
-		{
-			gAgentAvatarp->updateHeadOffset();
-			head_offset.mdV[VX] += gAgentAvatarp->mHeadOffset.mV[VX];
-			head_offset.mdV[VY] += gAgentAvatarp->mHeadOffset.mV[VY];
-			head_offset.mdV[VZ] += gAgentAvatarp->mHeadOffset.mV[VZ];
-			const LLMatrix4 mat(((LLViewerObject*) gAgentAvatarp->getParent())->getRenderMatrix().getF32ptr());
-			camera_position_global = gAgent.getPosGlobalFromAgent
-								((gAgentAvatarp->getPosition()+
-								 LLVector3(head_offset)*gAgentAvatarp->getRotation()) * mat);
-		}
-		else
-		{
-			head_offset.mdV[VZ] += gAgentAvatarp->mHeadOffset.mV[VZ];
-			camera_position_global = gAgent.getPosGlobalFromAgent(gAgentAvatarp->getRenderPosition());//frame_center_global;
-			head_offset = head_offset * gAgentAvatarp->getRenderRotation();
-			camera_position_global = camera_position_global + head_offset;
-		}
-	}
-	else if (mCameraMode == CAMERA_MODE_THIRD_PERSON && mFocusOnAvatar)
-	{
-		LLVector3 local_camera_offset;
-		F32 camera_distance = 0.f;
-
-		if (mSitCameraEnabled 
-			&& isAgentAvatarValid() 
-			&& gAgentAvatarp->isSitting() 
-			&& mSitCameraReferenceObject.notNull())
-		{
-			// sit camera
-			LLVector3 object_pos = mSitCameraReferenceObject->getRenderPosition();
-			LLQuaternion object_rot = mSitCameraReferenceObject->getRenderRotation();
-
-			LLVector3 target_pos = object_pos + (mSitCameraPos * object_rot);
-
-			camera_position_global = gAgent.getPosGlobalFromAgent(target_pos);
-		}
-		else
-		{
+        {
+            head_offset[VZ] -= fixup;
+        }
+        if (gAgentAvatarp->isSitting())
+        {
+            head_offset.mdV[VZ] += 0.1;
+        }
+
+        if (gAgentAvatarp->isSitting() && gAgentAvatarp->getParent())
+        {
+            gAgentAvatarp->updateHeadOffset();
+            head_offset.mdV[VX] += gAgentAvatarp->mHeadOffset.mV[VX];
+            head_offset.mdV[VY] += gAgentAvatarp->mHeadOffset.mV[VY];
+            head_offset.mdV[VZ] += gAgentAvatarp->mHeadOffset.mV[VZ];
+            const LLMatrix4 mat(((LLViewerObject*) gAgentAvatarp->getParent())->getRenderMatrix().getF32ptr());
+            camera_position_global = gAgent.getPosGlobalFromAgent
+                                ((gAgentAvatarp->getPosition()+
+                                 LLVector3(head_offset)*gAgentAvatarp->getRotation()) * mat);
+        }
+        else
+        {
+            head_offset.mdV[VZ] += gAgentAvatarp->mHeadOffset.mV[VZ];
+            camera_position_global = gAgent.getPosGlobalFromAgent(gAgentAvatarp->getRenderPosition());//frame_center_global;
+            head_offset = head_offset * gAgentAvatarp->getRenderRotation();
+            camera_position_global = camera_position_global + head_offset;
+        }
+    }
+    else if (mCameraMode == CAMERA_MODE_THIRD_PERSON && mFocusOnAvatar)
+    {
+        LLVector3 local_camera_offset;
+        F32 camera_distance = 0.f;
+
+        if (mSitCameraEnabled
+            && isAgentAvatarValid()
+            && gAgentAvatarp->isSitting()
+            && mSitCameraReferenceObject.notNull())
+        {
+            // sit camera
+            LLVector3 object_pos = mSitCameraReferenceObject->getRenderPosition();
+            LLQuaternion object_rot = mSitCameraReferenceObject->getRenderRotation();
+
+            LLVector3 target_pos = object_pos + (mSitCameraPos * object_rot);
+
+            camera_position_global = gAgent.getPosGlobalFromAgent(target_pos);
+        }
+        else
+        {
 // [RLVa:KB] - @setcam_eyeoffsetscale
             local_camera_offset = mCameraZoomFraction * getCameraOffsetInitial() * getCameraOffsetScale();
 // [/RLVa:KB]
 //            static LLCachedControl<F32> camera_offset_scale(gSavedSettings, "CameraOffsetScale");
 //            local_camera_offset = mCameraZoomFraction * getCameraOffsetInitial() * camera_offset_scale;
 
-			// are we sitting down?
-			if (isAgentAvatarValid() && gAgentAvatarp->getParent())
-			{
-				LLQuaternion parent_rot = ((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation();
-				// slam agent coordinate frame to proper parent local version
-				LLVector3 at_axis = gAgent.getFrameAgent().getAtAxis() * parent_rot;
-				at_axis.mV[VZ] = 0.f;
-				at_axis.normalize();
-				gAgent.resetAxes(at_axis * ~parent_rot);
-				
-				local_camera_offset = local_camera_offset * gAgent.getFrameAgent().getQuaternion() * parent_rot;
-			}
-			else
-			{
-				local_camera_offset = gAgent.getFrameAgent().rotateToAbsolute( local_camera_offset );
-			}
-
-			if (!isDisableCameraConstraints() && !mCameraCollidePlane.isExactlyZero() &&
-				(!isAgentAvatarValid() || !gAgentAvatarp->isSitting()))
-			{
-				LLVector3 plane_normal;
-				plane_normal.setVec(mCameraCollidePlane.mV);
-
-				F32 offset_dot_norm = local_camera_offset * plane_normal;
-				if (llabs(offset_dot_norm) < 0.001f)
-				{
-					offset_dot_norm = 0.001f;
-				}
-				
-				camera_distance = local_camera_offset.normalize();
-
-				F32 pos_dot_norm = gAgent.getPosAgentFromGlobal(frame_center_global + head_offset) * plane_normal;
-				
-				// if agent is outside the colliding half-plane
-				if (pos_dot_norm > mCameraCollidePlane.mV[VW])
-				{
-					// check to see if camera is on the opposite side (inside) the half-plane
-					if (offset_dot_norm + pos_dot_norm < mCameraCollidePlane.mV[VW])
-					{
-						// diminish offset by factor to push it back outside the half-plane
-						camera_distance *= (pos_dot_norm - mCameraCollidePlane.mV[VW] - CAMERA_COLLIDE_EPSILON) / -offset_dot_norm;
-					}
-				}
-				else
-				{
-					if (offset_dot_norm + pos_dot_norm > mCameraCollidePlane.mV[VW])
-					{
-						camera_distance *= (mCameraCollidePlane.mV[VW] - pos_dot_norm - CAMERA_COLLIDE_EPSILON) / offset_dot_norm;
-					}
-				}
-			}
-			else
-			{
-				camera_distance = local_camera_offset.normalize();
-			}
-
-			mTargetCameraDistance = llmax(camera_distance, MIN_CAMERA_DISTANCE);
-
-			if (mTargetCameraDistance != mCurrentCameraDistance)
-			{
-				F32 camera_lerp_amt = LLSmoothInterpolation::getInterpolant(CAMERA_ZOOM_HALF_LIFE);
-
-				mCurrentCameraDistance = ll_lerp(mCurrentCameraDistance, mTargetCameraDistance, camera_lerp_amt);
-			}
-
-			// Make the camera distance current
-			local_camera_offset *= mCurrentCameraDistance;
-
-			// set the global camera position
-			LLVector3d camera_offset;
-			
-			camera_offset.setVec( local_camera_offset );
-			camera_position_global = frame_center_global + head_offset + camera_offset;
-
-			if (isAgentAvatarValid())
-			{
-				LLVector3d camera_lag_d;
-				F32 lag_interp = LLSmoothInterpolation::getInterpolant(CAMERA_LAG_HALF_LIFE);
-				LLVector3 target_lag;
-				LLVector3 vel = gAgent.getVelocity();
-
-				// lag by appropriate amount for flying
-				F32 time_in_air = gAgentAvatarp->mTimeInAir.getElapsedTimeF32();
-				if(!mCameraAnimating && gAgentAvatarp->mInAir && time_in_air > GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME)
-				{
-					LLVector3 frame_at_axis = gAgent.getFrameAgent().getAtAxis();
-					frame_at_axis -= projected_vec(frame_at_axis, gAgent.getReferenceUpVector());
-					frame_at_axis.normalize();
-
-					//transition smoothly in air mode, to avoid camera pop
-					F32 u = (time_in_air - GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME) / GROUND_TO_AIR_CAMERA_TRANSITION_TIME;
-					u = llclamp(u, 0.f, 1.f);
-
-					lag_interp *= u;
-
-					if (gViewerWindow->getLeftMouseDown() && gViewerWindow->getLastPick().mObjectID == gAgentAvatarp->getID())
-					{
-						// disable camera lag when using mouse-directed steering
-						target_lag.clearVec();
-					}
-					else
-					{
+            // are we sitting down?
+            if (isAgentAvatarValid() && gAgentAvatarp->getParent())
+            {
+                LLQuaternion parent_rot = ((LLViewerObject*)gAgentAvatarp->getParent())->getRenderRotation();
+                // slam agent coordinate frame to proper parent local version
+                LLVector3 at_axis = gAgent.getFrameAgent().getAtAxis() * parent_rot;
+                at_axis.mV[VZ] = 0.f;
+                at_axis.normalize();
+                gAgent.resetAxes(at_axis * ~parent_rot);
+
+                local_camera_offset = local_camera_offset * gAgent.getFrameAgent().getQuaternion() * parent_rot;
+            }
+            else
+            {
+                local_camera_offset = gAgent.getFrameAgent().rotateToAbsolute( local_camera_offset );
+            }
+
+            if (!isDisableCameraConstraints() && !mCameraCollidePlane.isExactlyZero() &&
+                (!isAgentAvatarValid() || !gAgentAvatarp->isSitting()))
+            {
+                LLVector3 plane_normal;
+                plane_normal.setVec(mCameraCollidePlane.mV);
+
+                F32 offset_dot_norm = local_camera_offset * plane_normal;
+                if (llabs(offset_dot_norm) < 0.001f)
+                {
+                    offset_dot_norm = 0.001f;
+                }
+
+                camera_distance = local_camera_offset.normalize();
+
+                F32 pos_dot_norm = gAgent.getPosAgentFromGlobal(frame_center_global + head_offset) * plane_normal;
+
+                // if agent is outside the colliding half-plane
+                if (pos_dot_norm > mCameraCollidePlane.mV[VW])
+                {
+                    // check to see if camera is on the opposite side (inside) the half-plane
+                    if (offset_dot_norm + pos_dot_norm < mCameraCollidePlane.mV[VW])
+                    {
+                        // diminish offset by factor to push it back outside the half-plane
+                        camera_distance *= (pos_dot_norm - mCameraCollidePlane.mV[VW] - CAMERA_COLLIDE_EPSILON) / -offset_dot_norm;
+                    }
+                }
+                else
+                {
+                    if (offset_dot_norm + pos_dot_norm > mCameraCollidePlane.mV[VW])
+                    {
+                        camera_distance *= (mCameraCollidePlane.mV[VW] - pos_dot_norm - CAMERA_COLLIDE_EPSILON) / offset_dot_norm;
+                    }
+                }
+            }
+            else
+            {
+                camera_distance = local_camera_offset.normalize();
+            }
+
+            mTargetCameraDistance = llmax(camera_distance, MIN_CAMERA_DISTANCE);
+
+            if (mTargetCameraDistance != mCurrentCameraDistance)
+            {
+                F32 camera_lerp_amt = LLSmoothInterpolation::getInterpolant(CAMERA_ZOOM_HALF_LIFE);
+
+                mCurrentCameraDistance = ll_lerp(mCurrentCameraDistance, mTargetCameraDistance, camera_lerp_amt);
+            }
+
+            // Make the camera distance current
+            local_camera_offset *= mCurrentCameraDistance;
+
+            // set the global camera position
+            LLVector3d camera_offset;
+
+            camera_offset.setVec( local_camera_offset );
+            camera_position_global = frame_center_global + head_offset + camera_offset;
+
+            if (isAgentAvatarValid())
+            {
+                LLVector3d camera_lag_d;
+                F32 lag_interp = LLSmoothInterpolation::getInterpolant(CAMERA_LAG_HALF_LIFE);
+                LLVector3 target_lag;
+                LLVector3 vel = gAgent.getVelocity();
+
+                // lag by appropriate amount for flying
+                F32 time_in_air = gAgentAvatarp->mTimeInAir.getElapsedTimeF32();
+                if(!mCameraAnimating && gAgentAvatarp->mInAir && time_in_air > GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME)
+                {
+                    LLVector3 frame_at_axis = gAgent.getFrameAgent().getAtAxis();
+                    frame_at_axis -= projected_vec(frame_at_axis, gAgent.getReferenceUpVector());
+                    frame_at_axis.normalize();
+
+                    //transition smoothly in air mode, to avoid camera pop
+                    F32 u = (time_in_air - GROUND_TO_AIR_CAMERA_TRANSITION_START_TIME) / GROUND_TO_AIR_CAMERA_TRANSITION_TIME;
+                    u = llclamp(u, 0.f, 1.f);
+
+                    lag_interp *= u;
+
+                    if (gViewerWindow->getLeftMouseDown() && gViewerWindow->getLastPick().mObjectID == gAgentAvatarp->getID())
+                    {
+                        // disable camera lag when using mouse-directed steering
+                        target_lag.clearVec();
+                    }
+                    else
+                    {
                         LLCachedControl<F32> dynamic_camera_strength(gSavedSettings, "DynamicCameraStrength");
                         target_lag = vel * dynamic_camera_strength / 30.f;
-					}
-
-					mCameraLag = lerp(mCameraLag, target_lag, lag_interp);
-
-					F32 lag_dist = mCameraLag.magVec();
-					if (lag_dist > MAX_CAMERA_LAG)
-					{
-						mCameraLag = mCameraLag * MAX_CAMERA_LAG / lag_dist;
-					}
-
-					// clamp camera lag so that avatar is always in front
-					F32 dot = (mCameraLag - (frame_at_axis * (MIN_CAMERA_LAG * u))) * frame_at_axis;
-					if (dot < -(MIN_CAMERA_LAG * u))
-					{
-						mCameraLag -= (dot + (MIN_CAMERA_LAG * u)) * frame_at_axis;
-					}
-				}
-				else
-				{
-					mCameraLag = lerp(mCameraLag, LLVector3::zero, LLSmoothInterpolation::getInterpolant(0.15f));
-				}
-
-				camera_lag_d.setVec(mCameraLag);
-				camera_position_global = camera_position_global - camera_lag_d;
-			}
-		}
-	}
-	else
-	{
-		LLVector3d focusPosGlobal = calcFocusPositionTargetGlobal();
-		// camera gets pushed out later wrt mCameraFOVZoomFactor...this is "raw" value
-		camera_position_global = focusPosGlobal + mCameraFocusOffset;
-	}
-
-	auto& worldInst = LLWorld::instance();
-
-	if (!isDisableCameraConstraints() && !gAgent.isGodlike())
-	{
-		LLViewerRegion* regionp = worldInst.getRegionFromPosGlobal(camera_position_global);
-		bool constrain = true;
-		if(regionp && regionp->canManageEstate())
-		{
-			constrain = false;
-		}
-		if(constrain)
-		{
-			F32 max_dist = (CAMERA_MODE_CUSTOMIZE_AVATAR == mCameraMode) ? APPEARANCE_MAX_ZOOM : mDrawDistance;
-
-			LLVector3d camera_offset = camera_position_global - gAgent.getPositionGlobal();
-			F32 camera_distance = (F32)camera_offset.magVec();
-
-			if(camera_distance > max_dist)
-			{
-				camera_position_global = gAgent.getPositionGlobal() + (max_dist/camera_distance)*camera_offset;
-				isConstrained = TRUE;
-			}
-		}
+                    }
+
+                    mCameraLag = lerp(mCameraLag, target_lag, lag_interp);
+
+                    F32 lag_dist = mCameraLag.magVec();
+                    if (lag_dist > MAX_CAMERA_LAG)
+                    {
+                        mCameraLag = mCameraLag * MAX_CAMERA_LAG / lag_dist;
+                    }
+
+                    // clamp camera lag so that avatar is always in front
+                    F32 dot = (mCameraLag - (frame_at_axis * (MIN_CAMERA_LAG * u))) * frame_at_axis;
+                    if (dot < -(MIN_CAMERA_LAG * u))
+                    {
+                        mCameraLag -= (dot + (MIN_CAMERA_LAG * u)) * frame_at_axis;
+                    }
+                }
+                else
+                {
+                    mCameraLag = lerp(mCameraLag, LLVector3::zero, LLSmoothInterpolation::getInterpolant(0.15f));
+                }
+
+                camera_lag_d.setVec(mCameraLag);
+                camera_position_global = camera_position_global - camera_lag_d;
+            }
+        }
+    }
+    else
+    {
+        LLVector3d focusPosGlobal = calcFocusPositionTargetGlobal();
+        // camera gets pushed out later wrt mCameraFOVZoomFactor...this is "raw" value
+        camera_position_global = focusPosGlobal + mCameraFocusOffset;
+    }
+
+    auto& worldInst = LLWorld::instance();
+
+    if (!isDisableCameraConstraints() && !gAgent.isGodlike())
+    {
+        LLViewerRegion* regionp = worldInst.getRegionFromPosGlobal(camera_position_global);
+        bool constrain = true;
+        if(regionp && regionp->canManageEstate())
+        {
+            constrain = false;
+        }
+        if(constrain)
+        {
+            F32 max_dist = (CAMERA_MODE_CUSTOMIZE_AVATAR == mCameraMode) ? APPEARANCE_MAX_ZOOM : mDrawDistance;
+
+            LLVector3d camera_offset = camera_position_global - gAgent.getPositionGlobal();
+            F32 camera_distance = (F32)camera_offset.magVec();
+
+            if(camera_distance > max_dist)
+            {
+                camera_position_global = gAgent.getPositionGlobal() + (max_dist/camera_distance)*camera_offset;
+                isConstrained = TRUE;
+            }
+        }
 
 // JC - Could constrain camera based on parcel stuff here.
-//			LLViewerRegion *regionp = worldInst.getRegionFromPosGlobal(camera_position_global);
-//			
-//			if (regionp && !regionp->mParcelOverlay->isBuildCameraAllowed(regionp->getPosRegionFromGlobal(camera_position_global)))
-//			{
-//				camera_position_global = last_position_global;
+//          LLViewerRegion *regionp = worldInst.getRegionFromPosGlobal(camera_position_global);
+//
+//          if (regionp && !regionp->mParcelOverlay->isBuildCameraAllowed(regionp->getPosRegionFromGlobal(camera_position_global)))
+//          {
+//              camera_position_global = last_position_global;
 //
-//				isConstrained = TRUE;
-//			}
-	}
+//              isConstrained = TRUE;
+//          }
+    }
 
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	if ( (RlvActions::isRlvEnabled()) && ((CAMERA_MODE_THIRD_PERSON == mCameraMode) || (CAMERA_MODE_FOLLOW == mCameraMode)) && (RlvActions::isCameraDistanceClamped()) )
-	{
-		m_fRlvMinDist = m_fRlvMaxDist = false;
-
-		// Av-locked | Focus-locked | Result
-		// ===================================================
-		//     T     |      T       | skip focus => slam av
-		//     T     |      F       | skip focus => slam av
-		//     F     |      T       | skip av    => slam focus
-		//     F     |      F       | clamp focus then av
-		bool fCamAvDistClamped, fCamAvDistLocked = false; float nCamAvDistLimitMin, nCamAvDistLimitMax;
-		if ((fCamAvDistClamped = RlvActions::getCameraAvatarDistanceLimits(nCamAvDistLimitMin, nCamAvDistLimitMax)))
-			fCamAvDistLocked = nCamAvDistLimitMin == nCamAvDistLimitMax;
-		bool fCamOriginDistClamped, fCamOriginDistLocked = false; float nCamOriginDistLimitMin, nCamOriginDistLimitMax;
-		if ((fCamOriginDistClamped = RlvActions::getCameraOriginDistanceLimits(nCamOriginDistLimitMin, nCamOriginDistLimitMax)))
-			fCamOriginDistLocked = nCamOriginDistLimitMin == nCamOriginDistLimitMax;
-
-		// Check focus distance limits
-		if ( (fCamOriginDistClamped) && (!fCamAvDistLocked) )
-		{
-//			const LLVector3 offsetCameraLocal = mCameraZoomFraction * getCameraOffsetInitial() * gSavedSettings.getF32("CameraOffsetScale");
+    if ( (RlvActions::isRlvEnabled()) && ((CAMERA_MODE_THIRD_PERSON == mCameraMode) || (CAMERA_MODE_FOLLOW == mCameraMode)) && (RlvActions::isCameraDistanceClamped()) )
+    {
+        m_fRlvMinDist = m_fRlvMaxDist = false;
+
+        // Av-locked | Focus-locked | Result
+        // ===================================================
+        //     T     |      T       | skip focus => slam av
+        //     T     |      F       | skip focus => slam av
+        //     F     |      T       | skip av    => slam focus
+        //     F     |      F       | clamp focus then av
+        bool fCamAvDistClamped, fCamAvDistLocked = false; float nCamAvDistLimitMin, nCamAvDistLimitMax;
+        if ((fCamAvDistClamped = RlvActions::getCameraAvatarDistanceLimits(nCamAvDistLimitMin, nCamAvDistLimitMax)))
+            fCamAvDistLocked = nCamAvDistLimitMin == nCamAvDistLimitMax;
+        bool fCamOriginDistClamped, fCamOriginDistLocked = false; float nCamOriginDistLimitMin, nCamOriginDistLimitMax;
+        if ((fCamOriginDistClamped = RlvActions::getCameraOriginDistanceLimits(nCamOriginDistLimitMin, nCamOriginDistLimitMax)))
+            fCamOriginDistLocked = nCamOriginDistLimitMin == nCamOriginDistLimitMax;
+
+        // Check focus distance limits
+        if ( (fCamOriginDistClamped) && (!fCamAvDistLocked) )
+        {
+//          const LLVector3 offsetCameraLocal = mCameraZoomFraction * getCameraOffsetInitial() * gSavedSettings.getF32("CameraOffsetScale");
 // [RLVa:KB] - @setcam_eyeoffsetscale
-			const LLVector3 offsetCameraLocal = mCameraZoomFraction * getCameraOffsetInitial() * getCameraOffsetScale();
+            const LLVector3 offsetCameraLocal = mCameraZoomFraction * getCameraOffsetInitial() * getCameraOffsetScale();
 // [/RLVa:KB]
-			const LLVector3d offsetCamera(gAgent.getFrameAgent().rotateToAbsolute(offsetCameraLocal));
-			const LLVector3d posFocusCam = frame_center_global + head_offset + offsetCamera;
-			if (clampCameraPosition(camera_position_global, posFocusCam, nCamOriginDistLimitMin, nCamOriginDistLimitMax))
-				isConstrained = TRUE;
-		}
-
-		// Check avatar distance limits
-		if ( (fCamAvDistClamped) && (fCamAvDistLocked || !fCamOriginDistClamped) )
-		{
-			const LLVector3d posAvatarCam = gAgent.getPosGlobalFromAgent( (isAgentAvatarValid()) ? gAgentAvatarp->mHeadp->getWorldPosition() : gAgent.getPositionAgent() );
-			if (clampCameraPosition(camera_position_global, posAvatarCam, nCamAvDistLimitMin, nCamAvDistLimitMax))
-				isConstrained = TRUE;
-		}
-	}
+            const LLVector3d offsetCamera(gAgent.getFrameAgent().rotateToAbsolute(offsetCameraLocal));
+            const LLVector3d posFocusCam = frame_center_global + head_offset + offsetCamera;
+            if (clampCameraPosition(camera_position_global, posFocusCam, nCamOriginDistLimitMin, nCamOriginDistLimitMax))
+                isConstrained = TRUE;
+        }
+
+        // Check avatar distance limits
+        if ( (fCamAvDistClamped) && (fCamAvDistLocked || !fCamOriginDistClamped) )
+        {
+            const LLVector3d posAvatarCam = gAgent.getPosGlobalFromAgent( (isAgentAvatarValid()) ? gAgentAvatarp->mHeadp->getWorldPosition() : gAgent.getPositionAgent() );
+            if (clampCameraPosition(camera_position_global, posAvatarCam, nCamAvDistLimitMin, nCamAvDistLimitMax))
+                isConstrained = TRUE;
+        }
+    }
 // [/RLVa:KB]
 
-	// Don't let camera go underground
-	F32 camera_min_off_ground = getCameraMinOffGround();
-	camera_land_height = worldInst.resolveLandHeightGlobal(camera_position_global);
-	F32 minZ = llmax(F_ALMOST_ZERO, camera_land_height + camera_min_off_ground);
-	if (camera_position_global.mdV[VZ] < minZ)
-	{
-		camera_position_global.mdV[VZ] = minZ;
-		isConstrained = TRUE;
-	}
+    // Don't let camera go underground
+    F32 camera_min_off_ground = getCameraMinOffGround();
+    camera_land_height = worldInst.resolveLandHeightGlobal(camera_position_global);
+    F32 minZ = llmax(F_ALMOST_ZERO, camera_land_height + camera_min_off_ground);
+    if (camera_position_global.mdV[VZ] < minZ)
+    {
+        camera_position_global.mdV[VZ] = minZ;
+        isConstrained = TRUE;
+    }
 
-	if (hit_limit)
-	{
-		*hit_limit = isConstrained;
-	}
+    if (hit_limit)
+    {
+        *hit_limit = isConstrained;
+    }
 
-	return camera_position_global;
+    return camera_position_global;
 }
 
 // [RLVa:KB] - Checked: RLVa-2.0.0
 bool LLAgentCamera::allowFocusOffsetChange(const LLVector3d& offsetFocus)
 {
-	if (RlvActions::isCameraDistanceClamped())
-	{
-		if ( ((CAMERA_MODE_THIRD_PERSON == getCameraMode()) || (CAMERA_MODE_FOLLOW == getCameraMode())) && ((m_fRlvMinDist) || (m_fRlvMaxDist)) )
-		{
-			const LLVector3d posFocusGlobal = calcFocusPositionTargetGlobal();
-			// Don't allow moving the focus offset if at minimum and moving closer (or if at maximum and moving further) to prevent camera warping
-			F32 nCurDist = llabs((posFocusGlobal + mCameraFocusOffsetTarget - m_posRlvRefGlobal).magVec());
-			F32 nNewDist = llabs((posFocusGlobal + offsetFocus - m_posRlvRefGlobal).magVec());
-			if ( ((m_fRlvMaxDist) && (nNewDist > nCurDist)) || ((m_fRlvMinDist) && (nNewDist < nCurDist)) )
-				return false;
-		}
-	}
-	return true;
+    if (RlvActions::isCameraDistanceClamped())
+    {
+        if ( ((CAMERA_MODE_THIRD_PERSON == getCameraMode()) || (CAMERA_MODE_FOLLOW == getCameraMode())) && ((m_fRlvMinDist) || (m_fRlvMaxDist)) )
+        {
+            const LLVector3d posFocusGlobal = calcFocusPositionTargetGlobal();
+            // Don't allow moving the focus offset if at minimum and moving closer (or if at maximum and moving further) to prevent camera warping
+            F32 nCurDist = llabs((posFocusGlobal + mCameraFocusOffsetTarget - m_posRlvRefGlobal).magVec());
+            F32 nNewDist = llabs((posFocusGlobal + offsetFocus - m_posRlvRefGlobal).magVec());
+            if ( ((m_fRlvMaxDist) && (nNewDist > nCurDist)) || ((m_fRlvMinDist) && (nNewDist < nCurDist)) )
+                return false;
+        }
+    }
+    return true;
 }
 
 bool LLAgentCamera::clampCameraPosition(LLVector3d& posCamGlobal, const LLVector3d posCamRefGlobal, float nDistMin, float nDistMax)
 {
-	const LLVector3d offsetCamera = posCamGlobal - posCamRefGlobal;
-
-	F32 nCamAvDist = llabs(offsetCamera.magVec()), nDistMult = NAN;
-	if (nCamAvDist > nDistMax)
-	{
-		nDistMult = nDistMax / nCamAvDist;
-		m_fRlvMaxDist = true;
-	}
-	else if (nCamAvDist < nDistMin)
-	{
-		nDistMult = nDistMin / nCamAvDist;
-		m_fRlvMinDist = true;
-	}
-
-	if (!llisnan(nDistMult))
-	{
-		posCamGlobal = posCamRefGlobal + nDistMult * offsetCamera;
-		m_posRlvRefGlobal = posCamRefGlobal;
-		return true;
-	}
-	return false;
+    const LLVector3d offsetCamera = posCamGlobal - posCamRefGlobal;
+
+    F32 nCamAvDist = llabs(offsetCamera.magVec()), nDistMult = NAN;
+    if (nCamAvDist > nDistMax)
+    {
+        nDistMult = nDistMax / nCamAvDist;
+        m_fRlvMaxDist = true;
+    }
+    else if (nCamAvDist < nDistMin)
+    {
+        nDistMult = nDistMin / nCamAvDist;
+        m_fRlvMinDist = true;
+    }
+
+    if (!llisnan(nDistMult))
+    {
+        posCamGlobal = posCamRefGlobal + nDistMult * offsetCamera;
+        m_posRlvRefGlobal = posCamRefGlobal;
+        return true;
+    }
+    return false;
 }
 // [/RLVa:KB]
 
 LLVector3 LLAgentCamera::getCurrentCameraOffset()
 {
-	return (LLViewerCamera::getInstance()->getOrigin() - getAvatarRootPosition() - mThirdPersonHeadOffset) * ~getCurrentAvatarRotation();
+    return (LLViewerCamera::getInstance()->getOrigin() - getAvatarRootPosition() - mThirdPersonHeadOffset) * ~getCurrentAvatarRotation();
 }
 
 LLVector3d LLAgentCamera::getCurrentFocusOffset()
 {
-	return (mFocusTargetGlobal - gAgent.getPositionGlobal()) * ~getCurrentAvatarRotation();
+    return (mFocusTargetGlobal - gAgent.getPositionGlobal()) * ~getCurrentAvatarRotation();
 }
 
 LLQuaternion LLAgentCamera::getCurrentAvatarRotation()
 {
-	LLViewerObject* sit_object = (LLViewerObject*)gAgentAvatarp->getParent();
-	
-	LLQuaternion av_rot = gAgent.getFrameAgent().getQuaternion();
-	LLQuaternion obj_rot = sit_object ? sit_object->getRenderRotation() : LLQuaternion::DEFAULT;
-	return av_rot * obj_rot;
+    LLViewerObject* sit_object = (LLViewerObject*)gAgentAvatarp->getParent();
+
+    LLQuaternion av_rot = gAgent.getFrameAgent().getQuaternion();
+    LLQuaternion obj_rot = sit_object ? sit_object->getRenderRotation() : LLQuaternion::DEFAULT;
+    return av_rot * obj_rot;
 }
 
 bool LLAgentCamera::isJoystickCameraUsed()
 {
-	return ((mOrbitAroundRadians != 0) || (mOrbitOverAngle != 0) || !mPanFocusDiff.isNull());
+    return ((mOrbitAroundRadians != 0) || (mOrbitOverAngle != 0) || !mPanFocusDiff.isNull());
 }
 
 LLVector3 LLAgentCamera::getCameraOffsetInitial()
@@ -2247,7 +2247,7 @@ LLVector3 LLAgentCamera::getCameraOffsetInitial()
     static LLCachedControl<LLVector3> camera_offset_initial_rlv (gSavedSettings, "CameraOffsetRLVaView", LLVector3());
     return (ECameraPreset::CAMERA_RLV_SETCAM_VIEW != mCameraPreset) ? camera_offset_initial : camera_offset_initial_rlv;
 // [/RLVa:KB]
-//	return camera_offset_initial;
+//  return camera_offset_initial;
 }
 
 LLVector3d LLAgentCamera::getFocusOffsetInitial()
@@ -2257,15 +2257,15 @@ LLVector3d LLAgentCamera::getFocusOffsetInitial()
     static LLCachedControl<LLVector3d> focus_offset_initial_rlv(gSavedSettings, "FocusOffsetRLVaView", LLVector3d());
     return (ECameraPreset::CAMERA_RLV_SETCAM_VIEW != mCameraPreset) ? focus_offset_initial : focus_offset_initial_rlv;
 // [/RLVa:KB]
-//	return focus_offset_initial;
+//  return focus_offset_initial;
 }
 
 // [RLVa:KB] - @setcam_eyeoffsetscale
 F32 LLAgentCamera::getCameraOffsetScale() const
 {
     static LLCachedControl<F32> camera_offset_scale(gSavedSettings, "CameraOffsetScale", 1.0f);
-	static LLCachedControl<F32> camera_offset_scale_rlv(gSavedSettings, "CameraOffsetScaleRLVa", 0.0f);
-	return (ECameraPreset::CAMERA_RLV_SETCAM_VIEW != mCameraPreset) ? camera_offset_scale : camera_offset_scale_rlv;
+    static LLCachedControl<F32> camera_offset_scale_rlv(gSavedSettings, "CameraOffsetScaleRLVa", 0.0f);
+    return (ECameraPreset::CAMERA_RLV_SETCAM_VIEW != mCameraPreset) ? camera_offset_scale : camera_offset_scale_rlv;
 }
 // [/RLVa:KB]
 
@@ -2289,70 +2289,70 @@ LLVector3 LLAgentCamera::getAvatarRootPosition()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::handleScrollWheel(S32 clicks)
 {
-	if (mCameraMode == CAMERA_MODE_FOLLOW && getFocusOnAvatar())
-	{
-		if (!mFollowCam.getPositionLocked()) // not if the followCam position is locked in place
-		{
-			mFollowCam.zoom(clicks); 
-			if (mFollowCam.isZoomedToMinimumDistance())
-			{
-				changeCameraToMouselook(FALSE);
-			}
-		}
-	}
-	else
-	{
-		LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-		const F32 ROOT_ROOT_TWO = sqrt(F_SQRT2);
-
-		// Block if camera is animating
-		if (mCameraAnimating)
-		{
-			return;
-		}
-
-		if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
-		{
-			F32 zoom_factor = (F32)pow(0.8, -clicks);
-			cameraZoomIn(zoom_factor);
-		}
-		else if (mFocusOnAvatar && (mCameraMode == CAMERA_MODE_THIRD_PERSON))
-		{
-			MASK mask = gKeyboard->currentMask(TRUE);
-			if (mask & MASK_SHIFT)
-			{
-				LLVector3d offset = gSavedSettings.getVector3d("FocusOffsetRearView");
-				offset.mdV[VZ] += 0.1f * (F32)clicks;
-				gSavedSettings.setVector3d("FocusOffsetRearView", offset);
-				return;
-			}
-			else if (mask & MASK_CONTROL)
-			{
-				LLVector3 offset = gSavedSettings.getVector3("CameraOffsetRearView");
-				offset.mV[VZ] += 0.1f * (F32)clicks;
-				gSavedSettings.setVector3("CameraOffsetRearView", offset);
-				return;
-			}
-
-			F32 camera_offset_initial_mag = getCameraOffsetInitial().magVec();
-			
-//			F32 current_zoom_fraction = mTargetCameraDistance / (camera_offset_initial_mag * gSavedSettings.getF32("CameraOffsetScale"));
+    if (mCameraMode == CAMERA_MODE_FOLLOW && getFocusOnAvatar())
+    {
+        if (!mFollowCam.getPositionLocked()) // not if the followCam position is locked in place
+        {
+            mFollowCam.zoom(clicks);
+            if (mFollowCam.isZoomedToMinimumDistance())
+            {
+                changeCameraToMouselook(FALSE);
+            }
+        }
+    }
+    else
+    {
+        LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+        const F32 ROOT_ROOT_TWO = sqrt(F_SQRT2);
+
+        // Block if camera is animating
+        if (mCameraAnimating)
+        {
+            return;
+        }
+
+        if (selection->getObjectCount() && selection->getSelectType() == SELECT_TYPE_HUD)
+        {
+            F32 zoom_factor = (F32)pow(0.8, -clicks);
+            cameraZoomIn(zoom_factor);
+        }
+        else if (mFocusOnAvatar && (mCameraMode == CAMERA_MODE_THIRD_PERSON))
+        {
+            MASK mask = gKeyboard->currentMask(TRUE);
+            if (mask & MASK_SHIFT)
+            {
+                LLVector3d offset = gSavedSettings.getVector3d("FocusOffsetRearView");
+                offset.mdV[VZ] += 0.1f * (F32)clicks;
+                gSavedSettings.setVector3d("FocusOffsetRearView", offset);
+                return;
+            }
+            else if (mask & MASK_CONTROL)
+            {
+                LLVector3 offset = gSavedSettings.getVector3("CameraOffsetRearView");
+                offset.mV[VZ] += 0.1f * (F32)clicks;
+                gSavedSettings.setVector3("CameraOffsetRearView", offset);
+                return;
+            }
+
+            F32 camera_offset_initial_mag = getCameraOffsetInitial().magVec();
+
+//          F32 current_zoom_fraction = mTargetCameraDistance / (camera_offset_initial_mag * gSavedSettings.getF32("CameraOffsetScale"));
 // [RLVa:KB] - @setcam_eyeoffsetscale
-			F32 current_zoom_fraction = mTargetCameraDistance / (camera_offset_initial_mag * getCameraOffsetScale());
+            F32 current_zoom_fraction = mTargetCameraDistance / (camera_offset_initial_mag * getCameraOffsetScale());
 // [/RLVa:KB]
-			current_zoom_fraction *= 1.f - pow(ROOT_ROOT_TWO, clicks);
-			
+            current_zoom_fraction *= 1.f - pow(ROOT_ROOT_TWO, clicks);
+
 // [RLVa:KB] - @setcam_eyeoffsetscale
-			cameraOrbitIn(current_zoom_fraction * camera_offset_initial_mag * getCameraOffsetScale());
+            cameraOrbitIn(current_zoom_fraction * camera_offset_initial_mag * getCameraOffsetScale());
 // [/RLVa:KB]
-//			cameraOrbitIn(current_zoom_fraction * camera_offset_initial_mag * gSavedSettings.getF32("CameraOffsetScale"));
-		}
-		else
-		{
-			F32 current_zoom_fraction = (F32)mCameraFocusOffsetTarget.magVec();
-			cameraOrbitIn(current_zoom_fraction * (1.f - pow(ROOT_ROOT_TWO, clicks)));
-		}
-	}
+//          cameraOrbitIn(current_zoom_fraction * camera_offset_initial_mag * gSavedSettings.getF32("CameraOffsetScale"));
+        }
+        else
+        {
+            F32 current_zoom_fraction = (F32)mCameraFocusOffsetTarget.magVec();
+            cameraOrbitIn(current_zoom_fraction * (1.f - pow(ROOT_ROOT_TWO, clicks)));
+        }
+    }
 }
 
 
@@ -2361,17 +2361,17 @@ void LLAgentCamera::handleScrollWheel(S32 clicks)
 //-----------------------------------------------------------------------------
 F32 LLAgentCamera::getCameraMinOffGround()
 {
-	if (mCameraMode == CAMERA_MODE_MOUSELOOK)
-	{
-		return 0.f;
-	}
+    if (mCameraMode == CAMERA_MODE_MOUSELOOK)
+    {
+        return 0.f;
+    }
 
-	if (isDisableCameraConstraints())
-	{
-		return -1000.f;
-	}
+    if (isDisableCameraConstraints())
+    {
+        return -1000.f;
+    }
 
-	return 0.5f;
+    return 0.5f;
 }
 
 
@@ -2380,15 +2380,15 @@ F32 LLAgentCamera::getCameraMinOffGround()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::resetCamera()
 {
-	// Remove any pitch from the avatar
-	LLVector3 at = gAgent.getFrameAgent().getAtAxis();
-	at.mV[VZ] = 0.f;
-	at.normalize();
-	gAgent.resetAxes(at);
-	// have to explicitly clear field of view zoom now
-	mCameraFOVZoomFactor = 0.f;
+    // Remove any pitch from the avatar
+    LLVector3 at = gAgent.getFrameAgent().getAtAxis();
+    at.mV[VZ] = 0.f;
+    at.normalize();
+    gAgent.resetAxes(at);
+    // have to explicitly clear field of view zoom now
+    mCameraFOVZoomFactor = 0.f;
 
-	updateCamera();
+    updateCamera();
 }
 
 //-----------------------------------------------------------------------------
@@ -2396,63 +2396,63 @@ void LLAgentCamera::resetCamera()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::changeCameraToMouselook(BOOL animate)
 {
-	if (!gSavedSettings.getBOOL("EnableMouselook") 
+    if (!gSavedSettings.getBOOL("EnableMouselook")
 // [RLVa:KB] - Checked: RLVa-2.0.0
-		|| ( (RlvActions::isRlvEnabled()) && (!RlvActions::canChangeToMouselook()) )
+        || ( (RlvActions::isRlvEnabled()) && (!RlvActions::canChangeToMouselook()) )
 // [/RLVa:KB]
 
-		|| LLViewerJoystick::getInstance()->getOverrideCamera())
-	{
-		return;
-	}
-	
-	// visibility changes at end of animation
-	gViewerWindow->getWindow()->resetBusyCount();
-
-	// Menus should not remain open on switching to mouselook...
-	LLMenuGL::sMenuContainer->hideMenus();
-	LLUI::getInstance()->clearPopups();
-
-	// unpause avatar animation
-	gAgent.unpauseAnimation();
-
-	LLToolMgr::getInstance()->setCurrentToolset(gMouselookToolset);
-
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->stopMotion(ANIM_AGENT_BODY_NOISE);
-		gAgentAvatarp->stopMotion(ANIM_AGENT_BREATHE_ROT);
-	}
-
-	//gViewerWindow->stopGrab();
-	LLSelectMgr::getInstance()->deselectAll();
-//	gViewerWindow->hideCursor();
-//	gViewerWindow->moveCursorToCenter();
-
-	if (mCameraMode != CAMERA_MODE_MOUSELOOK)
-	{
-		gFocusMgr.setKeyboardFocus(NULL);
-		
-		updateLastCamera();
-		mCameraMode = CAMERA_MODE_MOUSELOOK;
-		AOEngine::getInstance()->inMouselook(TRUE);
-		const U32 old_flags = gAgent.getControlFlags();
-		gAgent.setControlFlags(AGENT_CONTROL_MOUSELOOK);
-		if (old_flags != gAgent.getControlFlags())
-		{
-			gAgent.setFlagsDirty();
-		}
-
-		if (animate)
-		{
-			startCameraAnimation();
-		}
-		else
-		{
-			mCameraAnimating = FALSE;
-			gAgent.endAnimationUpdateUI();
-		}
-	}
+        || LLViewerJoystick::getInstance()->getOverrideCamera())
+    {
+        return;
+    }
+
+    // visibility changes at end of animation
+    gViewerWindow->getWindow()->resetBusyCount();
+
+    // Menus should not remain open on switching to mouselook...
+    LLMenuGL::sMenuContainer->hideMenus();
+    LLUI::getInstance()->clearPopups();
+
+    // unpause avatar animation
+    gAgent.unpauseAnimation();
+
+    LLToolMgr::getInstance()->setCurrentToolset(gMouselookToolset);
+
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->stopMotion(ANIM_AGENT_BODY_NOISE);
+        gAgentAvatarp->stopMotion(ANIM_AGENT_BREATHE_ROT);
+    }
+
+    //gViewerWindow->stopGrab();
+    LLSelectMgr::getInstance()->deselectAll();
+//  gViewerWindow->hideCursor();
+//  gViewerWindow->moveCursorToCenter();
+
+    if (mCameraMode != CAMERA_MODE_MOUSELOOK)
+    {
+        gFocusMgr.setKeyboardFocus(NULL);
+
+        updateLastCamera();
+        mCameraMode = CAMERA_MODE_MOUSELOOK;
+        AOEngine::getInstance()->inMouselook(TRUE);
+        const U32 old_flags = gAgent.getControlFlags();
+        gAgent.setControlFlags(AGENT_CONTROL_MOUSELOOK);
+        if (old_flags != gAgent.getControlFlags())
+        {
+            gAgent.setFlagsDirty();
+        }
+
+        if (animate)
+        {
+            startCameraAnimation();
+        }
+        else
+        {
+            mCameraAnimating = FALSE;
+            gAgent.endAnimationUpdateUI();
+        }
+    }
 }
 
 
@@ -2461,24 +2461,24 @@ void LLAgentCamera::changeCameraToMouselook(BOOL animate)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::changeCameraToDefault()
 {
-	if (LLViewerJoystick::getInstance()->getOverrideCamera())
-	{
-		return;
-	}
+    if (LLViewerJoystick::getInstance()->getOverrideCamera())
+    {
+        return;
+    }
 
-	if (LLFollowCamMgr::getInstance()->getActiveFollowCamParams())
-	{
-		changeCameraToFollow();
-	}
-	else
-	{
-		changeCameraToThirdPerson();
-	}
-	if (ALCinematicMode::isEnabled() ||  gSavedSettings.getBOOL("HideUIControls"))
-	{
-		gViewerWindow->setUIVisibility(false);
-		LLPanelStandStopFlying::getInstance()->setVisible(false);
-	}
+    if (LLFollowCamMgr::getInstance()->getActiveFollowCamParams())
+    {
+        changeCameraToFollow();
+    }
+    else
+    {
+        changeCameraToThirdPerson();
+    }
+    if (ALCinematicMode::isEnabled() ||  gSavedSettings.getBOOL("HideUIControls"))
+    {
+        gViewerWindow->setUIVisibility(false);
+        LLPanelStandStopFlying::getInstance()->setVisible(false);
+    }
 }
 
 
@@ -2487,54 +2487,54 @@ void LLAgentCamera::changeCameraToDefault()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::changeCameraToFollow(BOOL animate)
 {
-	if (LLViewerJoystick::getInstance()->getOverrideCamera())
-	{
-		return;
-	}
-
-	if(mCameraMode != CAMERA_MODE_FOLLOW)
-	{
-		if (mCameraMode == CAMERA_MODE_MOUSELOOK)
-		{
-			animate = FALSE;
-		}
-		startCameraAnimation();
-
-		updateLastCamera();
-		mCameraMode = CAMERA_MODE_FOLLOW;
-		AOEngine::getInstance()->inMouselook(FALSE);
-
-		// bang-in the current focus, position, and up vector of the follow cam
-		mFollowCam.reset(mCameraPositionAgent, LLViewerCamera::getInstance()->getPointOfInterest(), LLVector3::z_axis);
-		
-		if (gBasicToolset)
-		{
-			LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
-		}
-
-		if (isAgentAvatarValid())
-		{
-			// SL-315
-			gAgentAvatarp->mPelvisp->setPosition(LLVector3::zero);
-			gAgentAvatarp->startMotion( ANIM_AGENT_BODY_NOISE );
-			gAgentAvatarp->startMotion( ANIM_AGENT_BREATHE_ROT );
-		}
-
-		// unpause avatar animation
-		gAgent.unpauseAnimation();
-
-		gAgent.clearControlFlags(AGENT_CONTROL_MOUSELOOK);
-
-		if (animate)
-		{
-			startCameraAnimation();
-		}
-		else
-		{
-			mCameraAnimating = FALSE;
-			gAgent.endAnimationUpdateUI();
-		}
-	}
+    if (LLViewerJoystick::getInstance()->getOverrideCamera())
+    {
+        return;
+    }
+
+    if(mCameraMode != CAMERA_MODE_FOLLOW)
+    {
+        if (mCameraMode == CAMERA_MODE_MOUSELOOK)
+        {
+            animate = FALSE;
+        }
+        startCameraAnimation();
+
+        updateLastCamera();
+        mCameraMode = CAMERA_MODE_FOLLOW;
+        AOEngine::getInstance()->inMouselook(FALSE);
+
+        // bang-in the current focus, position, and up vector of the follow cam
+        mFollowCam.reset(mCameraPositionAgent, LLViewerCamera::getInstance()->getPointOfInterest(), LLVector3::z_axis);
+
+        if (gBasicToolset)
+        {
+            LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
+        }
+
+        if (isAgentAvatarValid())
+        {
+            // SL-315
+            gAgentAvatarp->mPelvisp->setPosition(LLVector3::zero);
+            gAgentAvatarp->startMotion( ANIM_AGENT_BODY_NOISE );
+            gAgentAvatarp->startMotion( ANIM_AGENT_BREATHE_ROT );
+        }
+
+        // unpause avatar animation
+        gAgent.unpauseAnimation();
+
+        gAgent.clearControlFlags(AGENT_CONTROL_MOUSELOOK);
+
+        if (animate)
+        {
+            startCameraAnimation();
+        }
+        else
+        {
+            mCameraAnimating = FALSE;
+            gAgent.endAnimationUpdateUI();
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -2542,70 +2542,70 @@ void LLAgentCamera::changeCameraToFollow(BOOL animate)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::changeCameraToThirdPerson(BOOL animate)
 {
-	if (LLViewerJoystick::getInstance()->getOverrideCamera())
-	{
-		return;
-	}
-
-	gViewerWindow->getWindow()->resetBusyCount();
-
-	mCameraZoomFraction = INITIAL_ZOOM_FRACTION;
-
-	if (isAgentAvatarValid())
-	{
-		if (!gAgentAvatarp->isSitting())
-		{
-			// SL-315
-			gAgentAvatarp->mPelvisp->setPosition(LLVector3::zero);
-		}
-		gAgentAvatarp->startMotion(ANIM_AGENT_BODY_NOISE);
-		gAgentAvatarp->startMotion(ANIM_AGENT_BREATHE_ROT);
-	}
-
-	LLVector3 at_axis;
-
-	// unpause avatar animation
-	gAgent.unpauseAnimation();
-
-	if (mCameraMode != CAMERA_MODE_THIRD_PERSON)
-	{
-		if (gBasicToolset)
-		{
-			LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
-		}
-
-		mCameraLag.clearVec();
-		if (mCameraMode == CAMERA_MODE_MOUSELOOK)
-		{
-			mCurrentCameraDistance = MIN_CAMERA_DISTANCE;
-			mTargetCameraDistance = MIN_CAMERA_DISTANCE;
-			animate = FALSE;
-		}
-		updateLastCamera();
-		mCameraMode = CAMERA_MODE_THIRD_PERSON;
-		AOEngine::getInstance()->inMouselook(FALSE);
-		gAgent.clearControlFlags(AGENT_CONTROL_MOUSELOOK);
-	}
-
-	// Remove any pitch from the avatar
-	if (!isAgentAvatarValid() || !gAgentAvatarp->getParent())
-	{
-		at_axis = gAgent.getFrameAgent().getAtAxis();
-		at_axis.mV[VZ] = 0.f;
-		at_axis.normalize();
-		gAgent.resetAxes(at_axis);
-	}
-
-
-	if (animate)
-	{
-		startCameraAnimation();
-	}
-	else
-	{
-		mCameraAnimating = FALSE;
-		gAgent.endAnimationUpdateUI();
-	}
+    if (LLViewerJoystick::getInstance()->getOverrideCamera())
+    {
+        return;
+    }
+
+    gViewerWindow->getWindow()->resetBusyCount();
+
+    mCameraZoomFraction = INITIAL_ZOOM_FRACTION;
+
+    if (isAgentAvatarValid())
+    {
+        if (!gAgentAvatarp->isSitting())
+        {
+            // SL-315
+            gAgentAvatarp->mPelvisp->setPosition(LLVector3::zero);
+        }
+        gAgentAvatarp->startMotion(ANIM_AGENT_BODY_NOISE);
+        gAgentAvatarp->startMotion(ANIM_AGENT_BREATHE_ROT);
+    }
+
+    LLVector3 at_axis;
+
+    // unpause avatar animation
+    gAgent.unpauseAnimation();
+
+    if (mCameraMode != CAMERA_MODE_THIRD_PERSON)
+    {
+        if (gBasicToolset)
+        {
+            LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
+        }
+
+        mCameraLag.clearVec();
+        if (mCameraMode == CAMERA_MODE_MOUSELOOK)
+        {
+            mCurrentCameraDistance = MIN_CAMERA_DISTANCE;
+            mTargetCameraDistance = MIN_CAMERA_DISTANCE;
+            animate = FALSE;
+        }
+        updateLastCamera();
+        mCameraMode = CAMERA_MODE_THIRD_PERSON;
+        AOEngine::getInstance()->inMouselook(FALSE);
+        gAgent.clearControlFlags(AGENT_CONTROL_MOUSELOOK);
+    }
+
+    // Remove any pitch from the avatar
+    if (!isAgentAvatarValid() || !gAgentAvatarp->getParent())
+    {
+        at_axis = gAgent.getFrameAgent().getAtAxis();
+        at_axis.mV[VZ] = 0.f;
+        at_axis.normalize();
+        gAgent.resetAxes(at_axis);
+    }
+
+
+    if (animate)
+    {
+        startCameraAnimation();
+    }
+    else
+    {
+        mCameraAnimating = FALSE;
+        gAgent.endAnimationUpdateUI();
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -2613,122 +2613,122 @@ void LLAgentCamera::changeCameraToThirdPerson(BOOL animate)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::changeCameraToCustomizeAvatar()
 {
-	if (LLViewerJoystick::getInstance()->getOverrideCamera() || !isAgentAvatarValid())
-	{
-		return;
-	}
+    if (LLViewerJoystick::getInstance()->getOverrideCamera() || !isAgentAvatarValid())
+    {
+        return;
+    }
 
 // [RLVa:KB] - Checked: 2010-03-07 (RLVa-1.2.0c) | Modified: RLVa-1.0.0g
-	if ( (rlv_handler_t::isEnabled()) && (!RlvActions::canStand()) )
-	{
-		return;
-	}
+    if ( (rlv_handler_t::isEnabled()) && (!RlvActions::canStand()) )
+    {
+        return;
+    }
 // [/RLVa:KB]
 
-	gAgent.standUp(); // force stand up
-	gViewerWindow->getWindow()->resetBusyCount();
+    gAgent.standUp(); // force stand up
+    gViewerWindow->getWindow()->resetBusyCount();
 
     if (LLSelectMgr::getInstance()->getSelection()->isAttachment())
     {
         LLSelectMgr::getInstance()->deselectAll();
     }
 
-	if (gFaceEditToolset)
-	{
-		LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset);
-	}
-
-	startCameraAnimation();
-
-	if (mCameraMode != CAMERA_MODE_CUSTOMIZE_AVATAR)
-	{
-		updateLastCamera();
-		mCameraMode = CAMERA_MODE_CUSTOMIZE_AVATAR;
-		gAgent.clearControlFlags(AGENT_CONTROL_MOUSELOOK);
-
-		gFocusMgr.setKeyboardFocus( NULL );
-		gFocusMgr.setMouseCapture( NULL );
-		if( gMorphView )
-		{
-			gMorphView->setVisible( TRUE );
-		}
-		// Remove any pitch or rotation from the avatar
-		LLVector3 at = gAgent.getAtAxis();
-		at.mV[VZ] = 0.f;
-		at.normalize();
-		gAgent.resetAxes(at);
-
-		gAgent.sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_START);
-		gAgent.setCustomAnim(TRUE);
-		gAgentAvatarp->startMotion(ANIM_AGENT_CUSTOMIZE);
-		LLMotion* turn_motion = gAgentAvatarp->findMotion(ANIM_AGENT_CUSTOMIZE);
-
-		if (turn_motion)
-		{
-			// delay camera animation long enough to play through turn animation
-			setAnimationDuration(turn_motion->getDuration() + CUSTOMIZE_AVATAR_CAMERA_ANIM_SLOP);
-		}
-	}
-
-	LLVector3 agent_at = gAgent.getAtAxis();
-	agent_at.mV[VZ] = 0.f;
-	agent_at.normalize();
-
-	// default focus point for customize avatar
-	LLVector3 focus_target = isAgentAvatarValid() 
-		? gAgentAvatarp->mHeadp->getWorldPosition()
-		: gAgent.getPositionAgent();
-
-	LLVector3d camera_offset(agent_at * -1.0);
-	// push camera up and out from avatar
-	camera_offset.mdV[VZ] = 0.1f; 
-	camera_offset *= CUSTOMIZE_AVATAR_CAMERA_DEFAULT_DIST;
-	LLVector3d focus_target_global = gAgent.getPosGlobalFromAgent(focus_target);
-	setAnimationDuration(gSavedSettings.getF32("ZoomTime"));
-	setCameraPosAndFocusGlobal(focus_target_global + camera_offset, focus_target_global, gAgent.getID());
+    if (gFaceEditToolset)
+    {
+        LLToolMgr::getInstance()->setCurrentToolset(gFaceEditToolset);
+    }
+
+    startCameraAnimation();
+
+    if (mCameraMode != CAMERA_MODE_CUSTOMIZE_AVATAR)
+    {
+        updateLastCamera();
+        mCameraMode = CAMERA_MODE_CUSTOMIZE_AVATAR;
+        gAgent.clearControlFlags(AGENT_CONTROL_MOUSELOOK);
+
+        gFocusMgr.setKeyboardFocus( NULL );
+        gFocusMgr.setMouseCapture( NULL );
+        if( gMorphView )
+        {
+            gMorphView->setVisible( TRUE );
+        }
+        // Remove any pitch or rotation from the avatar
+        LLVector3 at = gAgent.getAtAxis();
+        at.mV[VZ] = 0.f;
+        at.normalize();
+        gAgent.resetAxes(at);
+
+        gAgent.sendAnimationRequest(ANIM_AGENT_CUSTOMIZE, ANIM_REQUEST_START);
+        gAgent.setCustomAnim(TRUE);
+        gAgentAvatarp->startMotion(ANIM_AGENT_CUSTOMIZE);
+        LLMotion* turn_motion = gAgentAvatarp->findMotion(ANIM_AGENT_CUSTOMIZE);
+
+        if (turn_motion)
+        {
+            // delay camera animation long enough to play through turn animation
+            setAnimationDuration(turn_motion->getDuration() + CUSTOMIZE_AVATAR_CAMERA_ANIM_SLOP);
+        }
+    }
+
+    LLVector3 agent_at = gAgent.getAtAxis();
+    agent_at.mV[VZ] = 0.f;
+    agent_at.normalize();
+
+    // default focus point for customize avatar
+    LLVector3 focus_target = isAgentAvatarValid()
+        ? gAgentAvatarp->mHeadp->getWorldPosition()
+        : gAgent.getPositionAgent();
+
+    LLVector3d camera_offset(agent_at * -1.0);
+    // push camera up and out from avatar
+    camera_offset.mdV[VZ] = 0.1f;
+    camera_offset *= CUSTOMIZE_AVATAR_CAMERA_DEFAULT_DIST;
+    LLVector3d focus_target_global = gAgent.getPosGlobalFromAgent(focus_target);
+    setAnimationDuration(gSavedSettings.getF32("ZoomTime"));
+    setCameraPosAndFocusGlobal(focus_target_global + camera_offset, focus_target_global, gAgent.getID());
 }
 
 
 void LLAgentCamera::switchCameraPreset(ECameraPreset preset)
 {
 // [RLVa:KB] - @setcam family
-	if (RlvActions::isRlvEnabled())
-	{
-		// Don't allow changing away from our view if an object is restricting it
-		if (RlvActions::isCameraPresetLocked())
-			preset = CAMERA_RLV_SETCAM_VIEW;
-
-		if (CAMERA_RLV_SETCAM_VIEW == preset)
-		{
-			if (CAMERA_RLV_SETCAM_VIEW == mCameraPreset)
-			{
-				// Don't reset anything if our view is already current
-				return;
-			}
-			else
-			{
-				// When switching to our view, copy the current values
-				gSavedSettings.setVector3("CameraOffsetRLVaView", getCameraOffsetInitial());
-				gSavedSettings.setVector3d("FocusOffsetRLVaView", getFocusOffsetInitial());
-				gSavedSettings.setF32("CameraOffsetScaleRLVa", getCameraOffsetScale());
-			}
-		}
-	}
+    if (RlvActions::isRlvEnabled())
+    {
+        // Don't allow changing away from our view if an object is restricting it
+        if (RlvActions::isCameraPresetLocked())
+            preset = CAMERA_RLV_SETCAM_VIEW;
+
+        if (CAMERA_RLV_SETCAM_VIEW == preset)
+        {
+            if (CAMERA_RLV_SETCAM_VIEW == mCameraPreset)
+            {
+                // Don't reset anything if our view is already current
+                return;
+            }
+            else
+            {
+                // When switching to our view, copy the current values
+                gSavedSettings.setVector3("CameraOffsetRLVaView", getCameraOffsetInitial());
+                gSavedSettings.setVector3d("FocusOffsetRLVaView", getFocusOffsetInitial());
+                gSavedSettings.setF32("CameraOffsetScaleRLVa", getCameraOffsetScale());
+            }
+        }
+    }
 // [/RLVa:KB]
 
-	//zoom is supposed to be reset for the front and group views
-	mCameraZoomFraction = 1.f;
+    //zoom is supposed to be reset for the front and group views
+    mCameraZoomFraction = 1.f;
 
-	//focusing on avatar in that case means following him on movements
-	mFocusOnAvatar = TRUE;
+    //focusing on avatar in that case means following him on movements
+    mFocusOnAvatar = TRUE;
 
-	mCameraPreset = preset;
+    mCameraPreset = preset;
 
-	resetPanDiff();
-	resetOrbitDiff();
-	resetCameraRoll();
+    resetPanDiff();
+    resetOrbitDiff();
+    resetCameraRoll();
 
-	gSavedSettings.setU32("CameraPresetType", mCameraPreset);
+    gSavedSettings.setU32("CameraPresetType", mCameraPreset);
 }
 
 
@@ -2737,17 +2737,17 @@ void LLAgentCamera::switchCameraPreset(ECameraPreset preset)
 //
 
 void LLAgentCamera::setAnimationDuration(F32 duration)
-{ 
-	if (mCameraAnimating)
-	{
-		// do not cut any existing camera animation short
-		F32 animation_left = llmax(0.f, mAnimationDuration - mAnimationTimer.getElapsedTimeF32());
-		mAnimationDuration = llmax(duration, animation_left);
-	}
-	else
-	{
-		mAnimationDuration = duration; 
-	}
+{
+    if (mCameraAnimating)
+    {
+        // do not cut any existing camera animation short
+        F32 animation_left = llmax(0.f, mAnimationDuration - mAnimationTimer.getElapsedTimeF32());
+        mAnimationDuration = llmax(duration, animation_left);
+    }
+    else
+    {
+        mAnimationDuration = duration;
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -2755,11 +2755,11 @@ void LLAgentCamera::setAnimationDuration(F32 duration)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::startCameraAnimation()
 {
-	mAnimationCameraStartGlobal = getCameraPositionGlobal();
-	mAnimationFocusStartGlobal = mFocusGlobal;
-	setAnimationDuration(gSavedSettings.getF32("ZoomTime"));
-	mAnimationTimer.reset();
-	mCameraAnimating = TRUE;
+    mAnimationCameraStartGlobal = getCameraPositionGlobal();
+    mAnimationFocusStartGlobal = mFocusGlobal;
+    setAnimationDuration(gSavedSettings.getF32("ZoomTime"));
+    mAnimationTimer.reset();
+    mCameraAnimating = TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -2767,23 +2767,23 @@ void LLAgentCamera::startCameraAnimation()
 //-----------------------------------------------------------------------------
 void LLAgentCamera::stopCameraAnimation()
 {
-	mCameraAnimating = FALSE;
+    mCameraAnimating = FALSE;
 }
 
 void LLAgentCamera::clearFocusObject()
 {
-	if (mFocusObject.notNull())
-	{
-		startCameraAnimation();
+    if (mFocusObject.notNull())
+    {
+        startCameraAnimation();
 
-		setFocusObject(NULL);
-		mFocusObjectOffset.clearVec();
-	}
+        setFocusObject(NULL);
+        mFocusObjectOffset.clearVec();
+    }
 }
 
 void LLAgentCamera::setFocusObject(LLViewerObject* object)
 {
-	mFocusObject = object;
+    mFocusObject = object;
 }
 
 // Focus on a point, but try to keep camera position stable.
@@ -2792,104 +2792,104 @@ void LLAgentCamera::setFocusObject(LLViewerObject* object)
 //-----------------------------------------------------------------------------
 void LLAgentCamera::setFocusGlobal(const LLPickInfo& pick)
 {
-	LLViewerObject* objectp = gObjectList.findObject(pick.mObjectID);
+    LLViewerObject* objectp = gObjectList.findObject(pick.mObjectID);
 
-	if (objectp && pick.mGLTFNodeIndex == -1)
-	{
-		// focus on object plus designated offset
-		// which may or may not be same as pick.mPosGlobal
-		setFocusGlobal(objectp->getPositionGlobal() + LLVector3d(pick.mObjectOffset), pick.mObjectID);
-	}
-	else
-	{
-		// focus directly on point where user clicked
-		setFocusGlobal(pick.mPosGlobal, pick.mObjectID);
-	}
+    if (objectp && pick.mGLTFNodeIndex == -1)
+    {
+        // focus on object plus designated offset
+        // which may or may not be same as pick.mPosGlobal
+        setFocusGlobal(objectp->getPositionGlobal() + LLVector3d(pick.mObjectOffset), pick.mObjectID);
+    }
+    else
+    {
+        // focus directly on point where user clicked
+        setFocusGlobal(pick.mPosGlobal, pick.mObjectID);
+    }
 }
 
 
 void LLAgentCamera::setFocusGlobal(const LLVector3d& focus, const LLUUID &object_id)
 {
-	setFocusObject(gObjectList.findObject(object_id));
-	LLVector3d old_focus = mFocusTargetGlobal;
-	LLViewerObject *focus_obj = mFocusObject;
-
-	// if focus has changed
-	if (old_focus != focus)
-	{
-		if (focus.isExactlyZero())
-		{
-			if (isAgentAvatarValid())
-			{
-				mFocusTargetGlobal = gAgent.getPosGlobalFromAgent(gAgentAvatarp->mHeadp->getWorldPosition());
-			}
-			else
-			{
-				mFocusTargetGlobal = gAgent.getPositionGlobal();
-			}
-			mCameraFocusOffsetTarget = getCameraPositionGlobal() - mFocusTargetGlobal;
-			mCameraFocusOffset = mCameraFocusOffsetTarget;
-			setLookAt(LOOKAT_TARGET_CLEAR);
-		}
-		else
-		{
-			mFocusTargetGlobal = focus;
-			if (!focus_obj)
-			{
-				mCameraFOVZoomFactor = 0.f;
-			}
-
-			mCameraFocusOffsetTarget = gAgent.getPosGlobalFromAgent(mCameraVirtualPositionAgent) - mFocusTargetGlobal;
-
-			startCameraAnimation();
-
-			if (focus_obj)
-			{
-				if (focus_obj->isAvatar())
-				{
-					setLookAt(LOOKAT_TARGET_FOCUS, focus_obj);
-				}
-				else
-				{
-					setLookAt(LOOKAT_TARGET_FOCUS, focus_obj, (gAgent.getPosAgentFromGlobal(focus) - focus_obj->getRenderPosition()) * ~focus_obj->getRenderRotation());
-				}
-			}
-			else
-			{
-				setLookAt(LOOKAT_TARGET_FOCUS, NULL, gAgent.getPosAgentFromGlobal(mFocusTargetGlobal));
-			}
-		}
-	}
-	else // focus == mFocusTargetGlobal
-	{
-		if (focus.isExactlyZero())
-		{
-			if (isAgentAvatarValid())
-			{
-				mFocusTargetGlobal = gAgent.getPosGlobalFromAgent(gAgentAvatarp->mHeadp->getWorldPosition());
-			}
-			else
-			{
-				mFocusTargetGlobal = gAgent.getPositionGlobal();
-			}
-		}
-		mCameraFocusOffsetTarget = (getCameraPositionGlobal() - mFocusTargetGlobal) / (1.f + mCameraFOVZoomFactor);;
-		mCameraFocusOffset = mCameraFocusOffsetTarget;
-	}
-
-	if (mFocusObject.notNull())
-	{
-		// for attachments, make offset relative to avatar, not the attachment
-		if (mFocusObject->isAttachment())
-		{
-			while (mFocusObject.notNull() && !mFocusObject->isAvatar())
-			{
-				mFocusObject = (LLViewerObject*) mFocusObject->getParent();
-			}
-			setFocusObject((LLViewerObject*)mFocusObject);
-		}
-		updateFocusOffset();
-	}
+    setFocusObject(gObjectList.findObject(object_id));
+    LLVector3d old_focus = mFocusTargetGlobal;
+    LLViewerObject *focus_obj = mFocusObject;
+
+    // if focus has changed
+    if (old_focus != focus)
+    {
+        if (focus.isExactlyZero())
+        {
+            if (isAgentAvatarValid())
+            {
+                mFocusTargetGlobal = gAgent.getPosGlobalFromAgent(gAgentAvatarp->mHeadp->getWorldPosition());
+            }
+            else
+            {
+                mFocusTargetGlobal = gAgent.getPositionGlobal();
+            }
+            mCameraFocusOffsetTarget = getCameraPositionGlobal() - mFocusTargetGlobal;
+            mCameraFocusOffset = mCameraFocusOffsetTarget;
+            setLookAt(LOOKAT_TARGET_CLEAR);
+        }
+        else
+        {
+            mFocusTargetGlobal = focus;
+            if (!focus_obj)
+            {
+                mCameraFOVZoomFactor = 0.f;
+            }
+
+            mCameraFocusOffsetTarget = gAgent.getPosGlobalFromAgent(mCameraVirtualPositionAgent) - mFocusTargetGlobal;
+
+            startCameraAnimation();
+
+            if (focus_obj)
+            {
+                if (focus_obj->isAvatar())
+                {
+                    setLookAt(LOOKAT_TARGET_FOCUS, focus_obj);
+                }
+                else
+                {
+                    setLookAt(LOOKAT_TARGET_FOCUS, focus_obj, (gAgent.getPosAgentFromGlobal(focus) - focus_obj->getRenderPosition()) * ~focus_obj->getRenderRotation());
+                }
+            }
+            else
+            {
+                setLookAt(LOOKAT_TARGET_FOCUS, NULL, gAgent.getPosAgentFromGlobal(mFocusTargetGlobal));
+            }
+        }
+    }
+    else // focus == mFocusTargetGlobal
+    {
+        if (focus.isExactlyZero())
+        {
+            if (isAgentAvatarValid())
+            {
+                mFocusTargetGlobal = gAgent.getPosGlobalFromAgent(gAgentAvatarp->mHeadp->getWorldPosition());
+            }
+            else
+            {
+                mFocusTargetGlobal = gAgent.getPositionGlobal();
+            }
+        }
+        mCameraFocusOffsetTarget = (getCameraPositionGlobal() - mFocusTargetGlobal) / (1.f + mCameraFOVZoomFactor);;
+        mCameraFocusOffset = mCameraFocusOffsetTarget;
+    }
+
+    if (mFocusObject.notNull())
+    {
+        // for attachments, make offset relative to avatar, not the attachment
+        if (mFocusObject->isAttachment())
+        {
+            while (mFocusObject.notNull() && !mFocusObject->isAvatar())
+            {
+                mFocusObject = (LLViewerObject*) mFocusObject->getParent();
+            }
+            setFocusObject((LLViewerObject*)mFocusObject);
+        }
+        updateFocusOffset();
+    }
 }
 
 // Used for avatar customization
@@ -2898,48 +2898,48 @@ void LLAgentCamera::setFocusGlobal(const LLVector3d& focus, const LLUUID &object
 //-----------------------------------------------------------------------------
 void LLAgentCamera::setCameraPosAndFocusGlobal(const LLVector3d& camera_pos, const LLVector3d& focus, const LLUUID &object_id)
 {
-	LLVector3d old_focus = mFocusTargetGlobal.isExactlyZero() ? focus : mFocusTargetGlobal;
-
-	F64 focus_delta_squared = (old_focus - focus).magVecSquared();
-	const F64 ANIM_EPSILON_SQUARED = 0.0001;
-	if (focus_delta_squared > ANIM_EPSILON_SQUARED)
-	{
-		startCameraAnimation();
-	}
-	
-	//LLViewerCamera::getInstance()->setOrigin( gAgent.getPosAgentFromGlobal( camera_pos ) );
-	setFocusObject(gObjectList.findObject(object_id));
-	mFocusTargetGlobal = focus;
-	mCameraFocusOffsetTarget = camera_pos - focus;
-	mCameraFocusOffset = mCameraFocusOffsetTarget;
-
-	if (mFocusObject)
-	{
-		if (mFocusObject->isAvatar())
-		{
-			setLookAt(LOOKAT_TARGET_FOCUS, mFocusObject);
-		}
-		else
-		{
-			setLookAt(LOOKAT_TARGET_FOCUS, mFocusObject, (gAgent.getPosAgentFromGlobal(focus) - mFocusObject->getRenderPosition()) * ~mFocusObject->getRenderRotation());
-		}
-	}
-	else
-	{
-		setLookAt(LOOKAT_TARGET_FOCUS, NULL, gAgent.getPosAgentFromGlobal(mFocusTargetGlobal));
-	}
-
-	if (mCameraAnimating)
-	{
-		const F64 ANIM_METERS_PER_SECOND = 50.0;
-		const F64 MIN_ANIM_SECONDS = 0.5;
-		const F64 MAX_ANIM_SECONDS = 1.0;
-		F64 anim_duration = llmax( MIN_ANIM_SECONDS, sqrt(focus_delta_squared) / ANIM_METERS_PER_SECOND );
-		anim_duration = llmin( anim_duration, MAX_ANIM_SECONDS );
-		setAnimationDuration( (F32)anim_duration );
-	}
-
-	updateFocusOffset();
+    LLVector3d old_focus = mFocusTargetGlobal.isExactlyZero() ? focus : mFocusTargetGlobal;
+
+    F64 focus_delta_squared = (old_focus - focus).magVecSquared();
+    const F64 ANIM_EPSILON_SQUARED = 0.0001;
+    if (focus_delta_squared > ANIM_EPSILON_SQUARED)
+    {
+        startCameraAnimation();
+    }
+
+    //LLViewerCamera::getInstance()->setOrigin( gAgent.getPosAgentFromGlobal( camera_pos ) );
+    setFocusObject(gObjectList.findObject(object_id));
+    mFocusTargetGlobal = focus;
+    mCameraFocusOffsetTarget = camera_pos - focus;
+    mCameraFocusOffset = mCameraFocusOffsetTarget;
+
+    if (mFocusObject)
+    {
+        if (mFocusObject->isAvatar())
+        {
+            setLookAt(LOOKAT_TARGET_FOCUS, mFocusObject);
+        }
+        else
+        {
+            setLookAt(LOOKAT_TARGET_FOCUS, mFocusObject, (gAgent.getPosAgentFromGlobal(focus) - mFocusObject->getRenderPosition()) * ~mFocusObject->getRenderRotation());
+        }
+    }
+    else
+    {
+        setLookAt(LOOKAT_TARGET_FOCUS, NULL, gAgent.getPosAgentFromGlobal(mFocusTargetGlobal));
+    }
+
+    if (mCameraAnimating)
+    {
+        const F64 ANIM_METERS_PER_SECOND = 50.0;
+        const F64 MIN_ANIM_SECONDS = 0.5;
+        const F64 MAX_ANIM_SECONDS = 1.0;
+        F64 anim_duration = llmax( MIN_ANIM_SECONDS, sqrt(focus_delta_squared) / ANIM_METERS_PER_SECOND );
+        anim_duration = llmin( anim_duration, MAX_ANIM_SECONDS );
+        setAnimationDuration( (F32)anim_duration );
+    }
+
+    updateFocusOffset();
 }
 
 //-----------------------------------------------------------------------------
@@ -2947,27 +2947,27 @@ void LLAgentCamera::setCameraPosAndFocusGlobal(const LLVector3d& camera_pos, con
 //-----------------------------------------------------------------------------
 void LLAgentCamera::setSitCamera(const LLUUID &object_id, const LLVector3 &camera_pos, const LLVector3 &camera_focus)
 {
-	BOOL camera_enabled = !object_id.isNull();
-
-	if (camera_enabled)
-	{
-		LLViewerObject *reference_object = gObjectList.findObject(object_id);
-		if (reference_object)
-		{
-			//convert to root object relative?
-			mSitCameraPos = camera_pos;
-			mSitCameraFocus = camera_focus;
-			mSitCameraReferenceObject = reference_object;
-			mSitCameraEnabled = TRUE;
-		}
-	}
-	else
-	{
-		mSitCameraPos.clearVec();
-		mSitCameraFocus.clearVec();
-		mSitCameraReferenceObject = NULL;
-		mSitCameraEnabled = FALSE;
-	}
+    BOOL camera_enabled = !object_id.isNull();
+
+    if (camera_enabled)
+    {
+        LLViewerObject *reference_object = gObjectList.findObject(object_id);
+        if (reference_object)
+        {
+            //convert to root object relative?
+            mSitCameraPos = camera_pos;
+            mSitCameraFocus = camera_focus;
+            mSitCameraReferenceObject = reference_object;
+            mSitCameraEnabled = TRUE;
+        }
+    }
+    else
+    {
+        mSitCameraPos.clearVec();
+        mSitCameraFocus.clearVec();
+        mSitCameraReferenceObject = NULL;
+        mSitCameraEnabled = FALSE;
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -2975,30 +2975,30 @@ void LLAgentCamera::setSitCamera(const LLUUID &object_id, const LLVector3 &camer
 //-----------------------------------------------------------------------------
 void LLAgentCamera::setFocusOnAvatar(BOOL focus_on_avatar, BOOL animate, BOOL reset_axes)
 {
-	if (focus_on_avatar != mFocusOnAvatar)
-	{
-		if (animate)
-		{
-			startCameraAnimation();
-		}
-		else
-		{
-			stopCameraAnimation();
-		}
-	}
-	
-	//RN: when focused on the avatar, we're not "looking" at it
-	// looking implies intent while focusing on avatar means
-	// you're just walking around with a camera on you...eesh.
-	if (!mFocusOnAvatar && focus_on_avatar && reset_axes)
-	{
-		setFocusGlobal(LLVector3d::zero);
-		mCameraFOVZoomFactor = 0.f;
-		if (mCameraMode == CAMERA_MODE_THIRD_PERSON)
-		{
-			LLVector3 at_axis;
-			if (!isAgentAvatarValid() || !gAgentAvatarp->getParent())
-			{
+    if (focus_on_avatar != mFocusOnAvatar)
+    {
+        if (animate)
+        {
+            startCameraAnimation();
+        }
+        else
+        {
+            stopCameraAnimation();
+        }
+    }
+
+    //RN: when focused on the avatar, we're not "looking" at it
+    // looking implies intent while focusing on avatar means
+    // you're just walking around with a camera on you...eesh.
+    if (!mFocusOnAvatar && focus_on_avatar && reset_axes)
+    {
+        setFocusGlobal(LLVector3d::zero);
+        mCameraFOVZoomFactor = 0.f;
+        if (mCameraMode == CAMERA_MODE_THIRD_PERSON)
+        {
+            LLVector3 at_axis;
+            if (!isAgentAvatarValid() || !gAgentAvatarp->getParent())
+            {
                 // In case of front view rotate agent to look into direction opposite to camera
                 // In case of rear view rotate agent into diraction same as camera, e t c
                 LLVector3 vect = getCameraOffsetInitial();
@@ -3012,51 +3012,51 @@ void LLAgentCamera::setFocusOnAvatar(BOOL focus_on_avatar, BOOL animate, BOOL re
                 at_axis.normalize();
                 gAgent.resetAxes(at_axis);
                 gAgent.yaw(0);
-			}
-		}
-	}
-	// unlocking camera from avatar
-	else if (mFocusOnAvatar && !focus_on_avatar)
-	{
-		// keep camera focus point consistent, even though it is now unlocked
-		setFocusGlobal(gAgent.getPositionGlobal() + calcThirdPersonFocusOffset(), gAgent.getID());
-		mAllowChangeToFollow = FALSE;
-	}
-	
-	mFocusOnAvatar = focus_on_avatar;
+            }
+        }
+    }
+    // unlocking camera from avatar
+    else if (mFocusOnAvatar && !focus_on_avatar)
+    {
+        // keep camera focus point consistent, even though it is now unlocked
+        setFocusGlobal(gAgent.getPositionGlobal() + calcThirdPersonFocusOffset(), gAgent.getID());
+        mAllowChangeToFollow = FALSE;
+    }
+
+    mFocusOnAvatar = focus_on_avatar;
 }
 
 
 BOOL LLAgentCamera::setLookAt(ELookAtType target_type, LLViewerObject *object, LLVector3 position)
 {
-	static LLCachedControl<bool> isPrivate(gSavedSettings, "AlchemyLookAtPrivate", false);
-	if (isPrivate)
-	{
-		target_type = LOOKAT_TARGET_NONE;
-		object = gAgentAvatarp;
-		position.clearVec();
-	}
-	else if(object && object->isAttachment())
-	{
-		LLViewerObject* parent = object;
-		while(parent)
-		{
-			if (parent == gAgentAvatarp)
-			{
-				// looking at an attachment on ourselves, which we don't want to do
-				object = gAgentAvatarp;
-				position.clearVec();
-			}
-			parent = (LLViewerObject*)parent->getParent();
-		}
-	}
-	if(!mLookAt || mLookAt->isDead())
-	{
-		mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT);
-		mLookAt->setSourceObject(gAgentAvatarp);
-	}
-
-	return mLookAt->setLookAt(target_type, object, position);
+    static LLCachedControl<bool> isPrivate(gSavedSettings, "AlchemyLookAtPrivate", false);
+    if (isPrivate)
+    {
+        target_type = LOOKAT_TARGET_NONE;
+        object = gAgentAvatarp;
+        position.clearVec();
+    }
+    else if(object && object->isAttachment())
+    {
+        LLViewerObject* parent = object;
+        while(parent)
+        {
+            if (parent == gAgentAvatarp)
+            {
+                // looking at an attachment on ourselves, which we don't want to do
+                object = gAgentAvatarp;
+                position.clearVec();
+            }
+            parent = (LLViewerObject*)parent->getParent();
+        }
+    }
+    if(!mLookAt || mLookAt->isDead())
+    {
+        mLookAt = (LLHUDEffectLookAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_LOOKAT);
+        mLookAt->setSourceObject(gAgentAvatarp);
+    }
+
+    return mLookAt->setLookAt(target_type, object, position);
 }
 
 //-----------------------------------------------------------------------------
@@ -3064,234 +3064,234 @@ BOOL LLAgentCamera::setLookAt(ELookAtType target_type, LLViewerObject *object, L
 //-----------------------------------------------------------------------------
 void LLAgentCamera::lookAtLastChat()
 {
-	// Block if camera is animating or not in normal third person camera mode
-	if (mCameraAnimating || !cameraThirdPerson())
-	{
-		return;
-	}
-
-	LLViewerObject *chatter = gObjectList.findObject(gAgent.getLastChatter());
-	if (!chatter)
-	{
-		return;
-	}
-
-	LLVector3 delta_pos;
-	if (chatter->isAvatar())
-	{
-		LLVOAvatar *chatter_av = (LLVOAvatar*)chatter;
-		if (isAgentAvatarValid() && chatter_av->mHeadp)
-		{
-			delta_pos = chatter_av->mHeadp->getWorldPosition() - gAgentAvatarp->mHeadp->getWorldPosition();
-		}
-		else
-		{
-			delta_pos = chatter->getPositionAgent() - gAgent.getPositionAgent();
-		}
-		delta_pos.normalize();
-
-		gAgent.setControlFlags(AGENT_CONTROL_STOP);
-
-		changeCameraToThirdPerson();
-
-		LLVector3 new_camera_pos = gAgentAvatarp->mHeadp->getWorldPosition();
-		LLVector3 left = delta_pos % LLVector3::z_axis;
-		left.normalize();
-		LLVector3 up = left % delta_pos;
-		up.normalize();
-		new_camera_pos -= delta_pos * 0.4f;
-		new_camera_pos += left * 0.3f;
-		new_camera_pos += up * 0.2f;
-
-		setFocusOnAvatar(FALSE, FALSE);
-
-		if (chatter_av->mHeadp)
-		{
-			setFocusGlobal(gAgent.getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()), gAgent.getLastChatter());
-			mCameraFocusOffsetTarget = gAgent.getPosGlobalFromAgent(new_camera_pos) - gAgent.getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition());
-		}
-		else
-		{
-			setFocusGlobal(chatter->getPositionGlobal(), gAgent.getLastChatter());
-			mCameraFocusOffsetTarget = gAgent.getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal();
-		}
-	}
-	else
-	{
-		delta_pos = chatter->getRenderPosition() - gAgent.getPositionAgent();
-		delta_pos.normalize();
-
-		gAgent.setControlFlags(AGENT_CONTROL_STOP);
-
-		changeCameraToThirdPerson();
-
-		LLVector3 new_camera_pos = gAgentAvatarp->mHeadp->getWorldPosition();
-		LLVector3 left = delta_pos % LLVector3::z_axis;
-		left.normalize();
-		LLVector3 up = left % delta_pos;
-		up.normalize();
-		new_camera_pos -= delta_pos * 0.4f;
-		new_camera_pos += left * 0.3f;
-		new_camera_pos += up * 0.2f;
-
-		setFocusOnAvatar(FALSE, FALSE);
-
-		setFocusGlobal(chatter->getPositionGlobal(), gAgent.getLastChatter());
-		mCameraFocusOffsetTarget = gAgent.getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal();
-	}
+    // Block if camera is animating or not in normal third person camera mode
+    if (mCameraAnimating || !cameraThirdPerson())
+    {
+        return;
+    }
+
+    LLViewerObject *chatter = gObjectList.findObject(gAgent.getLastChatter());
+    if (!chatter)
+    {
+        return;
+    }
+
+    LLVector3 delta_pos;
+    if (chatter->isAvatar())
+    {
+        LLVOAvatar *chatter_av = (LLVOAvatar*)chatter;
+        if (isAgentAvatarValid() && chatter_av->mHeadp)
+        {
+            delta_pos = chatter_av->mHeadp->getWorldPosition() - gAgentAvatarp->mHeadp->getWorldPosition();
+        }
+        else
+        {
+            delta_pos = chatter->getPositionAgent() - gAgent.getPositionAgent();
+        }
+        delta_pos.normalize();
+
+        gAgent.setControlFlags(AGENT_CONTROL_STOP);
+
+        changeCameraToThirdPerson();
+
+        LLVector3 new_camera_pos = gAgentAvatarp->mHeadp->getWorldPosition();
+        LLVector3 left = delta_pos % LLVector3::z_axis;
+        left.normalize();
+        LLVector3 up = left % delta_pos;
+        up.normalize();
+        new_camera_pos -= delta_pos * 0.4f;
+        new_camera_pos += left * 0.3f;
+        new_camera_pos += up * 0.2f;
+
+        setFocusOnAvatar(FALSE, FALSE);
+
+        if (chatter_av->mHeadp)
+        {
+            setFocusGlobal(gAgent.getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition()), gAgent.getLastChatter());
+            mCameraFocusOffsetTarget = gAgent.getPosGlobalFromAgent(new_camera_pos) - gAgent.getPosGlobalFromAgent(chatter_av->mHeadp->getWorldPosition());
+        }
+        else
+        {
+            setFocusGlobal(chatter->getPositionGlobal(), gAgent.getLastChatter());
+            mCameraFocusOffsetTarget = gAgent.getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal();
+        }
+    }
+    else
+    {
+        delta_pos = chatter->getRenderPosition() - gAgent.getPositionAgent();
+        delta_pos.normalize();
+
+        gAgent.setControlFlags(AGENT_CONTROL_STOP);
+
+        changeCameraToThirdPerson();
+
+        LLVector3 new_camera_pos = gAgentAvatarp->mHeadp->getWorldPosition();
+        LLVector3 left = delta_pos % LLVector3::z_axis;
+        left.normalize();
+        LLVector3 up = left % delta_pos;
+        up.normalize();
+        new_camera_pos -= delta_pos * 0.4f;
+        new_camera_pos += left * 0.3f;
+        new_camera_pos += up * 0.2f;
+
+        setFocusOnAvatar(FALSE, FALSE);
+
+        setFocusGlobal(chatter->getPositionGlobal(), gAgent.getLastChatter());
+        mCameraFocusOffsetTarget = gAgent.getPosGlobalFromAgent(new_camera_pos) - chatter->getPositionGlobal();
+    }
 }
 
 bool LLAgentCamera::isfollowCamLocked()
 {
-	return mFollowCam.getPositionLocked();
+    return mFollowCam.getPositionLocked();
 }
 
 BOOL LLAgentCamera::setPointAt(EPointAtType target_type, LLViewerObject *object, LLVector3 position)
 {
-	// disallow pointing at attachments and avatars
-	if (object && (object->isAttachment() || object->isAvatar()))
-	{
-		return FALSE;
-	}
-
-	static LLCachedControl<bool> disablePointAt(gSavedSettings, "AlchemyPointAtPrivate", false);
-	if (disablePointAt)
-	{
-		target_type = POINTAT_TARGET_CLEAR;
-		object = nullptr;
-		position.clear();
-	}
-	if (!mPointAt || mPointAt->isDead())
-	{
-		mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT);
-		mPointAt->setSourceObject(gAgentAvatarp);
-	}
-	return mPointAt->setPointAt(target_type, object, position);
+    // disallow pointing at attachments and avatars
+    if (object && (object->isAttachment() || object->isAvatar()))
+    {
+        return FALSE;
+    }
+
+    static LLCachedControl<bool> disablePointAt(gSavedSettings, "AlchemyPointAtPrivate", false);
+    if (disablePointAt)
+    {
+        target_type = POINTAT_TARGET_CLEAR;
+        object = nullptr;
+        position.clear();
+    }
+    if (!mPointAt || mPointAt->isDead())
+    {
+        mPointAt = (LLHUDEffectPointAt *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINTAT);
+        mPointAt->setSourceObject(gAgentAvatarp);
+    }
+    return mPointAt->setPointAt(target_type, object, position);
 }
 
 void LLAgentCamera::rotateToInitSitRot()
 {
-	gAgent.rotate(~gAgent.getFrameAgent().getQuaternion());
-	gAgent.rotate(mInitSitRot);
+    gAgent.rotate(~gAgent.getFrameAgent().getQuaternion());
+    gAgent.rotate(mInitSitRot);
 }
 
 void LLAgentCamera::resetCameraZoomFraction()
-{ 
-	mCameraZoomFraction = INITIAL_ZOOM_FRACTION; 
+{
+    mCameraZoomFraction = INITIAL_ZOOM_FRACTION;
 }
 
 ELookAtType LLAgentCamera::getLookAtType()
 {
-	if (mLookAt) 
-	{
-		return mLookAt->getLookAtType();
-	}
-	return LOOKAT_TARGET_NONE;
+    if (mLookAt)
+    {
+        return mLookAt->getLookAtType();
+    }
+    return LOOKAT_TARGET_NONE;
 }
 
 EPointAtType LLAgentCamera::getPointAtType()
-{ 
-	if (mPointAt) 
-	{
-		return mPointAt->getPointAtType();
-	}
-	return POINTAT_TARGET_NONE;
+{
+    if (mPointAt)
+    {
+        return mPointAt->getPointAtType();
+    }
+    return POINTAT_TARGET_NONE;
 }
 
 void LLAgentCamera::clearGeneralKeys()
 {
-	mAtKey 				= 0;
-	mWalkKey 			= 0;
-	mLeftKey 			= 0;
-	mUpKey 				= 0;
-	mYawKey 			= 0.f;
-	mPitchKey 			= 0.f;
+    mAtKey              = 0;
+    mWalkKey            = 0;
+    mLeftKey            = 0;
+    mUpKey              = 0;
+    mYawKey             = 0.f;
+    mPitchKey           = 0.f;
 }
 
 void LLAgentCamera::clearOrbitKeys()
 {
-	mOrbitLeftKey		= 0.f;
-	mOrbitRightKey		= 0.f;
-	mOrbitUpKey			= 0.f;
-	mOrbitDownKey		= 0.f;
-	mOrbitInKey			= 0.f;
-	mOrbitOutKey		= 0.f;
-	mRollLeftKey		= 0.f;
-	mRollRightKey		= 0.f;
+    mOrbitLeftKey       = 0.f;
+    mOrbitRightKey      = 0.f;
+    mOrbitUpKey         = 0.f;
+    mOrbitDownKey       = 0.f;
+    mOrbitInKey         = 0.f;
+    mOrbitOutKey        = 0.f;
+    mRollLeftKey        = 0.f;
+    mRollRightKey       = 0.f;
 }
 
 void LLAgentCamera::clearPanKeys()
 {
-	mPanRightKey		= 0.f;
-	mPanLeftKey			= 0.f;
-	mPanUpKey			= 0.f;
-	mPanDownKey			= 0.f;
-	mPanInKey			= 0.f;
-	mPanOutKey			= 0.f;
+    mPanRightKey        = 0.f;
+    mPanLeftKey         = 0.f;
+    mPanUpKey           = 0.f;
+    mPanDownKey         = 0.f;
+    mPanInKey           = 0.f;
+    mPanOutKey          = 0.f;
 }
 
 // static
 S32 LLAgentCamera::directionToKey(S32 direction)
 {
-	if (direction > 0) return 1;
-	if (direction < 0) return -1;
-	return 0;
+    if (direction > 0) return 1;
+    if (direction < 0) return -1;
+    return 0;
 }
 
 void LLAgentCamera::storeCameraPosition()
 {
-	gSavedPerAccountSettings.setVector3d("ALStoredCameraPos", getCameraPositionGlobal());
+    gSavedPerAccountSettings.setVector3d("ALStoredCameraPos", getCameraPositionGlobal());
 
-	// get a vector pointing forward from the camera view manually, getFocusTargetGlobal() will
-	// not return useful values if the camera is in flycam mode or was just switched out of
-	// flycam  mode and not repositioned after
-	LLVector3d forward = LLVector3d(1.0, 0.0, 0.0) * LLViewerCamera::getInstance()->getQuaternion() + getCameraPositionGlobal();
-	gSavedPerAccountSettings.setVector3d("ALStoredCameraFocus", forward);
-	gSavedPerAccountSettings.setF32("ALStoredCameraRoll", mRollAngle);
+    // get a vector pointing forward from the camera view manually, getFocusTargetGlobal() will
+    // not return useful values if the camera is in flycam mode or was just switched out of
+    // flycam  mode and not repositioned after
+    LLVector3d forward = LLVector3d(1.0, 0.0, 0.0) * LLViewerCamera::getInstance()->getQuaternion() + getCameraPositionGlobal();
+    gSavedPerAccountSettings.setVector3d("ALStoredCameraFocus", forward);
+    gSavedPerAccountSettings.setF32("ALStoredCameraRoll", mRollAngle);
 
-	LLUUID stored_camera_focus_object_id = LLUUID::null;
-	if (mFocusObject)
-	{
-		stored_camera_focus_object_id = mFocusObject->getID();
-	}
-	gSavedPerAccountSettings.setString("ALStoredCameraFocusObjectId", stored_camera_focus_object_id.asString());
+    LLUUID stored_camera_focus_object_id = LLUUID::null;
+    if (mFocusObject)
+    {
+        stored_camera_focus_object_id = mFocusObject->getID();
+    }
+    gSavedPerAccountSettings.setString("ALStoredCameraFocusObjectId", stored_camera_focus_object_id.asString());
 }
 
 void LLAgentCamera::loadCameraPosition()
 {
-	LLVector3d stored_camera_pos = gSavedPerAccountSettings.getVector3d("ALStoredCameraPos");
-	LLVector3d stored_camera_focus = gSavedPerAccountSettings.getVector3d("ALStoredCameraFocus");
-	F32 stored_camera_roll = gSavedPerAccountSettings.getF32("ALStoredCameraRoll");
-	LLUUID stored_camera_focus_object_id = LLUUID(gSavedPerAccountSettings.getString("ALStoredCameraFocusObjectId"));
+    LLVector3d stored_camera_pos = gSavedPerAccountSettings.getVector3d("ALStoredCameraPos");
+    LLVector3d stored_camera_focus = gSavedPerAccountSettings.getVector3d("ALStoredCameraFocus");
+    F32 stored_camera_roll = gSavedPerAccountSettings.getF32("ALStoredCameraRoll");
+    LLUUID stored_camera_focus_object_id = LLUUID(gSavedPerAccountSettings.getString("ALStoredCameraFocusObjectId"));
 
-	F32 renderFarClip = gSavedSettings.getF32("RenderFarClip");
-	F32 far_clip_squared = renderFarClip * renderFarClip;
+    F32 renderFarClip = gSavedSettings.getF32("RenderFarClip");
+    F32 far_clip_squared = renderFarClip * renderFarClip;
 
-	if (stored_camera_pos.isNull())
-	{
-		LLNotificationsUtil::add("LoadCameraPositionNoneSaved", LLSD());
-		return;
-	}
+    if (stored_camera_pos.isNull())
+    {
+        LLNotificationsUtil::add("LoadCameraPositionNoneSaved", LLSD());
+        return;
+    }
 
-	if (dist_vec_squared(gAgent.getPositionGlobal(), stored_camera_pos) > far_clip_squared)
-	{
-		LLNotificationsUtil::add("LoadCameraPositionOutsideDrawDistance", LLSD());
-		return;
-	}
+    if (dist_vec_squared(gAgent.getPositionGlobal(), stored_camera_pos) > far_clip_squared)
+    {
+        LLNotificationsUtil::add("LoadCameraPositionOutsideDrawDistance", LLSD());
+        return;
+    }
 
-	// switch off flycam mode if needed
-	if (LLViewerJoystick::getInstance()->getOverrideCamera())
-	{
-		handle_toggle_flycam();
+    // switch off flycam mode if needed
+    if (LLViewerJoystick::getInstance()->getOverrideCamera())
+    {
+        handle_toggle_flycam();
 
-		// exiting from flycam usually keeps the camera where it is but here we want it to actually move
-		LLViewerJoystick::getInstance()->setCameraNeedsUpdate(true);
-	}
+        // exiting from flycam usually keeps the camera where it is but here we want it to actually move
+        LLViewerJoystick::getInstance()->setCameraNeedsUpdate(true);
+    }
 
-	unlockView();
-	setCameraPosAndFocusGlobal(stored_camera_pos, stored_camera_focus, stored_camera_focus_object_id);
+    unlockView();
+    setCameraPosAndFocusGlobal(stored_camera_pos, stored_camera_focus, stored_camera_focus_object_id);
 
-	mRollAngle = stored_camera_roll;
+    mRollAngle = stored_camera_roll;
 }
 
 // EOF
diff --git a/indra/newview/llaisapi.cpp b/indra/newview/llaisapi.cpp
index 04d65b517c5a7682708291f8adb3704b3d637e53..77f8c64dd94e0b051b016fb1ecf294b757ebbec7 100644
--- a/indra/newview/llaisapi.cpp
+++ b/indra/newview/llaisapi.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llaisapi.cpp
- * @brief classes and functions for interfacing with the v3+ ais inventory service. 
+ * @brief classes and functions for interfacing with the v3+ ais inventory service.
  *
  * $LicenseInfo:firstyear=2013&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2013, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  *
@@ -95,7 +95,7 @@ std::string AISAPI::getLibCap()
     return std::string();
 }
 
-/*static*/ 
+/*static*/
 void AISAPI::CreateInventory(const LLUUID& parentId, const LLSD& newInventory, completion_t callback)
 {
     std::string cap = getInvCap();
@@ -115,15 +115,15 @@ void AISAPI::CreateInventory(const LLUUID& parentId, const LLSD& newInventory, c
     std::string url = cap + std::string("/category/") + parentId.asString() + "?tid=" + tid.asString();
     LL_DEBUGS("Inventory") << "url: " << url << " parentID " << parentId << " newInventory " << newInventory << LL_ENDL;
 
-    // I may be suffering from golden hammer here, but the first part of this bind 
-    // is actually a static cast for &HttpCoroutineAdapter::postAndSuspend so that 
+    // I may be suffering from golden hammer here, but the first part of this bind
+    // is actually a static cast for &HttpCoroutineAdapter::postAndSuspend so that
     // the compiler can identify the correct signature to select.
-    // 
+    //
     // Reads as follows:
     // LLSD     - method returning LLSD
     // (LLCoreHttpUtil::HttpCoroutineAdapter::*) - pointer to member function of HttpCoroutineAdapter
     // (LLCore::HttpRequest::ptr_t, const std::string &, const LLSD &, LLCore::HttpOptions::ptr_t, LLCore::HttpHeaders::ptr_t) - signature of method
-    //  
+    //
     invokationFn_t postFn = boost::bind(
         // Humans ignore next line.  It is just a cast.
         static_cast<LLSD (LLCoreHttpUtil::HttpCoroutineAdapter::*)(LLCore::HttpRequest::ptr_t, const std::string &, const LLSD &, LLCore::HttpOptions::ptr_t, LLCore::HttpHeaders::ptr_t)>
@@ -131,7 +131,7 @@ void AISAPI::CreateInventory(const LLUUID& parentId, const LLSD& newInventory, c
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::postAndSuspend), _1, _2, _3, _4, _5, _6);
@@ -141,7 +141,7 @@ void AISAPI::CreateInventory(const LLUUID& parentId, const LLSD& newInventory, c
     EnqueueAISCommand("CreateInventory", proc);
 }
 
-/*static*/ 
+/*static*/
 void AISAPI::SlamFolder(const LLUUID& folderId, const LLSD& newInventory, completion_t callback)
 {
     std::string cap = getInvCap();
@@ -168,7 +168,7 @@ void AISAPI::SlamFolder(const LLUUID& folderId, const LLSD& newInventory, comple
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::putAndSuspend), _1, _2, _3, _4, _5, _6);
@@ -204,7 +204,7 @@ void AISAPI::RemoveCategory(const LLUUID &categoryId, completion_t callback)
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndSuspend), _1, _2, _3, _5, _6);
@@ -215,7 +215,7 @@ void AISAPI::RemoveCategory(const LLUUID &categoryId, completion_t callback)
     EnqueueAISCommand("RemoveCategory", proc);
 }
 
-/*static*/ 
+/*static*/
 void AISAPI::RemoveItem(const LLUUID &itemId, completion_t callback)
 {
     std::string cap;
@@ -241,7 +241,7 @@ void AISAPI::RemoveItem(const LLUUID &itemId, completion_t callback)
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndSuspend), _1, _2, _3, _5, _6);
@@ -288,18 +288,18 @@ void AISAPI::CopyLibraryCategory(const LLUUID& sourceId, const LLUUID& destId, b
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::copyAndSuspend), _1, _2, _3, destination, _5, _6);
-         
+
     LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro,
         _1, copyFn, url, destId, LLSD(), callback, COPYLIBRARYCATEGORY));
 
     EnqueueAISCommand("CopyLibraryCategory", proc);
 }
 
-/*static*/ 
+/*static*/
 void AISAPI::PurgeDescendents(const LLUUID &categoryId, completion_t callback)
 {
     std::string cap;
@@ -325,7 +325,7 @@ void AISAPI::PurgeDescendents(const LLUUID &categoryId, completion_t callback)
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::deleteAndSuspend), _1, _2, _3, _5, _6);
@@ -361,7 +361,7 @@ void AISAPI::UpdateCategory(const LLUUID &categoryId, const LLSD &updates, compl
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndSuspend), _1, _2, _3, _4, _5, _6);
@@ -397,7 +397,7 @@ void AISAPI::UpdateItem(const LLUUID &itemId, const LLSD &updates, completion_t
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::patchAndSuspend), _1, _2, _3, _4, _5, _6);
@@ -411,36 +411,36 @@ void AISAPI::UpdateItem(const LLUUID &itemId, const LLSD &updates, completion_t
 /*static*/
 void AISAPI::FetchItem(const LLUUID &itemId, ITEM_TYPE type, completion_t callback)
 {
-	std::string cap;
+    std::string cap;
 
-	cap = (type == INVENTORY) ? getInvCap() : getLibCap();
-	if (cap.empty())
-	{
-		LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL;
+    cap = (type == INVENTORY) ? getInvCap() : getLibCap();
+    if (cap.empty())
+    {
+        LL_WARNS("Inventory") << "Inventory cap not found!" << LL_ENDL;
         if (callback)
         {
             callback(LLUUID::null);
         }
-		return;
-	}
-	std::string url = cap + std::string("/item/") + itemId.asString();
-
-	invokationFn_t getFn = boost::bind(
-		// Humans ignore next line.  It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload.
-		static_cast<LLSD(LLCoreHttpUtil::HttpCoroutineAdapter::*)(LLCore::HttpRequest::ptr_t, const std::string &, LLCore::HttpOptions::ptr_t, LLCore::HttpHeaders::ptr_t)>
-		//----
-		// _1 -> httpAdapter
-		// _2 -> httpRequest
-		// _3 -> url
-		// _4 -> body 
-		// _5 -> httpOptions
-		// _6 -> httpHeaders
-		(&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend), _1, _2, _3, _5, _6);
-
-	LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro,
-		_1, getFn, url, itemId, LLSD(), callback, FETCHITEM));
-
-	EnqueueAISCommand("FetchItem", proc);
+        return;
+    }
+    std::string url = cap + std::string("/item/") + itemId.asString();
+
+    invokationFn_t getFn = boost::bind(
+        // Humans ignore next line.  It is just a cast to specify which LLCoreHttpUtil::HttpCoroutineAdapter routine overload.
+        static_cast<LLSD(LLCoreHttpUtil::HttpCoroutineAdapter::*)(LLCore::HttpRequest::ptr_t, const std::string &, LLCore::HttpOptions::ptr_t, LLCore::HttpHeaders::ptr_t)>
+        //----
+        // _1 -> httpAdapter
+        // _2 -> httpRequest
+        // _3 -> url
+        // _4 -> body
+        // _5 -> httpOptions
+        // _6 -> httpHeaders
+        (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend), _1, _2, _3, _5, _6);
+
+    LLCoprocedureManager::CoProcedure_t proc(boost::bind(&AISAPI::InvokeAISCommandCoro,
+        _1, getFn, url, itemId, LLSD(), callback, FETCHITEM));
+
+    EnqueueAISCommand("FetchItem", proc);
 }
 
 /*static*/
@@ -480,7 +480,7 @@ void AISAPI::FetchCategoryChildren(const LLUUID &catId, ITEM_TYPE type, bool rec
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend), _1, _2, _3, _5, _6);
@@ -533,7 +533,7 @@ void AISAPI::FetchCategoryChildren(const std::string &identifier, bool recursive
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend), _1, _2, _3, _5, _6);
@@ -584,7 +584,7 @@ void AISAPI::FetchCategoryCategories(const LLUUID &catId, ITEM_TYPE type, bool r
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend), _1, _2, _3, _5, _6);
@@ -661,7 +661,7 @@ void AISAPI::FetchCategorySubset(const LLUUID& catId,
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend), _1, _2, _3, _5, _6);
@@ -698,7 +698,7 @@ void AISAPI::FetchCOF(completion_t callback)
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend), _1, _2, _3, _5, _6);
@@ -771,7 +771,7 @@ void AISAPI::FetchOrphans(completion_t callback)
         // _1 -> httpAdapter
         // _2 -> httpRequest
         // _3 -> url
-        // _4 -> body 
+        // _4 -> body
         // _5 -> httpOptions
         // _6 -> httpHeaders
         (&LLCoreHttpUtil::HttpCoroutineAdapter::getAndSuspend) , _1 , _2 , _3 , _5 , _6);
@@ -824,7 +824,7 @@ void AISAPI::onIdle(void *userdata)
             pending_in_pool++;
         }
     }
-    
+
     if (sPostponedQuery.empty())
     {
         // Nothing to do anymore
@@ -848,8 +848,8 @@ void AISAPI::onUpdateReceived(const LLSD& update, COMMAND_TYPE type, const LLSD&
 }
 
 /*static*/
-void AISAPI::InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, 
-        invokationFn_t invoke, std::string url, 
+void AISAPI::InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter,
+        invokationFn_t invoke, std::string url,
         LLUUID targetId, LLSD body, completion_t callback, COMMAND_TYPE type)
 {
     if (gDisconnected)
@@ -947,7 +947,7 @@ void AISAPI::InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t ht
         LL_WARNS("Inventory") << ll_pretty_print_sd(result) << LL_ENDL;
     }
 
-	LL_DEBUGS("Inventory", "AIS3") << "Result: " << result << LL_ENDL;
+    LL_DEBUGS("Inventory", "AIS3") << "Result: " << result << LL_ENDL;
     onUpdateReceived(result, type, body);
 
     if (callback && !callback.empty())
@@ -1038,22 +1038,22 @@ AISUpdate::AISUpdate(const LLSD& update, AISAPI::COMMAND_TYPE type, const LLSD&
 
     mTimer.setTimerExpirySec(AIS_EXPIRY_SECONDS);
     mTimer.start();
-	parseUpdate(update);
+    parseUpdate(update);
 }
 
 void AISUpdate::clearParseResults()
 {
-	mCatDescendentDeltas.clear();
-	mCatDescendentsKnown.clear();
-	mCatVersionsUpdated.clear();
-	mItemsCreated.clear();
+    mCatDescendentDeltas.clear();
+    mCatDescendentsKnown.clear();
+    mCatVersionsUpdated.clear();
+    mItemsCreated.clear();
     mItemsLost.clear();
-	mItemsUpdated.clear();
-	mCategoriesCreated.clear();
-	mCategoriesUpdated.clear();
-	mObjectsDeletedIds.clear();
-	mItemIds.clear();
-	mCategoryIds.clear();
+    mItemsUpdated.clear();
+    mCategoriesCreated.clear();
+    mCategoriesUpdated.clear();
+    mObjectsDeletedIds.clear();
+    mItemIds.clear();
+    mCategoryIds.clear();
 }
 
 void AISUpdate::checkTimeout()
@@ -1068,87 +1068,87 @@ void AISUpdate::checkTimeout()
 
 void AISUpdate::parseUpdate(const LLSD& update)
 {
-	clearParseResults();
-	parseMeta(update);
-	parseContent(update);
+    clearParseResults();
+    parseMeta(update);
+    parseContent(update);
 }
 
 void AISUpdate::parseMeta(const LLSD& update)
 {
-	// parse _categories_removed -> mObjectsDeletedIds
-	uuid_list_t cat_ids;
-	parseUUIDArray(update,"_categories_removed",cat_ids);
-	for (uuid_list_t::const_iterator it = cat_ids.begin();
-		 it != cat_ids.end(); ++it)
-	{
-		LLViewerInventoryCategory *cat = gInventory.getCategory(*it);
-		if(cat)
-		{
-			mCatDescendentDeltas[cat->getParentUUID()]--;
-			mObjectsDeletedIds.insert(*it);
-		}
-		else
-		{
-			LL_WARNS("Inventory") << "removed category not found " << *it << LL_ENDL;
-		}
-	}
-
-	// parse _categories_items_removed -> mObjectsDeletedIds
-	uuid_list_t item_ids;
-	parseUUIDArray(update,"_category_items_removed",item_ids);
-	parseUUIDArray(update,"_removed_items",item_ids);
-	for (uuid_list_t::const_iterator it = item_ids.begin();
-		 it != item_ids.end(); ++it)
-	{
-		LLViewerInventoryItem *item = gInventory.getItem(*it);
-		if(item)
-		{
-			mCatDescendentDeltas[item->getParentUUID()]--;
-			mObjectsDeletedIds.insert(*it);
-		}
-		else
-		{
-			LL_WARNS("Inventory") << "removed item not found " << *it << LL_ENDL;
-		}
-	}
-
-	// parse _broken_links_removed -> mObjectsDeletedIds
-	uuid_list_t broken_link_ids;
-	parseUUIDArray(update,"_broken_links_removed",broken_link_ids);
-	for (uuid_list_t::const_iterator it = broken_link_ids.begin();
-		 it != broken_link_ids.end(); ++it)
-	{
-		LLViewerInventoryItem *item = gInventory.getItem(*it);
-		if(item)
-		{
-			mCatDescendentDeltas[item->getParentUUID()]--;
-			mObjectsDeletedIds.insert(*it);
-		}
-		else
-		{
-			LL_WARNS("Inventory") << "broken link not found " << *it << LL_ENDL;
-		}
-	}
-
-	// parse _created_items
-	parseUUIDArray(update,"_created_items",mItemIds);
-
-	// parse _created_categories
-	parseUUIDArray(update,"_created_categories",mCategoryIds);
-
-	// Parse updated category versions.
-	const std::string& ucv = "_updated_category_versions";
-	if (update.has(ucv))
-	{
-		for(LLSD::map_const_iterator it = update[ucv].beginMap(),
-				end = update[ucv].endMap();
-			it != end; ++it)
-		{
-			const LLUUID id((*it).first);
-			S32 version = (*it).second.asInteger();
-			mCatVersionsUpdated[id] = version;
-		}
-	}
+    // parse _categories_removed -> mObjectsDeletedIds
+    uuid_list_t cat_ids;
+    parseUUIDArray(update,"_categories_removed",cat_ids);
+    for (uuid_list_t::const_iterator it = cat_ids.begin();
+         it != cat_ids.end(); ++it)
+    {
+        LLViewerInventoryCategory *cat = gInventory.getCategory(*it);
+        if(cat)
+        {
+            mCatDescendentDeltas[cat->getParentUUID()]--;
+            mObjectsDeletedIds.insert(*it);
+        }
+        else
+        {
+            LL_WARNS("Inventory") << "removed category not found " << *it << LL_ENDL;
+        }
+    }
+
+    // parse _categories_items_removed -> mObjectsDeletedIds
+    uuid_list_t item_ids;
+    parseUUIDArray(update,"_category_items_removed",item_ids);
+    parseUUIDArray(update,"_removed_items",item_ids);
+    for (uuid_list_t::const_iterator it = item_ids.begin();
+         it != item_ids.end(); ++it)
+    {
+        LLViewerInventoryItem *item = gInventory.getItem(*it);
+        if(item)
+        {
+            mCatDescendentDeltas[item->getParentUUID()]--;
+            mObjectsDeletedIds.insert(*it);
+        }
+        else
+        {
+            LL_WARNS("Inventory") << "removed item not found " << *it << LL_ENDL;
+        }
+    }
+
+    // parse _broken_links_removed -> mObjectsDeletedIds
+    uuid_list_t broken_link_ids;
+    parseUUIDArray(update,"_broken_links_removed",broken_link_ids);
+    for (uuid_list_t::const_iterator it = broken_link_ids.begin();
+         it != broken_link_ids.end(); ++it)
+    {
+        LLViewerInventoryItem *item = gInventory.getItem(*it);
+        if(item)
+        {
+            mCatDescendentDeltas[item->getParentUUID()]--;
+            mObjectsDeletedIds.insert(*it);
+        }
+        else
+        {
+            LL_WARNS("Inventory") << "broken link not found " << *it << LL_ENDL;
+        }
+    }
+
+    // parse _created_items
+    parseUUIDArray(update,"_created_items",mItemIds);
+
+    // parse _created_categories
+    parseUUIDArray(update,"_created_categories",mCategoryIds);
+
+    // Parse updated category versions.
+    const std::string& ucv = "_updated_category_versions";
+    if (update.has(ucv))
+    {
+        for(LLSD::map_const_iterator it = update[ucv].beginMap(),
+                end = update[ucv].endMap();
+            it != end; ++it)
+        {
+            const LLUUID id((*it).first);
+            S32 version = (*it).second.asInteger();
+            mCatVersionsUpdated[id] = version;
+        }
+    }
 }
 
 void AISUpdate::parseContent(const LLSD& update)
@@ -1157,14 +1157,14 @@ void AISUpdate::parseContent(const LLSD& update)
     // full item or folder.
     // Todo: Depending on error we might want to do something,
     // like removing a 404 item or refetching parent folder
-	if (update.has("linked_id") && update.has("parent_id"))
-	{
-		parseLink(update, mFetchDepth);
-	}
-	else if (update.has("item_id") && update.has("parent_id"))
-	{
-		parseItem(update);
-	}
+    if (update.has("linked_id") && update.has("parent_id"))
+    {
+        parseLink(update, mFetchDepth);
+    }
+    else if (update.has("item_id") && update.has("parent_id"))
+    {
+        parseItem(update);
+    }
 
     if (mType == AISAPI::FETCHCATEGORYSUBSET)
     {
@@ -1179,28 +1179,28 @@ void AISUpdate::parseContent(const LLSD& update)
     {
         parseCategory(update, mFetchDepth);
     }
-	else
-	{
-		if (update.has("_embedded"))
-		{
-			parseEmbedded(update["_embedded"], mFetchDepth);
-		}
-	}
+    else
+    {
+        if (update.has("_embedded"))
+        {
+            parseEmbedded(update["_embedded"], mFetchDepth);
+        }
+    }
 }
 
 void AISUpdate::parseItem(const LLSD& item_map)
 {
-	LLUUID item_id = item_map["item_id"].asUUID();
-	LLPointer<LLViewerInventoryItem> new_item(new LLViewerInventoryItem);
-	LLViewerInventoryItem *curr_item = gInventory.getItem(item_id);
-	if (curr_item)
-	{
-		// Default to current values where not provided.
-		new_item->copyViewerItem(curr_item);
-	}
-	BOOL rv = new_item->unpackMessage(item_map);
-	if (rv)
-	{
+    LLUUID item_id = item_map["item_id"].asUUID();
+    LLPointer<LLViewerInventoryItem> new_item(new LLViewerInventoryItem);
+    LLViewerInventoryItem *curr_item = gInventory.getItem(item_id);
+    if (curr_item)
+    {
+        // Default to current values where not provided.
+        new_item->copyViewerItem(curr_item);
+    }
+    BOOL rv = new_item->unpackMessage(item_map);
+    if (rv)
+    {
         if (mFetch)
         {
             mItemsCreated[item_id] = new_item;
@@ -1212,41 +1212,41 @@ void AISUpdate::parseItem(const LLSD& item_map)
             }
         }
         else if (curr_item)
-		{
-			mItemsUpdated[item_id] = new_item;
-			// This statement is here to cause a new entry with 0
-			// delta to be created if it does not already exist;
-			// otherwise has no effect.
-			mCatDescendentDeltas[new_item->getParentUUID()];
-		}
-		else
-		{
-			mItemsCreated[item_id] = new_item;
-			mCatDescendentDeltas[new_item->getParentUUID()]++;
+        {
+            mItemsUpdated[item_id] = new_item;
+            // This statement is here to cause a new entry with 0
+            // delta to be created if it does not already exist;
+            // otherwise has no effect.
+            mCatDescendentDeltas[new_item->getParentUUID()];
+        }
+        else
+        {
+            mItemsCreated[item_id] = new_item;
+            mCatDescendentDeltas[new_item->getParentUUID()]++;
             new_item->setComplete(true);
-		}
-	}
-	else
-	{
-		// *TODO: Wow, harsh.  Should we just complain and get out?
-		LL_ERRS() << "unpack failed" << LL_ENDL;
-	}
+        }
+    }
+    else
+    {
+        // *TODO: Wow, harsh.  Should we just complain and get out?
+        LL_ERRS() << "unpack failed" << LL_ENDL;
+    }
 }
 
 void AISUpdate::parseLink(const LLSD& link_map, S32 depth)
 {
-	LLUUID item_id = link_map["item_id"].asUUID();
-	LLPointer<LLViewerInventoryItem> new_link(new LLViewerInventoryItem);
-	LLViewerInventoryItem *curr_link = gInventory.getItem(item_id);
-	if (curr_link)
-	{
-		// Default to current values where not provided.
-		new_link->copyViewerItem(curr_link);
-	}
-	BOOL rv = new_link->unpackMessage(link_map);
-	if (rv)
-	{
-		const LLUUID& parent_id = new_link->getParentUUID();
+    LLUUID item_id = link_map["item_id"].asUUID();
+    LLPointer<LLViewerInventoryItem> new_link(new LLViewerInventoryItem);
+    LLViewerInventoryItem *curr_link = gInventory.getItem(item_id);
+    if (curr_link)
+    {
+        // Default to current values where not provided.
+        new_link->copyViewerItem(curr_link);
+    }
+    BOOL rv = new_link->unpackMessage(link_map);
+    if (rv)
+    {
+        const LLUUID& parent_id = new_link->getParentUUID();
         if (mFetch)
         {
             LLPermissions default_perms;
@@ -1264,38 +1264,38 @@ void AISUpdate::parseLink(const LLSD& link_map, S32 depth)
                 mItemsLost[item_id] = new_link;
             }
         }
-		else if (curr_link)
-		{
-			mItemsUpdated[item_id] = new_link;
-			// This statement is here to cause a new entry with 0
-			// delta to be created if it does not already exist;
-			// otherwise has no effect.
-			mCatDescendentDeltas[parent_id];
-		}
-		else
-		{
-			LLPermissions default_perms;
-			default_perms.init(gAgent.getID(),gAgent.getID(),LLUUID::null,LLUUID::null);
-			default_perms.initMasks(PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE);
-			new_link->setPermissions(default_perms);
-			LLSaleInfo default_sale_info;
-			new_link->setSaleInfo(default_sale_info);
-			//LL_DEBUGS("Inventory") << "creating link from llsd: " << ll_pretty_print_sd(link_map) << LL_ENDL;
-			mItemsCreated[item_id] = new_link;
-			mCatDescendentDeltas[parent_id]++;
+        else if (curr_link)
+        {
+            mItemsUpdated[item_id] = new_link;
+            // This statement is here to cause a new entry with 0
+            // delta to be created if it does not already exist;
+            // otherwise has no effect.
+            mCatDescendentDeltas[parent_id];
+        }
+        else
+        {
+            LLPermissions default_perms;
+            default_perms.init(gAgent.getID(),gAgent.getID(),LLUUID::null,LLUUID::null);
+            default_perms.initMasks(PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE,PERM_NONE);
+            new_link->setPermissions(default_perms);
+            LLSaleInfo default_sale_info;
+            new_link->setSaleInfo(default_sale_info);
+            //LL_DEBUGS("Inventory") << "creating link from llsd: " << ll_pretty_print_sd(link_map) << LL_ENDL;
+            mItemsCreated[item_id] = new_link;
+            mCatDescendentDeltas[parent_id]++;
             new_link->setComplete(true);
-		}
+        }
 
         if (link_map.has("_embedded"))
         {
             parseEmbedded(link_map["_embedded"], depth);
         }
-	}
-	else
-	{
-		// *TODO: Wow, harsh.  Should we just complain and get out?
-		LL_ERRS() << "unpack failed" << LL_ENDL;
-	}
+    }
+    else
+    {
+        // *TODO: Wow, harsh.  Should we just complain and get out?
+        LL_ERRS() << "unpack failed" << LL_ENDL;
+    }
 }
 
 
@@ -1331,10 +1331,10 @@ void AISUpdate::parseCategory(const LLSD& category_map, S32 depth)
         return;
     }
 
-	LLPointer<LLViewerInventoryCategory> new_cat;
-	if (curr_cat)
-	{
-		// Default to current values where not provided.
+    LLPointer<LLViewerInventoryCategory> new_cat;
+    if (curr_cat)
+    {
+        // Default to current values where not provided.
         new_cat = new LLViewerInventoryCategory(curr_cat);
     }
     else
@@ -1349,10 +1349,10 @@ void AISUpdate::parseCategory(const LLSD& category_map, S32 depth)
             new_cat = new LLViewerInventoryCategory(LLUUID::null);
         }
     }
-	BOOL rv = new_cat->unpackMessage(category_map);
-	// *NOTE: unpackMessage does not unpack version or descendent count.
-	if (rv)
-	{
+    BOOL rv = new_cat->unpackMessage(category_map);
+    // *NOTE: unpackMessage does not unpack version or descendent count.
+    if (rv)
+    {
         // Check descendent count first, as it may be needed
         // to populate newly created categories
         if (category_map.has("_embedded"))
@@ -1402,19 +1402,19 @@ void AISUpdate::parseCategory(const LLSD& category_map, S32 depth)
             }
             mCategoriesCreated[category_id] = new_cat;
         }
-		else if (curr_cat)
-		{
-			mCategoriesUpdated[category_id] = new_cat;
-			// This statement is here to cause a new entry with 0
-			// delta to be created if it does not already exist;
-			// otherwise has no effect.
-			mCatDescendentDeltas[new_cat->getParentUUID()];
-			// Capture update for the category itself as well.
-			mCatDescendentDeltas[category_id];
-		}
-		else
-		{
-			// Set version/descendents for newly created categories.
+        else if (curr_cat)
+        {
+            mCategoriesUpdated[category_id] = new_cat;
+            // This statement is here to cause a new entry with 0
+            // delta to be created if it does not already exist;
+            // otherwise has no effect.
+            mCatDescendentDeltas[new_cat->getParentUUID()];
+            // Capture update for the category itself as well.
+            mCatDescendentDeltas[category_id];
+        }
+        else
+        {
+            // Set version/descendents for newly created categories.
             uuid_int_map_t::const_iterator lookup_it = mCatDescendentsKnown.find(category_id);
             if (mCatDescendentsKnown.end() != lookup_it)
             {
@@ -1431,22 +1431,22 @@ void AISUpdate::parseCategory(const LLSD& category_map, S32 depth)
                         << " for new category " << category_id << LL_ENDL;
                     new_cat->setVersion(version);
                 }
-			}
-			mCategoriesCreated[category_id] = new_cat;
-			mCatDescendentDeltas[new_cat->getParentUUID()]++;
-		}
-	}
-	else
-	{
-		// *TODO: Wow, harsh.  Should we just complain and get out?
-		LL_ERRS() << "unpack failed" << LL_ENDL;
-	}
-
-	// Check for more embedded content.
-	if (category_map.has("_embedded"))
-	{
-		parseEmbedded(category_map["_embedded"], depth - 1);
-	}
+            }
+            mCategoriesCreated[category_id] = new_cat;
+            mCatDescendentDeltas[new_cat->getParentUUID()]++;
+        }
+    }
+    else
+    {
+        // *TODO: Wow, harsh.  Should we just complain and get out?
+        LL_ERRS() << "unpack failed" << LL_ENDL;
+    }
+
+    // Check for more embedded content.
+    if (category_map.has("_embedded"))
+    {
+        parseEmbedded(category_map["_embedded"], depth - 1);
+    }
 }
 
 void AISUpdate::parseDescendentCount(const LLUUID& category_id, LLFolderType::EType type, const LLSD& embedded)
@@ -1471,178 +1471,178 @@ void AISUpdate::parseEmbedded(const LLSD& embedded, S32 depth)
 {
     checkTimeout();
 
-	if (embedded.has("links")) // _embedded in a category
-	{
-		parseEmbeddedLinks(embedded["links"], depth);
-	}
-	if (embedded.has("items")) // _embedded in a category
-	{
-		parseEmbeddedItems(embedded["items"]);
-	}
-	if (embedded.has("item")) // _embedded in a link
-	{
-		parseEmbeddedItem(embedded["item"]);
-	}
-	if (embedded.has("categories")) // _embedded in a category
-	{
-		parseEmbeddedCategories(embedded["categories"], depth);
-	}
-	if (embedded.has("category")) // _embedded in a link
-	{
-		parseEmbeddedCategory(embedded["category"], depth);
-	}
+    if (embedded.has("links")) // _embedded in a category
+    {
+        parseEmbeddedLinks(embedded["links"], depth);
+    }
+    if (embedded.has("items")) // _embedded in a category
+    {
+        parseEmbeddedItems(embedded["items"]);
+    }
+    if (embedded.has("item")) // _embedded in a link
+    {
+        parseEmbeddedItem(embedded["item"]);
+    }
+    if (embedded.has("categories")) // _embedded in a category
+    {
+        parseEmbeddedCategories(embedded["categories"], depth);
+    }
+    if (embedded.has("category")) // _embedded in a link
+    {
+        parseEmbeddedCategory(embedded["category"], depth);
+    }
 }
 
 void AISUpdate::parseUUIDArray(const LLSD& content, const std::string_view name, uuid_list_t& ids)
 {
-	if (content.has(name))
-	{
-		for(const auto& sd : content[name].asArray())
-		{
-			ids.insert(sd.asUUID());
-		}
-	}
+    if (content.has(name))
+    {
+        for(const auto& sd : content[name].asArray())
+        {
+            ids.insert(sd.asUUID());
+        }
+    }
 }
 
 void AISUpdate::parseEmbeddedLinks(const LLSD& links, S32 depth)
 {
-	for(LLSD::map_const_iterator linkit = links.beginMap(),
-			linkend = links.endMap();
-		linkit != linkend; ++linkit)
-	{
-		const LLUUID link_id((*linkit).first);
-		const LLSD& link_map = (*linkit).second;
-		if (!mFetch && mItemIds.end() == mItemIds.find(link_id))
-		{
-			LL_DEBUGS("Inventory") << "Ignoring link not in items list " << link_id << LL_ENDL;
-		}
-		else
-		{
-			parseLink(link_map, depth);
-		}
-	}
+    for(LLSD::map_const_iterator linkit = links.beginMap(),
+            linkend = links.endMap();
+        linkit != linkend; ++linkit)
+    {
+        const LLUUID link_id((*linkit).first);
+        const LLSD& link_map = (*linkit).second;
+        if (!mFetch && mItemIds.end() == mItemIds.find(link_id))
+        {
+            LL_DEBUGS("Inventory") << "Ignoring link not in items list " << link_id << LL_ENDL;
+        }
+        else
+        {
+            parseLink(link_map, depth);
+        }
+    }
 }
 
 void AISUpdate::parseEmbeddedItem(const LLSD& item)
 {
-	// a single item (_embedded in a link)
-	if (item.has("item_id"))
-	{
-		if (mFetch || mItemIds.end() != mItemIds.find(item["item_id"].asUUID()))
-		{
-			parseItem(item);
-		}
-	}
+    // a single item (_embedded in a link)
+    if (item.has("item_id"))
+    {
+        if (mFetch || mItemIds.end() != mItemIds.find(item["item_id"].asUUID()))
+        {
+            parseItem(item);
+        }
+    }
 }
 
 void AISUpdate::parseEmbeddedItems(const LLSD& items)
 {
-	// a map of items (_embedded in a category)
-	for(LLSD::map_const_iterator itemit = items.beginMap(),
-			itemend = items.endMap();
-		itemit != itemend; ++itemit)
-	{
-		const LLUUID item_id((*itemit).first);
-		const LLSD& item_map = (*itemit).second;
-		if (!mFetch && mItemIds.end() == mItemIds.find(item_id))
-		{
-			LL_DEBUGS("Inventory") << "Ignoring item not in items list " << item_id << LL_ENDL;
-		}
-		else
-		{
-			parseItem(item_map);
-		}
-	}
+    // a map of items (_embedded in a category)
+    for(LLSD::map_const_iterator itemit = items.beginMap(),
+            itemend = items.endMap();
+        itemit != itemend; ++itemit)
+    {
+        const LLUUID item_id((*itemit).first);
+        const LLSD& item_map = (*itemit).second;
+        if (!mFetch && mItemIds.end() == mItemIds.find(item_id))
+        {
+            LL_DEBUGS("Inventory") << "Ignoring item not in items list " << item_id << LL_ENDL;
+        }
+        else
+        {
+            parseItem(item_map);
+        }
+    }
 }
 
 void AISUpdate::parseEmbeddedCategory(const LLSD& category, S32 depth)
 {
-	// a single category (_embedded in a link)
-	if (category.has("category_id"))
-	{
-		if (mFetch || mCategoryIds.end() != mCategoryIds.find(category["category_id"].asUUID()))
-		{
-			parseCategory(category, depth);
-		}
-	}
+    // a single category (_embedded in a link)
+    if (category.has("category_id"))
+    {
+        if (mFetch || mCategoryIds.end() != mCategoryIds.find(category["category_id"].asUUID()))
+        {
+            parseCategory(category, depth);
+        }
+    }
 }
 
 void AISUpdate::parseEmbeddedCategories(const LLSD& categories, S32 depth)
 {
-	// a map of categories (_embedded in a category)
-	for(LLSD::map_const_iterator categoryit = categories.beginMap(),
-			categoryend = categories.endMap();
-		categoryit != categoryend; ++categoryit)
-	{
-		const LLUUID category_id((*categoryit).first);
-		const LLSD& category_map = (*categoryit).second;
-		if (!mFetch && mCategoryIds.end() == mCategoryIds.find(category_id))
-		{
-			LL_DEBUGS("Inventory") << "Ignoring category not in categories list " << category_id << LL_ENDL;
-		}
-		else
-		{
-			parseCategory(category_map, depth);
-		}
-	}
+    // a map of categories (_embedded in a category)
+    for(LLSD::map_const_iterator categoryit = categories.beginMap(),
+            categoryend = categories.endMap();
+        categoryit != categoryend; ++categoryit)
+    {
+        const LLUUID category_id((*categoryit).first);
+        const LLSD& category_map = (*categoryit).second;
+        if (!mFetch && mCategoryIds.end() == mCategoryIds.find(category_id))
+        {
+            LL_DEBUGS("Inventory") << "Ignoring category not in categories list " << category_id << LL_ENDL;
+        }
+        else
+        {
+            parseCategory(category_map, depth);
+        }
+    }
 }
 
 void AISUpdate::doUpdate()
 {
     checkTimeout();
 
-	// Do version/descendant accounting.
-	for (auto catit = mCatDescendentDeltas.begin();
-		 catit != mCatDescendentDeltas.end(); ++catit)
-	{
+    // Do version/descendant accounting.
+    for (auto catit = mCatDescendentDeltas.begin();
+         catit != mCatDescendentDeltas.end(); ++catit)
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("Inventory") << "descendant accounting for " << catit->first << LL_ENDL;
+        LL_DEBUGS("Inventory") << "descendant accounting for " << catit->first << LL_ENDL;
 #endif
 
-		const LLUUID cat_id(catit->first);
-		// Don't account for update if we just created this category.
-		if (mCategoriesCreated.find(cat_id) != mCategoriesCreated.end())
-		{
-			LL_DEBUGS("Inventory") << "Skipping version increment for new category " << cat_id << LL_ENDL;
-			continue;
-		}
-
-		// Don't account for update unless AIS told us it updated that category.
-		if (mCatVersionsUpdated.find(cat_id) == mCatVersionsUpdated.end())
-		{
-			LL_DEBUGS("Inventory") << "Skipping version increment for non-updated category " << cat_id << LL_ENDL;
-			continue;
-		}
-
-		// If we have a known descendant count, set that now.
-		LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
-		if (cat)
-		{
-			S32 descendent_delta = catit->second;
-			S32 old_count = cat->getDescendentCount();
-			LL_DEBUGS("Inventory") << "Updating descendant count for "
-								   << cat->getName() << " " << cat_id
-								   << " with delta " << descendent_delta << " from "
-								   << old_count << " to " << (old_count+descendent_delta) << LL_ENDL;
-			LLInventoryModel::LLCategoryUpdate up(cat_id, descendent_delta);
-			gInventory.accountForUpdate(up);
-		}
-		else
-		{
-			LL_DEBUGS("Inventory") << "Skipping version accounting for unknown category " << cat_id << LL_ENDL;
-		}
-	}
-
-	// CREATE CATEGORIES
+        const LLUUID cat_id(catit->first);
+        // Don't account for update if we just created this category.
+        if (mCategoriesCreated.find(cat_id) != mCategoriesCreated.end())
+        {
+            LL_DEBUGS("Inventory") << "Skipping version increment for new category " << cat_id << LL_ENDL;
+            continue;
+        }
+
+        // Don't account for update unless AIS told us it updated that category.
+        if (mCatVersionsUpdated.find(cat_id) == mCatVersionsUpdated.end())
+        {
+            LL_DEBUGS("Inventory") << "Skipping version increment for non-updated category " << cat_id << LL_ENDL;
+            continue;
+        }
+
+        // If we have a known descendant count, set that now.
+        LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
+        if (cat)
+        {
+            S32 descendent_delta = catit->second;
+            S32 old_count = cat->getDescendentCount();
+            LL_DEBUGS("Inventory") << "Updating descendant count for "
+                                   << cat->getName() << " " << cat_id
+                                   << " with delta " << descendent_delta << " from "
+                                   << old_count << " to " << (old_count+descendent_delta) << LL_ENDL;
+            LLInventoryModel::LLCategoryUpdate up(cat_id, descendent_delta);
+            gInventory.accountForUpdate(up);
+        }
+        else
+        {
+            LL_DEBUGS("Inventory") << "Skipping version accounting for unknown category " << cat_id << LL_ENDL;
+        }
+    }
+
+    // CREATE CATEGORIES
     const S32 MAX_UPDATE_BACKLOG = 50; // stall prevention
-	for (deferred_category_map_t::const_iterator create_it = mCategoriesCreated.begin();
-		 create_it != mCategoriesCreated.end(); ++create_it)
-	{
-		LLUUID category_id(create_it->first);
-		LLPointer<LLViewerInventoryCategory> new_category = create_it->second;
+    for (deferred_category_map_t::const_iterator create_it = mCategoriesCreated.begin();
+         create_it != mCategoriesCreated.end(); ++create_it)
+    {
+        LLUUID category_id(create_it->first);
+        LLPointer<LLViewerInventoryCategory> new_category = create_it->second;
 
-		gInventory.updateCategory(new_category, LLInventoryObserver::CREATE);
-		LL_DEBUGS("Inventory") << "created category " << category_id << LL_ENDL;
+        gInventory.updateCategory(new_category, LLInventoryObserver::CREATE);
+        LL_DEBUGS("Inventory") << "created category " << category_id << LL_ENDL;
 
         // fetching can receive massive amount of items and folders
         if (gInventory.getChangedIDs().size() > MAX_UPDATE_BACKLOG)
@@ -1650,29 +1650,29 @@ void AISUpdate::doUpdate()
             gInventory.notifyObservers();
             checkTimeout();
         }
-	}
-
-	// UPDATE CATEGORIES
-	for (deferred_category_map_t::const_iterator update_it = mCategoriesUpdated.begin();
-		 update_it != mCategoriesUpdated.end(); ++update_it)
-	{
-		LLUUID category_id(update_it->first);
-		LLPointer<LLViewerInventoryCategory> new_category = update_it->second;
-		// Since this is a copy of the category *before* the accounting update, above,
-		// we need to transfer back the updated version/descendant count.
-		LLViewerInventoryCategory* curr_cat = gInventory.getCategory(new_category->getUUID());
-		if (!curr_cat)
-		{
-			LL_WARNS("Inventory") << "Failed to update unknown category " << new_category->getUUID() << LL_ENDL;
-		}
-		else
-		{
-			new_category->setVersion(curr_cat->getVersion());
-			new_category->setDescendentCount(curr_cat->getDescendentCount());
-			gInventory.updateCategory(new_category);
-			LL_DEBUGS("Inventory") << "updated category " << new_category->getName() << " " << category_id << LL_ENDL;
-		}
-	}
+    }
+
+    // UPDATE CATEGORIES
+    for (deferred_category_map_t::const_iterator update_it = mCategoriesUpdated.begin();
+         update_it != mCategoriesUpdated.end(); ++update_it)
+    {
+        LLUUID category_id(update_it->first);
+        LLPointer<LLViewerInventoryCategory> new_category = update_it->second;
+        // Since this is a copy of the category *before* the accounting update, above,
+        // we need to transfer back the updated version/descendant count.
+        LLViewerInventoryCategory* curr_cat = gInventory.getCategory(new_category->getUUID());
+        if (!curr_cat)
+        {
+            LL_WARNS("Inventory") << "Failed to update unknown category " << new_category->getUUID() << LL_ENDL;
+        }
+        else
+        {
+            new_category->setVersion(curr_cat->getVersion());
+            new_category->setDescendentCount(curr_cat->getDescendentCount());
+            gInventory.updateCategory(new_category);
+            LL_DEBUGS("Inventory") << "updated category " << new_category->getName() << " " << category_id << LL_ENDL;
+        }
+    }
 
     // LOST ITEMS
     if (!mItemsLost.empty())
@@ -1692,18 +1692,18 @@ void AISUpdate::doUpdate()
         }
     }
 
-	// CREATE ITEMS
-	for (deferred_item_map_t::const_iterator create_it = mItemsCreated.begin();
-		 create_it != mItemsCreated.end(); ++create_it)
-	{
-		LLUUID item_id(create_it->first);
-		LLPointer<LLViewerInventoryItem> new_item = create_it->second;
+    // CREATE ITEMS
+    for (deferred_item_map_t::const_iterator create_it = mItemsCreated.begin();
+         create_it != mItemsCreated.end(); ++create_it)
+    {
+        LLUUID item_id(create_it->first);
+        LLPointer<LLViewerInventoryItem> new_item = create_it->second;
 
-		// FIXME risky function since it calls updateServer() in some
-		// cases.  Maybe break out the update/create cases, in which
-		// case this is create.
-		LL_DEBUGS("Inventory") << "created item " << item_id << LL_ENDL;
-		gInventory.updateItem(new_item, LLInventoryObserver::CREATE);
+        // FIXME risky function since it calls updateServer() in some
+        // cases.  Maybe break out the update/create cases, in which
+        // case this is create.
+        LL_DEBUGS("Inventory") << "created item " << item_id << LL_ENDL;
+        gInventory.updateItem(new_item, LLInventoryObserver::CREATE);
 
         // fetching can receive massive amount of items and folders
         if (gInventory.getChangedIDs().size() > MAX_UPDATE_BACKLOG)
@@ -1711,48 +1711,48 @@ void AISUpdate::doUpdate()
             gInventory.notifyObservers();
             checkTimeout();
         }
-	}
-	
-	// UPDATE ITEMS
-	for (deferred_item_map_t::const_iterator update_it = mItemsUpdated.begin();
-		 update_it != mItemsUpdated.end(); ++update_it)
-	{
-		LLUUID item_id(update_it->first);
-		LLPointer<LLViewerInventoryItem> new_item = update_it->second;
-		// FIXME risky function since it calls updateServer() in some
-		// cases.  Maybe break out the update/create cases, in which
-		// case this is update.
-		LL_DEBUGS("Inventory") << "updated item " << item_id << LL_ENDL;
-		//LL_DEBUGS("Inventory") << ll_pretty_print_sd(new_item->asLLSD()) << LL_ENDL;
-		gInventory.updateItem(new_item);
-	}
-
-	// DELETE OBJECTS
-	for (uuid_list_t::const_iterator del_it = mObjectsDeletedIds.begin();
-		 del_it != mObjectsDeletedIds.end(); ++del_it)
-	{
-		LL_DEBUGS("Inventory") << "deleted item " << *del_it << LL_ENDL;
-		gInventory.onObjectDeletedFromServer(*del_it, false, false, false);
-	}
-
-	// TODO - how can we use this version info? Need to be sure all
-	// changes are going through AIS first, or at least through
-	// something with a reliable responder.
-	for (uuid_int_map_t::iterator ucv_it = mCatVersionsUpdated.begin();
-		 ucv_it != mCatVersionsUpdated.end(); ++ucv_it)
-	{
-		const LLUUID id = ucv_it->first;
-		S32 version = ucv_it->second;
-		LLViewerInventoryCategory *cat = gInventory.getCategory(id);
-		LL_DEBUGS("Inventory") << "cat version update " << cat->getName() << " to version " << cat->getVersion() << LL_ENDL;
-		if (cat->getVersion() != version)
-		{
-            // the AIS version should be considered the true version. Adjust 
-            // our local category model to reflect this version number.  Otherwise 
-            // it becomes possible to get stuck with the viewer being out of 
-            // sync with the inventory system.  Under normal circumstances 
-            // inventory COF is maintained on the viewer through calls to 
-            // LLInventoryModel::accountForUpdate when a changing operation 
+    }
+
+    // UPDATE ITEMS
+    for (deferred_item_map_t::const_iterator update_it = mItemsUpdated.begin();
+         update_it != mItemsUpdated.end(); ++update_it)
+    {
+        LLUUID item_id(update_it->first);
+        LLPointer<LLViewerInventoryItem> new_item = update_it->second;
+        // FIXME risky function since it calls updateServer() in some
+        // cases.  Maybe break out the update/create cases, in which
+        // case this is update.
+        LL_DEBUGS("Inventory") << "updated item " << item_id << LL_ENDL;
+        //LL_DEBUGS("Inventory") << ll_pretty_print_sd(new_item->asLLSD()) << LL_ENDL;
+        gInventory.updateItem(new_item);
+    }
+
+    // DELETE OBJECTS
+    for (uuid_list_t::const_iterator del_it = mObjectsDeletedIds.begin();
+         del_it != mObjectsDeletedIds.end(); ++del_it)
+    {
+        LL_DEBUGS("Inventory") << "deleted item " << *del_it << LL_ENDL;
+        gInventory.onObjectDeletedFromServer(*del_it, false, false, false);
+    }
+
+    // TODO - how can we use this version info? Need to be sure all
+    // changes are going through AIS first, or at least through
+    // something with a reliable responder.
+    for (uuid_int_map_t::iterator ucv_it = mCatVersionsUpdated.begin();
+         ucv_it != mCatVersionsUpdated.end(); ++ucv_it)
+    {
+        const LLUUID id = ucv_it->first;
+        S32 version = ucv_it->second;
+        LLViewerInventoryCategory *cat = gInventory.getCategory(id);
+        LL_DEBUGS("Inventory") << "cat version update " << cat->getName() << " to version " << cat->getVersion() << LL_ENDL;
+        if (cat->getVersion() != version)
+        {
+            // the AIS version should be considered the true version. Adjust
+            // our local category model to reflect this version number.  Otherwise
+            // it becomes possible to get stuck with the viewer being out of
+            // sync with the inventory system.  Under normal circumstances
+            // inventory COF is maintained on the viewer through calls to
+            // LLInventoryModel::accountForUpdate when a changing operation
             // is performed.  This occasionally gets out of sync however.
             if (version != LLViewerInventoryCategory::VERSION_UNKNOWN)
             {
@@ -1774,11 +1774,11 @@ void AISUpdate::doUpdate()
                 const S32 LONG_EXPIRY = 360;
                 cat->fetch(LONG_EXPIRY);
             }
-		}
-	}
+        }
+    }
 
     checkTimeout();
 
-	gInventory.notifyObservers();
+    gInventory.notifyObservers();
 }
 
diff --git a/indra/newview/llaisapi.h b/indra/newview/llaisapi.h
index 62c0a3bfa8e36b143b040e1dcfa3b6f9ce83dbb8..3206ef729ae62e1432c21f3bfff18bd9a6521732 100644
--- a/indra/newview/llaisapi.h
+++ b/indra/newview/llaisapi.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llaisapi.h
- * @brief classes and functions for interfacing with the v3+ ais inventory service. 
+ * @brief classes and functions for interfacing with the v3+ ais inventory service.
  *
  * $LicenseInfo:firstyear=2013&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2013, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -99,8 +99,8 @@ class AISAPI
     static std::string getInvCap();
     static std::string getLibCap();
 
-    static void InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter, 
-        invokationFn_t invoke, std::string url, LLUUID targetId, LLSD body, 
+    static void InvokeAISCommandCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter,
+        invokationFn_t invoke, std::string url, LLUUID targetId, LLSD body,
         completion_t callback, COMMAND_TYPE type);
 
     typedef std::pair<std::string, LLCoprocedureManager::CoProcedure_t> ais_query_item_t;
@@ -110,48 +110,48 @@ class AISAPI
 class AISUpdate
 {
 public:
-	AISUpdate(const LLSD& update, AISAPI::COMMAND_TYPE type, const LLSD& request_body);
-	void parseUpdate(const LLSD& update);
-	void parseMeta(const LLSD& update);
-	void parseContent(const LLSD& update);
-	void parseUUIDArray(const LLSD& content, const std::string_view name, uuid_list_t& ids);
-	void parseLink(const LLSD& link_map, S32 depth);
-	void parseItem(const LLSD& link_map);
-	void parseCategory(const LLSD& link_map, S32 depth);
-	void parseDescendentCount(const LLUUID& category_id, LLFolderType::EType type, const LLSD& embedded);
-	void parseEmbedded(const LLSD& embedded, S32 depth);
-	void parseEmbeddedLinks(const LLSD& links, S32 depth);
-	void parseEmbeddedItems(const LLSD& items);
-	void parseEmbeddedCategories(const LLSD& categories, S32 depth);
-	void parseEmbeddedItem(const LLSD& item);
-	void parseEmbeddedCategory(const LLSD& category, S32 depth);
-	void doUpdate();
+    AISUpdate(const LLSD& update, AISAPI::COMMAND_TYPE type, const LLSD& request_body);
+    void parseUpdate(const LLSD& update);
+    void parseMeta(const LLSD& update);
+    void parseContent(const LLSD& update);
+    void parseUUIDArray(const LLSD& content, const std::string_view name, uuid_list_t& ids);
+    void parseLink(const LLSD& link_map, S32 depth);
+    void parseItem(const LLSD& link_map);
+    void parseCategory(const LLSD& link_map, S32 depth);
+    void parseDescendentCount(const LLUUID& category_id, LLFolderType::EType type, const LLSD& embedded);
+    void parseEmbedded(const LLSD& embedded, S32 depth);
+    void parseEmbeddedLinks(const LLSD& links, S32 depth);
+    void parseEmbeddedItems(const LLSD& items);
+    void parseEmbeddedCategories(const LLSD& categories, S32 depth);
+    void parseEmbeddedItem(const LLSD& item);
+    void parseEmbeddedCategory(const LLSD& category, S32 depth);
+    void doUpdate();
 private:
-	void clearParseResults();
+    void clearParseResults();
     void checkTimeout();
 
     // Fetch can return large packets of data, throttle it to not cause lags
     // Todo: make throttle work over all fetch requests isntead of per-request
     const F32 AIS_EXPIRY_SECONDS = 0.008f;
 
-	typedef std::map<LLUUID,S32> uuid_int_map_t;
-	uuid_int_map_t mCatDescendentDeltas;
-	uuid_int_map_t mCatDescendentsKnown;
-	uuid_int_map_t mCatVersionsUpdated;
+    typedef std::map<LLUUID,S32> uuid_int_map_t;
+    uuid_int_map_t mCatDescendentDeltas;
+    uuid_int_map_t mCatDescendentsKnown;
+    uuid_int_map_t mCatVersionsUpdated;
 
-	typedef std::map<LLUUID,LLPointer<LLViewerInventoryItem> > deferred_item_map_t;
-	deferred_item_map_t mItemsCreated;
+    typedef std::map<LLUUID,LLPointer<LLViewerInventoryItem> > deferred_item_map_t;
+    deferred_item_map_t mItemsCreated;
     deferred_item_map_t mItemsLost;
-	deferred_item_map_t mItemsUpdated;
-	typedef std::map<LLUUID,LLPointer<LLViewerInventoryCategory> > deferred_category_map_t;
-	deferred_category_map_t mCategoriesCreated;
-	deferred_category_map_t mCategoriesUpdated;
-
-	// These keep track of uuid's mentioned in meta values.
-	// Useful for filtering out which content we are interested in.
-	uuid_list_t mObjectsDeletedIds;
-	uuid_list_t mItemIds;
-	uuid_list_t mCategoryIds;
+    deferred_item_map_t mItemsUpdated;
+    typedef std::map<LLUUID,LLPointer<LLViewerInventoryCategory> > deferred_category_map_t;
+    deferred_category_map_t mCategoriesCreated;
+    deferred_category_map_t mCategoriesUpdated;
+
+    // These keep track of uuid's mentioned in meta values.
+    // Useful for filtering out which content we are interested in.
+    uuid_list_t mObjectsDeletedIds;
+    uuid_list_t mItemIds;
+    uuid_list_t mCategoryIds;
     bool mFetch;
     S32 mFetchDepth;
     LLTimer mTimer;
diff --git a/indra/newview/llappearancemgr.cpp b/indra/newview/llappearancemgr.cpp
index 3a181b387ed24f3996d90ac9dccb5b4448a42d91..12d5d1c5548e009ebe7e26053069af7186d14bd9 100644
--- a/indra/newview/llappearancemgr.cpp
+++ b/indra/newview/llappearancemgr.cpp
@@ -1,29 +1,29 @@
-/** 
+/**
  * @file llappearancemgr.cpp
  * @brief Manager for initiating appearance changes on the viewer
  *
  * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
- 
+
 #include "llviewerprecompiledheaders.h"
 
 #include "llaccordionctrltab.h"
@@ -70,7 +70,7 @@
 
 #include "llavatarpropertiesprocessor.h"
 
-namespace 
+namespace
 {
     const S32   BAKE_RETRY_MAX_COUNT = 5;
     const F32   BAKE_RETRY_TIMEOUT = 2.0F;
@@ -86,8 +86,8 @@ void doAppearanceCb(LLPointer<LLInventoryCallback> cb, LLUUID id)
 
 std::string self_av_string()
 {
-	// On logout gAgentAvatarp can already be invalid
-	return isAgentAvatarValid() ? gAgentAvatarp->avString() : "";
+    // On logout gAgentAvatarp can already be invalid
+    return isAgentAvatarValid() ? gAgentAvatarp->avString() : "";
 }
 
 // RAII thingy to guarantee that a variable gets reset when the Setter
@@ -96,17 +96,17 @@ std::string self_av_string()
 class BoolSetter
 {
 public:
-	BoolSetter(bool& var):
-		mVar(var)
-	{
-		mVar = true;
-	}
-	~BoolSetter()
-	{
-		mVar = false; 
-	}
+    BoolSetter(bool& var):
+        mVar(var)
+    {
+        mVar = true;
+    }
+    ~BoolSetter()
+    {
+        mVar = false;
+    }
 private:
-	bool& mVar;
+    bool& mVar;
 };
 
 char ORDER_NUMBER_SEPARATOR('@');
@@ -114,54 +114,54 @@ char ORDER_NUMBER_SEPARATOR('@');
 class LLOutfitUnLockTimer: public LLEventTimer
 {
 public:
-	LLOutfitUnLockTimer(F32 period) : LLEventTimer(period)
-	{
-		// restart timer on BOF changed event
-		LLOutfitObserver::instance().addBOFChangedCallback(boost::bind(
-				&LLOutfitUnLockTimer::reset, this));
-		stop();
-	}
-
-	/*virtual*/
-	BOOL tick()
-	{
-		if(mEventTimer.hasExpired())
-		{
-			LLAppearanceMgr::instance().setOutfitLocked(false);
-		}
-		return FALSE;
-	}
-	void stop() { mEventTimer.stop(); }
-	void start() { mEventTimer.start(); }
-	void reset() { mEventTimer.reset(); }
-	BOOL getStarted() { return mEventTimer.getStarted(); }
-
-	LLTimer&  getEventTimer() { return mEventTimer;}
+    LLOutfitUnLockTimer(F32 period) : LLEventTimer(period)
+    {
+        // restart timer on BOF changed event
+        LLOutfitObserver::instance().addBOFChangedCallback(boost::bind(
+                &LLOutfitUnLockTimer::reset, this));
+        stop();
+    }
+
+    /*virtual*/
+    BOOL tick()
+    {
+        if(mEventTimer.hasExpired())
+        {
+            LLAppearanceMgr::instance().setOutfitLocked(false);
+        }
+        return FALSE;
+    }
+    void stop() { mEventTimer.stop(); }
+    void start() { mEventTimer.start(); }
+    void reset() { mEventTimer.reset(); }
+    BOOL getStarted() { return mEventTimer.getStarted(); }
+
+    LLTimer&  getEventTimer() { return mEventTimer;}
 };
 
 // support for secondlife:///app/appearance SLapps
 class LLAppearanceHandler : public LLCommandHandler
 {
 public:
-	// requests will be throttled from a non-trusted browser
-	LLAppearanceHandler() : LLCommandHandler("appearance", UNTRUSTED_THROTTLE) {}
+    // requests will be throttled from a non-trusted browser
+    LLAppearanceHandler() : LLCommandHandler("appearance", UNTRUSTED_THROTTLE) {}
 
-	bool handle(const LLSD& params,
+    bool handle(const LLSD& params,
                 const LLSD& query_map,
                 const std::string& grid,
                 LLMediaCtrl* web)
-	{
-		// support secondlife:///app/appearance/show, but for now we just
-		// make all secondlife:///app/appearance SLapps behave this way
-		if (!LLUI::getInstance()->mSettingGroups["config"]->getBOOL("EnableAppearance"))
-		{
-			LLNotificationsUtil::add("NoAppearance", LLSD(), LLSD(), std::string("SwitchToStandardSkinAndQuit"));
-			return true;
-		}
-
-		LLFloaterSidePanelContainer::showPanel("appearance", LLSD());
-		return true;
-	}
+    {
+        // support secondlife:///app/appearance/show, but for now we just
+        // make all secondlife:///app/appearance SLapps behave this way
+        if (!LLUI::getInstance()->mSettingGroups["config"]->getBOOL("EnableAppearance"))
+        {
+            LLNotificationsUtil::add("NoAppearance", LLSD(), LLSD(), std::string("SwitchToStandardSkinAndQuit"));
+            return true;
+        }
+
+        LLFloaterSidePanelContainer::showPanel("appearance", LLSD());
+        return true;
+    }
 };
 
 LLAppearanceHandler gAppearanceHandler;
@@ -169,27 +169,27 @@ LLAppearanceHandler gAppearanceHandler;
 
 LLUUID findDescendentCategoryIDByName(const LLUUID& parent_id, const std::string& name)
 {
-	LLInventoryModel::cat_array_t cat_array;
-	LLInventoryModel::item_array_t item_array;
-	LLNameCategoryCollector has_name(name);
-	gInventory.collectDescendentsIf(parent_id,
-									cat_array,
-									item_array,
-									LLInventoryModel::EXCLUDE_TRASH,
-									has_name);
-	if (0 == cat_array.size())
-		return LLUUID();
-	else
-	{
-		LLViewerInventoryCategory *cat = cat_array.at(0);
-		if (cat)
-			return cat->getUUID();
-		else
-		{
-			LL_WARNS() << "null cat" << LL_ENDL;
-			return LLUUID();
-		}
-	}
+    LLInventoryModel::cat_array_t cat_array;
+    LLInventoryModel::item_array_t item_array;
+    LLNameCategoryCollector has_name(name);
+    gInventory.collectDescendentsIf(parent_id,
+                                    cat_array,
+                                    item_array,
+                                    LLInventoryModel::EXCLUDE_TRASH,
+                                    has_name);
+    if (0 == cat_array.size())
+        return LLUUID();
+    else
+    {
+        LLViewerInventoryCategory *cat = cat_array.at(0);
+        if (cat)
+            return cat->getUUID();
+        else
+        {
+            LL_WARNS() << "null cat" << LL_ENDL;
+            return LLUUID();
+        }
+    }
 }
 
 // We want this to be much lower (e.g. 15.0 is usually fine), bumping
@@ -202,261 +202,261 @@ const F32 DEFAULT_RETRY_AFTER_INTERVAL = 300.0;
 // leave at 0 if the operations become actually reliable).
 const S32 DEFAULT_MAX_RETRIES = 0;
 
-class LLCallAfterInventoryBatchMgr: public LLEventTimer 
+class LLCallAfterInventoryBatchMgr: public LLEventTimer
 {
 public:
-	LLCallAfterInventoryBatchMgr(const LLUUID& dst_cat_id,
-								 const std::string& phase_name,
-								 nullary_func_t on_completion_func,
-								 nullary_func_t on_failure_func = no_op,
-								 F32 retry_after = DEFAULT_RETRY_AFTER_INTERVAL,
-								 S32 max_retries = DEFAULT_MAX_RETRIES
-		):
-		mDstCatID(dst_cat_id),
-		mTrackingPhase(phase_name),
-		mOnCompletionFunc(on_completion_func),
-		mOnFailureFunc(on_failure_func),
-		mRetryAfter(retry_after),
-		mMaxRetries(max_retries),
-		mPendingRequests(0),
-		mFailCount(0),
-		mCompletionOrFailureCalled(false),
-		mRetryCount(0),
-		LLEventTimer(5.0)
-	{
-		if (!mTrackingPhase.empty())
-		{
-			selfStartPhase(mTrackingPhase);
-		}
-	}
-
-	void addItems(LLInventoryModel::item_array_t& src_items)
-	{
-		for (LLInventoryModel::item_array_t::const_iterator it = src_items.begin();
-			 it != src_items.end();
-			 ++it)
-		{
-			LLViewerInventoryItem* item = *it;
-			llassert(item);
-			addItem(item->getUUID());
-		}
-	}
-
-	// Request or re-request operation for specified item.
-	void addItem(const LLUUID& item_id)
-	{
-		LL_DEBUGS("Avatar") << "item_id " << item_id << LL_ENDL;
-		if (!requestOperation(item_id))
-		{
-			LL_DEBUGS("Avatar") << "item_id " << item_id << " requestOperation false, skipping" << LL_ENDL;
-			return;
-		}
-
-		mPendingRequests++;
-		// On a re-request, this will reset the timer.
-		mWaitTimes[item_id] = LLTimer();
-		if (mRetryCounts.find(item_id) == mRetryCounts.end())
-		{
-			mRetryCounts[item_id] = 0;
-		}
-		else
-		{
-			mRetryCounts[item_id]++;
-		}
-	}
-
-	virtual bool requestOperation(const LLUUID& item_id) = 0;
-
-	void onOp(const LLUUID& src_id, const LLUUID& dst_id, LLTimer timestamp)
-	{
-		if (ll_frand() < gSavedSettings.getF32("InventoryDebugSimulateLateOpRate"))
-		{
-			LL_WARNS() << "Simulating late operation by punting handling to later" << LL_ENDL;
-			doAfterInterval(boost::bind(&LLCallAfterInventoryBatchMgr::onOp,this,src_id,dst_id,timestamp),
-							mRetryAfter);
-			return;
-		}
-		mPendingRequests--;
-		F32 elapsed = timestamp.getElapsedTimeF32();
-		LL_DEBUGS("Avatar") << "op done, src_id " << src_id << " dst_id " << dst_id << " after " << elapsed << " seconds" << LL_ENDL;
-		if (mWaitTimes.find(src_id) == mWaitTimes.end())
-		{
-			// No longer waiting for this item - either serviced
-			// already or gave up after too many retries.
-			LL_WARNS() << "duplicate or late operation, src_id " << src_id << "dst_id " << dst_id
-					<< " elapsed " << elapsed << " after end " << (S32) mCompletionOrFailureCalled << LL_ENDL;
-		}
-		mTimeStats.push(elapsed);
-		mWaitTimes.erase(src_id);
-		if (mWaitTimes.empty() && !mCompletionOrFailureCalled)
-		{
-			onCompletionOrFailure();
-		}
-	}
-
-	void onCompletionOrFailure()
-	{
-		assert (!mCompletionOrFailureCalled);
-		mCompletionOrFailureCalled = true;
-		
-		// Will never call onCompletion() if any item has been flagged as
-		// a failure - otherwise could wind up with corrupted
-		// outfit, involuntary nudity, etc.
-		reportStats();
-		if (!mTrackingPhase.empty())
-		{
-			selfStopPhase(mTrackingPhase);
-		}
-		if (!mFailCount)
-		{
-			onCompletion();
-		}
-		else
-		{
-			onFailure();
-		}
-	}
-
-	void onFailure()
-	{
-		LL_INFOS() << "failed" << LL_ENDL;
-		mOnFailureFunc();
-	}
-
-	void onCompletion()
-	{
-		LL_INFOS() << "done" << LL_ENDL;
-		mOnCompletionFunc();
-	}
-	
-	// virtual
-	// Will be deleted after returning true - only safe to do this if all callbacks have fired.
-	BOOL tick()
-	{
-		// mPendingRequests will be zero if all requests have been
-		// responded to.  mWaitTimes.empty() will be true if we have
-		// received at least one reply for each UUID.  If requests
-		// have been dropped and retried, these will not necessarily
-		// be the same.  Only safe to return true if all requests have
-		// been serviced, since it will result in this object being
-		// deleted.
-		bool all_done = (mPendingRequests==0);
-
-		if (!mWaitTimes.empty())
-		{
-			LL_WARNS() << "still waiting on " << mWaitTimes.size() << " items" << LL_ENDL;
-			for (std::map<LLUUID,LLTimer>::iterator it = mWaitTimes.begin();
-				 it != mWaitTimes.end();)
-			{
-				// Use a copy of iterator because it may be erased/invalidated.
-				std::map<LLUUID,LLTimer>::iterator curr_it = it;
-				++it;
-				
-				F32 time_waited = curr_it->second.getElapsedTimeF32();
-				S32 retries = mRetryCounts[curr_it->first];
-				if (time_waited > mRetryAfter)
-				{
-					if (retries < mMaxRetries)
-					{
-						LL_DEBUGS("Avatar") << "Waited " << time_waited <<
-							" for " << curr_it->first << ", retrying" << LL_ENDL;
-						mRetryCount++;
-						addItem(curr_it->first);
-					}
-					else
-					{
-						LL_WARNS() << "Giving up on " << curr_it->first << " after too many retries" << LL_ENDL;
-						mWaitTimes.erase(curr_it);
-						mFailCount++;
-					}
-				}
-				if (mWaitTimes.empty())
-				{
-					onCompletionOrFailure();
-				}
-
-			}
-		}
-		return all_done;
-	}
-
-	void reportStats()
-	{
-		LL_DEBUGS("Avatar") << "Phase: " << mTrackingPhase << LL_ENDL;
-		LL_DEBUGS("Avatar") << "mFailCount: " << mFailCount << LL_ENDL;
-		LL_DEBUGS("Avatar") << "mRetryCount: " << mRetryCount << LL_ENDL;
-		LL_DEBUGS("Avatar") << "Times: n " << mTimeStats.getCount() << " min " << mTimeStats.getMinValue() << " max " << mTimeStats.getMaxValue() << LL_ENDL;
-		LL_DEBUGS("Avatar") << "Mean " << mTimeStats.getMean() << " stddev " << mTimeStats.getStdDev() << LL_ENDL;
-	}
-	
-	virtual ~LLCallAfterInventoryBatchMgr()
-	{
-		LL_DEBUGS("Avatar") << "deleting" << LL_ENDL;
-	}
+    LLCallAfterInventoryBatchMgr(const LLUUID& dst_cat_id,
+                                 const std::string& phase_name,
+                                 nullary_func_t on_completion_func,
+                                 nullary_func_t on_failure_func = no_op,
+                                 F32 retry_after = DEFAULT_RETRY_AFTER_INTERVAL,
+                                 S32 max_retries = DEFAULT_MAX_RETRIES
+        ):
+        mDstCatID(dst_cat_id),
+        mTrackingPhase(phase_name),
+        mOnCompletionFunc(on_completion_func),
+        mOnFailureFunc(on_failure_func),
+        mRetryAfter(retry_after),
+        mMaxRetries(max_retries),
+        mPendingRequests(0),
+        mFailCount(0),
+        mCompletionOrFailureCalled(false),
+        mRetryCount(0),
+        LLEventTimer(5.0)
+    {
+        if (!mTrackingPhase.empty())
+        {
+            selfStartPhase(mTrackingPhase);
+        }
+    }
+
+    void addItems(LLInventoryModel::item_array_t& src_items)
+    {
+        for (LLInventoryModel::item_array_t::const_iterator it = src_items.begin();
+             it != src_items.end();
+             ++it)
+        {
+            LLViewerInventoryItem* item = *it;
+            llassert(item);
+            addItem(item->getUUID());
+        }
+    }
+
+    // Request or re-request operation for specified item.
+    void addItem(const LLUUID& item_id)
+    {
+        LL_DEBUGS("Avatar") << "item_id " << item_id << LL_ENDL;
+        if (!requestOperation(item_id))
+        {
+            LL_DEBUGS("Avatar") << "item_id " << item_id << " requestOperation false, skipping" << LL_ENDL;
+            return;
+        }
+
+        mPendingRequests++;
+        // On a re-request, this will reset the timer.
+        mWaitTimes[item_id] = LLTimer();
+        if (mRetryCounts.find(item_id) == mRetryCounts.end())
+        {
+            mRetryCounts[item_id] = 0;
+        }
+        else
+        {
+            mRetryCounts[item_id]++;
+        }
+    }
+
+    virtual bool requestOperation(const LLUUID& item_id) = 0;
+
+    void onOp(const LLUUID& src_id, const LLUUID& dst_id, LLTimer timestamp)
+    {
+        if (ll_frand() < gSavedSettings.getF32("InventoryDebugSimulateLateOpRate"))
+        {
+            LL_WARNS() << "Simulating late operation by punting handling to later" << LL_ENDL;
+            doAfterInterval(boost::bind(&LLCallAfterInventoryBatchMgr::onOp,this,src_id,dst_id,timestamp),
+                            mRetryAfter);
+            return;
+        }
+        mPendingRequests--;
+        F32 elapsed = timestamp.getElapsedTimeF32();
+        LL_DEBUGS("Avatar") << "op done, src_id " << src_id << " dst_id " << dst_id << " after " << elapsed << " seconds" << LL_ENDL;
+        if (mWaitTimes.find(src_id) == mWaitTimes.end())
+        {
+            // No longer waiting for this item - either serviced
+            // already or gave up after too many retries.
+            LL_WARNS() << "duplicate or late operation, src_id " << src_id << "dst_id " << dst_id
+                    << " elapsed " << elapsed << " after end " << (S32) mCompletionOrFailureCalled << LL_ENDL;
+        }
+        mTimeStats.push(elapsed);
+        mWaitTimes.erase(src_id);
+        if (mWaitTimes.empty() && !mCompletionOrFailureCalled)
+        {
+            onCompletionOrFailure();
+        }
+    }
+
+    void onCompletionOrFailure()
+    {
+        assert (!mCompletionOrFailureCalled);
+        mCompletionOrFailureCalled = true;
+
+        // Will never call onCompletion() if any item has been flagged as
+        // a failure - otherwise could wind up with corrupted
+        // outfit, involuntary nudity, etc.
+        reportStats();
+        if (!mTrackingPhase.empty())
+        {
+            selfStopPhase(mTrackingPhase);
+        }
+        if (!mFailCount)
+        {
+            onCompletion();
+        }
+        else
+        {
+            onFailure();
+        }
+    }
+
+    void onFailure()
+    {
+        LL_INFOS() << "failed" << LL_ENDL;
+        mOnFailureFunc();
+    }
+
+    void onCompletion()
+    {
+        LL_INFOS() << "done" << LL_ENDL;
+        mOnCompletionFunc();
+    }
+
+    // virtual
+    // Will be deleted after returning true - only safe to do this if all callbacks have fired.
+    BOOL tick()
+    {
+        // mPendingRequests will be zero if all requests have been
+        // responded to.  mWaitTimes.empty() will be true if we have
+        // received at least one reply for each UUID.  If requests
+        // have been dropped and retried, these will not necessarily
+        // be the same.  Only safe to return true if all requests have
+        // been serviced, since it will result in this object being
+        // deleted.
+        bool all_done = (mPendingRequests==0);
+
+        if (!mWaitTimes.empty())
+        {
+            LL_WARNS() << "still waiting on " << mWaitTimes.size() << " items" << LL_ENDL;
+            for (std::map<LLUUID,LLTimer>::iterator it = mWaitTimes.begin();
+                 it != mWaitTimes.end();)
+            {
+                // Use a copy of iterator because it may be erased/invalidated.
+                std::map<LLUUID,LLTimer>::iterator curr_it = it;
+                ++it;
+
+                F32 time_waited = curr_it->second.getElapsedTimeF32();
+                S32 retries = mRetryCounts[curr_it->first];
+                if (time_waited > mRetryAfter)
+                {
+                    if (retries < mMaxRetries)
+                    {
+                        LL_DEBUGS("Avatar") << "Waited " << time_waited <<
+                            " for " << curr_it->first << ", retrying" << LL_ENDL;
+                        mRetryCount++;
+                        addItem(curr_it->first);
+                    }
+                    else
+                    {
+                        LL_WARNS() << "Giving up on " << curr_it->first << " after too many retries" << LL_ENDL;
+                        mWaitTimes.erase(curr_it);
+                        mFailCount++;
+                    }
+                }
+                if (mWaitTimes.empty())
+                {
+                    onCompletionOrFailure();
+                }
+
+            }
+        }
+        return all_done;
+    }
+
+    void reportStats()
+    {
+        LL_DEBUGS("Avatar") << "Phase: " << mTrackingPhase << LL_ENDL;
+        LL_DEBUGS("Avatar") << "mFailCount: " << mFailCount << LL_ENDL;
+        LL_DEBUGS("Avatar") << "mRetryCount: " << mRetryCount << LL_ENDL;
+        LL_DEBUGS("Avatar") << "Times: n " << mTimeStats.getCount() << " min " << mTimeStats.getMinValue() << " max " << mTimeStats.getMaxValue() << LL_ENDL;
+        LL_DEBUGS("Avatar") << "Mean " << mTimeStats.getMean() << " stddev " << mTimeStats.getStdDev() << LL_ENDL;
+    }
+
+    virtual ~LLCallAfterInventoryBatchMgr()
+    {
+        LL_DEBUGS("Avatar") << "deleting" << LL_ENDL;
+    }
 
 protected:
-	std::string mTrackingPhase;
-	std::map<LLUUID,LLTimer> mWaitTimes;
-	std::map<LLUUID,S32> mRetryCounts;
-	LLUUID mDstCatID;
-	nullary_func_t mOnCompletionFunc;
-	nullary_func_t mOnFailureFunc;
-	F32 mRetryAfter;
-	S32 mMaxRetries;
-	S32 mPendingRequests;
-	S32 mFailCount;
-	S32 mRetryCount;
-	bool mCompletionOrFailureCalled;
-	LLViewerStats::StatsAccumulator mTimeStats;
+    std::string mTrackingPhase;
+    std::map<LLUUID,LLTimer> mWaitTimes;
+    std::map<LLUUID,S32> mRetryCounts;
+    LLUUID mDstCatID;
+    nullary_func_t mOnCompletionFunc;
+    nullary_func_t mOnFailureFunc;
+    F32 mRetryAfter;
+    S32 mMaxRetries;
+    S32 mPendingRequests;
+    S32 mFailCount;
+    S32 mRetryCount;
+    bool mCompletionOrFailureCalled;
+    LLViewerStats::StatsAccumulator mTimeStats;
 };
 
 class LLCallAfterInventoryCopyMgr: public LLCallAfterInventoryBatchMgr
 {
 public:
-	LLCallAfterInventoryCopyMgr(LLInventoryModel::item_array_t& src_items,
-								const LLUUID& dst_cat_id,
-								const std::string& phase_name,
-								nullary_func_t on_completion_func,
-								nullary_func_t on_failure_func = no_op,
-								 F32 retry_after = DEFAULT_RETRY_AFTER_INTERVAL,
-								 S32 max_retries = DEFAULT_MAX_RETRIES
-		):
-		LLCallAfterInventoryBatchMgr(dst_cat_id, phase_name, on_completion_func, on_failure_func, retry_after, max_retries)
-	{
-		addItems(src_items);
-		sInstanceCount++;
-	}
-
-	~LLCallAfterInventoryCopyMgr()
-	{
-		sInstanceCount--;
-	}
-	
-	virtual bool requestOperation(const LLUUID& item_id)
-	{
-		LLViewerInventoryItem *item = gInventory.getItem(item_id);
-		llassert(item);
-		LL_DEBUGS("Avatar") << "copying item " << item_id << LL_ENDL;
-		if (ll_frand() < gSavedSettings.getF32("InventoryDebugSimulateOpFailureRate"))
-		{
-			LL_DEBUGS("Avatar") << "simulating failure by not sending request for item " << item_id << LL_ENDL;
-			return true;
-		}
-		copy_inventory_item(
-			gAgent.getID(),
-			item->getPermissions().getOwner(),
-			item->getUUID(),
-			mDstCatID,
-			std::string(),
-			new LLBoostFuncInventoryCallback(boost::bind(&LLCallAfterInventoryBatchMgr::onOp,this,item_id,_1,LLTimer()))
-			);
-		return true;
-	}
-
-	static S32 getInstanceCount() { return sInstanceCount; }
-	
+    LLCallAfterInventoryCopyMgr(LLInventoryModel::item_array_t& src_items,
+                                const LLUUID& dst_cat_id,
+                                const std::string& phase_name,
+                                nullary_func_t on_completion_func,
+                                nullary_func_t on_failure_func = no_op,
+                                 F32 retry_after = DEFAULT_RETRY_AFTER_INTERVAL,
+                                 S32 max_retries = DEFAULT_MAX_RETRIES
+        ):
+        LLCallAfterInventoryBatchMgr(dst_cat_id, phase_name, on_completion_func, on_failure_func, retry_after, max_retries)
+    {
+        addItems(src_items);
+        sInstanceCount++;
+    }
+
+    ~LLCallAfterInventoryCopyMgr()
+    {
+        sInstanceCount--;
+    }
+
+    virtual bool requestOperation(const LLUUID& item_id)
+    {
+        LLViewerInventoryItem *item = gInventory.getItem(item_id);
+        llassert(item);
+        LL_DEBUGS("Avatar") << "copying item " << item_id << LL_ENDL;
+        if (ll_frand() < gSavedSettings.getF32("InventoryDebugSimulateOpFailureRate"))
+        {
+            LL_DEBUGS("Avatar") << "simulating failure by not sending request for item " << item_id << LL_ENDL;
+            return true;
+        }
+        copy_inventory_item(
+            gAgent.getID(),
+            item->getPermissions().getOwner(),
+            item->getUUID(),
+            mDstCatID,
+            std::string(),
+            new LLBoostFuncInventoryCallback(boost::bind(&LLCallAfterInventoryBatchMgr::onOp,this,item_id,_1,LLTimer()))
+            );
+        return true;
+    }
+
+    static S32 getInstanceCount() { return sInstanceCount; }
+
 private:
-	static S32 sInstanceCount;
+    static S32 sInstanceCount;
 };
 
 S32 LLCallAfterInventoryCopyMgr::sInstanceCount = 0;
@@ -464,97 +464,97 @@ S32 LLCallAfterInventoryCopyMgr::sInstanceCount = 0;
 class LLWearCategoryAfterCopy: public LLInventoryCallback
 {
 public:
-	LLWearCategoryAfterCopy(bool append):
-		mAppend(append)
-	{}
-
-	// virtual
-	void fire(const LLUUID& id)
-	{
-		// Wear the inventory category.
-		LLInventoryCategory* cat = gInventory.getCategory(id);
-		LLAppearanceMgr::instance().wearInventoryCategoryOnAvatar(cat, mAppend);
-	}
+    LLWearCategoryAfterCopy(bool append):
+        mAppend(append)
+    {}
+
+    // virtual
+    void fire(const LLUUID& id)
+    {
+        // Wear the inventory category.
+        LLInventoryCategory* cat = gInventory.getCategory(id);
+        LLAppearanceMgr::instance().wearInventoryCategoryOnAvatar(cat, mAppend);
+    }
 
 private:
-	bool mAppend;
+    bool mAppend;
 };
 
 class LLTrackPhaseWrapper : public LLInventoryCallback
 {
 public:
-	LLTrackPhaseWrapper(const std::string& phase_name, LLPointer<LLInventoryCallback> cb = NULL):
-		mTrackingPhase(phase_name),
-		mCB(cb)
-	{
-		selfStartPhase(mTrackingPhase);
-	}
-
-	// virtual
-	void fire(const LLUUID& id)
-	{
-		if (mCB)
-		{
-			mCB->fire(id);
-		}
-	}
-
-	// virtual
-	~LLTrackPhaseWrapper()
-	{
-		selfStopPhase(mTrackingPhase);
-	}
+    LLTrackPhaseWrapper(const std::string& phase_name, LLPointer<LLInventoryCallback> cb = NULL):
+        mTrackingPhase(phase_name),
+        mCB(cb)
+    {
+        selfStartPhase(mTrackingPhase);
+    }
+
+    // virtual
+    void fire(const LLUUID& id)
+    {
+        if (mCB)
+        {
+            mCB->fire(id);
+        }
+    }
+
+    // virtual
+    ~LLTrackPhaseWrapper()
+    {
+        selfStopPhase(mTrackingPhase);
+    }
 
 protected:
-	std::string mTrackingPhase;
-	LLPointer<LLInventoryCallback> mCB;
+    std::string mTrackingPhase;
+    LLPointer<LLInventoryCallback> mCB;
 };
 
 LLUpdateAppearanceOnDestroy::LLUpdateAppearanceOnDestroy(bool enforce_item_restrictions,
-														 bool enforce_ordering,
-														 nullary_func_t post_update_func 
-	):
-	mFireCount(0),
-	mEnforceItemRestrictions(enforce_item_restrictions),
-	mEnforceOrdering(enforce_ordering),
-	mPostUpdateFunc(post_update_func)
+                                                         bool enforce_ordering,
+                                                         nullary_func_t post_update_func
+    ):
+    mFireCount(0),
+    mEnforceItemRestrictions(enforce_item_restrictions),
+    mEnforceOrdering(enforce_ordering),
+    mPostUpdateFunc(post_update_func)
 {
-	selfStartPhase("update_appearance_on_destroy");
+    selfStartPhase("update_appearance_on_destroy");
 }
 
 void LLUpdateAppearanceOnDestroy::fire(const LLUUID& inv_item)
 {
-	LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getItem(inv_item);
-	const std::string item_name = item ? item->getName() : "ITEM NOT FOUND";
+    LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getItem(inv_item);
+    const std::string item_name = item ? item->getName() : "ITEM NOT FOUND";
 #ifndef LL_RELEASE_FOR_DOWNLOAD
-	LL_DEBUGS("Avatar") << self_av_string() << "callback fired [ name:" << item_name << " UUID:" << inv_item << " count:" << mFireCount << " ] " << LL_ENDL;
+    LL_DEBUGS("Avatar") << self_av_string() << "callback fired [ name:" << item_name << " UUID:" << inv_item << " count:" << mFireCount << " ] " << LL_ENDL;
 #endif
-	mFireCount++;
+    mFireCount++;
 }
 
 LLUpdateAppearanceOnDestroy::~LLUpdateAppearanceOnDestroy()
 {
-	if (LLApp::isRunning())
-	{
-		// speculative fix for MAINT-1150
-		//LL_INFOS("Avatar") << self_av_string() << "done update appearance on destroy" << LL_ENDL;
+    if (LLApp::isRunning())
+    {
+        // speculative fix for MAINT-1150
+        //LL_INFOS("Avatar") << self_av_string() << "done update appearance on destroy" << LL_ENDL;
 
-		selfStopPhase("update_appearance_on_destroy");
+        selfStopPhase("update_appearance_on_destroy");
 
-		LLAppearanceMgr::instance().updateAppearanceFromCOF(mEnforceItemRestrictions,
-															mEnforceOrdering,
-															mPostUpdateFunc);
-	}
+        LLAppearanceMgr::instance().updateAppearanceFromCOF(mEnforceItemRestrictions,
+                                                            mEnforceOrdering,
+                                                            mPostUpdateFunc);
+    }
 }
 
 LLUpdateAppearanceAndEditWearableOnDestroy::LLUpdateAppearanceAndEditWearableOnDestroy(const LLUUID& item_id):
-	mItemID(item_id)
+    mItemID(item_id)
 {
 }
 
 LLRequestServerAppearanceUpdateOnDestroy::~LLRequestServerAppearanceUpdateOnDestroy()
 {
-	LL_DEBUGS("Avatar") << "ATT requesting server appearance update" << LL_ENDL;
+    LL_DEBUGS("Avatar") << "ATT requesting server appearance update" << LL_ENDL;
     if (LLApp::isRunning())
     {
         LLAppearanceMgr::instance().requestServerAppearanceUpdate();
@@ -563,30 +563,30 @@ LLRequestServerAppearanceUpdateOnDestroy::~LLRequestServerAppearanceUpdateOnDest
 
 void edit_wearable_and_customize_avatar(LLUUID item_id)
 {
-	// Start editing the item if previously requested.
-	gAgentWearables.editWearableIfRequested(item_id);
-	
-	// TODO: camera mode may not be changed if a debug setting is tweaked
-	if( gAgentCamera.cameraCustomizeAvatar() )
-	{
-		// If we're in appearance editing mode, the current tab may need to be refreshed
-		LLSidepanelAppearance *panel = dynamic_cast<LLSidepanelAppearance*>(
-			LLFloaterSidePanelContainer::getPanel("appearance"));
-		if (panel)
-		{
-			panel->showDefaultSubpart();
-		}
-	}
+    // Start editing the item if previously requested.
+    gAgentWearables.editWearableIfRequested(item_id);
+
+    // TODO: camera mode may not be changed if a debug setting is tweaked
+    if( gAgentCamera.cameraCustomizeAvatar() )
+    {
+        // If we're in appearance editing mode, the current tab may need to be refreshed
+        LLSidepanelAppearance *panel = dynamic_cast<LLSidepanelAppearance*>(
+            LLFloaterSidePanelContainer::getPanel("appearance"));
+        if (panel)
+        {
+            panel->showDefaultSubpart();
+        }
+    }
 }
 
 LLUpdateAppearanceAndEditWearableOnDestroy::~LLUpdateAppearanceAndEditWearableOnDestroy()
 {
-	if (LLApp::isRunning())
-	{
-		LLAppearanceMgr::instance().updateAppearanceFromCOF(
-			true,true,
-			boost::bind(edit_wearable_and_customize_avatar, mItemID));
-	}
+    if (LLApp::isRunning())
+    {
+        LLAppearanceMgr::instance().updateAppearanceFromCOF(
+            true,true,
+            boost::bind(edit_wearable_and_customize_avatar, mItemID));
+    }
 }
 
 class LLBrokenLinkObserver : public LLInventoryObserver
@@ -657,738 +657,738 @@ void LLBrokenLinkObserver::postProcess()
 
 struct LLFoundData
 {
-	LLFoundData() :
-		mAssetType(LLAssetType::AT_NONE),
-		mWearableType(LLWearableType::WT_INVALID),
-		mWearable(NULL) {}
-
-	LLFoundData(const LLUUID& item_id,
-				const LLUUID& asset_id,
-				const std::string& name,
-				const LLAssetType::EType& asset_type,
-				const LLWearableType::EType& wearable_type,
-				const bool is_replacement = false
-		) :
-		mItemID(item_id),
-		mAssetID(asset_id),
-		mName(name),
-		mAssetType(asset_type),
-		mWearableType(wearable_type),
-		mIsReplacement(is_replacement),
-		mWearable( NULL ) {}
-	
-	LLUUID mItemID;
-	LLUUID mAssetID;
-	std::string mName;
-	LLAssetType::EType mAssetType;
-	LLWearableType::EType mWearableType;
-	LLViewerWearable* mWearable;
-	bool mIsReplacement;
+    LLFoundData() :
+        mAssetType(LLAssetType::AT_NONE),
+        mWearableType(LLWearableType::WT_INVALID),
+        mWearable(NULL) {}
+
+    LLFoundData(const LLUUID& item_id,
+                const LLUUID& asset_id,
+                const std::string& name,
+                const LLAssetType::EType& asset_type,
+                const LLWearableType::EType& wearable_type,
+                const bool is_replacement = false
+        ) :
+        mItemID(item_id),
+        mAssetID(asset_id),
+        mName(name),
+        mAssetType(asset_type),
+        mWearableType(wearable_type),
+        mIsReplacement(is_replacement),
+        mWearable( NULL ) {}
+
+    LLUUID mItemID;
+    LLUUID mAssetID;
+    std::string mName;
+    LLAssetType::EType mAssetType;
+    LLWearableType::EType mWearableType;
+    LLViewerWearable* mWearable;
+    bool mIsReplacement;
 };
 
-	
+
 class LLWearableHoldingPattern
 {
-	LOG_CLASS(LLWearableHoldingPattern);
+    LOG_CLASS(LLWearableHoldingPattern);
 
 public:
-	LLWearableHoldingPattern();
-	~LLWearableHoldingPattern();
-
-	bool pollFetchCompletion();
-	void onFetchCompletion();
-	bool isFetchCompleted();
-	bool isTimedOut();
-
-	void checkMissingWearables();
-	bool pollMissingWearables();
-	bool isMissingCompleted();
-	void recoverMissingWearable(LLWearableType::EType type);
-	void clearCOFLinksForMissingWearables();
-	
-	void onWearableAssetFetch(LLViewerWearable *wearable);
-	void onAllComplete();
-
-	typedef std::list<LLFoundData> found_list_t;
-	found_list_t& getFoundList();
-	void eraseTypeToLink(LLWearableType::EType type);
-	void eraseTypeToRecover(LLWearableType::EType type);
-	void setObjItems(const LLInventoryModel::item_array_t& items);
-	void setGestItems(const LLInventoryModel::item_array_t& items);
-	bool isMostRecent();
-	void handleLateArrivals();
-	void resetTime(F32 timeout);
-	static S32 countActive() { return sActiveHoldingPatterns.size(); }
-	S32 index() { return mIndex; }
-	
+    LLWearableHoldingPattern();
+    ~LLWearableHoldingPattern();
+
+    bool pollFetchCompletion();
+    void onFetchCompletion();
+    bool isFetchCompleted();
+    bool isTimedOut();
+
+    void checkMissingWearables();
+    bool pollMissingWearables();
+    bool isMissingCompleted();
+    void recoverMissingWearable(LLWearableType::EType type);
+    void clearCOFLinksForMissingWearables();
+
+    void onWearableAssetFetch(LLViewerWearable *wearable);
+    void onAllComplete();
+
+    typedef std::list<LLFoundData> found_list_t;
+    found_list_t& getFoundList();
+    void eraseTypeToLink(LLWearableType::EType type);
+    void eraseTypeToRecover(LLWearableType::EType type);
+    void setObjItems(const LLInventoryModel::item_array_t& items);
+    void setGestItems(const LLInventoryModel::item_array_t& items);
+    bool isMostRecent();
+    void handleLateArrivals();
+    void resetTime(F32 timeout);
+    static S32 countActive() { return sActiveHoldingPatterns.size(); }
+    S32 index() { return mIndex; }
+
 private:
-	found_list_t mFoundList;
-	LLInventoryModel::item_array_t mObjItems;
-	LLInventoryModel::item_array_t mGestItems;
-	typedef std::set<S32> type_set_t;
-	type_set_t mTypesToRecover;
-	type_set_t mTypesToLink;
-	S32 mResolved;
-	LLTimer mWaitTime;
-	bool mFired;
-	typedef std::set<LLWearableHoldingPattern*> type_set_hp;
-	static type_set_hp sActiveHoldingPatterns;
-	static S32 sNextIndex;
-	S32 mIndex;
-	bool mIsMostRecent;
-	std::set<LLViewerWearable*> mLateArrivals;
-	bool mIsAllComplete;
+    found_list_t mFoundList;
+    LLInventoryModel::item_array_t mObjItems;
+    LLInventoryModel::item_array_t mGestItems;
+    typedef std::set<S32> type_set_t;
+    type_set_t mTypesToRecover;
+    type_set_t mTypesToLink;
+    S32 mResolved;
+    LLTimer mWaitTime;
+    bool mFired;
+    typedef std::set<LLWearableHoldingPattern*> type_set_hp;
+    static type_set_hp sActiveHoldingPatterns;
+    static S32 sNextIndex;
+    S32 mIndex;
+    bool mIsMostRecent;
+    std::set<LLViewerWearable*> mLateArrivals;
+    bool mIsAllComplete;
 };
 
 LLWearableHoldingPattern::type_set_hp LLWearableHoldingPattern::sActiveHoldingPatterns;
 S32 LLWearableHoldingPattern::sNextIndex = 0;
 
 LLWearableHoldingPattern::LLWearableHoldingPattern():
-	mResolved(0),
-	mFired(false),
-	mIsMostRecent(true),
-	mIsAllComplete(false)
-{
-	if (countActive()>0)
-	{
-		LL_INFOS() << "Creating LLWearableHoldingPattern when "
-				   << countActive()
-				   << " other attempts are active."
-				   << " Flagging others as invalid."
-				   << LL_ENDL;
-		for (type_set_hp::iterator it = sActiveHoldingPatterns.begin();
-			 it != sActiveHoldingPatterns.end();
-			 ++it)
-		{
-			(*it)->mIsMostRecent = false;
-		}
-			 
-	}
-	mIndex = sNextIndex++;
-	sActiveHoldingPatterns.insert(this);
-	LL_DEBUGS("Avatar") << "HP " << index() << " created" << LL_ENDL;
-	selfStartPhase("holding_pattern");
+    mResolved(0),
+    mFired(false),
+    mIsMostRecent(true),
+    mIsAllComplete(false)
+{
+    if (countActive()>0)
+    {
+        LL_INFOS() << "Creating LLWearableHoldingPattern when "
+                   << countActive()
+                   << " other attempts are active."
+                   << " Flagging others as invalid."
+                   << LL_ENDL;
+        for (type_set_hp::iterator it = sActiveHoldingPatterns.begin();
+             it != sActiveHoldingPatterns.end();
+             ++it)
+        {
+            (*it)->mIsMostRecent = false;
+        }
+
+    }
+    mIndex = sNextIndex++;
+    sActiveHoldingPatterns.insert(this);
+    LL_DEBUGS("Avatar") << "HP " << index() << " created" << LL_ENDL;
+    selfStartPhase("holding_pattern");
 }
 
 LLWearableHoldingPattern::~LLWearableHoldingPattern()
 {
-	sActiveHoldingPatterns.erase(this);
-	if (isMostRecent())
-	{
-		selfStopPhase("holding_pattern");
-	}
-	LL_DEBUGS("Avatar") << "HP " << index() << " deleted" << LL_ENDL;
+    sActiveHoldingPatterns.erase(this);
+    if (isMostRecent())
+    {
+        selfStopPhase("holding_pattern");
+    }
+    LL_DEBUGS("Avatar") << "HP " << index() << " deleted" << LL_ENDL;
 }
 
 bool LLWearableHoldingPattern::isMostRecent()
 {
-	return mIsMostRecent;
+    return mIsMostRecent;
 }
 
 LLWearableHoldingPattern::found_list_t& LLWearableHoldingPattern::getFoundList()
 {
-	return mFoundList;
+    return mFoundList;
 }
 
 void LLWearableHoldingPattern::eraseTypeToLink(LLWearableType::EType type)
 {
-	mTypesToLink.erase(type);
+    mTypesToLink.erase(type);
 }
 
 void LLWearableHoldingPattern::eraseTypeToRecover(LLWearableType::EType type)
 {
-	mTypesToRecover.erase(type);
+    mTypesToRecover.erase(type);
 }
 
 void LLWearableHoldingPattern::setObjItems(const LLInventoryModel::item_array_t& items)
 {
-	mObjItems = items;
+    mObjItems = items;
 }
 
 void LLWearableHoldingPattern::setGestItems(const LLInventoryModel::item_array_t& items)
 {
-	mGestItems = items;
+    mGestItems = items;
 }
 
 bool LLWearableHoldingPattern::isFetchCompleted()
 {
-	return (mResolved >= (S32)getFoundList().size()); // have everything we were waiting for?
+    return (mResolved >= (S32)getFoundList().size()); // have everything we were waiting for?
 }
 
 bool LLWearableHoldingPattern::isTimedOut()
 {
-	return mWaitTime.hasExpired();
+    return mWaitTime.hasExpired();
 }
 
 void LLWearableHoldingPattern::checkMissingWearables()
 {
-	if (!isMostRecent())
-	{
-		// runway why don't we actually skip here?
-		LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
-	}
-
-	std::vector<S32> found_by_type(LLWearableType::WT_COUNT,0);
-	std::vector<S32> requested_by_type(LLWearableType::WT_COUNT,0);
-	for (found_list_t::iterator it = getFoundList().begin(); it != getFoundList().end(); ++it)
-	{
-		LLFoundData &data = *it;
-		if (data.mWearableType < LLWearableType::WT_COUNT)
-			requested_by_type[data.mWearableType]++;
-		if (data.mWearable)
-			found_by_type[data.mWearableType]++;
-	}
-
-	for (S32 type = 0; type < LLWearableType::WT_COUNT; ++type)
-	{
-		if (requested_by_type[type] > found_by_type[type])
-		{
-			LL_WARNS() << self_av_string() << "got fewer wearables than requested, type " << type << ": requested " << requested_by_type[type] << ", found " << found_by_type[type] << LL_ENDL;
-		}
-		if (found_by_type[type] > 0)
-			continue;
-		if (
-			// If at least one wearable of certain types (pants/shirt/skirt)
-			// was requested but none was found, create a default asset as a replacement.
-			// In all other cases, don't do anything.
-			// For critical types (shape/hair/skin/eyes), this will keep the avatar as a cloud 
-			// due to logic in LLVOAvatarSelf::getIsCloud().
-			// For non-critical types (tatoo, socks, etc.) the wearable will just be missing.
-			(requested_by_type[type] > 0) &&  
-			((type == LLWearableType::WT_PANTS) || (type == LLWearableType::WT_SHIRT) || (type == LLWearableType::WT_SKIRT)))
-		{
-			mTypesToRecover.insert(type);
-			mTypesToLink.insert(type);
-			recoverMissingWearable((LLWearableType::EType)type);
-			LL_WARNS() << self_av_string() << "need to replace " << type << LL_ENDL; 
-		}
-	}
-
-	resetTime(60.0F);
-
-	if (isMostRecent())
-	{
-		selfStartPhase("get_missing_wearables_2");
-	}
-	if (!pollMissingWearables())
-	{
-		doOnIdleRepeating(boost::bind(&LLWearableHoldingPattern::pollMissingWearables,this));
-	}
+    if (!isMostRecent())
+    {
+        // runway why don't we actually skip here?
+        LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
+    }
+
+    std::vector<S32> found_by_type(LLWearableType::WT_COUNT,0);
+    std::vector<S32> requested_by_type(LLWearableType::WT_COUNT,0);
+    for (found_list_t::iterator it = getFoundList().begin(); it != getFoundList().end(); ++it)
+    {
+        LLFoundData &data = *it;
+        if (data.mWearableType < LLWearableType::WT_COUNT)
+            requested_by_type[data.mWearableType]++;
+        if (data.mWearable)
+            found_by_type[data.mWearableType]++;
+    }
+
+    for (S32 type = 0; type < LLWearableType::WT_COUNT; ++type)
+    {
+        if (requested_by_type[type] > found_by_type[type])
+        {
+            LL_WARNS() << self_av_string() << "got fewer wearables than requested, type " << type << ": requested " << requested_by_type[type] << ", found " << found_by_type[type] << LL_ENDL;
+        }
+        if (found_by_type[type] > 0)
+            continue;
+        if (
+            // If at least one wearable of certain types (pants/shirt/skirt)
+            // was requested but none was found, create a default asset as a replacement.
+            // In all other cases, don't do anything.
+            // For critical types (shape/hair/skin/eyes), this will keep the avatar as a cloud
+            // due to logic in LLVOAvatarSelf::getIsCloud().
+            // For non-critical types (tatoo, socks, etc.) the wearable will just be missing.
+            (requested_by_type[type] > 0) &&
+            ((type == LLWearableType::WT_PANTS) || (type == LLWearableType::WT_SHIRT) || (type == LLWearableType::WT_SKIRT)))
+        {
+            mTypesToRecover.insert(type);
+            mTypesToLink.insert(type);
+            recoverMissingWearable((LLWearableType::EType)type);
+            LL_WARNS() << self_av_string() << "need to replace " << type << LL_ENDL;
+        }
+    }
+
+    resetTime(60.0F);
+
+    if (isMostRecent())
+    {
+        selfStartPhase("get_missing_wearables_2");
+    }
+    if (!pollMissingWearables())
+    {
+        doOnIdleRepeating(boost::bind(&LLWearableHoldingPattern::pollMissingWearables,this));
+    }
 }
 
 void LLWearableHoldingPattern::onAllComplete()
 {
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->outputRezTiming("Agent wearables fetch complete");
-	}
-
-	if (!isMostRecent())
-	{
-		// runway need to skip here?
-		LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
-	}
-
-	// Activate all gestures in this folder
-	if (mGestItems.size() > 0)
-	{
-		LL_DEBUGS("Avatar") << self_av_string() << "Activating " << mGestItems.size() << " gestures" << LL_ENDL;
-		
-		LLGestureMgr::instance().activateGestures(mGestItems);
-		
-		// Update the inventory item labels to reflect the fact
-		// they are active.
-		LLViewerInventoryCategory* catp =
-			gInventory.getCategory(LLAppearanceMgr::instance().getCOF());
-		
-		if (catp)
-		{
-			gInventory.updateCategory(catp);
-			gInventory.notifyObservers();
-		}
-	}
-
-	if (isAgentAvatarValid())
-	{
-		LL_DEBUGS("Avatar") << self_av_string() << "Updating " << mObjItems.size() << " attachments" << LL_ENDL;
-		LLAgentWearables::llvo_vec_t objects_to_remove;
-		LLAgentWearables::llvo_vec_t objects_to_retain;
-		LLInventoryModel::item_array_t items_to_add;
-
-		LLAgentWearables::findAttachmentsAddRemoveInfo(mObjItems,
-													   objects_to_remove,
-													   objects_to_retain,
-													   items_to_add);
-
-		LL_DEBUGS("Avatar") << self_av_string() << "Removing " << objects_to_remove.size()
-							<< " attachments" << LL_ENDL;
-
-		// Here we remove the attachment pos overrides for *all*
-		// attachments, even those that are not being removed. This is
-		// needed to get joint positions all slammed down to their
-		// pre-attachment states.
-		gAgentAvatarp->clearAttachmentOverrides();
-
-		if (objects_to_remove.size() || items_to_add.size())
-		{
-			LL_DEBUGS("Avatar") << "ATT will remove " << objects_to_remove.size()
-								<< " and add " << items_to_add.size() << " items" << LL_ENDL;
-		}
-
-		// Take off the attachments that will no longer be in the outfit.
-		LLAgentWearables::userRemoveMultipleAttachments(objects_to_remove);
-		
-		// Update wearables.
-		LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " updating agent wearables with "
-						   << mResolved << " wearable items " << LL_ENDL;
-		LLAppearanceMgr::instance().updateAgentWearables(this);
-		
-		// Restore attachment pos overrides for the attachments that
-		// are remaining in the outfit.
-		for (LLAgentWearables::llvo_vec_t::iterator it = objects_to_retain.begin();
-			 it != objects_to_retain.end();
-			 ++it)
-		{
-			LLViewerObject *objectp = *it;
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->outputRezTiming("Agent wearables fetch complete");
+    }
+
+    if (!isMostRecent())
+    {
+        // runway need to skip here?
+        LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
+    }
+
+    // Activate all gestures in this folder
+    if (mGestItems.size() > 0)
+    {
+        LL_DEBUGS("Avatar") << self_av_string() << "Activating " << mGestItems.size() << " gestures" << LL_ENDL;
+
+        LLGestureMgr::instance().activateGestures(mGestItems);
+
+        // Update the inventory item labels to reflect the fact
+        // they are active.
+        LLViewerInventoryCategory* catp =
+            gInventory.getCategory(LLAppearanceMgr::instance().getCOF());
+
+        if (catp)
+        {
+            gInventory.updateCategory(catp);
+            gInventory.notifyObservers();
+        }
+    }
+
+    if (isAgentAvatarValid())
+    {
+        LL_DEBUGS("Avatar") << self_av_string() << "Updating " << mObjItems.size() << " attachments" << LL_ENDL;
+        LLAgentWearables::llvo_vec_t objects_to_remove;
+        LLAgentWearables::llvo_vec_t objects_to_retain;
+        LLInventoryModel::item_array_t items_to_add;
+
+        LLAgentWearables::findAttachmentsAddRemoveInfo(mObjItems,
+                                                       objects_to_remove,
+                                                       objects_to_retain,
+                                                       items_to_add);
+
+        LL_DEBUGS("Avatar") << self_av_string() << "Removing " << objects_to_remove.size()
+                            << " attachments" << LL_ENDL;
+
+        // Here we remove the attachment pos overrides for *all*
+        // attachments, even those that are not being removed. This is
+        // needed to get joint positions all slammed down to their
+        // pre-attachment states.
+        gAgentAvatarp->clearAttachmentOverrides();
+
+        if (objects_to_remove.size() || items_to_add.size())
+        {
+            LL_DEBUGS("Avatar") << "ATT will remove " << objects_to_remove.size()
+                                << " and add " << items_to_add.size() << " items" << LL_ENDL;
+        }
+
+        // Take off the attachments that will no longer be in the outfit.
+        LLAgentWearables::userRemoveMultipleAttachments(objects_to_remove);
+
+        // Update wearables.
+        LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " updating agent wearables with "
+                           << mResolved << " wearable items " << LL_ENDL;
+        LLAppearanceMgr::instance().updateAgentWearables(this);
+
+        // Restore attachment pos overrides for the attachments that
+        // are remaining in the outfit.
+        for (LLAgentWearables::llvo_vec_t::iterator it = objects_to_retain.begin();
+             it != objects_to_retain.end();
+             ++it)
+        {
+            LLViewerObject *objectp = *it;
             if (!objectp->isAnimatedObject())
             {
                 gAgentAvatarp->addAttachmentOverridesForObject(objectp);
             }
-		}
-		
-		// Add new attachments to match those requested.
-		LL_DEBUGS("Avatar") << self_av_string() << "Adding " << items_to_add.size() << " attachments" << LL_ENDL;
-		LLAgentWearables::userAttachMultipleAttachments(items_to_add);
-	}
-
-	if (isFetchCompleted() && isMissingCompleted())
-	{
-		// Only safe to delete if all wearable callbacks and all missing wearables completed.
-		delete this;
-	}
-	else
-	{
-		mIsAllComplete = true;
-		handleLateArrivals();
-	}
+        }
+
+        // Add new attachments to match those requested.
+        LL_DEBUGS("Avatar") << self_av_string() << "Adding " << items_to_add.size() << " attachments" << LL_ENDL;
+        LLAgentWearables::userAttachMultipleAttachments(items_to_add);
+    }
+
+    if (isFetchCompleted() && isMissingCompleted())
+    {
+        // Only safe to delete if all wearable callbacks and all missing wearables completed.
+        delete this;
+    }
+    else
+    {
+        mIsAllComplete = true;
+        handleLateArrivals();
+    }
 }
 
 void LLWearableHoldingPattern::onFetchCompletion()
 {
-	if (isMostRecent())
-	{
-		selfStopPhase("get_wearables_2");
-	}
-		
-	if (!isMostRecent())
-	{
-		// runway skip here?
-		LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
-	}
+    if (isMostRecent())
+    {
+        selfStopPhase("get_wearables_2");
+    }
+
+    if (!isMostRecent())
+    {
+        // runway skip here?
+        LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
+    }
 
-	checkMissingWearables();
+    checkMissingWearables();
 }
 
 // Runs as an idle callback until all wearables are fetched (or we time out).
 bool LLWearableHoldingPattern::pollFetchCompletion()
 {
-	if (!isMostRecent())
-	{
-		// runway skip here?
-		LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
-	}
+    if (!isMostRecent())
+    {
+        // runway skip here?
+        LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
+    }
+
+    bool completed = isFetchCompleted();
+    bool timed_out = isTimedOut();
+    bool done = completed || timed_out;
 
-	bool completed = isFetchCompleted();
-	bool timed_out = isTimedOut();
-	bool done = completed || timed_out;
+    if (done)
+    {
+        LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " polling, done status: " << completed << " timed out " << timed_out
+                << " elapsed " << mWaitTime.getElapsedTimeF32() << LL_ENDL;
 
-	if (done)
-	{
-		LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " polling, done status: " << completed << " timed out " << timed_out
-				<< " elapsed " << mWaitTime.getElapsedTimeF32() << LL_ENDL;
+        mFired = true;
 
-		mFired = true;
-		
-		if (timed_out)
-		{
-			LL_WARNS() << self_av_string() << "Exceeded max wait time for wearables, updating appearance based on what has arrived" << LL_ENDL;
-		}
+        if (timed_out)
+        {
+            LL_WARNS() << self_av_string() << "Exceeded max wait time for wearables, updating appearance based on what has arrived" << LL_ENDL;
+        }
 
-		onFetchCompletion();
-	}
-	return done;
+        onFetchCompletion();
+    }
+    return done;
 }
 
 void recovered_item_link_cb(const LLUUID& item_id, LLWearableType::EType type, LLViewerWearable *wearable, LLWearableHoldingPattern* holder)
 {
-	if (!holder->isMostRecent())
-	{
-		LL_WARNS() << "HP " << holder->index() << " skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
-		// runway skip here?
-	}
-
-	LL_INFOS("Avatar") << "HP " << holder->index() << " recovered item link for type " << type << LL_ENDL;
-	holder->eraseTypeToLink(type);
-	// Add wearable to FoundData for actual wearing
-	LLViewerInventoryItem *item = gInventory.getItem(item_id);
-	LLViewerInventoryItem *linked_item = item ? item->getLinkedItem() : NULL;
-
-	if (linked_item)
-	{
-		gInventory.addChangedMask(LLInventoryObserver::LABEL, linked_item->getUUID());
-			
-		if (item)
-		{
-			LLFoundData found(linked_item->getUUID(),
-							  linked_item->getAssetUUID(),
-							  linked_item->getName(),
-							  linked_item->getType(),
-							  linked_item->isWearableType() ? linked_item->getWearableType() : LLWearableType::WT_INVALID,
-							  true // is replacement
-				);
-			found.mWearable = wearable;
-			holder->getFoundList().push_front(found);
-		}
-		else
-		{
-			LL_WARNS() << self_av_string() << "inventory link not found for recovered wearable" << LL_ENDL;
-		}
-	}
-	else
-	{
-		LL_WARNS() << self_av_string() << "HP " << holder->index() << " inventory link not found for recovered wearable" << LL_ENDL;
-	}
+    if (!holder->isMostRecent())
+    {
+        LL_WARNS() << "HP " << holder->index() << " skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
+        // runway skip here?
+    }
+
+    LL_INFOS("Avatar") << "HP " << holder->index() << " recovered item link for type " << type << LL_ENDL;
+    holder->eraseTypeToLink(type);
+    // Add wearable to FoundData for actual wearing
+    LLViewerInventoryItem *item = gInventory.getItem(item_id);
+    LLViewerInventoryItem *linked_item = item ? item->getLinkedItem() : NULL;
+
+    if (linked_item)
+    {
+        gInventory.addChangedMask(LLInventoryObserver::LABEL, linked_item->getUUID());
+
+        if (item)
+        {
+            LLFoundData found(linked_item->getUUID(),
+                              linked_item->getAssetUUID(),
+                              linked_item->getName(),
+                              linked_item->getType(),
+                              linked_item->isWearableType() ? linked_item->getWearableType() : LLWearableType::WT_INVALID,
+                              true // is replacement
+                );
+            found.mWearable = wearable;
+            holder->getFoundList().push_front(found);
+        }
+        else
+        {
+            LL_WARNS() << self_av_string() << "inventory link not found for recovered wearable" << LL_ENDL;
+        }
+    }
+    else
+    {
+        LL_WARNS() << self_av_string() << "HP " << holder->index() << " inventory link not found for recovered wearable" << LL_ENDL;
+    }
 }
 
 void recovered_item_cb(const LLUUID& item_id, LLWearableType::EType type, LLViewerWearable *wearable, LLWearableHoldingPattern* holder)
 {
-	if (!holder->isMostRecent())
-	{
-		// runway skip here?
-		LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
-	}
+    if (!holder->isMostRecent())
+    {
+        // runway skip here?
+        LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
+    }
 
-	LL_DEBUGS("Avatar") << self_av_string() << "Recovered item for type " << type << LL_ENDL;
-	LLConstPointer<LLInventoryObject> itemp = gInventory.getItem(item_id);
-	wearable->setItemID(item_id);
-	holder->eraseTypeToRecover(type);
-	llassert(itemp);
-	if (itemp)
-	{
-		LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(recovered_item_link_cb,_1,type,wearable,holder));
+    LL_DEBUGS("Avatar") << self_av_string() << "Recovered item for type " << type << LL_ENDL;
+    LLConstPointer<LLInventoryObject> itemp = gInventory.getItem(item_id);
+    wearable->setItemID(item_id);
+    holder->eraseTypeToRecover(type);
+    llassert(itemp);
+    if (itemp)
+    {
+        LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(recovered_item_link_cb,_1,type,wearable,holder));
 
-		link_inventory_object(LLAppearanceMgr::instance().getCOF(), itemp, cb);
-	}
+        link_inventory_object(LLAppearanceMgr::instance().getCOF(), itemp, cb);
+    }
 }
 
 void LLWearableHoldingPattern::recoverMissingWearable(LLWearableType::EType type)
 {
-	if (!isMostRecent())
-	{
-		// runway skip here?
-		LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
-	}
-	
-		// Try to recover by replacing missing wearable with a new one.
-	LLNotificationsUtil::add("ReplacedMissingWearable");
-	LL_DEBUGS("Avatar") << "Wearable of type '" << LLWearableType::getInstance()->getTypeName(type)
-				<< "' could not be downloaded.  Replaced inventory item with default wearable." << LL_ENDL;
-	LLViewerWearable* wearable = LLWearableList::instance().createNewWearable(type, gAgentAvatarp);
-
-	// Add a new one in the lost and found folder.
-	const LLUUID lost_and_found_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND);
-	LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(recovered_item_cb,_1,type,wearable,this));
+    if (!isMostRecent())
+    {
+        // runway skip here?
+        LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
+    }
+
+        // Try to recover by replacing missing wearable with a new one.
+    LLNotificationsUtil::add("ReplacedMissingWearable");
+    LL_DEBUGS("Avatar") << "Wearable of type '" << LLWearableType::getInstance()->getTypeName(type)
+                << "' could not be downloaded.  Replaced inventory item with default wearable." << LL_ENDL;
+    LLViewerWearable* wearable = LLWearableList::instance().createNewWearable(type, gAgentAvatarp);
+
+    // Add a new one in the lost and found folder.
+    const LLUUID lost_and_found_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND);
+    LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(recovered_item_cb,_1,type,wearable,this));
 
     create_inventory_wearable(gAgent.getID(),
-						  gAgent.getSessionID(),
-						  lost_and_found_id,
-						  wearable->getTransactionID(),
-						  wearable->getName(),
-						  wearable->getDescription(),
-						  wearable->getAssetType(),
-						  wearable->getType(),
-						  wearable->getPermissions().getMaskNextOwner(),
-						  cb);
+                          gAgent.getSessionID(),
+                          lost_and_found_id,
+                          wearable->getTransactionID(),
+                          wearable->getName(),
+                          wearable->getDescription(),
+                          wearable->getAssetType(),
+                          wearable->getType(),
+                          wearable->getPermissions().getMaskNextOwner(),
+                          cb);
 }
 
 bool LLWearableHoldingPattern::isMissingCompleted()
 {
-	return mTypesToLink.size()==0 && mTypesToRecover.size()==0;
+    return mTypesToLink.size()==0 && mTypesToRecover.size()==0;
 }
 
 void LLWearableHoldingPattern::clearCOFLinksForMissingWearables()
 {
-	for (found_list_t::iterator it = getFoundList().begin(); it != getFoundList().end(); ++it)
-	{
-		LLFoundData &data = *it;
-		if ((data.mWearableType < LLWearableType::WT_COUNT) && (!data.mWearable))
-		{
-			// Wearable link that was never resolved; remove links to it from COF
-			LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " removing link for unresolved item " << data.mItemID.asString() << LL_ENDL;
-			LLAppearanceMgr::instance().removeCOFItemLinks(data.mItemID);
-		}
-	}
+    for (found_list_t::iterator it = getFoundList().begin(); it != getFoundList().end(); ++it)
+    {
+        LLFoundData &data = *it;
+        if ((data.mWearableType < LLWearableType::WT_COUNT) && (!data.mWearable))
+        {
+            // Wearable link that was never resolved; remove links to it from COF
+            LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " removing link for unresolved item " << data.mItemID.asString() << LL_ENDL;
+            LLAppearanceMgr::instance().removeCOFItemLinks(data.mItemID);
+        }
+    }
 }
 
 bool LLWearableHoldingPattern::pollMissingWearables()
 {
-	if (!isMostRecent())
-	{
-		// runway skip here?
-		LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
-	}
-	
-	bool timed_out = isTimedOut();
-	bool missing_completed = isMissingCompleted();
-	bool done = timed_out || missing_completed;
-
-	if (!done)
-	{
-		LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " polling missing wearables, waiting for items " << mTypesToRecover.size()
-				<< " links " << mTypesToLink.size()
-				<< " wearables, timed out " << timed_out
-				<< " elapsed " << mWaitTime.getElapsedTimeF32()
-				<< " done " << done << LL_ENDL;
-	}
-
-	if (done)
-	{
-		if (isMostRecent())
-		{
-			selfStopPhase("get_missing_wearables_2");
-		}
-
-		gAgentAvatarp->debugWearablesLoaded();
-
-		// BAP - if we don't call clearCOFLinksForMissingWearables()
-		// here, we won't have to add the link back in later if the
-		// wearable arrives late.  This is to avoid corruption of
-		// wearable ordering info.  Also has the effect of making
-		// unworn item links visible in the COF under some
-		// circumstances.
-
-		//clearCOFLinksForMissingWearables();
-		onAllComplete();
-	}
-	return done;
+    if (!isMostRecent())
+    {
+        // runway skip here?
+        LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
+    }
+
+    bool timed_out = isTimedOut();
+    bool missing_completed = isMissingCompleted();
+    bool done = timed_out || missing_completed;
+
+    if (!done)
+    {
+        LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " polling missing wearables, waiting for items " << mTypesToRecover.size()
+                << " links " << mTypesToLink.size()
+                << " wearables, timed out " << timed_out
+                << " elapsed " << mWaitTime.getElapsedTimeF32()
+                << " done " << done << LL_ENDL;
+    }
+
+    if (done)
+    {
+        if (isMostRecent())
+        {
+            selfStopPhase("get_missing_wearables_2");
+        }
+
+        gAgentAvatarp->debugWearablesLoaded();
+
+        // BAP - if we don't call clearCOFLinksForMissingWearables()
+        // here, we won't have to add the link back in later if the
+        // wearable arrives late.  This is to avoid corruption of
+        // wearable ordering info.  Also has the effect of making
+        // unworn item links visible in the COF under some
+        // circumstances.
+
+        //clearCOFLinksForMissingWearables();
+        onAllComplete();
+    }
+    return done;
 }
 
 // Handle wearables that arrived after the timeout period expired.
 void LLWearableHoldingPattern::handleLateArrivals()
 {
-	// Only safe to run if we have previously finished the missing
-	// wearables and other processing - otherwise we could be in some
-	// intermediate state - but have not been superceded by a later
-	// outfit change request.
-	if (mLateArrivals.size() == 0)
-	{
-		// Nothing to process.
-		return;
-	}
-	if (!isMostRecent())
-	{
-		LL_WARNS() << self_av_string() << "Late arrivals not handled - outfit change no longer valid" << LL_ENDL;
-	}
-	if (!mIsAllComplete)
-	{
-		LL_WARNS() << self_av_string() << "Late arrivals not handled - in middle of missing wearables processing" << LL_ENDL;
-	}
-
-	LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " need to handle " << mLateArrivals.size() << " late arriving wearables" << LL_ENDL;
-
-	// Update mFoundList using late-arriving wearables.
-	std::set<LLWearableType::EType> replaced_types;
-	for (LLWearableHoldingPattern::found_list_t::iterator iter = getFoundList().begin();
-		 iter != getFoundList().end(); ++iter)
-	{
-		LLFoundData& data = *iter;
-		for (std::set<LLViewerWearable*>::iterator wear_it = mLateArrivals.begin();
-			 wear_it != mLateArrivals.end();
-			 ++wear_it)
-		{
-			LLViewerWearable *wearable = *wear_it;
-
-			if(wearable->getAssetID() == data.mAssetID)
-			{
-				data.mWearable = wearable;
-
-				replaced_types.insert(data.mWearableType);
-
-				// BAP - if we didn't call
-				// clearCOFLinksForMissingWearables() earlier, we
-				// don't need to restore the link here.  Fixes
-				// wearable ordering problems.
-
-				// LLAppearanceMgr::instance().addCOFItemLink(data.mItemID,false);
-
-				// BAP failing this means inventory or asset server
-				// are corrupted in a way we don't handle.
-				llassert((data.mWearableType < LLWearableType::WT_COUNT) && (wearable->getType() == data.mWearableType));
-				break;
-			}
-		}
-	}
-
-	// Remove COF links for any default wearables previously used to replace the late arrivals.
-	// All this pussyfooting around with a while loop and explicit
-	// iterator incrementing is to allow removing items from the list
-	// without clobbering the iterator we're using to navigate.
-	LLWearableHoldingPattern::found_list_t::iterator iter = getFoundList().begin();
-	while (iter != getFoundList().end())
-	{
-		LLFoundData& data = *iter;
-
-		// If an item of this type has recently shown up, removed the corresponding replacement wearable from COF.
-		if (data.mWearable && data.mIsReplacement &&
-			replaced_types.find(data.mWearableType) != replaced_types.end())
-		{
-			LLAppearanceMgr::instance().removeCOFItemLinks(data.mItemID);
-			std::list<LLFoundData>::iterator clobber_ator = iter;
-			++iter;
-			getFoundList().erase(clobber_ator);
-		}
-		else
-		{
-			++iter;
-		}
-	}
-
-	// Clear contents of late arrivals.
-	mLateArrivals.clear();
-
-	// Update appearance based on mFoundList
-	LLAppearanceMgr::instance().updateAgentWearables(this);
-}
-
-void LLWearableHoldingPattern::resetTime(F32 timeout)
+    // Only safe to run if we have previously finished the missing
+    // wearables and other processing - otherwise we could be in some
+    // intermediate state - but have not been superceded by a later
+    // outfit change request.
+    if (mLateArrivals.size() == 0)
+    {
+        // Nothing to process.
+        return;
+    }
+    if (!isMostRecent())
+    {
+        LL_WARNS() << self_av_string() << "Late arrivals not handled - outfit change no longer valid" << LL_ENDL;
+    }
+    if (!mIsAllComplete)
+    {
+        LL_WARNS() << self_av_string() << "Late arrivals not handled - in middle of missing wearables processing" << LL_ENDL;
+    }
+
+    LL_INFOS("Avatar") << self_av_string() << "HP " << index() << " need to handle " << mLateArrivals.size() << " late arriving wearables" << LL_ENDL;
+
+    // Update mFoundList using late-arriving wearables.
+    std::set<LLWearableType::EType> replaced_types;
+    for (LLWearableHoldingPattern::found_list_t::iterator iter = getFoundList().begin();
+         iter != getFoundList().end(); ++iter)
+    {
+        LLFoundData& data = *iter;
+        for (std::set<LLViewerWearable*>::iterator wear_it = mLateArrivals.begin();
+             wear_it != mLateArrivals.end();
+             ++wear_it)
+        {
+            LLViewerWearable *wearable = *wear_it;
+
+            if(wearable->getAssetID() == data.mAssetID)
+            {
+                data.mWearable = wearable;
+
+                replaced_types.insert(data.mWearableType);
+
+                // BAP - if we didn't call
+                // clearCOFLinksForMissingWearables() earlier, we
+                // don't need to restore the link here.  Fixes
+                // wearable ordering problems.
+
+                // LLAppearanceMgr::instance().addCOFItemLink(data.mItemID,false);
+
+                // BAP failing this means inventory or asset server
+                // are corrupted in a way we don't handle.
+                llassert((data.mWearableType < LLWearableType::WT_COUNT) && (wearable->getType() == data.mWearableType));
+                break;
+            }
+        }
+    }
+
+    // Remove COF links for any default wearables previously used to replace the late arrivals.
+    // All this pussyfooting around with a while loop and explicit
+    // iterator incrementing is to allow removing items from the list
+    // without clobbering the iterator we're using to navigate.
+    LLWearableHoldingPattern::found_list_t::iterator iter = getFoundList().begin();
+    while (iter != getFoundList().end())
+    {
+        LLFoundData& data = *iter;
+
+        // If an item of this type has recently shown up, removed the corresponding replacement wearable from COF.
+        if (data.mWearable && data.mIsReplacement &&
+            replaced_types.find(data.mWearableType) != replaced_types.end())
+        {
+            LLAppearanceMgr::instance().removeCOFItemLinks(data.mItemID);
+            std::list<LLFoundData>::iterator clobber_ator = iter;
+            ++iter;
+            getFoundList().erase(clobber_ator);
+        }
+        else
+        {
+            ++iter;
+        }
+    }
+
+    // Clear contents of late arrivals.
+    mLateArrivals.clear();
+
+    // Update appearance based on mFoundList
+    LLAppearanceMgr::instance().updateAgentWearables(this);
+}
+
+void LLWearableHoldingPattern::resetTime(F32 timeout)
 {
-	mWaitTime.reset();
-	mWaitTime.setTimerExpirySec(timeout);
+    mWaitTime.reset();
+    mWaitTime.setTimerExpirySec(timeout);
 }
 
 void LLWearableHoldingPattern::onWearableAssetFetch(LLViewerWearable *wearable)
 {
-	if (!isMostRecent())
-	{
-		LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
-	}
-	
-	mResolved += 1;  // just counting callbacks, not successes.
-	LL_DEBUGS("Avatar") << self_av_string() << "HP " << index() << " resolved " << mResolved << "/" << getFoundList().size() << LL_ENDL;
-	if (!wearable)
-	{
-		LL_WARNS() << self_av_string() << "no wearable found" << LL_ENDL;
-	}
-
-	if (mFired)
-	{
-		LL_WARNS() << self_av_string() << "called after holder fired" << LL_ENDL;
-		if (wearable)
-		{
-			mLateArrivals.insert(wearable);
-			if (mIsAllComplete)
-			{
-				handleLateArrivals();
-			}
-		}
-		return;
-	}
-
-	if (!wearable)
-	{
-		return;
-	}
-
-	U32 use_count = 0;
-	for (LLWearableHoldingPattern::found_list_t::iterator iter = getFoundList().begin();
-		iter != getFoundList().end(); ++iter)
-	{
-		LLFoundData& data = *iter;
-		if (wearable->getAssetID() == data.mAssetID)
-		{
-			// Failing this means inventory or asset server are corrupted in a way we don't handle.
-			if ((data.mWearableType >= LLWearableType::WT_COUNT) || (wearable->getType() != data.mWearableType))
-			{
-				LL_WARNS() << self_av_string() << "recovered wearable but type invalid. inventory wearable type: " << data.mWearableType << " asset wearable type: " << wearable->getType() << LL_ENDL;
-				break;
-			}
-
-			if (use_count == 0)
-			{
-				data.mWearable = wearable;
-				use_count++;
-			}
-			else
-			{
-				LLViewerInventoryItem* wearable_item = gInventory.getItem(data.mItemID);
-				if (wearable_item && wearable_item->isFinished() && wearable_item->getPermissions().allowModifyBy(gAgentID))
-				{
-					// We can't edit and do some other interactions with same asset twice, copy it
-					// Note: can't update incomplete items. Usually attached from previous viewer build, but
-					// consider adding fetch and completion callback
-					LLViewerWearable* new_wearable = LLWearableList::instance().createCopy(wearable, wearable->getName());
-					data.mWearable = new_wearable;
-					data.mAssetID = new_wearable->getAssetID();
-
-					// Update existing inventory item
-					wearable_item->setAssetUUID(new_wearable->getAssetID());
-					wearable_item->setTransactionID(new_wearable->getTransactionID());
-					gInventory.updateItem(wearable_item, LLInventoryObserver::INTERNAL);
-					wearable_item->updateServer(FALSE);
-
-					use_count++;
-				}
-				else
-				{
-					// Note: technically a bug, LLViewerWearable can identify only one item id at a time,
-					// yet we are tying it to multiple items here.
-					// LLViewerWearable need to support more then one item.
-					LL_WARNS() << "Same LLViewerWearable is used by multiple items! " << wearable->getAssetID() << LL_ENDL;
-					data.mWearable = wearable;
-				}
-			}
-		}
-	}
-
-	if (use_count > 1)
-	{
-		LL_WARNS() << "Copying wearable, multiple asset id uses! " << wearable->getAssetID() << LL_ENDL;
-		gInventory.notifyObservers();
-	}
+    if (!isMostRecent())
+    {
+        LL_WARNS() << self_av_string() << "skipping because LLWearableHolding pattern is invalid (superceded by later outfit request)" << LL_ENDL;
+    }
+
+    mResolved += 1;  // just counting callbacks, not successes.
+    LL_DEBUGS("Avatar") << self_av_string() << "HP " << index() << " resolved " << mResolved << "/" << getFoundList().size() << LL_ENDL;
+    if (!wearable)
+    {
+        LL_WARNS() << self_av_string() << "no wearable found" << LL_ENDL;
+    }
+
+    if (mFired)
+    {
+        LL_WARNS() << self_av_string() << "called after holder fired" << LL_ENDL;
+        if (wearable)
+        {
+            mLateArrivals.insert(wearable);
+            if (mIsAllComplete)
+            {
+                handleLateArrivals();
+            }
+        }
+        return;
+    }
+
+    if (!wearable)
+    {
+        return;
+    }
+
+    U32 use_count = 0;
+    for (LLWearableHoldingPattern::found_list_t::iterator iter = getFoundList().begin();
+        iter != getFoundList().end(); ++iter)
+    {
+        LLFoundData& data = *iter;
+        if (wearable->getAssetID() == data.mAssetID)
+        {
+            // Failing this means inventory or asset server are corrupted in a way we don't handle.
+            if ((data.mWearableType >= LLWearableType::WT_COUNT) || (wearable->getType() != data.mWearableType))
+            {
+                LL_WARNS() << self_av_string() << "recovered wearable but type invalid. inventory wearable type: " << data.mWearableType << " asset wearable type: " << wearable->getType() << LL_ENDL;
+                break;
+            }
+
+            if (use_count == 0)
+            {
+                data.mWearable = wearable;
+                use_count++;
+            }
+            else
+            {
+                LLViewerInventoryItem* wearable_item = gInventory.getItem(data.mItemID);
+                if (wearable_item && wearable_item->isFinished() && wearable_item->getPermissions().allowModifyBy(gAgentID))
+                {
+                    // We can't edit and do some other interactions with same asset twice, copy it
+                    // Note: can't update incomplete items. Usually attached from previous viewer build, but
+                    // consider adding fetch and completion callback
+                    LLViewerWearable* new_wearable = LLWearableList::instance().createCopy(wearable, wearable->getName());
+                    data.mWearable = new_wearable;
+                    data.mAssetID = new_wearable->getAssetID();
+
+                    // Update existing inventory item
+                    wearable_item->setAssetUUID(new_wearable->getAssetID());
+                    wearable_item->setTransactionID(new_wearable->getTransactionID());
+                    gInventory.updateItem(wearable_item, LLInventoryObserver::INTERNAL);
+                    wearable_item->updateServer(FALSE);
+
+                    use_count++;
+                }
+                else
+                {
+                    // Note: technically a bug, LLViewerWearable can identify only one item id at a time,
+                    // yet we are tying it to multiple items here.
+                    // LLViewerWearable need to support more then one item.
+                    LL_WARNS() << "Same LLViewerWearable is used by multiple items! " << wearable->getAssetID() << LL_ENDL;
+                    data.mWearable = wearable;
+                }
+            }
+        }
+    }
+
+    if (use_count > 1)
+    {
+        LL_WARNS() << "Copying wearable, multiple asset id uses! " << wearable->getAssetID() << LL_ENDL;
+        gInventory.notifyObservers();
+    }
 }
 
 static void onWearableAssetFetch(LLViewerWearable* wearable, void* data)
 {
-	LLWearableHoldingPattern* holder = (LLWearableHoldingPattern*)data;
-	holder->onWearableAssetFetch(wearable);
+    LLWearableHoldingPattern* holder = (LLWearableHoldingPattern*)data;
+    holder->onWearableAssetFetch(wearable);
 }
 
 
 static void removeDuplicateItems(LLInventoryModel::item_array_t& items)
 {
-	LLInventoryModel::item_array_t new_items;
-	std::set<LLUUID> items_seen;
-	std::deque<LLViewerInventoryItem*> tmp_list;
-	// Traverse from the front and keep the first of each item
-	// encountered, so we actually keep the *last* of each duplicate
-	// item.  This is needed to give the right priority when adding
-	// duplicate items to an existing outfit.
-	for (S32 i=items.size()-1; i>=0; i--)
-	{
-		LLViewerInventoryItem *item = items.at(i);
-		LLUUID item_id = item->getLinkedUUID();
-		if (items_seen.find(item_id)!=items_seen.end())
-			continue;
-		items_seen.insert(item_id);
-		tmp_list.push_front(item);
-	}
-	for (std::deque<LLViewerInventoryItem*>::iterator it = tmp_list.begin();
-		 it != tmp_list.end();
-		 ++it)
-	{
-		new_items.push_back(*it);
-	}
-	items = new_items;
+    LLInventoryModel::item_array_t new_items;
+    std::set<LLUUID> items_seen;
+    std::deque<LLViewerInventoryItem*> tmp_list;
+    // Traverse from the front and keep the first of each item
+    // encountered, so we actually keep the *last* of each duplicate
+    // item.  This is needed to give the right priority when adding
+    // duplicate items to an existing outfit.
+    for (S32 i=items.size()-1; i>=0; i--)
+    {
+        LLViewerInventoryItem *item = items.at(i);
+        LLUUID item_id = item->getLinkedUUID();
+        if (items_seen.find(item_id)!=items_seen.end())
+            continue;
+        items_seen.insert(item_id);
+        tmp_list.push_front(item);
+    }
+    for (std::deque<LLViewerInventoryItem*>::iterator it = tmp_list.begin();
+         it != tmp_list.end();
+         ++it)
+    {
+        new_items.push_back(*it);
+    }
+    items = new_items;
 }
 
 //=========================================================================
@@ -1402,15 +1402,15 @@ const LLUUID LLAppearanceMgr::getCOF() const
 
 S32 LLAppearanceMgr::getCOFVersion() const
 {
-	LLViewerInventoryCategory *cof = gInventory.getCategory(getCOF());
-	if (cof)
-	{
-		return cof->getVersion();
-	}
-	else
-	{
-		return LLViewerInventoryCategory::VERSION_UNKNOWN;
-	}
+    LLViewerInventoryCategory *cof = gInventory.getCategory(getCOF());
+    if (cof)
+    {
+        return cof->getVersion();
+    }
+    else
+    {
+        return LLViewerInventoryCategory::VERSION_UNKNOWN;
+    }
 }
 
 void LLAppearanceMgr::initCOFID()
@@ -1420,80 +1420,80 @@ void LLAppearanceMgr::initCOFID()
 
 const LLViewerInventoryItem* LLAppearanceMgr::getBaseOutfitLink()
 {
-	const LLUUID& current_outfit_cat = getCOF();
-	LLInventoryModel::cat_array_t cat_array;
-	LLInventoryModel::item_array_t item_array;
-	// Can't search on FT_OUTFIT since links to categories return FT_CATEGORY for type since they don't
-	// return preferred type.
-	LLIsType is_category( LLAssetType::AT_CATEGORY ); 
-	gInventory.collectDescendentsIf(current_outfit_cat,
-									cat_array,
-									item_array,
-									false,
-									is_category);
-	for (LLInventoryModel::item_array_t::const_iterator iter = item_array.begin();
-		 iter != item_array.end();
-		 iter++)
-	{
-		const LLViewerInventoryItem *item = (*iter);
-		const LLViewerInventoryCategory *cat = item->getLinkedCategory();
-		if (cat && cat->getPreferredType() == LLFolderType::FT_OUTFIT)
-		{
-			const LLUUID parent_id = cat->getParentUUID();
-			LLViewerInventoryCategory*  parent_cat =  gInventory.getCategory(parent_id);
-			// if base outfit moved to trash it means that we don't have base outfit
-			if (parent_cat != NULL && parent_cat->getPreferredType() == LLFolderType::FT_TRASH)
-			{
-				return NULL;
-			}
-			return item;
-		}
-	}
-	return NULL;
+    const LLUUID& current_outfit_cat = getCOF();
+    LLInventoryModel::cat_array_t cat_array;
+    LLInventoryModel::item_array_t item_array;
+    // Can't search on FT_OUTFIT since links to categories return FT_CATEGORY for type since they don't
+    // return preferred type.
+    LLIsType is_category( LLAssetType::AT_CATEGORY );
+    gInventory.collectDescendentsIf(current_outfit_cat,
+                                    cat_array,
+                                    item_array,
+                                    false,
+                                    is_category);
+    for (LLInventoryModel::item_array_t::const_iterator iter = item_array.begin();
+         iter != item_array.end();
+         iter++)
+    {
+        const LLViewerInventoryItem *item = (*iter);
+        const LLViewerInventoryCategory *cat = item->getLinkedCategory();
+        if (cat && cat->getPreferredType() == LLFolderType::FT_OUTFIT)
+        {
+            const LLUUID parent_id = cat->getParentUUID();
+            LLViewerInventoryCategory*  parent_cat =  gInventory.getCategory(parent_id);
+            // if base outfit moved to trash it means that we don't have base outfit
+            if (parent_cat != NULL && parent_cat->getPreferredType() == LLFolderType::FT_TRASH)
+            {
+                return NULL;
+            }
+            return item;
+        }
+    }
+    return NULL;
 }
 
 bool LLAppearanceMgr::getBaseOutfitName(std::string& name)
 {
-	const LLViewerInventoryItem* outfit_link = getBaseOutfitLink();
-	if(outfit_link)
-	{
-		const LLViewerInventoryCategory *cat = outfit_link->getLinkedCategory();
-		if (cat)
-		{
-			name = cat->getName();
-			return true;
-		}
-	}
-	return false;
+    const LLViewerInventoryItem* outfit_link = getBaseOutfitLink();
+    if(outfit_link)
+    {
+        const LLViewerInventoryCategory *cat = outfit_link->getLinkedCategory();
+        if (cat)
+        {
+            name = cat->getName();
+            return true;
+        }
+    }
+    return false;
 }
 
 const LLUUID LLAppearanceMgr::getBaseOutfitUUID()
 {
-	const LLViewerInventoryItem* outfit_link = getBaseOutfitLink();
-	if (!outfit_link || !outfit_link->getIsLinkType()) return LLUUID::null;
+    const LLViewerInventoryItem* outfit_link = getBaseOutfitLink();
+    if (!outfit_link || !outfit_link->getIsLinkType()) return LLUUID::null;
 
-	const LLViewerInventoryCategory* outfit_cat = outfit_link->getLinkedCategory();
-	if (!outfit_cat) return LLUUID::null;
+    const LLViewerInventoryCategory* outfit_cat = outfit_link->getLinkedCategory();
+    if (!outfit_cat) return LLUUID::null;
 
-	if (outfit_cat->getPreferredType() != LLFolderType::FT_OUTFIT)
-	{
-		LL_WARNS() << "Expected outfit type:" << LLFolderType::FT_OUTFIT << " but got type:" << outfit_cat->getType() << " for folder name:" << outfit_cat->getName() << LL_ENDL;
-		return LLUUID::null;
-	}
+    if (outfit_cat->getPreferredType() != LLFolderType::FT_OUTFIT)
+    {
+        LL_WARNS() << "Expected outfit type:" << LLFolderType::FT_OUTFIT << " but got type:" << outfit_cat->getType() << " for folder name:" << outfit_cat->getName() << LL_ENDL;
+        return LLUUID::null;
+    }
 
-	return outfit_cat->getUUID();
+    return outfit_cat->getUUID();
 }
 
 void wear_on_avatar_cb(const LLUUID& inv_item, bool do_replace = false)
 {
-	if (inv_item.isNull())
-		return;
-	
-	LLViewerInventoryItem *item = gInventory.getItem(inv_item);
-	if (item)
-	{
-		LLAppearanceMgr::instance().wearItemOnAvatar(inv_item, true, do_replace);
-	}
+    if (inv_item.isNull())
+        return;
+
+    LLViewerInventoryItem *item = gInventory.getItem(inv_item);
+    if (item)
+    {
+        LLAppearanceMgr::instance().wearItemOnAvatar(inv_item, true, do_replace);
+    }
 }
 
 void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
@@ -1535,13 +1535,13 @@ void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
             copy_inventory_item(gAgent.getID(), item_to_wear->getPermissions().getOwner(),
                                 item_to_wear->getUUID(), LLUUID::null, std::string(), cb);
             continue;
-        } 
+        }
         else if (!gInventory.isObjectDescendentOf(item_to_wear->getUUID(), gInventory.getRootFolderID()))
         {
-			// not in library and not in agent's inventory
+            // not in library and not in agent's inventory
             LL_DEBUGS("Avatar") << "inventory item not in user inventory or library, skipping "
                                 << item_to_wear->getName() << " id " << item_id_to_wear << LL_ENDL;
-            continue; 
+            continue;
         }
         else if (gInventory.isObjectDescendentOf(item_to_wear->getUUID(), gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH)))
         {
@@ -1583,20 +1583,20 @@ void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
                         LLUUID item_id = gAgentWearables.getWearableItemID(item_to_wear->getWearableType(),
                                                                            wearable_count-1);
 // [SL:KB] - Patch: Appearance-AISFilter | Checked: 2015-05-02 (Catznip-3.7)
-						removeCOFItemLinks(item_id, NULL, true);
+                        removeCOFItemLinks(item_id, NULL, true);
 // [/SL:KB]
-//						removeCOFItemLinks(item_id, cb);
+//                      removeCOFItemLinks(item_id, cb);
                     }
-                    
+
                     items_to_link.push_back(item_to_wear);
-                } 
+                }
             }
             break;
 
             case LLAssetType::AT_BODYPART:
             {
                 // TODO: investigate wearables may not be loaded at this point EXT-8231
-                
+
                 // Remove the existing wearables of the same type.
                 // Remove existing body parts anyway because we must not be able to wear e.g. two skins.
                 removeCOFLinksOfType(item_to_wear->getWearableType());
@@ -1607,7 +1607,7 @@ void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
                 items_to_link.push_back(item_to_wear);
             }
             break;
-                
+
             case LLAssetType::AT_OBJECT:
             {
                 rez_attachment(item_to_wear, NULL, replace);
@@ -1621,14 +1621,14 @@ void LLAppearanceMgr::wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
     // Batch up COF link creation - more efficient if using AIS.
     if (items_to_link.size())
     {
-        link_inventory_array(getCOF(), items_to_link, cb); 
+        link_inventory_array(getCOF(), items_to_link, cb);
     }
 }
 
 void LLAppearanceMgr::wearItemOnAvatar(const LLUUID& item_id_to_wear,
-									   bool do_update,
-									   bool replace,
-									   LLPointer<LLInventoryCallback> cb)
+                                       bool do_update,
+                                       bool replace,
+                                       LLPointer<LLInventoryCallback> cb)
 {
     uuid_vec_t ids;
     ids.push_back(item_id_to_wear);
@@ -1638,15 +1638,15 @@ void LLAppearanceMgr::wearItemOnAvatar(const LLUUID& item_id_to_wear,
 // Update appearance from outfit folder.
 void LLAppearanceMgr::changeOutfit(bool proceed, const LLUUID& category, bool append)
 {
-	if (!proceed)
-		return;
-	LLAppearanceMgr::instance().updateCOF(category,append);
+    if (!proceed)
+        return;
+    LLAppearanceMgr::instance().updateCOF(category,append);
 }
 
 void LLAppearanceMgr::replaceCurrentOutfit(const LLUUID& new_outfit)
 {
-	LLViewerInventoryCategory* cat = gInventory.getCategory(new_outfit);
-	wearInventoryCategory(cat, false, false);
+    LLViewerInventoryCategory* cat = gInventory.getCategory(new_outfit);
+    wearInventoryCategory(cat, false, false);
 }
 
 // Remove existing photo link from outfit folder.
@@ -1679,112 +1679,112 @@ void LLAppearanceMgr::removeOutfitPhoto(const LLUUID& outfit_id)
 // Open outfit renaming dialog.
 void LLAppearanceMgr::renameOutfit(const LLUUID& outfit_id)
 {
-	LLViewerInventoryCategory* cat = gInventory.getCategory(outfit_id);
-	if (!cat)
-	{
-		return;
-	}
+    LLViewerInventoryCategory* cat = gInventory.getCategory(outfit_id);
+    if (!cat)
+    {
+        return;
+    }
 
-	LLSD args;
-	args["NAME"] = cat->getName();
+    LLSD args;
+    args["NAME"] = cat->getName();
 
-	LLSD payload;
-	payload["cat_id"] = outfit_id;
+    LLSD payload;
+    payload["cat_id"] = outfit_id;
 
-	LLNotificationsUtil::add("RenameOutfit", args, payload, boost::bind(onOutfitRename, _1, _2));
+    LLNotificationsUtil::add("RenameOutfit", args, payload, boost::bind(onOutfitRename, _1, _2));
 }
 
 // User typed new outfit name.
 // static
 void LLAppearanceMgr::onOutfitRename(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0) return; // canceled
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option != 0) return; // canceled
 
-	std::string outfit_name = response["new_name"].asString();
-	LLStringUtil::trim(outfit_name);
-	if (!outfit_name.empty())
-	{
-		LLUUID cat_id = notification["payload"]["cat_id"].asUUID();
-		rename_category(&gInventory, cat_id, outfit_name);
-	}
+    std::string outfit_name = response["new_name"].asString();
+    LLStringUtil::trim(outfit_name);
+    if (!outfit_name.empty())
+    {
+        LLUUID cat_id = notification["payload"]["cat_id"].asUUID();
+        rename_category(&gInventory, cat_id, outfit_name);
+    }
 }
 
 void LLAppearanceMgr::setOutfitLocked(bool locked)
 {
-	if (mOutfitLocked == locked)
-	{
-		return;
-	}
+    if (mOutfitLocked == locked)
+    {
+        return;
+    }
 
-	mOutfitLocked = locked;
-	if (locked)
-	{
-		mUnlockOutfitTimer->reset();
-		mUnlockOutfitTimer->start();
-	}
-	else
-	{
-		mUnlockOutfitTimer->stop();
-	}
+    mOutfitLocked = locked;
+    if (locked)
+    {
+        mUnlockOutfitTimer->reset();
+        mUnlockOutfitTimer->start();
+    }
+    else
+    {
+        mUnlockOutfitTimer->stop();
+    }
 
-	LLOutfitObserver::instance().notifyOutfitLockChanged();
+    LLOutfitObserver::instance().notifyOutfitLockChanged();
 }
 
 void LLAppearanceMgr::addCategoryToCurrentOutfit(const LLUUID& cat_id)
 {
-	LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
-	wearInventoryCategory(cat, false, true);
+    LLViewerInventoryCategory* cat = gInventory.getCategory(cat_id);
+    wearInventoryCategory(cat, false, true);
 }
 
 void LLAppearanceMgr::takeOffOutfit(const LLUUID& cat_id)
 {
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	LLFindWearablesEx collector(/*is_worn=*/ true, /*include_body_parts=*/ false);
-
-	gInventory.collectDescendentsIf(cat_id, cats, items, FALSE, collector);
-
-	LLInventoryModel::item_array_t::const_iterator it = items.begin();
-	const LLInventoryModel::item_array_t::const_iterator it_end = items.end();
-	uuid_vec_t uuids_to_remove;
-	for( ; it_end != it; ++it)
-	{
-		LLViewerInventoryItem* item = *it;
-		uuids_to_remove.push_back(item->getUUID());
-	}
-	removeItemsFromAvatar(uuids_to_remove);
-
-	// deactivate all gestures in the outfit folder
-	LLInventoryModel::item_array_t gest_items;
-	getDescendentsOfAssetType(cat_id, gest_items, LLAssetType::AT_GESTURE);
-	for(S32 i = 0; i  < gest_items.size(); ++i)
-	{
-		LLViewerInventoryItem *gest_item = gest_items[i];
-		if ( LLGestureMgr::instance().isGestureActive( gest_item->getLinkedUUID()) )
-		{
-			LLGestureMgr::instance().deactivateGesture( gest_item->getLinkedUUID() );
-		}
-	}
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    LLFindWearablesEx collector(/*is_worn=*/ true, /*include_body_parts=*/ false);
+
+    gInventory.collectDescendentsIf(cat_id, cats, items, FALSE, collector);
+
+    LLInventoryModel::item_array_t::const_iterator it = items.begin();
+    const LLInventoryModel::item_array_t::const_iterator it_end = items.end();
+    uuid_vec_t uuids_to_remove;
+    for( ; it_end != it; ++it)
+    {
+        LLViewerInventoryItem* item = *it;
+        uuids_to_remove.push_back(item->getUUID());
+    }
+    removeItemsFromAvatar(uuids_to_remove);
+
+    // deactivate all gestures in the outfit folder
+    LLInventoryModel::item_array_t gest_items;
+    getDescendentsOfAssetType(cat_id, gest_items, LLAssetType::AT_GESTURE);
+    for(S32 i = 0; i  < gest_items.size(); ++i)
+    {
+        LLViewerInventoryItem *gest_item = gest_items[i];
+        if ( LLGestureMgr::instance().isGestureActive( gest_item->getLinkedUUID()) )
+        {
+            LLGestureMgr::instance().deactivateGesture( gest_item->getLinkedUUID() );
+        }
+    }
 }
 
 // Create a copy of src_id + contents as a subfolder of dst_id.
 void LLAppearanceMgr::shallowCopyCategory(const LLUUID& src_id, const LLUUID& dst_id,
-											  LLPointer<LLInventoryCallback> cb)
-{
-	LLInventoryCategory *src_cat = gInventory.getCategory(src_id);
-	if (!src_cat)
-	{
-		LL_WARNS() << "folder not found for src " << src_id.asString() << LL_ENDL;
-		return;
-	}
-	LL_INFOS() << "starting, src_id " << src_id << " name " << src_cat->getName() << " dst_id " << dst_id << LL_ENDL;
-	LLUUID parent_id = dst_id;
-	if(parent_id.isNull())
-	{
-		parent_id = gInventory.getRootFolderID();
-	}
-	gInventory.createNewCategory(
+                                              LLPointer<LLInventoryCallback> cb)
+{
+    LLInventoryCategory *src_cat = gInventory.getCategory(src_id);
+    if (!src_cat)
+    {
+        LL_WARNS() << "folder not found for src " << src_id.asString() << LL_ENDL;
+        return;
+    }
+    LL_INFOS() << "starting, src_id " << src_id << " name " << src_cat->getName() << " dst_id " << dst_id << LL_ENDL;
+    LLUUID parent_id = dst_id;
+    if(parent_id.isNull())
+    {
+        parent_id = gInventory.getRootFolderID();
+    }
+    gInventory.createNewCategory(
         parent_id,
         LLFolderType::FT_NONE,
         src_cat->getName(),
@@ -1799,348 +1799,348 @@ void LLAppearanceMgr::shallowCopyCategory(const LLUUID& src_id, const LLUUID& ds
 }
 
 void LLAppearanceMgr::slamCategoryLinks(const LLUUID& src_id, const LLUUID& dst_id,
-										bool include_folder_links, LLPointer<LLInventoryCallback> cb)
-{
-	LLInventoryModel::cat_array_t* cats;
-	LLInventoryModel::item_array_t* items;
-	LLSD contents = LLSD::emptyArray();
-	gInventory.getDirectDescendentsOf(src_id, cats, items);
-	if (!cats || !items)
-	{
-		// NULL means the call failed -- cats/items map doesn't exist (note: this does NOT mean
-		// that the cat just doesn't have any items or subfolders).
-		LLViewerInventoryCategory* category = gInventory.getCategory(src_id);
-		if (category)
-		{
-			LL_WARNS() << "Category '" << category->getName() << "' descendents corrupted, linking content failed." << LL_ENDL;
-		}
-		else
-		{
-			LL_WARNS() << "Category could not be retrieved, linking content failed." << LL_ENDL;
-		}
-		llassert(cats != NULL && items != NULL);
-
-		return;
-	}
-
-	LL_INFOS() << "copying " << items->size() << " items" << LL_ENDL;
-	for (LLInventoryModel::item_array_t::const_iterator iter = items->begin();
-		 iter != items->end();
-		 ++iter)
-	{
-		const LLViewerInventoryItem* item = (*iter);
-		switch (item->getActualType())
-		{
-			case LLAssetType::AT_LINK:
-			{
-				LL_DEBUGS("Avatar") << "linking inventory item " << item->getName() << LL_ENDL;
-				//getActualDescription() is used for a new description 
-				//to propagate ordering information saved in descriptions of links
-				LLSD item_contents;
-				item_contents["name"] = item->getName();
-				item_contents["desc"] = item->getActualDescription();
-				item_contents["linked_id"] = item->getLinkedUUID();
-				item_contents["type"] = LLAssetType::AT_LINK; 
-				contents.append(item_contents);
-				break;
-			}
-			case LLAssetType::AT_LINK_FOLDER:
-			{
-				LLViewerInventoryCategory *catp = item->getLinkedCategory();
-				if (catp && include_folder_links)
-				{
-					LL_DEBUGS("Avatar") << "linking inventory folder " << item->getName() << LL_ENDL;
-					LLSD base_contents;
-					base_contents["name"] = catp->getName();
-					base_contents["desc"] = ""; // categories don't have descriptions.
-					base_contents["linked_id"] = catp->getLinkedUUID();
-					base_contents["type"] = LLAssetType::AT_LINK_FOLDER; 
-					contents.append(base_contents);
-				}
-				break;
-			}
-			default:
-			{
-				// Linux refuses to compile unless all possible enums are handled. Really, Linux?
-				break;
-			}
-		}
-	}
-	slam_inventory_folder(dst_id, contents, cb);
+                                        bool include_folder_links, LLPointer<LLInventoryCallback> cb)
+{
+    LLInventoryModel::cat_array_t* cats;
+    LLInventoryModel::item_array_t* items;
+    LLSD contents = LLSD::emptyArray();
+    gInventory.getDirectDescendentsOf(src_id, cats, items);
+    if (!cats || !items)
+    {
+        // NULL means the call failed -- cats/items map doesn't exist (note: this does NOT mean
+        // that the cat just doesn't have any items or subfolders).
+        LLViewerInventoryCategory* category = gInventory.getCategory(src_id);
+        if (category)
+        {
+            LL_WARNS() << "Category '" << category->getName() << "' descendents corrupted, linking content failed." << LL_ENDL;
+        }
+        else
+        {
+            LL_WARNS() << "Category could not be retrieved, linking content failed." << LL_ENDL;
+        }
+        llassert(cats != NULL && items != NULL);
+
+        return;
+    }
+
+    LL_INFOS() << "copying " << items->size() << " items" << LL_ENDL;
+    for (LLInventoryModel::item_array_t::const_iterator iter = items->begin();
+         iter != items->end();
+         ++iter)
+    {
+        const LLViewerInventoryItem* item = (*iter);
+        switch (item->getActualType())
+        {
+            case LLAssetType::AT_LINK:
+            {
+                LL_DEBUGS("Avatar") << "linking inventory item " << item->getName() << LL_ENDL;
+                //getActualDescription() is used for a new description
+                //to propagate ordering information saved in descriptions of links
+                LLSD item_contents;
+                item_contents["name"] = item->getName();
+                item_contents["desc"] = item->getActualDescription();
+                item_contents["linked_id"] = item->getLinkedUUID();
+                item_contents["type"] = LLAssetType::AT_LINK;
+                contents.append(item_contents);
+                break;
+            }
+            case LLAssetType::AT_LINK_FOLDER:
+            {
+                LLViewerInventoryCategory *catp = item->getLinkedCategory();
+                if (catp && include_folder_links)
+                {
+                    LL_DEBUGS("Avatar") << "linking inventory folder " << item->getName() << LL_ENDL;
+                    LLSD base_contents;
+                    base_contents["name"] = catp->getName();
+                    base_contents["desc"] = ""; // categories don't have descriptions.
+                    base_contents["linked_id"] = catp->getLinkedUUID();
+                    base_contents["type"] = LLAssetType::AT_LINK_FOLDER;
+                    contents.append(base_contents);
+                }
+                break;
+            }
+            default:
+            {
+                // Linux refuses to compile unless all possible enums are handled. Really, Linux?
+                break;
+            }
+        }
+    }
+    slam_inventory_folder(dst_id, contents, cb);
 }
 // Copy contents of src_id to dst_id.
 void LLAppearanceMgr::shallowCopyCategoryContents(const LLUUID& src_id, const LLUUID& dst_id,
-													  LLPointer<LLInventoryCallback> cb)
-{
-	LLInventoryModel::cat_array_t* cats;
-	LLInventoryModel::item_array_t* items;
-	gInventory.getDirectDescendentsOf(src_id, cats, items);
-	LL_INFOS() << "copying " << items->size() << " items" << LL_ENDL;
-	LLInventoryObject::const_object_list_t link_array;
-	for (LLInventoryModel::item_array_t::const_iterator iter = items->begin();
-		 iter != items->end();
-		 ++iter)
-	{
-		const LLViewerInventoryItem* item = (*iter);
-		switch (item->getActualType())
-		{
-			case LLAssetType::AT_LINK:
-			{
-				LL_DEBUGS("Avatar") << "linking inventory item " << item->getName() << LL_ENDL;
-				link_array.push_back(LLConstPointer<LLInventoryObject>(item));
-				break;
-			}
-			case LLAssetType::AT_LINK_FOLDER:
-			{
-				LLViewerInventoryCategory *catp = item->getLinkedCategory();
-				// Skip copying outfit links.
-				if (catp && catp->getPreferredType() != LLFolderType::FT_OUTFIT)
-				{
-					LL_DEBUGS("Avatar") << "linking inventory folder " << item->getName() << LL_ENDL;
-					link_array.push_back(LLConstPointer<LLInventoryObject>(item));
-				}
-				break;
-			}
-			case LLAssetType::AT_CLOTHING:
-			case LLAssetType::AT_OBJECT:
-			case LLAssetType::AT_BODYPART:
-			case LLAssetType::AT_GESTURE:
-			{
-				LL_DEBUGS("Avatar") << "copying inventory item " << item->getName() << LL_ENDL;
-				copy_inventory_item(gAgent.getID(),
-									item->getPermissions().getOwner(),
-									item->getUUID(),
-									dst_id,
-									item->getName(),
-									cb);
-				break;
-			}
-			default:
-				// Ignore non-outfit asset types
-				break;
-		}
-	}
-	if (!link_array.empty())
-	{
-		link_inventory_array(dst_id, link_array, cb);
-	}
+                                                      LLPointer<LLInventoryCallback> cb)
+{
+    LLInventoryModel::cat_array_t* cats;
+    LLInventoryModel::item_array_t* items;
+    gInventory.getDirectDescendentsOf(src_id, cats, items);
+    LL_INFOS() << "copying " << items->size() << " items" << LL_ENDL;
+    LLInventoryObject::const_object_list_t link_array;
+    for (LLInventoryModel::item_array_t::const_iterator iter = items->begin();
+         iter != items->end();
+         ++iter)
+    {
+        const LLViewerInventoryItem* item = (*iter);
+        switch (item->getActualType())
+        {
+            case LLAssetType::AT_LINK:
+            {
+                LL_DEBUGS("Avatar") << "linking inventory item " << item->getName() << LL_ENDL;
+                link_array.push_back(LLConstPointer<LLInventoryObject>(item));
+                break;
+            }
+            case LLAssetType::AT_LINK_FOLDER:
+            {
+                LLViewerInventoryCategory *catp = item->getLinkedCategory();
+                // Skip copying outfit links.
+                if (catp && catp->getPreferredType() != LLFolderType::FT_OUTFIT)
+                {
+                    LL_DEBUGS("Avatar") << "linking inventory folder " << item->getName() << LL_ENDL;
+                    link_array.push_back(LLConstPointer<LLInventoryObject>(item));
+                }
+                break;
+            }
+            case LLAssetType::AT_CLOTHING:
+            case LLAssetType::AT_OBJECT:
+            case LLAssetType::AT_BODYPART:
+            case LLAssetType::AT_GESTURE:
+            {
+                LL_DEBUGS("Avatar") << "copying inventory item " << item->getName() << LL_ENDL;
+                copy_inventory_item(gAgent.getID(),
+                                    item->getPermissions().getOwner(),
+                                    item->getUUID(),
+                                    dst_id,
+                                    item->getName(),
+                                    cb);
+                break;
+            }
+            default:
+                // Ignore non-outfit asset types
+                break;
+        }
+    }
+    if (!link_array.empty())
+    {
+        link_inventory_array(dst_id, link_array, cb);
+    }
 }
 
 BOOL LLAppearanceMgr::getCanMakeFolderIntoOutfit(const LLUUID& folder_id)
 {
-	// These are the wearable items that are required for considering this
-	// folder as containing a complete outfit.
-	U32 required_wearables = 0;
-	required_wearables |= 1LL << LLWearableType::WT_SHAPE;
-	required_wearables |= 1LL << LLWearableType::WT_SKIN;
-	required_wearables |= 1LL << LLWearableType::WT_HAIR;
-	required_wearables |= 1LL << LLWearableType::WT_EYES;
-
-	// These are the wearables that the folder actually contains.
-	U32 folder_wearables = 0;
-	LLInventoryModel::cat_array_t* cats;
-	LLInventoryModel::item_array_t* items;
-	gInventory.getDirectDescendentsOf(folder_id, cats, items);
-	for (LLInventoryModel::item_array_t::const_iterator iter = items->begin();
-		 iter != items->end();
-		 ++iter)
-	{
-		const LLViewerInventoryItem* item = (*iter);
-		if (item->isWearableType())
-		{
-			const LLWearableType::EType wearable_type = item->getWearableType();
-			folder_wearables |= 1LL << wearable_type;
-		}
-	}
-
-	// If the folder contains the required wearables, return TRUE.
-	return ((required_wearables & folder_wearables) == required_wearables);
+    // These are the wearable items that are required for considering this
+    // folder as containing a complete outfit.
+    U32 required_wearables = 0;
+    required_wearables |= 1LL << LLWearableType::WT_SHAPE;
+    required_wearables |= 1LL << LLWearableType::WT_SKIN;
+    required_wearables |= 1LL << LLWearableType::WT_HAIR;
+    required_wearables |= 1LL << LLWearableType::WT_EYES;
+
+    // These are the wearables that the folder actually contains.
+    U32 folder_wearables = 0;
+    LLInventoryModel::cat_array_t* cats;
+    LLInventoryModel::item_array_t* items;
+    gInventory.getDirectDescendentsOf(folder_id, cats, items);
+    for (LLInventoryModel::item_array_t::const_iterator iter = items->begin();
+         iter != items->end();
+         ++iter)
+    {
+        const LLViewerInventoryItem* item = (*iter);
+        if (item->isWearableType())
+        {
+            const LLWearableType::EType wearable_type = item->getWearableType();
+            folder_wearables |= 1LL << wearable_type;
+        }
+    }
+
+    // If the folder contains the required wearables, return TRUE.
+    return ((required_wearables & folder_wearables) == required_wearables);
 }
 
 bool LLAppearanceMgr::getCanRemoveOutfit(const LLUUID& outfit_cat_id)
 {
-	// Disallow removing the base outfit.
-	if (outfit_cat_id == getBaseOutfitUUID())
-	{
-		return false;
-	}
+    // Disallow removing the base outfit.
+    if (outfit_cat_id == getBaseOutfitUUID())
+    {
+        return false;
+    }
 
-	// Check if the outfit folder itself is removable.
-	if (!get_is_category_removable(&gInventory, outfit_cat_id))
-	{
-		return false;
-	}
+    // Check if the outfit folder itself is removable.
+    if (!get_is_category_removable(&gInventory, outfit_cat_id))
+    {
+        return false;
+    }
 
-	// Check for the folder's non-removable descendants.
-	LLFindNonRemovableObjects filter_non_removable;
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	gInventory.collectDescendentsIf(outfit_cat_id, cats, items, false, filter_non_removable);
-	if (!cats.empty() || !items.empty())
-	{
-		return false;
-	}
+    // Check for the folder's non-removable descendants.
+    LLFindNonRemovableObjects filter_non_removable;
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    gInventory.collectDescendentsIf(outfit_cat_id, cats, items, false, filter_non_removable);
+    if (!cats.empty() || !items.empty())
+    {
+        return false;
+    }
 
-	return true;
+    return true;
 }
 
 // static
 bool LLAppearanceMgr::getCanRemoveFromCOF(const LLUUID& outfit_cat_id)
 {
-	if (gAgentWearables.isCOFChangeInProgress())
-	{
-		return false;
-	}
+    if (gAgentWearables.isCOFChangeInProgress())
+    {
+        return false;
+    }
 // [RLVa:KB] - Checked: RLVa-2.0.3
-	if ( (RlvActions::isRlvEnabled()) && (RlvFolderLocks::instance().isLockedFolder(outfit_cat_id, RLV_LOCK_REMOVE)) )
-	{
-		return false;
-	}
+    if ( (RlvActions::isRlvEnabled()) && (RlvFolderLocks::instance().isLockedFolder(outfit_cat_id, RLV_LOCK_REMOVE)) )
+    {
+        return false;
+    }
 // [/RLVa:KB]
 
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	LLFindWearablesEx is_worn(/*is_worn=*/ true, /*include_body_parts=*/ false);
-	gInventory.collectDescendentsIf(outfit_cat_id,
-		cats,
-		items,
-		LLInventoryModel::EXCLUDE_TRASH,
-		is_worn);
-	return items.size() > 0;
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    LLFindWearablesEx is_worn(/*is_worn=*/ true, /*include_body_parts=*/ false);
+    gInventory.collectDescendentsIf(outfit_cat_id,
+        cats,
+        items,
+        LLInventoryModel::EXCLUDE_TRASH,
+        is_worn);
+    return items.size() > 0;
 }
 
 // static
 bool LLAppearanceMgr::getCanAddToCOF(const LLUUID& outfit_cat_id)
 {
-	if (gAgentWearables.isCOFChangeInProgress())
-	{
-		return false;
-	}
+    if (gAgentWearables.isCOFChangeInProgress())
+    {
+        return false;
+    }
 
 // [RLVa:KB] - Checked: RLVa-2.0.3
-	if ( (RlvActions::isRlvEnabled()) && (RlvFolderLocks::instance().isLockedFolder(outfit_cat_id, RLV_LOCK_ADD)) )
-	{
-		return false;
-	}
+    if ( (RlvActions::isRlvEnabled()) && (RlvFolderLocks::instance().isLockedFolder(outfit_cat_id, RLV_LOCK_ADD)) )
+    {
+        return false;
+    }
 // [/RLVa:KB]
 
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	LLFindWearablesEx not_worn(/*is_worn=*/ false, /*include_body_parts=*/ false);
-	gInventory.collectDescendentsIf(outfit_cat_id,
-		cats,
-		items,
-		LLInventoryModel::EXCLUDE_TRASH,
-		not_worn);
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    LLFindWearablesEx not_worn(/*is_worn=*/ false, /*include_body_parts=*/ false);
+    gInventory.collectDescendentsIf(outfit_cat_id,
+        cats,
+        items,
+        LLInventoryModel::EXCLUDE_TRASH,
+        not_worn);
 
-	return items.size() > 0;
+    return items.size() > 0;
 }
 
 bool LLAppearanceMgr::getCanReplaceCOF(const LLUUID& outfit_cat_id)
 {
-	// Don't allow wearing anything while we're changing appearance.
-	if (gAgentWearables.isCOFChangeInProgress())
-	{
-		return false;
-	}
+    // Don't allow wearing anything while we're changing appearance.
+    if (gAgentWearables.isCOFChangeInProgress())
+    {
+        return false;
+    }
 
 // [RLVa:KB] - Checked: RLVa-2.0.3
-	// Block "Replace Current Outfit" if the user can't wear the new folder
-	if ( (RlvActions::isRlvEnabled()) && (RlvFolderLocks::instance().isLockedFolder(outfit_cat_id, RLV_LOCK_ADD)) )
-	{
-		return false;
-	}
+    // Block "Replace Current Outfit" if the user can't wear the new folder
+    if ( (RlvActions::isRlvEnabled()) && (RlvFolderLocks::instance().isLockedFolder(outfit_cat_id, RLV_LOCK_ADD)) )
+    {
+        return false;
+    }
 // [/RLVa:KB]
 
-	// Check whether it's the base outfit.
-	if (outfit_cat_id.isNull())
-	{
-		return false;
-	}
+    // Check whether it's the base outfit.
+    if (outfit_cat_id.isNull())
+    {
+        return false;
+    }
 
-	// Check whether the outfit contains any wearables
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	LLFindWearables is_wearable;
-	gInventory.collectDescendentsIf(outfit_cat_id,
-		cats,
-		items,
-		LLInventoryModel::EXCLUDE_TRASH,
-		is_wearable);
+    // Check whether the outfit contains any wearables
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    LLFindWearables is_wearable;
+    gInventory.collectDescendentsIf(outfit_cat_id,
+        cats,
+        items,
+        LLInventoryModel::EXCLUDE_TRASH,
+        is_wearable);
 
-	return items.size() > 0;
+    return items.size() > 0;
 }
 
 // Moved from LLWearableList::ContextMenu for wider utility.
 bool LLAppearanceMgr::canAddWearables(const uuid_vec_t& item_ids) const
 {
-	// TODO: investigate wearables may not be loaded at this point EXT-8231
-
-	U32 n_objects = 0;
-	U32 n_clothes = 0;
-
-	// Count given clothes (by wearable type) and objects.
-	for (uuid_vec_t::const_iterator it = item_ids.begin(); it != item_ids.end(); ++it)
-	{
-		const LLViewerInventoryItem* item = gInventory.getItem(*it);
-		if (!item)
-		{
-			return false;
-		}
-
-		if (item->getType() == LLAssetType::AT_OBJECT)
-		{
-			++n_objects;
-		}
-		else if (item->getType() == LLAssetType::AT_CLOTHING)
-		{
-			++n_clothes;
-		}
-		else if (item->getType() == LLAssetType::AT_BODYPART || item->getType() == LLAssetType::AT_GESTURE)
-		{
-			return isAgentAvatarValid();
-		}
-		else
-		{
-			LL_WARNS() << "Unexpected wearable type" << LL_ENDL;
-			return false;
-		}
-	}
-
-	// Check whether we can add all the objects.
-	if (!isAgentAvatarValid() || !gAgentAvatarp->canAttachMoreObjects(n_objects))
-	{
-		return false;
-	}
-
-	// Check whether we can add all the clothes.
+    // TODO: investigate wearables may not be loaded at this point EXT-8231
+
+    U32 n_objects = 0;
+    U32 n_clothes = 0;
+
+    // Count given clothes (by wearable type) and objects.
+    for (uuid_vec_t::const_iterator it = item_ids.begin(); it != item_ids.end(); ++it)
+    {
+        const LLViewerInventoryItem* item = gInventory.getItem(*it);
+        if (!item)
+        {
+            return false;
+        }
+
+        if (item->getType() == LLAssetType::AT_OBJECT)
+        {
+            ++n_objects;
+        }
+        else if (item->getType() == LLAssetType::AT_CLOTHING)
+        {
+            ++n_clothes;
+        }
+        else if (item->getType() == LLAssetType::AT_BODYPART || item->getType() == LLAssetType::AT_GESTURE)
+        {
+            return isAgentAvatarValid();
+        }
+        else
+        {
+            LL_WARNS() << "Unexpected wearable type" << LL_ENDL;
+            return false;
+        }
+    }
+
+    // Check whether we can add all the objects.
+    if (!isAgentAvatarValid() || !gAgentAvatarp->canAttachMoreObjects(n_objects))
+    {
+        return false;
+    }
+
+    // Check whether we can add all the clothes.
     U32 sum_clothes = n_clothes + gAgentWearables.getClothingLayerCount();
     return sum_clothes <= LLAgentWearables::MAX_CLOTHING_LAYERS;
 }
 
 void LLAppearanceMgr::purgeBaseOutfitLink(const LLUUID& category, LLPointer<LLInventoryCallback> cb)
 {
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	gInventory.collectDescendents(category, cats, items,
-								  LLInventoryModel::EXCLUDE_TRASH);
-	for (S32 i = 0; i < items.size(); ++i)
-	{
-		LLViewerInventoryItem *item = items.at(i);
-		if (item->getActualType() != LLAssetType::AT_LINK_FOLDER)
-			continue;
-		LLViewerInventoryCategory* catp = item->getLinkedCategory();
-		if(catp && catp->getPreferredType() == LLFolderType::FT_OUTFIT)
-		{
-			remove_inventory_item(item->getUUID(), cb);
-		}
-	}
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    gInventory.collectDescendents(category, cats, items,
+                                  LLInventoryModel::EXCLUDE_TRASH);
+    for (S32 i = 0; i < items.size(); ++i)
+    {
+        LLViewerInventoryItem *item = items.at(i);
+        if (item->getActualType() != LLAssetType::AT_LINK_FOLDER)
+            continue;
+        LLViewerInventoryCategory* catp = item->getLinkedCategory();
+        if(catp && catp->getPreferredType() == LLFolderType::FT_OUTFIT)
+        {
+            remove_inventory_item(item->getUUID(), cb);
+        }
+    }
 }
 
 // Keep the last N wearables of each type.  For viewer 2.0, N is 1 for
 // both body parts and clothing items.
 void LLAppearanceMgr::filterWearableItems(
-	LLInventoryModel::item_array_t& items, S32 max_per_type, S32 max_total)
+    LLInventoryModel::item_array_t& items, S32 max_per_type, S32 max_total)
 {
     // Restrict by max total items first.
     if ((max_total > 0) && (items.size() > max_total))
@@ -2168,7 +2168,7 @@ void LLAppearanceMgr::filterWearableItems(
                 continue;
 //            S32 start_index = llmax(0,size-max_per_type);
 // [SL:KB] - Patch: Appearance-Misc | Checked: 2010-05-11 (Catznip-2.0)
-			S32 start_index = llmax(0, size - ((LLWearableType::instance().getAllowMultiwear((LLWearableType::EType)i)) ? max_per_type : 1));
+            S32 start_index = llmax(0, size - ((LLWearableType::instance().getAllowMultiwear((LLWearableType::EType)i)) ? max_per_type : 1));
 // [/SL:KB[
             for (S32 j = start_index; j<size; j++)
             {
@@ -2182,478 +2182,478 @@ void LLAppearanceMgr::filterWearableItems(
 // [RLVa:KB] - Checked: 2010-03-05 (RLVa-1.2.0)
 void LLAppearanceMgr::updateCOF(const LLUUID& category, bool append)
 {
-	LLViewerInventoryCategory *pcat = gInventory.getCategory(category);
-	if (!pcat)
-	{
-		LL_WARNS() << "no category found for id " << category << LL_ENDL;
-		return;
-	}
-	LL_INFOS("Avatar") << self_av_string() << "starting, cat '" << (pcat ? pcat->getName() : "[UNKNOWN]") << "'" << LL_ENDL;
-
-	LLInventoryModel::item_array_t body_items_new, wear_items_new, obj_items_new, gest_items_new;
-	getDescendentsOfAssetType(category, body_items_new, LLAssetType::AT_BODYPART);
-	getDescendentsOfAssetType(category, wear_items_new, LLAssetType::AT_CLOTHING);
-	getDescendentsOfAssetType(category, obj_items_new, LLAssetType::AT_OBJECT);
-	getDescendentsOfAssetType(category, gest_items_new, LLAssetType::AT_GESTURE);
-	updateCOF(body_items_new, wear_items_new, obj_items_new, gest_items_new, append, category);
-}
-
-void LLAppearanceMgr::updateCOF(LLInventoryModel::item_array_t& body_items_new, 
-								LLInventoryModel::item_array_t& wear_items_new, 
-								LLInventoryModel::item_array_t& obj_items_new,
-								LLInventoryModel::item_array_t& gest_items_new,
-								bool append /*=false*/, const LLUUID& idOutfit /*=LLUUID::null*/, LLPointer<LLInventoryCallback> link_waiter /*= NULL*/)
+    LLViewerInventoryCategory *pcat = gInventory.getCategory(category);
+    if (!pcat)
+    {
+        LL_WARNS() << "no category found for id " << category << LL_ENDL;
+        return;
+    }
+    LL_INFOS("Avatar") << self_av_string() << "starting, cat '" << (pcat ? pcat->getName() : "[UNKNOWN]") << "'" << LL_ENDL;
+
+    LLInventoryModel::item_array_t body_items_new, wear_items_new, obj_items_new, gest_items_new;
+    getDescendentsOfAssetType(category, body_items_new, LLAssetType::AT_BODYPART);
+    getDescendentsOfAssetType(category, wear_items_new, LLAssetType::AT_CLOTHING);
+    getDescendentsOfAssetType(category, obj_items_new, LLAssetType::AT_OBJECT);
+    getDescendentsOfAssetType(category, gest_items_new, LLAssetType::AT_GESTURE);
+    updateCOF(body_items_new, wear_items_new, obj_items_new, gest_items_new, append, category);
+}
+
+void LLAppearanceMgr::updateCOF(LLInventoryModel::item_array_t& body_items_new,
+                                LLInventoryModel::item_array_t& wear_items_new,
+                                LLInventoryModel::item_array_t& obj_items_new,
+                                LLInventoryModel::item_array_t& gest_items_new,
+                                bool append /*=false*/, const LLUUID& idOutfit /*=LLUUID::null*/, LLPointer<LLInventoryCallback> link_waiter /*= NULL*/)
 // [/RLVa:KB]
 {
-//	LLViewerInventoryCategory *pcat = gInventory.getCategory(category);
-//	if (!pcat)
-//	{
-//		LL_WARNS() << "no category found for id " << category << LL_ENDL;
-//		return;
-//	}
-//	LL_INFOS("Avatar") << self_av_string() << "starting, cat '" << (pcat ? pcat->getName() : "[UNKNOWN]") << "'" << LL_ENDL;
+//  LLViewerInventoryCategory *pcat = gInventory.getCategory(category);
+//  if (!pcat)
+//  {
+//      LL_WARNS() << "no category found for id " << category << LL_ENDL;
+//      return;
+//  }
+//  LL_INFOS("Avatar") << self_av_string() << "starting, cat '" << (pcat ? pcat->getName() : "[UNKNOWN]") << "'" << LL_ENDL;
 // [RLVa:KB] - Checked: 2010-03-26 (RLVa-1.2.0)
-	LL_INFOS("Avatar") << "starting" << LL_ENDL;
+    LL_INFOS("Avatar") << "starting" << LL_ENDL;
 // [/RLVa:KB]
 
-	const LLUUID cof = getCOF();
-
-	// Deactivate currently active gestures in the COF, if replacing outfit
-	if (!append)
-	{
-		LLInventoryModel::item_array_t gest_items;
-		getDescendentsOfAssetType(cof, gest_items, LLAssetType::AT_GESTURE);
-		for(S32 i = 0; i  < gest_items.size(); ++i)
-		{
-			LLViewerInventoryItem *gest_item = gest_items.at(i);
-			if ( LLGestureMgr::instance().isGestureActive( gest_item->getLinkedUUID()) )
-			{
-				LLGestureMgr::instance().deactivateGesture( gest_item->getLinkedUUID() );
-			}
-		}
-	}
-	
-	// Collect and filter descendents to determine new COF contents.
-
-	//
-	// - Body parts: always include COF contents as a fallback in case any required parts are missing.
-	//
-	// Preserve body parts from COF if appending.
-	LLInventoryModel::item_array_t body_items;
-	getDescendentsOfAssetType(cof, body_items, LLAssetType::AT_BODYPART);
-//	getDescendentsOfAssetType(category, body_items, LLAssetType::AT_BODYPART);
+    const LLUUID cof = getCOF();
+
+    // Deactivate currently active gestures in the COF, if replacing outfit
+    if (!append)
+    {
+        LLInventoryModel::item_array_t gest_items;
+        getDescendentsOfAssetType(cof, gest_items, LLAssetType::AT_GESTURE);
+        for(S32 i = 0; i  < gest_items.size(); ++i)
+        {
+            LLViewerInventoryItem *gest_item = gest_items.at(i);
+            if ( LLGestureMgr::instance().isGestureActive( gest_item->getLinkedUUID()) )
+            {
+                LLGestureMgr::instance().deactivateGesture( gest_item->getLinkedUUID() );
+            }
+        }
+    }
+
+    // Collect and filter descendents to determine new COF contents.
+
+    //
+    // - Body parts: always include COF contents as a fallback in case any required parts are missing.
+    //
+    // Preserve body parts from COF if appending.
+    LLInventoryModel::item_array_t body_items;
+    getDescendentsOfAssetType(cof, body_items, LLAssetType::AT_BODYPART);
+//  getDescendentsOfAssetType(category, body_items, LLAssetType::AT_BODYPART);
 // [RLVa:KB] - Checked: RLVa-2.0.3
-	// Filter out any new body parts that can't be worn before adding them
-	if ( (RlvActions::isRlvEnabled()) && ((gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_ADD))) )
-		body_items_new.erase(std::remove_if(body_items_new.begin(), body_items_new.end(), RlvPredCanNotWearItem(RLV_WEAR_REPLACE)), body_items_new.end());
-	body_items.insert(body_items.end(), body_items_new.begin(), body_items_new.end());
+    // Filter out any new body parts that can't be worn before adding them
+    if ( (RlvActions::isRlvEnabled()) && ((gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_ADD))) )
+        body_items_new.erase(std::remove_if(body_items_new.begin(), body_items_new.end(), RlvPredCanNotWearItem(RLV_WEAR_REPLACE)), body_items_new.end());
+    body_items.insert(body_items.end(), body_items_new.begin(), body_items_new.end());
 // [/RLVa:KB]
-	// NOTE-RLVa: we don't actually want to favour COF body parts over the folder's body parts (if only because it breaks force wear)
-//	if (append)
-//		reverse(body_items.begin(), body_items.end());
-	// Reduce body items to max of one per type.
-	removeDuplicateItems(body_items);
-	filterWearableItems(body_items, 1, 0);
-
-	//
-	// - Wearables: include COF contents only if appending.
-	//
-	LLInventoryModel::item_array_t wear_items;
-	if (append)
-		getDescendentsOfAssetType(cof, wear_items, LLAssetType::AT_CLOTHING);
+    // NOTE-RLVa: we don't actually want to favour COF body parts over the folder's body parts (if only because it breaks force wear)
+//  if (append)
+//      reverse(body_items.begin(), body_items.end());
+    // Reduce body items to max of one per type.
+    removeDuplicateItems(body_items);
+    filterWearableItems(body_items, 1, 0);
+
+    //
+    // - Wearables: include COF contents only if appending.
+    //
+    LLInventoryModel::item_array_t wear_items;
+    if (append)
+        getDescendentsOfAssetType(cof, wear_items, LLAssetType::AT_CLOTHING);
 // [RLVa:KB] - Checked: RLVa-2.0.3
-	else if ( (RlvActions::isRlvEnabled()) && ((gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_REMOVE))) )
-	{
-		// Make sure that all currently locked clothing layers remain in COF when replacing
-		getDescendentsOfAssetType(cof, wear_items, LLAssetType::AT_CLOTHING);
-		wear_items.erase(std::remove_if(wear_items.begin(), wear_items.end(), RlvPredCanRemoveItem()), wear_items.end());
-	}
+    else if ( (RlvActions::isRlvEnabled()) && ((gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_REMOVE))) )
+    {
+        // Make sure that all currently locked clothing layers remain in COF when replacing
+        getDescendentsOfAssetType(cof, wear_items, LLAssetType::AT_CLOTHING);
+        wear_items.erase(std::remove_if(wear_items.begin(), wear_items.end(), RlvPredCanRemoveItem()), wear_items.end());
+    }
 // [/RLVa:KB]
-//	getDescendentsOfAssetType(category, wear_items, LLAssetType::AT_CLOTHING);
+//  getDescendentsOfAssetType(category, wear_items, LLAssetType::AT_CLOTHING);
 // [RLVa:KB] - Checked: RLVa-2.0.3
-	// Filter out any new wearables that can't be worn before adding them
-	if ( (RlvActions::isRlvEnabled()) && ((gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_ADD))) )
-		wear_items_new.erase(std::remove_if(wear_items_new.begin(), wear_items_new.end(), RlvPredCanNotWearItem(RLV_WEAR)), wear_items_new.end());
-	wear_items.insert(wear_items.end(), wear_items_new.begin(), wear_items_new.end());
+    // Filter out any new wearables that can't be worn before adding them
+    if ( (RlvActions::isRlvEnabled()) && ((gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_ADD))) )
+        wear_items_new.erase(std::remove_if(wear_items_new.begin(), wear_items_new.end(), RlvPredCanNotWearItem(RLV_WEAR)), wear_items_new.end());
+    wear_items.insert(wear_items.end(), wear_items_new.begin(), wear_items_new.end());
 // [/RLVa:KB]
-	// Reduce wearables to max of one per type.
-	removeDuplicateItems(wear_items);
-	filterWearableItems(wear_items, 0, LLAgentWearables::MAX_CLOTHING_LAYERS);
-
-	// - Attachments: include COF contents only if appending.
-	LLInventoryModel::item_array_t obj_items;
-	if (append)
-		getDescendentsOfAssetType(cof, obj_items, LLAssetType::AT_OBJECT);
+    // Reduce wearables to max of one per type.
+    removeDuplicateItems(wear_items);
+    filterWearableItems(wear_items, 0, LLAgentWearables::MAX_CLOTHING_LAYERS);
+
+    // - Attachments: include COF contents only if appending.
+    LLInventoryModel::item_array_t obj_items;
+    if (append)
+        getDescendentsOfAssetType(cof, obj_items, LLAssetType::AT_OBJECT);
 // [RLVa:KB] - Checked: RLVa-2.0.3
-	else if ( (RlvActions::isRlvEnabled()) && ((gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_REMOVE))) )
-	{
-		// Make sure that all currently locked attachments remain in COF when replacing
-		getDescendentsOfAssetType(cof, obj_items, LLAssetType::AT_OBJECT);
-		obj_items.erase(std::remove_if(obj_items.begin(), obj_items.end(), RlvPredCanRemoveItem()), obj_items.end());
-	}
+    else if ( (RlvActions::isRlvEnabled()) && ((gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_REMOVE))) )
+    {
+        // Make sure that all currently locked attachments remain in COF when replacing
+        getDescendentsOfAssetType(cof, obj_items, LLAssetType::AT_OBJECT);
+        obj_items.erase(std::remove_if(obj_items.begin(), obj_items.end(), RlvPredCanRemoveItem()), obj_items.end());
+    }
 // [/RLVa:KB]
-//	getDescendentsOfAssetType(category, obj_items, LLAssetType::AT_OBJECT);
+//  getDescendentsOfAssetType(category, obj_items, LLAssetType::AT_OBJECT);
 // [RLVa:KB] - Checked: RLVa-2.0.3
-	// Filter out any new attachments that can't be worn before adding them
-	if ( (RlvActions::isRlvEnabled()) && ((gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_ADD))) )
-		obj_items_new.erase(std::remove_if(obj_items_new.begin(), obj_items_new.end(), RlvPredCanNotWearItem(RLV_WEAR)), obj_items_new.end());
-	obj_items.insert(obj_items.end(), obj_items_new.begin(), obj_items_new.end());
+    // Filter out any new attachments that can't be worn before adding them
+    if ( (RlvActions::isRlvEnabled()) && ((gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) || (RlvFolderLocks::instance().hasLockedFolder(RLV_LOCK_ADD))) )
+        obj_items_new.erase(std::remove_if(obj_items_new.begin(), obj_items_new.end(), RlvPredCanNotWearItem(RLV_WEAR)), obj_items_new.end());
+    obj_items.insert(obj_items.end(), obj_items_new.begin(), obj_items_new.end());
 // [/RLVa:KB]
-	removeDuplicateItems(obj_items);
+    removeDuplicateItems(obj_items);
 
-	// - Gestures: include COF contents only if appending.
-	LLInventoryModel::item_array_t gest_items;
-	if (append)
-		getDescendentsOfAssetType(cof, gest_items, LLAssetType::AT_GESTURE);
-//	getDescendentsOfAssetType(category, gest_items, LLAssetType::AT_GESTURE);
+    // - Gestures: include COF contents only if appending.
+    LLInventoryModel::item_array_t gest_items;
+    if (append)
+        getDescendentsOfAssetType(cof, gest_items, LLAssetType::AT_GESTURE);
+//  getDescendentsOfAssetType(category, gest_items, LLAssetType::AT_GESTURE);
 // [RLVa:KB] - Checked: 2010-03-05 (RLVa-1.2.0)
-	gest_items.insert(gest_items.end(), gest_items_new.begin(), gest_items_new.end());
+    gest_items.insert(gest_items.end(), gest_items_new.begin(), gest_items_new.end());
 // [/RLVa:KB]
-	removeDuplicateItems(gest_items);
-	
-	// Create links to new COF contents.
-	LLInventoryModel::item_array_t all_items;
-	std::copy(body_items.begin(), body_items.end(), std::back_inserter(all_items));
-	std::copy(wear_items.begin(), wear_items.end(), std::back_inserter(all_items));
-	std::copy(obj_items.begin(), obj_items.end(), std::back_inserter(all_items));
-	std::copy(gest_items.begin(), gest_items.end(), std::back_inserter(all_items));
-
-	// Find any wearables that need description set to enforce ordering.
-	desc_map_t desc_map;
-	getWearableOrderingDescUpdates(wear_items, desc_map);
-
-	// Will link all the above items.
-	// link_waiter enforce flags are false because we've already fixed everything up in updateCOF().
-//	LLPointer<LLInventoryCallback> link_waiter = new LLUpdateAppearanceOnDestroy(false,false);
+    removeDuplicateItems(gest_items);
+
+    // Create links to new COF contents.
+    LLInventoryModel::item_array_t all_items;
+    std::copy(body_items.begin(), body_items.end(), std::back_inserter(all_items));
+    std::copy(wear_items.begin(), wear_items.end(), std::back_inserter(all_items));
+    std::copy(obj_items.begin(), obj_items.end(), std::back_inserter(all_items));
+    std::copy(gest_items.begin(), gest_items.end(), std::back_inserter(all_items));
+
+    // Find any wearables that need description set to enforce ordering.
+    desc_map_t desc_map;
+    getWearableOrderingDescUpdates(wear_items, desc_map);
+
+    // Will link all the above items.
+    // link_waiter enforce flags are false because we've already fixed everything up in updateCOF().
+//  LLPointer<LLInventoryCallback> link_waiter = new LLUpdateAppearanceOnDestroy(false,false);
 // [RLVa:KB] Checked: 2015-05-05 (RLVa-1.4.12)
-	if (!link_waiter)
-		link_waiter = new LLUpdateAppearanceOnDestroy(false, false);
+    if (!link_waiter)
+        link_waiter = new LLUpdateAppearanceOnDestroy(false, false);
 // [/RLVa:KB]
-	LLSD contents = LLSD::emptyArray();
-
-	for (LLInventoryModel::item_array_t::const_iterator it = all_items.begin();
-		 it != all_items.end(); ++it)
-	{
-		LLSD item_contents;
-		LLInventoryItem *item = *it;
-
-		std::string desc;
-		desc_map_t::const_iterator desc_iter = desc_map.find(item->getUUID());
-		if (desc_iter != desc_map.end())
-		{
-			desc = desc_iter->second;
-			LL_DEBUGS("Avatar") << item->getName() << " overriding desc to: " << desc
-								<< " (was: " << item->getActualDescription() << ")" << LL_ENDL;
-		}
-		else
-		{
-			desc = item->getActualDescription();
-		}
-
-		item_contents["name"] = item->getName();
-		item_contents["desc"] = desc;
-		item_contents["linked_id"] = item->getLinkedUUID();
-		item_contents["type"] = LLAssetType::AT_LINK; 
-		contents.append(item_contents);
-	}
-//	const LLUUID& base_id = append ? getBaseOutfitUUID() : category;
-//	LLViewerInventoryCategory *base_cat = gInventory.getCategory(base_id);
+    LLSD contents = LLSD::emptyArray();
+
+    for (LLInventoryModel::item_array_t::const_iterator it = all_items.begin();
+         it != all_items.end(); ++it)
+    {
+        LLSD item_contents;
+        LLInventoryItem *item = *it;
+
+        std::string desc;
+        desc_map_t::const_iterator desc_iter = desc_map.find(item->getUUID());
+        if (desc_iter != desc_map.end())
+        {
+            desc = desc_iter->second;
+            LL_DEBUGS("Avatar") << item->getName() << " overriding desc to: " << desc
+                                << " (was: " << item->getActualDescription() << ")" << LL_ENDL;
+        }
+        else
+        {
+            desc = item->getActualDescription();
+        }
+
+        item_contents["name"] = item->getName();
+        item_contents["desc"] = desc;
+        item_contents["linked_id"] = item->getLinkedUUID();
+        item_contents["type"] = LLAssetType::AT_LINK;
+        contents.append(item_contents);
+    }
+//  const LLUUID& base_id = append ? getBaseOutfitUUID() : category;
+//  LLViewerInventoryCategory *base_cat = gInventory.getCategory(base_id);
 // [RLVa:KB] - Checked: 2014-11-02 (RLVa-1.4.11)
-	const LLUUID& base_id = (append) ? getBaseOutfitUUID() : idOutfit;
-	LLViewerInventoryCategory* base_cat = (base_id.notNull()) ? gInventory.getCategory(base_id) : NULL;
+    const LLUUID& base_id = (append) ? getBaseOutfitUUID() : idOutfit;
+    LLViewerInventoryCategory* base_cat = (base_id.notNull()) ? gInventory.getCategory(base_id) : NULL;
 // [/RLVa:KB]
-	if (base_cat && (base_cat->getPreferredType() == LLFolderType::FT_OUTFIT))
-	{
-		LLSD base_contents;
-		base_contents["name"] = base_cat->getName();
-		base_contents["desc"] = "";
-		base_contents["linked_id"] = base_cat->getLinkedUUID();
-		base_contents["type"] = LLAssetType::AT_LINK_FOLDER; 
-		contents.append(base_contents);
-	}
-	if (gSavedSettings.getBOOL("DebugAvatarAppearanceMessage"))
-	{
-		dump_sequential_xml(gAgentAvatarp->getFullname() + "_slam_request", contents);
-	}
-	slam_inventory_folder(getCOF(), contents, link_waiter);
-
-	LL_DEBUGS("Avatar") << self_av_string() << "waiting for LLUpdateAppearanceOnDestroy" << LL_ENDL;
+    if (base_cat && (base_cat->getPreferredType() == LLFolderType::FT_OUTFIT))
+    {
+        LLSD base_contents;
+        base_contents["name"] = base_cat->getName();
+        base_contents["desc"] = "";
+        base_contents["linked_id"] = base_cat->getLinkedUUID();
+        base_contents["type"] = LLAssetType::AT_LINK_FOLDER;
+        contents.append(base_contents);
+    }
+    if (gSavedSettings.getBOOL("DebugAvatarAppearanceMessage"))
+    {
+        dump_sequential_xml(gAgentAvatarp->getFullname() + "_slam_request", contents);
+    }
+    slam_inventory_folder(getCOF(), contents, link_waiter);
+
+    LL_DEBUGS("Avatar") << self_av_string() << "waiting for LLUpdateAppearanceOnDestroy" << LL_ENDL;
 }
 
 void LLAppearanceMgr::updatePanelOutfitName(const std::string& name)
 {
-	LLSidepanelAppearance* panel_appearance =
-		dynamic_cast<LLSidepanelAppearance *>(LLFloaterSidePanelContainer::getPanel("appearance"));
-	if (panel_appearance)
-	{
-		panel_appearance->refreshCurrentOutfitName(name);
-	}
+    LLSidepanelAppearance* panel_appearance =
+        dynamic_cast<LLSidepanelAppearance *>(LLFloaterSidePanelContainer::getPanel("appearance"));
+    if (panel_appearance)
+    {
+        panel_appearance->refreshCurrentOutfitName(name);
+    }
 }
 
 void LLAppearanceMgr::createBaseOutfitLink(const LLUUID& category, LLPointer<LLInventoryCallback> link_waiter)
 {
-	const LLUUID cof = getCOF();
-	LLViewerInventoryCategory* catp = gInventory.getCategory(category);
-	std::string new_outfit_name = "";
+    const LLUUID cof = getCOF();
+    LLViewerInventoryCategory* catp = gInventory.getCategory(category);
+    std::string new_outfit_name = "";
 
-	purgeBaseOutfitLink(cof, link_waiter);
+    purgeBaseOutfitLink(cof, link_waiter);
 
-	if (catp && catp->getPreferredType() == LLFolderType::FT_OUTFIT)
-	{
-		link_inventory_object(cof, catp, link_waiter);
-		new_outfit_name = catp->getName();
-	}
-	
-	updatePanelOutfitName(new_outfit_name);
+    if (catp && catp->getPreferredType() == LLFolderType::FT_OUTFIT)
+    {
+        link_inventory_object(cof, catp, link_waiter);
+        new_outfit_name = catp->getName();
+    }
+
+    updatePanelOutfitName(new_outfit_name);
 }
 
 void LLAppearanceMgr::updateAgentWearables(LLWearableHoldingPattern* holder)
 {
-	LL_DEBUGS("Avatar") << "updateAgentWearables()" << LL_ENDL;
-	LLInventoryItem::item_array_t items;
-	std::vector< LLViewerWearable* > wearables;
-	wearables.reserve(32);
+    LL_DEBUGS("Avatar") << "updateAgentWearables()" << LL_ENDL;
+    LLInventoryItem::item_array_t items;
+    std::vector< LLViewerWearable* > wearables;
+    wearables.reserve(32);
 // [RLVa:KB] - Checked: 2011-03-31 (RLVa-1.3.0)
-	uuid_vec_t idsCurrent; LLInventoryModel::item_array_t itemsNew;
-	if (rlv_handler_t::isEnabled())
-	{
-		// Collect the item UUIDs of all currently worn wearables
-		gAgentWearables.getWearableItemIDs(idsCurrent);
-	}
+    uuid_vec_t idsCurrent; LLInventoryModel::item_array_t itemsNew;
+    if (rlv_handler_t::isEnabled())
+    {
+        // Collect the item UUIDs of all currently worn wearables
+        gAgentWearables.getWearableItemIDs(idsCurrent);
+    }
 // [/RLVa:KB]
 
-	// For each wearable type, find the wearables of that type.
-	for( S32 i = 0; i < LLWearableType::WT_COUNT; i++ )
-	{
-		for (LLWearableHoldingPattern::found_list_t::iterator iter = holder->getFoundList().begin();
-			 iter != holder->getFoundList().end(); ++iter)
-		{
-			LLFoundData& data = *iter;
-			LLViewerWearable* wearable = data.mWearable;
-			if( wearable && ((S32)wearable->getType() == i) )
-			{
-				LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getItem(data.mItemID);
-				if( item && (item->getAssetUUID() == wearable->getAssetID()) )
-				{
+    // For each wearable type, find the wearables of that type.
+    for( S32 i = 0; i < LLWearableType::WT_COUNT; i++ )
+    {
+        for (LLWearableHoldingPattern::found_list_t::iterator iter = holder->getFoundList().begin();
+             iter != holder->getFoundList().end(); ++iter)
+        {
+            LLFoundData& data = *iter;
+            LLViewerWearable* wearable = data.mWearable;
+            if( wearable && ((S32)wearable->getType() == i) )
+            {
+                LLViewerInventoryItem* item = (LLViewerInventoryItem*)gInventory.getItem(data.mItemID);
+                if( item && (item->getAssetUUID() == wearable->getAssetID()) )
+                {
 // [RLVa:KB] - Checked: 2010-03-19 (RLVa-1.2.0)
-					// TODO-RLVa: [RLVa-1.2.1] This is fall-back code so if we don't ever trigger this code it can just be removed
-					//   -> one way to trigger the assertion:
-					//			1) "Replace Outfit" on a folder with clothing and an attachment that goes @addoutfit=n
-					//			2) updateCOF will add/link the items into COF => no @addoutfit=n present yet => allowed
-					//			3) llOwnerSay("@addoutfit=n") executes
-					//			4) code below runs => @addoutfit=n conflicts with adding new wearables
-					//     => if it's left as-is then the wearables won't get worn (but remain in COF which causes issues of its own)
-					//     => if it's changed to debug-only then we make tge assumption that anything that makes it into COF is always OK
+                    // TODO-RLVa: [RLVa-1.2.1] This is fall-back code so if we don't ever trigger this code it can just be removed
+                    //   -> one way to trigger the assertion:
+                    //          1) "Replace Outfit" on a folder with clothing and an attachment that goes @addoutfit=n
+                    //          2) updateCOF will add/link the items into COF => no @addoutfit=n present yet => allowed
+                    //          3) llOwnerSay("@addoutfit=n") executes
+                    //          4) code below runs => @addoutfit=n conflicts with adding new wearables
+                    //     => if it's left as-is then the wearables won't get worn (but remain in COF which causes issues of its own)
+                    //     => if it's changed to debug-only then we make tge assumption that anything that makes it into COF is always OK
 #ifdef RLV_DEBUG
-					// NOTE: make sure we don't accidentally block setting the initial wearables
-					if ( (rlv_handler_t::isEnabled()) && (RLV_WEAR_LOCKED == gRlvWearableLocks.canWear(wearable->getType())) &&
-						 (!gAgentWearables.getWearableFromItemID(item->getUUID())) && (gAgentWearables.areWearablesLoaded()) )
-					{
-						RLV_VERIFY(RLV_WEAR_LOCKED == gRlvWearableLocks.canWear(wearable->getType()));
-						continue;
-					}
+                    // NOTE: make sure we don't accidentally block setting the initial wearables
+                    if ( (rlv_handler_t::isEnabled()) && (RLV_WEAR_LOCKED == gRlvWearableLocks.canWear(wearable->getType())) &&
+                         (!gAgentWearables.getWearableFromItemID(item->getUUID())) && (gAgentWearables.areWearablesLoaded()) )
+                    {
+                        RLV_VERIFY(RLV_WEAR_LOCKED == gRlvWearableLocks.canWear(wearable->getType()));
+                        continue;
+                    }
 #endif // RLV_DEBUG
 // [/RLVa:KB]
-					items.push_back(item);
-					wearables.push_back(wearable);
+                    items.push_back(item);
+                    wearables.push_back(wearable);
 // [RLVa:KB] - Checked: 2011-03-31 (RLVa-1.3.0)
-					if ( (rlv_handler_t::isEnabled()) && (gAgentWearables.areInitalWearablesLoaded()) )
-					{
-						// Remove the wearable from current item UUIDs if currently worn and requested, otherwise mark it as a new item
-						uuid_vec_t::iterator itItemID = std::find(idsCurrent.begin(), idsCurrent.end(), item->getUUID());
-						if (idsCurrent.end() != itItemID)
-							idsCurrent.erase(itItemID);
-						else
-							itemsNew.push_back(item);
-					}
+                    if ( (rlv_handler_t::isEnabled()) && (gAgentWearables.areInitalWearablesLoaded()) )
+                    {
+                        // Remove the wearable from current item UUIDs if currently worn and requested, otherwise mark it as a new item
+                        uuid_vec_t::iterator itItemID = std::find(idsCurrent.begin(), idsCurrent.end(), item->getUUID());
+                        if (idsCurrent.end() != itItemID)
+                            idsCurrent.erase(itItemID);
+                        else
+                            itemsNew.push_back(item);
+                    }
 // [/RLVa:KB]
-				}
-			}
-		}
-	}
+                }
+            }
+        }
+    }
 
 // [RLVa:KB] - Checked: 2011-03-31 (RLVa-1.3.0)
-	if ( (rlv_handler_t::isEnabled()) && (gAgentWearables.areInitalWearablesLoaded()) )
-	{
-		// We need to report removals before additions or scripts will get confused
-		for (uuid_vec_t::const_iterator itItemID = idsCurrent.begin(); itItemID != idsCurrent.end(); ++itItemID)
-		{
-			const LLWearable* pWearable = gAgentWearables.getWearableFromItemID(*itItemID);
-			if (pWearable)
-				RlvBehaviourNotifyHandler::onTakeOff(pWearable->getType(), true);
-		}
-		for (S32 idxItem = 0, cntItem = itemsNew.size(); idxItem < cntItem; idxItem++)
-		{
-			RlvBehaviourNotifyHandler::onWear(itemsNew.at(idxItem)->getWearableType(), true);
-		}
-	}
+    if ( (rlv_handler_t::isEnabled()) && (gAgentWearables.areInitalWearablesLoaded()) )
+    {
+        // We need to report removals before additions or scripts will get confused
+        for (uuid_vec_t::const_iterator itItemID = idsCurrent.begin(); itItemID != idsCurrent.end(); ++itItemID)
+        {
+            const LLWearable* pWearable = gAgentWearables.getWearableFromItemID(*itItemID);
+            if (pWearable)
+                RlvBehaviourNotifyHandler::onTakeOff(pWearable->getType(), true);
+        }
+        for (S32 idxItem = 0, cntItem = itemsNew.size(); idxItem < cntItem; idxItem++)
+        {
+            RlvBehaviourNotifyHandler::onWear(itemsNew.at(idxItem)->getWearableType(), true);
+        }
+    }
 // [/RLVa:KB]
 
-	if(wearables.size() > 0)
-	{
-		gAgentWearables.setWearableOutfit(items, wearables);
-	}
+    if(wearables.size() > 0)
+    {
+        gAgentWearables.setWearableOutfit(items, wearables);
+    }
 }
 
 S32 LLAppearanceMgr::countActiveHoldingPatterns()
 {
-	return LLWearableHoldingPattern::countActive();
+    return LLWearableHoldingPattern::countActive();
 }
 
 static void remove_non_link_items(LLInventoryModel::item_array_t &items)
 {
-	LLInventoryModel::item_array_t pruned_items;
-	for (LLInventoryModel::item_array_t::const_iterator iter = items.begin();
-		 iter != items.end();
-		 ++iter)
-	{
- 		const LLViewerInventoryItem *item = (*iter);
-		if (item && item->getIsLinkType())
-		{
-			pruned_items.push_back((*iter));
-		}
-	}
-	items = pruned_items;
+    LLInventoryModel::item_array_t pruned_items;
+    for (LLInventoryModel::item_array_t::const_iterator iter = items.begin();
+         iter != items.end();
+         ++iter)
+    {
+        const LLViewerInventoryItem *item = (*iter);
+        if (item && item->getIsLinkType())
+        {
+            pruned_items.push_back((*iter));
+        }
+    }
+    items = pruned_items;
 }
 
 //a predicate for sorting inventory items by actual descriptions
 bool sort_by_actual_description(const LLInventoryItem* item1, const LLInventoryItem* item2)
 {
-	if (!item1 || !item2) 
-	{
-		LL_WARNS() << "either item1 or item2 is NULL" << LL_ENDL;
-		return true;
-	}
+    if (!item1 || !item2)
+    {
+        LL_WARNS() << "either item1 or item2 is NULL" << LL_ENDL;
+        return true;
+    }
 
-	return item1->getActualDescription() < item2->getActualDescription();
+    return item1->getActualDescription() < item2->getActualDescription();
 }
 
 void item_array_diff(LLInventoryModel::item_array_t& full_list,
-					 LLInventoryModel::item_array_t& keep_list,
-					 LLInventoryModel::item_array_t& kill_list)
-	
-{
-	for (LLInventoryModel::item_array_t::iterator it = full_list.begin();
-		 it != full_list.end();
-		 ++it)
-	{
-		LLViewerInventoryItem *item = *it;
-		if (std::find(keep_list.begin(), keep_list.end(), item) == keep_list.end())
-		{
-			kill_list.push_back(item);
-		}
-	}
+                     LLInventoryModel::item_array_t& keep_list,
+                     LLInventoryModel::item_array_t& kill_list)
+
+{
+    for (LLInventoryModel::item_array_t::iterator it = full_list.begin();
+         it != full_list.end();
+         ++it)
+    {
+        LLViewerInventoryItem *item = *it;
+        if (std::find(keep_list.begin(), keep_list.end(), item) == keep_list.end())
+        {
+            kill_list.push_back(item);
+        }
+    }
 }
 
 S32 LLAppearanceMgr::findExcessOrDuplicateItems(const LLUUID& cat_id,
-												 LLAssetType::EType type,
-												 S32 max_items_per_type,
-												 S32 max_items_total,
-												 LLInventoryObject::object_list_t& items_to_kill)
-{
-	S32 to_kill_count = 0;
-
-	LLInventoryModel::item_array_t items;
-	getDescendentsOfAssetType(cat_id, items, type);
-	LLInventoryModel::item_array_t curr_items = items;
-	removeDuplicateItems(items);
-	if (max_items_per_type > 0 || max_items_total > 0)
-	{
-		filterWearableItems(items, max_items_per_type, max_items_total);
-	}
-	LLInventoryModel::item_array_t kill_items;
-	item_array_diff(curr_items,items,kill_items);
-	for (LLInventoryModel::item_array_t::iterator it = kill_items.begin();
-		 it != kill_items.end();
-		 ++it)
-	{
-		items_to_kill.push_back(LLPointer<LLInventoryObject>(*it));
-		to_kill_count++;
-	}
-	return to_kill_count;
-}
-	
+                                                 LLAssetType::EType type,
+                                                 S32 max_items_per_type,
+                                                 S32 max_items_total,
+                                                 LLInventoryObject::object_list_t& items_to_kill)
+{
+    S32 to_kill_count = 0;
+
+    LLInventoryModel::item_array_t items;
+    getDescendentsOfAssetType(cat_id, items, type);
+    LLInventoryModel::item_array_t curr_items = items;
+    removeDuplicateItems(items);
+    if (max_items_per_type > 0 || max_items_total > 0)
+    {
+        filterWearableItems(items, max_items_per_type, max_items_total);
+    }
+    LLInventoryModel::item_array_t kill_items;
+    item_array_diff(curr_items,items,kill_items);
+    for (LLInventoryModel::item_array_t::iterator it = kill_items.begin();
+         it != kill_items.end();
+         ++it)
+    {
+        items_to_kill.push_back(LLPointer<LLInventoryObject>(*it));
+        to_kill_count++;
+    }
+    return to_kill_count;
+}
+
 
 void LLAppearanceMgr::findAllExcessOrDuplicateItems(const LLUUID& cat_id,
-													LLInventoryObject::object_list_t& items_to_kill)
+                                                    LLInventoryObject::object_list_t& items_to_kill)
 {
-	findExcessOrDuplicateItems(cat_id,LLAssetType::AT_BODYPART,
-							   1, 0, items_to_kill);
-	findExcessOrDuplicateItems(cat_id,LLAssetType::AT_CLOTHING,
-							   0, LLAgentWearables::MAX_CLOTHING_LAYERS, items_to_kill);
-	findExcessOrDuplicateItems(cat_id,LLAssetType::AT_OBJECT,
-							   0, 0, items_to_kill);
+    findExcessOrDuplicateItems(cat_id,LLAssetType::AT_BODYPART,
+                               1, 0, items_to_kill);
+    findExcessOrDuplicateItems(cat_id,LLAssetType::AT_CLOTHING,
+                               0, LLAgentWearables::MAX_CLOTHING_LAYERS, items_to_kill);
+    findExcessOrDuplicateItems(cat_id,LLAssetType::AT_OBJECT,
+                               0, 0, items_to_kill);
 }
 
 void LLAppearanceMgr::enforceCOFItemRestrictions(LLPointer<LLInventoryCallback> cb)
 {
-	LLInventoryObject::object_list_t items_to_kill;
-	findAllExcessOrDuplicateItems(getCOF(), items_to_kill);
-	if (items_to_kill.size()>0)
-	{
-		// Remove duplicate or excess wearables. Should normally be enforced at the UI level, but
-		// this should catch anything that gets through.
-		remove_inventory_items(items_to_kill, cb);
-	}
+    LLInventoryObject::object_list_t items_to_kill;
+    findAllExcessOrDuplicateItems(getCOF(), items_to_kill);
+    if (items_to_kill.size()>0)
+    {
+        // Remove duplicate or excess wearables. Should normally be enforced at the UI level, but
+        // this should catch anything that gets through.
+        remove_inventory_items(items_to_kill, cb);
+    }
 }
 
 bool sort_by_linked_uuid(const LLViewerInventoryItem* item1, const LLViewerInventoryItem* item2)
 {
-	if (!item1 || !item2)
-	{
-		LL_WARNS() << "item1, item2 cannot be null, something is very wrong" << LL_ENDL;
-		return true;
-	}
+    if (!item1 || !item2)
+    {
+        LL_WARNS() << "item1, item2 cannot be null, something is very wrong" << LL_ENDL;
+        return true;
+    }
 
-	return item1->getLinkedUUID() < item2->getLinkedUUID();
+    return item1->getLinkedUUID() < item2->getLinkedUUID();
 }
 
 void get_sorted_base_and_cof_items(LLInventoryModel::item_array_t& cof_item_array, LLInventoryModel::item_array_t& outfit_item_array)
 {
-	LLUUID base_outfit_id = LLAppearanceMgr::instance().getBaseOutfitUUID();
+    LLUUID base_outfit_id = LLAppearanceMgr::instance().getBaseOutfitUUID();
 
-	if (base_outfit_id.notNull())
-	{
-		LLIsValidItemLink collector;
-		LLInventoryModel::cat_array_t sub_cat_array;
+    if (base_outfit_id.notNull())
+    {
+        LLIsValidItemLink collector;
+        LLInventoryModel::cat_array_t sub_cat_array;
 
-		gInventory.collectDescendents(base_outfit_id,
-			sub_cat_array,
-			outfit_item_array,
-			LLInventoryModel::EXCLUDE_TRASH);
+        gInventory.collectDescendents(base_outfit_id,
+            sub_cat_array,
+            outfit_item_array,
+            LLInventoryModel::EXCLUDE_TRASH);
 
-		LLInventoryModel::cat_array_t cof_cats;
+        LLInventoryModel::cat_array_t cof_cats;
 
-		gInventory.collectDescendentsIf(LLAppearanceMgr::instance().getCOF(), cof_cats, cof_item_array,
-			LLInventoryModel::EXCLUDE_TRASH, collector);
+        gInventory.collectDescendentsIf(LLAppearanceMgr::instance().getCOF(), cof_cats, cof_item_array,
+            LLInventoryModel::EXCLUDE_TRASH, collector);
 
-		for (U32 i = 0; i < outfit_item_array.size(); ++i)
-		{
-			LLViewerInventoryItem* linked_item = outfit_item_array.at(i)->getLinkedItem();
-			if (linked_item != NULL && linked_item->getActualType() == LLAssetType::AT_TEXTURE)
-			{
-				outfit_item_array.erase(outfit_item_array.begin() + i);
-				break;
-			}
-		}
+        for (U32 i = 0; i < outfit_item_array.size(); ++i)
+        {
+            LLViewerInventoryItem* linked_item = outfit_item_array.at(i)->getLinkedItem();
+            if (linked_item != NULL && linked_item->getActualType() == LLAssetType::AT_TEXTURE)
+            {
+                outfit_item_array.erase(outfit_item_array.begin() + i);
+                break;
+            }
+        }
 
-		std::sort(cof_item_array.begin(), cof_item_array.end(), sort_by_linked_uuid);
-		std::sort(outfit_item_array.begin(), outfit_item_array.end(), sort_by_linked_uuid);
-	}
+        std::sort(cof_item_array.begin(), cof_item_array.end(), sort_by_linked_uuid);
+        std::sort(outfit_item_array.begin(), outfit_item_array.end(), sort_by_linked_uuid);
+    }
 }
 
 
 void LLAppearanceMgr::updateAppearanceFromCOF(bool enforce_item_restrictions,
-											  bool enforce_ordering,
-											  nullary_func_t post_update_func)
+                                              bool enforce_ordering,
+                                              nullary_func_t post_update_func)
 {
-	if (mIsInUpdateAppearanceFromCOF)
-	{
-		LL_WARNS() << "Called updateAppearanceFromCOF inside updateAppearanceFromCOF, skipping" << LL_ENDL;
-		return;
-	}
+    if (mIsInUpdateAppearanceFromCOF)
+    {
+        LL_WARNS() << "Called updateAppearanceFromCOF inside updateAppearanceFromCOF, skipping" << LL_ENDL;
+        return;
+    }
 
-	LL_DEBUGS("Avatar") << self_av_string() << "starting" << LL_ENDL;
+    LL_DEBUGS("Avatar") << self_av_string() << "starting" << LL_ENDL;
 
     if (gInventory.hasPosiblyBrockenLinks())
     {
@@ -2688,292 +2688,292 @@ void LLAppearanceMgr::updateAppearanceFromCOF(bool enforce_item_restrictions,
         }
     }
 
-	if (enforce_item_restrictions)
-	{
-		// The point here is just to call
-		// updateAppearanceFromCOF() again after excess items
-		// have been removed. That time we will set
-		// enforce_item_restrictions to false so we don't get
-		// caught in a perpetual loop.
-		LLPointer<LLInventoryCallback> cb(
-			new LLUpdateAppearanceOnDestroy(false, enforce_ordering, post_update_func));
-		enforceCOFItemRestrictions(cb);
-		return;
-	}
-
-	if (enforce_ordering)
-	{
-		//checking integrity of the COF in terms of ordering of wearables, 
-		//checking and updating links' descriptions of wearables in the COF (before analyzed for "dirty" state)
+    if (enforce_item_restrictions)
+    {
+        // The point here is just to call
+        // updateAppearanceFromCOF() again after excess items
+        // have been removed. That time we will set
+        // enforce_item_restrictions to false so we don't get
+        // caught in a perpetual loop.
+        LLPointer<LLInventoryCallback> cb(
+            new LLUpdateAppearanceOnDestroy(false, enforce_ordering, post_update_func));
+        enforceCOFItemRestrictions(cb);
+        return;
+    }
+
+    if (enforce_ordering)
+    {
+        //checking integrity of the COF in terms of ordering of wearables,
+        //checking and updating links' descriptions of wearables in the COF (before analyzed for "dirty" state)
 // [SL:KB] - Patch: Appearance-AISFilter | Checked: 2015-03-01 (Catznip-3.7)
-		// Ordering information is pre-applied locally so no reason to reason to wait on the inventory backend
-		updateClothingOrderingInfo(LLUUID::null);
+        // Ordering information is pre-applied locally so no reason to reason to wait on the inventory backend
+        updateClothingOrderingInfo(LLUUID::null);
 // [/SL:KB]
 
-//		// As with enforce_item_restrictions handling above, we want
-//		// to wait for the update callbacks, then (finally!) call
-//		// updateAppearanceFromCOF() with no additional COF munging needed.
-//		LLPointer<LLInventoryCallback> cb(
-//			new LLUpdateAppearanceOnDestroy(false, false, post_update_func));
-//		updateClothingOrderingInfo(LLUUID::null, cb);
-//		return;
-	}
-
-	if (!validateClothingOrderingInfo())
-	{
-			
-		LLInventoryModel::item_array_t outfit_item_array;
-		LLInventoryModel::item_array_t cof_item_array;
-		get_sorted_base_and_cof_items(cof_item_array, outfit_item_array);
-
-		if (outfit_item_array.size() == cof_item_array.size())
-		{
-			for (U32 i = 0; i < cof_item_array.size(); ++i)
-			{
-				LLViewerInventoryItem *cof_it = cof_item_array.at(i);
-				LLViewerInventoryItem *base_it = outfit_item_array.at(i);
-
-				if (cof_it->getActualDescription() != base_it->getActualDescription())
-				{
-					if (cof_it->getLinkedUUID() == base_it->getLinkedUUID())
-					{
-						cof_it->setDescription(base_it->getActualDescription());
-						gInventory.updateItem(cof_it);
-					}
-				}
-			}
-			LLAppearanceMgr::getInstance()->updateIsDirty();
-		}
-
-	}
-
-	BoolSetter setIsInUpdateAppearanceFromCOF(mIsInUpdateAppearanceFromCOF);
-	selfStartPhase("update_appearance_from_cof");
-
-	// update dirty flag to see if the state of the COF matches
-	// the saved outfit stored as a folder link
-	updateIsDirty();
-
-	// Send server request for appearance update
-	if (gAgent.getRegion() && gAgent.getRegion()->getCentralBakeVersion())
-	{
-		requestServerAppearanceUpdate();
-	}
-
-	LLUUID current_outfit_id = getCOF();
-
-	// Find all the wearables that are in the COF's subtree.
-	LL_DEBUGS() << "LLAppearanceMgr::updateFromCOF()" << LL_ENDL;
-	LLInventoryModel::item_array_t wear_items;
-	LLInventoryModel::item_array_t obj_items;
-	LLInventoryModel::item_array_t gest_items;
-	getUserDescendents(current_outfit_id, wear_items, obj_items, gest_items);
-	// Get rid of non-links in case somehow the COF was corrupted.
-	remove_non_link_items(wear_items);
-	remove_non_link_items(obj_items);
-	remove_non_link_items(gest_items);
+//      // As with enforce_item_restrictions handling above, we want
+//      // to wait for the update callbacks, then (finally!) call
+//      // updateAppearanceFromCOF() with no additional COF munging needed.
+//      LLPointer<LLInventoryCallback> cb(
+//          new LLUpdateAppearanceOnDestroy(false, false, post_update_func));
+//      updateClothingOrderingInfo(LLUUID::null, cb);
+//      return;
+    }
+
+    if (!validateClothingOrderingInfo())
+    {
+
+        LLInventoryModel::item_array_t outfit_item_array;
+        LLInventoryModel::item_array_t cof_item_array;
+        get_sorted_base_and_cof_items(cof_item_array, outfit_item_array);
+
+        if (outfit_item_array.size() == cof_item_array.size())
+        {
+            for (U32 i = 0; i < cof_item_array.size(); ++i)
+            {
+                LLViewerInventoryItem *cof_it = cof_item_array.at(i);
+                LLViewerInventoryItem *base_it = outfit_item_array.at(i);
+
+                if (cof_it->getActualDescription() != base_it->getActualDescription())
+                {
+                    if (cof_it->getLinkedUUID() == base_it->getLinkedUUID())
+                    {
+                        cof_it->setDescription(base_it->getActualDescription());
+                        gInventory.updateItem(cof_it);
+                    }
+                }
+            }
+            LLAppearanceMgr::getInstance()->updateIsDirty();
+        }
+
+    }
+
+    BoolSetter setIsInUpdateAppearanceFromCOF(mIsInUpdateAppearanceFromCOF);
+    selfStartPhase("update_appearance_from_cof");
+
+    // update dirty flag to see if the state of the COF matches
+    // the saved outfit stored as a folder link
+    updateIsDirty();
+
+    // Send server request for appearance update
+    if (gAgent.getRegion() && gAgent.getRegion()->getCentralBakeVersion())
+    {
+        requestServerAppearanceUpdate();
+    }
+
+    LLUUID current_outfit_id = getCOF();
+
+    // Find all the wearables that are in the COF's subtree.
+    LL_DEBUGS() << "LLAppearanceMgr::updateFromCOF()" << LL_ENDL;
+    LLInventoryModel::item_array_t wear_items;
+    LLInventoryModel::item_array_t obj_items;
+    LLInventoryModel::item_array_t gest_items;
+    getUserDescendents(current_outfit_id, wear_items, obj_items, gest_items);
+    // Get rid of non-links in case somehow the COF was corrupted.
+    remove_non_link_items(wear_items);
+    remove_non_link_items(obj_items);
+    remove_non_link_items(gest_items);
 // [SL:KB] - Patch: Apperance-Misc | Checked: 2010-11-24 (Catznip-2.4)
-	// Since we're following folder links we might have picked up new duplicates, or exceeded MAX_CLOTHING_LAYERS
-	removeDuplicateItems(wear_items);
-	removeDuplicateItems(obj_items);
-	removeDuplicateItems(gest_items);
-	filterWearableItems(wear_items, LLAgentWearables::MAX_CLOTHING_LAYERS, LLAgentWearables::MAX_CLOTHING_LAYERS);
+    // Since we're following folder links we might have picked up new duplicates, or exceeded MAX_CLOTHING_LAYERS
+    removeDuplicateItems(wear_items);
+    removeDuplicateItems(obj_items);
+    removeDuplicateItems(gest_items);
+    filterWearableItems(wear_items, LLAgentWearables::MAX_CLOTHING_LAYERS, LLAgentWearables::MAX_CLOTHING_LAYERS);
 // [/SL:KB]
 
-	dumpItemArray(wear_items,"asset_dump: wear_item");
-	dumpItemArray(obj_items,"asset_dump: obj_item");
-
-	LLViewerInventoryCategory *cof = gInventory.getCategory(current_outfit_id);
-	if (!gInventory.isCategoryComplete(current_outfit_id))
-	{
-		LL_WARNS() << "COF info is not complete. Version " << cof->getVersion()
-				<< " descendent_count " << cof->getDescendentCount()
-				<< " viewer desc count " << cof->getViewerDescendentCount() << LL_ENDL;
-	}
-	if(!wear_items.size())
-	{
-		LLNotificationsUtil::add("CouldNotPutOnOutfit");
-		return;
-	}
-
-	//preparing the list of wearables in the correct order for LLAgentWearables
-	sortItemsByActualDescription(wear_items);
-
-
-	LL_DEBUGS("Avatar") << "HP block starts" << LL_ENDL;
-	LLTimer hp_block_timer;
-	LLWearableHoldingPattern* holder = new LLWearableHoldingPattern;
-
-	holder->setObjItems(obj_items);
-	holder->setGestItems(gest_items);
-		
-	// Note: can't do normal iteration, because if all the
-	// wearables can be resolved immediately, then the
-	// callback will be called (and this object deleted)
-	// before the final getNextData().
-
-	for(S32 i = 0; i  < wear_items.size(); ++i)
-	{
-		LLViewerInventoryItem *item = wear_items.at(i);
-		LLViewerInventoryItem *linked_item = item ? item->getLinkedItem() : NULL;
-
-		// Fault injection: use debug setting to test asset 
-		// fetch failures (should be replaced by new defaults in
-		// lost&found).
-		U32 skip_type = gSavedSettings.getU32("ForceAssetFail");
+    dumpItemArray(wear_items,"asset_dump: wear_item");
+    dumpItemArray(obj_items,"asset_dump: obj_item");
+
+    LLViewerInventoryCategory *cof = gInventory.getCategory(current_outfit_id);
+    if (!gInventory.isCategoryComplete(current_outfit_id))
+    {
+        LL_WARNS() << "COF info is not complete. Version " << cof->getVersion()
+                << " descendent_count " << cof->getDescendentCount()
+                << " viewer desc count " << cof->getViewerDescendentCount() << LL_ENDL;
+    }
+    if(!wear_items.size())
+    {
+        LLNotificationsUtil::add("CouldNotPutOnOutfit");
+        return;
+    }
+
+    //preparing the list of wearables in the correct order for LLAgentWearables
+    sortItemsByActualDescription(wear_items);
+
+
+    LL_DEBUGS("Avatar") << "HP block starts" << LL_ENDL;
+    LLTimer hp_block_timer;
+    LLWearableHoldingPattern* holder = new LLWearableHoldingPattern;
+
+    holder->setObjItems(obj_items);
+    holder->setGestItems(gest_items);
+
+    // Note: can't do normal iteration, because if all the
+    // wearables can be resolved immediately, then the
+    // callback will be called (and this object deleted)
+    // before the final getNextData().
+
+    for(S32 i = 0; i  < wear_items.size(); ++i)
+    {
+        LLViewerInventoryItem *item = wear_items.at(i);
+        LLViewerInventoryItem *linked_item = item ? item->getLinkedItem() : NULL;
+
+        // Fault injection: use debug setting to test asset
+        // fetch failures (should be replaced by new defaults in
+        // lost&found).
+        U32 skip_type = gSavedSettings.getU32("ForceAssetFail");
 // [RLVa:KB] - Checked: 2010-12-11 (RLVa-1.2.2)
-		U32 missing_type = gSavedSettings.getU32("ForceMissingType");
+        U32 missing_type = gSavedSettings.getU32("ForceMissingType");
 // [/RLVa:KB]
 
-		if (item && item->getIsLinkType() && linked_item)
-		{
-			LLFoundData found(linked_item->getUUID(),
-							  linked_item->getAssetUUID(),
-							  linked_item->getName(),
-							  linked_item->getType(),
-							  linked_item->isWearableType() ? linked_item->getWearableType() : LLWearableType::WT_INVALID
-				);
+        if (item && item->getIsLinkType() && linked_item)
+        {
+            LLFoundData found(linked_item->getUUID(),
+                              linked_item->getAssetUUID(),
+                              linked_item->getName(),
+                              linked_item->getType(),
+                              linked_item->isWearableType() ? linked_item->getWearableType() : LLWearableType::WT_INVALID
+                );
 
 // [RLVa:KB] - Checked: 2010-12-15 (RLVa-1.2.2)
 #ifdef LL_RELEASE_FOR_DOWNLOAD
-			// Don't allow forcing an invalid wearable if the initial wearables aren't set yet, or if any wearable type is currently locked
-			if ( (!rlv_handler_t::isEnabled()) || 
-				 ((gAgentWearables.areInitalWearablesLoaded()) && (!gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_REMOVE))) )
+            // Don't allow forcing an invalid wearable if the initial wearables aren't set yet, or if any wearable type is currently locked
+            if ( (!rlv_handler_t::isEnabled()) ||
+                 ((gAgentWearables.areInitalWearablesLoaded()) && (!gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_REMOVE))) )
 #endif // LL_RELEASE_FOR_DOWNLOAD
-			{
-				if (missing_type != LLWearableType::WT_INVALID && missing_type == found.mWearableType)
-				{
-					continue;
-				}
+            {
+                if (missing_type != LLWearableType::WT_INVALID && missing_type == found.mWearableType)
+                {
+                    continue;
+                }
 // [/RLVa:KB]
-				if (skip_type != LLWearableType::WT_INVALID && skip_type == found.mWearableType)
-				{
-					found.mAssetID.generate(); // Replace with new UUID, guaranteed not to exist in DB
-				}
+                if (skip_type != LLWearableType::WT_INVALID && skip_type == found.mWearableType)
+                {
+                    found.mAssetID.generate(); // Replace with new UUID, guaranteed not to exist in DB
+                }
 // [RLVa:KB] - Checked: 2010-12-15 (RLVa-1.2.2)
-			}
+            }
 // [/RLVa:KB]
-			//pushing back, not front, to preserve order of wearables for LLAgentWearables
-			holder->getFoundList().push_back(found);
-		}
-		else
-		{
-			if (!item)
-			{
-				LL_WARNS() << "Attempt to wear a null item " << LL_ENDL;
-			}
-			else if (!linked_item)
-			{
-				LL_WARNS() << "Attempt to wear a broken link [ name:" << item->getName() << " ] " << LL_ENDL;
-			}
-		}
-	}
-
-	selfStartPhase("get_wearables_2");
-
-	for (LLWearableHoldingPattern::found_list_t::iterator it = holder->getFoundList().begin();
-		 it != holder->getFoundList().end(); ++it)
-	{
-		LLFoundData& found = *it;
-
-		LL_DEBUGS() << self_av_string() << "waiting for onWearableAssetFetch callback, asset " << found.mAssetID.asString() << LL_ENDL;
-
-		// Fetch the wearables about to be worn.
-		LLWearableList::instance().getAsset(found.mAssetID,
-											found.mName,
-											gAgentAvatarp,
-											found.mAssetType,
-											onWearableAssetFetch,
-											(void*)holder);
-
-	}
-
-	holder->resetTime(gSavedSettings.getF32("MaxWearableWaitTime"));
-	if (!holder->pollFetchCompletion())
-	{
-		doOnIdleRepeating(boost::bind(&LLWearableHoldingPattern::pollFetchCompletion,holder));
-	}
-	post_update_func();
-
-	LL_DEBUGS("Avatar") << "HP block ends, elapsed " << hp_block_timer.getElapsedTimeF32() << LL_ENDL;
+            //pushing back, not front, to preserve order of wearables for LLAgentWearables
+            holder->getFoundList().push_back(found);
+        }
+        else
+        {
+            if (!item)
+            {
+                LL_WARNS() << "Attempt to wear a null item " << LL_ENDL;
+            }
+            else if (!linked_item)
+            {
+                LL_WARNS() << "Attempt to wear a broken link [ name:" << item->getName() << " ] " << LL_ENDL;
+            }
+        }
+    }
+
+    selfStartPhase("get_wearables_2");
+
+    for (LLWearableHoldingPattern::found_list_t::iterator it = holder->getFoundList().begin();
+         it != holder->getFoundList().end(); ++it)
+    {
+        LLFoundData& found = *it;
+
+        LL_DEBUGS() << self_av_string() << "waiting for onWearableAssetFetch callback, asset " << found.mAssetID.asString() << LL_ENDL;
+
+        // Fetch the wearables about to be worn.
+        LLWearableList::instance().getAsset(found.mAssetID,
+                                            found.mName,
+                                            gAgentAvatarp,
+                                            found.mAssetType,
+                                            onWearableAssetFetch,
+                                            (void*)holder);
+
+    }
+
+    holder->resetTime(gSavedSettings.getF32("MaxWearableWaitTime"));
+    if (!holder->pollFetchCompletion())
+    {
+        doOnIdleRepeating(boost::bind(&LLWearableHoldingPattern::pollFetchCompletion,holder));
+    }
+    post_update_func();
+
+    LL_DEBUGS("Avatar") << "HP block ends, elapsed " << hp_block_timer.getElapsedTimeF32() << LL_ENDL;
 }
 
 void LLAppearanceMgr::getDescendentsOfAssetType(const LLUUID& category,
-													LLInventoryModel::item_array_t& items,
-													LLAssetType::EType type)
-{
-	LLInventoryModel::cat_array_t cats;
-	LLIsType is_of_type(type);
-	gInventory.collectDescendentsIf(category,
-									cats,
-									items,
-									LLInventoryModel::EXCLUDE_TRASH,
-									is_of_type);
-}
-
-void LLAppearanceMgr::getUserDescendents(const LLUUID& category, 
-											 LLInventoryModel::item_array_t& wear_items,
-											 LLInventoryModel::item_array_t& obj_items,
-											 LLInventoryModel::item_array_t& gest_items)
-{
-	LLInventoryModel::cat_array_t wear_cats;
-	LLFindWearables is_wearable;
-	gInventory.collectDescendentsIf(category,
-									wear_cats,
-									wear_items,
-									LLInventoryModel::EXCLUDE_TRASH,
-									is_wearable);
-
-	LLInventoryModel::cat_array_t obj_cats;
-	LLIsType is_object( LLAssetType::AT_OBJECT );
-	gInventory.collectDescendentsIf(category,
-									obj_cats,
-									obj_items,
-									LLInventoryModel::EXCLUDE_TRASH,
-									is_object);
-
-	// Find all gestures in this folder
-	LLInventoryModel::cat_array_t gest_cats;
-	LLIsType is_gesture( LLAssetType::AT_GESTURE );
-	gInventory.collectDescendentsIf(category,
-									gest_cats,
-									gest_items,
-									LLInventoryModel::EXCLUDE_TRASH,
-									is_gesture);
+                                                    LLInventoryModel::item_array_t& items,
+                                                    LLAssetType::EType type)
+{
+    LLInventoryModel::cat_array_t cats;
+    LLIsType is_of_type(type);
+    gInventory.collectDescendentsIf(category,
+                                    cats,
+                                    items,
+                                    LLInventoryModel::EXCLUDE_TRASH,
+                                    is_of_type);
+}
+
+void LLAppearanceMgr::getUserDescendents(const LLUUID& category,
+                                             LLInventoryModel::item_array_t& wear_items,
+                                             LLInventoryModel::item_array_t& obj_items,
+                                             LLInventoryModel::item_array_t& gest_items)
+{
+    LLInventoryModel::cat_array_t wear_cats;
+    LLFindWearables is_wearable;
+    gInventory.collectDescendentsIf(category,
+                                    wear_cats,
+                                    wear_items,
+                                    LLInventoryModel::EXCLUDE_TRASH,
+                                    is_wearable);
+
+    LLInventoryModel::cat_array_t obj_cats;
+    LLIsType is_object( LLAssetType::AT_OBJECT );
+    gInventory.collectDescendentsIf(category,
+                                    obj_cats,
+                                    obj_items,
+                                    LLInventoryModel::EXCLUDE_TRASH,
+                                    is_object);
+
+    // Find all gestures in this folder
+    LLInventoryModel::cat_array_t gest_cats;
+    LLIsType is_gesture( LLAssetType::AT_GESTURE );
+    gInventory.collectDescendentsIf(category,
+                                    gest_cats,
+                                    gest_items,
+                                    LLInventoryModel::EXCLUDE_TRASH,
+                                    is_gesture);
 }
 
 void LLAppearanceMgr::wearInventoryCategory(LLInventoryCategory* category, bool copy, bool append)
 {
-	if(!category) return;
+    if(!category) return;
 
-	selfClearPhases();
-	selfStartPhase("wear_inventory_category");
+    selfClearPhases();
+    selfStartPhase("wear_inventory_category");
 
-	gAgentWearables.notifyLoadingStarted();
+    gAgentWearables.notifyLoadingStarted();
 
-	LL_INFOS("Avatar") << self_av_string() << "wearInventoryCategory( " << category->getName()
-			 << " )" << LL_ENDL;
+    LL_INFOS("Avatar") << self_av_string() << "wearInventoryCategory( " << category->getName()
+             << " )" << LL_ENDL;
 
-	// If we are copying from library, attempt to use AIS to copy the category.
+    // If we are copying from library, attempt to use AIS to copy the category.
     if (copy && AISAPI::isAvailable())
-	{
-		LLUUID parent_id;
-		parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_CLOTHING);
-		if (parent_id.isNull())
-		{
-			parent_id = gInventory.getRootFolderID();
-		}
-
-		LLPointer<LLInventoryCallback> copy_cb = new LLWearCategoryAfterCopy(append);
-		LLPointer<LLInventoryCallback> track_cb = new LLTrackPhaseWrapper(
-													std::string("wear_inventory_category_callback"), copy_cb);
+    {
+        LLUUID parent_id;
+        parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_CLOTHING);
+        if (parent_id.isNull())
+        {
+            parent_id = gInventory.getRootFolderID();
+        }
+
+        LLPointer<LLInventoryCallback> copy_cb = new LLWearCategoryAfterCopy(append);
+        LLPointer<LLInventoryCallback> track_cb = new LLTrackPhaseWrapper(
+                                                    std::string("wear_inventory_category_callback"), copy_cb);
 
         AISAPI::completion_t cr = boost::bind(&doAppearanceCb, track_cb, _1);
         AISAPI::CopyLibraryCategory(category->getUUID(), parent_id, false, cr);
-	}
+    }
     else
-	{
-		selfStartPhase("wear_inventory_category_fetch");
+    {
+        selfStartPhase("wear_inventory_category_fetch");
         if (AISAPI::isAvailable() && category->getPreferredType() == LLFolderType::FT_OUTFIT)
         {
             // for reliability just fetch it whole, linked items included
@@ -2991,66 +2991,66 @@ void LLAppearanceMgr::wearInventoryCategory(LLInventoryCategory* category, bool
                                                                     &LLAppearanceMgr::instance(),
                                                                     category->getUUID(), copy, append));
         }
-	}
+    }
 }
 
 S32 LLAppearanceMgr::getActiveCopyOperations() const
 {
-	return LLCallAfterInventoryCopyMgr::getInstanceCount(); 
+    return LLCallAfterInventoryCopyMgr::getInstanceCount();
 }
 
 void LLAppearanceMgr::wearCategoryFinal(const LLUUID& cat_id, bool copy_items, bool append)
 {
-	LL_INFOS("Avatar") << self_av_string() << "starting" << LL_ENDL;
-
-	selfStopPhase("wear_inventory_category_fetch");
-	
-	// We now have an outfit ready to be copied to agent inventory. Do
-	// it, and wear that outfit normally.
-	LLInventoryCategory* cat = gInventory.getCategory(cat_id);
-	if(copy_items)
-	{
-		LLInventoryModel::cat_array_t* cats;
-		LLInventoryModel::item_array_t* items;
-		gInventory.getDirectDescendentsOf(cat_id, cats, items);
-		std::string name;
-		if(!cat)
-		{
-			// should never happen.
-			name = "New Outfit";
-		}
-		else
-		{
-			name = cat->getName();
-		}
-		LLViewerInventoryItem* item = NULL;
-		LLInventoryModel::item_array_t::const_iterator it = items->begin();
-		LLInventoryModel::item_array_t::const_iterator end = items->end();
-		LLUUID pid;
-		for(; it < end; ++it)
-		{
-			item = *it;
-			if(item)
-			{
-				if(LLInventoryType::IT_GESTURE == item->getInventoryType())
-				{
-					pid = gInventory.findCategoryUUIDForType(LLFolderType::FT_GESTURE);
-				}
-				else
-				{
-					pid = gInventory.findCategoryUUIDForType(LLFolderType::FT_CLOTHING);
-				}
-				break;
-			}
-		}
-		if(pid.isNull())
-		{
-			pid = gInventory.getRootFolderID();
-		}
-
-		gInventory.createNewCategory(
-			pid,
-			LLFolderType::FT_NONE,
+    LL_INFOS("Avatar") << self_av_string() << "starting" << LL_ENDL;
+
+    selfStopPhase("wear_inventory_category_fetch");
+
+    // We now have an outfit ready to be copied to agent inventory. Do
+    // it, and wear that outfit normally.
+    LLInventoryCategory* cat = gInventory.getCategory(cat_id);
+    if(copy_items)
+    {
+        LLInventoryModel::cat_array_t* cats;
+        LLInventoryModel::item_array_t* items;
+        gInventory.getDirectDescendentsOf(cat_id, cats, items);
+        std::string name;
+        if(!cat)
+        {
+            // should never happen.
+            name = "New Outfit";
+        }
+        else
+        {
+            name = cat->getName();
+        }
+        LLViewerInventoryItem* item = NULL;
+        LLInventoryModel::item_array_t::const_iterator it = items->begin();
+        LLInventoryModel::item_array_t::const_iterator end = items->end();
+        LLUUID pid;
+        for(; it < end; ++it)
+        {
+            item = *it;
+            if(item)
+            {
+                if(LLInventoryType::IT_GESTURE == item->getInventoryType())
+                {
+                    pid = gInventory.findCategoryUUIDForType(LLFolderType::FT_GESTURE);
+                }
+                else
+                {
+                    pid = gInventory.findCategoryUUIDForType(LLFolderType::FT_CLOTHING);
+                }
+                break;
+            }
+        }
+        if(pid.isNull())
+        {
+            pid = gInventory.getRootFolderID();
+        }
+
+        gInventory.createNewCategory(
+            pid,
+            LLFolderType::FT_NONE,
             name,
             [cat_id, append](const LLUUID& new_cat_id)
         {
@@ -3070,204 +3070,204 @@ void LLAppearanceMgr::wearCategoryFinal(const LLUUID& cat_id, bool copy_items, b
         },
             cat->getThumbnailUUID()
         );
-	}
-	else
-	{
-		// Wear the inventory category.
-		LLAppearanceMgr::instance().wearInventoryCategoryOnAvatar(cat, append);
-	}
+    }
+    else
+    {
+        // Wear the inventory category.
+        LLAppearanceMgr::instance().wearInventoryCategoryOnAvatar(cat, append);
+    }
 }
 
 // *NOTE: hack to get from avatar inventory to avatar
 void LLAppearanceMgr::wearInventoryCategoryOnAvatar( LLInventoryCategory* category, bool append )
 {
-	// Avoid unintentionally overwriting old wearables.  We have to do
-	// this up front to avoid having to deal with the case of multiple
-	// wearables being dirty.
-	if (!category) return;
+    // Avoid unintentionally overwriting old wearables.  We have to do
+    // this up front to avoid having to deal with the case of multiple
+    // wearables being dirty.
+    if (!category) return;
+
+    if ( !LLInventoryCallbackManager::is_instantiated() )
+    {
+        // shutting down, ignore.
+        return;
+    }
 
-	if ( !LLInventoryCallbackManager::is_instantiated() )
-	{
-		// shutting down, ignore.
-		return;
-	}
+    LL_INFOS("Avatar") << self_av_string() << "wearInventoryCategoryOnAvatar '" << category->getName()
+             << "'" << LL_ENDL;
 
-	LL_INFOS("Avatar") << self_av_string() << "wearInventoryCategoryOnAvatar '" << category->getName()
-			 << "'" << LL_ENDL;
-			 	
-	if (gAgentCamera.cameraCustomizeAvatar())
-	{
-		// switching to outfit editor should automagically save any currently edited wearable
-		LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "edit_outfit"));
-	}
+    if (gAgentCamera.cameraCustomizeAvatar())
+    {
+        // switching to outfit editor should automagically save any currently edited wearable
+        LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "edit_outfit"));
+    }
 
-	LLAppearanceMgr::changeOutfit(TRUE, category->getUUID(), append);
+    LLAppearanceMgr::changeOutfit(TRUE, category->getUUID(), append);
 }
 
 // FIXME do we really want to search entire inventory for matching name?
 void LLAppearanceMgr::wearOutfitByName(const std::string& name)
 {
-	LL_INFOS("Avatar") << self_av_string() << "Wearing category " << name << LL_ENDL;
-
-	LLInventoryModel::cat_array_t cat_array;
-	LLInventoryModel::item_array_t item_array;
-	LLNameCategoryCollector has_name(name);
-	gInventory.collectDescendentsIf(gInventory.getRootFolderID(),
-									cat_array,
-									item_array,
-									LLInventoryModel::EXCLUDE_TRASH,
-									has_name);
-	bool copy_items = false;
-	LLInventoryCategory* cat = NULL;
-	if (cat_array.size() > 0)
-	{
-		// Just wear the first one that matches
-		cat = cat_array.at(0);
-	}
-	else
-	{
-		gInventory.collectDescendentsIf(LLUUID::null,
-										cat_array,
-										item_array,
-										LLInventoryModel::EXCLUDE_TRASH,
-										has_name);
-		if(cat_array.size() > 0)
-		{
-			cat = cat_array.at(0);
-			copy_items = true;
-		}
-	}
-
-	if(cat)
-	{
-		LLAppearanceMgr::wearInventoryCategory(cat, copy_items, false);
-	}
-	else
-	{
-		LL_WARNS() << "Couldn't find outfit " <<name<< " in wearOutfitByName()"
-				<< LL_ENDL;
-	}
+    LL_INFOS("Avatar") << self_av_string() << "Wearing category " << name << LL_ENDL;
+
+    LLInventoryModel::cat_array_t cat_array;
+    LLInventoryModel::item_array_t item_array;
+    LLNameCategoryCollector has_name(name);
+    gInventory.collectDescendentsIf(gInventory.getRootFolderID(),
+                                    cat_array,
+                                    item_array,
+                                    LLInventoryModel::EXCLUDE_TRASH,
+                                    has_name);
+    bool copy_items = false;
+    LLInventoryCategory* cat = NULL;
+    if (cat_array.size() > 0)
+    {
+        // Just wear the first one that matches
+        cat = cat_array.at(0);
+    }
+    else
+    {
+        gInventory.collectDescendentsIf(LLUUID::null,
+                                        cat_array,
+                                        item_array,
+                                        LLInventoryModel::EXCLUDE_TRASH,
+                                        has_name);
+        if(cat_array.size() > 0)
+        {
+            cat = cat_array.at(0);
+            copy_items = true;
+        }
+    }
+
+    if(cat)
+    {
+        LLAppearanceMgr::wearInventoryCategory(cat, copy_items, false);
+    }
+    else
+    {
+        LL_WARNS() << "Couldn't find outfit " <<name<< " in wearOutfitByName()"
+                << LL_ENDL;
+    }
 }
 
 bool areMatchingWearables(const LLViewerInventoryItem *a, const LLViewerInventoryItem *b)
 {
-	return (a->isWearableType() && b->isWearableType() &&
-			(a->getWearableType() == b->getWearableType()));
+    return (a->isWearableType() && b->isWearableType() &&
+            (a->getWearableType() == b->getWearableType()));
 }
 
 class LLDeferredCOFLinkObserver: public LLInventoryObserver
 {
 public:
-	LLDeferredCOFLinkObserver(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb, const std::string& description):
-		mItemID(item_id),
-		mCallback(cb),
-		mDescription(description)
-	{
-	}
-
-	~LLDeferredCOFLinkObserver()
-	{
-	}
-	
-	/* virtual */ void changed(U32 mask)
-	{
-		const LLInventoryItem *item = gInventory.getItem(mItemID);
-		if (item)
-		{
-			gInventory.removeObserver(this);
-			LLAppearanceMgr::instance().addCOFItemLink(item, mCallback, mDescription);
-			delete this;
-		}
-	}
+    LLDeferredCOFLinkObserver(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb, const std::string& description):
+        mItemID(item_id),
+        mCallback(cb),
+        mDescription(description)
+    {
+    }
+
+    ~LLDeferredCOFLinkObserver()
+    {
+    }
+
+    /* virtual */ void changed(U32 mask)
+    {
+        const LLInventoryItem *item = gInventory.getItem(mItemID);
+        if (item)
+        {
+            gInventory.removeObserver(this);
+            LLAppearanceMgr::instance().addCOFItemLink(item, mCallback, mDescription);
+            delete this;
+        }
+    }
 
 private:
-	const LLUUID mItemID;
-	std::string mDescription;
-	LLPointer<LLInventoryCallback> mCallback;
+    const LLUUID mItemID;
+    std::string mDescription;
+    LLPointer<LLInventoryCallback> mCallback;
 };
 
 
 // BAP - note that this runs asynchronously if the item is not already loaded from inventory.
 // Dangerous if caller assumes link will exist after calling the function.
 void LLAppearanceMgr::addCOFItemLink(const LLUUID &item_id,
-									 LLPointer<LLInventoryCallback> cb,
-									 const std::string description)
+                                     LLPointer<LLInventoryCallback> cb,
+                                     const std::string description)
 {
-	const LLInventoryItem *item = gInventory.getItem(item_id);
-	if (!item)
-	{
-		LLDeferredCOFLinkObserver *observer = new LLDeferredCOFLinkObserver(item_id, cb, description);
-		gInventory.addObserver(observer);
-	}
-	else
-	{
-		addCOFItemLink(item, cb, description);
-	}
+    const LLInventoryItem *item = gInventory.getItem(item_id);
+    if (!item)
+    {
+        LLDeferredCOFLinkObserver *observer = new LLDeferredCOFLinkObserver(item_id, cb, description);
+        gInventory.addObserver(observer);
+    }
+    else
+    {
+        addCOFItemLink(item, cb, description);
+    }
 }
 
 void LLAppearanceMgr::addCOFItemLink(const LLInventoryItem *item,
-									 LLPointer<LLInventoryCallback> cb,
-									 const std::string description)
-{
-	const LLViewerInventoryItem *vitem = dynamic_cast<const LLViewerInventoryItem*>(item);
-	if (!vitem)
-	{
-		LL_WARNS() << "not an llviewerinventoryitem, failed" << LL_ENDL;
-		return;
-	}
-
-	gInventory.addChangedMask(LLInventoryObserver::LABEL, vitem->getLinkedUUID());
-
-	LLInventoryModel::cat_array_t cat_array;
-	LLInventoryModel::item_array_t item_array;
-	gInventory.collectDescendents(LLAppearanceMgr::getCOF(),
-								  cat_array,
-								  item_array,
-								  LLInventoryModel::EXCLUDE_TRASH);
-	bool linked_already = false;
-	for (S32 i=0; i<item_array.size(); i++)
-	{
-		// Are these links to the same object?
-		const LLViewerInventoryItem* inv_item = item_array.at(i).get();
-		const LLWearableType::EType wearable_type = inv_item->getWearableType();
-
-		const bool is_body_part =    (wearable_type == LLWearableType::WT_SHAPE) 
-								  || (wearable_type == LLWearableType::WT_HAIR) 
-								  || (wearable_type == LLWearableType::WT_EYES)
-								  || (wearable_type == LLWearableType::WT_SKIN);
-
-		if (inv_item->getLinkedUUID() == vitem->getLinkedUUID())
-		{
-			linked_already = true;
-		}
-		// Are these links to different items of the same body part
-		// type? If so, new item will replace old.
-		else if ((vitem->isWearableType()) && (vitem->getWearableType() == wearable_type))
-		{
-			if (is_body_part && inv_item->getIsLinkType())
-			{
-				remove_inventory_item(inv_item->getUUID(), cb);
-			}
-			else if (!gAgentWearables.canAddWearable(wearable_type))
-			{
-				// MULTI-WEARABLES: make sure we don't go over clothing limits
-				remove_inventory_item(inv_item->getUUID(), cb);
-			}
-		}
-	}
-
-	if (!linked_already)
-	{
-		LLViewerInventoryItem *copy_item = new LLViewerInventoryItem;
-		copy_item->copyViewerItem(vitem);
-		copy_item->setDescription(description);
-		link_inventory_object(getCOF(), copy_item, cb);
-	}
+                                     LLPointer<LLInventoryCallback> cb,
+                                     const std::string description)
+{
+    const LLViewerInventoryItem *vitem = dynamic_cast<const LLViewerInventoryItem*>(item);
+    if (!vitem)
+    {
+        LL_WARNS() << "not an llviewerinventoryitem, failed" << LL_ENDL;
+        return;
+    }
+
+    gInventory.addChangedMask(LLInventoryObserver::LABEL, vitem->getLinkedUUID());
+
+    LLInventoryModel::cat_array_t cat_array;
+    LLInventoryModel::item_array_t item_array;
+    gInventory.collectDescendents(LLAppearanceMgr::getCOF(),
+                                  cat_array,
+                                  item_array,
+                                  LLInventoryModel::EXCLUDE_TRASH);
+    bool linked_already = false;
+    for (S32 i=0; i<item_array.size(); i++)
+    {
+        // Are these links to the same object?
+        const LLViewerInventoryItem* inv_item = item_array.at(i).get();
+        const LLWearableType::EType wearable_type = inv_item->getWearableType();
+
+        const bool is_body_part =    (wearable_type == LLWearableType::WT_SHAPE)
+                                  || (wearable_type == LLWearableType::WT_HAIR)
+                                  || (wearable_type == LLWearableType::WT_EYES)
+                                  || (wearable_type == LLWearableType::WT_SKIN);
+
+        if (inv_item->getLinkedUUID() == vitem->getLinkedUUID())
+        {
+            linked_already = true;
+        }
+        // Are these links to different items of the same body part
+        // type? If so, new item will replace old.
+        else if ((vitem->isWearableType()) && (vitem->getWearableType() == wearable_type))
+        {
+            if (is_body_part && inv_item->getIsLinkType())
+            {
+                remove_inventory_item(inv_item->getUUID(), cb);
+            }
+            else if (!gAgentWearables.canAddWearable(wearable_type))
+            {
+                // MULTI-WEARABLES: make sure we don't go over clothing limits
+                remove_inventory_item(inv_item->getUUID(), cb);
+            }
+        }
+    }
+
+    if (!linked_already)
+    {
+        LLViewerInventoryItem *copy_item = new LLViewerInventoryItem;
+        copy_item->copyViewerItem(vitem);
+        copy_item->setDescription(description);
+        link_inventory_object(getCOF(), copy_item, cb);
+    }
 }
 
 LLInventoryModel::item_array_t LLAppearanceMgr::findCOFItemLinks(const LLUUID& item_id)
 {
-	LLInventoryModel::item_array_t result;
+    LLInventoryModel::item_array_t result;
 
     LLUUID linked_id = gInventory.getLinkedItemID(item_id);
     LLInventoryModel::cat_array_t cat_array;
@@ -3284,86 +3284,86 @@ LLInventoryModel::item_array_t LLAppearanceMgr::findCOFItemLinks(const LLUUID& i
             result.push_back(item_array.at(i));
         }
     }
-	return result;
+    return result;
 }
 
 bool LLAppearanceMgr::isLinkedInCOF(const LLUUID& item_id)
 {
-	LLInventoryModel::item_array_t links = LLAppearanceMgr::instance().findCOFItemLinks(item_id);
-	return links.size() > 0;
+    LLInventoryModel::item_array_t links = LLAppearanceMgr::instance().findCOFItemLinks(item_id);
+    return links.size() > 0;
 }
 
 void LLAppearanceMgr::removeAllClothesFromAvatar()
 {
-	// Fetch worn clothes (i.e. the ones in COF).
-	LLInventoryModel::item_array_t clothing_items;
-	LLInventoryModel::cat_array_t dummy;
-	LLIsType is_clothing(LLAssetType::AT_CLOTHING);
-	gInventory.collectDescendentsIf(getCOF(),
-									dummy,
-									clothing_items,
-									LLInventoryModel::EXCLUDE_TRASH,
-									is_clothing);
-	uuid_vec_t item_ids;
-	for (LLInventoryModel::item_array_t::iterator it = clothing_items.begin();
-		it != clothing_items.end(); ++it)
-	{
-		item_ids.push_back((*it).get()->getLinkedUUID());
-	}
-
-	// Take them off by removing from COF.
-	removeItemsFromAvatar(item_ids);
+    // Fetch worn clothes (i.e. the ones in COF).
+    LLInventoryModel::item_array_t clothing_items;
+    LLInventoryModel::cat_array_t dummy;
+    LLIsType is_clothing(LLAssetType::AT_CLOTHING);
+    gInventory.collectDescendentsIf(getCOF(),
+                                    dummy,
+                                    clothing_items,
+                                    LLInventoryModel::EXCLUDE_TRASH,
+                                    is_clothing);
+    uuid_vec_t item_ids;
+    for (LLInventoryModel::item_array_t::iterator it = clothing_items.begin();
+        it != clothing_items.end(); ++it)
+    {
+        item_ids.push_back((*it).get()->getLinkedUUID());
+    }
+
+    // Take them off by removing from COF.
+    removeItemsFromAvatar(item_ids);
 }
 
 void LLAppearanceMgr::removeAllAttachmentsFromAvatar()
 {
-	if (!isAgentAvatarValid()) return;
+    if (!isAgentAvatarValid()) return;
 
-	LLAgentWearables::llvo_vec_t objects_to_remove;
-	
-	for (const auto& attach_pair : gAgentAvatarp->mAttachmentPoints)
-	{
+    LLAgentWearables::llvo_vec_t objects_to_remove;
+
+    for (const auto& attach_pair : gAgentAvatarp->mAttachmentPoints)
+    {
         LLViewerJointAttachment* attachment = attach_pair.second;
         for (LLViewerObject * attached_object : attachment->mAttachedObjects)
-		{
-			if (attached_object)
-			{
-				objects_to_remove.push_back(attached_object);
-			}
-		}
-	}
-	uuid_vec_t ids_to_remove;
-	for (LLAgentWearables::llvo_vec_t::iterator it = objects_to_remove.begin();
-		 it != objects_to_remove.end();
-		 ++it)
-	{
-		ids_to_remove.push_back((*it)->getAttachmentItemID());
-	}
-	removeItemsFromAvatar(ids_to_remove);
+        {
+            if (attached_object)
+            {
+                objects_to_remove.push_back(attached_object);
+            }
+        }
+    }
+    uuid_vec_t ids_to_remove;
+    for (LLAgentWearables::llvo_vec_t::iterator it = objects_to_remove.begin();
+         it != objects_to_remove.end();
+         ++it)
+    {
+        ids_to_remove.push_back((*it)->getAttachmentItemID());
+    }
+    removeItemsFromAvatar(ids_to_remove);
 }
 
 class LLUpdateOnCOFLinkRemove : public LLInventoryCallback
 {
 public:
-	LLUpdateOnCOFLinkRemove(const LLUUID& remove_item_id, LLPointer<LLInventoryCallback> cb = NULL):
-		mItemID(remove_item_id),
-		mCB(cb)
-	{
-	}
-
-	/* virtual */ void fire(const LLUUID& item_id)
-	{
-		// just removed cof link, "(wear)" suffix depends on presence of link, so update label
-		gInventory.addChangedMask(LLInventoryObserver::LABEL, mItemID);
-		if (mCB.notNull())
-		{
-			mCB->fire(item_id);
-		}
-	}
+    LLUpdateOnCOFLinkRemove(const LLUUID& remove_item_id, LLPointer<LLInventoryCallback> cb = NULL):
+        mItemID(remove_item_id),
+        mCB(cb)
+    {
+    }
+
+    /* virtual */ void fire(const LLUUID& item_id)
+    {
+        // just removed cof link, "(wear)" suffix depends on presence of link, so update label
+        gInventory.addChangedMask(LLInventoryObserver::LABEL, mItemID);
+        if (mCB.notNull())
+        {
+            mCB->fire(item_id);
+        }
+    }
 
 private:
-	LLUUID mItemID;
-	LLPointer<LLInventoryCallback> mCB;
+    LLUUID mItemID;
+    LLPointer<LLInventoryCallback> mCB;
 };
 
 //void LLAppearanceMgr::removeCOFItemLinks(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb)
@@ -3371,159 +3371,159 @@ class LLUpdateOnCOFLinkRemove : public LLInventoryCallback
 void LLAppearanceMgr::removeCOFItemLinks(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb, bool immediate_delete)
 // [/SL:KB]
 {
-	gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
-
-	LLInventoryModel::cat_array_t cat_array;
-	LLInventoryModel::item_array_t item_array;
-	gInventory.collectDescendents(LLAppearanceMgr::getCOF(),
-								  cat_array,
-								  item_array,
-								  LLInventoryModel::EXCLUDE_TRASH);
-	for (S32 i=0; i<item_array.size(); i++)
-	{
-		const LLViewerInventoryItem* item = item_array.at(i).get();
-		if (item->getIsLinkType() && item->getLinkedUUID() == item_id)
-		{
+    gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
+
+    LLInventoryModel::cat_array_t cat_array;
+    LLInventoryModel::item_array_t item_array;
+    gInventory.collectDescendents(LLAppearanceMgr::getCOF(),
+                                  cat_array,
+                                  item_array,
+                                  LLInventoryModel::EXCLUDE_TRASH);
+    for (S32 i=0; i<item_array.size(); i++)
+    {
+        const LLViewerInventoryItem* item = item_array.at(i).get();
+        if (item->getIsLinkType() && item->getLinkedUUID() == item_id)
+        {
 // [RLVa:KB] - Checked: 2013-02-12 (RLVa-1.4.8)
-			if (rlv_handler_t::isEnabled())
-			{
-				RLV_ASSERT(rlvPredCanRemoveItem(item));
-			}
-			remove_inventory_item(item->getUUID(), cb, immediate_delete);
+            if (rlv_handler_t::isEnabled())
+            {
+                RLV_ASSERT(rlvPredCanRemoveItem(item));
+            }
+            remove_inventory_item(item->getUUID(), cb, immediate_delete);
 // [/RLVa:KB]
-//			if (item->getType() == LLAssetType::AT_OBJECT)
-//			{
-//				// Immediate delete
-//				remove_inventory_item(item->getUUID(), cb, true);
-//				gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
-//			}
-//			else
-//			{
-//				// Delayed delete
-//				// Pointless to update item_id label here since link still exists and first notifyObservers
-//				// call will restore (wear) suffix, mark for update after deletion
-//				LLPointer<LLUpdateOnCOFLinkRemove> cb_label = new LLUpdateOnCOFLinkRemove(item_id, cb);
-//				remove_inventory_item(item->getUUID(), cb_label, false);
-//			}
-		}
-	}
+//          if (item->getType() == LLAssetType::AT_OBJECT)
+//          {
+//              // Immediate delete
+//              remove_inventory_item(item->getUUID(), cb, true);
+//              gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
+//          }
+//          else
+//          {
+//              // Delayed delete
+//              // Pointless to update item_id label here since link still exists and first notifyObservers
+//              // call will restore (wear) suffix, mark for update after deletion
+//              LLPointer<LLUpdateOnCOFLinkRemove> cb_label = new LLUpdateOnCOFLinkRemove(item_id, cb);
+//              remove_inventory_item(item->getUUID(), cb_label, false);
+//          }
+        }
+    }
 }
 
 void LLAppearanceMgr::removeCOFLinksOfType(LLWearableType::EType type, LLPointer<LLInventoryCallback> cb)
 {
-	LLFindWearablesOfType filter_wearables_of_type(type);
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	LLInventoryModel::item_array_t::const_iterator it;
-
-	gInventory.collectDescendentsIf(getCOF(), cats, items, true, filter_wearables_of_type);
-	for (it = items.begin(); it != items.end(); ++it)
-	{
-		const LLViewerInventoryItem* item = *it;
-		if (item->getIsLinkType()) // we must operate on links only
-		{
+    LLFindWearablesOfType filter_wearables_of_type(type);
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    LLInventoryModel::item_array_t::const_iterator it;
+
+    gInventory.collectDescendentsIf(getCOF(), cats, items, true, filter_wearables_of_type);
+    for (it = items.begin(); it != items.end(); ++it)
+    {
+        const LLViewerInventoryItem* item = *it;
+        if (item->getIsLinkType()) // we must operate on links only
+        {
 // [RLVa:KB] - Checked: 2013-02-12 (RLVa-1.4.8)
-			if (rlv_handler_t::isEnabled())
-			{
-				RLV_ASSERT(rlvPredCanRemoveItem(item));
-			}
+            if (rlv_handler_t::isEnabled())
+            {
+                RLV_ASSERT(rlvPredCanRemoveItem(item));
+            }
 // [/RLVa:KB]
-			remove_inventory_item(item->getUUID(), cb);
-		}
-	}
+            remove_inventory_item(item->getUUID(), cb);
+        }
+    }
 }
 
 void LLAppearanceMgr::updateIsDirty()
 {
-	LLUUID cof = getCOF();
-	LLUUID base_outfit;
-
-	// find base outfit link 
-	const LLViewerInventoryItem* base_outfit_item = getBaseOutfitLink();
-	LLViewerInventoryCategory* catp = NULL;
-	if (base_outfit_item && base_outfit_item->getIsLinkType())
-	{
-		catp = base_outfit_item->getLinkedCategory();
-	}
-	if(catp && catp->getPreferredType() == LLFolderType::FT_OUTFIT)
-	{
-		base_outfit = catp->getUUID();
-	}
-
-	// Set dirty to "false" if no base outfit found to disable "Save"
-	// and leave only "Save As" enabled in My Outfits.
-	mOutfitIsDirty = false;
-
-	if (base_outfit.notNull())
-	{
-		LLIsValidItemLink collector;
-
-		LLInventoryModel::cat_array_t cof_cats;
-		LLInventoryModel::item_array_t cof_items;
-		gInventory.collectDescendentsIf(cof, cof_cats, cof_items,
-									  LLInventoryModel::EXCLUDE_TRASH, collector);
-
-		LLInventoryModel::cat_array_t outfit_cats;
-		LLInventoryModel::item_array_t outfit_items;
-		gInventory.collectDescendentsIf(base_outfit, outfit_cats, outfit_items,
-									  LLInventoryModel::EXCLUDE_TRASH, collector);
-
-		for (U32 i = 0; i < outfit_items.size(); ++i)
-		{
-			LLViewerInventoryItem* linked_item = outfit_items.at(i)->getLinkedItem();
-			if (linked_item != NULL && linked_item->getActualType() == LLAssetType::AT_TEXTURE)
-			{
-				outfit_items.erase(outfit_items.begin() + i);
-				break;
-			}
-		}
-
-		if(outfit_items.size() != cof_items.size())
-		{
-			LL_DEBUGS("Avatar") << "item count different - base " << outfit_items.size() << " cof " << cof_items.size() << LL_ENDL;
-			// Current outfit folder should have one more item than the outfit folder.
-			// this one item is the link back to the outfit folder itself.
-			mOutfitIsDirty = true;
-			return;
-		}
-
-		//"dirty" - also means a difference in linked UUIDs and/or a difference in wearables order (links' descriptions)
-		std::sort(cof_items.begin(), cof_items.end(), sort_by_linked_uuid);
-		std::sort(outfit_items.begin(), outfit_items.end(), sort_by_linked_uuid);
-
-		for (U32 i = 0; i < cof_items.size(); ++i)
-		{
-			LLViewerInventoryItem *item1 = cof_items.at(i);
-			LLViewerInventoryItem *item2 = outfit_items.at(i);
-
-			if (item1->getLinkedUUID() != item2->getLinkedUUID() || 
-				item1->getName() != item2->getName() ||
-				item1->getActualDescription() != item2->getActualDescription())
-			{
-				if (item1->getLinkedUUID() != item2->getLinkedUUID())
-				{
-					LL_DEBUGS("Avatar") << "link id different " << LL_ENDL;
-				}
-				else
-				{
-					if (item1->getName() != item2->getName())
-					{
-						LL_DEBUGS("Avatar") << "name different " << item1->getName() << " " << item2->getName() << LL_ENDL;
-					}
-					if (item1->getActualDescription() != item2->getActualDescription())
-					{
-						LL_DEBUGS("Avatar") << "desc different " << item1->getActualDescription()
-											<< " " << item2->getActualDescription() 
-											<< " names " << item1->getName() << " " << item2->getName() << LL_ENDL;
-					}
-				}
-				mOutfitIsDirty = true;
-				return;
-			}
-		}
-	}
-	llassert(!mOutfitIsDirty);
-	LL_DEBUGS("Avatar") << "clean" << LL_ENDL;
+    LLUUID cof = getCOF();
+    LLUUID base_outfit;
+
+    // find base outfit link
+    const LLViewerInventoryItem* base_outfit_item = getBaseOutfitLink();
+    LLViewerInventoryCategory* catp = NULL;
+    if (base_outfit_item && base_outfit_item->getIsLinkType())
+    {
+        catp = base_outfit_item->getLinkedCategory();
+    }
+    if(catp && catp->getPreferredType() == LLFolderType::FT_OUTFIT)
+    {
+        base_outfit = catp->getUUID();
+    }
+
+    // Set dirty to "false" if no base outfit found to disable "Save"
+    // and leave only "Save As" enabled in My Outfits.
+    mOutfitIsDirty = false;
+
+    if (base_outfit.notNull())
+    {
+        LLIsValidItemLink collector;
+
+        LLInventoryModel::cat_array_t cof_cats;
+        LLInventoryModel::item_array_t cof_items;
+        gInventory.collectDescendentsIf(cof, cof_cats, cof_items,
+                                      LLInventoryModel::EXCLUDE_TRASH, collector);
+
+        LLInventoryModel::cat_array_t outfit_cats;
+        LLInventoryModel::item_array_t outfit_items;
+        gInventory.collectDescendentsIf(base_outfit, outfit_cats, outfit_items,
+                                      LLInventoryModel::EXCLUDE_TRASH, collector);
+
+        for (U32 i = 0; i < outfit_items.size(); ++i)
+        {
+            LLViewerInventoryItem* linked_item = outfit_items.at(i)->getLinkedItem();
+            if (linked_item != NULL && linked_item->getActualType() == LLAssetType::AT_TEXTURE)
+            {
+                outfit_items.erase(outfit_items.begin() + i);
+                break;
+            }
+        }
+
+        if(outfit_items.size() != cof_items.size())
+        {
+            LL_DEBUGS("Avatar") << "item count different - base " << outfit_items.size() << " cof " << cof_items.size() << LL_ENDL;
+            // Current outfit folder should have one more item than the outfit folder.
+            // this one item is the link back to the outfit folder itself.
+            mOutfitIsDirty = true;
+            return;
+        }
+
+        //"dirty" - also means a difference in linked UUIDs and/or a difference in wearables order (links' descriptions)
+        std::sort(cof_items.begin(), cof_items.end(), sort_by_linked_uuid);
+        std::sort(outfit_items.begin(), outfit_items.end(), sort_by_linked_uuid);
+
+        for (U32 i = 0; i < cof_items.size(); ++i)
+        {
+            LLViewerInventoryItem *item1 = cof_items.at(i);
+            LLViewerInventoryItem *item2 = outfit_items.at(i);
+
+            if (item1->getLinkedUUID() != item2->getLinkedUUID() ||
+                item1->getName() != item2->getName() ||
+                item1->getActualDescription() != item2->getActualDescription())
+            {
+                if (item1->getLinkedUUID() != item2->getLinkedUUID())
+                {
+                    LL_DEBUGS("Avatar") << "link id different " << LL_ENDL;
+                }
+                else
+                {
+                    if (item1->getName() != item2->getName())
+                    {
+                        LL_DEBUGS("Avatar") << "name different " << item1->getName() << " " << item2->getName() << LL_ENDL;
+                    }
+                    if (item1->getActualDescription() != item2->getActualDescription())
+                    {
+                        LL_DEBUGS("Avatar") << "desc different " << item1->getActualDescription()
+                                            << " " << item2->getActualDescription()
+                                            << " names " << item1->getName() << " " << item2->getName() << LL_ENDL;
+                    }
+                }
+                mOutfitIsDirty = true;
+                return;
+            }
+        }
+    }
+    llassert(!mOutfitIsDirty);
+    LL_DEBUGS("Avatar") << "clean" << LL_ENDL;
 }
 
 // *HACK: Must match name in Library or agent inventory
@@ -3534,154 +3534,154 @@ const std::string FEMALE_GESTURES_FOLDER = "Female Gestures";
 const std::string SPEECH_GESTURES_FOLDER = "Speech Gestures";
 const std::string OTHER_GESTURES_FOLDER = "Other Gestures";
 
-void LLAppearanceMgr::copyLibraryGestures()
-{
-	LL_INFOS("Avatar") << self_av_string() << "Copying library gestures" << LL_ENDL;
-
-	// Copy gestures
-	LLUUID lib_gesture_cat_id =
-		gInventory.findLibraryCategoryUUIDForType(LLFolderType::FT_GESTURE);
-	if (lib_gesture_cat_id.isNull())
-	{
-		LL_WARNS() << "Unable to copy gestures, source category not found" << LL_ENDL;
-	}
-	LLUUID dst_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_GESTURE);
-
-	std::vector<std::string> gesture_folders_to_copy;
-	gesture_folders_to_copy.push_back(MALE_GESTURES_FOLDER);
-	gesture_folders_to_copy.push_back(FEMALE_GESTURES_FOLDER);
-	gesture_folders_to_copy.push_back(COMMON_GESTURES_FOLDER);
-	gesture_folders_to_copy.push_back(SPEECH_GESTURES_FOLDER);
-	gesture_folders_to_copy.push_back(OTHER_GESTURES_FOLDER);
-
-	for(std::vector<std::string>::iterator it = gesture_folders_to_copy.begin();
-		it != gesture_folders_to_copy.end();
-		++it)
-	{
-		std::string& folder_name = *it;
-
-		LLPointer<LLInventoryCallback> cb(NULL);
-
-		// After copying gestures, activate Common, Other, plus
-		// Male and/or Female, depending upon the initial outfit gender.
-		ESex gender = gAgentAvatarp->getSex();
-
-		std::string activate_male_gestures;
-		std::string activate_female_gestures;
-		switch (gender) {
-			case SEX_MALE:
-				activate_male_gestures = MALE_GESTURES_FOLDER;
-				break;
-			case SEX_FEMALE:
-				activate_female_gestures = FEMALE_GESTURES_FOLDER;
-				break;
-			case SEX_BOTH:
-				activate_male_gestures = MALE_GESTURES_FOLDER;
-				activate_female_gestures = FEMALE_GESTURES_FOLDER;
-				break;
-		}
-
-		if (folder_name == activate_male_gestures ||
-			folder_name == activate_female_gestures ||
-			folder_name == COMMON_GESTURES_FOLDER ||
-			folder_name == OTHER_GESTURES_FOLDER)
-		{
-			cb = new LLBoostFuncInventoryCallback(activate_gesture_cb);
-		}
-
-		LLUUID cat_id = findDescendentCategoryIDByName(lib_gesture_cat_id,folder_name);
-		if (cat_id.isNull())
-		{
-			LL_WARNS() << self_av_string() << "failed to find gesture folder for " << folder_name << LL_ENDL;
-		}
-		else
-		{
-			LL_DEBUGS("Avatar") << self_av_string() << "initiating fetch and copy for " << folder_name << " cat_id " << cat_id << LL_ENDL;
-			callAfterCategoryFetch(cat_id,
-								   boost::bind(&LLAppearanceMgr::shallowCopyCategory,
-											   &LLAppearanceMgr::instance(),
-											   cat_id, dst_id, cb));
-		}
-	}
+void LLAppearanceMgr::copyLibraryGestures()
+{
+    LL_INFOS("Avatar") << self_av_string() << "Copying library gestures" << LL_ENDL;
+
+    // Copy gestures
+    LLUUID lib_gesture_cat_id =
+        gInventory.findLibraryCategoryUUIDForType(LLFolderType::FT_GESTURE);
+    if (lib_gesture_cat_id.isNull())
+    {
+        LL_WARNS() << "Unable to copy gestures, source category not found" << LL_ENDL;
+    }
+    LLUUID dst_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_GESTURE);
+
+    std::vector<std::string> gesture_folders_to_copy;
+    gesture_folders_to_copy.push_back(MALE_GESTURES_FOLDER);
+    gesture_folders_to_copy.push_back(FEMALE_GESTURES_FOLDER);
+    gesture_folders_to_copy.push_back(COMMON_GESTURES_FOLDER);
+    gesture_folders_to_copy.push_back(SPEECH_GESTURES_FOLDER);
+    gesture_folders_to_copy.push_back(OTHER_GESTURES_FOLDER);
+
+    for(std::vector<std::string>::iterator it = gesture_folders_to_copy.begin();
+        it != gesture_folders_to_copy.end();
+        ++it)
+    {
+        std::string& folder_name = *it;
+
+        LLPointer<LLInventoryCallback> cb(NULL);
+
+        // After copying gestures, activate Common, Other, plus
+        // Male and/or Female, depending upon the initial outfit gender.
+        ESex gender = gAgentAvatarp->getSex();
+
+        std::string activate_male_gestures;
+        std::string activate_female_gestures;
+        switch (gender) {
+            case SEX_MALE:
+                activate_male_gestures = MALE_GESTURES_FOLDER;
+                break;
+            case SEX_FEMALE:
+                activate_female_gestures = FEMALE_GESTURES_FOLDER;
+                break;
+            case SEX_BOTH:
+                activate_male_gestures = MALE_GESTURES_FOLDER;
+                activate_female_gestures = FEMALE_GESTURES_FOLDER;
+                break;
+        }
+
+        if (folder_name == activate_male_gestures ||
+            folder_name == activate_female_gestures ||
+            folder_name == COMMON_GESTURES_FOLDER ||
+            folder_name == OTHER_GESTURES_FOLDER)
+        {
+            cb = new LLBoostFuncInventoryCallback(activate_gesture_cb);
+        }
+
+        LLUUID cat_id = findDescendentCategoryIDByName(lib_gesture_cat_id,folder_name);
+        if (cat_id.isNull())
+        {
+            LL_WARNS() << self_av_string() << "failed to find gesture folder for " << folder_name << LL_ENDL;
+        }
+        else
+        {
+            LL_DEBUGS("Avatar") << self_av_string() << "initiating fetch and copy for " << folder_name << " cat_id " << cat_id << LL_ENDL;
+            callAfterCategoryFetch(cat_id,
+                                   boost::bind(&LLAppearanceMgr::shallowCopyCategory,
+                                               &LLAppearanceMgr::instance(),
+                                               cat_id, dst_id, cb));
+        }
+    }
 }
 
 // Handler for anything that's deferred until avatar de-clouds.
 void LLAppearanceMgr::onFirstFullyVisible()
 {
-	gAgentAvatarp->outputRezTiming("Avatar fully loaded");
-	gAgentAvatarp->reportAvatarRezTime();
-	gAgentAvatarp->debugAvatarVisible();
+    gAgentAvatarp->outputRezTiming("Avatar fully loaded");
+    gAgentAvatarp->reportAvatarRezTime();
+    gAgentAvatarp->debugAvatarVisible();
 
-	// If this is the first time we've ever logged in,
-	// then copy default gestures from the library.
-	if (gAgent.isFirstLogin()) {
-		copyLibraryGestures();
-	}
+    // If this is the first time we've ever logged in,
+    // then copy default gestures from the library.
+    if (gAgent.isFirstLogin()) {
+        copyLibraryGestures();
+    }
 }
 
 // update "dirty" state - defined outside class to allow for calling
 // after appearance mgr instance has been destroyed.
 void appearance_mgr_update_dirty_state()
 {
-	if (LLAppearanceMgr::instanceExists())
-	{
-		LLAppearanceMgr& app_mgr = LLAppearanceMgr::instance();
-		LLUUID image_id = app_mgr.getOutfitImage();
-		if(image_id.notNull())
-		{
-			LLPointer<LLInventoryCallback> cb = NULL;
-			link_inventory_object(app_mgr.getBaseOutfitUUID(), image_id, cb);
-		}
+    if (LLAppearanceMgr::instanceExists())
+    {
+        LLAppearanceMgr& app_mgr = LLAppearanceMgr::instance();
+        LLUUID image_id = app_mgr.getOutfitImage();
+        if(image_id.notNull())
+        {
+            LLPointer<LLInventoryCallback> cb = NULL;
+            link_inventory_object(app_mgr.getBaseOutfitUUID(), image_id, cb);
+        }
 
-		LLAppearanceMgr::getInstance()->updateIsDirty();
-		LLAppearanceMgr::getInstance()->setOutfitLocked(false);
-		gAgentWearables.notifyLoadingFinished();
-	}
+        LLAppearanceMgr::getInstance()->updateIsDirty();
+        LLAppearanceMgr::getInstance()->setOutfitLocked(false);
+        gAgentWearables.notifyLoadingFinished();
+    }
 }
 
 void update_base_outfit_after_ordering()
 {
-	LLAppearanceMgr& app_mgr = LLAppearanceMgr::instance();
-	app_mgr.setOutfitImage(LLUUID());
-	LLInventoryModel::cat_array_t sub_cat_array;
-	LLInventoryModel::item_array_t outfit_item_array;
-	gInventory.collectDescendents(app_mgr.getBaseOutfitUUID(),
-								sub_cat_array,
-								outfit_item_array,
-								LLInventoryModel::EXCLUDE_TRASH);
-	for (LLViewerInventoryItem* outfit_item : outfit_item_array)
-	{
-		LLViewerInventoryItem* linked_item = outfit_item->getLinkedItem();
-		if (linked_item != NULL)
-		{
-			if (linked_item->getActualType() == LLAssetType::AT_TEXTURE)
-			{
-				app_mgr.setOutfitImage(linked_item->getLinkedUUID());
-				if (linked_item->getName() == LLAppearanceMgr::sExpectedTextureName)
-				{
-					// Images with "appropriate" name take priority
-					break;
-				}
-			}
-		}
-		else if (outfit_item->getActualType() == LLAssetType::AT_TEXTURE)
-		{
-			app_mgr.setOutfitImage(outfit_item->getUUID());
-			if (outfit_item->getName() == LLAppearanceMgr::sExpectedTextureName)
-			{
-				// Images with "appropriate" name take priority
-				break;
-			}
-		}
-	}
-
-	LLPointer<LLInventoryCallback> dirty_state_updater =
-		new LLBoostFuncInventoryCallback(no_op_inventory_func, appearance_mgr_update_dirty_state);
-
-	//COF contains only links so we copy to the Base Outfit only links
-	const LLUUID base_outfit_id = app_mgr.getBaseOutfitUUID();
-	bool copy_folder_links = false;
-	app_mgr.slamCategoryLinks(app_mgr.getCOF(), base_outfit_id, copy_folder_links, dirty_state_updater);
+    LLAppearanceMgr& app_mgr = LLAppearanceMgr::instance();
+    app_mgr.setOutfitImage(LLUUID());
+    LLInventoryModel::cat_array_t sub_cat_array;
+    LLInventoryModel::item_array_t outfit_item_array;
+    gInventory.collectDescendents(app_mgr.getBaseOutfitUUID(),
+                                sub_cat_array,
+                                outfit_item_array,
+                                LLInventoryModel::EXCLUDE_TRASH);
+    for (LLViewerInventoryItem* outfit_item : outfit_item_array)
+    {
+        LLViewerInventoryItem* linked_item = outfit_item->getLinkedItem();
+        if (linked_item != NULL)
+        {
+            if (linked_item->getActualType() == LLAssetType::AT_TEXTURE)
+            {
+                app_mgr.setOutfitImage(linked_item->getLinkedUUID());
+                if (linked_item->getName() == LLAppearanceMgr::sExpectedTextureName)
+                {
+                    // Images with "appropriate" name take priority
+                    break;
+                }
+            }
+        }
+        else if (outfit_item->getActualType() == LLAssetType::AT_TEXTURE)
+        {
+            app_mgr.setOutfitImage(outfit_item->getUUID());
+            if (outfit_item->getName() == LLAppearanceMgr::sExpectedTextureName)
+            {
+                // Images with "appropriate" name take priority
+                break;
+            }
+        }
+    }
+
+    LLPointer<LLInventoryCallback> dirty_state_updater =
+        new LLBoostFuncInventoryCallback(no_op_inventory_func, appearance_mgr_update_dirty_state);
+
+    //COF contains only links so we copy to the Base Outfit only links
+    const LLUUID base_outfit_id = app_mgr.getBaseOutfitUUID();
+    bool copy_folder_links = false;
+    app_mgr.slamCategoryLinks(app_mgr.getCOF(), base_outfit_id, copy_folder_links, dirty_state_updater);
 
     if (base_outfit_id.notNull())
     {
@@ -3733,245 +3733,245 @@ void update_base_outfit_after_ordering()
 // to match the current COF. Fails if no current base outfit is set.
 bool LLAppearanceMgr::updateBaseOutfit()
 {
-	if (isOutfitLocked())
-	{
-		// don't allow modify locked outfit
-		llassert(!isOutfitLocked());
-		return false;
-	}
+    if (isOutfitLocked())
+    {
+        // don't allow modify locked outfit
+        llassert(!isOutfitLocked());
+        return false;
+    }
 
-	setOutfitLocked(true);
+    setOutfitLocked(true);
 
-	gAgentWearables.notifyLoadingStarted();
+    gAgentWearables.notifyLoadingStarted();
 
-	const LLUUID base_outfit_id = getBaseOutfitUUID();
-	if (base_outfit_id.isNull()) return false;
-	LL_DEBUGS("Avatar") << "saving cof to base outfit " << base_outfit_id << LL_ENDL;
+    const LLUUID base_outfit_id = getBaseOutfitUUID();
+    if (base_outfit_id.isNull()) return false;
+    LL_DEBUGS("Avatar") << "saving cof to base outfit " << base_outfit_id << LL_ENDL;
 
-	LLPointer<LLInventoryCallback> cb =
-		new LLBoostFuncInventoryCallback(no_op_inventory_func, update_base_outfit_after_ordering);
-	// Really shouldn't be needed unless there's a race condition -
-	// updateAppearanceFromCOF() already calls updateClothingOrderingInfo.
-	updateClothingOrderingInfo(LLUUID::null, cb);
+    LLPointer<LLInventoryCallback> cb =
+        new LLBoostFuncInventoryCallback(no_op_inventory_func, update_base_outfit_after_ordering);
+    // Really shouldn't be needed unless there's a race condition -
+    // updateAppearanceFromCOF() already calls updateClothingOrderingInfo.
+    updateClothingOrderingInfo(LLUUID::null, cb);
 
-	return true;
+    return true;
 }
 
 void LLAppearanceMgr::divvyWearablesByType(const LLInventoryModel::item_array_t& items, wearables_by_type_t& items_by_type)
 {
-	items_by_type.resize(LLWearableType::WT_COUNT);
-	if (items.empty()) return;
-
-	for (S32 i=0; i<items.size(); i++)
-	{
-		LLViewerInventoryItem *item = items.at(i);
-		if (!item)
-		{
-			LL_WARNS("Appearance") << "NULL item found" << LL_ENDL;
-			continue;
-		}
-		// Ignore non-wearables.
-		if (!item->isWearableType())
-			continue;
-		LLWearableType::EType type = item->getWearableType();
-		if(type < 0 || type >= LLWearableType::WT_COUNT)
-		{
-			LL_WARNS("Appearance") << "Invalid wearable type. Inventory type does not match wearable flag bitfield." << LL_ENDL;
-			continue;
-		}
-		items_by_type[type].push_back(item);
-	}
+    items_by_type.resize(LLWearableType::WT_COUNT);
+    if (items.empty()) return;
+
+    for (S32 i=0; i<items.size(); i++)
+    {
+        LLViewerInventoryItem *item = items.at(i);
+        if (!item)
+        {
+            LL_WARNS("Appearance") << "NULL item found" << LL_ENDL;
+            continue;
+        }
+        // Ignore non-wearables.
+        if (!item->isWearableType())
+            continue;
+        LLWearableType::EType type = item->getWearableType();
+        if(type < 0 || type >= LLWearableType::WT_COUNT)
+        {
+            LL_WARNS("Appearance") << "Invalid wearable type. Inventory type does not match wearable flag bitfield." << LL_ENDL;
+            continue;
+        }
+        items_by_type[type].push_back(item);
+    }
 }
 
 std::string build_order_string(LLWearableType::EType type, U32 i)
 {
-		std::ostringstream order_num;
-		order_num << ORDER_NUMBER_SEPARATOR << type * 100 + i;
-		return order_num.str();
+        std::ostringstream order_num;
+        order_num << ORDER_NUMBER_SEPARATOR << type * 100 + i;
+        return order_num.str();
 }
 
 struct WearablesOrderComparator
 {
-	LOG_CLASS(WearablesOrderComparator);
-	WearablesOrderComparator(const LLWearableType::EType type)
-	{
-		mControlSize = build_order_string(type, 0).size();
-	};
-
-	bool operator()(const LLInventoryItem* item1, const LLInventoryItem* item2)
-	{
-		const std::string& desc1 = item1->getActualDescription();
-		const std::string& desc2 = item2->getActualDescription();
-		
-		bool item1_valid = (desc1.size() == mControlSize) && (ORDER_NUMBER_SEPARATOR == desc1[0]);
-		bool item2_valid = (desc2.size() == mControlSize) && (ORDER_NUMBER_SEPARATOR == desc2[0]);
-
-		if (item1_valid && item2_valid)
-			return desc1 < desc2;
-
-		//we need to sink down invalid items: items with empty descriptions, items with "Broken link" descriptions,
-		//items with ordering information but not for the associated wearables type
-		if (!item1_valid && item2_valid) 
-			return false;
-		else if (item1_valid && !item2_valid)
-			return true;
-
-		return item1->getName() < item2->getName();
-	}
-
-	U32 mControlSize;
+    LOG_CLASS(WearablesOrderComparator);
+    WearablesOrderComparator(const LLWearableType::EType type)
+    {
+        mControlSize = build_order_string(type, 0).size();
+    };
+
+    bool operator()(const LLInventoryItem* item1, const LLInventoryItem* item2)
+    {
+        const std::string& desc1 = item1->getActualDescription();
+        const std::string& desc2 = item2->getActualDescription();
+
+        bool item1_valid = (desc1.size() == mControlSize) && (ORDER_NUMBER_SEPARATOR == desc1[0]);
+        bool item2_valid = (desc2.size() == mControlSize) && (ORDER_NUMBER_SEPARATOR == desc2[0]);
+
+        if (item1_valid && item2_valid)
+            return desc1 < desc2;
+
+        //we need to sink down invalid items: items with empty descriptions, items with "Broken link" descriptions,
+        //items with ordering information but not for the associated wearables type
+        if (!item1_valid && item2_valid)
+            return false;
+        else if (item1_valid && !item2_valid)
+            return true;
+
+        return item1->getName() < item2->getName();
+    }
+
+    U32 mControlSize;
 };
 
 void LLAppearanceMgr::getWearableOrderingDescUpdates(LLInventoryModel::item_array_t& wear_items,
-													 desc_map_t& desc_map)
-{
-	wearables_by_type_t items_by_type(LLWearableType::WT_COUNT);
-	divvyWearablesByType(wear_items, items_by_type);
-
-	for (U32 type = LLWearableType::WT_SHIRT; type < LLWearableType::WT_COUNT; type++)
-	{
-		U32 size = items_by_type[type].size();
-		if (!size) continue;
-		
-		//sinking down invalid items which need reordering
-		std::sort(items_by_type[type].begin(), items_by_type[type].end(), WearablesOrderComparator((LLWearableType::EType) type));
-		
-		//requesting updates only for those links which don't have "valid" descriptions
-		for (U32 i = 0; i < size; i++)
-		{
-			LLViewerInventoryItem* item = items_by_type[type][i];
-			if (!item) continue;
-			
-			std::string new_order_str = build_order_string((LLWearableType::EType)type, i);
-			if (new_order_str == item->getActualDescription()) continue;
-			
-			desc_map[item->getUUID()] = new_order_str;
-		}
-	}
+                                                     desc_map_t& desc_map)
+{
+    wearables_by_type_t items_by_type(LLWearableType::WT_COUNT);
+    divvyWearablesByType(wear_items, items_by_type);
+
+    for (U32 type = LLWearableType::WT_SHIRT; type < LLWearableType::WT_COUNT; type++)
+    {
+        U32 size = items_by_type[type].size();
+        if (!size) continue;
+
+        //sinking down invalid items which need reordering
+        std::sort(items_by_type[type].begin(), items_by_type[type].end(), WearablesOrderComparator((LLWearableType::EType) type));
+
+        //requesting updates only for those links which don't have "valid" descriptions
+        for (U32 i = 0; i < size; i++)
+        {
+            LLViewerInventoryItem* item = items_by_type[type][i];
+            if (!item) continue;
+
+            std::string new_order_str = build_order_string((LLWearableType::EType)type, i);
+            if (new_order_str == item->getActualDescription()) continue;
+
+            desc_map[item->getUUID()] = new_order_str;
+        }
+    }
 }
 
 bool LLAppearanceMgr::validateClothingOrderingInfo(LLUUID cat_id)
 {
-	// COF is processed if cat_id is not specified
-	if (cat_id.isNull())
-	{
-		cat_id = getCOF();
-	}
-
-	LLInventoryModel::item_array_t wear_items;
-	getDescendentsOfAssetType(cat_id, wear_items, LLAssetType::AT_CLOTHING);
-
-	// Identify items for which desc needs to change.
-	desc_map_t desc_map;
-	getWearableOrderingDescUpdates(wear_items, desc_map);
-
-	for (desc_map_t::const_iterator it = desc_map.begin();
-		 it != desc_map.end(); ++it)
-	{
-		const LLUUID& item_id = it->first;
-		const std::string& new_order_str = it->second;
-		LLViewerInventoryItem *item = gInventory.getItem(item_id);
-		LL_WARNS() << "Order validation fails: " << item->getName()
-				<< " needs to update desc to: " << new_order_str
-				<< " (from: " << item->getActualDescription() << ")" << LL_ENDL;
-	}
-	
-	return desc_map.size() == 0;
+    // COF is processed if cat_id is not specified
+    if (cat_id.isNull())
+    {
+        cat_id = getCOF();
+    }
+
+    LLInventoryModel::item_array_t wear_items;
+    getDescendentsOfAssetType(cat_id, wear_items, LLAssetType::AT_CLOTHING);
+
+    // Identify items for which desc needs to change.
+    desc_map_t desc_map;
+    getWearableOrderingDescUpdates(wear_items, desc_map);
+
+    for (desc_map_t::const_iterator it = desc_map.begin();
+         it != desc_map.end(); ++it)
+    {
+        const LLUUID& item_id = it->first;
+        const std::string& new_order_str = it->second;
+        LLViewerInventoryItem *item = gInventory.getItem(item_id);
+        LL_WARNS() << "Order validation fails: " << item->getName()
+                << " needs to update desc to: " << new_order_str
+                << " (from: " << item->getActualDescription() << ")" << LL_ENDL;
+    }
+
+    return desc_map.size() == 0;
 }
 
 void LLAppearanceMgr::updateClothingOrderingInfo(LLUUID cat_id,
-												 LLPointer<LLInventoryCallback> cb)
+                                                 LLPointer<LLInventoryCallback> cb)
 {
-	// COF is processed if cat_id is not specified
-	if (cat_id.isNull())
-	{
-		cat_id = getCOF();
-	}
+    // COF is processed if cat_id is not specified
+    if (cat_id.isNull())
+    {
+        cat_id = getCOF();
+    }
 
-	LLInventoryModel::item_array_t wear_items;
-	getDescendentsOfAssetType(cat_id, wear_items, LLAssetType::AT_CLOTHING);
+    LLInventoryModel::item_array_t wear_items;
+    getDescendentsOfAssetType(cat_id, wear_items, LLAssetType::AT_CLOTHING);
 
-	// Identify items for which desc needs to change.
-	desc_map_t desc_map;
-	getWearableOrderingDescUpdates(wear_items, desc_map);
+    // Identify items for which desc needs to change.
+    desc_map_t desc_map;
+    getWearableOrderingDescUpdates(wear_items, desc_map);
+
+    for (desc_map_t::const_iterator it = desc_map.begin();
+         it != desc_map.end(); ++it)
+    {
+        LLSD updates;
+        const LLUUID& item_id = it->first;
+        const std::string& new_order_str = it->second;
+        LLViewerInventoryItem *item = gInventory.getItem(item_id);
+        LL_DEBUGS("Avatar") << item->getName() << " updating desc to: " << new_order_str
+            << " (was: " << item->getActualDescription() << ")" << LL_ENDL;
+        updates["desc"] = new_order_str;
+        update_inventory_item(item_id,updates,cb);
+    }
 
-	for (desc_map_t::const_iterator it = desc_map.begin();
-		 it != desc_map.end(); ++it)
-	{
-		LLSD updates;
-		const LLUUID& item_id = it->first;
-		const std::string& new_order_str = it->second;
-		LLViewerInventoryItem *item = gInventory.getItem(item_id);
-		LL_DEBUGS("Avatar") << item->getName() << " updating desc to: " << new_order_str
-			<< " (was: " << item->getActualDescription() << ")" << LL_ENDL;
-		updates["desc"] = new_order_str;
-		update_inventory_item(item_id,updates,cb);
-	}
-		
 }
 
 
 LLSD LLAppearanceMgr::dumpCOF() const
 {
-	LLSD links = LLSD::emptyArray();
-	LLMD5 md5;
-	
-	LLInventoryModel::cat_array_t cat_array;
-	LLInventoryModel::item_array_t item_array;
-	gInventory.collectDescendents(getCOF(),cat_array,item_array,LLInventoryModel::EXCLUDE_TRASH);
-	for (S32 i=0; i<item_array.size(); i++)
-	{
-		const LLViewerInventoryItem* inv_item = item_array.at(i).get();
-		LLSD item;
-		LLUUID item_id(inv_item->getUUID());
-		md5.update((unsigned char*)item_id.mData, 16);
-		item["description"] = inv_item->getActualDescription();
-		md5.update(inv_item->getActualDescription());
-		item["asset_type"] = inv_item->getActualType();
-		LLUUID linked_id(inv_item->getLinkedUUID());
-		item["linked_id"] = linked_id;
-		md5.update((unsigned char*)linked_id.mData, 16);
-
-		if (LLAssetType::AT_LINK == inv_item->getActualType())
-		{
-			const LLViewerInventoryItem* linked_item = inv_item->getLinkedItem();
-			if (NULL == linked_item)
-			{
-				LL_WARNS() << "Broken link for item '" << inv_item->getName()
-						<< "' (" << inv_item->getUUID()
-						<< ") during requestServerAppearanceUpdate" << LL_ENDL;
-				continue;
-			}
-			// Some assets may be 'hidden' and show up as null in the viewer.
-			//if (linked_item->getAssetUUID().isNull())
-			//{
-			//	LL_WARNS() << "Broken link (null asset) for item '" << inv_item->getName()
-			//			<< "' (" << inv_item->getUUID()
-			//			<< ") during requestServerAppearanceUpdate" << LL_ENDL;
-			//	continue;
-			//}
-			LLUUID linked_asset_id(linked_item->getAssetUUID());
-			md5.update((unsigned char*)linked_asset_id.mData, 16);
-			U32 flags = linked_item->getFlags();
-			md5.update(std::to_string(flags));
-		}
-		else if (LLAssetType::AT_LINK_FOLDER != inv_item->getActualType())
-		{
-			LL_WARNS() << "Non-link item '" << inv_item->getName()
-					<< "' (" << inv_item->getUUID()
-					<< ") type " << (S32) inv_item->getActualType()
-					<< " during requestServerAppearanceUpdate" << LL_ENDL;
-			continue;
-		}
-		links.append(item);
-	}
-	LLSD result = LLSD::emptyMap();
-	result["cof_contents"] = links;
-	char cof_md5sum[MD5HEX_STR_SIZE];
-	md5.finalize();
-	md5.hex_digest(cof_md5sum);
-	result["cof_md5sum"] = std::string(cof_md5sum);
-	return result;
+    LLSD links = LLSD::emptyArray();
+    LLMD5 md5;
+
+    LLInventoryModel::cat_array_t cat_array;
+    LLInventoryModel::item_array_t item_array;
+    gInventory.collectDescendents(getCOF(),cat_array,item_array,LLInventoryModel::EXCLUDE_TRASH);
+    for (S32 i=0; i<item_array.size(); i++)
+    {
+        const LLViewerInventoryItem* inv_item = item_array.at(i).get();
+        LLSD item;
+        LLUUID item_id(inv_item->getUUID());
+        md5.update((unsigned char*)item_id.mData, 16);
+        item["description"] = inv_item->getActualDescription();
+        md5.update(inv_item->getActualDescription());
+        item["asset_type"] = inv_item->getActualType();
+        LLUUID linked_id(inv_item->getLinkedUUID());
+        item["linked_id"] = linked_id;
+        md5.update((unsigned char*)linked_id.mData, 16);
+
+        if (LLAssetType::AT_LINK == inv_item->getActualType())
+        {
+            const LLViewerInventoryItem* linked_item = inv_item->getLinkedItem();
+            if (NULL == linked_item)
+            {
+                LL_WARNS() << "Broken link for item '" << inv_item->getName()
+                        << "' (" << inv_item->getUUID()
+                        << ") during requestServerAppearanceUpdate" << LL_ENDL;
+                continue;
+            }
+            // Some assets may be 'hidden' and show up as null in the viewer.
+            //if (linked_item->getAssetUUID().isNull())
+            //{
+            //  LL_WARNS() << "Broken link (null asset) for item '" << inv_item->getName()
+            //          << "' (" << inv_item->getUUID()
+            //          << ") during requestServerAppearanceUpdate" << LL_ENDL;
+            //  continue;
+            //}
+            LLUUID linked_asset_id(linked_item->getAssetUUID());
+            md5.update((unsigned char*)linked_asset_id.mData, 16);
+            U32 flags = linked_item->getFlags();
+            md5.update(std::to_string(flags));
+        }
+        else if (LLAssetType::AT_LINK_FOLDER != inv_item->getActualType())
+        {
+            LL_WARNS() << "Non-link item '" << inv_item->getName()
+                    << "' (" << inv_item->getUUID()
+                    << ") type " << (S32) inv_item->getActualType()
+                    << " during requestServerAppearanceUpdate" << LL_ENDL;
+            continue;
+        }
+        links.append(item);
+    }
+    LLSD result = LLSD::emptyMap();
+    result["cof_contents"] = links;
+    char cof_md5sum[MD5HEX_STR_SIZE];
+    md5.finalize();
+    md5.hex_digest(cof_md5sum);
+    result["cof_md5sum"] = std::string(cof_md5sum);
+    return result;
 }
 
 void LLAppearanceMgr::cleanup()
@@ -4047,7 +4047,7 @@ void LLAppearanceMgr::serverAppearanceUpdateCoro(LLCoreHttpUtil::HttpCoroutineAd
     bool bRetry;
     do
     {
-        // If we have already received an update for this or higher cof version, 
+        // If we have already received an update for this or higher cof version,
         // put a warning in the log and cancel the request.
         S32 cofVersion = getCOFVersion();
         S32 lastRcv = gAgentAvatarp->mLastUpdateReceivedCOFVersion;
@@ -4119,9 +4119,9 @@ void LLAppearanceMgr::serverAppearanceUpdateCoro(LLCoreHttpUtil::HttpCoroutineAd
             std::string message = (result.has("error")) ? result["error"].asString() : status.toString();
             LL_WARNS("Avatar") << "Appearance Failure. server responded with \"" << message << "\"" << LL_ENDL;
 
-            // We may have requested a bake for a stale COF (especially if the inventory 
-            // is still updating.  If that is the case re send the request with the 
-            // corrected COF version.  (This may also be the case if the viewer is running 
+            // We may have requested a bake for a stale COF (especially if the inventory
+            // is still updating.  If that is the case re send the request with the
+            // corrected COF version.  (This may also be the case if the viewer is running
             // on multiple machines.
             if (result.has("expected"))
             {
@@ -4145,7 +4145,7 @@ void LLAppearanceMgr::serverAppearanceUpdateCoro(LLCoreHttpUtil::HttpCoroutineAd
 
                 LL_WARNS("Avatar") << "Bake retry #" << retryCount << " in " << timeout << " seconds." << LL_ENDL;
 
-                llcoro::suspendUntilTimeout(timeout); 
+                llcoro::suspendUntilTimeout(timeout);
                 if (LLApp::isExiting())
                 {
                     return;
@@ -4173,98 +4173,98 @@ void LLAppearanceMgr::serverAppearanceUpdateCoro(LLCoreHttpUtil::HttpCoroutineAd
 // Bad hack but if the viewer and server COF versions get out of sync all appearance requests will start to fail from that point on and require a relog to fix
 void LLAppearanceMgr::syncCofVersionAndRefresh()
 {
-	LLCoros::instance().launch("syncCofVersionAndRefreshCoro", 
-		boost::bind(&LLAppearanceMgr::syncCofVersionAndRefreshCoro, this));
+    LLCoros::instance().launch("syncCofVersionAndRefreshCoro",
+        boost::bind(&LLAppearanceMgr::syncCofVersionAndRefreshCoro, this));
 }
 
 void LLAppearanceMgr::syncCofVersionAndRefreshCoro()
 {
-	// If we don't have a region, report it as an error
-	if (gAgent.getRegion() == NULL)
-	{
-		LL_WARNS("Avatar") << "Region not set, cannot request cof_version increment" << LL_ENDL;
-		return;
-	}
-
-	std::string url = gAgent.getRegion()->getCapability("IncrementCOFVersion");
-	if (url.empty())
-	{
-		LL_WARNS("Avatar") << "No cap for IncrementCofVersion." << LL_ENDL;
-		return;
-	}
-
-	LL_INFOS("Avatar") << "Requesting cof_version be incremented via capability to: " << url << LL_ENDL;
-
-	LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter(
-		std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("syncCofVersionAndRefreshCoro", LLCore::HttpRequest::DEFAULT_POLICY_ID));
-
-	llcoro::suspend();
-	S32 retryCount(0);
-	bool bRetry;
-	do
-	{
-		// Actually send the request.
-		LL_DEBUGS("Avatar") << "Will send request COF sync" << LL_ENDL;
-
-		bRetry = false;
-	    LLCore::HttpRequest::ptr_t httpRequest(std::make_shared<LLCore::HttpRequest>());
-
-		LLSD result = httpAdapter->getAndSuspend(httpRequest, url);
-
-		LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
-		LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
-
-		if (!status)
-		{
-			std::string message = (result.has("error")) ? result["error"].asString() : status.toString();
-			LL_WARNS("Avatar") << "Appearance Failure. server responded with \"" << message << "\"" << LL_ENDL;
-
-			// Wait for a 1/2 second before trying again.  Just to keep from asking too quickly.
-			if (++retryCount > BAKE_RETRY_MAX_COUNT)
-			{
-				LL_WARNS("Avatar") << "COF increment retry count exceeded!" << LL_ENDL;
-				break;
-			}
-			F32 timeout = pow(BAKE_RETRY_TIMEOUT, static_cast<float>(retryCount)) - 1.0f;
-
-			LL_WARNS("Avatar") << "COF increment retry #" << retryCount << " in " << timeout << " seconds." << LL_ENDL;
-
-			llcoro::suspendUntilTimeout(timeout); 
-			bRetry = true;
-		}
-		else
-		{
-			LL_INFOS("Avatar") << "Successfully incremented agent's COF." << LL_ENDL;
-
-			result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
-
-			if (!result.isMap())
-			{
-				LL_WARNS("Avatar") << "Malformed response contents" << LL_ENDL;
-				bRetry = true;
-				continue;
-			}
-
-			// Slam the server version onto the local version
-			LLViewerInventoryCategory* pCOF = gInventory.getCategory(LLAppearanceMgr::instance().getCOF());
-			if (pCOF)
-			{
-				S32 cofVersion = result["version"].asInteger();
-				LL_INFOS("Avatar") << "Slamming server COF version: was " << pCOF->getVersion() << " now " << cofVersion << LL_ENDL;
-				pCOF->setVersion(cofVersion);
-				llassert(gAgentAvatarp->mLastUpdateReceivedCOFVersion < cofVersion);
-				gAgentAvatarp->mLastUpdateReceivedCOFVersion = cofVersion;
-			}
-
-			// The viewer version tends to be ahead of the server version so make sure our new request doesn't appear to be stale
-			gAgentAvatarp->mLastUpdateRequestCOFVersion = gAgentAvatarp->mLastUpdateReceivedCOFVersion;
-
-		}
-
-	} while (bRetry);
-
-	// Try and request an update even if we fail
-	LLAppearanceMgr::instance().requestServerAppearanceUpdate();
+    // If we don't have a region, report it as an error
+    if (gAgent.getRegion() == NULL)
+    {
+        LL_WARNS("Avatar") << "Region not set, cannot request cof_version increment" << LL_ENDL;
+        return;
+    }
+
+    std::string url = gAgent.getRegion()->getCapability("IncrementCOFVersion");
+    if (url.empty())
+    {
+        LL_WARNS("Avatar") << "No cap for IncrementCofVersion." << LL_ENDL;
+        return;
+    }
+
+    LL_INFOS("Avatar") << "Requesting cof_version be incremented via capability to: " << url << LL_ENDL;
+
+    LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter(
+        std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("syncCofVersionAndRefreshCoro", LLCore::HttpRequest::DEFAULT_POLICY_ID));
+
+    llcoro::suspend();
+    S32 retryCount(0);
+    bool bRetry;
+    do
+    {
+        // Actually send the request.
+        LL_DEBUGS("Avatar") << "Will send request COF sync" << LL_ENDL;
+
+        bRetry = false;
+        LLCore::HttpRequest::ptr_t httpRequest(std::make_shared<LLCore::HttpRequest>());
+
+        LLSD result = httpAdapter->getAndSuspend(httpRequest, url);
+
+        LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+        LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+        if (!status)
+        {
+            std::string message = (result.has("error")) ? result["error"].asString() : status.toString();
+            LL_WARNS("Avatar") << "Appearance Failure. server responded with \"" << message << "\"" << LL_ENDL;
+
+            // Wait for a 1/2 second before trying again.  Just to keep from asking too quickly.
+            if (++retryCount > BAKE_RETRY_MAX_COUNT)
+            {
+                LL_WARNS("Avatar") << "COF increment retry count exceeded!" << LL_ENDL;
+                break;
+            }
+            F32 timeout = pow(BAKE_RETRY_TIMEOUT, static_cast<float>(retryCount)) - 1.0f;
+
+            LL_WARNS("Avatar") << "COF increment retry #" << retryCount << " in " << timeout << " seconds." << LL_ENDL;
+
+            llcoro::suspendUntilTimeout(timeout);
+            bRetry = true;
+        }
+        else
+        {
+            LL_INFOS("Avatar") << "Successfully incremented agent's COF." << LL_ENDL;
+
+            result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS);
+
+            if (!result.isMap())
+            {
+                LL_WARNS("Avatar") << "Malformed response contents" << LL_ENDL;
+                bRetry = true;
+                continue;
+            }
+
+            // Slam the server version onto the local version
+            LLViewerInventoryCategory* pCOF = gInventory.getCategory(LLAppearanceMgr::instance().getCOF());
+            if (pCOF)
+            {
+                S32 cofVersion = result["version"].asInteger();
+                LL_INFOS("Avatar") << "Slamming server COF version: was " << pCOF->getVersion() << " now " << cofVersion << LL_ENDL;
+                pCOF->setVersion(cofVersion);
+                llassert(gAgentAvatarp->mLastUpdateReceivedCOFVersion < cofVersion);
+                gAgentAvatarp->mLastUpdateReceivedCOFVersion = cofVersion;
+            }
+
+            // The viewer version tends to be ahead of the server version so make sure our new request doesn't appear to be stale
+            gAgentAvatarp->mLastUpdateRequestCOFVersion = gAgentAvatarp->mLastUpdateReceivedCOFVersion;
+
+        }
+
+    } while (bRetry);
+
+    // Try and request an update even if we fail
+    LLAppearanceMgr::instance().requestServerAppearanceUpdate();
 }
 // [/SL:KB]
 
@@ -4355,79 +4355,79 @@ void LLAppearanceMgr::debugAppearanceUpdateCOF(const LLSD& content)
 
 std::string LLAppearanceMgr::getAppearanceServiceURL() const
 {
-	if (gSavedSettings.getString("DebugAvatarAppearanceServiceURLOverride").empty())
-	{
-		return mAppearanceServiceURL;
-	}
-	return gSavedSettings.getString("DebugAvatarAppearanceServiceURLOverride");
+    if (gSavedSettings.getString("DebugAvatarAppearanceServiceURLOverride").empty())
+    {
+        return mAppearanceServiceURL;
+    }
+    return gSavedSettings.getString("DebugAvatarAppearanceServiceURLOverride");
 }
 
 void show_created_outfit(LLUUID& folder_id, bool show_panel = true)
 {
-	if (!LLApp::isRunning())
-	{
-		LL_WARNS() << "called during shutdown, skipping" << LL_ENDL;
-		return;
-	}
-	
-	LL_DEBUGS("Avatar") << "called" << LL_ENDL;
-	LLSD key;
-	
-	//EXT-7727. For new accounts inventory callback is created during login process
-	// and may be processed after login process is finished
-	if (show_panel)
-	{
-		LL_DEBUGS("Avatar") << "showing panel" << LL_ENDL;
-		LLFloaterSidePanelContainer::showPanel("appearance", "panel_outfits_inventory", key);
-		
-	}
-	LLOutfitsList *outfits_list =
-		dynamic_cast<LLOutfitsList*>(LLFloaterSidePanelContainer::getPanel("appearance", "outfitslist_tab"));
-	if (outfits_list)
-	{
-		outfits_list->setSelectedOutfitByUUID(folder_id);
-	}
-	
-	LLAppearanceMgr::getInstance()->updateIsDirty();
-	gAgentWearables.notifyLoadingFinished(); // New outfit is saved.
-	LLAppearanceMgr::getInstance()->updatePanelOutfitName("");
-
-	// For SSB, need to update appearance after we add a base outfit
-	// link, since, the COF version has changed. There is a race
-	// condition in initial outfit setup which can lead to rez
-	// failures - SH-3860.
-	LL_DEBUGS("Avatar") << "requesting appearance update after createBaseOutfitLink" << LL_ENDL;
-	LLPointer<LLInventoryCallback> cb = new LLUpdateAppearanceOnDestroy;
-	LLAppearanceMgr::getInstance()->createBaseOutfitLink(folder_id, cb);
+    if (!LLApp::isRunning())
+    {
+        LL_WARNS() << "called during shutdown, skipping" << LL_ENDL;
+        return;
+    }
+
+    LL_DEBUGS("Avatar") << "called" << LL_ENDL;
+    LLSD key;
+
+    //EXT-7727. For new accounts inventory callback is created during login process
+    // and may be processed after login process is finished
+    if (show_panel)
+    {
+        LL_DEBUGS("Avatar") << "showing panel" << LL_ENDL;
+        LLFloaterSidePanelContainer::showPanel("appearance", "panel_outfits_inventory", key);
+
+    }
+    LLOutfitsList *outfits_list =
+        dynamic_cast<LLOutfitsList*>(LLFloaterSidePanelContainer::getPanel("appearance", "outfitslist_tab"));
+    if (outfits_list)
+    {
+        outfits_list->setSelectedOutfitByUUID(folder_id);
+    }
+
+    LLAppearanceMgr::getInstance()->updateIsDirty();
+    gAgentWearables.notifyLoadingFinished(); // New outfit is saved.
+    LLAppearanceMgr::getInstance()->updatePanelOutfitName("");
+
+    // For SSB, need to update appearance after we add a base outfit
+    // link, since, the COF version has changed. There is a race
+    // condition in initial outfit setup which can lead to rez
+    // failures - SH-3860.
+    LL_DEBUGS("Avatar") << "requesting appearance update after createBaseOutfitLink" << LL_ENDL;
+    LLPointer<LLInventoryCallback> cb = new LLUpdateAppearanceOnDestroy;
+    LLAppearanceMgr::getInstance()->createBaseOutfitLink(folder_id, cb);
 }
 
 void LLAppearanceMgr::onOutfitFolderCreated(const LLUUID& folder_id, bool show_panel)
 {
-	LLPointer<LLInventoryCallback> cb =
-		new LLBoostFuncInventoryCallback(no_op_inventory_func,
-										 boost::bind(&LLAppearanceMgr::onOutfitFolderCreatedAndClothingOrdered,this,folder_id,show_panel));
-	updateClothingOrderingInfo(LLUUID::null, cb);
+    LLPointer<LLInventoryCallback> cb =
+        new LLBoostFuncInventoryCallback(no_op_inventory_func,
+                                         boost::bind(&LLAppearanceMgr::onOutfitFolderCreatedAndClothingOrdered,this,folder_id,show_panel));
+    updateClothingOrderingInfo(LLUUID::null, cb);
 }
 
 void LLAppearanceMgr::onOutfitFolderCreatedAndClothingOrdered(const LLUUID& folder_id, bool show_panel)
 {
-	LLPointer<LLInventoryCallback> cb =
-		new LLBoostFuncInventoryCallback(no_op_inventory_func,
-										 boost::bind(show_created_outfit,folder_id,show_panel));
-	bool copy_folder_links = false;
-	slamCategoryLinks(getCOF(), folder_id, copy_folder_links, cb);
+    LLPointer<LLInventoryCallback> cb =
+        new LLBoostFuncInventoryCallback(no_op_inventory_func,
+                                         boost::bind(show_created_outfit,folder_id,show_panel));
+    bool copy_folder_links = false;
+    slamCategoryLinks(getCOF(), folder_id, copy_folder_links, cb);
 }
 
 void LLAppearanceMgr::makeNewOutfitLinks(const std::string& new_folder_name, bool show_panel)
 {
-	if (!isAgentAvatarValid()) return;
+    if (!isAgentAvatarValid()) return;
 
-	LL_DEBUGS("Avatar") << "creating new outfit" << LL_ENDL;
+    LL_DEBUGS("Avatar") << "creating new outfit" << LL_ENDL;
 
-	gAgentWearables.notifyLoadingStarted();
+    gAgentWearables.notifyLoadingStarted();
 
-	// First, make a folder in the My Outfits directory.
-	const LLUUID parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MY_OUTFITS);
+    // First, make a folder in the My Outfits directory.
+    const LLUUID parent_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MY_OUTFITS);
 
     gInventory.createNewCategory(
         parent_id,
@@ -4441,10 +4441,10 @@ void LLAppearanceMgr::makeNewOutfitLinks(const std::string& new_folder_name, boo
 
 void LLAppearanceMgr::wearBaseOutfit()
 {
-	const LLUUID& base_outfit_id = getBaseOutfitUUID();
-	if (base_outfit_id.isNull()) return;
-	
-	updateCOF(base_outfit_id);
+    const LLUUID& base_outfit_id = getBaseOutfitUUID();
+    if (base_outfit_id.isNull()) return;
+
+    updateCOF(base_outfit_id);
 }
 
 //void LLAppearanceMgr::removeItemsFromAvatar(const uuid_vec_t& ids_to_remove, nullary_func_t post_update_func)
@@ -4452,56 +4452,56 @@ void LLAppearanceMgr::wearBaseOutfit()
 void LLAppearanceMgr::removeItemsFromAvatar(const uuid_vec_t& ids_to_remove, nullary_func_t post_update_func, LLPointer<LLInventoryCallback> cb /*= NULL*/, bool immediate_delete /*= false*/)
 // [/SL:KB]
 {
-	if (ids_to_remove.empty())
-	{
-		LL_WARNS() << "called with empty list, nothing to do" << LL_ENDL;
-		return;
-	}
+    if (ids_to_remove.empty())
+    {
+        LL_WARNS() << "called with empty list, nothing to do" << LL_ENDL;
+        return;
+    }
 // [RLVa:KB] - Checked: 2013-02-12 (RLVa-1.4.8)
 //    LLPointer<LLInventoryCallback> cb = new LLUpdateAppearanceOnDestroy(true, true, post_update_func);
-	for (uuid_vec_t::const_iterator it = ids_to_remove.begin(); it != ids_to_remove.end(); ++it)
-	{
-		const LLUUID& id_to_remove = *it;
-		const LLUUID& linked_item_id = gInventory.getLinkedItemID(id_to_remove);
-
-		if ( (rlv_handler_t::isEnabled()) && (!rlvPredCanRemoveItem(linked_item_id)) )
-		{
-			continue;
-		}
-
-		LLViewerInventoryItem *item = gInventory.getItem(linked_item_id);
-		if (item && item->getType() == LLAssetType::AT_OBJECT)
-		{
-			LL_DEBUGS("Avatar") << "ATT removing attachment " << item->getName() << " id " << item->getUUID() << LL_ENDL;
-		}
-		if (item && item->getType() == LLAssetType::AT_BODYPART)
-		{
-		    continue;
-		}
-
-		if (!cb)
+    for (uuid_vec_t::const_iterator it = ids_to_remove.begin(); it != ids_to_remove.end(); ++it)
+    {
+        const LLUUID& id_to_remove = *it;
+        const LLUUID& linked_item_id = gInventory.getLinkedItemID(id_to_remove);
+
+        if ( (rlv_handler_t::isEnabled()) && (!rlvPredCanRemoveItem(linked_item_id)) )
+        {
+            continue;
+        }
+
+        LLViewerInventoryItem *item = gInventory.getItem(linked_item_id);
+        if (item && item->getType() == LLAssetType::AT_OBJECT)
+        {
+            LL_DEBUGS("Avatar") << "ATT removing attachment " << item->getName() << " id " << item->getUUID() << LL_ENDL;
+        }
+        if (item && item->getType() == LLAssetType::AT_BODYPART)
+        {
+            continue;
+        }
+
+        if (!cb)
             cb = new LLUpdateAppearanceOnDestroy(true, true, post_update_func);
-		removeCOFItemLinks(linked_item_id, cb, immediate_delete);
-		addDoomedTempAttachment(linked_item_id);
-	}
+        removeCOFItemLinks(linked_item_id, cb, immediate_delete);
+        addDoomedTempAttachment(linked_item_id);
+    }
 // [/RLVa:KB]
-////	LLPointer<LLInventoryCallback> cb = new LLUpdateAppearanceOnDestroy;
+////    LLPointer<LLInventoryCallback> cb = new LLUpdateAppearanceOnDestroy;
 //// [SL:KB] - Patch: Appearance-Misc | Checked: 2015-05-05 (Catznip-3.7)
-//	if (!cb)
-//	{
-//		cb = new LLUpdateAppearanceOnDestroy;
-//	}
+//  if (!cb)
+//  {
+//      cb = new LLUpdateAppearanceOnDestroy;
+//  }
 //// [/SL:KB]
-//	for (uuid_vec_t::const_iterator it = ids_to_remove.begin(); it != ids_to_remove.end(); ++it)
-//	{
-//		const LLUUID& id_to_remove = *it;
-//		const LLUUID& linked_item_id = gInventory.getLinkedItemID(id_to_remove);
+//  for (uuid_vec_t::const_iterator it = ids_to_remove.begin(); it != ids_to_remove.end(); ++it)
+//  {
+//      const LLUUID& id_to_remove = *it;
+//      const LLUUID& linked_item_id = gInventory.getLinkedItemID(id_to_remove);
 //// [SL:KB] - Patch: Appearance-Misc | Checked: 2015-05-05 (Catznip-3.7)
-//		removeCOFItemLinks(linked_item_id, cb, immediate_delete);
+//      removeCOFItemLinks(linked_item_id, cb, immediate_delete);
 //// [/SL:KB]
-////		removeCOFItemLinks(linked_item_id, cb);
-//		addDoomedTempAttachment(linked_item_id);
-//	}
+////        removeCOFItemLinks(linked_item_id, cb);
+//      addDoomedTempAttachment(linked_item_id);
+//  }
 }
 
 //void LLAppearanceMgr::removeItemFromAvatar(const LLUUID& id_to_remove, nullary_func_t post_update_func)
@@ -4509,8 +4509,8 @@ void LLAppearanceMgr::removeItemsFromAvatar(const uuid_vec_t& ids_to_remove, nul
 void LLAppearanceMgr::removeItemFromAvatar(const LLUUID& id_to_remove, nullary_func_t post_update_func, LLPointer<LLInventoryCallback> cb /*= NULL*/, bool immediate_delete /*= false*/)
 // [/SL:KB]
 {
-	uuid_vec_t ids_to_remove;
-	ids_to_remove.push_back(id_to_remove);
+    uuid_vec_t ids_to_remove;
+    ids_to_remove.push_back(id_to_remove);
 // [SL:KB] - Patch: Appearance-Misc | Checked: 2015-05-05 (Catznip-3.7)
     removeItemsFromAvatar(ids_to_remove, post_update_func, cb, immediate_delete);
 // [/SL:KB]
@@ -4521,172 +4521,172 @@ void LLAppearanceMgr::removeItemFromAvatar(const LLUUID& id_to_remove, nullary_f
 // Adds the given item ID to mDoomedTempAttachmentIDs iff it's a temp attachment
 void LLAppearanceMgr::addDoomedTempAttachment(const LLUUID& id_to_remove)
 {
-	LLViewerObject * attachmentp = gAgentAvatarp->findAttachmentByID(id_to_remove);
-	if (attachmentp &&
-		attachmentp->isTempAttachment())
-	{	// If this is a temp attachment and we want to remove it, record the ID 
-		// so it will be deleted when attachments are synced up with COF
-		mDoomedTempAttachmentIDs.insert(id_to_remove);
-		//LL_INFOS() << "Will remove temp attachment id " << id_to_remove << LL_ENDL;
-	}
+    LLViewerObject * attachmentp = gAgentAvatarp->findAttachmentByID(id_to_remove);
+    if (attachmentp &&
+        attachmentp->isTempAttachment())
+    {   // If this is a temp attachment and we want to remove it, record the ID
+        // so it will be deleted when attachments are synced up with COF
+        mDoomedTempAttachmentIDs.insert(id_to_remove);
+        //LL_INFOS() << "Will remove temp attachment id " << id_to_remove << LL_ENDL;
+    }
 }
 
 // Find AND REMOVES the given UUID from mDoomedTempAttachmentIDs
 bool LLAppearanceMgr::shouldRemoveTempAttachment(const LLUUID& item_id)
 {
-	doomed_temp_attachments_t::iterator iter = mDoomedTempAttachmentIDs.find(item_id);
-	if (iter != mDoomedTempAttachmentIDs.end())
-	{
-		mDoomedTempAttachmentIDs.erase(iter);
-		return true;
-	}
-	return false;
+    doomed_temp_attachments_t::iterator iter = mDoomedTempAttachmentIDs.find(item_id);
+    if (iter != mDoomedTempAttachmentIDs.end())
+    {
+        mDoomedTempAttachmentIDs.erase(iter);
+        return true;
+    }
+    return false;
 }
 
 
 bool LLAppearanceMgr::moveWearable(LLViewerInventoryItem* item, bool closer_to_body)
 {
-	if (!item || !item->isWearableType()) return false;
-	if (item->getType() != LLAssetType::AT_CLOTHING) return false;
-	if (!gInventory.isObjectDescendentOf(item->getUUID(), getCOF())) return false;
+    if (!item || !item->isWearableType()) return false;
+    if (item->getType() != LLAssetType::AT_CLOTHING) return false;
+    if (!gInventory.isObjectDescendentOf(item->getUUID(), getCOF())) return false;
 
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	LLFindWearablesOfType filter_wearables_of_type(item->getWearableType());
-	gInventory.collectDescendentsIf(getCOF(), cats, items, true, filter_wearables_of_type);
-	if (items.empty()) return false;
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    LLFindWearablesOfType filter_wearables_of_type(item->getWearableType());
+    gInventory.collectDescendentsIf(getCOF(), cats, items, true, filter_wearables_of_type);
+    if (items.empty()) return false;
 
-	// We assume that the items have valid descriptions.
-	std::sort(items.begin(), items.end(), WearablesOrderComparator(item->getWearableType()));
+    // We assume that the items have valid descriptions.
+    std::sort(items.begin(), items.end(), WearablesOrderComparator(item->getWearableType()));
 
-	if (closer_to_body && items.front() == item) return false;
-	if (!closer_to_body && items.back() == item) return false;
-	
-	LLInventoryModel::item_array_t::iterator it = std::find(items.begin(), items.end(), item);
-	if (items.end() == it) return false;
+    if (closer_to_body && items.front() == item) return false;
+    if (!closer_to_body && items.back() == item) return false;
 
+    LLInventoryModel::item_array_t::iterator it = std::find(items.begin(), items.end(), item);
+    if (items.end() == it) return false;
 
-	//swapping descriptions
-	closer_to_body ? --it : ++it;
-	LLViewerInventoryItem* swap_item = *it;
-	if (!swap_item) return false;
-	std::string tmp = swap_item->getActualDescription();
-	swap_item->setDescription(item->getActualDescription());
-	item->setDescription(tmp);
 
-	// LL_DEBUGS("Inventory") << "swap, item "
-	// 					   << ll_pretty_print_sd(item->asLLSD())
-	// 					   << " swap_item "
-	// 					   << ll_pretty_print_sd(swap_item->asLLSD()) << LL_ENDL;
+    //swapping descriptions
+    closer_to_body ? --it : ++it;
+    LLViewerInventoryItem* swap_item = *it;
+    if (!swap_item) return false;
+    std::string tmp = swap_item->getActualDescription();
+    swap_item->setDescription(item->getActualDescription());
+    item->setDescription(tmp);
 
-	// FIXME switch to use AISv3 where supported.
-	//items need to be updated on a dataserver
-	item->setComplete(TRUE);
-	item->updateServer(FALSE);
-	gInventory.updateItem(item);
+    // LL_DEBUGS("Inventory") << "swap, item "
+    //                     << ll_pretty_print_sd(item->asLLSD())
+    //                     << " swap_item "
+    //                     << ll_pretty_print_sd(swap_item->asLLSD()) << LL_ENDL;
 
-	swap_item->setComplete(TRUE);
-	swap_item->updateServer(FALSE);
-	gInventory.updateItem(swap_item);
+    // FIXME switch to use AISv3 where supported.
+    //items need to be updated on a dataserver
+    item->setComplete(TRUE);
+    item->updateServer(FALSE);
+    gInventory.updateItem(item);
 
-	//to cause appearance of the agent to be updated
-	bool result = false;
-	if ((result = gAgentWearables.moveWearable(item, closer_to_body)))
-	{
-		gAgentAvatarp->wearableUpdated(item->getWearableType());
-	}
+    swap_item->setComplete(TRUE);
+    swap_item->updateServer(FALSE);
+    gInventory.updateItem(swap_item);
 
-	setOutfitDirty(true);
+    //to cause appearance of the agent to be updated
+    bool result = false;
+    if ((result = gAgentWearables.moveWearable(item, closer_to_body)))
+    {
+        gAgentAvatarp->wearableUpdated(item->getWearableType());
+    }
 
-	//*TODO do we need to notify observers here in such a way?
-	gInventory.notifyObservers();
+    setOutfitDirty(true);
 
-	return result;
+    //*TODO do we need to notify observers here in such a way?
+    gInventory.notifyObservers();
+
+    return result;
 }
 
 //static
 void LLAppearanceMgr::sortItemsByActualDescription(LLInventoryModel::item_array_t& items)
 {
-	if (items.size() < 2) return;
+    if (items.size() < 2) return;
 
-	std::sort(items.begin(), items.end(), sort_by_actual_description);
+    std::sort(items.begin(), items.end(), sort_by_actual_description);
 }
 
 //#define DUMP_CAT_VERBOSE
 
 void LLAppearanceMgr::dumpCat(const LLUUID& cat_id, const std::string& msg)
 {
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	gInventory.collectDescendents(cat_id, cats, items, LLInventoryModel::EXCLUDE_TRASH);
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    gInventory.collectDescendents(cat_id, cats, items, LLInventoryModel::EXCLUDE_TRASH);
 
 #ifdef DUMP_CAT_VERBOSE
-	LL_INFOS() << LL_ENDL;
-	LL_INFOS() << str << LL_ENDL;
-	S32 hitcount = 0;
-	for(S32 i=0; i<items.size(); i++)
-	{
-		LLViewerInventoryItem *item = items.get(i);
-		if (item)
-			hitcount++;
-		LL_INFOS() << i <<" "<< item->getName() <<LL_ENDL;
-	}
+    LL_INFOS() << LL_ENDL;
+    LL_INFOS() << str << LL_ENDL;
+    S32 hitcount = 0;
+    for(S32 i=0; i<items.size(); i++)
+    {
+        LLViewerInventoryItem *item = items.get(i);
+        if (item)
+            hitcount++;
+        LL_INFOS() << i <<" "<< item->getName() <<LL_ENDL;
+    }
 #endif
-	LL_INFOS() << msg << " count " << items.size() << LL_ENDL;
+    LL_INFOS() << msg << " count " << items.size() << LL_ENDL;
 }
 
 void LLAppearanceMgr::dumpItemArray(const LLInventoryModel::item_array_t& items,
-									const std::string& msg)
+                                    const std::string& msg)
 {
-	for (S32 i=0; i<items.size(); i++)
-	{
-		LLViewerInventoryItem *item = items.at(i);
-		LLViewerInventoryItem *linked_item = item ? item->getLinkedItem() : NULL;
-		LLUUID asset_id;
-		if (linked_item)
-		{
-			asset_id = linked_item->getAssetUUID();
-		}
-		LL_DEBUGS("Avatar") << self_av_string() << msg << " " << i <<" " << (item ? item->getName() : "(nullitem)") << " " << asset_id.asString() << LL_ENDL;
-	}
+    for (S32 i=0; i<items.size(); i++)
+    {
+        LLViewerInventoryItem *item = items.at(i);
+        LLViewerInventoryItem *linked_item = item ? item->getLinkedItem() : NULL;
+        LLUUID asset_id;
+        if (linked_item)
+        {
+            asset_id = linked_item->getAssetUUID();
+        }
+        LL_DEBUGS("Avatar") << self_av_string() << msg << " " << i <<" " << (item ? item->getName() : "(nullitem)") << " " << asset_id.asString() << LL_ENDL;
+    }
 }
 
 bool LLAppearanceMgr::mActive = true;
 
 LLAppearanceMgr::LLAppearanceMgr():
-	mAttachmentInvLinkEnabled(false),
-	mOutfitIsDirty(false),
-	mOutfitLocked(false),
-	mInFlightTimer(),
-	mIsInUpdateAppearanceFromCOF(false),
+    mAttachmentInvLinkEnabled(false),
+    mOutfitIsDirty(false),
+    mOutfitLocked(false),
+    mInFlightTimer(),
+    mIsInUpdateAppearanceFromCOF(false),
     mOutstandingAppearanceBakeRequest(false),
     mRerequestAppearanceBake(false)
 {
-	LLOutfitObserver& outfit_observer = LLOutfitObserver::instance();
-	// unlock outfit on save operation completed
-	outfit_observer.addCOFSavedCallback(boost::bind(
-			&LLAppearanceMgr::setOutfitLocked, this, false));
+    LLOutfitObserver& outfit_observer = LLOutfitObserver::instance();
+    // unlock outfit on save operation completed
+    outfit_observer.addCOFSavedCallback(boost::bind(
+            &LLAppearanceMgr::setOutfitLocked, this, false));
 
-	mUnlockOutfitTimer.reset(new LLOutfitUnLockTimer(gSavedSettings.getS32(
-			"OutfitOperationsTimeout")));
+    mUnlockOutfitTimer.reset(new LLOutfitUnLockTimer(gSavedSettings.getS32(
+            "OutfitOperationsTimeout")));
 
-	gIdleCallbacks.addFunction(&LLAttachmentsMgr::onIdle, NULL);
-	gIdleCallbacks.addFunction(&LLAppearanceMgr::onIdle, NULL); //sheduling appearance update requests
+    gIdleCallbacks.addFunction(&LLAttachmentsMgr::onIdle, NULL);
+    gIdleCallbacks.addFunction(&LLAppearanceMgr::onIdle, NULL); //sheduling appearance update requests
 }
 
 LLAppearanceMgr::~LLAppearanceMgr()
 {
-	mActive = false;
+    mActive = false;
 }
 
 void LLAppearanceMgr::setAttachmentInvLinkEnable(bool val)
 {
-	LL_DEBUGS("Avatar") << "setAttachmentInvLinkEnable => " << (int) val << LL_ENDL;
-	mAttachmentInvLinkEnabled = val;
+    LL_DEBUGS("Avatar") << "setAttachmentInvLinkEnable => " << (int) val << LL_ENDL;
+    mAttachmentInvLinkEnabled = val;
 }
 boost::signals2::connection LLAppearanceMgr::setAttachmentsChangedCallback(attachments_changed_callback_t cb)
 {
-	return mAttachmentsChangeSignal.connect(cb);
+    return mAttachmentsChangeSignal.connect(cb);
 }
 
 void dumpAttachmentSet(const std::set<LLUUID>& atts, const std::string& msg)
@@ -4708,47 +4708,47 @@ void dumpAttachmentSet(const std::set<LLUUID>& atts, const std::string& msg)
 
 void LLAppearanceMgr::registerAttachment(const LLUUID& item_id)
 {
-	LLViewerInventoryItem *item = gInventory.getItem(item_id);
-	LL_DEBUGS("Avatar") << "ATT registering attachment "
-						<< (item ? item->getName() : "UNKNOWN") << " " << item_id << LL_ENDL;
-	gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
+    LLViewerInventoryItem *item = gInventory.getItem(item_id);
+    LL_DEBUGS("Avatar") << "ATT registering attachment "
+                        << (item ? item->getName() : "UNKNOWN") << " " << item_id << LL_ENDL;
+    gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
 
-	LLAttachmentsMgr::instance().onAttachmentArrived(item_id);
+    LLAttachmentsMgr::instance().onAttachmentArrived(item_id);
 
-	mAttachmentsChangeSignal();
+    mAttachmentsChangeSignal();
 }
 
 void LLAppearanceMgr::unregisterAttachment(const LLUUID& item_id)
 {
-	LLViewerInventoryItem *item = gInventory.getItem(item_id);
-	LL_DEBUGS("Avatar") << "ATT unregistering attachment "
-						<< (item ? item->getName() : "UNKNOWN") << " " << item_id << LL_ENDL;
-	gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
+    LLViewerInventoryItem *item = gInventory.getItem(item_id);
+    LL_DEBUGS("Avatar") << "ATT unregistering attachment "
+                        << (item ? item->getName() : "UNKNOWN") << " " << item_id << LL_ENDL;
+    gInventory.addChangedMask(LLInventoryObserver::LABEL, item_id);
 
     LLAttachmentsMgr::instance().onDetachCompleted(item_id);
-	if (mAttachmentInvLinkEnabled && isLinkedInCOF(item_id))
-	{
-		LL_DEBUGS("Avatar") << "ATT removing COF link for attachment "
-							<< (item ? item->getName() : "UNKNOWN") << " " << item_id << LL_ENDL;
-		LLAppearanceMgr::removeCOFItemLinks(item_id);
-	}
-	else
-	{
-		//LL_INFOS() << "no link changes, inv link not enabled" << LL_ENDL;
-	}
+    if (mAttachmentInvLinkEnabled && isLinkedInCOF(item_id))
+    {
+        LL_DEBUGS("Avatar") << "ATT removing COF link for attachment "
+                            << (item ? item->getName() : "UNKNOWN") << " " << item_id << LL_ENDL;
+        LLAppearanceMgr::removeCOFItemLinks(item_id);
+    }
+    else
+    {
+        //LL_INFOS() << "no link changes, inv link not enabled" << LL_ENDL;
+    }
 
-	mAttachmentsChangeSignal();
+    mAttachmentsChangeSignal();
 }
 
 BOOL LLAppearanceMgr::getIsInCOF(const LLUUID& obj_id) const
 {
-	const LLUUID& cof = getCOF();
-	if (obj_id == cof)
-		return TRUE;
-	const LLInventoryObject* obj = gInventory.getObject(obj_id);
-	if (obj && obj->getParentUUID() == cof)
-		return TRUE;
-	return FALSE;
+    const LLUUID& cof = getCOF();
+    if (obj_id == cof)
+        return TRUE;
+    const LLInventoryObject* obj = gInventory.getObject(obj_id);
+    if (obj && obj->getParentUUID() == cof)
+        return TRUE;
+    return FALSE;
 }
 
 bool LLAppearanceMgr::getIsInCOF(const LLInventoryObject* obj) const
@@ -4765,15 +4765,15 @@ bool LLAppearanceMgr::getIsProtectedCOFItem(const LLUUID& obj_id) const
 {
     if (!getIsInCOF(obj_id)) return false;
 
-	// If a non-link somehow ended up in COF, allow deletion.
-	const LLInventoryObject *obj = gInventory.getObject(obj_id);
-	if (obj && !obj->getIsLinkType())
-	{
+    // If a non-link somehow ended up in COF, allow deletion.
+    const LLInventoryObject *obj = gInventory.getObject(obj_id);
+    if (obj && !obj->getIsLinkType())
+    {
         return false;
-	}
+    }
 
-	// For now, don't allow direct deletion from the COF.  Instead, force users
-	// to choose "Detach" or "Take Off".
+    // For now, don't allow direct deletion from the COF.  Instead, force users
+    // to choose "Detach" or "Take Off".
     return true;
 }
 
@@ -4795,39 +4795,39 @@ bool LLAppearanceMgr::getIsProtectedCOFItem(const LLInventoryObject* obj) const
 class CallAfterCategoryFetchStage2: public LLInventoryFetchItemsObserver
 {
 public:
-	CallAfterCategoryFetchStage2(const uuid_vec_t& ids,
-								 nullary_func_t callable) :
-		LLInventoryFetchItemsObserver(ids),
-		mCallable(callable)
-	{
-	}
-	~CallAfterCategoryFetchStage2()
-	{
-	}
-	virtual void done()
-	{
-		LL_INFOS() << this << " done with incomplete " << mIncomplete.size()
-				<< " complete " << mComplete.size() <<  " calling callable" << LL_ENDL;
-
-		gInventory.removeObserver(this);
-		doOnIdleOneTime(mCallable);
-		delete this;
-	}
+    CallAfterCategoryFetchStage2(const uuid_vec_t& ids,
+                                 nullary_func_t callable) :
+        LLInventoryFetchItemsObserver(ids),
+        mCallable(callable)
+    {
+    }
+    ~CallAfterCategoryFetchStage2()
+    {
+    }
+    virtual void done()
+    {
+        LL_INFOS() << this << " done with incomplete " << mIncomplete.size()
+                << " complete " << mComplete.size() <<  " calling callable" << LL_ENDL;
+
+        gInventory.removeObserver(this);
+        doOnIdleOneTime(mCallable);
+        delete this;
+    }
 protected:
-	nullary_func_t mCallable;
+    nullary_func_t mCallable;
 };
 
 class CallAfterCategoryFetchStage1: public LLInventoryFetchDescendentsObserver
 {
 public:
-	CallAfterCategoryFetchStage1(const LLUUID& cat_id, nullary_func_t callable) :
-		LLInventoryFetchDescendentsObserver(cat_id),
-		mCallable(callable)
-	{
-	}
-	~CallAfterCategoryFetchStage1()
-	{
-	}
+    CallAfterCategoryFetchStage1(const LLUUID& cat_id, nullary_func_t callable) :
+        LLInventoryFetchDescendentsObserver(cat_id),
+        mCallable(callable)
+    {
+    }
+    ~CallAfterCategoryFetchStage1()
+    {
+    }
     /*virtual*/ void startFetch()
     {
         bool ais3 = AISAPI::isAvailable();
@@ -4842,8 +4842,8 @@ class CallAfterCategoryFetchStage1: public LLInventoryFetchDescendentsObserver
                 // as result fetch won't start and folder will potentially get stuck as
                 // incomplete in observer.
                 // Likely either both should use only version or both should check descendants.
-                cat->fetch();		//blindly fetch it without seeing if anything else is fetching it.
-                mIncomplete.push_back(*it);	//Add to list of things being downloaded for this observer.
+                cat->fetch();       //blindly fetch it without seeing if anything else is fetching it.
+                mIncomplete.push_back(*it); //Add to list of things being downloaded for this observer.
             }
             else if (!isCategoryComplete(cat))
             {
@@ -4895,8 +4895,8 @@ class CallAfterCategoryFetchStage1: public LLInventoryFetchDescendentsObserver
             }
         }
     }
-	virtual void done()
-	{
+    virtual void done()
+    {
         if (mComplete.empty())
         {
             // Ex: timeout
@@ -4909,54 +4909,54 @@ class CallAfterCategoryFetchStage1: public LLInventoryFetchDescendentsObserver
         }
 
 
-		// What we do here is get the complete information on the
-		// items in the requested category, and set up an observer
-		// that will wait for that to happen.
+        // What we do here is get the complete information on the
+        // items in the requested category, and set up an observer
+        // that will wait for that to happen.
         LLInventoryModel::cat_array_t* cats;
         LLInventoryModel::item_array_t* items;
         gInventory.getDirectDescendentsOf(mComplete.front(), cats, items);
 
-		S32 count = items->size();
-		if(!count)
-		{
-			LL_WARNS() << "Nothing fetched in category " << mComplete.front()
-					<< LL_ENDL;
-			gInventory.removeObserver(this);
-			doOnIdleOneTime(mCallable);
+        S32 count = items->size();
+        if(!count)
+        {
+            LL_WARNS() << "Nothing fetched in category " << mComplete.front()
+                    << LL_ENDL;
+            gInventory.removeObserver(this);
+            doOnIdleOneTime(mCallable);
 
-			delete this;
-			return;
-		}
+            delete this;
+            return;
+        }
 
         LLViewerInventoryCategory* cat = gInventory.getCategory(mComplete.front());
         S32 version = cat ? cat->getVersion() : -2;
-		LL_INFOS() << "stage1, category " << mComplete.front() << " got " << count << " items, version " << version << " passing to stage2 " << LL_ENDL;
-		uuid_vec_t ids;
-		for(S32 i = 0; i < count; ++i)
-		{
-			ids.push_back(items->at(i)->getUUID());
-		}
-		
-		gInventory.removeObserver(this);
-		
-		// do the fetch
-		CallAfterCategoryFetchStage2 *stage2 = new CallAfterCategoryFetchStage2(ids, mCallable);
-		stage2->startFetch();
-		if(stage2->isFinished())
-		{
-			// everything is already here - call done.
-			stage2->done();
-		}
-		else
-		{
-			// it's all on it's way - add an observer, and the inventory
-			// will call done for us when everything is here.
-			gInventory.addObserver(stage2);
-		}
-		delete this;
-	}
+        LL_INFOS() << "stage1, category " << mComplete.front() << " got " << count << " items, version " << version << " passing to stage2 " << LL_ENDL;
+        uuid_vec_t ids;
+        for(S32 i = 0; i < count; ++i)
+        {
+            ids.push_back(items->at(i)->getUUID());
+        }
+
+        gInventory.removeObserver(this);
+
+        // do the fetch
+        CallAfterCategoryFetchStage2 *stage2 = new CallAfterCategoryFetchStage2(ids, mCallable);
+        stage2->startFetch();
+        if(stage2->isFinished())
+        {
+            // everything is already here - call done.
+            stage2->done();
+        }
+        else
+        {
+            // it's all on it's way - add an observer, and the inventory
+            // will call done for us when everything is here.
+            gInventory.addObserver(stage2);
+        }
+        delete this;
+    }
 protected:
-	nullary_func_t mCallable;
+    nullary_func_t mCallable;
 };
 
 void callAfterCOFFetch(nullary_func_t cb)
@@ -5006,7 +5006,7 @@ void callAfterCategoryLinksFetch(const LLUUID &cat_id, nullary_func_t cb)
         LL_WARNS() << "AIS API v3 not available, can't use AISAPI::FetchCOF" << LL_ENDL;
         callAfterCategoryFetch(cat_id, cb);
     }
-    
+
 }
 
 void add_wearable_type_counts(const uuid_vec_t& ids,
@@ -5058,7 +5058,7 @@ void wear_multiple(const uuid_vec_t& ids, bool replace)
     {
         cb = new LLUpdateAppearanceOnDestroy;
     }
-	LLAppearanceMgr::instance().wearItemsOnAvatar(ids, true, replace, cb);
+    LLAppearanceMgr::instance().wearItemsOnAvatar(ids, true, replace, cb);
 }
 
 // SLapp for easy-wearing of a stock (library) avatar
@@ -5066,49 +5066,49 @@ void wear_multiple(const uuid_vec_t& ids, bool replace)
 class LLWearFolderHandler : public LLCommandHandler
 {
 public:
-	// not allowed from outside the app
-	LLWearFolderHandler() : LLCommandHandler("wear_folder", UNTRUSTED_BLOCK) { }
+    // not allowed from outside the app
+    LLWearFolderHandler() : LLCommandHandler("wear_folder", UNTRUSTED_BLOCK) { }
 
-	bool handle(const LLSD& tokens,
+    bool handle(const LLSD& tokens,
                 const LLSD& query_map,
                 const std::string& grid,
                 LLMediaCtrl* web)
-	{
-		LLSD::UUID folder_uuid;
-
-		if (folder_uuid.isNull() && query_map.has("folder_name"))
-		{
-			std::string outfit_folder_name = query_map["folder_name"];
-			folder_uuid = findDescendentCategoryIDByName(
-				gInventory.getLibraryRootFolderID(),
-				outfit_folder_name);	
-		}
-		if (folder_uuid.isNull() && query_map.has("folder_id"))
-		{
-			folder_uuid = query_map["folder_id"].asUUID();
-		}
-		
-		if (folder_uuid.notNull())
-		{
-			LLPointer<LLInventoryCategory> category = new LLInventoryCategory(folder_uuid,
-																			  LLUUID::null,
-																			  LLFolderType::FT_CLOTHING,
-																			  "Quick Appearance");
-			if ( gInventory.getCategory( folder_uuid ) != NULL )
-			{
-				// Assume this is coming from the predefined avatars web floater
-				LLAppearanceMgr::getInstance()->wearInventoryCategory(category, true, false);
-				
-				// *TODOw: This may not be necessary if initial outfit is chosen already -- josh
-				gAgent.setOutfitChosen(TRUE);
-			}
-		}
-
-		// release avatar picker keyboard focus
-		gFocusMgr.setKeyboardFocus( NULL );
-
-		return true;
-	}
+    {
+        LLSD::UUID folder_uuid;
+
+        if (folder_uuid.isNull() && query_map.has("folder_name"))
+        {
+            std::string outfit_folder_name = query_map["folder_name"];
+            folder_uuid = findDescendentCategoryIDByName(
+                gInventory.getLibraryRootFolderID(),
+                outfit_folder_name);
+        }
+        if (folder_uuid.isNull() && query_map.has("folder_id"))
+        {
+            folder_uuid = query_map["folder_id"].asUUID();
+        }
+
+        if (folder_uuid.notNull())
+        {
+            LLPointer<LLInventoryCategory> category = new LLInventoryCategory(folder_uuid,
+                                                                              LLUUID::null,
+                                                                              LLFolderType::FT_CLOTHING,
+                                                                              "Quick Appearance");
+            if ( gInventory.getCategory( folder_uuid ) != NULL )
+            {
+                // Assume this is coming from the predefined avatars web floater
+                LLAppearanceMgr::getInstance()->wearInventoryCategory(category, true, false);
+
+                // *TODOw: This may not be necessary if initial outfit is chosen already -- josh
+                gAgent.setOutfitChosen(TRUE);
+            }
+        }
+
+        // release avatar picker keyboard focus
+        gFocusMgr.setKeyboardFocus( NULL );
+
+        return true;
+    }
 };
 
 LLWearFolderHandler gWearFolderHandler;
diff --git a/indra/newview/llappearancemgr.h b/indra/newview/llappearancemgr.h
index 0a6e410c3d8d0b7c302259165edc275bea232746..73514e2471195abcd0588cbacbf07f3c8d136b1c 100644
--- a/indra/newview/llappearancemgr.h
+++ b/indra/newview/llappearancemgr.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llappearancemgr.h
  * @brief Manager for initiating appearance changes on the viewer
  *
  * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -43,170 +43,170 @@ class LLOutfitUnLockTimer;
 
 class LLAppearanceMgr final : public LLSingleton<LLAppearanceMgr>
 {
-	LLSINGLETON(LLAppearanceMgr);
-	~LLAppearanceMgr();
-	LOG_CLASS(LLAppearanceMgr);
+    LLSINGLETON(LLAppearanceMgr);
+    ~LLAppearanceMgr();
+    LOG_CLASS(LLAppearanceMgr);
+
+    friend class LLOutfitUnLockTimer;
 
-	friend class LLOutfitUnLockTimer;
-	
 public:
-	typedef std::vector<LLInventoryModel::item_array_t> wearables_by_type_t;
+    typedef std::vector<LLInventoryModel::item_array_t> wearables_by_type_t;
 
-	void updateAppearanceFromCOF(bool enforce_item_restrictions = true,
-								 bool enforce_ordering = true,
-								 nullary_func_t post_update_func = no_op);
-	void updateCOF(const LLUUID& category, bool append = false);
+    void updateAppearanceFromCOF(bool enforce_item_restrictions = true,
+                                 bool enforce_ordering = true,
+                                 nullary_func_t post_update_func = no_op);
+    void updateCOF(const LLUUID& category, bool append = false);
 // [RLVa:KB] - Checked: 2010-03-05 (RLVa-1.2.0a) | Added: RLVa-1.2.0a
-	void updateCOF(LLInventoryModel::item_array_t& body_items_new, 
-								LLInventoryModel::item_array_t& wear_items_new, 
-								LLInventoryModel::item_array_t& obj_items_new,
-								LLInventoryModel::item_array_t& gest_items_new,
-								bool append=false, const LLUUID& idOutfit=LLUUID::null, LLPointer<LLInventoryCallback> link_waiter = NULL);
+    void updateCOF(LLInventoryModel::item_array_t& body_items_new,
+                                LLInventoryModel::item_array_t& wear_items_new,
+                                LLInventoryModel::item_array_t& obj_items_new,
+                                LLInventoryModel::item_array_t& gest_items_new,
+                                bool append=false, const LLUUID& idOutfit=LLUUID::null, LLPointer<LLInventoryCallback> link_waiter = NULL);
 // [/RLVa:KB]
-	void wearInventoryCategory(LLInventoryCategory* category, bool copy, bool append);
-	void wearInventoryCategoryOnAvatar(LLInventoryCategory* category, bool append);
-	void wearCategoryFinal(const LLUUID& cat_id, bool copy_items, bool append);
-	void wearOutfitByName(const std::string& name);
-	void changeOutfit(bool proceed, const LLUUID& category, bool append);
-	void replaceCurrentOutfit(const LLUUID& new_outfit);
-	void renameOutfit(const LLUUID& outfit_id);
-	void removeOutfitPhoto(const LLUUID& outfit_id);
-	void takeOffOutfit(const LLUUID& cat_id);
-	void addCategoryToCurrentOutfit(const LLUUID& cat_id);
-	S32 findExcessOrDuplicateItems(const LLUUID& cat_id,
-								   LLAssetType::EType type,
-								   S32 max_items_per_type,
-								   S32 max_items_total,
-								   LLInventoryObject::object_list_t& items_to_kill);
-	void findAllExcessOrDuplicateItems(const LLUUID& cat_id,
-									  LLInventoryObject::object_list_t& items_to_kill);
-	void enforceCOFItemRestrictions(LLPointer<LLInventoryCallback> cb);
-
-	S32 getActiveCopyOperations() const;
-
-	// Replace category contents with copied links via the slam_inventory_folder
-	// command (single inventory operation where supported)
-	void slamCategoryLinks(const LLUUID& src_id, const LLUUID& dst_id,
-						   bool include_folder_links, LLPointer<LLInventoryCallback> cb);
- 
-	// Copy all items and the src category itself.
-	void shallowCopyCategory(const LLUUID& src_id, const LLUUID& dst_id,
-							 LLPointer<LLInventoryCallback> cb);
-
-	// Return whether this folder contains minimal contents suitable for making a full outfit.
-	BOOL getCanMakeFolderIntoOutfit(const LLUUID& folder_id);
-
-	// Determine whether a given outfit can be removed.
-	bool getCanRemoveOutfit(const LLUUID& outfit_cat_id);
-
-	// Determine whether we're wearing any of the outfit contents (excluding body parts).
-	static bool getCanRemoveFromCOF(const LLUUID& outfit_cat_id);
-
-	// Determine whether we can add anything (but body parts) from the outfit contents to COF.
-	static bool getCanAddToCOF(const LLUUID& outfit_cat_id);
-
-	// Determine whether we can replace current outfit with the given one.
-	bool getCanReplaceCOF(const LLUUID& outfit_cat_id);
+    void wearInventoryCategory(LLInventoryCategory* category, bool copy, bool append);
+    void wearInventoryCategoryOnAvatar(LLInventoryCategory* category, bool append);
+    void wearCategoryFinal(const LLUUID& cat_id, bool copy_items, bool append);
+    void wearOutfitByName(const std::string& name);
+    void changeOutfit(bool proceed, const LLUUID& category, bool append);
+    void replaceCurrentOutfit(const LLUUID& new_outfit);
+    void renameOutfit(const LLUUID& outfit_id);
+    void removeOutfitPhoto(const LLUUID& outfit_id);
+    void takeOffOutfit(const LLUUID& cat_id);
+    void addCategoryToCurrentOutfit(const LLUUID& cat_id);
+    S32 findExcessOrDuplicateItems(const LLUUID& cat_id,
+                                   LLAssetType::EType type,
+                                   S32 max_items_per_type,
+                                   S32 max_items_total,
+                                   LLInventoryObject::object_list_t& items_to_kill);
+    void findAllExcessOrDuplicateItems(const LLUUID& cat_id,
+                                      LLInventoryObject::object_list_t& items_to_kill);
+    void enforceCOFItemRestrictions(LLPointer<LLInventoryCallback> cb);
+
+    S32 getActiveCopyOperations() const;
+
+    // Replace category contents with copied links via the slam_inventory_folder
+    // command (single inventory operation where supported)
+    void slamCategoryLinks(const LLUUID& src_id, const LLUUID& dst_id,
+                           bool include_folder_links, LLPointer<LLInventoryCallback> cb);
+
+    // Copy all items and the src category itself.
+    void shallowCopyCategory(const LLUUID& src_id, const LLUUID& dst_id,
+                             LLPointer<LLInventoryCallback> cb);
+
+    // Return whether this folder contains minimal contents suitable for making a full outfit.
+    BOOL getCanMakeFolderIntoOutfit(const LLUUID& folder_id);
+
+    // Determine whether a given outfit can be removed.
+    bool getCanRemoveOutfit(const LLUUID& outfit_cat_id);
+
+    // Determine whether we're wearing any of the outfit contents (excluding body parts).
+    static bool getCanRemoveFromCOF(const LLUUID& outfit_cat_id);
+
+    // Determine whether we can add anything (but body parts) from the outfit contents to COF.
+    static bool getCanAddToCOF(const LLUUID& outfit_cat_id);
+
+    // Determine whether we can replace current outfit with the given one.
+    bool getCanReplaceCOF(const LLUUID& outfit_cat_id);
 
     // Can we add all referenced items to the avatar?
     bool canAddWearables(const uuid_vec_t& item_ids) const;
-    
-	// Copy all items in a category.
-	void shallowCopyCategoryContents(const LLUUID& src_id, const LLUUID& dst_id,
-									 LLPointer<LLInventoryCallback> cb);
-
-	// Find the Current Outfit folder.
-	const LLUUID getCOF() const;
-	S32 getCOFVersion() const;
+
+    // Copy all items in a category.
+    void shallowCopyCategoryContents(const LLUUID& src_id, const LLUUID& dst_id,
+                                     LLPointer<LLInventoryCallback> cb);
+
+    // Find the Current Outfit folder.
+    const LLUUID getCOF() const;
+    S32 getCOFVersion() const;
     void initCOFID();
 
-	// Debugging - get truncated LLSD summary of COF contents.
-	LLSD dumpCOF() const;
+    // Debugging - get truncated LLSD summary of COF contents.
+    LLSD dumpCOF() const;
     void cleanup();
 
-	// Finds the folder link to the currently worn outfit
-	const LLViewerInventoryItem *getBaseOutfitLink();
-	bool getBaseOutfitName(std::string &name);
+    // Finds the folder link to the currently worn outfit
+    const LLViewerInventoryItem *getBaseOutfitLink();
+    bool getBaseOutfitName(std::string &name);
 
-	// find the UUID of the currently worn outfit (Base Outfit)
-	const LLUUID getBaseOutfitUUID();
+    // find the UUID of the currently worn outfit (Base Outfit)
+    const LLUUID getBaseOutfitUUID();
 
     void wearItemsOnAvatar(const uuid_vec_t& item_ids_to_wear,
                            bool do_update,
                            bool replace,
                            LLPointer<LLInventoryCallback> cb = NULL);
 
-	// Wear/attach an item (from a user's inventory) on the agent
-	void wearItemOnAvatar(const LLUUID& item_to_wear, bool do_update, bool replace = false,
-						  LLPointer<LLInventoryCallback> cb = NULL);
+    // Wear/attach an item (from a user's inventory) on the agent
+    void wearItemOnAvatar(const LLUUID& item_to_wear, bool do_update, bool replace = false,
+                          LLPointer<LLInventoryCallback> cb = NULL);
 
-	// Update the displayed outfit name in UI.
-	void updatePanelOutfitName(const std::string& name);
+    // Update the displayed outfit name in UI.
+    void updatePanelOutfitName(const std::string& name);
 
-	void purgeBaseOutfitLink(const LLUUID& category, LLPointer<LLInventoryCallback> cb = NULL);
-	void createBaseOutfitLink(const LLUUID& category, LLPointer<LLInventoryCallback> link_waiter);
+    void purgeBaseOutfitLink(const LLUUID& category, LLPointer<LLInventoryCallback> cb = NULL);
+    void createBaseOutfitLink(const LLUUID& category, LLPointer<LLInventoryCallback> link_waiter);
 
-	void updateAgentWearables(LLWearableHoldingPattern* holder);
+    void updateAgentWearables(LLWearableHoldingPattern* holder);
 
-	S32 countActiveHoldingPatterns();
+    S32 countActiveHoldingPatterns();
 
-	// For debugging - could be moved elsewhere.
-	void dumpCat(const LLUUID& cat_id, const std::string& msg);
-	void dumpItemArray(const LLInventoryModel::item_array_t& items, const std::string& msg);
+    // For debugging - could be moved elsewhere.
+    void dumpCat(const LLUUID& cat_id, const std::string& msg);
+    void dumpItemArray(const LLInventoryModel::item_array_t& items, const std::string& msg);
 
-	// Attachment link management
-	void unregisterAttachment(const LLUUID& item_id);
-	void registerAttachment(const LLUUID& item_id);
-	void setAttachmentInvLinkEnable(bool val);
+    // Attachment link management
+    void unregisterAttachment(const LLUUID& item_id);
+    void registerAttachment(const LLUUID& item_id);
+    void setAttachmentInvLinkEnable(bool val);
 
-	// Add COF link to individual item.
-	void addCOFItemLink(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb = NULL, const std::string description = "");
-	void addCOFItemLink(const LLInventoryItem *item, LLPointer<LLInventoryCallback> cb = NULL, const std::string description = "");
+    // Add COF link to individual item.
+    void addCOFItemLink(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb = NULL, const std::string description = "");
+    void addCOFItemLink(const LLInventoryItem *item, LLPointer<LLInventoryCallback> cb = NULL, const std::string description = "");
 
-	// Find COF entries referencing the given item.
-	LLInventoryModel::item_array_t findCOFItemLinks(const LLUUID& item_id);
-	bool isLinkedInCOF(const LLUUID& item_id);
+    // Find COF entries referencing the given item.
+    LLInventoryModel::item_array_t findCOFItemLinks(const LLUUID& item_id);
+    bool isLinkedInCOF(const LLUUID& item_id);
 
-	// Remove COF entries
-//	void removeCOFItemLinks(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb = NULL);
+    // Remove COF entries
+//  void removeCOFItemLinks(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb = NULL);
 // [SL:KB] - Patch: Appearance-AISFilter | Checked: 2015-05-02 (Catznip-3.7)
-	void removeCOFItemLinks(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb = NULL, bool immediate_delete = false);
+    void removeCOFItemLinks(const LLUUID& item_id, LLPointer<LLInventoryCallback> cb = NULL, bool immediate_delete = false);
 // [/SL:KB]
-	void removeCOFLinksOfType(LLWearableType::EType type, LLPointer<LLInventoryCallback> cb = NULL);
-	void removeAllClothesFromAvatar();
-	void removeAllAttachmentsFromAvatar();
+    void removeCOFLinksOfType(LLWearableType::EType type, LLPointer<LLInventoryCallback> cb = NULL);
+    void removeAllClothesFromAvatar();
+    void removeAllAttachmentsFromAvatar();
 
-	// Special handling of temp attachments, which are not in the COF
-	bool shouldRemoveTempAttachment(const LLUUID& item_id);
+    // Special handling of temp attachments, which are not in the COF
+    bool shouldRemoveTempAttachment(const LLUUID& item_id);
 
-	//has the current outfit changed since it was loaded?
-	bool isOutfitDirty() { return mOutfitIsDirty; }
+    //has the current outfit changed since it was loaded?
+    bool isOutfitDirty() { return mOutfitIsDirty; }
 
-	// set false if you just loaded the outfit, true otherwise
-	void setOutfitDirty(bool isDirty) { mOutfitIsDirty = isDirty; }
-	
-	// manually compare ouftit folder link to COF to see if outfit has changed.
-	// should only be necessary to do on initial login.
-	void updateIsDirty();
+    // set false if you just loaded the outfit, true otherwise
+    void setOutfitDirty(bool isDirty) { mOutfitIsDirty = isDirty; }
 
-	void setOutfitLocked(bool locked);
+    // manually compare ouftit folder link to COF to see if outfit has changed.
+    // should only be necessary to do on initial login.
+    void updateIsDirty();
 
-	// Called when self avatar is first fully visible.
-	void onFirstFullyVisible();
+    void setOutfitLocked(bool locked);
 
-	// Copy initial gestures from library.
-	void copyLibraryGestures();
-	
-	void wearBaseOutfit();
+    // Called when self avatar is first fully visible.
+    void onFirstFullyVisible();
 
-	void setOutfitImage(const LLUUID& image_id) {mCOFImageID = image_id;}
-	LLUUID getOutfitImage() {return mCOFImageID;}
+    // Copy initial gestures from library.
+    void copyLibraryGestures();
 
-	// Overrides the base outfit with the content from COF
-	// @return false if there is no base outfit
-	bool updateBaseOutfit();
+    void wearBaseOutfit();
 
-	//Remove clothing or detach an object from the agent (a bodypart cannot be removed)
+    void setOutfitImage(const LLUUID& image_id) {mCOFImageID = image_id;}
+    LLUUID getOutfitImage() {return mCOFImageID;}
+
+    // Overrides the base outfit with the content from COF
+    // @return false if there is no base outfit
+    bool updateBaseOutfit();
+
+    //Remove clothing or detach an object from the agent (a bodypart cannot be removed)
 // [SL:KB] - Patch: Appearance-Misc | Checked: 2015-05-05 (Catznip-3.7)
     void removeItemFromAvatar(const LLUUID& id_to_remove, nullary_func_t post_update_func = no_op) { removeItemFromAvatar(id_to_remove, post_update_func, NULL, false); }
     void removeItemFromAvatar(const LLUUID& id_to_remove, nullary_func_t post_update_func /*= no_op*/, LLPointer<LLInventoryCallback> cb /*= NULL*/, bool immediate_delete /*= false*/);
@@ -218,150 +218,150 @@ class LLAppearanceMgr final : public LLSingleton<LLAppearanceMgr>
 //  void removeItemFromAvatar(const LLUUID& item_id, nullary_func_t post_update_func = no_op);
 
 
-	void onOutfitFolderCreated(const LLUUID& folder_id, bool show_panel);
-	void onOutfitFolderCreatedAndClothingOrdered(const LLUUID& folder_id, bool show_panel);
+    void onOutfitFolderCreated(const LLUUID& folder_id, bool show_panel);
+    void onOutfitFolderCreatedAndClothingOrdered(const LLUUID& folder_id, bool show_panel);
 
-	void makeNewOutfitLinks(const std::string& new_folder_name,bool show_panel = true);
+    void makeNewOutfitLinks(const std::string& new_folder_name,bool show_panel = true);
 
-	bool moveWearable(LLViewerInventoryItem* item, bool closer_to_body);
+    bool moveWearable(LLViewerInventoryItem* item, bool closer_to_body);
 
-	static void sortItemsByActualDescription(LLInventoryModel::item_array_t& items);
+    static void sortItemsByActualDescription(LLInventoryModel::item_array_t& items);
 
-	//Divvy items into arrays by wearable type
-	static void divvyWearablesByType(const LLInventoryModel::item_array_t& items, wearables_by_type_t& items_by_type);
+    //Divvy items into arrays by wearable type
+    static void divvyWearablesByType(const LLInventoryModel::item_array_t& items, wearables_by_type_t& items_by_type);
 
-	typedef std::map<LLUUID,std::string> desc_map_t;
+    typedef std::map<LLUUID,std::string> desc_map_t;
 
-	void getWearableOrderingDescUpdates(LLInventoryModel::item_array_t& wear_items, desc_map_t& desc_map);
+    void getWearableOrderingDescUpdates(LLInventoryModel::item_array_t& wear_items, desc_map_t& desc_map);
 
-	//Check ordering information on wearables stored in links' descriptions and update if it is invalid
-	// COF is processed if cat_id is not specified
-	bool validateClothingOrderingInfo(LLUUID cat_id = LLUUID::null);
-	
-	void updateClothingOrderingInfo(LLUUID cat_id = LLUUID::null,
-									LLPointer<LLInventoryCallback> cb = NULL);
+    //Check ordering information on wearables stored in links' descriptions and update if it is invalid
+    // COF is processed if cat_id is not specified
+    bool validateClothingOrderingInfo(LLUUID cat_id = LLUUID::null);
 
-	bool isOutfitLocked() { return mOutfitLocked; }
+    void updateClothingOrderingInfo(LLUUID cat_id = LLUUID::null,
+                                    LLPointer<LLInventoryCallback> cb = NULL);
 
-	bool isInUpdateAppearanceFromCOF() { return mIsInUpdateAppearanceFromCOF; }
+    bool isOutfitLocked() { return mOutfitLocked; }
 
-	static void onIdle(void *);
-	void requestServerAppearanceUpdate();
+    bool isInUpdateAppearanceFromCOF() { return mIsInUpdateAppearanceFromCOF; }
+
+    static void onIdle(void *);
+    void requestServerAppearanceUpdate();
 
 // [SL:KB] - Patch: Appearance-Misc | Checked: 2015-06-27 (Catznip-3.7)
-	void syncCofVersionAndRefresh();
+    void syncCofVersionAndRefresh();
 // [/SL:KB]
-	void setAppearanceServiceURL(const std::string& url) { mAppearanceServiceURL = url; }
-	std::string getAppearanceServiceURL() const;
+    void setAppearanceServiceURL(const std::string& url) { mAppearanceServiceURL = url; }
+    std::string getAppearanceServiceURL() const;
 
-	typedef boost::function<void ()> attachments_changed_callback_t;
-	typedef boost::signals2::signal<void ()> attachments_changed_signal_t;
-	boost::signals2::connection setAttachmentsChangedCallback(attachments_changed_callback_t cb);
+    typedef boost::function<void ()> attachments_changed_callback_t;
+    typedef boost::signals2::signal<void ()> attachments_changed_signal_t;
+    boost::signals2::connection setAttachmentsChangedCallback(attachments_changed_callback_t cb);
 
 
 private:
     void serverAppearanceUpdateCoro(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter);
 
 // [SL:KB] - Patch: Appearance-Misc
-	void syncCofVersionAndRefreshCoro();
+    void syncCofVersionAndRefreshCoro();
 // [/SL:KB]
 
     static void debugAppearanceUpdateCOF(const LLSD& content);
 
-	std::string		mAppearanceServiceURL;
+    std::string     mAppearanceServiceURL;
 
 private:
 
-	void filterWearableItems(LLInventoryModel::item_array_t& items, S32 max_per_type, S32 max_total);
-	
-	void getDescendentsOfAssetType(const LLUUID& category, 
-										  LLInventoryModel::item_array_t& items,
-										  LLAssetType::EType type);
+    void filterWearableItems(LLInventoryModel::item_array_t& items, S32 max_per_type, S32 max_total);
+
+    void getDescendentsOfAssetType(const LLUUID& category,
+                                          LLInventoryModel::item_array_t& items,
+                                          LLAssetType::EType type);
 
-	void getUserDescendents(const LLUUID& category, 
-								   LLInventoryModel::item_array_t& wear_items,
-								   LLInventoryModel::item_array_t& obj_items,
-								   LLInventoryModel::item_array_t& gest_items);
+    void getUserDescendents(const LLUUID& category,
+                                   LLInventoryModel::item_array_t& wear_items,
+                                   LLInventoryModel::item_array_t& obj_items,
+                                   LLInventoryModel::item_array_t& gest_items);
 
-	static void onOutfitRename(const LLSD& notification, const LLSD& response);
+    static void onOutfitRename(const LLSD& notification, const LLSD& response);
 
-	bool mAttachmentInvLinkEnabled;
-	bool mOutfitIsDirty;
-	bool mIsInUpdateAppearanceFromCOF; // to detect recursive calls.
+    bool mAttachmentInvLinkEnabled;
+    bool mOutfitIsDirty;
+    bool mIsInUpdateAppearanceFromCOF; // to detect recursive calls.
     bool mOutstandingAppearanceBakeRequest; // A bake request is outstanding.  Do not overlap.
     bool mRerequestAppearanceBake;
 
-	/**
-	 * Lock for blocking operations on outfit until server reply or timeout exceed
-	 * to avoid unsynchronized outfit state or performing duplicate operations.
-	 */
-	bool mOutfitLocked;
-	LLTimer mInFlightTimer;
-	static bool mActive;
-
-	attachments_changed_signal_t		mAttachmentsChangeSignal;
-	
-	LLUUID mCOFImageID;
+    /**
+     * Lock for blocking operations on outfit until server reply or timeout exceed
+     * to avoid unsynchronized outfit state or performing duplicate operations.
+     */
+    bool mOutfitLocked;
+    LLTimer mInFlightTimer;
+    static bool mActive;
+
+    attachments_changed_signal_t        mAttachmentsChangeSignal;
+
+    LLUUID mCOFImageID;
     LLUUID mCOFID;
 
-	std::unique_ptr<LLOutfitUnLockTimer> mUnlockOutfitTimer;
+    std::unique_ptr<LLOutfitUnLockTimer> mUnlockOutfitTimer;
 
-	// Set of temp attachment UUIDs that should be removed
-	typedef std::set<LLUUID> doomed_temp_attachments_t;
-	doomed_temp_attachments_t	mDoomedTempAttachmentIDs;
+    // Set of temp attachment UUIDs that should be removed
+    typedef std::set<LLUUID> doomed_temp_attachments_t;
+    doomed_temp_attachments_t   mDoomedTempAttachmentIDs;
 
-	void addDoomedTempAttachment(const LLUUID& id_to_remove);
+    void addDoomedTempAttachment(const LLUUID& id_to_remove);
 
-	//////////////////////////////////////////////////////////////////////////////////
-	// Item-specific convenience functions 
+    //////////////////////////////////////////////////////////////////////////////////
+    // Item-specific convenience functions
 public:
-	// Is this in the COF?
-	BOOL getIsInCOF(const LLUUID& obj_id) const;
+    // Is this in the COF?
+    BOOL getIsInCOF(const LLUUID& obj_id) const;
     bool getIsInCOF(const LLInventoryObject* obj) const;
-	// Is this in the COF and can the user delete it from the COF?
+    // Is this in the COF and can the user delete it from the COF?
     bool getIsProtectedCOFItem(const LLUUID& obj_id) const;
     bool getIsProtectedCOFItem(const LLInventoryObject* obj) const;
 
-	// Outfits will prioritize textures with such name to use for preview in gallery
-	static const std::string sExpectedTextureName;
+    // Outfits will prioritize textures with such name to use for preview in gallery
+    static const std::string sExpectedTextureName;
 };
 
 class LLUpdateAppearanceOnDestroy: public LLInventoryCallback
 {
 public:
-	LLUpdateAppearanceOnDestroy(bool enforce_item_restrictions = true,
-								bool enforce_ordering = true,
-								nullary_func_t post_update_func = no_op);
-	virtual ~LLUpdateAppearanceOnDestroy();
-	/* virtual */ void fire(const LLUUID& inv_item);
+    LLUpdateAppearanceOnDestroy(bool enforce_item_restrictions = true,
+                                bool enforce_ordering = true,
+                                nullary_func_t post_update_func = no_op);
+    virtual ~LLUpdateAppearanceOnDestroy();
+    /* virtual */ void fire(const LLUUID& inv_item);
 
 private:
-	U32 mFireCount;
-	bool mEnforceItemRestrictions;
-	bool mEnforceOrdering;
-	nullary_func_t mPostUpdateFunc;
+    U32 mFireCount;
+    bool mEnforceItemRestrictions;
+    bool mEnforceOrdering;
+    nullary_func_t mPostUpdateFunc;
 };
 
 class LLUpdateAppearanceAndEditWearableOnDestroy: public LLInventoryCallback
 {
 public:
-	LLUpdateAppearanceAndEditWearableOnDestroy(const LLUUID& item_id);
+    LLUpdateAppearanceAndEditWearableOnDestroy(const LLUUID& item_id);
+
+    /* virtual */ void fire(const LLUUID& item_id) {}
 
-	/* virtual */ void fire(const LLUUID& item_id) {}
+    ~LLUpdateAppearanceAndEditWearableOnDestroy();
 
-	~LLUpdateAppearanceAndEditWearableOnDestroy();
-	
 private:
-	LLUUID mItemID;
+    LLUUID mItemID;
 };
 
 class LLRequestServerAppearanceUpdateOnDestroy: public LLInventoryCallback
 {
 public:
-	LLRequestServerAppearanceUpdateOnDestroy() {}
-	~LLRequestServerAppearanceUpdateOnDestroy();
+    LLRequestServerAppearanceUpdateOnDestroy() {}
+    ~LLRequestServerAppearanceUpdateOnDestroy();
 
-	/* virtual */ void fire(const LLUUID& item_id) {}
+    /* virtual */ void fire(const LLUUID& item_id) {}
 };
 
 LLUUID findDescendentCategoryIDByName(const LLUUID& parent_id,const std::string& name);
diff --git a/indra/newview/llappviewer.cpp b/indra/newview/llappviewer.cpp
index fecaf530f20c4e6c73b2294e3addc883503cb815..33c2dd0e83cc89a7e7631928db9296b1a6e1615c 100644
--- a/indra/newview/llappviewer.cpp
+++ b/indra/newview/llappviewer.cpp
@@ -119,7 +119,7 @@
 #include "llscenemonitor.h"
 #include "llavatarrenderinfoaccountant.h"
 #include "lllocalbitmaps.h"
-#include "llperfstats.h" 
+#include "llperfstats.h"
 #include "llgltfmateriallist.h"
 
 // Linden library includes
@@ -163,7 +163,7 @@
 #include <boost/throw_exception.hpp>
 
 #if LL_WINDOWS
-#	include <share.h> // For _SH_DENYWR in processMarkerFiles
+#   include <share.h> // For _SH_DENYWR in processMarkerFiles
 #else
 #   include <sys/file.h> // For processMarkerFiles
 #endif
@@ -328,16 +328,16 @@ const char* gPlatform = LL_PLATFORM_KEY;
 
 LLSD gDebugInfo;
 
-U32	gFrameCount = 0;
+U32 gFrameCount = 0;
 U32 gForegroundFrameCount = 0; // number of frames that app window was in foreground
 LLPumpIO* gServicePump = NULL;
 
 U64MicrosecondsImplicit gFrameTime = 0;
 F32SecondsImplicit gFrameTimeSeconds = 0.f;
 F32SecondsImplicit gFrameIntervalSeconds = 0.f;
-F32 gFPSClamped = 10.f;						// Pretend we start at target rate.
-F32 gFrameDTClamped = 0.f;					// Time between adjacent checks to network for packets
-U64MicrosecondsImplicit	gStartTime = 0; // gStartTime is "private", used only to calculate gFrameTimeSeconds
+F32 gFPSClamped = 10.f;                     // Pretend we start at target rate.
+F32 gFrameDTClamped = 0.f;                  // Time between adjacent checks to network for packets
+U64MicrosecondsImplicit gStartTime = 0; // gStartTime is "private", used only to calculate gFrameTimeSeconds
 
 LLTimer gRenderStartTime;
 LLFrameTimer gForegroundTime;
@@ -350,24 +350,24 @@ F32 gLogoutMaxTime = LOGOUT_REQUEST_TIME;
 S32 gPendingMetricsUploads = 0;
 
 
-BOOL				gDisconnected = FALSE;
+BOOL                gDisconnected = FALSE;
 
 // used to restore texture state after a mode switch
-LLFrameTimer	gRestoreGLTimer;
-BOOL			gRestoreGL = FALSE;
-bool			gUseWireframe = FALSE;
+LLFrameTimer    gRestoreGLTimer;
+BOOL            gRestoreGL = FALSE;
+bool            gUseWireframe = FALSE;
 
 LLMemoryInfo gSysMemory;
 U64Bytes gMemoryAllocated(0); // updated in display_stats() in llviewerdisplay.cpp
 
 std::string gLastVersionChannel;
 
-LLVector3			gWindVec(3.0, 3.0, 0.0);
-LLVector3			gRelativeWindVec(0.0, 0.0, 0.0);
+LLVector3           gWindVec(3.0, 3.0, 0.0);
+LLVector3           gRelativeWindVec(0.0, 0.0, 0.0);
 
-U32		gPacketsIn = 0;
+U32     gPacketsIn = 0;
 
-BOOL				gPrintMessagesThisFrame = FALSE;
+BOOL                gPrintMessagesThisFrame = FALSE;
 
 BOOL gRandomizeFramerate = FALSE;
 BOOL gPeriodicSlowFrame = FALSE;
@@ -405,52 +405,52 @@ const char* const VIEWER_WINDOW_CLASSNAME = "Alchemy";
 static std::set<std::string> default_trans_args;
 void init_default_trans_args()
 {
-	default_trans_args.insert("CURRENT_GRID");
-	default_trans_args.insert("SECOND_LIFE"); // World
-	default_trans_args.insert("GRID_ADMIN");
-	default_trans_args.insert("APP_NAME");
-	default_trans_args.insert("CAPITALIZED_APP_NAME");
-	default_trans_args.insert("SECOND_LIFE_GRID");
-	default_trans_args.insert("SUPPORT_SITE");
+    default_trans_args.insert("CURRENT_GRID");
+    default_trans_args.insert("SECOND_LIFE"); // World
+    default_trans_args.insert("GRID_ADMIN");
+    default_trans_args.insert("APP_NAME");
+    default_trans_args.insert("CAPITALIZED_APP_NAME");
+    default_trans_args.insert("SECOND_LIFE_GRID");
+    default_trans_args.insert("SUPPORT_SITE");
 }
 
 struct SettingsFile : public LLInitParam::Block<SettingsFile>
 {
-	Mandatory<std::string>	name;
-	Optional<std::string>	file_name;
-	Optional<bool>			required,
-							persistent;
-	Optional<std::string>	file_name_setting;
-
-	SettingsFile()
-	:	name("name"),
-		file_name("file_name"),
-		required("required", false),
-		persistent("persistent", true),
-		file_name_setting("file_name_setting")
-	{}
+    Mandatory<std::string>  name;
+    Optional<std::string>   file_name;
+    Optional<bool>          required,
+                            persistent;
+    Optional<std::string>   file_name_setting;
+
+    SettingsFile()
+    :   name("name"),
+        file_name("file_name"),
+        required("required", false),
+        persistent("persistent", true),
+        file_name_setting("file_name_setting")
+    {}
 };
 
 struct SettingsGroup : public LLInitParam::Block<SettingsGroup>
 {
-	Mandatory<std::string>	name;
-	Mandatory<S32>			path_index;
-	Multiple<SettingsFile>	files;
-
-	SettingsGroup()
-	:	name("name"),
-		path_index("path_index"),
-		files("file")
-	{}
+    Mandatory<std::string>  name;
+    Mandatory<S32>          path_index;
+    Multiple<SettingsFile>  files;
+
+    SettingsGroup()
+    :   name("name"),
+        path_index("path_index"),
+        files("file")
+    {}
 };
 
 struct SettingsFiles : public LLInitParam::Block<SettingsFiles>
 {
-	Multiple<SettingsGroup>	groups;
+    Multiple<SettingsGroup> groups;
 
-	SettingsFiles()
-	: groups("group")
-	{}
+    SettingsFiles()
+    : groups("group")
+    {}
 };
 
 static std::string gWindowTitle;
@@ -465,120 +465,120 @@ static bool app_metrics_qa_mode = false;
 
 void idle_afk_check()
 {
-	// check idle timers
-	F32 current_idle = gAwayTriggerTimer.getElapsedTimeF32();
-	static const LLCachedControl<S32> afk_timeout_cc(gSavedSettings, "AFKTimeout");
+    // check idle timers
+    F32 current_idle = gAwayTriggerTimer.getElapsedTimeF32();
+    static const LLCachedControl<S32> afk_timeout_cc(gSavedSettings, "AFKTimeout");
 // [RLVa:KB] - Checked: 2010-05-03 (RLVa-1.2.0g) | Modified: RLVa-1.2.0g
-	// Enforce an idle time of 30 minutes if @allowidle=n restricted
-	F32 afk_timeout = (!gRlvHandler.hasBehaviour(RLV_BHVR_ALLOWIDLE)) ? afk_timeout_cc : 60 * 30;
+    // Enforce an idle time of 30 minutes if @allowidle=n restricted
+    F32 afk_timeout = (!gRlvHandler.hasBehaviour(RLV_BHVR_ALLOWIDLE)) ? afk_timeout_cc : 60 * 30;
 // [/RLVa:KB]
-//	F32 afk_timeout  = gSavedSettings.getS32("AFKTimeout");
-	if (afk_timeout && (current_idle > afk_timeout) && ! gAgent.getAFK())
-	{
-		LL_INFOS("IdleAway") << "Idle more than " << afk_timeout << " seconds: automatically changing to Away status" << LL_ENDL;
-		gAgent.setAFK();
-	}
+//  F32 afk_timeout  = gSavedSettings.getS32("AFKTimeout");
+    if (afk_timeout && (current_idle > afk_timeout) && ! gAgent.getAFK())
+    {
+        LL_INFOS("IdleAway") << "Idle more than " << afk_timeout << " seconds: automatically changing to Away status" << LL_ENDL;
+        gAgent.setAFK();
+    }
 }
 
 // A callback set in LLAppViewer::init()
 static void ui_audio_callback(const LLUUID& uuid)
 {
-	if (gAudiop)
-	{
-		SoundData soundData(uuid, gAgent.getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_UI);
-		gAudiop->triggerSound(soundData);
-	}
+    if (gAudiop)
+    {
+        SoundData soundData(uuid, gAgent.getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_UI);
+        gAudiop->triggerSound(soundData);
+    }
 }
 
 // A callback set in LLAppViewer::init()
 static void deferred_ui_audio_callback(const LLUUID& uuid)
 {
-	if (gAudiop)
-	{
-		SoundData soundData(uuid, gAgent.getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_UI);
-		LLDeferredSounds::instance().deferSound(soundData);
-	}
+    if (gAudiop)
+    {
+        SoundData soundData(uuid, gAgent.getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_UI);
+        LLDeferredSounds::instance().deferSound(soundData);
+    }
 }
 
-bool	create_text_segment_icon_from_url_match(LLUrlMatch* match,LLTextBase* base)
+bool    create_text_segment_icon_from_url_match(LLUrlMatch* match,LLTextBase* base)
 {
-	if(!match || !base || base->getPlainText())
-		return false;
-
-	LLUUID match_id = match->getID();
-
-	LLIconCtrl* icon;
-
-	if( match->getMenuName() == "menu_url_group.xml" // See LLUrlEntryGroup constructor
-		|| gAgent.isInGroup(match_id, TRUE)) //This check seems unfiting, urls are either /agent or /group
-	{
-		LLGroupIconCtrl::Params icon_params;
-		icon_params.group_id = match_id;
-		icon_params.rect = LLRect(0, 16, 16, 0);
-		icon_params.visible = true;
-		icon = LLUICtrlFactory::create<LLGroupIconCtrl>(icon_params);
-	}
-	else
-	{
-		LLAvatarIconCtrl::Params icon_params;
-		icon_params.avatar_id = match_id;
-		icon_params.rect = LLRect(0, 16, 16, 0);
-		icon_params.visible = true;
-		icon = LLUICtrlFactory::create<LLAvatarIconCtrl>(icon_params);
-	}
-
-	LLInlineViewSegment::Params params;
-	params.force_newline = false;
-	params.view = icon;
-	params.left_pad = 4;
-	params.right_pad = 4;
-	params.top_pad = -2;
-	params.bottom_pad = 2;
-
-	base->appendWidget(params," ",false);
-
-	return true;
+    if(!match || !base || base->getPlainText())
+        return false;
+
+    LLUUID match_id = match->getID();
+
+    LLIconCtrl* icon;
+
+    if( match->getMenuName() == "menu_url_group.xml" // See LLUrlEntryGroup constructor
+        || gAgent.isInGroup(match_id, TRUE)) //This check seems unfiting, urls are either /agent or /group
+    {
+        LLGroupIconCtrl::Params icon_params;
+        icon_params.group_id = match_id;
+        icon_params.rect = LLRect(0, 16, 16, 0);
+        icon_params.visible = true;
+        icon = LLUICtrlFactory::create<LLGroupIconCtrl>(icon_params);
+    }
+    else
+    {
+        LLAvatarIconCtrl::Params icon_params;
+        icon_params.avatar_id = match_id;
+        icon_params.rect = LLRect(0, 16, 16, 0);
+        icon_params.visible = true;
+        icon = LLUICtrlFactory::create<LLAvatarIconCtrl>(icon_params);
+    }
+
+    LLInlineViewSegment::Params params;
+    params.force_newline = false;
+    params.view = icon;
+    params.left_pad = 4;
+    params.right_pad = 4;
+    params.top_pad = -2;
+    params.bottom_pad = 2;
+
+    base->appendWidget(params," ",false);
+
+    return true;
 }
 
 // Use these strictly for things that are constructed at startup,
 // or for things that are performance critical.  JC
 static void settings_to_globals()
 {
-	LLSurface::setTextureSize(gSavedSettings.getU32("RegionTextureSize"));
+    LLSurface::setTextureSize(gSavedSettings.getU32("RegionTextureSize"));
 
 #if LL_DARWIN
     LLRender::sGLCoreProfile = true;
 #else
     LLRender::sGLCoreProfile = gSavedSettings.getBOOL("RenderGLContextCoreProfile");
 #endif
-	LLRender::sNsightDebugSupport = gSavedSettings.getBOOL("RenderNsightDebugSupport");
-	LLRender::sAnisotropicFilteringLevel = static_cast<F32>(gSavedSettings.getU32("RenderAnisotropicLevel"));
-	LLImageGL::sCompressTextures		= gSavedSettings.getBOOL("RenderCompressTextures");
-	LLVOVolume::sLODFactor				= llclamp(gSavedSettings.getF32("RenderVolumeLODFactor"), 0.01f, MAX_LOD_FACTOR);
-	LLVOVolume::sDistanceFactor			= 1.f-LLVOVolume::sLODFactor * 0.1f;
-	LLVolumeImplFlexible::sUpdateFactor = gSavedSettings.getF32("RenderFlexTimeFactor");
-	LLVOTree::sTreeFactor				= gSavedSettings.getF32("RenderTreeLODFactor");
-	LLVOAvatar::sLODFactor				= llclamp(gSavedSettings.getF32("RenderAvatarLODFactor"), 0.f, MAX_AVATAR_LOD_FACTOR);
-	LLVOAvatar::sPhysicsLODFactor		= llclamp(gSavedSettings.getF32("RenderAvatarPhysicsLODFactor"), 0.f, MAX_AVATAR_LOD_FACTOR);
-	LLVOAvatar::updateImpostorRendering(gSavedSettings.getU32("RenderAvatarMaxNonImpostors"));
-	LLVOAvatar::sVisibleInFirstPerson	= gSavedSettings.getBOOL("FirstPersonAvatarVisible");
-	// clamp auto-open time to some minimum usable value
-	LLFolderView::sAutoOpenTime			= llmax(0.25f, gSavedSettings.getF32("FolderAutoOpenDelay"));
-	LLSelectMgr::sRectSelectInclusive	= gSavedSettings.getBOOL("RectangleSelectInclusive");
-	LLSelectMgr::sRenderHiddenSelections = gSavedSettings.getBOOL("RenderHiddenSelections");
-	LLSelectMgr::sRenderLightRadius = gSavedSettings.getBOOL("RenderLightRadius");
-
-	gAgentPilot.setNumRuns(gSavedSettings.getS32("StatsNumRuns"));
-	gAgentPilot.setQuitAfterRuns(gSavedSettings.getBOOL("StatsQuitAfterRuns"));
-	gAgent.setHideGroupTitle(gSavedSettings.getBOOL("RenderHideGroupTitle"));
-
-	gDebugWindowProc = gSavedSettings.getBOOL("DebugWindowProc");
-	gShowObjectUpdates = gSavedSettings.getBOOL("ShowObjectUpdates");
+    LLRender::sNsightDebugSupport = gSavedSettings.getBOOL("RenderNsightDebugSupport");
+    LLRender::sAnisotropicFilteringLevel = static_cast<F32>(gSavedSettings.getU32("RenderAnisotropicLevel"));
+    LLImageGL::sCompressTextures        = gSavedSettings.getBOOL("RenderCompressTextures");
+    LLVOVolume::sLODFactor              = llclamp(gSavedSettings.getF32("RenderVolumeLODFactor"), 0.01f, MAX_LOD_FACTOR);
+    LLVOVolume::sDistanceFactor         = 1.f-LLVOVolume::sLODFactor * 0.1f;
+    LLVolumeImplFlexible::sUpdateFactor = gSavedSettings.getF32("RenderFlexTimeFactor");
+    LLVOTree::sTreeFactor               = gSavedSettings.getF32("RenderTreeLODFactor");
+    LLVOAvatar::sLODFactor              = llclamp(gSavedSettings.getF32("RenderAvatarLODFactor"), 0.f, MAX_AVATAR_LOD_FACTOR);
+    LLVOAvatar::sPhysicsLODFactor       = llclamp(gSavedSettings.getF32("RenderAvatarPhysicsLODFactor"), 0.f, MAX_AVATAR_LOD_FACTOR);
+    LLVOAvatar::updateImpostorRendering(gSavedSettings.getU32("RenderAvatarMaxNonImpostors"));
+    LLVOAvatar::sVisibleInFirstPerson   = gSavedSettings.getBOOL("FirstPersonAvatarVisible");
+    // clamp auto-open time to some minimum usable value
+    LLFolderView::sAutoOpenTime         = llmax(0.25f, gSavedSettings.getF32("FolderAutoOpenDelay"));
+    LLSelectMgr::sRectSelectInclusive   = gSavedSettings.getBOOL("RectangleSelectInclusive");
+    LLSelectMgr::sRenderHiddenSelections = gSavedSettings.getBOOL("RenderHiddenSelections");
+    LLSelectMgr::sRenderLightRadius = gSavedSettings.getBOOL("RenderLightRadius");
+
+    gAgentPilot.setNumRuns(gSavedSettings.getS32("StatsNumRuns"));
+    gAgentPilot.setQuitAfterRuns(gSavedSettings.getBOOL("StatsQuitAfterRuns"));
+    gAgent.setHideGroupTitle(gSavedSettings.getBOOL("RenderHideGroupTitle"));
+
+    gDebugWindowProc = gSavedSettings.getBOOL("DebugWindowProc");
+    gShowObjectUpdates = gSavedSettings.getBOOL("ShowObjectUpdates");
     LLWorldMapView::setScaleSetting(gSavedSettings.getF32("MapScale"));
-	
+
 #if LL_DARWIN
     LLWindowMacOSX::sUseMultGL = gSavedSettings.getBOOL("RenderAppleUseMultGL");
-	gHiDPISupport = gSavedSettings.getBOOL("RenderHiDPI");
+    gHiDPISupport = gSavedSettings.getBOOL("RenderHiDPI");
 #endif
 }
 
@@ -596,41 +596,41 @@ static void settings_modify()
 class LLFastTimerLogThread final : public LLThread
 {
 public:
-	std::string mFile;
-
-	LLFastTimerLogThread(std::string& test_name) : LLThread("fast timer log")
- 	{
-		std::string file_name = test_name + std::string(".slp");
-		mFile = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, file_name);
-	}
-
-	void run()
-	{
-		llofstream os(mFile.c_str());
-
-		while (!LLAppViewer::instance()->isQuitting())
-		{
-			LLTrace::BlockTimer::writeLog(os);
-			os.flush();
-			ms_sleep(32);
-		}
-
-		os.close();
-	}
+    std::string mFile;
+
+    LLFastTimerLogThread(std::string& test_name) : LLThread("fast timer log")
+    {
+        std::string file_name = test_name + std::string(".slp");
+        mFile = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, file_name);
+    }
+
+    void run()
+    {
+        llofstream os(mFile.c_str());
+
+        while (!LLAppViewer::instance()->isQuitting())
+        {
+            LLTrace::BlockTimer::writeLog(os);
+            os.flush();
+            ms_sleep(32);
+        }
+
+        os.close();
+    }
 };
 
 //virtual
 bool LLAppViewer::initSLURLHandler()
 {
-	// does nothing unless subclassed
-	return false;
+    // does nothing unless subclassed
+    return false;
 }
 
 //virtual
 bool LLAppViewer::sendURLToOtherInstance(const std::string& url)
 {
-	// does nothing unless subclassed
-	return false;
+    // does nothing unless subclassed
+    return false;
 }
 
 //----------------------------------------------------------------------------
@@ -646,394 +646,394 @@ LLPurgeDiskCacheThread* LLAppViewer::sPurgeDiskCacheThread = NULL;
 
 std::string getRuntime()
 {
-	return llformat("%.4f", (F32)LLTimer::getElapsedSeconds().value());
+    return llformat("%.4f", (F32)LLTimer::getElapsedSeconds().value());
 }
 
 LLAppViewer::LLAppViewer()
-:	mMarkerFile(),
-	mLogoutMarkerFile(),
-	mReportedCrash(false),
-	mNumSessions(0),
+:   mMarkerFile(),
+    mLogoutMarkerFile(),
+    mReportedCrash(false),
+    mNumSessions(0),
     mGeneralThreadPool(nullptr),
-	mPurgeCache(false),
-	mPurgeCacheOnExit(false),
-	mPurgeUserDataOnExit(false),
-	mSecondInstance(false),
-	mUpdaterNotFound(false),
-	mSavedFinalSnapshot(false),
-	mSavePerAccountSettings(false),		// don't save settings on logout unless login succeeded.
-	mQuitRequested(false),
-	mLogoutRequestSent(false),
-	mLastAgentControlFlags(0),
-	mLastAgentForceUpdate(0),
-	mMainloopTimeout(NULL),
-	mAgentRegionLastAlive(false),
-	mRandomizeFramerate(LLCachedControl<bool>(gSavedSettings,"Randomize Framerate", FALSE)),
-	mPeriodicSlowFrame(LLCachedControl<bool>(gSavedSettings,"Periodic Slow Frame", FALSE)),
-	mFastTimerLogThread(NULL),
-	mSettingsLocationList(NULL),
-	mIsFirstRun(false)
+    mPurgeCache(false),
+    mPurgeCacheOnExit(false),
+    mPurgeUserDataOnExit(false),
+    mSecondInstance(false),
+    mUpdaterNotFound(false),
+    mSavedFinalSnapshot(false),
+    mSavePerAccountSettings(false),     // don't save settings on logout unless login succeeded.
+    mQuitRequested(false),
+    mLogoutRequestSent(false),
+    mLastAgentControlFlags(0),
+    mLastAgentForceUpdate(0),
+    mMainloopTimeout(NULL),
+    mAgentRegionLastAlive(false),
+    mRandomizeFramerate(LLCachedControl<bool>(gSavedSettings,"Randomize Framerate", FALSE)),
+    mPeriodicSlowFrame(LLCachedControl<bool>(gSavedSettings,"Periodic Slow Frame", FALSE)),
+    mFastTimerLogThread(NULL),
+    mSettingsLocationList(NULL),
+    mIsFirstRun(false)
 {
-	if(NULL != sInstance)
-	{
-		LL_ERRS() << "Oh no! An instance of LLAppViewer already exists! LLAppViewer is sort of like a singleton." << LL_ENDL;
-	}
-
-	// Need to do this initialization before we do anything else, since anything
-	// that touches files should really go through the lldir API
-	gDirUtilp->initAppDirs("AlchemyNext");
-	//
-	// IMPORTANT! Do NOT put anything that will write
-	// into the log files during normal startup until AFTER
-	// we run the "program crashed last time" error handler below.
-	//
-	sInstance = this;
-
-	gLoggedInTime.stop();
-
-	processMarkerFiles();
-	//
-	// OK to write stuff to logs now, we've now crash reported if necessary
-	//
-
-	LLLoginInstance::instance().setPlatformInfo(gPlatform, LLOSInfo::instance().getOSVersionString(), LLOSInfo::instance().getOSStringSimple());
-
-	// Under some circumstances we want to read the static_debug_info.log file
-	// from the previous viewer run between this constructor call and the
-	// init() call, which will overwrite the static_debug_info.log file for
-	// THIS run. So setDebugFileNames() early.
-
-	// MAINT-8917: don't create a dump directory just for the
-	// static_debug_info.log file
-	std::string logdir = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "");
-	setDebugFileNames(logdir);
+    if(NULL != sInstance)
+    {
+        LL_ERRS() << "Oh no! An instance of LLAppViewer already exists! LLAppViewer is sort of like a singleton." << LL_ENDL;
+    }
+
+    // Need to do this initialization before we do anything else, since anything
+    // that touches files should really go through the lldir API
+    gDirUtilp->initAppDirs("AlchemyNext");
+    //
+    // IMPORTANT! Do NOT put anything that will write
+    // into the log files during normal startup until AFTER
+    // we run the "program crashed last time" error handler below.
+    //
+    sInstance = this;
+
+    gLoggedInTime.stop();
+
+    processMarkerFiles();
+    //
+    // OK to write stuff to logs now, we've now crash reported if necessary
+    //
+
+    LLLoginInstance::instance().setPlatformInfo(gPlatform, LLOSInfo::instance().getOSVersionString(), LLOSInfo::instance().getOSStringSimple());
+
+    // Under some circumstances we want to read the static_debug_info.log file
+    // from the previous viewer run between this constructor call and the
+    // init() call, which will overwrite the static_debug_info.log file for
+    // THIS run. So setDebugFileNames() early.
+
+    // MAINT-8917: don't create a dump directory just for the
+    // static_debug_info.log file
+    std::string logdir = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "");
+    setDebugFileNames(logdir);
 }
 
 LLAppViewer::~LLAppViewer()
 {
-	delete mSettingsLocationList;
+    delete mSettingsLocationList;
 
-	destroyMainloopTimeout();
+    destroyMainloopTimeout();
 
-	// If we got to this destructor somehow, the app didn't hang.
-	removeMarkerFiles();
+    // If we got to this destructor somehow, the app didn't hang.
+    removeMarkerFiles();
 }
 
 class LLUITranslationBridge : public LLTranslationBridge
 {
 public:
-	virtual std::string getString(const std::string &xml_desc)
-	{
-		return LLTrans::getString(xml_desc);
-	}
+    virtual std::string getString(const std::string &xml_desc)
+    {
+        return LLTrans::getString(xml_desc);
+    }
 };
 
 
 bool LLAppViewer::init()
 {
-	setupErrorHandling(mSecondInstance);
+    setupErrorHandling(mSecondInstance);
 
-	//
-	// Start of the application
-	//
+    //
+    // Start of the application
+    //
 
     // initialize the LLSettingsType translation bridge.
     LLTranslationBridge::ptr_t trans = std::make_shared<LLUITranslationBridge>();
     LLSettingsType::initParamSingleton(trans);
 
-	// initialize SSE options
-	LLVector4a::initClass();
+    // initialize SSE options
+    LLVector4a::initClass();
 
-	//initialize particle index pool
-	LLVOPartGroup::initClass();
+    //initialize particle index pool
+    LLVOPartGroup::initClass();
 
-	// set skin search path to default, will be overridden later
-	// this allows simple skinned file lookups to work
-	gDirUtilp->setSkinFolder("default", "en");
+    // set skin search path to default, will be overridden later
+    // this allows simple skinned file lookups to work
+    gDirUtilp->setSkinFolder("default", "en");
 
-//	initLoggingAndGetLastDuration();
+//  initLoggingAndGetLastDuration();
 
-	//
-	// OK to write stuff to logs now, we've now crash reported if necessary
-	//
-	init_default_trans_args();
+    //
+    // OK to write stuff to logs now, we've now crash reported if necessary
+    //
+    init_default_trans_args();
 
     // inits from settings.xml and from strings.xml
-	if (!initConfiguration())
-		return false;
+    if (!initConfiguration())
+        return false;
 
-	ALControlCache::initControls();
+    ALControlCache::initControls();
 
-	LL_INFOS("InitInfo") << "Configuration initialized." << LL_ENDL ;
+    LL_INFOS("InitInfo") << "Configuration initialized." << LL_ENDL ;
 
-	//set the max heap size.
-	initMaxHeapSize() ;
-	LLCoros::instance().setStackSize(gSavedSettings.getS32("CoroutineStackSize"));
+    //set the max heap size.
+    initMaxHeapSize() ;
+    LLCoros::instance().setStackSize(gSavedSettings.getS32("CoroutineStackSize"));
 
 
-	// Although initLoggingAndGetLastDuration() is the right place to mess with
-	// setFatalFunction(), we can't query gSavedSettings until after
-	// initConfiguration().
-	S32 rc(gSavedSettings.getS32("QAModeTermCode"));
-	if (rc >= 0)
-	{
-		// QAModeTermCode set, terminate with that rc on LL_ERRS. Use
-		// _exit() rather than exit() because normal cleanup depends too
-		// much on successful startup!
-		LLError::setFatalFunction([rc](const std::string&){ _exit(rc); });
-	}
+    // Although initLoggingAndGetLastDuration() is the right place to mess with
+    // setFatalFunction(), we can't query gSavedSettings until after
+    // initConfiguration().
+    S32 rc(gSavedSettings.getS32("QAModeTermCode"));
+    if (rc >= 0)
+    {
+        // QAModeTermCode set, terminate with that rc on LL_ERRS. Use
+        // _exit() rather than exit() because normal cleanup depends too
+        // much on successful startup!
+        LLError::setFatalFunction([rc](const std::string&){ _exit(rc); });
+    }
 
-	// Initialize the non-LLCurl libcurl library.  Should be called
-	// before consumers (LLTextureFetch).
-	mAppCoreHttp.init();
+    // Initialize the non-LLCurl libcurl library.  Should be called
+    // before consumers (LLTextureFetch).
+    mAppCoreHttp.init();
 
-	LL_INFOS("InitInfo") << "LLCore::Http initialized." << LL_ENDL ;
+    LL_INFOS("InitInfo") << "LLCore::Http initialized." << LL_ENDL ;
 
     LLMachineID::init();
 
-	{
-		if (gSavedSettings.getBOOL("QAModeMetrics"))
-		{
-			app_metrics_qa_mode = true;
-			app_metrics_interval = METRICS_INTERVAL_QA;
-		}
-		LLViewerAssetStatsFF::init();
-	}
-
-	initThreads();
-	LL_INFOS("InitInfo") << "Threads initialized." << LL_ENDL ;
-
-	// Initialize settings early so that the defaults for ignorable dialogs are
-	// picked up and then correctly re-saved after launching the updater (STORM-1268).
-	LLUI::settings_map_t settings_map;
-	settings_map["config"] = &gSavedSettings;
-	settings_map["ignores"] = &gWarningSettings;
-	settings_map["floater"] = &gSavedSettings; // *TODO: New settings file
-	settings_map["account"] = &gSavedPerAccountSettings;
-
-	LLUI::initParamSingleton(settings_map,
-		LLUIImageList::getInstance(),
-		ui_audio_callback,
-		deferred_ui_audio_callback);
-	LL_INFOS("InitInfo") << "UI initialized." << LL_ENDL ;
-
-	// NOW LLUI::getLanguage() should work. gDirUtilp must know the language
-	// for this session ASAP so all the file-loading commands that follow,
-	// that use findSkinnedFilenames(), will include the localized files.
-	gDirUtilp->setSkinFolder(gDirUtilp->getSkinFolder(), LLUI::getLanguage());
-
-	// Setup LLTrans after LLUI::initClass has been called.
-	initStrings();
+    {
+        if (gSavedSettings.getBOOL("QAModeMetrics"))
+        {
+            app_metrics_qa_mode = true;
+            app_metrics_interval = METRICS_INTERVAL_QA;
+        }
+        LLViewerAssetStatsFF::init();
+    }
+
+    initThreads();
+    LL_INFOS("InitInfo") << "Threads initialized." << LL_ENDL ;
+
+    // Initialize settings early so that the defaults for ignorable dialogs are
+    // picked up and then correctly re-saved after launching the updater (STORM-1268).
+    LLUI::settings_map_t settings_map;
+    settings_map["config"] = &gSavedSettings;
+    settings_map["ignores"] = &gWarningSettings;
+    settings_map["floater"] = &gSavedSettings; // *TODO: New settings file
+    settings_map["account"] = &gSavedPerAccountSettings;
+
+    LLUI::initParamSingleton(settings_map,
+        LLUIImageList::getInstance(),
+        ui_audio_callback,
+        deferred_ui_audio_callback);
+    LL_INFOS("InitInfo") << "UI initialized." << LL_ENDL ;
+
+    // NOW LLUI::getLanguage() should work. gDirUtilp must know the language
+    // for this session ASAP so all the file-loading commands that follow,
+    // that use findSkinnedFilenames(), will include the localized files.
+    gDirUtilp->setSkinFolder(gDirUtilp->getSkinFolder(), LLUI::getLanguage());
+
+    // Setup LLTrans after LLUI::initClass has been called.
+    initStrings();
 
     // initialize LLWearableType translation bridge.
     // Will immediately use LLTranslationBridge to init LLWearableDictionary
     LLWearableType::initParamSingleton(trans);
 
-	// Setup notifications after LLUI::initClass() has been called.
-	LLNotifications::instance();
-	LL_INFOS("InitInfo") << "Notifications initialized." << LL_ENDL ;
+    // Setup notifications after LLUI::initClass() has been called.
+    LLNotifications::instance();
+    LL_INFOS("InitInfo") << "Notifications initialized." << LL_ENDL ;
 
-	//////////////////////////////////////////////////////////////////////////////
-	//////////////////////////////////////////////////////////////////////////////
-	//////////////////////////////////////////////////////////////////////////////
-	//////////////////////////////////////////////////////////////////////////////
-	// *FIX: The following code isn't grouped into functions yet.
+    //////////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////////
+    //////////////////////////////////////////////////////////////////////////////
+    // *FIX: The following code isn't grouped into functions yet.
 
-	//
-	// Various introspection concerning the libs we're using - particularly
-	// the libs involved in getting to a full login screen.
-	//
-	LL_INFOS("InitInfo") << "J2C Engine is: " << LLImageJ2C::getEngineInfo() << LL_ENDL;
-	LL_INFOS("InitInfo") << "libcurl version is: " << LLCore::LLHttp::getCURLVersion() << LL_ENDL;
+    //
+    // Various introspection concerning the libs we're using - particularly
+    // the libs involved in getting to a full login screen.
+    //
+    LL_INFOS("InitInfo") << "J2C Engine is: " << LLImageJ2C::getEngineInfo() << LL_ENDL;
+    LL_INFOS("InitInfo") << "libcurl version is: " << LLCore::LLHttp::getCURLVersion() << LL_ENDL;
 
-	/////////////////////////////////////////////////
-	// OS-specific login dialogs
-	/////////////////////////////////////////////////
+    /////////////////////////////////////////////////
+    // OS-specific login dialogs
+    /////////////////////////////////////////////////
 
-	//test_cached_control();
+    //test_cached_control();
 
-	// track number of times that app has run
-	mNumSessions = gSavedSettings.getS32("NumSessions");
-	mNumSessions++;
-	gSavedSettings.setS32("NumSessions", mNumSessions);
+    // track number of times that app has run
+    mNumSessions = gSavedSettings.getS32("NumSessions");
+    mNumSessions++;
+    gSavedSettings.setS32("NumSessions", mNumSessions);
 
-	// LLKeyboard relies on LLUI to know what some accelerator keys are called.
-	LLKeyboard::setStringTranslatorFunc( LLTrans::getKeyboardString );
+    // LLKeyboard relies on LLUI to know what some accelerator keys are called.
+    LLKeyboard::setStringTranslatorFunc( LLTrans::getKeyboardString );
 
-	// Provide the text fields with callbacks for opening Urls
-	LLUrlAction::setOpenURLCallback(boost::bind(&LLWeb::loadURL, _1, LLStringUtil::null, LLStringUtil::null));
-	LLUrlAction::setOpenURLInternalCallback(boost::bind(&LLWeb::loadURLInternal, _1, LLStringUtil::null, LLStringUtil::null, false));
-	LLUrlAction::setOpenURLExternalCallback(boost::bind(&LLWeb::loadURLExternal, _1, true, LLStringUtil::null));
-	LLUrlAction::setExecuteSLURLCallback(&LLURLDispatcher::dispatchFromTextEditor);
+    // Provide the text fields with callbacks for opening Urls
+    LLUrlAction::setOpenURLCallback(boost::bind(&LLWeb::loadURL, _1, LLStringUtil::null, LLStringUtil::null));
+    LLUrlAction::setOpenURLInternalCallback(boost::bind(&LLWeb::loadURLInternal, _1, LLStringUtil::null, LLStringUtil::null, false));
+    LLUrlAction::setOpenURLExternalCallback(boost::bind(&LLWeb::loadURLExternal, _1, true, LLStringUtil::null));
+    LLUrlAction::setExecuteSLURLCallback(&LLURLDispatcher::dispatchFromTextEditor);
 
-	// Let code in llui access the viewer help floater
-	LLUI::getInstance()->mHelpImpl = LLViewerHelp::getInstance();
+    // Let code in llui access the viewer help floater
+    LLUI::getInstance()->mHelpImpl = LLViewerHelp::getInstance();
 
-	LL_INFOS("InitInfo") << "UI initialization is done." << LL_ENDL ;
+    LL_INFOS("InitInfo") << "UI initialization is done." << LL_ENDL ;
 
-	// Load translations for tooltips
-	LLFloater::initClass();
-	LLUrlFloaterDispatchHandler::registerInDispatcher();
+    // Load translations for tooltips
+    LLFloater::initClass();
+    LLUrlFloaterDispatchHandler::registerInDispatcher();
 
-	/////////////////////////////////////////////////
+    /////////////////////////////////////////////////
 
-	LLToolMgr::getInstance(); // Initialize tool manager if not already instantiated
+    LLToolMgr::getInstance(); // Initialize tool manager if not already instantiated
 
-	LLViewerFloaterReg::registerFloaters();
+    LLViewerFloaterReg::registerFloaters();
 
-	/////////////////////////////////////////////////
-	//
-	// Load settings files
-	//
-	//
-	LLGroupMgr::parseRoleActions("role_actions.xml");
+    /////////////////////////////////////////////////
+    //
+    // Load settings files
+    //
+    //
+    LLGroupMgr::parseRoleActions("role_actions.xml");
 
-	LLAgent::parseTeleportMessages("teleport_strings.xml");
+    LLAgent::parseTeleportMessages("teleport_strings.xml");
 
-	// load MIME type -> media impl mappings
-	std::string mime_types_name;
+    // load MIME type -> media impl mappings
+    std::string mime_types_name;
 #if LL_DARWIN
-	mime_types_name = "mime_types_mac.xml";
+    mime_types_name = "mime_types_mac.xml";
 #elif LL_LINUX
-	mime_types_name = "mime_types_linux.xml";
+    mime_types_name = "mime_types_linux.xml";
 #else
-	mime_types_name = "mime_types.xml";
+    mime_types_name = "mime_types.xml";
 #endif
-	LLMIMETypes::parseMIMETypes( mime_types_name );
-
-	// Copy settings to globals. *TODO: Remove or move to appropriage class initializers
-	settings_to_globals();
-	// Setup settings listeners
-	settings_setup_listeners();
-	// Modify settings based on system configuration and compile options
-	settings_modify();
-
-	// Find partition serial number (Windows) or hardware serial (Mac)
-	mSerialNumber = generateSerialNumber();
-
-	// do any necessary set-up for accepting incoming SLURLs from apps
-	initSLURLHandler();
-
-	if(false == initHardwareTest())
-	{
-		// Early out from user choice.
-		return false;
-	}
-	LL_INFOS("InitInfo") << "Hardware test initialization done." << LL_ENDL ;
-
-	// Prepare for out-of-memory situations, during which we will crash on
-	// purpose and save a dump.
+    LLMIMETypes::parseMIMETypes( mime_types_name );
+
+    // Copy settings to globals. *TODO: Remove or move to appropriage class initializers
+    settings_to_globals();
+    // Setup settings listeners
+    settings_setup_listeners();
+    // Modify settings based on system configuration and compile options
+    settings_modify();
+
+    // Find partition serial number (Windows) or hardware serial (Mac)
+    mSerialNumber = generateSerialNumber();
+
+    // do any necessary set-up for accepting incoming SLURLs from apps
+    initSLURLHandler();
+
+    if(false == initHardwareTest())
+    {
+        // Early out from user choice.
+        return false;
+    }
+    LL_INFOS("InitInfo") << "Hardware test initialization done." << LL_ENDL ;
+
+    // Prepare for out-of-memory situations, during which we will crash on
+    // purpose and save a dump.
 #if LL_WINDOWS && LL_RELEASE_FOR_DOWNLOAD && LL_USE_SMARTHEAP
-	MemSetErrorHandler(first_mem_error_handler);
+    MemSetErrorHandler(first_mem_error_handler);
 #endif // LL_WINDOWS && LL_RELEASE_FOR_DOWNLOAD && LL_USE_SMARTHEAP
 
-	// *Note: this is where gViewerStats used to be created.
+    // *Note: this is where gViewerStats used to be created.
 
-	if (!initCache())
-	{
-		LL_WARNS("InitInfo") << "Failed to init cache" << LL_ENDL;
-		std::ostringstream msg;
-		msg << LLTrans::getString("MBUnableToAccessFile");
-		OSMessageBox(msg.str(),LLStringUtil::null,OSMB_OK);
-		return 0;
-	}
-	LL_INFOS("InitInfo") << "Cache initialization is done." << LL_ENDL ;
+    if (!initCache())
+    {
+        LL_WARNS("InitInfo") << "Failed to init cache" << LL_ENDL;
+        std::ostringstream msg;
+        msg << LLTrans::getString("MBUnableToAccessFile");
+        OSMessageBox(msg.str(),LLStringUtil::null,OSMB_OK);
+        return 0;
+    }
+    LL_INFOS("InitInfo") << "Cache initialization is done." << LL_ENDL ;
 
     // Initialize event recorder
     LLViewerEventRecorder::createInstance();
 
-	//
-	// Initialize the window
-	//
-	gGLActive = TRUE;
-	initWindow();
-	LL_INFOS("InitInfo") << "Window is initialized." << LL_ENDL ;
+    //
+    // Initialize the window
+    //
+    gGLActive = TRUE;
+    initWindow();
+    LL_INFOS("InitInfo") << "Window is initialized." << LL_ENDL ;
 
     // writeSystemInfo can be called after window is initialized (gViewerWindow non-null)
     writeSystemInfo();
 
-	// initWindow also initializes the Feature List, so now we can initialize this global.
-	LLCubeMap::sUseCubeMaps = LLFeatureManager::getInstance()->isFeatureAvailable("RenderCubeMap");
+    // initWindow also initializes the Feature List, so now we can initialize this global.
+    LLCubeMap::sUseCubeMaps = LLFeatureManager::getInstance()->isFeatureAvailable("RenderCubeMap");
 
-	// call all self-registered classes
-	LLInitClassList::instance().fireCallbacks();
+    // call all self-registered classes
+    LLInitClassList::instance().fireCallbacks();
 
-	LLFolderViewItem::initClass(); // SJB: Needs to happen after initWindow(), not sure why but related to fonts
+    LLFolderViewItem::initClass(); // SJB: Needs to happen after initWindow(), not sure why but related to fonts
 
-	gGLManager.getGLInfo(gDebugInfo);
-	gGLManager.printGLInfoString();
+    gGLManager.getGLInfo(gDebugInfo);
+    gGLManager.printGLInfoString();
 
-	// If we don't have the right GL requirements, exit.
-	if (!gGLManager.mHasRequirements)
-	{
+    // If we don't have the right GL requirements, exit.
+    if (!gGLManager.mHasRequirements)
+    {
         // already handled with a MBVideoDrvErr
-		return 0;
-	}
-
-	// Without SSE2 support we will crash almost immediately, warn here.
-	if (!gSysCPU.hasSSE2())
-	{
-		// can't use an alert here since we're exiting and
-		// all hell breaks lose.
-		OSMessageBox(
-			LLNotifications::instance().getGlobalString("UnsupportedCPUSSE2"),
-			LLStringUtil::null,
-			OSMB_OK);
-		return 0;
-	}
-
-	// alert the user if they are using unsupported hardware
-	if(!gSavedSettings.getBOOL("AlertedUnsupportedHardware"))
-	{
-		bool unsupported = false;
-		LLSD args;
-		std::string minSpecs;
-
-		// get cpu data from xml
-		std::stringstream minCPUString(LLNotifications::instance().getGlobalString("UnsupportedCPUAmount"));
-		S32 minCPU = 0;
-		minCPUString >> minCPU;
-
-		// get RAM data from XML
-		std::stringstream minRAMString(LLNotifications::instance().getGlobalString("UnsupportedRAMAmount"));
-		U64Bytes minRAM;
-		minRAMString >> minRAM;
-
-		if(!LLFeatureManager::getInstance()->isGPUSupported() && LLFeatureManager::getInstance()->getGPUClass() != GPU_CLASS_UNKNOWN)
-		{
-			minSpecs += LLNotifications::instance().getGlobalString("UnsupportedGPU");
-			minSpecs += "\n";
-			unsupported = true;
-		}
-		if(gSysCPU.getMHz() < minCPU)
-		{
-			minSpecs += LLNotifications::instance().getGlobalString("UnsupportedCPU");
-			minSpecs += "\n";
-			unsupported = true;
-		}
-		if(gSysMemory.getPhysicalMemoryKB() < minRAM)
-		{
-			minSpecs += LLNotifications::instance().getGlobalString("UnsupportedRAM");
-			minSpecs += "\n";
-			unsupported = true;
-		}
-
-		if (LLFeatureManager::getInstance()->getGPUClass() == GPU_CLASS_UNKNOWN)
-		{
-			LLNotificationsUtil::add("UnknownGPU");
-		}
-
-		if(unsupported)
-		{
-			if(!gSavedSettings.controlExists("WarnUnsupportedHardware")
-				|| gSavedSettings.getBOOL("WarnUnsupportedHardware"))
-			{
-				args["MINSPECS"] = minSpecs;
-				LLNotificationsUtil::add("UnsupportedHardware", args );
-			}
-
-		}
-	}
+        return 0;
+    }
+
+    // Without SSE2 support we will crash almost immediately, warn here.
+    if (!gSysCPU.hasSSE2())
+    {
+        // can't use an alert here since we're exiting and
+        // all hell breaks lose.
+        OSMessageBox(
+            LLNotifications::instance().getGlobalString("UnsupportedCPUSSE2"),
+            LLStringUtil::null,
+            OSMB_OK);
+        return 0;
+    }
+
+    // alert the user if they are using unsupported hardware
+    if(!gSavedSettings.getBOOL("AlertedUnsupportedHardware"))
+    {
+        bool unsupported = false;
+        LLSD args;
+        std::string minSpecs;
+
+        // get cpu data from xml
+        std::stringstream minCPUString(LLNotifications::instance().getGlobalString("UnsupportedCPUAmount"));
+        S32 minCPU = 0;
+        minCPUString >> minCPU;
+
+        // get RAM data from XML
+        std::stringstream minRAMString(LLNotifications::instance().getGlobalString("UnsupportedRAMAmount"));
+        U64Bytes minRAM;
+        minRAMString >> minRAM;
+
+        if(!LLFeatureManager::getInstance()->isGPUSupported() && LLFeatureManager::getInstance()->getGPUClass() != GPU_CLASS_UNKNOWN)
+        {
+            minSpecs += LLNotifications::instance().getGlobalString("UnsupportedGPU");
+            minSpecs += "\n";
+            unsupported = true;
+        }
+        if(gSysCPU.getMHz() < minCPU)
+        {
+            minSpecs += LLNotifications::instance().getGlobalString("UnsupportedCPU");
+            minSpecs += "\n";
+            unsupported = true;
+        }
+        if(gSysMemory.getPhysicalMemoryKB() < minRAM)
+        {
+            minSpecs += LLNotifications::instance().getGlobalString("UnsupportedRAM");
+            minSpecs += "\n";
+            unsupported = true;
+        }
+
+        if (LLFeatureManager::getInstance()->getGPUClass() == GPU_CLASS_UNKNOWN)
+        {
+            LLNotificationsUtil::add("UnknownGPU");
+        }
+
+        if(unsupported)
+        {
+            if(!gSavedSettings.controlExists("WarnUnsupportedHardware")
+                || gSavedSettings.getBOOL("WarnUnsupportedHardware"))
+            {
+                args["MINSPECS"] = minSpecs;
+                LLNotificationsUtil::add("UnsupportedHardware", args );
+            }
+
+        }
+    }
 
 #if LL_WINDOWS && ADDRESS_SIZE == 64
     if (gGLManager.mIsIntel)
@@ -1084,54 +1084,54 @@ bool LLAppViewer::init()
 
     // Obsolete? mExpectedGLVersion is always zero
 #if LL_WINDOWS
-	if (gGLManager.mGLVersion < LLFeatureManager::getInstance()->getExpectedGLVersion())
-	{
-		std::string url;
-		if (gGLManager.mIsIntel)
-		{
-			url = LLTrans::getString("IntelDriverPage");
-		}
-		else if (gGLManager.mIsNVIDIA)
-		{
-			url = LLTrans::getString("NvidiaDriverPage");
-		}
-		else if (gGLManager.mIsAMD)
-		{
-			url = LLTrans::getString("AMDDriverPage");
-		}
-
-		if (!url.empty())
-		{
-			LLNotificationsUtil::add("OldGPUDriver", LLSD().with("URL", url));
-		}
-	}
+    if (gGLManager.mGLVersion < LLFeatureManager::getInstance()->getExpectedGLVersion())
+    {
+        std::string url;
+        if (gGLManager.mIsIntel)
+        {
+            url = LLTrans::getString("IntelDriverPage");
+        }
+        else if (gGLManager.mIsNVIDIA)
+        {
+            url = LLTrans::getString("NvidiaDriverPage");
+        }
+        else if (gGLManager.mIsAMD)
+        {
+            url = LLTrans::getString("AMDDriverPage");
+        }
+
+        if (!url.empty())
+        {
+            LLNotificationsUtil::add("OldGPUDriver", LLSD().with("URL", url));
+        }
+    }
 #endif
 
 
-	// save the graphics card
-	gDebugInfo["GraphicsCard"] = LLFeatureManager::getInstance()->getGPUString();
+    // save the graphics card
+    gDebugInfo["GraphicsCard"] = LLFeatureManager::getInstance()->getGPUString();
 
-	// Save the current version to the prefs file
-	gSavedSettings.setString("LastRunVersion",
-							 LLVersionInfo::instance().getChannelAndVersion());
+    // Save the current version to the prefs file
+    gSavedSettings.setString("LastRunVersion",
+                             LLVersionInfo::instance().getChannelAndVersion());
 
-	gSimLastTime = gRenderStartTime.getElapsedTimeF32();
-	gSimFrames = (F32)gFrameCount;
+    gSimLastTime = gRenderStartTime.getElapsedTimeF32();
+    gSimFrames = (F32)gFrameCount;
 
     if (gSavedSettings.getBOOL("JoystickEnabled"))
     {
         LLViewerJoystick::getInstance()->init(false);
     }
 
-	try {
-		initializeSecHandler();
-	}
-	catch (const LLProtectedDataException&)
-	{
-	  LLNotificationsUtil::add("CorruptedProtectedDataStore");
-	}
+    try {
+        initializeSecHandler();
+    }
+    catch (const LLProtectedDataException&)
+    {
+      LLNotificationsUtil::add("CorruptedProtectedDataStore");
+    }
 
-	gGLActive = FALSE;
+    gGLActive = FALSE;
 
 #if LL_RELEASE_FOR_DOWNLOAD
     // Skip updater if this is a non-interactive instance
@@ -1170,25 +1170,25 @@ bool LLAppViewer::init()
         }
     }
 
-	LLTextUtil::TextHelpers::iconCallbackCreationFunction = create_text_segment_icon_from_url_match;
+    LLTextUtil::TextHelpers::iconCallbackCreationFunction = create_text_segment_icon_from_url_match;
 
-	//EXT-7013 - On windows for some locale (Japanese) standard
-	//datetime formatting functions didn't support some parameters such as "weekday".
-	//Names for days and months localized in xml are also useful for Polish locale(STORM-107).
-	std::string language = gSavedSettings.getString("Language");
-	if(language == "ja" || language == "pl")
-	{
-		LLStringOps::setupWeekDaysNames(LLTrans::getString("dateTimeWeekdaysNames"));
-		LLStringOps::setupWeekDaysShortNames(LLTrans::getString("dateTimeWeekdaysShortNames"));
-		LLStringOps::setupMonthNames(LLTrans::getString("dateTimeMonthNames"));
-		LLStringOps::setupMonthShortNames(LLTrans::getString("dateTimeMonthShortNames"));
-		LLStringOps::setupDayFormat(LLTrans::getString("dateTimeDayFormat"));
-
-		LLStringOps::sAM = LLTrans::getString("dateTimeAM");
-		LLStringOps::sPM = LLTrans::getString("dateTimePM");
-	}
+    //EXT-7013 - On windows for some locale (Japanese) standard
+    //datetime formatting functions didn't support some parameters such as "weekday".
+    //Names for days and months localized in xml are also useful for Polish locale(STORM-107).
+    std::string language = gSavedSettings.getString("Language");
+    if(language == "ja" || language == "pl")
+    {
+        LLStringOps::setupWeekDaysNames(LLTrans::getString("dateTimeWeekdaysNames"));
+        LLStringOps::setupWeekDaysShortNames(LLTrans::getString("dateTimeWeekdaysShortNames"));
+        LLStringOps::setupMonthNames(LLTrans::getString("dateTimeMonthNames"));
+        LLStringOps::setupMonthShortNames(LLTrans::getString("dateTimeMonthShortNames"));
+        LLStringOps::setupDayFormat(LLTrans::getString("dateTimeDayFormat"));
+
+        LLStringOps::sAM = LLTrans::getString("dateTimeAM");
+        LLStringOps::sPM = LLTrans::getString("dateTimePM");
+    }
 
-	LLAgentLanguage::init();
+    LLAgentLanguage::init();
 
     /// Tell the Coprocedure manager how to discover and store the pool sizes
     // what I wanted
@@ -1196,27 +1196,27 @@ bool LLAppViewer::init()
         boost::bind(&LLControlGroup::getU32, boost::ref(gSavedSettings), _1),
         boost::bind(&LLControlGroup::declareU32, boost::ref(gSavedSettings), _1, _2, _3, LLControlVariable::PERSIST_ALWAYS));
 
-	// TODO: consider moving proxy initialization here or LLCopocedureManager after proxy initialization, may be implement
-	// some other protection to make sure we don't use network before initializng proxy
+    // TODO: consider moving proxy initialization here or LLCopocedureManager after proxy initialization, may be implement
+    // some other protection to make sure we don't use network before initializng proxy
 
-	/*----------------------------------------------------------------------*/
-	// nat 2016-06-29 moved the following here from the former mainLoop().
-	mMainloopTimeout = new LLWatchdogTimeout();
+    /*----------------------------------------------------------------------*/
+    // nat 2016-06-29 moved the following here from the former mainLoop().
+    mMainloopTimeout = new LLWatchdogTimeout();
 
-	// Create IO Pump to use for HTTP Requests.
-	gServicePump = new LLPumpIO(gAPRPoolp);
+    // Create IO Pump to use for HTTP Requests.
+    gServicePump = new LLPumpIO(gAPRPoolp);
 
-	// Note: this is where gLocalSpeakerMgr and gActiveSpeakerMgr used to be instantiated.
+    // Note: this is where gLocalSpeakerMgr and gActiveSpeakerMgr used to be instantiated.
 
-	LLVoiceChannel::initClass();
-	LLVoiceClient::initParamSingleton(gServicePump);
-	LLVoiceChannel::setCurrentVoiceChannelChangedCallback(boost::bind(&LLFloaterIMContainer::onCurrentChannelChanged, _1), true);
+    LLVoiceChannel::initClass();
+    LLVoiceClient::initParamSingleton(gServicePump);
+    LLVoiceChannel::setCurrentVoiceChannelChangedCallback(boost::bind(&LLFloaterIMContainer::onCurrentChannelChanged, _1), true);
 
-	joystick = LLViewerJoystick::getInstance();
-	joystick->setNeedsReset(true);
-	/*----------------------------------------------------------------------*/
-	// Load User's bindings
-	loadKeyBindings();
+    joystick = LLViewerJoystick::getInstance();
+    joystick->setNeedsReset(true);
+    /*----------------------------------------------------------------------*/
+    // Load User's bindings
+    loadKeyBindings();
 
     //LLSimpleton creations
     LLEnvironment::createInstance();
@@ -1234,27 +1234,27 @@ bool LLAppViewer::init()
 #endif
 
 #ifdef AL_DISCORD
-		ALDiscordManager::getInstance();
-		LL_INFOS("AppInit") << "Discord Integration Initialized." << LL_ENDL; 
+        ALDiscordManager::getInstance();
+        LL_INFOS("AppInit") << "Discord Integration Initialized." << LL_ENDL;
 #endif
 
-	return true;
+    return true;
 }
 
 void LLAppViewer::initMaxHeapSize()
 {
-	//set the max heap size.
-	//here is some info regarding to the max heap size:
-	//------------------------------------------------------------------------------------------
-	// OS       | setting | SL address bits | max manageable memory space | max heap size
-	// Win 32   | default | 32-bit          | 2GB                         | < 1.7GB
-	// Win 32   | /3G     | 32-bit          | 3GB                         | < 1.7GB or 2.7GB
-	//Linux 32  | default | 32-bit          | 3GB                         | < 2.7GB
-	//Linux 32  |HUGEMEM  | 32-bit          | 4GB                         | < 3.7GB
-	//64-bit OS |default  | 32-bit          | 4GB                         | < 3.7GB
-	//64-bit OS |default  | 64-bit          | N/A (> 4GB)                 | N/A (> 4GB)
-	//------------------------------------------------------------------------------------------
-	//currently SL is built under 32-bit setting, we set its max heap size no more than 1.6 GB.
+    //set the max heap size.
+    //here is some info regarding to the max heap size:
+    //------------------------------------------------------------------------------------------
+    // OS       | setting | SL address bits | max manageable memory space | max heap size
+    // Win 32   | default | 32-bit          | 2GB                         | < 1.7GB
+    // Win 32   | /3G     | 32-bit          | 3GB                         | < 1.7GB or 2.7GB
+    //Linux 32  | default | 32-bit          | 3GB                         | < 2.7GB
+    //Linux 32  |HUGEMEM  | 32-bit          | 4GB                         | < 3.7GB
+    //64-bit OS |default  | 32-bit          | 4GB                         | < 3.7GB
+    //64-bit OS |default  | 64-bit          | N/A (> 4GB)                 | N/A (> 4GB)
+    //------------------------------------------------------------------------------------------
+    //currently SL is built under 32-bit setting, we set its max heap size no more than 1.6 GB.
 
  #ifndef LL_X86_64
     F32Gigabytes max_heap_size_gb = (F32Gigabytes)gSavedSettings.getF32("MaxHeapSize") ;
@@ -1271,42 +1271,42 @@ LLTrace::BlockTimerStatHandle FTM_FRAME("Frame");
 
 bool LLAppViewer::frame()
 {
-	bool ret = false;
-
-	if (gSimulateMemLeak)
-	{
-		try
-		{
-			ret = doFrame();
-		}
-		catch (const LLContinueError&)
-		{
-			LOG_UNHANDLED_EXCEPTION("");
-		}
-		catch (const std::bad_alloc&)
-		{
-			LLMemory::logMemoryInfo(TRUE);
-			LLFloaterMemLeak* mem_leak_instance = LLFloaterReg::findTypedInstance<LLFloaterMemLeak>("mem_leaking");
-			if (mem_leak_instance)
-			{
-				mem_leak_instance->stop();
-			}
-			LL_WARNS() << "Bad memory allocation in LLAppViewer::frame()!" << LL_ENDL;
-		}
-	}
-	else
-	{ 
-		try
-		{
-			ret = doFrame();
-		}
-		catch (const LLContinueError&)
-		{
-			LOG_UNHANDLED_EXCEPTION("");
-		}
-	}
-
-	return ret;
+    bool ret = false;
+
+    if (gSimulateMemLeak)
+    {
+        try
+        {
+            ret = doFrame();
+        }
+        catch (const LLContinueError&)
+        {
+            LOG_UNHANDLED_EXCEPTION("");
+        }
+        catch (const std::bad_alloc&)
+        {
+            LLMemory::logMemoryInfo(TRUE);
+            LLFloaterMemLeak* mem_leak_instance = LLFloaterReg::findTypedInstance<LLFloaterMemLeak>("mem_leaking");
+            if (mem_leak_instance)
+            {
+                mem_leak_instance->stop();
+            }
+            LL_WARNS() << "Bad memory allocation in LLAppViewer::frame()!" << LL_ENDL;
+        }
+    }
+    else
+    {
+        try
+        {
+            ret = doFrame();
+        }
+        catch (const LLContinueError&)
+        {
+            LOG_UNHANDLED_EXCEPTION("");
+        }
+    }
+
+    return ret;
 }
 
 bool LLAppViewer::doFrame()
@@ -1399,65 +1399,65 @@ bool LLAppViewer::doFrame()
             }
         }
 
-		if (!LLApp::isExiting())
-		{
-			pingMainloopTimeout("Main:JoystickKeyboard");
-
-			// Scan keyboard for movement keys.  Command keys and typing
-			// are handled by windows callbacks.  Don't do this until we're
-			// done initializing.  JC
-			if (gViewerWindow
-				&& (gHeadlessClient || gViewerWindow->getWindow()->getVisible())
-				&& gViewerWindow->getActive()
-				&& !gViewerWindow->getWindow()->getMinimized()
-				&& LLStartUp::getStartupState() == STATE_STARTED
-				&& (gHeadlessClient || !gViewerWindow->getShowProgress())
-				&& !gFocusMgr.focusLocked())
-			{
+        if (!LLApp::isExiting())
+        {
+            pingMainloopTimeout("Main:JoystickKeyboard");
+
+            // Scan keyboard for movement keys.  Command keys and typing
+            // are handled by windows callbacks.  Don't do this until we're
+            // done initializing.  JC
+            if (gViewerWindow
+                && (gHeadlessClient || gViewerWindow->getWindow()->getVisible())
+                && gViewerWindow->getActive()
+                && !gViewerWindow->getWindow()->getMinimized()
+                && LLStartUp::getStartupState() == STATE_STARTED
+                && (gHeadlessClient || !gViewerWindow->getShowProgress())
+                && !gFocusMgr.focusLocked())
+            {
                 LLPerfStats::RecordSceneTime T (LLPerfStats::StatType_t::RENDER_IDLE);
-				joystick->scanJoystick();
-				gKeyboard->scanKeyboard();
+                joystick->scanJoystick();
+                gKeyboard->scanKeyboard();
                 gViewerInput.scanMouse();
                 if (gAgent.isCrouching())
                     gAgent.moveUp(-1);
-			}
+            }
 
-			// Update state based on messages, user input, object idle.
-			{
-				{
-					LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df pauseMainloopTimeout" )
-					pauseMainloopTimeout(); // *TODO: Remove. Messages shouldn't be stalling for 20+ seconds!
-				}
+            // Update state based on messages, user input, object idle.
+            {
+                {
+                    LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df pauseMainloopTimeout" )
+                    pauseMainloopTimeout(); // *TODO: Remove. Messages shouldn't be stalling for 20+ seconds!
+                }
 
-				{
+                {
                     LLPerfStats::RecordSceneTime T (LLPerfStats::StatType_t::RENDER_IDLE);
                     LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df idle");
-					idle();
-				}
+                    idle();
+                }
 
-				{
-					LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df resumeMainloopTimeout" )
-					resumeMainloopTimeout();
-				}
-			}
+                {
+                    LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df resumeMainloopTimeout" )
+                    resumeMainloopTimeout();
+                }
+            }
 
-			if (gDoDisconnect && (LLStartUp::getStartupState() == STATE_STARTED))
-			{
-				LL_PROFILE_ZONE_NAMED_CATEGORY_APP("Shutdown:SaveSnapshot");
-				pauseMainloopTimeout();
-				saveFinalSnapshot();
+            if (gDoDisconnect && (LLStartUp::getStartupState() == STATE_STARTED))
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_APP("Shutdown:SaveSnapshot");
+                pauseMainloopTimeout();
+                saveFinalSnapshot();
 
                 if (LLVoiceClient::instanceExists())
                 {
                     LLVoiceClient::getInstance()->terminate();
                 }
 
-				disconnectViewer();
-				resumeMainloopTimeout();
-			}
+                disconnectViewer();
+                resumeMainloopTimeout();
+            }
 
-			// Render scene.
-			// *TODO: Should we run display() even during gHeadlessClient?  DK 2011-02-18
+            // Render scene.
+            // *TODO: Should we run display() even during gHeadlessClient?  DK 2011-02-18
             if (!LLApp::isExiting() && !gHeadlessClient && gViewerWindow)
             {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_APP("df Display");
@@ -1481,159 +1481,159 @@ bool LLAppViewer::doFrame()
                     LLViewerStatsRecorder::instance().idle();
                 }
             }
-		}
+        }
 
-		{
-			LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df pauseMainloopTimeout2" )
-			pingMainloopTimeout("Main:Sleep");
+        {
+            LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df pauseMainloopTimeout2" )
+            pingMainloopTimeout("Main:Sleep");
 
-			pauseMainloopTimeout();
-		}
+            pauseMainloopTimeout();
+        }
 
-		// Sleep and run background threads
-		{
-			//LL_RECORD_BLOCK_TIME(SLEEP2);
-			LL_PROFILE_ZONE_WARN( "Sleep2" )
+        // Sleep and run background threads
+        {
+            //LL_RECORD_BLOCK_TIME(SLEEP2);
+            LL_PROFILE_ZONE_WARN( "Sleep2" )
 
-			// yield some time to the os based on command line option
-			static LLCachedControl<S32> yield_time(gSavedSettings, "YieldTime", -1);
-			if(yield_time >= 0)
-			{
+            // yield some time to the os based on command line option
+            static LLCachedControl<S32> yield_time(gSavedSettings, "YieldTime", -1);
+            if(yield_time >= 0)
+            {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_APP("Yield");
-				LL_PROFILE_ZONE_NUM( yield_time )
-				ms_sleep(yield_time);
-			}
-
-			if (gNonInteractive)
-			{
-				S32 non_interactive_ms_sleep_time = 100;
-				LLAppViewer::getTextureCache()->pause();
-				ms_sleep(non_interactive_ms_sleep_time);
-			}
-
-			// yield cooperatively when not running as foreground window
-			// and when not quiting (causes trouble at mac's cleanup stage)
-			if (!LLApp::isExiting()
-				&& ((gViewerWindow && !gViewerWindow->getWindow()->getVisible())
-					|| !gFocusMgr.getAppHasFocus()))
-			{
-				// Sleep if we're not rendering, or the window is minimized.
-				static LLCachedControl<S32> s_background_yield_time(gSavedSettings, "BackgroundYieldTime", 40);
-				S32 milliseconds_to_sleep = llclamp((S32)s_background_yield_time, 0, 1000);
-				// don't sleep when BackgroundYieldTime set to 0, since this will still yield to other threads
-				// of equal priority on Windows
-				if (milliseconds_to_sleep > 0)
-				{
+                LL_PROFILE_ZONE_NUM( yield_time )
+                ms_sleep(yield_time);
+            }
+
+            if (gNonInteractive)
+            {
+                S32 non_interactive_ms_sleep_time = 100;
+                LLAppViewer::getTextureCache()->pause();
+                ms_sleep(non_interactive_ms_sleep_time);
+            }
+
+            // yield cooperatively when not running as foreground window
+            // and when not quiting (causes trouble at mac's cleanup stage)
+            if (!LLApp::isExiting()
+                && ((gViewerWindow && !gViewerWindow->getWindow()->getVisible())
+                    || !gFocusMgr.getAppHasFocus()))
+            {
+                // Sleep if we're not rendering, or the window is minimized.
+                static LLCachedControl<S32> s_background_yield_time(gSavedSettings, "BackgroundYieldTime", 40);
+                S32 milliseconds_to_sleep = llclamp((S32)s_background_yield_time, 0, 1000);
+                // don't sleep when BackgroundYieldTime set to 0, since this will still yield to other threads
+                // of equal priority on Windows
+                if (milliseconds_to_sleep > 0)
+                {
                     LLPerfStats::RecordSceneTime T ( LLPerfStats::StatType_t::RENDER_SLEEP );
                     ms_sleep(milliseconds_to_sleep);
-					// also pause worker threads during this wait period
-					LLAppViewer::getTextureCache()->pause();
-				}
-			}
-
-			if (mRandomizeFramerate)
-			{
-				ms_sleep(rand() % 200);
-			}
-
-			if (mPeriodicSlowFrame
-				&& (gFrameCount % 10 == 0))
-			{
-				LL_INFOS() << "Periodic slow frame - sleeping 500 ms" << LL_ENDL;
-				ms_sleep(500);
-			}
-
-			S32 total_work_pending = 0;
-			S32 total_io_pending = 0;
-			{
-				S32 work_pending = 0;
-				S32 io_pending = 0;
-				F32 max_time = llmin(gFrameIntervalSeconds.value() *10.f, 1.f);
-
-				work_pending += updateTextureThreads(max_time);
-
-				{
+                    // also pause worker threads during this wait period
+                    LLAppViewer::getTextureCache()->pause();
+                }
+            }
+
+            if (mRandomizeFramerate)
+            {
+                ms_sleep(rand() % 200);
+            }
+
+            if (mPeriodicSlowFrame
+                && (gFrameCount % 10 == 0))
+            {
+                LL_INFOS() << "Periodic slow frame - sleeping 500 ms" << LL_ENDL;
+                ms_sleep(500);
+            }
+
+            S32 total_work_pending = 0;
+            S32 total_io_pending = 0;
+            {
+                S32 work_pending = 0;
+                S32 io_pending = 0;
+                F32 max_time = llmin(gFrameIntervalSeconds.value() *10.f, 1.f);
+
+                work_pending += updateTextureThreads(max_time);
+
+                {
                     LL_PROFILE_ZONE_NAMED_CATEGORY_APP("LFS Thread");
- 					io_pending += LLLFSThread::updateClass(1);
-				}
-
-				if (io_pending > 1000)
-				{
-					ms_sleep(llmin(io_pending/100,100)); // give the lfs some time to catch up
-				}
-
-				total_work_pending += work_pending ;
-				total_io_pending += io_pending ;
-
-			}
-
-			{
-				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df gMeshRepo" )
-				gMeshRepo.update() ;
-			}
-
-			if(!total_work_pending) //pause texture fetching threads if nothing to process.
-			{
-				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df getTextureCache" )
-				LLAppViewer::getTextureCache()->pause();
-				LLAppViewer::getTextureFetch()->pause();
-			}
-			if(!total_io_pending) //pause file threads if nothing to process.
-			{
-				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df LLVFSThread" )
-				LLLFSThread::sLocal->pause();
-			}
-
-			{
-				LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df resumeMainloopTimeout" )
-			    resumeMainloopTimeout();
-			}
-			pingMainloopTimeout("Main:End");
-		}
-	}
-
-	if (LLApp::isExiting())
-	{
-		// Save snapshot for next time, if we made it through initialization
-		if (STATE_STARTED == LLStartUp::getStartupState())
-		{
-			saveFinalSnapshot();
-		}
-
-		if (LLVoiceClient::instanceExists())
-		{
-			LLVoiceClient::getInstance()->terminate();
-		}
-
-		delete gServicePump;
-		gServicePump = NULL;
-
-		destroyMainloopTimeout();
-
-		LL_INFOS() << "Exiting main_loop" << LL_ENDL;
-	}
+                    io_pending += LLLFSThread::updateClass(1);
+                }
+
+                if (io_pending > 1000)
+                {
+                    ms_sleep(llmin(io_pending/100,100)); // give the lfs some time to catch up
+                }
+
+                total_work_pending += work_pending ;
+                total_io_pending += io_pending ;
+
+            }
+
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df gMeshRepo" )
+                gMeshRepo.update() ;
+            }
+
+            if(!total_work_pending) //pause texture fetching threads if nothing to process.
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df getTextureCache" )
+                LLAppViewer::getTextureCache()->pause();
+                LLAppViewer::getTextureFetch()->pause();
+            }
+            if(!total_io_pending) //pause file threads if nothing to process.
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df LLVFSThread" )
+                LLLFSThread::sLocal->pause();
+            }
+
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_APP( "df resumeMainloopTimeout" )
+                resumeMainloopTimeout();
+            }
+            pingMainloopTimeout("Main:End");
+        }
+    }
+
+    if (LLApp::isExiting())
+    {
+        // Save snapshot for next time, if we made it through initialization
+        if (STATE_STARTED == LLStartUp::getStartupState())
+        {
+            saveFinalSnapshot();
+        }
+
+        if (LLVoiceClient::instanceExists())
+        {
+            LLVoiceClient::getInstance()->terminate();
+        }
+
+        delete gServicePump;
+        gServicePump = NULL;
+
+        destroyMainloopTimeout();
+
+        LL_INFOS() << "Exiting main_loop" << LL_ENDL;
+    }
     }LLPerfStats::StatsRecorder::endFrame();
     LL_PROFILER_FRAME_END
 
-	return ! LLApp::isRunning();
+    return ! LLApp::isRunning();
 }
 
 S32 LLAppViewer::updateTextureThreads(F32 max_time)
 {
-	S32 work_pending = 0;
-	{
+    S32 work_pending = 0;
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_APP("Texture Cache");
- 		work_pending += LLAppViewer::getTextureCache()->update(max_time); // unpauses the texture cache thread
-	}
-	{
+        work_pending += LLAppViewer::getTextureCache()->update(max_time); // unpauses the texture cache thread
+    }
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_APP("Image Decode");
-	 	work_pending += LLAppViewer::getImageDecodeThread()->update(max_time); // unpauses the image thread
-	}
-	{
+        work_pending += LLAppViewer::getImageDecodeThread()->update(max_time); // unpauses the image thread
+    }
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_APP("Image Fetch");
-	 	work_pending += LLAppViewer::getTextureFetch()->update(max_time); // unpauses the texture fetch thread
-	}
-	return work_pending;
+        work_pending += LLAppViewer::getTextureFetch()->update(max_time); // unpauses the texture fetch thread
+    }
+    return work_pending;
 }
 
 void LLAppViewer::flushLFSIO()
@@ -1656,195 +1656,195 @@ void LLAppViewer::flushLFSIO()
 
 bool LLAppViewer::cleanup()
 {
-	//ditch LLVOAvatarSelf instance
-	gAgentAvatarp = NULL;
+    //ditch LLVOAvatarSelf instance
+    gAgentAvatarp = NULL;
 
     LLNotifications::instance().clear();
 
-	// workaround for DEV-35406 crash on shutdown
-	LLEventPumps::instance().reset(true);
+    // workaround for DEV-35406 crash on shutdown
+    LLEventPumps::instance().reset(true);
 
-	//dump scene loading monitor results
-	if (LLSceneMonitor::instanceExists())
-	{
-		if (!isSecondInstance())
-		{
+    //dump scene loading monitor results
+    if (LLSceneMonitor::instanceExists())
+    {
+        if (!isSecondInstance())
+        {
             std::string dump_path = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "scene_monitor_results.csv");
-			LLSceneMonitor::instance().dumpToFile(dump_path);
-		}
-		LLSceneMonitor::deleteSingleton();
-	}
-
-	// There used to be an 'if (LLFastTimerView::sAnalyzePerformance)' block
-	// here, completely redundant with the one that occurs later in this same
-	// function. Presumably the duplication was due to an automated merge gone
-	// bad. Not knowing which instance to prefer, we chose to retain the later
-	// one because it happens just after mFastTimerLogThread is deleted. This
-	// comment is in case we guessed wrong, so we can move it here instead.
+            LLSceneMonitor::instance().dumpToFile(dump_path);
+        }
+        LLSceneMonitor::deleteSingleton();
+    }
+
+    // There used to be an 'if (LLFastTimerView::sAnalyzePerformance)' block
+    // here, completely redundant with the one that occurs later in this same
+    // function. Presumably the duplication was due to an automated merge gone
+    // bad. Not knowing which instance to prefer, we chose to retain the later
+    // one because it happens just after mFastTimerLogThread is deleted. This
+    // comment is in case we guessed wrong, so we can move it here instead.
 
 #if LL_LINUX
-	// remove any old breakpad minidump files from the log directory
-	if (! isError())
-	{
-		std::string logdir = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "");
-		gDirUtilp->deleteFilesInDir(logdir, "*-*-*-*-*.dmp");
-	}
+    // remove any old breakpad minidump files from the log directory
+    if (! isError())
+    {
+        std::string logdir = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "");
+        gDirUtilp->deleteFilesInDir(logdir, "*-*-*-*-*.dmp");
+    }
 #endif
 
-	// Kill off LLLeap objects. We can find them all because LLLeap is derived
-	// from LLInstanceTracker.
-	LLLeap::instance_snapshot().deleteAll();
+    // Kill off LLLeap objects. We can find them all because LLLeap is derived
+    // from LLInstanceTracker.
+    LLLeap::instance_snapshot().deleteAll();
 
-	//flag all elements as needing to be destroyed immediately
-	// to ensure shutdown order
-	LLMortician::setZealous(TRUE);
+    //flag all elements as needing to be destroyed immediately
+    // to ensure shutdown order
+    LLMortician::setZealous(TRUE);
 
     // Give any remaining SLPlugin instances a chance to exit cleanly.
     LLPluginProcessParent::shutdown();
 
-	disconnectViewer();
-	LLViewerCamera::deleteSingleton();
+    disconnectViewer();
+    LLViewerCamera::deleteSingleton();
+
+    LL_INFOS() << "Viewer disconnected" << LL_ENDL;
 
-	LL_INFOS() << "Viewer disconnected" << LL_ENDL;
-	
-	if (gKeyboard)
-	{
-		gKeyboard->resetKeys();
-	}
+    if (gKeyboard)
+    {
+        gKeyboard->resetKeys();
+    }
 
-	display_cleanup();
+    display_cleanup();
 
-	release_start_screen(); // just in case
+    release_start_screen(); // just in case
 
-	LLError::logToFixedBuffer(NULL); // stop the fixed buffer recorder
+    LLError::logToFixedBuffer(NULL); // stop the fixed buffer recorder
 
-	LL_INFOS() << "Cleaning Up" << LL_ENDL;
+    LL_INFOS() << "Cleaning Up" << LL_ENDL;
 
-	// shut down mesh streamer
-	gMeshRepo.shutdown();
+    // shut down mesh streamer
+    gMeshRepo.shutdown();
 
-	// shut down Havok
-	LLPhysicsExtensions::quitSystem();
+    // shut down Havok
+    LLPhysicsExtensions::quitSystem();
 
-	// Must clean up texture references before viewer window is destroyed.
-	if(LLHUDManager::instanceExists())
-	{
-		LLHUDManager::getInstance()->updateEffects();
-		LLHUDObject::updateAll();
-		LLHUDManager::getInstance()->cleanupEffects();
-		LLHUDObject::cleanupHUDObjects();
-		LL_INFOS() << "HUD Objects cleaned up" << LL_ENDL;
-	}
+    // Must clean up texture references before viewer window is destroyed.
+    if(LLHUDManager::instanceExists())
+    {
+        LLHUDManager::getInstance()->updateEffects();
+        LLHUDObject::updateAll();
+        LLHUDManager::getInstance()->cleanupEffects();
+        LLHUDObject::cleanupHUDObjects();
+        LL_INFOS() << "HUD Objects cleaned up" << LL_ENDL;
+    }
 
-	LLKeyframeDataCache::clear();
+    LLKeyframeDataCache::clear();
 
- 	// End TransferManager before deleting systems it depends on (Audio, AssetStorage)
+    // End TransferManager before deleting systems it depends on (Audio, AssetStorage)
 #if 0 // this seems to get us stuck in an infinite loop...
-	gTransferManager.cleanup();
+    gTransferManager.cleanup();
 #endif
 
-	// Note: this is where gWorldMap used to be deleted.
+    // Note: this is where gWorldMap used to be deleted.
 
-	// Note: this is where gHUDManager used to be deleted.
-	if(LLHUDManager::instanceExists())
-	{
-		LLHUDManager::getInstance()->shutdownClass();
-	}
+    // Note: this is where gHUDManager used to be deleted.
+    if(LLHUDManager::instanceExists())
+    {
+        LLHUDManager::getInstance()->shutdownClass();
+    }
 
-	delete gAssetStorage;
-	gAssetStorage = NULL;
+    delete gAssetStorage;
+    gAssetStorage = NULL;
 
-	LLPolyMesh::freeAllMeshes();
+    LLPolyMesh::freeAllMeshes();
 
-	LLStartUp::cleanupNameCache();
+    LLStartUp::cleanupNameCache();
 
-	// Note: this is where gLocalSpeakerMgr and gActiveSpeakerMgr used to be deleted.
+    // Note: this is where gLocalSpeakerMgr and gActiveSpeakerMgr used to be deleted.
 
-	if (LLWorldMap::instanceExists())
-	{
-		LLWorldMap::getInstance()->reset(); // release any images
-	}
+    if (LLWorldMap::instanceExists())
+    {
+        LLWorldMap::getInstance()->reset(); // release any images
+    }
 
-	LLCalc::cleanUp();
+    LLCalc::cleanUp();
 
-	LL_INFOS() << "Global stuff deleted" << LL_ENDL;
+    LL_INFOS() << "Global stuff deleted" << LL_ENDL;
 
-	ALStreamInfo::deleteSingleton();
+    ALStreamInfo::deleteSingleton();
 
-	if (gAudiop)
-	{
+    if (gAudiop)
+    {
         LL_INFOS() << "Shutting down audio" << LL_ENDL;
 
-		// shut down the audio subsystem
+        // shut down the audio subsystem
         gAudiop->shutdown();
 
-		delete gAudiop;
-		gAudiop = nullptr;
-	}
-
-	// Note: this is where LLFeatureManager::getInstance()-> used to be deleted.
+        delete gAudiop;
+        gAudiop = nullptr;
+    }
 
-	// Patch up settings for next time
-	// Must do this before we delete the viewer window,
-	// such that we can suck rectangle information out of
-	// it.
-	cleanupSavedSettings();
-	LL_INFOS() << "Settings patched up" << LL_ENDL;
+    // Note: this is where LLFeatureManager::getInstance()-> used to be deleted.
 
-	// delete some of the files left around in the cache.
-	removeCacheFiles("*.wav");
-	removeCacheFiles("*.tmp");
-	removeCacheFiles("*.lso");
-	removeCacheFiles("*.out");
-	removeCacheFiles("*.dsf");
-	removeCacheFiles("*.bodypart");
-	removeCacheFiles("*.clothing");
+    // Patch up settings for next time
+    // Must do this before we delete the viewer window,
+    // such that we can suck rectangle information out of
+    // it.
+    cleanupSavedSettings();
+    LL_INFOS() << "Settings patched up" << LL_ENDL;
 
-	LL_INFOS() << "Cache files removed" << LL_ENDL;
+    // delete some of the files left around in the cache.
+    removeCacheFiles("*.wav");
+    removeCacheFiles("*.tmp");
+    removeCacheFiles("*.lso");
+    removeCacheFiles("*.out");
+    removeCacheFiles("*.dsf");
+    removeCacheFiles("*.bodypart");
+    removeCacheFiles("*.clothing");
 
-	LL_INFOS() << "Shutting down Views" << LL_ENDL;
+    LL_INFOS() << "Cache files removed" << LL_ENDL;
 
-	// Destroy the UI
-	if( gViewerWindow)
-		gViewerWindow->shutdownViews();
+    LL_INFOS() << "Shutting down Views" << LL_ENDL;
 
-	LL_INFOS() << "Cleaning up Inventory" << LL_ENDL;
+    // Destroy the UI
+    if( gViewerWindow)
+        gViewerWindow->shutdownViews();
 
-	// Cleanup Inventory after the UI since it will delete any remaining observers
-	// (Deleted observers should have already removed themselves)
-	gInventory.cleanupInventory();
+    LL_INFOS() << "Cleaning up Inventory" << LL_ENDL;
 
-	LLCoros::getInstance()->printActiveCoroutines();
+    // Cleanup Inventory after the UI since it will delete any remaining observers
+    // (Deleted observers should have already removed themselves)
+    gInventory.cleanupInventory();
 
-	LL_INFOS() << "Cleaning up Selections" << LL_ENDL;
+    LLCoros::getInstance()->printActiveCoroutines();
 
-	// Clean up selection managers after UI is destroyed, as UI may be observing them.
-	// Clean up before GL is shut down because we might be holding on to objects with texture references
-	LLSelectMgr::cleanupGlobals();
+    LL_INFOS() << "Cleaning up Selections" << LL_ENDL;
 
-	LL_INFOS() << "Shutting down OpenGL" << LL_ENDL;
+    // Clean up selection managers after UI is destroyed, as UI may be observing them.
+    // Clean up before GL is shut down because we might be holding on to objects with texture references
+    LLSelectMgr::cleanupGlobals();
 
-	// Shut down OpenGL
-	if( gViewerWindow)
-	{
-		gViewerWindow->shutdownGL();
+    LL_INFOS() << "Shutting down OpenGL" << LL_ENDL;
 
-		// Destroy window, and make sure we're not fullscreen
-		// This may generate window reshape and activation events.
-		// Therefore must do this before destroying the message system.
-		delete gViewerWindow;
-		gViewerWindow = NULL;
-		LL_INFOS() << "ViewerWindow deleted" << LL_ENDL;
-	}
+    // Shut down OpenGL
+    if( gViewerWindow)
+    {
+        gViewerWindow->shutdownGL();
+
+        // Destroy window, and make sure we're not fullscreen
+        // This may generate window reshape and activation events.
+        // Therefore must do this before destroying the message system.
+        delete gViewerWindow;
+        gViewerWindow = NULL;
+        LL_INFOS() << "ViewerWindow deleted" << LL_ENDL;
+    }
 
     LLSplashScreen::show();
     LLSplashScreen::update(LLTrans::getString("ShuttingDown"));
 
-	LL_INFOS() << "Cleaning up Keyboard & Joystick" << LL_ENDL;
+    LL_INFOS() << "Cleaning up Keyboard & Joystick" << LL_ENDL;
 
-	// viewer UI relies on keyboard so keep it aound until viewer UI isa gone
-	delete gKeyboard;
-	gKeyboard = NULL;
+    // viewer UI relies on keyboard so keep it aound until viewer UI isa gone
+    delete gKeyboard;
+    gKeyboard = NULL;
 
     if (LLViewerJoystick::instanceExists())
     {
@@ -1852,281 +1852,281 @@ bool LLAppViewer::cleanup()
         LLViewerJoystick::getInstance()->terminate();
     }
 
-	LL_INFOS() << "Cleaning up Objects" << LL_ENDL;
+    LL_INFOS() << "Cleaning up Objects" << LL_ENDL;
 
-	LLViewerObject::cleanupVOClasses();
+    LLViewerObject::cleanupVOClasses();
 
-	SUBSYSTEM_CLEANUP(LLAvatarAppearance);
+    SUBSYSTEM_CLEANUP(LLAvatarAppearance);
 
-	LLTracker::cleanupInstance();
+    LLTracker::cleanupInstance();
 
-	// *FIX: This is handled in LLAppViewerWin32::cleanup().
-	// I'm keeping the comment to remember its order in cleanup,
-	// in case of unforseen dependency.
-	//#if LL_WINDOWS
-	//	gDXHardware.cleanup();
-	//#endif // LL_WINDOWS
+    // *FIX: This is handled in LLAppViewerWin32::cleanup().
+    // I'm keeping the comment to remember its order in cleanup,
+    // in case of unforseen dependency.
+    //#if LL_WINDOWS
+    //  gDXHardware.cleanup();
+    //#endif // LL_WINDOWS
 
-	LLVolumeMgr* volume_manager = LLPrimitive::getVolumeManager();
-	if (!volume_manager->cleanup())
-	{
-		LL_WARNS() << "Remaining references in the volume manager!" << LL_ENDL;
-	}
-	LLPrimitive::cleanupVolumeManager();
+    LLVolumeMgr* volume_manager = LLPrimitive::getVolumeManager();
+    if (!volume_manager->cleanup())
+    {
+        LL_WARNS() << "Remaining references in the volume manager!" << LL_ENDL;
+    }
+    LLPrimitive::cleanupVolumeManager();
 
-	LL_INFOS() << "Additional Cleanup..." << LL_ENDL;
+    LL_INFOS() << "Additional Cleanup..." << LL_ENDL;
 
-	LLViewerParcelMgr::cleanupGlobals();
+    LLViewerParcelMgr::cleanupGlobals();
 
-	// *Note: this is where gViewerStats used to be deleted.
+    // *Note: this is where gViewerStats used to be deleted.
 
- 	//end_messaging_system();
+    //end_messaging_system();
 
-	LLPrimitive::cleanupVolumeManager();
-	SUBSYSTEM_CLEANUP(LLWorldMapView);
-	SUBSYSTEM_CLEANUP(LLFolderViewItem);
-	LL_INFOS() << "Saving Data" << LL_ENDL;
+    LLPrimitive::cleanupVolumeManager();
+    SUBSYSTEM_CLEANUP(LLWorldMapView);
+    SUBSYSTEM_CLEANUP(LLFolderViewItem);
+    LL_INFOS() << "Saving Data" << LL_ENDL;
 
-	// Store the time of our current logoff
-	gSavedPerAccountSettings.setU32("LastLogoff", time_corrected());
+    // Store the time of our current logoff
+    gSavedPerAccountSettings.setU32("LastLogoff", time_corrected());
 
     if (LLEnvironment::instanceExists())
     {
-		//Store environment settings if necessary
+        //Store environment settings if necessary
         LLEnvironment::getInstance()->saveToSettings();
     }
 
-	// Must do this after all panels have been deleted because panels that have persistent rects
-	// save their rects on delete.
-	gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
-
-	LLUIColorTable::instance().saveUserSettings(gSavedSettings.getBool("ResetUserColorsOnLogout"));
-
-	// PerAccountSettingsFile should be empty if no user has been logged on.
-	// *FIX:Mani This should get really saved in a "logoff" mode.
-	if (gSavedSettings.getString("PerAccountSettingsFile").empty())
-	{
-		LL_INFOS() << "Not saving per-account settings; don't know the account name yet." << LL_ENDL;
-	}
-	// Only save per account settings if the previous login succeeded, otherwise
-	// we might end up with a cleared out settings file in case a previous login
-	// failed after loading per account settings.
-	else if (!mSavePerAccountSettings)
-	{
-		LL_INFOS() << "Not saving per-account settings; last login was not successful." << LL_ENDL;
-	}
-	else
-	{
-		gSavedPerAccountSettings.saveToFile(gSavedSettings.getString("PerAccountSettingsFile"), TRUE);
-		LL_INFOS() << "Saved settings" << LL_ENDL;
-
-		if (LLViewerParcelAskPlay::instanceExists())
-		{
-			LLViewerParcelAskPlay::getInstance()->saveSettings();
-		}
-	}
-
-	std::string warnings_settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, getSettingsFilename("Default", "Warnings"));
-	gWarningSettings.saveToFile(warnings_settings_filename, TRUE);
-
-	// Save URL history file
-	LLURLHistory::saveFile("url_history.xml");
-
-	// save mute list. gMuteList used to also be deleted here too.
-	if (gAgent.isInitialized() && LLMuteList::instanceExists())
-	{
-		LLMuteList::getInstance()->cache(gAgent.getID());
-	}
-
-	//save call log list
-	if (LLConversationLog::instanceExists())
-	{
-		LLConversationLog::instance().cache();
-    }
-
-	if (mPurgeCacheOnExit)
-	{
-		LL_INFOS() << "Purging all cache files on exit" << LL_ENDL;
-		gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,""), "*.*");
-	}
-
-	writeDebugInfo();
-
-	LLLocationHistory::getInstance()->save();
-
-	LLAvatarIconIDCache::getInstance()->save();
-
-	// Stop the plugin read thread if it's running.
-	LLPluginProcessParent::setUseReadThread(false);
-
-	LL_INFOS() << "Shutting down Threads" << LL_ENDL;
-
-	// Let threads finish
-	LLTimer idleTimer;
-	idleTimer.reset();
-	const F64 max_idle_time = 5.f; // 5 seconds
-	while(1)
-	{
-		S32 pending = 0;
-		pending += LLAppViewer::getTextureCache()->update(1); // unpauses the worker thread
-		pending += LLAppViewer::getImageDecodeThread()->update(1); // unpauses the image thread
-		pending += LLAppViewer::getTextureFetch()->update(1); // unpauses the texture fetch thread
-		pending += LLLFSThread::updateClass(0);
-		F64 idle_time = idleTimer.getElapsedTimeF64();
-		if(!pending)
-		{
-			break ; //done
-		}
-		else if(idle_time >= max_idle_time)
-		{
-			LL_WARNS() << "Quitting with pending background tasks." << LL_ENDL;
-			break;
-		}
-	}
+    // Must do this after all panels have been deleted because panels that have persistent rects
+    // save their rects on delete.
+    gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
 
-    if (mPurgeUserDataOnExit)
+    LLUIColorTable::instance().saveUserSettings(gSavedSettings.getBool("ResetUserColorsOnLogout"));
+
+    // PerAccountSettingsFile should be empty if no user has been logged on.
+    // *FIX:Mani This should get really saved in a "logoff" mode.
+    if (gSavedSettings.getString("PerAccountSettingsFile").empty())
     {
-        // Ideally we should not save anything from this session since it is going to be purged now,
-        // but this is a very 'rare' case (user deleting himself), not worth overcomplicating 'save&cleanup' code
-        std::string user_path = gDirUtilp->getOSUserAppDir() + gDirUtilp->getDirDelimiter() + LLStartUp::getUserId();
-        gDirUtilp->deleteDirAndContents(user_path);
+        LL_INFOS() << "Not saving per-account settings; don't know the account name yet." << LL_ENDL;
     }
+    // Only save per account settings if the previous login succeeded, otherwise
+    // we might end up with a cleared out settings file in case a previous login
+    // failed after loading per account settings.
+    else if (!mSavePerAccountSettings)
+    {
+        LL_INFOS() << "Not saving per-account settings; last login was not successful." << LL_ENDL;
+    }
+    else
+    {
+        gSavedPerAccountSettings.saveToFile(gSavedSettings.getString("PerAccountSettingsFile"), TRUE);
+        LL_INFOS() << "Saved settings" << LL_ENDL;
 
-	// Delete workers first
-	// shotdown all worker threads before deleting them in case of co-dependencies
-	mAppCoreHttp.requestStop();
-	sTextureFetch->shutdown();
-	sTextureCache->shutdown();
-	sImageDecodeThread->shutdown();
-	sPurgeDiskCacheThread->shutdown();
-	if (mGeneralThreadPool)
-	{
-		mGeneralThreadPool->close();
-	}
-
-	sTextureFetch->shutDownTextureCacheThread() ;
-    LLLFSThread::sLocal->shutdown();
+        if (LLViewerParcelAskPlay::instanceExists())
+        {
+            LLViewerParcelAskPlay::getInstance()->saveSettings();
+        }
+    }
 
-	LL_INFOS() << "Shutting down disk cache" << LL_ENDL;
-	LLDiskCache::deleteSingleton();
+    std::string warnings_settings_filename = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, getSettingsFilename("Default", "Warnings"));
+    gWarningSettings.saveToFile(warnings_settings_filename, TRUE);
 
-	LL_INFOS() << "Shutting down message system" << LL_ENDL;
-	end_messaging_system();
+    // Save URL history file
+    LLURLHistory::saveFile("url_history.xml");
 
-	// Non-LLCurl libcurl library
-	mAppCoreHttp.cleanup();
+    // save mute list. gMuteList used to also be deleted here too.
+    if (gAgent.isInitialized() && LLMuteList::instanceExists())
+    {
+        LLMuteList::getInstance()->cache(gAgent.getID());
+    }
 
-	SUBSYSTEM_CLEANUP(LLFilePickerThread);
-	SUBSYSTEM_CLEANUP(LLDirPickerThread);
+    //save call log list
+    if (LLConversationLog::instanceExists())
+    {
+        LLConversationLog::instance().cache();
+    }
 
-	//MUST happen AFTER SUBSYSTEM_CLEANUP(LLCurl)
-	delete sTextureCache;
-    sTextureCache = NULL;
-    if (sTextureFetch)
+    if (mPurgeCacheOnExit)
+    {
+        LL_INFOS() << "Purging all cache files on exit" << LL_ENDL;
+        gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE,""), "*.*");
+    }
+
+    writeDebugInfo();
+
+    LLLocationHistory::getInstance()->save();
+
+    LLAvatarIconIDCache::getInstance()->save();
+
+    // Stop the plugin read thread if it's running.
+    LLPluginProcessParent::setUseReadThread(false);
+
+    LL_INFOS() << "Shutting down Threads" << LL_ENDL;
+
+    // Let threads finish
+    LLTimer idleTimer;
+    idleTimer.reset();
+    const F64 max_idle_time = 5.f; // 5 seconds
+    while(1)
+    {
+        S32 pending = 0;
+        pending += LLAppViewer::getTextureCache()->update(1); // unpauses the worker thread
+        pending += LLAppViewer::getImageDecodeThread()->update(1); // unpauses the image thread
+        pending += LLAppViewer::getTextureFetch()->update(1); // unpauses the texture fetch thread
+        pending += LLLFSThread::updateClass(0);
+        F64 idle_time = idleTimer.getElapsedTimeF64();
+        if(!pending)
+        {
+            break ; //done
+        }
+        else if(idle_time >= max_idle_time)
+        {
+            LL_WARNS() << "Quitting with pending background tasks." << LL_ENDL;
+            break;
+        }
+    }
+
+    if (mPurgeUserDataOnExit)
+    {
+        // Ideally we should not save anything from this session since it is going to be purged now,
+        // but this is a very 'rare' case (user deleting himself), not worth overcomplicating 'save&cleanup' code
+        std::string user_path = gDirUtilp->getOSUserAppDir() + gDirUtilp->getDirDelimiter() + LLStartUp::getUserId();
+        gDirUtilp->deleteDirAndContents(user_path);
+    }
+
+    // Delete workers first
+    // shotdown all worker threads before deleting them in case of co-dependencies
+    mAppCoreHttp.requestStop();
+    sTextureFetch->shutdown();
+    sTextureCache->shutdown();
+    sImageDecodeThread->shutdown();
+    sPurgeDiskCacheThread->shutdown();
+    if (mGeneralThreadPool)
+    {
+        mGeneralThreadPool->close();
+    }
+
+    sTextureFetch->shutDownTextureCacheThread() ;
+    LLLFSThread::sLocal->shutdown();
+
+    LL_INFOS() << "Shutting down disk cache" << LL_ENDL;
+    LLDiskCache::deleteSingleton();
+
+    LL_INFOS() << "Shutting down message system" << LL_ENDL;
+    end_messaging_system();
+
+    // Non-LLCurl libcurl library
+    mAppCoreHttp.cleanup();
+
+    SUBSYSTEM_CLEANUP(LLFilePickerThread);
+    SUBSYSTEM_CLEANUP(LLDirPickerThread);
+
+    //MUST happen AFTER SUBSYSTEM_CLEANUP(LLCurl)
+    delete sTextureCache;
+    sTextureCache = NULL;
+    if (sTextureFetch)
     {
         sTextureFetch->shutdown();
         sTextureFetch->waitOnPending();
         delete sTextureFetch;
         sTextureFetch = NULL;
     }
-	delete sImageDecodeThread;
+    delete sImageDecodeThread;
     sImageDecodeThread = NULL;
-	delete mFastTimerLogThread;
-	mFastTimerLogThread = NULL;
-	delete sPurgeDiskCacheThread;
-	sPurgeDiskCacheThread = NULL;
+    delete mFastTimerLogThread;
+    mFastTimerLogThread = NULL;
+    delete sPurgeDiskCacheThread;
+    sPurgeDiskCacheThread = NULL;
     delete mGeneralThreadPool;
     mGeneralThreadPool = NULL;
 
-	if (LLFastTimerView::sAnalyzePerformance)
-	{
-		LL_INFOS() << "Analyzing performance" << LL_ENDL;
+    if (LLFastTimerView::sAnalyzePerformance)
+    {
+        LL_INFOS() << "Analyzing performance" << LL_ENDL;
 
-		std::string baseline_name = LLTrace::BlockTimer::sLogName + "_baseline.slp";
-		std::string current_name  = LLTrace::BlockTimer::sLogName + ".slp";
-		std::string report_name   = LLTrace::BlockTimer::sLogName + "_report.csv";
+        std::string baseline_name = LLTrace::BlockTimer::sLogName + "_baseline.slp";
+        std::string current_name  = LLTrace::BlockTimer::sLogName + ".slp";
+        std::string report_name   = LLTrace::BlockTimer::sLogName + "_report.csv";
 
-		LLFastTimerView::doAnalysis(
-			gDirUtilp->getExpandedFilename(LL_PATH_LOGS, baseline_name),
-			gDirUtilp->getExpandedFilename(LL_PATH_LOGS, current_name),
-			gDirUtilp->getExpandedFilename(LL_PATH_LOGS, report_name));
-	}
+        LLFastTimerView::doAnalysis(
+            gDirUtilp->getExpandedFilename(LL_PATH_LOGS, baseline_name),
+            gDirUtilp->getExpandedFilename(LL_PATH_LOGS, current_name),
+            gDirUtilp->getExpandedFilename(LL_PATH_LOGS, report_name));
+    }
 
-	SUBSYSTEM_CLEANUP(LLMetricPerformanceTesterBasic) ;
+    SUBSYSTEM_CLEANUP(LLMetricPerformanceTesterBasic) ;
 
-	LL_INFOS() << "Cleaning up Media and Textures" << LL_ENDL;
+    LL_INFOS() << "Cleaning up Media and Textures" << LL_ENDL;
 
-	//Note:
-	//SUBSYSTEM_CLEANUP(LLViewerMedia) has to be put before gTextureList.shutdown()
-	//because some new image might be generated during cleaning up media. --bao
-	gTextureList.shutdown(); // shutdown again in case a callback added something
-	LLUIImageList::getInstance()->cleanUp();
+    //Note:
+    //SUBSYSTEM_CLEANUP(LLViewerMedia) has to be put before gTextureList.shutdown()
+    //because some new image might be generated during cleaning up media. --bao
+    gTextureList.shutdown(); // shutdown again in case a callback added something
+    LLUIImageList::getInstance()->cleanUp();
 
-	SUBSYSTEM_CLEANUP(LLImage);
-	SUBSYSTEM_CLEANUP(LLLFSThread);
+    SUBSYSTEM_CLEANUP(LLImage);
+    SUBSYSTEM_CLEANUP(LLLFSThread);
 
-	LL_INFOS() << "Misc Cleanup" << LL_ENDL;
+    LL_INFOS() << "Misc Cleanup" << LL_ENDL;
 
-	gSavedSettings.cleanup();
-	LLUIColorTable::instance().clear();
+    gSavedSettings.cleanup();
+    LLUIColorTable::instance().clear();
 
-	LLWatchdog::getInstance()->cleanup();
+    LLWatchdog::getInstance()->cleanup();
 
-	LLViewerAssetStatsFF::cleanup();
+    LLViewerAssetStatsFF::cleanup();
 
-	// If we're exiting to launch an URL, do that here so the screen
-	// is at the right resolution before we launch IE.
-	if (!gLaunchFileOnQuit.empty())
-	{
-		LL_INFOS() << "Launch file on quit." << LL_ENDL;
+    // If we're exiting to launch an URL, do that here so the screen
+    // is at the right resolution before we launch IE.
+    if (!gLaunchFileOnQuit.empty())
+    {
+        LL_INFOS() << "Launch file on quit." << LL_ENDL;
 #if LL_WINDOWS
-		// Indicate an application is starting.
-		SetCursor(LoadCursor(NULL, IDC_WAIT));
+        // Indicate an application is starting.
+        SetCursor(LoadCursor(NULL, IDC_WAIT));
 #endif
 
-		// HACK: Attempt to wait until the screen res. switch is complete.
-		ms_sleep(1000);
+        // HACK: Attempt to wait until the screen res. switch is complete.
+        ms_sleep(1000);
 
-		LLWeb::loadURLExternal( gLaunchFileOnQuit, false );
-		LL_INFOS() << "File launched." << LL_ENDL;
-	}
-	// make sure nothing uses applyProxySettings by this point.
-	LL_INFOS() << "Cleaning up LLProxy." << LL_ENDL;
-	SUBSYSTEM_CLEANUP(LLProxy);
+        LLWeb::loadURLExternal( gLaunchFileOnQuit, false );
+        LL_INFOS() << "File launched." << LL_ENDL;
+    }
+    // make sure nothing uses applyProxySettings by this point.
+    LL_INFOS() << "Cleaning up LLProxy." << LL_ENDL;
+    SUBSYSTEM_CLEANUP(LLProxy);
     LLCore::LLHttp::cleanup();
 
     // Manually cleanup sec handler for openssl 1.1.1+ compat
     clearSecHandler();
 
-	ll_close_fail_log();
+    ll_close_fail_log();
 
-	LLError::LLCallStacks::cleanup();
+    LLError::LLCallStacks::cleanup();
     LL::GLTFSceneManager::deleteSingleton();
-	LLEnvironment::deleteSingleton();
-	LLSelectMgr::deleteSingleton();
-	LLViewerEventRecorder::deleteSingleton();
+    LLEnvironment::deleteSingleton();
+    LLSelectMgr::deleteSingleton();
+    LLViewerEventRecorder::deleteSingleton();
     LLWorld::deleteSingleton();
     LLVoiceClient::deleteSingleton();
 
-	// It's not at first obvious where, in this long sequence, a generic cleanup
-	// call OUGHT to go. So let's say this: as we migrate cleanup from
-	// explicit hand-placed calls into the generic mechanism, eventually
-	// all cleanup will get subsumed into the generic call. So the calls you
-	// still see above are calls that MUST happen before the generic cleanup
-	// kicks in.
+    // It's not at first obvious where, in this long sequence, a generic cleanup
+    // call OUGHT to go. So let's say this: as we migrate cleanup from
+    // explicit hand-placed calls into the generic mechanism, eventually
+    // all cleanup will get subsumed into the generic call. So the calls you
+    // still see above are calls that MUST happen before the generic cleanup
+    // kicks in.
 
-	// This calls every remaining LLSingleton's cleanupSingleton() and
-	// deleteSingleton() methods.
-	LLSingletonBase::deleteAll();
+    // This calls every remaining LLSingleton's cleanupSingleton() and
+    // deleteSingleton() methods.
+    LLSingletonBase::deleteAll();
 
     LLSplashScreen::hide();
 
     LL_INFOS() << "Goodbye!" << LL_ENDL;
 
-	removeDumpDir();
+    removeDumpDir();
 
-	// return 0;
-	return true;
+    // return 0;
+    return true;
 }
 
 void LLAppViewer::initGeneralThread()
@@ -2142,11 +2142,11 @@ void LLAppViewer::initGeneralThread()
 
 bool LLAppViewer::initThreads()
 {
-	static const bool enable_threads = true;
+    static const bool enable_threads = true;
 
-	LLImage::initClass(gSavedSettings.getBOOL("TextureNewByteRange"),gSavedSettings.getS32("TextureReverseByteRange"));
+    LLImage::initClass(gSavedSettings.getBOOL("TextureNewByteRange"),gSavedSettings.getS32("TextureReverseByteRange"));
 
-	LLLFSThread::initClass(enable_threads && true); // TODO: fix crashes associated with this shutdo
+    LLLFSThread::initClass(enable_threads && true); // TODO: fix crashes associated with this shutdo
 
     //auto configure thread count
     LLSD threadCounts = gSavedSettings.getLLSD("ThreadPoolSizes");
@@ -2161,39 +2161,39 @@ bool LLAppViewer::initThreads()
     }
 
     // The only configurable thread count right now is ImageDecode
-    // The viewer typically starts around 8 threads not including image decode, 
+    // The viewer typically starts around 8 threads not including image decode,
     // so try to leave at least one core free
     S32 image_decode_count = llclamp(cores - 9, 1, 8);
     threadCounts["ImageDecode"] = image_decode_count;
     gSavedSettings.setLLSD("ThreadPoolSizes", threadCounts);
 
-	// Image decoding
-	LLAppViewer::sImageDecodeThread = new LLImageDecodeThread(enable_threads && true);
-	LLAppViewer::sTextureCache = new LLTextureCache(enable_threads && true);
-	LLAppViewer::sTextureFetch = new LLTextureFetch(LLAppViewer::getTextureCache(),
-													enable_threads && true,
-													app_metrics_qa_mode);
+    // Image decoding
+    LLAppViewer::sImageDecodeThread = new LLImageDecodeThread(enable_threads && true);
+    LLAppViewer::sTextureCache = new LLTextureCache(enable_threads && true);
+    LLAppViewer::sTextureFetch = new LLTextureFetch(LLAppViewer::getTextureCache(),
+                                                    enable_threads && true,
+                                                    app_metrics_qa_mode);
 
     // general task background thread (LLPerfStats, etc)
     LLAppViewer::instance()->initGeneralThread();
 
-	LLAppViewer::sPurgeDiskCacheThread = new LLPurgeDiskCacheThread();
+    LLAppViewer::sPurgeDiskCacheThread = new LLPurgeDiskCacheThread();
 
-	if (LLTrace::BlockTimer::sLog || LLTrace::BlockTimer::sMetricLog)
-	{
-		LLTrace::BlockTimer::setLogLock(new LLMutex());
-		mFastTimerLogThread = new LLFastTimerLogThread(LLTrace::BlockTimer::sLogName);
-		mFastTimerLogThread->start();
-	}
+    if (LLTrace::BlockTimer::sLog || LLTrace::BlockTimer::sMetricLog)
+    {
+        LLTrace::BlockTimer::setLogLock(new LLMutex());
+        mFastTimerLogThread = new LLFastTimerLogThread(LLTrace::BlockTimer::sLogName);
+        mFastTimerLogThread->start();
+    }
 
-	// Mesh streaming and caching
-	gMeshRepo.init();
+    // Mesh streaming and caching
+    gMeshRepo.init();
 
-	LLFilePickerThread::initClass();
-	LLDirPickerThread::initClass();
+    LLFilePickerThread::initClass();
+    LLDirPickerThread::initClass();
 
-	// *FIX: no error handling here!
-	return true;
+    // *FIX: no error handling here!
+    return true;
 }
 
 void errorCallback(LLError::ELevel level, const std::string &error_string)
@@ -2201,15 +2201,15 @@ void errorCallback(LLError::ELevel level, const std::string &error_string)
     if (level == LLError::LEVEL_ERROR)
     {
 #ifdef SHOW_ASSERT
-		static std::string last_message;
-		if (error_string == last_message) return;
+        static std::string last_message;
+        if (error_string == last_message) return;
         OSMessageBox(error_string, LLTrans::getString("MBFatalError"), OSMB_OK);
-		U32 response = OSMessageBox(error_string, LLTrans::getString("MBFatalError"), OSMB_YESNO);
-		if (response == OSBTN_NO)
-		{
-			last_message = error_string;
-			return;
-		}
+        U32 response = OSMessageBox(error_string, LLTrans::getString("MBFatalError"), OSMB_YESNO);
+        if (response == OSBTN_NO)
+        {
+            last_message = error_string;
+            return;
+        }
 #endif
 
         gDebugInfo["FatalMessage"] = error_string;
@@ -2245,7 +2245,7 @@ void LLAppViewer::initLoggingAndGetLastDuration()
     if (mSecondInstance)
     {
         LLFile::mkdir(gDirUtilp->getDumpLogsDirPath());
- 
+
         LLUUID uid;
         uid.generate();
         LLError::logToFile(gDirUtilp->getDumpLogsDirPath(uid.asString() + ".log"));
@@ -2316,123 +2316,123 @@ void LLAppViewer::initLoggingAndGetLastDuration()
 }
 
 bool LLAppViewer::loadSettingsFromDirectory(const std::string& location_key,
-					    bool set_defaults)
+                        bool set_defaults)
 {
-	if (!mSettingsLocationList)
-	{
-		LL_ERRS() << "Invalid settings location list" << LL_ENDL;
-	}
-
-	for (const SettingsGroup& group : mSettingsLocationList->groups)
-	{
-		// skip settings groups that aren't the one we requested
-		if (group.name() != location_key) continue;
-
-		ELLPath path_index = (ELLPath)group.path_index();
-		if(path_index <= LL_PATH_NONE || path_index >= LL_PATH_LAST)
-		{
-			LL_ERRS() << "Out of range path index in app_settings/settings_files.xml" << LL_ENDL;
-			return false;
-		}
-
-		for (const SettingsFile& file : group.files)
-		{
-			LL_INFOS("Settings") << "Attempting to load settings for the group " << file.name()
-			    << " - from location " << location_key << LL_ENDL;
-
-			auto settings_group = LLControlGroup::getInstance(file.name);
-			if(!settings_group)
-			{
-				LL_WARNS("Settings") << "No matching settings group for name " << file.name() << LL_ENDL;
-				continue;
-			}
-
-			std::string full_settings_path;
-
-			if (file.file_name_setting.isProvided()
-				&& gSavedSettings.controlExists(file.file_name_setting.getValue()))
-			{
-				// try to find filename stored in file_name_setting control
-				full_settings_path = gSavedSettings.getString(file.file_name_setting.getValue());
-				if (full_settings_path.empty())
-				{
-					continue;
-				}
-				else if (!gDirUtilp->fileExists(full_settings_path))
-				{
-					// search in default path
-					full_settings_path = gDirUtilp->getExpandedFilename((ELLPath)path_index, full_settings_path);
-				}
-			}
-			else
-			{
-				// by default, use specified file name
-				full_settings_path = gDirUtilp->getExpandedFilename((ELLPath)path_index, file.file_name());
-			}
-
-			if(settings_group->loadFromFile(full_settings_path, set_defaults, file.persistent))
-			{	// success!
-				LL_INFOS("Settings") << "Loaded settings file " << full_settings_path << LL_ENDL;
-			}
-			else
-			{	// failed to load
-				if(file.required)
-				{
+    if (!mSettingsLocationList)
+    {
+        LL_ERRS() << "Invalid settings location list" << LL_ENDL;
+    }
+
+    for (const SettingsGroup& group : mSettingsLocationList->groups)
+    {
+        // skip settings groups that aren't the one we requested
+        if (group.name() != location_key) continue;
+
+        ELLPath path_index = (ELLPath)group.path_index();
+        if(path_index <= LL_PATH_NONE || path_index >= LL_PATH_LAST)
+        {
+            LL_ERRS() << "Out of range path index in app_settings/settings_files.xml" << LL_ENDL;
+            return false;
+        }
+
+        for (const SettingsFile& file : group.files)
+        {
+            LL_INFOS("Settings") << "Attempting to load settings for the group " << file.name()
+                << " - from location " << location_key << LL_ENDL;
+
+            auto settings_group = LLControlGroup::getInstance(file.name);
+            if(!settings_group)
+            {
+                LL_WARNS("Settings") << "No matching settings group for name " << file.name() << LL_ENDL;
+                continue;
+            }
+
+            std::string full_settings_path;
+
+            if (file.file_name_setting.isProvided()
+                && gSavedSettings.controlExists(file.file_name_setting.getValue()))
+            {
+                // try to find filename stored in file_name_setting control
+                full_settings_path = gSavedSettings.getString(file.file_name_setting.getValue());
+                if (full_settings_path.empty())
+                {
+                    continue;
+                }
+                else if (!gDirUtilp->fileExists(full_settings_path))
+                {
+                    // search in default path
+                    full_settings_path = gDirUtilp->getExpandedFilename((ELLPath)path_index, full_settings_path);
+                }
+            }
+            else
+            {
+                // by default, use specified file name
+                full_settings_path = gDirUtilp->getExpandedFilename((ELLPath)path_index, file.file_name());
+            }
+
+            if(settings_group->loadFromFile(full_settings_path, set_defaults, file.persistent))
+            {   // success!
+                LL_INFOS("Settings") << "Loaded settings file " << full_settings_path << LL_ENDL;
+            }
+            else
+            {   // failed to load
+                if(file.required)
+                {
                     LLError::LLUserWarningMsg::showMissingFiles();
-					LL_ERRS() << "Error: Cannot load required settings file from: " << full_settings_path << LL_ENDL;
-					return false;
-				}
-				else
-				{
-					// only complain if we actually have a filename at this point
-					if (!full_settings_path.empty())
-					{
-						LL_INFOS("Settings") << "Cannot load " << full_settings_path << " - No settings found." << LL_ENDL;
-					}
-				}
-			}
-		}
-	}
-
-	return true;
+                    LL_ERRS() << "Error: Cannot load required settings file from: " << full_settings_path << LL_ENDL;
+                    return false;
+                }
+                else
+                {
+                    // only complain if we actually have a filename at this point
+                    if (!full_settings_path.empty())
+                    {
+                        LL_INFOS("Settings") << "Cannot load " << full_settings_path << " - No settings found." << LL_ENDL;
+                    }
+                }
+            }
+        }
+    }
+
+    return true;
 }
 
 std::string LLAppViewer::getSettingsFilename(const std::string& location_key,
-											 const std::string& file)
+                                             const std::string& file)
 {
-	for (const SettingsGroup& group : mSettingsLocationList->groups)
-	{
-		if (group.name() == location_key)
-		{
-			for (const SettingsFile& settings_file : group.files)
-			{
-				if (settings_file.name() == file)
-				{
-					return settings_file.file_name;
-				}
-			}
-		}
-	}
-
-	return std::string();
+    for (const SettingsGroup& group : mSettingsLocationList->groups)
+    {
+        if (group.name() == location_key)
+        {
+            for (const SettingsFile& settings_file : group.files)
+            {
+                if (settings_file.name() == file)
+                {
+                    return settings_file.file_name;
+                }
+            }
+        }
+    }
+
+    return std::string();
 }
 
 void LLAppViewer::loadColorSettings()
 {
-	LLUIColorTable::instance().loadFromSettings();
+    LLUIColorTable::instance().loadFromSettings();
 }
 
 namespace
 {
     void handleCommandLineError(LLControlGroupCLP& clp)
     {
-		LL_WARNS() << "Error parsing command line options. Command Line options ignored."  << LL_ENDL;
+        LL_WARNS() << "Error parsing command line options. Command Line options ignored."  << LL_ENDL;
 
-		LL_INFOS() << "Command line usage:\n" << clp << LL_ENDL;
+        LL_INFOS() << "Command line usage:\n" << clp << LL_ENDL;
 
-		OSMessageBox(STRINGIZE(LLTrans::getString("MBCmdLineError") << clp.getErrorMessage()),
-					 LLStringUtil::null,
-					 OSMB_OK);
+        OSMessageBox(STRINGIZE(LLTrans::getString("MBCmdLineError") << clp.getErrorMessage()),
+                     LLStringUtil::null,
+                     OSMB_OK);
     }
 } // anonymous namespace
 
@@ -2440,42 +2440,42 @@ namespace
 // Name can be specified as "<control_group>.<control_name>", with default group being Global.
 bool tempSetControl(const std::string& name, const std::string& value)
 {
-	std::string name_part;
-	std::string group_part;
-	LLControlVariable* control = NULL;
-
-	// Name can be further split into ControlGroup.Name, with the default control group being Global
-	size_t pos = name.find('.');
-	if (pos != std::string::npos)
-	{
-		group_part = name.substr(0, pos);
-		name_part = name.substr(pos+1);
-		LL_INFOS() << "Setting " << group_part << "." << name_part << " to " << value << LL_ENDL;
-		auto g = LLControlGroup::getInstance(group_part);
-		if (g) control = g->getControl(name_part);
-	}
-	else
-	{
-		LL_INFOS() << "Setting Global." << name << " to " << value << LL_ENDL;
-		control = gSavedSettings.getControl(name);
-	}
-
-	if (control)
-	{
-		control->setValue(value, false);
-		return true;
-	}
-	return false;
+    std::string name_part;
+    std::string group_part;
+    LLControlVariable* control = NULL;
+
+    // Name can be further split into ControlGroup.Name, with the default control group being Global
+    size_t pos = name.find('.');
+    if (pos != std::string::npos)
+    {
+        group_part = name.substr(0, pos);
+        name_part = name.substr(pos+1);
+        LL_INFOS() << "Setting " << group_part << "." << name_part << " to " << value << LL_ENDL;
+        auto g = LLControlGroup::getInstance(group_part);
+        if (g) control = g->getControl(name_part);
+    }
+    else
+    {
+        LL_INFOS() << "Setting Global." << name << " to " << value << LL_ENDL;
+        control = gSavedSettings.getControl(name);
+    }
+
+    if (control)
+    {
+        control->setValue(value, false);
+        return true;
+    }
+    return false;
 }
 
 bool LLAppViewer::initConfiguration()
 {
-	//Load settings files list
-	std::string settings_file_list = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "settings_files.xml");
-	LLXMLNodePtr root;
-	BOOL success = LLXMLNode::parseFile(settings_file_list, root, NULL);
-	if (!success)
-	{
+    //Load settings files list
+    std::string settings_file_list = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "settings_files.xml");
+    LLXMLNodePtr root;
+    BOOL success = LLXMLNode::parseFile(settings_file_list, root, NULL);
+    if (!success)
+    {
         LL_WARNS() << "Cannot load default configuration file " << settings_file_list << LL_ENDL;
         LLError::LLUserWarningMsg::showMissingFiles();
         if (gDirUtilp->fileExists(settings_file_list))
@@ -2492,175 +2492,175 @@ bool LLAppViewer::initConfiguration()
                 << "and contact https://support.secondlife.com if issue persists after reinstall."
                 << LL_ENDL;
         }
-	}
+    }
 
-	mSettingsLocationList = new SettingsFiles();
+    mSettingsLocationList = new SettingsFiles();
 
-	LLXUIParser parser;
-	parser.readXUI(root, *mSettingsLocationList, settings_file_list);
+    LLXUIParser parser;
+    parser.readXUI(root, *mSettingsLocationList, settings_file_list);
 
-	if (!mSettingsLocationList->validateBlock())
-	{
+    if (!mSettingsLocationList->validateBlock())
+    {
         LLError::LLUserWarningMsg::showMissingFiles();
         LL_ERRS() << "Invalid settings file list " << settings_file_list << LL_ENDL;
-	}
-
-	// The settings and command line parsing have a fragile
-	// order-of-operation:
-	// - load defaults from app_settings
-	// - set procedural settings values
-	// - read command line settings
-	// - selectively apply settings needed to load user settings.
+    }
+
+    // The settings and command line parsing have a fragile
+    // order-of-operation:
+    // - load defaults from app_settings
+    // - set procedural settings values
+    // - read command line settings
+    // - selectively apply settings needed to load user settings.
     // - load overrides from user_settings
-	// - apply command line settings (to override the overrides)
-	// - load per account settings (happens in llstartup
-
-	// - load defaults
-	bool set_defaults = true;
-	if(!loadSettingsFromDirectory("Default", set_defaults))
-	{
-		OSMessageBox(
-			"Unable to load default settings file. The installation may be corrupted.",
-			LLStringUtil::null,OSMB_OK);
-		return false;
-	}
-
-	initStrings(); // setup paths for LLTrans based on settings files only
-	// - set procedural settings
-	// Note: can't use LL_PATH_PER_SL_ACCOUNT for any of these since we haven't logged in yet
-	gSavedSettings.setString("ClientSettingsFile",
+    // - apply command line settings (to override the overrides)
+    // - load per account settings (happens in llstartup
+
+    // - load defaults
+    bool set_defaults = true;
+    if(!loadSettingsFromDirectory("Default", set_defaults))
+    {
+        OSMessageBox(
+            "Unable to load default settings file. The installation may be corrupted.",
+            LLStringUtil::null,OSMB_OK);
+        return false;
+    }
+
+    initStrings(); // setup paths for LLTrans based on settings files only
+    // - set procedural settings
+    // Note: can't use LL_PATH_PER_SL_ACCOUNT for any of these since we haven't logged in yet
+    gSavedSettings.setString("ClientSettingsFile",
         gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, getSettingsFilename("Default", "Global")));
 
-#ifndef	LL_RELEASE_FOR_DOWNLOAD
-	// provide developer build only overrides for these control variables that are not
-	// persisted to settings.xml
-	LLControlVariable* c = gSavedSettings.getControl("AllowMultipleViewers");
-	if (c)
-	{
-		c->setValue(true, false);
-	}
-
-	gSavedSettings.setBOOL("QAMode", TRUE );
-	gSavedSettings.setS32("WatchdogEnabled", 0);
+#ifndef LL_RELEASE_FOR_DOWNLOAD
+    // provide developer build only overrides for these control variables that are not
+    // persisted to settings.xml
+    LLControlVariable* c = gSavedSettings.getControl("AllowMultipleViewers");
+    if (c)
+    {
+        c->setValue(true, false);
+    }
+
+    gSavedSettings.setBOOL("QAMode", TRUE );
+    gSavedSettings.setS32("WatchdogEnabled", 0);
 #endif
 
-	// These are warnings that appear on the first experience of that condition.
-	// They are already set in the settings_default.xml file, but still need to be added to LLFirstUse
-	// for disable/reset ability
-//	LLFirstUse::addConfigVariable("FirstBalanceIncrease");
-//	LLFirstUse::addConfigVariable("FirstBalanceDecrease");
-//	LLFirstUse::addConfigVariable("FirstSit");
-//	LLFirstUse::addConfigVariable("FirstMap");
-//	LLFirstUse::addConfigVariable("FirstGoTo");
-//	LLFirstUse::addConfigVariable("FirstBuild");
-//	LLFirstUse::addConfigVariable("FirstLeftClickNoHit");
-//	LLFirstUse::addConfigVariable("FirstTeleport");
-//	LLFirstUse::addConfigVariable("FirstOverrideKeys");
-//	LLFirstUse::addConfigVariable("FirstAttach");
-//	LLFirstUse::addConfigVariable("FirstAppearance");
-//	LLFirstUse::addConfigVariable("FirstInventory");
-//	LLFirstUse::addConfigVariable("FirstSandbox");
-//	LLFirstUse::addConfigVariable("FirstFlexible");
-//	LLFirstUse::addConfigVariable("FirstDebugMenus");
-//	LLFirstUse::addConfigVariable("FirstSculptedPrim");
-//	LLFirstUse::addConfigVariable("FirstVoice");
-//	LLFirstUse::addConfigVariable("FirstMedia");
-
-	// - read command line settings.
-	LLControlGroupCLP clp;
-	std::string	cmd_line_config	= gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,
-														  "cmd_line.xml");
-
-	clp.configure(cmd_line_config, &gSavedSettings);
-
-	if(!initParseCommandLine(clp))
-	{
-		handleCommandLineError(clp);
-		return false;
-	}
-
-	// - selectively apply settings
-
-	// If the user has specified a alternate settings file name.
-	// Load	it now before loading the user_settings/settings.xml
-	if(clp.hasOption("settings"))
-	{
-		std::string	user_settings_filename =
-			gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS,
-										   clp.getOption("settings")[0]);
-		gSavedSettings.setString("ClientSettingsFile", user_settings_filename);
-		LL_INFOS("Settings")	<< "Using command line specified settings filename: "
-			<< user_settings_filename << LL_ENDL;
-	}
-
-	// - load overrides from user_settings
-	loadSettingsFromDirectory("User");
-
-	if (gSavedSettings.getBOOL("FirstRunThisInstall"))
-	{
-		// Set firstrun flag to indicate that some further init actiona should be taken
-		// like determining screen DPI value and so on
-		mIsFirstRun = true;
-
-		gSavedSettings.setBOOL("FirstRunThisInstall", FALSE);
-	}
-
-	if (clp.hasOption("sessionsettings"))
-	{
-		std::string session_settings_filename = clp.getOption("sessionsettings")[0];
-		gSavedSettings.setString("SessionSettingsFile", session_settings_filename);
-		LL_INFOS("Settings")	<< "Using session settings filename: "
-			<< session_settings_filename << LL_ENDL;
-	}
-	loadSettingsFromDirectory("Session");
-
-	if (clp.hasOption("usersessionsettings"))
-	{
-		std::string user_session_settings_filename = clp.getOption("usersessionsettings")[0];
-		gSavedSettings.setString("UserSessionSettingsFile", user_session_settings_filename);
-		LL_INFOS("Settings") << "Using user session settings filename: "
-			<< user_session_settings_filename << LL_ENDL;
-
-	}
-	loadSettingsFromDirectory("UserSession");
-
-	// - apply command line settings
-	if (! clp.notify())
-	{
-		handleCommandLineError(clp);
-		return false;
-	}
-
-	// Register the core crash option as soon as we can
-	// if we want gdb post-mortem on cores we need to be up and running
-	// ASAP or we might miss init issue etc.
-	if(gSavedSettings.getBOOL("DisableCrashLogger"))
-	{
-		LL_WARNS() << "Crashes will be handled by system, stack trace logs and crash logger are both disabled" << LL_ENDL;
-		disableCrashlogger();
-	}
-
-	gNonInteractive = gSavedSettings.getBOOL("NonInteractive");
-	// Handle initialization from settings.
-	// Start up the debugging console before handling other options.
-	if (gSavedSettings.getBOOL("ShowConsoleWindow") && !gNonInteractive)
-	{
-		initConsole();
-	}
-
-	if(clp.hasOption("help"))
-	{
-		std::ostringstream msg;
-		msg << LLTrans::getString("MBCmdLineUsg") << "\n" << clp;
-		LL_INFOS()	<< msg.str() << LL_ENDL;
-
-		OSMessageBox(
-			msg.str(),
-			LLStringUtil::null,
-			OSMB_OK);
-
-		return false;
-	}
+    // These are warnings that appear on the first experience of that condition.
+    // They are already set in the settings_default.xml file, but still need to be added to LLFirstUse
+    // for disable/reset ability
+//  LLFirstUse::addConfigVariable("FirstBalanceIncrease");
+//  LLFirstUse::addConfigVariable("FirstBalanceDecrease");
+//  LLFirstUse::addConfigVariable("FirstSit");
+//  LLFirstUse::addConfigVariable("FirstMap");
+//  LLFirstUse::addConfigVariable("FirstGoTo");
+//  LLFirstUse::addConfigVariable("FirstBuild");
+//  LLFirstUse::addConfigVariable("FirstLeftClickNoHit");
+//  LLFirstUse::addConfigVariable("FirstTeleport");
+//  LLFirstUse::addConfigVariable("FirstOverrideKeys");
+//  LLFirstUse::addConfigVariable("FirstAttach");
+//  LLFirstUse::addConfigVariable("FirstAppearance");
+//  LLFirstUse::addConfigVariable("FirstInventory");
+//  LLFirstUse::addConfigVariable("FirstSandbox");
+//  LLFirstUse::addConfigVariable("FirstFlexible");
+//  LLFirstUse::addConfigVariable("FirstDebugMenus");
+//  LLFirstUse::addConfigVariable("FirstSculptedPrim");
+//  LLFirstUse::addConfigVariable("FirstVoice");
+//  LLFirstUse::addConfigVariable("FirstMedia");
+
+    // - read command line settings.
+    LLControlGroupCLP clp;
+    std::string cmd_line_config = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS,
+                                                          "cmd_line.xml");
+
+    clp.configure(cmd_line_config, &gSavedSettings);
+
+    if(!initParseCommandLine(clp))
+    {
+        handleCommandLineError(clp);
+        return false;
+    }
+
+    // - selectively apply settings
+
+    // If the user has specified a alternate settings file name.
+    // Load it now before loading the user_settings/settings.xml
+    if(clp.hasOption("settings"))
+    {
+        std::string user_settings_filename =
+            gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS,
+                                           clp.getOption("settings")[0]);
+        gSavedSettings.setString("ClientSettingsFile", user_settings_filename);
+        LL_INFOS("Settings")    << "Using command line specified settings filename: "
+            << user_settings_filename << LL_ENDL;
+    }
+
+    // - load overrides from user_settings
+    loadSettingsFromDirectory("User");
+
+    if (gSavedSettings.getBOOL("FirstRunThisInstall"))
+    {
+        // Set firstrun flag to indicate that some further init actiona should be taken
+        // like determining screen DPI value and so on
+        mIsFirstRun = true;
+
+        gSavedSettings.setBOOL("FirstRunThisInstall", FALSE);
+    }
+
+    if (clp.hasOption("sessionsettings"))
+    {
+        std::string session_settings_filename = clp.getOption("sessionsettings")[0];
+        gSavedSettings.setString("SessionSettingsFile", session_settings_filename);
+        LL_INFOS("Settings")    << "Using session settings filename: "
+            << session_settings_filename << LL_ENDL;
+    }
+    loadSettingsFromDirectory("Session");
+
+    if (clp.hasOption("usersessionsettings"))
+    {
+        std::string user_session_settings_filename = clp.getOption("usersessionsettings")[0];
+        gSavedSettings.setString("UserSessionSettingsFile", user_session_settings_filename);
+        LL_INFOS("Settings") << "Using user session settings filename: "
+            << user_session_settings_filename << LL_ENDL;
+
+    }
+    loadSettingsFromDirectory("UserSession");
+
+    // - apply command line settings
+    if (! clp.notify())
+    {
+        handleCommandLineError(clp);
+        return false;
+    }
+
+    // Register the core crash option as soon as we can
+    // if we want gdb post-mortem on cores we need to be up and running
+    // ASAP or we might miss init issue etc.
+    if(gSavedSettings.getBOOL("DisableCrashLogger"))
+    {
+        LL_WARNS() << "Crashes will be handled by system, stack trace logs and crash logger are both disabled" << LL_ENDL;
+        disableCrashlogger();
+    }
+
+    gNonInteractive = gSavedSettings.getBOOL("NonInteractive");
+    // Handle initialization from settings.
+    // Start up the debugging console before handling other options.
+    if (gSavedSettings.getBOOL("ShowConsoleWindow") && !gNonInteractive)
+    {
+        initConsole();
+    }
+
+    if(clp.hasOption("help"))
+    {
+        std::ostringstream msg;
+        msg << LLTrans::getString("MBCmdLineUsg") << "\n" << clp;
+        LL_INFOS()  << msg.str() << LL_ENDL;
+
+        OSMessageBox(
+            msg.str(),
+            LLStringUtil::null,
+            OSMB_OK);
+
+        return false;
+    }
 
     if(clp.hasOption("set"))
     {
@@ -2678,7 +2678,7 @@ bool LLAppViewer::initConfiguration()
                 const std::string& value = *(++itr);
                 if (!tempSetControl(name,value))
                 {
-					LL_WARNS() << "Failed --set " << name << ": setting name unknown." << LL_ENDL;
+                    LL_WARNS() << "Failed --set " << name << ": setting name unknown." << LL_ENDL;
                 }
             }
         }
@@ -2686,37 +2686,37 @@ bool LLAppViewer::initConfiguration()
 
 #if AL_VIEWER_EVENT_RECORDER
     if  (clp.hasOption("logevents")) {
-		LLViewerEventRecorder::instance().setEventLoggingOn();
+        LLViewerEventRecorder::instance().setEventLoggingOn();
     }
 #endif
 
-	std::string CmdLineChannel(gSavedSettings.getString("CmdLineChannel"));
-	if(! CmdLineChannel.empty())
-    {
-		LLVersionInfo::instance().resetChannel(CmdLineChannel);
-	}
-
-	// If we have specified crash on startup, set the global so we'll trigger the crash at the right time
-	gCrashOnStartup = gSavedSettings.getBOOL("CrashOnStartup");
-
-	if (gSavedSettings.getBOOL("LogPerformance"))
-	{
-		LLTrace::BlockTimer::sLog = true;
-		LLTrace::BlockTimer::sLogName = std::string("performance");
-	}
-
-	std::string test_name(gSavedSettings.getString("LogMetrics"));
-	if (! test_name.empty())
- 	{
-		LLTrace::BlockTimer::sMetricLog = TRUE;
-		// '--logmetrics' is specified with a named test metric argument so the data gathering is done only on that test
-		// In the absence of argument, every metric would be gathered (makes for a rather slow run and hard to decipher report...)
-		LL_INFOS() << "'--logmetrics' argument : " << test_name << LL_ENDL;
-		LLTrace::BlockTimer::sLogName = test_name;
-	}
-
-	if (clp.hasOption("graphicslevel"))
-	{
+    std::string CmdLineChannel(gSavedSettings.getString("CmdLineChannel"));
+    if(! CmdLineChannel.empty())
+    {
+        LLVersionInfo::instance().resetChannel(CmdLineChannel);
+    }
+
+    // If we have specified crash on startup, set the global so we'll trigger the crash at the right time
+    gCrashOnStartup = gSavedSettings.getBOOL("CrashOnStartup");
+
+    if (gSavedSettings.getBOOL("LogPerformance"))
+    {
+        LLTrace::BlockTimer::sLog = true;
+        LLTrace::BlockTimer::sLogName = std::string("performance");
+    }
+
+    std::string test_name(gSavedSettings.getString("LogMetrics"));
+    if (! test_name.empty())
+    {
+        LLTrace::BlockTimer::sMetricLog = TRUE;
+        // '--logmetrics' is specified with a named test metric argument so the data gathering is done only on that test
+        // In the absence of argument, every metric would be gathered (makes for a rather slow run and hard to decipher report...)
+        LL_INFOS() << "'--logmetrics' argument : " << test_name << LL_ENDL;
+        LLTrace::BlockTimer::sLogName = test_name;
+    }
+
+    if (clp.hasOption("graphicslevel"))
+    {
         // User explicitly requested --graphicslevel on the command line. We
         // expect this switch has already set RenderQualityPerformance. Check
         // that value for validity later.
@@ -2725,18 +2725,18 @@ bool LLAppViewer::initConfiguration()
         // will call LLFeatureManager::applyRecommendedSettings(), which
         // overwrites this settings variable!
         mForceGraphicsLevel = gSavedSettings.getU32("RenderQualityPerformance");
-	}
+    }
 
-	LLFastTimerView::sAnalyzePerformance = gSavedSettings.getBOOL("AnalyzePerformance");
-	gAgentPilot.setReplaySession(gSavedSettings.getBOOL("ReplaySession"));
+    LLFastTimerView::sAnalyzePerformance = gSavedSettings.getBOOL("AnalyzePerformance");
+    gAgentPilot.setReplaySession(gSavedSettings.getBOOL("ReplaySession"));
 
-	if (gSavedSettings.getBOOL("DebugSession"))
-	{
-		gDebugSession = TRUE;
-		gDebugGL = TRUE;
+    if (gSavedSettings.getBOOL("DebugSession"))
+    {
+        gDebugSession = TRUE;
+        gDebugGL = TRUE;
 
-		ll_init_fail_log(gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "test_failures.log"));
-	}
+        ll_init_fail_log(gDirUtilp->getExpandedFilename(LL_PATH_LOGS, "test_failures.log"));
+    }
 
     if (gSavedSettings.getBOOL("RenderDebugGLSession"))
     {
@@ -2747,49 +2747,49 @@ bool LLAppViewer::initConfiguration()
         gSavedSettings.setBOOL("RenderDebugGLSession", FALSE);
     }
 
-	const LLControlVariable* skinfolder = gSavedSettings.getControl("SkinCurrent");
-	if(skinfolder && LLStringUtil::null != skinfolder->getValue().asString())
-	{
-		// Examining "Language" may not suffice -- see LLUI::getLanguage()
-		// logic. Unfortunately LLUI::getLanguage() doesn't yet do us much
-		// good because we haven't yet called LLUI::initClass().
-		gDirUtilp->setSkinFolder(skinfolder->getValue().asString(),
-								 gSavedSettings.getString("Language"));
+    const LLControlVariable* skinfolder = gSavedSettings.getControl("SkinCurrent");
+    if(skinfolder && LLStringUtil::null != skinfolder->getValue().asString())
+    {
+        // Examining "Language" may not suffice -- see LLUI::getLanguage()
+        // logic. Unfortunately LLUI::getLanguage() doesn't yet do us much
+        // good because we haven't yet called LLUI::initClass().
+        gDirUtilp->setSkinFolder(skinfolder->getValue().asString(),
+                                 gSavedSettings.getString("Language"));
         std::string skin_settings_file = gDirUtilp->findSkinnedFilename(LLDir::SKINBASE, "skin_settings.xml");
         (void)gSkinSettings.loadFromFile(skin_settings_file, true, false);
-	}
-
-	if (gSavedSettings.getBOOL("SpellCheck"))
-	{
-		std::list<std::string> dict_list;
-		std::string dict_setting = gSavedSettings.getString("SpellCheckDictionary");
-		boost::split(dict_list, dict_setting, boost::is_any_of(std::string(",")));
-		if (!dict_list.empty())
-		{
-			LLSpellChecker::setUseSpellCheck(dict_list.front());
-			dict_list.pop_front();
-			LLSpellChecker::instance().setSecondaryDictionaries(dict_list);
-		}
-	}
-
-	if (gNonInteractive)
-	{
-		tempSetControl("AllowMultipleViewers", "TRUE");
-		tempSetControl("SLURLPassToOtherInstance", "FALSE");
-		tempSetControl("RenderWater", "FALSE");
-		tempSetControl("FlyingAtExit", "FALSE");
-		tempSetControl("WindowWidth", "1024");
-		tempSetControl("WindowHeight", "200");
-		LLError::setEnabledLogTypesMask(0);
-		llassert_always(!gSavedSettings.getBOOL("SLURLPassToOtherInstance"));
-	}
-
-
-	// Handle slurl use. NOTE: Don't let SL-55321 reappear.
-	// This initial-SLURL logic, up through the call to
-	// sendURLToOtherInstance(), must precede LLSplashScreen::show() --
-	// because if sendURLToOtherInstance() succeeds, we take a fast exit,
-	// SKIPPING the splash screen and everything else.
+    }
+
+    if (gSavedSettings.getBOOL("SpellCheck"))
+    {
+        std::list<std::string> dict_list;
+        std::string dict_setting = gSavedSettings.getString("SpellCheckDictionary");
+        boost::split(dict_list, dict_setting, boost::is_any_of(std::string(",")));
+        if (!dict_list.empty())
+        {
+            LLSpellChecker::setUseSpellCheck(dict_list.front());
+            dict_list.pop_front();
+            LLSpellChecker::instance().setSecondaryDictionaries(dict_list);
+        }
+    }
+
+    if (gNonInteractive)
+    {
+        tempSetControl("AllowMultipleViewers", "TRUE");
+        tempSetControl("SLURLPassToOtherInstance", "FALSE");
+        tempSetControl("RenderWater", "FALSE");
+        tempSetControl("FlyingAtExit", "FALSE");
+        tempSetControl("WindowWidth", "1024");
+        tempSetControl("WindowHeight", "200");
+        LLError::setEnabledLogTypesMask(0);
+        llassert_always(!gSavedSettings.getBOOL("SLURLPassToOtherInstance"));
+    }
+
+
+    // Handle slurl use. NOTE: Don't let SL-55321 reappear.
+    // This initial-SLURL logic, up through the call to
+    // sendURLToOtherInstance(), must precede LLSplashScreen::show() --
+    // because if sendURLToOtherInstance() succeeds, we take a fast exit,
+    // SKIPPING the splash screen and everything else.
 
     // *FIX: This init code should be made more robust to prevent
     // the issue SL-55321 from returning. One thought is to allow
@@ -2807,167 +2807,167 @@ bool LLAppViewer::initConfiguration()
     // other browsers) and do the rough equivalent of command
     // injection and steal passwords. Phoenix. SL-55321
 
-	std::string starting_location;
-
-	std::string cmd_line_login_location(gSavedSettings.getString("CmdLineLoginLocation"));
-	if(! cmd_line_login_location.empty())
-	{
-		starting_location = cmd_line_login_location;
-	}
-	else
-	{
-		std::string default_login_location(gSavedSettings.getString("DefaultLoginLocation"));
-		if (! default_login_location.empty())
-		{
-			starting_location = default_login_location;
-		}
-	}
-
-	LLSLURL start_slurl;
-	if (! starting_location.empty())
-    {
-		start_slurl = starting_location;
-		LLStartUp::setStartSLURL(start_slurl);
-		if(start_slurl.getType() == LLSLURL::LOCATION)
-		{
-			LLGridManager::getInstance()->setGridChoice(start_slurl.getGrid(), false);
-		}
-	}
-
-	// NextLoginLocation is set as a side effect of LLStartUp::setStartSLURL()
-	std::string nextLoginLocation = gSavedSettings.getString( "NextLoginLocation" );
-	if ( !nextLoginLocation.empty() )
-	{
-		LL_DEBUGS("AppInit")<<"set start from NextLoginLocation: "<<nextLoginLocation<<LL_ENDL;
-		LLStartUp::setStartSLURL(LLSLURL(nextLoginLocation));
-	}
-	else if (   (   clp.hasOption("login") || clp.hasOption("autologin"))
-			 && gSavedSettings.getString("CmdLineLoginLocation").empty())
-	{
-		// If automatic login from command line with --login switch
-		// init StartSLURL location.
-		std::string start_slurl_setting = gSavedSettings.getString("LoginLocation");
-		LL_DEBUGS("AppInit") << "start slurl setting '" << start_slurl_setting << "'" << LL_ENDL;
-		LLStartUp::setStartSLURL(LLSLURL(start_slurl_setting));
-	}
-	else
-	{
-		// the login location will be set by the login panel (see LLPanelLogin)
-	}
-
-	//RN: if we received a URL, hand it off to the existing instance.
-	// don't call anotherInstanceRunning() when doing URL handoff, as
-	// it relies on checking a marker file which will not work when running
-	// out of different directories
-
-	if (start_slurl.isValid() &&
-		(gSavedSettings.getBOOL("SLURLPassToOtherInstance")))
-	{
-		if (sendURLToOtherInstance(start_slurl.getSLURLString()))
-		{
-			// successfully handed off URL to existing instance, exit
-			return false;
-		}
-    }
-
-	// Display splash screen.  Must be after above check for previous
-	// crash as this dialog is always frontmost.
-	std::string splash_msg;
-	LLStringUtil::format_map_t args;
-	args["[APP_NAME]"] = getSecondLifeTitle();
-	splash_msg = LLTrans::getString("StartupLoading", args);
-	LLSplashScreen::show();
-	LLSplashScreen::update(splash_msg);
-
-	//LLVolumeMgr::initClass();
-	LLVolumeMgr* volume_manager = new LLVolumeMgr();
-	volume_manager->useMutex();	// LLApp and LLMutex magic must be manually enabled
-	LLPrimitive::setVolumeManager(volume_manager);
-
-	// Note: this is where we used to initialize gFeatureManagerp.
-
-	gStartTime = totalTime();
-
-	//
-	// Set the name of the window
-	//
-	if (LLVersionInfo::instance().getViewerMaturity() != LLVersionInfo::RELEASE_VIEWER)
-	{
-		gWindowTitle = LLVersionInfo::instance().getChannelAndVersion();
-	}
-	else
-	{
-		gWindowTitle = LLTrans::getString("APP_NAME");
-	}
+    std::string starting_location;
+
+    std::string cmd_line_login_location(gSavedSettings.getString("CmdLineLoginLocation"));
+    if(! cmd_line_login_location.empty())
+    {
+        starting_location = cmd_line_login_location;
+    }
+    else
+    {
+        std::string default_login_location(gSavedSettings.getString("DefaultLoginLocation"));
+        if (! default_login_location.empty())
+        {
+            starting_location = default_login_location;
+        }
+    }
+
+    LLSLURL start_slurl;
+    if (! starting_location.empty())
+    {
+        start_slurl = starting_location;
+        LLStartUp::setStartSLURL(start_slurl);
+        if(start_slurl.getType() == LLSLURL::LOCATION)
+        {
+            LLGridManager::getInstance()->setGridChoice(start_slurl.getGrid(), false);
+        }
+    }
+
+    // NextLoginLocation is set as a side effect of LLStartUp::setStartSLURL()
+    std::string nextLoginLocation = gSavedSettings.getString( "NextLoginLocation" );
+    if ( !nextLoginLocation.empty() )
+    {
+        LL_DEBUGS("AppInit")<<"set start from NextLoginLocation: "<<nextLoginLocation<<LL_ENDL;
+        LLStartUp::setStartSLURL(LLSLURL(nextLoginLocation));
+    }
+    else if (   (   clp.hasOption("login") || clp.hasOption("autologin"))
+             && gSavedSettings.getString("CmdLineLoginLocation").empty())
+    {
+        // If automatic login from command line with --login switch
+        // init StartSLURL location.
+        std::string start_slurl_setting = gSavedSettings.getString("LoginLocation");
+        LL_DEBUGS("AppInit") << "start slurl setting '" << start_slurl_setting << "'" << LL_ENDL;
+        LLStartUp::setStartSLURL(LLSLURL(start_slurl_setting));
+    }
+    else
+    {
+        // the login location will be set by the login panel (see LLPanelLogin)
+    }
+
+    //RN: if we received a URL, hand it off to the existing instance.
+    // don't call anotherInstanceRunning() when doing URL handoff, as
+    // it relies on checking a marker file which will not work when running
+    // out of different directories
+
+    if (start_slurl.isValid() &&
+        (gSavedSettings.getBOOL("SLURLPassToOtherInstance")))
+    {
+        if (sendURLToOtherInstance(start_slurl.getSLURLString()))
+        {
+            // successfully handed off URL to existing instance, exit
+            return false;
+        }
+    }
+
+    // Display splash screen.  Must be after above check for previous
+    // crash as this dialog is always frontmost.
+    std::string splash_msg;
+    LLStringUtil::format_map_t args;
+    args["[APP_NAME]"] = getSecondLifeTitle();
+    splash_msg = LLTrans::getString("StartupLoading", args);
+    LLSplashScreen::show();
+    LLSplashScreen::update(splash_msg);
+
+    //LLVolumeMgr::initClass();
+    LLVolumeMgr* volume_manager = new LLVolumeMgr();
+    volume_manager->useMutex(); // LLApp and LLMutex magic must be manually enabled
+    LLPrimitive::setVolumeManager(volume_manager);
+
+    // Note: this is where we used to initialize gFeatureManagerp.
+
+    gStartTime = totalTime();
+
+    //
+    // Set the name of the window
+    //
+    if (LLVersionInfo::instance().getViewerMaturity() != LLVersionInfo::RELEASE_VIEWER)
+    {
+        gWindowTitle = LLVersionInfo::instance().getChannelAndVersion();
+    }
+    else
+    {
+        gWindowTitle = LLTrans::getString("APP_NAME");
+    }
 #if LL_DEBUG
-	gWindowTitle += std::string(" [DEBUG]");
+    gWindowTitle += std::string(" [DEBUG]");
 #elif defined(LL_RELEASE_WITH_DEBUG_INFO) || defined(SHOW_ASSERT)
     gWindowTitle += std::string(" [ASSERT]");
 #endif
-	if (!gArgs.empty())
-	{
-	gWindowTitle += std::string(" ") + gArgs;
-	}
-	LLStringUtil::truncate(gWindowTitle, 255);
-
-	//
-	// Check for another instance of the app running
-	// This happens AFTER LLSplashScreen::show(). That may or may not be
-	// important.
-	//
-	if (mSecondInstance && !gSavedSettings.getBOOL("AllowMultipleViewers"))
-	{
-		OSMessageBox(
-			LLTrans::getString("MBAlreadyRunning"),
-			LLStringUtil::null,
-			OSMB_OK);
-		return false;
-	}
-
-	if (mSecondInstance)
-	{
-		// This is the second instance of SL. Mute voice,
-		// but make sure the setting is *not* persisted.
-		// Also see LLVivoxVoiceClient::voiceEnabled()
-		LLControlVariable* enable_voice = gSavedSettings.getControl("EnableVoiceChat");
-		if(enable_voice && !gSavedSettings.getBOOL("VoiceMultiInstance"))
-		{
-			const BOOL DO_NOT_PERSIST = FALSE;
-			enable_voice->setValue(LLSD(FALSE), DO_NOT_PERSIST);
-		}
-	}
-
-	gLastRunVersion = gSavedSettings.getString("LastRunVersion");
-
-	loadColorSettings();
-
-	// Let anyone else who cares know that we've populated our settings
-	// variables.
-	for (const auto& key : LLControlGroup::key_snapshot())
-	{
-		// For each named instance of LLControlGroup, send an event saying
-		// we've initialized an LLControlGroup instance by that name.
-		LLEventPumps::instance().obtain("LLControlGroup").post(LLSDMap("init", key));
-	}
+    if (!gArgs.empty())
+    {
+    gWindowTitle += std::string(" ") + gArgs;
+    }
+    LLStringUtil::truncate(gWindowTitle, 255);
+
+    //
+    // Check for another instance of the app running
+    // This happens AFTER LLSplashScreen::show(). That may or may not be
+    // important.
+    //
+    if (mSecondInstance && !gSavedSettings.getBOOL("AllowMultipleViewers"))
+    {
+        OSMessageBox(
+            LLTrans::getString("MBAlreadyRunning"),
+            LLStringUtil::null,
+            OSMB_OK);
+        return false;
+    }
+
+    if (mSecondInstance)
+    {
+        // This is the second instance of SL. Mute voice,
+        // but make sure the setting is *not* persisted.
+        // Also see LLVivoxVoiceClient::voiceEnabled()
+        LLControlVariable* enable_voice = gSavedSettings.getControl("EnableVoiceChat");
+        if(enable_voice && !gSavedSettings.getBOOL("VoiceMultiInstance"))
+        {
+            const BOOL DO_NOT_PERSIST = FALSE;
+            enable_voice->setValue(LLSD(FALSE), DO_NOT_PERSIST);
+        }
+    }
+
+    gLastRunVersion = gSavedSettings.getString("LastRunVersion");
+
+    loadColorSettings();
+
+    // Let anyone else who cares know that we've populated our settings
+    // variables.
+    for (const auto& key : LLControlGroup::key_snapshot())
+    {
+        // For each named instance of LLControlGroup, send an event saying
+        // we've initialized an LLControlGroup instance by that name.
+        LLEventPumps::instance().obtain("LLControlGroup").post(LLSDMap("init", key));
+    }
 
 // [RLVa:KB] - Patch: RLVa-2.1.0
     if (LLControlVariable* pControl = gSavedSettings.getControl(RlvSettingNames::Main))
-	{
-		if ( (pControl->getValue().asBoolean()) && (pControl->hasUnsavedValue()) )
-		{
-			pControl->resetToDefault();
-			pControl->setValue(false);
-
-			std::ostringstream msg;
-			msg << LLTrans::getString("RLVaToggleMessageLogin", LLSD().with("[STATE]", LLTrans::getString("RLVaToggleDisabled")));
-			OSMessageBox(msg.str(), LLStringUtil::null, OSMB_OK);
-		}
-	}
+    {
+        if ( (pControl->getValue().asBoolean()) && (pControl->hasUnsavedValue()) )
+        {
+            pControl->resetToDefault();
+            pControl->setValue(false);
+
+            std::ostringstream msg;
+            msg << LLTrans::getString("RLVaToggleMessageLogin", LLSD().with("[STATE]", LLTrans::getString("RLVaToggleDisabled")));
+            OSMessageBox(msg.str(), LLStringUtil::null, OSMB_OK);
+        }
+    }
 // [/RLVa:KB]
 
     LLError::LLUserWarningMsg::setOutOfMemoryStrings(LLTrans::getString("MBOutOfMemoryTitle"), LLTrans::getString("MBOutOfMemoryErr"));
 
-	return true; // Config was successful.
+    return true; // Config was successful.
 }
 
 // The following logic is replicated in initConfiguration() (to be able to get
@@ -2976,184 +2976,184 @@ bool LLAppViewer::initConfiguration()
 // keeps growing, necessitating a method all its own.
 void LLAppViewer::initStrings()
 {
-	std::string strings_file = "strings.xml";
-	std::string strings_path_full = gDirUtilp->findSkinnedFilenameBaseLang(LLDir::XUI, strings_file);
-	if (strings_path_full.empty() || !LLFile::isfile(strings_path_full))
-	{
-		if (strings_path_full.empty())
-		{
-			LL_WARNS() << "The file '" << strings_file << "' is not found" << LL_ENDL;
-		}
-		else
-		{
-			llstat st;
-			int rc = LLFile::stat(strings_path_full, &st);
-			if (rc != 0)
-			{
-				LL_WARNS() << "The file '" << strings_path_full << "' failed to get status. Error code: " << rc << LL_ENDL;
-			}
-			else if (S_ISDIR(st.st_mode))
-			{
-				LL_WARNS() << "The filename '" << strings_path_full << "' is a directory name" << LL_ENDL;
-			}
-			else
-			{
-				LL_WARNS() << "The filename '" << strings_path_full << "' doesn't seem to be a regular file name" << LL_ENDL;
-			}
-		}
-
-		// initial check to make sure files are there failed
-		gDirUtilp->dumpCurrentDirectories(LLError::LEVEL_WARN);
+    std::string strings_file = "strings.xml";
+    std::string strings_path_full = gDirUtilp->findSkinnedFilenameBaseLang(LLDir::XUI, strings_file);
+    if (strings_path_full.empty() || !LLFile::isfile(strings_path_full))
+    {
+        if (strings_path_full.empty())
+        {
+            LL_WARNS() << "The file '" << strings_file << "' is not found" << LL_ENDL;
+        }
+        else
+        {
+            llstat st;
+            int rc = LLFile::stat(strings_path_full, &st);
+            if (rc != 0)
+            {
+                LL_WARNS() << "The file '" << strings_path_full << "' failed to get status. Error code: " << rc << LL_ENDL;
+            }
+            else if (S_ISDIR(st.st_mode))
+            {
+                LL_WARNS() << "The filename '" << strings_path_full << "' is a directory name" << LL_ENDL;
+            }
+            else
+            {
+                LL_WARNS() << "The filename '" << strings_path_full << "' doesn't seem to be a regular file name" << LL_ENDL;
+            }
+        }
+
+        // initial check to make sure files are there failed
+        gDirUtilp->dumpCurrentDirectories(LLError::LEVEL_WARN);
         LLError::LLUserWarningMsg::showMissingFiles();
-		LL_ERRS() << "Viewer failed to find localization and UI files."
-			<< " Please reinstall viewer from https://secondlife.com/support/downloads"
-			<< " and contact https://support.secondlife.com if issue persists after reinstall." << LL_ENDL;
-	}
-	LLTransUtil::parseStrings(strings_file, default_trans_args);
-	LLTransUtil::parseLanguageStrings("language_settings.xml");
-
-	// parseStrings() sets up the LLTrans substitution table. Add this one item.
-	LLTrans::setDefaultArg("[sourceid]", gSavedSettings.getString("sourceid"));
-
-	// Now that we've set "[sourceid]", have to go back through
-	// default_trans_args and reinitialize all those other keys because some
-	// of them, in turn, reference "[sourceid]".
-	for (const std::string& key : default_trans_args)
-	{
-		std::string brackets(key), nobrackets(key);
-		// Invalid to inspect key[0] if key is empty(). But then, the entire
-		// body of this loop is pointless if key is empty().
-		if (key.empty())
-			continue;
-
-		if (key[0] != '[')
-		{
-			// key was passed without brackets. That means that 'nobrackets'
-			// is correct but 'brackets' is not.
-			brackets = STRINGIZE('[' << brackets << ']');
-		}
-		else
-		{
-			// key was passed with brackets. That means that 'brackets' is
-			// correct but 'nobrackets' is not. Erase the left bracket.
-			nobrackets.erase(0, 1);
-			std::string::size_type length(nobrackets.length());
-			if (length && nobrackets[length - 1] == ']')
-			{
-				nobrackets.erase(length - 1);
-			}
-		}
-		// Calling LLTrans::getString() is what embeds the other default
-		// translation strings into this one.
-		LLTrans::setDefaultArg(brackets, LLTrans::getString(nobrackets));
-	}
-}
+        LL_ERRS() << "Viewer failed to find localization and UI files."
+            << " Please reinstall viewer from https://secondlife.com/support/downloads"
+            << " and contact https://support.secondlife.com if issue persists after reinstall." << LL_ENDL;
+    }
+    LLTransUtil::parseStrings(strings_file, default_trans_args);
+    LLTransUtil::parseLanguageStrings("language_settings.xml");
 
-bool LLAppViewer::initWindow()
-{
-	LL_INFOS("AppInit") << "Initializing window..." << LL_ENDL;
-
-	// store setting in a global for easy access and modification
-	gHeadlessClient = gSavedSettings.getBOOL("HeadlessClient");
-
-	// always start windowed
-	BOOL ignorePixelDepth = gSavedSettings.getBOOL("IgnorePixelDepth");
-
-	LLViewerWindow::Params window_params;
-	window_params
-		.title(gWindowTitle)
-		.name(VIEWER_WINDOW_CLASSNAME)
-		.x(gSavedSettings.getS32("WindowX"))
-		.y(gSavedSettings.getS32("WindowY"))
-		.width(gSavedSettings.getU32("WindowWidth"))
-		.height(gSavedSettings.getU32("WindowHeight"))
-		.min_width(gSavedSettings.getU32("MinWindowWidth"))
-		.min_height(gSavedSettings.getU32("MinWindowHeight"))
-		.fullscreen(gSavedSettings.getBOOL("FullScreen"))
-		.ignore_pixel_depth(ignorePixelDepth)
-		.first_run(mIsFirstRun);
-
-	gViewerWindow = new LLViewerWindow(window_params);
-
-	LL_INFOS("AppInit") << "gViewerwindow created." << LL_ENDL;
-
-	// Need to load feature table before cheking to start watchdog.
-	bool use_watchdog = false;
-	int watchdog_enabled_setting = gSavedSettings.getS32("WatchdogEnabled");
-	if (watchdog_enabled_setting == -1)
-	{
-		use_watchdog = !LLFeatureManager::getInstance()->isFeatureAvailable("WatchdogDisabled");
-	}
-	else
-	{
-		// The user has explicitly set this setting; always use that value.
-		use_watchdog = bool(watchdog_enabled_setting);
-	}
-
-	LL_INFOS("AppInit") << "watchdog"
-						<< (use_watchdog ? " " : " NOT ")
-						<< "enabled"
-						<< " (setting = " << watchdog_enabled_setting << ")"
-						<< LL_ENDL;
-
-	if (use_watchdog)
-	{
-		LLWatchdog::getInstance()->init();
-	}
-
-	LLNotificationsUI::LLNotificationManager::getInstance();
-
-	if (gSavedSettings.getBOOL("WindowMaximized"))
-	{
-		gViewerWindow->getWindow()->maximize();
-	}
-
-	//
-	// Initialize GL stuff
-	//
-
-	if (mForceGraphicsLevel && (LLFeatureManager::instance().isValidGraphicsLevel(*mForceGraphicsLevel)))
-	{
-		LLFeatureManager::getInstance()->setGraphicsLevel(*mForceGraphicsLevel, false);
-		gSavedSettings.setU32("RenderQualityPerformance", *mForceGraphicsLevel);
-	}
-
-	// Set this flag in case we crash while initializing GL
-	gSavedSettings.setBOOL("RenderInitError", TRUE);
-	gSavedSettings.saveToFile( gSavedSettings.getString("ClientSettingsFile"), TRUE );
-
-	gPipeline.init();
-	LL_INFOS("AppInit") << "gPipeline Initialized" << LL_ENDL;
-
-	stop_glerror();
-	gViewerWindow->initGLDefaults();
-
-	gSavedSettings.setBOOL("RenderInitError", FALSE);
-	gSavedSettings.saveToFile( gSavedSettings.getString("ClientSettingsFile"), TRUE );
-
-	//If we have a startup crash, it's usually near GL initialization, so simulate that.
-	if(gCrashOnStartup)
-	{
-		LLAppViewer::instance()->forceErrorLLError();
-	}
-
-	LLUI::sWindow = gViewerWindow->getWindow();
-
-	// Show watch cursor
-	gViewerWindow->setCursor(UI_CURSOR_WAIT);
-
-	// Finish view initialization
-	gViewerWindow->initBase();
-
-	// show viewer window
-	//gViewerWindow->getWindow()->show();
-
-	LL_INFOS("AppInit") << "Window initialization done." << LL_ENDL;
-
-	return true;
-}
+    // parseStrings() sets up the LLTrans substitution table. Add this one item.
+    LLTrans::setDefaultArg("[sourceid]", gSavedSettings.getString("sourceid"));
 
-bool LLAppViewer::isUpdaterMissing()
+    // Now that we've set "[sourceid]", have to go back through
+    // default_trans_args and reinitialize all those other keys because some
+    // of them, in turn, reference "[sourceid]".
+    for (const std::string& key : default_trans_args)
+    {
+        std::string brackets(key), nobrackets(key);
+        // Invalid to inspect key[0] if key is empty(). But then, the entire
+        // body of this loop is pointless if key is empty().
+        if (key.empty())
+            continue;
+
+        if (key[0] != '[')
+        {
+            // key was passed without brackets. That means that 'nobrackets'
+            // is correct but 'brackets' is not.
+            brackets = STRINGIZE('[' << brackets << ']');
+        }
+        else
+        {
+            // key was passed with brackets. That means that 'brackets' is
+            // correct but 'nobrackets' is not. Erase the left bracket.
+            nobrackets.erase(0, 1);
+            std::string::size_type length(nobrackets.length());
+            if (length && nobrackets[length - 1] == ']')
+            {
+                nobrackets.erase(length - 1);
+            }
+        }
+        // Calling LLTrans::getString() is what embeds the other default
+        // translation strings into this one.
+        LLTrans::setDefaultArg(brackets, LLTrans::getString(nobrackets));
+    }
+}
+
+bool LLAppViewer::initWindow()
+{
+    LL_INFOS("AppInit") << "Initializing window..." << LL_ENDL;
+
+    // store setting in a global for easy access and modification
+    gHeadlessClient = gSavedSettings.getBOOL("HeadlessClient");
+
+    // always start windowed
+    BOOL ignorePixelDepth = gSavedSettings.getBOOL("IgnorePixelDepth");
+
+    LLViewerWindow::Params window_params;
+    window_params
+        .title(gWindowTitle)
+        .name(VIEWER_WINDOW_CLASSNAME)
+        .x(gSavedSettings.getS32("WindowX"))
+        .y(gSavedSettings.getS32("WindowY"))
+        .width(gSavedSettings.getU32("WindowWidth"))
+        .height(gSavedSettings.getU32("WindowHeight"))
+        .min_width(gSavedSettings.getU32("MinWindowWidth"))
+        .min_height(gSavedSettings.getU32("MinWindowHeight"))
+        .fullscreen(gSavedSettings.getBOOL("FullScreen"))
+        .ignore_pixel_depth(ignorePixelDepth)
+        .first_run(mIsFirstRun);
+
+    gViewerWindow = new LLViewerWindow(window_params);
+
+    LL_INFOS("AppInit") << "gViewerwindow created." << LL_ENDL;
+
+    // Need to load feature table before cheking to start watchdog.
+    bool use_watchdog = false;
+    int watchdog_enabled_setting = gSavedSettings.getS32("WatchdogEnabled");
+    if (watchdog_enabled_setting == -1)
+    {
+        use_watchdog = !LLFeatureManager::getInstance()->isFeatureAvailable("WatchdogDisabled");
+    }
+    else
+    {
+        // The user has explicitly set this setting; always use that value.
+        use_watchdog = bool(watchdog_enabled_setting);
+    }
+
+    LL_INFOS("AppInit") << "watchdog"
+                        << (use_watchdog ? " " : " NOT ")
+                        << "enabled"
+                        << " (setting = " << watchdog_enabled_setting << ")"
+                        << LL_ENDL;
+
+    if (use_watchdog)
+    {
+        LLWatchdog::getInstance()->init();
+    }
+
+    LLNotificationsUI::LLNotificationManager::getInstance();
+
+    if (gSavedSettings.getBOOL("WindowMaximized"))
+    {
+        gViewerWindow->getWindow()->maximize();
+    }
+
+    //
+    // Initialize GL stuff
+    //
+
+    if (mForceGraphicsLevel && (LLFeatureManager::instance().isValidGraphicsLevel(*mForceGraphicsLevel)))
+    {
+        LLFeatureManager::getInstance()->setGraphicsLevel(*mForceGraphicsLevel, false);
+        gSavedSettings.setU32("RenderQualityPerformance", *mForceGraphicsLevel);
+    }
+
+    // Set this flag in case we crash while initializing GL
+    gSavedSettings.setBOOL("RenderInitError", TRUE);
+    gSavedSettings.saveToFile( gSavedSettings.getString("ClientSettingsFile"), TRUE );
+
+    gPipeline.init();
+    LL_INFOS("AppInit") << "gPipeline Initialized" << LL_ENDL;
+
+    stop_glerror();
+    gViewerWindow->initGLDefaults();
+
+    gSavedSettings.setBOOL("RenderInitError", FALSE);
+    gSavedSettings.saveToFile( gSavedSettings.getString("ClientSettingsFile"), TRUE );
+
+    //If we have a startup crash, it's usually near GL initialization, so simulate that.
+    if(gCrashOnStartup)
+    {
+        LLAppViewer::instance()->forceErrorLLError();
+    }
+
+    LLUI::sWindow = gViewerWindow->getWindow();
+
+    // Show watch cursor
+    gViewerWindow->setCursor(UI_CURSOR_WAIT);
+
+    // Finish view initialization
+    gViewerWindow->initBase();
+
+    // show viewer window
+    //gViewerWindow->getWindow()->show();
+
+    LL_INFOS("AppInit") << "Window initialization done." << LL_ENDL;
+
+    return true;
+}
+
+bool LLAppViewer::isUpdaterMissing()
 {
     return mUpdaterNotFound;
 }
@@ -3189,28 +3189,28 @@ void LLAppViewer::writeDebugInfo(bool isStatic)
 
 LLSD LLAppViewer::getViewerInfo() const
 {
-	// The point of having one method build an LLSD info block and the other
-	// construct the user-visible About string is to ensure that the same info
-	// is available to a getInfo() caller as to the user opening
-	// LLFloaterAbout.
-	LLSD info;
-	auto& versionInfo(LLVersionInfo::instance());
-	// With GitHub builds, the build number is too big to fit in a 32-bit int,
-	// and LLSD doesn't deal with integers wider than int. Use string.
-	info["VIEWER_VERSION"] = llsd::array(versionInfo.getMajor(), versionInfo.getMinor(),
-										 versionInfo.getPatch(), stringize(versionInfo.getBuild()));
-	info["VIEWER_VERSION_STR"] = versionInfo.getVersion();
-	info["CHANNEL"] = versionInfo.getChannel();
-	info["ADDRESS_SIZE"] = ADDRESS_SIZE;
-	std::string build_config = versionInfo.getBuildConfig();
-	if (build_config != "Release")
-	{
-		info["BUILD_CONFIG"] = build_config;
-	}
-
-	// return a URL to the release notes for this viewer, such as:
-	// https://releasenotes.secondlife.com/viewer/2.1.0.123456.html
-	std::string url = versionInfo.getReleaseNotes(); // VVM supplied
+    // The point of having one method build an LLSD info block and the other
+    // construct the user-visible About string is to ensure that the same info
+    // is available to a getInfo() caller as to the user opening
+    // LLFloaterAbout.
+    LLSD info;
+    auto& versionInfo(LLVersionInfo::instance());
+    // With GitHub builds, the build number is too big to fit in a 32-bit int,
+    // and LLSD doesn't deal with integers wider than int. Use string.
+    info["VIEWER_VERSION"] = llsd::array(versionInfo.getMajor(), versionInfo.getMinor(),
+                                         versionInfo.getPatch(), stringize(versionInfo.getBuild()));
+    info["VIEWER_VERSION_STR"] = versionInfo.getVersion();
+    info["CHANNEL"] = versionInfo.getChannel();
+    info["ADDRESS_SIZE"] = ADDRESS_SIZE;
+    std::string build_config = versionInfo.getBuildConfig();
+    if (build_config != "Release")
+    {
+        info["BUILD_CONFIG"] = build_config;
+    }
+
+    // return a URL to the release notes for this viewer, such as:
+    // https://releasenotes.secondlife.com/viewer/2.1.0.123456.html
+    std::string url = versionInfo.getReleaseNotes(); // VVM supplied
     if (url.empty())
     {
         url = LLTrans::getString("RELEASE_NOTES_BASE_URL");
@@ -3218,59 +3218,59 @@ LLSD LLAppViewer::getViewerInfo() const
             url += "/";
         url += LLURI::escape(versionInfo.getVersion()) + ".html";
     }
-	info["VIEWER_RELEASE_NOTES_URL"] = url;
+    info["VIEWER_RELEASE_NOTES_URL"] = url;
 
 #if LL_MSVC && !defined(LL_CLANG)
-	info["COMPILER"] = "MSVC";
-	info["COMPILER_VERSION"] = _MSC_FULL_VER;
+    info["COMPILER"] = "MSVC";
+    info["COMPILER_VERSION"] = _MSC_FULL_VER;
 #elif LL_CLANG
     info["COMPILER"] = "Clang";
     info["COMPILER_VERSION"] = __clang_version__;
 #elif LL_GNUC
-	info["COMPILER"] = "GCC";
-	info["COMPILER_VERSION"] = GCC_VERSION;
+    info["COMPILER"] = "GCC";
+    info["COMPILER_VERSION"] = GCC_VERSION;
 #elif LL_INTELC
-	info["COMPILER"] = "ICC";
-	info["COMPILER_VERSION"] = __ICC;
+    info["COMPILER"] = "ICC";
+    info["COMPILER_VERSION"] = __ICC;
 #endif
 
-	// Position
-	LLViewerRegion* region = gAgent.getRegion();
-	if (region)
-	{
+    // Position
+    LLViewerRegion* region = gAgent.getRegion();
+    if (region)
+    {
 // [RLVa:KB] - Checked: 2014-02-24 (RLVa-1.4.10)
-		if (RlvActions::canShowLocation())
-		{
+        if (RlvActions::canShowLocation())
+        {
 // [/RLVa:KB]
-			LLVector3d pos = gAgent.getPositionGlobal();
-			info["POSITION"] = ll_sd_from_vector3d(pos);
-			info["POSITION_LOCAL"] = ll_sd_from_vector3(gAgent.getPosAgentFromGlobal(pos));
-			info["REGION"] = gAgent.getRegion()->getName();
-
-			boost::regex regex("\\.(secondlife|lindenlab)\\..*");
-			info["HOSTNAME"] = ll_regex_replace(gAgent.getRegion()->getSimHostName(), regex, "");
-			info["SERVER_VERSION"] = gLastVersionChannel;
-			LLSLURL slurl;
-			LLAgentUI::buildSLURL(slurl);
-			info["SLURL"] = slurl.getSLURLString();
+            LLVector3d pos = gAgent.getPositionGlobal();
+            info["POSITION"] = ll_sd_from_vector3d(pos);
+            info["POSITION_LOCAL"] = ll_sd_from_vector3(gAgent.getPosAgentFromGlobal(pos));
+            info["REGION"] = gAgent.getRegion()->getName();
+
+            boost::regex regex("\\.(secondlife|lindenlab)\\..*");
+            info["HOSTNAME"] = ll_regex_replace(gAgent.getRegion()->getSimHostName(), regex, "");
+            info["SERVER_VERSION"] = gLastVersionChannel;
+            LLSLURL slurl;
+            LLAgentUI::buildSLURL(slurl);
+            info["SLURL"] = slurl.getSLURLString();
 // [RLVa:KB] - Checked: 2014-02-24 (RLVa-1.4.10)
-		}
-		else
-		{
-			info["REGION"] = RlvStrings::getString(RlvStringKeys::Hidden::Region);
-		}
-		info["SERVER_VERSION"] = gLastVersionChannel;
+        }
+        else
+        {
+            info["REGION"] = RlvStrings::getString(RlvStringKeys::Hidden::Region);
+        }
+        info["SERVER_VERSION"] = gLastVersionChannel;
 // [/RLVa:KB]
-	}
+    }
 
-	// CPU
-	info["CPU"] = gSysCPU.getCPUString();
-	info["MEMORY_MB"] = LLSD::Integer(gSysMemory.getPhysicalMemoryKB().valueInUnits<LLUnits::Megabytes>());
-	// Moved hack adjustment to Windows memory size into llsys.cpp
+    // CPU
+    info["CPU"] = gSysCPU.getCPUString();
+    info["MEMORY_MB"] = LLSD::Integer(gSysMemory.getPhysicalMemoryKB().valueInUnits<LLUnits::Megabytes>());
+    // Moved hack adjustment to Windows memory size into llsys.cpp
     info["CONCURRENCY"] = LLSD::Integer((S32) std::thread::hardware_concurrency());
-	info["OS_VERSION"] = LLOSInfo::instance().getOSString();
-	info["GRAPHICS_CARD_VENDOR"] = ll_safe_string((const char*)(glGetString(GL_VENDOR)));
-	info["GRAPHICS_CARD"] = ll_safe_string((const char*)(glGetString(GL_RENDERER)));
+    info["OS_VERSION"] = LLOSInfo::instance().getOSString();
+    info["GRAPHICS_CARD_VENDOR"] = ll_safe_string((const char*)(glGetString(GL_VENDOR)));
+    info["GRAPHICS_CARD"] = ll_safe_string((const char*)(glGetString(GL_RENDERER)));
 
 #if LL_WINDOWS
     std::string drvinfo;
@@ -3295,25 +3295,25 @@ LLSD LLAppViewer::getViewerInfo() const
         drvinfo = gDXHardware.getDriverVersionWMI(LLDXHardware::GPU_ANY);
     }
 
-	if (!drvinfo.empty())
-	{
-		info["GRAPHICS_DRIVER_VERSION"] = drvinfo;
-	}
-	else
-	{
-		LL_WARNS("DriverVersion")<< "Cannot get driver version from getDriverVersionWMI" << LL_ENDL;
-		LLSD driver_info = gDXHardware.getDisplayInfo();
-		if (driver_info.has("DriverVersion"))
-		{
-			info["GRAPHICS_DRIVER_VERSION"] = driver_info["DriverVersion"];
-		}
-	}
+    if (!drvinfo.empty())
+    {
+        info["GRAPHICS_DRIVER_VERSION"] = drvinfo;
+    }
+    else
+    {
+        LL_WARNS("DriverVersion")<< "Cannot get driver version from getDriverVersionWMI" << LL_ENDL;
+        LLSD driver_info = gDXHardware.getDisplayInfo();
+        if (driver_info.has("DriverVersion"))
+        {
+            info["GRAPHICS_DRIVER_VERSION"] = driver_info["DriverVersion"];
+        }
+    }
 #endif
 
 // [RLVa:KB] - Checked: 2010-04-18 (RLVa-1.2.0)
-	info["RLV_VERSION"] = (rlv_handler_t::isEnabled()) ? RlvStrings::getVersionAbout() : "(disabled)";
+    info["RLV_VERSION"] = (rlv_handler_t::isEnabled()) ? RlvStrings::getVersionAbout() : "(disabled)";
 // [/RLVa:KB]
-	info["OPENGL_VERSION"] = ll_safe_string((const char*)(glGetString(GL_VERSION)));
+    info["OPENGL_VERSION"] = ll_safe_string((const char*)(glGetString(GL_VERSION)));
 
     // Settings
 
@@ -3321,12 +3321,12 @@ LLSD LLAppViewer::getViewerInfo() const
     info["WINDOW_WIDTH"] = window_rect.getWidth();
     info["WINDOW_HEIGHT"] = window_rect.getHeight();
     info["FONT_SIZE_ADJUSTMENT"] = gSavedSettings.getF32("FontScreenDPI");
-	std::string mainfont = gSavedSettings.getString("FontOverrideMain");
-	info["FONT_MAIN_OVERRIDE"] = !mainfont.empty() ? mainfont : LLTrans::getString("Default");
-	std::string monofont = gSavedSettings.getString("FontOverrideMonospace");
-	info["FONT_MONO_OVERRIDE"] = !monofont.empty() ? monofont : LLTrans::getString("Default");
-	info["FONT_CHAT_OVERRIDE"] = gSavedSettings.getString("ChatFontName");
-	info["FONT_SCRIPT_OVERRIDE"] = gSavedSettings.getString("ScriptFontName");
+    std::string mainfont = gSavedSettings.getString("FontOverrideMain");
+    info["FONT_MAIN_OVERRIDE"] = !mainfont.empty() ? mainfont : LLTrans::getString("Default");
+    std::string monofont = gSavedSettings.getString("FontOverrideMonospace");
+    info["FONT_MONO_OVERRIDE"] = !monofont.empty() ? monofont : LLTrans::getString("Default");
+    info["FONT_CHAT_OVERRIDE"] = gSavedSettings.getString("ChatFontName");
+    info["FONT_SCRIPT_OVERRIDE"] = gSavedSettings.getString("ScriptFontName");
     info["UI_SCALE"] = gSavedSettings.getF32("UIScaleFactor");
     info["DRAW_DISTANCE"] = gSavedSettings.getF32("RenderFarClip");
     info["NET_BANDWITH"] = gSavedSettings.getF32("ThrottleBandwidthKBPS");
@@ -3338,16 +3338,16 @@ LLSD LLAppViewer::getViewerInfo() const
     info["HIDPI"] = gHiDPISupport;
 #endif
 
-	// Libraries
-	info["LIBCURL_VERSION"] = LLCore::LLHttp::getCURLVersion();
-	info["J2C_VERSION"] = LLImageJ2C::getEngineInfo();
-	bool want_fullname = true;
-	info["AUDIO_DRIVER_VERSION"] = gAudiop ? LLSD(gAudiop->getDriverName(want_fullname)) : "Undefined";
-	if(LLVoiceClient::getInstance()->voiceEnabled())
-	{
+    // Libraries
+    info["LIBCURL_VERSION"] = LLCore::LLHttp::getCURLVersion();
+    info["J2C_VERSION"] = LLImageJ2C::getEngineInfo();
+    bool want_fullname = true;
+    info["AUDIO_DRIVER_VERSION"] = gAudiop ? LLSD(gAudiop->getDriverName(want_fullname)) : "Undefined";
+    if(LLVoiceClient::getInstance()->voiceEnabled())
+    {
         LLVoiceVersionInfo version = LLVoiceClient::getInstance()->getVersion();
         const std::string build_version = version.mBuildVersion;
-		std::ostringstream version_string;
+        std::ostringstream version_string;
         if (std::equal(build_version.begin(), build_version.begin() + version.serverVersion.size(),
                        version.serverVersion.begin()))
         {  // Normal case: Show type and build version.
@@ -3357,216 +3357,216 @@ LLSD LLAppViewer::getViewerInfo() const
         {  // Mismatch: Show both versions.
             version_string << version.serverVersion << "/" << build_version << std::endl;
         }
-		info["VOICE_VERSION"] = version_string.str();
-	}
-	else
-	{
-		info["VOICE_VERSION"] = LLTrans::getString("NotConnected");
-	}
+        info["VOICE_VERSION"] = version_string.str();
+    }
+    else
+    {
+        info["VOICE_VERSION"] = LLTrans::getString("NotConnected");
+    }
 
 #if USE_CEF
-	std::ostringstream cef_ver_codec;
-	cef_ver_codec << "Dullahan: ";
-	cef_ver_codec << DULLAHAN_VERSION_MAJOR;
-	cef_ver_codec << ".";
-	cef_ver_codec << DULLAHAN_VERSION_MINOR;
-	cef_ver_codec << ".";
-	cef_ver_codec << DULLAHAN_VERSION_POINT;
-
-	cef_ver_codec << std::endl;
-	cef_ver_codec << "  CEF: ";
-	cef_ver_codec << CEF_VERSION;
-
-	cef_ver_codec << std::endl;
-	cef_ver_codec << "  Chromium: ";
-	cef_ver_codec << CHROME_VERSION_MAJOR;
-	cef_ver_codec << ".";
-	cef_ver_codec << CHROME_VERSION_MINOR;
-	cef_ver_codec << ".";
-	cef_ver_codec << CHROME_VERSION_BUILD;
-	cef_ver_codec << ".";
-	cef_ver_codec << CHROME_VERSION_PATCH;
-
-	info["CEF_VERSION"] = cef_ver_codec.str();
+    std::ostringstream cef_ver_codec;
+    cef_ver_codec << "Dullahan: ";
+    cef_ver_codec << DULLAHAN_VERSION_MAJOR;
+    cef_ver_codec << ".";
+    cef_ver_codec << DULLAHAN_VERSION_MINOR;
+    cef_ver_codec << ".";
+    cef_ver_codec << DULLAHAN_VERSION_POINT;
+
+    cef_ver_codec << std::endl;
+    cef_ver_codec << "  CEF: ";
+    cef_ver_codec << CEF_VERSION;
+
+    cef_ver_codec << std::endl;
+    cef_ver_codec << "  Chromium: ";
+    cef_ver_codec << CHROME_VERSION_MAJOR;
+    cef_ver_codec << ".";
+    cef_ver_codec << CHROME_VERSION_MINOR;
+    cef_ver_codec << ".";
+    cef_ver_codec << CHROME_VERSION_BUILD;
+    cef_ver_codec << ".";
+    cef_ver_codec << CHROME_VERSION_PATCH;
+
+    info["CEF_VERSION"] = cef_ver_codec.str();
 #else
-	info["CEF_VERSION"] = "Web Engine: Undefined";
+    info["CEF_VERSION"] = "Web Engine: Undefined";
 #endif
 
 #if USE_VLC
-	std::ostringstream vlc_ver_codec;
-	vlc_ver_codec << LIBVLC_VERSION_MAJOR;
-	vlc_ver_codec << ".";
-	vlc_ver_codec << LIBVLC_VERSION_MINOR;
-	vlc_ver_codec << ".";
-	vlc_ver_codec << LIBVLC_VERSION_REVISION;
-	info["LIBVLC_VERSION"] = vlc_ver_codec.str();
+    std::ostringstream vlc_ver_codec;
+    vlc_ver_codec << LIBVLC_VERSION_MAJOR;
+    vlc_ver_codec << ".";
+    vlc_ver_codec << LIBVLC_VERSION_MINOR;
+    vlc_ver_codec << ".";
+    vlc_ver_codec << LIBVLC_VERSION_REVISION;
+    info["LIBVLC_VERSION"] = vlc_ver_codec.str();
 #else
-	info["LIBVLC_VERSION"] = "Undefined";
+    info["LIBVLC_VERSION"] = "Undefined";
 #endif
 
-	S32 packets_in = LLViewerStats::instance().getRecording().getSum(LLStatViewer::PACKETS_IN);
-	if (packets_in > 0)
-	{
-		F64 packets_lost = LLViewerStats::instance().getRecording().getSum(LLStatViewer::PACKETS_LOST);
-		info["PACKETS_LOST"] = packets_lost;
-		info["PACKETS_IN"] = packets_in;
-		info["PACKETS_PCT"] = LLUnits::Ratio::fromValue(packets_lost / packets_in).value();
-	}
-
-	if (mServerReleaseNotesURL.empty())
-	{
-		if (gAgent.getRegion())
-		{
-			info["SERVER_RELEASE_NOTES_URL"] = LLTrans::getString("RetrievingData");
-		}
-		else
-		{
-			info["SERVER_RELEASE_NOTES_URL"] = LLTrans::getString("NotConnected");
-		}
-	}
-	else if (LLStringUtil::startsWith(mServerReleaseNotesURL, "http")) // it's an URL
-	{
-		info["SERVER_RELEASE_NOTES_URL"] = "[" + LLWeb::escapeURL(mServerReleaseNotesURL) + " " + LLTrans::getString("ReleaseNotes") + "]";
-	}
-	else
-	{
-		info["SERVER_RELEASE_NOTES_URL"] = mServerReleaseNotesURL;
-	}
-
-	// populate field for the texture cache with some details
-	S64Bytes texture_cache_used = getTextureCache()->getUsage();
-	S64Bytes texture_cache_max = getTextureCache()->getMaxUsage();
-	F64 percent_used = ((F64)texture_cache_used.value() / (F64)texture_cache_max.value()) * 100.0;
-	info["TEXTURE_CACHE_INFO"] = llformat("%dMB / %dMB (%.1f%% used)", S32Megabytes(texture_cache_used).value(), S32Megabytes(texture_cache_max).value(), percent_used);
+    S32 packets_in = LLViewerStats::instance().getRecording().getSum(LLStatViewer::PACKETS_IN);
+    if (packets_in > 0)
+    {
+        F64 packets_lost = LLViewerStats::instance().getRecording().getSum(LLStatViewer::PACKETS_LOST);
+        info["PACKETS_LOST"] = packets_lost;
+        info["PACKETS_IN"] = packets_in;
+        info["PACKETS_PCT"] = LLUnits::Ratio::fromValue(packets_lost / packets_in).value();
+    }
+
+    if (mServerReleaseNotesURL.empty())
+    {
+        if (gAgent.getRegion())
+        {
+            info["SERVER_RELEASE_NOTES_URL"] = LLTrans::getString("RetrievingData");
+        }
+        else
+        {
+            info["SERVER_RELEASE_NOTES_URL"] = LLTrans::getString("NotConnected");
+        }
+    }
+    else if (LLStringUtil::startsWith(mServerReleaseNotesURL, "http")) // it's an URL
+    {
+        info["SERVER_RELEASE_NOTES_URL"] = "[" + LLWeb::escapeURL(mServerReleaseNotesURL) + " " + LLTrans::getString("ReleaseNotes") + "]";
+    }
+    else
+    {
+        info["SERVER_RELEASE_NOTES_URL"] = mServerReleaseNotesURL;
+    }
+
+    // populate field for the texture cache with some details
+    S64Bytes texture_cache_used = getTextureCache()->getUsage();
+    S64Bytes texture_cache_max = getTextureCache()->getMaxUsage();
+    F64 percent_used = ((F64)texture_cache_used.value() / (F64)texture_cache_max.value()) * 100.0;
+    info["TEXTURE_CACHE_INFO"] = llformat("%dMB / %dMB (%.1f%% used)", S32Megabytes(texture_cache_used).value(), S32Megabytes(texture_cache_max).value(), percent_used);
 
     // populate field for new local disk cache with some details
     info["DISK_CACHE_INFO"] = LLDiskCache::getInstance()->getCacheInfo();
 
-	return info;
+    return info;
 }
 
 std::string LLAppViewer::getViewerInfoString(bool default_string) const
 {
-	std::ostringstream support;
-
-	LLSD info(getViewerInfo());
-
-	// Render the LLSD from getInfo() as a format_map_t
-	LLStringUtil::format_map_t args;
-
-	// allow the "Release Notes" URL label to be localized
-	args["ReleaseNotes"] = LLTrans::getString("ReleaseNotes", default_string);
-
-	for (LLSD::map_const_iterator ii(info.beginMap()), iend(info.endMap());
-		ii != iend; ++ii)
-	{
-		if (! ii->second.isArray())
-		{
-			// Scalar value
-			if (ii->second.isUndefined())
-			{
-				args[ii->first] = LLTrans::getString("none_text", default_string);
-			}
-			else
-			{
-				// don't forget to render value asString()
-				args[ii->first] = ii->second.asString();
-			}
-		}
-		else
-		{
-			// array value: build KEY_0, KEY_1 etc. entries
-			for (LLSD::Integer n(0), size(ii->second.size()); n < size; ++n)
-			{
-				args[STRINGIZE(ii->first << '_' << n)] = ii->second[n].asString();
-			}
-		}
-	}
-
-	// Now build the various pieces
-	support << LLTrans::getString("AboutHeader", args, default_string);
-	if (info.has("BUILD_CONFIG"))
-	{
-		support << "\n" << LLTrans::getString("BuildConfig", args, default_string);
-	}
-	if (info.has("REGION"))
-	{
+    std::ostringstream support;
+
+    LLSD info(getViewerInfo());
+
+    // Render the LLSD from getInfo() as a format_map_t
+    LLStringUtil::format_map_t args;
+
+    // allow the "Release Notes" URL label to be localized
+    args["ReleaseNotes"] = LLTrans::getString("ReleaseNotes", default_string);
+
+    for (LLSD::map_const_iterator ii(info.beginMap()), iend(info.endMap());
+        ii != iend; ++ii)
+    {
+        if (! ii->second.isArray())
+        {
+            // Scalar value
+            if (ii->second.isUndefined())
+            {
+                args[ii->first] = LLTrans::getString("none_text", default_string);
+            }
+            else
+            {
+                // don't forget to render value asString()
+                args[ii->first] = ii->second.asString();
+            }
+        }
+        else
+        {
+            // array value: build KEY_0, KEY_1 etc. entries
+            for (LLSD::Integer n(0), size(ii->second.size()); n < size; ++n)
+            {
+                args[STRINGIZE(ii->first << '_' << n)] = ii->second[n].asString();
+            }
+        }
+    }
+
+    // Now build the various pieces
+    support << LLTrans::getString("AboutHeader", args, default_string);
+    if (info.has("BUILD_CONFIG"))
+    {
+        support << "\n" << LLTrans::getString("BuildConfig", args, default_string);
+    }
+    if (info.has("REGION"))
+    {
 // [RLVa:KB] - Checked: 2014-02-24 (RLVa-1.4.10)
-		support << "\n\n" << LLTrans::getString( (RlvActions::canShowLocation()) ? "AboutPosition" : "AboutPositionRLVShowLoc", args, default_string);
+        support << "\n\n" << LLTrans::getString( (RlvActions::canShowLocation()) ? "AboutPosition" : "AboutPositionRLVShowLoc", args, default_string);
 // [/RLVa:KB]
-//		support << "\n\n" << LLTrans::getString("AboutPosition", args);
-	}
-	support << "\n\n" << LLTrans::getString("AboutSystem", args, default_string);
-	support << "\n";
-	if (info.has("GRAPHICS_DRIVER_VERSION"))
-	{
-		support << "\n" << LLTrans::getString("AboutDriver", args, default_string);
-	}
-	support << "\n" << LLTrans::getString("AboutOGL", args, default_string);
-	support << "\n\n" << LLTrans::getString("AboutSettings", args, default_string);
-
-	support << "\n\n" << LLTrans::getString("AboutLibs", args, default_string);
-	if (info.has("COMPILER"))
-	{
-		support << "\n" << LLTrans::getString("AboutCompiler", args, default_string);
-	}
-	if (info.has("PACKETS_IN"))
-	{
-		support << '\n' << LLTrans::getString("AboutTraffic", args, default_string);
-	}
-
-	// SLT timestamp
-	LLSD substitution;
-	substitution["datetime"] = (S32)time(NULL);//(S32)time_corrected();
-	support << "\n" << LLTrans::getString("AboutTime", substitution, default_string);
-
-	return support.str();
+//      support << "\n\n" << LLTrans::getString("AboutPosition", args);
+    }
+    support << "\n\n" << LLTrans::getString("AboutSystem", args, default_string);
+    support << "\n";
+    if (info.has("GRAPHICS_DRIVER_VERSION"))
+    {
+        support << "\n" << LLTrans::getString("AboutDriver", args, default_string);
+    }
+    support << "\n" << LLTrans::getString("AboutOGL", args, default_string);
+    support << "\n\n" << LLTrans::getString("AboutSettings", args, default_string);
+
+    support << "\n\n" << LLTrans::getString("AboutLibs", args, default_string);
+    if (info.has("COMPILER"))
+    {
+        support << "\n" << LLTrans::getString("AboutCompiler", args, default_string);
+    }
+    if (info.has("PACKETS_IN"))
+    {
+        support << '\n' << LLTrans::getString("AboutTraffic", args, default_string);
+    }
+
+    // SLT timestamp
+    LLSD substitution;
+    substitution["datetime"] = (S32)time(NULL);//(S32)time_corrected();
+    support << "\n" << LLTrans::getString("AboutTime", substitution, default_string);
+
+    return support.str();
 }
 
 void LLAppViewer::cleanupSavedSettings()
 {
-	gSavedSettings.setBOOL("MouseSun", FALSE);
+    gSavedSettings.setBOOL("MouseSun", FALSE);
 
-	gSavedSettings.setBOOL("UseEnergy", TRUE);				// force toggle to turn off, since sends message to simulator
+    gSavedSettings.setBOOL("UseEnergy", TRUE);              // force toggle to turn off, since sends message to simulator
 
-	gSavedSettings.setBOOL("DebugWindowProc", gDebugWindowProc);
+    gSavedSettings.setBOOL("DebugWindowProc", gDebugWindowProc);
 
-	gSavedSettings.setBOOL("ShowObjectUpdates", gShowObjectUpdates);
+    gSavedSettings.setBOOL("ShowObjectUpdates", gShowObjectUpdates);
 
-	if (gDebugView)
-	{
-		gSavedSettings.setBOOL("ShowDebugConsole", gDebugView->mDebugConsolep->getVisible());
-	}
+    if (gDebugView)
+    {
+        gSavedSettings.setBOOL("ShowDebugConsole", gDebugView->mDebugConsolep->getVisible());
+    }
 
-	// save window position if not maximized
-	// as we don't track it in callbacks
-	if(NULL != gViewerWindow)
-	{
-		BOOL maximized = gViewerWindow->getWindow()->getMaximized();
-		if (!maximized)
-		{
-			LLCoordScreen window_pos;
+    // save window position if not maximized
+    // as we don't track it in callbacks
+    if(NULL != gViewerWindow)
+    {
+        BOOL maximized = gViewerWindow->getWindow()->getMaximized();
+        if (!maximized)
+        {
+            LLCoordScreen window_pos;
 
-			if (gViewerWindow->getWindow()->getPosition(&window_pos))
-			{
-				gSavedSettings.setS32("WindowX", window_pos.mX);
-				gSavedSettings.setS32("WindowY", window_pos.mY);
-			}
-		}
-	}
+            if (gViewerWindow->getWindow()->getPosition(&window_pos))
+            {
+                gSavedSettings.setS32("WindowX", window_pos.mX);
+                gSavedSettings.setS32("WindowY", window_pos.mY);
+            }
+        }
+    }
 
     gSavedSettings.setF32("MapScale", LLWorldMapView::getScaleSetting());
 
-	// Some things are cached in LLAgent.
-	if (gAgent.isInitialized())
-	{
-		gSavedSettings.setF32("RenderFarClip", gAgentCamera.mDrawDistance);
-	}
+    // Some things are cached in LLAgent.
+    if (gAgent.isInitialized())
+    {
+        gSavedSettings.setF32("RenderFarClip", gAgentCamera.mDrawDistance);
+    }
 }
 
 void LLAppViewer::removeCacheFiles(const std::string& file_mask)
 {
-	gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), file_mask);
+    gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), file_mask);
 }
 
 void LLAppViewer::writeSystemInfo()
@@ -3578,311 +3578,311 @@ void LLAppViewer::writeSystemInfo()
     //Not ideal but sufficient for good reporting.
     gDebugInfo["SLLog"] = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,"Alchemy.old");  //LLError::logFileName();
 
-	gDebugInfo["ClientInfo"]["Name"] = LLVersionInfo::instance().getChannel();
-	gDebugInfo["ClientInfo"]["MajorVersion"] = LLVersionInfo::instance().getMajor();
-	gDebugInfo["ClientInfo"]["MinorVersion"] = LLVersionInfo::instance().getMinor();
-	gDebugInfo["ClientInfo"]["PatchVersion"] = LLVersionInfo::instance().getPatch();
-	gDebugInfo["ClientInfo"]["BuildVersion"] = std::to_string(LLVersionInfo::instance().getBuild());
-	gDebugInfo["ClientInfo"]["AddressSize"] = LLVersionInfo::instance().getAddressSize();
+    gDebugInfo["ClientInfo"]["Name"] = LLVersionInfo::instance().getChannel();
+    gDebugInfo["ClientInfo"]["MajorVersion"] = LLVersionInfo::instance().getMajor();
+    gDebugInfo["ClientInfo"]["MinorVersion"] = LLVersionInfo::instance().getMinor();
+    gDebugInfo["ClientInfo"]["PatchVersion"] = LLVersionInfo::instance().getPatch();
+    gDebugInfo["ClientInfo"]["BuildVersion"] = std::to_string(LLVersionInfo::instance().getBuild());
+    gDebugInfo["ClientInfo"]["AddressSize"] = LLVersionInfo::instance().getAddressSize();
 
-	gDebugInfo["CAFilename"] = gDirUtilp->getCAFile();
+    gDebugInfo["CAFilename"] = gDirUtilp->getCAFile();
 
-	gDebugInfo["CPUInfo"]["CPUString"] = gSysCPU.getCPUString();
-	gDebugInfo["CPUInfo"]["CPUFamily"] = gSysCPU.getFamily();
-	gDebugInfo["CPUInfo"]["CPUMhz"] = (S32)gSysCPU.getMHz();
-	gDebugInfo["CPUInfo"]["CPUAltivec"] = gSysCPU.hasAltivec();
-	gDebugInfo["CPUInfo"]["CPUSSE"] = gSysCPU.hasSSE();
-	gDebugInfo["CPUInfo"]["CPUSSE2"] = gSysCPU.hasSSE2();
+    gDebugInfo["CPUInfo"]["CPUString"] = gSysCPU.getCPUString();
+    gDebugInfo["CPUInfo"]["CPUFamily"] = gSysCPU.getFamily();
+    gDebugInfo["CPUInfo"]["CPUMhz"] = (S32)gSysCPU.getMHz();
+    gDebugInfo["CPUInfo"]["CPUAltivec"] = gSysCPU.hasAltivec();
+    gDebugInfo["CPUInfo"]["CPUSSE"] = gSysCPU.hasSSE();
+    gDebugInfo["CPUInfo"]["CPUSSE2"] = gSysCPU.hasSSE2();
 
-	gDebugInfo["RAMInfo"]["Physical"] = LLSD::Integer(gSysMemory.getPhysicalMemoryKB().value());
-	gDebugInfo["RAMInfo"]["Allocated"] = LLSD::Integer(gMemoryAllocated.valueInUnits<LLUnits::Kilobytes>());
-	gDebugInfo["OSInfo"] = LLOSInfo::instance().getOSStringSimple();
+    gDebugInfo["RAMInfo"]["Physical"] = LLSD::Integer(gSysMemory.getPhysicalMemoryKB().value());
+    gDebugInfo["RAMInfo"]["Allocated"] = LLSD::Integer(gMemoryAllocated.valueInUnits<LLUnits::Kilobytes>());
+    gDebugInfo["OSInfo"] = LLOSInfo::instance().getOSStringSimple();
 
-	// The user is not logged on yet, but record the current grid choice login url
-	// which may have been the intended grid.
-	gDebugInfo["GridName"] = LLGridManager::getInstance()->getGridId();
+    // The user is not logged on yet, but record the current grid choice login url
+    // which may have been the intended grid.
+    gDebugInfo["GridName"] = LLGridManager::getInstance()->getGridId();
 
-	// *FIX:Mani - move this down in llappviewerwin32
+    // *FIX:Mani - move this down in llappviewerwin32
 #ifdef LL_WINDOWS
-	DWORD thread_id = GetCurrentThreadId();
-	gDebugInfo["MainloopThreadID"] = (S32)thread_id;
+    DWORD thread_id = GetCurrentThreadId();
+    gDebugInfo["MainloopThreadID"] = (S32)thread_id;
 #endif
 
-	// "CrashNotHandled" is obsolete; it used (not very successsfully)
+    // "CrashNotHandled" is obsolete; it used (not very successsfully)
     // to try to distinguish crashes from freezes - the intent here to to avoid calling it a freeze
-	gDebugInfo["CrashNotHandled"] = LLSD::Boolean(false);
-
-	// Insert crash host url (url to post crash log to) if configured. This insures
-	// that the crash report will go to the proper location in the case of a
-	// prior freeze.
-	std::string crashHostUrl = gSavedSettings.get<std::string>("CrashHostUrl");
-	if(crashHostUrl != "")
-	{
-		gDebugInfo["CrashHostUrl"] = crashHostUrl;
-	}
-
-	// Dump some debugging info
-	LL_INFOS("SystemInfo") << "Application: " << LLTrans::getString("APP_NAME") << LL_ENDL;
-	LL_INFOS("SystemInfo") << "Version: " << LLVersionInfo::instance().getChannelAndVersion() << LL_ENDL;
-
-	// Dump the local time and time zone
-	time_t now;
-	time(&now);
-	char tbuffer[256];		/* Flawfinder: ignore */
-	strftime(tbuffer, 256, "%Y-%m-%dT%H:%M:%S %Z", localtime(&now));
-	LL_INFOS("SystemInfo") << "Local time: " << tbuffer << LL_ENDL;
-
-	// query some system information
-	LL_INFOS("SystemInfo") << "CPU info:\n" << gSysCPU << LL_ENDL;
-	LL_INFOS("SystemInfo") << "Memory info:\n" << gSysMemory << LL_ENDL;
-	LL_INFOS("SystemInfo") << "OS: " << LLOSInfo::instance().getOSStringSimple() << LL_ENDL;
-	LL_INFOS("SystemInfo") << "OS info: " << LLOSInfo::instance() << LL_ENDL;
+    gDebugInfo["CrashNotHandled"] = LLSD::Boolean(false);
+
+    // Insert crash host url (url to post crash log to) if configured. This insures
+    // that the crash report will go to the proper location in the case of a
+    // prior freeze.
+    std::string crashHostUrl = gSavedSettings.get<std::string>("CrashHostUrl");
+    if(crashHostUrl != "")
+    {
+        gDebugInfo["CrashHostUrl"] = crashHostUrl;
+    }
+
+    // Dump some debugging info
+    LL_INFOS("SystemInfo") << "Application: " << LLTrans::getString("APP_NAME") << LL_ENDL;
+    LL_INFOS("SystemInfo") << "Version: " << LLVersionInfo::instance().getChannelAndVersion() << LL_ENDL;
+
+    // Dump the local time and time zone
+    time_t now;
+    time(&now);
+    char tbuffer[256];      /* Flawfinder: ignore */
+    strftime(tbuffer, 256, "%Y-%m-%dT%H:%M:%S %Z", localtime(&now));
+    LL_INFOS("SystemInfo") << "Local time: " << tbuffer << LL_ENDL;
+
+    // query some system information
+    LL_INFOS("SystemInfo") << "CPU info:\n" << gSysCPU << LL_ENDL;
+    LL_INFOS("SystemInfo") << "Memory info:\n" << gSysMemory << LL_ENDL;
+    LL_INFOS("SystemInfo") << "OS: " << LLOSInfo::instance().getOSStringSimple() << LL_ENDL;
+    LL_INFOS("SystemInfo") << "OS info: " << LLOSInfo::instance() << LL_ENDL;
 
     gDebugInfo["SettingsFilename"] = gSavedSettings.getString("ClientSettingsFile");
-	gDebugInfo["ViewerExePath"] = gDirUtilp->getExecutablePathAndName();
-	gDebugInfo["CurrentPath"] = gDirUtilp->getCurPath();
-	gDebugInfo["FirstLogin"] = LLSD::Boolean(gAgent.isFirstLogin());
-	gDebugInfo["FirstRunThisInstall"] = gSavedSettings.getBOOL("FirstRunThisInstall");
+    gDebugInfo["ViewerExePath"] = gDirUtilp->getExecutablePathAndName();
+    gDebugInfo["CurrentPath"] = gDirUtilp->getCurPath();
+    gDebugInfo["FirstLogin"] = LLSD::Boolean(gAgent.isFirstLogin());
+    gDebugInfo["FirstRunThisInstall"] = gSavedSettings.getBOOL("FirstRunThisInstall");
     gDebugInfo["StartupState"] = LLStartUp::getStartupStateString();
 
-	std::vector<std::string> resolutions = LLWindow::getDisplaysResolutionList();
-	for (const auto& res_iter : resolutions)
-	{
-		gDebugInfo["DisplayInfo"].append(res_iter);
-	}
+    std::vector<std::string> resolutions = LLWindow::getDisplaysResolutionList();
+    for (const auto& res_iter : resolutions)
+    {
+        gDebugInfo["DisplayInfo"].append(res_iter);
+    }
 
-	writeDebugInfo(); // Save out debug_info.log early, in case of crash.
+    writeDebugInfo(); // Save out debug_info.log early, in case of crash.
 }
 
 // static
 void LLAppViewer::recordMarkerVersion(LLAPRFile& marker_file)
 {
-	std::string marker_version(LLVersionInfo::instance().getChannelAndVersion());
-	if ( marker_version.length() > MAX_MARKER_LENGTH )
-	{
-		LL_WARNS_ONCE("MarkerFile") << "Version length ("<< marker_version.length()<< ")"
-									<< " greater than maximum (" << MAX_MARKER_LENGTH << ")"
-									<< ": marker matching may be incorrect"
-									<< LL_ENDL;
-	}
-
-	// record the viewer version in the marker file
-	marker_file.write(marker_version.data(), marker_version.length());
+    std::string marker_version(LLVersionInfo::instance().getChannelAndVersion());
+    if ( marker_version.length() > MAX_MARKER_LENGTH )
+    {
+        LL_WARNS_ONCE("MarkerFile") << "Version length ("<< marker_version.length()<< ")"
+                                    << " greater than maximum (" << MAX_MARKER_LENGTH << ")"
+                                    << ": marker matching may be incorrect"
+                                    << LL_ENDL;
+    }
+
+    // record the viewer version in the marker file
+    marker_file.write(marker_version.data(), marker_version.length());
 }
 
 bool LLAppViewer::markerIsSameVersion(const std::string& marker_name) const
 {
-	bool sameVersion = false;
-
-	std::string my_version(LLVersionInfo::instance().getChannelAndVersion());
-	char marker_version[MAX_MARKER_LENGTH];
-	S32  marker_version_length;
-
-	LLAPRFile marker_file;
-	marker_file.open(marker_name, LL_APR_RB);
-	if (marker_file.getFileHandle())
-	{
-		marker_version_length = marker_file.read(marker_version, sizeof(marker_version));
-		std::string marker_string(marker_version, marker_version_length);
-		if ( 0 == my_version.compare( 0, my_version.length(), marker_version, 0, marker_version_length ) )
-		{
-			sameVersion = true;
-		}
-		LL_DEBUGS("MarkerFile") << "Compare markers for '" << marker_name << "': "
-								<< "\n   mine '" << my_version    << "'"
-								<< "\n marker '" << marker_string << "'"
-								<< "\n " << ( sameVersion ? "same" : "different" ) << " version"
-								<< LL_ENDL;
-		marker_file.close();
-	}
-	return sameVersion;
+    bool sameVersion = false;
+
+    std::string my_version(LLVersionInfo::instance().getChannelAndVersion());
+    char marker_version[MAX_MARKER_LENGTH];
+    S32  marker_version_length;
+
+    LLAPRFile marker_file;
+    marker_file.open(marker_name, LL_APR_RB);
+    if (marker_file.getFileHandle())
+    {
+        marker_version_length = marker_file.read(marker_version, sizeof(marker_version));
+        std::string marker_string(marker_version, marker_version_length);
+        if ( 0 == my_version.compare( 0, my_version.length(), marker_version, 0, marker_version_length ) )
+        {
+            sameVersion = true;
+        }
+        LL_DEBUGS("MarkerFile") << "Compare markers for '" << marker_name << "': "
+                                << "\n   mine '" << my_version    << "'"
+                                << "\n marker '" << marker_string << "'"
+                                << "\n " << ( sameVersion ? "same" : "different" ) << " version"
+                                << LL_ENDL;
+        marker_file.close();
+    }
+    return sameVersion;
 }
 
 void LLAppViewer::processMarkerFiles()
 {
-	//We've got 4 things to test for here
-	// - Other Process Running (SecondLife.exec_marker present, locked)
-	// - Freeze (SecondLife.exec_marker present, not locked)
-	// - LLError Crash (SecondLife.llerror_marker present)
-	// - Other Crash (SecondLife.error_marker present)
-	// These checks should also remove these files for the last 2 cases if they currently exist
-
-	std::ostringstream marker_log_stream;
-	bool marker_is_same_version = true;
-	// first, look for the marker created at startup and deleted on a clean exit
-	mMarkerFileName = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,MARKER_FILE_NAME);
-	if (LLAPRFile::isExist(mMarkerFileName, NULL, LL_APR_RB))
-	{
-		// File exists...
-		// first, read it to see if it was created by the same version (we need this later)
-		marker_is_same_version = markerIsSameVersion(mMarkerFileName);
-
-		// now test to see if this file is locked by a running process (try to open for write)
-		marker_log_stream << "Checking exec marker file for lock...";
-		mMarkerFile.open(mMarkerFileName, LL_APR_WB);
-		apr_file_t* fMarker = mMarkerFile.getFileHandle() ;
-		if (!fMarker)
-		{
-			marker_log_stream << "Exec marker file open failed - assume it is locked.";
-			mSecondInstance = true; // lock means that instance is running.
-		}
-		else
-		{
-			// We were able to open it, now try to lock it ourselves...
-			if (apr_file_lock(fMarker, APR_FLOCK_NONBLOCK | APR_FLOCK_EXCLUSIVE) != APR_SUCCESS)
-			{
-				marker_log_stream << "Locking exec marker failed.";
-				mSecondInstance = true; // lost a race? be conservative
-			}
-			else
-			{
-				// No other instances; we've locked this file now, so record our version; delete on quit.
-				recordMarkerVersion(mMarkerFile);
-				marker_log_stream << "Exec marker file existed but was not locked; rewritten.";
-			}
-		}
-		initLoggingAndGetLastDuration();
-
-		std::string marker_log_msg(marker_log_stream.str());
-		LL_INFOS("MarkerFile") << marker_log_msg << LL_ENDL;
-
-		if (mSecondInstance)
-		{
-			LL_INFOS("MarkerFile") << "Exec marker '"<< mMarkerFileName << "' owned by another instance" << LL_ENDL;
-		}
-		else if (marker_is_same_version)
-		{
-			// the file existed, is ours, and matched our version, so we can report on what it says
-			LL_INFOS("MarkerFile") << "Exec marker '"<< mMarkerFileName << "' found; last exec crashed" << LL_ENDL;
-			gLastExecEvent = LAST_EXEC_OTHER_CRASH;
-		}
-		else
-		{
-			LL_INFOS("MarkerFile") << "Exec marker '"<< mMarkerFileName << "' found, but versions did not match" << LL_ENDL;
-		}
-	}
-	else // marker did not exist... last exec (if any) did not freeze
-	{
-		initLoggingAndGetLastDuration();
-		// Create the marker file for this execution & lock it; it will be deleted on a clean exit
-		apr_status_t s;
-		s = mMarkerFile.open(mMarkerFileName, LL_APR_WB, TRUE);
-
-		if (s == APR_SUCCESS && mMarkerFile.getFileHandle())
-		{
-			LL_DEBUGS("MarkerFile") << "Exec marker file '"<< mMarkerFileName << "' created." << LL_ENDL;
-			if (APR_SUCCESS == apr_file_lock(mMarkerFile.getFileHandle(), APR_FLOCK_NONBLOCK | APR_FLOCK_EXCLUSIVE))
-			{
-				recordMarkerVersion(mMarkerFile);
-				LL_DEBUGS("MarkerFile") << "Exec marker file locked." << LL_ENDL;
-			}
-			else
-			{
-				LL_WARNS("MarkerFile") << "Exec marker file cannot be locked." << LL_ENDL;
-			}
-		}
-		else
-		{
-			LL_WARNS("MarkerFile") << "Failed to create exec marker file '"<< mMarkerFileName << "'." << LL_ENDL;
-		}
-	}
-
-	// now check for cases in which the exec marker may have been cleaned up by crash handlers
-
-	// check for any last exec event report based on whether or not it happened during logout
-	// (the logout marker is created when logout begins)
-	std::string logout_marker_file =  gDirUtilp->getExpandedFilename(LL_PATH_LOGS, LOGOUT_MARKER_FILE_NAME);
-	if(LLAPRFile::isExist(logout_marker_file, NULL, LL_APR_RB))
-	{
-		if (markerIsSameVersion(logout_marker_file))
-		{
-			gLastExecEvent = LAST_EXEC_LOGOUT_FROZE;
-			LL_INFOS("MarkerFile") << "Logout crash marker '"<< logout_marker_file << "', changing LastExecEvent to LOGOUT_FROZE" << LL_ENDL;
-		}
-		else
-		{
-			LL_INFOS("MarkerFile") << "Logout crash marker '"<< logout_marker_file << "' found, but versions did not match" << LL_ENDL;
-		}
-		LLAPRFile::remove(logout_marker_file);
-	}
-	// further refine based on whether or not a marker created during an llerr crash is found
-	std::string llerror_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, LLERROR_MARKER_FILE_NAME);
-	if(LLAPRFile::isExist(llerror_marker_file, NULL, LL_APR_RB))
-	{
-		if (markerIsSameVersion(llerror_marker_file))
-		{
-			if ( gLastExecEvent == LAST_EXEC_LOGOUT_FROZE )
-			{
-				gLastExecEvent = LAST_EXEC_LOGOUT_CRASH;
-				LL_INFOS("MarkerFile") << "LLError marker '"<< llerror_marker_file << "' crashed, setting LastExecEvent to LOGOUT_CRASH" << LL_ENDL;
-			}
-			else
-			{
-				gLastExecEvent = LAST_EXEC_LLERROR_CRASH;
-				LL_INFOS("MarkerFile") << "LLError marker '"<< llerror_marker_file << "' crashed, setting LastExecEvent to LLERROR_CRASH" << LL_ENDL;
-			}
-		}
-		else
-		{
-			LL_INFOS("MarkerFile") << "LLError marker '"<< llerror_marker_file << "' found, but versions did not match" << LL_ENDL;
-		}
-		LLAPRFile::remove(llerror_marker_file);
-	}
-	// and last refine based on whether or not a marker created during a non-llerr crash is found
-	std::string error_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, ERROR_MARKER_FILE_NAME);
-	if(LLAPRFile::isExist(error_marker_file, NULL, LL_APR_RB))
-	{
-		if (markerIsSameVersion(error_marker_file))
-		{
-			if (gLastExecEvent == LAST_EXEC_LOGOUT_FROZE)
-			{
-				gLastExecEvent = LAST_EXEC_LOGOUT_CRASH;
-				LL_INFOS("MarkerFile") << "Error marker '"<< error_marker_file << "' crashed, setting LastExecEvent to LOGOUT_CRASH" << LL_ENDL;
-			}
-			else
-			{
-				gLastExecEvent = LAST_EXEC_OTHER_CRASH;
-				LL_INFOS("MarkerFile") << "Error marker '"<< error_marker_file << "' crashed, setting LastExecEvent to " << gLastExecEvent << LL_ENDL;
-			}
-		}
-		else
-		{
-			LL_INFOS("MarkerFile") << "Error marker '"<< error_marker_file << "' marker found, but versions did not match" << LL_ENDL;
-		}
-		LLAPRFile::remove(error_marker_file);
-	}
+    //We've got 4 things to test for here
+    // - Other Process Running (SecondLife.exec_marker present, locked)
+    // - Freeze (SecondLife.exec_marker present, not locked)
+    // - LLError Crash (SecondLife.llerror_marker present)
+    // - Other Crash (SecondLife.error_marker present)
+    // These checks should also remove these files for the last 2 cases if they currently exist
+
+    std::ostringstream marker_log_stream;
+    bool marker_is_same_version = true;
+    // first, look for the marker created at startup and deleted on a clean exit
+    mMarkerFileName = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,MARKER_FILE_NAME);
+    if (LLAPRFile::isExist(mMarkerFileName, NULL, LL_APR_RB))
+    {
+        // File exists...
+        // first, read it to see if it was created by the same version (we need this later)
+        marker_is_same_version = markerIsSameVersion(mMarkerFileName);
+
+        // now test to see if this file is locked by a running process (try to open for write)
+        marker_log_stream << "Checking exec marker file for lock...";
+        mMarkerFile.open(mMarkerFileName, LL_APR_WB);
+        apr_file_t* fMarker = mMarkerFile.getFileHandle() ;
+        if (!fMarker)
+        {
+            marker_log_stream << "Exec marker file open failed - assume it is locked.";
+            mSecondInstance = true; // lock means that instance is running.
+        }
+        else
+        {
+            // We were able to open it, now try to lock it ourselves...
+            if (apr_file_lock(fMarker, APR_FLOCK_NONBLOCK | APR_FLOCK_EXCLUSIVE) != APR_SUCCESS)
+            {
+                marker_log_stream << "Locking exec marker failed.";
+                mSecondInstance = true; // lost a race? be conservative
+            }
+            else
+            {
+                // No other instances; we've locked this file now, so record our version; delete on quit.
+                recordMarkerVersion(mMarkerFile);
+                marker_log_stream << "Exec marker file existed but was not locked; rewritten.";
+            }
+        }
+        initLoggingAndGetLastDuration();
+
+        std::string marker_log_msg(marker_log_stream.str());
+        LL_INFOS("MarkerFile") << marker_log_msg << LL_ENDL;
+
+        if (mSecondInstance)
+        {
+            LL_INFOS("MarkerFile") << "Exec marker '"<< mMarkerFileName << "' owned by another instance" << LL_ENDL;
+        }
+        else if (marker_is_same_version)
+        {
+            // the file existed, is ours, and matched our version, so we can report on what it says
+            LL_INFOS("MarkerFile") << "Exec marker '"<< mMarkerFileName << "' found; last exec crashed" << LL_ENDL;
+            gLastExecEvent = LAST_EXEC_OTHER_CRASH;
+        }
+        else
+        {
+            LL_INFOS("MarkerFile") << "Exec marker '"<< mMarkerFileName << "' found, but versions did not match" << LL_ENDL;
+        }
+    }
+    else // marker did not exist... last exec (if any) did not freeze
+    {
+        initLoggingAndGetLastDuration();
+        // Create the marker file for this execution & lock it; it will be deleted on a clean exit
+        apr_status_t s;
+        s = mMarkerFile.open(mMarkerFileName, LL_APR_WB, TRUE);
+
+        if (s == APR_SUCCESS && mMarkerFile.getFileHandle())
+        {
+            LL_DEBUGS("MarkerFile") << "Exec marker file '"<< mMarkerFileName << "' created." << LL_ENDL;
+            if (APR_SUCCESS == apr_file_lock(mMarkerFile.getFileHandle(), APR_FLOCK_NONBLOCK | APR_FLOCK_EXCLUSIVE))
+            {
+                recordMarkerVersion(mMarkerFile);
+                LL_DEBUGS("MarkerFile") << "Exec marker file locked." << LL_ENDL;
+            }
+            else
+            {
+                LL_WARNS("MarkerFile") << "Exec marker file cannot be locked." << LL_ENDL;
+            }
+        }
+        else
+        {
+            LL_WARNS("MarkerFile") << "Failed to create exec marker file '"<< mMarkerFileName << "'." << LL_ENDL;
+        }
+    }
+
+    // now check for cases in which the exec marker may have been cleaned up by crash handlers
+
+    // check for any last exec event report based on whether or not it happened during logout
+    // (the logout marker is created when logout begins)
+    std::string logout_marker_file =  gDirUtilp->getExpandedFilename(LL_PATH_LOGS, LOGOUT_MARKER_FILE_NAME);
+    if(LLAPRFile::isExist(logout_marker_file, NULL, LL_APR_RB))
+    {
+        if (markerIsSameVersion(logout_marker_file))
+        {
+            gLastExecEvent = LAST_EXEC_LOGOUT_FROZE;
+            LL_INFOS("MarkerFile") << "Logout crash marker '"<< logout_marker_file << "', changing LastExecEvent to LOGOUT_FROZE" << LL_ENDL;
+        }
+        else
+        {
+            LL_INFOS("MarkerFile") << "Logout crash marker '"<< logout_marker_file << "' found, but versions did not match" << LL_ENDL;
+        }
+        LLAPRFile::remove(logout_marker_file);
+    }
+    // further refine based on whether or not a marker created during an llerr crash is found
+    std::string llerror_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, LLERROR_MARKER_FILE_NAME);
+    if(LLAPRFile::isExist(llerror_marker_file, NULL, LL_APR_RB))
+    {
+        if (markerIsSameVersion(llerror_marker_file))
+        {
+            if ( gLastExecEvent == LAST_EXEC_LOGOUT_FROZE )
+            {
+                gLastExecEvent = LAST_EXEC_LOGOUT_CRASH;
+                LL_INFOS("MarkerFile") << "LLError marker '"<< llerror_marker_file << "' crashed, setting LastExecEvent to LOGOUT_CRASH" << LL_ENDL;
+            }
+            else
+            {
+                gLastExecEvent = LAST_EXEC_LLERROR_CRASH;
+                LL_INFOS("MarkerFile") << "LLError marker '"<< llerror_marker_file << "' crashed, setting LastExecEvent to LLERROR_CRASH" << LL_ENDL;
+            }
+        }
+        else
+        {
+            LL_INFOS("MarkerFile") << "LLError marker '"<< llerror_marker_file << "' found, but versions did not match" << LL_ENDL;
+        }
+        LLAPRFile::remove(llerror_marker_file);
+    }
+    // and last refine based on whether or not a marker created during a non-llerr crash is found
+    std::string error_marker_file = gDirUtilp->getExpandedFilename(LL_PATH_LOGS, ERROR_MARKER_FILE_NAME);
+    if(LLAPRFile::isExist(error_marker_file, NULL, LL_APR_RB))
+    {
+        if (markerIsSameVersion(error_marker_file))
+        {
+            if (gLastExecEvent == LAST_EXEC_LOGOUT_FROZE)
+            {
+                gLastExecEvent = LAST_EXEC_LOGOUT_CRASH;
+                LL_INFOS("MarkerFile") << "Error marker '"<< error_marker_file << "' crashed, setting LastExecEvent to LOGOUT_CRASH" << LL_ENDL;
+            }
+            else
+            {
+                gLastExecEvent = LAST_EXEC_OTHER_CRASH;
+                LL_INFOS("MarkerFile") << "Error marker '"<< error_marker_file << "' crashed, setting LastExecEvent to " << gLastExecEvent << LL_ENDL;
+            }
+        }
+        else
+        {
+            LL_INFOS("MarkerFile") << "Error marker '"<< error_marker_file << "' marker found, but versions did not match" << LL_ENDL;
+        }
+        LLAPRFile::remove(error_marker_file);
+    }
 }
 
 void LLAppViewer::removeMarkerFiles()
 {
-	if (!mSecondInstance)
-	{
-		if (mMarkerFile.getFileHandle())
-		{
-			mMarkerFile.close() ;
-			LLAPRFile::remove( mMarkerFileName );
-			LL_DEBUGS("MarkerFile") << "removed exec marker '"<<mMarkerFileName<<"'"<< LL_ENDL;
-		}
-		else
-		{
-			LL_WARNS("MarkerFile") << "marker '"<<mMarkerFileName<<"' not open"<< LL_ENDL;
- 		}
-
-		if (mLogoutMarkerFile.getFileHandle())
-		{
-			mLogoutMarkerFile.close();
-			LLAPRFile::remove( mLogoutMarkerFileName );
-			LL_DEBUGS("MarkerFile") << "removed logout marker '"<<mLogoutMarkerFileName<<"'"<< LL_ENDL;
-		}
-		else
-		{
-			LL_WARNS("MarkerFile") << "logout marker '"<<mLogoutMarkerFileName<<"' not open"<< LL_ENDL;
-		}
-	}
-	else
-	{
-		LL_WARNS("MarkerFile") << "leaving markers because this is a second instance" << LL_ENDL;
-	}
+    if (!mSecondInstance)
+    {
+        if (mMarkerFile.getFileHandle())
+        {
+            mMarkerFile.close() ;
+            LLAPRFile::remove( mMarkerFileName );
+            LL_DEBUGS("MarkerFile") << "removed exec marker '"<<mMarkerFileName<<"'"<< LL_ENDL;
+        }
+        else
+        {
+            LL_WARNS("MarkerFile") << "marker '"<<mMarkerFileName<<"' not open"<< LL_ENDL;
+        }
+
+        if (mLogoutMarkerFile.getFileHandle())
+        {
+            mLogoutMarkerFile.close();
+            LLAPRFile::remove( mLogoutMarkerFileName );
+            LL_DEBUGS("MarkerFile") << "removed logout marker '"<<mLogoutMarkerFileName<<"'"<< LL_ENDL;
+        }
+        else
+        {
+            LL_WARNS("MarkerFile") << "logout marker '"<<mLogoutMarkerFileName<<"' not open"<< LL_ENDL;
+        }
+    }
+    else
+    {
+        LL_WARNS("MarkerFile") << "leaving markers because this is a second instance" << LL_ENDL;
+    }
 }
 
 void LLAppViewer::removeDumpDir()
@@ -3905,145 +3905,145 @@ void LLAppViewer::removeDumpDir()
 
 void LLAppViewer::forceQuit()
 {
-	LLApp::setQuitting();
+    LLApp::setQuitting();
 }
 
 //TODO: remove
 void LLAppViewer::fastQuit(S32 error_code)
 {
-	// finish pending transfers
-	flushLFSIO();
-	// let sim know we're logging out
-	sendLogoutRequest();
-	// flush network buffers by shutting down messaging system
-	end_messaging_system();
-	// figure out the error code
-	S32 final_error_code = error_code ? error_code : (S32)isError();
-	// this isn't a crash
-	removeMarkerFiles();
-	// get outta here
-	_exit(final_error_code);
+    // finish pending transfers
+    flushLFSIO();
+    // let sim know we're logging out
+    sendLogoutRequest();
+    // flush network buffers by shutting down messaging system
+    end_messaging_system();
+    // figure out the error code
+    S32 final_error_code = error_code ? error_code : (S32)isError();
+    // this isn't a crash
+    removeMarkerFiles();
+    // get outta here
+    _exit(final_error_code);
 }
 
 void LLAppViewer::requestQuit()
 {
-	LL_INFOS() << "requestQuit" << LL_ENDL;
-
-	LLViewerRegion* region = gAgent.getRegion();
-
-	if( (LLStartUp::getStartupState() < STATE_STARTED) || !region )
-	{
-		// If we have a region, make some attempt to send a logout request first.
-		// This prevents the halfway-logged-in avatar from hanging around inworld for a couple minutes.
-		if(region)
-		{
-			sendLogoutRequest();
-		}
-
-		// Quit immediately
-		forceQuit();
-		return;
-	}
-
-	// Try to send metrics back to the grid
-	metricsSend(!gDisconnected);
-
-	// Try to send last batch of avatar rez metrics.
-	if (!gDisconnected && isAgentAvatarValid())
-	{
-		gAgentAvatarp->updateAvatarRezMetrics(true); // force a last packet to be sent.
-	}
-
-	if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral"))
-	{
-		LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
-		effectp->setPositionGlobal(gAgent.getPositionGlobal());
-		effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-		LLHUDManager::getInstance()->sendEffects();
-		effectp->markDead();//remove it.
-	}
-
-	// Attempt to close all floaters that might be
-	// editing things.
-	if (gFloaterView)
-	{
-		// application is quitting
-		gFloaterView->closeAllChildren(true);
-	}
-
-	// Send preferences once, when exiting
-	bool include_preferences = true;
-	send_viewer_stats(include_preferences);
-
-	gLogoutTimer.reset();
-	mQuitRequested = true;
+    LL_INFOS() << "requestQuit" << LL_ENDL;
+
+    LLViewerRegion* region = gAgent.getRegion();
+
+    if( (LLStartUp::getStartupState() < STATE_STARTED) || !region )
+    {
+        // If we have a region, make some attempt to send a logout request first.
+        // This prevents the halfway-logged-in avatar from hanging around inworld for a couple minutes.
+        if(region)
+        {
+            sendLogoutRequest();
+        }
+
+        // Quit immediately
+        forceQuit();
+        return;
+    }
+
+    // Try to send metrics back to the grid
+    metricsSend(!gDisconnected);
+
+    // Try to send last batch of avatar rez metrics.
+    if (!gDisconnected && isAgentAvatarValid())
+    {
+        gAgentAvatarp->updateAvatarRezMetrics(true); // force a last packet to be sent.
+    }
+
+    if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral"))
+    {
+        LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
+        effectp->setPositionGlobal(gAgent.getPositionGlobal());
+        effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+        LLHUDManager::getInstance()->sendEffects();
+        effectp->markDead();//remove it.
+    }
+
+    // Attempt to close all floaters that might be
+    // editing things.
+    if (gFloaterView)
+    {
+        // application is quitting
+        gFloaterView->closeAllChildren(true);
+    }
+
+    // Send preferences once, when exiting
+    bool include_preferences = true;
+    send_viewer_stats(include_preferences);
+
+    gLogoutTimer.reset();
+    mQuitRequested = true;
 }
 
 static bool finish_quit(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 
-	if (option == 0)
-	{
-		LLAppViewer::instance()->requestQuit();
-	}
-	return false;
+    if (option == 0)
+    {
+        LLAppViewer::instance()->requestQuit();
+    }
+    return false;
 }
 static LLNotificationFunctorRegistration finish_quit_reg("ConfirmQuit", finish_quit);
 
 void LLAppViewer::userQuit()
 {
-	LL_INFOS() << "User requested quit" << LL_ENDL;
-	if (gDisconnected
-		|| !gViewerWindow
-		|| !gViewerWindow->getProgressView()
-		|| gViewerWindow->getProgressView()->getVisible())
-	{
-		requestQuit();
-	}
-	else
-	{
-		LLNotificationsUtil::add("ConfirmQuit");
-	}
-}
-
-static bool finish_early_exit(const LLSD& notification, const LLSD& response)
+    LL_INFOS() << "User requested quit" << LL_ENDL;
+    if (gDisconnected
+        || !gViewerWindow
+        || !gViewerWindow->getProgressView()
+        || gViewerWindow->getProgressView()->getVisible())
+    {
+        requestQuit();
+    }
+    else
+    {
+        LLNotificationsUtil::add("ConfirmQuit");
+    }
+}
+
+static bool finish_early_exit(const LLSD& notification, const LLSD& response)
 {
-	LLAppViewer::instance()->forceQuit();
-	return false;
+    LLAppViewer::instance()->forceQuit();
+    return false;
 }
 
 void LLAppViewer::earlyExit(const std::string& name, const LLSD& substitutions)
 {
-   	LL_WARNS() << "app_early_exit: " << name << LL_ENDL;
-	gDoDisconnect = TRUE;
-	LLNotificationsUtil::add(name, substitutions, LLSD(), finish_early_exit);
+    LL_WARNS() << "app_early_exit: " << name << LL_ENDL;
+    gDoDisconnect = TRUE;
+    LLNotificationsUtil::add(name, substitutions, LLSD(), finish_early_exit);
 }
 
 // case where we need the viewer to exit without any need for notifications
 void LLAppViewer::earlyExitNoNotify()
 {
-   	LL_WARNS() << "app_early_exit with no notification: " << LL_ENDL;
-	gDoDisconnect = TRUE;
-	finish_early_exit( LLSD(), LLSD() );
+    LL_WARNS() << "app_early_exit with no notification: " << LL_ENDL;
+    gDoDisconnect = TRUE;
+    finish_early_exit( LLSD(), LLSD() );
 }
 
 void LLAppViewer::abortQuit()
 {
     LL_INFOS() << "abortQuit()" << LL_ENDL;
-	mQuitRequested = false;
+    mQuitRequested = false;
 }
 
 //static
 U32 LLAppViewer::getTextureCacheVersion()
 {
-	// Viewer texture cache version, change if the texture cache format changes.
-	// 2021-03-10 Bumping up by one to help obviate texture cache issues with
-	//            Simple Cache Viewer - see SL-14985 for more information
-	//const U32 TEXTURE_CACHE_VERSION = 8;
-	const U32 TEXTURE_CACHE_VERSION = 12;
+    // Viewer texture cache version, change if the texture cache format changes.
+    // 2021-03-10 Bumping up by one to help obviate texture cache issues with
+    //            Simple Cache Viewer - see SL-14985 for more information
+    //const U32 TEXTURE_CACHE_VERSION = 8;
+    const U32 TEXTURE_CACHE_VERSION = 12;
 
-	return TEXTURE_CACHE_VERSION ;
+    return TEXTURE_CACHE_VERSION ;
 }
 
 //static
@@ -4058,129 +4058,129 @@ U32 LLAppViewer::getDiskCacheVersion()
 //static
 U32 LLAppViewer::getObjectCacheVersion()
 {
-	// Viewer object cache version, change if object update
-	// format changes. JC
-	const U32 INDRA_OBJECT_CACHE_VERSION = 17;
+    // Viewer object cache version, change if object update
+    // format changes. JC
+    const U32 INDRA_OBJECT_CACHE_VERSION = 17;
 
-	return INDRA_OBJECT_CACHE_VERSION;
+    return INDRA_OBJECT_CACHE_VERSION;
 }
 
 bool LLAppViewer::initCache()
 {
-	mPurgeCache = false;
-	BOOL read_only = mSecondInstance ? TRUE : FALSE;
-	LLAppViewer::getTextureCache()->setReadOnly(read_only) ;
-	LLVOCache::initParamSingleton(read_only);
-
-	// Create disk cache singleton
-	LLDiskCache::createInstance();
-	LLDiskCache::getInstance()->setReadonly(read_only);
-
-	bool texture_cache_mismatch = false;
-	if (gSavedSettings.getS32("LocalCacheVersion") != LLAppViewer::getTextureCacheVersion())
-	{
-		texture_cache_mismatch = true;
-		if(!read_only)
-		{
-			gSavedSettings.setS32("LocalCacheVersion", LLAppViewer::getTextureCacheVersion());
-		}
-	}
-
-	bool disk_cache_mismatch = false;
-	if (gSavedSettings.getS32("DiskCacheVersion") != LLAppViewer::getDiskCacheVersion())
-	{
-		disk_cache_mismatch = true;
-		if (!read_only)
-		{
-			gSavedSettings.setS32("DiskCacheVersion", LLAppViewer::getDiskCacheVersion());
-		}
-	}
-
-	if(!read_only)
-	{
-		// Purge cache if user requested it
-		if (gSavedSettings.getBOOL("PurgeCacheOnStartup") ||
-			gSavedSettings.getBOOL("PurgeCacheOnNextStartup"))
-		{
-			LL_INFOS("AppCache") << "Startup cache purge requested: " << (gSavedSettings.getBOOL("PurgeCacheOnStartup") ? "ALWAYS" : "ONCE") << LL_ENDL;
-			gSavedSettings.setBOOL("PurgeCacheOnNextStartup", FALSE);
-			mPurgeCache = true;
-			// STORM-1141 force purgeAllTextures to get called to prevent a crash here. -brad
-			texture_cache_mismatch = true;
-		}
-
-		// Setup and verify the cache location
-		std::string cache_location = gSavedSettings.getString("CacheLocation");
-		std::string new_cache_location = gSavedSettings.getString("NewCacheLocation");
-		if (new_cache_location != cache_location)
-		{
-			LLSplashScreen::update(LLTrans::getString("StartupChangingCacheLocation"));
-			LL_INFOS("AppCache") << "Cache location changed, cache needs purging" << LL_ENDL;
-			gDirUtilp->setCacheDir(gSavedSettings.getString("CacheLocation"));
-			purgeCache(); // purge old cache
-			gSavedSettings.setString("CacheLocation", new_cache_location);
-			gSavedSettings.setString("CacheLocationTopFolder", gDirUtilp->getBaseFileName(new_cache_location));
-		}
-	}
-
-	if (!gDirUtilp->setCacheDir(gSavedSettings.getString("CacheLocation")))
-	{
-		LL_WARNS("AppCache") << "Unable to set cache location" << LL_ENDL;
-		gSavedSettings.setString("CacheLocation", "");
-		gSavedSettings.setString("CacheLocationTopFolder", "");
-	}
-
-	if (!read_only)
-	{
+    mPurgeCache = false;
+    BOOL read_only = mSecondInstance ? TRUE : FALSE;
+    LLAppViewer::getTextureCache()->setReadOnly(read_only) ;
+    LLVOCache::initParamSingleton(read_only);
+
+    // Create disk cache singleton
+    LLDiskCache::createInstance();
+    LLDiskCache::getInstance()->setReadonly(read_only);
+
+    bool texture_cache_mismatch = false;
+    if (gSavedSettings.getS32("LocalCacheVersion") != LLAppViewer::getTextureCacheVersion())
+    {
+        texture_cache_mismatch = true;
+        if(!read_only)
+        {
+            gSavedSettings.setS32("LocalCacheVersion", LLAppViewer::getTextureCacheVersion());
+        }
+    }
+
+    bool disk_cache_mismatch = false;
+    if (gSavedSettings.getS32("DiskCacheVersion") != LLAppViewer::getDiskCacheVersion())
+    {
+        disk_cache_mismatch = true;
+        if (!read_only)
+        {
+            gSavedSettings.setS32("DiskCacheVersion", LLAppViewer::getDiskCacheVersion());
+        }
+    }
+
+    if(!read_only)
+    {
+        // Purge cache if user requested it
+        if (gSavedSettings.getBOOL("PurgeCacheOnStartup") ||
+            gSavedSettings.getBOOL("PurgeCacheOnNextStartup"))
+        {
+            LL_INFOS("AppCache") << "Startup cache purge requested: " << (gSavedSettings.getBOOL("PurgeCacheOnStartup") ? "ALWAYS" : "ONCE") << LL_ENDL;
+            gSavedSettings.setBOOL("PurgeCacheOnNextStartup", FALSE);
+            mPurgeCache = true;
+            // STORM-1141 force purgeAllTextures to get called to prevent a crash here. -brad
+            texture_cache_mismatch = true;
+        }
+
+        // Setup and verify the cache location
+        std::string cache_location = gSavedSettings.getString("CacheLocation");
+        std::string new_cache_location = gSavedSettings.getString("NewCacheLocation");
+        if (new_cache_location != cache_location)
+        {
+            LLSplashScreen::update(LLTrans::getString("StartupChangingCacheLocation"));
+            LL_INFOS("AppCache") << "Cache location changed, cache needs purging" << LL_ENDL;
+            gDirUtilp->setCacheDir(gSavedSettings.getString("CacheLocation"));
+            purgeCache(); // purge old cache
+            gSavedSettings.setString("CacheLocation", new_cache_location);
+            gSavedSettings.setString("CacheLocationTopFolder", gDirUtilp->getBaseFileName(new_cache_location));
+        }
+    }
+
+    if (!gDirUtilp->setCacheDir(gSavedSettings.getString("CacheLocation")))
+    {
+        LL_WARNS("AppCache") << "Unable to set cache location" << LL_ENDL;
+        gSavedSettings.setString("CacheLocation", "");
+        gSavedSettings.setString("CacheLocationTopFolder", "");
+    }
+
+    if (!read_only)
+    {
         if (mPurgeCache)
-		{
-			LLSplashScreen::update(LLTrans::getString("StartupClearingCache"));
-			purgeCache();
-		}
-
-		if (gSavedSettings.getBool("PurgeCacheSelective"))
-		{
-			purgeCacheSelective(gSavedSettings.getLLSD("PurgeCacheSelectiveData"));
-			gSavedSettings.setLLSD("PurgeCacheSelectiveData", LLSD());
-			gSavedSettings.setBOOL("PurgeCacheSelective", false);
-		}
-	}
-
-	// Init the asset cache
-	{
-		LLSplashScreen::update(LLTrans::getString("StartupInitializingDiskCache"));
-		const uintmax_t disk_cache_mb = (uintmax_t)gSavedSettings.getU32("DiskCacheSize");
-		const uintmax_t disk_cache_bytes = disk_cache_mb * 1024ull * 1024ull;
-
-		const bool enable_cache_debug_info = gSavedSettings.getBOOL("EnableDiskCacheDebugInfo");
-		LLDiskCache::getInstance()->init(LL_PATH_CACHE, disk_cache_bytes, enable_cache_debug_info, disk_cache_mismatch);
-
-		if (!read_only)
-		{
-			// purge excessive files from the new file system based cache in background thread
-			LLAppViewer::getPurgeDiskCacheThread()->start();
-		}
-	}
-
-	// Init the texture cache
-	{
-		{
-			std::random_device rnddev;
-			std::mt19937 rng(rnddev());
-			std::uniform_int_distribution<> dist(0, 9);
-
-			LLSplashScreen::update(LLTrans::getString(llformat("StartupInitializingTextureCache%d", dist(rng))));
-		}
-
-		const S64 MB = 1024ll * 1024ll;
-		const S64 MIN_CACHE_SIZE = 1024ll * MB;
-		const S64 MAX_CACHE_SIZE = 16384ll * MB;
-
-		S64 texture_cache_size = (S64)(gSavedSettings.getU32("TextureCacheSize")) * MB;
-		texture_cache_size = llclamp(texture_cache_size, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
-
-		LLAppViewer::getTextureCache()->initCache(LL_PATH_CACHE, texture_cache_size, texture_cache_mismatch);
-	}
+        {
+            LLSplashScreen::update(LLTrans::getString("StartupClearingCache"));
+            purgeCache();
+        }
+
+        if (gSavedSettings.getBool("PurgeCacheSelective"))
+        {
+            purgeCacheSelective(gSavedSettings.getLLSD("PurgeCacheSelectiveData"));
+            gSavedSettings.setLLSD("PurgeCacheSelectiveData", LLSD());
+            gSavedSettings.setBOOL("PurgeCacheSelective", false);
+        }
+    }
+
+    // Init the asset cache
+    {
+        LLSplashScreen::update(LLTrans::getString("StartupInitializingDiskCache"));
+        const uintmax_t disk_cache_mb = (uintmax_t)gSavedSettings.getU32("DiskCacheSize");
+        const uintmax_t disk_cache_bytes = disk_cache_mb * 1024ull * 1024ull;
+
+        const bool enable_cache_debug_info = gSavedSettings.getBOOL("EnableDiskCacheDebugInfo");
+        LLDiskCache::getInstance()->init(LL_PATH_CACHE, disk_cache_bytes, enable_cache_debug_info, disk_cache_mismatch);
+
+        if (!read_only)
+        {
+            // purge excessive files from the new file system based cache in background thread
+            LLAppViewer::getPurgeDiskCacheThread()->start();
+        }
+    }
+
+    // Init the texture cache
+    {
+        {
+            std::random_device rnddev;
+            std::mt19937 rng(rnddev());
+            std::uniform_int_distribution<> dist(0, 9);
+
+            LLSplashScreen::update(LLTrans::getString(llformat("StartupInitializingTextureCache%d", dist(rng))));
+        }
+
+        const S64 MB = 1024ll * 1024ll;
+        const S64 MIN_CACHE_SIZE = 1024ll * MB;
+        const S64 MAX_CACHE_SIZE = 16384ll * MB;
+
+        S64 texture_cache_size = (S64)(gSavedSettings.getU32("TextureCacheSize")) * MB;
+        texture_cache_size = llclamp(texture_cache_size, MIN_CACHE_SIZE, MAX_CACHE_SIZE);
+
+        LLAppViewer::getTextureCache()->initCache(LL_PATH_CACHE, texture_cache_size, texture_cache_mismatch);
+    }
 
     const U32 CACHE_NUMBER_OF_REGIONS_FOR_OBJECTS = 128;
     LLVOCache::getInstance()->initCache(LL_PATH_CACHE, CACHE_NUMBER_OF_REGIONS_FOR_OBJECTS, getObjectCacheVersion());
@@ -4190,202 +4190,202 @@ bool LLAppViewer::initCache()
 
 void LLAppViewer::addOnIdleCallback(const boost::function<void()>& cb)
 {
-	gMainloopWork.post(cb);
+    gMainloopWork.post(cb);
 }
 
 void LLAppViewer::loadKeyBindings()
 {
-	std::string key_bindings_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "key_bindings.xml");
-	if (!gDirUtilp->fileExists(key_bindings_file) || !gViewerInput.loadBindingsXML(key_bindings_file))
-	{
-		// Failed to load custom bindings, try default ones
-		key_bindings_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "key_bindings.xml");
-		if (!gViewerInput.loadBindingsXML(key_bindings_file))
-		{
+    std::string key_bindings_file = gDirUtilp->getExpandedFilename(LL_PATH_USER_SETTINGS, "key_bindings.xml");
+    if (!gDirUtilp->fileExists(key_bindings_file) || !gViewerInput.loadBindingsXML(key_bindings_file))
+    {
+        // Failed to load custom bindings, try default ones
+        key_bindings_file = gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "key_bindings.xml");
+        if (!gViewerInput.loadBindingsXML(key_bindings_file))
+        {
             LLError::LLUserWarningMsg::showMissingFiles();
-			LL_ERRS("InitInfo") << "Unable to open default key bindings from " << key_bindings_file << LL_ENDL;
-		}
-	}
+            LL_ERRS("InitInfo") << "Unable to open default key bindings from " << key_bindings_file << LL_ENDL;
+        }
+    }
     LLUrlRegistry::instance().setKeybindingHandler(&gViewerInput);
 }
 
 void LLAppViewer::purgeCache()
 {
-	LL_INFOS("AppCache") << "Purging Cache and Texture Cache..." << LL_ENDL;
-	LLSplashScreen::update(LLTrans::getString("StartupClearingTextureCache"));
-	LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE);
-
-	LLSplashScreen::update(LLTrans::getString("StartupClearingDiskCache"));
-	LLDiskCache::getInstance()->clearCache(LL_PATH_CACHE, false);
-
-	LLSplashScreen::update(LLTrans::getString("StartupClearingObjectCache"));
-	LLVOCache::getInstance()->removeCache(LL_PATH_CACHE);
-
-	LLSplashScreen::update(LLTrans::getString("StartupClearingShaderCache"));
-	LLViewerShaderMgr::instance()->clearShaderCache();
-	purgeWebCache();
-	gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "inv_cache"));
-	gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "lslpreproc"));
-	gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "gridcache"));
-	gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), "*");
+    LL_INFOS("AppCache") << "Purging Cache and Texture Cache..." << LL_ENDL;
+    LLSplashScreen::update(LLTrans::getString("StartupClearingTextureCache"));
+    LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE);
+
+    LLSplashScreen::update(LLTrans::getString("StartupClearingDiskCache"));
+    LLDiskCache::getInstance()->clearCache(LL_PATH_CACHE, false);
+
+    LLSplashScreen::update(LLTrans::getString("StartupClearingObjectCache"));
+    LLVOCache::getInstance()->removeCache(LL_PATH_CACHE);
+
+    LLSplashScreen::update(LLTrans::getString("StartupClearingShaderCache"));
+    LLViewerShaderMgr::instance()->clearShaderCache();
+    purgeWebCache();
+    gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "inv_cache"));
+    gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "lslpreproc"));
+    gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "gridcache"));
+    gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), "*");
 }
 
 void LLAppViewer::purgeCacheSelective(const LLSD& insd)
 {
-	if(insd.has("textures"))
-	{
-		LL_INFOS("AppCache") << "Purging Texture Cache..." << LL_ENDL;
-		LLSplashScreen::update(LLTrans::getString("StartupClearingTextureCache"));
-		LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE);
-	}
-
-	if (insd.has("assets"))
-	{
-		LL_INFOS("AppCache") << "Purging Disk Cache..." << LL_ENDL;
-		LLSplashScreen::update(LLTrans::getString("StartupClearingDiskCache"));
-		LLDiskCache::getInstance()->clearCache(LL_PATH_CACHE, false);
-	}
-
-	if (insd.has("regions"))
-	{
-		LL_INFOS("AppCache") << "Purging Object Cache..." << LL_ENDL;
-		LLSplashScreen::update(LLTrans::getString("StartupClearingObjectCache"));
-		LLVOCache::getInstance()->removeCache(LL_PATH_CACHE);
-	}
-
-	if (insd.has("inventory"))
-	{
-		LL_INFOS("AppCache") << "Purging Inventory Cache..." << LL_ENDL;
-		gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "inv_cache"));
-	}
-
-	if (insd.has("shaders"))
-	{
-		LL_INFOS("AppCache") << "Purging Shader Cache..." << LL_ENDL;
-		LLSplashScreen::update(LLTrans::getString("StartupClearingShaderCache"));
-		LLViewerShaderMgr::instance()->clearShaderCache();
-	}
-
-	if (insd.has("web"))
-	{
-		purgeWebCache();
-	}
-
-	if (insd.has("userdata"))
-	{
-		gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "lslpreproc"));
-		gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), "*.*");
-	}
+    if(insd.has("textures"))
+    {
+        LL_INFOS("AppCache") << "Purging Texture Cache..." << LL_ENDL;
+        LLSplashScreen::update(LLTrans::getString("StartupClearingTextureCache"));
+        LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE);
+    }
+
+    if (insd.has("assets"))
+    {
+        LL_INFOS("AppCache") << "Purging Disk Cache..." << LL_ENDL;
+        LLSplashScreen::update(LLTrans::getString("StartupClearingDiskCache"));
+        LLDiskCache::getInstance()->clearCache(LL_PATH_CACHE, false);
+    }
+
+    if (insd.has("regions"))
+    {
+        LL_INFOS("AppCache") << "Purging Object Cache..." << LL_ENDL;
+        LLSplashScreen::update(LLTrans::getString("StartupClearingObjectCache"));
+        LLVOCache::getInstance()->removeCache(LL_PATH_CACHE);
+    }
+
+    if (insd.has("inventory"))
+    {
+        LL_INFOS("AppCache") << "Purging Inventory Cache..." << LL_ENDL;
+        gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "inv_cache"));
+    }
+
+    if (insd.has("shaders"))
+    {
+        LL_INFOS("AppCache") << "Purging Shader Cache..." << LL_ENDL;
+        LLSplashScreen::update(LLTrans::getString("StartupClearingShaderCache"));
+        LLViewerShaderMgr::instance()->clearShaderCache();
+    }
+
+    if (insd.has("web"))
+    {
+        purgeWebCache();
+    }
+
+    if (insd.has("userdata"))
+    {
+        gDirUtilp->deleteDirAndContents(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "lslpreproc"));
+        gDirUtilp->deleteFilesInDir(gDirUtilp->getExpandedFilename(LL_PATH_CACHE, ""), "*.*");
+    }
 }
 
 void LLAppViewer::purgeWebCache()
 {
-	LL_INFOS("AppCache") << "Purging CEF Cache..." << LL_ENDL;
-	std::string browser_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "cef_cache");
-	if (LLFile::isdir(browser_cache))
-	{
-		// cef does not support clear_cache and clear_cookies, so clear what we can manually.
-		gDirUtilp->deleteDirAndContents(browser_cache);
-	}
-	std::string browser_data = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "cef_data");
-	if (LLFile::isdir(browser_data))
-	{
-		gDirUtilp->deleteDirAndContents(browser_data);
-	}
+    LL_INFOS("AppCache") << "Purging CEF Cache..." << LL_ENDL;
+    std::string browser_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "cef_cache");
+    if (LLFile::isdir(browser_cache))
+    {
+        // cef does not support clear_cache and clear_cookies, so clear what we can manually.
+        gDirUtilp->deleteDirAndContents(browser_cache);
+    }
+    std::string browser_data = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "cef_data");
+    if (LLFile::isdir(browser_data))
+    {
+        gDirUtilp->deleteDirAndContents(browser_data);
+    }
 }
 
 //purge cache immediately, do not wait until the next login.
 void LLAppViewer::purgeCacheImmediate()
 {
-	LL_INFOS("AppCache") << "Purging Object Cache and Texture Cache immediately..." << LL_ENDL;
-	LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE, false);
-	LLVOCache::getInstance()->removeCache(LL_PATH_CACHE, true);
+    LL_INFOS("AppCache") << "Purging Object Cache and Texture Cache immediately..." << LL_ENDL;
+    LLAppViewer::getTextureCache()->purgeCache(LL_PATH_CACHE, false);
+    LLVOCache::getInstance()->removeCache(LL_PATH_CACHE, true);
 }
 
 std::string LLAppViewer::getSecondLifeTitle() const
 {
-	return LLTrans::getString("APP_NAME");
+    return LLTrans::getString("APP_NAME");
 }
 
 std::string LLAppViewer::getWindowTitle() const
 {
-	return gWindowTitle;
+    return gWindowTitle;
 }
 
 // Callback from a dialog indicating user was logged out.
 bool finish_disconnect(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 
-	if (1 == option)
-	{
+    if (1 == option)
+    {
         LLAppViewer::instance()->forceQuit();
-	}
-	return false;
+    }
+    return false;
 }
 
 // Callback from an early disconnect dialog, force an exit
 bool finish_forced_disconnect(const LLSD& notification, const LLSD& response)
 {
-	LLAppViewer::instance()->forceQuit();
-	return false;
+    LLAppViewer::instance()->forceQuit();
+    return false;
 }
 
 
 void LLAppViewer::forceDisconnect(const std::string& mesg)
 {
-	if (gDoDisconnect)
-    {
-		// Already popped up one of these dialogs, don't
-		// do this again.
-		return;
-    }
-
-	// *TODO: Translate the message if possible
-	std::string big_reason = LLAgent::sTeleportErrorMessages[mesg];
-	if ( big_reason.size() == 0 )
-	{
-		big_reason = mesg;
-	}
-
-	LLSD args;
-	gDoDisconnect = TRUE;
-
-	if (LLStartUp::getStartupState() < STATE_STARTED)
-	{
-		// Tell users what happened
-		args["ERROR_MESSAGE"] = big_reason;
-		LLNotificationsUtil::add("ErrorMessage", args, LLSD(), &finish_forced_disconnect);
-	}
-	else
-	{
-		args["MESSAGE"] = big_reason;
-		LLNotificationsUtil::add("YouHaveBeenLoggedOut", args, LLSD(), &finish_disconnect );
-	}
+    if (gDoDisconnect)
+    {
+        // Already popped up one of these dialogs, don't
+        // do this again.
+        return;
+    }
+
+    // *TODO: Translate the message if possible
+    std::string big_reason = LLAgent::sTeleportErrorMessages[mesg];
+    if ( big_reason.size() == 0 )
+    {
+        big_reason = mesg;
+    }
+
+    LLSD args;
+    gDoDisconnect = TRUE;
+
+    if (LLStartUp::getStartupState() < STATE_STARTED)
+    {
+        // Tell users what happened
+        args["ERROR_MESSAGE"] = big_reason;
+        LLNotificationsUtil::add("ErrorMessage", args, LLSD(), &finish_forced_disconnect);
+    }
+    else
+    {
+        args["MESSAGE"] = big_reason;
+        LLNotificationsUtil::add("YouHaveBeenLoggedOut", args, LLSD(), &finish_disconnect );
+    }
 }
 
 void LLAppViewer::badNetworkHandler()
 {
-	// Dump the packet
-	gMessageSystem->dumpPacketToLog();
-
-	// Flush all of our caches on exit in the case of disconnect due to
-	// invalid packets.
-
-	mPurgeCacheOnExit = TRUE;
-
-	std::ostringstream message;
-	message <<
-		"The viewer has detected mangled network data indicative\n"
-		"of a bad upstream network connection or an incomplete\n"
-		"local installation of " << LLAppViewer::instance()->getSecondLifeTitle() << ". \n"
-		" \n"
-		"Try uninstalling and reinstalling to see if this resolves \n"
-		"the issue. \n"
-		" \n"
-		"If the problem continues, see the Tech Support FAQ at: \n"
-		"www.secondlife.com/support";
-	forceDisconnect(message.str());
+    // Dump the packet
+    gMessageSystem->dumpPacketToLog();
+
+    // Flush all of our caches on exit in the case of disconnect due to
+    // invalid packets.
+
+    mPurgeCacheOnExit = TRUE;
+
+    std::ostringstream message;
+    message <<
+        "The viewer has detected mangled network data indicative\n"
+        "of a bad upstream network connection or an incomplete\n"
+        "local installation of " << LLAppViewer::instance()->getSecondLifeTitle() << ". \n"
+        " \n"
+        "Try uninstalling and reinstalling to see if this resolves \n"
+        "the issue. \n"
+        " \n"
+        "If the problem continues, see the Tech Support FAQ at: \n"
+        "www.secondlife.com/support";
+    forceDisconnect(message.str());
 }
 
 // This routine may get called more than once during the shutdown process.
@@ -4393,758 +4393,758 @@ void LLAppViewer::badNetworkHandler()
 // is destroyed.
 void LLAppViewer::saveFinalSnapshot()
 {
-	if (!mSavedFinalSnapshot)
-	{
-		gSavedSettings.setVector3d("FocusPosOnLogout", gAgentCamera.calcFocusPositionTargetGlobal());
-		gSavedSettings.setVector3d("CameraPosOnLogout", gAgentCamera.calcCameraPositionTargetGlobal());
-		gViewerWindow->setCursor(UI_CURSOR_WAIT);
-		gAgentCamera.changeCameraToThirdPerson( FALSE );	// don't animate, need immediate switch
-		gSavedSettings.setBOOL("ShowParcelOwners", FALSE);
-		idle();
-
-		std::string snap_filename = gDirUtilp->getLindenUserDir();
-		snap_filename += gDirUtilp->getDirDelimiter();
-		snap_filename += LLStartUp::getScreenLastFilename();
-		// use full pixel dimensions of viewer window (not post-scale dimensions)
-		gViewerWindow->saveSnapshot(snap_filename,
-									gViewerWindow->getWindowWidthRaw(),
-									gViewerWindow->getWindowHeightRaw(),
-									FALSE,
-									gSavedSettings.getBOOL("RenderHUDInSnapshot"),
-									TRUE,
-									LLSnapshotModel::SNAPSHOT_TYPE_COLOR,
-									LLSnapshotModel::SNAPSHOT_FORMAT_PNG);
-		mSavedFinalSnapshot = TRUE;
-
-		if (gAgent.isInHomeRegion())
-		{
-			LLVector3d home;
-			if (gAgent.getHomePosGlobal(&home) && dist_vec(home, gAgent.getPositionGlobal()) < 10)
-			{
-				// We are at home position or close to it, see if we need to create home screenshot
-				// Notes:
-				// 1. It might be beneficial to also replace home if file is too old
-				// 2. This is far from best way/place to update screenshot since location might be not fully loaded,
-				// but we don't have many options
-				std::string snap_home = gDirUtilp->getLindenUserDir();
-				snap_home += gDirUtilp->getDirDelimiter();
-				snap_home += LLStartUp::getScreenHomeFilename();
-				if (!gDirUtilp->fileExists(snap_home))
-				{
-					// We are at home position yet no home image exist, fix it
-					LLFile::copy(snap_filename, snap_home);
-				}
-			}
-		}
-	}
+    if (!mSavedFinalSnapshot)
+    {
+        gSavedSettings.setVector3d("FocusPosOnLogout", gAgentCamera.calcFocusPositionTargetGlobal());
+        gSavedSettings.setVector3d("CameraPosOnLogout", gAgentCamera.calcCameraPositionTargetGlobal());
+        gViewerWindow->setCursor(UI_CURSOR_WAIT);
+        gAgentCamera.changeCameraToThirdPerson( FALSE );    // don't animate, need immediate switch
+        gSavedSettings.setBOOL("ShowParcelOwners", FALSE);
+        idle();
+
+        std::string snap_filename = gDirUtilp->getLindenUserDir();
+        snap_filename += gDirUtilp->getDirDelimiter();
+        snap_filename += LLStartUp::getScreenLastFilename();
+        // use full pixel dimensions of viewer window (not post-scale dimensions)
+        gViewerWindow->saveSnapshot(snap_filename,
+                                    gViewerWindow->getWindowWidthRaw(),
+                                    gViewerWindow->getWindowHeightRaw(),
+                                    FALSE,
+                                    gSavedSettings.getBOOL("RenderHUDInSnapshot"),
+                                    TRUE,
+                                    LLSnapshotModel::SNAPSHOT_TYPE_COLOR,
+                                    LLSnapshotModel::SNAPSHOT_FORMAT_PNG);
+        mSavedFinalSnapshot = TRUE;
+
+        if (gAgent.isInHomeRegion())
+        {
+            LLVector3d home;
+            if (gAgent.getHomePosGlobal(&home) && dist_vec(home, gAgent.getPositionGlobal()) < 10)
+            {
+                // We are at home position or close to it, see if we need to create home screenshot
+                // Notes:
+                // 1. It might be beneficial to also replace home if file is too old
+                // 2. This is far from best way/place to update screenshot since location might be not fully loaded,
+                // but we don't have many options
+                std::string snap_home = gDirUtilp->getLindenUserDir();
+                snap_home += gDirUtilp->getDirDelimiter();
+                snap_home += LLStartUp::getScreenHomeFilename();
+                if (!gDirUtilp->fileExists(snap_home))
+                {
+                    // We are at home position yet no home image exist, fix it
+                    LLFile::copy(snap_filename, snap_home);
+                }
+            }
+        }
+    }
 }
 
 void LLAppViewer::loadNameCache()
 {
-	// display names cache
-	std::string file;
-	if (LLGridManager::getInstance()->isInSecondlife())
-	{
-		file = "avatar_name_cache.llsd";
-	}
-	else
-	{
-		std::string gridlabel = LLGridManager::getInstance()->getGridId();
-		LLStringUtil::toLower(gridlabel);
-		file = llformat("avatar_name_cache.%s.llsd", gridlabel.c_str());
-	}
-	std::string filename =
-		gDirUtilp->getExpandedFilename(LL_PATH_CACHE, file);
-	LL_INFOS("AvNameCache") << filename << LL_ENDL;
-	llifstream name_cache_stream(filename.c_str());
-	if(name_cache_stream.is_open())
-	{
-		if ( ! LLAvatarNameCache::getInstance()->importFile(name_cache_stream))
+    // display names cache
+    std::string file;
+    if (LLGridManager::getInstance()->isInSecondlife())
+    {
+        file = "avatar_name_cache.llsd";
+    }
+    else
+    {
+        std::string gridlabel = LLGridManager::getInstance()->getGridId();
+        LLStringUtil::toLower(gridlabel);
+        file = llformat("avatar_name_cache.%s.llsd", gridlabel.c_str());
+    }
+    std::string filename =
+        gDirUtilp->getExpandedFilename(LL_PATH_CACHE, file);
+    LL_INFOS("AvNameCache") << filename << LL_ENDL;
+    llifstream name_cache_stream(filename.c_str());
+    if(name_cache_stream.is_open())
+    {
+        if ( ! LLAvatarNameCache::getInstance()->importFile(name_cache_stream))
         {
             LL_WARNS("AppInit") << "removing invalid '" << filename << "'" << LL_ENDL;
             name_cache_stream.close();
             LLFile::remove(filename);
         }
-	}
-
-	if (!gCacheName) return;
-
-	std::string name_file;
-	if (LLGridManager::getInstance()->isInSecondlife())
-	{
-		name_file = "name.cache";
-	}
-	else
-	{
-		std::string gridid = LLGridManager::getInstance()->getGridId();
-		LLStringUtil::toLower(gridid);
-		name_file = llformat("name.%s.cache", gridid.c_str());
-	}
-
-	std::string name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, name_file);
-	llifstream cache_file(name_cache.c_str());
-	if(cache_file.is_open())
-	{
-		if(gCacheName->importFile(cache_file)) return;
-	}
+    }
+
+    if (!gCacheName) return;
+
+    std::string name_file;
+    if (LLGridManager::getInstance()->isInSecondlife())
+    {
+        name_file = "name.cache";
+    }
+    else
+    {
+        std::string gridid = LLGridManager::getInstance()->getGridId();
+        LLStringUtil::toLower(gridid);
+        name_file = llformat("name.%s.cache", gridid.c_str());
+    }
+
+    std::string name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, name_file);
+    llifstream cache_file(name_cache.c_str());
+    if(cache_file.is_open())
+    {
+        if(gCacheName->importFile(cache_file)) return;
+    }
 }
 
 void LLAppViewer::saveNameCache()
 {
-	// display names cache
-	std::string file;
-	if (LLGridManager::getInstance()->isInSecondlife())
-	{
-		file = "avatar_name_cache.llsd";
-	}
-	else
-	{
-		std::string gridlabel = LLGridManager::getInstance()->getGridId();
-		LLStringUtil::toLower(gridlabel);
-		file = llformat("avatar_name_cache.%s.llsd", gridlabel.c_str());
-	}
-	std::string filename =
-		gDirUtilp->getExpandedFilename(LL_PATH_CACHE, file);
-	llofstream name_cache_stream(filename.c_str());
-	if(name_cache_stream.is_open())
-	{
-		LLAvatarNameCache::getInstance()->exportFile(name_cache_stream);
+    // display names cache
+    std::string file;
+    if (LLGridManager::getInstance()->isInSecondlife())
+    {
+        file = "avatar_name_cache.llsd";
+    }
+    else
+    {
+        std::string gridlabel = LLGridManager::getInstance()->getGridId();
+        LLStringUtil::toLower(gridlabel);
+        file = llformat("avatar_name_cache.%s.llsd", gridlabel.c_str());
+    }
+    std::string filename =
+        gDirUtilp->getExpandedFilename(LL_PATH_CACHE, file);
+    llofstream name_cache_stream(filename.c_str());
+    if(name_cache_stream.is_open())
+    {
+        LLAvatarNameCache::getInstance()->exportFile(name_cache_stream);
     }
 
     // real names cache
-	if (gCacheName)
-    {
-		std::string name_file;
-		if (LLGridManager::getInstance()->isInSecondlife())
-		{
-			name_file = "name.cache";
-		}
-		else
-		{
-			std::string gridid = LLGridManager::getInstance()->getGridId();
-			LLStringUtil::toLower(gridid);
-			name_file = llformat("name.%s.cache", gridid.c_str());
-		}
+    if (gCacheName)
+    {
+        std::string name_file;
+        if (LLGridManager::getInstance()->isInSecondlife())
+        {
+            name_file = "name.cache";
+        }
+        else
+        {
+            std::string gridid = LLGridManager::getInstance()->getGridId();
+            LLStringUtil::toLower(gridid);
+            name_file = llformat("name.%s.cache", gridid.c_str());
+        }
+
+        std::string name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, name_file);
+        llofstream cache_file(name_cache.c_str());
+        if(cache_file.is_open())
+        {
+            gCacheName->exportFile(cache_file);
+        }
+    }
+}
+
+
+/*! @brief      This class is an LLFrameTimer that can be created with
+                an elapsed time that starts counting up from the given value
+                rather than 0.0.
+
+                Otherwise it behaves the same way as LLFrameTimer.
+*/
+class LLFrameStatsTimer : public LLFrameTimer
+{
+public:
+    LLFrameStatsTimer(F64 elapsed_already = 0.0)
+        : LLFrameTimer()
+        {
+            mStartTime -= elapsed_already;
+        }
+};
+
+static LLTrace::BlockTimerStatHandle FTM_AUDIO_UPDATE("Update Audio");
+static LLTrace::BlockTimerStatHandle FTM_CLEANUP("Cleanup");
+static LLTrace::BlockTimerStatHandle FTM_CLEANUP_DRAWABLES("Drawables");
+static LLTrace::BlockTimerStatHandle FTM_IDLE_CB("Idle Callbacks");
+static LLTrace::BlockTimerStatHandle FTM_LOD_UPDATE("Update LOD");
+static LLTrace::BlockTimerStatHandle FTM_OBJECTLIST_UPDATE("Update Objectlist");
+static LLTrace::BlockTimerStatHandle FTM_REGION_UPDATE("Update Region");
+static LLTrace::BlockTimerStatHandle FTM_WORLD_UPDATE("Update World");
+static LLTrace::BlockTimerStatHandle FTM_NETWORK("Network");
+static LLTrace::BlockTimerStatHandle FTM_AGENT_NETWORK("Agent Network");
+static LLTrace::BlockTimerStatHandle FTM_VLMANAGER("VL Manager");
+static LLTrace::BlockTimerStatHandle FTM_AGENT_POSITION("Agent Position");
+static LLTrace::BlockTimerStatHandle FTM_HUD_EFFECTS("HUD Effects");
+
+///////////////////////////////////////////////////////
+// idle()
+//
+// Called every time the window is not doing anything.
+// Receive packets, update statistics, and schedule a redisplay.
+///////////////////////////////////////////////////////
+void LLAppViewer::idle()
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_APP;
+    pingMainloopTimeout("Main:Idle");
+
+    // Update frame timers
+    static LLTimer idle_timer;
+
+    LLFrameTimer::updateFrameTime();
+    LLFrameTimer::updateFrameCount();
+    LLEventTimer::updateClass();
+    LLPerfStats::updateClass();
+
+    // LLApp::stepFrame() performs the above three calls plus mRunner.run().
+    // Not sure why we don't call stepFrame() here, except that LLRunner seems
+    // completely redundant with LLEventTimer.
+    LLNotificationsUI::LLToast::updateClass();
+    LLSmoothInterpolation::updateInterpolants();
+    LLMortician::updateClass();
+    LLFilePickerThread::clearDead();  //calls LLFilePickerThread::notify()
+    LLDirPickerThread::clearDead();
+    F32 dt_raw = idle_timer.getElapsedTimeAndResetF32();
+
+    LLGLTFMaterialList::flushUpdates();
+
+    // Service the WorkQueue we use for replies from worker threads.
+    // Use function statics for the timeslice setting so we only have to fetch
+    // and convert MainWorkTime once.
+    static F32 MainWorkTimeRaw = gSavedSettings.getF32("MainWorkTime");
+    static F32Milliseconds MainWorkTimeMs(MainWorkTimeRaw);
+    // MainWorkTime is specified in fractional milliseconds, but std::chrono
+    // uses integer representations. What if we want less than a microsecond?
+    // Use nanoseconds. We're very sure we will never need to specify a
+    // MainWorkTime that would be larger than we could express in
+    // std::chrono::nanoseconds.
+    static std::chrono::nanoseconds MainWorkTimeNanoSec{
+        std::chrono::nanoseconds::rep(MainWorkTimeMs.value() * 1000000)};
+    gMainloopWork.runFor(MainWorkTimeNanoSec);
+
+    // Cap out-of-control frame times
+    // Too low because in menus, swapping, debugger, etc.
+    // Too high because idle called with no objects in view, etc.
+    const F32 MIN_FRAME_RATE = 1.f;
+    const F32 MAX_FRAME_RATE = 200.f;
+
+    F32 frame_rate_clamped = 1.f / dt_raw;
+    frame_rate_clamped = llclamp(frame_rate_clamped, MIN_FRAME_RATE, MAX_FRAME_RATE);
+    gFrameDTClamped = 1.f / frame_rate_clamped;
+
+    // Global frame timer
+    // Smoothly weight toward current frame
+    gFPSClamped = (frame_rate_clamped + (4.f * gFPSClamped)) / 5.f;
+
+    static const LLCachedControl<F32> qas(gSavedSettings, "QuitAfterSeconds");
+    if (qas > 0.f)
+    {
+        if (gRenderStartTime.getElapsedTimeF32() > qas)
+        {
+            LL_INFOS() << "Quitting after " << qas << " seconds. See setting \"QuitAfterSeconds\"." << LL_ENDL;
+            LLAppViewer::instance()->forceQuit();
+        }
+    }
+
+    // Must wait until both have avatar object and mute list, so poll
+    // here.
+    LLIMProcessing::requestOfflineMessages();
+
+    ///////////////////////////////////
+    //
+    // Special case idle if still starting up
+    //
+    if (LLStartUp::getStartupState() < STATE_STARTED)
+    {
+        // Skip rest if idle startup returns false (essentially, no world yet)
+        gGLActive = TRUE;
+        if (!idle_startup())
+        {
+            gGLActive = FALSE;
+            return;
+        }
+        gGLActive = FALSE;
+    }
+
+    auto& worldInst = LLWorld::instance();
+
+    F32 yaw = 0.f;              // radians
+
+    if (!gDisconnected)
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_NETWORK("network"); //LL_RECORD_BLOCK_TIME(FTM_NETWORK);
+        // Update spaceserver timeinfo
+        worldInst.setSpaceTimeUSec(worldInst.getSpaceTimeUSec() + LLUnits::Seconds::fromValue(dt_raw));
+
+
+        //////////////////////////////////////
+        //
+        // Update simulator agent state
+        //
+
+        static const LLCachedControl<bool> rotateRight(gSavedSettings, "RotateRight");
+        if (rotateRight)
+        {
+            gAgent.moveYaw(-1.f);
+        }
+
+        {
+            LL_PROFILE_ZONE_NAMED_CATEGORY_APP("Autopilot");
+            // Handle automatic walking towards points
+            gAgentPilot.updateTarget();
+            gAgent.autoPilot(&yaw);
+
+            //BD - Animator
+            gDragonAnimator.update();
+        }
+
+        static LLFrameTimer agent_update_timer;
+
+        // When appropriate, update agent location to the simulator.
+        F32 agent_update_time = agent_update_timer.getElapsedTimeF32();
+        F32 agent_force_update_time = mLastAgentForceUpdate + agent_update_time;
+        bool timed_out = agent_update_time > (1.0f / (F32)AGENT_UPDATES_PER_SECOND);
+        BOOL force_send =
+            // if there is something to send
+            (gAgent.controlFlagsDirty() && timed_out)
+            // if something changed
+            || (mLastAgentControlFlags != gAgent.getControlFlags())
+            // keep alive
+            || (agent_force_update_time > (1.0f / (F32) AGENT_FORCE_UPDATES_PER_SECOND));
+        // timing out doesn't warranty that an update will be sent,
+        // just that it will be checked.
+        if (force_send || timed_out)
+        {
+            LL_PROFILE_ZONE_SCOPED_CATEGORY_NETWORK;
+            // Send avatar and camera info
+            mLastAgentControlFlags = gAgent.getControlFlags();
+            mLastAgentForceUpdate = force_send ? 0 : agent_force_update_time;
+            send_agent_update(force_send);
+            agent_update_timer.reset();
+        }
+    }
+
+    //////////////////////////////////////
+    //
+    // Manage statistics
+    //
+    //
+    {
+        // Initialize the viewer_stats_timer with an already elapsed time
+        // of SEND_STATS_PERIOD so that the initial stats report will
+        // be sent immediately.
+        static LLFrameStatsTimer viewer_stats_timer(SEND_STATS_PERIOD);
+
+        // Update session stats every large chunk of time
+        // *FIX: (?) SAMANTHA
+        if (viewer_stats_timer.getElapsedTimeF32() >= SEND_STATS_PERIOD && !gDisconnected)
+        {
+            LL_INFOS() << "Transmitting sessions stats" << LL_ENDL;
+            bool include_preferences = false;
+            send_viewer_stats(include_preferences);
+            viewer_stats_timer.reset();
+        }
+
+        // Print the object debugging stats
+        static LLFrameTimer object_debug_timer;
+        if (object_debug_timer.getElapsedTimeF32() > 5.f)
+        {
+            object_debug_timer.reset();
+            if (gObjectList.mNumDeadObjectUpdates)
+            {
+                LL_INFOS() << "Dead object updates: " << gObjectList.mNumDeadObjectUpdates << LL_ENDL;
+                gObjectList.mNumDeadObjectUpdates = 0;
+            }
+            if (gObjectList.mNumUnknownUpdates)
+            {
+                LL_INFOS() << "Unknown object updates: " << gObjectList.mNumUnknownUpdates << LL_ENDL;
+                gObjectList.mNumUnknownUpdates = 0;
+            }
+
+        }
+    }
+
+    if (!gDisconnected)
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Network");
+
+        ////////////////////////////////////////////////
+        //
+        // Network processing
+        //
+        // NOTE: Starting at this point, we may still have pointers to "dead" objects
+        // floating throughout the various object lists.
+        //
+        idleNameCache();
+        idleNetwork();
+
+
+        // Check for away from keyboard, kick idle agents.
+        idle_afk_check();
+
+        //  Update statistics for this frame
+        update_statistics();
+    }
+
+    ////////////////////////////////////////
+    //
+    // Handle the regular UI idle callbacks as well as
+    // hover callbacks
+    //
+
+#ifdef LL_DARWIN
+    if (!mQuitRequested)  //MAINT-4243
+#endif
+    {
+//      LL_RECORD_BLOCK_TIME(FTM_IDLE_CB);
+
+        // Do event notifications if necessary.  Yes, we may want to move this elsewhere.
+        gEventNotifier.update();
+
+        gIdleCallbacks.callFunctions();
+        gInventory.idleNotifyObservers();
+        LLAvatarTracker::instance().idleNotifyObservers();
+    }
+
+    // Metrics logging (LLViewerAssetStats, etc.)
+    {
+        static LLTimer report_interval;
+
+        // *TODO:  Add configuration controls for this
+        F32 seconds = report_interval.getElapsedTimeF32();
+        if (seconds >= app_metrics_interval)
+        {
+            metricsSend(! gDisconnected);
+            report_interval.reset();
+        }
+    }
+
+
+    // Update layonts, handle mouse events, tooltips, e t c
+    // updateUI() needs to be called even in case viewer disconected
+    // since related notification still needs handling and allows
+    // opening chat.
+    gViewerWindow->updateUI();
+
+    if (gDisconnected)
+    {
+        return;
+    }
+
+    if (gTeleportDisplay)
+    {
+        return;
+    }
+
+    ///////////////////////////////////////
+    // Agent and camera movement
+    //
+    LLCoordGL current_mouse = gViewerWindow->getCurrentMouse();
+
+    {
+        // After agent and camera moved, figure out if we need to
+        // deselect objects.
+        LLSelectMgr::getInstance()->deselectAllIfTooFar();
+
+    }
+
+    {
+        // Handle pending gesture processing
+        LL_RECORD_BLOCK_TIME(FTM_AGENT_POSITION);
+        LLGestureMgr::instance().update();
+
+        gAgent.updateAgentPosition(gFrameDTClamped, yaw, current_mouse.mX, current_mouse.mY);
+    }
+
+    {
+        LL_RECORD_BLOCK_TIME(FTM_OBJECTLIST_UPDATE);
+
+        if (!(logoutRequestSent() && hasSavedFinalSnapshot()))
+        {
+            gObjectList.update(gAgent);
+            LL::GLTFSceneManager::instance().update();
+        }
+    }
+
+    //////////////////////////////////////
+    //
+    // Deletes objects...
+    // Has to be done after doing idleUpdates (which can kill objects)
+    //
 
-        std::string name_cache = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, name_file);
-        llofstream cache_file(name_cache.c_str());
-        if(cache_file.is_open())
+    {
+        LL_RECORD_BLOCK_TIME(FTM_CLEANUP);
         {
-            gCacheName->exportFile(cache_file);
+            gObjectList.cleanDeadObjects();
         }
-	}
-}
+        {
+            LL_RECORD_BLOCK_TIME(FTM_CLEANUP_DRAWABLES);
+            LLDrawable::cleanupDeadDrawables();
+        }
+    }
 
+    //
+    // After this point, in theory we should never see a dead object
+    // in the various object/drawable lists.
+    //
 
-/*!	@brief		This class is an LLFrameTimer that can be created with
-				an elapsed time that starts counting up from the given value
-				rather than 0.0.
+    //////////////////////////////////////
+    //
+    // Update/send HUD effects
+    //
+    // At this point, HUD effects may clean up some references to
+    // dead objects.
+    //
 
-				Otherwise it behaves the same way as LLFrameTimer.
-*/
-class LLFrameStatsTimer : public LLFrameTimer
-{
-public:
-	LLFrameStatsTimer(F64 elapsed_already = 0.0)
-		: LLFrameTimer()
-		{
-			mStartTime -= elapsed_already;
-		}
-};
+    {
+        LL_RECORD_BLOCK_TIME(FTM_HUD_EFFECTS);
+        LLSelectMgr::getInstance()->updateEffects();
+        LLHUDManager::getInstance()->cleanupEffects();
+        LLHUDManager::getInstance()->sendEffects();
+    }
 
-static LLTrace::BlockTimerStatHandle FTM_AUDIO_UPDATE("Update Audio");
-static LLTrace::BlockTimerStatHandle FTM_CLEANUP("Cleanup");
-static LLTrace::BlockTimerStatHandle FTM_CLEANUP_DRAWABLES("Drawables");
-static LLTrace::BlockTimerStatHandle FTM_IDLE_CB("Idle Callbacks");
-static LLTrace::BlockTimerStatHandle FTM_LOD_UPDATE("Update LOD");
-static LLTrace::BlockTimerStatHandle FTM_OBJECTLIST_UPDATE("Update Objectlist");
-static LLTrace::BlockTimerStatHandle FTM_REGION_UPDATE("Update Region");
-static LLTrace::BlockTimerStatHandle FTM_WORLD_UPDATE("Update World");
-static LLTrace::BlockTimerStatHandle FTM_NETWORK("Network");
-static LLTrace::BlockTimerStatHandle FTM_AGENT_NETWORK("Agent Network");
-static LLTrace::BlockTimerStatHandle FTM_VLMANAGER("VL Manager");
-static LLTrace::BlockTimerStatHandle FTM_AGENT_POSITION("Agent Position");
-static LLTrace::BlockTimerStatHandle FTM_HUD_EFFECTS("HUD Effects");
+    ////////////////////////////////////////
+    //
+    // Unpack layer data that we've received
+    //
 
-///////////////////////////////////////////////////////
-// idle()
-//
-// Called every time the window is not doing anything.
-// Receive packets, update statistics, and schedule a redisplay.
-///////////////////////////////////////////////////////
-void LLAppViewer::idle()
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_APP;
-	pingMainloopTimeout("Main:Idle");
+    {
+        LL_RECORD_BLOCK_TIME(FTM_NETWORK);
+        gVLManager.unpackData();
+    }
 
-	// Update frame timers
-	static LLTimer idle_timer;
+    /////////////////////////
+    //
+    // Update surfaces, and surface textures as well.
+    //
 
-	LLFrameTimer::updateFrameTime();
-	LLFrameTimer::updateFrameCount();
-	LLEventTimer::updateClass();
-    LLPerfStats::updateClass();
+    worldInst.updateVisibilities();
+    {
+        const F32 max_region_update_time = .001f; // 1ms
+        LL_RECORD_BLOCK_TIME(FTM_REGION_UPDATE);
+        worldInst.updateRegions(max_region_update_time);
+    }
 
-	// LLApp::stepFrame() performs the above three calls plus mRunner.run().
-	// Not sure why we don't call stepFrame() here, except that LLRunner seems
-	// completely redundant with LLEventTimer.
-	LLNotificationsUI::LLToast::updateClass();
-	LLSmoothInterpolation::updateInterpolants();
-	LLMortician::updateClass();
-	LLFilePickerThread::clearDead();  //calls LLFilePickerThread::notify()
-	LLDirPickerThread::clearDead();
-	F32 dt_raw = idle_timer.getElapsedTimeAndResetF32();
+    /////////////////////////
+    //
+    // Update weather effects
+    //
 
-    LLGLTFMaterialList::flushUpdates();
+    // Update wind vector
+    LLVector3 wind_position_region;
+    static LLVector3 average_wind;
 
-	// Service the WorkQueue we use for replies from worker threads.
-	// Use function statics for the timeslice setting so we only have to fetch
-	// and convert MainWorkTime once.
-	static F32 MainWorkTimeRaw = gSavedSettings.getF32("MainWorkTime");
-	static F32Milliseconds MainWorkTimeMs(MainWorkTimeRaw);
-	// MainWorkTime is specified in fractional milliseconds, but std::chrono
-	// uses integer representations. What if we want less than a microsecond?
-	// Use nanoseconds. We're very sure we will never need to specify a
-	// MainWorkTime that would be larger than we could express in
-	// std::chrono::nanoseconds.
-	static std::chrono::nanoseconds MainWorkTimeNanoSec{
-		std::chrono::nanoseconds::rep(MainWorkTimeMs.value() * 1000000)};
-	gMainloopWork.runFor(MainWorkTimeNanoSec);
-
-	// Cap out-of-control frame times
-	// Too low because in menus, swapping, debugger, etc.
-	// Too high because idle called with no objects in view, etc.
-	const F32 MIN_FRAME_RATE = 1.f;
-	const F32 MAX_FRAME_RATE = 200.f;
-
-	F32 frame_rate_clamped = 1.f / dt_raw;
-	frame_rate_clamped = llclamp(frame_rate_clamped, MIN_FRAME_RATE, MAX_FRAME_RATE);
-	gFrameDTClamped = 1.f / frame_rate_clamped;
-
-	// Global frame timer
-	// Smoothly weight toward current frame
-	gFPSClamped = (frame_rate_clamped + (4.f * gFPSClamped)) / 5.f;
-
-	static const LLCachedControl<F32> qas(gSavedSettings, "QuitAfterSeconds");
-	if (qas > 0.f)
-	{
-		if (gRenderStartTime.getElapsedTimeF32() > qas)
-		{
-			LL_INFOS() << "Quitting after " << qas << " seconds. See setting \"QuitAfterSeconds\"." << LL_ENDL;
-			LLAppViewer::instance()->forceQuit();
-		}
-	}
-
-	// Must wait until both have avatar object and mute list, so poll
-	// here.
-	LLIMProcessing::requestOfflineMessages();
-
-	///////////////////////////////////
-	//
-	// Special case idle if still starting up
-	//
-	if (LLStartUp::getStartupState() < STATE_STARTED)
-	{
-		// Skip rest if idle startup returns false (essentially, no world yet)
-		gGLActive = TRUE;
-		if (!idle_startup())
-		{
-			gGLActive = FALSE;
-			return;
-		}
-		gGLActive = FALSE;
-	}
-
-	auto& worldInst = LLWorld::instance();
-
-    F32 yaw = 0.f;				// radians
-
-	if (!gDisconnected)
-	{
-		LL_PROFILE_ZONE_NAMED_CATEGORY_NETWORK("network"); //LL_RECORD_BLOCK_TIME(FTM_NETWORK);
-		// Update spaceserver timeinfo
-	    worldInst.setSpaceTimeUSec(worldInst.getSpaceTimeUSec() + LLUnits::Seconds::fromValue(dt_raw));
-
-
-	    //////////////////////////////////////
-	    //
-	    // Update simulator agent state
-	    //
-
-		static const LLCachedControl<bool> rotateRight(gSavedSettings, "RotateRight");
-		if (rotateRight)
-		{
-			gAgent.moveYaw(-1.f);
-		}
-
-		{
-            LL_PROFILE_ZONE_NAMED_CATEGORY_APP("Autopilot");
-			// Handle automatic walking towards points
-			gAgentPilot.updateTarget();
-			gAgent.autoPilot(&yaw);
+    LLViewerRegion *regionp;
+    regionp = worldInst.resolveRegionGlobal(wind_position_region, gAgent.getPositionGlobal());  // puts agent's local coords into wind_position
+    if (regionp)
+    {
+        gWindVec = regionp->mWind.getVelocity(wind_position_region);
 
-			//BD - Animator
-			gDragonAnimator.update();
-		}
+        // Compute average wind and use to drive motion of water
 
-		static LLFrameTimer agent_update_timer;
+        average_wind = regionp->mWind.getAverage();
+        gSky.setWind(average_wind);
+        //LLVOWater::setWind(average_wind);
+    }
+    else
+    {
+        gWindVec.setVec(0.0f, 0.0f, 0.0f);
+    }
 
-		// When appropriate, update agent location to the simulator.
-		F32 agent_update_time = agent_update_timer.getElapsedTimeF32();
-		F32 agent_force_update_time = mLastAgentForceUpdate + agent_update_time;
-        bool timed_out = agent_update_time > (1.0f / (F32)AGENT_UPDATES_PER_SECOND);
-        BOOL force_send =
-            // if there is something to send
-            (gAgent.controlFlagsDirty() && timed_out)
-            // if something changed
-            || (mLastAgentControlFlags != gAgent.getControlFlags())
-            // keep alive
-            || (agent_force_update_time > (1.0f / (F32) AGENT_FORCE_UPDATES_PER_SECOND));
-        // timing out doesn't warranty that an update will be sent,
-        // just that it will be checked.
-		if (force_send || timed_out)
-		{
-			LL_PROFILE_ZONE_SCOPED_CATEGORY_NETWORK;
-			// Send avatar and camera info
-			mLastAgentControlFlags = gAgent.getControlFlags();
-			mLastAgentForceUpdate = force_send ? 0 : agent_force_update_time;
-			send_agent_update(force_send);
-			agent_update_timer.reset();
-		}
-	}
-
-	//////////////////////////////////////
-	//
-	// Manage statistics
-	//
-	//
-	{
-		// Initialize the viewer_stats_timer with an already elapsed time
-		// of SEND_STATS_PERIOD so that the initial stats report will
-		// be sent immediately.
-		static LLFrameStatsTimer viewer_stats_timer(SEND_STATS_PERIOD);
-
-		// Update session stats every large chunk of time
-		// *FIX: (?) SAMANTHA
-		if (viewer_stats_timer.getElapsedTimeF32() >= SEND_STATS_PERIOD && !gDisconnected)
-		{
-			LL_INFOS() << "Transmitting sessions stats" << LL_ENDL;
-			bool include_preferences = false;
-			send_viewer_stats(include_preferences);
-			viewer_stats_timer.reset();
-		}
-
-		// Print the object debugging stats
-		static LLFrameTimer object_debug_timer;
-		if (object_debug_timer.getElapsedTimeF32() > 5.f)
-		{
-			object_debug_timer.reset();
-			if (gObjectList.mNumDeadObjectUpdates)
-			{
-				LL_INFOS() << "Dead object updates: " << gObjectList.mNumDeadObjectUpdates << LL_ENDL;
-				gObjectList.mNumDeadObjectUpdates = 0;
-			}
-			if (gObjectList.mNumUnknownUpdates)
-			{
-				LL_INFOS() << "Unknown object updates: " << gObjectList.mNumUnknownUpdates << LL_ENDL;
-				gObjectList.mNumUnknownUpdates = 0;
-			}
-
-		}
-	}
-
-	if (!gDisconnected)
-	{
-        LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Network");
+    //////////////////////////////////////
+    //
+    // Sort and cull in the new renderer are moved to pipeline.cpp
+    // Here, particles are updated and drawables are moved.
+    //
 
-	    ////////////////////////////////////////////////
-	    //
-	    // Network processing
-	    //
-	    // NOTE: Starting at this point, we may still have pointers to "dead" objects
-	    // floating throughout the various object lists.
-	    //
-		idleNameCache();
-		idleNetwork();
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_APP("world update"); //LL_RECORD_BLOCK_TIME(FTM_WORLD_UPDATE);
+        gPipeline.updateMove();
+    }
 
+    worldInst.updateParticles();
 
-		// Check for away from keyboard, kick idle agents.
-		idle_afk_check();
+    if (gAgentPilot.isPlaying() && gAgentPilot.getOverrideCamera())
+    {
+        gAgentPilot.moveCamera();
+    }
+    else if (LLViewerJoystick::getInstance()->getOverrideCamera())
+    {
+        LLViewerJoystick::getInstance()->moveFlycam();
+    }
+    else
+    {
+        if (LLToolMgr::getInstance()->inBuildMode())
+        {
+            LLViewerJoystick::getInstance()->moveObjects();
+        }
 
-		//  Update statistics for this frame
-		update_statistics();
-	}
+        gAgentCamera.updateCamera();
+    }
 
-	////////////////////////////////////////
-	//
-	// Handle the regular UI idle callbacks as well as
-	// hover callbacks
-	//
+    // update media focus
+    LLViewerMediaFocus::getInstance()->update();
 
-#ifdef LL_DARWIN
-	if (!mQuitRequested)  //MAINT-4243
-#endif
-	{
-// 		LL_RECORD_BLOCK_TIME(FTM_IDLE_CB);
+    // Update marketplace
+    LLMarketplaceInventoryImporter::update();
+    LLMarketplaceInventoryNotifications::update();
 
-		// Do event notifications if necessary.  Yes, we may want to move this elsewhere.
-		gEventNotifier.update();
+    // objects and camera should be in sync, do LOD calculations now
+    {
+        LL_RECORD_BLOCK_TIME(FTM_LOD_UPDATE);
+        gObjectList.updateApparentAngles(gAgent);
+    }
 
-		gIdleCallbacks.callFunctions();
-		gInventory.idleNotifyObservers();
-		LLAvatarTracker::instance().idleNotifyObservers();
-	}
+    // Update AV render info
+    LLAvatarRenderInfoAccountant::getInstance()->idle();
 
-	// Metrics logging (LLViewerAssetStats, etc.)
-	{
-		static LLTimer report_interval;
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_APP("audio update"); //LL_RECORD_BLOCK_TIME(FTM_AUDIO_UPDATE);
 
-		// *TODO:  Add configuration controls for this
-		F32 seconds = report_interval.getElapsedTimeF32();
-		if (seconds >= app_metrics_interval)
-		{
-			metricsSend(! gDisconnected);
-			report_interval.reset();
-		}
-	}
+        if (gAudiop)
+        {
+            audio_update_volume(false);
+            audio_update_listener();
+            audio_update_wind(false);
 
+            // this line actually commits the changes we've made to source positions, etc.
+            gAudiop->idle();
+        }
+    }
 
-    // Update layonts, handle mouse events, tooltips, e t c
-    // updateUI() needs to be called even in case viewer disconected
-    // since related notification still needs handling and allows
-    // opening chat.
-    gViewerWindow->updateUI();
+    // Handle shutdown process, for example,
+    // wait for floaters to close, send quit message,
+    // forcibly quit if it has taken too long
+    if (mQuitRequested)
+    {
+        gGLActive = TRUE;
+        idleShutdown();
+    }
+}
+
+void LLAppViewer::idleShutdown()
+{
+    // Wait for all modal alerts to get resolved
+    if (LLModalDialog::activeCount() > 0)
+    {
+        return;
+    }
 
-	if (gDisconnected)
+    // close IM interface
+    if(gIMMgr)
     {
-		return;
+        gIMMgr->disconnectAllSessions();
     }
 
-	if (gTeleportDisplay)
+    // Wait for all floaters to get resolved
+    if (gFloaterView
+        && !gFloaterView->allChildrenClosed())
     {
-		return;
+        return;
     }
 
-	///////////////////////////////////////
-	// Agent and camera movement
-	//
-	LLCoordGL current_mouse = gViewerWindow->getCurrentMouse();
 
-	{
-		// After agent and camera moved, figure out if we need to
-		// deselect objects.
-		LLSelectMgr::getInstance()->deselectAllIfTooFar();
 
-	}
 
-	{
-		// Handle pending gesture processing
-		LL_RECORD_BLOCK_TIME(FTM_AGENT_POSITION);
-		LLGestureMgr::instance().update();
+    // ProductEngine: Try moving this code to where we shut down sTextureCache in cleanup()
+    // *TODO: ugly
+    static bool saved_teleport_history = false;
+    if (!saved_teleport_history)
+    {
+        saved_teleport_history = true;
+        LLTeleportHistory::getInstance()->dump();
+        LLLocationHistory::getInstance()->save(); // *TODO: find a better place for doing this
+        return;
+    }
 
-		gAgent.updateAgentPosition(gFrameDTClamped, yaw, current_mouse.mX, current_mouse.mY);
-	}
+    static bool saved_snapshot = false;
+    if (!saved_snapshot)
+    {
+        saved_snapshot = true;
+        saveFinalSnapshot();
+        return;
+    }
 
-	{
-		LL_RECORD_BLOCK_TIME(FTM_OBJECTLIST_UPDATE);
+    const F32 SHUTDOWN_UPLOAD_SAVE_TIME = 5.f;
 
-        if (!(logoutRequestSent() && hasSavedFinalSnapshot()))
-		{
-			gObjectList.update(gAgent);
-            LL::GLTFSceneManager::instance().update();
-		}
-	}
-
-	//////////////////////////////////////
-	//
-	// Deletes objects...
-	// Has to be done after doing idleUpdates (which can kill objects)
-	//
-
-	{
-		LL_RECORD_BLOCK_TIME(FTM_CLEANUP);
-		{
-			gObjectList.cleanDeadObjects();
-		}
-		{
-			LL_RECORD_BLOCK_TIME(FTM_CLEANUP_DRAWABLES);
-			LLDrawable::cleanupDeadDrawables();
-		}
-	}
-
-	//
-	// After this point, in theory we should never see a dead object
-	// in the various object/drawable lists.
-	//
-
-	//////////////////////////////////////
-	//
-	// Update/send HUD effects
-	//
-	// At this point, HUD effects may clean up some references to
-	// dead objects.
-	//
-
-	{
-		LL_RECORD_BLOCK_TIME(FTM_HUD_EFFECTS);
-		LLSelectMgr::getInstance()->updateEffects();
-		LLHUDManager::getInstance()->cleanupEffects();
-		LLHUDManager::getInstance()->sendEffects();
-	}
-
-	////////////////////////////////////////
-	//
-	// Unpack layer data that we've received
-	//
-
-	{
-		LL_RECORD_BLOCK_TIME(FTM_NETWORK);
-		gVLManager.unpackData();
-	}
-
-	/////////////////////////
-	//
-	// Update surfaces, and surface textures as well.
-	//
-
-	worldInst.updateVisibilities();
-	{
-		const F32 max_region_update_time = .001f; // 1ms
-		LL_RECORD_BLOCK_TIME(FTM_REGION_UPDATE);
-		worldInst.updateRegions(max_region_update_time);
-	}
-
-	/////////////////////////
-	//
-	// Update weather effects
-	//
-
-	// Update wind vector
-	LLVector3 wind_position_region;
-	static LLVector3 average_wind;
-
-	LLViewerRegion *regionp;
-	regionp = worldInst.resolveRegionGlobal(wind_position_region, gAgent.getPositionGlobal());	// puts agent's local coords into wind_position
-	if (regionp)
-	{
-		gWindVec = regionp->mWind.getVelocity(wind_position_region);
-
-		// Compute average wind and use to drive motion of water
-
-		average_wind = regionp->mWind.getAverage();
-		gSky.setWind(average_wind);
-		//LLVOWater::setWind(average_wind);
-	}
-	else
-	{
-		gWindVec.setVec(0.0f, 0.0f, 0.0f);
-	}
-
-	//////////////////////////////////////
-	//
-	// Sort and cull in the new renderer are moved to pipeline.cpp
-	// Here, particles are updated and drawables are moved.
-	//
-
-	{
-		LL_PROFILE_ZONE_NAMED_CATEGORY_APP("world update"); //LL_RECORD_BLOCK_TIME(FTM_WORLD_UPDATE);
-		gPipeline.updateMove();
-	}
-
-	worldInst.updateParticles();
-
-	if (gAgentPilot.isPlaying() && gAgentPilot.getOverrideCamera())
-	{
-		gAgentPilot.moveCamera();
-	}
-	else if (LLViewerJoystick::getInstance()->getOverrideCamera())
-	{
-		LLViewerJoystick::getInstance()->moveFlycam();
-	}
-	else
-	{
-		if (LLToolMgr::getInstance()->inBuildMode())
-		{
-			LLViewerJoystick::getInstance()->moveObjects();
-		}
-
-		gAgentCamera.updateCamera();
-	}
-
-	// update media focus
-	LLViewerMediaFocus::getInstance()->update();
-
-	// Update marketplace
-	LLMarketplaceInventoryImporter::update();
-	LLMarketplaceInventoryNotifications::update();
-
-	// objects and camera should be in sync, do LOD calculations now
-	{
-		LL_RECORD_BLOCK_TIME(FTM_LOD_UPDATE);
-		gObjectList.updateApparentAngles(gAgent);
-	}
-
-	// Update AV render info
-	LLAvatarRenderInfoAccountant::getInstance()->idle();
-
-	{
-		LL_PROFILE_ZONE_NAMED_CATEGORY_APP("audio update"); //LL_RECORD_BLOCK_TIME(FTM_AUDIO_UPDATE);
-
-		if (gAudiop)
-		{
-		    audio_update_volume(false);
-			audio_update_listener();
-			audio_update_wind(false);
-
-			// this line actually commits the changes we've made to source positions, etc.
-			gAudiop->idle();
-		}
-	}
-
-	// Handle shutdown process, for example,
-	// wait for floaters to close, send quit message,
-	// forcibly quit if it has taken too long
-	if (mQuitRequested)
-	{
-		gGLActive = TRUE;
-		idleShutdown();
-	}
-}
+    S32 pending_uploads = gAssetStorage->getNumPendingUploads();
+    if (pending_uploads > 0
+        && gLogoutTimer.getElapsedTimeF32() < SHUTDOWN_UPLOAD_SAVE_TIME
+        && !logoutRequestSent())
+    {
+        static S32 total_uploads = 0;
+        // Sometimes total upload count can change during logout.
+        total_uploads = llmax(total_uploads, pending_uploads);
+        gViewerWindow->setShowProgress(TRUE);
+        S32 finished_uploads = total_uploads - pending_uploads;
+        F32 percent = 100.f * finished_uploads / total_uploads;
+        gViewerWindow->setProgressPercent(percent);
+        gViewerWindow->setProgressString(LLTrans::getString("SavingSettings"));
+        return;
+    }
 
-void LLAppViewer::idleShutdown()
-{
-	// Wait for all modal alerts to get resolved
-	if (LLModalDialog::activeCount() > 0)
-	{
-		return;
-	}
-
-	// close IM interface
-	if(gIMMgr)
-	{
-		gIMMgr->disconnectAllSessions();
-	}
-
-	// Wait for all floaters to get resolved
-	if (gFloaterView
-		&& !gFloaterView->allChildrenClosed())
-	{
-		return;
-	}
-
-
-
-
-	// ProductEngine: Try moving this code to where we shut down sTextureCache in cleanup()
-	// *TODO: ugly
-	static bool saved_teleport_history = false;
-	if (!saved_teleport_history)
-	{
-		saved_teleport_history = true;
-		LLTeleportHistory::getInstance()->dump();
-		LLLocationHistory::getInstance()->save(); // *TODO: find a better place for doing this
-		return;
-	}
-
-	static bool saved_snapshot = false;
-	if (!saved_snapshot)
-	{
-		saved_snapshot = true;
-		saveFinalSnapshot();
-		return;
-	}
-
-	const F32 SHUTDOWN_UPLOAD_SAVE_TIME = 5.f;
-
-	S32 pending_uploads = gAssetStorage->getNumPendingUploads();
-	if (pending_uploads > 0
-		&& gLogoutTimer.getElapsedTimeF32() < SHUTDOWN_UPLOAD_SAVE_TIME
-		&& !logoutRequestSent())
-	{
-		static S32 total_uploads = 0;
-		// Sometimes total upload count can change during logout.
-		total_uploads = llmax(total_uploads, pending_uploads);
-		gViewerWindow->setShowProgress(TRUE);
-		S32 finished_uploads = total_uploads - pending_uploads;
-		F32 percent = 100.f * finished_uploads / total_uploads;
-		gViewerWindow->setProgressPercent(percent);
-		gViewerWindow->setProgressString(LLTrans::getString("SavingSettings"));
-		return;
-	}
-
-	if (gPendingMetricsUploads > 0
-		&& gLogoutTimer.getElapsedTimeF32() < SHUTDOWN_UPLOAD_SAVE_TIME
-		&& !logoutRequestSent())
-	{
+    if (gPendingMetricsUploads > 0
+        && gLogoutTimer.getElapsedTimeF32() < SHUTDOWN_UPLOAD_SAVE_TIME
+        && !logoutRequestSent())
+    {
+        gViewerWindow->setShowProgress(TRUE);
+        gViewerWindow->setProgressPercent(100.f);
+        gViewerWindow->setProgressString(LLTrans::getString("LoggingOut"));
+        return;
+    }
+
+    // All floaters are closed.  Tell server we want to quit.
+    if( !logoutRequestSent() )
+    {
+        sendLogoutRequest();
+
+        // Wait for a LogoutReply message
         gViewerWindow->setShowProgress(TRUE);
         gViewerWindow->setProgressPercent(100.f);
         gViewerWindow->setProgressString(LLTrans::getString("LoggingOut"));
-		return;
-	}
-
-	// All floaters are closed.  Tell server we want to quit.
-	if( !logoutRequestSent() )
-	{
-		sendLogoutRequest();
-
-		// Wait for a LogoutReply message
-		gViewerWindow->setShowProgress(TRUE);
-		gViewerWindow->setProgressPercent(100.f);
-		gViewerWindow->setProgressString(LLTrans::getString("LoggingOut"));
-		return;
-	}
-
-	// Make sure that we quit if we haven't received a reply from the server.
-	if( logoutRequestSent()
-		&& gLogoutTimer.getElapsedTimeF32() > gLogoutMaxTime )
-	{
-		forceQuit();
-		return;
-	}
+        return;
+    }
+
+    // Make sure that we quit if we haven't received a reply from the server.
+    if( logoutRequestSent()
+        && gLogoutTimer.getElapsedTimeF32() > gLogoutMaxTime )
+    {
+        forceQuit();
+        return;
+    }
 }
 
 void LLAppViewer::sendLogoutRequest()
 {
-	if(!mLogoutRequestSent && gMessageSystem)
-	{
-		//Set internal status variables and marker files before actually starting the logout process
-		gLogoutInProgress = TRUE;
-		if (!mSecondInstance)
-		{
-			mLogoutMarkerFileName = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,LOGOUT_MARKER_FILE_NAME);
-
-			mLogoutMarkerFile.open(mLogoutMarkerFileName, LL_APR_WB);
-			if (mLogoutMarkerFile.getFileHandle())
-			{
-				LL_INFOS("MarkerFile") << "Created logout marker file '"<< mLogoutMarkerFileName << "' " << LL_ENDL;
-				recordMarkerVersion(mLogoutMarkerFile);
-			}
-			else
-			{
-				LL_WARNS("MarkerFile") << "Cannot create logout marker file " << mLogoutMarkerFileName << LL_ENDL;
-			}
-		}
-		else
-		{
-			LL_INFOS("MarkerFile") << "Did not logout marker file because this is a second instance" << LL_ENDL;
-		}
-
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_LogoutRequest);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		gAgent.sendReliableMessage();
-
-		gLogoutTimer.reset();
-		gLogoutMaxTime = LOGOUT_REQUEST_TIME;
-		mLogoutRequestSent = TRUE;
-
-		if(LLVoiceClient::instanceExists())
-		{
-			LLVoiceClient::getInstance()->leaveChannel();
-		}
-	}
+    if(!mLogoutRequestSent && gMessageSystem)
+    {
+        //Set internal status variables and marker files before actually starting the logout process
+        gLogoutInProgress = TRUE;
+        if (!mSecondInstance)
+        {
+            mLogoutMarkerFileName = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,LOGOUT_MARKER_FILE_NAME);
+
+            mLogoutMarkerFile.open(mLogoutMarkerFileName, LL_APR_WB);
+            if (mLogoutMarkerFile.getFileHandle())
+            {
+                LL_INFOS("MarkerFile") << "Created logout marker file '"<< mLogoutMarkerFileName << "' " << LL_ENDL;
+                recordMarkerVersion(mLogoutMarkerFile);
+            }
+            else
+            {
+                LL_WARNS("MarkerFile") << "Cannot create logout marker file " << mLogoutMarkerFileName << LL_ENDL;
+            }
+        }
+        else
+        {
+            LL_INFOS("MarkerFile") << "Did not logout marker file because this is a second instance" << LL_ENDL;
+        }
+
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_LogoutRequest);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        gAgent.sendReliableMessage();
+
+        gLogoutTimer.reset();
+        gLogoutMaxTime = LOGOUT_REQUEST_TIME;
+        mLogoutRequestSent = TRUE;
+
+        if(LLVoiceClient::instanceExists())
+        {
+            LLVoiceClient::getInstance()->leaveChannel();
+        }
+    }
 }
 
 void LLAppViewer::updateNameLookupUrl(const LLViewerRegion * regionp)
@@ -5190,19 +5190,19 @@ void LLAppViewer::updateNameLookupUrl(const LLViewerRegion * regionp)
 
 void LLAppViewer::idleNameCache()
 {
-	// Neither old nor new name cache can function before agent has a region
-	LLViewerRegion* region = gAgent.getRegion();
+    // Neither old nor new name cache can function before agent has a region
+    LLViewerRegion* region = gAgent.getRegion();
     if (!region)
     {
         return;
     }
 
-	// deal with any queued name requests and replies.
-	gCacheName->processPending();
+    // deal with any queued name requests and replies.
+    gCacheName->processPending();
 
-	// Can't run the new cache until we have the list of capabilities
-	// for the agent region, and can therefore decide whether to use
-	// display names or fall back to the old name system.
+    // Can't run the new cache until we have the list of capabilities
+    // for the agent region, and can therefore decide whether to use
+    // display names or fall back to the old name system.
     if (!region->capabilitiesReceived())
     {
         return;
@@ -5232,143 +5232,143 @@ static LLTrace::BlockTimerStatHandle FTM_CHECK_REGION_CIRCUIT("Check Region Circ
 void LLAppViewer::idleNetwork()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_NETWORK;
-	pingMainloopTimeout("idleNetwork");
-
-	gObjectList.mNumNewObjects = 0;
-	S32 total_decoded = 0;
-
-	static const LLCachedControl<bool> speedTest(gSavedSettings, "SpeedTest");
-	if (!speedTest)
-	{
-		LL_PROFILE_ZONE_NAMED_CATEGORY_NETWORK("idle network"); //LL_RECORD_BLOCK_TIME(FTM_IDLE_NETWORK); // decode
-
-		LLTimer check_message_timer;
-		//  Read all available packets from network
-		const S64 frame_count = gFrameCount;  // U32->S64
-		F32 total_time = 0.0f;
-
-		{
-			LockMessageChecker lmc(gMessageSystem);
-			while (lmc.checkAllMessages(frame_count, gServicePump))
-			{
-				if (gDoDisconnect)
-				{
-					// We're disconnecting, don't process any more messages from the server
-					// We're usually disconnecting due to either network corruption or a
-					// server going down, so this is OK.
-					break;
-				}
-
-				total_decoded++;
-				gPacketsIn++;
-
-				if (total_decoded > MESSAGE_MAX_PER_FRAME)
-				{
-					break;
-				}
+    pingMainloopTimeout("idleNetwork");
+
+    gObjectList.mNumNewObjects = 0;
+    S32 total_decoded = 0;
+
+    static const LLCachedControl<bool> speedTest(gSavedSettings, "SpeedTest");
+    if (!speedTest)
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_NETWORK("idle network"); //LL_RECORD_BLOCK_TIME(FTM_IDLE_NETWORK); // decode
+
+        LLTimer check_message_timer;
+        //  Read all available packets from network
+        const S64 frame_count = gFrameCount;  // U32->S64
+        F32 total_time = 0.0f;
+
+        {
+            LockMessageChecker lmc(gMessageSystem);
+            while (lmc.checkAllMessages(frame_count, gServicePump))
+            {
+                if (gDoDisconnect)
+                {
+                    // We're disconnecting, don't process any more messages from the server
+                    // We're usually disconnecting due to either network corruption or a
+                    // server going down, so this is OK.
+                    break;
+                }
+
+                total_decoded++;
+                gPacketsIn++;
+
+                if (total_decoded > MESSAGE_MAX_PER_FRAME)
+                {
+                    break;
+                }
 
 #ifdef TIME_THROTTLE_MESSAGES
-				// Prevent slow packets from completely destroying the frame rate.
-				// This usually happens due to clumps of avatars taking huge amount
-				// of network processing time (which needs to be fixed, but this is
-				// a good limit anyway).
-				total_time = check_message_timer.getElapsedTimeF32();
-				if (total_time >= CheckMessagesMaxTime)
-					break;
+                // Prevent slow packets from completely destroying the frame rate.
+                // This usually happens due to clumps of avatars taking huge amount
+                // of network processing time (which needs to be fixed, but this is
+                // a good limit anyway).
+                total_time = check_message_timer.getElapsedTimeF32();
+                if (total_time >= CheckMessagesMaxTime)
+                    break;
 #endif
-			}
+            }
 
-			// Handle per-frame message system processing.
-			static LLCachedControl<F32> sAckCollectTime(gSavedSettings, "AckCollectTime", 0.1f);
-			lmc.processAcks(sAckCollectTime);
-		}
+            // Handle per-frame message system processing.
+            static LLCachedControl<F32> sAckCollectTime(gSavedSettings, "AckCollectTime", 0.1f);
+            lmc.processAcks(sAckCollectTime);
+        }
 
 #ifdef TIME_THROTTLE_MESSAGES
-		if (total_time >= CheckMessagesMaxTime)
-		{
-			// Increase CheckMessagesMaxTime so that we will eventually catch up
-			CheckMessagesMaxTime *= 1.035f; // 3.5% ~= x2 in 20 frames, ~8x in 60 frames
-		}
-		else
-		{
-			// Reset CheckMessagesMaxTime to default value
-			CheckMessagesMaxTime = CHECK_MESSAGES_DEFAULT_MAX_TIME;
-		}
+        if (total_time >= CheckMessagesMaxTime)
+        {
+            // Increase CheckMessagesMaxTime so that we will eventually catch up
+            CheckMessagesMaxTime *= 1.035f; // 3.5% ~= x2 in 20 frames, ~8x in 60 frames
+        }
+        else
+        {
+            // Reset CheckMessagesMaxTime to default value
+            CheckMessagesMaxTime = CHECK_MESSAGES_DEFAULT_MAX_TIME;
+        }
 #endif
 
 
 
-		// we want to clear the control after sending out all necessary agent updates
-		gAgent.resetControlFlags();
-
-		// Decode enqueued messages...
-		S32 remaining_possible_decodes = MESSAGE_MAX_PER_FRAME - total_decoded;
-
-		if( remaining_possible_decodes <= 0 )
-		{
-			LL_INFOS() << "Maxed out number of messages per frame at " << MESSAGE_MAX_PER_FRAME << LL_ENDL;
-		}
-
-		if (gPrintMessagesThisFrame)
-		{
-			LL_INFOS() << "Decoded " << total_decoded << " msgs this frame!" << LL_ENDL;
-			gPrintMessagesThisFrame = FALSE;
-		}
-	}
-	add(LLStatViewer::NUM_NEW_OBJECTS, gObjectList.mNumNewObjects);
-
-	// Retransmit unacknowledged packets.
-	gXferManager->retransmitUnackedPackets();
-	gAssetStorage->checkForTimeouts();
-	gViewerThrottle.updateDynamicThrottle();
-
-	// Check that the circuit between the viewer and the agent's current
-	// region is still alive
-	LLViewerRegion *agent_region = gAgent.getRegion();
-	if (agent_region && (LLStartUp::getStartupState()==STATE_STARTED))
-	{
-		LLUUID this_region_id = agent_region->getRegionID();
-		bool this_region_alive = agent_region->isAlive();
-		if ((mAgentRegionLastAlive && !this_region_alive) // newly dead
-		    && (mAgentRegionLastID == this_region_id)) // same region
-		{
-			forceDisconnect(LLTrans::getString("AgentLostConnection"));
-		}
-		mAgentRegionLastID = this_region_id;
-		mAgentRegionLastAlive = this_region_alive;
-	}
+        // we want to clear the control after sending out all necessary agent updates
+        gAgent.resetControlFlags();
+
+        // Decode enqueued messages...
+        S32 remaining_possible_decodes = MESSAGE_MAX_PER_FRAME - total_decoded;
+
+        if( remaining_possible_decodes <= 0 )
+        {
+            LL_INFOS() << "Maxed out number of messages per frame at " << MESSAGE_MAX_PER_FRAME << LL_ENDL;
+        }
+
+        if (gPrintMessagesThisFrame)
+        {
+            LL_INFOS() << "Decoded " << total_decoded << " msgs this frame!" << LL_ENDL;
+            gPrintMessagesThisFrame = FALSE;
+        }
+    }
+    add(LLStatViewer::NUM_NEW_OBJECTS, gObjectList.mNumNewObjects);
+
+    // Retransmit unacknowledged packets.
+    gXferManager->retransmitUnackedPackets();
+    gAssetStorage->checkForTimeouts();
+    gViewerThrottle.updateDynamicThrottle();
+
+    // Check that the circuit between the viewer and the agent's current
+    // region is still alive
+    LLViewerRegion *agent_region = gAgent.getRegion();
+    if (agent_region && (LLStartUp::getStartupState()==STATE_STARTED))
+    {
+        LLUUID this_region_id = agent_region->getRegionID();
+        bool this_region_alive = agent_region->isAlive();
+        if ((mAgentRegionLastAlive && !this_region_alive) // newly dead
+            && (mAgentRegionLastID == this_region_id)) // same region
+        {
+            forceDisconnect(LLTrans::getString("AgentLostConnection"));
+        }
+        mAgentRegionLastID = this_region_id;
+        mAgentRegionLastAlive = this_region_alive;
+    }
 }
 
 void LLAppViewer::disconnectViewer()
 {
-	if (gDisconnected)
-	{
-		return;
-	}
-	//
-	// Cleanup after quitting.
-	//
-	// Save snapshot for next time, if we made it through initialization
-
-	LL_INFOS() << "Disconnecting viewer!" << LL_ENDL;
-
-	// Dump our frame statistics
-
-	// Remember if we were flying
-	gSavedSettings.setBOOL("FlyingAtExit", gAgent.getFlying() );
-
-	// Un-minimize all windows so they don't get saved minimized
-	if (gFloaterView)
-	{
-		gFloaterView->restoreAll();
-	}
-
-	if (LLSelectMgr::instanceExists())
-	{
-		LLSelectMgr::getInstance()->deselectAll();
-	}
-
-	// save inventory if appropriate
+    if (gDisconnected)
+    {
+        return;
+    }
+    //
+    // Cleanup after quitting.
+    //
+    // Save snapshot for next time, if we made it through initialization
+
+    LL_INFOS() << "Disconnecting viewer!" << LL_ENDL;
+
+    // Dump our frame statistics
+
+    // Remember if we were flying
+    gSavedSettings.setBOOL("FlyingAtExit", gAgent.getFlying() );
+
+    // Un-minimize all windows so they don't get saved minimized
+    if (gFloaterView)
+    {
+        gFloaterView->restoreAll();
+    }
+
+    if (LLSelectMgr::instanceExists())
+    {
+        LLSelectMgr::getInstance()->deselectAll();
+    }
+
+    // save inventory if appropriate
     if (gInventory.isInventoryUsable()
         && gAgent.getID().notNull()) // Shouldn't be null at this stage
     {
@@ -5383,53 +5383,53 @@ void LLAppViewer::disconnectViewer()
         }
     }
 
-	saveNameCache();
-	if (LLExperienceCache::instanceExists())
-	{
-		// TODO: LLExperienceCache::cleanup() logic should be moved to
-		// cleanupSingleton().
-		LLExperienceCache::instance().cleanup();
-	}
+    saveNameCache();
+    if (LLExperienceCache::instanceExists())
+    {
+        // TODO: LLExperienceCache::cleanup() logic should be moved to
+        // cleanupSingleton().
+        LLExperienceCache::instance().cleanup();
+    }
 
-	// close inventory interface, close all windows
-	LLSidepanelInventory::cleanup();
+    // close inventory interface, close all windows
+    LLSidepanelInventory::cleanup();
 
 // [SL:KB] - Patch: Appearance-Misc | Checked: 2013-02-12 (Catznip-3.4)
-	// Destroying all objects below will trigger attachment detaching code and attempt to remove the COF links for them
-	LLAppearanceMgr::instance().setAttachmentInvLinkEnable(false);
+    // Destroying all objects below will trigger attachment detaching code and attempt to remove the COF links for them
+    LLAppearanceMgr::instance().setAttachmentInvLinkEnable(false);
 // [/SL:KB]
 
 // [RLVa:KB] - Checked: RLVa-2.3 (Housekeeping)
-	SUBSYSTEM_CLEANUP(RlvHandler);
+    SUBSYSTEM_CLEANUP(RlvHandler);
 // [/RLVa:KB]
 
-	gAgentWearables.cleanup();
-	gAgentCamera.cleanup();
-	// Also writes cached agent settings to gSavedSettings
-	gAgent.cleanup();
+    gAgentWearables.cleanup();
+    gAgentCamera.cleanup();
+    // Also writes cached agent settings to gSavedSettings
+    gAgent.cleanup();
 
-	// This is where we used to call gObjectList.destroy() and then delete gWorldp.
-	// Now we just ask the LLWorld singleton to cleanly shut down.
-	if(LLWorld::instanceExists())
-	{
-		LLWorld::getInstance()->resetClass();
-	}
-	LLVOCache::deleteSingleton();
+    // This is where we used to call gObjectList.destroy() and then delete gWorldp.
+    // Now we just ask the LLWorld singleton to cleanly shut down.
+    if(LLWorld::instanceExists())
+    {
+        LLWorld::getInstance()->resetClass();
+    }
+    LLVOCache::deleteSingleton();
 
-	// call all self-registered classes
-	LLDestroyClassList::instance().fireCallbacks();
+    // call all self-registered classes
+    LLDestroyClassList::instance().fireCallbacks();
 
-	cleanup_xfer_manager();
-	gDisconnected = TRUE;
+    cleanup_xfer_manager();
+    gDisconnected = TRUE;
 
-	// Pass the connection state to LLUrlEntryParcel not to attempt
-	// parcel info requests while disconnected.
-	LLUrlEntryParcel::setDisconnected(gDisconnected);
+    // Pass the connection state to LLUrlEntryParcel not to attempt
+    // parcel info requests while disconnected.
+    LLUrlEntryParcel::setDisconnected(gDisconnected);
 }
 
 void LLAppViewer::forceErrorLLError()
 {
-   	LL_ERRS() << "This is a deliberate llerror" << LL_ENDL;
+    LL_ERRS() << "This is a deliberate llerror" << LL_ENDL;
 }
 
 void LLAppViewer::forceErrorLLErrorMsg()
@@ -5442,7 +5442,7 @@ void LLAppViewer::forceErrorLLErrorMsg()
 
 void LLAppViewer::forceErrorBreakpoint()
 {
-   	LL_WARNS() << "Forcing a deliberate breakpoint" << LL_ENDL;
+    LL_WARNS() << "Forcing a deliberate breakpoint" << LL_ENDL;
 #ifdef LL_WINDOWS
     DebugBreak();
 #else
@@ -5453,7 +5453,7 @@ void LLAppViewer::forceErrorBreakpoint()
 
 void LLAppViewer::forceErrorBadMemoryAccess()
 {
-   	LL_WARNS() << "Forcing a deliberate bad memory access" << LL_ENDL;
+    LL_WARNS() << "Forcing a deliberate bad memory access" << LL_ENDL;
     S32* crash = NULL;
     *crash = 0xDEADBEEF;
     return;
@@ -5461,7 +5461,7 @@ void LLAppViewer::forceErrorBadMemoryAccess()
 
 void LLAppViewer::forceErrorInfiniteLoop()
 {
-   	LL_WARNS() << "Forcing a deliberate infinite loop" << LL_ENDL;
+    LL_WARNS() << "Forcing a deliberate infinite loop" << LL_ENDL;
     // Loop is intentionally complicated to fool basic loop detection
     LLTimer timer_total;
     LLTimer timer_expiry;
@@ -5480,7 +5480,7 @@ void LLAppViewer::forceErrorInfiniteLoop()
 
 void LLAppViewer::forceErrorSoftwareException()
 {
-   	LL_WARNS() << "Forcing a deliberate exception" << LL_ENDL;
+    LL_WARNS() << "Forcing a deliberate exception" << LL_ENDL;
     LLTHROW(LLException("User selected Force Software Exception"));
 }
 
@@ -5493,8 +5493,8 @@ void LLAppViewer::forceErrorOSSpecificException()
 
 void LLAppViewer::forceErrorDriverCrash()
 {
-   	LL_WARNS() << "Forcing a deliberate driver crash" << LL_ENDL;
-	glDeleteTextures(1, NULL);
+    LL_WARNS() << "Forcing a deliberate driver crash" << LL_ENDL;
+    glDeleteTextures(1, NULL);
 }
 
 void LLAppViewer::forceErrorCoroutineCrash()
@@ -5526,132 +5526,132 @@ void LLAppViewer::forceErrorThreadCrash()
 
 void LLAppViewer::initMainloopTimeout(const std::string& state, F32 secs)
 {
-	if(!mMainloopTimeout)
-	{
-		mMainloopTimeout = new LLWatchdogTimeout();
-		resumeMainloopTimeout(state, secs);
-	}
+    if(!mMainloopTimeout)
+    {
+        mMainloopTimeout = new LLWatchdogTimeout();
+        resumeMainloopTimeout(state, secs);
+    }
 }
 
 void LLAppViewer::destroyMainloopTimeout()
 {
-	if(mMainloopTimeout)
-	{
-		delete mMainloopTimeout;
-		mMainloopTimeout = NULL;
-	}
+    if(mMainloopTimeout)
+    {
+        delete mMainloopTimeout;
+        mMainloopTimeout = NULL;
+    }
 }
 
 void LLAppViewer::resumeMainloopTimeout(const std::string& state, F32 secs)
 {
-	if(mMainloopTimeout)
-	{
-		if(secs < 0.0f)
-		{
-			static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60);
-			secs = mainloop_timeout;
-		}
-
-		mMainloopTimeout->setTimeout(secs);
-		mMainloopTimeout->start(state);
-	}
+    if(mMainloopTimeout)
+    {
+        if(secs < 0.0f)
+        {
+            static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60);
+            secs = mainloop_timeout;
+        }
+
+        mMainloopTimeout->setTimeout(secs);
+        mMainloopTimeout->start(state);
+    }
 }
 
 void LLAppViewer::pauseMainloopTimeout()
 {
-	if(mMainloopTimeout)
-	{
-		mMainloopTimeout->stop();
-	}
+    if(mMainloopTimeout)
+    {
+        mMainloopTimeout->stop();
+    }
 }
 
 void LLAppViewer::pingMainloopTimeout(const std::string& state, F32 secs)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_APP;
 
-	if(mMainloopTimeout)
-	{
-		if(secs < 0.0f)
-		{
-			static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60);
-			secs = mainloop_timeout;
-		}
-
-		mMainloopTimeout->setTimeout(secs);
-		mMainloopTimeout->ping(state);
-	}
+    if(mMainloopTimeout)
+    {
+        if(secs < 0.0f)
+        {
+            static LLCachedControl<F32> mainloop_timeout(gSavedSettings, "MainloopTimeoutDefault", 60);
+            secs = mainloop_timeout;
+        }
+
+        mMainloopTimeout->setTimeout(secs);
+        mMainloopTimeout->ping(state);
+    }
 }
 
 void LLAppViewer::handleLoginComplete()
 {
-	gLoggedInTime.start();
-	initMainloopTimeout("Mainloop Init");
-
-	// Store some data to DebugInfo in case of a freeze.
-	gDebugInfo["ClientInfo"]["Name"] = LLVersionInfo::instance().getChannel();
-
-	gDebugInfo["ClientInfo"]["MajorVersion"] = LLVersionInfo::instance().getMajor();
-	gDebugInfo["ClientInfo"]["MinorVersion"] = LLVersionInfo::instance().getMinor();
-	gDebugInfo["ClientInfo"]["PatchVersion"] = LLVersionInfo::instance().getPatch();
-	gDebugInfo["ClientInfo"]["BuildVersion"] = std::to_string(LLVersionInfo::instance().getBuild());
-
-	LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
-	if ( parcel && parcel->getMusicURL()[0])
-	{
-		gDebugInfo["ParcelMusicURL"] = parcel->getMusicURL();
-	}
-	if ( parcel && parcel->getMediaURL()[0])
-	{
-		gDebugInfo["ParcelMediaURL"] = parcel->getMediaURL();
-	}
-
-	gDebugInfo["SettingsFilename"] = gSavedSettings.getString("ClientSettingsFile");
-	gDebugInfo["CAFilename"] = gDirUtilp->getCAFile();
-	gDebugInfo["ViewerExePath"] = gDirUtilp->getExecutablePathAndName();
-	gDebugInfo["CurrentPath"] = gDirUtilp->getCurPath();
-
-	if(gAgent.getRegion())
-	{
-		gDebugInfo["CurrentSimHost"] = gAgent.getRegion()->getSimHostName();
-		gDebugInfo["CurrentRegion"] = gAgent.getRegion()->getName();
-	}
-
-	if(LLAppViewer::instance()->mMainloopTimeout)
-	{
-		gDebugInfo["MainloopTimeoutState"] = LLAppViewer::instance()->mMainloopTimeout->getState();
-	}
-	
-	if (gAgentAvatarp)
-	{
-		gWindowTitle.append(" - ").append(gAgentAvatarp->getFullname());
-		gViewerWindow->getWindow()->setTitle(gWindowTitle);
-	}
-
-	mOnLoginCompleted();
-	mOnLoginCompleted.disconnect_all_slots(); // No longer needed
+    gLoggedInTime.start();
+    initMainloopTimeout("Mainloop Init");
+
+    // Store some data to DebugInfo in case of a freeze.
+    gDebugInfo["ClientInfo"]["Name"] = LLVersionInfo::instance().getChannel();
+
+    gDebugInfo["ClientInfo"]["MajorVersion"] = LLVersionInfo::instance().getMajor();
+    gDebugInfo["ClientInfo"]["MinorVersion"] = LLVersionInfo::instance().getMinor();
+    gDebugInfo["ClientInfo"]["PatchVersion"] = LLVersionInfo::instance().getPatch();
+    gDebugInfo["ClientInfo"]["BuildVersion"] = std::to_string(LLVersionInfo::instance().getBuild());
+
+    LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
+    if ( parcel && parcel->getMusicURL()[0])
+    {
+        gDebugInfo["ParcelMusicURL"] = parcel->getMusicURL();
+    }
+    if ( parcel && parcel->getMediaURL()[0])
+    {
+        gDebugInfo["ParcelMediaURL"] = parcel->getMediaURL();
+    }
+
+    gDebugInfo["SettingsFilename"] = gSavedSettings.getString("ClientSettingsFile");
+    gDebugInfo["CAFilename"] = gDirUtilp->getCAFile();
+    gDebugInfo["ViewerExePath"] = gDirUtilp->getExecutablePathAndName();
+    gDebugInfo["CurrentPath"] = gDirUtilp->getCurPath();
+
+    if(gAgent.getRegion())
+    {
+        gDebugInfo["CurrentSimHost"] = gAgent.getRegion()->getSimHostName();
+        gDebugInfo["CurrentRegion"] = gAgent.getRegion()->getName();
+    }
+
+    if(LLAppViewer::instance()->mMainloopTimeout)
+    {
+        gDebugInfo["MainloopTimeoutState"] = LLAppViewer::instance()->mMainloopTimeout->getState();
+    }
+
+    if (gAgentAvatarp)
+    {
+        gWindowTitle.append(" - ").append(gAgentAvatarp->getFullname());
+        gViewerWindow->getWindow()->setTitle(gWindowTitle);
+    }
+
+    mOnLoginCompleted();
+    mOnLoginCompleted.disconnect_all_slots(); // No longer needed
 
 // [SL:KB] - Patch: Build-AssetRecovery | Checked: 2011-11-24 (Catznip-3.2)
-	LLAssetRecoverQueue::recoverIfNeeded();
+    LLAssetRecoverQueue::recoverIfNeeded();
 // [/SL:KB]
 
-	writeDebugInfo();
+    writeDebugInfo();
 
-	// we logged in successfully, so save settings on logout
-	LL_INFOS() << "Login successful, per account settings will be saved on log out." << LL_ENDL;
-	mSavePerAccountSettings=true;
+    // we logged in successfully, so save settings on logout
+    LL_INFOS() << "Login successful, per account settings will be saved on log out." << LL_ENDL;
+    mSavePerAccountSettings=true;
 }
 
 //virtual
 void LLAppViewer::setMasterSystemAudioMute(bool mute)
 {
-	gSavedSettings.setBOOL("MuteAudio", mute);
+    gSavedSettings.setBOOL("MuteAudio", mute);
 }
 
 //virtual
 bool LLAppViewer::getMasterSystemAudioMute()
 {
-	static const LLCachedControl<bool> mute_audio(gSavedSettings, "MuteAudio");
-	return mute_audio;
+    static const LLCachedControl<bool> mute_audio(gSavedSettings, "MuteAudio");
+    return mute_audio;
 }
 
 //----------------------------------------------------------------------------
@@ -5667,10 +5667,10 @@ bool LLAppViewer::getMasterSystemAudioMute()
  */
 void LLAppViewer::metricsUpdateRegion(U64 region_handle)
 {
-	if (0 != region_handle)
-	{
-		LLViewerAssetStatsFF::set_region(region_handle);
-	}
+    if (0 != region_handle)
+    {
+        LLViewerAssetStatsFF::set_region(region_handle);
+    }
 }
 
 /**
@@ -5679,35 +5679,35 @@ void LLAppViewer::metricsUpdateRegion(U64 region_handle)
  */
 void LLAppViewer::metricsSend(bool enable_reporting)
 {
-	if (! gViewerAssetStats)
-		return;
+    if (! gViewerAssetStats)
+        return;
 
-	if (LLAppViewer::sTextureFetch)
-	{
-		LLViewerRegion * regionp = gAgent.getRegion();
+    if (LLAppViewer::sTextureFetch)
+    {
+        LLViewerRegion * regionp = gAgent.getRegion();
 
-		if (enable_reporting && regionp)
-		{
-			std::string	caps_url = regionp->getCapability("ViewerMetrics");
+        if (enable_reporting && regionp)
+        {
+            std::string caps_url = regionp->getCapability("ViewerMetrics");
 
             LLSD sd = gViewerAssetStats->asLLSD(true);
 
-			// Send a report request into 'thread1' to get the rest of the data
-			// and provide some additional parameters while here.
-			LLAppViewer::sTextureFetch->commandSendMetrics(caps_url,
-														   gAgentSessionID,
-														   gAgentID,
-														   sd);
-		}
-		else
-		{
-			LLAppViewer::sTextureFetch->commandDataBreak();
-		}
-	}
-
-	// Reset even if we can't report.  Rather than gather up a huge chunk of
-	// data, we'll keep to our sampling interval and retain the data
-	// resolution in time.
-	gViewerAssetStats->restart();
+            // Send a report request into 'thread1' to get the rest of the data
+            // and provide some additional parameters while here.
+            LLAppViewer::sTextureFetch->commandSendMetrics(caps_url,
+                                                           gAgentSessionID,
+                                                           gAgentID,
+                                                           sd);
+        }
+        else
+        {
+            LLAppViewer::sTextureFetch->commandDataBreak();
+        }
+    }
+
+    // Reset even if we can't report.  Rather than gather up a huge chunk of
+    // data, we'll keep to our sampling interval and retain the data
+    // resolution in time.
+    gViewerAssetStats->restart();
 }
 
diff --git a/indra/newview/llattachmentsmgr.cpp b/indra/newview/llattachmentsmgr.cpp
index c921c68f040846c9d9376b044310a2f1fe46b325..db5838afce46c1f2910bbe0205972914546b7069 100644
--- a/indra/newview/llattachmentsmgr.cpp
+++ b/indra/newview/llattachmentsmgr.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llattachmentsmgr.cpp
  * @brief Manager for initiating attachments changes on the viewer
  *
  * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -66,7 +66,7 @@ void LLAttachmentsMgr::addAttachmentRequest(const LLUUID& item_id,
                                             const BOOL add, const BOOL fRlvForce /*=FALSE*/)
 // [/RLVa:KB]
 {
-	LLViewerInventoryItem *item = gInventory.getItem(item_id);
+    LLViewerInventoryItem *item = gInventory.getItem(item_id);
 
     if (mAttachmentRequests.wasRequestedRecently(item_id))
     {
@@ -75,84 +75,84 @@ void LLAttachmentsMgr::addAttachmentRequest(const LLUUID& item_id,
         return;
     }
 
-	LL_DEBUGS("Avatar") << "ATT adding attachment to mPendingAttachments "
-						<< (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
+    LL_DEBUGS("Avatar") << "ATT adding attachment to mPendingAttachments "
+                        << (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
 
-	AttachmentsInfo attachment;
-	attachment.mItemID = item_id;
-	attachment.mAttachmentPt = attachment_pt;
-	attachment.mAdd = add;
+    AttachmentsInfo attachment;
+    attachment.mItemID = item_id;
+    attachment.mAttachmentPt = attachment_pt;
+    attachment.mAdd = add;
 
 // [RLVa:KB] - Checked: 2010-09-23 (RLVa-1.2.1)
-	if ( (RlvActions::isRlvEnabled()) && (!fRlvForce) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) && (gAgentWearables.areInitialAttachmentsRequested()) )
-	{
-		const LLInventoryItem* pItem = gInventory.getItem(item_id); 
-		if (!pItem)
-			return;
-
-		LLViewerJointAttachment* pAttachPt = NULL;
-		ERlvWearMask eWearMask = gRlvAttachmentLocks.canAttach(pItem, &pAttachPt);
-		if ( ((add) && ((RLV_WEAR_ADD & eWearMask) == 0)) || ((!add) && ((RLV_WEAR_REPLACE & eWearMask) == 0)) )
-			return;
-
-		if ( (0 == attachment_pt) && (NULL != pAttachPt) )
-			attachment.mAttachmentPt = RlvAttachPtLookup::getAttachPointIndex(pAttachPt);
-		RlvAttachmentLockWatchdog::instance().onWearAttachment(pItem, (add) ? RLV_WEAR_ADD : RLV_WEAR_REPLACE);
-		attachment.mAdd = true;
-	}
+    if ( (RlvActions::isRlvEnabled()) && (!fRlvForce) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) && (gAgentWearables.areInitialAttachmentsRequested()) )
+    {
+        const LLInventoryItem* pItem = gInventory.getItem(item_id);
+        if (!pItem)
+            return;
+
+        LLViewerJointAttachment* pAttachPt = NULL;
+        ERlvWearMask eWearMask = gRlvAttachmentLocks.canAttach(pItem, &pAttachPt);
+        if ( ((add) && ((RLV_WEAR_ADD & eWearMask) == 0)) || ((!add) && ((RLV_WEAR_REPLACE & eWearMask) == 0)) )
+            return;
+
+        if ( (0 == attachment_pt) && (NULL != pAttachPt) )
+            attachment.mAttachmentPt = RlvAttachPtLookup::getAttachPointIndex(pAttachPt);
+        RlvAttachmentLockWatchdog::instance().onWearAttachment(pItem, (add) ? RLV_WEAR_ADD : RLV_WEAR_REPLACE);
+        attachment.mAdd = true;
+    }
 // [/RLVa:KB]
 
-	mPendingAttachments.push_back(attachment);
+    mPendingAttachments.push_back(attachment);
 
     mAttachmentRequests.addTime(item_id);
 }
 
 void LLAttachmentsMgr::onAttachmentRequested(const LLUUID& item_id)
 {
-	LLViewerInventoryItem *item = gInventory.getItem(item_id);
-	LL_DEBUGS("Avatar") << "ATT attachment was requested "
-						<< (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
+    LLViewerInventoryItem *item = gInventory.getItem(item_id);
+    LL_DEBUGS("Avatar") << "ATT attachment was requested "
+                        << (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
     mAttachmentRequests.addTime(item_id);
 }
 
 // static
 void LLAttachmentsMgr::onIdle(void *)
 {
-	LLAttachmentsMgr::instance().onIdle();
+    LLAttachmentsMgr::instance().onIdle();
 }
 
 void LLAttachmentsMgr::onIdle()
 {
-	// Make sure we got a region before trying anything else
-	if( !gAgent.getRegion() )
-	{
-		return;
-	}
+    // Make sure we got a region before trying anything else
+    if( !gAgent.getRegion() )
+    {
+        return;
+    }
+
+    if (LLApp::isExiting())
+    {
+        return;
+    }
 
-	if (LLApp::isExiting())
-	{
-		return;
-	}
+    requestPendingAttachments();
 
-	requestPendingAttachments();
+    linkRecentlyArrivedAttachments();
 
-	linkRecentlyArrivedAttachments();
+    expireOldAttachmentRequests();
 
-	expireOldAttachmentRequests();
+    expireOldDetachRequests();
 
-	expireOldDetachRequests();
+    checkInvalidCOFLinks();
 
-	checkInvalidCOFLinks();
-	
-	spamStatusInfo();
+    spamStatusInfo();
 }
 
 void LLAttachmentsMgr::requestPendingAttachments()
 {
-	if (mPendingAttachments.size())
-	{
-		requestAttachments(mPendingAttachments);
-	}
+    if (mPendingAttachments.size())
+    {
+        requestAttachments(mPendingAttachments);
+    }
 }
 
 // Send request(s) for a group of attachments. As coded, this can
@@ -161,41 +161,41 @@ void LLAttachmentsMgr::requestPendingAttachments()
 // limit should not be hit in practice.
 void LLAttachmentsMgr::requestAttachments(attachments_vec_t& attachment_requests)
 {
-	// Make sure we got a region before trying anything else
-	if( !gAgent.getRegion() )
-	{
-		return;
-	}
+    // Make sure we got a region before trying anything else
+    if( !gAgent.getRegion() )
+    {
+        return;
+    }
 
     // For unknown reasons, requesting many attachments at once causes
     // frequent server-side failures. Here we're limiting the number
     // of attachments requested per idle loop.
     //const S32 max_objects_per_request = 5;
     const S32 max_objects_per_request = 1;
-	S32 obj_count = llmin((S32)attachment_requests.size(),max_objects_per_request);
-	if (obj_count == 0)
-	{
-		return;
-	}
-
-	// Limit number of packets to send
-	const S32 MAX_PACKETS_TO_SEND = 10;
-	const S32 OBJECTS_PER_PACKET = 4;
-	const S32 MAX_OBJECTS_TO_SEND = MAX_PACKETS_TO_SEND * OBJECTS_PER_PACKET;
-	if( obj_count > MAX_OBJECTS_TO_SEND )
-	{
+    S32 obj_count = llmin((S32)attachment_requests.size(),max_objects_per_request);
+    if (obj_count == 0)
+    {
+        return;
+    }
+
+    // Limit number of packets to send
+    const S32 MAX_PACKETS_TO_SEND = 10;
+    const S32 OBJECTS_PER_PACKET = 4;
+    const S32 MAX_OBJECTS_TO_SEND = MAX_PACKETS_TO_SEND * OBJECTS_PER_PACKET;
+    if( obj_count > MAX_OBJECTS_TO_SEND )
+    {
         LL_WARNS() << "ATT Too many attachments requested: " << obj_count
                    << " exceeds limit of " << MAX_OBJECTS_TO_SEND << LL_ENDL;
 
-		obj_count = MAX_OBJECTS_TO_SEND;
-	}
+        obj_count = MAX_OBJECTS_TO_SEND;
+    }
 
-	LL_DEBUGS("Avatar") << "ATT [RezMultipleAttachmentsFromInv] attaching multiple from attachment_requests,"
-		" total obj_count " << obj_count << LL_ENDL;
+    LL_DEBUGS("Avatar") << "ATT [RezMultipleAttachmentsFromInv] attaching multiple from attachment_requests,"
+        " total obj_count " << obj_count << LL_ENDL;
 
-	LLUUID compound_msg_id;
-	compound_msg_id.generate();
-	LLMessageSystem* msg = gMessageSystem;
+    LLUUID compound_msg_id;
+    compound_msg_id.generate();
+    LLMessageSystem* msg = gMessageSystem;
 
     // by construction above, obj_count <= attachment_requests.size(), so no
     // check against attachment_requests.empty() is needed.
@@ -203,29 +203,29 @@ void LLAttachmentsMgr::requestAttachments(attachments_vec_t& attachment_requests
 
     for (S32 i=0; i<obj_count; i++)
     {
-		if( 0 == (i % OBJECTS_PER_PACKET) )
-		{
-			// Start a new message chunk
-			msg->newMessageFast(_PREHASH_RezMultipleAttachmentsFromInv);
-			msg->nextBlockFast(_PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-			msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-			msg->nextBlockFast(_PREHASH_HeaderData);
-			msg->addUUIDFast(_PREHASH_CompoundMsgID, compound_msg_id );
-			msg->addU8Fast(_PREHASH_TotalObjects, obj_count );
-			msg->addBOOLFast(_PREHASH_FirstDetachAll, false );
-		}
-
-		const AttachmentsInfo& attachment = attachment_requests.front();
-		LLViewerInventoryItem* item = gInventory.getItem(attachment.mItemID);
-		if (item)
+        if( 0 == (i % OBJECTS_PER_PACKET) )
+        {
+            // Start a new message chunk
+            msg->newMessageFast(_PREHASH_RezMultipleAttachmentsFromInv);
+            msg->nextBlockFast(_PREHASH_AgentData);
+            msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+            msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+            msg->nextBlockFast(_PREHASH_HeaderData);
+            msg->addUUIDFast(_PREHASH_CompoundMsgID, compound_msg_id );
+            msg->addU8Fast(_PREHASH_TotalObjects, obj_count );
+            msg->addBOOLFast(_PREHASH_FirstDetachAll, false );
+        }
+
+        const AttachmentsInfo& attachment = attachment_requests.front();
+        LLViewerInventoryItem* item = gInventory.getItem(attachment.mItemID);
+        if (item)
         {
             LL_DEBUGS("Avatar") << "ATT requesting from attachment_requests " << item->getName()
                                 << " " << item->getLinkedUUID() << LL_ENDL;
             S32 attachment_pt = attachment.mAttachmentPt;
-            if (attachment.mAdd) 
+            if (attachment.mAdd)
                 attachment_pt |= ATTACHMENT_ADD;
-            
+
             msg->nextBlockFast(_PREHASH_ObjectData );
             msg->addUUIDFast(_PREHASH_ItemID, item->getLinkedUUID());
             msg->addUUIDFast(_PREHASH_OwnerID, item->getPermissions().getOwner());
@@ -235,17 +235,17 @@ void LLAttachmentsMgr::requestAttachments(attachments_vec_t& attachment_requests
             msg->addStringFast(_PREHASH_Description, item->getDescription());
         }
         else
-		{
-			LL_WARNS("Avatar") << "ATT Attempted to add non-existent item ID:" << attachment.mItemID << LL_ENDL;
-		}
-
-		if( (i+1 == obj_count) || ((OBJECTS_PER_PACKET-1) == (i % OBJECTS_PER_PACKET)) )
-		{
-			// End of message chunk
-			msg->sendReliable( gAgent.getRegion()->getHost() );
-		}
+        {
+            LL_WARNS("Avatar") << "ATT Attempted to add non-existent item ID:" << attachment.mItemID << LL_ENDL;
+        }
+
+        if( (i+1 == obj_count) || ((OBJECTS_PER_PACKET-1) == (i % OBJECTS_PER_PACKET)) )
+        {
+            // End of message chunk
+            msg->sendReliable( gAgent.getRegion()->getHost() );
+        }
         attachment_requests.pop_front();
-	}
+    }
 }
 
 void LLAttachmentsMgr::linkRecentlyArrivedAttachments()
@@ -319,14 +319,14 @@ void LLAttachmentsMgr::LLItemRequestTimes::addTime(const LLUUID& inv_item_id)
 {
     LLInventoryItem *item = gInventory.getItem(inv_item_id);
     LL_DEBUGS("Avatar") << "ATT " << mOpName << " adding request time " << (item ? item->getName() : "UNKNOWN") << " " << inv_item_id << LL_ENDL;
-	LLTimer current_time;
-	(*this)[inv_item_id] = current_time;
+    LLTimer current_time;
+    (*this)[inv_item_id] = current_time;
 }
 
 void LLAttachmentsMgr::LLItemRequestTimes::removeTime(const LLUUID& inv_item_id)
 {
     LLInventoryItem *item = gInventory.getItem(inv_item_id);
-	S32 remove_count = (*this).erase(inv_item_id);
+    S32 remove_count = (*this).erase(inv_item_id);
     if (remove_count)
     {
         LL_DEBUGS("Avatar") << "ATT " << mOpName << " removing request time "
@@ -336,9 +336,9 @@ void LLAttachmentsMgr::LLItemRequestTimes::removeTime(const LLUUID& inv_item_id)
 
 BOOL LLAttachmentsMgr::LLItemRequestTimes::getTime(const LLUUID& inv_item_id, LLTimer& timer) const
 {
-	std::map<LLUUID,LLTimer>::const_iterator it = (*this).find(inv_item_id);
-	if (it != (*this).end())
-	{
+    std::map<LLUUID,LLTimer>::const_iterator it = (*this).find(inv_item_id);
+    if (it != (*this).end())
+    {
         timer = it->second;
         return TRUE;
     }
@@ -350,7 +350,7 @@ BOOL LLAttachmentsMgr::LLItemRequestTimes::wasRequestedRecently(const LLUUID& in
     LLTimer request_time;
     if (getTime(inv_item_id, request_time))
     {
-		F32 request_time_elapsed = request_time.getElapsedTimeF32();
+        F32 request_time_elapsed = request_time.getElapsedTimeF32();
         return request_time_elapsed < mTimeout;
     }
     else
@@ -370,7 +370,7 @@ BOOL LLAttachmentsMgr::LLItemRequestTimes::wasRequestedRecently(const LLUUID& in
 // requestServerAppearanceUpdate() calls may occur.
 void LLAttachmentsMgr::expireOldAttachmentRequests()
 {
-	for (std::map<LLUUID,LLTimer>::iterator it = mAttachmentRequests.begin();
+    for (std::map<LLUUID,LLTimer>::iterator it = mAttachmentRequests.begin();
          it != mAttachmentRequests.end(); )
     {
         std::map<LLUUID,LLTimer>::iterator curr_it = it;
@@ -388,7 +388,7 @@ void LLAttachmentsMgr::expireOldAttachmentRequests()
 
 void LLAttachmentsMgr::expireOldDetachRequests()
 {
-	for (std::map<LLUUID,LLTimer>::iterator it = mDetachRequests.begin();
+    for (std::map<LLUUID,LLTimer>::iterator it = mDetachRequests.begin();
          it != mDetachRequests.end(); )
     {
         std::map<LLUUID,LLTimer>::iterator curr_it = it;
@@ -495,55 +495,55 @@ bool LLAttachmentsMgr::isAttachmentStateComplete() const
 //
 void LLAttachmentsMgr::checkInvalidCOFLinks()
 {
-	if (!gInventory.isInventoryUsable())
-	{
-		return;
-	}
-	LLInventoryModel::cat_array_t cat_array;
-	LLInventoryModel::item_array_t item_array;
-	gInventory.collectDescendents(LLAppearanceMgr::instance().getCOF(),
-								  cat_array,item_array,LLInventoryModel::EXCLUDE_TRASH);
-	for (S32 i=0; i<item_array.size(); i++)
-	{
-		const LLViewerInventoryItem* inv_item = item_array.at(i).get();
-		const LLUUID& item_id = inv_item->getLinkedUUID();
-		if (inv_item->getType() == LLAssetType::AT_OBJECT)
-		{
-			LLTimer timer;
-			bool is_flagged_questionable = mQuestionableCOFLinks.getTime(item_id,timer);
-			bool is_wearing_attachment = isAgentAvatarValid() && gAgentAvatarp->isWearingAttachment(item_id);
-			if (is_wearing_attachment && is_flagged_questionable)
-			{
-				LL_DEBUGS("Avatar") << "ATT was flagged questionable but is now " 
-									<< (is_wearing_attachment ? "attached " : "") 
-									<<"removing flag after "
-									<< timer.getElapsedTimeF32() << " item "
-									<< inv_item->getName() << " id " << item_id << LL_ENDL;
-				mQuestionableCOFLinks.removeTime(item_id);
-			}
-		}
-	}
-
-	for(LLItemRequestTimes::iterator it = mQuestionableCOFLinks.begin();
-		it != mQuestionableCOFLinks.end(); )
-	{
-		LLItemRequestTimes::iterator curr_it = it;
-		++it;
-		const LLUUID& item_id = curr_it->first;
-		LLViewerInventoryItem *inv_item = gInventory.getItem(item_id);
-		if (curr_it->second.getElapsedTimeF32() > MAX_BAD_COF_TIME)
-		{
-			if (LLAppearanceMgr::instance().isLinkedInCOF(item_id))
-			{
-				LL_DEBUGS("Avatar") << "ATT Linked in COF but not attached or requested, deleting link after "
-									<< curr_it->second.getElapsedTimeF32() << " seconds for " 
-									<< (inv_item ? inv_item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
-				LLAppearanceMgr::instance().removeCOFItemLinks(item_id);
-			}
-			mQuestionableCOFLinks.erase(curr_it);
-			continue;
-		}
-	}
+    if (!gInventory.isInventoryUsable())
+    {
+        return;
+    }
+    LLInventoryModel::cat_array_t cat_array;
+    LLInventoryModel::item_array_t item_array;
+    gInventory.collectDescendents(LLAppearanceMgr::instance().getCOF(),
+                                  cat_array,item_array,LLInventoryModel::EXCLUDE_TRASH);
+    for (S32 i=0; i<item_array.size(); i++)
+    {
+        const LLViewerInventoryItem* inv_item = item_array.at(i).get();
+        const LLUUID& item_id = inv_item->getLinkedUUID();
+        if (inv_item->getType() == LLAssetType::AT_OBJECT)
+        {
+            LLTimer timer;
+            bool is_flagged_questionable = mQuestionableCOFLinks.getTime(item_id,timer);
+            bool is_wearing_attachment = isAgentAvatarValid() && gAgentAvatarp->isWearingAttachment(item_id);
+            if (is_wearing_attachment && is_flagged_questionable)
+            {
+                LL_DEBUGS("Avatar") << "ATT was flagged questionable but is now "
+                                    << (is_wearing_attachment ? "attached " : "")
+                                    <<"removing flag after "
+                                    << timer.getElapsedTimeF32() << " item "
+                                    << inv_item->getName() << " id " << item_id << LL_ENDL;
+                mQuestionableCOFLinks.removeTime(item_id);
+            }
+        }
+    }
+
+    for(LLItemRequestTimes::iterator it = mQuestionableCOFLinks.begin();
+        it != mQuestionableCOFLinks.end(); )
+    {
+        LLItemRequestTimes::iterator curr_it = it;
+        ++it;
+        const LLUUID& item_id = curr_it->first;
+        LLViewerInventoryItem *inv_item = gInventory.getItem(item_id);
+        if (curr_it->second.getElapsedTimeF32() > MAX_BAD_COF_TIME)
+        {
+            if (LLAppearanceMgr::instance().isLinkedInCOF(item_id))
+            {
+                LL_DEBUGS("Avatar") << "ATT Linked in COF but not attached or requested, deleting link after "
+                                    << curr_it->second.getElapsedTimeF32() << " seconds for "
+                                    << (inv_item ? inv_item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
+                LLAppearanceMgr::instance().removeCOFItemLinks(item_id);
+            }
+            mQuestionableCOFLinks.erase(curr_it);
+            continue;
+        }
+    }
 }
 
 void LLAttachmentsMgr::spamStatusInfo()
@@ -555,7 +555,7 @@ void LLAttachmentsMgr::spamStatusInfo()
     if (spam_timer.getElapsedTimeF32() > spam_frequency)
     {
         spam_timer.reset();
-        
+
         LLInventoryModel::cat_array_t cat_array;
         LLInventoryModel::item_array_t item_array;
         gInventory.collectDescendents(LLAppearanceMgr::instance().getCOF(),
@@ -579,24 +579,24 @@ void LLAttachmentsMgr::spamStatusInfo()
 // [SL:KB] - Patch: Appearance-PhantomAttach | Checked: Catznip-5.0
 void LLAttachmentsMgr::refreshAttachments()
 {
-	if (!isAgentAvatarValid())
-		return;
-
-	for (const auto& kvpAttachPt : gAgentAvatarp->mAttachmentPoints)
-	{
-		for (const LLViewerObject* pAttachObj : kvpAttachPt.second->mAttachedObjects)
-		{
-			const LLUUID& idItem = pAttachObj->getAttachmentItemID();
-			if ( (mAttachmentRequests.wasRequestedRecently(idItem)) || (pAttachObj->isTempAttachment()) )
-				continue;
-
-			AttachmentsInfo attachment;
-			attachment.mItemID = idItem;
-			attachment.mAttachmentPt = kvpAttachPt.first;
-			attachment.mAdd = true;
-			mPendingAttachments.push_back(attachment);
-			mAttachmentRequests.addTime(idItem);
-		}
-	}
+    if (!isAgentAvatarValid())
+        return;
+
+    for (const auto& kvpAttachPt : gAgentAvatarp->mAttachmentPoints)
+    {
+        for (const LLViewerObject* pAttachObj : kvpAttachPt.second->mAttachedObjects)
+        {
+            const LLUUID& idItem = pAttachObj->getAttachmentItemID();
+            if ( (mAttachmentRequests.wasRequestedRecently(idItem)) || (pAttachObj->isTempAttachment()) )
+                continue;
+
+            AttachmentsInfo attachment;
+            attachment.mItemID = idItem;
+            attachment.mAttachmentPt = kvpAttachPt.first;
+            attachment.mAdd = true;
+            mPendingAttachments.push_back(attachment);
+            mAttachmentRequests.addTime(idItem);
+        }
+    }
 }
 // [/SL:KB]
diff --git a/indra/newview/llattachmentsmgr.h b/indra/newview/llattachmentsmgr.h
index 78704f6e2f6d8208921845f05106117782225a77..55cc56b60bcde49d64d3ded1ae8a72a1e4d54fdb 100644
--- a/indra/newview/llattachmentsmgr.h
+++ b/indra/newview/llattachmentsmgr.h
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file llattachmentsmgr.h
  * @brief Batches up attachment requests and sends them all
  * in one message.
@@ -6,21 +6,21 @@
  * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -32,7 +32,7 @@
 
 //--------------------------------------------------------------------------------
 // LLAttachmentsMgr
-// 
+//
 // This class manages batching up of requests at two stages of
 // attachment rezzing.
 //
@@ -61,29 +61,29 @@
 class LLAttachmentsMgr final : public LLSingleton<LLAttachmentsMgr>
 {
     LLSINGLETON(LLAttachmentsMgr);
-	virtual ~LLAttachmentsMgr();
+    virtual ~LLAttachmentsMgr();
 
 public:
     // Stores info for attachments that will be requested during idle.
-	struct AttachmentsInfo
-	{
-		LLUUID mItemID;
-		U8 mAttachmentPt;
-		BOOL mAdd;
-	};
-	typedef std::deque<AttachmentsInfo> attachments_vec_t;
+    struct AttachmentsInfo
+    {
+        LLUUID mItemID;
+        U8 mAttachmentPt;
+        BOOL mAdd;
+    };
+    typedef std::deque<AttachmentsInfo> attachments_vec_t;
 
 // [RLVa:KB] - Checked: 2010-09-13 (RLVa-1.2.1)
-	void addAttachmentRequest(const LLUUID& item_id,
+    void addAttachmentRequest(const LLUUID& item_id,
                               const U8 attachment_pt,
                               const BOOL add, const BOOL fRlvForce = FALSE);
 // [/RLVa:KB]
-//	void addAttachmentRequest(const LLUUID& item_id,
+//  void addAttachmentRequest(const LLUUID& item_id,
 //                              const U8 attachment_pt,
 //                              const BOOL add);
     void onAttachmentRequested(const LLUUID& item_id);
-	void requestAttachments(attachments_vec_t& attachment_requests);
-	static void onIdle(void *);
+    void requestAttachments(attachments_vec_t& attachment_requests);
+    static void onIdle(void *);
 
     void onAttachmentArrived(const LLUUID& inv_item_id);
 
@@ -111,30 +111,30 @@ class LLAttachmentsMgr final : public LLSingleton<LLAttachmentsMgr>
         std::string mOpName;
     };
 
-	void removeAttachmentRequestTime(const LLUUID& inv_item_id);
-	void onIdle();
-	void requestPendingAttachments();
-	void linkRecentlyArrivedAttachments();
+    void removeAttachmentRequestTime(const LLUUID& inv_item_id);
+    void onIdle();
+    void requestPendingAttachments();
+    void linkRecentlyArrivedAttachments();
     void expireOldAttachmentRequests();
     void expireOldDetachRequests();
     void checkInvalidCOFLinks();
     void spamStatusInfo();
 
     // Attachments that we are planning to rez but haven't requested from the server yet.
-	attachments_vec_t mPendingAttachments;
+    attachments_vec_t mPendingAttachments;
 
-	// Attachments that have been requested from server but have not arrived yet.
-	LLItemRequestTimes mAttachmentRequests;
+    // Attachments that have been requested from server but have not arrived yet.
+    LLItemRequestTimes mAttachmentRequests;
 
     // Attachments that have been requested to detach but have not gone away yet.
-	LLItemRequestTimes mDetachRequests;
+    LLItemRequestTimes mDetachRequests;
 
     // Attachments that have arrived but have not been linked in the COF yet.
     std::set<LLUUID> mRecentlyArrivedAttachments;
     LLTimer mCOFLinkBatchTimer;
 
     // Attachments that are linked in the COF but may be invalid.
-	LLItemRequestTimes mQuestionableCOFLinks;
+    LLItemRequestTimes mQuestionableCOFLinks;
 };
 
 #endif
diff --git a/indra/newview/lldrawable.h b/indra/newview/lldrawable.h
index 9c767f8aa286259e280ad477f3ca6ff60abcb134..6c768e3838b20bc66d72bb1f9c93ab9efdf32590 100644
--- a/indra/newview/lldrawable.h
+++ b/indra/newview/lldrawable.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lldrawable.h
  * @brief LLDrawable class definition
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -67,271 +67,271 @@ class LLDrawable
 public:
     typedef std::vector<LLFace*> face_list_t;
 
-	LLDrawable(const LLDrawable& rhs) = delete;
-	LLDrawable& operator=(const LLDrawable& rhs) = delete;
-
-	static void initClass();
-
-	LLDrawable(LLViewerObject *vobj, bool new_entry = false);
-	
-	void markDead();			// Mark this drawable as dead
-	BOOL isDead() const			{ return isState(DEAD); }
-	BOOL isNew() const			{ return !isState(BUILT); }
-	BOOL isUnload() const		{ return isState(FOR_UNLOAD); }
-
-	BOOL isLight() const;
-
-	virtual void setVisible(LLCamera& camera_in, std::vector<LLDrawable*>* results = NULL, BOOL for_select = FALSE);
-
-	LLSpatialGroup* getSpatialGroup()const          {return (LLSpatialGroup*)getGroup();}
-	LLViewerRegion* getRegion()               const { return mVObjp->getRegion(); }
-	const LLTextureEntry* getTextureEntry(U8 which) const { return mVObjp->getTE(which); }
-	LLPointer<LLViewerObject>& getVObj()							  { return mVObjp; }
-	const LLViewerObject *getVObj()	const						  { return mVObjp; }
-	LLVOVolume*	getVOVolume() const; // cast mVObjp tp LLVOVolume if OK
-
-	const LLMatrix4a&     getWorldMatrix() const		{ return mXform.getWorldMatrix(); }
-	const LLMatrix4a&	  getRenderMatrix() const;
-	void				  setPosition(LLVector3 v) const { }
-	const LLVector3&	  getPosition() const			{ return mXform.getPosition(); }
-	const LLVector3&      getWorldPosition() const		{ return mXform.getPositionW(); }
-	const LLVector3		  getPositionAgent() const;
-	const LLVector3&	  getScale() const				{ return mCurrentScale; }
-	void				  setScale(const LLVector3& scale) { mCurrentScale = scale; }
-	const LLQuaternion&   getWorldRotation() const		{ return mXform.getWorldRotation(); }
-	const LLQuaternion&   getRotation() const			{ return mXform.getRotation(); }
-	F32			          getIntensity() const			{ return llmin(mXform.getScale().mV[0], 4.f); }
-	S32					  getLOD() const				{ return mVObjp ? mVObjp->getLOD() : 1; }
-
-	void  getMinMax(LLVector3& min,LLVector3& max) const { mXform.getMinMax(min,max); }
-	LLXformMatrix*		getXform() { return &mXform; }
-
-	U32					getState()           const { return mState; }
-	BOOL				isState   (U32 bits) const { return ((mState & bits) != 0); }
-	void                setState  (U32 bits)       { mState |= bits; }
-	void                clearState(U32 bits)       { mState &= ~bits; }
-
-	BOOL				isAvatar()	const			{ return mVObjp.notNull() && mVObjp->isAvatar(); }
-	BOOL				isRoot() const				{ return !mParent || mParent->isAvatar(); }
+    LLDrawable(const LLDrawable& rhs) = delete;
+    LLDrawable& operator=(const LLDrawable& rhs) = delete;
+
+    static void initClass();
+
+    LLDrawable(LLViewerObject *vobj, bool new_entry = false);
+
+    void markDead();            // Mark this drawable as dead
+    BOOL isDead() const         { return isState(DEAD); }
+    BOOL isNew() const          { return !isState(BUILT); }
+    BOOL isUnload() const       { return isState(FOR_UNLOAD); }
+
+    BOOL isLight() const;
+
+    virtual void setVisible(LLCamera& camera_in, std::vector<LLDrawable*>* results = NULL, BOOL for_select = FALSE);
+
+    LLSpatialGroup* getSpatialGroup()const          {return (LLSpatialGroup*)getGroup();}
+    LLViewerRegion* getRegion()               const { return mVObjp->getRegion(); }
+    const LLTextureEntry* getTextureEntry(U8 which) const { return mVObjp->getTE(which); }
+    LLPointer<LLViewerObject>& getVObj()                              { return mVObjp; }
+    const LLViewerObject *getVObj() const                         { return mVObjp; }
+    LLVOVolume* getVOVolume() const; // cast mVObjp tp LLVOVolume if OK
+
+    const LLMatrix4a&     getWorldMatrix() const        { return mXform.getWorldMatrix(); }
+    const LLMatrix4a&     getRenderMatrix() const;
+    void                  setPosition(LLVector3 v) const { }
+    const LLVector3&      getPosition() const           { return mXform.getPosition(); }
+    const LLVector3&      getWorldPosition() const      { return mXform.getPositionW(); }
+    const LLVector3       getPositionAgent() const;
+    const LLVector3&      getScale() const              { return mCurrentScale; }
+    void                  setScale(const LLVector3& scale) { mCurrentScale = scale; }
+    const LLQuaternion&   getWorldRotation() const      { return mXform.getWorldRotation(); }
+    const LLQuaternion&   getRotation() const           { return mXform.getRotation(); }
+    F32                   getIntensity() const          { return llmin(mXform.getScale().mV[0], 4.f); }
+    S32                   getLOD() const                { return mVObjp ? mVObjp->getLOD() : 1; }
+
+    void  getMinMax(LLVector3& min,LLVector3& max) const { mXform.getMinMax(min,max); }
+    LLXformMatrix*      getXform() { return &mXform; }
+
+    U32                 getState()           const { return mState; }
+    BOOL                isState   (U32 bits) const { return ((mState & bits) != 0); }
+    void                setState  (U32 bits)       { mState |= bits; }
+    void                clearState(U32 bits)       { mState &= ~bits; }
+
+    BOOL                isAvatar()  const           { return mVObjp.notNull() && mVObjp->isAvatar(); }
+    BOOL                isRoot() const              { return !mParent || mParent->isAvatar(); }
     LLDrawable*         getRoot();
-	BOOL				isSpatialRoot() const		{ return !mParent || mParent->isAvatar(); }
-	virtual BOOL		isSpatialBridge() const		{ return FALSE; }
-	virtual LLSpatialPartition* asPartition()		{ return NULL; }
-	LLDrawable*			getParent() const			{ return mParent; }
-	
-	// must set parent through LLViewerObject::		()
-	//BOOL                setParent(LLDrawable *parent);
-	
-	inline LLFace*      getFace(const S32 i) const;
-	inline S32			getNumFaces()      	 const;
+    BOOL                isSpatialRoot() const       { return !mParent || mParent->isAvatar(); }
+    virtual BOOL        isSpatialBridge() const     { return FALSE; }
+    virtual LLSpatialPartition* asPartition()       { return NULL; }
+    LLDrawable*         getParent() const           { return mParent; }
+
+    // must set parent through LLViewerObject::     ()
+    //BOOL                setParent(LLDrawable *parent);
+
+    inline LLFace*      getFace(const S32 i) const;
+    inline S32          getNumFaces()        const;
     face_list_t& getFaces() { return mFaces; }
     const face_list_t& getFaces() const { return mFaces; }
 
-	//void                removeFace(const S32 i); // SJB: Avoid using this, it's slow
-	LLFace*				addFace(LLFacePool *poolp, LLViewerTexture *texturep);
-	LLFace*				addFace(const LLTextureEntry *te, LLViewerTexture *texturep);
-	LLFace*				addFace(const LLTextureEntry *te, LLViewerTexture *texturep, LLViewerTexture *normalp);
-	LLFace*				addFace(const LLTextureEntry *te, LLViewerTexture *texturep, LLViewerTexture *normalp, LLViewerTexture *specularp);
-	void				deleteFaces(S32 offset, S32 count);
-	void                setNumFaces(const S32 numFaces, LLFacePool *poolp, LLViewerTexture *texturep);
-	void                setNumFacesFast(const S32 numFaces, LLFacePool *poolp, LLViewerTexture *texturep);
-	void				mergeFaces(LLDrawable* src);
-
-	void init(bool new_entry);
-	void unload();
-	void destroy();
-
-	void update();
-	F32 updateXform(BOOL undamped);
-
-	virtual void makeActive();
-	/*virtual*/ void makeStatic(BOOL warning_enabled = TRUE);
-
-	BOOL isActive()	const							{ return isState(ACTIVE); }
-	BOOL isStatic() const							{ return !isActive(); }
-	BOOL isAnimating() const;
-
-	virtual BOOL updateMove();
-	virtual void movePartition();
-	
-	void updateTexture();
-	void updateMaterial();
-	virtual void updateDistance(LLCamera& camera, bool force_update);
-	BOOL updateGeometry();
-	void updateFaceSize(S32 idx);
-		
-	void updateSpecialHoverCursor(BOOL enabled);
-
-	virtual void shiftPos(const LLVector4a &shift_vector);
-
-	S32 getGeneration() const					{ return mGeneration; }
-
-	BOOL getLit() const							{ return isState(UNLIT) ? FALSE : TRUE; }
-	void setLit(BOOL lit)						{ lit ? clearState(UNLIT) : setState(UNLIT); }
-
-	bool isVisible() const;
-	bool isRecentlyVisible() const;
-
-	virtual void cleanupReferences();
-
-	void setGroup(LLViewerOctreeGroup* group);
-	void setRadius(const F32 radius);
-	F32 getRadius() const						{ return mRadius; }
-	F32 getVisibilityRadius() const;
-
-	void updateUVMinMax();	// Updates the cache of sun space bounding box.
-
-	const LLVector3& getBounds(LLVector3& min, LLVector3& max) const;
-	virtual void updateSpatialExtents();
-	virtual void updateBinRadius();
-	
-	void setRenderType(S32 type) 				{ mRenderType = type; }
-	BOOL isRenderType(S32 type) 				{ return mRenderType == type; }
-	S32  getRenderType()						{ return mRenderType; }
-	
-	// Debugging methods
-	S32 findReferences(LLDrawable *drawablep); // Not const because of @#$! iterators...
-
-	LLSpatialPartition* getSpatialPartition();
-	
-	void removeFromOctree();
-
-	void setSpatialBridge(LLSpatialBridge* bridge) { mSpatialBridge = (LLDrawable*) bridge; }
-	LLSpatialBridge* getSpatialBridge() { return (LLSpatialBridge*) (LLDrawable*) mSpatialBridge; }
-
-	// Statics
-	static void incrementVisible();
-	static void cleanupDeadDrawables();
+    //void                removeFace(const S32 i); // SJB: Avoid using this, it's slow
+    LLFace*             addFace(LLFacePool *poolp, LLViewerTexture *texturep);
+    LLFace*             addFace(const LLTextureEntry *te, LLViewerTexture *texturep);
+    LLFace*             addFace(const LLTextureEntry *te, LLViewerTexture *texturep, LLViewerTexture *normalp);
+    LLFace*             addFace(const LLTextureEntry *te, LLViewerTexture *texturep, LLViewerTexture *normalp, LLViewerTexture *specularp);
+    void                deleteFaces(S32 offset, S32 count);
+    void                setNumFaces(const S32 numFaces, LLFacePool *poolp, LLViewerTexture *texturep);
+    void                setNumFacesFast(const S32 numFaces, LLFacePool *poolp, LLViewerTexture *texturep);
+    void                mergeFaces(LLDrawable* src);
+
+    void init(bool new_entry);
+    void unload();
+    void destroy();
+
+    void update();
+    F32 updateXform(BOOL undamped);
+
+    virtual void makeActive();
+    /*virtual*/ void makeStatic(BOOL warning_enabled = TRUE);
+
+    BOOL isActive() const                           { return isState(ACTIVE); }
+    BOOL isStatic() const                           { return !isActive(); }
+    BOOL isAnimating() const;
+
+    virtual BOOL updateMove();
+    virtual void movePartition();
+
+    void updateTexture();
+    void updateMaterial();
+    virtual void updateDistance(LLCamera& camera, bool force_update);
+    BOOL updateGeometry();
+    void updateFaceSize(S32 idx);
+
+    void updateSpecialHoverCursor(BOOL enabled);
+
+    virtual void shiftPos(const LLVector4a &shift_vector);
+
+    S32 getGeneration() const                   { return mGeneration; }
+
+    BOOL getLit() const                         { return isState(UNLIT) ? FALSE : TRUE; }
+    void setLit(BOOL lit)                       { lit ? clearState(UNLIT) : setState(UNLIT); }
+
+    bool isVisible() const;
+    bool isRecentlyVisible() const;
+
+    virtual void cleanupReferences();
+
+    void setGroup(LLViewerOctreeGroup* group);
+    void setRadius(const F32 radius);
+    F32 getRadius() const                       { return mRadius; }
+    F32 getVisibilityRadius() const;
+
+    void updateUVMinMax();  // Updates the cache of sun space bounding box.
+
+    const LLVector3& getBounds(LLVector3& min, LLVector3& max) const;
+    virtual void updateSpatialExtents();
+    virtual void updateBinRadius();
+
+    void setRenderType(S32 type)                { mRenderType = type; }
+    BOOL isRenderType(S32 type)                 { return mRenderType == type; }
+    S32  getRenderType()                        { return mRenderType; }
+
+    // Debugging methods
+    S32 findReferences(LLDrawable *drawablep); // Not const because of @#$! iterators...
+
+    LLSpatialPartition* getSpatialPartition();
+
+    void removeFromOctree();
+
+    void setSpatialBridge(LLSpatialBridge* bridge) { mSpatialBridge = (LLDrawable*) bridge; }
+    LLSpatialBridge* getSpatialBridge() { return (LLSpatialBridge*) (LLDrawable*) mSpatialBridge; }
+
+    // Statics
+    static void incrementVisible();
+    static void cleanupDeadDrawables();
 
 protected:
-	~LLDrawable() { destroy(); }
-	void moveUpdatePipeline(BOOL moved);
-	void updatePartition();
-	BOOL updateMoveDamped();
-	BOOL updateMoveUndamped();
-	
+    ~LLDrawable() { destroy(); }
+    void moveUpdatePipeline(BOOL moved);
+    void updatePartition();
+    BOOL updateMoveDamped();
+    BOOL updateMoveUndamped();
+
 public:
-	friend class LLPipeline;
-	friend class LLDrawPool;
-	friend class LLSpatialBridge;
-	
-	typedef boost::unordered_set<LLPointer<LLDrawable> > drawable_set_t;
+    friend class LLPipeline;
+    friend class LLDrawPool;
+    friend class LLSpatialBridge;
+
+    typedef boost::unordered_set<LLPointer<LLDrawable> > drawable_set_t;
     typedef std::set<LLPointer<LLDrawable> > ordered_drawable_set_t;
-	typedef std::vector<LLPointer<LLDrawable> > drawable_vector_t;
-	typedef std::list<LLPointer<LLDrawable> > drawable_list_t;
-	typedef std::queue<LLPointer<LLDrawable> > drawable_queue_t;
-	
-	struct CompareDistanceGreater
-	{
-		bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
-		{
-			return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
-		}
-	};
-
-	struct CompareDistanceGreaterVisibleFirst
-	{
-		bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
-		{
-			if (lhs->isVisible() && !rhs->isVisible())
-			{
-				return TRUE; //visible things come first
-			}
-			else if (!lhs->isVisible() && rhs->isVisible())
-			{
-				return FALSE; //rhs is visible, comes first
-			}
-			
-			return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
-		}
-	};
-	
-	typedef enum e_drawable_flags
-	{
- 		IN_REBUILD_Q	= 0x00000001,
-		EARLY_MOVE		= 0x00000004,
-		MOVE_UNDAMPED	= 0x00000008,
-		ON_MOVE_LIST	= 0x00000010,
-		UV				= 0x00000020,
-		UNLIT			= 0x00000040,
-		LIGHT			= 0x00000080,
-		REBUILD_VOLUME  = 0x00000100,	//volume changed LOD or parameters, or vertex buffer changed
-		REBUILD_TCOORD	= 0x00000200,	//texture coordinates changed
-		REBUILD_COLOR	= 0x00000400,	//color changed
-		REBUILD_POSITION= 0x00000800,	//vertex positions/normals changed
-		REBUILD_GEOMETRY= REBUILD_POSITION|REBUILD_TCOORD|REBUILD_COLOR,
-		REBUILD_MATERIAL= REBUILD_TCOORD|REBUILD_COLOR,
-		REBUILD_ALL		= REBUILD_GEOMETRY|REBUILD_VOLUME,
-		REBUILD_RIGGED	= 0x00001000,
-		ON_SHIFT_LIST	= 0x00002000,
-		ACTIVE			= 0x00004000,
-		DEAD			= 0x00008000,
-		INVISIBLE		= 0x00010000, // stay invisible until flag is cleared
- 		NEARBY_LIGHT	= 0x00020000, // In gPipeline.mNearbyLightSet
-		BUILT			= 0x00040000,
-		FORCE_INVISIBLE = 0x00080000, // stay invis until CLEAR_INVISIBLE is set (set of orphaned)
-		HAS_ALPHA		= 0x00100000,
-		RIGGED			= 0x00200000, //has a rigged face
+    typedef std::vector<LLPointer<LLDrawable> > drawable_vector_t;
+    typedef std::list<LLPointer<LLDrawable> > drawable_list_t;
+    typedef std::queue<LLPointer<LLDrawable> > drawable_queue_t;
+
+    struct CompareDistanceGreater
+    {
+        bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
+        {
+            return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
+        }
+    };
+
+    struct CompareDistanceGreaterVisibleFirst
+    {
+        bool operator()(const LLDrawable* const& lhs, const LLDrawable* const& rhs)
+        {
+            if (lhs->isVisible() && !rhs->isVisible())
+            {
+                return TRUE; //visible things come first
+            }
+            else if (!lhs->isVisible() && rhs->isVisible())
+            {
+                return FALSE; //rhs is visible, comes first
+            }
+
+            return lhs->mDistanceWRTCamera < rhs->mDistanceWRTCamera; // farthest = last
+        }
+    };
+
+    typedef enum e_drawable_flags
+    {
+        IN_REBUILD_Q    = 0x00000001,
+        EARLY_MOVE      = 0x00000004,
+        MOVE_UNDAMPED   = 0x00000008,
+        ON_MOVE_LIST    = 0x00000010,
+        UV              = 0x00000020,
+        UNLIT           = 0x00000040,
+        LIGHT           = 0x00000080,
+        REBUILD_VOLUME  = 0x00000100,   //volume changed LOD or parameters, or vertex buffer changed
+        REBUILD_TCOORD  = 0x00000200,   //texture coordinates changed
+        REBUILD_COLOR   = 0x00000400,   //color changed
+        REBUILD_POSITION= 0x00000800,   //vertex positions/normals changed
+        REBUILD_GEOMETRY= REBUILD_POSITION|REBUILD_TCOORD|REBUILD_COLOR,
+        REBUILD_MATERIAL= REBUILD_TCOORD|REBUILD_COLOR,
+        REBUILD_ALL     = REBUILD_GEOMETRY|REBUILD_VOLUME,
+        REBUILD_RIGGED  = 0x00001000,
+        ON_SHIFT_LIST   = 0x00002000,
+        ACTIVE          = 0x00004000,
+        DEAD            = 0x00008000,
+        INVISIBLE       = 0x00010000, // stay invisible until flag is cleared
+        NEARBY_LIGHT    = 0x00020000, // In gPipeline.mNearbyLightSet
+        BUILT           = 0x00040000,
+        FORCE_INVISIBLE = 0x00080000, // stay invis until CLEAR_INVISIBLE is set (set of orphaned)
+        HAS_ALPHA       = 0x00100000,
+        RIGGED          = 0x00200000, //has a rigged face
         RIGGED_CHILD    = 0x00400000, //has a child with a rigged face
-		PARTITION_MOVE	= 0x00800000,
-		ANIMATED_CHILD  = 0x01000000,
-		ACTIVE_CHILD	= 0x02000000,
-		FOR_UNLOAD		= 0x04000000, //should be unload from memory
+        PARTITION_MOVE  = 0x00800000,
+        ANIMATED_CHILD  = 0x01000000,
+        ACTIVE_CHILD    = 0x02000000,
+        FOR_UNLOAD      = 0x04000000, //should be unload from memory
         MIRROR          = 0x08000000, // Used as a mirror, needs a hero probe position to be calculated.
-	} EDrawableFlags;
+    } EDrawableFlags;
 
 public:
-	LLXformMatrix       mXform;
+    LLXformMatrix       mXform;
 
-	// vis data
-	LLPointer<LLDrawable> mParent;
+    // vis data
+    LLPointer<LLDrawable> mParent;
 
-	F32				mDistanceWRTCamera;
+    F32             mDistanceWRTCamera;
 
-	static F32 sCurPixelAngle; //current pixels per radian
+    static F32 sCurPixelAngle; //current pixels per radian
 
 private:
-	U32				mState;
-	S32				mRenderType;
-	LLPointer<LLViewerObject> mVObjp;
-	face_list_t     mFaces;
-	LLPointer<LLDrawable> mSpatialBridge;
-	
-	F32				mRadius;
-	S32				mGeneration;
-	
-	LLVector3		mCurrentScale;
-	
-	static U32 sNumZombieDrawables;
-	static std::vector<LLPointer<LLDrawable> > sDeadList;
+    U32             mState;
+    S32             mRenderType;
+    LLPointer<LLViewerObject> mVObjp;
+    face_list_t     mFaces;
+    LLPointer<LLDrawable> mSpatialBridge;
+
+    F32             mRadius;
+    S32             mGeneration;
+
+    LLVector3       mCurrentScale;
+
+    static U32 sNumZombieDrawables;
+    static std::vector<LLPointer<LLDrawable> > sDeadList;
 } LL_ALIGN_POSTFIX(16);
 
 
 inline LLFace* LLDrawable::getFace(const S32 i) const
 {
-	//switch these asserts to LL_ERRS() -- davep
-	//llassert((U32)i < mFaces.size());
-	//llassert(mFaces[i]);
-
-	if ((U32) i >= mFaces.size())
-	{
-		LL_WARNS() << "Invalid face index." << LL_ENDL;
-		return NULL;
-	}
-
-	if (!mFaces[i])
-	{
-		LL_WARNS() << "Null face found." << LL_ENDL;
-		return NULL;
-	}
-	
-	return mFaces[i];
+    //switch these asserts to LL_ERRS() -- davep
+    //llassert((U32)i < mFaces.size());
+    //llassert(mFaces[i]);
+
+    if ((U32) i >= mFaces.size())
+    {
+        LL_WARNS() << "Invalid face index." << LL_ENDL;
+        return NULL;
+    }
+
+    if (!mFaces[i])
+    {
+        LL_WARNS() << "Null face found." << LL_ENDL;
+        return NULL;
+    }
+
+    return mFaces[i];
 }
 
 
 inline S32 LLDrawable::getNumFaces()const
 {
-	return (S32)mFaces.size();
+    return (S32)mFaces.size();
 }
 
 #endif
diff --git a/indra/newview/lldrawpool.h b/indra/newview/lldrawpool.h
index dd6ef5c2125cfccf2034f6eceb2e000b7c92735a..778f8c0e5ddd38a82b7625689bca1f2ff8948168 100644
--- a/indra/newview/lldrawpool.h
+++ b/indra/newview/lldrawpool.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lldrawpool.h
  * @brief LLDrawPool class definition
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -43,87 +43,87 @@ class LLMeshSkinInfo;
 class LLDrawPool
 {
 public:
-	static S32 sNumDrawPools;
+    static S32 sNumDrawPools;
 
-	enum
-	{
-		// Correspond to LLPipeline render type
+    enum
+    {
+        // Correspond to LLPipeline render type
         // Also controls render order, so passes that don't use alpha masking/blending should come before
         // other passes to preserve hierarchical Z for occlusion queries.  Occlusion queries happen just
         // before grass, so grass should be the first alpha masked pool.  Other ordering should be done
         // based on fill rate and likelihood to occlude future passes (faster, large occluders first).
-        //  
+        //
         POOL_SKY = 1,
         POOL_WL_SKY,
-		POOL_SIMPLE,
-		POOL_FULLBRIGHT,
-		POOL_BUMP,
+        POOL_SIMPLE,
+        POOL_FULLBRIGHT,
+        POOL_BUMP,
         POOL_MATERIALS,
         POOL_GLTF_PBR,
-		POOL_TERRAIN,
+        POOL_TERRAIN,
         POOL_GRASS,
         POOL_GLTF_PBR_ALPHA_MASK,
-		POOL_TREE,
-		POOL_ALPHA_MASK,
-		POOL_FULLBRIGHT_ALPHA_MASK,
-		POOL_AVATAR,
-		POOL_CONTROL_AV, // Animesh
-		POOL_GLOW,
-		POOL_ALPHA_PRE_WATER,
+        POOL_TREE,
+        POOL_ALPHA_MASK,
+        POOL_FULLBRIGHT_ALPHA_MASK,
+        POOL_AVATAR,
+        POOL_CONTROL_AV, // Animesh
+        POOL_GLOW,
+        POOL_ALPHA_PRE_WATER,
         POOL_VOIDWATER,
         POOL_WATER,
         POOL_ALPHA_POST_WATER,
         POOL_ALPHA, // note there is no actual "POOL_ALPHA" but pre-water and post-water pools consume POOL_ALPHA faces
-		NUM_POOL_TYPES,
-	};
-	
-	LLDrawPool(const U32 type);
-	virtual ~LLDrawPool();
-
-	virtual BOOL isDead() = 0;
-
-	S32 getId() const { return mId; }
-	U32 getType() const { return mType; }
-
-	BOOL getSkipRenderFlag() const { return mSkipRender;}
-	void setSkipRenderFlag( BOOL flag ) { mSkipRender = flag; }
-
-	virtual LLViewerTexture *getDebugTexture();
-	virtual void beginRenderPass( S32 pass );
-	virtual void endRenderPass( S32 pass );
-	virtual S32	 getNumPasses();
-	
-	virtual void beginDeferredPass(S32 pass);
-	virtual void endDeferredPass(S32 pass);
-	virtual S32 getNumDeferredPasses();
-	virtual void renderDeferred(S32 pass = 0);
-
-	virtual void beginPostDeferredPass(S32 pass);
-	virtual void endPostDeferredPass(S32 pass);
-	virtual S32 getNumPostDeferredPasses();
-	virtual void renderPostDeferred(S32 pass = 0);
-
-	virtual void beginShadowPass(S32 pass);
-	virtual void endShadowPass(S32 pass);
-	virtual S32 getNumShadowPasses();
-	virtual void renderShadow(S32 pass = 0);
+        NUM_POOL_TYPES,
+    };
+
+    LLDrawPool(const U32 type);
+    virtual ~LLDrawPool();
+
+    virtual BOOL isDead() = 0;
+
+    S32 getId() const { return mId; }
+    U32 getType() const { return mType; }
+
+    BOOL getSkipRenderFlag() const { return mSkipRender;}
+    void setSkipRenderFlag( BOOL flag ) { mSkipRender = flag; }
+
+    virtual LLViewerTexture *getDebugTexture();
+    virtual void beginRenderPass( S32 pass );
+    virtual void endRenderPass( S32 pass );
+    virtual S32  getNumPasses();
+
+    virtual void beginDeferredPass(S32 pass);
+    virtual void endDeferredPass(S32 pass);
+    virtual S32 getNumDeferredPasses();
+    virtual void renderDeferred(S32 pass = 0);
+
+    virtual void beginPostDeferredPass(S32 pass);
+    virtual void endPostDeferredPass(S32 pass);
+    virtual S32 getNumPostDeferredPasses();
+    virtual void renderPostDeferred(S32 pass = 0);
+
+    virtual void beginShadowPass(S32 pass);
+    virtual void endShadowPass(S32 pass);
+    virtual S32 getNumShadowPasses();
+    virtual void renderShadow(S32 pass = 0);
 
     virtual void render(S32 pass = 0) {};
     virtual void prerender() {};
     virtual U32 getVertexDataMask() { return 0; } // DEPRECATED -- draw pool doesn't actually determine vertex data mask any more
-	virtual BOOL verify() const { return TRUE; }		// Verify that all data in the draw pool is correct!
-	virtual S32 getShaderLevel() const { return mShaderLevel; }
-	
-	static LLDrawPool* createPool(const U32 type, LLViewerTexture *tex0 = NULL);
-	virtual LLViewerTexture* getTexture() = 0;
-	virtual BOOL isFacePool() { return FALSE; }
-	virtual void resetDrawOrders() = 0;
+    virtual BOOL verify() const { return TRUE; }        // Verify that all data in the draw pool is correct!
+    virtual S32 getShaderLevel() const { return mShaderLevel; }
+
+    static LLDrawPool* createPool(const U32 type, LLViewerTexture *tex0 = NULL);
+    virtual LLViewerTexture* getTexture() = 0;
+    virtual BOOL isFacePool() { return FALSE; }
+    virtual void resetDrawOrders() = 0;
     virtual void pushFaceGeometry() {}
 
-	S32 mShaderLevel;
-	S32	mId;
-	U32 mType;				// Type of draw pool
-	BOOL mSkipRender;
+    S32 mShaderLevel;
+    S32 mId;
+    U32 mType;              // Type of draw pool
+    BOOL mSkipRender;
 };
 
 class LLRenderPass : public LLDrawPool
@@ -132,77 +132,77 @@ class LLRenderPass : public LLDrawPool
     // list of possible LLRenderPass types to assign a render batch to
     // NOTE: "rigged" variant MUST be non-rigged variant + 1
     // see LLVolumeGeometryManager::registerFace()
-	enum
-	{
-		PASS_SIMPLE = NUM_POOL_TYPES,
+    enum
+    {
+        PASS_SIMPLE = NUM_POOL_TYPES,
         PASS_SIMPLE_RIGGED,
-		PASS_GRASS,
-		PASS_FULLBRIGHT,
+        PASS_GRASS,
+        PASS_FULLBRIGHT,
         PASS_FULLBRIGHT_RIGGED,
-		PASS_INVISIBLE,
+        PASS_INVISIBLE,
         PASS_INVISIBLE_RIGGED,
-		PASS_INVISI_SHINY, 
+        PASS_INVISI_SHINY,
         PASS_INVISI_SHINY_RIGGED,
-		PASS_FULLBRIGHT_SHINY,
+        PASS_FULLBRIGHT_SHINY,
         PASS_FULLBRIGHT_SHINY_RIGGED,
-		PASS_SHINY,
+        PASS_SHINY,
         PASS_SHINY_RIGGED,
-		PASS_BUMP,
+        PASS_BUMP,
         PASS_BUMP_RIGGED,
-		PASS_POST_BUMP,
+        PASS_POST_BUMP,
         PASS_POST_BUMP_RIGGED,
-		PASS_MATERIAL,
+        PASS_MATERIAL,
         PASS_MATERIAL_RIGGED,
-		PASS_MATERIAL_ALPHA,
+        PASS_MATERIAL_ALPHA,
         PASS_MATERIAL_ALPHA_RIGGED,
-		PASS_MATERIAL_ALPHA_MASK,              // Diffuse texture used as alpha mask
+        PASS_MATERIAL_ALPHA_MASK,              // Diffuse texture used as alpha mask
         PASS_MATERIAL_ALPHA_MASK_RIGGED,
-		PASS_MATERIAL_ALPHA_EMISSIVE,
+        PASS_MATERIAL_ALPHA_EMISSIVE,
         PASS_MATERIAL_ALPHA_EMISSIVE_RIGGED,
-		PASS_SPECMAP,
+        PASS_SPECMAP,
         PASS_SPECMAP_RIGGED,
-		PASS_SPECMAP_BLEND,
+        PASS_SPECMAP_BLEND,
         PASS_SPECMAP_BLEND_RIGGED,
-		PASS_SPECMAP_MASK,                     // Diffuse texture used as alpha mask and specular texture(map)
+        PASS_SPECMAP_MASK,                     // Diffuse texture used as alpha mask and specular texture(map)
         PASS_SPECMAP_MASK_RIGGED,
-		PASS_SPECMAP_EMISSIVE,
+        PASS_SPECMAP_EMISSIVE,
         PASS_SPECMAP_EMISSIVE_RIGGED,
-		PASS_NORMMAP,
+        PASS_NORMMAP,
         PASS_NORMMAP_RIGGED,
-		PASS_NORMMAP_BLEND,
+        PASS_NORMMAP_BLEND,
         PASS_NORMMAP_BLEND_RIGGED,
-		PASS_NORMMAP_MASK,                     // Diffuse texture used as alpha mask and normal map
+        PASS_NORMMAP_MASK,                     // Diffuse texture used as alpha mask and normal map
         PASS_NORMMAP_MASK_RIGGED,
-		PASS_NORMMAP_EMISSIVE,
+        PASS_NORMMAP_EMISSIVE,
         PASS_NORMMAP_EMISSIVE_RIGGED,
-		PASS_NORMSPEC,
+        PASS_NORMSPEC,
         PASS_NORMSPEC_RIGGED,
-		PASS_NORMSPEC_BLEND, 
+        PASS_NORMSPEC_BLEND,
         PASS_NORMSPEC_BLEND_RIGGED,
-		PASS_NORMSPEC_MASK,                    // Diffuse texture used as alpha mask with normal and specular map
+        PASS_NORMSPEC_MASK,                    // Diffuse texture used as alpha mask with normal and specular map
         PASS_NORMSPEC_MASK_RIGGED,
-		PASS_NORMSPEC_EMISSIVE,
+        PASS_NORMSPEC_EMISSIVE,
         PASS_NORMSPEC_EMISSIVE_RIGGED,
-		PASS_GLOW,
+        PASS_GLOW,
         PASS_GLOW_RIGGED,
         PASS_GLTF_GLOW,
         PASS_GLTF_GLOW_RIGGED,
-		PASS_ALPHA,
+        PASS_ALPHA,
         PASS_ALPHA_RIGGED,
-		PASS_ALPHA_MASK,
+        PASS_ALPHA_MASK,
         PASS_ALPHA_MASK_RIGGED,
-		PASS_FULLBRIGHT_ALPHA_MASK,            // Diffuse texture used as alpha mask and fullbright
+        PASS_FULLBRIGHT_ALPHA_MASK,            // Diffuse texture used as alpha mask and fullbright
         PASS_FULLBRIGHT_ALPHA_MASK_RIGGED,
-		PASS_ALPHA_INVISIBLE,
+        PASS_ALPHA_INVISIBLE,
         PASS_ALPHA_INVISIBLE_RIGGED,
         PASS_GLTF_PBR,
         PASS_GLTF_PBR_RIGGED,
         PASS_GLTF_PBR_ALPHA_MASK,
         PASS_GLTF_PBR_ALPHA_MASK_RIGGED,
-		NUM_RENDER_TYPES,
-	};
+        NUM_RENDER_TYPES,
+    };
 
-	#ifdef LL_PROFILER_ENABLE_RENDER_DOC
+    #ifdef LL_PROFILER_ENABLE_RENDER_DOC
     static inline const char* lookupPassName(U32 pass)
     {
         switch (pass)
@@ -336,22 +336,22 @@ class LLRenderPass : public LLDrawPool
             default:
                 return "Unknown pass";
         }
-	}
-	#else
+    }
+    #else
     static inline const char* lookupPass(U32 pass) { return ""; }
-	#endif
+    #endif
 
-	LLRenderPass(const U32 type);
-	virtual ~LLRenderPass();
-	/*virtual*/ LLViewerTexture* getDebugTexture() { return NULL; }
-	LLViewerTexture* getTexture() { return NULL; }
-	BOOL isDead() { return FALSE; }
-	void resetDrawOrders() { }
+    LLRenderPass(const U32 type);
+    virtual ~LLRenderPass();
+    /*virtual*/ LLViewerTexture* getDebugTexture() { return NULL; }
+    LLViewerTexture* getTexture() { return NULL; }
+    BOOL isDead() { return FALSE; }
+    void resetDrawOrders() { }
 
-	static void applyModelMatrix(const LLDrawInfo& params);
+    static void applyModelMatrix(const LLDrawInfo& params);
     // For rendering that doesn't use LLDrawInfo for some reason
-	static void applyModelMatrix(const LLMatrix4a* model_matrix);
-	void pushBatches(U32 type, bool texture = true, bool batch_textures = false);
+    static void applyModelMatrix(const LLMatrix4a* model_matrix);
+    void pushBatches(U32 type, bool texture = true, bool batch_textures = false);
     void pushUntexturedBatches(U32 type);
 
     void pushRiggedBatches(U32 type, bool texture = true, bool batch_textures = false);
@@ -379,104 +379,104 @@ class LLRenderPass : public LLDrawPool
     static void pushUntexturedGLTFBatch(LLDrawInfo& params);
     static void pushUntexturedRiggedGLTFBatch(LLDrawInfo& params, LLVOAvatar*& lastAvatar, U64& lastMeshId);
 
-	void pushMaskBatches(U32 type, bool texture = true, bool batch_textures = false);
+    void pushMaskBatches(U32 type, bool texture = true, bool batch_textures = false);
     void pushRiggedMaskBatches(U32 type, bool texture = true, bool batch_textures = false);
-	void pushBatch(LLDrawInfo& params, bool texture, bool batch_textures = false);
+    void pushBatch(LLDrawInfo& params, bool texture, bool batch_textures = false);
     void pushUntexturedBatch(LLDrawInfo& params);
-	void pushBumpBatch(LLDrawInfo& params, bool texture, bool batch_textures = false);
+    void pushBumpBatch(LLDrawInfo& params, bool texture, bool batch_textures = false);
     static bool uploadMatrixPalette(LLDrawInfo& params);
     static bool uploadMatrixPalette(LLVOAvatar* avatar, LLMeshSkinInfo* skinInfo);
-	virtual void renderGroup(LLSpatialGroup* group, U32 type, bool texture = true);
+    virtual void renderGroup(LLSpatialGroup* group, U32 type, bool texture = true);
     virtual void renderRiggedGroup(LLSpatialGroup* group, U32 type, bool texture = true);
 };
 
 class LLFacePool : public LLDrawPool
 {
 public:
-	typedef std::vector<LLFace*> face_array_t;
-	
-	enum
-	{
-		SHADER_LEVEL_SCATTERING = 2
-	};
+    typedef std::vector<LLFace*> face_array_t;
+
+    enum
+    {
+        SHADER_LEVEL_SCATTERING = 2
+    };
 
 public:
-	LLFacePool(const U32 type);
-	virtual ~LLFacePool();
-	
-	BOOL isDead() { return mReferences.empty(); }
-	
-	virtual LLViewerTexture *getTexture();
-	virtual void dirtyTextures(const std::set<LLViewerFetchedTexture*>& textures);
+    LLFacePool(const U32 type);
+    virtual ~LLFacePool();
+
+    BOOL isDead() { return mReferences.empty(); }
+
+    virtual LLViewerTexture *getTexture();
+    virtual void dirtyTextures(const std::set<LLViewerFetchedTexture*>& textures);
+
+    virtual void enqueue(LLFace *face);
+    virtual BOOL addFace(LLFace *face);
+    virtual BOOL removeFace(LLFace *face);
 
-	virtual void enqueue(LLFace *face);
-	virtual BOOL addFace(LLFace *face);
-	virtual BOOL removeFace(LLFace *face);
+    virtual BOOL verify() const;        // Verify that all data in the draw pool is correct!
 
-	virtual BOOL verify() const;		// Verify that all data in the draw pool is correct!
-	
-	virtual void resetDrawOrders();
-	void resetAll();
+    virtual void resetDrawOrders();
+    void resetAll();
 
-	void destroy();
+    void destroy();
 
-	void buildEdges();
+    void buildEdges();
 
-	void addFaceReference(LLFace *facep);
-	void removeFaceReference(LLFace *facep);
+    void addFaceReference(LLFace *facep);
+    void removeFaceReference(LLFace *facep);
 
-	void printDebugInfo() const;
-	
-	BOOL isFacePool() { return TRUE; }
+    void printDebugInfo() const;
+
+    BOOL isFacePool() { return TRUE; }
 
     // call drawIndexed on every draw face
     void pushFaceGeometry();
 
-	friend class LLFace;
-	friend class LLPipeline;
+    friend class LLFace;
+    friend class LLPipeline;
 public:
-	face_array_t	mDrawFace;
-	face_array_t	mMoveFace;
-	face_array_t	mReferences;
+    face_array_t    mDrawFace;
+    face_array_t    mMoveFace;
+    face_array_t    mReferences;
 
 public:
-	class LLOverrideFaceColor
-	{
-	public:
-		LLOverrideFaceColor(LLDrawPool* pool)
-			: mOverride(sOverrideFaceColor), mPool(pool)
-		{
-			sOverrideFaceColor = TRUE;
-		}
-		LLOverrideFaceColor(LLDrawPool* pool, const LLColor4& color)
-			: mOverride(sOverrideFaceColor), mPool(pool)
-		{
-			sOverrideFaceColor = TRUE;
-			setColor(color);
-		}
-		LLOverrideFaceColor(LLDrawPool* pool, const LLColor4U& color)
-			: mOverride(sOverrideFaceColor), mPool(pool)
-		{
-			sOverrideFaceColor = TRUE;
-			setColor(color);
-		}
-		LLOverrideFaceColor(LLDrawPool* pool, F32 r, F32 g, F32 b, F32 a)
-			: mOverride(sOverrideFaceColor), mPool(pool)
-		{
-			sOverrideFaceColor = TRUE;
-			setColor(r, g, b, a);
-		}
-		~LLOverrideFaceColor()
-		{
-			sOverrideFaceColor = mOverride;
-		}
-		void setColor(const LLColor4& color);
-		void setColor(const LLColor4U& color);
-		void setColor(F32 r, F32 g, F32 b, F32 a);
-		BOOL mOverride;
-		LLDrawPool* mPool;
-		static BOOL sOverrideFaceColor;
-	};
+    class LLOverrideFaceColor
+    {
+    public:
+        LLOverrideFaceColor(LLDrawPool* pool)
+            : mOverride(sOverrideFaceColor), mPool(pool)
+        {
+            sOverrideFaceColor = TRUE;
+        }
+        LLOverrideFaceColor(LLDrawPool* pool, const LLColor4& color)
+            : mOverride(sOverrideFaceColor), mPool(pool)
+        {
+            sOverrideFaceColor = TRUE;
+            setColor(color);
+        }
+        LLOverrideFaceColor(LLDrawPool* pool, const LLColor4U& color)
+            : mOverride(sOverrideFaceColor), mPool(pool)
+        {
+            sOverrideFaceColor = TRUE;
+            setColor(color);
+        }
+        LLOverrideFaceColor(LLDrawPool* pool, F32 r, F32 g, F32 b, F32 a)
+            : mOverride(sOverrideFaceColor), mPool(pool)
+        {
+            sOverrideFaceColor = TRUE;
+            setColor(r, g, b, a);
+        }
+        ~LLOverrideFaceColor()
+        {
+            sOverrideFaceColor = mOverride;
+        }
+        void setColor(const LLColor4& color);
+        void setColor(const LLColor4U& color);
+        void setColor(F32 r, F32 g, F32 b, F32 a);
+        BOOL mOverride;
+        LLDrawPool* mPool;
+        static BOOL sOverrideFaceColor;
+    };
 };
 
 
diff --git a/indra/newview/lldrawpoolalpha.cpp b/indra/newview/lldrawpoolalpha.cpp
index 4d6d8070b2562e6f8cbc3e1a34fb253d2c51118d..78409d9790ffd1daaeb76e362bd95a7e77c0d81a 100644
--- a/indra/newview/lldrawpoolalpha.cpp
+++ b/indra/newview/lldrawpoolalpha.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lldrawpoolalpha.cpp
  * @brief LLDrawPoolAlpha class implementation
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -39,7 +39,7 @@
 #include "lldrawable.h"
 #include "llface.h"
 #include "llviewercamera.h"
-#include "llviewertexturelist.h"	// For debugging
+#include "llviewertexturelist.h"    // For debugging
 #include "llviewerobjectlist.h" // For debugging
 #include "llviewerwindow.h"
 #include "pipeline.h"
@@ -66,11 +66,11 @@ static const F32 MINIMUM_ALPHA = 0.004f; // ~ 1/255
 static const F32 MINIMUM_IMPOSTOR_ALPHA = 0.1f;
 
 LLDrawPoolAlpha::LLDrawPoolAlpha(U32 type) :
-		LLRenderPass(type), target_shader(NULL),
-		mColorSFactor(LLRender::BF_UNDEF), mColorDFactor(LLRender::BF_UNDEF),
-		mAlphaSFactor(LLRender::BF_UNDEF), mAlphaDFactor(LLRender::BF_UNDEF)
+        LLRenderPass(type), target_shader(NULL),
+        mColorSFactor(LLRender::BF_UNDEF), mColorDFactor(LLRender::BF_UNDEF),
+        mAlphaSFactor(LLRender::BF_UNDEF), mAlphaDFactor(LLRender::BF_UNDEF)
 {
- 
+
 }
 
 LLDrawPoolAlpha::~LLDrawPoolAlpha()
@@ -80,15 +80,15 @@ LLDrawPoolAlpha::~LLDrawPoolAlpha()
 
 void LLDrawPoolAlpha::prerender()
 {
-	mShaderLevel = LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
+    mShaderLevel = LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
 
     // TODO: is this even necessay?  These are probably set to never discard
     LLViewerFetchedTexture::sFlatNormalImagep->addTextureStats(1024.f*1024.f);
     LLViewerFetchedTexture::sWhiteImagep->addTextureStats(1024.f * 1024.f);
 }
 
-S32 LLDrawPoolAlpha::getNumPostDeferredPasses() 
-{ 
+S32 LLDrawPoolAlpha::getNumPostDeferredPasses()
+{
     return 1;
 }
 
@@ -108,7 +108,7 @@ static void prepare_alpha_shader(LLGLSLShader* shader, bool textureGamma, bool d
     {
         shader->mCanBindFast = false;
     }
-    
+
     shader->bind();
     shader->uniform1f(LLShaderMgr::DISPLAY_GAMMA, (gamma > 0.1f) ? 1.0f / gamma : (1.0f / 2.2f));
 
@@ -139,15 +139,15 @@ static void prepare_alpha_shader(LLGLSLShader* shader, bool textureGamma, bool d
 
     //also prepare rigged variant
     if (shader->mRiggedVariant && shader->mRiggedVariant != shader)
-    { 
+    {
         prepare_alpha_shader(shader->mRiggedVariant, textureGamma, deferredEnvironment, water_sign);
     }
 }
 
 extern BOOL gCubeSnapshot;
 
-void LLDrawPoolAlpha::renderPostDeferred(S32 pass) 
-{ 
+void LLDrawPoolAlpha::renderPostDeferred(S32 pass)
+{
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
 
     if (LLPipeline::isWaterClip() && getType() == LLDrawPool::POOL_ALPHA_PRE_WATER)
@@ -177,13 +177,13 @@ void LLDrawPoolAlpha::renderPostDeferred(S32 pass)
     prepare_alpha_shader(pbr_emissive_shader, true, false, water_sign);
 
 
-    fullbright_shader   = 
+    fullbright_shader   =
         (LLPipeline::sImpostorRender) ? &gDeferredFullbrightAlphaMaskProgram :
         (LLPipeline::sRenderingHUDs) ? &gHUDFullbrightAlphaMaskAlphaProgram :
         &gDeferredFullbrightAlphaMaskAlphaProgram;
     prepare_alpha_shader(fullbright_shader, true, true, water_sign);
 
-    simple_shader   = 
+    simple_shader   =
         (LLPipeline::sImpostorRender) ? &gDeferredAlphaImpostorProgram :
         (LLPipeline::sRenderingHUDs) ? &gHUDAlphaProgram :
         &gDeferredAlphaProgram;
@@ -196,8 +196,8 @@ void LLDrawPoolAlpha::renderPostDeferred(S32 pass)
         prepare_alpha_shader(&materialShader[i], false, true, water_sign);
     }
 
-    pbr_shader = 
-        (LLPipeline::sRenderingHUDs) ? &gHUDPBRAlphaProgram : 
+    pbr_shader =
+        (LLPipeline::sRenderingHUDs) ? &gHUDPBRAlphaProgram :
         &gDeferredPBRAlphaProgram;
 
     prepare_alpha_shader(pbr_shader, false, true, water_sign);
@@ -217,7 +217,7 @@ void LLDrawPoolAlpha::renderPostDeferred(S32 pass)
 
     // final pass, render to depth for depth of field effects
     if (!LLPipeline::sImpostorRender && LLPipeline::RenderDepthOfField && !gCubeSnapshot && !LLPipeline::sRenderingHUDs && getType() == LLDrawPool::POOL_ALPHA_POST_WATER)
-    { 
+    {
         //update depth buffer sampler
         simple_shader = fullbright_shader = &gDeferredFullbrightAlphaMaskProgram;
 
@@ -229,7 +229,7 @@ void LLDrawPoolAlpha::renderPostDeferred(S32 pass)
 
         // If the face is more than 90% transparent, then don't update the Depth buffer for Dof
         // We don't want the nearly invisible objects to cause of DoF effects
-        renderAlpha(getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2, 
+        renderAlpha(getVertexDataMask() | LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2,
             true); // <--- discard mostly transparent faces
 
         gGL.setColorMask(true, false);
@@ -287,8 +287,8 @@ void LLDrawPoolAlpha::forwardRender(bool rigged)
 
 void LLDrawPoolAlpha::renderDebugAlpha()
 {
-	if (sShowDebugAlpha)
-	{
+    if (sShowDebugAlpha)
+    {
         gHighlightProgram.bind();
         gGL.diffuseColor4f(1, 0, 0, 1);
         gGL.getTexUnit(0)->bindFast(LLViewerFetchedTexture::getSmokeImage());
@@ -296,19 +296,19 @@ void LLDrawPoolAlpha::renderDebugAlpha()
 
         renderAlphaHighlight();
 
-		pushUntexturedBatches(LLRenderPass::PASS_ALPHA_MASK);
-		pushUntexturedBatches(LLRenderPass::PASS_ALPHA_INVISIBLE);
+        pushUntexturedBatches(LLRenderPass::PASS_ALPHA_MASK);
+        pushUntexturedBatches(LLRenderPass::PASS_ALPHA_INVISIBLE);
 
-		// Material alpha mask
-		gGL.diffuseColor4f(0, 0, 1, 1);
-		pushUntexturedBatches(LLRenderPass::PASS_MATERIAL_ALPHA_MASK);
-		pushUntexturedBatches(LLRenderPass::PASS_NORMMAP_MASK);
-		pushUntexturedBatches(LLRenderPass::PASS_SPECMAP_MASK);
-		pushUntexturedBatches(LLRenderPass::PASS_NORMSPEC_MASK);
-		pushUntexturedBatches(LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
+        // Material alpha mask
+        gGL.diffuseColor4f(0, 0, 1, 1);
+        pushUntexturedBatches(LLRenderPass::PASS_MATERIAL_ALPHA_MASK);
+        pushUntexturedBatches(LLRenderPass::PASS_NORMMAP_MASK);
+        pushUntexturedBatches(LLRenderPass::PASS_SPECMAP_MASK);
+        pushUntexturedBatches(LLRenderPass::PASS_NORMSPEC_MASK);
+        pushUntexturedBatches(LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
         pushUntexturedBatches(LLRenderPass::PASS_GLTF_PBR_ALPHA_MASK);
 
-		gGL.diffuseColor4f(0, 1, 0, 1);
+        gGL.diffuseColor4f(0, 1, 0, 1);
         pushUntexturedBatches(LLRenderPass::PASS_INVISIBLE);
 
         gHighlightProgram.mRiggedVariant->bind();
@@ -329,7 +329,7 @@ void LLDrawPoolAlpha::renderDebugAlpha()
         gGL.diffuseColor4f(0, 1, 0, 1);
         pushRiggedBatches(LLRenderPass::PASS_INVISIBLE_RIGGED, false);
         LLGLSLShader::sCurBoundShaderPtr->unbind();
-	}
+    }
 }
 
 void LLDrawPoolAlpha::renderAlphaHighlight()
@@ -348,7 +348,7 @@ void LLDrawPoolAlpha::renderAlphaHighlight()
             if (group->getSpatialPartition()->mRenderByGroup &&
                 !group->isDead())
             {
-                LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA+pass]; // <-- hacky + pass to use PASS_ALPHA_RIGGED on second pass 
+                LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[LLRenderPass::PASS_ALPHA+pass]; // <-- hacky + pass to use PASS_ALPHA_RIGGED on second pass
 
                 for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k)
                 {
@@ -403,7 +403,7 @@ inline void Draw(LLDrawInfo* draw, U32 mask)
 {
     draw->mVertexBuffer->setBuffer();
     LLRenderPass::applyModelMatrix(*draw);
-	draw->mVertexBuffer->drawRange(LLRender::TRIANGLES, draw->mStart, draw->mEnd, draw->mCount, draw->mOffset);                    
+    draw->mVertexBuffer->drawRange(LLRender::TRIANGLES, draw->mStart, draw->mEnd, draw->mCount, draw->mOffset);
 }
 
 bool LLDrawPoolAlpha::TexSetup(LLDrawInfo* draw, bool use_material)
@@ -485,19 +485,19 @@ bool LLDrawPoolAlpha::TexSetup(LLDrawInfo* draw, bool use_material)
 void LLDrawPoolAlpha::RestoreTexSetup(bool tex_setup)
 {
     if (tex_setup)
-	{
-		gGL.getTexUnit(0)->activate();
+    {
+        gGL.getTexUnit(0)->activate();
         gGL.matrixMode(LLRender::MM_TEXTURE);
-		gGL.loadIdentity();
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-	}
+        gGL.loadIdentity();
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+    }
 }
 
 void LLDrawPoolAlpha::drawEmissive(LLDrawInfo* draw)
 {
     LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::EMISSIVE_BRIGHTNESS, 1.f);
     draw->mVertexBuffer->setBuffer();
-	draw->mVertexBuffer->drawRange(LLRender::TRIANGLES, draw->mStart, draw->mEnd, draw->mCount, draw->mOffset);
+    draw->mVertexBuffer->drawRange(LLRender::TRIANGLES, draw->mStart, draw->mEnd, draw->mCount, draw->mOffset);
 }
 
 
@@ -561,7 +561,7 @@ void LLDrawPoolAlpha::renderRiggedPbrEmissives(std::vector<LLDrawInfo*>& emissiv
 {
     LLGLDepthTest depth(GL_TRUE, GL_FALSE); //disable depth writes since "emissive" is additive so sorting doesn't matter
     pbr_emissive_shader->bind(true);
-    
+
     LLVOAvatar* lastAvatar = nullptr;
     U64 lastMeshId = 0;
 
@@ -588,7 +588,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
     BOOL initialized_lighting = FALSE;
-	BOOL light_enabled = TRUE;
+    BOOL light_enabled = TRUE;
 
     LLVOAvatar* lastAvatar = nullptr;
     U64 lastMeshId = 0;
@@ -607,7 +607,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)
         begin = gPipeline.beginAlphaGroups();
         end = gPipeline.endAlphaGroups();
     }
-    
+
     LLEnvironment& env = LLEnvironment::instance();
     F32 water_height = env.getWaterHeight();
 
@@ -619,15 +619,15 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)
 
 
     for (LLCullResult::sg_iterator i = begin; i != end; ++i)
-	{
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWPOOL("renderAlpha - group");
-		LLSpatialGroup* group = *i;
-		llassert(group);
-		llassert(group->getSpatialPartition());
+        LLSpatialGroup* group = *i;
+        llassert(group);
+        llassert(group->getSpatialPartition());
 
-		if (group->getSpatialPartition()->mRenderByGroup &&
-		    !group->isDead())
-		{
+        if (group->getSpatialPartition()->mRenderByGroup &&
+            !group->isDead())
+        {
 
             LLSpatialBridge* bridge = group->getSpatialPartition()->asBridge();
             const LLVector4a* ext = bridge ? bridge->getSpatialExtents() : group->getExtents();
@@ -660,17 +660,17 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)
             pbr_emissives.resize(0);
             pbr_rigged_emissives.resize(0);
 
-			bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE
-													  || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE;
+            bool is_particle_or_hud_particle = group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_PARTICLE
+                                                      || group->getSpatialPartition()->mPartitionType == LLViewerRegion::PARTITION_HUD_PARTICLE;
 
-			bool disable_cull = is_particle_or_hud_particle;
-			LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0);
+            bool disable_cull = is_particle_or_hud_particle;
+            LLGLDisable cull(disable_cull ? GL_CULL_FACE : 0);
 
-			LLSpatialGroup::drawmap_elem_t& draw_info = rigged ? group->mDrawMap[LLRenderPass::PASS_ALPHA_RIGGED] : group->mDrawMap[LLRenderPass::PASS_ALPHA];
+            LLSpatialGroup::drawmap_elem_t& draw_info = rigged ? group->mDrawMap[LLRenderPass::PASS_ALPHA_RIGGED] : group->mDrawMap[LLRenderPass::PASS_ALPHA];
 
             for (LLSpatialGroup::drawmap_elem_t::iterator k = draw_info.begin(); k != draw_info.end(); ++k)
-			{
-				LLDrawInfo& params = **k;
+            {
+                LLDrawInfo& params = **k;
                 if ((bool)params.mAvatar != rigged)
                 {
                     continue;
@@ -681,7 +681,7 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)
                 LLRenderPass::applyModelMatrix(params);
 
                 LLMaterial* mat = NULL;
-                LLGLTFMaterial *gltf_mat = params.mGLTFMaterial; 
+                LLGLTFMaterial *gltf_mat = params.mGLTFMaterial;
 
                 LLGLDisable cull_face(gltf_mat && gltf_mat->mDoubleSided ? GL_CULL_FACE : 0);
 
@@ -803,8 +803,8 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)
 
                 bool tex_setup = TexSetup(&params, (mat != nullptr));
 
-				{
-					gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor);
+                {
+                    gGL.blendFunc((LLRender::eBlendFactor) params.mBlendFuncSrc, (LLRender::eBlendFactor) params.mBlendFuncDst, mAlphaSFactor, mAlphaDFactor);
 
                     bool reset_minimum_alpha = false;
                     if (!LLPipeline::sImpostorRender &&
@@ -823,13 +823,13 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)
                     {
                         current_shader->setMinimumAlpha(MINIMUM_ALPHA);
                     }
-				}
+                }
 
-				// If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow).  Interleaving these state-changing calls is expensive, but glow must be drawn Z-sorted with alpha.
-				if (getType() != LLDrawPool::POOL_ALPHA_PRE_WATER &&
+                // If this alpha mesh has glow, then draw it a second time to add the destination-alpha (=glow).  Interleaving these state-changing calls is expensive, but glow must be drawn Z-sorted with alpha.
+                if (getType() != LLDrawPool::POOL_ALPHA_PRE_WATER &&
                     (!is_particle_or_hud_particle || params.mHasGlow) &&
-					params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE))
-				{
+                    params.mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE))
+                {
                     if (params.mAvatar != nullptr)
                     {
                         if (params.mGLTFMaterial.isNull())
@@ -852,16 +852,16 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)
                             pbr_emissives.push_back(&params);
                         }
                     }
-				}
-			
-				if (tex_setup)
-				{
-					gGL.getTexUnit(0)->activate();
+                }
+
+                if (tex_setup)
+                {
+                    gGL.getTexUnit(0)->activate();
                     gGL.matrixMode(LLRender::MM_TEXTURE);
-					gGL.loadIdentity();
-					gGL.matrixMode(LLRender::MM_MODELVIEW);
-				}
-			}
+                    gGL.loadIdentity();
+                    gGL.matrixMode(LLRender::MM_MODELVIEW);
+                }
+            }
 
             // render emissive faces into alpha channel for bloom effects
             if (!depth_only)
@@ -910,17 +910,17 @@ void LLDrawPoolAlpha::renderAlpha(U32 mask, bool depth_only, bool rigged)
                     lastShader->bind();
                 }
             }
-		}
-	}
+        }
+    }
 
-	gGL.setSceneBlendType(LLRender::BT_ALPHA);
+    gGL.setSceneBlendType(LLRender::BT_ALPHA);
 
-	LLVertexBuffer::unbind();
+    LLVertexBuffer::unbind();
 
-	if (!light_enabled)
-	{
-		gPipeline.enableLightsDynamic();
-	}
+    if (!light_enabled)
+    {
+        gPipeline.enableLightsDynamic();
+    }
 }
 
 bool LLDrawPoolAlpha::uploadMatrixPalette(const LLDrawInfo& params)
diff --git a/indra/newview/lldrawpoolbump.cpp b/indra/newview/lldrawpoolbump.cpp
index 70c44f75eca904ff833925ee27f69ba43e07d3d9..303e5effbe9335ea848496f4a91bf4f2dab13b1c 100644
--- a/indra/newview/lldrawpoolbump.cpp
+++ b/indra/newview/lldrawpoolbump.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lldrawpoolbump.cpp
  * @brief LLDrawPoolBump class implementation
  *
  * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -54,7 +54,7 @@
 //#include "../tools/imdebug/imdebug.h"
 
 // static
-LLStandardBumpmap gStandardBumpmapList[TEM_BUMPMAP_COUNT]; 
+LLStandardBumpmap gStandardBumpmapList[TEM_BUMPMAP_COUNT];
 LL::WorkQueue::weak_t LLBumpImageList::sMainQueue;
 LL::WorkQueue::weak_t LLBumpImageList::sTexUpdateQueue;
 LLRenderTarget LLBumpImageList::sRenderTarget;
@@ -84,13 +84,13 @@ static BOOL shiny = FALSE;
 #define LL_BUMPLIST_MULTITHREADED 1
 
 
-// static 
+// static
 void LLStandardBumpmap::shutdown()
 {
-	LLStandardBumpmap::destroyGL();
+    LLStandardBumpmap::destroyGL();
 }
 
-// static 
+// static
 void LLStandardBumpmap::restoreGL()
 {
     addstandard();
@@ -99,12 +99,12 @@ void LLStandardBumpmap::restoreGL()
 // static
 void LLStandardBumpmap::addstandard()
 {
-	if(!gTextureList.isInitialized())
-	{
-		//Note: loading pre-configuration sometimes triggers this call.
-		//But it is safe to return here because bump images will be reloaded during initialization later.
-		return ;
-	}
+    if(!gTextureList.isInitialized())
+    {
+        //Note: loading pre-configuration sometimes triggers this call.
+        //But it is safe to return here because bump images will be reloaded during initialization later.
+        return ;
+    }
 
     if (LLStartUp::getStartupState() < STATE_SEED_CAP_GRANTED)
     {
@@ -112,102 +112,102 @@ void LLStandardBumpmap::addstandard()
         return;
     }
 
-	// can't assert; we destroyGL and restoreGL a lot during *first* startup, which populates this list already, THEN we explicitly init the list as part of *normal* startup.  Sigh.  So clear the list every time before we (re-)add the standard bumpmaps.
-	//llassert( LLStandardBumpmap::sStandardBumpmapCount == 0 );
-	clear();
-	LL_INFOS() << "Adding standard bumpmaps." << LL_ENDL;
-	gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount++] = LLStandardBumpmap("None");		// BE_NO_BUMP
-	gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount++] = LLStandardBumpmap("Brightness");	// BE_BRIGHTNESS
-	gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount++] = LLStandardBumpmap("Darkness");	// BE_DARKNESS
-
-	std::string file_name = gDirUtilp->getExpandedFilename( LL_PATH_APP_SETTINGS, "std_bump.ini" );
-	LLFILE* file = LLFile::fopen( file_name, "rt" );	 /*Flawfinder: ignore*/
-	if( !file )
-	{
-		LL_WARNS() << "Could not open std_bump <" << file_name << ">" << LL_ENDL;
-		return;
-	}
-
-	S32 file_version = 0;
-
-	S32 fields_read = fscanf( file, "LLStandardBumpmap version %d", &file_version );
-	if( fields_read != 1 )
-	{
-		LL_WARNS() << "Bad LLStandardBumpmap header" << LL_ENDL;
-		fclose(file);
-		return;
-	}
-
-	if( file_version > STD_BUMP_LATEST_FILE_VERSION )
-	{
-		LL_WARNS() << "LLStandardBumpmap has newer version (" << file_version << ") than viewer (" << STD_BUMP_LATEST_FILE_VERSION << ")" << LL_ENDL;
-		fclose(file);
-		return;
-	}
-
-	while( !feof(file) && (LLStandardBumpmap::sStandardBumpmapCount < (U32)TEM_BUMPMAP_COUNT) )
-	{
-		// *NOTE: This buffer size is hard coded into scanf() below.
-		char label[2048] = "";	/* Flawfinder: ignore */
-		char bump_image_id[2048] = "";	/* Flawfinder: ignore */
-		fields_read = fscanf(	/* Flawfinder: ignore */
-			file, "\n%2047s %2047s", label, bump_image_id);
-		if( EOF == fields_read )
-		{
-			break;
-		}
-		if( fields_read != 2 )
-		{
-			LL_WARNS() << "Bad LLStandardBumpmap entry" << LL_ENDL;
-			fclose(file);
-			return;
-		}
-
-// 		LL_INFOS() << "Loading bumpmap: " << bump_image_id << " from viewerart" << LL_ENDL;
-		gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mLabel = label;
-		gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage = 
-			LLViewerTextureManager::getFetchedTexture(LLUUID(bump_image_id));	
-		gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->setBoostLevel(LLGLTexture::LOCAL) ;
-		gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->setLoadedCallback(LLBumpImageList::onSourceStandardLoaded, 0, TRUE, FALSE, NULL, NULL );
-		gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->forceToSaveRawImage(0, 30.f) ;
-		LLStandardBumpmap::sStandardBumpmapCount++;
-	}
-
-	fclose( file );
+    // can't assert; we destroyGL and restoreGL a lot during *first* startup, which populates this list already, THEN we explicitly init the list as part of *normal* startup.  Sigh.  So clear the list every time before we (re-)add the standard bumpmaps.
+    //llassert( LLStandardBumpmap::sStandardBumpmapCount == 0 );
+    clear();
+    LL_INFOS() << "Adding standard bumpmaps." << LL_ENDL;
+    gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount++] = LLStandardBumpmap("None");       // BE_NO_BUMP
+    gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount++] = LLStandardBumpmap("Brightness"); // BE_BRIGHTNESS
+    gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount++] = LLStandardBumpmap("Darkness");   // BE_DARKNESS
+
+    std::string file_name = gDirUtilp->getExpandedFilename( LL_PATH_APP_SETTINGS, "std_bump.ini" );
+    LLFILE* file = LLFile::fopen( file_name, "rt" );     /*Flawfinder: ignore*/
+    if( !file )
+    {
+        LL_WARNS() << "Could not open std_bump <" << file_name << ">" << LL_ENDL;
+        return;
+    }
+
+    S32 file_version = 0;
+
+    S32 fields_read = fscanf( file, "LLStandardBumpmap version %d", &file_version );
+    if( fields_read != 1 )
+    {
+        LL_WARNS() << "Bad LLStandardBumpmap header" << LL_ENDL;
+        fclose(file);
+        return;
+    }
+
+    if( file_version > STD_BUMP_LATEST_FILE_VERSION )
+    {
+        LL_WARNS() << "LLStandardBumpmap has newer version (" << file_version << ") than viewer (" << STD_BUMP_LATEST_FILE_VERSION << ")" << LL_ENDL;
+        fclose(file);
+        return;
+    }
+
+    while( !feof(file) && (LLStandardBumpmap::sStandardBumpmapCount < (U32)TEM_BUMPMAP_COUNT) )
+    {
+        // *NOTE: This buffer size is hard coded into scanf() below.
+        char label[2048] = "";  /* Flawfinder: ignore */
+        char bump_image_id[2048] = "";  /* Flawfinder: ignore */
+        fields_read = fscanf(   /* Flawfinder: ignore */
+            file, "\n%2047s %2047s", label, bump_image_id);
+        if( EOF == fields_read )
+        {
+            break;
+        }
+        if( fields_read != 2 )
+        {
+            LL_WARNS() << "Bad LLStandardBumpmap entry" << LL_ENDL;
+            fclose(file);
+            return;
+        }
+
+//      LL_INFOS() << "Loading bumpmap: " << bump_image_id << " from viewerart" << LL_ENDL;
+        gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mLabel = label;
+        gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage =
+            LLViewerTextureManager::getFetchedTexture(LLUUID(bump_image_id));
+        gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->setBoostLevel(LLGLTexture::LOCAL) ;
+        gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->setLoadedCallback(LLBumpImageList::onSourceStandardLoaded, 0, TRUE, FALSE, NULL, NULL );
+        gStandardBumpmapList[LLStandardBumpmap::sStandardBumpmapCount].mImage->forceToSaveRawImage(0, 30.f) ;
+        LLStandardBumpmap::sStandardBumpmapCount++;
+    }
+
+    fclose( file );
 }
 
 // static
 void LLStandardBumpmap::clear()
 {
-	LL_INFOS() << "Clearing standard bumpmaps." << LL_ENDL;
-	for( U32 i = 0; i < LLStandardBumpmap::sStandardBumpmapCount; i++ )
-	{
-		gStandardBumpmapList[i].mLabel.assign("");
-		gStandardBumpmapList[i].mImage = NULL;
-	}
-	sStandardBumpmapCount = 0;
+    LL_INFOS() << "Clearing standard bumpmaps." << LL_ENDL;
+    for( U32 i = 0; i < LLStandardBumpmap::sStandardBumpmapCount; i++ )
+    {
+        gStandardBumpmapList[i].mLabel.assign("");
+        gStandardBumpmapList[i].mImage = NULL;
+    }
+    sStandardBumpmapCount = 0;
 }
 
 // static
 void LLStandardBumpmap::destroyGL()
 {
-	clear();
+    clear();
 }
 
 
 
 ////////////////////////////////////////////////////////////////
 
-LLDrawPoolBump::LLDrawPoolBump() 
+LLDrawPoolBump::LLDrawPoolBump()
 :  LLRenderPass(LLDrawPool::POOL_BUMP)
 {
-	shiny = FALSE;
+    shiny = FALSE;
 }
 
 
 void LLDrawPoolBump::prerender()
 {
-	mShaderLevel = LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
+    mShaderLevel = LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT);
 }
 
 // static
@@ -220,80 +220,80 @@ S32 LLDrawPoolBump::numBumpPasses()
 //static
 void LLDrawPoolBump::bindCubeMap(LLGLSLShader* shader, S32 shader_level, S32& diffuse_channel, S32& cube_channel)
 {
-	LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
-	if( cube_map && !LLPipeline::sReflectionProbesEnabled )
-	{
-		if (shader )
-		{
-			if (shader_level > 1)
-			{
+    LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
+    if( cube_map && !LLPipeline::sReflectionProbesEnabled )
+    {
+        if (shader )
+        {
+            if (shader_level > 1)
+            {
                 cube_map->setMatrix(1);
-				// Make sure that texture coord generation happens for tex unit 1, as that's the one we use for 
-				// the cube map in the one pass shiny shaders
-				cube_channel = shader->enableTexture(LLViewerShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
-				cube_map->enableTexture(cube_channel);
-				diffuse_channel = shader->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
-			}
-			else
-			{
+                // Make sure that texture coord generation happens for tex unit 1, as that's the one we use for
+                // the cube map in the one pass shiny shaders
+                cube_channel = shader->enableTexture(LLViewerShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
+                cube_map->enableTexture(cube_channel);
+                diffuse_channel = shader->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
+            }
+            else
+            {
                 cube_map->setMatrix(0);
-				cube_channel = shader->enableTexture(LLViewerShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
-				diffuse_channel = -1;
-				cube_map->enable(cube_channel);
-			}			
-			gGL.getTexUnit(cube_channel)->bind(cube_map);
-			gGL.getTexUnit(0)->activate();
-		}
-		else
-		{
-			cube_channel = 0;
-			diffuse_channel = -1;
-			gGL.getTexUnit(0)->disable();
-			cube_map->enable(0);
+                cube_channel = shader->enableTexture(LLViewerShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
+                diffuse_channel = -1;
+                cube_map->enable(cube_channel);
+            }
+            gGL.getTexUnit(cube_channel)->bind(cube_map);
+            gGL.getTexUnit(0)->activate();
+        }
+        else
+        {
+            cube_channel = 0;
+            diffuse_channel = -1;
+            gGL.getTexUnit(0)->disable();
+            cube_map->enable(0);
             cube_map->setMatrix(0);
-			gGL.getTexUnit(0)->bind(cube_map);
-		}
-	}
+            gGL.getTexUnit(0)->bind(cube_map);
+        }
+    }
 }
 
 //static
 void LLDrawPoolBump::unbindCubeMap(LLGLSLShader* shader, S32 shader_level, S32& diffuse_channel, S32& cube_channel)
 {
-	LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
-	if( cube_map && !LLPipeline::sReflectionProbesEnabled)
-	{
-		if (shader_level > 1)
-		{
-			shader->disableTexture(LLViewerShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
-					
-			if (LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 0)
-			{
-				if (diffuse_channel != 0)
-				{
-					shader->disableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
-				}
-			}
-		}
+    LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
+    if( cube_map && !LLPipeline::sReflectionProbesEnabled)
+    {
+        if (shader_level > 1)
+        {
+            shader->disableTexture(LLViewerShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
+
+            if (LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 0)
+            {
+                if (diffuse_channel != 0)
+                {
+                    shader->disableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
+                }
+            }
+        }
         // Moved below shader->disableTexture call to avoid false alarms from auto-re-enable of textures on stage 0
         // MAINT-755
-		cube_map->disable();
+        cube_map->disable();
         cube_map->restoreMatrix();
-	}
+    }
 }
 
 void LLDrawPoolBump::beginFullbrightShiny()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_SHINY);
-	
-	sVertexMask = VERTEX_MASK_SHINY | LLVertexBuffer::MAP_TEXCOORD0;
 
-	// Second pass: environment map
-	shader = &gDeferredFullbrightShinyProgram;
+    sVertexMask = VERTEX_MASK_SHINY | LLVertexBuffer::MAP_TEXCOORD0;
+
+    // Second pass: environment map
+    shader = &gDeferredFullbrightShinyProgram;
     if (LLPipeline::sRenderingHUDs)
     {
         shader = &gHUDFullbrightShinyProgram;
     }
-    
+
     if (mRigged)
     {
         llassert(shader->mRiggedVariant);
@@ -307,23 +307,23 @@ void LLDrawPoolBump::beginFullbrightShiny()
         gGL.getTexUnit(channel)->bind(&gPipeline.mExposureMap);
     }
 
-	LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
-	
+    LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
+
     if (cube_map && !LLPipeline::sReflectionProbesEnabled)
     {
-        // Make sure that texture coord generation happens for tex unit 1, as that's the one we use for 
-		// the cube map in the one pass shiny shaders
-		gGL.getTexUnit(1)->disable();
-		cube_channel = shader->enableTexture(LLViewerShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
-		cube_map->enableTexture(cube_channel);
-		diffuse_channel = shader->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
-
-		gGL.getTexUnit(cube_channel)->bind(cube_map);
-		gGL.getTexUnit(0)->activate();
+        // Make sure that texture coord generation happens for tex unit 1, as that's the one we use for
+        // the cube map in the one pass shiny shaders
+        gGL.getTexUnit(1)->disable();
+        cube_channel = shader->enableTexture(LLViewerShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
+        cube_map->enableTexture(cube_channel);
+        diffuse_channel = shader->enableTexture(LLViewerShaderMgr::DIFFUSE_MAP);
+
+        gGL.getTexUnit(cube_channel)->bind(cube_map);
+        gGL.getTexUnit(0)->activate();
     }
 
-	{
-		shader->bind();
+    {
+        shader->bind();
         if (LLPipeline::sReflectionProbesEnabled)
         {
             gPipeline.bindReflectionProbes(*shader);
@@ -332,25 +332,25 @@ void LLDrawPoolBump::beginFullbrightShiny()
         {
             gPipeline.setEnvMat(*shader);
         }
-	}
+    }
 
-	if (mShaderLevel > 1)
-	{ //indexed texture rendering, channel 0 is always diffuse
-		diffuse_channel = 0;
-	}
+    if (mShaderLevel > 1)
+    { //indexed texture rendering, channel 0 is always diffuse
+        diffuse_channel = 0;
+    }
 
-	shiny = TRUE;
+    shiny = TRUE;
 }
 
 void LLDrawPoolBump::renderFullbrightShiny()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_SHINY);
 
-	{
-		LLGLEnable blend_enable(GL_BLEND);
+    {
+        LLGLEnable blend_enable(GL_BLEND);
 
-		if (mShaderLevel > 1)
-		{
+        if (mShaderLevel > 1)
+        {
             if (mRigged)
             {
                 LLRenderPass::pushRiggedBatches(LLRenderPass::PASS_FULLBRIGHT_SHINY_RIGGED, true, true);
@@ -359,9 +359,9 @@ void LLDrawPoolBump::renderFullbrightShiny()
             {
                 LLRenderPass::pushBatches(LLRenderPass::PASS_FULLBRIGHT_SHINY, true, true);
             }
-		}
-		else
-		{
+        }
+        else
+        {
             if (mRigged)
             {
                 LLRenderPass::pushRiggedBatches(LLRenderPass::PASS_FULLBRIGHT_SHINY_RIGGED);
@@ -370,125 +370,125 @@ void LLDrawPoolBump::renderFullbrightShiny()
             {
                 LLRenderPass::pushBatches(LLRenderPass::PASS_FULLBRIGHT_SHINY);
             }
-		}
-	}
+        }
+    }
 }
 
 void LLDrawPoolBump::endFullbrightShiny()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_SHINY);
 
-	LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
-	if( cube_map && !LLPipeline::sReflectionProbesEnabled )
-	{
-		cube_map->disable();
+    LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
+    if( cube_map && !LLPipeline::sReflectionProbesEnabled )
+    {
+        cube_map->disable();
         if (shader->mFeatures.hasReflectionProbes)
         {
             gPipeline.unbindReflectionProbes(*shader);
         }
-		shader->unbind();
-	}
-	
-	diffuse_channel = -1;
-	cube_channel = 0;
-	shiny = FALSE;
+        shader->unbind();
+    }
+
+    diffuse_channel = -1;
+    cube_channel = 0;
+    shiny = FALSE;
 }
 
 void LLDrawPoolBump::renderGroup(LLSpatialGroup* group, U32 type, bool texture = true)
-{					
-	LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[type];	
-	
-	for (LLDrawInfo* k : draw_info)
-	{
-		LLDrawInfo& params = *k;
-		
-		applyModelMatrix(params);
-
-		params.mVertexBuffer->setBuffer();
-		params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart, params.mEnd, params.mCount, params.mOffset);
-	}
+{
+    LLSpatialGroup::drawmap_elem_t& draw_info = group->mDrawMap[type];
+
+    for (LLDrawInfo* k : draw_info)
+    {
+        LLDrawInfo& params = *k;
+
+        applyModelMatrix(params);
+
+        params.mVertexBuffer->setBuffer();
+        params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart, params.mEnd, params.mCount, params.mOffset);
+    }
 }
 
 
 // static
 BOOL LLDrawPoolBump::bindBumpMap(LLDrawInfo& params, S32 channel)
 {
-	U8 bump_code = params.mBump;
+    U8 bump_code = params.mBump;
 
-	return bindBumpMap(bump_code, params.mTexture, channel);
+    return bindBumpMap(bump_code, params.mTexture, channel);
 }
 
 //static
 BOOL LLDrawPoolBump::bindBumpMap(LLFace* face, S32 channel)
 {
-	const LLTextureEntry* te = face->getTextureEntry();
-	if (te)
-	{
-		U8 bump_code = te->getBumpmap();
-		return bindBumpMap(bump_code, face->getTexture(), channel);
-	}
-
-	return FALSE;
+    const LLTextureEntry* te = face->getTextureEntry();
+    if (te)
+    {
+        U8 bump_code = te->getBumpmap();
+        return bindBumpMap(bump_code, face->getTexture(), channel);
+    }
+
+    return FALSE;
 }
 
 //static
 BOOL LLDrawPoolBump::bindBumpMap(U8 bump_code, LLViewerTexture* texture, S32 channel)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-	//Note: texture atlas does not support bump texture now.
-	LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(texture) ;
-	if(!tex)
-	{
-		//if the texture is not a fetched texture
-		return FALSE;
-	}
-
-	LLViewerTexture* bump = NULL;
-
-	switch( bump_code )
-	{
-	case BE_NO_BUMP:		
-		break;
-	case BE_BRIGHTNESS: 
-	case BE_DARKNESS:
-		bump = gBumpImageList.getBrightnessDarknessImage( tex, bump_code );
-		break;
-
-	default:
-		if( bump_code < LLStandardBumpmap::sStandardBumpmapCount )
-		{
-			bump = gStandardBumpmapList[bump_code].mImage;
-			gBumpImageList.addTextureStats(bump_code, tex->getID(), tex->getMaxVirtualSize());
-		}
-		break;
-	}
-
-	if (bump)
-	{
-		if (channel == -2)
-		{
-			gGL.getTexUnit(1)->bindFast(bump);
-			gGL.getTexUnit(0)->bindFast(bump);
-		}
-		else
-		{
+    //Note: texture atlas does not support bump texture now.
+    LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(texture) ;
+    if(!tex)
+    {
+        //if the texture is not a fetched texture
+        return FALSE;
+    }
+
+    LLViewerTexture* bump = NULL;
+
+    switch( bump_code )
+    {
+    case BE_NO_BUMP:
+        break;
+    case BE_BRIGHTNESS:
+    case BE_DARKNESS:
+        bump = gBumpImageList.getBrightnessDarknessImage( tex, bump_code );
+        break;
+
+    default:
+        if( bump_code < LLStandardBumpmap::sStandardBumpmapCount )
+        {
+            bump = gStandardBumpmapList[bump_code].mImage;
+            gBumpImageList.addTextureStats(bump_code, tex->getID(), tex->getMaxVirtualSize());
+        }
+        break;
+    }
+
+    if (bump)
+    {
+        if (channel == -2)
+        {
+            gGL.getTexUnit(1)->bindFast(bump);
+            gGL.getTexUnit(0)->bindFast(bump);
+        }
+        else
+        {
             // NOTE: do not use bindFast here (see SL-16222)
             gGL.getTexUnit(channel)->bind(bump);
-		}
+        }
 
-		return TRUE;
-	}
+        return TRUE;
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 //static
 void LLDrawPoolBump::beginBump()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_BUMP);
-	sVertexMask = VERTEX_MASK_BUMP;
-	// Optional second pass: emboss bump map
-	stop_glerror();
+    sVertexMask = VERTEX_MASK_BUMP;
+    // Optional second pass: emboss bump map
+    stop_glerror();
 
     shader = &gObjectBumpProgram;
 
@@ -500,21 +500,21 @@ void LLDrawPoolBump::beginBump()
 
     shader->bind();
 
-	gGL.setSceneBlendType(LLRender::BT_MULT_X2);
-	stop_glerror();
+    gGL.setSceneBlendType(LLRender::BT_MULT_X2);
+    stop_glerror();
 }
 
 //static
 void LLDrawPoolBump::renderBump(U32 pass)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_BUMP);
-	LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_LEQUAL);
-	LLGLEnable blend(GL_BLEND);
-	gGL.diffuseColor4f(1,1,1,1);
-	/// Get rid of z-fighting with non-bump pass.
-	LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
-	glPolygonOffset(-1.0f, -1.0f);
-	pushBumpBatches(pass);
+    LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_LEQUAL);
+    LLGLEnable blend(GL_BLEND);
+    gGL.diffuseColor4f(1,1,1,1);
+    /// Get rid of z-fighting with non-bump pass.
+    LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
+    glPolygonOffset(-1.0f, -1.0f);
+    pushBumpBatches(pass);
 }
 
 //static
@@ -526,7 +526,7 @@ void LLDrawPoolBump::endBump(U32 pass)
 }
 
 S32 LLDrawPoolBump::getNumDeferredPasses()
-{ 
+{
     return 1;
 }
 
@@ -589,7 +589,7 @@ void LLDrawPoolBump::renderDeferred(S32 pass)
 void LLDrawPoolBump::renderPostDeferred(S32 pass)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-    
+
     S32 num_passes = LLPipeline::sRenderingHUDs ? 1 : 2; // skip rigged pass when rendering HUDs
 
     for (int i = 0; i < num_passes; ++i)
@@ -617,127 +617,127 @@ void LLDrawPoolBump::renderPostDeferred(S32 pass)
 
 void LLBumpImageList::init()
 {
-	llassert( mBrightnessEntries.size() == 0 );
-	llassert( mDarknessEntries.size() == 0 );
+    llassert( mBrightnessEntries.size() == 0 );
+    llassert( mDarknessEntries.size() == 0 );
 
-	LLStandardBumpmap::restoreGL();
+    LLStandardBumpmap::restoreGL();
     sMainQueue = LL::WorkQueue::getInstance("mainloop");
     sTexUpdateQueue = LL::WorkQueue::getInstance("LLImageGL"); // Share work queue with tex loader.
 }
 
 void LLBumpImageList::clear()
 {
-	LL_INFOS() << "Clearing dynamic bumpmaps." << LL_ENDL;
-	// these will be re-populated on-demand
-	mBrightnessEntries.clear();
-	mDarknessEntries.clear();
+    LL_INFOS() << "Clearing dynamic bumpmaps." << LL_ENDL;
+    // these will be re-populated on-demand
+    mBrightnessEntries.clear();
+    mDarknessEntries.clear();
 
     sRenderTarget.release();
 
-	LLStandardBumpmap::clear();
+    LLStandardBumpmap::clear();
 }
 
 void LLBumpImageList::shutdown()
 {
-	clear();
-	LLStandardBumpmap::shutdown();
+    clear();
+    LLStandardBumpmap::shutdown();
 }
 
 void LLBumpImageList::destroyGL()
 {
-	clear();
-	LLStandardBumpmap::destroyGL();
+    clear();
+    LLStandardBumpmap::destroyGL();
 }
 
 void LLBumpImageList::restoreGL()
 {
-	if(!gTextureList.isInitialized())
-	{
-		//safe to return here because bump images will be reloaded during initialization later.
-		return ;
-	}
-
-	LLStandardBumpmap::restoreGL();
-	// Images will be recreated as they are needed.
+    if(!gTextureList.isInitialized())
+    {
+        //safe to return here because bump images will be reloaded during initialization later.
+        return ;
+    }
+
+    LLStandardBumpmap::restoreGL();
+    // Images will be recreated as they are needed.
 }
 
 
 LLBumpImageList::~LLBumpImageList()
 {
-	// Shutdown should have already been called.
-	llassert( mBrightnessEntries.size() == 0 );
-	llassert( mDarknessEntries.size() == 0 );
+    // Shutdown should have already been called.
+    llassert( mBrightnessEntries.size() == 0 );
+    llassert( mDarknessEntries.size() == 0 );
 }
 
 
 // Note: Does nothing for entries in gStandardBumpmapList that are not actually standard bump images (e.g. none, brightness, and darkness)
 void LLBumpImageList::addTextureStats(U8 bump, const LLUUID& base_image_id, F32 virtual_size)
 {
-	bump &= TEM_BUMP_MASK;
-	LLViewerFetchedTexture* bump_image = gStandardBumpmapList[bump].mImage;
-	if( bump_image )
-	{		
-		bump_image->addTextureStats(virtual_size);
-	}
+    bump &= TEM_BUMP_MASK;
+    LLViewerFetchedTexture* bump_image = gStandardBumpmapList[bump].mImage;
+    if( bump_image )
+    {
+        bump_image->addTextureStats(virtual_size);
+    }
 }
 
 
 void LLBumpImageList::updateImages()
-{	
-	for (bump_image_map_t::iterator iter = mBrightnessEntries.begin(); iter != mBrightnessEntries.end(); )
-	{
-		LLViewerTexture* image = iter->second;
-		if( image )
-		{
-			BOOL destroy = TRUE;
-			if( image->hasGLTexture())
-			{
-				if( image->getBoundRecently() )
-				{
-					destroy = FALSE;
-				}
-				else
-				{
-					image->destroyGLTexture();
-				}
-			}
-
-			if( destroy )
-			{
-				//LL_INFOS() << "*** Destroying bright " << (void*)image << LL_ENDL;
-				iter = mBrightnessEntries.erase(iter);   // deletes the image thanks to reference counting
+{
+    for (bump_image_map_t::iterator iter = mBrightnessEntries.begin(); iter != mBrightnessEntries.end(); )
+    {
+        LLViewerTexture* image = iter->second;
+        if( image )
+        {
+            BOOL destroy = TRUE;
+            if( image->hasGLTexture())
+            {
+                if( image->getBoundRecently() )
+                {
+                    destroy = FALSE;
+                }
+                else
+                {
+                    image->destroyGLTexture();
+                }
+            }
+
+            if( destroy )
+            {
+                //LL_INFOS() << "*** Destroying bright " << (void*)image << LL_ENDL;
+                iter = mBrightnessEntries.erase(iter);   // deletes the image thanks to reference counting
                 continue;
-			}
-		}
+            }
+        }
         ++iter;
-	}
-	
-	for (bump_image_map_t::iterator iter = mDarknessEntries.begin(); iter != mDarknessEntries.end(); )
-	{
-		bump_image_map_t::iterator curiter = iter++;
-		LLViewerTexture* image = curiter->second;
-		if( image )
-		{
-			BOOL destroy = TRUE;
-			if( image->hasGLTexture())
-			{
-				if( image->getBoundRecently() )
-				{
-					destroy = FALSE;
-				}
-				else
-				{
-					image->destroyGLTexture();
-				}
-			}
-
-			if( destroy )
-			{
-				//LL_INFOS() << "*** Destroying dark " << (void*)image << LL_ENDL;;
-				mDarknessEntries.erase(curiter);  // deletes the image thanks to reference counting
-			}
-		}
-	}
+    }
+
+    for (bump_image_map_t::iterator iter = mDarknessEntries.begin(); iter != mDarknessEntries.end(); )
+    {
+        bump_image_map_t::iterator curiter = iter++;
+        LLViewerTexture* image = curiter->second;
+        if( image )
+        {
+            BOOL destroy = TRUE;
+            if( image->hasGLTexture())
+            {
+                if( image->getBoundRecently() )
+                {
+                    destroy = FALSE;
+                }
+                else
+                {
+                    image->destroyGLTexture();
+                }
+            }
+
+            if( destroy )
+            {
+                //LL_INFOS() << "*** Destroying dark " << (void*)image << LL_ENDL;;
+                mDarknessEntries.erase(curiter);  // deletes the image thanks to reference counting
+            }
+        }
+    }
 }
 
 
@@ -745,52 +745,52 @@ void LLBumpImageList::updateImages()
 LLViewerTexture* LLBumpImageList::getBrightnessDarknessImage(LLViewerFetchedTexture* src_image, U8 bump_code )
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-	llassert( (bump_code == BE_BRIGHTNESS) || (bump_code == BE_DARKNESS) );
-
-	LLViewerTexture* bump = NULL;
-	
-	bump_image_map_t* entries_list = NULL;
-	void (*callback_func)( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata ) = NULL;
-
-	switch( bump_code )
-	{
-	case BE_BRIGHTNESS:
-		entries_list = &mBrightnessEntries;
-		callback_func = LLBumpImageList::onSourceBrightnessLoaded;
-		break;
-	case BE_DARKNESS:
-		entries_list = &mDarknessEntries;
-		callback_func = LLBumpImageList::onSourceDarknessLoaded;
-		break;
-	default:
-		llassert(0);
-		return NULL;
-	}
-
-	bump_image_map_t::iterator iter = entries_list->find(src_image->getID());
-	if (iter != entries_list->end() && iter->second.notNull())
-	{
-		bump = iter->second;
-	}
-	else
-	{
-		(*entries_list)[src_image->getID()] = LLViewerTextureManager::getLocalTexture( TRUE );
-		bump = (*entries_list)[src_image->getID()]; // In case callback was called immediately and replaced the image
-	}
-
-	if (!src_image->hasCallbacks())
-	{ //if image has no callbacks but resolutions don't match, trigger raw image loaded callback again
-		if (src_image->getWidth() != bump->getWidth() ||
-			src_image->getHeight() != bump->getHeight())// ||
-			//(LLPipeline::sRenderDeferred && bump->getComponents() != 4))
-		{
-			src_image->setBoostLevel(LLGLTexture::BOOST_BUMP) ;
-			src_image->setLoadedCallback( callback_func, 0, TRUE, FALSE, new LLUUID(src_image->getID()), NULL );
-			src_image->forceToSaveRawImage(0) ;
-		}
-	}
-
-	return bump;
+    llassert( (bump_code == BE_BRIGHTNESS) || (bump_code == BE_DARKNESS) );
+
+    LLViewerTexture* bump = NULL;
+
+    bump_image_map_t* entries_list = NULL;
+    void (*callback_func)( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata ) = NULL;
+
+    switch( bump_code )
+    {
+    case BE_BRIGHTNESS:
+        entries_list = &mBrightnessEntries;
+        callback_func = LLBumpImageList::onSourceBrightnessLoaded;
+        break;
+    case BE_DARKNESS:
+        entries_list = &mDarknessEntries;
+        callback_func = LLBumpImageList::onSourceDarknessLoaded;
+        break;
+    default:
+        llassert(0);
+        return NULL;
+    }
+
+    bump_image_map_t::iterator iter = entries_list->find(src_image->getID());
+    if (iter != entries_list->end() && iter->second.notNull())
+    {
+        bump = iter->second;
+    }
+    else
+    {
+        (*entries_list)[src_image->getID()] = LLViewerTextureManager::getLocalTexture( TRUE );
+        bump = (*entries_list)[src_image->getID()]; // In case callback was called immediately and replaced the image
+    }
+
+    if (!src_image->hasCallbacks())
+    { //if image has no callbacks but resolutions don't match, trigger raw image loaded callback again
+        if (src_image->getWidth() != bump->getWidth() ||
+            src_image->getHeight() != bump->getHeight())// ||
+            //(LLPipeline::sRenderDeferred && bump->getComponents() != 4))
+        {
+            src_image->setBoostLevel(LLGLTexture::BOOST_BUMP) ;
+            src_image->setLoadedCallback( callback_func, 0, TRUE, FALSE, new LLUUID(src_image->getID()), NULL );
+            src_image->forceToSaveRawImage(0) ;
+        }
+    }
+
+    return bump;
 }
 
 
@@ -798,94 +798,94 @@ LLViewerTexture* LLBumpImageList::getBrightnessDarknessImage(LLViewerFetchedText
 void LLBumpImageList::onSourceBrightnessLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata )
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-	LLUUID* source_asset_id = (LLUUID*)userdata;
-	LLBumpImageList::onSourceLoaded( success, src_vi, src, *source_asset_id, BE_BRIGHTNESS );
-	if( final )
-	{
-		delete source_asset_id;
-	}
+    LLUUID* source_asset_id = (LLUUID*)userdata;
+    LLBumpImageList::onSourceLoaded( success, src_vi, src, *source_asset_id, BE_BRIGHTNESS );
+    if( final )
+    {
+        delete source_asset_id;
+    }
 }
 
 // static
 void LLBumpImageList::onSourceDarknessLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata )
 {
-	LLUUID* source_asset_id = (LLUUID*)userdata;
-	LLBumpImageList::onSourceLoaded( success, src_vi, src, *source_asset_id, BE_DARKNESS );
-	if( final )
-	{
-		delete source_asset_id;
-	}
+    LLUUID* source_asset_id = (LLUUID*)userdata;
+    LLBumpImageList::onSourceLoaded( success, src_vi, src, *source_asset_id, BE_DARKNESS );
+    if( final )
+    {
+        delete source_asset_id;
+    }
 }
 
 void LLBumpImageList::onSourceStandardLoaded( BOOL success, LLViewerFetchedTexture* src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
 {
-	if (success && LLPipeline::sRenderDeferred)
-	{
+    if (success && LLPipeline::sRenderDeferred)
+    {
         LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-		LLPointer<LLImageRaw> nrm_image = new LLImageRaw(src->getWidth(), src->getHeight(), 4);
-		{
-			generateNormalMapFromAlpha(src, nrm_image);
-		}
-		src_vi->setExplicitFormat(GL_RGBA, GL_RGBA);
-		{
-			src_vi->createGLTexture(src_vi->getDiscardLevel(), nrm_image);
-		}
-	}
+        LLPointer<LLImageRaw> nrm_image = new LLImageRaw(src->getWidth(), src->getHeight(), 4);
+        {
+            generateNormalMapFromAlpha(src, nrm_image);
+        }
+        src_vi->setExplicitFormat(GL_RGBA, GL_RGBA);
+        {
+            src_vi->createGLTexture(src_vi->getDiscardLevel(), nrm_image);
+        }
+    }
 }
 
 void LLBumpImageList::generateNormalMapFromAlpha(LLImageRaw* src, LLImageRaw* nrm_image)
 {
-	U8* nrm_data = nrm_image->getData();
-	S32 resX = src->getWidth();
-	S32 resY = src->getHeight();
-
-	U8* src_data = src->getData();
-
-	S32 src_cmp = src->getComponents();
-
-	F32 norm_scale = LLPipeline::RenderNormalMapScale;
-
-	U32 idx = 0;
-	//generate normal map from pseudo-heightfield
-	for (S32 j = 0; j < resY; ++j)
-	{
-		for (S32 i = 0; i < resX; ++i)
-		{
-			S32 rX = (i+1)%resX;
-			S32 rY = (j+1)%resY;
-			S32 lX = (i-1)%resX;
-			S32 lY = (j-1)%resY;
-
-			if (lX < 0)
-			{
-				lX += resX;
-			}
-			if (lY < 0)
-			{
-				lY += resY;
-			}
-
-			F32 cH = (F32) src_data[(j*resX+i)*src_cmp+src_cmp-1];
-
-			LLVector3 right = LLVector3(norm_scale, 0, (F32) src_data[(j*resX+rX)*src_cmp+src_cmp-1]-cH);
-			LLVector3 left = LLVector3(-norm_scale, 0, (F32) src_data[(j*resX+lX)*src_cmp+src_cmp-1]-cH);
-			LLVector3 up = LLVector3(0, -norm_scale, (F32) src_data[(lY*resX+i)*src_cmp+src_cmp-1]-cH);
-			LLVector3 down = LLVector3(0, norm_scale, (F32) src_data[(rY*resX+i)*src_cmp+src_cmp-1]-cH);
-
-			LLVector3 norm = right%down + down%left + left%up + up%right;
-		
-			norm.normVec();
-			
-			norm *= 0.5f;
-			norm += LLVector3(0.5f,0.5f,0.5f);
-
-			idx = (j*resX+i)*4;
-			nrm_data[idx+0]= (U8) (norm.mV[0]*255);
-			nrm_data[idx+1]= (U8) (norm.mV[1]*255);
-			nrm_data[idx+2]= (U8) (norm.mV[2]*255);
-			nrm_data[idx+3]= src_data[(j*resX+i)*src_cmp+src_cmp-1];
-		}
-	}
+    U8* nrm_data = nrm_image->getData();
+    S32 resX = src->getWidth();
+    S32 resY = src->getHeight();
+
+    U8* src_data = src->getData();
+
+    S32 src_cmp = src->getComponents();
+
+    F32 norm_scale = LLPipeline::RenderNormalMapScale;
+
+    U32 idx = 0;
+    //generate normal map from pseudo-heightfield
+    for (S32 j = 0; j < resY; ++j)
+    {
+        for (S32 i = 0; i < resX; ++i)
+        {
+            S32 rX = (i+1)%resX;
+            S32 rY = (j+1)%resY;
+            S32 lX = (i-1)%resX;
+            S32 lY = (j-1)%resY;
+
+            if (lX < 0)
+            {
+                lX += resX;
+            }
+            if (lY < 0)
+            {
+                lY += resY;
+            }
+
+            F32 cH = (F32) src_data[(j*resX+i)*src_cmp+src_cmp-1];
+
+            LLVector3 right = LLVector3(norm_scale, 0, (F32) src_data[(j*resX+rX)*src_cmp+src_cmp-1]-cH);
+            LLVector3 left = LLVector3(-norm_scale, 0, (F32) src_data[(j*resX+lX)*src_cmp+src_cmp-1]-cH);
+            LLVector3 up = LLVector3(0, -norm_scale, (F32) src_data[(lY*resX+i)*src_cmp+src_cmp-1]-cH);
+            LLVector3 down = LLVector3(0, norm_scale, (F32) src_data[(rY*resX+i)*src_cmp+src_cmp-1]-cH);
+
+            LLVector3 norm = right%down + down%left + left%up + up%right;
+
+            norm.normVec();
+
+            norm *= 0.5f;
+            norm += LLVector3(0.5f,0.5f,0.5f);
+
+            idx = (j*resX+i)*4;
+            nrm_data[idx+0]= (U8) (norm.mV[0]*255);
+            nrm_data[idx+1]= (U8) (norm.mV[1]*255);
+            nrm_data[idx+2]= (U8) (norm.mV[2]*255);
+            nrm_data[idx+3]= src_data[(j*resX+i)*src_cmp+src_cmp-1];
+        }
+    }
 }
 
 // static
@@ -893,147 +893,147 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI
 {
     LL_PROFILE_ZONE_SCOPED;
 
-	if( success )
-	{
+    if( success )
+    {
         LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
 
 
-		bump_image_map_t& entries_list(bump_code == BE_BRIGHTNESS ? gBumpImageList.mBrightnessEntries : gBumpImageList.mDarknessEntries );
-		bump_image_map_t::iterator iter = entries_list.find(source_asset_id);
-
-		{
-			if (iter == entries_list.end() ||
-				iter->second.isNull() ||
-							iter->second->getWidth() != src->getWidth() ||
-							iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution
-			{ //make sure an entry exists for this image
-				entries_list[src_vi->getID()] = LLViewerTextureManager::getLocalTexture(TRUE);
-				iter = entries_list.find(src_vi->getID());
-			}
-		}
-
-		if (iter->second->getWidth() != src->getWidth() ||
-			iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution
-		{
-			LLPointer<LLImageRaw> dst_image = new LLImageRaw(src->getWidth(), src->getHeight(), 1);
-			U8* dst_data = dst_image->getData();
-			S32 dst_data_size = dst_image->getDataSize();
-
-			U8* src_data = src->getData();
-			S32 src_data_size = src->getDataSize();
-
-			S32 src_components = src->getComponents();
-
-			// Convert to luminance and then scale and bias that to get ready for
-			// embossed bump mapping.  (0-255 maps to 127-255)
-
-			// Convert to fixed point so we don't have to worry about precision/clamping.
-			const S32 FIXED_PT = 8;
-			const S32 R_WEIGHT = S32(0.2995f * (1<<FIXED_PT));
-			const S32 G_WEIGHT = S32(0.5875f * (1<<FIXED_PT));
-			const S32 B_WEIGHT = S32(0.1145f * (1<<FIXED_PT));
-
-			S32 minimum = 255;
-			S32 maximum = 0;
-
-			switch( src_components )
-			{
-			case 1:
-			case 2:
-				{
-					if( src_data_size == dst_data_size * src_components )
-					{
-						for( S32 i = 0, j=0; i < dst_data_size; i++, j+= src_components )
-						{
-							dst_data[i] = src_data[j];
-							if( dst_data[i] < minimum )
-							{
-								minimum = dst_data[i];
-							}
-							if( dst_data[i] > maximum )
-							{
-								maximum = dst_data[i];
-							}
-						}
-					}
-					else
-					{
-						llassert(0);
-						dst_image->clear();
-					}
-				}
-				break;
-			case 3:
-			case 4:
-				{
-					if( src_data_size == dst_data_size * src_components )
-					{
-						for( S32 i = 0, j=0; i < dst_data_size; i++, j+= src_components )
-						{
-							// RGB to luminance
-							dst_data[i] = (R_WEIGHT * src_data[j] + G_WEIGHT * src_data[j+1] + B_WEIGHT * src_data[j+2]) >> FIXED_PT;
-							//llassert( dst_data[i] <= 255 );true because it's 8bit
-							if( dst_data[i] < minimum )
-							{
-								minimum = dst_data[i];
-							}
-							if( dst_data[i] > maximum )
-							{
-								maximum = dst_data[i];
-							}
-						}
-					}
-					else
-					{
-						llassert(0);
-						dst_image->clear();
-					}
-				}
-				break;
-			default:
-				llassert(0);
-				dst_image->clear();
-				break;
-			}
-
-			if( maximum > minimum )
-			{
-				U8 bias_and_scale_lut[256];
-				F32 twice_one_over_range = 2.f / (maximum - minimum);
-				S32 i;
-
-				const F32 ARTIFICIAL_SCALE = 2.f;  // Advantage: exaggerates the effect in midrange.  Disadvantage: clamps at the extremes.
-				if (BE_DARKNESS == bump_code)
-				{
-					for( i = minimum; i <= maximum; i++ )
-					{
-						F32 minus_one_to_one = F32(maximum - i) * twice_one_over_range - 1.f;
-						bias_and_scale_lut[i] = llclampb(ll_round(127 * minus_one_to_one * ARTIFICIAL_SCALE + 128));
-					}
-				}
-				else
-				{
-					for( i = minimum; i <= maximum; i++ )
-					{
-						F32 minus_one_to_one = F32(i - minimum) * twice_one_over_range - 1.f;
-						bias_and_scale_lut[i] = llclampb(ll_round(127 * minus_one_to_one * ARTIFICIAL_SCALE + 128));
-					}
-				}
-
-				for( i = 0; i < dst_data_size; i++ )
-				{
-					dst_data[i] = bias_and_scale_lut[dst_data[i]];
-				}
-			}
-
-			//---------------------------------------------------
-			// immediately assign bump to a smart pointer in case some local smart pointer
-			// accidentally releases it.
+        bump_image_map_t& entries_list(bump_code == BE_BRIGHTNESS ? gBumpImageList.mBrightnessEntries : gBumpImageList.mDarknessEntries );
+        bump_image_map_t::iterator iter = entries_list.find(source_asset_id);
+
+        {
+            if (iter == entries_list.end() ||
+                iter->second.isNull() ||
+                            iter->second->getWidth() != src->getWidth() ||
+                            iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution
+            { //make sure an entry exists for this image
+                entries_list[src_vi->getID()] = LLViewerTextureManager::getLocalTexture(TRUE);
+                iter = entries_list.find(src_vi->getID());
+            }
+        }
+
+        if (iter->second->getWidth() != src->getWidth() ||
+            iter->second->getHeight() != src->getHeight()) // bump not cached yet or has changed resolution
+        {
+            LLPointer<LLImageRaw> dst_image = new LLImageRaw(src->getWidth(), src->getHeight(), 1);
+            U8* dst_data = dst_image->getData();
+            S32 dst_data_size = dst_image->getDataSize();
+
+            U8* src_data = src->getData();
+            S32 src_data_size = src->getDataSize();
+
+            S32 src_components = src->getComponents();
+
+            // Convert to luminance and then scale and bias that to get ready for
+            // embossed bump mapping.  (0-255 maps to 127-255)
+
+            // Convert to fixed point so we don't have to worry about precision/clamping.
+            const S32 FIXED_PT = 8;
+            const S32 R_WEIGHT = S32(0.2995f * (1<<FIXED_PT));
+            const S32 G_WEIGHT = S32(0.5875f * (1<<FIXED_PT));
+            const S32 B_WEIGHT = S32(0.1145f * (1<<FIXED_PT));
+
+            S32 minimum = 255;
+            S32 maximum = 0;
+
+            switch( src_components )
+            {
+            case 1:
+            case 2:
+                {
+                    if( src_data_size == dst_data_size * src_components )
+                    {
+                        for( S32 i = 0, j=0; i < dst_data_size; i++, j+= src_components )
+                        {
+                            dst_data[i] = src_data[j];
+                            if( dst_data[i] < minimum )
+                            {
+                                minimum = dst_data[i];
+                            }
+                            if( dst_data[i] > maximum )
+                            {
+                                maximum = dst_data[i];
+                            }
+                        }
+                    }
+                    else
+                    {
+                        llassert(0);
+                        dst_image->clear();
+                    }
+                }
+                break;
+            case 3:
+            case 4:
+                {
+                    if( src_data_size == dst_data_size * src_components )
+                    {
+                        for( S32 i = 0, j=0; i < dst_data_size; i++, j+= src_components )
+                        {
+                            // RGB to luminance
+                            dst_data[i] = (R_WEIGHT * src_data[j] + G_WEIGHT * src_data[j+1] + B_WEIGHT * src_data[j+2]) >> FIXED_PT;
+                            //llassert( dst_data[i] <= 255 );true because it's 8bit
+                            if( dst_data[i] < minimum )
+                            {
+                                minimum = dst_data[i];
+                            }
+                            if( dst_data[i] > maximum )
+                            {
+                                maximum = dst_data[i];
+                            }
+                        }
+                    }
+                    else
+                    {
+                        llassert(0);
+                        dst_image->clear();
+                    }
+                }
+                break;
+            default:
+                llassert(0);
+                dst_image->clear();
+                break;
+            }
+
+            if( maximum > minimum )
+            {
+                U8 bias_and_scale_lut[256];
+                F32 twice_one_over_range = 2.f / (maximum - minimum);
+                S32 i;
+
+                const F32 ARTIFICIAL_SCALE = 2.f;  // Advantage: exaggerates the effect in midrange.  Disadvantage: clamps at the extremes.
+                if (BE_DARKNESS == bump_code)
+                {
+                    for( i = minimum; i <= maximum; i++ )
+                    {
+                        F32 minus_one_to_one = F32(maximum - i) * twice_one_over_range - 1.f;
+                        bias_and_scale_lut[i] = llclampb(ll_round(127 * minus_one_to_one * ARTIFICIAL_SCALE + 128));
+                    }
+                }
+                else
+                {
+                    for( i = minimum; i <= maximum; i++ )
+                    {
+                        F32 minus_one_to_one = F32(i - minimum) * twice_one_over_range - 1.f;
+                        bias_and_scale_lut[i] = llclampb(ll_round(127 * minus_one_to_one * ARTIFICIAL_SCALE + 128));
+                    }
+                }
+
+                for( i = 0; i < dst_data_size; i++ )
+                {
+                    dst_data[i] = bias_and_scale_lut[dst_data[i]];
+                }
+            }
+
+            //---------------------------------------------------
+            // immediately assign bump to a smart pointer in case some local smart pointer
+            // accidentally releases it.
             LLPointer<LLViewerTexture> bump = iter->second;
 
-			if (!LLPipeline::sRenderDeferred)
-			{
-				bump->setExplicitFormat(GL_ALPHA8, GL_ALPHA);
+            if (!LLPipeline::sRenderDeferred)
+            {
+                bump->setExplicitFormat(GL_ALPHA8, GL_ALPHA);
 
 #if LL_BUMPLIST_MULTITHREADED
                 auto tex_queue = LLImageGLThread::sEnabledTextures ? sTexUpdateQueue.lock() : nullptr;
@@ -1059,9 +1059,9 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI
                 {
                     bump->createGLTexture(0, dst_image);
                 }
-			}
-			else 
-			{ //convert to normal map
+            }
+            else
+            { //convert to normal map
                 LL_PROFILE_ZONE_NAMED("bil - create normal map");
                 LLImageGL* img = bump->getGLTexture();
                 LLImageRaw* dst_ptr = dst_image.get();
@@ -1165,16 +1165,16 @@ void LLBumpImageList::onSourceLoaded( BOOL success, LLViewerTexture *src_vi, LLI
                 }
 
 
-			}
+            }
 
-			iter->second = bump; // derefs (and deletes) old image
-			//---------------------------------------------------
-		}
-	}
+            iter->second = bump; // derefs (and deletes) old image
+            //---------------------------------------------------
+        }
+    }
 }
 
 void LLDrawPoolBump::pushBumpBatches(U32 type)
-{	
+{
     LLVOAvatar* avatar = nullptr;
     U64 skin = 0;
 
@@ -1186,12 +1186,12 @@ void LLDrawPoolBump::pushBumpBatches(U32 type)
     LLCullResult::drawinfo_iterator begin = gPipeline.beginRenderMap(type);
     LLCullResult::drawinfo_iterator end = gPipeline.endRenderMap(type);
 
-	for (LLCullResult::drawinfo_iterator i = begin; i != end; ++i)	
-	{
-		LLDrawInfo& params = **i;
+    for (LLCullResult::drawinfo_iterator i = begin; i != end; ++i)
+    {
+        LLDrawInfo& params = **i;
 
-		if (LLDrawPoolBump::bindBumpMap(params))
-		{
+        if (LLDrawPoolBump::bindBumpMap(params))
+        {
             if (mRigged)
             {
                 if (avatar != params.mAvatar.get() || skin != params.mSkinInfo->mHash)
@@ -1207,80 +1207,80 @@ void LLDrawPoolBump::pushBumpBatches(U32 type)
                     }
                 }
             }
-			pushBumpBatch(params, false);
-		}
-	}
+            pushBumpBatch(params, false);
+        }
+    }
 }
 
 void LLRenderPass::pushBumpBatch(LLDrawInfo& params, bool texture, bool batch_textures)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-	applyModelMatrix(params);
-
-	bool tex_setup = false;
-
-	if (batch_textures && params.mTextureList.size() > 1)
-	{
-		for (U32 i = 0; i < params.mTextureList.size(); ++i)
-		{
-			if (params.mTextureList[i].notNull())
-			{
-				gGL.getTexUnit(i)->bindFast(params.mTextureList[i]);
-			}
-		}
-	}
-	else
-	{ //not batching textures or batch has only 1 texture -- might need a texture matrix
-		if (params.mTextureMatrix)
-		{
-			if (shiny)
-			{
-				gGL.getTexUnit(0)->activate();
-				gGL.matrixMode(LLRender::MM_TEXTURE);
-			}
-			else
-			{
-				gGL.getTexUnit(0)->activate();
-				gGL.matrixMode(LLRender::MM_TEXTURE);
-				gGL.loadMatrix(*params.mTextureMatrix);
-				gPipeline.mTextureMatrixOps++;
-			}
-
-			gGL.loadMatrix(*params.mTextureMatrix);
-			gPipeline.mTextureMatrixOps++;
-
-			tex_setup = true;
-		}
-
-		if (shiny && mShaderLevel > 1 && texture)
-		{
-			if (params.mTexture.notNull())
-			{
-				gGL.getTexUnit(diffuse_channel)->bindFast(params.mTexture);
-			}
-			else
-			{
-				gGL.getTexUnit(diffuse_channel)->unbind(LLTexUnit::TT_TEXTURE);
-			}
-		}
-	}
-
-	params.mVertexBuffer->setBuffer();
-	params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart, params.mEnd, params.mCount, params.mOffset);
+    applyModelMatrix(params);
+
+    bool tex_setup = false;
+
+    if (batch_textures && params.mTextureList.size() > 1)
+    {
+        for (U32 i = 0; i < params.mTextureList.size(); ++i)
+        {
+            if (params.mTextureList[i].notNull())
+            {
+                gGL.getTexUnit(i)->bindFast(params.mTextureList[i]);
+            }
+        }
+    }
+    else
+    { //not batching textures or batch has only 1 texture -- might need a texture matrix
+        if (params.mTextureMatrix)
+        {
+            if (shiny)
+            {
+                gGL.getTexUnit(0)->activate();
+                gGL.matrixMode(LLRender::MM_TEXTURE);
+            }
+            else
+            {
+                gGL.getTexUnit(0)->activate();
+                gGL.matrixMode(LLRender::MM_TEXTURE);
+                gGL.loadMatrix(*params.mTextureMatrix);
+                gPipeline.mTextureMatrixOps++;
+            }
+
+            gGL.loadMatrix(*params.mTextureMatrix);
+            gPipeline.mTextureMatrixOps++;
+
+            tex_setup = true;
+        }
+
+        if (shiny && mShaderLevel > 1 && texture)
+        {
+            if (params.mTexture.notNull())
+            {
+                gGL.getTexUnit(diffuse_channel)->bindFast(params.mTexture);
+            }
+            else
+            {
+                gGL.getTexUnit(diffuse_channel)->unbind(LLTexUnit::TT_TEXTURE);
+            }
+        }
+    }
+
+    params.mVertexBuffer->setBuffer();
+    params.mVertexBuffer->drawRange(LLRender::TRIANGLES, params.mStart, params.mEnd, params.mCount, params.mOffset);
 
     if (tex_setup)
-	{
-		if (shiny)
-		{
-			gGL.getTexUnit(0)->activate();
-		}
-		else
-		{
-			gGL.getTexUnit(0)->activate();
-			gGL.matrixMode(LLRender::MM_TEXTURE);
-		}
-		gGL.loadIdentity();
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-	}
+    {
+        if (shiny)
+        {
+            gGL.getTexUnit(0)->activate();
+        }
+        else
+        {
+            gGL.getTexUnit(0)->activate();
+            gGL.matrixMode(LLRender::MM_TEXTURE);
+        }
+        gGL.loadIdentity();
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+    }
 }
 
diff --git a/indra/newview/lldrawpoolterrain.cpp b/indra/newview/lldrawpoolterrain.cpp
index 0ea5cf927babb9b07ee44ed92bef03a0e2a61547..31ec99bff2b4de9b4370735aa490bc706960da56 100644
--- a/indra/newview/lldrawpoolterrain.cpp
+++ b/indra/newview/lldrawpoolterrain.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lldrawpoolterrain.cpp
  * @brief LLDrawPoolTerrain class implementation
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -39,7 +39,7 @@
 #include "llsurfacepatch.h"
 #include "llviewerregion.h"
 #include "llvlcomposition.h"
-#include "llviewerparcelmgr.h"		// for gRenderParcelOwnership
+#include "llviewerparcelmgr.h"      // for gRenderParcelOwnership
 #include "llviewerparceloverlay.h"
 #include "llvosurfacepatch.h"
 #include "llviewercamera.h"
@@ -60,47 +60,47 @@ F32 LLDrawPoolTerrain::sPBRDetailScale = DETAIL_SCALE;
 static LLGLSLShader* sShader = NULL;
 
 LLDrawPoolTerrain::LLDrawPoolTerrain(LLViewerTexture *texturep) :
-	LLFacePool(POOL_TERRAIN),
-	mTexturep(texturep)
+    LLFacePool(POOL_TERRAIN),
+    mTexturep(texturep)
 {
-	// Hack!
-	sDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainScale");
-	sPBRDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainPBRScale");
-	sPBRDetailMode = gSavedSettings.getS32("RenderTerrainPBRDetail");
-	mAlphaRampImagep = LLViewerTextureManager::getFetchedTexture(IMG_ALPHA_GRAD);
-
-	//gGL.getTexUnit(0)->bind(mAlphaRampImagep.get());
-	mAlphaRampImagep->setAddressMode(LLTexUnit::TAM_CLAMP);
-
-	m2DAlphaRampImagep = LLViewerTextureManager::getFetchedTexture(IMG_ALPHA_GRAD_2D);
-
-	//gGL.getTexUnit(0)->bind(m2DAlphaRampImagep.get());
-	m2DAlphaRampImagep->setAddressMode(LLTexUnit::TAM_CLAMP);
-	
-	mTexturep->setBoostLevel(LLGLTexture::BOOST_TERRAIN);
-	
-	//gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    // Hack!
+    sDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainScale");
+    sPBRDetailScale = 1.f/gSavedSettings.getF32("RenderTerrainPBRScale");
+    sPBRDetailMode = gSavedSettings.getS32("RenderTerrainPBRDetail");
+    mAlphaRampImagep = LLViewerTextureManager::getFetchedTexture(IMG_ALPHA_GRAD);
+
+    //gGL.getTexUnit(0)->bind(mAlphaRampImagep.get());
+    mAlphaRampImagep->setAddressMode(LLTexUnit::TAM_CLAMP);
+
+    m2DAlphaRampImagep = LLViewerTextureManager::getFetchedTexture(IMG_ALPHA_GRAD_2D);
+
+    //gGL.getTexUnit(0)->bind(m2DAlphaRampImagep.get());
+    m2DAlphaRampImagep->setAddressMode(LLTexUnit::TAM_CLAMP);
+
+    mTexturep->setBoostLevel(LLGLTexture::BOOST_TERRAIN);
+
+    //gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
 }
 
 LLDrawPoolTerrain::~LLDrawPoolTerrain()
 {
-	llassert( gPipeline.findPool( getType(), getTexture() ) == NULL );
+    llassert( gPipeline.findPool( getType(), getTexture() ) == NULL );
 }
 
-U32 LLDrawPoolTerrain::getVertexDataMask() 
-{ 
-	if (LLPipeline::sShadowRender)
-	{
-		return LLVertexBuffer::MAP_VERTEX;
-	}
-	else if (LLGLSLShader::sCurBoundShaderPtr)
-	{
-		return VERTEX_DATA_MASK & ~(LLVertexBuffer::MAP_TEXCOORD2 | LLVertexBuffer::MAP_TEXCOORD3);
-	}
-	else
-	{
-		return VERTEX_DATA_MASK; 
-	}
+U32 LLDrawPoolTerrain::getVertexDataMask()
+{
+    if (LLPipeline::sShadowRender)
+    {
+        return LLVertexBuffer::MAP_VERTEX;
+    }
+    else if (LLGLSLShader::sCurBoundShaderPtr)
+    {
+        return VERTEX_DATA_MASK & ~(LLVertexBuffer::MAP_TEXCOORD2 | LLVertexBuffer::MAP_TEXCOORD3);
+    }
+    else
+    {
+        return VERTEX_DATA_MASK;
+    }
 }
 
 void LLDrawPoolTerrain::prerender()
@@ -111,51 +111,51 @@ void LLDrawPoolTerrain::prerender()
 void LLDrawPoolTerrain::boostTerrainDetailTextures()
 {
     // Hack! Get the region that this draw pool is rendering from!
-	LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
-	LLVLComposition *compp = regionp->getComposition();
+    LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
+    LLVLComposition *compp = regionp->getComposition();
     compp->boost();
 }
 
 void LLDrawPoolTerrain::beginDeferredPass(S32 pass)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_TERRAIN);
-	LLFacePool::beginRenderPass(pass);
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_TERRAIN);
+    LLFacePool::beginRenderPass(pass);
 }
 
 void LLDrawPoolTerrain::endDeferredPass(S32 pass)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_TERRAIN);
-	LLFacePool::endRenderPass(pass);
-	sShader->unbind();
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_TERRAIN);
+    LLFacePool::endRenderPass(pass);
+    sShader->unbind();
 }
 
 void LLDrawPoolTerrain::renderDeferred(S32 pass)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_TERRAIN);
-	if (mDrawFace.empty())
-	{
-		return;
-	}
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_TERRAIN);
+    if (mDrawFace.empty())
+    {
+        return;
+    }
 
     boostTerrainDetailTextures();
 
-	renderFullShader();
+    renderFullShader();
 
-	// Special-case for land ownership feedback
-	static const LLCachedControl<bool> show_parcel_owners(gSavedSettings, "ShowParcelOwners");
-	if (show_parcel_owners)
-	{
-		hilightParcelOwners();
-	}
+    // Special-case for land ownership feedback
+    static const LLCachedControl<bool> show_parcel_owners(gSavedSettings, "ShowParcelOwners");
+    if (show_parcel_owners)
+    {
+        hilightParcelOwners();
+    }
 
 }
 
 void LLDrawPoolTerrain::beginShadowPass(S32 pass)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_SHADOW_TERRAIN);
-	LLFacePool::beginRenderPass(pass);
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	gDeferredShadowProgram.bind();
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_SHADOW_TERRAIN);
+    LLFacePool::beginRenderPass(pass);
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    gDeferredShadowProgram.bind();
 
     LLEnvironment& environment = LLEnvironment::instance();
     gDeferredShadowProgram.uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0);
@@ -163,56 +163,56 @@ void LLDrawPoolTerrain::beginShadowPass(S32 pass)
 
 void LLDrawPoolTerrain::endShadowPass(S32 pass)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_SHADOW_TERRAIN);
-	LLFacePool::endRenderPass(pass);
-	gDeferredShadowProgram.unbind();
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_SHADOW_TERRAIN);
+    LLFacePool::endRenderPass(pass);
+    gDeferredShadowProgram.unbind();
 }
 
 void LLDrawPoolTerrain::renderShadow(S32 pass)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_SHADOW_TERRAIN);
-	if (mDrawFace.empty())
-	{
-		return;
-	}
-	//LLGLEnable offset(GL_POLYGON_OFFSET);
-	//glCullFace(GL_FRONT);
-	drawLoop();
-	//glCullFace(GL_BACK);
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_SHADOW_TERRAIN);
+    if (mDrawFace.empty())
+    {
+        return;
+    }
+    //LLGLEnable offset(GL_POLYGON_OFFSET);
+    //glCullFace(GL_FRONT);
+    drawLoop();
+    //glCullFace(GL_BACK);
 }
 
 
 void LLDrawPoolTerrain::drawLoop()
 {
-	if (!mDrawFace.empty())
-	{
-		for (LLFace* facep : mDrawFace)
-		{
+    if (!mDrawFace.empty())
+    {
+        for (LLFace* facep : mDrawFace)
+        {
 
-			if (!facep || !facep->getDrawable() || !facep->getDrawable()->getRegion())
-				continue;
+            if (!facep || !facep->getDrawable() || !facep->getDrawable()->getRegion())
+                continue;
 
             llassert(gGL.getMatrixMode() == LLRender::MM_MODELVIEW);
-			LLMatrix4a* model_matrix = &(facep->getDrawable()->getRegion()->mRenderMatrix);
-			if (model_matrix && model_matrix->isIdentity())
-			{
-				model_matrix = NULL;
-			}
+            LLMatrix4a* model_matrix = &(facep->getDrawable()->getRegion()->mRenderMatrix);
+            if (model_matrix && model_matrix->isIdentity())
+            {
+                model_matrix = NULL;
+            }
             LLRenderPass::applyModelMatrix(model_matrix);
 
-			facep->renderIndexed();
-		}
-	}
+            facep->renderIndexed();
+        }
+    }
 }
 
 void LLDrawPoolTerrain::renderFullShader()
 {
     const BOOL use_local_materials = gLocalTerrainMaterials.materialsReady(true, false);
-	// Hack! Get the region that this draw pool is rendering from!
-	LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
-	LLVLComposition *compp = regionp->getComposition();
+    // Hack! Get the region that this draw pool is rendering from!
+    LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
+    LLVLComposition *compp = regionp->getComposition();
     const BOOL use_textures = !use_local_materials && (compp->getMaterialType() == LLTerrainMaterials::Type::TEXTURE);
-    
+
     if (use_textures)
     {
         // Use textures
@@ -231,136 +231,136 @@ void LLDrawPoolTerrain::renderFullShader()
 
 void LLDrawPoolTerrain::renderFullShaderTextures()
 {
-	// Hack! Get the region that this draw pool is rendering from!
-	LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
-	LLVLComposition *compp = regionp->getComposition();
+    // Hack! Get the region that this draw pool is rendering from!
+    LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
+    LLVLComposition *compp = regionp->getComposition();
 
 // [SL:KB] - Patch: Render-TextureToggle (Catznip-4.0)
-	LLViewerTexture *detail_texture0p = (LLPipeline::sRenderTextures) ? compp->mDetailTextures[0] : LLViewerFetchedTexture::sDefaultDiffuseImagep;
-	LLViewerTexture *detail_texture1p = (LLPipeline::sRenderTextures) ? compp->mDetailTextures[1] : LLViewerFetchedTexture::sDefaultDiffuseImagep;
-	LLViewerTexture *detail_texture2p = (LLPipeline::sRenderTextures) ? compp->mDetailTextures[2] : LLViewerFetchedTexture::sDefaultDiffuseImagep;
-	LLViewerTexture *detail_texture3p = (LLPipeline::sRenderTextures) ? compp->mDetailTextures[3] : LLViewerFetchedTexture::sDefaultDiffuseImagep;
+    LLViewerTexture *detail_texture0p = (LLPipeline::sRenderTextures) ? compp->mDetailTextures[0] : LLViewerFetchedTexture::sDefaultDiffuseImagep;
+    LLViewerTexture *detail_texture1p = (LLPipeline::sRenderTextures) ? compp->mDetailTextures[1] : LLViewerFetchedTexture::sDefaultDiffuseImagep;
+    LLViewerTexture *detail_texture2p = (LLPipeline::sRenderTextures) ? compp->mDetailTextures[2] : LLViewerFetchedTexture::sDefaultDiffuseImagep;
+    LLViewerTexture *detail_texture3p = (LLPipeline::sRenderTextures) ? compp->mDetailTextures[3] : LLViewerFetchedTexture::sDefaultDiffuseImagep;
 // [/SL:KB]
-//	LLViewerTexture *detail_texture0p = compp->mDetailTextures[0];
-//	LLViewerTexture *detail_texture1p = compp->mDetailTextures[1];
-//	LLViewerTexture *detail_texture2p = compp->mDetailTextures[2];
-//	LLViewerTexture *detail_texture3p = compp->mDetailTextures[3];
-
-
-	LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
-	F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
-	F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
-
-	LLVector4 tp0, tp1;
-	
-	tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
-	tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
-
-	//
-	// detail texture 0
-	//
-	S32 detail0 = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0);
-	gGL.getTexUnit(detail0)->bind(detail_texture0p);
+//  LLViewerTexture *detail_texture0p = compp->mDetailTextures[0];
+//  LLViewerTexture *detail_texture1p = compp->mDetailTextures[1];
+//  LLViewerTexture *detail_texture2p = compp->mDetailTextures[2];
+//  LLViewerTexture *detail_texture3p = compp->mDetailTextures[3];
+
+
+    LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
+    F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
+    F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
+
+    LLVector4 tp0, tp1;
+
+    tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
+    tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
+
+    //
+    // detail texture 0
+    //
+    S32 detail0 = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0);
+    gGL.getTexUnit(detail0)->bind(detail_texture0p);
     gGL.getTexUnit(detail0)->setTextureAddressMode(LLTexUnit::TAM_WRAP);
-	gGL.getTexUnit(detail0)->activate();
+    gGL.getTexUnit(detail0)->activate();
+
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+    llassert(shader);
 
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-	llassert(shader);
-		
-	shader->uniform4fv(LLShaderMgr::OBJECT_PLANE_S, 1, tp0.mV);
-	shader->uniform4fv(LLShaderMgr::OBJECT_PLANE_T, 1, tp1.mV);
+    shader->uniform4fv(LLShaderMgr::OBJECT_PLANE_S, 1, tp0.mV);
+    shader->uniform4fv(LLShaderMgr::OBJECT_PLANE_T, 1, tp1.mV);
 
     LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater();
 
-	//
-	// detail texture 1
-	//
-	S32 detail1 = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL1); 
-	gGL.getTexUnit(detail1)->bind(detail_texture1p);
-	gGL.getTexUnit(detail1)->setTextureAddressMode(LLTexUnit::TAM_WRAP);
-	gGL.getTexUnit(detail1)->activate();
-	
-	// detail texture 2
-	//
-	S32 detail2 = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL2);
-	gGL.getTexUnit(detail2)->bind(detail_texture2p);
+    //
+    // detail texture 1
+    //
+    S32 detail1 = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL1);
+    gGL.getTexUnit(detail1)->bind(detail_texture1p);
+    gGL.getTexUnit(detail1)->setTextureAddressMode(LLTexUnit::TAM_WRAP);
+    gGL.getTexUnit(detail1)->activate();
+
+    // detail texture 2
+    //
+    S32 detail2 = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL2);
+    gGL.getTexUnit(detail2)->bind(detail_texture2p);
     gGL.getTexUnit(detail2)->setTextureAddressMode(LLTexUnit::TAM_WRAP);
-	gGL.getTexUnit(detail2)->activate();
-	
-
-	// detail texture 3
-	//
-	S32 detail3 = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL3);
-	gGL.getTexUnit(detail3)->bind(detail_texture3p);
-	gGL.getTexUnit(detail3)->setTextureAddressMode(LLTexUnit::TAM_WRAP);
-	gGL.getTexUnit(detail3)->activate();
-
-	//
-	// Alpha Ramp 
-	//
-	S32 alpha_ramp = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
-	gGL.getTexUnit(alpha_ramp)->bind(m2DAlphaRampImagep);
+    gGL.getTexUnit(detail2)->activate();
+
+
+    // detail texture 3
+    //
+    S32 detail3 = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL3);
+    gGL.getTexUnit(detail3)->bind(detail_texture3p);
+    gGL.getTexUnit(detail3)->setTextureAddressMode(LLTexUnit::TAM_WRAP);
+    gGL.getTexUnit(detail3)->activate();
+
+    //
+    // Alpha Ramp
+    //
+    S32 alpha_ramp = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
+    gGL.getTexUnit(alpha_ramp)->bind(m2DAlphaRampImagep);
     gGL.getTexUnit(alpha_ramp)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
 
-	// GL_BLEND disabled by default
-	drawLoop();
-
-	// Disable multitexture
-	sShader->disableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
-	sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0);
-	sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL1);
-	sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL2);
-	sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL3);
-
-	gGL.getTexUnit(alpha_ramp)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(alpha_ramp)->disable();
-	gGL.getTexUnit(alpha_ramp)->activate();
-	
-	gGL.getTexUnit(detail3)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(detail3)->disable();
-	gGL.getTexUnit(detail3)->activate();
-
-	gGL.getTexUnit(detail2)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(detail2)->disable();
-	gGL.getTexUnit(detail2)->activate();
-
-	gGL.getTexUnit(detail1)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(detail1)->disable();
-	gGL.getTexUnit(detail1)->activate();
-	
-	//----------------------------------------------------------------------------
-	// Restore Texture Unit 0 defaults
-	
-	gGL.getTexUnit(detail0)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(detail0)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(detail0)->activate();
+    // GL_BLEND disabled by default
+    drawLoop();
+
+    // Disable multitexture
+    sShader->disableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
+    sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0);
+    sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL1);
+    sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL2);
+    sShader->disableTexture(LLViewerShaderMgr::TERRAIN_DETAIL3);
+
+    gGL.getTexUnit(alpha_ramp)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(alpha_ramp)->disable();
+    gGL.getTexUnit(alpha_ramp)->activate();
+
+    gGL.getTexUnit(detail3)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(detail3)->disable();
+    gGL.getTexUnit(detail3)->activate();
+
+    gGL.getTexUnit(detail2)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(detail2)->disable();
+    gGL.getTexUnit(detail2)->activate();
+
+    gGL.getTexUnit(detail1)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(detail1)->disable();
+    gGL.getTexUnit(detail1)->activate();
+
+    //----------------------------------------------------------------------------
+    // Restore Texture Unit 0 defaults
+
+    gGL.getTexUnit(detail0)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(detail0)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(detail0)->activate();
 }
 
 // *TODO: Investigate use of bindFast for PBR terrain textures
 void LLDrawPoolTerrain::renderFullShaderPBR(BOOL local_materials)
 {
-	// Hack! Get the region that this draw pool is rendering from!
-	LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
-	LLVLComposition *compp = regionp->getComposition();
-	LLPointer<LLFetchedGLTFMaterial> (*fetched_materials)[LLVLComposition::ASSET_COUNT] = &compp->mDetailMaterials;
+    // Hack! Get the region that this draw pool is rendering from!
+    LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
+    LLVLComposition *compp = regionp->getComposition();
+    LLPointer<LLFetchedGLTFMaterial> (*fetched_materials)[LLVLComposition::ASSET_COUNT] = &compp->mDetailMaterials;
 
-	constexpr U32 terrain_material_count = LLVLComposition::ASSET_COUNT;
+    constexpr U32 terrain_material_count = LLVLComposition::ASSET_COUNT;
 #ifdef SHOW_ASSERT
-	constexpr U32 shader_material_count = 1 + LLViewerShaderMgr::TERRAIN_DETAIL3_BASE_COLOR - LLViewerShaderMgr::TERRAIN_DETAIL0_BASE_COLOR;
-	llassert(shader_material_count == terrain_material_count);
+    constexpr U32 shader_material_count = 1 + LLViewerShaderMgr::TERRAIN_DETAIL3_BASE_COLOR - LLViewerShaderMgr::TERRAIN_DETAIL0_BASE_COLOR;
+    llassert(shader_material_count == terrain_material_count);
 #endif
 
     if (local_materials)
     {
         // Override region terrain with the global local override terrain
-		fetched_materials = &gLocalTerrainMaterials.mDetailMaterials;
+        fetched_materials = &gLocalTerrainMaterials.mDetailMaterials;
+    }
+    const LLGLTFMaterial* materials[terrain_material_count];
+    for (U32 i = 0; i < terrain_material_count; ++i)
+    {
+        materials[i] = (*fetched_materials)[i].get();
+        if (!materials[i]) { materials[i] = &LLGLTFMaterial::sDefault; }
     }
-	const LLGLTFMaterial* materials[terrain_material_count];
-	for (U32 i = 0; i < terrain_material_count; ++i)
-	{
-		materials[i] = (*fetched_materials)[i].get();
-		if (!materials[i]) { materials[i] = &LLGLTFMaterial::sDefault; }
-	}
 
     S32 detail_basecolor[terrain_material_count];
     S32 detail_normal[terrain_material_count];
@@ -369,19 +369,19 @@ void LLDrawPoolTerrain::renderFullShaderPBR(BOOL local_materials)
 
     for (U32 i = 0; i < terrain_material_count; ++i)
     {
-		LLViewerTexture* detail_basecolor_texturep = nullptr;
-		LLViewerTexture* detail_normal_texturep = nullptr;
-		LLViewerTexture* detail_metalrough_texturep = nullptr;
-		LLViewerTexture* detail_emissive_texturep = nullptr;
-
-		const LLFetchedGLTFMaterial* fetched_material = (*fetched_materials)[i].get();
-		if (fetched_material)
-		{
-			detail_basecolor_texturep = fetched_material->mBaseColorTexture;
-			detail_normal_texturep = fetched_material->mNormalTexture;
-			detail_metalrough_texturep = fetched_material->mMetallicRoughnessTexture;
-			detail_emissive_texturep = fetched_material->mEmissiveTexture;
-		}
+        LLViewerTexture* detail_basecolor_texturep = nullptr;
+        LLViewerTexture* detail_normal_texturep = nullptr;
+        LLViewerTexture* detail_metalrough_texturep = nullptr;
+        LLViewerTexture* detail_emissive_texturep = nullptr;
+
+        const LLFetchedGLTFMaterial* fetched_material = (*fetched_materials)[i].get();
+        if (fetched_material)
+        {
+            detail_basecolor_texturep = fetched_material->mBaseColorTexture;
+            detail_normal_texturep = fetched_material->mNormalTexture;
+            detail_metalrough_texturep = fetched_material->mMetallicRoughnessTexture;
+            detail_emissive_texturep = fetched_material->mEmissiveTexture;
+        }
 
         detail_basecolor[i] = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_DETAIL0_BASE_COLOR + i);
         if (detail_basecolor_texturep)
@@ -441,20 +441,12 @@ void LLDrawPoolTerrain::renderFullShaderPBR(BOOL local_materials)
         }
     }
 
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-	llassert(shader);
-		
-
-    // *TODO: Figure out why this offset is *sometimes* producing seams at the
-    // region edge, and repeat jumps when crossing regions, when
-    // RenderTerrainPBRScale is not a factor of the region scale.
-	LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
-	F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sPBRDetailScale)*sPBRDetailScale;
-	F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sPBRDetailScale)*sPBRDetailScale;
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+    llassert(shader);
 
     LLGLTFMaterial::TextureTransform base_color_transform;
     base_color_transform.mScale = LLVector2(sPBRDetailScale, sPBRDetailScale);
-    base_color_transform.mOffset = LLVector2(offset_x, offset_y);
+    // *TODO: mOffset and mRotation left at defaults for now. (per-material texture transforms are implemented in another branch)
     F32 base_color_packed[8];
     base_color_transform.getPacked(base_color_packed);
     // *HACK: Use the same texture repeats for all PBR terrain textures for now
@@ -463,11 +455,11 @@ void LLDrawPoolTerrain::renderFullShaderPBR(BOOL local_materials)
 
     LLSettingsWater::ptr_t pwater = LLEnvironment::instance().getCurrentWater();
 
-	//
-	// Alpha Ramp 
-	//
-	S32 alpha_ramp = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
-	gGL.getTexUnit(alpha_ramp)->bind(m2DAlphaRampImagep);
+    //
+    // Alpha Ramp
+    //
+    S32 alpha_ramp = sShader->enableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
+    gGL.getTexUnit(alpha_ramp)->bind(m2DAlphaRampImagep);
     gGL.getTexUnit(alpha_ramp)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
 
     //
@@ -512,16 +504,16 @@ void LLDrawPoolTerrain::renderFullShaderPBR(BOOL local_materials)
     }
     shader->uniform4f(LLShaderMgr::TERRAIN_MINIMUM_ALPHAS, minimum_alphas[0], minimum_alphas[1], minimum_alphas[2], minimum_alphas[3]);
 
-	// GL_BLEND disabled by default
-	drawLoop();
+    // GL_BLEND disabled by default
+    drawLoop();
 
-	// Disable multitexture
+    // Disable multitexture
 
-	sShader->disableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
+    sShader->disableTexture(LLViewerShaderMgr::TERRAIN_ALPHARAMP);
 
-	gGL.getTexUnit(alpha_ramp)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(alpha_ramp)->disable();
-	gGL.getTexUnit(alpha_ramp)->activate();
+    gGL.getTexUnit(alpha_ramp)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(alpha_ramp)->disable();
+    gGL.getTexUnit(alpha_ramp)->activate();
 
     for (U32 i = 0; i < terrain_material_count; ++i)
     {
@@ -568,462 +560,462 @@ void LLDrawPoolTerrain::renderFullShaderPBR(BOOL local_materials)
 
 void LLDrawPoolTerrain::hilightParcelOwners()
 {
-	{ //use fullbright shader for highlighting
-		LLGLSLShader* old_shader = sShader;
-		sShader->unbind();
-		sShader = &gDeferredHighlightProgram;
-		sShader->bind();
-		gGL.diffuseColor4f(1, 1, 1, 1);
-		LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
-		glPolygonOffset(-1.0f, -1.0f);
-		renderOwnership();
-		sShader = old_shader;
-		sShader->bind();
-	}
-	
+    { //use fullbright shader for highlighting
+        LLGLSLShader* old_shader = sShader;
+        sShader->unbind();
+        sShader = &gDeferredHighlightProgram;
+        sShader->bind();
+        gGL.diffuseColor4f(1, 1, 1, 1);
+        LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
+        glPolygonOffset(-1.0f, -1.0f);
+        renderOwnership();
+        sShader = old_shader;
+        sShader->bind();
+    }
+
 }
 
 void LLDrawPoolTerrain::renderFull4TU()
 {
-	// Hack! Get the region that this draw pool is rendering from!
-	LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
-	LLVLComposition *compp = regionp->getComposition();
-	LLViewerTexture *detail_texture0p = compp->mDetailTextures[0];
-	LLViewerTexture *detail_texture1p = compp->mDetailTextures[1];
-	LLViewerTexture *detail_texture2p = compp->mDetailTextures[2];
-	LLViewerTexture *detail_texture3p = compp->mDetailTextures[3];
-
-	LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
-	F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
-	F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
-
-	LLVector4 tp0, tp1;
-	
-	tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
-	tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
-
-	gGL.blendFunc(LLRender::BF_ONE_MINUS_SOURCE_ALPHA, LLRender::BF_SOURCE_ALPHA);
-	
-	//----------------------------------------------------------------------------
-	// Pass 1/1
-
-	//
-	// Stage 0: detail texture 0
-	//
-	gGL.getTexUnit(0)->activate();
-	gGL.getTexUnit(0)->bind(detail_texture0p);
-	
-	glEnable(GL_TEXTURE_GEN_S);
-	glEnable(GL_TEXTURE_GEN_T);
-	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-
-	glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
-	glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
-
-	//
-	// Stage 1: Generate alpha ramp for detail0/detail1 transition
-	//
-
-	gGL.getTexUnit(1)->bind(m2DAlphaRampImagep.get());
-	gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(1)->activate();
-	
-	//
-	// Stage 2: Interpolate detail1 with existing based on ramp
-	//
-	gGL.getTexUnit(2)->bind(detail_texture1p);
-	gGL.getTexUnit(2)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(2)->activate();
-
-	glEnable(GL_TEXTURE_GEN_S);
-	glEnable(GL_TEXTURE_GEN_T);
-	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
-	glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
-
-	//
-	// Stage 3: Modulate with primary (vertex) color for lighting
-	//
-	gGL.getTexUnit(3)->bind(detail_texture1p);
-	gGL.getTexUnit(3)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(3)->activate();
-	
-	gGL.getTexUnit(0)->activate();
-	
-	// GL_BLEND disabled by default
-	drawLoop();
-
-	//----------------------------------------------------------------------------
-	// Second pass
-
-	// Stage 0: Write detail3 into base
-	//
-	gGL.getTexUnit(0)->activate();
-	gGL.getTexUnit(0)->bind(detail_texture3p);
-
-	glEnable(GL_TEXTURE_GEN_S);
-	glEnable(GL_TEXTURE_GEN_T);
-	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
-	glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
-
-	//
-	// Stage 1: Generate alpha ramp for detail2/detail3 transition
-	//
-	gGL.getTexUnit(1)->bind(m2DAlphaRampImagep);
-	gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(1)->activate();
-
-	// Set the texture matrix
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.translatef(-2.f, 0.f, 0.f);
-
-	//
-	// Stage 2: Interpolate detail2 with existing based on ramp
-	//
-	gGL.getTexUnit(2)->bind(detail_texture2p);
-	gGL.getTexUnit(2)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(2)->activate();
-
-	glEnable(GL_TEXTURE_GEN_S);
-	glEnable(GL_TEXTURE_GEN_T);
-	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
-	glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
-
-	//
-	// Stage 3: Generate alpha ramp for detail1/detail2 transition
-	//
-	gGL.getTexUnit(3)->bind(m2DAlphaRampImagep);
-	gGL.getTexUnit(3)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(3)->activate();
-
-	// Set the texture matrix
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.translatef(-1.f, 0.f, 0.f);
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-
-	gGL.getTexUnit(0)->activate();
-	{
-		LLGLEnable blend(GL_BLEND);
-		drawLoop();
-	}
-
-	LLVertexBuffer::unbind();
-	// Disable multitexture
-	gGL.getTexUnit(3)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(3)->disable();
-	gGL.getTexUnit(3)->activate();
-	
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-
-	gGL.getTexUnit(2)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(2)->disable();
-	gGL.getTexUnit(2)->activate();
-	
-	glDisable(GL_TEXTURE_GEN_S);
-	glDisable(GL_TEXTURE_GEN_T);
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-
-	gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE);	
-	gGL.getTexUnit(1)->disable();
-	gGL.getTexUnit(1)->activate();
- 	
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-
-	// Restore blend state
-	gGL.setSceneBlendType(LLRender::BT_ALPHA);
-	
-	//----------------------------------------------------------------------------
-	// Restore Texture Unit 0 defaults
-	
-	gGL.getTexUnit(0)->activate();
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-	
-	glDisable(GL_TEXTURE_GEN_S);
-	glDisable(GL_TEXTURE_GEN_T);
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
+    // Hack! Get the region that this draw pool is rendering from!
+    LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
+    LLVLComposition *compp = regionp->getComposition();
+    LLViewerTexture *detail_texture0p = compp->mDetailTextures[0];
+    LLViewerTexture *detail_texture1p = compp->mDetailTextures[1];
+    LLViewerTexture *detail_texture2p = compp->mDetailTextures[2];
+    LLViewerTexture *detail_texture3p = compp->mDetailTextures[3];
+
+    LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
+    F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
+    F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
+
+    LLVector4 tp0, tp1;
+
+    tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
+    tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
+
+    gGL.blendFunc(LLRender::BF_ONE_MINUS_SOURCE_ALPHA, LLRender::BF_SOURCE_ALPHA);
+
+    //----------------------------------------------------------------------------
+    // Pass 1/1
+
+    //
+    // Stage 0: detail texture 0
+    //
+    gGL.getTexUnit(0)->activate();
+    gGL.getTexUnit(0)->bind(detail_texture0p);
+
+    glEnable(GL_TEXTURE_GEN_S);
+    glEnable(GL_TEXTURE_GEN_T);
+    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+
+    glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
+    glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
+
+    //
+    // Stage 1: Generate alpha ramp for detail0/detail1 transition
+    //
+
+    gGL.getTexUnit(1)->bind(m2DAlphaRampImagep.get());
+    gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(1)->activate();
+
+    //
+    // Stage 2: Interpolate detail1 with existing based on ramp
+    //
+    gGL.getTexUnit(2)->bind(detail_texture1p);
+    gGL.getTexUnit(2)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(2)->activate();
+
+    glEnable(GL_TEXTURE_GEN_S);
+    glEnable(GL_TEXTURE_GEN_T);
+    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
+    glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
+
+    //
+    // Stage 3: Modulate with primary (vertex) color for lighting
+    //
+    gGL.getTexUnit(3)->bind(detail_texture1p);
+    gGL.getTexUnit(3)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(3)->activate();
+
+    gGL.getTexUnit(0)->activate();
+
+    // GL_BLEND disabled by default
+    drawLoop();
+
+    //----------------------------------------------------------------------------
+    // Second pass
+
+    // Stage 0: Write detail3 into base
+    //
+    gGL.getTexUnit(0)->activate();
+    gGL.getTexUnit(0)->bind(detail_texture3p);
+
+    glEnable(GL_TEXTURE_GEN_S);
+    glEnable(GL_TEXTURE_GEN_T);
+    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
+    glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
+
+    //
+    // Stage 1: Generate alpha ramp for detail2/detail3 transition
+    //
+    gGL.getTexUnit(1)->bind(m2DAlphaRampImagep);
+    gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(1)->activate();
+
+    // Set the texture matrix
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.translatef(-2.f, 0.f, 0.f);
+
+    //
+    // Stage 2: Interpolate detail2 with existing based on ramp
+    //
+    gGL.getTexUnit(2)->bind(detail_texture2p);
+    gGL.getTexUnit(2)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(2)->activate();
+
+    glEnable(GL_TEXTURE_GEN_S);
+    glEnable(GL_TEXTURE_GEN_T);
+    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
+    glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
+
+    //
+    // Stage 3: Generate alpha ramp for detail1/detail2 transition
+    //
+    gGL.getTexUnit(3)->bind(m2DAlphaRampImagep);
+    gGL.getTexUnit(3)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(3)->activate();
+
+    // Set the texture matrix
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.translatef(-1.f, 0.f, 0.f);
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+
+    gGL.getTexUnit(0)->activate();
+    {
+        LLGLEnable blend(GL_BLEND);
+        drawLoop();
+    }
+
+    LLVertexBuffer::unbind();
+    // Disable multitexture
+    gGL.getTexUnit(3)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(3)->disable();
+    gGL.getTexUnit(3)->activate();
+
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+
+    gGL.getTexUnit(2)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(2)->disable();
+    gGL.getTexUnit(2)->activate();
+
+    glDisable(GL_TEXTURE_GEN_S);
+    glDisable(GL_TEXTURE_GEN_T);
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+
+    gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(1)->disable();
+    gGL.getTexUnit(1)->activate();
+
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+
+    // Restore blend state
+    gGL.setSceneBlendType(LLRender::BT_ALPHA);
+
+    //----------------------------------------------------------------------------
+    // Restore Texture Unit 0 defaults
+
+    gGL.getTexUnit(0)->activate();
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+
+
+    glDisable(GL_TEXTURE_GEN_S);
+    glDisable(GL_TEXTURE_GEN_T);
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
 }
 
 void LLDrawPoolTerrain::renderFull2TU()
 {
-	// Hack! Get the region that this draw pool is rendering from!
-	LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
-	LLVLComposition *compp = regionp->getComposition();
-	LLViewerTexture *detail_texture0p = compp->mDetailTextures[0];
-	LLViewerTexture *detail_texture1p = compp->mDetailTextures[1];
-	LLViewerTexture *detail_texture2p = compp->mDetailTextures[2];
-	LLViewerTexture *detail_texture3p = compp->mDetailTextures[3];
-
-	LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
-	F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
-	F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
-
-	LLVector4 tp0, tp1;
-	
-	tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
-	tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
-
-	gGL.blendFunc(LLRender::BF_ONE_MINUS_SOURCE_ALPHA, LLRender::BF_SOURCE_ALPHA);
-	
-	//----------------------------------------------------------------------------
-	// Pass 1/4
-
-	//
-	// Stage 0: Render detail 0 into base
-	//
-	gGL.getTexUnit(0)->bind(detail_texture0p);
-	glEnable(GL_TEXTURE_GEN_S);
-	glEnable(GL_TEXTURE_GEN_T);
-	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-
-	glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
-	glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
-
-	drawLoop();
-
-	//----------------------------------------------------------------------------
-	// Pass 2/4
-	
-	//
-	// Stage 0: Generate alpha ramp for detail0/detail1 transition
-	//
-	gGL.getTexUnit(0)->bind(m2DAlphaRampImagep);
-	
-	glDisable(GL_TEXTURE_GEN_S);
-	glDisable(GL_TEXTURE_GEN_T);
-	
-	//
-	// Stage 1: Write detail1
-	//
-	gGL.getTexUnit(1)->bind(detail_texture1p);
-	gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(1)->activate();
-
-	glEnable(GL_TEXTURE_GEN_S);
-	glEnable(GL_TEXTURE_GEN_T);
-	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
-	glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
-
-	gGL.getTexUnit(0)->activate();
-	{
-		LLGLEnable blend(GL_BLEND);
-		drawLoop();
-	}
-	//----------------------------------------------------------------------------
-	// Pass 3/4
-	
-	//
-	// Stage 0: Generate alpha ramp for detail1/detail2 transition
-	//
-	gGL.getTexUnit(0)->bind(m2DAlphaRampImagep);
-
-	// Set the texture matrix
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.translatef(-1.f, 0.f, 0.f);
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-
-	//
-	// Stage 1: Write detail2
-	//
-	gGL.getTexUnit(1)->bind(detail_texture2p);
-	gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(1)->activate();
-	
-	glEnable(GL_TEXTURE_GEN_S);
-	glEnable(GL_TEXTURE_GEN_T);
-	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
-	glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
-
-	{
-		LLGLEnable blend(GL_BLEND);
-		drawLoop();
-	}
-	
-	//----------------------------------------------------------------------------
-	// Pass 4/4
-	
-	//
-	// Stage 0: Generate alpha ramp for detail2/detail3 transition
-	//
-	gGL.getTexUnit(0)->activate();
-	gGL.getTexUnit(0)->bind(m2DAlphaRampImagep);
-	// Set the texture matrix
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.translatef(-2.f, 0.f, 0.f);
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-
-	// Stage 1: Write detail3
-	gGL.getTexUnit(1)->bind(detail_texture3p);
-	gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(1)->activate();
-
-	glEnable(GL_TEXTURE_GEN_S);
-	glEnable(GL_TEXTURE_GEN_T);
-	glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
-	glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
-	glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
-
-	gGL.getTexUnit(0)->activate();
-	{
-		LLGLEnable blend(GL_BLEND);
-		drawLoop();
-	}
-	
-	// Restore blend state
-	gGL.setSceneBlendType(LLRender::BT_ALPHA);
-	
-	// Disable multitexture
-	
-	gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(1)->disable();
-	gGL.getTexUnit(1)->activate();
-
-	glDisable(GL_TEXTURE_GEN_S);
-	glDisable(GL_TEXTURE_GEN_T);
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-
-	//----------------------------------------------------------------------------
-	// Restore Texture Unit 0 defaults
-	
-	gGL.getTexUnit(0)->activate();
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-	glDisable(GL_TEXTURE_GEN_S);
-	glDisable(GL_TEXTURE_GEN_T);
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
+    // Hack! Get the region that this draw pool is rendering from!
+    LLViewerRegion *regionp = mDrawFace[0]->getDrawable()->getVObj()->getRegion();
+    LLVLComposition *compp = regionp->getComposition();
+    LLViewerTexture *detail_texture0p = compp->mDetailTextures[0];
+    LLViewerTexture *detail_texture1p = compp->mDetailTextures[1];
+    LLViewerTexture *detail_texture2p = compp->mDetailTextures[2];
+    LLViewerTexture *detail_texture3p = compp->mDetailTextures[3];
+
+    LLVector3d region_origin_global = gAgent.getRegion()->getOriginGlobal();
+    F32 offset_x = (F32)fmod(region_origin_global.mdV[VX], 1.0/(F64)sDetailScale)*sDetailScale;
+    F32 offset_y = (F32)fmod(region_origin_global.mdV[VY], 1.0/(F64)sDetailScale)*sDetailScale;
+
+    LLVector4 tp0, tp1;
+
+    tp0.setVec(sDetailScale, 0.0f, 0.0f, offset_x);
+    tp1.setVec(0.0f, sDetailScale, 0.0f, offset_y);
+
+    gGL.blendFunc(LLRender::BF_ONE_MINUS_SOURCE_ALPHA, LLRender::BF_SOURCE_ALPHA);
+
+    //----------------------------------------------------------------------------
+    // Pass 1/4
+
+    //
+    // Stage 0: Render detail 0 into base
+    //
+    gGL.getTexUnit(0)->bind(detail_texture0p);
+    glEnable(GL_TEXTURE_GEN_S);
+    glEnable(GL_TEXTURE_GEN_T);
+    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+
+    glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
+    glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
+
+    drawLoop();
+
+    //----------------------------------------------------------------------------
+    // Pass 2/4
+
+    //
+    // Stage 0: Generate alpha ramp for detail0/detail1 transition
+    //
+    gGL.getTexUnit(0)->bind(m2DAlphaRampImagep);
+
+    glDisable(GL_TEXTURE_GEN_S);
+    glDisable(GL_TEXTURE_GEN_T);
+
+    //
+    // Stage 1: Write detail1
+    //
+    gGL.getTexUnit(1)->bind(detail_texture1p);
+    gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(1)->activate();
+
+    glEnable(GL_TEXTURE_GEN_S);
+    glEnable(GL_TEXTURE_GEN_T);
+    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
+    glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
+
+    gGL.getTexUnit(0)->activate();
+    {
+        LLGLEnable blend(GL_BLEND);
+        drawLoop();
+    }
+    //----------------------------------------------------------------------------
+    // Pass 3/4
+
+    //
+    // Stage 0: Generate alpha ramp for detail1/detail2 transition
+    //
+    gGL.getTexUnit(0)->bind(m2DAlphaRampImagep);
+
+    // Set the texture matrix
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.translatef(-1.f, 0.f, 0.f);
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+
+    //
+    // Stage 1: Write detail2
+    //
+    gGL.getTexUnit(1)->bind(detail_texture2p);
+    gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(1)->activate();
+
+    glEnable(GL_TEXTURE_GEN_S);
+    glEnable(GL_TEXTURE_GEN_T);
+    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
+    glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
+
+    {
+        LLGLEnable blend(GL_BLEND);
+        drawLoop();
+    }
+
+    //----------------------------------------------------------------------------
+    // Pass 4/4
+
+    //
+    // Stage 0: Generate alpha ramp for detail2/detail3 transition
+    //
+    gGL.getTexUnit(0)->activate();
+    gGL.getTexUnit(0)->bind(m2DAlphaRampImagep);
+    // Set the texture matrix
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.translatef(-2.f, 0.f, 0.f);
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+
+    // Stage 1: Write detail3
+    gGL.getTexUnit(1)->bind(detail_texture3p);
+    gGL.getTexUnit(1)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(1)->activate();
+
+    glEnable(GL_TEXTURE_GEN_S);
+    glEnable(GL_TEXTURE_GEN_T);
+    glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
+    glTexGenfv(GL_S, GL_OBJECT_PLANE, tp0.mV);
+    glTexGenfv(GL_T, GL_OBJECT_PLANE, tp1.mV);
+
+    gGL.getTexUnit(0)->activate();
+    {
+        LLGLEnable blend(GL_BLEND);
+        drawLoop();
+    }
+
+    // Restore blend state
+    gGL.setSceneBlendType(LLRender::BT_ALPHA);
+
+    // Disable multitexture
+
+    gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(1)->disable();
+    gGL.getTexUnit(1)->activate();
+
+    glDisable(GL_TEXTURE_GEN_S);
+    glDisable(GL_TEXTURE_GEN_T);
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+
+    //----------------------------------------------------------------------------
+    // Restore Texture Unit 0 defaults
+
+    gGL.getTexUnit(0)->activate();
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+
+    glDisable(GL_TEXTURE_GEN_S);
+    glDisable(GL_TEXTURE_GEN_T);
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
 }
 
 
 void LLDrawPoolTerrain::renderSimple()
 {
-	LLVector4 tp0, tp1;
-
-	//----------------------------------------------------------------------------
-	// Pass 1/1
-
-	// Stage 0: Base terrain texture pass
-	mTexturep->addTextureStats(1024.f*1024.f);
-
-	gGL.getTexUnit(0)->activate();
-	gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(0)->bind(mTexturep);
-	
-	LLVector3 origin_agent = mDrawFace[0]->getDrawable()->getVObj()->getRegion()->getOriginAgent();
-	F32 tscale = 1.f/256.f;
-	tp0.setVec(tscale, 0.f, 0.0f, -1.f*(origin_agent.mV[0]/256.f));
-	tp1.setVec(0.f, tscale, 0.0f, -1.f*(origin_agent.mV[1]/256.f));
-	
-	sShader->uniform4fv(LLShaderMgr::OBJECT_PLANE_S, 1, tp0.mV);
-	sShader->uniform4fv(LLShaderMgr::OBJECT_PLANE_T, 1, tp1.mV);
-
-	drawLoop();
-
-	//----------------------------------------------------------------------------
-	// Restore Texture Unit 0 defaults
-	
-	gGL.getTexUnit(0)->activate();
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.loadIdentity();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
+    LLVector4 tp0, tp1;
+
+    //----------------------------------------------------------------------------
+    // Pass 1/1
+
+    // Stage 0: Base terrain texture pass
+    mTexturep->addTextureStats(1024.f*1024.f);
+
+    gGL.getTexUnit(0)->activate();
+    gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(0)->bind(mTexturep);
+
+    LLVector3 origin_agent = mDrawFace[0]->getDrawable()->getVObj()->getRegion()->getOriginAgent();
+    F32 tscale = 1.f/256.f;
+    tp0.setVec(tscale, 0.f, 0.0f, -1.f*(origin_agent.mV[0]/256.f));
+    tp1.setVec(0.f, tscale, 0.0f, -1.f*(origin_agent.mV[1]/256.f));
+
+    sShader->uniform4fv(LLShaderMgr::OBJECT_PLANE_S, 1, tp0.mV);
+    sShader->uniform4fv(LLShaderMgr::OBJECT_PLANE_T, 1, tp1.mV);
+
+    drawLoop();
+
+    //----------------------------------------------------------------------------
+    // Restore Texture Unit 0 defaults
+
+    gGL.getTexUnit(0)->activate();
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.loadIdentity();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
 }
 
 //============================================================================
 
 void LLDrawPoolTerrain::renderOwnership()
 {
-	LLGLSPipelineAlpha gls_pipeline_alpha;
-
-	llassert(!mDrawFace.empty());
-
-	// Each terrain pool is associated with a single region.
-	// We need to peek back into the viewer's data to find out
-	// which ownership overlay texture to use.
-	LLFace					*facep				= mDrawFace[0];
-	LLDrawable				*drawablep			= facep->getDrawable();
-	const LLViewerObject	*objectp				= drawablep->getVObj();
-	const LLVOSurfacePatch	*vo_surface_patchp	= (LLVOSurfacePatch *)objectp;
-	LLSurfacePatch			*surface_patchp		= vo_surface_patchp->getPatch();
-	LLSurface				*surfacep			= surface_patchp->getSurface();
-	LLViewerRegion			*regionp			= surfacep->getRegion();
-	LLViewerParcelOverlay	*overlayp			= regionp->getParcelOverlay();
-	LLViewerTexture			*texturep			= overlayp->getTexture();
-
-	gGL.getTexUnit(0)->bind(texturep);
-
-	// *NOTE: Because the region is 256 meters wide, but has 257 pixels, the 
-	// texture coordinates for pixel 256x256 is not 1,1. This makes the
-	// ownership map not line up with the selection. We address this with
-	// a texture matrix multiply.
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.pushMatrix();
-
-	const F32 TEXTURE_FUDGE = 257.f / 256.f;
-	gGL.scalef( TEXTURE_FUDGE, TEXTURE_FUDGE, 1.f );
-	for (LLFace* facep : mDrawFace)
-	{
-		facep->renderIndexed();
-	}
-
-	gGL.matrixMode(LLRender::MM_TEXTURE);
-	gGL.popMatrix();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
+    LLGLSPipelineAlpha gls_pipeline_alpha;
+
+    llassert(!mDrawFace.empty());
+
+    // Each terrain pool is associated with a single region.
+    // We need to peek back into the viewer's data to find out
+    // which ownership overlay texture to use.
+    LLFace                  *facep              = mDrawFace[0];
+    LLDrawable              *drawablep          = facep->getDrawable();
+    const LLViewerObject    *objectp                = drawablep->getVObj();
+    const LLVOSurfacePatch  *vo_surface_patchp  = (LLVOSurfacePatch *)objectp;
+    LLSurfacePatch          *surface_patchp     = vo_surface_patchp->getPatch();
+    LLSurface               *surfacep           = surface_patchp->getSurface();
+    LLViewerRegion          *regionp            = surfacep->getRegion();
+    LLViewerParcelOverlay   *overlayp           = regionp->getParcelOverlay();
+    LLViewerTexture         *texturep           = overlayp->getTexture();
+
+    gGL.getTexUnit(0)->bind(texturep);
+
+    // *NOTE: Because the region is 256 meters wide, but has 257 pixels, the
+    // texture coordinates for pixel 256x256 is not 1,1. This makes the
+    // ownership map not line up with the selection. We address this with
+    // a texture matrix multiply.
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.pushMatrix();
+
+    const F32 TEXTURE_FUDGE = 257.f / 256.f;
+    gGL.scalef( TEXTURE_FUDGE, TEXTURE_FUDGE, 1.f );
+    for (LLFace* facep : mDrawFace)
+    {
+        facep->renderIndexed();
+    }
+
+    gGL.matrixMode(LLRender::MM_TEXTURE);
+    gGL.popMatrix();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
 }
 
 
 void LLDrawPoolTerrain::dirtyTextures(const std::set<LLViewerFetchedTexture*>& textures)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-	LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(mTexturep) ;
-	if (tex && textures.find(tex) != textures.end())
-	{
-		for (LLFace* facep : mReferences)
-		{
-			gPipeline.markTextured(facep->getDrawable());
-		}
-	}
+    LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(mTexturep) ;
+    if (tex && textures.find(tex) != textures.end())
+    {
+        for (LLFace* facep : mReferences)
+        {
+            gPipeline.markTextured(facep->getDrawable());
+        }
+    }
 }
 
 LLViewerTexture *LLDrawPoolTerrain::getTexture()
 {
-	return mTexturep;
+    return mTexturep;
 }
 
 LLViewerTexture *LLDrawPoolTerrain::getDebugTexture()
 {
-	return mTexturep;
+    return mTexturep;
 }
 
 
 LLColor3 LLDrawPoolTerrain::getDebugColor() const
 {
-	return LLColor3(0.f, 0.f, 1.f);
+    return LLColor3(0.f, 0.f, 1.f);
 }
diff --git a/indra/newview/lldrawpoolterrain.h b/indra/newview/lldrawpoolterrain.h
index 07199d187b7974ea0fc9ccfa3c03b6669f01306b..dcf259c606f7a4ff45d781904dc5c3fce367fd04 100644
--- a/indra/newview/lldrawpoolterrain.h
+++ b/indra/newview/lldrawpoolterrain.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lldrawpoolterrain.h
  * @brief LLDrawPoolTerrain class definition
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -31,7 +31,7 @@
 
 class LLDrawPoolTerrain final : public LLFacePool
 {
-	LLPointer<LLViewerTexture> mTexturep;
+    LLPointer<LLViewerTexture> mTexturep;
 public:
     enum
     {
@@ -40,51 +40,51 @@ class LLDrawPoolTerrain final : public LLFacePool
                     LLVertexBuffer::MAP_TANGENT | // Only PBR terrain uses this currently
                     LLVertexBuffer::MAP_TEXCOORD0 |
                     LLVertexBuffer::MAP_TEXCOORD1
-	};
+    };
 
-	virtual U32 getVertexDataMask();
-	LLDrawPoolTerrain(LLViewerTexture *texturep);
-	virtual ~LLDrawPoolTerrain();
+    virtual U32 getVertexDataMask();
+    LLDrawPoolTerrain(LLViewerTexture *texturep);
+    virtual ~LLDrawPoolTerrain();
 
-	/*virtual*/ S32 getNumDeferredPasses() { return 1; }
-	/*virtual*/ void beginDeferredPass(S32 pass);
-	/*virtual*/ void endDeferredPass(S32 pass);
-	/*virtual*/ void renderDeferred(S32 pass);
+    /*virtual*/ S32 getNumDeferredPasses() { return 1; }
+    /*virtual*/ void beginDeferredPass(S32 pass);
+    /*virtual*/ void endDeferredPass(S32 pass);
+    /*virtual*/ void renderDeferred(S32 pass);
 
-	/*virtual*/ S32 getNumShadowPasses() { return 1; }
-	/*virtual*/ void beginShadowPass(S32 pass);
-	/*virtual*/ void endShadowPass(S32 pass);
-	/*virtual*/ void renderShadow(S32 pass);
+    /*virtual*/ S32 getNumShadowPasses() { return 1; }
+    /*virtual*/ void beginShadowPass(S32 pass);
+    /*virtual*/ void endShadowPass(S32 pass);
+    /*virtual*/ void renderShadow(S32 pass);
 
-	/*virtual*/ void prerender();
-	/*virtual*/ void dirtyTextures(const std::set<LLViewerFetchedTexture*>& textures);
-	/*virtual*/ LLViewerTexture *getTexture();
-	/*virtual*/ LLViewerTexture *getDebugTexture();
-	/*virtual*/ LLColor3 getDebugColor() const; // For AGP debug display
+    /*virtual*/ void prerender();
+    /*virtual*/ void dirtyTextures(const std::set<LLViewerFetchedTexture*>& textures);
+    /*virtual*/ LLViewerTexture *getTexture();
+    /*virtual*/ LLViewerTexture *getDebugTexture();
+    /*virtual*/ LLColor3 getDebugColor() const; // For AGP debug display
 
-	LLPointer<LLViewerTexture> mAlphaRampImagep;
-	LLPointer<LLViewerTexture> m2DAlphaRampImagep;
-	LLPointer<LLViewerTexture> mAlphaNoiseImagep;
+    LLPointer<LLViewerTexture> mAlphaRampImagep;
+    LLPointer<LLViewerTexture> m2DAlphaRampImagep;
+    LLPointer<LLViewerTexture> mAlphaNoiseImagep;
 
-	static S32 sPBRDetailMode;
-	static F32 sDetailScale; // textures per meter
-	static F32 sPBRDetailScale; // textures per meter
+    static S32 sPBRDetailMode;
+    static F32 sDetailScale; // textures per meter
+    static F32 sPBRDetailScale; // textures per meter
 
 protected:
     void boostTerrainDetailTextures();
 
-	void renderSimple();
-	void renderOwnership();
+    void renderSimple();
+    void renderOwnership();
 
-	void renderFull2TU();
-	void renderFull4TU();
-	void renderFullShader();
-	void renderFullShaderTextures();
-	void renderFullShaderPBR(BOOL local_materials = false);
-	void drawLoop();
+    void renderFull2TU();
+    void renderFull4TU();
+    void renderFullShader();
+    void renderFullShaderTextures();
+    void renderFullShaderPBR(BOOL local_materials = false);
+    void drawLoop();
 
 private:
-	void hilightParcelOwners();
+    void hilightParcelOwners();
 };
 
 #endif // LL_LLDRAWPOOLSIMPLE_H
diff --git a/indra/newview/lldrawpoolwlsky.cpp b/indra/newview/lldrawpoolwlsky.cpp
index ee73e8a7cef36db2b900a050a7a38a5bac124c1b..e964b6984a5398330d8cce9c2b5463d24b51aee9 100644
--- a/indra/newview/lldrawpoolwlsky.cpp
+++ b/indra/newview/lldrawpoolwlsky.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lldrawpoolwlsky.cpp
  * @brief LLDrawPoolWLSky class implementation
  *
  * $LicenseInfo:firstyear=2007&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -32,7 +32,7 @@
 #include "llface.h"
 #include "llimage.h"
 #include "llrender.h"
-#include "llenvironment.h" 
+#include "llenvironment.h"
 #include "llglslshader.h"
 #include "llgl.h"
 
@@ -58,7 +58,7 @@ static LLGLSLShader* moon_shader  = NULL;
 static float sStarTime;
 
 LLDrawPoolWLSky::LLDrawPoolWLSky(void) :
-	LLDrawPool(POOL_WL_SKY)
+    LLDrawPool(POOL_WL_SKY)
 {
 }
 
@@ -68,13 +68,13 @@ LLDrawPoolWLSky::~LLDrawPoolWLSky()
 
 LLViewerTexture *LLDrawPoolWLSky::getDebugTexture()
 {
-	return NULL;
+    return NULL;
 }
 
 void LLDrawPoolWLSky::beginDeferredPass(S32 pass)
 {
-	sky_shader = &gDeferredWLSkyProgram;
-	cloud_shader = &gDeferredWLCloudProgram;
+    sky_shader = &gDeferredWLSkyProgram;
+    cloud_shader = &gDeferredWLCloudProgram;
 
     sun_shader = &gDeferredWLSunProgram;
 
@@ -97,34 +97,34 @@ void LLDrawPoolWLSky::renderDome(const LLVector3& camPosLocal, F32 camHeightLoca
     llassert_always(NULL != shader);
 
     gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-
-	//chop off translation
-	if (LLPipeline::sReflectionRender && camPosLocal.mV[2] > 256.f)
-	{
-		gGL.translatef(camPosLocal.mV[0], camPosLocal.mV[1], 256.f-camPosLocal.mV[2]*0.5f);
-	}
-	else
-	{
-		gGL.translatef(camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]);
-	}
-		
-
-	// the windlight sky dome works most conveniently in a coordinate system
-	// where Y is up, so permute our basis vectors accordingly.
-	gGL.rotatef(120.f, 1.f / F_SQRT3, 1.f / F_SQRT3, 1.f / F_SQRT3);
-
-	gGL.scalef(0.333f, 0.333f, 0.333f);
-
-	gGL.translatef(0.f,-camHeightLocal, 0.f);
-	
-	// Draw WL Sky
-	shader->uniform3f(sCamPosLocal, 0.f, camHeightLocal, 0.f);
+    gGL.pushMatrix();
+
+    //chop off translation
+    if (LLPipeline::sReflectionRender && camPosLocal.mV[2] > 256.f)
+    {
+        gGL.translatef(camPosLocal.mV[0], camPosLocal.mV[1], 256.f-camPosLocal.mV[2]*0.5f);
+    }
+    else
+    {
+        gGL.translatef(camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]);
+    }
+
+
+    // the windlight sky dome works most conveniently in a coordinate system
+    // where Y is up, so permute our basis vectors accordingly.
+    gGL.rotatef(120.f, 1.f / F_SQRT3, 1.f / F_SQRT3, 1.f / F_SQRT3);
+
+    gGL.scalef(0.333f, 0.333f, 0.333f);
+
+    gGL.translatef(0.f,-camHeightLocal, 0.f);
+
+    // Draw WL Sky
+    shader->uniform3f(sCamPosLocal, 0.f, camHeightLocal, 0.f);
 
     gSky.mVOWLSkyp->drawDome();
 
     gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.popMatrix();
+    gGL.popMatrix();
 }
 
 extern LLPointer<LLImageGL> gEXRImage;
@@ -149,8 +149,8 @@ void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 ca
 
     LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin();
 
-	if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY))
-	{
+    if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY))
+    {
         if (use_hdri_sky())
         {
             sky_shader = &gEnvironmentMapProgram;
@@ -210,9 +210,9 @@ void LLDrawPoolWLSky::renderSkyHazeDeferred(const LLVector3& camPosLocal, F32 ca
         sky_shader->uniform1i(LLShaderMgr::SUN_UP_FACTOR, psky->getIsSunUp() ? 1 : 0);
 
         /// Render the skydome
-        renderDome(origin, camHeightLocal, sky_shader);	
+        renderDome(origin, camHeightLocal, sky_shader);
 
-		sky_shader->unbind();
+        sky_shader->unbind();
     }
 }
 
@@ -223,30 +223,30 @@ void LLDrawPoolWLSky::renderStarsDeferred(const LLVector3& camPosLocal) const
         return;
     }
 
-	LLGLSPipelineBlendSkyBox gls_sky(true, false);
+    LLGLSPipelineBlendSkyBox gls_sky(true, false);
 
-	gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
+    gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
 
     F32 star_alpha = LLEnvironment::instance().getCurrentSky()->getStarBrightness() / 500.0f;
 
-	// If start_brightness is not set, exit
-	if(star_alpha < 0.001f)
-	{
-		LL_DEBUGS("SKY") << "star_brightness below threshold." << LL_ENDL;
-		return;
-	}
+    // If start_brightness is not set, exit
+    if(star_alpha < 0.001f)
+    {
+        LL_DEBUGS("SKY") << "star_brightness below threshold." << LL_ENDL;
+        return;
+    }
 
-	gDeferredStarProgram.bind();	
+    gDeferredStarProgram.bind();
 
     LLViewerTexture* tex_a = gSky.mVOSkyp->getBloomTex();
     LLViewerTexture* tex_b = gSky.mVOSkyp->getBloomTexNext();
 
     F32 blend_factor = LLEnvironment::instance().getCurrentSky()->getBlendFactor();
-	
+
     if (tex_a && (!tex_b || (tex_a == tex_b)))
     {
         // Bind current and next sun textures
-		gGL.getTexUnit(0)->bind(tex_a);
+        gGL.getTexUnit(0)->bind(tex_a);
         gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE);
         blend_factor = 0;
     }
@@ -262,29 +262,29 @@ void LLDrawPoolWLSky::renderStarsDeferred(const LLVector3& camPosLocal) const
         gGL.getTexUnit(1)->bind(tex_b);
     }
 
-	gGL.pushMatrix();
-	gGL.translatef(camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]);
-	gGL.rotatef(gFrameTimeSeconds*0.01f, 0.f, 0.f, 1.f);
+    gGL.pushMatrix();
+    gGL.translatef(camPosLocal.mV[0], camPosLocal.mV[1], camPosLocal.mV[2]);
+    gGL.rotatef(gFrameTimeSeconds*0.01f, 0.f, 0.f, 1.f);
     gDeferredStarProgram.uniform1f(LLShaderMgr::BLEND_FACTOR, blend_factor);
 
     if (LLPipeline::sReflectionRender)
     {
         star_alpha = 1.0f;
     }
-	gDeferredStarProgram.uniform1f(sCustomAlpha, star_alpha);
+    gDeferredStarProgram.uniform1f(sCustomAlpha, star_alpha);
 
     sStarTime = (F32)LLFrameTimer::getElapsedSeconds() * 0.5f;
 
     gDeferredStarProgram.uniform1f(LLShaderMgr::WATER_TIME, sStarTime);
 
-	gSky.mVOWLSkyp->drawStars();
+    gSky.mVOWLSkyp->drawStars();
 
     gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
     gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE);
 
     gDeferredStarProgram.unbind();
 
-	gGL.popMatrix();
+    gGL.popMatrix();
 }
 
 void LLDrawPoolWLSky::renderSkyCloudsDeferred(const LLVector3& camPosLocal, F32 camHeightLocal, LLGLSLShader* cloudshader) const
@@ -294,13 +294,13 @@ void LLDrawPoolWLSky::renderSkyCloudsDeferred(const LLVector3& camPosLocal, F32
         return;
     }
 
-	if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS) && gSky.mVOSkyp && gSky.mVOSkyp->getCloudNoiseTex())
-	{
+    if (gPipeline.canUseWindLightShaders() && gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS) && gSky.mVOSkyp && gSky.mVOSkyp->getCloudNoiseTex())
+    {
         LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
 
-		LLGLSPipelineBlendSkyBox pipeline(true, true);
-		
-		cloudshader->bind();
+        LLGLSPipelineBlendSkyBox pipeline(true, true);
+
+        cloudshader->bind();
 
         LLPointer<LLViewerTexture> cloud_noise      = gSky.mVOSkyp->getCloudNoiseTex();
         LLPointer<LLViewerTexture> cloud_noise_next = gSky.mVOSkyp->getCloudNoiseTexNext();
@@ -341,14 +341,14 @@ void LLDrawPoolWLSky::renderSkyCloudsDeferred(const LLVector3& camPosLocal, F32
         cloudshader->uniform1f(LLShaderMgr::CLOUD_VARIANCE, cloud_variance);
         cloudshader->uniform1f(LLShaderMgr::SUN_MOON_GLOW_FACTOR, psky->getSunMoonGlowFactor());
 
-		/// Render the skydome
+        /// Render the skydome
         renderDome(camPosLocal, camHeightLocal, cloudshader);
 
-		cloudshader->unbind();
+        cloudshader->unbind();
 
         gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
         gGL.getTexUnit(1)->unbind(LLTexUnit::TT_TEXTURE);
-	}
+    }
 }
 
 void LLDrawPoolWLSky::renderHeavenlyBodies()
@@ -358,19 +358,19 @@ void LLDrawPoolWLSky::renderHeavenlyBodies()
     LLGLSPipelineBlendSkyBox gls_skybox(true, true); // SL-14113 we need moon to write to depth to clip stars behind
 
     LLVector3 const & origin = LLViewerCamera::getInstance()->getOrigin();
-	gGL.pushMatrix();
-	gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]);
+    gGL.pushMatrix();
+    gGL.translatef(origin.mV[0], origin.mV[1], origin.mV[2]);
 
-	LLFace * face = gSky.mVOSkyp->mFace[LLVOSky::FACE_SUN];
+    LLFace * face = gSky.mVOSkyp->mFace[LLVOSky::FACE_SUN];
 
     F32 blend_factor = LLEnvironment::instance().getCurrentSky()->getBlendFactor();
     bool can_use_vertex_shaders = gPipeline.shadersLoaded();
     bool can_use_windlight_shaders = gPipeline.canUseWindLightShaders();
 
 
-	if (gSky.mVOSkyp->getSun().getDraw() && face && face->getGeomCount())
-	{
-		LLPointer<LLViewerTexture> tex_a = face->getTexture(LLRender::DIFFUSE_MAP);
+    if (gSky.mVOSkyp->getSun().getDraw() && face && face->getGeomCount())
+    {
+        LLPointer<LLViewerTexture> tex_a = face->getTexture(LLRender::DIFFUSE_MAP);
         LLPointer<LLViewerTexture> tex_b = face->getTexture(LLRender::ALTERNATE_DIFFUSE_MAP);
 
         gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
@@ -414,17 +414,17 @@ void LLDrawPoolWLSky::renderHeavenlyBodies()
                 sun_shader->unbind();
             }
         }
-	}
+    }
 
-	face = gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON];
+    face = gSky.mVOSkyp->mFace[LLVOSky::FACE_MOON];
 
-	if (gSky.mVOSkyp->getMoon().getDraw() && face && face->getTexture(LLRender::DIFFUSE_MAP) && face->getGeomCount() && moon_shader)
-	{        
+    if (gSky.mVOSkyp->getMoon().getDraw() && face && face->getTexture(LLRender::DIFFUSE_MAP) && face->getGeomCount() && moon_shader)
+    {
         LLViewerTexture* tex_a = face->getTexture(LLRender::DIFFUSE_MAP);
         LLViewerTexture* tex_b = face->getTexture(LLRender::ALTERNATE_DIFFUSE_MAP);
 
-		LLColor4 color(gSky.mVOSkyp->getMoon().getInterpColor());
-		
+        LLColor4 color(gSky.mVOSkyp->getMoon().getInterpColor());
+
         if (can_use_vertex_shaders && can_use_windlight_shaders && (tex_a || tex_b))
         {
             moon_shader->bind();
@@ -471,10 +471,10 @@ void LLDrawPoolWLSky::renderHeavenlyBodies()
 void LLDrawPoolWLSky::renderDeferred(S32 pass)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_WL_SKY);
-	if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY) || gSky.mVOSkyp.isNull())
-	{
-		return;
-	}
+    if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SKY) || gSky.mVOSkyp.isNull())
+    {
+        return;
+    }
 
     // TODO: remove gSky.mVOSkyp and fold sun/moon into LLVOWLSky
     gSky.mVOSkyp->updateGeometry(gSky.mVOSkyp->mDrawable);
@@ -503,7 +503,7 @@ void LLDrawPoolWLSky::renderDeferred(S32 pass)
 
 LLViewerTexture* LLDrawPoolWLSky::getTexture()
 {
-	return NULL;
+    return NULL;
 }
 
 void LLDrawPoolWLSky::resetDrawOrders()
diff --git a/indra/newview/llenvironment.cpp b/indra/newview/llenvironment.cpp
index a9a66e52603e116f18919902abb991643c795a2b..5053805dbbbb04c872bc8f559944e400cc3a7aa5 100644
--- a/indra/newview/llenvironment.cpp
+++ b/indra/newview/llenvironment.cpp
@@ -5,21 +5,21 @@
  * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2011, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -97,7 +97,7 @@ namespace
     const std::string KEY_ACTION("action");
     const std::string KEY_ACTIONDATA("action_data");
     const std::string KEY_EXPERIENCEID("public_id");
-    const std::string KEY_OBJECTNAME("ObjectName");     // some of these do not conform to the '_' format.  
+    const std::string KEY_OBJECTNAME("ObjectName");     // some of these do not conform to the '_' format.
     const std::string KEY_PARCELNAME("ParcelName");     // But changing these would also alter the Experience Log requirements.
     const std::string KEY_COUNT("Count");
 
@@ -373,13 +373,13 @@ namespace
         virtual ~LLSettingsInjected() = default;
 
         typename SETTINGT::ptr_t getSource() const                    { return this->mSource; }
-        void setSource(const typename SETTINGT::ptr_t &source)        
+        void setSource(const typename SETTINGT::ptr_t &source)
         {
             if (source.get() == this) // do not set a source to itself.
                 return;
-            this->mSource = source; 
-            this->setDirtyFlag(true); 
-            this->mLastSourceHash = 0; 
+            this->mSource = source;
+            this->setDirtyFlag(true);
+            this->mLastSourceHash = 0;
         }
 
         virtual bool isDirty() const override { return SETTINGT::isDirty() || (this->mSource->isDirty()); }
@@ -568,7 +568,7 @@ namespace
             if (!this->mSource)
                 return;
 
-            // clears the dirty flag on this object.  Need to prevent triggering 
+            // clears the dirty flag on this object.  Need to prevent triggering
             // more calls into this updateSettings
             LLSettingsBase::updateSettings();
 
@@ -827,7 +827,7 @@ const S32 LLEnvironment::NO_TRACK(-1);
 const S32 LLEnvironment::NO_VERSION(-3); // For viewer sided change, like ENV_LOCAL. -3 since -1 and -2 are taken by parcel initial server/viewer version
 const S32 LLEnvironment::VERSION_CLEANUP(-4); // for cleanups
 
-const F32 LLEnvironment::SUN_DELTA_YAW(F_PI);   // 180deg 
+const F32 LLEnvironment::SUN_DELTA_YAW(F_PI);   // 180deg
 
 
 const U32 LLEnvironment::DayInstance::NO_ANIMATE_SKY(0x01);
@@ -932,9 +932,9 @@ bool LLEnvironment::canEdit() const
     return true;
 }
 
-const LLSettingsSky::ptr_t& LLEnvironment::getCurrentSky() const 
-{ 
-    const LLSettingsSky::ptr_t& psky = mCurrentEnvironment->getSky(); 
+const LLSettingsSky::ptr_t& LLEnvironment::getCurrentSky() const
+{
+    const LLSettingsSky::ptr_t& psky = mCurrentEnvironment->getSky();
 
     if (!psky && mCurrentEnvironment->getEnvironmentSelection() >= ENV_EDIT)
     {
@@ -950,9 +950,9 @@ const LLSettingsSky::ptr_t& LLEnvironment::getCurrentSky() const
     return psky;
 }
 
-const LLSettingsWater::ptr_t& LLEnvironment::getCurrentWater() const 
+const LLSettingsWater::ptr_t& LLEnvironment::getCurrentWater() const
 {
-    const LLSettingsWater::ptr_t& pwater = mCurrentEnvironment->getWater(); 
+    const LLSettingsWater::ptr_t& pwater = mCurrentEnvironment->getWater();
 
     if (!pwater && mCurrentEnvironment->getEnvironmentSelection() >= ENV_EDIT)
     {
@@ -1197,7 +1197,7 @@ void LLEnvironment::setEnvironment(LLEnvironment::EnvSelection_t env, LLEnvironm
             }
         }
     }
-        
+
     if (fixed.second)
     {
         logEnvironment(env, fixed.second, env_version);
@@ -1493,12 +1493,12 @@ void LLEnvironment::updateEnvironment(LLSettingsBase::Seconds transition, bool f
     {
         if (transition != TRANSITION_INSTANT)
         {
-	        DayInstance::ptr_t trans = std::make_shared<DayTransition>(
-	            mCurrentEnvironment->getSky(), mCurrentEnvironment->getWater(), pinstance, transition);
-	
-	        trans->animate();
-	
-	        mCurrentEnvironment = trans;
+            DayInstance::ptr_t trans = std::make_shared<DayTransition>(
+                mCurrentEnvironment->getSky(), mCurrentEnvironment->getWater(), pinstance, transition);
+
+            trans->animate();
+
+            mCurrentEnvironment = trans;
         }
         else
         {
@@ -1658,12 +1658,12 @@ void LLEnvironment::update(const LLViewerCamera * cam)
 
 void LLEnvironment::updateCloudScroll()
 {
-    // This is a function of the environment rather than the sky, since it should 
+    // This is a function of the environment rather than the sky, since it should
     // persist through sky transitions.
     static LLTimer s_cloud_timer;
 
     F64 delta_t = s_cloud_timer.getElapsedTimeAndResetF64();
-    
+
     if (mCurrentEnvironment->getSky() && !mCloudScrollPaused)
     {
         LLVector2 rate = mCurrentEnvironment->getSky()->getCloudScrollRate();
@@ -1708,7 +1708,7 @@ void LLEnvironment::updateGLVariablesForSettings(LLShaderUniforms* uniforms, con
                 value = legacy_setting_it->second;
             }
         }
-        
+
 
         if(value.isUndefined())
         {
@@ -1761,7 +1761,7 @@ void LLEnvironment::updateGLVariablesForSettings(LLShaderUniforms* uniforms, con
                 };
 
                 switch (it.second.getShaderKey())
-                { 
+                {
                 case LLShaderMgr::BLUE_HORIZON:
                 case LLShaderMgr::BLUE_DENSITY:
                     vect4 = max_vec(vect4);
@@ -2161,7 +2161,7 @@ void LLEnvironment::coroUpdateEnvironment(S32 parcel_id, S32 track_no, UpdateInf
                 query << "&";
         }
         if (track_no != NO_TRACK)
-        { 
+        {
             query << "trackno=" << track_no;
         }
         url += query.str();
@@ -2244,7 +2244,7 @@ void LLEnvironment::coroResetEnvironment(S32 parcel_id, S32 track_no, environmen
     LLSD result = httpAdapter->deleteAndSuspend(httpRequest, url);
     // results that come back may contain the new settings
 
-    LLSD notify; 
+    LLSD notify;
 
     LLSD httpResults = result["http_result"];
     LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
@@ -2525,7 +2525,7 @@ void LLEnvironment::onAgentPositionHasChanged(const LLVector3 &localpos)
 S32 LLEnvironment::calculateSkyTrackForAltitude(F64 altitude)
 {
     auto it = std::find_if_not(mTrackAltitudes.begin(), mTrackAltitudes.end(), [altitude](F32 test) { return altitude > test; });
-    
+
     if (it == mTrackAltitudes.begin())
         return 1;
     else if (it == mTrackAltitudes.end())
@@ -2549,19 +2549,19 @@ void LLEnvironment::handleEnvironmentPush(LLSD &message)
 
 
     if (action == ACTION_CLEARENVIRONMENT)
-    { 
+    {
         handleEnvironmentPushClear(experience_id, action_data, transition_time);
     }
     else if (action == ACTION_PUSHFULLENVIRONMENT)
-    { 
+    {
         handleEnvironmentPushFull(experience_id, action_data, transition_time);
     }
     else if (action == ACTION_PUSHPARTIALENVIRONMENT)
-    { 
+    {
         handleEnvironmentPushPartial(experience_id, action_data, transition_time);
     }
     else
-    { 
+    {
         LL_WARNS("ENVIRONMENT", "GENERICMESSAGES") << "Unknown environment push action '" << action << "'" << LL_ENDL;
     }
 }
@@ -2775,9 +2775,9 @@ bool LLEnvironment::DayInstance::setSky(const LLSettingsSky::ptr_t &psky)
     mInitialized = false;
 
     bool changed = psky == nullptr || mSky == nullptr || mSky->getHash() != psky->getHash();
-    
+
     bool different_sky = mSky != psky;
-    
+
     mSky = psky;
     mSky->mReplaced |= different_sky;
     mSky->update();
@@ -2905,7 +2905,7 @@ LLEnvironment::DayTransition::DayTransition(const LLSettingsSky::ptr_t &skystart
     mNextInstance(end),
     mTransitionTime(time)
 {
-    
+
 }
 
 bool LLEnvironment::DayTransition::applyTimeDelta(const LLSettingsBase::Seconds& delta)
@@ -2917,14 +2917,14 @@ bool LLEnvironment::DayTransition::applyTimeDelta(const LLSettingsBase::Seconds&
     return changed;
 }
 
-void LLEnvironment::DayTransition::animate() 
+void LLEnvironment::DayTransition::animate()
 {
     mNextInstance->animate();
 
     mWater = mStartWater->buildClone();
     mBlenderWater = std::make_shared<LLSettingsBlenderTimeDelta>(mWater, mStartWater, mNextInstance->getWater(), mTransitionTime);
     mBlenderWater->setOnFinished(
-        [this](LLSettingsBlender::ptr_t blender) { 
+        [this](LLSettingsBlender::ptr_t blender) {
             mBlenderWater.reset();
 
             if (!mBlenderSky && !mBlenderWater)
@@ -3333,8 +3333,8 @@ namespace
         return changed;
     }
 
-    void DayInjection::setBaseDayInstance(const LLEnvironment::DayInstance::ptr_t &baseday) 
-    { 
+    void DayInjection::setBaseDayInstance(const LLEnvironment::DayInstance::ptr_t &baseday)
+    {
         mBaseDayInstance = baseday;
 
         if (mSkyExperience.isNull())
@@ -3543,7 +3543,7 @@ namespace
 
             mBlenderSky = std::make_shared<LLSettingsBlenderTimeDelta>(target_sky, start_sky, psky, transition);
             mBlenderSky->setOnFinished(
-                [this, psky](LLSettingsBlender::ptr_t blender) 
+                [this, psky](LLSettingsBlender::ptr_t blender)
                 {
                     mBlenderSky.reset();
                     mInjectedSky->setSource(psky);
@@ -3567,7 +3567,7 @@ namespace
             return;
         }
         if (transition == LLEnvironment::TRANSITION_INSTANT)
-        { 
+        {
             mBlenderWater.reset();
             mInjectedWater->setSource(pwater);
         }
@@ -3579,7 +3579,7 @@ namespace
 
             mBlenderWater = std::make_shared<LLSettingsBlenderTimeDelta>(scratch_Water, start_Water, pwater, transition);
             mBlenderWater->setOnFinished(
-                [this, pwater](LLSettingsBlender::ptr_t blender) 
+                [this, pwater](LLSettingsBlender::ptr_t blender)
                 {
                     mBlenderWater.reset();
                     mInjectedWater->setSource(pwater);
@@ -3600,7 +3600,7 @@ namespace
             LLEnvironment::EnvSelection_t base_env(mBaseDayInstance->getEnvironmentSelection());
             LLEnvironment::DayInstance::ptr_t nextbase = LLEnvironment::instance().getSharedEnvironmentInstance();
 
-            if ((base_env == LLEnvironment::ENV_NONE) || (nextbase == mBaseDayInstance) || 
+            if ((base_env == LLEnvironment::ENV_NONE) || (nextbase == mBaseDayInstance) ||
                     (!mSkyExperience.isNull() && !mWaterExperience.isNull()))
             {   // base instance completely overridden, or not changed no transition will happen
                 return;
@@ -3632,7 +3632,7 @@ namespace
     void DayInjection::checkExperience()
     {
         if ((!mDayExperience.isNull()) && (mSkyExperience != mDayExperience) && (mWaterExperience != mDayExperience))
-        {   // There was a day experience but we've replaced it with a water and a sky experience. 
+        {   // There was a day experience but we've replaced it with a water and a sky experience.
             mDayExperience.setNull();
             mBaseDayInstance = LLEnvironment::instance().getSharedEnvironmentInstance();
         }
diff --git a/indra/newview/llface.cpp b/indra/newview/llface.cpp
index 15ecaecaeb158c59c865b68c24e884002627b1d3..5c11816acaf453a1f3999c7e92c8eb2721920e8a 100644
--- a/indra/newview/llface.cpp
+++ b/indra/newview/llface.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llface.cpp
  * @brief LLFace class implementation
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -79,49 +79,49 @@ BOOL LLFace::sSafeRenderSelect = TRUE; // FALSE
 
 /*
 For each vertex, given:
-	B - binormal
-	T - tangent
-	N - normal
-	P - position
+    B - binormal
+    T - tangent
+    N - normal
+    P - position
 
 The resulting texture coordinate <u,v> is:
 
-	u = 2(B dot P)
-	v = 2(T dot P)
+    u = 2(B dot P)
+    v = 2(T dot P)
 */
 void planarProjection(LLVector2 &tc, const LLVector4a& normal,
-					  const LLVector4a &center, const LLVector4a& vec)
-{	
-	LLVector4a binormal;
-	F32 d = normal[0];
-
-	if (d >= 0.5f || d <= -0.5f)
-	{
-		if (d < 0)
-		{
-			binormal.set(0,-1,0);
-		}
-		else
-		{
-			binormal.set(0, 1, 0);
-		}
-	}
-	else
-	{
+                      const LLVector4a &center, const LLVector4a& vec)
+{
+    LLVector4a binormal;
+    F32 d = normal[0];
+
+    if (d >= 0.5f || d <= -0.5f)
+    {
+        if (d < 0)
+        {
+            binormal.set(0,-1,0);
+        }
+        else
+        {
+            binormal.set(0, 1, 0);
+        }
+    }
+    else
+    {
         if (normal[1] > 0)
-		{
-			binormal.set(-1,0,0);
-		}
-		else
-		{
-			binormal.set(1,0,0);
-		}
-	}
-	LLVector4a tangent;
-	tangent.setCross3(binormal,normal);
-
-	tc.mV[1] = -((tangent.dot3(vec).getF32())*2 - 0.5f);
-	tc.mV[0] = 1.0f+((binormal.dot3(vec).getF32())*2 - 0.5f);
+        {
+            binormal.set(-1,0,0);
+        }
+        else
+        {
+            binormal.set(1,0,0);
+        }
+    }
+    LLVector4a tangent;
+    tangent.setCross3(binormal,normal);
+
+    tc.mV[1] = -((tangent.dot3(vec).getF32())*2 - 0.5f);
+    tc.mV[0] = 1.0f+((binormal.dot3(vec).getF32())*2 - 0.5f);
 }
 
 ////////////////////
@@ -132,187 +132,187 @@ void planarProjection(LLVector2 &tc, const LLVector4a& normal,
 void LLFace::init(LLDrawable* drawablep, LLViewerObject* objp)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE;
-	mLastUpdateTime = gFrameTimeSeconds;
-	mLastMoveTime = 0.f;
-	mLastSkinTime = gFrameTimeSeconds;
-	mVSize = 0.f;
-	mPixelArea = 16.f;
-	mState      = GLOBAL;
-	mDrawPoolp  = NULL;
-	mPoolType = 0;
-	mCenterLocal = objp->getPosition();
-	mCenterAgent = drawablep->getPositionAgent();
-	mDistance	= 0.f;
-
-	mGeomCount		= 0;
-	mGeomIndex		= 0;
-	mIndicesCount	= 0;
-
-	//special value to indicate uninitialized position
-	mIndicesIndex	= 0xFFFFFFFF;
-	
-	for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i)
-	{
-		mIndexInTex[i] = 0;
-		mTexture[i] = NULL;
-	}
-
-	mTEOffset		= -1;
-	mTextureIndex = FACE_DO_NOT_BATCH_TEXTURES;
-
-	setDrawable(drawablep);
-	mVObjp = objp;
-
-	mReferenceIndex = -1;
-
-	mTextureMatrix = NULL;
-	mDrawInfo = NULL;
-
-	mFaceColor = LLColor4(1,0,0,1);
-
-	mImportanceToCamera = 0.f ;
-	mBoundingSphereRadius = 0.0f ;
-
-	mHasMedia = false ;
-	mIsMediaAllowed = true;
+    mLastUpdateTime = gFrameTimeSeconds;
+    mLastMoveTime = 0.f;
+    mLastSkinTime = gFrameTimeSeconds;
+    mVSize = 0.f;
+    mPixelArea = 16.f;
+    mState      = GLOBAL;
+    mDrawPoolp  = NULL;
+    mPoolType = 0;
+    mCenterLocal = objp->getPosition();
+    mCenterAgent = drawablep->getPositionAgent();
+    mDistance   = 0.f;
+
+    mGeomCount      = 0;
+    mGeomIndex      = 0;
+    mIndicesCount   = 0;
+
+    //special value to indicate uninitialized position
+    mIndicesIndex   = 0xFFFFFFFF;
+
+    for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i)
+    {
+        mIndexInTex[i] = 0;
+        mTexture[i] = NULL;
+    }
+
+    mTEOffset       = -1;
+    mTextureIndex = FACE_DO_NOT_BATCH_TEXTURES;
+
+    setDrawable(drawablep);
+    mVObjp = objp;
+
+    mReferenceIndex = -1;
+
+    mTextureMatrix = NULL;
+    mDrawInfo = NULL;
+
+    mFaceColor = LLColor4(1,0,0,1);
+
+    mImportanceToCamera = 0.f ;
+    mBoundingSphereRadius = 0.0f ;
+
+    mHasMedia = false ;
+    mIsMediaAllowed = true;
 
 // [SL:KB] - Patch: Render-TextureToggle (Catznip-4.0)
-	mShowDiffTexture = true;
+    mShowDiffTexture = true;
 // [/SL:KB]
 }
 
 void LLFace::destroy()
 {
-	if (gDebugGL)
-	{
-		gPipeline.checkReferences(this);
-	}
-
-	for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i)
-	{
-		if(mTexture[i].notNull())
-		{
-			mTexture[i]->removeFace(i, this) ;
-			mTexture[i] = NULL;
-		}
-	}
-	
-	if (isState(LLFace::PARTICLE))
-	{
-		clearState(LLFace::PARTICLE);
-	}
-
-	if (mDrawPoolp)
-	{
-		mDrawPoolp->removeFace(this);
-		mDrawPoolp = NULL;
-	}
-
-	if (mTextureMatrix)
-	{
-		delete mTextureMatrix;
-		mTextureMatrix = NULL;
-
-		if (mDrawablep)
-		{
-			LLSpatialGroup* group = mDrawablep->getSpatialGroup();
-			if (group)
-			{
-				group->dirtyGeom();
-				gPipeline.markRebuild(group);
-			}
-		}
-	}
-	
-	setDrawInfo(NULL);
-
-	mDrawablep = NULL;
-	mVObjp = NULL;
+    if (gDebugGL)
+    {
+        gPipeline.checkReferences(this);
+    }
+
+    for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i)
+    {
+        if(mTexture[i].notNull())
+        {
+            mTexture[i]->removeFace(i, this) ;
+            mTexture[i] = NULL;
+        }
+    }
+
+    if (isState(LLFace::PARTICLE))
+    {
+        clearState(LLFace::PARTICLE);
+    }
+
+    if (mDrawPoolp)
+    {
+        mDrawPoolp->removeFace(this);
+        mDrawPoolp = NULL;
+    }
+
+    if (mTextureMatrix)
+    {
+        delete mTextureMatrix;
+        mTextureMatrix = NULL;
+
+        if (mDrawablep)
+        {
+            LLSpatialGroup* group = mDrawablep->getSpatialGroup();
+            if (group)
+            {
+                group->dirtyGeom();
+                gPipeline.markRebuild(group);
+            }
+        }
+    }
+
+    setDrawInfo(NULL);
+
+    mDrawablep = NULL;
+    mVObjp = NULL;
 }
 
 void LLFace::setWorldMatrix(const LLMatrix4 &mat)
 {
-	LL_ERRS() << "Faces on this drawable are not independently modifiable\n" << LL_ENDL;
+    LL_ERRS() << "Faces on this drawable are not independently modifiable\n" << LL_ENDL;
 }
 
 void LLFace::setPool(LLFacePool* pool)
 {
-	mDrawPoolp = pool;
+    mDrawPoolp = pool;
 }
 
 void LLFace::setPool(LLFacePool* new_pool, LLViewerTexture *texturep)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
-
-	if (!new_pool)
-	{
-		LL_ERRS() << "Setting pool to null!" << LL_ENDL;
-	}
-
-	if (new_pool != mDrawPoolp)
-	{
-		// Remove from old pool
-		if (mDrawPoolp)
-		{
-			mDrawPoolp->removeFace(this);
-
-			if (mDrawablep)
-			{
-				gPipeline.markRebuild(mDrawablep, LLDrawable::REBUILD_ALL);
-			}
-		}
-		mGeomIndex = 0;
-
-		// Add to new pool
-		if (new_pool)
-		{
-			new_pool->addFace(this);
-		}
-		mDrawPoolp = new_pool;
-	}
-	
-	setTexture(texturep) ;
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
+
+    if (!new_pool)
+    {
+        LL_ERRS() << "Setting pool to null!" << LL_ENDL;
+    }
+
+    if (new_pool != mDrawPoolp)
+    {
+        // Remove from old pool
+        if (mDrawPoolp)
+        {
+            mDrawPoolp->removeFace(this);
+
+            if (mDrawablep)
+            {
+                gPipeline.markRebuild(mDrawablep, LLDrawable::REBUILD_ALL);
+            }
+        }
+        mGeomIndex = 0;
+
+        // Add to new pool
+        if (new_pool)
+        {
+            new_pool->addFace(this);
+        }
+        mDrawPoolp = new_pool;
+    }
+
+    setTexture(texturep) ;
 }
 
-void LLFace::setTexture(U32 ch, LLViewerTexture* tex) 
+void LLFace::setTexture(U32 ch, LLViewerTexture* tex)
 {
-	llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
+    llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
 
-	if(mTexture[ch] == tex)
-	{
-		return ;
-	}
+    if(mTexture[ch] == tex)
+    {
+        return ;
+    }
 
 // [SL:KB] - Patch: Render-TextureToggle (Catznip-4.0)
-	if ( (LLRender::DIFFUSE_MAP == ch) && (!mShowDiffTexture) )
-	{
-		mOrigDiffTexture = tex;
-		if (LLViewerFetchedTexture::sDefaultDiffuseImagep.get() == mTexture[ch].get())
-			return;
-	}
+    if ( (LLRender::DIFFUSE_MAP == ch) && (!mShowDiffTexture) )
+    {
+        mOrigDiffTexture = tex;
+        if (LLViewerFetchedTexture::sDefaultDiffuseImagep.get() == mTexture[ch].get())
+            return;
+    }
 // [/SL:KB]
 
-	if(mTexture[ch].notNull())
-	{
-		mTexture[ch]->removeFace(ch, this) ;
-	}	
-	
-	if(tex)
-	{
-		tex->addFace(ch, this) ;
-	}
-
-	mTexture[ch] = tex ;
+    if(mTexture[ch].notNull())
+    {
+        mTexture[ch]->removeFace(ch, this) ;
+    }
+
+    if(tex)
+    {
+        tex->addFace(ch, this) ;
+    }
+
+    mTexture[ch] = tex ;
 }
 
-void LLFace::setTexture(LLViewerTexture* tex) 
+void LLFace::setTexture(LLViewerTexture* tex)
 {
-	setDiffuseMap(tex);
+    setDiffuseMap(tex);
 }
 
 void LLFace::setDiffuseMap(LLViewerTexture* tex)
 {
-	setTexture(LLRender::DIFFUSE_MAP, tex);
+    setTexture(LLRender::DIFFUSE_MAP, tex);
 }
 
 void LLFace::setAlternateDiffuseMap(LLViewerTexture* tex)
@@ -322,282 +322,282 @@ void LLFace::setAlternateDiffuseMap(LLViewerTexture* tex)
 
 void LLFace::setNormalMap(LLViewerTexture* tex)
 {
-	setTexture(LLRender::NORMAL_MAP, tex);
+    setTexture(LLRender::NORMAL_MAP, tex);
 }
 
 void LLFace::setSpecularMap(LLViewerTexture* tex)
 {
-	setTexture(LLRender::SPECULAR_MAP, tex);
+    setTexture(LLRender::SPECULAR_MAP, tex);
 }
 
 void LLFace::dirtyTexture()
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
 
-	LLDrawable* drawablep = getDrawable();
+    LLDrawable* drawablep = getDrawable();
 
-	if (mVObjp.notNull() && mVObjp->getVolume())
-	{
-		for (U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch)
-		{
-			if (mTexture[ch].notNull() && mTexture[ch]->getComponents() == 4)
-			{ //dirty texture on an alpha object should be treated as an LoD update
-				LLVOVolume* vobj = drawablep->getVOVolume();
-				if (vobj)
-				{
-					vobj->mLODChanged = TRUE;
+    if (mVObjp.notNull() && mVObjp->getVolume())
+    {
+        for (U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch)
+        {
+            if (mTexture[ch].notNull() && mTexture[ch]->getComponents() == 4)
+            { //dirty texture on an alpha object should be treated as an LoD update
+                LLVOVolume* vobj = drawablep->getVOVolume();
+                if (vobj)
+                {
+                    vobj->mLODChanged = TRUE;
 
                     vobj->updateVisualComplexity();
-				}
-				gPipeline.markRebuild(drawablep, LLDrawable::REBUILD_VOLUME);
-			}
-		}
-	}
+                }
+                gPipeline.markRebuild(drawablep, LLDrawable::REBUILD_VOLUME);
+            }
+        }
+    }
 
-	gPipeline.markTextured(drawablep);
+    gPipeline.markTextured(drawablep);
 }
 
 void LLFace::switchTexture(U32 ch, LLViewerTexture* new_texture)
 {
-	llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
+    llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
 
-	if(mTexture[ch] == new_texture)
-	{
-		return ;
-	}
+    if(mTexture[ch] == new_texture)
+    {
+        return ;
+    }
 
-	if(!new_texture)
-	{
-		LL_ERRS() << "Can not switch to a null texture." << LL_ENDL;
-		return;
-	}
+    if(!new_texture)
+    {
+        LL_ERRS() << "Can not switch to a null texture." << LL_ENDL;
+        return;
+    }
 
-	llassert(mTexture[ch].notNull());
+    llassert(mTexture[ch].notNull());
 
-	if (ch == LLRender::DIFFUSE_MAP)
-	{
+    if (ch == LLRender::DIFFUSE_MAP)
+    {
         if (getViewerObject())
         {
-			getViewerObject()->changeTEImage(mTEOffset, new_texture) ;
+            getViewerObject()->changeTEImage(mTEOffset, new_texture) ;
         }
-	}
+    }
 
-	setTexture(ch, new_texture) ;	
-	dirtyTexture();
+    setTexture(ch, new_texture) ;
+    dirtyTexture();
 }
 
 void LLFace::setTEOffset(const S32 te_offset)
 {
-	mTEOffset = te_offset;
+    mTEOffset = te_offset;
 }
 
 
 void LLFace::setFaceColor(const LLColor4& color)
 {
-	mFaceColor = color;
-	setState(USE_FACE_COLOR);
+    mFaceColor = color;
+    setState(USE_FACE_COLOR);
 }
 
 void LLFace::unsetFaceColor()
 {
-	clearState(USE_FACE_COLOR);
+    clearState(USE_FACE_COLOR);
 }
 
 void LLFace::setDrawable(LLDrawable *drawable)
 {
-	mDrawablep  = drawable;
-	mXform      = &drawable->mXform;
+    mDrawablep  = drawable;
+    mXform      = &drawable->mXform;
 }
 
 void LLFace::setSize(S32 num_vertices, S32 num_indices, bool align)
 {
-	if (align)
-	{
-		//allocate vertices in blocks of 4 for alignment
-		num_vertices = (num_vertices + 0x3) & ~0x3;
-	}
-	
-	if (mGeomCount != num_vertices ||
-		mIndicesCount != num_indices)
-	{
-		mGeomCount    = num_vertices;
-		mIndicesCount = num_indices;
-		mVertexBuffer = NULL;
-	}
-
-	llassert(verify());
+    if (align)
+    {
+        //allocate vertices in blocks of 4 for alignment
+        num_vertices = (num_vertices + 0x3) & ~0x3;
+    }
+
+    if (mGeomCount != num_vertices ||
+        mIndicesCount != num_indices)
+    {
+        mGeomCount    = num_vertices;
+        mIndicesCount = num_indices;
+        mVertexBuffer = NULL;
+    }
+
+    llassert(verify());
 }
 
-void LLFace::setGeomIndex(U16 idx) 
-{ 
-	if (mGeomIndex != idx)
-	{
-		mGeomIndex = idx; 
-		mVertexBuffer = NULL;
-	}
+void LLFace::setGeomIndex(U16 idx)
+{
+    if (mGeomIndex != idx)
+    {
+        mGeomIndex = idx;
+        mVertexBuffer = NULL;
+    }
 }
 
 void LLFace::setTextureIndex(U8 index)
 {
-	if (index != mTextureIndex)
-	{
-		mTextureIndex = index;
-
-		if (mTextureIndex != FACE_DO_NOT_BATCH_TEXTURES)
-		{
-			mDrawablep->setState(LLDrawable::REBUILD_POSITION);
-		}
-		else
-		{
-			if (mDrawInfo && !mDrawInfo->mTextureList.empty())
-			{
-				LL_ERRS() << "Face with no texture index references indexed texture draw info." << LL_ENDL;
-			}
-		}
-	}
+    if (index != mTextureIndex)
+    {
+        mTextureIndex = index;
+
+        if (mTextureIndex != FACE_DO_NOT_BATCH_TEXTURES)
+        {
+            mDrawablep->setState(LLDrawable::REBUILD_POSITION);
+        }
+        else
+        {
+            if (mDrawInfo && !mDrawInfo->mTextureList.empty())
+            {
+                LL_ERRS() << "Face with no texture index references indexed texture draw info." << LL_ENDL;
+            }
+        }
+    }
 }
 
-void LLFace::setIndicesIndex(S32 idx) 
-{ 
-	if (mIndicesIndex != idx)
-	{
-		mIndicesIndex = idx; 
-		mVertexBuffer = NULL;
-	}
+void LLFace::setIndicesIndex(S32 idx)
+{
+    if (mIndicesIndex != idx)
+    {
+        mIndicesIndex = idx;
+        mVertexBuffer = NULL;
+    }
 }
-	
+
 //============================================================================
 
 U16 LLFace::getGeometryAvatar(
-						LLStrider<LLVector3> &vertices,
-						LLStrider<LLVector3> &normals,
-						LLStrider<LLVector2> &tex_coords,
-						LLStrider<F32>		 &vertex_weights,
-						LLStrider<LLVector4a> &clothing_weights)
+                        LLStrider<LLVector3> &vertices,
+                        LLStrider<LLVector3> &normals,
+                        LLStrider<LLVector2> &tex_coords,
+                        LLStrider<F32>       &vertex_weights,
+                        LLStrider<LLVector4a> &clothing_weights)
 {
-	if (mVertexBuffer.notNull())
-	{
-		mVertexBuffer->getVertexStrider      (vertices, mGeomIndex, mGeomCount);
-		mVertexBuffer->getNormalStrider      (normals, mGeomIndex, mGeomCount);
-		mVertexBuffer->getTexCoord0Strider    (tex_coords, mGeomIndex, mGeomCount);
-		mVertexBuffer->getWeightStrider(vertex_weights, mGeomIndex, mGeomCount);
-		mVertexBuffer->getClothWeightStrider(clothing_weights, mGeomIndex, mGeomCount);
-	}
-
-	return mGeomIndex;
+    if (mVertexBuffer.notNull())
+    {
+        mVertexBuffer->getVertexStrider      (vertices, mGeomIndex, mGeomCount);
+        mVertexBuffer->getNormalStrider      (normals, mGeomIndex, mGeomCount);
+        mVertexBuffer->getTexCoord0Strider    (tex_coords, mGeomIndex, mGeomCount);
+        mVertexBuffer->getWeightStrider(vertex_weights, mGeomIndex, mGeomCount);
+        mVertexBuffer->getClothWeightStrider(clothing_weights, mGeomIndex, mGeomCount);
+    }
+
+    return mGeomIndex;
 }
 
 U16 LLFace::getGeometry(LLStrider<LLVector3> &vertices, LLStrider<LLVector3> &normals,
-					    LLStrider<LLVector2> &tex_coords, LLStrider<U16> &indicesp)
+                        LLStrider<LLVector2> &tex_coords, LLStrider<U16> &indicesp)
 {
-	if (mVertexBuffer.notNull())
-	{
-		mVertexBuffer->getVertexStrider(vertices,   mGeomIndex, mGeomCount);
-		if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL))
-		{
-			mVertexBuffer->getNormalStrider(normals,    mGeomIndex, mGeomCount);
-		}
-		if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD0))
-		{
-			mVertexBuffer->getTexCoord0Strider(tex_coords, mGeomIndex, mGeomCount);
-		}
-
-		mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount);
-	}
-	
-	return mGeomIndex;
+    if (mVertexBuffer.notNull())
+    {
+        mVertexBuffer->getVertexStrider(vertices,   mGeomIndex, mGeomCount);
+        if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL))
+        {
+            mVertexBuffer->getNormalStrider(normals,    mGeomIndex, mGeomCount);
+        }
+        if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD0))
+        {
+            mVertexBuffer->getTexCoord0Strider(tex_coords, mGeomIndex, mGeomCount);
+        }
+
+        mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount);
+    }
+
+    return mGeomIndex;
 }
 
 void LLFace::updateCenterAgent()
 {
-	if (mDrawablep->isActive())
-	{
-		LLVector4a local_pos;
-		local_pos.load3(mCenterLocal.mV);
-
-		getRenderMatrix().affineTransform(local_pos,local_pos);
-		mCenterAgent.set(local_pos.getF32ptr());
-	}
-	else
-	{
-		mCenterAgent = mCenterLocal;
-	}
+    if (mDrawablep->isActive())
+    {
+        LLVector4a local_pos;
+        local_pos.load3(mCenterLocal.mV);
+
+        getRenderMatrix().affineTransform(local_pos,local_pos);
+        mCenterAgent.set(local_pos.getF32ptr());
+    }
+    else
+    {
+        mCenterAgent = mCenterLocal;
+    }
 }
 
 void LLFace::renderSelected(LLViewerTexture *imagep, const LLColor4& color)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
-
-	if (mDrawablep == NULL || mDrawablep->getSpatialGroup() == NULL)
-	{
-		return;
-	}
-
-	mDrawablep->getSpatialGroup()->rebuildGeom();
-	mDrawablep->getSpatialGroup()->rebuildMesh();
-		
-	if(mVertexBuffer.isNull())
-	{
-		return;
-	}
-
-	if (mGeomCount > 0 && mIndicesCount > 0)
-	{
-		gGL.getTexUnit(0)->bind(imagep);
-	
-		gGL.pushMatrix();
-
-		const LLMatrix4a* model_matrix = NULL;
-		if (mDrawablep->isActive())
-		{
-			model_matrix = &(mDrawablep->getRenderMatrix());
-		}
-		else
-		{
-			model_matrix = &mDrawablep->getRegion()->mRenderMatrix;
-		}
-		if(model_matrix && !model_matrix->isIdentity())
-		{
-			gGL.multMatrix(*model_matrix);
-		}
-
-		gGL.diffuseColor4fv(color.mV);
-
-		if (mDrawablep->isState(LLDrawable::RIGGED))
-		{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
+
+    if (mDrawablep == NULL || mDrawablep->getSpatialGroup() == NULL)
+    {
+        return;
+    }
+
+    mDrawablep->getSpatialGroup()->rebuildGeom();
+    mDrawablep->getSpatialGroup()->rebuildMesh();
+
+    if(mVertexBuffer.isNull())
+    {
+        return;
+    }
+
+    if (mGeomCount > 0 && mIndicesCount > 0)
+    {
+        gGL.getTexUnit(0)->bind(imagep);
+
+        gGL.pushMatrix();
+
+        const LLMatrix4a* model_matrix = NULL;
+        if (mDrawablep->isActive())
+        {
+            model_matrix = &(mDrawablep->getRenderMatrix());
+        }
+        else
+        {
+            model_matrix = &mDrawablep->getRegion()->mRenderMatrix;
+        }
+        if(model_matrix && !model_matrix->isIdentity())
+        {
+            gGL.multMatrix(*model_matrix);
+        }
+
+        gGL.diffuseColor4fv(color.mV);
+
+        if (mDrawablep->isState(LLDrawable::RIGGED))
+        {
 #if 0 // TODO --  there is no way this won't destroy our GL machine as implemented, rewrite it to not rely on software skinning
-			LLVOVolume* volume = mDrawablep->getVOVolume();
-			if (volume)
-			{
-				LLRiggedVolume* rigged = volume->getRiggedVolume();
-				if (rigged)
-				{
+            LLVOVolume* volume = mDrawablep->getVOVolume();
+            if (volume)
+            {
+                LLRiggedVolume* rigged = volume->getRiggedVolume();
+                if (rigged)
+                {
                     // called when selecting a face during edit of a mesh object
-					LLGLEnable offset(GL_POLYGON_OFFSET_FILL);
-					glPolygonOffset(-1.f, -1.f);
-					gGL.multMatrix(volume->getRelativeXform());
-					const LLVolumeFace& vol_face = rigged->getVolumeFace(getTEOffset());
+                    LLGLEnable offset(GL_POLYGON_OFFSET_FILL);
+                    glPolygonOffset(-1.f, -1.f);
+                    gGL.multMatrix(volume->getRelativeXform());
+                    const LLVolumeFace& vol_face = rigged->getVolumeFace(getTEOffset());
                     LLVertexBuffer::drawElements(LLRender::TRIANGLES,vol_face.mPositions, vol_face.mTexCoords, vol_face.mNumIndices, vol_face.mIndices);
-				}
-			}
+                }
+            }
 #endif
-		}
-		else
-		{
-			// cheaters sometimes prosper...
-			//
-			mVertexBuffer->setBuffer();
-			mVertexBuffer->draw(LLRender::TRIANGLES, mIndicesCount, mIndicesIndex);
-		}
-
-		gGL.popMatrix();
-	}
+        }
+        else
+        {
+            // cheaters sometimes prosper...
+            //
+            mVertexBuffer->setBuffer();
+            mVertexBuffer->draw(LLRender::TRIANGLES, mIndicesCount, mIndicesIndex);
+        }
+
+        gGL.popMatrix();
+    }
 }
 
 
 void renderFace(LLDrawable* drawable, LLFace *face)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
 
     LLVOVolume* vobj = drawable->getVOVolume();
     if (vobj)
@@ -659,7 +659,7 @@ void LLFace::renderOneWireframe(const LLColor4 &color, F32 fogCfx, bool wirefram
 
         LLGLEnable offset(GL_POLYGON_OFFSET_LINE);
         glPolygonOffset(3.f, 3.f);
-		gGL.setLineWidth(5.f);
+        gGL.setLineWidth(5.f);
         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
         renderFace(mDrawablep, this);
     }
@@ -667,235 +667,235 @@ void LLFace::renderOneWireframe(const LLColor4 &color, F32 fogCfx, bool wirefram
 
 void LLFace::setDrawInfo(LLDrawInfo* draw_info)
 {
-	mDrawInfo = draw_info;
+    mDrawInfo = draw_info;
 }
 
 void LLFace::printDebugInfo() const
 {
-	LLFacePool *poolp = getPool();
-	LL_INFOS() << "Object: " << getViewerObject()->mID << LL_ENDL;
-	if (getDrawable())
-	{
-		LL_INFOS() << "Type: " << LLPrimitive::pCodeToString(getDrawable()->getVObj()->getPCode()) << LL_ENDL;
-	}
-	if (getTexture())
-	{
-		LL_INFOS() << "Texture: " << getTexture() << " Comps: " << (U32)getTexture()->getComponents() << LL_ENDL;
-	}
-	else
-	{
-		LL_INFOS() << "No texture: " << LL_ENDL;
-	}
-
-	LL_INFOS() << "Face: " << this << LL_ENDL;
-	LL_INFOS() << "State: " << getState() << LL_ENDL;
-	LL_INFOS() << "Geom Index Data:" << LL_ENDL;
-	LL_INFOS() << "--------------------" << LL_ENDL;
-	LL_INFOS() << "GI: " << mGeomIndex << " Count:" << mGeomCount << LL_ENDL;
-	LL_INFOS() << "Face Index Data:" << LL_ENDL;
-	LL_INFOS() << "--------------------" << LL_ENDL;
-	LL_INFOS() << "II: " << mIndicesIndex << " Count:" << mIndicesCount << LL_ENDL;
-	LL_INFOS() << LL_ENDL;
-
-	if (poolp)
-	{
-		poolp->printDebugInfo();
-
-		S32 pool_references = 0;
-		for (std::vector<LLFace*>::iterator iter = poolp->mReferences.begin();
-			 iter != poolp->mReferences.end(); iter++)
-		{
-			LLFace *facep = *iter;
-			if (facep == this)
-			{
-				LL_INFOS() << "Pool reference: " << pool_references << LL_ENDL;
-				pool_references++;
-			}
-		}
-
-		if (pool_references != 1)
-		{
-			LL_INFOS() << "Incorrect number of pool references!" << LL_ENDL;
-		}
-	}
+    LLFacePool *poolp = getPool();
+    LL_INFOS() << "Object: " << getViewerObject()->mID << LL_ENDL;
+    if (getDrawable())
+    {
+        LL_INFOS() << "Type: " << LLPrimitive::pCodeToString(getDrawable()->getVObj()->getPCode()) << LL_ENDL;
+    }
+    if (getTexture())
+    {
+        LL_INFOS() << "Texture: " << getTexture() << " Comps: " << (U32)getTexture()->getComponents() << LL_ENDL;
+    }
+    else
+    {
+        LL_INFOS() << "No texture: " << LL_ENDL;
+    }
+
+    LL_INFOS() << "Face: " << this << LL_ENDL;
+    LL_INFOS() << "State: " << getState() << LL_ENDL;
+    LL_INFOS() << "Geom Index Data:" << LL_ENDL;
+    LL_INFOS() << "--------------------" << LL_ENDL;
+    LL_INFOS() << "GI: " << mGeomIndex << " Count:" << mGeomCount << LL_ENDL;
+    LL_INFOS() << "Face Index Data:" << LL_ENDL;
+    LL_INFOS() << "--------------------" << LL_ENDL;
+    LL_INFOS() << "II: " << mIndicesIndex << " Count:" << mIndicesCount << LL_ENDL;
+    LL_INFOS() << LL_ENDL;
+
+    if (poolp)
+    {
+        poolp->printDebugInfo();
+
+        S32 pool_references = 0;
+        for (std::vector<LLFace*>::iterator iter = poolp->mReferences.begin();
+             iter != poolp->mReferences.end(); iter++)
+        {
+            LLFace *facep = *iter;
+            if (facep == this)
+            {
+                LL_INFOS() << "Pool reference: " << pool_references << LL_ENDL;
+                pool_references++;
+            }
+        }
+
+        if (pool_references != 1)
+        {
+            LL_INFOS() << "Incorrect number of pool references!" << LL_ENDL;
+        }
+    }
 
 #if 0
-	LL_INFOS() << "Indices:" << LL_ENDL;
-	LL_INFOS() << "--------------------" << LL_ENDL;
-
-	const U32 *indicesp = getRawIndices();
-	S32 indices_count = getIndicesCount();
-	S32 geom_start = getGeomStart();
-
-	for (S32 i = 0; i < indices_count; i++)
-	{
-		LL_INFOS() << i << ":" << indicesp[i] << ":" << (S32)(indicesp[i] - geom_start) << LL_ENDL;
-	}
-	LL_INFOS() << LL_ENDL;
-
-	LL_INFOS() << "Vertices:" << LL_ENDL;
-	LL_INFOS() << "--------------------" << LL_ENDL;
-	for (S32 i = 0; i < mGeomCount; i++)
-	{
-		LL_INFOS() << mGeomIndex + i << ":" << poolp->getVertex(mGeomIndex + i) << LL_ENDL;
-	}
-	LL_INFOS() << LL_ENDL;
+    LL_INFOS() << "Indices:" << LL_ENDL;
+    LL_INFOS() << "--------------------" << LL_ENDL;
+
+    const U32 *indicesp = getRawIndices();
+    S32 indices_count = getIndicesCount();
+    S32 geom_start = getGeomStart();
+
+    for (S32 i = 0; i < indices_count; i++)
+    {
+        LL_INFOS() << i << ":" << indicesp[i] << ":" << (S32)(indicesp[i] - geom_start) << LL_ENDL;
+    }
+    LL_INFOS() << LL_ENDL;
+
+    LL_INFOS() << "Vertices:" << LL_ENDL;
+    LL_INFOS() << "--------------------" << LL_ENDL;
+    for (S32 i = 0; i < mGeomCount; i++)
+    {
+        LL_INFOS() << mGeomIndex + i << ":" << poolp->getVertex(mGeomIndex + i) << LL_ENDL;
+    }
+    LL_INFOS() << LL_ENDL;
 #endif
 }
 
 // Transform the texture coordinates for this face.
 static void xform(LLVector2 &tex_coord, F32 cosAng, F32 sinAng, F32 offS, F32 offT, F32 magS, F32 magT)
 {
-	// New, good way
-	F32 s = tex_coord.mV[0];
-	F32 t = tex_coord.mV[1];
+    // New, good way
+    F32 s = tex_coord.mV[0];
+    F32 t = tex_coord.mV[1];
 
-	// Texture transforms are done about the center of the face.
-	s -= 0.5; 
-	t -= 0.5;
+    // Texture transforms are done about the center of the face.
+    s -= 0.5;
+    t -= 0.5;
 
-	// Handle rotation
-	F32 temp = s;
-	s  = s     * cosAng + t * sinAng;
-	t  = -temp * sinAng + t * cosAng;
+    // Handle rotation
+    F32 temp = s;
+    s  = s     * cosAng + t * sinAng;
+    t  = -temp * sinAng + t * cosAng;
 
-	// Then scale
-	s *= magS;
-	t *= magT;
+    // Then scale
+    s *= magS;
+    t *= magT;
 
-	// Then offset
-	s += offS + 0.5f; 
-	t += offT + 0.5f;
+    // Then offset
+    s += offS + 0.5f;
+    t += offT + 0.5f;
 
-	tex_coord.mV[0] = s;
-	tex_coord.mV[1] = t;
+    tex_coord.mV[0] = s;
+    tex_coord.mV[1] = t;
 }
 
 // Transform the texture coordinates for this face.
-static void xform4a(LLVector4a &tex_coord, const LLVector4a& trans, const LLVector4Logical& mask, const LLVector4a& rot0, const LLVector4a& rot1, const LLVector4a& offset, const LLVector4a& scale) 
+static void xform4a(LLVector4a &tex_coord, const LLVector4a& trans, const LLVector4Logical& mask, const LLVector4a& rot0, const LLVector4a& rot1, const LLVector4a& offset, const LLVector4a& scale)
 {
-	//tex coord is two coords, <s0, t0, s1, t1>
-	LLVector4a st;
-
-	// Texture transforms are done about the center of the face.
-	st.setAdd(tex_coord, trans);
-	
-	// <s0 * cosAng, s0*-sinAng, s1*cosAng, s1*-sinAng>
-	LLVector4a s0;
-	s0.splat(st, 0);
-	LLVector4a s1;
-	s1.splat(st, 2);
-	LLVector4a ss;
-	ss.setSelectWithMask(mask, s1, s0);
-
-	LLVector4a a; 
-	a.setMul(rot0, ss);
-	
-	// <t0*sinAng, t0*cosAng, t1*sinAng, t1*cosAng>
-	LLVector4a t0;
-	t0.splat(st, 1);
-	LLVector4a t1;
-	t1.splat(st, 3);
-	LLVector4a tt;
-	tt.setSelectWithMask(mask, t1, t0);
-
-	LLVector4a b;
-	b.setMul(rot1, tt);
-		
-	st.setAdd(a,b);
-
-	// Then scale
-	st.mul(scale);
-
-	// Then offset
-	tex_coord.setAdd(st, offset);
+    //tex coord is two coords, <s0, t0, s1, t1>
+    LLVector4a st;
+
+    // Texture transforms are done about the center of the face.
+    st.setAdd(tex_coord, trans);
+
+    // <s0 * cosAng, s0*-sinAng, s1*cosAng, s1*-sinAng>
+    LLVector4a s0;
+    s0.splat(st, 0);
+    LLVector4a s1;
+    s1.splat(st, 2);
+    LLVector4a ss;
+    ss.setSelectWithMask(mask, s1, s0);
+
+    LLVector4a a;
+    a.setMul(rot0, ss);
+
+    // <t0*sinAng, t0*cosAng, t1*sinAng, t1*cosAng>
+    LLVector4a t0;
+    t0.splat(st, 1);
+    LLVector4a t1;
+    t1.splat(st, 3);
+    LLVector4a tt;
+    tt.setSelectWithMask(mask, t1, t0);
+
+    LLVector4a b;
+    b.setMul(rot1, tt);
+
+    st.setAdd(a,b);
+
+    // Then scale
+    st.mul(scale);
+
+    // Then offset
+    tex_coord.setAdd(st, offset);
 }
 
 
 bool less_than_max_mag(const LLVector4a& vec)
 {
-	LLVector4a MAX_MAG;
-	MAX_MAG.splat(1024.f*1024.f);
+    LLVector4a MAX_MAG;
+    MAX_MAG.splat(1024.f*1024.f);
+
+    LLVector4a val;
+    val.setAbs(vec);
 
-	LLVector4a val;
-	val.setAbs(vec);
+    S32 lt = val.lessThan(MAX_MAG).getGatheredBits() & 0x7;
 
-	S32 lt = val.lessThan(MAX_MAG).getGatheredBits() & 0x7;
-	
-	return lt == 0x7;
+    return lt == 0x7;
 }
 
 BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f,
                              const LLMatrix4a& mat_vert, BOOL global_volume)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
-
-	//get bounding box
-	if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION | LLDrawable::REBUILD_RIGGED))
-	{
-		if (f >= volume.getNumVolumeFaces())
-		{
-			LL_WARNS() << "Generating bounding box for invalid face index!" << LL_ENDL;
-			f = 0;
-		}
-
-		const LLVolumeFace &face = volume.getVolumeFace(f);
-		
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE
+
+    //get bounding box
+    if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION | LLDrawable::REBUILD_RIGGED))
+    {
+        if (f >= volume.getNumVolumeFaces())
+        {
+            LL_WARNS() << "Generating bounding box for invalid face index!" << LL_ENDL;
+            f = 0;
+        }
+
+        const LLVolumeFace &face = volume.getVolumeFace(f);
+
 #ifdef SHOW_DEBUG
-        LL_DEBUGS("RiggedBox") << "updating extents for face " << f 
-                               << " starting extents " << mExtents[0] << ", " << mExtents[1] 
-                               << " starting vf extents " << face.mExtents[0] << ", " << face.mExtents[1] 
+        LL_DEBUGS("RiggedBox") << "updating extents for face " << f
+                               << " starting extents " << mExtents[0] << ", " << mExtents[1]
+                               << " starting vf extents " << face.mExtents[0] << ", " << face.mExtents[1]
                                << " num verts " << face.mNumVertices << LL_ENDL;
 #endif
 
         // MAINT-8264 - stray vertices, especially in low LODs, cause bounding box errors.
-		if (face.mNumVertices < 3) 
+        if (face.mNumVertices < 3)
         {
 #ifdef SHOW_DEBUG
-            LL_DEBUGS("RiggedBox") << "skipping face " << f << ", bad num vertices " 
+            LL_DEBUGS("RiggedBox") << "skipping face " << f << ", bad num vertices "
                                    << face.mNumVertices << " " << face.mNumIndices << " " << face.mWeights << LL_ENDL;
 #endif
             return FALSE;
         }
-        
-		llassert(less_than_max_mag(face.mExtents[0]));
-		llassert(less_than_max_mag(face.mExtents[1]));
 
-		mat_vert.mulBoundBox(face.mExtents, mExtents);
+        llassert(less_than_max_mag(face.mExtents[0]));
+        llassert(less_than_max_mag(face.mExtents[1]));
+
+        mat_vert.mulBoundBox(face.mExtents, mExtents);
 
 #ifdef SHOW_DEBUG
-        LL_DEBUGS("RiggedBox") << "updated extents for face " << f 
+        LL_DEBUGS("RiggedBox") << "updated extents for face " << f
                                << " bbox gave extents " << mExtents[0] << ", " << mExtents[1] << LL_ENDL;
 #endif
 
-		if (!mDrawablep->isActive())
-		{	// Shift position for region
-			LLVector4a offset;
-			offset.load3(mDrawablep->getRegion()->getOriginAgent().mV);
-			mExtents[0].add(offset);
-			mExtents[1].add(offset);
+        if (!mDrawablep->isActive())
+        {   // Shift position for region
+            LLVector4a offset;
+            offset.load3(mDrawablep->getRegion()->getOriginAgent().mV);
+            mExtents[0].add(offset);
+            mExtents[1].add(offset);
 #ifdef SHOW_DEBUG
-            LL_DEBUGS("RiggedBox") << "updating extents for face " << f 
+            LL_DEBUGS("RiggedBox") << "updating extents for face " << f
                                    << " not active, added offset " << offset << LL_ENDL;
 #endif
-		}
+        }
 #ifdef SHOW_DEBUG
-        LL_DEBUGS("RiggedBox") << "updated extents for face " << f 
+        LL_DEBUGS("RiggedBox") << "updated extents for face " << f
                                << " to " << mExtents[0] << ", " << mExtents[1] << LL_ENDL;
 #endif
-		LLVector4a t;
-		t.setAdd(mExtents[0],mExtents[1]);
-		t.mul(0.5f);
+        LLVector4a t;
+        t.setAdd(mExtents[0],mExtents[1]);
+        t.mul(0.5f);
 
-		mCenterLocal.set(t.getF32ptr());
+        mCenterLocal.set(t.getF32ptr());
 
-		t.setSub(mExtents[1],mExtents[0]);
-		mBoundingSphereRadius = t.getLength3().getF32()*0.5f;
+        t.setSub(mExtents[1],mExtents[0]);
+        mBoundingSphereRadius = t.getLength3().getF32()*0.5f;
 
-		updateCenterAgent();
-	}
+        updateCenterAgent();
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 
@@ -907,123 +907,123 @@ BOOL LLFace::genVolumeBBoxes(const LLVolume &volume, S32 f,
 // with the implications.
 LLVector2 LLFace::surfaceToTexture(LLVector2 surface_coord, const LLVector4a& position, const LLVector4a& normal)
 {
-	LLVector2 tc = surface_coord;
-	
-	const LLTextureEntry *tep = getTextureEntry();
-
-	if (tep == NULL)
-	{
-		// can't do much without the texture entry
-		return surface_coord;
-	}
-
-	//VECTORIZE THIS
-	// see if we have a non-default mapping
+    LLVector2 tc = surface_coord;
+
+    const LLTextureEntry *tep = getTextureEntry();
+
+    if (tep == NULL)
+    {
+        // can't do much without the texture entry
+        return surface_coord;
+    }
+
+    //VECTORIZE THIS
+    // see if we have a non-default mapping
     U8 texgen = getTextureEntry()->getTexGen();
-	if (texgen != LLTextureEntry::TEX_GEN_DEFAULT)
-	{
-		LLVector4a& center = *(mDrawablep->getVOVolume()->getVolume()->getVolumeFace(mTEOffset).mCenter);
-		
-		LLVector4a volume_position;
-		LLVector3 v_position(position.getF32ptr());
-
-		volume_position.load3(mDrawablep->getVOVolume()->agentPositionToVolume(v_position).mV);
-		
-		if (!mDrawablep->getVOVolume()->isVolumeGlobal())
-		{
-			LLVector4a scale;
-			scale.load3(mVObjp->getScale().mV);
-			volume_position.mul(scale);
-		}
-		
-		LLVector4a volume_normal;
-		LLVector3 v_normal(normal.getF32ptr());
-		volume_normal.load3(mDrawablep->getVOVolume()->agentDirectionToVolume(v_normal).mV);
-		volume_normal.normalize3fast();
-		
-		if (texgen == LLTextureEntry::TEX_GEN_PLANAR)
-		{
-			planarProjection(tc, volume_normal, center, volume_position);
-		}		
-	}
-
-	if (mTextureMatrix)	// if we have a texture matrix, use it
-	{
-		LLVector4a tc4(tc.mV[VX],tc.mV[VY],0.f);
-		mTextureMatrix->affineTransform(tc4,tc4);
-		tc.set(tc4.getF32ptr());
-	}
-	
-	else // otherwise use the texture entry parameters
-	{
-		xform(tc, cos(tep->getRotation()), sin(tep->getRotation()),
-			  tep->mOffsetS, tep->mOffsetT, tep->mScaleS, tep->mScaleT);
-	}
-
-	
-	return tc;
+    if (texgen != LLTextureEntry::TEX_GEN_DEFAULT)
+    {
+        LLVector4a& center = *(mDrawablep->getVOVolume()->getVolume()->getVolumeFace(mTEOffset).mCenter);
+
+        LLVector4a volume_position;
+        LLVector3 v_position(position.getF32ptr());
+
+        volume_position.load3(mDrawablep->getVOVolume()->agentPositionToVolume(v_position).mV);
+
+        if (!mDrawablep->getVOVolume()->isVolumeGlobal())
+        {
+            LLVector4a scale;
+            scale.load3(mVObjp->getScale().mV);
+            volume_position.mul(scale);
+        }
+
+        LLVector4a volume_normal;
+        LLVector3 v_normal(normal.getF32ptr());
+        volume_normal.load3(mDrawablep->getVOVolume()->agentDirectionToVolume(v_normal).mV);
+        volume_normal.normalize3fast();
+
+        if (texgen == LLTextureEntry::TEX_GEN_PLANAR)
+        {
+            planarProjection(tc, volume_normal, center, volume_position);
+        }
+    }
+
+    if (mTextureMatrix) // if we have a texture matrix, use it
+    {
+        LLVector4a tc4(tc.mV[VX],tc.mV[VY],0.f);
+        mTextureMatrix->affineTransform(tc4,tc4);
+        tc.set(tc4.getF32ptr());
+    }
+
+    else // otherwise use the texture entry parameters
+    {
+        xform(tc, cos(tep->getRotation()), sin(tep->getRotation()),
+              tep->mOffsetS, tep->mOffsetT, tep->mScaleS, tep->mScaleT);
+    }
+
+
+    return tc;
 }
 
 // Returns scale compared to default texgen, and face orientation as calculated
 // by planarProjection(). This is needed to match planar texgen parameters.
 void LLFace::getPlanarProjectedParams(LLQuaternion* face_rot, LLVector3* face_pos, F32* scale) const
 {
-	const LLMatrix4a& vol_mat = getWorldMatrix();
-	const LLVolumeFace& vf = getViewerObject()->getVolume()->getVolumeFace(mTEOffset);
+    const LLMatrix4a& vol_mat = getWorldMatrix();
+    const LLVolumeFace& vf = getViewerObject()->getVolume()->getVolumeFace(mTEOffset);
     if (!vf.mNormals)
     {
         LL_WARNS( ) << "Volume face without normals (object id: " << getViewerObject()->getID().asString() << ")" << LL_ENDL;
         return;
     }
-    
+
     if (!vf.mTangents)
     {
         LL_WARNS( ) << "Volume face without tangents (object id: " << getViewerObject()->getID().asString() << ")" << LL_ENDL;
         return;
     }
-	const LLVector4a& normal = vf.mNormals[0];
-	const LLVector4a& tangent = vf.mTangents[0];
+    const LLVector4a& normal = vf.mNormals[0];
+    const LLVector4a& tangent = vf.mTangents[0];
 
-	LLVector4a binormal;
-	binormal.setCross3(normal, tangent);
-	binormal.mul(tangent.getF32ptr()[3]);
+    LLVector4a binormal;
+    binormal.setCross3(normal, tangent);
+    binormal.mul(tangent.getF32ptr()[3]);
 
-	LLVector2 projected_binormal;
-	planarProjection(projected_binormal, normal, *vf.mCenter, binormal);
-	projected_binormal -= LLVector2(0.5f, 0.5f); // this normally happens in xform()
-	*scale = projected_binormal.length();
-	// rotate binormal to match what planarProjection() thinks it is,
-	// then find rotation from that:
-	projected_binormal.normalize();
-	F32 ang = acos(projected_binormal.mV[VY]);
-	ang = (projected_binormal.mV[VX] < 0.f) ? -ang : ang;
+    LLVector2 projected_binormal;
+    planarProjection(projected_binormal, normal, *vf.mCenter, binormal);
+    projected_binormal -= LLVector2(0.5f, 0.5f); // this normally happens in xform()
+    *scale = projected_binormal.length();
+    // rotate binormal to match what planarProjection() thinks it is,
+    // then find rotation from that:
+    projected_binormal.normalize();
+    F32 ang = acos(projected_binormal.mV[VY]);
+    ang = (projected_binormal.mV[VX] < 0.f) ? -ang : ang;
 
-	ALGLMath::genRot(RAD_TO_DEG * ang, normal).rotate(binormal, binormal);
+    ALGLMath::genRot(RAD_TO_DEG * ang, normal).rotate(binormal, binormal);
 
-	LLVector4a x_axis;
-	x_axis.setCross3(binormal, normal);
+    LLVector4a x_axis;
+    x_axis.setCross3(binormal, normal);
 
-	//VECTORIZE THIS
-	LLQuaternion local_rot(LLVector3(x_axis.getF32ptr()), LLVector3(binormal.getF32ptr()), LLVector3(normal.getF32ptr()));
-	*face_rot = local_rot * LLMatrix4(vol_mat.getF32ptr()).quaternion();
+    //VECTORIZE THIS
+    LLQuaternion local_rot(LLVector3(x_axis.getF32ptr()), LLVector3(binormal.getF32ptr()), LLVector3(normal.getF32ptr()));
+    *face_rot = local_rot * LLMatrix4(vol_mat.getF32ptr()).quaternion();
 
-	face_pos->set(vol_mat.getRow<VW>().getF32ptr());
+    face_pos->set(vol_mat.getRow<VW>().getF32ptr());
 }
 
 // Returns the necessary texture transform to align this face's TE to align_to's TE
-bool LLFace::calcAlignedPlanarTE(const LLFace* align_to,  LLVector2* res_st_offset, 
-								 LLVector2* res_st_scale, F32* res_st_rot, LLRender::eTexIndex map) const
+bool LLFace::calcAlignedPlanarTE(const LLFace* align_to,  LLVector2* res_st_offset,
+                                 LLVector2* res_st_scale, F32* res_st_rot, LLRender::eTexIndex map) const
 {
-	if (!align_to)
-	{
-		return false;
-	}
-	const LLTextureEntry *orig_tep = align_to->getTextureEntry();
-	if ((orig_tep->getTexGen() != LLTextureEntry::TEX_GEN_PLANAR) ||
-		(getTextureEntry()->getTexGen() != LLTextureEntry::TEX_GEN_PLANAR))
-	{
-		return false;
-	}
+    if (!align_to)
+    {
+        return false;
+    }
+    const LLTextureEntry *orig_tep = align_to->getTextureEntry();
+    if ((orig_tep->getTexGen() != LLTextureEntry::TEX_GEN_PLANAR) ||
+        (getTextureEntry()->getTexGen() != LLTextureEntry::TEX_GEN_PLANAR))
+    {
+        return false;
+    }
 
     F32 map_rot = 0.f, map_scaleS = 0.f, map_scaleT = 0.f, map_offsS = 0.f, map_offsT = 0.f;
 
@@ -1069,55 +1069,55 @@ bool LLFace::calcAlignedPlanarTE(const LLFace* align_to,  LLVector2* res_st_offs
         break;
     }
 
-	LLVector3 orig_pos, this_pos;
-	LLQuaternion orig_face_rot, this_face_rot;
-	F32 orig_proj_scale, this_proj_scale;
-	align_to->getPlanarProjectedParams(&orig_face_rot, &orig_pos, &orig_proj_scale);
-	getPlanarProjectedParams(&this_face_rot, &this_pos, &this_proj_scale);
-
-	// The rotation of "this face's" texture:
-	LLQuaternion orig_st_rot = LLQuaternion(map_rot, LLVector3::z_axis) * orig_face_rot;
-	LLQuaternion this_st_rot = orig_st_rot * ~this_face_rot;
-	F32 x_ang, y_ang, z_ang;
-	this_st_rot.getEulerAngles(&x_ang, &y_ang, &z_ang);
-	*res_st_rot = z_ang;
-
-	// Offset and scale of "this face's" texture:
-	LLVector3 centers_dist = (this_pos - orig_pos) * ~orig_st_rot;
-	LLVector3 st_scale(map_scaleS, map_scaleT, 1.f);
-	st_scale *= orig_proj_scale;
-	centers_dist.scaleVec(st_scale);
-	LLVector2 orig_st_offset(map_offsS, map_offsT);
-
-	*res_st_offset = orig_st_offset + (LLVector2)centers_dist;
-	res_st_offset->mV[VX] -= (S32)res_st_offset->mV[VX];
-	res_st_offset->mV[VY] -= (S32)res_st_offset->mV[VY];
-
-	st_scale /= this_proj_scale;
-	*res_st_scale = (LLVector2)st_scale;
-	return true;
+    LLVector3 orig_pos, this_pos;
+    LLQuaternion orig_face_rot, this_face_rot;
+    F32 orig_proj_scale, this_proj_scale;
+    align_to->getPlanarProjectedParams(&orig_face_rot, &orig_pos, &orig_proj_scale);
+    getPlanarProjectedParams(&this_face_rot, &this_pos, &this_proj_scale);
+
+    // The rotation of "this face's" texture:
+    LLQuaternion orig_st_rot = LLQuaternion(map_rot, LLVector3::z_axis) * orig_face_rot;
+    LLQuaternion this_st_rot = orig_st_rot * ~this_face_rot;
+    F32 x_ang, y_ang, z_ang;
+    this_st_rot.getEulerAngles(&x_ang, &y_ang, &z_ang);
+    *res_st_rot = z_ang;
+
+    // Offset and scale of "this face's" texture:
+    LLVector3 centers_dist = (this_pos - orig_pos) * ~orig_st_rot;
+    LLVector3 st_scale(map_scaleS, map_scaleT, 1.f);
+    st_scale *= orig_proj_scale;
+    centers_dist.scaleVec(st_scale);
+    LLVector2 orig_st_offset(map_offsS, map_offsT);
+
+    *res_st_offset = orig_st_offset + (LLVector2)centers_dist;
+    res_st_offset->mV[VX] -= (S32)res_st_offset->mV[VX];
+    res_st_offset->mV[VY] -= (S32)res_st_offset->mV[VY];
+
+    st_scale /= this_proj_scale;
+    *res_st_scale = (LLVector2)st_scale;
+    return true;
 }
 
 void LLFace::updateRebuildFlags()
 {
-	if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME))
-	{ //this rebuild is zero overhead (direct consequence of some change that affects this face)
-		mLastUpdateTime = gFrameTimeSeconds;
-	}
-	else
-	{ //this rebuild is overhead (side effect of some change that does not affect this face)
-		mLastMoveTime = gFrameTimeSeconds;
-	}
+    if (mDrawablep->isState(LLDrawable::REBUILD_VOLUME))
+    { //this rebuild is zero overhead (direct consequence of some change that affects this face)
+        mLastUpdateTime = gFrameTimeSeconds;
+    }
+    else
+    { //this rebuild is overhead (side effect of some change that does not affect this face)
+        mLastMoveTime = gFrameTimeSeconds;
+    }
 }
 
 
 bool LLFace::canRenderAsMask()
 {
-	const LLTextureEntry* te = getTextureEntry();
-	if( !te || !getViewerObject() || !getTexture() )
-	{
-		return false;
-	}
+    const LLTextureEntry* te = getTextureEntry();
+    if( !te || !getViewerObject() || !getTexture() )
+    {
+        return false;
+    }
 
     if (te->getGLTFRenderMaterial())
     {
@@ -1134,31 +1134,31 @@ bool LLFace::canRenderAsMask()
         return false;
     }
 
-	
-	LLMaterial* mat = te->getMaterialParams();
-	if (mat && mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND)
-	{
-		return false;
-	}
-
-	static const LLCachedControl<bool> use_rmse_auto_mask(gSavedSettings, "RenderAutoMaskAlphaUseRMSE", true);
-	static const LLCachedControl<F32> auto_mask_max_rmse(gSavedSettings, "RenderAutoMaskAlphaMaxRMSE", 0.18f);
-	static const LLCachedControl<F32> auto_mask_max_mid(gSavedSettings, "RenderAutoMaskAlphaMaxMid", 0.25f);
-	if ((te->getColor().mV[3] == 1.0f) && // can't treat as mask if we have face alpha
-		(te->getGlow() == 0.f) && // glowing masks are hard to implement - don't mask
-		(getTexture()->getIsAlphaMask((!getViewerObject()->isAttachment() && use_rmse_auto_mask) ? auto_mask_max_rmse : -1.f, auto_mask_max_mid))) // texture actually qualifies for masking (lazily recalculated but expensive)
-	{
-		if (getViewerObject()->isHUDAttachment() || te->getFullbright())
-		{ //hud attachments and fullbright objects are NOT subject to the deferred rendering pipe
-			return LLPipeline::sAutoMaskAlphaNonDeferred;
-		}
-		else
-		{
-			return LLPipeline::sAutoMaskAlphaDeferred;
-		}
-	}
-
-	return false;
+
+    LLMaterial* mat = te->getMaterialParams();
+    if (mat && mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND)
+    {
+        return false;
+    }
+
+    static const LLCachedControl<bool> use_rmse_auto_mask(gSavedSettings, "RenderAutoMaskAlphaUseRMSE", true);
+    static const LLCachedControl<F32> auto_mask_max_rmse(gSavedSettings, "RenderAutoMaskAlphaMaxRMSE", 0.18f);
+    static const LLCachedControl<F32> auto_mask_max_mid(gSavedSettings, "RenderAutoMaskAlphaMaxMid", 0.25f);
+    if ((te->getColor().mV[3] == 1.0f) && // can't treat as mask if we have face alpha
+        (te->getGlow() == 0.f) && // glowing masks are hard to implement - don't mask
+        (getTexture()->getIsAlphaMask((!getViewerObject()->isAttachment() && use_rmse_auto_mask) ? auto_mask_max_rmse : -1.f, auto_mask_max_mid))) // texture actually qualifies for masking (lazily recalculated but expensive)
+    {
+        if (getViewerObject()->isHUDAttachment() || te->getFullbright())
+        { //hud attachments and fullbright objects are NOT subject to the deferred rendering pipe
+            return LLPipeline::sAutoMaskAlphaNonDeferred;
+        }
+        else
+        {
+            return LLPipeline::sAutoMaskAlphaDeferred;
+        }
+    }
+
+    return false;
 }
 
 BOOL LLFace::getGeometryVolume(const LLVolume& volume,
@@ -1170,7 +1170,7 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
                                 bool no_debug_assert)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE;
-	llassert(verify());
+    llassert(verify());
 
     if (face_index < 0 || face_index >= volume.getNumVolumeFaces())
     {
@@ -1188,163 +1188,163 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
     bool rigged = isState(RIGGED);
 
     const LLVolumeFace &vf = volume.getVolumeFace(face_index);
-	S32 num_vertices = (S32)vf.mNumVertices;
-	S32 num_indices = (S32) vf.mNumIndices;
-	
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCTREE))
-	{
-		updateRebuildFlags();
-	}
-
-	if (mVertexBuffer.notNull())
-	{
-		if (num_indices + (S32) mIndicesIndex > mVertexBuffer->getNumIndices())
-		{
-			if (gDebugGL)
-			{
-				LL_WARNS() << "Index buffer overflow!" << LL_ENDL;
-				LL_WARNS() << "Indices Count: " << mIndicesCount
-						<< " VF Num Indices: " << num_indices
-						<< " Indices Index: " << mIndicesIndex
-						<< " VB Num Indices: " << mVertexBuffer->getNumIndices() << LL_ENDL;
-				LL_WARNS()	<< " Face Index: " << face_index
-						<< " Pool Type: " << mPoolType << LL_ENDL;
-				llassert(no_debug_assert);
-			}
-			return FALSE;
-		}
-
-		if (num_vertices + mGeomIndex > mVertexBuffer->getNumVerts())
-		{
-			if (gDebugGL)
-			{
-				LL_WARNS() << "Vertex buffer overflow!" << LL_ENDL;
-				llassert(no_debug_assert);
-			}
-			return FALSE;
-		}
-	}
-
-	LLStrider<LLVector3> vert;
-	LLStrider<LLVector2> tex_coords0;
-	LLStrider<LLVector2> tex_coords1;
-	LLStrider<LLVector2> tex_coords2;
-	LLStrider<LLVector3> norm;
-	LLStrider<LLColor4U> colors;
-	LLStrider<LLVector3> tangent;
-	LLStrider<U16> indicesp;
-	LLStrider<LLVector4a> wght;
-
-	BOOL full_rebuild = force_rebuild || mDrawablep->isState(LLDrawable::REBUILD_VOLUME);
-	
-	BOOL global_volume = mDrawablep->getVOVolume()->isVolumeGlobal();
-	LLVector3 scale;
-	if (global_volume)
-	{
-		scale.setVec(1,1,1);
-	}
-	else
-	{
-		scale = mVObjp->getScale();
-	}
-	
-	bool rebuild_pos = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_POSITION);
-	bool rebuild_color = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_COLOR);
-	bool rebuild_emissive = rebuild_color && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE);
-	bool rebuild_tcoord = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_TCOORD);
-	bool rebuild_normal = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL);
-	bool rebuild_tangent = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TANGENT);
-	bool rebuild_weights = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_WEIGHT4);
-
-	const LLTextureEntry *tep = mVObjp->getTE(face_index);
-	const U8 bump_code = tep ? tep->getBumpmap() : 0;
-
-	BOOL is_static = mDrawablep->isStatic();
-	BOOL is_global = is_static;
-
-	LLVector3 center_sum(0.f, 0.f, 0.f);
-	
-	if (is_global)
-	{
-		setState(GLOBAL);
-	}
-	else
-	{
-		clearState(GLOBAL);
-	}
-
-	LLColor4U color = tep->getColor();
+    S32 num_vertices = (S32)vf.mNumVertices;
+    S32 num_indices = (S32) vf.mNumIndices;
+
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCTREE))
+    {
+        updateRebuildFlags();
+    }
+
+    if (mVertexBuffer.notNull())
+    {
+        if (num_indices + (S32) mIndicesIndex > mVertexBuffer->getNumIndices())
+        {
+            if (gDebugGL)
+            {
+                LL_WARNS() << "Index buffer overflow!" << LL_ENDL;
+                LL_WARNS() << "Indices Count: " << mIndicesCount
+                        << " VF Num Indices: " << num_indices
+                        << " Indices Index: " << mIndicesIndex
+                        << " VB Num Indices: " << mVertexBuffer->getNumIndices() << LL_ENDL;
+                LL_WARNS()  << " Face Index: " << face_index
+                        << " Pool Type: " << mPoolType << LL_ENDL;
+                llassert(no_debug_assert);
+            }
+            return FALSE;
+        }
+
+        if (num_vertices + mGeomIndex > mVertexBuffer->getNumVerts())
+        {
+            if (gDebugGL)
+            {
+                LL_WARNS() << "Vertex buffer overflow!" << LL_ENDL;
+                llassert(no_debug_assert);
+            }
+            return FALSE;
+        }
+    }
+
+    LLStrider<LLVector3> vert;
+    LLStrider<LLVector2> tex_coords0;
+    LLStrider<LLVector2> tex_coords1;
+    LLStrider<LLVector2> tex_coords2;
+    LLStrider<LLVector3> norm;
+    LLStrider<LLColor4U> colors;
+    LLStrider<LLVector3> tangent;
+    LLStrider<U16> indicesp;
+    LLStrider<LLVector4a> wght;
+
+    BOOL full_rebuild = force_rebuild || mDrawablep->isState(LLDrawable::REBUILD_VOLUME);
+
+    BOOL global_volume = mDrawablep->getVOVolume()->isVolumeGlobal();
+    LLVector3 scale;
+    if (global_volume)
+    {
+        scale.setVec(1,1,1);
+    }
+    else
+    {
+        scale = mVObjp->getScale();
+    }
+
+    bool rebuild_pos = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_POSITION);
+    bool rebuild_color = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_COLOR);
+    bool rebuild_emissive = rebuild_color && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_EMISSIVE);
+    bool rebuild_tcoord = full_rebuild || mDrawablep->isState(LLDrawable::REBUILD_TCOORD);
+    bool rebuild_normal = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL);
+    bool rebuild_tangent = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TANGENT);
+    bool rebuild_weights = rebuild_pos && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_WEIGHT4);
+
+    const LLTextureEntry *tep = mVObjp->getTE(face_index);
+    const U8 bump_code = tep ? tep->getBumpmap() : 0;
+
+    BOOL is_static = mDrawablep->isStatic();
+    BOOL is_global = is_static;
+
+    LLVector3 center_sum(0.f, 0.f, 0.f);
+
+    if (is_global)
+    {
+        setState(GLOBAL);
+    }
+    else
+    {
+        clearState(GLOBAL);
+    }
+
+    LLColor4U color = tep->getColor();
 
     if (tep->getGLTFRenderMaterial())
     {
         color = tep->getGLTFRenderMaterial()->mBaseColor;
     }
 
-	if (rebuild_color)
-	{ //decide if shiny goes in alpha channel of color
-		if (tep && 
-			!isInAlphaPool())  // <--- alpha channel MUST contain transparency, not shiny
-	{
-			LLMaterial* mat = tep->getMaterialParams().get();
-						
-			bool shiny_in_alpha = false;
-			
-			//store shiny in alpha if we don't have a specular map
-			if  (!mat || mat->getSpecularID().isNull())
-			{
-				shiny_in_alpha = true;
-			}
-
-			if (shiny_in_alpha)
-			{
-				static const GLfloat SHININESS_TO_ALPHA[4] =
-				{
-					0.0000f,
-					0.25f,
-					0.5f,
-					0.75f
-				};
-			
-				llassert(tep->getShiny() <= 3);
-				color.mV[3] = U8 (SHININESS_TO_ALPHA[tep->getShiny()] * 255);
-			}
-		}
-	}
-
-	// INDICES
-	if (full_rebuild)
-	{
+    if (rebuild_color)
+    { //decide if shiny goes in alpha channel of color
+        if (tep &&
+            !isInAlphaPool() && tep->getGLTFRenderMaterial() == nullptr)  // <--- alpha channel MUST contain transparency, not shiny
+    {
+            LLMaterial* mat = tep->getMaterialParams().get();
+
+            bool shiny_in_alpha = false;
+
+            //store shiny in alpha if we don't have a specular map
+            if  (!mat || mat->getSpecularID().isNull())
+            {
+                shiny_in_alpha = true;
+            }
+
+            if (shiny_in_alpha)
+            {
+                static const GLfloat SHININESS_TO_ALPHA[4] =
+                {
+                    0.0000f,
+                    0.25f,
+                    0.5f,
+                    0.75f
+                };
+
+                llassert(tep->getShiny() <= 3);
+                color.mV[3] = U8 (SHININESS_TO_ALPHA[tep->getShiny()] * 255);
+            }
+        }
+    }
+
+    // INDICES
+    if (full_rebuild)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - indices");
-		mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount);
+        mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount);
 
-		volatile __m128i* dst = (__m128i*) indicesp.get();
-		__m128i* src = (__m128i*) vf.mIndices;
-		__m128i offset = _mm_set1_epi16(index_offset);
+        volatile __m128i* dst = (__m128i*) indicesp.get();
+        __m128i* src = (__m128i*) vf.mIndices;
+        __m128i offset = _mm_set1_epi16(index_offset);
 
-		S32 end = num_indices/8;
-		
-		for (S32 i = 0; i < end; i++)
-		{
-			__m128i res = _mm_add_epi16(src[i], offset);
-			_mm_storeu_si128((__m128i*) dst++, res);
-		}
+        S32 end = num_indices/8;
+
+        for (S32 i = 0; i < end; i++)
+        {
+            __m128i res = _mm_add_epi16(src[i], offset);
+            _mm_storeu_si128((__m128i*) dst++, res);
+        }
 
-		{
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - indices tail");
-			U16* idx = (U16*) dst;
+            U16* idx = (U16*) dst;
+
+            for (S32 i = end*8; i < num_indices; ++i)
+            {
+                *idx++ = vf.mIndices[i]+index_offset;
+            }
+        }
+    }
 
-			for (S32 i = end*8; i < num_indices; ++i)
-			{
-				*idx++ = vf.mIndices[i]+index_offset;
-			}
-		}
-	}
-	
 
     LLMaterial* mat = tep->getMaterialParams().get();
     LLGLTFMaterial* gltf_mat = tep->getGLTFRenderMaterial();
 
-	F32 r = 0, os = 0, ot = 0, ms = 0, mt = 0, cos_ang = 0, sin_ang = 0;
+    F32 r = 0, os = 0, ot = 0, ms = 0, mt = 0, cos_ang = 0, sin_ang = 0;
 
     constexpr S32 XFORM_NONE = 0;
     constexpr S32 XFORM_BLINNPHONG_COLOR = 1;
@@ -1409,12 +1409,12 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
             }
         }
     }
-	
+
     const LLMeshSkinInfo* skin = nullptr;
     LLMatrix4a mat_vert;
-	LLMatrix4a mat_normal;
-	mat_vert.setIdentity();
-	mat_normal.setIdentity();
+    LLMatrix4a mat_normal;
+    mat_vert.setIdentity();
+    mat_normal.setIdentity();
 
     // prepare mat_vert
     if (rebuild_pos)
@@ -1441,9 +1441,9 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
             }
 
             //TODO -- cache this (check profile marker above)?
-			mat_normal = skin->mBindShapeMatrix;
-			mat_normal.invert();
-			mat_normal.transpose();
+            mat_normal = skin->mBindShapeMatrix;
+            mat_normal.invert();
+            mat_normal.transpose();
         }
         else
         {
@@ -1451,334 +1451,334 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
         }
     }
 
-	{
-		//if it's not fullbright and has no normals, bake sunlight based on face normal
-		//bool bake_sunlight = !getTextureEntry()->getFullbright() &&
-		//  !mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL);
+    {
+        //if it's not fullbright and has no normals, bake sunlight based on face normal
+        //bool bake_sunlight = !getTextureEntry()->getFullbright() &&
+        //  !mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_NORMAL);
 
-		if (rebuild_tcoord)
-		{
+        if (rebuild_tcoord)
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - tcoord");
-									
-			//bump setup
-			LLVector4a binormal_dir( -sin_ang, cos_ang, 0.f );
-			LLVector4a bump_s_primary_light_ray(0.f, 0.f, 0.f);
-			LLVector4a bump_t_primary_light_ray(0.f, 0.f, 0.f);
-
-			LLQuaternion bump_quat;
-			if (mDrawablep->isActive())
-			{
-				bump_quat = LLQuaternion(LLMatrix4(mDrawablep->getRenderMatrix()));
-			}
-		
-			if (bump_code)
-			{
-				mVObjp->getVolume()->genTangents(face_index);
-				F32 offset_multiple; 
-				switch( bump_code )
-				{
-					case BE_NO_BUMP:
-					offset_multiple = 0.f;
-					break;
-					case BE_BRIGHTNESS:
-					case BE_DARKNESS:
-					if( mTexture[LLRender::DIFFUSE_MAP].notNull() && mTexture[LLRender::DIFFUSE_MAP]->hasGLTexture())
-					{
-						// Offset by approximately one texel
-						S32 cur_discard = mTexture[LLRender::DIFFUSE_MAP]->getDiscardLevel();
-						S32 max_size = llmax( mTexture[LLRender::DIFFUSE_MAP]->getWidth(), mTexture[LLRender::DIFFUSE_MAP]->getHeight() );
-						max_size <<= cur_discard;
-						const F32 ARTIFICIAL_OFFSET = 2.f;
-						offset_multiple = ARTIFICIAL_OFFSET / (F32)max_size;
-					}
-					else
-					{
-						offset_multiple = 1.f/256;
-					}
-					break;
-
-					default:  // Standard bumpmap textures.  Assumed to be 256x256
-					offset_multiple = 1.f / 256;
-					break;
-				}
-
-				F32 s_scale = 1.f;
-				F32 t_scale = 1.f;
-				if( tep )
-				{
-					tep->getScale( &s_scale, &t_scale );
-				}
-				// Use the nudged south when coming from above sun angle, such
-				// that emboss mapping always shows up on the upward faces of cubes when 
-				// it's noon (since a lot of builders build with the sun forced to noon).
-				LLVector3   sun_ray  = gSky.mVOSkyp->mBumpSunDir;
-				LLVector3   moon_ray = gSky.mVOSkyp->getMoon().getDirection();
-				LLVector3& primary_light_ray = (sun_ray.mV[VZ] > 0) ? sun_ray : moon_ray;
-
-				bump_s_primary_light_ray.load3((offset_multiple * s_scale * primary_light_ray).mV);
-				bump_t_primary_light_ray.load3((offset_multiple * t_scale * primary_light_ray).mV);
-			}
-
-			U8 texgen = getTextureEntry() ? getTextureEntry()->getTexGen() : LLTextureEntry::TEX_GEN_DEFAULT;
-			if (rebuild_tcoord && texgen != LLTextureEntry::TEX_GEN_DEFAULT)
-			{ //planar texgen needs binormals
-				mVObjp->getVolume()->genTangents(face_index);
-			}
-
-			U8 tex_mode = 0;
-	
-			bool tex_anim = false;
-
-				LLVOVolume* vobj = (LLVOVolume*) (LLViewerObject*) mVObjp;	
-				tex_mode = vobj->mTexAnimMode;
-
-			if (vobj->mTextureAnimp)
-			{ //texture animation is in play, override specular and normal map tex coords with diffuse texcoords
-				tex_anim = true;
-			}
-
-			if (isState(TEXTURE_ANIM))
-			{
-				if (!tex_mode)
-				{
-					clearState(TEXTURE_ANIM);
-				}
-				else
-				{
-					os = ot = 0.f;
-					r = 0.f;
-					cos_ang = 1.f;
-					sin_ang = 0.f;
-					ms = mt = 1.f;
+
+            //bump setup
+            LLVector4a binormal_dir( -sin_ang, cos_ang, 0.f );
+            LLVector4a bump_s_primary_light_ray(0.f, 0.f, 0.f);
+            LLVector4a bump_t_primary_light_ray(0.f, 0.f, 0.f);
+
+            LLQuaternion bump_quat;
+            if (mDrawablep->isActive())
+            {
+                bump_quat = LLQuaternion(LLMatrix4(mDrawablep->getRenderMatrix()));
+            }
+
+            if (bump_code)
+            {
+                mVObjp->getVolume()->genTangents(face_index);
+                F32 offset_multiple;
+                switch( bump_code )
+                {
+                    case BE_NO_BUMP:
+                    offset_multiple = 0.f;
+                    break;
+                    case BE_BRIGHTNESS:
+                    case BE_DARKNESS:
+                    if( mTexture[LLRender::DIFFUSE_MAP].notNull() && mTexture[LLRender::DIFFUSE_MAP]->hasGLTexture())
+                    {
+                        // Offset by approximately one texel
+                        S32 cur_discard = mTexture[LLRender::DIFFUSE_MAP]->getDiscardLevel();
+                        S32 max_size = llmax( mTexture[LLRender::DIFFUSE_MAP]->getWidth(), mTexture[LLRender::DIFFUSE_MAP]->getHeight() );
+                        max_size <<= cur_discard;
+                        const F32 ARTIFICIAL_OFFSET = 2.f;
+                        offset_multiple = ARTIFICIAL_OFFSET / (F32)max_size;
+                    }
+                    else
+                    {
+                        offset_multiple = 1.f/256;
+                    }
+                    break;
+
+                    default:  // Standard bumpmap textures.  Assumed to be 256x256
+                    offset_multiple = 1.f / 256;
+                    break;
+                }
+
+                F32 s_scale = 1.f;
+                F32 t_scale = 1.f;
+                if( tep )
+                {
+                    tep->getScale( &s_scale, &t_scale );
+                }
+                // Use the nudged south when coming from above sun angle, such
+                // that emboss mapping always shows up on the upward faces of cubes when
+                // it's noon (since a lot of builders build with the sun forced to noon).
+                LLVector3   sun_ray  = gSky.mVOSkyp->mBumpSunDir;
+                LLVector3   moon_ray = gSky.mVOSkyp->getMoon().getDirection();
+                LLVector3& primary_light_ray = (sun_ray.mV[VZ] > 0) ? sun_ray : moon_ray;
+
+                bump_s_primary_light_ray.load3((offset_multiple * s_scale * primary_light_ray).mV);
+                bump_t_primary_light_ray.load3((offset_multiple * t_scale * primary_light_ray).mV);
+            }
+
+            U8 texgen = getTextureEntry() ? getTextureEntry()->getTexGen() : LLTextureEntry::TEX_GEN_DEFAULT;
+            if (rebuild_tcoord && texgen != LLTextureEntry::TEX_GEN_DEFAULT)
+            { //planar texgen needs binormals
+                mVObjp->getVolume()->genTangents(face_index);
+            }
+
+            U8 tex_mode = 0;
+
+            bool tex_anim = false;
+
+                LLVOVolume* vobj = (LLVOVolume*) (LLViewerObject*) mVObjp;
+                tex_mode = vobj->mTexAnimMode;
+
+            if (vobj->mTextureAnimp)
+            { //texture animation is in play, override specular and normal map tex coords with diffuse texcoords
+                tex_anim = true;
+            }
+
+            if (isState(TEXTURE_ANIM))
+            {
+                if (!tex_mode)
+                {
+                    clearState(TEXTURE_ANIM);
+                }
+                else
+                {
+                    os = ot = 0.f;
+                    r = 0.f;
+                    cos_ang = 1.f;
+                    sin_ang = 0.f;
+                    ms = mt = 1.f;
 
                     xforms = XFORM_NONE;
-				}
+                }
 
-				if (getVirtualSize() >= MIN_TEX_ANIM_SIZE) // || isState(LLFace::RIGGED))
-				{ //don't override texture transform during tc bake
-					tex_mode = 0;
-				}
-			}
+                if (getVirtualSize() >= MIN_TEX_ANIM_SIZE) // || isState(LLFace::RIGGED))
+                { //don't override texture transform during tc bake
+                    tex_mode = 0;
+                }
+            }
 
-			LLVector4a scalea;
-			scalea.load3(scale.mV);
+            LLVector4a scalea;
+            scalea.load3(scale.mV);
 
-			bool do_bump = bump_code && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1);
+            bool do_bump = bump_code && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1);
+
+            if ((mat || gltf_mat) && !do_bump)
+            {
+                do_bump  = mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1)
+                         || mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD2);
+            }
 
-			if ((mat || gltf_mat) && !do_bump)
-			{
-				do_bump  = mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1)
-					     || mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD2);
-			}
-			
             // For GLTF materials: Transforms will be applied later
-			bool do_tex_mat = tex_mode && mTextureMatrix && !gltf_mat;
+            bool do_tex_mat = tex_mode && mTextureMatrix && !gltf_mat;
 
-			if (!do_bump)
-			{ //not bump mapped, might be able to do a cheap update
-				mVertexBuffer->getTexCoord0Strider(tex_coords0, mGeomIndex, mGeomCount);
+            if (!do_bump)
+            { //not bump mapped, might be able to do a cheap update
+                mVertexBuffer->getTexCoord0Strider(tex_coords0, mGeomIndex, mGeomCount);
 
-				if (texgen != LLTextureEntry::TEX_GEN_PLANAR)
-				{
+                if (texgen != LLTextureEntry::TEX_GEN_PLANAR)
+                {
                     LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - texgen");
-					if (!do_tex_mat)
-					{
-						if (xforms == XFORM_NONE)
-						{
+                    if (!do_tex_mat)
+                    {
+                        if (xforms == XFORM_NONE)
+                        {
                             LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("ggv - texgen 1");
-							S32 tc_size = (num_vertices*2*sizeof(F32)+0xF) & ~0xF;
-							LLVector4a::memcpyNonAliased16((F32*) tex_coords0.get(), (F32*) vf.mTexCoords, tc_size);
-						}
-						else
-						{
+                            S32 tc_size = (num_vertices*2*sizeof(F32)+0xF) & ~0xF;
+                            LLVector4a::memcpyNonAliased16((F32*) tex_coords0.get(), (F32*) vf.mTexCoords, tc_size);
+                        }
+                        else
+                        {
                             LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("ggv - texgen 2");
-							F32* dst = (F32*) tex_coords0.get();
-							LLVector4a* src = (LLVector4a*) vf.mTexCoords;
-
-							LLVector4a trans;
-							trans.splat(-0.5f);
-
-							LLVector4a rot0;
-							rot0.set(cos_ang, -sin_ang, cos_ang, -sin_ang);
-
-							LLVector4a rot1;
-							rot1.set(sin_ang, cos_ang, sin_ang, cos_ang);
-
-							LLVector4a scale;
-							scale.set(ms, mt, ms, mt);
-
-							LLVector4a offset;
-							offset.set(os+0.5f, ot+0.5f, os+0.5f, ot+0.5f);
-
-							LLVector4Logical mask;
-							mask.clear();
-							mask.setElement<2>();
-							mask.setElement<3>();
-
-							U32 count = num_vertices/2 + num_vertices%2;
-
-							for (S32 i = 0; i < count; i++)
-							{	
-								LLVector4a res = *src++;
-								xform4a(res, trans, mask, rot0, rot1, offset, scale);
-								res.store4a(dst);
-								dst += 4;
-							}
-						}
-					}
-					else
-					{ //do tex mat, no texgen, no bump
-						for (S32 i = 0; i < num_vertices; i++)
-						{
-							LLVector4a tc(vf.mTexCoords[i].mV[VX],vf.mTexCoords[i].mV[VY],0.f);
-							mTextureMatrix->affineTransform(tc,tc);
-							(tex_coords0++)->set(tc.getF32ptr());
-						}
-					}
-				}
-				else
-				{ //no bump, tex gen planar
+                            F32* dst = (F32*) tex_coords0.get();
+                            LLVector4a* src = (LLVector4a*) vf.mTexCoords;
+
+                            LLVector4a trans;
+                            trans.splat(-0.5f);
+
+                            LLVector4a rot0;
+                            rot0.set(cos_ang, -sin_ang, cos_ang, -sin_ang);
+
+                            LLVector4a rot1;
+                            rot1.set(sin_ang, cos_ang, sin_ang, cos_ang);
+
+                            LLVector4a scale;
+                            scale.set(ms, mt, ms, mt);
+
+                            LLVector4a offset;
+                            offset.set(os+0.5f, ot+0.5f, os+0.5f, ot+0.5f);
+
+                            LLVector4Logical mask;
+                            mask.clear();
+                            mask.setElement<2>();
+                            mask.setElement<3>();
+
+                            U32 count = num_vertices/2 + num_vertices%2;
+
+                            for (S32 i = 0; i < count; i++)
+                            {
+                                LLVector4a res = *src++;
+                                xform4a(res, trans, mask, rot0, rot1, offset, scale);
+                                res.store4a(dst);
+                                dst += 4;
+                            }
+                        }
+                    }
+                    else
+                    { //do tex mat, no texgen, no bump
+                        for (S32 i = 0; i < num_vertices; i++)
+                        {
+                            LLVector4a tc(vf.mTexCoords[i].mV[VX],vf.mTexCoords[i].mV[VY],0.f);
+                            mTextureMatrix->affineTransform(tc,tc);
+                            (tex_coords0++)->set(tc.getF32ptr());
+                        }
+                    }
+                }
+                else
+                { //no bump, tex gen planar
                     LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - texgen planar");
-					if (do_tex_mat)
-					{
-						for (S32 i = 0; i < num_vertices; i++)
-						{	
-							LLVector2 tc(vf.mTexCoords[i]);
-							const LLVector4a& norm = vf.mNormals[i];
-							const LLVector4a& center = *(vf.mCenter);
-							LLVector4a vec = vf.mPositions[i];	
-							vec.mul(scalea);
-							planarProjection(tc, norm, center, vec);
-						
-							LLVector4a tmp(tc.mV[VX],tc.mV[VY],0.f);
-							mTextureMatrix->affineTransform(tmp,tmp);
-							(tex_coords0++)->set(tmp.getF32ptr());
-						}
-					}
-					else if (xforms != XFORM_NONE)
-					{
-						for (S32 i = 0; i < num_vertices; i++)
-						{	
-							LLVector2 tc(vf.mTexCoords[i]);
-							const LLVector4a& norm = vf.mNormals[i];
-							const LLVector4a& center = *(vf.mCenter);
-							LLVector4a vec = vf.mPositions[i];	
-							vec.mul(scalea);
-							planarProjection(tc, norm, center, vec);
-						
-							xform(tc, cos_ang, sin_ang, os, ot, ms, mt);
-
-							*tex_coords0++ = tc;	
-						}
-					}
-					else
-					{
-						for (S32 i = 0; i < num_vertices; i++)
-						{	
-							LLVector2 tc(vf.mTexCoords[i]);
-							LLVector4a& norm = vf.mNormals[i];
-							LLVector4a& center = *(vf.mCenter);
-							LLVector4a vec = vf.mPositions[i];	
-							vec.mul(scalea);
-							planarProjection(tc, norm, center, vec);
-
-							*tex_coords0++ = tc;	
-						}
-					}
-				}
-			}
-			else
-			{ //bump mapped or has material, just do the whole expensive loop
+                    if (do_tex_mat)
+                    {
+                        for (S32 i = 0; i < num_vertices; i++)
+                        {
+                            LLVector2 tc(vf.mTexCoords[i]);
+                            const LLVector4a& norm = vf.mNormals[i];
+                            const LLVector4a& center = *(vf.mCenter);
+                            LLVector4a vec = vf.mPositions[i];
+                            vec.mul(scalea);
+                            planarProjection(tc, norm, center, vec);
+
+                            LLVector4a tmp(tc.mV[VX],tc.mV[VY],0.f);
+                            mTextureMatrix->affineTransform(tmp,tmp);
+                            (tex_coords0++)->set(tmp.getF32ptr());
+                        }
+                    }
+                    else if (xforms != XFORM_NONE)
+                    {
+                        for (S32 i = 0; i < num_vertices; i++)
+                        {
+                            LLVector2 tc(vf.mTexCoords[i]);
+                            const LLVector4a& norm = vf.mNormals[i];
+                            const LLVector4a& center = *(vf.mCenter);
+                            LLVector4a vec = vf.mPositions[i];
+                            vec.mul(scalea);
+                            planarProjection(tc, norm, center, vec);
+
+                            xform(tc, cos_ang, sin_ang, os, ot, ms, mt);
+
+                            *tex_coords0++ = tc;
+                        }
+                    }
+                    else
+                    {
+                        for (S32 i = 0; i < num_vertices; i++)
+                        {
+                            LLVector2 tc(vf.mTexCoords[i]);
+                            LLVector4a& norm = vf.mNormals[i];
+                            LLVector4a& center = *(vf.mCenter);
+                            LLVector4a vec = vf.mPositions[i];
+                            vec.mul(scalea);
+                            planarProjection(tc, norm, center, vec);
+
+                            *tex_coords0++ = tc;
+                        }
+                    }
+                }
+            }
+            else
+            { //bump mapped or has material, just do the whole expensive loop
                 LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - texgen default");
 
-				std::vector<LLVector2> bump_tc;
-		
-				if (mat && !mat->getNormalID().isNull())
-				{ //writing out normal and specular texture coordinates, not bump offsets
-					do_bump = false;
-				}
+                std::vector<LLVector2> bump_tc;
+
+                if (mat && !mat->getNormalID().isNull())
+                { //writing out normal and specular texture coordinates, not bump offsets
+                    do_bump = false;
+                }
 
-				LLStrider<LLVector2> dst;
+                LLStrider<LLVector2> dst;
 
-				for (U32 ch = 0; ch < 3; ++ch)
-				{
+                for (U32 ch = 0; ch < 3; ++ch)
+                {
                     S32 xform_channel = XFORM_NONE;
-					switch (ch)
-					{
-						case 0: 
+                    switch (ch)
+                    {
+                        case 0:
                             xform_channel = XFORM_BLINNPHONG_COLOR;
-							mVertexBuffer->getTexCoord0Strider(dst, mGeomIndex, mGeomCount); 
-							break;
-						case 1:
+                            mVertexBuffer->getTexCoord0Strider(dst, mGeomIndex, mGeomCount);
+                            break;
+                        case 1:
                             xform_channel = XFORM_BLINNPHONG_NORMAL;
-							if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1))
-							{
-								mVertexBuffer->getTexCoord1Strider(dst, mGeomIndex, mGeomCount);
-								if (mat && !tex_anim)
-								{
-									r  = mat->getNormalRotation();
-									mat->getNormalOffset(os, ot);
-									mat->getNormalRepeat(ms, mt);
-
-									cos_ang = cos(r);
-									sin_ang = sin(r);
-
-								}
-							}
-							else
-							{
-								continue;
-							}
-							break;
-						case 2:
+                            if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD1))
+                            {
+                                mVertexBuffer->getTexCoord1Strider(dst, mGeomIndex, mGeomCount);
+                                if (mat && !tex_anim)
+                                {
+                                    r  = mat->getNormalRotation();
+                                    mat->getNormalOffset(os, ot);
+                                    mat->getNormalRepeat(ms, mt);
+
+                                    cos_ang = cos(r);
+                                    sin_ang = sin(r);
+
+                                }
+                            }
+                            else
+                            {
+                                continue;
+                            }
+                            break;
+                        case 2:
                             xform_channel = XFORM_BLINNPHONG_SPECULAR;
-							if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD2))
-							{
-								mVertexBuffer->getTexCoord2Strider(dst, mGeomIndex, mGeomCount);
-								if (mat && !tex_anim)
-								{
-									r  = mat->getSpecularRotation();
-									mat->getSpecularOffset(os, ot);
-									mat->getSpecularRepeat(ms, mt);
-
-									cos_ang = cos(r);
-									sin_ang = sin(r);
-								}
-							}
-							else
-							{
-								continue;
-							}
-							break;
-					}
+                            if (mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_TEXCOORD2))
+                            {
+                                mVertexBuffer->getTexCoord2Strider(dst, mGeomIndex, mGeomCount);
+                                if (mat && !tex_anim)
+                                {
+                                    r  = mat->getSpecularRotation();
+                                    mat->getSpecularOffset(os, ot);
+                                    mat->getSpecularRepeat(ms, mt);
+
+                                    cos_ang = cos(r);
+                                    sin_ang = sin(r);
+                                }
+                            }
+                            else
+                            {
+                                continue;
+                            }
+                            break;
+                    }
                     const bool do_xform = (xforms & xform_channel) != XFORM_NONE;
-					
+
 
                     for (S32 i = 0; i < num_vertices; i++)
-                    {   
+                    {
                         LLVector2 tc(vf.mTexCoords[i]);
-                
+
                         LLVector4a& norm = vf.mNormals[i];
-                    
+
                         LLVector4a& center = *(vf.mCenter);
-               
+
                         if (texgen != LLTextureEntry::TEX_GEN_DEFAULT)
                         {
                             LLVector4a vec = vf.mPositions[i];
-                    
+
                             vec.mul(scalea);
 
                             if (texgen == LLTextureEntry::TEX_GEN_PLANAR)
                             {
                                 planarProjection(tc, norm, center, vec);
-                            }       
+                            }
                         }
 
                         if (tex_mode && mTextureMatrix)
                         {
-							LLVector4a tmp(tc.mV[VX],tc.mV[VY],0.f);
-							mTextureMatrix->affineTransform(tmp,tmp);
-							tc.set(tmp.getF32ptr());
+                            LLVector4a tmp(tc.mV[VX],tc.mV[VY],0.f);
+                            mTextureMatrix->affineTransform(tmp,tmp);
+                            tc.set(tmp.getF32ptr());
                         }
                         else if (do_xform)
                         {
@@ -1791,239 +1791,239 @@ BOOL LLFace::getGeometryVolume(const LLVolume& volume,
                             bump_tc.push_back(tc);
                         }
                     }
-				}
+                }
+
+                if ((!mat && !gltf_mat) && do_bump)
+                {
+                    mVertexBuffer->getTexCoord1Strider(tex_coords1, mGeomIndex, mGeomCount);
 
-				if ((!mat && !gltf_mat) && do_bump)
-				{
-					mVertexBuffer->getTexCoord1Strider(tex_coords1, mGeomIndex, mGeomCount);
-		
                     mVObjp->getVolume()->genTangents(face_index);
 
-					for (S32 i = 0; i < num_vertices; i++)
-					{
-						LLVector4a tangent = vf.mTangents[i];
-
-						LLVector4a binorm;
-						binorm.setCross3(vf.mNormals[i], tangent);
-						binorm.mul(tangent.getF32ptr()[3]);
-
-						LLMatrix4a tangent_to_object;
-						tangent_to_object.setRows(tangent, binorm, vf.mNormals[i]);
-						LLVector4a t;
-						tangent_to_object.rotate(binormal_dir, t);
-						LLVector4a binormal;
-						mat_normal.rotate(t, binormal);
-						
-						//VECTORIZE THIS
-						if (mDrawablep->isActive())
-						{
-							LLVector3 t;
-							t.set(binormal.getF32ptr());
-							t *= bump_quat;
-							binormal.load3(t.mV);
-						}
-
-						binormal.normalize3fast();
-
-						LLVector2 tc = bump_tc[i];
-						tc += LLVector2( bump_s_primary_light_ray.dot3(tangent).getF32(), bump_t_primary_light_ray.dot3(binormal).getF32() );
-					
-						*tex_coords1++ = tc;
-					}
-				}
-			}
-		}
-
-		if (rebuild_pos)
-		{
-			LLVector4a* src = vf.mPositions;
-			
-			//_mm_prefetch((char*)src, _MM_HINT_T0);
-
-			LLVector4a* end = src+num_vertices;
-			//LLVector4a* end_64 = end-4;
-
-			llassert(num_vertices > 0);
-		
-			mVertexBuffer->getVertexStrider(vert, mGeomIndex, mGeomCount);
-			
-			
-			F32* dst = (F32*) vert.get();
-			F32* end_f32 = dst+mGeomCount*4;
-
-			//_mm_prefetch((char*)dst, _MM_HINT_NTA);
-			//_mm_prefetch((char*)src, _MM_HINT_NTA);
-				
-			//_mm_prefetch((char*)dst, _MM_HINT_NTA);
-
-
-			LLVector4a res0; //,res1,res2,res3;
-			res0.clear();
-
-			LLVector4a texIdx;
-
-			S32 index = mTextureIndex < FACE_DO_NOT_BATCH_TEXTURES ? mTextureIndex : 0;
-
-			F32 val = 0.f;
-			S32* vp = (S32*) &val;
-			*vp = index;
-			
-			llassert(index < LLGLSLShader::sIndexedTextureChannels);
-
-			LLVector4Logical mask;
-			mask.clear();
-			mask.setElement<3>();
-		
-			texIdx.set(0,0,0,val);
-
-			LLVector4a tmp;
-
-			
-			while (src < end)
-			{	
-				mat_vert.affineTransform(*src++, res0);
-				tmp.setSelectWithMask(mask, texIdx, res0);
-				tmp.store4a((F32*) dst);
-				dst += 4;
-			}
-			
-			while (dst < end_f32)
-			{
-				res0.store4a((F32*) dst);
-				dst += 4;
-			}
-		}
-
-		if (rebuild_normal)
-		{
+                    for (S32 i = 0; i < num_vertices; i++)
+                    {
+                        LLVector4a tangent = vf.mTangents[i];
+
+                        LLVector4a binorm;
+                        binorm.setCross3(vf.mNormals[i], tangent);
+                        binorm.mul(tangent.getF32ptr()[3]);
+
+                        LLMatrix4a tangent_to_object;
+                        tangent_to_object.setRows(tangent, binorm, vf.mNormals[i]);
+                        LLVector4a t;
+                        tangent_to_object.rotate(binormal_dir, t);
+                        LLVector4a binormal;
+                        mat_normal.rotate(t, binormal);
+
+                        //VECTORIZE THIS
+                        if (mDrawablep->isActive())
+                        {
+                            LLVector3 t;
+                            t.set(binormal.getF32ptr());
+                            t *= bump_quat;
+                            binormal.load3(t.mV);
+                        }
+
+                        binormal.normalize3fast();
+
+                        LLVector2 tc = bump_tc[i];
+                        tc += LLVector2( bump_s_primary_light_ray.dot3(tangent).getF32(), bump_t_primary_light_ray.dot3(binormal).getF32() );
+
+                        *tex_coords1++ = tc;
+                    }
+                }
+            }
+        }
+
+        if (rebuild_pos)
+        {
+            LLVector4a* src = vf.mPositions;
+
+            //_mm_prefetch((char*)src, _MM_HINT_T0);
+
+            LLVector4a* end = src+num_vertices;
+            //LLVector4a* end_64 = end-4;
+
+            llassert(num_vertices > 0);
+
+            mVertexBuffer->getVertexStrider(vert, mGeomIndex, mGeomCount);
+
+
+            F32* dst = (F32*) vert.get();
+            F32* end_f32 = dst+mGeomCount*4;
+
+            //_mm_prefetch((char*)dst, _MM_HINT_NTA);
+            //_mm_prefetch((char*)src, _MM_HINT_NTA);
+
+            //_mm_prefetch((char*)dst, _MM_HINT_NTA);
+
+
+            LLVector4a res0; //,res1,res2,res3;
+            res0.clear();
+
+            LLVector4a texIdx;
+
+            S32 index = mTextureIndex < FACE_DO_NOT_BATCH_TEXTURES ? mTextureIndex : 0;
+
+            F32 val = 0.f;
+            S32* vp = (S32*) &val;
+            *vp = index;
+
+            llassert(index < LLGLSLShader::sIndexedTextureChannels);
+
+            LLVector4Logical mask;
+            mask.clear();
+            mask.setElement<3>();
+
+            texIdx.set(0,0,0,val);
+
+            LLVector4a tmp;
+
+
+            while (src < end)
+            {
+                mat_vert.affineTransform(*src++, res0);
+                tmp.setSelectWithMask(mask, texIdx, res0);
+                tmp.store4a((F32*) dst);
+                dst += 4;
+            }
+
+            while (dst < end_f32)
+            {
+                res0.store4a((F32*) dst);
+                dst += 4;
+            }
+        }
+
+        if (rebuild_normal)
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - normal");
 
-			mVertexBuffer->getNormalStrider(norm, mGeomIndex, mGeomCount);
-			F32* normals = (F32*) norm.get();
-			LLVector4a* src = vf.mNormals;
-			LLVector4a* end = src+num_vertices;
-
-			while (src < end)
-			{	
-				LLVector4a normal;
-				mat_normal.rotate(*src++, normal);
-				normal.store4a(normals);
-				normals += 4;
-			}
-		}
-		
-		if (rebuild_tangent)
-		{
+            mVertexBuffer->getNormalStrider(norm, mGeomIndex, mGeomCount);
+            F32* normals = (F32*) norm.get();
+            LLVector4a* src = vf.mNormals;
+            LLVector4a* end = src+num_vertices;
+
+            while (src < end)
+            {
+                LLVector4a normal;
+                mat_normal.rotate(*src++, normal);
+                normal.store4a(normals);
+                normals += 4;
+            }
+        }
+
+        if (rebuild_tangent)
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - tangent");
-			mVertexBuffer->getTangentStrider(tangent, mGeomIndex, mGeomCount);
-			F32* tangents = (F32*) tangent.get();
-			
+            mVertexBuffer->getTangentStrider(tangent, mGeomIndex, mGeomCount);
+            F32* tangents = (F32*) tangent.get();
+
             mVObjp->getVolume()->genTangents(face_index);
-			
-			LLVector4Logical mask;
-			mask.clear();
-			mask.setElement<3>();
-
-			LLVector4a* src = vf.mTangents;
-			LLVector4a* end = vf.mTangents +num_vertices;
-
-			while (src < end)
-			{
-				LLVector4a tangent_out;
-				mat_normal.rotate(*src, tangent_out);
-				tangent_out.setSelectWithMask(mask, *src, tangent_out);
-				tangent_out.store4a(tangents);
-				
-				src++;
-				tangents += 4;
-			}
-		}
-	
-		if (rebuild_weights && vf.mWeights)
-		{
+
+            LLVector4Logical mask;
+            mask.clear();
+            mask.setElement<3>();
+
+            LLVector4a* src = vf.mTangents;
+            LLVector4a* end = vf.mTangents +num_vertices;
+
+            while (src < end)
+            {
+                LLVector4a tangent_out;
+                mat_normal.rotate(*src, tangent_out);
+                tangent_out.setSelectWithMask(mask, *src, tangent_out);
+                tangent_out.store4a(tangents);
+
+                src++;
+                tangents += 4;
+            }
+        }
+
+        if (rebuild_weights && vf.mWeights)
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - weight");
-			mVertexBuffer->getWeight4Strider(wght, mGeomIndex, mGeomCount);
-			wght.copyArray(0, vf.mWeights, num_vertices);
-		}
+            mVertexBuffer->getWeight4Strider(wght, mGeomIndex, mGeomCount);
+            wght.copyArray(0, vf.mWeights, num_vertices);
+        }
 
-		if (rebuild_color && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_COLOR) )
-		{
+        if (rebuild_color && mVertexBuffer->hasDataType(LLVertexBuffer::TYPE_COLOR) )
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - color");
-			mVertexBuffer->getColorStrider(colors, mGeomIndex, mGeomCount);
-
-			LLVector4a src;
-
-			U32 vec[4];
-			vec[0] = vec[1] = vec[2] = vec[3] = color.asRGBA();
-		
-			src.loadua((F32*) vec);
-
-			F32* dst = (F32*) colors.get();
-			S32 num_vecs = num_vertices/4;
-			if (num_vertices%4 > 0)
-			{
-				++num_vecs;
-			}
-
-			for (S32 i = 0; i < num_vecs; i++)
-			{	
-				src.store4a(dst);
-				dst += 4;
-			}
-		}
-
-		if (rebuild_emissive)
-		{
+            mVertexBuffer->getColorStrider(colors, mGeomIndex, mGeomCount);
+
+            LLVector4a src;
+
+            U32 vec[4];
+            vec[0] = vec[1] = vec[2] = vec[3] = color.asRGBA();
+
+            src.loadua((F32*) vec);
+
+            F32* dst = (F32*) colors.get();
+            S32 num_vecs = num_vertices/4;
+            if (num_vertices%4 > 0)
+            {
+                ++num_vecs;
+            }
+
+            for (S32 i = 0; i < num_vecs; i++)
+            {
+                src.store4a(dst);
+                dst += 4;
+            }
+        }
+
+        if (rebuild_emissive)
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_FACE("getGeometryVolume - emissive");
-			LLStrider<LLColor4U> emissive;
-			mVertexBuffer->getEmissiveStrider(emissive, mGeomIndex, mGeomCount);
-
-			U8 glow = (U8) llclamp((S32) (getTextureEntry()->getGlow()*255), 0, 255);
-
-			LLVector4a src;
-
-		
-			LLColor4U glow4u = LLColor4U(0,0,0,glow);
-
-			U32 glow32 = glow4u.asRGBA();
-
-			U32 vec[4];
-			vec[0] = vec[1] = vec[2] = vec[3] = glow32;
-		
-			src.loadua((F32*) vec);
-
-			F32* dst = (F32*) emissive.get();
-			S32 num_vecs = num_vertices/4;
-			if (num_vertices%4 > 0)
-			{
-				++num_vecs;
-			}
-
-			for (S32 i = 0; i < num_vecs; i++)
-			{	
-				src.store4a(dst);
-				dst += 4;
-			}
-		}
-	}
-
-	if (rebuild_tcoord)
-	{
-		mTexExtents[0].setVec(0,0);
-		mTexExtents[1].setVec(1,1);
-		xform(mTexExtents[0], cos_ang, sin_ang, os, ot, ms, mt);
-		xform(mTexExtents[1], cos_ang, sin_ang, os, ot, ms, mt);
-		
-		F32 es = vf.mTexCoordExtents[1].mV[0] - vf.mTexCoordExtents[0].mV[0] ;
-		F32 et = vf.mTexCoordExtents[1].mV[1] - vf.mTexCoordExtents[0].mV[1] ;
-		mTexExtents[0][0] *= es ;
-		mTexExtents[1][0] *= es ;
-		mTexExtents[0][1] *= et ;
-		mTexExtents[1][1] *= et ;
-	}
-
-
-	return TRUE;
+            LLStrider<LLColor4U> emissive;
+            mVertexBuffer->getEmissiveStrider(emissive, mGeomIndex, mGeomCount);
+
+            U8 glow = (U8) llclamp((S32) (getTextureEntry()->getGlow()*255), 0, 255);
+
+            LLVector4a src;
+
+
+            LLColor4U glow4u = LLColor4U(0,0,0,glow);
+
+            U32 glow32 = glow4u.asRGBA();
+
+            U32 vec[4];
+            vec[0] = vec[1] = vec[2] = vec[3] = glow32;
+
+            src.loadua((F32*) vec);
+
+            F32* dst = (F32*) emissive.get();
+            S32 num_vecs = num_vertices/4;
+            if (num_vertices%4 > 0)
+            {
+                ++num_vecs;
+            }
+
+            for (S32 i = 0; i < num_vecs; i++)
+            {
+                src.store4a(dst);
+                dst += 4;
+            }
+        }
+    }
+
+    if (rebuild_tcoord)
+    {
+        mTexExtents[0].setVec(0,0);
+        mTexExtents[1].setVec(1,1);
+        xform(mTexExtents[0], cos_ang, sin_ang, os, ot, ms, mt);
+        xform(mTexExtents[1], cos_ang, sin_ang, os, ot, ms, mt);
+
+        F32 es = vf.mTexCoordExtents[1].mV[0] - vf.mTexCoordExtents[0].mV[0] ;
+        F32 et = vf.mTexCoordExtents[1].mV[1] - vf.mTexCoordExtents[0].mV[1] ;
+        mTexExtents[0][0] *= es ;
+        mTexExtents[1][0] *= es ;
+        mTexExtents[0][1] *= et ;
+        mTexExtents[1][1] *= et ;
+    }
+
+
+    return TRUE;
 }
 
 void LLFace::renderIndexed()
@@ -2036,18 +2036,18 @@ void LLFace::renderIndexed()
 }
 
 //check if the face has a media
-BOOL LLFace::hasMedia() const 
+BOOL LLFace::hasMedia() const
 {
-	if(mHasMedia)
-	{
-		return TRUE ;
-	}
-	if(mTexture[LLRender::DIFFUSE_MAP].notNull()) 
-	{
-		return mTexture[LLRender::DIFFUSE_MAP]->hasParcelMedia() ;  //if has a parcel media
-	}
-
-	return FALSE ; //no media.
+    if(mHasMedia)
+    {
+        return TRUE ;
+    }
+    if(mTexture[LLRender::DIFFUSE_MAP].notNull())
+    {
+        return mTexture[LLRender::DIFFUSE_MAP]->hasParcelMedia() ;  //if has a parcel media
+    }
+
+    return FALSE ; //no media.
 }
 
 const F32 LEAST_IMPORTANCE = 0.05f ;
@@ -2055,65 +2055,65 @@ const F32 LEAST_IMPORTANCE_FOR_LARGE_IMAGE = 0.3f ;
 
 void LLFace::resetVirtualSize()
 {
-	setVirtualSize(0.f);
-	mImportanceToCamera = 0.f;
+    setVirtualSize(0.f);
+    mImportanceToCamera = 0.f;
 }
 
 F32 LLFace::getTextureVirtualSize()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	F32 radius;
-	F32 cos_angle_to_view_dir;	
-	BOOL in_frustum = calcPixelArea(cos_angle_to_view_dir, radius);
-
-	if (mPixelArea < F_ALMOST_ZERO || !in_frustum)
-	{
-		setVirtualSize(0.f) ;
-		return 0.f;
-	}
-
-	//get area of circle in texture space
-	LLVector2 tdim = mTexExtents[1] - mTexExtents[0];
-	F32 texel_area = (tdim * 0.5f).lengthSquared()*3.14159f;
-	if (texel_area <= 0)
-	{
-		// Probably animated, use default
-		texel_area = 1.f;
-	}
-
-	F32 face_area;
-	if (mVObjp->isSculpted() && texel_area > 1.f)
-	{
-		//sculpts can break assumptions about texel area
-		face_area = mPixelArea;
-	}
-	else
-	{
-		//apply texel area to face area to get accurate ratio
-		//face_area /= llclamp(texel_area, 1.f/64.f, 16.f);
-		face_area =  mPixelArea / llclamp(texel_area, 0.015625f, 128.f);
-	}
-
-	face_area = LLFace::adjustPixelArea(mImportanceToCamera, face_area) ;
-	if(face_area > LLViewerTexture::sMinLargeImageSize) //if is large image, shrink face_area by considering the partial overlapping.
-	{
-		if(mImportanceToCamera > LEAST_IMPORTANCE_FOR_LARGE_IMAGE && mTexture[LLRender::DIFFUSE_MAP].notNull() && mTexture[LLRender::DIFFUSE_MAP]->isLargeImage())
-		{		
-			face_area *= adjustPartialOverlapPixelArea(cos_angle_to_view_dir, radius );
-		}	
-	}
-
-	setVirtualSize(face_area) ;
-
-	return face_area;
+    F32 radius;
+    F32 cos_angle_to_view_dir;
+    BOOL in_frustum = calcPixelArea(cos_angle_to_view_dir, radius);
+
+    if (mPixelArea < F_ALMOST_ZERO || !in_frustum)
+    {
+        setVirtualSize(0.f) ;
+        return 0.f;
+    }
+
+    //get area of circle in texture space
+    LLVector2 tdim = mTexExtents[1] - mTexExtents[0];
+    F32 texel_area = (tdim * 0.5f).lengthSquared()*3.14159f;
+    if (texel_area <= 0)
+    {
+        // Probably animated, use default
+        texel_area = 1.f;
+    }
+
+    F32 face_area;
+    if (mVObjp->isSculpted() && texel_area > 1.f)
+    {
+        //sculpts can break assumptions about texel area
+        face_area = mPixelArea;
+    }
+    else
+    {
+        //apply texel area to face area to get accurate ratio
+        //face_area /= llclamp(texel_area, 1.f/64.f, 16.f);
+        face_area =  mPixelArea / llclamp(texel_area, 0.015625f, 128.f);
+    }
+
+    face_area = LLFace::adjustPixelArea(mImportanceToCamera, face_area) ;
+    if(face_area > LLViewerTexture::sMinLargeImageSize) //if is large image, shrink face_area by considering the partial overlapping.
+    {
+        if(mImportanceToCamera > LEAST_IMPORTANCE_FOR_LARGE_IMAGE && mTexture[LLRender::DIFFUSE_MAP].notNull() && mTexture[LLRender::DIFFUSE_MAP]->isLargeImage())
+        {
+            face_area *= adjustPartialOverlapPixelArea(cos_angle_to_view_dir, radius );
+        }
+    }
+
+    setVirtualSize(face_area) ;
+
+    return face_area;
 }
 
 BOOL LLFace::calcPixelArea(F32& cos_angle_to_view_dir, F32& radius)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_FACE;
 
-	//VECTORIZE THIS
-	//get area of circle around face
+    //VECTORIZE THIS
+    //get area of circle around face
 
     LLVector4a center;
     LLVector4a size;
@@ -2139,238 +2139,238 @@ BOOL LLFace::calcPixelArea(F32& cos_angle_to_view_dir, F32& radius)
         center.load3(getPositionAgent().mV);
         size.setSub(mExtents[1], mExtents[0]);
     }
-	size.mul(0.5f);
-
-	LLViewerCamera* camera = LLViewerCamera::getInstance();
-
-	F32 size_squared = size.dot3(size).getF32();
-	LLVector4a lookAt;
-	LLVector4a t;
-	t.load3(camera->getOrigin().mV);
-	lookAt.setSub(center, t);
-	
-	F32 dist = lookAt.getLength3().getF32();
-	dist = llmax(dist-size.getLength3().getF32(), 0.001f);
-	//ramp down distance for nearby objects
-	if (dist < 16.f)
-	{
-		dist /= 16.f;
-		dist *= dist;
-		dist *= 16.f;
-	}
-
-	lookAt.normalize3fast() ;	
-
-	//get area of circle around node
-	F32 app_angle = atanf((F32) sqrt(size_squared) / dist);
-	radius = app_angle*LLDrawable::sCurPixelAngle;
-	mPixelArea = radius*radius * 3.14159f;
-	LLVector4a x_axis;
-	x_axis.load3(camera->getXAxis().mV);
-	cos_angle_to_view_dir = lookAt.dot3(x_axis).getF32();
-
-	//if has media, check if the face is out of the view frustum.	
-	if(hasMedia())
-	{
-		if(!camera->AABBInFrustum(center, size)) 
-		{
-			mImportanceToCamera = 0.f ;
-			return false ;
-		}
-		if(cos_angle_to_view_dir > camera->getCosHalfFov()) //the center is within the view frustum
-		{
-			cos_angle_to_view_dir = 1.0f ;
-		}
-		else
-		{		
-			LLVector4a d;
-			d.setSub(lookAt, x_axis);
-
-			if(dist * dist * d.dot3(d) < size_squared)
-			{
-				cos_angle_to_view_dir = 1.0f ;
-			}
-		}
-	}
-
-	if(dist < mBoundingSphereRadius) //camera is very close
-	{
-		cos_angle_to_view_dir = 1.0f ;
-		mImportanceToCamera = 1.0f ;
-	}
-	else
-	{		
-		mImportanceToCamera = LLFace::calcImportanceToCamera(cos_angle_to_view_dir, dist) ;
-	}
-
-	return true ;
+    size.mul(0.5f);
+
+    LLViewerCamera* camera = LLViewerCamera::getInstance();
+
+    F32 size_squared = size.dot3(size).getF32();
+    LLVector4a lookAt;
+    LLVector4a t;
+    t.load3(camera->getOrigin().mV);
+    lookAt.setSub(center, t);
+
+    F32 dist = lookAt.getLength3().getF32();
+    dist = llmax(dist-size.getLength3().getF32(), 0.001f);
+    //ramp down distance for nearby objects
+    if (dist < 16.f)
+    {
+        dist /= 16.f;
+        dist *= dist;
+        dist *= 16.f;
+    }
+
+    lookAt.normalize3fast() ;
+
+    //get area of circle around node
+    F32 app_angle = atanf((F32) sqrt(size_squared) / dist);
+    radius = app_angle*LLDrawable::sCurPixelAngle;
+    mPixelArea = radius*radius * 3.14159f;
+    LLVector4a x_axis;
+    x_axis.load3(camera->getXAxis().mV);
+    cos_angle_to_view_dir = lookAt.dot3(x_axis).getF32();
+
+    //if has media, check if the face is out of the view frustum.
+    if(hasMedia())
+    {
+        if(!camera->AABBInFrustum(center, size))
+        {
+            mImportanceToCamera = 0.f ;
+            return false ;
+        }
+        if(cos_angle_to_view_dir > camera->getCosHalfFov()) //the center is within the view frustum
+        {
+            cos_angle_to_view_dir = 1.0f ;
+        }
+        else
+        {
+            LLVector4a d;
+            d.setSub(lookAt, x_axis);
+
+            if(dist * dist * d.dot3(d) < size_squared)
+            {
+                cos_angle_to_view_dir = 1.0f ;
+            }
+        }
+    }
+
+    if(dist < mBoundingSphereRadius) //camera is very close
+    {
+        cos_angle_to_view_dir = 1.0f ;
+        mImportanceToCamera = 1.0f ;
+    }
+    else
+    {
+        mImportanceToCamera = LLFace::calcImportanceToCamera(cos_angle_to_view_dir, dist) ;
+    }
+
+    return true ;
 }
 
 //the projection of the face partially overlaps with the screen
 F32 LLFace::adjustPartialOverlapPixelArea(F32 cos_angle_to_view_dir, F32 radius )
 {
-	F32 screen_radius = (F32)llmax(gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw()) ;
-	F32 center_angle = acosf(cos_angle_to_view_dir) ;
-	F32 d = center_angle * LLDrawable::sCurPixelAngle ;
-
-	if(d + radius > screen_radius + 5.f)
-	{
-		//----------------------------------------------
-		//calculate the intersection area of two circles
-		//F32 radius_square = radius * radius ;
-		//F32 d_square = d * d ;
-		//F32 screen_radius_square = screen_radius * screen_radius ;
-		//face_area = 
-		//	radius_square * acosf((d_square + radius_square - screen_radius_square)/(2 * d * radius)) +
-		//	screen_radius_square * acosf((d_square + screen_radius_square - radius_square)/(2 * d * screen_radius)) -
-		//	0.5f * sqrtf((-d + radius + screen_radius) * (d + radius - screen_radius) * (d - radius + screen_radius) * (d + radius + screen_radius)) ;			
-		//----------------------------------------------
-
-		//the above calculation is too expensive
-		//the below is a good estimation: bounding box of the bounding sphere:
-		F32 alpha = 0.5f * (radius + screen_radius - d) / radius ;
-		alpha = llclamp(alpha, 0.f, 1.f) ;
-		return alpha * alpha ;
-	}
-	return 1.0f ;
+    F32 screen_radius = (F32)llmax(gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw()) ;
+    F32 center_angle = acosf(cos_angle_to_view_dir) ;
+    F32 d = center_angle * LLDrawable::sCurPixelAngle ;
+
+    if(d + radius > screen_radius + 5.f)
+    {
+        //----------------------------------------------
+        //calculate the intersection area of two circles
+        //F32 radius_square = radius * radius ;
+        //F32 d_square = d * d ;
+        //F32 screen_radius_square = screen_radius * screen_radius ;
+        //face_area =
+        //  radius_square * acosf((d_square + radius_square - screen_radius_square)/(2 * d * radius)) +
+        //  screen_radius_square * acosf((d_square + screen_radius_square - radius_square)/(2 * d * screen_radius)) -
+        //  0.5f * sqrtf((-d + radius + screen_radius) * (d + radius - screen_radius) * (d - radius + screen_radius) * (d + radius + screen_radius)) ;
+        //----------------------------------------------
+
+        //the above calculation is too expensive
+        //the below is a good estimation: bounding box of the bounding sphere:
+        F32 alpha = 0.5f * (radius + screen_radius - d) / radius ;
+        alpha = llclamp(alpha, 0.f, 1.f) ;
+        return alpha * alpha ;
+    }
+    return 1.0f ;
 }
 
 const S8 FACE_IMPORTANCE_LEVEL = 4 ;
 const F32 FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[FACE_IMPORTANCE_LEVEL][2] = //{distance, importance_weight}
-	{{16.1f, 1.0f}, {32.1f, 0.5f}, {48.1f, 0.2f}, {96.1f, 0.05f} } ;
+    {{16.1f, 1.0f}, {32.1f, 0.5f}, {48.1f, 0.2f}, {96.1f, 0.05f} } ;
 const F32 FACE_IMPORTANCE_TO_CAMERA_OVER_ANGLE[FACE_IMPORTANCE_LEVEL][2] =    //{cos(angle), importance_weight}
-	{{0.985f /*cos(10 degrees)*/, 1.0f}, {0.94f /*cos(20 degrees)*/, 0.8f}, {0.866f /*cos(30 degrees)*/, 0.64f}, {0.0f, 0.36f}} ;
+    {{0.985f /*cos(10 degrees)*/, 1.0f}, {0.94f /*cos(20 degrees)*/, 0.8f}, {0.866f /*cos(30 degrees)*/, 0.64f}, {0.0f, 0.36f}} ;
 
-//static 
+//static
 F32 LLFace::calcImportanceToCamera(F32 cos_angle_to_view_dir, F32 dist)
 {
-	F32 importance = 0.f ;
-	
-	LLViewerCamera& camera = LLViewerCamera::instance();
-
-	if(cos_angle_to_view_dir > camera.getCosHalfFov() &&
-		dist < FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[FACE_IMPORTANCE_LEVEL - 1][0]) 
-	{
-		F32 camera_moving_speed = camera.getAverageSpeed() ;
-		F32 camera_angular_speed = camera.getAverageAngularSpeed();
-
-		if(camera_moving_speed > 10.0f || camera_angular_speed > 1.0f)
-		{
-			//if camera moves or rotates too fast, ignore the importance factor
-			return 0.f ;
-		}
-		
-		S32 i = 0 ;
-		for(i = 0; i < FACE_IMPORTANCE_LEVEL && dist > FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[i][0]; ++i);
-		i = llmin(i, FACE_IMPORTANCE_LEVEL - 1) ;
-		F32 dist_factor = FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[i][1] ;
-		
-		for(i = 0; i < FACE_IMPORTANCE_LEVEL && cos_angle_to_view_dir < FACE_IMPORTANCE_TO_CAMERA_OVER_ANGLE[i][0] ; ++i) ;
-		i = llmin(i, FACE_IMPORTANCE_LEVEL - 1) ;
-		importance = dist_factor * FACE_IMPORTANCE_TO_CAMERA_OVER_ANGLE[i][1] ;
-	}
-
-	return importance ;
+    F32 importance = 0.f ;
+
+    LLViewerCamera& camera = LLViewerCamera::instance();
+
+    if(cos_angle_to_view_dir > camera.getCosHalfFov() &&
+        dist < FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[FACE_IMPORTANCE_LEVEL - 1][0])
+    {
+        F32 camera_moving_speed = camera.getAverageSpeed() ;
+        F32 camera_angular_speed = camera.getAverageAngularSpeed();
+
+        if(camera_moving_speed > 10.0f || camera_angular_speed > 1.0f)
+        {
+            //if camera moves or rotates too fast, ignore the importance factor
+            return 0.f ;
+        }
+
+        S32 i = 0 ;
+        for(i = 0; i < FACE_IMPORTANCE_LEVEL && dist > FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[i][0]; ++i);
+        i = llmin(i, FACE_IMPORTANCE_LEVEL - 1) ;
+        F32 dist_factor = FACE_IMPORTANCE_TO_CAMERA_OVER_DISTANCE[i][1] ;
+
+        for(i = 0; i < FACE_IMPORTANCE_LEVEL && cos_angle_to_view_dir < FACE_IMPORTANCE_TO_CAMERA_OVER_ANGLE[i][0] ; ++i) ;
+        i = llmin(i, FACE_IMPORTANCE_LEVEL - 1) ;
+        importance = dist_factor * FACE_IMPORTANCE_TO_CAMERA_OVER_ANGLE[i][1] ;
+    }
+
+    return importance ;
 }
 
-//static 
+//static
 F32 LLFace::adjustPixelArea(F32 importance, F32 pixel_area)
 {
-	if(pixel_area > LLViewerTexture::sMaxSmallImageSize)
-	{
-		if(importance < LEAST_IMPORTANCE) //if the face is not important, do not load hi-res.
-		{
-			static const F32 MAX_LEAST_IMPORTANCE_IMAGE_SIZE = 128.0f * 128.0f ;
-			pixel_area = llmin(pixel_area * 0.5f, MAX_LEAST_IMPORTANCE_IMAGE_SIZE) ;
-		}
-		else if(pixel_area > LLViewerTexture::sMinLargeImageSize) //if is large image, shrink face_area by considering the partial overlapping.
-		{
-			if(importance < LEAST_IMPORTANCE_FOR_LARGE_IMAGE)//if the face is not important, do not load hi-res.
-			{
-				pixel_area = LLViewerTexture::sMinLargeImageSize ;
-			}				
-		}
-	}
-
-	return pixel_area ;
+    if(pixel_area > LLViewerTexture::sMaxSmallImageSize)
+    {
+        if(importance < LEAST_IMPORTANCE) //if the face is not important, do not load hi-res.
+        {
+            static const F32 MAX_LEAST_IMPORTANCE_IMAGE_SIZE = 128.0f * 128.0f ;
+            pixel_area = llmin(pixel_area * 0.5f, MAX_LEAST_IMPORTANCE_IMAGE_SIZE) ;
+        }
+        else if(pixel_area > LLViewerTexture::sMinLargeImageSize) //if is large image, shrink face_area by considering the partial overlapping.
+        {
+            if(importance < LEAST_IMPORTANCE_FOR_LARGE_IMAGE)//if the face is not important, do not load hi-res.
+            {
+                pixel_area = LLViewerTexture::sMinLargeImageSize ;
+            }
+        }
+    }
+
+    return pixel_area ;
 }
 
 BOOL LLFace::verify(const U32* indices_array) const
 {
-	BOOL ok = TRUE;
-
-	if( mVertexBuffer.isNull() )
-	{ //no vertex buffer, face is implicitly valid
-		return TRUE;
-	}
-	
-	// First, check whether the face data fits within the pool's range.
-	if ((mGeomIndex + mGeomCount) > mVertexBuffer->getNumVerts())
-	{
-		ok = FALSE;
-		LL_INFOS() << "Face references invalid vertices!" << LL_ENDL;
-	}
-
-	S32 indices_count = (S32)getIndicesCount();
-	
-	if (!indices_count)
-	{
-		return TRUE;
-	}
-	
-	if (indices_count > LL_MAX_INDICES_COUNT)
-	{
-		ok = FALSE;
-		LL_INFOS() << "Face has bogus indices count" << LL_ENDL;
-	}
-	
-	if (mIndicesIndex + mIndicesCount > mVertexBuffer->getNumIndices())
-	{
-		ok = FALSE;
-		LL_INFOS() << "Face references invalid indices!" << LL_ENDL;
-	}
+    BOOL ok = TRUE;
+
+    if( mVertexBuffer.isNull() )
+    { //no vertex buffer, face is implicitly valid
+        return TRUE;
+    }
+
+    // First, check whether the face data fits within the pool's range.
+    if ((mGeomIndex + mGeomCount) > mVertexBuffer->getNumVerts())
+    {
+        ok = FALSE;
+        LL_INFOS() << "Face references invalid vertices!" << LL_ENDL;
+    }
+
+    S32 indices_count = (S32)getIndicesCount();
+
+    if (!indices_count)
+    {
+        return TRUE;
+    }
+
+    if (indices_count > LL_MAX_INDICES_COUNT)
+    {
+        ok = FALSE;
+        LL_INFOS() << "Face has bogus indices count" << LL_ENDL;
+    }
+
+    if (mIndicesIndex + mIndicesCount > mVertexBuffer->getNumIndices())
+    {
+        ok = FALSE;
+        LL_INFOS() << "Face references invalid indices!" << LL_ENDL;
+    }
 
 #if 0
-	S32 geom_start = getGeomStart();
-	S32 geom_count = mGeomCount;
-
-	const U32 *indicesp = indices_array ? indices_array + mIndicesIndex : getRawIndices();
-
-	for (S32 i = 0; i < indices_count; i++)
-	{
-		S32 delta = indicesp[i] - geom_start;
-		if (0 > delta)
-		{
-			LL_WARNS() << "Face index too low!" << LL_ENDL;
-			LL_INFOS() << "i:" << i << " Index:" << indicesp[i] << " GStart: " << geom_start << LL_ENDL;
-			ok = FALSE;
-		}
-		else if (delta >= geom_count)
-		{
-			LL_WARNS() << "Face index too high!" << LL_ENDL;
-			LL_INFOS() << "i:" << i << " Index:" << indicesp[i] << " GEnd: " << geom_start + geom_count << LL_ENDL;
-			ok = FALSE;
-		}
-	}
+    S32 geom_start = getGeomStart();
+    S32 geom_count = mGeomCount;
+
+    const U32 *indicesp = indices_array ? indices_array + mIndicesIndex : getRawIndices();
+
+    for (S32 i = 0; i < indices_count; i++)
+    {
+        S32 delta = indicesp[i] - geom_start;
+        if (0 > delta)
+        {
+            LL_WARNS() << "Face index too low!" << LL_ENDL;
+            LL_INFOS() << "i:" << i << " Index:" << indicesp[i] << " GStart: " << geom_start << LL_ENDL;
+            ok = FALSE;
+        }
+        else if (delta >= geom_count)
+        {
+            LL_WARNS() << "Face index too high!" << LL_ENDL;
+            LL_INFOS() << "i:" << i << " Index:" << indicesp[i] << " GEnd: " << geom_start + geom_count << LL_ENDL;
+            ok = FALSE;
+        }
+    }
 #endif
 
-	if (!ok)
-	{
-		printDebugInfo();
-	}
-	return ok;
+    if (!ok)
+    {
+        printDebugInfo();
+    }
+    return ok;
 }
 
 
 void LLFace::setViewerObject(LLViewerObject* objp)
 {
-	mVObjp = objp;
+    mVObjp = objp;
 }
 
 
 const LLMatrix4a& LLFace::getRenderMatrix() const
 {
-	return mDrawablep->getRenderMatrix();
+    return mDrawablep->getRenderMatrix();
 }
 
 //============================================================================
@@ -2378,139 +2378,139 @@ const LLMatrix4a& LLFace::getRenderMatrix() const
 
 S32 LLFace::getColors(LLStrider<LLColor4U> &colors)
 {
-	if (!mGeomCount)
-	{
-		return -1;
-	}
-	
-	// llassert(mGeomIndex >= 0);
-	mVertexBuffer->getColorStrider(colors, mGeomIndex, mGeomCount);
-	return mGeomIndex;
+    if (!mGeomCount)
+    {
+        return -1;
+    }
+
+    // llassert(mGeomIndex >= 0);
+    mVertexBuffer->getColorStrider(colors, mGeomIndex, mGeomCount);
+    return mGeomIndex;
 }
 
-S32	LLFace::getIndices(LLStrider<U16> &indicesp)
+S32 LLFace::getIndices(LLStrider<U16> &indicesp)
 {
-	mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount);
-	llassert(indicesp[0] != indicesp[1]);
-	return mIndicesIndex;
+    mVertexBuffer->getIndexStrider(indicesp, mIndicesIndex, mIndicesCount);
+    llassert(indicesp[0] != indicesp[1]);
+    return mIndicesIndex;
 }
 
 LLVector3 LLFace::getPositionAgent() const
 {
-	if (mDrawablep->isStatic())
-	{
-		return mCenterAgent;
-	}
-	else
-	{
-		LLVector4a center_local;
-		center_local.load3(mCenterLocal.mV);
-		getRenderMatrix().affineTransform(center_local,center_local);
-		return LLVector3(center_local.getF32ptr());
-	}
+    if (mDrawablep->isStatic())
+    {
+        return mCenterAgent;
+    }
+    else
+    {
+        LLVector4a center_local;
+        center_local.load3(mCenterLocal.mV);
+        getRenderMatrix().affineTransform(center_local,center_local);
+        return LLVector3(center_local.getF32ptr());
+    }
 }
 
 LLViewerTexture* LLFace::getTexture(U32 ch) const
 {
-	llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
+    llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
 
 // [SL:KB] - Patch: Render-TextureToggle (Catznip-4.0)
-	// Check whether the diffuse texture needs to be obscured or restored
-	if (mShowDiffTexture != LLPipeline::sRenderTextures)
-		setDefaultTexture(LLRender::DIFFUSE_MAP, !LLPipeline::sRenderTextures);
+    // Check whether the diffuse texture needs to be obscured or restored
+    if (mShowDiffTexture != LLPipeline::sRenderTextures)
+        setDefaultTexture(LLRender::DIFFUSE_MAP, !LLPipeline::sRenderTextures);
 // [/SL:KB]
 
-	return mTexture[ch] ;
+    return mTexture[ch] ;
 }
 
 // [SL:KB] - Patch: Render-TextureToggle (Catznip-4.0)
 bool LLFace::isDefaultTexture(U32 nChannel) const
 {
-	// NOTE: mShowDiffTexture gets flipped before the clear (good) but also before the restore (bad) and hence can't
-	//       be used to tell whether we're usurping a texture channel for our own use
-	return (LLRender::DIFFUSE_MAP == nChannel) ? mOrigDiffTexture.notNull() : false;
+    // NOTE: mShowDiffTexture gets flipped before the clear (good) but also before the restore (bad) and hence can't
+    //       be used to tell whether we're usurping a texture channel for our own use
+    return (LLRender::DIFFUSE_MAP == nChannel) ? mOrigDiffTexture.notNull() : false;
 }
 
 void LLFace::setDefaultTexture(U32 nChannel, bool fShowDefault) const
 {
-	bool fUpdated = false;
-	if ( (LLRender::DIFFUSE_MAP == nChannel) && (mVObjp) && (!mVObjp->isDead()) && ((LL_PCODE_VOLUME == mVObjp->getPCode()) || (LLViewerObject::LL_VO_PART_GROUP == mVObjp->getPCode())) )
-	{
-		if ( ((mShowDiffTexture) && (fShowDefault)) ||
-		     ((!mShowDiffTexture) && (fShowDefault) && (mOrigDiffTexture.notNull()) && (mTexture[nChannel]) && (mTexture[nChannel]->getID() != LLViewerFetchedTexture::sDefaultDiffuseImagep->getID())) )
-		{
-			if (mOrigDiffTexture.notNull())
-				mShowDiffTexture = true;				// Swap out the default texture
-			else
-				mOrigDiffTexture = mTexture[nChannel];	// Cache the original texture
-
-			if ( (!gRlvHandler.hasBehaviour(RLV_BHVR_SETCAM_TEXTURES)) || (!mVObjp->isAttachment()) )
-			{
-				if (LL_PCODE_VOLUME == mVObjp->getPCode())
-					const_cast<LLFace*>(this)->switchTexture(nChannel, LLViewerFetchedTexture::sDefaultDiffuseImagep);
-				else
-					const_cast<LLFace*>(this)->setTexture(nChannel, LLViewerFetchedTexture::sDefaultDiffuseImagep);
-			}
-			mShowDiffTexture = false; fUpdated = true;
-		}
-		else if ( (!mShowDiffTexture) && (!fShowDefault) && (mOrigDiffTexture.notNull()) )
-		{
-			mShowDiffTexture = true;
-			if (LL_PCODE_VOLUME == mVObjp->getPCode())
-				const_cast<LLFace*>(this)->switchTexture(nChannel, mOrigDiffTexture);
-			else
-				const_cast<LLFace*>(this)->setTexture(nChannel, mOrigDiffTexture);
-			mOrigDiffTexture = nullptr; fUpdated = true;
-		}
-
-		if ((fUpdated) && (mDrawablep))
-		{
-			gPipeline.markTextured(mDrawablep);
-			mDrawablep->updateTexture();
-		}
-	}
-
-	// Always flip the flag even if we didn't obscure so we don't keep wasting cycles with negative checks
-	mShowDiffTexture = !fShowDefault;
+    bool fUpdated = false;
+    if ( (LLRender::DIFFUSE_MAP == nChannel) && (mVObjp) && (!mVObjp->isDead()) && ((LL_PCODE_VOLUME == mVObjp->getPCode()) || (LLViewerObject::LL_VO_PART_GROUP == mVObjp->getPCode())) )
+    {
+        if ( ((mShowDiffTexture) && (fShowDefault)) ||
+             ((!mShowDiffTexture) && (fShowDefault) && (mOrigDiffTexture.notNull()) && (mTexture[nChannel]) && (mTexture[nChannel]->getID() != LLViewerFetchedTexture::sDefaultDiffuseImagep->getID())) )
+        {
+            if (mOrigDiffTexture.notNull())
+                mShowDiffTexture = true;                // Swap out the default texture
+            else
+                mOrigDiffTexture = mTexture[nChannel];  // Cache the original texture
+
+            if ( (!gRlvHandler.hasBehaviour(RLV_BHVR_SETCAM_TEXTURES)) || (!mVObjp->isAttachment()) )
+            {
+                if (LL_PCODE_VOLUME == mVObjp->getPCode())
+                    const_cast<LLFace*>(this)->switchTexture(nChannel, LLViewerFetchedTexture::sDefaultDiffuseImagep);
+                else
+                    const_cast<LLFace*>(this)->setTexture(nChannel, LLViewerFetchedTexture::sDefaultDiffuseImagep);
+            }
+            mShowDiffTexture = false; fUpdated = true;
+        }
+        else if ( (!mShowDiffTexture) && (!fShowDefault) && (mOrigDiffTexture.notNull()) )
+        {
+            mShowDiffTexture = true;
+            if (LL_PCODE_VOLUME == mVObjp->getPCode())
+                const_cast<LLFace*>(this)->switchTexture(nChannel, mOrigDiffTexture);
+            else
+                const_cast<LLFace*>(this)->setTexture(nChannel, mOrigDiffTexture);
+            mOrigDiffTexture = nullptr; fUpdated = true;
+        }
+
+        if ((fUpdated) && (mDrawablep))
+        {
+            gPipeline.markTextured(mDrawablep);
+            mDrawablep->updateTexture();
+        }
+    }
+
+    // Always flip the flag even if we didn't obscure so we don't keep wasting cycles with negative checks
+    mShowDiffTexture = !fShowDefault;
 }
 // [/SL:KB]
 
 void LLFace::setVertexBuffer(LLVertexBuffer* buffer)
 {
-	if (buffer)
-	{
-		LLSculptIDSize::instance().inc(mDrawablep, buffer->getSize() + buffer->getIndicesSize());
-	}
-
-	if (mVertexBuffer)
-	{
-		LLSculptIDSize::instance().dec(mDrawablep);
-	}
-
-	mVertexBuffer = buffer;
-	llassert(verify());
+    if (buffer)
+    {
+        LLSculptIDSize::instance().inc(mDrawablep, buffer->getSize() + buffer->getIndicesSize());
+    }
+
+    if (mVertexBuffer)
+    {
+        LLSculptIDSize::instance().dec(mDrawablep);
+    }
+
+    mVertexBuffer = buffer;
+    llassert(verify());
 }
 
 void LLFace::clearVertexBuffer()
 {
-	if (mVertexBuffer)
-	{
-		LLSculptIDSize::instance().dec(mDrawablep);
-	}
+    if (mVertexBuffer)
+    {
+        LLSculptIDSize::instance().dec(mDrawablep);
+    }
 
-	mVertexBuffer = NULL;
+    mVertexBuffer = NULL;
 }
 
 S32 LLFace::getRiggedIndex(U32 type) const
 {
-	if (mRiggedIndex.empty())
-	{
-		return -1;
-	}
+    if (mRiggedIndex.empty())
+    {
+        return -1;
+    }
 
-	llassert(type < mRiggedIndex.size());
+    llassert(type < mRiggedIndex.size());
 
-	return mRiggedIndex[type];
+    return mRiggedIndex[type];
 }
 
 U64 LLFace::getSkinHash()
diff --git a/indra/newview/llfeaturemanager.cpp b/indra/newview/llfeaturemanager.cpp
index cca34425f43ce35573e239e6e4717a50e9afe99c..6494e1551c6b00230f681e0c3833c267e8b17033 100644
--- a/indra/newview/llfeaturemanager.cpp
+++ b/indra/newview/llfeaturemanager.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llfeaturemanager.cpp
  * @brief LLFeatureManager class implementation
  *
  * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -71,12 +71,12 @@ const char FEATURE_TABLE_FILENAME[] = "featuretable.txt";
 #if 0                               // consuming code in #if 0 below
 #endif
 LLFeatureInfo::LLFeatureInfo(const std::string& name, const BOOL available, const F32 level)
-	: mValid(TRUE), mName(name), mAvailable(available), mRecommendedLevel(level)
+    : mValid(TRUE), mName(name), mAvailable(available), mRecommendedLevel(level)
 {
 }
 
 LLFeatureList::LLFeatureList(const std::string& name)
-	: mName(name)
+    : mName(name)
 {
 }
 
@@ -86,292 +86,292 @@ LLFeatureList::~LLFeatureList()
 
 void LLFeatureList::addFeature(const std::string& name, const BOOL available, const F32 level)
 {
-	if (mFeatures.count(name))
-	{
-		LL_WARNS("RenderInit") << "LLFeatureList::Attempting to add preexisting feature " << name << LL_ENDL;
-	}
+    if (mFeatures.count(name))
+    {
+        LL_WARNS("RenderInit") << "LLFeatureList::Attempting to add preexisting feature " << name << LL_ENDL;
+    }
 
-	LLFeatureInfo fi(name, available, level);
+    LLFeatureInfo fi(name, available, level);
     LL_DEBUGS_ONCE("RenderInit") << "Feature '" << name << "' "
                                  << (available ? "" : "not " ) << "available"
                                  << " at " << level
                                  << LL_ENDL;
-	mFeatures[name] = fi;
+    mFeatures[name] = fi;
 }
 
 BOOL LLFeatureList::isFeatureAvailable(const std::string& name)
 {
-	if (mFeatures.count(name))
-	{
-		return mFeatures[name].mAvailable;
-	}
-
-	LL_WARNS_ONCE("RenderInit") << "Feature " << name << " not on feature list!" << LL_ENDL;
-	
-	// changing this to TRUE so you have to explicitly disable 
-	// something for it to be disabled
-	return TRUE;
+    if (mFeatures.count(name))
+    {
+        return mFeatures[name].mAvailable;
+    }
+
+    LL_WARNS_ONCE("RenderInit") << "Feature " << name << " not on feature list!" << LL_ENDL;
+
+    // changing this to TRUE so you have to explicitly disable
+    // something for it to be disabled
+    return TRUE;
 }
 
 F32 LLFeatureList::getRecommendedValue(const std::string& name)
 {
-	if (mFeatures.count(name) && isFeatureAvailable(name))
-	{
+    if (mFeatures.count(name) && isFeatureAvailable(name))
+    {
         LL_DEBUGS_ONCE("RenderInit") << "Setting '" << name << "' to recommended value " <<  mFeatures[name].mRecommendedLevel << LL_ENDL;
-		return mFeatures[name].mRecommendedLevel;
-	}
+        return mFeatures[name].mRecommendedLevel;
+    }
 
-	LL_WARNS_ONCE("RenderInit") << "Feature " << name << " not on feature list or not available!" << LL_ENDL;
-	return 0;
+    LL_WARNS_ONCE("RenderInit") << "Feature " << name << " not on feature list or not available!" << LL_ENDL;
+    return 0;
 }
 
 BOOL LLFeatureList::maskList(LLFeatureList &mask)
 {
-	LL_DEBUGS_ONCE() << "Masking with " << mask.mName << LL_ENDL;
-	//
-	// Lookup the specified feature mask, and overlay it on top of the
-	// current feature mask.
-	//
-
-	LLFeatureInfo mask_fi;
-
-	feature_map_t::iterator feature_it;
-	for (feature_it = mask.mFeatures.begin(); feature_it != mask.mFeatures.end(); ++feature_it)
-	{
-		mask_fi = feature_it->second;
-		//
-		// Look for the corresponding feature
-		//
-		if (!mFeatures.count(mask_fi.mName))
-		{
-			LL_WARNS("RenderInit") << "Feature " << mask_fi.mName << " in mask not in top level!" << LL_ENDL;
-			continue;
-		}
-
-		LLFeatureInfo &cur_fi = mFeatures[mask_fi.mName];
-		if (mask_fi.mAvailable && !cur_fi.mAvailable)
-		{
-			LL_WARNS("RenderInit") << "Mask attempting to reenabling disabled feature, ignoring " << cur_fi.mName << LL_ENDL;
-			continue;
-		}
-		cur_fi.mAvailable = mask_fi.mAvailable;
-		cur_fi.mRecommendedLevel = llmin(cur_fi.mRecommendedLevel, mask_fi.mRecommendedLevel);
-		LL_DEBUGS("RenderInit") << "Feature mask " << mask.mName
-				<< " Feature " << mask_fi.mName
-				<< " Mask: " << mask_fi.mRecommendedLevel
-				<< " Now: " << cur_fi.mRecommendedLevel << LL_ENDL;
-	}
-
-	LL_DEBUGS("RenderInit") << "After applying mask " << mask.mName << std::endl;
-		// Will conditionally call dump only if the above message will be logged, thanks 
-		// to it being wrapped by the LL_DEBUGS and LL_ENDL macros.
-		dump();
-	LL_CONT << LL_ENDL;
-
-	return TRUE;
+    LL_DEBUGS_ONCE() << "Masking with " << mask.mName << LL_ENDL;
+    //
+    // Lookup the specified feature mask, and overlay it on top of the
+    // current feature mask.
+    //
+
+    LLFeatureInfo mask_fi;
+
+    feature_map_t::iterator feature_it;
+    for (feature_it = mask.mFeatures.begin(); feature_it != mask.mFeatures.end(); ++feature_it)
+    {
+        mask_fi = feature_it->second;
+        //
+        // Look for the corresponding feature
+        //
+        if (!mFeatures.count(mask_fi.mName))
+        {
+            LL_WARNS("RenderInit") << "Feature " << mask_fi.mName << " in mask not in top level!" << LL_ENDL;
+            continue;
+        }
+
+        LLFeatureInfo &cur_fi = mFeatures[mask_fi.mName];
+        if (mask_fi.mAvailable && !cur_fi.mAvailable)
+        {
+            LL_WARNS("RenderInit") << "Mask attempting to reenabling disabled feature, ignoring " << cur_fi.mName << LL_ENDL;
+            continue;
+        }
+        cur_fi.mAvailable = mask_fi.mAvailable;
+        cur_fi.mRecommendedLevel = llmin(cur_fi.mRecommendedLevel, mask_fi.mRecommendedLevel);
+        LL_DEBUGS("RenderInit") << "Feature mask " << mask.mName
+                << " Feature " << mask_fi.mName
+                << " Mask: " << mask_fi.mRecommendedLevel
+                << " Now: " << cur_fi.mRecommendedLevel << LL_ENDL;
+    }
+
+    LL_DEBUGS("RenderInit") << "After applying mask " << mask.mName << std::endl;
+        // Will conditionally call dump only if the above message will be logged, thanks
+        // to it being wrapped by the LL_DEBUGS and LL_ENDL macros.
+        dump();
+    LL_CONT << LL_ENDL;
+
+    return TRUE;
 }
 
 void LLFeatureList::dump()
 {
-	LL_DEBUGS("RenderInit") << "Feature list: " << mName << LL_ENDL;
-
-	LLFeatureInfo fi;
-	feature_map_t::iterator feature_it;
-	for (feature_it = mFeatures.begin(); feature_it != mFeatures.end(); ++feature_it)
-	{
-		fi = feature_it->second;
-		LL_DEBUGS("RenderInit") << "With " << mName << " feature " << fi.mName << " " << fi.mAvailable << ":" << fi.mRecommendedLevel << LL_ENDL;
-	}
+    LL_DEBUGS("RenderInit") << "Feature list: " << mName << LL_ENDL;
+
+    LLFeatureInfo fi;
+    feature_map_t::iterator feature_it;
+    for (feature_it = mFeatures.begin(); feature_it != mFeatures.end(); ++feature_it)
+    {
+        fi = feature_it->second;
+        LL_DEBUGS("RenderInit") << "With " << mName << " feature " << fi.mName << " " << fi.mAvailable << ":" << fi.mRecommendedLevel << LL_ENDL;
+    }
 }
 
 static const std::vector<std::string> sGraphicsLevelNames = boost::assign::list_of
-	("Low")
-	("LowMid")
-	("Mid")
-	("MidHigh")
-	("High")
-	("HighUltra")
-	("Ultra")
+    ("Low")
+    ("LowMid")
+    ("Mid")
+    ("MidHigh")
+    ("High")
+    ("HighUltra")
+    ("Ultra")
 ;
 
 U32 LLFeatureManager::getMaxGraphicsLevel() const
 {
-	return sGraphicsLevelNames.size() - 1;
+    return sGraphicsLevelNames.size() - 1;
 }
 
 bool LLFeatureManager::isValidGraphicsLevel(U32 level) const
 {
-	return (level <= getMaxGraphicsLevel());
+    return (level <= getMaxGraphicsLevel());
 }
 
 std::string LLFeatureManager::getNameForGraphicsLevel(U32 level) const
 {
-	if (isValidGraphicsLevel(level))
-	{
-		return sGraphicsLevelNames[level];
-	}
-	return STRINGIZE("Invalid graphics level " << level << ", valid are 0 .. "
-					 << getMaxGraphicsLevel());
+    if (isValidGraphicsLevel(level))
+    {
+        return sGraphicsLevelNames[level];
+    }
+    return STRINGIZE("Invalid graphics level " << level << ", valid are 0 .. "
+                     << getMaxGraphicsLevel());
 }
 
 S32 LLFeatureManager::getGraphicsLevelForName(const std::string& name) const
 {
-	const std::string FixedFunction("FixedFunction");
-	std::string rname(name);
-	if (LLStringUtil::endsWith(rname, FixedFunction))
-	{
-		// chop off any "FixedFunction" suffix
-		rname = rname.substr(0, rname.length() - FixedFunction.length());
-	}
-	for (S32 i(0), iend(getMaxGraphicsLevel()); i <= iend; ++i)
-	{
-		if (sGraphicsLevelNames[i] == rname)
-		{
-			return i;
-		}
-	}
-	return -1;
+    const std::string FixedFunction("FixedFunction");
+    std::string rname(name);
+    if (LLStringUtil::endsWith(rname, FixedFunction))
+    {
+        // chop off any "FixedFunction" suffix
+        rname = rname.substr(0, rname.length() - FixedFunction.length());
+    }
+    for (S32 i(0), iend(getMaxGraphicsLevel()); i <= iend; ++i)
+    {
+        if (sGraphicsLevelNames[i] == rname)
+        {
+            return i;
+        }
+    }
+    return -1;
 }
 
 LLFeatureList *LLFeatureManager::findMask(const std::string& name)
 {
-	if (mMaskList.count(name))
-	{
-		return mMaskList[name];
-	}
+    if (mMaskList.count(name))
+    {
+        return mMaskList[name];
+    }
 
-	return NULL;
+    return NULL;
 }
 
 BOOL LLFeatureManager::maskFeatures(const std::string& name)
 {
-	LLFeatureList *maskp = findMask(name);
-	if (!maskp)
-	{
- 		LL_DEBUGS("RenderInit") << "Unknown feature mask " << name << LL_ENDL;
-		return FALSE;
-	}
-	LL_INFOS("RenderInit") << "Applying GPU Feature list: " << name << LL_ENDL;
-	return maskList(*maskp);
+    LLFeatureList *maskp = findMask(name);
+    if (!maskp)
+    {
+        LL_DEBUGS("RenderInit") << "Unknown feature mask " << name << LL_ENDL;
+        return FALSE;
+    }
+    LL_INFOS("RenderInit") << "Applying GPU Feature list: " << name << LL_ENDL;
+    return maskList(*maskp);
 }
 
 bool LLFeatureManager::loadFeatureTables()
 {
-	// *TODO - if I or anyone else adds something else to the skipped list
-	// make this data driven.  Put it in the feature table and parse it
-	// correctly
-	mSkippedFeatures.insert("RenderGamma");
-	mSkippedFeatures.insert("RenderVBOEnable");
-	mSkippedFeatures.insert("RenderFogRatio");
+    // *TODO - if I or anyone else adds something else to the skipped list
+    // make this data driven.  Put it in the feature table and parse it
+    // correctly
+    mSkippedFeatures.insert("RenderGamma");
+    mSkippedFeatures.insert("RenderVBOEnable");
+    mSkippedFeatures.insert("RenderFogRatio");
 
-	// first table is install with app
-	std::string app_path = gDirUtilp->getAppRODataDir();
-	app_path += gDirUtilp->getDirDelimiter();
+    // first table is install with app
+    std::string app_path = gDirUtilp->getAppRODataDir();
+    app_path += gDirUtilp->getDirDelimiter();
 
-	std::string filename;
-	filename = FEATURE_TABLE_FILENAME;
+    std::string filename;
+    filename = FEATURE_TABLE_FILENAME;
 
-	app_path += filename;
+    app_path += filename;
 
-	bool parse_ok = parseFeatureTable(app_path);
+    bool parse_ok = parseFeatureTable(app_path);
 
-	return parse_ok;
+    return parse_ok;
 }
 
 
 bool LLFeatureManager::parseFeatureTable(std::string filename)
 {
-	LL_INFOS("RenderInit") << "Attempting to parse feature table from " << filename << LL_ENDL;
-
-	llifstream file;
-	std::string name;
-	U32		version;
-	
-	cleanupFeatureTables(); // in case an earlier attempt left partial results
-	file.open(filename.c_str()); 	 /*Flawfinder: ignore*/
-
-	if (!file)
-	{
-		LL_WARNS("RenderInit") << "Unable to open feature table " << filename << LL_ENDL;
-		return FALSE;
-	}
-
-	// Check file version
-	file >> name;
-	if (name != "version")
-	{
-		LL_WARNS("RenderInit") << filename << " does not appear to be a valid feature table!" << LL_ENDL;
-		return false;
-	}
-	file >> version;
-
-	mTableVersion = version;
-	LL_INFOS("RenderInit") << "Found feature table version " << version << LL_ENDL;
-
-	LLFeatureList *flp = NULL;
-	bool parse_ok = true;
-	while (parse_ok && file >> name )
-	{
-		char buffer[MAX_STRING];		 /*Flawfinder: ignore*/
-		
-		if (name.substr(0,2) == "//")
-		{
-			// This is a comment.
-			file.getline(buffer, MAX_STRING);
-			continue;
-		}
-        
-		if (name == "list")
-		{
-			LL_DEBUGS("RenderInit") << "Before new list" << std::endl;
-			if (flp)
-			{
-				flp->dump();
-			}
-			else
-			{
-				LL_CONT << "No current list";
-			}
-			LL_CONT << LL_ENDL;
-			
-			// It's a new mask, create it.
-			file >> name;
-			if (!mMaskList.count(name))
-			{
+    LL_INFOS("RenderInit") << "Attempting to parse feature table from " << filename << LL_ENDL;
+
+    llifstream file;
+    std::string name;
+    U32     version;
+
+    cleanupFeatureTables(); // in case an earlier attempt left partial results
+    file.open(filename.c_str());     /*Flawfinder: ignore*/
+
+    if (!file)
+    {
+        LL_WARNS("RenderInit") << "Unable to open feature table " << filename << LL_ENDL;
+        return FALSE;
+    }
+
+    // Check file version
+    file >> name;
+    if (name != "version")
+    {
+        LL_WARNS("RenderInit") << filename << " does not appear to be a valid feature table!" << LL_ENDL;
+        return false;
+    }
+    file >> version;
+
+    mTableVersion = version;
+    LL_INFOS("RenderInit") << "Found feature table version " << version << LL_ENDL;
+
+    LLFeatureList *flp = NULL;
+    bool parse_ok = true;
+    while (parse_ok && file >> name )
+    {
+        char buffer[MAX_STRING];         /*Flawfinder: ignore*/
+
+        if (name.substr(0,2) == "//")
+        {
+            // This is a comment.
+            file.getline(buffer, MAX_STRING);
+            continue;
+        }
+
+        if (name == "list")
+        {
+            LL_DEBUGS("RenderInit") << "Before new list" << std::endl;
+            if (flp)
+            {
+                flp->dump();
+            }
+            else
+            {
+                LL_CONT << "No current list";
+            }
+            LL_CONT << LL_ENDL;
+
+            // It's a new mask, create it.
+            file >> name;
+            if (!mMaskList.count(name))
+            {
                 flp = new LLFeatureList(name);
                 mMaskList[name] = flp;
             }
             else
             {
-				LL_WARNS("RenderInit") << "Overriding mask '" << name << "'; this is invalid!" << LL_ENDL;
-				parse_ok = false;
-			}
-		}
-		else
-		{
-			if (flp)
-			{
+                LL_WARNS("RenderInit") << "Overriding mask '" << name << "'; this is invalid!" << LL_ENDL;
+                parse_ok = false;
+            }
+        }
+        else
+        {
+            if (flp)
+            {
                 S32 available;
                 F32 recommended;
                 file >> available >> recommended;
                 flp->addFeature(name, available, recommended);
             }
-			else
-			{
-				LL_WARNS("RenderInit") << "Specified parameter before <list> keyword!" << LL_ENDL;
-				parse_ok = false;
-			}
-		}
-	}
-	file.close();
-
-	if (!parse_ok)
-	{
-		LL_WARNS("RenderInit") << "Discarding feature table data from " << filename << LL_ENDL;
-		cleanupFeatureTables();
-	}
-	
-	return parse_ok;
+            else
+            {
+                LL_WARNS("RenderInit") << "Specified parameter before <list> keyword!" << LL_ENDL;
+                parse_ok = false;
+            }
+        }
+    }
+    file.close();
+
+    if (!parse_ok)
+    {
+        LL_WARNS("RenderInit") << "Discarding feature table data from " << filename << LL_ENDL;
+        cleanupFeatureTables();
+    }
+
+    return parse_ok;
 }
 
 F32 gpu_benchmark();
@@ -381,9 +381,9 @@ F32 gpu_benchmark();
 F32 logExceptionBenchmark()
 {
     // FIXME: gpu_benchmark uses many C++ classes on the stack to control state.
-    //  SEH exceptions with our current exception handling options do not call 
+    //  SEH exceptions with our current exception handling options do not call
     //  destructors for these classes, resulting in an undefined state should
-    //  this handler be invoked.  
+    //  this handler be invoked.
     F32 gbps = -1;
     __try
     {
@@ -405,25 +405,25 @@ F32 logExceptionBenchmark()
 
 bool LLFeatureManager::loadGPUClass()
 {
-	if (!gSavedSettings.getBOOL("SkipBenchmark"))
-	{
-		F32 class1_gbps = gSavedSettings.getF32("RenderClass1MemoryBandwidth");
-		//get memory bandwidth from benchmark
-		F32 gbps;
-		try
-		{
+    if (!gSavedSettings.getBOOL("SkipBenchmark"))
+    {
+        F32 class1_gbps = gSavedSettings.getF32("RenderClass1MemoryBandwidth");
+        //get memory bandwidth from benchmark
+        F32 gbps;
+        try
+        {
 #if LL_WINDOWS
-			gbps = logExceptionBenchmark();
+            gbps = logExceptionBenchmark();
 #else
-			gbps = gpu_benchmark();
+            gbps = gpu_benchmark();
 #endif
-		}
-		catch (const std::exception& e)
-		{
-			gbps = -1.f;
-			LL_WARNS("RenderInit") << "GPU benchmark failed: " << e.what() << LL_ENDL;
-		}
-	
+        }
+        catch (const std::exception& e)
+        {
+            gbps = -1.f;
+            LL_WARNS("RenderInit") << "GPU benchmark failed: " << e.what() << LL_ENDL;
+        }
+
         mGPUMemoryBandwidth = gbps;
 
         // bias by CPU speed
@@ -432,36 +432,36 @@ bool LLFeatureManager::loadGPUClass()
         F32 cpu_bias = llclamp(cpu_mhz / cpu_basis_mhz, 0.5f, 1.f);
         gbps *= cpu_bias;
 
-		if (gbps < 0.f)
-		{ //couldn't bench, default to Low
-	#if LL_DARWIN
-		//GLVersion is misleading on OSX, just default to class 3 if we can't bench
-		LL_WARNS("RenderInit") << "Unable to get an accurate benchmark; defaulting to class 3" << LL_ENDL;
-		mGPUClass = GPU_CLASS_3;
-	#else
-			mGPUClass = GPU_CLASS_0;
-	#endif
-		}
-		else if (gbps <= class1_gbps)
-		{
-			mGPUClass = GPU_CLASS_1;
-		}
-		else if (gbps <= class1_gbps *2.f)
-		{
-			mGPUClass = GPU_CLASS_2;
-		}
-		else if (gbps <= class1_gbps*4.f)
-		{
-			mGPUClass = GPU_CLASS_3;
-		}
-		else if (gbps <= class1_gbps*8.f)
-		{
-			mGPUClass = GPU_CLASS_4;
-		}
-		else 
-		{
-			mGPUClass = GPU_CLASS_5;
-		}
+        if (gbps < 0.f)
+        { //couldn't bench, default to Low
+    #if LL_DARWIN
+        //GLVersion is misleading on OSX, just default to class 3 if we can't bench
+        LL_WARNS("RenderInit") << "Unable to get an accurate benchmark; defaulting to class 3" << LL_ENDL;
+        mGPUClass = GPU_CLASS_3;
+    #else
+            mGPUClass = GPU_CLASS_0;
+    #endif
+        }
+        else if (gbps <= class1_gbps)
+        {
+            mGPUClass = GPU_CLASS_1;
+        }
+        else if (gbps <= class1_gbps *2.f)
+        {
+            mGPUClass = GPU_CLASS_2;
+        }
+        else if (gbps <= class1_gbps*4.f)
+        {
+            mGPUClass = GPU_CLASS_3;
+        }
+        else if (gbps <= class1_gbps*8.f)
+        {
+            mGPUClass = GPU_CLASS_4;
+        }
+        else
+        {
+            mGPUClass = GPU_CLASS_5;
+        }
 
     #if LL_WINDOWS
         const F32Gigabytes MIN_PHYSICAL_MEMORY(2);
@@ -474,118 +474,118 @@ bool LLFeatureManager::loadGPUClass()
             mGPUClass = (EGPUClass)(mGPUClass - 1);
         }
     #endif //LL_WINDOWS
-	} //end if benchmark
-	else
-	{
-		//setting says don't benchmark MAINT-7558
+    } //end if benchmark
+    else
+    {
+        //setting says don't benchmark MAINT-7558
         LL_WARNS("RenderInit") << "Setting 'SkipBenchmark' is true; defaulting to class 1 (may be required for some GPUs)" << LL_ENDL;
-        
-		mGPUClass = GPU_CLASS_1;
-	}
 
-	// defaults
-	mGPUString = gGLManager.getRawGLString();
-	mGPUSupported = TRUE;
+        mGPUClass = GPU_CLASS_1;
+    }
+
+    // defaults
+    mGPUString = gGLManager.getRawGLString();
+    mGPUSupported = TRUE;
 
-	return true; // indicates that a gpu value was established
+    return true; // indicates that a gpu value was established
 }
 
 void LLFeatureManager::cleanupFeatureTables()
 {
-	std::for_each(mMaskList.begin(), mMaskList.end(), DeletePairedPointer());
-	mMaskList.clear();
+    std::for_each(mMaskList.begin(), mMaskList.end(), DeletePairedPointer());
+    mMaskList.clear();
 }
 
 void LLFeatureManager::initSingleton()
 {
-	// load the tables
-	loadFeatureTables();
+    // load the tables
+    loadFeatureTables();
 
-	// get the gpu class
-	loadGPUClass();
+    // get the gpu class
+    loadGPUClass();
 
-	// apply the base masks, so we know if anything is disabled
-	applyBaseMasks();
+    // apply the base masks, so we know if anything is disabled
+    applyBaseMasks();
 }
 
 void LLFeatureManager::applyRecommendedSettings()
 {
-	// apply saved settings
-	// cap the level at 2 (high)
-	U32 level = llmax(GPU_CLASS_0, llmin(mGPUClass, GPU_CLASS_5));
-
-	LL_INFOS("RenderInit") << "Applying Recommended Features for level " << level << LL_ENDL;
-
-	setGraphicsLevel(level, false);
-	gSavedSettings.setU32("RenderQualityPerformance", level);
-
-	// now apply the tweaks to draw distance
-	// these are double negatives, because feature masks only work by
-	// downgrading values, so i needed to make a true value go to false
-	// for certain cards, thus the awkward name, "Disregard..."
-	if(!gSavedSettings.getBOOL("Disregard96DefaultDrawDistance"))
-	{
-		gSavedSettings.setF32("RenderFarClip", 96.0f);
-	}
-	else if(!gSavedSettings.getBOOL("Disregard128DefaultDrawDistance"))
-	{
-		gSavedSettings.setF32("RenderFarClip", 128.0f);
-	}
+    // apply saved settings
+    // cap the level at 2 (high)
+    U32 level = llmax(GPU_CLASS_0, llmin(mGPUClass, GPU_CLASS_5));
+
+    LL_INFOS("RenderInit") << "Applying Recommended Features for level " << level << LL_ENDL;
+
+    setGraphicsLevel(level, false);
+    gSavedSettings.setU32("RenderQualityPerformance", level);
+
+    // now apply the tweaks to draw distance
+    // these are double negatives, because feature masks only work by
+    // downgrading values, so i needed to make a true value go to false
+    // for certain cards, thus the awkward name, "Disregard..."
+    if(!gSavedSettings.getBOOL("Disregard96DefaultDrawDistance"))
+    {
+        gSavedSettings.setF32("RenderFarClip", 96.0f);
+    }
+    else if(!gSavedSettings.getBOOL("Disregard128DefaultDrawDistance"))
+    {
+        gSavedSettings.setF32("RenderFarClip", 128.0f);
+    }
 }
 
 void LLFeatureManager::applyFeatures(bool skipFeatures)
 {
-	// see featuretable.txt / featuretable_linux.txt / featuretable_mac.txt
+    // see featuretable.txt / featuretable_linux.txt / featuretable_mac.txt
 
 #ifndef LL_RELEASE_FOR_DOWNLOAD
-	dump();
+    dump();
 #endif
 
-	// scroll through all of these and set their corresponding control value
-	for(feature_map_t::iterator mIt = mFeatures.begin(); 
-		mIt != mFeatures.end(); 
-		++mIt)
-	{
-		// skip features you want to skip
-		// do this for when you don't want to change certain settings
-		if(skipFeatures)
-		{
-			if(mSkippedFeatures.find(mIt->first) != mSkippedFeatures.end())
-			{
-				continue;
-			}
-		}
-
-		// get the control setting
-		LLControlVariable* ctrl = gSavedSettings.getControl(mIt->first);
-		if(ctrl == NULL)
-		{
-			LL_WARNS("RenderInit") << "AHHH! Control setting " << mIt->first << " does not exist!" << LL_ENDL;
-			continue;
-		}
-
-		// handle all the different types
-		if(ctrl->isType(TYPE_BOOLEAN))
-		{
-			gSavedSettings.setBOOL(mIt->first, (BOOL)getRecommendedValue(mIt->first));
-		}
-		else if (ctrl->isType(TYPE_S32))
-		{
-			gSavedSettings.setS32(mIt->first, (S32)getRecommendedValue(mIt->first));
-		}
-		else if (ctrl->isType(TYPE_U32))
-		{
-			gSavedSettings.setU32(mIt->first, (U32)getRecommendedValue(mIt->first));
-		}
-		else if (ctrl->isType(TYPE_F32))
-		{
-			gSavedSettings.setF32(mIt->first, (F32)getRecommendedValue(mIt->first));
-		}
-		else
-		{
-			LL_WARNS("RenderInit") << "AHHH! Control variable is not a numeric type!" << LL_ENDL;
-		}
-	}
+    // scroll through all of these and set their corresponding control value
+    for(feature_map_t::iterator mIt = mFeatures.begin();
+        mIt != mFeatures.end();
+        ++mIt)
+    {
+        // skip features you want to skip
+        // do this for when you don't want to change certain settings
+        if(skipFeatures)
+        {
+            if(mSkippedFeatures.find(mIt->first) != mSkippedFeatures.end())
+            {
+                continue;
+            }
+        }
+
+        // get the control setting
+        LLControlVariable* ctrl = gSavedSettings.getControl(mIt->first);
+        if(ctrl == NULL)
+        {
+            LL_WARNS("RenderInit") << "AHHH! Control setting " << mIt->first << " does not exist!" << LL_ENDL;
+            continue;
+        }
+
+        // handle all the different types
+        if(ctrl->isType(TYPE_BOOLEAN))
+        {
+            gSavedSettings.setBOOL(mIt->first, (BOOL)getRecommendedValue(mIt->first));
+        }
+        else if (ctrl->isType(TYPE_S32))
+        {
+            gSavedSettings.setS32(mIt->first, (S32)getRecommendedValue(mIt->first));
+        }
+        else if (ctrl->isType(TYPE_U32))
+        {
+            gSavedSettings.setU32(mIt->first, (U32)getRecommendedValue(mIt->first));
+        }
+        else if (ctrl->isType(TYPE_F32))
+        {
+            gSavedSettings.setF32(mIt->first, (F32)getRecommendedValue(mIt->first));
+        }
+        else
+        {
+            LL_WARNS("RenderInit") << "AHHH! Control variable is not a numeric type!" << LL_ENDL;
+        }
+    }
 }
 
 void LLFeatureManager::setGraphicsLevel(U32 level, bool skipFeatures)
@@ -608,69 +608,69 @@ void LLFeatureManager::setGraphicsLevel(U32 level, bool skipFeatures)
 
 void LLFeatureManager::applyBaseMasks()
 {
-	// reapply masks
-	mFeatures.clear();
-
-	LLFeatureList* maskp = findMask("all");
-	if(maskp == NULL)
-	{
-		LL_WARNS("RenderInit") << "AHH! No \"all\" in feature table!" << LL_ENDL;
-		return;
-	}
-
-	mFeatures = maskp->getFeatures();
-
-	// mask class
-	if (mGPUClass >= 0 && mGPUClass < 6)
-	{
-		const char* class_table[] =
-		{
-			"Class0",
-			"Class1",
-			"Class2",
-			"Class3",
-			"Class4",
-			"Class5",
-		};
-
-		LL_INFOS("RenderInit") << "Setting GPU Class to " << class_table[mGPUClass] << LL_ENDL;
-		maskFeatures(class_table[mGPUClass]);
-	}
-	else
-	{
-		LL_INFOS("RenderInit") << "Setting GPU Class to Unknown" << LL_ENDL;
-		maskFeatures("Unknown");
-	}
-
-	// now all those wacky ones
-	if (gGLManager.mIsNVIDIA)
-	{
-		maskFeatures("NVIDIA");
-	}
-	if (gGLManager.mIsAMD)
-	{
-		maskFeatures("AMD");
-	}
-	if (gGLManager.mIsIntel)
-	{
-		maskFeatures("Intel");
-	}
-	if (gGLManager.mGLVersion < 3.f)
-	{
-		maskFeatures("OpenGLPre30");
-	}
-	if (gGLManager.mNumTextureImageUnits <= 8)
-	{
-		maskFeatures("TexUnit8orLess");
-	}
-	if (gGLManager.mNumTextureImageUnits <= 16)
-	{
-		maskFeatures("TexUnit16orLess");
-	}
-	if (gGLManager.mVRAM > 512)
-	{
-		maskFeatures("VRAMGT512");
-	}
+    // reapply masks
+    mFeatures.clear();
+
+    LLFeatureList* maskp = findMask("all");
+    if(maskp == NULL)
+    {
+        LL_WARNS("RenderInit") << "AHH! No \"all\" in feature table!" << LL_ENDL;
+        return;
+    }
+
+    mFeatures = maskp->getFeatures();
+
+    // mask class
+    if (mGPUClass >= 0 && mGPUClass < 6)
+    {
+        const char* class_table[] =
+        {
+            "Class0",
+            "Class1",
+            "Class2",
+            "Class3",
+            "Class4",
+            "Class5",
+        };
+
+        LL_INFOS("RenderInit") << "Setting GPU Class to " << class_table[mGPUClass] << LL_ENDL;
+        maskFeatures(class_table[mGPUClass]);
+    }
+    else
+    {
+        LL_INFOS("RenderInit") << "Setting GPU Class to Unknown" << LL_ENDL;
+        maskFeatures("Unknown");
+    }
+
+    // now all those wacky ones
+    if (gGLManager.mIsNVIDIA)
+    {
+        maskFeatures("NVIDIA");
+    }
+    if (gGLManager.mIsAMD)
+    {
+        maskFeatures("AMD");
+    }
+    if (gGLManager.mIsIntel)
+    {
+        maskFeatures("Intel");
+    }
+    if (gGLManager.mGLVersion < 3.f)
+    {
+        maskFeatures("OpenGLPre30");
+    }
+    if (gGLManager.mNumTextureImageUnits <= 8)
+    {
+        maskFeatures("TexUnit8orLess");
+    }
+    if (gGLManager.mNumTextureImageUnits <= 16)
+    {
+        maskFeatures("TexUnit16orLess");
+    }
+    if (gGLManager.mVRAM > 512)
+    {
+        maskFeatures("VRAMGT512");
+    }
     if (gGLManager.mVRAM < 2048)
     {
         maskFeatures("VRAMLT2GB");
@@ -679,84 +679,84 @@ void LLFeatureManager::applyBaseMasks()
     {
         maskFeatures("GL3");
     }
-	if (2.f > gGLManager.mMaxAnisotropy)
-	{
-		maskFeatures("AnisotropicMissing");
-	}
-
-	// now mask by gpu string
-	// Replaces ' ' with '_' in mGPUString to deal with inability for parser to handle spaces
-	std::string gpustr = mGPUString;
-	for (std::string::iterator iter = gpustr.begin(); iter != gpustr.end(); ++iter)
-	{
-		if (*iter == ' ')
-		{
-			*iter = '_';
-		}
-	}
-
-	//LL_INFOS() << "Masking features from gpu table match: " << gpustr << LL_ENDL;
-	maskFeatures(gpustr);
-
-	if (isSafe())
-	{
-		maskFeatures("safe");
-	}
+    if (2.f > gGLManager.mMaxAnisotropy)
+    {
+        maskFeatures("AnisotropicMissing");
+    }
+
+    // now mask by gpu string
+    // Replaces ' ' with '_' in mGPUString to deal with inability for parser to handle spaces
+    std::string gpustr = mGPUString;
+    for (std::string::iterator iter = gpustr.begin(); iter != gpustr.end(); ++iter)
+    {
+        if (*iter == ' ')
+        {
+            *iter = '_';
+        }
+    }
+
+    //LL_INFOS() << "Masking features from gpu table match: " << gpustr << LL_ENDL;
+    maskFeatures(gpustr);
+
+    if (isSafe())
+    {
+        maskFeatures("safe");
+    }
 }
 
 LLSD LLFeatureManager::getRecommendedSettingsMap()
 {
-	// Create the map and fill it with the hardware recommended settings.
-	// It's needed to create an initial Default graphics preset (MAINT-6435).
-	// The process is similar to the one LLFeatureManager::applyRecommendedSettings() does.
-
-	LLSD map(LLSD::emptyMap());
-
-	U32 level = llmax(GPU_CLASS_0, llmin(mGPUClass, GPU_CLASS_5));
-	LL_INFOS("RenderInit") << "Getting the map of recommended settings for level " << level << LL_ENDL;
-
-	std::string features(isValidGraphicsLevel(level) ? getNameForGraphicsLevel(level) : "Low");
-
-	maskFeatures(features);
-
-	LLControlVariable* ctrl = gSavedSettings.getControl("RenderQualityPerformance"); // include the quality value for correct preset loading   
-	map["RenderQualityPerformance"]["Value"] = (LLSD::Integer)level;
-	map["RenderQualityPerformance"]["Comment"] = ctrl->getComment();;
-	map["RenderQualityPerformance"]["Persist"] = 1;
-	map["RenderQualityPerformance"]["Type"] = LLControlGroup::typeEnumToString(ctrl->type());
-
-
-
-	for (feature_map_t::iterator mIt = mFeatures.begin(); mIt != mFeatures.end(); ++mIt)
-	{
-		LLControlVariable* ctrl = gSavedSettings.getControl(mIt->first);
-		if (ctrl == NULL)
-		{
-			LL_WARNS("RenderInit") << "AHHH! Control setting " << mIt->first << " does not exist!" << LL_ENDL;
-			continue;
-		}
-
-		if (ctrl->isType(TYPE_BOOLEAN))
-		{
-			map[mIt->first]["Value"] = (LLSD::Boolean)getRecommendedValue(mIt->first);
-		}
-		else if (ctrl->isType(TYPE_S32) || ctrl->isType(TYPE_U32))
-		{
-			map[mIt->first]["Value"] = (LLSD::Integer)getRecommendedValue(mIt->first);
-		}
-		else if (ctrl->isType(TYPE_F32))
-		{
-			map[mIt->first]["Value"] = (LLSD::Real)getRecommendedValue(mIt->first);
-		}
-		else
-		{
-			LL_WARNS("RenderInit") << "AHHH! Control variable is not a numeric type!" << LL_ENDL;
-			continue;
-		}
-		map[mIt->first]["Comment"] = ctrl->getComment();;
-		map[mIt->first]["Persist"] = 1;
-		map[mIt->first]["Type"] = LLControlGroup::typeEnumToString(ctrl->type());
-	}
-	
-	return map;
+    // Create the map and fill it with the hardware recommended settings.
+    // It's needed to create an initial Default graphics preset (MAINT-6435).
+    // The process is similar to the one LLFeatureManager::applyRecommendedSettings() does.
+
+    LLSD map(LLSD::emptyMap());
+
+    U32 level = llmax(GPU_CLASS_0, llmin(mGPUClass, GPU_CLASS_5));
+    LL_INFOS("RenderInit") << "Getting the map of recommended settings for level " << level << LL_ENDL;
+
+    std::string features(isValidGraphicsLevel(level) ? getNameForGraphicsLevel(level) : "Low");
+
+    maskFeatures(features);
+
+    LLControlVariable* ctrl = gSavedSettings.getControl("RenderQualityPerformance"); // include the quality value for correct preset loading
+    map["RenderQualityPerformance"]["Value"] = (LLSD::Integer)level;
+    map["RenderQualityPerformance"]["Comment"] = ctrl->getComment();;
+    map["RenderQualityPerformance"]["Persist"] = 1;
+    map["RenderQualityPerformance"]["Type"] = LLControlGroup::typeEnumToString(ctrl->type());
+
+
+
+    for (feature_map_t::iterator mIt = mFeatures.begin(); mIt != mFeatures.end(); ++mIt)
+    {
+        LLControlVariable* ctrl = gSavedSettings.getControl(mIt->first);
+        if (ctrl == NULL)
+        {
+            LL_WARNS("RenderInit") << "AHHH! Control setting " << mIt->first << " does not exist!" << LL_ENDL;
+            continue;
+        }
+
+        if (ctrl->isType(TYPE_BOOLEAN))
+        {
+            map[mIt->first]["Value"] = (LLSD::Boolean)getRecommendedValue(mIt->first);
+        }
+        else if (ctrl->isType(TYPE_S32) || ctrl->isType(TYPE_U32))
+        {
+            map[mIt->first]["Value"] = (LLSD::Integer)getRecommendedValue(mIt->first);
+        }
+        else if (ctrl->isType(TYPE_F32))
+        {
+            map[mIt->first]["Value"] = (LLSD::Real)getRecommendedValue(mIt->first);
+        }
+        else
+        {
+            LL_WARNS("RenderInit") << "AHHH! Control variable is not a numeric type!" << LL_ENDL;
+            continue;
+        }
+        map[mIt->first]["Comment"] = ctrl->getComment();;
+        map[mIt->first]["Persist"] = 1;
+        map[mIt->first]["Type"] = LLControlGroup::typeEnumToString(ctrl->type());
+    }
+
+    return map;
 }
diff --git a/indra/newview/llfetchedgltfmaterial.cpp b/indra/newview/llfetchedgltfmaterial.cpp
index 1dd1dbabbefd8ea9577e6b9ff8e976faac1b468b..5296f401194b41816b4be3a5fffb70fcdf7faad8 100644
--- a/indra/newview/llfetchedgltfmaterial.cpp
+++ b/indra/newview/llfetchedgltfmaterial.cpp
@@ -77,16 +77,7 @@ void LLFetchedGLTFMaterial::bind(LLViewerTexture* media_tex)
     {
         if (mAlphaMode == LLGLTFMaterial::ALPHA_MODE_MASK)
         {
-            // dividing the alpha cutoff by transparency here allows the shader to compare against
-            // the alpha value of the texture without needing the transparency value
-            if (mBaseColor.mV[3] > 0.f)
-            {
-                min_alpha = mAlphaCutoff / mBaseColor.mV[3];
-            }
-            else
-            {
-                min_alpha = 1024.f;
-            }
+            min_alpha = mAlphaCutoff;
         }
         shader->uniform1f(LLShaderMgr::MINIMUM_ALPHA, min_alpha);
     }
diff --git a/indra/newview/llfilepicker.cpp b/indra/newview/llfilepicker.cpp
index f10ff03b7f0e9ddc9f8a7d258a4a3c9a601ea6b1..cef294636154486f74d20a5a35a224bfc0b9102c 100644
--- a/indra/newview/llfilepicker.cpp
+++ b/indra/newview/llfilepicker.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llfilepicker.cpp
  * @brief OS-specific file picker
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -34,7 +34,7 @@
 #include "llframetimer.h"
 #include "lltrans.h"
 #include "llviewercontrol.h"
-#include "llwindow.h"	// beforeDialog()
+#include "llwindow.h"   // beforeDialog()
 
 #if LL_SDL
 #include "llwindowsdl.h"
@@ -82,206 +82,206 @@ LLFilePicker LLFilePicker::sInstance;
 // Implementation
 //
 LLFilePicker::LLFilePicker()
-	: mCurrentFile(0),
-	  mLocked(false)
+    : mCurrentFile(0),
+      mLocked(false)
 
 {
-	reset();
+    reset();
 
 #if LL_WINDOWS && !LL_NFD
-	mOFN.lStructSize = sizeof(OPENFILENAMEW);
-	mOFN.hwndOwner = NULL;  // Set later
-	mOFN.hInstance = NULL;
-	mOFN.lpstrCustomFilter = NULL;
-	mOFN.nMaxCustFilter = 0;
-	mOFN.lpstrFile = NULL;							// set in open and close
-	mOFN.nMaxFile = LL_MAX_PATH;
-	mOFN.lpstrFileTitle = NULL;
-	mOFN.nMaxFileTitle = 0;
-	mOFN.lpstrInitialDir = NULL;
-	mOFN.lpstrTitle = NULL;
-	mOFN.Flags = 0;									// set in open and close
-	mOFN.nFileOffset = 0;
-	mOFN.nFileExtension = 0;
-	mOFN.lpstrDefExt = NULL;
-	mOFN.lCustData = 0L;
-	mOFN.lpfnHook = NULL;
-	mOFN.lpTemplateName = NULL;
-	mFilesW[0] = '\0';
+    mOFN.lStructSize = sizeof(OPENFILENAMEW);
+    mOFN.hwndOwner = NULL;  // Set later
+    mOFN.hInstance = NULL;
+    mOFN.lpstrCustomFilter = NULL;
+    mOFN.nMaxCustFilter = 0;
+    mOFN.lpstrFile = NULL;                          // set in open and close
+    mOFN.nMaxFile = LL_MAX_PATH;
+    mOFN.lpstrFileTitle = NULL;
+    mOFN.nMaxFileTitle = 0;
+    mOFN.lpstrInitialDir = NULL;
+    mOFN.lpstrTitle = NULL;
+    mOFN.Flags = 0;                                 // set in open and close
+    mOFN.nFileOffset = 0;
+    mOFN.nFileExtension = 0;
+    mOFN.lpstrDefExt = NULL;
+    mOFN.lCustData = 0L;
+    mOFN.lpfnHook = NULL;
+    mOFN.lpTemplateName = NULL;
+    mFilesW[0] = '\0';
 #elif LL_DARWIN
-	mPickOptions = 0;
+    mPickOptions = 0;
 #endif
 
 }
 
 LLFilePicker::~LLFilePicker()
 {
-	// nothing
+    // nothing
 }
 
-// utility function to check if access to local file system via file browser 
+// utility function to check if access to local file system via file browser
 // is enabled and if not, tidy up and indicate we're not allowed to do this.
 bool LLFilePicker::check_local_file_access_enabled()
 {
-	// if local file browsing is turned off, return without opening dialog
-	bool local_file_system_browsing_enabled = gSavedSettings.getBOOL("LocalFileSystemBrowsingEnabled");
-	if ( ! local_file_system_browsing_enabled )
-	{
-		mFiles.clear();
-		return false;
-	}
-
-	return true;
+    // if local file browsing is turned off, return without opening dialog
+    bool local_file_system_browsing_enabled = gSavedSettings.getBOOL("LocalFileSystemBrowsingEnabled");
+    if ( ! local_file_system_browsing_enabled )
+    {
+        mFiles.clear();
+        return false;
+    }
+
+    return true;
 }
 
 const std::string LLFilePicker::getFirstFile()
 {
-	mCurrentFile = 0;
-	return getNextFile();
+    mCurrentFile = 0;
+    return getNextFile();
 }
 
 const std::string LLFilePicker::getNextFile()
 {
-	if (mCurrentFile >= getFileCount())
-	{
-		mLocked = false;
-		return std::string();
-	}
-	else
-	{
-		return mFiles[mCurrentFile++];
-	}
+    if (mCurrentFile >= getFileCount())
+    {
+        mLocked = false;
+        return std::string();
+    }
+    else
+    {
+        return mFiles[mCurrentFile++];
+    }
 }
 
 const std::string LLFilePicker::getCurFile()
 {
-	if (mCurrentFile >= getFileCount())
-	{
-		mLocked = false;
-		return std::string();
-	}
-	else
-	{
-		return mFiles[mCurrentFile];
-	}
+    if (mCurrentFile >= getFileCount())
+    {
+        mLocked = false;
+        return std::string();
+    }
+    else
+    {
+        return mFiles[mCurrentFile];
+    }
 }
 
 void LLFilePicker::reset()
 {
-	mLocked = false;
-	mFiles.clear();
-	mCurrentFile = 0;
+    mLocked = false;
+    mFiles.clear();
+    mCurrentFile = 0;
 }
 
 #if LL_NFD
 std::vector<nfdfilteritem_t> LLFilePicker::setupFilter(ELoadFilter filter)
 {
-	std::vector<nfdfilteritem_t> filter_vec;
-	switch (filter)
-	{
+    std::vector<nfdfilteritem_t> filter_vec;
+    switch (filter)
+    {
     case FFLOAD_ALL:
-    	break;
+        break;
     case FFLOAD_EXE:
 #if LL_WINDOWS
-   		filter_vec.emplace_back(nfdfilteritem_t{"Executables", "exe"});
+        filter_vec.emplace_back(nfdfilteritem_t{"Executables", "exe"});
 #endif
-		break;
-	case FFLOAD_WAV:
-		filter_vec.emplace_back(nfdfilteritem_t{"Sounds", "wav"});
-		break;
-	case FFLOAD_IMAGE:
-		filter_vec.emplace_back(nfdfilteritem_t{"Images", "tga,bmp,jpg,jpeg,png,webp"});
-		break;
-	case FFLOAD_ANIM:
-		filter_vec.emplace_back(nfdfilteritem_t{"Animations", "bvh,anim"});
-		break;
+        break;
+    case FFLOAD_WAV:
+        filter_vec.emplace_back(nfdfilteritem_t{"Sounds", "wav"});
+        break;
+    case FFLOAD_IMAGE:
+        filter_vec.emplace_back(nfdfilteritem_t{"Images", "tga,bmp,jpg,jpeg,png,webp"});
+        break;
+    case FFLOAD_ANIM:
+        filter_vec.emplace_back(nfdfilteritem_t{"Animations", "bvh,anim"});
+        break;
     case FFLOAD_GLTF:
-		filter_vec.emplace_back(nfdfilteritem_t{"GLTF Files", "gltf,glb"});
-        break;
-	case FFLOAD_COLLADA:
-		filter_vec.emplace_back(nfdfilteritem_t{"Scene", "dae"});
-		break;
-	case FFLOAD_XML:
-		filter_vec.emplace_back(nfdfilteritem_t{"XML files", "xml"});
-		break;
-	case FFLOAD_SLOBJECT:
-		filter_vec.emplace_back(nfdfilteritem_t{"Objects", "slobject"});
-		break;
-	case FFLOAD_RAW:
-		filter_vec.emplace_back(nfdfilteritem_t{"RAW files", "raw"});
-		break;
-	case FFLOAD_MODEL:
-		filter_vec.emplace_back(nfdfilteritem_t{"Model files", "dae"});
-		break;
+        filter_vec.emplace_back(nfdfilteritem_t{"GLTF Files", "gltf,glb"});
+        break;
+    case FFLOAD_COLLADA:
+        filter_vec.emplace_back(nfdfilteritem_t{"Scene", "dae"});
+        break;
+    case FFLOAD_XML:
+        filter_vec.emplace_back(nfdfilteritem_t{"XML files", "xml"});
+        break;
+    case FFLOAD_SLOBJECT:
+        filter_vec.emplace_back(nfdfilteritem_t{"Objects", "slobject"});
+        break;
+    case FFLOAD_RAW:
+        filter_vec.emplace_back(nfdfilteritem_t{"RAW files", "raw"});
+        break;
+    case FFLOAD_MODEL:
+        filter_vec.emplace_back(nfdfilteritem_t{"Model files", "dae"});
+        break;
     case FFLOAD_MATERIAL:
-		filter_vec.emplace_back(nfdfilteritem_t{"GLTF Files", "gltf,glb"});
+        filter_vec.emplace_back(nfdfilteritem_t{"GLTF Files", "gltf,glb"});
         break;
     case FFLOAD_MATERIAL_TEXTURE:
-		filter_vec.emplace_back(nfdfilteritem_t{"GLTF Import", "gltf,glb,tga,bmp,jpg,jpeg,png"});
-		filter_vec.emplace_back(nfdfilteritem_t{"GLTF Files", "gltf,glb"});
-		filter_vec.emplace_back(nfdfilteritem_t{"Images", "tga,bmp,jpg,jpeg,png,webp"});
-        break;
-	case FFLOAD_SCRIPT:
-		filter_vec.emplace_back(nfdfilteritem_t{"Script files", "lsl"});
-		break;
-	case FFLOAD_DICTIONARY:
-		filter_vec.emplace_back(nfdfilteritem_t{"Dictionary files", "dic,xcu"});
-		break;
-	case FFLOAD_ZIP:
-		filter_vec.emplace_back(nfdfilteritem_t{"ZIP files", "zip"});
-	default:
-		break;
-	}
-	return filter_vec;
+        filter_vec.emplace_back(nfdfilteritem_t{"GLTF Import", "gltf,glb,tga,bmp,jpg,jpeg,png"});
+        filter_vec.emplace_back(nfdfilteritem_t{"GLTF Files", "gltf,glb"});
+        filter_vec.emplace_back(nfdfilteritem_t{"Images", "tga,bmp,jpg,jpeg,png,webp"});
+        break;
+    case FFLOAD_SCRIPT:
+        filter_vec.emplace_back(nfdfilteritem_t{"Script files", "lsl"});
+        break;
+    case FFLOAD_DICTIONARY:
+        filter_vec.emplace_back(nfdfilteritem_t{"Dictionary files", "dic,xcu"});
+        break;
+    case FFLOAD_ZIP:
+        filter_vec.emplace_back(nfdfilteritem_t{"ZIP files", "zip"});
+    default:
+        break;
+    }
+    return filter_vec;
 }
 
 BOOL LLFilePicker::getOpenFile(ELoadFilter filter, bool blocking)
 {
-	if( mLocked )
-	{
-		return FALSE;
-	}
-	BOOL success = FALSE;
-
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return FALSE;
-	}
-
-	// initialize NFD
+    if( mLocked )
+    {
+        return FALSE;
+    }
+    BOOL success = FALSE;
+
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return FALSE;
+    }
+
+    // initialize NFD
     NFD::Guard nfdGuard;
 
-	// auto-freeing memory
+    // auto-freeing memory
     NFD::UniquePath outPath;
 
     // prepare filters for the dialog
     auto filterItem = setupFilter(filter);
-	//
-	if (blocking)
-	{
-		// Modal, so pause agent
-		send_agent_pause();
-	}
-
-	reset();
-	
-	// show the dialog
+    //
+    if (blocking)
+    {
+        // Modal, so pause agent
+        send_agent_pause();
+    }
+
+    reset();
+
+    // show the dialog
     nfdresult_t result = NFD::OpenDialog(outPath, filterItem.data(), filterItem.size());
-    if (result == NFD_OKAY) 
-	{
-		mFiles.push_back(outPath.get());
-		success = TRUE;
-    }
-
-	if (blocking)
-	{
-		send_agent_resume();
-		// Account for the fact that the app has been stalled.
-		LLFrameTimer::updateFrameTime();
-	}
-	
-	return success;
+    if (result == NFD_OKAY)
+    {
+        mFiles.push_back(outPath.get());
+        success = TRUE;
+    }
+
+    if (blocking)
+    {
+        send_agent_resume();
+        // Account for the fact that the app has been stalled.
+        LLFrameTimer::updateFrameTime();
+    }
+
+    return success;
 }
 
 BOOL LLFilePicker::getOpenFileModeless(ELoadFilter filter,
@@ -304,71 +304,71 @@ BOOL LLFilePicker::getOpenFileModeless(ELoadFilter filter,
 
 BOOL LLFilePicker::getMultipleOpenFiles(ELoadFilter filter, bool blocking)
 {
-	if( mLocked )
-	{
-		return FALSE;
-	}
-	BOOL success = FALSE;
-
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return FALSE;
-	}
-
-	// initialize NFD
+    if( mLocked )
+    {
+        return FALSE;
+    }
+    BOOL success = FALSE;
+
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return FALSE;
+    }
+
+    // initialize NFD
     NFD::Guard nfdGuard;
 
-	auto filterItem = setupFilter(filter);
+    auto filterItem = setupFilter(filter);
 
-	reset();
+    reset();
 
-	if (blocking)
-	{
-		// Modal, so pause agent
-		send_agent_pause();
-	}
+    if (blocking)
+    {
+        // Modal, so pause agent
+        send_agent_pause();
+    }
 
     // auto-freeing memory
     NFD::UniquePathSet outPaths;
 
     // show the dialog
     nfdresult_t result = NFD::OpenDialogMultiple(outPaths, filterItem.data(), filterItem.size());
-    if (result == NFD_OKAY) 
-	{
+    if (result == NFD_OKAY)
+    {
         LL_INFOS() << "Success!" << LL_ENDL;
 
         nfdpathsetsize_t numPaths;
         NFD::PathSet::Count(outPaths, numPaths);
 
         nfdpathsetsize_t i;
-        for (i = 0; i < numPaths; ++i) 
-		{
+        for (i = 0; i < numPaths; ++i)
+        {
             NFD::UniquePathSetPath path;
             NFD::PathSet::GetPath(outPaths, i, path);
-			mFiles.push_back(path.get());
+            mFiles.push_back(path.get());
             LL_INFOS() << "Path " << i << ": " << path.get() << LL_ENDL;
         }
-		success = TRUE;
-    } 
-	else if (result == NFD_CANCEL) 
-	{
+        success = TRUE;
+    }
+    else if (result == NFD_CANCEL)
+    {
         LL_INFOS() << "User pressed cancel." << LL_ENDL;
-    } 
-	else 
-	{
+    }
+    else
+    {
         LL_INFOS() << "Error: " << NFD::GetError() << LL_ENDL;
     }
 
-	if (blocking)
-	{
-		send_agent_resume();
+    if (blocking)
+    {
+        send_agent_resume();
 
-		// Account for the fact that the app has been stalled.
-		LLFrameTimer::updateFrameTime();
-	}
+        // Account for the fact that the app has been stalled.
+        LLFrameTimer::updateFrameTime();
+    }
 
-	return success;
+    return success;
 }
 
 BOOL LLFilePicker::getMultipleOpenFilesModeless(ELoadFilter filter,
@@ -392,172 +392,172 @@ BOOL LLFilePicker::getMultipleOpenFilesModeless(ELoadFilter filter,
 
 BOOL LLFilePicker::getSaveFile(ESaveFilter filter, const std::string& filename, bool blocking)
 {
-	if( mLocked )
-	{
-		return FALSE;
-	}
-	BOOL success = FALSE;
-
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return FALSE;
-	}
+    if( mLocked )
+    {
+        return FALSE;
+    }
+    BOOL success = FALSE;
+
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return FALSE;
+    }
 
     // initialize NFD
     NFD::Guard nfdGuard;
 
-	std::vector<nfdfilteritem_t> filter_vec;
-	std::string saved_filename = filename;
-	switch( filter )
-	{
-	case FFSAVE_ALL:
-		filter_vec.emplace_back(nfdfilteritem_t{"WAV Sounds", "wav"});
-		filter_vec.emplace_back(nfdfilteritem_t{"Targa, Bitmap Images", "tga,bmp"});
-		break;
-	case FFSAVE_WAV:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.wav";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"WAV Sounds", "wav"});
-		break;
-	case FFSAVE_TGA:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.tga";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"Targa Images", "tga"});
-		break;
-	case FFSAVE_BMP:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.bmp";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"Bitmap Images", "bmp"});
-		break;
-	case FFSAVE_PNG:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.png";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"PNG Images", "png"});
-		break;
-	case FFSAVE_WEBP:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.webp";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"WebP Images", "webp"});
-		break;
-	case FFSAVE_TGAPNGWEBP:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.png";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"PNG Images", "png"});
-		filter_vec.emplace_back(nfdfilteritem_t{"Targa Images", "tga"});
-		filter_vec.emplace_back(nfdfilteritem_t{"Jpeg Images", "jpg,jpeg"});
-		filter_vec.emplace_back(nfdfilteritem_t{"Jpeg2000 Images", "j2c"});
-		filter_vec.emplace_back(nfdfilteritem_t{"Bitmap Images", "bmp"});
-		filter_vec.emplace_back(nfdfilteritem_t{"WebP Images", "webp"});
-		break;
-	case FFSAVE_JPEG:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.jpeg";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"Jpeg Images", "jpg,jpeg"});
-		break;
-	case FFSAVE_AVI:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.avi";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"AVI Movie File", "avi"});
-		break;
-	case FFSAVE_ANIM:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.xaf";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"XAF Anim File", "xaf"});
-		break;
-	case FFSAVE_CSV:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.csv";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"Comma seperated values", "csv"});
-		break;
-	case FFSAVE_XML:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.xml";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"XML File", "xml"});
-		break;
-	case FFSAVE_COLLADA:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.collada";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"COLLADA File", "collada"});
-		break;
-	case FFSAVE_RAW:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.raw";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"RAW files", "raw"});
-		break;
-	case FFSAVE_J2C:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.j2c";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"Compressed Images", "j2c"});
-		break;
-	case FFSAVE_SCRIPT:
-		if (filename.empty())
-		{
-			saved_filename = "untitled.lsl";
-		}
-		filter_vec.emplace_back(nfdfilteritem_t{"LSL Files", "lsl"});
-		break;
-	default:
-		return FALSE;
-	}
-
-	reset();
-
-	if (blocking)
-	{
-		// Modal, so pause agent
-		send_agent_pause();
-	}
-
-	{
-		NFD::UniquePath savePath;
-
-		// show the dialog
-		nfdresult_t result = NFD::SaveDialog(savePath, filter_vec.data(), filter_vec.size(), NULL, saved_filename.c_str());
-		if (result == NFD_OKAY) {
-			mFiles.push_back(savePath.get());
-			success = TRUE;
-		}
-		gKeyboard->resetKeys();
-	}
-
-	if (blocking)
-	{
-		send_agent_resume();
-
-		// Account for the fact that the app has been stalled.
-		LLFrameTimer::updateFrameTime();
-	}
-
-	return success;
+    std::vector<nfdfilteritem_t> filter_vec;
+    std::string saved_filename = filename;
+    switch( filter )
+    {
+    case FFSAVE_ALL:
+        filter_vec.emplace_back(nfdfilteritem_t{"WAV Sounds", "wav"});
+        filter_vec.emplace_back(nfdfilteritem_t{"Targa, Bitmap Images", "tga,bmp"});
+        break;
+    case FFSAVE_WAV:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.wav";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"WAV Sounds", "wav"});
+        break;
+    case FFSAVE_TGA:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.tga";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"Targa Images", "tga"});
+        break;
+    case FFSAVE_BMP:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.bmp";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"Bitmap Images", "bmp"});
+        break;
+    case FFSAVE_PNG:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.png";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"PNG Images", "png"});
+        break;
+    case FFSAVE_WEBP:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.webp";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"WebP Images", "webp"});
+        break;
+    case FFSAVE_TGAPNGWEBP:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.png";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"PNG Images", "png"});
+        filter_vec.emplace_back(nfdfilteritem_t{"Targa Images", "tga"});
+        filter_vec.emplace_back(nfdfilteritem_t{"Jpeg Images", "jpg,jpeg"});
+        filter_vec.emplace_back(nfdfilteritem_t{"Jpeg2000 Images", "j2c"});
+        filter_vec.emplace_back(nfdfilteritem_t{"Bitmap Images", "bmp"});
+        filter_vec.emplace_back(nfdfilteritem_t{"WebP Images", "webp"});
+        break;
+    case FFSAVE_JPEG:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.jpeg";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"Jpeg Images", "jpg,jpeg"});
+        break;
+    case FFSAVE_AVI:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.avi";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"AVI Movie File", "avi"});
+        break;
+    case FFSAVE_ANIM:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.xaf";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"XAF Anim File", "xaf"});
+        break;
+    case FFSAVE_CSV:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.csv";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"Comma seperated values", "csv"});
+        break;
+    case FFSAVE_XML:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.xml";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"XML File", "xml"});
+        break;
+    case FFSAVE_COLLADA:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.collada";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"COLLADA File", "collada"});
+        break;
+    case FFSAVE_RAW:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.raw";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"RAW files", "raw"});
+        break;
+    case FFSAVE_J2C:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.j2c";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"Compressed Images", "j2c"});
+        break;
+    case FFSAVE_SCRIPT:
+        if (filename.empty())
+        {
+            saved_filename = "untitled.lsl";
+        }
+        filter_vec.emplace_back(nfdfilteritem_t{"LSL Files", "lsl"});
+        break;
+    default:
+        return FALSE;
+    }
+
+    reset();
+
+    if (blocking)
+    {
+        // Modal, so pause agent
+        send_agent_pause();
+    }
+
+    {
+        NFD::UniquePath savePath;
+
+        // show the dialog
+        nfdresult_t result = NFD::SaveDialog(savePath, filter_vec.data(), filter_vec.size(), NULL, saved_filename.c_str());
+        if (result == NFD_OKAY) {
+            mFiles.push_back(savePath.get());
+            success = TRUE;
+        }
+        gKeyboard->resetKeys();
+    }
+
+    if (blocking)
+    {
+        send_agent_resume();
+
+        // Account for the fact that the app has been stalled.
+        LLFrameTimer::updateFrameTime();
+    }
+
+    return success;
 }
 
 BOOL LLFilePicker::getSaveFileModeless(ESaveFilter filter,
@@ -582,57 +582,57 @@ BOOL LLFilePicker::getSaveFileModeless(ESaveFilter filter,
 
 BOOL LLFilePicker::setupFilter(ELoadFilter filter)
 {
-	BOOL res = TRUE;
-	switch (filter)
-	{
+    BOOL res = TRUE;
+    switch (filter)
+    {
     case FFLOAD_ALL:
-		mOFN.lpstrFilter = L"All Files (*.*)\0*.*\0" \
-		SOUND_FILTER \
-		IMAGE_FILTER \
-		ANIM_FILTER \
-		MATERIAL_FILTER \
-		L"\0";
-		break;
+        mOFN.lpstrFilter = L"All Files (*.*)\0*.*\0" \
+        SOUND_FILTER \
+        IMAGE_FILTER \
+        ANIM_FILTER \
+        MATERIAL_FILTER \
+        L"\0";
+        break;
     case FFLOAD_EXE:
-		mOFN.lpstrFilter = EXECUTABLE_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_WAV:
-		mOFN.lpstrFilter = SOUND_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_IMAGE:
-		mOFN.lpstrFilter = IMAGE_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_ANIM:
-		mOFN.lpstrFilter = ANIM_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_GLTF:
-		mOFN.lpstrFilter = GLTF_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_COLLADA:
-		mOFN.lpstrFilter = COLLADA_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_XML:
-		mOFN.lpstrFilter = XML_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_SLOBJECT:
-		mOFN.lpstrFilter = SLOBJECT_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_RAW:
-		mOFN.lpstrFilter = RAW_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_MODEL:
-		mOFN.lpstrFilter = MODEL_FILTER \
-			L"\0";
-		break;
+        mOFN.lpstrFilter = EXECUTABLE_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_WAV:
+        mOFN.lpstrFilter = SOUND_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_IMAGE:
+        mOFN.lpstrFilter = IMAGE_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_ANIM:
+        mOFN.lpstrFilter = ANIM_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_GLTF:
+        mOFN.lpstrFilter = GLTF_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_COLLADA:
+        mOFN.lpstrFilter = COLLADA_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_XML:
+        mOFN.lpstrFilter = XML_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_SLOBJECT:
+        mOFN.lpstrFilter = SLOBJECT_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_RAW:
+        mOFN.lpstrFilter = RAW_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_MODEL:
+        mOFN.lpstrFilter = MODEL_FILTER \
+            L"\0";
+        break;
     case FFLOAD_MATERIAL:
         mOFN.lpstrFilter = MATERIAL_FILTER \
             L"\0";
@@ -647,74 +647,74 @@ BOOL LLFilePicker::setupFilter(ELoadFilter filter)
         mOFN.lpstrFilter = HDRI_FILTER \
             L"\0";
         break;
-	case FFLOAD_SCRIPT:
-		mOFN.lpstrFilter = SCRIPT_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_DICTIONARY:
-		mOFN.lpstrFilter = DICTIONARY_FILTER \
-			L"\0";
-		break;
-	case FFLOAD_ZIP:
-		mOFN.lpstrFilter = ZIP_FILTER \
-			L"\0";
-		break;
-	default:
-		res = FALSE;
-		break;
-	}
-	return res;
+    case FFLOAD_SCRIPT:
+        mOFN.lpstrFilter = SCRIPT_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_DICTIONARY:
+        mOFN.lpstrFilter = DICTIONARY_FILTER \
+            L"\0";
+        break;
+    case FFLOAD_ZIP:
+        mOFN.lpstrFilter = ZIP_FILTER \
+            L"\0";
+        break;
+    default:
+        res = FALSE;
+        break;
+    }
+    return res;
 }
 
 BOOL LLFilePicker::getOpenFile(ELoadFilter filter, bool blocking)
 {
-	if( mLocked )
-	{
-		return FALSE;
-	}
-	BOOL success = FALSE;
-
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return FALSE;
-	}
-
-	// don't provide default file selection
-	mFilesW[0] = '\0';
-
-	mOFN.hwndOwner = (HWND)gViewerWindow->getPlatformWindow();
-	mOFN.lpstrFile = mFilesW;
-	mOFN.nMaxFile = SINGLE_FILENAME_BUFFER_SIZE;
-	mOFN.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR ;
-	mOFN.nFilterIndex = 1;
-
-	setupFilter(filter);
-	
-	if (blocking)
-	{
-		// Modal, so pause agent
-		send_agent_pause();
-	}
-
-	reset();
-	
-	// NOTA BENE: hitting the file dialog triggers a window focus event, destroying the selection manager!!
-	success = GetOpenFileName(&mOFN);
-	if (success)
-	{
-		std::string filename = ll_convert_wide_to_string(mFilesW);
-		mFiles.push_back(filename);
-	}
-
-	if (blocking)
-	{
-		send_agent_resume();
-		// Account for the fact that the app has been stalled.
-		LLFrameTimer::updateFrameTime();
-	}
-	
-	return success;
+    if( mLocked )
+    {
+        return FALSE;
+    }
+    BOOL success = FALSE;
+
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return FALSE;
+    }
+
+    // don't provide default file selection
+    mFilesW[0] = '\0';
+
+    mOFN.hwndOwner = (HWND)gViewerWindow->getPlatformWindow();
+    mOFN.lpstrFile = mFilesW;
+    mOFN.nMaxFile = SINGLE_FILENAME_BUFFER_SIZE;
+    mOFN.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR ;
+    mOFN.nFilterIndex = 1;
+
+    setupFilter(filter);
+
+    if (blocking)
+    {
+        // Modal, so pause agent
+        send_agent_pause();
+    }
+
+    reset();
+
+    // NOTA BENE: hitting the file dialog triggers a window focus event, destroying the selection manager!!
+    success = GetOpenFileName(&mOFN);
+    if (success)
+    {
+        std::string filename = ll_convert_wide_to_string(mFilesW);
+        mFiles.push_back(filename);
+    }
+
+    if (blocking)
+    {
+        send_agent_resume();
+        // Account for the fact that the app has been stalled.
+        LLFrameTimer::updateFrameTime();
+    }
+
+    return success;
 }
 
 BOOL LLFilePicker::getOpenFileModeless(ELoadFilter filter,
@@ -728,79 +728,79 @@ BOOL LLFilePicker::getOpenFileModeless(ELoadFilter filter,
 
 BOOL LLFilePicker::getMultipleOpenFiles(ELoadFilter filter, bool blocking)
 {
-	if( mLocked )
-	{
-		return FALSE;
-	}
-	BOOL success = FALSE;
-
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return FALSE;
-	}
-
-	// don't provide default file selection
-	mFilesW[0] = '\0';
-
-	mOFN.hwndOwner = (HWND)gViewerWindow->getPlatformWindow();
-	mOFN.lpstrFile = mFilesW;
-	mOFN.nFilterIndex = 1;
-	mOFN.nMaxFile = FILENAME_BUFFER_SIZE;
-	mOFN.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR |
-		OFN_EXPLORER | OFN_ALLOWMULTISELECT;
-
-	setupFilter(filter);
-
-	reset();
-
-	if (blocking)
-	{
-		// Modal, so pause agent
-		send_agent_pause();
-	}
-
-	// NOTA BENE: hitting the file dialog triggers a window focus event, destroying the selection manager!!
-	success = GetOpenFileName(&mOFN); // pauses until ok or cancel.
-	if( success )
-	{
-		// The getopenfilename api doesn't tell us if we got more than
-		// one file, so we have to test manually by checking string
-		// lengths.
-		if( wcslen(mOFN.lpstrFile) > mOFN.nFileOffset )	/*Flawfinder: ignore*/
-		{
-			std::string filename = ll_convert_wide_to_string(mFilesW);
-			mFiles.push_back(filename);
-		}
-		else
-		{
-			mLocked = true;
-			WCHAR* tptrw = mFilesW;
-			std::string dirname;
-			while(1)
-			{
-				if (*tptrw == 0 && *(tptrw+1) == 0) // double '\0'
-					break;
-				if (*tptrw == 0)
-					tptrw++; // shouldn't happen?
-				std::string filename = ll_convert_wide_to_string(tptrw);
-				if (dirname.empty())
-					dirname = filename + "\\";
-				else
-					mFiles.push_back(dirname + filename);
-				tptrw += wcslen(tptrw);
-			}
-		}
-	}
-
-	if (blocking)
-	{
-		send_agent_resume();
-	}
-
-	// Account for the fact that the app has been stalled.
-	LLFrameTimer::updateFrameTime();
-	return success;
+    if( mLocked )
+    {
+        return FALSE;
+    }
+    BOOL success = FALSE;
+
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return FALSE;
+    }
+
+    // don't provide default file selection
+    mFilesW[0] = '\0';
+
+    mOFN.hwndOwner = (HWND)gViewerWindow->getPlatformWindow();
+    mOFN.lpstrFile = mFilesW;
+    mOFN.nFilterIndex = 1;
+    mOFN.nMaxFile = FILENAME_BUFFER_SIZE;
+    mOFN.Flags = OFN_HIDEREADONLY | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR |
+        OFN_EXPLORER | OFN_ALLOWMULTISELECT;
+
+    setupFilter(filter);
+
+    reset();
+
+    if (blocking)
+    {
+        // Modal, so pause agent
+        send_agent_pause();
+    }
+
+    // NOTA BENE: hitting the file dialog triggers a window focus event, destroying the selection manager!!
+    success = GetOpenFileName(&mOFN); // pauses until ok or cancel.
+    if( success )
+    {
+        // The getopenfilename api doesn't tell us if we got more than
+        // one file, so we have to test manually by checking string
+        // lengths.
+        if( wcslen(mOFN.lpstrFile) > mOFN.nFileOffset ) /*Flawfinder: ignore*/
+        {
+            std::string filename = ll_convert_wide_to_string(mFilesW);
+            mFiles.push_back(filename);
+        }
+        else
+        {
+            mLocked = true;
+            WCHAR* tptrw = mFilesW;
+            std::string dirname;
+            while(1)
+            {
+                if (*tptrw == 0 && *(tptrw+1) == 0) // double '\0'
+                    break;
+                if (*tptrw == 0)
+                    tptrw++; // shouldn't happen?
+                std::string filename = ll_convert_wide_to_string(tptrw);
+                if (dirname.empty())
+                    dirname = filename + "\\";
+                else
+                    mFiles.push_back(dirname + filename);
+                tptrw += wcslen(tptrw);
+            }
+        }
+    }
+
+    if (blocking)
+    {
+        send_agent_resume();
+    }
+
+    // Account for the fact that the app has been stalled.
+    LLFrameTimer::updateFrameTime();
+    return success;
 }
 
 BOOL LLFilePicker::getMultipleOpenFilesModeless(ELoadFilter filter,
@@ -814,247 +814,247 @@ BOOL LLFilePicker::getMultipleOpenFilesModeless(ELoadFilter filter,
 
 BOOL LLFilePicker::getSaveFile(ESaveFilter filter, const std::string& filename, bool blocking)
 {
-	if( mLocked )
-	{
-		return FALSE;
-	}
-	BOOL success = FALSE;
-
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return FALSE;
-	}
-
-	mOFN.lpstrFile = mFilesW;
-	if (!filename.empty())
-	{
-		std::wstring tstring = ll_convert_string_to_wide(filename);
-		wcsncpy(mFilesW, tstring.c_str(), FILENAME_BUFFER_SIZE);	}	/*Flawfinder: ignore*/
-	else
-	{
-		mFilesW[0] = '\0';
-	}
-	mOFN.hwndOwner = (HWND)gViewerWindow->getPlatformWindow();
-
-	switch( filter )
-	{
-	case FFSAVE_ALL:
-		mOFN.lpstrDefExt = NULL;
-		mOFN.lpstrFilter =
-			L"All Files (*.*)\0*.*\0" \
-			L"WAV Sounds (*.wav)\0*.wav\0" \
-			L"Targa, Bitmap Images (*.tga; *.bmp)\0*.tga;*.bmp\0" \
-			L"\0";
-		break;
-	case FFSAVE_WAV:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.wav", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"wav";
-		mOFN.lpstrFilter =
-			L"WAV Sounds (*.wav)\0*.wav\0" \
-			L"\0";
-		break;
-	case FFSAVE_TGA:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.tga", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"tga";
-		mOFN.lpstrFilter =
-			L"Targa Images (*.tga)\0*.tga\0" \
-			L"\0";
-		break;
-	case FFSAVE_BMP:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.bmp", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"bmp";
-		mOFN.lpstrFilter =
-			L"Bitmap Images (*.bmp)\0*.bmp\0" \
-			L"\0";
-		break;
-	case FFSAVE_PNG:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.png", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"png";
-		mOFN.lpstrFilter =
-			L"PNG Images (*.png)\0*.png\0" \
-			L"\0";
-		break;
-	case FFSAVE_WEBP:
-		if (filename.empty())
-		{
-			wcsncpy(mFilesW, L"untitled.webp", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"webp";
-		mOFN.lpstrFilter =
-			L"WebP Images (*.webp)\0*.webp\0" \
-			L"\0";
-		break;
-	case FFSAVE_TGAPNGWEBP:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.png", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-			//PNG by default
-		}
-		mOFN.lpstrDefExt = L"png";
-		mOFN.lpstrFilter =
-			L"PNG Images (*.png)\0*.png\0" \
-			L"Targa Images (*.tga)\0*.tga\0" \
-			L"Jpeg Images (*.jpg)\0*.jpg\0" \
-			L"Jpeg2000 Images (*.j2c)\0*.j2c\0" \
-			L"Bitmap Images (*.bmp)\0*.bmp\0" \
-			L"WebP Images (*.webp)\0*.webp\0" \
-			L"\0";
-		break;
-
-	case FFSAVE_JPEG:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.jpeg", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"jpg";
-		mOFN.lpstrFilter =
-			L"JPEG Images (*.jpg *.jpeg)\0*.jpg;*.jpeg\0" \
-			L"\0";
-		break;
-	case FFSAVE_AVI:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.avi", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"avi";
-		mOFN.lpstrFilter =
-			L"AVI Movie File (*.avi)\0*.avi\0" \
-			L"\0";
-		break;
-	case FFSAVE_ANIM:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.xaf", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"xaf";
-		mOFN.lpstrFilter =
-			L"XAF Anim File (*.xaf)\0*.xaf\0" \
-			L"\0";
-		break;
-	case FFSAVE_GLTF:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.glb", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"glb";
-		mOFN.lpstrFilter =
-			L"glTF Asset File (*.gltf *.glb)\0*.gltf;*.glb\0" \
-			L"\0";
-		break;
-	case FFSAVE_CSV:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.csv", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-			
-		mOFN.lpstrDefExt = L"csv";
-		mOFN.lpstrFilter =
-			L"Comma seperated values (*.csv)\0*.csv\0" \
-			L"\0";
-		break;
-	case FFSAVE_XML:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.xml", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-
-		mOFN.lpstrDefExt = L"xml";
-		mOFN.lpstrFilter =
-			L"XML File (*.xml)\0*.xml\0" \
-			L"\0";
-		break;
-	case FFSAVE_COLLADA:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.collada", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"collada";
-		mOFN.lpstrFilter =
-			L"COLLADA File (*.collada)\0*.collada\0" \
-			L"\0";
-		break;
-	case FFSAVE_RAW:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.raw", FILENAME_BUFFER_SIZE);	/*Flawfinder: ignore*/
-		}
-		mOFN.lpstrDefExt = L"raw";
-		mOFN.lpstrFilter =	RAW_FILTER \
-							L"\0";
-		break;
-	case FFSAVE_J2C:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.j2c", FILENAME_BUFFER_SIZE);
-		}
-		mOFN.lpstrDefExt = L"j2c";
-		mOFN.lpstrFilter =
-			L"Compressed Images (*.j2c)\0*.j2c\0" \
-			L"\0";
-		break;
-	case FFSAVE_SCRIPT:
-		if (filename.empty())
-		{
-			wcsncpy( mFilesW,L"untitled.lsl", FILENAME_BUFFER_SIZE);
-		}
-		mOFN.lpstrDefExt = L"txt";
-		mOFN.lpstrFilter = L"LSL Files (*.lsl)\0*.lsl\0" L"\0";
-		break;
-	default:
-		return FALSE;
-	}
-
- 
-	mOFN.nMaxFile = SINGLE_FILENAME_BUFFER_SIZE;
-	mOFN.Flags = OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST;
-
-	reset();
-
-	if (blocking)
-	{
-		// Modal, so pause agent
-		send_agent_pause();
-	}
-
-	{
-		// NOTA BENE: hitting the file dialog triggers a window focus event, destroying the selection manager!!
-		try
-		{
-			success = GetSaveFileName(&mOFN);
-			if (success)
-			{
-				std::string filename = ll_convert_wide_to_string(mFilesW);
-				mFiles.push_back(filename);
-			}
-		}
-		catch (...)
-		{
-			LOG_UNHANDLED_EXCEPTION("");
-		}
-		gKeyboard->resetKeys();
-	}
-
-	if (blocking)
-	{
-		send_agent_resume();
-	}
-
-	// Account for the fact that the app has been stalled.
-	LLFrameTimer::updateFrameTime();
-	return success;
+    if( mLocked )
+    {
+        return FALSE;
+    }
+    BOOL success = FALSE;
+
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return FALSE;
+    }
+
+    mOFN.lpstrFile = mFilesW;
+    if (!filename.empty())
+    {
+        std::wstring tstring = ll_convert_string_to_wide(filename);
+        wcsncpy(mFilesW, tstring.c_str(), FILENAME_BUFFER_SIZE);    }   /*Flawfinder: ignore*/
+    else
+    {
+        mFilesW[0] = '\0';
+    }
+    mOFN.hwndOwner = (HWND)gViewerWindow->getPlatformWindow();
+
+    switch( filter )
+    {
+    case FFSAVE_ALL:
+        mOFN.lpstrDefExt = NULL;
+        mOFN.lpstrFilter =
+            L"All Files (*.*)\0*.*\0" \
+            L"WAV Sounds (*.wav)\0*.wav\0" \
+            L"Targa, Bitmap Images (*.tga; *.bmp)\0*.tga;*.bmp\0" \
+            L"\0";
+        break;
+    case FFSAVE_WAV:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.wav", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"wav";
+        mOFN.lpstrFilter =
+            L"WAV Sounds (*.wav)\0*.wav\0" \
+            L"\0";
+        break;
+    case FFSAVE_TGA:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.tga", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"tga";
+        mOFN.lpstrFilter =
+            L"Targa Images (*.tga)\0*.tga\0" \
+            L"\0";
+        break;
+    case FFSAVE_BMP:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.bmp", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"bmp";
+        mOFN.lpstrFilter =
+            L"Bitmap Images (*.bmp)\0*.bmp\0" \
+            L"\0";
+        break;
+    case FFSAVE_PNG:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.png", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"png";
+        mOFN.lpstrFilter =
+            L"PNG Images (*.png)\0*.png\0" \
+            L"\0";
+        break;
+    case FFSAVE_WEBP:
+        if (filename.empty())
+        {
+            wcsncpy(mFilesW, L"untitled.webp", FILENAME_BUFFER_SIZE);   /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"webp";
+        mOFN.lpstrFilter =
+            L"WebP Images (*.webp)\0*.webp\0" \
+            L"\0";
+        break;
+    case FFSAVE_TGAPNGWEBP:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.png", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+            //PNG by default
+        }
+        mOFN.lpstrDefExt = L"png";
+        mOFN.lpstrFilter =
+            L"PNG Images (*.png)\0*.png\0" \
+            L"Targa Images (*.tga)\0*.tga\0" \
+            L"Jpeg Images (*.jpg)\0*.jpg\0" \
+            L"Jpeg2000 Images (*.j2c)\0*.j2c\0" \
+            L"Bitmap Images (*.bmp)\0*.bmp\0" \
+            L"WebP Images (*.webp)\0*.webp\0" \
+            L"\0";
+        break;
+
+    case FFSAVE_JPEG:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.jpeg", FILENAME_BUFFER_SIZE);   /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"jpg";
+        mOFN.lpstrFilter =
+            L"JPEG Images (*.jpg *.jpeg)\0*.jpg;*.jpeg\0" \
+            L"\0";
+        break;
+    case FFSAVE_AVI:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.avi", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"avi";
+        mOFN.lpstrFilter =
+            L"AVI Movie File (*.avi)\0*.avi\0" \
+            L"\0";
+        break;
+    case FFSAVE_ANIM:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.xaf", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"xaf";
+        mOFN.lpstrFilter =
+            L"XAF Anim File (*.xaf)\0*.xaf\0" \
+            L"\0";
+        break;
+    case FFSAVE_GLTF:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.glb", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"glb";
+        mOFN.lpstrFilter =
+            L"glTF Asset File (*.gltf *.glb)\0*.gltf;*.glb\0" \
+            L"\0";
+        break;
+    case FFSAVE_CSV:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.csv", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+
+        mOFN.lpstrDefExt = L"csv";
+        mOFN.lpstrFilter =
+            L"Comma seperated values (*.csv)\0*.csv\0" \
+            L"\0";
+        break;
+    case FFSAVE_XML:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.xml", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+
+        mOFN.lpstrDefExt = L"xml";
+        mOFN.lpstrFilter =
+            L"XML File (*.xml)\0*.xml\0" \
+            L"\0";
+        break;
+    case FFSAVE_COLLADA:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.collada", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"collada";
+        mOFN.lpstrFilter =
+            L"COLLADA File (*.collada)\0*.collada\0" \
+            L"\0";
+        break;
+    case FFSAVE_RAW:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.raw", FILENAME_BUFFER_SIZE);    /*Flawfinder: ignore*/
+        }
+        mOFN.lpstrDefExt = L"raw";
+        mOFN.lpstrFilter =  RAW_FILTER \
+                            L"\0";
+        break;
+    case FFSAVE_J2C:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.j2c", FILENAME_BUFFER_SIZE);
+        }
+        mOFN.lpstrDefExt = L"j2c";
+        mOFN.lpstrFilter =
+            L"Compressed Images (*.j2c)\0*.j2c\0" \
+            L"\0";
+        break;
+    case FFSAVE_SCRIPT:
+        if (filename.empty())
+        {
+            wcsncpy( mFilesW,L"untitled.lsl", FILENAME_BUFFER_SIZE);
+        }
+        mOFN.lpstrDefExt = L"txt";
+        mOFN.lpstrFilter = L"LSL Files (*.lsl)\0*.lsl\0" L"\0";
+        break;
+    default:
+        return FALSE;
+    }
+
+
+    mOFN.nMaxFile = SINGLE_FILENAME_BUFFER_SIZE;
+    mOFN.Flags = OFN_OVERWRITEPROMPT | OFN_NOCHANGEDIR | OFN_PATHMUSTEXIST;
+
+    reset();
+
+    if (blocking)
+    {
+        // Modal, so pause agent
+        send_agent_pause();
+    }
+
+    {
+        // NOTA BENE: hitting the file dialog triggers a window focus event, destroying the selection manager!!
+        try
+        {
+            success = GetSaveFileName(&mOFN);
+            if (success)
+            {
+                std::string filename = ll_convert_wide_to_string(mFilesW);
+                mFiles.push_back(filename);
+            }
+        }
+        catch (...)
+        {
+            LOG_UNHANDLED_EXCEPTION("");
+        }
+        gKeyboard->resetKeys();
+    }
+
+    if (blocking)
+    {
+        send_agent_resume();
+    }
+
+    // Account for the fact that the app has been stalled.
+    LLFrameTimer::updateFrameTime();
+    return success;
 }
 
 BOOL LLFilePicker::getSaveFileModeless(ESaveFilter filter,
@@ -1097,7 +1097,7 @@ std::unique_ptr<std::vector<std::string>> LLFilePicker::navOpenFilterProc(ELoadF
             allowedv->emplace_back("bmpf");
             allowedv->emplace_back("tpic");
             allowedv->emplace_back("png");
-			allowedv->emplace_back("webp");
+            allowedv->emplace_back("webp");
             break;
             break;
         case FFLOAD_WAV:
@@ -1139,33 +1139,33 @@ std::unique_ptr<std::vector<std::string>> LLFilePicker::navOpenFilterProc(ELoadF
             LL_WARNS() << "Unsupported format." << LL_ENDL;
     }
 
-	return allowedv;
+    return allowedv;
 }
 
-bool	LLFilePicker::doNavChooseDialog(ELoadFilter filter)
+bool    LLFilePicker::doNavChooseDialog(ELoadFilter filter)
 {
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return false;
-	}
-    
-	gViewerWindow->getWindow()->beforeDialog();
-    
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return false;
+    }
+
+    gViewerWindow->getWindow()->beforeDialog();
+
     std::unique_ptr<std::vector<std::string>> allowed_types = navOpenFilterProc(filter);
-    
+
     std::unique_ptr<std::vector<std::string>> filev  = doLoadDialog(allowed_types.get(),
                                                     mPickOptions);
 
-	gViewerWindow->getWindow()->afterDialog();
+    gViewerWindow->getWindow()->afterDialog();
 
     if (filev && filev->size() > 0)
     {
         mFiles.insert(mFiles.end(), filev->begin(), filev->end());
         return true;
     }
-	
-	return false;
+
+    return false;
 }
 
 bool    LLFilePicker::doNavChooseDialogModeless(ELoadFilter filter,
@@ -1177,14 +1177,14 @@ bool    LLFilePicker::doNavChooseDialogModeless(ELoadFilter filter,
     {
         return false;
     }
-    
+
     std::unique_ptr<std::vector<std::string>> allowed_types=navOpenFilterProc(filter);
-    
+
     doLoadDialogModeless(allowed_types.get(),
                                                     mPickOptions,
                                                     callback,
                                                     userdata);
-    
+
     return true;
 }
 
@@ -1198,11 +1198,11 @@ void set_nav_save_data(LLFilePicker::ESaveFilter filter, std::string &extension,
         case LLFilePicker::FFSAVE_TGA:
             extension = "tga";
             break;
-		case LLFilePicker::FFSAVE_TGAPNGWEBP:
-			extension = "png,tga,jpg,jpeg,j2c,bmp,bmpf,webp";
+        case LLFilePicker::FFSAVE_TGAPNGWEBP:
+            extension = "png,tga,jpg,jpeg,j2c,bmp,bmpf,webp";
             break;
         case LLFilePicker::FFSAVE_BMP:
-			extension = "bmp,bmpf";
+            extension = "bmp,bmpf";
             break;
         case LLFilePicker::FFSAVE_JPEG:
             extension = "jpeg";
@@ -1210,9 +1210,9 @@ void set_nav_save_data(LLFilePicker::ESaveFilter filter, std::string &extension,
         case LLFilePicker::FFSAVE_PNG:
             extension = "png";
             break;
-		case LLFilePicker::FFSAVE_WEBP:
-			extension = "webp";
-			break;
+        case LLFilePicker::FFSAVE_WEBP:
+            extension = "webp";
+            break;
         case LLFilePicker::FFSAVE_AVI:
             extension = "mov";
             break;
@@ -1223,13 +1223,13 @@ void set_nav_save_data(LLFilePicker::ESaveFilter filter, std::string &extension,
         case LLFilePicker::FFSAVE_GLTF:
             extension = "glb";
             break;
-            
+
         case LLFilePicker::FFSAVE_XML:
             extension = "xml";
             break;
-		case LLFilePicker::FFSAVE_CSV:
-			extension = "csv";
-			break;
+        case LLFilePicker::FFSAVE_CSV:
+            extension = "csv";
+            break;
         case LLFilePicker::FFSAVE_RAW:
             extension = "raw";
             break;
@@ -1237,11 +1237,11 @@ void set_nav_save_data(LLFilePicker::ESaveFilter filter, std::string &extension,
         case LLFilePicker::FFSAVE_J2C:
             extension = "j2c";
             break;
-        
+
         case LLFilePicker::FFSAVE_SCRIPT:
             extension = "lsl";
             break;
-        
+
         case LLFilePicker::FFSAVE_ALL:
         default:
             extension = "";
@@ -1249,32 +1249,32 @@ void set_nav_save_data(LLFilePicker::ESaveFilter filter, std::string &extension,
     }
 }
 
-bool	LLFilePicker::doNavSaveDialog(ESaveFilter filter, const std::string& filename)
+bool    LLFilePicker::doNavSaveDialog(ESaveFilter filter, const std::string& filename)
 {
-	// Setup the type, creator, and extension
-    std::string		extension, type, creator;
-    
+    // Setup the type, creator, and extension
+    std::string     extension, type, creator;
+
     set_nav_save_data(filter, extension, type, creator);
-	
+
     std::string namestring = filename;
     if (namestring.empty()) namestring="Untitled";
-    
-	gViewerWindow->getWindow()->beforeDialog();
 
-	// Run the dialog
-    std::unique_ptr<std::string> filev = doSaveDialog(&namestring, 
+    gViewerWindow->getWindow()->beforeDialog();
+
+    // Run the dialog
+    std::unique_ptr<std::string> filev = doSaveDialog(&namestring,
                  &extension,
                  mPickOptions);
 
-	gViewerWindow->getWindow()->afterDialog();
+    gViewerWindow->getWindow()->afterDialog();
 
-	if ( filev && !filev->empty() )
-	{
+    if ( filev && !filev->empty() )
+    {
         mFiles.push_back(*filev);
-		return true;
+        return true;
     }
-	
-	return false;
+
+    return false;
 }
 
 bool    LLFilePicker::doNavSaveDialogModeless(ESaveFilter filter,
@@ -1284,9 +1284,9 @@ bool    LLFilePicker::doNavSaveDialogModeless(ESaveFilter filter,
 {
     // Setup the type, creator, and extension
     std::string        extension, type, creator;
-    
+
     set_nav_save_data(filter, extension, type, creator);
-    
+
     std::string namestring = filename;
     if (namestring.empty()) namestring="Untitled";
 
@@ -1303,57 +1303,57 @@ bool    LLFilePicker::doNavSaveDialogModeless(ESaveFilter filter,
 
 BOOL LLFilePicker::getOpenFile(ELoadFilter filter, bool blocking)
 {
-	if( mLocked )
-		return FALSE;
+    if( mLocked )
+        return FALSE;
+
+    BOOL success = FALSE;
 
-	BOOL success = FALSE;
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return FALSE;
+    }
 
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return FALSE;
-	}
+    reset();
 
-	reset();
-	
     mPickOptions &= ~F_MULTIPLE;
     mPickOptions |= F_FILE;
- 
-    if (filter == FFLOAD_DIRECTORY) //This should only be called from lldirpicker. 
+
+    if (filter == FFLOAD_DIRECTORY) //This should only be called from lldirpicker.
     {
 
         mPickOptions |= ( F_NAV_SUPPORT | F_DIRECTORY );
         mPickOptions &= ~F_FILE;
     }
 
-	if (filter == FFLOAD_ALL)	// allow application bundles etc. to be traversed; important for DEV-16869, but generally useful
-	{
+    if (filter == FFLOAD_ALL)   // allow application bundles etc. to be traversed; important for DEV-16869, but generally useful
+    {
         mPickOptions |= F_NAV_SUPPORT;
-	}
-	
-	if (blocking) // always true for linux/mac
-	{
-		// Modal, so pause agent
-		send_agent_pause();
-	}
-
-
-	success = doNavChooseDialog(filter);
-		
-	if (success)
-	{
-		if (!getFileCount())
-			success = false;
-	}
-
-	if (blocking)
-	{
-		send_agent_resume();
-		// Account for the fact that the app has been stalled.
-		LLFrameTimer::updateFrameTime();
-	}
-
-	return success;
+    }
+
+    if (blocking) // always true for linux/mac
+    {
+        // Modal, so pause agent
+        send_agent_pause();
+    }
+
+
+    success = doNavChooseDialog(filter);
+
+    if (success)
+    {
+        if (!getFileCount())
+            success = false;
+    }
+
+    if (blocking)
+    {
+        send_agent_resume();
+        // Account for the fact that the app has been stalled.
+        LLFrameTimer::updateFrameTime();
+    }
+
+    return success;
 }
 
 
@@ -1371,10 +1371,10 @@ BOOL LLFilePicker::getOpenFileModeless(ELoadFilter filter,
     }
 
     reset();
-    
+
     mPickOptions &= ~F_MULTIPLE;
     mPickOptions |= F_FILE;
- 
+
     if (filter == FFLOAD_DIRECTORY) //This should only be called from lldirpicker.
     {
 
@@ -1392,47 +1392,47 @@ BOOL LLFilePicker::getOpenFileModeless(ELoadFilter filter,
 
 BOOL LLFilePicker::getMultipleOpenFiles(ELoadFilter filter, bool blocking)
 {
-	if( mLocked )
-		return FALSE;
-
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return FALSE;
-	}
-    
+    if( mLocked )
+        return FALSE;
+
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return FALSE;
+    }
+
     BOOL success = FALSE;
 
-	reset();
-    
+    reset();
+
     mPickOptions |= F_FILE;
 
     mPickOptions |= F_MULTIPLE;
 
-	if (blocking) // always true for linux/mac
-	{
-		// Modal, so pause agent
-		send_agent_pause();
-	}
-
-	success = doNavChooseDialog(filter);
-
-	if (blocking)
-	{
-		send_agent_resume();
-	}
-
-	if (success)
-	{
-		if (!getFileCount())
-			success = false;
-		if (getFileCount() > 1)
-			mLocked = true;
-	}
-
-	// Account for the fact that the app has been stalled.
-	LLFrameTimer::updateFrameTime();
-	return success;
+    if (blocking) // always true for linux/mac
+    {
+        // Modal, so pause agent
+        send_agent_pause();
+    }
+
+    success = doNavChooseDialog(filter);
+
+    if (blocking)
+    {
+        send_agent_resume();
+    }
+
+    if (success)
+    {
+        if (!getFileCount())
+            success = false;
+        if (getFileCount() > 1)
+            mLocked = true;
+    }
+
+    // Account for the fact that the app has been stalled.
+    LLFrameTimer::updateFrameTime();
+    return success;
 }
 
 
@@ -1450,7 +1450,7 @@ BOOL LLFilePicker::getMultipleOpenFilesModeless(ELoadFilter filter,
     }
 
     reset();
-    
+
     mPickOptions |= F_FILE;
 
     mPickOptions |= F_MULTIPLE;
@@ -1461,42 +1461,42 @@ BOOL LLFilePicker::getMultipleOpenFilesModeless(ELoadFilter filter,
 BOOL LLFilePicker::getSaveFile(ESaveFilter filter, const std::string& filename, bool blocking)
 {
 
-	if( mLocked )
-		return false;
-	BOOL success = false;
+    if( mLocked )
+        return false;
+    BOOL success = false;
+
+    // if local file browsing is turned off, return without opening dialog
+    if ( check_local_file_access_enabled() == false )
+    {
+        return false;
+    }
 
-	// if local file browsing is turned off, return without opening dialog
-	if ( check_local_file_access_enabled() == false )
-	{
-		return false;
-	}
+    reset();
 
-	reset();
-	
     mPickOptions &= ~F_MULTIPLE;
 
-	if (blocking)
-	{
-		// Modal, so pause agent
-		send_agent_pause();
-	}
+    if (blocking)
+    {
+        // Modal, so pause agent
+        send_agent_pause();
+    }
 
     success = doNavSaveDialog(filter, filename);
 
     if (success)
-	{
-		if (!getFileCount())
-			success = false;
-	}
-
-	if (blocking)
-	{
-		send_agent_resume();
-	}
-
-	// Account for the fact that the app has been stalled.
-	LLFrameTimer::updateFrameTime();
-	return success;
+    {
+        if (!getFileCount())
+            success = false;
+    }
+
+    if (blocking)
+    {
+        send_agent_resume();
+    }
+
+    // Account for the fact that the app has been stalled.
+    LLFrameTimer::updateFrameTime();
+    return success;
 }
 
 BOOL LLFilePicker::getSaveFileModeless(ESaveFilter filter,
@@ -1506,7 +1506,7 @@ BOOL LLFilePicker::getSaveFileModeless(ESaveFilter filter,
 {
     if( mLocked )
         return false;
-    
+
     // if local file browsing is turned off, return without opening dialog
     if ( check_local_file_access_enabled() == false )
     {
@@ -1514,7 +1514,7 @@ BOOL LLFilePicker::getSaveFileModeless(ESaveFilter filter,
     }
 
     reset();
-    
+
     mPickOptions &= ~F_MULTIPLE;
 
     return doNavSaveDialogModeless(filter, filename, callback, userdata);
@@ -1528,23 +1528,23 @@ BOOL LLFilePicker::getSaveFileModeless(ESaveFilter filter,
 
 BOOL LLFilePicker::getSaveFile( ESaveFilter filter, const std::string& filename, bool blocking )
 {
-	// if local file browsing is turned off, return without opening dialog
-	// (Even though this is a stub, I think we still should not return anything at all)
-	if ( check_local_file_access_enabled() == false )
-	{
-		return FALSE;
-	}
-
-	reset();
-	
-	LL_INFOS() << "getSaveFile suggested filename is [" << filename
-		<< "]" << LL_ENDL;
-	if (!filename.empty())
-	{
-		mFiles.push_back(gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter() + filename);
-		return TRUE;
-	}
-	return FALSE;
+    // if local file browsing is turned off, return without opening dialog
+    // (Even though this is a stub, I think we still should not return anything at all)
+    if ( check_local_file_access_enabled() == false )
+    {
+        return FALSE;
+    }
+
+    reset();
+
+    LL_INFOS() << "getSaveFile suggested filename is [" << filename
+        << "]" << LL_ENDL;
+    if (!filename.empty())
+    {
+        mFiles.push_back(gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter() + filename);
+        return TRUE;
+    }
+    return FALSE;
 }
 
 BOOL LLFilePicker::getSaveFileModeless(ESaveFilter filter,
@@ -1578,19 +1578,19 @@ BOOL LLFilePicker::getOpenFile( ELoadFilter filter, bool blocking )
     }
 
     reset();
-	
-	// HACK: Static filenames for 'open' until we implement filepicker
-	std::string filename = gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter() + "upload";
-	switch (filter)
-	{
-	case FFLOAD_WAV: filename += ".wav"; break;
-	case FFLOAD_IMAGE: filename += ".tga"; break;
-	case FFLOAD_ANIM: filename += ".bvh"; break;
-	default: break;
-	}
-	mFiles.push_back(filename);
-	LL_INFOS() << "getOpenFile: Will try to open file: " << filename << LL_ENDL;
-	return TRUE;
+
+    // HACK: Static filenames for 'open' until we implement filepicker
+    std::string filename = gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter() + "upload";
+    switch (filter)
+    {
+    case FFLOAD_WAV: filename += ".wav"; break;
+    case FFLOAD_IMAGE: filename += ".tga"; break;
+    case FFLOAD_ANIM: filename += ".bvh"; break;
+    default: break;
+    }
+    mFiles.push_back(filename);
+    LL_INFOS() << "getOpenFile: Will try to open file: " << filename << LL_ENDL;
+    return TRUE;
 }
 
 BOOL LLFilePicker::getOpenFileModeless(ELoadFilter filter,
@@ -1623,7 +1623,7 @@ BOOL LLFilePicker::getMultipleOpenFiles( ELoadFilter filter, bool blocking)
     }
 
     reset();
-	return FALSE;
+    return FALSE;
 }
 
 BOOL LLFilePicker::getMultipleOpenFilesModeless(ELoadFilter filter,
@@ -1649,20 +1649,20 @@ BOOL LLFilePicker::getMultipleOpenFilesModeless(ELoadFilter filter,
 
 BOOL LLFilePicker::getSaveFile( ESaveFilter filter, const std::string& filename )
 {
-	reset();	
-	return FALSE;
+    reset();
+    return FALSE;
 }
 
 BOOL LLFilePicker::getOpenFile( ELoadFilter filter )
 {
-	reset();
-	return FALSE;
+    reset();
+    return FALSE;
 }
 
 BOOL LLFilePicker::getMultipleOpenFiles( ELoadFilter filter, bool blocking)
 {
-	reset();
-	return FALSE;
+    reset();
+    return FALSE;
 }
 
 #endif // LL_LINUX
diff --git a/indra/newview/llfilepicker.h b/indra/newview/llfilepicker.h
index 49a132cb37c900540cf86925d72a29bca4f6ee9a..8a31e5d9d4eedf7fd62277952e84c8a065a8e5c0 100644
--- a/indra/newview/llfilepicker.h
+++ b/indra/newview/llfilepicker.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llfilepicker.h
  * @brief OS-specific file picker
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -60,122 +60,122 @@
 class LLFilePicker
 {
 public:
-	// calling this before main() is undefined
-	static LLFilePicker& instance( void ) { return sInstance; }
-
-	enum ELoadFilter
-	{
-		FFLOAD_ALL = 1,
-		FFLOAD_WAV = 2,
-		FFLOAD_IMAGE = 3,
-		FFLOAD_ANIM = 4,
-		FFLOAD_GLTF = 5,
-		FFLOAD_XML = 6,
-		FFLOAD_SLOBJECT = 7,
-		FFLOAD_RAW = 8,
-		FFLOAD_MODEL = 9,
-		FFLOAD_COLLADA = 10,
-		FFLOAD_SCRIPT = 11,
-		FFLOAD_DICTIONARY = 12,
+    // calling this before main() is undefined
+    static LLFilePicker& instance( void ) { return sInstance; }
+
+    enum ELoadFilter
+    {
+        FFLOAD_ALL = 1,
+        FFLOAD_WAV = 2,
+        FFLOAD_IMAGE = 3,
+        FFLOAD_ANIM = 4,
+        FFLOAD_GLTF = 5,
+        FFLOAD_XML = 6,
+        FFLOAD_SLOBJECT = 7,
+        FFLOAD_RAW = 8,
+        FFLOAD_MODEL = 9,
+        FFLOAD_COLLADA = 10,
+        FFLOAD_SCRIPT = 11,
+        FFLOAD_DICTIONARY = 12,
         FFLOAD_DIRECTORY = 13,   // To call from lldirpicker.
         FFLOAD_EXE = 14,          // Note: EXE will be treated as ALL on Windows and Linux but not on Darwin
         FFLOAD_MATERIAL = 15,
         FFLOAD_MATERIAL_TEXTURE = 16,
         FFLOAD_HDRI = 17,
-		FFLOAD_ZIP = 18
-	};
-
-	enum ESaveFilter
-	{
-		FFSAVE_ALL = 1,
-		FFSAVE_WAV = 3,
-		FFSAVE_TGA = 4,
-		FFSAVE_BMP = 5,
-		FFSAVE_AVI = 6,
-		FFSAVE_ANIM = 7,
-		FFSAVE_GLTF = 8,
-		FFSAVE_XML = 9,
-		FFSAVE_COLLADA = 10,
-		FFSAVE_RAW = 11,
-		FFSAVE_J2C = 12,
-		FFSAVE_PNG = 13,
-		FFSAVE_JPEG = 14,
-		FFSAVE_SCRIPT = 15,
-		FFSAVE_TGAPNGWEBP = 16,
-		FFSAVE_WEBP = 17,
-		FFSAVE_CSV
-	};
-
-	// open the dialog. This is a modal operation
-	BOOL getSaveFile( ESaveFilter filter = FFSAVE_ALL, const std::string& filename = LLStringUtil::null, bool blocking = true);
+        FFLOAD_ZIP = 18
+    };
+
+    enum ESaveFilter
+    {
+        FFSAVE_ALL = 1,
+        FFSAVE_WAV = 3,
+        FFSAVE_TGA = 4,
+        FFSAVE_BMP = 5,
+        FFSAVE_AVI = 6,
+        FFSAVE_ANIM = 7,
+        FFSAVE_GLTF = 8,
+        FFSAVE_XML = 9,
+        FFSAVE_COLLADA = 10,
+        FFSAVE_RAW = 11,
+        FFSAVE_J2C = 12,
+        FFSAVE_PNG = 13,
+        FFSAVE_JPEG = 14,
+        FFSAVE_SCRIPT = 15,
+        FFSAVE_TGAPNGWEBP = 16,
+        FFSAVE_WEBP = 17,
+        FFSAVE_CSV
+    };
+
+    // open the dialog. This is a modal operation
+    BOOL getSaveFile( ESaveFilter filter = FFSAVE_ALL, const std::string& filename = LLStringUtil::null, bool blocking = true);
     BOOL getSaveFileModeless(ESaveFilter filter,
                              const std::string& filename,
                              void (*callback)(bool, std::string&, void*),
                              void *userdata);
-	BOOL getOpenFile( ELoadFilter filter = FFLOAD_ALL, bool blocking = true  );
+    BOOL getOpenFile( ELoadFilter filter = FFLOAD_ALL, bool blocking = true  );
     // Todo: implement getOpenFileModeless and getMultipleOpenFilesModeless
     // for windows and use directly instead of ugly LLFilePickerThread
     BOOL getOpenFileModeless( ELoadFilter filter, void (*callback)(bool, std::vector<std::string> &, void*), void *userdata); // MAC only.
-	BOOL getMultipleOpenFiles( ELoadFilter filter = FFLOAD_ALL, bool blocking = true );
+    BOOL getMultipleOpenFiles( ELoadFilter filter = FFLOAD_ALL, bool blocking = true );
     BOOL getMultipleOpenFilesModeless( ELoadFilter filter, void (*callback)(bool, std::vector<std::string> &, void*), void *userdata ); // MAC only
 
-	// Get the filename(s) found. getFirstFile() sets the pointer to
-	// the start of the structure and allows the start of iteration.
-	const std::string getFirstFile();
+    // Get the filename(s) found. getFirstFile() sets the pointer to
+    // the start of the structure and allows the start of iteration.
+    const std::string getFirstFile();
+
+    // getNextFile() increments the internal representation and
+    // returns the next file specified by the user. Returns NULL when
+    // no more files are left. Further calls to getNextFile() are
+    // undefined.
+    const std::string getNextFile();
 
-	// getNextFile() increments the internal representation and
-	// returns the next file specified by the user. Returns NULL when
-	// no more files are left. Further calls to getNextFile() are
-	// undefined.
-	const std::string getNextFile();
+    // This utility function extracts the current file name without
+    // doing any incrementing.
+    const std::string getCurFile();
 
-	// This utility function extracts the current file name without
-	// doing any incrementing.
-	const std::string getCurFile();
+    // Returns the index of the current file.
+    S32 getCurFileNum() const { return mCurrentFile; }
 
-	// Returns the index of the current file.
-	S32 getCurFileNum() const { return mCurrentFile; }
+    S32 getFileCount() const { return (S32)mFiles.size(); }
 
-	S32 getFileCount() const { return (S32)mFiles.size(); }
+    // see lldir.h : getBaseFileName and getDirName to extract base or directory names
 
-	// see lldir.h : getBaseFileName and getDirName to extract base or directory names
-	
-	// clear any lists of buffers or whatever, and make sure the file
-	// picker isn't locked.
-	void reset();
+    // clear any lists of buffers or whatever, and make sure the file
+    // picker isn't locked.
+    void reset();
 
 private:
-	enum
-	{
-		SINGLE_FILENAME_BUFFER_SIZE = 1024,
-		//FILENAME_BUFFER_SIZE = 65536
-		FILENAME_BUFFER_SIZE = 65000
-	};
-
-	// utility function to check if access to local file system via file browser 
-	// is enabled and if not, tidy up and indicate we're not allowed to do this.
-	bool check_local_file_access_enabled();
-	
+    enum
+    {
+        SINGLE_FILENAME_BUFFER_SIZE = 1024,
+        //FILENAME_BUFFER_SIZE = 65536
+        FILENAME_BUFFER_SIZE = 65000
+    };
+
+    // utility function to check if access to local file system via file browser
+    // is enabled and if not, tidy up and indicate we're not allowed to do this.
+    bool check_local_file_access_enabled();
+
 #if LL_NFD
-	std::vector<nfdfilteritem_t> setupFilter(ELoadFilter filter);
+    std::vector<nfdfilteritem_t> setupFilter(ELoadFilter filter);
 #endif
 
 #if LL_WINDOWS && !LL_NFD
-	OPENFILENAMEW mOFN;				// for open and save dialogs
-	WCHAR mFilesW[FILENAME_BUFFER_SIZE];
+    OPENFILENAMEW mOFN;             // for open and save dialogs
+    WCHAR mFilesW[FILENAME_BUFFER_SIZE];
 
-	BOOL setupFilter(ELoadFilter filter);
+    BOOL setupFilter(ELoadFilter filter);
 #endif
 
 #if LL_DARWIN && !LL_NFD
     S32 mPickOptions;
-	std::vector<std::string> mFileVector;
-	
-	bool doNavChooseDialog(ELoadFilter filter);
-	bool doNavChooseDialogModeless(ELoadFilter filter,
+    std::vector<std::string> mFileVector;
+
+    bool doNavChooseDialog(ELoadFilter filter);
+    bool doNavChooseDialogModeless(ELoadFilter filter,
                                    void (*callback)(bool, std::vector<std::string>&, void*),
                                    void *userdata);
-	bool doNavSaveDialog(ESaveFilter filter, const std::string& filename);
+    bool doNavSaveDialog(ESaveFilter filter, const std::string& filename);
     std::unique_ptr<std::vector<std::string>> navOpenFilterProc(ELoadFilter filter);
     bool doNavSaveDialogModeless(ESaveFilter filter,
                                  const std::string& filename,
@@ -183,16 +183,16 @@ class LLFilePicker
                                  void *userdata);
 #endif
 
-	std::vector<std::string> mFiles;
-	S32 mCurrentFile;
-	bool mLocked;
+    std::vector<std::string> mFiles;
+    S32 mCurrentFile;
+    bool mLocked;
+
+    static LLFilePicker sInstance;
 
-	static LLFilePicker sInstance;
-	
 public:
-	// don't call these directly please.
-	LLFilePicker();
-	~LLFilePicker();
+    // don't call these directly please.
+    LLFilePicker();
+    ~LLFilePicker();
 };
 
 #endif
diff --git a/indra/newview/llfloaterblocked.cpp b/indra/newview/llfloaterblocked.cpp
index dc4190c2769b871abb7d21ef284ff0639a2b4b50..c455215faa6b15cb7c07efe24b6585beb15f6107 100644
--- a/indra/newview/llfloaterblocked.cpp
+++ b/indra/newview/llfloaterblocked.cpp
@@ -60,277 +60,277 @@ const std::string EXCEPTION_TAB_NAME = "avatar_rendering_tab";
 static LLPanelInjector<LLPanelBlockList> t_panel_blocked_list("panel_block_list");
 
 LLPanelBlockList::LLPanelBlockList()
-	: LLPanel()
+    : LLPanel()
 {
-	mCommitCallbackRegistrar.add("Block.AddAvatar", boost::bind(&LLPanelBlockList::onAddAvatar, this, _1));
-	mCommitCallbackRegistrar.add("Block.AddByName",	boost::bind(&LLPanelBlockList::onAddByName));
-	mCommitCallbackRegistrar.add("Block.Remove", boost::bind(&LLPanelBlockList::onRemoveSelection, this));
+    mCommitCallbackRegistrar.add("Block.AddAvatar", boost::bind(&LLPanelBlockList::onAddAvatar, this, _1));
+    mCommitCallbackRegistrar.add("Block.AddByName", boost::bind(&LLPanelBlockList::onAddByName));
+    mCommitCallbackRegistrar.add("Block.Remove", boost::bind(&LLPanelBlockList::onRemoveSelection, this));
 }
 
 LLPanelBlockList::~LLPanelBlockList()
 {
-	LLMuteList::getInstance()->removeObserver(this);
+    LLMuteList::getInstance()->removeObserver(this);
 }
 
 // virtual
 BOOL LLPanelBlockList::postBuild()
 {
-	setVisibleCallback(boost::bind(&LLPanelBlockList::removePicker, this));
+    setVisibleCallback(boost::bind(&LLPanelBlockList::removePicker, this));
 
-	m_pBlockList = findChild<LLScrollListCtrl>("block_list");
-	m_pBlockList->setCommitOnDelete(true);
-	m_pBlockList->setCommitOnSelectionChange(true);
-	m_pBlockList->setCommitCallback(boost::bind(&LLPanelBlockList::onSelectionChange, this));
+    m_pBlockList = findChild<LLScrollListCtrl>("block_list");
+    m_pBlockList->setCommitOnDelete(true);
+    m_pBlockList->setCommitOnSelectionChange(true);
+    m_pBlockList->setCommitCallback(boost::bind(&LLPanelBlockList::onSelectionChange, this));
 
-	// Restore last sort order
-	if (U32 nSortValue = gSavedSettings.getU32("BlockMuteSortOrder"))
-		m_pBlockList->sortByColumnIndex(nSortValue >> 4, nSortValue & 0xF);
-	m_pBlockList->setSortChangedCallback(boost::bind(&LLPanelBlockList::onColumnSortChange, this));
+    // Restore last sort order
+    if (U32 nSortValue = gSavedSettings.getU32("BlockMuteSortOrder"))
+        m_pBlockList->sortByColumnIndex(nSortValue >> 4, nSortValue & 0xF);
+    m_pBlockList->setSortChangedCallback(boost::bind(&LLPanelBlockList::onColumnSortChange, this));
 
-	m_pTrashBtn = findChild<LLButton>("block_trash_btn");
+    m_pTrashBtn = findChild<LLButton>("block_trash_btn");
 
-	LLMuteList::getInstance()->addObserver(this);
+    LLMuteList::getInstance()->addObserver(this);
 
-	return TRUE;
+    return TRUE;
 }
 
 // virtual
 void LLPanelBlockList::onOpen(const LLSD& sdParam)
 {
-	refresh();
+    refresh();
 
-	if ( (sdParam.has(BLOCKED_PARAM_NAME)) && (sdParam[BLOCKED_PARAM_NAME].asUUID().notNull()) )
-	{
-		LLMute muteEntry(sdParam[BLOCKED_PARAM_NAME].asUUID());
-		selectEntry(muteEntry);
-	}
+    if ( (sdParam.has(BLOCKED_PARAM_NAME)) && (sdParam[BLOCKED_PARAM_NAME].asUUID().notNull()) )
+    {
+        LLMute muteEntry(sdParam[BLOCKED_PARAM_NAME].asUUID());
+        selectEntry(muteEntry);
+    }
 }
 
 void LLPanelBlockList::refresh()
 {
-	const LLSD& sdSel = m_pBlockList->getSelectedValue();
-
-	LLSD sdGenericRow; LLSD& sdGenericColumns = sdGenericRow["columns"];
-	sdGenericColumns[0]["column"] = "item_name"; sdGenericColumns[0]["type"] = "text";
-	sdGenericColumns[1]["column"] = "item_type"; sdGenericColumns[1]["type"] = "text";
-
-	LLSD sdAgentRow(sdGenericRow); LLSD& sdAgentColumns = sdAgentRow["columns"];
-	sdAgentColumns[2]["column"] = "item_text"; sdAgentColumns[2]["type"] = "checkbox";
-	sdAgentColumns[3]["column"] = "item_voice"; sdAgentColumns[3]["type"] = "checkbox";
-	sdAgentColumns[4]["column"] = "item_particles"; sdAgentColumns[4]["type"] = "checkbox";
-	sdAgentColumns[5]["column"] = "item_sounds"; sdAgentColumns[5]["type"] = "checkbox";
-
-	m_pBlockList->deleteAllItems();
-	const std::vector<LLMute> muteEntries = LLMuteList::getInstance()->getMutes();
-	for (const LLMute& muteEntry : muteEntries)
-	{
-		if ( (!m_strFilter.empty()) && (!boost::icontains(muteEntry.mName, m_strFilter)) )
-			continue;
-
-		switch (muteEntry.mType)
-		{
-			case LLMute::AGENT:
-				{
-					sdAgentRow["value"] = LLSD().with("id", muteEntry.mID).with("name", muteEntry.mName);
-					sdAgentColumns[0]["value"] = muteEntry.mName;
-					sdAgentColumns[1]["value"] = muteEntry.getDisplayType();
-					sdAgentColumns[2]["value"] = (muteEntry.mFlags & LLMute::flagTextChat) == 0;
-					sdAgentColumns[3]["value"] = (muteEntry.mFlags & LLMute::flagVoiceChat) == 0;
-					sdAgentColumns[4]["value"] = (muteEntry.mFlags & LLMute::flagParticles) == 0;
-					sdAgentColumns[5]["value"] = (muteEntry.mFlags & LLMute::flagObjectSounds) == 0;
-					m_pBlockList->addElement(sdAgentRow, boost::bind(&LLPanelBlockList::onToggleMuteFlag, this, _1, _2), ADD_BOTTOM);
-				}
-				break;
-			default:
-				{
-					sdGenericRow["value"] = LLSD().with("id", muteEntry.mID).with("name", muteEntry.mName);
-					sdGenericColumns[0]["value"] = muteEntry.mName;
-					sdGenericColumns[1]["value"] = muteEntry.getDisplayType();
-					m_pBlockList->addElement(sdGenericRow, ADD_BOTTOM);
-				}
-				break;
-		}
-	}
-	selectEntry(sdSel);
+    const LLSD& sdSel = m_pBlockList->getSelectedValue();
+
+    LLSD sdGenericRow; LLSD& sdGenericColumns = sdGenericRow["columns"];
+    sdGenericColumns[0]["column"] = "item_name"; sdGenericColumns[0]["type"] = "text";
+    sdGenericColumns[1]["column"] = "item_type"; sdGenericColumns[1]["type"] = "text";
+
+    LLSD sdAgentRow(sdGenericRow); LLSD& sdAgentColumns = sdAgentRow["columns"];
+    sdAgentColumns[2]["column"] = "item_text"; sdAgentColumns[2]["type"] = "checkbox";
+    sdAgentColumns[3]["column"] = "item_voice"; sdAgentColumns[3]["type"] = "checkbox";
+    sdAgentColumns[4]["column"] = "item_particles"; sdAgentColumns[4]["type"] = "checkbox";
+    sdAgentColumns[5]["column"] = "item_sounds"; sdAgentColumns[5]["type"] = "checkbox";
+
+    m_pBlockList->deleteAllItems();
+    const std::vector<LLMute> muteEntries = LLMuteList::getInstance()->getMutes();
+    for (const LLMute& muteEntry : muteEntries)
+    {
+        if ( (!m_strFilter.empty()) && (!boost::icontains(muteEntry.mName, m_strFilter)) )
+            continue;
+
+        switch (muteEntry.mType)
+        {
+            case LLMute::AGENT:
+                {
+                    sdAgentRow["value"] = LLSD().with("id", muteEntry.mID).with("name", muteEntry.mName);
+                    sdAgentColumns[0]["value"] = muteEntry.mName;
+                    sdAgentColumns[1]["value"] = muteEntry.getDisplayType();
+                    sdAgentColumns[2]["value"] = (muteEntry.mFlags & LLMute::flagTextChat) == 0;
+                    sdAgentColumns[3]["value"] = (muteEntry.mFlags & LLMute::flagVoiceChat) == 0;
+                    sdAgentColumns[4]["value"] = (muteEntry.mFlags & LLMute::flagParticles) == 0;
+                    sdAgentColumns[5]["value"] = (muteEntry.mFlags & LLMute::flagObjectSounds) == 0;
+                    m_pBlockList->addElement(sdAgentRow, boost::bind(&LLPanelBlockList::onToggleMuteFlag, this, _1, _2), ADD_BOTTOM);
+                }
+                break;
+            default:
+                {
+                    sdGenericRow["value"] = LLSD().with("id", muteEntry.mID).with("name", muteEntry.mName);
+                    sdGenericColumns[0]["value"] = muteEntry.mName;
+                    sdGenericColumns[1]["value"] = muteEntry.getDisplayType();
+                    m_pBlockList->addElement(sdGenericRow, ADD_BOTTOM);
+                }
+                break;
+        }
+    }
+    selectEntry(sdSel);
 }
 
 void LLPanelBlockList::removePicker()
 {
-	if (m_hPicker.get())
-	{
-		m_hPicker.get()->closeFloater();
-	}
+    if (m_hPicker.get())
+    {
+        m_hPicker.get()->closeFloater();
+    }
 }
 
 void LLPanelBlockList::selectEntry(const LLMute& muteEntry)
 {
-	const std::vector<LLScrollListItem*> muteItems = m_pBlockList->getAllData();
-	for (auto itItem = muteItems.begin(); itItem != muteItems.end(); ++itItem)
-	{
-		const LLSD& sdValue = (*itItem)->getValue();
-		if ( (muteEntry.mID == sdValue["id"].asUUID()) && ((muteEntry.mName.empty()) ||(muteEntry.mName == sdValue["name"].asString())) )
-		{
-			S32 idxItem = itItem - muteItems.begin();
-			if (idxItem != m_pBlockList->getFirstSelectedIndex())
-			{
-				m_pBlockList->deselectAllItems();
-				m_pBlockList->selectNthItem(idxItem);
-				break;
-			}
-		}
-	}
+    const std::vector<LLScrollListItem*> muteItems = m_pBlockList->getAllData();
+    for (auto itItem = muteItems.begin(); itItem != muteItems.end(); ++itItem)
+    {
+        const LLSD& sdValue = (*itItem)->getValue();
+        if ( (muteEntry.mID == sdValue["id"].asUUID()) && ((muteEntry.mName.empty()) ||(muteEntry.mName == sdValue["name"].asString())) )
+        {
+            S32 idxItem = itItem - muteItems.begin();
+            if (idxItem != m_pBlockList->getFirstSelectedIndex())
+            {
+                m_pBlockList->deselectAllItems();
+                m_pBlockList->selectNthItem(idxItem);
+                break;
+            }
+        }
+    }
 }
 
 void LLPanelBlockList::setFilterString(const std::string& strFilter)
 {
-	m_strFilter = strFilter;
-	refresh();
+    m_strFilter = strFilter;
+    refresh();
 }
 
 void LLPanelBlockList::updateButtons()
 {
-	bool fHasSelection = (nullptr != m_pBlockList->getFirstSelected());
-	m_pTrashBtn->setEnabled(fHasSelection);
+    bool fHasSelection = (nullptr != m_pBlockList->getFirstSelected());
+    m_pTrashBtn->setEnabled(fHasSelection);
 }
 
 void LLPanelBlockList::onChange()
 {
-	if (m_fRefreshOnChange)
-	{
-		refresh();
-	}
+    if (m_fRefreshOnChange)
+    {
+        refresh();
+    }
 }
 
 void LLPanelBlockList::onAddAvatar(LLUICtrl* pCtrl)
 {
-	if (!m_hPicker.isDead())
-	{
-		m_hPicker.get()->setVisibleAndFrontmost(true);
-		return;
-	}
+    if (!m_hPicker.isDead())
+    {
+        m_hPicker.get()->setVisibleAndFrontmost(true);
+        return;
+    }
 
-	if (LLFloater* pRootFloater = gFloaterView->getParentFloater(pCtrl))
-	{
-		LLFloaterAvatarPicker* pPicker = LLFloaterAvatarPicker::show(
-			boost::bind(&LLPanelBlockList::onAddAvatarCallback, _1, _2),
-			false /*allow_multiple*/, true /*close_on_select*/, false /*skip_agent*/, pRootFloater->getName(), pCtrl);
-		pRootFloater->addDependentFloater(pPicker);
-		m_hPicker = pPicker->getHandle();
-	}
+    if (LLFloater* pRootFloater = gFloaterView->getParentFloater(pCtrl))
+    {
+        LLFloaterAvatarPicker* pPicker = LLFloaterAvatarPicker::show(
+            boost::bind(&LLPanelBlockList::onAddAvatarCallback, _1, _2),
+            false /*allow_multiple*/, true /*close_on_select*/, false /*skip_agent*/, pRootFloater->getName(), pCtrl);
+        pRootFloater->addDependentFloater(pPicker);
+        m_hPicker = pPicker->getHandle();
+    }
 }
 
 // static
 void LLPanelBlockList::onAddAvatarCallback(const uuid_vec_t& idAgents, const std::vector<LLAvatarName>& avAgents)
 {
-	if ( (idAgents.empty()) || (avAgents.empty()) )
-	{
-		return;
-	}
+    if ( (idAgents.empty()) || (avAgents.empty()) )
+    {
+        return;
+    }
 
-	LLMute mute(idAgents[0], avAgents[0].getLegacyName(), LLMute::AGENT);
-	if (LLMuteList::getInstance()->add(mute))
-	{
-		LLFloaterBlocked::showMuteAndSelect(mute.mID);
-	}
+    LLMute mute(idAgents[0], avAgents[0].getLegacyName(), LLMute::AGENT);
+    if (LLMuteList::getInstance()->add(mute))
+    {
+        LLFloaterBlocked::showMuteAndSelect(mute.mID);
+    }
 }
 
 // static
 void LLPanelBlockList::onAddByName()
 {
-	LLFloaterGetBlockedObjectName::show(&LLPanelBlockList::onAddByNameCallback);
+    LLFloaterGetBlockedObjectName::show(&LLPanelBlockList::onAddByNameCallback);
 }
 
 // static
 void LLPanelBlockList::onAddByNameCallback(const std::string& strBlockName)
 {
-	if (strBlockName.empty())
-	{
-		return;
-	}
+    if (strBlockName.empty())
+    {
+        return;
+    }
 
-	LLMute mute(LLUUID::null, strBlockName, LLMute::BY_NAME);
-	if (!LLMuteList::getInstance()->add(mute))
-	{
-		LLNotificationsUtil::add("MuteByNameFailed");
-	}
+    LLMute mute(LLUUID::null, strBlockName, LLMute::BY_NAME);
+    if (!LLMuteList::getInstance()->add(mute))
+    {
+        LLNotificationsUtil::add("MuteByNameFailed");
+    }
 }
 
 void LLPanelBlockList::onRemoveSelection()
 {
-	m_fRefreshOnChange = false;
+    m_fRefreshOnChange = false;
 
-	std::vector<LLScrollListItem*> selItems = m_pBlockList->getAllSelected();
-	for (std::vector<LLScrollListItem*>::iterator itItem = selItems.begin(); itItem != selItems.end(); ++itItem)
-	{
-		LLScrollListItem* pSelItem = *itItem; const LLSD sdValue = pSelItem->getValue();
+    std::vector<LLScrollListItem*> selItems = m_pBlockList->getAllSelected();
+    for (std::vector<LLScrollListItem*>::iterator itItem = selItems.begin(); itItem != selItems.end(); ++itItem)
+    {
+        LLScrollListItem* pSelItem = *itItem; const LLSD sdValue = pSelItem->getValue();
 
-		LLMute selMute(sdValue["id"].asUUID(), sdValue["name"].asString());
-		if (LLMuteList::getInstance()->remove(selMute))
-		{
-			m_pBlockList->deleteSingleItem(pSelItem);
-		}
-	}
+        LLMute selMute(sdValue["id"].asUUID(), sdValue["name"].asString());
+        if (LLMuteList::getInstance()->remove(selMute))
+        {
+            m_pBlockList->deleteSingleItem(pSelItem);
+        }
+    }
 
-	m_fRefreshOnChange = true;
+    m_fRefreshOnChange = true;
 }
 
 void LLPanelBlockList::onColumnSortChange()
 {
-	U32 nSortValue = 0;
+    U32 nSortValue = 0;
 
-	S32 idxColumn = m_pBlockList->getSortColumnIndex();
-	if (-1 != idxColumn)
-	{
-		nSortValue = idxColumn << 4 | ((m_pBlockList->getSortAscending()) ? 1 : 0);
-	}
+    S32 idxColumn = m_pBlockList->getSortColumnIndex();
+    if (-1 != idxColumn)
+    {
+        nSortValue = idxColumn << 4 | ((m_pBlockList->getSortAscending()) ? 1 : 0);
+    }
 
-	gSavedSettings.setU32("BlockMuteSortOrder", nSortValue);
+    gSavedSettings.setU32("BlockMuteSortOrder", nSortValue);
 }
 
 void LLPanelBlockList::onIdleRefresh(LLHandle<LLPanel> hPanel)
 {
-	if (!hPanel.isDead())
-	{
-		((LLPanelBlockList*)hPanel.get())->refresh();
-	}
+    if (!hPanel.isDead())
+    {
+        ((LLPanelBlockList*)hPanel.get())->refresh();
+    }
 }
 
 void LLPanelBlockList::onSelectionChange()
 {
-	updateButtons();
+    updateButtons();
 }
 
 void LLPanelBlockList::onToggleMuteFlag(const LLSD& sdValue, const LLScrollListCell* pCell)
 {
-	if (!pCell)
-		return;
+    if (!pCell)
+        return;
 
-	LLMute muteEntry(sdValue["id"].asUUID(), sdValue["name"].asString(), LLMute::AGENT); U32 muteFlag = 0;
+    LLMute muteEntry(sdValue["id"].asUUID(), sdValue["name"].asString(), LLMute::AGENT); U32 muteFlag = 0;
 
-	const std::string& strColumnName = pCell->getColumnName();
-	if ("item_text" == strColumnName)
-		muteFlag = LLMute::flagTextChat;
-	else if ("item_voice" == strColumnName)
-		muteFlag = LLMute::flagVoiceChat;
-	else if ("item_particles" == strColumnName)
-		muteFlag = LLMute::flagParticles;
-	else if ("item_sounds" == strColumnName)
-		muteFlag = LLMute::flagObjectSounds;
+    const std::string& strColumnName = pCell->getColumnName();
+    if ("item_text" == strColumnName)
+        muteFlag = LLMute::flagTextChat;
+    else if ("item_voice" == strColumnName)
+        muteFlag = LLMute::flagVoiceChat;
+    else if ("item_particles" == strColumnName)
+        muteFlag = LLMute::flagParticles;
+    else if ("item_sounds" == strColumnName)
+        muteFlag = LLMute::flagObjectSounds;
 
-	if (muteFlag)
-	{
-		m_fRefreshOnChange = false;
-		if (pCell->getValue().asBoolean())
-			LLMuteList::getInstance()->add(muteEntry, muteFlag);
-		else
-			LLMuteList::getInstance()->remove(muteEntry, muteFlag);
-		m_fRefreshOnChange = true;
+    if (muteFlag)
+    {
+        m_fRefreshOnChange = false;
+        if (pCell->getValue().asBoolean())
+            LLMuteList::getInstance()->add(muteEntry, muteFlag);
+        else
+            LLMuteList::getInstance()->remove(muteEntry, muteFlag);
+        m_fRefreshOnChange = true;
 
-		selectEntry(muteEntry);
+        selectEntry(muteEntry);
 
-		// Refreshing now will invalidate an iterator upstream so do it on the next idle tick
-		doOnIdleOneTime(boost::bind(&LLPanelBlockList::onIdleRefresh, getHandle()));
-	}
+        // Refreshing now will invalidate an iterator upstream so do it on the next idle tick
+        doOnIdleOneTime(boost::bind(&LLPanelBlockList::onIdleRefresh, getHandle()));
+    }
 }
 
 // ============================================================================
@@ -340,102 +340,102 @@ void LLPanelBlockList::onToggleMuteFlag(const LLSD& sdValue, const LLScrollListC
 static LLPanelInjector<LLPanelDerenderList> t_panel_derender_list("panel_derender_list");
 
 LLPanelDerenderList::LLPanelDerenderList()
-	: LLPanel()
-	, m_pDerenderList(NULL)
+    : LLPanel()
+    , m_pDerenderList(NULL)
 {
 }
 
 LLPanelDerenderList::~LLPanelDerenderList()
 {
-	m_DerenderChangeConn.disconnect();
+    m_DerenderChangeConn.disconnect();
 }
 
 BOOL LLPanelDerenderList::postBuild()
 {
-	m_pDerenderList = findChild<LLScrollListCtrl>("derender_list");
-	m_pDerenderList->setCommitCallback(boost::bind(&LLPanelDerenderList::onSelectionChange, this));
-	m_pDerenderList->setCommitOnDelete(true);
-	m_pDerenderList->setCommitOnSelectionChange(true);
+    m_pDerenderList = findChild<LLScrollListCtrl>("derender_list");
+    m_pDerenderList->setCommitCallback(boost::bind(&LLPanelDerenderList::onSelectionChange, this));
+    m_pDerenderList->setCommitOnDelete(true);
+    m_pDerenderList->setCommitOnSelectionChange(true);
 
-	// Restore last sort order
-	U32 nSortValue = gSavedSettings.getU32("BlockDerenderSortOrder");
-	if (nSortValue)
-	{
-		m_pDerenderList->sortByColumnIndex(nSortValue >> 4, nSortValue & 0xF);
-	}
-	m_pDerenderList->setSortChangedCallback(boost::bind(&LLPanelDerenderList::onColumnSortChange, this));
+    // Restore last sort order
+    U32 nSortValue = gSavedSettings.getU32("BlockDerenderSortOrder");
+    if (nSortValue)
+    {
+        m_pDerenderList->sortByColumnIndex(nSortValue >> 4, nSortValue & 0xF);
+    }
+    m_pDerenderList->setSortChangedCallback(boost::bind(&LLPanelDerenderList::onColumnSortChange, this));
 
-	m_DerenderChangeConn = LLDerenderList::setChangeCallback(boost::bind(&LLPanelDerenderList::refresh, this));
-	findChild<LLUICtrl>("derender_trash_btn")->setCommitCallback(boost::bind(&LLPanelDerenderList::onSelectionRemove, this));
+    m_DerenderChangeConn = LLDerenderList::setChangeCallback(boost::bind(&LLPanelDerenderList::refresh, this));
+    findChild<LLUICtrl>("derender_trash_btn")->setCommitCallback(boost::bind(&LLPanelDerenderList::onSelectionRemove, this));
 
-	return TRUE;
+    return TRUE;
 }
 
 void LLPanelDerenderList::onOpen(const LLSD& sdParam)
 {
-	refresh();
+    refresh();
 
-	if ( (sdParam.has(DERENDER_PARAM_NAME)) && (sdParam[DERENDER_PARAM_NAME].asUUID().notNull()) )
-	{
-		m_pDerenderList->selectByID(sdParam[DERENDER_PARAM_NAME].asUUID());
-	}
+    if ( (sdParam.has(DERENDER_PARAM_NAME)) && (sdParam[DERENDER_PARAM_NAME].asUUID().notNull()) )
+    {
+        m_pDerenderList->selectByID(sdParam[DERENDER_PARAM_NAME].asUUID());
+    }
 }
 
 void LLPanelDerenderList::onColumnSortChange()
 {
-	U32 nSortValue = 0;
-	
-	S32 idxColumn = m_pDerenderList->getSortColumnIndex();
-	if (-1 != idxColumn)
-	{
-		nSortValue = idxColumn << 4 | ((m_pDerenderList->getSortAscending()) ? 1 : 0);
-	}
+    U32 nSortValue = 0;
 
-	gSavedSettings.setU32("BlockDerenderSortOrder", nSortValue);
+    S32 idxColumn = m_pDerenderList->getSortColumnIndex();
+    if (-1 != idxColumn)
+    {
+        nSortValue = idxColumn << 4 | ((m_pDerenderList->getSortAscending()) ? 1 : 0);
+    }
+
+    gSavedSettings.setU32("BlockDerenderSortOrder", nSortValue);
 }
 
 void LLPanelDerenderList::onSelectionChange()
 {
-	bool hasSelected = (NULL != m_pDerenderList->getFirstSelected());
-	getChildView("derender_trash_btn")->setEnabled(hasSelected);
+    bool hasSelected = (NULL != m_pDerenderList->getFirstSelected());
+    getChildView("derender_trash_btn")->setEnabled(hasSelected);
 }
 
 void LLPanelDerenderList::onSelectionRemove()
 {
-	std::vector<LLScrollListItem*> selItems = m_pDerenderList->getAllSelected(); uuid_vec_t idsObject;
-//	std::for_each(selItems.begin(), selItems.end(), [&idsObject](const LLScrollListItem* i) { idsObject.push_back(i->getValue().asUUID()); });
-	for (std::vector<LLScrollListItem*>::iterator itItem = selItems.begin(); itItem != selItems.end(); ++itItem)
-	{
-		idsObject.push_back((*itItem)->getValue().asUUID());
-	}
+    std::vector<LLScrollListItem*> selItems = m_pDerenderList->getAllSelected(); uuid_vec_t idsObject;
+//  std::for_each(selItems.begin(), selItems.end(), [&idsObject](const LLScrollListItem* i) { idsObject.push_back(i->getValue().asUUID()); });
+    for (std::vector<LLScrollListItem*>::iterator itItem = selItems.begin(); itItem != selItems.end(); ++itItem)
+    {
+        idsObject.push_back((*itItem)->getValue().asUUID());
+    }
 
-	LLDerenderList::instance().removeObjects(LLDerenderEntry::TYPE_OBJECT, idsObject);
+    LLDerenderList::instance().removeObjects(LLDerenderEntry::TYPE_OBJECT, idsObject);
 }
 
 void LLPanelDerenderList::refresh()
 {
-	m_pDerenderList->clearRows();
-	if (LLDerenderList::instanceExists())
-	{
-		LLSD sdRow;	LLSD& sdColumns = sdRow["columns"];
-		sdColumns[0]["column"] = "object_name";   sdColumns[0]["type"] = "text";
-		sdColumns[1]["column"] = "location";      sdColumns[1]["type"] = "text";
-		sdColumns[2]["column"] = "derender_type"; sdColumns[2]["type"] = "text";
-
-		for (const auto& pEntry : LLDerenderList::instance().getEntries())
-		{
-			sdRow["value"] = pEntry->getID();
-			sdColumns[0]["value"] = pEntry->getName();
-			if (LLDerenderEntry::TYPE_OBJECT == pEntry->getType())
-			{
-				auto pObjEntry = static_cast<LLDerenderObject*>(pEntry.get());
-				sdColumns[1]["value"] = fmt::format(FMT_STRING("{} <{}, {}, {}>"), pObjEntry->strRegionName, ll_round(pObjEntry->posRegion.mV[VX]), ll_round(pObjEntry->posRegion.mV[VY]), ll_round(pObjEntry->posRegion.mV[VZ]));
-			}
-			sdColumns[2]["value"] = (pEntry->isPersistent()) ? LLTrans::getString("Permanent") : LLTrans::getString("Temporary");
-
-			m_pDerenderList->addElement(sdRow, ADD_BOTTOM);
-		}
-	}
+    m_pDerenderList->clearRows();
+    if (LLDerenderList::instanceExists())
+    {
+        LLSD sdRow; LLSD& sdColumns = sdRow["columns"];
+        sdColumns[0]["column"] = "object_name";   sdColumns[0]["type"] = "text";
+        sdColumns[1]["column"] = "location";      sdColumns[1]["type"] = "text";
+        sdColumns[2]["column"] = "derender_type"; sdColumns[2]["type"] = "text";
+
+        for (const auto& pEntry : LLDerenderList::instance().getEntries())
+        {
+            sdRow["value"] = pEntry->getID();
+            sdColumns[0]["value"] = pEntry->getName();
+            if (LLDerenderEntry::TYPE_OBJECT == pEntry->getType())
+            {
+                auto pObjEntry = static_cast<LLDerenderObject*>(pEntry.get());
+                sdColumns[1]["value"] = fmt::format(FMT_STRING("{} <{}, {}, {}>"), pObjEntry->strRegionName, ll_round(pObjEntry->posRegion.mV[VX]), ll_round(pObjEntry->posRegion.mV[VY]), ll_round(pObjEntry->posRegion.mV[VZ]));
+            }
+            sdColumns[2]["value"] = (pEntry->isPersistent()) ? LLTrans::getString("Permanent") : LLTrans::getString("Temporary");
+
+            m_pDerenderList->addElement(sdRow, ADD_BOTTOM);
+        }
+    }
 }
 
 // ============================================================================
@@ -445,114 +445,114 @@ void LLPanelDerenderList::refresh()
 static LLPanelInjector<LLPanelAssetBlocklist> t_panel_asset_list("panel_asset_block_list");
 
 LLPanelAssetBlocklist::LLPanelAssetBlocklist()
-	: LLPanel()
+    : LLPanel()
 {
 }
 
 LLPanelAssetBlocklist::~LLPanelAssetBlocklist()
 {
-	mAssetBlocklistChangeConn.disconnect();
+    mAssetBlocklistChangeConn.disconnect();
 }
 
 BOOL LLPanelAssetBlocklist::postBuild()
 {
-	mAssetBlocklist = findChild<LLScrollListCtrl>("asset_list");
-	mAssetBlocklist->setCommitCallback(boost::bind(&LLPanelAssetBlocklist::onSelectionChange, this));
-	mAssetBlocklist->setCommitOnDelete(true);
-	mAssetBlocklist->setCommitOnSelectionChange(true);
+    mAssetBlocklist = findChild<LLScrollListCtrl>("asset_list");
+    mAssetBlocklist->setCommitCallback(boost::bind(&LLPanelAssetBlocklist::onSelectionChange, this));
+    mAssetBlocklist->setCommitOnDelete(true);
+    mAssetBlocklist->setCommitOnSelectionChange(true);
 
-	// Restore last sort order
-	U32 nSortValue = gSavedSettings.getU32("BlockAssetSortOrder");
-	if (nSortValue)
-	{
-		mAssetBlocklist->sortByColumnIndex(nSortValue >> 4, nSortValue & 0xF);
-	}
-	mAssetBlocklist->setSortChangedCallback(boost::bind(&LLPanelAssetBlocklist::onColumnSortChange, this));
+    // Restore last sort order
+    U32 nSortValue = gSavedSettings.getU32("BlockAssetSortOrder");
+    if (nSortValue)
+    {
+        mAssetBlocklist->sortByColumnIndex(nSortValue >> 4, nSortValue & 0xF);
+    }
+    mAssetBlocklist->setSortChangedCallback(boost::bind(&LLPanelAssetBlocklist::onColumnSortChange, this));
 
-	mAssetBlocklistChangeConn = ALAssetBlocklist::instance().setChangeCallback(boost::bind(&LLPanelAssetBlocklist::refresh, this));
-	findChild<LLUICtrl>("asset_trash_btn")->setCommitCallback(boost::bind(&LLPanelAssetBlocklist::onSelectionRemove, this));
+    mAssetBlocklistChangeConn = ALAssetBlocklist::instance().setChangeCallback(boost::bind(&LLPanelAssetBlocklist::refresh, this));
+    findChild<LLUICtrl>("asset_trash_btn")->setCommitCallback(boost::bind(&LLPanelAssetBlocklist::onSelectionRemove, this));
 
-	return TRUE;
+    return TRUE;
 }
 
 void LLPanelAssetBlocklist::onOpen(const LLSD& sdParam)
 {
-	refresh();
+    refresh();
 
-	if ((sdParam.has(ASSET_PARAM_NAME)) && (sdParam[ASSET_PARAM_NAME].asUUID().notNull()))
-	{
-		mAssetBlocklist->selectByID(sdParam[ASSET_PARAM_NAME].asUUID());
-	}
+    if ((sdParam.has(ASSET_PARAM_NAME)) && (sdParam[ASSET_PARAM_NAME].asUUID().notNull()))
+    {
+        mAssetBlocklist->selectByID(sdParam[ASSET_PARAM_NAME].asUUID());
+    }
 }
 
 void LLPanelAssetBlocklist::onColumnSortChange()
 {
-	U32 nSortValue = 0;
+    U32 nSortValue = 0;
 
-	S32 idxColumn = mAssetBlocklist->getSortColumnIndex();
-	if (-1 != idxColumn)
-	{
-		nSortValue = idxColumn << 4 | ((mAssetBlocklist->getSortAscending()) ? 1 : 0);
-	}
+    S32 idxColumn = mAssetBlocklist->getSortColumnIndex();
+    if (-1 != idxColumn)
+    {
+        nSortValue = idxColumn << 4 | ((mAssetBlocklist->getSortAscending()) ? 1 : 0);
+    }
 
-	gSavedSettings.setU32("BlockAssetSortOrder", nSortValue);
+    gSavedSettings.setU32("BlockAssetSortOrder", nSortValue);
 }
 
 void LLPanelAssetBlocklist::onSelectionChange()
 {
-	bool hasSelected = (NULL != mAssetBlocklist->getFirstSelected());
-	getChildView("asset_trash_btn")->setEnabled(hasSelected);
+    bool hasSelected = (NULL != mAssetBlocklist->getFirstSelected());
+    getChildView("asset_trash_btn")->setEnabled(hasSelected);
 }
 
 void LLPanelAssetBlocklist::onSelectionRemove()
 {
-	uuid_vec_t ids;
-	std::vector<LLScrollListItem*> selItems = mAssetBlocklist->getAllSelected(); 
-	for (LLScrollListItem* itemp : selItems)
-	{
-		ids.push_back(itemp->getValue().asUUID());
-	}
+    uuid_vec_t ids;
+    std::vector<LLScrollListItem*> selItems = mAssetBlocklist->getAllSelected();
+    for (LLScrollListItem* itemp : selItems)
+    {
+        ids.push_back(itemp->getValue().asUUID());
+    }
 
-	ALAssetBlocklist::instance().removeEntries(ids);
+    ALAssetBlocklist::instance().removeEntries(ids);
 }
 
 void LLPanelAssetBlocklist::refresh()
 {
-	mAssetBlocklist->clearRows();
-	if (ALAssetBlocklist::instanceExists())
-	{
-		LLSD sdRow;	LLSD& sdColumns = sdRow["columns"];
-		sdColumns[0]["column"] = "name";  sdColumns[0]["type"] = "text";
-		sdColumns[1]["column"] = "location"; sdColumns[1]["type"] = "text";
-		sdColumns[2]["column"] = "asset_type";    sdColumns[2]["type"] = "text";
-		sdColumns[3]["column"] = "date";  sdColumns[3]["type"] = "text";
-		sdColumns[4]["column"] = "persist";  sdColumns[4]["type"] = "text";
-
-		for (const auto& [key, data] : ALAssetBlocklist::instance().getEntries())
-		{
-			sdRow["value"] = key;
-
-			std::string owner_name = "Unknown";
-			LLAvatarName avName;
-			if (LLAvatarNameCache::get(data.mOwnerID, &avName))
-			{
-				owner_name = avName.getUserName();
-			}
-			sdColumns[0]["value"] = owner_name;
-			sdColumns[1]["value"] = data.mLocation;
-			sdColumns[2]["value"] = LLTrans::getString(LLAssetType::lookupHumanReadable(data.mAssetType));
-
-			std::string timeStr = getString("blockedDate");
-			LLSD substitution;
-			substitution["datetime"] = (S32)data.mDate.secondsSinceEpoch();
-			LLStringUtil::format(timeStr, substitution);
-
-			sdColumns[3]["value"] = timeStr;
-			sdColumns[4]["value"] = data.mPersist ? LLTrans::getString("Permanent") : LLTrans::getString("Temporary");
-			
-			mAssetBlocklist->addElement(sdRow, ADD_BOTTOM);
-		}
-	}
+    mAssetBlocklist->clearRows();
+    if (ALAssetBlocklist::instanceExists())
+    {
+        LLSD sdRow; LLSD& sdColumns = sdRow["columns"];
+        sdColumns[0]["column"] = "name";  sdColumns[0]["type"] = "text";
+        sdColumns[1]["column"] = "location"; sdColumns[1]["type"] = "text";
+        sdColumns[2]["column"] = "asset_type";    sdColumns[2]["type"] = "text";
+        sdColumns[3]["column"] = "date";  sdColumns[3]["type"] = "text";
+        sdColumns[4]["column"] = "persist";  sdColumns[4]["type"] = "text";
+
+        for (const auto& [key, data] : ALAssetBlocklist::instance().getEntries())
+        {
+            sdRow["value"] = key;
+
+            std::string owner_name = "Unknown";
+            LLAvatarName avName;
+            if (LLAvatarNameCache::get(data.mOwnerID, &avName))
+            {
+                owner_name = avName.getUserName();
+            }
+            sdColumns[0]["value"] = owner_name;
+            sdColumns[1]["value"] = data.mLocation;
+            sdColumns[2]["value"] = LLTrans::getString(LLAssetType::lookupHumanReadable(data.mAssetType));
+
+            std::string timeStr = getString("blockedDate");
+            LLSD substitution;
+            substitution["datetime"] = (S32)data.mDate.secondsSinceEpoch();
+            LLStringUtil::format(timeStr, substitution);
+
+            sdColumns[3]["value"] = timeStr;
+            sdColumns[4]["value"] = data.mPersist ? LLTrans::getString("Permanent") : LLTrans::getString("Temporary");
+
+            mAssetBlocklist->addElement(sdRow, ADD_BOTTOM);
+        }
+    }
 }
 
 // ============================================================================
@@ -562,26 +562,26 @@ void LLPanelAssetBlocklist::refresh()
 class LLPanelAvatarRenderingContextMenu : public LLListContextMenu
 {
 public:
-	LLPanelAvatarRenderingContextMenu(LLPanelAvatarRendering* pAvRenderingPanel)
-		: m_pAvRenderingPanel(pAvRenderingPanel)
-	{
-	}
+    LLPanelAvatarRenderingContextMenu(LLPanelAvatarRendering* pAvRenderingPanel)
+        : m_pAvRenderingPanel(pAvRenderingPanel)
+    {
+    }
 
 protected:
-	LLContextMenu* createMenu() override
-	{
-		LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
-		registrar.add("Settings.SetRendering", boost::bind(&LLPanelAvatarRendering::onSetException, m_pAvRenderingPanel, mUUIDs.front(), _2));
+    LLContextMenu* createMenu() override
+    {
+        LLUICtrl::CommitCallbackRegistry::ScopedRegistrar registrar;
+        registrar.add("Settings.SetRendering", boost::bind(&LLPanelAvatarRendering::onSetException, m_pAvRenderingPanel, mUUIDs.front(), _2));
 
-		LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
-		enable_registrar.add("Settings.IsSelected", boost::bind(&LLPanelAvatarRendering::onHasException, m_pAvRenderingPanel, mUUIDs.front(), _2));
+        LLUICtrl::EnableCallbackRegistry::ScopedRegistrar enable_registrar;
+        enable_registrar.add("Settings.IsSelected", boost::bind(&LLPanelAvatarRendering::onHasException, m_pAvRenderingPanel, mUUIDs.front(), _2));
 
-		LLContextMenu* pMenu = createFromFile("menu_avatar_rendering_settings.xml");
-		return pMenu;
-	}
+        LLContextMenu* pMenu = createFromFile("menu_avatar_rendering_settings.xml");
+        return pMenu;
+    }
 
 protected:
-	LLPanelAvatarRendering* m_pAvRenderingPanel;
+    LLPanelAvatarRendering* m_pAvRenderingPanel;
 };
 
 // ============================================================================
@@ -590,28 +590,28 @@ class LLPanelAvatarRenderingContextMenu : public LLListContextMenu
 
 static std::string createTimestamp(S32 datetime)
 {
-	std::string timeStr = "[" + LLTrans::getString("TimeMonth") + "]/[" + LLTrans::getString("TimeDay") + "]/[" + LLTrans::getString("TimeYear") + "]";
-	LLStringUtil::format(timeStr, LLSD().with("datetime", datetime));
-	return timeStr;
+    std::string timeStr = "[" + LLTrans::getString("TimeMonth") + "]/[" + LLTrans::getString("TimeDay") + "]/[" + LLTrans::getString("TimeYear") + "]";
+    LLStringUtil::format(timeStr, LLSD().with("datetime", datetime));
+    return timeStr;
 }
 
 static LLVOAvatar* findAvatar(const LLUUID& idAgent)
 {
-	LLViewerObject* pAvObj = gObjectList.findObject(idAgent);
-	while ( (pAvObj) && (pAvObj->isAttachment()) )
-		pAvObj = (LLViewerObject*)pAvObj->getParent();
+    LLViewerObject* pAvObj = gObjectList.findObject(idAgent);
+    while ( (pAvObj) && (pAvObj->isAttachment()) )
+        pAvObj = (LLViewerObject*)pAvObj->getParent();
 
-	if ((pAvObj) && (pAvObj->isAvatar()) )
-		return (LLVOAvatar*)pAvObj;
-	return nullptr;
+    if ((pAvObj) && (pAvObj->isAvatar()) )
+        return (LLVOAvatar*)pAvObj;
+    return nullptr;
 }
 
 static void setAvatarRenderSetting(const LLUUID& idAgent, LLVOAvatar::VisualMuteSettings eSetting)
 {
-	if (LLVOAvatar* pAvatar = findAvatar(idAgent))
-		pAvatar->setVisualMuteSettings(LLVOAvatar::VisualMuteSettings(eSetting));
-	else
-		LLRenderMuteList::getInstance()->saveVisualMuteSetting(idAgent, eSetting);
+    if (LLVOAvatar* pAvatar = findAvatar(idAgent))
+        pAvatar->setVisualMuteSettings(LLVOAvatar::VisualMuteSettings(eSetting));
+    else
+        LLRenderMuteList::getInstance()->saveVisualMuteSetting(idAgent, eSetting);
 }
 
 // ============================================================================
@@ -621,218 +621,218 @@ static void setAvatarRenderSetting(const LLUUID& idAgent, LLVOAvatar::VisualMute
 static LLPanelInjector<LLPanelAvatarRendering> t_panel_block_avatar_rendering("panel_block_avatar_rendering");
 
 LLPanelAvatarRendering::LLPanelAvatarRendering()
-	: LLPanel()
+    : LLPanel()
 {
-	mCommitCallbackRegistrar.add("Rendering.AddException", boost::bind(&LLPanelAvatarRendering::onAddException, this, _1, _2));
-	mCommitCallbackRegistrar.add("Rendering.RemoveException", boost::bind(&LLPanelAvatarRendering::onRemoveException, this));
+    mCommitCallbackRegistrar.add("Rendering.AddException", boost::bind(&LLPanelAvatarRendering::onAddException, this, _1, _2));
+    mCommitCallbackRegistrar.add("Rendering.RemoveException", boost::bind(&LLPanelAvatarRendering::onRemoveException, this));
 }
 
 LLPanelAvatarRendering::~LLPanelAvatarRendering()
 {
-	delete m_pContextMenu;
-	LLRenderMuteList::getInstance()->removeObserver(this);
+    delete m_pContextMenu;
+    LLRenderMuteList::getInstance()->removeObserver(this);
 }
 
 // virtual
 BOOL LLPanelAvatarRendering::postBuild()
 {
-	setVisibleCallback(boost::bind(&LLPanelAvatarRendering::removePicker, this));
+    setVisibleCallback(boost::bind(&LLPanelAvatarRendering::removePicker, this));
 
-	m_pExceptionList = findChild<LLNameListCtrl>("exception_list");
-	m_pExceptionList->setCommitOnDelete(true);
-	m_pExceptionList->setCommitOnSelectionChange(true);
-	m_pExceptionList->setCommitCallback(boost::bind(&LLPanelAvatarRendering::onSelectionChange, this));
-	m_pExceptionList->setRightMouseDownCallback(boost::bind(&LLPanelAvatarRendering::onExceptionMenu, this, _2, _3));
+    m_pExceptionList = findChild<LLNameListCtrl>("exception_list");
+    m_pExceptionList->setCommitOnDelete(true);
+    m_pExceptionList->setCommitOnSelectionChange(true);
+    m_pExceptionList->setCommitCallback(boost::bind(&LLPanelAvatarRendering::onSelectionChange, this));
+    m_pExceptionList->setRightMouseDownCallback(boost::bind(&LLPanelAvatarRendering::onExceptionMenu, this, _2, _3));
 
-	// Restore last sort order
-	if (U32 nSortValue = gSavedSettings.getU32("BlockRenderingSortOrder"))
-		m_pExceptionList->sortByColumnIndex(nSortValue >> 4, nSortValue & 0xF);
-	m_pExceptionList->setSortChangedCallback(boost::bind(&LLPanelAvatarRendering::onColumnSortChange, this));
+    // Restore last sort order
+    if (U32 nSortValue = gSavedSettings.getU32("BlockRenderingSortOrder"))
+        m_pExceptionList->sortByColumnIndex(nSortValue >> 4, nSortValue & 0xF);
+    m_pExceptionList->setSortChangedCallback(boost::bind(&LLPanelAvatarRendering::onColumnSortChange, this));
 
-	m_pTrashBtn = findChild<LLButton>("rendering_exception_trash_btn");
+    m_pTrashBtn = findChild<LLButton>("rendering_exception_trash_btn");
 
-	LLRenderMuteList::getInstance()->addObserver(this);
-	m_pContextMenu = new LLPanelAvatarRenderingContextMenu(this);
+    LLRenderMuteList::getInstance()->addObserver(this);
+    m_pContextMenu = new LLPanelAvatarRenderingContextMenu(this);
 
-	return TRUE;
+    return TRUE;
 }
 
 // virtual
 void LLPanelAvatarRendering::onOpen(const LLSD& sdParam)
 {
-	refresh();
+    refresh();
 
-	if ((sdParam.has(EXCEPTION_PARAM_NAME)) && (sdParam[EXCEPTION_PARAM_NAME].asUUID().notNull()))
-	{
-		m_pExceptionList->selectByID(sdParam[EXCEPTION_PARAM_NAME].asUUID());
-	}
+    if ((sdParam.has(EXCEPTION_PARAM_NAME)) && (sdParam[EXCEPTION_PARAM_NAME].asUUID().notNull()))
+    {
+        m_pExceptionList->selectByID(sdParam[EXCEPTION_PARAM_NAME].asUUID());
+    }
 }
 
 void LLPanelAvatarRendering::refresh()
 {
-	const LLUUID idSel = m_pExceptionList->getSelectedValue().asUUID();
+    const LLUUID idSel = m_pExceptionList->getSelectedValue().asUUID();
 
-	m_pExceptionList->deleteAllItems();
+    m_pExceptionList->deleteAllItems();
 
-	LLAvatarName avName; LLNameListCtrl::NameItem paramItem;
-	for (const auto& kvEntry : LLRenderMuteList::getInstance()->sVisuallyMuteSettingsMap)
-	{
-		if ( (!LLAvatarNameCache::get(kvEntry.first, &avName)) || ((!m_strFilter.empty()) && (!boost::icontains(avName.getCompleteName(), m_strFilter))) )
-			continue;
+    LLAvatarName avName; LLNameListCtrl::NameItem paramItem;
+    for (const auto& kvEntry : LLRenderMuteList::getInstance()->sVisuallyMuteSettingsMap)
+    {
+        if ( (!LLAvatarNameCache::get(kvEntry.first, &avName)) || ((!m_strFilter.empty()) && (!boost::icontains(avName.getCompleteName(), m_strFilter))) )
+            continue;
 
-		paramItem.value = kvEntry.first;
-		paramItem.columns.add().value(avName.getCompleteName()).column("name");
-		paramItem.columns.add().value(getString(kvEntry.second == 1 ? "av_never_render" : "av_always_render")).column("setting");
-		paramItem.columns.add().value(createTimestamp(LLRenderMuteList::getInstance()->getVisualMuteDate(kvEntry.first))).column("timestamp");
-		m_pExceptionList->addNameItemRow(paramItem);
-	}
+        paramItem.value = kvEntry.first;
+        paramItem.columns.add().value(avName.getCompleteName()).column("name");
+        paramItem.columns.add().value(getString(kvEntry.second == 1 ? "av_never_render" : "av_always_render")).column("setting");
+        paramItem.columns.add().value(createTimestamp(LLRenderMuteList::getInstance()->getVisualMuteDate(kvEntry.first))).column("timestamp");
+        m_pExceptionList->addNameItemRow(paramItem);
+    }
 
-	if (idSel.notNull())
-	{
-		m_pExceptionList->selectByID(idSel);
-	}
+    if (idSel.notNull())
+    {
+        m_pExceptionList->selectByID(idSel);
+    }
 }
 
 void LLPanelAvatarRendering::removePicker()
 {
-	if (m_hPicker.get())
-	{
-		m_hPicker.get()->closeFloater();
-	}
+    if (m_hPicker.get())
+    {
+        m_hPicker.get()->closeFloater();
+    }
 }
 
 void LLPanelAvatarRendering::setFilterString(const std::string& strFilter)
 {
-	m_strFilter = strFilter;
-	refresh();
+    m_strFilter = strFilter;
+    refresh();
 }
 
 void LLPanelAvatarRendering::updateButtons()
 {
-	bool fHasSelection = (nullptr != m_pExceptionList->getFirstSelected());
-	m_pTrashBtn->setEnabled(fHasSelection);
+    bool fHasSelection = (nullptr != m_pExceptionList->getFirstSelected());
+    m_pTrashBtn->setEnabled(fHasSelection);
 }
 
 void LLPanelAvatarRendering::onChange()
 {
-	if (m_fRefreshOnChange)
-	{
-		refresh();
-	}
+    if (m_fRefreshOnChange)
+    {
+        refresh();
+    }
 }
 
 void LLPanelAvatarRendering::onAddException(LLUICtrl* pCtrl, const LLSD& sdParam)
 {
-	const std::string strParam = sdParam.asString();
+    const std::string strParam = sdParam.asString();
 
-	LLVOAvatar::VisualMuteSettings eSetting = (LLVOAvatar::VisualMuteSettings)0;
-	if ("never" == strParam)
-		eSetting = LLVOAvatar::AV_DO_NOT_RENDER;
-	else if ("always" == strParam)
-		eSetting = LLVOAvatar::AV_ALWAYS_RENDER;
+    LLVOAvatar::VisualMuteSettings eSetting = (LLVOAvatar::VisualMuteSettings)0;
+    if ("never" == strParam)
+        eSetting = LLVOAvatar::AV_DO_NOT_RENDER;
+    else if ("always" == strParam)
+        eSetting = LLVOAvatar::AV_ALWAYS_RENDER;
 
-	if (LLFloater* pRootFloater = gFloaterView->getParentFloater(pCtrl))
-	{
-		removePicker();
+    if (LLFloater* pRootFloater = gFloaterView->getParentFloater(pCtrl))
+    {
+        removePicker();
 
-		LLFloaterAvatarPicker* pPicker = LLFloaterAvatarPicker::show(
-			boost::bind(&LLPanelAvatarRendering::onAddExceptionCb, _1, eSetting),
-			false /*allow_multiple*/, true /*close_on_select*/, false /*skip_agent*/, pRootFloater->getName(), pCtrl);
-		pRootFloater->addDependentFloater(pPicker);
-		m_hPicker = pPicker->getHandle();
-	}
+        LLFloaterAvatarPicker* pPicker = LLFloaterAvatarPicker::show(
+            boost::bind(&LLPanelAvatarRendering::onAddExceptionCb, _1, eSetting),
+            false /*allow_multiple*/, true /*close_on_select*/, false /*skip_agent*/, pRootFloater->getName(), pCtrl);
+        pRootFloater->addDependentFloater(pPicker);
+        m_hPicker = pPicker->getHandle();
+    }
 }
 
 void LLPanelAvatarRendering::onAddExceptionCb(const uuid_vec_t& idAgents, S32 nSetting)
 {
-	if (idAgents.empty())
-		return;
+    if (idAgents.empty())
+        return;
 
-	for (const LLUUID& idAgent : idAgents)
-	{
-		setAvatarRenderSetting(idAgent, (LLVOAvatar::VisualMuteSettings)nSetting);
-	}
+    for (const LLUUID& idAgent : idAgents)
+    {
+        setAvatarRenderSetting(idAgent, (LLVOAvatar::VisualMuteSettings)nSetting);
+    }
 
-	LLFloaterBlocked::showRenderExceptionAndSelect(idAgents[0]);
+    LLFloaterBlocked::showRenderExceptionAndSelect(idAgents[0]);
 }
 
 bool LLPanelAvatarRendering::onHasException(const LLUUID& idAgent, const LLSD& sdParamn)
 {
-	const std::string strParam = sdParamn.asString();
+    const std::string strParam = sdParamn.asString();
 
-	LLVOAvatar::VisualMuteSettings eSetting = (LLVOAvatar::VisualMuteSettings)LLRenderMuteList::getInstance()->getSavedVisualMuteSetting(idAgent);
-	if ("default" == strParam)
-		return (eSetting == LLVOAvatar::AV_RENDER_NORMALLY);
-	else if ("non_default" == strParam)
-		return (eSetting != LLVOAvatar::AV_RENDER_NORMALLY);
-	else if ("never" == strParam)
-		return (eSetting == LLVOAvatar::AV_DO_NOT_RENDER);
-	else if ("always" == strParam)
-		return (eSetting == LLVOAvatar::AV_ALWAYS_RENDER);
-	return false;
+    LLVOAvatar::VisualMuteSettings eSetting = (LLVOAvatar::VisualMuteSettings)LLRenderMuteList::getInstance()->getSavedVisualMuteSetting(idAgent);
+    if ("default" == strParam)
+        return (eSetting == LLVOAvatar::AV_RENDER_NORMALLY);
+    else if ("non_default" == strParam)
+        return (eSetting != LLVOAvatar::AV_RENDER_NORMALLY);
+    else if ("never" == strParam)
+        return (eSetting == LLVOAvatar::AV_DO_NOT_RENDER);
+    else if ("always" == strParam)
+        return (eSetting == LLVOAvatar::AV_ALWAYS_RENDER);
+    return false;
 }
 
 void LLPanelAvatarRendering::onExceptionMenu(S32 x, S32 y)
 {
-	m_pExceptionList->selectItemAt(x, y, MASK_NONE);
+    m_pExceptionList->selectItemAt(x, y, MASK_NONE);
 
-	uuid_vec_t selected_uuids;
-	if (m_pExceptionList->getCurrentID().notNull())
-	{
-		selected_uuids.push_back(m_pExceptionList->getCurrentID());
-		m_pContextMenu->show(m_pExceptionList, selected_uuids, x, y);
-	}
+    uuid_vec_t selected_uuids;
+    if (m_pExceptionList->getCurrentID().notNull())
+    {
+        selected_uuids.push_back(m_pExceptionList->getCurrentID());
+        m_pContextMenu->show(m_pExceptionList, selected_uuids, x, y);
+    }
 }
 
 void LLPanelAvatarRendering::onRemoveException()
 {
-	m_fRefreshOnChange = false;
+    m_fRefreshOnChange = false;
 
-	const std::vector<LLScrollListItem*> selItems = m_pExceptionList->getAllSelected();
-	for (auto* pSelItem : selItems)
-	{
-		const LLSD sdValue = pSelItem->getValue();
-		if (sdValue.isUUID())
-		{
-			setAvatarRenderSetting(sdValue.asUUID(), LLVOAvatar::AV_RENDER_NORMALLY);
-			m_pExceptionList->deleteSingleItem(pSelItem);
-		}
-	}
+    const std::vector<LLScrollListItem*> selItems = m_pExceptionList->getAllSelected();
+    for (auto* pSelItem : selItems)
+    {
+        const LLSD sdValue = pSelItem->getValue();
+        if (sdValue.isUUID())
+        {
+            setAvatarRenderSetting(sdValue.asUUID(), LLVOAvatar::AV_RENDER_NORMALLY);
+            m_pExceptionList->deleteSingleItem(pSelItem);
+        }
+    }
 
-	m_fRefreshOnChange = true;
+    m_fRefreshOnChange = true;
 }
 
 void LLPanelAvatarRendering::onSetException(const LLUUID& idAgent, const LLSD& sdParamn)
 {
-	const std::string strParam = sdParamn.asString();
+    const std::string strParam = sdParamn.asString();
 
-	LLVOAvatar::VisualMuteSettings nSetting = (LLVOAvatar::VisualMuteSettings)0;
-	if ("default" == strParam)
-		nSetting = LLVOAvatar::AV_RENDER_NORMALLY;
-	else if ("never" == strParam)
-		nSetting = LLVOAvatar::AV_DO_NOT_RENDER;
-	else if ("always" == strParam)
-		nSetting = LLVOAvatar::AV_ALWAYS_RENDER;
+    LLVOAvatar::VisualMuteSettings nSetting = (LLVOAvatar::VisualMuteSettings)0;
+    if ("default" == strParam)
+        nSetting = LLVOAvatar::AV_RENDER_NORMALLY;
+    else if ("never" == strParam)
+        nSetting = LLVOAvatar::AV_DO_NOT_RENDER;
+    else if ("always" == strParam)
+        nSetting = LLVOAvatar::AV_ALWAYS_RENDER;
 
-	setAvatarRenderSetting(idAgent, nSetting);
+    setAvatarRenderSetting(idAgent, nSetting);
 }
 
 void LLPanelAvatarRendering::onColumnSortChange()
 {
-	U32 nSortValue = 0;
+    U32 nSortValue = 0;
 
-	S32 idxColumn = m_pExceptionList->getSortColumnIndex();
-	if (-1 != idxColumn)
-	{
-		nSortValue = idxColumn << 4 | ((m_pExceptionList->getSortAscending()) ? 1 : 0);
-	}
+    S32 idxColumn = m_pExceptionList->getSortColumnIndex();
+    if (-1 != idxColumn)
+    {
+        nSortValue = idxColumn << 4 | ((m_pExceptionList->getSortAscending()) ? 1 : 0);
+    }
 
-	gSavedSettings.setU32("BlockRenderingSortOrder", nSortValue);
+    gSavedSettings.setU32("BlockRenderingSortOrder", nSortValue);
 }
 
 void LLPanelAvatarRendering::onSelectionChange()
 {
-	updateButtons();
+    updateButtons();
 }
 
 // ============================================================================
@@ -840,7 +840,7 @@ void LLPanelAvatarRendering::onSelectionChange()
 //
 
 LLFloaterBlocked::LLFloaterBlocked(const LLSD& sdKey)
-	: LLFloater(sdKey)
+    : LLFloater(sdKey)
 {
 }
 
@@ -850,69 +850,69 @@ LLFloaterBlocked::~LLFloaterBlocked()
 
 BOOL LLFloaterBlocked::postBuild()
 {
-	m_pFilterEditor = findChild<LLFilterEditor>("blocked_filter");
-	m_pFilterEditor->setCommitCallback(boost::bind(&LLFloaterBlocked::onFilterEdit, this, _2));
+    m_pFilterEditor = findChild<LLFilterEditor>("blocked_filter");
+    m_pFilterEditor->setCommitCallback(boost::bind(&LLFloaterBlocked::onFilterEdit, this, _2));
 
-	m_pBlockedTabs = findChild<LLTabContainer>("blocked_tabs");
-	m_pBlockedTabs->setCommitCallback(boost::bind(&LLFloaterBlocked::onTabSelect, this, _2));
+    m_pBlockedTabs = findChild<LLTabContainer>("blocked_tabs");
+    m_pBlockedTabs->setCommitCallback(boost::bind(&LLFloaterBlocked::onTabSelect, this, _2));
 
-	return TRUE;
+    return TRUE;
 }
 
 void LLFloaterBlocked::onOpen(const LLSD& sdParam)
 {
-	if (sdParam.has(BLOCKED_PARAM_NAME))
-		m_pBlockedTabs->selectTabByName(BLOCKED_TAB_NAME);
-	else if (sdParam.has(DERENDER_PARAM_NAME))
-		m_pBlockedTabs->selectTabByName(DERENDER_TAB_NAME);
-	else if (sdParam.has(ASSET_PARAM_NAME))
-		m_pBlockedTabs->selectTabByName(ASSET_TAB_NAME);
-	if (sdParam.has(EXCEPTION_PARAM_NAME))
-		m_pBlockedTabs->selectTabByName(EXCEPTION_TAB_NAME);
-	else if ( (sdParam.isString()) && (m_pBlockedTabs->hasChild(sdParam.asString())) )
-		m_pBlockedTabs->selectTabByName(sdParam.asString());
-	else
-		m_pBlockedTabs->getCurrentPanel()->onOpen(sdParam);
-	mKey.clear();
+    if (sdParam.has(BLOCKED_PARAM_NAME))
+        m_pBlockedTabs->selectTabByName(BLOCKED_TAB_NAME);
+    else if (sdParam.has(DERENDER_PARAM_NAME))
+        m_pBlockedTabs->selectTabByName(DERENDER_TAB_NAME);
+    else if (sdParam.has(ASSET_PARAM_NAME))
+        m_pBlockedTabs->selectTabByName(ASSET_TAB_NAME);
+    if (sdParam.has(EXCEPTION_PARAM_NAME))
+        m_pBlockedTabs->selectTabByName(EXCEPTION_TAB_NAME);
+    else if ( (sdParam.isString()) && (m_pBlockedTabs->hasChild(sdParam.asString())) )
+        m_pBlockedTabs->selectTabByName(sdParam.asString());
+    else
+        m_pBlockedTabs->getCurrentPanel()->onOpen(sdParam);
+    mKey.clear();
 }
 
 void LLFloaterBlocked::onFilterEdit(const std::string& strFilter)
 {
-	if (LLPanelBlockBase* pCurPanel = dynamic_cast<LLPanelBlockBase*>(m_pBlockedTabs->getCurrentPanel()))
-	{
-		pCurPanel->setFilterString(strFilter);
-	}
+    if (LLPanelBlockBase* pCurPanel = dynamic_cast<LLPanelBlockBase*>(m_pBlockedTabs->getCurrentPanel()))
+    {
+        pCurPanel->setFilterString(strFilter);
+    }
 }
 
 void LLFloaterBlocked::onTabSelect(const LLSD& sdParam)
 {
-	LLPanel* pActivePanel = m_pBlockedTabs->getPanelByName(sdParam.asString());
-	if (pActivePanel)
-	{
-		if (LLPanelBlockBase* pActivePanelBase = dynamic_cast<LLPanelBlockBase*>(pActivePanel))
-			m_pFilterEditor->setText(pActivePanelBase->getFilterString());
-		pActivePanel->onOpen(mKey);
-	}
+    LLPanel* pActivePanel = m_pBlockedTabs->getPanelByName(sdParam.asString());
+    if (pActivePanel)
+    {
+        if (LLPanelBlockBase* pActivePanelBase = dynamic_cast<LLPanelBlockBase*>(pActivePanel))
+            m_pFilterEditor->setText(pActivePanelBase->getFilterString());
+        pActivePanel->onOpen(mKey);
+    }
 }
 
 void LLFloaterBlocked::showMuteAndSelect(const LLUUID& idMute)
 {
-	LLFloaterReg::showInstance("blocked", LLSD().with(BLOCKED_PARAM_NAME, idMute));
+    LLFloaterReg::showInstance("blocked", LLSD().with(BLOCKED_PARAM_NAME, idMute));
 }
 
 void LLFloaterBlocked::showDerenderAndSelect(const LLUUID& idEntry)
 {
-	LLFloaterReg::showInstance("blocked", LLSD().with(DERENDER_PARAM_NAME, idEntry));
+    LLFloaterReg::showInstance("blocked", LLSD().with(DERENDER_PARAM_NAME, idEntry));
 }
 
 void LLFloaterBlocked::showAssetAndSelect(const LLUUID& idEntry)
 {
-	LLFloaterReg::showInstance("blocked", LLSD().with(ASSET_PARAM_NAME, idEntry));
+    LLFloaterReg::showInstance("blocked", LLSD().with(ASSET_PARAM_NAME, idEntry));
 }
 
 void LLFloaterBlocked::showRenderExceptionAndSelect(const LLUUID& idEntry)
 {
-	LLFloaterReg::showInstance("blocked", LLSD().with(EXCEPTION_PARAM_NAME, idEntry));
+    LLFloaterReg::showInstance("blocked", LLSD().with(EXCEPTION_PARAM_NAME, idEntry));
 }
 
 // ============================================================================
diff --git a/indra/newview/llfloaterblocked.h b/indra/newview/llfloaterblocked.h
index b881457d5a4675a4475a4dd050d4dc53da75ead1..376fcb1f9b6dd205fae5c16fb1aa029e362bdf6c 100644
--- a/indra/newview/llfloaterblocked.h
+++ b/indra/newview/llfloaterblocked.h
@@ -45,8 +45,8 @@ extern const std::string EXCEPTION_TAB_NAME;
 class LLPanelBlockBase
 {
 public:
-	virtual const std::string& getFilterString() const = 0;
-	virtual void               setFilterString(const std::string& strFilter) = 0;
+    virtual const std::string& getFilterString() const = 0;
+    virtual void               setFilterString(const std::string& strFilter) = 0;
 };
 
 // ============================================================================
@@ -56,54 +56,54 @@ class LLPanelBlockBase
 class LLPanelBlockList final : public LLPanel, public LLMuteListObserver, public LLPanelBlockBase
 {
 public:
-	LLPanelBlockList();
-	~LLPanelBlockList();
+    LLPanelBlockList();
+    ~LLPanelBlockList();
 
-	/*
-	 * LLPanel overrides
-	 */
+    /*
+     * LLPanel overrides
+     */
 public:
-	BOOL postBuild() override;
-	void onOpen(const LLSD& sdParam) override;
+    BOOL postBuild() override;
+    void onOpen(const LLSD& sdParam) override;
 
-	/*
-	 * Member functions
-	 */
+    /*
+     * Member functions
+     */
 public:
-	const std::string& getFilterString() const override { return m_strFilter; }
-	void setFilterString(const std::string& strFilter) override;
+    const std::string& getFilterString() const override { return m_strFilter; }
+    void setFilterString(const std::string& strFilter) override;
 protected:
-	void refresh() override;
-	void removePicker();
-	void selectEntry(const LLSD& sdValue) { LLMute muteEntry(sdValue["id"].asUUID(), sdValue["name"].asString()); selectEntry(muteEntry); }
-	void selectEntry(const LLMute& muteEntry);
-	void updateButtons();
-
-	/*
-	 * Event handlers
-	 */
+    void refresh() override;
+    void removePicker();
+    void selectEntry(const LLSD& sdValue) { LLMute muteEntry(sdValue["id"].asUUID(), sdValue["name"].asString()); selectEntry(muteEntry); }
+    void selectEntry(const LLMute& muteEntry);
+    void updateButtons();
+
+    /*
+     * Event handlers
+     */
 public:
-	void onChange() override;
+    void onChange() override;
 protected:
-	       void onAddAvatar(LLUICtrl* pCtrl);
-	static void onAddAvatarCallback(const uuid_vec_t& idAgents, const std::vector<LLAvatarName>& avAgents);
-	static void onAddByName();
-	static void onAddByNameCallback(const std::string& strBlockName);
-		   void onRemoveSelection();
-		   void onColumnSortChange();
-	static void onIdleRefresh(LLHandle<LLPanel> hPanel);
-		   void onSelectionChange();
-		   void onToggleMuteFlag(const LLSD& sdValue, const LLScrollListCell* pCell);
-
-	/*
-	 * Member variables
-	 */
+           void onAddAvatar(LLUICtrl* pCtrl);
+    static void onAddAvatarCallback(const uuid_vec_t& idAgents, const std::vector<LLAvatarName>& avAgents);
+    static void onAddByName();
+    static void onAddByNameCallback(const std::string& strBlockName);
+           void onRemoveSelection();
+           void onColumnSortChange();
+    static void onIdleRefresh(LLHandle<LLPanel> hPanel);
+           void onSelectionChange();
+           void onToggleMuteFlag(const LLSD& sdValue, const LLScrollListCell* pCell);
+
+    /*
+     * Member variables
+     */
 protected:
-	bool                m_fRefreshOnChange = true;
-	std::string         m_strFilter;
-	LLScrollListCtrl*   m_pBlockList = nullptr;
-	LLButton*           m_pTrashBtn = nullptr;
-	LLHandle<LLFloater> m_hPicker;
+    bool                m_fRefreshOnChange = true;
+    std::string         m_strFilter;
+    LLScrollListCtrl*   m_pBlockList = nullptr;
+    LLButton*           m_pTrashBtn = nullptr;
+    LLHandle<LLFloater> m_hPicker;
 };
 
 // ============================================================================
@@ -113,36 +113,36 @@ class LLPanelBlockList final : public LLPanel, public LLMuteListObserver, public
 class LLPanelDerenderList final : public LLPanel
 {
 public:
-	LLPanelDerenderList();
-	~LLPanelDerenderList();
+    LLPanelDerenderList();
+    ~LLPanelDerenderList();
 
-	/*
-	 * LLPanel overrides
-	 */
+    /*
+     * LLPanel overrides
+     */
 public:
-	BOOL postBuild() override;
-	void onOpen(const LLSD& sdParam) override;
+    BOOL postBuild() override;
+    void onOpen(const LLSD& sdParam) override;
 
-	/*
-	 * Member functions
-	 */
+    /*
+     * Member functions
+     */
 protected:
-	void refresh() override;
+    void refresh() override;
 
-	/*
-	 * Event handlers
-	 */
+    /*
+     * Event handlers
+     */
 protected:
-	void onColumnSortChange();
-	void onSelectionChange();
-	void onSelectionRemove();
+    void onColumnSortChange();
+    void onSelectionChange();
+    void onSelectionRemove();
 
-	/*
-	 * Member variables
-	 */
+    /*
+     * Member variables
+     */
 protected:
-	LLScrollListCtrl*           m_pDerenderList;
-	boost::signals2::connection m_DerenderChangeConn;
+    LLScrollListCtrl*           m_pDerenderList;
+    boost::signals2::connection m_DerenderChangeConn;
 };
 
 // ============================================================================
@@ -152,36 +152,36 @@ class LLPanelDerenderList final : public LLPanel
 class LLPanelAssetBlocklist final : public LLPanel
 {
 public:
-	LLPanelAssetBlocklist();
-	~LLPanelAssetBlocklist();
+    LLPanelAssetBlocklist();
+    ~LLPanelAssetBlocklist();
 
-	/*
-	 * LLPanel overrides
-	 */
+    /*
+     * LLPanel overrides
+     */
 public:
-	BOOL postBuild() override;
-	void onOpen(const LLSD& sdParam) override;
+    BOOL postBuild() override;
+    void onOpen(const LLSD& sdParam) override;
 
-	/*
-	 * Member functions
-	 */
+    /*
+     * Member functions
+     */
 protected:
-	void refresh() override;
+    void refresh() override;
 
-	/*
-	 * Event handlers
-	 */
+    /*
+     * Event handlers
+     */
 protected:
-	void onColumnSortChange();
-	void onSelectionChange();
-	void onSelectionRemove();
+    void onColumnSortChange();
+    void onSelectionChange();
+    void onSelectionRemove();
 
-	/*
-	 * Member variables
-	 */
+    /*
+     * Member variables
+     */
 protected:
-	LLScrollListCtrl* mAssetBlocklist = nullptr;
-	boost::signals2::connection mAssetBlocklistChangeConn;
+    LLScrollListCtrl* mAssetBlocklist = nullptr;
+    boost::signals2::connection mAssetBlocklistChangeConn;
 };
 
 // ============================================================================
@@ -190,55 +190,55 @@ class LLPanelAssetBlocklist final : public LLPanel
 
 class LLPanelAvatarRendering final : public LLPanel, public LLMuteListObserver, public LLPanelBlockBase
 {
-	friend class LLPanelAvatarRenderingContextMenu;
+    friend class LLPanelAvatarRenderingContextMenu;
 public:
-	LLPanelAvatarRendering();
-	~LLPanelAvatarRendering();
+    LLPanelAvatarRendering();
+    ~LLPanelAvatarRendering();
 
-	/*
-	 * LLPanel overrides
-	 */
+    /*
+     * LLPanel overrides
+     */
 public:
-	BOOL postBuild() override;
-	void onOpen(const LLSD& sdParam) override;
+    BOOL postBuild() override;
+    void onOpen(const LLSD& sdParam) override;
 
-	/*
-	 * Member functions
-	 */
+    /*
+     * Member functions
+     */
 public:
-	const std::string& getFilterString() const override { return m_strFilter; }
-	void setFilterString(const std::string& strFilter) override;
+    const std::string& getFilterString() const override { return m_strFilter; }
+    void setFilterString(const std::string& strFilter) override;
 protected:
-	void refresh() override;
-	void removePicker();
-	void updateButtons();
+    void refresh() override;
+    void removePicker();
+    void updateButtons();
 
-	/*
-	 * Event handlers
-	 */
+    /*
+     * Event handlers
+     */
 public:
-	void onChange() override;
+    void onChange() override;
 protected:
-	void onAddException(LLUICtrl* pCtrl, const LLSD& sdParam);
-	static void onAddExceptionCb(const uuid_vec_t& idAgents, S32 nSetting);
-	bool onHasException(const LLUUID& idAgent, const LLSD& sdParamn);
-	void onExceptionMenu(S32 x, S32 y);
-	void onRemoveException();
-	void onSetException(const LLUUID& idAgent, const LLSD& sdParamn);
-
-	void onColumnSortChange();
-	void onSelectionChange();
-
-	/*
-	 * Member variables
-	 */
+    void onAddException(LLUICtrl* pCtrl, const LLSD& sdParam);
+    static void onAddExceptionCb(const uuid_vec_t& idAgents, S32 nSetting);
+    bool onHasException(const LLUUID& idAgent, const LLSD& sdParamn);
+    void onExceptionMenu(S32 x, S32 y);
+    void onRemoveException();
+    void onSetException(const LLUUID& idAgent, const LLSD& sdParamn);
+
+    void onColumnSortChange();
+    void onSelectionChange();
+
+    /*
+     * Member variables
+     */
 protected:
-	bool                m_fRefreshOnChange = true;
-	std::string         m_strFilter;
-	LLNameListCtrl*     m_pExceptionList = nullptr;
-	LLButton*           m_pTrashBtn = nullptr;
-	LLListContextMenu*  m_pContextMenu = nullptr;
-	LLHandle<LLFloater> m_hPicker;
+    bool                m_fRefreshOnChange = true;
+    std::string         m_strFilter;
+    LLNameListCtrl*     m_pExceptionList = nullptr;
+    LLButton*           m_pTrashBtn = nullptr;
+    LLListContextMenu*  m_pContextMenu = nullptr;
+    LLHandle<LLFloater> m_hPicker;
 };
 
 // ============================================================================
@@ -248,38 +248,38 @@ class LLPanelAvatarRendering final : public LLPanel, public LLMuteListObserver,
 class LLFloaterBlocked final : public LLFloater
 {
 public:
-	LLFloaterBlocked(const LLSD& sdKey);
-	~LLFloaterBlocked();
+    LLFloaterBlocked(const LLSD& sdKey);
+    ~LLFloaterBlocked();
 
-	/*
-	 * LLFloater overrides
-	 */
+    /*
+     * LLFloater overrides
+     */
 public:
-	BOOL postBuild() override;
-	void onOpen(const LLSD& sdParam) override;
+    BOOL postBuild() override;
+    void onOpen(const LLSD& sdParam) override;
 
-	/*
-	 * Event handlers
-	 */
+    /*
+     * Event handlers
+     */
 protected:
-	void onFilterEdit(const std::string& strFilter);
-	void onTabSelect(const LLSD& sdParam);
+    void onFilterEdit(const std::string& strFilter);
+    void onTabSelect(const LLSD& sdParam);
 
-	/*
-	 * Member functions
-	 */
+    /*
+     * Member functions
+     */
 public:
-	static void showMuteAndSelect(const LLUUID& idMute);
-	static void showDerenderAndSelect(const LLUUID& idEntry);
-	static void showAssetAndSelect(const LLUUID& idEntry);
-	static void showRenderExceptionAndSelect(const LLUUID& idEntry);
-
-	/*
-	 * Member variables
-	 */
+    static void showMuteAndSelect(const LLUUID& idMute);
+    static void showDerenderAndSelect(const LLUUID& idEntry);
+    static void showAssetAndSelect(const LLUUID& idEntry);
+    static void showRenderExceptionAndSelect(const LLUUID& idEntry);
+
+    /*
+     * Member variables
+     */
 protected:
-	LLFilterEditor* m_pFilterEditor = nullptr;
-	LLTabContainer* m_pBlockedTabs = nullptr;
+    LLFilterEditor* m_pFilterEditor = nullptr;
+    LLTabContainer* m_pBlockedTabs = nullptr;
 };
 
 // ============================================================================
diff --git a/indra/newview/llfloaterimagepreview.cpp b/indra/newview/llfloaterimagepreview.cpp
index 57ea559f286904daf6220139922e53d94c9c6eab..d2f5fe3d436e4b3aae2a9345aa8554b9e1a18e72 100644
--- a/indra/newview/llfloaterimagepreview.cpp
+++ b/indra/newview/llfloaterimagepreview.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llfloaterimagepreview.cpp
  * @brief LLFloaterImagePreview class implementation
  *
  * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -65,23 +65,23 @@
 const S32 PREVIEW_BORDER_WIDTH = 2;
 const S32 PREVIEW_RESIZE_HANDLE_SIZE = S32(RESIZE_HANDLE_WIDTH * OO_SQRT2) + PREVIEW_BORDER_WIDTH;
 const S32 PREVIEW_HPAD = PREVIEW_RESIZE_HANDLE_SIZE;
-const S32 PREVIEW_VPAD = -24 + 35;	// yuk, hard coded
+const S32 PREVIEW_VPAD = -24 + 35;  // yuk, hard coded
 const S32 PREF_BUTTON_HEIGHT = 16 + 7 + 16 + 35;
 const S32 PREVIEW_TEXTURE_HEIGHT = 320;
 
 //-----------------------------------------------------------------------------
 // LLFloaterImagePreview()
 //-----------------------------------------------------------------------------
-LLFloaterImagePreview::LLFloaterImagePreview(const std::string& filename) : 
-	LLFloaterNameDesc(filename),
+LLFloaterImagePreview::LLFloaterImagePreview(const std::string& filename) :
+    LLFloaterNameDesc(filename),
 
-	mAvatarPreview(NULL),
-	mSculptedPreview(NULL),
-	mLastMouseX(0),
-	mLastMouseY(0),
-	mImagep(NULL)
+    mAvatarPreview(NULL),
+    mSculptedPreview(NULL),
+    mLastMouseX(0),
+    mLastMouseY(0),
+    mImagep(NULL)
 {
-	loadImage(mFilenameAndPath);
+    loadImage(mFilenameAndPath);
 }
 
 //-----------------------------------------------------------------------------
@@ -89,33 +89,33 @@ LLFloaterImagePreview::LLFloaterImagePreview(const std::string& filename) :
 //-----------------------------------------------------------------------------
 BOOL LLFloaterImagePreview::postBuild()
 {
-	if (!LLFloaterNameDesc::postBuild())
-	{
-		return FALSE;
-	}
-	
-	LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
-	if (iface)
-	{
-		iface->selectFirstItem();
-	}
-	childSetCommitCallback("clothing_type_combo", onPreviewTypeCommit, this);
-
-	mPreviewRect.set(PREVIEW_HPAD, 
-		PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD,
-		getRect().getWidth() - PREVIEW_HPAD, 
-		PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
-	mPreviewImageRect.set(0.f, 1.f, 1.f, 0.f);
-
-	getChildView("bad_image_text")->setVisible(FALSE);
-
-	if (mRawImagep.notNull() && gAgent.getRegion() != NULL)
-	{
-		mAvatarPreview = new LLImagePreviewAvatar(256, 256);
-		mAvatarPreview->setPreviewTarget("mPelvis", "mUpperBodyMesh0", mRawImagep, 2.f, FALSE);
-
-		mSculptedPreview = new LLImagePreviewSculpted(256, 256);
-		mSculptedPreview->setPreviewTarget(mRawImagep, 2.0f);
+    if (!LLFloaterNameDesc::postBuild())
+    {
+        return FALSE;
+    }
+
+    LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
+    if (iface)
+    {
+        iface->selectFirstItem();
+    }
+    childSetCommitCallback("clothing_type_combo", onPreviewTypeCommit, this);
+
+    mPreviewRect.set(PREVIEW_HPAD,
+        PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD,
+        getRect().getWidth() - PREVIEW_HPAD,
+        PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
+    mPreviewImageRect.set(0.f, 1.f, 1.f, 0.f);
+
+    getChildView("bad_image_text")->setVisible(FALSE);
+
+    if (mRawImagep.notNull() && gAgent.getRegion() != NULL)
+    {
+        mAvatarPreview = new LLImagePreviewAvatar(256, 256);
+        mAvatarPreview->setPreviewTarget("mPelvis", "mUpperBodyMesh0", mRawImagep, 2.f, FALSE);
+
+        mSculptedPreview = new LLImagePreviewSculpted(256, 256);
+        mSculptedPreview->setPreviewTarget(mRawImagep, 2.0f);
 
         if (mRawImagep->getWidth() * mRawImagep->getHeight() <= LL_IMAGE_REZ_LOSSLESS_CUTOFF * LL_IMAGE_REZ_LOSSLESS_CUTOFF)
         {
@@ -125,24 +125,24 @@ BOOL LLFloaterImagePreview::postBuild()
             check_box->setEnabled(TRUE);
             check_box->setControlVariable(gSavedSettings.getControl("LosslessJ2CUpload"));
         }
-	}
-	else
-	{
-		mAvatarPreview = NULL;
-		mSculptedPreview = NULL;
-		getChildView("bad_image_text")->setVisible(TRUE);
-		getChildView("clothing_type_combo")->setEnabled(FALSE);
-		getChildView("ok_btn")->setEnabled(FALSE);
+    }
+    else
+    {
+        mAvatarPreview = NULL;
+        mSculptedPreview = NULL;
+        getChildView("bad_image_text")->setVisible(TRUE);
+        getChildView("clothing_type_combo")->setEnabled(FALSE);
+        getChildView("ok_btn")->setEnabled(FALSE);
 
-		if(!mImageLoadError.empty())
-		{
-			getChild<LLUICtrl>("bad_image_text")->setValue(mImageLoadError.c_str());
-		}
-	}
-	
-	getChild<LLUICtrl>("ok_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnOK, this));
-	
-	return TRUE;
+        if(!mImageLoadError.empty())
+        {
+            getChild<LLUICtrl>("bad_image_text")->setValue(mImageLoadError.c_str());
+        }
+    }
+
+    getChild<LLUICtrl>("ok_btn")->setCommitCallback(boost::bind(&LLFloaterNameDesc::onBtnOK, this));
+
+    return TRUE;
 }
 
 
@@ -159,70 +159,70 @@ S32 LLFloaterImagePreview::getExpectedUploadCost() const
 //-----------------------------------------------------------------------------
 LLFloaterImagePreview::~LLFloaterImagePreview()
 {
-	clearAllPreviewTextures();
+    clearAllPreviewTextures();
 
-	mRawImagep = NULL;
-	mImagep = NULL ;
+    mRawImagep = NULL;
+    mImagep = NULL ;
 }
 
-//static 
+//static
 //-----------------------------------------------------------------------------
 // onPreviewTypeCommit()
 //-----------------------------------------------------------------------------
-void	LLFloaterImagePreview::onPreviewTypeCommit(LLUICtrl* ctrl, void* userdata)
-{
-	LLFloaterImagePreview *fp =(LLFloaterImagePreview *)userdata;
-	
-	if (!fp->mAvatarPreview || !fp->mSculptedPreview)
-	{
-		return;
-	}
-
-	S32 which_mode = 0;
-
-	LLCtrlSelectionInterface* iface = fp->childGetSelectionInterface("clothing_type_combo");
-	if (iface)
-	{
-		which_mode = iface->getFirstSelectedIndex();
-	}
-
-	switch(which_mode)
-	{
-	case 0:
-		break;
-	case 1:
-		fp->mAvatarPreview->setPreviewTarget("mSkull", "mHairMesh0", fp->mRawImagep, 0.4f, FALSE);
-		break;
-	case 2:
-		fp->mAvatarPreview->setPreviewTarget("mSkull", "mHeadMesh0", fp->mRawImagep, 0.4f, FALSE);
-		break;
-	case 3:
-		fp->mAvatarPreview->setPreviewTarget("mChest", "mUpperBodyMesh0", fp->mRawImagep, 1.0f, FALSE);
-		break;
-	case 4:
-		fp->mAvatarPreview->setPreviewTarget("mKneeLeft", "mLowerBodyMesh0", fp->mRawImagep, 1.2f, FALSE);
-		break;
-	case 5:
-		fp->mAvatarPreview->setPreviewTarget("mSkull", "mHeadMesh0", fp->mRawImagep, 0.4f, TRUE);
-		break;
-	case 6:
-		fp->mAvatarPreview->setPreviewTarget("mChest", "mUpperBodyMesh0", fp->mRawImagep, 1.2f, TRUE);
-		break;
-	case 7:
-		fp->mAvatarPreview->setPreviewTarget("mKneeLeft", "mLowerBodyMesh0", fp->mRawImagep, 1.2f, TRUE);
-		break;
-	case 8:
-		fp->mAvatarPreview->setPreviewTarget("mKneeLeft", "mSkirtMesh0", fp->mRawImagep, 1.3f, FALSE);
-		break;
-	case 9:
-		fp->mSculptedPreview->setPreviewTarget(fp->mRawImagep, 2.0f);
-		break;
-	default:
-		break;
-	}
-	
-	fp->mAvatarPreview->refresh();
-	fp->mSculptedPreview->refresh();
+void    LLFloaterImagePreview::onPreviewTypeCommit(LLUICtrl* ctrl, void* userdata)
+{
+    LLFloaterImagePreview *fp =(LLFloaterImagePreview *)userdata;
+
+    if (!fp->mAvatarPreview || !fp->mSculptedPreview)
+    {
+        return;
+    }
+
+    S32 which_mode = 0;
+
+    LLCtrlSelectionInterface* iface = fp->childGetSelectionInterface("clothing_type_combo");
+    if (iface)
+    {
+        which_mode = iface->getFirstSelectedIndex();
+    }
+
+    switch(which_mode)
+    {
+    case 0:
+        break;
+    case 1:
+        fp->mAvatarPreview->setPreviewTarget("mSkull", "mHairMesh0", fp->mRawImagep, 0.4f, FALSE);
+        break;
+    case 2:
+        fp->mAvatarPreview->setPreviewTarget("mSkull", "mHeadMesh0", fp->mRawImagep, 0.4f, FALSE);
+        break;
+    case 3:
+        fp->mAvatarPreview->setPreviewTarget("mChest", "mUpperBodyMesh0", fp->mRawImagep, 1.0f, FALSE);
+        break;
+    case 4:
+        fp->mAvatarPreview->setPreviewTarget("mKneeLeft", "mLowerBodyMesh0", fp->mRawImagep, 1.2f, FALSE);
+        break;
+    case 5:
+        fp->mAvatarPreview->setPreviewTarget("mSkull", "mHeadMesh0", fp->mRawImagep, 0.4f, TRUE);
+        break;
+    case 6:
+        fp->mAvatarPreview->setPreviewTarget("mChest", "mUpperBodyMesh0", fp->mRawImagep, 1.2f, TRUE);
+        break;
+    case 7:
+        fp->mAvatarPreview->setPreviewTarget("mKneeLeft", "mLowerBodyMesh0", fp->mRawImagep, 1.2f, TRUE);
+        break;
+    case 8:
+        fp->mAvatarPreview->setPreviewTarget("mKneeLeft", "mSkirtMesh0", fp->mRawImagep, 1.3f, FALSE);
+        break;
+    case 9:
+        fp->mSculptedPreview->setPreviewTarget(fp->mRawImagep, 2.0f);
+        break;
+    default:
+        break;
+    }
+
+    fp->mAvatarPreview->refresh();
+    fp->mSculptedPreview->refresh();
 }
 
 
@@ -231,16 +231,16 @@ void	LLFloaterImagePreview::onPreviewTypeCommit(LLUICtrl* ctrl, void* userdata)
 //-----------------------------------------------------------------------------
 void LLFloaterImagePreview::clearAllPreviewTextures()
 {
-	if (mAvatarPreview)
-	{
-		mAvatarPreview->clearPreviewTexture("mHairMesh0");
-		mAvatarPreview->clearPreviewTexture("mUpperBodyMesh0");
-		mAvatarPreview->clearPreviewTexture("mLowerBodyMesh0");
-		mAvatarPreview->clearPreviewTexture("mHeadMesh0");
-		mAvatarPreview->clearPreviewTexture("mUpperBodyMesh0");
-		mAvatarPreview->clearPreviewTexture("mLowerBodyMesh0");
-		mAvatarPreview->clearPreviewTexture("mSkirtMesh0");
-	}
+    if (mAvatarPreview)
+    {
+        mAvatarPreview->clearPreviewTexture("mHairMesh0");
+        mAvatarPreview->clearPreviewTexture("mUpperBodyMesh0");
+        mAvatarPreview->clearPreviewTexture("mLowerBodyMesh0");
+        mAvatarPreview->clearPreviewTexture("mHeadMesh0");
+        mAvatarPreview->clearPreviewTexture("mUpperBodyMesh0");
+        mAvatarPreview->clearPreviewTexture("mLowerBodyMesh0");
+        mAvatarPreview->clearPreviewTexture("mSkirtMesh0");
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -248,92 +248,92 @@ void LLFloaterImagePreview::clearAllPreviewTextures()
 //-----------------------------------------------------------------------------
 void LLFloaterImagePreview::draw()
 {
-	LLFloater::draw();
-	LLRect r = getRect();
-
-	if (mRawImagep.notNull())
-	{
-		LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
-		U32 selected = 0;
-		if (iface)
-			selected = iface->getFirstSelectedIndex();
-		
-		if (selected <= 0)
-		{
-			gl_rect_2d_checkerboard(mPreviewRect);
-
-			if(mImagep.notNull())
-			{
-				gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mImagep->getTexName());
-			}
-			else
-			{
-				mImagep = LLViewerTextureManager::getLocalTexture(mRawImagep.get(), FALSE) ;
-				
-				gGL.getTexUnit(0)->unbind(mImagep->getTarget()) ;
-				gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mImagep->getTexName());
-				stop_glerror();
-
-				gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
-				
-				gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
-				if (mAvatarPreview)
-				{
-					mAvatarPreview->setTexture(mImagep->getTexName());
-					mSculptedPreview->setTexture(mImagep->getTexName());
-				}
-			}
-
-			gGL.color3f(1.f, 1.f, 1.f);
-			gGL.begin( LLRender::TRIANGLE_STRIP );
-			{
-				gGL.texCoord2f(mPreviewImageRect.mLeft, mPreviewImageRect.mTop);
-				gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD);
-				gGL.texCoord2f(mPreviewImageRect.mLeft, mPreviewImageRect.mBottom);
-				gGL.vertex2i(PREVIEW_HPAD, PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
-				gGL.texCoord2f(mPreviewImageRect.mRight, mPreviewImageRect.mTop);
-				gGL.vertex2i(r.getWidth() - PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD);
-				gGL.texCoord2f(mPreviewImageRect.mRight, mPreviewImageRect.mBottom);
-				gGL.vertex2i(r.getWidth() - PREVIEW_HPAD, PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
-			}
-			gGL.end();
-
-			gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-			stop_glerror();
-		}
-		else
-		{
-			if ((mAvatarPreview) && (mSculptedPreview))
-			{
-				gGL.color3f(1.f, 1.f, 1.f);
-
-				if (selected == 9)
-				{
-					gGL.getTexUnit(0)->bind(mSculptedPreview);
-				}
-				else
-				{
-					gGL.getTexUnit(0)->bind(mAvatarPreview);
-				}
-
-				gGL.begin( LLRender::TRIANGLE_STRIP );
-				{
-					gGL.texCoord2f(0.f, 1.f);
-					gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD);
-					gGL.texCoord2f(0.f, 0.f);
-					gGL.vertex2i(PREVIEW_HPAD, PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
-					gGL.texCoord2f(1.f, 1.f);
-					gGL.vertex2i(r.getWidth() - PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD);
-					gGL.texCoord2f(1.f, 0.f);
-					gGL.vertex2i(r.getWidth() - PREVIEW_HPAD, PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
-				}
-				gGL.end();
-
-				gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-			}
-		}
-	}
+    LLFloater::draw();
+    LLRect r = getRect();
+
+    if (mRawImagep.notNull())
+    {
+        LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
+        U32 selected = 0;
+        if (iface)
+            selected = iface->getFirstSelectedIndex();
+
+        if (selected <= 0)
+        {
+            gl_rect_2d_checkerboard(mPreviewRect);
+
+            if(mImagep.notNull())
+            {
+                gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mImagep->getTexName());
+            }
+            else
+            {
+                mImagep = LLViewerTextureManager::getLocalTexture(mRawImagep.get(), FALSE) ;
+
+                gGL.getTexUnit(0)->unbind(mImagep->getTarget()) ;
+                gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mImagep->getTexName());
+                stop_glerror();
+
+                gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
+
+                gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
+                if (mAvatarPreview)
+                {
+                    mAvatarPreview->setTexture(mImagep->getTexName());
+                    mSculptedPreview->setTexture(mImagep->getTexName());
+                }
+            }
+
+            gGL.color3f(1.f, 1.f, 1.f);
+            gGL.begin( LLRender::TRIANGLE_STRIP );
+            {
+                gGL.texCoord2f(mPreviewImageRect.mLeft, mPreviewImageRect.mTop);
+                gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD);
+                gGL.texCoord2f(mPreviewImageRect.mLeft, mPreviewImageRect.mBottom);
+                gGL.vertex2i(PREVIEW_HPAD, PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
+                gGL.texCoord2f(mPreviewImageRect.mRight, mPreviewImageRect.mTop);
+                gGL.vertex2i(r.getWidth() - PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD);
+                gGL.texCoord2f(mPreviewImageRect.mRight, mPreviewImageRect.mBottom);
+                gGL.vertex2i(r.getWidth() - PREVIEW_HPAD, PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
+            }
+            gGL.end();
+
+            gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+
+            stop_glerror();
+        }
+        else
+        {
+            if ((mAvatarPreview) && (mSculptedPreview))
+            {
+                gGL.color3f(1.f, 1.f, 1.f);
+
+                if (selected == 9)
+                {
+                    gGL.getTexUnit(0)->bind(mSculptedPreview);
+                }
+                else
+                {
+                    gGL.getTexUnit(0)->bind(mAvatarPreview);
+                }
+
+                gGL.begin( LLRender::TRIANGLE_STRIP );
+                {
+                    gGL.texCoord2f(0.f, 1.f);
+                    gGL.vertex2i(PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD);
+                    gGL.texCoord2f(0.f, 0.f);
+                    gGL.vertex2i(PREVIEW_HPAD, PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
+                    gGL.texCoord2f(1.f, 1.f);
+                    gGL.vertex2i(r.getWidth() - PREVIEW_HPAD, PREVIEW_TEXTURE_HEIGHT + PREVIEW_VPAD);
+                    gGL.texCoord2f(1.f, 0.f);
+                    gGL.vertex2i(r.getWidth() - PREVIEW_HPAD, PREVIEW_HPAD + PREF_BUTTON_HEIGHT + PREVIEW_HPAD);
+                }
+                gGL.end();
+
+                gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+            }
+        }
+    }
 }
 
 
@@ -344,62 +344,62 @@ bool LLFloaterImagePreview::loadImage(const std::string& src_filename)
 {
     try
     {
-	std::string exten = gDirUtilp->getExtension(src_filename);
-	U32 codec = LLImageBase::getCodecFromExtension(exten);
-
-	LLImageDimensionsInfo image_info;
-	if (!image_info.load(src_filename,codec))
-	{
-		mImageLoadError = image_info.getLastError();
-		return false;
-	}
-
-	S32 max_width = gSavedSettings.getS32("max_texture_dimension_X");
-	S32 max_height = gSavedSettings.getS32("max_texture_dimension_Y");
-
-	if ((image_info.getWidth() > max_width) || (image_info.getHeight() > max_height))
-	{
-		LLStringUtil::format_map_t args;
-		args["WIDTH"] = llformat("%d", max_width);
-		args["HEIGHT"] = llformat("%d", max_height);
-
-		mImageLoadError = LLTrans::getString("texture_load_dimensions_error", args);
-		return false;
-	}
-	
-	// Load the image
-	LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
-	if (image.isNull())
-	{
-		return false;
-	}
-	if (!image->load(src_filename))
-	{
-		return false;
-	}
-	// Decompress or expand it in a raw image structure
-	LLPointer<LLImageRaw> raw_image = new LLImageRaw;
-	if (!image->decode(raw_image, 0.0f))
-	{
-		return false;
-	}
-	// Check the image constraints
-	if ((image->getComponents() != 3) && (image->getComponents() != 4))
-	{
-		image->setLastError("Image files with less than 3 or more than 4 components are not supported.");
-		return false;
-	}
-	
-	raw_image->biasedScaleToPowerOfTwo(LLViewerFetchedTexture::MAX_IMAGE_SIZE_DEFAULT);
-	mRawImagep = raw_image;
+    std::string exten = gDirUtilp->getExtension(src_filename);
+    U32 codec = LLImageBase::getCodecFromExtension(exten);
+
+    LLImageDimensionsInfo image_info;
+    if (!image_info.load(src_filename,codec))
+    {
+        mImageLoadError = image_info.getLastError();
+        return false;
+    }
+
+    S32 max_width = gSavedSettings.getS32("max_texture_dimension_X");
+    S32 max_height = gSavedSettings.getS32("max_texture_dimension_Y");
+
+    if ((image_info.getWidth() > max_width) || (image_info.getHeight() > max_height))
+    {
+        LLStringUtil::format_map_t args;
+        args["WIDTH"] = llformat("%d", max_width);
+        args["HEIGHT"] = llformat("%d", max_height);
+
+        mImageLoadError = LLTrans::getString("texture_load_dimensions_error", args);
+        return false;
+    }
+
+    // Load the image
+    LLPointer<LLImageFormatted> image = LLImageFormatted::createFromType(codec);
+    if (image.isNull())
+    {
+        return false;
+    }
+    if (!image->load(src_filename))
+    {
+        return false;
+    }
+    // Decompress or expand it in a raw image structure
+    LLPointer<LLImageRaw> raw_image = new LLImageRaw;
+    if (!image->decode(raw_image, 0.0f))
+    {
+        return false;
+    }
+    // Check the image constraints
+    if ((image->getComponents() != 3) && (image->getComponents() != 4))
+    {
+        image->setLastError("Image files with less than 3 or more than 4 components are not supported.");
+        return false;
+    }
+
+    raw_image->biasedScaleToPowerOfTwo(LLViewerFetchedTexture::MAX_IMAGE_SIZE_DEFAULT);
+    mRawImagep = raw_image;
     }
     catch (...)
     {
         LOG_UNHANDLED_EXCEPTION("");
         return false;
     }
-	
-	return true;
+
+    return true;
 }
 
 //-----------------------------------------------------------------------------
@@ -407,17 +407,17 @@ bool LLFloaterImagePreview::loadImage(const std::string& src_filename)
 //-----------------------------------------------------------------------------
 BOOL LLFloaterImagePreview::handleMouseDown(S32 x, S32 y, MASK mask)
 {
-	if (mPreviewRect.pointInRect(x, y))
-	{
-		bringToFront( x, y );
-		gFocusMgr.setMouseCapture(this);
-		gViewerWindow->hideCursor();
-		mLastMouseX = x;
-		mLastMouseY = y;
-		return TRUE;
-	}
+    if (mPreviewRect.pointInRect(x, y))
+    {
+        bringToFront( x, y );
+        gFocusMgr.setMouseCapture(this);
+        gViewerWindow->hideCursor();
+        mLastMouseX = x;
+        mLastMouseY = y;
+        return TRUE;
+    }
 
-	return LLFloater::handleMouseDown(x, y, mask);
+    return LLFloater::handleMouseDown(x, y, mask);
 }
 
 //-----------------------------------------------------------------------------
@@ -425,9 +425,9 @@ BOOL LLFloaterImagePreview::handleMouseDown(S32 x, S32 y, MASK mask)
 //-----------------------------------------------------------------------------
 BOOL LLFloaterImagePreview::handleMouseUp(S32 x, S32 y, MASK mask)
 {
-	gFocusMgr.setMouseCapture(FALSE);
-	gViewerWindow->showCursor();
-	return LLFloater::handleMouseUp(x, y, mask);
+    gFocusMgr.setMouseCapture(FALSE);
+    gViewerWindow->showCursor();
+    return LLFloater::handleMouseUp(x, y, mask);
 }
 
 //-----------------------------------------------------------------------------
@@ -435,119 +435,119 @@ BOOL LLFloaterImagePreview::handleMouseUp(S32 x, S32 y, MASK mask)
 //-----------------------------------------------------------------------------
 BOOL LLFloaterImagePreview::handleHover(S32 x, S32 y, MASK mask)
 {
-	MASK local_mask = mask & ~MASK_ALT;
-
-	if (mAvatarPreview && hasMouseCapture())
-	{
-		if (local_mask == MASK_PAN)
-		{
-			// pan here
-			LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
-			if (iface && iface->getFirstSelectedIndex() <= 0)
-			{
-				mPreviewImageRect.translate((F32)(x - mLastMouseX) * -0.005f * mPreviewImageRect.getWidth(), 
-					(F32)(y - mLastMouseY) * -0.005f * mPreviewImageRect.getHeight());
-			}
-			else
-			{
-				mAvatarPreview->pan((F32)(x - mLastMouseX) * -0.005f, (F32)(y - mLastMouseY) * -0.005f);
-				mSculptedPreview->pan((F32)(x - mLastMouseX) * -0.005f, (F32)(y - mLastMouseY) * -0.005f);
-			}
-		}
-		else if (local_mask == MASK_ORBIT)
-		{
-			F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
-			F32 pitch_radians = (F32)(y - mLastMouseY) * 0.02f;
-			
-			mAvatarPreview->rotate(yaw_radians, pitch_radians);
-			mSculptedPreview->rotate(yaw_radians, pitch_radians);
-		}
-		else 
-		{
-			LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
-			if (iface && iface->getFirstSelectedIndex() <= 0)
-			{
-				F32 zoom_amt = (F32)(y - mLastMouseY) * -0.002f;
-				mPreviewImageRect.stretch(zoom_amt);
-			}
-			else
-			{
-				F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
-				F32 zoom_amt = (F32)(y - mLastMouseY) * 0.02f;
-				
-				mAvatarPreview->rotate(yaw_radians, 0.f);
-				mAvatarPreview->zoom(zoom_amt);
-				mSculptedPreview->rotate(yaw_radians, 0.f);
-				mSculptedPreview->zoom(zoom_amt);
-			}
-		}
-
-		LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
-		if (iface && iface->getFirstSelectedIndex() <= 0)
-		{
-			if (mPreviewImageRect.getWidth() > 1.f)
-			{
-				mPreviewImageRect.stretch((1.f - mPreviewImageRect.getWidth()) * 0.5f);
-			}
-			else if (mPreviewImageRect.getWidth() < 0.1f)
-			{
-				mPreviewImageRect.stretch((0.1f - mPreviewImageRect.getWidth()) * 0.5f);
-			}
-
-			if (mPreviewImageRect.getHeight() > 1.f)
-			{
-				mPreviewImageRect.stretch((1.f - mPreviewImageRect.getHeight()) * 0.5f);
-			}
-			else if (mPreviewImageRect.getHeight() < 0.1f)
-			{
-				mPreviewImageRect.stretch((0.1f - mPreviewImageRect.getHeight()) * 0.5f);
-			}
-
-			if (mPreviewImageRect.mLeft < 0.f)
-			{
-				mPreviewImageRect.translate(-mPreviewImageRect.mLeft, 0.f);
-			}
-			else if (mPreviewImageRect.mRight > 1.f)
-			{
-				mPreviewImageRect.translate(1.f - mPreviewImageRect.mRight, 0.f);
-			}
-
-			if (mPreviewImageRect.mBottom < 0.f)
-			{
-				mPreviewImageRect.translate(0.f, -mPreviewImageRect.mBottom);
-			}
-			else if (mPreviewImageRect.mTop > 1.f)
-			{
-				mPreviewImageRect.translate(0.f, 1.f - mPreviewImageRect.mTop);
-			}
-		}
-		else
-		{
-			mAvatarPreview->refresh();
-			mSculptedPreview->refresh();
-		}
-
-		LLUI::setMousePositionLocal(this, mLastMouseX, mLastMouseY);
-	}
-
-	if (!mPreviewRect.pointInRect(x, y) || !mAvatarPreview || !mSculptedPreview)
-	{
-		return LLFloater::handleHover(x, y, mask);
-	}
-	else if (local_mask == MASK_ORBIT)
-	{
-		gViewerWindow->setCursor(UI_CURSOR_TOOLCAMERA);
-	}
-	else if (local_mask == MASK_PAN)
-	{
-		gViewerWindow->setCursor(UI_CURSOR_TOOLPAN);
-	}
-	else
-	{
-		gViewerWindow->setCursor(UI_CURSOR_TOOLZOOMIN);
-	}
-
-	return TRUE;
+    MASK local_mask = mask & ~MASK_ALT;
+
+    if (mAvatarPreview && hasMouseCapture())
+    {
+        if (local_mask == MASK_PAN)
+        {
+            // pan here
+            LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
+            if (iface && iface->getFirstSelectedIndex() <= 0)
+            {
+                mPreviewImageRect.translate((F32)(x - mLastMouseX) * -0.005f * mPreviewImageRect.getWidth(),
+                    (F32)(y - mLastMouseY) * -0.005f * mPreviewImageRect.getHeight());
+            }
+            else
+            {
+                mAvatarPreview->pan((F32)(x - mLastMouseX) * -0.005f, (F32)(y - mLastMouseY) * -0.005f);
+                mSculptedPreview->pan((F32)(x - mLastMouseX) * -0.005f, (F32)(y - mLastMouseY) * -0.005f);
+            }
+        }
+        else if (local_mask == MASK_ORBIT)
+        {
+            F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
+            F32 pitch_radians = (F32)(y - mLastMouseY) * 0.02f;
+
+            mAvatarPreview->rotate(yaw_radians, pitch_radians);
+            mSculptedPreview->rotate(yaw_radians, pitch_radians);
+        }
+        else
+        {
+            LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
+            if (iface && iface->getFirstSelectedIndex() <= 0)
+            {
+                F32 zoom_amt = (F32)(y - mLastMouseY) * -0.002f;
+                mPreviewImageRect.stretch(zoom_amt);
+            }
+            else
+            {
+                F32 yaw_radians = (F32)(x - mLastMouseX) * -0.01f;
+                F32 zoom_amt = (F32)(y - mLastMouseY) * 0.02f;
+
+                mAvatarPreview->rotate(yaw_radians, 0.f);
+                mAvatarPreview->zoom(zoom_amt);
+                mSculptedPreview->rotate(yaw_radians, 0.f);
+                mSculptedPreview->zoom(zoom_amt);
+            }
+        }
+
+        LLCtrlSelectionInterface* iface = childGetSelectionInterface("clothing_type_combo");
+        if (iface && iface->getFirstSelectedIndex() <= 0)
+        {
+            if (mPreviewImageRect.getWidth() > 1.f)
+            {
+                mPreviewImageRect.stretch((1.f - mPreviewImageRect.getWidth()) * 0.5f);
+            }
+            else if (mPreviewImageRect.getWidth() < 0.1f)
+            {
+                mPreviewImageRect.stretch((0.1f - mPreviewImageRect.getWidth()) * 0.5f);
+            }
+
+            if (mPreviewImageRect.getHeight() > 1.f)
+            {
+                mPreviewImageRect.stretch((1.f - mPreviewImageRect.getHeight()) * 0.5f);
+            }
+            else if (mPreviewImageRect.getHeight() < 0.1f)
+            {
+                mPreviewImageRect.stretch((0.1f - mPreviewImageRect.getHeight()) * 0.5f);
+            }
+
+            if (mPreviewImageRect.mLeft < 0.f)
+            {
+                mPreviewImageRect.translate(-mPreviewImageRect.mLeft, 0.f);
+            }
+            else if (mPreviewImageRect.mRight > 1.f)
+            {
+                mPreviewImageRect.translate(1.f - mPreviewImageRect.mRight, 0.f);
+            }
+
+            if (mPreviewImageRect.mBottom < 0.f)
+            {
+                mPreviewImageRect.translate(0.f, -mPreviewImageRect.mBottom);
+            }
+            else if (mPreviewImageRect.mTop > 1.f)
+            {
+                mPreviewImageRect.translate(0.f, 1.f - mPreviewImageRect.mTop);
+            }
+        }
+        else
+        {
+            mAvatarPreview->refresh();
+            mSculptedPreview->refresh();
+        }
+
+        LLUI::setMousePositionLocal(this, mLastMouseX, mLastMouseY);
+    }
+
+    if (!mPreviewRect.pointInRect(x, y) || !mAvatarPreview || !mSculptedPreview)
+    {
+        return LLFloater::handleHover(x, y, mask);
+    }
+    else if (local_mask == MASK_ORBIT)
+    {
+        gViewerWindow->setCursor(UI_CURSOR_TOOLCAMERA);
+    }
+    else if (local_mask == MASK_PAN)
+    {
+        gViewerWindow->setCursor(UI_CURSOR_TOOLPAN);
+    }
+    else
+    {
+        gViewerWindow->setCursor(UI_CURSOR_TOOLZOOMIN);
+    }
+
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -555,16 +555,16 @@ BOOL LLFloaterImagePreview::handleHover(S32 x, S32 y, MASK mask)
 //-----------------------------------------------------------------------------
 BOOL LLFloaterImagePreview::handleScrollWheel(S32 x, S32 y, S32 clicks)
 {
-	if (mPreviewRect.pointInRect(x, y) && mAvatarPreview)
-	{
-		mAvatarPreview->zoom((F32)clicks * -0.2f);
-		mAvatarPreview->refresh();
+    if (mPreviewRect.pointInRect(x, y) && mAvatarPreview)
+    {
+        mAvatarPreview->zoom((F32)clicks * -0.2f);
+        mAvatarPreview->refresh();
 
-		mSculptedPreview->zoom((F32)clicks * -0.2f);
-		mSculptedPreview->refresh();
-	}
+        mSculptedPreview->zoom((F32)clicks * -0.2f);
+        mSculptedPreview->refresh();
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -573,7 +573,7 @@ BOOL LLFloaterImagePreview::handleScrollWheel(S32 x, S32 y, S32 clicks)
 // static
 void LLFloaterImagePreview::onMouseCaptureLostImagePreview(LLMouseHandler* handler)
 {
-	gViewerWindow->showCursor();
+    gViewerWindow->showCursor();
 }
 
 
@@ -582,63 +582,63 @@ void LLFloaterImagePreview::onMouseCaptureLostImagePreview(LLMouseHandler* handl
 //-----------------------------------------------------------------------------
 LLImagePreviewAvatar::LLImagePreviewAvatar(S32 width, S32 height) : LLViewerDynamicTexture(width, height, 3, ORDER_MIDDLE, FALSE)
 {
-	mNeedsUpdate = TRUE;
-	mTargetJoint = NULL;
-	mTargetMesh = NULL;
-	mCameraDistance = 0.f;
-	mCameraYaw = 0.f;
-	mCameraPitch = 0.f;
-	mCameraZoom = 1.f;
+    mNeedsUpdate = TRUE;
+    mTargetJoint = NULL;
+    mTargetMesh = NULL;
+    mCameraDistance = 0.f;
+    mCameraYaw = 0.f;
+    mCameraPitch = 0.f;
+    mCameraZoom = 1.f;
 
-	mDummyAvatar = (LLVOAvatar*)gObjectList.createObjectViewer(LL_PCODE_LEGACY_AVATAR, gAgent.getRegion(), LLViewerObject::CO_FLAG_UI_AVATAR);
-	mDummyAvatar->mSpecialRenderMode = 2;
+    mDummyAvatar = (LLVOAvatar*)gObjectList.createObjectViewer(LL_PCODE_LEGACY_AVATAR, gAgent.getRegion(), LLViewerObject::CO_FLAG_UI_AVATAR);
+    mDummyAvatar->mSpecialRenderMode = 2;
 
-	mTextureName = 0;
+    mTextureName = 0;
 }
 
 
 LLImagePreviewAvatar::~LLImagePreviewAvatar()
 {
-	mDummyAvatar->markDead();
+    mDummyAvatar->markDead();
 }
 
 //virtual
 S8 LLImagePreviewAvatar::getType() const
 {
-	return LLViewerDynamicTexture::LL_IMAGE_PREVIEW_AVATAR ;
-}
-
-void LLImagePreviewAvatar::setPreviewTarget(const std::string& joint_name, const std::string& mesh_name, LLImageRaw* imagep, F32 distance, BOOL male) 
-{ 
-	mTargetJoint = mDummyAvatar->mRoot->findJoint(joint_name);
-	// clear out existing test mesh
-	if (mTargetMesh)
-	{
-		mTargetMesh->setTestTexture(0);
-	}
-
-	if (male)
-	{
-		mDummyAvatar->setVisualParamWeight( "male", 1.f );
-		mDummyAvatar->updateVisualParams();
-		mDummyAvatar->updateGeometry(mDummyAvatar->mDrawable);
-	}
-	else
-	{
-		mDummyAvatar->setVisualParamWeight( "male", 0.f );
-		mDummyAvatar->updateVisualParams();
-		mDummyAvatar->updateGeometry(mDummyAvatar->mDrawable);
-	}
-	mDummyAvatar->mRoot->setVisible(FALSE, TRUE);
-
-	mTargetMesh = dynamic_cast<LLViewerJointMesh*>(mDummyAvatar->mRoot->findJoint(mesh_name));
-	mTargetMesh->setTestTexture(mTextureName);
-	mTargetMesh->setVisible(TRUE, FALSE);
-	mCameraDistance = distance;
-	mCameraZoom = 1.f;
-	mCameraPitch = 0.f;
-	mCameraYaw = 0.f;
-	mCameraOffset.clearVec();
+    return LLViewerDynamicTexture::LL_IMAGE_PREVIEW_AVATAR ;
+}
+
+void LLImagePreviewAvatar::setPreviewTarget(const std::string& joint_name, const std::string& mesh_name, LLImageRaw* imagep, F32 distance, BOOL male)
+{
+    mTargetJoint = mDummyAvatar->mRoot->findJoint(joint_name);
+    // clear out existing test mesh
+    if (mTargetMesh)
+    {
+        mTargetMesh->setTestTexture(0);
+    }
+
+    if (male)
+    {
+        mDummyAvatar->setVisualParamWeight( "male", 1.f );
+        mDummyAvatar->updateVisualParams();
+        mDummyAvatar->updateGeometry(mDummyAvatar->mDrawable);
+    }
+    else
+    {
+        mDummyAvatar->setVisualParamWeight( "male", 0.f );
+        mDummyAvatar->updateVisualParams();
+        mDummyAvatar->updateGeometry(mDummyAvatar->mDrawable);
+    }
+    mDummyAvatar->mRoot->setVisible(FALSE, TRUE);
+
+    mTargetMesh = dynamic_cast<LLViewerJointMesh*>(mDummyAvatar->mRoot->findJoint(mesh_name));
+    mTargetMesh->setTestTexture(mTextureName);
+    mTargetMesh->setVisible(TRUE, FALSE);
+    mCameraDistance = distance;
+    mCameraZoom = 1.f;
+    mCameraPitch = 0.f;
+    mCameraYaw = 0.f;
+    mCameraOffset.clearVec();
 }
 
 //-----------------------------------------------------------------------------
@@ -646,15 +646,15 @@ void LLImagePreviewAvatar::setPreviewTarget(const std::string& joint_name, const
 //-----------------------------------------------------------------------------
 void LLImagePreviewAvatar::clearPreviewTexture(const std::string& mesh_name)
 {
-	if (mDummyAvatar)
-	{
-		LLViewerJointMesh *mesh = dynamic_cast<LLViewerJointMesh*>(mDummyAvatar->mRoot->findJoint(mesh_name));
-		// clear out existing test mesh
-		if (mesh)
-		{
-			mesh->setTestTexture(0);
-		}
-	}
+    if (mDummyAvatar)
+    {
+        LLViewerJointMesh *mesh = dynamic_cast<LLViewerJointMesh*>(mDummyAvatar->mRoot->findJoint(mesh_name));
+        // clear out existing test mesh
+        if (mesh)
+        {
+            mesh->setTestTexture(0);
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -662,82 +662,82 @@ void LLImagePreviewAvatar::clearPreviewTexture(const std::string& mesh_name)
 //-----------------------------------------------------------------------------
 BOOL LLImagePreviewAvatar::render()
 {
-	mNeedsUpdate = FALSE;
-	LLVOAvatar* avatarp = mDummyAvatar;
+    mNeedsUpdate = FALSE;
+    LLVOAvatar* avatarp = mDummyAvatar;
+
+    gGL.pushUIMatrix();
+    gGL.loadUIIdentity();
 
-	gGL.pushUIMatrix();
-	gGL.loadUIIdentity();
+    gGL.matrixMode(LLRender::MM_PROJECTION);
+    gGL.pushMatrix();
+    gGL.loadIdentity();
+    gGL.ortho(0.0f, mFullWidth, 0.0f, mFullHeight, -1.0f, 1.0f);
 
-	gGL.matrixMode(LLRender::MM_PROJECTION);
-	gGL.pushMatrix();
-	gGL.loadIdentity();
-	gGL.ortho(0.0f, mFullWidth, 0.0f, mFullHeight, -1.0f, 1.0f);
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+    gGL.loadIdentity();
 
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-	gGL.loadIdentity();
-	
 
-	LLGLSUIDefault def;
-	gGL.color4f(0.15f, 0.2f, 0.3f, 1.f);
+    LLGLSUIDefault def;
+    gGL.color4f(0.15f, 0.2f, 0.3f, 1.f);
 
-	gUIProgram.bind();
+    gUIProgram.bind();
 
-	gl_rect_2d_simple( mFullWidth, mFullHeight );
+    gl_rect_2d_simple( mFullWidth, mFullHeight );
 
-	gGL.matrixMode(LLRender::MM_PROJECTION);
-	gGL.popMatrix();
+    gGL.matrixMode(LLRender::MM_PROJECTION);
+    gGL.popMatrix();
 
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.popMatrix();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.popMatrix();
 
-	gGL.flush();
-	LLVector3 target_pos = mTargetJoint->getWorldPosition();
+    gGL.flush();
+    LLVector3 target_pos = mTargetJoint->getWorldPosition();
 
-	LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) * 
-		LLQuaternion(mCameraYaw, LLVector3::z_axis);
+    LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) *
+        LLQuaternion(mCameraYaw, LLVector3::z_axis);
 
-	LLQuaternion av_rot = avatarp->mPelvisp->getWorldRotation() * camera_rot;
-	LLViewerCamera::getInstance()->setOriginAndLookAt(
-		target_pos + ((LLVector3(mCameraDistance, 0.f, 0.f) + mCameraOffset) * av_rot),		// camera
-		LLVector3::z_axis,																	// up
-		target_pos + (mCameraOffset  * av_rot) );											// point of interest
+    LLQuaternion av_rot = avatarp->mPelvisp->getWorldRotation() * camera_rot;
+    LLViewerCamera::getInstance()->setOriginAndLookAt(
+        target_pos + ((LLVector3(mCameraDistance, 0.f, 0.f) + mCameraOffset) * av_rot),     // camera
+        LLVector3::z_axis,                                                                  // up
+        target_pos + (mCameraOffset  * av_rot) );                                           // point of interest
 
-	stop_glerror();
+    stop_glerror();
 
-	LLViewerCamera::getInstance()->setAspect((F32)mFullWidth / mFullHeight);
-	LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom);
-	LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight, FALSE);
+    LLViewerCamera::getInstance()->setAspect((F32)mFullWidth / mFullHeight);
+    LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom);
+    LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight, FALSE);
 
-	LLVertexBuffer::unbind();
-	avatarp->updateLOD();
-		
-	if (avatarp->mDrawable.notNull())
-	{
-		LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE);
-		// make sure alpha=0 shows avatar material color
-		LLGLDisable no_blend(GL_BLEND);
+    LLVertexBuffer::unbind();
+    avatarp->updateLOD();
 
-		LLFace* face = avatarp->mDrawable->getFace(0);
-		if (face)
-		{
-			LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)face->getPool();
-			gPipeline.enableLightsPreview();
-			avatarPoolp->renderAvatars(avatarp);  // renders only one avatar
-		}
-	}
+    if (avatarp->mDrawable.notNull())
+    {
+        LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE);
+        // make sure alpha=0 shows avatar material color
+        LLGLDisable no_blend(GL_BLEND);
+
+        LLFace* face = avatarp->mDrawable->getFace(0);
+        if (face)
+        {
+            LLDrawPoolAvatar *avatarPoolp = (LLDrawPoolAvatar *)face->getPool();
+            gPipeline.enableLightsPreview();
+            avatarPoolp->renderAvatars(avatarp);  // renders only one avatar
+        }
+    }
 
-	gGL.popUIMatrix();
-	gGL.color4f(1,1,1,1);
-	return TRUE;
+    gGL.popUIMatrix();
+    gGL.color4f(1,1,1,1);
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
 // refresh()
 //-----------------------------------------------------------------------------
 void LLImagePreviewAvatar::refresh()
-{ 
-	mNeedsUpdate = TRUE; 
+{
+    mNeedsUpdate = TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -745,9 +745,9 @@ void LLImagePreviewAvatar::refresh()
 //-----------------------------------------------------------------------------
 void LLImagePreviewAvatar::rotate(F32 yaw_radians, F32 pitch_radians)
 {
-	mCameraYaw = mCameraYaw + yaw_radians;
+    mCameraYaw = mCameraYaw + yaw_radians;
 
-	mCameraPitch = llclamp(mCameraPitch + pitch_radians, F_PI_BY_TWO * -0.8f, F_PI_BY_TWO * 0.8f);
+    mCameraPitch = llclamp(mCameraPitch + pitch_radians, F_PI_BY_TWO * -0.8f, F_PI_BY_TWO * 0.8f);
 }
 
 //-----------------------------------------------------------------------------
@@ -755,13 +755,13 @@ void LLImagePreviewAvatar::rotate(F32 yaw_radians, F32 pitch_radians)
 //-----------------------------------------------------------------------------
 void LLImagePreviewAvatar::zoom(F32 zoom_amt)
 {
-	mCameraZoom	= llclamp(mCameraZoom + zoom_amt, 1.f, 10.f);
+    mCameraZoom = llclamp(mCameraZoom + zoom_amt, 1.f, 10.f);
 }
 
 void LLImagePreviewAvatar::pan(F32 right, F32 up)
 {
-	mCameraOffset.mV[VY] = llclamp(mCameraOffset.mV[VY] + right * mCameraDistance / mCameraZoom, -1.f, 1.f);
-	mCameraOffset.mV[VZ] = llclamp(mCameraOffset.mV[VZ] + up * mCameraDistance / mCameraZoom, -1.f, 1.f);
+    mCameraOffset.mV[VY] = llclamp(mCameraOffset.mV[VY] + right * mCameraDistance / mCameraZoom, -1.f, 1.f);
+    mCameraOffset.mV[VZ] = llclamp(mCameraOffset.mV[VZ] + up * mCameraDistance / mCameraZoom, -1.f, 1.f);
 }
 
 
@@ -771,19 +771,19 @@ void LLImagePreviewAvatar::pan(F32 right, F32 up)
 
 LLImagePreviewSculpted::LLImagePreviewSculpted(S32 width, S32 height) : LLViewerDynamicTexture(width, height, 3, ORDER_MIDDLE, FALSE)
 {
-	mNeedsUpdate = TRUE;
-	mCameraDistance = 0.f;
-	mCameraYaw = 0.f;
-	mCameraPitch = 0.f;
-	mCameraZoom = 1.f;
-	mTextureName = 0;
+    mNeedsUpdate = TRUE;
+    mCameraDistance = 0.f;
+    mCameraYaw = 0.f;
+    mCameraPitch = 0.f;
+    mCameraZoom = 1.f;
+    mTextureName = 0;
+
+    LLVolumeParams volume_params;
+    volume_params.setType(LL_PCODE_PROFILE_CIRCLE, LL_PCODE_PATH_CIRCLE);
+    volume_params.setSculptID(LLUUID::null, LL_SCULPT_TYPE_SPHERE);
 
-	LLVolumeParams volume_params;
-	volume_params.setType(LL_PCODE_PROFILE_CIRCLE, LL_PCODE_PATH_CIRCLE);
-	volume_params.setSculptID(LLUUID::null, LL_SCULPT_TYPE_SPHERE);
-	
-	F32 const HIGHEST_LOD = 4.0f;
-	mVolume = new LLVolume(volume_params,  HIGHEST_LOD);
+    F32 const HIGHEST_LOD = 4.0f;
+    mVolume = new LLVolume(volume_params,  HIGHEST_LOD);
 }
 
 
@@ -794,67 +794,67 @@ LLImagePreviewSculpted::~LLImagePreviewSculpted()
 //virtual
 S8 LLImagePreviewSculpted::getType() const
 {
-	return LLViewerDynamicTexture::LL_IMAGE_PREVIEW_SCULPTED ;
+    return LLViewerDynamicTexture::LL_IMAGE_PREVIEW_SCULPTED ;
 }
 
 void LLImagePreviewSculpted::setPreviewTarget(LLImageRaw* imagep, F32 distance)
-{ 
-	mCameraDistance = distance;
-	mCameraZoom = 1.f;
-	mCameraPitch = 0.f;
-	mCameraYaw = 0.f;
-	mCameraOffset.clearVec();
-
-	if (imagep)
-	{
-		mVolume->sculpt(imagep->getWidth(), imagep->getHeight(), imagep->getComponents(), imagep->getData(), 0, false);
-	}
-
-	const LLVolumeFace &vf = mVolume->getVolumeFace(0);
-	U32 num_indices = vf.mNumIndices;
-	U32 num_vertices = vf.mNumVertices;
-
-	mVertexBuffer = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
-	if (!mVertexBuffer->allocateBuffer(num_vertices, num_indices))
-	{
-		LL_WARNS() << "Failed to allocate Vertex Buffer for image preview to"
-			<< num_vertices << " vertices and "
-			<< num_indices << " indices" << LL_ENDL;
-		// We are likely to crash on getTexCoord0Strider()
-	}
-
-	LLStrider<LLVector3> vertex_strider;
-	LLStrider<LLVector3> normal_strider;
-	LLStrider<LLVector2> tc_strider;
-	LLStrider<U16> index_strider;
-
-	mVertexBuffer->getVertexStrider(vertex_strider);
-	mVertexBuffer->getNormalStrider(normal_strider);
-	mVertexBuffer->getTexCoord0Strider(tc_strider);
-	mVertexBuffer->getIndexStrider(index_strider);
-
-	// build vertices and normals
-	LLStrider<LLVector3> pos;
-	pos = (LLVector3*) vf.mPositions; pos.setStride(16);
-	LLStrider<LLVector3> norm;
-	norm = (LLVector3*) vf.mNormals; norm.setStride(16);
-	LLStrider<LLVector2> tc;
-	tc = (LLVector2*) vf.mTexCoords; tc.setStride(8);
-
-	for (U32 i = 0; i < num_vertices; i++)
-	{
-		*(vertex_strider++) = *pos++;
-		LLVector3 normal = *norm++;
-		normal.normalize();
-		*(normal_strider++) = normal;
-		*(tc_strider++) = *tc++;
-	}
-
-	// build indices
-	for (U16 i = 0; i < num_indices; i++)
-	{
-		*(index_strider++) = vf.mIndices[i];
-	}
+{
+    mCameraDistance = distance;
+    mCameraZoom = 1.f;
+    mCameraPitch = 0.f;
+    mCameraYaw = 0.f;
+    mCameraOffset.clearVec();
+
+    if (imagep)
+    {
+        mVolume->sculpt(imagep->getWidth(), imagep->getHeight(), imagep->getComponents(), imagep->getData(), 0, false);
+    }
+
+    const LLVolumeFace &vf = mVolume->getVolumeFace(0);
+    U32 num_indices = vf.mNumIndices;
+    U32 num_vertices = vf.mNumVertices;
+
+    mVertexBuffer = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_TEXCOORD0);
+    if (!mVertexBuffer->allocateBuffer(num_vertices, num_indices))
+    {
+        LL_WARNS() << "Failed to allocate Vertex Buffer for image preview to"
+            << num_vertices << " vertices and "
+            << num_indices << " indices" << LL_ENDL;
+        // We are likely to crash on getTexCoord0Strider()
+    }
+
+    LLStrider<LLVector3> vertex_strider;
+    LLStrider<LLVector3> normal_strider;
+    LLStrider<LLVector2> tc_strider;
+    LLStrider<U16> index_strider;
+
+    mVertexBuffer->getVertexStrider(vertex_strider);
+    mVertexBuffer->getNormalStrider(normal_strider);
+    mVertexBuffer->getTexCoord0Strider(tc_strider);
+    mVertexBuffer->getIndexStrider(index_strider);
+
+    // build vertices and normals
+    LLStrider<LLVector3> pos;
+    pos = (LLVector3*) vf.mPositions; pos.setStride(16);
+    LLStrider<LLVector3> norm;
+    norm = (LLVector3*) vf.mNormals; norm.setStride(16);
+    LLStrider<LLVector2> tc;
+    tc = (LLVector2*) vf.mTexCoords; tc.setStride(8);
+
+    for (U32 i = 0; i < num_vertices; i++)
+    {
+        *(vertex_strider++) = *pos++;
+        LLVector3 normal = *norm++;
+        normal.normalize();
+        *(normal_strider++) = normal;
+        *(tc_strider++) = *tc++;
+    }
+
+    // build indices
+    for (U16 i = 0; i < num_indices; i++)
+    {
+        *(index_strider++) = vf.mIndices[i];
+    }
 
     mVertexBuffer->unmapBuffer();
 }
@@ -865,82 +865,82 @@ void LLImagePreviewSculpted::setPreviewTarget(LLImageRaw* imagep, F32 distance)
 //-----------------------------------------------------------------------------
 BOOL LLImagePreviewSculpted::render()
 {
-	mNeedsUpdate = FALSE;
-	LLGLSUIDefault def;
-	LLGLDisable no_blend(GL_BLEND);
-	LLGLEnable cull(GL_CULL_FACE);
-	LLGLDepthTest depth(GL_TRUE);
+    mNeedsUpdate = FALSE;
+    LLGLSUIDefault def;
+    LLGLDisable no_blend(GL_BLEND);
+    LLGLEnable cull(GL_CULL_FACE);
+    LLGLDepthTest depth(GL_TRUE);
+
+    gGL.matrixMode(LLRender::MM_PROJECTION);
+    gGL.pushMatrix();
+    gGL.loadIdentity();
+    gGL.ortho(0.0f, mFullWidth, 0.0f, mFullHeight, -1.0f, 1.0f);
 
-	gGL.matrixMode(LLRender::MM_PROJECTION);
-	gGL.pushMatrix();
-	gGL.loadIdentity();
-	gGL.ortho(0.0f, mFullWidth, 0.0f, mFullHeight, -1.0f, 1.0f);
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+    gGL.loadIdentity();
 
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-	gGL.loadIdentity();
-		
-	gGL.color4f(0.15f, 0.2f, 0.3f, 1.f);
+    gGL.color4f(0.15f, 0.2f, 0.3f, 1.f);
 
-	gUIProgram.bind();
+    gUIProgram.bind();
 
-	gl_rect_2d_simple( mFullWidth, mFullHeight );
-	
-	gGL.matrixMode(LLRender::MM_PROJECTION);
-	gGL.popMatrix();
+    gl_rect_2d_simple( mFullWidth, mFullHeight );
 
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.popMatrix();
+    gGL.matrixMode(LLRender::MM_PROJECTION);
+    gGL.popMatrix();
 
-	glClear(GL_DEPTH_BUFFER_BIT);
-	
-	LLVector3 target_pos(0, 0, 0);
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.popMatrix();
 
-	LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) * 
-		LLQuaternion(mCameraYaw, LLVector3::z_axis);
+    glClear(GL_DEPTH_BUFFER_BIT);
 
-	LLQuaternion av_rot = camera_rot;
-	LLViewerCamera::getInstance()->setOriginAndLookAt(
-		target_pos + ((LLVector3(mCameraDistance, 0.f, 0.f) + mCameraOffset) * av_rot),		// camera
-		LLVector3::z_axis,																	// up
-		target_pos + (mCameraOffset  * av_rot) );											// point of interest
+    LLVector3 target_pos(0, 0, 0);
 
-	stop_glerror();
+    LLQuaternion camera_rot = LLQuaternion(mCameraPitch, LLVector3::y_axis) *
+        LLQuaternion(mCameraYaw, LLVector3::z_axis);
 
-	LLViewerCamera::getInstance()->setAspect((F32) mFullWidth / mFullHeight);
-	LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom);
-	LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight, FALSE);
+    LLQuaternion av_rot = camera_rot;
+    LLViewerCamera::getInstance()->setOriginAndLookAt(
+        target_pos + ((LLVector3(mCameraDistance, 0.f, 0.f) + mCameraOffset) * av_rot),     // camera
+        LLVector3::z_axis,                                                                  // up
+        target_pos + (mCameraOffset  * av_rot) );                                           // point of interest
 
-	const LLVolumeFace &vf = mVolume->getVolumeFace(0);
-	U32 num_indices = vf.mNumIndices;
-	
-	gPipeline.enableLightsAvatar();
+    stop_glerror();
 
-	gObjectPreviewProgram.bind();
-	gPipeline.enableLightsPreview();
+    LLViewerCamera::getInstance()->setAspect((F32) mFullWidth / mFullHeight);
+    LLViewerCamera::getInstance()->setView(LLViewerCamera::getInstance()->getDefaultFOV() / mCameraZoom);
+    LLViewerCamera::getInstance()->setPerspective(FALSE, mOrigin.mX, mOrigin.mY, mFullWidth, mFullHeight, FALSE);
 
-	gGL.pushMatrix();
-	const F32 SCALE = 1.25f;
-	gGL.scalef(SCALE, SCALE, SCALE);
-	const F32 BRIGHTNESS = 0.9f;
-	gGL.diffuseColor3f(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS);
+    const LLVolumeFace &vf = mVolume->getVolumeFace(0);
+    U32 num_indices = vf.mNumIndices;
 
-	mVertexBuffer->setBuffer();
-	mVertexBuffer->draw(LLRender::TRIANGLES, num_indices, 0);
+    gPipeline.enableLightsAvatar();
 
-	gGL.popMatrix();
+    gObjectPreviewProgram.bind();
+    gPipeline.enableLightsPreview();
 
-	gObjectPreviewProgram.unbind();
+    gGL.pushMatrix();
+    const F32 SCALE = 1.25f;
+    gGL.scalef(SCALE, SCALE, SCALE);
+    const F32 BRIGHTNESS = 0.9f;
+    gGL.diffuseColor3f(BRIGHTNESS, BRIGHTNESS, BRIGHTNESS);
 
-	return TRUE;
+    mVertexBuffer->setBuffer();
+    mVertexBuffer->draw(LLRender::TRIANGLES, num_indices, 0);
+
+    gGL.popMatrix();
+
+    gObjectPreviewProgram.unbind();
+
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
 // refresh()
 //-----------------------------------------------------------------------------
 void LLImagePreviewSculpted::refresh()
-{ 
-	mNeedsUpdate = TRUE; 
+{
+    mNeedsUpdate = TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -948,9 +948,9 @@ void LLImagePreviewSculpted::refresh()
 //-----------------------------------------------------------------------------
 void LLImagePreviewSculpted::rotate(F32 yaw_radians, F32 pitch_radians)
 {
-	mCameraYaw = mCameraYaw + yaw_radians;
+    mCameraYaw = mCameraYaw + yaw_radians;
 
-	mCameraPitch = llclamp(mCameraPitch + pitch_radians, F_PI_BY_TWO * -0.8f, F_PI_BY_TWO * 0.8f);
+    mCameraPitch = llclamp(mCameraPitch + pitch_radians, F_PI_BY_TWO * -0.8f, F_PI_BY_TWO * 0.8f);
 }
 
 //-----------------------------------------------------------------------------
@@ -958,11 +958,11 @@ void LLImagePreviewSculpted::rotate(F32 yaw_radians, F32 pitch_radians)
 //-----------------------------------------------------------------------------
 void LLImagePreviewSculpted::zoom(F32 zoom_amt)
 {
-	mCameraZoom	= llclamp(mCameraZoom + zoom_amt, 1.f, 10.f);
+    mCameraZoom = llclamp(mCameraZoom + zoom_amt, 1.f, 10.f);
 }
 
 void LLImagePreviewSculpted::pan(F32 right, F32 up)
 {
-	mCameraOffset.mV[VY] = llclamp(mCameraOffset.mV[VY] + right * mCameraDistance / mCameraZoom, -1.f, 1.f);
-	mCameraOffset.mV[VZ] = llclamp(mCameraOffset.mV[VZ] + up * mCameraDistance / mCameraZoom, -1.f, 1.f);
+    mCameraOffset.mV[VY] = llclamp(mCameraOffset.mV[VY] + right * mCameraDistance / mCameraZoom, -1.f, 1.f);
+    mCameraOffset.mV[VZ] = llclamp(mCameraOffset.mV[VZ] + up * mCameraDistance / mCameraZoom, -1.f, 1.f);
 }
diff --git a/indra/newview/llfloaterimagepreview.h b/indra/newview/llfloaterimagepreview.h
index 173ad5ae5dae09fc3cb02ff0bf73a38da0dcdf87..850a5fb1dcf78b43c5907c6ea3ab0657f74381e4 100644
--- a/indra/newview/llfloaterimagepreview.h
+++ b/indra/newview/llfloaterimagepreview.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llfloaterimagepreview.h
  * @brief LLFloaterImagePreview class definition
  *
  * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -43,104 +43,104 @@ class LLVolume;
 class LLImagePreviewSculpted final : public LLViewerDynamicTexture
 {
 protected:
-	virtual ~LLImagePreviewSculpted();
+    virtual ~LLImagePreviewSculpted();
 
  public:
-	LLImagePreviewSculpted(S32 width, S32 height);	
+    LLImagePreviewSculpted(S32 width, S32 height);
 
-	S8 getType() const override;
+    S8 getType() const override;
 
-	void setPreviewTarget(LLImageRaw *imagep, F32 distance);
-	void setTexture(U32 name) { mTextureName = name; }
+    void setPreviewTarget(LLImageRaw *imagep, F32 distance);
+    void setTexture(U32 name) { mTextureName = name; }
 
-	BOOL render() override;
-	void refresh();
-	void rotate(F32 yaw_radians, F32 pitch_radians);
-	void zoom(F32 zoom_amt);
-	void pan(F32 right, F32 up);
-	virtual BOOL needsRender() override { return mNeedsUpdate; }
+    BOOL render() override;
+    void refresh();
+    void rotate(F32 yaw_radians, F32 pitch_radians);
+    void zoom(F32 zoom_amt);
+    void pan(F32 right, F32 up);
+    virtual BOOL needsRender() override { return mNeedsUpdate; }
 
  protected:
-	BOOL        mNeedsUpdate;
-	U32         mTextureName;
-	F32			mCameraDistance;
-	F32			mCameraYaw;
-	F32			mCameraPitch;
-	F32			mCameraZoom;
-	LLVector3	mCameraOffset;
-	LLPointer<LLVolume> mVolume;
-	LLPointer<LLVertexBuffer> mVertexBuffer;
+    BOOL        mNeedsUpdate;
+    U32         mTextureName;
+    F32         mCameraDistance;
+    F32         mCameraYaw;
+    F32         mCameraPitch;
+    F32         mCameraZoom;
+    LLVector3   mCameraOffset;
+    LLPointer<LLVolume> mVolume;
+    LLPointer<LLVertexBuffer> mVertexBuffer;
 };
 
 
 class LLImagePreviewAvatar final : public LLViewerDynamicTexture
 {
 protected:
-	virtual ~LLImagePreviewAvatar();
+    virtual ~LLImagePreviewAvatar();
 
 public:
-	LLImagePreviewAvatar(S32 width, S32 height);	
+    LLImagePreviewAvatar(S32 width, S32 height);
 
-	S8 getType() const override;
+    S8 getType() const override;
 
-	void setPreviewTarget(const std::string& joint_name, const std::string& mesh_name, LLImageRaw* imagep, F32 distance, BOOL male);
-	void setTexture(U32 name) { mTextureName = name; }
-	void clearPreviewTexture(const std::string& mesh_name);
+    void setPreviewTarget(const std::string& joint_name, const std::string& mesh_name, LLImageRaw* imagep, F32 distance, BOOL male);
+    void setTexture(U32 name) { mTextureName = name; }
+    void clearPreviewTexture(const std::string& mesh_name);
 
-	BOOL	render() override;
-	void	refresh();
-	void	rotate(F32 yaw_radians, F32 pitch_radians);
-	void	zoom(F32 zoom_amt);
-	void	pan(F32 right, F32 up);
-	virtual BOOL needsRender() override { return mNeedsUpdate; }
+    BOOL    render() override;
+    void    refresh();
+    void    rotate(F32 yaw_radians, F32 pitch_radians);
+    void    zoom(F32 zoom_amt);
+    void    pan(F32 right, F32 up);
+    virtual BOOL needsRender() override { return mNeedsUpdate; }
 
 protected:
-	BOOL		mNeedsUpdate;
-	LLJoint*	mTargetJoint;
-	LLViewerJointMesh*	mTargetMesh;
-	F32			mCameraDistance;
-	F32			mCameraYaw;
-	F32			mCameraPitch;
-	F32			mCameraZoom;
-	LLVector3	mCameraOffset;
-	LLPointer<LLVOAvatar> mDummyAvatar;
-	U32			mTextureName;
+    BOOL        mNeedsUpdate;
+    LLJoint*    mTargetJoint;
+    LLViewerJointMesh*  mTargetMesh;
+    F32         mCameraDistance;
+    F32         mCameraYaw;
+    F32         mCameraPitch;
+    F32         mCameraZoom;
+    LLVector3   mCameraOffset;
+    LLPointer<LLVOAvatar> mDummyAvatar;
+    U32         mTextureName;
 };
 
 class LLFloaterImagePreview final : public LLFloaterNameDesc
 {
 public:
-	LLFloaterImagePreview(const std::string& filename);
-	virtual ~LLFloaterImagePreview();
+    LLFloaterImagePreview(const std::string& filename);
+    virtual ~LLFloaterImagePreview();
 
-	BOOL postBuild() override;
+    BOOL postBuild() override;
 
     S32 getExpectedUploadCost() const override;
-	
-	BOOL handleMouseDown(S32 x, S32 y, MASK mask) override;
-	BOOL handleMouseUp(S32 x, S32 y, MASK mask) override;
-	BOOL handleHover(S32 x, S32 y, MASK mask) override;
-	BOOL handleScrollWheel(S32 x, S32 y, S32 clicks) override;
 
-	static void onMouseCaptureLostImagePreview(LLMouseHandler*);
+    BOOL handleMouseDown(S32 x, S32 y, MASK mask) override;
+    BOOL handleMouseUp(S32 x, S32 y, MASK mask) override;
+    BOOL handleHover(S32 x, S32 y, MASK mask) override;
+    BOOL handleScrollWheel(S32 x, S32 y, S32 clicks) override;
+
+    static void onMouseCaptureLostImagePreview(LLMouseHandler*);
 
-	void clearAllPreviewTextures();
+    void clearAllPreviewTextures();
 
 protected:
-	static void		onPreviewTypeCommit(LLUICtrl*,void*);
-	void			draw() override;
-	bool			loadImage(const std::string& filename);
-
-	LLPointer<LLImageRaw> mRawImagep;
-	LLPointer<LLImagePreviewAvatar> mAvatarPreview;
-	LLPointer<LLImagePreviewSculpted> mSculptedPreview;
-	S32				mLastMouseX;
-	S32				mLastMouseY;
-	LLRect			mPreviewRect;
-	LLRectf			mPreviewImageRect;
-	LLPointer<LLViewerTexture> mImagep ;
-	
-	std::string mImageLoadError;
+    static void     onPreviewTypeCommit(LLUICtrl*,void*);
+    void            draw() override;
+    bool            loadImage(const std::string& filename);
+
+    LLPointer<LLImageRaw> mRawImagep;
+    LLPointer<LLImagePreviewAvatar> mAvatarPreview;
+    LLPointer<LLImagePreviewSculpted> mSculptedPreview;
+    S32             mLastMouseX;
+    S32             mLastMouseY;
+    LLRect          mPreviewRect;
+    LLRectf         mPreviewImageRect;
+    LLPointer<LLViewerTexture> mImagep ;
+
+    std::string mImageLoadError;
 };
 
 #endif  // LL_LLFLOATERIMAGEPREVIEW_H
diff --git a/indra/newview/llfloaterimnearbychat.cpp b/indra/newview/llfloaterimnearbychat.cpp
index 1193af4d9b8abe595723a7ca67f561000820a766..d48f8636c9527aed0f1f7cd622602a9cc84e4118 100644
--- a/indra/newview/llfloaterimnearbychat.cpp
+++ b/indra/newview/llfloaterimnearbychat.cpp
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file LLFloaterIMNearbyChat.cpp
  * @brief LLFloaterIMNearbyChat class implementation
  *
@@ -6,21 +6,21 @@
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
  * Copyright (C) 2010-2016, Kitty Barnett
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -88,49 +88,49 @@ void send_chat_from_viewer(std::string utf8_out_text, EChatType type, S32 channe
 // [/RLVa:KB]
 
 struct LLChatTypeTrigger {
-	std::string name;
-	EChatType type;
+    std::string name;
+    EChatType type;
 };
 
 static LLChatTypeTrigger sChatTypeTriggers[] = {
-	{ "/whisper"	, CHAT_TYPE_WHISPER},
-	{ "/shout"	, CHAT_TYPE_SHOUT}
+    { "/whisper"    , CHAT_TYPE_WHISPER},
+    { "/shout"  , CHAT_TYPE_SHOUT}
 };
 
 bool cb_do_nothing()
 {
-	return false;
+    return false;
 }
 
 LLFloaterIMNearbyChat::LLFloaterIMNearbyChat(const LLSD& llsd)
-:	LLFloaterIMSessionTab(LLSD(LLUUID::null)),
-	//mOutputMonitor(NULL),
-	mSpeakerMgr(NULL),
+:   LLFloaterIMSessionTab(LLSD(LLUUID::null)),
+    //mOutputMonitor(NULL),
+    mSpeakerMgr(NULL),
 // [SL:KB] - Patch: Chat-NearbyToastWidth | Checked: 2010-11-10 (Catznip-2.4)
-	mReshapeSignal(NULL),
+    mReshapeSignal(NULL),
 // [/SL:KB]
-	mExpandedHeight(COLLAPSED_HEIGHT + EXPANDED_HEIGHT)
+    mExpandedHeight(COLLAPSED_HEIGHT + EXPANDED_HEIGHT)
 {
     mIsP2PChat = false;
-	mIsNearbyChat = true;
-	mSpeakerMgr = LLLocalSpeakerMgr::getInstance();
+    mIsNearbyChat = true;
+    mSpeakerMgr = LLLocalSpeakerMgr::getInstance();
 
-	// Required by LLFloaterIMSessionTab::mGearBtn
-	// But nearby floater has no 'per agent' menu items, 
-	mEnableCallbackRegistrar.add("Avatar.EnableGearItem", boost::bind(&cb_do_nothing));
-	mCommitCallbackRegistrar.add("Avatar.GearDoToSelected", boost::bind(&cb_do_nothing));
-	mEnableCallbackRegistrar.add("Avatar.CheckGearItem", boost::bind(&cb_do_nothing));
+    // Required by LLFloaterIMSessionTab::mGearBtn
+    // But nearby floater has no 'per agent' menu items,
+    mEnableCallbackRegistrar.add("Avatar.EnableGearItem", boost::bind(&cb_do_nothing));
+    mCommitCallbackRegistrar.add("Avatar.GearDoToSelected", boost::bind(&cb_do_nothing));
+    mEnableCallbackRegistrar.add("Avatar.CheckGearItem", boost::bind(&cb_do_nothing));
 
     mMinFloaterHeight = EXPANDED_MIN_HEIGHT;
 
-	mChatChannelConnection = gSavedSettings.getControl("AlchemyNearbyChatChannel")->getCommitSignal()->connect([this](LLControlVariable*, const LLSD& newval, const LLSD&) { changeChannelLabel(newval.asInteger()); });
+    mChatChannelConnection = gSavedSettings.getControl("AlchemyNearbyChatChannel")->getCommitSignal()->connect([this](LLControlVariable*, const LLSD& newval, const LLSD&) { changeChannelLabel(newval.asInteger()); });
 }
 
 // [SL:KB] - Patch: Chat-NearbyToastWidth | Checked: 2010-11-10 (Catznip-2.4)
 LLFloaterIMNearbyChat::~LLFloaterIMNearbyChat()
 {
-	delete mReshapeSignal;
-	mChatChannelConnection.disconnect();
+    delete mReshapeSignal;
+    mChatChannelConnection.disconnect();
 }
 // [/SL:KB]
 
@@ -145,796 +145,796 @@ LLFloaterIMNearbyChat* LLFloaterIMNearbyChat::buildFloater(const LLSD& key)
 BOOL LLFloaterIMNearbyChat::postBuild()
 {
 // [SL:KB] - Patch: Chat-Misc | Checked: Catznip-5.2
-	if (mIsNearbyChat)
-	{
-		mExtendedButtonPanel = getChild<LLPanel>("nearby_toolbar");
-		mExtendedButtonPanel->setVisible(true);
+    if (mIsNearbyChat)
+    {
+        mExtendedButtonPanel = getChild<LLPanel>("nearby_toolbar");
+        mExtendedButtonPanel->setVisible(true);
 
-		mExtendedButtonPanel->getChild<LLUICtrl>("chat_history_btn")->setCommitCallback(boost::bind(&LLFloaterReg::showInstance, "preview_conversation", LLUUID::null, true));
-	}
+        mExtendedButtonPanel->getChild<LLUICtrl>("chat_history_btn")->setCommitCallback(boost::bind(&LLFloaterReg::showInstance, "preview_conversation", LLUUID::null, true));
+    }
 // [/SL:KB]
 
     setIsSingleInstance(TRUE);
     BOOL result = LLFloaterIMSessionTab::postBuild();
 
-	mInputEditor->setAutoreplaceCallback(boost::bind(&LLAutoReplace::autoreplaceCallback, LLAutoReplace::getInstance(), _1, _2, _3, _4, _5));
-	mInputEditor->setCommitCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxCommit, this));
-	mInputEditor->setKeystrokeCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxKeystroke, this));
-	mInputEditor->setFocusLostCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxFocusLost, this));
-	mInputEditor->setFocusReceivedCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxFocusReceived, this));
-	changeChannelLabel(gSavedSettings.getS32("AlchemyNearbyChatChannel"));
-	mInputEditor->setFont(LLViewerChat::getChatFont());
+    mInputEditor->setAutoreplaceCallback(boost::bind(&LLAutoReplace::autoreplaceCallback, LLAutoReplace::getInstance(), _1, _2, _3, _4, _5));
+    mInputEditor->setCommitCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxCommit, this));
+    mInputEditor->setKeystrokeCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxKeystroke, this));
+    mInputEditor->setFocusLostCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxFocusLost, this));
+    mInputEditor->setFocusReceivedCallback(boost::bind(&LLFloaterIMNearbyChat::onChatBoxFocusReceived, this));
+    changeChannelLabel(gSavedSettings.getS32("AlchemyNearbyChatChannel"));
+    mInputEditor->setFont(LLViewerChat::getChatFont());
 
-	// Title must be defined BEFORE call to addConversationListItem() because
-	// it is used to show the item's name in the conversations list
-	setTitle(LLTrans::getString("NearbyChatTitle"));
+    // Title must be defined BEFORE call to addConversationListItem() because
+    // it is used to show the item's name in the conversations list
+    setTitle(LLTrans::getString("NearbyChatTitle"));
 
-	// obsolete, but may be needed for backward compatibility?
-	gSavedSettings.declareS32("nearbychat_showicons_and_names", 2, "NearByChat header settings", LLControlVariable::PERSIST_NONDFT);
+    // obsolete, but may be needed for backward compatibility?
+    gSavedSettings.declareS32("nearbychat_showicons_and_names", 2, "NearByChat header settings", LLControlVariable::PERSIST_NONDFT);
 
-	if (gSavedPerAccountSettings.getBOOL("LogShowHistory"))
-	{
-		loadHistory();
-	}
+    if (gSavedPerAccountSettings.getBOOL("LogShowHistory"))
+    {
+        loadHistory();
+    }
 
-	return result;
+    return result;
 }
 
 // virtual
 void LLFloaterIMNearbyChat::closeHostedFloater()
 {
-	LLFloaterEmojiPicker::saveState();
-
-	LLFloaterIMContainer* floater_container = LLFloaterIMContainer::getInstance();
-	if (getHost())
-	{
-		floater_container->closeFloater();
-	}
-	else // If detached from conversations window close anyway
-	{
-		closeFloater();
-		floater_container->selectNextConversationByID(LLUUID());
-	}
+    LLFloaterEmojiPicker::saveState();
+
+    LLFloaterIMContainer* floater_container = LLFloaterIMContainer::getInstance();
+    if (getHost())
+    {
+        floater_container->closeFloater();
+    }
+    else // If detached from conversations window close anyway
+    {
+        closeFloater();
+        floater_container->selectNextConversationByID(LLUUID());
+    }
 }
 
 void LLFloaterIMNearbyChat::closeFloater(bool app_quitting)
 {
-	LLFloaterEmojiPicker::saveState();
-
-	if (!getHost() || app_quitting)
-	{
-		LLFloaterIMSessionTab::closeFloater(app_quitting);
-	}
-
-	LLFloaterIMContainer* floater_container = LLFloaterIMContainer::findInstance();
-	if (floater_container && !app_quitting)
-	{
-		if (getHost())
-		{
-			LLFloaterIMContainer::getInstance()->closeFloater(app_quitting);
-		}
-		else // If detached from conversations window close anyway
-		{
-			floater_container->selectNextConversationByID(LLUUID());
-		}
-	}
+    LLFloaterEmojiPicker::saveState();
+
+    if (!getHost() || app_quitting)
+    {
+        LLFloaterIMSessionTab::closeFloater(app_quitting);
+    }
+
+    LLFloaterIMContainer* floater_container = LLFloaterIMContainer::findInstance();
+    if (floater_container && !app_quitting)
+    {
+        if (getHost())
+        {
+            LLFloaterIMContainer::getInstance()->closeFloater(app_quitting);
+        }
+        else // If detached from conversations window close anyway
+        {
+            floater_container->selectNextConversationByID(LLUUID());
+        }
+    }
 }
 
 // virtual
 void LLFloaterIMNearbyChat::refresh()
 {
-	displaySpeakingIndicator();
-	updateCallBtnState(LLVoiceClient::getInstance()->getUserPTTState());
-
-	// *HACK: Update transparency type depending on whether our children have focus.
-	// This is needed because this floater is chrome and thus cannot accept focus, so
-	// the transparency type setting code from LLFloater::setFocus() isn't reached.
-	if (getTransparencyType() != TT_DEFAULT)
-	{
-		setTransparencyType(hasFocus() ? TT_ACTIVE : TT_INACTIVE);
-	}
+    displaySpeakingIndicator();
+    updateCallBtnState(LLVoiceClient::getInstance()->getUserPTTState());
+
+    // *HACK: Update transparency type depending on whether our children have focus.
+    // This is needed because this floater is chrome and thus cannot accept focus, so
+    // the transparency type setting code from LLFloater::setFocus() isn't reached.
+    if (getTransparencyType() != TT_DEFAULT)
+    {
+        setTransparencyType(hasFocus() ? TT_ACTIVE : TT_INACTIVE);
+    }
 }
 
 void LLFloaterIMNearbyChat::reloadMessages(bool clean_messages/* = false*/)
 {
-	if (clean_messages)
-	{
-		mMessageArchive.clear();
-		if (gSavedPerAccountSettings.getBOOL("LogShowHistory"))
-		{
-			loadHistory();
-		}
-	}
-
-	mChatHistory->clear();
-
-	LLSD do_not_log;
-	do_not_log["do_not_log"] = true;
-	for(std::vector<LLChat>::iterator it = mMessageArchive.begin();it!=mMessageArchive.end();++it)
-	{
-		// Update the messages without re-writing them to a log file.
-		addMessage(*it,false, do_not_log);
-	}
-	mInputEditor->setFont(LLViewerChat::getChatFont());
+    if (clean_messages)
+    {
+        mMessageArchive.clear();
+        if (gSavedPerAccountSettings.getBOOL("LogShowHistory"))
+        {
+            loadHistory();
+        }
+    }
+
+    mChatHistory->clear();
+
+    LLSD do_not_log;
+    do_not_log["do_not_log"] = true;
+    for(std::vector<LLChat>::iterator it = mMessageArchive.begin();it!=mMessageArchive.end();++it)
+    {
+        // Update the messages without re-writing them to a log file.
+        addMessage(*it,false, do_not_log);
+    }
+    mInputEditor->setFont(LLViewerChat::getChatFont());
 }
 
 void LLFloaterIMNearbyChat::loadHistory()
 {
-	LLSD do_not_log;
-	do_not_log["do_not_log"] = true;
-
-	std::list<LLSD> history;
-	LLLogChat::loadChatHistory("chat", history);
-
-	std::list<LLSD>::const_iterator it = history.begin();
-	while (it != history.end())
-	{
-		const LLSD& msg = *it;
-
-		std::string from = msg[LL_IM_FROM];
-		LLUUID from_id;
-		if (msg[LL_IM_FROM_ID].isDefined())
-		{
-			from_id = msg[LL_IM_FROM_ID].asUUID();
-		}
-		else
- 		{
-			std::string legacy_name = gCacheName->buildLegacyName(from);
-			from_id = LLAvatarNameCache::getInstance()->findIdByName(legacy_name);
- 		}
-
-		LLChat chat;
-		chat.mFromName = from;
-		chat.mFromID = from_id;
-		chat.mText = msg[LL_IM_TEXT].asString();
-		chat.mTimeStr = msg[LL_IM_TIME].asString();
-		chat.mChatStyle = CHAT_STYLE_HISTORY;
-
-		chat.mSourceType = CHAT_SOURCE_AGENT;
-		if (from_id.isNull() && SYSTEM_FROM == from)
-		{
-			chat.mSourceType = CHAT_SOURCE_SYSTEM;
-
-		}
-		else if (from_id.isNull())
-		{
-			chat.mSourceType = isWordsName(from) ? CHAT_SOURCE_UNKNOWN : CHAT_SOURCE_OBJECT;
-		}
-
-		addMessage(chat, true, do_not_log);
-
-		it++;
-	}
+    LLSD do_not_log;
+    do_not_log["do_not_log"] = true;
+
+    std::list<LLSD> history;
+    LLLogChat::loadChatHistory("chat", history);
+
+    std::list<LLSD>::const_iterator it = history.begin();
+    while (it != history.end())
+    {
+        const LLSD& msg = *it;
+
+        std::string from = msg[LL_IM_FROM];
+        LLUUID from_id;
+        if (msg[LL_IM_FROM_ID].isDefined())
+        {
+            from_id = msg[LL_IM_FROM_ID].asUUID();
+        }
+        else
+        {
+            std::string legacy_name = gCacheName->buildLegacyName(from);
+            from_id = LLAvatarNameCache::getInstance()->findIdByName(legacy_name);
+        }
+
+        LLChat chat;
+        chat.mFromName = from;
+        chat.mFromID = from_id;
+        chat.mText = msg[LL_IM_TEXT].asString();
+        chat.mTimeStr = msg[LL_IM_TIME].asString();
+        chat.mChatStyle = CHAT_STYLE_HISTORY;
+
+        chat.mSourceType = CHAT_SOURCE_AGENT;
+        if (from_id.isNull() && SYSTEM_FROM == from)
+        {
+            chat.mSourceType = CHAT_SOURCE_SYSTEM;
+
+        }
+        else if (from_id.isNull())
+        {
+            chat.mSourceType = isWordsName(from) ? CHAT_SOURCE_UNKNOWN : CHAT_SOURCE_OBJECT;
+        }
+
+        addMessage(chat, true, do_not_log);
+
+        it++;
+    }
 }
 
 void LLFloaterIMNearbyChat::removeScreenChat()
 {
     LLNotificationsUI::LLScreenChannelBase* chat_channel = LLNotificationsUI::LLChannelManager::getInstance()->findChannelByID(
         LLNotificationsUI::NEARBY_CHAT_CHANNEL_UUID);
-	if(chat_channel)
-	{
-		chat_channel->removeToastsFromChannel();
-	}
+    if(chat_channel)
+    {
+        chat_channel->removeToastsFromChannel();
+    }
 }
 
 
 void LLFloaterIMNearbyChat::setVisible(BOOL visible)
 {
-	LLFloaterIMSessionTab::setVisible(visible);
+    LLFloaterIMSessionTab::setVisible(visible);
 
-	if(visible && isMessagePaneExpanded()) // <alchemy/>
-	{
-		removeScreenChat();
-	}
+    if(visible && isMessagePaneExpanded()) // <alchemy/>
+    {
+        removeScreenChat();
+    }
 }
 
 
 void LLFloaterIMNearbyChat::setVisibleAndFrontmost(BOOL take_focus, const LLSD& key)
 {
-	LLFloaterIMSessionTab::setVisibleAndFrontmost(take_focus, key);
+    LLFloaterIMSessionTab::setVisibleAndFrontmost(take_focus, key);
 
-	if(!isTornOff() && matchesKey(key)) // <alchemy/>
-	{
-		LLFloaterIMContainer::getInstance()->selectConversationPair(mSessionID, true, take_focus);
-	}
+    if(!isTornOff() && matchesKey(key)) // <alchemy/>
+    {
+        LLFloaterIMContainer::getInstance()->selectConversationPair(mSessionID, true, take_focus);
+    }
 }
 
 // virtual
 void LLFloaterIMNearbyChat::onTearOffClicked()
 {
-	LLFloaterIMSessionTab::onTearOffClicked();
+    LLFloaterIMSessionTab::onTearOffClicked();
 
-	// see CHUI-170: Save torn-off state of the nearby chat between sessions
-	bool in_the_multifloater(getHost());
-	gSavedPerAccountSettings.setBOOL("NearbyChatIsNotTornOff", in_the_multifloater);
+    // see CHUI-170: Save torn-off state of the nearby chat between sessions
+    bool in_the_multifloater(getHost());
+    gSavedPerAccountSettings.setBOOL("NearbyChatIsNotTornOff", in_the_multifloater);
 }
 
 
 // virtual
 void LLFloaterIMNearbyChat::onOpen(const LLSD& key)
 {
-	LLFloaterIMSessionTab::onOpen(key);
-	if(!isMessagePaneExpanded())
-	{
-		restoreFloater();
-		onCollapseToLine(this);
-	}
+    LLFloaterIMSessionTab::onOpen(key);
+    if(!isMessagePaneExpanded())
+    {
+        restoreFloater();
+        onCollapseToLine(this);
+    }
 }
 
 // virtual
 void LLFloaterIMNearbyChat::onClose(bool app_quitting)
 {
-	// Override LLFloaterIMSessionTab::onClose() so that Nearby Chat is not removed from the conversation floater
-	LLFloaterIMSessionTab::restoreFloater();
-	if (app_quitting)
-	{
-		// We are starting and closing floater in "expanded" state
-		// Update expanded (restored) rect and position for use in next session
-		forceReshape();
-		storeRectControl();
-	}
+    // Override LLFloaterIMSessionTab::onClose() so that Nearby Chat is not removed from the conversation floater
+    LLFloaterIMSessionTab::restoreFloater();
+    if (app_quitting)
+    {
+        // We are starting and closing floater in "expanded" state
+        // Update expanded (restored) rect and position for use in next session
+        forceReshape();
+        storeRectControl();
+    }
 }
 
 // virtual
 void LLFloaterIMNearbyChat::onClickCloseBtn(bool)
 
 {
-	if (!isTornOff())
-	{
-		return;
-	}
-	closeHostedFloater();
+    if (!isTornOff())
+    {
+        return;
+    }
+    closeHostedFloater();
 }
 
 void LLFloaterIMNearbyChat::onChatFontChange(LLFontGL* fontp)
 {
-	// Update things with the new font whohoo
-	if (mInputEditor)
-	{
-		mInputEditor->setFont(fontp);
-	}
+    // Update things with the new font whohoo
+    if (mInputEditor)
+    {
+        mInputEditor->setFont(fontp);
+    }
 }
 
 
 void LLFloaterIMNearbyChat::show()
 {
-		openFloater(getKey());
+        openFloater(getKey());
 }
 
 bool LLFloaterIMNearbyChat::isMessagePanelVisible() const
 {
-	bool isVisible = false;
-	LLFloaterIMContainer* im_box = LLFloaterIMContainer::getInstance();
-	// Is the IM floater container ever null?
-	llassert(im_box != NULL);
-	if (im_box != NULL)
-	{
-		isVisible =
-				isChatMultiTab() && !isTornOff() ?
-			im_box->isShown() && im_box->getSelectedSession().isNull() && !im_box->isMessagesPaneCollapsed() :
-			isShown() && isMessagePaneExpanded();
-	}
-
-	return isVisible;
+    bool isVisible = false;
+    LLFloaterIMContainer* im_box = LLFloaterIMContainer::getInstance();
+    // Is the IM floater container ever null?
+    llassert(im_box != NULL);
+    if (im_box != NULL)
+    {
+        isVisible =
+                isChatMultiTab() && !isTornOff() ?
+            im_box->isShown() && im_box->getSelectedSession().isNull() && !im_box->isMessagesPaneCollapsed() :
+            isShown() && isMessagePaneExpanded();
+    }
+
+    return isVisible;
 }
 
 bool LLFloaterIMNearbyChat::isChatVisible() const
 {
-	bool isVisible = false;
-	LLFloaterIMContainer* im_box = LLFloaterIMContainer::getInstance();
-	// Is the IM floater container ever null?
-	llassert(im_box != NULL);
-	if (im_box)
-	{
-		isVisible = !isTornOff() ?
-			im_box->isShown() && im_box->getSelectedSession().isNull() :
-			isShown();
-	}
-
-	return isVisible;
+    bool isVisible = false;
+    LLFloaterIMContainer* im_box = LLFloaterIMContainer::getInstance();
+    // Is the IM floater container ever null?
+    llassert(im_box != NULL);
+    if (im_box)
+    {
+        isVisible = !isTornOff() ?
+            im_box->isShown() && im_box->getSelectedSession().isNull() :
+            isShown();
+    }
+
+    return isVisible;
 }
 
 // [SL:KB] - Patch: Chat-NearbyToastWidth | Checked: 2010-11-10 (Catznip-2.4)
 // virtual
 void LLFloaterIMNearbyChat::reshape(S32 width, S32 height, BOOL called_from_parent)
 {
-	LLFloater::reshape(width, height, called_from_parent);
+    LLFloater::reshape(width, height, called_from_parent);
 
-	if (mReshapeSignal)
-	{
-		(*mReshapeSignal)(this, width, height);
-	}
+    if (mReshapeSignal)
+    {
+        (*mReshapeSignal)(this, width, height);
+    }
 }
 
 boost::signals2::connection LLFloaterIMNearbyChat::setReshapeCallback(const reshape_signal_t::slot_type& cb)
 {
-	if (!mReshapeSignal)
-	{
-		mReshapeSignal = new reshape_signal_t();
-	}
-	return mReshapeSignal->connect(cb); 
+    if (!mReshapeSignal)
+    {
+        mReshapeSignal = new reshape_signal_t();
+    }
+    return mReshapeSignal->connect(cb);
 }
 // [/SL:KB]
 
 void LLFloaterIMNearbyChat::showHistory()
 {
-	openFloater();
-	LLFloaterIMContainer::getInstance()->selectConversation(LLUUID(NULL));
-
-	if(!isMessagePaneExpanded())
-	{
-		restoreFloater();
-		setFocus(true);
-	}
-	else
-	{
-		LLFloaterIMContainer::getInstance()->setFocus(TRUE);
-	}
-	setResizeLimits(getMinWidth(), EXPANDED_MIN_HEIGHT);
+    openFloater();
+    LLFloaterIMContainer::getInstance()->selectConversation(LLUUID(NULL));
+
+    if(!isMessagePaneExpanded())
+    {
+        restoreFloater();
+        setFocus(true);
+    }
+    else
+    {
+        LLFloaterIMContainer::getInstance()->setFocus(TRUE);
+    }
+    setResizeLimits(getMinWidth(), EXPANDED_MIN_HEIGHT);
 }
 
 std::string LLFloaterIMNearbyChat::getCurrentChat()
 {
-	return mInputEditor ? mInputEditor->getText() : LLStringUtil::null;
+    return mInputEditor ? mInputEditor->getText() : LLStringUtil::null;
 }
 
 // virtual
 BOOL LLFloaterIMNearbyChat::handleKeyHere( KEY key, MASK mask )
 {
-	BOOL handled = FALSE;
-
-	if (KEY_RETURN == key && mask == (MASK_CONTROL|MASK_SHIFT))
-	{
-		// whisper
-		sendChat(CHAT_TYPE_WHISPER);
-		handled = TRUE;
-	}
-	else if( KEY_RETURN == key && mask == MASK_CONTROL)
-	{
-		// shout
-		sendChat(CHAT_TYPE_SHOUT);
-		handled = TRUE;
-	}
-	else if (KEY_RETURN == key && mask == MASK_ALT)
-	{
-		// shout
-		sendChat(CHAT_TYPE_OOC);
-		handled = TRUE;
-	}
-
-	if((mask == MASK_ALT) && isTornOff())
-	{
-		LLFloaterIMContainer* floater_container = LLFloaterIMContainer::getInstance();
-		if ((KEY_UP == key) || (KEY_LEFT == key))
-		{
-			floater_container->selectNextorPreviousConversation(false);
-			handled = TRUE;
-		}
-		if ((KEY_DOWN == key ) || (KEY_RIGHT == key))
-		{
-			floater_container->selectNextorPreviousConversation(true);
-			handled = TRUE;
-		}
-	}
-
-	return handled;
+    BOOL handled = FALSE;
+
+    if (KEY_RETURN == key && mask == (MASK_CONTROL|MASK_SHIFT))
+    {
+        // whisper
+        sendChat(CHAT_TYPE_WHISPER);
+        handled = TRUE;
+    }
+    else if( KEY_RETURN == key && mask == MASK_CONTROL)
+    {
+        // shout
+        sendChat(CHAT_TYPE_SHOUT);
+        handled = TRUE;
+    }
+    else if (KEY_RETURN == key && mask == MASK_ALT)
+    {
+        // shout
+        sendChat(CHAT_TYPE_OOC);
+        handled = TRUE;
+    }
+
+    if((mask == MASK_ALT) && isTornOff())
+    {
+        LLFloaterIMContainer* floater_container = LLFloaterIMContainer::getInstance();
+        if ((KEY_UP == key) || (KEY_LEFT == key))
+        {
+            floater_container->selectNextorPreviousConversation(false);
+            handled = TRUE;
+        }
+        if ((KEY_DOWN == key ) || (KEY_RIGHT == key))
+        {
+            floater_container->selectNextorPreviousConversation(true);
+            handled = TRUE;
+        }
+    }
+
+    return handled;
 }
 
 BOOL LLFloaterIMNearbyChat::matchChatTypeTrigger(const std::string& in_str, std::string* out_str)
 {
-	U32 in_len = in_str.length();
-	S32 cnt = sizeof(sChatTypeTriggers) / sizeof(*sChatTypeTriggers);
-	
-	bool string_was_found = false;
-
-	for (S32 n = 0; n < cnt && !string_was_found; n++)
-	{
-		if (in_len <= sChatTypeTriggers[n].name.length())
-		{
-			std::string trigger_trunc = sChatTypeTriggers[n].name;
-			LLStringUtil::truncate(trigger_trunc, in_len);
-
-			if (!LLStringUtil::compareInsensitive(in_str, trigger_trunc))
-			{
-				*out_str = sChatTypeTriggers[n].name;
-				string_was_found = true;
-			}
-		}
-	}
-
-	return string_was_found;
+    U32 in_len = in_str.length();
+    S32 cnt = sizeof(sChatTypeTriggers) / sizeof(*sChatTypeTriggers);
+
+    bool string_was_found = false;
+
+    for (S32 n = 0; n < cnt && !string_was_found; n++)
+    {
+        if (in_len <= sChatTypeTriggers[n].name.length())
+        {
+            std::string trigger_trunc = sChatTypeTriggers[n].name;
+            LLStringUtil::truncate(trigger_trunc, in_len);
+
+            if (!LLStringUtil::compareInsensitive(in_str, trigger_trunc))
+            {
+                *out_str = sChatTypeTriggers[n].name;
+                string_was_found = true;
+            }
+        }
+    }
+
+    return string_was_found;
 }
 
 void LLFloaterIMNearbyChat::onChatBoxKeystroke()
 {
-	LLFloaterIMContainer* im_box = LLFloaterIMContainer::findInstance();
-	if (im_box)
-	{
-		im_box->flashConversationItemWidget(mSessionID,false);
-	}
-
-	LLFirstUse::otherAvatarChatFirst(false);
-
-	LLWString raw_text = mInputEditor->getWText();
-
-	// Can't trim the end, because that will cause autocompletion
-	// to eat trailing spaces that might be part of a gesture.
-	LLWStringUtil::trimHead(raw_text);
-
-	S32 length = raw_text.length();
-
-	if ((length > 0)
-		&& (raw_text[0] != '/')		// forward slash is used for escape (eg. emote) sequences
-		&& (raw_text[0] != ':')	// colon is used in for MUD poses
-		)
-	{
-		gAgent.startTyping();
-	}
-	else
-	{
-		gAgent.stopTyping();
-	}
-
-	/* Doesn't work -- can't tell the difference between a backspace
-	   that killed the selection vs. backspace at the end of line.
-	if (length > 1 
-		&& text[0] == '/'
-		&& key == KEY_BACKSPACE)
-	{
-		// the selection will already be deleted, but we need to trim
-		// off the character before
-		std::string new_text = raw_text.substr(0, length-1);
-		mInputEditor->setText( new_text );
-		mInputEditor->setCursorToEnd();
-		length = length - 1;
-	}
-	*/
-
-	KEY key = gKeyboard->currentKey();
-
-
-	// Ignore "special" keys, like backspace, arrows, etc.
-	if (gSavedSettings.getBOOL("ChatAutocompleteGestures")
-		&& length > 1
-		&& raw_text[0] == '/'
-		&& key < KEY_SPECIAL)
-	{
-		// we're starting a gesture, attempt to autocomplete
-
-		std::string utf8_trigger = wstring_to_utf8str(raw_text);
-		std::string utf8_out_str(utf8_trigger);
-
-		if (LLGestureMgr::instance().matchPrefix(utf8_trigger, &utf8_out_str))
-		{
-			std::string rest_of_match = utf8_out_str.substr(utf8_trigger.size());
-			if (!rest_of_match.empty())
-			{
-				mInputEditor->setText(utf8_trigger + rest_of_match); // keep original capitalization for user-entered part
-				// Select to end of line, starting from the character
-				// after the last one the user typed.
-				mInputEditor->selectByCursorPosition(utf8_out_str.size()-rest_of_match.size(),utf8_out_str.size());
-			}
-
-		}
-		else if (matchChatTypeTrigger(utf8_trigger, &utf8_out_str))
-		{
-			std::string rest_of_match = utf8_out_str.substr(utf8_trigger.size());
-			mInputEditor->setText(utf8_trigger + rest_of_match + " "); // keep original capitalization for user-entered part
-			mInputEditor->endOfDoc();
-		}
-
-		//LL_INFOS() << "GESTUREDEBUG " << trigger 
-		//	<< " len " << length
-		//	<< " outlen " << out_str.getLength()
-		//	<< LL_ENDL;
-	}
+    LLFloaterIMContainer* im_box = LLFloaterIMContainer::findInstance();
+    if (im_box)
+    {
+        im_box->flashConversationItemWidget(mSessionID,false);
+    }
+
+    LLFirstUse::otherAvatarChatFirst(false);
+
+    LLWString raw_text = mInputEditor->getWText();
+
+    // Can't trim the end, because that will cause autocompletion
+    // to eat trailing spaces that might be part of a gesture.
+    LLWStringUtil::trimHead(raw_text);
+
+    S32 length = raw_text.length();
+
+    if ((length > 0)
+        && (raw_text[0] != '/')     // forward slash is used for escape (eg. emote) sequences
+        && (raw_text[0] != ':') // colon is used in for MUD poses
+        )
+    {
+        gAgent.startTyping();
+    }
+    else
+    {
+        gAgent.stopTyping();
+    }
+
+    /* Doesn't work -- can't tell the difference between a backspace
+       that killed the selection vs. backspace at the end of line.
+    if (length > 1
+        && text[0] == '/'
+        && key == KEY_BACKSPACE)
+    {
+        // the selection will already be deleted, but we need to trim
+        // off the character before
+        std::string new_text = raw_text.substr(0, length-1);
+        mInputEditor->setText( new_text );
+        mInputEditor->setCursorToEnd();
+        length = length - 1;
+    }
+    */
+
+    KEY key = gKeyboard->currentKey();
+
+
+    // Ignore "special" keys, like backspace, arrows, etc.
+    if (gSavedSettings.getBOOL("ChatAutocompleteGestures")
+        && length > 1
+        && raw_text[0] == '/'
+        && key < KEY_SPECIAL)
+    {
+        // we're starting a gesture, attempt to autocomplete
+
+        std::string utf8_trigger = wstring_to_utf8str(raw_text);
+        std::string utf8_out_str(utf8_trigger);
+
+        if (LLGestureMgr::instance().matchPrefix(utf8_trigger, &utf8_out_str))
+        {
+            std::string rest_of_match = utf8_out_str.substr(utf8_trigger.size());
+            if (!rest_of_match.empty())
+            {
+                mInputEditor->setText(utf8_trigger + rest_of_match); // keep original capitalization for user-entered part
+                // Select to end of line, starting from the character
+                // after the last one the user typed.
+                mInputEditor->selectByCursorPosition(utf8_out_str.size()-rest_of_match.size(),utf8_out_str.size());
+            }
+
+        }
+        else if (matchChatTypeTrigger(utf8_trigger, &utf8_out_str))
+        {
+            std::string rest_of_match = utf8_out_str.substr(utf8_trigger.size());
+            mInputEditor->setText(utf8_trigger + rest_of_match + " "); // keep original capitalization for user-entered part
+            mInputEditor->endOfDoc();
+        }
+
+        //LL_INFOS() << "GESTUREDEBUG " << trigger
+        //  << " len " << length
+        //  << " outlen " << out_str.getLength()
+        //  << LL_ENDL;
+    }
 }
 
 // static
 void LLFloaterIMNearbyChat::onChatBoxFocusLost()
 {
-	// stop typing animation
-	gAgent.stopTyping();
+    // stop typing animation
+    gAgent.stopTyping();
 }
 
 void LLFloaterIMNearbyChat::onChatBoxFocusReceived()
 {
-	mInputEditor->setEnabled(!gDisconnected);
+    mInputEditor->setEnabled(!gDisconnected);
 }
 
 EChatType LLFloaterIMNearbyChat::processChatTypeTriggers(EChatType type, std::string &str)
 {
-	U32 length = str.length();
-	S32 cnt = sizeof(sChatTypeTriggers) / sizeof(*sChatTypeTriggers);
-	
-	for (S32 n = 0; n < cnt; n++)
-	{
-		if (length >= sChatTypeTriggers[n].name.length())
-		{
-			std::string trigger = str.substr(0, sChatTypeTriggers[n].name.length());
-
-			if (!LLStringUtil::compareInsensitive(trigger, sChatTypeTriggers[n].name))
-			{
-				U32 trigger_length = sChatTypeTriggers[n].name.length();
-
-				// It's to remove space after trigger name
-				if (length > trigger_length && str[trigger_length] == ' ')
-					trigger_length++;
-
-				str = str.substr(trigger_length, length);
-
-				if (CHAT_TYPE_NORMAL == type)
-					return sChatTypeTriggers[n].type;
-				else
-					break;
-			}
-		}
-	}
-
-	return type;
+    U32 length = str.length();
+    S32 cnt = sizeof(sChatTypeTriggers) / sizeof(*sChatTypeTriggers);
+
+    for (S32 n = 0; n < cnt; n++)
+    {
+        if (length >= sChatTypeTriggers[n].name.length())
+        {
+            std::string trigger = str.substr(0, sChatTypeTriggers[n].name.length());
+
+            if (!LLStringUtil::compareInsensitive(trigger, sChatTypeTriggers[n].name))
+            {
+                U32 trigger_length = sChatTypeTriggers[n].name.length();
+
+                // It's to remove space after trigger name
+                if (length > trigger_length && str[trigger_length] == ' ')
+                    trigger_length++;
+
+                str = str.substr(trigger_length, length);
+
+                if (CHAT_TYPE_NORMAL == type)
+                    return sChatTypeTriggers[n].type;
+                else
+                    break;
+            }
+        }
+    }
+
+    return type;
 }
 
 void LLFloaterIMNearbyChat::sendChat( EChatType type )
 {
-	processChat(mInputEditor, type, [&](const auto& emojistr) { updateUsedEmojis(emojistr); });
-
-	// If the user wants to stop chatting on hitting return, lose focus
-	// and go out of chat mode.
-	if (gSavedSettings.getBOOL("CloseChatOnReturn"))
-	{
-		stopChat();
-		if (isTornOff())
-		{
-			closeHostedFloater();
-		}
-	}
+    processChat(mInputEditor, type, [&](const auto& emojistr) { updateUsedEmojis(emojistr); });
+
+    // If the user wants to stop chatting on hitting return, lose focus
+    // and go out of chat mode.
+    if (gSavedSettings.getBOOL("CloseChatOnReturn"))
+    {
+        stopChat();
+        if (isTornOff())
+        {
+            closeHostedFloater();
+        }
+    }
 }
 
 void LLFloaterIMNearbyChat::addMessage(const LLChat& chat,bool archive,const LLSD &args)
 {
-	appendMessage(chat, args);
-
-	if(archive)
-	{
-		mMessageArchive.push_back(chat);
-		if(mMessageArchive.size() > 200)
-		{
-			mMessageArchive.erase(mMessageArchive.begin());
-		}
-	}
-
-	// logging
-	if (!args["do_not_log"].asBoolean() && gSavedPerAccountSettings.getS32("KeepConversationLogTranscripts") > 1)
-	{
-		std::string from_name = chat.mFromName;
-
-		if (chat.mSourceType == CHAT_SOURCE_AGENT)
-		{
-			// if the chat is coming from an agent, log the complete name
-			LLAvatarName av_name;
-			LLAvatarNameCache::get(chat.mFromID, &av_name);
-
-			if (!av_name.isDisplayNameDefault())
-			{
-				from_name = av_name.getCompleteName();
-			}
-		}
-
-		LLLogChat::saveHistory("chat", from_name, chat.mFromID, chat.mText);
-	}
+    appendMessage(chat, args);
+
+    if(archive)
+    {
+        mMessageArchive.push_back(chat);
+        if(mMessageArchive.size() > 200)
+        {
+            mMessageArchive.erase(mMessageArchive.begin());
+        }
+    }
+
+    // logging
+    if (!args["do_not_log"].asBoolean() && gSavedPerAccountSettings.getS32("KeepConversationLogTranscripts") > 1)
+    {
+        std::string from_name = chat.mFromName;
+
+        if (chat.mSourceType == CHAT_SOURCE_AGENT)
+        {
+            // if the chat is coming from an agent, log the complete name
+            LLAvatarName av_name;
+            LLAvatarNameCache::get(chat.mFromID, &av_name);
+
+            if (!av_name.isDisplayNameDefault())
+            {
+                from_name = av_name.getCompleteName();
+            }
+        }
+
+        LLLogChat::saveHistory("chat", from_name, chat.mFromID, chat.mText);
+    }
 }
 
 
 void LLFloaterIMNearbyChat::onChatBoxCommit()
 {
-	sendChat(CHAT_TYPE_NORMAL);
+    sendChat(CHAT_TYPE_NORMAL);
 
-	gAgent.stopTyping();
+    gAgent.stopTyping();
 }
 
 void LLFloaterIMNearbyChat::displaySpeakingIndicator()
 {
-	LLSpeakerMgr::speaker_list_t speaker_list;
-	LLUUID id;
-
-	id.setNull();
-	mSpeakerMgr->update(FALSE);
-	mSpeakerMgr->getSpeakerList(&speaker_list, FALSE);
-
-	for (LLSpeakerMgr::speaker_list_t::iterator i = speaker_list.begin(); i != speaker_list.end(); ++i)
-	{
-		LLPointer<LLSpeaker> s = *i;
-		if (s->mSpeechVolume > 0 || s->mStatus == LLSpeaker::STATUS_SPEAKING)
-		{
-			id = s->mID;
-			break;
-		}
-	}
+    LLSpeakerMgr::speaker_list_t speaker_list;
+    LLUUID id;
+
+    id.setNull();
+    mSpeakerMgr->update(FALSE);
+    mSpeakerMgr->getSpeakerList(&speaker_list, FALSE);
+
+    for (LLSpeakerMgr::speaker_list_t::iterator i = speaker_list.begin(); i != speaker_list.end(); ++i)
+    {
+        LLPointer<LLSpeaker> s = *i;
+        if (s->mSpeechVolume > 0 || s->mStatus == LLSpeaker::STATUS_SPEAKING)
+        {
+            id = s->mID;
+            break;
+        }
+    }
 }
 
 void LLFloaterIMNearbyChat::changeChannelLabel(S32 channel)
 {
-	if (channel == 0)
-		mInputEditor->setLabel(LLTrans::getString("NearbyChatTitle"));
-	else
-	{
-		LLStringUtil::format_map_t args;
-		args["CHANNEL"] = llformat("%d", channel);
-		mInputEditor->setLabel(LLTrans::getString("NearbyChatTitleChannel", args));
-	}
+    if (channel == 0)
+        mInputEditor->setLabel(LLTrans::getString("NearbyChatTitle"));
+    else
+    {
+        LLStringUtil::format_map_t args;
+        args["CHANNEL"] = llformat("%d", channel);
+        mInputEditor->setLabel(LLTrans::getString("NearbyChatTitleChannel", args));
+    }
 }
 
 void LLFloaterIMNearbyChat::sendChatFromViewer(const std::string &utf8text, EChatType type, BOOL animate)
 {
-	sendChatFromViewer(utf8str_to_wstring(utf8text), type, animate);
+    sendChatFromViewer(utf8str_to_wstring(utf8text), type, animate);
 }
 
 void LLFloaterIMNearbyChat::sendChatFromViewer(const LLWString &wtext, EChatType type, BOOL animate)
 {
-	// Look for "/20 foo" channel chats.
-	S32 channel = gSavedSettings.getS32("AlchemyNearbyChatChannel");
-	LLWString out_text = stripChannelNumber(wtext, &channel);
-	std::string utf8_out_text = wstring_to_utf8str(out_text);
-	std::string utf8_text = wstring_to_utf8str(wtext);
-
-	utf8_text = utf8str_trim(utf8_text);
-	if (!utf8_text.empty())
-	{
-		utf8_text = utf8str_truncate(utf8_text, MAX_STRING - 1);
-	}
+    // Look for "/20 foo" channel chats.
+    S32 channel = gSavedSettings.getS32("AlchemyNearbyChatChannel");
+    LLWString out_text = stripChannelNumber(wtext, &channel);
+    std::string utf8_out_text = wstring_to_utf8str(out_text);
+    std::string utf8_text = wstring_to_utf8str(wtext);
+
+    utf8_text = utf8str_trim(utf8_text);
+    if (!utf8_text.empty())
+    {
+        utf8_text = utf8str_truncate(utf8_text, MAX_STRING - 1);
+    }
 
 // [RLVa:KB] - Checked: 2010-03-27 (RLVa-1.2.0b) | Modified: RLVa-1.2.0b
-	if ( (0 == channel) && (RlvActions::isRlvEnabled()) )
-	{
-		// Adjust the (public) chat "volume" on chat and gestures (also takes care of playing the proper animation)
-		type = RlvActions::checkChatVolume(type);
-		animate &= !RlvActions::hasBehaviour( (!RlvUtil::isEmote(utf8_text)) ? RLV_BHVR_REDIRCHAT : RLV_BHVR_REDIREMOTE );
-	}
+    if ( (0 == channel) && (RlvActions::isRlvEnabled()) )
+    {
+        // Adjust the (public) chat "volume" on chat and gestures (also takes care of playing the proper animation)
+        type = RlvActions::checkChatVolume(type);
+        animate &= !RlvActions::hasBehaviour( (!RlvUtil::isEmote(utf8_text)) ? RLV_BHVR_REDIRCHAT : RLV_BHVR_REDIREMOTE );
+    }
 // [/RLVa:KB]
 
-	// Don't animate for chats people can't hear (chat to scripts)
-	if (animate && (channel == 0))
-	{
-		if (type == CHAT_TYPE_WHISPER)
-		{
-			LL_DEBUGS() << "You whisper " << utf8_text << LL_ENDL;
-			gAgent.sendAnimationRequest(ANIM_AGENT_WHISPER, ANIM_REQUEST_START);
-		}
-		else if (type == CHAT_TYPE_NORMAL)
-		{
-			LL_DEBUGS() << "You say " << utf8_text << LL_ENDL;
-			gAgent.sendAnimationRequest(ANIM_AGENT_TALK, ANIM_REQUEST_START);
-		}
-		else if (type == CHAT_TYPE_SHOUT)
-		{
-			LL_DEBUGS() << "You shout " << utf8_text << LL_ENDL;
-			gAgent.sendAnimationRequest(ANIM_AGENT_SHOUT, ANIM_REQUEST_START);
-		}
-		else
-		{
-			LL_INFOS() << "send_chat_from_viewer() - invalid volume" << LL_ENDL;
-			return;
-		}
-	}
-	else
-	{
-		if (type != CHAT_TYPE_START && type != CHAT_TYPE_STOP)
-		{
-			LL_DEBUGS() << "Channel chat: " << utf8_text << LL_ENDL;
-		}
-	}
-
-	send_chat_from_viewer(utf8_out_text, type, channel);
+    // Don't animate for chats people can't hear (chat to scripts)
+    if (animate && (channel == 0))
+    {
+        if (type == CHAT_TYPE_WHISPER)
+        {
+            LL_DEBUGS() << "You whisper " << utf8_text << LL_ENDL;
+            gAgent.sendAnimationRequest(ANIM_AGENT_WHISPER, ANIM_REQUEST_START);
+        }
+        else if (type == CHAT_TYPE_NORMAL)
+        {
+            LL_DEBUGS() << "You say " << utf8_text << LL_ENDL;
+            gAgent.sendAnimationRequest(ANIM_AGENT_TALK, ANIM_REQUEST_START);
+        }
+        else if (type == CHAT_TYPE_SHOUT)
+        {
+            LL_DEBUGS() << "You shout " << utf8_text << LL_ENDL;
+            gAgent.sendAnimationRequest(ANIM_AGENT_SHOUT, ANIM_REQUEST_START);
+        }
+        else
+        {
+            LL_INFOS() << "send_chat_from_viewer() - invalid volume" << LL_ENDL;
+            return;
+        }
+    }
+    else
+    {
+        if (type != CHAT_TYPE_START && type != CHAT_TYPE_STOP)
+        {
+            LL_DEBUGS() << "Channel chat: " << utf8_text << LL_ENDL;
+        }
+    }
+
+    send_chat_from_viewer(utf8_out_text, type, channel);
 }
 
-// static 
+// static
 bool LLFloaterIMNearbyChat::isWordsName(const std::string& name)
 {
-	// checking to see if it's display name plus username in parentheses
-	std::string::size_type open_paren = name.find(" (", 0);
-	std::string::size_type close_paren = name.find(')', 0);
-
-	if (open_paren != std::string::npos &&
-		close_paren == name.length()-1)
-	{
-		return true;
-	}
-	else
-	{
-		//checking for a single space
-		std::string::size_type pos = name.find(' ', 0);
-		return std::string::npos != pos && name.rfind(' ', name.length()) == pos && 0 != pos && name.length()-1 != pos;
-	}
+    // checking to see if it's display name plus username in parentheses
+    std::string::size_type open_paren = name.find(" (", 0);
+    std::string::size_type close_paren = name.find(')', 0);
+
+    if (open_paren != std::string::npos &&
+        close_paren == name.length()-1)
+    {
+        return true;
+    }
+    else
+    {
+        //checking for a single space
+        std::string::size_type pos = name.find(' ', 0);
+        return std::string::npos != pos && name.rfind(' ', name.length()) == pos && 0 != pos && name.length()-1 != pos;
+    }
 }
 
-// static 
+// static
 void LLFloaterIMNearbyChat::startChat(const char* line)
 {
-	LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
-	if (nearby_chat)
-	{
-		if(!nearby_chat->isTornOff())
-		{
-			LLFloaterIMContainer::getInstance()->selectConversation(LLUUID(NULL));
-		}
-		if(nearby_chat->isMinimized())
-		{
-			nearby_chat->setMinimized(false);
-		}
-		nearby_chat->show();
-		nearby_chat->setFocus(TRUE);
-
-		if (line)
-		{
-			std::string line_string(line);
-			nearby_chat->mInputEditor->setText(line_string);
-		}
-
-		nearby_chat->mInputEditor->endOfDoc();
-	}
+    LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
+    if (nearby_chat)
+    {
+        if(!nearby_chat->isTornOff())
+        {
+            LLFloaterIMContainer::getInstance()->selectConversation(LLUUID(NULL));
+        }
+        if(nearby_chat->isMinimized())
+        {
+            nearby_chat->setMinimized(false);
+        }
+        nearby_chat->show();
+        nearby_chat->setFocus(TRUE);
+
+        if (line)
+        {
+            std::string line_string(line);
+            nearby_chat->mInputEditor->setText(line_string);
+        }
+
+        nearby_chat->mInputEditor->endOfDoc();
+    }
 }
 
 // Exit "chat mode" and do the appropriate focus changes
 // static
 void LLFloaterIMNearbyChat::stopChat()
 {
-	LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
-	if (nearby_chat)
-	{
-		nearby_chat->mInputEditor->setFocus(FALSE);
-	    gAgent.stopTyping();
-	}
+    LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
+    if (nearby_chat)
+    {
+        nearby_chat->mInputEditor->setFocus(FALSE);
+        gAgent.stopTyping();
+    }
 }
 
 // If input of the form "/20foo" or "/20 foo", returns "foo" and channel 20.
 // Otherwise returns input and channel 0.
 LLWString LLFloaterIMNearbyChat::stripChannelNumber(const LLWString &mesg, S32* channel)
 {
-	if (mesg[0] == '/'
-		&& mesg[1] == '/')
-	{
-		// This is a "repeat channel send"
-		*channel = sLastSpecialChatChannel;
-		return mesg.substr(2, mesg.length() - 2);
-	}
-	else if (mesg[0] == '/'
-			 && mesg[1]
-			 && (LLStringOps::isDigit(mesg[1])
-				 || (mesg[1] == '-' && mesg[2] && LLStringOps::isDigit(mesg[2]))))
-	{
-		// This a special "/20" speak on a channel
-		S32 pos = 0;
-
-		// Copy the channel number into a string
-		LLWString channel_string;
-		llwchar c;
-		do
-		{
-			c = mesg[pos+1];
-			channel_string.push_back(c);
-			pos++;
-		}
-		while(c && pos < 64 && (LLStringOps::isDigit(c) || (pos==1 && c =='-')));
-		
-		// Move the pointer forward to the first non-whitespace char
-		// Check isspace before looping, so we can handle "/33foo"
-		// as well as "/33 foo"
-		while(c && iswspace(c))
-		{
-			c = mesg[pos+1];
-			pos++;
-		}
-		
-		sLastSpecialChatChannel = strtol(wstring_to_utf8str(channel_string).c_str(), NULL, 10);
-		*channel = sLastSpecialChatChannel;
-		return mesg.substr(pos, mesg.length() - pos);
-	}
-	else
-	{
-		// This is normal chat.
-		*channel = 0;
-		return mesg;
-	}
+    if (mesg[0] == '/'
+        && mesg[1] == '/')
+    {
+        // This is a "repeat channel send"
+        *channel = sLastSpecialChatChannel;
+        return mesg.substr(2, mesg.length() - 2);
+    }
+    else if (mesg[0] == '/'
+             && mesg[1]
+             && (LLStringOps::isDigit(mesg[1])
+                 || (mesg[1] == '-' && mesg[2] && LLStringOps::isDigit(mesg[2]))))
+    {
+        // This a special "/20" speak on a channel
+        S32 pos = 0;
+
+        // Copy the channel number into a string
+        LLWString channel_string;
+        llwchar c;
+        do
+        {
+            c = mesg[pos+1];
+            channel_string.push_back(c);
+            pos++;
+        }
+        while(c && pos < 64 && (LLStringOps::isDigit(c) || (pos==1 && c =='-')));
+
+        // Move the pointer forward to the first non-whitespace char
+        // Check isspace before looping, so we can handle "/33foo"
+        // as well as "/33 foo"
+        while(c && iswspace(c))
+        {
+            c = mesg[pos+1];
+            pos++;
+        }
+
+        sLastSpecialChatChannel = strtol(wstring_to_utf8str(channel_string).c_str(), NULL, 10);
+        *channel = sLastSpecialChatChannel;
+        return mesg.substr(pos, mesg.length() - pos);
+    }
+    else
+    {
+        // This is normal chat.
+        *channel = 0;
+        return mesg;
+    }
 }
 
 //void send_chat_from_viewer(const std::string& utf8_out_text, EChatType type, S32 channel)
@@ -943,44 +943,44 @@ void send_chat_from_viewer_impl(std::string utf8_out_text, EChatType type, S32 c
 // [/RLVa:KB]
 {
 // [RLVa:KB] - Checked: 2010-02-27 (RLVa-1.2.0b) | Modified: RLVa-1.2.0a
-	// Only process chat messages (ie not CHAT_TYPE_START, CHAT_TYPE_STOP, etc)
-	if ( (RlvActions::isRlvEnabled()) && ( (CHAT_TYPE_WHISPER == type) || (CHAT_TYPE_NORMAL == type) || (CHAT_TYPE_SHOUT == type) ) )
-	{
-		if (0 == channel)
-		{
-			// Clamp the volume of the chat if needed
-			type = RlvActions::checkChatVolume(type);
-
-			// Redirect chat if needed
-			if ( ( (gRlvHandler.hasBehaviour(RLV_BHVR_REDIRCHAT) || (gRlvHandler.hasBehaviour(RLV_BHVR_REDIREMOTE)) ) && 
-				 (gRlvHandler.redirectChatOrEmote(utf8_out_text)) ) )
-			{
-				return;
-			}
-
-			// Filter public chat if sendchat restricted
-			if (gRlvHandler.hasBehaviour(RLV_BHVR_SENDCHAT))
-				gRlvHandler.filterChat(utf8_out_text, true);
-		}
-		else
-		{
-			// Don't allow chat on a non-public channel if sendchannel restricted (unless the channel is an exception)
-			if (!RlvActions::canSendChannel(channel))
-				return;
-
-			// Don't allow chat on debug channel if @sendchat, @redirchat or @rediremote restricted (shows as public chat on viewers)
-			if (CHAT_CHANNEL_DEBUG == channel)
-			{
-				bool fIsEmote = RlvUtil::isEmote(utf8_out_text);
-				if ( (gRlvHandler.hasBehaviour(RLV_BHVR_SENDCHAT)) || 
-					 ((!fIsEmote) && (gRlvHandler.hasBehaviour(RLV_BHVR_REDIRCHAT))) || 
-					 ((fIsEmote) && (gRlvHandler.hasBehaviour(RLV_BHVR_REDIREMOTE))) )
-				{
-					return;
-				}
-			}
-		}
-	}
+    // Only process chat messages (ie not CHAT_TYPE_START, CHAT_TYPE_STOP, etc)
+    if ( (RlvActions::isRlvEnabled()) && ( (CHAT_TYPE_WHISPER == type) || (CHAT_TYPE_NORMAL == type) || (CHAT_TYPE_SHOUT == type) ) )
+    {
+        if (0 == channel)
+        {
+            // Clamp the volume of the chat if needed
+            type = RlvActions::checkChatVolume(type);
+
+            // Redirect chat if needed
+            if ( ( (gRlvHandler.hasBehaviour(RLV_BHVR_REDIRCHAT) || (gRlvHandler.hasBehaviour(RLV_BHVR_REDIREMOTE)) ) &&
+                 (gRlvHandler.redirectChatOrEmote(utf8_out_text)) ) )
+            {
+                return;
+            }
+
+            // Filter public chat if sendchat restricted
+            if (gRlvHandler.hasBehaviour(RLV_BHVR_SENDCHAT))
+                gRlvHandler.filterChat(utf8_out_text, true);
+        }
+        else
+        {
+            // Don't allow chat on a non-public channel if sendchannel restricted (unless the channel is an exception)
+            if (!RlvActions::canSendChannel(channel))
+                return;
+
+            // Don't allow chat on debug channel if @sendchat, @redirchat or @rediremote restricted (shows as public chat on viewers)
+            if (CHAT_CHANNEL_DEBUG == channel)
+            {
+                bool fIsEmote = RlvUtil::isEmote(utf8_out_text);
+                if ( (gRlvHandler.hasBehaviour(RLV_BHVR_SENDCHAT)) ||
+                     ((!fIsEmote) && (gRlvHandler.hasBehaviour(RLV_BHVR_REDIRCHAT))) ||
+                     ((fIsEmote) && (gRlvHandler.hasBehaviour(RLV_BHVR_REDIREMOTE))) )
+                {
+                    return;
+                }
+            }
+        }
+    }
 // [/RLVa:KB]
 
     LLMessageSystem* msg = gMessageSystem;
@@ -1018,58 +1018,58 @@ void send_chat_from_viewer_impl(std::string utf8_out_text, EChatType type, S32 c
 // [SL:KB]
 void send_chat_from_viewer(std::string utf8_out_text, EChatType type, S32 channel)
 {
-	size_t maxChatLen = (channel >= 0) ? DB_CHAT_MSG_STR_LEN : DB_CHAT_MSG_STR_LEN / 2;
-	if (utf8_out_text.length() <= maxChatLen)
-	{
-		send_chat_from_viewer_impl(utf8_out_text, type, channel);
-	}
-	else
-	{
-		std::list<std::string> lines;
-		utf8str_split(lines, utf8_out_text, maxChatLen, ' ');
-		for (const std::string& strLine : lines)
-			send_chat_from_viewer_impl(strLine, type, channel);
-	}
+    size_t maxChatLen = (channel >= 0) ? DB_CHAT_MSG_STR_LEN : DB_CHAT_MSG_STR_LEN / 2;
+    if (utf8_out_text.length() <= maxChatLen)
+    {
+        send_chat_from_viewer_impl(utf8_out_text, type, channel);
+    }
+    else
+    {
+        std::list<std::string> lines;
+        utf8str_split(lines, utf8_out_text, maxChatLen, ' ');
+        for (const std::string& strLine : lines)
+            send_chat_from_viewer_impl(strLine, type, channel);
+    }
 }
 // [/SL:KB]
 
 class LLChatCommandHandler : public LLCommandHandler
 {
 public:
-	// not allowed from outside the app
-	LLChatCommandHandler() : LLCommandHandler("chat", UNTRUSTED_THROTTLE) { }
+    // not allowed from outside the app
+    LLChatCommandHandler() : LLCommandHandler("chat", UNTRUSTED_THROTTLE) { }
 
     // Your code here
-	bool handle(const LLSD& tokens,
+    bool handle(const LLSD& tokens,
                 const LLSD& query_map,
                 const std::string& grid,
                 LLMediaCtrl* web)
-	{
-		bool retval = false;
-		// Need at least 2 tokens to have a valid message.
-		if (tokens.size() < 2)
-		{
-			retval = false;
-		}
-		else
-		{
-		S32 channel = tokens[0].asInteger();
-			// VWR-19499 Restrict function to chat channels greater than 0.
-			if ((channel > 0) && (channel < CHAT_CHANNEL_DEBUG))
-			{
-				retval = true;
-		// Send unescaped message, see EXT-6353.
-		std::string unescaped_mesg (LLURI::unescape(tokens[1].asString()));
-		send_chat_from_viewer(unescaped_mesg, CHAT_TYPE_NORMAL, channel);
-			}
-			else
-			{
-				retval = false;
-				// Tell us this is an unsupported SLurl.
-			}
-		}
-		return retval;
-	}
+    {
+        bool retval = false;
+        // Need at least 2 tokens to have a valid message.
+        if (tokens.size() < 2)
+        {
+            retval = false;
+        }
+        else
+        {
+        S32 channel = tokens[0].asInteger();
+            // VWR-19499 Restrict function to chat channels greater than 0.
+            if ((channel > 0) && (channel < CHAT_CHANNEL_DEBUG))
+            {
+                retval = true;
+        // Send unescaped message, see EXT-6353.
+        std::string unescaped_mesg (LLURI::unescape(tokens[1].asString()));
+        send_chat_from_viewer(unescaped_mesg, CHAT_TYPE_NORMAL, channel);
+            }
+            else
+            {
+                retval = false;
+                // Tell us this is an unsupported SLurl.
+            }
+        }
+        return retval;
+    }
 };
 
 // Creating the object registers with the dispatcher.
diff --git a/indra/newview/llfloaternamedesc.h b/indra/newview/llfloaternamedesc.h
index d943b3927e067eb0fa4537042a1afae28d88b2ef..85d29b07df185a731f24560e8feaf1d0b394cf9d 100644
--- a/indra/newview/llfloaternamedesc.h
+++ b/indra/newview/llfloaternamedesc.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llfloaternamedesc.h
  * @brief LLFloaterNameDesc class definition
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -39,46 +39,46 @@ class LLRadioGroup;
 class LLFloaterNameDesc : public LLFloater
 {
 public:
-	LLFloaterNameDesc(const LLSD& filename);
-	virtual ~LLFloaterNameDesc();
-	virtual BOOL postBuild();
-	
-	void		onBtnOK();
-	void		onBtnCancel();
-	void		doCommit();
+    LLFloaterNameDesc(const LLSD& filename);
+    virtual ~LLFloaterNameDesc();
+    virtual BOOL postBuild();
+
+    void        onBtnOK();
+    void        onBtnCancel();
+    void        doCommit();
+
+    virtual S32 getExpectedUploadCost() const;
 
-	virtual S32 getExpectedUploadCost() const;
-	
 protected:
-	virtual void		onCommit();
+    virtual void        onCommit();
 
 protected:
-	BOOL        mIsAudio;
-	bool		mIsText;
+    BOOL        mIsAudio;
+    bool        mIsText;
 
-	std::string		mFilenameAndPath;
-	std::string		mFilename;
+    std::string     mFilenameAndPath;
+    std::string     mFilename;
 };
 
 class LLFloaterSoundPreview final : public LLFloaterNameDesc
 {
 public:
-	LLFloaterSoundPreview(const LLSD& filename );
-	virtual BOOL postBuild();
+    LLFloaterSoundPreview(const LLSD& filename );
+    virtual BOOL postBuild();
 };
 
 class LLFloaterAnimPreview final : public LLFloaterNameDesc
 {
 public:
-	LLFloaterAnimPreview(const LLSD& filename );
-	virtual BOOL postBuild();
+    LLFloaterAnimPreview(const LLSD& filename );
+    virtual BOOL postBuild();
 };
 
 class LLFloaterScriptPreview final : public LLFloaterNameDesc
 {
 public:
-	LLFloaterScriptPreview(const LLSD& filename );
-	virtual BOOL postBuild();
+    LLFloaterScriptPreview(const LLSD& filename );
+    virtual BOOL postBuild();
 };
 
 #endif  // LL_LLFLOATERNAMEDESC_H
diff --git a/indra/newview/llfloaterpreference.cpp b/indra/newview/llfloaterpreference.cpp
index 6edf42cbf48789119b1a0bde1915c684bc4c882d..8915a159f50b93b253a2364e497e307902fc0f8c 100644
--- a/indra/newview/llfloaterpreference.cpp
+++ b/indra/newview/llfloaterpreference.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llfloaterpreference.cpp
  * @brief Global preferences with and without persistence.
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -175,23 +175,23 @@ const std::string DEFAULT_SKIN = "alchemy";
 
 typedef enum e_skin_type
 {
-	SYSTEM_SKIN,
-	USER_SKIN
+    SYSTEM_SKIN,
+    USER_SKIN
 } ESkinType;
 
 typedef struct skin_t
 {
-	std::string mName = "Unknown";
-	std::string mAuthor = "Unknown";
-	std::string mUrl = "Unknown";
-	LLDate mDate = LLDate(0.0);
-	std::string mCompatVer = "Unknown";
-	std::string mNotes = LLStringUtil::null;
-	ESkinType mType = USER_SKIN;
-	
+    std::string mName = "Unknown";
+    std::string mAuthor = "Unknown";
+    std::string mUrl = "Unknown";
+    LLDate mDate = LLDate(0.0);
+    std::string mCompatVer = "Unknown";
+    std::string mNotes = LLStringUtil::null;
+    ESkinType mType = USER_SKIN;
+
 } skin_t;
 
-// global functions 
+// global functions
 
 // helper functions for getting/freeing the web browser media
 // if creating/destroying these is too slow, we'll need to create
@@ -207,60 +207,60 @@ void fractionFromDecimal(F32 decimal_val, S32& numerator, S32& denominator);
 
 bool callback_clear_cache(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if ( option == 0 ) // YES
-	{
-		// flag client texture cache for clearing next time the client runs
-		gSavedSettings.setBOOL("PurgeCacheOnNextStartup", TRUE);
-		LLNotificationsUtil::add("CacheWillClear");
-	}
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if ( option == 0 ) // YES
+    {
+        // flag client texture cache for clearing next time the client runs
+        gSavedSettings.setBOOL("PurgeCacheOnNextStartup", TRUE);
+        LLNotificationsUtil::add("CacheWillClear");
+    }
 
-	return false;
+    return false;
 }
 
 bool callback_clear_browser_cache(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if ( option == 0 ) // YES
-	{
-		// clean web
-		LLViewerMedia::getInstance()->clearAllCaches();
-		LLViewerMedia::getInstance()->clearAllCookies();
-		
-		// clean nav bar history
-		LLNavigationBar::getInstance()->clearHistoryCache();
-		
-		// flag client texture cache for clearing next time the client runs
-		gSavedSettings.setBOOL("PurgeWebCacheOnNextStartup", TRUE);
-		LLNotificationsUtil::add("WebCacheWillClear");
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if ( option == 0 ) // YES
+    {
+        // clean web
+        LLViewerMedia::getInstance()->clearAllCaches();
+        LLViewerMedia::getInstance()->clearAllCookies();
+
+        // clean nav bar history
+        LLNavigationBar::getInstance()->clearHistoryCache();
 
-		LLSearchHistory::getInstance()->clearHistory();
-		LLSearchHistory::getInstance()->save();
-		LLSearchComboBox* search_ctrl = LLNavigationBar::getInstance()->getChild<LLSearchComboBox>("search_combo_box");
-		search_ctrl->clearHistory();
+        // flag client texture cache for clearing next time the client runs
+        gSavedSettings.setBOOL("PurgeWebCacheOnNextStartup", TRUE);
+        LLNotificationsUtil::add("WebCacheWillClear");
+
+        LLSearchHistory::getInstance()->clearHistory();
+        LLSearchHistory::getInstance()->save();
+        LLSearchComboBox* search_ctrl = LLNavigationBar::getInstance()->getChild<LLSearchComboBox>("search_combo_box");
+        search_ctrl->clearHistory();
+
+        LLTeleportHistoryStorage::getInstance()->purgeItems();
+        LLTeleportHistoryStorage::getInstance()->save();
+    }
 
-		LLTeleportHistoryStorage::getInstance()->purgeItems();
-		LLTeleportHistoryStorage::getInstance()->save();
-	}
-	
-	return false;
+    return false;
 }
 
 
 
 void fractionFromDecimal(F32 decimal_val, S32& numerator, S32& denominator)
 {
-	numerator = 0;
-	denominator = 0;
-	for (F32 test_denominator = 1.f; test_denominator < 30.f; test_denominator += 1.f)
-	{
-		if (fmodf((decimal_val * test_denominator) + 0.01f, 1.f) < 0.02f)
-		{
-			numerator = ll_round(decimal_val * test_denominator);
-			denominator = ll_round(test_denominator);
-			break;
-		}
-	}
+    numerator = 0;
+    denominator = 0;
+    for (F32 test_denominator = 1.f; test_denominator < 30.f; test_denominator += 1.f)
+    {
+        if (fmodf((decimal_val * test_denominator) + 0.01f, 1.f) < 0.02f)
+        {
+            numerator = ll_round(decimal_val * test_denominator);
+            denominator = ll_round(test_denominator);
+            break;
+        }
+    }
 }
 
 // handle secondlife:///app/worldmap/{NAME}/{COORDS} URLs
@@ -304,104 +304,104 @@ LLKeybindingHandler gKeybindHandler;
 std::string LLFloaterPreference::sSkin = "";
 
 LLFloaterPreference::LLFloaterPreference(const LLSD& key)
-	: LLFloater(key),
-	mGotPersonalInfo(false),
-	mOriginalIMViaEmail(false),
-	mLanguageChanged(false),
-	mAvatarDataInitialized(false),
-	mSearchDataDirty(true)
-{
-	LLConversationLog::instance().addObserver(this);
-
-	//Build Floater is now Called from 	LLFloaterReg::add("preferences", "floater_preferences.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterPreference>);
-	
-	static bool registered_dialog = false;
-	if (!registered_dialog)
-	{
-		LLFloaterReg::add("keybind_dialog", "floater_select_key.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLSetKeyBindDialog>);
-		registered_dialog = true;
-	}
-	
-	mCommitCallbackRegistrar.add("Pref.Cancel",				boost::bind(&LLFloaterPreference::onBtnCancel, this, _2));
-	mCommitCallbackRegistrar.add("Pref.OK",					boost::bind(&LLFloaterPreference::onBtnOK, this, _2));
-	
-	mCommitCallbackRegistrar.add("Pref.ClearCache",				boost::bind(&LLFloaterPreference::onClickClearCache, this));
-	mCommitCallbackRegistrar.add("Pref.WebClearCache",			boost::bind(&LLFloaterPreference::onClickBrowserClearCache, this));
-	mCommitCallbackRegistrar.add("Pref.SetCache",				boost::bind(&LLFloaterPreference::onClickSetCache, this));
-	mCommitCallbackRegistrar.add("Pref.ResetCache",				boost::bind(&LLFloaterPreference::onClickResetCache, this));
-	mCommitCallbackRegistrar.add("Pref.SetSounds",				boost::bind(&LLFloaterPreference::onClickSetSounds, this));
-	mCommitCallbackRegistrar.add("Pref.ClickEnablePopup",		boost::bind(&LLFloaterPreference::onClickEnablePopup, this));
-	mCommitCallbackRegistrar.add("Pref.ClickDisablePopup",		boost::bind(&LLFloaterPreference::onClickDisablePopup, this));	
-	mCommitCallbackRegistrar.add("Pref.LogPath",				boost::bind(&LLFloaterPreference::onClickLogPath, this));
-	mCommitCallbackRegistrar.add("Pref.RenderExceptions",       boost::bind(&LLFloaterPreference::onClickRenderExceptions, this));
-	mCommitCallbackRegistrar.add("Pref.AutoAdjustments",         boost::bind(&LLFloaterPreference::onClickAutoAdjustments, this));
-	mCommitCallbackRegistrar.add("Pref.HardwareDefaults",		boost::bind(&LLFloaterPreference::setHardwareDefaults, this));
-	mCommitCallbackRegistrar.add("Pref.AvatarImpostorsEnable",	boost::bind(&LLFloaterPreference::onAvatarImpostorsEnable, this));
-	mCommitCallbackRegistrar.add("Pref.UpdateIndirectMaxComplexity",	boost::bind(&LLFloaterPreference::updateMaxComplexity, this));
+    : LLFloater(key),
+    mGotPersonalInfo(false),
+    mOriginalIMViaEmail(false),
+    mLanguageChanged(false),
+    mAvatarDataInitialized(false),
+    mSearchDataDirty(true)
+{
+    LLConversationLog::instance().addObserver(this);
+
+    //Build Floater is now Called from  LLFloaterReg::add("preferences", "floater_preferences.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLFloaterPreference>);
+
+    static bool registered_dialog = false;
+    if (!registered_dialog)
+    {
+        LLFloaterReg::add("keybind_dialog", "floater_select_key.xml", (LLFloaterBuildFunc)&LLFloaterReg::build<LLSetKeyBindDialog>);
+        registered_dialog = true;
+    }
+
+    mCommitCallbackRegistrar.add("Pref.Cancel",             boost::bind(&LLFloaterPreference::onBtnCancel, this, _2));
+    mCommitCallbackRegistrar.add("Pref.OK",                 boost::bind(&LLFloaterPreference::onBtnOK, this, _2));
+
+    mCommitCallbackRegistrar.add("Pref.ClearCache",             boost::bind(&LLFloaterPreference::onClickClearCache, this));
+    mCommitCallbackRegistrar.add("Pref.WebClearCache",          boost::bind(&LLFloaterPreference::onClickBrowserClearCache, this));
+    mCommitCallbackRegistrar.add("Pref.SetCache",               boost::bind(&LLFloaterPreference::onClickSetCache, this));
+    mCommitCallbackRegistrar.add("Pref.ResetCache",             boost::bind(&LLFloaterPreference::onClickResetCache, this));
+    mCommitCallbackRegistrar.add("Pref.SetSounds",              boost::bind(&LLFloaterPreference::onClickSetSounds, this));
+    mCommitCallbackRegistrar.add("Pref.ClickEnablePopup",       boost::bind(&LLFloaterPreference::onClickEnablePopup, this));
+    mCommitCallbackRegistrar.add("Pref.ClickDisablePopup",      boost::bind(&LLFloaterPreference::onClickDisablePopup, this));
+    mCommitCallbackRegistrar.add("Pref.LogPath",                boost::bind(&LLFloaterPreference::onClickLogPath, this));
+    mCommitCallbackRegistrar.add("Pref.RenderExceptions",       boost::bind(&LLFloaterPreference::onClickRenderExceptions, this));
+    mCommitCallbackRegistrar.add("Pref.AutoAdjustments",         boost::bind(&LLFloaterPreference::onClickAutoAdjustments, this));
+    mCommitCallbackRegistrar.add("Pref.HardwareDefaults",       boost::bind(&LLFloaterPreference::setHardwareDefaults, this));
+    mCommitCallbackRegistrar.add("Pref.AvatarImpostorsEnable",  boost::bind(&LLFloaterPreference::onAvatarImpostorsEnable, this));
+    mCommitCallbackRegistrar.add("Pref.UpdateIndirectMaxComplexity",    boost::bind(&LLFloaterPreference::updateMaxComplexity, this));
     mCommitCallbackRegistrar.add("Pref.RenderOptionUpdate",     boost::bind(&LLFloaterPreference::onRenderOptionEnable, this));
-	mCommitCallbackRegistrar.add("Pref.WindowedMod",			boost::bind(&LLFloaterPreference::onCommitWindowedMode, this));
-	mCommitCallbackRegistrar.add("Pref.UpdateSliderText",		boost::bind(&LLFloaterPreference::refreshUI,this));
-	mCommitCallbackRegistrar.add("Pref.QualityPerformance",		boost::bind(&LLFloaterPreference::onChangeQuality, this, _2));
-	mCommitCallbackRegistrar.add("Pref.applyUIColor",			boost::bind(&LLFloaterPreference::applyUIColor, this ,_1, _2));
-	mCommitCallbackRegistrar.add("Pref.getUIColor",				boost::bind(&LLFloaterPreference::getUIColor, this ,_1, _2));
-	mCommitCallbackRegistrar.add("Pref.MaturitySettings",		boost::bind(&LLFloaterPreference::onChangeMaturity, this));
-	mCommitCallbackRegistrar.add("Pref.BlockList",				boost::bind(&LLFloaterPreference::onClickBlockList, this));
-	mCommitCallbackRegistrar.add("Pref.Proxy",					boost::bind(&LLFloaterPreference::onClickProxySettings, this));
-	mCommitCallbackRegistrar.add("Pref.TranslationSettings",	boost::bind(&LLFloaterPreference::onClickTranslationSettings, this));
-	mCommitCallbackRegistrar.add("Pref.AutoReplace",            boost::bind(&LLFloaterPreference::onClickAutoReplace, this));
-	mCommitCallbackRegistrar.add("Pref.PermsDefault",           boost::bind(&LLFloaterPreference::onClickPermsDefault, this));
-	mCommitCallbackRegistrar.add("Pref.RememberedUsernames",    boost::bind(&LLFloaterPreference::onClickRememberedUsernames, this));
-	mCommitCallbackRegistrar.add("Pref.SpellChecker",           boost::bind(&LLFloaterPreference::onClickSpellChecker, this));
-	mCommitCallbackRegistrar.add("Pref.Advanced",				boost::bind(&LLFloaterPreference::onClickAdvanced, this));
-
-	sSkin = gSavedSettings.getString("SkinCurrent");
-
-	mCommitCallbackRegistrar.add("Pref.ClickActionChange",		boost::bind(&LLFloaterPreference::onClickActionChange, this));
-
-	LLAvatarPropertiesProcessor::getInstance()->addObserver(LLUUID::null, this);
+    mCommitCallbackRegistrar.add("Pref.WindowedMod",            boost::bind(&LLFloaterPreference::onCommitWindowedMode, this));
+    mCommitCallbackRegistrar.add("Pref.UpdateSliderText",       boost::bind(&LLFloaterPreference::refreshUI,this));
+    mCommitCallbackRegistrar.add("Pref.QualityPerformance",     boost::bind(&LLFloaterPreference::onChangeQuality, this, _2));
+    mCommitCallbackRegistrar.add("Pref.applyUIColor",           boost::bind(&LLFloaterPreference::applyUIColor, this ,_1, _2));
+    mCommitCallbackRegistrar.add("Pref.getUIColor",             boost::bind(&LLFloaterPreference::getUIColor, this ,_1, _2));
+    mCommitCallbackRegistrar.add("Pref.MaturitySettings",       boost::bind(&LLFloaterPreference::onChangeMaturity, this));
+    mCommitCallbackRegistrar.add("Pref.BlockList",              boost::bind(&LLFloaterPreference::onClickBlockList, this));
+    mCommitCallbackRegistrar.add("Pref.Proxy",                  boost::bind(&LLFloaterPreference::onClickProxySettings, this));
+    mCommitCallbackRegistrar.add("Pref.TranslationSettings",    boost::bind(&LLFloaterPreference::onClickTranslationSettings, this));
+    mCommitCallbackRegistrar.add("Pref.AutoReplace",            boost::bind(&LLFloaterPreference::onClickAutoReplace, this));
+    mCommitCallbackRegistrar.add("Pref.PermsDefault",           boost::bind(&LLFloaterPreference::onClickPermsDefault, this));
+    mCommitCallbackRegistrar.add("Pref.RememberedUsernames",    boost::bind(&LLFloaterPreference::onClickRememberedUsernames, this));
+    mCommitCallbackRegistrar.add("Pref.SpellChecker",           boost::bind(&LLFloaterPreference::onClickSpellChecker, this));
+    mCommitCallbackRegistrar.add("Pref.Advanced",               boost::bind(&LLFloaterPreference::onClickAdvanced, this));
+
+    sSkin = gSavedSettings.getString("SkinCurrent");
+
+    mCommitCallbackRegistrar.add("Pref.ClickActionChange",      boost::bind(&LLFloaterPreference::onClickActionChange, this));
+
+    LLAvatarPropertiesProcessor::getInstance()->addObserver(LLUUID::null, this);
 
     mComplexityChangedSignal = gSavedSettings.getControl("RenderAvatarMaxComplexity")->getCommitSignal()->connect(boost::bind(&LLFloaterPreference::updateComplexityText, this));
 
-	mCommitCallbackRegistrar.add("Pref.ClearLog",				boost::bind(&LLConversationLog::onClearLog, &LLConversationLog::instance()));
-	mCommitCallbackRegistrar.add("Pref.DeleteTranscripts",      boost::bind(&LLFloaterPreference::onDeleteTranscripts, this));
-	mCommitCallbackRegistrar.add("UpdateFilter", boost::bind(&LLFloaterPreference::onUpdateFilterTerm, this, false));
+    mCommitCallbackRegistrar.add("Pref.ClearLog",               boost::bind(&LLConversationLog::onClearLog, &LLConversationLog::instance()));
+    mCommitCallbackRegistrar.add("Pref.DeleteTranscripts",      boost::bind(&LLFloaterPreference::onDeleteTranscripts, this));
+    mCommitCallbackRegistrar.add("UpdateFilter", boost::bind(&LLFloaterPreference::onUpdateFilterTerm, this, false));
 
 #if !LL_HAVOK
-	mCommitCallbackRegistrar.add("Pref.AddGrid", boost::bind(&LLFloaterPreference::onClickAddGrid, this));
+    mCommitCallbackRegistrar.add("Pref.AddGrid", boost::bind(&LLFloaterPreference::onClickAddGrid, this));
     mCommitCallbackRegistrar.add("Pref.ActivateGrid", boost::bind(&LLFloaterPreference::onClickActivateGrid, this));
-	mCommitCallbackRegistrar.add("Pref.RemoveGrid", boost::bind(&LLFloaterPreference::onClickRemoveGrid, this));
-	mCommitCallbackRegistrar.add("Pref.RefreshGrid", boost::bind(&LLFloaterPreference::onClickRefreshGrid, this));
-	mCommitCallbackRegistrar.add("Pref.DebugGrid", boost::bind(&LLFloaterPreference::onClickDebugGrid, this));
-	mCommitCallbackRegistrar.add("Pref.SelectGrid", boost::bind(&LLFloaterPreference::onSelectGrid, this, _2));
+    mCommitCallbackRegistrar.add("Pref.RemoveGrid", boost::bind(&LLFloaterPreference::onClickRemoveGrid, this));
+    mCommitCallbackRegistrar.add("Pref.RefreshGrid", boost::bind(&LLFloaterPreference::onClickRefreshGrid, this));
+    mCommitCallbackRegistrar.add("Pref.DebugGrid", boost::bind(&LLFloaterPreference::onClickDebugGrid, this));
+    mCommitCallbackRegistrar.add("Pref.SelectGrid", boost::bind(&LLFloaterPreference::onSelectGrid, this, _2));
 #endif
-	mCommitCallbackRegistrar.add("Pref.AddSkin", boost::bind(&LLFloaterPreference::onAddSkin, this));
-	mCommitCallbackRegistrar.add("Pref.RemoveSkin", boost::bind(&LLFloaterPreference::onRemoveSkin, this));
-	mCommitCallbackRegistrar.add("Pref.ApplySkin", boost::bind(&LLFloaterPreference::onApplySkin, this));
-	mCommitCallbackRegistrar.add("Pref.SelectSkin", boost::bind(&LLFloaterPreference::onSelectSkin, this, _2));
-
-	mCommitCallbackRegistrar.add("Pref.ResetControlDefault", [](LLUICtrl* ctrl, const LLSD& userdata)
-		{
-			const std::string& control_name = userdata.asString();
-			LLControlVariable* controlp = gSavedSettings.getControl(control_name);
-			if (controlp)
-			{
-				controlp->resetToDefault(true);
-			}
-		});
+    mCommitCallbackRegistrar.add("Pref.AddSkin", boost::bind(&LLFloaterPreference::onAddSkin, this));
+    mCommitCallbackRegistrar.add("Pref.RemoveSkin", boost::bind(&LLFloaterPreference::onRemoveSkin, this));
+    mCommitCallbackRegistrar.add("Pref.ApplySkin", boost::bind(&LLFloaterPreference::onApplySkin, this));
+    mCommitCallbackRegistrar.add("Pref.SelectSkin", boost::bind(&LLFloaterPreference::onSelectSkin, this, _2));
+
+    mCommitCallbackRegistrar.add("Pref.ResetControlDefault", [](LLUICtrl* ctrl, const LLSD& userdata)
+        {
+            const std::string& control_name = userdata.asString();
+            LLControlVariable* controlp = gSavedSettings.getControl(control_name);
+            if (controlp)
+            {
+                controlp->resetToDefault(true);
+            }
+        });
 }
 
 void LLFloaterPreference::processProperties( void* pData, EAvatarProcessorType type )
 {
     if ( APT_PROPERTIES_LEGACY == type )
-	{
+    {
         const LLAvatarLegacyData* pAvatarData = static_cast<const LLAvatarLegacyData*>( pData );
-		if (pAvatarData && (gAgent.getID() == pAvatarData->avatar_id) && (pAvatarData->avatar_id.notNull()))
-		{
+        if (pAvatarData && (gAgent.getID() == pAvatarData->avatar_id) && (pAvatarData->avatar_id.notNull()))
+        {
             mAllowPublish = (bool)(pAvatarData->flags & AVATAR_ALLOW_PUBLISH);
             mAvatarDataInitialized = true;
             getChild<LLUICtrl>("online_searchresults")->setValue(mAllowPublish);
-		}
-	}	
+        }
+    }
 }
 
 void LLFloaterPreference::saveAvatarProperties( void )
@@ -454,94 +454,94 @@ void LLFloaterPreference::saveAvatarPropertiesCoro(const std::string cap_url, bo
 
 BOOL LLFloaterPreference::postBuild()
 {
-	gSavedSettings.getControl("ChatBubbleOpacity")->getSignal()->connect(boost::bind(&LLFloaterPreference::onNameTagOpacityChange, this, _2));
+    gSavedSettings.getControl("ChatBubbleOpacity")->getSignal()->connect(boost::bind(&LLFloaterPreference::onNameTagOpacityChange, this, _2));
 
-	gSavedSettings.getControl("PreferredMaturity")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeMaturity, this));
+    gSavedSettings.getControl("PreferredMaturity")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeMaturity, this));
 
-	gSavedPerAccountSettings.getControl("ModelUploadFolder")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeModelFolder, this));
+    gSavedPerAccountSettings.getControl("ModelUploadFolder")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeModelFolder, this));
     gSavedPerAccountSettings.getControl("PBRUploadFolder")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangePBRFolder, this));
-	gSavedPerAccountSettings.getControl("TextureUploadFolder")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeTextureFolder, this));
-	gSavedPerAccountSettings.getControl("SoundUploadFolder")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeSoundFolder, this));
-	gSavedPerAccountSettings.getControl("AnimationUploadFolder")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeAnimationFolder, this));
-
-	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
-	if (!tabcontainer->selectTab(gSavedSettings.getS32("LastPrefTab")))
-		tabcontainer->selectFirstTab();
-
-	getChild<LLUICtrl>("cache_location")->setEnabled(FALSE); // make it read-only but selectable (STORM-227)
-	std::string cache_location = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "");
-	setCacheLocation(cache_location);
-
-	getChild<LLUICtrl>("log_path_string")->setEnabled(FALSE); // make it read-only but selectable
-
-	getChild<LLComboBox>("language_combobox")->setCommitCallback(boost::bind(&LLFloaterPreference::onLanguageChange, this));
-
-	getChild<LLComboBox>("FriendIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"FriendIMOptions"));
-	getChild<LLComboBox>("NonFriendIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"NonFriendIMOptions"));
-	getChild<LLComboBox>("ConferenceIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"ConferenceIMOptions"));
-	getChild<LLComboBox>("GroupChatOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"GroupChatOptions"));
-	getChild<LLComboBox>("NearbyChatOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"NearbyChatOptions"));
-	getChild<LLComboBox>("ObjectIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"ObjectIMOptions"));
-
-	// if floater is opened before login set default localized do not disturb message
-	if (LLStartUp::getStartupState() < STATE_STARTED)
-	{
-		gSavedPerAccountSettings.setString("DoNotDisturbModeResponse", LLTrans::getString("DoNotDisturbModeResponseDefault"));
-		gSavedPerAccountSettings.setString("ALRejectTeleportOffersResponse", LLTrans::getString("RejectTeleportOffersResponseDefault"));
-		gSavedPerAccountSettings.setString("ALRejectFriendshipRequestsResponse", LLTrans::getString("RejectFriendshipRequestsResponseDefault"));
-	}
-
-	// set 'enable' property for 'Clear log...' button
-	changed();
-
-	LLLogChat::getInstance()->setSaveHistorySignal(boost::bind(&LLFloaterPreference::onLogChatHistorySaved, this));
-	
+    gSavedPerAccountSettings.getControl("TextureUploadFolder")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeTextureFolder, this));
+    gSavedPerAccountSettings.getControl("SoundUploadFolder")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeSoundFolder, this));
+    gSavedPerAccountSettings.getControl("AnimationUploadFolder")->getSignal()->connect(boost::bind(&LLFloaterPreference::onChangeAnimationFolder, this));
+
+    LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
+    if (!tabcontainer->selectTab(gSavedSettings.getS32("LastPrefTab")))
+        tabcontainer->selectFirstTab();
+
+    getChild<LLUICtrl>("cache_location")->setEnabled(FALSE); // make it read-only but selectable (STORM-227)
+    std::string cache_location = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "");
+    setCacheLocation(cache_location);
+
+    getChild<LLUICtrl>("log_path_string")->setEnabled(FALSE); // make it read-only but selectable
+
+    getChild<LLComboBox>("language_combobox")->setCommitCallback(boost::bind(&LLFloaterPreference::onLanguageChange, this));
+
+    getChild<LLComboBox>("FriendIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"FriendIMOptions"));
+    getChild<LLComboBox>("NonFriendIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"NonFriendIMOptions"));
+    getChild<LLComboBox>("ConferenceIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"ConferenceIMOptions"));
+    getChild<LLComboBox>("GroupChatOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"GroupChatOptions"));
+    getChild<LLComboBox>("NearbyChatOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"NearbyChatOptions"));
+    getChild<LLComboBox>("ObjectIMOptions")->setCommitCallback(boost::bind(&LLFloaterPreference::onNotificationsChange, this,"ObjectIMOptions"));
+
+    // if floater is opened before login set default localized do not disturb message
+    if (LLStartUp::getStartupState() < STATE_STARTED)
+    {
+        gSavedPerAccountSettings.setString("DoNotDisturbModeResponse", LLTrans::getString("DoNotDisturbModeResponseDefault"));
+        gSavedPerAccountSettings.setString("ALRejectTeleportOffersResponse", LLTrans::getString("RejectTeleportOffersResponseDefault"));
+        gSavedPerAccountSettings.setString("ALRejectFriendshipRequestsResponse", LLTrans::getString("RejectFriendshipRequestsResponseDefault"));
+    }
+
+    // set 'enable' property for 'Clear log...' button
+    changed();
+
+    LLLogChat::getInstance()->setSaveHistorySignal(boost::bind(&LLFloaterPreference::onLogChatHistorySaved, this));
+
 #if !LL_HAVOK
-	refreshGridList();
-	mGridListChangedConnection = LLGridManager::getInstance()->addGridListChangedCallback(boost::bind(&LLFloaterPreference::refreshGridList, this));
+    refreshGridList();
+    mGridListChangedConnection = LLGridManager::getInstance()->addGridListChangedCallback(boost::bind(&LLFloaterPreference::refreshGridList, this));
 #else
-	if(tabcontainer)
-	{
-		auto tab = tabcontainer->getPanelByName("grids");
-		if(tab) tabcontainer->removeTabPanel(tab);
-	}
+    if(tabcontainer)
+    {
+        auto tab = tabcontainer->getPanelByName("grids");
+        if(tab) tabcontainer->removeTabPanel(tab);
+    }
 #endif
 
-	loadUserSkins();
-	
-
-	LLSliderCtrl* fov_slider = getChild<LLSliderCtrl>("camera_fov");
-	fov_slider->setMinValue(LLViewerCamera::getInstance()->getMinView());
-	fov_slider->setMaxValue(LLViewerCamera::getInstance()->getMaxView());
-	
-	// Hook up and init for filtering
-	mFilterEdit = getChild<LLSearchEditor>("search_prefs_edit");
-	mFilterEdit->setKeystrokeCallback(boost::bind(&LLFloaterPreference::onUpdateFilterTerm, this, false));
-
-	// Load and assign label for 'default language'
-	std::string user_filename = gDirUtilp->getExpandedFilename(LL_PATH_DEFAULT_SKIN, "default_languages.xml");
-	std::map<std::string, std::string> labels;
-	if (loadFromFilename(user_filename, labels))
-	{
-		std::string system_lang = gSavedSettings.getString("SystemLanguage");
-		std::map<std::string, std::string>::iterator iter = labels.find(system_lang);
-		if (iter != labels.end())
-		{
-			getChild<LLComboBox>("language_combobox")->add(iter->second, LLSD("default"), ADD_TOP, true);
-		}
-		else
-		{
-			LL_WARNS() << "Language \"" << system_lang << "\" is not in default_languages.xml" << LL_ENDL;
-			getChild<LLComboBox>("language_combobox")->add("System default", LLSD("default"), ADD_TOP, true);
-		}
-	}
-	else
-	{
-		LL_WARNS() << "Failed to load labels from " << user_filename << ". Using default." << LL_ENDL;
-		getChild<LLComboBox>("language_combobox")->add("System default", LLSD("default"), ADD_TOP, true);
-	}
-
-	return TRUE;
+    loadUserSkins();
+
+
+    LLSliderCtrl* fov_slider = getChild<LLSliderCtrl>("camera_fov");
+    fov_slider->setMinValue(LLViewerCamera::getInstance()->getMinView());
+    fov_slider->setMaxValue(LLViewerCamera::getInstance()->getMaxView());
+
+    // Hook up and init for filtering
+    mFilterEdit = getChild<LLSearchEditor>("search_prefs_edit");
+    mFilterEdit->setKeystrokeCallback(boost::bind(&LLFloaterPreference::onUpdateFilterTerm, this, false));
+
+    // Load and assign label for 'default language'
+    std::string user_filename = gDirUtilp->getExpandedFilename(LL_PATH_DEFAULT_SKIN, "default_languages.xml");
+    std::map<std::string, std::string> labels;
+    if (loadFromFilename(user_filename, labels))
+    {
+        std::string system_lang = gSavedSettings.getString("SystemLanguage");
+        std::map<std::string, std::string>::iterator iter = labels.find(system_lang);
+        if (iter != labels.end())
+        {
+            getChild<LLComboBox>("language_combobox")->add(iter->second, LLSD("default"), ADD_TOP, true);
+        }
+        else
+        {
+            LL_WARNS() << "Language \"" << system_lang << "\" is not in default_languages.xml" << LL_ENDL;
+            getChild<LLComboBox>("language_combobox")->add("System default", LLSD("default"), ADD_TOP, true);
+        }
+    }
+    else
+    {
+        LL_WARNS() << "Failed to load labels from " << user_filename << ". Using default." << LL_ENDL;
+        getChild<LLComboBox>("language_combobox")->add("System default", LLSD("default"), ADD_TOP, true);
+    }
+
+    return TRUE;
 }
 
 void LLFloaterPreference::updateDeleteTranscriptsButton()
@@ -551,27 +551,27 @@ void LLFloaterPreference::updateDeleteTranscriptsButton()
 
 void LLFloaterPreference::onDoNotDisturbResponseChanged()
 {
-	// set "DoNotDisturbResponseChanged" TRUE if user edited message differs from default, FALSE otherwise
-	bool response_changed_flag =
-			LLTrans::getString("DoNotDisturbModeResponseDefault")
-					!= getChild<LLUICtrl>("do_not_disturb_response")->getValue().asString();
+    // set "DoNotDisturbResponseChanged" TRUE if user edited message differs from default, FALSE otherwise
+    bool response_changed_flag =
+            LLTrans::getString("DoNotDisturbModeResponseDefault")
+                    != getChild<LLUICtrl>("do_not_disturb_response")->getValue().asString();
 
-	gSavedPerAccountSettings.setBOOL("DoNotDisturbResponseChanged", response_changed_flag );
+    gSavedPerAccountSettings.setBOOL("DoNotDisturbResponseChanged", response_changed_flag );
 
-	bool reject_friendship_requests_response_changed_flag = 
-			LLTrans::getString("RejectFriendshipRequestsResponseDefault")
-				!= getChild<LLUICtrl>("autorespond_reject_friends_response")->getValue().asString();
+    bool reject_friendship_requests_response_changed_flag =
+            LLTrans::getString("RejectFriendshipRequestsResponseDefault")
+                != getChild<LLUICtrl>("autorespond_reject_friends_response")->getValue().asString();
 
-	gSavedPerAccountSettings.setBOOL("ALRejectFriendshipRequestsChanged", reject_friendship_requests_response_changed_flag);
+    gSavedPerAccountSettings.setBOOL("ALRejectFriendshipRequestsChanged", reject_friendship_requests_response_changed_flag);
 }
 
 void LLFloaterPreference::onRejectTeleportOffersResponseChanged()
 {
-	bool reject_teleport_offers_response_changed_flag =
-			LLTrans::getString("RejectTeleportOffersResponseDefault")
-					!= getChild<LLUICtrl>("autorespond_rto_response")->getValue().asString();
+    bool reject_teleport_offers_response_changed_flag =
+            LLTrans::getString("RejectTeleportOffersResponseDefault")
+                    != getChild<LLUICtrl>("autorespond_rto_response")->getValue().asString();
 
-	gSavedPerAccountSettings.setBOOL("ALRejectTeleportOffersResponseChanged", reject_teleport_offers_response_changed_flag);
+    gSavedPerAccountSettings.setBOOL("ALRejectTeleportOffersResponseChanged", reject_teleport_offers_response_changed_flag);
 }
 
 #if !LL_HAVOK
@@ -580,36 +580,36 @@ void LLFloaterPreference::onRejectTeleportOffersResponseChanged()
 
 void LLFloaterPreference::refreshGridList()
 {
-	LLScrollListCtrl* grid_list = getChild<LLScrollListCtrl>("grid_list");
-	grid_list->clearRows();
-	std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();
-	for (auto& known_grid : known_grids)
-    {
-		if (!known_grid.first.empty() && !known_grid.second.empty())
-		{
-			bool connected_grid = LLGridManager::getInstance()->getGrid() == known_grid.first;
-			std::vector<std::string> uris;
-			LLGridManager::getInstance()->getLoginURIs(known_grid.first, uris);
-			LLURI login_uri = LLURI(uris.at(0));
-			
-			LLSD row;
-			row["id"] = known_grid.first;
-			row["columns"][0]["column"] = "grid_label";
-			row["columns"][0]["value"] = known_grid.second;
-			row["columns"][0]["font"]["style"] = connected_grid ? "BOLD" : "NORMAL";
-			row["columns"][1]["column"] = "login_uri";
-			row["columns"][1]["value"] = login_uri.authority();
-			row["columns"][1]["font"]["style"] = connected_grid ? "BOLD" : "NORMAL";
-			
-			grid_list->addElement(row);
-		}
-	}
+    LLScrollListCtrl* grid_list = getChild<LLScrollListCtrl>("grid_list");
+    grid_list->clearRows();
+    std::map<std::string, std::string> known_grids = LLGridManager::getInstance()->getKnownGrids();
+    for (auto& known_grid : known_grids)
+    {
+        if (!known_grid.first.empty() && !known_grid.second.empty())
+        {
+            bool connected_grid = LLGridManager::getInstance()->getGrid() == known_grid.first;
+            std::vector<std::string> uris;
+            LLGridManager::getInstance()->getLoginURIs(known_grid.first, uris);
+            LLURI login_uri = LLURI(uris.at(0));
+
+            LLSD row;
+            row["id"] = known_grid.first;
+            row["columns"][0]["column"] = "grid_label";
+            row["columns"][0]["value"] = known_grid.second;
+            row["columns"][0]["font"]["style"] = connected_grid ? "BOLD" : "NORMAL";
+            row["columns"][1]["column"] = "login_uri";
+            row["columns"][1]["value"] = login_uri.authority();
+            row["columns"][1]["font"]["style"] = connected_grid ? "BOLD" : "NORMAL";
+
+            grid_list->addElement(row);
+        }
+    }
 }
 
 void LLFloaterPreference::onClickAddGrid()
 {
-	std::string login_uri = getChild<LLLineEditor>("add_grid")->getValue().asString();
-	LLGridManager::getInstance()->addRemoteGrid(login_uri, LLGridManager::ADD_MANUAL);
+    std::string login_uri = getChild<LLLineEditor>("add_grid")->getValue().asString();
+    LLGridManager::getInstance()->addRemoteGrid(login_uri, LLGridManager::ADD_MANUAL);
 }
 
 void LLFloaterPreference::onClickActivateGrid()
@@ -620,63 +620,63 @@ void LLFloaterPreference::onClickActivateGrid()
 
 void LLFloaterPreference::onClickRemoveGrid()
 {
-	std::string grid = getChild<LLScrollListCtrl>("grid_list")->getSelectedValue().asString();
-	if (LLGridManager::getInstance()->getGrid() == grid)
-	{
-		LLNotificationsUtil::add("CannotRemoveConnectedGrid",
-								 LLSD().with("GRID", LLGridManager::getInstance()->getGridLabel()));
-	}
-	else
-	{
-		LLNotificationsUtil::add("ConfirmRemoveGrid",
-								 LLSD().with("GRID", LLGridManager::getInstance()->getGridLabel(grid)),
-								 LLSD(grid), boost::bind(&LLFloaterPreference::handleRemoveGridCB, this, _1, _2));
-	}
+    std::string grid = getChild<LLScrollListCtrl>("grid_list")->getSelectedValue().asString();
+    if (LLGridManager::getInstance()->getGrid() == grid)
+    {
+        LLNotificationsUtil::add("CannotRemoveConnectedGrid",
+                                 LLSD().with("GRID", LLGridManager::getInstance()->getGridLabel()));
+    }
+    else
+    {
+        LLNotificationsUtil::add("ConfirmRemoveGrid",
+                                 LLSD().with("GRID", LLGridManager::getInstance()->getGridLabel(grid)),
+                                 LLSD(grid), boost::bind(&LLFloaterPreference::handleRemoveGridCB, this, _1, _2));
+    }
 }
 
 void LLFloaterPreference::onClickRefreshGrid()
 {
-	std::string grid = getChild<LLScrollListCtrl>("grid_list")->getSelectedValue().asString();
-	// So I'm a little paranoid, no big deal...
-	if (!LLGridManager::getInstance()->isSystemGrid(grid))
-	{
-		LLGridManager::getInstance()->addRemoteGrid(grid, LLGridManager::ADD_MANUAL);
-	}
+    std::string grid = getChild<LLScrollListCtrl>("grid_list")->getSelectedValue().asString();
+    // So I'm a little paranoid, no big deal...
+    if (!LLGridManager::getInstance()->isSystemGrid(grid))
+    {
+        LLGridManager::getInstance()->addRemoteGrid(grid, LLGridManager::ADD_MANUAL);
+    }
 }
 
 void LLFloaterPreference::onClickDebugGrid()
 {
-	LLSD args;
-	std::stringstream data_str;
-	const std::string& grid = getChild<LLScrollListCtrl>("grid_list")->getSelectedValue().asString().c_str();
-	LLSD gridInfo = LLGridManager::getInstance()->getGridInfo(grid);
-	LLSDSerialize::toPrettyXML(gridInfo, data_str);
-	args["title"] = llformat("%s - %s", LLTrans::getString("GridInfoTitle").c_str(), grid.c_str());
-	args["data"] = data_str.str();
-	LLFloaterReg::showInstance("generic_text", args);
+    LLSD args;
+    std::stringstream data_str;
+    const std::string& grid = getChild<LLScrollListCtrl>("grid_list")->getSelectedValue().asString().c_str();
+    LLSD gridInfo = LLGridManager::getInstance()->getGridInfo(grid);
+    LLSDSerialize::toPrettyXML(gridInfo, data_str);
+    args["title"] = llformat("%s - %s", LLTrans::getString("GridInfoTitle").c_str(), grid.c_str());
+    args["data"] = data_str.str();
+    LLFloaterReg::showInstance("generic_text", args);
 }
 
 void LLFloaterPreference::onSelectGrid(const LLSD& data)
 {
     getChild<LLUICtrl>("activate_grid")->setEnabled(LLStartUp::getStartupState() < STATE_LOGIN_CLEANUP
                                                     && LLGridManager::getInstance()->getGrid() != data.asString());
-	getChild<LLUICtrl>("remove_grid")->setEnabled(LLGridManager::getInstance()->getGrid() != data.asString()
-												  && !LLGridManager::getInstance()->isSystemGrid(data.asString()));
-	getChild<LLUICtrl>("refresh_grid")->setEnabled(!LLGridManager::getInstance()->isSystemGrid(data.asString()));
-	getChild<LLUICtrl>("debug_grid")->setEnabled(!data.asString().empty());
+    getChild<LLUICtrl>("remove_grid")->setEnabled(LLGridManager::getInstance()->getGrid() != data.asString()
+                                                  && !LLGridManager::getInstance()->isSystemGrid(data.asString()));
+    getChild<LLUICtrl>("refresh_grid")->setEnabled(!LLGridManager::getInstance()->isSystemGrid(data.asString()));
+    getChild<LLUICtrl>("debug_grid")->setEnabled(!data.asString().empty());
 }
 
 bool LLFloaterPreference::handleRemoveGridCB(const LLSD& notification, const LLSD& response)
 {
-	const S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (0 == option)
-	{
-		const std::string& grid = notification["payload"].asString();
-		if (!LLGridManager::getInstance()->removeGrid(grid))
-			LLNotificationsUtil::add("RemoveGridFailure",
-									 LLSD().with("GRID", notification["substitutions"]["GRID"].asString()));
-	}
-	return false;
+    const S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (0 == option)
+    {
+        const std::string& grid = notification["payload"].asString();
+        if (!LLGridManager::getInstance()->removeGrid(grid))
+            LLNotificationsUtil::add("RemoveGridFailure",
+                                     LLSD().with("GRID", notification["substitutions"]["GRID"].asString()));
+    }
+    return false;
 }
 #endif
 
@@ -685,568 +685,568 @@ bool LLFloaterPreference::handleRemoveGridCB(const LLSD& notification, const LLS
 
 skin_t manifestFromJson(const std::string& filename, const ESkinType type)
 {
-	skin_t skin;
-	llifstream in;
-	in.open(filename);
-	if (in.is_open())
-	{
-		boost::system::error_code ec;
-		auto root = boost::json::parse(in, ec);
-		if (!ec.failed() && root.is_object())
+    skin_t skin;
+    llifstream in;
+    in.open(filename);
+    if (in.is_open())
+    {
+        boost::system::error_code ec;
+        auto root = boost::json::parse(in, ec);
+        if (!ec.failed() && root.is_object())
         {
-			auto jobj = root.as_object();
+            auto jobj = root.as_object();
             skin.mName = jobj.contains("name") ? boost::json::value_to<std::string>(jobj.at("name")) : "Unknown";
             skin.mAuthor = jobj.contains("author") ? boost::json::value_to<std::string>(jobj.at("author")) : LLTrans::getString("Unknown");
             skin.mUrl = jobj.contains("url") ? boost::json::value_to<std::string>(jobj.at("url")) : LLTrans::getString("Unknown");
-			skin.mCompatVer = jobj.contains("compatibility") ? boost::json::value_to<std::string>(jobj.at("compatibility")) : LLTrans::getString("Unknown");
-			skin.mDate = jobj.contains("date") ? LLDate(boost::json::value_to<std::string>(jobj.at("date"))) : LLDate::now();
-			skin.mNotes = jobj.contains("notes") ? boost::json::value_to<std::string>(jobj.at("notes")) : "";
-			// If it's a system skin, the compatability version is always the current build
-			if (type == SYSTEM_SKIN)
-			{
-				skin.mCompatVer = LLVersionInfo::instance().getShortVersion();
-			}
-        } 
-		else
-		{
-			LL_WARNS() << "Failed to parse " << filename << ": " << ec.message() << LL_ENDL;
-		}
-		in.close();
-	}
-	skin.mType = type;
-	return skin;
+            skin.mCompatVer = jobj.contains("compatibility") ? boost::json::value_to<std::string>(jobj.at("compatibility")) : LLTrans::getString("Unknown");
+            skin.mDate = jobj.contains("date") ? LLDate(boost::json::value_to<std::string>(jobj.at("date"))) : LLDate::now();
+            skin.mNotes = jobj.contains("notes") ? boost::json::value_to<std::string>(jobj.at("notes")) : "";
+            // If it's a system skin, the compatability version is always the current build
+            if (type == SYSTEM_SKIN)
+            {
+                skin.mCompatVer = LLVersionInfo::instance().getShortVersion();
+            }
+        }
+        else
+        {
+            LL_WARNS() << "Failed to parse " << filename << ": " << ec.message() << LL_ENDL;
+        }
+        in.close();
+    }
+    skin.mType = type;
+    return skin;
 }
 
 void LLFloaterPreference::loadUserSkins()
 {
-	mUserSkins.clear();
-	LLDirIterator sysiter(gDirUtilp->getSkinBaseDir(), "*");
-	bool found = true;
-	while (found)
-	{
-		std::string dir;
-		if ((found = sysiter.next(dir)))
-		{
-			const std::string& fullpath = gDirUtilp->add(gDirUtilp->getSkinBaseDir(), dir);
-			if (!LLFile::isdir(fullpath)) continue; // only directories!
-			
-			const std::string& manifestpath = gDirUtilp->add(fullpath, "manifest.json");
-			skin_t skin = manifestFromJson(manifestpath, SYSTEM_SKIN);
-			
-			mUserSkins.emplace(dir, skin);
-		}
-	}
-	
-	const std::string userskindir = gDirUtilp->add(gDirUtilp->getOSUserAppDir(), "skins");
-	if (LLFile::isdir(userskindir))
-	{
-		LLDirIterator iter(userskindir, "*");
-		found = true;
-		while (found)
-		{
-			std::string dir;
-			if ((found = iter.next(dir)))
-			{
-				const std::string& fullpath = gDirUtilp->add(userskindir, dir);
-				if (!LLFile::isdir(fullpath)) continue; // only directories!
-
-				const std::string& manifestpath = gDirUtilp->add(fullpath, "manifest.json");
-				skin_t skin = manifestFromJson(manifestpath, USER_SKIN);
-
-				mUserSkins.emplace(dir, skin);
-			}
-		}
-	}
-	reloadSkinList();
+    mUserSkins.clear();
+    LLDirIterator sysiter(gDirUtilp->getSkinBaseDir(), "*");
+    bool found = true;
+    while (found)
+    {
+        std::string dir;
+        if ((found = sysiter.next(dir)))
+        {
+            const std::string& fullpath = gDirUtilp->add(gDirUtilp->getSkinBaseDir(), dir);
+            if (!LLFile::isdir(fullpath)) continue; // only directories!
+
+            const std::string& manifestpath = gDirUtilp->add(fullpath, "manifest.json");
+            skin_t skin = manifestFromJson(manifestpath, SYSTEM_SKIN);
+
+            mUserSkins.emplace(dir, skin);
+        }
+    }
+
+    const std::string userskindir = gDirUtilp->add(gDirUtilp->getOSUserAppDir(), "skins");
+    if (LLFile::isdir(userskindir))
+    {
+        LLDirIterator iter(userskindir, "*");
+        found = true;
+        while (found)
+        {
+            std::string dir;
+            if ((found = iter.next(dir)))
+            {
+                const std::string& fullpath = gDirUtilp->add(userskindir, dir);
+                if (!LLFile::isdir(fullpath)) continue; // only directories!
+
+                const std::string& manifestpath = gDirUtilp->add(fullpath, "manifest.json");
+                skin_t skin = manifestFromJson(manifestpath, USER_SKIN);
+
+                mUserSkins.emplace(dir, skin);
+            }
+        }
+    }
+    reloadSkinList();
 }
 
 void LLFloaterPreference::reloadSkinList()
 {
-	LLScrollListCtrl* skin_list = getChild<LLScrollListCtrl>("skin_list");
-	const std::string current_skin = gSavedSettings.getString("SkinCurrent");
-	
-	skin_list->clearRows();
+    LLScrollListCtrl* skin_list = getChild<LLScrollListCtrl>("skin_list");
+    const std::string current_skin = gSavedSettings.getString("SkinCurrent");
 
-	// User Downloaded Skins
-	for (const auto& skin : mUserSkins)
-	{
-		LLSD row;
-		row["id"] = skin.first;
-		row["columns"][0]["value"] = skin.second.mName == "Unknown" ? skin.first : skin.second.mName;
-		row["columns"][0]["font"]["style"] = current_skin == skin.first ? "BOLD" : "NORMAL";
-		skin_list->addElement(row);
-	}
-	skin_list->setSelectedByValue(current_skin, TRUE);
-	onSelectSkin(skin_list->getSelectedValue());
+    skin_list->clearRows();
+
+    // User Downloaded Skins
+    for (const auto& skin : mUserSkins)
+    {
+        LLSD row;
+        row["id"] = skin.first;
+        row["columns"][0]["value"] = skin.second.mName == "Unknown" ? skin.first : skin.second.mName;
+        row["columns"][0]["font"]["style"] = current_skin == skin.first ? "BOLD" : "NORMAL";
+        skin_list->addElement(row);
+    }
+    skin_list->setSelectedByValue(current_skin, TRUE);
+    onSelectSkin(skin_list->getSelectedValue());
 }
 
 void LLFloaterPreference::onAddSkin()
 {
-	LLFilePickerReplyThread::startPicker(boost::bind(&LLFloaterPreference::onAddSkinCallback, this, _1), LLFilePicker::FFLOAD_ZIP, false);
+    LLFilePickerReplyThread::startPicker(boost::bind(&LLFloaterPreference::onAddSkinCallback, this, _1), LLFilePicker::FFLOAD_ZIP, false);
 }
 
 void LLFloaterPreference::onAddSkinCallback(const std::vector<std::string>& filenames)
 {
-	const std::string& package = filenames[0];
-	auto zip = std::make_unique<ALUnZip>(package);
-	if (zip->isValid())
-	{
-		size_t buf_size = zip->getSizeFile("manifest.json");
-		if (buf_size)
-		{
-			buf_size++;
-			buf_size *= sizeof(char);
-			auto buf = std::make_unique<char[]>(buf_size);
-			zip->extractFile("manifest.json", buf.get(), buf_size);
-			buf[buf_size - 1] = '\0'; // force.
-			std::stringstream ss;
-			ss << std::string(const_cast<const char*>(buf.get()), buf_size);
-			buf.reset();
-				
-			boost::system::error_code ec;
-			auto root = boost::json::parse(ss, ec);
-			if (!ec.failed() && root.is_object())
-			{
-				const auto& jobj = root.as_object();
-				const std::string& name = jobj.contains("name") ? boost::json::value_to<std::string>(jobj.at("name")) : "Unknown";
-				std::string pathname = gDirUtilp->add(gDirUtilp->getOSUserAppDir(), "skins");
-				if (!gDirUtilp->fileExists(pathname))
-				{
-					LLFile::mkdir(pathname);
-				}
-				pathname = gDirUtilp->add(pathname, name);
-				if (!LLFile::isdir(pathname) && (LLFile::mkdir(pathname) != 0))
-				{
-					LLNotificationsUtil::add("AddSkinUnpackFailed");
-				}
-				else if (!zip->extract(pathname))
-				{
-					LLNotificationsUtil::add("AddSkinUnpackFailed");
-				}
-				else
-				{
-					loadUserSkins();
-					LLNotificationsUtil::add("AddSkinSuccess", LLSD().with("PACKAGE", name));
-				}
-			}
-			else
-			{
-				LLNotificationsUtil::add("AddSkinCantParseManifest", LLSD().with("PACKAGE", package));
-			}
-		}
-		else
-		{
-			LLNotificationsUtil::add("AddSkinNoManifest", LLSD().with("PACKAGE", package));
-		}
-	}
+    const std::string& package = filenames[0];
+    auto zip = std::make_unique<ALUnZip>(package);
+    if (zip->isValid())
+    {
+        size_t buf_size = zip->getSizeFile("manifest.json");
+        if (buf_size)
+        {
+            buf_size++;
+            buf_size *= sizeof(char);
+            auto buf = std::make_unique<char[]>(buf_size);
+            zip->extractFile("manifest.json", buf.get(), buf_size);
+            buf[buf_size - 1] = '\0'; // force.
+            std::stringstream ss;
+            ss << std::string(const_cast<const char*>(buf.get()), buf_size);
+            buf.reset();
+
+            boost::system::error_code ec;
+            auto root = boost::json::parse(ss, ec);
+            if (!ec.failed() && root.is_object())
+            {
+                const auto& jobj = root.as_object();
+                const std::string& name = jobj.contains("name") ? boost::json::value_to<std::string>(jobj.at("name")) : "Unknown";
+                std::string pathname = gDirUtilp->add(gDirUtilp->getOSUserAppDir(), "skins");
+                if (!gDirUtilp->fileExists(pathname))
+                {
+                    LLFile::mkdir(pathname);
+                }
+                pathname = gDirUtilp->add(pathname, name);
+                if (!LLFile::isdir(pathname) && (LLFile::mkdir(pathname) != 0))
+                {
+                    LLNotificationsUtil::add("AddSkinUnpackFailed");
+                }
+                else if (!zip->extract(pathname))
+                {
+                    LLNotificationsUtil::add("AddSkinUnpackFailed");
+                }
+                else
+                {
+                    loadUserSkins();
+                    LLNotificationsUtil::add("AddSkinSuccess", LLSD().with("PACKAGE", name));
+                }
+            }
+            else
+            {
+                LLNotificationsUtil::add("AddSkinCantParseManifest", LLSD().with("PACKAGE", package));
+            }
+        }
+        else
+        {
+            LLNotificationsUtil::add("AddSkinNoManifest", LLSD().with("PACKAGE", package));
+        }
+    }
 }
 
 void LLFloaterPreference::onRemoveSkin()
 {
-	LLScrollListCtrl* skin_list = findChild<LLScrollListCtrl>("skin_list");
-	if (skin_list)
-	{
-		LLSD args;
-		args["SKIN"] = skin_list->getSelectedValue().asString();
-		LLNotificationsUtil::add("ConfirmRemoveSkin", args, args,
-								 boost::bind(&LLFloaterPreference::callbackRemoveSkin, this, _1, _2));
-	}
+    LLScrollListCtrl* skin_list = findChild<LLScrollListCtrl>("skin_list");
+    if (skin_list)
+    {
+        LLSD args;
+        args["SKIN"] = skin_list->getSelectedValue().asString();
+        LLNotificationsUtil::add("ConfirmRemoveSkin", args, args,
+                                 boost::bind(&LLFloaterPreference::callbackRemoveSkin, this, _1, _2));
+    }
 }
 
 void LLFloaterPreference::callbackRemoveSkin(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option == 0) // YES
-	{
-		const std::string& skin = notification["payload"]["SKIN"].asString();
-		std::string dir = gDirUtilp->add(gDirUtilp->getOSUserAppDir(), "skins");
-		dir = gDirUtilp->add(dir, skin);
-		if (gDirUtilp->deleteDirAndContents(dir) > 0)
-		{
-			skinmap_t::iterator iter = mUserSkins.find(skin);
-			if (iter != mUserSkins.end())
-				mUserSkins.erase(iter);
-			// If we just deleted the current skin, reset to default. It might not even be a good
-			// idea to allow this, but we'll see!
-			if (gSavedSettings.getString("SkinCurrent") == skin)
-			{
-				gSavedSettings.setString("SkinCurrent", DEFAULT_SKIN);
-			}
-			LLNotificationsUtil::add("RemoveSkinSuccess", LLSD().with("SKIN", skin));
-		}
-		else
-		{
-			LLNotificationsUtil::add("RemoveSkinFailure", LLSD().with("SKIN", skin));
-		}
-		reloadSkinList();
-	}
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option == 0) // YES
+    {
+        const std::string& skin = notification["payload"]["SKIN"].asString();
+        std::string dir = gDirUtilp->add(gDirUtilp->getOSUserAppDir(), "skins");
+        dir = gDirUtilp->add(dir, skin);
+        if (gDirUtilp->deleteDirAndContents(dir) > 0)
+        {
+            skinmap_t::iterator iter = mUserSkins.find(skin);
+            if (iter != mUserSkins.end())
+                mUserSkins.erase(iter);
+            // If we just deleted the current skin, reset to default. It might not even be a good
+            // idea to allow this, but we'll see!
+            if (gSavedSettings.getString("SkinCurrent") == skin)
+            {
+                gSavedSettings.setString("SkinCurrent", DEFAULT_SKIN);
+            }
+            LLNotificationsUtil::add("RemoveSkinSuccess", LLSD().with("SKIN", skin));
+        }
+        else
+        {
+            LLNotificationsUtil::add("RemoveSkinFailure", LLSD().with("SKIN", skin));
+        }
+        reloadSkinList();
+    }
 }
 
 void LLFloaterPreference::callbackApplySkin(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	switch (option)
-	{
-		case 0:	// Yes
-			gSavedSettings.setBOOL("ResetUserColorsOnLogout", TRUE);
-			break;
-		case 1:	// No
-			gSavedSettings.setBOOL("ResetUserColorsOnLogout", FALSE);
-			break;
-		case 2:	// Cancel
-			gSavedSettings.setString("SkinCurrent", sSkin);
-			reloadSkinList();
-			break;
-		default:
-			LL_WARNS() << "Unhandled option! How could this be?" << LL_ENDL;
-			break;
-	}
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    switch (option)
+    {
+        case 0: // Yes
+            gSavedSettings.setBOOL("ResetUserColorsOnLogout", TRUE);
+            break;
+        case 1: // No
+            gSavedSettings.setBOOL("ResetUserColorsOnLogout", FALSE);
+            break;
+        case 2: // Cancel
+            gSavedSettings.setString("SkinCurrent", sSkin);
+            reloadSkinList();
+            break;
+        default:
+            LL_WARNS() << "Unhandled option! How could this be?" << LL_ENDL;
+            break;
+    }
 }
 
 void LLFloaterPreference::onApplySkin()
 {
-	LLScrollListCtrl* skin_list = findChild<LLScrollListCtrl>("skin_list");
-	if (skin_list)
-	{
-		gSavedSettings.setString("SkinCurrent", skin_list->getSelectedValue().asString());
-		reloadSkinList();
-	}
-	if (sSkin != gSavedSettings.getString("SkinCurrent"))
-	{
-		LLNotificationsUtil::add("ChangeSkin", LLSD(), LLSD(),
-								 boost::bind(&LLFloaterPreference::callbackApplySkin, this, _1, _2));
-	}
+    LLScrollListCtrl* skin_list = findChild<LLScrollListCtrl>("skin_list");
+    if (skin_list)
+    {
+        gSavedSettings.setString("SkinCurrent", skin_list->getSelectedValue().asString());
+        reloadSkinList();
+    }
+    if (sSkin != gSavedSettings.getString("SkinCurrent"))
+    {
+        LLNotificationsUtil::add("ChangeSkin", LLSD(), LLSD(),
+                                 boost::bind(&LLFloaterPreference::callbackApplySkin, this, _1, _2));
+    }
 }
 
 void LLFloaterPreference::onSelectSkin(const LLSD& data)
 {
-	bool userskin = false;
-	skinmap_t::iterator iter = mUserSkins.find(data.asString());
-	if (iter != mUserSkins.end())
-	{
-		refreshSkinInfo(iter->second);
-		userskin = (iter->second.mType == USER_SKIN);
-	}
-	getChild<LLUICtrl>("remove_skin")->setEnabled(userskin);
+    bool userskin = false;
+    skinmap_t::iterator iter = mUserSkins.find(data.asString());
+    if (iter != mUserSkins.end())
+    {
+        refreshSkinInfo(iter->second);
+        userskin = (iter->second.mType == USER_SKIN);
+    }
+    getChild<LLUICtrl>("remove_skin")->setEnabled(userskin);
 }
 
 void LLFloaterPreference::refreshSkinInfo(const skin_t& skin)
 {
-	getChild<LLTextBase>("skin_name")->setText(skin.mName);
-	getChild<LLTextBase>("skin_author")->setText(skin.mAuthor);
-	getChild<LLTextBase>("skin_homepage")->setText(skin.mUrl);
-	getChild<LLTextBase>("skin_date")->setText(skin.mDate.toHTTPDateString("%A, %d %b %Y"));
-	getChild<LLTextBase>("skin_compatibility")->setText(skin.mCompatVer);
-	getChild<LLTextBase>("skin_notes")->setText(skin.mNotes);
+    getChild<LLTextBase>("skin_name")->setText(skin.mName);
+    getChild<LLTextBase>("skin_author")->setText(skin.mAuthor);
+    getChild<LLTextBase>("skin_homepage")->setText(skin.mUrl);
+    getChild<LLTextBase>("skin_date")->setText(skin.mDate.toHTTPDateString("%A, %d %b %Y"));
+    getChild<LLTextBase>("skin_compatibility")->setText(skin.mCompatVer);
+    getChild<LLTextBase>("skin_notes")->setText(skin.mNotes);
 }
 
 LLFloaterPreference::~LLFloaterPreference()
 {
 #if !LL_HAVOK
-	if (mGridListChangedConnection.connected())
-		mGridListChangedConnection.disconnect();
+    if (mGridListChangedConnection.connected())
+        mGridListChangedConnection.disconnect();
 #endif
-	LLAvatarPropertiesProcessor::getInstance()->removeObserver(LLUUID::null, this);
-	LLConversationLog::instance().removeObserver(this);
+    LLAvatarPropertiesProcessor::getInstance()->removeObserver(LLUUID::null, this);
+    LLConversationLog::instance().removeObserver(this);
     mComplexityChangedSignal.disconnect();
-	mDnDModeConnection.disconnect();
-	mRejectTeleportConnection.disconnect();
+    mDnDModeConnection.disconnect();
+    mRejectTeleportConnection.disconnect();
 }
 
 void LLFloaterPreference::draw()
 {
-	BOOL has_first_selected = (getChildRef<LLScrollListCtrl>("disabled_popups").getFirstSelected()!=NULL);
-	gSavedSettings.setBOOL("FirstSelectedDisabledPopups", has_first_selected);
-	
-	has_first_selected = (getChildRef<LLScrollListCtrl>("enabled_popups").getFirstSelected()!=NULL);
-	gSavedSettings.setBOOL("FirstSelectedEnabledPopups", has_first_selected);
-	
-	LLFloater::draw();
+    BOOL has_first_selected = (getChildRef<LLScrollListCtrl>("disabled_popups").getFirstSelected()!=NULL);
+    gSavedSettings.setBOOL("FirstSelectedDisabledPopups", has_first_selected);
+
+    has_first_selected = (getChildRef<LLScrollListCtrl>("enabled_popups").getFirstSelected()!=NULL);
+    gSavedSettings.setBOOL("FirstSelectedEnabledPopups", has_first_selected);
+
+    LLFloater::draw();
 }
 
 void LLFloaterPreference::saveSettings()
 {
-	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
-	child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
-	child_list_t::const_iterator end = tabcontainer->getChildList()->end();
-	for ( ; iter != end; ++iter)
-	{
-		LLView* view = *iter;
-		LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
-		if (panel)
-			panel->saveSettings();
-	}
+    LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
+    child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
+    child_list_t::const_iterator end = tabcontainer->getChildList()->end();
+    for ( ; iter != end; ++iter)
+    {
+        LLView* view = *iter;
+        LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
+        if (panel)
+            panel->saveSettings();
+    }
     saveIgnoredNotifications();
-}	
+}
 
 void LLFloaterPreference::apply()
 {
-	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
-	if (sSkin != gSavedSettings.getString("SkinCurrent"))
-	{
-		sSkin = gSavedSettings.getString("SkinCurrent");
-	}
-	// Call apply() on all panels that derive from LLPanelPreference
-	for (child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
-		 iter != tabcontainer->getChildList()->end(); ++iter)
-	{
-		LLView* view = *iter;
-		LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
-		if (panel)
-			panel->apply();
-	}
-	
-	gViewerWindow->requestResolutionUpdate(); // for UIScaleFactor
-
-	LLSliderCtrl* fov_slider = getChild<LLSliderCtrl>("camera_fov");
-	fov_slider->setMinValue(LLViewerCamera::getInstance()->getMinView());
-	fov_slider->setMaxValue(LLViewerCamera::getInstance()->getMaxView());
-	
-	std::string cache_location = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "");
-	setCacheLocation(cache_location);
-	
-	if (hasChild("web_proxy_enabled", TRUE) &&hasChild("web_proxy_editor", TRUE) && hasChild("web_proxy_port", TRUE))
-	{
-		bool proxy_enable = getChild<LLUICtrl>("web_proxy_enabled")->getValue();
-		std::string proxy_address = getChild<LLUICtrl>("web_proxy_editor")->getValue();
-		int proxy_port = getChild<LLUICtrl>("web_proxy_port")->getValue();
-		LLViewerMedia::getInstance()->setProxyConfig(proxy_enable, proxy_address, proxy_port);
-	}
-	
-	if (mGotPersonalInfo)
-	{ 
-		bool new_im_via_email = getChild<LLUICtrl>("send_im_to_email")->getValue().asBoolean();
-		bool new_hide_online = getChild<LLUICtrl>("online_visibility")->getValue().asBoolean();		
-	
-		if ((!LLGridManager::instance().isInSecondlife() && (new_im_via_email != mOriginalIMViaEmail))
-			||(new_hide_online != mOriginalHideOnlineStatus))
-		{
-			// This hack is because we are representing several different 	 
-			// possible strings with a single checkbox. Since most users 	 
-			// can only select between 2 values, we represent it as a 	 
-			// checkbox. This breaks down a little bit for liaisons, but 	 
-			// works out in the end. 	 
-			if (new_hide_online != mOriginalHideOnlineStatus)
-			{
-				if (new_hide_online) mDirectoryVisibility = VISIBILITY_HIDDEN;
-				else mDirectoryVisibility = VISIBILITY_DEFAULT;
-			 //Update showonline value, otherwise multiple applys won't work
-				mOriginalHideOnlineStatus = new_hide_online;
-			}
-			gAgent.sendAgentUpdateUserInfo(new_im_via_email,mDirectoryVisibility);
-		}
-	}
-
-	saveAvatarProperties();
+    LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
+    if (sSkin != gSavedSettings.getString("SkinCurrent"))
+    {
+        sSkin = gSavedSettings.getString("SkinCurrent");
+    }
+    // Call apply() on all panels that derive from LLPanelPreference
+    for (child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
+         iter != tabcontainer->getChildList()->end(); ++iter)
+    {
+        LLView* view = *iter;
+        LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
+        if (panel)
+            panel->apply();
+    }
+
+    gViewerWindow->requestResolutionUpdate(); // for UIScaleFactor
+
+    LLSliderCtrl* fov_slider = getChild<LLSliderCtrl>("camera_fov");
+    fov_slider->setMinValue(LLViewerCamera::getInstance()->getMinView());
+    fov_slider->setMaxValue(LLViewerCamera::getInstance()->getMaxView());
+
+    std::string cache_location = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, "");
+    setCacheLocation(cache_location);
+
+    if (hasChild("web_proxy_enabled", TRUE) &&hasChild("web_proxy_editor", TRUE) && hasChild("web_proxy_port", TRUE))
+    {
+        bool proxy_enable = getChild<LLUICtrl>("web_proxy_enabled")->getValue();
+        std::string proxy_address = getChild<LLUICtrl>("web_proxy_editor")->getValue();
+        int proxy_port = getChild<LLUICtrl>("web_proxy_port")->getValue();
+        LLViewerMedia::getInstance()->setProxyConfig(proxy_enable, proxy_address, proxy_port);
+    }
+
+    if (mGotPersonalInfo)
+    {
+        bool new_im_via_email = getChild<LLUICtrl>("send_im_to_email")->getValue().asBoolean();
+        bool new_hide_online = getChild<LLUICtrl>("online_visibility")->getValue().asBoolean();
+
+        if ((!LLGridManager::instance().isInSecondlife() && (new_im_via_email != mOriginalIMViaEmail))
+            ||(new_hide_online != mOriginalHideOnlineStatus))
+        {
+            // This hack is because we are representing several different
+            // possible strings with a single checkbox. Since most users
+            // can only select between 2 values, we represent it as a
+            // checkbox. This breaks down a little bit for liaisons, but
+            // works out in the end.
+            if (new_hide_online != mOriginalHideOnlineStatus)
+            {
+                if (new_hide_online) mDirectoryVisibility = VISIBILITY_HIDDEN;
+                else mDirectoryVisibility = VISIBILITY_DEFAULT;
+             //Update showonline value, otherwise multiple applys won't work
+                mOriginalHideOnlineStatus = new_hide_online;
+            }
+            gAgent.sendAgentUpdateUserInfo(new_im_via_email,mDirectoryVisibility);
+        }
+    }
+
+    saveAvatarProperties();
 }
 
 void LLFloaterPreference::cancel()
 {
-	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
-	// Call cancel() on all panels that derive from LLPanelPreference
-	for (child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
-		iter != tabcontainer->getChildList()->end(); ++iter)
-	{
-		LLView* view = *iter;
-		LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
-		if (panel)
-			panel->cancel();
-	}
-	// hide joystick pref floater
-	LLFloaterReg::hideInstance("pref_joystick");
-
-	// hide translation settings floater
-	LLFloaterReg::hideInstance("prefs_translation");
-	
-	// hide autoreplace settings floater
-	LLFloaterReg::hideInstance("prefs_autoreplace");
-	
-	// hide spellchecker settings folder
-	LLFloaterReg::hideInstance("prefs_spellchecker");
-
-	// hide advanced graphics floater
-	LLFloaterReg::hideInstance("prefs_graphics_advanced");
-	
-	// reverts any changes to current skin
-	gSavedSettings.setString("SkinCurrent", sSkin);
-
-	updateClickActionViews();
-
-	LLFloaterPreferenceProxy * advanced_proxy_settings = LLFloaterReg::findTypedInstance<LLFloaterPreferenceProxy>("prefs_proxy");
-	if (advanced_proxy_settings)
-	{
-		advanced_proxy_settings->cancel();
-	}
-	//Need to reload the navmesh if the pathing console is up
-	LLHandle<LLFloaterPathfindingConsole> pathfindingConsoleHandle = LLFloaterPathfindingConsole::getInstanceHandle();
-	if ( !pathfindingConsoleHandle.isDead() )
-	{
-		LLFloaterPathfindingConsole* pPathfindingConsole = pathfindingConsoleHandle.get();
-		pPathfindingConsole->onRegionBoundaryCross();
-	}
-
-	if (!mSavedGraphicsPreset.empty())
-	{
-		gSavedSettings.setString("PresetGraphicActive", mSavedGraphicsPreset);
-		LLPresetsManager::getInstance()->triggerChangeSignal();
-	}
+    LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
+    // Call cancel() on all panels that derive from LLPanelPreference
+    for (child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
+        iter != tabcontainer->getChildList()->end(); ++iter)
+    {
+        LLView* view = *iter;
+        LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
+        if (panel)
+            panel->cancel();
+    }
+    // hide joystick pref floater
+    LLFloaterReg::hideInstance("pref_joystick");
+
+    // hide translation settings floater
+    LLFloaterReg::hideInstance("prefs_translation");
+
+    // hide autoreplace settings floater
+    LLFloaterReg::hideInstance("prefs_autoreplace");
+
+    // hide spellchecker settings folder
+    LLFloaterReg::hideInstance("prefs_spellchecker");
+
+    // hide advanced graphics floater
+    LLFloaterReg::hideInstance("prefs_graphics_advanced");
+
+    // reverts any changes to current skin
+    gSavedSettings.setString("SkinCurrent", sSkin);
+
+    updateClickActionViews();
+
+    LLFloaterPreferenceProxy * advanced_proxy_settings = LLFloaterReg::findTypedInstance<LLFloaterPreferenceProxy>("prefs_proxy");
+    if (advanced_proxy_settings)
+    {
+        advanced_proxy_settings->cancel();
+    }
+    //Need to reload the navmesh if the pathing console is up
+    LLHandle<LLFloaterPathfindingConsole> pathfindingConsoleHandle = LLFloaterPathfindingConsole::getInstanceHandle();
+    if ( !pathfindingConsoleHandle.isDead() )
+    {
+        LLFloaterPathfindingConsole* pPathfindingConsole = pathfindingConsoleHandle.get();
+        pPathfindingConsole->onRegionBoundaryCross();
+    }
+
+    if (!mSavedGraphicsPreset.empty())
+    {
+        gSavedSettings.setString("PresetGraphicActive", mSavedGraphicsPreset);
+        LLPresetsManager::getInstance()->triggerChangeSignal();
+    }
 
     restoreIgnoredNotifications();
 }
 
 void LLFloaterPreference::onOpen(const LLSD& key)
 {
-	// this variable and if that follows it are used to properly handle do not disturb mode response message
-	// if user is logged in and we haven't initialized do not disturb mode response yet, do it
-	if (!mDnDInit && LLStartUp::getStartupState() == STATE_STARTED)
-	{
-		// Special approach is used for do not disturb response localization, because "DoNotDisturbModeResponse" is
-		// in non-localizable xml, and also because it may be changed by user and in this case it shouldn't be localized.
-		// To keep track of whether do not disturb response is default or changed by user additional setting DoNotDisturbResponseChanged
-		// was added into per account settings.
-
-		// initialization should happen once,so setting variable to TRUE
-		mDnDInit = true;
-		// this connection is needed to properly set "DoNotDisturbResponseChanged" setting when user makes changes in
-		// do not disturb response message.
-		mDnDModeConnection = gSavedPerAccountSettings.getControl("DoNotDisturbModeResponse")->getSignal()->connect(boost::bind(&LLFloaterPreference::onDoNotDisturbResponseChanged, this));
-
-		mRejectTeleportConnection =  gSavedPerAccountSettings.getControl("ALRejectTeleportOffersResponse")->getSignal()->connect(boost::bind(&LLFloaterPreference::onRejectTeleportOffersResponseChanged, this));
-
-	}
-	gAgent.sendAgentUserInfoRequest();
-
-	/////////////////////////// From LLPanelGeneral //////////////////////////
-	// if we have no agent, we can't let them choose anything
-	// if we have an agent, then we only let them choose if they have a choice
-	bool can_choose_maturity =
-		gAgent.getID().notNull() &&
-		(gAgent.isMature() || gAgent.isGodlike());
-	
-	LLComboBox* maturity_combo = getChild<LLComboBox>("maturity_desired_combobox");
+    // this variable and if that follows it are used to properly handle do not disturb mode response message
+    // if user is logged in and we haven't initialized do not disturb mode response yet, do it
+    if (!mDnDInit && LLStartUp::getStartupState() == STATE_STARTED)
+    {
+        // Special approach is used for do not disturb response localization, because "DoNotDisturbModeResponse" is
+        // in non-localizable xml, and also because it may be changed by user and in this case it shouldn't be localized.
+        // To keep track of whether do not disturb response is default or changed by user additional setting DoNotDisturbResponseChanged
+        // was added into per account settings.
+
+        // initialization should happen once,so setting variable to TRUE
+        mDnDInit = true;
+        // this connection is needed to properly set "DoNotDisturbResponseChanged" setting when user makes changes in
+        // do not disturb response message.
+        mDnDModeConnection = gSavedPerAccountSettings.getControl("DoNotDisturbModeResponse")->getSignal()->connect(boost::bind(&LLFloaterPreference::onDoNotDisturbResponseChanged, this));
+
+        mRejectTeleportConnection =  gSavedPerAccountSettings.getControl("ALRejectTeleportOffersResponse")->getSignal()->connect(boost::bind(&LLFloaterPreference::onRejectTeleportOffersResponseChanged, this));
+
+    }
+    gAgent.sendAgentUserInfoRequest();
+
+    /////////////////////////// From LLPanelGeneral //////////////////////////
+    // if we have no agent, we can't let them choose anything
+    // if we have an agent, then we only let them choose if they have a choice
+    bool can_choose_maturity =
+        gAgent.getID().notNull() &&
+        (gAgent.isMature() || gAgent.isGodlike());
+
+    LLComboBox* maturity_combo = getChild<LLComboBox>("maturity_desired_combobox");
     LLAvatarPropertiesProcessor::getInstance()->sendAvatarLegacyPropertiesRequest( gAgent.getID() );
-	if (can_choose_maturity)
-	{		
-		// if they're not adult or a god, they shouldn't see the adult selection, so delete it
-		if (!gAgent.isAdult() && !gAgent.isGodlikeWithoutAdminMenuFakery())
-		{
-			// we're going to remove the adult entry from the combo
-			LLScrollListCtrl* maturity_list = maturity_combo->findChild<LLScrollListCtrl>("ComboBox");
-			if (maturity_list)
-			{
-				maturity_list->deleteItems(LLSD(SIM_ACCESS_ADULT));
-			}
-		}
-		getChildView("maturity_desired_combobox")->setEnabled( true);
-		getChildView("maturity_desired_textbox")->setVisible( false);
-	}
-	else
-	{
-		getChild<LLUICtrl>("maturity_desired_textbox")->setValue(maturity_combo->getSelectedItemLabel());
-		getChildView("maturity_desired_combobox")->setEnabled( false);
-	}
-
-	// Forget previous language changes.
-	mLanguageChanged = false;
-
-	// Display selected maturity icons.
-	onChangeMaturity();
-
-	onChangeModelFolder();
+    if (can_choose_maturity)
+    {
+        // if they're not adult or a god, they shouldn't see the adult selection, so delete it
+        if (!gAgent.isAdult() && !gAgent.isGodlikeWithoutAdminMenuFakery())
+        {
+            // we're going to remove the adult entry from the combo
+            LLScrollListCtrl* maturity_list = maturity_combo->findChild<LLScrollListCtrl>("ComboBox");
+            if (maturity_list)
+            {
+                maturity_list->deleteItems(LLSD(SIM_ACCESS_ADULT));
+            }
+        }
+        getChildView("maturity_desired_combobox")->setEnabled( true);
+        getChildView("maturity_desired_textbox")->setVisible( false);
+    }
+    else
+    {
+        getChild<LLUICtrl>("maturity_desired_textbox")->setValue(maturity_combo->getSelectedItemLabel());
+        getChildView("maturity_desired_combobox")->setEnabled( false);
+    }
+
+    // Forget previous language changes.
+    mLanguageChanged = false;
+
+    // Display selected maturity icons.
+    onChangeMaturity();
+
+    onChangeModelFolder();
     onChangePBRFolder();
-	onChangeTextureFolder();
-	onChangeSoundFolder();
-	onChangeAnimationFolder();
-
-	// Load (double-)click to walk/teleport settings.
-	updateClickActionViews();
-	
-	// Enabled/disabled popups, might have been changed by user actions
-	// while preferences floater was closed.
-	buildPopupLists();
-
-
-	//get the options that were checked
-	onNotificationsChange("FriendIMOptions");
-	onNotificationsChange("NonFriendIMOptions");
-	onNotificationsChange("ConferenceIMOptions");
-	onNotificationsChange("GroupChatOptions");
-	onNotificationsChange("NearbyChatOptions");
-	onNotificationsChange("ObjectIMOptions");
-
-	LLPanelLogin::setAlwaysRefresh(true);
-	refresh();
-	
-	// Make sure the current state of prefs are saved away when
-	// when the floater is opened.  That will make cancel do its
-	// job
-	saveSettings();
-
-	// Make sure there is a default preference file
-	LLPresetsManager::getInstance()->createMissingDefault(PRESETS_CAMERA);
-	LLPresetsManager::getInstance()->createMissingDefault(PRESETS_GRAPHIC);
-
-	bool started = (LLStartUp::getStartupState() == STATE_STARTED);
-
-	LLButton* exceptions_btn = findChild<LLButton>("RenderExceptionsButton");
+    onChangeTextureFolder();
+    onChangeSoundFolder();
+    onChangeAnimationFolder();
+
+    // Load (double-)click to walk/teleport settings.
+    updateClickActionViews();
+
+    // Enabled/disabled popups, might have been changed by user actions
+    // while preferences floater was closed.
+    buildPopupLists();
+
+
+    //get the options that were checked
+    onNotificationsChange("FriendIMOptions");
+    onNotificationsChange("NonFriendIMOptions");
+    onNotificationsChange("ConferenceIMOptions");
+    onNotificationsChange("GroupChatOptions");
+    onNotificationsChange("NearbyChatOptions");
+    onNotificationsChange("ObjectIMOptions");
+
+    LLPanelLogin::setAlwaysRefresh(true);
+    refresh();
+
+    // Make sure the current state of prefs are saved away when
+    // when the floater is opened.  That will make cancel do its
+    // job
+    saveSettings();
+
+    // Make sure there is a default preference file
+    LLPresetsManager::getInstance()->createMissingDefault(PRESETS_CAMERA);
+    LLPresetsManager::getInstance()->createMissingDefault(PRESETS_GRAPHIC);
+
+    bool started = (LLStartUp::getStartupState() == STATE_STARTED);
+
+    LLButton* exceptions_btn = findChild<LLButton>("RenderExceptionsButton");
     LLButton* auto_adjustments_btn = findChild<LLButton>("AutoAdjustmentsButton");
-	if (exceptions_btn && auto_adjustments_btn)
-	{
-		exceptions_btn->setEnabled(started);
+    if (exceptions_btn && auto_adjustments_btn)
+    {
+        exceptions_btn->setEnabled(started);
         auto_adjustments_btn->setEnabled(started);
-	}
+    }
 
     collectSearchableItems();
-	if (!mFilterEdit->getText().empty())
-	{
-		mFilterEdit->setText(LLStringExplicit(""));
-		onUpdateFilterTerm(true);
-	}
+    if (!mFilterEdit->getText().empty())
+    {
+        mFilterEdit->setText(LLStringExplicit(""));
+        onUpdateFilterTerm(true);
+    }
 }
 
 void LLFloaterPreference::onRenderOptionEnable()
 {
-	refreshEnabledGraphics();
+    refreshEnabledGraphics();
 }
 
 void LLFloaterPreference::onAvatarImpostorsEnable()
 {
-	refreshEnabledGraphics();
+    refreshEnabledGraphics();
 }
 
 //static
 void LLFloaterPreference::initDoNotDisturbResponse()
-	{
-		if (!gSavedPerAccountSettings.getBOOL("DoNotDisturbResponseChanged"))
-		{
-			//LLTrans::getString("DoNotDisturbModeResponseDefault") is used here for localization (EXT-5885)
-			gSavedPerAccountSettings.setString("DoNotDisturbModeResponse", LLTrans::getString("DoNotDisturbModeResponseDefault"));
-		}
-
-		if (!gSavedPerAccountSettings.getBOOL("ALRejectFriendshipRequestsChanged"))
-		{
-			gSavedPerAccountSettings.setString("ALRejectFriendshipRequestsResponse", LLTrans::getString("RejectFriendshipRequestsResponseDefault"));
-		}
-	}
-
-//static 
+    {
+        if (!gSavedPerAccountSettings.getBOOL("DoNotDisturbResponseChanged"))
+        {
+            //LLTrans::getString("DoNotDisturbModeResponseDefault") is used here for localization (EXT-5885)
+            gSavedPerAccountSettings.setString("DoNotDisturbModeResponse", LLTrans::getString("DoNotDisturbModeResponseDefault"));
+        }
+
+        if (!gSavedPerAccountSettings.getBOOL("ALRejectFriendshipRequestsChanged"))
+        {
+            gSavedPerAccountSettings.setString("ALRejectFriendshipRequestsResponse", LLTrans::getString("RejectFriendshipRequestsResponseDefault"));
+        }
+    }
+
+//static
 void LLFloaterPreference::updateShowFavoritesCheckbox(bool val)
 {
-	LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
-	if (instance)
-	{
-		instance->getChild<LLUICtrl>("favorites_on_login_check")->setValue(val);
-	}	
+    LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
+    if (instance)
+    {
+        instance->getChild<LLUICtrl>("favorites_on_login_check")->setValue(val);
+    }
 }
 
 void LLFloaterPreference::setHardwareDefaults()
 {
-	std::string preset_graphic_active = gSavedSettings.getString("PresetGraphicActive");
-	if (!preset_graphic_active.empty())
-	{
-		saveGraphicsPreset(preset_graphic_active);
-		saveSettings(); // save here to be able to return to the previous preset by Cancel
-	}
+    std::string preset_graphic_active = gSavedSettings.getString("PresetGraphicActive");
+    if (!preset_graphic_active.empty())
+    {
+        saveGraphicsPreset(preset_graphic_active);
+        saveSettings(); // save here to be able to return to the previous preset by Cancel
+    }
     setRecommendedSettings();
 }
 
@@ -1255,25 +1255,25 @@ void LLFloaterPreference::setRecommendedSettings()
     resetAutotuneSettings();
     gSavedSettings.getControl("RenderVSyncEnable")->resetToDefault(true);
 
-	LLFeatureManager::getInstance()->applyRecommendedSettings();
+    LLFeatureManager::getInstance()->applyRecommendedSettings();
 
-	// reset indirects before refresh because we may have changed what they control
-	LLAvatarComplexityControls::setIndirectControls(); 
+    // reset indirects before refresh because we may have changed what they control
+    LLAvatarComplexityControls::setIndirectControls();
 
-	refreshEnabledGraphics();
+    refreshEnabledGraphics();
 
-	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
-	child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
-	child_list_t::const_iterator end = tabcontainer->getChildList()->end();
-	for ( ; iter != end; ++iter)
-	{
-		LLView* view = *iter;
-		LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
-		if (panel)
-		{
-			panel->setHardwareDefaults();
-		}
-	}
+    LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
+    child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
+    child_list_t::const_iterator end = tabcontainer->getChildList()->end();
+    for ( ; iter != end; ++iter)
+    {
+        LLView* view = *iter;
+        LLPanelPreference* panel = dynamic_cast<LLPanelPreference*>(view);
+        if (panel)
+        {
+            panel->setHardwareDefaults();
+        }
+    }
 }
 
 void LLFloaterPreference::resetAutotuneSettings()
@@ -1300,435 +1300,435 @@ void LLFloaterPreference::resetAutotuneSettings()
 
 void LLFloaterPreference::getControlNames(std::vector<std::string>& names)
 {
-	LLView* view = findChild<LLView>("display");
-	LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
-	if (view && advanced)
-	{
-		std::list<LLView*> stack;
-		stack.push_back(view);
-		stack.push_back(advanced);
-		while(!stack.empty())
-		{
-			// Process view on top of the stack
-			LLView* curview = stack.front();
-			stack.pop_front();
-
-			LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
-			if (ctrl)
-			{
-				LLControlVariable* control = ctrl->getControlVariable();
-				if (control)
-				{
-					std::string control_name = control->getName();
-					if (std::find(names.begin(), names.end(), control_name) == names.end())
-					{
-						names.push_back(control_name);
-					}
-				}
-			}
-
-			for (child_list_t::const_iterator iter = curview->getChildList()->begin();
-				iter != curview->getChildList()->end(); ++iter)
-			{
-				stack.push_back(*iter);
-			}
-		}
-	}
+    LLView* view = findChild<LLView>("display");
+    LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
+    if (view && advanced)
+    {
+        std::list<LLView*> stack;
+        stack.push_back(view);
+        stack.push_back(advanced);
+        while(!stack.empty())
+        {
+            // Process view on top of the stack
+            LLView* curview = stack.front();
+            stack.pop_front();
+
+            LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
+            if (ctrl)
+            {
+                LLControlVariable* control = ctrl->getControlVariable();
+                if (control)
+                {
+                    std::string control_name = control->getName();
+                    if (std::find(names.begin(), names.end(), control_name) == names.end())
+                    {
+                        names.push_back(control_name);
+                    }
+                }
+            }
+
+            for (child_list_t::const_iterator iter = curview->getChildList()->begin();
+                iter != curview->getChildList()->end(); ++iter)
+            {
+                stack.push_back(*iter);
+            }
+        }
+    }
 }
 
 //virtual
 void LLFloaterPreference::onClose(bool app_quitting)
 {
-	gSavedSettings.setS32("LastPrefTab", getChild<LLTabContainer>("pref core")->getCurrentPanelIndex());
-	LLPanelLogin::setAlwaysRefresh(false);
-	if (!app_quitting)
-	{
-		cancel();
-	}
+    gSavedSettings.setS32("LastPrefTab", getChild<LLTabContainer>("pref core")->getCurrentPanelIndex());
+    LLPanelLogin::setAlwaysRefresh(false);
+    if (!app_quitting)
+    {
+        cancel();
+    }
 }
 
-// static 
+// static
 void LLFloaterPreference::onBtnOK(const LLSD& userdata)
 {
-	// commit any outstanding text entry
-	if (hasFocus())
-	{
-		LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
-		if (cur_focus && cur_focus->acceptsTextInput())
-		{
-			cur_focus->onCommit();
-		}
-	}
-
-	if (canClose())
-	{
-		saveSettings();
-		apply();
-		
-		if (userdata.asString() == "closeadvanced")
-		{
-			LLFloaterReg::hideInstance("prefs_graphics_advanced");
-		}
-		else
-		{
-			closeFloater(false);
-		}
-
-		//Conversation transcript and log path changed so reload conversations based on new location
-		if(mPriorInstantMessageLogPath.length())
-		{
-			if(moveTranscriptsAndLog())
-			{
-				//When floaters are empty but have a chat history files, reload chat history into them
-				LLFloaterIMSessionTab::reloadEmptyFloaters();
-			}
-			//Couldn't move files so restore the old path and show a notification
-			else
-			{
-				gSavedPerAccountSettings.setString("InstantMessageLogPath", mPriorInstantMessageLogPath);
-				LLNotificationsUtil::add("PreferenceChatPathChanged");
-			}
-			mPriorInstantMessageLogPath.clear();
-		}
-
-		LLUIColorTable::instance().saveUserSettings();
-		gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
-		
-		//Only save once logged in and loaded per account settings
-		if(mGotPersonalInfo)
-		{
-			gSavedPerAccountSettings.saveToFile(gSavedSettings.getString("PerAccountSettingsFile"), TRUE);
-	}
-	}
-	else
-	{
-		// Show beep, pop up dialog, etc.
-		LL_INFOS("Preferences") << "Can't close preferences!" << LL_ENDL;
-	}
-
-	LLPanelLogin::updateLocationSelectorsVisibility();	
-	//Need to reload the navmesh if the pathing console is up
-	LLHandle<LLFloaterPathfindingConsole> pathfindingConsoleHandle = LLFloaterPathfindingConsole::getInstanceHandle();
-	if ( !pathfindingConsoleHandle.isDead() )
-	{
-		LLFloaterPathfindingConsole* pPathfindingConsole = pathfindingConsoleHandle.get();
-		pPathfindingConsole->onRegionBoundaryCross();
-	}
-}
-
-// static 
+    // commit any outstanding text entry
+    if (hasFocus())
+    {
+        LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
+        if (cur_focus && cur_focus->acceptsTextInput())
+        {
+            cur_focus->onCommit();
+        }
+    }
+
+    if (canClose())
+    {
+        saveSettings();
+        apply();
+
+        if (userdata.asString() == "closeadvanced")
+        {
+            LLFloaterReg::hideInstance("prefs_graphics_advanced");
+        }
+        else
+        {
+            closeFloater(false);
+        }
+
+        //Conversation transcript and log path changed so reload conversations based on new location
+        if(mPriorInstantMessageLogPath.length())
+        {
+            if(moveTranscriptsAndLog())
+            {
+                //When floaters are empty but have a chat history files, reload chat history into them
+                LLFloaterIMSessionTab::reloadEmptyFloaters();
+            }
+            //Couldn't move files so restore the old path and show a notification
+            else
+            {
+                gSavedPerAccountSettings.setString("InstantMessageLogPath", mPriorInstantMessageLogPath);
+                LLNotificationsUtil::add("PreferenceChatPathChanged");
+            }
+            mPriorInstantMessageLogPath.clear();
+        }
+
+        LLUIColorTable::instance().saveUserSettings();
+        gSavedSettings.saveToFile(gSavedSettings.getString("ClientSettingsFile"), TRUE);
+
+        //Only save once logged in and loaded per account settings
+        if(mGotPersonalInfo)
+        {
+            gSavedPerAccountSettings.saveToFile(gSavedSettings.getString("PerAccountSettingsFile"), TRUE);
+    }
+    }
+    else
+    {
+        // Show beep, pop up dialog, etc.
+        LL_INFOS("Preferences") << "Can't close preferences!" << LL_ENDL;
+    }
+
+    LLPanelLogin::updateLocationSelectorsVisibility();
+    //Need to reload the navmesh if the pathing console is up
+    LLHandle<LLFloaterPathfindingConsole> pathfindingConsoleHandle = LLFloaterPathfindingConsole::getInstanceHandle();
+    if ( !pathfindingConsoleHandle.isDead() )
+    {
+        LLFloaterPathfindingConsole* pPathfindingConsole = pathfindingConsoleHandle.get();
+        pPathfindingConsole->onRegionBoundaryCross();
+    }
+}
+
+// static
 void LLFloaterPreference::onBtnCancel(const LLSD& userdata)
 {
-	if (hasFocus())
-	{
-		LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
-		if (cur_focus && cur_focus->acceptsTextInput())
-		{
-			cur_focus->onCommit();
-		}
-		refresh();
-	}
-	cancel();
-
-	if (userdata.asString() == "closeadvanced")
-	{
-		LLFloaterReg::hideInstance("prefs_graphics_advanced");
-	}
-	else
-	{
-		closeFloater();
-	}
-}
-
-// static 
+    if (hasFocus())
+    {
+        LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
+        if (cur_focus && cur_focus->acceptsTextInput())
+        {
+            cur_focus->onCommit();
+        }
+        refresh();
+    }
+    cancel();
+
+    if (userdata.asString() == "closeadvanced")
+    {
+        LLFloaterReg::hideInstance("prefs_graphics_advanced");
+    }
+    else
+    {
+        closeFloater();
+    }
+}
+
+// static
 void LLFloaterPreference::updateUserInfo(const std::string& visibility, bool im_via_email, bool is_verified_email, const std::string& email)
 {
-	LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
-	if (instance)
-	{
+    LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
+    if (instance)
+    {
         instance->setPersonalInfo(visibility, im_via_email, is_verified_email, email);
-	}
+    }
 }
 
 void LLFloaterPreference::refreshEnabledGraphics()
 {
-	LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
-	if (instance)
-	{
-		instance->refresh();
-	}
+    LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
+    if (instance)
+    {
+        instance->refresh();
+    }
 
-	LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
-	if (advanced)
-	{
-		advanced->refresh();
-	}
+    LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
+    if (advanced)
+    {
+        advanced->refresh();
+    }
 }
 
 void LLFloaterPreference::onClickClearCache()
 {
-	LLFloaterReg::showInstance("clear_cache");
+    LLFloaterReg::showInstance("clear_cache");
 }
 
 void LLFloaterPreference::onClickBrowserClearCache()
 {
-	LLNotificationsUtil::add("ConfirmClearBrowserCache", LLSD(), LLSD(), callback_clear_browser_cache);
+    LLNotificationsUtil::add("ConfirmClearBrowserCache", LLSD(), LLSD(), callback_clear_browser_cache);
 }
 
 // Called when user changes language via the combobox.
 void LLFloaterPreference::onLanguageChange()
 {
-	// Let the user know that the change will only take effect after restart.
-	// Do it only once so that we're not too irritating.
-	if (!mLanguageChanged)
-	{
-		LLNotificationsUtil::add("ChangeLanguage");
-		mLanguageChanged = true;
-	}
+    // Let the user know that the change will only take effect after restart.
+    // Do it only once so that we're not too irritating.
+    if (!mLanguageChanged)
+    {
+        LLNotificationsUtil::add("ChangeLanguage");
+        mLanguageChanged = true;
+    }
 }
 
 void LLFloaterPreference::onNotificationsChange(const std::string& OptionName)
 {
-	mNotificationOptions[OptionName] = getChild<LLComboBox>(OptionName)->getSelectedItemLabel();
+    mNotificationOptions[OptionName] = getChild<LLComboBox>(OptionName)->getSelectedItemLabel();
 
-	bool show_notifications_alert = true;
-	for (notifications_map::iterator it_notification = mNotificationOptions.begin(); it_notification != mNotificationOptions.end(); it_notification++)
-	{
-		if(it_notification->second != "No action")
-		{
-			show_notifications_alert = false;
-			break;
-		}
-	}
+    bool show_notifications_alert = true;
+    for (notifications_map::iterator it_notification = mNotificationOptions.begin(); it_notification != mNotificationOptions.end(); it_notification++)
+    {
+        if(it_notification->second != "No action")
+        {
+            show_notifications_alert = false;
+            break;
+        }
+    }
 
-	getChild<LLTextBox>("notifications_alert")->setVisible(show_notifications_alert);
+    getChild<LLTextBox>("notifications_alert")->setVisible(show_notifications_alert);
 }
 
 void LLFloaterPreference::onNameTagOpacityChange(const LLSD& newvalue)
 {
-	LLColorSwatchCtrl* color_swatch = findChild<LLColorSwatchCtrl>("background");
-	if (color_swatch)
-	{
-		LLColor4 new_color = color_swatch->get();
-		color_swatch->set( new_color.setAlpha(newvalue.asReal()) );
-	}
+    LLColorSwatchCtrl* color_swatch = findChild<LLColorSwatchCtrl>("background");
+    if (color_swatch)
+    {
+        LLColor4 new_color = color_swatch->get();
+        color_swatch->set( new_color.setAlpha(newvalue.asReal()) );
+    }
 }
 
 void LLFloaterPreference::onClickSetCache()
 {
-	std::string cur_name(gSavedSettings.getString("CacheLocation"));
-//	std::string cur_top_folder(gDirUtilp->getBaseFileName(cur_name));
-	
-	std::string proposed_name(cur_name);
+    std::string cur_name(gSavedSettings.getString("CacheLocation"));
+//  std::string cur_top_folder(gDirUtilp->getBaseFileName(cur_name));
+
+    std::string proposed_name(cur_name);
 
-	(new LLDirPickerThread(boost::bind(&LLFloaterPreference::changeCachePath, this, _1, _2), proposed_name))->getFile();
+    (new LLDirPickerThread(boost::bind(&LLFloaterPreference::changeCachePath, this, _1, _2), proposed_name))->getFile();
 }
 
 void LLFloaterPreference::changeCachePath(const std::vector<std::string>& filenames, std::string proposed_name)
 {
-	std::string dir_name = filenames[0];
-	if (!dir_name.empty() && dir_name != proposed_name)
-	{
-		std::string new_top_folder(gDirUtilp->getBaseFileName(dir_name));
-		LLNotificationsUtil::add("CacheWillBeMoved");
-		gSavedSettings.setString("NewCacheLocation", dir_name);
-		gSavedSettings.setString("NewCacheLocationTopFolder", new_top_folder);
-	}
-	else
-	{
-		std::string cache_location = gDirUtilp->getCacheDir();
-		gSavedSettings.setString("CacheLocation", cache_location);
-		std::string top_folder(gDirUtilp->getBaseFileName(cache_location));
-		gSavedSettings.setString("CacheLocationTopFolder", top_folder);
-	}
+    std::string dir_name = filenames[0];
+    if (!dir_name.empty() && dir_name != proposed_name)
+    {
+        std::string new_top_folder(gDirUtilp->getBaseFileName(dir_name));
+        LLNotificationsUtil::add("CacheWillBeMoved");
+        gSavedSettings.setString("NewCacheLocation", dir_name);
+        gSavedSettings.setString("NewCacheLocationTopFolder", new_top_folder);
+    }
+    else
+    {
+        std::string cache_location = gDirUtilp->getCacheDir();
+        gSavedSettings.setString("CacheLocation", cache_location);
+        std::string top_folder(gDirUtilp->getBaseFileName(cache_location));
+        gSavedSettings.setString("CacheLocationTopFolder", top_folder);
+    }
 }
 
 void LLFloaterPreference::onClickResetCache()
 {
-	if (gDirUtilp->getCacheDir(false) == gDirUtilp->getCacheDir(true))
-	{
-		// The cache location was already the default.
-		return;
-	}
-	gSavedSettings.setString("NewCacheLocation", "");
-	gSavedSettings.setString("NewCacheLocationTopFolder", "");
-	LLNotificationsUtil::add("CacheWillBeMoved");
-	std::string cache_location = gDirUtilp->getCacheDir(false);
-	gSavedSettings.setString("CacheLocation", cache_location);
-	std::string top_folder(gDirUtilp->getBaseFileName(cache_location));
-	gSavedSettings.setString("CacheLocationTopFolder", top_folder);
+    if (gDirUtilp->getCacheDir(false) == gDirUtilp->getCacheDir(true))
+    {
+        // The cache location was already the default.
+        return;
+    }
+    gSavedSettings.setString("NewCacheLocation", "");
+    gSavedSettings.setString("NewCacheLocationTopFolder", "");
+    LLNotificationsUtil::add("CacheWillBeMoved");
+    std::string cache_location = gDirUtilp->getCacheDir(false);
+    gSavedSettings.setString("CacheLocation", cache_location);
+    std::string top_folder(gDirUtilp->getBaseFileName(cache_location));
+    gSavedSettings.setString("CacheLocationTopFolder", top_folder);
 }
 
 void LLFloaterPreference::buildPopupLists()
 {
-	LLScrollListCtrl& disabled_popups =
-		getChildRef<LLScrollListCtrl>("disabled_popups");
-	LLScrollListCtrl& enabled_popups =
-		getChildRef<LLScrollListCtrl>("enabled_popups");
-	
-	disabled_popups.deleteAllItems();
-	enabled_popups.deleteAllItems();
-	
-	for (LLNotifications::TemplateMap::const_iterator iter = LLNotifications::instance().templatesBegin();
-		 iter != LLNotifications::instance().templatesEnd();
-		 ++iter)
-	{
-		LLNotificationTemplatePtr templatep = iter->second;
-		LLNotificationFormPtr formp = templatep->mForm;
-		
-		LLNotificationForm::EIgnoreType ignore = formp->getIgnoreType();
-		if (ignore <= LLNotificationForm::IGNORE_NO)
-			continue;
-		
-		LLSD row;
-		row["columns"][0]["value"] = formp->getIgnoreMessage();
-		row["columns"][0]["font"] = "SANSSERIF_SMALL";
-		row["columns"][0]["width"] = 400;
-		
-		LLScrollListItem* item = NULL;
-		
-		bool show_popup = !formp->getIgnored();
-		if (!show_popup)
-		{
-			if (ignore == LLNotificationForm::IGNORE_WITH_LAST_RESPONSE)
-			{
-				LLSD last_response = LLUI::getInstance()->mSettingGroups["config"]->getLLSD("Default" + templatep->mName);
-				if (!last_response.isUndefined())
-				{
-					for (LLSD::map_const_iterator it = last_response.beginMap();
-						 it != last_response.endMap();
-						 ++it)
-					{
-						if (it->second.asBoolean())
-						{
-							row["columns"][1]["value"] = formp->getElement(it->first)["ignore"].asString();
-							row["columns"][1]["font"] = "SANSSERIF_SMALL";
-							row["columns"][1]["width"] = 360;
-							break;
-						}
-					}
-				}
-			}
-			item = disabled_popups.addElement(row);
-		}
-		else
-		{
-			item = enabled_popups.addElement(row);
-		}
-		
-		if (item)
-		{
-			item->setUserdata((void*)&iter->first);
-		}
-	}
+    LLScrollListCtrl& disabled_popups =
+        getChildRef<LLScrollListCtrl>("disabled_popups");
+    LLScrollListCtrl& enabled_popups =
+        getChildRef<LLScrollListCtrl>("enabled_popups");
+
+    disabled_popups.deleteAllItems();
+    enabled_popups.deleteAllItems();
+
+    for (LLNotifications::TemplateMap::const_iterator iter = LLNotifications::instance().templatesBegin();
+         iter != LLNotifications::instance().templatesEnd();
+         ++iter)
+    {
+        LLNotificationTemplatePtr templatep = iter->second;
+        LLNotificationFormPtr formp = templatep->mForm;
+
+        LLNotificationForm::EIgnoreType ignore = formp->getIgnoreType();
+        if (ignore <= LLNotificationForm::IGNORE_NO)
+            continue;
+
+        LLSD row;
+        row["columns"][0]["value"] = formp->getIgnoreMessage();
+        row["columns"][0]["font"] = "SANSSERIF_SMALL";
+        row["columns"][0]["width"] = 400;
+
+        LLScrollListItem* item = NULL;
+
+        bool show_popup = !formp->getIgnored();
+        if (!show_popup)
+        {
+            if (ignore == LLNotificationForm::IGNORE_WITH_LAST_RESPONSE)
+            {
+                LLSD last_response = LLUI::getInstance()->mSettingGroups["config"]->getLLSD("Default" + templatep->mName);
+                if (!last_response.isUndefined())
+                {
+                    for (LLSD::map_const_iterator it = last_response.beginMap();
+                         it != last_response.endMap();
+                         ++it)
+                    {
+                        if (it->second.asBoolean())
+                        {
+                            row["columns"][1]["value"] = formp->getElement(it->first)["ignore"].asString();
+                            row["columns"][1]["font"] = "SANSSERIF_SMALL";
+                            row["columns"][1]["width"] = 360;
+                            break;
+                        }
+                    }
+                }
+            }
+            item = disabled_popups.addElement(row);
+        }
+        else
+        {
+            item = enabled_popups.addElement(row);
+        }
+
+        if (item)
+        {
+            item->setUserdata((void*)&iter->first);
+        }
+    }
 }
 
 void LLFloaterPreference::refreshEnabledState()
 {
 // [RLVa:KB] - Checked: 2013-05-11 (RLVa-1.4.9)
-	if (RlvActions::isRlvEnabled())
-	{
-		getChild<LLUICtrl>("do_not_disturb_response")->setEnabled(!RlvActions::hasBehaviour(RLV_BHVR_SENDIM));
-	}
+    if (RlvActions::isRlvEnabled())
+    {
+        getChild<LLUICtrl>("do_not_disturb_response")->setEnabled(!RlvActions::hasBehaviour(RLV_BHVR_SENDIM));
+    }
 // [/RLVa:KB]
 
-	// Cannot have floater active until caps have been received
-	getChild<LLButton>("default_creation_permissions")->setEnabled(LLStartUp::getStartupState() < STATE_STARTED ? false : true);
+    // Cannot have floater active until caps have been received
+    getChild<LLButton>("default_creation_permissions")->setEnabled(LLStartUp::getStartupState() < STATE_STARTED ? false : true);
 
-	getChildView("block_list")->setEnabled(LLLoginInstance::getInstance()->authSuccess());
+    getChildView("block_list")->setEnabled(LLLoginInstance::getInstance()->authSuccess());
 }
 
 void LLAvatarComplexityControls::setIndirectControls()
 {
-	/*
-	 * We have controls that have an indirect relationship between the control
-	 * values and adjacent text and the underlying setting they influence.
-	 * In each case, the control and its associated setting are named Indirect<something>
-	 * This method interrogates the controlled setting and establishes the
-	 * appropriate value for the indirect control. It must be called whenever the
-	 * underlying setting may have changed other than through the indirect control,
-	 * such as when the 'Reset all to recommended settings' button is used...
-	 */
-	setIndirectMaxNonImpostors();
-	setIndirectMaxArc();
+    /*
+     * We have controls that have an indirect relationship between the control
+     * values and adjacent text and the underlying setting they influence.
+     * In each case, the control and its associated setting are named Indirect<something>
+     * This method interrogates the controlled setting and establishes the
+     * appropriate value for the indirect control. It must be called whenever the
+     * underlying setting may have changed other than through the indirect control,
+     * such as when the 'Reset all to recommended settings' button is used...
+     */
+    setIndirectMaxNonImpostors();
+    setIndirectMaxArc();
 }
 
 // static
 void LLAvatarComplexityControls::setIndirectMaxNonImpostors()
 {
-	U32 max_non_impostors = gSavedSettings.getU32("RenderAvatarMaxNonImpostors");
-	// for this one, we just need to make zero, which means off, the max value of the slider
-	U32 indirect_max_non_impostors = (0 == max_non_impostors) ? LLVOAvatar::NON_IMPOSTORS_MAX_SLIDER : max_non_impostors;
-	gSavedSettings.setU32("IndirectMaxNonImpostors", indirect_max_non_impostors);
+    U32 max_non_impostors = gSavedSettings.getU32("RenderAvatarMaxNonImpostors");
+    // for this one, we just need to make zero, which means off, the max value of the slider
+    U32 indirect_max_non_impostors = (0 == max_non_impostors) ? LLVOAvatar::NON_IMPOSTORS_MAX_SLIDER : max_non_impostors;
+    gSavedSettings.setU32("IndirectMaxNonImpostors", indirect_max_non_impostors);
 }
 
 void LLAvatarComplexityControls::setIndirectMaxArc()
 {
-	U32 max_arc = gSavedSettings.getU32("RenderAvatarMaxComplexity");
-	U32 indirect_max_arc;
-	if (0 == max_arc)
-	{
-		// the off position is all the way to the right, so set to control max
-		indirect_max_arc = INDIRECT_MAX_ARC_OFF;
-	}
-	else
-	{
-		// This is the inverse of the calculation in updateMaxComplexity
-		indirect_max_arc = (U32)ll_round(((log(F32(max_arc)) - MIN_ARC_LOG) / ARC_LIMIT_MAP_SCALE)) + MIN_INDIRECT_ARC_LIMIT;
-	}
-	gSavedSettings.setU32("IndirectMaxComplexity", indirect_max_arc);
+    U32 max_arc = gSavedSettings.getU32("RenderAvatarMaxComplexity");
+    U32 indirect_max_arc;
+    if (0 == max_arc)
+    {
+        // the off position is all the way to the right, so set to control max
+        indirect_max_arc = INDIRECT_MAX_ARC_OFF;
+    }
+    else
+    {
+        // This is the inverse of the calculation in updateMaxComplexity
+        indirect_max_arc = (U32)ll_round(((log(F32(max_arc)) - MIN_ARC_LOG) / ARC_LIMIT_MAP_SCALE)) + MIN_INDIRECT_ARC_LIMIT;
+    }
+    gSavedSettings.setU32("IndirectMaxComplexity", indirect_max_arc);
 }
 
 void LLFloaterPreference::refresh()
 {
-	LLPanel::refresh();
+    LLPanel::refresh();
     LLAvatarComplexityControls::setText(
         gSavedSettings.getU32("RenderAvatarMaxComplexity"),
         getChild<LLTextBox>("IndirectMaxComplexityText", true));
-	refreshEnabledState();
-	LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
-	if (advanced)
-	{
-		advanced->refresh();
-	}
+    refreshEnabledState();
+    LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
+    if (advanced)
+    {
+        advanced->refresh();
+    }
     updateClickActionViews();
 }
 
 void LLFloaterPreference::onCommitWindowedMode()
 {
-	refresh();
+    refresh();
 }
 
 void LLFloaterPreference::onChangeQuality(const LLSD& data)
 {
-	U32 level = (U32)(data.asReal());
-	LLFeatureManager::getInstance()->setGraphicsLevel(level, true);
-	refreshEnabledGraphics();
-	refresh();
+    U32 level = (U32)(data.asReal());
+    LLFeatureManager::getInstance()->setGraphicsLevel(level, true);
+    refreshEnabledGraphics();
+    refresh();
 }
 
 void LLFloaterPreference::onClickSetSounds()
 {
-	// Disable Enable gesture sounds checkbox if the master sound is disabled 
-	// or if sound effects are disabled.
-	getChild<LLCheckBoxCtrl>("gesture_audio_play_btn")->setEnabled(!gSavedSettings.getBOOL("MuteSounds"));
+    // Disable Enable gesture sounds checkbox if the master sound is disabled
+    // or if sound effects are disabled.
+    getChild<LLCheckBoxCtrl>("gesture_audio_play_btn")->setEnabled(!gSavedSettings.getBOOL("MuteSounds"));
 }
 
 void LLFloaterPreference::onClickEnablePopup()
-{	
-	LLScrollListCtrl& disabled_popups = getChildRef<LLScrollListCtrl>("disabled_popups");
-	
-	std::vector<LLScrollListItem*> items = disabled_popups.getAllSelected();
-	std::vector<LLScrollListItem*>::iterator itor;
-	for (itor = items.begin(); itor != items.end(); ++itor)
-	{
-		LLNotificationTemplatePtr templatep = LLNotifications::instance().getTemplate(*(std::string*)((*itor)->getUserdata()));
-		//gSavedSettings.setWarning(templatep->mName, TRUE);
-		std::string notification_name = templatep->mName;
-		LLUI::getInstance()->mSettingGroups["ignores"]->setBOOL(notification_name, TRUE);
-	}
-	
-	buildPopupLists();
+{
+    LLScrollListCtrl& disabled_popups = getChildRef<LLScrollListCtrl>("disabled_popups");
+
+    std::vector<LLScrollListItem*> items = disabled_popups.getAllSelected();
+    std::vector<LLScrollListItem*>::iterator itor;
+    for (itor = items.begin(); itor != items.end(); ++itor)
+    {
+        LLNotificationTemplatePtr templatep = LLNotifications::instance().getTemplate(*(std::string*)((*itor)->getUserdata()));
+        //gSavedSettings.setWarning(templatep->mName, TRUE);
+        std::string notification_name = templatep->mName;
+        LLUI::getInstance()->mSettingGroups["ignores"]->setBOOL(notification_name, TRUE);
+    }
+
+    buildPopupLists();
     if (!mFilterEdit->getText().empty())
     {
         filterIgnorableNotifications();
@@ -1736,18 +1736,18 @@ void LLFloaterPreference::onClickEnablePopup()
 }
 
 void LLFloaterPreference::onClickDisablePopup()
-{	
-	LLScrollListCtrl& enabled_popups = getChildRef<LLScrollListCtrl>("enabled_popups");
-	
-	std::vector<LLScrollListItem*> items = enabled_popups.getAllSelected();
-	std::vector<LLScrollListItem*>::iterator itor;
-	for (itor = items.begin(); itor != items.end(); ++itor)
-	{
-		LLNotificationTemplatePtr templatep = LLNotifications::instance().getTemplate(*(std::string*)((*itor)->getUserdata()));
-		templatep->mForm->setIgnored(true);
-	}
-	
-	buildPopupLists();
+{
+    LLScrollListCtrl& enabled_popups = getChildRef<LLScrollListCtrl>("enabled_popups");
+
+    std::vector<LLScrollListItem*> items = enabled_popups.getAllSelected();
+    std::vector<LLScrollListItem*>::iterator itor;
+    for (itor = items.begin(); itor != items.end(); ++itor)
+    {
+        LLNotificationTemplatePtr templatep = LLNotifications::instance().getTemplate(*(std::string*)((*itor)->getUserdata()));
+        templatep->mForm->setIgnored(true);
+    }
+
+    buildPopupLists();
     if (!mFilterEdit->getText().empty())
     {
         filterIgnorableNotifications();
@@ -1756,226 +1756,226 @@ void LLFloaterPreference::onClickDisablePopup()
 
 void LLFloaterPreference::resetAllIgnored()
 {
-	for (LLNotifications::TemplateMap::const_iterator iter = LLNotifications::instance().templatesBegin();
-		 iter != LLNotifications::instance().templatesEnd();
-		 ++iter)
-	{
-		if (iter->second->mForm->getIgnoreType() > LLNotificationForm::IGNORE_NO)
-		{
-			iter->second->mForm->setIgnored(false);
-		}
-	}
+    for (LLNotifications::TemplateMap::const_iterator iter = LLNotifications::instance().templatesBegin();
+         iter != LLNotifications::instance().templatesEnd();
+         ++iter)
+    {
+        if (iter->second->mForm->getIgnoreType() > LLNotificationForm::IGNORE_NO)
+        {
+            iter->second->mForm->setIgnored(false);
+        }
+    }
 }
 
 void LLFloaterPreference::setAllIgnored()
 {
-	for (LLNotifications::TemplateMap::const_iterator iter = LLNotifications::instance().templatesBegin();
-		 iter != LLNotifications::instance().templatesEnd();
-		 ++iter)
-	{
-		if (iter->second->mForm->getIgnoreType() > LLNotificationForm::IGNORE_NO)
-		{
-			iter->second->mForm->setIgnored(true);
-		}
-	}
+    for (LLNotifications::TemplateMap::const_iterator iter = LLNotifications::instance().templatesBegin();
+         iter != LLNotifications::instance().templatesEnd();
+         ++iter)
+    {
+        if (iter->second->mForm->getIgnoreType() > LLNotificationForm::IGNORE_NO)
+        {
+            iter->second->mForm->setIgnored(true);
+        }
+    }
 }
 
 void LLFloaterPreference::onClickLogPath()
 {
-	std::string proposed_name(gSavedPerAccountSettings.getString("InstantMessageLogPath"));	 
-	mPriorInstantMessageLogPath.clear();
-	
+    std::string proposed_name(gSavedPerAccountSettings.getString("InstantMessageLogPath"));
+    mPriorInstantMessageLogPath.clear();
 
-	(new LLDirPickerThread(boost::bind(&LLFloaterPreference::changeLogPath, this, _1, _2), proposed_name))->getFile();
+
+    (new LLDirPickerThread(boost::bind(&LLFloaterPreference::changeLogPath, this, _1, _2), proposed_name))->getFile();
 }
 
 void LLFloaterPreference::changeLogPath(const std::vector<std::string>& filenames, std::string proposed_name)
 {
-	//Path changed
-	if (proposed_name != filenames[0])
-	{
-		gSavedPerAccountSettings.setString("InstantMessageLogPath", filenames[0]);
-		mPriorInstantMessageLogPath = proposed_name;
+    //Path changed
+    if (proposed_name != filenames[0])
+    {
+        gSavedPerAccountSettings.setString("InstantMessageLogPath", filenames[0]);
+        mPriorInstantMessageLogPath = proposed_name;
 
-		// enable/disable 'Delete transcripts button
-		updateDeleteTranscriptsButton();
-	}
+        // enable/disable 'Delete transcripts button
+        updateDeleteTranscriptsButton();
+    }
 }
 
 bool LLFloaterPreference::moveTranscriptsAndLog()
 {
-	std::string instantMessageLogPath(gSavedPerAccountSettings.getString("InstantMessageLogPath"));
-	std::string chatLogPath = gDirUtilp->add(instantMessageLogPath, gDirUtilp->getUserName());
-
-	bool madeDirectory = false;
-
-	//Does the directory really exist, if not then make it
-	if(!LLFile::isdir(chatLogPath))
-	{
-		//mkdir success is defined as zero
-		if(LLFile::mkdir(chatLogPath) != 0)
-		{
-			return false;
-		}
-		madeDirectory = true;
-	}
-	
-	std::string originalConversationLogDir = LLConversationLog::instance().getFileName();
-	std::string targetConversationLogDir = gDirUtilp->add(chatLogPath, "conversation.log");
-	//Try to move the conversation log
-	if(!LLConversationLog::instance().moveLog(originalConversationLogDir, targetConversationLogDir))
-	{
-		//Couldn't move the log and created a new directory so remove the new directory
-		if(madeDirectory)
-		{
-			LLFile::rmdir(chatLogPath);
-		}
-		return false;
-	}
-
-	//Attempt to move transcripts
-	std::vector<std::string> listOfTranscripts;
-	std::vector<std::string> listOfFilesMoved;
-
-	LLLogChat::getListOfTranscriptFiles(listOfTranscripts);
-
-	if(!LLLogChat::moveTranscripts(gDirUtilp->getChatLogsDir(), 
-									instantMessageLogPath, 
-									listOfTranscripts,
-									listOfFilesMoved))
-	{
-		//Couldn't move all the transcripts so restore those that moved back to their old location
-		LLLogChat::moveTranscripts(instantMessageLogPath, 
-			gDirUtilp->getChatLogsDir(), 
-			listOfFilesMoved);
-
-		//Move the conversation log back
-		LLConversationLog::instance().moveLog(targetConversationLogDir, originalConversationLogDir);
-
-		if(madeDirectory)
-		{
-			LLFile::rmdir(chatLogPath);
-		}
-
-		return false;
-	}
-
-	gDirUtilp->setChatLogsDir(instantMessageLogPath);
-	gDirUtilp->updatePerAccountChatLogsDir();
-
-	return true;
+    std::string instantMessageLogPath(gSavedPerAccountSettings.getString("InstantMessageLogPath"));
+    std::string chatLogPath = gDirUtilp->add(instantMessageLogPath, gDirUtilp->getUserName());
+
+    bool madeDirectory = false;
+
+    //Does the directory really exist, if not then make it
+    if(!LLFile::isdir(chatLogPath))
+    {
+        //mkdir success is defined as zero
+        if(LLFile::mkdir(chatLogPath) != 0)
+        {
+            return false;
+        }
+        madeDirectory = true;
+    }
+
+    std::string originalConversationLogDir = LLConversationLog::instance().getFileName();
+    std::string targetConversationLogDir = gDirUtilp->add(chatLogPath, "conversation.log");
+    //Try to move the conversation log
+    if(!LLConversationLog::instance().moveLog(originalConversationLogDir, targetConversationLogDir))
+    {
+        //Couldn't move the log and created a new directory so remove the new directory
+        if(madeDirectory)
+        {
+            LLFile::rmdir(chatLogPath);
+        }
+        return false;
+    }
+
+    //Attempt to move transcripts
+    std::vector<std::string> listOfTranscripts;
+    std::vector<std::string> listOfFilesMoved;
+
+    LLLogChat::getListOfTranscriptFiles(listOfTranscripts);
+
+    if(!LLLogChat::moveTranscripts(gDirUtilp->getChatLogsDir(),
+                                    instantMessageLogPath,
+                                    listOfTranscripts,
+                                    listOfFilesMoved))
+    {
+        //Couldn't move all the transcripts so restore those that moved back to their old location
+        LLLogChat::moveTranscripts(instantMessageLogPath,
+            gDirUtilp->getChatLogsDir(),
+            listOfFilesMoved);
+
+        //Move the conversation log back
+        LLConversationLog::instance().moveLog(targetConversationLogDir, originalConversationLogDir);
+
+        if(madeDirectory)
+        {
+            LLFile::rmdir(chatLogPath);
+        }
+
+        return false;
+    }
+
+    gDirUtilp->setChatLogsDir(instantMessageLogPath);
+    gDirUtilp->updatePerAccountChatLogsDir();
+
+    return true;
 }
 
-void LLFloaterPreference::setPersonalInfo(const std::string& visibility, bool im_via_email, bool is_verified_email, const std::string& email)
-{
-	mGotPersonalInfo = true;
-	mOriginalIMViaEmail = im_via_email;
-	mDirectoryVisibility = visibility;
-	
-	if (visibility == VISIBILITY_DEFAULT)
-	{
-		mOriginalHideOnlineStatus = false;
-		getChildView("online_visibility")->setEnabled(TRUE); 	 
-	}
-	else if (visibility == VISIBILITY_HIDDEN)
-	{
-		mOriginalHideOnlineStatus = true;
-		getChildView("online_visibility")->setEnabled(TRUE); 	 
-	}
-	else
-	{
-		mOriginalHideOnlineStatus = true;
-	}
-	
-	getChild<LLUICtrl>("online_searchresults")->setEnabled(TRUE);
-	getChildView("friends_online_notify_checkbox")->setEnabled(TRUE);
-	getChild<LLUICtrl>("online_visibility")->setValue(mOriginalHideOnlineStatus); 	 
-	getChild<LLUICtrl>("online_visibility")->setLabelArg("[DIR_VIS]", mDirectoryVisibility);
-	getChildView("favorites_on_login_check")->setEnabled(TRUE);
-	getChildView("log_path_button")->setEnabled(TRUE);
-	getChildView("conversation_log_combo")->setEnabled(TRUE);
-	LLCheckBoxCtrl* send_im_to_email = getChild<LLCheckBoxCtrl>("send_im_to_email");
-	if (LLGridManager::instance().isInSecondlife())
-	{
-		childSetEnabled("email_settings", true);
-		childSetVisible("email_settings", true);
-		send_im_to_email->setVisible(FALSE);
-	}
-	else
-	{
-		childSetEnabled("email_settings", false);
-		childSetVisible("email_settings", false);
-
-		std::string display_email(email);
-		if (display_email.size() > 30)
-		{
-			display_email.resize(30);
-			display_email += "...";
-		}
-		send_im_to_email->setVisible(TRUE);
-		send_im_to_email->setEnabled(is_verified_email);
-		send_im_to_email->setValue(im_via_email);
-		send_im_to_email->setLabelArg("[EMAIL]", display_email);
-		
-	    std::string tooltip;
-	    if (!is_verified_email)
-		{
-	        tooltip = getString("email_unverified_tooltip");
-		}
-
-		send_im_to_email->setToolTip(tooltip);
-	}
-
-	getChild<LLUICtrl>("voice_call_friends_only_check")->setEnabled(TRUE);
-	getChild<LLUICtrl>("voice_call_friends_only_check")->setValue(gSavedPerAccountSettings.getBOOL("VoiceCallsFriendsOnly"));
-
-	getChildView("Enable_Discord_Integration")->setEnabled(TRUE);
-	getChildView("Discord_Integration_Show_Name")->setEnabled(TRUE);
-	getChildView("Discord_Integration_Show_Region")->setEnabled(TRUE);
+void LLFloaterPreference::setPersonalInfo(const std::string& visibility, bool im_via_email, bool is_verified_email, const std::string& email)
+{
+    mGotPersonalInfo = true;
+    mOriginalIMViaEmail = im_via_email;
+    mDirectoryVisibility = visibility;
+
+    if (visibility == VISIBILITY_DEFAULT)
+    {
+        mOriginalHideOnlineStatus = false;
+        getChildView("online_visibility")->setEnabled(TRUE);
+    }
+    else if (visibility == VISIBILITY_HIDDEN)
+    {
+        mOriginalHideOnlineStatus = true;
+        getChildView("online_visibility")->setEnabled(TRUE);
+    }
+    else
+    {
+        mOriginalHideOnlineStatus = true;
+    }
+
+    getChild<LLUICtrl>("online_searchresults")->setEnabled(TRUE);
+    getChildView("friends_online_notify_checkbox")->setEnabled(TRUE);
+    getChild<LLUICtrl>("online_visibility")->setValue(mOriginalHideOnlineStatus);
+    getChild<LLUICtrl>("online_visibility")->setLabelArg("[DIR_VIS]", mDirectoryVisibility);
+    getChildView("favorites_on_login_check")->setEnabled(TRUE);
+    getChildView("log_path_button")->setEnabled(TRUE);
+    getChildView("conversation_log_combo")->setEnabled(TRUE);
+    LLCheckBoxCtrl* send_im_to_email = getChild<LLCheckBoxCtrl>("send_im_to_email");
+    if (LLGridManager::instance().isInSecondlife())
+    {
+        childSetEnabled("email_settings", true);
+        childSetVisible("email_settings", true);
+        send_im_to_email->setVisible(FALSE);
+    }
+    else
+    {
+        childSetEnabled("email_settings", false);
+        childSetVisible("email_settings", false);
+
+        std::string display_email(email);
+        if (display_email.size() > 30)
+        {
+            display_email.resize(30);
+            display_email += "...";
+        }
+        send_im_to_email->setVisible(TRUE);
+        send_im_to_email->setEnabled(is_verified_email);
+        send_im_to_email->setValue(im_via_email);
+        send_im_to_email->setLabelArg("[EMAIL]", display_email);
+
+        std::string tooltip;
+        if (!is_verified_email)
+        {
+            tooltip = getString("email_unverified_tooltip");
+        }
+
+        send_im_to_email->setToolTip(tooltip);
+    }
+
+    getChild<LLUICtrl>("voice_call_friends_only_check")->setEnabled(TRUE);
+    getChild<LLUICtrl>("voice_call_friends_only_check")->setValue(gSavedPerAccountSettings.getBOOL("VoiceCallsFriendsOnly"));
+
+    getChildView("Enable_Discord_Integration")->setEnabled(TRUE);
+    getChildView("Discord_Integration_Show_Name")->setEnabled(TRUE);
+    getChildView("Discord_Integration_Show_Region")->setEnabled(TRUE);
 }
 
 
 void LLFloaterPreference::refreshUI()
 {
-	refresh();
+    refresh();
 }
 
 void LLAvatarComplexityControls::updateMax(LLSliderCtrl* slider, LLTextBox* value_label, bool short_val)
 {
-	// Called when the IndirectMaxComplexity control changes
-	// Responsible for fixing the slider label (IndirectMaxComplexityText) and setting RenderAvatarMaxComplexity
-	U32 indirect_value = slider->getValue().asInteger();
-	U32 max_arc;
-	
-	if (INDIRECT_MAX_ARC_OFF == indirect_value)
-	{
-		// The 'off' position is when the slider is all the way to the right, 
-		// which is a value of INDIRECT_MAX_ARC_OFF,
-		// so it is necessary to set max_arc to 0 disable muted avatars.
-		max_arc = 0;
-	}
-	else
-	{
-		// if this is changed, the inverse calculation in setIndirectMaxArc
-		// must be changed to match
-		max_arc = (U32)ll_round(exp(MIN_ARC_LOG + (ARC_LIMIT_MAP_SCALE * (indirect_value - MIN_INDIRECT_ARC_LIMIT))));
-	}
-
-	gSavedSettings.setU32("RenderAvatarMaxComplexity", (U32)max_arc);
-	setText(max_arc, value_label, short_val);
+    // Called when the IndirectMaxComplexity control changes
+    // Responsible for fixing the slider label (IndirectMaxComplexityText) and setting RenderAvatarMaxComplexity
+    U32 indirect_value = slider->getValue().asInteger();
+    U32 max_arc;
+
+    if (INDIRECT_MAX_ARC_OFF == indirect_value)
+    {
+        // The 'off' position is when the slider is all the way to the right,
+        // which is a value of INDIRECT_MAX_ARC_OFF,
+        // so it is necessary to set max_arc to 0 disable muted avatars.
+        max_arc = 0;
+    }
+    else
+    {
+        // if this is changed, the inverse calculation in setIndirectMaxArc
+        // must be changed to match
+        max_arc = (U32)ll_round(exp(MIN_ARC_LOG + (ARC_LIMIT_MAP_SCALE * (indirect_value - MIN_INDIRECT_ARC_LIMIT))));
+    }
+
+    gSavedSettings.setU32("RenderAvatarMaxComplexity", (U32)max_arc);
+    setText(max_arc, value_label, short_val);
 }
 
 void LLAvatarComplexityControls::setText(U32 value, LLTextBox* text_box, bool short_val)
 {
-	if (0 == value)
-	{
-		text_box->setText(LLTrans::getString("no_limit"));
-	}
-	else
-	{
+    if (0 == value)
+    {
+        text_box->setText(LLTrans::getString("no_limit"));
+    }
+    else
+    {
         std::string text_value = short_val ? llformat("%d", value / 1000) : llformat("%d", value);
         text_box->setText(text_value);
-	}
+    }
 }
 
 void LLAvatarComplexityControls::updateMaxRenderTime(LLSliderCtrl* slider, LLTextBox* value_label, bool short_val)
@@ -1997,7 +1997,7 @@ void LLAvatarComplexityControls::setRenderTimeText(F32 value, LLTextBox* text_bo
 
 void LLFloaterPreference::updateMaxComplexity()
 {
-	// Called when the IndirectMaxComplexity control changes
+    // Called when the IndirectMaxComplexity control changes
     LLAvatarComplexityControls::updateMax(
         getChild<LLSliderCtrl>("IndirectMaxComplexity"),
         getChild<LLTextBox>("IndirectMaxComplexityText"));
@@ -2050,16 +2050,16 @@ bool LLFloaterPreference::loadFromFilename(const std::string& filename, std::map
 
 void LLFloaterPreference::onChangeMaturity()
 {
-	U8 sim_access = gSavedSettings.getU32("PreferredMaturity");
+    U8 sim_access = gSavedSettings.getU32("PreferredMaturity");
 
-	getChild<LLIconCtrl>("rating_icon_general")->setVisible(sim_access == SIM_ACCESS_PG
-															|| sim_access == SIM_ACCESS_MATURE
-															|| sim_access == SIM_ACCESS_ADULT);
+    getChild<LLIconCtrl>("rating_icon_general")->setVisible(sim_access == SIM_ACCESS_PG
+                                                            || sim_access == SIM_ACCESS_MATURE
+                                                            || sim_access == SIM_ACCESS_ADULT);
 
-	getChild<LLIconCtrl>("rating_icon_moderate")->setVisible(sim_access == SIM_ACCESS_MATURE
-															|| sim_access == SIM_ACCESS_ADULT);
+    getChild<LLIconCtrl>("rating_icon_moderate")->setVisible(sim_access == SIM_ACCESS_MATURE
+                                                            || sim_access == SIM_ACCESS_ADULT);
 
-	getChild<LLIconCtrl>("rating_icon_adult")->setVisible(sim_access == SIM_ACCESS_ADULT);
+    getChild<LLIconCtrl>("rating_icon_adult")->setVisible(sim_access == SIM_ACCESS_ADULT);
 }
 
 std::string get_category_path(LLFolderType::EType cat_type)
@@ -2113,25 +2113,25 @@ void LLFloaterPreference::onChangeAnimationFolder()
 void LLFloaterPreference::onClickBlockList()
 {
 // [SL:KB] - Patch: World-Derender | Checked: Catznip-3.2
-	LLFloaterReg::showInstance("blocked");
+    LLFloaterReg::showInstance("blocked");
 // [/SL:KB]
-//	LLFloaterSidePanelContainer::showPanel("people", "panel_people",
-//		LLSD().with("people_panel_tab_name", "blocked_panel"));
+//  LLFloaterSidePanelContainer::showPanel("people", "panel_people",
+//      LLSD().with("people_panel_tab_name", "blocked_panel"));
 }
 
 void LLFloaterPreference::onClickProxySettings()
 {
-	LLFloaterReg::showInstance("prefs_proxy");
+    LLFloaterReg::showInstance("prefs_proxy");
 }
 
 void LLFloaterPreference::onClickTranslationSettings()
 {
-	LLFloaterReg::showInstance("prefs_translation");
+    LLFloaterReg::showInstance("prefs_translation");
 }
 
 void LLFloaterPreference::onClickAutoReplace()
 {
-	LLFloaterReg::showInstance("prefs_autoreplace");
+    LLFloaterReg::showInstance("prefs_autoreplace");
 }
 
 void LLFloaterPreference::onClickSpellChecker()
@@ -2155,19 +2155,19 @@ void LLFloaterPreference::onClickAutoAdjustments()
 
 void LLFloaterPreference::onClickAdvanced()
 {
-	LLFloaterReg::showInstance("prefs_graphics_advanced");
+    LLFloaterReg::showInstance("prefs_graphics_advanced");
 
-	LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
-	for (child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
-		 iter != tabcontainer->getChildList()->end(); ++iter)
-	{
-		LLView* view = *iter;
-		LLPanelPreferenceGraphics* panel = dynamic_cast<LLPanelPreferenceGraphics*>(view);
-		if (panel)
-		{
-			panel->resetDirtyChilds();
-		}
-	}
+    LLTabContainer* tabcontainer = getChild<LLTabContainer>("pref core");
+    for (child_list_t::const_iterator iter = tabcontainer->getChildList()->begin();
+         iter != tabcontainer->getChildList()->end(); ++iter)
+    {
+        LLView* view = *iter;
+        LLPanelPreferenceGraphics* panel = dynamic_cast<LLPanelPreferenceGraphics*>(view);
+        if (panel)
+        {
+            panel->resetDirtyChilds();
+        }
+    }
 }
 
 void LLFloaterPreference::onClickActionChange()
@@ -2177,7 +2177,7 @@ void LLFloaterPreference::onClickActionChange()
 
 void LLFloaterPreference::onClickPermsDefault()
 {
-	LLFloaterReg::showInstance("perms_default");
+    LLFloaterReg::showInstance("perms_default");
 }
 
 void LLFloaterPreference::onClickRememberedUsernames()
@@ -2187,29 +2187,29 @@ void LLFloaterPreference::onClickRememberedUsernames()
 
 void LLFloaterPreference::onDeleteTranscripts()
 {
-	LLSD args;
-	args["FOLDER"] = gDirUtilp->getUserName();
+    LLSD args;
+    args["FOLDER"] = gDirUtilp->getUserName();
 
-	LLNotificationsUtil::add("PreferenceChatDeleteTranscripts", args, LLSD(), boost::bind(&LLFloaterPreference::onDeleteTranscriptsResponse, this, _1, _2));
+    LLNotificationsUtil::add("PreferenceChatDeleteTranscripts", args, LLSD(), boost::bind(&LLFloaterPreference::onDeleteTranscriptsResponse, this, _1, _2));
 }
 
 void LLFloaterPreference::onDeleteTranscriptsResponse(const LLSD& notification, const LLSD& response)
 {
-	if (0 == LLNotificationsUtil::getSelectedOption(notification, response))
-	{
-		LLLogChat::deleteTranscripts();
-		updateDeleteTranscriptsButton();
-	}
+    if (0 == LLNotificationsUtil::getSelectedOption(notification, response))
+    {
+        LLLogChat::deleteTranscripts();
+        updateDeleteTranscriptsButton();
+    }
 }
 
 void LLFloaterPreference::onLogChatHistorySaved()
 {
-	LLButton * delete_transcripts_buttonp = getChild<LLButton>("delete_transcripts");
+    LLButton * delete_transcripts_buttonp = getChild<LLButton>("delete_transcripts");
 
-	if (!delete_transcripts_buttonp->getEnabled())
-	{
-		delete_transcripts_buttonp->setEnabled(true);
-	}
+    if (!delete_transcripts_buttonp->getEnabled())
+    {
+        delete_transcripts_buttonp->setEnabled(true);
+    }
 }
 
 void LLFloaterPreference::updateClickActionControls()
@@ -2237,13 +2237,13 @@ void LLFloaterPreference::updateClickActionControls()
                               KEY_NONE,
                               MASK_NONE,
                               single_clk_action == 1);
-            
+
             panel->setKeyBind("walk_to",
                               EMouseClickType::CLICK_DOUBLELEFT,
                               KEY_NONE,
                               MASK_NONE,
                               double_clk_action == 1);
-            
+
             panel->setKeyBind("teleport_to",
                               EMouseClickType::CLICK_DOUBLELEFT,
                               KEY_NONE,
@@ -2288,8 +2288,8 @@ void LLFloaterPreference::updateClickActionViews()
         }
     }
 
-	getChild<LLComboBox>("single_click_action_combo")->setValue((int)click_to_walk);
-	getChild<LLComboBox>("double_click_action_combo")->setValue(dbl_click_to_teleport ? 2 : (int)dbl_click_to_walk);
+    getChild<LLComboBox>("single_click_action_combo")->setValue((int)click_to_walk);
+    getChild<LLComboBox>("double_click_action_combo")->setValue(dbl_click_to_teleport ? 2 : (int)dbl_click_to_walk);
 }
 
 void LLFloaterPreference::updateSearchableItems()
@@ -2299,62 +2299,62 @@ void LLFloaterPreference::updateSearchableItems()
 
 void LLFloaterPreference::applyUIColor(LLUICtrl* ctrl, const LLSD& param)
 {
-	LLUIColorTable::instance().setColor(param.asString(), LLColor4(ctrl->getValue()));
+    LLUIColorTable::instance().setColor(param.asString(), LLColor4(ctrl->getValue()));
 }
 
 void LLFloaterPreference::getUIColor(LLUICtrl* ctrl, const LLSD& param)
 {
-	LLColorSwatchCtrl* color_swatch = (LLColorSwatchCtrl*) ctrl;
-	color_swatch->setOriginal(LLUIColorTable::instance().getColor(param.asString()));
+    LLColorSwatchCtrl* color_swatch = (LLColorSwatchCtrl*) ctrl;
+    color_swatch->setOriginal(LLUIColorTable::instance().getColor(param.asString()));
 }
 
 void LLFloaterPreference::setCacheLocation(const LLStringExplicit& location)
 {
-	LLUICtrl* cache_location_editor = getChild<LLUICtrl>("cache_location");
-	cache_location_editor->setValue(location);
-	cache_location_editor->setToolTip(location);
+    LLUICtrl* cache_location_editor = getChild<LLUICtrl>("cache_location");
+    cache_location_editor->setValue(location);
+    cache_location_editor->setToolTip(location);
 }
 
 void LLFloaterPreference::selectPanel(const LLSD& name)
 {
-	LLTabContainer * tab_containerp = getChild<LLTabContainer>("pref core");
-	LLPanel * panel = tab_containerp->getPanelByName(name.asString());
-	if (NULL != panel)
-	{
-		tab_containerp->selectTabPanel(panel);
-	}
+    LLTabContainer * tab_containerp = getChild<LLTabContainer>("pref core");
+    LLPanel * panel = tab_containerp->getPanelByName(name.asString());
+    if (NULL != panel)
+    {
+        tab_containerp->selectTabPanel(panel);
+    }
 }
 
 void LLFloaterPreference::selectPrivacyPanel()
 {
-	selectPanel("im");
+    selectPanel("im");
 }
 
 void LLFloaterPreference::selectChatPanel()
 {
-	selectPanel("chat");
+    selectPanel("chat");
 }
 
 void LLFloaterPreference::changed()
 {
-	getChild<LLButton>("clear_log")->setEnabled(LLConversationLog::instance().getConversations().size() > 0);
+    getChild<LLButton>("clear_log")->setEnabled(LLConversationLog::instance().getConversations().size() > 0);
 
-	// set 'enable' property for 'Delete transcripts...' button
-	updateDeleteTranscriptsButton();
+    // set 'enable' property for 'Delete transcripts...' button
+    updateDeleteTranscriptsButton();
 
 }
 
 void LLFloaterPreference::saveGraphicsPreset(std::string& preset)
 {
-	mSavedGraphicsPreset = preset;
+    mSavedGraphicsPreset = preset;
 }
 
 //------------------------------Updater---------------------------------------
 
 static bool handleBandwidthChanged(const LLSD& newvalue)
 {
-	gViewerThrottle.setMaxBandwidth((F32) newvalue.asReal());
-	return true;
+    gViewerThrottle.setMaxBandwidth((F32) newvalue.asReal());
+    return true;
 }
 
 class LLPanelPreference::Updater : public LLEventTimer
@@ -2362,37 +2362,37 @@ class LLPanelPreference::Updater : public LLEventTimer
 
 public:
 
-	typedef boost::function<bool(const LLSD&)> callback_t;
+    typedef boost::function<bool(const LLSD&)> callback_t;
 
-	Updater(callback_t cb, F32 period)
-	:LLEventTimer(period),
-	 mCallback(cb)
-	{
-		mEventTimer.stop();
-	}
+    Updater(callback_t cb, F32 period)
+    :LLEventTimer(period),
+     mCallback(cb)
+    {
+        mEventTimer.stop();
+    }
 
-	virtual ~Updater(){}
+    virtual ~Updater(){}
 
-	void update(const LLSD& new_value)
-	{
-		mNewValue = new_value;
-		mEventTimer.start();
-	}
+    void update(const LLSD& new_value)
+    {
+        mNewValue = new_value;
+        mEventTimer.start();
+    }
 
 protected:
 
-	BOOL tick()
-	{
-		mCallback(mNewValue);
-		mEventTimer.stop();
+    BOOL tick()
+    {
+        mCallback(mNewValue);
+        mEventTimer.stop();
 
-		return FALSE;
-	}
+        return FALSE;
+    }
 
 private:
 
-	LLSD mNewValue;
-	callback_t mCallback;
+    LLSD mNewValue;
+    callback_t mCallback;
 };
 //----------------------------------------------------------------------------
 static LLPanelInjector<LLPanelPreference> t_places("panel_preference");
@@ -2400,154 +2400,154 @@ LLPanelPreference::LLPanelPreference()
 : LLPanel(),
   mBandWidthUpdater(NULL)
 {
-	mCommitCallbackRegistrar.add("Pref.setControlFalse",	boost::bind(&LLPanelPreference::setControlFalse,this, _2));
-	mCommitCallbackRegistrar.add("Pref.updateMediaAutoPlayCheckbox",	boost::bind(&LLPanelPreference::updateMediaAutoPlayCheckbox, this, _1));
-	mCommitCallbackRegistrar.add("Pref.PrefDelete",	boost::bind(&LLPanelPreference::deletePreset, this, _2));
-	mCommitCallbackRegistrar.add("Pref.PrefSave",	boost::bind(&LLPanelPreference::savePreset, this, _2));
-	mCommitCallbackRegistrar.add("Pref.PrefLoad",	boost::bind(&LLPanelPreference::loadPreset, this, _2));
+    mCommitCallbackRegistrar.add("Pref.setControlFalse",    boost::bind(&LLPanelPreference::setControlFalse,this, _2));
+    mCommitCallbackRegistrar.add("Pref.updateMediaAutoPlayCheckbox",    boost::bind(&LLPanelPreference::updateMediaAutoPlayCheckbox, this, _1));
+    mCommitCallbackRegistrar.add("Pref.PrefDelete", boost::bind(&LLPanelPreference::deletePreset, this, _2));
+    mCommitCallbackRegistrar.add("Pref.PrefSave",   boost::bind(&LLPanelPreference::savePreset, this, _2));
+    mCommitCallbackRegistrar.add("Pref.PrefLoad",   boost::bind(&LLPanelPreference::loadPreset, this, _2));
 }
 
 //virtual
 BOOL LLPanelPreference::postBuild()
 {
-	////////////////////// PanelGeneral ///////////////////
-	if (hasChild("display_names_check", TRUE))
-	{
-		BOOL use_people_api = gSavedSettings.getBOOL("UsePeopleAPI");
-		LLCheckBoxCtrl* ctrl_display_name = getChild<LLCheckBoxCtrl>("display_names_check");
-		ctrl_display_name->setEnabled(use_people_api);
-		if (!use_people_api)
-		{
-			ctrl_display_name->setValue(FALSE);
-		}
-	}
-
-	////////////////////// PanelVoice ///////////////////
-	if (hasChild("voice_unavailable", TRUE))
-	{
-		BOOL voice_disabled = gSavedSettings.getBOOL("CmdLineDisableVoice");
-		getChildView("voice_unavailable")->setVisible( voice_disabled);
-		getChildView("enable_voice_check")->setVisible( !voice_disabled);
-	}
-
-	//////////////////////PanelPrivacy ///////////////////
-	if (hasChild("media_enabled", TRUE))
-	{
-		bool media_enabled = gSavedSettings.getBOOL("AudioStreamingMedia");
-		
-		getChild<LLCheckBoxCtrl>("media_enabled")->set(media_enabled);
-		getChild<LLCheckBoxCtrl>("autoplay_enabled")->setEnabled(media_enabled);
-	}
-	if (hasChild("music_enabled", TRUE))
-	{
-		getChild<LLCheckBoxCtrl>("music_enabled")->set(gSavedSettings.getBOOL("AudioStreamingMusic"));
-	}
-	if (hasChild("voice_call_friends_only_check", TRUE))
-	{
-		getChild<LLCheckBoxCtrl>("voice_call_friends_only_check")->setCommitCallback(boost::bind(&showFriendsOnlyWarning, _1, _2));
-	}
-	if (hasChild("allow_multiple_viewer_check", TRUE))
-	{
-		getChild<LLCheckBoxCtrl>("allow_multiple_viewer_check")->setCommitCallback(boost::bind(&showMultipleViewersWarning, _1, _2));
-	}
-	if (hasChild("favorites_on_login_check", TRUE))
-	{
-		getChild<LLCheckBoxCtrl>("favorites_on_login_check")->setCommitCallback(boost::bind(&handleFavoritesOnLoginChanged, _1, _2));
-		bool show_favorites_at_login = LLPanelLogin::getShowFavorites();
-		getChild<LLCheckBoxCtrl>("favorites_on_login_check")->setValue(show_favorites_at_login);
-	}
-	if (hasChild("mute_chb_label", TRUE))
-	{
-		getChild<LLTextBox>("mute_chb_label")->setShowCursorHand(false);
-		getChild<LLTextBox>("mute_chb_label")->setSoundFlags(LLView::MOUSE_UP);
-		getChild<LLTextBox>("mute_chb_label")->setClickedCallback(boost::bind(&toggleMuteWhenMinimized));
-	}
-
-	//////////////////////PanelSetup ///////////////////
-	if (hasChild("max_bandwidth", TRUE))
-	{
-		mBandWidthUpdater = new LLPanelPreference::Updater(boost::bind(&handleBandwidthChanged, _1), BANDWIDTH_UPDATER_TIMEOUT);
-		mBandwithConnection = gSavedSettings.getControl("ThrottleBandwidthKBPS")->getSignal()->connect(boost::bind(&LLPanelPreference::Updater::update, mBandWidthUpdater, _2));
-	}
+    ////////////////////// PanelGeneral ///////////////////
+    if (hasChild("display_names_check", TRUE))
+    {
+        BOOL use_people_api = gSavedSettings.getBOOL("UsePeopleAPI");
+        LLCheckBoxCtrl* ctrl_display_name = getChild<LLCheckBoxCtrl>("display_names_check");
+        ctrl_display_name->setEnabled(use_people_api);
+        if (!use_people_api)
+        {
+            ctrl_display_name->setValue(FALSE);
+        }
+    }
+
+    ////////////////////// PanelVoice ///////////////////
+    if (hasChild("voice_unavailable", TRUE))
+    {
+        BOOL voice_disabled = gSavedSettings.getBOOL("CmdLineDisableVoice");
+        getChildView("voice_unavailable")->setVisible( voice_disabled);
+        getChildView("enable_voice_check")->setVisible( !voice_disabled);
+    }
+
+    //////////////////////PanelPrivacy ///////////////////
+    if (hasChild("media_enabled", TRUE))
+    {
+        bool media_enabled = gSavedSettings.getBOOL("AudioStreamingMedia");
+
+        getChild<LLCheckBoxCtrl>("media_enabled")->set(media_enabled);
+        getChild<LLCheckBoxCtrl>("autoplay_enabled")->setEnabled(media_enabled);
+    }
+    if (hasChild("music_enabled", TRUE))
+    {
+        getChild<LLCheckBoxCtrl>("music_enabled")->set(gSavedSettings.getBOOL("AudioStreamingMusic"));
+    }
+    if (hasChild("voice_call_friends_only_check", TRUE))
+    {
+        getChild<LLCheckBoxCtrl>("voice_call_friends_only_check")->setCommitCallback(boost::bind(&showFriendsOnlyWarning, _1, _2));
+    }
+    if (hasChild("allow_multiple_viewer_check", TRUE))
+    {
+        getChild<LLCheckBoxCtrl>("allow_multiple_viewer_check")->setCommitCallback(boost::bind(&showMultipleViewersWarning, _1, _2));
+    }
+    if (hasChild("favorites_on_login_check", TRUE))
+    {
+        getChild<LLCheckBoxCtrl>("favorites_on_login_check")->setCommitCallback(boost::bind(&handleFavoritesOnLoginChanged, _1, _2));
+        bool show_favorites_at_login = LLPanelLogin::getShowFavorites();
+        getChild<LLCheckBoxCtrl>("favorites_on_login_check")->setValue(show_favorites_at_login);
+    }
+    if (hasChild("mute_chb_label", TRUE))
+    {
+        getChild<LLTextBox>("mute_chb_label")->setShowCursorHand(false);
+        getChild<LLTextBox>("mute_chb_label")->setSoundFlags(LLView::MOUSE_UP);
+        getChild<LLTextBox>("mute_chb_label")->setClickedCallback(boost::bind(&toggleMuteWhenMinimized));
+    }
+
+    //////////////////////PanelSetup ///////////////////
+    if (hasChild("max_bandwidth", TRUE))
+    {
+        mBandWidthUpdater = new LLPanelPreference::Updater(boost::bind(&handleBandwidthChanged, _1), BANDWIDTH_UPDATER_TIMEOUT);
+        mBandwithConnection = gSavedSettings.getControl("ThrottleBandwidthKBPS")->getSignal()->connect(boost::bind(&LLPanelPreference::Updater::update, mBandWidthUpdater, _2));
+    }
 
 #ifndef LL_LINUX
-	if (hasChild("enable_game_mode_check", TRUE))
-	{
-		getChild<LLCheckBoxCtrl>("enable_game_mode_check")->setEnabled(FALSE);
-		getChild<LLCheckBoxCtrl>("enable_game_mode_check")->setToolTip(LLTrans::getString("NotAvailableOnPlatform"));
-	}
+    if (hasChild("enable_game_mode_check", TRUE))
+    {
+        getChild<LLCheckBoxCtrl>("enable_game_mode_check")->setEnabled(FALSE);
+        getChild<LLCheckBoxCtrl>("enable_game_mode_check")->setToolTip(LLTrans::getString("NotAvailableOnPlatform"));
+    }
 #endif
 
 #ifdef EXTERNAL_TOS
-	LLRadioGroup* ext_browser_settings = getChild<LLRadioGroup>("preferred_browser_behavior");
-	if (ext_browser_settings)
-	{
-		// turn off ability to set external/internal browser
-		ext_browser_settings->setSelectedByValue(LLWeb::BROWSER_EXTERNAL_ONLY, true);
-		ext_browser_settings->setEnabled(false);
-	}
+    LLRadioGroup* ext_browser_settings = getChild<LLRadioGroup>("preferred_browser_behavior");
+    if (ext_browser_settings)
+    {
+        // turn off ability to set external/internal browser
+        ext_browser_settings->setSelectedByValue(LLWeb::BROWSER_EXTERNAL_ONLY, true);
+        ext_browser_settings->setEnabled(false);
+    }
 #endif
 
-	apply();
-	return true;
+    apply();
+    return true;
 }
 
 LLPanelPreference::~LLPanelPreference()
 {
-	mBandwithConnection.disconnect();
-	if (mBandWidthUpdater)
-	{
-		delete mBandWidthUpdater;
-	}
+    mBandwithConnection.disconnect();
+    if (mBandWidthUpdater)
+    {
+        delete mBandWidthUpdater;
+    }
 }
 void LLPanelPreference::apply()
 {
-	// no-op
+    // no-op
 }
 
 void LLPanelPreference::saveSettings()
 {
-	LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
-
-	// Save the value of all controls in the hierarchy
-	mSavedValues.clear();
-	std::list<LLView*> view_stack;
-	view_stack.push_back(this);
-	if (advanced)
-	{
-		view_stack.push_back(advanced);
-	}
-	while(!view_stack.empty())
-	{
-		// Process view on top of the stack
-		LLView* curview = view_stack.front();
-		view_stack.pop_front();
-
-		LLColorSwatchCtrl* color_swatch = dynamic_cast<LLColorSwatchCtrl *>(curview);
-		if (color_swatch)
-		{
-			mSavedColors[color_swatch->getName()] = color_swatch->get();
-		}
-		else
-		{
-			LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
-			if (ctrl)
-			{
-				LLControlVariable* control = ctrl->getControlVariable();
-				if (control)
-				{
-					mSavedValues[control] = control->getValue();
-				}
-			}
-		}
-			
-		// Push children onto the end of the work stack
-		for (child_list_t::const_iterator iter = curview->getChildList()->begin();
-			 iter != curview->getChildList()->end(); ++iter)
-		{
-			view_stack.push_back(*iter);
-		}
-	}
+    LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
+
+    // Save the value of all controls in the hierarchy
+    mSavedValues.clear();
+    std::list<LLView*> view_stack;
+    view_stack.push_back(this);
+    if (advanced)
+    {
+        view_stack.push_back(advanced);
+    }
+    while(!view_stack.empty())
+    {
+        // Process view on top of the stack
+        LLView* curview = view_stack.front();
+        view_stack.pop_front();
+
+        LLColorSwatchCtrl* color_swatch = dynamic_cast<LLColorSwatchCtrl *>(curview);
+        if (color_swatch)
+        {
+            mSavedColors[color_swatch->getName()] = color_swatch->get();
+        }
+        else
+        {
+            LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
+            if (ctrl)
+            {
+                LLControlVariable* control = ctrl->getControlVariable();
+                if (control)
+                {
+                    mSavedValues[control] = control->getValue();
+                }
+            }
+        }
+
+        // Push children onto the end of the work stack
+        for (child_list_t::const_iterator iter = curview->getChildList()->begin();
+             iter != curview->getChildList()->end(); ++iter)
+        {
+            view_stack.push_back(*iter);
+        }
+    }
 
     if (LLStartUp::getStartupState() == STATE_STARTED)
     {
@@ -2569,104 +2569,104 @@ void LLPanelPreference::showMultipleViewersWarning(LLUICtrl* checkbox, const LLS
 
 void LLPanelPreference::showFriendsOnlyWarning(LLUICtrl* checkbox, const LLSD& value)
 {
-	if (checkbox)
-	{
-		gSavedPerAccountSettings.setBOOL("VoiceCallsFriendsOnly", checkbox->getValue().asBoolean());
-		if (checkbox->getValue())
-		{
-			LLNotificationsUtil::add("FriendsAndGroupsOnly");
-		}
-	}
+    if (checkbox)
+    {
+        gSavedPerAccountSettings.setBOOL("VoiceCallsFriendsOnly", checkbox->getValue().asBoolean());
+        if (checkbox->getValue())
+        {
+            LLNotificationsUtil::add("FriendsAndGroupsOnly");
+        }
+    }
 }
 
 void LLPanelPreference::handleFavoritesOnLoginChanged(LLUICtrl* checkbox, const LLSD& value)
 {
-	if (checkbox)
-	{
-		LLFavoritesOrderStorage::instance().showFavoritesOnLoginChanged(checkbox->getValue().asBoolean());
-		if(checkbox->getValue())
-		{
-			LLNotificationsUtil::add("FavoritesOnLogin");
-		}
-	}
+    if (checkbox)
+    {
+        LLFavoritesOrderStorage::instance().showFavoritesOnLoginChanged(checkbox->getValue().asBoolean());
+        if(checkbox->getValue())
+        {
+            LLNotificationsUtil::add("FavoritesOnLogin");
+        }
+    }
 }
 
 void LLPanelPreference::toggleMuteWhenMinimized()
 {
-	std::string mute("MuteWhenMinimized");
-	gSavedSettings.setBOOL(mute, !gSavedSettings.getBOOL(mute));
-	LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
-	if (instance)
-	{
-		instance->getChild<LLCheckBoxCtrl>("mute_when_minimized")->setBtnFocus();
-	}
+    std::string mute("MuteWhenMinimized");
+    gSavedSettings.setBOOL(mute, !gSavedSettings.getBOOL(mute));
+    LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
+    if (instance)
+    {
+        instance->getChild<LLCheckBoxCtrl>("mute_when_minimized")->setBtnFocus();
+    }
 }
 
 void LLPanelPreference::cancel()
 {
-	for (control_values_map_t::iterator iter =  mSavedValues.begin();
-		 iter !=  mSavedValues.end(); ++iter)
-	{
-		LLControlVariable* control = iter->first;
-		LLSD ctrl_value = iter->second;
+    for (control_values_map_t::iterator iter =  mSavedValues.begin();
+         iter !=  mSavedValues.end(); ++iter)
+    {
+        LLControlVariable* control = iter->first;
+        LLSD ctrl_value = iter->second;
 
-		if((control->getName() == "InstantMessageLogPath") && (ctrl_value.asString() == ""))
-		{
-			continue;
-		}
+        if((control->getName() == "InstantMessageLogPath") && (ctrl_value.asString() == ""))
+        {
+            continue;
+        }
 
-		control->set(ctrl_value);
-	}
+        control->set(ctrl_value);
+    }
 
-	for (string_color_map_t::iterator iter = mSavedColors.begin();
-		 iter != mSavedColors.end(); ++iter)
-	{
-		LLColorSwatchCtrl* color_swatch = findChild<LLColorSwatchCtrl>(iter->first);
-		if (color_swatch)
-		{
-			color_swatch->set(iter->second);
-			color_swatch->onCommit();
-		}
-	}
+    for (string_color_map_t::iterator iter = mSavedColors.begin();
+         iter != mSavedColors.end(); ++iter)
+    {
+        LLColorSwatchCtrl* color_swatch = findChild<LLColorSwatchCtrl>(iter->first);
+        if (color_swatch)
+        {
+            color_swatch->set(iter->second);
+            color_swatch->onCommit();
+        }
+    }
 }
 
 void LLPanelPreference::setControlFalse(const LLSD& user_data)
 {
-	std::string control_name = user_data.asString();
-	LLControlVariable* control = findControl(control_name);
-	
-	if (control)
-		control->set(LLSD(FALSE));
+    std::string control_name = user_data.asString();
+    LLControlVariable* control = findControl(control_name);
+
+    if (control)
+        control->set(LLSD(FALSE));
 }
 
 void LLPanelPreference::updateMediaAutoPlayCheckbox(LLUICtrl* ctrl)
 {
-	std::string name = ctrl->getName();
+    std::string name = ctrl->getName();
 
-	// Disable "Allow Media to auto play" only when both
-	// "Streaming Music" and "Media" are unchecked. STORM-513.
-	if ((name == "enable_music") || (name == "enable_media"))
-	{
-		bool music_enabled = getChild<LLCheckBoxCtrl>("enable_music")->get();
-		bool media_enabled = getChild<LLCheckBoxCtrl>("enable_media")->get();
+    // Disable "Allow Media to auto play" only when both
+    // "Streaming Music" and "Media" are unchecked. STORM-513.
+    if ((name == "enable_music") || (name == "enable_media"))
+    {
+        bool music_enabled = getChild<LLCheckBoxCtrl>("enable_music")->get();
+        bool media_enabled = getChild<LLCheckBoxCtrl>("enable_media")->get();
 
-		getChild<LLCheckBoxCtrl>("media_auto_play_combo")->setEnabled(music_enabled || media_enabled);
-	}
+        getChild<LLCheckBoxCtrl>("media_auto_play_combo")->setEnabled(music_enabled || media_enabled);
+    }
 }
 
 void LLPanelPreference::deletePreset(const LLSD& user_data)
 {
-	LLFloaterReg::showInstance("delete_pref_preset", user_data.asString());
+    LLFloaterReg::showInstance("delete_pref_preset", user_data.asString());
 }
 
 void LLPanelPreference::savePreset(const LLSD& user_data)
 {
-	LLFloaterReg::showInstance("save_pref_preset", user_data.asString());
+    LLFloaterReg::showInstance("save_pref_preset", user_data.asString());
 }
 
 void LLPanelPreference::loadPreset(const LLSD& user_data)
 {
-	LLFloaterReg::showInstance("load_pref_preset", user_data.asString());
+    LLFloaterReg::showInstance("load_pref_preset", user_data.asString());
 }
 
 void LLPanelPreference::setHardwareDefaults()
@@ -2676,38 +2676,38 @@ void LLPanelPreference::setHardwareDefaults()
 class LLPanelPreferencePrivacy : public LLPanelPreference
 {
 public:
-	LLPanelPreferencePrivacy()
-	{
-		mAccountIndependentSettings.push_back("AutoDisengageMic");
-	}
-
-	/*virtual*/ void saveSettings()
-	{
-		LLPanelPreference::saveSettings();
-
-		// Don't save (=erase from the saved values map) per-account privacy settings
-		// if we're not logged in, otherwise they will be reset to defaults on log off.
-		if (LLStartUp::getStartupState() != STATE_STARTED)
-		{
-			// Erase only common settings, assuming there are no color settings on Privacy page.
-			for (control_values_map_t::iterator it = mSavedValues.begin(); it != mSavedValues.end(); )
-			{
-				const std::string setting = it->first->getName();
-				if (find(mAccountIndependentSettings.begin(),
-					mAccountIndependentSettings.end(), setting) == mAccountIndependentSettings.end())
-				{
-					mSavedValues.erase(it++);
-				}
-				else
-				{
-					++it;
-				}
-			}
-		}
-	}
+    LLPanelPreferencePrivacy()
+    {
+        mAccountIndependentSettings.push_back("AutoDisengageMic");
+    }
+
+    /*virtual*/ void saveSettings()
+    {
+        LLPanelPreference::saveSettings();
+
+        // Don't save (=erase from the saved values map) per-account privacy settings
+        // if we're not logged in, otherwise they will be reset to defaults on log off.
+        if (LLStartUp::getStartupState() != STATE_STARTED)
+        {
+            // Erase only common settings, assuming there are no color settings on Privacy page.
+            for (control_values_map_t::iterator it = mSavedValues.begin(); it != mSavedValues.end(); )
+            {
+                const std::string setting = it->first->getName();
+                if (find(mAccountIndependentSettings.begin(),
+                    mAccountIndependentSettings.end(), setting) == mAccountIndependentSettings.end())
+                {
+                    mSavedValues.erase(it++);
+                }
+                else
+                {
+                    ++it;
+                }
+            }
+        }
+    }
 
 private:
-	std::list<std::string> mAccountIndependentSettings;
+    std::list<std::string> mAccountIndependentSettings;
 };
 
 static LLPanelInjector<LLPanelPreferenceGraphics> t_pref_graph("panel_preference_graphics");
@@ -2715,166 +2715,166 @@ static LLPanelInjector<LLPanelPreferencePrivacy> t_pref_privacy("panel_preferenc
 
 BOOL LLPanelPreferenceGraphics::postBuild()
 {
-	LLFloaterReg::showInstance("prefs_graphics_advanced");
-	LLFloaterReg::hideInstance("prefs_graphics_advanced");
+    LLFloaterReg::showInstance("prefs_graphics_advanced");
+    LLFloaterReg::hideInstance("prefs_graphics_advanced");
 
-	resetDirtyChilds();
-	setPresetText();
+    resetDirtyChilds();
+    setPresetText();
 
-	LLPresetsManager* presetsMgr = LLPresetsManager::getInstance();
+    LLPresetsManager* presetsMgr = LLPresetsManager::getInstance();
     presetsMgr->setPresetListChangeCallback(boost::bind(&LLPanelPreferenceGraphics::onPresetsListChange, this));
     presetsMgr->createMissingDefault(PRESETS_GRAPHIC); // a no-op after the first time, but that's ok
-    
-	return LLPanelPreference::postBuild();
+
+    return LLPanelPreference::postBuild();
 }
 
 void LLPanelPreferenceGraphics::draw()
 {
-	setPresetText();
-	LLPanelPreference::draw();
+    setPresetText();
+    LLPanelPreference::draw();
 }
 
 void LLPanelPreferenceGraphics::onPresetsListChange()
 {
-	resetDirtyChilds();
-	setPresetText();
+    resetDirtyChilds();
+    setPresetText();
 
-	LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
-	if (instance && !gSavedSettings.getString("PresetGraphicActive").empty())
-	{
-		instance->saveSettings(); //make cancel work correctly after changing the preset
-	}
+    LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
+    if (instance && !gSavedSettings.getString("PresetGraphicActive").empty())
+    {
+        instance->saveSettings(); //make cancel work correctly after changing the preset
+    }
 }
 
 void LLPanelPreferenceGraphics::setPresetText()
 {
-	LLTextBox* preset_text = getChild<LLTextBox>("preset_text");
+    LLTextBox* preset_text = getChild<LLTextBox>("preset_text");
 
-	std::string preset_graphic_active = gSavedSettings.getString("PresetGraphicActive");
+    std::string preset_graphic_active = gSavedSettings.getString("PresetGraphicActive");
 
-	if (!preset_graphic_active.empty() && preset_graphic_active != preset_text->getText())
-	{
-		LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
-		if (instance)
-		{
-			instance->saveGraphicsPreset(preset_graphic_active);
-		}
-	}
+    if (!preset_graphic_active.empty() && preset_graphic_active != preset_text->getText())
+    {
+        LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
+        if (instance)
+        {
+            instance->saveGraphicsPreset(preset_graphic_active);
+        }
+    }
 
     if (hasDirtyChilds() && !preset_graphic_active.empty())
-	{
-		preset_graphic_active.clear();
-	}
-
-	if (!preset_graphic_active.empty())
-	{
-		if (preset_graphic_active == PRESETS_DEFAULT)
-		{
-			preset_graphic_active = LLTrans::getString(PRESETS_DEFAULT);
-		}
-		preset_text->setText(preset_graphic_active);
-	}
-	else
-	{
-		preset_text->setText(LLTrans::getString("none_paren_cap"));
-	}
-
-	preset_text->resetDirty();
+    {
+        preset_graphic_active.clear();
+    }
+
+    if (!preset_graphic_active.empty())
+    {
+        if (preset_graphic_active == PRESETS_DEFAULT)
+        {
+            preset_graphic_active = LLTrans::getString(PRESETS_DEFAULT);
+        }
+        preset_text->setText(preset_graphic_active);
+    }
+    else
+    {
+        preset_text->setText(LLTrans::getString("none_paren_cap"));
+    }
+
+    preset_text->resetDirty();
 }
 
 bool LLPanelPreferenceGraphics::hasDirtyChilds()
 {
-	LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
-	std::list<LLView*> view_stack;
-	view_stack.push_back(this);
-	if (advanced)
-	{
-		view_stack.push_back(advanced);
-	}
-	while(!view_stack.empty())
-	{
-		// Process view on top of the stack
-		LLView* curview = view_stack.front();
-		view_stack.pop_front();
-
-		LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
-		if (ctrl)
-		{
-			if (ctrl->isDirty())
-			{
-				LLControlVariable* control = ctrl->getControlVariable();
-				if (control)
-				{
-					std::string control_name = control->getName();
-					if (!control_name.empty())
-					{
-						return true;
-					}
-				}
-			}
-		}
-		// Push children onto the end of the work stack
-		for (child_list_t::const_iterator iter = curview->getChildList()->begin();
-			 iter != curview->getChildList()->end(); ++iter)
-		{
-			view_stack.push_back(*iter);
-		}
-	}
-
-	return false;
+    LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
+    std::list<LLView*> view_stack;
+    view_stack.push_back(this);
+    if (advanced)
+    {
+        view_stack.push_back(advanced);
+    }
+    while(!view_stack.empty())
+    {
+        // Process view on top of the stack
+        LLView* curview = view_stack.front();
+        view_stack.pop_front();
+
+        LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
+        if (ctrl)
+        {
+            if (ctrl->isDirty())
+            {
+                LLControlVariable* control = ctrl->getControlVariable();
+                if (control)
+                {
+                    std::string control_name = control->getName();
+                    if (!control_name.empty())
+                    {
+                        return true;
+                    }
+                }
+            }
+        }
+        // Push children onto the end of the work stack
+        for (child_list_t::const_iterator iter = curview->getChildList()->begin();
+             iter != curview->getChildList()->end(); ++iter)
+        {
+            view_stack.push_back(*iter);
+        }
+    }
+
+    return false;
 }
 
 void LLPanelPreferenceGraphics::resetDirtyChilds()
 {
-	LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
-	std::list<LLView*> view_stack;
-	view_stack.push_back(this);
-	if (advanced)
-	{
-		view_stack.push_back(advanced);
-	}
-	while(!view_stack.empty())
-	{
-		// Process view on top of the stack
-		LLView* curview = view_stack.front();
-		view_stack.pop_front();
-
-		LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
-		if (ctrl)
-		{
-			ctrl->resetDirty();
-		}
-		// Push children onto the end of the work stack
-		for (child_list_t::const_iterator iter = curview->getChildList()->begin();
-			 iter != curview->getChildList()->end(); ++iter)
-		{
-			view_stack.push_back(*iter);
-		}
-	}	
+    LLFloater* advanced = LLFloaterReg::findTypedInstance<LLFloater>("prefs_graphics_advanced");
+    std::list<LLView*> view_stack;
+    view_stack.push_back(this);
+    if (advanced)
+    {
+        view_stack.push_back(advanced);
+    }
+    while(!view_stack.empty())
+    {
+        // Process view on top of the stack
+        LLView* curview = view_stack.front();
+        view_stack.pop_front();
+
+        LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
+        if (ctrl)
+        {
+            ctrl->resetDirty();
+        }
+        // Push children onto the end of the work stack
+        for (child_list_t::const_iterator iter = curview->getChildList()->begin();
+             iter != curview->getChildList()->end(); ++iter)
+        {
+            view_stack.push_back(*iter);
+        }
+    }
 }
 
 void LLPanelPreferenceGraphics::cancel()
 {
-	LLPanelPreference::cancel();
+    LLPanelPreference::cancel();
 }
 void LLPanelPreferenceGraphics::saveSettings()
 {
-	resetDirtyChilds();
-	std::string preset_graphic_active = gSavedSettings.getString("PresetGraphicActive");
-	if (preset_graphic_active.empty())
-	{
-		LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
-		if (instance)
-		{
-			//don't restore previous preset after closing Preferences
-			instance->saveGraphicsPreset(preset_graphic_active);
-		}
-	}
-	LLPanelPreference::saveSettings();
+    resetDirtyChilds();
+    std::string preset_graphic_active = gSavedSettings.getString("PresetGraphicActive");
+    if (preset_graphic_active.empty())
+    {
+        LLFloaterPreference* instance = LLFloaterReg::findTypedInstance<LLFloaterPreference>("preferences");
+        if (instance)
+        {
+            //don't restore previous preset after closing Preferences
+            instance->saveGraphicsPreset(preset_graphic_active);
+        }
+    }
+    LLPanelPreference::saveSettings();
 }
 void LLPanelPreferenceGraphics::setHardwareDefaults()
 {
-	resetDirtyChilds();
+    resetDirtyChilds();
 }
 
 //------------------------LLPanelPreferenceControls--------------------------------
@@ -3444,7 +3444,7 @@ void LLPanelPreferenceControls::onDefaultKeyBind(bool all_modes)
     {
         return;
     }
-    
+
     if (mEditingColumn > 0)
     {
         if (all_modes)
@@ -3486,12 +3486,12 @@ void LLPanelPreferenceControls::onCancelKeyBind()
 }
 
 LLFloaterPreferenceProxy::LLFloaterPreferenceProxy(const LLSD& key)
-	: LLFloater(key),
-	  mSocksSettingsDirty(false)
+    : LLFloater(key),
+      mSocksSettingsDirty(false)
 {
-	mCommitCallbackRegistrar.add("Proxy.OK",                boost::bind(&LLFloaterPreferenceProxy::onBtnOk, this));
-	mCommitCallbackRegistrar.add("Proxy.Cancel",            boost::bind(&LLFloaterPreferenceProxy::onBtnCancel, this));
-	mCommitCallbackRegistrar.add("Proxy.Change",            boost::bind(&LLFloaterPreferenceProxy::onChangeSocksSettings, this));
+    mCommitCallbackRegistrar.add("Proxy.OK",                boost::bind(&LLFloaterPreferenceProxy::onBtnOk, this));
+    mCommitCallbackRegistrar.add("Proxy.Cancel",            boost::bind(&LLFloaterPreferenceProxy::onBtnCancel, this));
+    mCommitCallbackRegistrar.add("Proxy.Change",            boost::bind(&LLFloaterPreferenceProxy::onChangeSocksSettings, this));
 }
 
 LLFloaterPreferenceProxy::~LLFloaterPreferenceProxy()
@@ -3500,192 +3500,192 @@ LLFloaterPreferenceProxy::~LLFloaterPreferenceProxy()
 
 BOOL LLFloaterPreferenceProxy::postBuild()
 {
-	LLRadioGroup* socksAuth = getChild<LLRadioGroup>("socks5_auth_type");
-	if (!socksAuth)
-	{
-		return FALSE;
-	}
-	if (socksAuth->getSelectedValue().asString() == "None")
-	{
-		getChild<LLLineEditor>("socks5_username")->setEnabled(false);
-		getChild<LLLineEditor>("socks5_password")->setEnabled(false);
-	}
-	else
-	{
-		// Populate the SOCKS 5 credential fields with protected values.
-		LLPointer<LLCredential> socks_cred = gSecAPIHandler->loadCredential("SOCKS5");
-		getChild<LLLineEditor>("socks5_username")->setValue(socks_cred->getIdentifier()["username"].asString());
-		getChild<LLLineEditor>("socks5_password")->setValue(socks_cred->getAuthenticator()["creds"].asString());
-	}
-
-	return TRUE;
+    LLRadioGroup* socksAuth = getChild<LLRadioGroup>("socks5_auth_type");
+    if (!socksAuth)
+    {
+        return FALSE;
+    }
+    if (socksAuth->getSelectedValue().asString() == "None")
+    {
+        getChild<LLLineEditor>("socks5_username")->setEnabled(false);
+        getChild<LLLineEditor>("socks5_password")->setEnabled(false);
+    }
+    else
+    {
+        // Populate the SOCKS 5 credential fields with protected values.
+        LLPointer<LLCredential> socks_cred = gSecAPIHandler->loadCredential("SOCKS5");
+        getChild<LLLineEditor>("socks5_username")->setValue(socks_cred->getIdentifier()["username"].asString());
+        getChild<LLLineEditor>("socks5_password")->setValue(socks_cred->getAuthenticator()["creds"].asString());
+    }
+
+    return TRUE;
 }
 
 void LLFloaterPreferenceProxy::onOpen(const LLSD& key)
 {
-	saveSettings();
+    saveSettings();
 }
 
 void LLFloaterPreferenceProxy::onClose(bool app_quitting)
 {
-	if(app_quitting)
-	{
-		cancel();
-	}
+    if(app_quitting)
+    {
+        cancel();
+    }
 
-	if (mSocksSettingsDirty)
-	{
+    if (mSocksSettingsDirty)
+    {
 
-		// If the user plays with the Socks proxy settings after login, it's only fair we let them know
-		// it will not be updated until next restart.
-		if (LLStartUp::getStartupState()>STATE_LOGIN_WAIT)
-		{
-			LLNotifications::instance().add("ChangeProxySettings", LLSD(), LLSD());
-			mSocksSettingsDirty = false; // we have notified the user now be quiet again
-		}
-	}
+        // If the user plays with the Socks proxy settings after login, it's only fair we let them know
+        // it will not be updated until next restart.
+        if (LLStartUp::getStartupState()>STATE_LOGIN_WAIT)
+        {
+            LLNotifications::instance().add("ChangeProxySettings", LLSD(), LLSD());
+            mSocksSettingsDirty = false; // we have notified the user now be quiet again
+        }
+    }
 }
 
 void LLFloaterPreferenceProxy::saveSettings()
 {
-	// Save the value of all controls in the hierarchy
-	mSavedValues.clear();
-	std::list<LLView*> view_stack;
-	view_stack.push_back(this);
-	while(!view_stack.empty())
-	{
-		// Process view on top of the stack
-		LLView* curview = view_stack.front();
-		view_stack.pop_front();
-
-		LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
-		if (ctrl)
-		{
-			LLControlVariable* control = ctrl->getControlVariable();
-			if (control)
-			{
-				mSavedValues[control] = control->getValue();
-			}
-		}
-
-		// Push children onto the end of the work stack
-		for (child_list_t::const_iterator iter = curview->getChildList()->begin();
-				iter != curview->getChildList()->end(); ++iter)
-		{
-			view_stack.push_back(*iter);
-		}
-	}
+    // Save the value of all controls in the hierarchy
+    mSavedValues.clear();
+    std::list<LLView*> view_stack;
+    view_stack.push_back(this);
+    while(!view_stack.empty())
+    {
+        // Process view on top of the stack
+        LLView* curview = view_stack.front();
+        view_stack.pop_front();
+
+        LLUICtrl* ctrl = dynamic_cast<LLUICtrl*>(curview);
+        if (ctrl)
+        {
+            LLControlVariable* control = ctrl->getControlVariable();
+            if (control)
+            {
+                mSavedValues[control] = control->getValue();
+            }
+        }
+
+        // Push children onto the end of the work stack
+        for (child_list_t::const_iterator iter = curview->getChildList()->begin();
+                iter != curview->getChildList()->end(); ++iter)
+        {
+            view_stack.push_back(*iter);
+        }
+    }
 }
 
 void LLFloaterPreferenceProxy::onBtnOk()
 {
-	// commit any outstanding text entry
-	if (hasFocus())
-	{
-		LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
-		if (cur_focus && cur_focus->acceptsTextInput())
-		{
-			cur_focus->onCommit();
-		}
-	}
-
-	// Save SOCKS proxy credentials securely if password auth is enabled
-	LLRadioGroup* socksAuth = getChild<LLRadioGroup>("socks5_auth_type");
-	if (socksAuth->getSelectedValue().asString() == "UserPass")
-	{
-		LLSD socks_id = LLSD::emptyMap();
-		socks_id["type"] = "SOCKS5";
-		socks_id["username"] = getChild<LLLineEditor>("socks5_username")->getValue().asString();
-
-		LLSD socks_authenticator = LLSD::emptyMap();
-		socks_authenticator["type"] = "SOCKS5";
-		socks_authenticator["creds"] = getChild<LLLineEditor>("socks5_password")->getValue().asString();
-
-		// Using "SOCKS5" as the "grid" argument since the same proxy
-		// settings will be used for all grids and because there is no
-		// way to specify the type of credential.
-		LLPointer<LLCredential> socks_cred = gSecAPIHandler->createCredential("SOCKS5", socks_id, socks_authenticator);
-		gSecAPIHandler->saveCredential(socks_cred, true);
-	}
-	else
-	{
-		// Clear SOCKS5 credentials since they are no longer needed.
-		LLPointer<LLCredential> socks_cred = new LLCredential("SOCKS5");
-		gSecAPIHandler->deleteCredential(socks_cred);
-	}
-
-	closeFloater(false);
+    // commit any outstanding text entry
+    if (hasFocus())
+    {
+        LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
+        if (cur_focus && cur_focus->acceptsTextInput())
+        {
+            cur_focus->onCommit();
+        }
+    }
+
+    // Save SOCKS proxy credentials securely if password auth is enabled
+    LLRadioGroup* socksAuth = getChild<LLRadioGroup>("socks5_auth_type");
+    if (socksAuth->getSelectedValue().asString() == "UserPass")
+    {
+        LLSD socks_id = LLSD::emptyMap();
+        socks_id["type"] = "SOCKS5";
+        socks_id["username"] = getChild<LLLineEditor>("socks5_username")->getValue().asString();
+
+        LLSD socks_authenticator = LLSD::emptyMap();
+        socks_authenticator["type"] = "SOCKS5";
+        socks_authenticator["creds"] = getChild<LLLineEditor>("socks5_password")->getValue().asString();
+
+        // Using "SOCKS5" as the "grid" argument since the same proxy
+        // settings will be used for all grids and because there is no
+        // way to specify the type of credential.
+        LLPointer<LLCredential> socks_cred = gSecAPIHandler->createCredential("SOCKS5", socks_id, socks_authenticator);
+        gSecAPIHandler->saveCredential(socks_cred, true);
+    }
+    else
+    {
+        // Clear SOCKS5 credentials since they are no longer needed.
+        LLPointer<LLCredential> socks_cred = new LLCredential("SOCKS5");
+        gSecAPIHandler->deleteCredential(socks_cred);
+    }
+
+    closeFloater(false);
 }
 
 void LLFloaterPreferenceProxy::onBtnCancel()
 {
-	if (hasFocus())
-	{
-		LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
-		if (cur_focus && cur_focus->acceptsTextInput())
-		{
-			cur_focus->onCommit();
-		}
-		refresh();
-	}
+    if (hasFocus())
+    {
+        LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
+        if (cur_focus && cur_focus->acceptsTextInput())
+        {
+            cur_focus->onCommit();
+        }
+        refresh();
+    }
 
-	cancel();
+    cancel();
 }
 
 void LLFloaterPreferenceProxy::onClickCloseBtn(bool app_quitting)
 {
-	cancel();
+    cancel();
 }
 
 void LLFloaterPreferenceProxy::cancel()
 {
 
-	for (control_values_map_t::iterator iter =  mSavedValues.begin();
-			iter !=  mSavedValues.end(); ++iter)
-	{
-		LLControlVariable* control = iter->first;
-		LLSD ctrl_value = iter->second;
-		control->set(ctrl_value);
-	}
-	mSocksSettingsDirty = false;
-	closeFloater();
+    for (control_values_map_t::iterator iter =  mSavedValues.begin();
+            iter !=  mSavedValues.end(); ++iter)
+    {
+        LLControlVariable* control = iter->first;
+        LLSD ctrl_value = iter->second;
+        control->set(ctrl_value);
+    }
+    mSocksSettingsDirty = false;
+    closeFloater();
 }
 
-void LLFloaterPreferenceProxy::onChangeSocksSettings() 
+void LLFloaterPreferenceProxy::onChangeSocksSettings()
 {
-	mSocksSettingsDirty = true;
+    mSocksSettingsDirty = true;
 
-	LLRadioGroup* socksAuth = getChild<LLRadioGroup>("socks5_auth_type");
-	if (socksAuth->getSelectedValue().asString() == "None")
-	{
-		getChild<LLLineEditor>("socks5_username")->setEnabled(false);
-		getChild<LLLineEditor>("socks5_password")->setEnabled(false);
-	}
-	else
-	{
-		getChild<LLLineEditor>("socks5_username")->setEnabled(true);
-		getChild<LLLineEditor>("socks5_password")->setEnabled(true);
-	}
+    LLRadioGroup* socksAuth = getChild<LLRadioGroup>("socks5_auth_type");
+    if (socksAuth->getSelectedValue().asString() == "None")
+    {
+        getChild<LLLineEditor>("socks5_username")->setEnabled(false);
+        getChild<LLLineEditor>("socks5_password")->setEnabled(false);
+    }
+    else
+    {
+        getChild<LLLineEditor>("socks5_username")->setEnabled(true);
+        getChild<LLLineEditor>("socks5_password")->setEnabled(true);
+    }
 
-	// Check for invalid states for the other HTTP proxy radio
-	LLRadioGroup* otherHttpProxy = getChild<LLRadioGroup>("other_http_proxy_type");
-	if ((otherHttpProxy->getSelectedValue().asString() == "Socks" &&
-			getChild<LLCheckBoxCtrl>("socks_proxy_enabled")->get() == FALSE )||(
-					otherHttpProxy->getSelectedValue().asString() == "Web" &&
-					getChild<LLCheckBoxCtrl>("web_proxy_enabled")->get() == FALSE ) )
-	{
-		otherHttpProxy->selectFirstItem();
-	}
+    // Check for invalid states for the other HTTP proxy radio
+    LLRadioGroup* otherHttpProxy = getChild<LLRadioGroup>("other_http_proxy_type");
+    if ((otherHttpProxy->getSelectedValue().asString() == "Socks" &&
+            getChild<LLCheckBoxCtrl>("socks_proxy_enabled")->get() == FALSE )||(
+                    otherHttpProxy->getSelectedValue().asString() == "Web" &&
+                    getChild<LLCheckBoxCtrl>("web_proxy_enabled")->get() == FALSE ) )
+    {
+        otherHttpProxy->selectFirstItem();
+    }
 
 }
 
 void LLFloaterPreference::onUpdateFilterTerm(bool force)
 {
-	LLWString seachValue = utf8str_to_wstring( mFilterEdit->getValue().asString() );
-	LLWStringUtil::toLower( seachValue );
+    LLWString seachValue = utf8str_to_wstring( mFilterEdit->getValue().asString() );
+    LLWStringUtil::toLower( seachValue );
 
-	if( !mSearchData || (mSearchData->mLastFilter == seachValue && !force))
-		return;
+    if( !mSearchData || (mSearchData->mLastFilter == seachValue && !force))
+        return;
 
     if (mSearchDataDirty)
     {
@@ -3693,17 +3693,17 @@ void LLFloaterPreference::onUpdateFilterTerm(bool force)
         collectSearchableItems();
     }
 
-	mSearchData->mLastFilter = seachValue;
+    mSearchData->mLastFilter = seachValue;
 
-	if( !mSearchData->mRootTab )
-		return;
+    if( !mSearchData->mRootTab )
+        return;
 
-	mSearchData->mRootTab->hightlightAndHide( seachValue );
+    mSearchData->mRootTab->hightlightAndHide( seachValue );
     filterIgnorableNotifications();
 
-	LLTabContainer *pRoot = getChild< LLTabContainer >( "pref core" );
-	if( pRoot )
-		pRoot->selectFirstTab();
+    LLTabContainer *pRoot = getChild< LLTabContainer >( "pref core" );
+    if( pRoot )
+        pRoot->selectFirstTab();
 }
 
 void LLFloaterPreference::filterIgnorableNotifications()
@@ -3719,91 +3719,91 @@ void LLFloaterPreference::filterIgnorableNotifications()
 
 void collectChildren( LLView const *aView, ll::prefs::PanelDataPtr aParentPanel, ll::prefs::TabContainerDataPtr aParentTabContainer )
 {
-	if( !aView )
-		return;
-
-	llassert_always( aParentPanel || aParentTabContainer );
-
-	LLView::child_list_const_iter_t itr = aView->beginChild();
-	LLView::child_list_const_iter_t itrEnd = aView->endChild();
-
-	while( itr != itrEnd )
-	{
-		LLView *pView = *itr;
-		ll::prefs::PanelDataPtr pCurPanelData = aParentPanel;
-		ll::prefs::TabContainerDataPtr pCurTabContainer = aParentTabContainer;
-		if( !pView )
-			continue;
-		LLPanel const *pPanel = dynamic_cast< LLPanel const *>( pView );
-		LLTabContainer const *pTabContainer = dynamic_cast< LLTabContainer const *>( pView );
-		ll::ui::SearchableControl const *pSCtrl = dynamic_cast< ll::ui::SearchableControl const *>( pView );
-
-		if( pTabContainer )
-		{
-			pCurPanelData.reset();
-
-			pCurTabContainer                = std::make_shared<ll::prefs::TabContainerData>();
-			pCurTabContainer->mTabContainer = const_cast< LLTabContainer *>( pTabContainer );
-			pCurTabContainer->mLabel        = pTabContainer->getLabel();
-			pCurTabContainer->mPanel        = 0;
-
-			if( aParentPanel )
-				aParentPanel->mChildPanel.push_back( pCurTabContainer );
-			if( aParentTabContainer )
-				aParentTabContainer->mChildPanel.push_back( pCurTabContainer );
-		}
-		else if( pPanel )
-		{
-			pCurTabContainer.reset();
-
-			pCurPanelData         = std::make_shared<ll::prefs::PanelData>();
-			pCurPanelData->mPanel = pPanel;
-			pCurPanelData->mLabel = pPanel->getLabel();
-
-			llassert_always( aParentPanel || aParentTabContainer );
-
-			if( aParentTabContainer )
-				aParentTabContainer->mChildPanel.push_back( pCurPanelData );
-			else if( aParentPanel )
-				aParentPanel->mChildPanel.push_back( pCurPanelData );
-		}
-		else if( pSCtrl && pSCtrl->getSearchText().size() )
-		{
-			ll::prefs::SearchableItemPtr item = std::make_shared<ll::prefs::SearchableItem>();
-			item->mView                       = pView;
-			item->mCtrl                       = pSCtrl;
-
-			item->mLabel = utf8str_to_wstring( pSCtrl->getSearchText() );
-			LLWStringUtil::toLower( item->mLabel );
-
-			llassert_always( aParentPanel || aParentTabContainer );
-
-			if( aParentPanel )
-				aParentPanel->mChildren.push_back( item );
-			if( aParentTabContainer )
-				aParentTabContainer->mChildren.push_back( item );
-		}
-		collectChildren( pView, pCurPanelData, pCurTabContainer );
-		++itr;
-	}
+    if( !aView )
+        return;
+
+    llassert_always( aParentPanel || aParentTabContainer );
+
+    LLView::child_list_const_iter_t itr = aView->beginChild();
+    LLView::child_list_const_iter_t itrEnd = aView->endChild();
+
+    while( itr != itrEnd )
+    {
+        LLView *pView = *itr;
+        ll::prefs::PanelDataPtr pCurPanelData = aParentPanel;
+        ll::prefs::TabContainerDataPtr pCurTabContainer = aParentTabContainer;
+        if( !pView )
+            continue;
+        LLPanel const *pPanel = dynamic_cast< LLPanel const *>( pView );
+        LLTabContainer const *pTabContainer = dynamic_cast< LLTabContainer const *>( pView );
+        ll::ui::SearchableControl const *pSCtrl = dynamic_cast< ll::ui::SearchableControl const *>( pView );
+
+        if( pTabContainer )
+        {
+            pCurPanelData.reset();
+
+            pCurTabContainer                = std::make_shared<ll::prefs::TabContainerData>();
+            pCurTabContainer->mTabContainer = const_cast< LLTabContainer *>( pTabContainer );
+            pCurTabContainer->mLabel        = pTabContainer->getLabel();
+            pCurTabContainer->mPanel        = 0;
+
+            if( aParentPanel )
+                aParentPanel->mChildPanel.push_back( pCurTabContainer );
+            if( aParentTabContainer )
+                aParentTabContainer->mChildPanel.push_back( pCurTabContainer );
+        }
+        else if( pPanel )
+        {
+            pCurTabContainer.reset();
+
+            pCurPanelData         = std::make_shared<ll::prefs::PanelData>();
+            pCurPanelData->mPanel = pPanel;
+            pCurPanelData->mLabel = pPanel->getLabel();
+
+            llassert_always( aParentPanel || aParentTabContainer );
+
+            if( aParentTabContainer )
+                aParentTabContainer->mChildPanel.push_back( pCurPanelData );
+            else if( aParentPanel )
+                aParentPanel->mChildPanel.push_back( pCurPanelData );
+        }
+        else if( pSCtrl && pSCtrl->getSearchText().size() )
+        {
+            ll::prefs::SearchableItemPtr item = std::make_shared<ll::prefs::SearchableItem>();
+            item->mView                       = pView;
+            item->mCtrl                       = pSCtrl;
+
+            item->mLabel = utf8str_to_wstring( pSCtrl->getSearchText() );
+            LLWStringUtil::toLower( item->mLabel );
+
+            llassert_always( aParentPanel || aParentTabContainer );
+
+            if( aParentPanel )
+                aParentPanel->mChildren.push_back( item );
+            if( aParentTabContainer )
+                aParentTabContainer->mChildren.push_back( item );
+        }
+        collectChildren( pView, pCurPanelData, pCurTabContainer );
+        ++itr;
+    }
 }
 
 void LLFloaterPreference::collectSearchableItems()
 {
-	mSearchData.reset( nullptr );
-	LLTabContainer *pRoot = getChild< LLTabContainer >( "pref core" );
-	if( mFilterEdit && pRoot )
-	{
-		mSearchData.reset(new ll::prefs::SearchData() );
+    mSearchData.reset( nullptr );
+    LLTabContainer *pRoot = getChild< LLTabContainer >( "pref core" );
+    if( mFilterEdit && pRoot )
+    {
+        mSearchData.reset(new ll::prefs::SearchData() );
 
-		ll::prefs::TabContainerDataPtr pRootTabcontainer = std::make_shared<ll::prefs::TabContainerData>();
-		pRootTabcontainer->mTabContainer                 = pRoot;
-		pRootTabcontainer->mLabel                        = pRoot->getLabel();
-		mSearchData->mRootTab                            = pRootTabcontainer;
+        ll::prefs::TabContainerDataPtr pRootTabcontainer = std::make_shared<ll::prefs::TabContainerData>();
+        pRootTabcontainer->mTabContainer                 = pRoot;
+        pRootTabcontainer->mLabel                        = pRoot->getLabel();
+        mSearchData->mRootTab                            = pRootTabcontainer;
 
-		collectChildren( this, ll::prefs::PanelDataPtr(), pRootTabcontainer );
-	}
-	mSearchDataDirty = false;
+        collectChildren( this, ll::prefs::PanelDataPtr(), pRootTabcontainer );
+    }
+    mSearchDataDirty = false;
 }
 
 void LLFloaterPreference::saveIgnoredNotifications()
diff --git a/indra/newview/llfloaterpreference.h b/indra/newview/llfloaterpreference.h
index ca5de03a3c01fbd682c4113d463e75d38248f1fb..248bc5002cfcdb67b683ec05b8d0cca47cd5cf85 100644
--- a/indra/newview/llfloaterpreference.h
+++ b/indra/newview/llfloaterpreference.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llfloaterpreference.h
  * @brief LLPreferenceCore class definition
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -55,223 +55,223 @@ struct skin_t;
 
 namespace ll
 {
-	namespace prefs
-	{
-		struct SearchData;
-	}
+    namespace prefs
+    {
+        struct SearchData;
+    }
 }
 
 typedef std::map<std::string, std::string> notifications_map;
 
 typedef enum
-	{
-		GS_LOW_GRAPHICS,
-		GS_MID_GRAPHICS,
-		GS_HIGH_GRAPHICS,
-		GS_ULTRA_GRAPHICS
-		
-	} EGraphicsSettings;
+    {
+        GS_LOW_GRAPHICS,
+        GS_MID_GRAPHICS,
+        GS_HIGH_GRAPHICS,
+        GS_ULTRA_GRAPHICS
+
+    } EGraphicsSettings;
 
 // Floater to control preferences (display, audio, bandwidth, general.
 class LLFloaterPreference final : public LLFloater, public LLAvatarPropertiesObserver, public LLConversationLogObserver
 {
-public: 
-	LLFloaterPreference(const LLSD& key);
-	~LLFloaterPreference();
-
-	void apply();
-	void cancel();
-	/*virtual*/ void draw();
-	/*virtual*/ BOOL postBuild();
-	/*virtual*/ void onOpen(const LLSD& key);
-	/*virtual*/	void onClose(bool app_quitting);
-	/*virtual*/ void changed();
-	/*virtual*/ void changed(const LLUUID& session_id, U32 mask) {};
-
-	// static data update, called from message handler
-	static void updateUserInfo(const std::string& visibility, bool im_via_email, bool is_verified_email, const std::string& email);
-
-	// refresh all the graphics preferences menus
-	static void refreshEnabledGraphics();
-	
-	// translate user's do not disturb response message according to current locale if message is default, otherwise do nothing
-	static void initDoNotDisturbResponse();
-
-	// update Show Favorites checkbox
-	static void updateShowFavoritesCheckbox(bool val);
-
-	void processProperties( void* pData, EAvatarProcessorType type );
-	void saveAvatarProperties( void );
+public:
+    LLFloaterPreference(const LLSD& key);
+    ~LLFloaterPreference();
+
+    void apply();
+    void cancel();
+    /*virtual*/ void draw();
+    /*virtual*/ BOOL postBuild();
+    /*virtual*/ void onOpen(const LLSD& key);
+    /*virtual*/ void onClose(bool app_quitting);
+    /*virtual*/ void changed();
+    /*virtual*/ void changed(const LLUUID& session_id, U32 mask) {};
+
+    // static data update, called from message handler
+    static void updateUserInfo(const std::string& visibility, bool im_via_email, bool is_verified_email, const std::string& email);
+
+    // refresh all the graphics preferences menus
+    static void refreshEnabledGraphics();
+
+    // translate user's do not disturb response message according to current locale if message is default, otherwise do nothing
+    static void initDoNotDisturbResponse();
+
+    // update Show Favorites checkbox
+    static void updateShowFavoritesCheckbox(bool val);
+
+    void processProperties( void* pData, EAvatarProcessorType type );
+    void saveAvatarProperties( void );
     static void saveAvatarPropertiesCoro(const std::string url, bool allow_publish);
-	void selectPrivacyPanel();
-	void selectChatPanel();
-	void getControlNames(std::vector<std::string>& names);
-	// updates click/double-click action controls depending on values from settings.xml
-	void updateClickActionViews();
+    void selectPrivacyPanel();
+    void selectChatPanel();
+    void getControlNames(std::vector<std::string>& names);
+    // updates click/double-click action controls depending on values from settings.xml
+    void updateClickActionViews();
     void updateSearchableItems();
 
-	void		onBtnOK(const LLSD& userdata);
-	void		onBtnCancel(const LLSD& userdata);
-
-protected:	
-
-	void		onClickClearCache();			// Clear viewer texture cache, file cache on next startup
-	void		onClickBrowserClearCache();		// Clear web history and caches as well as viewer caches above
-	void		onLanguageChange();
-	void		onNotificationsChange(const std::string& OptionName);
-	void		onNameTagOpacityChange(const LLSD& newvalue);
-
-	// set value of "DoNotDisturbResponseChanged" in account settings depending on whether do not disturb response
-	// string differs from default after user changes.
-	void onDoNotDisturbResponseChanged();
-	void onRejectTeleportOffersResponseChanged();
-	// if the custom settings box is clicked
-	void onChangeCustom();
-	void updateMeterText(LLUICtrl* ctrl);
-	// callback for defaults
-	void setHardwareDefaults();
-	void setRecommended();
-	// callback for when client modifies a render option
+    void        onBtnOK(const LLSD& userdata);
+    void        onBtnCancel(const LLSD& userdata);
+
+protected:
+
+    void        onClickClearCache();            // Clear viewer texture cache, file cache on next startup
+    void        onClickBrowserClearCache();     // Clear web history and caches as well as viewer caches above
+    void        onLanguageChange();
+    void        onNotificationsChange(const std::string& OptionName);
+    void        onNameTagOpacityChange(const LLSD& newvalue);
+
+    // set value of "DoNotDisturbResponseChanged" in account settings depending on whether do not disturb response
+    // string differs from default after user changes.
+    void onDoNotDisturbResponseChanged();
+    void onRejectTeleportOffersResponseChanged();
+    // if the custom settings box is clicked
+    void onChangeCustom();
+    void updateMeterText(LLUICtrl* ctrl);
+    // callback for defaults
+    void setHardwareDefaults();
+    void setRecommended();
+    // callback for when client modifies a render option
     void onRenderOptionEnable();
-	// callback for when client turns on impostors
-	void onAvatarImpostorsEnable();
+    // callback for when client turns on impostors
+    void onAvatarImpostorsEnable();
 
-	// callback for commit in the "Single click on land" and "Double click on land" comboboxes.
-	void onClickActionChange();
-	// updates click/double-click action keybindngs depending on view values
-	void updateClickActionControls();
+    // callback for commit in the "Single click on land" and "Double click on land" comboboxes.
+    void onClickActionChange();
+    // updates click/double-click action keybindngs depending on view values
+    void updateClickActionControls();
 
 public:
-	// This function squirrels away the current values of the controls so that
-	// cancel() can restore them.	
-	void saveSettings();
-
-	void saveIgnoredNotifications();
-	void restoreIgnoredNotifications();
-
-	void setCacheLocation(const LLStringExplicit& location);
-
-	void onClickSetCache();
-	void changeCachePath(const std::vector<std::string>& filenames, std::string proposed_name);
-	void onClickResetCache();
-	void onClickSetSounds();
-	void onClickEnablePopup();
-	void onClickDisablePopup();	
-	void resetAllIgnored();
-	void setAllIgnored();
-	void onClickLogPath();
-	void changeLogPath(const std::vector<std::string>& filenames, std::string proposed_name);
-	bool moveTranscriptsAndLog();
-	void enableHistory();
-	void setPersonalInfo(const std::string& visibility, bool im_via_email, bool is_verified_email, const std::string& email);
-	void refreshEnabledState();
-	void onCommitWindowedMode();
-	void refresh();	// Refresh enable/disable
-	// if the quality radio buttons are changed
-	void onChangeQuality(const LLSD& data);
-	
-	void refreshUI();
-
-	void onCommitMediaEnabled();
-	void onCommitMusicEnabled();
-	void applyResolution();
-	void onChangeMaturity();
-	void onChangeModelFolder();
+    // This function squirrels away the current values of the controls so that
+    // cancel() can restore them.
+    void saveSettings();
+
+    void saveIgnoredNotifications();
+    void restoreIgnoredNotifications();
+
+    void setCacheLocation(const LLStringExplicit& location);
+
+    void onClickSetCache();
+    void changeCachePath(const std::vector<std::string>& filenames, std::string proposed_name);
+    void onClickResetCache();
+    void onClickSetSounds();
+    void onClickEnablePopup();
+    void onClickDisablePopup();
+    void resetAllIgnored();
+    void setAllIgnored();
+    void onClickLogPath();
+    void changeLogPath(const std::vector<std::string>& filenames, std::string proposed_name);
+    bool moveTranscriptsAndLog();
+    void enableHistory();
+    void setPersonalInfo(const std::string& visibility, bool im_via_email, bool is_verified_email, const std::string& email);
+    void refreshEnabledState();
+    void onCommitWindowedMode();
+    void refresh(); // Refresh enable/disable
+    // if the quality radio buttons are changed
+    void onChangeQuality(const LLSD& data);
+
+    void refreshUI();
+
+    void onCommitMediaEnabled();
+    void onCommitMusicEnabled();
+    void applyResolution();
+    void onChangeMaturity();
+    void onChangeModelFolder();
     void onChangePBRFolder();
-	void onChangeTextureFolder();
-	void onChangeSoundFolder();
-	void onChangeAnimationFolder();
-	void onClickBlockList();
-	void onClickProxySettings();
-	void onClickTranslationSettings();
-	void onClickPermsDefault();
-	void onClickRememberedUsernames();
-	void onClickAutoReplace();
-	void onClickSpellChecker();
-	void onClickRenderExceptions();
-	void onClickAutoAdjustments();
-	void onClickAdvanced();
-	void applyUIColor(LLUICtrl* ctrl, const LLSD& param);
-	void getUIColor(LLUICtrl* ctrl, const LLSD& param);
-	void onLogChatHistorySaved();	
-	void buildPopupLists();
-	static void refreshSkin(void* data);
-	void selectPanel(const LLSD& name);
-	void saveCameraPreset(std::string& preset);
-	void saveGraphicsPreset(std::string& preset);
+    void onChangeTextureFolder();
+    void onChangeSoundFolder();
+    void onChangeAnimationFolder();
+    void onClickBlockList();
+    void onClickProxySettings();
+    void onClickTranslationSettings();
+    void onClickPermsDefault();
+    void onClickRememberedUsernames();
+    void onClickAutoReplace();
+    void onClickSpellChecker();
+    void onClickRenderExceptions();
+    void onClickAutoAdjustments();
+    void onClickAdvanced();
+    void applyUIColor(LLUICtrl* ctrl, const LLSD& param);
+    void getUIColor(LLUICtrl* ctrl, const LLSD& param);
+    void onLogChatHistorySaved();
+    void buildPopupLists();
+    static void refreshSkin(void* data);
+    void selectPanel(const LLSD& name);
+    void saveCameraPreset(std::string& preset);
+    void saveGraphicsPreset(std::string& preset);
 
     void setRecommendedSettings();
     void resetAutotuneSettings();
 
 private:
 
-	void onDeleteTranscripts();
-	void onDeleteTranscriptsResponse(const LLSD& notification, const LLSD& response);
-	void updateDeleteTranscriptsButton();
-	void updateMaxComplexity();
+    void onDeleteTranscripts();
+    void onDeleteTranscriptsResponse(const LLSD& notification, const LLSD& response);
+    void updateDeleteTranscriptsButton();
+    void updateMaxComplexity();
     void updateComplexityText();
-	static bool loadFromFilename(const std::string& filename, std::map<std::string, std::string> &label_map);
+    static bool loadFromFilename(const std::string& filename, std::map<std::string, std::string> &label_map);
 
 #ifndef LL_HAVOK
-	void refreshGridList();
-	void onClickAddGrid();
+    void refreshGridList();
+    void onClickAddGrid();
     void onClickActivateGrid();
-	void onClickRemoveGrid();
-	void onClickRefreshGrid();
-	void onClickDebugGrid();
-	void onSelectGrid(const LLSD& data);
-	bool handleRemoveGridCB(const LLSD& notification, const LLSD& response);
+    void onClickRemoveGrid();
+    void onClickRefreshGrid();
+    void onClickDebugGrid();
+    void onSelectGrid(const LLSD& data);
+    bool handleRemoveGridCB(const LLSD& notification, const LLSD& response);
 #endif
 
-	void loadUserSkins();
-	void reloadSkinList();
-	void onAddSkin();
-	void onAddSkinCallback(const std::vector<std::string>& filenames);
-	void onRemoveSkin();
-	void callbackRemoveSkin(const LLSD& notification, const LLSD& response);
-	void onApplySkin();
-	void callbackApplySkin(const LLSD& notification, const LLSD& response);
-	void onSelectSkin(const LLSD& data);
-	void refreshSkinInfo(const skin_t& skin);
-
-	static std::string sSkin;
-	notifications_map mNotificationOptions;
-	bool mGotPersonalInfo;
-	bool mOriginalIMViaEmail;
-	bool mLanguageChanged;
-	bool mAvatarDataInitialized;
-	std::string mPriorInstantMessageLogPath;
-	
-	bool mOriginalHideOnlineStatus;
-	std::string mDirectoryVisibility;
-	
-	bool mAllowPublish; // Allow showing agent in search
-	std::string mSavedCameraPreset;
-	std::string mSavedGraphicsPreset;
-
-	typedef std::map<std::string, skin_t> skinmap_t;
-	skinmap_t mUserSkins;
-	
+    void loadUserSkins();
+    void reloadSkinList();
+    void onAddSkin();
+    void onAddSkinCallback(const std::vector<std::string>& filenames);
+    void onRemoveSkin();
+    void callbackRemoveSkin(const LLSD& notification, const LLSD& response);
+    void onApplySkin();
+    void callbackApplySkin(const LLSD& notification, const LLSD& response);
+    void onSelectSkin(const LLSD& data);
+    void refreshSkinInfo(const skin_t& skin);
+
+    static std::string sSkin;
+    notifications_map mNotificationOptions;
+    bool mGotPersonalInfo;
+    bool mOriginalIMViaEmail;
+    bool mLanguageChanged;
+    bool mAvatarDataInitialized;
+    std::string mPriorInstantMessageLogPath;
+
+    bool mOriginalHideOnlineStatus;
+    std::string mDirectoryVisibility;
+
+    bool mAllowPublish; // Allow showing agent in search
+    std::string mSavedCameraPreset;
+    std::string mSavedGraphicsPreset;
+
+    typedef std::map<std::string, skin_t> skinmap_t;
+    skinmap_t mUserSkins;
+
 #if !LL_HAVOK
-	boost::signals2::connection mGridListChangedConnection;
+    boost::signals2::connection mGridListChangedConnection;
 #endif
 
-	LOG_CLASS(LLFloaterPreference);
+    LOG_CLASS(LLFloaterPreference);
 
-	LLSearchEditor *mFilterEdit;
-	std::unique_ptr< ll::prefs::SearchData > mSearchData;
-	bool mSearchDataDirty;
+    LLSearchEditor *mFilterEdit;
+    std::unique_ptr< ll::prefs::SearchData > mSearchData;
+    bool mSearchDataDirty;
 
-    boost::signals2::connection	mComplexityChangedSignal;
-	boost::signals2::connection mDnDModeConnection;
-	boost::signals2::connection mRejectTeleportConnection;
-	boost::signals2::connection mChatBubbleOpacityConnection;
-	boost::signals2::connection mPreferredMaturityConnection;
+    boost::signals2::connection mComplexityChangedSignal;
+    boost::signals2::connection mDnDModeConnection;
+    boost::signals2::connection mRejectTeleportConnection;
+    boost::signals2::connection mChatBubbleOpacityConnection;
+    boost::signals2::connection mPreferredMaturityConnection;
 
-	bool mDnDInit = false;
+    bool mDnDInit = false;
 
-	void onUpdateFilterTerm( bool force = false );
-	void collectSearchableItems();
+    void onUpdateFilterTerm( bool force = false );
+    void collectSearchableItems();
     void filterIgnorableNotifications();
 
     std::map<std::string, bool> mIgnorableNotifs;
@@ -280,90 +280,90 @@ class LLFloaterPreference final : public LLFloater, public LLAvatarPropertiesObs
 class LLPanelPreference : public LLPanel
 {
 public:
-	LLPanelPreference();
-	/*virtual*/ BOOL postBuild();
-	
-	virtual ~LLPanelPreference();
+    LLPanelPreference();
+    /*virtual*/ BOOL postBuild();
 
-	virtual void apply();
-	virtual void cancel();
-	void setControlFalse(const LLSD& user_data);
-	virtual void setHardwareDefaults();
+    virtual ~LLPanelPreference();
 
-	// Disables "Allow Media to auto play" check box only when both
-	// "Streaming Music" and "Media" are unchecked. Otherwise enables it.
-	void updateMediaAutoPlayCheckbox(LLUICtrl* ctrl);
+    virtual void apply();
+    virtual void cancel();
+    void setControlFalse(const LLSD& user_data);
+    virtual void setHardwareDefaults();
 
-	// This function squirrels away the current values of the controls so that
-	// cancel() can restore them.
-	virtual void saveSettings();
+    // Disables "Allow Media to auto play" check box only when both
+    // "Streaming Music" and "Media" are unchecked. Otherwise enables it.
+    void updateMediaAutoPlayCheckbox(LLUICtrl* ctrl);
 
-	void deletePreset(const LLSD& user_data);
-	void savePreset(const LLSD& user_data);
-	void loadPreset(const LLSD& user_data);
+    // This function squirrels away the current values of the controls so that
+    // cancel() can restore them.
+    virtual void saveSettings();
 
-	class Updater;
+    void deletePreset(const LLSD& user_data);
+    void savePreset(const LLSD& user_data);
+    void loadPreset(const LLSD& user_data);
+
+    class Updater;
 
 protected:
-	typedef std::map<LLControlVariable*, LLSD> control_values_map_t;
-	control_values_map_t mSavedValues;
+    typedef std::map<LLControlVariable*, LLSD> control_values_map_t;
+    control_values_map_t mSavedValues;
 
 private:
-	//for "Only friends and groups can call or IM me"
-	static void showFriendsOnlyWarning(LLUICtrl*, const LLSD&);
+    //for "Only friends and groups can call or IM me"
+    static void showFriendsOnlyWarning(LLUICtrl*, const LLSD&);
     //for  "Allow Multiple Viewers"
     static void showMultipleViewersWarning(LLUICtrl*, const LLSD&);
-	//for "Show my Favorite Landmarks at Login"
-	static void handleFavoritesOnLoginChanged(LLUICtrl* checkbox, const LLSD& value);
+    //for "Show my Favorite Landmarks at Login"
+    static void handleFavoritesOnLoginChanged(LLUICtrl* checkbox, const LLSD& value);
 
-	static void toggleMuteWhenMinimized();
-	typedef std::map<std::string, LLColor4> string_color_map_t;
-	string_color_map_t mSavedColors;
+    static void toggleMuteWhenMinimized();
+    typedef std::map<std::string, LLColor4> string_color_map_t;
+    string_color_map_t mSavedColors;
 
-	Updater* mBandWidthUpdater;
-	boost::signals2::connection mBandwithConnection;
-	LOG_CLASS(LLPanelPreference);
+    Updater* mBandWidthUpdater;
+    boost::signals2::connection mBandwithConnection;
+    LOG_CLASS(LLPanelPreference);
 };
 
 class LLPanelPreferenceGraphics final : public LLPanelPreference
 {
 public:
-	BOOL postBuild();
-	void draw();
-	void cancel();
-	void saveSettings();
-	void resetDirtyChilds();
-	void setHardwareDefaults();
-	void setPresetText();
+    BOOL postBuild();
+    void draw();
+    void cancel();
+    void saveSettings();
+    void resetDirtyChilds();
+    void setHardwareDefaults();
+    void setPresetText();
 
-	static const std::string getPresetsPath();
+    static const std::string getPresetsPath();
 
 protected:
-	bool hasDirtyChilds();
+    bool hasDirtyChilds();
 
 private:
-	void onPresetsListChange();
-	LOG_CLASS(LLPanelPreferenceGraphics);
+    void onPresetsListChange();
+    LOG_CLASS(LLPanelPreferenceGraphics);
 };
 
 class LLPanelPreferenceControls final : public LLPanelPreference, public LLKeyBindResponderInterface
 {
-	LOG_CLASS(LLPanelPreferenceControls);
+    LOG_CLASS(LLPanelPreferenceControls);
 public:
-	LLPanelPreferenceControls();
-	virtual ~LLPanelPreferenceControls();
+    LLPanelPreferenceControls();
+    virtual ~LLPanelPreferenceControls();
 
-	BOOL postBuild();
+    BOOL postBuild();
 
-	void apply();
-	void cancel();
-	void saveSettings();
-	void resetDirtyChilds();
+    void apply();
+    void cancel();
+    void saveSettings();
+    void resetDirtyChilds();
 
-	void onListCommit();
-	void onModeCommit();
-	void onRestoreDefaultsBtn();
-	void onRestoreDefaultsResponse(const LLSD& notification, const LLSD& response);
+    void onListCommit();
+    void onModeCommit();
+    void onRestoreDefaultsBtn();
+    void onRestoreDefaultsResponse(const LLSD& notification, const LLSD& response);
 
     // Bypass to let Move & view read values without need to create own key binding handler
     // Todo: consider a better way to share access to keybindings
@@ -373,73 +373,73 @@ class LLPanelPreferenceControls final : public LLPanelPreference, public LLKeyBi
     void updateAndApply();
 
     // from interface
-	/*virtual*/ bool onSetKeyBind(EMouseClickType click, KEY key, MASK mask, bool all_modes);
+    /*virtual*/ bool onSetKeyBind(EMouseClickType click, KEY key, MASK mask, bool all_modes);
     /*virtual*/ void onDefaultKeyBind(bool all_modes);
     /*virtual*/ void onCancelKeyBind();
 
 private:
-	// reloads settings, discards current changes, updates table
-	void regenerateControls();
+    // reloads settings, discards current changes, updates table
+    void regenerateControls();
 
-	// These fuctions do not clean previous content
-	bool addControlTableColumns(const std::string &filename);
-	bool addControlTableRows(const std::string &filename);
-	void addControlTableSeparator();
+    // These fuctions do not clean previous content
+    bool addControlTableColumns(const std::string &filename);
+    bool addControlTableRows(const std::string &filename);
+    void addControlTableSeparator();
 
-	// Cleans content and then adds content from xml files according to current mEditingMode
+    // Cleans content and then adds content from xml files according to current mEditingMode
     void populateControlTable();
 
     // Updates keybindings from storage to table
     void updateTable();
 
-	LLScrollListCtrl* pControlsTable;
-	LLComboBox *pKeyModeBox;
-	LLKeyConflictHandler mConflictHandler[LLKeyConflictHandler::MODE_COUNT];
-	std::string mEditingControl;
-	S32 mEditingColumn;
-	S32 mEditingMode;
+    LLScrollListCtrl* pControlsTable;
+    LLComboBox *pKeyModeBox;
+    LLKeyConflictHandler mConflictHandler[LLKeyConflictHandler::MODE_COUNT];
+    std::string mEditingControl;
+    S32 mEditingColumn;
+    S32 mEditingMode;
 };
 
 class LLAvatarComplexityControls
 {
-  public: 
-	static void updateMax(LLSliderCtrl* slider, LLTextBox* value_label, bool short_val = false);
-	static void setText(U32 value, LLTextBox* text_box, bool short_val = false);
-	static void updateMaxRenderTime(LLSliderCtrl* slider, LLTextBox* value_label, bool short_val = false);
-	static void setRenderTimeText(F32 value, LLTextBox* text_box, bool short_val = false);
-	static void setIndirectControls();
-	static void setIndirectMaxNonImpostors();
-	static void setIndirectMaxArc();
-	LOG_CLASS(LLAvatarComplexityControls);
+  public:
+    static void updateMax(LLSliderCtrl* slider, LLTextBox* value_label, bool short_val = false);
+    static void setText(U32 value, LLTextBox* text_box, bool short_val = false);
+    static void updateMaxRenderTime(LLSliderCtrl* slider, LLTextBox* value_label, bool short_val = false);
+    static void setRenderTimeText(F32 value, LLTextBox* text_box, bool short_val = false);
+    static void setIndirectControls();
+    static void setIndirectMaxNonImpostors();
+    static void setIndirectMaxArc();
+    LOG_CLASS(LLAvatarComplexityControls);
 };
 
 class LLFloaterPreferenceProxy final : public LLFloater
 {
-public: 
-	LLFloaterPreferenceProxy(const LLSD& key);
-	~LLFloaterPreferenceProxy();
-
-	/// show off our menu
-	static void show();
-	void cancel();
-	
+public:
+    LLFloaterPreferenceProxy(const LLSD& key);
+    ~LLFloaterPreferenceProxy();
+
+    /// show off our menu
+    static void show();
+    void cancel();
+
 protected:
-	BOOL postBuild();
-	void onOpen(const LLSD& key);
-	void onClose(bool app_quitting);
-	void saveSettings();
-	void onBtnOk();
-	void onBtnCancel();
-	void onClickCloseBtn(bool app_quitting = false);
+    BOOL postBuild();
+    void onOpen(const LLSD& key);
+    void onClose(bool app_quitting);
+    void saveSettings();
+    void onBtnOk();
+    void onBtnCancel();
+    void onClickCloseBtn(bool app_quitting = false);
 
-	void onChangeSocksSettings();
+    void onChangeSocksSettings();
 
 private:
-	
-	bool mSocksSettingsDirty;
-	typedef std::map<LLControlVariable*, LLSD> control_values_map_t;
-	control_values_map_t mSavedValues;
-	LOG_CLASS(LLFloaterPreferenceProxy);
+
+    bool mSocksSettingsDirty;
+    typedef std::map<LLControlVariable*, LLSD> control_values_map_t;
+    control_values_map_t mSavedValues;
+    LOG_CLASS(LLFloaterPreferenceProxy);
 };
 
 
diff --git a/indra/newview/llfloaterregioninfo.cpp b/indra/newview/llfloaterregioninfo.cpp
index 6a4ac6b8bd9f060ee8de2f5b72e48734f7cc804a..1919b0422c614a279a18225cb11349edcb83bc1f 100644
--- a/indra/newview/llfloaterregioninfo.cpp
+++ b/indra/newview/llfloaterregioninfo.cpp
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file llfloaterregioninfo.cpp
  * @author Aaron Brashears
  * @brief Implementation of the region info and controls floater and panels.
@@ -6,21 +6,21 @@
  * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -50,13 +50,13 @@
 #include "llavataractions.h"
 #include "llavatarname.h"
 #include "llfloateravatarpicker.h"
-#include "llbutton.h" 
+#include "llbutton.h"
 #include "llcheckboxctrl.h"
 #include "llclipboard.h"
 #include "llcombobox.h"
 #include "llestateinfomodel.h"
 #include "llfilepicker.h"
-#include "llfloatergodtools.h"	// for send_sim_wide_deletes()
+#include "llfloatergodtools.h"  // for send_sim_wide_deletes()
 #include "llfloatertopobjects.h" // added to fix SL-32336
 #include "llfloatergroups.h"
 #include "llfloaterreg.h"
@@ -114,70 +114,70 @@ const U32 MAX_LISTED_NAMES = 100;
 class LLDispatchEstateUpdateInfo : public LLDispatchHandler
 {
 public:
-	LLDispatchEstateUpdateInfo() {}
-	virtual ~LLDispatchEstateUpdateInfo() {}
-	virtual bool operator()(
-		const LLDispatcher* dispatcher,
-		const std::string& key,
-		const LLUUID& invoice,
-		const sparam_t& strings);
+    LLDispatchEstateUpdateInfo() {}
+    virtual ~LLDispatchEstateUpdateInfo() {}
+    virtual bool operator()(
+        const LLDispatcher* dispatcher,
+        const std::string& key,
+        const LLUUID& invoice,
+        const sparam_t& strings);
 };
 
 class LLDispatchSetEstateAccess : public LLDispatchHandler
 {
 public:
-	LLDispatchSetEstateAccess() {}
-	virtual ~LLDispatchSetEstateAccess() {}
-	virtual bool operator()(
-		const LLDispatcher* dispatcher,
-		const std::string& key,
-		const LLUUID& invoice,
-		const sparam_t& strings);
+    LLDispatchSetEstateAccess() {}
+    virtual ~LLDispatchSetEstateAccess() {}
+    virtual bool operator()(
+        const LLDispatcher* dispatcher,
+        const std::string& key,
+        const LLUUID& invoice,
+        const sparam_t& strings);
 };
 
 class LLDispatchSetEstateExperience : public LLDispatchHandler
 {
 public:
-	virtual bool operator()(
-		const LLDispatcher* dispatcher,
-		const std::string& key,
-		const LLUUID& invoice,
-		const sparam_t& strings);
+    virtual bool operator()(
+        const LLDispatcher* dispatcher,
+        const std::string& key,
+        const LLUUID& invoice,
+        const sparam_t& strings);
 
-	static LLSD getIDs( sparam_t::const_iterator it, sparam_t::const_iterator end, S32 count );
+    static LLSD getIDs( sparam_t::const_iterator it, sparam_t::const_iterator end, S32 count );
 };
 
 
 /*
 void unpack_request_params(
-	LLMessageSystem* msg,
-	LLDispatcher::sparam_t& strings,
-	LLDispatcher::iparam_t& integers)
-{
-	char str_buf[MAX_STRING];
-	S32 str_count = msg->getNumberOfBlocksFast(_PREHASH_StringData);
-	S32 i;
-	for (i = 0; i < str_count; ++i)
-	{
-		// we treat the SParam as binary data (since it might be an 
-		// LLUUID in compressed form which may have embedded \0's,)
-		str_buf[0] = '\0';
-		S32 data_size = msg->getSizeFast(_PREHASH_StringData, i, _PREHASH_SParam);
-		if (data_size >= 0)
-		{
-			msg->getBinaryDataFast(_PREHASH_StringData, _PREHASH_SParam,
-								   str_buf, data_size, i, MAX_STRING - 1);
-			strings.push_back(std::string(str_buf, data_size));
-		}
-	}
-
-	U32 int_buf;
-	S32 int_count = msg->getNumberOfBlocksFast(_PREHASH_IntegerData);
-	for (i = 0; i < int_count; ++i)
-	{
-		msg->getU32("IntegerData", "IParam", int_buf, i);
-		integers.push_back(int_buf);
-	}
+    LLMessageSystem* msg,
+    LLDispatcher::sparam_t& strings,
+    LLDispatcher::iparam_t& integers)
+{
+    char str_buf[MAX_STRING];
+    S32 str_count = msg->getNumberOfBlocksFast(_PREHASH_StringData);
+    S32 i;
+    for (i = 0; i < str_count; ++i)
+    {
+        // we treat the SParam as binary data (since it might be an
+        // LLUUID in compressed form which may have embedded \0's,)
+        str_buf[0] = '\0';
+        S32 data_size = msg->getSizeFast(_PREHASH_StringData, i, _PREHASH_SParam);
+        if (data_size >= 0)
+        {
+            msg->getBinaryDataFast(_PREHASH_StringData, _PREHASH_SParam,
+                                   str_buf, data_size, i, MAX_STRING - 1);
+            strings.push_back(std::string(str_buf, data_size));
+        }
+    }
+
+    U32 int_buf;
+    S32 int_count = msg->getNumberOfBlocksFast(_PREHASH_IntegerData);
+    for (i = 0; i < int_count; ++i)
+    {
+        msg->getU32("IntegerData", "IParam", int_buf, i);
+        integers.push_back(int_buf);
+    }
 }
 */
 
@@ -229,74 +229,74 @@ LLUUID LLFloaterRegionInfo::sRequestInvoice;
 
 
 LLFloaterRegionInfo::LLFloaterRegionInfo(const LLSD& seed)
-	: LLFloater(seed),
+    : LLFloater(seed),
     mEnvironmentPanel(NULL),
     mRegionChangedCallback()
 {}
 
 BOOL LLFloaterRegionInfo::postBuild()
 {
-	mTab = getChild<LLTabContainer>("region_panels");
-	mTab->setCommitCallback(boost::bind(&LLFloaterRegionInfo::onTabSelected, this, _2));
-
-	// contruct the panels
-	LLPanelRegionInfo* panel;
-	panel = new LLPanelEstateInfo;
-	mInfoPanels.push_back(panel);
-	panel->buildFromFile("panel_region_estate.xml");
-	mTab->addTabPanel(LLTabContainer::TabPanelParams().panel(panel).select_tab(true));
-
-	panel = new LLPanelEstateAccess;
-	mInfoPanels.push_back(panel);
-	panel->buildFromFile("panel_region_access.xml");
-	mTab->addTabPanel(panel);
-
-	panel = new LLPanelEstateCovenant;
-	mInfoPanels.push_back(panel);
-	panel->buildFromFile("panel_region_covenant.xml");
-	mTab->addTabPanel(panel);
-
-	panel = new LLPanelRegionGeneralInfo;
-	mInfoPanels.push_back(panel);
-	panel->getCommitCallbackRegistrar().add("RegionInfo.ManageTelehub",	boost::bind(&LLPanelRegionInfo::onClickManageTelehub, panel));
-	panel->buildFromFile("panel_region_general.xml");
-	mTab->addTabPanel(panel);
-
-	panel = new LLPanelRegionTerrainInfo;
-	mInfoPanels.push_back(panel);
-	panel->buildFromFile("panel_region_terrain.xml");
-	mTab->addTabPanel(panel);
+    mTab = getChild<LLTabContainer>("region_panels");
+    mTab->setCommitCallback(boost::bind(&LLFloaterRegionInfo::onTabSelected, this, _2));
+
+    // contruct the panels
+    LLPanelRegionInfo* panel;
+    panel = new LLPanelEstateInfo;
+    mInfoPanels.push_back(panel);
+    panel->buildFromFile("panel_region_estate.xml");
+    mTab->addTabPanel(LLTabContainer::TabPanelParams().panel(panel).select_tab(true));
+
+    panel = new LLPanelEstateAccess;
+    mInfoPanels.push_back(panel);
+    panel->buildFromFile("panel_region_access.xml");
+    mTab->addTabPanel(panel);
+
+    panel = new LLPanelEstateCovenant;
+    mInfoPanels.push_back(panel);
+    panel->buildFromFile("panel_region_covenant.xml");
+    mTab->addTabPanel(panel);
+
+    panel = new LLPanelRegionGeneralInfo;
+    mInfoPanels.push_back(panel);
+    panel->getCommitCallbackRegistrar().add("RegionInfo.ManageTelehub", boost::bind(&LLPanelRegionInfo::onClickManageTelehub, panel));
+    panel->buildFromFile("panel_region_general.xml");
+    mTab->addTabPanel(panel);
+
+    panel = new LLPanelRegionTerrainInfo;
+    mInfoPanels.push_back(panel);
+    panel->buildFromFile("panel_region_terrain.xml");
+    mTab->addTabPanel(panel);
 
     mEnvironmentPanel = new LLPanelRegionEnvironment;
     mEnvironmentPanel->buildFromFile("panel_region_environment.xml");
 //  mEnvironmentPanel->configureForRegion();
     mTab->addTabPanel(mEnvironmentPanel);
 
-	panel = new LLPanelRegionDebugInfo;
-	mInfoPanels.push_back(panel);
-	panel->buildFromFile("panel_region_debug.xml");
-	mTab->addTabPanel(panel);
+    panel = new LLPanelRegionDebugInfo;
+    mInfoPanels.push_back(panel);
+    panel->buildFromFile("panel_region_debug.xml");
+    mTab->addTabPanel(panel);
+
+    if(gDisconnected)
+    {
+        return TRUE;
+    }
 
-	if(gDisconnected)
-	{
-		return TRUE;
-	}
+    if(!gAgent.getRegionCapability("RegionExperiences").empty())
+    {
+        panel = new LLPanelRegionExperiences;
+        mInfoPanels.push_back(panel);
+        panel->buildFromFile("panel_region_experiences.xml");
+        mTab->addTabPanel(panel);
+    }
 
-	if(!gAgent.getRegionCapability("RegionExperiences").empty())
-	{
-		panel = new LLPanelRegionExperiences;
-		mInfoPanels.push_back(panel);
-		panel->buildFromFile("panel_region_experiences.xml");
-		mTab->addTabPanel(panel);
-	}
-	
-	gMessageSystem->setHandlerFuncFast(_PREHASH_EstateOwnerMessage, 
-		&processEstateOwnerRequest);
+    gMessageSystem->setHandlerFuncFast(_PREHASH_EstateOwnerMessage,
+        &processEstateOwnerRequest);
 
-	// Request region info when agent region changes.
-	mRegionChangedCallback = gAgent.addRegionChangedCallback(boost::bind(&LLFloaterRegionInfo::onRegionChanged, this));
+    // Request region info when agent region changes.
+    mRegionChangedCallback = gAgent.addRegionChangedCallback(boost::bind(&LLFloaterRegionInfo::onRegionChanged, this));
 
-	return TRUE;
+    return TRUE;
 }
 
 LLFloaterRegionInfo::~LLFloaterRegionInfo()
@@ -309,26 +309,26 @@ LLFloaterRegionInfo::~LLFloaterRegionInfo()
 
 void LLFloaterRegionInfo::onOpen(const LLSD& key)
 {
-	if(gDisconnected)
-	{
-		disableTabCtrls();
-		return;
-	}
-	refreshFromRegion(gAgent.getRegion());
-	requestRegionInfo();
+    if(gDisconnected)
+    {
+        disableTabCtrls();
+        return;
+    }
+    refreshFromRegion(gAgent.getRegion());
+    requestRegionInfo();
 
-	if (!mGodLevelChangeSlot.connected())
-	{
-		mGodLevelChangeSlot = gAgent.registerGodLevelChanageListener(boost::bind(&LLFloaterRegionInfo::onGodLevelChange, this, _1));
-	}
+    if (!mGodLevelChangeSlot.connected())
+    {
+        mGodLevelChangeSlot = gAgent.registerGodLevelChanageListener(boost::bind(&LLFloaterRegionInfo::onGodLevelChange, this, _1));
+    }
 }
 
 void LLFloaterRegionInfo::onClose(bool app_quitting)
 {
-	if (mGodLevelChangeSlot.connected())
-	{
-		mGodLevelChangeSlot.disconnect();
-	}
+    if (mGodLevelChangeSlot.connected())
+    {
+        mGodLevelChangeSlot.disconnect();
+    }
 }
 
 void LLFloaterRegionInfo::onRegionChanged()
@@ -341,266 +341,266 @@ void LLFloaterRegionInfo::onRegionChanged()
 
 void LLFloaterRegionInfo::requestRegionInfo()
 {
-	LLTabContainer* tab = findChild<LLTabContainer>("region_panels");
-	if (tab)
-	{
-		tab->getChild<LLPanel>("General")->setCtrlsEnabled(FALSE);
-		tab->getChild<LLPanel>("Debug")->setCtrlsEnabled(FALSE);
-		tab->getChild<LLPanel>("Terrain")->setCtrlsEnabled(FALSE);
-		tab->getChild<LLPanel>("Estate")->setCtrlsEnabled(FALSE);
+    LLTabContainer* tab = findChild<LLTabContainer>("region_panels");
+    if (tab)
+    {
+        tab->getChild<LLPanel>("General")->setCtrlsEnabled(FALSE);
+        tab->getChild<LLPanel>("Debug")->setCtrlsEnabled(FALSE);
+        tab->getChild<LLPanel>("Terrain")->setCtrlsEnabled(FALSE);
+        tab->getChild<LLPanel>("Estate")->setCtrlsEnabled(FALSE);
         tab->getChild<LLPanel>("Access")->setCtrlsEnabled(FALSE);
-	}
+    }
 
-	// Must allow anyone to request the RegionInfo data
-	// so non-owners/non-gods can see the values. 
-	// Therefore can't use an EstateOwnerMessage JC
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_RequestRegionInfo);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gAgent.sendReliableMessage();
+    // Must allow anyone to request the RegionInfo data
+    // so non-owners/non-gods can see the values.
+    // Therefore can't use an EstateOwnerMessage JC
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_RequestRegionInfo);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gAgent.sendReliableMessage();
 }
 
 // static
 void LLFloaterRegionInfo::processEstateOwnerRequest(LLMessageSystem* msg,void**)
 {
-	static LLDispatcher dispatch;
-	LLFloaterRegionInfo* floater = LLFloaterReg::findTypedInstance<LLFloaterRegionInfo>("region_info");
-	if(!floater)
-	{
-		return;
-	}
-	
-	if (!estate_dispatch_initialized)
-	{
-		LLPanelEstateInfo::initDispatch(dispatch);
-	}
-
-	LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate();
-
-	// unpack the message
-	std::string request;
-	LLUUID invoice;
-	LLDispatcher::sparam_t strings;
-	LLDispatcher::unpackMessage(msg, request, invoice, strings);
-	if(invoice != getLastInvoice())
-	{
-		LL_WARNS() << "Mismatched Estate message: " << request << LL_ENDL;
-		return;
-	}
-
-	//dispatch the message
-	dispatch.dispatch(request, invoice, strings);
-
-	if (panel)
-	{
-		panel->updateControls(gAgent.getRegion());
-	}
+    static LLDispatcher dispatch;
+    LLFloaterRegionInfo* floater = LLFloaterReg::findTypedInstance<LLFloaterRegionInfo>("region_info");
+    if(!floater)
+    {
+        return;
+    }
+
+    if (!estate_dispatch_initialized)
+    {
+        LLPanelEstateInfo::initDispatch(dispatch);
+    }
+
+    LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate();
+
+    // unpack the message
+    std::string request;
+    LLUUID invoice;
+    LLDispatcher::sparam_t strings;
+    LLDispatcher::unpackMessage(msg, request, invoice, strings);
+    if(invoice != getLastInvoice())
+    {
+        LL_WARNS() << "Mismatched Estate message: " << request << LL_ENDL;
+        return;
+    }
+
+    //dispatch the message
+    dispatch.dispatch(request, invoice, strings);
+
+    if (panel)
+    {
+        panel->updateControls(gAgent.getRegion());
+    }
 }
 
 
 // static
 void LLFloaterRegionInfo::processRegionInfo(LLMessageSystem* msg)
 {
-	LLPanel* panel;
-	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	if(!floater)
-	{
-		return;
-	}
+    LLPanel* panel;
+    LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
+    if(!floater)
+    {
+        return;
+    }
 #if 0
-	// We need to re-request environment setting here,
-	// otherwise after we apply (send) updated region settings we won't get them back,
-	// so our environment won't be updated.
-	// This is also the way to know about externally changed region environment.
-	LLEnvManagerNew::instance().requestRegionSettings();
-#endif	
-	LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
-
-	LLViewerRegion* region = gAgent.getRegion();
-	BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate());
-
-	// *TODO: Replace parsing msg with accessing the region info model.
-	LLRegionInfoModel& region_info = LLRegionInfoModel::instance();
-
-	// extract message
-	std::string sim_name;
-	std::string sim_type = LLTrans::getString("land_type_unknown");
-	U64 region_flags;
-	U8 agent_limit;
-	S32 hard_agent_limit;
-	F32 object_bonus_factor;
-	U8 sim_access;
-	F32 water_height;
-	F32 terrain_raise_limit;
-	F32 terrain_lower_limit;
-	BOOL use_estate_sun;
-	F32 sun_hour;
-	msg->getStringFast(_PREHASH_RegionInfo, _PREHASH_SimName, sim_name);
-	msg->getU8Fast(_PREHASH_RegionInfo, _PREHASH_MaxAgents, agent_limit);
-	msg->getS32Fast(_PREHASH_RegionInfo2, _PREHASH_HardMaxAgents, hard_agent_limit);
-	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_ObjectBonusFactor, object_bonus_factor);
-	msg->getU8Fast(_PREHASH_RegionInfo, _PREHASH_SimAccess, sim_access);
-	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_WaterHeight, water_height);
-	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainRaiseLimit, terrain_raise_limit);
-	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainLowerLimit, terrain_lower_limit);
-	msg->getBOOLFast(_PREHASH_RegionInfo, _PREHASH_UseEstateSun, use_estate_sun);
-	// actually the "last set" sun hour, not the current sun hour. JC
-	msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_SunHour, sun_hour);
-	// the only reasonable way to decide if we actually have any data is to
-	// check to see if any of these fields have nonzero sizes
-	if (msg->getSizeFast(_PREHASH_RegionInfo2, _PREHASH_ProductSKU) > 0 ||
-		msg->getSizeFast(_PREHASH_RegionInfo2, _PREHASH_ProductName) > 0)
-	{
-		msg->getStringFast(_PREHASH_RegionInfo2, _PREHASH_ProductName, sim_type);
-		LLTrans::findString(sim_type, sim_type); // try localizing sim product name
-	}
-
-	if (msg->hasFast(_PREHASH_RegionInfo3))
-	{
-		msg->getU64Fast(_PREHASH_RegionInfo3, _PREHASH_RegionFlagsExtended, region_flags);
-	}
-	else
-	{
-		U32 flags = 0;
-		msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_RegionFlags, flags);
-		region_flags = flags;
-	}
-
-	if (msg->has(_PREHASH_RegionInfo5))
-	{
-		F32 chat_whisper_range;
-		F32 chat_normal_range;
-		F32 chat_shout_range;
-		F32 chat_whisper_offset;
-		F32 chat_normal_offset;
-		F32 chat_shout_offset;
-		U32 chat_flags;
-
-		msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatWhisperRange, chat_whisper_range);
-		msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatNormalRange, chat_normal_range);
-		msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatShoutRange, chat_shout_range);
-		msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatWhisperOffset, chat_whisper_offset);
-		msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatNormalOffset, chat_normal_offset);
-		msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatShoutOffset, chat_shout_offset);
-		msg->getU32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatFlags, chat_flags);
-
-		LL_INFOS() << "Whisper range: " << chat_whisper_range << " normal range: " << chat_normal_range << " shout range: " << chat_shout_range
-			<< " whisper offset: " << chat_whisper_offset << " normal offset: " << chat_normal_offset << " shout offset: " << chat_shout_offset
-			<< " chat flags: " << chat_flags << LL_ENDL;
-	}
-
-	// GENERAL PANEL
-	panel = tab->getChild<LLPanel>("General");
-	panel->getChild<LLUICtrl>("region_text")->setValue(LLSD(sim_name));
-	panel->getChild<LLUICtrl>("region_type")->setValue(LLSD(sim_type));
-	panel->getChild<LLUICtrl>("version_channel_text")->setValue(gLastVersionChannel);
-
-	panel->getChild<LLUICtrl>("block_terraform_check")->setValue((region_flags & REGION_FLAGS_BLOCK_TERRAFORM) ? TRUE : FALSE );
-	panel->getChild<LLUICtrl>("block_fly_check")->setValue((region_flags & REGION_FLAGS_BLOCK_FLY) ? TRUE : FALSE );
-	panel->getChild<LLUICtrl>("block_fly_over_check")->setValue((region_flags & REGION_FLAGS_BLOCK_FLYOVER) ? TRUE : FALSE );
-	panel->getChild<LLUICtrl>("allow_damage_check")->setValue((region_flags & REGION_FLAGS_ALLOW_DAMAGE) ? TRUE : FALSE );
-	panel->getChild<LLUICtrl>("restrict_pushobject")->setValue((region_flags & REGION_FLAGS_RESTRICT_PUSHOBJECT) ? TRUE : FALSE );
-	panel->getChild<LLUICtrl>("allow_land_resell_check")->setValue((region_flags & REGION_FLAGS_BLOCK_LAND_RESELL) ? FALSE : TRUE );
-	panel->getChild<LLUICtrl>("allow_parcel_changes_check")->setValue((region_flags & REGION_FLAGS_ALLOW_PARCEL_CHANGES) ? TRUE : FALSE );
-	panel->getChild<LLUICtrl>("block_parcel_search_check")->setValue((region_flags & REGION_FLAGS_BLOCK_PARCEL_SEARCH) ? TRUE : FALSE );
-	panel->getChild<LLUICtrl>("agent_limit_spin")->setValue(LLSD((F32)agent_limit) );
-	panel->getChild<LLUICtrl>("object_bonus_spin")->setValue(LLSD(object_bonus_factor) );
-	panel->getChild<LLUICtrl>("access_combo")->setValue(LLSD(sim_access) );
-
-	panel->getChild<LLSpinCtrl>("agent_limit_spin")->setMaxValue(hard_agent_limit);
-
-	LLPanelRegionGeneralInfo* panel_general = LLFloaterRegionInfo::getPanelGeneral();
-	if (panel)
-	{
-		panel_general->setObjBonusFactor(object_bonus_factor);
-	}
-
- 	// detect teen grid for maturity
-
-	U32 parent_estate_id;
-	msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_ParentEstateID, parent_estate_id);
-	BOOL teen_grid = (parent_estate_id == 5);  // *TODO add field to estate table and test that
-	panel->getChildView("access_combo")->setEnabled(gAgent.isGodlike() || (region && region->canManageEstate() && !teen_grid));
-	panel->setCtrlsEnabled(allow_modify);
-	
-
-	// DEBUG PANEL
-	panel = tab->getChild<LLPanel>("Debug");
-
-	panel->getChild<LLUICtrl>("region_text")->setValue(LLSD(sim_name) );
-	panel->getChild<LLUICtrl>("disable_scripts_check")->setValue(LLSD((BOOL)((region_flags & REGION_FLAGS_SKIP_SCRIPTS) ? TRUE : FALSE )) );
-	panel->getChild<LLUICtrl>("disable_collisions_check")->setValue(LLSD((BOOL)((region_flags & REGION_FLAGS_SKIP_COLLISIONS) ? TRUE : FALSE )) );
-	panel->getChild<LLUICtrl>("disable_physics_check")->setValue(LLSD((BOOL)((region_flags & REGION_FLAGS_SKIP_PHYSICS) ? TRUE : FALSE )) );
-	panel->setCtrlsEnabled(allow_modify);
-
-	// TERRAIN PANEL
-	panel = tab->getChild<LLPanel>("Terrain");
-
-	panel->getChild<LLUICtrl>("region_text")->setValue(LLSD(sim_name));
-	panel->getChild<LLUICtrl>("water_height_spin")->setValue(region_info.mWaterHeight);
-	panel->getChild<LLUICtrl>("terrain_raise_spin")->setValue(region_info.mTerrainRaiseLimit);
-	panel->getChild<LLUICtrl>("terrain_lower_spin")->setValue(region_info.mTerrainLowerLimit);
-
-	panel->setCtrlsEnabled(allow_modify);
-
-	if (floater->getVisible())
-	{
-		// Note: region info also causes LLRegionInfoModel::instance().update(msg); -> requestRegion(); -> changed message
-		// we need to know env version here and in update(msg) to know when to request and when not to, when to filter 'changed'
-		floater->refreshFromRegion(gAgent.getRegion());
-	} // else will rerequest on onOpen either way
+    // We need to re-request environment setting here,
+    // otherwise after we apply (send) updated region settings we won't get them back,
+    // so our environment won't be updated.
+    // This is also the way to know about externally changed region environment.
+    LLEnvManagerNew::instance().requestRegionSettings();
+#endif
+    LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
+
+    LLViewerRegion* region = gAgent.getRegion();
+    BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate());
+
+    // *TODO: Replace parsing msg with accessing the region info model.
+    LLRegionInfoModel& region_info = LLRegionInfoModel::instance();
+
+    // extract message
+    std::string sim_name;
+    std::string sim_type = LLTrans::getString("land_type_unknown");
+    U64 region_flags;
+    U8 agent_limit;
+    S32 hard_agent_limit;
+    F32 object_bonus_factor;
+    U8 sim_access;
+    F32 water_height;
+    F32 terrain_raise_limit;
+    F32 terrain_lower_limit;
+    BOOL use_estate_sun;
+    F32 sun_hour;
+    msg->getStringFast(_PREHASH_RegionInfo, _PREHASH_SimName, sim_name);
+    msg->getU8Fast(_PREHASH_RegionInfo, _PREHASH_MaxAgents, agent_limit);
+    msg->getS32Fast(_PREHASH_RegionInfo2, _PREHASH_HardMaxAgents, hard_agent_limit);
+    msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_ObjectBonusFactor, object_bonus_factor);
+    msg->getU8Fast(_PREHASH_RegionInfo, _PREHASH_SimAccess, sim_access);
+    msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_WaterHeight, water_height);
+    msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainRaiseLimit, terrain_raise_limit);
+    msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainLowerLimit, terrain_lower_limit);
+    msg->getBOOLFast(_PREHASH_RegionInfo, _PREHASH_UseEstateSun, use_estate_sun);
+    // actually the "last set" sun hour, not the current sun hour. JC
+    msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_SunHour, sun_hour);
+    // the only reasonable way to decide if we actually have any data is to
+    // check to see if any of these fields have nonzero sizes
+    if (msg->getSizeFast(_PREHASH_RegionInfo2, _PREHASH_ProductSKU) > 0 ||
+        msg->getSizeFast(_PREHASH_RegionInfo2, _PREHASH_ProductName) > 0)
+    {
+        msg->getStringFast(_PREHASH_RegionInfo2, _PREHASH_ProductName, sim_type);
+        LLTrans::findString(sim_type, sim_type); // try localizing sim product name
+    }
+
+    if (msg->hasFast(_PREHASH_RegionInfo3))
+    {
+        msg->getU64Fast(_PREHASH_RegionInfo3, _PREHASH_RegionFlagsExtended, region_flags);
+    }
+    else
+    {
+        U32 flags = 0;
+        msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_RegionFlags, flags);
+        region_flags = flags;
+    }
+
+    if (msg->has(_PREHASH_RegionInfo5))
+    {
+        F32 chat_whisper_range;
+        F32 chat_normal_range;
+        F32 chat_shout_range;
+        F32 chat_whisper_offset;
+        F32 chat_normal_offset;
+        F32 chat_shout_offset;
+        U32 chat_flags;
+
+        msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatWhisperRange, chat_whisper_range);
+        msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatNormalRange, chat_normal_range);
+        msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatShoutRange, chat_shout_range);
+        msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatWhisperOffset, chat_whisper_offset);
+        msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatNormalOffset, chat_normal_offset);
+        msg->getF32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatShoutOffset, chat_shout_offset);
+        msg->getU32Fast(_PREHASH_RegionInfo5, _PREHASH_ChatFlags, chat_flags);
+
+        LL_INFOS() << "Whisper range: " << chat_whisper_range << " normal range: " << chat_normal_range << " shout range: " << chat_shout_range
+            << " whisper offset: " << chat_whisper_offset << " normal offset: " << chat_normal_offset << " shout offset: " << chat_shout_offset
+            << " chat flags: " << chat_flags << LL_ENDL;
+    }
+
+    // GENERAL PANEL
+    panel = tab->getChild<LLPanel>("General");
+    panel->getChild<LLUICtrl>("region_text")->setValue(LLSD(sim_name));
+    panel->getChild<LLUICtrl>("region_type")->setValue(LLSD(sim_type));
+    panel->getChild<LLUICtrl>("version_channel_text")->setValue(gLastVersionChannel);
+
+    panel->getChild<LLUICtrl>("block_terraform_check")->setValue((region_flags & REGION_FLAGS_BLOCK_TERRAFORM) ? TRUE : FALSE );
+    panel->getChild<LLUICtrl>("block_fly_check")->setValue((region_flags & REGION_FLAGS_BLOCK_FLY) ? TRUE : FALSE );
+    panel->getChild<LLUICtrl>("block_fly_over_check")->setValue((region_flags & REGION_FLAGS_BLOCK_FLYOVER) ? TRUE : FALSE );
+    panel->getChild<LLUICtrl>("allow_damage_check")->setValue((region_flags & REGION_FLAGS_ALLOW_DAMAGE) ? TRUE : FALSE );
+    panel->getChild<LLUICtrl>("restrict_pushobject")->setValue((region_flags & REGION_FLAGS_RESTRICT_PUSHOBJECT) ? TRUE : FALSE );
+    panel->getChild<LLUICtrl>("allow_land_resell_check")->setValue((region_flags & REGION_FLAGS_BLOCK_LAND_RESELL) ? FALSE : TRUE );
+    panel->getChild<LLUICtrl>("allow_parcel_changes_check")->setValue((region_flags & REGION_FLAGS_ALLOW_PARCEL_CHANGES) ? TRUE : FALSE );
+    panel->getChild<LLUICtrl>("block_parcel_search_check")->setValue((region_flags & REGION_FLAGS_BLOCK_PARCEL_SEARCH) ? TRUE : FALSE );
+    panel->getChild<LLUICtrl>("agent_limit_spin")->setValue(LLSD((F32)agent_limit) );
+    panel->getChild<LLUICtrl>("object_bonus_spin")->setValue(LLSD(object_bonus_factor) );
+    panel->getChild<LLUICtrl>("access_combo")->setValue(LLSD(sim_access) );
+
+    panel->getChild<LLSpinCtrl>("agent_limit_spin")->setMaxValue(hard_agent_limit);
+
+    LLPanelRegionGeneralInfo* panel_general = LLFloaterRegionInfo::getPanelGeneral();
+    if (panel)
+    {
+        panel_general->setObjBonusFactor(object_bonus_factor);
+    }
+
+    // detect teen grid for maturity
+
+    U32 parent_estate_id;
+    msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_ParentEstateID, parent_estate_id);
+    BOOL teen_grid = (parent_estate_id == 5);  // *TODO add field to estate table and test that
+    panel->getChildView("access_combo")->setEnabled(gAgent.isGodlike() || (region && region->canManageEstate() && !teen_grid));
+    panel->setCtrlsEnabled(allow_modify);
+
+
+    // DEBUG PANEL
+    panel = tab->getChild<LLPanel>("Debug");
+
+    panel->getChild<LLUICtrl>("region_text")->setValue(LLSD(sim_name) );
+    panel->getChild<LLUICtrl>("disable_scripts_check")->setValue(LLSD((BOOL)((region_flags & REGION_FLAGS_SKIP_SCRIPTS) ? TRUE : FALSE )) );
+    panel->getChild<LLUICtrl>("disable_collisions_check")->setValue(LLSD((BOOL)((region_flags & REGION_FLAGS_SKIP_COLLISIONS) ? TRUE : FALSE )) );
+    panel->getChild<LLUICtrl>("disable_physics_check")->setValue(LLSD((BOOL)((region_flags & REGION_FLAGS_SKIP_PHYSICS) ? TRUE : FALSE )) );
+    panel->setCtrlsEnabled(allow_modify);
+
+    // TERRAIN PANEL
+    panel = tab->getChild<LLPanel>("Terrain");
+
+    panel->getChild<LLUICtrl>("region_text")->setValue(LLSD(sim_name));
+    panel->getChild<LLUICtrl>("water_height_spin")->setValue(region_info.mWaterHeight);
+    panel->getChild<LLUICtrl>("terrain_raise_spin")->setValue(region_info.mTerrainRaiseLimit);
+    panel->getChild<LLUICtrl>("terrain_lower_spin")->setValue(region_info.mTerrainLowerLimit);
+
+    panel->setCtrlsEnabled(allow_modify);
+
+    if (floater->getVisible())
+    {
+        // Note: region info also causes LLRegionInfoModel::instance().update(msg); -> requestRegion(); -> changed message
+        // we need to know env version here and in update(msg) to know when to request and when not to, when to filter 'changed'
+        floater->refreshFromRegion(gAgent.getRegion());
+    } // else will rerequest on onOpen either way
 }
 
 // static
 LLPanelEstateInfo* LLFloaterRegionInfo::getPanelEstate()
 {
-	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	if (!floater) return NULL;
-	LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
-	LLPanelEstateInfo* panel = (LLPanelEstateInfo*)tab->getChild<LLPanel>("Estate");
-	return panel;
+    LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
+    if (!floater) return NULL;
+    LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
+    LLPanelEstateInfo* panel = (LLPanelEstateInfo*)tab->getChild<LLPanel>("Estate");
+    return panel;
 }
 
 // static
 LLPanelEstateAccess* LLFloaterRegionInfo::getPanelAccess()
 {
-	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	if (!floater) return NULL;
-	LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
-	LLPanelEstateAccess* panel = (LLPanelEstateAccess*)tab->getChild<LLPanel>("Access");
-	return panel;
+    LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
+    if (!floater) return NULL;
+    LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
+    LLPanelEstateAccess* panel = (LLPanelEstateAccess*)tab->getChild<LLPanel>("Access");
+    return panel;
 }
 
 // static
 LLPanelEstateCovenant* LLFloaterRegionInfo::getPanelCovenant()
 {
-	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	if (!floater) return NULL;
-	LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
-	LLPanelEstateCovenant* panel = (LLPanelEstateCovenant*)tab->getChild<LLPanel>("Covenant");
-	return panel;
+    LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
+    if (!floater) return NULL;
+    LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
+    LLPanelEstateCovenant* panel = (LLPanelEstateCovenant*)tab->getChild<LLPanel>("Covenant");
+    return panel;
 }
 
 // static
 LLPanelRegionGeneralInfo* LLFloaterRegionInfo::getPanelGeneral()
 {
-	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	if (!floater) return NULL;
-	LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
-	LLPanelRegionGeneralInfo* panel = (LLPanelRegionGeneralInfo*)tab->getChild<LLPanel>("General");
-	return panel;
+    LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
+    if (!floater) return NULL;
+    LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
+    LLPanelRegionGeneralInfo* panel = (LLPanelRegionGeneralInfo*)tab->getChild<LLPanel>("General");
+    return panel;
 }
 
 // static
 LLPanelRegionEnvironment* LLFloaterRegionInfo::getPanelEnvironment()
 {
-	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	if (!floater) return NULL;
-	LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
-	LLPanelRegionEnvironment* panel = (LLPanelRegionEnvironment*)tab->getChild<LLPanel>("panel_env_info");
-	return panel;
+    LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
+    if (!floater) return NULL;
+    LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
+    LLPanelRegionEnvironment* panel = (LLPanelRegionEnvironment*)tab->getChild<LLPanel>("panel_env_info");
+    return panel;
 }
 
 LLTerrainMaterials::Type material_type_from_ctrl(LLCheckBoxCtrl* ctrl)
@@ -616,91 +616,91 @@ void material_type_to_ctrl(LLCheckBoxCtrl* ctrl, LLTerrainMaterials::Type new_ty
 // static
 LLPanelRegionTerrainInfo* LLFloaterRegionInfo::getPanelRegionTerrain()
 {
-	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	if (!floater)
-	{
-		llassert(floater);
-		return NULL;
-	}
+    LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
+    if (!floater)
+    {
+        llassert(floater);
+        return NULL;
+    }
 
-	LLTabContainer* tab_container = floater->getChild<LLTabContainer>("region_panels");
-	LLPanelRegionTerrainInfo* panel =
-		dynamic_cast<LLPanelRegionTerrainInfo*>(tab_container->getChild<LLPanel>("Terrain"));
-	llassert(panel);
-	return panel;
+    LLTabContainer* tab_container = floater->getChild<LLTabContainer>("region_panels");
+    LLPanelRegionTerrainInfo* panel =
+        dynamic_cast<LLPanelRegionTerrainInfo*>(tab_container->getChild<LLPanel>("Terrain"));
+    llassert(panel);
+    return panel;
 }
 
 LLPanelRegionExperiences* LLFloaterRegionInfo::getPanelExperiences()
 {
-	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	if (!floater) return NULL;
-	LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
-	return (LLPanelRegionExperiences*)tab->getChild<LLPanel>("Experiences");
+    LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
+    if (!floater) return NULL;
+    LLTabContainer* tab = floater->getChild<LLTabContainer>("region_panels");
+    return (LLPanelRegionExperiences*)tab->getChild<LLPanel>("Experiences");
 }
 
 void LLFloaterRegionInfo::disableTabCtrls()
 {
-	LLTabContainer* tab = getChild<LLTabContainer>("region_panels");
+    LLTabContainer* tab = getChild<LLTabContainer>("region_panels");
 
-	tab->getChild<LLPanel>("General")->setCtrlsEnabled(FALSE);
-	tab->getChild<LLPanel>("Debug")->setCtrlsEnabled(FALSE);
-	tab->getChild<LLPanel>("Terrain")->setCtrlsEnabled(FALSE);
-	tab->getChild<LLPanel>("panel_env_info")->setCtrlsEnabled(FALSE);
-	tab->getChild<LLPanel>("Estate")->setCtrlsEnabled(FALSE);
-	tab->getChild<LLPanel>("Access")->setCtrlsEnabled(FALSE);
+    tab->getChild<LLPanel>("General")->setCtrlsEnabled(FALSE);
+    tab->getChild<LLPanel>("Debug")->setCtrlsEnabled(FALSE);
+    tab->getChild<LLPanel>("Terrain")->setCtrlsEnabled(FALSE);
+    tab->getChild<LLPanel>("panel_env_info")->setCtrlsEnabled(FALSE);
+    tab->getChild<LLPanel>("Estate")->setCtrlsEnabled(FALSE);
+    tab->getChild<LLPanel>("Access")->setCtrlsEnabled(FALSE);
 }
 
 void LLFloaterRegionInfo::onTabSelected(const LLSD& param)
 {
-	LLPanel* active_panel = getChild<LLPanel>(param.asString());
-	active_panel->onOpen(LLSD());
+    LLPanel* active_panel = getChild<LLPanel>(param.asString());
+    active_panel->onOpen(LLSD());
 }
 
 void LLFloaterRegionInfo::refreshFromRegion(LLViewerRegion* region)
 {
-	if (!region)
-	{
-		return; 
-	}
+    if (!region)
+    {
+        return;
+    }
 
-	// call refresh from region on all panels
-	for (const auto& infoPanel : mInfoPanels)
-	{
-		infoPanel->refreshFromRegion(region);
-	}
-	mEnvironmentPanel->refreshFromRegion(region);
+    // call refresh from region on all panels
+    for (const auto& infoPanel : mInfoPanels)
+    {
+        infoPanel->refreshFromRegion(region);
+    }
+    mEnvironmentPanel->refreshFromRegion(region);
 }
 
 // public
 void LLFloaterRegionInfo::refresh()
 {
-	for(info_panels_t::iterator iter = mInfoPanels.begin();
-		iter != mInfoPanels.end(); ++iter)
-	{
-		(*iter)->refresh();
-	}
+    for(info_panels_t::iterator iter = mInfoPanels.begin();
+        iter != mInfoPanels.end(); ++iter)
+    {
+        (*iter)->refresh();
+    }
     mEnvironmentPanel->refresh();
 }
 
 void LLFloaterRegionInfo::enableTopButtons()
 {
-	getChildView("top_colliders_btn")->setEnabled(true);
-	getChildView("top_scripts_btn")->setEnabled(true);
+    getChildView("top_colliders_btn")->setEnabled(true);
+    getChildView("top_scripts_btn")->setEnabled(true);
 }
 
 void LLFloaterRegionInfo::disableTopButtons()
 {
-	getChildView("top_colliders_btn")->setEnabled(false);
-	getChildView("top_scripts_btn")->setEnabled(false);
+    getChildView("top_colliders_btn")->setEnabled(false);
+    getChildView("top_scripts_btn")->setEnabled(false);
 }
 
 void LLFloaterRegionInfo::onGodLevelChange(U8 god_level)
 {
-	LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
-	if (floater && floater->getVisible())
-	{
-		refreshFromRegion(gAgent.getRegion());
-	}
+    LLFloaterRegionInfo* floater = LLFloaterReg::getTypedInstance<LLFloaterRegionInfo>("region_info");
+    if (floater && floater->getVisible())
+    {
+        refreshFromRegion(gAgent.getRegion());
+    }
 }
 
 ///----------------------------------------------------------------------------
@@ -712,58 +712,58 @@ void LLFloaterRegionInfo::onGodLevelChange(U8 god_level)
 //
 
 LLPanelRegionInfo::LLPanelRegionInfo()
-	: LLPanel()
+    : LLPanel()
 {
 }
 
 void LLPanelRegionInfo::onBtnSet()
 {
-	if (sendUpdate())
-	{
-		disableButton("apply_btn");
-	}
+    if (sendUpdate())
+    {
+        disableButton("apply_btn");
+    }
 }
 
 void LLPanelRegionInfo::onChangeChildCtrl(LLUICtrl* ctrl)
 {
-	updateChild(ctrl); // virtual function
+    updateChild(ctrl); // virtual function
 }
 
 // Enables the "set" button if it is not already enabled
 void LLPanelRegionInfo::onChangeAnything()
 {
-	enableButton("apply_btn");
-	refresh();
+    enableButton("apply_btn");
+    refresh();
 }
 
 // static
 // Enables set button on change to line editor
 void LLPanelRegionInfo::onChangeText(LLLineEditor* caller, void* user_data)
 {
-	LLPanelRegionInfo* panel = dynamic_cast<LLPanelRegionInfo*>(caller->getParent());
-	if(panel)
-	{
-		panel->enableButton("apply_btn");
-		panel->refresh();
-	}
+    LLPanelRegionInfo* panel = dynamic_cast<LLPanelRegionInfo*>(caller->getParent());
+    if(panel)
+    {
+        panel->enableButton("apply_btn");
+        panel->refresh();
+    }
 }
 
 
 // virtual
 BOOL LLPanelRegionInfo::postBuild()
 {
-	// If the panel has an Apply button, set a callback for it.
-	LLUICtrl* apply_btn = findChild<LLUICtrl>("apply_btn");
-	if (apply_btn)
-	{
-		apply_btn->setCommitCallback(boost::bind(&LLPanelRegionInfo::onBtnSet, this));
-	}
+    // If the panel has an Apply button, set a callback for it.
+    LLUICtrl* apply_btn = findChild<LLUICtrl>("apply_btn");
+    if (apply_btn)
+    {
+        apply_btn->setCommitCallback(boost::bind(&LLPanelRegionInfo::onBtnSet, this));
+    }
 
-	refresh();
-	return TRUE;
+    refresh();
+    return TRUE;
 }
 
-// virtual 
+// virtual
 void LLPanelRegionInfo::updateChild(LLUICtrl* child_ctr)
 {
 }
@@ -771,64 +771,64 @@ void LLPanelRegionInfo::updateChild(LLUICtrl* child_ctr)
 // virtual
 bool LLPanelRegionInfo::refreshFromRegion(LLViewerRegion* region)
 {
-	if (region) mHost = region->getHost();
-	return true;
+    if (region) mHost = region->getHost();
+    return true;
 }
 
 void LLPanelRegionInfo::sendEstateOwnerMessage(
-	LLMessageSystem* msg,
-	const std::string& request,
-	const LLUUID& invoice,
-	const strings_t& strings)
-{
-	LL_INFOS() << "Sending estate request '" << request << "'" << LL_ENDL;
-	msg->newMessageFast(_PREHASH_EstateOwnerMessage);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
-	msg->nextBlockFast(_PREHASH_MethodData);
-	msg->addStringFast(_PREHASH_Method, request);
-	msg->addUUIDFast(_PREHASH_Invoice, invoice);
-	if(strings.empty())
-	{
-		msg->nextBlockFast(_PREHASH_ParamList);
-		msg->addStringFast(_PREHASH_Parameter, NULL);
-	}
-	else
-	{
-		strings_t::const_iterator it = strings.begin();
-		strings_t::const_iterator end = strings.end();
-		for(; it != end; ++it)
-		{
-			msg->nextBlockFast(_PREHASH_ParamList);
-			msg->addStringFast(_PREHASH_Parameter, *it);
-		}
-	}
-	msg->sendReliable(mHost);
+    LLMessageSystem* msg,
+    const std::string& request,
+    const LLUUID& invoice,
+    const strings_t& strings)
+{
+    LL_INFOS() << "Sending estate request '" << request << "'" << LL_ENDL;
+    msg->newMessageFast(_PREHASH_EstateOwnerMessage);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
+    msg->nextBlockFast(_PREHASH_MethodData);
+    msg->addStringFast(_PREHASH_Method, request);
+    msg->addUUIDFast(_PREHASH_Invoice, invoice);
+    if(strings.empty())
+    {
+        msg->nextBlockFast(_PREHASH_ParamList);
+        msg->addStringFast(_PREHASH_Parameter, NULL);
+    }
+    else
+    {
+        strings_t::const_iterator it = strings.begin();
+        strings_t::const_iterator end = strings.end();
+        for(; it != end; ++it)
+        {
+            msg->nextBlockFast(_PREHASH_ParamList);
+            msg->addStringFast(_PREHASH_Parameter, *it);
+        }
+    }
+    msg->sendReliable(mHost);
 }
 
 void LLPanelRegionInfo::enableButton(const std::string& btn_name, BOOL enable)
 {
-	LLView* button = findChildView(btn_name);
-	if (button) button->setEnabled(enable);
+    LLView* button = findChildView(btn_name);
+    if (button) button->setEnabled(enable);
 }
 
 void LLPanelRegionInfo::disableButton(const std::string& btn_name)
 {
-	LLView* button = findChildView(btn_name);
-	if (button) button->setEnabled(FALSE);
+    LLView* button = findChildView(btn_name);
+    if (button) button->setEnabled(FALSE);
 }
 
 void LLPanelRegionInfo::initCtrl(const std::string& name)
 {
-	getChild<LLUICtrl>(name)->setCommitCallback(boost::bind(&LLPanelRegionInfo::onChangeAnything, this));
+    getChild<LLUICtrl>(name)->setCommitCallback(boost::bind(&LLPanelRegionInfo::onChangeAnything, this));
 }
 
 void LLPanelRegionInfo::onClickManageTelehub()
 {
-	LLFloaterReg::hideInstance("region_info");
-	LLFloaterReg::showInstance("telehubs");
+    LLFloaterReg::hideInstance("region_info");
+    LLFloaterReg::showInstance("telehubs");
 }
 
 /////////////////////////////////////////////////////////////////////////////
@@ -836,181 +836,181 @@ void LLPanelRegionInfo::onClickManageTelehub()
 //
 bool LLPanelRegionGeneralInfo::refreshFromRegion(LLViewerRegion* region)
 {
-	BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate());
-	setCtrlsEnabled(allow_modify);
-	getChildView("apply_btn")->setEnabled(FALSE);
-	getChildView("access_text")->setEnabled(allow_modify);
-	// getChildView("access_combo")->setEnabled(allow_modify);
-	// now set in processRegionInfo for teen grid detection
-	getChildView("kick_btn")->setEnabled(allow_modify);
-	getChildView("kick_all_btn")->setEnabled(allow_modify);
-	getChildView("im_btn")->setEnabled(allow_modify);
-	getChildView("manage_telehub_btn")->setEnabled(allow_modify);
+    BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate());
+    setCtrlsEnabled(allow_modify);
+    getChildView("apply_btn")->setEnabled(FALSE);
+    getChildView("access_text")->setEnabled(allow_modify);
+    // getChildView("access_combo")->setEnabled(allow_modify);
+    // now set in processRegionInfo for teen grid detection
+    getChildView("kick_btn")->setEnabled(allow_modify);
+    getChildView("kick_all_btn")->setEnabled(allow_modify);
+    getChildView("im_btn")->setEnabled(allow_modify);
+    getChildView("manage_telehub_btn")->setEnabled(allow_modify);
 
-	// Data gets filled in by processRegionInfo
+    // Data gets filled in by processRegionInfo
 
-	return LLPanelRegionInfo::refreshFromRegion(region);
+    return LLPanelRegionInfo::refreshFromRegion(region);
 }
 
 BOOL LLPanelRegionGeneralInfo::postBuild()
 {
-	// Enable the "Apply" button if something is changed. JC
-	initCtrl("block_terraform_check");
-	initCtrl("block_fly_check");
-	initCtrl("block_fly_over_check");
-	initCtrl("allow_damage_check");
-	initCtrl("allow_land_resell_check");
-	initCtrl("allow_parcel_changes_check");
-	initCtrl("agent_limit_spin");
-	initCtrl("object_bonus_spin");
-	initCtrl("access_combo");
-	initCtrl("restrict_pushobject");
-	initCtrl("block_parcel_search_check");
-
-	childSetAction("kick_btn", boost::bind(&LLPanelRegionGeneralInfo::onClickKick, this));
-	childSetAction("kick_all_btn", onClickKickAll, this);
-	childSetAction("im_btn", onClickMessage, this);
-//	childSetAction("manage_telehub_btn", onClickManageTelehub, this);
-
-	LLUICtrl* apply_btn = findChild<LLUICtrl>("apply_btn");
-	if (apply_btn)
-	{
-		apply_btn->setCommitCallback(boost::bind(&LLPanelRegionGeneralInfo::onBtnSet, this));
-	}
-
-	refresh();
-	return TRUE;
+    // Enable the "Apply" button if something is changed. JC
+    initCtrl("block_terraform_check");
+    initCtrl("block_fly_check");
+    initCtrl("block_fly_over_check");
+    initCtrl("allow_damage_check");
+    initCtrl("allow_land_resell_check");
+    initCtrl("allow_parcel_changes_check");
+    initCtrl("agent_limit_spin");
+    initCtrl("object_bonus_spin");
+    initCtrl("access_combo");
+    initCtrl("restrict_pushobject");
+    initCtrl("block_parcel_search_check");
+
+    childSetAction("kick_btn", boost::bind(&LLPanelRegionGeneralInfo::onClickKick, this));
+    childSetAction("kick_all_btn", onClickKickAll, this);
+    childSetAction("im_btn", onClickMessage, this);
+//  childSetAction("manage_telehub_btn", onClickManageTelehub, this);
+
+    LLUICtrl* apply_btn = findChild<LLUICtrl>("apply_btn");
+    if (apply_btn)
+    {
+        apply_btn->setCommitCallback(boost::bind(&LLPanelRegionGeneralInfo::onBtnSet, this));
+    }
+
+    refresh();
+    return TRUE;
 }
 
 void LLPanelRegionGeneralInfo::onBtnSet()
 {
-	if(mObjBonusFactor == getChild<LLUICtrl>("object_bonus_spin")->getValue().asReal())
-	{
-		if (sendUpdate())
-		{
-			disableButton("apply_btn");
-		}
-	}
-	else
-	{
-		LLNotificationsUtil::add("ChangeObjectBonusFactor", LLSD(), LLSD(), boost::bind(&LLPanelRegionGeneralInfo::onChangeObjectBonus, this, _1, _2));
-	}
+    if(mObjBonusFactor == getChild<LLUICtrl>("object_bonus_spin")->getValue().asReal())
+    {
+        if (sendUpdate())
+        {
+            disableButton("apply_btn");
+        }
+    }
+    else
+    {
+        LLNotificationsUtil::add("ChangeObjectBonusFactor", LLSD(), LLSD(), boost::bind(&LLPanelRegionGeneralInfo::onChangeObjectBonus, this, _1, _2));
+    }
 }
 
 bool LLPanelRegionGeneralInfo::onChangeObjectBonus(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option == 0)
-	{
-		if (sendUpdate())
-		{
-			disableButton("apply_btn");
-		}
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option == 0)
+    {
+        if (sendUpdate())
+        {
+            disableButton("apply_btn");
+        }
+    }
+    return false;
 }
 
 void LLPanelRegionGeneralInfo::onClickKick()
 {
-	LL_INFOS() << "LLPanelRegionGeneralInfo::onClickKick" << LL_ENDL;
+    LL_INFOS() << "LLPanelRegionGeneralInfo::onClickKick" << LL_ENDL;
 
-	// this depends on the grandparent view being a floater
-	// in order to set up floater dependency
+    // this depends on the grandparent view being a floater
+    // in order to set up floater dependency
     LLView * button = findChild<LLButton>("kick_btn");
-	LLFloater* parent_floater = gFloaterView->getParentFloater(this);
-	LLFloater* child_floater = LLFloaterAvatarPicker::show(boost::bind(&LLPanelRegionGeneralInfo::onKickCommit, this, _1), 
+    LLFloater* parent_floater = gFloaterView->getParentFloater(this);
+    LLFloater* child_floater = LLFloaterAvatarPicker::show(boost::bind(&LLPanelRegionGeneralInfo::onKickCommit, this, _1),
                                                                                 FALSE, TRUE, FALSE, parent_floater->getName(), button);
-	if (child_floater)
-	{
-		parent_floater->addDependentFloater(child_floater);
-	}
+    if (child_floater)
+    {
+        parent_floater->addDependentFloater(child_floater);
+    }
 }
 
 void LLPanelRegionGeneralInfo::onKickCommit(const uuid_vec_t& ids)
 {
-	if (ids.empty()) return;
-	if(ids[0].notNull())
-	{
-		strings_t strings;
-		// [0] = our agent id
-		// [1] = target agent id
-		std::string buffer;
-		gAgent.getID().toString(buffer);
-		strings.push_back(buffer);
+    if (ids.empty()) return;
+    if(ids[0].notNull())
+    {
+        strings_t strings;
+        // [0] = our agent id
+        // [1] = target agent id
+        std::string buffer;
+        gAgent.getID().toString(buffer);
+        strings.push_back(buffer);
 
-		ids[0].toString(buffer);
-		strings.push_back(strings_t::value_type(buffer));
+        ids[0].toString(buffer);
+        strings.push_back(strings_t::value_type(buffer));
 
-		LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-		sendEstateOwnerMessage(gMessageSystem, "teleporthomeuser", invoice, strings);
-	}
+        LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+        sendEstateOwnerMessage(gMessageSystem, "teleporthomeuser", invoice, strings);
+    }
 }
 
 // static
 void LLPanelRegionGeneralInfo::onClickKickAll(void* userdata)
 {
-	LL_INFOS() << "LLPanelRegionGeneralInfo::onClickKickAll" << LL_ENDL;
-	LLNotificationsUtil::add("KickUsersFromRegion", 
-									LLSD(), 
-									LLSD(), 
-									boost::bind(&LLPanelRegionGeneralInfo::onKickAllCommit, (LLPanelRegionGeneralInfo*)userdata, _1, _2));
+    LL_INFOS() << "LLPanelRegionGeneralInfo::onClickKickAll" << LL_ENDL;
+    LLNotificationsUtil::add("KickUsersFromRegion",
+                                    LLSD(),
+                                    LLSD(),
+                                    boost::bind(&LLPanelRegionGeneralInfo::onKickAllCommit, (LLPanelRegionGeneralInfo*)userdata, _1, _2));
 }
 
 bool LLPanelRegionGeneralInfo::onKickAllCommit(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option == 0)
-	{
-		strings_t strings;
-		// [0] = our agent id
-		std::string buffer;
-		gAgent.getID().toString(buffer);
-		strings.push_back(buffer);
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option == 0)
+    {
+        strings_t strings;
+        // [0] = our agent id
+        std::string buffer;
+        gAgent.getID().toString(buffer);
+        strings.push_back(buffer);
 
-		LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-		// historical message name
-		sendEstateOwnerMessage(gMessageSystem, "teleporthomeallusers", invoice, strings);
-	}
-	return false;
+        LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+        // historical message name
+        sendEstateOwnerMessage(gMessageSystem, "teleporthomeallusers", invoice, strings);
+    }
+    return false;
 }
 
 // static
 void LLPanelRegionGeneralInfo::onClickMessage(void* userdata)
 {
-	LL_INFOS() << "LLPanelRegionGeneralInfo::onClickMessage" << LL_ENDL;
-	LLNotificationsUtil::add("MessageRegion", 
-		LLSD(), 
-		LLSD(), 
-		boost::bind(&LLPanelRegionGeneralInfo::onMessageCommit, (LLPanelRegionGeneralInfo*)userdata, _1, _2));
+    LL_INFOS() << "LLPanelRegionGeneralInfo::onClickMessage" << LL_ENDL;
+    LLNotificationsUtil::add("MessageRegion",
+        LLSD(),
+        LLSD(),
+        boost::bind(&LLPanelRegionGeneralInfo::onMessageCommit, (LLPanelRegionGeneralInfo*)userdata, _1, _2));
 }
 
 // static
 bool LLPanelRegionGeneralInfo::onMessageCommit(const LLSD& notification, const LLSD& response)
 {
-	if(LLNotificationsUtil::getSelectedOption(notification, response) != 0) return false;
-
-	std::string text = response["message"].asString();
-	if (text.empty()) return false;
-
-	LL_INFOS() << "Message to everyone: " << text << LL_ENDL;
-	strings_t strings;
-	// [0] grid_x, unused here
-	// [1] grid_y, unused here
-	// [2] agent_id of sender
-	// [3] sender name
-	// [4] message
-	strings.push_back("-1");
-	strings.push_back("-1");
-	std::string buffer;
-	gAgent.getID().toString(buffer);
-	strings.push_back(buffer);
-	std::string name;
-	LLAgentUI::buildFullname(name);
-	strings.push_back(strings_t::value_type(name));
-	strings.push_back(strings_t::value_type(text));
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	sendEstateOwnerMessage(gMessageSystem, "simulatormessage", invoice, strings);
-	return false;
+    if(LLNotificationsUtil::getSelectedOption(notification, response) != 0) return false;
+
+    std::string text = response["message"].asString();
+    if (text.empty()) return false;
+
+    LL_INFOS() << "Message to everyone: " << text << LL_ENDL;
+    strings_t strings;
+    // [0] grid_x, unused here
+    // [1] grid_y, unused here
+    // [2] agent_id of sender
+    // [3] sender name
+    // [4] message
+    strings.push_back("-1");
+    strings.push_back("-1");
+    std::string buffer;
+    gAgent.getID().toString(buffer);
+    strings.push_back(buffer);
+    std::string name;
+    LLAgentUI::buildFullname(name);
+    strings.push_back(strings_t::value_type(name));
+    strings.push_back(strings_t::value_type(text));
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    sendEstateOwnerMessage(gMessageSystem, "simulatormessage", invoice, strings);
+    return false;
 }
 
 // setregioninfo
@@ -1026,74 +1026,74 @@ bool LLPanelRegionGeneralInfo::onMessageCommit(const LLSD& notification, const L
 // strings[9] = 'Y' - block parcel search, 'N' - allow
 BOOL LLPanelRegionGeneralInfo::sendUpdate()
 {
-	LL_INFOS() << "LLPanelRegionGeneralInfo::sendUpdate()" << LL_ENDL;
-
-	// First try using a Cap.  If that fails use the old method.
-	LLSD body;
-	std::string url = gAgent.getRegionCapability("DispatchRegionInfo");
-	if (!url.empty())
-	{
-		body["block_terraform"] = getChild<LLUICtrl>("block_terraform_check")->getValue();
-		body["block_fly"] = getChild<LLUICtrl>("block_fly_check")->getValue();
-		body["block_fly_over"] = getChild<LLUICtrl>("block_fly_over_check")->getValue();
-		body["allow_damage"] = getChild<LLUICtrl>("allow_damage_check")->getValue();
-		body["allow_land_resell"] = getChild<LLUICtrl>("allow_land_resell_check")->getValue();
-		body["agent_limit"] = getChild<LLUICtrl>("agent_limit_spin")->getValue();
-		body["prim_bonus"] = getChild<LLUICtrl>("object_bonus_spin")->getValue();
-		body["sim_access"] = getChild<LLUICtrl>("access_combo")->getValue();
-		body["restrict_pushobject"] = getChild<LLUICtrl>("restrict_pushobject")->getValue();
-		body["allow_parcel_changes"] = getChild<LLUICtrl>("allow_parcel_changes_check")->getValue();
-		body["block_parcel_search"] = getChild<LLUICtrl>("block_parcel_search_check")->getValue();
+    LL_INFOS() << "LLPanelRegionGeneralInfo::sendUpdate()" << LL_ENDL;
+
+    // First try using a Cap.  If that fails use the old method.
+    LLSD body;
+    std::string url = gAgent.getRegionCapability("DispatchRegionInfo");
+    if (!url.empty())
+    {
+        body["block_terraform"] = getChild<LLUICtrl>("block_terraform_check")->getValue();
+        body["block_fly"] = getChild<LLUICtrl>("block_fly_check")->getValue();
+        body["block_fly_over"] = getChild<LLUICtrl>("block_fly_over_check")->getValue();
+        body["allow_damage"] = getChild<LLUICtrl>("allow_damage_check")->getValue();
+        body["allow_land_resell"] = getChild<LLUICtrl>("allow_land_resell_check")->getValue();
+        body["agent_limit"] = getChild<LLUICtrl>("agent_limit_spin")->getValue();
+        body["prim_bonus"] = getChild<LLUICtrl>("object_bonus_spin")->getValue();
+        body["sim_access"] = getChild<LLUICtrl>("access_combo")->getValue();
+        body["restrict_pushobject"] = getChild<LLUICtrl>("restrict_pushobject")->getValue();
+        body["allow_parcel_changes"] = getChild<LLUICtrl>("allow_parcel_changes_check")->getValue();
+        body["block_parcel_search"] = getChild<LLUICtrl>("block_parcel_search_check")->getValue();
 
         LLCoreHttpUtil::HttpCoroutineAdapter::messageHttpPost(url, body,
             "Region info update posted.", "Region info update not posted.");
-	}
-	else
-	{
-		strings_t strings;
-		std::string buffer;
+    }
+    else
+    {
+        strings_t strings;
+        std::string buffer;
 
-		buffer = llformat("%s", (getChild<LLUICtrl>("block_terraform_check")->getValue().asBoolean() ? "Y" : "N"));
-		strings.push_back(strings_t::value_type(buffer));
+        buffer = llformat("%s", (getChild<LLUICtrl>("block_terraform_check")->getValue().asBoolean() ? "Y" : "N"));
+        strings.push_back(strings_t::value_type(buffer));
 
-		buffer = llformat("%s", (getChild<LLUICtrl>("block_fly_check")->getValue().asBoolean() ? "Y" : "N"));
-		strings.push_back(strings_t::value_type(buffer));
+        buffer = llformat("%s", (getChild<LLUICtrl>("block_fly_check")->getValue().asBoolean() ? "Y" : "N"));
+        strings.push_back(strings_t::value_type(buffer));
 
-		buffer = llformat("%s", (getChild<LLUICtrl>("allow_damage_check")->getValue().asBoolean() ? "Y" : "N"));
-		strings.push_back(strings_t::value_type(buffer));
+        buffer = llformat("%s", (getChild<LLUICtrl>("allow_damage_check")->getValue().asBoolean() ? "Y" : "N"));
+        strings.push_back(strings_t::value_type(buffer));
 
-		buffer = llformat("%s", (getChild<LLUICtrl>("allow_land_resell_check")->getValue().asBoolean() ? "Y" : "N"));
-		strings.push_back(strings_t::value_type(buffer));
+        buffer = llformat("%s", (getChild<LLUICtrl>("allow_land_resell_check")->getValue().asBoolean() ? "Y" : "N"));
+        strings.push_back(strings_t::value_type(buffer));
 
-		F32 value = (F32)getChild<LLUICtrl>("agent_limit_spin")->getValue().asReal();
-		buffer = llformat("%f", value);
-		strings.push_back(strings_t::value_type(buffer));
+        F32 value = (F32)getChild<LLUICtrl>("agent_limit_spin")->getValue().asReal();
+        buffer = llformat("%f", value);
+        strings.push_back(strings_t::value_type(buffer));
 
-		value = (F32)getChild<LLUICtrl>("object_bonus_spin")->getValue().asReal();
-		buffer = llformat("%f", value);
-		strings.push_back(strings_t::value_type(buffer));
+        value = (F32)getChild<LLUICtrl>("object_bonus_spin")->getValue().asReal();
+        buffer = llformat("%f", value);
+        strings.push_back(strings_t::value_type(buffer));
 
-		buffer = llformat("%d", getChild<LLUICtrl>("access_combo")->getValue().asInteger());
-		strings.push_back(strings_t::value_type(buffer));
+        buffer = llformat("%d", getChild<LLUICtrl>("access_combo")->getValue().asInteger());
+        strings.push_back(strings_t::value_type(buffer));
 
-		buffer = llformat("%s", (getChild<LLUICtrl>("restrict_pushobject")->getValue().asBoolean() ? "Y" : "N"));
-		strings.push_back(strings_t::value_type(buffer));
+        buffer = llformat("%s", (getChild<LLUICtrl>("restrict_pushobject")->getValue().asBoolean() ? "Y" : "N"));
+        strings.push_back(strings_t::value_type(buffer));
 
-		buffer = llformat("%s", (getChild<LLUICtrl>("allow_parcel_changes_check")->getValue().asBoolean() ? "Y" : "N"));
-		strings.push_back(strings_t::value_type(buffer));
+        buffer = llformat("%s", (getChild<LLUICtrl>("allow_parcel_changes_check")->getValue().asBoolean() ? "Y" : "N"));
+        strings.push_back(strings_t::value_type(buffer));
 
-		LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-		sendEstateOwnerMessage(gMessageSystem, "setregioninfo", invoice, strings);
-	}
+        LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+        sendEstateOwnerMessage(gMessageSystem, "setregioninfo", invoice, strings);
+    }
 
-	// if we changed access levels, tell user about it
-	LLViewerRegion* region = gAgent.getRegion();
-	if (region && (getChild<LLUICtrl>("access_combo")->getValue().asInteger() != region->getSimAccess()) )
-	{
-		LLNotificationsUtil::add("RegionMaturityChange");
-	}	
+    // if we changed access levels, tell user about it
+    LLViewerRegion* region = gAgent.getRegion();
+    if (region && (getChild<LLUICtrl>("access_combo")->getValue().asInteger() != region->getSimAccess()) )
+    {
+        LLNotificationsUtil::add("RegionMaturityChange");
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 /////////////////////////////////////////////////////////////////////////////
@@ -1101,219 +1101,219 @@ BOOL LLPanelRegionGeneralInfo::sendUpdate()
 /////////////////////////////////////////////////////////////////////////////
 BOOL LLPanelRegionDebugInfo::postBuild()
 {
-	LLPanelRegionInfo::postBuild();
-	initCtrl("disable_scripts_check");
-	initCtrl("disable_collisions_check");
-	initCtrl("disable_physics_check");
+    LLPanelRegionInfo::postBuild();
+    initCtrl("disable_scripts_check");
+    initCtrl("disable_collisions_check");
+    initCtrl("disable_physics_check");
 
-	childSetAction("choose_avatar_btn", boost::bind(&LLPanelRegionDebugInfo::onClickChooseAvatar, this));
-	childSetAction("return_btn", onClickReturn, this);
-	childSetAction("top_colliders_btn", onClickTopColliders, this);
-	childSetAction("top_scripts_btn", onClickTopScripts, this);
-	childSetAction("restart_btn", onClickRestart, this);
-	childSetAction("cancel_restart_btn", onClickCancelRestart, this);
-	childSetAction("region_debug_console_btn", onClickDebugConsole, this);
+    childSetAction("choose_avatar_btn", boost::bind(&LLPanelRegionDebugInfo::onClickChooseAvatar, this));
+    childSetAction("return_btn", onClickReturn, this);
+    childSetAction("top_colliders_btn", onClickTopColliders, this);
+    childSetAction("top_scripts_btn", onClickTopScripts, this);
+    childSetAction("restart_btn", onClickRestart, this);
+    childSetAction("cancel_restart_btn", onClickCancelRestart, this);
+    childSetAction("region_debug_console_btn", onClickDebugConsole, this);
 
-	return TRUE;
+    return TRUE;
 }
 
 // virtual
 bool LLPanelRegionDebugInfo::refreshFromRegion(LLViewerRegion* region)
 {
-	BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate());
-	setCtrlsEnabled(allow_modify);
-	getChildView("apply_btn")->setEnabled(FALSE);
-	getChildView("target_avatar_name")->setEnabled(FALSE);
-	
-	getChildView("choose_avatar_btn")->setEnabled(allow_modify);
-	getChildView("return_scripts")->setEnabled(allow_modify && !mTargetAvatar.isNull());
-	getChildView("return_other_land")->setEnabled(allow_modify && !mTargetAvatar.isNull());
-	getChildView("return_estate_wide")->setEnabled(allow_modify && !mTargetAvatar.isNull());
-	getChildView("return_btn")->setEnabled(allow_modify && !mTargetAvatar.isNull());
-	getChildView("top_colliders_btn")->setEnabled(allow_modify);
-	getChildView("top_scripts_btn")->setEnabled(allow_modify);
-	getChildView("restart_btn")->setEnabled(allow_modify);
-	getChildView("cancel_restart_btn")->setEnabled(allow_modify);
-	getChildView("region_debug_console_btn")->setEnabled(allow_modify);
-
-	return LLPanelRegionInfo::refreshFromRegion(region);
+    BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate());
+    setCtrlsEnabled(allow_modify);
+    getChildView("apply_btn")->setEnabled(FALSE);
+    getChildView("target_avatar_name")->setEnabled(FALSE);
+
+    getChildView("choose_avatar_btn")->setEnabled(allow_modify);
+    getChildView("return_scripts")->setEnabled(allow_modify && !mTargetAvatar.isNull());
+    getChildView("return_other_land")->setEnabled(allow_modify && !mTargetAvatar.isNull());
+    getChildView("return_estate_wide")->setEnabled(allow_modify && !mTargetAvatar.isNull());
+    getChildView("return_btn")->setEnabled(allow_modify && !mTargetAvatar.isNull());
+    getChildView("top_colliders_btn")->setEnabled(allow_modify);
+    getChildView("top_scripts_btn")->setEnabled(allow_modify);
+    getChildView("restart_btn")->setEnabled(allow_modify);
+    getChildView("cancel_restart_btn")->setEnabled(allow_modify);
+    getChildView("region_debug_console_btn")->setEnabled(allow_modify);
+
+    return LLPanelRegionInfo::refreshFromRegion(region);
 }
 
 // virtual
 BOOL LLPanelRegionDebugInfo::sendUpdate()
 {
-	LL_INFOS() << "LLPanelRegionDebugInfo::sendUpdate" << LL_ENDL;
-	strings_t strings;
-	std::string buffer;
+    LL_INFOS() << "LLPanelRegionDebugInfo::sendUpdate" << LL_ENDL;
+    strings_t strings;
+    std::string buffer;
 
-	buffer = llformat("%s", (getChild<LLUICtrl>("disable_scripts_check")->getValue().asBoolean() ? "Y" : "N"));
-	strings.push_back(buffer);
+    buffer = llformat("%s", (getChild<LLUICtrl>("disable_scripts_check")->getValue().asBoolean() ? "Y" : "N"));
+    strings.push_back(buffer);
 
-	buffer = llformat("%s", (getChild<LLUICtrl>("disable_collisions_check")->getValue().asBoolean() ? "Y" : "N"));
-	strings.push_back(buffer);
+    buffer = llformat("%s", (getChild<LLUICtrl>("disable_collisions_check")->getValue().asBoolean() ? "Y" : "N"));
+    strings.push_back(buffer);
 
-	buffer = llformat("%s", (getChild<LLUICtrl>("disable_physics_check")->getValue().asBoolean() ? "Y" : "N"));
-	strings.push_back(buffer);
+    buffer = llformat("%s", (getChild<LLUICtrl>("disable_physics_check")->getValue().asBoolean() ? "Y" : "N"));
+    strings.push_back(buffer);
 
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	sendEstateOwnerMessage(gMessageSystem, "setregiondebug", invoice, strings);
-	return TRUE;
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    sendEstateOwnerMessage(gMessageSystem, "setregiondebug", invoice, strings);
+    return TRUE;
 }
 
 void LLPanelRegionDebugInfo::onClickChooseAvatar()
 {
     LLView * button = findChild<LLButton>("choose_avatar_btn");
     LLFloater* parent_floater = gFloaterView->getParentFloater(this);
-	LLFloater * child_floater = LLFloaterAvatarPicker::show(boost::bind(&LLPanelRegionDebugInfo::callbackAvatarID, this, _1, _2), 
+    LLFloater * child_floater = LLFloaterAvatarPicker::show(boost::bind(&LLPanelRegionDebugInfo::callbackAvatarID, this, _1, _2),
                                                                                     FALSE, TRUE, FALSE, parent_floater->getName(), button);
-	if (child_floater)
-	{
-		parent_floater->addDependentFloater(child_floater);
-	}
+    if (child_floater)
+    {
+        parent_floater->addDependentFloater(child_floater);
+    }
 }
 
 
 void LLPanelRegionDebugInfo::callbackAvatarID(const uuid_vec_t& ids, const std::vector<LLAvatarName> names)
 {
-	if (ids.empty() || names.empty()) return;
-	mTargetAvatar = ids[0];
-	getChild<LLUICtrl>("target_avatar_name")->setValue(LLSD(names[0].getCompleteName()));
-	refreshFromRegion( gAgent.getRegion() );
+    if (ids.empty() || names.empty()) return;
+    mTargetAvatar = ids[0];
+    getChild<LLUICtrl>("target_avatar_name")->setValue(LLSD(names[0].getCompleteName()));
+    refreshFromRegion( gAgent.getRegion() );
 }
 
 // static
 void LLPanelRegionDebugInfo::onClickReturn(void* data)
 {
-	LLPanelRegionDebugInfo* panelp = (LLPanelRegionDebugInfo*) data;
-	if (panelp->mTargetAvatar.isNull()) return;
-
-	LLSD args;
-	args["USER_NAME"] = panelp->getChild<LLUICtrl>("target_avatar_name")->getValue().asString();
-	LLSD payload;
-	payload["avatar_id"] = panelp->mTargetAvatar;
-	
-	U32 flags = SWD_ALWAYS_RETURN_OBJECTS;
-
-	if (panelp->getChild<LLUICtrl>("return_scripts")->getValue().asBoolean())
-	{
-		flags |= SWD_SCRIPTED_ONLY;
-	}
-	
-	if (panelp->getChild<LLUICtrl>("return_other_land")->getValue().asBoolean())
-	{
-		flags |= SWD_OTHERS_LAND_ONLY;
-	}
-	payload["flags"] = int(flags);
-	payload["return_estate_wide"] = panelp->getChild<LLUICtrl>("return_estate_wide")->getValue().asBoolean();
-	LLNotificationsUtil::add("EstateObjectReturn", args, payload, 
-									boost::bind(&LLPanelRegionDebugInfo::callbackReturn, panelp, _1, _2));
+    LLPanelRegionDebugInfo* panelp = (LLPanelRegionDebugInfo*) data;
+    if (panelp->mTargetAvatar.isNull()) return;
+
+    LLSD args;
+    args["USER_NAME"] = panelp->getChild<LLUICtrl>("target_avatar_name")->getValue().asString();
+    LLSD payload;
+    payload["avatar_id"] = panelp->mTargetAvatar;
+
+    U32 flags = SWD_ALWAYS_RETURN_OBJECTS;
+
+    if (panelp->getChild<LLUICtrl>("return_scripts")->getValue().asBoolean())
+    {
+        flags |= SWD_SCRIPTED_ONLY;
+    }
+
+    if (panelp->getChild<LLUICtrl>("return_other_land")->getValue().asBoolean())
+    {
+        flags |= SWD_OTHERS_LAND_ONLY;
+    }
+    payload["flags"] = int(flags);
+    payload["return_estate_wide"] = panelp->getChild<LLUICtrl>("return_estate_wide")->getValue().asBoolean();
+    LLNotificationsUtil::add("EstateObjectReturn", args, payload,
+                                    boost::bind(&LLPanelRegionDebugInfo::callbackReturn, panelp, _1, _2));
 }
 
 bool LLPanelRegionDebugInfo::callbackReturn(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0) return false;
-
-	LLUUID target_avatar = notification["payload"]["avatar_id"].asUUID();
-	if (!target_avatar.isNull())
-	{
-		U32 flags = notification["payload"]["flags"].asInteger();
-		bool return_estate_wide = notification["payload"]["return_estate_wide"];
-		if (return_estate_wide)
-		{
-			// send as estate message - routed by spaceserver to all regions in estate
-			strings_t strings;
-			strings.push_back(llformat("%d", flags));
-			strings.push_back(target_avatar.asString());
-
-			LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-		
-			sendEstateOwnerMessage(gMessageSystem, "estateobjectreturn", invoice, strings);
-		}
-		else
-		{
-			// send to this simulator only
-  			send_sim_wide_deletes(target_avatar, flags);
-  		}
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option != 0) return false;
+
+    LLUUID target_avatar = notification["payload"]["avatar_id"].asUUID();
+    if (!target_avatar.isNull())
+    {
+        U32 flags = notification["payload"]["flags"].asInteger();
+        bool return_estate_wide = notification["payload"]["return_estate_wide"];
+        if (return_estate_wide)
+        {
+            // send as estate message - routed by spaceserver to all regions in estate
+            strings_t strings;
+            strings.push_back(llformat("%d", flags));
+            strings.push_back(target_avatar.asString());
+
+            LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+
+            sendEstateOwnerMessage(gMessageSystem, "estateobjectreturn", invoice, strings);
+        }
+        else
+        {
+            // send to this simulator only
+            send_sim_wide_deletes(target_avatar, flags);
+        }
+    }
+    return false;
 }
 
 
 // static
 void LLPanelRegionDebugInfo::onClickTopColliders(void* data)
 {
-	LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data;
-	strings_t strings;
-	strings.push_back("1");	// one physics step
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	LLFloaterTopObjects* instance = LLFloaterReg::getTypedInstance<LLFloaterTopObjects>("top_objects");
-	if(!instance) return;
-	LLFloaterReg::showInstance("top_objects");
-	instance->clearList();
-	instance->disableRefreshBtn();
+    LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data;
+    strings_t strings;
+    strings.push_back("1"); // one physics step
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    LLFloaterTopObjects* instance = LLFloaterReg::getTypedInstance<LLFloaterTopObjects>("top_objects");
+    if(!instance) return;
+    LLFloaterReg::showInstance("top_objects");
+    instance->clearList();
+    instance->disableRefreshBtn();
 
-	self->getChildView("top_colliders_btn")->setEnabled(false);
-	self->getChildView("top_scripts_btn")->setEnabled(false);
+    self->getChildView("top_colliders_btn")->setEnabled(false);
+    self->getChildView("top_scripts_btn")->setEnabled(false);
 
-	self->sendEstateOwnerMessage(gMessageSystem, "colliders", invoice, strings);
+    self->sendEstateOwnerMessage(gMessageSystem, "colliders", invoice, strings);
 }
 
 // static
 void LLPanelRegionDebugInfo::onClickTopScripts(void* data)
 {
-	LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data;
-	strings_t strings;
-	strings.push_back("6");	// top 5 scripts
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	LLFloaterTopObjects* instance = LLFloaterReg::getTypedInstance<LLFloaterTopObjects>("top_objects");
-	if(!instance) return;
-	LLFloaterReg::showInstance("top_objects");
-	instance->clearList();
-	instance->disableRefreshBtn();
+    LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data;
+    strings_t strings;
+    strings.push_back("6"); // top 5 scripts
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    LLFloaterTopObjects* instance = LLFloaterReg::getTypedInstance<LLFloaterTopObjects>("top_objects");
+    if(!instance) return;
+    LLFloaterReg::showInstance("top_objects");
+    instance->clearList();
+    instance->disableRefreshBtn();
 
-	self->getChildView("top_colliders_btn")->setEnabled(false);
-	self->getChildView("top_scripts_btn")->setEnabled(false);
+    self->getChildView("top_colliders_btn")->setEnabled(false);
+    self->getChildView("top_scripts_btn")->setEnabled(false);
 
-	self->sendEstateOwnerMessage(gMessageSystem, "scripts", invoice, strings);
+    self->sendEstateOwnerMessage(gMessageSystem, "scripts", invoice, strings);
 }
 
 // static
 void LLPanelRegionDebugInfo::onClickRestart(void* data)
 {
-	LLPanelRegionDebugInfo* self = static_cast<LLPanelRegionDebugInfo*>(data);
-	LLSD payload;
-	payload["SECONDS"] = self->getChild<LLUICtrl>("restart_timer")->getValue().asString();
-	LLNotificationsUtil::add("ConfirmRestart", payload, payload,
-		boost::bind(&LLPanelRegionDebugInfo::callbackRestart, self, _1, _2));
+    LLPanelRegionDebugInfo* self = static_cast<LLPanelRegionDebugInfo*>(data);
+    LLSD payload;
+    payload["SECONDS"] = self->getChild<LLUICtrl>("restart_timer")->getValue().asString();
+    LLNotificationsUtil::add("ConfirmRestart", payload, payload,
+        boost::bind(&LLPanelRegionDebugInfo::callbackRestart, self, _1, _2));
 }
 
 bool LLPanelRegionDebugInfo::callbackRestart(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0) return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option != 0) return false;
 
-	strings_t strings;
-	strings.push_back(notification["payload"]["SECONDS"].asString());
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	sendEstateOwnerMessage(gMessageSystem, "restart", invoice, strings);
-	return false;
+    strings_t strings;
+    strings.push_back(notification["payload"]["SECONDS"].asString());
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    sendEstateOwnerMessage(gMessageSystem, "restart", invoice, strings);
+    return false;
 }
 
 // static
 void LLPanelRegionDebugInfo::onClickCancelRestart(void* data)
 {
-	LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data;
-	strings_t strings;
-	strings.push_back("-1");
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	self->sendEstateOwnerMessage(gMessageSystem, "restart", invoice, strings);
+    LLPanelRegionDebugInfo* self = (LLPanelRegionDebugInfo*)data;
+    strings_t strings;
+    strings.push_back("-1");
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    self->sendEstateOwnerMessage(gMessageSystem, "restart", invoice, strings);
 }
 
 // static
 void LLPanelRegionDebugInfo::onClickDebugConsole(void* data)
 {
-	LLFloaterReg::showInstance("region_debug_console");
+    LLFloaterReg::showInstance("region_debug_console");
 }
 
 bool LLPanelRegionTerrainInfo::validateTextureSizes()
@@ -1328,30 +1328,30 @@ bool LLPanelRegionTerrainInfo::validateTextureSizes()
     bool valid = true;
     static LLCachedControl<U32> max_texture_resolution(gSavedSettings, "RenderMaxTextureResolution", 2048);
     const S32 max_terrain_texture_size = (S32)max_texture_resolution;
-	for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
-	{
+    for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
+    {
         LLTextureCtrl* texture_ctrl = mTextureDetailCtrl[i];
-		if (!texture_ctrl) continue;
-
-		LLUUID image_asset_id = texture_ctrl->getImageAssetID();
-		LLViewerFetchedTexture* img = LLViewerTextureManager::getFetchedTexture(image_asset_id);
-		S32 components = img->getComponents();
-		// Must ask for highest resolution version's width. JC
-		S32 width = img->getFullWidth();
-		S32 height = img->getFullHeight();
-
-		//LL_INFOS() << "texture detail " << i << " is " << width << "x" << height << "x" << components << LL_ENDL;
-
-		if (components != 3 && components != 4)
-		{
-			LLSD args;
-			args["TEXTURE_NUM"] = i+1;
-			args["TEXTURE_BIT_DEPTH"] = llformat("%d",components * 8);
+        if (!texture_ctrl) continue;
+
+        LLUUID image_asset_id = texture_ctrl->getImageAssetID();
+        LLViewerFetchedTexture* img = LLViewerTextureManager::getFetchedTexture(image_asset_id);
+        S32 components = img->getComponents();
+        // Must ask for highest resolution version's width. JC
+        S32 width = img->getFullWidth();
+        S32 height = img->getFullHeight();
+
+        //LL_INFOS() << "texture detail " << i << " is " << width << "x" << height << "x" << components << LL_ENDL;
+
+        if (components != 3 && components != 4)
+        {
+            LLSD args;
+            args["TEXTURE_NUM"] = i+1;
+            args["TEXTURE_BIT_DEPTH"] = llformat("%d",components * 8);
             args["MAX_SIZE"] = max_terrain_texture_size;
-			LLNotificationsUtil::add("InvalidTerrainBitDepth", args);
+            LLNotificationsUtil::add("InvalidTerrainBitDepth", args);
             valid = false;
-			continue;
-		}
+            continue;
+        }
 
         if (components == 4)
         {
@@ -1383,20 +1383,20 @@ bool LLPanelRegionTerrainInfo::validateTextureSizes()
             }
         }
 
-		if (width > max_terrain_texture_size || height > max_terrain_texture_size)
-		{
+        if (width > max_terrain_texture_size || height > max_terrain_texture_size)
+        {
 
-			LLSD args;
-			args["TEXTURE_NUM"] = i+1;
-			args["TEXTURE_SIZE_X"] = width;
-			args["TEXTURE_SIZE_Y"] = height;
+            LLSD args;
+            args["TEXTURE_NUM"] = i+1;
+            args["TEXTURE_SIZE_X"] = width;
+            args["TEXTURE_SIZE_Y"] = height;
             args["MAX_SIZE"] = max_terrain_texture_size;
-			LLNotificationsUtil::add("InvalidTerrainSize", args);
-			valid = false;
-		}
-	}
+            LLNotificationsUtil::add("InvalidTerrainSize", args);
+            valid = false;
+        }
+    }
 
-	return valid;
+    return valid;
 }
 
 bool LLPanelRegionTerrainInfo::validateMaterials()
@@ -1473,18 +1473,18 @@ bool LLPanelRegionTerrainInfo::validateMaterials()
 
 BOOL LLPanelRegionTerrainInfo::validateTextureHeights()
 {
-	for (S32 i = 0; i < CORNER_COUNT; ++i)
-	{
-		std::string low = llformat("height_start_spin_%d", i);
-		std::string high = llformat("height_range_spin_%d", i);
+    for (S32 i = 0; i < CORNER_COUNT; ++i)
+    {
+        std::string low = llformat("height_start_spin_%d", i);
+        std::string high = llformat("height_range_spin_%d", i);
 
-		if (getChild<LLUICtrl>(low)->getValue().asReal() > getChild<LLUICtrl>(high)->getValue().asReal())
-		{
-			return FALSE;
-		}
-	}
+        if (getChild<LLUICtrl>(low)->getValue().asReal() > getChild<LLUICtrl>(high)->getValue().asReal())
+        {
+            return FALSE;
+        }
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 /////////////////////////////////////////////////////////////////////////////
@@ -1509,46 +1509,46 @@ LLPanelRegionTerrainInfo::LLPanelRegionTerrainInfo()
 
 BOOL LLPanelRegionTerrainInfo::postBuild()
 {
-	LLPanelRegionInfo::postBuild();
-	
-	initCtrl("water_height_spin");
-	initCtrl("terrain_raise_spin");
-	initCtrl("terrain_lower_spin");
+    LLPanelRegionInfo::postBuild();
+
+    initCtrl("water_height_spin");
+    initCtrl("terrain_raise_spin");
+    initCtrl("terrain_lower_spin");
 
     mMaterialTypeCtrl = findChild<LLCheckBoxCtrl>("terrain_material_type");
     if (mMaterialTypeCtrl) { mMaterialTypeCtrl->setCommitCallback(boost::bind(&LLPanelRegionTerrainInfo::onSelectMaterialType, this)); }
 
-	std::string buffer;
+    std::string buffer;
 
-	for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
-	{
-		buffer = llformat("texture_detail_%d", i);
-		initCtrl(buffer);
+    for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
+    {
+        buffer = llformat("texture_detail_%d", i);
+        initCtrl(buffer);
         mTextureDetailCtrl[i] = findChild<LLTextureCtrl>(buffer);
-	}
-	for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
-	{
-		buffer = llformat("material_detail_%d", i);
-		initCtrl(buffer);
+    }
+    for(S32 i = 0; i < LLTerrainMaterials::ASSET_COUNT; ++i)
+    {
+        buffer = llformat("material_detail_%d", i);
+        initCtrl(buffer);
         mMaterialDetailCtrl[i] = findChild<LLTextureCtrl>(buffer);
-	}
+    }
 
-	for(S32 i = 0; i < CORNER_COUNT; ++i)
-	{
-		buffer = llformat("height_start_spin_%d", i);
-		initCtrl(buffer);
-		buffer = llformat("height_range_spin_%d", i);
-		initCtrl(buffer);
-	}
+    for(S32 i = 0; i < CORNER_COUNT; ++i)
+    {
+        buffer = llformat("height_start_spin_%d", i);
+        initCtrl(buffer);
+        buffer = llformat("height_range_spin_%d", i);
+        initCtrl(buffer);
+    }
 
-	childSetAction("download_raw_btn", onClickDownloadRaw, this);
-	childSetAction("upload_raw_btn", onClickUploadRaw, this);
-	childSetAction("bake_terrain_btn", onClickBakeTerrain, this);
+    childSetAction("download_raw_btn", onClickDownloadRaw, this);
+    childSetAction("upload_raw_btn", onClickUploadRaw, this);
+    childSetAction("bake_terrain_btn", onClickBakeTerrain, this);
 
-	mAskedTextureHeights = false;
-	mConfirmedTextureHeights = false;
+    mAskedTextureHeights = false;
+    mConfirmedTextureHeights = false;
 
-	return LLPanelRegionInfo::postBuild();
+    return LLPanelRegionInfo::postBuild();
 }
 
 void LLPanelRegionTerrainInfo::onSelectMaterialType()
@@ -1584,9 +1584,9 @@ void LLPanelRegionTerrainInfo::updateForMaterialType()
 
     // Toggle visibility of labels
     LLUICtrl* texture_label = findChild<LLUICtrl>("detail_texture_text");
-	if (texture_label) { texture_label->setVisible(show_texture_controls); }
+    if (texture_label) { texture_label->setVisible(show_texture_controls); }
     LLUICtrl* material_label = findChild<LLUICtrl>("detail_material_text");
-	if (material_label) { material_label->setVisible(show_material_controls); }
+    if (material_label) { material_label->setVisible(show_material_controls); }
 
     // Toggle visibility of documentation labels for terrain blending ranges
     const std::vector<std::string> doc_suffixes { "5", "10", "11" };
@@ -1605,19 +1605,19 @@ void LLPanelRegionTerrainInfo::updateForMaterialType()
 // virtual
 bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
 {
-	BOOL owner_or_god = gAgent.isGodlike() 
-						|| (region && (region->getOwner() == gAgent.getID()));
-	BOOL owner_or_god_or_manager = owner_or_god
-						|| (region && region->isEstateManager());
-	setCtrlsEnabled(owner_or_god_or_manager);
+    BOOL owner_or_god = gAgent.isGodlike()
+                        || (region && (region->getOwner() == gAgent.getID()));
+    BOOL owner_or_god_or_manager = owner_or_god
+                        || (region && region->isEstateManager());
+    setCtrlsEnabled(owner_or_god_or_manager);
 
-	getChildView("apply_btn")->setEnabled(FALSE);
+    getChildView("apply_btn")->setEnabled(FALSE);
 
-	if (region)
-	{
-		getChild<LLUICtrl>("region_text")->setValue(LLSD(region->getName()));
+    if (region)
+    {
+        getChild<LLUICtrl>("region_text")->setValue(LLSD(region->getName()));
 
-		LLVLComposition* compp = region->getComposition();
+        LLVLComposition* compp = region->getComposition();
 
         static LLCachedControl<bool> feature_pbr_terrain_enabled(gSavedSettings, "RenderTerrainPBREnabled", false);
 
@@ -1710,42 +1710,42 @@ bool LLPanelRegionTerrainInfo::refreshFromRegion(LLViewerRegion* region)
             }
         }
 
-		std::string buffer;
-		for(S32 i = 0; i < CORNER_COUNT; ++i)
-    	{
-			buffer = llformat("height_start_spin_%d", i);
-			getChild<LLUICtrl>(buffer)->setValue(LLSD(compp->getStartHeight(i)));
-			buffer = llformat("height_range_spin_%d", i);
-			getChild<LLUICtrl>(buffer)->setValue(LLSD(compp->getHeightRange(i)));
-		}
-	}
-	else
-	{
-		LL_DEBUGS() << "no region set" << LL_ENDL;
-		getChild<LLUICtrl>("region_text")->setValue(LLSD(""));
-	}
-    
+        std::string buffer;
+        for(S32 i = 0; i < CORNER_COUNT; ++i)
+        {
+            buffer = llformat("height_start_spin_%d", i);
+            getChild<LLUICtrl>(buffer)->setValue(LLSD(compp->getStartHeight(i)));
+            buffer = llformat("height_range_spin_%d", i);
+            getChild<LLUICtrl>(buffer)->setValue(LLSD(compp->getHeightRange(i)));
+        }
+    }
+    else
+    {
+        LL_DEBUGS() << "no region set" << LL_ENDL;
+        getChild<LLUICtrl>("region_text")->setValue(LLSD(""));
+    }
+
     // Update visibility of terrain swatches, etc
     refresh();
 
-	getChildView("download_raw_btn")->setEnabled(owner_or_god);
-	getChildView("upload_raw_btn")->setEnabled(owner_or_god);
-	getChildView("bake_terrain_btn")->setEnabled(owner_or_god);
+    getChildView("download_raw_btn")->setEnabled(owner_or_god);
+    getChildView("upload_raw_btn")->setEnabled(owner_or_god);
+    getChildView("bake_terrain_btn")->setEnabled(owner_or_god);
 
-	return LLPanelRegionInfo::refreshFromRegion(region);
+    return LLPanelRegionInfo::refreshFromRegion(region);
 }
 
 
 // virtual
 BOOL LLPanelRegionTerrainInfo::sendUpdate()
 {
-	LL_INFOS() << "LLPanelRegionTerrainInfo::sendUpdate" << LL_ENDL;
+    LL_INFOS() << "LLPanelRegionTerrainInfo::sendUpdate" << LL_ENDL;
 
-	// Make sure user hasn't chosen wacky textures.
-	if (!validateTextureSizes())
-	{
-		return FALSE;
-	}
+    // Make sure user hasn't chosen wacky textures.
+    if (!validateTextureSizes())
+    {
+        return FALSE;
+    }
 
     // Prevent applying unsupported alpha blend/double-sided materials
     if (!validateMaterials())
@@ -1753,20 +1753,20 @@ BOOL LLPanelRegionTerrainInfo::sendUpdate()
         return FALSE;
     }
 
-	// Check if terrain Elevation Ranges are correct
-	if (gSavedSettings.getBOOL("RegionCheckTextureHeights") && !validateTextureHeights())
-	{
-		if (!mAskedTextureHeights)
-		{
-			LLNotificationsUtil::add("ConfirmTextureHeights", LLSD(), LLSD(), boost::bind(&LLPanelRegionTerrainInfo::callbackTextureHeights, this, _1, _2));
-			mAskedTextureHeights = true;
-			return FALSE;
-		}
-		else if (!mConfirmedTextureHeights)
-		{
-			return FALSE;
-		}
-	}
+    // Check if terrain Elevation Ranges are correct
+    if (gSavedSettings.getBOOL("RegionCheckTextureHeights") && !validateTextureHeights())
+    {
+        if (!mAskedTextureHeights)
+        {
+            LLNotificationsUtil::add("ConfirmTextureHeights", LLSD(), LLSD(), boost::bind(&LLPanelRegionTerrainInfo::callbackTextureHeights, this, _1, _2));
+            mAskedTextureHeights = true;
+            return FALSE;
+        }
+        else if (!mConfirmedTextureHeights)
+        {
+            return FALSE;
+        }
+    }
 
     std::string buffer;
     strings_t strings;
@@ -1784,8 +1784,8 @@ BOOL LLPanelRegionTerrainInfo::sendUpdate()
     // =======================================
     // Assemble and send texturedetail message
 
-	std::string id_str;
-	LLMessageSystem* msg = gMessageSystem;
+    std::string id_str;
+    LLMessageSystem* msg = gMessageSystem;
 
     // Send either material IDs instead of texture IDs depending on
     // material_type - they both occupy the same slot.
@@ -1819,146 +1819,146 @@ BOOL LLPanelRegionTerrainInfo::sendUpdate()
             mLastSetTextures[i] = tmp_id;
         }
     }
-	sendEstateOwnerMessage(msg, "texturedetail", invoice, strings);
-	strings.clear();
+    sendEstateOwnerMessage(msg, "texturedetail", invoice, strings);
+    strings.clear();
 
-	// ========================================
-	// Assemble and send textureheights message
+    // ========================================
+    // Assemble and send textureheights message
 
-	for(S32 i = 0; i < CORNER_COUNT; ++i)
-	{
-		buffer = llformat("height_start_spin_%d", i);
-		std::string buffer2 = llformat("height_range_spin_%d", i);
-		std::string buffer3 = llformat("%d %f %f", i, (F32)getChild<LLUICtrl>(buffer)->getValue().asReal(), (F32)getChild<LLUICtrl>(buffer2)->getValue().asReal());
-		strings.push_back(buffer3);
-	}
-	sendEstateOwnerMessage(msg, "textureheights", invoice, strings);
-	strings.clear();
+    for(S32 i = 0; i < CORNER_COUNT; ++i)
+    {
+        buffer = llformat("height_start_spin_%d", i);
+        std::string buffer2 = llformat("height_range_spin_%d", i);
+        std::string buffer3 = llformat("%d %f %f", i, (F32)getChild<LLUICtrl>(buffer)->getValue().asReal(), (F32)getChild<LLUICtrl>(buffer2)->getValue().asReal());
+        strings.push_back(buffer3);
+    }
+    sendEstateOwnerMessage(msg, "textureheights", invoice, strings);
+    strings.clear();
 
-	// ========================================
-	// Send texturecommit message
+    // ========================================
+    // Send texturecommit message
 
-	sendEstateOwnerMessage(msg, "texturecommit", invoice, strings);
+    sendEstateOwnerMessage(msg, "texturecommit", invoice, strings);
 
-	return TRUE;
+    return TRUE;
 }
 
 bool LLPanelRegionTerrainInfo::callbackTextureHeights(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option == 0) // ok
-	{
-		mConfirmedTextureHeights = true;
-	}
-	else if (option == 1) // cancel
-	{
-		mConfirmedTextureHeights = false;
-	}
-	else if (option == 2) // don't ask
-	{
-		gSavedSettings.setBOOL("RegionCheckTextureHeights", FALSE);
-		mConfirmedTextureHeights = true;
-	}
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option == 0) // ok
+    {
+        mConfirmedTextureHeights = true;
+    }
+    else if (option == 1) // cancel
+    {
+        mConfirmedTextureHeights = false;
+    }
+    else if (option == 2) // don't ask
+    {
+        gSavedSettings.setBOOL("RegionCheckTextureHeights", FALSE);
+        mConfirmedTextureHeights = true;
+    }
 
-	onBtnSet();
+    onBtnSet();
 
-	mAskedTextureHeights = false;
-	return false;
+    mAskedTextureHeights = false;
+    return false;
 }
 
 // static
 void LLPanelRegionTerrainInfo::onClickDownloadRaw(void* data)
 {
-	LLDir::getScrubbedFileName(LLRegionInfoModel::instance().mSimName+"_terrain.raw");
-	LLFilePickerReplyThread::startPicker(boost::bind(&LLPanelRegionTerrainInfo::onClickDownloadRawCallback, _1, data), LLFilePicker::FFSAVE_RAW, LLDir::getScrubbedFileName(LLRegionInfoModel::instance().mSimName + "_terrain.raw"));
+    LLDir::getScrubbedFileName(LLRegionInfoModel::instance().mSimName+"_terrain.raw");
+    LLFilePickerReplyThread::startPicker(boost::bind(&LLPanelRegionTerrainInfo::onClickDownloadRawCallback, _1, data), LLFilePicker::FFSAVE_RAW, LLDir::getScrubbedFileName(LLRegionInfoModel::instance().mSimName + "_terrain.raw"));
 }
 
 // static
 void LLPanelRegionTerrainInfo::onClickDownloadRawCallback(const std::vector<std::string>& filenames, void* data)
 {
-	std::string filepath = filenames[0];
-	gXferManager->expectFileForRequest(filepath);
+    std::string filepath = filenames[0];
+    gXferManager->expectFileForRequest(filepath);
 
-	LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data;
-	strings_t strings;
-	strings.push_back("download filename");
-	strings.push_back(filepath);
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	self->sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings);
+    LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data;
+    strings_t strings;
+    strings.push_back("download filename");
+    strings.push_back(filepath);
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    self->sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings);
 }
 
 // static
 void LLPanelRegionTerrainInfo::onClickUploadRaw(void* data)
 {
-	LLFilePickerReplyThread::startPicker(boost::bind(&LLPanelRegionTerrainInfo::onClickUploadRawCallback, data, _1), LLFilePicker::FFLOAD_RAW, false);
+    LLFilePickerReplyThread::startPicker(boost::bind(&LLPanelRegionTerrainInfo::onClickUploadRawCallback, data, _1), LLFilePicker::FFLOAD_RAW, false);
 }
 
 // static
 void LLPanelRegionTerrainInfo::onClickUploadRawCallback(void* data, const std::vector<std::string>& filenames)
 {
-	std::string filepath = filenames[0];
-	gXferManager->expectFileForTransfer(filepath);
+    std::string filepath = filenames[0];
+    gXferManager->expectFileForTransfer(filepath);
 
-	LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data;
-	strings_t strings;
-	strings.push_back("upload filename");
-	strings.push_back(filepath);
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	self->sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings);
+    LLPanelRegionTerrainInfo* self = (LLPanelRegionTerrainInfo*)data;
+    strings_t strings;
+    strings.push_back("upload filename");
+    strings.push_back(filepath);
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    self->sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings);
 
-	LLNotificationsUtil::add("RawUploadStarted");
+    LLNotificationsUtil::add("RawUploadStarted");
 }
 
 // static
 void LLPanelRegionTerrainInfo::onClickBakeTerrain(void* data)
 {
-	LLNotificationsUtil::add("ConfirmBakeTerrain", LLSD(), LLSD(), boost::bind(&LLPanelRegionTerrainInfo::callbackBakeTerrain, (LLPanelRegionTerrainInfo*)data, _1, _2));
+    LLNotificationsUtil::add("ConfirmBakeTerrain", LLSD(), LLSD(), boost::bind(&LLPanelRegionTerrainInfo::callbackBakeTerrain, (LLPanelRegionTerrainInfo*)data, _1, _2));
 }
 
 bool LLPanelRegionTerrainInfo::callbackBakeTerrain(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0) return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option != 0) return false;
 
-	strings_t strings;
-	strings.push_back("bake");
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings);
+    strings_t strings;
+    strings.push_back("bake");
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    sendEstateOwnerMessage(gMessageSystem, "terrain", invoice, strings);
 
-	return false;
+    return false;
 }
 
 /////////////////////////////////////////////////////////////////////////////
 // LLPanelEstateInfo
 //
 
-LLPanelEstateInfo::LLPanelEstateInfo() 
-:	LLPanelRegionInfo(),
-	mEstateID(0)	// invalid
+LLPanelEstateInfo::LLPanelEstateInfo()
+:   LLPanelRegionInfo(),
+    mEstateID(0)    // invalid
 {
-	LLEstateInfoModel& estate_info = LLEstateInfoModel::instance();
-	estate_info.setCommitCallback(boost::bind(&LLPanelEstateInfo::refreshFromEstate, this));
-	estate_info.setUpdateCallback(boost::bind(&LLPanelEstateInfo::refreshFromEstate, this));
+    LLEstateInfoModel& estate_info = LLEstateInfoModel::instance();
+    estate_info.setCommitCallback(boost::bind(&LLPanelEstateInfo::refreshFromEstate, this));
+    estate_info.setUpdateCallback(boost::bind(&LLPanelEstateInfo::refreshFromEstate, this));
 }
 
 // static
 void LLPanelEstateInfo::initDispatch(LLDispatcher& dispatch)
 {
-	std::string name;
-	
-	name.assign("estateupdateinfo");
-	static LLDispatchEstateUpdateInfo estate_update_info;
-	dispatch.addHandler(name, &estate_update_info);
+    std::string name;
 
-	name.assign("setaccess");
-	static LLDispatchSetEstateAccess set_access;
-	dispatch.addHandler(name, &set_access);
+    name.assign("estateupdateinfo");
+    static LLDispatchEstateUpdateInfo estate_update_info;
+    dispatch.addHandler(name, &estate_update_info);
 
-	name.assign("setexperience");
-	static LLDispatchSetEstateExperience set_experience;
-	dispatch.addHandler(name, &set_experience);
+    name.assign("setaccess");
+    static LLDispatchSetEstateAccess set_access;
+    dispatch.addHandler(name, &set_access);
 
-	estate_dispatch_initialized = true;
+    name.assign("setexperience");
+    static LLDispatchSetEstateExperience set_experience;
+    dispatch.addHandler(name, &set_experience);
+
+    estate_dispatch_initialized = true;
 }
 
 //---------------------------------------------------------------------------
@@ -1967,49 +1967,49 @@ void LLPanelEstateInfo::initDispatch(LLDispatcher& dispatch)
 
 void LLPanelEstateInfo::onClickKickUser()
 {
-	// this depends on the grandparent view being a floater
-	// in order to set up floater dependency
+    // this depends on the grandparent view being a floater
+    // in order to set up floater dependency
     LLView * button = findChild<LLButton>("kick_user_from_estate_btn");
-	LLFloater* parent_floater = gFloaterView->getParentFloater(this);
-	LLFloater* child_floater = LLFloaterAvatarPicker::show(boost::bind(&LLPanelEstateInfo::onKickUserCommit, this, _1), 
+    LLFloater* parent_floater = gFloaterView->getParentFloater(this);
+    LLFloater* child_floater = LLFloaterAvatarPicker::show(boost::bind(&LLPanelEstateInfo::onKickUserCommit, this, _1),
                                                                         FALSE, TRUE, FALSE, parent_floater->getName(), button);
-	if (child_floater)
-	{
-		parent_floater->addDependentFloater(child_floater);
-	}
+    if (child_floater)
+    {
+        parent_floater->addDependentFloater(child_floater);
+    }
 }
 
 void LLPanelEstateInfo::onKickUserCommit(const uuid_vec_t& ids)
 {
-	if (ids.empty()) return;
-	
-	//Bring up a confirmation dialog
-	LLSD args;
-	args["EVIL_USER"] = LLSLURL("agent", ids[0], "completename").getSLURLString();
-	LLSD payload;
-	payload["agent_id"] = ids[0];
-	LLNotificationsUtil::add("EstateKickUser", args, payload, boost::bind(&LLPanelEstateInfo::kickUserConfirm, this, _1, _2));
+    if (ids.empty()) return;
+
+    //Bring up a confirmation dialog
+    LLSD args;
+    args["EVIL_USER"] = LLSLURL("agent", ids[0], "completename").getSLURLString();
+    LLSD payload;
+    payload["agent_id"] = ids[0];
+    LLNotificationsUtil::add("EstateKickUser", args, payload, boost::bind(&LLPanelEstateInfo::kickUserConfirm, this, _1, _2));
 
 }
 
 bool LLPanelEstateInfo::kickUserConfirm(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	switch(option)
-	{
-	case 0:
-		{
-			//Kick User
-			strings_t strings;
-			strings.push_back(notification["payload"]["agent_id"].asString());
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    switch(option)
+    {
+    case 0:
+        {
+            //Kick User
+            strings_t strings;
+            strings.push_back(notification["payload"]["agent_id"].asString());
 
-			sendEstateOwnerMessage(gMessageSystem, "kickestate", LLFloaterRegionInfo::getLastInvoice(), strings);
-			break;
-		}
-	default:
-		break;
-	}
-	return false;
+            sendEstateOwnerMessage(gMessageSystem, "kickestate", LLFloaterRegionInfo::getLastInvoice(), strings);
+            break;
+        }
+    default:
+        break;
+    }
+    return false;
 }
 
 //---------------------------------------------------------------------------
@@ -2020,270 +2020,270 @@ bool LLPanelEstateInfo::kickUserConfirm(const LLSD& notification, const LLSD& re
 //---------------------------------------------------------------------------
 std::string all_estates_text()
 {
-	LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate();
-	if (!panel) return "(" + LLTrans::getString("RegionInfoError") + ")";
-
-	LLStringUtil::format_map_t args;
-	std::string owner = panel->getOwnerName();
-
-	LLViewerRegion* region = gAgent.getRegion();
-	if (gAgent.isGodlike())
-	{
-		args["[OWNER]"] = owner.c_str();
-		return LLTrans::getString("RegionInfoAllEstatesOwnedBy", args);
-	}
-	else if (region && region->getOwner() == gAgent.getID())
-	{
-		return LLTrans::getString("RegionInfoAllEstatesYouOwn");
-	}
-	else if (region && region->isEstateManager())
-	{
-		args["[OWNER]"] = owner.c_str();
-		return LLTrans::getString("RegionInfoAllEstatesYouManage", args);
-	}
-	else
-	{
-		return "(" + LLTrans::getString("RegionInfoError") + ")";
-	}
+    LLPanelEstateInfo* panel = LLFloaterRegionInfo::getPanelEstate();
+    if (!panel) return "(" + LLTrans::getString("RegionInfoError") + ")";
+
+    LLStringUtil::format_map_t args;
+    std::string owner = panel->getOwnerName();
+
+    LLViewerRegion* region = gAgent.getRegion();
+    if (gAgent.isGodlike())
+    {
+        args["[OWNER]"] = owner.c_str();
+        return LLTrans::getString("RegionInfoAllEstatesOwnedBy", args);
+    }
+    else if (region && region->getOwner() == gAgent.getID())
+    {
+        return LLTrans::getString("RegionInfoAllEstatesYouOwn");
+    }
+    else if (region && region->isEstateManager())
+    {
+        args["[OWNER]"] = owner.c_str();
+        return LLTrans::getString("RegionInfoAllEstatesYouManage", args);
+    }
+    else
+    {
+        return "(" + LLTrans::getString("RegionInfoError") + ")";
+    }
 }
 
 // static
 bool LLPanelEstateInfo::isLindenEstate()
 {
-	U32 estate_id = LLEstateInfoModel::instance().getID();
-	return (estate_id <= ESTATE_LAST_LINDEN);
+    U32 estate_id = LLEstateInfoModel::instance().getID();
+    return (estate_id <= ESTATE_LAST_LINDEN);
 }
 
 struct LLEstateAccessChangeInfo
 {
-	LLEstateAccessChangeInfo(const LLSD& sd)
-	{
-		mDialogName = sd["dialog_name"].asString();
-		mOperationFlag = (U32)sd["operation"].asInteger();
-		LLSD::array_const_iterator end_it = sd["allowed_ids"].endArray();
-		for (LLSD::array_const_iterator id_it = sd["allowed_ids"].beginArray();
-			id_it != end_it;
-			++id_it)
-		{
-			mAgentOrGroupIDs.push_back(id_it->asUUID());
-		}
-	}
-
-	const LLSD asLLSD() const
-	{
-		LLSD sd;
-		sd["name"] = mDialogName;
-		sd["operation"] = (S32)mOperationFlag;
-		for (U32 i = 0; i < mAgentOrGroupIDs.size(); ++i)
-		{
-			sd["allowed_ids"].append(mAgentOrGroupIDs[i]);
-			if (mAgentNames.size() > i)
-			{
-				sd["allowed_names"].append(mAgentNames[i].asLLSD());
-			}
-		}
-		return sd;
-	}
-
-	U32 mOperationFlag;	// ESTATE_ACCESS_BANNED_AGENT_ADD, _REMOVE, etc.
-	std::string mDialogName;
-	uuid_vec_t mAgentOrGroupIDs; // List of agent IDs to apply to this change
-	std::vector<LLAvatarName> mAgentNames; // Optional list of the agent names for notifications
+    LLEstateAccessChangeInfo(const LLSD& sd)
+    {
+        mDialogName = sd["dialog_name"].asString();
+        mOperationFlag = (U32)sd["operation"].asInteger();
+        LLSD::array_const_iterator end_it = sd["allowed_ids"].endArray();
+        for (LLSD::array_const_iterator id_it = sd["allowed_ids"].beginArray();
+            id_it != end_it;
+            ++id_it)
+        {
+            mAgentOrGroupIDs.push_back(id_it->asUUID());
+        }
+    }
+
+    const LLSD asLLSD() const
+    {
+        LLSD sd;
+        sd["name"] = mDialogName;
+        sd["operation"] = (S32)mOperationFlag;
+        for (U32 i = 0; i < mAgentOrGroupIDs.size(); ++i)
+        {
+            sd["allowed_ids"].append(mAgentOrGroupIDs[i]);
+            if (mAgentNames.size() > i)
+            {
+                sd["allowed_names"].append(mAgentNames[i].asLLSD());
+            }
+        }
+        return sd;
+    }
+
+    U32 mOperationFlag; // ESTATE_ACCESS_BANNED_AGENT_ADD, _REMOVE, etc.
+    std::string mDialogName;
+    uuid_vec_t mAgentOrGroupIDs; // List of agent IDs to apply to this change
+    std::vector<LLAvatarName> mAgentNames; // Optional list of the agent names for notifications
 };
 
 // static
 void LLPanelEstateInfo::updateEstateOwnerName(const std::string& name)
 {
-	LLPanelEstateInfo* panelp = LLFloaterRegionInfo::getPanelEstate();
-	if (panelp)
-	{
-		panelp->setOwnerName(name);
-	}
+    LLPanelEstateInfo* panelp = LLFloaterRegionInfo::getPanelEstate();
+    if (panelp)
+    {
+        panelp->setOwnerName(name);
+    }
 }
 
 // static
 void LLPanelEstateInfo::updateEstateName(const std::string& name)
 {
-	LLPanelEstateInfo* panelp = LLFloaterRegionInfo::getPanelEstate();
-	if (panelp)
-	{
-		panelp->getChildRef<LLTextBox>("estate_name").setText(name);
-	}
+    LLPanelEstateInfo* panelp = LLFloaterRegionInfo::getPanelEstate();
+    if (panelp)
+    {
+        panelp->getChildRef<LLTextBox>("estate_name").setText(name);
+    }
 }
 
 void LLPanelEstateInfo::updateControls(LLViewerRegion* region)
 {
-	BOOL god = gAgent.isGodlike();
-	BOOL owner = (region && (region->getOwner() == gAgent.getID()));
-	BOOL manager = (region && region->isEstateManager());
-	setCtrlsEnabled(god || owner || manager);
-	
-	getChildView("apply_btn")->setEnabled(FALSE);
+    BOOL god = gAgent.isGodlike();
+    BOOL owner = (region && (region->getOwner() == gAgent.getID()));
+    BOOL manager = (region && region->isEstateManager());
+    setCtrlsEnabled(god || owner || manager);
+
+    getChildView("apply_btn")->setEnabled(FALSE);
     getChildView("estate_owner")->setEnabled(TRUE);
-	getChildView("message_estate_btn")->setEnabled(god || owner || manager);
-	getChildView("kick_user_from_estate_btn")->setEnabled(god || owner || manager);
+    getChildView("message_estate_btn")->setEnabled(god || owner || manager);
+    getChildView("kick_user_from_estate_btn")->setEnabled(god || owner || manager);
 
-	refresh();
+    refresh();
 }
 
 bool LLPanelEstateInfo::refreshFromRegion(LLViewerRegion* region)
 {
-	updateControls(region);
-	
-	// let the parent class handle the general data collection. 
-	bool rv = LLPanelRegionInfo::refreshFromRegion(region);
+    updateControls(region);
+
+    // let the parent class handle the general data collection.
+    bool rv = LLPanelRegionInfo::refreshFromRegion(region);
+
+    // We want estate info. To make sure it works across region
+    // boundaries and multiple packets, we add a serial number to the
+    // integers and track against that on update.
+    strings_t strings;
+    //integers_t integers;
+    //LLFloaterRegionInfo::incrementSerial();
+    LLFloaterRegionInfo::nextInvoice();
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    //integers.push_back(LLFloaterRegionInfo::());::getPanelEstate();
 
-	// We want estate info. To make sure it works across region
-	// boundaries and multiple packets, we add a serial number to the
-	// integers and track against that on update.
-	strings_t strings;
-	//integers_t integers;
-	//LLFloaterRegionInfo::incrementSerial();
-	LLFloaterRegionInfo::nextInvoice();
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	//integers.push_back(LLFloaterRegionInfo::());::getPanelEstate();
 
-	
-	sendEstateOwnerMessage(gMessageSystem, "getinfo", invoice, strings);
+    sendEstateOwnerMessage(gMessageSystem, "getinfo", invoice, strings);
 
-	refresh();
+    refresh();
 
-	return rv;
+    return rv;
 }
 
 void LLPanelEstateInfo::updateChild(LLUICtrl* child_ctrl)
 {
-	// Ensure appropriate state of the management ui.
-	updateControls(gAgent.getRegion());
+    // Ensure appropriate state of the management ui.
+    updateControls(gAgent.getRegion());
 }
 
 bool LLPanelEstateInfo::estateUpdate(LLMessageSystem* msg)
 {
-	LL_INFOS() << "LLPanelEstateInfo::estateUpdate()" << LL_ENDL;
-	return false;
+    LL_INFOS() << "LLPanelEstateInfo::estateUpdate()" << LL_ENDL;
+    return false;
 }
 
 
 BOOL LLPanelEstateInfo::postBuild()
 {
-	// set up the callbacks for the generic controls
-	initCtrl("externally_visible_radio");
-	initCtrl("allow_direct_teleport");
-	initCtrl("limit_payment");
-	initCtrl("limit_age_verified");
+    // set up the callbacks for the generic controls
+    initCtrl("externally_visible_radio");
+    initCtrl("allow_direct_teleport");
+    initCtrl("limit_payment");
+    initCtrl("limit_age_verified");
     initCtrl("limit_bots");
-	initCtrl("voice_chat_check");
+    initCtrl("voice_chat_check");
     initCtrl("parcel_access_override");
 
-	childSetAction("message_estate_btn", boost::bind(&LLPanelEstateInfo::onClickMessageEstate, this));
-	childSetAction("kick_user_from_estate_btn", boost::bind(&LLPanelEstateInfo::onClickKickUser, this));
+    childSetAction("message_estate_btn", boost::bind(&LLPanelEstateInfo::onClickMessageEstate, this));
+    childSetAction("kick_user_from_estate_btn", boost::bind(&LLPanelEstateInfo::onClickKickUser, this));
 
-	getChild<LLUICtrl>("parcel_access_override")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeAccessOverride, this));
+    getChild<LLUICtrl>("parcel_access_override")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeAccessOverride, this));
 
-	getChild<LLUICtrl>("externally_visible_radio")->setFocus(TRUE);
+    getChild<LLUICtrl>("externally_visible_radio")->setFocus(TRUE);
 
     getChild<LLTextBox>("estate_owner")->setIsFriendCallback(LLAvatarActions::isFriend);
 
-	return LLPanelRegionInfo::postBuild();
+    return LLPanelRegionInfo::postBuild();
 }
 
 void LLPanelEstateInfo::refresh()
 {
-	// Disable access restriction controls if they make no sense.
-	bool public_access = ("estate_public_access" == getChild<LLUICtrl>("externally_visible_radio")->getValue().asString());
+    // Disable access restriction controls if they make no sense.
+    bool public_access = ("estate_public_access" == getChild<LLUICtrl>("externally_visible_radio")->getValue().asString());
 
-	getChildView("Only Allow")->setEnabled(public_access);
-	getChildView("limit_payment")->setEnabled(public_access);
-	getChildView("limit_age_verified")->setEnabled(public_access);
+    getChildView("Only Allow")->setEnabled(public_access);
+    getChildView("limit_payment")->setEnabled(public_access);
+    getChildView("limit_age_verified")->setEnabled(public_access);
     getChildView("limit_bots")->setEnabled(public_access);
 
-	// if this is set to false, then the limit fields are meaningless and should be turned off
-	if (public_access == false)
-	{
-		getChild<LLUICtrl>("limit_payment")->setValue(false);
-		getChild<LLUICtrl>("limit_age_verified")->setValue(false);
+    // if this is set to false, then the limit fields are meaningless and should be turned off
+    if (public_access == false)
+    {
+        getChild<LLUICtrl>("limit_payment")->setValue(false);
+        getChild<LLUICtrl>("limit_age_verified")->setValue(false);
         getChild<LLUICtrl>("limit_bots")->setValue(false);
-	}
+    }
 }
 
 void LLPanelEstateInfo::refreshFromEstate()
 {
-	const LLEstateInfoModel& estate_info = LLEstateInfoModel::instance();
+    const LLEstateInfoModel& estate_info = LLEstateInfoModel::instance();
 
-	getChild<LLUICtrl>("estate_name")->setValue(estate_info.getName());
-	setOwnerName(LLSLURL("agent", estate_info.getOwnerID(), "inspect").getSLURLString());
+    getChild<LLUICtrl>("estate_name")->setValue(estate_info.getName());
+    setOwnerName(LLSLURL("agent", estate_info.getOwnerID(), "inspect").getSLURLString());
 
-	getChild<LLUICtrl>("externally_visible_radio")->setValue(estate_info.getIsExternallyVisible() ? "estate_public_access" : "estate_restricted_access");
-	getChild<LLUICtrl>("voice_chat_check")->setValue(estate_info.getAllowVoiceChat());
-	getChild<LLUICtrl>("allow_direct_teleport")->setValue(estate_info.getAllowDirectTeleport());
-	getChild<LLUICtrl>("limit_payment")->setValue(estate_info.getDenyAnonymous());
-	getChild<LLUICtrl>("limit_age_verified")->setValue(estate_info.getDenyAgeUnverified());
+    getChild<LLUICtrl>("externally_visible_radio")->setValue(estate_info.getIsExternallyVisible() ? "estate_public_access" : "estate_restricted_access");
+    getChild<LLUICtrl>("voice_chat_check")->setValue(estate_info.getAllowVoiceChat());
+    getChild<LLUICtrl>("allow_direct_teleport")->setValue(estate_info.getAllowDirectTeleport());
+    getChild<LLUICtrl>("limit_payment")->setValue(estate_info.getDenyAnonymous());
+    getChild<LLUICtrl>("limit_age_verified")->setValue(estate_info.getDenyAgeUnverified());
     getChild<LLUICtrl>("parcel_access_override")->setValue(estate_info.getAllowAccessOverride());
     getChild<LLUICtrl>("limit_bots")->setValue(estate_info.getDenyScriptedAgents());
 
-	// Ensure appriopriate state of the management UI
-	updateControls(gAgent.getRegion());
-	refresh();
+    // Ensure appriopriate state of the management UI
+    updateControls(gAgent.getRegion());
+    refresh();
 }
 
 BOOL LLPanelEstateInfo::sendUpdate()
 {
-	LL_INFOS() << "LLPanelEsateInfo::sendUpdate()" << LL_ENDL;
+    LL_INFOS() << "LLPanelEsateInfo::sendUpdate()" << LL_ENDL;
 
-	LLNotification::Params params("ChangeLindenEstate");
-	params.functor.function(boost::bind(&LLPanelEstateInfo::callbackChangeLindenEstate, this, _1, _2));
+    LLNotification::Params params("ChangeLindenEstate");
+    params.functor.function(boost::bind(&LLPanelEstateInfo::callbackChangeLindenEstate, this, _1, _2));
 
-	if (isLindenEstate())
-	{
-		// trying to change reserved estate, warn
-		LLNotifications::instance().add(params);
-	}
-	else
-	{
-		// for normal estates, just make the change
-		LLNotifications::instance().forceResponse(params, 0);
-	}
-	return TRUE;
+    if (isLindenEstate())
+    {
+        // trying to change reserved estate, warn
+        LLNotifications::instance().add(params);
+    }
+    else
+    {
+        // for normal estates, just make the change
+        LLNotifications::instance().forceResponse(params, 0);
+    }
+    return TRUE;
 }
 
 bool LLPanelEstateInfo::callbackChangeLindenEstate(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	switch(option)
-	{
-	case 0:
-		{
-			LLEstateInfoModel& estate_info = LLEstateInfoModel::instance();
-
-			// update model
-			estate_info.setUseFixedSun(false); // we don't support fixed sun estates anymore
-			estate_info.setIsExternallyVisible("estate_public_access" == getChild<LLUICtrl>("externally_visible_radio")->getValue().asString());
-			estate_info.setAllowDirectTeleport(getChild<LLUICtrl>("allow_direct_teleport")->getValue().asBoolean());
-			estate_info.setDenyAnonymous(getChild<LLUICtrl>("limit_payment")->getValue().asBoolean());
-			estate_info.setDenyAgeUnverified(getChild<LLUICtrl>("limit_age_verified")->getValue().asBoolean());
-			estate_info.setAllowVoiceChat(getChild<LLUICtrl>("voice_chat_check")->getValue().asBoolean());
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    switch(option)
+    {
+    case 0:
+        {
+            LLEstateInfoModel& estate_info = LLEstateInfoModel::instance();
+
+            // update model
+            estate_info.setUseFixedSun(false); // we don't support fixed sun estates anymore
+            estate_info.setIsExternallyVisible("estate_public_access" == getChild<LLUICtrl>("externally_visible_radio")->getValue().asString());
+            estate_info.setAllowDirectTeleport(getChild<LLUICtrl>("allow_direct_teleport")->getValue().asBoolean());
+            estate_info.setDenyAnonymous(getChild<LLUICtrl>("limit_payment")->getValue().asBoolean());
+            estate_info.setDenyAgeUnverified(getChild<LLUICtrl>("limit_age_verified")->getValue().asBoolean());
+            estate_info.setAllowVoiceChat(getChild<LLUICtrl>("voice_chat_check")->getValue().asBoolean());
             estate_info.setAllowAccessOverride(getChild<LLUICtrl>("parcel_access_override")->getValue().asBoolean());
             estate_info.setDenyScriptedAgents(getChild<LLUICtrl>("limit_bots")->getValue().asBoolean());
             // JIGGLYPUFF
             //estate_info.setAllowAccessOverride(getChild<LLUICtrl>("")->getValue().asBoolean());
-			// send the update to sim
-			estate_info.sendEstateInfo();
-		}
-
-		// we don't want to do this because we'll get it automatically from the sim
-		// after the spaceserver processes it
-//		else
-//		{
-//			// caps method does not automatically send this info
-//			LLFloaterRegionInfo::requestRegionInfo();
-//		}
-		break;
-	case 1:
-	default:
-		// do nothing
-		break;
-	}
-	return false;
+            // send the update to sim
+            estate_info.sendEstateInfo();
+        }
+
+        // we don't want to do this because we'll get it automatically from the sim
+        // after the spaceserver processes it
+//      else
+//      {
+//          // caps method does not automatically send this info
+//          LLFloaterRegionInfo::requestRegionInfo();
+//      }
+        break;
+    case 1:
+    default:
+        // do nothing
+        break;
+    }
+    return false;
 }
 
 
@@ -2293,326 +2293,326 @@ bool LLPanelEstateInfo::callbackChangeLindenEstate(const LLSD& notification, con
 // IParam[0] = serial
 void LLPanelEstateInfo::getEstateOwner()
 {
-	// TODO -- disable the panel
-	// and call this function whenever we cross a region boundary
-	// re-enable when owner matches, and get new estate info
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_EstateOwnerRequest);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    // TODO -- disable the panel
+    // and call this function whenever we cross a region boundary
+    // re-enable when owner matches, and get new estate info
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_EstateOwnerRequest);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
 
-	msg->nextBlockFast(_PREHASH_RequestData);
-	msg->addStringFast(_PREHASH_Request, "getowner");
+    msg->nextBlockFast(_PREHASH_RequestData);
+    msg->addStringFast(_PREHASH_Request, "getowner");
 
-	// we send an empty string so that the variable block is not empty
-	msg->nextBlockFast(_PREHASH_StringData);
-	msg->addStringFast(_PREHASH_SParam, "");
+    // we send an empty string so that the variable block is not empty
+    msg->nextBlockFast(_PREHASH_StringData);
+    msg->addStringFast(_PREHASH_SParam, "");
 
-	msg->nextBlockFast(_PREHASH_IntegerData);
-	msg->addS32Fast(_PREHASH_IParam, LLFloaterRegionInfo::getSerial());
+    msg->nextBlockFast(_PREHASH_IntegerData);
+    msg->addS32Fast(_PREHASH_IParam, LLFloaterRegionInfo::getSerial());
 
-	gAgent.sendMessage();
+    gAgent.sendMessage();
 }
 */
 
 const std::string LLPanelEstateInfo::getOwnerName() const
 {
-	return getChild<LLUICtrl>("estate_owner")->getValue().asString();
+    return getChild<LLUICtrl>("estate_owner")->getValue().asString();
 }
 
 void LLPanelEstateInfo::setOwnerName(const std::string& name)
 {
-	getChild<LLUICtrl>("estate_owner")->setValue(LLSD(name));
+    getChild<LLUICtrl>("estate_owner")->setValue(LLSD(name));
 }
 
 // static
 void LLPanelEstateInfo::onClickMessageEstate(void* userdata)
 {
-	LL_INFOS() << "LLPanelEstateInfo::onClickMessageEstate" << LL_ENDL;
-	LLNotificationsUtil::add("MessageEstate", LLSD(), LLSD(), boost::bind(&LLPanelEstateInfo::onMessageCommit, (LLPanelEstateInfo*)userdata, _1, _2));
+    LL_INFOS() << "LLPanelEstateInfo::onClickMessageEstate" << LL_ENDL;
+    LLNotificationsUtil::add("MessageEstate", LLSD(), LLSD(), boost::bind(&LLPanelEstateInfo::onMessageCommit, (LLPanelEstateInfo*)userdata, _1, _2));
 }
 
 bool LLPanelEstateInfo::onMessageCommit(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	std::string text = response["message"].asString();
-	if(option != 0) return false;
-	if(text.empty()) return false;
-	LL_INFOS() << "Message to everyone: " << text << LL_ENDL;
-	strings_t strings;
-	//integers_t integers;
-	std::string name;
-	LLAgentUI::buildFullname(name);
-	strings.push_back(strings_t::value_type(name));
-	strings.push_back(strings_t::value_type(text));
-	LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
-	sendEstateOwnerMessage(gMessageSystem, "instantmessage", invoice, strings);
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    std::string text = response["message"].asString();
+    if(option != 0) return false;
+    if(text.empty()) return false;
+    LL_INFOS() << "Message to everyone: " << text << LL_ENDL;
+    strings_t strings;
+    //integers_t integers;
+    std::string name;
+    LLAgentUI::buildFullname(name);
+    strings.push_back(strings_t::value_type(name));
+    strings.push_back(strings_t::value_type(text));
+    LLUUID invoice(LLFloaterRegionInfo::getLastInvoice());
+    sendEstateOwnerMessage(gMessageSystem, "instantmessage", invoice, strings);
+    return false;
 }
 
 void LLPanelEstateInfo::onChangeAccessOverride()
 {
-	if (!getChild<LLUICtrl>("parcel_access_override")->getValue().asBoolean())
-	{
-		LLNotificationsUtil::add("EstateParcelAccessOverride");
-	}
+    if (!getChild<LLUICtrl>("parcel_access_override")->getValue().asBoolean())
+    {
+        LLNotificationsUtil::add("EstateParcelAccessOverride");
+    }
 }
 
 LLPanelEstateCovenant::LLPanelEstateCovenant()
-	:
-	mCovenantID(LLUUID::null),
-	mAssetStatus(ASSET_ERROR)
+    :
+    mCovenantID(LLUUID::null),
+    mAssetStatus(ASSET_ERROR)
 {
 }
 
-// virtual 
+// virtual
 bool LLPanelEstateCovenant::refreshFromRegion(LLViewerRegion* region)
 {
-	LLTextBox* region_name = getChild<LLTextBox>("region_name_text");
-	if (region_name)
-	{
-		region_name->setText(region->getName());
-	}
-
-	LLTextBox* resellable_clause = getChild<LLTextBox>("resellable_clause");
-	if (resellable_clause)
-	{
-		if (region->getRegionFlag(REGION_FLAGS_BLOCK_LAND_RESELL))
-		{
-			resellable_clause->setText(getString("can_not_resell"));
-		}
-		else
-		{
-			resellable_clause->setText(getString("can_resell"));
-		}
-	}
-	
-	LLTextBox* changeable_clause = getChild<LLTextBox>("changeable_clause");
-	if (changeable_clause)
-	{
-		if (region->getRegionFlag(REGION_FLAGS_ALLOW_PARCEL_CHANGES))
-		{
-			changeable_clause->setText(getString("can_change"));
-		}
-		else
-		{
-			changeable_clause->setText(getString("can_not_change"));
-		}
-	}
-
-	LLTextBox* region_maturity = getChild<LLTextBox>("region_maturity_text");
-	if (region_maturity)
-	{
-		region_maturity->setText(region->getSimAccessString());
-	}
-	
-	LLTextBox* region_landtype = getChild<LLTextBox>("region_landtype_text");
-	region_landtype->setText(region->getLocalizedSimProductName());
+    LLTextBox* region_name = getChild<LLTextBox>("region_name_text");
+    if (region_name)
+    {
+        region_name->setText(region->getName());
+    }
+
+    LLTextBox* resellable_clause = getChild<LLTextBox>("resellable_clause");
+    if (resellable_clause)
+    {
+        if (region->getRegionFlag(REGION_FLAGS_BLOCK_LAND_RESELL))
+        {
+            resellable_clause->setText(getString("can_not_resell"));
+        }
+        else
+        {
+            resellable_clause->setText(getString("can_resell"));
+        }
+    }
+
+    LLTextBox* changeable_clause = getChild<LLTextBox>("changeable_clause");
+    if (changeable_clause)
+    {
+        if (region->getRegionFlag(REGION_FLAGS_ALLOW_PARCEL_CHANGES))
+        {
+            changeable_clause->setText(getString("can_change"));
+        }
+        else
+        {
+            changeable_clause->setText(getString("can_not_change"));
+        }
+    }
+
+    LLTextBox* region_maturity = getChild<LLTextBox>("region_maturity_text");
+    if (region_maturity)
+    {
+        region_maturity->setText(region->getSimAccessString());
+    }
+
+    LLTextBox* region_landtype = getChild<LLTextBox>("region_landtype_text");
+    region_landtype->setText(region->getLocalizedSimProductName());
 
     getChild<LLButton>("reset_covenant")->setEnabled(gAgent.isGodlike() || (region && region->canManageEstate()));
-	
-	// let the parent class handle the general data collection. 
-	bool rv = LLPanelRegionInfo::refreshFromRegion(region);
-	LLMessageSystem *msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_EstateCovenantRequest);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID,	gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID,gAgent.getSessionID());
-	msg->sendReliable(region->getHost());
-	return rv;
-}
-
-// virtual 
+
+    // let the parent class handle the general data collection.
+    bool rv = LLPanelRegionInfo::refreshFromRegion(region);
+    LLMessageSystem *msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_EstateCovenantRequest);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID,  gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID,gAgent.getSessionID());
+    msg->sendReliable(region->getHost());
+    return rv;
+}
+
+// virtual
 bool LLPanelEstateCovenant::estateUpdate(LLMessageSystem* msg)
 {
-	LL_INFOS() << "LLPanelEstateCovenant::estateUpdate()" << LL_ENDL;
-	return true;
+    LL_INFOS() << "LLPanelEstateCovenant::estateUpdate()" << LL_ENDL;
+    return true;
 }
-	
-// virtual 
+
+// virtual
 BOOL LLPanelEstateCovenant::postBuild()
 {
-	mEstateNameText = getChild<LLTextBox>("estate_name_text");
-	mEstateOwnerText = getChild<LLTextBox>("estate_owner_text");
+    mEstateNameText = getChild<LLTextBox>("estate_name_text");
+    mEstateOwnerText = getChild<LLTextBox>("estate_owner_text");
     mEstateOwnerText->setIsFriendCallback(LLAvatarActions::isFriend);
-	mLastModifiedText = getChild<LLTextBox>("covenant_timestamp_text");
-	mEditor = getChild<LLViewerTextEditor>("covenant_editor");
-	LLButton* reset_button = getChild<LLButton>("reset_covenant");
-	reset_button->setEnabled(gAgent.canManageEstate());
-	reset_button->setClickedCallback(LLPanelEstateCovenant::resetCovenantID, NULL);
+    mLastModifiedText = getChild<LLTextBox>("covenant_timestamp_text");
+    mEditor = getChild<LLViewerTextEditor>("covenant_editor");
+    LLButton* reset_button = getChild<LLButton>("reset_covenant");
+    reset_button->setEnabled(gAgent.canManageEstate());
+    reset_button->setClickedCallback(LLPanelEstateCovenant::resetCovenantID, NULL);
 
-	return LLPanelRegionInfo::postBuild();
+    return LLPanelRegionInfo::postBuild();
 }
 
-// virtual 
+// virtual
 void LLPanelEstateCovenant::updateChild(LLUICtrl* child_ctrl)
 {
 }
 
 // virtual
 BOOL LLPanelEstateCovenant::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
-								  EDragAndDropType cargo_type,
-								  void* cargo_data,
-								  EAcceptance* accept,
-								  std::string& tooltip_msg)
-{
-	LLInventoryItem* item = (LLInventoryItem*)cargo_data;
-
-	if (!gAgent.canManageEstate())
-	{
-		*accept = ACCEPT_NO;
-		return TRUE;
-	}
-
-	switch(cargo_type)
-	{
-	case DAD_NOTECARD:
-		*accept = ACCEPT_YES_COPY_SINGLE;
-		if (item && drop)
-		{
-			LLSD payload;
-			payload["item_id"] = item->getUUID();
-			LLNotificationsUtil::add("EstateChangeCovenant", LLSD(), payload,
-									LLPanelEstateCovenant::confirmChangeCovenantCallback);
-		}
-		break;
-	default:
-		*accept = ACCEPT_NO;
-		break;
-	}
-
-	return TRUE;
-} 
-
-// static 
+                                  EDragAndDropType cargo_type,
+                                  void* cargo_data,
+                                  EAcceptance* accept,
+                                  std::string& tooltip_msg)
+{
+    LLInventoryItem* item = (LLInventoryItem*)cargo_data;
+
+    if (!gAgent.canManageEstate())
+    {
+        *accept = ACCEPT_NO;
+        return TRUE;
+    }
+
+    switch(cargo_type)
+    {
+    case DAD_NOTECARD:
+        *accept = ACCEPT_YES_COPY_SINGLE;
+        if (item && drop)
+        {
+            LLSD payload;
+            payload["item_id"] = item->getUUID();
+            LLNotificationsUtil::add("EstateChangeCovenant", LLSD(), payload,
+                                    LLPanelEstateCovenant::confirmChangeCovenantCallback);
+        }
+        break;
+    default:
+        *accept = ACCEPT_NO;
+        break;
+    }
+
+    return TRUE;
+}
+
+// static
 bool LLPanelEstateCovenant::confirmChangeCovenantCallback(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	LLInventoryItem* item = gInventory.getItem(notification["payload"]["item_id"].asUUID());
-	LLPanelEstateCovenant* self = LLFloaterRegionInfo::getPanelCovenant();
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    LLInventoryItem* item = gInventory.getItem(notification["payload"]["item_id"].asUUID());
+    LLPanelEstateCovenant* self = LLFloaterRegionInfo::getPanelCovenant();
 
-	if (!item || !self) return false;
+    if (!item || !self) return false;
 
-	switch(option)
-	{
-	case 0:
-		self->loadInvItem(item);
-		break;
-	default:
-		break;
-	}
-	return false;
+    switch(option)
+    {
+    case 0:
+        self->loadInvItem(item);
+        break;
+    default:
+        break;
+    }
+    return false;
 }
 
 // static
 void LLPanelEstateCovenant::resetCovenantID(void* userdata)
 {
-	LLNotificationsUtil::add("EstateChangeCovenant", LLSD(), LLSD(), confirmResetCovenantCallback);
+    LLNotificationsUtil::add("EstateChangeCovenant", LLSD(), LLSD(), confirmResetCovenantCallback);
 }
 
 // static
 bool LLPanelEstateCovenant::confirmResetCovenantCallback(const LLSD& notification, const LLSD& response)
 {
-	LLPanelEstateCovenant* self = LLFloaterRegionInfo::getPanelCovenant();
-	if (!self) return false;
+    LLPanelEstateCovenant* self = LLFloaterRegionInfo::getPanelCovenant();
+    if (!self) return false;
 
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	switch(option)
-	{
-	case 0:		
-		self->loadInvItem(NULL);
-		break;
-	default:
-		break;
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    switch(option)
+    {
+    case 0:
+        self->loadInvItem(NULL);
+        break;
+    default:
+        break;
+    }
+    return false;
 }
 
 void LLPanelEstateCovenant::loadInvItem(LLInventoryItem *itemp)
 {
-	const BOOL high_priority = TRUE;	
-	if (itemp)
-	{
-		gAssetStorage->getInvItemAsset(gAgent.getRegionHost(),
-									gAgent.getID(),
-									gAgent.getSessionID(),
-									itemp->getPermissions().getOwner(),
-									LLUUID::null,
-									itemp->getUUID(),
-									itemp->getAssetUUID(),
-									itemp->getType(),
+    const BOOL high_priority = TRUE;
+    if (itemp)
+    {
+        gAssetStorage->getInvItemAsset(gAgent.getRegionHost(),
+                                    gAgent.getID(),
+                                    gAgent.getSessionID(),
+                                    itemp->getPermissions().getOwner(),
+                                    LLUUID::null,
+                                    itemp->getUUID(),
+                                    itemp->getAssetUUID(),
+                                    itemp->getType(),
                                     onLoadComplete,
-									(void*)this,
-									high_priority);
-		mAssetStatus = ASSET_LOADING;
-	}
-	else
-	{
-		mAssetStatus = ASSET_LOADED;
-		setCovenantTextEditor(LLTrans::getString("RegionNoCovenant"));
-		sendChangeCovenantID(LLUUID::null);
-	}
+                                    (void*)this,
+                                    high_priority);
+        mAssetStatus = ASSET_LOADING;
+    }
+    else
+    {
+        mAssetStatus = ASSET_LOADED;
+        setCovenantTextEditor(LLTrans::getString("RegionNoCovenant"));
+        sendChangeCovenantID(LLUUID::null);
+    }
 }
 
 // static
 void LLPanelEstateCovenant::onLoadComplete(const LLUUID& asset_uuid,
-									       LLAssetType::EType type,
-									       void* user_data, S32 status, LLExtStat ext_status)
-{
-	LL_INFOS() << "LLPanelEstateCovenant::onLoadComplete()" << LL_ENDL;
-	LLPanelEstateCovenant* panelp = (LLPanelEstateCovenant*)user_data;
-	if( panelp )
-	{
-		if(0 == status)
-		{
-			LLFileSystem file(asset_uuid, type, LLFileSystem::READ);
-
-			S32 file_length = file.getSize();
-
-			std::vector<char> buffer(file_length+1);
-			file.read((U8*)&buffer[0], file_length);
-			// put a EOS at the end
-			buffer[file_length] = 0;
-
-			if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) )
-			{
-				if( !panelp->mEditor->importBuffer( &buffer[0], file_length+1 ) )
-				{
-					LL_WARNS() << "Problem importing estate covenant." << LL_ENDL;
-					LLNotificationsUtil::add("ProblemImportingEstateCovenant");
-				}
-				else
-				{
-					panelp->sendChangeCovenantID(asset_uuid);	
-				}
-			}
-			else
-			{
-				// Version 0 (just text, doesn't include version number)
-				panelp->sendChangeCovenantID(asset_uuid);
-			}
-		}
-		else
-		{
-			if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
-				LL_ERR_FILE_EMPTY == status)
-			{
-				LLNotificationsUtil::add("MissingNotecardAssetID");
-			}
-			else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
-			{
-				LLNotificationsUtil::add("NotAllowedToViewNotecard");
-			}
-			else
-			{
-				LLNotificationsUtil::add("UnableToLoadNotecardAsset");
-			}
-
-			LL_WARNS() << "Problem loading notecard: " << status << LL_ENDL;
-		}
-		panelp->mAssetStatus = ASSET_LOADED;
-		panelp->setCovenantID(asset_uuid);
-	}
+                                           LLAssetType::EType type,
+                                           void* user_data, S32 status, LLExtStat ext_status)
+{
+    LL_INFOS() << "LLPanelEstateCovenant::onLoadComplete()" << LL_ENDL;
+    LLPanelEstateCovenant* panelp = (LLPanelEstateCovenant*)user_data;
+    if( panelp )
+    {
+        if(0 == status)
+        {
+            LLFileSystem file(asset_uuid, type, LLFileSystem::READ);
+
+            S32 file_length = file.getSize();
+
+            std::vector<char> buffer(file_length+1);
+            file.read((U8*)&buffer[0], file_length);
+            // put a EOS at the end
+            buffer[file_length] = 0;
+
+            if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) )
+            {
+                if( !panelp->mEditor->importBuffer( &buffer[0], file_length+1 ) )
+                {
+                    LL_WARNS() << "Problem importing estate covenant." << LL_ENDL;
+                    LLNotificationsUtil::add("ProblemImportingEstateCovenant");
+                }
+                else
+                {
+                    panelp->sendChangeCovenantID(asset_uuid);
+                }
+            }
+            else
+            {
+                // Version 0 (just text, doesn't include version number)
+                panelp->sendChangeCovenantID(asset_uuid);
+            }
+        }
+        else
+        {
+            if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
+                LL_ERR_FILE_EMPTY == status)
+            {
+                LLNotificationsUtil::add("MissingNotecardAssetID");
+            }
+            else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
+            {
+                LLNotificationsUtil::add("NotAllowedToViewNotecard");
+            }
+            else
+            {
+                LLNotificationsUtil::add("UnableToLoadNotecardAsset");
+            }
+
+            LL_WARNS() << "Problem loading notecard: " << status << LL_ENDL;
+        }
+        panelp->mAssetStatus = ASSET_LOADED;
+        panelp->setCovenantID(asset_uuid);
+    }
 }
 
 // key = "estatechangecovenantid"
@@ -2620,97 +2620,97 @@ void LLPanelEstateCovenant::onLoadComplete(const LLUUID& asset_uuid,
 // strings[1] = str(covenant_id)
 void LLPanelEstateCovenant::sendChangeCovenantID(const LLUUID &asset_id)
 {
-	if (asset_id != getCovenantID())
-	{
+    if (asset_id != getCovenantID())
+    {
         setCovenantID(asset_id);
 
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_EstateOwnerMessage);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_EstateOwnerMessage);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
 
-		msg->nextBlockFast(_PREHASH_MethodData);
-		msg->addStringFast(_PREHASH_Method, "estatechangecovenantid");
-		msg->addUUIDFast(_PREHASH_Invoice, LLFloaterRegionInfo::getLastInvoice());
+        msg->nextBlockFast(_PREHASH_MethodData);
+        msg->addStringFast(_PREHASH_Method, "estatechangecovenantid");
+        msg->addUUIDFast(_PREHASH_Invoice, LLFloaterRegionInfo::getLastInvoice());
 
-		msg->nextBlockFast(_PREHASH_ParamList);
-		msg->addStringFast(_PREHASH_Parameter, getCovenantID().asString());
-		gAgent.sendReliableMessage();
-	}
+        msg->nextBlockFast(_PREHASH_ParamList);
+        msg->addStringFast(_PREHASH_Parameter, getCovenantID().asString());
+        gAgent.sendReliableMessage();
+    }
 }
 
-// virtual 
+// virtual
 BOOL LLPanelEstateCovenant::sendUpdate()
 {
-	return TRUE;
+    return TRUE;
 }
 
 std::string LLPanelEstateCovenant::getEstateName() const
 {
-	return mEstateNameText->getText();
+    return mEstateNameText->getText();
 }
 
 void LLPanelEstateCovenant::setEstateName(const std::string& name)
 {
-	mEstateNameText->setText(name);
+    mEstateNameText->setText(name);
 }
 
 // static
 void LLPanelEstateCovenant::updateCovenantText(const std::string& string, const LLUUID& asset_id)
 {
-	LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant();
-	if( panelp )
-	{
-		panelp->mEditor->setText(string);
-		panelp->setCovenantID(asset_id);
-	}
+    LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant();
+    if( panelp )
+    {
+        panelp->mEditor->setText(string);
+        panelp->setCovenantID(asset_id);
+    }
 }
 
 // static
 void LLPanelEstateCovenant::updateEstateName(const std::string& name)
 {
-	LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant();
-	if( panelp )
-	{
-		panelp->mEstateNameText->setText(name);
-	}
+    LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant();
+    if( panelp )
+    {
+        panelp->mEstateNameText->setText(name);
+    }
 }
 
 // static
 void LLPanelEstateCovenant::updateLastModified(const std::string& text)
 {
-	LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant();
-	if( panelp )
-	{
-		panelp->mLastModifiedText->setText(text);
-	}
+    LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant();
+    if( panelp )
+    {
+        panelp->mLastModifiedText->setText(text);
+    }
 }
 
 // static
 void LLPanelEstateCovenant::updateEstateOwnerName(const std::string& name)
 {
-	LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant();
-	if( panelp )
-	{
-		panelp->mEstateOwnerText->setText(name);
-	}
+    LLPanelEstateCovenant* panelp = LLFloaterRegionInfo::getPanelCovenant();
+    if( panelp )
+    {
+        panelp->mEstateOwnerText->setText(name);
+    }
 }
 
 std::string LLPanelEstateCovenant::getOwnerName() const
 {
-	return mEstateOwnerText->getText();
+    return mEstateOwnerText->getText();
 }
 
 void LLPanelEstateCovenant::setOwnerName(const std::string& name)
 {
-	mEstateOwnerText->setText(name);
+    mEstateOwnerText->setText(name);
 }
 
 void LLPanelEstateCovenant::setCovenantTextEditor(const std::string& text)
 {
-	mEditor->setText(text);
+    mEditor->setText(text);
 }
 
 // key = "estateupdateinfo"
@@ -2725,47 +2725,47 @@ void LLPanelEstateCovenant::setCovenantTextEditor(const std::string& text)
 // strings[8] = str(send_to_agent_only)
 // strings[9] = str(abuse_email_addr)
 bool LLDispatchEstateUpdateInfo::operator()(
-		const LLDispatcher* dispatcher,
-		const std::string& key,
-		const LLUUID& invoice,
-		const sparam_t& strings)
+        const LLDispatcher* dispatcher,
+        const std::string& key,
+        const LLUUID& invoice,
+        const sparam_t& strings)
 {
-	LL_DEBUGS() << "Received estate update" << LL_ENDL;
+    LL_DEBUGS() << "Received estate update" << LL_ENDL;
 
-	// Update estate info model.
-	// This will call LLPanelEstateInfo::refreshFromEstate().
-	// *TODO: Move estate message handling stuff to llestateinfomodel.cpp.
-	LLEstateInfoModel::instance().update(strings);
+    // Update estate info model.
+    // This will call LLPanelEstateInfo::refreshFromEstate().
+    // *TODO: Move estate message handling stuff to llestateinfomodel.cpp.
+    LLEstateInfoModel::instance().update(strings);
 
-	return true;
+    return true;
 }
 
 bool LLDispatchSetEstateAccess::operator()(
-	const LLDispatcher* dispatcher,
-	const std::string& key,
-	const LLUUID& invoice,
-	const sparam_t& strings)
+    const LLDispatcher* dispatcher,
+    const std::string& key,
+    const LLUUID& invoice,
+    const sparam_t& strings)
 {
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (panel && panel->getPendingUpdate())
-	{
-		panel->setPendingUpdate(false);
-		panel->updateLists();
-	}
-	return true;
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (panel && panel->getPendingUpdate())
+    {
+        panel->setPendingUpdate(false);
+        panel->updateLists();
+    }
+    return true;
 }
 
 // static
 LLSD LLDispatchSetEstateExperience::getIDs( sparam_t::const_iterator it, sparam_t::const_iterator end, S32 count )
 {
-	LLSD idList = LLSD::emptyArray();
-	LLUUID id;
-	while (count-- > 0 && it < end)
-	{
-		memcpy(id.mData, (*(it++)).data(), UUID_BYTES);
-		idList.append(id);
-	}
-	return idList;
+    LLSD idList = LLSD::emptyArray();
+    LLUUID id;
+    while (count-- > 0 && it < end)
+    {
+        memcpy(id.mData, (*(it++)).data(), UUID_BYTES);
+        idList.append(id);
+    }
+    return idList;
 }
 
 // key = "setexperience"
@@ -2777,91 +2777,91 @@ LLSD LLDispatchSetEstateExperience::getIDs( sparam_t::const_iterator it, sparam_
 // strings[5] = bin(uuid) ...
 // ...
 bool LLDispatchSetEstateExperience::operator()(
-	const LLDispatcher* dispatcher,
-	const std::string& key,
-	const LLUUID& invoice,
-	const sparam_t& strings)
+    const LLDispatcher* dispatcher,
+    const std::string& key,
+    const LLUUID& invoice,
+    const sparam_t& strings)
 {
-	LLPanelRegionExperiences* panel = LLFloaterRegionInfo::getPanelExperiences();
-	if (!panel)
-		return true;
+    LLPanelRegionExperiences* panel = LLFloaterRegionInfo::getPanelExperiences();
+    if (!panel)
+        return true;
 
-	const sparam_t::size_type MIN_SIZE = 5;
-	if (strings.size() < MIN_SIZE)
-		return true;
+    const sparam_t::size_type MIN_SIZE = 5;
+    if (strings.size() < MIN_SIZE)
+        return true;
 
-	// Skip 2 parameters
-	sparam_t::const_iterator it = strings.begin();
-	++it; // U32 estate_id = strtol((*it).c_str(), NULL, 10);
-	++it; // U32 send_to_agent_only = strtoul((*(++it)).c_str(), NULL, 10);
+    // Skip 2 parameters
+    sparam_t::const_iterator it = strings.begin();
+    ++it; // U32 estate_id = strtol((*it).c_str(), NULL, 10);
+    ++it; // U32 send_to_agent_only = strtoul((*(++it)).c_str(), NULL, 10);
 
-	// Read 3 parameters
-	S32 num_blocked = strtol((*(it++)).c_str(), NULL, 10);
-	S32 num_trusted = strtol((*(it++)).c_str(), NULL, 10);
-	S32 num_allowed = strtol((*(it++)).c_str(), NULL, 10);
+    // Read 3 parameters
+    S32 num_blocked = strtol((*(it++)).c_str(), NULL, 10);
+    S32 num_trusted = strtol((*(it++)).c_str(), NULL, 10);
+    S32 num_allowed = strtol((*(it++)).c_str(), NULL, 10);
 
-	LLSD ids = LLSD::emptyMap()
-		.with("blocked", getIDs(it, strings.end(), num_blocked))
-		.with("trusted", getIDs(it + num_blocked, strings.end(), num_trusted))
-		.with("allowed", getIDs(it + num_blocked + num_trusted, strings.end(), num_allowed));
+    LLSD ids = LLSD::emptyMap()
+        .with("blocked", getIDs(it, strings.end(), num_blocked))
+        .with("trusted", getIDs(it + num_blocked, strings.end(), num_trusted))
+        .with("allowed", getIDs(it + num_blocked + num_trusted, strings.end(), num_allowed));
 
-	panel->processResponse(ids);
+    panel->processResponse(ids);
 
-	return true;
+    return true;
 }
 
 BOOL LLPanelRegionExperiences::postBuild()
 {
-	mAllowed = setupList("panel_allowed", ESTATE_EXPERIENCE_ALLOWED_ADD, ESTATE_EXPERIENCE_ALLOWED_REMOVE);
-	mTrusted = setupList("panel_trusted", ESTATE_EXPERIENCE_TRUSTED_ADD, ESTATE_EXPERIENCE_TRUSTED_REMOVE);
-	mBlocked = setupList("panel_blocked", ESTATE_EXPERIENCE_BLOCKED_ADD, ESTATE_EXPERIENCE_BLOCKED_REMOVE);
+    mAllowed = setupList("panel_allowed", ESTATE_EXPERIENCE_ALLOWED_ADD, ESTATE_EXPERIENCE_ALLOWED_REMOVE);
+    mTrusted = setupList("panel_trusted", ESTATE_EXPERIENCE_TRUSTED_ADD, ESTATE_EXPERIENCE_TRUSTED_REMOVE);
+    mBlocked = setupList("panel_blocked", ESTATE_EXPERIENCE_BLOCKED_ADD, ESTATE_EXPERIENCE_BLOCKED_REMOVE);
 
-	getChild<LLLayoutPanel>("trusted_layout_panel")->setVisible(TRUE);
-	getChild<LLTextBox>("experiences_help_text")->setText(getString("estate_caption"));
-	getChild<LLTextBox>("trusted_text_help")->setText(getString("trusted_estate_text"));
-	getChild<LLTextBox>("allowed_text_help")->setText(getString("allowed_estate_text"));
-	getChild<LLTextBox>("blocked_text_help")->setText(getString("blocked_estate_text"));
+    getChild<LLLayoutPanel>("trusted_layout_panel")->setVisible(TRUE);
+    getChild<LLTextBox>("experiences_help_text")->setText(getString("estate_caption"));
+    getChild<LLTextBox>("trusted_text_help")->setText(getString("trusted_estate_text"));
+    getChild<LLTextBox>("allowed_text_help")->setText(getString("allowed_estate_text"));
+    getChild<LLTextBox>("blocked_text_help")->setText(getString("blocked_estate_text"));
 
-	return LLPanelRegionInfo::postBuild();
+    return LLPanelRegionInfo::postBuild();
 }
 
 LLPanelExperienceListEditor* LLPanelRegionExperiences::setupList( const char* control_name, U32 add_id, U32 remove_id )
 {
-	LLPanelExperienceListEditor* child = findChild<LLPanelExperienceListEditor>(control_name);
-	if(child)
-	{
-		child->getChild<LLTextBox>("text_name")->setText(child->getString(control_name));
-		child->setMaxExperienceIDs(ESTATE_MAX_EXPERIENCE_IDS);
-		child->setAddedCallback(  boost::bind(&LLPanelRegionExperiences::itemChanged, this, add_id, _1));
-		child->setRemovedCallback(boost::bind(&LLPanelRegionExperiences::itemChanged, this, remove_id, _1));
-	}
+    LLPanelExperienceListEditor* child = findChild<LLPanelExperienceListEditor>(control_name);
+    if(child)
+    {
+        child->getChild<LLTextBox>("text_name")->setText(child->getString(control_name));
+        child->setMaxExperienceIDs(ESTATE_MAX_EXPERIENCE_IDS);
+        child->setAddedCallback(  boost::bind(&LLPanelRegionExperiences::itemChanged, this, add_id, _1));
+        child->setRemovedCallback(boost::bind(&LLPanelRegionExperiences::itemChanged, this, remove_id, _1));
+    }
 
-	return child;
+    return child;
 }
 
 
 void LLPanelRegionExperiences::processResponse( const LLSD& content )
 {
-	if(content.has("default"))
-	{
-		mDefaultExperience = content["default"].asUUID();
-	}
+    if(content.has("default"))
+    {
+        mDefaultExperience = content["default"].asUUID();
+    }
+
+    mAllowed->setExperienceIds(content["allowed"]);
+    mBlocked->setExperienceIds(content["blocked"]);
 
-	mAllowed->setExperienceIds(content["allowed"]);
-	mBlocked->setExperienceIds(content["blocked"]);
+    LLSD trusted = content["trusted"];
+    if(mDefaultExperience.notNull())
+    {
+        mTrusted->setStickyFunction(boost::bind(LLPanelExperiencePicker::FilterMatching, _1, mDefaultExperience));
+        trusted.append(mDefaultExperience);
+    }
 
-	LLSD trusted = content["trusted"];
-	if(mDefaultExperience.notNull())
-	{
-		mTrusted->setStickyFunction(boost::bind(LLPanelExperiencePicker::FilterMatching, _1, mDefaultExperience));
-		trusted.append(mDefaultExperience);
-	}
+    mTrusted->setExperienceIds(trusted);
 
-	mTrusted->setExperienceIds(trusted);
-	
-	mAllowed->refreshExperienceCounter();
-	mBlocked->refreshExperienceCounter();
-	mTrusted->refreshExperienceCounter();
+    mAllowed->refreshExperienceCounter();
+    mBlocked->refreshExperienceCounter();
+    mTrusted->refreshExperienceCounter();
 
 }
 
@@ -2870,81 +2870,81 @@ void LLPanelRegionExperiences::processResponse( const LLSD& content )
 // static
 bool LLPanelRegionExperiences::experienceCoreConfirm(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	const U32 originalFlags = (U32)notification["payload"]["operation"].asInteger();
-
-	LLViewerRegion* region = gAgent.getRegion();
-	
-	LLSD::array_const_iterator end_it = notification["payload"]["allowed_ids"].endArray();
-
-	for (LLSD::array_const_iterator iter = notification["payload"]["allowed_ids"].beginArray();
-		iter != end_it;
-	     iter++)
-	{
-		U32 flags = originalFlags;
-		if (iter + 1 != end_it)
-			flags |= ESTATE_ACCESS_NO_REPLY;
-
-		const LLUUID id = iter->asUUID();
-		switch(option)
-		{
-			case 0:
-			    // This estate
-			    sendEstateExperienceDelta(flags, id);
-			    break;
-			case 1:
-			{
-				// All estates, either than I own or manage for this owner.  
-				// This will be verified on simulator. JC
-				if (!region) break;
-				if (region->getOwner() == gAgent.getID()
-				    || gAgent.isGodlike())
-				{
-					flags |= ESTATE_ACCESS_APPLY_TO_ALL_ESTATES;
-					sendEstateExperienceDelta(flags, id);
-				}
-				else if (region->isEstateManager())
-				{
-					flags |= ESTATE_ACCESS_APPLY_TO_MANAGED_ESTATES;
-					sendEstateExperienceDelta(flags, id);
-				}
-				break;
-			}
-			case 2:
-			default:
-			    break;
-		}
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    const U32 originalFlags = (U32)notification["payload"]["operation"].asInteger();
+
+    LLViewerRegion* region = gAgent.getRegion();
+
+    LLSD::array_const_iterator end_it = notification["payload"]["allowed_ids"].endArray();
+
+    for (LLSD::array_const_iterator iter = notification["payload"]["allowed_ids"].beginArray();
+        iter != end_it;
+         iter++)
+    {
+        U32 flags = originalFlags;
+        if (iter + 1 != end_it)
+            flags |= ESTATE_ACCESS_NO_REPLY;
+
+        const LLUUID id = iter->asUUID();
+        switch(option)
+        {
+            case 0:
+                // This estate
+                sendEstateExperienceDelta(flags, id);
+                break;
+            case 1:
+            {
+                // All estates, either than I own or manage for this owner.
+                // This will be verified on simulator. JC
+                if (!region) break;
+                if (region->getOwner() == gAgent.getID()
+                    || gAgent.isGodlike())
+                {
+                    flags |= ESTATE_ACCESS_APPLY_TO_ALL_ESTATES;
+                    sendEstateExperienceDelta(flags, id);
+                }
+                else if (region->isEstateManager())
+                {
+                    flags |= ESTATE_ACCESS_APPLY_TO_MANAGED_ESTATES;
+                    sendEstateExperienceDelta(flags, id);
+                }
+                break;
+            }
+            case 2:
+            default:
+                break;
+        }
+    }
+    return false;
 }
 
 
 // Send the actual "estateexperiencedelta" message
 void LLPanelRegionExperiences::sendEstateExperienceDelta(U32 flags, const LLUUID& experience_id)
 {
-	strings_t str(3, std::string());
-	gAgent.getID().toString(str[0]);
-	str[1] = llformat("%u", flags);
-	experience_id.toString(str[2]);
+    strings_t str(3, std::string());
+    gAgent.getID().toString(str[0]);
+    str[1] = llformat("%u", flags);
+    experience_id.toString(str[2]);
 
-	LLPanelRegionExperiences* panel = LLFloaterRegionInfo::getPanelExperiences();
-	if (panel)
-	{
-		panel->sendEstateOwnerMessage(gMessageSystem, "estateexperiencedelta", LLFloaterRegionInfo::getLastInvoice(), str);
-	}
+    LLPanelRegionExperiences* panel = LLFloaterRegionInfo::getPanelExperiences();
+    if (panel)
+    {
+        panel->sendEstateOwnerMessage(gMessageSystem, "estateexperiencedelta", LLFloaterRegionInfo::getLastInvoice(), str);
+    }
 }
 
 
 void LLPanelRegionExperiences::infoCallback(LLHandle<LLPanelRegionExperiences> handle, const LLSD& content)
-{	
-	if(handle.isDead())
-		return;
+{
+    if(handle.isDead())
+        return;
 
-	LLPanelRegionExperiences* floater = handle.get();
-	if (floater)
-	{
-		floater->processResponse(content);
-	}
+    LLPanelRegionExperiences* floater = handle.get();
+    if (floater)
+    {
+        floater->processResponse(content);
+    }
 }
 
 /*static*/
@@ -2957,26 +2957,26 @@ std::string LLPanelRegionExperiences::regionCapabilityQuery(LLViewerRegion* regi
 
 bool LLPanelRegionExperiences::refreshFromRegion(LLViewerRegion* region)
 {
-	BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate());
+    BOOL allow_modify = gAgent.isGodlike() || (region && region->canManageEstate());
 
-	mAllowed->loading();
-	mAllowed->setReadonly(!allow_modify);
-	// remove grid-wide experiences
-	mAllowed->addFilter(boost::bind(LLPanelExperiencePicker::FilterWithProperty, _1, LLExperienceCache::PROPERTY_GRID));
-	// remove default experience
-	mAllowed->addFilter(boost::bind(LLPanelExperiencePicker::FilterMatching, _1, mDefaultExperience));
+    mAllowed->loading();
+    mAllowed->setReadonly(!allow_modify);
+    // remove grid-wide experiences
+    mAllowed->addFilter(boost::bind(LLPanelExperiencePicker::FilterWithProperty, _1, LLExperienceCache::PROPERTY_GRID));
+    // remove default experience
+    mAllowed->addFilter(boost::bind(LLPanelExperiencePicker::FilterMatching, _1, mDefaultExperience));
 
-	mBlocked->loading();
-	mBlocked->setReadonly(!allow_modify);
-	// only grid-wide experiences
-	mBlocked->addFilter(boost::bind(LLPanelExperiencePicker::FilterWithoutProperty, _1, LLExperienceCache::PROPERTY_GRID));
-	// but not privileged ones
-	mBlocked->addFilter(boost::bind(LLPanelExperiencePicker::FilterWithProperty, _1, LLExperienceCache::PROPERTY_PRIVILEGED));
-	// remove default experience
-	mBlocked->addFilter(boost::bind(LLPanelExperiencePicker::FilterMatching, _1, mDefaultExperience));
+    mBlocked->loading();
+    mBlocked->setReadonly(!allow_modify);
+    // only grid-wide experiences
+    mBlocked->addFilter(boost::bind(LLPanelExperiencePicker::FilterWithoutProperty, _1, LLExperienceCache::PROPERTY_GRID));
+    // but not privileged ones
+    mBlocked->addFilter(boost::bind(LLPanelExperiencePicker::FilterWithProperty, _1, LLExperienceCache::PROPERTY_PRIVILEGED));
+    // remove default experience
+    mBlocked->addFilter(boost::bind(LLPanelExperiencePicker::FilterMatching, _1, mDefaultExperience));
 
-	mTrusted->loading();
-	mTrusted->setReadonly(!allow_modify);
+    mTrusted->loading();
+    mTrusted->setReadonly(!allow_modify);
 
     LLExperienceCache::instance().getRegionExperiences(boost::bind(&LLPanelRegionExperiences::regionCapabilityQuery, region, _1),
         boost::bind(&LLPanelRegionExperiences::infoCallback, getDerivedHandle<LLPanelRegionExperiences>(), _1));
@@ -2986,87 +2986,87 @@ bool LLPanelRegionExperiences::refreshFromRegion(LLViewerRegion* region)
 
 LLSD LLPanelRegionExperiences::addIds(LLPanelExperienceListEditor* panel)
 {
-	LLSD ids;
-	const uuid_list_t& id_list = panel->getExperienceIds();
-	for(uuid_list_t::const_iterator it = id_list.begin(); it != id_list.end(); ++it)
-	{
-		ids.append(*it);
-	}
-	return ids;
+    LLSD ids;
+    const uuid_list_t& id_list = panel->getExperienceIds();
+    for(uuid_list_t::const_iterator it = id_list.begin(); it != id_list.end(); ++it)
+    {
+        ids.append(*it);
+    }
+    return ids;
 }
 
 
 BOOL LLPanelRegionExperiences::sendUpdate()
 {
-	LLViewerRegion* region = gAgent.getRegion();
+    LLViewerRegion* region = gAgent.getRegion();
 
     LLSD content;
 
-	content["allowed"]=addIds(mAllowed);
-	content["blocked"]=addIds(mBlocked);
-	content["trusted"]=addIds(mTrusted);
+    content["allowed"]=addIds(mAllowed);
+    content["blocked"]=addIds(mBlocked);
+    content["trusted"]=addIds(mTrusted);
 
     LLExperienceCache::instance().setRegionExperiences(boost::bind(&LLPanelRegionExperiences::regionCapabilityQuery, region, _1),
         content, boost::bind(&LLPanelRegionExperiences::infoCallback, getDerivedHandle<LLPanelRegionExperiences>(), _1));
 
-	return TRUE;
+    return TRUE;
 }
 
 void LLPanelRegionExperiences::itemChanged( U32 event_type, const LLUUID& id )
 {
-	std::string dialog_name;
-	switch (event_type)
-	{
-		case ESTATE_EXPERIENCE_ALLOWED_ADD:
-			dialog_name = "EstateAllowedExperienceAdd";
-			break;
+    std::string dialog_name;
+    switch (event_type)
+    {
+        case ESTATE_EXPERIENCE_ALLOWED_ADD:
+            dialog_name = "EstateAllowedExperienceAdd";
+            break;
 
-		case ESTATE_EXPERIENCE_ALLOWED_REMOVE:
-			dialog_name = "EstateAllowedExperienceRemove";
-			break;
+        case ESTATE_EXPERIENCE_ALLOWED_REMOVE:
+            dialog_name = "EstateAllowedExperienceRemove";
+            break;
 
-		case ESTATE_EXPERIENCE_TRUSTED_ADD:
-			dialog_name = "EstateTrustedExperienceAdd";
-			break;
+        case ESTATE_EXPERIENCE_TRUSTED_ADD:
+            dialog_name = "EstateTrustedExperienceAdd";
+            break;
 
-		case ESTATE_EXPERIENCE_TRUSTED_REMOVE:
-			dialog_name = "EstateTrustedExperienceRemove";
-			break;
+        case ESTATE_EXPERIENCE_TRUSTED_REMOVE:
+            dialog_name = "EstateTrustedExperienceRemove";
+            break;
 
-		case ESTATE_EXPERIENCE_BLOCKED_ADD:
-			dialog_name = "EstateBlockedExperienceAdd";
-			break;
+        case ESTATE_EXPERIENCE_BLOCKED_ADD:
+            dialog_name = "EstateBlockedExperienceAdd";
+            break;
 
-		case ESTATE_EXPERIENCE_BLOCKED_REMOVE:
-			dialog_name = "EstateBlockedExperienceRemove";
-			break;
+        case ESTATE_EXPERIENCE_BLOCKED_REMOVE:
+            dialog_name = "EstateBlockedExperienceRemove";
+            break;
 
-		default:
-			return;
-	}
+        default:
+            return;
+    }
 
-	LLSD payload;
-	payload["operation"] = (S32)event_type;
-	payload["dialog_name"] = dialog_name;
-	payload["allowed_ids"].append(id);
+    LLSD payload;
+    payload["operation"] = (S32)event_type;
+    payload["dialog_name"] = dialog_name;
+    payload["allowed_ids"].append(id);
 
-	LLSD args;
-	args["ALL_ESTATES"] = all_estates_text();
+    LLSD args;
+    args["ALL_ESTATES"] = all_estates_text();
 
-	LLNotification::Params params(dialog_name);
-	params.payload(payload)
-		.substitutions(args)
-		.functor.function(LLPanelRegionExperiences::experienceCoreConfirm);
-	if (LLPanelEstateInfo::isLindenEstate())
-	{
-		LLNotifications::instance().forceResponse(params, 0);
-	}
-	else
-	{
-		LLNotifications::instance().add(params);
-	}
+    LLNotification::Params params(dialog_name);
+    params.payload(payload)
+        .substitutions(args)
+        .functor.function(LLPanelRegionExperiences::experienceCoreConfirm);
+    if (LLPanelEstateInfo::isLindenEstate())
+    {
+        LLNotifications::instance().forceResponse(params, 0);
+    }
+    else
+    {
+        LLNotifications::instance().add(params);
+    }
 
-	onChangeAnything();
+    onChangeAnything();
 }
 
 
@@ -3076,583 +3076,583 @@ LLPanelEstateAccess::LLPanelEstateAccess()
 
 BOOL LLPanelEstateAccess::postBuild()
 {
-	getChild<LLUICtrl>("allowed_avatar_name_list")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeChildCtrl, this, _1));
-	LLNameListCtrl *avatar_name_list = getChild<LLNameListCtrl>("allowed_avatar_name_list");
-	if (avatar_name_list)
-	{
-		avatar_name_list->setCommitOnSelectionChange(TRUE); 
-		avatar_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS);
-	}
-
-	getChild<LLUICtrl>("allowed_search_input")->setCommitCallback(boost::bind(&LLPanelEstateAccess::onAllowedSearchEdit, this, _2));
-	childSetAction("add_allowed_avatar_btn", boost::bind(&LLPanelEstateAccess::onClickAddAllowedAgent, this));
-	childSetAction("remove_allowed_avatar_btn", boost::bind(&LLPanelEstateAccess::onClickRemoveAllowedAgent, this));
-	childSetAction("copy_allowed_list_btn", boost::bind(&LLPanelEstateAccess::onClickCopyAllowedList, this));
-
-	getChild<LLUICtrl>("allowed_group_name_list")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeChildCtrl, this, _1));
-	LLNameListCtrl* group_name_list = getChild<LLNameListCtrl>("allowed_group_name_list");
-	if (group_name_list)
-	{
-		group_name_list->setCommitOnSelectionChange(TRUE);
-		group_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS);
-	}
-
-	getChild<LLUICtrl>("allowed_group_search_input")->setCommitCallback(boost::bind(&LLPanelEstateAccess::onAllowedGroupsSearchEdit, this, _2));
-	getChild<LLUICtrl>("add_allowed_group_btn")->setCommitCallback(boost::bind(&LLPanelEstateAccess::onClickAddAllowedGroup, this));
-	childSetAction("remove_allowed_group_btn", boost::bind(&LLPanelEstateAccess::onClickRemoveAllowedGroup, this));
-	childSetAction("copy_allowed_group_list_btn", boost::bind(&LLPanelEstateAccess::onClickCopyAllowedGroupList, this));
-
-	getChild<LLUICtrl>("banned_avatar_name_list")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeChildCtrl, this, _1));
-	LLNameListCtrl* banned_name_list = getChild<LLNameListCtrl>("banned_avatar_name_list");
-	if (banned_name_list)
-	{
-		banned_name_list->setCommitOnSelectionChange(TRUE);
-		banned_name_list->setMaxItemCount(ESTATE_MAX_BANNED_IDS);
-	}
-
-	getChild<LLUICtrl>("banned_search_input")->setCommitCallback(boost::bind(&LLPanelEstateAccess::onBannedSearchEdit, this, _2));
-	childSetAction("add_banned_avatar_btn", boost::bind(&LLPanelEstateAccess::onClickAddBannedAgent, this));
-	childSetAction("remove_banned_avatar_btn", boost::bind(&LLPanelEstateAccess::onClickRemoveBannedAgent, this));
-	childSetAction("copy_banned_list_btn", boost::bind(&LLPanelEstateAccess::onClickCopyBannedList, this));
-
-	getChild<LLUICtrl>("estate_manager_name_list")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeChildCtrl, this, _1));
-	LLNameListCtrl* manager_name_list = getChild<LLNameListCtrl>("estate_manager_name_list");
-	if (manager_name_list)
-	{
-		manager_name_list->setCommitOnSelectionChange(TRUE);
-		manager_name_list->setMaxItemCount(ESTATE_MAX_MANAGERS * 4);	// Allow extras for dupe issue
-	}
-
-	childSetAction("add_estate_manager_btn", boost::bind(&LLPanelEstateAccess::onClickAddEstateManager, this));
-	childSetAction("remove_estate_manager_btn", boost::bind(&LLPanelEstateAccess::onClickRemoveEstateManager, this));
-
-	return TRUE;
-}
+    getChild<LLUICtrl>("allowed_avatar_name_list")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeChildCtrl, this, _1));
+    LLNameListCtrl *avatar_name_list = getChild<LLNameListCtrl>("allowed_avatar_name_list");
+    if (avatar_name_list)
+    {
+        avatar_name_list->setCommitOnSelectionChange(TRUE);
+        avatar_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS);
+    }
 
-void LLPanelEstateAccess::updateControls(LLViewerRegion* region)
-{
-	BOOL god = gAgent.isGodlike();
-	BOOL owner = (region && (region->getOwner() == gAgent.getID()));
-	BOOL manager = (region && region->isEstateManager());
-	BOOL enable_cotrols = god || owner || manager;	
-	setCtrlsEnabled(enable_cotrols);
-	
-	BOOL has_allowed_avatar = getChild<LLNameListCtrl>("allowed_avatar_name_list")->getFirstSelected() ? TRUE : FALSE;
-	BOOL has_allowed_group = getChild<LLNameListCtrl>("allowed_group_name_list")->getFirstSelected() ? TRUE : FALSE;
-	BOOL has_banned_agent = getChild<LLNameListCtrl>("banned_avatar_name_list")->getFirstSelected() ? TRUE : FALSE;
-	BOOL has_estate_manager = getChild<LLNameListCtrl>("estate_manager_name_list")->getFirstSelected() ? TRUE : FALSE;
-
-	getChildView("add_allowed_avatar_btn")->setEnabled(enable_cotrols);
-	getChildView("remove_allowed_avatar_btn")->setEnabled(has_allowed_avatar && enable_cotrols);
-	getChildView("allowed_avatar_name_list")->setEnabled(enable_cotrols);
-
-	getChildView("add_allowed_group_btn")->setEnabled(enable_cotrols);
-	getChildView("remove_allowed_group_btn")->setEnabled(has_allowed_group && enable_cotrols);
-	getChildView("allowed_group_name_list")->setEnabled(enable_cotrols);
-
-	// Can't ban people from mainland, orientation islands, etc. because this
-	// creates much network traffic and server load.
-	// Disable their accounts in CSR tool instead.
-	bool linden_estate = LLPanelEstateInfo::isLindenEstate();
-	bool enable_ban = enable_cotrols && !linden_estate;
-	getChildView("add_banned_avatar_btn")->setEnabled(enable_ban);
-	getChildView("remove_banned_avatar_btn")->setEnabled(has_banned_agent && enable_ban);
-	getChildView("banned_avatar_name_list")->setEnabled(enable_cotrols);
-
-	// estate managers can't add estate managers
-	getChildView("add_estate_manager_btn")->setEnabled(god || owner);
-	getChildView("remove_estate_manager_btn")->setEnabled(has_estate_manager && (god || owner));
-	getChildView("estate_manager_name_list")->setEnabled(god || owner);
-
-	if (enable_cotrols != mCtrlsEnabled)
-	{
-		mCtrlsEnabled = enable_cotrols;
-		updateLists(); // update the lists on the agent's access level change
-	}
-}
+    getChild<LLUICtrl>("allowed_search_input")->setCommitCallback(boost::bind(&LLPanelEstateAccess::onAllowedSearchEdit, this, _2));
+    childSetAction("add_allowed_avatar_btn", boost::bind(&LLPanelEstateAccess::onClickAddAllowedAgent, this));
+    childSetAction("remove_allowed_avatar_btn", boost::bind(&LLPanelEstateAccess::onClickRemoveAllowedAgent, this));
+    childSetAction("copy_allowed_list_btn", boost::bind(&LLPanelEstateAccess::onClickCopyAllowedList, this));
 
-//---------------------------------------------------------------------------
-// Add/Remove estate access button callbacks
-//---------------------------------------------------------------------------
-void LLPanelEstateAccess::onClickAddAllowedAgent()
-{
-	LLCtrlListInterface *list = childGetListInterface("allowed_avatar_name_list");
-	if (!list) return;
-	if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS)
-	{
-		//args
+    getChild<LLUICtrl>("allowed_group_name_list")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeChildCtrl, this, _1));
+    LLNameListCtrl* group_name_list = getChild<LLNameListCtrl>("allowed_group_name_list");
+    if (group_name_list)
+    {
+        group_name_list->setCommitOnSelectionChange(TRUE);
+        group_name_list->setMaxItemCount(ESTATE_MAX_ACCESS_IDS);
+    }
 
-		LLSD args;
-		args["MAX_AGENTS"] = llformat("%d", ESTATE_MAX_ACCESS_IDS);
-		LLNotificationsUtil::add("MaxAllowedAgentOnRegion", args);
-		return;
-	}
-	accessAddCore(ESTATE_ACCESS_ALLOWED_AGENT_ADD, "EstateAllowedAgentAdd");
-}
+    getChild<LLUICtrl>("allowed_group_search_input")->setCommitCallback(boost::bind(&LLPanelEstateAccess::onAllowedGroupsSearchEdit, this, _2));
+    getChild<LLUICtrl>("add_allowed_group_btn")->setCommitCallback(boost::bind(&LLPanelEstateAccess::onClickAddAllowedGroup, this));
+    childSetAction("remove_allowed_group_btn", boost::bind(&LLPanelEstateAccess::onClickRemoveAllowedGroup, this));
+    childSetAction("copy_allowed_group_list_btn", boost::bind(&LLPanelEstateAccess::onClickCopyAllowedGroupList, this));
 
-void LLPanelEstateAccess::onClickRemoveAllowedAgent()
+    getChild<LLUICtrl>("banned_avatar_name_list")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeChildCtrl, this, _1));
+    LLNameListCtrl* banned_name_list = getChild<LLNameListCtrl>("banned_avatar_name_list");
+    if (banned_name_list)
+    {
+        banned_name_list->setCommitOnSelectionChange(TRUE);
+        banned_name_list->setMaxItemCount(ESTATE_MAX_BANNED_IDS);
+    }
+
+    getChild<LLUICtrl>("banned_search_input")->setCommitCallback(boost::bind(&LLPanelEstateAccess::onBannedSearchEdit, this, _2));
+    childSetAction("add_banned_avatar_btn", boost::bind(&LLPanelEstateAccess::onClickAddBannedAgent, this));
+    childSetAction("remove_banned_avatar_btn", boost::bind(&LLPanelEstateAccess::onClickRemoveBannedAgent, this));
+    childSetAction("copy_banned_list_btn", boost::bind(&LLPanelEstateAccess::onClickCopyBannedList, this));
+
+    getChild<LLUICtrl>("estate_manager_name_list")->setCommitCallback(boost::bind(&LLPanelEstateInfo::onChangeChildCtrl, this, _1));
+    LLNameListCtrl* manager_name_list = getChild<LLNameListCtrl>("estate_manager_name_list");
+    if (manager_name_list)
+    {
+        manager_name_list->setCommitOnSelectionChange(TRUE);
+        manager_name_list->setMaxItemCount(ESTATE_MAX_MANAGERS * 4);    // Allow extras for dupe issue
+    }
+
+    childSetAction("add_estate_manager_btn", boost::bind(&LLPanelEstateAccess::onClickAddEstateManager, this));
+    childSetAction("remove_estate_manager_btn", boost::bind(&LLPanelEstateAccess::onClickRemoveEstateManager, this));
+
+    return TRUE;
+}
+
+void LLPanelEstateAccess::updateControls(LLViewerRegion* region)
+{
+    BOOL god = gAgent.isGodlike();
+    BOOL owner = (region && (region->getOwner() == gAgent.getID()));
+    BOOL manager = (region && region->isEstateManager());
+    BOOL enable_cotrols = god || owner || manager;
+    setCtrlsEnabled(enable_cotrols);
+
+    BOOL has_allowed_avatar = getChild<LLNameListCtrl>("allowed_avatar_name_list")->getFirstSelected() ? TRUE : FALSE;
+    BOOL has_allowed_group = getChild<LLNameListCtrl>("allowed_group_name_list")->getFirstSelected() ? TRUE : FALSE;
+    BOOL has_banned_agent = getChild<LLNameListCtrl>("banned_avatar_name_list")->getFirstSelected() ? TRUE : FALSE;
+    BOOL has_estate_manager = getChild<LLNameListCtrl>("estate_manager_name_list")->getFirstSelected() ? TRUE : FALSE;
+
+    getChildView("add_allowed_avatar_btn")->setEnabled(enable_cotrols);
+    getChildView("remove_allowed_avatar_btn")->setEnabled(has_allowed_avatar && enable_cotrols);
+    getChildView("allowed_avatar_name_list")->setEnabled(enable_cotrols);
+
+    getChildView("add_allowed_group_btn")->setEnabled(enable_cotrols);
+    getChildView("remove_allowed_group_btn")->setEnabled(has_allowed_group && enable_cotrols);
+    getChildView("allowed_group_name_list")->setEnabled(enable_cotrols);
+
+    // Can't ban people from mainland, orientation islands, etc. because this
+    // creates much network traffic and server load.
+    // Disable their accounts in CSR tool instead.
+    bool linden_estate = LLPanelEstateInfo::isLindenEstate();
+    bool enable_ban = enable_cotrols && !linden_estate;
+    getChildView("add_banned_avatar_btn")->setEnabled(enable_ban);
+    getChildView("remove_banned_avatar_btn")->setEnabled(has_banned_agent && enable_ban);
+    getChildView("banned_avatar_name_list")->setEnabled(enable_cotrols);
+
+    // estate managers can't add estate managers
+    getChildView("add_estate_manager_btn")->setEnabled(god || owner);
+    getChildView("remove_estate_manager_btn")->setEnabled(has_estate_manager && (god || owner));
+    getChildView("estate_manager_name_list")->setEnabled(god || owner);
+
+    if (enable_cotrols != mCtrlsEnabled)
+    {
+        mCtrlsEnabled = enable_cotrols;
+        updateLists(); // update the lists on the agent's access level change
+    }
+}
+
+//---------------------------------------------------------------------------
+// Add/Remove estate access button callbacks
+//---------------------------------------------------------------------------
+void LLPanelEstateAccess::onClickAddAllowedAgent()
+{
+    LLCtrlListInterface *list = childGetListInterface("allowed_avatar_name_list");
+    if (!list) return;
+    if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS)
+    {
+        //args
+
+        LLSD args;
+        args["MAX_AGENTS"] = llformat("%d", ESTATE_MAX_ACCESS_IDS);
+        LLNotificationsUtil::add("MaxAllowedAgentOnRegion", args);
+        return;
+    }
+    accessAddCore(ESTATE_ACCESS_ALLOWED_AGENT_ADD, "EstateAllowedAgentAdd");
+}
+
+void LLPanelEstateAccess::onClickRemoveAllowedAgent()
 {
-	accessRemoveCore(ESTATE_ACCESS_ALLOWED_AGENT_REMOVE, "EstateAllowedAgentRemove", "allowed_avatar_name_list");
+    accessRemoveCore(ESTATE_ACCESS_ALLOWED_AGENT_REMOVE, "EstateAllowedAgentRemove", "allowed_avatar_name_list");
 }
 
 void LLPanelEstateAccess::onClickAddAllowedGroup()
 {
-	LLCtrlListInterface *list = childGetListInterface("allowed_group_name_list");
-	if (!list) return;
-	if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS)
-	{
-		LLSD args;
-		args["MAX_GROUPS"] = llformat("%d", ESTATE_MAX_ACCESS_IDS);
-		LLNotificationsUtil::add("MaxAllowedGroupsOnRegion", args);
-		return;
-	}
-
-	LLNotification::Params params("ChangeLindenAccess");
-	params.functor.function(boost::bind(&LLPanelEstateAccess::addAllowedGroup, this, _1, _2));
-	if (LLPanelEstateInfo::isLindenEstate())
-	{
-		LLNotifications::instance().add(params);
-	}
-	else
-	{
-		LLNotifications::instance().forceResponse(params, 0);
-	}
+    LLCtrlListInterface *list = childGetListInterface("allowed_group_name_list");
+    if (!list) return;
+    if (list->getItemCount() >= ESTATE_MAX_ACCESS_IDS)
+    {
+        LLSD args;
+        args["MAX_GROUPS"] = llformat("%d", ESTATE_MAX_ACCESS_IDS);
+        LLNotificationsUtil::add("MaxAllowedGroupsOnRegion", args);
+        return;
+    }
+
+    LLNotification::Params params("ChangeLindenAccess");
+    params.functor.function(boost::bind(&LLPanelEstateAccess::addAllowedGroup, this, _1, _2));
+    if (LLPanelEstateInfo::isLindenEstate())
+    {
+        LLNotifications::instance().add(params);
+    }
+    else
+    {
+        LLNotifications::instance().forceResponse(params, 0);
+    }
 }
 
 bool LLPanelEstateAccess::addAllowedGroup(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0) return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option != 0) return false;
 
-	LLFloater* parent_floater = gFloaterView->getParentFloater(this);
+    LLFloater* parent_floater = gFloaterView->getParentFloater(this);
 
-	LLFloaterGroupPicker* widget = LLFloaterReg::showTypedInstance<LLFloaterGroupPicker>("group_picker", LLSD(gAgent.getID()));
-	if (widget)
-	{
-		widget->removeNoneOption();
-		widget->setSelectGroupCallback(boost::bind(&LLPanelEstateAccess::addAllowedGroup2, this, _1));
-		if (parent_floater)
-		{
-			LLRect new_rect = gFloaterView->findNeighboringPosition(parent_floater, widget);
-			widget->setOrigin(new_rect.mLeft, new_rect.mBottom);
-			parent_floater->addDependentFloater(widget);
-		}
-	}
+    LLFloaterGroupPicker* widget = LLFloaterReg::showTypedInstance<LLFloaterGroupPicker>("group_picker", LLSD(gAgent.getID()));
+    if (widget)
+    {
+        widget->removeNoneOption();
+        widget->setSelectGroupCallback(boost::bind(&LLPanelEstateAccess::addAllowedGroup2, this, _1));
+        if (parent_floater)
+        {
+            LLRect new_rect = gFloaterView->findNeighboringPosition(parent_floater, widget);
+            widget->setOrigin(new_rect.mLeft, new_rect.mBottom);
+            parent_floater->addDependentFloater(widget);
+        }
+    }
 
-	return false;
+    return false;
 }
 
 void LLPanelEstateAccess::onClickRemoveAllowedGroup()
 {
-	accessRemoveCore(ESTATE_ACCESS_ALLOWED_GROUP_REMOVE, "EstateAllowedGroupRemove", "allowed_group_name_list");
+    accessRemoveCore(ESTATE_ACCESS_ALLOWED_GROUP_REMOVE, "EstateAllowedGroupRemove", "allowed_group_name_list");
 }
 
 void LLPanelEstateAccess::onClickAddBannedAgent()
 {
-	LLCtrlListInterface *list = childGetListInterface("banned_avatar_name_list");
-	if (!list) return;
-	if (list->getItemCount() >= ESTATE_MAX_BANNED_IDS)
-	{
-		LLSD args;
-		args["MAX_BANNED"] = llformat("%d", ESTATE_MAX_BANNED_IDS);
-		LLNotificationsUtil::add("MaxBannedAgentsOnRegion", args);
-		return;
-	}
-	accessAddCore(ESTATE_ACCESS_BANNED_AGENT_ADD, "EstateBannedAgentAdd");
+    LLCtrlListInterface *list = childGetListInterface("banned_avatar_name_list");
+    if (!list) return;
+    if (list->getItemCount() >= ESTATE_MAX_BANNED_IDS)
+    {
+        LLSD args;
+        args["MAX_BANNED"] = llformat("%d", ESTATE_MAX_BANNED_IDS);
+        LLNotificationsUtil::add("MaxBannedAgentsOnRegion", args);
+        return;
+    }
+    accessAddCore(ESTATE_ACCESS_BANNED_AGENT_ADD, "EstateBannedAgentAdd");
 }
 
 void LLPanelEstateAccess::onClickRemoveBannedAgent()
 {
-	accessRemoveCore(ESTATE_ACCESS_BANNED_AGENT_REMOVE, "EstateBannedAgentRemove", "banned_avatar_name_list");
+    accessRemoveCore(ESTATE_ACCESS_BANNED_AGENT_REMOVE, "EstateBannedAgentRemove", "banned_avatar_name_list");
 }
 
 void LLPanelEstateAccess::onClickCopyAllowedList()
 {
-	copyListToClipboard("allowed_avatar_name_list");
+    copyListToClipboard("allowed_avatar_name_list");
 }
 
 void LLPanelEstateAccess::onClickCopyAllowedGroupList()
 {
-	copyListToClipboard("allowed_group_name_list");
+    copyListToClipboard("allowed_group_name_list");
 }
 
 void LLPanelEstateAccess::onClickCopyBannedList()
 {
-	copyListToClipboard("banned_avatar_name_list");
+    copyListToClipboard("banned_avatar_name_list");
 }
 
 // static
 void LLPanelEstateAccess::onClickAddEstateManager()
 {
-	LLCtrlListInterface *list = childGetListInterface("estate_manager_name_list");
-	if (!list) return;
-	if (list->getItemCount() >= ESTATE_MAX_MANAGERS)
-	{	// Tell user they can't add more managers
-		LLSD args;
-		args["MAX_MANAGER"] = llformat("%d", ESTATE_MAX_MANAGERS);
-		LLNotificationsUtil::add("MaxManagersOnRegion", args);
-	}
-	else
-	{	// Go pick managers to add
-		accessAddCore(ESTATE_ACCESS_MANAGER_ADD, "EstateManagerAdd");
-	}
+    LLCtrlListInterface *list = childGetListInterface("estate_manager_name_list");
+    if (!list) return;
+    if (list->getItemCount() >= ESTATE_MAX_MANAGERS)
+    {   // Tell user they can't add more managers
+        LLSD args;
+        args["MAX_MANAGER"] = llformat("%d", ESTATE_MAX_MANAGERS);
+        LLNotificationsUtil::add("MaxManagersOnRegion", args);
+    }
+    else
+    {   // Go pick managers to add
+        accessAddCore(ESTATE_ACCESS_MANAGER_ADD, "EstateManagerAdd");
+    }
 }
 
 // static
 void LLPanelEstateAccess::onClickRemoveEstateManager()
 {
-	accessRemoveCore(ESTATE_ACCESS_MANAGER_REMOVE, "EstateManagerRemove", "estate_manager_name_list");
+    accessRemoveCore(ESTATE_ACCESS_MANAGER_REMOVE, "EstateManagerRemove", "estate_manager_name_list");
 }
 
 
 // Special case callback for groups, since it has different callback format than names
 void LLPanelEstateAccess::addAllowedGroup2(LLUUID id)
 {
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (panel)
-	{
-		LLNameListCtrl* group_list = panel->getChild<LLNameListCtrl>("allowed_group_name_list");
-		LLScrollListItem* item = group_list->getNameItemByAgentId(id);
-		if (item)
-		{
-			LLSD args;
-			args["GROUP"] = item->getColumn(0)->getValue().asString();
-			LLNotificationsUtil::add("GroupIsAlreadyInList", args);
-			return;
-		}
-	}
-	
-	LLSD payload;
-	payload["operation"] = (S32)ESTATE_ACCESS_ALLOWED_GROUP_ADD;
-	payload["dialog_name"] = "EstateAllowedGroupAdd";
-	payload["allowed_ids"].append(id);
-
-	LLSD args;
-	args["ALL_ESTATES"] = all_estates_text();
-
-	LLNotification::Params params("EstateAllowedGroupAdd");
-	params.payload(payload)
-		.substitutions(args)
-		.functor.function(accessCoreConfirm);
-	if (LLPanelEstateInfo::isLindenEstate())
-	{
-		LLNotifications::instance().forceResponse(params, 0);
-	}
-	else
-	{
-		LLNotifications::instance().add(params);
-	}
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (panel)
+    {
+        LLNameListCtrl* group_list = panel->getChild<LLNameListCtrl>("allowed_group_name_list");
+        LLScrollListItem* item = group_list->getNameItemByAgentId(id);
+        if (item)
+        {
+            LLSD args;
+            args["GROUP"] = item->getColumn(0)->getValue().asString();
+            LLNotificationsUtil::add("GroupIsAlreadyInList", args);
+            return;
+        }
+    }
+
+    LLSD payload;
+    payload["operation"] = (S32)ESTATE_ACCESS_ALLOWED_GROUP_ADD;
+    payload["dialog_name"] = "EstateAllowedGroupAdd";
+    payload["allowed_ids"].append(id);
+
+    LLSD args;
+    args["ALL_ESTATES"] = all_estates_text();
+
+    LLNotification::Params params("EstateAllowedGroupAdd");
+    params.payload(payload)
+        .substitutions(args)
+        .functor.function(accessCoreConfirm);
+    if (LLPanelEstateInfo::isLindenEstate())
+    {
+        LLNotifications::instance().forceResponse(params, 0);
+    }
+    else
+    {
+        LLNotifications::instance().add(params);
+    }
 }
 
 // static
 void LLPanelEstateAccess::accessAddCore(U32 operation_flag, const std::string& dialog_name)
 {
-	LLSD payload;
-	payload["operation"] = (S32)operation_flag;
-	payload["dialog_name"] = dialog_name;
-	// agent id filled in after avatar picker
+    LLSD payload;
+    payload["operation"] = (S32)operation_flag;
+    payload["dialog_name"] = dialog_name;
+    // agent id filled in after avatar picker
 
-	LLNotification::Params params("ChangeLindenAccess");
-	params.payload(payload)
-		.functor.function(accessAddCore2);
+    LLNotification::Params params("ChangeLindenAccess");
+    params.payload(payload)
+        .functor.function(accessAddCore2);
 
-	if (LLPanelEstateInfo::isLindenEstate())
-	{
-		LLNotifications::instance().add(params);
-	}
-	else
-	{
-		// same as clicking "OK"
-		LLNotifications::instance().forceResponse(params, 0);
-	}
+    if (LLPanelEstateInfo::isLindenEstate())
+    {
+        LLNotifications::instance().add(params);
+    }
+    else
+    {
+        // same as clicking "OK"
+        LLNotifications::instance().forceResponse(params, 0);
+    }
 }
 
 // static
 bool LLPanelEstateAccess::accessAddCore2(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0)
-	{
-		// abort change
-		return false;
-	}
-
-	LLEstateAccessChangeInfo* change_info = new LLEstateAccessChangeInfo(notification["payload"]);
-	//Get parent floater name
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	LLFloater* parent_floater = panel ? gFloaterView->getParentFloater(panel) : NULL;
-	const std::string& parent_floater_name = parent_floater ? parent_floater->getName() : "";
-
-	//Determine the button that triggered opening of the avatar picker 
-	//(so that a shadow frustum from the button to the avatar picker can be created)
-	LLView * button = NULL;
-	switch (change_info->mOperationFlag)
-	{
-	case ESTATE_ACCESS_ALLOWED_AGENT_ADD:
-		button = panel->findChild<LLButton>("add_allowed_avatar_btn");
-		break;
-
-	case ESTATE_ACCESS_BANNED_AGENT_ADD:
-		button = panel->findChild<LLButton>("add_banned_avatar_btn");
-		break;
-
-	case ESTATE_ACCESS_MANAGER_ADD:
-		button = panel->findChild<LLButton>("add_estate_manager_btn");
-		break;
-	}
-
-	// avatar picker yes multi-select, yes close-on-select
-	LLFloater* child_floater = LLFloaterAvatarPicker::show(boost::bind(&LLPanelEstateAccess::accessAddCore3, _1, _2, (void*)change_info),
-		TRUE, TRUE, FALSE, parent_floater_name, button);
-
-	//Allows the closed parent floater to close the child floater (avatar picker)
-	if (child_floater)
-	{
-		parent_floater->addDependentFloater(child_floater);
-	}
-
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option != 0)
+    {
+        // abort change
+        return false;
+    }
+
+    LLEstateAccessChangeInfo* change_info = new LLEstateAccessChangeInfo(notification["payload"]);
+    //Get parent floater name
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    LLFloater* parent_floater = panel ? gFloaterView->getParentFloater(panel) : NULL;
+    const std::string& parent_floater_name = parent_floater ? parent_floater->getName() : "";
+
+    //Determine the button that triggered opening of the avatar picker
+    //(so that a shadow frustum from the button to the avatar picker can be created)
+    LLView * button = NULL;
+    switch (change_info->mOperationFlag)
+    {
+    case ESTATE_ACCESS_ALLOWED_AGENT_ADD:
+        button = panel->findChild<LLButton>("add_allowed_avatar_btn");
+        break;
+
+    case ESTATE_ACCESS_BANNED_AGENT_ADD:
+        button = panel->findChild<LLButton>("add_banned_avatar_btn");
+        break;
+
+    case ESTATE_ACCESS_MANAGER_ADD:
+        button = panel->findChild<LLButton>("add_estate_manager_btn");
+        break;
+    }
+
+    // avatar picker yes multi-select, yes close-on-select
+    LLFloater* child_floater = LLFloaterAvatarPicker::show(boost::bind(&LLPanelEstateAccess::accessAddCore3, _1, _2, (void*)change_info),
+        TRUE, TRUE, FALSE, parent_floater_name, button);
+
+    //Allows the closed parent floater to close the child floater (avatar picker)
+    if (child_floater)
+    {
+        parent_floater->addDependentFloater(child_floater);
+    }
+
+    return false;
 }
 
 // static
 void LLPanelEstateAccess::accessAddCore3(const uuid_vec_t& ids, std::vector<LLAvatarName> names, void* data)
 {
-	LLEstateAccessChangeInfo* change_info = (LLEstateAccessChangeInfo*)data;
-	if (!change_info) return;
-	if (ids.empty())
-	{
-		// User didn't select a name.
-		delete change_info;
-		change_info = NULL;
-		return;
-	}
-	// User did select a name.
-	change_info->mAgentOrGroupIDs = ids;
-	// Can't put estate owner on ban list
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (!panel) return;
-	LLViewerRegion* region = gAgent.getRegion();
-	if (!region) return;
-
-	if (change_info->mOperationFlag & ESTATE_ACCESS_ALLOWED_AGENT_ADD)
-	{
-		LLNameListCtrl* name_list = panel->getChild<LLNameListCtrl>("allowed_avatar_name_list");
-		int currentCount = (name_list ? name_list->getItemCount() : 0);
-		if (ids.size() + currentCount > ESTATE_MAX_ACCESS_IDS)
-		{
-			LLSD args;
-			args["NUM_ADDED"] = llformat("%d", ids.size());
-			args["MAX_AGENTS"] = llformat("%d", ESTATE_MAX_ACCESS_IDS);
-			args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeAllowedAgents");
-			args["NUM_EXCESS"] = llformat("%d", (ids.size() + currentCount) - ESTATE_MAX_ACCESS_IDS);
-			LLNotificationsUtil::add("MaxAgentOnRegionBatch", args);
-			delete change_info;
-			return;
-		}
-
-		uuid_vec_t ids_allowed;
-		std::vector<LLAvatarName> names_allowed;
-		std::string already_allowed;
-		bool single = true;
-		for (U32 i = 0; i < ids.size(); ++i)
-		{
-			LLScrollListItem* item = name_list->getNameItemByAgentId(ids[i]);
-			if (item)
-			{
-				if (!already_allowed.empty())
-				{
-					already_allowed += ", ";
-					single = false;
-				}
-				already_allowed += item->getColumn(0)->getValue().asString();
-			}
-			else
-			{
-				ids_allowed.push_back(ids[i]);
-				names_allowed.push_back(names[i]);
-			}
-		}
-		if (!already_allowed.empty())
-		{
-			LLSD args;
-			args["AGENT"] = already_allowed;
-			args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeAllowedAgents");
-			LLNotificationsUtil::add(single ? "AgentIsAlreadyInList" : "AgentsAreAlreadyInList", args);
-			if (ids_allowed.empty())
-			{
-				delete change_info;
-				return;
-			}
-		}
-		change_info->mAgentOrGroupIDs = ids_allowed;
-		change_info->mAgentNames = names_allowed;
-	}
-	if (change_info->mOperationFlag & ESTATE_ACCESS_BANNED_AGENT_ADD)
-	{
-		LLNameListCtrl* name_list = panel->getChild<LLNameListCtrl>("banned_avatar_name_list");
-		LLNameListCtrl* em_list = panel->getChild<LLNameListCtrl>("estate_manager_name_list");
-		int currentCount = (name_list ? name_list->getItemCount() : 0);
-		if (ids.size() + currentCount > ESTATE_MAX_BANNED_IDS)
-		{
-			LLSD args;
-			args["NUM_ADDED"] = llformat("%d", ids.size());
-			args["MAX_AGENTS"] = llformat("%d", ESTATE_MAX_BANNED_IDS);
-			args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeBannedAgents");
-			args["NUM_EXCESS"] = llformat("%d", (ids.size() + currentCount) - ESTATE_MAX_BANNED_IDS);
-			LLNotificationsUtil::add("MaxAgentOnRegionBatch", args);
-			delete change_info;
-			return;
-		}
-
-		uuid_vec_t ids_allowed;
-		std::vector<LLAvatarName> names_allowed;
-		std::string already_banned;
-		std::string em_ban;
-		bool single = true;
-		for (U32 i = 0; i < ids.size(); ++i)
-		{
-			bool is_allowed = true;
-			LLScrollListItem* em_item = em_list->getNameItemByAgentId(ids[i]);
-			if (em_item)
-			{
-				if (!em_ban.empty())
-				{
-					em_ban += ", ";
-				}
-				em_ban += em_item->getColumn(0)->getValue().asString();
-				is_allowed = false;
-			}
-
-			LLScrollListItem* item = name_list->getNameItemByAgentId(ids[i]);
-			if (item)
-			{
-				if (!already_banned.empty())
-				{
-					already_banned += ", ";
-					single = false;
-				}
-				already_banned += item->getColumn(0)->getValue().asString();
-				is_allowed = false;
-			}
-
-			if (is_allowed)
-			{
-				ids_allowed.push_back(ids[i]);
-				names_allowed.push_back(names[i]);
-			}
-		}
-		if (!em_ban.empty())
-		{
-			LLSD args;
-			args["AGENT"] = em_ban;
-			LLNotificationsUtil::add("ProblemBanningEstateManager", args);
-			if (ids_allowed.empty())
-			{
-				delete change_info;
-				return;
-			}
-		}
-		if (!already_banned.empty())
-		{
-			LLSD args;
-			args["AGENT"] = already_banned;
-			args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeBannedAgents");
-			LLNotificationsUtil::add(single ? "AgentIsAlreadyInList" : "AgentsAreAlreadyInList", args);
-			if (ids_allowed.empty())
-			{
-				delete change_info;
-				return;
-			}
-		}
-		change_info->mAgentOrGroupIDs = ids_allowed;
-		change_info->mAgentNames = names_allowed;
-	}
-
-	LLSD args;
-	args["ALL_ESTATES"] = all_estates_text();
-	LLNotification::Params params(change_info->mDialogName);
-	params.substitutions(args)
-		.payload(change_info->asLLSD())
-		.functor.function(accessCoreConfirm);
-
-	if (LLPanelEstateInfo::isLindenEstate())
-	{
-		// just apply to this estate
-		LLNotifications::instance().forceResponse(params, 0);
-	}
-	else
-	{
-		// ask if this estate or all estates with this owner
-		LLNotifications::instance().add(params);
-	}
+    LLEstateAccessChangeInfo* change_info = (LLEstateAccessChangeInfo*)data;
+    if (!change_info) return;
+    if (ids.empty())
+    {
+        // User didn't select a name.
+        delete change_info;
+        change_info = NULL;
+        return;
+    }
+    // User did select a name.
+    change_info->mAgentOrGroupIDs = ids;
+    // Can't put estate owner on ban list
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (!panel) return;
+    LLViewerRegion* region = gAgent.getRegion();
+    if (!region) return;
+
+    if (change_info->mOperationFlag & ESTATE_ACCESS_ALLOWED_AGENT_ADD)
+    {
+        LLNameListCtrl* name_list = panel->getChild<LLNameListCtrl>("allowed_avatar_name_list");
+        int currentCount = (name_list ? name_list->getItemCount() : 0);
+        if (ids.size() + currentCount > ESTATE_MAX_ACCESS_IDS)
+        {
+            LLSD args;
+            args["NUM_ADDED"] = llformat("%d", ids.size());
+            args["MAX_AGENTS"] = llformat("%d", ESTATE_MAX_ACCESS_IDS);
+            args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeAllowedAgents");
+            args["NUM_EXCESS"] = llformat("%d", (ids.size() + currentCount) - ESTATE_MAX_ACCESS_IDS);
+            LLNotificationsUtil::add("MaxAgentOnRegionBatch", args);
+            delete change_info;
+            return;
+        }
+
+        uuid_vec_t ids_allowed;
+        std::vector<LLAvatarName> names_allowed;
+        std::string already_allowed;
+        bool single = true;
+        for (U32 i = 0; i < ids.size(); ++i)
+        {
+            LLScrollListItem* item = name_list->getNameItemByAgentId(ids[i]);
+            if (item)
+            {
+                if (!already_allowed.empty())
+                {
+                    already_allowed += ", ";
+                    single = false;
+                }
+                already_allowed += item->getColumn(0)->getValue().asString();
+            }
+            else
+            {
+                ids_allowed.push_back(ids[i]);
+                names_allowed.push_back(names[i]);
+            }
+        }
+        if (!already_allowed.empty())
+        {
+            LLSD args;
+            args["AGENT"] = already_allowed;
+            args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeAllowedAgents");
+            LLNotificationsUtil::add(single ? "AgentIsAlreadyInList" : "AgentsAreAlreadyInList", args);
+            if (ids_allowed.empty())
+            {
+                delete change_info;
+                return;
+            }
+        }
+        change_info->mAgentOrGroupIDs = ids_allowed;
+        change_info->mAgentNames = names_allowed;
+    }
+    if (change_info->mOperationFlag & ESTATE_ACCESS_BANNED_AGENT_ADD)
+    {
+        LLNameListCtrl* name_list = panel->getChild<LLNameListCtrl>("banned_avatar_name_list");
+        LLNameListCtrl* em_list = panel->getChild<LLNameListCtrl>("estate_manager_name_list");
+        int currentCount = (name_list ? name_list->getItemCount() : 0);
+        if (ids.size() + currentCount > ESTATE_MAX_BANNED_IDS)
+        {
+            LLSD args;
+            args["NUM_ADDED"] = llformat("%d", ids.size());
+            args["MAX_AGENTS"] = llformat("%d", ESTATE_MAX_BANNED_IDS);
+            args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeBannedAgents");
+            args["NUM_EXCESS"] = llformat("%d", (ids.size() + currentCount) - ESTATE_MAX_BANNED_IDS);
+            LLNotificationsUtil::add("MaxAgentOnRegionBatch", args);
+            delete change_info;
+            return;
+        }
+
+        uuid_vec_t ids_allowed;
+        std::vector<LLAvatarName> names_allowed;
+        std::string already_banned;
+        std::string em_ban;
+        bool single = true;
+        for (U32 i = 0; i < ids.size(); ++i)
+        {
+            bool is_allowed = true;
+            LLScrollListItem* em_item = em_list->getNameItemByAgentId(ids[i]);
+            if (em_item)
+            {
+                if (!em_ban.empty())
+                {
+                    em_ban += ", ";
+                }
+                em_ban += em_item->getColumn(0)->getValue().asString();
+                is_allowed = false;
+            }
+
+            LLScrollListItem* item = name_list->getNameItemByAgentId(ids[i]);
+            if (item)
+            {
+                if (!already_banned.empty())
+                {
+                    already_banned += ", ";
+                    single = false;
+                }
+                already_banned += item->getColumn(0)->getValue().asString();
+                is_allowed = false;
+            }
+
+            if (is_allowed)
+            {
+                ids_allowed.push_back(ids[i]);
+                names_allowed.push_back(names[i]);
+            }
+        }
+        if (!em_ban.empty())
+        {
+            LLSD args;
+            args["AGENT"] = em_ban;
+            LLNotificationsUtil::add("ProblemBanningEstateManager", args);
+            if (ids_allowed.empty())
+            {
+                delete change_info;
+                return;
+            }
+        }
+        if (!already_banned.empty())
+        {
+            LLSD args;
+            args["AGENT"] = already_banned;
+            args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeBannedAgents");
+            LLNotificationsUtil::add(single ? "AgentIsAlreadyInList" : "AgentsAreAlreadyInList", args);
+            if (ids_allowed.empty())
+            {
+                delete change_info;
+                return;
+            }
+        }
+        change_info->mAgentOrGroupIDs = ids_allowed;
+        change_info->mAgentNames = names_allowed;
+    }
+
+    LLSD args;
+    args["ALL_ESTATES"] = all_estates_text();
+    LLNotification::Params params(change_info->mDialogName);
+    params.substitutions(args)
+        .payload(change_info->asLLSD())
+        .functor.function(accessCoreConfirm);
+
+    if (LLPanelEstateInfo::isLindenEstate())
+    {
+        // just apply to this estate
+        LLNotifications::instance().forceResponse(params, 0);
+    }
+    else
+    {
+        // ask if this estate or all estates with this owner
+        LLNotifications::instance().add(params);
+    }
 }
 
 // static
 void LLPanelEstateAccess::accessRemoveCore(U32 operation_flag, const std::string& dialog_name, const std::string& list_ctrl_name)
 {
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (!panel) return;
-	LLNameListCtrl* name_list = panel->getChild<LLNameListCtrl>(list_ctrl_name);
-	if (!name_list) return;
-
-	std::vector<LLScrollListItem*> list_vector = name_list->getAllSelected();
-	if (list_vector.size() == 0)
-		return;
-
-	LLSD payload;
-	payload["operation"] = (S32)operation_flag;
-	payload["dialog_name"] = dialog_name;
-
-	for (std::vector<LLScrollListItem*>::const_iterator iter = list_vector.begin();
-		iter != list_vector.end();
-		iter++)
-	{
-		LLScrollListItem *item = (*iter);
-		payload["allowed_ids"].append(item->getUUID());
-	}
-
-	LLNotification::Params params("ChangeLindenAccess");
-	params.payload(payload)
-		.functor.function(accessRemoveCore2);
-
-	if (LLPanelEstateInfo::isLindenEstate())
-	{
-		// warn on change linden estate
-		LLNotifications::instance().add(params);
-	}
-	else
-	{
-		// just proceed, as if clicking OK
-		LLNotifications::instance().forceResponse(params, 0);
-	}
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (!panel) return;
+    LLNameListCtrl* name_list = panel->getChild<LLNameListCtrl>(list_ctrl_name);
+    if (!name_list) return;
+
+    std::vector<LLScrollListItem*> list_vector = name_list->getAllSelected();
+    if (list_vector.size() == 0)
+        return;
+
+    LLSD payload;
+    payload["operation"] = (S32)operation_flag;
+    payload["dialog_name"] = dialog_name;
+
+    for (std::vector<LLScrollListItem*>::const_iterator iter = list_vector.begin();
+        iter != list_vector.end();
+        iter++)
+    {
+        LLScrollListItem *item = (*iter);
+        payload["allowed_ids"].append(item->getUUID());
+    }
+
+    LLNotification::Params params("ChangeLindenAccess");
+    params.payload(payload)
+        .functor.function(accessRemoveCore2);
+
+    if (LLPanelEstateInfo::isLindenEstate())
+    {
+        // warn on change linden estate
+        LLNotifications::instance().add(params);
+    }
+    else
+    {
+        // just proceed, as if clicking OK
+        LLNotifications::instance().forceResponse(params, 0);
+    }
 }
 
 // static
 bool LLPanelEstateAccess::accessRemoveCore2(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0)
-	{
-		// abort
-		return false;
-	}
-
-	// If Linden estate, can only apply to "this" estate, not all estates
-	// owned by NULL.
-	if (LLPanelEstateInfo::isLindenEstate())
-	{
-		accessCoreConfirm(notification, response);
-	}
-	else
-	{
-		LLSD args;
-		args["ALL_ESTATES"] = all_estates_text();
-		LLNotificationsUtil::add(notification["payload"]["dialog_name"],
-			args,
-			notification["payload"],
-			accessCoreConfirm);
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option != 0)
+    {
+        // abort
+        return false;
+    }
+
+    // If Linden estate, can only apply to "this" estate, not all estates
+    // owned by NULL.
+    if (LLPanelEstateInfo::isLindenEstate())
+    {
+        accessCoreConfirm(notification, response);
+    }
+    else
+    {
+        LLSD args;
+        args["ALL_ESTATES"] = all_estates_text();
+        LLNotificationsUtil::add(notification["payload"]["dialog_name"],
+            args,
+            notification["payload"],
+            accessCoreConfirm);
+    }
+    return false;
 }
 
 // Used for both access add and remove operations, depending on the mOperationFlag
@@ -3660,133 +3660,133 @@ bool LLPanelEstateAccess::accessRemoveCore2(const LLSD& notification, const LLSD
 // static
 bool LLPanelEstateAccess::accessCoreConfirm(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	const U32 originalFlags = (U32)notification["payload"]["operation"].asInteger();
-	U32 flags = originalFlags;
-
-	LLViewerRegion* region = gAgent.getRegion();
-
-	if (option == 2) // cancel
-	{		
-		return false;
-	}
-	else if (option == 1)
-	{
-		// All estates, either than I own or manage for this owner.  
-		// This will be verified on simulator. JC
-		if (!region) return false;
-		if (region->getOwner() == gAgent.getID()
-			|| gAgent.isGodlike())
-		{
-			flags |= ESTATE_ACCESS_APPLY_TO_ALL_ESTATES;
-		}
-		else if (region->isEstateManager())
-		{
-			flags |= ESTATE_ACCESS_APPLY_TO_MANAGED_ESTATES;
-		}
-	}
-
-	std::string names;
-	U32 listed_names = 0;
-	for (U32 i = 0; i < notification["payload"]["allowed_ids"].size(); ++i)
-	{
-		if (i + 1 != notification["payload"]["allowed_ids"].size())
-		{
-			flags |= ESTATE_ACCESS_NO_REPLY;
-		}
-		else
-		{
-			flags &= ~ESTATE_ACCESS_NO_REPLY;
-		}
-
-		const LLUUID id = notification["payload"]["allowed_ids"][i].asUUID();
-		if (((U32)notification["payload"]["operation"].asInteger() & ESTATE_ACCESS_BANNED_AGENT_ADD)
-			&& region && (region->getOwner() == id))
-		{
-			LLNotificationsUtil::add("OwnerCanNotBeDenied");
-			break;
-		}
-
-		sendEstateAccessDelta(flags, id);
-
-		if ((flags & (ESTATE_ACCESS_ALLOWED_GROUP_ADD | ESTATE_ACCESS_ALLOWED_GROUP_REMOVE)) == 0)
-		{
-			// fill the name list for confirmation
-			if (listed_names < MAX_LISTED_NAMES)
-			{
-				if (!names.empty())
-				{
-					names += ", ";
-				}
-				if (!notification["payload"]["allowed_names"][i]["display_name"].asString().empty())
-				{
-					names += notification["payload"]["allowed_names"][i]["display_name"].asString();
-				}
-				else
-				{ //try to get an agent name from cache
-					LLAvatarName av_name;
-					if (LLAvatarNameCache::get(id, &av_name))
-					{
-						names += av_name.getCompleteName();
-					}
-				}
-				
-			}
-			listed_names++;
-		}
-	}
-	if (listed_names > MAX_LISTED_NAMES)
-	{
-		LLSD args;
-		args["EXTRA_COUNT"] = llformat("%d", listed_names - MAX_LISTED_NAMES);
-		names += " " + LLTrans::getString("AndNMore", args);
-	}
-
-	if (!names.empty()) // show the conirmation
-	{
-		LLSD args;
-		args["AGENT"] = names;
-
-		if (flags & (ESTATE_ACCESS_ALLOWED_AGENT_ADD | ESTATE_ACCESS_ALLOWED_AGENT_REMOVE))
-		{
-			args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeAllowedAgents");
-		}
-		else if (flags & (ESTATE_ACCESS_BANNED_AGENT_ADD | ESTATE_ACCESS_BANNED_AGENT_REMOVE))
-		{
-			args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeBannedAgents");
-		}
-
-		if (flags & ESTATE_ACCESS_APPLY_TO_ALL_ESTATES)
-		{
-			args["ESTATE"] = LLTrans::getString("RegionInfoAllEstates");
-		}
-		else if (flags & ESTATE_ACCESS_APPLY_TO_MANAGED_ESTATES)
-		{
-			args["ESTATE"] = LLTrans::getString("RegionInfoManagedEstates");
-		}
-		else
-		{
-			args["ESTATE"] = LLTrans::getString("RegionInfoThisEstate");
-		}
-
-		bool single = (listed_names == 1);
-		if (flags & (ESTATE_ACCESS_ALLOWED_AGENT_ADD | ESTATE_ACCESS_BANNED_AGENT_ADD))
-		{
-			LLNotificationsUtil::add(single ? "AgentWasAddedToList" : "AgentsWereAddedToList", args);
-		}
-		else if (flags & (ESTATE_ACCESS_ALLOWED_AGENT_REMOVE | ESTATE_ACCESS_BANNED_AGENT_REMOVE))
-		{
-			LLNotificationsUtil::add(single ? "AgentWasRemovedFromList" : "AgentsWereRemovedFromList", args);
-		}		
-	}
-
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (panel)
-	{
-		panel->setPendingUpdate(true);
-	}
-
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    const U32 originalFlags = (U32)notification["payload"]["operation"].asInteger();
+    U32 flags = originalFlags;
+
+    LLViewerRegion* region = gAgent.getRegion();
+
+    if (option == 2) // cancel
+    {
+        return false;
+    }
+    else if (option == 1)
+    {
+        // All estates, either than I own or manage for this owner.
+        // This will be verified on simulator. JC
+        if (!region) return false;
+        if (region->getOwner() == gAgent.getID()
+            || gAgent.isGodlike())
+        {
+            flags |= ESTATE_ACCESS_APPLY_TO_ALL_ESTATES;
+        }
+        else if (region->isEstateManager())
+        {
+            flags |= ESTATE_ACCESS_APPLY_TO_MANAGED_ESTATES;
+        }
+    }
+
+    std::string names;
+    U32 listed_names = 0;
+    for (U32 i = 0; i < notification["payload"]["allowed_ids"].size(); ++i)
+    {
+        if (i + 1 != notification["payload"]["allowed_ids"].size())
+        {
+            flags |= ESTATE_ACCESS_NO_REPLY;
+        }
+        else
+        {
+            flags &= ~ESTATE_ACCESS_NO_REPLY;
+        }
+
+        const LLUUID id = notification["payload"]["allowed_ids"][i].asUUID();
+        if (((U32)notification["payload"]["operation"].asInteger() & ESTATE_ACCESS_BANNED_AGENT_ADD)
+            && region && (region->getOwner() == id))
+        {
+            LLNotificationsUtil::add("OwnerCanNotBeDenied");
+            break;
+        }
+
+        sendEstateAccessDelta(flags, id);
+
+        if ((flags & (ESTATE_ACCESS_ALLOWED_GROUP_ADD | ESTATE_ACCESS_ALLOWED_GROUP_REMOVE)) == 0)
+        {
+            // fill the name list for confirmation
+            if (listed_names < MAX_LISTED_NAMES)
+            {
+                if (!names.empty())
+                {
+                    names += ", ";
+                }
+                if (!notification["payload"]["allowed_names"][i]["display_name"].asString().empty())
+                {
+                    names += notification["payload"]["allowed_names"][i]["display_name"].asString();
+                }
+                else
+                { //try to get an agent name from cache
+                    LLAvatarName av_name;
+                    if (LLAvatarNameCache::get(id, &av_name))
+                    {
+                        names += av_name.getCompleteName();
+                    }
+                }
+
+            }
+            listed_names++;
+        }
+    }
+    if (listed_names > MAX_LISTED_NAMES)
+    {
+        LLSD args;
+        args["EXTRA_COUNT"] = llformat("%d", listed_names - MAX_LISTED_NAMES);
+        names += " " + LLTrans::getString("AndNMore", args);
+    }
+
+    if (!names.empty()) // show the conirmation
+    {
+        LLSD args;
+        args["AGENT"] = names;
+
+        if (flags & (ESTATE_ACCESS_ALLOWED_AGENT_ADD | ESTATE_ACCESS_ALLOWED_AGENT_REMOVE))
+        {
+            args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeAllowedAgents");
+        }
+        else if (flags & (ESTATE_ACCESS_BANNED_AGENT_ADD | ESTATE_ACCESS_BANNED_AGENT_REMOVE))
+        {
+            args["LIST_TYPE"] = LLTrans::getString("RegionInfoListTypeBannedAgents");
+        }
+
+        if (flags & ESTATE_ACCESS_APPLY_TO_ALL_ESTATES)
+        {
+            args["ESTATE"] = LLTrans::getString("RegionInfoAllEstates");
+        }
+        else if (flags & ESTATE_ACCESS_APPLY_TO_MANAGED_ESTATES)
+        {
+            args["ESTATE"] = LLTrans::getString("RegionInfoManagedEstates");
+        }
+        else
+        {
+            args["ESTATE"] = LLTrans::getString("RegionInfoThisEstate");
+        }
+
+        bool single = (listed_names == 1);
+        if (flags & (ESTATE_ACCESS_ALLOWED_AGENT_ADD | ESTATE_ACCESS_BANNED_AGENT_ADD))
+        {
+            LLNotificationsUtil::add(single ? "AgentWasAddedToList" : "AgentsWereAddedToList", args);
+        }
+        else if (flags & (ESTATE_ACCESS_ALLOWED_AGENT_REMOVE | ESTATE_ACCESS_BANNED_AGENT_REMOVE))
+        {
+            LLNotificationsUtil::add(single ? "AgentWasRemovedFromList" : "AgentsWereRemovedFromList", args);
+        }
+    }
+
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (panel)
+    {
+        panel->setPendingUpdate(true);
+    }
+
+    return false;
 }
 
 // key = "estateaccessdelta"
@@ -3797,164 +3797,164 @@ bool LLPanelEstateAccess::accessCoreConfirm(const LLSD& notification, const LLSD
 // static
 void LLPanelEstateAccess::sendEstateAccessDelta(U32 flags, const LLUUID& agent_or_group_id)
 {
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_EstateOwnerMessage);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_EstateOwnerMessage);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
 
-	msg->nextBlockFast(_PREHASH_MethodData);
-	msg->addStringFast(_PREHASH_Method, "estateaccessdelta");
-	msg->addUUIDFast(_PREHASH_Invoice, LLFloaterRegionInfo::getLastInvoice());
+    msg->nextBlockFast(_PREHASH_MethodData);
+    msg->addStringFast(_PREHASH_Method, "estateaccessdelta");
+    msg->addUUIDFast(_PREHASH_Invoice, LLFloaterRegionInfo::getLastInvoice());
 
-	std::string buf;
-	gAgent.getID().toString(buf);
-	msg->nextBlockFast(_PREHASH_ParamList);
-	msg->addStringFast(_PREHASH_Parameter, buf);
+    std::string buf;
+    gAgent.getID().toString(buf);
+    msg->nextBlockFast(_PREHASH_ParamList);
+    msg->addStringFast(_PREHASH_Parameter, buf);
 
-	buf = llformat("%u", flags);
-	msg->nextBlockFast(_PREHASH_ParamList);
-	msg->addStringFast(_PREHASH_Parameter, buf);
+    buf = llformat("%u", flags);
+    msg->nextBlockFast(_PREHASH_ParamList);
+    msg->addStringFast(_PREHASH_Parameter, buf);
 
-	agent_or_group_id.toString(buf);
-	msg->nextBlockFast(_PREHASH_ParamList);
-	msg->addStringFast(_PREHASH_Parameter, buf);
+    agent_or_group_id.toString(buf);
+    msg->nextBlockFast(_PREHASH_ParamList);
+    msg->addStringFast(_PREHASH_Parameter, buf);
 
-	gAgent.sendReliableMessage();
+    gAgent.sendReliableMessage();
 }
 
 void LLPanelEstateAccess::updateChild(LLUICtrl* child_ctrl)
 {
-	// Ensure appropriate state of the management ui.
-	updateControls(gAgent.getRegion());
+    // Ensure appropriate state of the management ui.
+    updateControls(gAgent.getRegion());
 }
 
 void LLPanelEstateAccess::updateLists()
 {
-	std::string cap_url = gAgent.getRegionCapability("EstateAccess");
-	if (!cap_url.empty())
-	{
-		LLCoros::instance().launch("LLFloaterRegionInfo::requestEstateGetAccessCoro", boost::bind(LLPanelEstateAccess::requestEstateGetAccessCoro, cap_url));
-	}
+    std::string cap_url = gAgent.getRegionCapability("EstateAccess");
+    if (!cap_url.empty())
+    {
+        LLCoros::instance().launch("LLFloaterRegionInfo::requestEstateGetAccessCoro", boost::bind(LLPanelEstateAccess::requestEstateGetAccessCoro, cap_url));
+    }
 }
 
 void LLPanelEstateAccess::requestEstateGetAccessCoro(std::string url)
 {
-	LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
-	LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t	httpAdapter(std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("requestEstateGetAccessoCoro", httpPolicy));
+    LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+    LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t httpAdapter(std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("requestEstateGetAccessoCoro", httpPolicy));
     LLCore::HttpRequest::ptr_t httpRequest(std::make_shared<LLCore::HttpRequest>());
 
-	LLSD result = httpAdapter->getAndSuspend(httpRequest, url);
-
-	LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
-	LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
-
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (!panel) return;
-	
-	LLNameListCtrl* allowed_agent_name_list	= panel->getChild<LLNameListCtrl>("allowed_avatar_name_list");
-	if (allowed_agent_name_list && result.has("AllowedAgents"))
-	{
-		LLStringUtil::format_map_t args;
-		args["[ALLOWEDAGENTS]"] = llformat("%d", result["AllowedAgents"].size());
-		args["[MAXACCESS]"] = llformat("%d", ESTATE_MAX_ACCESS_IDS);
-		std::string msg = LLTrans::getString("RegionInfoAllowedResidents", args);
-		panel->getChild<LLUICtrl>("allow_resident_label")->setValue(LLSD(msg));
-
-		allowed_agent_name_list->clearSortOrder();
-		allowed_agent_name_list->deleteAllItems();
-		for (const auto& llsd_val : result["AllowedAgents"].asArray())
-		{ 
-			LLUUID id = llsd_val["id"].asUUID();
-			allowed_agent_name_list->addNameItem(id);
-		}
-		allowed_agent_name_list->sortByName(TRUE);
-	}
-
-	LLNameListCtrl* banned_agent_name_list = panel->getChild<LLNameListCtrl>("banned_avatar_name_list");
-	if (banned_agent_name_list && result.has("BannedAgents"))
-	{
-		LLStringUtil::format_map_t args;
-		args["[BANNEDAGENTS]"] = llformat("%d", result["BannedAgents"].size());
-		args["[MAXBANNED]"] = llformat("%d", ESTATE_MAX_BANNED_IDS);
-		std::string msg = LLTrans::getString("RegionInfoBannedResidents", args);
-		panel->getChild<LLUICtrl>("ban_resident_label")->setValue(LLSD(msg));
-
-		banned_agent_name_list->clearSortOrder();
-		banned_agent_name_list->deleteAllItems();
-		for (const auto& llsd_val : result["BannedAgents"].asArray())
-		{
-			LLSD item;
-			item["id"] = llsd_val["id"].asUUID();
-			LLSD& columns = item["columns"];
-
-			columns[0]["column"] = "name"; // to be populated later
-
-			columns[1]["column"] = "last_login_date";
-			columns[1]["value"] = llsd_val["last_login_date"].asString().substr(0, 16); // cut the seconds
-
-			std::string ban_date = llsd_val["ban_date"].asString();
-			columns[2]["column"] = "ban_date";
-			columns[2]["value"] = ban_date[0] != '0' ? ban_date.substr(0, 16) : LLTrans::getString("na"); // server returns the "0000-00-00 00:00:00" date in case it doesn't know it
-
-			columns[3]["column"] = "bannedby";
-			LLUUID banning_id = llsd_val["banning_id"].asUUID();
-			LLAvatarName av_name;
-			if (banning_id.isNull())
-			{
-				columns[3]["value"] = LLTrans::getString("na");
-			}
-			else if (LLAvatarNameCache::get(banning_id, &av_name))
-			{
-				columns[3]["value"] = av_name.getCompleteName(); //TODO: fetch the name if it wasn't cached
-			}
-
-			banned_agent_name_list->addElement(item);
-		}
-		banned_agent_name_list->sortByName(TRUE);
-	}
-
-	LLNameListCtrl* allowed_group_name_list = panel->getChild<LLNameListCtrl>("allowed_group_name_list");
-	if (allowed_group_name_list && result.has("AllowedGroups"))
-	{
-		LLStringUtil::format_map_t args;
-		args["[ALLOWEDGROUPS]"] = llformat("%d", result["AllowedGroups"].size());
-		args["[MAXACCESS]"] = llformat("%d", ESTATE_MAX_GROUP_IDS);
-		std::string msg = LLTrans::getString("RegionInfoAllowedGroups", args);
-		panel->getChild<LLUICtrl>("allow_group_label")->setValue(LLSD(msg));
-
-		allowed_group_name_list->clearSortOrder();
-		allowed_group_name_list->deleteAllItems();
-		for (const auto& llsd_val : result["AllowedGroups"].asArray())
-		{
-			LLUUID id = llsd_val["id"].asUUID();
-			allowed_group_name_list->addGroupNameItem(id);
-		}
-		allowed_group_name_list->sortByName(TRUE);
-	}
-
-	LLNameListCtrl* estate_manager_name_list = panel->getChild<LLNameListCtrl>("estate_manager_name_list");
-	if (estate_manager_name_list && result.has("Managers"))
-	{
-		LLStringUtil::format_map_t args;
-		args["[ESTATEMANAGERS]"] = llformat("%d", result["Managers"].size());
-		args["[MAXMANAGERS]"] = llformat("%d", ESTATE_MAX_MANAGERS);
-		std::string msg = LLTrans::getString("RegionInfoEstateManagers", args);
-		panel->getChild<LLUICtrl>("estate_manager_label")->setValue(LLSD(msg));
-
-		estate_manager_name_list->clearSortOrder();
-		estate_manager_name_list->deleteAllItems();
-		for (const auto& llsd_val : result["Managers"].asArray())
-		{
-			LLUUID id = llsd_val["agent_id"].asUUID();
-			estate_manager_name_list->addNameItem(id);
-		}
-		estate_manager_name_list->sortByName(TRUE);
-	}
-
-
-	panel->updateControls(gAgent.getRegion());
+    LLSD result = httpAdapter->getAndSuspend(httpRequest, url);
+
+    LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+    LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (!panel) return;
+
+    LLNameListCtrl* allowed_agent_name_list = panel->getChild<LLNameListCtrl>("allowed_avatar_name_list");
+    if (allowed_agent_name_list && result.has("AllowedAgents"))
+    {
+        LLStringUtil::format_map_t args;
+        args["[ALLOWEDAGENTS]"] = llformat("%d", result["AllowedAgents"].size());
+        args["[MAXACCESS]"] = llformat("%d", ESTATE_MAX_ACCESS_IDS);
+        std::string msg = LLTrans::getString("RegionInfoAllowedResidents", args);
+        panel->getChild<LLUICtrl>("allow_resident_label")->setValue(LLSD(msg));
+
+        allowed_agent_name_list->clearSortOrder();
+        allowed_agent_name_list->deleteAllItems();
+        for (const auto& llsd_val : result["AllowedAgents"].asArray())
+        {
+            LLUUID id = llsd_val["id"].asUUID();
+            allowed_agent_name_list->addNameItem(id);
+        }
+        allowed_agent_name_list->sortByName(TRUE);
+    }
+
+    LLNameListCtrl* banned_agent_name_list = panel->getChild<LLNameListCtrl>("banned_avatar_name_list");
+    if (banned_agent_name_list && result.has("BannedAgents"))
+    {
+        LLStringUtil::format_map_t args;
+        args["[BANNEDAGENTS]"] = llformat("%d", result["BannedAgents"].size());
+        args["[MAXBANNED]"] = llformat("%d", ESTATE_MAX_BANNED_IDS);
+        std::string msg = LLTrans::getString("RegionInfoBannedResidents", args);
+        panel->getChild<LLUICtrl>("ban_resident_label")->setValue(LLSD(msg));
+
+        banned_agent_name_list->clearSortOrder();
+        banned_agent_name_list->deleteAllItems();
+        for (const auto& llsd_val : result["BannedAgents"].asArray())
+        {
+            LLSD item;
+            item["id"] = llsd_val["id"].asUUID();
+            LLSD& columns = item["columns"];
+
+            columns[0]["column"] = "name"; // to be populated later
+
+            columns[1]["column"] = "last_login_date";
+            columns[1]["value"] = llsd_val["last_login_date"].asString().substr(0, 16); // cut the seconds
+
+            std::string ban_date = llsd_val["ban_date"].asString();
+            columns[2]["column"] = "ban_date";
+            columns[2]["value"] = ban_date[0] != '0' ? ban_date.substr(0, 16) : LLTrans::getString("na"); // server returns the "0000-00-00 00:00:00" date in case it doesn't know it
+
+            columns[3]["column"] = "bannedby";
+            LLUUID banning_id = llsd_val["banning_id"].asUUID();
+            LLAvatarName av_name;
+            if (banning_id.isNull())
+            {
+                columns[3]["value"] = LLTrans::getString("na");
+            }
+            else if (LLAvatarNameCache::get(banning_id, &av_name))
+            {
+                columns[3]["value"] = av_name.getCompleteName(); //TODO: fetch the name if it wasn't cached
+            }
+
+            banned_agent_name_list->addElement(item);
+        }
+        banned_agent_name_list->sortByName(TRUE);
+    }
+
+    LLNameListCtrl* allowed_group_name_list = panel->getChild<LLNameListCtrl>("allowed_group_name_list");
+    if (allowed_group_name_list && result.has("AllowedGroups"))
+    {
+        LLStringUtil::format_map_t args;
+        args["[ALLOWEDGROUPS]"] = llformat("%d", result["AllowedGroups"].size());
+        args["[MAXACCESS]"] = llformat("%d", ESTATE_MAX_GROUP_IDS);
+        std::string msg = LLTrans::getString("RegionInfoAllowedGroups", args);
+        panel->getChild<LLUICtrl>("allow_group_label")->setValue(LLSD(msg));
+
+        allowed_group_name_list->clearSortOrder();
+        allowed_group_name_list->deleteAllItems();
+        for (const auto& llsd_val : result["AllowedGroups"].asArray())
+        {
+            LLUUID id = llsd_val["id"].asUUID();
+            allowed_group_name_list->addGroupNameItem(id);
+        }
+        allowed_group_name_list->sortByName(TRUE);
+    }
+
+    LLNameListCtrl* estate_manager_name_list = panel->getChild<LLNameListCtrl>("estate_manager_name_list");
+    if (estate_manager_name_list && result.has("Managers"))
+    {
+        LLStringUtil::format_map_t args;
+        args["[ESTATEMANAGERS]"] = llformat("%d", result["Managers"].size());
+        args["[MAXMANAGERS]"] = llformat("%d", ESTATE_MAX_MANAGERS);
+        std::string msg = LLTrans::getString("RegionInfoEstateManagers", args);
+        panel->getChild<LLUICtrl>("estate_manager_label")->setValue(LLSD(msg));
+
+        estate_manager_name_list->clearSortOrder();
+        estate_manager_name_list->deleteAllItems();
+        for (const auto& llsd_val : result["Managers"].asArray())
+        {
+            LLUUID id = llsd_val["agent_id"].asUUID();
+            estate_manager_name_list->addNameItem(id);
+        }
+        estate_manager_name_list->sortByName(TRUE);
+    }
+
+
+    panel->updateControls(gAgent.getRegion());
 }
 
 //---------------------------------------------------------------------------
@@ -3962,76 +3962,76 @@ void LLPanelEstateAccess::requestEstateGetAccessCoro(std::string url)
 //---------------------------------------------------------------------------
 void LLPanelEstateAccess::onAllowedSearchEdit(const std::string& search_string)
 {
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (!panel) return;
-	LLNameListCtrl* allowed_agent_name_list = panel->getChild<LLNameListCtrl>("allowed_avatar_name_list");
-	searchAgent(allowed_agent_name_list, search_string);
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (!panel) return;
+    LLNameListCtrl* allowed_agent_name_list = panel->getChild<LLNameListCtrl>("allowed_avatar_name_list");
+    searchAgent(allowed_agent_name_list, search_string);
 }
 
 void LLPanelEstateAccess::onAllowedGroupsSearchEdit(const std::string& search_string)
 {
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (!panel) return;
-	LLNameListCtrl* allowed_group_name_list = panel->getChild<LLNameListCtrl>("allowed_group_name_list");
-	searchAgent(allowed_group_name_list, search_string);
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (!panel) return;
+    LLNameListCtrl* allowed_group_name_list = panel->getChild<LLNameListCtrl>("allowed_group_name_list");
+    searchAgent(allowed_group_name_list, search_string);
 }
 
 void LLPanelEstateAccess::onBannedSearchEdit(const std::string& search_string)
 {
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (!panel) return;
-	LLNameListCtrl* banned_agent_name_list = panel->getChild<LLNameListCtrl>("banned_avatar_name_list");
-	searchAgent(banned_agent_name_list, search_string);
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (!panel) return;
+    LLNameListCtrl* banned_agent_name_list = panel->getChild<LLNameListCtrl>("banned_avatar_name_list");
+    searchAgent(banned_agent_name_list, search_string);
 }
 
 void LLPanelEstateAccess::searchAgent(LLNameListCtrl* listCtrl, const std::string& search_string)
 {
-	if (!listCtrl) return;
+    if (!listCtrl) return;
 
-	if (!search_string.empty())
-	{
-		listCtrl->setSearchColumn(0); // name column
-		listCtrl->searchItems(search_string, false, true);
-	}
-	else
-	{
-		listCtrl->deselectAllItems(TRUE);
-	}
+    if (!search_string.empty())
+    {
+        listCtrl->setSearchColumn(0); // name column
+        listCtrl->searchItems(search_string, false, true);
+    }
+    else
+    {
+        listCtrl->deselectAllItems(TRUE);
+    }
 }
 
 void LLPanelEstateAccess::copyListToClipboard(std::string list_name)
 {
-	LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
-	if (!panel) return;
-	LLNameListCtrl* name_list = panel->getChild<LLNameListCtrl>(list_name);
-	if (!name_list) return;
-
-	std::vector<LLScrollListItem*> list_vector = name_list->getAllData();
-	if (list_vector.size() == 0) return;
-
-	LLSD::String list_to_copy;
-	for (std::vector<LLScrollListItem*>::const_iterator iter = list_vector.begin();
-		 iter != list_vector.end();
-		 iter++)
-	{
-		LLScrollListItem *item = (*iter);
-		if (item)
-		{
-			list_to_copy += item->getColumn(0)->getValue().asString();
-		}
-		if (std::next(iter) != list_vector.end())
-		{
-			list_to_copy += "\n";
-		}
-	}
-
-	LLClipboard::instance().copyToClipboard(utf8str_to_wstring(list_to_copy), 0, list_to_copy.length());
+    LLPanelEstateAccess* panel = LLFloaterRegionInfo::getPanelAccess();
+    if (!panel) return;
+    LLNameListCtrl* name_list = panel->getChild<LLNameListCtrl>(list_name);
+    if (!name_list) return;
+
+    std::vector<LLScrollListItem*> list_vector = name_list->getAllData();
+    if (list_vector.size() == 0) return;
+
+    LLSD::String list_to_copy;
+    for (std::vector<LLScrollListItem*>::const_iterator iter = list_vector.begin();
+         iter != list_vector.end();
+         iter++)
+    {
+        LLScrollListItem *item = (*iter);
+        if (item)
+        {
+            list_to_copy += item->getColumn(0)->getValue().asString();
+        }
+        if (std::next(iter) != list_vector.end())
+        {
+            list_to_copy += "\n";
+        }
+    }
+
+    LLClipboard::instance().copyToClipboard(utf8str_to_wstring(list_to_copy), 0, list_to_copy.length());
 }
 
 bool LLPanelEstateAccess::refreshFromRegion(LLViewerRegion* region)
 {
-	updateLists();
-	return LLPanelRegionInfo::refreshFromRegion(region);
+    updateLists();
+    return LLPanelRegionInfo::refreshFromRegion(region);
 }
 
 //=========================================================================
diff --git a/indra/newview/llfloaterregioninfo.h b/indra/newview/llfloaterregioninfo.h
index b4762039bd75244dbea7501bfe54f3057f48a284..dc4da26b8e8da27dd59c759d20a206c30cba83e3 100644
--- a/indra/newview/llfloaterregioninfo.h
+++ b/indra/newview/llfloaterregioninfo.h
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file llfloaterregioninfo.h
  * @author Aaron Brashears
  * @brief Declaration of the region info and controls floater and panels.
@@ -6,21 +6,21 @@
  * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -73,58 +73,58 @@ class LLEventTimer;
 
 class LLFloaterRegionInfo final : public LLFloater
 {
-	friend class LLFloaterReg;
+    friend class LLFloaterReg;
 public:
 
 
-	void onOpen(const LLSD& key) override;
-	void onClose(bool app_quitting) override;
-	BOOL postBuild() override;
+    void onOpen(const LLSD& key) override;
+    void onClose(bool app_quitting) override;
+    BOOL postBuild() override;
+
+    static void processEstateOwnerRequest(LLMessageSystem* msg, void**);
 
-	static void processEstateOwnerRequest(LLMessageSystem* msg, void**);
+    // get and process region info if necessary.
+    static void processRegionInfo(LLMessageSystem* msg);
 
-	// get and process region info if necessary.
-	static void processRegionInfo(LLMessageSystem* msg);
+    static const LLUUID& getLastInvoice() { return sRequestInvoice; }
+    static void nextInvoice() { sRequestInvoice.generate(); }
+    //static S32 getSerial() { return sRequestSerial; }
+    //static void incrementSerial() { sRequestSerial++; }
 
-	static const LLUUID& getLastInvoice() { return sRequestInvoice; }
-	static void nextInvoice() { sRequestInvoice.generate(); }
-	//static S32 getSerial() { return sRequestSerial; }
-	//static void incrementSerial() { sRequestSerial++; }
+    static LLPanelEstateInfo* getPanelEstate();
+    static LLPanelEstateAccess* getPanelAccess();
+    static LLPanelEstateCovenant* getPanelCovenant();
+    static LLPanelRegionTerrainInfo* getPanelRegionTerrain();
+    static LLPanelRegionExperiences* getPanelExperiences();
+    static LLPanelRegionGeneralInfo* getPanelGeneral();
+    static LLPanelRegionEnvironment* getPanelEnvironment();
 
-	static LLPanelEstateInfo* getPanelEstate();
-	static LLPanelEstateAccess* getPanelAccess();
-	static LLPanelEstateCovenant* getPanelCovenant();
-	static LLPanelRegionTerrainInfo* getPanelRegionTerrain();
-	static LLPanelRegionExperiences* getPanelExperiences();
-	static LLPanelRegionGeneralInfo* getPanelGeneral();
-	static LLPanelRegionEnvironment* getPanelEnvironment();
+    // from LLPanel
+    void refresh() override;
 
-	// from LLPanel
-	void refresh() override;
-	
-	void onRegionChanged();
-	void requestRegionInfo();
-	void enableTopButtons();
-	void disableTopButtons();
+    void onRegionChanged();
+    void requestRegionInfo();
+    void enableTopButtons();
+    void disableTopButtons();
 
 private:
-	
-	LLFloaterRegionInfo(const LLSD& seed);
-	~LLFloaterRegionInfo();
+
+    LLFloaterRegionInfo(const LLSD& seed);
+    ~LLFloaterRegionInfo();
 
 protected:
-	void onTabSelected(const LLSD& param);
-	void disableTabCtrls();
-	void refreshFromRegion(LLViewerRegion* region);
-	void onGodLevelChange(U8 god_level);
-
-	// member data
-	LLTabContainer* mTab;
-	typedef std::vector<LLPanelRegionInfo*> info_panels_t;
-	info_panels_t mInfoPanels;
+    void onTabSelected(const LLSD& param);
+    void disableTabCtrls();
+    void refreshFromRegion(LLViewerRegion* region);
+    void onGodLevelChange(U8 god_level);
+
+    // member data
+    LLTabContainer* mTab;
+    typedef std::vector<LLPanelRegionInfo*> info_panels_t;
+    info_panels_t mInfoPanels;
     LLPanelRegionEnvironment *mEnvironmentPanel;
-    //static S32 sRequestSerial;	// serial # of last EstateOwnerRequest
-	static LLUUID sRequestInvoice;
+    //static S32 sRequestSerial;    // serial # of last EstateOwnerRequest
+    static LLUUID sRequestInvoice;
 
 private:
     LLAgent::god_level_change_slot_t   mGodLevelChangeSlot;
@@ -136,42 +136,42 @@ class LLFloaterRegionInfo final : public LLFloater
 class LLPanelRegionInfo : public LLPanel
 {
 public:
-	LLPanelRegionInfo();
-	
-	void onBtnSet();
-	void onChangeChildCtrl(LLUICtrl* ctrl);
-	void onChangeAnything();
-	static void onChangeText(LLLineEditor* caller, void* user_data);
-	
-	virtual bool refreshFromRegion(LLViewerRegion* region);
-	virtual bool estateUpdate(LLMessageSystem* msg) { return true; }
-	
-	BOOL postBuild() override;
-	virtual void updateChild(LLUICtrl* child_ctrl);
-	
-	void enableButton(const std::string& btn_name, BOOL enable = TRUE);
-	void disableButton(const std::string& btn_name);
-	
-	void onClickManageTelehub();
-	
+    LLPanelRegionInfo();
+
+    void onBtnSet();
+    void onChangeChildCtrl(LLUICtrl* ctrl);
+    void onChangeAnything();
+    static void onChangeText(LLLineEditor* caller, void* user_data);
+
+    virtual bool refreshFromRegion(LLViewerRegion* region);
+    virtual bool estateUpdate(LLMessageSystem* msg) { return true; }
+
+    BOOL postBuild() override;
+    virtual void updateChild(LLUICtrl* child_ctrl);
+
+    void enableButton(const std::string& btn_name, BOOL enable = TRUE);
+    void disableButton(const std::string& btn_name);
+
+    void onClickManageTelehub();
+
 protected:
-	void initCtrl(const std::string& name);
-	
-	// Returns TRUE if update sent and apply button should be
-	// disabled.
-	virtual BOOL sendUpdate() { return TRUE; }
-	
-	typedef std::vector<std::string> strings_t;
-	//typedef std::vector<U32> integers_t;
-	void sendEstateOwnerMessage(
-					 LLMessageSystem* msg,
-					 const std::string& request,
-					 const LLUUID& invoice,
-					 const strings_t& strings);
-	
-	
-	// member data
-	LLHost mHost;
+    void initCtrl(const std::string& name);
+
+    // Returns TRUE if update sent and apply button should be
+    // disabled.
+    virtual BOOL sendUpdate() { return TRUE; }
+
+    typedef std::vector<std::string> strings_t;
+    //typedef std::vector<U32> integers_t;
+    void sendEstateOwnerMessage(
+                     LLMessageSystem* msg,
+                     const std::string& request,
+                     const LLUUID& invoice,
+                     const strings_t& strings);
+
+
+    // member data
+    LLHost mHost;
 };
 
 /////////////////////////////////////////////////////////////////////////////
@@ -180,30 +180,30 @@ class LLPanelRegionInfo : public LLPanel
 
 class LLPanelRegionGeneralInfo : public LLPanelRegionInfo
 {
-	
+
 public:
-	LLPanelRegionGeneralInfo()
-		:	LLPanelRegionInfo()	{}
-	~LLPanelRegionGeneralInfo() {}
-	
-	bool refreshFromRegion(LLViewerRegion* region) override;
-	
-	BOOL postBuild() override;
-	
-	void onBtnSet();
-	void setObjBonusFactor(F32 object_bonus_factor) {mObjBonusFactor = object_bonus_factor;}
+    LLPanelRegionGeneralInfo()
+        :   LLPanelRegionInfo() {}
+    ~LLPanelRegionGeneralInfo() {}
+
+    bool refreshFromRegion(LLViewerRegion* region) override;
+
+    BOOL postBuild() override;
+
+    void onBtnSet();
+    void setObjBonusFactor(F32 object_bonus_factor) {mObjBonusFactor = object_bonus_factor;}
 
 protected:
-	BOOL sendUpdate() override;
-	void onClickKick();
-	void onKickCommit(const uuid_vec_t& ids);
-	static void onClickKickAll(void* userdata);
-	bool onKickAllCommit(const LLSD& notification, const LLSD& response);
-	static void onClickMessage(void* userdata);
-	bool onMessageCommit(const LLSD& notification, const LLSD& response);
-	bool onChangeObjectBonus(const LLSD& notification, const LLSD& response);
+    BOOL sendUpdate() override;
+    void onClickKick();
+    void onKickCommit(const uuid_vec_t& ids);
+    static void onClickKickAll(void* userdata);
+    bool onKickAllCommit(const LLSD& notification, const LLSD& response);
+    static void onClickMessage(void* userdata);
+    bool onMessageCommit(const LLSD& notification, const LLSD& response);
+    bool onChangeObjectBonus(const LLSD& notification, const LLSD& response);
 
-	F32 mObjBonusFactor;
+    F32 mObjBonusFactor;
 
 };
 
@@ -212,70 +212,70 @@ class LLPanelRegionGeneralInfo : public LLPanelRegionInfo
 class LLPanelRegionDebugInfo : public LLPanelRegionInfo
 {
 public:
-	LLPanelRegionDebugInfo()
-		:	LLPanelRegionInfo(), mTargetAvatar() {}
-	~LLPanelRegionDebugInfo() {}
-
-	BOOL postBuild() override;
-	
-	bool refreshFromRegion(LLViewerRegion* region) override;
-	
+    LLPanelRegionDebugInfo()
+        :   LLPanelRegionInfo(), mTargetAvatar() {}
+    ~LLPanelRegionDebugInfo() {}
+
+    BOOL postBuild() override;
+
+    bool refreshFromRegion(LLViewerRegion* region) override;
+
 protected:
-	BOOL sendUpdate() override;
-
-	void onClickChooseAvatar();
-	void callbackAvatarID(const uuid_vec_t& ids, const std::vector<LLAvatarName> names);
-	static void onClickReturn(void *);
-	bool callbackReturn(const LLSD& notification, const LLSD& response);
-	static void onClickTopColliders(void*);
-	static void onClickTopScripts(void*);
-	static void onClickRestart(void* data);
-	bool callbackRestart(const LLSD& notification, const LLSD& response);
-	static void onClickCancelRestart(void* data);
-	static void onClickDebugConsole(void* data);
-	
+    BOOL sendUpdate() override;
+
+    void onClickChooseAvatar();
+    void callbackAvatarID(const uuid_vec_t& ids, const std::vector<LLAvatarName> names);
+    static void onClickReturn(void *);
+    bool callbackReturn(const LLSD& notification, const LLSD& response);
+    static void onClickTopColliders(void*);
+    static void onClickTopScripts(void*);
+    static void onClickRestart(void* data);
+    bool callbackRestart(const LLSD& notification, const LLSD& response);
+    static void onClickCancelRestart(void* data);
+    static void onClickDebugConsole(void* data);
+
 private:
-	LLUUID mTargetAvatar;
+    LLUUID mTargetAvatar;
 };
 
 /////////////////////////////////////////////////////////////////////////////
 
 class LLPanelRegionTerrainInfo : public LLPanelRegionInfo
 {
-	LOG_CLASS(LLPanelRegionTerrainInfo);
+    LOG_CLASS(LLPanelRegionTerrainInfo);
 
 public:
-	LLPanelRegionTerrainInfo();
-	~LLPanelRegionTerrainInfo() {}
-	
-	BOOL postBuild() override;
-	
+    LLPanelRegionTerrainInfo();
+    ~LLPanelRegionTerrainInfo() {}
+
+    BOOL postBuild() override;
+
     bool refreshFromRegion(LLViewerRegion* region) override;                // refresh local settings from region update from simulator
-	void setEnvControls(bool available);									// Whether environment settings are available for this region
+    void setEnvControls(bool available);                                    // Whether environment settings are available for this region
 
     bool validateTextureSizes();
     bool validateMaterials();
-	BOOL validateTextureHeights();
+    BOOL validateTextureHeights();
+
+    //static void onChangeAnything(LLUICtrl* ctrl, void* userData);         // callback for any change, to enable commit button
 
-	//static void onChangeAnything(LLUICtrl* ctrl, void* userData);			// callback for any change, to enable commit button
-	
     void onSelectMaterialType();
     void updateForMaterialType();
 
-	static void onClickDownloadRaw(void*);
-	static void onClickDownloadRawCallback(const std::vector<std::string>& filenames, void* data);
-	static void onClickUploadRaw(void*);
-	static void onClickUploadRawCallback(void* data, const std::vector<std::string>& filenames);
-	static void onClickBakeTerrain(void*);
-	bool callbackBakeTerrain(const LLSD& notification, const LLSD& response);
-	bool callbackTextureHeights(const LLSD& notification, const LLSD& response);
+    static void onClickDownloadRaw(void*);
+    static void onClickDownloadRawCallback(const std::vector<std::string>& filenames, void* data);
+    static void onClickUploadRaw(void*);
+    static void onClickUploadRawCallback(void* data, const std::vector<std::string>& filenames);
+    static void onClickBakeTerrain(void*);
+    bool callbackBakeTerrain(const LLSD& notification, const LLSD& response);
+    bool callbackTextureHeights(const LLSD& notification, const LLSD& response);
 
 protected:
-	BOOL sendUpdate() override;
+    BOOL sendUpdate() override;
 
 private:
-	bool mConfirmedTextureHeights;
-	bool mAskedTextureHeights;
+    bool mConfirmedTextureHeights;
+    bool mAskedTextureHeights;
     LLCheckBoxCtrl* mMaterialTypeCtrl = nullptr;
     LLTextureCtrl* mTextureDetailCtrl[LLTerrainMaterials::ASSET_COUNT];
     LLTextureCtrl* mMaterialDetailCtrl[LLTerrainMaterials::ASSET_COUNT];
@@ -288,59 +288,59 @@ class LLPanelRegionTerrainInfo : public LLPanelRegionInfo
 class LLPanelEstateInfo : public LLPanelRegionInfo
 {
 public:
-	static void initDispatch(LLDispatcher& dispatch);
-	
-	void onChangeFixedSun();
-	void onChangeUseGlobalTime();
-	void onChangeAccessOverride();
-	
-	void onClickEditSky();
-	void onClickEditSkyHelp();	
-	void onClickEditDayCycle();
-	void onClickEditDayCycleHelp();
-
-	void onClickKickUser();
-
-
-	bool kickUserConfirm(const LLSD& notification, const LLSD& response);
-
-	void onKickUserCommit(const uuid_vec_t& ids);
-	static void onClickMessageEstate(void* data);
-	bool onMessageCommit(const LLSD& notification, const LLSD& response);
-	
-	LLPanelEstateInfo();
-	~LLPanelEstateInfo() {}
-	
-	void updateControls(LLViewerRegion* region);
-	
-	static void updateEstateName(const std::string& name);
-	static void updateEstateOwnerName(const std::string& name);
-
-	bool refreshFromRegion(LLViewerRegion* region) override;
-	bool estateUpdate(LLMessageSystem* msg) override;
-	
-	BOOL postBuild() override;
-	void updateChild(LLUICtrl* child_ctrl) override;
-	void refresh() override;
-
-	void refreshFromEstate();
-	
-	static bool isLindenEstate();
-	
-	const std::string getOwnerName() const;
-	void setOwnerName(const std::string& name);
+    static void initDispatch(LLDispatcher& dispatch);
+
+    void onChangeFixedSun();
+    void onChangeUseGlobalTime();
+    void onChangeAccessOverride();
+
+    void onClickEditSky();
+    void onClickEditSkyHelp();
+    void onClickEditDayCycle();
+    void onClickEditDayCycleHelp();
+
+    void onClickKickUser();
+
+
+    bool kickUserConfirm(const LLSD& notification, const LLSD& response);
+
+    void onKickUserCommit(const uuid_vec_t& ids);
+    static void onClickMessageEstate(void* data);
+    bool onMessageCommit(const LLSD& notification, const LLSD& response);
+
+    LLPanelEstateInfo();
+    ~LLPanelEstateInfo() {}
+
+    void updateControls(LLViewerRegion* region);
+
+    static void updateEstateName(const std::string& name);
+    static void updateEstateOwnerName(const std::string& name);
+
+    bool refreshFromRegion(LLViewerRegion* region) override;
+    bool estateUpdate(LLMessageSystem* msg) override;
+
+    BOOL postBuild() override;
+    void updateChild(LLUICtrl* child_ctrl) override;
+    void refresh() override;
+
+    void refreshFromEstate();
+
+    static bool isLindenEstate();
+
+    const std::string getOwnerName() const;
+    void setOwnerName(const std::string& name);
 
 protected:
-	BOOL sendUpdate() override;
-	// confirmation dialog callback
-	bool callbackChangeLindenEstate(const LLSD& notification, const LLSD& response);
+    BOOL sendUpdate() override;
+    // confirmation dialog callback
+    bool callbackChangeLindenEstate(const LLSD& notification, const LLSD& response);
+
+    void commitEstateAccess();
+    void commitEstateManagers();
 
-	void commitEstateAccess();
-	void commitEstateManagers();
-	
-	BOOL checkSunHourSlider(LLUICtrl* child_ctrl);
+    BOOL checkSunHourSlider(LLUICtrl* child_ctrl);
 
-	U32 mEstateID;
+    U32 mEstateID;
 };
 
 /////////////////////////////////////////////////////////////////////////////
@@ -348,59 +348,59 @@ class LLPanelEstateInfo : public LLPanelRegionInfo
 class LLPanelEstateCovenant : public LLPanelRegionInfo
 {
 public:
-	LLPanelEstateCovenant();
-	~LLPanelEstateCovenant() {}
-	
-	BOOL postBuild() override;
-	void updateChild(LLUICtrl* child_ctrl) override;
-	bool refreshFromRegion(LLViewerRegion* region) override;
-	bool estateUpdate(LLMessageSystem* msg) override;
-
-	// LLView overrides
-	BOOL handleDragAndDrop(S32 x, S32 y, MASK mask,
-						   BOOL drop, EDragAndDropType cargo_type,
-						   void *cargo_data, EAcceptance *accept,
-						   std::string& tooltip_msg) override;
-	static bool confirmChangeCovenantCallback(const LLSD& notification, const LLSD& response);
-	static void resetCovenantID(void* userdata);
-	static bool confirmResetCovenantCallback(const LLSD& notification, const LLSD& response);
-	void sendChangeCovenantID(const LLUUID &asset_id);
-	void loadInvItem(LLInventoryItem *itemp);
-	static void onLoadComplete(const LLUUID& asset_uuid,
-							   LLAssetType::EType type,
-							   void* user_data, S32 status, LLExtStat ext_status);
-
-	// Accessor functions
-	static void updateCovenantText(const std::string& string, const LLUUID& asset_id);
-	static void updateEstateName(const std::string& name);
-	static void updateLastModified(const std::string& text);
-	static void updateEstateOwnerName(const std::string& name);
-
-	const LLUUID& getCovenantID() const { return mCovenantID; }
-	void setCovenantID(const LLUUID& id) { mCovenantID = id; }
-	std::string getEstateName() const;
-	void setEstateName(const std::string& name);
-	std::string getOwnerName() const;
-	void setOwnerName(const std::string& name);
-	void setCovenantTextEditor(const std::string& text);
-
-	typedef enum e_asset_status
-	{
-		ASSET_ERROR,
-		ASSET_UNLOADED,
-		ASSET_LOADING,
-		ASSET_LOADED
-	} EAssetStatus;
+    LLPanelEstateCovenant();
+    ~LLPanelEstateCovenant() {}
+
+    BOOL postBuild() override;
+    void updateChild(LLUICtrl* child_ctrl) override;
+    bool refreshFromRegion(LLViewerRegion* region) override;
+    bool estateUpdate(LLMessageSystem* msg) override;
+
+    // LLView overrides
+    BOOL handleDragAndDrop(S32 x, S32 y, MASK mask,
+                           BOOL drop, EDragAndDropType cargo_type,
+                           void *cargo_data, EAcceptance *accept,
+                           std::string& tooltip_msg) override;
+    static bool confirmChangeCovenantCallback(const LLSD& notification, const LLSD& response);
+    static void resetCovenantID(void* userdata);
+    static bool confirmResetCovenantCallback(const LLSD& notification, const LLSD& response);
+    void sendChangeCovenantID(const LLUUID &asset_id);
+    void loadInvItem(LLInventoryItem *itemp);
+    static void onLoadComplete(const LLUUID& asset_uuid,
+                               LLAssetType::EType type,
+                               void* user_data, S32 status, LLExtStat ext_status);
+
+    // Accessor functions
+    static void updateCovenantText(const std::string& string, const LLUUID& asset_id);
+    static void updateEstateName(const std::string& name);
+    static void updateLastModified(const std::string& text);
+    static void updateEstateOwnerName(const std::string& name);
+
+    const LLUUID& getCovenantID() const { return mCovenantID; }
+    void setCovenantID(const LLUUID& id) { mCovenantID = id; }
+    std::string getEstateName() const;
+    void setEstateName(const std::string& name);
+    std::string getOwnerName() const;
+    void setOwnerName(const std::string& name);
+    void setCovenantTextEditor(const std::string& text);
+
+    typedef enum e_asset_status
+    {
+        ASSET_ERROR,
+        ASSET_UNLOADED,
+        ASSET_LOADING,
+        ASSET_LOADED
+    } EAssetStatus;
 
 protected:
-	BOOL sendUpdate() override;
-	LLTextBox*				mEstateNameText;
-	LLTextBox*				mEstateOwnerText;
-	LLTextBox*				mLastModifiedText;
-	// CovenantID from sim
-	LLUUID					mCovenantID;
-	LLViewerTextEditor*		mEditor;
-	EAssetStatus			mAssetStatus;
+    BOOL sendUpdate() override;
+    LLTextBox*              mEstateNameText;
+    LLTextBox*              mEstateOwnerText;
+    LLTextBox*              mLastModifiedText;
+    // CovenantID from sim
+    LLUUID                  mCovenantID;
+    LLViewerTextEditor*     mEditor;
+    EAssetStatus            mAssetStatus;
 };
 
 /////////////////////////////////////////////////////////////////////////////
@@ -411,98 +411,98 @@ class LLPanelRegionExperiences : public LLPanelRegionInfo
     LOG_CLASS(LLPanelRegionExperiences);
 
 public:
-	LLPanelRegionExperiences(){}
-	BOOL postBuild() override;
-	
-	static bool experienceCoreConfirm(const LLSD& notification, const LLSD& response);
-	static void sendEstateExperienceDelta(U32 flags, const LLUUID& agent_id);
+    LLPanelRegionExperiences(){}
+    BOOL postBuild() override;
 
-	static void infoCallback(LLHandle<LLPanelRegionExperiences> handle, const LLSD& content);
-	bool refreshFromRegion(LLViewerRegion* region) override;
-	void sendPurchaseRequest()const;
-	void processResponse( const LLSD& content );
+    static bool experienceCoreConfirm(const LLSD& notification, const LLSD& response);
+    static void sendEstateExperienceDelta(U32 flags, const LLUUID& agent_id);
+
+    static void infoCallback(LLHandle<LLPanelRegionExperiences> handle, const LLSD& content);
+    bool refreshFromRegion(LLViewerRegion* region) override;
+    void sendPurchaseRequest()const;
+    void processResponse( const LLSD& content );
 
 protected:
-	BOOL sendUpdate() override;
+    BOOL sendUpdate() override;
 
 private:
-	void refreshRegionExperiences();
+    void refreshRegionExperiences();
 
     static std::string regionCapabilityQuery(LLViewerRegion* region, const std::string &cap);
 
-	LLPanelExperienceListEditor* setupList(const char* control_name, U32 add_id, U32 remove_id);
-	static LLSD addIds( LLPanelExperienceListEditor* panel );
+    LLPanelExperienceListEditor* setupList(const char* control_name, U32 add_id, U32 remove_id);
+    static LLSD addIds( LLPanelExperienceListEditor* panel );
 
-	void itemChanged(U32 event_type, const LLUUID& id);
+    void itemChanged(U32 event_type, const LLUUID& id);
 
-	LLPanelExperienceListEditor* mTrusted;
-	LLPanelExperienceListEditor* mAllowed;
-	LLPanelExperienceListEditor* mBlocked;
-	LLUUID mDefaultExperience;
+    LLPanelExperienceListEditor* mTrusted;
+    LLPanelExperienceListEditor* mAllowed;
+    LLPanelExperienceListEditor* mBlocked;
+    LLUUID mDefaultExperience;
 };
 
 
 class LLPanelEstateAccess : public LLPanelRegionInfo
 {
-	LOG_CLASS(LLPanelEstateAccess);
+    LOG_CLASS(LLPanelEstateAccess);
 
 public:
-	LLPanelEstateAccess();
+    LLPanelEstateAccess();
 
-	BOOL postBuild() override;
-	void updateChild(LLUICtrl* child_ctrl) override;
+    BOOL postBuild() override;
+    void updateChild(LLUICtrl* child_ctrl) override;
 
-	void updateControls(LLViewerRegion* region);
-	void updateLists();
+    void updateControls(LLViewerRegion* region);
+    void updateLists();
 
-	void setPendingUpdate(bool pending) { mPendingUpdate = pending; }
-	bool getPendingUpdate() { return mPendingUpdate; }
+    void setPendingUpdate(bool pending) { mPendingUpdate = pending; }
+    bool getPendingUpdate() { return mPendingUpdate; }
 
-	bool refreshFromRegion(LLViewerRegion* region) override;
+    bool refreshFromRegion(LLViewerRegion* region) override;
 
 private:
-	void onClickAddAllowedAgent();
-	void onClickRemoveAllowedAgent();
-	void onClickCopyAllowedList();
-	void onClickAddAllowedGroup();
-	void onClickRemoveAllowedGroup();
-	void onClickCopyAllowedGroupList();
-	void onClickAddBannedAgent();
-	void onClickRemoveBannedAgent();
+    void onClickAddAllowedAgent();
+    void onClickRemoveAllowedAgent();
+    void onClickCopyAllowedList();
+    void onClickAddAllowedGroup();
+    void onClickRemoveAllowedGroup();
+    void onClickCopyAllowedGroupList();
+    void onClickAddBannedAgent();
+    void onClickRemoveBannedAgent();
     void onClickCopyBannedList();
-	void onClickAddEstateManager();
-	void onClickRemoveEstateManager();
-	void onAllowedSearchEdit(const std::string& search_string);
-	void onAllowedGroupsSearchEdit(const std::string& search_string);
-	void onBannedSearchEdit(const std::string& search_string);
-	
-	// Group picker callback is different, can't use core methods below
-	bool addAllowedGroup(const LLSD& notification, const LLSD& response);
-	void addAllowedGroup2(LLUUID id);
-
-	// Core methods for all above add/remove button clicks
-	static void accessAddCore(U32 operation_flag, const std::string& dialog_name);
-	static bool accessAddCore2(const LLSD& notification, const LLSD& response);
-	static void accessAddCore3(const uuid_vec_t& ids, std::vector<LLAvatarName> names, void* data);
-
-	static void accessRemoveCore(U32 operation_flag, const std::string& dialog_name, const std::string& list_ctrl_name);
-	static bool accessRemoveCore2(const LLSD& notification, const LLSD& response);
-
-	// used for both add and remove operations
-	static bool accessCoreConfirm(const LLSD& notification, const LLSD& response);
-
-	// Send the actual EstateOwnerRequest "estateaccessdelta" message
+    void onClickAddEstateManager();
+    void onClickRemoveEstateManager();
+    void onAllowedSearchEdit(const std::string& search_string);
+    void onAllowedGroupsSearchEdit(const std::string& search_string);
+    void onBannedSearchEdit(const std::string& search_string);
+
+    // Group picker callback is different, can't use core methods below
+    bool addAllowedGroup(const LLSD& notification, const LLSD& response);
+    void addAllowedGroup2(LLUUID id);
+
+    // Core methods for all above add/remove button clicks
+    static void accessAddCore(U32 operation_flag, const std::string& dialog_name);
+    static bool accessAddCore2(const LLSD& notification, const LLSD& response);
+    static void accessAddCore3(const uuid_vec_t& ids, std::vector<LLAvatarName> names, void* data);
+
+    static void accessRemoveCore(U32 operation_flag, const std::string& dialog_name, const std::string& list_ctrl_name);
+    static bool accessRemoveCore2(const LLSD& notification, const LLSD& response);
+
+    // used for both add and remove operations
+    static bool accessCoreConfirm(const LLSD& notification, const LLSD& response);
+
+    // Send the actual EstateOwnerRequest "estateaccessdelta" message
 public:
-	static void sendEstateAccessDelta(U32 flags, const LLUUID& agent_id);
+    static void sendEstateAccessDelta(U32 flags, const LLUUID& agent_id);
 
 private:
-	static void requestEstateGetAccessCoro(std::string url);
+    static void requestEstateGetAccessCoro(std::string url);
 
-	void searchAgent(LLNameListCtrl* listCtrl, const std::string& search_string);
-	void copyListToClipboard(std::string list_name);
+    void searchAgent(LLNameListCtrl* listCtrl, const std::string& search_string);
+    void copyListToClipboard(std::string list_name);
 
-	bool mPendingUpdate;
-	BOOL mCtrlsEnabled;
+    bool mPendingUpdate;
+    BOOL mCtrlsEnabled;
 };
 
 #endif
diff --git a/indra/newview/llgltfmaterialpreviewmgr.cpp b/indra/newview/llgltfmaterialpreviewmgr.cpp
index 938374b0e6dccb46025350714a81d9fe92ce8bd8..86a5c077e3b6db0d7ba9063fe612e577735bb16e 100644
--- a/indra/newview/llgltfmaterialpreviewmgr.cpp
+++ b/indra/newview/llgltfmaterialpreviewmgr.cpp
@@ -302,12 +302,12 @@ PreviewSphere create_preview_sphere(LLPointer<LLFetchedGLTFMaterial>& material,
     LLStrider<LLVector2> texcoords;
     LLStrider<LLColor4U> colors;
     LLStrider<LLVector4a> tangents;
-	buf->getIndexStrider(indices);
-	buf->getVertexStrider(positions);
-	buf->getNormalStrider(normals);
-	buf->getTexCoord0Strider(texcoords);
-	buf->getColorStrider(colors);
-	buf->getTangentStrider(tangents);
+    buf->getIndexStrider(indices);
+    buf->getVertexStrider(positions);
+    buf->getNormalStrider(normals);
+    buf->getTexCoord0Strider(texcoords);
+    buf->getColorStrider(colors);
+    buf->getTangentStrider(tangents);
     U32 index_offset = 0;
     U32 vertex_offset = 0;
     for (const LLVolumeFace& face : volume->getVolumeFaces())
@@ -427,7 +427,7 @@ BOOL LLGLTFPreviewTexture::render()
 
     glClearColor(0, 0, 0, 0);
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-    
+
     LLGLDepthTest(GL_FALSE);
     LLGLDisable stencil(GL_STENCIL_TEST);
     LLGLDisable scissor(GL_SCISSOR_TEST);
@@ -525,27 +525,27 @@ BOOL LLGLTFPreviewTexture::render()
     LLVertexBuffer::unbind();
     gPipeline.generateGlow(&gPipeline.mPostMap);
     gPipeline.combineGlow(&gPipeline.mPostMap, &screen);
-	gPipeline.renderDoF(&screen, &gPipeline.mPostMap);
-	gPipeline.applyFXAA(&gPipeline.mPostMap, &screen);
+    gPipeline.renderDoF(&screen, &gPipeline.mPostMap);
+    gPipeline.applyFXAA(&gPipeline.mPostMap, &screen);
 
     // *HACK: Restore mExposureMap (it will be consumed by generateExposure next frame)
     gPipeline.mExposureMap.swapFBORefs(gPipeline.mLastExposure);
 
     // Final render
 
-	gDeferredPostNoDoFProgram.bind();
+    gDeferredPostNoDoFProgram.bind();
 
-	// From LLPipeline::renderFinalize: "Whatever is last in the above post processing chain should _always_ be rendered directly here.  If not, expect problems."
-	gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, &screen);
-	gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, mBoundTarget, true);
+    // From LLPipeline::renderFinalize: "Whatever is last in the above post processing chain should _always_ be rendered directly here.  If not, expect problems."
+    gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, &screen);
+    gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, mBoundTarget, true);
 
-	{
-		LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
-		gPipeline.mScreenTriangleVB->setBuffer();
-		gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-	}
+    {
+        LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
+        gPipeline.mScreenTriangleVB->setBuffer();
+        gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    }
 
-	gDeferredPostNoDoFProgram.unbind();
+    gDeferredPostNoDoFProgram.unbind();
 
     // Clean up
     gPipeline.setupHWLights();
diff --git a/indra/newview/llheroprobemanager.cpp b/indra/newview/llheroprobemanager.cpp
index 63561a531d28bf68441c5ec055373d90126c5d3d..978cca61e3df29b3cc76b946cc80ceca8e49d09a 100644
--- a/indra/newview/llheroprobemanager.cpp
+++ b/indra/newview/llheroprobemanager.cpp
@@ -66,7 +66,7 @@ LLHeroProbeManager::LLHeroProbeManager()
 
 LLHeroProbeManager::~LLHeroProbeManager()
 {
-	cleanup();
+    cleanup();
 
     mHeroVOList.clear();
     mNearestHero = nullptr;
@@ -131,7 +131,7 @@ void LLHeroProbeManager::update()
                 float center_distance = cameraDirection * (vo->getPositionAgent() - camera_pos);
 
                 if (distance > LLViewerCamera::instance().getFar())
-					continue;
+                    continue;
 
                 LLVector4a center;
                 center.load3(vo->getPositionAgent().mV);
@@ -143,18 +143,18 @@ void LLHeroProbeManager::update()
 
                 if (distance < last_distance && center_distance < camera_center_distance && visible)
                 {
-					probe_present = true;
-					mNearestHero = vo;
-					last_distance = distance;
+                    probe_present = true;
+                    mNearestHero = vo;
+                    last_distance = distance;
                     camera_center_distance = center_distance;
-				}
+                }
             }
             else
             {
                 unregisterViewerObject(vo);
             }
         }
-        
+
         // Don't even try to do anything if we didn't find a single mirror present.
         if (!probe_present)
             return;
@@ -163,7 +163,7 @@ void LLHeroProbeManager::update()
         {
             LLVector3 hero_pos = mNearestHero->getPositionAgent();
             LLVector3 face_normal = LLVector3(0, 0, 1);
-            
+
             face_normal *= mNearestHero->mDrawable->getWorldRotation();
             face_normal.normalize();
 
@@ -181,8 +181,8 @@ void LLHeroProbeManager::update()
             // Detect visible faces of a cube based on camera direction and distance
 
             // Define the cube faces
-            static LLVector3 cubeFaces[6] = { 
-                LLVector3(1, 0, 0), 
+            static LLVector3 cubeFaces[6] = {
+                LLVector3(1, 0, 0),
                 LLVector3(-1, 0, 0),
                 LLVector3(0, 1, 0),
                 LLVector3(0, -1, 0),
@@ -194,7 +194,7 @@ void LLHeroProbeManager::update()
             for (int i = 0; i < 6; i++)
             {
                 float cube_facing = fmax(-1, fmin(1.0f, cameraDirection * cubeFaces[i])) * 0.6 + 0.4;
-                    
+
                 float updateRate;
                 if (cube_facing < 0.1f)
                 {
@@ -209,18 +209,18 @@ void LLHeroProbeManager::update()
             }
         }
         else
-        { 
+        {
             mNearestHero = nullptr;
         }
-            
+
         mHeroProbeStrength = 1;
     }
     else
     {
         probe_pos.load3(camera_pos.mV);
     }
-    
-    
+
+
     static LLCachedControl<S32> sDetail(gSavedSettings, "RenderHeroReflectionProbeDetail", -1);
     static LLCachedControl<S32> sLevel(gSavedSettings, "RenderHeroReflectionProbeLevel", 3);
 
@@ -229,9 +229,9 @@ void LLHeroProbeManager::update()
         LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("hpmu - realtime");
         // Probe 0 is always our mirror probe.
         mProbes[0]->mOrigin = probe_pos;
-        
+
         bool radiance_pass = gPipeline.mReflectionMapManager.isRadiancePass();
-        
+
         gPipeline.mReflectionMapManager.mRadiancePass = true;
         mRenderingMirror = true;
 
@@ -250,19 +250,19 @@ void LLHeroProbeManager::update()
             generateRadiance(mProbes[j]);
         }
         mRenderingMirror = false;
-        
+
         gPipeline.mReflectionMapManager.mRadiancePass = radiance_pass;
 
         mProbes[0]->mViewerObject = mNearestHero;
         mProbes[0]->autoAdjustOrigin();
     }
-    
+
     mCurrentProbeUpdateFrame++;
 }
 
 // Do the reflection map update render passes.
 // For every 12 calls of this function, one complete reflection probe radiance map and irradiance map is generated
-// First six passes render the scene with direct lighting only into a scratch space cube map at the end of the cube map array and generate 
+// First six passes render the scene with direct lighting only into a scratch space cube map at the end of the cube map array and generate
 // a simple mip chain (not convolution filter).
 // At the end of these passes, an irradiance map is generated for this probe and placed into the irradiance cube map array at the index for this probe
 // The next six passes render the scene with both radiance and irradiance into the same scratch space cube map and generate a simple mip chain.
@@ -274,11 +274,11 @@ void LLHeroProbeManager::updateProbeFace(LLReflectionMap* probe, U32 face, bool
     gPipeline.mRT = &gPipeline.mHeroProbeRT;
 
     probe->update(mRenderTarget.getWidth(), face, is_dynamic, near_clip);
-    
+
     gPipeline.mRT = &gPipeline.mMainRT;
 
     S32 sourceIdx = mReflectionProbeCount;
-    
+
     // Unlike the reflectionmap manager, all probes are considered "realtime" for hero probes.
     sourceIdx += 1;
 
@@ -286,7 +286,7 @@ void LLHeroProbeManager::updateProbeFace(LLReflectionMap* probe, U32 face, bool
     LLGLDepthTest depth(GL_FALSE, GL_FALSE);
     LLGLDisable cull(GL_CULL_FACE);
     LLGLDisable blend(GL_BLEND);
-    
+
     // downsample to placeholder map
     {
         gGL.matrixMode(gGL.MM_MODELVIEW);
@@ -352,14 +352,14 @@ void LLHeroProbeManager::updateProbeFace(LLReflectionMap* probe, U32 face, bool
             }
 
             gGL.getTexUnit(depthChannel)->bind(depth_rt, true);
-            
+
             gReflectionMipProgram.uniform1f(resScale, 1.f / (mProbeResolution * 2));
             gReflectionMipProgram.uniform1f(znear, probe->getNearClip());
             gReflectionMipProgram.uniform1f(zfar, MAX_FAR_CLIP);
-            
+
             gPipeline.mScreenTriangleVB->setBuffer();
             gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-            
+
             res /= 2;
 
             S32 mip = i - (mMipChain.size() - mips);
@@ -460,12 +460,12 @@ void LLHeroProbeManager::updateUniforms()
     }
 
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
-    
+
     LLMatrix4a modelview = gGLModelView;
     LLVector4a oa; // scratch space for transformed origin
     oa.set(0, 0, 0, 0);
     mHeroData.heroProbeCount = 1;
-    
+
     if (mNearestHero != nullptr && !mNearestHero->isDead())
     {
         if (mNearestHero->getReflectionProbeIsBox())
@@ -477,18 +477,18 @@ void LLHeroProbeManager::updateUniforms()
         {
             mProbes[0]->mRadius = mNearestHero->getScale().mV[0] * 0.5f;
         }
-        
+
         modelview.affineTransform(mProbes[0]->mOrigin, oa);
         mHeroData.heroShape = 0;
         if (!mProbes[0]->getBox(mHeroData.heroBox))
         {
             mHeroData.heroShape = 1;
         }
-        
+
         mHeroData.heroSphere.set(oa.getF32ptr());
         mHeroData.heroSphere.mV[3] = mProbes[0]->mRadius;
     }
-    
+
     mHeroData.heroMipCount = mMipChain.size();
 }
 
@@ -537,14 +537,14 @@ void LLHeroProbeManager::initReflectionMaps()
         llassert(mProbes[0] == mDefaultProbe);
 
         // For hero probes, we treat this as the main mirror probe.
-        
+
         mDefaultProbe->mCubeIndex = 0;
         mDefaultProbe->mCubeArray = mTexture;
         mDefaultProbe->mDistance  = gSavedSettings.getF32("RenderHeroProbeDistance");
         mDefaultProbe->mRadius = 4096.f;
         mDefaultProbe->mProbeIndex = 0;
         touch_default_probe(mDefaultProbe);
-        
+
         mProbes.push_back(mDefaultProbe);
     }
 
@@ -555,9 +555,9 @@ void LLHeroProbeManager::initReflectionMaps()
         buff->allocateBuffer(4, 0);
 
         LLStrider<LLVector3> v;
-        
+
         buff->getVertexStrider(v);
-        
+
         v[0] = LLVector3(-1, -1, -1);
         v[1] = LLVector3(1, -1, -1);
         v[2] = LLVector3(-1, 1, -1);
@@ -569,8 +569,8 @@ void LLHeroProbeManager::initReflectionMaps()
     }
 }
 
-void LLHeroProbeManager::cleanup() 
-{ 
+void LLHeroProbeManager::cleanup()
+{
     mVertexBuffer = nullptr;
     mRenderTarget.release();
     mHeroRenderTarget.release();
@@ -582,7 +582,7 @@ void LLHeroProbeManager::cleanup()
     mProbes.clear();
 
     mReflectionMaps.clear();
-    
+
     mDefaultProbe = nullptr;
     mUpdatingProbe = nullptr;
     /*
@@ -618,7 +618,7 @@ bool LLHeroProbeManager::registerViewerObject(LLVOVolume* drawablep)
         mHeroVOList.push_back(drawablep);
         return true;
     }
-    
+
     return false;
 }
 
diff --git a/indra/newview/llimprocessing.cpp b/indra/newview/llimprocessing.cpp
index 9c4eeb1609b0eda86c4bd7dfdd3659d28d4ba1f6..f76d2fce11322cd27537469bdf51bb500d246e23 100644
--- a/indra/newview/llimprocessing.cpp
+++ b/indra/newview/llimprocessing.cpp
@@ -1,1903 +1,1903 @@
-/**
-* @file LLIMProcessing.cpp
-* @brief Container for Instant Messaging
-*
-* $LicenseInfo:firstyear=2001&license=viewerlgpl$
-* Second Life Viewer Source Code
-* Copyright (C) 2018, Linden Research, Inc.
-*
-* This library is free software; you can redistribute it and/or
-* modify it under the terms of the GNU Lesser General Public
-* License as published by the Free Software Foundation;
-* version 2.1 of the License only.
-*
-* This library is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this library; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
-*
-* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
-* $/LicenseInfo$
-*/
-
-#include "llviewerprecompiledheaders.h"
-
-#include "llimprocessing.h"
-
-#include "llagent.h"
-#include "llappviewer.h"
-#include "llavatarnamecache.h"
-#include "llfirstuse.h"
-#include "llfloaterreg.h"
-#include "llfloaterimnearbychat.h"
-#include "llimview.h"
-#include "llinventoryobserver.h"
-#include "llinventorymodel.h"
-#include "llmutelist.h"
-#include "llnotifications.h"
-#include "llnotificationsutil.h"
-#include "llnotificationmanager.h"
-#include "llpanelgroup.h"
-#include "llregex.h"
-#include "llregionhandle.h"
-#include "llsdserialize.h"
-#include "llslurl.h"
-#include "llstring.h"
-#include "lltoastnotifypanel.h"
-#include "lltrans.h"
-#include "llviewergenericmessage.h"
-#include "llviewerobjectlist.h"
-#include "llviewermessage.h"
-#include "llviewerwindow.h"
-#include "llviewerregion.h"
-#include "llvoavatarself.h"
-#include "llworld.h"
-// [RLVa:KB] - Checked: 2010-03-09 (RLVa-1.2.0a)
-#include "rlvactions.h"
-#include "rlvhelper.h"
-#include "rlvhandler.h"
-#include "rlvinventory.h"
-#include "rlvui.h"
-// [/RLVa:KB]
-
-#include "boost/lexical_cast.hpp"
-
-extern void on_new_message(const LLSD& msg);
-
-// Strip out "Resident" for display, but only if the message came from a user
-// (rather than a script)
-static std::string clean_name_from_im(const std::string& name, EInstantMessage type)
-{
-    switch (type)
-    {
-        case IM_NOTHING_SPECIAL:
-        case IM_MESSAGEBOX:
-        case IM_GROUP_INVITATION:
-        case IM_INVENTORY_OFFERED:
-        case IM_INVENTORY_ACCEPTED:
-        case IM_INVENTORY_DECLINED:
-        case IM_GROUP_VOTE:
-        case IM_GROUP_MESSAGE_DEPRECATED:
-            //IM_TASK_INVENTORY_OFFERED
-            //IM_TASK_INVENTORY_ACCEPTED
-            //IM_TASK_INVENTORY_DECLINED
-        case IM_NEW_USER_DEFAULT:
-        case IM_SESSION_INVITE:
-        case IM_SESSION_P2P_INVITE:
-        case IM_SESSION_GROUP_START:
-        case IM_SESSION_CONFERENCE_START:
-        case IM_SESSION_SEND:
-        case IM_SESSION_LEAVE:
-            //IM_FROM_TASK
-        case IM_DO_NOT_DISTURB_AUTO_RESPONSE:
-        case IM_CONSOLE_AND_CHAT_HISTORY:
-        case IM_LURE_USER:
-        case IM_LURE_ACCEPTED:
-        case IM_LURE_DECLINED:
-        case IM_GODLIKE_LURE_USER:
-        case IM_TELEPORT_REQUEST:
-        case IM_GROUP_ELECTION_DEPRECATED:
-            //IM_GOTO_URL
-            //IM_FROM_TASK_AS_ALERT
-        case IM_GROUP_NOTICE:
-        case IM_GROUP_NOTICE_INVENTORY_ACCEPTED:
-        case IM_GROUP_NOTICE_INVENTORY_DECLINED:
-        case IM_GROUP_INVITATION_ACCEPT:
-        case IM_GROUP_INVITATION_DECLINE:
-        case IM_GROUP_NOTICE_REQUESTED:
-        case IM_FRIENDSHIP_OFFERED:
-        case IM_FRIENDSHIP_ACCEPTED:
-        case IM_FRIENDSHIP_DECLINED_DEPRECATED:
-            //IM_TYPING_START
-            //IM_TYPING_STOP
-            return LLCacheName::cleanFullName(name);
-        default:
-            return name;
-    }
-}
-
-static std::string clean_name_from_task_im(const std::string& msg,
-    BOOL from_group)
-{
-    boost::smatch match;
-    static const boost::regex returned_exp(
-        "(.*been returned to your inventory lost and found folder by )(.+)( (from|near).*)");
-    if (ll_regex_match(msg, match, returned_exp))
-    {
-        // match objects are 1-based for groups
-        std::string final = match[1].str();
-        std::string name = match[2].str();
-        // Don't try to clean up group names
-        if (!from_group)
-        {
-            final += LLCacheName::buildUsername(name);
-        }
-        final += match[3].str();
-        return final;
-    }
-    return msg;
-}
-
-const std::string NOT_ONLINE_MSG("User not online - message will be stored and delivered later.");
-const std::string NOT_ONLINE_INVENTORY("User not online - inventory has been saved.");
-void translate_if_needed(std::string& message)
-{
-    if (message == NOT_ONLINE_MSG)
-    {
-        message = LLTrans::getString("not_online_msg");
-    }
-    else if (message == NOT_ONLINE_INVENTORY)
-    {
-        message = LLTrans::getString("not_online_inventory");
-    }
-}
-
-class LLPostponedIMSystemTipNotification : public LLPostponedNotification
-{
-protected:
-    /* virtual */
-    void modifyNotificationParams()
-    {
-        LLSD payload = mParams.payload;
-        payload["SESSION_NAME"] = mName;
-        mParams.payload = payload;
-    }
-};
-
-class LLPostponedOfferNotification : public LLPostponedNotification
-{
-protected:
-    /* virtual */
-    void modifyNotificationParams()
-    {
-        LLSD substitutions = mParams.substitutions;
-        substitutions["NAME"] = mName;
-        mParams.substitutions = substitutions;
-    }
-};
-
-void inventory_offer_handler(LLOfferInfo* info)
-{
-    // If muted, don't even go through the messaging stuff.  Just curtail the offer here.
-    // Passing in a null UUID handles the case of where you have muted one of your own objects by_name.
-    // The solution for STORM-1297 seems to handle the cases where the object is owned by someone else.
-    if (LLMuteList::getInstance()->isMuted(info->mFromID, info->mFromName) ||
-        LLMuteList::getInstance()->isMuted(LLUUID::null, info->mFromName))
-    {
-        info->forceResponse(IOR_MUTE);
-        return;
-    }
-
-    // Strip any SLURL from the message display. (DEV-2754)
-    std::string msg = info->mDesc;
-	size_t indx = msg.find(" ( http://slurl.com/secondlife/");
-    if (indx == std::string::npos)
-    {
-        // try to find new slurl host
-        indx = msg.find(" ( http://maps.secondlife.com/secondlife/");
-    }
-    if (indx != std::string::npos && indx >= 0)
-    {
-        LLStringUtil::truncate(msg, indx);
-    }
-
-    // Avoid the Accept/Discard dialog if the user so desires. JC
-    bool bAutoAccept(false);
-    if ((gSavedSettings.getBOOL("AutoAcceptNewInventory"))
-        && ((!rlv_handler_t::isEnabled()) || (!RlvInventory::instance().isGiveToRLVOffer(*info))))
-    {
-		bAutoAccept = true;
-		if (info->mType != LLAssetType::AT_NOTECARD
-			|| info->mType != LLAssetType::AT_LANDMARK
-			|| info->mType != LLAssetType::AT_TEXTURE)
-		{
-			LLSD args;
-			args["NAME"] = LLSLURL(info->mFromGroup ? "group" : "agent", info->mFromID, "about").getSLURLString();
-			if (info->mFromObject)
-				args["ITEM"] = msg;
-			else
-			{
-				const std::string& verb = "select?name=" + LLURI::escape(msg);
-				args["ITEM"] = LLSLURL("inventory", info->mObjectID, verb.c_str()).getSLURLString();
-			}
-			LLNotificationsUtil::add("AutoAcceptedInventory", args);
-		}
-	}
-
-    // Strip any SLURL from the message display. (DEV-2754)
-        // try to find new slurl host
-
-    LLSD args;
-    args["[OBJECTNAME]"] = msg;
-
-    LLSD payload;
-
-    // must protect against a NULL return from lookupHumanReadable()
-    std::string typestr = ll_safe_string(LLAssetType::lookupHumanReadable(info->mType));
-    if (!typestr.empty())
-    {
-        // human readable matches string name from strings.xml
-        // lets get asset type localized name
-        args["OBJECTTYPE"] = LLTrans::getString(typestr);
-    }
-    else
-    {
-        LL_WARNS("Messaging") << "LLAssetType::lookupHumanReadable() returned NULL - probably bad asset type: " << info->mType << LL_ENDL;
-        args["OBJECTTYPE"] = "";
-
-        // This seems safest, rather than propagating bogosity
-        LL_WARNS("Messaging") << "Forcing an inventory-decline for probably-bad asset type." << LL_ENDL;
-        info->forceResponse(IOR_DECLINE);
-        return;
-    }
-
-    // If mObjectID is null then generate the object_id based on msg to prevent
-    // multiple creation of chiclets for same object.
-    LLUUID object_id = info->mObjectID;
-    if (object_id.isNull())
-        object_id.generate(msg);
-
-    payload["from_id"] = info->mFromID;
-    // Needed by LLScriptFloaterManager to bind original notification with 
-    // faked for toast one.
-    payload["object_id"] = object_id;
-    // Flag indicating that this notification is faked for toast.
-    payload["give_inventory_notification"] = FALSE;
-    args["OBJECTFROMNAME"] = info->mFromName;
-    args["NAME"] = info->mFromName;
-    if (info->mFromGroup)
-    {
-        args["NAME_SLURL"] = LLSLURL("group", info->mFromID, "about").getSLURLString();
-    }
-    else
-    {
-// [SL:KB] - Patch: UI-Notifications | Checked: 2011-04-11 (Catznip-2.5.0a) | Added: Catznip-2.5.0a
-		args["NAME_LABEL"] = LLSLURL("agent", info->mFromID, "completename").getSLURLString();
-// [/SL:KB]
-        args["NAME_SLURL"] = LLSLURL("agent", info->mFromID, "about").getSLURLString();
-    }
-    std::string verb = "select?name=" + LLURI::escape(msg);
-    args["ITEM_SLURL"] = LLSLURL("inventory", info->mObjectID, verb.c_str()).getSLURLString();
-
-    LLNotification::Params p;
-
-    // Object -> Agent Inventory Offer
-    if (info->mFromObject && !bAutoAccept)
-    {
-// [RLVa:KB] - Checked: RLVa-1.2.2
-		// Only filter if the object owner is a nearby agent
-		if ( (RlvActions::isRlvEnabled()) && (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, info->mFromID)) && (RlvUtil::isNearbyAgent(info->mFromID)) )
-		{
-			payload["rlv_shownames"] = TRUE;
-			args["NAME_SLURL"] = LLSLURL("agent", info->mFromID, "rlvanonym").getSLURLString();
-		}
-// [/RLVa:KB]
-
-        // Inventory Slurls don't currently work for non agent transfers, so only display the object name.
-        args["ITEM_SLURL"] = msg;
-        // Note: sets inventory_task_offer_callback as the callback
-        p.substitutions(args).payload(payload).functor.responder(LLNotificationResponderPtr(info));
-        info->mPersist = true;
-
-        // Offers from your own objects need a special notification template.
-        p.name = info->mFromID == gAgentID ? "OwnObjectGiveItem" : "ObjectGiveItem";
-
-        // Pop up inv offer chiclet and let the user accept (keep), or reject (and silently delete) the inventory.
-        LLPostponedNotification::add<LLPostponedOfferNotification>(p, info->mFromID, info->mFromGroup == TRUE);
-    }
-    else // Agent -> Agent Inventory Offer
-    {
-// [RLVa:KB] - Checked: RLVa-2.0.1
-		// Only filter if the offer is from a nearby agent and if there's no open IM session (doesn't necessarily have to be focused)
-		bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
-			(RlvActions::canShowName(RlvActions::SNC_DEFAULT, info->mFromID)) || (!RlvUtil::isNearbyAgent(info->mFromID)) || (RlvUIEnabler::hasOpenIM(info->mFromID)) || (RlvUIEnabler::hasOpenProfile(info->mFromID));
-		if (!fRlvCanShowName)
-		{
-			payload["rlv_shownames"] = TRUE;
-            LLAvatarName av_name;
-            if (LLAvatarNameCache::get(info->mFromID, &av_name))
-            {
-                args["NAME"] = RlvStrings::getAnonym(av_name);
-            }
-            else
-            {
-				args["NAME"] = RlvStrings::getAnonym(info->mFromName);
-            }
-			args["NAME_SLURL"] = LLSLURL("agent", info->mFromID, "rlvanonym").getSLURLString();
-		}
-// [/RLVa:KB]
-
-        p.responder = info;
-        // Note: sets inventory_offer_callback as the callback
-        // *TODO fix memory leak
-        // inventory_offer_callback() is not invoked if user received notification and 
-        // closes viewer(without responding the notification)
-        p.substitutions(args).payload(payload).functor.responder(LLNotificationResponderPtr(info));
-        info->mPersist = true;
-        p.name = "UserGiveItem";
-        p.offer_from_agent = true;
-
-        // Prefetch the item into your local inventory.
-        LLInventoryFetchItemsObserver* fetch_item = new LLInventoryFetchItemsObserver(info->mObjectID);
-        fetch_item->startFetch();
-        if (fetch_item->isFinished())
-        {
-            fetch_item->done();
-        }
-        else
-        {
-            gInventory.addObserver(fetch_item);
-        }
-
-        // In viewer 2 we're now auto receiving inventory offers and messaging as such (not sending reject messages).
-        info->send_auto_receive_response();
-
-        if (gAgent.isDoNotDisturb())
-        {
-            send_do_not_disturb_message(gMessageSystem, info->mFromID);
-        }
-
-        if (!bAutoAccept) // if we auto accept, do not pester the user
-        {
-            // Inform user that there is a script floater via toast system
-            payload["give_inventory_notification"] = TRUE;
-            p.payload = payload;
-            LLPostponedNotification::add<LLPostponedOfferNotification>(p, info->mFromID, false);
-        }
-
-        if (bAutoAccept && gSavedSettings.getBOOL("ShowNewInventory"))
-        {
-            LLViewerInventoryCategory* catp = NULL;
-            catp = (LLViewerInventoryCategory*)gInventory.getCategory(info->mObjectID);
-            LLViewerInventoryItem* itemp = NULL;
-            if(!catp)
-            {
-                itemp = (LLViewerInventoryItem*)gInventory.getItem(info->mObjectID);
-            }
-
-            LLOpenAgentOffer* open_agent_offer = new LLOpenAgentOffer(info->mObjectID, info->mFromName, false);
-            open_agent_offer->startFetch();
-            if(catp || (itemp && itemp->isFinished()))
-            {
-                open_agent_offer->done();
-            }
-            else
-            {
-                gInventory.addObserver(open_agent_offer);
-            }
-        }
-    }
-
-    LLFirstUse::newInventory();
-}
-
-// Callback for name resolution of a god/estate message
-static void god_message_name_cb(const LLAvatarName& av_name, LLChat chat, std::string message)
-{
-    LLSD args;
-    args["NAME"] = av_name.getCompleteName();
-    args["MESSAGE"] = message;
-    LLNotificationsUtil::add("GodMessage", args);
-
-    // Treat like a system message and put in chat history.
-    chat.mSourceType = CHAT_SOURCE_SYSTEM;
-    chat.mText = message;
-
-    LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
-    if (nearby_chat)
-    {
-        nearby_chat->addMessage(chat);
-    }
-}
-
-static bool parse_lure_bucket(const std::string& bucket,
-    U64& region_handle,
-    LLVector3& pos,
-    LLVector3& look_at,
-    U8& region_access)
-{
-    // tokenize the bucket
-    typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
-    boost::char_separator<char> sep("|", "", boost::keep_empty_tokens);
-    tokenizer tokens(bucket, sep);
-    tokenizer::iterator iter = tokens.begin();
-
-    S32 gx, gy, rx, ry, rz, lx, ly, lz;
-    try
-    {
-        gx = boost::lexical_cast<S32>((*(iter)).c_str());
-        gy = boost::lexical_cast<S32>((*(++iter)).c_str());
-        rx = boost::lexical_cast<S32>((*(++iter)).c_str());
-        ry = boost::lexical_cast<S32>((*(++iter)).c_str());
-        rz = boost::lexical_cast<S32>((*(++iter)).c_str());
-        lx = boost::lexical_cast<S32>((*(++iter)).c_str());
-        ly = boost::lexical_cast<S32>((*(++iter)).c_str());
-        lz = boost::lexical_cast<S32>((*(++iter)).c_str());
-    }
-    catch (const boost::bad_lexical_cast&)
-    {
-        LL_WARNS("parse_lure_bucket")
-            << "Couldn't parse lure bucket."
-            << LL_ENDL;
-        return false;
-    }
-    // Grab region access
-    region_access = SIM_ACCESS_MIN;
-    if (++iter != tokens.end())
-    {
-        std::string access_str((*iter).c_str());
-        LLStringUtil::trim(access_str);
-        if (access_str == "A")
-        {
-            region_access = SIM_ACCESS_ADULT;
-        }
-        else if (access_str == "M")
-        {
-            region_access = SIM_ACCESS_MATURE;
-        }
-        else if (access_str == "PG")
-        {
-            region_access = SIM_ACCESS_PG;
-        }
-    }
-
-    pos.setVec((F32)rx, (F32)ry, (F32)rz);
-    look_at.setVec((F32)lx, (F32)ly, (F32)lz);
-
-    region_handle = to_region_handle(gx, gy);
-    return true;
-}
-
-static void notification_display_name_callback(const LLUUID& id,
-    const LLAvatarName& av_name,
-    const std::string& name,
-    LLSD& substitutions,
-    const LLSD& payload)
-{
-    substitutions["NAME"] = av_name.getDisplayName();
-    LLNotificationsUtil::add(name, substitutions, payload);
-}
-
-void LLIMProcessing::processNewMessage(LLUUID from_id,
-    BOOL from_group,
-    LLUUID to_id,
-    U8 offline,
-    EInstantMessage dialog, // U8
-    LLUUID session_id,
-    U32 timestamp,
-    std::string name,
-    std::string message,
-    U32 parent_estate_id,
-    LLUUID region_id,
-    LLVector3 position,
-    U8 *binary_bucket,
-    S32 binary_bucket_size,
-    LLHost &sender,
-    LLUUID aux_id)
-{
-    LLChat chat;
-    std::string buffer;
-
-    // make sure that we don't have an empty or all-whitespace name
-    LLStringUtil::trim(name);
-    static const LLCachedControl<bool> sMarkUnnamedObjects(gSavedSettings, "AlchemyChatMarkUnnamedObjects", true);
-    if (sMarkUnnamedObjects && name.empty())
-    {
-        name = LLTrans::getString("Unnamed");
-    }
-
-    // Preserve the unaltered name for use in group notice mute checking.
-    std::string original_name = name;
-
-    // IDEVO convert new-style "Resident" names for display
-    name = clean_name_from_im(name, dialog);
-
-    BOOL is_do_not_disturb = gAgent.isDoNotDisturb();
-    BOOL is_rejecting_tp_offers = gAgent.isRejectTeleportOffers();
-    static LLCachedControl<bool> ALDontRejectTeleportOffersFromFriends(gSavedPerAccountSettings, "ALDontRejectTeleportOffersFromFriends");
-   
-    BOOL is_muted = LLMuteList::getInstance()->isMuted(from_id, name, LLMute::flagTextChat)
-        // object IMs contain sender object id in session_id (STORM-1209)
-        || (dialog == IM_FROM_TASK && LLMuteList::getInstance()->isMuted(session_id));
-
-    BOOL is_rejecting_friendship_requests = gAgent.getRejectFriendshipRequests();
-
-    BOOL is_owned_by_me = FALSE;
-    BOOL is_friend = (LLAvatarTracker::instance().getBuddyInfo(from_id) == NULL) ? false : true;
-    BOOL accept_im_from_only_friend = gSavedPerAccountSettings.getBOOL("VoiceCallsFriendsOnly");
-    BOOL is_linden = chat.mSourceType != CHAT_SOURCE_OBJECT &&
-        LLMuteList::isLinden(name);
-
-    chat.mMuted = is_muted;
-    chat.mFromID = from_id;
-    chat.mFromName = name;
-    chat.mSourceType = (from_id.isNull() || (name == std::string(SYSTEM_FROM))) ? CHAT_SOURCE_SYSTEM : CHAT_SOURCE_AGENT;
-
-    if (chat.mSourceType == CHAT_SOURCE_SYSTEM)
-    { // Translate server message if required (MAINT-6109)
-        translate_if_needed(message);
-    }
-
-    LLViewerObject *source = gObjectList.findObject(session_id); //Session ID is probably the wrong thing.
-    if (source)
-    {
-        is_owned_by_me = source->permYouOwner();
-    }
-
-    std::string separator_string(": ");
-
-    LLSD args;
-    LLSD payload;
-    LLNotification::Params params;
-
-    switch (dialog)
-    {
-        case IM_CONSOLE_AND_CHAT_HISTORY:
-            args["MESSAGE"] = message;
-            payload["from_id"] = from_id;
-
-            params.name = "IMSystemMessageTip";
-            params.substitutions = args;
-            params.payload = payload;
-            LLPostponedNotification::add<LLPostponedIMSystemTipNotification>(params, from_id, false);
-            break;
-
-        case IM_NOTHING_SPECIAL:	// p2p IM
-            // Don't show dialog, just do IM
-            if (!gAgent.isGodlike()
-                && gAgent.getRegion()->isPrelude()
-                && to_id.isNull())
-            {
-                // do nothing -- don't distract newbies in
-                // Prelude with global IMs
-            }
-// [RLVa:KB] - Checked: RLVa-2.1.0
-			else if ( (RlvActions::isRlvEnabled()) && (offline == IM_ONLINE) && (!is_muted) && ((!accept_im_from_only_friend) || (is_friend)) &&
-					  (message.length() > 3) && (RLV_CMD_PREFIX == message[0]) && (RlvHandler::instance().processIMQuery(from_id, message)) )
-			{
-				// Eat the message and do nothing
-			}
-// [/RLVa:KB]
-//            else if (offline == IM_ONLINE
-//                && is_do_not_disturb
-//                && from_id.notNull() //not a system message
-//                && to_id.notNull()) //not global message
-// [RLVa:KB] - Checked: 2010-11-30 (RLVa-1.3.0)
-			else if (offline == IM_ONLINE
-				&& is_do_not_disturb
-				&& from_id.notNull() //not a system message
-				&& to_id.notNull() //not global message
-				&& RlvActions::canReceiveIM(from_id))
-// [/RLVa:KB]
-            {
-
-                // now store incoming IM in chat history
-
-                buffer = message;
-
-                LL_DEBUGS("Messaging") << "session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
-
-                // add to IM panel, but do not bother the user
-                gIMMgr->addMessage(
-                    session_id,
-                    from_id,
-                    name,
-                    buffer,
-                    IM_OFFLINE == offline,
-                    LLStringUtil::null,
-                    dialog,
-                    parent_estate_id,
-                    region_id,
-                    position,
-                    false,      // is_region_msg
-                    timestamp);
-
-                if (!gIMMgr->isDNDMessageSend(session_id))
-                {
-                    // return a standard "do not disturb" message, but only do it to online IM
-                    // (i.e. not other auto responses and not store-and-forward IM)
-                    send_do_not_disturb_message(gMessageSystem, from_id, session_id);
-                    gIMMgr->setDNDMessageSent(session_id, true);
-                }
-
-            }
-            else if (from_id.isNull())
-            {
-                LLSD args;
-                args["MESSAGE"] = message;
-                LLNotificationsUtil::add("SystemMessage", args);
-            }
-            else if (to_id.isNull())
-            {
-                // Message to everyone from GOD, look up the fullname since
-                // server always slams name to legacy names
-                LLAvatarNameCache::get(from_id, boost::bind(god_message_name_cb, _2, chat, message));
-            }
-            else
-            {
-                // standard message, not from system
-                std::string saved;
-                if (offline == IM_OFFLINE)
-                {
-                    LLStringUtil::format_map_t args;
-                    args["[LONG_TIMESTAMP]"] = formatted_time(timestamp);
-                    saved = LLTrans::getString("Saved_message", args);
-                }
-                buffer = saved + message;
-
-                LL_DEBUGS("Messaging") << "session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
-
-                bool mute_im = is_muted;
-                if (accept_im_from_only_friend && !is_friend && !is_linden)
-                {
-                    if (!gIMMgr->isNonFriendSessionNotified(session_id))
-                    {
-                        std::string message = LLTrans::getString("IM_unblock_only_groups_friends");
-                        gIMMgr->addMessage(session_id, from_id, name, message, IM_OFFLINE == offline);
-                        gIMMgr->addNotifiedNonFriendSessionID(session_id);
-                    }
-
-                    mute_im = true;
-                }
-
-// [RLVa:KB] - Checked: 2010-11-30 (RLVa-1.3.0)
-				// Don't block offline IMs, or IMs from Lindens
-				if ( (rlv_handler_t::isEnabled()) && (offline != IM_OFFLINE) && (!RlvActions::canReceiveIM(from_id)) && (!LLMuteList::isLinden(original_name) ))
-				{
-					if (!mute_im)
-						RlvUtil::sendBusyMessage(from_id, RlvStrings::getString(RlvStringKeys::Blocked::RecvImRemote), session_id);
-					buffer = RlvStrings::getString(RlvStringKeys::Blocked::RecvIm);
-				}
-// [/RLVa:KB]
-
-                if (!mute_im)
-                {
-                    bool region_message = false;
-                    if (region_id.isNull())
-                    {
-                        LLViewerRegion* regionp = LLWorld::instance().getRegionFromID(from_id);
-                        if (regionp)
-                        {
-                            region_message = true;
-                        }
-                    }
-                    gIMMgr->addMessage(
-                        session_id,
-                        from_id,
-                        name,
-                        buffer,
-                        IM_OFFLINE == offline,
-                        LLStringUtil::null,
-                        dialog,
-                        parent_estate_id,
-                        region_id,
-                        position,
-                        region_message,
-                        timestamp);
-                }
-                else
-                {
-                    /*
-                    EXT-5099
-                    */
-                }
-            }
-            break;
-
-        case IM_TYPING_START:
-		{
-			static LLCachedControl<bool> sNotifyIncomingMessage(gSavedSettings, "AlchemyNotifyIncomingMessage");
-			if (sNotifyIncomingMessage &&
-				!gIMMgr->hasSession(session_id) &&
-				((accept_im_from_only_friend && (is_friend || is_linden)) ||
-				(!(is_muted || is_do_not_disturb)))
-				)
-			{
-				LLStringUtil::format_map_t args;
-				args["[NAME]"] = name;
-				const std::string notify_str = LLTrans::getString("NotifyIncomingMessage", args);
-				gIMMgr->addMessage(session_id,
-					from_id,
-					LLStringUtil::null,
-					notify_str,
-					IM_ONLINE,
-					LLStringUtil::null,
-					IM_NOTHING_SPECIAL,
-					parent_estate_id,
-					region_id,
-					position,
-					false,
-                    0
-				);
-			}
-
-            gIMMgr->processIMTypingStart(from_id, dialog);
-		}
-        break;
-
-        case IM_TYPING_STOP:
-        {
-            gIMMgr->processIMTypingStop(from_id, dialog);
-        }
-        break;
-
-        case IM_MESSAGEBOX:
-        {
-            // This is a block, modeless dialog.
-            args["MESSAGE"] = message;
-            LLNotificationsUtil::add("SystemMessageTip", args);
-        }
-        break;
-        case IM_GROUP_NOTICE:
-        case IM_GROUP_NOTICE_REQUESTED:
-        {
-            LL_INFOS("Messaging") << "Received IM_GROUP_NOTICE message." << LL_ENDL;
-
-            LLUUID agent_id;
-            U8 has_inventory;
-            U8 asset_type = 0;
-            LLUUID group_id;
-            std::string item_name;
-
-            if (aux_id.notNull())
-            {
-                // aux_id contains group id, binary bucket contains name and asset type
-                group_id = aux_id;
-                has_inventory = binary_bucket_size > 1 ? TRUE : FALSE;
-                from_group = TRUE; // inaccurate value correction
-                if (has_inventory)
-                {
-                    std::string str_bucket = ll_safe_string((char*)binary_bucket, binary_bucket_size);
-
-                    typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
-                    boost::char_separator<char> sep("|", "", boost::keep_empty_tokens);
-                    tokenizer tokens(str_bucket, sep);
-                    tokenizer::iterator iter = tokens.begin();
-
-                    asset_type = (LLAssetType::EType)(atoi((*(iter++)).c_str()));
-                    iter++; // wearable type if applicable, otherwise asset type
-                    item_name = std::string((*(iter++)).c_str());
-                    // Note There is more elements in 'tokens' ...
-
-
-                    for (int i = 0; i < 6; i++)
-                    {
-                        LL_WARNS() << *(iter++) << LL_ENDL;
-                        iter++;
-                    }
-                }
-            }
-            else
-            {
-                // All info is in binary bucket, read it for more information.
-                struct notice_bucket_header_t
-                {
-                    U8 has_inventory;
-                    U8 asset_type;
-                    LLUUID group_id;
-                };
-                struct notice_bucket_full_t
-                {
-                    struct notice_bucket_header_t header;
-                    U8 item_name[DB_INV_ITEM_NAME_BUF_SIZE];
-                }*notice_bin_bucket;
-
-                // Make sure the binary bucket is big enough to hold the header 
-                // and a null terminated item name.
-                if ((binary_bucket_size < (S32)((sizeof(notice_bucket_header_t) + sizeof(U8))))
-                    || (binary_bucket[binary_bucket_size - 1] != '\0'))
-                {
-                    LL_WARNS("Messaging") << "Malformed group notice binary bucket" << LL_ENDL;
-                    break;
-                }
-
-                notice_bin_bucket = (struct notice_bucket_full_t*) &binary_bucket[0];
-                has_inventory = notice_bin_bucket->header.has_inventory;
-                asset_type = notice_bin_bucket->header.asset_type;
-                group_id = notice_bin_bucket->header.group_id;
-                item_name = ll_safe_string((const char*)notice_bin_bucket->item_name);
-            }
-
-            if (group_id != from_id)
-            {
-                agent_id = from_id;
-            }
-            else
-            {
-                std::string::size_type index = original_name.find(" Resident");
-                if (index != std::string::npos)
-                {
-                    original_name = original_name.substr(0, index);
-                }
-
-                // The group notice packet does not have an AgentID.  Obtain one from the name cache.
-                // If last name is "Resident" strip it out so the cache name lookup works.
-                std::string legacy_name = gCacheName->buildLegacyName(original_name);
-                agent_id = LLAvatarNameCache::getInstance()->findIdByName(legacy_name);
-
-                if (agent_id.isNull())
-                {
-                    LL_WARNS("Messaging") << "buildLegacyName returned null while processing " << original_name << LL_ENDL;
-                }
-            }
-
-            if (agent_id.notNull() && LLMuteList::getInstance()->isMuted(agent_id))
-            {
-                break;
-            }
-
-            // If there is inventory, give the user the inventory offer.
-            LLOfferInfo* info = NULL;
-
-            if (has_inventory)
-            {
-                info = new LLOfferInfo();
-
-                info->mIM = dialog;
-                info->mFromID = from_id;
-                info->mFromGroup = from_group;
-                info->mTransactionID = session_id;
-                info->mType = (LLAssetType::EType) asset_type;
-                info->mFolderID = gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(info->mType));
-                std::string from_name;
-
-                from_name += "A group member named ";
-                from_name += name;
-
-                info->mFromName = from_name;
-                info->mDesc = item_name;
-                info->mHost = sender;
-            }
-
-            std::string str(message);
-
-            // Tokenize the string.
-            // TODO: Support escaped tokens ("||" -> "|")
-            typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
-            boost::char_separator<char> sep("|", "", boost::keep_empty_tokens);
-            tokenizer tokens(str, sep);
-            tokenizer::iterator iter = tokens.begin();
-
-            std::string subj(*iter++);
-            std::string mes(*iter++);
-
-            // Send the notification down the new path.
-            // For requested notices, we don't want to send the popups.
-            if (dialog != IM_GROUP_NOTICE_REQUESTED)
-            {
-                payload["subject"] = subj;
-                payload["message"] = mes;
-                payload["sender_name"] = name;
-                payload["sender_id"] = agent_id;
-                payload["group_id"] = group_id;
-                payload["inventory_name"] = item_name;
-                payload["received_time"] = LLDate::now();
-                if (info && info->asLLSD())
-                {
-                    payload["inventory_offer"] = info->asLLSD();
-                }
-
-                LLSD args;
-                args["SUBJECT"] = subj;
-                args["MESSAGE"] = mes;
-                LLDate notice_date = LLDate(timestamp).notNull() ? LLDate(timestamp) : LLDate::now();
-                LLNotifications::instance().add(LLNotification::Params("GroupNotice").substitutions(args).payload(payload).time_stamp(notice_date));
-            }
-
-            // Also send down the old path for now.
-            if (IM_GROUP_NOTICE_REQUESTED == dialog)
-            {
-
-                LLPanelGroup::showNotice(subj, mes, group_id, has_inventory, item_name, info);
-            }
-            else
-            {
-                delete info;
-            }
-        }
-        break;
-        case IM_GROUP_INVITATION:
-        {
-            if (!is_muted)
-            {
-                // group is not blocked, but we still need to check agent that sent the invitation
-                // and we have no agent's id
-                // Note: server sends username "first.last".
-                is_muted |= LLMuteList::getInstance()->isMuted(name);
-            }
-            if (is_do_not_disturb || is_muted)
-            {
-                send_do_not_disturb_message(gMessageSystem, from_id);
-            }
-
-            if (!is_muted)
-            {
-                LL_INFOS("Messaging") << "Received IM_GROUP_INVITATION message." << LL_ENDL;
-                // Read the binary bucket for more information.
-                struct invite_bucket_t
-                {
-                    S32 membership_fee;
-                    LLUUID role_id;
-                }*invite_bucket;
-
-                // Make sure the binary bucket is the correct size.
-                if (binary_bucket_size != sizeof(invite_bucket_t))
-                {
-                    LL_WARNS("Messaging") << "Malformed group invite binary bucket" << LL_ENDL;
-                    break;
-                }
-
-                invite_bucket = (struct invite_bucket_t*) &binary_bucket[0];
-                S32 membership_fee = ntohl(invite_bucket->membership_fee);
-
-                LLSD payload;
-                payload["transaction_id"] = session_id;
-                payload["group_id"] = from_group ? from_id : aux_id;
-                payload["name"] = name;
-                payload["message"] = message;
-                payload["fee"] = membership_fee;
-                payload["use_offline_cap"] = session_id.isNull() && (offline == IM_OFFLINE);
-
-                LLSD args;
-                args["MESSAGE"] = message;
-                // we shouldn't pass callback functor since it is registered in LLFunctorRegistration
-                LLNotificationsUtil::add("JoinGroup", args, payload);
-            }
-        }
-        break;
-
-        case IM_INVENTORY_OFFERED:
-        case IM_TASK_INVENTORY_OFFERED:
-            // Someone has offered us some inventory.
-        {
-            LLOfferInfo* info = new LLOfferInfo;
-            if (IM_INVENTORY_OFFERED == dialog)
-            {
-                struct offer_agent_bucket_t
-                {
-                    S8		asset_type;
-                    LLUUID	object_id;
-                }*bucketp;
-
-                if (sizeof(offer_agent_bucket_t) != binary_bucket_size)
-                {
-                    LL_WARNS("Messaging") << "Malformed inventory offer from agent" << LL_ENDL;
-                    delete info;
-                    break;
-                }
-                bucketp = (struct offer_agent_bucket_t*) &binary_bucket[0];
-                info->mType = (LLAssetType::EType) bucketp->asset_type;
-                info->mObjectID = bucketp->object_id;
-                info->mFromObject = FALSE;
-            }
-            else // IM_TASK_INVENTORY_OFFERED
-            {
-                if (sizeof(S8) == binary_bucket_size)
-                {
-                    info->mType = (LLAssetType::EType) binary_bucket[0];
-                }
-                else
-                {
-                    /*RIDER*/ // The previous version of the protocol returned the wrong binary bucket... we 
-                    // still might be able to figure out the type... even though the offer is not retrievable. 
-
-                    // Should be safe to remove once DRTSIM-451 fully deploys
-                    std::string str_bucket(reinterpret_cast<char *>(binary_bucket));
-                    std::string str_type(str_bucket.substr(0, str_bucket.find('|')));
-
-                    std::stringstream type_convert(str_type);
-
-                    S32 type;
-                    type_convert >> type;
-
-                    // We could try AT_UNKNOWN which would be more accurate, but that causes an auto decline
-                    info->mType = static_cast<LLAssetType::EType>(type);
-                    // Don't break in the case of a bad binary bucket.  Go ahead and show the 
-                    // accept/decline popup even though it will not do anything.
-                    LL_WARNS("Messaging") << "Malformed inventory offer from object, type might be " << info->mType << LL_ENDL;
-                }
-                info->mObjectID = LLUUID::null;
-                info->mFromObject = TRUE;
-            }
-
-            info->mIM = dialog;
-            info->mFromID = from_id;
-            info->mFromGroup = from_group;
-            info->mFolderID = gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(info->mType));
-
-            info->mTransactionID = session_id.notNull() ? session_id : aux_id;
-
-            info->mFromName = name;
-            info->mDesc = message;
-            info->mHost = sender;
-            //if (((is_do_not_disturb && !is_owned_by_me) || is_muted))
-            if (is_muted)
-            {
-                // Prefetch the offered item so that it can be discarded by the appropriate observer. (EXT-4331)
-                if (IM_INVENTORY_OFFERED == dialog)
-                {
-                    LLInventoryFetchItemsObserver* fetch_item = new LLInventoryFetchItemsObserver(info->mObjectID);
-                    fetch_item->startFetch();
-                    delete fetch_item;
-                    // Same as closing window
-                    info->forceResponse(IOR_DECLINE);
-                }
-                else
-                {
-                    info->forceResponse(IOR_MUTE);
-                }
-            }
-            // old logic: busy mode must not affect interaction with objects (STORM-565)
-            // new logic: inventory offers from in-world objects should be auto-declined (CHUI-519)
-            else if (is_do_not_disturb && dialog == IM_TASK_INVENTORY_OFFERED)
-            {
-                // Until throttling is implemented, do not disturb mode should reject inventory instead of silently
-                // accepting it.  SEE SL-39554
-                info->forceResponse(IOR_DECLINE);
-            }
-            else
-            {
-                inventory_offer_handler(info);
-            }
-        }
-        break;
-
-        case IM_INVENTORY_ACCEPTED:
-        {
-//            args["NAME"] = LLSLURL("agent", from_id, "completename").getSLURLString();;
-//            args["ORIGINAL_NAME"] = original_name;
-// [RLVa:KB] - Checked: RLVa-1.2.2
-			// Only anonymize the name if the agent is nearby, there isn't an open IM session to them and their profile isn't open
-			bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
-				(RlvActions::canShowName(RlvActions::SNC_DEFAULT, from_id)) || (!RlvUtil::isNearbyAgent(from_id)) || (RlvUIEnabler::hasOpenProfile(from_id)) || (RlvUIEnabler::hasOpenIM(from_id));
-			args["NAME"] = LLSLURL("agent", from_id, (fRlvCanShowName) ? "completename" : "rlvanonym").getSLURLString();
-			if (RlvActions::canShowName(RlvActions::SNC_DEFAULT, from_id))
-				args["ORIGINAL_NAME"] = original_name;
-			else
-				args["ORIGINAL_NAME"] = RlvStrings::getAnonym(original_name);
-// [/RLVa:KB]
-            LLSD payload;
-            payload["from_id"] = from_id;
-            // Passing the "SESSION_NAME" to use it for IM notification logging
-            // in LLTipHandler::processNotification(). See STORM-941.
-            payload["SESSION_NAME"] = name;
-            LLNotificationsUtil::add("InventoryAccepted", args, payload);
-            break;
-        }
-        case IM_INVENTORY_DECLINED:
-        {
-//            args["NAME"] = LLSLURL("agent", from_id, "completename").getSLURLString();;
-// [RLVa:KB] - Checked: RLVa-1.2.2
-			// Only anonymize the name if the agent is nearby, there isn't an open IM session to them and their profile isn't open
-			bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
-				(RlvActions::canShowName(RlvActions::SNC_DEFAULT, from_id)) || (!RlvUtil::isNearbyAgent(from_id)) || (RlvUIEnabler::hasOpenProfile(from_id)) || (RlvUIEnabler::hasOpenIM(from_id));
-			args["NAME"] = LLSLURL("agent", from_id, (fRlvCanShowName) ? "completename" : "rlvanonym").getSLURLString();;
-// [/RLVa:KB]
-            LLSD payload;
-            payload["from_id"] = from_id;
-            LLNotificationsUtil::add("InventoryDeclined", args, payload);
-            break;
-        }
-        // TODO: _DEPRECATED suffix as part of vote removal - DEV-24856
-        case IM_GROUP_VOTE:
-        {
-            LL_WARNS("Messaging") << "Received IM: IM_GROUP_VOTE_DEPRECATED" << LL_ENDL;
-        }
-        break;
-
-        case IM_GROUP_ELECTION_DEPRECATED:
-        {
-            LL_WARNS("Messaging") << "Received IM: IM_GROUP_ELECTION_DEPRECATED" << LL_ENDL;
-        }
-        break;
-
-        case IM_FROM_TASK:
-        {
-
-            if (is_do_not_disturb && !is_owned_by_me)
-            {
-                return;
-            }
-
-            // Build a link to open the object IM info window.
-            std::string location = ll_safe_string((char*)binary_bucket, binary_bucket_size - 1);
-
-            if (session_id.notNull())
-            {
-                chat.mFromID = session_id;
-            }
-            else
-            {
-                // This message originated on a region without the updated code for task id and slurl information.
-                // We just need a unique ID for this object that isn't the owner ID.
-                // If it is the owner ID it will overwrite the style that contains the link to that owner's profile.
-                // This isn't ideal - it will make 1 style for all objects owned by the the same person/group.
-                // This works because the only thing we can really do in this case is show the owner name and link to their profile.
-                chat.mFromID = from_id ^ gAgent.getSessionID();
-            }
-
-            chat.mSourceType = CHAT_SOURCE_OBJECT;
-
-            // To conclude that the source type of message is CHAT_SOURCE_SYSTEM it's not
-            // enough to check only from name (i.e. fromName = "Second Life"). For example
-            // source type of messages from objects called "Second Life" should not be CHAT_SOURCE_SYSTEM.
-            bool chat_from_system = (SYSTEM_FROM == name) && region_id.isNull() && position.isNull();
-            if (chat_from_system)
-            {
-                // System's UUID is NULL (fixes EXT-4766)
-                chat.mFromID = LLUUID::null;
-                chat.mSourceType = CHAT_SOURCE_SYSTEM;
-            }
-
-            // IDEVO Some messages have embedded resident names
-            message = clean_name_from_task_im(message, from_group);
-
-            LLSD query_string;
-            query_string["owner"] = from_id;
-// [RLVa:KB] - Checked: RLVa-1.2.0
-			if (RlvActions::isRlvEnabled())
-			{
-				// NOTE: the chat message itself will be filtered in LLNearbyChatHandler::processChat()
-				if ( (!RlvActions::canShowName(RlvActions::SNC_DEFAULT)) && (!from_group) && (RlvUtil::isNearbyAgent(from_id)) )
-				{
-					query_string["rlv_shownames"] = TRUE;
-
-					RlvUtil::filterNames(name);
-					chat.mFromName = name;
-				}
-				if (!RlvActions::canShowLocation())
-				{
-					std::string::size_type idxPos = location.find('/');
-					if ( (std::string::npos != idxPos) && (RlvUtil::isNearbyRegion(location.substr(0, idxPos))) )
-						location = RlvStrings::getString(RlvStringKeys::Hidden::Region);
-				}
-			}
-// [/RLVa:KB]
-            query_string["slurl"] = location;
-            query_string["name"] = name;
-            if (from_group)
-            {
-                query_string["groupowned"] = "true";
-            }
-
-//           chat.mURL = LLSLURL("objectim", session_id, "").getSLURLString();
-// [SL:KB] - Checked: 2010-11-02 (RLVa-1.2.2a) | Added: RLVa-1.2.2a
-			chat.mURL = LLSLURL("objectim", session_id, LLURI::mapToQueryString(query_string)).getSLURLString();
-// [/SL:KB]
-           chat.mText = message;
-
-            // Note: lie to Nearby Chat, pretending that this is NOT an IM, because
-            // IMs from obejcts don't open IM sessions.
-            LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
-            if (!chat_from_system && nearby_chat)
-            {
-                chat.mOwnerID = from_id;
-                LLSD args;
-                args["slurl"] = location;
-
-                // Look for IRC-style emotes here so object name formatting is correct
-                std::string prefix = message.substr(0, 4);
-                if (prefix == "/me " || prefix == "/me'")
-                {
-                    chat.mChatStyle = CHAT_STYLE_IRC;
-                }
-
-                LLNotificationsUI::LLNotificationManager::instance().onChat(chat, args);
-                if (message != "")
-                {
-                    LLSD msg_notify;
-                    msg_notify["session_id"] = LLUUID();
-                    msg_notify["from_id"] = chat.mFromID;
-                    msg_notify["source_type"] = chat.mSourceType;
-                    on_new_message(msg_notify);
-                }
-            }
-
-
-            //Object IMs send with from name: 'Second Life' need to be displayed also in notification toasts (EXT-1590)
-            if (!chat_from_system) break;
-
-            LLSD substitutions;
-            substitutions["NAME"] = name;
-            substitutions["MSG"] = message;
-
-            LLSD payload;
-            payload["object_id"] = session_id;
-            payload["owner_id"] = from_id;
-            payload["from_id"] = from_id;
-            payload["slurl"] = location;
-            payload["name"] = name;
-
-            if (from_group)
-            {
-                payload["group_owned"] = "true";
-            }
-
-            LLNotificationsUtil::add("ServerObjectMessage", substitutions, payload);
-        }
-        break;
-
-        case IM_SESSION_SEND:		// ad-hoc or group IMs
-
-            // Only show messages if we have a session open (which
-            // should happen after you get an "invitation"
-//           if (!gIMMgr->hasSession(session_id))
-// [SL:KB] - Patch: Chat-GroupSnooze | Checked: Catznip-3.3
-            if (!gIMMgr->hasSession(session_id) && (!gAgent.isInGroup(session_id) || (!gIMMgr->checkSnoozeExpiration(session_id) || !gIMMgr->restoreSnoozedSession(session_id))) )
-// [/SL:KB]
-            {
-                return;
-            }
-
-            else if (offline == IM_ONLINE && is_do_not_disturb)
-            {
-
-                // return a standard "do not disturb" message, but only do it to online IM 
-                // (i.e. not other auto responses and not store-and-forward IM)
-                if (!gIMMgr->hasSession(session_id))
-                {
-                    // if there is not a panel for this conversation (i.e. it is a new IM conversation
-                    // initiated by the other party) then...
-                    send_do_not_disturb_message(gMessageSystem, from_id, session_id);
-                }
-
-                // now store incoming IM in chat history
-
-                buffer = message;
-
-                LL_DEBUGS("Messaging") << "message in dnd; session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
-
-                // add to IM panel, but do not bother the user
-                gIMMgr->addMessage(
-                    session_id,
-                    from_id,
-                    name,
-                    buffer,
-                    IM_OFFLINE == offline,
-                    ll_safe_string((char*)binary_bucket),
-                    IM_SESSION_INVITE,
-                    parent_estate_id,
-                    region_id,
-                    position,
-                    false,      // is_region_msg
-                    timestamp);
-            }
-            else
-            {
-                // standard message, not from system
-                std::string saved;
-                if (offline == IM_OFFLINE)
-                {
-                    saved = llformat("(Saved %s) ", formatted_time(timestamp).c_str());
-                }
-
-                buffer = saved + message;
-
-                LL_DEBUGS("Messaging") << "standard message session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
-
-                gIMMgr->addMessage(
-                    session_id,
-                    from_id,
-                    name,
-                    buffer,
-                    (IM_OFFLINE == offline),
-                    ll_safe_string((char*)binary_bucket),   // session name
-                    IM_SESSION_INVITE,
-                    parent_estate_id,
-                    region_id,
-                    position,
-                    false,      // is_region_msg
-                    timestamp);
-            }
-            break;
-
-        case IM_FROM_TASK_AS_ALERT:
-            if (is_do_not_disturb && !is_owned_by_me)
-            {
-                return;
-            }
-            {
-                // Construct a viewer alert for this message.
-                args["NAME"] = name;
-                args["MESSAGE"] = message;
-                LLNotificationsUtil::add("ObjectMessage", args);
-            }
-            break;
-        case IM_DO_NOT_DISTURB_AUTO_RESPONSE:
-            if (is_muted)
-            {
-                LL_DEBUGS("Messaging") << "Ignoring do-not-disturb response from " << from_id << LL_ENDL;
-                return;
-            }
-            else
-            {
-                gIMMgr->addMessage(session_id, from_id, name, message);
-            }
-            break;
-
-        case IM_LURE_USER:
-        case IM_TELEPORT_REQUEST:
-        {
- // [RLVa:KB] - Checked: RLVa-1.4.9
-			// If we auto-accept the offer/request then this will override DnD status (but we'll still let the other party know later)
-			bool fRlvAutoAccept = (rlv_handler_t::isEnabled()) &&
-				( ((IM_LURE_USER == dialog) && (RlvActions::autoAcceptTeleportOffer(from_id))) ||
-				  ((IM_TELEPORT_REQUEST == dialog) && (RlvActions::autoAcceptTeleportRequest(from_id))) );
-// [/RLVa:KB]
-
-           if (is_muted)
-            {
-                return;
-            }
-            else if (gSavedPerAccountSettings.getBOOL("VoiceCallsFriendsOnly") && (LLAvatarTracker::instance().getBuddyInfo(from_id) == NULL))
-            {
-                return;
-            }
-            else if ((is_rejecting_tp_offers && (!ALDontRejectTeleportOffersFromFriends || (ALDontRejectTeleportOffersFromFriends && !is_friend))) && (!fRlvAutoAccept))
-            {
-                send_rejecting_tp_offers_message(gMessageSystem, from_id);
-            }
-            else
-            {
-//				if (is_do_not_disturb) 
-// [RLVa:KB] - Checked: RLVa-1.4.9
-				if ( (is_do_not_disturb) && (!fRlvAutoAccept) )
-// [/RLVa:KB]
-                {
-                    send_do_not_disturb_message(gMessageSystem, from_id);
-                }
-
-                LLVector3 pos, look_at;
-                U64 region_handle(0);
-                U8 region_access(SIM_ACCESS_MIN);
-                std::string region_info = ll_safe_string((char*)binary_bucket, binary_bucket_size);
-                std::string region_access_str = LLStringUtil::null;
-                std::string region_access_icn = LLStringUtil::null;
-                std::string region_access_lc = LLStringUtil::null;
-
-                bool canUserAccessDstRegion = true;
-                bool doesUserRequireMaturityIncrease = false;
-
-                // Do not parse the (empty) lure bucket for TELEPORT_REQUEST
-                if (IM_TELEPORT_REQUEST != dialog && parse_lure_bucket(region_info, region_handle, pos, look_at, region_access))
-                {
-                    region_access_str = LLViewerRegion::accessToString(region_access);
-                    region_access_icn = LLViewerRegion::getAccessIcon(region_access);
-                    region_access_lc = region_access_str;
-                    LLStringUtil::toLower(region_access_lc);
-
-                    if (!gAgent.isGodlike())
-                    {
-                        switch (region_access)
-                        {
-                            case SIM_ACCESS_MIN:
-                            case SIM_ACCESS_PG:
-                                break;
-                            case SIM_ACCESS_MATURE:
-                                if (gAgent.isTeen())
-                                {
-                                    canUserAccessDstRegion = false;
-                                }
-                                else if (gAgent.prefersPG())
-                                {
-                                    doesUserRequireMaturityIncrease = true;
-                                }
-                                break;
-                            case SIM_ACCESS_ADULT:
-                                if (!gAgent.isAdult())
-                                {
-                                    canUserAccessDstRegion = false;
-                                }
-                                else if (!gAgent.prefersAdult())
-                                {
-                                    doesUserRequireMaturityIncrease = true;
-                                }
-                                break;
-                            default:
-                                llassert(0);
-                                break;
-                        }
-                    }
-                }
-
-// [RLVa:KB] - Checked: RLVa-1.4.9
-				if (rlv_handler_t::isEnabled())
-				{
-                    bool fBlockTpLure = (IM_LURE_USER == dialog) && (!RlvActions::canAcceptTpOffer(from_id));
-                    bool fBlockTpRequest = (IM_TELEPORT_REQUEST == dialog) && (!RlvActions::canAcceptTpRequest(from_id));
-					if ( fBlockTpLure || fBlockTpRequest )
-					{
-						RlvUtil::sendBusyMessage(from_id, RlvStrings::getString(fBlockTpLure ? RlvStringKeys::Blocked::TpLureRemote : RlvStringKeys::Blocked::TpRequestRemote));
-						if (is_do_not_disturb)
-							send_do_not_disturb_message(gMessageSystem, from_id);
-						return;
-					}
-
-					// Censor message if: 1) restricted from receiving IMs from the sender, or 2) teleport offer/request and @showloc=n restricted
-					if ( (!RlvActions::canReceiveIM(from_id)) || 
-						 ((gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) && (IM_LURE_USER == dialog || IM_TELEPORT_REQUEST == dialog)) )
-					{
-						message = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
-					}
-				}
-// [/RLVa:KB]
-
-				LLSD args;
-                // *TODO: Translate -> [FIRST] [LAST] (maybe)
-// [SL:KB] - Patch: UI-Notifications | Checked: 2011-04-11 (Catznip-2.5.0a) | Added: Catznip-2.5.0a
-				args["NAME_LABEL"] = LLSLURL("agent", from_id, "completename").getSLURLString();
-// [/SL:KB]
-                args["NAME_SLURL"] = LLSLURL("agent", from_id, "about").getSLURLString();
-                args["MESSAGE"] = message;
-                args["MATURITY_STR"] = region_access_str;
-                args["MATURITY_ICON"] = region_access_icn;
-                args["REGION_CONTENT_MATURITY"] = region_access_lc;
-                LLSD payload;
-                payload["from_id"] = from_id;
-                payload["lure_id"] = session_id;
-                payload["godlike"] = FALSE;
-                payload["region_maturity"] = region_access;
-
-                if (!canUserAccessDstRegion)
-                {
-                    LLNotification::Params params("TeleportOffered_MaturityBlocked");
-                    params.substitutions = args;
-                    params.payload = payload;
-                    LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
-                    send_simple_im(from_id, LLTrans::getString("TeleportMaturityExceeded"), IM_NOTHING_SPECIAL, session_id);
-                    send_simple_im(from_id, LLStringUtil::null, IM_LURE_DECLINED, session_id);
-                }
-                else if (doesUserRequireMaturityIncrease)
-                {
-                    LLNotification::Params params("TeleportOffered_MaturityExceeded");
-                    params.substitutions = args;
-                    params.payload = payload;
-                    LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
-                }
-                else
-                {
-                    LLNotification::Params params;
-                    if (IM_LURE_USER == dialog)
-                    {
-                        params.name = "TeleportOffered";
-                        params.functor.name = "TeleportOffered";
-                    }
-                    else if (IM_TELEPORT_REQUEST == dialog)
-                    {
-                        params.name = "TeleportRequest";
-                        params.functor.name = "TeleportRequest";
-                    }
-
-                    params.substitutions = args;
-                    params.payload = payload;
-
-// [RLVa:KB] - Checked: RLVa-1.4.9
-					if (fRlvAutoAccept)
-					{
-						if (IM_LURE_USER == dialog)
-							gRlvHandler.setCanCancelTp(false);
-						if (is_do_not_disturb)
-							send_do_not_disturb_message(gMessageSystem, from_id);
-						LLNotifications::instance().forceResponse(LLNotification::Params(params.name).payload(payload), 0);
-					}
-					else
-					{
-						LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
-					}
-// [/RLVa:KB]
-//                    LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
-                }
-            }
-        }
-        break;
-
-        case IM_GODLIKE_LURE_USER:
-        {
-            LLVector3 pos, look_at;
-            U64 region_handle(0);
-            U8 region_access(SIM_ACCESS_MIN);
-            std::string region_info = ll_safe_string((char*)binary_bucket, binary_bucket_size);
-            std::string region_access_str = LLStringUtil::null;
-            std::string region_access_icn = LLStringUtil::null;
-            std::string region_access_lc = LLStringUtil::null;
-
-            bool canUserAccessDstRegion = true;
-            bool doesUserRequireMaturityIncrease = false;
-
-            if (parse_lure_bucket(region_info, region_handle, pos, look_at, region_access))
-            {
-                region_access_str = LLViewerRegion::accessToString(region_access);
-                region_access_icn = LLViewerRegion::getAccessIcon(region_access);
-                region_access_lc = region_access_str;
-                LLStringUtil::toLower(region_access_lc);
-
-                if (!gAgent.isGodlike())
-                {
-                    switch (region_access)
-                    {
-                        case SIM_ACCESS_MIN:
-                        case SIM_ACCESS_PG:
-                            break;
-                        case SIM_ACCESS_MATURE:
-                            if (gAgent.isTeen())
-                            {
-                                canUserAccessDstRegion = false;
-                            }
-                            else if (gAgent.prefersPG())
-                            {
-                                doesUserRequireMaturityIncrease = true;
-                            }
-                            break;
-                        case SIM_ACCESS_ADULT:
-                            if (!gAgent.isAdult())
-                            {
-                                canUserAccessDstRegion = false;
-                            }
-                            else if (!gAgent.prefersAdult())
-                            {
-                                doesUserRequireMaturityIncrease = true;
-                            }
-                            break;
-                        default:
-                            llassert(0);
-                            break;
-                    }
-                }
-            }
-
-            LLSD args;
-            // *TODO: Translate -> [FIRST] [LAST] (maybe)
-            args["NAME_SLURL"] = LLSLURL("agent", from_id, "about").getSLURLString();
-            args["MESSAGE"] = message;
-            args["MATURITY_STR"] = region_access_str;
-            args["MATURITY_ICON"] = region_access_icn;
-            args["REGION_CONTENT_MATURITY"] = region_access_lc;
-            LLSD payload;
-            payload["from_id"] = from_id;
-            payload["lure_id"] = session_id;
-            payload["godlike"] = TRUE;
-            payload["region_maturity"] = region_access;
-
-            if (!canUserAccessDstRegion)
-            {
-                LLNotification::Params params("TeleportOffered_MaturityBlocked");
-                params.substitutions = args;
-                params.payload = payload;
-                LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
-                send_simple_im(from_id, LLTrans::getString("TeleportMaturityExceeded"), IM_NOTHING_SPECIAL, session_id);
-                send_simple_im(from_id, LLStringUtil::null, IM_LURE_DECLINED, session_id);
-            }
-            else if (doesUserRequireMaturityIncrease)
-            {
-                LLNotification::Params params("TeleportOffered_MaturityExceeded");
-                params.substitutions = args;
-                params.payload = payload;
-                LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
-            }
-            else
-            {
-                // do not show a message box, because you're about to be
-                // teleported.
-                LLNotifications::instance().forceResponse(LLNotification::Params("TeleportOffered").payload(payload), 0);
-            }
-        }
-        break;
-
-        case IM_GOTO_URL:
-        {
-            LLSD args;
-            // n.b. this is for URLs sent by the system, not for
-            // URLs sent by scripts (i.e. llLoadURL)
-            if (binary_bucket_size <= 0)
-            {
-                LL_WARNS("Messaging") << "bad binary_bucket_size: "
-                    << binary_bucket_size
-                    << " - aborting function." << LL_ENDL;
-                return;
-            }
-
-            std::string url;
-
-            url.assign((char*)binary_bucket, binary_bucket_size - 1);
-            args["MESSAGE"] = message;
-            args["URL"] = url;
-            LLSD payload;
-            payload["url"] = url;
-            LLNotificationsUtil::add("GotoURL", args, payload);
-        }
-        break;
-
-        case IM_FRIENDSHIP_OFFERED:
-        {
-            if (is_rejecting_friendship_requests)
-            {
-                send_rejecting_friendship_requests_message(gMessageSystem, from_id);
-                return;
-            }
-
-            LLSD payload;
-            payload["from_id"] = from_id;
-            payload["session_id"] = session_id;
-            payload["online"] = (offline == IM_ONLINE);
-            payload["sender"] = sender.getIPandPort();
-
-            bool add_notification = true;
-            for (auto& panel : LLToastNotifyPanel::instance_snapshot())
-            {
-                const std::string& notification_name = panel.getNotificationName();
-                if (notification_name == "OfferFriendship" && panel.isControlPanelEnabled())
-                {
-                    add_notification = false;
-                    break;
-                }
-            }
-
-            if (is_muted && add_notification)
-            {
-                LLNotifications::instance().forceResponse(LLNotification::Params("OfferFriendship").payload(payload), 1);
-            }
-            else
-            {
-                if (is_do_not_disturb)
-                {
-                    send_do_not_disturb_message(gMessageSystem, from_id);
-                }
-// [SL:KB] - Patch: UI-Notifications | Checked: 2011-04-11 (Catznip-2.5.0a) | Added: Catznip-2.5.0a
-				args["NAME_LABEL"] = LLSLURL("agent", from_id, "completename").getSLURLString();
-// [/SL:KB]
-                args["NAME_SLURL"] = LLSLURL("agent", from_id, "about").getSLURLString();
-
-                if (add_notification)
-                {
-                    if (message.empty())
-                    {
-                        //support for frienship offers from clients before July 2008
-                        LLNotificationsUtil::add("OfferFriendshipNoMessage", args, payload);
-                    }
-                    else
-                    {
-                        args["[MESSAGE]"] = message;
-                        LLNotification::Params params("OfferFriendship");
-                        params.substitutions = args;
-                        params.payload = payload;
-                        LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
-                    }
-                }
-            }
-        }
-        break;
-
-        case IM_FRIENDSHIP_ACCEPTED:
-        {
-            // In the case of an offline IM, the formFriendship() may be extraneous
-            // as the database should already include the relationship.  But it
-            // doesn't hurt for dupes.
-            LLAvatarTracker::formFriendship(from_id);
-
-            std::vector<std::string> strings;
-            strings.push_back(from_id.asString());
-            send_generic_message("requestonlinenotification", strings);
-
-            args["NAME"] = name;
-            LLSD payload;
-            payload["from_id"] = from_id;
-            LLAvatarNameCache::get(from_id, boost::bind(&notification_display_name_callback, _1, _2, "FriendshipAccepted", args, payload));
-        }
-        break;
-
-        case IM_FRIENDSHIP_DECLINED_DEPRECATED:
-        default:
-            LL_WARNS("Messaging") << "Instant message calling for unknown dialog "
-                << (S32)dialog << LL_ENDL;
-            break;
-    }
-
-    LLWindow* viewer_window = gViewerWindow->getWindow();
-    if (viewer_window && viewer_window->getMinimized())
-    {
-        viewer_window->flashIcon(5.f);
-    }
-}
-
-void LLIMProcessing::requestOfflineMessages()
-{
-    static BOOL requested = FALSE;
-    if (!requested
-        && gMessageSystem
-        && !gDisconnected
-        && LLMuteList::getInstance()->isLoaded()
-        && isAgentAvatarValid()
-        && gAgent.getRegion()
-        && gAgent.getRegion()->capabilitiesReceived())
-    {
-        std::string cap_url = gAgent.getRegionCapability("ReadOfflineMsgs");
-
-        // Auto-accepted inventory items may require the avatar object
-        // to build a correct name.  Likewise, inventory offers from
-        // muted avatars require the mute list to properly mute.
-        if (cap_url.empty()
-            || gAgent.getRegionCapability("AcceptFriendship").empty()
-            || gAgent.getRegionCapability("AcceptGroupInvite").empty())
-        {
-            // Offline messages capability provides no session/transaction ids for message AcceptFriendship and IM_GROUP_INVITATION to work
-            // So make sure we have the caps before using it.
-            requestOfflineMessagesLegacy();
-        }
-        else
-        {
-            LLCoros::instance().launch("LLIMProcessing::requestOfflineMessagesCoro",
-                boost::bind(&LLIMProcessing::requestOfflineMessagesCoro, cap_url));
-        }
-        requested = TRUE;
-    }
-}
-
-void LLIMProcessing::requestOfflineMessagesCoro(std::string url)
-{
-    LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
-    LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
-        httpAdapter(std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("requestOfflineMessagesCoro", httpPolicy));
-    LLCore::HttpRequest::ptr_t httpRequest(std::make_shared<LLCore::HttpRequest>());
-
-    LLSD result = httpAdapter->getAndSuspend(httpRequest, url);
-
-    LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
-    LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
-
-    if (!status) // success = httpResults["success"].asBoolean();
-    {
-        LL_WARNS("Messaging") << "Error requesting offline messages via capability " << url << ", Status: " << status.toString() << "\nFalling back to legacy method." << LL_ENDL;
-
-        requestOfflineMessagesLegacy();
-        return;
-    }
-
-    LLSD contents = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_CONTENT];
-
-    if (!contents.size())
-    {
-        LL_WARNS("Messaging") << "No contents received for offline messages via capability " << url << LL_ENDL;
-        return;
-    }
-
-    // Todo: once dirtsim-369 releases, remove one of the map/array options
-    LLSD messages;
-    if (contents.isArray())
-    {
-        messages = *contents.beginArray();
-    }
-    else if (contents.has("messages"))
-    {
-        messages = contents["messages"];
-    }
-    else
-    {
-        LL_WARNS("Messaging") << "Invalid offline message content received via capability " << url << LL_ENDL;
-        return;
-    }
-
-    if (!messages.isArray())
-    {
-        LL_WARNS("Messaging") << "Invalid offline message content received via capability " << url << LL_ENDL;
-        return;
-    }
-
-    if (messages.size() == 0)
-    {
-        // Nothing to process
-        return;
-    }
-
-    if (!gAgent.getRegion())
-    {
-        LL_WARNS("Messaging") << "Region null while attempting to load messages." << LL_ENDL;
-        return;
-    }
-
-    LL_INFOS("Messaging") << "Processing offline messages." << LL_ENDL;
-
-    LLHost sender = gAgent.getRegionHost();
-
-    LLSD::array_iterator i = messages.beginArray();
-    LLSD::array_iterator iEnd = messages.endArray();
-    for (; i != iEnd; ++i)
-    {
-        const LLSD &message_data(*i);
-
-        /* RIDER: Many fields in this message are using a '_' rather than the standard '-'.  This 
-         * should be changed but would require tight coordination with the simulator. 
-         */
-        LLVector3 position;
-        if (message_data.has("position"))
-        {
-            position.setValue(message_data["position"]);
-        }
-        else
-        {
-            position.set(message_data["local_x"].asReal(), message_data["local_y"].asReal(), message_data["local_z"].asReal());
-        }
-
-        std::vector<U8> bin_bucket;
-        if (message_data.has("binary_bucket"))
-        {
-            bin_bucket = message_data["binary_bucket"].asBinary();
-        }
-        else
-        {
-            bin_bucket.push_back(0);
-        }
-
-        // Todo: once drtsim-451 releases, remove the string option
-        BOOL from_group;
-        if (message_data["from_group"].isInteger())
-        {
-            from_group = message_data["from_group"].asInteger();
-        }
-        else
-        {
-            from_group = message_data["from_group"].asString() == "Y";
-        }
-
-        EInstantMessage dialog = static_cast<EInstantMessage>(message_data["dialog"].asInteger());
-        LLUUID session_id = message_data["transaction-id"].asUUID();
-        if (session_id.isNull() && dialog == IM_FROM_TASK)
-        {
-            session_id = message_data["asset_id"].asUUID();
-        }
-        LLIMProcessing::processNewMessage(
-            message_data["from_agent_id"].asUUID(),
-            from_group,
-            message_data["to_agent_id"].asUUID(),
-            message_data.has("offline") ? static_cast<U8>(message_data["offline"].asInteger()) : IM_OFFLINE,
-            dialog,
-            session_id,
-            static_cast<U32>(message_data["timestamp"].asInteger()),
-            message_data["from_agent_name"].asString(),
-            message_data["message"].asString(),
-            static_cast<U32>((message_data.has("parent_estate_id")) ? message_data["parent_estate_id"].asInteger() : 1), // 1 - IMMainland
-            message_data["region_id"].asUUID(),
-            position,
-            bin_bucket.data(),
-            bin_bucket.size(),
-            sender,
-            message_data["asset_id"].asUUID());
-
-    }
-}
-
-void LLIMProcessing::requestOfflineMessagesLegacy()
-{
-    LL_INFOS("Messaging") << "Requesting offline messages (Legacy)." << LL_ENDL;
-
-    LLMessageSystem* msg = gMessageSystem;
-    msg->newMessageFast(_PREHASH_RetrieveInstantMessages);
-    msg->nextBlockFast(_PREHASH_AgentData);
-    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-    gAgent.sendReliableMessage();
-}
-
+/**
+* @file LLIMProcessing.cpp
+* @brief Container for Instant Messaging
+*
+* $LicenseInfo:firstyear=2001&license=viewerlgpl$
+* Second Life Viewer Source Code
+* Copyright (C) 2018, Linden Research, Inc.
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License as published by the Free Software Foundation;
+* version 2.1 of the License only.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this library; if not, write to the Free Software
+* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*
+* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
+* $/LicenseInfo$
+*/
+
+#include "llviewerprecompiledheaders.h"
+
+#include "llimprocessing.h"
+
+#include "llagent.h"
+#include "llappviewer.h"
+#include "llavatarnamecache.h"
+#include "llfirstuse.h"
+#include "llfloaterreg.h"
+#include "llfloaterimnearbychat.h"
+#include "llimview.h"
+#include "llinventoryobserver.h"
+#include "llinventorymodel.h"
+#include "llmutelist.h"
+#include "llnotifications.h"
+#include "llnotificationsutil.h"
+#include "llnotificationmanager.h"
+#include "llpanelgroup.h"
+#include "llregex.h"
+#include "llregionhandle.h"
+#include "llsdserialize.h"
+#include "llslurl.h"
+#include "llstring.h"
+#include "lltoastnotifypanel.h"
+#include "lltrans.h"
+#include "llviewergenericmessage.h"
+#include "llviewerobjectlist.h"
+#include "llviewermessage.h"
+#include "llviewerwindow.h"
+#include "llviewerregion.h"
+#include "llvoavatarself.h"
+#include "llworld.h"
+// [RLVa:KB] - Checked: 2010-03-09 (RLVa-1.2.0a)
+#include "rlvactions.h"
+#include "rlvhelper.h"
+#include "rlvhandler.h"
+#include "rlvinventory.h"
+#include "rlvui.h"
+// [/RLVa:KB]
+
+#include "boost/lexical_cast.hpp"
+
+extern void on_new_message(const LLSD& msg);
+
+// Strip out "Resident" for display, but only if the message came from a user
+// (rather than a script)
+static std::string clean_name_from_im(const std::string& name, EInstantMessage type)
+{
+    switch (type)
+    {
+        case IM_NOTHING_SPECIAL:
+        case IM_MESSAGEBOX:
+        case IM_GROUP_INVITATION:
+        case IM_INVENTORY_OFFERED:
+        case IM_INVENTORY_ACCEPTED:
+        case IM_INVENTORY_DECLINED:
+        case IM_GROUP_VOTE:
+        case IM_GROUP_MESSAGE_DEPRECATED:
+            //IM_TASK_INVENTORY_OFFERED
+            //IM_TASK_INVENTORY_ACCEPTED
+            //IM_TASK_INVENTORY_DECLINED
+        case IM_NEW_USER_DEFAULT:
+        case IM_SESSION_INVITE:
+        case IM_SESSION_P2P_INVITE:
+        case IM_SESSION_GROUP_START:
+        case IM_SESSION_CONFERENCE_START:
+        case IM_SESSION_SEND:
+        case IM_SESSION_LEAVE:
+            //IM_FROM_TASK
+        case IM_DO_NOT_DISTURB_AUTO_RESPONSE:
+        case IM_CONSOLE_AND_CHAT_HISTORY:
+        case IM_LURE_USER:
+        case IM_LURE_ACCEPTED:
+        case IM_LURE_DECLINED:
+        case IM_GODLIKE_LURE_USER:
+        case IM_TELEPORT_REQUEST:
+        case IM_GROUP_ELECTION_DEPRECATED:
+            //IM_GOTO_URL
+            //IM_FROM_TASK_AS_ALERT
+        case IM_GROUP_NOTICE:
+        case IM_GROUP_NOTICE_INVENTORY_ACCEPTED:
+        case IM_GROUP_NOTICE_INVENTORY_DECLINED:
+        case IM_GROUP_INVITATION_ACCEPT:
+        case IM_GROUP_INVITATION_DECLINE:
+        case IM_GROUP_NOTICE_REQUESTED:
+        case IM_FRIENDSHIP_OFFERED:
+        case IM_FRIENDSHIP_ACCEPTED:
+        case IM_FRIENDSHIP_DECLINED_DEPRECATED:
+            //IM_TYPING_START
+            //IM_TYPING_STOP
+            return LLCacheName::cleanFullName(name);
+        default:
+            return name;
+    }
+}
+
+static std::string clean_name_from_task_im(const std::string& msg,
+    BOOL from_group)
+{
+    boost::smatch match;
+    static const boost::regex returned_exp(
+        "(.*been returned to your inventory lost and found folder by )(.+)( (from|near).*)");
+    if (ll_regex_match(msg, match, returned_exp))
+    {
+        // match objects are 1-based for groups
+        std::string final = match[1].str();
+        std::string name = match[2].str();
+        // Don't try to clean up group names
+        if (!from_group)
+        {
+            final += LLCacheName::buildUsername(name);
+        }
+        final += match[3].str();
+        return final;
+    }
+    return msg;
+}
+
+const std::string NOT_ONLINE_MSG("User not online - message will be stored and delivered later.");
+const std::string NOT_ONLINE_INVENTORY("User not online - inventory has been saved.");
+void translate_if_needed(std::string& message)
+{
+    if (message == NOT_ONLINE_MSG)
+    {
+        message = LLTrans::getString("not_online_msg");
+    }
+    else if (message == NOT_ONLINE_INVENTORY)
+    {
+        message = LLTrans::getString("not_online_inventory");
+    }
+}
+
+class LLPostponedIMSystemTipNotification : public LLPostponedNotification
+{
+protected:
+    /* virtual */
+    void modifyNotificationParams()
+    {
+        LLSD payload = mParams.payload;
+        payload["SESSION_NAME"] = mName;
+        mParams.payload = payload;
+    }
+};
+
+class LLPostponedOfferNotification : public LLPostponedNotification
+{
+protected:
+    /* virtual */
+    void modifyNotificationParams()
+    {
+        LLSD substitutions = mParams.substitutions;
+        substitutions["NAME"] = mName;
+        mParams.substitutions = substitutions;
+    }
+};
+
+void inventory_offer_handler(LLOfferInfo* info)
+{
+    // If muted, don't even go through the messaging stuff.  Just curtail the offer here.
+    // Passing in a null UUID handles the case of where you have muted one of your own objects by_name.
+    // The solution for STORM-1297 seems to handle the cases where the object is owned by someone else.
+    if (LLMuteList::getInstance()->isMuted(info->mFromID, info->mFromName) ||
+        LLMuteList::getInstance()->isMuted(LLUUID::null, info->mFromName))
+    {
+        info->forceResponse(IOR_MUTE);
+        return;
+    }
+
+    // Strip any SLURL from the message display. (DEV-2754)
+    std::string msg = info->mDesc;
+    size_t indx = msg.find(" ( http://slurl.com/secondlife/");
+    if (indx == std::string::npos)
+    {
+        // try to find new slurl host
+        indx = msg.find(" ( http://maps.secondlife.com/secondlife/");
+    }
+    if (indx != std::string::npos && indx >= 0)
+    {
+        LLStringUtil::truncate(msg, indx);
+    }
+
+    // Avoid the Accept/Discard dialog if the user so desires. JC
+    bool bAutoAccept(false);
+    if ((gSavedSettings.getBOOL("AutoAcceptNewInventory"))
+        && ((!rlv_handler_t::isEnabled()) || (!RlvInventory::instance().isGiveToRLVOffer(*info))))
+    {
+        bAutoAccept = true;
+        if (info->mType != LLAssetType::AT_NOTECARD
+            || info->mType != LLAssetType::AT_LANDMARK
+            || info->mType != LLAssetType::AT_TEXTURE)
+        {
+            LLSD args;
+            args["NAME"] = LLSLURL(info->mFromGroup ? "group" : "agent", info->mFromID, "about").getSLURLString();
+            if (info->mFromObject)
+                args["ITEM"] = msg;
+            else
+            {
+                const std::string& verb = "select?name=" + LLURI::escape(msg);
+                args["ITEM"] = LLSLURL("inventory", info->mObjectID, verb.c_str()).getSLURLString();
+            }
+            LLNotificationsUtil::add("AutoAcceptedInventory", args);
+        }
+    }
+
+    // Strip any SLURL from the message display. (DEV-2754)
+        // try to find new slurl host
+
+    LLSD args;
+    args["[OBJECTNAME]"] = msg;
+
+    LLSD payload;
+
+    // must protect against a NULL return from lookupHumanReadable()
+    std::string typestr = ll_safe_string(LLAssetType::lookupHumanReadable(info->mType));
+    if (!typestr.empty())
+    {
+        // human readable matches string name from strings.xml
+        // lets get asset type localized name
+        args["OBJECTTYPE"] = LLTrans::getString(typestr);
+    }
+    else
+    {
+        LL_WARNS("Messaging") << "LLAssetType::lookupHumanReadable() returned NULL - probably bad asset type: " << info->mType << LL_ENDL;
+        args["OBJECTTYPE"] = "";
+
+        // This seems safest, rather than propagating bogosity
+        LL_WARNS("Messaging") << "Forcing an inventory-decline for probably-bad asset type." << LL_ENDL;
+        info->forceResponse(IOR_DECLINE);
+        return;
+    }
+
+    // If mObjectID is null then generate the object_id based on msg to prevent
+    // multiple creation of chiclets for same object.
+    LLUUID object_id = info->mObjectID;
+    if (object_id.isNull())
+        object_id.generate(msg);
+
+    payload["from_id"] = info->mFromID;
+    // Needed by LLScriptFloaterManager to bind original notification with
+    // faked for toast one.
+    payload["object_id"] = object_id;
+    // Flag indicating that this notification is faked for toast.
+    payload["give_inventory_notification"] = FALSE;
+    args["OBJECTFROMNAME"] = info->mFromName;
+    args["NAME"] = info->mFromName;
+    if (info->mFromGroup)
+    {
+        args["NAME_SLURL"] = LLSLURL("group", info->mFromID, "about").getSLURLString();
+    }
+    else
+    {
+// [SL:KB] - Patch: UI-Notifications | Checked: 2011-04-11 (Catznip-2.5.0a) | Added: Catznip-2.5.0a
+        args["NAME_LABEL"] = LLSLURL("agent", info->mFromID, "completename").getSLURLString();
+// [/SL:KB]
+        args["NAME_SLURL"] = LLSLURL("agent", info->mFromID, "about").getSLURLString();
+    }
+    std::string verb = "select?name=" + LLURI::escape(msg);
+    args["ITEM_SLURL"] = LLSLURL("inventory", info->mObjectID, verb.c_str()).getSLURLString();
+
+    LLNotification::Params p;
+
+    // Object -> Agent Inventory Offer
+    if (info->mFromObject && !bAutoAccept)
+    {
+// [RLVa:KB] - Checked: RLVa-1.2.2
+        // Only filter if the object owner is a nearby agent
+        if ( (RlvActions::isRlvEnabled()) && (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, info->mFromID)) && (RlvUtil::isNearbyAgent(info->mFromID)) )
+        {
+            payload["rlv_shownames"] = TRUE;
+            args["NAME_SLURL"] = LLSLURL("agent", info->mFromID, "rlvanonym").getSLURLString();
+        }
+// [/RLVa:KB]
+
+        // Inventory Slurls don't currently work for non agent transfers, so only display the object name.
+        args["ITEM_SLURL"] = msg;
+        // Note: sets inventory_task_offer_callback as the callback
+        p.substitutions(args).payload(payload).functor.responder(LLNotificationResponderPtr(info));
+        info->mPersist = true;
+
+        // Offers from your own objects need a special notification template.
+        p.name = info->mFromID == gAgentID ? "OwnObjectGiveItem" : "ObjectGiveItem";
+
+        // Pop up inv offer chiclet and let the user accept (keep), or reject (and silently delete) the inventory.
+        LLPostponedNotification::add<LLPostponedOfferNotification>(p, info->mFromID, info->mFromGroup == TRUE);
+    }
+    else // Agent -> Agent Inventory Offer
+    {
+// [RLVa:KB] - Checked: RLVa-2.0.1
+        // Only filter if the offer is from a nearby agent and if there's no open IM session (doesn't necessarily have to be focused)
+        bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
+            (RlvActions::canShowName(RlvActions::SNC_DEFAULT, info->mFromID)) || (!RlvUtil::isNearbyAgent(info->mFromID)) || (RlvUIEnabler::hasOpenIM(info->mFromID)) || (RlvUIEnabler::hasOpenProfile(info->mFromID));
+        if (!fRlvCanShowName)
+        {
+            payload["rlv_shownames"] = TRUE;
+            LLAvatarName av_name;
+            if (LLAvatarNameCache::get(info->mFromID, &av_name))
+            {
+                args["NAME"] = RlvStrings::getAnonym(av_name);
+            }
+            else
+            {
+                args["NAME"] = RlvStrings::getAnonym(info->mFromName);
+            }
+            args["NAME_SLURL"] = LLSLURL("agent", info->mFromID, "rlvanonym").getSLURLString();
+        }
+// [/RLVa:KB]
+
+        p.responder = info;
+        // Note: sets inventory_offer_callback as the callback
+        // *TODO fix memory leak
+        // inventory_offer_callback() is not invoked if user received notification and
+        // closes viewer(without responding the notification)
+        p.substitutions(args).payload(payload).functor.responder(LLNotificationResponderPtr(info));
+        info->mPersist = true;
+        p.name = "UserGiveItem";
+        p.offer_from_agent = true;
+
+        // Prefetch the item into your local inventory.
+        LLInventoryFetchItemsObserver* fetch_item = new LLInventoryFetchItemsObserver(info->mObjectID);
+        fetch_item->startFetch();
+        if (fetch_item->isFinished())
+        {
+            fetch_item->done();
+        }
+        else
+        {
+            gInventory.addObserver(fetch_item);
+        }
+
+        // In viewer 2 we're now auto receiving inventory offers and messaging as such (not sending reject messages).
+        info->send_auto_receive_response();
+
+        if (gAgent.isDoNotDisturb())
+        {
+            send_do_not_disturb_message(gMessageSystem, info->mFromID);
+        }
+
+        if (!bAutoAccept) // if we auto accept, do not pester the user
+        {
+            // Inform user that there is a script floater via toast system
+            payload["give_inventory_notification"] = TRUE;
+            p.payload = payload;
+            LLPostponedNotification::add<LLPostponedOfferNotification>(p, info->mFromID, false);
+        }
+
+        if (bAutoAccept && gSavedSettings.getBOOL("ShowNewInventory"))
+        {
+            LLViewerInventoryCategory* catp = NULL;
+            catp = (LLViewerInventoryCategory*)gInventory.getCategory(info->mObjectID);
+            LLViewerInventoryItem* itemp = NULL;
+            if(!catp)
+            {
+                itemp = (LLViewerInventoryItem*)gInventory.getItem(info->mObjectID);
+            }
+
+            LLOpenAgentOffer* open_agent_offer = new LLOpenAgentOffer(info->mObjectID, info->mFromName, false);
+            open_agent_offer->startFetch();
+            if(catp || (itemp && itemp->isFinished()))
+            {
+                open_agent_offer->done();
+            }
+            else
+            {
+                gInventory.addObserver(open_agent_offer);
+            }
+        }
+    }
+
+    LLFirstUse::newInventory();
+}
+
+// Callback for name resolution of a god/estate message
+static void god_message_name_cb(const LLAvatarName& av_name, LLChat chat, std::string message)
+{
+    LLSD args;
+    args["NAME"] = av_name.getCompleteName();
+    args["MESSAGE"] = message;
+    LLNotificationsUtil::add("GodMessage", args);
+
+    // Treat like a system message and put in chat history.
+    chat.mSourceType = CHAT_SOURCE_SYSTEM;
+    chat.mText = message;
+
+    LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
+    if (nearby_chat)
+    {
+        nearby_chat->addMessage(chat);
+    }
+}
+
+static bool parse_lure_bucket(const std::string& bucket,
+    U64& region_handle,
+    LLVector3& pos,
+    LLVector3& look_at,
+    U8& region_access)
+{
+    // tokenize the bucket
+    typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+    boost::char_separator<char> sep("|", "", boost::keep_empty_tokens);
+    tokenizer tokens(bucket, sep);
+    tokenizer::iterator iter = tokens.begin();
+
+    S32 gx, gy, rx, ry, rz, lx, ly, lz;
+    try
+    {
+        gx = boost::lexical_cast<S32>((*(iter)).c_str());
+        gy = boost::lexical_cast<S32>((*(++iter)).c_str());
+        rx = boost::lexical_cast<S32>((*(++iter)).c_str());
+        ry = boost::lexical_cast<S32>((*(++iter)).c_str());
+        rz = boost::lexical_cast<S32>((*(++iter)).c_str());
+        lx = boost::lexical_cast<S32>((*(++iter)).c_str());
+        ly = boost::lexical_cast<S32>((*(++iter)).c_str());
+        lz = boost::lexical_cast<S32>((*(++iter)).c_str());
+    }
+    catch (const boost::bad_lexical_cast&)
+    {
+        LL_WARNS("parse_lure_bucket")
+            << "Couldn't parse lure bucket."
+            << LL_ENDL;
+        return false;
+    }
+    // Grab region access
+    region_access = SIM_ACCESS_MIN;
+    if (++iter != tokens.end())
+    {
+        std::string access_str((*iter).c_str());
+        LLStringUtil::trim(access_str);
+        if (access_str == "A")
+        {
+            region_access = SIM_ACCESS_ADULT;
+        }
+        else if (access_str == "M")
+        {
+            region_access = SIM_ACCESS_MATURE;
+        }
+        else if (access_str == "PG")
+        {
+            region_access = SIM_ACCESS_PG;
+        }
+    }
+
+    pos.setVec((F32)rx, (F32)ry, (F32)rz);
+    look_at.setVec((F32)lx, (F32)ly, (F32)lz);
+
+    region_handle = to_region_handle(gx, gy);
+    return true;
+}
+
+static void notification_display_name_callback(const LLUUID& id,
+    const LLAvatarName& av_name,
+    const std::string& name,
+    LLSD& substitutions,
+    const LLSD& payload)
+{
+    substitutions["NAME"] = av_name.getDisplayName();
+    LLNotificationsUtil::add(name, substitutions, payload);
+}
+
+void LLIMProcessing::processNewMessage(LLUUID from_id,
+    BOOL from_group,
+    LLUUID to_id,
+    U8 offline,
+    EInstantMessage dialog, // U8
+    LLUUID session_id,
+    U32 timestamp,
+    std::string name,
+    std::string message,
+    U32 parent_estate_id,
+    LLUUID region_id,
+    LLVector3 position,
+    U8 *binary_bucket,
+    S32 binary_bucket_size,
+    LLHost &sender,
+    LLUUID aux_id)
+{
+    LLChat chat;
+    std::string buffer;
+
+    // make sure that we don't have an empty or all-whitespace name
+    LLStringUtil::trim(name);
+    static const LLCachedControl<bool> sMarkUnnamedObjects(gSavedSettings, "AlchemyChatMarkUnnamedObjects", true);
+    if (sMarkUnnamedObjects && name.empty())
+    {
+        name = LLTrans::getString("Unnamed");
+    }
+
+    // Preserve the unaltered name for use in group notice mute checking.
+    std::string original_name = name;
+
+    // IDEVO convert new-style "Resident" names for display
+    name = clean_name_from_im(name, dialog);
+
+    BOOL is_do_not_disturb = gAgent.isDoNotDisturb();
+    BOOL is_rejecting_tp_offers = gAgent.isRejectTeleportOffers();
+    static LLCachedControl<bool> ALDontRejectTeleportOffersFromFriends(gSavedPerAccountSettings, "ALDontRejectTeleportOffersFromFriends");
+
+    BOOL is_muted = LLMuteList::getInstance()->isMuted(from_id, name, LLMute::flagTextChat)
+        // object IMs contain sender object id in session_id (STORM-1209)
+        || (dialog == IM_FROM_TASK && LLMuteList::getInstance()->isMuted(session_id));
+
+    BOOL is_rejecting_friendship_requests = gAgent.getRejectFriendshipRequests();
+
+    BOOL is_owned_by_me = FALSE;
+    BOOL is_friend = (LLAvatarTracker::instance().getBuddyInfo(from_id) == NULL) ? false : true;
+    BOOL accept_im_from_only_friend = gSavedPerAccountSettings.getBOOL("VoiceCallsFriendsOnly");
+    BOOL is_linden = chat.mSourceType != CHAT_SOURCE_OBJECT &&
+        LLMuteList::isLinden(name);
+
+    chat.mMuted = is_muted;
+    chat.mFromID = from_id;
+    chat.mFromName = name;
+    chat.mSourceType = (from_id.isNull() || (name == std::string(SYSTEM_FROM))) ? CHAT_SOURCE_SYSTEM : CHAT_SOURCE_AGENT;
+
+    if (chat.mSourceType == CHAT_SOURCE_SYSTEM)
+    { // Translate server message if required (MAINT-6109)
+        translate_if_needed(message);
+    }
+
+    LLViewerObject *source = gObjectList.findObject(session_id); //Session ID is probably the wrong thing.
+    if (source)
+    {
+        is_owned_by_me = source->permYouOwner();
+    }
+
+    std::string separator_string(": ");
+
+    LLSD args;
+    LLSD payload;
+    LLNotification::Params params;
+
+    switch (dialog)
+    {
+        case IM_CONSOLE_AND_CHAT_HISTORY:
+            args["MESSAGE"] = message;
+            payload["from_id"] = from_id;
+
+            params.name = "IMSystemMessageTip";
+            params.substitutions = args;
+            params.payload = payload;
+            LLPostponedNotification::add<LLPostponedIMSystemTipNotification>(params, from_id, false);
+            break;
+
+        case IM_NOTHING_SPECIAL:    // p2p IM
+            // Don't show dialog, just do IM
+            if (!gAgent.isGodlike()
+                && gAgent.getRegion()->isPrelude()
+                && to_id.isNull())
+            {
+                // do nothing -- don't distract newbies in
+                // Prelude with global IMs
+            }
+// [RLVa:KB] - Checked: RLVa-2.1.0
+            else if ( (RlvActions::isRlvEnabled()) && (offline == IM_ONLINE) && (!is_muted) && ((!accept_im_from_only_friend) || (is_friend)) &&
+                      (message.length() > 3) && (RLV_CMD_PREFIX == message[0]) && (RlvHandler::instance().processIMQuery(from_id, message)) )
+            {
+                // Eat the message and do nothing
+            }
+// [/RLVa:KB]
+//            else if (offline == IM_ONLINE
+//                && is_do_not_disturb
+//                && from_id.notNull() //not a system message
+//                && to_id.notNull()) //not global message
+// [RLVa:KB] - Checked: 2010-11-30 (RLVa-1.3.0)
+            else if (offline == IM_ONLINE
+                && is_do_not_disturb
+                && from_id.notNull() //not a system message
+                && to_id.notNull() //not global message
+                && RlvActions::canReceiveIM(from_id))
+// [/RLVa:KB]
+            {
+
+                // now store incoming IM in chat history
+
+                buffer = message;
+
+                LL_DEBUGS("Messaging") << "session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
+
+                // add to IM panel, but do not bother the user
+                gIMMgr->addMessage(
+                    session_id,
+                    from_id,
+                    name,
+                    buffer,
+                    IM_OFFLINE == offline,
+                    LLStringUtil::null,
+                    dialog,
+                    parent_estate_id,
+                    region_id,
+                    position,
+                    false,      // is_region_msg
+                    timestamp);
+
+                if (!gIMMgr->isDNDMessageSend(session_id))
+                {
+                    // return a standard "do not disturb" message, but only do it to online IM
+                    // (i.e. not other auto responses and not store-and-forward IM)
+                    send_do_not_disturb_message(gMessageSystem, from_id, session_id);
+                    gIMMgr->setDNDMessageSent(session_id, true);
+                }
+
+            }
+            else if (from_id.isNull())
+            {
+                LLSD args;
+                args["MESSAGE"] = message;
+                LLNotificationsUtil::add("SystemMessage", args);
+            }
+            else if (to_id.isNull())
+            {
+                // Message to everyone from GOD, look up the fullname since
+                // server always slams name to legacy names
+                LLAvatarNameCache::get(from_id, boost::bind(god_message_name_cb, _2, chat, message));
+            }
+            else
+            {
+                // standard message, not from system
+                std::string saved;
+                if (offline == IM_OFFLINE)
+                {
+                    LLStringUtil::format_map_t args;
+                    args["[LONG_TIMESTAMP]"] = formatted_time(timestamp);
+                    saved = LLTrans::getString("Saved_message", args);
+                }
+                buffer = saved + message;
+
+                LL_DEBUGS("Messaging") << "session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
+
+                bool mute_im = is_muted;
+                if (accept_im_from_only_friend && !is_friend && !is_linden)
+                {
+                    if (!gIMMgr->isNonFriendSessionNotified(session_id))
+                    {
+                        std::string message = LLTrans::getString("IM_unblock_only_groups_friends");
+                        gIMMgr->addMessage(session_id, from_id, name, message, IM_OFFLINE == offline);
+                        gIMMgr->addNotifiedNonFriendSessionID(session_id);
+                    }
+
+                    mute_im = true;
+                }
+
+// [RLVa:KB] - Checked: 2010-11-30 (RLVa-1.3.0)
+                // Don't block offline IMs, or IMs from Lindens
+                if ( (rlv_handler_t::isEnabled()) && (offline != IM_OFFLINE) && (!RlvActions::canReceiveIM(from_id)) && (!LLMuteList::isLinden(original_name) ))
+                {
+                    if (!mute_im)
+                        RlvUtil::sendBusyMessage(from_id, RlvStrings::getString(RlvStringKeys::Blocked::RecvImRemote), session_id);
+                    buffer = RlvStrings::getString(RlvStringKeys::Blocked::RecvIm);
+                }
+// [/RLVa:KB]
+
+                if (!mute_im)
+                {
+                    bool region_message = false;
+                    if (region_id.isNull())
+                    {
+                        LLViewerRegion* regionp = LLWorld::instance().getRegionFromID(from_id);
+                        if (regionp)
+                        {
+                            region_message = true;
+                        }
+                    }
+                    gIMMgr->addMessage(
+                        session_id,
+                        from_id,
+                        name,
+                        buffer,
+                        IM_OFFLINE == offline,
+                        LLStringUtil::null,
+                        dialog,
+                        parent_estate_id,
+                        region_id,
+                        position,
+                        region_message,
+                        timestamp);
+                }
+                else
+                {
+                    /*
+                    EXT-5099
+                    */
+                }
+            }
+            break;
+
+        case IM_TYPING_START:
+        {
+            static LLCachedControl<bool> sNotifyIncomingMessage(gSavedSettings, "AlchemyNotifyIncomingMessage");
+            if (sNotifyIncomingMessage &&
+                !gIMMgr->hasSession(session_id) &&
+                ((accept_im_from_only_friend && (is_friend || is_linden)) ||
+                (!(is_muted || is_do_not_disturb)))
+                )
+            {
+                LLStringUtil::format_map_t args;
+                args["[NAME]"] = name;
+                const std::string notify_str = LLTrans::getString("NotifyIncomingMessage", args);
+                gIMMgr->addMessage(session_id,
+                    from_id,
+                    LLStringUtil::null,
+                    notify_str,
+                    IM_ONLINE,
+                    LLStringUtil::null,
+                    IM_NOTHING_SPECIAL,
+                    parent_estate_id,
+                    region_id,
+                    position,
+                    false,
+                    0
+                );
+            }
+
+            gIMMgr->processIMTypingStart(from_id, dialog);
+        }
+        break;
+
+        case IM_TYPING_STOP:
+        {
+            gIMMgr->processIMTypingStop(from_id, dialog);
+        }
+        break;
+
+        case IM_MESSAGEBOX:
+        {
+            // This is a block, modeless dialog.
+            args["MESSAGE"] = message;
+            LLNotificationsUtil::add("SystemMessageTip", args);
+        }
+        break;
+        case IM_GROUP_NOTICE:
+        case IM_GROUP_NOTICE_REQUESTED:
+        {
+            LL_INFOS("Messaging") << "Received IM_GROUP_NOTICE message." << LL_ENDL;
+
+            LLUUID agent_id;
+            U8 has_inventory;
+            U8 asset_type = 0;
+            LLUUID group_id;
+            std::string item_name;
+
+            if (aux_id.notNull())
+            {
+                // aux_id contains group id, binary bucket contains name and asset type
+                group_id = aux_id;
+                has_inventory = binary_bucket_size > 1 ? TRUE : FALSE;
+                from_group = TRUE; // inaccurate value correction
+                if (has_inventory)
+                {
+                    std::string str_bucket = ll_safe_string((char*)binary_bucket, binary_bucket_size);
+
+                    typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+                    boost::char_separator<char> sep("|", "", boost::keep_empty_tokens);
+                    tokenizer tokens(str_bucket, sep);
+                    tokenizer::iterator iter = tokens.begin();
+
+                    asset_type = (LLAssetType::EType)(atoi((*(iter++)).c_str()));
+                    iter++; // wearable type if applicable, otherwise asset type
+                    item_name = std::string((*(iter++)).c_str());
+                    // Note There is more elements in 'tokens' ...
+
+
+                    for (int i = 0; i < 6; i++)
+                    {
+                        LL_WARNS() << *(iter++) << LL_ENDL;
+                        iter++;
+                    }
+                }
+            }
+            else
+            {
+                // All info is in binary bucket, read it for more information.
+                struct notice_bucket_header_t
+                {
+                    U8 has_inventory;
+                    U8 asset_type;
+                    LLUUID group_id;
+                };
+                struct notice_bucket_full_t
+                {
+                    struct notice_bucket_header_t header;
+                    U8 item_name[DB_INV_ITEM_NAME_BUF_SIZE];
+                }*notice_bin_bucket;
+
+                // Make sure the binary bucket is big enough to hold the header
+                // and a null terminated item name.
+                if ((binary_bucket_size < (S32)((sizeof(notice_bucket_header_t) + sizeof(U8))))
+                    || (binary_bucket[binary_bucket_size - 1] != '\0'))
+                {
+                    LL_WARNS("Messaging") << "Malformed group notice binary bucket" << LL_ENDL;
+                    break;
+                }
+
+                notice_bin_bucket = (struct notice_bucket_full_t*) &binary_bucket[0];
+                has_inventory = notice_bin_bucket->header.has_inventory;
+                asset_type = notice_bin_bucket->header.asset_type;
+                group_id = notice_bin_bucket->header.group_id;
+                item_name = ll_safe_string((const char*)notice_bin_bucket->item_name);
+            }
+
+            if (group_id != from_id)
+            {
+                agent_id = from_id;
+            }
+            else
+            {
+                std::string::size_type index = original_name.find(" Resident");
+                if (index != std::string::npos)
+                {
+                    original_name = original_name.substr(0, index);
+                }
+
+                // The group notice packet does not have an AgentID.  Obtain one from the name cache.
+                // If last name is "Resident" strip it out so the cache name lookup works.
+                std::string legacy_name = gCacheName->buildLegacyName(original_name);
+                agent_id = LLAvatarNameCache::getInstance()->findIdByName(legacy_name);
+
+                if (agent_id.isNull())
+                {
+                    LL_WARNS("Messaging") << "buildLegacyName returned null while processing " << original_name << LL_ENDL;
+                }
+            }
+
+            if (agent_id.notNull() && LLMuteList::getInstance()->isMuted(agent_id))
+            {
+                break;
+            }
+
+            // If there is inventory, give the user the inventory offer.
+            LLOfferInfo* info = NULL;
+
+            if (has_inventory)
+            {
+                info = new LLOfferInfo();
+
+                info->mIM = dialog;
+                info->mFromID = from_id;
+                info->mFromGroup = from_group;
+                info->mTransactionID = session_id;
+                info->mType = (LLAssetType::EType) asset_type;
+                info->mFolderID = gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(info->mType));
+                std::string from_name;
+
+                from_name += "A group member named ";
+                from_name += name;
+
+                info->mFromName = from_name;
+                info->mDesc = item_name;
+                info->mHost = sender;
+            }
+
+            std::string str(message);
+
+            // Tokenize the string.
+            // TODO: Support escaped tokens ("||" -> "|")
+            typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+            boost::char_separator<char> sep("|", "", boost::keep_empty_tokens);
+            tokenizer tokens(str, sep);
+            tokenizer::iterator iter = tokens.begin();
+
+            std::string subj(*iter++);
+            std::string mes(*iter++);
+
+            // Send the notification down the new path.
+            // For requested notices, we don't want to send the popups.
+            if (dialog != IM_GROUP_NOTICE_REQUESTED)
+            {
+                payload["subject"] = subj;
+                payload["message"] = mes;
+                payload["sender_name"] = name;
+                payload["sender_id"] = agent_id;
+                payload["group_id"] = group_id;
+                payload["inventory_name"] = item_name;
+                payload["received_time"] = LLDate::now();
+                if (info && info->asLLSD())
+                {
+                    payload["inventory_offer"] = info->asLLSD();
+                }
+
+                LLSD args;
+                args["SUBJECT"] = subj;
+                args["MESSAGE"] = mes;
+                LLDate notice_date = LLDate(timestamp).notNull() ? LLDate(timestamp) : LLDate::now();
+                LLNotifications::instance().add(LLNotification::Params("GroupNotice").substitutions(args).payload(payload).time_stamp(notice_date));
+            }
+
+            // Also send down the old path for now.
+            if (IM_GROUP_NOTICE_REQUESTED == dialog)
+            {
+
+                LLPanelGroup::showNotice(subj, mes, group_id, has_inventory, item_name, info);
+            }
+            else
+            {
+                delete info;
+            }
+        }
+        break;
+        case IM_GROUP_INVITATION:
+        {
+            if (!is_muted)
+            {
+                // group is not blocked, but we still need to check agent that sent the invitation
+                // and we have no agent's id
+                // Note: server sends username "first.last".
+                is_muted |= LLMuteList::getInstance()->isMuted(name);
+            }
+            if (is_do_not_disturb || is_muted)
+            {
+                send_do_not_disturb_message(gMessageSystem, from_id);
+            }
+
+            if (!is_muted)
+            {
+                LL_INFOS("Messaging") << "Received IM_GROUP_INVITATION message." << LL_ENDL;
+                // Read the binary bucket for more information.
+                struct invite_bucket_t
+                {
+                    S32 membership_fee;
+                    LLUUID role_id;
+                }*invite_bucket;
+
+                // Make sure the binary bucket is the correct size.
+                if (binary_bucket_size != sizeof(invite_bucket_t))
+                {
+                    LL_WARNS("Messaging") << "Malformed group invite binary bucket" << LL_ENDL;
+                    break;
+                }
+
+                invite_bucket = (struct invite_bucket_t*) &binary_bucket[0];
+                S32 membership_fee = ntohl(invite_bucket->membership_fee);
+
+                LLSD payload;
+                payload["transaction_id"] = session_id;
+                payload["group_id"] = from_group ? from_id : aux_id;
+                payload["name"] = name;
+                payload["message"] = message;
+                payload["fee"] = membership_fee;
+                payload["use_offline_cap"] = session_id.isNull() && (offline == IM_OFFLINE);
+
+                LLSD args;
+                args["MESSAGE"] = message;
+                // we shouldn't pass callback functor since it is registered in LLFunctorRegistration
+                LLNotificationsUtil::add("JoinGroup", args, payload);
+            }
+        }
+        break;
+
+        case IM_INVENTORY_OFFERED:
+        case IM_TASK_INVENTORY_OFFERED:
+            // Someone has offered us some inventory.
+        {
+            LLOfferInfo* info = new LLOfferInfo;
+            if (IM_INVENTORY_OFFERED == dialog)
+            {
+                struct offer_agent_bucket_t
+                {
+                    S8      asset_type;
+                    LLUUID  object_id;
+                }*bucketp;
+
+                if (sizeof(offer_agent_bucket_t) != binary_bucket_size)
+                {
+                    LL_WARNS("Messaging") << "Malformed inventory offer from agent" << LL_ENDL;
+                    delete info;
+                    break;
+                }
+                bucketp = (struct offer_agent_bucket_t*) &binary_bucket[0];
+                info->mType = (LLAssetType::EType) bucketp->asset_type;
+                info->mObjectID = bucketp->object_id;
+                info->mFromObject = FALSE;
+            }
+            else // IM_TASK_INVENTORY_OFFERED
+            {
+                if (sizeof(S8) == binary_bucket_size)
+                {
+                    info->mType = (LLAssetType::EType) binary_bucket[0];
+                }
+                else
+                {
+                    /*RIDER*/ // The previous version of the protocol returned the wrong binary bucket... we
+                    // still might be able to figure out the type... even though the offer is not retrievable.
+
+                    // Should be safe to remove once DRTSIM-451 fully deploys
+                    std::string str_bucket(reinterpret_cast<char *>(binary_bucket));
+                    std::string str_type(str_bucket.substr(0, str_bucket.find('|')));
+
+                    std::stringstream type_convert(str_type);
+
+                    S32 type;
+                    type_convert >> type;
+
+                    // We could try AT_UNKNOWN which would be more accurate, but that causes an auto decline
+                    info->mType = static_cast<LLAssetType::EType>(type);
+                    // Don't break in the case of a bad binary bucket.  Go ahead and show the
+                    // accept/decline popup even though it will not do anything.
+                    LL_WARNS("Messaging") << "Malformed inventory offer from object, type might be " << info->mType << LL_ENDL;
+                }
+                info->mObjectID = LLUUID::null;
+                info->mFromObject = TRUE;
+            }
+
+            info->mIM = dialog;
+            info->mFromID = from_id;
+            info->mFromGroup = from_group;
+            info->mFolderID = gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(info->mType));
+
+            info->mTransactionID = session_id.notNull() ? session_id : aux_id;
+
+            info->mFromName = name;
+            info->mDesc = message;
+            info->mHost = sender;
+            //if (((is_do_not_disturb && !is_owned_by_me) || is_muted))
+            if (is_muted)
+            {
+                // Prefetch the offered item so that it can be discarded by the appropriate observer. (EXT-4331)
+                if (IM_INVENTORY_OFFERED == dialog)
+                {
+                    LLInventoryFetchItemsObserver* fetch_item = new LLInventoryFetchItemsObserver(info->mObjectID);
+                    fetch_item->startFetch();
+                    delete fetch_item;
+                    // Same as closing window
+                    info->forceResponse(IOR_DECLINE);
+                }
+                else
+                {
+                    info->forceResponse(IOR_MUTE);
+                }
+            }
+            // old logic: busy mode must not affect interaction with objects (STORM-565)
+            // new logic: inventory offers from in-world objects should be auto-declined (CHUI-519)
+            else if (is_do_not_disturb && dialog == IM_TASK_INVENTORY_OFFERED)
+            {
+                // Until throttling is implemented, do not disturb mode should reject inventory instead of silently
+                // accepting it.  SEE SL-39554
+                info->forceResponse(IOR_DECLINE);
+            }
+            else
+            {
+                inventory_offer_handler(info);
+            }
+        }
+        break;
+
+        case IM_INVENTORY_ACCEPTED:
+        {
+//            args["NAME"] = LLSLURL("agent", from_id, "completename").getSLURLString();;
+//            args["ORIGINAL_NAME"] = original_name;
+// [RLVa:KB] - Checked: RLVa-1.2.2
+            // Only anonymize the name if the agent is nearby, there isn't an open IM session to them and their profile isn't open
+            bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
+                (RlvActions::canShowName(RlvActions::SNC_DEFAULT, from_id)) || (!RlvUtil::isNearbyAgent(from_id)) || (RlvUIEnabler::hasOpenProfile(from_id)) || (RlvUIEnabler::hasOpenIM(from_id));
+            args["NAME"] = LLSLURL("agent", from_id, (fRlvCanShowName) ? "completename" : "rlvanonym").getSLURLString();
+            if (RlvActions::canShowName(RlvActions::SNC_DEFAULT, from_id))
+                args["ORIGINAL_NAME"] = original_name;
+            else
+                args["ORIGINAL_NAME"] = RlvStrings::getAnonym(original_name);
+// [/RLVa:KB]
+            LLSD payload;
+            payload["from_id"] = from_id;
+            // Passing the "SESSION_NAME" to use it for IM notification logging
+            // in LLTipHandler::processNotification(). See STORM-941.
+            payload["SESSION_NAME"] = name;
+            LLNotificationsUtil::add("InventoryAccepted", args, payload);
+            break;
+        }
+        case IM_INVENTORY_DECLINED:
+        {
+//            args["NAME"] = LLSLURL("agent", from_id, "completename").getSLURLString();;
+// [RLVa:KB] - Checked: RLVa-1.2.2
+            // Only anonymize the name if the agent is nearby, there isn't an open IM session to them and their profile isn't open
+            bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
+                (RlvActions::canShowName(RlvActions::SNC_DEFAULT, from_id)) || (!RlvUtil::isNearbyAgent(from_id)) || (RlvUIEnabler::hasOpenProfile(from_id)) || (RlvUIEnabler::hasOpenIM(from_id));
+            args["NAME"] = LLSLURL("agent", from_id, (fRlvCanShowName) ? "completename" : "rlvanonym").getSLURLString();;
+// [/RLVa:KB]
+            LLSD payload;
+            payload["from_id"] = from_id;
+            LLNotificationsUtil::add("InventoryDeclined", args, payload);
+            break;
+        }
+        // TODO: _DEPRECATED suffix as part of vote removal - DEV-24856
+        case IM_GROUP_VOTE:
+        {
+            LL_WARNS("Messaging") << "Received IM: IM_GROUP_VOTE_DEPRECATED" << LL_ENDL;
+        }
+        break;
+
+        case IM_GROUP_ELECTION_DEPRECATED:
+        {
+            LL_WARNS("Messaging") << "Received IM: IM_GROUP_ELECTION_DEPRECATED" << LL_ENDL;
+        }
+        break;
+
+        case IM_FROM_TASK:
+        {
+
+            if (is_do_not_disturb && !is_owned_by_me)
+            {
+                return;
+            }
+
+            // Build a link to open the object IM info window.
+            std::string location = ll_safe_string((char*)binary_bucket, binary_bucket_size - 1);
+
+            if (session_id.notNull())
+            {
+                chat.mFromID = session_id;
+            }
+            else
+            {
+                // This message originated on a region without the updated code for task id and slurl information.
+                // We just need a unique ID for this object that isn't the owner ID.
+                // If it is the owner ID it will overwrite the style that contains the link to that owner's profile.
+                // This isn't ideal - it will make 1 style for all objects owned by the the same person/group.
+                // This works because the only thing we can really do in this case is show the owner name and link to their profile.
+                chat.mFromID = from_id ^ gAgent.getSessionID();
+            }
+
+            chat.mSourceType = CHAT_SOURCE_OBJECT;
+
+            // To conclude that the source type of message is CHAT_SOURCE_SYSTEM it's not
+            // enough to check only from name (i.e. fromName = "Second Life"). For example
+            // source type of messages from objects called "Second Life" should not be CHAT_SOURCE_SYSTEM.
+            bool chat_from_system = (SYSTEM_FROM == name) && region_id.isNull() && position.isNull();
+            if (chat_from_system)
+            {
+                // System's UUID is NULL (fixes EXT-4766)
+                chat.mFromID = LLUUID::null;
+                chat.mSourceType = CHAT_SOURCE_SYSTEM;
+            }
+
+            // IDEVO Some messages have embedded resident names
+            message = clean_name_from_task_im(message, from_group);
+
+            LLSD query_string;
+            query_string["owner"] = from_id;
+// [RLVa:KB] - Checked: RLVa-1.2.0
+            if (RlvActions::isRlvEnabled())
+            {
+                // NOTE: the chat message itself will be filtered in LLNearbyChatHandler::processChat()
+                if ( (!RlvActions::canShowName(RlvActions::SNC_DEFAULT)) && (!from_group) && (RlvUtil::isNearbyAgent(from_id)) )
+                {
+                    query_string["rlv_shownames"] = TRUE;
+
+                    RlvUtil::filterNames(name);
+                    chat.mFromName = name;
+                }
+                if (!RlvActions::canShowLocation())
+                {
+                    std::string::size_type idxPos = location.find('/');
+                    if ( (std::string::npos != idxPos) && (RlvUtil::isNearbyRegion(location.substr(0, idxPos))) )
+                        location = RlvStrings::getString(RlvStringKeys::Hidden::Region);
+                }
+            }
+// [/RLVa:KB]
+            query_string["slurl"] = location;
+            query_string["name"] = name;
+            if (from_group)
+            {
+                query_string["groupowned"] = "true";
+            }
+
+//           chat.mURL = LLSLURL("objectim", session_id, "").getSLURLString();
+// [SL:KB] - Checked: 2010-11-02 (RLVa-1.2.2a) | Added: RLVa-1.2.2a
+            chat.mURL = LLSLURL("objectim", session_id, LLURI::mapToQueryString(query_string)).getSLURLString();
+// [/SL:KB]
+           chat.mText = message;
+
+            // Note: lie to Nearby Chat, pretending that this is NOT an IM, because
+            // IMs from obejcts don't open IM sessions.
+            LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
+            if (!chat_from_system && nearby_chat)
+            {
+                chat.mOwnerID = from_id;
+                LLSD args;
+                args["slurl"] = location;
+
+                // Look for IRC-style emotes here so object name formatting is correct
+                std::string prefix = message.substr(0, 4);
+                if (prefix == "/me " || prefix == "/me'")
+                {
+                    chat.mChatStyle = CHAT_STYLE_IRC;
+                }
+
+                LLNotificationsUI::LLNotificationManager::instance().onChat(chat, args);
+                if (message != "")
+                {
+                    LLSD msg_notify;
+                    msg_notify["session_id"] = LLUUID();
+                    msg_notify["from_id"] = chat.mFromID;
+                    msg_notify["source_type"] = chat.mSourceType;
+                    on_new_message(msg_notify);
+                }
+            }
+
+
+            //Object IMs send with from name: 'Second Life' need to be displayed also in notification toasts (EXT-1590)
+            if (!chat_from_system) break;
+
+            LLSD substitutions;
+            substitutions["NAME"] = name;
+            substitutions["MSG"] = message;
+
+            LLSD payload;
+            payload["object_id"] = session_id;
+            payload["owner_id"] = from_id;
+            payload["from_id"] = from_id;
+            payload["slurl"] = location;
+            payload["name"] = name;
+
+            if (from_group)
+            {
+                payload["group_owned"] = "true";
+            }
+
+            LLNotificationsUtil::add("ServerObjectMessage", substitutions, payload);
+        }
+        break;
+
+        case IM_SESSION_SEND:       // ad-hoc or group IMs
+
+            // Only show messages if we have a session open (which
+            // should happen after you get an "invitation"
+//           if (!gIMMgr->hasSession(session_id))
+// [SL:KB] - Patch: Chat-GroupSnooze | Checked: Catznip-3.3
+            if (!gIMMgr->hasSession(session_id) && (!gAgent.isInGroup(session_id) || (!gIMMgr->checkSnoozeExpiration(session_id) || !gIMMgr->restoreSnoozedSession(session_id))) )
+// [/SL:KB]
+            {
+                return;
+            }
+
+            else if (offline == IM_ONLINE && is_do_not_disturb)
+            {
+
+                // return a standard "do not disturb" message, but only do it to online IM
+                // (i.e. not other auto responses and not store-and-forward IM)
+                if (!gIMMgr->hasSession(session_id))
+                {
+                    // if there is not a panel for this conversation (i.e. it is a new IM conversation
+                    // initiated by the other party) then...
+                    send_do_not_disturb_message(gMessageSystem, from_id, session_id);
+                }
+
+                // now store incoming IM in chat history
+
+                buffer = message;
+
+                LL_DEBUGS("Messaging") << "message in dnd; session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
+
+                // add to IM panel, but do not bother the user
+                gIMMgr->addMessage(
+                    session_id,
+                    from_id,
+                    name,
+                    buffer,
+                    IM_OFFLINE == offline,
+                    ll_safe_string((char*)binary_bucket),
+                    IM_SESSION_INVITE,
+                    parent_estate_id,
+                    region_id,
+                    position,
+                    false,      // is_region_msg
+                    timestamp);
+            }
+            else
+            {
+                // standard message, not from system
+                std::string saved;
+                if (offline == IM_OFFLINE)
+                {
+                    saved = llformat("(Saved %s) ", formatted_time(timestamp).c_str());
+                }
+
+                buffer = saved + message;
+
+                LL_DEBUGS("Messaging") << "standard message session_id( " << session_id << " ), from_id( " << from_id << " )" << LL_ENDL;
+
+                gIMMgr->addMessage(
+                    session_id,
+                    from_id,
+                    name,
+                    buffer,
+                    (IM_OFFLINE == offline),
+                    ll_safe_string((char*)binary_bucket),   // session name
+                    IM_SESSION_INVITE,
+                    parent_estate_id,
+                    region_id,
+                    position,
+                    false,      // is_region_msg
+                    timestamp);
+            }
+            break;
+
+        case IM_FROM_TASK_AS_ALERT:
+            if (is_do_not_disturb && !is_owned_by_me)
+            {
+                return;
+            }
+            {
+                // Construct a viewer alert for this message.
+                args["NAME"] = name;
+                args["MESSAGE"] = message;
+                LLNotificationsUtil::add("ObjectMessage", args);
+            }
+            break;
+        case IM_DO_NOT_DISTURB_AUTO_RESPONSE:
+            if (is_muted)
+            {
+                LL_DEBUGS("Messaging") << "Ignoring do-not-disturb response from " << from_id << LL_ENDL;
+                return;
+            }
+            else
+            {
+                gIMMgr->addMessage(session_id, from_id, name, message);
+            }
+            break;
+
+        case IM_LURE_USER:
+        case IM_TELEPORT_REQUEST:
+        {
+ // [RLVa:KB] - Checked: RLVa-1.4.9
+            // If we auto-accept the offer/request then this will override DnD status (but we'll still let the other party know later)
+            bool fRlvAutoAccept = (rlv_handler_t::isEnabled()) &&
+                ( ((IM_LURE_USER == dialog) && (RlvActions::autoAcceptTeleportOffer(from_id))) ||
+                  ((IM_TELEPORT_REQUEST == dialog) && (RlvActions::autoAcceptTeleportRequest(from_id))) );
+// [/RLVa:KB]
+
+           if (is_muted)
+            {
+                return;
+            }
+            else if (gSavedPerAccountSettings.getBOOL("VoiceCallsFriendsOnly") && (LLAvatarTracker::instance().getBuddyInfo(from_id) == NULL))
+            {
+                return;
+            }
+            else if ((is_rejecting_tp_offers && (!ALDontRejectTeleportOffersFromFriends || (ALDontRejectTeleportOffersFromFriends && !is_friend))) && (!fRlvAutoAccept))
+            {
+                send_rejecting_tp_offers_message(gMessageSystem, from_id);
+            }
+            else
+            {
+//              if (is_do_not_disturb)
+// [RLVa:KB] - Checked: RLVa-1.4.9
+                if ( (is_do_not_disturb) && (!fRlvAutoAccept) )
+// [/RLVa:KB]
+                {
+                    send_do_not_disturb_message(gMessageSystem, from_id);
+                }
+
+                LLVector3 pos, look_at;
+                U64 region_handle(0);
+                U8 region_access(SIM_ACCESS_MIN);
+                std::string region_info = ll_safe_string((char*)binary_bucket, binary_bucket_size);
+                std::string region_access_str = LLStringUtil::null;
+                std::string region_access_icn = LLStringUtil::null;
+                std::string region_access_lc = LLStringUtil::null;
+
+                bool canUserAccessDstRegion = true;
+                bool doesUserRequireMaturityIncrease = false;
+
+                // Do not parse the (empty) lure bucket for TELEPORT_REQUEST
+                if (IM_TELEPORT_REQUEST != dialog && parse_lure_bucket(region_info, region_handle, pos, look_at, region_access))
+                {
+                    region_access_str = LLViewerRegion::accessToString(region_access);
+                    region_access_icn = LLViewerRegion::getAccessIcon(region_access);
+                    region_access_lc = region_access_str;
+                    LLStringUtil::toLower(region_access_lc);
+
+                    if (!gAgent.isGodlike())
+                    {
+                        switch (region_access)
+                        {
+                            case SIM_ACCESS_MIN:
+                            case SIM_ACCESS_PG:
+                                break;
+                            case SIM_ACCESS_MATURE:
+                                if (gAgent.isTeen())
+                                {
+                                    canUserAccessDstRegion = false;
+                                }
+                                else if (gAgent.prefersPG())
+                                {
+                                    doesUserRequireMaturityIncrease = true;
+                                }
+                                break;
+                            case SIM_ACCESS_ADULT:
+                                if (!gAgent.isAdult())
+                                {
+                                    canUserAccessDstRegion = false;
+                                }
+                                else if (!gAgent.prefersAdult())
+                                {
+                                    doesUserRequireMaturityIncrease = true;
+                                }
+                                break;
+                            default:
+                                llassert(0);
+                                break;
+                        }
+                    }
+                }
+
+// [RLVa:KB] - Checked: RLVa-1.4.9
+                if (rlv_handler_t::isEnabled())
+                {
+                    bool fBlockTpLure = (IM_LURE_USER == dialog) && (!RlvActions::canAcceptTpOffer(from_id));
+                    bool fBlockTpRequest = (IM_TELEPORT_REQUEST == dialog) && (!RlvActions::canAcceptTpRequest(from_id));
+                    if ( fBlockTpLure || fBlockTpRequest )
+                    {
+                        RlvUtil::sendBusyMessage(from_id, RlvStrings::getString(fBlockTpLure ? RlvStringKeys::Blocked::TpLureRemote : RlvStringKeys::Blocked::TpRequestRemote));
+                        if (is_do_not_disturb)
+                            send_do_not_disturb_message(gMessageSystem, from_id);
+                        return;
+                    }
+
+                    // Censor message if: 1) restricted from receiving IMs from the sender, or 2) teleport offer/request and @showloc=n restricted
+                    if ( (!RlvActions::canReceiveIM(from_id)) ||
+                         ((gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) && (IM_LURE_USER == dialog || IM_TELEPORT_REQUEST == dialog)) )
+                    {
+                        message = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
+                    }
+                }
+// [/RLVa:KB]
+
+                LLSD args;
+                // *TODO: Translate -> [FIRST] [LAST] (maybe)
+// [SL:KB] - Patch: UI-Notifications | Checked: 2011-04-11 (Catznip-2.5.0a) | Added: Catznip-2.5.0a
+                args["NAME_LABEL"] = LLSLURL("agent", from_id, "completename").getSLURLString();
+// [/SL:KB]
+                args["NAME_SLURL"] = LLSLURL("agent", from_id, "about").getSLURLString();
+                args["MESSAGE"] = message;
+                args["MATURITY_STR"] = region_access_str;
+                args["MATURITY_ICON"] = region_access_icn;
+                args["REGION_CONTENT_MATURITY"] = region_access_lc;
+                LLSD payload;
+                payload["from_id"] = from_id;
+                payload["lure_id"] = session_id;
+                payload["godlike"] = FALSE;
+                payload["region_maturity"] = region_access;
+
+                if (!canUserAccessDstRegion)
+                {
+                    LLNotification::Params params("TeleportOffered_MaturityBlocked");
+                    params.substitutions = args;
+                    params.payload = payload;
+                    LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
+                    send_simple_im(from_id, LLTrans::getString("TeleportMaturityExceeded"), IM_NOTHING_SPECIAL, session_id);
+                    send_simple_im(from_id, LLStringUtil::null, IM_LURE_DECLINED, session_id);
+                }
+                else if (doesUserRequireMaturityIncrease)
+                {
+                    LLNotification::Params params("TeleportOffered_MaturityExceeded");
+                    params.substitutions = args;
+                    params.payload = payload;
+                    LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
+                }
+                else
+                {
+                    LLNotification::Params params;
+                    if (IM_LURE_USER == dialog)
+                    {
+                        params.name = "TeleportOffered";
+                        params.functor.name = "TeleportOffered";
+                    }
+                    else if (IM_TELEPORT_REQUEST == dialog)
+                    {
+                        params.name = "TeleportRequest";
+                        params.functor.name = "TeleportRequest";
+                    }
+
+                    params.substitutions = args;
+                    params.payload = payload;
+
+// [RLVa:KB] - Checked: RLVa-1.4.9
+                    if (fRlvAutoAccept)
+                    {
+                        if (IM_LURE_USER == dialog)
+                            gRlvHandler.setCanCancelTp(false);
+                        if (is_do_not_disturb)
+                            send_do_not_disturb_message(gMessageSystem, from_id);
+                        LLNotifications::instance().forceResponse(LLNotification::Params(params.name).payload(payload), 0);
+                    }
+                    else
+                    {
+                        LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
+                    }
+// [/RLVa:KB]
+//                    LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
+                }
+            }
+        }
+        break;
+
+        case IM_GODLIKE_LURE_USER:
+        {
+            LLVector3 pos, look_at;
+            U64 region_handle(0);
+            U8 region_access(SIM_ACCESS_MIN);
+            std::string region_info = ll_safe_string((char*)binary_bucket, binary_bucket_size);
+            std::string region_access_str = LLStringUtil::null;
+            std::string region_access_icn = LLStringUtil::null;
+            std::string region_access_lc = LLStringUtil::null;
+
+            bool canUserAccessDstRegion = true;
+            bool doesUserRequireMaturityIncrease = false;
+
+            if (parse_lure_bucket(region_info, region_handle, pos, look_at, region_access))
+            {
+                region_access_str = LLViewerRegion::accessToString(region_access);
+                region_access_icn = LLViewerRegion::getAccessIcon(region_access);
+                region_access_lc = region_access_str;
+                LLStringUtil::toLower(region_access_lc);
+
+                if (!gAgent.isGodlike())
+                {
+                    switch (region_access)
+                    {
+                        case SIM_ACCESS_MIN:
+                        case SIM_ACCESS_PG:
+                            break;
+                        case SIM_ACCESS_MATURE:
+                            if (gAgent.isTeen())
+                            {
+                                canUserAccessDstRegion = false;
+                            }
+                            else if (gAgent.prefersPG())
+                            {
+                                doesUserRequireMaturityIncrease = true;
+                            }
+                            break;
+                        case SIM_ACCESS_ADULT:
+                            if (!gAgent.isAdult())
+                            {
+                                canUserAccessDstRegion = false;
+                            }
+                            else if (!gAgent.prefersAdult())
+                            {
+                                doesUserRequireMaturityIncrease = true;
+                            }
+                            break;
+                        default:
+                            llassert(0);
+                            break;
+                    }
+                }
+            }
+
+            LLSD args;
+            // *TODO: Translate -> [FIRST] [LAST] (maybe)
+            args["NAME_SLURL"] = LLSLURL("agent", from_id, "about").getSLURLString();
+            args["MESSAGE"] = message;
+            args["MATURITY_STR"] = region_access_str;
+            args["MATURITY_ICON"] = region_access_icn;
+            args["REGION_CONTENT_MATURITY"] = region_access_lc;
+            LLSD payload;
+            payload["from_id"] = from_id;
+            payload["lure_id"] = session_id;
+            payload["godlike"] = TRUE;
+            payload["region_maturity"] = region_access;
+
+            if (!canUserAccessDstRegion)
+            {
+                LLNotification::Params params("TeleportOffered_MaturityBlocked");
+                params.substitutions = args;
+                params.payload = payload;
+                LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
+                send_simple_im(from_id, LLTrans::getString("TeleportMaturityExceeded"), IM_NOTHING_SPECIAL, session_id);
+                send_simple_im(from_id, LLStringUtil::null, IM_LURE_DECLINED, session_id);
+            }
+            else if (doesUserRequireMaturityIncrease)
+            {
+                LLNotification::Params params("TeleportOffered_MaturityExceeded");
+                params.substitutions = args;
+                params.payload = payload;
+                LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
+            }
+            else
+            {
+                // do not show a message box, because you're about to be
+                // teleported.
+                LLNotifications::instance().forceResponse(LLNotification::Params("TeleportOffered").payload(payload), 0);
+            }
+        }
+        break;
+
+        case IM_GOTO_URL:
+        {
+            LLSD args;
+            // n.b. this is for URLs sent by the system, not for
+            // URLs sent by scripts (i.e. llLoadURL)
+            if (binary_bucket_size <= 0)
+            {
+                LL_WARNS("Messaging") << "bad binary_bucket_size: "
+                    << binary_bucket_size
+                    << " - aborting function." << LL_ENDL;
+                return;
+            }
+
+            std::string url;
+
+            url.assign((char*)binary_bucket, binary_bucket_size - 1);
+            args["MESSAGE"] = message;
+            args["URL"] = url;
+            LLSD payload;
+            payload["url"] = url;
+            LLNotificationsUtil::add("GotoURL", args, payload);
+        }
+        break;
+
+        case IM_FRIENDSHIP_OFFERED:
+        {
+            if (is_rejecting_friendship_requests)
+            {
+                send_rejecting_friendship_requests_message(gMessageSystem, from_id);
+                return;
+            }
+
+            LLSD payload;
+            payload["from_id"] = from_id;
+            payload["session_id"] = session_id;
+            payload["online"] = (offline == IM_ONLINE);
+            payload["sender"] = sender.getIPandPort();
+
+            bool add_notification = true;
+            for (auto& panel : LLToastNotifyPanel::instance_snapshot())
+            {
+                const std::string& notification_name = panel.getNotificationName();
+                if (notification_name == "OfferFriendship" && panel.isControlPanelEnabled())
+                {
+                    add_notification = false;
+                    break;
+                }
+            }
+
+            if (is_muted && add_notification)
+            {
+                LLNotifications::instance().forceResponse(LLNotification::Params("OfferFriendship").payload(payload), 1);
+            }
+            else
+            {
+                if (is_do_not_disturb)
+                {
+                    send_do_not_disturb_message(gMessageSystem, from_id);
+                }
+// [SL:KB] - Patch: UI-Notifications | Checked: 2011-04-11 (Catznip-2.5.0a) | Added: Catznip-2.5.0a
+                args["NAME_LABEL"] = LLSLURL("agent", from_id, "completename").getSLURLString();
+// [/SL:KB]
+                args["NAME_SLURL"] = LLSLURL("agent", from_id, "about").getSLURLString();
+
+                if (add_notification)
+                {
+                    if (message.empty())
+                    {
+                        //support for frienship offers from clients before July 2008
+                        LLNotificationsUtil::add("OfferFriendshipNoMessage", args, payload);
+                    }
+                    else
+                    {
+                        args["[MESSAGE]"] = message;
+                        LLNotification::Params params("OfferFriendship");
+                        params.substitutions = args;
+                        params.payload = payload;
+                        LLPostponedNotification::add<LLPostponedOfferNotification>(params, from_id, false);
+                    }
+                }
+            }
+        }
+        break;
+
+        case IM_FRIENDSHIP_ACCEPTED:
+        {
+            // In the case of an offline IM, the formFriendship() may be extraneous
+            // as the database should already include the relationship.  But it
+            // doesn't hurt for dupes.
+            LLAvatarTracker::formFriendship(from_id);
+
+            std::vector<std::string> strings;
+            strings.push_back(from_id.asString());
+            send_generic_message("requestonlinenotification", strings);
+
+            args["NAME"] = name;
+            LLSD payload;
+            payload["from_id"] = from_id;
+            LLAvatarNameCache::get(from_id, boost::bind(&notification_display_name_callback, _1, _2, "FriendshipAccepted", args, payload));
+        }
+        break;
+
+        case IM_FRIENDSHIP_DECLINED_DEPRECATED:
+        default:
+            LL_WARNS("Messaging") << "Instant message calling for unknown dialog "
+                << (S32)dialog << LL_ENDL;
+            break;
+    }
+
+    LLWindow* viewer_window = gViewerWindow->getWindow();
+    if (viewer_window && viewer_window->getMinimized())
+    {
+        viewer_window->flashIcon(5.f);
+    }
+}
+
+void LLIMProcessing::requestOfflineMessages()
+{
+    static BOOL requested = FALSE;
+    if (!requested
+        && gMessageSystem
+        && !gDisconnected
+        && LLMuteList::getInstance()->isLoaded()
+        && isAgentAvatarValid()
+        && gAgent.getRegion()
+        && gAgent.getRegion()->capabilitiesReceived())
+    {
+        std::string cap_url = gAgent.getRegionCapability("ReadOfflineMsgs");
+
+        // Auto-accepted inventory items may require the avatar object
+        // to build a correct name.  Likewise, inventory offers from
+        // muted avatars require the mute list to properly mute.
+        if (cap_url.empty()
+            || gAgent.getRegionCapability("AcceptFriendship").empty()
+            || gAgent.getRegionCapability("AcceptGroupInvite").empty())
+        {
+            // Offline messages capability provides no session/transaction ids for message AcceptFriendship and IM_GROUP_INVITATION to work
+            // So make sure we have the caps before using it.
+            requestOfflineMessagesLegacy();
+        }
+        else
+        {
+            LLCoros::instance().launch("LLIMProcessing::requestOfflineMessagesCoro",
+                boost::bind(&LLIMProcessing::requestOfflineMessagesCoro, cap_url));
+        }
+        requested = TRUE;
+    }
+}
+
+void LLIMProcessing::requestOfflineMessagesCoro(std::string url)
+{
+    LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
+    LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
+        httpAdapter(std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("requestOfflineMessagesCoro", httpPolicy));
+    LLCore::HttpRequest::ptr_t httpRequest(std::make_shared<LLCore::HttpRequest>());
+
+    LLSD result = httpAdapter->getAndSuspend(httpRequest, url);
+
+    LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS];
+    LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults);
+
+    if (!status) // success = httpResults["success"].asBoolean();
+    {
+        LL_WARNS("Messaging") << "Error requesting offline messages via capability " << url << ", Status: " << status.toString() << "\nFalling back to legacy method." << LL_ENDL;
+
+        requestOfflineMessagesLegacy();
+        return;
+    }
+
+    LLSD contents = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS_CONTENT];
+
+    if (!contents.size())
+    {
+        LL_WARNS("Messaging") << "No contents received for offline messages via capability " << url << LL_ENDL;
+        return;
+    }
+
+    // Todo: once dirtsim-369 releases, remove one of the map/array options
+    LLSD messages;
+    if (contents.isArray())
+    {
+        messages = *contents.beginArray();
+    }
+    else if (contents.has("messages"))
+    {
+        messages = contents["messages"];
+    }
+    else
+    {
+        LL_WARNS("Messaging") << "Invalid offline message content received via capability " << url << LL_ENDL;
+        return;
+    }
+
+    if (!messages.isArray())
+    {
+        LL_WARNS("Messaging") << "Invalid offline message content received via capability " << url << LL_ENDL;
+        return;
+    }
+
+    if (messages.size() == 0)
+    {
+        // Nothing to process
+        return;
+    }
+
+    if (!gAgent.getRegion())
+    {
+        LL_WARNS("Messaging") << "Region null while attempting to load messages." << LL_ENDL;
+        return;
+    }
+
+    LL_INFOS("Messaging") << "Processing offline messages." << LL_ENDL;
+
+    LLHost sender = gAgent.getRegionHost();
+
+    LLSD::array_iterator i = messages.beginArray();
+    LLSD::array_iterator iEnd = messages.endArray();
+    for (; i != iEnd; ++i)
+    {
+        const LLSD &message_data(*i);
+
+        /* RIDER: Many fields in this message are using a '_' rather than the standard '-'.  This
+         * should be changed but would require tight coordination with the simulator.
+         */
+        LLVector3 position;
+        if (message_data.has("position"))
+        {
+            position.setValue(message_data["position"]);
+        }
+        else
+        {
+            position.set(message_data["local_x"].asReal(), message_data["local_y"].asReal(), message_data["local_z"].asReal());
+        }
+
+        std::vector<U8> bin_bucket;
+        if (message_data.has("binary_bucket"))
+        {
+            bin_bucket = message_data["binary_bucket"].asBinary();
+        }
+        else
+        {
+            bin_bucket.push_back(0);
+        }
+
+        // Todo: once drtsim-451 releases, remove the string option
+        BOOL from_group;
+        if (message_data["from_group"].isInteger())
+        {
+            from_group = message_data["from_group"].asInteger();
+        }
+        else
+        {
+            from_group = message_data["from_group"].asString() == "Y";
+        }
+
+        EInstantMessage dialog = static_cast<EInstantMessage>(message_data["dialog"].asInteger());
+        LLUUID session_id = message_data["transaction-id"].asUUID();
+        if (session_id.isNull() && dialog == IM_FROM_TASK)
+        {
+            session_id = message_data["asset_id"].asUUID();
+        }
+        LLIMProcessing::processNewMessage(
+            message_data["from_agent_id"].asUUID(),
+            from_group,
+            message_data["to_agent_id"].asUUID(),
+            message_data.has("offline") ? static_cast<U8>(message_data["offline"].asInteger()) : IM_OFFLINE,
+            dialog,
+            session_id,
+            static_cast<U32>(message_data["timestamp"].asInteger()),
+            message_data["from_agent_name"].asString(),
+            message_data["message"].asString(),
+            static_cast<U32>((message_data.has("parent_estate_id")) ? message_data["parent_estate_id"].asInteger() : 1), // 1 - IMMainland
+            message_data["region_id"].asUUID(),
+            position,
+            bin_bucket.data(),
+            bin_bucket.size(),
+            sender,
+            message_data["asset_id"].asUUID());
+
+    }
+}
+
+void LLIMProcessing::requestOfflineMessagesLegacy()
+{
+    LL_INFOS("Messaging") << "Requesting offline messages (Legacy)." << LL_ENDL;
+
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_RetrieveInstantMessages);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gAgent.sendReliableMessage();
+}
+
diff --git a/indra/newview/llinventoryfunctions.cpp b/indra/newview/llinventoryfunctions.cpp
index 0db149da2e13b37e5917d10cca1a04c4f0074ff9..20501f17e54b9233e7d4bb33fd4721b569a44f38 100644
--- a/indra/newview/llinventoryfunctions.cpp
+++ b/indra/newview/llinventoryfunctions.cpp
@@ -903,12 +903,6 @@ bool get_is_category_and_children_removable(LLInventoryModel* model, const LLUUI
         return false;
     }
 
-    const LLUUID mp_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MARKETPLACE_LISTINGS);
-    if (mp_id.notNull() && gInventory.isObjectDescendentOf(folder_id, mp_id))
-    {
-        return false;
-    }
-
     LLInventoryModel::cat_array_t cat_array;
     LLInventoryModel::item_array_t item_array;
     model->collectDescendents(
diff --git a/indra/newview/llmanip.cpp b/indra/newview/llmanip.cpp
index 3cd83cb2c11e66e2f6a98bc676e289a606a60b92..10ef51c4a026c2a490b03cc83b740ebe67858603 100644
--- a/indra/newview/llmanip.cpp
+++ b/indra/newview/llmanip.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llmanip.cpp
  * @brief LLManip class implementation
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -47,10 +47,10 @@
 #include "llviewercamera.h"
 #include "llviewerjoint.h"
 #include "llviewerobject.h"
-#include "llviewerregion.h"	// getRegion()
+#include "llviewerregion.h" // getRegion()
 #include "llviewerwindow.h"
 #include "llvoavatar.h"
-#include "llworld.h"		// for LLWorld::getInstance()
+#include "llworld.h"        // for LLWorld::getInstance()
 #include "llresmgr.h"
 #include "pipeline.h"
 #include "llglheaders.h"
@@ -58,39 +58,39 @@
 // Local constants...
 const S32 VERTICAL_OFFSET = 50;
 
-F32		LLManip::sHelpTextVisibleTime = 2.f;
-F32		LLManip::sHelpTextFadeTime = 2.f;
-S32		LLManip::sNumTimesHelpTextShown = 0;
-S32		LLManip::sMaxTimesShowHelpText = 5;
-F32		LLManip::sGridMaxSubdivisionLevel = 32.f;
-F32		LLManip::sGridMinSubdivisionLevel = 1.f / 32.f;
+F32     LLManip::sHelpTextVisibleTime = 2.f;
+F32     LLManip::sHelpTextFadeTime = 2.f;
+S32     LLManip::sNumTimesHelpTextShown = 0;
+S32     LLManip::sMaxTimesShowHelpText = 5;
+F32     LLManip::sGridMaxSubdivisionLevel = 32.f;
+F32     LLManip::sGridMinSubdivisionLevel = 1.f / 32.f;
 LLVector2 LLManip::sTickLabelSpacing(60.f, 25.f);
 
 
 //static
 void LLManip::rebuild(LLViewerObject* vobj)
 {
-	LLDrawable* drawablep = vobj->mDrawable;
-	if (drawablep && drawablep->getVOVolume())
-	{
-		gPipeline.markRebuild(drawablep,LLDrawable::REBUILD_VOLUME);
-		drawablep->setState(LLDrawable::MOVE_UNDAMPED); // force to UNDAMPED
-		drawablep->updateMove();
-		LLSpatialGroup* group = drawablep->getSpatialGroup();
-		if (group)
-		{
-			group->dirtyGeom();
-			gPipeline.markRebuild(group);
-		}
-
-		LLViewerObject::const_child_list_t& child_list = vobj->getChildren();
-		for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin(), endIter = child_list.end();
-			 iter != endIter; ++iter)
-		{
-			LLViewerObject* child = *iter;
-			rebuild(child);
-		}
-	}
+    LLDrawable* drawablep = vobj->mDrawable;
+    if (drawablep && drawablep->getVOVolume())
+    {
+        gPipeline.markRebuild(drawablep,LLDrawable::REBUILD_VOLUME);
+        drawablep->setState(LLDrawable::MOVE_UNDAMPED); // force to UNDAMPED
+        drawablep->updateMove();
+        LLSpatialGroup* group = drawablep->getSpatialGroup();
+        if (group)
+        {
+            group->dirtyGeom();
+            gPipeline.markRebuild(group);
+        }
+
+        LLViewerObject::const_child_list_t& child_list = vobj->getChildren();
+        for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin(), endIter = child_list.end();
+             iter != endIter; ++iter)
+        {
+            LLViewerObject* child = *iter;
+            rebuild(child);
+        }
+    }
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -98,208 +98,208 @@ void LLManip::rebuild(LLViewerObject* vobj)
 
 
 LLManip::LLManip( const std::string& name, LLToolComposite* composite )
-	:
-	LLTool( name, composite ),
-	mInSnapRegime(FALSE),
-	mHighlightedPart(LL_NO_PART),
-	mManipPart(LL_NO_PART)
+    :
+    LLTool( name, composite ),
+    mInSnapRegime(FALSE),
+    mHighlightedPart(LL_NO_PART),
+    mManipPart(LL_NO_PART)
 {
 }
 
 void LLManip::getManipNormal(LLViewerObject* object, EManipPart manip, LLVector3 &normal)
 {
-	LLVector3 grid_origin;
-	LLVector3 grid_scale;
-	LLQuaternion grid_rotation;
-
-	LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
-
-	if (manip >= LL_X_ARROW && manip <= LL_Z_ARROW)
-	{
-		LLVector3 arrow_axis;
-		getManipAxis(object, manip, arrow_axis);
-
-		LLVector3 cross = arrow_axis % LLViewerCamera::getInstance()->getAtAxis();
-		normal = cross % arrow_axis;
-		normal.normVec();
-	}
-	else if (manip >= LL_YZ_PLANE && manip <= LL_XY_PLANE)
-	{
-		switch (manip)
-		{
-		case LL_YZ_PLANE:
-			normal = LLVector3::x_axis;
-			break;
-		case LL_XZ_PLANE:
-			normal = LLVector3::y_axis;
-			break;
-		case LL_XY_PLANE:
-			normal = LLVector3::z_axis;
-			break;
-		default:
-			break;
-		}
-		normal.rotVec(grid_rotation);
-	}
-	else
-	{
-		normal.clearVec();
-	}
+    LLVector3 grid_origin;
+    LLVector3 grid_scale;
+    LLQuaternion grid_rotation;
+
+    LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
+
+    if (manip >= LL_X_ARROW && manip <= LL_Z_ARROW)
+    {
+        LLVector3 arrow_axis;
+        getManipAxis(object, manip, arrow_axis);
+
+        LLVector3 cross = arrow_axis % LLViewerCamera::getInstance()->getAtAxis();
+        normal = cross % arrow_axis;
+        normal.normVec();
+    }
+    else if (manip >= LL_YZ_PLANE && manip <= LL_XY_PLANE)
+    {
+        switch (manip)
+        {
+        case LL_YZ_PLANE:
+            normal = LLVector3::x_axis;
+            break;
+        case LL_XZ_PLANE:
+            normal = LLVector3::y_axis;
+            break;
+        case LL_XY_PLANE:
+            normal = LLVector3::z_axis;
+            break;
+        default:
+            break;
+        }
+        normal.rotVec(grid_rotation);
+    }
+    else
+    {
+        normal.clearVec();
+    }
 }
 
 
 BOOL LLManip::getManipAxis(LLViewerObject* object, EManipPart manip, LLVector3 &axis)
 {
-	LLVector3 grid_origin;
-	LLVector3 grid_scale;
-	LLQuaternion grid_rotation;
-
-	LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
-
-	if (manip == LL_X_ARROW)
-	{
-		axis = LLVector3::x_axis;
-	}
-	else if (manip == LL_Y_ARROW)
-	{
-		axis = LLVector3::y_axis;
-	}
-	else if (manip == LL_Z_ARROW)
-	{
-		axis = LLVector3::z_axis;
-	}
-	else
-	{
-		return FALSE;
-	}
-
-	axis.rotVec( grid_rotation );
-	return TRUE;
+    LLVector3 grid_origin;
+    LLVector3 grid_scale;
+    LLQuaternion grid_rotation;
+
+    LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
+
+    if (manip == LL_X_ARROW)
+    {
+        axis = LLVector3::x_axis;
+    }
+    else if (manip == LL_Y_ARROW)
+    {
+        axis = LLVector3::y_axis;
+    }
+    else if (manip == LL_Z_ARROW)
+    {
+        axis = LLVector3::z_axis;
+    }
+    else
+    {
+        return FALSE;
+    }
+
+    axis.rotVec( grid_rotation );
+    return TRUE;
 }
 
 F32 LLManip::getSubdivisionLevel(const LLVector3 &reference_point, const LLVector3 &translate_axis, F32 grid_scale, S32 min_pixel_spacing, F32 min_subdivisions, F32 max_subdivisions)
 {
-	//update current snap subdivision level
-	LLVector3 cam_to_reference;
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		cam_to_reference = LLVector3(1.f / gAgentCamera.mHUDCurZoom, 0.f, 0.f);
-	}
-	else
-	{
-		cam_to_reference = reference_point - LLViewerCamera::getInstance()->getOrigin();
-	}
-	F32 current_range = cam_to_reference.normVec();
-
-	F32 projected_translation_axis_length = (translate_axis % cam_to_reference).magVec();
-	F32 subdivisions = llmax(projected_translation_axis_length * grid_scale / (current_range / LLViewerCamera::getInstance()->getPixelMeterRatio() * min_pixel_spacing), 0.f);
-	// figure out nearest power of 2 that subdivides grid_scale with result > min_pixel_spacing
-	subdivisions = llclamp((F32)pow(2.f, llfloor(log(subdivisions) / log(2.f))), min_subdivisions, max_subdivisions);
-
-	return subdivisions;
+    //update current snap subdivision level
+    LLVector3 cam_to_reference;
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        cam_to_reference = LLVector3(1.f / gAgentCamera.mHUDCurZoom, 0.f, 0.f);
+    }
+    else
+    {
+        cam_to_reference = reference_point - LLViewerCamera::getInstance()->getOrigin();
+    }
+    F32 current_range = cam_to_reference.normVec();
+
+    F32 projected_translation_axis_length = (translate_axis % cam_to_reference).magVec();
+    F32 subdivisions = llmax(projected_translation_axis_length * grid_scale / (current_range / LLViewerCamera::getInstance()->getPixelMeterRatio() * min_pixel_spacing), 0.f);
+    // figure out nearest power of 2 that subdivides grid_scale with result > min_pixel_spacing
+    subdivisions = llclamp((F32)pow(2.f, llfloor(log(subdivisions) / log(2.f))), min_subdivisions, max_subdivisions);
+
+    return subdivisions;
 }
 
 void LLManip::handleSelect()
 {
-	mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
+    mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
 }
 
 void LLManip::handleDeselect()
 {
-	mHighlightedPart = LL_NO_PART;
-	mManipPart = LL_NO_PART;
-	mObjectSelection = NULL;
+    mHighlightedPart = LL_NO_PART;
+    mManipPart = LL_NO_PART;
+    mObjectSelection = NULL;
 }
 
 LLObjectSelectionHandle LLManip::getSelection()
 {
-	return mObjectSelection;
+    return mObjectSelection;
 }
 
 BOOL LLManip::handleHover(S32 x, S32 y, MASK mask)
 {
-	// We only handle the event if mousedown started with us
-	if( hasMouseCapture() )
-	{
-		if( mObjectSelection->isEmpty() )
-		{
-			// Somehow the object got deselected while we were dragging it.
-			// Release the mouse
-			setMouseCapture( FALSE );
-		}
+    // We only handle the event if mousedown started with us
+    if( hasMouseCapture() )
+    {
+        if( mObjectSelection->isEmpty() )
+        {
+            // Somehow the object got deselected while we were dragging it.
+            // Release the mouse
+            setMouseCapture( FALSE );
+        }
 
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("UserInput") << "hover handled by LLManip (active)" << LL_ENDL;
+        LL_DEBUGS("UserInput") << "hover handled by LLManip (active)" << LL_ENDL;
 #endif
-	}
-	else
-	{
+    }
+    else
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("UserInput") << "hover handled by LLManip (inactive)" << LL_ENDL;
+        LL_DEBUGS("UserInput") << "hover handled by LLManip (inactive)" << LL_ENDL;
 #endif
-	}
-	gViewerWindow->setCursor(UI_CURSOR_ARROW);
-	return TRUE;
+    }
+    gViewerWindow->setCursor(UI_CURSOR_ARROW);
+    return TRUE;
 }
 
 
 BOOL LLManip::handleMouseUp(S32 x, S32 y, MASK mask)
 {
-	BOOL	handled = FALSE;
-	if( hasMouseCapture() )
-	{
-		handled = TRUE;
-		setMouseCapture( FALSE );
-	}
-	return handled;
+    BOOL    handled = FALSE;
+    if( hasMouseCapture() )
+    {
+        handled = TRUE;
+        setMouseCapture( FALSE );
+    }
+    return handled;
 }
 
 void LLManip::updateGridSettings()
 {
-	sGridMaxSubdivisionLevel = gSavedSettings.getBOOL("GridSubUnit") ? (F32)gSavedSettings.getS32("GridSubdivision") : 1.f;
+    sGridMaxSubdivisionLevel = gSavedSettings.getBOOL("GridSubUnit") ? (F32)gSavedSettings.getS32("GridSubdivision") : 1.f;
 }
 
 BOOL LLManip::getMousePointOnPlaneAgent(LLVector3& point, S32 x, S32 y, LLVector3 origin, LLVector3 normal)
 {
-	LLVector3d origin_double = gAgent.getPosGlobalFromAgent(origin);
-	LLVector3d global_point;
-	BOOL result = getMousePointOnPlaneGlobal(global_point, x, y, origin_double, normal);
-	point = gAgent.getPosAgentFromGlobal(global_point);
-	return result;
+    LLVector3d origin_double = gAgent.getPosGlobalFromAgent(origin);
+    LLVector3d global_point;
+    BOOL result = getMousePointOnPlaneGlobal(global_point, x, y, origin_double, normal);
+    point = gAgent.getPosAgentFromGlobal(global_point);
+    return result;
 }
 
 BOOL LLManip::getMousePointOnPlaneGlobal(LLVector3d& point, S32 x, S32 y, LLVector3d origin, LLVector3 normal) const
 {
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		BOOL result = FALSE;
-		F32 mouse_x = ((F32)x / gViewerWindow->getWorldViewWidthScaled() - 0.5f) * LLViewerCamera::getInstance()->getAspect() / gAgentCamera.mHUDCurZoom;
-		F32 mouse_y = ((F32)y / gViewerWindow->getWorldViewHeightScaled() - 0.5f) / gAgentCamera.mHUDCurZoom;
-
-		LLVector3 origin_agent = gAgent.getPosAgentFromGlobal(origin);
-		LLVector3 mouse_pos = LLVector3(0.f, -mouse_x, mouse_y);
-		if (llabs(normal.mV[VX]) < 0.001f)
-		{
-			// use largish value that should be outside HUD manipulation range
-			mouse_pos.mV[VX] = 10.f;
-		}
-		else
-		{
-			mouse_pos.mV[VX] = (normal * (origin_agent - mouse_pos))
-								/ (normal.mV[VX]);
-			result = TRUE;
-		}
-
-		point = gAgent.getPosGlobalFromAgent(mouse_pos);
-		return result;
-	}
-	else
-	{
-		return gViewerWindow->mousePointOnPlaneGlobal(
-										point, x, y, origin, normal );
-	}
-
-	//return FALSE;
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        BOOL result = FALSE;
+        F32 mouse_x = ((F32)x / gViewerWindow->getWorldViewWidthScaled() - 0.5f) * LLViewerCamera::getInstance()->getAspect() / gAgentCamera.mHUDCurZoom;
+        F32 mouse_y = ((F32)y / gViewerWindow->getWorldViewHeightScaled() - 0.5f) / gAgentCamera.mHUDCurZoom;
+
+        LLVector3 origin_agent = gAgent.getPosAgentFromGlobal(origin);
+        LLVector3 mouse_pos = LLVector3(0.f, -mouse_x, mouse_y);
+        if (llabs(normal.mV[VX]) < 0.001f)
+        {
+            // use largish value that should be outside HUD manipulation range
+            mouse_pos.mV[VX] = 10.f;
+        }
+        else
+        {
+            mouse_pos.mV[VX] = (normal * (origin_agent - mouse_pos))
+                                / (normal.mV[VX]);
+            result = TRUE;
+        }
+
+        point = gAgent.getPosGlobalFromAgent(mouse_pos);
+        return result;
+    }
+    else
+    {
+        return gViewerWindow->mousePointOnPlaneGlobal(
+                                        point, x, y, origin, normal );
+    }
+
+    //return FALSE;
 }
 
 // Given the line defined by mouse cursor (a1 + a_param*(a2-a1)) and the line defined by b1 + b_param*(b2-b1),
@@ -307,160 +307,160 @@ BOOL LLManip::getMousePointOnPlaneGlobal(LLVector3d& point, S32 x, S32 y, LLVect
 // Returns false if the two lines are parallel.
 BOOL LLManip::nearestPointOnLineFromMouse( S32 x, S32 y, const LLVector3& b1, const LLVector3& b2, F32 &a_param, F32 &b_param )
 {
-	LLVector3 a1;
-	LLVector3 a2;
-
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		F32 mouse_x = (((F32)x / gViewerWindow->getWindowWidthScaled()) - 0.5f) * LLViewerCamera::getInstance()->getAspect() / gAgentCamera.mHUDCurZoom;
-		F32 mouse_y = (((F32)y / gViewerWindow->getWindowHeightScaled()) - 0.5f) / gAgentCamera.mHUDCurZoom;
-		a1 = LLVector3(llmin(b1.mV[VX] - 0.1f, b2.mV[VX] - 0.1f, 0.f), -mouse_x, mouse_y);
-		a2 = a1 + LLVector3(1.f, 0.f, 0.f);
-	}
-	else
-	{
-		a1 = gAgentCamera.getCameraPositionAgent();
-		a2 = gAgentCamera.getCameraPositionAgent() + LLVector3(gViewerWindow->mouseDirectionGlobal(x, y));
-	}
-
-	BOOL parallel = TRUE;
-	LLVector3 a = a2 - a1;
-	LLVector3 b = b2 - b1;
-
-	LLVector3 normal;
-	F32 dist, denom;
-	normal = (b % a) % b;	// normal to plane (P) through b and (shortest line between a and b)
-	normal.normVec();
-	dist = b1 * normal;			// distance from origin to P
-
-	denom = normal * a; 
-	if( (denom < -F_APPROXIMATELY_ZERO) || (F_APPROXIMATELY_ZERO < denom) )
-	{
-		a_param = (dist - normal * a1) / denom;
-		parallel = FALSE;
-	}
-
-	normal = (a % b) % a;	// normal to plane (P) through a and (shortest line between a and b)
-	normal.normVec();
-	dist = a1 * normal;			// distance from origin to P
-	denom = normal * b; 
-	if( (denom < -F_APPROXIMATELY_ZERO) || (F_APPROXIMATELY_ZERO < denom) )
-	{
-		b_param = (dist - normal * b1) / denom;
-		parallel = FALSE;
-	}
-
-	return parallel;
+    LLVector3 a1;
+    LLVector3 a2;
+
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        F32 mouse_x = (((F32)x / gViewerWindow->getWindowWidthScaled()) - 0.5f) * LLViewerCamera::getInstance()->getAspect() / gAgentCamera.mHUDCurZoom;
+        F32 mouse_y = (((F32)y / gViewerWindow->getWindowHeightScaled()) - 0.5f) / gAgentCamera.mHUDCurZoom;
+        a1 = LLVector3(llmin(b1.mV[VX] - 0.1f, b2.mV[VX] - 0.1f, 0.f), -mouse_x, mouse_y);
+        a2 = a1 + LLVector3(1.f, 0.f, 0.f);
+    }
+    else
+    {
+        a1 = gAgentCamera.getCameraPositionAgent();
+        a2 = gAgentCamera.getCameraPositionAgent() + LLVector3(gViewerWindow->mouseDirectionGlobal(x, y));
+    }
+
+    BOOL parallel = TRUE;
+    LLVector3 a = a2 - a1;
+    LLVector3 b = b2 - b1;
+
+    LLVector3 normal;
+    F32 dist, denom;
+    normal = (b % a) % b;   // normal to plane (P) through b and (shortest line between a and b)
+    normal.normVec();
+    dist = b1 * normal;         // distance from origin to P
+
+    denom = normal * a;
+    if( (denom < -F_APPROXIMATELY_ZERO) || (F_APPROXIMATELY_ZERO < denom) )
+    {
+        a_param = (dist - normal * a1) / denom;
+        parallel = FALSE;
+    }
+
+    normal = (a % b) % a;   // normal to plane (P) through a and (shortest line between a and b)
+    normal.normVec();
+    dist = a1 * normal;         // distance from origin to P
+    denom = normal * b;
+    if( (denom < -F_APPROXIMATELY_ZERO) || (F_APPROXIMATELY_ZERO < denom) )
+    {
+        b_param = (dist - normal * b1) / denom;
+        parallel = FALSE;
+    }
+
+    return parallel;
 }
 
 LLVector3 LLManip::getSavedPivotPoint() const
 {
-	return LLSelectMgr::getInstance()->getSavedBBoxOfSelection().getCenterAgent();
+    return LLSelectMgr::getInstance()->getSavedBBoxOfSelection().getCenterAgent();
 }
 
 LLVector3 LLManip::getPivotPoint()
 {
-	static LLCachedControl<bool> editRootAxis(gSavedSettings, "AlchemyEditRootAxis", false);
+    static LLCachedControl<bool> editRootAxis(gSavedSettings, "AlchemyEditRootAxis", false);
     LLViewerObject* object = mObjectSelection->getFirstRootObject(TRUE);
-	if (object && (mObjectSelection->getObjectCount() == 1 || editRootAxis) && mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
-	{
+    if (object && (mObjectSelection->getObjectCount() == 1 || editRootAxis) && mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
+    {
         LLSelectNode* select_node = mObjectSelection->getFirstNode();
         if (select_node->mSelectedGLTFNode != -1)
         {
             return object->getGLTFNodePositionAgent(select_node->mSelectedGLTFNode);
         }
-		return object->getPivotPositionAgent();
-	}
-	return LLSelectMgr::getInstance()->getBBoxOfSelection().getCenterAgent();
+        return object->getPivotPositionAgent();
+    }
+    return LLSelectMgr::getInstance()->getBBoxOfSelection().getCenterAgent();
 }
 
 
 void LLManip::renderGuidelines(BOOL draw_x, BOOL draw_y, BOOL draw_z)
 {
-	LLVector3 grid_origin;
-	LLQuaternion grid_rot;
-	LLVector3 grid_scale;
-	LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rot, grid_scale);
-
-	const BOOL children_ok = TRUE;
-	LLViewerObject* object = mObjectSelection->getFirstRootObject(children_ok);
-	if (!object)
-	{
-		return;
-	}
-
-	//LLVector3  center_agent  = LLSelectMgr::getInstance()->getBBoxOfSelection().getCenterAgent();
-	LLVector3  center_agent  = getPivotPoint();
-
-	gGL.pushMatrix();
-	{
-		gGL.translatef(center_agent.mV[VX], center_agent.mV[VY], center_agent.mV[VZ]);
-
-		F32 angle_radians, x, y, z;
-
-		grid_rot.getAngleAxis(&angle_radians, &x, &y, &z);
-		gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
-
-		F32 region_size = object->getRegion()->getWidth();
-
-		const F32 LINE_ALPHA = 0.33f;
-
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-		LLUI::setLineWidth(1.5f);
-
-		if (draw_x)
-		{
-			gGL.color4f(1.f, 0.f, 0.f, LINE_ALPHA);
-			gGL.begin(LLRender::LINES);
-			gGL.vertex3f( -region_size, 0.f, 0.f );
-			gGL.vertex3f(  region_size, 0.f, 0.f );
-			gGL.end();
-		}
-
-		if (draw_y)
-		{
-			gGL.color4f(0.f, 1.f, 0.f, LINE_ALPHA);
-			gGL.begin(LLRender::LINES);
-			gGL.vertex3f( 0.f, -region_size, 0.f );
-			gGL.vertex3f( 0.f,  region_size, 0.f );
-			gGL.end();
-		}
-
-		if (draw_z)
-		{
-			gGL.color4f(0.f, 0.f, 1.f, LINE_ALPHA);
-			gGL.begin(LLRender::LINES);
-			gGL.vertex3f( 0.f, 0.f, -region_size );
-			gGL.vertex3f( 0.f, 0.f,  region_size );
-			gGL.end();
-		}
-		LLUI::setLineWidth(1.0f);
-	}
-	gGL.popMatrix();
+    LLVector3 grid_origin;
+    LLQuaternion grid_rot;
+    LLVector3 grid_scale;
+    LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rot, grid_scale);
+
+    const BOOL children_ok = TRUE;
+    LLViewerObject* object = mObjectSelection->getFirstRootObject(children_ok);
+    if (!object)
+    {
+        return;
+    }
+
+    //LLVector3  center_agent  = LLSelectMgr::getInstance()->getBBoxOfSelection().getCenterAgent();
+    LLVector3  center_agent  = getPivotPoint();
+
+    gGL.pushMatrix();
+    {
+        gGL.translatef(center_agent.mV[VX], center_agent.mV[VY], center_agent.mV[VZ]);
+
+        F32 angle_radians, x, y, z;
+
+        grid_rot.getAngleAxis(&angle_radians, &x, &y, &z);
+        gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
+
+        F32 region_size = object->getRegion()->getWidth();
+
+        const F32 LINE_ALPHA = 0.33f;
+
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+        LLUI::setLineWidth(1.5f);
+
+        if (draw_x)
+        {
+            gGL.color4f(1.f, 0.f, 0.f, LINE_ALPHA);
+            gGL.begin(LLRender::LINES);
+            gGL.vertex3f( -region_size, 0.f, 0.f );
+            gGL.vertex3f(  region_size, 0.f, 0.f );
+            gGL.end();
+        }
+
+        if (draw_y)
+        {
+            gGL.color4f(0.f, 1.f, 0.f, LINE_ALPHA);
+            gGL.begin(LLRender::LINES);
+            gGL.vertex3f( 0.f, -region_size, 0.f );
+            gGL.vertex3f( 0.f,  region_size, 0.f );
+            gGL.end();
+        }
+
+        if (draw_z)
+        {
+            gGL.color4f(0.f, 0.f, 1.f, LINE_ALPHA);
+            gGL.begin(LLRender::LINES);
+            gGL.vertex3f( 0.f, 0.f, -region_size );
+            gGL.vertex3f( 0.f, 0.f,  region_size );
+            gGL.end();
+        }
+        LLUI::setLineWidth(1.0f);
+    }
+    gGL.popMatrix();
 }
 
-void LLManip::renderXYZ(const LLVector3 &vec) 
+void LLManip::renderXYZ(const LLVector3 &vec)
 {
-	const S32 PAD = 10;
-	std::string feedback_string;
-	S32 window_center_x = gViewerWindow->getWorldViewRectScaled().getWidth() / 2;
-	S32 window_center_y = gViewerWindow->getWorldViewRectScaled().getHeight() / 2;
-	S32 vertical_offset = window_center_y - VERTICAL_OFFSET;
-
-
-	gGL.pushMatrix();
-	{
-		LLUIImagePtr imagep = LLUI::getUIImage("Rounded_Square");
-		gViewerWindow->setup2DRender();
-		const LLVector2& display_scale = gViewerWindow->getDisplayScale();
-		gGL.color4f(0.f, 0.f, 0.f, 0.7f);
-
-		imagep->draw(
-			(window_center_x - 115) * display_scale.mV[VX],
-			(window_center_y + vertical_offset - PAD) * display_scale.mV[VY],
-			235 * display_scale.mV[VX],
-			(PAD * 2 + 10) * display_scale.mV[VY],
-			LLColor4(0.f, 0.f, 0.f, 0.7f) );
+    const S32 PAD = 10;
+    std::string feedback_string;
+    S32 window_center_x = gViewerWindow->getWorldViewRectScaled().getWidth() / 2;
+    S32 window_center_y = gViewerWindow->getWorldViewRectScaled().getHeight() / 2;
+    S32 vertical_offset = window_center_y - VERTICAL_OFFSET;
+
+
+    gGL.pushMatrix();
+    {
+        LLUIImagePtr imagep = LLUI::getUIImage("Rounded_Square");
+        gViewerWindow->setup2DRender();
+        const LLVector2& display_scale = gViewerWindow->getDisplayScale();
+        gGL.color4f(0.f, 0.f, 0.f, 0.7f);
+
+        imagep->draw(
+            (window_center_x - 115) * display_scale.mV[VX],
+            (window_center_y + vertical_offset - PAD) * display_scale.mV[VY],
+            235 * display_scale.mV[VX],
+            (PAD * 2 + 10) * display_scale.mV[VY],
+            LLColor4(0.f, 0.f, 0.f, 0.7f) );
 
         LLFontGL* font = LLFontGL::getFontSansSerif();
         LLLocale locale(LLLocale::USER_LOCALE);
@@ -506,126 +506,126 @@ void LLManip::renderXYZ(const LLVector3 &vec)
 
 void LLManip::renderTickText(const LLVector3& pos, const LLWString& text, const LLColor4 &color)
 {
-	const LLFontGL* big_fontp = LLFontGL::getFontSansSerif();
-
-	BOOL hud_selection = mObjectSelection->getSelectType() == SELECT_TYPE_HUD;
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-	LLVector3 render_pos = pos;
-	if (hud_selection)
-	{
-		F32 zoom_amt = gAgentCamera.mHUDCurZoom;
-		F32 inv_zoom_amt = 1.f / zoom_amt;
-		// scale text back up to counter-act zoom level
-		render_pos = pos * zoom_amt;
-		gGL.scalef(inv_zoom_amt, inv_zoom_amt, inv_zoom_amt);
-	}
-
-	// render shadow first
-	LLColor4 shadow_color = LLColor4::black;
-	shadow_color.mV[VALPHA] = color.mV[VALPHA] * 0.5f;
-	gViewerWindow->setup3DViewport(1, -1);
-	hud_render_text(text, render_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW,  -0.5f * big_fontp->getWidthF32(text.c_str()), 3.f, shadow_color, mObjectSelection->getSelectType() == SELECT_TYPE_HUD);
-	gViewerWindow->setup3DViewport();
-	hud_render_text(text, render_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(text.c_str()), 3.f, color, mObjectSelection->getSelectType() == SELECT_TYPE_HUD);
-
-	gGL.popMatrix();
+    const LLFontGL* big_fontp = LLFontGL::getFontSansSerif();
+
+    BOOL hud_selection = mObjectSelection->getSelectType() == SELECT_TYPE_HUD;
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+    LLVector3 render_pos = pos;
+    if (hud_selection)
+    {
+        F32 zoom_amt = gAgentCamera.mHUDCurZoom;
+        F32 inv_zoom_amt = 1.f / zoom_amt;
+        // scale text back up to counter-act zoom level
+        render_pos = pos * zoom_amt;
+        gGL.scalef(inv_zoom_amt, inv_zoom_amt, inv_zoom_amt);
+    }
+
+    // render shadow first
+    LLColor4 shadow_color = LLColor4::black;
+    shadow_color.mV[VALPHA] = color.mV[VALPHA] * 0.5f;
+    gViewerWindow->setup3DViewport(1, -1);
+    hud_render_text(text, render_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW,  -0.5f * big_fontp->getWidthF32(text.c_str()), 3.f, shadow_color, mObjectSelection->getSelectType() == SELECT_TYPE_HUD);
+    gViewerWindow->setup3DViewport();
+    hud_render_text(text, render_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(text.c_str()), 3.f, color, mObjectSelection->getSelectType() == SELECT_TYPE_HUD);
+
+    gGL.popMatrix();
 }
 
 void LLManip::renderTickValue(const LLVector3& pos, F32 value, const std::string& suffix, const LLColor4 &color)
 {
-	LLLocale locale(LLLocale::USER_LOCALE);
-
-	const LLFontGL* big_fontp = LLFontGL::getFontSansSerif();
-	const LLFontGL* small_fontp = LLFontGL::getFontSansSerifSmall();
-
-	std::string val_string;
-	std::string fraction_string;
-	F32 val_to_print = ll_round(value, 0.001f);
-	S32 fractional_portion = ll_round(fmodf(llabs(val_to_print), 1.f) * 100.f);
-	if (val_to_print < 0.f)
-	{
-		if (fractional_portion == 0)
-		{
-			val_string = llformat("-%d%s", lltrunc(llabs(val_to_print)), suffix.c_str());
-		}
-		else
-		{
-			val_string = llformat("-%d", lltrunc(llabs(val_to_print)));
-		}
-	}
-	else
-	{
-		if (fractional_portion == 0)
-		{
-			val_string = llformat("%d%s", lltrunc(llabs(val_to_print)), suffix.c_str());
-		}
-		else
-		{
-			val_string = llformat("%d", lltrunc(val_to_print));
-		}
-	}
-
-	BOOL hud_selection = mObjectSelection->getSelectType() == SELECT_TYPE_HUD;
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-	{
-		LLVector3 render_pos = pos;
-		if (hud_selection)
-		{
-			F32 zoom_amt = gAgentCamera.mHUDCurZoom;
-			F32 inv_zoom_amt = 1.f / zoom_amt;
-			// scale text back up to counter-act zoom level
-			render_pos = pos * zoom_amt;
-			gGL.scalef(inv_zoom_amt, inv_zoom_amt, inv_zoom_amt);
-		}
-
-		if (fractional_portion != 0)
-		{
-			fraction_string = llformat("%c%02d%s", LLResMgr::getDecimalPoint(), fractional_portion, suffix.c_str());
-
-			hud_render_utf8text(val_string, render_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::DROP_SHADOW, -1.f * big_fontp->getWidthF32(val_string), 3.f, color, hud_selection);
-			hud_render_utf8text(fraction_string, render_pos, *small_fontp, LLFontGL::NORMAL, LLFontGL::DROP_SHADOW, 1.f, 3.f, color, hud_selection);
-		}
-		else
-		{
-			hud_render_utf8text(val_string, render_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::DROP_SHADOW, -0.5f * big_fontp->getWidthF32(val_string), 3.f, color, hud_selection);
-		}
-	}
-	gGL.popMatrix();
+    LLLocale locale(LLLocale::USER_LOCALE);
+
+    const LLFontGL* big_fontp = LLFontGL::getFontSansSerif();
+    const LLFontGL* small_fontp = LLFontGL::getFontSansSerifSmall();
+
+    std::string val_string;
+    std::string fraction_string;
+    F32 val_to_print = ll_round(value, 0.001f);
+    S32 fractional_portion = ll_round(fmodf(llabs(val_to_print), 1.f) * 100.f);
+    if (val_to_print < 0.f)
+    {
+        if (fractional_portion == 0)
+        {
+            val_string = llformat("-%d%s", lltrunc(llabs(val_to_print)), suffix.c_str());
+        }
+        else
+        {
+            val_string = llformat("-%d", lltrunc(llabs(val_to_print)));
+        }
+    }
+    else
+    {
+        if (fractional_portion == 0)
+        {
+            val_string = llformat("%d%s", lltrunc(llabs(val_to_print)), suffix.c_str());
+        }
+        else
+        {
+            val_string = llformat("%d", lltrunc(val_to_print));
+        }
+    }
+
+    BOOL hud_selection = mObjectSelection->getSelectType() == SELECT_TYPE_HUD;
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+    {
+        LLVector3 render_pos = pos;
+        if (hud_selection)
+        {
+            F32 zoom_amt = gAgentCamera.mHUDCurZoom;
+            F32 inv_zoom_amt = 1.f / zoom_amt;
+            // scale text back up to counter-act zoom level
+            render_pos = pos * zoom_amt;
+            gGL.scalef(inv_zoom_amt, inv_zoom_amt, inv_zoom_amt);
+        }
+
+        if (fractional_portion != 0)
+        {
+            fraction_string = llformat("%c%02d%s", LLResMgr::getDecimalPoint(), fractional_portion, suffix.c_str());
+
+            hud_render_utf8text(val_string, render_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::DROP_SHADOW, -1.f * big_fontp->getWidthF32(val_string), 3.f, color, hud_selection);
+            hud_render_utf8text(fraction_string, render_pos, *small_fontp, LLFontGL::NORMAL, LLFontGL::DROP_SHADOW, 1.f, 3.f, color, hud_selection);
+        }
+        else
+        {
+            hud_render_utf8text(val_string, render_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::DROP_SHADOW, -0.5f * big_fontp->getWidthF32(val_string), 3.f, color, hud_selection);
+        }
+    }
+    gGL.popMatrix();
 }
 
 LLColor4 LLManip::setupSnapGuideRenderPass(S32 pass)
 {
-	static LLUIColor grid_color_fg = LLUIColorTable::instance().getColor("GridlineColor");
-	static LLUIColor grid_color_bg = LLUIColorTable::instance().getColor("GridlineBGColor");
-	static LLUIColor grid_color_shadow = LLUIColorTable::instance().getColor("GridlineShadowColor");
-
-	LLColor4 line_color;
-	F32 line_alpha = ALControlCache::GridOpacity;
-
-	switch(pass)
-	{
-	case 0:
-		// shadow
-		gViewerWindow->setup3DViewport(1, -1);
-		line_color = grid_color_shadow;
-		line_color.mV[VALPHA] *= line_alpha;
-		LLUI::setLineWidth(2.f);
-		break;
-	case 1:
-		// hidden lines
-		gViewerWindow->setup3DViewport();
-		line_color = grid_color_bg;
-		line_color.mV[VALPHA] *= line_alpha;
-		LLUI::setLineWidth(1.f);
-		break;
-	case 2:
-		// visible lines
-		line_color = grid_color_fg;
-		line_color.mV[VALPHA] *= line_alpha;
-		break;
-	}
-
-	return line_color;
+    static LLUIColor grid_color_fg = LLUIColorTable::instance().getColor("GridlineColor");
+    static LLUIColor grid_color_bg = LLUIColorTable::instance().getColor("GridlineBGColor");
+    static LLUIColor grid_color_shadow = LLUIColorTable::instance().getColor("GridlineShadowColor");
+
+    LLColor4 line_color;
+    F32 line_alpha = ALControlCache::GridOpacity;
+
+    switch(pass)
+    {
+    case 0:
+        // shadow
+        gViewerWindow->setup3DViewport(1, -1);
+        line_color = grid_color_shadow;
+        line_color.mV[VALPHA] *= line_alpha;
+        LLUI::setLineWidth(2.f);
+        break;
+    case 1:
+        // hidden lines
+        gViewerWindow->setup3DViewport();
+        line_color = grid_color_bg;
+        line_color.mV[VALPHA] *= line_alpha;
+        LLUI::setLineWidth(1.f);
+        break;
+    case 2:
+        // visible lines
+        line_color = grid_color_fg;
+        line_color.mV[VALPHA] *= line_alpha;
+        break;
+    }
+
+    return line_color;
 }
diff --git a/indra/newview/llmaniprotate.cpp b/indra/newview/llmaniprotate.cpp
index 36e340453f8985762ccdc9d3374263c6c38aeb08..b555eebf8fe869da6a596ed7bbbc83191cb9b34a 100644
--- a/indra/newview/llmaniprotate.cpp
+++ b/indra/newview/llmaniprotate.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llmaniprotate.cpp
  * @brief LLManipRotate class implementation
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -64,7 +64,7 @@
 #include "llvoavatarself.h"
 #include "llhudrender.h"
 
-const F32 RADIUS_PIXELS = 100.f;		// size in screen space
+const F32 RADIUS_PIXELS = 100.f;        // size in screen space
 const F32 SQ_RADIUS = RADIUS_PIXELS * RADIUS_PIXELS;
 const F32 WIDTH_PIXELS = 8;
 const S32 CIRCLE_STEPS = 100;
@@ -84,502 +84,502 @@ const F32 MANIPULATOR_SCALE_HALF_LIFE = 0.07f;
 extern void handle_reset_rotation(void*);  // in LLViewerWindow
 
 LLManipRotate::LLManipRotate( LLToolComposite* composite )
-: 	LLManip( std::string("Rotate"), composite ),
-	mRotationCenter(),
-	mCenterScreen(),
-	mRotation(),
-	mMouseDown(),
-	mMouseCur(),
-	mRadiusMeters(0.f),
-	mCenterToCam(),
-	mCenterToCamNorm(),
-	mCenterToCamMag(0.f),
-	mCenterToProfilePlane(),
-	mCenterToProfilePlaneMag(0.f),
-	mSendUpdateOnMouseUp( FALSE ),
-	mSmoothRotate( FALSE ),
-	mCamEdgeOn(FALSE),
-	mManipulatorScales(1.f, 1.f, 1.f, 1.f)
+:   LLManip( std::string("Rotate"), composite ),
+    mRotationCenter(),
+    mCenterScreen(),
+    mRotation(),
+    mMouseDown(),
+    mMouseCur(),
+    mRadiusMeters(0.f),
+    mCenterToCam(),
+    mCenterToCamNorm(),
+    mCenterToCamMag(0.f),
+    mCenterToProfilePlane(),
+    mCenterToProfilePlaneMag(0.f),
+    mSendUpdateOnMouseUp( FALSE ),
+    mSmoothRotate( FALSE ),
+    mCamEdgeOn(FALSE),
+    mManipulatorScales(1.f, 1.f, 1.f, 1.f)
 { }
 
 void LLManipRotate::handleSelect()
 {
-	// *FIX: put this in mouseDown?
-	LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+    // *FIX: put this in mouseDown?
+    LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
     if (gFloaterTools)
     {
         gFloaterTools->setStatusText("rotate");
     }
-	LLManip::handleSelect();
+    LLManip::handleSelect();
 }
 
 void LLManipRotate::render()
 {
-	LLGLSUIDefault gls_ui;
-	gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep);
-	LLGLDepthTest gls_depth(GL_TRUE);
-	LLGLEnable gl_blend(GL_BLEND);
-	
-	// You can rotate if you can move
-	LLViewerObject* first_object = mObjectSelection->getFirstMoveableObject(TRUE);
-	if( !first_object )
-	{
-		return;
-	}
-
-	if( !updateVisiblity() )
-	{
-		return;
-	}
-
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		F32 zoom = gAgentCamera.mHUDCurZoom;
-		gGL.scalef(zoom, zoom, zoom);
-	}
-
-
-	LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
-
-	LLColor4 highlight_outside( 1.f, 1.f, 0.f, 1.f );
-	LLColor4 highlight_inside( 0.7f, 0.7f, 0.f, 0.5f );
-	F32 width_meters = WIDTH_PIXELS * mRadiusMeters / RADIUS_PIXELS;
-
-	gGL.pushMatrix();
-	{
-		
-		// are we in the middle of a constrained drag?
-		if (mManipPart >= LL_ROT_X && mManipPart <= LL_ROT_Z)
-		{
-			renderSnapGuides();
-		}
-		else
-		{
-			gDebugProgram.bind();
-
-			LLGLEnable cull_face(GL_CULL_FACE);
-			LLGLDepthTest gls_depth(GL_FALSE);
-			gGL.pushMatrix();
-			{
-				// Draw "sphere" (intersection of sphere with tangent cone that has apex at camera)
-				gGL.translatef( mCenterToProfilePlane.mV[VX], mCenterToProfilePlane.mV[VY], mCenterToProfilePlane.mV[VZ] );
-				gGL.translatef( center.mV[VX], center.mV[VY], center.mV[VZ] );
-
-				// Inverse change of basis vectors
-				LLVector3 forward = mCenterToCamNorm;
-				LLVector3 left = gAgent.getUpAxis() % forward;
-				left.normVec();
-				LLVector3 up = forward % left;
-
-				LLVector4 a(-forward);
-				a.mV[3] = 0;
-				LLVector4 b(up);
-				b.mV[3] = 0;
-				LLVector4 c(left);
-				c.mV[3] = 0;
-				LLMatrix4 mat;
-				mat.initRows(a, b, c, LLVector4(0.f, 0.f, 0.f, 1.f));
-
-				gGL.multMatrix( &mat.mMatrix[0][0] );
-
-				static const LLMatrix4a sphere_rot = ALGLMath::genRot(-90, 0.f, 1.f, 0.f);
-				gGL.rotatef(sphere_rot);
-				LLColor4 color;
-				if (mManipPart == LL_ROT_ROLL || mHighlightedPart == LL_ROT_ROLL)
-				{
-					color.setVec(0.8f, 0.8f, 0.8f, 0.8f);
-					gGL.scalef(mManipulatorScales.mV[VW], mManipulatorScales.mV[VW], mManipulatorScales.mV[VW]);
-				}
-				else
-				{
-					color.setVec( 0.7f, 0.7f, 0.7f, 0.6f );
-				}
-				gGL.diffuseColor4fv(color.mV);
-				gl_washer_2d(mRadiusMeters + width_meters, mRadiusMeters, CIRCLE_STEPS, color, color);
-
-
-				if (mManipPart == LL_NO_PART)
-				{
-					gGL.color4f( 0.7f, 0.7f, 0.7f, 0.3f );
-					gGL.diffuseColor4f(0.7f, 0.7f, 0.7f, 0.3f);
-					gl_circle_2d( 0, 0,  mRadiusMeters, CIRCLE_STEPS, TRUE );
-				}
-				
-				gGL.flush();
-			}
-			gGL.popMatrix();
-
-			gUIProgram.bind();
-		}
-		
-		gGL.translatef( center.mV[VX], center.mV[VY], center.mV[VZ] );
-
-		LLQuaternion rot;
-		F32 angle_radians, x, y, z;
-
-		LLVector3 grid_origin;
-		LLVector3 grid_scale;
-		LLQuaternion grid_rotation;
-
-		LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
-
-		grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
-		gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
-
-
-		gDebugProgram.bind();
-
-		if (mManipPart == LL_ROT_Z)
-		{
-			mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, SELECTED_MANIPULATOR_SCALE, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
-			gGL.pushMatrix();
-			{
-				// selected part
-				gGL.scalef(mManipulatorScales.mV[VZ], mManipulatorScales.mV[VZ], mManipulatorScales.mV[VZ]);
-				renderActiveRing( mRadiusMeters, width_meters, LLColor4( 0.f, 0.f, 1.f, 1.f) , LLColor4( 0.f, 0.f, 1.f, 0.3f ));
-			}
-			gGL.popMatrix();
-		}
-		else if (mManipPart == LL_ROT_Y)
-		{
-			mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, SELECTED_MANIPULATOR_SCALE, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
-			gGL.pushMatrix();
-			{
-				static const LLMatrix4a y_rot = ALGLMath::genRot(90.f, 1.f, 0.f, 0.f);
-				gGL.rotatef(y_rot);
-				gGL.scalef(mManipulatorScales.mV[VY], mManipulatorScales.mV[VY], mManipulatorScales.mV[VY]);
-				renderActiveRing( mRadiusMeters, width_meters, LLColor4( 0.f, 1.f, 0.f, 1.f), LLColor4( 0.f, 1.f, 0.f, 0.3f));
-			}
-			gGL.popMatrix();
-		}
-		else if (mManipPart == LL_ROT_X)
-		{
-			mManipulatorScales = lerp(mManipulatorScales, LLVector4(SELECTED_MANIPULATOR_SCALE, 1.f, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
-			gGL.pushMatrix();
-			{
-				static const LLMatrix4a x_rot = ALGLMath::genRot(90.f, 0.f, 1.f, 0.f);
-				gGL.rotatef(x_rot);
-				gGL.scalef(mManipulatorScales.mV[VX], mManipulatorScales.mV[VX], mManipulatorScales.mV[VX]);
-				renderActiveRing( mRadiusMeters, width_meters, LLColor4( 1.f, 0.f, 0.f, 1.f), LLColor4( 1.f, 0.f, 0.f, 0.3f));
-			}
-			gGL.popMatrix();
-		}
-		else if (mManipPart == LL_ROT_ROLL)
-		{
-			mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, 1.f, SELECTED_MANIPULATOR_SCALE), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
-		}
-		else if (mManipPart == LL_NO_PART)
-		{
-			if (mHighlightedPart == LL_NO_PART)
-			{
-				mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
-			}
-
-			LLGLEnable cull_face(GL_CULL_FACE);
-			LLGLEnable clip_plane0(GL_CLIP_PLANE0);
-			LLGLDepthTest gls_depth(GL_FALSE);
-			//LLGLDisable gls_stencil(GL_STENCIL_TEST);
-
-			// First pass: centers. Second pass: sides.
-			static const LLMatrix4a side1_rot = ALGLMath::genRot(90.f, 1.f, 0.f, 0.f);
-			static const LLMatrix4a side2_rot = ALGLMath::genRot(90.f, 0.f, 1.f, 0.f);
-			for( S32 i=0; i<2; i++ )
-			{
-				
-				gGL.pushMatrix();
-				{
-					if (mHighlightedPart == LL_ROT_Z)
-					{
-						mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, SELECTED_MANIPULATOR_SCALE, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
-						gGL.scalef(mManipulatorScales.mV[VZ], mManipulatorScales.mV[VZ], mManipulatorScales.mV[VZ]);
-						// hovering over part
-						gl_ring( mRadiusMeters, width_meters, LLColor4( 0.f, 0.f, 1.f, 1.f ), LLColor4( 0.f, 0.f, 1.f, 0.5f ), CIRCLE_STEPS, i);
-					}
-					else
-					{
-						// default
-						gl_ring( mRadiusMeters, width_meters, LLColor4( 0.f, 0.f, 0.8f, 0.8f ), LLColor4( 0.f, 0.f, 0.8f, 0.4f ), CIRCLE_STEPS, i);
-					}
-				}
-				gGL.popMatrix();
-				
-				gGL.pushMatrix();
-				{
-					gGL.rotatef(side1_rot);
-					if (mHighlightedPart == LL_ROT_Y)
-					{
-						mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, SELECTED_MANIPULATOR_SCALE, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
-						gGL.scalef(mManipulatorScales.mV[VY], mManipulatorScales.mV[VY], mManipulatorScales.mV[VY]);
-						// hovering over part
-						gl_ring( mRadiusMeters, width_meters, LLColor4( 0.f, 1.f, 0.f, 1.f ), LLColor4( 0.f, 1.f, 0.f, 0.5f ), CIRCLE_STEPS, i);
-					}
-					else
-					{
-						// default
-						gl_ring( mRadiusMeters, width_meters, LLColor4( 0.f, 0.8f, 0.f, 0.8f ), LLColor4( 0.f, 0.8f, 0.f, 0.4f ), CIRCLE_STEPS, i);
-					}						
-				}
-				gGL.popMatrix();
-
-				gGL.pushMatrix();
-				{
-					gGL.rotatef(side2_rot);
-					if (mHighlightedPart == LL_ROT_X)
-					{
-						mManipulatorScales = lerp(mManipulatorScales, LLVector4(SELECTED_MANIPULATOR_SCALE, 1.f, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
-						gGL.scalef(mManipulatorScales.mV[VX], mManipulatorScales.mV[VX], mManipulatorScales.mV[VX]);
-	
-						// hovering over part
-						gl_ring( mRadiusMeters, width_meters, LLColor4( 1.f, 0.f, 0.f, 1.f ), LLColor4( 1.f, 0.f, 0.f, 0.5f ), CIRCLE_STEPS, i);
-					}
-					else
-					{
-						// default
-						gl_ring( mRadiusMeters, width_meters, LLColor4( 0.8f, 0.f, 0.f, 0.8f ), LLColor4( 0.8f, 0.f, 0.f, 0.4f ), CIRCLE_STEPS, i);
-					}
-				}
-				gGL.popMatrix();
-
-				if (mHighlightedPart == LL_ROT_ROLL)
-				{
-					mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, 1.f, SELECTED_MANIPULATOR_SCALE), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
-				}
-				
-			}
-			
-		}
-
-		gUIProgram.bind();
-	}
-	gGL.popMatrix();
-	gGL.popMatrix();
-	
-
-	LLVector3 euler_angles;
-	LLQuaternion object_rot = first_object->getRotationEdit();
-	object_rot.getEulerAngles(&(euler_angles.mV[VX]), &(euler_angles.mV[VY]), &(euler_angles.mV[VZ]));
-	euler_angles *= RAD_TO_DEG;
-	euler_angles.mV[VX] = ll_round(fmodf(euler_angles.mV[VX] + 360.f, 360.f), 0.05f);
-	euler_angles.mV[VY] = ll_round(fmodf(euler_angles.mV[VY] + 360.f, 360.f), 0.05f);
-	euler_angles.mV[VZ] = ll_round(fmodf(euler_angles.mV[VZ] + 360.f, 360.f), 0.05f);
-
-	renderXYZ(euler_angles);
+    LLGLSUIDefault gls_ui;
+    gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep);
+    LLGLDepthTest gls_depth(GL_TRUE);
+    LLGLEnable gl_blend(GL_BLEND);
+
+    // You can rotate if you can move
+    LLViewerObject* first_object = mObjectSelection->getFirstMoveableObject(TRUE);
+    if( !first_object )
+    {
+        return;
+    }
+
+    if( !updateVisiblity() )
+    {
+        return;
+    }
+
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        F32 zoom = gAgentCamera.mHUDCurZoom;
+        gGL.scalef(zoom, zoom, zoom);
+    }
+
+
+    LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
+
+    LLColor4 highlight_outside( 1.f, 1.f, 0.f, 1.f );
+    LLColor4 highlight_inside( 0.7f, 0.7f, 0.f, 0.5f );
+    F32 width_meters = WIDTH_PIXELS * mRadiusMeters / RADIUS_PIXELS;
+
+    gGL.pushMatrix();
+    {
+
+        // are we in the middle of a constrained drag?
+        if (mManipPart >= LL_ROT_X && mManipPart <= LL_ROT_Z)
+        {
+            renderSnapGuides();
+        }
+        else
+        {
+            gDebugProgram.bind();
+
+            LLGLEnable cull_face(GL_CULL_FACE);
+            LLGLDepthTest gls_depth(GL_FALSE);
+            gGL.pushMatrix();
+            {
+                // Draw "sphere" (intersection of sphere with tangent cone that has apex at camera)
+                gGL.translatef( mCenterToProfilePlane.mV[VX], mCenterToProfilePlane.mV[VY], mCenterToProfilePlane.mV[VZ] );
+                gGL.translatef( center.mV[VX], center.mV[VY], center.mV[VZ] );
+
+                // Inverse change of basis vectors
+                LLVector3 forward = mCenterToCamNorm;
+                LLVector3 left = gAgent.getUpAxis() % forward;
+                left.normVec();
+                LLVector3 up = forward % left;
+
+                LLVector4 a(-forward);
+                a.mV[3] = 0;
+                LLVector4 b(up);
+                b.mV[3] = 0;
+                LLVector4 c(left);
+                c.mV[3] = 0;
+                LLMatrix4 mat;
+                mat.initRows(a, b, c, LLVector4(0.f, 0.f, 0.f, 1.f));
+
+                gGL.multMatrix( &mat.mMatrix[0][0] );
+
+                static const LLMatrix4a sphere_rot = ALGLMath::genRot(-90, 0.f, 1.f, 0.f);
+                gGL.rotatef(sphere_rot);
+                LLColor4 color;
+                if (mManipPart == LL_ROT_ROLL || mHighlightedPart == LL_ROT_ROLL)
+                {
+                    color.setVec(0.8f, 0.8f, 0.8f, 0.8f);
+                    gGL.scalef(mManipulatorScales.mV[VW], mManipulatorScales.mV[VW], mManipulatorScales.mV[VW]);
+                }
+                else
+                {
+                    color.setVec( 0.7f, 0.7f, 0.7f, 0.6f );
+                }
+                gGL.diffuseColor4fv(color.mV);
+                gl_washer_2d(mRadiusMeters + width_meters, mRadiusMeters, CIRCLE_STEPS, color, color);
+
+
+                if (mManipPart == LL_NO_PART)
+                {
+                    gGL.color4f( 0.7f, 0.7f, 0.7f, 0.3f );
+                    gGL.diffuseColor4f(0.7f, 0.7f, 0.7f, 0.3f);
+                    gl_circle_2d( 0, 0,  mRadiusMeters, CIRCLE_STEPS, TRUE );
+                }
+
+                gGL.flush();
+            }
+            gGL.popMatrix();
+
+            gUIProgram.bind();
+        }
+
+        gGL.translatef( center.mV[VX], center.mV[VY], center.mV[VZ] );
+
+        LLQuaternion rot;
+        F32 angle_radians, x, y, z;
+
+        LLVector3 grid_origin;
+        LLVector3 grid_scale;
+        LLQuaternion grid_rotation;
+
+        LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
+
+        grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
+        gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
+
+
+        gDebugProgram.bind();
+
+        if (mManipPart == LL_ROT_Z)
+        {
+            mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, SELECTED_MANIPULATOR_SCALE, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
+            gGL.pushMatrix();
+            {
+                // selected part
+                gGL.scalef(mManipulatorScales.mV[VZ], mManipulatorScales.mV[VZ], mManipulatorScales.mV[VZ]);
+                renderActiveRing( mRadiusMeters, width_meters, LLColor4( 0.f, 0.f, 1.f, 1.f) , LLColor4( 0.f, 0.f, 1.f, 0.3f ));
+            }
+            gGL.popMatrix();
+        }
+        else if (mManipPart == LL_ROT_Y)
+        {
+            mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, SELECTED_MANIPULATOR_SCALE, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
+            gGL.pushMatrix();
+            {
+                static const LLMatrix4a y_rot = ALGLMath::genRot(90.f, 1.f, 0.f, 0.f);
+                gGL.rotatef(y_rot);
+                gGL.scalef(mManipulatorScales.mV[VY], mManipulatorScales.mV[VY], mManipulatorScales.mV[VY]);
+                renderActiveRing( mRadiusMeters, width_meters, LLColor4( 0.f, 1.f, 0.f, 1.f), LLColor4( 0.f, 1.f, 0.f, 0.3f));
+            }
+            gGL.popMatrix();
+        }
+        else if (mManipPart == LL_ROT_X)
+        {
+            mManipulatorScales = lerp(mManipulatorScales, LLVector4(SELECTED_MANIPULATOR_SCALE, 1.f, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
+            gGL.pushMatrix();
+            {
+                static const LLMatrix4a x_rot = ALGLMath::genRot(90.f, 0.f, 1.f, 0.f);
+                gGL.rotatef(x_rot);
+                gGL.scalef(mManipulatorScales.mV[VX], mManipulatorScales.mV[VX], mManipulatorScales.mV[VX]);
+                renderActiveRing( mRadiusMeters, width_meters, LLColor4( 1.f, 0.f, 0.f, 1.f), LLColor4( 1.f, 0.f, 0.f, 0.3f));
+            }
+            gGL.popMatrix();
+        }
+        else if (mManipPart == LL_ROT_ROLL)
+        {
+            mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, 1.f, SELECTED_MANIPULATOR_SCALE), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
+        }
+        else if (mManipPart == LL_NO_PART)
+        {
+            if (mHighlightedPart == LL_NO_PART)
+            {
+                mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
+            }
+
+            LLGLEnable cull_face(GL_CULL_FACE);
+            LLGLEnable clip_plane0(GL_CLIP_PLANE0);
+            LLGLDepthTest gls_depth(GL_FALSE);
+            //LLGLDisable gls_stencil(GL_STENCIL_TEST);
+
+            // First pass: centers. Second pass: sides.
+            static const LLMatrix4a side1_rot = ALGLMath::genRot(90.f, 1.f, 0.f, 0.f);
+            static const LLMatrix4a side2_rot = ALGLMath::genRot(90.f, 0.f, 1.f, 0.f);
+            for( S32 i=0; i<2; i++ )
+            {
+
+                gGL.pushMatrix();
+                {
+                    if (mHighlightedPart == LL_ROT_Z)
+                    {
+                        mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, SELECTED_MANIPULATOR_SCALE, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
+                        gGL.scalef(mManipulatorScales.mV[VZ], mManipulatorScales.mV[VZ], mManipulatorScales.mV[VZ]);
+                        // hovering over part
+                        gl_ring( mRadiusMeters, width_meters, LLColor4( 0.f, 0.f, 1.f, 1.f ), LLColor4( 0.f, 0.f, 1.f, 0.5f ), CIRCLE_STEPS, i);
+                    }
+                    else
+                    {
+                        // default
+                        gl_ring( mRadiusMeters, width_meters, LLColor4( 0.f, 0.f, 0.8f, 0.8f ), LLColor4( 0.f, 0.f, 0.8f, 0.4f ), CIRCLE_STEPS, i);
+                    }
+                }
+                gGL.popMatrix();
+
+                gGL.pushMatrix();
+                {
+                    gGL.rotatef(side1_rot);
+                    if (mHighlightedPart == LL_ROT_Y)
+                    {
+                        mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, SELECTED_MANIPULATOR_SCALE, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
+                        gGL.scalef(mManipulatorScales.mV[VY], mManipulatorScales.mV[VY], mManipulatorScales.mV[VY]);
+                        // hovering over part
+                        gl_ring( mRadiusMeters, width_meters, LLColor4( 0.f, 1.f, 0.f, 1.f ), LLColor4( 0.f, 1.f, 0.f, 0.5f ), CIRCLE_STEPS, i);
+                    }
+                    else
+                    {
+                        // default
+                        gl_ring( mRadiusMeters, width_meters, LLColor4( 0.f, 0.8f, 0.f, 0.8f ), LLColor4( 0.f, 0.8f, 0.f, 0.4f ), CIRCLE_STEPS, i);
+                    }
+                }
+                gGL.popMatrix();
+
+                gGL.pushMatrix();
+                {
+                    gGL.rotatef(side2_rot);
+                    if (mHighlightedPart == LL_ROT_X)
+                    {
+                        mManipulatorScales = lerp(mManipulatorScales, LLVector4(SELECTED_MANIPULATOR_SCALE, 1.f, 1.f, 1.f), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
+                        gGL.scalef(mManipulatorScales.mV[VX], mManipulatorScales.mV[VX], mManipulatorScales.mV[VX]);
+
+                        // hovering over part
+                        gl_ring( mRadiusMeters, width_meters, LLColor4( 1.f, 0.f, 0.f, 1.f ), LLColor4( 1.f, 0.f, 0.f, 0.5f ), CIRCLE_STEPS, i);
+                    }
+                    else
+                    {
+                        // default
+                        gl_ring( mRadiusMeters, width_meters, LLColor4( 0.8f, 0.f, 0.f, 0.8f ), LLColor4( 0.8f, 0.f, 0.f, 0.4f ), CIRCLE_STEPS, i);
+                    }
+                }
+                gGL.popMatrix();
+
+                if (mHighlightedPart == LL_ROT_ROLL)
+                {
+                    mManipulatorScales = lerp(mManipulatorScales, LLVector4(1.f, 1.f, 1.f, SELECTED_MANIPULATOR_SCALE), LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE));
+                }
+
+            }
+
+        }
+
+        gUIProgram.bind();
+    }
+    gGL.popMatrix();
+    gGL.popMatrix();
+
+
+    LLVector3 euler_angles;
+    LLQuaternion object_rot = first_object->getRotationEdit();
+    object_rot.getEulerAngles(&(euler_angles.mV[VX]), &(euler_angles.mV[VY]), &(euler_angles.mV[VZ]));
+    euler_angles *= RAD_TO_DEG;
+    euler_angles.mV[VX] = ll_round(fmodf(euler_angles.mV[VX] + 360.f, 360.f), 0.05f);
+    euler_angles.mV[VY] = ll_round(fmodf(euler_angles.mV[VY] + 360.f, 360.f), 0.05f);
+    euler_angles.mV[VZ] = ll_round(fmodf(euler_angles.mV[VZ] + 360.f, 360.f), 0.05f);
+
+    renderXYZ(euler_angles);
 }
 
 BOOL LLManipRotate::handleMouseDown(S32 x, S32 y, MASK mask)
 {
-	BOOL	handled = FALSE;
-
-	LLViewerObject* first_object = mObjectSelection->getFirstMoveableObject(TRUE);
-	if( first_object )
-	{
-		if( mHighlightedPart != LL_NO_PART )
-		{
-			handled = handleMouseDownOnPart( x, y, mask );
-		}
-	}
-
-	return handled;
+    BOOL    handled = FALSE;
+
+    LLViewerObject* first_object = mObjectSelection->getFirstMoveableObject(TRUE);
+    if( first_object )
+    {
+        if( mHighlightedPart != LL_NO_PART )
+        {
+            handled = handleMouseDownOnPart( x, y, mask );
+        }
+    }
+
+    return handled;
 }
 
 // Assumes that one of the parts of the manipulator was hit.
 BOOL LLManipRotate::handleMouseDownOnPart( S32 x, S32 y, MASK mask )
 {
-	BOOL can_rotate = canAffectSelection();
-	if (!can_rotate)
-	{
-		return FALSE;
-	}
-
-	highlightManipulators(x, y);
-	S32 hit_part = mHighlightedPart;
-	// we just started a drag, so save initial object positions
-	LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_ROTATE);
-
-	// save selection center
-	mRotationCenter = gAgent.getPosGlobalFromAgent( getPivotPoint() ); //LLSelectMgr::getInstance()->getSelectionCenterGlobal();
-
-	mManipPart = (EManipPart)hit_part;
-	LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
-
-	if( mManipPart == LL_ROT_GENERAL)
-	{
-		mMouseDown = intersectMouseWithSphere( x, y, center, mRadiusMeters);
-	}
-	else
-	{
-		// Project onto the plane of the ring
-		LLVector3 axis = getConstraintAxis();
-
-		F32 axis_onto_cam = llabs( axis * mCenterToCamNorm );
-		const F32 AXIS_ONTO_CAM_TOL = cos( 85.f * DEG_TO_RAD );
-		if( axis_onto_cam < AXIS_ONTO_CAM_TOL )
-		{
-			LLVector3 up_from_axis = mCenterToCamNorm % axis;
-			up_from_axis.normVec();
-			LLVector3 cur_intersection;
-			getMousePointOnPlaneAgent(cur_intersection, x, y, center, mCenterToCam);
-			cur_intersection -= center;
-			mMouseDown = projected_vec(cur_intersection, up_from_axis);
-			F32 mouse_depth = SNAP_GUIDE_INNER_RADIUS * mRadiusMeters;
-			F32 mouse_dist_sqrd = mMouseDown.magVecSquared();
-			if (mouse_dist_sqrd > 0.0001f)
-			{
-				mouse_depth = sqrtf((SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) * (SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) - 
-									mouse_dist_sqrd);
-			}
-			LLVector3 projected_center_to_cam = mCenterToCamNorm - projected_vec(mCenterToCamNorm, axis);
-			mMouseDown += mouse_depth * projected_center_to_cam;
-
-		}
-		else
-		{
-			mMouseDown = findNearestPointOnRing( x, y, center, axis ) - center;
-			mMouseDown.normVec();
-		}
-	}
-
-	mMouseCur = mMouseDown;
-	mAgentSelfAtAxis = gAgent.getAtAxis(); // no point checking if avatar was selected, just save the value
-
-	// Route future Mouse messages here preemptively.  (Release on mouse up.)
-	setMouseCapture( TRUE );
-	LLSelectMgr::getInstance()->enableSilhouette(FALSE);
-
-	mHelpTextTimer.reset();
-	sNumTimesHelpTextShown++;
-	return TRUE;
+    BOOL can_rotate = canAffectSelection();
+    if (!can_rotate)
+    {
+        return FALSE;
+    }
+
+    highlightManipulators(x, y);
+    S32 hit_part = mHighlightedPart;
+    // we just started a drag, so save initial object positions
+    LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_ROTATE);
+
+    // save selection center
+    mRotationCenter = gAgent.getPosGlobalFromAgent( getPivotPoint() ); //LLSelectMgr::getInstance()->getSelectionCenterGlobal();
+
+    mManipPart = (EManipPart)hit_part;
+    LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
+
+    if( mManipPart == LL_ROT_GENERAL)
+    {
+        mMouseDown = intersectMouseWithSphere( x, y, center, mRadiusMeters);
+    }
+    else
+    {
+        // Project onto the plane of the ring
+        LLVector3 axis = getConstraintAxis();
+
+        F32 axis_onto_cam = llabs( axis * mCenterToCamNorm );
+        const F32 AXIS_ONTO_CAM_TOL = cos( 85.f * DEG_TO_RAD );
+        if( axis_onto_cam < AXIS_ONTO_CAM_TOL )
+        {
+            LLVector3 up_from_axis = mCenterToCamNorm % axis;
+            up_from_axis.normVec();
+            LLVector3 cur_intersection;
+            getMousePointOnPlaneAgent(cur_intersection, x, y, center, mCenterToCam);
+            cur_intersection -= center;
+            mMouseDown = projected_vec(cur_intersection, up_from_axis);
+            F32 mouse_depth = SNAP_GUIDE_INNER_RADIUS * mRadiusMeters;
+            F32 mouse_dist_sqrd = mMouseDown.magVecSquared();
+            if (mouse_dist_sqrd > 0.0001f)
+            {
+                mouse_depth = sqrtf((SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) * (SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) -
+                                    mouse_dist_sqrd);
+            }
+            LLVector3 projected_center_to_cam = mCenterToCamNorm - projected_vec(mCenterToCamNorm, axis);
+            mMouseDown += mouse_depth * projected_center_to_cam;
+
+        }
+        else
+        {
+            mMouseDown = findNearestPointOnRing( x, y, center, axis ) - center;
+            mMouseDown.normVec();
+        }
+    }
+
+    mMouseCur = mMouseDown;
+    mAgentSelfAtAxis = gAgent.getAtAxis(); // no point checking if avatar was selected, just save the value
+
+    // Route future Mouse messages here preemptively.  (Release on mouse up.)
+    setMouseCapture( TRUE );
+    LLSelectMgr::getInstance()->enableSilhouette(FALSE);
+
+    mHelpTextTimer.reset();
+    sNumTimesHelpTextShown++;
+    return TRUE;
 }
 
 
 LLVector3 LLManipRotate::findNearestPointOnRing( S32 x, S32 y, const LLVector3& center, const LLVector3& axis )
 {
-	// Project the delta onto the ring and rescale it by the radius so that it's _on_ the ring.
-	LLVector3 proj_onto_ring;
-	getMousePointOnPlaneAgent(proj_onto_ring, x, y, center, axis);
-	proj_onto_ring -= center;
-	proj_onto_ring.normVec();
+    // Project the delta onto the ring and rescale it by the radius so that it's _on_ the ring.
+    LLVector3 proj_onto_ring;
+    getMousePointOnPlaneAgent(proj_onto_ring, x, y, center, axis);
+    proj_onto_ring -= center;
+    proj_onto_ring.normVec();
 
-	return center + proj_onto_ring * mRadiusMeters;
+    return center + proj_onto_ring * mRadiusMeters;
 }
 
 BOOL LLManipRotate::handleMouseUp(S32 x, S32 y, MASK mask)
 {
-	// first, perform normal processing in case this was a quick-click
-	handleHover(x, y, mask);
-
-	if( hasMouseCapture() )
-	{
-		for (LLObjectSelection::iterator iter = mObjectSelection->begin();
-		 iter != mObjectSelection->end(); iter++)
-		{
-			LLSelectNode* selectNode = *iter;
-			LLViewerObject* object = selectNode->getObject();
-			LLViewerObject* root_object = (object == NULL) ? NULL : object->getRootEdit();
-
-			// have permission to move and object is root of selection or individually selected
-			if (object->permMove() && !object->isPermanentEnforced() &&
-				((root_object == NULL) || !root_object->isPermanentEnforced()) &&
-				(object->isRootEdit() || selectNode->mIndividualSelection))
-			{
-				object->mUnselectedChildrenPositions.clear() ;
-			}
-		}
-
-		mManipPart = LL_NO_PART;
-
-		// Might have missed last update due to timing.
-		LLSelectMgr::getInstance()->sendMultipleUpdate( UPD_ROTATION | UPD_POSITION );
-		LLSelectMgr::getInstance()->enableSilhouette(TRUE);
-		//gAgent.setObjectTracking(gSavedSettings.getBOOL("TrackFocusObject"));
-
-		LLSelectMgr::getInstance()->updateSelectionCenter();
-		LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
-	}
-
-	return LLManip::handleMouseUp(x, y, mask);
+    // first, perform normal processing in case this was a quick-click
+    handleHover(x, y, mask);
+
+    if( hasMouseCapture() )
+    {
+        for (LLObjectSelection::iterator iter = mObjectSelection->begin();
+         iter != mObjectSelection->end(); iter++)
+        {
+            LLSelectNode* selectNode = *iter;
+            LLViewerObject* object = selectNode->getObject();
+            LLViewerObject* root_object = (object == NULL) ? NULL : object->getRootEdit();
+
+            // have permission to move and object is root of selection or individually selected
+            if (object->permMove() && !object->isPermanentEnforced() &&
+                ((root_object == NULL) || !root_object->isPermanentEnforced()) &&
+                (object->isRootEdit() || selectNode->mIndividualSelection))
+            {
+                object->mUnselectedChildrenPositions.clear() ;
+            }
+        }
+
+        mManipPart = LL_NO_PART;
+
+        // Might have missed last update due to timing.
+        LLSelectMgr::getInstance()->sendMultipleUpdate( UPD_ROTATION | UPD_POSITION );
+        LLSelectMgr::getInstance()->enableSilhouette(TRUE);
+        //gAgent.setObjectTracking(gSavedSettings.getBOOL("TrackFocusObject"));
+
+        LLSelectMgr::getInstance()->updateSelectionCenter();
+        LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+    }
+
+    return LLManip::handleMouseUp(x, y, mask);
 }
 
 
 BOOL LLManipRotate::handleHover(S32 x, S32 y, MASK mask)
 {
-	if( hasMouseCapture() )
-	{
-		if( mObjectSelection->isEmpty() )
-		{
-			// Somehow the object got deselected while we were dragging it.
-			setMouseCapture( FALSE );
-		}
-		else
-		{
-			drag(x, y);
-		}
+    if( hasMouseCapture() )
+    {
+        if( mObjectSelection->isEmpty() )
+        {
+            // Somehow the object got deselected while we were dragging it.
+            setMouseCapture( FALSE );
+        }
+        else
+        {
+            drag(x, y);
+        }
 
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("UserInput") << "hover handled by LLManipRotate (active)" << LL_ENDL;		
+        LL_DEBUGS("UserInput") << "hover handled by LLManipRotate (active)" << LL_ENDL;
 #endif
-	}
-	else
-	{
-		highlightManipulators(x, y);
+    }
+    else
+    {
+        highlightManipulators(x, y);
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("UserInput") << "hover handled by LLManipRotate (inactive)" << LL_ENDL;		
+        LL_DEBUGS("UserInput") << "hover handled by LLManipRotate (inactive)" << LL_ENDL;
 #endif
-	}
+    }
 
-	gViewerWindow->setCursor(UI_CURSOR_TOOLROTATE);
-	return TRUE;
+    gViewerWindow->setCursor(UI_CURSOR_TOOLROTATE);
+    return TRUE;
 }
 
 
-LLVector3 LLManipRotate::projectToSphere( F32 x, F32 y, BOOL* on_sphere ) 
+LLVector3 LLManipRotate::projectToSphere( F32 x, F32 y, BOOL* on_sphere )
 {
-	F32 z = 0.f;
-	F32 dist_squared = x*x + y*y;
+    F32 z = 0.f;
+    F32 dist_squared = x*x + y*y;
 
-	*on_sphere = dist_squared <= SQ_RADIUS;
+    *on_sphere = dist_squared <= SQ_RADIUS;
     if( *on_sphere )
-	{    
+    {
         z = sqrt(SQ_RADIUS - dist_squared);
     }
-	return LLVector3( x, y, z );
+    return LLVector3( x, y, z );
 }
 
 // Freeform rotation
 void LLManipRotate::drag( S32 x, S32 y )
 {
-	if( !updateVisiblity() )
-	{
-		return;
-	}
-
-	if( mManipPart == LL_ROT_GENERAL )
-	{
-		mRotation = dragUnconstrained(x, y);
-	}
-	else
-	{
-		mRotation = dragConstrained(x, y);
-	}
-
-	BOOL damped = mSmoothRotate;
-	mSmoothRotate = FALSE;
-    bool gltf_mode = false;
+    if( !updateVisiblity() )
+    {
+        return;
+    }
+
+    if( mManipPart == LL_ROT_GENERAL )
+    {
+        mRotation = dragUnconstrained(x, y);
+    }
+    else
+    {
+        mRotation = dragConstrained(x, y);
+    }
 
-	for (LLObjectSelection::iterator iter = mObjectSelection->begin();
-		 iter != mObjectSelection->end(); iter++)
-	{
-		LLSelectNode* selectNode = *iter;
-		LLViewerObject* object = selectNode->getObject();
-		LLViewerObject* root_object = (object == NULL) ? NULL : object->getRootEdit();
+    BOOL damped = mSmoothRotate;
+    mSmoothRotate = FALSE;
+    bool gltf_mode = false;
 
-		// have permission to move and object is root of selection or individually selected
-		if (object->permMove() && !object->isPermanentEnforced() &&
-			((root_object == NULL) || !root_object->isPermanentEnforced()) &&
-			(object->isRootEdit() || selectNode->mIndividualSelection))
-		{
+    for (LLObjectSelection::iterator iter = mObjectSelection->begin();
+         iter != mObjectSelection->end(); iter++)
+    {
+        LLSelectNode* selectNode = *iter;
+        LLViewerObject* object = selectNode->getObject();
+        LLViewerObject* root_object = (object == NULL) ? NULL : object->getRootEdit();
+
+        // have permission to move and object is root of selection or individually selected
+        if (object->permMove() && !object->isPermanentEnforced() &&
+            ((root_object == NULL) || !root_object->isPermanentEnforced()) &&
+            (object->isRootEdit() || selectNode->mIndividualSelection))
+        {
 
             if (selectNode->mSelectedGLTFNode != -1)
             {
@@ -653,10 +653,10 @@ void LLManipRotate::drag( S32 x, S32 y )
                     object->resetChildrenRotationAndPosition(child_rotations, child_positions);
                 }
             }
-		}
-	}
+        }
+    }
 
-	// update positions
+    // update positions
     if (!gltf_mode)
     {
         for (LLObjectSelection::iterator iter = mObjectSelection->begin();
@@ -684,7 +684,7 @@ void LLManipRotate::drag( S32 x, S32 y )
                 {
                     if (object->isAttachment() && object->mDrawable.notNull())
                     {
-                        // need to work in drawable space to handle selected items from multiple attachments 
+                        // need to work in drawable space to handle selected items from multiple attachments
                         // (which have no shared frame of reference other than their render positions)
                         LLXform* parent_xform = object->mDrawable->getXform()->getParent();
                         new_position = (selectNode->mSavedPositionLocal * parent_xform->getWorldRotation()) + parent_xform->getWorldPosition();
@@ -696,7 +696,7 @@ void LLManipRotate::drag( S32 x, S32 y )
                         old_position = object->getPositionAgent();
                     }
 
-                    new_position = (new_position - center) * mRotation;		// new relative rotated position
+                    new_position = (new_position - center) * mRotation;     // new relative rotated position
                     new_position += center;
 
                     if (object->isRootEdit() && !object->isAttachment())
@@ -752,1244 +752,1244 @@ void LLManipRotate::drag( S32 x, S32 y )
         }
     }
 
-	// store changes to override updates
-	for (LLSelectNode* selectNode : LLSelectMgr::getInstance()->getSelection()->begin_end())
-	{
-		LLViewerObject*cur = selectNode->getObject();
-		LLViewerObject *root_object = (cur == NULL) ? NULL : cur->getRootEdit();
+    // store changes to override updates
+    for (LLSelectNode* selectNode : LLSelectMgr::getInstance()->getSelection()->begin_end())
+    {
+        LLViewerObject*cur = selectNode->getObject();
+        LLViewerObject *root_object = (cur == NULL) ? NULL : cur->getRootEdit();
 
         if( cur->permModify() && cur->permMove() && !cur->isPermanentEnforced() &&
-			((root_object == NULL) || !root_object->isPermanentEnforced()) &&
-			(!cur->isAvatar() || LLSelectMgr::getInstance()->mAllowSelectAvatar))
-		{
+            ((root_object == NULL) || !root_object->isPermanentEnforced()) &&
+            (!cur->isAvatar() || LLSelectMgr::getInstance()->mAllowSelectAvatar))
+        {
            selectNode->mLastRotation = cur->getRotation();
            selectNode->mLastPositionLocal = cur->getPosition();
-		}
-	}	
+        }
+    }
 
-	LLSelectMgr::getInstance()->updateSelectionCenter();
+    LLSelectMgr::getInstance()->updateSelectionCenter();
 
-	// RN: just clear focus so camera doesn't follow spurious object updates
-	gAgentCamera.clearFocusObject();
-	dialog_refresh_all();
+    // RN: just clear focus so camera doesn't follow spurious object updates
+    gAgentCamera.clearFocusObject();
+    dialog_refresh_all();
 }
 
 void LLManipRotate::renderActiveRing( F32 radius, F32 width, const LLColor4& front_color, const LLColor4& back_color)
 {
-	LLGLEnable cull_face(GL_CULL_FACE);
-	{
-		gl_ring(radius, width, back_color, back_color * 0.5f, CIRCLE_STEPS, FALSE);
-		gl_ring(radius, width, back_color, back_color * 0.5f, CIRCLE_STEPS, TRUE);
-	}
-	{
-		LLGLDepthTest gls_depth(GL_FALSE);
-		gl_ring(radius, width, front_color, front_color * 0.5f, CIRCLE_STEPS, FALSE);
-		gl_ring(radius, width, front_color, front_color * 0.5f, CIRCLE_STEPS, TRUE);
-	}
+    LLGLEnable cull_face(GL_CULL_FACE);
+    {
+        gl_ring(radius, width, back_color, back_color * 0.5f, CIRCLE_STEPS, FALSE);
+        gl_ring(radius, width, back_color, back_color * 0.5f, CIRCLE_STEPS, TRUE);
+    }
+    {
+        LLGLDepthTest gls_depth(GL_FALSE);
+        gl_ring(radius, width, front_color, front_color * 0.5f, CIRCLE_STEPS, FALSE);
+        gl_ring(radius, width, front_color, front_color * 0.5f, CIRCLE_STEPS, TRUE);
+    }
 }
 
 void LLManipRotate::renderSnapGuides()
 {
-	if (!ALControlCache::SnapEnabled)
-	{
-		return;
-	}
-
-	LLVector3 grid_origin;
-	LLVector3 grid_scale;
-	LLQuaternion grid_rotation;
-
-	LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale, true);
-
-	LLVector3 constraint_axis = getConstraintAxis();
-
-	LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
-	LLVector3 cam_at_axis;
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		cam_at_axis.setVec(1.f, 0.f, 0.f);
-	}
-	else
-	{
-		cam_at_axis = center - gAgentCamera.getCameraPositionAgent();
-		cam_at_axis.normVec();
-	}
-
-	LLVector3 world_snap_axis;
-	LLVector3 test_axis = constraint_axis;
-
-	BOOL constrain_to_ref_object = FALSE;
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_ATTACHMENT && isAgentAvatarValid())
-	{
-		test_axis = test_axis * ~grid_rotation;
-	}
-	else if (LLSelectMgr::getInstance()->getGridMode() == GRID_MODE_REF_OBJECT)
-	{
-		test_axis = test_axis * ~grid_rotation;
-		constrain_to_ref_object = TRUE;
-	}
-
-	test_axis.abs();
-
-	// find closest global/reference axis to local constraint axis;
-	if (test_axis.mV[VX] > test_axis.mV[VY] && test_axis.mV[VX] > test_axis.mV[VZ])
-	{
-		world_snap_axis = LLVector3::y_axis;
-	}
-	else if (test_axis.mV[VY] > test_axis.mV[VZ])
-	{
-		world_snap_axis = LLVector3::z_axis;
-	}
-	else
-	{
-		world_snap_axis = LLVector3::x_axis;
-	}
-
-	LLVector3 projected_snap_axis = world_snap_axis;
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_ATTACHMENT && isAgentAvatarValid())
-	{
-		projected_snap_axis = projected_snap_axis * grid_rotation;
-	}
-	else if (constrain_to_ref_object)
-	{
-		projected_snap_axis = projected_snap_axis * grid_rotation;
-	}
-
-	// project world snap axis onto constraint plane
-	projected_snap_axis -= projected_vec(projected_snap_axis, constraint_axis);
-	projected_snap_axis.normVec();
-
-	static const LLWString direction_up_text = utf8string_to_wstring(LLTrans::getString("Direction_Up"));
-	static const LLWString direction_down_text = utf8string_to_wstring(LLTrans::getString("Direction_Down"));
-
-	static const LLWString direction_forward_text = utf8string_to_wstring(LLTrans::getString("Direction_Forward"));
-	static const LLWString direction_back_text = utf8string_to_wstring(LLTrans::getString("Direction_Back"));
-	static const LLWString direction_right_text = utf8string_to_wstring(LLTrans::getString("Direction_Right"));
-	static const LLWString direction_left_text = utf8string_to_wstring(LLTrans::getString("Direction_Left"));
-
-	static const LLWString direction_north_text = utf8string_to_wstring(LLTrans::getString("Direction_North"));
-	static const LLWString direction_south_text = utf8string_to_wstring(LLTrans::getString("Direction_South"));
-	static const LLWString direction_east_text = utf8string_to_wstring(LLTrans::getString("Direction_East"));
-	static const LLWString direction_west_text = utf8string_to_wstring(LLTrans::getString("Direction_West"));
-
-	S32 num_rings = mCamEdgeOn ? 2 : 1;
-	for (S32 ring_num = 0; ring_num < num_rings; ring_num++)
-	{
-		LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
-
-		if (mCamEdgeOn)
-		{
-			// draw two opposing rings
-			if (ring_num == 0)
-			{
-				center += constraint_axis * mRadiusMeters * 0.5f;
-			}
-			else
-			{
-				center -= constraint_axis * mRadiusMeters * 0.5f;
-			}
-		}
-
-		LLGLDepthTest gls_depth(GL_FALSE);
-		for (S32 pass = 0; pass < 3; pass++)
-		{
-			// render snap guide ring
-			gGL.pushMatrix();
-			
-			LLQuaternion snap_guide_rot;
-			F32 angle_radians, x, y, z;
-			snap_guide_rot.shortestArc(LLVector3::z_axis, getConstraintAxis());
-			snap_guide_rot.getAngleAxis(&angle_radians, &x, &y, &z);
-			gGL.translatef(center.mV[VX], center.mV[VY], center.mV[VZ]);
-			gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
-
-			LLColor4 line_color = setupSnapGuideRenderPass(pass);
-
-			gGL.color4fv(line_color.mV);
-
-			if (mCamEdgeOn)
-			{
-				// render an arc
-				LLVector3 edge_normal = cam_at_axis % constraint_axis;
-				edge_normal.normVec();
-				LLVector3 x_axis_snap = LLVector3::x_axis * snap_guide_rot;
-				LLVector3 y_axis_snap = LLVector3::y_axis * snap_guide_rot;
-
-				F32 end_angle = atan2(y_axis_snap * edge_normal, x_axis_snap * edge_normal);
-				//F32 start_angle = angle_between((-1.f * LLVector3::x_axis) * snap_guide_rot, edge_normal);
-				F32 start_angle = end_angle - F_PI;
-				gl_arc_2d(0.f, 0.f, mRadiusMeters * SNAP_GUIDE_INNER_RADIUS, CIRCLE_STEPS, FALSE, start_angle, end_angle);
-			}
-			else
-			{
-				gl_circle_2d(0.f, 0.f, mRadiusMeters * SNAP_GUIDE_INNER_RADIUS, CIRCLE_STEPS, FALSE);
-			}
-			gGL.popMatrix();
-
-			for (S32 i = 0; i < 64; i++)
-			{
-				BOOL render_text = TRUE;
-				F32 deg = 5.625f * (F32)i;
-				LLVector3 inner_point;
-				LLVector3 outer_point;
-				LLVector3 text_point;
-				LLQuaternion rot(deg * DEG_TO_RAD, constraint_axis);
-				gGL.begin(LLRender::LINES);
-				{
-					inner_point = (projected_snap_axis * mRadiusMeters * SNAP_GUIDE_INNER_RADIUS * rot) + center;
-					F32 tick_length = 0.f;
-					if (i % 16 == 0)
-					{
-						tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_1 - SNAP_GUIDE_INNER_RADIUS);
-					}
-					else if (i % 8 == 0)
-					{
-						tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_2 - SNAP_GUIDE_INNER_RADIUS);
-					}
-					else if (i % 4 == 0)
-					{
-						tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_3 - SNAP_GUIDE_INNER_RADIUS);
-					}
-					else if (i % 2 == 0)
-					{
-						tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_4 - SNAP_GUIDE_INNER_RADIUS);
-					}
-					else
-					{
-						tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_5 - SNAP_GUIDE_INNER_RADIUS);
-					}
-					
-					if (mCamEdgeOn)
-					{
-						// don't draw ticks that are on back side of circle
-						F32 dot = cam_at_axis * (projected_snap_axis * rot);
-						if (dot > 0.f)
-						{
-							outer_point = inner_point;
-							render_text = FALSE;
-						}
-						else
-						{
-							if (ring_num == 0)
-							{
-								outer_point = inner_point + (constraint_axis * tick_length) * rot;
-							}
-							else
-							{
-								outer_point = inner_point - (constraint_axis * tick_length) * rot;
-							}
-						}
-					}
-					else
-					{
-						outer_point = inner_point + (projected_snap_axis * tick_length) * rot;
-					}
-
-					text_point = outer_point + (projected_snap_axis * mRadiusMeters * 0.1f) * rot;
-
-					gGL.vertex3fv(inner_point.mV);
-					gGL.vertex3fv(outer_point.mV);
-				}
-				gGL.end();
-
-				//RN: text rendering does own shadow pass, so only render once
-				if (pass == 1 && render_text && i % 16 == 0)
-				{
-					if (world_snap_axis.mV[VX])
-					{
-						if (i == 0)
-						{
-							renderTickText(text_point, mObjectSelection->isAttachment() ? direction_forward_text : direction_east_text, LLColor4::white);
-						}
-						else if (i == 16)
-						{
-							if (constraint_axis.mV[VZ] > 0.f)
-							{
-								renderTickText(text_point, mObjectSelection->isAttachment() ? direction_left_text : direction_north_text, LLColor4::white);
-							}
-							else
-							{
-								renderTickText(text_point, mObjectSelection->isAttachment() ? direction_right_text : direction_south_text, LLColor4::white);
-							}
-						}
-						else if (i == 32)
-						{
-							renderTickText(text_point, mObjectSelection->isAttachment() ? direction_back_text : direction_west_text, LLColor4::white);
-						}
-						else
-						{
-							if (constraint_axis.mV[VZ] > 0.f)
-							{
-								renderTickText(text_point, mObjectSelection->isAttachment() ? direction_right_text : direction_south_text, LLColor4::white);
-							}
-							else
-							{
-								renderTickText(text_point, mObjectSelection->isAttachment() ? direction_left_text : direction_north_text, LLColor4::white);
-							}
-						}
-					}
-					else if (world_snap_axis.mV[VY])
-					{
-						if (i == 0)
-						{
-							renderTickText(text_point, mObjectSelection->isAttachment() ? direction_left_text : direction_north_text, LLColor4::white);
-						}
-						else if (i == 16)
-						{
-							if (constraint_axis.mV[VX] > 0.f)
-							{
-								renderTickText(text_point, direction_up_text, LLColor4::white);
-							}
-							else
-							{
-								renderTickText(text_point, direction_down_text, LLColor4::white);
-							}
-						}
-						else if (i == 32)
-						{
-							renderTickText(text_point, mObjectSelection->isAttachment() ? direction_right_text : direction_south_text, LLColor4::white);
-						}
-						else
-						{
-							if (constraint_axis.mV[VX] > 0.f)
-							{
-								renderTickText(text_point, direction_down_text, LLColor4::white);
-							}
-							else
-							{
-								renderTickText(text_point, direction_up_text, LLColor4::white);
-							}
-						}
-					}
-					else if (world_snap_axis.mV[VZ])
-					{
-						if (i == 0)
-						{
-							renderTickText(text_point, direction_up_text, LLColor4::white);
-						}
-						else if (i == 16)
-						{
-							if (constraint_axis.mV[VY] > 0.f)
-							{
-								renderTickText(text_point, mObjectSelection->isAttachment() ? direction_forward_text : direction_east_text, LLColor4::white);
-							}
-							else
-							{
-								renderTickText(text_point, mObjectSelection->isAttachment() ? direction_back_text : direction_west_text, LLColor4::white);
-							}
-						}
-						else if (i == 32)
-						{
-							renderTickText(text_point, direction_down_text, LLColor4::white);
-						}
-						else
-						{
-							if (constraint_axis.mV[VY] > 0.f)
-							{
-								renderTickText(text_point, mObjectSelection->isAttachment() ? direction_back_text : direction_west_text, LLColor4::white);
-							}
-							else
-							{
-								renderTickText(text_point, mObjectSelection->isAttachment() ? direction_forward_text : direction_east_text, LLColor4::white);
-							}
-						}
-					}
-				}
-				gGL.color4fv(line_color.mV);
-			}
-
-			// now render projected object axis
-			if (mInSnapRegime)
-			{
-				LLVector3 object_axis;
-				getObjectAxisClosestToMouse(object_axis);
-
-				// project onto constraint plane
-				LLSelectNode* first_node = mObjectSelection->getFirstMoveableNode(TRUE);
-				object_axis = object_axis * first_node->getObject()->getRenderRotation();
-				object_axis = object_axis - (object_axis * getConstraintAxis()) * getConstraintAxis();
-				object_axis.normVec();
-				object_axis = object_axis * SNAP_GUIDE_INNER_RADIUS * mRadiusMeters + center;
-				LLVector3 line_start = center;
-
-				gGL.begin(LLRender::LINES);
-				{
-					gGL.vertex3fv(line_start.mV);
-					gGL.vertex3fv(object_axis.mV);
-				}
-				gGL.end();
-
-				// draw snap guide arrow
-				gGL.begin(LLRender::TRIANGLES);
-				{
-					LLVector3 arrow_dir;
-					LLVector3 arrow_span = (object_axis - line_start) % getConstraintAxis();
-					arrow_span.normVec();
-
-					arrow_dir = mCamEdgeOn ? getConstraintAxis() : object_axis - line_start;
-					arrow_dir.normVec();
-					if (ring_num == 1)
-					{
-						arrow_dir *= -1.f;
-					}
-					gGL.vertex3fv((object_axis + arrow_dir * mRadiusMeters * 0.1f).mV);
-					gGL.vertex3fv((object_axis + arrow_span * mRadiusMeters * 0.1f).mV);
-					gGL.vertex3fv((object_axis - arrow_span * mRadiusMeters * 0.1f).mV);
-				}
-				gGL.end();
-
-				{
-					LLGLDepthTest gls_depth(GL_TRUE);
-					gGL.begin(LLRender::LINES);
-					{
-						gGL.vertex3fv(line_start.mV);
-						gGL.vertex3fv(object_axis.mV);
-					}
-					gGL.end();
-
-					// draw snap guide arrow
-					gGL.begin(LLRender::TRIANGLES);
-					{
-						LLVector3 arrow_dir;
-						LLVector3 arrow_span = (object_axis - line_start) % getConstraintAxis();
-						arrow_span.normVec();
-
-						arrow_dir = mCamEdgeOn ? getConstraintAxis() : object_axis - line_start;
-						arrow_dir.normVec();
-						if (ring_num == 1)
-						{
-							arrow_dir *= -1.f;
-						}
-
-						gGL.vertex3fv((object_axis + arrow_dir * mRadiusMeters * 0.1f).mV);
-						gGL.vertex3fv((object_axis + arrow_span * mRadiusMeters * 0.1f).mV);
-						gGL.vertex3fv((object_axis - arrow_span * mRadiusMeters * 0.1f).mV);
-					}
-					gGL.end();
-				}
-			}
-		}
-	}
-
-
-	// render help text
-	if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
-	{
-		if (mHelpTextTimer.getElapsedTimeF32() < sHelpTextVisibleTime + sHelpTextFadeTime && sNumTimesHelpTextShown < sMaxTimesShowHelpText)
-		{
-			LLVector3 selection_center_start = LLSelectMgr::getInstance()->getSavedBBoxOfSelection().getCenterAgent();
-
-			LLVector3 offset_dir = LLViewerCamera::getInstance()->getUpAxis();
-
-			F32 line_alpha = ALControlCache::GridOpacity;
-
-			LLVector3 help_text_pos = selection_center_start + (mRadiusMeters * 3.f * offset_dir);
-			const LLFontGL* big_fontp = LLFontGL::getFontSansSerif();
-
-			static const LLWString help_text = utf8str_to_wstring(LLTrans::getString("manip_hint1"));
-			LLColor4 help_text_color = LLColor4::white;
-			help_text_color.mV[VALPHA] = clamp_rescale(mHelpTextTimer.getElapsedTimeF32(), sHelpTextVisibleTime, sHelpTextVisibleTime + sHelpTextFadeTime, line_alpha, 0.f);
-			hud_render_text(help_text, help_text_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(help_text.c_str()), 3.f, help_text_color, false);
-			static const LLWString help_text2 = utf8str_to_wstring(LLTrans::getString("manip_hint2"));
-			help_text_pos -= offset_dir * mRadiusMeters * 0.4f;
-			hud_render_text(help_text2, help_text_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(help_text2.c_str()), 3.f, help_text_color, false);
-		}
-	}
-}
+    if (!ALControlCache::SnapEnabled)
+    {
+        return;
+    }
 
-// Returns TRUE if center of sphere is visible.  Also sets a bunch of member variables that are used later (e.g. mCenterToCam)
-BOOL LLManipRotate::updateVisiblity()
-{
-	// Don't want to recalculate the center of the selection during a drag.
-	// Due to packet delays, sometimes half the objects in the selection have their
-	// new position and half have their old one.  This creates subtle errors in the
-	// computed center position for that frame.  Unfortunately, these errors
-	// accumulate.  The result is objects seem to "fly apart" during rotations.
-	// JC - 03.26.2002
-	if (!hasMouseCapture())
-	{
-		mRotationCenter = gAgent.getPosGlobalFromAgent( getPivotPoint() );//LLSelectMgr::getInstance()->getSelectionCenterGlobal();
-	}
-
-	BOOL visible = FALSE;
-
-	//Assume that UI scale factor is equivalent for X and Y axis
-	F32 ui_scale_factor = LLUI::getScaleFactor().mV[VX];
-
-	LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		mCenterToCam = LLVector3(-1.f / gAgentCamera.mHUDCurZoom, 0.f, 0.f);
-		mCenterToCamNorm = mCenterToCam;
-		mCenterToCamMag = mCenterToCamNorm.normVec();
-
-		mRadiusMeters = RADIUS_PIXELS / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels();
-		mRadiusMeters /= gAgentCamera.mHUDCurZoom;
-		mRadiusMeters *= ui_scale_factor;
-
-		mCenterToProfilePlaneMag = mRadiusMeters * mRadiusMeters / mCenterToCamMag;
-		mCenterToProfilePlane = -mCenterToProfilePlaneMag * mCenterToCamNorm;
-
-		// x axis range is (-aspect * 0.5f, +aspect * 0.5)
-		// y axis range is (-0.5, 0.5)
-		// so use getWorldViewHeightRaw as scale factor when converting to pixel coordinates
-		mCenterScreen.set((S32)((0.5f - center.mV[VY]) / gAgentCamera.mHUDCurZoom * gViewerWindow->getWorldViewHeightScaled()),
-							(S32)((center.mV[VZ] + 0.5f) / gAgentCamera.mHUDCurZoom * gViewerWindow->getWorldViewHeightScaled()));
-		visible = TRUE;
-	}
-	else
-	{
-		visible = LLViewerCamera::getInstance()->projectPosAgentToScreen(center, mCenterScreen );
-		if( visible )
-		{
-			mCenterToCam = gAgentCamera.getCameraPositionAgent() - center;
-			mCenterToCamNorm = mCenterToCam;
-			mCenterToCamMag = mCenterToCamNorm.normVec();
-			LLVector3 cameraAtAxis = LLViewerCamera::getInstance()->getAtAxis();
-			cameraAtAxis.normVec();
-
-			F32 z_dist = -1.f * (mCenterToCam * cameraAtAxis);
-
-			// Don't drag manip if object too far away
-			if (ALControlCache::LimitSelectDistance)
-			{
-				F32 max_select_distance = ALControlCache::MaxSelectDistance;
-				if (dist_vec_squared(gAgent.getPositionAgent(), center) > (max_select_distance * max_select_distance))
-				{
-					visible = FALSE;
-				}
-			}
-			
-			if (mCenterToCamMag > 0.001f)
-			{
-				F32 fraction_of_fov = RADIUS_PIXELS / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels();
-				F32 apparent_angle = fraction_of_fov * LLViewerCamera::getInstance()->getView();  // radians
-				mRadiusMeters = z_dist * tan(apparent_angle);
-				mRadiusMeters *= ui_scale_factor;
-
-				mCenterToProfilePlaneMag = mRadiusMeters * mRadiusMeters / mCenterToCamMag;
-				mCenterToProfilePlane = -mCenterToProfilePlaneMag * mCenterToCamNorm;
-			}
-			else
-			{
-				visible = FALSE;
-			}
-		}
-	}
-
-	mCamEdgeOn = FALSE;
-	F32 axis_onto_cam = mManipPart >= LL_ROT_X ? llabs( getConstraintAxis() * mCenterToCamNorm ) : 0.f;
-	if( axis_onto_cam < AXIS_ONTO_CAM_TOLERANCE )
-	{
-		mCamEdgeOn = TRUE;
-	}
-
-	return visible;
-}
+    LLVector3 grid_origin;
+    LLVector3 grid_scale;
+    LLQuaternion grid_rotation;
 
-LLQuaternion LLManipRotate::dragUnconstrained( S32 x, S32 y )
-{
-	LLVector3 cam = gAgentCamera.getCameraPositionAgent();
-	LLVector3 center =  gAgent.getPosAgentFromGlobal( mRotationCenter );
-
-	mMouseCur = intersectMouseWithSphere( x, y, center, mRadiusMeters);
-
-	F32 delta_x = (F32)(mCenterScreen.mX - x);
-	F32 delta_y = (F32)(mCenterScreen.mY - y);
-
-	F32 dist_from_sphere_center = sqrt(delta_x * delta_x + delta_y * delta_y);
-
-	LLVector3 axis = mMouseDown % mMouseCur;
-	F32 angle = atan2(sqrtf(axis * axis), mMouseDown * mMouseCur);
-	axis.normVec();
-	LLQuaternion sphere_rot( angle, axis );
-	
-	if (is_approx_zero(1.f - mMouseDown * mMouseCur))
-	{
-		return LLQuaternion::DEFAULT;
-	}
-	else if (dist_from_sphere_center < RADIUS_PIXELS)
-	{
-		return sphere_rot;
-	}
-	else
-	{
-		LLVector3 intersection;
-		getMousePointOnPlaneAgent( intersection, x, y, center + mCenterToProfilePlane, mCenterToCamNorm );
-
-		// amount dragging in sphere from center to periphery would rotate object
-		F32 in_sphere_angle = F_PI_BY_TWO;
-		F32 dist_to_tangent_point = mRadiusMeters;
-		if( !is_approx_zero( mCenterToProfilePlaneMag ) )
-		{
-			dist_to_tangent_point = sqrt( mRadiusMeters * mRadiusMeters - mCenterToProfilePlaneMag * mCenterToProfilePlaneMag );
-			in_sphere_angle = atan2( dist_to_tangent_point, mCenterToProfilePlaneMag );
-		}
-
-		LLVector3 profile_center_to_intersection = intersection - (center + mCenterToProfilePlane);
-		F32 dist_to_intersection = profile_center_to_intersection.normVec();
-		F32 angle = (-1.f + dist_to_intersection / dist_to_tangent_point) * in_sphere_angle;
-
-		LLVector3 axis;
-		if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-		{
-			axis = LLVector3(-1.f, 0.f, 0.f) % profile_center_to_intersection;
-		}
-		else
-		{
-			axis = (cam - center) % profile_center_to_intersection;
-			axis.normVec();
-		}
-		return sphere_rot * LLQuaternion( angle, axis );
-	}
-}
+    LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale, true);
 
-LLVector3 LLManipRotate::getConstraintAxis()
-{
-	LLVector3 axis;
-	if( LL_ROT_ROLL == mManipPart )
-	{
-		axis = mCenterToCamNorm;
-	}
-	else
-	{
-		S32 axis_dir = mManipPart - LL_ROT_X;
-		if ((axis_dir >= LL_NO_PART) && (axis_dir < LL_Z_ARROW))
-		{
-			axis.mV[axis_dir] = 1.f;
-		}
-		else
-		{
-#ifndef LL_RELEASE_FOR_DOWNLOAD
-			LL_ERRS() << "Got bogus hit part in LLManipRotate::getConstraintAxis():" << mManipPart << LL_ENDL;
-#else
-			LL_WARNS() << "Got bogus hit part in LLManipRotate::getConstraintAxis():" << mManipPart << LL_ENDL;
-#endif
-			axis.mV[0] = 1.f;
-		}
+    LLVector3 constraint_axis = getConstraintAxis();
+
+    LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
+    LLVector3 cam_at_axis;
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        cam_at_axis.setVec(1.f, 0.f, 0.f);
+    }
+    else
+    {
+        cam_at_axis = center - gAgentCamera.getCameraPositionAgent();
+        cam_at_axis.normVec();
+    }
 
-		LLVector3 grid_origin;
-		LLVector3 grid_scale;
-		LLQuaternion grid_rotation;
+    LLVector3 world_snap_axis;
+    LLVector3 test_axis = constraint_axis;
 
-		LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
+    BOOL constrain_to_ref_object = FALSE;
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_ATTACHMENT && isAgentAvatarValid())
+    {
+        test_axis = test_axis * ~grid_rotation;
+    }
+    else if (LLSelectMgr::getInstance()->getGridMode() == GRID_MODE_REF_OBJECT)
+    {
+        test_axis = test_axis * ~grid_rotation;
+        constrain_to_ref_object = TRUE;
+    }
 
-		LLSelectNode* first_node = mObjectSelection->getFirstMoveableNode(TRUE);
-		if (first_node)
-		{
-			// *FIX: get agent local attachment grid working
-			// Put rotation into frame of first selected root object
-			axis = axis * grid_rotation;
-		}
-	}
+    test_axis.abs();
 
-	return axis;
-}
+    // find closest global/reference axis to local constraint axis;
+    if (test_axis.mV[VX] > test_axis.mV[VY] && test_axis.mV[VX] > test_axis.mV[VZ])
+    {
+        world_snap_axis = LLVector3::y_axis;
+    }
+    else if (test_axis.mV[VY] > test_axis.mV[VZ])
+    {
+        world_snap_axis = LLVector3::z_axis;
+    }
+    else
+    {
+        world_snap_axis = LLVector3::x_axis;
+    }
 
-LLQuaternion LLManipRotate::dragConstrained( S32 x, S32 y )
-{
-	LLSelectNode* first_object_node = mObjectSelection->getFirstMoveableNode(TRUE);
-	LLVector3 constraint_axis = getConstraintAxis();
-	LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
-
-	F32 angle = 0.f;
-
-	// build snap axes
-	LLVector3 grid_origin;
-	LLVector3 grid_scale;
-	LLQuaternion grid_rotation;
-
-	LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
-
-	LLVector3 axis1;
-	LLVector3 axis2;
-
-	LLVector3 test_axis = constraint_axis;
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_ATTACHMENT && isAgentAvatarValid())
-	{
-		test_axis = test_axis * ~grid_rotation;
-	}
-	else if (LLSelectMgr::getInstance()->getGridMode() == GRID_MODE_REF_OBJECT)
-	{
-		test_axis = test_axis * ~grid_rotation;
-	}
-	test_axis.abs();
-
-	// find closest global axis to constraint axis;
-	if (test_axis.mV[VX] > test_axis.mV[VY] && test_axis.mV[VX] > test_axis.mV[VZ])
-	{
-		axis1 = LLVector3::y_axis;
-	}
-	else if (test_axis.mV[VY] > test_axis.mV[VZ])
-	{
-		axis1 = LLVector3::z_axis;
-	}
-	else
-	{
-		axis1 = LLVector3::x_axis;
-	}
-
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_ATTACHMENT && isAgentAvatarValid())
-	{
-		axis1 = axis1 * grid_rotation;
-	}
-	else if (LLSelectMgr::getInstance()->getGridMode() == GRID_MODE_REF_OBJECT)
-	{
-		axis1 = axis1 * grid_rotation;
-	}
-
-	//project axis onto constraint plane
-	axis1 -= (axis1 * constraint_axis) * constraint_axis;
-	axis1.normVec();
-
-	// calculate third and final axis
-	axis2 = constraint_axis % axis1;
-
-	//F32 axis_onto_cam = llabs( constraint_axis * mCenterToCamNorm );
-	if( mCamEdgeOn )
-	{
-		// We're looking at the ring edge-on.
-		LLVector3 snap_plane_center = (center + (constraint_axis * mRadiusMeters * 0.5f));
-		LLVector3 cam_to_snap_plane;
-		if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-		{
-			cam_to_snap_plane.setVec(1.f, 0.f, 0.f);
-		}
-		else
-		{
-			cam_to_snap_plane = snap_plane_center - gAgentCamera.getCameraPositionAgent();
-			cam_to_snap_plane.normVec();
-		}
-
-		LLVector3 projected_mouse;
-		BOOL hit = getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, constraint_axis);
-		projected_mouse -= snap_plane_center;
-
-		if (ALControlCache::SnapEnabled) {
-			S32 snap_plane = 0;
-	
-			F32 dot = cam_to_snap_plane * constraint_axis;
-			if (llabs(dot) < 0.01f)
-			{
-				// looking at ring edge on, project onto view plane and check if mouse is past ring
-				getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, cam_to_snap_plane);
-				projected_mouse -= snap_plane_center;
-				dot = projected_mouse * constraint_axis;
-				if (projected_mouse * constraint_axis > 0)
-				{
-					snap_plane = 1;
-				}
-				projected_mouse -= dot * constraint_axis;
-			}
-			else if (dot > 0.f)
-			{
-				// look for mouse position outside and in front of snap circle
-				if (hit && projected_mouse.magVec() > SNAP_GUIDE_INNER_RADIUS * mRadiusMeters && projected_mouse * cam_to_snap_plane < 0.f)
-				{
-					snap_plane = 1;
-				}
-			}
-			else
-			{
-				// look for mouse position inside or in back of snap circle
-				if (projected_mouse.magVec() < SNAP_GUIDE_INNER_RADIUS * mRadiusMeters || projected_mouse * cam_to_snap_plane > 0.f || !hit)
-				{
-					snap_plane = 1;
-				}
-			}
-	
-			if (snap_plane == 0)
-			{
-				// try other plane
-				snap_plane_center = (center - (constraint_axis * mRadiusMeters * 0.5f));
-				if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-				{
-					cam_to_snap_plane.setVec(1.f, 0.f, 0.f);
-				}
-				else
-				{
-					cam_to_snap_plane = snap_plane_center - gAgentCamera.getCameraPositionAgent();
-					cam_to_snap_plane.normVec();
-				}
-	
-				hit = getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, constraint_axis);
-				projected_mouse -= snap_plane_center;
-	
-				dot = cam_to_snap_plane * constraint_axis;
-				if (llabs(dot) < 0.01f)
-				{
-					// looking at ring edge on, project onto view plane and check if mouse is past ring
-					getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, cam_to_snap_plane);
-					projected_mouse -= snap_plane_center;
-					dot = projected_mouse * constraint_axis;
-					if (projected_mouse * constraint_axis < 0)
-					{
-						snap_plane = 2;
-					}
-					projected_mouse -= dot * constraint_axis;
-				}
-				else if (dot < 0.f)
-				{
-					// look for mouse position outside and in front of snap circle
-					if (hit && projected_mouse.magVec() > SNAP_GUIDE_INNER_RADIUS * mRadiusMeters && projected_mouse * cam_to_snap_plane < 0.f)
-					{
-						snap_plane = 2;
-					}
-				}
-				else
-				{
-					// look for mouse position inside or in back of snap circle
-					if (projected_mouse.magVec() < SNAP_GUIDE_INNER_RADIUS * mRadiusMeters || projected_mouse * cam_to_snap_plane > 0.f || !hit)
-					{
-						snap_plane = 2;
-					}
-				}
-			}
-			
-			if (snap_plane > 0)
-			{
-				LLVector3 cam_at_axis;
-				if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-				{
-					cam_at_axis.setVec(1.f, 0.f, 0.f);
-				}
-				else
-				{
-					cam_at_axis = snap_plane_center - gAgentCamera.getCameraPositionAgent();
-					cam_at_axis.normVec();
-				}
-	
-				// first, project mouse onto screen plane at point tangent to rotation radius. 
-				getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, cam_at_axis);
-				// project that point onto rotation plane
-				projected_mouse -= snap_plane_center;
-				projected_mouse -= projected_vec(projected_mouse, constraint_axis);
-	
-				F32 mouse_lateral_dist = llmin(SNAP_GUIDE_INNER_RADIUS * mRadiusMeters, projected_mouse.magVec());
-				F32 mouse_depth = SNAP_GUIDE_INNER_RADIUS * mRadiusMeters;
-				if (llabs(mouse_lateral_dist) > 0.01f)
-				{
-					mouse_depth = sqrtf((SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) * (SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) - 
-										(mouse_lateral_dist * mouse_lateral_dist));
-				}
-				LLVector3 projected_camera_at = cam_at_axis - projected_vec(cam_at_axis, constraint_axis);
-				projected_mouse -= mouse_depth * projected_camera_at;
-	
-				if (!mInSnapRegime)
-				{
-					mSmoothRotate = TRUE;
-				}
-				mInSnapRegime = TRUE;
-				// 0 to 360 deg
-				F32 mouse_angle = fmodf(atan2(projected_mouse * axis1, projected_mouse * axis2) * RAD_TO_DEG + 360.f, 360.f);
-				
-				F32 relative_mouse_angle = fmodf(mouse_angle + (SNAP_ANGLE_DETENTE / 2), SNAP_ANGLE_INCREMENT);
-	
-				LLVector3 object_axis;
-				getObjectAxisClosestToMouse(object_axis);
-                if (first_object_node)
-                {
-                    object_axis = object_axis * first_object_node->mSavedRotation;
-                }
-	
-				// project onto constraint plane
-				object_axis = object_axis - (object_axis * getConstraintAxis()) * getConstraintAxis();
-				object_axis.normVec();
-	
-				if (relative_mouse_angle < SNAP_ANGLE_DETENTE)
-				{
-					F32 quantized_mouse_angle = mouse_angle - (relative_mouse_angle - (SNAP_ANGLE_DETENTE * 0.5f));
-					angle = (quantized_mouse_angle * DEG_TO_RAD) - atan2(object_axis * axis1, object_axis * axis2);
-				}
-				else
-				{
-					angle = (mouse_angle * DEG_TO_RAD) - atan2(object_axis * axis1, object_axis * axis2);
-				}
-				return LLQuaternion( -angle, constraint_axis );
-			}
-			else
-			{
-				if (mInSnapRegime)
-				{
-					mSmoothRotate = TRUE;
-				}
-				mInSnapRegime = FALSE;
-			}
-		}
-		else {
-			if (mInSnapRegime)
-			{
-				mSmoothRotate = TRUE;
-			}
-			mInSnapRegime = FALSE;
-		}
-		
-		if (!mInSnapRegime)
-		{
-			LLVector3 up_from_axis = mCenterToCamNorm % constraint_axis;
-			up_from_axis.normVec();
-			LLVector3 cur_intersection;
-			getMousePointOnPlaneAgent(cur_intersection, x, y, center, mCenterToCam);
-			cur_intersection -= center;
-			mMouseCur = projected_vec(cur_intersection, up_from_axis);
-			F32 mouse_depth = SNAP_GUIDE_INNER_RADIUS * mRadiusMeters;
-			F32 mouse_dist_sqrd = mMouseCur.magVecSquared();
-			if (mouse_dist_sqrd > 0.0001f)
-			{
-				mouse_depth = sqrtf((SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) * (SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) - 
-									mouse_dist_sqrd);
-			}
-			LLVector3 projected_center_to_cam = mCenterToCamNorm - projected_vec(mCenterToCamNorm, constraint_axis);
-			mMouseCur += mouse_depth * projected_center_to_cam;
-
-			F32 dist = (cur_intersection * up_from_axis) - (mMouseDown * up_from_axis);
-			angle = dist / (SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) * -F_PI_BY_TWO;
-		}
-	}
-	else
-	{
-		LLVector3 projected_mouse;
-		getMousePointOnPlaneAgent(projected_mouse, x, y, center, constraint_axis);
-		projected_mouse -= center;
-		mMouseCur = projected_mouse;
-		mMouseCur.normVec();
-
-		if (!first_object_node)
-		{
-			return LLQuaternion::DEFAULT;
-		}
-
-		if (ALControlCache::SnapEnabled && projected_mouse.magVec() > SNAP_GUIDE_INNER_RADIUS * mRadiusMeters)
-		{
-			if (!mInSnapRegime)
-			{
-				mSmoothRotate = TRUE;
-			}
-			mInSnapRegime = TRUE;
-			// 0 to 360 deg
-			F32 mouse_angle = fmodf(atan2(projected_mouse * axis1, projected_mouse * axis2) * RAD_TO_DEG + 360.f, 360.f);
-			
-			F32 relative_mouse_angle = fmodf(mouse_angle + (SNAP_ANGLE_DETENTE / 2), SNAP_ANGLE_INCREMENT);
-
-			LLVector3 object_axis;
-			getObjectAxisClosestToMouse(object_axis);
-			object_axis = object_axis * first_object_node->mSavedRotation;
-
-			// project onto constraint plane
-			object_axis = object_axis - (object_axis * getConstraintAxis()) * getConstraintAxis();
-			object_axis.normVec();
-
-			if (relative_mouse_angle < SNAP_ANGLE_DETENTE)
-			{
-				F32 quantized_mouse_angle = mouse_angle - (relative_mouse_angle - (SNAP_ANGLE_DETENTE * 0.5f));
-				angle = (quantized_mouse_angle * DEG_TO_RAD) - atan2(object_axis * axis1, object_axis * axis2);
-			}
-			else
-			{
-				angle = (mouse_angle * DEG_TO_RAD) - atan2(object_axis * axis1, object_axis * axis2);
-			}
-			return LLQuaternion( -angle, constraint_axis );
-		}
-		else
-		{
-			if (mInSnapRegime)
-			{
-				mSmoothRotate = TRUE;
-			}
-			mInSnapRegime = FALSE;
-		}
-
-		LLVector3 cross_product = mMouseDown % mMouseCur;
-		angle = atan2(sqrtf(cross_product * cross_product), mMouseCur * mMouseDown);
-		F32 dir = cross_product * constraint_axis;  // cross product
-		if( dir < 0.f )
-		{
-			angle *= -1.f;
-		}
-	}
-
-	F32 rot_step = gSavedSettings.getF32("RotationStep");
-	F32 step_size = DEG_TO_RAD * rot_step;
-	angle -= fmod(angle, step_size);
-		
-	return LLQuaternion( angle, constraint_axis );
-}
+    LLVector3 projected_snap_axis = world_snap_axis;
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_ATTACHMENT && isAgentAvatarValid())
+    {
+        projected_snap_axis = projected_snap_axis * grid_rotation;
+    }
+    else if (constrain_to_ref_object)
+    {
+        projected_snap_axis = projected_snap_axis * grid_rotation;
+    }
 
+    // project world snap axis onto constraint plane
+    projected_snap_axis -= projected_vec(projected_snap_axis, constraint_axis);
+    projected_snap_axis.normVec();
 
+    static const LLWString direction_up_text = utf8string_to_wstring(LLTrans::getString("Direction_Up"));
+    static const LLWString direction_down_text = utf8string_to_wstring(LLTrans::getString("Direction_Down"));
 
-LLVector3 LLManipRotate::intersectMouseWithSphere( S32 x, S32 y, const LLVector3& sphere_center, F32 sphere_radius)
-{
-	LLVector3 ray_pt;
-	LLVector3 ray_dir;
-	mouseToRay( x, y, &ray_pt, &ray_dir);
-	return intersectRayWithSphere( ray_pt, ray_dir, sphere_center, sphere_radius );
-}
+    static const LLWString direction_forward_text = utf8string_to_wstring(LLTrans::getString("Direction_Forward"));
+    static const LLWString direction_back_text = utf8string_to_wstring(LLTrans::getString("Direction_Back"));
+    static const LLWString direction_right_text = utf8string_to_wstring(LLTrans::getString("Direction_Right"));
+    static const LLWString direction_left_text = utf8string_to_wstring(LLTrans::getString("Direction_Left"));
 
-LLVector3 LLManipRotate::intersectRayWithSphere( const LLVector3& ray_pt, const LLVector3& ray_dir, const LLVector3& sphere_center, F32 sphere_radius)
-{
-	LLVector3 ray_pt_to_center = sphere_center - ray_pt;
-	F32 center_distance = ray_pt_to_center.normVec();
-
-	F32 dot = ray_dir * ray_pt_to_center;
-
-	if (dot == 0.f)
-	{
-		return LLVector3::zero;
-	}
-
-	// point which ray hits plane centered on sphere origin, facing ray origin
-	LLVector3 intersection_sphere_plane = ray_pt + (ray_dir * center_distance / dot); 
-	// vector from sphere origin to the point, normalized to sphere radius
-	LLVector3 sphere_center_to_intersection = (intersection_sphere_plane - sphere_center) / sphere_radius;
-
-	F32 dist_squared = sphere_center_to_intersection.magVecSquared();
-	LLVector3 result;
-
-	if (dist_squared > 1.f)
-	{
-		result = sphere_center_to_intersection;
-		result.normVec();
-	}
-	else
-	{
-		result = sphere_center_to_intersection - ray_dir * sqrt(1.f - dist_squared);
-	}
-
-	return result;
-}
+    static const LLWString direction_north_text = utf8string_to_wstring(LLTrans::getString("Direction_North"));
+    static const LLWString direction_south_text = utf8string_to_wstring(LLTrans::getString("Direction_South"));
+    static const LLWString direction_east_text = utf8string_to_wstring(LLTrans::getString("Direction_East"));
+    static const LLWString direction_west_text = utf8string_to_wstring(LLTrans::getString("Direction_West"));
 
-// Utility function.  Should probably be moved to another class.
-// x,y - mouse position in scaled window coordinates (NOT GL viewport coordinates)
-//static
-void LLManipRotate::mouseToRay( S32 x, S32 y, LLVector3* ray_pt, LLVector3* ray_dir )
-{
-	if (LLSelectMgr::getInstance()->getSelection()->getSelectType() == SELECT_TYPE_HUD)
-	{
-		F32 mouse_x = (((F32)x / gViewerWindow->getWorldViewRectScaled().getWidth()) - 0.5f) / gAgentCamera.mHUDCurZoom;
-		F32 mouse_y = ((((F32)y) / gViewerWindow->getWorldViewRectScaled().getHeight()) - 0.5f) / gAgentCamera.mHUDCurZoom;
-
-		*ray_pt = LLVector3(-1.f, -mouse_x, mouse_y);
-		*ray_dir = LLVector3(1.f, 0.f, 0.f);
-	}
-	else
-	{
-    	*ray_pt = gAgentCamera.getCameraPositionAgent();
-        *ray_dir = gViewerWindow->mouseDirectionGlobal(x, y);
-	}
-}
+    S32 num_rings = mCamEdgeOn ? 2 : 1;
+    for (S32 ring_num = 0; ring_num < num_rings; ring_num++)
+    {
+        LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
 
-void LLManipRotate::highlightManipulators( S32 x, S32 y )
-{
-	mHighlightedPart = LL_NO_PART;
-
-	//LLBBox bbox = LLSelectMgr::getInstance()->getBBoxOfSelection();
-	LLViewerObject *first_object = mObjectSelection->getFirstMoveableObject(TRUE);
-	
-	if (!first_object)
-	{
-		return;
-	}
-	
-	LLVector3 rotation_center = gAgent.getPosAgentFromGlobal(mRotationCenter);
-	LLVector3 mouse_dir_x;
-	LLVector3 mouse_dir_y;
-	LLVector3 mouse_dir_z;
-	LLVector3 intersection_roll;
-
-	LLVector3 grid_origin;
-	LLVector3 grid_scale;
-	LLQuaternion grid_rotation;
-
-	LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
-
-	LLVector3 rot_x_axis = LLVector3::x_axis * grid_rotation;
-	LLVector3 rot_y_axis = LLVector3::y_axis * grid_rotation;
-	LLVector3 rot_z_axis = LLVector3::z_axis * grid_rotation;
-
-	F32 proj_rot_x_axis = llabs(rot_x_axis * mCenterToCamNorm);
-	F32 proj_rot_y_axis = llabs(rot_y_axis * mCenterToCamNorm);
-	F32 proj_rot_z_axis = llabs(rot_z_axis * mCenterToCamNorm);
-
-	F32 min_select_distance = 0.f;
-	F32 cur_select_distance = 0.f;
-
-	// test x
-	getMousePointOnPlaneAgent(mouse_dir_x, x, y, rotation_center, rot_x_axis);
-	mouse_dir_x -= rotation_center;
-	// push intersection point out when working at obtuse angle to make ring easier to hit
-	mouse_dir_x *= 1.f + (1.f - llabs(rot_x_axis * mCenterToCamNorm)) * 0.1f;
-
-	// test y
-	getMousePointOnPlaneAgent(mouse_dir_y, x, y, rotation_center, rot_y_axis);
-	mouse_dir_y -= rotation_center;
-	mouse_dir_y *= 1.f + (1.f - llabs(rot_y_axis * mCenterToCamNorm)) * 0.1f;
-
-	// test z
-	getMousePointOnPlaneAgent(mouse_dir_z, x, y, rotation_center, rot_z_axis);
-	mouse_dir_z -= rotation_center;
-	mouse_dir_z *= 1.f + (1.f - llabs(rot_z_axis * mCenterToCamNorm)) * 0.1f;
-
-	// test roll
-	getMousePointOnPlaneAgent(intersection_roll, x, y, rotation_center, mCenterToCamNorm);
-	intersection_roll -= rotation_center;
-
-	F32 dist_x = mouse_dir_x.normVec();
-	F32 dist_y = mouse_dir_y.normVec();
-	F32 dist_z = mouse_dir_z.normVec();
-
-	F32 distance_threshold = (MAX_MANIP_SELECT_DISTANCE * mRadiusMeters) / gViewerWindow->getWorldViewHeightScaled();
-
-	if (llabs(dist_x - mRadiusMeters) * llmax(0.05f, proj_rot_x_axis) < distance_threshold)
-	{
-		// selected x
-		cur_select_distance = dist_x * mouse_dir_x * mCenterToCamNorm;
-		if (cur_select_distance >= -0.05f && (min_select_distance == 0.f || cur_select_distance > min_select_distance))
-		{
-			min_select_distance = cur_select_distance;
-			mHighlightedPart = LL_ROT_X;
-		}
-	}
-	if (llabs(dist_y - mRadiusMeters) * llmax(0.05f, proj_rot_y_axis) < distance_threshold)
-	{
-		// selected y
-		cur_select_distance = dist_y * mouse_dir_y * mCenterToCamNorm;
-		if (cur_select_distance >= -0.05f && (min_select_distance == 0.f || cur_select_distance > min_select_distance))
-		{
-			min_select_distance = cur_select_distance;
-			mHighlightedPart = LL_ROT_Y;
-		}
-	}
-	if (llabs(dist_z - mRadiusMeters) * llmax(0.05f, proj_rot_z_axis) < distance_threshold)
-	{
-		// selected z
-		cur_select_distance = dist_z * mouse_dir_z * mCenterToCamNorm;
-		if (cur_select_distance >= -0.05f && (min_select_distance == 0.f || cur_select_distance > min_select_distance))
-		{
-			min_select_distance = cur_select_distance;
-			mHighlightedPart = LL_ROT_Z;
-		}
-	}
-
-	// test for edge-on intersections
-	if (proj_rot_x_axis < 0.05f)
-	{
-		if ((proj_rot_y_axis > 0.05f && (dist_y * llabs(mouse_dir_y * rot_x_axis) < distance_threshold) && dist_y < mRadiusMeters) ||
-			(proj_rot_z_axis > 0.05f && (dist_z * llabs(mouse_dir_z * rot_x_axis) < distance_threshold) && dist_z < mRadiusMeters))
-		{
-			mHighlightedPart = LL_ROT_X;
-		}
-	}
-
-	if (proj_rot_y_axis < 0.05f)
-	{
-		if ((proj_rot_x_axis > 0.05f && (dist_x * llabs(mouse_dir_x * rot_y_axis) < distance_threshold) && dist_x < mRadiusMeters) ||
-			(proj_rot_z_axis > 0.05f && (dist_z * llabs(mouse_dir_z * rot_y_axis) < distance_threshold) && dist_z < mRadiusMeters))
-		{
-			mHighlightedPart = LL_ROT_Y;
-		}
-	}
-
-	if (proj_rot_z_axis < 0.05f)
-	{
-		if ((proj_rot_x_axis > 0.05f && (dist_x * llabs(mouse_dir_x * rot_z_axis) < distance_threshold) && dist_x < mRadiusMeters) ||
-			(proj_rot_y_axis > 0.05f && (dist_y * llabs(mouse_dir_y * rot_z_axis) < distance_threshold) && dist_y < mRadiusMeters))
-		{
-			mHighlightedPart = LL_ROT_Z;
-		}
-	}
-
-	// test for roll
-	if (mHighlightedPart == LL_NO_PART)
-	{
-		F32 roll_distance = intersection_roll.magVec();
-		F32 width_meters = WIDTH_PIXELS * mRadiusMeters / RADIUS_PIXELS;
-
-		// use larger distance threshold for roll as it is checked only if something else wasn't highlighted
-		if (llabs(roll_distance - (mRadiusMeters + (width_meters * 2.f))) < distance_threshold * 2.f)
-		{
-			mHighlightedPart = LL_ROT_ROLL;
-		}
-		else if (roll_distance < mRadiusMeters)
-		{
-			mHighlightedPart = LL_ROT_GENERAL;
-		}
-	}
-}
+        if (mCamEdgeOn)
+        {
+            // draw two opposing rings
+            if (ring_num == 0)
+            {
+                center += constraint_axis * mRadiusMeters * 0.5f;
+            }
+            else
+            {
+                center -= constraint_axis * mRadiusMeters * 0.5f;
+            }
+        }
 
-S32 LLManipRotate::getObjectAxisClosestToMouse(LLVector3& object_axis)
-{
-	LLSelectNode* first_object_node = mObjectSelection->getFirstMoveableNode(TRUE);
-
-	if (!first_object_node)
-	{
-		object_axis.clearVec();
-		return -1;
-	}
-
-	LLQuaternion obj_rotation = first_object_node->mSavedRotation;
-	LLVector3 mouse_down_object = mMouseDown * ~obj_rotation;
-	LLVector3 mouse_down_abs = mouse_down_object;
-	mouse_down_abs.abs();
-
-	S32 axis_index = 0;
-	if (mouse_down_abs.mV[VX] > mouse_down_abs.mV[VY] && mouse_down_abs.mV[VX] > mouse_down_abs.mV[VZ])
-	{
-		if (mouse_down_object.mV[VX] > 0.f)
-		{
-			object_axis = LLVector3::x_axis;
-		}
-		else
-		{
-			object_axis = LLVector3::x_axis_neg;
-		}
-		axis_index = VX;
-	}
-	else if (mouse_down_abs.mV[VY] > mouse_down_abs.mV[VZ])
-	{
-		if (mouse_down_object.mV[VY] > 0.f)
-		{
-			object_axis = LLVector3::y_axis;
-		}
-		else
-		{
-			object_axis = LLVector3::y_axis_neg;
-		}
-		axis_index = VY;
-	}
-	else
-	{
-		if (mouse_down_object.mV[VZ] > 0.f)
-		{
-			object_axis = LLVector3::z_axis;
-		}
-		else
-		{
-			object_axis = LLVector3::z_axis_neg;
-		}
-		axis_index = VZ;
-	}
-
-	return axis_index;
-}
+        LLGLDepthTest gls_depth(GL_FALSE);
+        for (S32 pass = 0; pass < 3; pass++)
+        {
+            // render snap guide ring
+            gGL.pushMatrix();
 
-//virtual
-BOOL LLManipRotate::canAffectSelection()
-{
-	BOOL can_rotate = mObjectSelection->getObjectCount() != 0;
-	if (can_rotate)
-	{
-		struct f : public LLSelectedObjectFunctor
-		{
-			virtual bool apply(LLViewerObject* objectp)
-			{
-				LLViewerObject *root_object = (objectp == NULL) ? NULL : objectp->getRootEdit();
-				return objectp->permMove() && !objectp->isPermanentEnforced() &&
-					((root_object == NULL) || !root_object->isPermanentEnforced()) &&
-					(objectp->permModify() || !ALControlCache::EditLinkedParts);
-			}
-		} func;
-		can_rotate = mObjectSelection->applyToObjects(&func);
-	}
-	return can_rotate;
+            LLQuaternion snap_guide_rot;
+            F32 angle_radians, x, y, z;
+            snap_guide_rot.shortestArc(LLVector3::z_axis, getConstraintAxis());
+            snap_guide_rot.getAngleAxis(&angle_radians, &x, &y, &z);
+            gGL.translatef(center.mV[VX], center.mV[VY], center.mV[VZ]);
+            gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
+
+            LLColor4 line_color = setupSnapGuideRenderPass(pass);
+
+            gGL.color4fv(line_color.mV);
+
+            if (mCamEdgeOn)
+            {
+                // render an arc
+                LLVector3 edge_normal = cam_at_axis % constraint_axis;
+                edge_normal.normVec();
+                LLVector3 x_axis_snap = LLVector3::x_axis * snap_guide_rot;
+                LLVector3 y_axis_snap = LLVector3::y_axis * snap_guide_rot;
+
+                F32 end_angle = atan2(y_axis_snap * edge_normal, x_axis_snap * edge_normal);
+                //F32 start_angle = angle_between((-1.f * LLVector3::x_axis) * snap_guide_rot, edge_normal);
+                F32 start_angle = end_angle - F_PI;
+                gl_arc_2d(0.f, 0.f, mRadiusMeters * SNAP_GUIDE_INNER_RADIUS, CIRCLE_STEPS, FALSE, start_angle, end_angle);
+            }
+            else
+            {
+                gl_circle_2d(0.f, 0.f, mRadiusMeters * SNAP_GUIDE_INNER_RADIUS, CIRCLE_STEPS, FALSE);
+            }
+            gGL.popMatrix();
+
+            for (S32 i = 0; i < 64; i++)
+            {
+                BOOL render_text = TRUE;
+                F32 deg = 5.625f * (F32)i;
+                LLVector3 inner_point;
+                LLVector3 outer_point;
+                LLVector3 text_point;
+                LLQuaternion rot(deg * DEG_TO_RAD, constraint_axis);
+                gGL.begin(LLRender::LINES);
+                {
+                    inner_point = (projected_snap_axis * mRadiusMeters * SNAP_GUIDE_INNER_RADIUS * rot) + center;
+                    F32 tick_length = 0.f;
+                    if (i % 16 == 0)
+                    {
+                        tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_1 - SNAP_GUIDE_INNER_RADIUS);
+                    }
+                    else if (i % 8 == 0)
+                    {
+                        tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_2 - SNAP_GUIDE_INNER_RADIUS);
+                    }
+                    else if (i % 4 == 0)
+                    {
+                        tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_3 - SNAP_GUIDE_INNER_RADIUS);
+                    }
+                    else if (i % 2 == 0)
+                    {
+                        tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_4 - SNAP_GUIDE_INNER_RADIUS);
+                    }
+                    else
+                    {
+                        tick_length = mRadiusMeters * (SNAP_GUIDE_RADIUS_5 - SNAP_GUIDE_INNER_RADIUS);
+                    }
+
+                    if (mCamEdgeOn)
+                    {
+                        // don't draw ticks that are on back side of circle
+                        F32 dot = cam_at_axis * (projected_snap_axis * rot);
+                        if (dot > 0.f)
+                        {
+                            outer_point = inner_point;
+                            render_text = FALSE;
+                        }
+                        else
+                        {
+                            if (ring_num == 0)
+                            {
+                                outer_point = inner_point + (constraint_axis * tick_length) * rot;
+                            }
+                            else
+                            {
+                                outer_point = inner_point - (constraint_axis * tick_length) * rot;
+                            }
+                        }
+                    }
+                    else
+                    {
+                        outer_point = inner_point + (projected_snap_axis * tick_length) * rot;
+                    }
+
+                    text_point = outer_point + (projected_snap_axis * mRadiusMeters * 0.1f) * rot;
+
+                    gGL.vertex3fv(inner_point.mV);
+                    gGL.vertex3fv(outer_point.mV);
+                }
+                gGL.end();
+
+                //RN: text rendering does own shadow pass, so only render once
+                if (pass == 1 && render_text && i % 16 == 0)
+                {
+                    if (world_snap_axis.mV[VX])
+                    {
+                        if (i == 0)
+                        {
+                            renderTickText(text_point, mObjectSelection->isAttachment() ? direction_forward_text : direction_east_text, LLColor4::white);
+                        }
+                        else if (i == 16)
+                        {
+                            if (constraint_axis.mV[VZ] > 0.f)
+                            {
+                                renderTickText(text_point, mObjectSelection->isAttachment() ? direction_left_text : direction_north_text, LLColor4::white);
+                            }
+                            else
+                            {
+                                renderTickText(text_point, mObjectSelection->isAttachment() ? direction_right_text : direction_south_text, LLColor4::white);
+                            }
+                        }
+                        else if (i == 32)
+                        {
+                            renderTickText(text_point, mObjectSelection->isAttachment() ? direction_back_text : direction_west_text, LLColor4::white);
+                        }
+                        else
+                        {
+                            if (constraint_axis.mV[VZ] > 0.f)
+                            {
+                                renderTickText(text_point, mObjectSelection->isAttachment() ? direction_right_text : direction_south_text, LLColor4::white);
+                            }
+                            else
+                            {
+                                renderTickText(text_point, mObjectSelection->isAttachment() ? direction_left_text : direction_north_text, LLColor4::white);
+                            }
+                        }
+                    }
+                    else if (world_snap_axis.mV[VY])
+                    {
+                        if (i == 0)
+                        {
+                            renderTickText(text_point, mObjectSelection->isAttachment() ? direction_left_text : direction_north_text, LLColor4::white);
+                        }
+                        else if (i == 16)
+                        {
+                            if (constraint_axis.mV[VX] > 0.f)
+                            {
+                                renderTickText(text_point, direction_up_text, LLColor4::white);
+                            }
+                            else
+                            {
+                                renderTickText(text_point, direction_down_text, LLColor4::white);
+                            }
+                        }
+                        else if (i == 32)
+                        {
+                            renderTickText(text_point, mObjectSelection->isAttachment() ? direction_right_text : direction_south_text, LLColor4::white);
+                        }
+                        else
+                        {
+                            if (constraint_axis.mV[VX] > 0.f)
+                            {
+                                renderTickText(text_point, direction_down_text, LLColor4::white);
+                            }
+                            else
+                            {
+                                renderTickText(text_point, direction_up_text, LLColor4::white);
+                            }
+                        }
+                    }
+                    else if (world_snap_axis.mV[VZ])
+                    {
+                        if (i == 0)
+                        {
+                            renderTickText(text_point, direction_up_text, LLColor4::white);
+                        }
+                        else if (i == 16)
+                        {
+                            if (constraint_axis.mV[VY] > 0.f)
+                            {
+                                renderTickText(text_point, mObjectSelection->isAttachment() ? direction_forward_text : direction_east_text, LLColor4::white);
+                            }
+                            else
+                            {
+                                renderTickText(text_point, mObjectSelection->isAttachment() ? direction_back_text : direction_west_text, LLColor4::white);
+                            }
+                        }
+                        else if (i == 32)
+                        {
+                            renderTickText(text_point, direction_down_text, LLColor4::white);
+                        }
+                        else
+                        {
+                            if (constraint_axis.mV[VY] > 0.f)
+                            {
+                                renderTickText(text_point, mObjectSelection->isAttachment() ? direction_back_text : direction_west_text, LLColor4::white);
+                            }
+                            else
+                            {
+                                renderTickText(text_point, mObjectSelection->isAttachment() ? direction_forward_text : direction_east_text, LLColor4::white);
+                            }
+                        }
+                    }
+                }
+                gGL.color4fv(line_color.mV);
+            }
+
+            // now render projected object axis
+            if (mInSnapRegime)
+            {
+                LLVector3 object_axis;
+                getObjectAxisClosestToMouse(object_axis);
+
+                // project onto constraint plane
+                LLSelectNode* first_node = mObjectSelection->getFirstMoveableNode(TRUE);
+                object_axis = object_axis * first_node->getObject()->getRenderRotation();
+                object_axis = object_axis - (object_axis * getConstraintAxis()) * getConstraintAxis();
+                object_axis.normVec();
+                object_axis = object_axis * SNAP_GUIDE_INNER_RADIUS * mRadiusMeters + center;
+                LLVector3 line_start = center;
+
+                gGL.begin(LLRender::LINES);
+                {
+                    gGL.vertex3fv(line_start.mV);
+                    gGL.vertex3fv(object_axis.mV);
+                }
+                gGL.end();
+
+                // draw snap guide arrow
+                gGL.begin(LLRender::TRIANGLES);
+                {
+                    LLVector3 arrow_dir;
+                    LLVector3 arrow_span = (object_axis - line_start) % getConstraintAxis();
+                    arrow_span.normVec();
+
+                    arrow_dir = mCamEdgeOn ? getConstraintAxis() : object_axis - line_start;
+                    arrow_dir.normVec();
+                    if (ring_num == 1)
+                    {
+                        arrow_dir *= -1.f;
+                    }
+                    gGL.vertex3fv((object_axis + arrow_dir * mRadiusMeters * 0.1f).mV);
+                    gGL.vertex3fv((object_axis + arrow_span * mRadiusMeters * 0.1f).mV);
+                    gGL.vertex3fv((object_axis - arrow_span * mRadiusMeters * 0.1f).mV);
+                }
+                gGL.end();
+
+                {
+                    LLGLDepthTest gls_depth(GL_TRUE);
+                    gGL.begin(LLRender::LINES);
+                    {
+                        gGL.vertex3fv(line_start.mV);
+                        gGL.vertex3fv(object_axis.mV);
+                    }
+                    gGL.end();
+
+                    // draw snap guide arrow
+                    gGL.begin(LLRender::TRIANGLES);
+                    {
+                        LLVector3 arrow_dir;
+                        LLVector3 arrow_span = (object_axis - line_start) % getConstraintAxis();
+                        arrow_span.normVec();
+
+                        arrow_dir = mCamEdgeOn ? getConstraintAxis() : object_axis - line_start;
+                        arrow_dir.normVec();
+                        if (ring_num == 1)
+                        {
+                            arrow_dir *= -1.f;
+                        }
+
+                        gGL.vertex3fv((object_axis + arrow_dir * mRadiusMeters * 0.1f).mV);
+                        gGL.vertex3fv((object_axis + arrow_span * mRadiusMeters * 0.1f).mV);
+                        gGL.vertex3fv((object_axis - arrow_span * mRadiusMeters * 0.1f).mV);
+                    }
+                    gGL.end();
+                }
+            }
+        }
+    }
+
+
+    // render help text
+    if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
+    {
+        if (mHelpTextTimer.getElapsedTimeF32() < sHelpTextVisibleTime + sHelpTextFadeTime && sNumTimesHelpTextShown < sMaxTimesShowHelpText)
+        {
+            LLVector3 selection_center_start = LLSelectMgr::getInstance()->getSavedBBoxOfSelection().getCenterAgent();
+
+            LLVector3 offset_dir = LLViewerCamera::getInstance()->getUpAxis();
+
+            F32 line_alpha = ALControlCache::GridOpacity;
+
+            LLVector3 help_text_pos = selection_center_start + (mRadiusMeters * 3.f * offset_dir);
+            const LLFontGL* big_fontp = LLFontGL::getFontSansSerif();
+
+            static const LLWString help_text = utf8str_to_wstring(LLTrans::getString("manip_hint1"));
+            LLColor4 help_text_color = LLColor4::white;
+            help_text_color.mV[VALPHA] = clamp_rescale(mHelpTextTimer.getElapsedTimeF32(), sHelpTextVisibleTime, sHelpTextVisibleTime + sHelpTextFadeTime, line_alpha, 0.f);
+            hud_render_text(help_text, help_text_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(help_text.c_str()), 3.f, help_text_color, false);
+            static const LLWString help_text2 = utf8str_to_wstring(LLTrans::getString("manip_hint2"));
+            help_text_pos -= offset_dir * mRadiusMeters * 0.4f;
+            hud_render_text(help_text2, help_text_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(help_text2.c_str()), 3.f, help_text_color, false);
+        }
+    }
+}
+
+// Returns TRUE if center of sphere is visible.  Also sets a bunch of member variables that are used later (e.g. mCenterToCam)
+BOOL LLManipRotate::updateVisiblity()
+{
+    // Don't want to recalculate the center of the selection during a drag.
+    // Due to packet delays, sometimes half the objects in the selection have their
+    // new position and half have their old one.  This creates subtle errors in the
+    // computed center position for that frame.  Unfortunately, these errors
+    // accumulate.  The result is objects seem to "fly apart" during rotations.
+    // JC - 03.26.2002
+    if (!hasMouseCapture())
+    {
+        mRotationCenter = gAgent.getPosGlobalFromAgent( getPivotPoint() );//LLSelectMgr::getInstance()->getSelectionCenterGlobal();
+    }
+
+    BOOL visible = FALSE;
+
+    //Assume that UI scale factor is equivalent for X and Y axis
+    F32 ui_scale_factor = LLUI::getScaleFactor().mV[VX];
+
+    LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        mCenterToCam = LLVector3(-1.f / gAgentCamera.mHUDCurZoom, 0.f, 0.f);
+        mCenterToCamNorm = mCenterToCam;
+        mCenterToCamMag = mCenterToCamNorm.normVec();
+
+        mRadiusMeters = RADIUS_PIXELS / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels();
+        mRadiusMeters /= gAgentCamera.mHUDCurZoom;
+        mRadiusMeters *= ui_scale_factor;
+
+        mCenterToProfilePlaneMag = mRadiusMeters * mRadiusMeters / mCenterToCamMag;
+        mCenterToProfilePlane = -mCenterToProfilePlaneMag * mCenterToCamNorm;
+
+        // x axis range is (-aspect * 0.5f, +aspect * 0.5)
+        // y axis range is (-0.5, 0.5)
+        // so use getWorldViewHeightRaw as scale factor when converting to pixel coordinates
+        mCenterScreen.set((S32)((0.5f - center.mV[VY]) / gAgentCamera.mHUDCurZoom * gViewerWindow->getWorldViewHeightScaled()),
+                            (S32)((center.mV[VZ] + 0.5f) / gAgentCamera.mHUDCurZoom * gViewerWindow->getWorldViewHeightScaled()));
+        visible = TRUE;
+    }
+    else
+    {
+        visible = LLViewerCamera::getInstance()->projectPosAgentToScreen(center, mCenterScreen );
+        if( visible )
+        {
+            mCenterToCam = gAgentCamera.getCameraPositionAgent() - center;
+            mCenterToCamNorm = mCenterToCam;
+            mCenterToCamMag = mCenterToCamNorm.normVec();
+            LLVector3 cameraAtAxis = LLViewerCamera::getInstance()->getAtAxis();
+            cameraAtAxis.normVec();
+
+            F32 z_dist = -1.f * (mCenterToCam * cameraAtAxis);
+
+            // Don't drag manip if object too far away
+            if (ALControlCache::LimitSelectDistance)
+            {
+                F32 max_select_distance = ALControlCache::MaxSelectDistance;
+                if (dist_vec_squared(gAgent.getPositionAgent(), center) > (max_select_distance * max_select_distance))
+                {
+                    visible = FALSE;
+                }
+            }
+
+            if (mCenterToCamMag > 0.001f)
+            {
+                F32 fraction_of_fov = RADIUS_PIXELS / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels();
+                F32 apparent_angle = fraction_of_fov * LLViewerCamera::getInstance()->getView();  // radians
+                mRadiusMeters = z_dist * tan(apparent_angle);
+                mRadiusMeters *= ui_scale_factor;
+
+                mCenterToProfilePlaneMag = mRadiusMeters * mRadiusMeters / mCenterToCamMag;
+                mCenterToProfilePlane = -mCenterToProfilePlaneMag * mCenterToCamNorm;
+            }
+            else
+            {
+                visible = FALSE;
+            }
+        }
+    }
+
+    mCamEdgeOn = FALSE;
+    F32 axis_onto_cam = mManipPart >= LL_ROT_X ? llabs( getConstraintAxis() * mCenterToCamNorm ) : 0.f;
+    if( axis_onto_cam < AXIS_ONTO_CAM_TOLERANCE )
+    {
+        mCamEdgeOn = TRUE;
+    }
+
+    return visible;
+}
+
+LLQuaternion LLManipRotate::dragUnconstrained( S32 x, S32 y )
+{
+    LLVector3 cam = gAgentCamera.getCameraPositionAgent();
+    LLVector3 center =  gAgent.getPosAgentFromGlobal( mRotationCenter );
+
+    mMouseCur = intersectMouseWithSphere( x, y, center, mRadiusMeters);
+
+    F32 delta_x = (F32)(mCenterScreen.mX - x);
+    F32 delta_y = (F32)(mCenterScreen.mY - y);
+
+    F32 dist_from_sphere_center = sqrt(delta_x * delta_x + delta_y * delta_y);
+
+    LLVector3 axis = mMouseDown % mMouseCur;
+    F32 angle = atan2(sqrtf(axis * axis), mMouseDown * mMouseCur);
+    axis.normVec();
+    LLQuaternion sphere_rot( angle, axis );
+
+    if (is_approx_zero(1.f - mMouseDown * mMouseCur))
+    {
+        return LLQuaternion::DEFAULT;
+    }
+    else if (dist_from_sphere_center < RADIUS_PIXELS)
+    {
+        return sphere_rot;
+    }
+    else
+    {
+        LLVector3 intersection;
+        getMousePointOnPlaneAgent( intersection, x, y, center + mCenterToProfilePlane, mCenterToCamNorm );
+
+        // amount dragging in sphere from center to periphery would rotate object
+        F32 in_sphere_angle = F_PI_BY_TWO;
+        F32 dist_to_tangent_point = mRadiusMeters;
+        if( !is_approx_zero( mCenterToProfilePlaneMag ) )
+        {
+            dist_to_tangent_point = sqrt( mRadiusMeters * mRadiusMeters - mCenterToProfilePlaneMag * mCenterToProfilePlaneMag );
+            in_sphere_angle = atan2( dist_to_tangent_point, mCenterToProfilePlaneMag );
+        }
+
+        LLVector3 profile_center_to_intersection = intersection - (center + mCenterToProfilePlane);
+        F32 dist_to_intersection = profile_center_to_intersection.normVec();
+        F32 angle = (-1.f + dist_to_intersection / dist_to_tangent_point) * in_sphere_angle;
+
+        LLVector3 axis;
+        if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+        {
+            axis = LLVector3(-1.f, 0.f, 0.f) % profile_center_to_intersection;
+        }
+        else
+        {
+            axis = (cam - center) % profile_center_to_intersection;
+            axis.normVec();
+        }
+        return sphere_rot * LLQuaternion( angle, axis );
+    }
+}
+
+LLVector3 LLManipRotate::getConstraintAxis()
+{
+    LLVector3 axis;
+    if( LL_ROT_ROLL == mManipPart )
+    {
+        axis = mCenterToCamNorm;
+    }
+    else
+    {
+        S32 axis_dir = mManipPart - LL_ROT_X;
+        if ((axis_dir >= LL_NO_PART) && (axis_dir < LL_Z_ARROW))
+        {
+            axis.mV[axis_dir] = 1.f;
+        }
+        else
+        {
+#ifndef LL_RELEASE_FOR_DOWNLOAD
+            LL_ERRS() << "Got bogus hit part in LLManipRotate::getConstraintAxis():" << mManipPart << LL_ENDL;
+#else
+            LL_WARNS() << "Got bogus hit part in LLManipRotate::getConstraintAxis():" << mManipPart << LL_ENDL;
+#endif
+            axis.mV[0] = 1.f;
+        }
+
+        LLVector3 grid_origin;
+        LLVector3 grid_scale;
+        LLQuaternion grid_rotation;
+
+        LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
+
+        LLSelectNode* first_node = mObjectSelection->getFirstMoveableNode(TRUE);
+        if (first_node)
+        {
+            // *FIX: get agent local attachment grid working
+            // Put rotation into frame of first selected root object
+            axis = axis * grid_rotation;
+        }
+    }
+
+    return axis;
+}
+
+LLQuaternion LLManipRotate::dragConstrained( S32 x, S32 y )
+{
+    LLSelectNode* first_object_node = mObjectSelection->getFirstMoveableNode(TRUE);
+    LLVector3 constraint_axis = getConstraintAxis();
+    LLVector3 center = gAgent.getPosAgentFromGlobal( mRotationCenter );
+
+    F32 angle = 0.f;
+
+    // build snap axes
+    LLVector3 grid_origin;
+    LLVector3 grid_scale;
+    LLQuaternion grid_rotation;
+
+    LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
+
+    LLVector3 axis1;
+    LLVector3 axis2;
+
+    LLVector3 test_axis = constraint_axis;
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_ATTACHMENT && isAgentAvatarValid())
+    {
+        test_axis = test_axis * ~grid_rotation;
+    }
+    else if (LLSelectMgr::getInstance()->getGridMode() == GRID_MODE_REF_OBJECT)
+    {
+        test_axis = test_axis * ~grid_rotation;
+    }
+    test_axis.abs();
+
+    // find closest global axis to constraint axis;
+    if (test_axis.mV[VX] > test_axis.mV[VY] && test_axis.mV[VX] > test_axis.mV[VZ])
+    {
+        axis1 = LLVector3::y_axis;
+    }
+    else if (test_axis.mV[VY] > test_axis.mV[VZ])
+    {
+        axis1 = LLVector3::z_axis;
+    }
+    else
+    {
+        axis1 = LLVector3::x_axis;
+    }
+
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_ATTACHMENT && isAgentAvatarValid())
+    {
+        axis1 = axis1 * grid_rotation;
+    }
+    else if (LLSelectMgr::getInstance()->getGridMode() == GRID_MODE_REF_OBJECT)
+    {
+        axis1 = axis1 * grid_rotation;
+    }
+
+    //project axis onto constraint plane
+    axis1 -= (axis1 * constraint_axis) * constraint_axis;
+    axis1.normVec();
+
+    // calculate third and final axis
+    axis2 = constraint_axis % axis1;
+
+    //F32 axis_onto_cam = llabs( constraint_axis * mCenterToCamNorm );
+    if( mCamEdgeOn )
+    {
+        // We're looking at the ring edge-on.
+        LLVector3 snap_plane_center = (center + (constraint_axis * mRadiusMeters * 0.5f));
+        LLVector3 cam_to_snap_plane;
+        if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+        {
+            cam_to_snap_plane.setVec(1.f, 0.f, 0.f);
+        }
+        else
+        {
+            cam_to_snap_plane = snap_plane_center - gAgentCamera.getCameraPositionAgent();
+            cam_to_snap_plane.normVec();
+        }
+
+        LLVector3 projected_mouse;
+        BOOL hit = getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, constraint_axis);
+        projected_mouse -= snap_plane_center;
+
+        if (ALControlCache::SnapEnabled) {
+            S32 snap_plane = 0;
+
+            F32 dot = cam_to_snap_plane * constraint_axis;
+            if (llabs(dot) < 0.01f)
+            {
+                // looking at ring edge on, project onto view plane and check if mouse is past ring
+                getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, cam_to_snap_plane);
+                projected_mouse -= snap_plane_center;
+                dot = projected_mouse * constraint_axis;
+                if (projected_mouse * constraint_axis > 0)
+                {
+                    snap_plane = 1;
+                }
+                projected_mouse -= dot * constraint_axis;
+            }
+            else if (dot > 0.f)
+            {
+                // look for mouse position outside and in front of snap circle
+                if (hit && projected_mouse.magVec() > SNAP_GUIDE_INNER_RADIUS * mRadiusMeters && projected_mouse * cam_to_snap_plane < 0.f)
+                {
+                    snap_plane = 1;
+                }
+            }
+            else
+            {
+                // look for mouse position inside or in back of snap circle
+                if (projected_mouse.magVec() < SNAP_GUIDE_INNER_RADIUS * mRadiusMeters || projected_mouse * cam_to_snap_plane > 0.f || !hit)
+                {
+                    snap_plane = 1;
+                }
+            }
+
+            if (snap_plane == 0)
+            {
+                // try other plane
+                snap_plane_center = (center - (constraint_axis * mRadiusMeters * 0.5f));
+                if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+                {
+                    cam_to_snap_plane.setVec(1.f, 0.f, 0.f);
+                }
+                else
+                {
+                    cam_to_snap_plane = snap_plane_center - gAgentCamera.getCameraPositionAgent();
+                    cam_to_snap_plane.normVec();
+                }
+
+                hit = getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, constraint_axis);
+                projected_mouse -= snap_plane_center;
+
+                dot = cam_to_snap_plane * constraint_axis;
+                if (llabs(dot) < 0.01f)
+                {
+                    // looking at ring edge on, project onto view plane and check if mouse is past ring
+                    getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, cam_to_snap_plane);
+                    projected_mouse -= snap_plane_center;
+                    dot = projected_mouse * constraint_axis;
+                    if (projected_mouse * constraint_axis < 0)
+                    {
+                        snap_plane = 2;
+                    }
+                    projected_mouse -= dot * constraint_axis;
+                }
+                else if (dot < 0.f)
+                {
+                    // look for mouse position outside and in front of snap circle
+                    if (hit && projected_mouse.magVec() > SNAP_GUIDE_INNER_RADIUS * mRadiusMeters && projected_mouse * cam_to_snap_plane < 0.f)
+                    {
+                        snap_plane = 2;
+                    }
+                }
+                else
+                {
+                    // look for mouse position inside or in back of snap circle
+                    if (projected_mouse.magVec() < SNAP_GUIDE_INNER_RADIUS * mRadiusMeters || projected_mouse * cam_to_snap_plane > 0.f || !hit)
+                    {
+                        snap_plane = 2;
+                    }
+                }
+            }
+
+            if (snap_plane > 0)
+            {
+                LLVector3 cam_at_axis;
+                if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+                {
+                    cam_at_axis.setVec(1.f, 0.f, 0.f);
+                }
+                else
+                {
+                    cam_at_axis = snap_plane_center - gAgentCamera.getCameraPositionAgent();
+                    cam_at_axis.normVec();
+                }
+
+                // first, project mouse onto screen plane at point tangent to rotation radius.
+                getMousePointOnPlaneAgent(projected_mouse, x, y, snap_plane_center, cam_at_axis);
+                // project that point onto rotation plane
+                projected_mouse -= snap_plane_center;
+                projected_mouse -= projected_vec(projected_mouse, constraint_axis);
+
+                F32 mouse_lateral_dist = llmin(SNAP_GUIDE_INNER_RADIUS * mRadiusMeters, projected_mouse.magVec());
+                F32 mouse_depth = SNAP_GUIDE_INNER_RADIUS * mRadiusMeters;
+                if (llabs(mouse_lateral_dist) > 0.01f)
+                {
+                    mouse_depth = sqrtf((SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) * (SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) -
+                                        (mouse_lateral_dist * mouse_lateral_dist));
+                }
+                LLVector3 projected_camera_at = cam_at_axis - projected_vec(cam_at_axis, constraint_axis);
+                projected_mouse -= mouse_depth * projected_camera_at;
+
+                if (!mInSnapRegime)
+                {
+                    mSmoothRotate = TRUE;
+                }
+                mInSnapRegime = TRUE;
+                // 0 to 360 deg
+                F32 mouse_angle = fmodf(atan2(projected_mouse * axis1, projected_mouse * axis2) * RAD_TO_DEG + 360.f, 360.f);
+
+                F32 relative_mouse_angle = fmodf(mouse_angle + (SNAP_ANGLE_DETENTE / 2), SNAP_ANGLE_INCREMENT);
+
+                LLVector3 object_axis;
+                getObjectAxisClosestToMouse(object_axis);
+                if (first_object_node)
+                {
+                    object_axis = object_axis * first_object_node->mSavedRotation;
+                }
+
+                // project onto constraint plane
+                object_axis = object_axis - (object_axis * getConstraintAxis()) * getConstraintAxis();
+                object_axis.normVec();
+
+                if (relative_mouse_angle < SNAP_ANGLE_DETENTE)
+                {
+                    F32 quantized_mouse_angle = mouse_angle - (relative_mouse_angle - (SNAP_ANGLE_DETENTE * 0.5f));
+                    angle = (quantized_mouse_angle * DEG_TO_RAD) - atan2(object_axis * axis1, object_axis * axis2);
+                }
+                else
+                {
+                    angle = (mouse_angle * DEG_TO_RAD) - atan2(object_axis * axis1, object_axis * axis2);
+                }
+                return LLQuaternion( -angle, constraint_axis );
+            }
+            else
+            {
+                if (mInSnapRegime)
+                {
+                    mSmoothRotate = TRUE;
+                }
+                mInSnapRegime = FALSE;
+            }
+        }
+        else {
+            if (mInSnapRegime)
+            {
+                mSmoothRotate = TRUE;
+            }
+            mInSnapRegime = FALSE;
+        }
+
+        if (!mInSnapRegime)
+        {
+            LLVector3 up_from_axis = mCenterToCamNorm % constraint_axis;
+            up_from_axis.normVec();
+            LLVector3 cur_intersection;
+            getMousePointOnPlaneAgent(cur_intersection, x, y, center, mCenterToCam);
+            cur_intersection -= center;
+            mMouseCur = projected_vec(cur_intersection, up_from_axis);
+            F32 mouse_depth = SNAP_GUIDE_INNER_RADIUS * mRadiusMeters;
+            F32 mouse_dist_sqrd = mMouseCur.magVecSquared();
+            if (mouse_dist_sqrd > 0.0001f)
+            {
+                mouse_depth = sqrtf((SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) * (SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) -
+                                    mouse_dist_sqrd);
+            }
+            LLVector3 projected_center_to_cam = mCenterToCamNorm - projected_vec(mCenterToCamNorm, constraint_axis);
+            mMouseCur += mouse_depth * projected_center_to_cam;
+
+            F32 dist = (cur_intersection * up_from_axis) - (mMouseDown * up_from_axis);
+            angle = dist / (SNAP_GUIDE_INNER_RADIUS * mRadiusMeters) * -F_PI_BY_TWO;
+        }
+    }
+    else
+    {
+        LLVector3 projected_mouse;
+        getMousePointOnPlaneAgent(projected_mouse, x, y, center, constraint_axis);
+        projected_mouse -= center;
+        mMouseCur = projected_mouse;
+        mMouseCur.normVec();
+
+        if (!first_object_node)
+        {
+            return LLQuaternion::DEFAULT;
+        }
+
+        if (ALControlCache::SnapEnabled && projected_mouse.magVec() > SNAP_GUIDE_INNER_RADIUS * mRadiusMeters)
+        {
+            if (!mInSnapRegime)
+            {
+                mSmoothRotate = TRUE;
+            }
+            mInSnapRegime = TRUE;
+            // 0 to 360 deg
+            F32 mouse_angle = fmodf(atan2(projected_mouse * axis1, projected_mouse * axis2) * RAD_TO_DEG + 360.f, 360.f);
+
+            F32 relative_mouse_angle = fmodf(mouse_angle + (SNAP_ANGLE_DETENTE / 2), SNAP_ANGLE_INCREMENT);
+
+            LLVector3 object_axis;
+            getObjectAxisClosestToMouse(object_axis);
+            object_axis = object_axis * first_object_node->mSavedRotation;
+
+            // project onto constraint plane
+            object_axis = object_axis - (object_axis * getConstraintAxis()) * getConstraintAxis();
+            object_axis.normVec();
+
+            if (relative_mouse_angle < SNAP_ANGLE_DETENTE)
+            {
+                F32 quantized_mouse_angle = mouse_angle - (relative_mouse_angle - (SNAP_ANGLE_DETENTE * 0.5f));
+                angle = (quantized_mouse_angle * DEG_TO_RAD) - atan2(object_axis * axis1, object_axis * axis2);
+            }
+            else
+            {
+                angle = (mouse_angle * DEG_TO_RAD) - atan2(object_axis * axis1, object_axis * axis2);
+            }
+            return LLQuaternion( -angle, constraint_axis );
+        }
+        else
+        {
+            if (mInSnapRegime)
+            {
+                mSmoothRotate = TRUE;
+            }
+            mInSnapRegime = FALSE;
+        }
+
+        LLVector3 cross_product = mMouseDown % mMouseCur;
+        angle = atan2(sqrtf(cross_product * cross_product), mMouseCur * mMouseDown);
+        F32 dir = cross_product * constraint_axis;  // cross product
+        if( dir < 0.f )
+        {
+            angle *= -1.f;
+        }
+    }
+
+    F32 rot_step = gSavedSettings.getF32("RotationStep");
+    F32 step_size = DEG_TO_RAD * rot_step;
+    angle -= fmod(angle, step_size);
+
+    return LLQuaternion( angle, constraint_axis );
+}
+
+
+
+LLVector3 LLManipRotate::intersectMouseWithSphere( S32 x, S32 y, const LLVector3& sphere_center, F32 sphere_radius)
+{
+    LLVector3 ray_pt;
+    LLVector3 ray_dir;
+    mouseToRay( x, y, &ray_pt, &ray_dir);
+    return intersectRayWithSphere( ray_pt, ray_dir, sphere_center, sphere_radius );
+}
+
+LLVector3 LLManipRotate::intersectRayWithSphere( const LLVector3& ray_pt, const LLVector3& ray_dir, const LLVector3& sphere_center, F32 sphere_radius)
+{
+    LLVector3 ray_pt_to_center = sphere_center - ray_pt;
+    F32 center_distance = ray_pt_to_center.normVec();
+
+    F32 dot = ray_dir * ray_pt_to_center;
+
+    if (dot == 0.f)
+    {
+        return LLVector3::zero;
+    }
+
+    // point which ray hits plane centered on sphere origin, facing ray origin
+    LLVector3 intersection_sphere_plane = ray_pt + (ray_dir * center_distance / dot);
+    // vector from sphere origin to the point, normalized to sphere radius
+    LLVector3 sphere_center_to_intersection = (intersection_sphere_plane - sphere_center) / sphere_radius;
+
+    F32 dist_squared = sphere_center_to_intersection.magVecSquared();
+    LLVector3 result;
+
+    if (dist_squared > 1.f)
+    {
+        result = sphere_center_to_intersection;
+        result.normVec();
+    }
+    else
+    {
+        result = sphere_center_to_intersection - ray_dir * sqrt(1.f - dist_squared);
+    }
+
+    return result;
+}
+
+// Utility function.  Should probably be moved to another class.
+// x,y - mouse position in scaled window coordinates (NOT GL viewport coordinates)
+//static
+void LLManipRotate::mouseToRay( S32 x, S32 y, LLVector3* ray_pt, LLVector3* ray_dir )
+{
+    if (LLSelectMgr::getInstance()->getSelection()->getSelectType() == SELECT_TYPE_HUD)
+    {
+        F32 mouse_x = (((F32)x / gViewerWindow->getWorldViewRectScaled().getWidth()) - 0.5f) / gAgentCamera.mHUDCurZoom;
+        F32 mouse_y = ((((F32)y) / gViewerWindow->getWorldViewRectScaled().getHeight()) - 0.5f) / gAgentCamera.mHUDCurZoom;
+
+        *ray_pt = LLVector3(-1.f, -mouse_x, mouse_y);
+        *ray_dir = LLVector3(1.f, 0.f, 0.f);
+    }
+    else
+    {
+        *ray_pt = gAgentCamera.getCameraPositionAgent();
+        *ray_dir = gViewerWindow->mouseDirectionGlobal(x, y);
+    }
+}
+
+void LLManipRotate::highlightManipulators( S32 x, S32 y )
+{
+    mHighlightedPart = LL_NO_PART;
+
+    //LLBBox bbox = LLSelectMgr::getInstance()->getBBoxOfSelection();
+    LLViewerObject *first_object = mObjectSelection->getFirstMoveableObject(TRUE);
+
+    if (!first_object)
+    {
+        return;
+    }
+
+    LLVector3 rotation_center = gAgent.getPosAgentFromGlobal(mRotationCenter);
+    LLVector3 mouse_dir_x;
+    LLVector3 mouse_dir_y;
+    LLVector3 mouse_dir_z;
+    LLVector3 intersection_roll;
+
+    LLVector3 grid_origin;
+    LLVector3 grid_scale;
+    LLQuaternion grid_rotation;
+
+    LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
+
+    LLVector3 rot_x_axis = LLVector3::x_axis * grid_rotation;
+    LLVector3 rot_y_axis = LLVector3::y_axis * grid_rotation;
+    LLVector3 rot_z_axis = LLVector3::z_axis * grid_rotation;
+
+    F32 proj_rot_x_axis = llabs(rot_x_axis * mCenterToCamNorm);
+    F32 proj_rot_y_axis = llabs(rot_y_axis * mCenterToCamNorm);
+    F32 proj_rot_z_axis = llabs(rot_z_axis * mCenterToCamNorm);
+
+    F32 min_select_distance = 0.f;
+    F32 cur_select_distance = 0.f;
+
+    // test x
+    getMousePointOnPlaneAgent(mouse_dir_x, x, y, rotation_center, rot_x_axis);
+    mouse_dir_x -= rotation_center;
+    // push intersection point out when working at obtuse angle to make ring easier to hit
+    mouse_dir_x *= 1.f + (1.f - llabs(rot_x_axis * mCenterToCamNorm)) * 0.1f;
+
+    // test y
+    getMousePointOnPlaneAgent(mouse_dir_y, x, y, rotation_center, rot_y_axis);
+    mouse_dir_y -= rotation_center;
+    mouse_dir_y *= 1.f + (1.f - llabs(rot_y_axis * mCenterToCamNorm)) * 0.1f;
+
+    // test z
+    getMousePointOnPlaneAgent(mouse_dir_z, x, y, rotation_center, rot_z_axis);
+    mouse_dir_z -= rotation_center;
+    mouse_dir_z *= 1.f + (1.f - llabs(rot_z_axis * mCenterToCamNorm)) * 0.1f;
+
+    // test roll
+    getMousePointOnPlaneAgent(intersection_roll, x, y, rotation_center, mCenterToCamNorm);
+    intersection_roll -= rotation_center;
+
+    F32 dist_x = mouse_dir_x.normVec();
+    F32 dist_y = mouse_dir_y.normVec();
+    F32 dist_z = mouse_dir_z.normVec();
+
+    F32 distance_threshold = (MAX_MANIP_SELECT_DISTANCE * mRadiusMeters) / gViewerWindow->getWorldViewHeightScaled();
+
+    if (llabs(dist_x - mRadiusMeters) * llmax(0.05f, proj_rot_x_axis) < distance_threshold)
+    {
+        // selected x
+        cur_select_distance = dist_x * mouse_dir_x * mCenterToCamNorm;
+        if (cur_select_distance >= -0.05f && (min_select_distance == 0.f || cur_select_distance > min_select_distance))
+        {
+            min_select_distance = cur_select_distance;
+            mHighlightedPart = LL_ROT_X;
+        }
+    }
+    if (llabs(dist_y - mRadiusMeters) * llmax(0.05f, proj_rot_y_axis) < distance_threshold)
+    {
+        // selected y
+        cur_select_distance = dist_y * mouse_dir_y * mCenterToCamNorm;
+        if (cur_select_distance >= -0.05f && (min_select_distance == 0.f || cur_select_distance > min_select_distance))
+        {
+            min_select_distance = cur_select_distance;
+            mHighlightedPart = LL_ROT_Y;
+        }
+    }
+    if (llabs(dist_z - mRadiusMeters) * llmax(0.05f, proj_rot_z_axis) < distance_threshold)
+    {
+        // selected z
+        cur_select_distance = dist_z * mouse_dir_z * mCenterToCamNorm;
+        if (cur_select_distance >= -0.05f && (min_select_distance == 0.f || cur_select_distance > min_select_distance))
+        {
+            min_select_distance = cur_select_distance;
+            mHighlightedPart = LL_ROT_Z;
+        }
+    }
+
+    // test for edge-on intersections
+    if (proj_rot_x_axis < 0.05f)
+    {
+        if ((proj_rot_y_axis > 0.05f && (dist_y * llabs(mouse_dir_y * rot_x_axis) < distance_threshold) && dist_y < mRadiusMeters) ||
+            (proj_rot_z_axis > 0.05f && (dist_z * llabs(mouse_dir_z * rot_x_axis) < distance_threshold) && dist_z < mRadiusMeters))
+        {
+            mHighlightedPart = LL_ROT_X;
+        }
+    }
+
+    if (proj_rot_y_axis < 0.05f)
+    {
+        if ((proj_rot_x_axis > 0.05f && (dist_x * llabs(mouse_dir_x * rot_y_axis) < distance_threshold) && dist_x < mRadiusMeters) ||
+            (proj_rot_z_axis > 0.05f && (dist_z * llabs(mouse_dir_z * rot_y_axis) < distance_threshold) && dist_z < mRadiusMeters))
+        {
+            mHighlightedPart = LL_ROT_Y;
+        }
+    }
+
+    if (proj_rot_z_axis < 0.05f)
+    {
+        if ((proj_rot_x_axis > 0.05f && (dist_x * llabs(mouse_dir_x * rot_z_axis) < distance_threshold) && dist_x < mRadiusMeters) ||
+            (proj_rot_y_axis > 0.05f && (dist_y * llabs(mouse_dir_y * rot_z_axis) < distance_threshold) && dist_y < mRadiusMeters))
+        {
+            mHighlightedPart = LL_ROT_Z;
+        }
+    }
+
+    // test for roll
+    if (mHighlightedPart == LL_NO_PART)
+    {
+        F32 roll_distance = intersection_roll.magVec();
+        F32 width_meters = WIDTH_PIXELS * mRadiusMeters / RADIUS_PIXELS;
+
+        // use larger distance threshold for roll as it is checked only if something else wasn't highlighted
+        if (llabs(roll_distance - (mRadiusMeters + (width_meters * 2.f))) < distance_threshold * 2.f)
+        {
+            mHighlightedPart = LL_ROT_ROLL;
+        }
+        else if (roll_distance < mRadiusMeters)
+        {
+            mHighlightedPart = LL_ROT_GENERAL;
+        }
+    }
+}
+
+S32 LLManipRotate::getObjectAxisClosestToMouse(LLVector3& object_axis)
+{
+    LLSelectNode* first_object_node = mObjectSelection->getFirstMoveableNode(TRUE);
+
+    if (!first_object_node)
+    {
+        object_axis.clearVec();
+        return -1;
+    }
+
+    LLQuaternion obj_rotation = first_object_node->mSavedRotation;
+    LLVector3 mouse_down_object = mMouseDown * ~obj_rotation;
+    LLVector3 mouse_down_abs = mouse_down_object;
+    mouse_down_abs.abs();
+
+    S32 axis_index = 0;
+    if (mouse_down_abs.mV[VX] > mouse_down_abs.mV[VY] && mouse_down_abs.mV[VX] > mouse_down_abs.mV[VZ])
+    {
+        if (mouse_down_object.mV[VX] > 0.f)
+        {
+            object_axis = LLVector3::x_axis;
+        }
+        else
+        {
+            object_axis = LLVector3::x_axis_neg;
+        }
+        axis_index = VX;
+    }
+    else if (mouse_down_abs.mV[VY] > mouse_down_abs.mV[VZ])
+    {
+        if (mouse_down_object.mV[VY] > 0.f)
+        {
+            object_axis = LLVector3::y_axis;
+        }
+        else
+        {
+            object_axis = LLVector3::y_axis_neg;
+        }
+        axis_index = VY;
+    }
+    else
+    {
+        if (mouse_down_object.mV[VZ] > 0.f)
+        {
+            object_axis = LLVector3::z_axis;
+        }
+        else
+        {
+            object_axis = LLVector3::z_axis_neg;
+        }
+        axis_index = VZ;
+    }
+
+    return axis_index;
+}
+
+//virtual
+BOOL LLManipRotate::canAffectSelection()
+{
+    BOOL can_rotate = mObjectSelection->getObjectCount() != 0;
+    if (can_rotate)
+    {
+        struct f : public LLSelectedObjectFunctor
+        {
+            virtual bool apply(LLViewerObject* objectp)
+            {
+                LLViewerObject *root_object = (objectp == NULL) ? NULL : objectp->getRootEdit();
+                return objectp->permMove() && !objectp->isPermanentEnforced() &&
+                    ((root_object == NULL) || !root_object->isPermanentEnforced()) &&
+                    (objectp->permModify() || !ALControlCache::EditLinkedParts);
+            }
+        } func;
+        can_rotate = mObjectSelection->applyToObjects(&func);
+    }
+    return can_rotate;
 }
 
diff --git a/indra/newview/llmaniptranslate.cpp b/indra/newview/llmaniptranslate.cpp
index df6536458d5b40eb0f124f3b80410cb80074b064..bb6f99d01a61977602cc467229c33b2177da9f6c 100644
--- a/indra/newview/llmaniptranslate.cpp
+++ b/indra/newview/llmaniptranslate.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llmaniptranslate.cpp
  * @brief LLManipTranslate class implementation
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -79,202 +79,202 @@ const F32 SNAP_ARROW_SCALE = 0.7f;
 
 static LLPointer<LLViewerTexture> sGridTex = NULL ;
 
-const LLManip::EManipPart MANIPULATOR_IDS[9] = 
+const LLManip::EManipPart MANIPULATOR_IDS[9] =
 {
-	LLManip::LL_X_ARROW,
-	LLManip::LL_Y_ARROW,
-	LLManip::LL_Z_ARROW,
-	LLManip::LL_X_ARROW,
-	LLManip::LL_Y_ARROW,
-	LLManip::LL_Z_ARROW,
-	LLManip::LL_YZ_PLANE,
-	LLManip::LL_XZ_PLANE,
-	LLManip::LL_XY_PLANE
+    LLManip::LL_X_ARROW,
+    LLManip::LL_Y_ARROW,
+    LLManip::LL_Z_ARROW,
+    LLManip::LL_X_ARROW,
+    LLManip::LL_Y_ARROW,
+    LLManip::LL_Z_ARROW,
+    LLManip::LL_YZ_PLANE,
+    LLManip::LL_XZ_PLANE,
+    LLManip::LL_XY_PLANE
 };
 
-const U32 ARROW_TO_AXIS[4] = 
+const U32 ARROW_TO_AXIS[4] =
 {
-	VX,
-	VX,
-	VY,
-	VZ
+    VX,
+    VX,
+    VY,
+    VZ
 };
 
 // Sort manipulator handles by their screen-space projection
 struct ClosestToCamera
 {
-	bool operator()(const LLManipTranslate::ManipulatorHandle& a,
-					const LLManipTranslate::ManipulatorHandle& b) const
-	{
-		return a.mEndPosition.mV[VZ] < b.mEndPosition.mV[VZ];
-	}
+    bool operator()(const LLManipTranslate::ManipulatorHandle& a,
+                    const LLManipTranslate::ManipulatorHandle& b) const
+    {
+        return a.mEndPosition.mV[VZ] < b.mEndPosition.mV[VZ];
+    }
 };
 
 LLManipTranslate::LLManipTranslate( LLToolComposite* composite )
-:	LLManip( std::string("Move"), composite ),
-	mLastHoverMouseX(-1),
-	mLastHoverMouseY(-1),
-	mMouseOutsideSlop(FALSE),
-	mCopyMadeThisDrag(FALSE),
-	mMouseDownX(-1),
-	mMouseDownY(-1),
-	mAxisArrowLength(50),
-	mConeSize(0),
-	mArrowLengthMeters(0.f),
-	mGridSizeMeters(1.f),
-	mPlaneManipOffsetMeters(0.f),
-	mUpdateTimer(),
-	mSnapOffsetMeters(0.f),
-	mSubdivisions(10.f),
-	mInSnapRegime(FALSE),
-	mArrowScales(1.f, 1.f, 1.f),
-	mPlaneScales(1.f, 1.f, 1.f),
-	mPlaneManipPositions(1.f, 1.f, 1.f, 1.f)
-{ 
-	if (sGridTex.isNull())
-	{ 
-		restoreGL();
-	}
+:   LLManip( std::string("Move"), composite ),
+    mLastHoverMouseX(-1),
+    mLastHoverMouseY(-1),
+    mMouseOutsideSlop(FALSE),
+    mCopyMadeThisDrag(FALSE),
+    mMouseDownX(-1),
+    mMouseDownY(-1),
+    mAxisArrowLength(50),
+    mConeSize(0),
+    mArrowLengthMeters(0.f),
+    mGridSizeMeters(1.f),
+    mPlaneManipOffsetMeters(0.f),
+    mUpdateTimer(),
+    mSnapOffsetMeters(0.f),
+    mSubdivisions(10.f),
+    mInSnapRegime(FALSE),
+    mArrowScales(1.f, 1.f, 1.f),
+    mPlaneScales(1.f, 1.f, 1.f),
+    mPlaneManipPositions(1.f, 1.f, 1.f, 1.f)
+{
+    if (sGridTex.isNull())
+    {
+        restoreGL();
+    }
 }
 
 //static
 U32 LLManipTranslate::getGridTexName()
 {
-	if(sGridTex.isNull())
-	{
-		restoreGL() ;
-	}
+    if(sGridTex.isNull())
+    {
+        restoreGL() ;
+    }
 
-	return sGridTex.isNull() ? 0 : sGridTex->getTexName() ;
+    return sGridTex.isNull() ? 0 : sGridTex->getTexName() ;
 }
 
 //static
 void LLManipTranslate::destroyGL()
 {
-	if (sGridTex)
-	{
-		sGridTex = NULL ;
-	}
+    if (sGridTex)
+    {
+        sGridTex = NULL ;
+    }
 }
 
 //static
 void LLManipTranslate::restoreGL()
 {
-	//generate grid texture
-	U32 rez = 512;
-	U32 mip = 0;
-
-	destroyGL() ;
-	sGridTex = LLViewerTextureManager::getLocalTexture() ;
-	if(!sGridTex->createGLTexture())
-	{
-		sGridTex = NULL ;
-		return ;
-	}
-
-	GLuint* d = new GLuint[rez*rez];	
-
-	gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, sGridTex->getTexName(), true);
-	gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
-
-	while (rez >= 1)
-	{
-		for (U32 i = 0; i < rez*rez; i++)
-		{
-			d[i] = 0x00FFFFFF;
-		}
-		
-		U32 subcol = 0xFFFFFFFF;
-		if (rez >= 4)
-		{	//large grain grid
-			for (U32 i = 0; i < rez; i++)
-			{
-				if (rez <= 16)
-				{
-					if (rez == 16)
-					{
-						subcol = 0xA0FFFFFF;
-					}
-					else if (rez == 8)
-					{
-						subcol = 0x80FFFFFF;
-					}
-					else
-					{
-						subcol = 0x40FFFFFF;
-					}
-				}
-				else
-				{
-					subcol = 0xFFFFFFFF;	
-				}
-				d[i			*rez+ 0		 ] = subcol;
-				d[0			*rez+ i		 ] = subcol;				
-				if (rez >= 32)
-				{
-					d[i			*rez+ (rez-1)] = subcol;
-					d[(rez-1)	*rez+ i		 ] = subcol;
-				}
-
-				if (rez >= 64)
-				{
-					subcol = 0xFFFFFFFF;
-					
-					if (i > 0 && i < (rez-1))
-					{
-						d[i			*rez+ 1		 ] = subcol;
-						d[i			*rez+ (rez-2)] = subcol;
-						d[1			*rez+ i		 ] = subcol;
-						d[(rez-2)	*rez+ i		 ] = subcol;
-					}
-				}
-			}
-		}
-
-		subcol = 0x50A0A0A0;
-		if (rez >= 128)
-		{ //small grain grid
-			for (U32 i = 8; i < rez; i+=8)
-			{
-				for (U32 j = 2; j < rez-2; j++)
-				{
-					d[i	*rez+ j] = subcol;
-					d[j	*rez+ i] = subcol;			
-				}
-			}
-		}
-		if (rez >= 64)
-		{ //medium grain grid
-			if (rez == 64)
-			{
-				subcol = 0x50A0A0A0;
-			}
-			else
-			{
-				subcol = 0xA0D0D0D0;
-			}
-
-			for (U32 i = 32; i < rez; i+=32)
-			{
-				U32 pi = i-1;
-				for (U32 j = 2; j < rez-2; j++)
-				{
-					d[i		*rez+ j] = subcol;
-					d[j		*rez+ i] = subcol;
-
-					if (rez > 128)
-					{
-						d[pi	*rez+ j] = subcol;
-						d[j		*rez+ pi] = subcol;			
-					}
-				}
-			}
-		}
-		LLImageGL::setManualImage(GL_TEXTURE_2D, mip, GL_RGBA, rez, rez, GL_RGBA, GL_UNSIGNED_BYTE, d);
-		rez = rez >> 1;
-		mip++;
-	}
-	delete [] d;
+    //generate grid texture
+    U32 rez = 512;
+    U32 mip = 0;
+
+    destroyGL() ;
+    sGridTex = LLViewerTextureManager::getLocalTexture() ;
+    if(!sGridTex->createGLTexture())
+    {
+        sGridTex = NULL ;
+        return ;
+    }
+
+    GLuint* d = new GLuint[rez*rez];
+
+    gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, sGridTex->getTexName(), true);
+    gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
+
+    while (rez >= 1)
+    {
+        for (U32 i = 0; i < rez*rez; i++)
+        {
+            d[i] = 0x00FFFFFF;
+        }
+
+        U32 subcol = 0xFFFFFFFF;
+        if (rez >= 4)
+        {   //large grain grid
+            for (U32 i = 0; i < rez; i++)
+            {
+                if (rez <= 16)
+                {
+                    if (rez == 16)
+                    {
+                        subcol = 0xA0FFFFFF;
+                    }
+                    else if (rez == 8)
+                    {
+                        subcol = 0x80FFFFFF;
+                    }
+                    else
+                    {
+                        subcol = 0x40FFFFFF;
+                    }
+                }
+                else
+                {
+                    subcol = 0xFFFFFFFF;
+                }
+                d[i         *rez+ 0      ] = subcol;
+                d[0         *rez+ i      ] = subcol;
+                if (rez >= 32)
+                {
+                    d[i         *rez+ (rez-1)] = subcol;
+                    d[(rez-1)   *rez+ i      ] = subcol;
+                }
+
+                if (rez >= 64)
+                {
+                    subcol = 0xFFFFFFFF;
+
+                    if (i > 0 && i < (rez-1))
+                    {
+                        d[i         *rez+ 1      ] = subcol;
+                        d[i         *rez+ (rez-2)] = subcol;
+                        d[1         *rez+ i      ] = subcol;
+                        d[(rez-2)   *rez+ i      ] = subcol;
+                    }
+                }
+            }
+        }
+
+        subcol = 0x50A0A0A0;
+        if (rez >= 128)
+        { //small grain grid
+            for (U32 i = 8; i < rez; i+=8)
+            {
+                for (U32 j = 2; j < rez-2; j++)
+                {
+                    d[i *rez+ j] = subcol;
+                    d[j *rez+ i] = subcol;
+                }
+            }
+        }
+        if (rez >= 64)
+        { //medium grain grid
+            if (rez == 64)
+            {
+                subcol = 0x50A0A0A0;
+            }
+            else
+            {
+                subcol = 0xA0D0D0D0;
+            }
+
+            for (U32 i = 32; i < rez; i+=32)
+            {
+                U32 pi = i-1;
+                for (U32 j = 2; j < rez-2; j++)
+                {
+                    d[i     *rez+ j] = subcol;
+                    d[j     *rez+ i] = subcol;
+
+                    if (rez > 128)
+                    {
+                        d[pi    *rez+ j] = subcol;
+                        d[j     *rez+ pi] = subcol;
+                    }
+                }
+            }
+        }
+        LLImageGL::setManualImage(GL_TEXTURE_2D, mip, GL_RGBA, rez, rez, GL_RGBA, GL_UNSIGNED_BYTE, d);
+        rez = rez >> 1;
+        mip++;
+    }
+    delete [] d;
 }
 
 
@@ -285,387 +285,387 @@ LLManipTranslate::~LLManipTranslate()
 
 void LLManipTranslate::handleSelect()
 {
-	LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+    LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
     if (gFloaterTools)
     {
         gFloaterTools->setStatusText("move");
     }
-	LLManip::handleSelect();
+    LLManip::handleSelect();
 }
 
 BOOL LLManipTranslate::handleMouseDown(S32 x, S32 y, MASK mask)
 {
-	BOOL	handled = FALSE;
-
-	// didn't click in any UI object, so must have clicked in the world
-	if( (mHighlightedPart == LL_X_ARROW ||
-		 mHighlightedPart == LL_Y_ARROW ||
-		 mHighlightedPart == LL_Z_ARROW ||
-		 mHighlightedPart == LL_YZ_PLANE ||
-		 mHighlightedPart == LL_XZ_PLANE ||
-		 mHighlightedPart == LL_XY_PLANE ) )
-	{
-		handled = handleMouseDownOnPart( x, y, mask );
-	}
-
-	return handled;
+    BOOL    handled = FALSE;
+
+    // didn't click in any UI object, so must have clicked in the world
+    if( (mHighlightedPart == LL_X_ARROW ||
+         mHighlightedPart == LL_Y_ARROW ||
+         mHighlightedPart == LL_Z_ARROW ||
+         mHighlightedPart == LL_YZ_PLANE ||
+         mHighlightedPart == LL_XZ_PLANE ||
+         mHighlightedPart == LL_XY_PLANE ) )
+    {
+        handled = handleMouseDownOnPart( x, y, mask );
+    }
+
+    return handled;
 }
 
 // Assumes that one of the arrows on an object was hit.
 BOOL LLManipTranslate::handleMouseDownOnPart( S32 x, S32 y, MASK mask )
 {
-	BOOL can_move = canAffectSelection();
-	if (!can_move)
-	{
-		return FALSE;
-	}
-
-	highlightManipulators(x, y);
-	S32 hit_part = mHighlightedPart;
-
-	if( (hit_part != LL_X_ARROW) && 
-		(hit_part != LL_Y_ARROW) &&
-		(hit_part != LL_Z_ARROW) &&
-		(hit_part != LL_YZ_PLANE) &&
-		(hit_part != LL_XZ_PLANE) &&
-		(hit_part != LL_XY_PLANE) )
-	{
-		return TRUE;
-	}
-
-	mHelpTextTimer.reset();
-	sNumTimesHelpTextShown++;
-
-	LLSelectMgr::getInstance()->getGrid(mGridOrigin, mGridRotation, mGridScale);
-
-	LLSelectMgr::getInstance()->enableSilhouette(FALSE);
-
-	// we just started a drag, so save initial object positions
-	LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_MOVE);
-
-	mManipPart = (EManipPart)hit_part;
-	mMouseDownX = x;
-	mMouseDownY = y;
-	mMouseOutsideSlop = FALSE;
-
-	LLVector3		axis;
-
-	LLSelectNode *selectNode = mObjectSelection->getFirstMoveableNode(TRUE);
-
-	if (!selectNode)
-	{
-		// didn't find the object in our selection...oh well
-		LL_WARNS() << "Trying to translate an unselected object" << LL_ENDL;
-		return TRUE;
-	}
-
-	LLViewerObject *selected_object = selectNode->getObject();
-	if (!selected_object)
-	{
-		// somehow we lost the object!
-		LL_WARNS() << "Translate manip lost the object, no selected object" << LL_ENDL;
-		gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
-		return TRUE;
-	}
-
-	// Compute unit vectors for arrow hit and a plane through that vector
-	BOOL axis_exists = getManipAxis(selected_object, mManipPart, axis);
-	getManipNormal(selected_object, mManipPart, mManipNormal);
-
-	//LLVector3 select_center_agent = gAgent.getPosAgentFromGlobal(LLSelectMgr::getInstance()->getSelectionCenterGlobal());
-	// TomY: The above should (?) be identical to the below
-	LLVector3 select_center_agent = getPivotPoint();
-	mSubdivisions = getSubdivisionLevel(select_center_agent, axis_exists ? axis : LLVector3::z_axis, getMinGridScale());
-
-	// if we clicked on a planar manipulator, recenter mouse cursor
-	if (mManipPart >= LL_YZ_PLANE && mManipPart <= LL_XY_PLANE)
-	{
-		LLCoordGL mouse_pos;
-		if (!LLViewerCamera::getInstance()->projectPosAgentToScreen(select_center_agent, mouse_pos))
-		{
-			// mouse_pos may be nonsense
-			LL_WARNS() << "Failed to project object center to screen" << LL_ENDL;
-		}
-		else if (gSavedSettings.getBOOL("SnapToMouseCursor"))
-		{
-			LLUI::setMousePositionScreen(mouse_pos.mX, mouse_pos.mY);
-			x = mouse_pos.mX;
-			y = mouse_pos.mY;
-		}
-	}
-
-	LLSelectMgr::getInstance()->updateSelectionCenter();
-	LLVector3d object_start_global = gAgent.getPosGlobalFromAgent(getPivotPoint());
-	getMousePointOnPlaneGlobal(mDragCursorStartGlobal, x, y, object_start_global, mManipNormal);
-	mDragSelectionStartGlobal = object_start_global;
-	mCopyMadeThisDrag = FALSE;
-
-	// Route future Mouse messages here preemptively.  (Release on mouse up.)
-	setMouseCapture( TRUE );
-
-	return TRUE;
+    BOOL can_move = canAffectSelection();
+    if (!can_move)
+    {
+        return FALSE;
+    }
+
+    highlightManipulators(x, y);
+    S32 hit_part = mHighlightedPart;
+
+    if( (hit_part != LL_X_ARROW) &&
+        (hit_part != LL_Y_ARROW) &&
+        (hit_part != LL_Z_ARROW) &&
+        (hit_part != LL_YZ_PLANE) &&
+        (hit_part != LL_XZ_PLANE) &&
+        (hit_part != LL_XY_PLANE) )
+    {
+        return TRUE;
+    }
+
+    mHelpTextTimer.reset();
+    sNumTimesHelpTextShown++;
+
+    LLSelectMgr::getInstance()->getGrid(mGridOrigin, mGridRotation, mGridScale);
+
+    LLSelectMgr::getInstance()->enableSilhouette(FALSE);
+
+    // we just started a drag, so save initial object positions
+    LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_MOVE);
+
+    mManipPart = (EManipPart)hit_part;
+    mMouseDownX = x;
+    mMouseDownY = y;
+    mMouseOutsideSlop = FALSE;
+
+    LLVector3       axis;
+
+    LLSelectNode *selectNode = mObjectSelection->getFirstMoveableNode(TRUE);
+
+    if (!selectNode)
+    {
+        // didn't find the object in our selection...oh well
+        LL_WARNS() << "Trying to translate an unselected object" << LL_ENDL;
+        return TRUE;
+    }
+
+    LLViewerObject *selected_object = selectNode->getObject();
+    if (!selected_object)
+    {
+        // somehow we lost the object!
+        LL_WARNS() << "Translate manip lost the object, no selected object" << LL_ENDL;
+        gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
+        return TRUE;
+    }
+
+    // Compute unit vectors for arrow hit and a plane through that vector
+    BOOL axis_exists = getManipAxis(selected_object, mManipPart, axis);
+    getManipNormal(selected_object, mManipPart, mManipNormal);
+
+    //LLVector3 select_center_agent = gAgent.getPosAgentFromGlobal(LLSelectMgr::getInstance()->getSelectionCenterGlobal());
+    // TomY: The above should (?) be identical to the below
+    LLVector3 select_center_agent = getPivotPoint();
+    mSubdivisions = getSubdivisionLevel(select_center_agent, axis_exists ? axis : LLVector3::z_axis, getMinGridScale());
+
+    // if we clicked on a planar manipulator, recenter mouse cursor
+    if (mManipPart >= LL_YZ_PLANE && mManipPart <= LL_XY_PLANE)
+    {
+        LLCoordGL mouse_pos;
+        if (!LLViewerCamera::getInstance()->projectPosAgentToScreen(select_center_agent, mouse_pos))
+        {
+            // mouse_pos may be nonsense
+            LL_WARNS() << "Failed to project object center to screen" << LL_ENDL;
+        }
+        else if (gSavedSettings.getBOOL("SnapToMouseCursor"))
+        {
+            LLUI::setMousePositionScreen(mouse_pos.mX, mouse_pos.mY);
+            x = mouse_pos.mX;
+            y = mouse_pos.mY;
+        }
+    }
+
+    LLSelectMgr::getInstance()->updateSelectionCenter();
+    LLVector3d object_start_global = gAgent.getPosGlobalFromAgent(getPivotPoint());
+    getMousePointOnPlaneGlobal(mDragCursorStartGlobal, x, y, object_start_global, mManipNormal);
+    mDragSelectionStartGlobal = object_start_global;
+    mCopyMadeThisDrag = FALSE;
+
+    // Route future Mouse messages here preemptively.  (Release on mouse up.)
+    setMouseCapture( TRUE );
+
+    return TRUE;
 }
 
 BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask)
 {
-	// Translation tool only works if mouse button is down.
-	// Bail out if mouse not down.
-	if( !hasMouseCapture() )
-	{
+    // Translation tool only works if mouse button is down.
+    // Bail out if mouse not down.
+    if( !hasMouseCapture() )
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (inactive)" << LL_ENDL;	
+        LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (inactive)" << LL_ENDL;
 #endif
-		// Always show cursor
-		// gViewerWindow->setCursor(UI_CURSOR_ARROW);
-		gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
-
-		highlightManipulators(x, y);
-		return TRUE;
-	}
-	
-	// Handle auto-rotation if necessary.
-	LLRect world_rect = gViewerWindow->getWorldViewRectScaled();
-	const F32 ROTATE_ANGLE_PER_SECOND = 30.f * DEG_TO_RAD;
-	const S32 ROTATE_H_MARGIN = world_rect.getWidth() / 20;
-	const F32 rotate_angle = ROTATE_ANGLE_PER_SECOND / gFPSClamped;
-	BOOL rotated = FALSE;
-
-	// ...build mode moves camera about focus point
-	if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
-	{
-		if (x < ROTATE_H_MARGIN)
-		{
-			gAgentCamera.cameraOrbitAround(rotate_angle);
-			rotated = TRUE;
-		}
-		else if (x > world_rect.getWidth() - ROTATE_H_MARGIN)
-		{
-			gAgentCamera.cameraOrbitAround(-rotate_angle);
-			rotated = TRUE;
-		}
-	}
-
-	// Suppress processing if mouse hasn't actually moved.
-	// This may cause problems if the camera moves outside of the
-	// rotation above.
-	if( x == mLastHoverMouseX && y == mLastHoverMouseY && !rotated)
-	{
+        // Always show cursor
+        // gViewerWindow->setCursor(UI_CURSOR_ARROW);
+        gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
+
+        highlightManipulators(x, y);
+        return TRUE;
+    }
+
+    // Handle auto-rotation if necessary.
+    LLRect world_rect = gViewerWindow->getWorldViewRectScaled();
+    const F32 ROTATE_ANGLE_PER_SECOND = 30.f * DEG_TO_RAD;
+    const S32 ROTATE_H_MARGIN = world_rect.getWidth() / 20;
+    const F32 rotate_angle = ROTATE_ANGLE_PER_SECOND / gFPSClamped;
+    BOOL rotated = FALSE;
+
+    // ...build mode moves camera about focus point
+    if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
+    {
+        if (x < ROTATE_H_MARGIN)
+        {
+            gAgentCamera.cameraOrbitAround(rotate_angle);
+            rotated = TRUE;
+        }
+        else if (x > world_rect.getWidth() - ROTATE_H_MARGIN)
+        {
+            gAgentCamera.cameraOrbitAround(-rotate_angle);
+            rotated = TRUE;
+        }
+    }
+
+    // Suppress processing if mouse hasn't actually moved.
+    // This may cause problems if the camera moves outside of the
+    // rotation above.
+    if( x == mLastHoverMouseX && y == mLastHoverMouseY && !rotated)
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (mouse unmoved)" << LL_ENDL;
+        LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (mouse unmoved)" << LL_ENDL;
 #endif
-		gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
-		return TRUE;
-	}
-	mLastHoverMouseX = x;
-	mLastHoverMouseY = y;
-
-	// Suppress if mouse hasn't moved past the initial slop region
-	// Reset once we start moving
-	if( !mMouseOutsideSlop )
-	{
-		if (abs(mMouseDownX - x) < MOUSE_DRAG_SLOP && abs(mMouseDownY - y) < MOUSE_DRAG_SLOP )
-		{
+        gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
+        return TRUE;
+    }
+    mLastHoverMouseX = x;
+    mLastHoverMouseY = y;
+
+    // Suppress if mouse hasn't moved past the initial slop region
+    // Reset once we start moving
+    if( !mMouseOutsideSlop )
+    {
+        if (abs(mMouseDownX - x) < MOUSE_DRAG_SLOP && abs(mMouseDownY - y) < MOUSE_DRAG_SLOP )
+        {
 #ifdef SHOW_DEBUG
-			LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (mouse inside slop)" << LL_ENDL;
+            LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (mouse inside slop)" << LL_ENDL;
 #endif
-			gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
-			return TRUE;
-		}
-		else
-		{
-			// ...just went outside the slop region
-			mMouseOutsideSlop = TRUE;
-			// If holding down shift, leave behind a copy.
-			if (mask == MASK_COPY)
-			{
-				// ...we're trying to make a copy
-				LLSelectMgr::getInstance()->selectDuplicate(LLVector3::zero, FALSE);
-				mCopyMadeThisDrag = TRUE;
-
-				// When we make the copy, we don't want to do any other processing.
-				// If so, the object will also be moved, and the copy will be offset.
+            gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
+            return TRUE;
+        }
+        else
+        {
+            // ...just went outside the slop region
+            mMouseOutsideSlop = TRUE;
+            // If holding down shift, leave behind a copy.
+            if (mask == MASK_COPY)
+            {
+                // ...we're trying to make a copy
+                LLSelectMgr::getInstance()->selectDuplicate(LLVector3::zero, FALSE);
+                mCopyMadeThisDrag = TRUE;
+
+                // When we make the copy, we don't want to do any other processing.
+                // If so, the object will also be moved, and the copy will be offset.
 #ifdef SHOW_DEBUG
-				LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (made copy)" << LL_ENDL;
+                LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (made copy)" << LL_ENDL;
 #endif
-				gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
-			}
-		}
-	}
-
-	// Throttle updates to 10 per second.
-
-	LLVector3		axis_f;
-	LLVector3d		axis_d;
-
-	// pick the first object to constrain to grid w/ common origin
-	// this is so we don't screw up groups
-	LLSelectNode* selectNode = mObjectSelection->getFirstMoveableNode(TRUE);
-	if (!selectNode)
-	{
-		// somehow we lost the object!
-		LL_WARNS() << "Translate manip lost the object, no selectNode" << LL_ENDL;
-		gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
-		return TRUE;
-	}
-
-	LLViewerObject* object = selectNode->getObject();
-	if (!object)
-	{
-		// somehow we lost the object!
-		LL_WARNS() << "Translate manip lost the object, no object in selectNode" << LL_ENDL;
-		gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
-		return TRUE;
-	}
-
-	// Compute unit vectors for arrow hit and a plane through that vector
-	BOOL axis_exists = getManipAxis(object, mManipPart, axis_f);		// TODO: move this
-
-	axis_d.setVec(axis_f);
-
-	LLSelectMgr::getInstance()->updateSelectionCenter();
-	LLVector3d current_pos_global = gAgent.getPosGlobalFromAgent(getPivotPoint());
-
-	mSubdivisions = getSubdivisionLevel(getPivotPoint(), axis_f, getMinGridScale());
-
-	// Project the cursor onto that plane
-	LLVector3d relative_move;
-	getMousePointOnPlaneGlobal(relative_move, x, y, current_pos_global, mManipNormal);\
-	relative_move -= mDragCursorStartGlobal;
-
-	// You can't move more than some distance from your original mousedown point.
-	if (gSavedSettings.getBOOL("LimitDragDistance"))
-	{
-		F32 max_drag_distance = gSavedSettings.getF32("MaxDragDistance");
-
-		if (relative_move.magVecSquared() > max_drag_distance * max_drag_distance)
-		{
-			LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (too far)" << LL_ENDL;
-			gViewerWindow->setCursor(UI_CURSOR_NOLOCKED);
-			return TRUE;
-		}
-	}
-
-	F64 axis_magnitude = relative_move * axis_d;					// dot product
-	LLVector3d cursor_point_snap_line;
-	
-	F64 off_axis_magnitude;
-
-	getMousePointOnPlaneGlobal(cursor_point_snap_line, x, y, current_pos_global, mSnapOffsetAxis % axis_f);
-	off_axis_magnitude = axis_exists ? llabs((cursor_point_snap_line - current_pos_global) * LLVector3d(mSnapOffsetAxis)) : 0.f;
-
-	if (ALControlCache::SnapEnabled)
-	{
-		if (off_axis_magnitude > mSnapOffsetMeters)
-		{
-			mInSnapRegime = TRUE;
-			LLVector3 cursor_snap_agent = gAgent.getPosAgentFromGlobal(cursor_point_snap_line);
-
-			F32 cursor_grid_dist = (cursor_snap_agent - mGridOrigin) * axis_f;
-			
-			F32 snap_dist = getMinGridScale() / (2.f * mSubdivisions);
-			F32 relative_snap_dist = fmodf(llabs(cursor_grid_dist) + snap_dist, getMinGridScale() / mSubdivisions);
-			if (relative_snap_dist < snap_dist * 2.f)
-			{
-				if (cursor_grid_dist > 0.f)
-				{
-					cursor_grid_dist -= relative_snap_dist - snap_dist;
-				}
-				else
-				{
-					cursor_grid_dist += relative_snap_dist - snap_dist;
-				}
-			}
-
-			F32 object_start_on_axis = (gAgent.getPosAgentFromGlobal(mDragSelectionStartGlobal) - mGridOrigin) * axis_f;
-			axis_magnitude = cursor_grid_dist - object_start_on_axis;
-		}
-		else if (mManipPart >= LL_YZ_PLANE && mManipPart <= LL_XY_PLANE)
-		{
-			// subtract offset from object center
-			LLVector3d cursor_point_global;
-			getMousePointOnPlaneGlobal( cursor_point_global, x, y, current_pos_global, mManipNormal );
-			cursor_point_global -= (mDragCursorStartGlobal - mDragSelectionStartGlobal);
-
-			// snap to planar grid
-			LLVector3 cursor_point_agent = gAgent.getPosAgentFromGlobal(cursor_point_global);
-			LLVector3 camera_plane_projection = LLViewerCamera::getInstance()->getAtAxis();
-			camera_plane_projection -= projected_vec(camera_plane_projection, mManipNormal);
-			camera_plane_projection.normVec();
-			LLVector3 camera_projected_dir = camera_plane_projection;
-			camera_plane_projection.rotVec(~mGridRotation);
-			camera_plane_projection.scaleVec(mGridScale);
-			camera_plane_projection.abs();
-			F32 max_grid_scale;
-			if (camera_plane_projection.mV[VX] > camera_plane_projection.mV[VY] &&
-				camera_plane_projection.mV[VX] > camera_plane_projection.mV[VZ])
-			{
-				max_grid_scale = mGridScale.mV[VX];
-			}
-			else if (camera_plane_projection.mV[VY] > camera_plane_projection.mV[VZ])
-			{
-				max_grid_scale = mGridScale.mV[VY];
-			}
-			else
-			{
-				max_grid_scale = mGridScale.mV[VZ];
-			}
-
-			F32 num_subdivisions = getSubdivisionLevel(getPivotPoint(), camera_projected_dir, max_grid_scale);
-
-			F32 grid_scale_a;
-			F32 grid_scale_b;
-			LLVector3 cursor_point_grid = (cursor_point_agent - mGridOrigin) * ~mGridRotation;
-
-			switch (mManipPart)
-			{
-			case LL_YZ_PLANE:
-				grid_scale_a = mGridScale.mV[VY] / num_subdivisions;
-				grid_scale_b = mGridScale.mV[VZ] / num_subdivisions;
-				cursor_point_grid.mV[VY] -= fmod(cursor_point_grid.mV[VY] + grid_scale_a * 0.5f, grid_scale_a) - grid_scale_a * 0.5f;
-				cursor_point_grid.mV[VZ] -= fmod(cursor_point_grid.mV[VZ] + grid_scale_b * 0.5f, grid_scale_b) - grid_scale_b * 0.5f;
-				break;
-			case LL_XZ_PLANE:
-				grid_scale_a = mGridScale.mV[VX] / num_subdivisions;
-				grid_scale_b = mGridScale.mV[VZ] / num_subdivisions;
-				cursor_point_grid.mV[VX] -= fmod(cursor_point_grid.mV[VX] + grid_scale_a * 0.5f, grid_scale_a) - grid_scale_a * 0.5f;
-				cursor_point_grid.mV[VZ] -= fmod(cursor_point_grid.mV[VZ] + grid_scale_b * 0.5f, grid_scale_b) - grid_scale_b * 0.5f;
-				break;
-			case LL_XY_PLANE:
-				grid_scale_a = mGridScale.mV[VX] / num_subdivisions;
-				grid_scale_b = mGridScale.mV[VY] / num_subdivisions;
-				cursor_point_grid.mV[VX] -= fmod(cursor_point_grid.mV[VX] + grid_scale_a * 0.5f, grid_scale_a) - grid_scale_a * 0.5f;
-				cursor_point_grid.mV[VY] -= fmod(cursor_point_grid.mV[VY] + grid_scale_b * 0.5f, grid_scale_b) - grid_scale_b * 0.5f;
-				break;
-			default:
-				break;
-			}
-			cursor_point_agent = (cursor_point_grid * mGridRotation) + mGridOrigin;
-			relative_move.setVec(cursor_point_agent - gAgent.getPosAgentFromGlobal(mDragSelectionStartGlobal));
-			mInSnapRegime = TRUE;
-		}
-		else
-		{
-			mInSnapRegime = FALSE;
-		}
-	}
-	else
-	{
-		mInSnapRegime = FALSE;
-	}
-
-	// Clamp to arrow direction
-	// *FIX: does this apply anymore?
-	if (!axis_exists)
-	{
-		axis_magnitude = relative_move.normVec();
-		axis_d.setVec(relative_move);
-		axis_d.normVec();
-		axis_f.setVec(axis_d);
-	}
-
-	LLVector3d clamped_relative_move = axis_magnitude * axis_d;	// scalar multiply
-	LLVector3 clamped_relative_move_f = (F32)axis_magnitude * axis_f; // scalar multiply
-	
+                gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
+            }
+        }
+    }
+
+    // Throttle updates to 10 per second.
+
+    LLVector3       axis_f;
+    LLVector3d      axis_d;
+
+    // pick the first object to constrain to grid w/ common origin
+    // this is so we don't screw up groups
+    LLSelectNode* selectNode = mObjectSelection->getFirstMoveableNode(TRUE);
+    if (!selectNode)
+    {
+        // somehow we lost the object!
+        LL_WARNS() << "Translate manip lost the object, no selectNode" << LL_ENDL;
+        gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
+        return TRUE;
+    }
+
+    LLViewerObject* object = selectNode->getObject();
+    if (!object)
+    {
+        // somehow we lost the object!
+        LL_WARNS() << "Translate manip lost the object, no object in selectNode" << LL_ENDL;
+        gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
+        return TRUE;
+    }
+
+    // Compute unit vectors for arrow hit and a plane through that vector
+    BOOL axis_exists = getManipAxis(object, mManipPart, axis_f);        // TODO: move this
+
+    axis_d.setVec(axis_f);
+
+    LLSelectMgr::getInstance()->updateSelectionCenter();
+    LLVector3d current_pos_global = gAgent.getPosGlobalFromAgent(getPivotPoint());
+
+    mSubdivisions = getSubdivisionLevel(getPivotPoint(), axis_f, getMinGridScale());
+
+    // Project the cursor onto that plane
+    LLVector3d relative_move;
+    getMousePointOnPlaneGlobal(relative_move, x, y, current_pos_global, mManipNormal);\
+    relative_move -= mDragCursorStartGlobal;
+
+    // You can't move more than some distance from your original mousedown point.
+    if (gSavedSettings.getBOOL("LimitDragDistance"))
+    {
+        F32 max_drag_distance = gSavedSettings.getF32("MaxDragDistance");
+
+        if (relative_move.magVecSquared() > max_drag_distance * max_drag_distance)
+        {
+            LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (too far)" << LL_ENDL;
+            gViewerWindow->setCursor(UI_CURSOR_NOLOCKED);
+            return TRUE;
+        }
+    }
+
+    F64 axis_magnitude = relative_move * axis_d;                    // dot product
+    LLVector3d cursor_point_snap_line;
+
+    F64 off_axis_magnitude;
+
+    getMousePointOnPlaneGlobal(cursor_point_snap_line, x, y, current_pos_global, mSnapOffsetAxis % axis_f);
+    off_axis_magnitude = axis_exists ? llabs((cursor_point_snap_line - current_pos_global) * LLVector3d(mSnapOffsetAxis)) : 0.f;
+
+    if (ALControlCache::SnapEnabled)
+    {
+        if (off_axis_magnitude > mSnapOffsetMeters)
+        {
+            mInSnapRegime = TRUE;
+            LLVector3 cursor_snap_agent = gAgent.getPosAgentFromGlobal(cursor_point_snap_line);
+
+            F32 cursor_grid_dist = (cursor_snap_agent - mGridOrigin) * axis_f;
+
+            F32 snap_dist = getMinGridScale() / (2.f * mSubdivisions);
+            F32 relative_snap_dist = fmodf(llabs(cursor_grid_dist) + snap_dist, getMinGridScale() / mSubdivisions);
+            if (relative_snap_dist < snap_dist * 2.f)
+            {
+                if (cursor_grid_dist > 0.f)
+                {
+                    cursor_grid_dist -= relative_snap_dist - snap_dist;
+                }
+                else
+                {
+                    cursor_grid_dist += relative_snap_dist - snap_dist;
+                }
+            }
+
+            F32 object_start_on_axis = (gAgent.getPosAgentFromGlobal(mDragSelectionStartGlobal) - mGridOrigin) * axis_f;
+            axis_magnitude = cursor_grid_dist - object_start_on_axis;
+        }
+        else if (mManipPart >= LL_YZ_PLANE && mManipPart <= LL_XY_PLANE)
+        {
+            // subtract offset from object center
+            LLVector3d cursor_point_global;
+            getMousePointOnPlaneGlobal( cursor_point_global, x, y, current_pos_global, mManipNormal );
+            cursor_point_global -= (mDragCursorStartGlobal - mDragSelectionStartGlobal);
+
+            // snap to planar grid
+            LLVector3 cursor_point_agent = gAgent.getPosAgentFromGlobal(cursor_point_global);
+            LLVector3 camera_plane_projection = LLViewerCamera::getInstance()->getAtAxis();
+            camera_plane_projection -= projected_vec(camera_plane_projection, mManipNormal);
+            camera_plane_projection.normVec();
+            LLVector3 camera_projected_dir = camera_plane_projection;
+            camera_plane_projection.rotVec(~mGridRotation);
+            camera_plane_projection.scaleVec(mGridScale);
+            camera_plane_projection.abs();
+            F32 max_grid_scale;
+            if (camera_plane_projection.mV[VX] > camera_plane_projection.mV[VY] &&
+                camera_plane_projection.mV[VX] > camera_plane_projection.mV[VZ])
+            {
+                max_grid_scale = mGridScale.mV[VX];
+            }
+            else if (camera_plane_projection.mV[VY] > camera_plane_projection.mV[VZ])
+            {
+                max_grid_scale = mGridScale.mV[VY];
+            }
+            else
+            {
+                max_grid_scale = mGridScale.mV[VZ];
+            }
+
+            F32 num_subdivisions = getSubdivisionLevel(getPivotPoint(), camera_projected_dir, max_grid_scale);
+
+            F32 grid_scale_a;
+            F32 grid_scale_b;
+            LLVector3 cursor_point_grid = (cursor_point_agent - mGridOrigin) * ~mGridRotation;
+
+            switch (mManipPart)
+            {
+            case LL_YZ_PLANE:
+                grid_scale_a = mGridScale.mV[VY] / num_subdivisions;
+                grid_scale_b = mGridScale.mV[VZ] / num_subdivisions;
+                cursor_point_grid.mV[VY] -= fmod(cursor_point_grid.mV[VY] + grid_scale_a * 0.5f, grid_scale_a) - grid_scale_a * 0.5f;
+                cursor_point_grid.mV[VZ] -= fmod(cursor_point_grid.mV[VZ] + grid_scale_b * 0.5f, grid_scale_b) - grid_scale_b * 0.5f;
+                break;
+            case LL_XZ_PLANE:
+                grid_scale_a = mGridScale.mV[VX] / num_subdivisions;
+                grid_scale_b = mGridScale.mV[VZ] / num_subdivisions;
+                cursor_point_grid.mV[VX] -= fmod(cursor_point_grid.mV[VX] + grid_scale_a * 0.5f, grid_scale_a) - grid_scale_a * 0.5f;
+                cursor_point_grid.mV[VZ] -= fmod(cursor_point_grid.mV[VZ] + grid_scale_b * 0.5f, grid_scale_b) - grid_scale_b * 0.5f;
+                break;
+            case LL_XY_PLANE:
+                grid_scale_a = mGridScale.mV[VX] / num_subdivisions;
+                grid_scale_b = mGridScale.mV[VY] / num_subdivisions;
+                cursor_point_grid.mV[VX] -= fmod(cursor_point_grid.mV[VX] + grid_scale_a * 0.5f, grid_scale_a) - grid_scale_a * 0.5f;
+                cursor_point_grid.mV[VY] -= fmod(cursor_point_grid.mV[VY] + grid_scale_b * 0.5f, grid_scale_b) - grid_scale_b * 0.5f;
+                break;
+            default:
+                break;
+            }
+            cursor_point_agent = (cursor_point_grid * mGridRotation) + mGridOrigin;
+            relative_move.setVec(cursor_point_agent - gAgent.getPosAgentFromGlobal(mDragSelectionStartGlobal));
+            mInSnapRegime = TRUE;
+        }
+        else
+        {
+            mInSnapRegime = FALSE;
+        }
+    }
+    else
+    {
+        mInSnapRegime = FALSE;
+    }
+
+    // Clamp to arrow direction
+    // *FIX: does this apply anymore?
+    if (!axis_exists)
+    {
+        axis_magnitude = relative_move.normVec();
+        axis_d.setVec(relative_move);
+        axis_d.normVec();
+        axis_f.setVec(axis_d);
+    }
+
+    LLVector3d clamped_relative_move = axis_magnitude * axis_d; // scalar multiply
+    LLVector3 clamped_relative_move_f = (F32)axis_magnitude * axis_f; // scalar multiply
+
     for (LLObjectSelection::iterator iter = mObjectSelection->begin();
         iter != mObjectSelection->end(); iter++)
     {
@@ -733,28 +733,28 @@ BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask)
                     LLVector3d new_position_global = selectNode->mSavedPositionGlobal + clamped_relative_move;
 
                     // Don't let object centers go too far underground
-				LLWorld* world_inst = LLWorld::getInstance();
-				F64 min_height = world_inst->getMinAllowedZ(object, object->getPositionGlobal());
+                LLWorld* world_inst = LLWorld::getInstance();
+                F64 min_height = world_inst->getMinAllowedZ(object, object->getPositionGlobal());
                     if (new_position_global.mdV[VZ] < min_height)
                     {
                         new_position_global.mdV[VZ] = min_height;
                     }
 
                     // For safety, cap heights where objects can be dragged
-				if (new_position_global.mdV[VZ] > LLWorld::getInstance()->getRegionMaxHeight())
+                if (new_position_global.mdV[VZ] > LLWorld::getInstance()->getRegionMaxHeight())
                     {
-					new_position_global.mdV[VZ] = LLWorld::getInstance()->getRegionMaxHeight();
+                    new_position_global.mdV[VZ] = LLWorld::getInstance()->getRegionMaxHeight();
                     }
 
                     // Grass is always drawn on the ground, so clamp its position to the ground
                     if (object->getPCode() == LL_PCODE_LEGACY_GRASS)
                     {
-					new_position_global.mdV[VZ] = world_inst->resolveLandHeightGlobal(new_position_global) + 1.f;
+                    new_position_global.mdV[VZ] = world_inst->resolveLandHeightGlobal(new_position_global) + 1.f;
                     }
 
                     if (object->isRootEdit())
                     {
-					new_position_global = world_inst->clipToVisibleRegions(object->getPositionGlobal(), new_position_global);
+                    new_position_global = world_inst->clipToVisibleRegions(object->getPositionGlobal(), new_position_global);
                     }
 
                     // PR: Only update if changed
@@ -787,1536 +787,1536 @@ BOOL LLManipTranslate::handleHover(S32 x, S32 y, MASK mask)
     }
 
 
-	LLSelectMgr::getInstance()->updateSelectionCenter();
-	gAgentCamera.clearFocusObject();
-	dialog_refresh_all();		// ??? is this necessary?
+    LLSelectMgr::getInstance()->updateSelectionCenter();
+    gAgentCamera.clearFocusObject();
+    dialog_refresh_all();       // ??? is this necessary?
 
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (active)" << LL_ENDL;
+    LL_DEBUGS("UserInput") << "hover handled by LLManipTranslate (active)" << LL_ENDL;
 #endif
-	gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
-	return TRUE;
+    gViewerWindow->setCursor(UI_CURSOR_TOOLTRANSLATE);
+    return TRUE;
 }
 
 void LLManipTranslate::highlightManipulators(S32 x, S32 y)
 {
-	mHighlightedPart = LL_NO_PART;
-
-	if (!mObjectSelection->getObjectCount())
-	{
-		return;
-	}
-	
-	//LLBBox bbox = LLSelectMgr::getInstance()->getBBoxOfSelection();
-	LLMatrix4 projMatrix( LLViewerCamera::getInstance()->getProjection().getF32ptr() );
-	LLMatrix4 modelView( LLViewerCamera::getInstance()->getModelview().getF32ptr() );
-
-	LLVector3 object_position = getPivotPoint();
-	
-	LLVector3 grid_origin;
-	LLVector3 grid_scale;
-	LLQuaternion grid_rotation;
-
-	LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
-
-	LLVector3 relative_camera_dir;
-
-	LLMatrix4 transform;
-
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		relative_camera_dir = LLVector3(1.f, 0.f, 0.f) * ~grid_rotation;
-		LLVector4 translation(object_position);
-		transform.initRotTrans(grid_rotation, translation);
-		LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
-		transform *= cfr;
-		LLMatrix4 window_scale;
-		F32 zoom_level = 2.f * gAgentCamera.mHUDCurZoom;
-		window_scale.initAll(LLVector3(zoom_level / LLViewerCamera::getInstance()->getAspect(), zoom_level, 0.f),
-			LLQuaternion::DEFAULT,
-			LLVector3::zero);
-		transform *= window_scale;
-	}
-	else
-	{
-		relative_camera_dir = (object_position - LLViewerCamera::getInstance()->getOrigin()) * ~grid_rotation;
-		relative_camera_dir.normVec();
-
-		transform.initRotTrans(grid_rotation, LLVector4(object_position));
-		transform *= modelView;
-		transform *= projMatrix;
-	}
-		
-	S32 numManips = 0;
-
-	// edges
-	mManipulatorVertices[numManips++] = LLVector4(mArrowLengthMeters * MANIPULATOR_HOTSPOT_START, 0.f, 0.f, 1.f);
-	mManipulatorVertices[numManips++] = LLVector4(mArrowLengthMeters * MANIPULATOR_HOTSPOT_END, 0.f, 0.f, 1.f);
-
-	mManipulatorVertices[numManips++] = LLVector4(0.f, mArrowLengthMeters * MANIPULATOR_HOTSPOT_START, 0.f, 1.f);
-	mManipulatorVertices[numManips++] = LLVector4(0.f, mArrowLengthMeters * MANIPULATOR_HOTSPOT_END, 0.f, 1.f);
-
-	mManipulatorVertices[numManips++] = LLVector4(0.f, 0.f, mArrowLengthMeters * MANIPULATOR_HOTSPOT_START, 1.f);
-	mManipulatorVertices[numManips++] = LLVector4(0.f, 0.f, mArrowLengthMeters * MANIPULATOR_HOTSPOT_END, 1.f);
-
-	mManipulatorVertices[numManips++] = LLVector4(mArrowLengthMeters * -MANIPULATOR_HOTSPOT_START, 0.f, 0.f, 1.f);
-	mManipulatorVertices[numManips++] = LLVector4(mArrowLengthMeters * -MANIPULATOR_HOTSPOT_END, 0.f, 0.f, 1.f);
-
-	mManipulatorVertices[numManips++] = LLVector4(0.f, mArrowLengthMeters * -MANIPULATOR_HOTSPOT_START, 0.f, 1.f);
-	mManipulatorVertices[numManips++] = LLVector4(0.f, mArrowLengthMeters * -MANIPULATOR_HOTSPOT_END, 0.f, 1.f);
-
-	mManipulatorVertices[numManips++] = LLVector4(0.f, 0.f, mArrowLengthMeters * -MANIPULATOR_HOTSPOT_START, 1.f);
-	mManipulatorVertices[numManips++] = LLVector4(0.f, 0.f, mArrowLengthMeters * -MANIPULATOR_HOTSPOT_END, 1.f);
-
-	S32 num_arrow_manips = numManips;
-
-	// planar manipulators
-	BOOL planar_manip_yz_visible = FALSE;
-	BOOL planar_manip_xz_visible = FALSE;
-	BOOL planar_manip_xy_visible = FALSE;
-
-	mManipulatorVertices[numManips] = LLVector4(0.f, mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), 1.f);
-	mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
-	mManipulatorVertices[numManips] = LLVector4(0.f, mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), 1.f);
-	mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
-	if (llabs(relative_camera_dir.mV[VX]) > MIN_PLANE_MANIP_DOT_PRODUCT)
-	{
-		planar_manip_yz_visible = TRUE;
-	}
-
-	mManipulatorVertices[numManips] = LLVector4(mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), 0.f, mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), 1.f);
-	mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
-	mManipulatorVertices[numManips] = LLVector4(mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), 0.f, mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), 1.f);
-	mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
-	if (llabs(relative_camera_dir.mV[VY]) > MIN_PLANE_MANIP_DOT_PRODUCT)
-	{
-		planar_manip_xz_visible = TRUE;
-	}
-
-	mManipulatorVertices[numManips] = LLVector4(mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), 0.f, 1.f);
-	mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
-	mManipulatorVertices[numManips] = LLVector4(mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), 0.f, 1.f);
-	mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
-	if (llabs(relative_camera_dir.mV[VZ]) > MIN_PLANE_MANIP_DOT_PRODUCT)
-	{
-		planar_manip_xy_visible = TRUE;
-	}
-
-	// Project up to 9 manipulators to screen space 2*X, 2*Y, 2*Z, 3*planes
-	std::vector<ManipulatorHandle> projected_manipulators;
-	projected_manipulators.reserve(9);
-	
-	for (S32 i = 0; i < num_arrow_manips; i+= 2)
-	{
-		LLVector4 projected_start = mManipulatorVertices[i] * transform;
-		projected_start = projected_start * (1.f / projected_start.mV[VW]);
-
-		LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
-		projected_end = projected_end * (1.f / projected_end.mV[VW]);
-
-		ManipulatorHandle projected_manip(
-				LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), 
-				LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]), 
-				MANIPULATOR_IDS[i / 2],
-				10.f); // 10 pixel hotspot for arrows
-		projected_manipulators.push_back(projected_manip);
-	}
-
-	if (planar_manip_yz_visible)
-	{
-		S32 i = num_arrow_manips;
-		LLVector4 projected_start = mManipulatorVertices[i] * transform;
-		projected_start = projected_start * (1.f / projected_start.mV[VW]);
-
-		LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
-		projected_end = projected_end * (1.f / projected_end.mV[VW]);
-
-		ManipulatorHandle projected_manip(
-				LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), 
-				LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]), 
-				MANIPULATOR_IDS[i / 2],
-				20.f); // 20 pixels for planar manipulators
-		projected_manipulators.push_back(projected_manip);
-	}
-
-	if (planar_manip_xz_visible)
-	{
-		S32 i = num_arrow_manips + 2;
-		LLVector4 projected_start = mManipulatorVertices[i] * transform;
-		projected_start = projected_start * (1.f / projected_start.mV[VW]);
-
-		LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
-		projected_end = projected_end * (1.f / projected_end.mV[VW]);
-
-		ManipulatorHandle projected_manip(
-				LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), 
-				LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]), 
-				MANIPULATOR_IDS[i / 2],
-				20.f); // 20 pixels for planar manipulators
-		projected_manipulators.push_back(projected_manip);
-	}
-
-	if (planar_manip_xy_visible)
-	{
-		S32 i = num_arrow_manips + 4;
-		LLVector4 projected_start = mManipulatorVertices[i] * transform;
-		projected_start = projected_start * (1.f / projected_start.mV[VW]);
-
-		LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
-		projected_end = projected_end * (1.f / projected_end.mV[VW]);
-
-		ManipulatorHandle projected_manip(
-				LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]), 
-				LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]), 
-				MANIPULATOR_IDS[i / 2],
-				20.f); // 20 pixels for planar manipulators
-		projected_manipulators.push_back(projected_manip);
-	}
-
-	LLVector2 manip_start_2d;
-	LLVector2 manip_end_2d;
-	LLVector2 manip_dir;
-	LLRect world_view_rect = gViewerWindow->getWorldViewRectScaled();
-	F32 half_width = (F32)world_view_rect.getWidth() / 2.f;
-	F32 half_height = (F32)world_view_rect.getHeight() / 2.f;
-	LLVector2 mousePos((F32)x - half_width, (F32)y - half_height);
-	LLVector2 mouse_delta;
-
-	// Keep order consistent with insertion via stable_sort
-	std::stable_sort( projected_manipulators.begin(),
-		projected_manipulators.end(),
-		ClosestToCamera() );
-
-	std::vector<ManipulatorHandle>::iterator it = projected_manipulators.begin();
-	for ( ; it != projected_manipulators.end(); ++it)
-	{
-		ManipulatorHandle& manipulator = *it;
-		{
-			manip_start_2d.setVec(manipulator.mStartPosition.mV[VX] * half_width, manipulator.mStartPosition.mV[VY] * half_height);
-			manip_end_2d.setVec(manipulator.mEndPosition.mV[VX] * half_width, manipulator.mEndPosition.mV[VY] * half_height);
-			manip_dir = manip_end_2d - manip_start_2d;
-
-			mouse_delta = mousePos - manip_start_2d;
-
-			F32 manip_length = manip_dir.normVec();
-
-			F32 mouse_pos_manip = mouse_delta * manip_dir;
-			F32 mouse_dist_manip_squared = mouse_delta.magVecSquared() - (mouse_pos_manip * mouse_pos_manip);
-
-			if (mouse_pos_manip > 0.f &&
-				mouse_pos_manip < manip_length &&
-				mouse_dist_manip_squared < manipulator.mHotSpotRadius * manipulator.mHotSpotRadius)
-			{
-				mHighlightedPart = manipulator.mManipID;
-				break;
-			}
-		}
-	}
-}
+    mHighlightedPart = LL_NO_PART;
 
-F32 LLManipTranslate::getMinGridScale()
-{
-	F32 scale;
-	switch (mManipPart)
-	{
-	case LL_NO_PART:
-	default:
-		scale = 1.f;
-		break;
-	case LL_X_ARROW:
-		scale = mGridScale.mV[VX];
-		break;
-	case LL_Y_ARROW:
-		scale = mGridScale.mV[VY];
-		break;
-	case LL_Z_ARROW:
-		scale = mGridScale.mV[VZ];
-		break;
-	case LL_YZ_PLANE:
-		scale = llmin(mGridScale.mV[VY], mGridScale.mV[VZ]);
-		break;
-	case LL_XZ_PLANE:
-		scale = llmin(mGridScale.mV[VX], mGridScale.mV[VZ]);
-		break;
-	case LL_XY_PLANE:
-		scale = llmin(mGridScale.mV[VX], mGridScale.mV[VY]);
-		break;
-	}
-
-	return scale;
-}
+    if (!mObjectSelection->getObjectCount())
+    {
+        return;
+    }
 
+    //LLBBox bbox = LLSelectMgr::getInstance()->getBBoxOfSelection();
+    LLMatrix4 projMatrix( LLViewerCamera::getInstance()->getProjection().getF32ptr() );
+    LLMatrix4 modelView( LLViewerCamera::getInstance()->getModelview().getF32ptr() );
 
-BOOL LLManipTranslate::handleMouseUp(S32 x, S32 y, MASK mask)
-{
-	// first, perform normal processing in case this was a quick-click
-	handleHover(x, y, mask);
-
-	if(hasMouseCapture())
-	{
-		// make sure arrow colors go back to normal
-		mManipPart = LL_NO_PART;
-		LLSelectMgr::getInstance()->enableSilhouette(TRUE);
-
-		// Might have missed last update due to UPDATE_DELAY timing.
-		LLSelectMgr::getInstance()->sendMultipleUpdate( UPD_POSITION );
-		
-		mInSnapRegime = FALSE;
-		LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
-		//gAgent.setObjectTracking(gSavedSettings.getBOOL("TrackFocusObject"));
-	}
-
-	return LLManip::handleMouseUp(x, y, mask);
-}
+    LLVector3 object_position = getPivotPoint();
 
+    LLVector3 grid_origin;
+    LLVector3 grid_scale;
+    LLQuaternion grid_rotation;
 
-void LLManipTranslate::render()
-{
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		F32 zoom = gAgentCamera.mHUDCurZoom;
-		gGL.scalef(zoom, zoom, zoom);
-	}
-	{
-		LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
-		renderGuidelines();
-	}
-	{
-		//LLGLDisable gls_stencil(GL_STENCIL_TEST);
-		renderTranslationHandles();
-		renderSnapGuides();
-	}
-	gGL.popMatrix();
-
-	renderText();
-}
+    LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
 
-void LLManipTranslate::renderSnapGuides()
-{
-	if (!ALControlCache::SnapEnabled)
-	{
-		return;
-	}
-
-	F32 max_subdivisions = sGridMaxSubdivisionLevel;//(F32)gSavedSettings.getS32("GridSubdivision");
-	F32 line_alpha = ALControlCache::GridOpacity;
-
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	LLGLDepthTest gls_depth(GL_TRUE);
-	LLGLDisable gls_cull(GL_CULL_FACE);
-	LLVector3 translate_axis;
-
-	if (mManipPart == LL_NO_PART)
-	{
-		return;
-	}
-
-	LLSelectNode *first_node = mObjectSelection->getFirstMoveableNode(TRUE);
-	if (!first_node)
-	{
-		return;
-	}
-	
-	updateGridSettings();
-
-	F32 smallest_grid_unit_scale = getMinGridScale() / max_subdivisions;
-	LLVector3 grid_origin;
-	LLVector3 grid_scale;
-	LLQuaternion grid_rotation;
-
-	LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
-	LLVector3 saved_selection_center = getSavedPivotPoint(); //LLSelectMgr::getInstance()->getSavedBBoxOfSelection().getCenterAgent();
-	LLVector3 selection_center = getPivotPoint();
-
-	LLViewerObject *first_object = first_node->getObject();
-
-	//pick appropriate projection plane for snap rulers according to relative camera position
-	if (mManipPart >= LL_X_ARROW && mManipPart <= LL_Z_ARROW)
-	{
-		LLVector3 normal;
-		LLColor4 inner_color;
-		LLManip::EManipPart temp_manip = mManipPart;
-		switch (mManipPart)
-		{
-		case LL_X_ARROW:
-			normal.setVec(1,0,0);
-			inner_color.setVec(0,1,1,line_alpha);
-			mManipPart = LL_YZ_PLANE;
-			break;
-		case LL_Y_ARROW:
-			normal.setVec(0,1,0);
-			inner_color.setVec(1,0,1,line_alpha);
-			mManipPart = LL_XZ_PLANE;
-			break;
-		case LL_Z_ARROW:
-			normal.setVec(0,0,1);
-			inner_color.setVec(1,1,0,line_alpha);
-			mManipPart = LL_XY_PLANE;
-			break;
-		default:
-			break;
-		}
-
-		highlightIntersection(normal, selection_center, grid_rotation, inner_color);
-		mManipPart = temp_manip;
-		getManipAxis(first_object, mManipPart, translate_axis);
-
-		LLVector3 at_axis_abs;
-		if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-		{
-			at_axis_abs = LLVector3::x_axis * ~grid_rotation;
-		}
-		else
-		{
-			at_axis_abs = saved_selection_center - LLViewerCamera::getInstance()->getOrigin();
-			at_axis_abs.normVec();
-
-			at_axis_abs = at_axis_abs * ~grid_rotation;
-		}
-		at_axis_abs.abs();
-
-		if (at_axis_abs.mV[VX] > at_axis_abs.mV[VY] && at_axis_abs.mV[VX] > at_axis_abs.mV[VZ])
-		{
-			if (mManipPart == LL_Y_ARROW)
-			{
-				mSnapOffsetAxis = LLVector3::z_axis;
-			}
-			else if (mManipPart == LL_Z_ARROW)
-			{
-				mSnapOffsetAxis = LLVector3::y_axis;
-			}
-			else if (at_axis_abs.mV[VY] > at_axis_abs.mV[VZ])
-			{
-				mSnapOffsetAxis = LLVector3::z_axis;
-			}
-			else
-			{
-				mSnapOffsetAxis = LLVector3::y_axis;
-			}
-		}
-		else if (at_axis_abs.mV[VY] > at_axis_abs.mV[VZ])
-		{
-			if (mManipPart == LL_X_ARROW)
-			{
-				mSnapOffsetAxis = LLVector3::z_axis;
-			}
-			else if (mManipPart == LL_Z_ARROW)
-			{
-				mSnapOffsetAxis = LLVector3::x_axis;
-			}
-			else if (at_axis_abs.mV[VX] > at_axis_abs.mV[VZ])
-			{
-				mSnapOffsetAxis = LLVector3::z_axis;
-			}
-			else
-			{
-				mSnapOffsetAxis = LLVector3::x_axis;
-			}
-		}
-		else
-		{
-			if (mManipPart == LL_X_ARROW)
-			{
-				mSnapOffsetAxis = LLVector3::y_axis;
-			}
-			else if (mManipPart == LL_Y_ARROW)
-			{
-				mSnapOffsetAxis = LLVector3::x_axis;
-			}
-			else if (at_axis_abs.mV[VX] > at_axis_abs.mV[VY])
-			{
-				mSnapOffsetAxis = LLVector3::y_axis;
-			}
-			else
-			{
-				mSnapOffsetAxis = LLVector3::x_axis;
-			}
-		}
-
-		mSnapOffsetAxis = mSnapOffsetAxis * grid_rotation;
-
-		F32 guide_size_meters;
-
-		if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-		{
-			guide_size_meters = 1.f / gAgentCamera.mHUDCurZoom;
-			mSnapOffsetMeters = mArrowLengthMeters * 1.5f;
-		}
-		else
-		{
-			LLVector3 cam_to_selection = getPivotPoint() - LLViewerCamera::getInstance()->getOrigin();
-			F32 current_range = cam_to_selection.normVec();
-			guide_size_meters = SNAP_GUIDE_SCREEN_SIZE * gViewerWindow->getWorldViewHeightRaw() * current_range / LLViewerCamera::getInstance()->getPixelMeterRatio();
-	
-			F32 fraction_of_fov = mAxisArrowLength / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels();
-			F32 apparent_angle = fraction_of_fov * LLViewerCamera::getInstance()->getView();  // radians
-			F32 offset_at_camera = tan(apparent_angle) * 1.5f;
-			F32 range = dist_vec(gAgent.getPosAgentFromGlobal(first_node->mSavedPositionGlobal), LLViewerCamera::getInstance()->getOrigin());
-			mSnapOffsetMeters = range * offset_at_camera;
-		}
-
-		LLVector3 tick_start;
-		LLVector3 tick_end;
-
-		// how far away from grid origin is the selection along the axis of translation?
-		F32 dist_grid_axis = (selection_center - mGridOrigin) * translate_axis;
-		// find distance to nearest smallest grid unit
-		F32 offset_nearest_grid_unit = fmodf(dist_grid_axis, smallest_grid_unit_scale);
-		// how many smallest grid units are we away from largest grid scale?
-		S32 sub_div_offset = ll_round(fmodf(dist_grid_axis - offset_nearest_grid_unit, getMinGridScale() / sGridMinSubdivisionLevel) / smallest_grid_unit_scale);
-		S32 num_ticks_per_side = llmax(1, llfloor(0.5f * guide_size_meters / smallest_grid_unit_scale));
-
-		LLGLDepthTest gls_depth(GL_FALSE);
-
-		for (S32 pass = 0; pass < 3; pass++)
-		{
-			LLColor4 line_color = setupSnapGuideRenderPass(pass);
-			LLGLDepthTest gls_depth(pass != 1);
-
-			gGL.begin(LLRender::LINES);
-			{
-				LLVector3 line_start = selection_center + (mSnapOffsetMeters * mSnapOffsetAxis) + (translate_axis * (guide_size_meters * 0.5f + offset_nearest_grid_unit));
-				LLVector3 line_end = selection_center + (mSnapOffsetMeters * mSnapOffsetAxis) - (translate_axis * (guide_size_meters * 0.5f + offset_nearest_grid_unit));
-				LLVector3 line_mid = (line_start + line_end) * 0.5f;
-
-				gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW] * 0.2f);
-				gGL.vertex3fv(line_start.mV);
-				gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
-				gGL.vertex3fv(line_mid.mV);
-				gGL.vertex3fv(line_mid.mV);
-				gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW] * 0.2f);
-				gGL.vertex3fv(line_end.mV);
-
-				line_start.setVec(selection_center + (mSnapOffsetAxis * -mSnapOffsetMeters) + (translate_axis * guide_size_meters * 0.5f));
-				line_end.setVec(selection_center + (mSnapOffsetAxis * -mSnapOffsetMeters) - (translate_axis * guide_size_meters * 0.5f));
-				line_mid = (line_start + line_end) * 0.5f;
-
-				gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW] * 0.2f);
-				gGL.vertex3fv(line_start.mV);
-				gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
-				gGL.vertex3fv(line_mid.mV);
-				gGL.vertex3fv(line_mid.mV);
-				gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW] * 0.2f);
-				gGL.vertex3fv(line_end.mV);
-
-				for (S32 i = -num_ticks_per_side; i <= num_ticks_per_side; i++)
-				{
-					tick_start = selection_center + (translate_axis * (smallest_grid_unit_scale * (F32)i - offset_nearest_grid_unit));
-
-					//No need check this condition to prevent tick position scaling (FIX MAINT-5207/5208)
-					//F32 cur_subdivisions = getSubdivisionLevel(tick_start, translate_axis, getMinGridScale());
-					/*if (fmodf((F32)(i + sub_div_offset), (max_subdivisions / cur_subdivisions)) != 0.f)
-					{
-						continue;
-					}*/
-
-					// add in off-axis offset
-					tick_start += (mSnapOffsetAxis * mSnapOffsetMeters);
-
-					F32 tick_scale = 1.f;
-					for (F32 division_level = max_subdivisions; division_level >= sGridMinSubdivisionLevel; division_level /= 2.f)
-					{
-						if (fmodf((F32)(i + sub_div_offset), division_level) == 0.f)
-						{
-							break;
-						}
-						tick_scale *= 0.7f;
-					}
-
-// 					S32 num_ticks_to_fade = is_sub_tick ? num_ticks_per_side / 2 : num_ticks_per_side;
-// 					F32 alpha = line_alpha * (1.f - (0.8f *  ((F32)llabs(i) / (F32)num_ticks_to_fade)));
-
-					tick_end = tick_start + (mSnapOffsetAxis * mSnapOffsetMeters * tick_scale);
-
-					gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
-					gGL.vertex3fv(tick_start.mV);
-					gGL.vertex3fv(tick_end.mV);
-
-					tick_start = selection_center + (mSnapOffsetAxis * -mSnapOffsetMeters) +
-						(translate_axis * (getMinGridScale() / (F32)(max_subdivisions) * (F32)i - offset_nearest_grid_unit));
-					tick_end = tick_start - (mSnapOffsetAxis * mSnapOffsetMeters * tick_scale);
-
-					gGL.vertex3fv(tick_start.mV);
-					gGL.vertex3fv(tick_end.mV);
-				}
-			}
-			gGL.end();
-
-			if (mInSnapRegime)
-			{
-				LLVector3 line_start = selection_center - mSnapOffsetAxis * mSnapOffsetMeters;
-				LLVector3 line_end = selection_center + mSnapOffsetAxis * mSnapOffsetMeters;
-
-				gGL.begin(LLRender::LINES);
-				{
-					gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
-
-					gGL.vertex3fv(line_start.mV);
-					gGL.vertex3fv(line_end.mV);
-				}
-				gGL.end();
-
-				// draw snap guide arrow
-				gGL.begin(LLRender::TRIANGLES);
-				{
-					gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
-
-					LLVector3 arrow_dir;
-					LLVector3 arrow_span = translate_axis;
-
-					arrow_dir = -mSnapOffsetAxis;
-					gGL.vertex3fv((line_start + arrow_dir * mConeSize * SNAP_ARROW_SCALE).mV);
-					gGL.vertex3fv((line_start + arrow_span * mConeSize * SNAP_ARROW_SCALE).mV);
-					gGL.vertex3fv((line_start - arrow_span * mConeSize * SNAP_ARROW_SCALE).mV);
-
-					arrow_dir = mSnapOffsetAxis;
-					gGL.vertex3fv((line_end + arrow_dir * mConeSize * SNAP_ARROW_SCALE).mV);
-					gGL.vertex3fv((line_end + arrow_span * mConeSize * SNAP_ARROW_SCALE).mV);
-					gGL.vertex3fv((line_end - arrow_span * mConeSize * SNAP_ARROW_SCALE).mV);
-				}
-				gGL.end();
-			}
-		}
-
-		sub_div_offset = ll_round(fmod(dist_grid_axis - offset_nearest_grid_unit, getMinGridScale() * 32.f) / smallest_grid_unit_scale);
-
-		LLVector2 screen_translate_axis(llabs(translate_axis * LLViewerCamera::getInstance()->getLeftAxis()), llabs(translate_axis * LLViewerCamera::getInstance()->getUpAxis()));
-		screen_translate_axis.normVec();
-
-		S32 tick_label_spacing = ll_round(screen_translate_axis * sTickLabelSpacing);
-        
-		// render tickmark values
-		for (S32 i = -num_ticks_per_side; i <= num_ticks_per_side; i++)
-		{
-			LLVector3 tick_pos = selection_center + (translate_axis * ((smallest_grid_unit_scale * (F32)i) - offset_nearest_grid_unit));
-			F32 alpha = line_alpha * (1.f - (0.5f *  ((F32)llabs(i) / (F32)num_ticks_per_side)));
-
-			F32 tick_scale = 1.f;
-			for (F32 division_level = max_subdivisions; division_level >= sGridMinSubdivisionLevel; division_level /= 2.f)
-			{
-				if (fmodf((F32)(i + sub_div_offset), division_level) == 0.f)
-				{
-					break;
-				}
-				tick_scale *= 0.7f;
-			}
-
-			if (fmodf((F32)(i + sub_div_offset), (max_subdivisions / getSubdivisionLevel(tick_pos, translate_axis, getMinGridScale(), tick_label_spacing))) == 0.f)
-			{
-				F32 snap_offset_meters;
-
-				if (mSnapOffsetAxis * LLViewerCamera::getInstance()->getUpAxis() > 0.f)
-				{
-					snap_offset_meters = mSnapOffsetMeters;			
-				}
-				else
-				{
-					snap_offset_meters = -mSnapOffsetMeters;
-				}
-				LLVector3 text_origin = selection_center + 
-						(translate_axis * ((smallest_grid_unit_scale * (F32)i) - offset_nearest_grid_unit)) + 
-							(mSnapOffsetAxis * snap_offset_meters * (1.f + tick_scale));
-				
-				LLVector3 tick_offset = (tick_pos - mGridOrigin) * ~mGridRotation;
-				F32 offset_val = 0.5f * tick_offset.mV[ARROW_TO_AXIS[mManipPart]] / getMinGridScale();
-				EGridMode grid_mode = LLSelectMgr::getInstance()->getGridMode();
-				F32 text_highlight = 0.8f;
-				if(i - ll_round(offset_nearest_grid_unit / smallest_grid_unit_scale) == 0 && mInSnapRegime)
-				{
-					text_highlight = 1.f;
-				}
-				
-				if (grid_mode == GRID_MODE_WORLD)
-				{
-					// rescale units to meters from multiple of grid scale
-					offset_val *= 2.f * grid_scale[ARROW_TO_AXIS[mManipPart]];
-					renderTickValue(text_origin, offset_val, std::string("m"), LLColor4(text_highlight, text_highlight, text_highlight, alpha));
-				}
-				else
-				{
-					renderTickValue(text_origin, offset_val, std::string("x"), LLColor4(text_highlight, text_highlight, text_highlight, alpha));
-				}
-			}
-		}
-		if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
-		{
-			// render helpful text
-			if (mHelpTextTimer.getElapsedTimeF32() < sHelpTextVisibleTime + sHelpTextFadeTime && sNumTimesHelpTextShown < sMaxTimesShowHelpText)
-			{
-				F32 snap_offset_meters_up;
-				if (mSnapOffsetAxis * LLViewerCamera::getInstance()->getUpAxis() > 0.f)
-				{
-					snap_offset_meters_up = mSnapOffsetMeters;			
-				}
-				else
-				{
-					snap_offset_meters_up = -mSnapOffsetMeters;
-				}
-
-				LLVector3 selection_center_start = getSavedPivotPoint();//LLSelectMgr::getInstance()->getSavedBBoxOfSelection().getCenterAgent();
-
-				LLVector3 help_text_pos = selection_center_start + (snap_offset_meters_up * 3.f * mSnapOffsetAxis);
-				const LLFontGL* big_fontp = LLFontGL::getFontSansSerif();
-
-				static const LLWString translate_help_text = utf8str_to_wstring(LLTrans::getString("manip_hint1"));
-				LLColor4 help_text_color = LLColor4::white;
-				help_text_color.mV[VALPHA] = clamp_rescale(mHelpTextTimer.getElapsedTimeF32(), sHelpTextVisibleTime, sHelpTextVisibleTime + sHelpTextFadeTime, line_alpha, 0.f);
-				hud_render_text(translate_help_text, help_text_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(translate_help_text.c_str()), 3.f, help_text_color, false);
-				static const LLWString translate_help_text2 = utf8str_to_wstring(LLTrans::getString("manip_hint2"));
-				help_text_pos -= LLViewerCamera::getInstance()->getUpAxis() * mSnapOffsetMeters * 0.2f;
-				hud_render_text(translate_help_text2, help_text_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(translate_help_text2.c_str()), 3.f, help_text_color, false);
-			}
-		}
-	}
-	else
-	{
-		// render gridlines for planar snapping
-
-		F32 u = 0, v = 0;
-        LLColor4 inner_color;
-		LLVector3 normal;
-		LLVector3 grid_center = selection_center - grid_origin;
-		F32 usc = 1;
-		F32 vsc = 1;
-		
-		grid_center *= ~grid_rotation;
-
-		switch (mManipPart)
-		{
-		case LL_YZ_PLANE:
-			u = grid_center.mV[VY];
-			v = grid_center.mV[VZ];
-			usc = grid_scale.mV[VY];
-			vsc = grid_scale.mV[VZ];
-			inner_color.setVec(0,1,1,line_alpha);
-			normal.setVec(1,0,0);
-			break;
-		case LL_XZ_PLANE:
-			u = grid_center.mV[VX];
-			v = grid_center.mV[VZ];
-			usc = grid_scale.mV[VX];
-			vsc = grid_scale.mV[VZ];
-			inner_color.setVec(1,0,1,line_alpha);
-			normal.setVec(0,1,0);
-			break;
-		case LL_XY_PLANE:
-			u = grid_center.mV[VX];
-			v = grid_center.mV[VY];
-			usc = grid_scale.mV[VX];
-			vsc = grid_scale.mV[VY];
-			inner_color.setVec(1,1,0,line_alpha);
-			normal.setVec(0,0,1);
-			break;
-		default:
-			break;
-		}
-
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-		highlightIntersection(normal, selection_center, grid_rotation, inner_color);
-
-		gGL.pushMatrix();
-
-		F32 x,y,z,angle_radians;
-		grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
-		gGL.translatef(selection_center.mV[VX], selection_center.mV[VY], selection_center.mV[VZ]);
-		gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
-		
-		F32 sz = mGridSizeMeters;
-		F32 tiles = sz;
-
-		gGL.matrixMode(LLRender::MM_TEXTURE);
-		gGL.pushMatrix();
-		usc = 1.0f/usc;
-		vsc = 1.0f/vsc;
-		
-		while (usc > vsc*4.0f)
-		{
-			usc *= 0.5f;
-		}
-		while (vsc > usc * 4.0f)
-		{
-			vsc *= 0.5f;
-		}
-
-		gGL.scalef(usc, vsc, 1.0f);
-		gGL.translatef(u, v, 0);
-		
-		float a = line_alpha;
-
-		{
-			//draw grid behind objects
-			LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
-
-			{
-				//LLGLDisable stencil(GL_STENCIL_TEST);
-				{
-					LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GREATER);
-					gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, getGridTexName());
-					gGL.flush();
-					gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE_MINUS_SOURCE_ALPHA);
-					renderGrid(u,v,tiles,0.9f, 0.9f, 0.9f,a*0.15f);
-					gGL.flush();
-					gGL.setSceneBlendType(LLRender::BT_ALPHA);
-				}
-				
-				{
-					//draw black overlay
-					gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-					renderGrid(u,v,tiles,0.0f, 0.0f, 0.0f,a*0.16f);
-
-					//draw grid top
-					gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, getGridTexName());
-					renderGrid(u,v,tiles,1,1,1,a);
-
-					gGL.popMatrix();
-					gGL.matrixMode(LLRender::MM_MODELVIEW);
-					gGL.popMatrix();
-				}
-
-				{
-					LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
-					renderGuidelines();
-				}
-
-				{
-					LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GREATER);
-					gGL.flush();
-
-					switch (mManipPart)
-					{
-					  case LL_YZ_PLANE:
-						renderGuidelines(FALSE, TRUE, TRUE);
-						break;
-					  case LL_XZ_PLANE:
-						renderGuidelines(TRUE, FALSE, TRUE);
-						break;
-					  case LL_XY_PLANE:
-						renderGuidelines(TRUE, TRUE, FALSE);
-						break;
-					  default:
-						break;
-					}
-					gGL.flush();
-				}
-			}
-		}
-	}
-}
+    LLVector3 relative_camera_dir;
 
-void LLManipTranslate::renderGrid(F32 x, F32 y, F32 size, F32 r, F32 g, F32 b, F32 a)
-{
-	F32 d = size*0.5f;
-
-	for (F32 xx = -size-d; xx < size+d; xx += d)
-	{
-		gGL.begin(LLRender::TRIANGLE_STRIP);
-		for (F32 yy = -size-d; yy < size+d; yy += d)
-		{
-			float dx, dy, da;
-
-			dx = xx; dy = yy;
-			da = sqrtf(llmax(0.0f, 1.0f-sqrtf(dx*dx+dy*dy)/size))*a;
-			gGL.texCoord2f(dx, dy);
-			renderGridVert(dx,dy,r,g,b,da);
-
-			dx = xx+d; dy = yy;
-			da = sqrtf(llmax(0.0f, 1.0f-sqrtf(dx*dx+dy*dy)/size))*a;
-			gGL.texCoord2f(dx, dy);
-			renderGridVert(dx,dy,r,g,b,da);
-			
-			dx = xx; dy = yy+d;
-			da = sqrtf(llmax(0.0f, 1.0f-sqrtf(dx*dx+dy*dy)/size))*a;
-			gGL.texCoord2f(dx, dy);
-			renderGridVert(dx,dy,r,g,b,da);
-
-			dx = xx+d; dy = yy+d;
-			da = sqrtf(llmax(0.0f, 1.0f-sqrtf(dx*dx+dy*dy)/size))*a;
-			gGL.texCoord2f(dx, dy);
-			renderGridVert(dx,dy,r,g,b,da);
-		}
-		gGL.end();
-	}
-
-	
-}
+    LLMatrix4 transform;
 
-void LLManipTranslate::highlightIntersection(LLVector3 normal, 
-											 LLVector3 selection_center, 
-											 LLQuaternion grid_rotation, 
-											 LLColor4 inner_color)
-{
-#if 0 // DEPRECATED
-	if (!gSavedSettings.getBOOL("GridCrossSections"))
-	{
-		return;
-	}
-	
-	
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-
-	
-	static const U32 types[] = { LLRenderPass::PASS_SIMPLE, LLRenderPass::PASS_ALPHA, LLRenderPass::PASS_FULLBRIGHT, LLRenderPass::PASS_SHINY };
-	static const U32 num_types = LL_ARRAY_SIZE(types);
-
-	GLuint stencil_mask = 0xFFFFFFFF;
-	//stencil in volumes
-
-	gGL.flush();
-
-	if (shader)
-	{
-		gClipProgram.bind();
-	}
-		
-	{
-		//glStencilMask(stencil_mask); //deprecated
-		//glClearStencil(1);
-		//glClear(GL_STENCIL_BUFFER_BIT);
-		LLGLEnable cull_face(GL_CULL_FACE);
-		//LLGLEnable stencil(GL_STENCIL_TEST);
-		LLGLDepthTest depth (GL_TRUE, GL_FALSE, GL_ALWAYS);
-		//glStencilFunc(GL_ALWAYS, 0, stencil_mask);
-		gGL.setColorMask(false, false);
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-		gGL.diffuseColor4f(1,1,1,1);
-
-		//setup clip plane
-		normal = normal * grid_rotation;
-		if (normal * (LLViewerCamera::getInstance()->getOrigin()-selection_center) < 0)
-		{
-			normal = -normal;
-		}
-		F32 d = -(selection_center * normal);
-		LLVector4a plane(normal.mV[0], normal.mV[1], normal.mV[2], d );
-
-		LLMatrix4a inv_mat = gGL.getModelviewMatrix();
-		inv_mat.invert();
-		inv_mat.transpose();
-		inv_mat.rotate4(plane,plane);
-
-		static LLStaticHashedString sClipPlane("clip_plane");
-		gClipProgram.uniform4fv(sClipPlane, 1, plane.getF32ptr());
-		
-		BOOL particles = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
-		BOOL clouds = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS);
-		
-		if (particles)
-		{
-			LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
-		}
-		if (clouds)
-		{
-			LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_CLOUDS);
-		}
-		
-		//stencil in volumes
-		//glStencilOp(GL_INCR, GL_INCR, GL_INCR);
-		glCullFace(GL_FRONT);
-		for (U32 i = 0; i < num_types; i++)
-		{
-			gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, FALSE);
-		}
-
-		//glStencilOp(GL_DECR, GL_DECR, GL_DECR);
-		glCullFace(GL_BACK);
-		for (U32 i = 0; i < num_types; i++)
-		{
-			gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, FALSE);
-		}
-		
-		if (particles)
-		{
-			LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
-		}
-		if (clouds)
-		{
-			LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_CLOUDS);
-		}
-
-		gGL.setColorMask(true, false);
-	}
-	gGL.color4f(1,1,1,1);
-
-	gGL.pushMatrix();
-
-	F32 x,y,z,angle_radians;
-	grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
-	gGL.translatef(selection_center.mV[VX], selection_center.mV[VY], selection_center.mV[VZ]);
-	gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
-	
-	F32 sz = mGridSizeMeters;
-	F32 tiles = sz;
-
-	if (shader)
-	{
-		shader->bind();
-	}
-
-	//draw volume/plane intersections
-	{
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-		LLGLDepthTest depth(GL_FALSE);
-		//LLGLEnable stencil(GL_STENCIL_TEST);
-		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
-		glStencilFunc(GL_EQUAL, 0, stencil_mask);
-		renderGrid(0,0,tiles,inner_color.mV[0], inner_color.mV[1], inner_color.mV[2], 0.25f);
-	}
-
-	glStencilFunc(GL_ALWAYS, 255, 0xFFFFFFFF);
-	glStencilMask(0xFFFFFFFF);
-	glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
-
-	gGL.popMatrix();
-#endif
-}
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        relative_camera_dir = LLVector3(1.f, 0.f, 0.f) * ~grid_rotation;
+        LLVector4 translation(object_position);
+        transform.initRotTrans(grid_rotation, translation);
+        LLMatrix4 cfr(OGL_TO_CFR_ROTATION);
+        transform *= cfr;
+        LLMatrix4 window_scale;
+        F32 zoom_level = 2.f * gAgentCamera.mHUDCurZoom;
+        window_scale.initAll(LLVector3(zoom_level / LLViewerCamera::getInstance()->getAspect(), zoom_level, 0.f),
+            LLQuaternion::DEFAULT,
+            LLVector3::zero);
+        transform *= window_scale;
+    }
+    else
+    {
+        relative_camera_dir = (object_position - LLViewerCamera::getInstance()->getOrigin()) * ~grid_rotation;
+        relative_camera_dir.normVec();
 
-void LLManipTranslate::renderText()
-{
-	if (mObjectSelection->getRootObjectCount() && !mObjectSelection->isAttachment())
-	{
-		LLVector3 pos = getPivotPoint();
-		renderXYZ(pos);
-	}
-	else
-	{
-		const BOOL children_ok = TRUE;
-		LLViewerObject* objectp = mObjectSelection->getFirstRootObject(children_ok);
-		if (objectp)
-		{
-			renderXYZ(objectp->getPositionEdit());
-		}
-	}
-}
+        transform.initRotTrans(grid_rotation, LLVector4(object_position));
+        transform *= modelView;
+        transform *= projMatrix;
+    }
 
-void LLManipTranslate::renderTranslationHandles()
-{
-	LLVector3 grid_origin;
-	LLVector3 grid_scale;
-	LLQuaternion grid_rotation;
-	LLGLDepthTest gls_depth(GL_FALSE);
-	
-	LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
-	LLVector3 at_axis;
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		at_axis = LLVector3::x_axis * ~grid_rotation;
-	}
-	else
-	{
-		at_axis = LLViewerCamera::getInstance()->getAtAxis() * ~grid_rotation;
-	}
-
-	if (at_axis.mV[VX] > 0.f)
-	{
-		mPlaneManipPositions.mV[VX] = 1.f;
-	}
-	else
-	{
-		mPlaneManipPositions.mV[VX] = -1.f;
-	}
-
-	if (at_axis.mV[VY] > 0.f)
-	{
-		mPlaneManipPositions.mV[VY] = 1.f;
-	}
-	else
-	{
-		mPlaneManipPositions.mV[VY] = -1.f;
-	}
-
-	if (at_axis.mV[VZ] > 0.f)
-	{
-		mPlaneManipPositions.mV[VZ] = 1.f;
-	}
-	else
-	{
-		mPlaneManipPositions.mV[VZ] = -1.f;
-	}
-
-	LLViewerObject *first_object = mObjectSelection->getFirstMoveableObject(TRUE);
-	if (!first_object) return;
-
-	LLVector3 selection_center = getPivotPoint();
-
-	// Drag handles 	
-	if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-	{
-		mArrowLengthMeters = mAxisArrowLength / gViewerWindow->getWorldViewHeightRaw();
-		mArrowLengthMeters /= gAgentCamera.mHUDCurZoom;
-	}
-	else
-	{
-		LLVector3 camera_pos_agent = gAgentCamera.getCameraPositionAgent();
-		F32 range = dist_vec(camera_pos_agent, selection_center);
-		F32 range_from_agent = dist_vec(gAgent.getPositionAgent(), selection_center);
-		
-		// Don't draw handles if you're too far away
-		if (ALControlCache::LimitSelectDistance)
-		{
-			if (range_from_agent > ALControlCache::MaxSelectDistance)
-			{
-				return;
-			}
-		}
-
-		if (range > 0.001f)
-		{
-			// range != zero
-			F32 fraction_of_fov = mAxisArrowLength / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels();
-			F32 apparent_angle = fraction_of_fov * LLViewerCamera::getInstance()->getView();  // radians
-			mArrowLengthMeters = range * tan(apparent_angle);
-		}
-		else
-		{
-			// range == zero
-			mArrowLengthMeters = 1.0f;
-		}
-	}
-	//Assume that UI scale factor is equivalent for X and Y axis
-	F32 ui_scale_factor = LLUI::getScaleFactor().mV[VX];
-	mArrowLengthMeters *= ui_scale_factor;
-
-	mPlaneManipOffsetMeters = mArrowLengthMeters * 1.8f;
-	mGridSizeMeters = ALControlCache::GridDrawSize;
-	mConeSize = mArrowLengthMeters / 4.f;
-
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-	{
-		gGL.translatef(selection_center.mV[VX], selection_center.mV[VY], selection_center.mV[VZ]);
-
-		F32 angle_radians, x, y, z;
-		grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
-
-		gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
-
-		LLQuaternion invRotation = grid_rotation;
-		invRotation.conjQuat();
-
-		LLVector3 relative_camera_dir;
-		
-		if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-		{
-			relative_camera_dir = LLVector3::x_axis * invRotation;
-		}
-		else
-		{
-			relative_camera_dir = (selection_center - LLViewerCamera::getInstance()->getOrigin()) * invRotation;
-		}
-		relative_camera_dir.normVec();
-
-		{
-			gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-			LLGLDisable cull_face(GL_CULL_FACE);
-
-			LLColor4 color1;
-			LLColor4 color2;
-
-			// update manipulator sizes
-			for (S32 index = 0; index < 3; index++)
-			{
-				if (index == mManipPart - LL_X_ARROW || index == mHighlightedPart - LL_X_ARROW)
-				{
-					mArrowScales.mV[index] = ll_lerp(mArrowScales.mV[index], SELECTED_ARROW_SCALE, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
-					mPlaneScales.mV[index] = ll_lerp(mPlaneScales.mV[index], 1.f, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
-				}
-				else if (index == mManipPart - LL_YZ_PLANE || index == mHighlightedPart - LL_YZ_PLANE)
-				{
-					mArrowScales.mV[index] = ll_lerp(mArrowScales.mV[index], 1.f, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
-					mPlaneScales.mV[index] = ll_lerp(mPlaneScales.mV[index], SELECTED_ARROW_SCALE, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
-				}
-				else
-				{
-					mArrowScales.mV[index] = ll_lerp(mArrowScales.mV[index], 1.f, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
-					mPlaneScales.mV[index] = ll_lerp(mPlaneScales.mV[index], 1.f, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
-				}
-			}
-
-			if ((mManipPart == LL_NO_PART || mManipPart == LL_YZ_PLANE) && llabs(relative_camera_dir.mV[VX]) > MIN_PLANE_MANIP_DOT_PRODUCT)
-			{
-				// render YZ plane manipulator
-				gGL.pushMatrix();
-				gGL.scalef(mPlaneManipPositions.mV[VX], mPlaneManipPositions.mV[VY], mPlaneManipPositions.mV[VZ]);
-				gGL.translatef(0.f, mPlaneManipOffsetMeters, mPlaneManipOffsetMeters);
-				gGL.scalef(mPlaneScales.mV[VX], mPlaneScales.mV[VX], mPlaneScales.mV[VX]);
-				if (mHighlightedPart == LL_YZ_PLANE)
-				{
-					color1.setVec(0.f, 1.f, 0.f, 1.f);
-					color2.setVec(0.f, 0.f, 1.f, 1.f);
-				}
-				else
-				{
-					color1.setVec(0.f, 1.f, 0.f, 0.6f);
-					color2.setVec(0.f, 0.f, 1.f, 0.6f);
-				}
-				gGL.begin(LLRender::TRIANGLES);
-				{
-					gGL.color4fv(color1.mV);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f));
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f));
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
-
-					gGL.color4fv(color2.mV);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f), mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f));
-				}
-				gGL.end();
-
-				LLUI::setLineWidth(3.0f);
-				gGL.begin(LLRender::LINES);
-				{
-					gGL.color4f(0.f, 0.f, 0.f, 0.3f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.1f,   mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.1f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.1f,   mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.4f);
-
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.1f,  mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.1f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.4f,  mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.1f);
-				}
-				gGL.end();
-				LLUI::setLineWidth(1.0f);
-				gGL.popMatrix();
-			}
-
-			if ((mManipPart == LL_NO_PART || mManipPart == LL_XZ_PLANE) && llabs(relative_camera_dir.mV[VY]) > MIN_PLANE_MANIP_DOT_PRODUCT)
-			{
-				// render XZ plane manipulator
-				gGL.pushMatrix();
-				gGL.scalef(mPlaneManipPositions.mV[VX], mPlaneManipPositions.mV[VY], mPlaneManipPositions.mV[VZ]);
-				gGL.translatef(mPlaneManipOffsetMeters, 0.f, mPlaneManipOffsetMeters);
-				gGL.scalef(mPlaneScales.mV[VY], mPlaneScales.mV[VY], mPlaneScales.mV[VY]);
-				if (mHighlightedPart == LL_XZ_PLANE)
-				{
-					color1.setVec(0.f, 0.f, 1.f, 1.f);
-					color2.setVec(1.f, 0.f, 0.f, 1.f);
-				}
-				else
-				{
-					color1.setVec(0.f, 0.f, 1.f, 0.6f);
-					color2.setVec(1.f, 0.f, 0.f, 0.6f);
-				}
-
-				gGL.begin(LLRender::TRIANGLES);
-				{
-					gGL.color4fv(color1.mV);
-					gGL.vertex3f(mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f), 0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
-					gGL.vertex3f(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f), 0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
-					gGL.vertex3f(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f));
-
-					gGL.color4fv(color2.mV);
-					gGL.vertex3f(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f));
-					gGL.vertex3f(mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f),	0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f));
-					gGL.vertex3f(mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f),	0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
-				}
-				gGL.end();
-
-				LLUI::setLineWidth(3.0f);
-				gGL.begin(LLRender::LINES);
-				{
-					gGL.color4f(0.f, 0.f, 0.f, 0.3f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.1f,   0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.1f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.1f,   0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.4f);
-																				
-					gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.1f,   0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.1f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
-					gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.4f,   0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.1f);
-				}
-				gGL.end();
-				LLUI::setLineWidth(1.0f);
-
-				gGL.popMatrix();
-			}
-
-			if ((mManipPart == LL_NO_PART || mManipPart == LL_XY_PLANE) && llabs(relative_camera_dir.mV[VZ]) > MIN_PLANE_MANIP_DOT_PRODUCT)
-			{
-				// render XY plane manipulator
-				gGL.pushMatrix();
-				gGL.scalef(mPlaneManipPositions.mV[VX], mPlaneManipPositions.mV[VY], mPlaneManipPositions.mV[VZ]);
-				
-/*				 			  Y
-				 			  ^
-				 			  v1
-				 			  |  \ 
-				 			  |<- v0
-				 			  |  /| \ 
-				 			  v2__v__v3 > X
-*/
-					LLVector3 v0,v1,v2,v3;
-#if 0
-					// This should theoretically work but looks off; could be tuned later -SJB
-					gGL.translatef(-mPlaneManipOffsetMeters, -mPlaneManipOffsetMeters, 0.f);
-					v0 = LLVector3(mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), 0.f);
-					v1 = LLVector3(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.75f), 0.f);
-					v2 = LLVector3(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f);
-					v3 = LLVector3(mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.75f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f);
-#else
-					gGL.translatef(mPlaneManipOffsetMeters, mPlaneManipOffsetMeters, 0.f);
-					v0 = LLVector3(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f);
-					v1 = LLVector3(mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f), 0.f);
-					v2 = LLVector3(mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), 0.f);
-					v3 = LLVector3(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f), mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), 0.f);
-#endif
-					gGL.scalef(mPlaneScales.mV[VZ], mPlaneScales.mV[VZ], mPlaneScales.mV[VZ]);
-					if (mHighlightedPart == LL_XY_PLANE)
-					{
-						color1.setVec(1.f, 0.f, 0.f, 1.f);
-						color2.setVec(0.f, 1.f, 0.f, 1.f);
-					}
-					else
-					{
-						color1.setVec(0.8f, 0.f, 0.f, 0.6f);
-						color2.setVec(0.f, 0.8f, 0.f, 0.6f);
-					}
-				
-					gGL.begin(LLRender::TRIANGLES);
-					{
-						gGL.color4fv(color1.mV);
-						gGL.vertex3fv(v0.mV);
-						gGL.vertex3fv(v1.mV);
-						gGL.vertex3fv(v2.mV);
-
-						gGL.color4fv(color2.mV);
-						gGL.vertex3fv(v2.mV);
-						gGL.vertex3fv(v3.mV);
-						gGL.vertex3fv(v0.mV);
-					}
-					gGL.end();
-
-					LLUI::setLineWidth(3.0f);
-					gGL.begin(LLRender::LINES);
-					{
-						gGL.color4f(0.f, 0.f, 0.f, 0.3f);
-						LLVector3 v12 = (v1 + v2) * .5f;
-						gGL.vertex3fv(v0.mV);
-						gGL.vertex3fv(v12.mV);
-						gGL.vertex3fv(v12.mV);
-						gGL.vertex3fv((v12 + (v0-v12)*.3f + (v2-v12)*.3f).mV);
-						gGL.vertex3fv(v12.mV);
-						gGL.vertex3fv((v12 + (v0-v12)*.3f + (v1-v12)*.3f).mV);
-
-						LLVector3 v23 = (v2 + v3) * .5f;
-						gGL.vertex3fv(v0.mV);
-						gGL.vertex3fv(v23.mV);
-						gGL.vertex3fv(v23.mV);
-						gGL.vertex3fv((v23 + (v0-v23)*.3f + (v3-v23)*.3f).mV);
-						gGL.vertex3fv(v23.mV);
-						gGL.vertex3fv((v23 + (v0-v23)*.3f + (v2-v23)*.3f).mV);
-					}
-					gGL.end();
-					LLUI::setLineWidth(1.0f);
-
-				gGL.popMatrix();
-			}
-		}
-		{
-			gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-			// Since we draw handles with depth testing off, we need to draw them in the 
-			// proper depth order.
-
-			// Copied from LLDrawable::updateGeometry
-			LLVector3 pos_agent     = first_object->getPositionAgent();
-			LLVector3 camera_agent	= gAgentCamera.getCameraPositionAgent();
-			LLVector3 headPos		= pos_agent - camera_agent;
-
-			LLVector3 orientWRTHead    = headPos * invRotation;
-
-			// Find nearest vertex
-			U32 nearest = (orientWRTHead.mV[0] < 0.0f ? 1 : 0) + 
-				(orientWRTHead.mV[1] < 0.0f ? 2 : 0) + 
-				(orientWRTHead.mV[2] < 0.0f ? 4 : 0);
-
-			// opposite faces on Linden cubes:
-			// 0 & 5
-			// 1 & 3
-			// 2 & 4
-
-			// Table of order to draw faces, based on nearest vertex
-			static U32 face_list[8][NUM_AXES*2] = { 
-				{ 2,0,1, 4,5,3 }, // v6  F201 F453
-				{ 2,0,3, 4,5,1 }, // v7  F203 F451
-				{ 4,0,1, 2,5,3 }, // v5  F401 F253
-				{ 4,0,3, 2,5,1 }, // v4  F403 F251
-				{ 2,5,1, 4,0,3 }, // v2  F251 F403
-				{ 2,5,3, 4,0,1 }, // v3  F253 F401
-				{ 4,5,1, 2,0,3 }, // v1  F451 F203
-				{ 4,5,3, 2,0,1 }, // v0  F453 F201
-			};
-			static const EManipPart which_arrow[6] = {
-				LL_Z_ARROW,
-				LL_X_ARROW,
-				LL_Y_ARROW,
-				LL_X_ARROW,
-				LL_Y_ARROW,
-				LL_Z_ARROW};
-
-			// draw arrows for deeper faces first, closer faces last
-			LLVector3 camera_axis;
-			if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
-			{
-				camera_axis = LLVector3::x_axis;
-			}
-			else
-			{
-				camera_axis.setVec(gAgentCamera.getCameraPositionAgent() - first_object->getPositionAgent());
-			}
-
-			for (U32 i = 0; i < NUM_AXES*2; i++)
-			{				
-				U32 face = face_list[nearest][i];
-
-				LLVector3 arrow_axis;
-				getManipAxis(first_object, which_arrow[face], arrow_axis);
-
-				renderArrow(which_arrow[face],
-							mManipPart,
-							(face >= 3) ? -mConeSize : mConeSize,
-							(face >= 3) ? -mArrowLengthMeters : mArrowLengthMeters,
-							mConeSize,
-							FALSE);
-			}
-		}
-	}
-	gGL.popMatrix();
-}
+    S32 numManips = 0;
 
+    // edges
+    mManipulatorVertices[numManips++] = LLVector4(mArrowLengthMeters * MANIPULATOR_HOTSPOT_START, 0.f, 0.f, 1.f);
+    mManipulatorVertices[numManips++] = LLVector4(mArrowLengthMeters * MANIPULATOR_HOTSPOT_END, 0.f, 0.f, 1.f);
 
-void LLManipTranslate::renderArrow(S32 which_arrow, S32 selected_arrow, F32 box_size, F32 arrow_size, F32 handle_size, BOOL reverse_direction)
-{
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	LLGLEnable gls_blend(GL_BLEND);
-
-	for (S32 pass = 1; pass <= 2; pass++)
-	{	
-		LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, pass == 1 ? GL_LEQUAL : GL_GREATER);
-		gGL.pushMatrix();
-			
-		S32 index = 0;
-	
-		index = ARROW_TO_AXIS[which_arrow];
-		
-		// assign a color for this arrow
-		LLColor4 color;  // black
-		if (which_arrow == selected_arrow || which_arrow == mHighlightedPart)
-		{
-			color.mV[index] = (pass == 1) ? 1.f : 0.5f;
-		}
-		else if (selected_arrow != LL_NO_PART)
-		{
-			color.mV[VALPHA] = 0.f;
-		}
-		else 
-		{
-			color.mV[index] = pass == 1 ? .8f : .35f ;			// red, green, or blue
-			color.mV[VALPHA] = 0.6f;
-		}
-		gGL.color4fv( color.mV );
-
-		LLVector3 vec;
-
-		{
-			LLUI::setLineWidth(2.0f);
-			gGL.begin(LLRender::LINES);
-				vec.mV[index] = box_size;
-				gGL.vertex3f(vec.mV[0], vec.mV[1], vec.mV[2]);
-
-				vec.mV[index] = arrow_size;
-				gGL.vertex3f(vec.mV[0], vec.mV[1], vec.mV[2]);
-			gGL.end();
-			LLUI::setLineWidth(1.0f);
-		}
-		
-		gGL.translatef(vec.mV[0], vec.mV[1], vec.mV[2]);
-		gGL.scalef(handle_size, handle_size, handle_size);
-
-		F32 rot = 0.0f;
-		LLVector3 axis;
-
-		switch(which_arrow)
-		{
-		case LL_X_ARROW:
-			rot = reverse_direction ? -90.0f : 90.0f;
-			axis.mV[1] = 1.0f;
-			break;
-		case LL_Y_ARROW:
-			rot = reverse_direction ? 90.0f : -90.0f;
-			axis.mV[0] = 1.0f;
-			break;
-		case LL_Z_ARROW:
-			rot = reverse_direction ? 180.0f : 0.0f;
-			axis.mV[0] = 1.0f;
-			break;
-		default:
-			LL_ERRS() << "renderArrow called with bad arrow " << which_arrow << LL_ENDL;
-			break;
-		}
-
-		gGL.diffuseColor4fv(color.mV);
-		gGL.rotatef(rot, axis.mV[0], axis.mV[1], axis.mV[2]);
-		gGL.scalef(mArrowScales.mV[index], mArrowScales.mV[index], mArrowScales.mV[index] * 1.5f);
-
-		gCone.render();
-
-		gGL.popMatrix();
-	}
-}
+    mManipulatorVertices[numManips++] = LLVector4(0.f, mArrowLengthMeters * MANIPULATOR_HOTSPOT_START, 0.f, 1.f);
+    mManipulatorVertices[numManips++] = LLVector4(0.f, mArrowLengthMeters * MANIPULATOR_HOTSPOT_END, 0.f, 1.f);
 
-void LLManipTranslate::renderGridVert(F32 x_trans, F32 y_trans, F32 r, F32 g, F32 b, F32 alpha)
-{
-	gGL.color4f(r, g, b, alpha);
-	switch (mManipPart)
-	{
-	case LL_YZ_PLANE:
-		gGL.vertex3f(0, x_trans, y_trans);
-		break;
-	case LL_XZ_PLANE:
-		gGL.vertex3f(x_trans, 0, y_trans);
-		break;
-	case LL_XY_PLANE:
-		gGL.vertex3f(x_trans, y_trans, 0);
-		break;
-	default:
-		gGL.vertex3f(0,0,0);
-		break;
-	}
+    mManipulatorVertices[numManips++] = LLVector4(0.f, 0.f, mArrowLengthMeters * MANIPULATOR_HOTSPOT_START, 1.f);
+    mManipulatorVertices[numManips++] = LLVector4(0.f, 0.f, mArrowLengthMeters * MANIPULATOR_HOTSPOT_END, 1.f);
 
-}
+    mManipulatorVertices[numManips++] = LLVector4(mArrowLengthMeters * -MANIPULATOR_HOTSPOT_START, 0.f, 0.f, 1.f);
+    mManipulatorVertices[numManips++] = LLVector4(mArrowLengthMeters * -MANIPULATOR_HOTSPOT_END, 0.f, 0.f, 1.f);
 
-// virtual
-BOOL LLManipTranslate::canAffectSelection()
-{
-	BOOL can_move = mObjectSelection->getObjectCount() != 0;
-	if (can_move)
-	{
-		struct f : public LLSelectedObjectFunctor
-		{
-			virtual bool apply(LLViewerObject* objectp)
-			{
-				LLViewerObject *root_object = (objectp == NULL) ? NULL : objectp->getRootEdit();
-				return objectp->permMove() && !objectp->isPermanentEnforced() &&
-					((root_object == NULL) || !root_object->isPermanentEnforced()) &&
-					(objectp->permModify() || !ALControlCache::EditLinkedParts);
-			}
-		} func;
-		can_move = mObjectSelection->applyToObjects(&func);
-	}
-	return can_move;
+    mManipulatorVertices[numManips++] = LLVector4(0.f, mArrowLengthMeters * -MANIPULATOR_HOTSPOT_START, 0.f, 1.f);
+    mManipulatorVertices[numManips++] = LLVector4(0.f, mArrowLengthMeters * -MANIPULATOR_HOTSPOT_END, 0.f, 1.f);
+
+    mManipulatorVertices[numManips++] = LLVector4(0.f, 0.f, mArrowLengthMeters * -MANIPULATOR_HOTSPOT_START, 1.f);
+    mManipulatorVertices[numManips++] = LLVector4(0.f, 0.f, mArrowLengthMeters * -MANIPULATOR_HOTSPOT_END, 1.f);
+
+    S32 num_arrow_manips = numManips;
+
+    // planar manipulators
+    BOOL planar_manip_yz_visible = FALSE;
+    BOOL planar_manip_xz_visible = FALSE;
+    BOOL planar_manip_xy_visible = FALSE;
+
+    mManipulatorVertices[numManips] = LLVector4(0.f, mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), 1.f);
+    mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
+    mManipulatorVertices[numManips] = LLVector4(0.f, mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), 1.f);
+    mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
+    if (llabs(relative_camera_dir.mV[VX]) > MIN_PLANE_MANIP_DOT_PRODUCT)
+    {
+        planar_manip_yz_visible = TRUE;
+    }
+
+    mManipulatorVertices[numManips] = LLVector4(mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), 0.f, mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), 1.f);
+    mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
+    mManipulatorVertices[numManips] = LLVector4(mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), 0.f, mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), 1.f);
+    mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
+    if (llabs(relative_camera_dir.mV[VY]) > MIN_PLANE_MANIP_DOT_PRODUCT)
+    {
+        planar_manip_xz_visible = TRUE;
+    }
+
+    mManipulatorVertices[numManips] = LLVector4(mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), mPlaneManipOffsetMeters * (1.f - PLANE_TICK_SIZE * 0.5f), 0.f, 1.f);
+    mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
+    mManipulatorVertices[numManips] = LLVector4(mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), mPlaneManipOffsetMeters * (1.f + PLANE_TICK_SIZE * 0.5f), 0.f, 1.f);
+    mManipulatorVertices[numManips++].scaleVec(mPlaneManipPositions);
+    if (llabs(relative_camera_dir.mV[VZ]) > MIN_PLANE_MANIP_DOT_PRODUCT)
+    {
+        planar_manip_xy_visible = TRUE;
+    }
+
+    // Project up to 9 manipulators to screen space 2*X, 2*Y, 2*Z, 3*planes
+    std::vector<ManipulatorHandle> projected_manipulators;
+    projected_manipulators.reserve(9);
+
+    for (S32 i = 0; i < num_arrow_manips; i+= 2)
+    {
+        LLVector4 projected_start = mManipulatorVertices[i] * transform;
+        projected_start = projected_start * (1.f / projected_start.mV[VW]);
+
+        LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
+        projected_end = projected_end * (1.f / projected_end.mV[VW]);
+
+        ManipulatorHandle projected_manip(
+                LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]),
+                LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]),
+                MANIPULATOR_IDS[i / 2],
+                10.f); // 10 pixel hotspot for arrows
+        projected_manipulators.push_back(projected_manip);
+    }
+
+    if (planar_manip_yz_visible)
+    {
+        S32 i = num_arrow_manips;
+        LLVector4 projected_start = mManipulatorVertices[i] * transform;
+        projected_start = projected_start * (1.f / projected_start.mV[VW]);
+
+        LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
+        projected_end = projected_end * (1.f / projected_end.mV[VW]);
+
+        ManipulatorHandle projected_manip(
+                LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]),
+                LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]),
+                MANIPULATOR_IDS[i / 2],
+                20.f); // 20 pixels for planar manipulators
+        projected_manipulators.push_back(projected_manip);
+    }
+
+    if (planar_manip_xz_visible)
+    {
+        S32 i = num_arrow_manips + 2;
+        LLVector4 projected_start = mManipulatorVertices[i] * transform;
+        projected_start = projected_start * (1.f / projected_start.mV[VW]);
+
+        LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
+        projected_end = projected_end * (1.f / projected_end.mV[VW]);
+
+        ManipulatorHandle projected_manip(
+                LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]),
+                LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]),
+                MANIPULATOR_IDS[i / 2],
+                20.f); // 20 pixels for planar manipulators
+        projected_manipulators.push_back(projected_manip);
+    }
+
+    if (planar_manip_xy_visible)
+    {
+        S32 i = num_arrow_manips + 4;
+        LLVector4 projected_start = mManipulatorVertices[i] * transform;
+        projected_start = projected_start * (1.f / projected_start.mV[VW]);
+
+        LLVector4 projected_end = mManipulatorVertices[i + 1] * transform;
+        projected_end = projected_end * (1.f / projected_end.mV[VW]);
+
+        ManipulatorHandle projected_manip(
+                LLVector3(projected_start.mV[VX], projected_start.mV[VY], projected_start.mV[VZ]),
+                LLVector3(projected_end.mV[VX], projected_end.mV[VY], projected_end.mV[VZ]),
+                MANIPULATOR_IDS[i / 2],
+                20.f); // 20 pixels for planar manipulators
+        projected_manipulators.push_back(projected_manip);
+    }
+
+    LLVector2 manip_start_2d;
+    LLVector2 manip_end_2d;
+    LLVector2 manip_dir;
+    LLRect world_view_rect = gViewerWindow->getWorldViewRectScaled();
+    F32 half_width = (F32)world_view_rect.getWidth() / 2.f;
+    F32 half_height = (F32)world_view_rect.getHeight() / 2.f;
+    LLVector2 mousePos((F32)x - half_width, (F32)y - half_height);
+    LLVector2 mouse_delta;
+
+    // Keep order consistent with insertion via stable_sort
+    std::stable_sort( projected_manipulators.begin(),
+        projected_manipulators.end(),
+        ClosestToCamera() );
+
+    std::vector<ManipulatorHandle>::iterator it = projected_manipulators.begin();
+    for ( ; it != projected_manipulators.end(); ++it)
+    {
+        ManipulatorHandle& manipulator = *it;
+        {
+            manip_start_2d.setVec(manipulator.mStartPosition.mV[VX] * half_width, manipulator.mStartPosition.mV[VY] * half_height);
+            manip_end_2d.setVec(manipulator.mEndPosition.mV[VX] * half_width, manipulator.mEndPosition.mV[VY] * half_height);
+            manip_dir = manip_end_2d - manip_start_2d;
+
+            mouse_delta = mousePos - manip_start_2d;
+
+            F32 manip_length = manip_dir.normVec();
+
+            F32 mouse_pos_manip = mouse_delta * manip_dir;
+            F32 mouse_dist_manip_squared = mouse_delta.magVecSquared() - (mouse_pos_manip * mouse_pos_manip);
+
+            if (mouse_pos_manip > 0.f &&
+                mouse_pos_manip < manip_length &&
+                mouse_dist_manip_squared < manipulator.mHotSpotRadius * manipulator.mHotSpotRadius)
+            {
+                mHighlightedPart = manipulator.mManipID;
+                break;
+            }
+        }
+    }
+}
+
+F32 LLManipTranslate::getMinGridScale()
+{
+    F32 scale;
+    switch (mManipPart)
+    {
+    case LL_NO_PART:
+    default:
+        scale = 1.f;
+        break;
+    case LL_X_ARROW:
+        scale = mGridScale.mV[VX];
+        break;
+    case LL_Y_ARROW:
+        scale = mGridScale.mV[VY];
+        break;
+    case LL_Z_ARROW:
+        scale = mGridScale.mV[VZ];
+        break;
+    case LL_YZ_PLANE:
+        scale = llmin(mGridScale.mV[VY], mGridScale.mV[VZ]);
+        break;
+    case LL_XZ_PLANE:
+        scale = llmin(mGridScale.mV[VX], mGridScale.mV[VZ]);
+        break;
+    case LL_XY_PLANE:
+        scale = llmin(mGridScale.mV[VX], mGridScale.mV[VY]);
+        break;
+    }
+
+    return scale;
+}
+
+
+BOOL LLManipTranslate::handleMouseUp(S32 x, S32 y, MASK mask)
+{
+    // first, perform normal processing in case this was a quick-click
+    handleHover(x, y, mask);
+
+    if(hasMouseCapture())
+    {
+        // make sure arrow colors go back to normal
+        mManipPart = LL_NO_PART;
+        LLSelectMgr::getInstance()->enableSilhouette(TRUE);
+
+        // Might have missed last update due to UPDATE_DELAY timing.
+        LLSelectMgr::getInstance()->sendMultipleUpdate( UPD_POSITION );
+
+        mInSnapRegime = FALSE;
+        LLSelectMgr::getInstance()->saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+        //gAgent.setObjectTracking(gSavedSettings.getBOOL("TrackFocusObject"));
+    }
+
+    return LLManip::handleMouseUp(x, y, mask);
+}
+
+
+void LLManipTranslate::render()
+{
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        F32 zoom = gAgentCamera.mHUDCurZoom;
+        gGL.scalef(zoom, zoom, zoom);
+    }
+    {
+        LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
+        renderGuidelines();
+    }
+    {
+        //LLGLDisable gls_stencil(GL_STENCIL_TEST);
+        renderTranslationHandles();
+        renderSnapGuides();
+    }
+    gGL.popMatrix();
+
+    renderText();
+}
+
+void LLManipTranslate::renderSnapGuides()
+{
+    if (!ALControlCache::SnapEnabled)
+    {
+        return;
+    }
+
+    F32 max_subdivisions = sGridMaxSubdivisionLevel;//(F32)gSavedSettings.getS32("GridSubdivision");
+    F32 line_alpha = ALControlCache::GridOpacity;
+
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    LLGLDepthTest gls_depth(GL_TRUE);
+    LLGLDisable gls_cull(GL_CULL_FACE);
+    LLVector3 translate_axis;
+
+    if (mManipPart == LL_NO_PART)
+    {
+        return;
+    }
+
+    LLSelectNode *first_node = mObjectSelection->getFirstMoveableNode(TRUE);
+    if (!first_node)
+    {
+        return;
+    }
+
+    updateGridSettings();
+
+    F32 smallest_grid_unit_scale = getMinGridScale() / max_subdivisions;
+    LLVector3 grid_origin;
+    LLVector3 grid_scale;
+    LLQuaternion grid_rotation;
+
+    LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
+    LLVector3 saved_selection_center = getSavedPivotPoint(); //LLSelectMgr::getInstance()->getSavedBBoxOfSelection().getCenterAgent();
+    LLVector3 selection_center = getPivotPoint();
+
+    LLViewerObject *first_object = first_node->getObject();
+
+    //pick appropriate projection plane for snap rulers according to relative camera position
+    if (mManipPart >= LL_X_ARROW && mManipPart <= LL_Z_ARROW)
+    {
+        LLVector3 normal;
+        LLColor4 inner_color;
+        LLManip::EManipPart temp_manip = mManipPart;
+        switch (mManipPart)
+        {
+        case LL_X_ARROW:
+            normal.setVec(1,0,0);
+            inner_color.setVec(0,1,1,line_alpha);
+            mManipPart = LL_YZ_PLANE;
+            break;
+        case LL_Y_ARROW:
+            normal.setVec(0,1,0);
+            inner_color.setVec(1,0,1,line_alpha);
+            mManipPart = LL_XZ_PLANE;
+            break;
+        case LL_Z_ARROW:
+            normal.setVec(0,0,1);
+            inner_color.setVec(1,1,0,line_alpha);
+            mManipPart = LL_XY_PLANE;
+            break;
+        default:
+            break;
+        }
+
+        highlightIntersection(normal, selection_center, grid_rotation, inner_color);
+        mManipPart = temp_manip;
+        getManipAxis(first_object, mManipPart, translate_axis);
+
+        LLVector3 at_axis_abs;
+        if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+        {
+            at_axis_abs = LLVector3::x_axis * ~grid_rotation;
+        }
+        else
+        {
+            at_axis_abs = saved_selection_center - LLViewerCamera::getInstance()->getOrigin();
+            at_axis_abs.normVec();
+
+            at_axis_abs = at_axis_abs * ~grid_rotation;
+        }
+        at_axis_abs.abs();
+
+        if (at_axis_abs.mV[VX] > at_axis_abs.mV[VY] && at_axis_abs.mV[VX] > at_axis_abs.mV[VZ])
+        {
+            if (mManipPart == LL_Y_ARROW)
+            {
+                mSnapOffsetAxis = LLVector3::z_axis;
+            }
+            else if (mManipPart == LL_Z_ARROW)
+            {
+                mSnapOffsetAxis = LLVector3::y_axis;
+            }
+            else if (at_axis_abs.mV[VY] > at_axis_abs.mV[VZ])
+            {
+                mSnapOffsetAxis = LLVector3::z_axis;
+            }
+            else
+            {
+                mSnapOffsetAxis = LLVector3::y_axis;
+            }
+        }
+        else if (at_axis_abs.mV[VY] > at_axis_abs.mV[VZ])
+        {
+            if (mManipPart == LL_X_ARROW)
+            {
+                mSnapOffsetAxis = LLVector3::z_axis;
+            }
+            else if (mManipPart == LL_Z_ARROW)
+            {
+                mSnapOffsetAxis = LLVector3::x_axis;
+            }
+            else if (at_axis_abs.mV[VX] > at_axis_abs.mV[VZ])
+            {
+                mSnapOffsetAxis = LLVector3::z_axis;
+            }
+            else
+            {
+                mSnapOffsetAxis = LLVector3::x_axis;
+            }
+        }
+        else
+        {
+            if (mManipPart == LL_X_ARROW)
+            {
+                mSnapOffsetAxis = LLVector3::y_axis;
+            }
+            else if (mManipPart == LL_Y_ARROW)
+            {
+                mSnapOffsetAxis = LLVector3::x_axis;
+            }
+            else if (at_axis_abs.mV[VX] > at_axis_abs.mV[VY])
+            {
+                mSnapOffsetAxis = LLVector3::y_axis;
+            }
+            else
+            {
+                mSnapOffsetAxis = LLVector3::x_axis;
+            }
+        }
+
+        mSnapOffsetAxis = mSnapOffsetAxis * grid_rotation;
+
+        F32 guide_size_meters;
+
+        if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+        {
+            guide_size_meters = 1.f / gAgentCamera.mHUDCurZoom;
+            mSnapOffsetMeters = mArrowLengthMeters * 1.5f;
+        }
+        else
+        {
+            LLVector3 cam_to_selection = getPivotPoint() - LLViewerCamera::getInstance()->getOrigin();
+            F32 current_range = cam_to_selection.normVec();
+            guide_size_meters = SNAP_GUIDE_SCREEN_SIZE * gViewerWindow->getWorldViewHeightRaw() * current_range / LLViewerCamera::getInstance()->getPixelMeterRatio();
+
+            F32 fraction_of_fov = mAxisArrowLength / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels();
+            F32 apparent_angle = fraction_of_fov * LLViewerCamera::getInstance()->getView();  // radians
+            F32 offset_at_camera = tan(apparent_angle) * 1.5f;
+            F32 range = dist_vec(gAgent.getPosAgentFromGlobal(first_node->mSavedPositionGlobal), LLViewerCamera::getInstance()->getOrigin());
+            mSnapOffsetMeters = range * offset_at_camera;
+        }
+
+        LLVector3 tick_start;
+        LLVector3 tick_end;
+
+        // how far away from grid origin is the selection along the axis of translation?
+        F32 dist_grid_axis = (selection_center - mGridOrigin) * translate_axis;
+        // find distance to nearest smallest grid unit
+        F32 offset_nearest_grid_unit = fmodf(dist_grid_axis, smallest_grid_unit_scale);
+        // how many smallest grid units are we away from largest grid scale?
+        S32 sub_div_offset = ll_round(fmodf(dist_grid_axis - offset_nearest_grid_unit, getMinGridScale() / sGridMinSubdivisionLevel) / smallest_grid_unit_scale);
+        S32 num_ticks_per_side = llmax(1, llfloor(0.5f * guide_size_meters / smallest_grid_unit_scale));
+
+        LLGLDepthTest gls_depth(GL_FALSE);
+
+        for (S32 pass = 0; pass < 3; pass++)
+        {
+            LLColor4 line_color = setupSnapGuideRenderPass(pass);
+            LLGLDepthTest gls_depth(pass != 1);
+
+            gGL.begin(LLRender::LINES);
+            {
+                LLVector3 line_start = selection_center + (mSnapOffsetMeters * mSnapOffsetAxis) + (translate_axis * (guide_size_meters * 0.5f + offset_nearest_grid_unit));
+                LLVector3 line_end = selection_center + (mSnapOffsetMeters * mSnapOffsetAxis) - (translate_axis * (guide_size_meters * 0.5f + offset_nearest_grid_unit));
+                LLVector3 line_mid = (line_start + line_end) * 0.5f;
+
+                gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW] * 0.2f);
+                gGL.vertex3fv(line_start.mV);
+                gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
+                gGL.vertex3fv(line_mid.mV);
+                gGL.vertex3fv(line_mid.mV);
+                gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW] * 0.2f);
+                gGL.vertex3fv(line_end.mV);
+
+                line_start.setVec(selection_center + (mSnapOffsetAxis * -mSnapOffsetMeters) + (translate_axis * guide_size_meters * 0.5f));
+                line_end.setVec(selection_center + (mSnapOffsetAxis * -mSnapOffsetMeters) - (translate_axis * guide_size_meters * 0.5f));
+                line_mid = (line_start + line_end) * 0.5f;
+
+                gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW] * 0.2f);
+                gGL.vertex3fv(line_start.mV);
+                gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
+                gGL.vertex3fv(line_mid.mV);
+                gGL.vertex3fv(line_mid.mV);
+                gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW] * 0.2f);
+                gGL.vertex3fv(line_end.mV);
+
+                for (S32 i = -num_ticks_per_side; i <= num_ticks_per_side; i++)
+                {
+                    tick_start = selection_center + (translate_axis * (smallest_grid_unit_scale * (F32)i - offset_nearest_grid_unit));
+
+                    //No need check this condition to prevent tick position scaling (FIX MAINT-5207/5208)
+                    //F32 cur_subdivisions = getSubdivisionLevel(tick_start, translate_axis, getMinGridScale());
+                    /*if (fmodf((F32)(i + sub_div_offset), (max_subdivisions / cur_subdivisions)) != 0.f)
+                    {
+                        continue;
+                    }*/
+
+                    // add in off-axis offset
+                    tick_start += (mSnapOffsetAxis * mSnapOffsetMeters);
+
+                    F32 tick_scale = 1.f;
+                    for (F32 division_level = max_subdivisions; division_level >= sGridMinSubdivisionLevel; division_level /= 2.f)
+                    {
+                        if (fmodf((F32)(i + sub_div_offset), division_level) == 0.f)
+                        {
+                            break;
+                        }
+                        tick_scale *= 0.7f;
+                    }
+
+//                  S32 num_ticks_to_fade = is_sub_tick ? num_ticks_per_side / 2 : num_ticks_per_side;
+//                  F32 alpha = line_alpha * (1.f - (0.8f *  ((F32)llabs(i) / (F32)num_ticks_to_fade)));
+
+                    tick_end = tick_start + (mSnapOffsetAxis * mSnapOffsetMeters * tick_scale);
+
+                    gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
+                    gGL.vertex3fv(tick_start.mV);
+                    gGL.vertex3fv(tick_end.mV);
+
+                    tick_start = selection_center + (mSnapOffsetAxis * -mSnapOffsetMeters) +
+                        (translate_axis * (getMinGridScale() / (F32)(max_subdivisions) * (F32)i - offset_nearest_grid_unit));
+                    tick_end = tick_start - (mSnapOffsetAxis * mSnapOffsetMeters * tick_scale);
+
+                    gGL.vertex3fv(tick_start.mV);
+                    gGL.vertex3fv(tick_end.mV);
+                }
+            }
+            gGL.end();
+
+            if (mInSnapRegime)
+            {
+                LLVector3 line_start = selection_center - mSnapOffsetAxis * mSnapOffsetMeters;
+                LLVector3 line_end = selection_center + mSnapOffsetAxis * mSnapOffsetMeters;
+
+                gGL.begin(LLRender::LINES);
+                {
+                    gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
+
+                    gGL.vertex3fv(line_start.mV);
+                    gGL.vertex3fv(line_end.mV);
+                }
+                gGL.end();
+
+                // draw snap guide arrow
+                gGL.begin(LLRender::TRIANGLES);
+                {
+                    gGL.color4f(line_color.mV[VX], line_color.mV[VY], line_color.mV[VZ], line_color.mV[VW]);
+
+                    LLVector3 arrow_dir;
+                    LLVector3 arrow_span = translate_axis;
+
+                    arrow_dir = -mSnapOffsetAxis;
+                    gGL.vertex3fv((line_start + arrow_dir * mConeSize * SNAP_ARROW_SCALE).mV);
+                    gGL.vertex3fv((line_start + arrow_span * mConeSize * SNAP_ARROW_SCALE).mV);
+                    gGL.vertex3fv((line_start - arrow_span * mConeSize * SNAP_ARROW_SCALE).mV);
+
+                    arrow_dir = mSnapOffsetAxis;
+                    gGL.vertex3fv((line_end + arrow_dir * mConeSize * SNAP_ARROW_SCALE).mV);
+                    gGL.vertex3fv((line_end + arrow_span * mConeSize * SNAP_ARROW_SCALE).mV);
+                    gGL.vertex3fv((line_end - arrow_span * mConeSize * SNAP_ARROW_SCALE).mV);
+                }
+                gGL.end();
+            }
+        }
+
+        sub_div_offset = ll_round(fmod(dist_grid_axis - offset_nearest_grid_unit, getMinGridScale() * 32.f) / smallest_grid_unit_scale);
+
+        LLVector2 screen_translate_axis(llabs(translate_axis * LLViewerCamera::getInstance()->getLeftAxis()), llabs(translate_axis * LLViewerCamera::getInstance()->getUpAxis()));
+        screen_translate_axis.normVec();
+
+        S32 tick_label_spacing = ll_round(screen_translate_axis * sTickLabelSpacing);
+
+        // render tickmark values
+        for (S32 i = -num_ticks_per_side; i <= num_ticks_per_side; i++)
+        {
+            LLVector3 tick_pos = selection_center + (translate_axis * ((smallest_grid_unit_scale * (F32)i) - offset_nearest_grid_unit));
+            F32 alpha = line_alpha * (1.f - (0.5f *  ((F32)llabs(i) / (F32)num_ticks_per_side)));
+
+            F32 tick_scale = 1.f;
+            for (F32 division_level = max_subdivisions; division_level >= sGridMinSubdivisionLevel; division_level /= 2.f)
+            {
+                if (fmodf((F32)(i + sub_div_offset), division_level) == 0.f)
+                {
+                    break;
+                }
+                tick_scale *= 0.7f;
+            }
+
+            if (fmodf((F32)(i + sub_div_offset), (max_subdivisions / getSubdivisionLevel(tick_pos, translate_axis, getMinGridScale(), tick_label_spacing))) == 0.f)
+            {
+                F32 snap_offset_meters;
+
+                if (mSnapOffsetAxis * LLViewerCamera::getInstance()->getUpAxis() > 0.f)
+                {
+                    snap_offset_meters = mSnapOffsetMeters;
+                }
+                else
+                {
+                    snap_offset_meters = -mSnapOffsetMeters;
+                }
+                LLVector3 text_origin = selection_center +
+                        (translate_axis * ((smallest_grid_unit_scale * (F32)i) - offset_nearest_grid_unit)) +
+                            (mSnapOffsetAxis * snap_offset_meters * (1.f + tick_scale));
+
+                LLVector3 tick_offset = (tick_pos - mGridOrigin) * ~mGridRotation;
+                F32 offset_val = 0.5f * tick_offset.mV[ARROW_TO_AXIS[mManipPart]] / getMinGridScale();
+                EGridMode grid_mode = LLSelectMgr::getInstance()->getGridMode();
+                F32 text_highlight = 0.8f;
+                if(i - ll_round(offset_nearest_grid_unit / smallest_grid_unit_scale) == 0 && mInSnapRegime)
+                {
+                    text_highlight = 1.f;
+                }
+
+                if (grid_mode == GRID_MODE_WORLD)
+                {
+                    // rescale units to meters from multiple of grid scale
+                    offset_val *= 2.f * grid_scale[ARROW_TO_AXIS[mManipPart]];
+                    renderTickValue(text_origin, offset_val, std::string("m"), LLColor4(text_highlight, text_highlight, text_highlight, alpha));
+                }
+                else
+                {
+                    renderTickValue(text_origin, offset_val, std::string("x"), LLColor4(text_highlight, text_highlight, text_highlight, alpha));
+                }
+            }
+        }
+        if (mObjectSelection->getSelectType() != SELECT_TYPE_HUD)
+        {
+            // render helpful text
+            if (mHelpTextTimer.getElapsedTimeF32() < sHelpTextVisibleTime + sHelpTextFadeTime && sNumTimesHelpTextShown < sMaxTimesShowHelpText)
+            {
+                F32 snap_offset_meters_up;
+                if (mSnapOffsetAxis * LLViewerCamera::getInstance()->getUpAxis() > 0.f)
+                {
+                    snap_offset_meters_up = mSnapOffsetMeters;
+                }
+                else
+                {
+                    snap_offset_meters_up = -mSnapOffsetMeters;
+                }
+
+                LLVector3 selection_center_start = getSavedPivotPoint();//LLSelectMgr::getInstance()->getSavedBBoxOfSelection().getCenterAgent();
+
+                LLVector3 help_text_pos = selection_center_start + (snap_offset_meters_up * 3.f * mSnapOffsetAxis);
+                const LLFontGL* big_fontp = LLFontGL::getFontSansSerif();
+
+                static const LLWString translate_help_text = utf8str_to_wstring(LLTrans::getString("manip_hint1"));
+                LLColor4 help_text_color = LLColor4::white;
+                help_text_color.mV[VALPHA] = clamp_rescale(mHelpTextTimer.getElapsedTimeF32(), sHelpTextVisibleTime, sHelpTextVisibleTime + sHelpTextFadeTime, line_alpha, 0.f);
+                hud_render_text(translate_help_text, help_text_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(translate_help_text.c_str()), 3.f, help_text_color, false);
+                static const LLWString translate_help_text2 = utf8str_to_wstring(LLTrans::getString("manip_hint2"));
+                help_text_pos -= LLViewerCamera::getInstance()->getUpAxis() * mSnapOffsetMeters * 0.2f;
+                hud_render_text(translate_help_text2, help_text_pos, *big_fontp, LLFontGL::NORMAL, LLFontGL::NO_SHADOW, -0.5f * big_fontp->getWidthF32(translate_help_text2.c_str()), 3.f, help_text_color, false);
+            }
+        }
+    }
+    else
+    {
+        // render gridlines for planar snapping
+
+        F32 u = 0, v = 0;
+        LLColor4 inner_color;
+        LLVector3 normal;
+        LLVector3 grid_center = selection_center - grid_origin;
+        F32 usc = 1;
+        F32 vsc = 1;
+
+        grid_center *= ~grid_rotation;
+
+        switch (mManipPart)
+        {
+        case LL_YZ_PLANE:
+            u = grid_center.mV[VY];
+            v = grid_center.mV[VZ];
+            usc = grid_scale.mV[VY];
+            vsc = grid_scale.mV[VZ];
+            inner_color.setVec(0,1,1,line_alpha);
+            normal.setVec(1,0,0);
+            break;
+        case LL_XZ_PLANE:
+            u = grid_center.mV[VX];
+            v = grid_center.mV[VZ];
+            usc = grid_scale.mV[VX];
+            vsc = grid_scale.mV[VZ];
+            inner_color.setVec(1,0,1,line_alpha);
+            normal.setVec(0,1,0);
+            break;
+        case LL_XY_PLANE:
+            u = grid_center.mV[VX];
+            v = grid_center.mV[VY];
+            usc = grid_scale.mV[VX];
+            vsc = grid_scale.mV[VY];
+            inner_color.setVec(1,1,0,line_alpha);
+            normal.setVec(0,0,1);
+            break;
+        default:
+            break;
+        }
+
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+        highlightIntersection(normal, selection_center, grid_rotation, inner_color);
+
+        gGL.pushMatrix();
+
+        F32 x,y,z,angle_radians;
+        grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
+        gGL.translatef(selection_center.mV[VX], selection_center.mV[VY], selection_center.mV[VZ]);
+        gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
+
+        F32 sz = mGridSizeMeters;
+        F32 tiles = sz;
+
+        gGL.matrixMode(LLRender::MM_TEXTURE);
+        gGL.pushMatrix();
+        usc = 1.0f/usc;
+        vsc = 1.0f/vsc;
+
+        while (usc > vsc*4.0f)
+        {
+            usc *= 0.5f;
+        }
+        while (vsc > usc * 4.0f)
+        {
+            vsc *= 0.5f;
+        }
+
+        gGL.scalef(usc, vsc, 1.0f);
+        gGL.translatef(u, v, 0);
+
+        float a = line_alpha;
+
+        {
+            //draw grid behind objects
+            LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
+
+            {
+                //LLGLDisable stencil(GL_STENCIL_TEST);
+                {
+                    LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GREATER);
+                    gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, getGridTexName());
+                    gGL.flush();
+                    gGL.blendFunc(LLRender::BF_ZERO, LLRender::BF_ONE_MINUS_SOURCE_ALPHA);
+                    renderGrid(u,v,tiles,0.9f, 0.9f, 0.9f,a*0.15f);
+                    gGL.flush();
+                    gGL.setSceneBlendType(LLRender::BT_ALPHA);
+                }
+
+                {
+                    //draw black overlay
+                    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+                    renderGrid(u,v,tiles,0.0f, 0.0f, 0.0f,a*0.16f);
+
+                    //draw grid top
+                    gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, getGridTexName());
+                    renderGrid(u,v,tiles,1,1,1,a);
+
+                    gGL.popMatrix();
+                    gGL.matrixMode(LLRender::MM_MODELVIEW);
+                    gGL.popMatrix();
+                }
+
+                {
+                    LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
+                    renderGuidelines();
+                }
+
+                {
+                    LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GREATER);
+                    gGL.flush();
+
+                    switch (mManipPart)
+                    {
+                      case LL_YZ_PLANE:
+                        renderGuidelines(FALSE, TRUE, TRUE);
+                        break;
+                      case LL_XZ_PLANE:
+                        renderGuidelines(TRUE, FALSE, TRUE);
+                        break;
+                      case LL_XY_PLANE:
+                        renderGuidelines(TRUE, TRUE, FALSE);
+                        break;
+                      default:
+                        break;
+                    }
+                    gGL.flush();
+                }
+            }
+        }
+    }
+}
+
+void LLManipTranslate::renderGrid(F32 x, F32 y, F32 size, F32 r, F32 g, F32 b, F32 a)
+{
+    F32 d = size*0.5f;
+
+    for (F32 xx = -size-d; xx < size+d; xx += d)
+    {
+        gGL.begin(LLRender::TRIANGLE_STRIP);
+        for (F32 yy = -size-d; yy < size+d; yy += d)
+        {
+            float dx, dy, da;
+
+            dx = xx; dy = yy;
+            da = sqrtf(llmax(0.0f, 1.0f-sqrtf(dx*dx+dy*dy)/size))*a;
+            gGL.texCoord2f(dx, dy);
+            renderGridVert(dx,dy,r,g,b,da);
+
+            dx = xx+d; dy = yy;
+            da = sqrtf(llmax(0.0f, 1.0f-sqrtf(dx*dx+dy*dy)/size))*a;
+            gGL.texCoord2f(dx, dy);
+            renderGridVert(dx,dy,r,g,b,da);
+
+            dx = xx; dy = yy+d;
+            da = sqrtf(llmax(0.0f, 1.0f-sqrtf(dx*dx+dy*dy)/size))*a;
+            gGL.texCoord2f(dx, dy);
+            renderGridVert(dx,dy,r,g,b,da);
+
+            dx = xx+d; dy = yy+d;
+            da = sqrtf(llmax(0.0f, 1.0f-sqrtf(dx*dx+dy*dy)/size))*a;
+            gGL.texCoord2f(dx, dy);
+            renderGridVert(dx,dy,r,g,b,da);
+        }
+        gGL.end();
+    }
+
+
+}
+
+void LLManipTranslate::highlightIntersection(LLVector3 normal,
+                                             LLVector3 selection_center,
+                                             LLQuaternion grid_rotation,
+                                             LLColor4 inner_color)
+{
+#if 0 // DEPRECATED
+    if (!gSavedSettings.getBOOL("GridCrossSections"))
+    {
+        return;
+    }
+
+
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+
+
+    static const U32 types[] = { LLRenderPass::PASS_SIMPLE, LLRenderPass::PASS_ALPHA, LLRenderPass::PASS_FULLBRIGHT, LLRenderPass::PASS_SHINY };
+    static const U32 num_types = LL_ARRAY_SIZE(types);
+
+    GLuint stencil_mask = 0xFFFFFFFF;
+    //stencil in volumes
+
+    gGL.flush();
+
+    if (shader)
+    {
+        gClipProgram.bind();
+    }
+
+    {
+        //glStencilMask(stencil_mask); //deprecated
+        //glClearStencil(1);
+        //glClear(GL_STENCIL_BUFFER_BIT);
+        LLGLEnable cull_face(GL_CULL_FACE);
+        //LLGLEnable stencil(GL_STENCIL_TEST);
+        LLGLDepthTest depth (GL_TRUE, GL_FALSE, GL_ALWAYS);
+        //glStencilFunc(GL_ALWAYS, 0, stencil_mask);
+        gGL.setColorMask(false, false);
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+
+        gGL.diffuseColor4f(1,1,1,1);
+
+        //setup clip plane
+        normal = normal * grid_rotation;
+        if (normal * (LLViewerCamera::getInstance()->getOrigin()-selection_center) < 0)
+        {
+            normal = -normal;
+        }
+        F32 d = -(selection_center * normal);
+        LLVector4a plane(normal.mV[0], normal.mV[1], normal.mV[2], d );
+
+        LLMatrix4a inv_mat = gGL.getModelviewMatrix();
+        inv_mat.invert();
+        inv_mat.transpose();
+        inv_mat.rotate4(plane,plane);
+
+        static LLStaticHashedString sClipPlane("clip_plane");
+        gClipProgram.uniform4fv(sClipPlane, 1, plane.getF32ptr());
+
+        BOOL particles = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
+        BOOL clouds = gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_CLOUDS);
+
+        if (particles)
+        {
+            LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
+        }
+        if (clouds)
+        {
+            LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_CLOUDS);
+        }
+
+        //stencil in volumes
+        //glStencilOp(GL_INCR, GL_INCR, GL_INCR);
+        glCullFace(GL_FRONT);
+        for (U32 i = 0; i < num_types; i++)
+        {
+            gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, FALSE);
+        }
+
+        //glStencilOp(GL_DECR, GL_DECR, GL_DECR);
+        glCullFace(GL_BACK);
+        for (U32 i = 0; i < num_types; i++)
+        {
+            gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, FALSE);
+        }
+
+        if (particles)
+        {
+            LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
+        }
+        if (clouds)
+        {
+            LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_CLOUDS);
+        }
+
+        gGL.setColorMask(true, false);
+    }
+    gGL.color4f(1,1,1,1);
+
+    gGL.pushMatrix();
+
+    F32 x,y,z,angle_radians;
+    grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
+    gGL.translatef(selection_center.mV[VX], selection_center.mV[VY], selection_center.mV[VZ]);
+    gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
+
+    F32 sz = mGridSizeMeters;
+    F32 tiles = sz;
+
+    if (shader)
+    {
+        shader->bind();
+    }
+
+    //draw volume/plane intersections
+    {
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+        LLGLDepthTest depth(GL_FALSE);
+        //LLGLEnable stencil(GL_STENCIL_TEST);
+        glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
+        glStencilFunc(GL_EQUAL, 0, stencil_mask);
+        renderGrid(0,0,tiles,inner_color.mV[0], inner_color.mV[1], inner_color.mV[2], 0.25f);
+    }
+
+    glStencilFunc(GL_ALWAYS, 255, 0xFFFFFFFF);
+    glStencilMask(0xFFFFFFFF);
+    glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+
+    gGL.popMatrix();
+#endif
+}
+
+void LLManipTranslate::renderText()
+{
+    if (mObjectSelection->getRootObjectCount() && !mObjectSelection->isAttachment())
+    {
+        LLVector3 pos = getPivotPoint();
+        renderXYZ(pos);
+    }
+    else
+    {
+        const BOOL children_ok = TRUE;
+        LLViewerObject* objectp = mObjectSelection->getFirstRootObject(children_ok);
+        if (objectp)
+        {
+            renderXYZ(objectp->getPositionEdit());
+        }
+    }
+}
+
+void LLManipTranslate::renderTranslationHandles()
+{
+    LLVector3 grid_origin;
+    LLVector3 grid_scale;
+    LLQuaternion grid_rotation;
+    LLGLDepthTest gls_depth(GL_FALSE);
+
+    LLSelectMgr::getInstance()->getGrid(grid_origin, grid_rotation, grid_scale);
+    LLVector3 at_axis;
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        at_axis = LLVector3::x_axis * ~grid_rotation;
+    }
+    else
+    {
+        at_axis = LLViewerCamera::getInstance()->getAtAxis() * ~grid_rotation;
+    }
+
+    if (at_axis.mV[VX] > 0.f)
+    {
+        mPlaneManipPositions.mV[VX] = 1.f;
+    }
+    else
+    {
+        mPlaneManipPositions.mV[VX] = -1.f;
+    }
+
+    if (at_axis.mV[VY] > 0.f)
+    {
+        mPlaneManipPositions.mV[VY] = 1.f;
+    }
+    else
+    {
+        mPlaneManipPositions.mV[VY] = -1.f;
+    }
+
+    if (at_axis.mV[VZ] > 0.f)
+    {
+        mPlaneManipPositions.mV[VZ] = 1.f;
+    }
+    else
+    {
+        mPlaneManipPositions.mV[VZ] = -1.f;
+    }
+
+    LLViewerObject *first_object = mObjectSelection->getFirstMoveableObject(TRUE);
+    if (!first_object) return;
+
+    LLVector3 selection_center = getPivotPoint();
+
+    // Drag handles
+    if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+    {
+        mArrowLengthMeters = mAxisArrowLength / gViewerWindow->getWorldViewHeightRaw();
+        mArrowLengthMeters /= gAgentCamera.mHUDCurZoom;
+    }
+    else
+    {
+        LLVector3 camera_pos_agent = gAgentCamera.getCameraPositionAgent();
+        F32 range = dist_vec(camera_pos_agent, selection_center);
+        F32 range_from_agent = dist_vec(gAgent.getPositionAgent(), selection_center);
+
+        // Don't draw handles if you're too far away
+        if (ALControlCache::LimitSelectDistance)
+        {
+            if (range_from_agent > ALControlCache::MaxSelectDistance)
+            {
+                return;
+            }
+        }
+
+        if (range > 0.001f)
+        {
+            // range != zero
+            F32 fraction_of_fov = mAxisArrowLength / (F32) LLViewerCamera::getInstance()->getViewHeightInPixels();
+            F32 apparent_angle = fraction_of_fov * LLViewerCamera::getInstance()->getView();  // radians
+            mArrowLengthMeters = range * tan(apparent_angle);
+        }
+        else
+        {
+            // range == zero
+            mArrowLengthMeters = 1.0f;
+        }
+    }
+    //Assume that UI scale factor is equivalent for X and Y axis
+    F32 ui_scale_factor = LLUI::getScaleFactor().mV[VX];
+    mArrowLengthMeters *= ui_scale_factor;
+
+    mPlaneManipOffsetMeters = mArrowLengthMeters * 1.8f;
+    mGridSizeMeters = ALControlCache::GridDrawSize;
+    mConeSize = mArrowLengthMeters / 4.f;
+
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+    {
+        gGL.translatef(selection_center.mV[VX], selection_center.mV[VY], selection_center.mV[VZ]);
+
+        F32 angle_radians, x, y, z;
+        grid_rotation.getAngleAxis(&angle_radians, &x, &y, &z);
+
+        gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
+
+        LLQuaternion invRotation = grid_rotation;
+        invRotation.conjQuat();
+
+        LLVector3 relative_camera_dir;
+
+        if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+        {
+            relative_camera_dir = LLVector3::x_axis * invRotation;
+        }
+        else
+        {
+            relative_camera_dir = (selection_center - LLViewerCamera::getInstance()->getOrigin()) * invRotation;
+        }
+        relative_camera_dir.normVec();
+
+        {
+            gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+            LLGLDisable cull_face(GL_CULL_FACE);
+
+            LLColor4 color1;
+            LLColor4 color2;
+
+            // update manipulator sizes
+            for (S32 index = 0; index < 3; index++)
+            {
+                if (index == mManipPart - LL_X_ARROW || index == mHighlightedPart - LL_X_ARROW)
+                {
+                    mArrowScales.mV[index] = ll_lerp(mArrowScales.mV[index], SELECTED_ARROW_SCALE, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
+                    mPlaneScales.mV[index] = ll_lerp(mPlaneScales.mV[index], 1.f, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
+                }
+                else if (index == mManipPart - LL_YZ_PLANE || index == mHighlightedPart - LL_YZ_PLANE)
+                {
+                    mArrowScales.mV[index] = ll_lerp(mArrowScales.mV[index], 1.f, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
+                    mPlaneScales.mV[index] = ll_lerp(mPlaneScales.mV[index], SELECTED_ARROW_SCALE, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
+                }
+                else
+                {
+                    mArrowScales.mV[index] = ll_lerp(mArrowScales.mV[index], 1.f, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
+                    mPlaneScales.mV[index] = ll_lerp(mPlaneScales.mV[index], 1.f, LLSmoothInterpolation::getInterpolant(MANIPULATOR_SCALE_HALF_LIFE ));
+                }
+            }
+
+            if ((mManipPart == LL_NO_PART || mManipPart == LL_YZ_PLANE) && llabs(relative_camera_dir.mV[VX]) > MIN_PLANE_MANIP_DOT_PRODUCT)
+            {
+                // render YZ plane manipulator
+                gGL.pushMatrix();
+                gGL.scalef(mPlaneManipPositions.mV[VX], mPlaneManipPositions.mV[VY], mPlaneManipPositions.mV[VZ]);
+                gGL.translatef(0.f, mPlaneManipOffsetMeters, mPlaneManipOffsetMeters);
+                gGL.scalef(mPlaneScales.mV[VX], mPlaneScales.mV[VX], mPlaneScales.mV[VX]);
+                if (mHighlightedPart == LL_YZ_PLANE)
+                {
+                    color1.setVec(0.f, 1.f, 0.f, 1.f);
+                    color2.setVec(0.f, 0.f, 1.f, 1.f);
+                }
+                else
+                {
+                    color1.setVec(0.f, 1.f, 0.f, 0.6f);
+                    color2.setVec(0.f, 0.f, 1.f, 0.6f);
+                }
+                gGL.begin(LLRender::TRIANGLES);
+                {
+                    gGL.color4fv(color1.mV);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f));
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f));
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
+
+                    gGL.color4fv(color2.mV);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f), mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f));
+                }
+                gGL.end();
+
+                LLUI::setLineWidth(3.0f);
+                gGL.begin(LLRender::LINES);
+                {
+                    gGL.color4f(0.f, 0.f, 0.f, 0.3f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.1f,   mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.1f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.1f,   mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.4f);
+
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.1f,  mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.1f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.4f,  mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.1f);
+                }
+                gGL.end();
+                LLUI::setLineWidth(1.0f);
+                gGL.popMatrix();
+            }
+
+            if ((mManipPart == LL_NO_PART || mManipPart == LL_XZ_PLANE) && llabs(relative_camera_dir.mV[VY]) > MIN_PLANE_MANIP_DOT_PRODUCT)
+            {
+                // render XZ plane manipulator
+                gGL.pushMatrix();
+                gGL.scalef(mPlaneManipPositions.mV[VX], mPlaneManipPositions.mV[VY], mPlaneManipPositions.mV[VZ]);
+                gGL.translatef(mPlaneManipOffsetMeters, 0.f, mPlaneManipOffsetMeters);
+                gGL.scalef(mPlaneScales.mV[VY], mPlaneScales.mV[VY], mPlaneScales.mV[VY]);
+                if (mHighlightedPart == LL_XZ_PLANE)
+                {
+                    color1.setVec(0.f, 0.f, 1.f, 1.f);
+                    color2.setVec(1.f, 0.f, 0.f, 1.f);
+                }
+                else
+                {
+                    color1.setVec(0.f, 0.f, 1.f, 0.6f);
+                    color2.setVec(1.f, 0.f, 0.f, 0.6f);
+                }
+
+                gGL.begin(LLRender::TRIANGLES);
+                {
+                    gGL.color4fv(color1.mV);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f), 0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
+                    gGL.vertex3f(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f), 0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
+                    gGL.vertex3f(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f));
+
+                    gGL.color4fv(color2.mV);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f));
+                    gGL.vertex3f(mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f),   0.f, mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f));
+                    gGL.vertex3f(mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f),   0.f, mPlaneManipOffsetMeters * (PLANE_TICK_SIZE * 0.25f));
+                }
+                gGL.end();
+
+                LLUI::setLineWidth(3.0f);
+                gGL.begin(LLRender::LINES);
+                {
+                    gGL.color4f(0.f, 0.f, 0.f, 0.3f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.1f,   0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.1f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * PLANE_TICK_SIZE  * 0.1f,   0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.4f);
+
+                    gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.1f,   0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.1f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.25f,  0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.25f);
+                    gGL.vertex3f(mPlaneManipOffsetMeters * -PLANE_TICK_SIZE * 0.4f,   0.f, mPlaneManipOffsetMeters * PLANE_TICK_SIZE * 0.1f);
+                }
+                gGL.end();
+                LLUI::setLineWidth(1.0f);
+
+                gGL.popMatrix();
+            }
+
+            if ((mManipPart == LL_NO_PART || mManipPart == LL_XY_PLANE) && llabs(relative_camera_dir.mV[VZ]) > MIN_PLANE_MANIP_DOT_PRODUCT)
+            {
+                // render XY plane manipulator
+                gGL.pushMatrix();
+                gGL.scalef(mPlaneManipPositions.mV[VX], mPlaneManipPositions.mV[VY], mPlaneManipPositions.mV[VZ]);
+
+/*                            Y
+                              ^
+                              v1
+                              |  \
+                              |<- v0
+                              |  /| \
+                              v2__v__v3 > X
+*/
+                    LLVector3 v0,v1,v2,v3;
+#if 0
+                    // This should theoretically work but looks off; could be tuned later -SJB
+                    gGL.translatef(-mPlaneManipOffsetMeters, -mPlaneManipOffsetMeters, 0.f);
+                    v0 = LLVector3(mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), 0.f);
+                    v1 = LLVector3(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.75f), 0.f);
+                    v2 = LLVector3(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f);
+                    v3 = LLVector3(mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.75f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f);
+#else
+                    gGL.translatef(mPlaneManipOffsetMeters, mPlaneManipOffsetMeters, 0.f);
+                    v0 = LLVector3(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.25f), 0.f);
+                    v1 = LLVector3(mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f), 0.f);
+                    v2 = LLVector3(mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), 0.f);
+                    v3 = LLVector3(mPlaneManipOffsetMeters * (-PLANE_TICK_SIZE * 0.75f), mPlaneManipOffsetMeters * ( PLANE_TICK_SIZE * 0.25f), 0.f);
+#endif
+                    gGL.scalef(mPlaneScales.mV[VZ], mPlaneScales.mV[VZ], mPlaneScales.mV[VZ]);
+                    if (mHighlightedPart == LL_XY_PLANE)
+                    {
+                        color1.setVec(1.f, 0.f, 0.f, 1.f);
+                        color2.setVec(0.f, 1.f, 0.f, 1.f);
+                    }
+                    else
+                    {
+                        color1.setVec(0.8f, 0.f, 0.f, 0.6f);
+                        color2.setVec(0.f, 0.8f, 0.f, 0.6f);
+                    }
+
+                    gGL.begin(LLRender::TRIANGLES);
+                    {
+                        gGL.color4fv(color1.mV);
+                        gGL.vertex3fv(v0.mV);
+                        gGL.vertex3fv(v1.mV);
+                        gGL.vertex3fv(v2.mV);
+
+                        gGL.color4fv(color2.mV);
+                        gGL.vertex3fv(v2.mV);
+                        gGL.vertex3fv(v3.mV);
+                        gGL.vertex3fv(v0.mV);
+                    }
+                    gGL.end();
+
+                    LLUI::setLineWidth(3.0f);
+                    gGL.begin(LLRender::LINES);
+                    {
+                        gGL.color4f(0.f, 0.f, 0.f, 0.3f);
+                        LLVector3 v12 = (v1 + v2) * .5f;
+                        gGL.vertex3fv(v0.mV);
+                        gGL.vertex3fv(v12.mV);
+                        gGL.vertex3fv(v12.mV);
+                        gGL.vertex3fv((v12 + (v0-v12)*.3f + (v2-v12)*.3f).mV);
+                        gGL.vertex3fv(v12.mV);
+                        gGL.vertex3fv((v12 + (v0-v12)*.3f + (v1-v12)*.3f).mV);
+
+                        LLVector3 v23 = (v2 + v3) * .5f;
+                        gGL.vertex3fv(v0.mV);
+                        gGL.vertex3fv(v23.mV);
+                        gGL.vertex3fv(v23.mV);
+                        gGL.vertex3fv((v23 + (v0-v23)*.3f + (v3-v23)*.3f).mV);
+                        gGL.vertex3fv(v23.mV);
+                        gGL.vertex3fv((v23 + (v0-v23)*.3f + (v2-v23)*.3f).mV);
+                    }
+                    gGL.end();
+                    LLUI::setLineWidth(1.0f);
+
+                gGL.popMatrix();
+            }
+        }
+        {
+            gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+
+            // Since we draw handles with depth testing off, we need to draw them in the
+            // proper depth order.
+
+            // Copied from LLDrawable::updateGeometry
+            LLVector3 pos_agent     = first_object->getPositionAgent();
+            LLVector3 camera_agent  = gAgentCamera.getCameraPositionAgent();
+            LLVector3 headPos       = pos_agent - camera_agent;
+
+            LLVector3 orientWRTHead    = headPos * invRotation;
+
+            // Find nearest vertex
+            U32 nearest = (orientWRTHead.mV[0] < 0.0f ? 1 : 0) +
+                (orientWRTHead.mV[1] < 0.0f ? 2 : 0) +
+                (orientWRTHead.mV[2] < 0.0f ? 4 : 0);
+
+            // opposite faces on Linden cubes:
+            // 0 & 5
+            // 1 & 3
+            // 2 & 4
+
+            // Table of order to draw faces, based on nearest vertex
+            static U32 face_list[8][NUM_AXES*2] = {
+                { 2,0,1, 4,5,3 }, // v6  F201 F453
+                { 2,0,3, 4,5,1 }, // v7  F203 F451
+                { 4,0,1, 2,5,3 }, // v5  F401 F253
+                { 4,0,3, 2,5,1 }, // v4  F403 F251
+                { 2,5,1, 4,0,3 }, // v2  F251 F403
+                { 2,5,3, 4,0,1 }, // v3  F253 F401
+                { 4,5,1, 2,0,3 }, // v1  F451 F203
+                { 4,5,3, 2,0,1 }, // v0  F453 F201
+            };
+            static const EManipPart which_arrow[6] = {
+                LL_Z_ARROW,
+                LL_X_ARROW,
+                LL_Y_ARROW,
+                LL_X_ARROW,
+                LL_Y_ARROW,
+                LL_Z_ARROW};
+
+            // draw arrows for deeper faces first, closer faces last
+            LLVector3 camera_axis;
+            if (mObjectSelection->getSelectType() == SELECT_TYPE_HUD)
+            {
+                camera_axis = LLVector3::x_axis;
+            }
+            else
+            {
+                camera_axis.setVec(gAgentCamera.getCameraPositionAgent() - first_object->getPositionAgent());
+            }
+
+            for (U32 i = 0; i < NUM_AXES*2; i++)
+            {
+                U32 face = face_list[nearest][i];
+
+                LLVector3 arrow_axis;
+                getManipAxis(first_object, which_arrow[face], arrow_axis);
+
+                renderArrow(which_arrow[face],
+                            mManipPart,
+                            (face >= 3) ? -mConeSize : mConeSize,
+                            (face >= 3) ? -mArrowLengthMeters : mArrowLengthMeters,
+                            mConeSize,
+                            FALSE);
+            }
+        }
+    }
+    gGL.popMatrix();
+}
+
+
+void LLManipTranslate::renderArrow(S32 which_arrow, S32 selected_arrow, F32 box_size, F32 arrow_size, F32 handle_size, BOOL reverse_direction)
+{
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    LLGLEnable gls_blend(GL_BLEND);
+
+    for (S32 pass = 1; pass <= 2; pass++)
+    {
+        LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, pass == 1 ? GL_LEQUAL : GL_GREATER);
+        gGL.pushMatrix();
+
+        S32 index = 0;
+
+        index = ARROW_TO_AXIS[which_arrow];
+
+        // assign a color for this arrow
+        LLColor4 color;  // black
+        if (which_arrow == selected_arrow || which_arrow == mHighlightedPart)
+        {
+            color.mV[index] = (pass == 1) ? 1.f : 0.5f;
+        }
+        else if (selected_arrow != LL_NO_PART)
+        {
+            color.mV[VALPHA] = 0.f;
+        }
+        else
+        {
+            color.mV[index] = pass == 1 ? .8f : .35f ;          // red, green, or blue
+            color.mV[VALPHA] = 0.6f;
+        }
+        gGL.color4fv( color.mV );
+
+        LLVector3 vec;
+
+        {
+            LLUI::setLineWidth(2.0f);
+            gGL.begin(LLRender::LINES);
+                vec.mV[index] = box_size;
+                gGL.vertex3f(vec.mV[0], vec.mV[1], vec.mV[2]);
+
+                vec.mV[index] = arrow_size;
+                gGL.vertex3f(vec.mV[0], vec.mV[1], vec.mV[2]);
+            gGL.end();
+            LLUI::setLineWidth(1.0f);
+        }
+
+        gGL.translatef(vec.mV[0], vec.mV[1], vec.mV[2]);
+        gGL.scalef(handle_size, handle_size, handle_size);
+
+        F32 rot = 0.0f;
+        LLVector3 axis;
+
+        switch(which_arrow)
+        {
+        case LL_X_ARROW:
+            rot = reverse_direction ? -90.0f : 90.0f;
+            axis.mV[1] = 1.0f;
+            break;
+        case LL_Y_ARROW:
+            rot = reverse_direction ? 90.0f : -90.0f;
+            axis.mV[0] = 1.0f;
+            break;
+        case LL_Z_ARROW:
+            rot = reverse_direction ? 180.0f : 0.0f;
+            axis.mV[0] = 1.0f;
+            break;
+        default:
+            LL_ERRS() << "renderArrow called with bad arrow " << which_arrow << LL_ENDL;
+            break;
+        }
+
+        gGL.diffuseColor4fv(color.mV);
+        gGL.rotatef(rot, axis.mV[0], axis.mV[1], axis.mV[2]);
+        gGL.scalef(mArrowScales.mV[index], mArrowScales.mV[index], mArrowScales.mV[index] * 1.5f);
+
+        gCone.render();
+
+        gGL.popMatrix();
+    }
+}
+
+void LLManipTranslate::renderGridVert(F32 x_trans, F32 y_trans, F32 r, F32 g, F32 b, F32 alpha)
+{
+    gGL.color4f(r, g, b, alpha);
+    switch (mManipPart)
+    {
+    case LL_YZ_PLANE:
+        gGL.vertex3f(0, x_trans, y_trans);
+        break;
+    case LL_XZ_PLANE:
+        gGL.vertex3f(x_trans, 0, y_trans);
+        break;
+    case LL_XY_PLANE:
+        gGL.vertex3f(x_trans, y_trans, 0);
+        break;
+    default:
+        gGL.vertex3f(0,0,0);
+        break;
+    }
+
+}
+
+// virtual
+BOOL LLManipTranslate::canAffectSelection()
+{
+    BOOL can_move = mObjectSelection->getObjectCount() != 0;
+    if (can_move)
+    {
+        struct f : public LLSelectedObjectFunctor
+        {
+            virtual bool apply(LLViewerObject* objectp)
+            {
+                LLViewerObject *root_object = (objectp == NULL) ? NULL : objectp->getRootEdit();
+                return objectp->permMove() && !objectp->isPermanentEnforced() &&
+                    ((root_object == NULL) || !root_object->isPermanentEnforced()) &&
+                    (objectp->permModify() || !ALControlCache::EditLinkedParts);
+            }
+        } func;
+        can_move = mObjectSelection->applyToObjects(&func);
+    }
+    return can_move;
 }
diff --git a/indra/newview/llmaterialeditor.cpp b/indra/newview/llmaterialeditor.cpp
index cb61b40714ede4235aa39f5cec985ce5c048aacc..833e856499c4931e4d29dc49f122db0fe12c7948 100644
--- a/indra/newview/llmaterialeditor.cpp
+++ b/indra/newview/llmaterialeditor.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llmaterialeditor.cpp
  * @brief Implementation of the gltf material editor
  *
  * $LicenseInfo:firstyear=2022&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -48,7 +48,7 @@
 #include "llviewertexture.h"
 #include "llsdutil.h"
 #include "llselectmgr.h"
-#include "llstatusbar.h"	// can_afford_transaction()
+#include "llstatusbar.h"    // can_afford_transaction()
 #include "lltoolpie.h"
 #include "llviewerinventory.h"
 #include "llinventory.h"
@@ -513,7 +513,7 @@ BOOL LLMaterialEditor::postBuild()
         // Apply changes to object live
         applyToSelection();
     };
- 
+
     childSetCommitCallback("double sided", changes_callback, (void*)&MATERIAL_DOUBLE_SIDED_DIRTY);
 
     // BaseColor
@@ -561,7 +561,7 @@ BOOL LLMaterialEditor::postBuild()
     // Disable/enable setCanApplyImmediately() based on
     // working from inventory, upload or editing inworld
 
-	return LLPreview::postBuild();
+    return LLPreview::postBuild();
 }
 
 void LLMaterialEditor::onClickCloseBtn(bool app_quitting)
@@ -1301,7 +1301,7 @@ const std::string LLMaterialEditor::buildMaterialDescription()
     desc << LLTrans::getString("Material Texture Name Header");
 
     // add the texture names for each just so long as the material
-    // we loaded has an entry for it (i think testing the texture 
+    // we loaded has an entry for it (i think testing the texture
     // control UUI for NULL is a valid metric for if it was loaded
     // or not but I suspect this code will change a lot so may need
     // to revisit
@@ -1383,7 +1383,7 @@ bool LLMaterialEditor::saveIfNeeded()
         }
     }
     else
-    { 
+    {
         // Make a new inventory item and set upload permissions
         LLPermissions local_permissions;
         local_permissions.init(gAgent.getID(), gAgent.getID(), LLUUID::null, LLUUID::null);
@@ -1412,7 +1412,7 @@ bool LLMaterialEditor::saveIfNeeded()
         // We do not update floater with uploaded asset yet, so just close it.
         closeFloater();
     }
-    
+
     return true;
 }
 
@@ -1827,7 +1827,7 @@ void LLMaterialEditor::onSaveAsMsgCallback(const LLSD& notification, const LLSD&
         }
         else
         {
-            LLNotificationsUtil::add("InvalidMaterialName", LLSD(), LLSD(), [this](const LLSD& notification, const LLSD& response) 
+            LLNotificationsUtil::add("InvalidMaterialName", LLSD(), LLSD(), [this](const LLSD& notification, const LLSD& response)
                 {
                     LLNotificationsUtil::add("SaveMaterialAs", LLSD().with("DESC", mMaterialName), LLSD(),
                         boost::bind(&LLMaterialEditor::onSaveAsMsgCallback, this, _1, _2));
@@ -1991,7 +1991,7 @@ void LLMaterialEditor::loadMaterialFromFile(const std::string& filename, S32 ind
         std::list<std::string> material_list;
         std::vector<tinygltf::Material>::const_iterator mat_iter = model_in.materials.begin();
         std::vector<tinygltf::Material>::const_iterator mat_end = model_in.materials.end();
-        
+
         for (; mat_iter != mat_end; mat_iter++)
         {
             std::string mat_name = mat_iter->name;
@@ -2630,28 +2630,28 @@ bool LLMaterialEditor::setFromGltfModel(const tinygltf::Model& model, S32 index,
 }
 
 /**
- * Build a texture name from the contents of the (in tinyGLFT parlance) 
+ * Build a texture name from the contents of the (in tinyGLFT parlance)
  * Image URI. This often is filepath to the original image on the users'
  *  local file system.
  */
 const std::string LLMaterialEditor::getImageNameFromUri(std::string image_uri, const std::string texture_type)
 {
-    // getBaseFileName() works differently on each platform and file patchs 
-    // can contain both types of delimiter so unify them then extract the 
+    // getBaseFileName() works differently on each platform and file patchs
+    // can contain both types of delimiter so unify them then extract the
     // base name (no path or extension)
     std::replace(image_uri.begin(), image_uri.end(), '\\', gDirUtilp->getDirDelimiter()[0]);
     std::replace(image_uri.begin(), image_uri.end(), '/', gDirUtilp->getDirDelimiter()[0]);
     const bool strip_extension = true;
     std::string stripped_uri = gDirUtilp->getBaseFileName(image_uri, strip_extension);
 
-    // sometimes they can be really long and unwieldy - 64 chars is enough for anyone :) 
+    // sometimes they can be really long and unwieldy - 64 chars is enough for anyone :)
     const int max_texture_name_length = 64;
     if (stripped_uri.length() > max_texture_name_length)
     {
         stripped_uri = stripped_uri.substr(0, max_texture_name_length - 1);
     }
 
-    // We intend to append the type of texture (base color, emissive etc.) to the 
+    // We intend to append the type of texture (base color, emissive etc.) to the
     // name of the texture but sometimes the creator already did that.  To try
     // to avoid repeats (not perfect), we look for the texture type in the name
     // and if we find it, do not append the type, later on. One way this fails
@@ -2717,15 +2717,15 @@ const std::string LLMaterialEditor::getImageNameFromUri(std::string image_uri, c
 /**
  * Update the metadata for the material based on what we find in the loaded
  * file (along with some assumptions and interpretations...). Fields include
- * the name of the material, a material description and the names of the 
+ * the name of the material, a material description and the names of the
  * composite textures.
  */
 void LLMaterialEditor::setFromGltfMetaData(const std::string& filename, const tinygltf::Model& model, S32 index)
 {
-    // Use the name (without any path/extension) of the file that was 
-    // uploaded as the base of the material name. Then if the name of the 
+    // Use the name (without any path/extension) of the file that was
+    // uploaded as the base of the material name. Then if the name of the
     // scene is present and not blank, append that and use the result as
-    // the name of the material. This is a first pass at creating a 
+    // the name of the material. This is a first pass at creating a
     // naming scheme that is useful to real content creators and hopefully
     // avoid 500 materials in your inventory called "scene" or "Default"
     const bool strip_extension = true;
@@ -2756,10 +2756,10 @@ void LLMaterialEditor::setFromGltfMetaData(const std::string& filename, const ti
         // scene name isn't present so no point using it
     }
 
-    // If we have a valid material or scene name, use it to build the short and 
-    // long versions of the material name. The long version is used 
+    // If we have a valid material or scene name, use it to build the short and
+    // long versions of the material name. The long version is used
     // as you might expect, for the material name. The short version is
-    // used as part of the image/texture name - the theory is that will 
+    // used as part of the image/texture name - the theory is that will
     // allow content creators to track the material and the corresponding
     // textures
     if (material_name.length())
@@ -2767,9 +2767,9 @@ void LLMaterialEditor::setFromGltfMetaData(const std::string& filename, const ti
         mMaterialNameShort = base_filename;
 
         mMaterialName = STRINGIZE(
-            base_filename << 
-            " " << 
-            "(" << 
+            base_filename <<
+            " " <<
+            "(" <<
             material_name <<
             ")"
         );
@@ -2785,14 +2785,14 @@ void LLMaterialEditor::setFromGltfMetaData(const std::string& filename, const ti
     LLInventoryObject::correctInventoryName(mMaterialName);
     LLInventoryObject::correctInventoryName(mMaterialNameShort);
 
-    // We also set the title of the floater to match the 
+    // We also set the title of the floater to match the
     // name of the material
     setTitle(mMaterialName);
 
     /**
-     * Extract / derive the names of each composite texture. For each, the 
+     * Extract / derive the names of each composite texture. For each, the
      * index is used to to determine which of the "Images" is used. If the index
-     * is -1 then that texture type is not present in the material (Seems to be 
+     * is -1 then that texture type is not present in the material (Seems to be
      * quite common that a material is missing 1 or more types of texture)
      */
     if (model.materials.size() > index)
@@ -2800,8 +2800,8 @@ void LLMaterialEditor::setFromGltfMetaData(const std::string& filename, const ti
         const tinygltf::Material& first_material = model.materials[index];
 
         mBaseColorName = MATERIAL_BASE_COLOR_DEFAULT_NAME;
-        // note: unlike the other textures, base color doesn't have its own entry 
-        // in the tinyGLTF Material struct. Rather, it is taken from a 
+        // note: unlike the other textures, base color doesn't have its own entry
+        // in the tinyGLTF Material struct. Rather, it is taken from a
         // sub-texture in the pbrMetallicRoughness member
         int index = first_material.pbrMetallicRoughness.baseColorTexture.index;
         if (index > -1 && index < model.images.size())
@@ -2955,7 +2955,7 @@ class LLRenderMaterialOverrideFunctor : public LLSelectedNodeFunctor
                 else
                 {
                     // mSavedGLTFOverrideMaterials[te] being present but null
-                    // means we need to use a default value 
+                    // means we need to use a default value
                     revert_mat = new LLGLTFMaterial();
                 }
             }
@@ -3296,7 +3296,7 @@ bool LLMaterialEditor::setFromSelection()
 
         // Ovverdired might have been updated,
         // refresh state of local textures in overrides
-        // 
+        //
         // Todo: this probably shouldn't be here, but in localbitmap,
         // subscried to all material overrides if we want copied
         // objects to get properly updated as well
@@ -3319,7 +3319,7 @@ void LLMaterialEditor::loadAsset()
     {
         item = getItem();
     }
-    
+
     bool fail = false;
 
     if (item)
@@ -3523,16 +3523,16 @@ void LLMaterialEditor::saveTexture(LLImageJ2C* img, const std::string& name, con
     LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared<LLNewBufferedResourceUploadInfo>(
         buffer,
         asset_id,
-        name, 
-        name, 
+        name,
+        name,
         0,
-        LLFolderType::FT_TEXTURE, 
+        LLFolderType::FT_TEXTURE,
         LLInventoryType::IT_TEXTURE,
         LLAssetType::AT_TEXTURE,
         LLFloaterPerms::getNextOwnerPerms("Uploads"),
         LLFloaterPerms::getGroupPerms("Uploads"),
         LLFloaterPerms::getEveryonePerms("Uploads"),
-        expected_upload_cost, 
+        expected_upload_cost,
         false,
         cb,
         failed_upload));
diff --git a/indra/newview/llpanelface.cpp b/indra/newview/llpanelface.cpp
index 9b0d14cd3c78d2a9e494a9c3a212a4d06285b1bd..c257137cd5a4deacf002316061283acd21af152c 100644
--- a/indra/newview/llpanelface.cpp
+++ b/indra/newview/llpanelface.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llpanelface.cpp
  * @brief Panel in the tools floater for editing face textures, colors, etc.
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -28,7 +28,7 @@
 
 // file include
 #include "llpanelface.h"
- 
+
 // library includes
 #include "llcalc.h"
 #include "llerror.h"
@@ -102,15 +102,15 @@ LLPanelFace::Selection LLPanelFace::sMaterialOverrideSelection;
 // Constant definitions for comboboxes
 // Must match the commbobox definitions in panel_tools_texture.xml
 //
-const S32 MATMEDIA_MATERIAL = 0;	// Material
-const S32 MATMEDIA_PBR = 1;			// PBR
-const S32 MATMEDIA_MEDIA = 2;		// Media
-const S32 MATTYPE_DIFFUSE = 0;		// Diffuse material texture
-const S32 MATTYPE_NORMAL = 1;		// Normal map
-const S32 MATTYPE_SPECULAR = 2;		// Specular map
-const S32 ALPHAMODE_MASK = 2;		// Alpha masking mode
-const S32 BUMPY_TEXTURE = 18;		// use supplied normal map
-const S32 SHINY_TEXTURE = 4;		// use supplied specular map
+const S32 MATMEDIA_MATERIAL = 0;    // Material
+const S32 MATMEDIA_PBR = 1;         // PBR
+const S32 MATMEDIA_MEDIA = 2;       // Media
+const S32 MATTYPE_DIFFUSE = 0;      // Diffuse material texture
+const S32 MATTYPE_NORMAL = 1;       // Normal map
+const S32 MATTYPE_SPECULAR = 2;     // Specular map
+const S32 ALPHAMODE_MASK = 2;       // Alpha masking mode
+const S32 BUMPY_TEXTURE = 18;       // use supplied normal map
+const S32 SHINY_TEXTURE = 4;        // use supplied specular map
 const S32 PBRTYPE_RENDER_MATERIAL_ID = 0;  // Render Material ID
 const S32 PBRTYPE_BASE_COLOR = 1;   // PBR Base Color
 const S32 PBRTYPE_METALLIC_ROUGHNESS = 2; // PBR Metallic
@@ -159,7 +159,7 @@ void LLPanelFace::updateSelectedGLTFMaterials(std::function<void(LLGLTFMaterial*
             return true;
         }
 
-		std::function<void(LLGLTFMaterial*)> mFunc;
+        std::function<void(LLGLTFMaterial*)> mFunc;
     } select_func(func);
 
     LLSelectMgr::getInstance()->getSelection()->applyToTEs(&select_func);
@@ -176,7 +176,7 @@ void readSelectedGLTFMaterial(std::function<T(const LLGLTFMaterial*)> func, T& v
         {
             const LLTextureEntry* tep = object->getTE(face);
             const LLGLTFMaterial* render_material = tep->getGLTFRenderMaterial();
-            
+
             return mFunc(render_material);
         }
 
@@ -211,9 +211,9 @@ LLRender::eTexIndex LLPanelFace::getTextureChannelToEdit()
         }
     }
 
-	channel_to_edit = (channel_to_edit == LLRender::NORMAL_MAP)		? (getCurrentNormalMap().isNull()		? LLRender::DIFFUSE_MAP : channel_to_edit) : channel_to_edit;
-	channel_to_edit = (channel_to_edit == LLRender::SPECULAR_MAP)	? (getCurrentSpecularMap().isNull()		? LLRender::DIFFUSE_MAP : channel_to_edit) : channel_to_edit;
-	return channel_to_edit;
+    channel_to_edit = (channel_to_edit == LLRender::NORMAL_MAP)     ? (getCurrentNormalMap().isNull()       ? LLRender::DIFFUSE_MAP : channel_to_edit) : channel_to_edit;
+    channel_to_edit = (channel_to_edit == LLRender::SPECULAR_MAP)   ? (getCurrentSpecularMap().isNull()     ? LLRender::DIFFUSE_MAP : channel_to_edit) : channel_to_edit;
+    return channel_to_edit;
 }
 
 LLRender::eTexIndex LLPanelFace::getTextureDropChannel()
@@ -240,66 +240,66 @@ LLGLTFMaterial::TextureInfo LLPanelFace::getPBRDropChannel()
 
 // Things the UI provides...
 //
-LLUUID	LLPanelFace::getCurrentNormalMap()			{ return mBumpyTextureCtrl->getImageAssetID();	}
-LLUUID	LLPanelFace::getCurrentSpecularMap()		{ return mShinyTextureCtrl->getImageAssetID();	}
-U32		LLPanelFace::getCurrentShininess()			{ return mComboShininess->getCurrentIndex();	}
-U32		LLPanelFace::getCurrentBumpiness()			{ return mComboBumpiness->getCurrentIndex();	}
-U8			LLPanelFace::getCurrentDiffuseAlphaMode()	{ return (U8)mComboAlphaMode->getCurrentIndex();	}
-U8			LLPanelFace::getCurrentAlphaMaskCutoff()	{ return (U8)mSpinMaskCutoff->getValue().asInteger();			}
-U8			LLPanelFace::getCurrentEnvIntensity()		{ return (U8)mSpinEnvironment->getValue().asInteger();			}
-U8			LLPanelFace::getCurrentGlossiness()			{ return (U8)mSpinGlossiness->getValue().asInteger();			}
-F32		LLPanelFace::getCurrentBumpyRot()			{ return getChild<LLUICtrl>("bumpyRot")->getValue().asReal();		}
-F32		LLPanelFace::getCurrentBumpyScaleU()		{ return getChild<LLUICtrl>("bumpyScaleU")->getValue().asReal();	}
-F32		LLPanelFace::getCurrentBumpyScaleV()		{ return getChild<LLUICtrl>("bumpyScaleV")->getValue().asReal();	}
-F32		LLPanelFace::getCurrentBumpyOffsetU()		{ return getChild<LLUICtrl>("bumpyOffsetU")->getValue().asReal();	}
-F32		LLPanelFace::getCurrentBumpyOffsetV()		{ return getChild<LLUICtrl>("bumpyOffsetV")->getValue().asReal();	}
-F32		LLPanelFace::getCurrentShinyRot()			{ return getChild<LLUICtrl>("shinyRot")->getValue().asReal();		}
-F32		LLPanelFace::getCurrentShinyScaleU()		{ return getChild<LLUICtrl>("shinyScaleU")->getValue().asReal();	}
-F32		LLPanelFace::getCurrentShinyScaleV()		{ return getChild<LLUICtrl>("shinyScaleV")->getValue().asReal();	}
-F32		LLPanelFace::getCurrentShinyOffsetU()		{ return getChild<LLUICtrl>("shinyOffsetU")->getValue().asReal();	}
-F32		LLPanelFace::getCurrentShinyOffsetV()		{ return getChild<LLUICtrl>("shinyOffsetV")->getValue().asReal();	}
+LLUUID  LLPanelFace::getCurrentNormalMap()          { return mBumpyTextureCtrl->getImageAssetID();  }
+LLUUID  LLPanelFace::getCurrentSpecularMap()        { return mShinyTextureCtrl->getImageAssetID();  }
+U32     LLPanelFace::getCurrentShininess()          { return mComboShininess->getCurrentIndex();    }
+U32     LLPanelFace::getCurrentBumpiness()          { return mComboBumpiness->getCurrentIndex();    }
+U8          LLPanelFace::getCurrentDiffuseAlphaMode()   { return (U8)mComboAlphaMode->getCurrentIndex();    }
+U8          LLPanelFace::getCurrentAlphaMaskCutoff()    { return (U8)mSpinMaskCutoff->getValue().asInteger();           }
+U8          LLPanelFace::getCurrentEnvIntensity()       { return (U8)mSpinEnvironment->getValue().asInteger();          }
+U8          LLPanelFace::getCurrentGlossiness()         { return (U8)mSpinGlossiness->getValue().asInteger();           }
+F32     LLPanelFace::getCurrentBumpyRot()           { return getChild<LLUICtrl>("bumpyRot")->getValue().asReal();       }
+F32     LLPanelFace::getCurrentBumpyScaleU()        { return getChild<LLUICtrl>("bumpyScaleU")->getValue().asReal();    }
+F32     LLPanelFace::getCurrentBumpyScaleV()        { return getChild<LLUICtrl>("bumpyScaleV")->getValue().asReal();    }
+F32     LLPanelFace::getCurrentBumpyOffsetU()       { return getChild<LLUICtrl>("bumpyOffsetU")->getValue().asReal();   }
+F32     LLPanelFace::getCurrentBumpyOffsetV()       { return getChild<LLUICtrl>("bumpyOffsetV")->getValue().asReal();   }
+F32     LLPanelFace::getCurrentShinyRot()           { return getChild<LLUICtrl>("shinyRot")->getValue().asReal();       }
+F32     LLPanelFace::getCurrentShinyScaleU()        { return getChild<LLUICtrl>("shinyScaleU")->getValue().asReal();    }
+F32     LLPanelFace::getCurrentShinyScaleV()        { return getChild<LLUICtrl>("shinyScaleV")->getValue().asReal();    }
+F32     LLPanelFace::getCurrentShinyOffsetU()       { return getChild<LLUICtrl>("shinyOffsetU")->getValue().asReal();   }
+F32     LLPanelFace::getCurrentShinyOffsetV()       { return getChild<LLUICtrl>("shinyOffsetV")->getValue().asReal();   }
 
 //
 // Methods
 //
 
-BOOL	LLPanelFace::postBuild()
+BOOL    LLPanelFace::postBuild()
 {
     mComboShininess = getChild<LLComboBox>("combobox shininess");
     mComboShininess->setCommitCallback(std::bind(onCommitShiny, std::placeholders::_1, this));
 
     mComboBumpiness = getChild<LLComboBox>("combobox bumpiness");
     mComboBumpiness->setCommitCallback(std::bind(onCommitBump, std::placeholders::_1, this));
-	
-	mComboAlphaMode = getChild<LLComboBox>("combobox alphamode");
+
+    mComboAlphaMode = getChild<LLComboBox>("combobox alphamode");
     mComboAlphaMode->setCommitCallback(std::bind(onCommitAlphaMode, std::placeholders::_1, this));
 
-	childSetCommitCallback("TexScaleU",&LLPanelFace::onCommitTextureScaleX, this);
-	childSetCommitCallback("TexScaleV",&LLPanelFace::onCommitTextureScaleY, this);
-	childSetCommitCallback("TexRot",&LLPanelFace::onCommitTextureRot, this);
-	childSetCommitCallback("rptctrl",&LLPanelFace::onCommitRepeatsPerMeter, this);
-	childSetCommitCallback("checkbox planar align",&LLPanelFace::onCommitPlanarAlign, this);
-	childSetCommitCallback("TexOffsetU",LLPanelFace::onCommitTextureOffsetX, this);
-	childSetCommitCallback("TexOffsetV",LLPanelFace::onCommitTextureOffsetY, this);
-
-	childSetCommitCallback("bumpyScaleU",&LLPanelFace::onCommitMaterialBumpyScaleX, this);
-	childSetCommitCallback("bumpyScaleV",&LLPanelFace::onCommitMaterialBumpyScaleY, this);
-	childSetCommitCallback("bumpyRot",&LLPanelFace::onCommitMaterialBumpyRot, this);
-	childSetCommitCallback("bumpyOffsetU",&LLPanelFace::onCommitMaterialBumpyOffsetX, this);
-	childSetCommitCallback("bumpyOffsetV",&LLPanelFace::onCommitMaterialBumpyOffsetY, this);
-	childSetCommitCallback("shinyScaleU",&LLPanelFace::onCommitMaterialShinyScaleX, this);
-	childSetCommitCallback("shinyScaleV",&LLPanelFace::onCommitMaterialShinyScaleY, this);
-	childSetCommitCallback("shinyRot",&LLPanelFace::onCommitMaterialShinyRot, this);
-	childSetCommitCallback("shinyOffsetU",&LLPanelFace::onCommitMaterialShinyOffsetX, this);
-	childSetCommitCallback("shinyOffsetV",&LLPanelFace::onCommitMaterialShinyOffsetY, this);
-
-	mSpinGlossiness = getChild<LLSpinCtrl>("glossiness");
+    childSetCommitCallback("TexScaleU",&LLPanelFace::onCommitTextureScaleX, this);
+    childSetCommitCallback("TexScaleV",&LLPanelFace::onCommitTextureScaleY, this);
+    childSetCommitCallback("TexRot",&LLPanelFace::onCommitTextureRot, this);
+    childSetCommitCallback("rptctrl",&LLPanelFace::onCommitRepeatsPerMeter, this);
+    childSetCommitCallback("checkbox planar align",&LLPanelFace::onCommitPlanarAlign, this);
+    childSetCommitCallback("TexOffsetU",LLPanelFace::onCommitTextureOffsetX, this);
+    childSetCommitCallback("TexOffsetV",LLPanelFace::onCommitTextureOffsetY, this);
+
+    childSetCommitCallback("bumpyScaleU",&LLPanelFace::onCommitMaterialBumpyScaleX, this);
+    childSetCommitCallback("bumpyScaleV",&LLPanelFace::onCommitMaterialBumpyScaleY, this);
+    childSetCommitCallback("bumpyRot",&LLPanelFace::onCommitMaterialBumpyRot, this);
+    childSetCommitCallback("bumpyOffsetU",&LLPanelFace::onCommitMaterialBumpyOffsetX, this);
+    childSetCommitCallback("bumpyOffsetV",&LLPanelFace::onCommitMaterialBumpyOffsetY, this);
+    childSetCommitCallback("shinyScaleU",&LLPanelFace::onCommitMaterialShinyScaleX, this);
+    childSetCommitCallback("shinyScaleV",&LLPanelFace::onCommitMaterialShinyScaleY, this);
+    childSetCommitCallback("shinyRot",&LLPanelFace::onCommitMaterialShinyRot, this);
+    childSetCommitCallback("shinyOffsetU",&LLPanelFace::onCommitMaterialShinyOffsetX, this);
+    childSetCommitCallback("shinyOffsetV",&LLPanelFace::onCommitMaterialShinyOffsetY, this);
+
+    mSpinGlossiness = getChild<LLSpinCtrl>("glossiness");
     mSpinGlossiness->setCommitCallback(std::bind(onCommitMaterialGloss, std::placeholders::_1, this));
 
-	mSpinEnvironment = getChild<LLSpinCtrl>("environment");
+    mSpinEnvironment = getChild<LLSpinCtrl>("environment");
     mSpinEnvironment->setCommitCallback(std::bind(onCommitMaterialEnv, std::placeholders::_1, this));
 
-	mSpinMaskCutoff = getChild<LLSpinCtrl>("maskcutoff");
+    mSpinMaskCutoff = getChild<LLSpinCtrl>("maskcutoff");
     mSpinMaskCutoff->setCommitCallback(std::bind(onCommitMaterialMaskCutoff, std::placeholders::_1, this));
     childSetCommitCallback("add_media", &LLPanelFace::onClickBtnAddMedia, this);
     childSetCommitCallback("delete_media", &LLPanelFace::onClickBtnDeleteMedia, this);
@@ -313,15 +313,15 @@ BOOL	LLPanelFace::postBuild()
     LLGLTFMaterialList::addSelectionUpdateCallback(&LLPanelFace::onMaterialOverrideReceived);
     sMaterialOverrideSelection.connect();
 
-	childSetAction("button align",&LLPanelFace::onClickAutoFix,this);
-	childSetAction("button align textures", &LLPanelFace::onAlignTexture, this);
+    childSetAction("button align",&LLPanelFace::onClickAutoFix,this);
+    childSetAction("button align textures", &LLPanelFace::onAlignTexture, this);
     childSetAction("pbr_from_inventory", &LLPanelFace::onClickBtnLoadInvPBR, this);
     childSetAction("edit_selected_pbr", &LLPanelFace::onClickBtnEditPBR, this);
     childSetAction("save_selected_pbr", &LLPanelFace::onClickBtnSavePBR, this);
 
-	setMouseOpaque(FALSE);
+    setMouseOpaque(FALSE);
 
-    LLTextureCtrl*	pbr_ctrl = findChild<LLTextureCtrl>("pbr_control");
+    LLTextureCtrl*  pbr_ctrl = findChild<LLTextureCtrl>("pbr_control");
     if (pbr_ctrl)
     {
         pbr_ctrl->setDefaultImageAssetID(LLUUID::null);
@@ -341,107 +341,107 @@ BOOL	LLPanelFace::postBuild()
         pbr_ctrl->setInventoryPickType(PICK_MATERIAL);
     }
 
-	mTextureCtrl = getChild<LLTextureCtrl>("texture control");
-	{
-		mTextureCtrl->setDefaultImageAssetID(DEFAULT_OBJECT_TEXTURE);
-		mTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitTexture, this, _2) );
-		mTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelTexture, this, _2) );
-		mTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectTexture, this, _2) );
-		mTextureCtrl->setDragCallback(boost::bind(&LLPanelFace::onDragTexture, this, _2));
-		mTextureCtrl->setOnTextureSelectedCallback(boost::bind(&LLPanelFace::onTextureSelectionChanged, this, _1));
-		mTextureCtrl->setOnCloseCallback( boost::bind(&LLPanelFace::onCloseTexturePicker, this, _2) );
-
-		mTextureCtrl->setFollowsTop();
-		mTextureCtrl->setFollowsLeft();
-		mTextureCtrl->setImmediateFilterPermMask(PERM_NONE);
-		mTextureCtrl->setDnDFilterPermMask(PERM_COPY | PERM_TRANSFER);
-	}
-
-	mShinyTextureCtrl = getChild<LLTextureCtrl>("shinytexture control");
-	{
-		mShinyTextureCtrl->setDefaultImageAssetID(DEFAULT_OBJECT_SPECULAR);
-		mShinyTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitSpecularTexture, this, _2) );
-		mShinyTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelSpecularTexture, this, _2) );
-		mShinyTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectSpecularTexture, this, _2) );
-		mShinyTextureCtrl->setOnCloseCallback( boost::bind(&LLPanelFace::onCloseTexturePicker, this, _2) );
-		
-		mShinyTextureCtrl->setDragCallback(boost::bind(&LLPanelFace::onDragTexture, this, _2));
-		mShinyTextureCtrl->setOnTextureSelectedCallback(boost::bind(&LLPanelFace::onTextureSelectionChanged, this, _1));
-		mShinyTextureCtrl->setFollowsTop();
-		mShinyTextureCtrl->setFollowsLeft();
-		mShinyTextureCtrl->setImmediateFilterPermMask(PERM_NONE);
-		mShinyTextureCtrl->setDnDFilterPermMask(PERM_COPY | PERM_TRANSFER);
-	}
-
-	mBumpyTextureCtrl = getChild<LLTextureCtrl>("bumpytexture control");
-	{
-		mBumpyTextureCtrl->setDefaultImageAssetID(DEFAULT_OBJECT_NORMAL);
-		mBumpyTextureCtrl->setBlankImageAssetID(BLANK_OBJECT_NORMAL);
-		mBumpyTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitNormalTexture, this, _2) );
-		mBumpyTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelNormalTexture, this, _2) );
-		mBumpyTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectNormalTexture, this, _2) );
-		mBumpyTextureCtrl->setOnCloseCallback( boost::bind(&LLPanelFace::onCloseTexturePicker, this, _2) );
-
-		mBumpyTextureCtrl->setDragCallback(boost::bind(&LLPanelFace::onDragTexture, this, _2));
-		mBumpyTextureCtrl->setOnTextureSelectedCallback(boost::bind(&LLPanelFace::onTextureSelectionChanged, this, _1));
-		mBumpyTextureCtrl->setFollowsTop();
-		mBumpyTextureCtrl->setFollowsLeft();
-		mBumpyTextureCtrl->setImmediateFilterPermMask(PERM_NONE);
-		mBumpyTextureCtrl->setDnDFilterPermMask(PERM_COPY | PERM_TRANSFER);
-	}
-
-	mColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
-	{
-		mColorSwatch->setCommitCallback(boost::bind(&LLPanelFace::onCommitColor, this, _2));
-		mColorSwatch->setOnCancelCallback(boost::bind(&LLPanelFace::onCancelColor, this, _2));
-		mColorSwatch->setOnSelectCallback(boost::bind(&LLPanelFace::onSelectColor, this, _2));
-		mColorSwatch->setFollowsTop();
-		mColorSwatch->setFollowsLeft();
-		mColorSwatch->setCanApplyImmediately(TRUE);
-	}
-
-	mShinyColorSwatch = getChild<LLColorSwatchCtrl>("shinycolorswatch");
-	{
-		mShinyColorSwatch->setCommitCallback(boost::bind(&LLPanelFace::onCommitShinyColor, this, _2));
-		mShinyColorSwatch->setOnCancelCallback(boost::bind(&LLPanelFace::onCancelShinyColor, this, _2));
-		mShinyColorSwatch->setOnSelectCallback(boost::bind(&LLPanelFace::onSelectShinyColor, this, _2));
-		mShinyColorSwatch->setFollowsTop();
-		mShinyColorSwatch->setFollowsLeft();
-		mShinyColorSwatch->setCanApplyImmediately(TRUE);
-	}
-
-	mLabelColorTransp = getChild<LLTextBox>("color trans");
-	{
-		mLabelColorTransp->setFollowsTop();
-		mLabelColorTransp->setFollowsLeft();
-	}
-
-	mCtrlColorTransp = getChild<LLSpinCtrl>("ColorTrans");
-	{
-		mCtrlColorTransp->setCommitCallback(boost::bind(&LLPanelFace::onCommitAlpha, this, _2));
-		mCtrlColorTransp->setPrecision(0);
-		mCtrlColorTransp->setFollowsTop();
-		mCtrlColorTransp->setFollowsLeft();
-	}
-
-	mCheckFullbright = getChild<LLCheckBoxCtrl>("checkbox fullbright");
-	{
-		mCheckFullbright->setCommitCallback(LLPanelFace::onCommitFullbright, this);
-	}
-
-	mComboTexGen = getChild<LLComboBox>("combobox texgen");
-	{
-		mComboTexGen->setCommitCallback(LLPanelFace::onCommitTexGen, this);
-		mComboTexGen->setFollows(FOLLOWS_LEFT | FOLLOWS_TOP);	
-	}
+    mTextureCtrl = getChild<LLTextureCtrl>("texture control");
+    {
+        mTextureCtrl->setDefaultImageAssetID(DEFAULT_OBJECT_TEXTURE);
+        mTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitTexture, this, _2) );
+        mTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelTexture, this, _2) );
+        mTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectTexture, this, _2) );
+        mTextureCtrl->setDragCallback(boost::bind(&LLPanelFace::onDragTexture, this, _2));
+        mTextureCtrl->setOnTextureSelectedCallback(boost::bind(&LLPanelFace::onTextureSelectionChanged, this, _1));
+        mTextureCtrl->setOnCloseCallback( boost::bind(&LLPanelFace::onCloseTexturePicker, this, _2) );
+
+        mTextureCtrl->setFollowsTop();
+        mTextureCtrl->setFollowsLeft();
+        mTextureCtrl->setImmediateFilterPermMask(PERM_NONE);
+        mTextureCtrl->setDnDFilterPermMask(PERM_COPY | PERM_TRANSFER);
+    }
+
+    mShinyTextureCtrl = getChild<LLTextureCtrl>("shinytexture control");
+    {
+        mShinyTextureCtrl->setDefaultImageAssetID(DEFAULT_OBJECT_SPECULAR);
+        mShinyTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitSpecularTexture, this, _2) );
+        mShinyTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelSpecularTexture, this, _2) );
+        mShinyTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectSpecularTexture, this, _2) );
+        mShinyTextureCtrl->setOnCloseCallback( boost::bind(&LLPanelFace::onCloseTexturePicker, this, _2) );
+
+        mShinyTextureCtrl->setDragCallback(boost::bind(&LLPanelFace::onDragTexture, this, _2));
+        mShinyTextureCtrl->setOnTextureSelectedCallback(boost::bind(&LLPanelFace::onTextureSelectionChanged, this, _1));
+        mShinyTextureCtrl->setFollowsTop();
+        mShinyTextureCtrl->setFollowsLeft();
+        mShinyTextureCtrl->setImmediateFilterPermMask(PERM_NONE);
+        mShinyTextureCtrl->setDnDFilterPermMask(PERM_COPY | PERM_TRANSFER);
+    }
+
+    mBumpyTextureCtrl = getChild<LLTextureCtrl>("bumpytexture control");
+    {
+        mBumpyTextureCtrl->setDefaultImageAssetID(DEFAULT_OBJECT_NORMAL);
+        mBumpyTextureCtrl->setBlankImageAssetID(BLANK_OBJECT_NORMAL);
+        mBumpyTextureCtrl->setCommitCallback( boost::bind(&LLPanelFace::onCommitNormalTexture, this, _2) );
+        mBumpyTextureCtrl->setOnCancelCallback( boost::bind(&LLPanelFace::onCancelNormalTexture, this, _2) );
+        mBumpyTextureCtrl->setOnSelectCallback( boost::bind(&LLPanelFace::onSelectNormalTexture, this, _2) );
+        mBumpyTextureCtrl->setOnCloseCallback( boost::bind(&LLPanelFace::onCloseTexturePicker, this, _2) );
+
+        mBumpyTextureCtrl->setDragCallback(boost::bind(&LLPanelFace::onDragTexture, this, _2));
+        mBumpyTextureCtrl->setOnTextureSelectedCallback(boost::bind(&LLPanelFace::onTextureSelectionChanged, this, _1));
+        mBumpyTextureCtrl->setFollowsTop();
+        mBumpyTextureCtrl->setFollowsLeft();
+        mBumpyTextureCtrl->setImmediateFilterPermMask(PERM_NONE);
+        mBumpyTextureCtrl->setDnDFilterPermMask(PERM_COPY | PERM_TRANSFER);
+    }
+
+    mColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
+    {
+        mColorSwatch->setCommitCallback(boost::bind(&LLPanelFace::onCommitColor, this, _2));
+        mColorSwatch->setOnCancelCallback(boost::bind(&LLPanelFace::onCancelColor, this, _2));
+        mColorSwatch->setOnSelectCallback(boost::bind(&LLPanelFace::onSelectColor, this, _2));
+        mColorSwatch->setFollowsTop();
+        mColorSwatch->setFollowsLeft();
+        mColorSwatch->setCanApplyImmediately(TRUE);
+    }
+
+    mShinyColorSwatch = getChild<LLColorSwatchCtrl>("shinycolorswatch");
+    {
+        mShinyColorSwatch->setCommitCallback(boost::bind(&LLPanelFace::onCommitShinyColor, this, _2));
+        mShinyColorSwatch->setOnCancelCallback(boost::bind(&LLPanelFace::onCancelShinyColor, this, _2));
+        mShinyColorSwatch->setOnSelectCallback(boost::bind(&LLPanelFace::onSelectShinyColor, this, _2));
+        mShinyColorSwatch->setFollowsTop();
+        mShinyColorSwatch->setFollowsLeft();
+        mShinyColorSwatch->setCanApplyImmediately(TRUE);
+    }
+
+    mLabelColorTransp = getChild<LLTextBox>("color trans");
+    {
+        mLabelColorTransp->setFollowsTop();
+        mLabelColorTransp->setFollowsLeft();
+    }
+
+    mCtrlColorTransp = getChild<LLSpinCtrl>("ColorTrans");
+    {
+        mCtrlColorTransp->setCommitCallback(boost::bind(&LLPanelFace::onCommitAlpha, this, _2));
+        mCtrlColorTransp->setPrecision(0);
+        mCtrlColorTransp->setFollowsTop();
+        mCtrlColorTransp->setFollowsLeft();
+    }
+
+    mCheckFullbright = getChild<LLCheckBoxCtrl>("checkbox fullbright");
+    {
+        mCheckFullbright->setCommitCallback(LLPanelFace::onCommitFullbright, this);
+    }
+
+    mComboTexGen = getChild<LLComboBox>("combobox texgen");
+    {
+        mComboTexGen->setCommitCallback(LLPanelFace::onCommitTexGen, this);
+        mComboTexGen->setFollows(FOLLOWS_LEFT | FOLLOWS_TOP);
+    }
 
     mComboMatMedia = getChild<LLComboBox>("combobox matmedia");
-	{
+    {
         mComboMatMedia->setCommitCallback(LLPanelFace::onCommitMaterialsMedia,this);
         mComboMatMedia->selectNthItem(MATMEDIA_MATERIAL);
-	}
+    }
 
-	mRadioMatType = findChild<LLRadioGroup>("radio_material_type");
+    mRadioMatType = findChild<LLRadioGroup>("radio_material_type");
     if(mRadioMatType)
     {
         mRadioMatType->setCommitCallback(LLPanelFace::onCommitMaterialType, this);
@@ -455,10 +455,10 @@ BOOL	LLPanelFace::postBuild()
         radio_pbr_type->selectNthItem(PBRTYPE_RENDER_MATERIAL_ID);
     }
 
-	mCtrlGlow = getChild<LLSpinCtrl>("glow");
-	{
-		mCtrlGlow->setCommitCallback(LLPanelFace::onCommitGlow, this);
-	}
+    mCtrlGlow = getChild<LLSpinCtrl>("glow");
+    {
+        mCtrlGlow->setCommitCallback(LLPanelFace::onCommitGlow, this);
+    }
 
     mBtnCopyColor = findChild<LLButton>("copy_color_btn");
     mBtnCopyColor->setCommitCallback([this](LLUICtrl*, const LLSD&) { onCopyColor(); });
@@ -473,13 +473,13 @@ BOOL	LLPanelFace::postBuild()
     mTitleMedia = getChild<LLMediaCtrl>("title_media");
     mTitleMediaText = getChild<LLTextBox>("media_info");
 
-	clearCtrls();
+    clearCtrls();
 
-	return TRUE;
+    return TRUE;
 }
 
 LLPanelFace::LLPanelFace()
-:	LLPanel(),
+:   LLPanel(),
     mIsAlpha(false),
     mComboMatMedia(NULL),
     mTitleMedia(NULL),
@@ -489,7 +489,7 @@ LLPanelFace::LLPanelFace()
     USE_TEXTURE = LLTrans::getString("use_texture");
     mCommitCallbackRegistrar.add("PanelFace.menuDoToSelected", boost::bind(&LLPanelFace::menuDoToSelected, this, _2));
     mEnableCallbackRegistrar.add("PanelFace.menuEnable", boost::bind(&LLPanelFace::menuEnableItem, this, _2));
-	mCommitCallbackRegistrar.add("BuildTool.SelectSameTexture", boost::bind(&LLPanelFace::onClickBtnSelectSameTexture, this, _1, _2));
+    mCommitCallbackRegistrar.add("BuildTool.SelectSameTexture", boost::bind(&LLPanelFace::onClickBtnSelectSameTexture, this, _1, _2));
 }
 
 LLPanelFace::~LLPanelFace()
@@ -526,114 +526,114 @@ void LLPanelFace::draw()
 
 void LLPanelFace::sendTexture()
 {
-	if( !mTextureCtrl->getTentative() )
-	{
-		// we grab the item id first, because we want to do a
-		// permissions check in the selection manager. ARGH!
-		LLUUID id = mTextureCtrl->getImageItemID();
-		if(id.isNull())
-		{
-			id = mTextureCtrl->getImageAssetID();
-		}
+    if( !mTextureCtrl->getTentative() )
+    {
+        // we grab the item id first, because we want to do a
+        // permissions check in the selection manager. ARGH!
+        LLUUID id = mTextureCtrl->getImageItemID();
+        if(id.isNull())
+        {
+            id = mTextureCtrl->getImageAssetID();
+        }
         if (!LLSelectMgr::getInstance()->selectionSetImage(id))
         {
             // need to refresh value in texture ctrl
             refresh();
         }
-	}
+    }
 }
 
 void LLPanelFace::sendBump(U32 bumpiness)
-{	
-	if (bumpiness < BUMPY_TEXTURE)
-{	
-		LL_DEBUGS("Materials") << "clearing bumptexture control" << LL_ENDL;	
-		mBumpyTextureCtrl->clear();
-        mBumpyTextureCtrl->setImageAssetID(LLUUID());		
-	}
+{
+    if (bumpiness < BUMPY_TEXTURE)
+{
+        LL_DEBUGS("Materials") << "clearing bumptexture control" << LL_ENDL;
+        mBumpyTextureCtrl->clear();
+        mBumpyTextureCtrl->setImageAssetID(LLUUID());
+    }
 
-	updateBumpyControls(bumpiness == BUMPY_TEXTURE, true);
+    updateBumpyControls(bumpiness == BUMPY_TEXTURE, true);
 
-	LLUUID current_normal_map = mBumpyTextureCtrl->getImageAssetID();
+    LLUUID current_normal_map = mBumpyTextureCtrl->getImageAssetID();
 
-	U8 bump = (U8) bumpiness & TEM_BUMP_MASK;
+    U8 bump = (U8) bumpiness & TEM_BUMP_MASK;
 
-	// Clear legacy bump to None when using an actual normal map
-	//
-	if (!current_normal_map.isNull())
-		bump = 0;
+    // Clear legacy bump to None when using an actual normal map
+    //
+    if (!current_normal_map.isNull())
+        bump = 0;
 
-	// Set the normal map or reset it to null as appropriate
-	//
-	LLSelectedTEMaterial::setNormalID(this, current_normal_map);
+    // Set the normal map or reset it to null as appropriate
+    //
+    LLSelectedTEMaterial::setNormalID(this, current_normal_map);
 
-	LLSelectMgr::getInstance()->selectionSetBumpmap( bump, mBumpyTextureCtrl->getImageItemID() );
+    LLSelectMgr::getInstance()->selectionSetBumpmap( bump, mBumpyTextureCtrl->getImageItemID() );
 }
 
 void LLPanelFace::sendTexGen()
 {
-	U8 tex_gen = (U8) mComboTexGen->getCurrentIndex() << TEM_TEX_GEN_SHIFT;
-	LLSelectMgr::getInstance()->selectionSetTexGen( tex_gen );
+    U8 tex_gen = (U8) mComboTexGen->getCurrentIndex() << TEM_TEX_GEN_SHIFT;
+    LLSelectMgr::getInstance()->selectionSetTexGen( tex_gen );
 }
 
 void LLPanelFace::sendShiny(U32 shininess)
 {
-	if (shininess < SHINY_TEXTURE)
-	{
+    if (shininess < SHINY_TEXTURE)
+    {
         mShinyTextureCtrl->clear();
-		mShinyTextureCtrl->setImageAssetID(LLUUID());		
-	}
+        mShinyTextureCtrl->setImageAssetID(LLUUID());
+    }
+
+    LLUUID specmap = getCurrentSpecularMap();
 
-	LLUUID specmap = getCurrentSpecularMap();
+    U8 shiny = (U8) shininess & TEM_SHINY_MASK;
+    if (!specmap.isNull())
+        shiny = 0;
 
-	U8 shiny = (U8) shininess & TEM_SHINY_MASK;
-	if (!specmap.isNull())
-		shiny = 0;
+    LLSelectedTEMaterial::setSpecularID(this, specmap);
 
-	LLSelectedTEMaterial::setSpecularID(this, specmap);
+    LLSelectMgr::getInstance()->selectionSetShiny( shiny, mShinyTextureCtrl->getImageItemID() );
 
-	LLSelectMgr::getInstance()->selectionSetShiny( shiny, mShinyTextureCtrl->getImageItemID() );
+    updateShinyControls(!specmap.isNull(), true);
 
-	updateShinyControls(!specmap.isNull(), true);
-	
 }
 
 void LLPanelFace::sendFullbright()
 {
-	U8 fullbright = mCheckFullbright->get() ? TEM_FULLBRIGHT_MASK : 0;
-	LLSelectMgr::getInstance()->selectionSetFullbright( fullbright );
+    U8 fullbright = mCheckFullbright->get() ? TEM_FULLBRIGHT_MASK : 0;
+    LLSelectMgr::getInstance()->selectionSetFullbright( fullbright );
 }
 
 void LLPanelFace::sendColor()
 {
-	const LLColor4& color = mColorSwatch->get();
-	LLSelectMgr::getInstance()->selectionSetColorOnly( color );
+    const LLColor4& color = mColorSwatch->get();
+    LLSelectMgr::getInstance()->selectionSetColorOnly( color );
 }
 
 void LLPanelFace::sendAlpha()
-{	
-	F32 alpha = (100.f - mCtrlColorTransp->get()) / 100.f;
+{
+    F32 alpha = (100.f - mCtrlColorTransp->get()) / 100.f;
 
-	LLSelectMgr::getInstance()->selectionSetAlphaOnly( alpha );
+    LLSelectMgr::getInstance()->selectionSetAlphaOnly( alpha );
 }
 
 
 void LLPanelFace::sendGlow()
 {
-	if (mCtrlGlow)
-	{
-		F32 glow = mCtrlGlow->get();
-		LLSelectMgr::getInstance()->selectionSetGlow( glow );
-	}
+    if (mCtrlGlow)
+    {
+        F32 glow = mCtrlGlow->get();
+        LLSelectMgr::getInstance()->selectionSetGlow( glow );
+    }
 }
 
 struct LLPanelFaceSetTEFunctor : public LLSelectedTEFunctor
 {
-	LLPanelFaceSetTEFunctor(LLPanelFace* panel) : mPanel(panel) {}
-	virtual bool apply(LLViewerObject* object, S32 te)
-	{
-		BOOL valid;
-		F32 value;
+    LLPanelFaceSetTEFunctor(LLPanelFace* panel) : mPanel(panel) {}
+    virtual bool apply(LLViewerObject* object, S32 te)
+    {
+        BOOL valid;
+        F32 value;
         std::string prefix;
 
         // Effectively the same as MATMEDIA_PBR sans using different radio,
@@ -651,175 +651,175 @@ struct LLPanelFaceSetTEFunctor : public LLSelectedTEFunctor
             prefix = "shiny";
             break;
         }
-        
+
         LLSpinCtrl * ctrlTexScaleS = mPanel->getChild<LLSpinCtrl>(prefix + "ScaleU");
         LLSpinCtrl * ctrlTexScaleT = mPanel->getChild<LLSpinCtrl>(prefix + "ScaleV");
         LLSpinCtrl * ctrlTexOffsetS = mPanel->getChild<LLSpinCtrl>(prefix + "OffsetU");
         LLSpinCtrl * ctrlTexOffsetT = mPanel->getChild<LLSpinCtrl>(prefix + "OffsetV");
         LLSpinCtrl * ctrlTexRotation = mPanel->getChild<LLSpinCtrl>(prefix + "Rot");
 
-		LLCheckBoxCtrl*	cb_planar_align = mPanel->getChild<LLCheckBoxCtrl>("checkbox planar align");
-		bool align_planar = (cb_planar_align && cb_planar_align->get());
+        LLCheckBoxCtrl* cb_planar_align = mPanel->getChild<LLCheckBoxCtrl>("checkbox planar align");
+        bool align_planar = (cb_planar_align && cb_planar_align->get());
 
-		llassert(object);
+        llassert(object);
 
-		if (ctrlTexScaleS)
-		{
-			valid = !ctrlTexScaleS->getTentative(); // || !checkFlipScaleS->getTentative();
-			if (valid || align_planar)
-			{
-				value = ctrlTexScaleS->get();
+        if (ctrlTexScaleS)
+        {
+            valid = !ctrlTexScaleS->getTentative(); // || !checkFlipScaleS->getTentative();
+            if (valid || align_planar)
+            {
+                value = ctrlTexScaleS->get();
                 if (mPanel->mComboTexGen && mPanel->mComboTexGen->getCurrentIndex() == 1)
-				{
-					value *= 0.5f;
-				}
-				object->setTEScaleS( te, value );
-
-				if (align_planar) 
-				{
-					LLPanelFace::LLSelectedTEMaterial::setNormalRepeatX(mPanel, value, te, object->getID());
-					LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatX(mPanel, value, te, object->getID());
-				}
-			}
-		}
-
-		if (ctrlTexScaleT)
-		{
-			valid = !ctrlTexScaleT->getTentative(); // || !checkFlipScaleT->getTentative();
-			if (valid || align_planar)
-			{
-				value = ctrlTexScaleT->get();
-				//if( checkFlipScaleT->get() )
-				//{
-				//	value = -value;
-				//}
+                {
+                    value *= 0.5f;
+                }
+                object->setTEScaleS( te, value );
+
+                if (align_planar)
+                {
+                    LLPanelFace::LLSelectedTEMaterial::setNormalRepeatX(mPanel, value, te, object->getID());
+                    LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatX(mPanel, value, te, object->getID());
+                }
+            }
+        }
+
+        if (ctrlTexScaleT)
+        {
+            valid = !ctrlTexScaleT->getTentative(); // || !checkFlipScaleT->getTentative();
+            if (valid || align_planar)
+            {
+                value = ctrlTexScaleT->get();
+                //if( checkFlipScaleT->get() )
+                //{
+                //  value = -value;
+                //}
                 if (mPanel->mComboTexGen && mPanel->mComboTexGen->getCurrentIndex() == 1)
-				{
-					value *= 0.5f;
-				}
-				object->setTEScaleT( te, value );
-
-				if (align_planar) 
-				{
-					LLPanelFace::LLSelectedTEMaterial::setNormalRepeatY(mPanel, value, te, object->getID());
-					LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatY(mPanel, value, te, object->getID());
-				}
-			}
-		}
-
-		if (ctrlTexOffsetS)
-		{
-			valid = !ctrlTexOffsetS->getTentative();
-			if (valid || align_planar)
-			{
-				value = ctrlTexOffsetS->get();
-				object->setTEOffsetS( te, value );
-
-				if (align_planar) 
-				{
-					LLPanelFace::LLSelectedTEMaterial::setNormalOffsetX(mPanel, value, te, object->getID());
-					LLPanelFace::LLSelectedTEMaterial::setSpecularOffsetX(mPanel, value, te, object->getID());
-				}
-			}
-		}
-
-		if (ctrlTexOffsetT)
-		{
-			valid = !ctrlTexOffsetT->getTentative();
-			if (valid || align_planar)
-			{
-				value = ctrlTexOffsetT->get();
-				object->setTEOffsetT( te, value );
-
-				if (align_planar) 
-				{
-					LLPanelFace::LLSelectedTEMaterial::setNormalOffsetY(mPanel, value, te, object->getID());
-					LLPanelFace::LLSelectedTEMaterial::setSpecularOffsetY(mPanel, value, te, object->getID());
-				}
-			}
-		}
-
-		if (ctrlTexRotation)
-		{
-			valid = !ctrlTexRotation->getTentative();
-			if (valid || align_planar)
-			{
-				value = ctrlTexRotation->get() * DEG_TO_RAD;
-				object->setTERotation( te, value );
-
-				if (align_planar) 
-				{
-					LLPanelFace::LLSelectedTEMaterial::setNormalRotation(mPanel, value, te, object->getID());
-					LLPanelFace::LLSelectedTEMaterial::setSpecularRotation(mPanel, value, te, object->getID());
-				}
-			}
-		}
-		return true;
-	}
+                {
+                    value *= 0.5f;
+                }
+                object->setTEScaleT( te, value );
+
+                if (align_planar)
+                {
+                    LLPanelFace::LLSelectedTEMaterial::setNormalRepeatY(mPanel, value, te, object->getID());
+                    LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatY(mPanel, value, te, object->getID());
+                }
+            }
+        }
+
+        if (ctrlTexOffsetS)
+        {
+            valid = !ctrlTexOffsetS->getTentative();
+            if (valid || align_planar)
+            {
+                value = ctrlTexOffsetS->get();
+                object->setTEOffsetS( te, value );
+
+                if (align_planar)
+                {
+                    LLPanelFace::LLSelectedTEMaterial::setNormalOffsetX(mPanel, value, te, object->getID());
+                    LLPanelFace::LLSelectedTEMaterial::setSpecularOffsetX(mPanel, value, te, object->getID());
+                }
+            }
+        }
+
+        if (ctrlTexOffsetT)
+        {
+            valid = !ctrlTexOffsetT->getTentative();
+            if (valid || align_planar)
+            {
+                value = ctrlTexOffsetT->get();
+                object->setTEOffsetT( te, value );
+
+                if (align_planar)
+                {
+                    LLPanelFace::LLSelectedTEMaterial::setNormalOffsetY(mPanel, value, te, object->getID());
+                    LLPanelFace::LLSelectedTEMaterial::setSpecularOffsetY(mPanel, value, te, object->getID());
+                }
+            }
+        }
+
+        if (ctrlTexRotation)
+        {
+            valid = !ctrlTexRotation->getTentative();
+            if (valid || align_planar)
+            {
+                value = ctrlTexRotation->get() * DEG_TO_RAD;
+                object->setTERotation( te, value );
+
+                if (align_planar)
+                {
+                    LLPanelFace::LLSelectedTEMaterial::setNormalRotation(mPanel, value, te, object->getID());
+                    LLPanelFace::LLSelectedTEMaterial::setSpecularRotation(mPanel, value, te, object->getID());
+                }
+            }
+        }
+        return true;
+    }
 private:
-	LLPanelFace* mPanel;
+    LLPanelFace* mPanel;
 };
 
 // Functor that aligns a face to mCenterFace
 struct LLPanelFaceSetAlignedTEFunctor : public LLSelectedTEFunctor
 {
-	LLPanelFaceSetAlignedTEFunctor(LLPanelFace* panel, LLFace* center_face) :
-		mPanel(panel),
-		mCenterFace(center_face) {}
-
-	virtual bool apply(LLViewerObject* object, S32 te)
-	{
-		LLFace* facep = object->mDrawable->getFace(te);
-		if (!facep)
-		{
-			return true;
-		}
-
-		if (facep->getViewerObject()->getVolume()->getNumVolumeFaces() <= te)
-		{
-			return true;
-		}
-
-		bool set_aligned = true;
-		if (facep == mCenterFace)
-		{
-			set_aligned = false;
-		}
-		if (set_aligned)
-		{
-			LLVector2 uv_offset, uv_scale;
-			F32 uv_rot;
-			set_aligned = facep->calcAlignedPlanarTE(mCenterFace, &uv_offset, &uv_scale, &uv_rot);
-			if (set_aligned)
-			{
-				object->setTEOffset(te, uv_offset.mV[VX], uv_offset.mV[VY]);
-				object->setTEScale(te, uv_scale.mV[VX], uv_scale.mV[VY]);
-				object->setTERotation(te, uv_rot);
-
-				LLPanelFace::LLSelectedTEMaterial::setNormalRotation(mPanel, uv_rot, te, object->getID());
-				LLPanelFace::LLSelectedTEMaterial::setSpecularRotation(mPanel, uv_rot, te, object->getID());
-
-				LLPanelFace::LLSelectedTEMaterial::setNormalOffsetX(mPanel, uv_offset.mV[VX], te, object->getID());
-				LLPanelFace::LLSelectedTEMaterial::setNormalOffsetY(mPanel, uv_offset.mV[VY], te, object->getID());
-				LLPanelFace::LLSelectedTEMaterial::setNormalRepeatX(mPanel, uv_scale.mV[VX], te, object->getID());
-				LLPanelFace::LLSelectedTEMaterial::setNormalRepeatY(mPanel, uv_scale.mV[VY], te, object->getID());
-
-				LLPanelFace::LLSelectedTEMaterial::setSpecularOffsetX(mPanel, uv_offset.mV[VX], te, object->getID());
-				LLPanelFace::LLSelectedTEMaterial::setSpecularOffsetY(mPanel, uv_offset.mV[VY], te, object->getID());
-				LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatX(mPanel, uv_scale.mV[VX], te, object->getID());
-				LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatY(mPanel, uv_scale.mV[VY], te, object->getID());
-			}
-		}
-		if (!set_aligned)
-		{
-			LLPanelFaceSetTEFunctor setfunc(mPanel);
-			setfunc.apply(object, te);
-		}
-		return true;
-	}
+    LLPanelFaceSetAlignedTEFunctor(LLPanelFace* panel, LLFace* center_face) :
+        mPanel(panel),
+        mCenterFace(center_face) {}
+
+    virtual bool apply(LLViewerObject* object, S32 te)
+    {
+        LLFace* facep = object->mDrawable->getFace(te);
+        if (!facep)
+        {
+            return true;
+        }
+
+        if (facep->getViewerObject()->getVolume()->getNumVolumeFaces() <= te)
+        {
+            return true;
+        }
+
+        bool set_aligned = true;
+        if (facep == mCenterFace)
+        {
+            set_aligned = false;
+        }
+        if (set_aligned)
+        {
+            LLVector2 uv_offset, uv_scale;
+            F32 uv_rot;
+            set_aligned = facep->calcAlignedPlanarTE(mCenterFace, &uv_offset, &uv_scale, &uv_rot);
+            if (set_aligned)
+            {
+                object->setTEOffset(te, uv_offset.mV[VX], uv_offset.mV[VY]);
+                object->setTEScale(te, uv_scale.mV[VX], uv_scale.mV[VY]);
+                object->setTERotation(te, uv_rot);
+
+                LLPanelFace::LLSelectedTEMaterial::setNormalRotation(mPanel, uv_rot, te, object->getID());
+                LLPanelFace::LLSelectedTEMaterial::setSpecularRotation(mPanel, uv_rot, te, object->getID());
+
+                LLPanelFace::LLSelectedTEMaterial::setNormalOffsetX(mPanel, uv_offset.mV[VX], te, object->getID());
+                LLPanelFace::LLSelectedTEMaterial::setNormalOffsetY(mPanel, uv_offset.mV[VY], te, object->getID());
+                LLPanelFace::LLSelectedTEMaterial::setNormalRepeatX(mPanel, uv_scale.mV[VX], te, object->getID());
+                LLPanelFace::LLSelectedTEMaterial::setNormalRepeatY(mPanel, uv_scale.mV[VY], te, object->getID());
+
+                LLPanelFace::LLSelectedTEMaterial::setSpecularOffsetX(mPanel, uv_offset.mV[VX], te, object->getID());
+                LLPanelFace::LLSelectedTEMaterial::setSpecularOffsetY(mPanel, uv_offset.mV[VY], te, object->getID());
+                LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatX(mPanel, uv_scale.mV[VX], te, object->getID());
+                LLPanelFace::LLSelectedTEMaterial::setSpecularRepeatY(mPanel, uv_scale.mV[VY], te, object->getID());
+            }
+        }
+        if (!set_aligned)
+        {
+            LLPanelFaceSetTEFunctor setfunc(mPanel);
+            setfunc.apply(object, te);
+        }
+        return true;
+    }
 private:
-	LLPanelFace* mPanel;
-	LLFace* mCenterFace;
+    LLPanelFace* mPanel;
+    LLFace* mCenterFace;
 };
 
 struct LLPanelFaceSetAlignedConcreteTEFunctor : public LLSelectedTEFunctor
@@ -875,7 +875,7 @@ struct LLPanelFaceSetAlignedConcreteTEFunctor : public LLSelectedTEFunctor
                 }
             }
         }
-        
+
         return true;
     }
 private:
@@ -887,36 +887,36 @@ struct LLPanelFaceSetAlignedConcreteTEFunctor : public LLSelectedTEFunctor
 // Functor that tests if a face is aligned to mCenterFace
 struct LLPanelFaceGetIsAlignedTEFunctor : public LLSelectedTEFunctor
 {
-	LLPanelFaceGetIsAlignedTEFunctor(LLFace* center_face) :
-		mCenterFace(center_face) {}
-
-	virtual bool apply(LLViewerObject* object, S32 te)
-	{
-		LLFace* facep = object->mDrawable->getFace(te);
-		if (!facep)
-		{
-			return false;
-		}
-
-		if (facep->getViewerObject()->getVolume()->getNumVolumeFaces() <= te)
-		{ //volume face does not exist, can't be aligned
-			return false;
-		}
-
-		if (facep == mCenterFace)
-		{
-			return true;
-		}
-		
-		LLVector2 aligned_st_offset, aligned_st_scale;
-		F32 aligned_st_rot;
-		if ( facep->calcAlignedPlanarTE(mCenterFace, &aligned_st_offset, &aligned_st_scale, &aligned_st_rot) )
-		{
-			const LLTextureEntry* tep = facep->getTextureEntry();
-			LLVector2 st_offset, st_scale;
-			tep->getOffset(&st_offset.mV[VX], &st_offset.mV[VY]);
-			tep->getScale(&st_scale.mV[VX], &st_scale.mV[VY]);
-			F32 st_rot = tep->getRotation();
+    LLPanelFaceGetIsAlignedTEFunctor(LLFace* center_face) :
+        mCenterFace(center_face) {}
+
+    virtual bool apply(LLViewerObject* object, S32 te)
+    {
+        LLFace* facep = object->mDrawable->getFace(te);
+        if (!facep)
+        {
+            return false;
+        }
+
+        if (facep->getViewerObject()->getVolume()->getNumVolumeFaces() <= te)
+        { //volume face does not exist, can't be aligned
+            return false;
+        }
+
+        if (facep == mCenterFace)
+        {
+            return true;
+        }
+
+        LLVector2 aligned_st_offset, aligned_st_scale;
+        F32 aligned_st_rot;
+        if ( facep->calcAlignedPlanarTE(mCenterFace, &aligned_st_offset, &aligned_st_scale, &aligned_st_rot) )
+        {
+            const LLTextureEntry* tep = facep->getTextureEntry();
+            LLVector2 st_offset, st_scale;
+            tep->getOffset(&st_offset.mV[VX], &st_offset.mV[VY]);
+            tep->getScale(&st_scale.mV[VX], &st_scale.mV[VY]);
+            F32 st_rot = tep->getRotation();
 
             bool eq_offset_x = is_approx_equal_fraction(st_offset.mV[VX], aligned_st_offset.mV[VX], 12);
             bool eq_offset_y = is_approx_equal_fraction(st_offset.mV[VY], aligned_st_offset.mV[VY], 12);
@@ -924,49 +924,49 @@ struct LLPanelFaceGetIsAlignedTEFunctor : public LLSelectedTEFunctor
             bool eq_scale_y  = is_approx_equal_fraction(st_scale.mV[VY], aligned_st_scale.mV[VY], 12);
             bool eq_rot      = is_approx_equal_fraction(st_rot, aligned_st_rot, 6);
 
-			// needs a fuzzy comparison, because of fp errors
-			if (eq_offset_x && 
-				eq_offset_y && 
-				eq_scale_x &&
-				eq_scale_y &&
-				eq_rot)
-			{
-				return true;
-			}
-		}
-		return false;
-	}
+            // needs a fuzzy comparison, because of fp errors
+            if (eq_offset_x &&
+                eq_offset_y &&
+                eq_scale_x &&
+                eq_scale_y &&
+                eq_rot)
+            {
+                return true;
+            }
+        }
+        return false;
+    }
 private:
-	LLFace* mCenterFace;
+    LLFace* mCenterFace;
 };
 
 struct LLPanelFaceSendFunctor : public LLSelectedObjectFunctor
 {
-	virtual bool apply(LLViewerObject* object)
-	{
-		object->sendTEUpdate();
-		return true;
-	}
+    virtual bool apply(LLViewerObject* object)
+    {
+        object->sendTEUpdate();
+        return true;
+    }
 };
 
 void LLPanelFace::sendTextureInfo()
 {
-	if ((bool)childGetValue("checkbox planar align").asBoolean())
-	{
-		LLFace* last_face = NULL;
-		bool identical_face =false;
-		LLSelectedTE::getFace(last_face, identical_face);		
-		LLPanelFaceSetAlignedTEFunctor setfunc(this, last_face);
-		LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc);
-	}
-	else
-	{
-		LLPanelFaceSetTEFunctor setfunc(this);
-		LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc);
-	}
+    if ((bool)childGetValue("checkbox planar align").asBoolean())
+    {
+        LLFace* last_face = NULL;
+        bool identical_face =false;
+        LLSelectedTE::getFace(last_face, identical_face);
+        LLPanelFaceSetAlignedTEFunctor setfunc(this, last_face);
+        LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc);
+    }
+    else
+    {
+        LLPanelFaceSetTEFunctor setfunc(this);
+        LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc);
+    }
 
-	LLPanelFaceSendFunctor sendfunc;
-	LLSelectMgr::getInstance()->getSelection()->applyToObjects(&sendfunc);
+    LLPanelFaceSendFunctor sendfunc;
+    LLSelectMgr::getInstance()->getSelection()->applyToObjects(&sendfunc);
 }
 
 void LLPanelFace::alignTestureLayer()
@@ -981,19 +981,19 @@ void LLPanelFace::alignTestureLayer()
 
 void LLPanelFace::getState()
 {
-	updateUI();
+    updateUI();
 }
 
 void LLPanelFace::updateUI(bool force_set_values /*false*/)
 { //set state of UI to match state of texture entry(ies)  (calls setEnabled, setValue, etc, but NOT setVisible)
     LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstNode();
-	LLViewerObject* objectp = node ? node->getObject() : NULL;
+    LLViewerObject* objectp = node ? node->getObject() : NULL;
 
-	if (objectp
-		&& objectp->getPCode() == LL_PCODE_VOLUME
-		&& objectp->permModify())
-	{
-		BOOL editable = objectp->permModify() && !objectp->isPermanentEnforced();
+    if (objectp
+        && objectp->getPCode() == LL_PCODE_VOLUME
+        && objectp->permModify())
+    {
+        BOOL editable = objectp->permModify() && !objectp->isPermanentEnforced();
         BOOL attachment = objectp->isAttachment();
 
         bool has_pbr_material;
@@ -1002,9 +1002,9 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
 
         const bool has_material = !has_pbr_material;
 
-		// only turn on auto-adjust button if there is a media renderer and the media is loaded
+        // only turn on auto-adjust button if there is a media renderer and the media is loaded
         childSetEnabled("button align", editable);
-		
+
         if (mComboMatMedia->getCurrentIndex() < MATMEDIA_MATERIAL)
         {
             // When selecting an object with a pbr and UI combo is not set,
@@ -1041,8 +1041,8 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
 
         static S32 selected_te = -1;
         static LLUUID prev_obj_id;
-        if ((LLToolFace::getInstance() == LLToolMgr::getInstance()->getCurrentTool()) && 
-            !LLSelectMgr::getInstance()->getSelection()->isMultipleTESelected()) 
+        if ((LLToolFace::getInstance() == LLToolMgr::getInstance()->getCurrentTool()) &&
+            !LLSelectMgr::getInstance()->getSelection()->isMultipleTESelected())
         {
             S32 new_selection = -1; // Don't use getLastSelectedTE, it could have been deselected
             S32 num_tes = llmin((S32)objectp->getNumTEs(), (S32)objectp->getNumFaces());
@@ -1065,11 +1065,11 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
                 {
                     mComboMatMedia->selectNthItem(MATMEDIA_PBR);
                 }
-                else if (te_has_media) 
+                else if (te_has_media)
                 {
                     mComboMatMedia->selectNthItem(MATMEDIA_MEDIA);
                 }
-                else if (id.notNull() || normmap_id.notNull() || specmap_id.notNull()) 
+                else if (id.notNull() || normmap_id.notNull() || specmap_id.notNull())
                 {
                     mComboMatMedia->selectNthItem(MATMEDIA_MATERIAL);
                 }
@@ -1077,11 +1077,11 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
                 prev_obj_id = objectp->getID();
             }
         }
-        else 
+        else
         {
             if (prev_obj_id != objectp->getID())
             {
-                if (has_pbr_material && (mComboMatMedia->getCurrentIndex() == MATMEDIA_MATERIAL)) 
+                if (has_pbr_material && (mComboMatMedia->getCurrentIndex() == MATMEDIA_MATERIAL))
                 {
                     mComboMatMedia->selectNthItem(MATMEDIA_PBR);
                 }
@@ -1110,24 +1110,24 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
         const bool pbr_selected = mComboMatMedia->getCurrentIndex() == MATMEDIA_PBR;
         const bool texture_info_selected = pbr_selected && radio_pbr_type->getSelectedIndex() != PBRTYPE_RENDER_MATERIAL_ID;
 
-		getChildView("checkbox_sync_settings")->setEnabled(editable);
-		childSetValue("checkbox_sync_settings", gSavedSettings.getBOOL("SyncMaterialSettings"));
+        getChildView("checkbox_sync_settings")->setEnabled(editable);
+        childSetValue("checkbox_sync_settings", gSavedSettings.getBOOL("SyncMaterialSettings"));
 
-		updateVisibility(objectp);
+        updateVisibility(objectp);
 
-		// Color swatch
-		{
-			getChildView("color label")->setEnabled(editable);
-		}
-		LLColorSwatchCtrl* color_swatch = findChild<LLColorSwatchCtrl>("colorswatch");
+        // Color swatch
+        {
+            getChildView("color label")->setEnabled(editable);
+        }
+        LLColorSwatchCtrl* color_swatch = findChild<LLColorSwatchCtrl>("colorswatch");
 
-		LLColor4 color = LLColor4::white;
-		bool identical_color = false;
+        LLColor4 color = LLColor4::white;
+        bool identical_color = false;
 
-		if (color_swatch)
-		{
-			LLSelectedTE::getColor(color, identical_color);
-			LLColor4 prev_color = color_swatch->get();
+        if (color_swatch)
+        {
+            LLSelectedTE::getColor(color, identical_color);
+            LLColor4 prev_color = color_swatch->get();
 
             color_swatch->setOriginal(color);
             color_swatch->set(color, force_set_values || (prev_color != color) || !editable);
@@ -1135,177 +1135,177 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
             color_swatch->setValid(editable && !has_pbr_material);
             color_swatch->setEnabled( editable && !has_pbr_material);
             color_swatch->setCanApplyImmediately( editable && !has_pbr_material);
-		}
+        }
 
-		// Color transparency
-		getChildView("color trans")->setEnabled(editable);
+        // Color transparency
+        getChildView("color trans")->setEnabled(editable);
 
-		F32 transparency = (1.f - color.mV[VALPHA]) * 100.f;
-		getChild<LLUICtrl>("ColorTrans")->setValue(editable ? transparency : 0);
-		getChildView("ColorTrans")->setEnabled(editable && has_material);
+        F32 transparency = (1.f - color.mV[VALPHA]) * 100.f;
+        getChild<LLUICtrl>("ColorTrans")->setValue(editable ? transparency : 0);
+        getChildView("ColorTrans")->setEnabled(editable && has_material);
 
-		U8 shiny = 0;
-		bool identical_shiny = false;
+        U8 shiny = 0;
+        bool identical_shiny = false;
 
-		// Shiny
-		LLSelectedTE::getShiny(shiny, identical_shiny);
-		identical = identical && identical_shiny;
+        // Shiny
+        LLSelectedTE::getShiny(shiny, identical_shiny);
+        identical = identical && identical_shiny;
 
-		shiny = specmap_id.isNull() ? shiny : SHINY_TEXTURE;
+        shiny = specmap_id.isNull() ? shiny : SHINY_TEXTURE;
 
-		LLCtrlSelectionInterface* combobox_shininess = mComboShininess->getSelectionInterface();
-		if (combobox_shininess)
-		{
-			combobox_shininess->selectNthItem((S32)shiny);
-		}
+        LLCtrlSelectionInterface* combobox_shininess = mComboShininess->getSelectionInterface();
+        if (combobox_shininess)
+        {
+            combobox_shininess->selectNthItem((S32)shiny);
+        }
 
-		getChildView("label shininess")->setEnabled(editable);
+        getChildView("label shininess")->setEnabled(editable);
         mComboShininess->setEnabled(editable);
 
-		getChildView("label glossiness")->setEnabled(editable);			
-		mSpinGlossiness->setEnabled(editable);
+        getChildView("label glossiness")->setEnabled(editable);
+        mSpinGlossiness->setEnabled(editable);
 
-		getChildView("label environment")->setEnabled(editable);
+        getChildView("label environment")->setEnabled(editable);
         mSpinEnvironment->setEnabled(editable);
-		getChildView("label shinycolor")->setEnabled(editable);
-					
-		mComboShininess->setTentative(!identical_spec);
+        getChildView("label shinycolor")->setEnabled(editable);
+
+        mComboShininess->setTentative(!identical_spec);
         mSpinGlossiness->setTentative(!identical_spec);
-        mSpinEnvironment->setTentative(!identical_spec);			
-			
-		{
+        mSpinEnvironment->setTentative(!identical_spec);
+
+        {
             mShinyColorSwatch->setTentative(!identical_spec);
-			mShinyColorSwatch->setValid(editable);
-			mShinyColorSwatch->setEnabled( editable );
-			mShinyColorSwatch->setCanApplyImmediately( editable );
-		}
-
-		U8 bumpy = 0;
-		// Bumpy
-		{
-			bool identical_bumpy = false;
-			LLSelectedTE::getBumpmap(bumpy,identical_bumpy);
-
-			LLUUID norm_map_id = getCurrentNormalMap();
-			LLCtrlSelectionInterface* combobox_bumpiness = childGetSelectionInterface("combobox bumpiness");
-
-			bumpy = norm_map_id.isNull() ? bumpy : BUMPY_TEXTURE;
-
-			if (combobox_bumpiness)
-			{
-				combobox_bumpiness->selectNthItem((S32)bumpy);
-			}
-			else
-			{
-				LL_WARNS() << "failed childGetSelectionInterface for 'combobox bumpiness'" << LL_ENDL;
-			}
-
-			getChildView("combobox bumpiness")->setEnabled(editable);
-			getChild<LLUICtrl>("combobox bumpiness")->setTentative(!identical_bumpy);
-			getChildView("label bumpiness")->setEnabled(editable);
-		}
-
-		// Texture
-		{
-			mIsAlpha = FALSE;
-			LLGLenum image_format = GL_RGB;
-			bool identical_image_format = false;
-			LLSelectedTE::getImageFormat(image_format, identical_image_format);
-            
-			mIsAlpha = FALSE;
-			switch (image_format)
-			{
-				case GL_RGBA:
-				case GL_ALPHA:
-				{
-					mIsAlpha = TRUE;
-				}
-				break;
-
-				case GL_RGB: break;
-				default:
-				{
-					LL_WARNS() << "Unexpected tex format in LLPanelFace...resorting to no alpha" << LL_ENDL;
-				}
-				break;
-			}
-
-			if (LLViewerMedia::getInstance()->textureHasMedia(id))
-			{
-				getChildView("button align")->setEnabled(editable);
-			}
-			
-			// Diffuse Alpha Mode
-
-			// Init to the default that is appropriate for the alpha content of the asset
-			//
-			U8 alpha_mode = mIsAlpha ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
-
-			bool identical_alpha_mode = false;
-
-			// See if that's been overridden by a material setting for same...
-			//
-			LLSelectedTEMaterial::getCurrentDiffuseAlphaMode(alpha_mode, identical_alpha_mode, mIsAlpha);
-
-			LLCtrlSelectionInterface* combobox_alphamode = mComboAlphaMode->getSelectionInterface();
-			if (combobox_alphamode)
-			{
-				//it is invalid to have any alpha mode other than blend if transparency is greater than zero ... 
-				// Want masking? Want emissive? Tough! You get BLEND!
-				alpha_mode = (transparency > 0.f) ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : alpha_mode;
-
-				// ... unless there is no alpha channel in the texture, in which case alpha mode MUST be none
-				alpha_mode = mIsAlpha ? alpha_mode : LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
-
-				combobox_alphamode->selectNthItem(alpha_mode);
-			}
-			else
-			{
-				LL_WARNS() << "failed childGetSelectionInterface for 'combobox alphamode'" << LL_ENDL;
-			}
-
-			updateAlphaControls();
-
-			if (texture_ctrl)
-			{
-				if (identical_diffuse)
-				{
-					texture_ctrl->setTentative(FALSE);
-					texture_ctrl->setEnabled(editable && !has_pbr_material);
-					texture_ctrl->setImageAssetID(id);
-					getChildView("combobox alphamode")->setEnabled(editable && mIsAlpha && transparency <= 0.f && !has_pbr_material);
-					getChildView("label alphamode")->setEnabled(editable && mIsAlpha && !has_pbr_material);
-					getChildView("maskcutoff")->setEnabled(editable && mIsAlpha && !has_pbr_material);
-					getChildView("label maskcutoff")->setEnabled(editable && mIsAlpha && !has_pbr_material);
-
-					texture_ctrl->setBakeTextureEnabled(TRUE);
-				}
-				else if (id.isNull())
-				{
-					// None selected
-					texture_ctrl->setTentative(FALSE);
-					texture_ctrl->setEnabled(FALSE);
-					texture_ctrl->setImageAssetID(LLUUID::null);
-					getChildView("combobox alphamode")->setEnabled(FALSE);
-					getChildView("label alphamode")->setEnabled(FALSE);
-					getChildView("maskcutoff")->setEnabled(FALSE);
-					getChildView("label maskcutoff")->setEnabled(FALSE);
-
-					texture_ctrl->setBakeTextureEnabled(false);
-				}
-				else
-				{
-					// Tentative: multiple selected with different textures
-					texture_ctrl->setTentative(TRUE);
-					texture_ctrl->setEnabled(editable && !has_pbr_material);
-					texture_ctrl->setImageAssetID(id);
-					getChildView("combobox alphamode")->setEnabled(editable && mIsAlpha && transparency <= 0.f && !has_pbr_material);
-					getChildView("label alphamode")->setEnabled(editable && mIsAlpha && !has_pbr_material);
-					getChildView("maskcutoff")->setEnabled(editable && mIsAlpha && !has_pbr_material);
-					getChildView("label maskcutoff")->setEnabled(editable && mIsAlpha && !has_pbr_material);
-					
-					texture_ctrl->setBakeTextureEnabled(TRUE);
-				}
+            mShinyColorSwatch->setValid(editable);
+            mShinyColorSwatch->setEnabled( editable );
+            mShinyColorSwatch->setCanApplyImmediately( editable );
+        }
+
+        U8 bumpy = 0;
+        // Bumpy
+        {
+            bool identical_bumpy = false;
+            LLSelectedTE::getBumpmap(bumpy,identical_bumpy);
+
+            LLUUID norm_map_id = getCurrentNormalMap();
+            LLCtrlSelectionInterface* combobox_bumpiness = childGetSelectionInterface("combobox bumpiness");
+
+            bumpy = norm_map_id.isNull() ? bumpy : BUMPY_TEXTURE;
+
+            if (combobox_bumpiness)
+            {
+                combobox_bumpiness->selectNthItem((S32)bumpy);
+            }
+            else
+            {
+                LL_WARNS() << "failed childGetSelectionInterface for 'combobox bumpiness'" << LL_ENDL;
+            }
+
+            getChildView("combobox bumpiness")->setEnabled(editable);
+            getChild<LLUICtrl>("combobox bumpiness")->setTentative(!identical_bumpy);
+            getChildView("label bumpiness")->setEnabled(editable);
+        }
+
+        // Texture
+        {
+            mIsAlpha = FALSE;
+            LLGLenum image_format = GL_RGB;
+            bool identical_image_format = false;
+            LLSelectedTE::getImageFormat(image_format, identical_image_format);
+
+            mIsAlpha = FALSE;
+            switch (image_format)
+            {
+                case GL_RGBA:
+                case GL_ALPHA:
+                {
+                    mIsAlpha = TRUE;
+                }
+                break;
+
+                case GL_RGB: break;
+                default:
+                {
+                    LL_WARNS() << "Unexpected tex format in LLPanelFace...resorting to no alpha" << LL_ENDL;
+                }
+                break;
+            }
+
+            if (LLViewerMedia::getInstance()->textureHasMedia(id))
+            {
+                getChildView("button align")->setEnabled(editable);
+            }
+
+            // Diffuse Alpha Mode
+
+            // Init to the default that is appropriate for the alpha content of the asset
+            //
+            U8 alpha_mode = mIsAlpha ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
+
+            bool identical_alpha_mode = false;
+
+            // See if that's been overridden by a material setting for same...
+            //
+            LLSelectedTEMaterial::getCurrentDiffuseAlphaMode(alpha_mode, identical_alpha_mode, mIsAlpha);
+
+            LLCtrlSelectionInterface* combobox_alphamode = mComboAlphaMode->getSelectionInterface();
+            if (combobox_alphamode)
+            {
+                //it is invalid to have any alpha mode other than blend if transparency is greater than zero ...
+                // Want masking? Want emissive? Tough! You get BLEND!
+                alpha_mode = (transparency > 0.f) ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : alpha_mode;
+
+                // ... unless there is no alpha channel in the texture, in which case alpha mode MUST be none
+                alpha_mode = mIsAlpha ? alpha_mode : LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
+
+                combobox_alphamode->selectNthItem(alpha_mode);
+            }
+            else
+            {
+                LL_WARNS() << "failed childGetSelectionInterface for 'combobox alphamode'" << LL_ENDL;
+            }
+
+            updateAlphaControls();
+
+            if (texture_ctrl)
+            {
+                if (identical_diffuse)
+                {
+                    texture_ctrl->setTentative(FALSE);
+                    texture_ctrl->setEnabled(editable && !has_pbr_material);
+                    texture_ctrl->setImageAssetID(id);
+                    getChildView("combobox alphamode")->setEnabled(editable && mIsAlpha && transparency <= 0.f && !has_pbr_material);
+                    getChildView("label alphamode")->setEnabled(editable && mIsAlpha && !has_pbr_material);
+                    getChildView("maskcutoff")->setEnabled(editable && mIsAlpha && !has_pbr_material);
+                    getChildView("label maskcutoff")->setEnabled(editable && mIsAlpha && !has_pbr_material);
+
+                    texture_ctrl->setBakeTextureEnabled(TRUE);
+                }
+                else if (id.isNull())
+                {
+                    // None selected
+                    texture_ctrl->setTentative(FALSE);
+                    texture_ctrl->setEnabled(FALSE);
+                    texture_ctrl->setImageAssetID(LLUUID::null);
+                    getChildView("combobox alphamode")->setEnabled(FALSE);
+                    getChildView("label alphamode")->setEnabled(FALSE);
+                    getChildView("maskcutoff")->setEnabled(FALSE);
+                    getChildView("label maskcutoff")->setEnabled(FALSE);
+
+                    texture_ctrl->setBakeTextureEnabled(false);
+                }
+                else
+                {
+                    // Tentative: multiple selected with different textures
+                    texture_ctrl->setTentative(TRUE);
+                    texture_ctrl->setEnabled(editable && !has_pbr_material);
+                    texture_ctrl->setImageAssetID(id);
+                    getChildView("combobox alphamode")->setEnabled(editable && mIsAlpha && transparency <= 0.f && !has_pbr_material);
+                    getChildView("label alphamode")->setEnabled(editable && mIsAlpha && !has_pbr_material);
+                    getChildView("maskcutoff")->setEnabled(editable && mIsAlpha && !has_pbr_material);
+                    getChildView("label maskcutoff")->setEnabled(editable && mIsAlpha && !has_pbr_material);
+
+                    texture_ctrl->setBakeTextureEnabled(TRUE);
+                }
 
                 if (attachment)
                 {
@@ -1318,13 +1318,13 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
                 {
                     texture_ctrl->setImmediateFilterPermMask(PERM_NONE);
                 }
-			}
+            }
 
-			if (shinytexture_ctrl)
-			{
-				shinytexture_ctrl->setTentative( !identical_spec );
-				shinytexture_ctrl->setEnabled( editable && !has_pbr_material);
-				shinytexture_ctrl->setImageAssetID( specmap_id );
+            if (shinytexture_ctrl)
+            {
+                shinytexture_ctrl->setTentative( !identical_spec );
+                shinytexture_ctrl->setEnabled( editable && !has_pbr_material);
+                shinytexture_ctrl->setImageAssetID( specmap_id );
 
                 if (attachment)
                 {
@@ -1334,13 +1334,13 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
                 {
                     shinytexture_ctrl->setImmediateFilterPermMask(PERM_NONE);
                 }
-			}
+            }
 
-			if (bumpytexture_ctrl)
-			{
-				bumpytexture_ctrl->setTentative( !identical_norm );
-				bumpytexture_ctrl->setEnabled( editable && !has_pbr_material);
-				bumpytexture_ctrl->setImageAssetID( normmap_id );
+            if (bumpytexture_ctrl)
+            {
+                bumpytexture_ctrl->setTentative( !identical_norm );
+                bumpytexture_ctrl->setEnabled( editable && !has_pbr_material);
+                bumpytexture_ctrl->setImageAssetID( normmap_id );
 
                 if (attachment)
                 {
@@ -1350,242 +1350,242 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
                 {
                     bumpytexture_ctrl->setImmediateFilterPermMask(PERM_NONE);
                 }
-			}
-		}
-
-		// planar align
-		bool align_planar = false;
-		bool identical_planar_aligned = false;
-		{
-			LLCheckBoxCtrl*	cb_planar_align = getChild<LLCheckBoxCtrl>("checkbox planar align");
-			align_planar = (cb_planar_align && cb_planar_align->get());
-
-			bool enabled = (editable && isIdenticalPlanarTexgen() && !texture_info_selected);
-			childSetValue("checkbox planar align", align_planar && enabled);
+            }
+        }
+
+        // planar align
+        bool align_planar = false;
+        bool identical_planar_aligned = false;
+        {
+            LLCheckBoxCtrl* cb_planar_align = getChild<LLCheckBoxCtrl>("checkbox planar align");
+            align_planar = (cb_planar_align && cb_planar_align->get());
+
+            bool enabled = (editable && isIdenticalPlanarTexgen() && !texture_info_selected);
+            childSetValue("checkbox planar align", align_planar && enabled);
             childSetVisible("checkbox planar align", enabled);
-			childSetEnabled("checkbox planar align", enabled);
-			childSetEnabled("button align textures", enabled && LLSelectMgr::getInstance()->getSelection()->getObjectCount() > 1);
-
-			if (align_planar && enabled)
-			{
-				LLFace* last_face = NULL;
-				bool identical_face = false;
-				LLSelectedTE::getFace(last_face, identical_face);
-
-				LLPanelFaceGetIsAlignedTEFunctor get_is_aligend_func(last_face);
-				// this will determine if the texture param controls are tentative:
-				identical_planar_aligned = LLSelectMgr::getInstance()->getSelection()->applyToTEs(&get_is_aligend_func);
-			}
-		}
-		
-		// Needs to be public and before tex scale settings below to properly reflect
-		// behavior when in planar vs default texgen modes in the
-		// NORSPEC-84 et al
-		//
-		LLTextureEntry::e_texgen selected_texgen = LLTextureEntry::TEX_GEN_DEFAULT;
-		bool identical_texgen = true;		
-		bool identical_planar_texgen = false;
-
-		{	
-			LLSelectedTE::getTexGen(selected_texgen, identical_texgen);
-			identical_planar_texgen = (identical_texgen && (selected_texgen == LLTextureEntry::TEX_GEN_PLANAR));
-		}
-
-		// Texture scale
-		{
-			bool identical_diff_scale_s = false;
-			bool identical_spec_scale_s = false;
-			bool identical_norm_scale_s = false;
-
-			identical = align_planar ? identical_planar_aligned : identical;
-
-			F32 diff_scale_s = 1.f;			
-			F32 spec_scale_s = 1.f;
-			F32 norm_scale_s = 1.f;
-
-			LLSelectedTE::getScaleS(diff_scale_s, identical_diff_scale_s);			
-			LLSelectedTEMaterial::getSpecularRepeatX(spec_scale_s, identical_spec_scale_s);
-			LLSelectedTEMaterial::getNormalRepeatX(norm_scale_s, identical_norm_scale_s);
-
-			diff_scale_s = editable ? diff_scale_s : 1.0f;
-			diff_scale_s *= identical_planar_texgen ? 2.0f : 1.0f;
-			
-			norm_scale_s = editable ? norm_scale_s : 1.0f;
-			norm_scale_s *= identical_planar_texgen ? 2.0f : 1.0f;
-
-			spec_scale_s = editable ? spec_scale_s : 1.0f;
-			spec_scale_s *= identical_planar_texgen ? 2.0f : 1.0f;
-
-			getChild<LLUICtrl>("TexScaleU")->setValue(diff_scale_s);
-			getChild<LLUICtrl>("shinyScaleU")->setValue(spec_scale_s);
-			getChild<LLUICtrl>("bumpyScaleU")->setValue(norm_scale_s);
+            childSetEnabled("checkbox planar align", enabled);
+            childSetEnabled("button align textures", enabled && LLSelectMgr::getInstance()->getSelection()->getObjectCount() > 1);
+
+            if (align_planar && enabled)
+            {
+                LLFace* last_face = NULL;
+                bool identical_face = false;
+                LLSelectedTE::getFace(last_face, identical_face);
+
+                LLPanelFaceGetIsAlignedTEFunctor get_is_aligend_func(last_face);
+                // this will determine if the texture param controls are tentative:
+                identical_planar_aligned = LLSelectMgr::getInstance()->getSelection()->applyToTEs(&get_is_aligend_func);
+            }
+        }
+
+        // Needs to be public and before tex scale settings below to properly reflect
+        // behavior when in planar vs default texgen modes in the
+        // NORSPEC-84 et al
+        //
+        LLTextureEntry::e_texgen selected_texgen = LLTextureEntry::TEX_GEN_DEFAULT;
+        bool identical_texgen = true;
+        bool identical_planar_texgen = false;
+
+        {
+            LLSelectedTE::getTexGen(selected_texgen, identical_texgen);
+            identical_planar_texgen = (identical_texgen && (selected_texgen == LLTextureEntry::TEX_GEN_PLANAR));
+        }
+
+        // Texture scale
+        {
+            bool identical_diff_scale_s = false;
+            bool identical_spec_scale_s = false;
+            bool identical_norm_scale_s = false;
+
+            identical = align_planar ? identical_planar_aligned : identical;
+
+            F32 diff_scale_s = 1.f;
+            F32 spec_scale_s = 1.f;
+            F32 norm_scale_s = 1.f;
+
+            LLSelectedTE::getScaleS(diff_scale_s, identical_diff_scale_s);
+            LLSelectedTEMaterial::getSpecularRepeatX(spec_scale_s, identical_spec_scale_s);
+            LLSelectedTEMaterial::getNormalRepeatX(norm_scale_s, identical_norm_scale_s);
+
+            diff_scale_s = editable ? diff_scale_s : 1.0f;
+            diff_scale_s *= identical_planar_texgen ? 2.0f : 1.0f;
+
+            norm_scale_s = editable ? norm_scale_s : 1.0f;
+            norm_scale_s *= identical_planar_texgen ? 2.0f : 1.0f;
+
+            spec_scale_s = editable ? spec_scale_s : 1.0f;
+            spec_scale_s *= identical_planar_texgen ? 2.0f : 1.0f;
+
+            getChild<LLUICtrl>("TexScaleU")->setValue(diff_scale_s);
+            getChild<LLUICtrl>("shinyScaleU")->setValue(spec_scale_s);
+            getChild<LLUICtrl>("bumpyScaleU")->setValue(norm_scale_s);
 
             getChildView("TexScaleU")->setEnabled(editable && has_material);
             getChildView("shinyScaleU")->setEnabled(editable && has_material && specmap_id.notNull());
             getChildView("bumpyScaleU")->setEnabled(editable && has_material && normmap_id.notNull());
 
-			BOOL diff_scale_tentative = !(identical && identical_diff_scale_s);
-			BOOL norm_scale_tentative = !(identical && identical_norm_scale_s);
-			BOOL spec_scale_tentative = !(identical && identical_spec_scale_s);
+            BOOL diff_scale_tentative = !(identical && identical_diff_scale_s);
+            BOOL norm_scale_tentative = !(identical && identical_norm_scale_s);
+            BOOL spec_scale_tentative = !(identical && identical_spec_scale_s);
 
-			getChild<LLUICtrl>("TexScaleU")->setTentative(  LLSD(diff_scale_tentative));			
-			getChild<LLUICtrl>("shinyScaleU")->setTentative(LLSD(spec_scale_tentative));			
-			getChild<LLUICtrl>("bumpyScaleU")->setTentative(LLSD(norm_scale_tentative));
-		}
+            getChild<LLUICtrl>("TexScaleU")->setTentative(  LLSD(diff_scale_tentative));
+            getChild<LLUICtrl>("shinyScaleU")->setTentative(LLSD(spec_scale_tentative));
+            getChild<LLUICtrl>("bumpyScaleU")->setTentative(LLSD(norm_scale_tentative));
+        }
 
-		{
-			bool identical_diff_scale_t = false;
-			bool identical_spec_scale_t = false;
-			bool identical_norm_scale_t = false;
+        {
+            bool identical_diff_scale_t = false;
+            bool identical_spec_scale_t = false;
+            bool identical_norm_scale_t = false;
 
-			F32 diff_scale_t = 1.f;			
-			F32 spec_scale_t = 1.f;
-			F32 norm_scale_t = 1.f;
+            F32 diff_scale_t = 1.f;
+            F32 spec_scale_t = 1.f;
+            F32 norm_scale_t = 1.f;
 
-			LLSelectedTE::getScaleT(diff_scale_t, identical_diff_scale_t);
-			LLSelectedTEMaterial::getSpecularRepeatY(spec_scale_t, identical_spec_scale_t);
-			LLSelectedTEMaterial::getNormalRepeatY(norm_scale_t, identical_norm_scale_t);
+            LLSelectedTE::getScaleT(diff_scale_t, identical_diff_scale_t);
+            LLSelectedTEMaterial::getSpecularRepeatY(spec_scale_t, identical_spec_scale_t);
+            LLSelectedTEMaterial::getNormalRepeatY(norm_scale_t, identical_norm_scale_t);
 
-			diff_scale_t = editable ? diff_scale_t : 1.0f;
-			diff_scale_t *= identical_planar_texgen ? 2.0f : 1.0f;
+            diff_scale_t = editable ? diff_scale_t : 1.0f;
+            diff_scale_t *= identical_planar_texgen ? 2.0f : 1.0f;
 
-			norm_scale_t = editable ? norm_scale_t : 1.0f;
-			norm_scale_t *= identical_planar_texgen ? 2.0f : 1.0f;
+            norm_scale_t = editable ? norm_scale_t : 1.0f;
+            norm_scale_t *= identical_planar_texgen ? 2.0f : 1.0f;
 
-			spec_scale_t = editable ? spec_scale_t : 1.0f;
-			spec_scale_t *= identical_planar_texgen ? 2.0f : 1.0f;
+            spec_scale_t = editable ? spec_scale_t : 1.0f;
+            spec_scale_t *= identical_planar_texgen ? 2.0f : 1.0f;
 
-			BOOL diff_scale_tentative = !identical_diff_scale_t;
-			BOOL norm_scale_tentative = !identical_norm_scale_t;
-			BOOL spec_scale_tentative = !identical_spec_scale_t;
+            BOOL diff_scale_tentative = !identical_diff_scale_t;
+            BOOL norm_scale_tentative = !identical_norm_scale_t;
+            BOOL spec_scale_tentative = !identical_spec_scale_t;
 
             getChildView("TexScaleV")->setEnabled(editable && has_material);
             getChildView("shinyScaleV")->setEnabled(editable && has_material && specmap_id.notNull());
             getChildView("bumpyScaleV")->setEnabled(editable && has_material && normmap_id.notNull());
 
-			if (force_set_values)
-			{
-				getChild<LLSpinCtrl>("TexScaleV")->forceSetValue(diff_scale_t);
-			}
-			else
-			{
-				getChild<LLSpinCtrl>("TexScaleV")->setValue(diff_scale_t);
-			}
-			getChild<LLUICtrl>("shinyScaleV")->setValue(norm_scale_t);
-			getChild<LLUICtrl>("bumpyScaleV")->setValue(spec_scale_t);
-
-			getChild<LLUICtrl>("TexScaleV")->setTentative(LLSD(diff_scale_tentative));
-			getChild<LLUICtrl>("shinyScaleV")->setTentative(LLSD(norm_scale_tentative));
-			getChild<LLUICtrl>("bumpyScaleV")->setTentative(LLSD(spec_scale_tentative));
-		}
-
-		// Texture offset
-		{
-			bool identical_diff_offset_s = false;
-			bool identical_norm_offset_s = false;
-			bool identical_spec_offset_s = false;
-
-			F32 diff_offset_s = 0.0f;
-			F32 norm_offset_s = 0.0f;
-			F32 spec_offset_s = 0.0f;
-
-			LLSelectedTE::getOffsetS(diff_offset_s, identical_diff_offset_s);
-			LLSelectedTEMaterial::getNormalOffsetX(norm_offset_s, identical_norm_offset_s);
-			LLSelectedTEMaterial::getSpecularOffsetX(spec_offset_s, identical_spec_offset_s);
-
-			BOOL diff_offset_u_tentative = !(align_planar ? identical_planar_aligned : identical_diff_offset_s);
-			BOOL norm_offset_u_tentative = !(align_planar ? identical_planar_aligned : identical_norm_offset_s);
-			BOOL spec_offset_u_tentative = !(align_planar ? identical_planar_aligned : identical_spec_offset_s);
-
-			getChild<LLUICtrl>("TexOffsetU")->setValue(  editable ? diff_offset_s : 0.0f);
-			getChild<LLUICtrl>("bumpyOffsetU")->setValue(editable ? norm_offset_s : 0.0f);
-			getChild<LLUICtrl>("shinyOffsetU")->setValue(editable ? spec_offset_s : 0.0f);
-
-			getChild<LLUICtrl>("TexOffsetU")->setTentative(LLSD(diff_offset_u_tentative));
-			getChild<LLUICtrl>("shinyOffsetU")->setTentative(LLSD(norm_offset_u_tentative));
-			getChild<LLUICtrl>("bumpyOffsetU")->setTentative(LLSD(spec_offset_u_tentative));
+            if (force_set_values)
+            {
+                getChild<LLSpinCtrl>("TexScaleV")->forceSetValue(diff_scale_t);
+            }
+            else
+            {
+                getChild<LLSpinCtrl>("TexScaleV")->setValue(diff_scale_t);
+            }
+            getChild<LLUICtrl>("shinyScaleV")->setValue(norm_scale_t);
+            getChild<LLUICtrl>("bumpyScaleV")->setValue(spec_scale_t);
+
+            getChild<LLUICtrl>("TexScaleV")->setTentative(LLSD(diff_scale_tentative));
+            getChild<LLUICtrl>("shinyScaleV")->setTentative(LLSD(norm_scale_tentative));
+            getChild<LLUICtrl>("bumpyScaleV")->setTentative(LLSD(spec_scale_tentative));
+        }
+
+        // Texture offset
+        {
+            bool identical_diff_offset_s = false;
+            bool identical_norm_offset_s = false;
+            bool identical_spec_offset_s = false;
+
+            F32 diff_offset_s = 0.0f;
+            F32 norm_offset_s = 0.0f;
+            F32 spec_offset_s = 0.0f;
+
+            LLSelectedTE::getOffsetS(diff_offset_s, identical_diff_offset_s);
+            LLSelectedTEMaterial::getNormalOffsetX(norm_offset_s, identical_norm_offset_s);
+            LLSelectedTEMaterial::getSpecularOffsetX(spec_offset_s, identical_spec_offset_s);
+
+            BOOL diff_offset_u_tentative = !(align_planar ? identical_planar_aligned : identical_diff_offset_s);
+            BOOL norm_offset_u_tentative = !(align_planar ? identical_planar_aligned : identical_norm_offset_s);
+            BOOL spec_offset_u_tentative = !(align_planar ? identical_planar_aligned : identical_spec_offset_s);
+
+            getChild<LLUICtrl>("TexOffsetU")->setValue(  editable ? diff_offset_s : 0.0f);
+            getChild<LLUICtrl>("bumpyOffsetU")->setValue(editable ? norm_offset_s : 0.0f);
+            getChild<LLUICtrl>("shinyOffsetU")->setValue(editable ? spec_offset_s : 0.0f);
+
+            getChild<LLUICtrl>("TexOffsetU")->setTentative(LLSD(diff_offset_u_tentative));
+            getChild<LLUICtrl>("shinyOffsetU")->setTentative(LLSD(norm_offset_u_tentative));
+            getChild<LLUICtrl>("bumpyOffsetU")->setTentative(LLSD(spec_offset_u_tentative));
 
             getChildView("TexOffsetU")->setEnabled(editable && has_material);
             getChildView("shinyOffsetU")->setEnabled(editable && has_material && specmap_id.notNull());
             getChildView("bumpyOffsetU")->setEnabled(editable && has_material && normmap_id.notNull());
-		}
+        }
+
+        {
+            bool identical_diff_offset_t = false;
+            bool identical_norm_offset_t = false;
+            bool identical_spec_offset_t = false;
 
-		{
-			bool identical_diff_offset_t = false;
-			bool identical_norm_offset_t = false;
-			bool identical_spec_offset_t = false;
+            F32 diff_offset_t = 0.0f;
+            F32 norm_offset_t = 0.0f;
+            F32 spec_offset_t = 0.0f;
 
-			F32 diff_offset_t = 0.0f;
-			F32 norm_offset_t = 0.0f;
-			F32 spec_offset_t = 0.0f;
+            LLSelectedTE::getOffsetT(diff_offset_t, identical_diff_offset_t);
+            LLSelectedTEMaterial::getNormalOffsetY(norm_offset_t, identical_norm_offset_t);
+            LLSelectedTEMaterial::getSpecularOffsetY(spec_offset_t, identical_spec_offset_t);
 
-			LLSelectedTE::getOffsetT(diff_offset_t, identical_diff_offset_t);
-			LLSelectedTEMaterial::getNormalOffsetY(norm_offset_t, identical_norm_offset_t);
-			LLSelectedTEMaterial::getSpecularOffsetY(spec_offset_t, identical_spec_offset_t);
-			
-			BOOL diff_offset_v_tentative = !(align_planar ? identical_planar_aligned : identical_diff_offset_t);
-			BOOL norm_offset_v_tentative = !(align_planar ? identical_planar_aligned : identical_norm_offset_t);
-			BOOL spec_offset_v_tentative = !(align_planar ? identical_planar_aligned : identical_spec_offset_t);
+            BOOL diff_offset_v_tentative = !(align_planar ? identical_planar_aligned : identical_diff_offset_t);
+            BOOL norm_offset_v_tentative = !(align_planar ? identical_planar_aligned : identical_norm_offset_t);
+            BOOL spec_offset_v_tentative = !(align_planar ? identical_planar_aligned : identical_spec_offset_t);
 
-			getChild<LLUICtrl>("TexOffsetV")->setValue(  editable ? diff_offset_t : 0.0f);
-			getChild<LLUICtrl>("bumpyOffsetV")->setValue(editable ? norm_offset_t : 0.0f);
-			getChild<LLUICtrl>("shinyOffsetV")->setValue(editable ? spec_offset_t : 0.0f);
+            getChild<LLUICtrl>("TexOffsetV")->setValue(  editable ? diff_offset_t : 0.0f);
+            getChild<LLUICtrl>("bumpyOffsetV")->setValue(editable ? norm_offset_t : 0.0f);
+            getChild<LLUICtrl>("shinyOffsetV")->setValue(editable ? spec_offset_t : 0.0f);
 
-			getChild<LLUICtrl>("TexOffsetV")->setTentative(LLSD(diff_offset_v_tentative));
-			getChild<LLUICtrl>("shinyOffsetV")->setTentative(LLSD(norm_offset_v_tentative));
-			getChild<LLUICtrl>("bumpyOffsetV")->setTentative(LLSD(spec_offset_v_tentative));
+            getChild<LLUICtrl>("TexOffsetV")->setTentative(LLSD(diff_offset_v_tentative));
+            getChild<LLUICtrl>("shinyOffsetV")->setTentative(LLSD(norm_offset_v_tentative));
+            getChild<LLUICtrl>("bumpyOffsetV")->setTentative(LLSD(spec_offset_v_tentative));
 
             getChildView("TexOffsetV")->setEnabled(editable && has_material);
             getChildView("shinyOffsetV")->setEnabled(editable && has_material && specmap_id.notNull());
             getChildView("bumpyOffsetV")->setEnabled(editable && has_material && normmap_id.notNull());
-		}
+        }
 
-		// Texture rotation
-		{
-			bool identical_diff_rotation = false;
-			bool identical_norm_rotation = false;
-			bool identical_spec_rotation = false;
+        // Texture rotation
+        {
+            bool identical_diff_rotation = false;
+            bool identical_norm_rotation = false;
+            bool identical_spec_rotation = false;
 
-			F32 diff_rotation = 0.f;
-			F32 norm_rotation = 0.f;
-			F32 spec_rotation = 0.f;
+            F32 diff_rotation = 0.f;
+            F32 norm_rotation = 0.f;
+            F32 spec_rotation = 0.f;
 
-			LLSelectedTE::getRotation(diff_rotation,identical_diff_rotation);
-			LLSelectedTEMaterial::getSpecularRotation(spec_rotation,identical_spec_rotation);
-			LLSelectedTEMaterial::getNormalRotation(norm_rotation,identical_norm_rotation);
+            LLSelectedTE::getRotation(diff_rotation,identical_diff_rotation);
+            LLSelectedTEMaterial::getSpecularRotation(spec_rotation,identical_spec_rotation);
+            LLSelectedTEMaterial::getNormalRotation(norm_rotation,identical_norm_rotation);
 
-			BOOL diff_rot_tentative = !(align_planar ? identical_planar_aligned : identical_diff_rotation);
-			BOOL norm_rot_tentative = !(align_planar ? identical_planar_aligned : identical_norm_rotation);
-			BOOL spec_rot_tentative = !(align_planar ? identical_planar_aligned : identical_spec_rotation);
+            BOOL diff_rot_tentative = !(align_planar ? identical_planar_aligned : identical_diff_rotation);
+            BOOL norm_rot_tentative = !(align_planar ? identical_planar_aligned : identical_norm_rotation);
+            BOOL spec_rot_tentative = !(align_planar ? identical_planar_aligned : identical_spec_rotation);
 
-			F32 diff_rot_deg = diff_rotation * RAD_TO_DEG;
-			F32 norm_rot_deg = norm_rotation * RAD_TO_DEG;
-			F32 spec_rot_deg = spec_rotation * RAD_TO_DEG;
+            F32 diff_rot_deg = diff_rotation * RAD_TO_DEG;
+            F32 norm_rot_deg = norm_rotation * RAD_TO_DEG;
+            F32 spec_rot_deg = spec_rotation * RAD_TO_DEG;
 
             getChildView("TexRot")->setEnabled(editable && has_material);
             getChildView("shinyRot")->setEnabled(editable && has_material && specmap_id.notNull());
             getChildView("bumpyRot")->setEnabled(editable && has_material && normmap_id.notNull());
 
-			getChild<LLUICtrl>("TexRot")->setTentative(diff_rot_tentative);
-			getChild<LLUICtrl>("shinyRot")->setTentative(LLSD(norm_rot_tentative));
-			getChild<LLUICtrl>("bumpyRot")->setTentative(LLSD(spec_rot_tentative));
+            getChild<LLUICtrl>("TexRot")->setTentative(diff_rot_tentative);
+            getChild<LLUICtrl>("shinyRot")->setTentative(LLSD(norm_rot_tentative));
+            getChild<LLUICtrl>("bumpyRot")->setTentative(LLSD(spec_rot_tentative));
 
-			getChild<LLUICtrl>("TexRot")->setValue(  editable ? diff_rot_deg : 0.0f);			
-			getChild<LLUICtrl>("shinyRot")->setValue(editable ? spec_rot_deg : 0.0f);
-			getChild<LLUICtrl>("bumpyRot")->setValue(editable ? norm_rot_deg : 0.0f);
-		}
+            getChild<LLUICtrl>("TexRot")->setValue(  editable ? diff_rot_deg : 0.0f);
+            getChild<LLUICtrl>("shinyRot")->setValue(editable ? spec_rot_deg : 0.0f);
+            getChild<LLUICtrl>("bumpyRot")->setValue(editable ? norm_rot_deg : 0.0f);
+        }
 
-		{
-			F32 glow = 0.f;
-			bool identical_glow = false;
-			LLSelectedTE::getGlow(glow,identical_glow);
+        {
+            F32 glow = 0.f;
+            bool identical_glow = false;
+            LLSelectedTE::getGlow(glow,identical_glow);
             mCtrlGlow->setValue(glow);
             mCtrlGlow->setTentative(!identical_glow);
             mCtrlGlow->setEnabled(editable);
-			getChildView("glow label")->setEnabled(editable);
-		}
+            getChildView("glow label")->setEnabled(editable);
+        }
 
-		{
+        {
             // Maps from enum to combobox entry index
             mComboTexGen->selectNthItem(((S32) selected_texgen) >> 1);
             mComboTexGen->setEnabled(editable);
@@ -1593,40 +1593,40 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
             getChildView("tex gen")->setEnabled(editable);
         }
 
-		{
-			U8 fullbright_flag = 0;
-			bool identical_fullbright = false;
-			
-			LLSelectedTE::getFullbright(fullbright_flag,identical_fullbright);
+        {
+            U8 fullbright_flag = 0;
+            bool identical_fullbright = false;
+
+            LLSelectedTE::getFullbright(fullbright_flag,identical_fullbright);
 
-			getChild<LLUICtrl>("checkbox fullbright")->setValue((S32)(fullbright_flag != 0));
-			getChildView("checkbox fullbright")->setEnabled(editable && !has_pbr_material);
-			getChild<LLUICtrl>("checkbox fullbright")->setTentative(!identical_fullbright);
+            getChild<LLUICtrl>("checkbox fullbright")->setValue((S32)(fullbright_flag != 0));
+            getChildView("checkbox fullbright")->setEnabled(editable && !has_pbr_material);
+            getChild<LLUICtrl>("checkbox fullbright")->setTentative(!identical_fullbright);
             mComboMatMedia->setEnabledByValue("Materials", !has_pbr_material);
-		}
-		
-		// Repeats per meter
-		{
-			F32 repeats_diff = 1.f;
-			F32 repeats_norm = 1.f;
-			F32 repeats_spec = 1.f;
-
-			bool identical_diff_repeats = false;
-			bool identical_norm_repeats = false;
-			bool identical_spec_repeats = false;
-
-			LLSelectedTE::getMaxDiffuseRepeats(repeats_diff, identical_diff_repeats);
-			LLSelectedTEMaterial::getMaxNormalRepeats(repeats_norm, identical_norm_repeats);
-			LLSelectedTEMaterial::getMaxSpecularRepeats(repeats_spec, identical_spec_repeats);			
-
-			LLComboBox*	mComboTexGen = getChild<LLComboBox>("combobox texgen");
-			if (mComboTexGen)
-			{
-				S32 index = mComboTexGen ? mComboTexGen->getCurrentIndex() : 0;
+        }
+
+        // Repeats per meter
+        {
+            F32 repeats_diff = 1.f;
+            F32 repeats_norm = 1.f;
+            F32 repeats_spec = 1.f;
+
+            bool identical_diff_repeats = false;
+            bool identical_norm_repeats = false;
+            bool identical_spec_repeats = false;
+
+            LLSelectedTE::getMaxDiffuseRepeats(repeats_diff, identical_diff_repeats);
+            LLSelectedTEMaterial::getMaxNormalRepeats(repeats_norm, identical_norm_repeats);
+            LLSelectedTEMaterial::getMaxSpecularRepeats(repeats_spec, identical_spec_repeats);
+
+            LLComboBox* mComboTexGen = getChild<LLComboBox>("combobox texgen");
+            if (mComboTexGen)
+            {
+                S32 index = mComboTexGen ? mComboTexGen->getCurrentIndex() : 0;
                 bool enabled = editable && (index != 1);
                 bool identical_repeats = true;
                 S32 material_selection = mComboMatMedia->getCurrentIndex();
-				F32  repeats = 1.0f;
+                F32  repeats = 1.0f;
 
                 U32 material_type = MATTYPE_DIFFUSE;
                 if (material_selection == MATMEDIA_MATERIAL)
@@ -1676,194 +1676,194 @@ void LLPanelFace::updateUI(bool force_set_values /*false*/)
                 break;
                 }
 
-				BOOL repeats_tentative = !identical_repeats;
-
-				LLSpinCtrl* rpt_ctrl = getChild<LLSpinCtrl>("rptctrl");
-				if (force_set_values)
-				{
-					//onCommit, previosly edited element updates related ones
-					rpt_ctrl->forceSetValue(editable ? repeats : 1.0f);
-				}
-				else
-				{
-					rpt_ctrl->setValue(editable ? repeats : 1.0f);
-				}
-				rpt_ctrl->setTentative(LLSD(repeats_tentative));
+                BOOL repeats_tentative = !identical_repeats;
+
+                LLSpinCtrl* rpt_ctrl = getChild<LLSpinCtrl>("rptctrl");
+                if (force_set_values)
+                {
+                    //onCommit, previosly edited element updates related ones
+                    rpt_ctrl->forceSetValue(editable ? repeats : 1.0f);
+                }
+                else
+                {
+                    rpt_ctrl->setValue(editable ? repeats : 1.0f);
+                }
+                rpt_ctrl->setTentative(LLSD(repeats_tentative));
                 rpt_ctrl->setEnabled(has_material && !identical_planar_texgen && enabled);
-			}
-		}
+            }
+        }
 
-		// Materials
-		{
-			LLMaterialPtr material;
-			LLSelectedTEMaterial::getCurrent(material, identical);
+        // Materials
+        {
+            LLMaterialPtr material;
+            LLSelectedTEMaterial::getCurrent(material, identical);
 
             if (material && editable)
-			{
-				LL_DEBUGS("Materials") << material->asLLSD() << LL_ENDL;
+            {
+                LL_DEBUGS("Materials") << material->asLLSD() << LL_ENDL;
 
-				// Alpha
+                // Alpha
                 LLCtrlSelectionInterface* combobox_alphamode = mComboAlphaMode->getSelectionInterface();
-				if (combobox_alphamode)
-				{
-					U32 alpha_mode = material->getDiffuseAlphaMode();
-
-					if (transparency > 0.f)
-					{ //it is invalid to have any alpha mode other than blend if transparency is greater than zero ... 
-						alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_BLEND;
-					}
-
-					if (!mIsAlpha)
-					{ // ... unless there is no alpha channel in the texture, in which case alpha mode MUST ebe none
-						alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
-					}
-
-					combobox_alphamode->selectNthItem(alpha_mode);
-				}
-				else
-				{
-					LL_WARNS() << "failed childGetSelectionInterface for 'combobox alphamode'" << LL_ENDL;
-				}
-				mSpinMaskCutoff->setValue(material->getAlphaMaskCutoff());
-				updateAlphaControls();
-
-				identical_planar_texgen = isIdenticalPlanarTexgen();
-
-				// Shiny (specular)
-				F32 offset_x, offset_y, repeat_x, repeat_y, rot;
+                if (combobox_alphamode)
+                {
+                    U32 alpha_mode = material->getDiffuseAlphaMode();
+
+                    if (transparency > 0.f)
+                    { //it is invalid to have any alpha mode other than blend if transparency is greater than zero ...
+                        alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_BLEND;
+                    }
+
+                    if (!mIsAlpha)
+                    { // ... unless there is no alpha channel in the texture, in which case alpha mode MUST ebe none
+                        alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
+                    }
+
+                    combobox_alphamode->selectNthItem(alpha_mode);
+                }
+                else
+                {
+                    LL_WARNS() << "failed childGetSelectionInterface for 'combobox alphamode'" << LL_ENDL;
+                }
+                mSpinMaskCutoff->setValue(material->getAlphaMaskCutoff());
+                updateAlphaControls();
+
+                identical_planar_texgen = isIdenticalPlanarTexgen();
+
+                // Shiny (specular)
+                F32 offset_x, offset_y, repeat_x, repeat_y, rot;
                 mShinyTextureCtrl->setImageAssetID(material->getSpecularID());
 
-				if (!material->getSpecularID().isNull() && (shiny == SHINY_TEXTURE))
-				{
-					material->getSpecularOffset(offset_x,offset_y);
-					material->getSpecularRepeat(repeat_x,repeat_y);
-
-					if (identical_planar_texgen)
-					{
-						repeat_x *= 2.0f;
-						repeat_y *= 2.0f;
-					}
-
-					rot = material->getSpecularRotation();
-					getChild<LLUICtrl>("shinyScaleU")->setValue(repeat_x);
-					getChild<LLUICtrl>("shinyScaleV")->setValue(repeat_y);
-					getChild<LLUICtrl>("shinyRot")->setValue(rot*RAD_TO_DEG);
-					getChild<LLUICtrl>("shinyOffsetU")->setValue(offset_x);
-					getChild<LLUICtrl>("shinyOffsetV")->setValue(offset_y);
+                if (!material->getSpecularID().isNull() && (shiny == SHINY_TEXTURE))
+                {
+                    material->getSpecularOffset(offset_x,offset_y);
+                    material->getSpecularRepeat(repeat_x,repeat_y);
+
+                    if (identical_planar_texgen)
+                    {
+                        repeat_x *= 2.0f;
+                        repeat_y *= 2.0f;
+                    }
+
+                    rot = material->getSpecularRotation();
+                    getChild<LLUICtrl>("shinyScaleU")->setValue(repeat_x);
+                    getChild<LLUICtrl>("shinyScaleV")->setValue(repeat_y);
+                    getChild<LLUICtrl>("shinyRot")->setValue(rot*RAD_TO_DEG);
+                    getChild<LLUICtrl>("shinyOffsetU")->setValue(offset_x);
+                    getChild<LLUICtrl>("shinyOffsetV")->setValue(offset_y);
                     mSpinGlossiness->setValue(material->getSpecularLightExponent());
                     mSpinEnvironment->setValue(material->getEnvironmentIntensity());
                     getChild<LLUICtrl>("mirror")->setValue(material->getEnvironmentIntensity());
 
-					updateShinyControls(!material->getSpecularID().isNull(), true);
-				}
+                    updateShinyControls(!material->getSpecularID().isNull(), true);
+                }
 
-				// Assert desired colorswatch color to match material AFTER updateShinyControls
-				// to avoid getting overwritten with the default on some UI state changes.
-				//
-				if (!material->getSpecularID().isNull())
-				{
-					LLColor4 new_color = material->getSpecularLightColor();
-					LLColor4 old_color = mShinyColorSwatch->get();
+                // Assert desired colorswatch color to match material AFTER updateShinyControls
+                // to avoid getting overwritten with the default on some UI state changes.
+                //
+                if (!material->getSpecularID().isNull())
+                {
+                    LLColor4 new_color = material->getSpecularLightColor();
+                    LLColor4 old_color = mShinyColorSwatch->get();
 
-					mShinyColorSwatch->setOriginal(new_color);
+                    mShinyColorSwatch->setOriginal(new_color);
                     mShinyColorSwatch->set(new_color, force_set_values || old_color != new_color || !editable);
-				}
+                }
 
-				// Bumpy (normal)
+                // Bumpy (normal)
                 mBumpyTextureCtrl->setImageAssetID(material->getNormalID());
 
-				if (!material->getNormalID().isNull())
-				{
-					material->getNormalOffset(offset_x,offset_y);
-					material->getNormalRepeat(repeat_x,repeat_y);
-
-					if (identical_planar_texgen)
-					{
-						repeat_x *= 2.0f;
-						repeat_y *= 2.0f;
-					}
-			
-					rot = material->getNormalRotation();
-					getChild<LLUICtrl>("bumpyScaleU")->setValue(repeat_x);
-					getChild<LLUICtrl>("bumpyScaleV")->setValue(repeat_y);
-					getChild<LLUICtrl>("bumpyRot")->setValue(rot*RAD_TO_DEG);
-					getChild<LLUICtrl>("bumpyOffsetU")->setValue(offset_x);
-					getChild<LLUICtrl>("bumpyOffsetV")->setValue(offset_y);
-
-					updateBumpyControls(!material->getNormalID().isNull(), true);
-				}
-			}
-		}
+                if (!material->getNormalID().isNull())
+                {
+                    material->getNormalOffset(offset_x,offset_y);
+                    material->getNormalRepeat(repeat_x,repeat_y);
+
+                    if (identical_planar_texgen)
+                    {
+                        repeat_x *= 2.0f;
+                        repeat_y *= 2.0f;
+                    }
+
+                    rot = material->getNormalRotation();
+                    getChild<LLUICtrl>("bumpyScaleU")->setValue(repeat_x);
+                    getChild<LLUICtrl>("bumpyScaleV")->setValue(repeat_y);
+                    getChild<LLUICtrl>("bumpyRot")->setValue(rot*RAD_TO_DEG);
+                    getChild<LLUICtrl>("bumpyOffsetU")->setValue(offset_x);
+                    getChild<LLUICtrl>("bumpyOffsetV")->setValue(offset_y);
+
+                    updateBumpyControls(!material->getNormalID().isNull(), true);
+                }
+            }
+        }
         S32 selected_count = LLSelectMgr::getInstance()->getSelection()->getObjectCount();
         BOOL single_volume = (selected_count == 1);
 
         mBtnCopyColor->setEnabled(editable&& single_volume);
         mBtnPasteColor->setEnabled(editable&& single_volume&& mClipboardParams.has("color"));
 
-		// Set variable values for numeric expressions
-		LLCalc* calcp = LLCalc::getInstance();
-		calcp->setVar(LLCalc::TEX_U_SCALE, childGetValue("TexScaleU").asReal());
-		calcp->setVar(LLCalc::TEX_V_SCALE, childGetValue("TexScaleV").asReal());
-		calcp->setVar(LLCalc::TEX_U_OFFSET, childGetValue("TexOffsetU").asReal());
-		calcp->setVar(LLCalc::TEX_V_OFFSET, childGetValue("TexOffsetV").asReal());
-		calcp->setVar(LLCalc::TEX_ROTATION, childGetValue("TexRot").asReal());
+        // Set variable values for numeric expressions
+        LLCalc* calcp = LLCalc::getInstance();
+        calcp->setVar(LLCalc::TEX_U_SCALE, childGetValue("TexScaleU").asReal());
+        calcp->setVar(LLCalc::TEX_V_SCALE, childGetValue("TexScaleV").asReal());
+        calcp->setVar(LLCalc::TEX_U_OFFSET, childGetValue("TexOffsetU").asReal());
+        calcp->setVar(LLCalc::TEX_V_OFFSET, childGetValue("TexOffsetV").asReal());
+        calcp->setVar(LLCalc::TEX_ROTATION, childGetValue("TexRot").asReal());
         calcp->setVar(LLCalc::TEX_TRANSPARENCY, mCtrlColorTransp->getValue().asReal());
         calcp->setVar(LLCalc::TEX_GLOW, mCtrlGlow->getValue().asReal());
 
-		getChild<LLUICtrl>("btn_select_same_diff")->setEnabled(LLSelectMgr::getInstance()->getTEMode() && mTextureCtrl->getEnabled() && identical_diffuse);
-		getChild<LLUICtrl>("btn_select_same_norm")->setEnabled(LLSelectMgr::getInstance()->getTEMode() && mBumpyTextureCtrl->getEnabled() && identical_norm);
-		getChild<LLUICtrl>("btn_select_same_spec")->setEnabled(LLSelectMgr::getInstance()->getTEMode() && mShinyTextureCtrl->getEnabled() && identical_spec);
-	}
-	else
-	{
-		// Disable all UICtrls
-		clearCtrls();
-
-		// Disable non-UICtrls
-        LLTextureCtrl*	pbr_ctrl = findChild<LLTextureCtrl>("pbr_control");
+        getChild<LLUICtrl>("btn_select_same_diff")->setEnabled(LLSelectMgr::getInstance()->getTEMode() && mTextureCtrl->getEnabled() && identical_diffuse);
+        getChild<LLUICtrl>("btn_select_same_norm")->setEnabled(LLSelectMgr::getInstance()->getTEMode() && mBumpyTextureCtrl->getEnabled() && identical_norm);
+        getChild<LLUICtrl>("btn_select_same_spec")->setEnabled(LLSelectMgr::getInstance()->getTEMode() && mShinyTextureCtrl->getEnabled() && identical_spec);
+    }
+    else
+    {
+        // Disable all UICtrls
+        clearCtrls();
+
+        // Disable non-UICtrls
+        LLTextureCtrl*  pbr_ctrl = findChild<LLTextureCtrl>("pbr_control");
         if (pbr_ctrl)
         {
             pbr_ctrl->setImageAssetID(LLUUID::null);
             pbr_ctrl->setEnabled(FALSE);
         }
-		LLTextureCtrl*	texture_ctrl = getChild<LLTextureCtrl>("texture control"); 
-		if (texture_ctrl)
-		{
-			texture_ctrl->setImageAssetID( LLUUID::null );
-			texture_ctrl->setEnabled( FALSE );  // this is a LLUICtrl, but we don't want it to have keyboard focus so we add it as a child, not a ctrl.
-// 			texture_ctrl->setValid(FALSE);
-		}
-		LLColorSwatchCtrl* mColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
-		if (mColorSwatch)
-		{
-			mColorSwatch->setEnabled( FALSE );			
-			mColorSwatch->setFallbackImage(LLUI::getUIImage("locked_image.j2c") );
-			mColorSwatch->setValid(FALSE);
-		}
+        LLTextureCtrl*  texture_ctrl = getChild<LLTextureCtrl>("texture control");
+        if (texture_ctrl)
+        {
+            texture_ctrl->setImageAssetID( LLUUID::null );
+            texture_ctrl->setEnabled( FALSE );  // this is a LLUICtrl, but we don't want it to have keyboard focus so we add it as a child, not a ctrl.
+//          texture_ctrl->setValid(FALSE);
+        }
+        LLColorSwatchCtrl* mColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
+        if (mColorSwatch)
+        {
+            mColorSwatch->setEnabled( FALSE );
+            mColorSwatch->setFallbackImage(LLUI::getUIImage("locked_image.j2c") );
+            mColorSwatch->setValid(FALSE);
+        }
 
         mRadioMatType->setSelectedIndex(0);
-		getChildView("color trans")->setEnabled(FALSE);
-		getChildView("rptctrl")->setEnabled(FALSE);
-		getChildView("tex gen")->setEnabled(FALSE);
-		getChildView("label shininess")->setEnabled(FALSE);
-		getChildView("label bumpiness")->setEnabled(FALSE);
-		getChildView("button align")->setEnabled(FALSE);
+        getChildView("color trans")->setEnabled(FALSE);
+        getChildView("rptctrl")->setEnabled(FALSE);
+        getChildView("tex gen")->setEnabled(FALSE);
+        getChildView("label shininess")->setEnabled(FALSE);
+        getChildView("label bumpiness")->setEnabled(FALSE);
+        getChildView("button align")->setEnabled(FALSE);
         getChildView("pbr_from_inventory")->setEnabled(FALSE);
         getChildView("edit_selected_pbr")->setEnabled(FALSE);
         getChildView("save_selected_pbr")->setEnabled(FALSE);
-		
-		updateVisibility();
 
-		// Set variable values for numeric expressions
-		LLCalc* calcp = LLCalc::getInstance();
-		calcp->clearVar(LLCalc::TEX_U_SCALE);
-		calcp->clearVar(LLCalc::TEX_V_SCALE);
-		calcp->clearVar(LLCalc::TEX_U_OFFSET);
-		calcp->clearVar(LLCalc::TEX_V_OFFSET);
-		calcp->clearVar(LLCalc::TEX_ROTATION);
-		calcp->clearVar(LLCalc::TEX_TRANSPARENCY);
-		calcp->clearVar(LLCalc::TEX_GLOW);		
-	}
+        updateVisibility();
+
+        // Set variable values for numeric expressions
+        LLCalc* calcp = LLCalc::getInstance();
+        calcp->clearVar(LLCalc::TEX_U_SCALE);
+        calcp->clearVar(LLCalc::TEX_V_SCALE);
+        calcp->clearVar(LLCalc::TEX_U_OFFSET);
+        calcp->clearVar(LLCalc::TEX_V_OFFSET);
+        calcp->clearVar(LLCalc::TEX_ROTATION);
+        calcp->clearVar(LLCalc::TEX_TRANSPARENCY);
+        calcp->clearVar(LLCalc::TEX_GLOW);
+    }
 }
 
 // One-off listener that updates the build floater UI when the agent inventory adds or removes an item
@@ -1872,7 +1872,7 @@ class PBRPickerAgentListener : public LLInventoryObserver
 protected:
     bool mChangePending = true;
 public:
-	PBRPickerAgentListener() : LLInventoryObserver()
+    PBRPickerAgentListener() : LLInventoryObserver()
     {
         gInventory.addObserver(this);
     }
@@ -1882,7 +1882,7 @@ class PBRPickerAgentListener : public LLInventoryObserver
         return mChangePending;
     }
 
-	void changed(U32 mask) override
+    void changed(U32 mask) override
     {
         if (!(mask & (ADD | REMOVE)))
         {
@@ -2056,7 +2056,7 @@ void LLPanelFace::updateCopyTexButton()
 {
     LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
     bool enable = (objectp && objectp->getPCode() == LL_PCODE_VOLUME && objectp->permModify()
-                                                    && !objectp->isPermanentEnforced() && !objectp->isInventoryPending() 
+                                                    && !objectp->isPermanentEnforced() && !objectp->isInventoryPending()
                                                     && (LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 1)
                                                     && LLMaterialEditor::canClipboardObjectsMaterial());
     mBtnCopyTextures->setEnabled(enable);
@@ -2067,8 +2067,8 @@ void LLPanelFace::updateCopyTexButton()
 
 void LLPanelFace::refresh()
 {
-	LL_DEBUGS("Materials") << LL_ENDL;
-	getState();
+    LL_DEBUGS("Materials") << LL_ENDL;
+    getState();
 }
 
 void LLPanelFace::refreshMedia()
@@ -2189,7 +2189,7 @@ void LLPanelFace::refreshMedia()
                 // initial media title is the media URL (until we get the name)
                 media_title = media_data_get.getHomeURL();
             }
-            // else all faces might be empty. 
+            // else all faces might be empty.
         }
         else // there' re Different Medias' been set on on the faces.
         {
@@ -2261,19 +2261,19 @@ void LLPanelFace::onMaterialOverrideReceived(const LLUUID& object_id, S32 side)
 //
 void LLPanelFace::navigateToTitleMedia( const std::string url )
 {
-	std::string multi_media_info_str = LLTrans::getString("Multiple Media");
-	if (url.empty() || multi_media_info_str == url)
-	{
-		// nothing to show
-		mNeedMediaTitle = false;
-	}
-	else if (mTitleMedia)
-	{
-		LLPluginClassMedia* media_plugin = mTitleMedia->getMediaPlugin();
-		// check if url changed or if we need a new media source
-		if (mTitleMedia->getCurrentNavUrl() != url || media_plugin == NULL)
-		{
-			mTitleMedia->navigateTo( url );
+    std::string multi_media_info_str = LLTrans::getString("Multiple Media");
+    if (url.empty() || multi_media_info_str == url)
+    {
+        // nothing to show
+        mNeedMediaTitle = false;
+    }
+    else if (mTitleMedia)
+    {
+        LLPluginClassMedia* media_plugin = mTitleMedia->getMediaPlugin();
+        // check if url changed or if we need a new media source
+        if (mTitleMedia->getCurrentNavUrl() != url || media_plugin == NULL)
+        {
+            mTitleMedia->navigateTo( url );
 
             LLViewerMediaImpl* impl = LLViewerMedia::getInstance()->getMediaImplFromTextureID(mTitleMedia->getTextureID());
             if (impl)
@@ -2281,11 +2281,11 @@ void LLPanelFace::navigateToTitleMedia( const std::string url )
                 // if it's a page with a movie, we don't want to hear it
                 impl->setVolume(0);
             };
-		}
+        }
 
-		// flag that we need to update the title (even if no request were made)
-		mNeedMediaTitle = true;
-	}
+        // flag that we need to update the title (even if no request were made)
+        mNeedMediaTitle = true;
+    }
 }
 
 bool LLPanelFace::selectedMediaEditable()
@@ -2344,7 +2344,7 @@ void LLPanelFace::updateMediaSettings()
 
     const LLMediaEntry default_media_data;
 
-    // controls 
+    // controls
     U8 value_u8 = default_media_data.getControls();
     struct functor_getter_controls : public LLSelectedTEGetFunctor< U8 >
     {
@@ -2833,58 +2833,58 @@ void LLPanelFace::updateMediaTitle()
 // static
 F32 LLPanelFace::valueGlow(LLViewerObject* object, S32 face)
 {
-	return (F32)(object->getTE(face)->getGlow());
+    return (F32)(object->getTE(face)->getGlow());
 }
 
 
 void LLPanelFace::onCommitColor(const LLSD& data)
 {
-	sendColor();
+    sendColor();
 }
 
 void LLPanelFace::onCommitShinyColor(const LLSD& data)
 {
-	LLSelectedTEMaterial::setSpecularLightColor(this, mShinyColorSwatch->get());
+    LLSelectedTEMaterial::setSpecularLightColor(this, mShinyColorSwatch->get());
 }
 
 void LLPanelFace::onCommitAlpha(const LLSD& data)
 {
-	sendAlpha();
+    sendAlpha();
 }
 
 void LLPanelFace::onCancelColor(const LLSD& data)
 {
-	LLSelectMgr::getInstance()->selectionRevertColors();
+    LLSelectMgr::getInstance()->selectionRevertColors();
 }
 
 void LLPanelFace::onCancelShinyColor(const LLSD& data)
 {
-	LLSelectMgr::getInstance()->selectionRevertShinyColors();
+    LLSelectMgr::getInstance()->selectionRevertShinyColors();
 }
 
 void LLPanelFace::onSelectColor(const LLSD& data)
 {
-	LLSelectMgr::getInstance()->saveSelectedObjectColors();
-	sendColor();
+    LLSelectMgr::getInstance()->saveSelectedObjectColors();
+    sendColor();
 }
 
 void LLPanelFace::onSelectShinyColor(const LLSD& data)
 {
     LLSelectedTEMaterial::setSpecularLightColor(this, mShinyColorSwatch->get());
-	LLSelectMgr::getInstance()->saveSelectedShinyColors();
+    LLSelectMgr::getInstance()->saveSelectedShinyColors();
 }
 
 // static
 void LLPanelFace::onCommitMaterialsMedia(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	// Force to default states to side-step problems with menu contents
-	// and generally reflecting old state when switching tabs or objects
-	//
-	self->updateShinyControls(false,true);
-	self->updateBumpyControls(false,true);
-	self->updateUI();
-	self->refreshMedia();
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    // Force to default states to side-step problems with menu contents
+    // and generally reflecting old state when switching tabs or objects
+    //
+    self->updateShinyControls(false,true);
+    self->updateBumpyControls(false,true);
+    self->updateUI();
+    self->refreshMedia();
 }
 
 void LLPanelFace::updateVisibility(LLViewerObject* objectp /* = nullptr */)
@@ -2893,18 +2893,18 @@ void LLPanelFace::updateVisibility(LLViewerObject* objectp /* = nullptr */)
     LLRadioGroup* radio_pbr_type = findChild<LLRadioGroup>("radio_pbr_type");
     LLComboBox* combo_shininess = findChild<LLComboBox>("combobox shininess");
     LLComboBox* combo_bumpiness = findChild<LLComboBox>("combobox bumpiness");
-	if (!radio_mat_type || !radio_pbr_type || !mComboMatMedia || !combo_shininess || !combo_bumpiness)
-	{
-		LL_WARNS("Materials") << "Combo box not found...exiting." << LL_ENDL;
-		return;
-	}
-	U32 materials_media = mComboMatMedia->getCurrentIndex();
-	U32 material_type = radio_mat_type->getSelectedIndex();
-	bool show_media = (materials_media == MATMEDIA_MEDIA) && mComboMatMedia->getEnabled();
+    if (!radio_mat_type || !radio_pbr_type || !mComboMatMedia || !combo_shininess || !combo_bumpiness)
+    {
+        LL_WARNS("Materials") << "Combo box not found...exiting." << LL_ENDL;
+        return;
+    }
+    U32 materials_media = mComboMatMedia->getCurrentIndex();
+    U32 material_type = radio_mat_type->getSelectedIndex();
+    bool show_media = (materials_media == MATMEDIA_MEDIA) && mComboMatMedia->getEnabled();
     bool show_material = materials_media == MATMEDIA_MATERIAL;
-	bool show_texture = (show_media || (show_material && (material_type == MATTYPE_DIFFUSE) && mComboMatMedia->getEnabled()));
-	bool show_bumpiness = show_material && (material_type == MATTYPE_NORMAL) && mComboMatMedia->getEnabled();
-	bool show_shininess = show_material && (material_type == MATTYPE_SPECULAR) && mComboMatMedia->getEnabled();
+    bool show_texture = (show_media || (show_material && (material_type == MATTYPE_DIFFUSE) && mComboMatMedia->getEnabled()));
+    bool show_bumpiness = show_material && (material_type == MATTYPE_NORMAL) && mComboMatMedia->getEnabled();
+    bool show_shininess = show_material && (material_type == MATTYPE_SPECULAR) && mComboMatMedia->getEnabled();
     const bool show_pbr = mComboMatMedia->getCurrentIndex() == MATMEDIA_PBR && mComboMatMedia->getEnabled();
     const U32 pbr_type = findChild<LLRadioGroup>("radio_pbr_type")->getSelectedIndex();
     const LLGLTFMaterial::TextureInfo texture_info = texture_info_from_pbrtype(pbr_type);
@@ -2918,65 +2918,65 @@ void LLPanelFace::updateVisibility(LLViewerObject* objectp /* = nullptr */)
     getChildView("combobox texgen")->setVisible(show_material || show_media || show_pbr_asset);
     getChildView("button align textures")->setVisible(show_material || show_media);
 
-	// Media controls
+    // Media controls
     mTitleMediaText->setVisible(show_media);
-	getChildView("add_media")->setVisible(show_media);
-	getChildView("delete_media")->setVisible(show_media);
-	getChildView("button align")->setVisible(show_media);
-
-	// Diffuse texture controls
-	getChildView("texture control")->setVisible(show_texture && show_material);
-	getChildView("label alphamode")->setVisible(show_texture && show_material);
-	getChildView("combobox alphamode")->setVisible(show_texture && show_material);
-	getChildView("label maskcutoff")->setVisible(false);
-	getChildView("maskcutoff")->setVisible(false);
+    getChildView("add_media")->setVisible(show_media);
+    getChildView("delete_media")->setVisible(show_media);
+    getChildView("button align")->setVisible(show_media);
+
+    // Diffuse texture controls
+    getChildView("texture control")->setVisible(show_texture && show_material);
+    getChildView("label alphamode")->setVisible(show_texture && show_material);
+    getChildView("combobox alphamode")->setVisible(show_texture && show_material);
+    getChildView("label maskcutoff")->setVisible(false);
+    getChildView("maskcutoff")->setVisible(false);
     getChild<LLUICtrl>("btn_select_same_diff")->setVisible(show_texture && show_material);
     if (show_texture && show_material)
-	{
-		updateAlphaControls();
-	}
+    {
+        updateAlphaControls();
+    }
     // texture scale and position controls
-	getChildView("TexScaleU")->setVisible(show_texture);
-	getChildView("TexScaleV")->setVisible(show_texture);
-	getChildView("TexRot")->setVisible(show_texture);
-	getChildView("TexOffsetU")->setVisible(show_texture);
-	getChildView("TexOffsetV")->setVisible(show_texture);
+    getChildView("TexScaleU")->setVisible(show_texture);
+    getChildView("TexScaleV")->setVisible(show_texture);
+    getChildView("TexRot")->setVisible(show_texture);
+    getChildView("TexOffsetU")->setVisible(show_texture);
+    getChildView("TexOffsetV")->setVisible(show_texture);
 
-	// Specular map controls
+    // Specular map controls
     mShinyTextureCtrl->setVisible(show_shininess);
     mComboShininess->setVisible(show_shininess);
-	getChildView("label shininess")->setVisible(show_shininess);
-	getChildView("label glossiness")->setVisible(false);
+    getChildView("label shininess")->setVisible(show_shininess);
+    getChildView("label glossiness")->setVisible(false);
     mSpinGlossiness->setVisible(false);
-	getChildView("label environment")->setVisible(false);
+    getChildView("label environment")->setVisible(false);
     mSpinEnvironment->setVisible(false);
-	getChildView("label shinycolor")->setVisible(false);
+    getChildView("label shinycolor")->setVisible(false);
     mShinyColorSwatch->setVisible(false);
-	if (show_shininess)
-	{
-		updateShinyControls();
-	}
-	getChildView("shinyScaleU")->setVisible(show_shininess);
-	getChildView("shinyScaleV")->setVisible(show_shininess);
-	getChildView("shinyRot")->setVisible(show_shininess);
-	getChildView("shinyOffsetU")->setVisible(show_shininess);
-	getChildView("shinyOffsetV")->setVisible(show_shininess);
-	getChild<LLUICtrl>("btn_select_same_spec")->setVisible(show_shininess);
-
-	// Normal map controls
-	if (show_bumpiness)
-	{
-		updateBumpyControls();
-	}
+    if (show_shininess)
+    {
+        updateShinyControls();
+    }
+    getChildView("shinyScaleU")->setVisible(show_shininess);
+    getChildView("shinyScaleV")->setVisible(show_shininess);
+    getChildView("shinyRot")->setVisible(show_shininess);
+    getChildView("shinyOffsetU")->setVisible(show_shininess);
+    getChildView("shinyOffsetV")->setVisible(show_shininess);
+    getChild<LLUICtrl>("btn_select_same_spec")->setVisible(show_shininess);
+
+    // Normal map controls
+    if (show_bumpiness)
+    {
+        updateBumpyControls();
+    }
     mBumpyTextureCtrl->setVisible(show_bumpiness);
     mComboBumpiness->setVisible(show_bumpiness);
-	getChildView("label bumpiness")->setVisible(show_bumpiness);
-	getChildView("bumpyScaleU")->setVisible(show_bumpiness);
-	getChildView("bumpyScaleV")->setVisible(show_bumpiness);
-	getChildView("bumpyRot")->setVisible(show_bumpiness);
-	getChildView("bumpyOffsetU")->setVisible(show_bumpiness);
-	getChildView("bumpyOffsetV")->setVisible(show_bumpiness);
-	getChild<LLUICtrl>("btn_select_same_norm")->setVisible(show_bumpiness);
+    getChildView("label bumpiness")->setVisible(show_bumpiness);
+    getChildView("bumpyScaleU")->setVisible(show_bumpiness);
+    getChildView("bumpyScaleV")->setVisible(show_bumpiness);
+    getChildView("bumpyRot")->setVisible(show_bumpiness);
+    getChildView("bumpyOffsetU")->setVisible(show_bumpiness);
+    getChildView("bumpyOffsetV")->setVisible(show_bumpiness);
+    getChild<LLUICtrl>("btn_select_same_norm")->setVisible(show_bumpiness);
 
     getChild<LLSpinCtrl>("rptctrl")->setVisible(show_material || show_media);
 
@@ -2988,11 +2988,11 @@ void LLPanelFace::updateVisibility(LLViewerObject* objectp /* = nullptr */)
 void LLPanelFace::onCommitMaterialType(LLUICtrl* ctrl, void* userdata)
 {
     LLPanelFace* self = (LLPanelFace*) userdata;
-	 // Force to default states to side-step problems with menu contents
-	 // and generally reflecting old state when switching tabs or objects
-	 //
-	 self->updateShinyControls(false,true);
-	 self->updateBumpyControls(false,true);
+     // Force to default states to side-step problems with menu contents
+     // and generally reflecting old state when switching tabs or objects
+     //
+     self->updateShinyControls(false,true);
+     self->updateBumpyControls(false,true);
     self->updateUI();
 }
 
@@ -3009,145 +3009,145 @@ void LLPanelFace::onCommitPbrType(LLUICtrl* ctrl, void* userdata)
 // static
 void LLPanelFace::onCommitBump(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
+    LLPanelFace* self = (LLPanelFace*) userdata;
 
-	U32 bumpiness = self->mComboBumpiness->getCurrentIndex();
+    U32 bumpiness = self->mComboBumpiness->getCurrentIndex();
 
-	self->sendBump(bumpiness);
+    self->sendBump(bumpiness);
 }
 
 // static
 void LLPanelFace::onCommitTexGen(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	self->sendTexGen();
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    self->sendTexGen();
 }
 
 // static
 void LLPanelFace::updateShinyControls(bool is_setting_texture, bool mess_with_shiny_combobox)
 {
-	LLUUID shiny_texture_ID = mShinyTextureCtrl->getImageAssetID();
-	LL_DEBUGS("Materials") << "Shiny texture selected: " << shiny_texture_ID << LL_ENDL;
-	if(mess_with_shiny_combobox)
-	{
-		if (!shiny_texture_ID.isNull() && is_setting_texture)
-		{
+    LLUUID shiny_texture_ID = mShinyTextureCtrl->getImageAssetID();
+    LL_DEBUGS("Materials") << "Shiny texture selected: " << shiny_texture_ID << LL_ENDL;
+    if(mess_with_shiny_combobox)
+    {
+        if (!shiny_texture_ID.isNull() && is_setting_texture)
+        {
             if (!mComboShininess->itemExists(USE_TEXTURE))
-			{
+            {
                 mComboShininess->add(USE_TEXTURE);
-			}
+            }
             mComboShininess->setSimple(USE_TEXTURE);
-		}
-		else
-		{
+        }
+        else
+        {
             if (mComboShininess->itemExists(USE_TEXTURE))
-			{
+            {
                 mComboShininess->remove(SHINY_TEXTURE);
                 mComboShininess->selectFirstItem();
-			}
-		}
-	}
-	else
-	{
+            }
+        }
+    }
+    else
+    {
         if (shiny_texture_ID.isNull() && mComboShininess->itemExists(USE_TEXTURE))
-		{
+        {
             mComboShininess->remove(SHINY_TEXTURE);
             mComboShininess->selectFirstItem();
-		}
-	}
-
-
-	LLRadioGroup* radio_mat_type = getChild<LLRadioGroup>("radio_material_type");
-	U32 materials_media = mComboMatMedia->getCurrentIndex();
-	U32 material_type = radio_mat_type->getSelectedIndex();
-	bool show_material = (materials_media == MATMEDIA_MATERIAL);
-	bool show_shininess = show_material && (material_type == MATTYPE_SPECULAR) && mComboMatMedia->getEnabled();
-	U32 shiny_value = mComboShininess->getCurrentIndex();
-	bool show_shinyctrls = (shiny_value == SHINY_TEXTURE) && show_shininess; // Use texture
-	getChildView("label glossiness")->setVisible(show_shinyctrls);
+        }
+    }
+
+
+    LLRadioGroup* radio_mat_type = getChild<LLRadioGroup>("radio_material_type");
+    U32 materials_media = mComboMatMedia->getCurrentIndex();
+    U32 material_type = radio_mat_type->getSelectedIndex();
+    bool show_material = (materials_media == MATMEDIA_MATERIAL);
+    bool show_shininess = show_material && (material_type == MATTYPE_SPECULAR) && mComboMatMedia->getEnabled();
+    U32 shiny_value = mComboShininess->getCurrentIndex();
+    bool show_shinyctrls = (shiny_value == SHINY_TEXTURE) && show_shininess; // Use texture
+    getChildView("label glossiness")->setVisible(show_shinyctrls);
     mSpinGlossiness->setVisible(show_shinyctrls);
-	getChildView("label environment")->setVisible(show_shinyctrls);
+    getChildView("label environment")->setVisible(show_shinyctrls);
     mSpinEnvironment->setVisible(show_shinyctrls);
-	getChildView("label shinycolor")->setVisible(show_shinyctrls);
+    getChildView("label shinycolor")->setVisible(show_shinyctrls);
     mShinyColorSwatch->setVisible(show_shinyctrls);
 }
 
 // static
 void LLPanelFace::updateBumpyControls(bool is_setting_texture, bool mess_with_combobox)
 {
-	const LLUUID& bumpy_texture_ID = mBumpyTextureCtrl->getImageAssetID();
-	LL_DEBUGS("Materials") << "texture: " << bumpy_texture_ID << (mess_with_combobox ? "" : " do not") << " update combobox" << LL_ENDL;
+    const LLUUID& bumpy_texture_ID = mBumpyTextureCtrl->getImageAssetID();
+    LL_DEBUGS("Materials") << "texture: " << bumpy_texture_ID << (mess_with_combobox ? "" : " do not") << " update combobox" << LL_ENDL;
 
-	if (mess_with_combobox)
-	{
-		const LLUUID& bumpy_texture_ID = mBumpyTextureCtrl->getImageAssetID();
-		LL_DEBUGS("Materials") << "texture: " << bumpy_texture_ID << (mess_with_combobox ? "" : " do not") << " update combobox" << LL_ENDL;
+    if (mess_with_combobox)
+    {
+        const LLUUID& bumpy_texture_ID = mBumpyTextureCtrl->getImageAssetID();
+        LL_DEBUGS("Materials") << "texture: " << bumpy_texture_ID << (mess_with_combobox ? "" : " do not") << " update combobox" << LL_ENDL;
 
-		if (!bumpy_texture_ID.isNull() && is_setting_texture)
-		{
+        if (!bumpy_texture_ID.isNull() && is_setting_texture)
+        {
             if (!mComboBumpiness->itemExists(USE_TEXTURE))
-			{
+            {
                 mComboBumpiness->add(USE_TEXTURE);
-			}
+            }
             mComboBumpiness->setSimple(USE_TEXTURE);
-		}
-		else
-		{
+        }
+        else
+        {
             if (mComboBumpiness->itemExists(USE_TEXTURE))
-			{
+            {
                 mComboBumpiness->remove(BUMPY_TEXTURE);
                 mComboBumpiness->selectFirstItem();
-			}
-		}
-	}
+            }
+        }
+    }
 }
 
 // static
 void LLPanelFace::onCommitShiny(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
+    LLPanelFace* self = (LLPanelFace*) userdata;
 
-	U32 shininess = self->mComboShininess->getCurrentIndex();
+    U32 shininess = self->mComboShininess->getCurrentIndex();
 
-	self->sendShiny(shininess);
+    self->sendShiny(shininess);
 }
 
 // static
 void LLPanelFace::updateAlphaControls()
 {
-	U32 alpha_value = mComboAlphaMode->getCurrentIndex();
-	bool show_alphactrls = (alpha_value == ALPHAMODE_MASK); // Alpha masking
-    
+    U32 alpha_value = mComboAlphaMode->getCurrentIndex();
+    bool show_alphactrls = (alpha_value == ALPHAMODE_MASK); // Alpha masking
+
     U32 mat_media = mComboMatMedia->getCurrentIndex();
     U32 mat_type = mRadioMatType->getSelectedIndex();
 
     show_alphactrls = show_alphactrls && (mat_media == MATMEDIA_MATERIAL);
     show_alphactrls = show_alphactrls && (mat_type == MATTYPE_DIFFUSE);
-    
-	getChildView("label maskcutoff")->setVisible(show_alphactrls);
+
+    getChildView("label maskcutoff")->setVisible(show_alphactrls);
     mSpinMaskCutoff->setVisible(show_alphactrls);
 }
 
 // static
 void LLPanelFace::onCommitAlphaMode(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	self->updateAlphaControls();
-	LLSelectedTEMaterial::setDiffuseAlphaMode(self,self->getCurrentDiffuseAlphaMode());
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    self->updateAlphaControls();
+    LLSelectedTEMaterial::setDiffuseAlphaMode(self,self->getCurrentDiffuseAlphaMode());
 }
 
 // static
 void LLPanelFace::onCommitFullbright(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	self->sendFullbright();
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    self->sendFullbright();
 }
 
 // static
 void LLPanelFace::onCommitGlow(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	self->sendGlow();
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    self->sendGlow();
 }
 
 // static
@@ -3236,101 +3236,101 @@ BOOL LLPanelFace::onDragTexture(LLUICtrl*, LLInventoryItem* item)
 
 void LLPanelFace::onCommitTexture( const LLSD& data )
 {
-	add(LLStatViewer::EDIT_TEXTURE, 1);
-	sendTexture();
+    add(LLStatViewer::EDIT_TEXTURE, 1);
+    sendTexture();
 }
 
 void LLPanelFace::onCancelTexture(const LLSD& data)
 {
-	LLSelectMgr::getInstance()->selectionRevertTextures();
+    LLSelectMgr::getInstance()->selectionRevertTextures();
 }
 
 void LLPanelFace::onSelectTexture(const LLSD& data)
 {
-	LLSelectMgr::getInstance()->saveSelectedObjectTextures();
-	sendTexture();
-
-	LLGLenum image_format;
-	bool identical_image_format = false;
-	LLSelectedTE::getImageFormat(image_format, identical_image_format);
-    
-	LLCtrlSelectionInterface* combobox_alphamode = mComboAlphaMode->getSelectionInterface();
-
-	U32 alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
-	if (combobox_alphamode)
-	{
-		switch (image_format)
-		{
-		case GL_RGBA:
-		case GL_ALPHA:
-			{
-				alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_BLEND;
-			}
-			break;
-
-		case GL_RGB: break;
-		default:
-			{
-				LL_WARNS() << "Unexpected tex format in LLPanelFace...resorting to no alpha" << LL_ENDL;
-			}
-			break;
-		}
-
-		combobox_alphamode->selectNthItem(alpha_mode);
-	}
-	LLSelectedTEMaterial::setDiffuseAlphaMode(this, getCurrentDiffuseAlphaMode());
+    LLSelectMgr::getInstance()->saveSelectedObjectTextures();
+    sendTexture();
+
+    LLGLenum image_format;
+    bool identical_image_format = false;
+    LLSelectedTE::getImageFormat(image_format, identical_image_format);
+
+    LLCtrlSelectionInterface* combobox_alphamode = mComboAlphaMode->getSelectionInterface();
+
+    U32 alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
+    if (combobox_alphamode)
+    {
+        switch (image_format)
+        {
+        case GL_RGBA:
+        case GL_ALPHA:
+            {
+                alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_BLEND;
+            }
+            break;
+
+        case GL_RGB: break;
+        default:
+            {
+                LL_WARNS() << "Unexpected tex format in LLPanelFace...resorting to no alpha" << LL_ENDL;
+            }
+            break;
+        }
+
+        combobox_alphamode->selectNthItem(alpha_mode);
+    }
+    LLSelectedTEMaterial::setDiffuseAlphaMode(this, getCurrentDiffuseAlphaMode());
 }
 
 void LLPanelFace::onCloseTexturePicker(const LLSD& data)
 {
-	LL_DEBUGS("Materials") << data << LL_ENDL;
-	updateUI();
+    LL_DEBUGS("Materials") << data << LL_ENDL;
+    updateUI();
 }
 
 void LLPanelFace::onCommitSpecularTexture( const LLSD& data )
 {
-	LL_DEBUGS("Materials") << data << LL_ENDL;
-	sendShiny(SHINY_TEXTURE);
+    LL_DEBUGS("Materials") << data << LL_ENDL;
+    sendShiny(SHINY_TEXTURE);
 }
 
 void LLPanelFace::onCommitNormalTexture( const LLSD& data )
 {
-	LL_DEBUGS("Materials") << data << LL_ENDL;
-	LLUUID nmap_id = getCurrentNormalMap();
-	sendBump(nmap_id.isNull() ? 0 : BUMPY_TEXTURE);
+    LL_DEBUGS("Materials") << data << LL_ENDL;
+    LLUUID nmap_id = getCurrentNormalMap();
+    sendBump(nmap_id.isNull() ? 0 : BUMPY_TEXTURE);
 }
 
 void LLPanelFace::onCancelSpecularTexture(const LLSD& data)
 {
-	U8 shiny = 0;
-	bool identical_shiny = false;
-	LLSelectedTE::getShiny(shiny, identical_shiny);
+    U8 shiny = 0;
+    bool identical_shiny = false;
+    LLSelectedTE::getShiny(shiny, identical_shiny);
     LLUUID spec_map_id = mShinyTextureCtrl->getImageAssetID();
-	shiny = spec_map_id.isNull() ? shiny : SHINY_TEXTURE;
-	sendShiny(shiny);
+    shiny = spec_map_id.isNull() ? shiny : SHINY_TEXTURE;
+    sendShiny(shiny);
 }
 
 void LLPanelFace::onCancelNormalTexture(const LLSD& data)
 {
-	U8 bumpy = 0;
-	bool identical_bumpy = false;
-	LLSelectedTE::getBumpmap(bumpy, identical_bumpy);
+    U8 bumpy = 0;
+    bool identical_bumpy = false;
+    LLSelectedTE::getBumpmap(bumpy, identical_bumpy);
     LLUUID spec_map_id = mBumpyTextureCtrl->getImageAssetID();
-	bumpy = spec_map_id.isNull() ? bumpy : BUMPY_TEXTURE;
-	sendBump(bumpy);
+    bumpy = spec_map_id.isNull() ? bumpy : BUMPY_TEXTURE;
+    sendBump(bumpy);
 }
 
 void LLPanelFace::onSelectSpecularTexture(const LLSD& data)
 {
-	LL_DEBUGS("Materials") << data << LL_ENDL;
-	sendShiny(SHINY_TEXTURE);
+    LL_DEBUGS("Materials") << data << LL_ENDL;
+    sendShiny(SHINY_TEXTURE);
 }
 
 void LLPanelFace::onSelectNormalTexture(const LLSD& data)
 {
-	LL_DEBUGS("Materials") << data << LL_ENDL;
-	LLUUID nmap_id = getCurrentNormalMap();
-	sendBump(nmap_id.isNull() ? 0 : BUMPY_TEXTURE);
+    LL_DEBUGS("Materials") << data << LL_ENDL;
+    LLUUID nmap_id = getCurrentNormalMap();
+    sendBump(nmap_id.isNull() ? 0 : BUMPY_TEXTURE);
 }
 
 //////////////////////////////////////////////////////////////////////////////
@@ -3407,212 +3407,212 @@ bool LLPanelFace::multipleFacesSelectedConfirm(const LLSD& notification, const L
 //static
 void LLPanelFace::syncOffsetX(LLPanelFace* self, F32 offsetU)
 {
-	LLSelectedTEMaterial::setNormalOffsetX(self,offsetU);
-	LLSelectedTEMaterial::setSpecularOffsetX(self,offsetU);
-	self->getChild<LLSpinCtrl>("TexOffsetU")->forceSetValue(offsetU);
-	self->sendTextureInfo();
+    LLSelectedTEMaterial::setNormalOffsetX(self,offsetU);
+    LLSelectedTEMaterial::setSpecularOffsetX(self,offsetU);
+    self->getChild<LLSpinCtrl>("TexOffsetU")->forceSetValue(offsetU);
+    self->sendTextureInfo();
 }
 
 //static
 void LLPanelFace::syncOffsetY(LLPanelFace* self, F32 offsetV)
 {
-	LLSelectedTEMaterial::setNormalOffsetY(self,offsetV);
-	LLSelectedTEMaterial::setSpecularOffsetY(self,offsetV);
-	self->getChild<LLSpinCtrl>("TexOffsetV")->forceSetValue(offsetV);
-	self->sendTextureInfo();
+    LLSelectedTEMaterial::setNormalOffsetY(self,offsetV);
+    LLSelectedTEMaterial::setSpecularOffsetY(self,offsetV);
+    self->getChild<LLSpinCtrl>("TexOffsetV")->forceSetValue(offsetV);
+    self->sendTextureInfo();
 }
 
 //static
 void LLPanelFace::onCommitMaterialBumpyOffsetX(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
 
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		syncOffsetX(self,self->getCurrentBumpyOffsetU());
-	}
-	else
-	{
-		LLSelectedTEMaterial::setNormalOffsetX(self,self->getCurrentBumpyOffsetU());
-	}
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        syncOffsetX(self,self->getCurrentBumpyOffsetU());
+    }
+    else
+    {
+        LLSelectedTEMaterial::setNormalOffsetX(self,self->getCurrentBumpyOffsetU());
+    }
 
 }
 
 //static
 void LLPanelFace::onCommitMaterialBumpyOffsetY(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
 
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		syncOffsetY(self,self->getCurrentBumpyOffsetV());
-	}
-	else
-	{
-		LLSelectedTEMaterial::setNormalOffsetY(self,self->getCurrentBumpyOffsetV());
-	}
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        syncOffsetY(self,self->getCurrentBumpyOffsetV());
+    }
+    else
+    {
+        LLSelectedTEMaterial::setNormalOffsetY(self,self->getCurrentBumpyOffsetV());
+    }
 }
 
 //static
 void LLPanelFace::onCommitMaterialShinyOffsetX(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
 
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		syncOffsetX(self, self->getCurrentShinyOffsetU());
-	}
-	else
-	{
-		LLSelectedTEMaterial::setSpecularOffsetX(self,self->getCurrentShinyOffsetU());
-	}
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        syncOffsetX(self, self->getCurrentShinyOffsetU());
+    }
+    else
+    {
+        LLSelectedTEMaterial::setSpecularOffsetX(self,self->getCurrentShinyOffsetU());
+    }
 }
 
 //static
 void LLPanelFace::onCommitMaterialShinyOffsetY(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
 
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		syncOffsetY(self,self->getCurrentShinyOffsetV());
-	}
-	else
-	{
-		LLSelectedTEMaterial::setSpecularOffsetY(self,self->getCurrentShinyOffsetV());
-	}
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        syncOffsetY(self,self->getCurrentShinyOffsetV());
+    }
+    else
+    {
+        LLSelectedTEMaterial::setSpecularOffsetY(self,self->getCurrentShinyOffsetV());
+    }
 }
 
 //static
 void LLPanelFace::syncRepeatX(LLPanelFace* self, F32 scaleU)
 {
-	LLSelectedTEMaterial::setNormalRepeatX(self,scaleU);
-	LLSelectedTEMaterial::setSpecularRepeatX(self,scaleU);
-	self->sendTextureInfo();
+    LLSelectedTEMaterial::setNormalRepeatX(self,scaleU);
+    LLSelectedTEMaterial::setSpecularRepeatX(self,scaleU);
+    self->sendTextureInfo();
 }
 
 //static
 void LLPanelFace::syncRepeatY(LLPanelFace* self, F32 scaleV)
 {
-	LLSelectedTEMaterial::setNormalRepeatY(self,scaleV);
-	LLSelectedTEMaterial::setSpecularRepeatY(self,scaleV);
-	self->sendTextureInfo();
+    LLSelectedTEMaterial::setNormalRepeatY(self,scaleV);
+    LLSelectedTEMaterial::setSpecularRepeatY(self,scaleV);
+    self->sendTextureInfo();
 }
 
 //static
 void LLPanelFace::onCommitMaterialBumpyScaleX(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
-	F32 bumpy_scale_u = self->getCurrentBumpyScaleU();
-	if (self->isIdenticalPlanarTexgen())
-	{
-		bumpy_scale_u *= 0.5f;
-	}
-
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		self->getChild<LLSpinCtrl>("TexScaleU")->forceSetValue(self->getCurrentBumpyScaleU());
-		syncRepeatX(self, bumpy_scale_u);
-	}
-	else
-	{
-		LLSelectedTEMaterial::setNormalRepeatX(self,bumpy_scale_u);
-	}
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
+    F32 bumpy_scale_u = self->getCurrentBumpyScaleU();
+    if (self->isIdenticalPlanarTexgen())
+    {
+        bumpy_scale_u *= 0.5f;
+    }
+
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        self->getChild<LLSpinCtrl>("TexScaleU")->forceSetValue(self->getCurrentBumpyScaleU());
+        syncRepeatX(self, bumpy_scale_u);
+    }
+    else
+    {
+        LLSelectedTEMaterial::setNormalRepeatX(self,bumpy_scale_u);
+    }
 }
 
 //static
 void LLPanelFace::onCommitMaterialBumpyScaleY(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
-	F32 bumpy_scale_v = self->getCurrentBumpyScaleV();
-	if (self->isIdenticalPlanarTexgen())
-	{
-		bumpy_scale_v *= 0.5f;
-	}
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
+    F32 bumpy_scale_v = self->getCurrentBumpyScaleV();
+    if (self->isIdenticalPlanarTexgen())
+    {
+        bumpy_scale_v *= 0.5f;
+    }
 
 
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		self->getChild<LLSpinCtrl>("TexScaleV")->forceSetValue(self->getCurrentBumpyScaleV());
-		syncRepeatY(self, bumpy_scale_v);
-	}
-	else
-	{
-		LLSelectedTEMaterial::setNormalRepeatY(self,bumpy_scale_v);
-	}
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        self->getChild<LLSpinCtrl>("TexScaleV")->forceSetValue(self->getCurrentBumpyScaleV());
+        syncRepeatY(self, bumpy_scale_v);
+    }
+    else
+    {
+        LLSelectedTEMaterial::setNormalRepeatY(self,bumpy_scale_v);
+    }
 }
 
 //static
 void LLPanelFace::onCommitMaterialShinyScaleX(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
-	F32 shiny_scale_u = self->getCurrentShinyScaleU();
-	if (self->isIdenticalPlanarTexgen())
-	{
-		shiny_scale_u *= 0.5f;
-	}
-
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		self->getChild<LLSpinCtrl>("TexScaleU")->forceSetValue(self->getCurrentShinyScaleU());
-		syncRepeatX(self, shiny_scale_u);
-	}
-	else
-	{
-		LLSelectedTEMaterial::setSpecularRepeatX(self,shiny_scale_u);
-	}
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
+    F32 shiny_scale_u = self->getCurrentShinyScaleU();
+    if (self->isIdenticalPlanarTexgen())
+    {
+        shiny_scale_u *= 0.5f;
+    }
+
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        self->getChild<LLSpinCtrl>("TexScaleU")->forceSetValue(self->getCurrentShinyScaleU());
+        syncRepeatX(self, shiny_scale_u);
+    }
+    else
+    {
+        LLSelectedTEMaterial::setSpecularRepeatX(self,shiny_scale_u);
+    }
 }
 
 //static
 void LLPanelFace::onCommitMaterialShinyScaleY(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
-	F32 shiny_scale_v = self->getCurrentShinyScaleV();
-	if (self->isIdenticalPlanarTexgen())
-	{
-		shiny_scale_v *= 0.5f;
-	}
-
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		self->getChild<LLSpinCtrl>("TexScaleV")->forceSetValue(self->getCurrentShinyScaleV());
-		syncRepeatY(self, shiny_scale_v);
-	}
-	else
-	{
-		LLSelectedTEMaterial::setSpecularRepeatY(self,shiny_scale_v);
-	}
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
+    F32 shiny_scale_v = self->getCurrentShinyScaleV();
+    if (self->isIdenticalPlanarTexgen())
+    {
+        shiny_scale_v *= 0.5f;
+    }
+
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        self->getChild<LLSpinCtrl>("TexScaleV")->forceSetValue(self->getCurrentShinyScaleV());
+        syncRepeatY(self, shiny_scale_v);
+    }
+    else
+    {
+        LLSelectedTEMaterial::setSpecularRepeatY(self,shiny_scale_v);
+    }
 }
 
 //static
 void LLPanelFace::syncMaterialRot(LLPanelFace* self, F32 rot, int te)
 {
-	LLSelectedTEMaterial::setNormalRotation(self,rot * DEG_TO_RAD, te);
-	LLSelectedTEMaterial::setSpecularRotation(self,rot * DEG_TO_RAD, te);
-	self->sendTextureInfo();
+    LLSelectedTEMaterial::setNormalRotation(self,rot * DEG_TO_RAD, te);
+    LLSelectedTEMaterial::setSpecularRotation(self,rot * DEG_TO_RAD, te);
+    self->sendTextureInfo();
 }
 
 //static
 void LLPanelFace::onCommitMaterialBumpyRot(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
 
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		self->getChild<LLSpinCtrl>("TexRot")->forceSetValue(self->getCurrentBumpyRot());
-		syncMaterialRot(self, self->getCurrentBumpyRot());
-	}
-	else
-	{
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        self->getChild<LLSpinCtrl>("TexRot")->forceSetValue(self->getCurrentBumpyRot());
+        syncMaterialRot(self, self->getCurrentBumpyRot());
+    }
+    else
+    {
         if ((bool)self->childGetValue("checkbox planar align").asBoolean())
         {
             LLFace* last_face = NULL;
@@ -3625,22 +3625,22 @@ void LLPanelFace::onCommitMaterialBumpyRot(LLUICtrl* ctrl, void* userdata)
         {
             LLSelectedTEMaterial::setNormalRotation(self, self->getCurrentBumpyRot() * DEG_TO_RAD);
         }
-	}
+    }
 }
 
 //static
 void LLPanelFace::onCommitMaterialShinyRot(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
 
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		self->getChild<LLSpinCtrl>("TexRot")->forceSetValue(self->getCurrentShinyRot());
-		syncMaterialRot(self, self->getCurrentShinyRot());
-	}
-	else
-	{
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        self->getChild<LLSpinCtrl>("TexRot")->forceSetValue(self->getCurrentShinyRot());
+        syncMaterialRot(self, self->getCurrentShinyRot());
+    }
+    else
+    {
         if ((bool)self->childGetValue("checkbox planar align").asBoolean())
         {
             LLFace* last_face = NULL;
@@ -3653,136 +3653,136 @@ void LLPanelFace::onCommitMaterialShinyRot(LLUICtrl* ctrl, void* userdata)
         {
             LLSelectedTEMaterial::setSpecularRotation(self, self->getCurrentShinyRot() * DEG_TO_RAD);
         }
-	}
+    }
 }
 
 //static
 void LLPanelFace::onCommitMaterialGloss(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
-	LLSelectedTEMaterial::setSpecularLightExponent(self,self->getCurrentGlossiness());
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
+    LLSelectedTEMaterial::setSpecularLightExponent(self,self->getCurrentGlossiness());
 }
 
 //static
 void LLPanelFace::onCommitMaterialEnv(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	llassert_always(self);
-	LLSelectedTEMaterial::setEnvironmentIntensity(self,self->getCurrentEnvIntensity());
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    llassert_always(self);
+    LLSelectedTEMaterial::setEnvironmentIntensity(self,self->getCurrentEnvIntensity());
 }
 
 //static
 void LLPanelFace::onCommitMaterialMaskCutoff(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	LLSelectedTEMaterial::setAlphaMaskCutoff(self,self->getCurrentAlphaMaskCutoff());
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    LLSelectedTEMaterial::setAlphaMaskCutoff(self,self->getCurrentAlphaMaskCutoff());
 }
 
 // static
 void LLPanelFace::onCommitTextureInfo( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	self->sendTextureInfo();
-	// vertical scale and repeats per meter depends on each other, so force set on changes
-	self->updateUI(true);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    self->sendTextureInfo();
+    // vertical scale and repeats per meter depends on each other, so force set on changes
+    self->updateUI(true);
 }
 
 // static
 void LLPanelFace::onCommitTextureScaleX( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		F32 bumpy_scale_u = self->getChild<LLUICtrl>("TexScaleU")->getValue().asReal();
-		if (self->isIdenticalPlanarTexgen())
-		{
-			bumpy_scale_u *= 0.5f;
-		}
-		syncRepeatX(self, bumpy_scale_u);
-	}
-	else
-	{
-		self->sendTextureInfo();
-	}
-	self->updateUI(true);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        F32 bumpy_scale_u = self->getChild<LLUICtrl>("TexScaleU")->getValue().asReal();
+        if (self->isIdenticalPlanarTexgen())
+        {
+            bumpy_scale_u *= 0.5f;
+        }
+        syncRepeatX(self, bumpy_scale_u);
+    }
+    else
+    {
+        self->sendTextureInfo();
+    }
+    self->updateUI(true);
 }
 
 // static
 void LLPanelFace::onCommitTextureScaleY( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		F32 bumpy_scale_v = self->getChild<LLUICtrl>("TexScaleV")->getValue().asReal();
-		if (self->isIdenticalPlanarTexgen())
-		{
-			bumpy_scale_v *= 0.5f;
-		}
-		syncRepeatY(self, bumpy_scale_v);
-	}
-	else
-	{
-		self->sendTextureInfo();
-	}
-	self->updateUI(true);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        F32 bumpy_scale_v = self->getChild<LLUICtrl>("TexScaleV")->getValue().asReal();
+        if (self->isIdenticalPlanarTexgen())
+        {
+            bumpy_scale_v *= 0.5f;
+        }
+        syncRepeatY(self, bumpy_scale_v);
+    }
+    else
+    {
+        self->sendTextureInfo();
+    }
+    self->updateUI(true);
 }
 
 // static
 void LLPanelFace::onCommitTextureRot( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
+    LLPanelFace* self = (LLPanelFace*) userdata;
 
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		syncMaterialRot(self, self->getChild<LLUICtrl>("TexRot")->getValue().asReal());
-	}
-	else
-	{
-		self->sendTextureInfo();
-	}
-	self->updateUI(true);
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        syncMaterialRot(self, self->getChild<LLUICtrl>("TexRot")->getValue().asReal());
+    }
+    else
+    {
+        self->sendTextureInfo();
+    }
+    self->updateUI(true);
 }
 
 // static
 void LLPanelFace::onCommitTextureOffsetX( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		syncOffsetX(self, self->getChild<LLUICtrl>("TexOffsetU")->getValue().asReal());
-	}
-	else
-	{
-		self->sendTextureInfo();
-	}
-	self->updateUI(true);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        syncOffsetX(self, self->getChild<LLUICtrl>("TexOffsetU")->getValue().asReal());
+    }
+    else
+    {
+        self->sendTextureInfo();
+    }
+    self->updateUI(true);
 }
 
 // static
 void LLPanelFace::onCommitTextureOffsetY( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		syncOffsetY(self, self->getChild<LLUICtrl>("TexOffsetV")->getValue().asReal());
-	}
-	else
-	{
-		self->sendTextureInfo();
-	}
-	self->updateUI(true);
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        syncOffsetY(self, self->getChild<LLUICtrl>("TexOffsetV")->getValue().asReal());
+    }
+    else
+    {
+        self->sendTextureInfo();
+    }
+    self->updateUI(true);
 }
 
 // Commit the number of repeats per meter
 // static
 void LLPanelFace::onCommitRepeatsPerMeter(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	
-	LLUICtrl*	repeats_ctrl	= self->getChild<LLUICtrl>("rptctrl");
-	
-	U32 materials_media = self->mComboMatMedia->getCurrentIndex();
+    LLPanelFace* self = (LLPanelFace*) userdata;
+
+    LLUICtrl*   repeats_ctrl    = self->getChild<LLUICtrl>("rptctrl");
+
+    U32 materials_media = self->mComboMatMedia->getCurrentIndex();
     U32 material_type = 0;
     if (materials_media == MATMEDIA_PBR)
     {
@@ -3795,126 +3795,126 @@ void LLPanelFace::onCommitRepeatsPerMeter(LLUICtrl* ctrl, void* userdata)
         material_type = radio_mat_type->getSelectedIndex();
     }
 
-	F32 repeats_per_meter	= repeats_ctrl->getValue().asReal();
-	
+    F32 repeats_per_meter   = repeats_ctrl->getValue().asReal();
+
    F32 obj_scale_s = 1.0f;
    F32 obj_scale_t = 1.0f;
 
-	bool identical_scale_s = false;
-	bool identical_scale_t = false;
-
-	LLSelectedTE::getObjectScaleS(obj_scale_s, identical_scale_s);
-	LLSelectedTE::getObjectScaleS(obj_scale_t, identical_scale_t);
-
-	LLUICtrl* bumpy_scale_u = self->getChild<LLUICtrl>("bumpyScaleU");
-	LLUICtrl* bumpy_scale_v = self->getChild<LLUICtrl>("bumpyScaleV");
-	LLUICtrl* shiny_scale_u = self->getChild<LLUICtrl>("shinyScaleU");
-	LLUICtrl* shiny_scale_v = self->getChild<LLUICtrl>("shinyScaleV");
- 
-	if (gSavedSettings.getBOOL("SyncMaterialSettings"))
-	{
-		LLSelectMgr::getInstance()->selectionTexScaleAutofit( repeats_per_meter );
-
-		bumpy_scale_u->setValue(obj_scale_s * repeats_per_meter);
-		bumpy_scale_v->setValue(obj_scale_t * repeats_per_meter);
-
-		LLSelectedTEMaterial::setNormalRepeatX(self,obj_scale_s * repeats_per_meter);
-		LLSelectedTEMaterial::setNormalRepeatY(self,obj_scale_t * repeats_per_meter);
-
-		shiny_scale_u->setValue(obj_scale_s * repeats_per_meter);
-		shiny_scale_v->setValue(obj_scale_t * repeats_per_meter);
-
-		LLSelectedTEMaterial::setSpecularRepeatX(self,obj_scale_s * repeats_per_meter);
-		LLSelectedTEMaterial::setSpecularRepeatY(self,obj_scale_t * repeats_per_meter);
-	}
-	else
-	{
-		switch (material_type)
-		{
-			case MATTYPE_DIFFUSE:
-			{
-				LLSelectMgr::getInstance()->selectionTexScaleAutofit( repeats_per_meter );
-			}
-			break;
-
-			case MATTYPE_NORMAL:
-			{
-				bumpy_scale_u->setValue(obj_scale_s * repeats_per_meter);
-				bumpy_scale_v->setValue(obj_scale_t * repeats_per_meter);
-
-				LLSelectedTEMaterial::setNormalRepeatX(self,obj_scale_s * repeats_per_meter);
-				LLSelectedTEMaterial::setNormalRepeatY(self,obj_scale_t * repeats_per_meter);
-			}
-			break;
-
-			case MATTYPE_SPECULAR:
-			{
-				shiny_scale_u->setValue(obj_scale_s * repeats_per_meter);
-				shiny_scale_v->setValue(obj_scale_t * repeats_per_meter);
-
-				LLSelectedTEMaterial::setSpecularRepeatX(self,obj_scale_s * repeats_per_meter);
-				LLSelectedTEMaterial::setSpecularRepeatY(self,obj_scale_t * repeats_per_meter);
-			}
-			break;
-
-			default:
-				llassert(false);
-				break;
-		}
-	}
-	// vertical scale and repeats per meter depends on each other, so force set on changes
-	self->updateUI(true);
+    bool identical_scale_s = false;
+    bool identical_scale_t = false;
+
+    LLSelectedTE::getObjectScaleS(obj_scale_s, identical_scale_s);
+    LLSelectedTE::getObjectScaleS(obj_scale_t, identical_scale_t);
+
+    LLUICtrl* bumpy_scale_u = self->getChild<LLUICtrl>("bumpyScaleU");
+    LLUICtrl* bumpy_scale_v = self->getChild<LLUICtrl>("bumpyScaleV");
+    LLUICtrl* shiny_scale_u = self->getChild<LLUICtrl>("shinyScaleU");
+    LLUICtrl* shiny_scale_v = self->getChild<LLUICtrl>("shinyScaleV");
+
+    if (gSavedSettings.getBOOL("SyncMaterialSettings"))
+    {
+        LLSelectMgr::getInstance()->selectionTexScaleAutofit( repeats_per_meter );
+
+        bumpy_scale_u->setValue(obj_scale_s * repeats_per_meter);
+        bumpy_scale_v->setValue(obj_scale_t * repeats_per_meter);
+
+        LLSelectedTEMaterial::setNormalRepeatX(self,obj_scale_s * repeats_per_meter);
+        LLSelectedTEMaterial::setNormalRepeatY(self,obj_scale_t * repeats_per_meter);
+
+        shiny_scale_u->setValue(obj_scale_s * repeats_per_meter);
+        shiny_scale_v->setValue(obj_scale_t * repeats_per_meter);
+
+        LLSelectedTEMaterial::setSpecularRepeatX(self,obj_scale_s * repeats_per_meter);
+        LLSelectedTEMaterial::setSpecularRepeatY(self,obj_scale_t * repeats_per_meter);
+    }
+    else
+    {
+        switch (material_type)
+        {
+            case MATTYPE_DIFFUSE:
+            {
+                LLSelectMgr::getInstance()->selectionTexScaleAutofit( repeats_per_meter );
+            }
+            break;
+
+            case MATTYPE_NORMAL:
+            {
+                bumpy_scale_u->setValue(obj_scale_s * repeats_per_meter);
+                bumpy_scale_v->setValue(obj_scale_t * repeats_per_meter);
+
+                LLSelectedTEMaterial::setNormalRepeatX(self,obj_scale_s * repeats_per_meter);
+                LLSelectedTEMaterial::setNormalRepeatY(self,obj_scale_t * repeats_per_meter);
+            }
+            break;
+
+            case MATTYPE_SPECULAR:
+            {
+                shiny_scale_u->setValue(obj_scale_s * repeats_per_meter);
+                shiny_scale_v->setValue(obj_scale_t * repeats_per_meter);
+
+                LLSelectedTEMaterial::setSpecularRepeatX(self,obj_scale_s * repeats_per_meter);
+                LLSelectedTEMaterial::setSpecularRepeatY(self,obj_scale_t * repeats_per_meter);
+            }
+            break;
+
+            default:
+                llassert(false);
+                break;
+        }
+    }
+    // vertical scale and repeats per meter depends on each other, so force set on changes
+    self->updateUI(true);
 }
 
 struct LLPanelFaceSetMediaFunctor : public LLSelectedTEFunctor
 {
-	virtual bool apply(LLViewerObject* object, S32 te)
-	{
-		viewer_media_t pMediaImpl;
-				
-		const LLTextureEntry* tep = object->getTE(te);
-		const LLMediaEntry* mep = tep->hasMedia() ? tep->getMediaData() : NULL;
-		if ( mep )
-		{
-			pMediaImpl = LLViewerMedia::getInstance()->getMediaImplFromTextureID(mep->getMediaID());
-		}
-		
-		if ( pMediaImpl.isNull())
-		{
-			// If we didn't find face media for this face, check whether this face is showing parcel media.
-			pMediaImpl = LLViewerMedia::getInstance()->getMediaImplFromTextureID(tep->getID());
-		}
-		
-		if ( pMediaImpl.notNull())
-		{
-			LLPluginClassMedia *media = pMediaImpl->getMediaPlugin();
-			if(media)
-			{
-				S32 media_width = media->getWidth();
-				S32 media_height = media->getHeight();
-				S32 texture_width = media->getTextureWidth();
-				S32 texture_height = media->getTextureHeight();
-				F32 scale_s = (F32)media_width / (F32)texture_width;
-				F32 scale_t = (F32)media_height / (F32)texture_height;
-
-				// set scale and adjust offset
-				object->setTEScaleS( te, scale_s );
-				object->setTEScaleT( te, scale_t );	// don't need to flip Y anymore since QT does this for us now.
-				object->setTEOffsetS( te, -( 1.0f - scale_s ) / 2.0f );
-				object->setTEOffsetT( te, -( 1.0f - scale_t ) / 2.0f );
-			}
-		}
-		return true;
-	};
+    virtual bool apply(LLViewerObject* object, S32 te)
+    {
+        viewer_media_t pMediaImpl;
+
+        const LLTextureEntry* tep = object->getTE(te);
+        const LLMediaEntry* mep = tep->hasMedia() ? tep->getMediaData() : NULL;
+        if ( mep )
+        {
+            pMediaImpl = LLViewerMedia::getInstance()->getMediaImplFromTextureID(mep->getMediaID());
+        }
+
+        if ( pMediaImpl.isNull())
+        {
+            // If we didn't find face media for this face, check whether this face is showing parcel media.
+            pMediaImpl = LLViewerMedia::getInstance()->getMediaImplFromTextureID(tep->getID());
+        }
+
+        if ( pMediaImpl.notNull())
+        {
+            LLPluginClassMedia *media = pMediaImpl->getMediaPlugin();
+            if(media)
+            {
+                S32 media_width = media->getWidth();
+                S32 media_height = media->getHeight();
+                S32 texture_width = media->getTextureWidth();
+                S32 texture_height = media->getTextureHeight();
+                F32 scale_s = (F32)media_width / (F32)texture_width;
+                F32 scale_t = (F32)media_height / (F32)texture_height;
+
+                // set scale and adjust offset
+                object->setTEScaleS( te, scale_s );
+                object->setTEScaleT( te, scale_t ); // don't need to flip Y anymore since QT does this for us now.
+                object->setTEOffsetS( te, -( 1.0f - scale_s ) / 2.0f );
+                object->setTEOffsetT( te, -( 1.0f - scale_t ) / 2.0f );
+            }
+        }
+        return true;
+    };
 };
 
 void LLPanelFace::onClickAutoFix(void* userdata)
 {
-	LLPanelFaceSetMediaFunctor setfunc;
-	LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc);
+    LLPanelFaceSetMediaFunctor setfunc;
+    LLSelectMgr::getInstance()->getSelection()->applyToTEs(&setfunc);
 
-	LLPanelFaceSendFunctor sendfunc;
-	LLSelectMgr::getInstance()->getSelection()->applyToObjects(&sendfunc);
+    LLPanelFaceSendFunctor sendfunc;
+    LLSelectMgr::getInstance()->getSelection()->applyToObjects(&sendfunc);
 }
 
 void LLPanelFace::onAlignTexture(void* userdata)
@@ -4293,7 +4293,7 @@ void LLPanelFace::onCopyTexture()
 
                     {
                         te_data["te"]["itemfullperm"] = full_perm;
-                        te_data["te"]["fromlibrary"] = from_library; 
+                        te_data["te"]["fromlibrary"] = from_library;
 
                         // If full permission object, texture is free to copy,
                         // but otherwise we need to check inventory and extract permissions
@@ -4422,7 +4422,7 @@ void LLPanelFace::onPasteTexture()
     }
 
     // we can copy if single face was copied in edit face mode or if face count matches
-    if (!((clipboard.size() == 1) && mClipboardParams["texture_all_tes"].asBoolean()) 
+    if (!((clipboard.size() == 1) && mClipboardParams["texture_all_tes"].asBoolean())
         && compare_tes != clipboard.size())
     {
         LLSD notif_args;
@@ -4804,9 +4804,9 @@ bool LLPanelFace::menuEnableItem(const LLSD& userdata)
 // static
 void LLPanelFace::onCommitPlanarAlign(LLUICtrl* ctrl, void* userdata)
 {
-	LLPanelFace* self = (LLPanelFace*) userdata;
-	self->getState();
-	self->sendTextureInfo();
+    LLPanelFace* self = (LLPanelFace*) userdata;
+    self->getState();
+    self->sendTextureInfo();
 }
 
 void LLPanelFace::updateGLTFTextureTransform(float value, U32 pbr_type, std::function<void(LLGLTFMaterial::TextureTransform*)> edit)
@@ -5055,54 +5055,54 @@ void LLPanelFace::onCommitGLTFTextureOffsetV(LLUICtrl* ctrl)
 
 void LLPanelFace::onTextureSelectionChanged(LLInventoryItem* itemp)
 {
-	LL_DEBUGS("Materials") << "item asset " << itemp->getAssetUUID() << LL_ENDL;
-	LLRadioGroup* radio_mat_type = findChild<LLRadioGroup>("radio_material_type");
-	if(!radio_mat_type)
-	{
-	    return;
-	}
-	U32 mattype = radio_mat_type->getSelectedIndex();
-	std::string which_control="texture control";
-	switch (mattype)
-	{
-		case MATTYPE_SPECULAR:
-			which_control = "shinytexture control";
-			break;
-		case MATTYPE_NORMAL:
-			which_control = "bumpytexture control";
-			break;
-		// no default needed
-	}
-	LL_DEBUGS("Materials") << "control " << which_control << LL_ENDL;
-	LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>(which_control);
-	if (texture_ctrl)
-	{
-		LLUUID obj_owner_id;
-		std::string obj_owner_name;
-		LLSelectMgr::instance().selectGetOwner(obj_owner_id, obj_owner_name);
-
-		LLSaleInfo sale_info;
-		LLSelectMgr::instance().selectGetSaleInfo(sale_info);
-
-		bool can_copy = itemp->getPermissions().allowCopyBy(gAgentID); // do we have perm to copy this texture?
-		bool can_transfer = itemp->getPermissions().allowOperationBy(PERM_TRANSFER, gAgentID); // do we have perm to transfer this texture?
-		bool is_object_owner = gAgentID == obj_owner_id; // does object for which we are going to apply texture belong to the agent?
-		bool not_for_sale = !sale_info.isForSale(); // is object for which we are going to apply texture not for sale?
-
-		if (can_copy && can_transfer)
-		{
-			texture_ctrl->setCanApply(true, true);
-			return;
-		}
-
-		// if texture has (no-transfer) attribute it can be applied only for object which we own and is not for sale
-		texture_ctrl->setCanApply(false, can_transfer ? true : is_object_owner && not_for_sale);
-
-		if (gSavedSettings.getBOOL("TextureLivePreview"))
-		{
-			LLNotificationsUtil::add("LivePreviewUnavailable");
-		}
-	}
+    LL_DEBUGS("Materials") << "item asset " << itemp->getAssetUUID() << LL_ENDL;
+    LLRadioGroup* radio_mat_type = findChild<LLRadioGroup>("radio_material_type");
+    if(!radio_mat_type)
+    {
+        return;
+    }
+    U32 mattype = radio_mat_type->getSelectedIndex();
+    std::string which_control="texture control";
+    switch (mattype)
+    {
+        case MATTYPE_SPECULAR:
+            which_control = "shinytexture control";
+            break;
+        case MATTYPE_NORMAL:
+            which_control = "bumpytexture control";
+            break;
+        // no default needed
+    }
+    LL_DEBUGS("Materials") << "control " << which_control << LL_ENDL;
+    LLTextureCtrl* texture_ctrl = getChild<LLTextureCtrl>(which_control);
+    if (texture_ctrl)
+    {
+        LLUUID obj_owner_id;
+        std::string obj_owner_name;
+        LLSelectMgr::instance().selectGetOwner(obj_owner_id, obj_owner_name);
+
+        LLSaleInfo sale_info;
+        LLSelectMgr::instance().selectGetSaleInfo(sale_info);
+
+        bool can_copy = itemp->getPermissions().allowCopyBy(gAgentID); // do we have perm to copy this texture?
+        bool can_transfer = itemp->getPermissions().allowOperationBy(PERM_TRANSFER, gAgentID); // do we have perm to transfer this texture?
+        bool is_object_owner = gAgentID == obj_owner_id; // does object for which we are going to apply texture belong to the agent?
+        bool not_for_sale = !sale_info.isForSale(); // is object for which we are going to apply texture not for sale?
+
+        if (can_copy && can_transfer)
+        {
+            texture_ctrl->setCanApply(true, true);
+            return;
+        }
+
+        // if texture has (no-transfer) attribute it can be applied only for object which we own and is not for sale
+        texture_ctrl->setCanApply(false, can_transfer ? true : is_object_owner && not_for_sale);
+
+        if (gSavedSettings.getBOOL("TextureLivePreview"))
+        {
+            LLNotificationsUtil::add("LivePreviewUnavailable");
+        }
+    }
 }
 
 void LLPanelFace::onPbrSelectionChanged(LLInventoryItem* itemp)
@@ -5142,81 +5142,81 @@ void LLPanelFace::onPbrSelectionChanged(LLInventoryItem* itemp)
 
 bool LLPanelFace::isIdenticalPlanarTexgen()
 {
-	LLTextureEntry::e_texgen selected_texgen = LLTextureEntry::TEX_GEN_DEFAULT;
-	bool identical_texgen = false;
-	LLSelectedTE::getTexGen(selected_texgen, identical_texgen);
-	return (identical_texgen && (selected_texgen == LLTextureEntry::TEX_GEN_PLANAR));
+    LLTextureEntry::e_texgen selected_texgen = LLTextureEntry::TEX_GEN_DEFAULT;
+    bool identical_texgen = false;
+    LLSelectedTE::getTexGen(selected_texgen, identical_texgen);
+    return (identical_texgen && (selected_texgen == LLTextureEntry::TEX_GEN_PLANAR));
 }
 
 void LLPanelFace::LLSelectedTE::getFace(LLFace*& face_to_return, bool& identical_face)
-{		
-	struct LLSelectedTEGetFace : public LLSelectedTEGetFunctor<LLFace *>
-	{
-		LLFace* get(LLViewerObject* object, S32 te)
-		{
-			return (object->mDrawable) ? object->mDrawable->getFace(te): NULL;
-		}
-	} get_te_face_func;
-	identical_face = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_te_face_func, face_to_return, false, (LLFace*)nullptr);
+{
+    struct LLSelectedTEGetFace : public LLSelectedTEGetFunctor<LLFace *>
+    {
+        LLFace* get(LLViewerObject* object, S32 te)
+        {
+            return (object->mDrawable) ? object->mDrawable->getFace(te): NULL;
+        }
+    } get_te_face_func;
+    identical_face = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_te_face_func, face_to_return, false, (LLFace*)nullptr);
 }
 
 void LLPanelFace::LLSelectedTE::getImageFormat(LLGLenum& image_format_to_return, bool& identical_face)
 {
-	LLGLenum image_format = {};
-	struct LLSelectedTEGetImageFormat : public LLSelectedTEGetFunctor<LLGLenum>
-	{
-		LLGLenum get(LLViewerObject* object, S32 te_index)
-		{
-			LLViewerTexture* image = object->getTEImage(te_index);
-			return image ? image->getPrimaryFormat() : GL_RGB;
-		}
-	} get_glenum;
-	identical_face = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_glenum, image_format);
-	image_format_to_return = image_format;
+    LLGLenum image_format = {};
+    struct LLSelectedTEGetImageFormat : public LLSelectedTEGetFunctor<LLGLenum>
+    {
+        LLGLenum get(LLViewerObject* object, S32 te_index)
+        {
+            LLViewerTexture* image = object->getTEImage(te_index);
+            return image ? image->getPrimaryFormat() : GL_RGB;
+        }
+    } get_glenum;
+    identical_face = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue(&get_glenum, image_format);
+    image_format_to_return = image_format;
 }
 
 void LLPanelFace::LLSelectedTE::getTexId(LLUUID& id, bool& identical)
-{		
-	struct LLSelectedTEGetTexId : public LLSelectedTEGetFunctor<LLUUID>
-	{
-		LLUUID get(LLViewerObject* object, S32 te_index)
-		{
-			LLTextureEntry *te = object->getTE(te_index);
-			if (te)
-			{
-				if ((te->getID() == IMG_USE_BAKED_EYES) || (te->getID() == IMG_USE_BAKED_HAIR) || (te->getID() == IMG_USE_BAKED_HEAD) || (te->getID() == IMG_USE_BAKED_LOWER) || (te->getID() == IMG_USE_BAKED_SKIRT) || (te->getID() == IMG_USE_BAKED_UPPER)
-					|| (te->getID() == IMG_USE_BAKED_LEFTARM) || (te->getID() == IMG_USE_BAKED_LEFTLEG) || (te->getID() == IMG_USE_BAKED_AUX1) || (te->getID() == IMG_USE_BAKED_AUX2) || (te->getID() == IMG_USE_BAKED_AUX3))
-				{
-					return te->getID();
-				}
-			}
-
-			LLUUID id;
-			LLViewerTexture* image = object->getTEImage(te_index);
-			if (image)
-			{
-				id = image->getID();
-			}
-
-			if (!id.isNull() && LLViewerMedia::getInstance()->textureHasMedia(id))
-			{
-				if (te)
-				{
-					LLViewerTexture* tex = te->getID().notNull() ? gTextureList.findImage(te->getID(), TEX_LIST_STANDARD) : NULL;
-					if(!tex)
-					{
-						tex = LLViewerFetchedTexture::sDefaultImagep;
-					}
-					if (tex)
-					{
-						id = tex->getID();
-					}
-				}
-			}
-			return id;
-		}
-	} func;
-	identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, id );
+{
+    struct LLSelectedTEGetTexId : public LLSelectedTEGetFunctor<LLUUID>
+    {
+        LLUUID get(LLViewerObject* object, S32 te_index)
+        {
+            LLTextureEntry *te = object->getTE(te_index);
+            if (te)
+            {
+                if ((te->getID() == IMG_USE_BAKED_EYES) || (te->getID() == IMG_USE_BAKED_HAIR) || (te->getID() == IMG_USE_BAKED_HEAD) || (te->getID() == IMG_USE_BAKED_LOWER) || (te->getID() == IMG_USE_BAKED_SKIRT) || (te->getID() == IMG_USE_BAKED_UPPER)
+                    || (te->getID() == IMG_USE_BAKED_LEFTARM) || (te->getID() == IMG_USE_BAKED_LEFTLEG) || (te->getID() == IMG_USE_BAKED_AUX1) || (te->getID() == IMG_USE_BAKED_AUX2) || (te->getID() == IMG_USE_BAKED_AUX3))
+                {
+                    return te->getID();
+                }
+            }
+
+            LLUUID id;
+            LLViewerTexture* image = object->getTEImage(te_index);
+            if (image)
+            {
+                id = image->getID();
+            }
+
+            if (!id.isNull() && LLViewerMedia::getInstance()->textureHasMedia(id))
+            {
+                if (te)
+                {
+                    LLViewerTexture* tex = te->getID().notNull() ? gTextureList.findImage(te->getID(), TEX_LIST_STANDARD) : NULL;
+                    if(!tex)
+                    {
+                        tex = LLViewerFetchedTexture::sDefaultImagep;
+                    }
+                    if (tex)
+                    {
+                        id = tex->getID();
+                    }
+                }
+            }
+            return id;
+        }
+    } func;
+    identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, id );
 }
 
 void LLPanelFace::LLSelectedTE::getPbrMaterialId(LLUUID& id, bool& identical, bool& has_faces_with_pbr, bool& has_faces_without_pbr)
@@ -5249,7 +5249,7 @@ void LLPanelFace::LLSelectedTE::getPbrMaterialId(LLUUID& id, bool& identical, bo
                 {
                     mIdenticalId = false;
                 }
-                
+
                 LLGLTFMaterial* te_override = object->getTE(te_index)->getGLTFMaterialOverride();
                 if (te_override)
                 {
@@ -5292,194 +5292,194 @@ void LLPanelFace::LLSelectedTE::getPbrMaterialId(LLUUID& id, bool& identical, bo
 
 void LLPanelFace::LLSelectedTEMaterial::getCurrent(LLMaterialPtr& material_ptr, bool& identical_material)
 {
-	struct MaterialFunctor : public LLSelectedTEGetFunctor<LLMaterialPtr>
-	{
-		LLMaterialPtr get(LLViewerObject* object, S32 te_index)
-		{
-			return object->getTE(te_index)->getMaterialParams();
-		}
-	} func;
-	identical_material = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, material_ptr);
+    struct MaterialFunctor : public LLSelectedTEGetFunctor<LLMaterialPtr>
+    {
+        LLMaterialPtr get(LLViewerObject* object, S32 te_index)
+        {
+            return object->getTE(te_index)->getMaterialParams();
+        }
+    } func;
+    identical_material = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, material_ptr);
 }
 
 void LLPanelFace::LLSelectedTEMaterial::getMaxSpecularRepeats(F32& repeats, bool& identical)
 {
-	struct LLSelectedTEGetMaxSpecRepeats : public LLSelectedTEGetFunctor<F32>
-	{
-		F32 get(LLViewerObject* object, S32 face)
-		{
-			LLMaterial* mat = object->getTE(face)->getMaterialParams().get();
-			U32 s_axis = VX;
-			U32 t_axis = VY;
-			F32 repeats_s = 1.0f;
-			F32 repeats_t = 1.0f;
-			if (mat)
-			{
-				mat->getSpecularRepeat(repeats_s, repeats_t);
-				repeats_s /= object->getScale().mV[s_axis];
-				repeats_t /= object->getScale().mV[t_axis];
-			}					
-			return llmax(repeats_s, repeats_t);
-		}
-
-	} max_spec_repeats_func;
-	identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &max_spec_repeats_func, repeats);
+    struct LLSelectedTEGetMaxSpecRepeats : public LLSelectedTEGetFunctor<F32>
+    {
+        F32 get(LLViewerObject* object, S32 face)
+        {
+            LLMaterial* mat = object->getTE(face)->getMaterialParams().get();
+            U32 s_axis = VX;
+            U32 t_axis = VY;
+            F32 repeats_s = 1.0f;
+            F32 repeats_t = 1.0f;
+            if (mat)
+            {
+                mat->getSpecularRepeat(repeats_s, repeats_t);
+                repeats_s /= object->getScale().mV[s_axis];
+                repeats_t /= object->getScale().mV[t_axis];
+            }
+            return llmax(repeats_s, repeats_t);
+        }
+
+    } max_spec_repeats_func;
+    identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &max_spec_repeats_func, repeats);
 }
 
 void LLPanelFace::LLSelectedTEMaterial::getMaxNormalRepeats(F32& repeats, bool& identical)
 {
-	struct LLSelectedTEGetMaxNormRepeats : public LLSelectedTEGetFunctor<F32>
-	{
-		F32 get(LLViewerObject* object, S32 face)
-		{
-			LLMaterial* mat = object->getTE(face)->getMaterialParams().get();
-			U32 s_axis = VX;
-			U32 t_axis = VY;
-			F32 repeats_s = 1.0f;
-			F32 repeats_t = 1.0f;
-			if (mat)
-			{
-				mat->getNormalRepeat(repeats_s, repeats_t);
-				repeats_s /= object->getScale().mV[s_axis];
-				repeats_t /= object->getScale().mV[t_axis];
-			}					
-			return llmax(repeats_s, repeats_t);
-		}
-
-	} max_norm_repeats_func;
-	identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &max_norm_repeats_func, repeats);
+    struct LLSelectedTEGetMaxNormRepeats : public LLSelectedTEGetFunctor<F32>
+    {
+        F32 get(LLViewerObject* object, S32 face)
+        {
+            LLMaterial* mat = object->getTE(face)->getMaterialParams().get();
+            U32 s_axis = VX;
+            U32 t_axis = VY;
+            F32 repeats_s = 1.0f;
+            F32 repeats_t = 1.0f;
+            if (mat)
+            {
+                mat->getNormalRepeat(repeats_s, repeats_t);
+                repeats_s /= object->getScale().mV[s_axis];
+                repeats_t /= object->getScale().mV[t_axis];
+            }
+            return llmax(repeats_s, repeats_t);
+        }
+
+    } max_norm_repeats_func;
+    identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &max_norm_repeats_func, repeats);
 }
 
 void LLPanelFace::LLSelectedTEMaterial::getCurrentDiffuseAlphaMode(U8& diffuse_alpha_mode, bool& identical, bool diffuse_texture_has_alpha)
 {
-	struct LLSelectedTEGetDiffuseAlphaMode : public LLSelectedTEGetFunctor<U8>
-	{
-		LLSelectedTEGetDiffuseAlphaMode() : _isAlpha(false) {}
-		LLSelectedTEGetDiffuseAlphaMode(bool diffuse_texture_has_alpha) : _isAlpha(diffuse_texture_has_alpha) {}
-		virtual ~LLSelectedTEGetDiffuseAlphaMode() {}
-
-		U8 get(LLViewerObject* object, S32 face)
-		{
-			U8 diffuse_mode = _isAlpha ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
-
-			LLTextureEntry* tep = object->getTE(face);
-			if (tep)
-			{
-				LLMaterial* mat = tep->getMaterialParams().get();
-				if (mat)
-				{
-					diffuse_mode = mat->getDiffuseAlphaMode();
-				}
-			}
-			
-			return diffuse_mode;
-		}
-		bool _isAlpha; // whether or not the diffuse texture selected contains alpha information
-	} get_diff_mode(diffuse_texture_has_alpha);
-	identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &get_diff_mode, diffuse_alpha_mode);
+    struct LLSelectedTEGetDiffuseAlphaMode : public LLSelectedTEGetFunctor<U8>
+    {
+        LLSelectedTEGetDiffuseAlphaMode() : _isAlpha(false) {}
+        LLSelectedTEGetDiffuseAlphaMode(bool diffuse_texture_has_alpha) : _isAlpha(diffuse_texture_has_alpha) {}
+        virtual ~LLSelectedTEGetDiffuseAlphaMode() {}
+
+        U8 get(LLViewerObject* object, S32 face)
+        {
+            U8 diffuse_mode = _isAlpha ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
+
+            LLTextureEntry* tep = object->getTE(face);
+            if (tep)
+            {
+                LLMaterial* mat = tep->getMaterialParams().get();
+                if (mat)
+                {
+                    diffuse_mode = mat->getDiffuseAlphaMode();
+                }
+            }
+
+            return diffuse_mode;
+        }
+        bool _isAlpha; // whether or not the diffuse texture selected contains alpha information
+    } get_diff_mode(diffuse_texture_has_alpha);
+    identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &get_diff_mode, diffuse_alpha_mode);
 }
 
 void LLPanelFace::LLSelectedTE::getObjectScaleS(F32& scale_s, bool& identical)
-{	
-	struct LLSelectedTEGetObjectScaleS : public LLSelectedTEGetFunctor<F32>
-	{
-		F32 get(LLViewerObject* object, S32 face)
-		{
-			U32 s_axis = VX;
-			U32 t_axis = VY;
-			LLPrimitive::getTESTAxes(face, &s_axis, &t_axis);
-			return object->getScale().mV[s_axis];
-		}
+{
+    struct LLSelectedTEGetObjectScaleS : public LLSelectedTEGetFunctor<F32>
+    {
+        F32 get(LLViewerObject* object, S32 face)
+        {
+            U32 s_axis = VX;
+            U32 t_axis = VY;
+            LLPrimitive::getTESTAxes(face, &s_axis, &t_axis);
+            return object->getScale().mV[s_axis];
+        }
 
-	} scale_s_func;
-	identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &scale_s_func, scale_s );
+    } scale_s_func;
+    identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &scale_s_func, scale_s );
 }
 
 void LLPanelFace::LLSelectedTE::getObjectScaleT(F32& scale_t, bool& identical)
-{	
-	struct LLSelectedTEGetObjectScaleS : public LLSelectedTEGetFunctor<F32>
-	{
-		F32 get(LLViewerObject* object, S32 face)
-		{
-			U32 s_axis = VX;
-			U32 t_axis = VY;
-			LLPrimitive::getTESTAxes(face, &s_axis, &t_axis);
-			return object->getScale().mV[t_axis];
-		}
+{
+    struct LLSelectedTEGetObjectScaleS : public LLSelectedTEGetFunctor<F32>
+    {
+        F32 get(LLViewerObject* object, S32 face)
+        {
+            U32 s_axis = VX;
+            U32 t_axis = VY;
+            LLPrimitive::getTESTAxes(face, &s_axis, &t_axis);
+            return object->getScale().mV[t_axis];
+        }
 
-	} scale_t_func;
-	identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &scale_t_func, scale_t );
+    } scale_t_func;
+    identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &scale_t_func, scale_t );
 }
 
 void LLPanelFace::LLSelectedTE::getMaxDiffuseRepeats(F32& repeats, bool& identical)
 {
-	struct LLSelectedTEGetMaxDiffuseRepeats : public LLSelectedTEGetFunctor<F32>
-	{
-		F32 get(LLViewerObject* object, S32 face)
-		{
-			U32 s_axis = VX;
-			U32 t_axis = VY;
-			LLPrimitive::getTESTAxes(face, &s_axis, &t_axis);
-			F32 repeats_s = object->getTE(face)->mScaleS / object->getScale().mV[s_axis];
-			F32 repeats_t = object->getTE(face)->mScaleT / object->getScale().mV[t_axis];
-			return llmax(repeats_s, repeats_t);
-		}
+    struct LLSelectedTEGetMaxDiffuseRepeats : public LLSelectedTEGetFunctor<F32>
+    {
+        F32 get(LLViewerObject* object, S32 face)
+        {
+            U32 s_axis = VX;
+            U32 t_axis = VY;
+            LLPrimitive::getTESTAxes(face, &s_axis, &t_axis);
+            F32 repeats_s = object->getTE(face)->mScaleS / object->getScale().mV[s_axis];
+            F32 repeats_t = object->getTE(face)->mScaleT / object->getScale().mV[t_axis];
+            return llmax(repeats_s, repeats_t);
+        }
 
-	} max_diff_repeats_func;
-	identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &max_diff_repeats_func, repeats );
+    } max_diff_repeats_func;
+    identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &max_diff_repeats_func, repeats );
 }
 
 void LLPanelFace::onClickBtnSelectSameTexture(const LLUICtrl* ctrl, const LLSD& user_data)
 {
-	char channel = user_data.asStringRef()[0];
-
-	std::unordered_set<LLViewerObject*> objects;
-
-	// get a list of all linksets where at least one face is selected
-	for (auto iter = LLSelectMgr::getInstance()->getSelection()->valid_begin();
-		iter != LLSelectMgr::getInstance()->getSelection()->valid_end(); iter++)
-	{
-		objects.insert((*iter)->getObject()->getRootEdit());
-	}
-
-	// clean out the selection
-	LLSelectMgr::getInstance()->deselectAll();
-
-	// select all faces of all linksets that were found before
-	LLObjectSelectionHandle handle;
-	for(auto objectp : objects)
-	{
-		handle = LLSelectMgr::getInstance()->selectObjectAndFamily(objectp, true, false);
-	}
-
-	// grab the texture ID from the texture selector
-	LLTextureCtrl* texture_control = mTextureCtrl;
-	if (channel == 'n')
-	{
-		texture_control = mBumpyTextureCtrl;
-	}
-	else if (channel == 's')
-	{
-		texture_control = mShinyTextureCtrl;
-	}
+    char channel = user_data.asStringRef()[0];
+
+    std::unordered_set<LLViewerObject*> objects;
+
+    // get a list of all linksets where at least one face is selected
+    for (auto iter = LLSelectMgr::getInstance()->getSelection()->valid_begin();
+        iter != LLSelectMgr::getInstance()->getSelection()->valid_end(); iter++)
+    {
+        objects.insert((*iter)->getObject()->getRootEdit());
+    }
+
+    // clean out the selection
+    LLSelectMgr::getInstance()->deselectAll();
+
+    // select all faces of all linksets that were found before
+    LLObjectSelectionHandle handle;
+    for(auto objectp : objects)
+    {
+        handle = LLSelectMgr::getInstance()->selectObjectAndFamily(objectp, true, false);
+    }
+
+    // grab the texture ID from the texture selector
+    LLTextureCtrl* texture_control = mTextureCtrl;
+    if (channel == 'n')
+    {
+        texture_control = mBumpyTextureCtrl;
+    }
+    else if (channel == 's')
+    {
+        texture_control = mShinyTextureCtrl;
+    }
     else if (channel == 'p')
     {
         texture_control = getChild<LLTextureCtrl>("pbr_control");
     }
 
-	LLUUID id = texture_control->getImageAssetID();
+    LLUUID id = texture_control->getImageAssetID();
 
-	// go through all selected links in all selecrted linksets
-	for (auto iter = handle->begin(); iter != handle->end(); iter++)
-	{
-		LLSelectNode* node = *iter;
-		LLViewerObject* objectp = node->getObject();
+    // go through all selected links in all selecrted linksets
+    for (auto iter = handle->begin(); iter != handle->end(); iter++)
+    {
+        LLSelectNode* node = *iter;
+        LLViewerObject* objectp = node->getObject();
 
-		U8 te_count = objectp->getNumTEs();
+        U8 te_count = objectp->getNumTEs();
 
-		for (U8 i = 0; i < te_count; i++)
-		{
-			LLUUID image_id = objectp->getRenderMaterialID(i); // Always check PBR material to prevent selection of non-editable faces
+        for (U8 i = 0; i < te_count; i++)
+        {
+            LLUUID image_id = objectp->getRenderMaterialID(i); // Always check PBR material to prevent selection of non-editable faces
             if (image_id.isNull())
             {
                 if (channel == 'd')
@@ -5503,12 +5503,12 @@ void LLPanelFace::onClickBtnSelectSameTexture(const LLUICtrl* ctrl, const LLSD&
                 }
             }
 
-			// deselect all faces that use a different texture UUID
-			if (image_id != id)
-			{
-				objectp->setTESelected(i, false);
-				node->selectTE(i, false);
-			}
-		}
-	}
+            // deselect all faces that use a different texture UUID
+            if (image_id != id)
+            {
+                objectp->setTESelected(i, false);
+                node->selectTE(i, false);
+            }
+        }
+    }
 }
diff --git a/indra/newview/llpanelface.h b/indra/newview/llpanelface.h
index 402e03cfc9bf6b9a984960386e3aaddf93e25a85..bd1b7f737c5c45fb1825626b76c3a541738d5780 100644
--- a/indra/newview/llpanelface.h
+++ b/indra/newview/llpanelface.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llpanelface.h
  * @brief Panel in the tools floater for editing face textures, colors, etc.
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -66,181 +66,181 @@ class PBRPickerObjectListener;
 // boost who?
 //
 template<
-	typename DataType,
-	typename SetValueType,
-	void (LLMaterial::*MaterialEditFunc)(SetValueType data) >
+    typename DataType,
+    typename SetValueType,
+    void (LLMaterial::*MaterialEditFunc)(SetValueType data) >
 class LLMaterialEditFunctor
 {
 public:
-	LLMaterialEditFunctor(const DataType& data) : _data(data) {}
-	virtual ~LLMaterialEditFunctor() {}
-	virtual void apply(LLMaterialPtr& material) { (material->*(MaterialEditFunc))(_data); }
-	DataType _data;
+    LLMaterialEditFunctor(const DataType& data) : _data(data) {}
+    virtual ~LLMaterialEditFunctor() {}
+    virtual void apply(LLMaterialPtr& material) { (material->*(MaterialEditFunc))(_data); }
+    DataType _data;
 };
 
 template<
-	typename DataType,
-	DataType (LLMaterial::*MaterialGetFunc)() >
+    typename DataType,
+    DataType (LLMaterial::*MaterialGetFunc)() >
 class LLMaterialGetFunctor
 {
 public:
-	LLMaterialGetFunctor() {}
-	virtual DataType get(LLMaterialPtr& material) { return (material->*(MaterialGetFunc)); }
+    LLMaterialGetFunctor() {}
+    virtual DataType get(LLMaterialPtr& material) { return (material->*(MaterialGetFunc)); }
 };
 
 template<
-	typename DataType,
-	DataType (LLTextureEntry::*TEGetFunc)() >
+    typename DataType,
+    DataType (LLTextureEntry::*TEGetFunc)() >
 class LLTEGetFunctor
 {
 public:
-	LLTEGetFunctor() {}
-	virtual DataType get(LLTextureEntry* entry) { return (entry*(TEGetFunc)); }
+    LLTEGetFunctor() {}
+    virtual DataType get(LLTextureEntry* entry) { return (entry*(TEGetFunc)); }
 };
 
 class LLPanelFace : public LLPanel
 {
 public:
-	virtual BOOL	postBuild();
-	LLPanelFace();
-	virtual ~LLPanelFace();
+    virtual BOOL    postBuild();
+    LLPanelFace();
+    virtual ~LLPanelFace();
 
-	void			refresh();
-    void			refreshMedia();
-    void			unloadMedia();
+    void            refresh();
+    void            refreshMedia();
+    void            unloadMedia();
 
     static void onMaterialOverrideReceived(const LLUUID& object_id, S32 side);
 
     /*virtual*/ void onVisibilityChange(BOOL new_visibility);
     /*virtual*/ void draw();
 
-	LLMaterialPtr createDefaultMaterial(LLMaterialPtr current_material)
-	{
-		LLMaterialPtr new_material(!current_material.isNull() ? new LLMaterial(current_material->asLLSD()) : new LLMaterial());
-		llassert_always(new_material);
+    LLMaterialPtr createDefaultMaterial(LLMaterialPtr current_material)
+    {
+        LLMaterialPtr new_material(!current_material.isNull() ? new LLMaterial(current_material->asLLSD()) : new LLMaterial());
+        llassert_always(new_material);
 
-		// Preserve old diffuse alpha mode or assert correct default blend mode as appropriate for the alpha channel content of the diffuse texture
-		//
-		new_material->setDiffuseAlphaMode(current_material.isNull() ? (isAlpha() ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE) : current_material->getDiffuseAlphaMode());
-		return new_material;
-	}
+        // Preserve old diffuse alpha mode or assert correct default blend mode as appropriate for the alpha channel content of the diffuse texture
+        //
+        new_material->setDiffuseAlphaMode(current_material.isNull() ? (isAlpha() ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE) : current_material->getDiffuseAlphaMode());
+        return new_material;
+    }
 
-	LLRender::eTexIndex getTextureChannelToEdit();
+    LLRender::eTexIndex getTextureChannelToEdit();
     LLRender::eTexIndex getTextureDropChannel();
     LLGLTFMaterial::TextureInfo getPBRDropChannel();
 
 protected:
-    void			navigateToTitleMedia(const std::string url);
-    bool			selectedMediaEditable();
-    void			clearMediaSettings();
-    void			updateMediaSettings();
-    void			updateMediaTitle();
-
-	void			getState();
-
-	void			sendTexture();			// applies and sends texture
-	void			sendTextureInfo();		// applies and sends texture scale, offset, etc.
-	void			sendColor();			// applies and sends color
-	void			sendAlpha();			// applies and sends transparency
-	void			sendBump(U32 bumpiness);				// applies and sends bump map
-	void			sendTexGen();				// applies and sends bump map
-	void			sendShiny(U32 shininess);			// applies and sends shininess
-	void			sendFullbright();		// applies and sends full bright
-
-	void			sendGlow();
+    void            navigateToTitleMedia(const std::string url);
+    bool            selectedMediaEditable();
+    void            clearMediaSettings();
+    void            updateMediaSettings();
+    void            updateMediaTitle();
+
+    void            getState();
+
+    void            sendTexture();          // applies and sends texture
+    void            sendTextureInfo();      // applies and sends texture scale, offset, etc.
+    void            sendColor();            // applies and sends color
+    void            sendAlpha();            // applies and sends transparency
+    void            sendBump(U32 bumpiness);                // applies and sends bump map
+    void            sendTexGen();               // applies and sends bump map
+    void            sendShiny(U32 shininess);           // applies and sends shininess
+    void            sendFullbright();       // applies and sends full bright
+
+    void            sendGlow();
     void            alignTestureLayer();
 
     void            updateCopyTexButton();
 
-    void 	onCommitPbr(const LLSD& data);
-    void 	onCancelPbr(const LLSD& data);
-    void 	onSelectPbr(const LLSD& data);
+    void    onCommitPbr(const LLSD& data);
+    void    onCancelPbr(const LLSD& data);
+    void    onSelectPbr(const LLSD& data);
     static BOOL onDragPbr(LLUICtrl* ctrl, LLInventoryItem* item);
 
-	// this function is to return TRUE if the drag should succeed.
-	static BOOL onDragTexture(LLUICtrl* ctrl, LLInventoryItem* item);
-
-	void 	onCommitTexture(const LLSD& data);
-	void 	onCancelTexture(const LLSD& data);
-	void 	onSelectTexture(const LLSD& data);
-	void 	onCommitSpecularTexture(const LLSD& data);
-	void 	onCancelSpecularTexture(const LLSD& data);
-	void 	onSelectSpecularTexture(const LLSD& data);
-	void 	onCommitNormalTexture(const LLSD& data);
-	void 	onCancelNormalTexture(const LLSD& data);
-	void 	onSelectNormalTexture(const LLSD& data);
-	void 	onCommitColor(const LLSD& data);
-	void 	onCommitShinyColor(const LLSD& data);
-	void 	onCommitAlpha(const LLSD& data);
-	void 	onCancelColor(const LLSD& data);
-	void 	onCancelShinyColor(const LLSD& data);
-	void 	onSelectColor(const LLSD& data);
-	void 	onSelectShinyColor(const LLSD& data);
-
-	void 	onCloseTexturePicker(const LLSD& data);
+    // this function is to return TRUE if the drag should succeed.
+    static BOOL onDragTexture(LLUICtrl* ctrl, LLInventoryItem* item);
+
+    void    onCommitTexture(const LLSD& data);
+    void    onCancelTexture(const LLSD& data);
+    void    onSelectTexture(const LLSD& data);
+    void    onCommitSpecularTexture(const LLSD& data);
+    void    onCancelSpecularTexture(const LLSD& data);
+    void    onSelectSpecularTexture(const LLSD& data);
+    void    onCommitNormalTexture(const LLSD& data);
+    void    onCancelNormalTexture(const LLSD& data);
+    void    onSelectNormalTexture(const LLSD& data);
+    void    onCommitColor(const LLSD& data);
+    void    onCommitShinyColor(const LLSD& data);
+    void    onCommitAlpha(const LLSD& data);
+    void    onCancelColor(const LLSD& data);
+    void    onCancelShinyColor(const LLSD& data);
+    void    onSelectColor(const LLSD& data);
+    void    onSelectShinyColor(const LLSD& data);
+
+    void    onCloseTexturePicker(const LLSD& data);
 
     static bool deleteMediaConfirm(const LLSD& notification, const LLSD& response);
     static bool multipleFacesSelectedConfirm(const LLSD& notification, const LLSD& response);
 
-	// Make UI reflect state of currently selected material (refresh)
-	// and UI mode (e.g. editing normal map v diffuse map)
-	//
-	// @param force_set_values forces spinners to set value even if they are focused
-	void updateUI(bool force_set_values = false);
-
-	// Convenience func to determine if all faces in selection have
-	// identical planar texgen settings during edits
-	// 
-	bool isIdenticalPlanarTexgen();
-
-	// Callback funcs for individual controls
-	//
-	static void		onCommitTextureInfo(LLUICtrl* ctrl, void* userdata);
-	static void		onCommitTextureScaleX(LLUICtrl* ctrl, void* userdata);
-	static void		onCommitTextureScaleY(LLUICtrl* ctrl, void* userdata);
-	static void		onCommitTextureRot(LLUICtrl* ctrl, void* userdata);
-	static void		onCommitTextureOffsetX(LLUICtrl* ctrl, void* userdata);
-	static void		onCommitTextureOffsetY(LLUICtrl* ctrl, void* userdata);
-
-	static void		onCommitMaterialBumpyScaleX(	LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialBumpyScaleY(	LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialBumpyRot(		LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialBumpyOffsetX(	LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialBumpyOffsetY(	LLUICtrl* ctrl, void* userdata);
-
-	static void		syncRepeatX(LLPanelFace* self, F32 scaleU);
-	static void		syncRepeatY(LLPanelFace* self, F32 scaleV);
-	static void		syncOffsetX(LLPanelFace* self, F32 offsetU);
-	static void		syncOffsetY(LLPanelFace* self, F32 offsetV);
-	static void 	syncMaterialRot(LLPanelFace* self, F32 rot, int te = -1);
-
-	static void		onCommitMaterialShinyScaleX(	LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialShinyScaleY(	LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialShinyRot(		LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialShinyOffsetX(	LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialShinyOffsetY(	LLUICtrl* ctrl, void* userdata);
-
-	static void		onCommitMaterialGloss(			LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialEnv(				LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialMaskCutoff(	LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialID( LLUICtrl* ctrl, void* userdata);
-
-	static void		onCommitMaterialsMedia(	LLUICtrl* ctrl, void* userdata);
-	static void		onCommitMaterialType(	LLUICtrl* ctrl, void* userdata);
-    static void		onCommitPbrType(LLUICtrl* ctrl, void* userdata);
-	static void 	onClickBtnEditMedia(LLUICtrl* ctrl, void* userdata);
-	static void 	onClickBtnDeleteMedia(LLUICtrl* ctrl, void* userdata);
-	static void 	onClickBtnAddMedia(LLUICtrl* ctrl, void* userdata);
-	static void		onCommitBump(				LLUICtrl* ctrl, void* userdata);
-	static void		onCommitTexGen(			LLUICtrl* ctrl, void* userdata);
-	static void		onCommitShiny(				LLUICtrl* ctrl, void* userdata);
-	static void		onCommitAlphaMode(		LLUICtrl* ctrl, void* userdata);
-	static void		onCommitFullbright(		LLUICtrl* ctrl, void* userdata);
-	static void     onCommitGlow(				LLUICtrl* ctrl, void *userdata);
-	static void		onCommitPlanarAlign(		LLUICtrl* ctrl, void* userdata);
-	static void		onCommitRepeatsPerMeter(	LLUICtrl* ctrl, void* userinfo);
-
-	void onClickBtnSelectSameTexture(const LLUICtrl* ctrl, const LLSD& user_data);
+    // Make UI reflect state of currently selected material (refresh)
+    // and UI mode (e.g. editing normal map v diffuse map)
+    //
+    // @param force_set_values forces spinners to set value even if they are focused
+    void updateUI(bool force_set_values = false);
+
+    // Convenience func to determine if all faces in selection have
+    // identical planar texgen settings during edits
+    //
+    bool isIdenticalPlanarTexgen();
+
+    // Callback funcs for individual controls
+    //
+    static void     onCommitTextureInfo(LLUICtrl* ctrl, void* userdata);
+    static void     onCommitTextureScaleX(LLUICtrl* ctrl, void* userdata);
+    static void     onCommitTextureScaleY(LLUICtrl* ctrl, void* userdata);
+    static void     onCommitTextureRot(LLUICtrl* ctrl, void* userdata);
+    static void     onCommitTextureOffsetX(LLUICtrl* ctrl, void* userdata);
+    static void     onCommitTextureOffsetY(LLUICtrl* ctrl, void* userdata);
+
+    static void     onCommitMaterialBumpyScaleX(    LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialBumpyScaleY(    LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialBumpyRot(       LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialBumpyOffsetX(   LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialBumpyOffsetY(   LLUICtrl* ctrl, void* userdata);
+
+    static void     syncRepeatX(LLPanelFace* self, F32 scaleU);
+    static void     syncRepeatY(LLPanelFace* self, F32 scaleV);
+    static void     syncOffsetX(LLPanelFace* self, F32 offsetU);
+    static void     syncOffsetY(LLPanelFace* self, F32 offsetV);
+    static void     syncMaterialRot(LLPanelFace* self, F32 rot, int te = -1);
+
+    static void     onCommitMaterialShinyScaleX(    LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialShinyScaleY(    LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialShinyRot(       LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialShinyOffsetX(   LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialShinyOffsetY(   LLUICtrl* ctrl, void* userdata);
+
+    static void     onCommitMaterialGloss(          LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialEnv(                LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialMaskCutoff( LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialID( LLUICtrl* ctrl, void* userdata);
+
+    static void     onCommitMaterialsMedia( LLUICtrl* ctrl, void* userdata);
+    static void     onCommitMaterialType(   LLUICtrl* ctrl, void* userdata);
+    static void     onCommitPbrType(LLUICtrl* ctrl, void* userdata);
+    static void     onClickBtnEditMedia(LLUICtrl* ctrl, void* userdata);
+    static void     onClickBtnDeleteMedia(LLUICtrl* ctrl, void* userdata);
+    static void     onClickBtnAddMedia(LLUICtrl* ctrl, void* userdata);
+    static void     onCommitBump(               LLUICtrl* ctrl, void* userdata);
+    static void     onCommitTexGen(         LLUICtrl* ctrl, void* userdata);
+    static void     onCommitShiny(              LLUICtrl* ctrl, void* userdata);
+    static void     onCommitAlphaMode(      LLUICtrl* ctrl, void* userdata);
+    static void     onCommitFullbright(     LLUICtrl* ctrl, void* userdata);
+    static void     onCommitGlow(               LLUICtrl* ctrl, void *userdata);
+    static void     onCommitPlanarAlign(        LLUICtrl* ctrl, void* userdata);
+    static void     onCommitRepeatsPerMeter(    LLUICtrl* ctrl, void* userinfo);
+
+    void onClickBtnSelectSameTexture(const LLUICtrl* ctrl, const LLSD& user_data);
 
     void            onCommitGLTFTextureScaleU(LLUICtrl* ctrl);
     void            onCommitGLTFTextureScaleV(LLUICtrl* ctrl);
@@ -248,11 +248,11 @@ class LLPanelFace : public LLPanel
     void            onCommitGLTFTextureOffsetU(LLUICtrl* ctrl);
     void            onCommitGLTFTextureOffsetV(LLUICtrl* ctrl);
 
-	static void		onClickAutoFix(void*);
-    static void		onAlignTexture(void*);
-    static void 	onClickBtnLoadInvPBR(void* userdata);
-    static void 	onClickBtnEditPBR(void* userdata);
-    static void 	onClickBtnSavePBR(void* userdata);
+    static void     onClickAutoFix(void*);
+    static void     onAlignTexture(void*);
+    static void     onClickBtnLoadInvPBR(void* userdata);
+    static void     onClickBtnEditPBR(void* userdata);
+    static void     onClickBtnSavePBR(void* userdata);
 
 public: // needs to be accessible to selection manager
     void            onCopyColor(); // records all selected faces
@@ -266,10 +266,10 @@ class LLPanelFace : public LLPanel
     void            menuDoToSelected(const LLSD& userdata);
     bool            menuEnableItem(const LLSD& userdata);
 
-	static F32     valueGlow(LLViewerObject* object, S32 face);
+    static F32     valueGlow(LLViewerObject* object, S32 face);
 
 public:
-	LLTextureCtrl*     mTextureCtrl      = nullptr;
+    LLTextureCtrl*     mTextureCtrl      = nullptr;
     LLTextureCtrl*     mShinyTextureCtrl = nullptr;
     LLTextureCtrl*     mBumpyTextureCtrl = nullptr;
     LLColorSwatchCtrl* mColorSwatch      = nullptr;
@@ -280,7 +280,7 @@ class LLPanelFace : public LLPanel
     LLComboBox* mComboShininess = nullptr;
     LLComboBox* mComboAlphaMode    = nullptr;
 
-	LLRadioGroup* mRadioMatType = nullptr;
+    LLRadioGroup* mRadioMatType = nullptr;
 
     LLCheckBoxCtrl* mCheckFullbright = nullptr;
 
@@ -289,200 +289,200 @@ class LLPanelFace : public LLPanel
 
     LLSpinCtrl* mCtrlGlow = nullptr;
 
-	LLSpinCtrl* mSpinGlossiness = nullptr;
+    LLSpinCtrl* mSpinGlossiness = nullptr;
     LLSpinCtrl* mSpinEnvironment = nullptr;
     LLSpinCtrl* mSpinMaskCutoff  = nullptr;
 
 private:
-	bool		isAlpha() { return mIsAlpha; }
-
-	// Convenience funcs to keep the visual flack to a minimum
-	//
-	LLUUID	getCurrentNormalMap();
-	LLUUID	getCurrentSpecularMap();
-	U32		getCurrentShininess();
-	U32		getCurrentBumpiness();
-	U8		getCurrentDiffuseAlphaMode();
-	U8		getCurrentAlphaMaskCutoff();
-	U8		getCurrentEnvIntensity();
-	U8		getCurrentGlossiness();
-	F32		getCurrentBumpyRot();
-	F32		getCurrentBumpyScaleU();
-	F32		getCurrentBumpyScaleV();
-	F32		getCurrentBumpyOffsetU();
-	F32		getCurrentBumpyOffsetV();
-	F32		getCurrentShinyRot();
-	F32		getCurrentShinyScaleU();
-	F32		getCurrentShinyScaleV();
-	F32		getCurrentShinyOffsetU();
-	F32		getCurrentShinyOffsetV();
+    bool        isAlpha() { return mIsAlpha; }
+
+    // Convenience funcs to keep the visual flack to a minimum
+    //
+    LLUUID  getCurrentNormalMap();
+    LLUUID  getCurrentSpecularMap();
+    U32     getCurrentShininess();
+    U32     getCurrentBumpiness();
+    U8      getCurrentDiffuseAlphaMode();
+    U8      getCurrentAlphaMaskCutoff();
+    U8      getCurrentEnvIntensity();
+    U8      getCurrentGlossiness();
+    F32     getCurrentBumpyRot();
+    F32     getCurrentBumpyScaleU();
+    F32     getCurrentBumpyScaleV();
+    F32     getCurrentBumpyOffsetU();
+    F32     getCurrentBumpyOffsetV();
+    F32     getCurrentShinyRot();
+    F32     getCurrentShinyScaleU();
+    F32     getCurrentShinyScaleV();
+    F32     getCurrentShinyOffsetU();
+    F32     getCurrentShinyOffsetV();
 
     LLComboBox *mComboMatMedia;
     LLMediaCtrl *mTitleMedia;
     LLTextBox *mTitleMediaText;
 
-	// Update visibility of controls to match current UI mode
-	// (e.g. materials vs media editing)
-	//
-	// Do NOT call updateUI from within this function.
-	//
-	void updateVisibility(LLViewerObject* objectp = nullptr);
-
-	// Hey look everyone, a type-safe alternative to copy and paste! :)
-	//
-
-	// Update material parameters by applying 'edit_func' to selected TEs
-	//
-	template<
-		typename DataType,
-		typename SetValueType,
-		void (LLMaterial::*MaterialEditFunc)(SetValueType data) >
-	static void edit(LLPanelFace* p, DataType data, int te = -1, const LLUUID &only_for_object_id = LLUUID())
-	{
-		LLMaterialEditFunctor< DataType, SetValueType, MaterialEditFunc > edit(data);
-		struct LLSelectedTEEditMaterial : public LLSelectedTEMaterialFunctor
-		{
-			LLSelectedTEEditMaterial(LLPanelFace* panel, LLMaterialEditFunctor< DataType, SetValueType, MaterialEditFunc >* editp, const LLUUID &only_for_object_id) : _panel(panel), _edit(editp), _only_for_object_id(only_for_object_id) {}
-			virtual ~LLSelectedTEEditMaterial() {};
-			virtual LLMaterialPtr apply(LLViewerObject* object, S32 face, LLTextureEntry* tep, LLMaterialPtr& current_material)
-			{
-				if (_edit && (_only_for_object_id.isNull() || _only_for_object_id == object->getID()))
-				{
-					LLMaterialPtr new_material = _panel->createDefaultMaterial(current_material);
-					llassert_always(new_material);
-
-					// Determine correct alpha mode for current diffuse texture
-					// (i.e. does it have an alpha channel that makes alpha mode useful)
-					//
-					// _panel->isAlpha() "lies" when one face has alpha and the rest do not (NORSPEC-329)
-					// need to get per-face answer to this question for sane alpha mode retention on updates.
-					//					
-					bool is_alpha_face = object->isImageAlphaBlended(face);
-
-					// need to keep this original answer for valid comparisons in logic below
-					//
-					U8 original_default_alpha_mode = is_alpha_face ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
-					
-					U8 default_alpha_mode = original_default_alpha_mode;
-
-					if (!current_material.isNull())
-					{
-						default_alpha_mode = current_material->getDiffuseAlphaMode();
-					}
-
-					// Insure we don't inherit the default of blend by accident...
-					// this will be stomped by a legit request to change the alpha mode by the apply() below
-					//
-					new_material->setDiffuseAlphaMode(default_alpha_mode);
-
-					// Do "It"!
-					//
-					_edit->apply(new_material);
-
-					U32		new_alpha_mode			= new_material->getDiffuseAlphaMode();
-					LLUUID	new_normal_map_id		= new_material->getNormalID();
-					LLUUID	new_spec_map_id			= new_material->getSpecularID();
-
-					if ((new_alpha_mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) && !is_alpha_face)
-					{
-						new_alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
-						new_material->setDiffuseAlphaMode(LLMaterial::DIFFUSE_ALPHA_MODE_NONE);
-					}
-
-					bool is_default_blend_mode		= (new_alpha_mode == original_default_alpha_mode);
-					bool is_need_material			= !is_default_blend_mode || !new_normal_map_id.isNull() || !new_spec_map_id.isNull();
-
-					if (!is_need_material)
-					{
-						LL_DEBUGS("Materials") << "Removing material from object " << object->getID() << " face " << face << LL_ENDL;
-						LLMaterialMgr::getInstance()->remove(object->getID(),face);
-						new_material = NULL;
-					}
-					else
-					{
-						LL_DEBUGS("Materials") << "Putting material on object " << object->getID() << " face " << face << ", material: " << new_material->asLLSD() << LL_ENDL;
-						LLMaterialMgr::getInstance()->put(object->getID(),face,*new_material);
-					}
-
-					object->setTEMaterialParams(face, new_material);
-					return new_material;
-				}
-				return NULL;
-			}
-			LLMaterialEditFunctor< DataType, SetValueType, MaterialEditFunc >*	_edit;
-			LLPanelFace *_panel;
-			const LLUUID & _only_for_object_id;
-		} editor(p, &edit, only_for_object_id);
-		LLSelectMgr::getInstance()->selectionSetMaterialParams(&editor, te);
-	}
-
-	template<
-		typename DataType,
-		typename ReturnType,
-		ReturnType (LLMaterial::* const MaterialGetFunc)() const  >
-	static void getTEMaterialValue(DataType& data_to_return, bool& identical,DataType default_value, bool has_tolerance = false, DataType tolerance = DataType())
-	{
-		DataType data_value;
-		struct GetTEMaterialVal : public LLSelectedTEGetFunctor<DataType>
-		{
-			GetTEMaterialVal(DataType default_value) : _default(default_value) {}
-			virtual ~GetTEMaterialVal() {}
-
-			DataType get(LLViewerObject* object, S32 face)
-			{
-				DataType ret = _default;
-				LLMaterialPtr material_ptr;
-				LLTextureEntry* tep = object ? object->getTE(face) : NULL;
-				if (tep)
-				{
-					material_ptr = tep->getMaterialParams();
-					if (!material_ptr.isNull())
-					{
-						ret = (material_ptr->*(MaterialGetFunc))();
-					}
-				}
-				return ret;
-			}
-			DataType _default;
-		} GetFunc(default_value);
-		identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &GetFunc, data_value, has_tolerance, tolerance);
-		data_to_return = data_value;
-	}
-
-	template<
-		typename DataType,
-		typename ReturnType, // some kids just have to different...
-		ReturnType (LLTextureEntry::* const TEGetFunc)() const >
-	static void getTEValue(DataType& data_to_return, bool& identical, DataType default_value, bool has_tolerance = false, DataType tolerance = DataType())
-	{
-		DataType data_value = DataType();
-		struct GetTEVal : public LLSelectedTEGetFunctor<DataType>
-		{
-			GetTEVal(DataType default_value) : _default(default_value) {}
-			virtual ~GetTEVal() {}
-
-			DataType get(LLViewerObject* object, S32 face) {
-				LLTextureEntry* tep = object ? object->getTE(face) : NULL;
-				return tep ? ((tep->*(TEGetFunc))()) : _default;
-			}
-			DataType _default;
-		} GetTEValFunc(default_value);
-		identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &GetTEValFunc, data_value, has_tolerance, tolerance );
-		data_to_return = data_value;
-	}
-
-	// Update vis and enabling of specific subsets of controls based on material params
-	// (e.g. hide the spec controls if no spec texture is applied)
-	//
-	void updateShinyControls(bool is_setting_texture = false, bool mess_with_combobox = false);
-	void updateBumpyControls(bool is_setting_texture = false, bool mess_with_combobox = false);
-	void updateAlphaControls();
-
-	/*
-	 * Checks whether the selected texture from the LLFloaterTexturePicker can be applied to the currently selected object.
-	 * If agent selects texture which is not allowed to be applied for the currently selected object,
-	 * all controls of the floater texture picker which allow to apply the texture will be disabled.
-	 */
+    // Update visibility of controls to match current UI mode
+    // (e.g. materials vs media editing)
+    //
+    // Do NOT call updateUI from within this function.
+    //
+    void updateVisibility(LLViewerObject* objectp = nullptr);
+
+    // Hey look everyone, a type-safe alternative to copy and paste! :)
+    //
+
+    // Update material parameters by applying 'edit_func' to selected TEs
+    //
+    template<
+        typename DataType,
+        typename SetValueType,
+        void (LLMaterial::*MaterialEditFunc)(SetValueType data) >
+    static void edit(LLPanelFace* p, DataType data, int te = -1, const LLUUID &only_for_object_id = LLUUID())
+    {
+        LLMaterialEditFunctor< DataType, SetValueType, MaterialEditFunc > edit(data);
+        struct LLSelectedTEEditMaterial : public LLSelectedTEMaterialFunctor
+        {
+            LLSelectedTEEditMaterial(LLPanelFace* panel, LLMaterialEditFunctor< DataType, SetValueType, MaterialEditFunc >* editp, const LLUUID &only_for_object_id) : _panel(panel), _edit(editp), _only_for_object_id(only_for_object_id) {}
+            virtual ~LLSelectedTEEditMaterial() {};
+            virtual LLMaterialPtr apply(LLViewerObject* object, S32 face, LLTextureEntry* tep, LLMaterialPtr& current_material)
+            {
+                if (_edit && (_only_for_object_id.isNull() || _only_for_object_id == object->getID()))
+                {
+                    LLMaterialPtr new_material = _panel->createDefaultMaterial(current_material);
+                    llassert_always(new_material);
+
+                    // Determine correct alpha mode for current diffuse texture
+                    // (i.e. does it have an alpha channel that makes alpha mode useful)
+                    //
+                    // _panel->isAlpha() "lies" when one face has alpha and the rest do not (NORSPEC-329)
+                    // need to get per-face answer to this question for sane alpha mode retention on updates.
+                    //
+                    bool is_alpha_face = object->isImageAlphaBlended(face);
+
+                    // need to keep this original answer for valid comparisons in logic below
+                    //
+                    U8 original_default_alpha_mode = is_alpha_face ? LLMaterial::DIFFUSE_ALPHA_MODE_BLEND : LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
+
+                    U8 default_alpha_mode = original_default_alpha_mode;
+
+                    if (!current_material.isNull())
+                    {
+                        default_alpha_mode = current_material->getDiffuseAlphaMode();
+                    }
+
+                    // Insure we don't inherit the default of blend by accident...
+                    // this will be stomped by a legit request to change the alpha mode by the apply() below
+                    //
+                    new_material->setDiffuseAlphaMode(default_alpha_mode);
+
+                    // Do "It"!
+                    //
+                    _edit->apply(new_material);
+
+                    U32     new_alpha_mode          = new_material->getDiffuseAlphaMode();
+                    LLUUID  new_normal_map_id       = new_material->getNormalID();
+                    LLUUID  new_spec_map_id         = new_material->getSpecularID();
+
+                    if ((new_alpha_mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND) && !is_alpha_face)
+                    {
+                        new_alpha_mode = LLMaterial::DIFFUSE_ALPHA_MODE_NONE;
+                        new_material->setDiffuseAlphaMode(LLMaterial::DIFFUSE_ALPHA_MODE_NONE);
+                    }
+
+                    bool is_default_blend_mode      = (new_alpha_mode == original_default_alpha_mode);
+                    bool is_need_material           = !is_default_blend_mode || !new_normal_map_id.isNull() || !new_spec_map_id.isNull();
+
+                    if (!is_need_material)
+                    {
+                        LL_DEBUGS("Materials") << "Removing material from object " << object->getID() << " face " << face << LL_ENDL;
+                        LLMaterialMgr::getInstance()->remove(object->getID(),face);
+                        new_material = NULL;
+                    }
+                    else
+                    {
+                        LL_DEBUGS("Materials") << "Putting material on object " << object->getID() << " face " << face << ", material: " << new_material->asLLSD() << LL_ENDL;
+                        LLMaterialMgr::getInstance()->put(object->getID(),face,*new_material);
+                    }
+
+                    object->setTEMaterialParams(face, new_material);
+                    return new_material;
+                }
+                return NULL;
+            }
+            LLMaterialEditFunctor< DataType, SetValueType, MaterialEditFunc >*  _edit;
+            LLPanelFace *_panel;
+            const LLUUID & _only_for_object_id;
+        } editor(p, &edit, only_for_object_id);
+        LLSelectMgr::getInstance()->selectionSetMaterialParams(&editor, te);
+    }
+
+    template<
+        typename DataType,
+        typename ReturnType,
+        ReturnType (LLMaterial::* const MaterialGetFunc)() const  >
+    static void getTEMaterialValue(DataType& data_to_return, bool& identical,DataType default_value, bool has_tolerance = false, DataType tolerance = DataType())
+    {
+        DataType data_value;
+        struct GetTEMaterialVal : public LLSelectedTEGetFunctor<DataType>
+        {
+            GetTEMaterialVal(DataType default_value) : _default(default_value) {}
+            virtual ~GetTEMaterialVal() {}
+
+            DataType get(LLViewerObject* object, S32 face)
+            {
+                DataType ret = _default;
+                LLMaterialPtr material_ptr;
+                LLTextureEntry* tep = object ? object->getTE(face) : NULL;
+                if (tep)
+                {
+                    material_ptr = tep->getMaterialParams();
+                    if (!material_ptr.isNull())
+                    {
+                        ret = (material_ptr->*(MaterialGetFunc))();
+                    }
+                }
+                return ret;
+            }
+            DataType _default;
+        } GetFunc(default_value);
+        identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &GetFunc, data_value, has_tolerance, tolerance);
+        data_to_return = data_value;
+    }
+
+    template<
+        typename DataType,
+        typename ReturnType, // some kids just have to different...
+        ReturnType (LLTextureEntry::* const TEGetFunc)() const >
+    static void getTEValue(DataType& data_to_return, bool& identical, DataType default_value, bool has_tolerance = false, DataType tolerance = DataType())
+    {
+        DataType data_value = DataType();
+        struct GetTEVal : public LLSelectedTEGetFunctor<DataType>
+        {
+            GetTEVal(DataType default_value) : _default(default_value) {}
+            virtual ~GetTEVal() {}
+
+            DataType get(LLViewerObject* object, S32 face) {
+                LLTextureEntry* tep = object ? object->getTE(face) : NULL;
+                return tep ? ((tep->*(TEGetFunc))()) : _default;
+            }
+            DataType _default;
+        } GetTEValFunc(default_value);
+        identical = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &GetTEValFunc, data_value, has_tolerance, tolerance );
+        data_to_return = data_value;
+    }
+
+    // Update vis and enabling of specific subsets of controls based on material params
+    // (e.g. hide the spec controls if no spec texture is applied)
+    //
+    void updateShinyControls(bool is_setting_texture = false, bool mess_with_combobox = false);
+    void updateBumpyControls(bool is_setting_texture = false, bool mess_with_combobox = false);
+    void updateAlphaControls();
+
+    /*
+     * Checks whether the selected texture from the LLFloaterTexturePicker can be applied to the currently selected object.
+     * If agent selects texture which is not allowed to be applied for the currently selected object,
+     * all controls of the floater texture picker which allow to apply the texture will be disabled.
+     */
     void onTextureSelectionChanged(LLInventoryItem* itemp);
     void onPbrSelectionChanged(LLInventoryItem* itemp);
 
@@ -494,13 +494,13 @@ class LLPanelFace : public LLPanel
 
     void setMaterialOverridesFromSelection();
 
-	LLButton* mBtnCopyColor = nullptr;
-	LLButton* mBtnPasteColor = nullptr;
-	LLButton* mBtnCopyTextures = nullptr;
-	LLButton* mBtnPasteTextures = nullptr;
+    LLButton* mBtnCopyColor = nullptr;
+    LLButton* mBtnPasteColor = nullptr;
+    LLButton* mBtnCopyTextures = nullptr;
+    LLButton* mBtnPasteTextures = nullptr;
+
+    bool mIsAlpha;
 
-	bool mIsAlpha;
-	
     LLSD            mClipboardParams;
 
     LLSD mMediaSettings;
@@ -543,17 +543,17 @@ class LLPanelFace : public LLPanel
     std::unique_ptr<PBRPickerObjectListener> mVOInventoryListener;
 
 public:
-	#if defined(DEF_GET_MAT_STATE)
-		#undef DEF_GET_MAT_STATE
-	#endif
+    #if defined(DEF_GET_MAT_STATE)
+        #undef DEF_GET_MAT_STATE
+    #endif
 
-	#if defined(DEF_GET_TE_STATE)
-		#undef DEF_GET_TE_STATE
-	#endif
+    #if defined(DEF_GET_TE_STATE)
+        #undef DEF_GET_TE_STATE
+    #endif
 
-	#if defined(DEF_EDIT_MAT_STATE)
-		DEF_EDIT_MAT_STATE
-	#endif
+    #if defined(DEF_EDIT_MAT_STATE)
+        DEF_EDIT_MAT_STATE
+    #endif
 
     // Accessors for selected TE material state
     //
@@ -579,74 +579,74 @@ class LLPanelFace : public LLPanel
             getTEValue< DataType, ReturnType, &LLTextureEntry::TexEntryMemberFunc >(data, identical, DefaultValue, has_tolerance, tolerance);   \
         }
 
-	class LLSelectedTEMaterial
-	{
-	public:
-		static void getCurrent(LLMaterialPtr& material_ptr, bool& identical_material);
-		static void getMaxSpecularRepeats(F32& repeats, bool& identical);
-		static void getMaxNormalRepeats(F32& repeats, bool& identical);
-		static void getCurrentDiffuseAlphaMode(U8& diffuse_alpha_mode, bool& identical, bool diffuse_texture_has_alpha);
-
-		DEF_GET_MAT_STATE(LLUUID,const LLUUID&,getNormalID,LLUUID::null, false, LLUUID::null)
-		DEF_GET_MAT_STATE(LLUUID,const LLUUID&,getSpecularID,LLUUID::null, false, LLUUID::null)
-		DEF_GET_MAT_STATE(F32,F32,getSpecularRepeatX,1.0f, true, 0.001f)
-		DEF_GET_MAT_STATE(F32,F32,getSpecularRepeatY,1.0f, true, 0.001f)
-		DEF_GET_MAT_STATE(F32,F32,getSpecularOffsetX,0.0f, true, 0.001f)
-		DEF_GET_MAT_STATE(F32,F32,getSpecularOffsetY,0.0f, true, 0.001f)
-		DEF_GET_MAT_STATE(F32,F32,getSpecularRotation,0.0f, true, 0.001f)
-
-		DEF_GET_MAT_STATE(F32,F32,getNormalRepeatX,1.0f, true, 0.001f)
-		DEF_GET_MAT_STATE(F32,F32,getNormalRepeatY,1.0f, true, 0.001f)
-		DEF_GET_MAT_STATE(F32,F32,getNormalOffsetX,0.0f, true, 0.001f)
-		DEF_GET_MAT_STATE(F32,F32,getNormalOffsetY,0.0f, true, 0.001f)
-		DEF_GET_MAT_STATE(F32,F32,getNormalRotation,0.0f, true, 0.001f)
-
-		DEF_EDIT_MAT_STATE(U8,U8,setDiffuseAlphaMode);
-		DEF_EDIT_MAT_STATE(U8,U8,setAlphaMaskCutoff);
-
-		DEF_EDIT_MAT_STATE(F32,F32,setNormalOffsetX);
-		DEF_EDIT_MAT_STATE(F32,F32,setNormalOffsetY);
-		DEF_EDIT_MAT_STATE(F32,F32,setNormalRepeatX);
-		DEF_EDIT_MAT_STATE(F32,F32,setNormalRepeatY);
-		DEF_EDIT_MAT_STATE(F32,F32,setNormalRotation);
-
-		DEF_EDIT_MAT_STATE(F32,F32,setSpecularOffsetX);
-		DEF_EDIT_MAT_STATE(F32,F32,setSpecularOffsetY);
-		DEF_EDIT_MAT_STATE(F32,F32,setSpecularRepeatX);
-		DEF_EDIT_MAT_STATE(F32,F32,setSpecularRepeatY);
-		DEF_EDIT_MAT_STATE(F32,F32,setSpecularRotation);
-
-		DEF_EDIT_MAT_STATE(U8,U8,setEnvironmentIntensity);
-		DEF_EDIT_MAT_STATE(U8,U8,setSpecularLightExponent);
-
-		DEF_EDIT_MAT_STATE(LLUUID,const LLUUID&,setNormalID);
-		DEF_EDIT_MAT_STATE(LLUUID,const LLUUID&,setSpecularID);
-		DEF_EDIT_MAT_STATE(LLColor4U,	const LLColor4U&,setSpecularLightColor);
-	};
-
-	class LLSelectedTE
-	{
-	public:
-		static void getFace(class LLFace*& face_to_return, bool& identical_face);
-		static void getImageFormat(LLGLenum& image_format_to_return, bool& identical_face);
-		static void getTexId(LLUUID& id, bool& identical);
+    class LLSelectedTEMaterial
+    {
+    public:
+        static void getCurrent(LLMaterialPtr& material_ptr, bool& identical_material);
+        static void getMaxSpecularRepeats(F32& repeats, bool& identical);
+        static void getMaxNormalRepeats(F32& repeats, bool& identical);
+        static void getCurrentDiffuseAlphaMode(U8& diffuse_alpha_mode, bool& identical, bool diffuse_texture_has_alpha);
+
+        DEF_GET_MAT_STATE(LLUUID,const LLUUID&,getNormalID,LLUUID::null, false, LLUUID::null)
+        DEF_GET_MAT_STATE(LLUUID,const LLUUID&,getSpecularID,LLUUID::null, false, LLUUID::null)
+        DEF_GET_MAT_STATE(F32,F32,getSpecularRepeatX,1.0f, true, 0.001f)
+        DEF_GET_MAT_STATE(F32,F32,getSpecularRepeatY,1.0f, true, 0.001f)
+        DEF_GET_MAT_STATE(F32,F32,getSpecularOffsetX,0.0f, true, 0.001f)
+        DEF_GET_MAT_STATE(F32,F32,getSpecularOffsetY,0.0f, true, 0.001f)
+        DEF_GET_MAT_STATE(F32,F32,getSpecularRotation,0.0f, true, 0.001f)
+
+        DEF_GET_MAT_STATE(F32,F32,getNormalRepeatX,1.0f, true, 0.001f)
+        DEF_GET_MAT_STATE(F32,F32,getNormalRepeatY,1.0f, true, 0.001f)
+        DEF_GET_MAT_STATE(F32,F32,getNormalOffsetX,0.0f, true, 0.001f)
+        DEF_GET_MAT_STATE(F32,F32,getNormalOffsetY,0.0f, true, 0.001f)
+        DEF_GET_MAT_STATE(F32,F32,getNormalRotation,0.0f, true, 0.001f)
+
+        DEF_EDIT_MAT_STATE(U8,U8,setDiffuseAlphaMode);
+        DEF_EDIT_MAT_STATE(U8,U8,setAlphaMaskCutoff);
+
+        DEF_EDIT_MAT_STATE(F32,F32,setNormalOffsetX);
+        DEF_EDIT_MAT_STATE(F32,F32,setNormalOffsetY);
+        DEF_EDIT_MAT_STATE(F32,F32,setNormalRepeatX);
+        DEF_EDIT_MAT_STATE(F32,F32,setNormalRepeatY);
+        DEF_EDIT_MAT_STATE(F32,F32,setNormalRotation);
+
+        DEF_EDIT_MAT_STATE(F32,F32,setSpecularOffsetX);
+        DEF_EDIT_MAT_STATE(F32,F32,setSpecularOffsetY);
+        DEF_EDIT_MAT_STATE(F32,F32,setSpecularRepeatX);
+        DEF_EDIT_MAT_STATE(F32,F32,setSpecularRepeatY);
+        DEF_EDIT_MAT_STATE(F32,F32,setSpecularRotation);
+
+        DEF_EDIT_MAT_STATE(U8,U8,setEnvironmentIntensity);
+        DEF_EDIT_MAT_STATE(U8,U8,setSpecularLightExponent);
+
+        DEF_EDIT_MAT_STATE(LLUUID,const LLUUID&,setNormalID);
+        DEF_EDIT_MAT_STATE(LLUUID,const LLUUID&,setSpecularID);
+        DEF_EDIT_MAT_STATE(LLColor4U,   const LLColor4U&,setSpecularLightColor);
+    };
+
+    class LLSelectedTE
+    {
+    public:
+        static void getFace(class LLFace*& face_to_return, bool& identical_face);
+        static void getImageFormat(LLGLenum& image_format_to_return, bool& identical_face);
+        static void getTexId(LLUUID& id, bool& identical);
         static void getPbrMaterialId(LLUUID& id, bool& identical, bool& has_pbr, bool& has_faces_without_pbr);
-		static void getObjectScaleS(F32& scale_s, bool& identical);
-		static void getObjectScaleT(F32& scale_t, bool& identical);
-		static void getMaxDiffuseRepeats(F32& repeats, bool& identical);
-
-		DEF_GET_TE_STATE(U8,U8,getBumpmap,0, false, 0)
-		DEF_GET_TE_STATE(U8,U8,getShiny,0, false, 0)
-		DEF_GET_TE_STATE(U8,U8,getFullbright,0, false, 0)
-		DEF_GET_TE_STATE(F32,F32,getRotation,0.0f, true, 0.001f)
-		DEF_GET_TE_STATE(F32,F32,getOffsetS,0.0f, true, 0.001f)
-		DEF_GET_TE_STATE(F32,F32,getOffsetT,0.0f, true, 0.001f)
-		DEF_GET_TE_STATE(F32,F32,getScaleS,1.0f, true, 0.001f)
-		DEF_GET_TE_STATE(F32,F32,getScaleT,1.0f, true, 0.001f)
-		DEF_GET_TE_STATE(F32,F32,getGlow,0.0f, true, 0.001f)
-		DEF_GET_TE_STATE(LLTextureEntry::e_texgen,LLTextureEntry::e_texgen,getTexGen,LLTextureEntry::TEX_GEN_DEFAULT, false, LLTextureEntry::TEX_GEN_DEFAULT)
-		DEF_GET_TE_STATE(LLColor4,const LLColor4&,getColor,LLColor4::white, false, LLColor4::black);
-	};
+        static void getObjectScaleS(F32& scale_s, bool& identical);
+        static void getObjectScaleT(F32& scale_t, bool& identical);
+        static void getMaxDiffuseRepeats(F32& repeats, bool& identical);
+
+        DEF_GET_TE_STATE(U8,U8,getBumpmap,0, false, 0)
+        DEF_GET_TE_STATE(U8,U8,getShiny,0, false, 0)
+        DEF_GET_TE_STATE(U8,U8,getFullbright,0, false, 0)
+        DEF_GET_TE_STATE(F32,F32,getRotation,0.0f, true, 0.001f)
+        DEF_GET_TE_STATE(F32,F32,getOffsetS,0.0f, true, 0.001f)
+        DEF_GET_TE_STATE(F32,F32,getOffsetT,0.0f, true, 0.001f)
+        DEF_GET_TE_STATE(F32,F32,getScaleS,1.0f, true, 0.001f)
+        DEF_GET_TE_STATE(F32,F32,getScaleT,1.0f, true, 0.001f)
+        DEF_GET_TE_STATE(F32,F32,getGlow,0.0f, true, 0.001f)
+        DEF_GET_TE_STATE(LLTextureEntry::e_texgen,LLTextureEntry::e_texgen,getTexGen,LLTextureEntry::TEX_GEN_DEFAULT, false, LLTextureEntry::TEX_GEN_DEFAULT)
+        DEF_GET_TE_STATE(LLColor4,const LLColor4&,getColor,LLColor4::white, false, LLColor4::black);
+    };
 };
 
 #endif
diff --git a/indra/newview/llpanelmaininventory.cpp b/indra/newview/llpanelmaininventory.cpp
index d3c9b606214e0a8bd56eb81fa48329f3f934ffb2..bf66ecedc5f0d73f94f1e8128cb83143a962fbda 100644
--- a/indra/newview/llpanelmaininventory.cpp
+++ b/indra/newview/llpanelmaininventory.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llpanelmaininventory.cpp
  * @brief Implementation of llpanelmaininventory.
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -77,29 +77,29 @@ static LLPanelInjector<LLPanelMainInventory> t_inventory("panel_main_inventory")
 class LLFloaterInventoryFinder final : public LLFloater
 {
 public:
-	LLFloaterInventoryFinder( LLPanelMainInventory* inventory_view);
-	virtual void draw();
-	/*virtual*/	BOOL	postBuild();
-	void changeFilter(LLInventoryFilter* filter);
-	void updateElementsFromFilter();
-	BOOL getCheckShowEmpty();
-	BOOL getCheckSinceLogoff();
-	U32 getDateSearchDirection();
-
-	void onCreatorSelfFilterCommit();
-	void onCreatorOtherFilterCommit();
-
-	static void onTimeAgo(LLUICtrl*, void *);
-	static void onCloseBtn(void* user_data);
-	static void selectAllTypes(void* user_data);
-	static void selectNoTypes(void* user_data);
+    LLFloaterInventoryFinder( LLPanelMainInventory* inventory_view);
+    virtual void draw();
+    /*virtual*/ BOOL    postBuild();
+    void changeFilter(LLInventoryFilter* filter);
+    void updateElementsFromFilter();
+    BOOL getCheckShowEmpty();
+    BOOL getCheckSinceLogoff();
+    U32 getDateSearchDirection();
+
+    void onCreatorSelfFilterCommit();
+    void onCreatorOtherFilterCommit();
+
+    static void onTimeAgo(LLUICtrl*, void *);
+    static void onCloseBtn(void* user_data);
+    static void selectAllTypes(void* user_data);
+    static void selectNoTypes(void* user_data);
 private:
-	LLPanelMainInventory*	mPanelMainInventory;
-	LLSpinCtrl*			mSpinSinceDays;
-	LLSpinCtrl*			mSpinSinceHours;
-	LLCheckBoxCtrl*		mCreatorSelf;
-	LLCheckBoxCtrl*		mCreatorOthers;
-	LLInventoryFilter*	mFilter;
+    LLPanelMainInventory*   mPanelMainInventory;
+    LLSpinCtrl*         mSpinSinceDays;
+    LLSpinCtrl*         mSpinSinceHours;
+    LLCheckBoxCtrl*     mCreatorSelf;
+    LLCheckBoxCtrl*     mCreatorOthers;
+    LLInventoryFilter*  mFilter;
 };
 
 ///----------------------------------------------------------------------------
@@ -107,15 +107,15 @@ class LLFloaterInventoryFinder final : public LLFloater
 ///----------------------------------------------------------------------------
 
 LLPanelMainInventory::LLPanelMainInventory(const LLPanel::Params& p)
-	: LLPanel(p),
-	  mActivePanel(NULL),
-	  mWornItemsPanel(NULL),
-	  mSavedFolderState(NULL),
-	  mFilterText(""),
-	  mMenuGearDefault(NULL),
-	  mMenuVisibility(NULL),
-	  mMenuAddHandle(),
-	  mNeedUploadCost(true),
+    : LLPanel(p),
+      mActivePanel(NULL),
+      mWornItemsPanel(NULL),
+      mSavedFolderState(NULL),
+      mFilterText(""),
+      mMenuGearDefault(NULL),
+      mMenuVisibility(NULL),
+      mMenuAddHandle(),
+      mNeedUploadCost(true),
       mMenuViewDefault(NULL),
       mSingleFolderMode(false),
       mForceShowInvLayout(false),
@@ -123,129 +123,129 @@ LLPanelMainInventory::LLPanelMainInventory(const LLPanel::Params& p)
       mListViewRootUpdatedConnection(),
       mGalleryRootUpdatedConnection()
 {
-	// Menu Callbacks (non contex menus)
-	mCommitCallbackRegistrar.add("Inventory.DoToSelected", boost::bind(&LLPanelMainInventory::doToSelected, this, _2));
-	mCommitCallbackRegistrar.add("Inventory.OpenAllFolders", boost::bind(&LLPanelMainInventory::openAllFolders, this));
-	mCommitCallbackRegistrar.add("Inventory.CloseAllFolders", boost::bind(&LLPanelMainInventory::closeAllFolders, this));
-	mCommitCallbackRegistrar.add("Inventory.EmptyTrash", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyTrash", LLFolderType::FT_TRASH));
-	mCommitCallbackRegistrar.add("Inventory.EmptyLostAndFound", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyLostAndFound", LLFolderType::FT_LOST_AND_FOUND));
-	mCommitCallbackRegistrar.add("Inventory.DoCreate", boost::bind(&LLPanelMainInventory::doCreate, this, _2));
-	mCommitCallbackRegistrar.add("Inventory.ShowFilters", boost::bind(&LLPanelMainInventory::toggleFindOptions, this));
-	mCommitCallbackRegistrar.add("Inventory.ResetFilters", boost::bind(&LLPanelMainInventory::resetFilters, this));
-	mCommitCallbackRegistrar.add("Inventory.SetSortBy", boost::bind(&LLPanelMainInventory::setSortBy, this, _2));
+    // Menu Callbacks (non contex menus)
+    mCommitCallbackRegistrar.add("Inventory.DoToSelected", boost::bind(&LLPanelMainInventory::doToSelected, this, _2));
+    mCommitCallbackRegistrar.add("Inventory.OpenAllFolders", boost::bind(&LLPanelMainInventory::openAllFolders, this));
+    mCommitCallbackRegistrar.add("Inventory.CloseAllFolders", boost::bind(&LLPanelMainInventory::closeAllFolders, this));
+    mCommitCallbackRegistrar.add("Inventory.EmptyTrash", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyTrash", LLFolderType::FT_TRASH));
+    mCommitCallbackRegistrar.add("Inventory.EmptyLostAndFound", boost::bind(&LLInventoryModel::emptyFolderType, &gInventory, "ConfirmEmptyLostAndFound", LLFolderType::FT_LOST_AND_FOUND));
+    mCommitCallbackRegistrar.add("Inventory.DoCreate", boost::bind(&LLPanelMainInventory::doCreate, this, _2));
+    mCommitCallbackRegistrar.add("Inventory.ShowFilters", boost::bind(&LLPanelMainInventory::toggleFindOptions, this));
+    mCommitCallbackRegistrar.add("Inventory.ResetFilters", boost::bind(&LLPanelMainInventory::resetFilters, this));
+    mCommitCallbackRegistrar.add("Inventory.SetSortBy", boost::bind(&LLPanelMainInventory::setSortBy, this, _2));
 
     mEnableCallbackRegistrar.add("Inventory.EnvironmentEnabled", [](LLUICtrl *, const LLSD &) { return LLPanelMainInventory::hasSettingsInventory(); });
     mEnableCallbackRegistrar.add("Inventory.MaterialsEnabled", [](LLUICtrl *, const LLSD &) { return LLPanelMainInventory::hasMaterialsInventory(); });
 
 
-	mSavedFolderState = new LLSaveFolderState();
-	mSavedFolderState->setApply(FALSE);
+    mSavedFolderState = new LLSaveFolderState();
+    mSavedFolderState->setApply(FALSE);
 }
 
 BOOL LLPanelMainInventory::postBuild()
 {
-	gInventory.addObserver(this);
-	
-	mFilterTabs = getChild<LLTabContainer>("inventory filter tabs");
-	mFilterTabs->setCommitCallback(boost::bind(&LLPanelMainInventory::onFilterSelected, this));
-	
+    gInventory.addObserver(this);
+
+    mFilterTabs = getChild<LLTabContainer>("inventory filter tabs");
+    mFilterTabs->setCommitCallback(boost::bind(&LLPanelMainInventory::onFilterSelected, this));
+
     mCounterCtrl = getChild<LLUICtrl>("ItemcountText");
-    
-	//panel->getFilter().markDefault();
-
-	// Set up the default inv. panel/filter settings.
-	mActivePanel = getChild<LLInventoryPanel>(ALL_ITEMS);
-	if (mActivePanel)
-	{
-		// "All Items" is the previous only view, so it gets the InventorySortOrder
-		mActivePanel->setSortOrder(gSavedSettings.getU32(LLInventoryPanel::DEFAULT_SORT_ORDER));
-		mActivePanel->getFilter().markDefault();
-		mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
-		mActivePanel->setSelectCallback(boost::bind(&LLPanelMainInventory::onSelectionChange, this, mActivePanel, _1, _2));
-		mResortActivePanel = true;
-	}
-	LLInventoryPanel* recent_items_panel = getChild<LLInventoryPanel>(RECENT_ITEMS);
-	if (recent_items_panel)
-	{
-		// assign default values until we will be sure that we have setting to restore
-		recent_items_panel->setSinceLogoff(TRUE);
-		recent_items_panel->setSortOrder(LLInventoryFilter::SO_DATE);
-		recent_items_panel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
-		LLInventoryFilter& recent_filter = recent_items_panel->getFilter();
-		recent_filter.setFilterObjectTypes(recent_filter.getFilterObjectTypes() & ~(0x1 << LLInventoryType::IT_CATEGORY));
-		recent_filter.setEmptyLookupMessage("InventoryNoMatchingRecentItems");
-		recent_filter.markDefault();
-		recent_items_panel->setSelectCallback(boost::bind(&LLPanelMainInventory::onSelectionChange, this, recent_items_panel, _1, _2));
-	}
-
-	mWornItemsPanel = getChild<LLInventoryPanel>(WORN_ITEMS);
-	if (mWornItemsPanel)
-	{
-		U32 filter_types = 0x0;
-		filter_types |= 0x1 << LLInventoryType::IT_WEARABLE;
-		filter_types |= 0x1 << LLInventoryType::IT_ATTACHMENT;
-		filter_types |= 0x1 << LLInventoryType::IT_OBJECT;
-		mWornItemsPanel->setFilterTypes(filter_types);
-		mWornItemsPanel->setFilterWorn();
-		mWornItemsPanel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
-		mWornItemsPanel->setFilterLinks(LLInventoryFilter::FILTERLINK_EXCLUDE_LINKS);
-		LLInventoryFilter& worn_filter = mWornItemsPanel->getFilter();
-		worn_filter.setFilterCategoryTypes(worn_filter.getFilterCategoryTypes() | (1ULL << LLFolderType::FT_INBOX));
-		worn_filter.markDefault();
-		mWornItemsPanel->setSelectCallback(boost::bind(&LLPanelMainInventory::onSelectionChange, this, mWornItemsPanel, _1, _2));
-	}
-	mSearchTypeCombo  = getChild<LLComboBox>("search_type");
-	if(mSearchTypeCombo)
-	{
-		mSearchTypeCombo->setCommitCallback(boost::bind(&LLPanelMainInventory::onSelectSearchType, this));
-	}
-	// Now load the stored settings from disk, if available.
-	std::string filterSaveName(gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, FILTERS_FILENAME));
-	LL_INFOS("Inventory") << "LLPanelMainInventory::init: reading from " << filterSaveName << LL_ENDL;
-	llifstream file(filterSaveName.c_str());
-	LLSD savedFilterState;
-	if (file.is_open())
-	{
-		LLSDSerialize::fromXML(savedFilterState, file);
-		file.close();
-
-		// Load the persistent "Recent Items" settings.
-		// Note that the "All Items" settings do not persist.
-		if(recent_items_panel)
-		{
-			if(savedFilterState.has(recent_items_panel->getFilter().getName()))
-			{
-				LLSD recent_items = savedFilterState.get(
-					recent_items_panel->getFilter().getName());
-				LLInventoryFilter::Params p;
-				LLParamSDParser parser;
-				parser.readSD(recent_items, p);
-				recent_items_panel->getFilter().fromParams(p);
-				recent_items_panel->setSortOrder(gSavedSettings.getU32(LLInventoryPanel::RECENTITEMS_SORT_ORDER));
-			}
-		}
-		if(mActivePanel)
-		{
-			if(savedFilterState.has(mActivePanel->getFilter().getName()))
-			{
-				LLSD items = savedFilterState.get(mActivePanel->getFilter().getName());
-				LLInventoryFilter::Params p;
-				LLParamSDParser parser;
-				parser.readSD(items, p);
-				mActivePanel->getFilter().setSearchVisibilityTypes(p);
-			}
-		}
-
-	}
-
-	mFilterEditor = getChild<LLFilterEditor>("inventory search editor");
-	if (mFilterEditor)
-	{
-		mFilterEditor->setCommitCallback(boost::bind(&LLPanelMainInventory::onFilterEdit, this, _2));
-	}
-
-	mGearMenuButton = getChild<LLMenuButton>("options_gear_btn");
-	mVisibilityMenuButton = getChild<LLMenuButton>("options_visibility_btn");
+
+    //panel->getFilter().markDefault();
+
+    // Set up the default inv. panel/filter settings.
+    mActivePanel = getChild<LLInventoryPanel>(ALL_ITEMS);
+    if (mActivePanel)
+    {
+        // "All Items" is the previous only view, so it gets the InventorySortOrder
+        mActivePanel->setSortOrder(gSavedSettings.getU32(LLInventoryPanel::DEFAULT_SORT_ORDER));
+        mActivePanel->getFilter().markDefault();
+        mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
+        mActivePanel->setSelectCallback(boost::bind(&LLPanelMainInventory::onSelectionChange, this, mActivePanel, _1, _2));
+        mResortActivePanel = true;
+    }
+    LLInventoryPanel* recent_items_panel = getChild<LLInventoryPanel>(RECENT_ITEMS);
+    if (recent_items_panel)
+    {
+        // assign default values until we will be sure that we have setting to restore
+        recent_items_panel->setSinceLogoff(TRUE);
+        recent_items_panel->setSortOrder(LLInventoryFilter::SO_DATE);
+        recent_items_panel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
+        LLInventoryFilter& recent_filter = recent_items_panel->getFilter();
+        recent_filter.setFilterObjectTypes(recent_filter.getFilterObjectTypes() & ~(0x1 << LLInventoryType::IT_CATEGORY));
+        recent_filter.setEmptyLookupMessage("InventoryNoMatchingRecentItems");
+        recent_filter.markDefault();
+        recent_items_panel->setSelectCallback(boost::bind(&LLPanelMainInventory::onSelectionChange, this, recent_items_panel, _1, _2));
+    }
+
+    mWornItemsPanel = getChild<LLInventoryPanel>(WORN_ITEMS);
+    if (mWornItemsPanel)
+    {
+        U32 filter_types = 0x0;
+        filter_types |= 0x1 << LLInventoryType::IT_WEARABLE;
+        filter_types |= 0x1 << LLInventoryType::IT_ATTACHMENT;
+        filter_types |= 0x1 << LLInventoryType::IT_OBJECT;
+        mWornItemsPanel->setFilterTypes(filter_types);
+        mWornItemsPanel->setFilterWorn();
+        mWornItemsPanel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
+        mWornItemsPanel->setFilterLinks(LLInventoryFilter::FILTERLINK_EXCLUDE_LINKS);
+        LLInventoryFilter& worn_filter = mWornItemsPanel->getFilter();
+        worn_filter.setFilterCategoryTypes(worn_filter.getFilterCategoryTypes() | (1ULL << LLFolderType::FT_INBOX));
+        worn_filter.markDefault();
+        mWornItemsPanel->setSelectCallback(boost::bind(&LLPanelMainInventory::onSelectionChange, this, mWornItemsPanel, _1, _2));
+    }
+    mSearchTypeCombo  = getChild<LLComboBox>("search_type");
+    if(mSearchTypeCombo)
+    {
+        mSearchTypeCombo->setCommitCallback(boost::bind(&LLPanelMainInventory::onSelectSearchType, this));
+    }
+    // Now load the stored settings from disk, if available.
+    std::string filterSaveName(gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, FILTERS_FILENAME));
+    LL_INFOS("Inventory") << "LLPanelMainInventory::init: reading from " << filterSaveName << LL_ENDL;
+    llifstream file(filterSaveName.c_str());
+    LLSD savedFilterState;
+    if (file.is_open())
+    {
+        LLSDSerialize::fromXML(savedFilterState, file);
+        file.close();
+
+        // Load the persistent "Recent Items" settings.
+        // Note that the "All Items" settings do not persist.
+        if(recent_items_panel)
+        {
+            if(savedFilterState.has(recent_items_panel->getFilter().getName()))
+            {
+                LLSD recent_items = savedFilterState.get(
+                    recent_items_panel->getFilter().getName());
+                LLInventoryFilter::Params p;
+                LLParamSDParser parser;
+                parser.readSD(recent_items, p);
+                recent_items_panel->getFilter().fromParams(p);
+                recent_items_panel->setSortOrder(gSavedSettings.getU32(LLInventoryPanel::RECENTITEMS_SORT_ORDER));
+            }
+        }
+        if(mActivePanel)
+        {
+            if(savedFilterState.has(mActivePanel->getFilter().getName()))
+            {
+                LLSD items = savedFilterState.get(mActivePanel->getFilter().getName());
+                LLInventoryFilter::Params p;
+                LLParamSDParser parser;
+                parser.readSD(items, p);
+                mActivePanel->getFilter().setSearchVisibilityTypes(p);
+            }
+        }
+
+    }
+
+    mFilterEditor = getChild<LLFilterEditor>("inventory search editor");
+    if (mFilterEditor)
+    {
+        mFilterEditor->setCommitCallback(boost::bind(&LLPanelMainInventory::onFilterEdit, this, _2));
+    }
+
+    mGearMenuButton = getChild<LLMenuButton>("options_gear_btn");
+    mVisibilityMenuButton = getChild<LLMenuButton>("options_visibility_btn");
     mViewMenuButton = getChild<LLMenuButton>("view_btn");
 
     mBackBtn = getChild<LLButton>("back_btn");
@@ -275,73 +275,73 @@ BOOL LLPanelMainInventory::postBuild()
     mGalleryRootUpdatedConnection = mCombinationGalleryPanel->setRootChangedCallback(boost::bind(&LLPanelMainInventory::onCombinationRootChanged, this, true));
     mCombinationGalleryPanel->setSelectionChangeCallback(boost::bind(&LLPanelMainInventory::onCombinationGallerySelectionChanged, this, _1));
 
-	initListCommandsHandlers();
+    initListCommandsHandlers();
 
-	const std::string sound_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getSoundUploadCost());
-	const std::string animation_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getAnimationUploadCost());
+    const std::string sound_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getSoundUploadCost());
+    const std::string animation_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getAnimationUploadCost());
 
-	LLMenuGL* menu = (LLMenuGL*)mMenuAddHandle.get();
-	if (menu)
-	{
-		menu->getChild<LLMenuItemGL>("Upload Sound")->setLabelArg("[COST]", sound_upload_cost_str);
-		menu->getChild<LLMenuItemGL>("Upload Animation")->setLabelArg("[COST]", animation_upload_cost_str);
-	}
+    LLMenuGL* menu = (LLMenuGL*)mMenuAddHandle.get();
+    if (menu)
+    {
+        menu->getChild<LLMenuItemGL>("Upload Sound")->setLabelArg("[COST]", sound_upload_cost_str);
+        menu->getChild<LLMenuItemGL>("Upload Animation")->setLabelArg("[COST]", animation_upload_cost_str);
+    }
 
-	// Trigger callback for focus received so we can deselect items in inbox/outbox
-	LLFocusableElement::setFocusReceivedCallback(boost::bind(&LLPanelMainInventory::onFocusReceived, this));
+    // Trigger callback for focus received so we can deselect items in inbox/outbox
+    LLFocusableElement::setFocusReceivedCallback(boost::bind(&LLPanelMainInventory::onFocusReceived, this));
 
-	return TRUE;
+    return TRUE;
 }
 
 // Destroys the object
 LLPanelMainInventory::~LLPanelMainInventory( void )
 {
-	// Save the filters state.
-	// Some params types cannot be saved this way
-	// for example, LLParamSDParser doesn't know about U64,
-	// so some FilterOps params should be revised.
-	LLSD filterRoot;
-	LLInventoryPanel* all_items_panel = getChild<LLInventoryPanel>(ALL_ITEMS);
-	if (all_items_panel)
-	{
-		LLSD filterState;
-		LLInventoryPanel::InventoryState p;
-		all_items_panel->getFilter().toParams(p.filter);
-		all_items_panel->getRootViewModel().getSorter().toParams(p.sort);
-		if (p.validateBlock(false))
-		{
-			LLParamSDParser().writeSD(filterState, p);
-			filterRoot[all_items_panel->getName()] = filterState;
-		}
-	}
-
-	LLInventoryPanel* panel = findChild<LLInventoryPanel>(RECENT_ITEMS);
-	if (panel)
-	{
-		LLSD filterState;
-		LLInventoryPanel::InventoryState p;
-		panel->getFilter().toParams(p.filter);
-		panel->getRootViewModel().getSorter().toParams(p.sort);
-		if (p.validateBlock(false))
-		{
-			LLParamSDParser().writeSD(filterState, p);
-			filterRoot[panel->getName()] = filterState;
-		}
-	}
-
-	std::string filterSaveName(gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, FILTERS_FILENAME));
-	llofstream filtersFile(filterSaveName.c_str());
-	if(!LLSDSerialize::toPrettyXML(filterRoot, filtersFile))
-	{
-		LL_WARNS() << "Could not write to filters save file " << filterSaveName << LL_ENDL;
-	}
-	else
-    {
-		filtersFile.close();
-    }
-    
-	gInventory.removeObserver(this);
-	delete mSavedFolderState;
+    // Save the filters state.
+    // Some params types cannot be saved this way
+    // for example, LLParamSDParser doesn't know about U64,
+    // so some FilterOps params should be revised.
+    LLSD filterRoot;
+    LLInventoryPanel* all_items_panel = getChild<LLInventoryPanel>(ALL_ITEMS);
+    if (all_items_panel)
+    {
+        LLSD filterState;
+        LLInventoryPanel::InventoryState p;
+        all_items_panel->getFilter().toParams(p.filter);
+        all_items_panel->getRootViewModel().getSorter().toParams(p.sort);
+        if (p.validateBlock(false))
+        {
+            LLParamSDParser().writeSD(filterState, p);
+            filterRoot[all_items_panel->getName()] = filterState;
+        }
+    }
+
+    LLInventoryPanel* panel = findChild<LLInventoryPanel>(RECENT_ITEMS);
+    if (panel)
+    {
+        LLSD filterState;
+        LLInventoryPanel::InventoryState p;
+        panel->getFilter().toParams(p.filter);
+        panel->getRootViewModel().getSorter().toParams(p.sort);
+        if (p.validateBlock(false))
+        {
+            LLParamSDParser().writeSD(filterState, p);
+            filterRoot[panel->getName()] = filterState;
+        }
+    }
+
+    std::string filterSaveName(gDirUtilp->getExpandedFilename(LL_PATH_PER_SL_ACCOUNT, FILTERS_FILENAME));
+    llofstream filtersFile(filterSaveName.c_str());
+    if(!LLSDSerialize::toPrettyXML(filterRoot, filtersFile))
+    {
+        LL_WARNS() << "Could not write to filters save file " << filterSaveName << LL_ENDL;
+    }
+    else
+    {
+        filtersFile.close();
+    }
+
+    gInventory.removeObserver(this);
+    delete mSavedFolderState;
 
     auto menu = mMenuAddHandle.get();
     if(menu)
@@ -362,57 +362,57 @@ LLPanelMainInventory::~LLPanelMainInventory( void )
 
 LLInventoryPanel* LLPanelMainInventory::getAllItemsPanel()
 {
-	return  getChild<LLInventoryPanel>(ALL_ITEMS);
+    return  getChild<LLInventoryPanel>(ALL_ITEMS);
 }
 
 void LLPanelMainInventory::selectAllItemsPanel()
 {
-	mFilterTabs->selectFirstTab();
+    mFilterTabs->selectFirstTab();
 }
 
 bool LLPanelMainInventory::isRecentItemsPanelSelected()
 {
-	return (RECENT_ITEMS == getActivePanel()->getName());
+    return (RECENT_ITEMS == getActivePanel()->getName());
 }
 
 void LLPanelMainInventory::startSearch()
 {
-	// this forces focus to line editor portion of search editor
-	if (mFilterEditor)
-	{
-		mFilterEditor->focusFirstItem(TRUE);
-	}
+    // this forces focus to line editor portion of search editor
+    if (mFilterEditor)
+    {
+        mFilterEditor->focusFirstItem(TRUE);
+    }
 }
 
 BOOL LLPanelMainInventory::handleKeyHere(KEY key, MASK mask)
 {
-	LLFolderView* root_folder = mActivePanel ? mActivePanel->getRootFolder() : NULL;
-	if (root_folder)
-	{
-		// first check for user accepting current search results
-		if (mFilterEditor 
-			&& mFilterEditor->hasFocus()
-		    && (key == KEY_RETURN 
-		    	|| key == KEY_DOWN)
-		    && mask == MASK_NONE)
-		{
-			// move focus to inventory proper
-			mActivePanel->setFocus(TRUE);
-			root_folder->scrollToShowSelection();
-			return TRUE;
-		}
-
-		if (mActivePanel->hasFocus() && key == KEY_UP)
-		{
-			startSearch();
-		}
+    LLFolderView* root_folder = mActivePanel ? mActivePanel->getRootFolder() : NULL;
+    if (root_folder)
+    {
+        // first check for user accepting current search results
+        if (mFilterEditor
+            && mFilterEditor->hasFocus()
+            && (key == KEY_RETURN
+                || key == KEY_DOWN)
+            && mask == MASK_NONE)
+        {
+            // move focus to inventory proper
+            mActivePanel->setFocus(TRUE);
+            root_folder->scrollToShowSelection();
+            return TRUE;
+        }
+
+        if (mActivePanel->hasFocus() && key == KEY_UP)
+        {
+            startSearch();
+        }
         if(mSingleFolderMode && key == KEY_LEFT)
         {
             onBackFolderClicked();
         }
-	}
+    }
 
-	return LLPanel::handleKeyHere(key, mask);
+    return LLPanel::handleKeyHere(key, mask);
 
 }
 
@@ -421,17 +421,17 @@ BOOL LLPanelMainInventory::handleKeyHere(KEY key, MASK mask)
 
 void LLPanelMainInventory::doToSelected(const LLSD& userdata)
 {
-	getPanel()->doToSelected(userdata);
+    getPanel()->doToSelected(userdata);
 }
 
 void LLPanelMainInventory::openAllFolders()
 {
-	getPanel()->getRootFolder()->openAllFolders();
+    getPanel()->getRootFolder()->openAllFolders();
 }
 
 void LLPanelMainInventory::closeAllFolders()
 {
-	getPanel()->getRootFolder()->closeAllFolders();
+    getPanel()->getRootFolder()->closeAllFolders();
 }
 
 S32 get_instance_num()
@@ -446,13 +446,13 @@ LLFloaterSidePanelContainer* LLPanelMainInventory::newWindow()
 {
     S32 instance_num = get_instance_num();
 
-	if (!gAgentCamera.cameraMouselook())
-	{
+    if (!gAgentCamera.cameraMouselook())
+    {
         LLFloaterSidePanelContainer* floater = LLFloaterReg::showTypedInstance<LLFloaterSidePanelContainer>("inventory", LLSD(instance_num));
         LLSidepanelInventory* sidepanel_inventory = floater->findChild<LLSidepanelInventory>("main_panel");
         sidepanel_inventory->initInventoryViews();
-		return floater;
-	}
+        return floater;
+    }
     return NULL;
 }
 
@@ -482,7 +482,7 @@ void LLPanelMainInventory::newFolderWindow(LLUUID folder_id, LLUUID item_to_sele
             }
         }
     }
-    
+
     S32 instance_num = get_instance_num();
 
     LLFloaterSidePanelContainer* inventory_container = LLFloaterReg::showTypedInstance<LLFloaterSidePanelContainer>("inventory", LLSD(instance_num));
@@ -510,7 +510,7 @@ void LLPanelMainInventory::newFolderWindow(LLUUID folder_id, LLUUID item_to_sele
 
 void LLPanelMainInventory::doCreate(const LLSD& userdata)
 {
-	reset_inventory_filter();
+    reset_inventory_filter();
     if(mSingleFolderMode)
     {
         if(isListViewMode() || isCombinationViewMode())
@@ -571,14 +571,14 @@ void LLPanelMainInventory::doCreate(const LLSD& userdata)
 
 void LLPanelMainInventory::resetFilters()
 {
-	LLFloaterInventoryFinder *finder = getFinder();
-	getCurrentFilter().resetDefault();
-	if (finder)
-	{
-		finder->updateElementsFromFilter();
-	}
+    LLFloaterInventoryFinder *finder = getFinder();
+    getCurrentFilter().resetDefault();
+    if (finder)
+    {
+        finder->updateElementsFromFilter();
+    }
 
-	setFilterTextFromFilter();
+    setFilterTextFromFilter();
 }
 
 void LLPanelMainInventory::resetAllItemsFilters()
@@ -606,44 +606,44 @@ void LLPanelMainInventory::findLinks(const LLUUID& item_id, const std::string& i
 
 void LLPanelMainInventory::setSortBy(const LLSD& userdata)
 {
-	U32 sort_order_mask = getActivePanel()->getSortOrder();
-	std::string sort_type = userdata.asString();
-	if (sort_type == "name")
-	{
-		sort_order_mask &= ~LLInventoryFilter::SO_DATE;
-	}
-	else if (sort_type == "date")
-	{
-		sort_order_mask |= LLInventoryFilter::SO_DATE;
-	}
-	else if (sort_type == "foldersalwaysbyname")
-	{
-		if ( sort_order_mask & LLInventoryFilter::SO_FOLDERS_BY_NAME )
-		{
-			sort_order_mask &= ~LLInventoryFilter::SO_FOLDERS_BY_NAME;
-		}
-		else
-		{
-			sort_order_mask |= LLInventoryFilter::SO_FOLDERS_BY_NAME;
-		}
-	}
-	else if (sort_type == "systemfolderstotop")
-	{
-		if ( sort_order_mask & LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP )
-		{
-			sort_order_mask &= ~LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
-		}
-		else
-		{
-			sort_order_mask |= LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
-		}
-	}
+    U32 sort_order_mask = getActivePanel()->getSortOrder();
+    std::string sort_type = userdata.asString();
+    if (sort_type == "name")
+    {
+        sort_order_mask &= ~LLInventoryFilter::SO_DATE;
+    }
+    else if (sort_type == "date")
+    {
+        sort_order_mask |= LLInventoryFilter::SO_DATE;
+    }
+    else if (sort_type == "foldersalwaysbyname")
+    {
+        if ( sort_order_mask & LLInventoryFilter::SO_FOLDERS_BY_NAME )
+        {
+            sort_order_mask &= ~LLInventoryFilter::SO_FOLDERS_BY_NAME;
+        }
+        else
+        {
+            sort_order_mask |= LLInventoryFilter::SO_FOLDERS_BY_NAME;
+        }
+    }
+    else if (sort_type == "systemfolderstotop")
+    {
+        if ( sort_order_mask & LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP )
+        {
+            sort_order_mask &= ~LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
+        }
+        else
+        {
+            sort_order_mask |= LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
+        }
+    }
     if(mSingleFolderMode && !isListViewMode())
     {
         mCombinationGalleryPanel->setSortOrder(sort_order_mask, true);
     }
 
-	getActivePanel()->setSortOrder(sort_order_mask);
+    getActivePanel()->setSortOrder(sort_order_mask);
     if (isRecentItemsPanelSelected())
     {
         gSavedSettings.setU32("RecentItemsSortOrder", sort_order_mask);
@@ -656,23 +656,23 @@ void LLPanelMainInventory::setSortBy(const LLSD& userdata)
 
 void LLPanelMainInventory::onSelectSearchType()
 {
-	std::string new_type = mSearchTypeCombo->getValue();
-	if (new_type == "search_by_name")
-	{
-		setSearchType(LLInventoryFilter::SEARCHTYPE_NAME);
-	}
-	if (new_type == "search_by_creator")
-	{
-		setSearchType(LLInventoryFilter::SEARCHTYPE_CREATOR);
-	}
-	if (new_type == "search_by_description")
-	{
-		setSearchType(LLInventoryFilter::SEARCHTYPE_DESCRIPTION);
-	}
-	if (new_type == "search_by_UUID")
-	{
-		setSearchType(LLInventoryFilter::SEARCHTYPE_UUID);
-	}
+    std::string new_type = mSearchTypeCombo->getValue();
+    if (new_type == "search_by_name")
+    {
+        setSearchType(LLInventoryFilter::SEARCHTYPE_NAME);
+    }
+    if (new_type == "search_by_creator")
+    {
+        setSearchType(LLInventoryFilter::SEARCHTYPE_CREATOR);
+    }
+    if (new_type == "search_by_description")
+    {
+        setSearchType(LLInventoryFilter::SEARCHTYPE_DESCRIPTION);
+    }
+    if (new_type == "search_by_UUID")
+    {
+        setSearchType(LLInventoryFilter::SEARCHTYPE_UUID);
+    }
 }
 
 void LLPanelMainInventory::setSearchType(LLInventoryFilter::ESearchType type)
@@ -709,70 +709,70 @@ void LLPanelMainInventory::updateSearchTypeCombo()
         search_type = getActivePanel()->getSearchType();
     }
 
-	switch(search_type)
-	{
-		case LLInventoryFilter::SEARCHTYPE_CREATOR:
-			mSearchTypeCombo->setValue("search_by_creator");
-			break;
-		case LLInventoryFilter::SEARCHTYPE_DESCRIPTION:
-			mSearchTypeCombo->setValue("search_by_description");
-			break;
-		case LLInventoryFilter::SEARCHTYPE_UUID:
-			mSearchTypeCombo->setValue("search_by_UUID");
-			break;
-		case LLInventoryFilter::SEARCHTYPE_NAME:
-		default:
-			mSearchTypeCombo->setValue("search_by_name");
-			break;
-	}
+    switch(search_type)
+    {
+        case LLInventoryFilter::SEARCHTYPE_CREATOR:
+            mSearchTypeCombo->setValue("search_by_creator");
+            break;
+        case LLInventoryFilter::SEARCHTYPE_DESCRIPTION:
+            mSearchTypeCombo->setValue("search_by_description");
+            break;
+        case LLInventoryFilter::SEARCHTYPE_UUID:
+            mSearchTypeCombo->setValue("search_by_UUID");
+            break;
+        case LLInventoryFilter::SEARCHTYPE_NAME:
+        default:
+            mSearchTypeCombo->setValue("search_by_name");
+            break;
+    }
 }
 
 // static
 BOOL LLPanelMainInventory::filtersVisible(void* user_data)
 {
-	LLPanelMainInventory* self = (LLPanelMainInventory*)user_data;
-	if(!self) return FALSE;
+    LLPanelMainInventory* self = (LLPanelMainInventory*)user_data;
+    if(!self) return FALSE;
 
-	return self->getFinder() != NULL;
+    return self->getFinder() != NULL;
 }
 
 void LLPanelMainInventory::onClearSearch()
 {
-	BOOL initially_active = FALSE;
-	LLFloater *finder = getFinder();
-	if (mActivePanel && (getActivePanel() != mWornItemsPanel))
-	{
-		initially_active = mActivePanel->getFilter().isNotDefault();
-		setFilterSubString(LLStringUtil::null);
-		mActivePanel->setFilterTypes(0xffffffffffffffffULL);
-		mActivePanel->setFilterLinks(LLInventoryFilter::FILTERLINK_INCLUDE_LINKS);
-	}
-
-	if (finder)
-	{
-		LLFloaterInventoryFinder::selectAllTypes(finder);
-	}
-
-	// re-open folders that were initially open in case filter was active
-	if (mActivePanel && (mFilterSubString.size() || initially_active) && !mSingleFolderMode)
-	{
-		mSavedFolderState->setApply(TRUE);
-		mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
-		LLOpenFoldersWithSelection opener;
-		mActivePanel->getRootFolder()->applyFunctorRecursively(opener);
-		mActivePanel->getRootFolder()->scrollToShowSelection();
-	}
-	mFilterSubString = "";
-
-	LLSidepanelInventory * sidepanel_inventory = getParentSidepanelInventory();
-	if (sidepanel_inventory)
-	{
-		LLPanelMarketplaceInbox* inbox_panel = sidepanel_inventory->getChild<LLPanelMarketplaceInbox>("marketplace_inbox");
-		if (inbox_panel)
-		{
-			inbox_panel->onClearSearch();
-		}
-	}
+    BOOL initially_active = FALSE;
+    LLFloater *finder = getFinder();
+    if (mActivePanel && (getActivePanel() != mWornItemsPanel))
+    {
+        initially_active = mActivePanel->getFilter().isNotDefault();
+        setFilterSubString(LLStringUtil::null);
+        mActivePanel->setFilterTypes(0xffffffffffffffffULL);
+        mActivePanel->setFilterLinks(LLInventoryFilter::FILTERLINK_INCLUDE_LINKS);
+    }
+
+    if (finder)
+    {
+        LLFloaterInventoryFinder::selectAllTypes(finder);
+    }
+
+    // re-open folders that were initially open in case filter was active
+    if (mActivePanel && (mFilterSubString.size() || initially_active) && !mSingleFolderMode)
+    {
+        mSavedFolderState->setApply(TRUE);
+        mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
+        LLOpenFoldersWithSelection opener;
+        mActivePanel->getRootFolder()->applyFunctorRecursively(opener);
+        mActivePanel->getRootFolder()->scrollToShowSelection();
+    }
+    mFilterSubString = "";
+
+    LLSidepanelInventory * sidepanel_inventory = getParentSidepanelInventory();
+    if (sidepanel_inventory)
+    {
+        LLPanelMarketplaceInbox* inbox_panel = sidepanel_inventory->getChild<LLPanelMarketplaceInbox>("marketplace_inbox");
+        if (inbox_panel)
+        {
+            inbox_panel->onClearSearch();
+        }
+    }
 }
 
 void LLPanelMainInventory::onFilterEdit(const std::string& search_string )
@@ -788,15 +788,15 @@ void LLPanelMainInventory::onFilterEdit(const std::string& search_string )
         mCombinationGalleryPanel->setFilterSubString(search_string);
     }
 
-	if (search_string == "")
-	{
-		onClearSearch();
-	}
+    if (search_string == "")
+    {
+        onClearSearch();
+    }
 
-	if (!mActivePanel)
-	{
-		return;
-	}
+    if (!mActivePanel)
+    {
+        return;
+    }
 
     if (!LLInventoryModelBackgroundFetch::instance().inventoryFetchStarted())
     {
@@ -804,221 +804,221 @@ void LLPanelMainInventory::onFilterEdit(const std::string& search_string )
         LLInventoryModelBackgroundFetch::instance().start();
     }
 
-	mFilterSubString = search_string;
-	if (mActivePanel->getFilterSubString().empty() && mFilterSubString.empty())
-	{
-			// current filter and new filter empty, do nothing
-			return;
-	}
+    mFilterSubString = search_string;
+    if (mActivePanel->getFilterSubString().empty() && mFilterSubString.empty())
+    {
+            // current filter and new filter empty, do nothing
+            return;
+    }
 
-	// save current folder open state if no filter currently applied
-	if (!mActivePanel->getFilter().isNotDefault())
-	{
-		mSavedFolderState->setApply(FALSE);
-		mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
-	}
+    // save current folder open state if no filter currently applied
+    if (!mActivePanel->getFilter().isNotDefault())
+    {
+        mSavedFolderState->setApply(FALSE);
+        mActivePanel->getRootFolder()->applyFunctorRecursively(*mSavedFolderState);
+    }
 
-	// set new filter string
-	setFilterSubString(mFilterSubString);
+    // set new filter string
+    setFilterSubString(mFilterSubString);
 
     LLSidepanelInventory * sidepanel_inventory = getParentSidepanelInventory();
-	if (sidepanel_inventory)
-	{
-		LLPanelMarketplaceInbox* inbox_panel = sidepanel_inventory->getChild<LLPanelMarketplaceInbox>("marketplace_inbox");
-		if (inbox_panel)
-		{
-			inbox_panel->onFilterEdit(search_string);
-		}
-	}
+    if (sidepanel_inventory)
+    {
+        LLPanelMarketplaceInbox* inbox_panel = sidepanel_inventory->getChild<LLPanelMarketplaceInbox>("marketplace_inbox");
+        if (inbox_panel)
+        {
+            inbox_panel->onFilterEdit(search_string);
+        }
+    }
 }
 
 
  //static
  BOOL LLPanelMainInventory::incrementalFind(LLFolderViewItem* first_item, const char *find_text, BOOL backward)
  {
- 	LLPanelMainInventory* active_view = NULL;
-	
-	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
-	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
-	{
-		LLPanelMainInventory* iv = dynamic_cast<LLPanelMainInventory*>(*iter);
-		if (iv)
-		{
-			if (gFocusMgr.childHasKeyboardFocus(iv))
-			{
-				active_view = iv;
-				break;
-			}
- 		}
- 	}
-
- 	if (!active_view)
- 	{
- 		return FALSE;
- 	}
-
- 	std::string search_string(find_text);
-
- 	if (search_string.empty())
- 	{
- 		return FALSE;
- 	}
-
- 	if (active_view->getPanel() &&
- 		active_view->getPanel()->getRootFolder()->search(first_item, search_string, backward))
- 	{
- 		return TRUE;
- 	}
-
- 	return FALSE;
+    LLPanelMainInventory* active_view = NULL;
+
+    LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("inventory");
+    for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
+    {
+        LLPanelMainInventory* iv = dynamic_cast<LLPanelMainInventory*>(*iter);
+        if (iv)
+        {
+            if (gFocusMgr.childHasKeyboardFocus(iv))
+            {
+                active_view = iv;
+                break;
+            }
+        }
+    }
+
+    if (!active_view)
+    {
+        return FALSE;
+    }
+
+    std::string search_string(find_text);
+
+    if (search_string.empty())
+    {
+        return FALSE;
+    }
+
+    if (active_view->getPanel() &&
+        active_view->getPanel()->getRootFolder()->search(first_item, search_string, backward))
+    {
+        return TRUE;
+    }
+
+    return FALSE;
  }
 
 void LLPanelMainInventory::onFilterSelected()
 {
-	// Find my index
+    // Find my index
     setActivePanel();
 
-	if (!mActivePanel)
-	{
-		return;
-	}
-
-	if (getActivePanel() == mWornItemsPanel)
-	{
-		mActivePanel->openAllFolders();
-	}
-	updateSearchTypeCombo();
-	setFilterSubString(mFilterSubString);
-	LLInventoryFilter& filter = getCurrentFilter();
-	LLFloaterInventoryFinder *finder = getFinder();
-	if (finder)
-	{
-		finder->changeFilter(&filter);
+    if (!mActivePanel)
+    {
+        return;
+    }
+
+    if (getActivePanel() == mWornItemsPanel)
+    {
+        mActivePanel->openAllFolders();
+    }
+    updateSearchTypeCombo();
+    setFilterSubString(mFilterSubString);
+    LLInventoryFilter& filter = getCurrentFilter();
+    LLFloaterInventoryFinder *finder = getFinder();
+    if (finder)
+    {
+        finder->changeFilter(&filter);
         if (mSingleFolderMode)
         {
             finder->setTitle(getLocalizedRootName());
         }
-	}
-	if (filter.isActive() && !LLInventoryModelBackgroundFetch::instance().inventoryFetchStarted())
-	{
+    }
+    if (filter.isActive() && !LLInventoryModelBackgroundFetch::instance().inventoryFetchStarted())
+    {
         llassert(false); // this should have been done on startup
-		LLInventoryModelBackgroundFetch::instance().start();
-	}
-	setFilterTextFromFilter();
+        LLInventoryModelBackgroundFetch::instance().start();
+    }
+    setFilterTextFromFilter();
 }
 
-const std::string LLPanelMainInventory::getFilterSubString() 
-{ 
-	return mActivePanel->getFilterSubString(); 
+const std::string LLPanelMainInventory::getFilterSubString()
+{
+    return mActivePanel->getFilterSubString();
 }
 
-void LLPanelMainInventory::setFilterSubString(const std::string& string) 
-{ 
-	mActivePanel->setFilterSubString(string); 
+void LLPanelMainInventory::setFilterSubString(const std::string& string)
+{
+    mActivePanel->setFilterSubString(string);
 }
 
 BOOL LLPanelMainInventory::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
-										 EDragAndDropType cargo_type,
-										 void* cargo_data,
-										 EAcceptance* accept,
-										 std::string& tooltip_msg)
-{
-	// Check to see if we are auto scrolling from the last frame
-	LLInventoryPanel* panel = (LLInventoryPanel*)this->getActivePanel();
-	BOOL needsToScroll = panel->getScrollableContainer()->canAutoScroll(x, y);
-	if(mFilterTabs)
-	{
-		if(needsToScroll)
-		{
-			mFilterTabs->startDragAndDropDelayTimer();
-		}
-	}
-	
-	BOOL handled = LLPanel::handleDragAndDrop(x, y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
-
-	return handled;
+                                         EDragAndDropType cargo_type,
+                                         void* cargo_data,
+                                         EAcceptance* accept,
+                                         std::string& tooltip_msg)
+{
+    // Check to see if we are auto scrolling from the last frame
+    LLInventoryPanel* panel = (LLInventoryPanel*)this->getActivePanel();
+    BOOL needsToScroll = panel->getScrollableContainer()->canAutoScroll(x, y);
+    if(mFilterTabs)
+    {
+        if(needsToScroll)
+        {
+            mFilterTabs->startDragAndDropDelayTimer();
+        }
+    }
+
+    BOOL handled = LLPanel::handleDragAndDrop(x, y, mask, drop, cargo_type, cargo_data, accept, tooltip_msg);
+
+    return handled;
 }
 
 // virtual
 void LLPanelMainInventory::changed(U32)
 {
-	updateItemcountText();
+    updateItemcountText();
 }
 
 void LLPanelMainInventory::setFocusFilterEditor()
 {
-	if(mFilterEditor)
-	{
-		mFilterEditor->setFocus(true);
-	}
+    if(mFilterEditor)
+    {
+        mFilterEditor->setFocus(true);
+    }
 }
 
 // virtual
 void LLPanelMainInventory::draw()
 {
-	if (mActivePanel && mFilterEditor)
-	{
-		mFilterEditor->setText(mFilterSubString);
-	}	
-	if (mActivePanel && mResortActivePanel)
-	{
-		// EXP-756: Force resorting of the list the first time we draw the list: 
-		// In the case of date sorting, we don't have enough information at initialization time
-		// to correctly sort the folders. Later manual resort doesn't do anything as the order value is 
-		// set correctly. The workaround is to reset the order to alphabetical (or anything) then to the correct order.
-		U32 order = mActivePanel->getSortOrder();
-		mActivePanel->setSortOrder(LLInventoryFilter::SO_NAME);
-		mActivePanel->setSortOrder(order);
-		mResortActivePanel = false;
-	}
-	LLPanel::draw();
-	updateItemcountText();
+    if (mActivePanel && mFilterEditor)
+    {
+        mFilterEditor->setText(mFilterSubString);
+    }
+    if (mActivePanel && mResortActivePanel)
+    {
+        // EXP-756: Force resorting of the list the first time we draw the list:
+        // In the case of date sorting, we don't have enough information at initialization time
+        // to correctly sort the folders. Later manual resort doesn't do anything as the order value is
+        // set correctly. The workaround is to reset the order to alphabetical (or anything) then to the correct order.
+        U32 order = mActivePanel->getSortOrder();
+        mActivePanel->setSortOrder(LLInventoryFilter::SO_NAME);
+        mActivePanel->setSortOrder(order);
+        mResortActivePanel = false;
+    }
+    LLPanel::draw();
+    updateItemcountText();
     updateCombinationVisibility();
 }
 
 void LLPanelMainInventory::updateItemcountText()
 {
-	if(mItemCount != gInventory.getItemCount())
-	{
-		mItemCount = gInventory.getItemCount();
-		mItemCountString = "";
-		LLLocale locale(LLLocale::USER_LOCALE);
-		LLResMgr::getIntegerString(mItemCountString, mItemCount);
-	}
-
-	if(mCategoryCount != gInventory.getCategoryCount())
-	{
-		mCategoryCount = gInventory.getCategoryCount();
-		mCategoryCountString = "";
-		LLLocale locale(LLLocale::USER_LOCALE);
-		LLResMgr::getIntegerString(mCategoryCountString, mCategoryCount);
-	}
-
-	LLStringUtil::format_map_t string_args;
-	string_args["[ITEM_COUNT]"] = mItemCountString;
-	string_args["[CATEGORY_COUNT]"] = mCategoryCountString;
-	string_args["[FILTER]"] = getFilterText();
-
-	std::string text = "";
-
-	if (LLInventoryModelBackgroundFetch::instance().folderFetchActive())
-	{
-		static LLUIString itemcount_fetching_str = getString("ItemcountFetching");
-		itemcount_fetching_str.setArgList(string_args);
-		text = itemcount_fetching_str.getString();
-	}
-	else if (LLInventoryModelBackgroundFetch::instance().isEverythingFetched())
-	{
-		static LLUIString itemcount_completed_str = getString("ItemcountCompleted");
-		itemcount_completed_str.setArgList(string_args);
-		text = itemcount_completed_str.getString();
-	}
-	else
-	{
-		static LLUIString itemcount_unknown_str = getString("ItemcountUnknown");
-		itemcount_unknown_str.setArgList(string_args);
-		text = itemcount_unknown_str.getString();
-	}
+    if(mItemCount != gInventory.getItemCount())
+    {
+        mItemCount = gInventory.getItemCount();
+        mItemCountString = "";
+        LLLocale locale(LLLocale::USER_LOCALE);
+        LLResMgr::getIntegerString(mItemCountString, mItemCount);
+    }
+
+    if(mCategoryCount != gInventory.getCategoryCount())
+    {
+        mCategoryCount = gInventory.getCategoryCount();
+        mCategoryCountString = "";
+        LLLocale locale(LLLocale::USER_LOCALE);
+        LLResMgr::getIntegerString(mCategoryCountString, mCategoryCount);
+    }
+
+    LLStringUtil::format_map_t string_args;
+    string_args["[ITEM_COUNT]"] = mItemCountString;
+    string_args["[CATEGORY_COUNT]"] = mCategoryCountString;
+    string_args["[FILTER]"] = getFilterText();
+
+    std::string text = "";
+
+    if (LLInventoryModelBackgroundFetch::instance().folderFetchActive())
+    {
+        static LLUIString itemcount_fetching_str = getString("ItemcountFetching");
+        itemcount_fetching_str.setArgList(string_args);
+        text = itemcount_fetching_str.getString();
+    }
+    else if (LLInventoryModelBackgroundFetch::instance().isEverythingFetched())
+    {
+        static LLUIString itemcount_completed_str = getString("ItemcountCompleted");
+        itemcount_completed_str.setArgList(string_args);
+        text = itemcount_completed_str.getString();
+    }
+    else
+    {
+        static LLUIString itemcount_unknown_str = getString("ItemcountUnknown");
+        itemcount_unknown_str.setArgList(string_args);
+        text = itemcount_unknown_str.getString();
+    }
 
     if (mSingleFolderMode)
     {
@@ -1034,40 +1034,40 @@ void LLPanelMainInventory::updateItemcountText()
             text = getString("ItemcountCompleted", string_args);
         }
     }
-	
+
     mCounterCtrl->setValue(text);
     mCounterCtrl->setToolTip(text);
 }
 
 void LLPanelMainInventory::onFocusReceived()
 {
-	LLSidepanelInventory *sidepanel_inventory =	LLFloaterSidePanelContainer::getPanel<LLSidepanelInventory>("inventory");
-	if (!sidepanel_inventory)
-	{
-		LL_WARNS() << "Could not find Inventory Panel in My Inventory floater" << LL_ENDL;
-		return;
-	}
+    LLSidepanelInventory *sidepanel_inventory = LLFloaterSidePanelContainer::getPanel<LLSidepanelInventory>("inventory");
+    if (!sidepanel_inventory)
+    {
+        LL_WARNS() << "Could not find Inventory Panel in My Inventory floater" << LL_ENDL;
+        return;
+    }
 
-	sidepanel_inventory->clearSelections(false, true);
+    sidepanel_inventory->clearSelections(false, true);
 }
 
-void LLPanelMainInventory::setFilterTextFromFilter() 
-{ 
-	mFilterText = getCurrentFilter().getFilterText();
+void LLPanelMainInventory::setFilterTextFromFilter()
+{
+    mFilterText = getCurrentFilter().getFilterText();
 }
 
 void LLPanelMainInventory::toggleFindOptions()
 {
-	LLFloater *floater = getFinder();
-	if (!floater)
-	{
-		LLFloaterInventoryFinder * finder = new LLFloaterInventoryFinder(this);
-		mFinderHandle = finder->getHandle();
-		finder->openFloater();
+    LLFloater *floater = getFinder();
+    if (!floater)
+    {
+        LLFloaterInventoryFinder * finder = new LLFloaterInventoryFinder(this);
+        mFinderHandle = finder->getHandle();
+        finder->openFloater();
 
-		LLFloater* parent_floater = gFloaterView->getParentFloater(this);
-		if (parent_floater)
-			parent_floater->addDependentFloater(mFinderHandle);
+        LLFloater* parent_floater = gFloaterView->getParentFloater(this);
+        if (parent_floater)
+            parent_floater->addDependentFloater(mFinderHandle);
 
         if (!LLInventoryModelBackgroundFetch::instance().inventoryFetchStarted())
         {
@@ -1079,232 +1079,232 @@ void LLPanelMainInventory::toggleFindOptions()
         {
             finder->setTitle(getLocalizedRootName());
         }
-	}
-	else
-	{
-		floater->closeFloater();
-	}
+    }
+    else
+    {
+        floater->closeFloater();
+    }
 }
 
 void LLPanelMainInventory::setSelectCallback(const LLFolderView::signal_t::slot_type& cb)
 {
-	getChild<LLInventoryPanel>(ALL_ITEMS)->setSelectCallback(cb);
-	getChild<LLInventoryPanel>(RECENT_ITEMS)->setSelectCallback(cb);
+    getChild<LLInventoryPanel>(ALL_ITEMS)->setSelectCallback(cb);
+    getChild<LLInventoryPanel>(RECENT_ITEMS)->setSelectCallback(cb);
 }
 
 void LLPanelMainInventory::onSelectionChange(LLInventoryPanel *panel, const std::deque<LLFolderViewItem*>& items, BOOL user_action)
 {
-	updateListCommands();
-	panel->onSelectionChange(items, user_action);
+    updateListCommands();
+    panel->onSelectionChange(items, user_action);
 }
 
 ///----------------------------------------------------------------------------
 /// LLFloaterInventoryFinder
 ///----------------------------------------------------------------------------
 
-LLFloaterInventoryFinder* LLPanelMainInventory::getFinder() 
-{ 
-	return (LLFloaterInventoryFinder*)mFinderHandle.get();
+LLFloaterInventoryFinder* LLPanelMainInventory::getFinder()
+{
+    return (LLFloaterInventoryFinder*)mFinderHandle.get();
 }
 
 
-LLFloaterInventoryFinder::LLFloaterInventoryFinder(LLPanelMainInventory* inventory_view) :	
-	LLFloater(LLSD()),
-	mPanelMainInventory(inventory_view),
-	mFilter(&inventory_view->getPanel()->getFilter())
+LLFloaterInventoryFinder::LLFloaterInventoryFinder(LLPanelMainInventory* inventory_view) :
+    LLFloater(LLSD()),
+    mPanelMainInventory(inventory_view),
+    mFilter(&inventory_view->getPanel()->getFilter())
 {
-	buildFromFile("floater_inventory_view_finder.xml");
-	updateElementsFromFilter();
+    buildFromFile("floater_inventory_view_finder.xml");
+    updateElementsFromFilter();
 }
 
 BOOL LLFloaterInventoryFinder::postBuild()
 {
-	const LLRect& viewrect = mPanelMainInventory->getRect();
-	setRect(LLRect(viewrect.mLeft - getRect().getWidth(), viewrect.mTop, viewrect.mLeft, viewrect.mTop - getRect().getHeight()));
+    const LLRect& viewrect = mPanelMainInventory->getRect();
+    setRect(LLRect(viewrect.mLeft - getRect().getWidth(), viewrect.mTop, viewrect.mLeft, viewrect.mTop - getRect().getHeight()));
 
-	childSetAction("All", selectAllTypes, this);
-	childSetAction("None", selectNoTypes, this);
+    childSetAction("All", selectAllTypes, this);
+    childSetAction("None", selectNoTypes, this);
 
-	mSpinSinceHours = getChild<LLSpinCtrl>("spin_hours_ago");
-	childSetCommitCallback("spin_hours_ago", onTimeAgo, this);
+    mSpinSinceHours = getChild<LLSpinCtrl>("spin_hours_ago");
+    childSetCommitCallback("spin_hours_ago", onTimeAgo, this);
 
-	mSpinSinceDays = getChild<LLSpinCtrl>("spin_days_ago");
-	childSetCommitCallback("spin_days_ago", onTimeAgo, this);
+    mSpinSinceDays = getChild<LLSpinCtrl>("spin_days_ago");
+    childSetCommitCallback("spin_days_ago", onTimeAgo, this);
 
-	mCreatorSelf = getChild<LLCheckBoxCtrl>("check_created_by_me");
-	mCreatorOthers = getChild<LLCheckBoxCtrl>("check_created_by_others");
-	mCreatorSelf->setCommitCallback(boost::bind(&LLFloaterInventoryFinder::onCreatorSelfFilterCommit, this));
-	mCreatorOthers->setCommitCallback(boost::bind(&LLFloaterInventoryFinder::onCreatorOtherFilterCommit, this));
+    mCreatorSelf = getChild<LLCheckBoxCtrl>("check_created_by_me");
+    mCreatorOthers = getChild<LLCheckBoxCtrl>("check_created_by_others");
+    mCreatorSelf->setCommitCallback(boost::bind(&LLFloaterInventoryFinder::onCreatorSelfFilterCommit, this));
+    mCreatorOthers->setCommitCallback(boost::bind(&LLFloaterInventoryFinder::onCreatorOtherFilterCommit, this));
 
-	childSetAction("Close", onCloseBtn, this);
+    childSetAction("Close", onCloseBtn, this);
 
-	updateElementsFromFilter();
-	return TRUE;
+    updateElementsFromFilter();
+    return TRUE;
 }
 void LLFloaterInventoryFinder::onTimeAgo(LLUICtrl *ctrl, void *user_data)
 {
-	LLFloaterInventoryFinder *self = (LLFloaterInventoryFinder *)user_data;
-	if (!self) return;
-	
-	if ( self->mSpinSinceDays->get() ||  self->mSpinSinceHours->get() )
-	{
-		self->getChild<LLUICtrl>("check_since_logoff")->setValue(false);
-
-		U32 days = (U32)self->mSpinSinceDays->get();
-		U32 hours = (U32)self->mSpinSinceHours->get();
-		if (hours >= 24)
-		{
-			// Try to handle both cases of spinner clicking and text input in a sensible fashion as best as possible.
-			// There is no way to tell if someone has clicked the spinner to get to 24 or input 24 manually, so in
-			// this case add to days.  Any value > 24 means they have input the hours manually, so do not add to the
-			// current day value.
-			if (24 == hours)  // Got to 24 via spinner clicking or text input of 24
-			{
-				days = days + hours / 24;
-			}
-			else	// Text input, so do not add to days
-			{ 
-				days = hours / 24;
-			}
-			hours = (U32)hours % 24;
-			self->mSpinSinceHours->setFocus(false);
-			self->mSpinSinceDays->setFocus(false);
-			self->mSpinSinceDays->set((F32)days);
-			self->mSpinSinceHours->set((F32)hours);
-			self->mSpinSinceHours->setFocus(true);
-		}
-	}
+    LLFloaterInventoryFinder *self = (LLFloaterInventoryFinder *)user_data;
+    if (!self) return;
+
+    if ( self->mSpinSinceDays->get() ||  self->mSpinSinceHours->get() )
+    {
+        self->getChild<LLUICtrl>("check_since_logoff")->setValue(false);
+
+        U32 days = (U32)self->mSpinSinceDays->get();
+        U32 hours = (U32)self->mSpinSinceHours->get();
+        if (hours >= 24)
+        {
+            // Try to handle both cases of spinner clicking and text input in a sensible fashion as best as possible.
+            // There is no way to tell if someone has clicked the spinner to get to 24 or input 24 manually, so in
+            // this case add to days.  Any value > 24 means they have input the hours manually, so do not add to the
+            // current day value.
+            if (24 == hours)  // Got to 24 via spinner clicking or text input of 24
+            {
+                days = days + hours / 24;
+            }
+            else    // Text input, so do not add to days
+            {
+                days = hours / 24;
+            }
+            hours = (U32)hours % 24;
+            self->mSpinSinceHours->setFocus(false);
+            self->mSpinSinceDays->setFocus(false);
+            self->mSpinSinceDays->set((F32)days);
+            self->mSpinSinceHours->set((F32)hours);
+            self->mSpinSinceHours->setFocus(true);
+        }
+    }
 }
 
 void LLFloaterInventoryFinder::changeFilter(LLInventoryFilter* filter)
 {
-	mFilter = filter;
-	updateElementsFromFilter();
+    mFilter = filter;
+    updateElementsFromFilter();
 }
 
 void LLFloaterInventoryFinder::updateElementsFromFilter()
 {
-	if (!mFilter)
-		return;
-
-	// Get data needed for filter display
-	U32 filter_types = mFilter->getFilterObjectTypes();
-	LLInventoryFilter::EFolderShow show_folders = mFilter->getShowFolderState();
-	U32 hours = mFilter->getHoursAgo();
-	U32 date_search_direction = mFilter->getDateSearchDirection();
-
-	LLInventoryFilter::EFilterCreatorType filter_creator = mFilter->getFilterCreatorType();
-	bool show_created_by_me = ((filter_creator == LLInventoryFilter::FILTERCREATOR_ALL) || (filter_creator == LLInventoryFilter::FILTERCREATOR_SELF));
-	bool show_created_by_others = ((filter_creator == LLInventoryFilter::FILTERCREATOR_ALL) || (filter_creator == LLInventoryFilter::FILTERCREATOR_OTHERS));
-
-	// update the ui elements
-	setTitle(mFilter->getName());
-
-	getChild<LLUICtrl>("check_animation")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_ANIMATION));
-
-	getChild<LLUICtrl>("check_calling_card")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_CALLINGCARD));
-	getChild<LLUICtrl>("check_clothing")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_WEARABLE));
-	getChild<LLUICtrl>("check_gesture")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_GESTURE));
-	getChild<LLUICtrl>("check_landmark")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_LANDMARK));
-	getChild<LLUICtrl>("check_material")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_MATERIAL));
-	getChild<LLUICtrl>("check_notecard")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_NOTECARD));
-	getChild<LLUICtrl>("check_object")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_OBJECT));
-	getChild<LLUICtrl>("check_script")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_LSL));
-	getChild<LLUICtrl>("check_sound")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_SOUND));
-	getChild<LLUICtrl>("check_texture")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_TEXTURE));
-	getChild<LLUICtrl>("check_snapshot")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_SNAPSHOT));
+    if (!mFilter)
+        return;
+
+    // Get data needed for filter display
+    U32 filter_types = mFilter->getFilterObjectTypes();
+    LLInventoryFilter::EFolderShow show_folders = mFilter->getShowFolderState();
+    U32 hours = mFilter->getHoursAgo();
+    U32 date_search_direction = mFilter->getDateSearchDirection();
+
+    LLInventoryFilter::EFilterCreatorType filter_creator = mFilter->getFilterCreatorType();
+    bool show_created_by_me = ((filter_creator == LLInventoryFilter::FILTERCREATOR_ALL) || (filter_creator == LLInventoryFilter::FILTERCREATOR_SELF));
+    bool show_created_by_others = ((filter_creator == LLInventoryFilter::FILTERCREATOR_ALL) || (filter_creator == LLInventoryFilter::FILTERCREATOR_OTHERS));
+
+    // update the ui elements
+    setTitle(mFilter->getName());
+
+    getChild<LLUICtrl>("check_animation")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_ANIMATION));
+
+    getChild<LLUICtrl>("check_calling_card")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_CALLINGCARD));
+    getChild<LLUICtrl>("check_clothing")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_WEARABLE));
+    getChild<LLUICtrl>("check_gesture")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_GESTURE));
+    getChild<LLUICtrl>("check_landmark")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_LANDMARK));
+    getChild<LLUICtrl>("check_material")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_MATERIAL));
+    getChild<LLUICtrl>("check_notecard")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_NOTECARD));
+    getChild<LLUICtrl>("check_object")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_OBJECT));
+    getChild<LLUICtrl>("check_script")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_LSL));
+    getChild<LLUICtrl>("check_sound")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_SOUND));
+    getChild<LLUICtrl>("check_texture")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_TEXTURE));
+    getChild<LLUICtrl>("check_snapshot")->setValue((S32) (filter_types & 0x1 << LLInventoryType::IT_SNAPSHOT));
     getChild<LLUICtrl>("check_settings")->setValue((S32)(filter_types & 0x1 << LLInventoryType::IT_SETTINGS));
-	getChild<LLUICtrl>("check_show_empty")->setValue(show_folders == LLInventoryFilter::SHOW_ALL_FOLDERS);
+    getChild<LLUICtrl>("check_show_empty")->setValue(show_folders == LLInventoryFilter::SHOW_ALL_FOLDERS);
 
-	getChild<LLUICtrl>("check_created_by_me")->setValue(show_created_by_me);
-	getChild<LLUICtrl>("check_created_by_others")->setValue(show_created_by_others);
+    getChild<LLUICtrl>("check_created_by_me")->setValue(show_created_by_me);
+    getChild<LLUICtrl>("check_created_by_others")->setValue(show_created_by_others);
 
-	getChild<LLUICtrl>("check_since_logoff")->setValue(mFilter->isSinceLogoff());
-	mSpinSinceHours->set((F32)(hours % 24));
-	mSpinSinceDays->set((F32)(hours / 24));
-	getChild<LLRadioGroup>("date_search_direction")->setSelectedIndex(date_search_direction);
+    getChild<LLUICtrl>("check_since_logoff")->setValue(mFilter->isSinceLogoff());
+    mSpinSinceHours->set((F32)(hours % 24));
+    mSpinSinceDays->set((F32)(hours / 24));
+    getChild<LLRadioGroup>("date_search_direction")->setSelectedIndex(date_search_direction);
 }
 
 void LLFloaterInventoryFinder::draw()
 {
-	U64 filter = 0xffffffffffffffffULL;
-	BOOL filtered_by_all_types = TRUE;
-
-	if (!getChild<LLUICtrl>("check_animation")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_ANIMATION);
-		filtered_by_all_types = FALSE;
-	}
-
-
-	if (!getChild<LLUICtrl>("check_calling_card")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_CALLINGCARD);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_clothing")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_WEARABLE);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_gesture")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_GESTURE);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_landmark")->getValue())
-
-
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_LANDMARK);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_material")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_MATERIAL);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_notecard")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_NOTECARD);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_object")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_OBJECT);
-		filter &= ~(0x1 << LLInventoryType::IT_ATTACHMENT);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_script")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_LSL);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_sound")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_SOUND);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_texture")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_TEXTURE);
-		filtered_by_all_types = FALSE;
-	}
-
-	if (!getChild<LLUICtrl>("check_snapshot")->getValue())
-	{
-		filter &= ~(0x1 << LLInventoryType::IT_SNAPSHOT);
-		filtered_by_all_types = FALSE;
-	}
+    U64 filter = 0xffffffffffffffffULL;
+    BOOL filtered_by_all_types = TRUE;
+
+    if (!getChild<LLUICtrl>("check_animation")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_ANIMATION);
+        filtered_by_all_types = FALSE;
+    }
+
+
+    if (!getChild<LLUICtrl>("check_calling_card")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_CALLINGCARD);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_clothing")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_WEARABLE);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_gesture")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_GESTURE);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_landmark")->getValue())
+
+
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_LANDMARK);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_material")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_MATERIAL);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_notecard")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_NOTECARD);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_object")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_OBJECT);
+        filter &= ~(0x1 << LLInventoryType::IT_ATTACHMENT);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_script")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_LSL);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_sound")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_SOUND);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_texture")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_TEXTURE);
+        filtered_by_all_types = FALSE;
+    }
+
+    if (!getChild<LLUICtrl>("check_snapshot")->getValue())
+    {
+        filter &= ~(0x1 << LLInventoryType::IT_SNAPSHOT);
+        filtered_by_all_types = FALSE;
+    }
 
     if (!getChild<LLUICtrl>("check_settings")->getValue())
     {
@@ -1312,11 +1312,11 @@ void LLFloaterInventoryFinder::draw()
         filtered_by_all_types = FALSE;
     }
 
-	if (!filtered_by_all_types || (mPanelMainInventory->getPanel()->getFilter().getFilterTypes() & LLInventoryFilter::FILTERTYPE_DATE))
-	{
-		// don't include folders in filter, unless I've selected everything or filtering by date
-		filter &= ~(0x1 << LLInventoryType::IT_CATEGORY);
-	}
+    if (!filtered_by_all_types || (mPanelMainInventory->getPanel()->getFilter().getFilterTypes() & LLInventoryFilter::FILTERTYPE_DATE))
+    {
+        // don't include folders in filter, unless I've selected everything or filtering by date
+        filter &= ~(0x1 << LLInventoryType::IT_CATEGORY);
+    }
 
 
     bool is_sf_mode = mPanelMainInventory->isSingleFolderMode();
@@ -1340,28 +1340,28 @@ void LLFloaterInventoryFinder::draw()
         mPanelMainInventory->getPanel()->setFilterTypes(filter);
     }
 
-	if (getCheckSinceLogoff())
-	{
-		mSpinSinceDays->set(0);
-		mSpinSinceHours->set(0);
-	}
-	U32 days = (U32)mSpinSinceDays->get();
-	U32 hours = (U32)mSpinSinceHours->get();
-	if (hours >= 24)
-	{
-		days = hours / 24;
-		hours = (U32)hours % 24;
-		// A UI element that has focus will not display a new value set to it
-		mSpinSinceHours->setFocus(false);
-		mSpinSinceDays->setFocus(false);
-		mSpinSinceDays->set((F32)days);
-		mSpinSinceHours->set((F32)hours);
-		mSpinSinceHours->setFocus(true);
-	}
-	hours += days * 24;
-
-
-	mPanelMainInventory->setFilterTextFromFilter();
+    if (getCheckSinceLogoff())
+    {
+        mSpinSinceDays->set(0);
+        mSpinSinceHours->set(0);
+    }
+    U32 days = (U32)mSpinSinceDays->get();
+    U32 hours = (U32)mSpinSinceHours->get();
+    if (hours >= 24)
+    {
+        days = hours / 24;
+        hours = (U32)hours % 24;
+        // A UI element that has focus will not display a new value set to it
+        mSpinSinceHours->setFocus(false);
+        mSpinSinceDays->setFocus(false);
+        mSpinSinceDays->set((F32)days);
+        mSpinSinceHours->set((F32)hours);
+        mSpinSinceHours->setFocus(true);
+    }
+    hours += days * 24;
+
+
+    mPanelMainInventory->setFilterTextFromFilter();
     if(is_sf_mode && mPanelMainInventory->isGalleryViewMode())
     {
         mPanelMainInventory->mCombinationGalleryPanel->getFilter().setHoursAgo(hours);
@@ -1381,109 +1381,109 @@ void LLFloaterInventoryFinder::draw()
         mPanelMainInventory->getPanel()->setDateSearchDirection(getDateSearchDirection());
     }
 
-	LLPanel::draw();
+    LLPanel::draw();
 }
 
 void LLFloaterInventoryFinder::onCreatorSelfFilterCommit()
 {
-	bool show_creator_self = mCreatorSelf->getValue();
-	bool show_creator_other = mCreatorOthers->getValue();
+    bool show_creator_self = mCreatorSelf->getValue();
+    bool show_creator_other = mCreatorOthers->getValue();
 
-	if(show_creator_self && show_creator_other)
-	{
+    if(show_creator_self && show_creator_other)
+    {
         mPanelMainInventory->getCurrentFilter().setFilterCreator(LLInventoryFilter::FILTERCREATOR_ALL);
-	}
-	else if(show_creator_self)
-	{
+    }
+    else if(show_creator_self)
+    {
         mPanelMainInventory->getCurrentFilter().setFilterCreator(LLInventoryFilter::FILTERCREATOR_SELF);
-	}
-	else if(!show_creator_self || !show_creator_other)
-	{
+    }
+    else if(!show_creator_self || !show_creator_other)
+    {
         mPanelMainInventory->getCurrentFilter().setFilterCreator(LLInventoryFilter::FILTERCREATOR_OTHERS);
-		mCreatorOthers->set(TRUE);
-	}
+        mCreatorOthers->set(TRUE);
+    }
 }
 
 void LLFloaterInventoryFinder::onCreatorOtherFilterCommit()
 {
-	bool show_creator_self = mCreatorSelf->getValue();
-	bool show_creator_other = mCreatorOthers->getValue();
+    bool show_creator_self = mCreatorSelf->getValue();
+    bool show_creator_other = mCreatorOthers->getValue();
 
-	if(show_creator_self && show_creator_other)
-	{
+    if(show_creator_self && show_creator_other)
+    {
         mPanelMainInventory->getCurrentFilter().setFilterCreator(LLInventoryFilter::FILTERCREATOR_ALL);
-	}
-	else if(show_creator_other)
-	{
+    }
+    else if(show_creator_other)
+    {
         mPanelMainInventory->getCurrentFilter().setFilterCreator(LLInventoryFilter::FILTERCREATOR_OTHERS);
-	}
-	else if(!show_creator_other || !show_creator_self)
-	{
+    }
+    else if(!show_creator_other || !show_creator_self)
+    {
         mPanelMainInventory->getCurrentFilter().setFilterCreator(LLInventoryFilter::FILTERCREATOR_SELF);
-		mCreatorSelf->set(TRUE);
-	}
+        mCreatorSelf->set(TRUE);
+    }
 }
 
 BOOL LLFloaterInventoryFinder::getCheckShowEmpty()
 {
-	return getChild<LLUICtrl>("check_show_empty")->getValue();
+    return getChild<LLUICtrl>("check_show_empty")->getValue();
 }
 
 BOOL LLFloaterInventoryFinder::getCheckSinceLogoff()
 {
-	return getChild<LLUICtrl>("check_since_logoff")->getValue();
+    return getChild<LLUICtrl>("check_since_logoff")->getValue();
 }
 
 U32 LLFloaterInventoryFinder::getDateSearchDirection()
 {
-	return 	getChild<LLRadioGroup>("date_search_direction")->getSelectedIndex();
+    return  getChild<LLRadioGroup>("date_search_direction")->getSelectedIndex();
 }
 
 void LLFloaterInventoryFinder::onCloseBtn(void* user_data)
 {
-	LLFloaterInventoryFinder* finderp = (LLFloaterInventoryFinder*)user_data;
-	finderp->closeFloater();
+    LLFloaterInventoryFinder* finderp = (LLFloaterInventoryFinder*)user_data;
+    finderp->closeFloater();
 }
 
 // static
 void LLFloaterInventoryFinder::selectAllTypes(void* user_data)
 {
-	LLFloaterInventoryFinder* self = (LLFloaterInventoryFinder*)user_data;
-	if(!self) return;
-
-	self->getChild<LLUICtrl>("check_animation")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_calling_card")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_clothing")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_gesture")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_landmark")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_material")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_notecard")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_object")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_script")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_sound")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_texture")->setValue(TRUE);
-	self->getChild<LLUICtrl>("check_snapshot")->setValue(TRUE);
+    LLFloaterInventoryFinder* self = (LLFloaterInventoryFinder*)user_data;
+    if(!self) return;
+
+    self->getChild<LLUICtrl>("check_animation")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_calling_card")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_clothing")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_gesture")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_landmark")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_material")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_notecard")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_object")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_script")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_sound")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_texture")->setValue(TRUE);
+    self->getChild<LLUICtrl>("check_snapshot")->setValue(TRUE);
     self->getChild<LLUICtrl>("check_settings")->setValue(TRUE);
 }
 
 //static
 void LLFloaterInventoryFinder::selectNoTypes(void* user_data)
 {
-	LLFloaterInventoryFinder* self = (LLFloaterInventoryFinder*)user_data;
-	if(!self) return;
-
-	self->getChild<LLUICtrl>("check_animation")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_calling_card")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_clothing")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_gesture")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_landmark")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_material")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_notecard")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_object")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_script")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_sound")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_texture")->setValue(FALSE);
-	self->getChild<LLUICtrl>("check_snapshot")->setValue(FALSE);
+    LLFloaterInventoryFinder* self = (LLFloaterInventoryFinder*)user_data;
+    if(!self) return;
+
+    self->getChild<LLUICtrl>("check_animation")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_calling_card")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_clothing")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_gesture")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_landmark")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_material")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_notecard")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_object")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_script")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_sound")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_texture")->setValue(FALSE);
+    self->getChild<LLUICtrl>("check_snapshot")->setValue(FALSE);
     self->getChild<LLUICtrl>("check_settings")->setValue(FALSE);
 }
 
@@ -1492,28 +1492,28 @@ void LLFloaterInventoryFinder::selectNoTypes(void* user_data)
 
 void LLPanelMainInventory::initListCommandsHandlers()
 {
-	childSetAction("add_btn", boost::bind(&LLPanelMainInventory::onAddButtonClick, this));
+    childSetAction("add_btn", boost::bind(&LLPanelMainInventory::onAddButtonClick, this));
     childSetAction("view_mode_btn", boost::bind(&LLPanelMainInventory::onViewModeClick, this));
     childSetAction("up_btn", boost::bind(&LLPanelMainInventory::onUpFolderClicked, this));
     childSetAction("back_btn", boost::bind(&LLPanelMainInventory::onBackFolderClicked, this));
     childSetAction("forward_btn", boost::bind(&LLPanelMainInventory::onForwardFolderClicked, this));
 
-	mCommitCallbackRegistrar.add("Inventory.GearDefault.Custom.Action", boost::bind(&LLPanelMainInventory::onCustomAction, this, _2));
-	mEnableCallbackRegistrar.add("Inventory.GearDefault.Check", boost::bind(&LLPanelMainInventory::isActionChecked, this, _2));
-	mEnableCallbackRegistrar.add("Inventory.GearDefault.Enable", boost::bind(&LLPanelMainInventory::isActionEnabled, this, _2));
+    mCommitCallbackRegistrar.add("Inventory.GearDefault.Custom.Action", boost::bind(&LLPanelMainInventory::onCustomAction, this, _2));
+    mEnableCallbackRegistrar.add("Inventory.GearDefault.Check", boost::bind(&LLPanelMainInventory::isActionChecked, this, _2));
+    mEnableCallbackRegistrar.add("Inventory.GearDefault.Enable", boost::bind(&LLPanelMainInventory::isActionEnabled, this, _2));
     mEnableCallbackRegistrar.add("Inventory.GearDefault.Visible", boost::bind(&LLPanelMainInventory::isActionVisible, this, _2));
-	mMenuGearDefault = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>("menu_inventory_gear_default.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
-	mGearMenuButton->setMenu(mMenuGearDefault, LLMenuButton::MP_BOTTOM_LEFT, true);
+    mMenuGearDefault = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>("menu_inventory_gear_default.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+    mGearMenuButton->setMenu(mMenuGearDefault, LLMenuButton::MP_BOTTOM_LEFT, true);
     mMenuViewDefault = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>("menu_inventory_view_default.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
     mViewMenuButton->setMenu(mMenuViewDefault, LLMenuButton::MP_BOTTOM_LEFT, true);
-	LLMenuGL* menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_inventory_add.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
-	mMenuAddHandle = menu->getHandle();
+    LLMenuGL* menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_inventory_add.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+    mMenuAddHandle = menu->getHandle();
 
-	mMenuVisibility = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>("menu_inventory_search_visibility.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+    mMenuVisibility = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>("menu_inventory_search_visibility.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
     mVisibilityMenuButton->setMenu(mMenuVisibility, LLMenuButton::MP_BOTTOM_LEFT, true);
 
-	// Update the trash button when selected item(s) get worn or taken off.
-	LLOutfitObserver::instance().addCOFChangedCallback(boost::bind(&LLPanelMainInventory::updateListCommands, this));
+    // Update the trash button when selected item(s) get worn or taken off.
+    LLOutfitObserver::instance().addCOFChangedCallback(boost::bind(&LLPanelMainInventory::updateListCommands, this));
 }
 
 void LLPanelMainInventory::updateListCommands()
@@ -1525,15 +1525,15 @@ void LLPanelMainInventory::onAddButtonClick()
 // Gray out the "New Folder" option when the Recent tab is active as new folders will not be displayed
 // unless "Always show folders" is checked in the filter options.
 
-	LLMenuGL* menu = (LLMenuGL*)mMenuAddHandle.get();
-	if (menu)
-	{
+    LLMenuGL* menu = (LLMenuGL*)mMenuAddHandle.get();
+    if (menu)
+    {
         disableAddIfNeeded();
 
-		setUploadCostIfNeeded();
+        setUploadCostIfNeeded();
 
-		showActionMenu(menu,"add_btn");
-	}
+        showActionMenu(menu,"add_btn");
+    }
 }
 
 void LLPanelMainInventory::setActivePanel()
@@ -1747,22 +1747,22 @@ LLUUID LLPanelMainInventory::getSingleFolderViewRoot()
 
 void LLPanelMainInventory::showActionMenu(LLMenuGL* menu, std::string spawning_view_name)
 {
-	if (menu)
-	{
-		menu->buildDrawLabels();
-		menu->updateParent(LLMenuGL::sMenuContainer);
-		LLView* spawning_view = getChild<LLView> (spawning_view_name);
-		S32 menu_x, menu_y;
-		//show menu in co-ordinates of panel
-		spawning_view->localPointToOtherView(0, 0, &menu_x, &menu_y, this);
-		LLMenuGL::showPopup(this, menu, menu_x, menu_y);
-	}
+    if (menu)
+    {
+        menu->buildDrawLabels();
+        menu->updateParent(LLMenuGL::sMenuContainer);
+        LLView* spawning_view = getChild<LLView> (spawning_view_name);
+        S32 menu_x, menu_y;
+        //show menu in co-ordinates of panel
+        spawning_view->localPointToOtherView(0, 0, &menu_x, &menu_y, this);
+        LLMenuGL::showPopup(this, menu, menu_x, menu_y);
+    }
 }
 
 void LLPanelMainInventory::onClipboardAction(const LLSD& userdata)
 {
-	std::string command_name = userdata.asString();
-	getActivePanel()->doToSelected(command_name);
+    std::string command_name = userdata.asString();
+    getActivePanel()->doToSelected(command_name);
 }
 
 void LLPanelMainInventory::saveTexture(const LLSD& userdata)
@@ -1783,93 +1783,93 @@ void LLPanelMainInventory::saveTexture(const LLSD& userdata)
         item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
     }
 
-	LLPreviewTexture* preview_texture = LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", LLSD(item_id), TAKE_FOCUS_YES);
-	if (preview_texture)
-	{
-		preview_texture->openToSave();
-	}
+    LLPreviewTexture* preview_texture = LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", LLSD(item_id), TAKE_FOCUS_YES);
+    if (preview_texture)
+    {
+        preview_texture->openToSave();
+    }
 }
 
 void LLPanelMainInventory::onCustomAction(const LLSD& userdata)
 {
-	if (!isActionEnabled(userdata))
-		return;
-
-	const std::string command_name = userdata.asString();
-
-	if (command_name == "new_window")
-	{
-		newWindow();
-	}
-	if (command_name == "sort_by_name")
-	{
-		const LLSD arg = "name";
-		setSortBy(arg);
-	}
-	if (command_name == "sort_by_recent")
-	{
-		const LLSD arg = "date";
-		setSortBy(arg);
-	}
-	if (command_name == "sort_folders_by_name")
-	{
-		const LLSD arg = "foldersalwaysbyname";
-		setSortBy(arg);
-	}
-	if (command_name == "sort_system_folders_to_top")
-	{
-		const LLSD arg = "systemfolderstotop";
-		setSortBy(arg);
-	}
-	if (command_name == "show_filters")
-	{
-		toggleFindOptions();
-	}
-	if (command_name == "reset_filters")
-	{
-		resetFilters();
-	}
-	if (command_name == "open_folders")
-	{
-		openAllFolders();
-	}
-	if (command_name == "close_folders")
-	{
-		closeAllFolders();
-	}
-	if (command_name == "empty_trash")
-	{
-		const std::string notification = "ConfirmEmptyTrash";
-		gInventory.emptyFolderType(notification, LLFolderType::FT_TRASH);
-	}
-	if (command_name == "empty_lostnfound")
-	{
-		const std::string notification = "ConfirmEmptyLostAndFound";
-		gInventory.emptyFolderType(notification, LLFolderType::FT_LOST_AND_FOUND);
-	}
-	if (command_name == "save_texture")
-	{
-		saveTexture(userdata);
-	}
-	// This doesn't currently work, since the viewer can't change an assetID an item.
-	if (command_name == "regenerate_link")
-	{
-		LLInventoryPanel *active_panel = getActivePanel();
-		LLFolderViewItem* current_item = active_panel->getRootFolder()->getCurSelectedItem();
-		if (!current_item)
-		{
-			return;
-		}
-		const LLUUID item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
-		LLViewerInventoryItem *item = gInventory.getItem(item_id);
-		if (item)
-		{
-			item->regenerateLink();
-		}
-		active_panel->setSelection(item_id, TAKE_FOCUS_NO);
-	}
-	if (command_name == "find_original")
-	{
+    if (!isActionEnabled(userdata))
+        return;
+
+    const std::string command_name = userdata.asString();
+
+    if (command_name == "new_window")
+    {
+        newWindow();
+    }
+    if (command_name == "sort_by_name")
+    {
+        const LLSD arg = "name";
+        setSortBy(arg);
+    }
+    if (command_name == "sort_by_recent")
+    {
+        const LLSD arg = "date";
+        setSortBy(arg);
+    }
+    if (command_name == "sort_folders_by_name")
+    {
+        const LLSD arg = "foldersalwaysbyname";
+        setSortBy(arg);
+    }
+    if (command_name == "sort_system_folders_to_top")
+    {
+        const LLSD arg = "systemfolderstotop";
+        setSortBy(arg);
+    }
+    if (command_name == "show_filters")
+    {
+        toggleFindOptions();
+    }
+    if (command_name == "reset_filters")
+    {
+        resetFilters();
+    }
+    if (command_name == "open_folders")
+    {
+        openAllFolders();
+    }
+    if (command_name == "close_folders")
+    {
+        closeAllFolders();
+    }
+    if (command_name == "empty_trash")
+    {
+        const std::string notification = "ConfirmEmptyTrash";
+        gInventory.emptyFolderType(notification, LLFolderType::FT_TRASH);
+    }
+    if (command_name == "empty_lostnfound")
+    {
+        const std::string notification = "ConfirmEmptyLostAndFound";
+        gInventory.emptyFolderType(notification, LLFolderType::FT_LOST_AND_FOUND);
+    }
+    if (command_name == "save_texture")
+    {
+        saveTexture(userdata);
+    }
+    // This doesn't currently work, since the viewer can't change an assetID an item.
+    if (command_name == "regenerate_link")
+    {
+        LLInventoryPanel *active_panel = getActivePanel();
+        LLFolderViewItem* current_item = active_panel->getRootFolder()->getCurSelectedItem();
+        if (!current_item)
+        {
+            return;
+        }
+        const LLUUID item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
+        LLViewerInventoryItem *item = gInventory.getItem(item_id);
+        if (item)
+        {
+            item->regenerateLink();
+        }
+        active_panel->setSelection(item_id, TAKE_FOCUS_NO);
+    }
+    if (command_name == "find_original")
+    {
         if(mSingleFolderMode && isGalleryViewMode())
         {
             LLInventoryObject *obj = gInventory.getObject(mCombinationGalleryPanel->getFirstSelectedItemID());
@@ -1880,17 +1880,17 @@ void LLPanelMainInventory::onCustomAction(const LLSD& userdata)
         }
         else
         {
-		LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
-		if (!current_item)
-		{
-			return;
-		}
-		static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->performAction(getActivePanel()->getModel(), "goto");
+        LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
+        if (!current_item)
+        {
+            return;
         }
-	}
+        static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->performAction(getActivePanel()->getModel(), "goto");
+        }
+    }
 
-	if (command_name == "find_links")
-	{
+    if (command_name == "find_links")
+    {
         if(mSingleFolderMode && isGalleryViewMode())
         {
             LLFloaterSidePanelContainer* inventory_container = newWindow();
@@ -1922,10 +1922,10 @@ void LLPanelMainInventory::onCustomAction(const LLSD& userdata)
             const std::string &item_name = current_item->getViewModelItem()->getName();
             findLinks(item_id, item_name);
         }
-	}
+    }
 
-	if (command_name == "replace_links")
-	{
+    if (command_name == "replace_links")
+    {
         LLSD params;
         if(mSingleFolderMode && isGalleryViewMode())
         {
@@ -1933,23 +1933,23 @@ void LLPanelMainInventory::onCustomAction(const LLSD& userdata)
         }
         else
         {
-		LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
-		if (current_item)
-		{
-			LLInvFVBridge* bridge = (LLInvFVBridge*)current_item->getViewModelItem();
+        LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
+        if (current_item)
+        {
+            LLInvFVBridge* bridge = (LLInvFVBridge*)current_item->getViewModelItem();
 
-			if (bridge)
-			{
-				LLInventoryObject* obj = bridge->getInventoryObject();
-				if (obj && obj->getType() != LLAssetType::AT_CATEGORY && obj->getActualType() != LLAssetType::AT_LINK_FOLDER)
-				{
-					params = LLSD(obj->getUUID());
-				}
-			}
-		}
+            if (bridge)
+            {
+                LLInventoryObject* obj = bridge->getInventoryObject();
+                if (obj && obj->getType() != LLAssetType::AT_CATEGORY && obj->getActualType() != LLAssetType::AT_LINK_FOLDER)
+                {
+                    params = LLSD(obj->getUUID());
+                }
+            }
+        }
         }
-		LLFloaterReg::showInstance("linkreplace", params);
-	}
+        LLFloaterReg::showInstance("linkreplace", params);
+    }
 
     if (command_name == "close_inv_windows")
     {
@@ -1970,20 +1970,20 @@ void LLPanelMainInventory::onCustomAction(const LLSD& userdata)
         getCurrentFilter().toggleSearchVisibilityOutfits();
     }
 
-	if (command_name == "toggle_search_trash")
-	{
+    if (command_name == "toggle_search_trash")
+    {
         getCurrentFilter().toggleSearchVisibilityTrash();
-	}
+    }
 
-	if (command_name == "toggle_search_library")
-	{
+    if (command_name == "toggle_search_library")
+    {
         getCurrentFilter().toggleSearchVisibilityLibrary();
-	}
+    }
 
-	if (command_name == "include_links")
-	{
+    if (command_name == "include_links")
+    {
         getCurrentFilter().toggleSearchVisibilityLinks();
-	}
+    }
 
     if (command_name == "share")
     {
@@ -2017,15 +2017,15 @@ void LLPanelMainInventory::onCustomAction(const LLSD& userdata)
 
 void LLPanelMainInventory::onVisibilityChange( BOOL new_visibility )
 {
-	if(!new_visibility)
-	{
-		LLMenuGL* menu = (LLMenuGL*)mMenuAddHandle.get();
-		if (menu)
-		{
-			menu->setVisible(FALSE);
-		}
-		getActivePanel()->getRootFolder()->finishRenamingItem();
-	}
+    if(!new_visibility)
+    {
+        LLMenuGL* menu = (LLMenuGL*)mMenuAddHandle.get();
+        if (menu)
+        {
+            menu->setVisible(FALSE);
+        }
+        getActivePanel()->getRootFolder()->finishRenamingItem();
+    }
 }
 
 bool LLPanelMainInventory::isSaveTextureEnabled(const LLSD& userdata)
@@ -2043,124 +2043,124 @@ bool LLPanelMainInventory::isSaveTextureEnabled(const LLSD& userdata)
             inv_item = dynamic_cast<LLViewerInventoryItem*>(static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getInventoryObject());
         }
     }
-		if(inv_item)
-		{
-			bool can_save = inv_item->checkPermissionsSet(PERM_ITEM_UNRESTRICTED);
+        if(inv_item)
+        {
+            bool can_save = inv_item->checkPermissionsSet(PERM_ITEM_UNRESTRICTED);
             LLInventoryType::EType curr_type = inv_item->getInventoryType();
-			return can_save && (curr_type == LLInventoryType::IT_TEXTURE || curr_type == LLInventoryType::IT_SNAPSHOT);
-		}
+            return can_save && (curr_type == LLInventoryType::IT_TEXTURE || curr_type == LLInventoryType::IT_SNAPSHOT);
+        }
 
-	return false;
+    return false;
 }
 
 BOOL LLPanelMainInventory::isActionEnabled(const LLSD& userdata)
 {
-	const std::string command_name = userdata.asString();
-	if (command_name == "not_empty")
-	{
-		BOOL status = FALSE;
-		LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
-		if (current_item)
-		{
-			const LLUUID& item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
-			LLInventoryModel::cat_array_t* cat_array;
-			LLInventoryModel::item_array_t* item_array;
-			gInventory.getDirectDescendentsOf(item_id, cat_array, item_array);
-			status = (0 == cat_array->size() && 0 == item_array->size());
-		}
-		return status;
-	}
-	if (command_name == "delete")
-	{
-		return getActivePanel()->isSelectionRemovable();
-	}
-	if (command_name == "save_texture")
-	{
-		return isSaveTextureEnabled(userdata);
-	}
-	if (command_name == "find_original")
-	{
+    const std::string command_name = userdata.asString();
+    if (command_name == "not_empty")
+    {
+        BOOL status = FALSE;
+        LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
+        if (current_item)
+        {
+            const LLUUID& item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
+            LLInventoryModel::cat_array_t* cat_array;
+            LLInventoryModel::item_array_t* item_array;
+            gInventory.getDirectDescendentsOf(item_id, cat_array, item_array);
+            status = (0 == cat_array->size() && 0 == item_array->size());
+        }
+        return status;
+    }
+    if (command_name == "delete")
+    {
+        return getActivePanel()->isSelectionRemovable();
+    }
+    if (command_name == "save_texture")
+    {
+        return isSaveTextureEnabled(userdata);
+    }
+    if (command_name == "find_original")
+    {
         LLUUID item_id;
         if(mSingleFolderMode && isGalleryViewMode())
         {
             item_id = mCombinationGalleryPanel->getFirstSelectedItemID();
         }
         else{
-		LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
-		if (!current_item) return FALSE;
+        LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
+        if (!current_item) return FALSE;
         item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
         }
-		const LLViewerInventoryItem *item = gInventory.getItem(item_id);
-		if (item && item->getIsLinkType() && !item->getIsBrokenLink())
-		{
-			return TRUE;
-		}
-		return FALSE;
-	}
+        const LLViewerInventoryItem *item = gInventory.getItem(item_id);
+        if (item && item->getIsLinkType() && !item->getIsBrokenLink())
+        {
+            return TRUE;
+        }
+        return FALSE;
+    }
 
-	if (command_name == "find_links")
-	{
+    if (command_name == "find_links")
+    {
         LLUUID item_id;
         if(mSingleFolderMode && isGalleryViewMode())
         {
             item_id = mCombinationGalleryPanel->getFirstSelectedItemID();
         }
         else{
-		LLFolderView* root = getActivePanel()->getRootFolder();
-		std::set<LLFolderViewItem*> selection_set = root->getSelectionList();
-		if (selection_set.size() != 1) return FALSE;
-		LLFolderViewItem* current_item = root->getCurSelectedItem();
-		if (!current_item) return FALSE;
-		item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
-        }
-		const LLInventoryObject *obj = gInventory.getObject(item_id);
-		if (obj && !obj->getIsLinkType() && LLAssetType::lookupCanLink(obj->getType()))
-		{
-			return TRUE;
-		}
-		return FALSE;
-	}
-	// This doesn't currently work, since the viewer can't change an assetID an item.
-	if (command_name == "regenerate_link")
-	{
-		LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
-		if (!current_item) return FALSE;
-		const LLUUID& item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
-		const LLViewerInventoryItem *item = gInventory.getItem(item_id);
-		if (item && item->getIsBrokenLink())
-		{
-			return TRUE;
-		}
-		return FALSE;
-	}
-
-	if (command_name == "share")
-	{
+        LLFolderView* root = getActivePanel()->getRootFolder();
+        std::set<LLFolderViewItem*> selection_set = root->getSelectionList();
+        if (selection_set.size() != 1) return FALSE;
+        LLFolderViewItem* current_item = root->getCurSelectedItem();
+        if (!current_item) return FALSE;
+        item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
+        }
+        const LLInventoryObject *obj = gInventory.getObject(item_id);
+        if (obj && !obj->getIsLinkType() && LLAssetType::lookupCanLink(obj->getType()))
+        {
+            return TRUE;
+        }
+        return FALSE;
+    }
+    // This doesn't currently work, since the viewer can't change an assetID an item.
+    if (command_name == "regenerate_link")
+    {
+        LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
+        if (!current_item) return FALSE;
+        const LLUUID& item_id = static_cast<LLFolderViewModelItemInventory*>(current_item->getViewModelItem())->getUUID();
+        const LLViewerInventoryItem *item = gInventory.getItem(item_id);
+        if (item && item->getIsBrokenLink())
+        {
+            return TRUE;
+        }
+        return FALSE;
+    }
+
+    if (command_name == "share")
+    {
         if(mSingleFolderMode && isGalleryViewMode())
         {
             return can_share_item(mCombinationGalleryPanel->getFirstSelectedItemID());
         }
         else{
-		LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
-		if (!current_item) return FALSE;
-		LLSidepanelInventory* parent = LLFloaterSidePanelContainer::getPanel<LLSidepanelInventory>("inventory");
-		return parent ? parent->canShare() : FALSE;
-        }
-	}
-	if (command_name == "empty_trash")
-	{
-		const LLUUID &trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-		LLInventoryModel::EHasChildren children = gInventory.categoryHasChildren(trash_id);
-		return children != LLInventoryModel::CHILDREN_NO && gInventory.isCategoryComplete(trash_id);
-	}
-	if (command_name == "empty_lostnfound")
-	{
-		const LLUUID &trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND);
-		LLInventoryModel::EHasChildren children = gInventory.categoryHasChildren(trash_id);
-		return children != LLInventoryModel::CHILDREN_NO && gInventory.isCategoryComplete(trash_id);
-	}
-
-	return TRUE;
+        LLFolderViewItem* current_item = getActivePanel()->getRootFolder()->getCurSelectedItem();
+        if (!current_item) return FALSE;
+        LLSidepanelInventory* parent = LLFloaterSidePanelContainer::getPanel<LLSidepanelInventory>("inventory");
+        return parent ? parent->canShare() : FALSE;
+        }
+    }
+    if (command_name == "empty_trash")
+    {
+        const LLUUID &trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+        LLInventoryModel::EHasChildren children = gInventory.categoryHasChildren(trash_id);
+        return children != LLInventoryModel::CHILDREN_NO && gInventory.isCategoryComplete(trash_id);
+    }
+    if (command_name == "empty_lostnfound")
+    {
+        const LLUUID &trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LOST_AND_FOUND);
+        LLInventoryModel::EHasChildren children = gInventory.categoryHasChildren(trash_id);
+        return children != LLInventoryModel::CHILDREN_NO && gInventory.isCategoryComplete(trash_id);
+    }
+
+    return TRUE;
 }
 
 bool LLPanelMainInventory::isActionVisible(const LLSD& userdata)
@@ -2180,47 +2180,47 @@ bool LLPanelMainInventory::isActionVisible(const LLSD& userdata)
 
 BOOL LLPanelMainInventory::isActionChecked(const LLSD& userdata)
 {
-	U32 sort_order_mask = (mSingleFolderMode && isGalleryViewMode()) ? mCombinationGalleryPanel->getSortOrder() :  getActivePanel()->getSortOrder();
-	const std::string command_name = userdata.asString();
-	if (command_name == "sort_by_name")
-	{
-		return ~sort_order_mask & LLInventoryFilter::SO_DATE;
-	}
+    U32 sort_order_mask = (mSingleFolderMode && isGalleryViewMode()) ? mCombinationGalleryPanel->getSortOrder() :  getActivePanel()->getSortOrder();
+    const std::string command_name = userdata.asString();
+    if (command_name == "sort_by_name")
+    {
+        return ~sort_order_mask & LLInventoryFilter::SO_DATE;
+    }
 
-	if (command_name == "sort_by_recent")
-	{
-		return sort_order_mask & LLInventoryFilter::SO_DATE;
-	}
+    if (command_name == "sort_by_recent")
+    {
+        return sort_order_mask & LLInventoryFilter::SO_DATE;
+    }
 
-	if (command_name == "sort_folders_by_name")
-	{
-		return sort_order_mask & LLInventoryFilter::SO_FOLDERS_BY_NAME;
-	}
+    if (command_name == "sort_folders_by_name")
+    {
+        return sort_order_mask & LLInventoryFilter::SO_FOLDERS_BY_NAME;
+    }
 
-	if (command_name == "sort_system_folders_to_top")
-	{
-		return sort_order_mask & LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
-	}
+    if (command_name == "sort_system_folders_to_top")
+    {
+        return sort_order_mask & LLInventoryFilter::SO_SYSTEM_FOLDERS_TO_TOP;
+    }
 
     if (command_name == "toggle_search_outfits")
     {
         return (getCurrentFilter().getSearchVisibilityTypes() & LLInventoryFilter::VISIBILITY_OUTFITS) != 0;
     }
 
-	if (command_name == "toggle_search_trash")
-	{
-		return (getCurrentFilter().getSearchVisibilityTypes() & LLInventoryFilter::VISIBILITY_TRASH) != 0;
-	}
+    if (command_name == "toggle_search_trash")
+    {
+        return (getCurrentFilter().getSearchVisibilityTypes() & LLInventoryFilter::VISIBILITY_TRASH) != 0;
+    }
 
-	if (command_name == "toggle_search_library")
-	{
-		return (getCurrentFilter().getSearchVisibilityTypes() & LLInventoryFilter::VISIBILITY_LIBRARY) != 0;
-	}
+    if (command_name == "toggle_search_library")
+    {
+        return (getCurrentFilter().getSearchVisibilityTypes() & LLInventoryFilter::VISIBILITY_LIBRARY) != 0;
+    }
 
-	if (command_name == "include_links")
-	{
+    if (command_name == "include_links")
+    {
         return (getCurrentFilter().getSearchVisibilityTypes() & LLInventoryFilter::VISIBILITY_LINKS) != 0;
-	}	
+    }
 
     if (command_name == "list_view")
     {
@@ -2235,20 +2235,20 @@ BOOL LLPanelMainInventory::isActionChecked(const LLSD& userdata)
         return isCombinationViewMode();
     }
 
-	return FALSE;
+    return FALSE;
 }
 
 void LLPanelMainInventory::setUploadCostIfNeeded()
 {
-	LLMenuGL* menu = (LLMenuGL*)mMenuAddHandle.get();
-	if(mNeedUploadCost && menu)
-	{
-		const std::string sound_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getSoundUploadCost());
-		const std::string animation_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getAnimationUploadCost());
+    LLMenuGL* menu = (LLMenuGL*)mMenuAddHandle.get();
+    if(mNeedUploadCost && menu)
+    {
+        const std::string sound_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getSoundUploadCost());
+        const std::string animation_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getAnimationUploadCost());
 
-		menu->getChild<LLView>("Upload Sound")->setLabelArg("[COST]", sound_upload_cost_str);
-		menu->getChild<LLView>("Upload Animation")->setLabelArg("[COST]", animation_upload_cost_str);
-	}
+        menu->getChild<LLView>("Upload Sound")->setLabelArg("[COST]", sound_upload_cost_str);
+        menu->getChild<LLView>("Upload Animation")->setLabelArg("[COST]", animation_upload_cost_str);
+    }
 }
 
 bool is_add_allowed(LLUUID folder_id)
@@ -2428,7 +2428,7 @@ void LLPanelMainInventory::updateCombinationVisibility()
         {
             mCombinationGalleryPanel->handleModifiedFilter();
         }
-        
+
         getActivePanel()->getRootFolder();
 
         if (mReshapeInvLayout
@@ -2552,7 +2552,7 @@ void LLPanelMainInventory::setViewMode(EViewModeType mode)
                 sort_order = mCombinationInventoryPanel->getSortOrder();
                 break;
         }
-            
+
         LLUUID cur_root = getCurrentSFVRoot();
         mViewMode = mode;
 
diff --git a/indra/newview/llpanelvolume.cpp b/indra/newview/llpanelvolume.cpp
index 8df70353100b5322e7eda9b1a8d2d86e371b3fe5..dacf4a5c93e92816353475ea97308ca77571cc1c 100644
--- a/indra/newview/llpanelvolume.cpp
+++ b/indra/newview/llpanelvolume.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llpanelvolume.cpp
  * @brief Object editing (position, scale, etc.) in the tools floater
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -91,7 +91,7 @@ const F32 DEFAULT_GRAVITY_MULTIPLIER = 1.f;
 const F32 DEFAULT_DENSITY = 1000.f;
 
 // "Features" Tab
-BOOL	LLPanelVolume::postBuild()
+BOOL    LLPanelVolume::postBuild()
 {
     mLabelEditObject = getChild<LLTextBox>("edit_object");
     mLabelSelectSingle = getChild<LLTextBox>("select_single");
@@ -99,12 +99,12 @@ BOOL	LLPanelVolume::postBuild()
     mCheckAnimesh = getChild<LLCheckBoxCtrl>("Animated Mesh Checkbox Ctrl");
     mCheckAnimesh->setCommitCallback(std::bind(&LLPanelVolume::onCommitAnimatedMeshCheckbox, this, std::placeholders::_1, this));
 
-	// Flexible Objects Parameters
-	{
+    // Flexible Objects Parameters
+    {
         mCheckFlexible1D = getChild<LLCheckBoxCtrl>("Flexible1D Checkbox Ctrl");
         mCheckFlexible1D->setCommitCallback(std::bind(&LLPanelVolume::onCommitIsFlexible, this, std::placeholders::_1, this));
 
-		mSpinSections = getChild<LLSpinCtrl>("FlexNumSections");
+        mSpinSections = getChild<LLSpinCtrl>("FlexNumSections");
         mSpinSections->setValidateBeforeCommit(precommitValidate);
         mSpinSections->setCommitCallback(std::bind(onCommitFlexible, std::placeholders::_1, this));
 
@@ -135,14 +135,14 @@ BOOL	LLPanelVolume::postBuild()
         mSpinForceZ = getChild<LLSpinCtrl>("FlexForceZ");
         mSpinForceZ->setValidateBeforeCommit(precommitValidate);
         mSpinForceZ->setCommitCallback(std::bind(onCommitFlexible, std::placeholders::_1, this));
-	}
+    }
 
-	// LIGHT Parameters
-	{
+    // LIGHT Parameters
+    {
         mCheckLight = getChild<LLCheckBoxCtrl>("Light Checkbox Ctrl");
         mCheckLight->setCommitCallback(std::bind(onCommitIsLight, std::placeholders::_1, this));
 
-		mLightColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
+        mLightColorSwatch = getChild<LLColorSwatchCtrl>("colorswatch");
         mLightColorSwatch->setOnCancelCallback(std::bind(&LLPanelVolume::onLightCancelColor, this, std::placeholders::_2));
         mLightColorSwatch->setOnSelectCallback(std::bind(&LLPanelVolume::onLightSelectColor, this, std::placeholders::_2));
         mLightColorSwatch->setCommitCallback(std::bind(onCommitLight, std::placeholders::_1, this));
@@ -152,7 +152,7 @@ BOOL	LLPanelVolume::postBuild()
         mLightTextureCtrl->setOnSelectCallback(boost::bind(&LLPanelVolume::onLightSelectTexture, this, _2));
         mLightTextureCtrl->setCommitCallback(std::bind(onCommitLight, std::placeholders::_1, this));
 
-		mLightIntensity = getChild<LLSpinCtrl>("Light Intensity");
+        mLightIntensity = getChild<LLSpinCtrl>("Light Intensity");
         mLightIntensity->setValidateBeforeCommit(precommitValidate);
         mLightIntensity->setCommitCallback(std::bind(onCommitLight, std::placeholders::_1, this));
 
@@ -160,23 +160,23 @@ BOOL	LLPanelVolume::postBuild()
         mLightRadius->setValidateBeforeCommit(precommitValidate);
         mLightRadius->setCommitCallback(std::bind(onCommitLight, std::placeholders::_1, this));
 
-		mLightFalloff = getChild<LLSpinCtrl>("Light Falloff");
+        mLightFalloff = getChild<LLSpinCtrl>("Light Falloff");
         mLightFalloff->setValidateBeforeCommit(precommitValidate);
         mLightFalloff->setCommitCallback(std::bind(onCommitLight, std::placeholders::_1, this));
 
-		mLightFOV = getChild<LLSpinCtrl>("Light FOV");
+        mLightFOV = getChild<LLSpinCtrl>("Light FOV");
         mLightFOV->setValidateBeforeCommit(precommitValidate);
         mLightFOV->setCommitCallback(std::bind(onCommitLight, std::placeholders::_1, this));
 
-		mLightFocus = getChild<LLSpinCtrl>("Light Focus");
+        mLightFocus = getChild<LLSpinCtrl>("Light Focus");
         mLightFocus->setValidateBeforeCommit(precommitValidate);
         mLightFocus->setCommitCallback(std::bind(onCommitLight, std::placeholders::_1, this));
 
         mLightAmbiance = getChild<LLSpinCtrl>("Light Ambiance");
         mLightAmbiance->setValidateBeforeCommit(precommitValidate);
         mLightAmbiance->setCommitCallback(std::bind(onCommitLight, std::placeholders::_1, this));
-	}
-	
+    }
+
     // REFLECTION PROBE Parameters
     {
         childSetCommitCallback("Reflection Probe", onCommitIsReflectionProbe, this);
@@ -187,30 +187,30 @@ BOOL	LLPanelVolume::postBuild()
         childSetCommitCallback("Probe Near Clip", onCommitProbe, this);
     }
 
-	// PHYSICS Parameters
-	{
+    // PHYSICS Parameters
+    {
         mLabelPhysicsShapeType = getChild<LLTextBox>("label physicsshapetype");
 
-		// PhysicsShapeType combobox
-		mComboPhysicsShapeType = getChild<LLComboBox>("Physics Shape Type Combo Ctrl");
-		mComboPhysicsShapeType->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsShapeType, this, _1, mComboPhysicsShapeType));
-	
-		// PhysicsGravity
-		mSpinPhysicsGravity = getChild<LLSpinCtrl>("Physics Gravity");
-		mSpinPhysicsGravity->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsGravity, this, _1, mSpinPhysicsGravity));
+        // PhysicsShapeType combobox
+        mComboPhysicsShapeType = getChild<LLComboBox>("Physics Shape Type Combo Ctrl");
+        mComboPhysicsShapeType->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsShapeType, this, _1, mComboPhysicsShapeType));
 
-		// PhysicsFriction
-		mSpinPhysicsFriction = getChild<LLSpinCtrl>("Physics Friction");
-		mSpinPhysicsFriction->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsFriction, this, _1, mSpinPhysicsFriction));
+        // PhysicsGravity
+        mSpinPhysicsGravity = getChild<LLSpinCtrl>("Physics Gravity");
+        mSpinPhysicsGravity->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsGravity, this, _1, mSpinPhysicsGravity));
 
-		// PhysicsDensity
-		mSpinPhysicsDensity = getChild<LLSpinCtrl>("Physics Density");
-		mSpinPhysicsDensity->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsDensity, this, _1, mSpinPhysicsDensity));
+        // PhysicsFriction
+        mSpinPhysicsFriction = getChild<LLSpinCtrl>("Physics Friction");
+        mSpinPhysicsFriction->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsFriction, this, _1, mSpinPhysicsFriction));
 
-		// PhysicsRestitution
-		mSpinPhysicsRestitution = getChild<LLSpinCtrl>("Physics Restitution");
-		mSpinPhysicsRestitution->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsRestitution, this, _1, mSpinPhysicsRestitution));
-	}
+        // PhysicsDensity
+        mSpinPhysicsDensity = getChild<LLSpinCtrl>("Physics Density");
+        mSpinPhysicsDensity->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsDensity, this, _1, mSpinPhysicsDensity));
+
+        // PhysicsRestitution
+        mSpinPhysicsRestitution = getChild<LLSpinCtrl>("Physics Restitution");
+        mSpinPhysicsRestitution->setCommitCallback(boost::bind(&LLPanelVolume::sendPhysicsRestitution, this, _1, mSpinPhysicsRestitution));
+    }
 
     mBtnCopyFeatures = findChild<LLButton>("copy_features_btn");
     mBtnCopyFeatures->setCommitCallback([this](LLUICtrl*, const LLSD&) { onCopyFeatures(); });
@@ -226,45 +226,45 @@ BOOL	LLPanelVolume::postBuild()
     mBtnPipetteLight = findChild<LLButton>("pipette_light_btn");
     mBtnPipetteLight->setCommitCallback([this](LLUICtrl*, const LLSD&) { onClickPipetteLight(); });
 
-	std::map<std::string, std::string> material_name_map;
-	material_name_map["Stone"]= LLTrans::getString("Stone");
-	material_name_map["Metal"]= LLTrans::getString("Metal");	
-	material_name_map["Glass"]= LLTrans::getString("Glass");	
-	material_name_map["Wood"]= LLTrans::getString("Wood");	
-	material_name_map["Flesh"]= LLTrans::getString("Flesh");
-	material_name_map["Plastic"]= LLTrans::getString("Plastic");
-	material_name_map["Rubber"]= LLTrans::getString("Rubber");	
-	material_name_map["Light"]= LLTrans::getString("Light");		
-	
-	LLMaterialTable::basic.initTableTransNames(material_name_map);
-
-	// material type popup
-	mComboMaterial = getChild<LLComboBox>("material");
+    std::map<std::string, std::string> material_name_map;
+    material_name_map["Stone"]= LLTrans::getString("Stone");
+    material_name_map["Metal"]= LLTrans::getString("Metal");
+    material_name_map["Glass"]= LLTrans::getString("Glass");
+    material_name_map["Wood"]= LLTrans::getString("Wood");
+    material_name_map["Flesh"]= LLTrans::getString("Flesh");
+    material_name_map["Plastic"]= LLTrans::getString("Plastic");
+    material_name_map["Rubber"]= LLTrans::getString("Rubber");
+    material_name_map["Light"]= LLTrans::getString("Light");
+
+    LLMaterialTable::basic.initTableTransNames(material_name_map);
+
+    // material type popup
+    mComboMaterial = getChild<LLComboBox>("material");
     mComboMaterial->setCommitCallback(std::bind(onCommitMaterial, std::placeholders::_1, this));
-	mComboMaterial->removeall();
-
-	for (LLMaterialTable::info_list_t::iterator iter = LLMaterialTable::basic.mMaterialInfoList.begin();
-		 iter != LLMaterialTable::basic.mMaterialInfoList.end(); ++iter)
-	{
-		LLMaterialInfo* minfop = *iter;
-		if (minfop->mMCode != LL_MCODE_LIGHT)
-		{
-			mComboMaterial->add(minfop->mName);  
-		}
-	}
-	mComboMaterialItemCount = mComboMaterial->getItemCount();
-	
-	// Start with everyone disabled
-	clearCtrls();
-
-	return TRUE;
+    mComboMaterial->removeall();
+
+    for (LLMaterialTable::info_list_t::iterator iter = LLMaterialTable::basic.mMaterialInfoList.begin();
+         iter != LLMaterialTable::basic.mMaterialInfoList.end(); ++iter)
+    {
+        LLMaterialInfo* minfop = *iter;
+        if (minfop->mMCode != LL_MCODE_LIGHT)
+        {
+            mComboMaterial->add(minfop->mName);
+        }
+    }
+    mComboMaterialItemCount = mComboMaterial->getItemCount();
+
+    // Start with everyone disabled
+    clearCtrls();
+
+    return TRUE;
 }
 
 LLPanelVolume::LLPanelVolume()
-	: LLPanel(),
-	  mComboMaterialItemCount(0)
+    : LLPanel(),
+      mComboMaterialItemCount(0)
 {
-	setMouseOpaque(FALSE);
+    setMouseOpaque(FALSE);
 
     mCommitCallbackRegistrar.add("PanelVolume.menuDoToSelected", boost::bind(&LLPanelVolume::menuDoToSelected, this, _2));
     mEnableCallbackRegistrar.add("PanelVolume.menuEnable", boost::bind(&LLPanelVolume::menuEnableItem, this, _2));
@@ -273,129 +273,129 @@ LLPanelVolume::LLPanelVolume()
 
 LLPanelVolume::~LLPanelVolume()
 {
-	// Children all cleaned up by default view destructor.
+    // Children all cleaned up by default view destructor.
 }
 
 void LLPanelVolume::getState( )
 {
-	LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject();
-	LLViewerObject* root_objectp = objectp;
-	if(!objectp)
-	{
-		objectp = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
-		// *FIX: shouldn't we just keep the child?
-		if (objectp)
-		{
-			LLViewerObject* parentp = objectp->getRootEdit();
-
-			if (parentp)
-			{
-				root_objectp = parentp;
-			}
-			else
-			{
-				root_objectp = objectp;
-			}
-		}
-	}
-
-	LLVOVolume *volobjp = NULL;
-	if ( objectp && (objectp->getPCode() == LL_PCODE_VOLUME))
-	{
-		volobjp = (LLVOVolume *)objectp;
-	}
-	LLVOVolume *root_volobjp = NULL;
+    LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject();
+    LLViewerObject* root_objectp = objectp;
+    if(!objectp)
+    {
+        objectp = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
+        // *FIX: shouldn't we just keep the child?
+        if (objectp)
+        {
+            LLViewerObject* parentp = objectp->getRootEdit();
+
+            if (parentp)
+            {
+                root_objectp = parentp;
+            }
+            else
+            {
+                root_objectp = objectp;
+            }
+        }
+    }
+
+    LLVOVolume *volobjp = NULL;
+    if ( objectp && (objectp->getPCode() == LL_PCODE_VOLUME))
+    {
+        volobjp = (LLVOVolume *)objectp;
+    }
+    LLVOVolume *root_volobjp = NULL;
     if (root_objectp && (root_objectp->getPCode() == LL_PCODE_VOLUME))
     {
         root_volobjp  = (LLVOVolume *)root_objectp;
     }
-	
-	if( !objectp )
-	{
-		//forfeit focus
-		if (gFocusMgr.childHasKeyboardFocus(this))
-		{
-			gFocusMgr.setKeyboardFocus(NULL);
-		}
-
-		// Disable all text input fields
-		clearCtrls();
-
-		return;
-	}
-
-	LLUUID owner_id;
-	std::string owner_name;
-	LLSelectMgr::getInstance()->selectGetOwner(owner_id, owner_name);
-
-	// BUG? Check for all objects being editable?
-	BOOL editable = root_objectp->permModify() && !root_objectp->isPermanentEnforced();
-	BOOL single_volume = LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME )
-		&& LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 1;
-    BOOL single_root_volume = LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME ) && 
+
+    if( !objectp )
+    {
+        //forfeit focus
+        if (gFocusMgr.childHasKeyboardFocus(this))
+        {
+            gFocusMgr.setKeyboardFocus(NULL);
+        }
+
+        // Disable all text input fields
+        clearCtrls();
+
+        return;
+    }
+
+    LLUUID owner_id;
+    std::string owner_name;
+    LLSelectMgr::getInstance()->selectGetOwner(owner_id, owner_name);
+
+    // BUG? Check for all objects being editable?
+    BOOL editable = root_objectp->permModify() && !root_objectp->isPermanentEnforced();
+    BOOL single_volume = LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME )
+        && LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 1;
+    BOOL single_root_volume = LLSelectMgr::getInstance()->selectionAllPCode( LL_PCODE_VOLUME ) &&
         LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() == 1;
 
-	// Select Single Message
-	if (single_volume)
-	{
+    // Select Single Message
+    if (single_volume)
+    {
         mLabelEditObject->setVisible(true);
         mLabelEditObject->setEnabled(true);
         mLabelSelectSingle->setVisible(false);
-	}
-	else
-	{	
-		mLabelEditObject->setVisible(false);
+    }
+    else
+    {
+        mLabelEditObject->setVisible(false);
         mLabelSelectSingle->setVisible(true);
         mLabelSelectSingle->setEnabled(true);
-	}
-    
-	// Light properties
-	BOOL is_light = volobjp && volobjp->getIsLight();
+    }
+
+    // Light properties
+    BOOL is_light = volobjp && volobjp->getIsLight();
     mCheckLight->setValue(is_light);
     mCheckLight->setEnabled(editable && single_volume && volobjp);
-	
-	if (is_light && editable && single_volume)
-	{
-		//mLabelColor		 ->setEnabled( TRUE );
 
-		mLightColorSwatch->setEnabled( TRUE );
-		mLightColorSwatch->setValid( TRUE );
-		mLightColorSwatch->set(volobjp->getLightSRGBBaseColor());
+    if (is_light && editable && single_volume)
+    {
+        //mLabelColor        ->setEnabled( TRUE );
+
+        mLightColorSwatch->setEnabled( TRUE );
+        mLightColorSwatch->setValid( TRUE );
+        mLightColorSwatch->set(volobjp->getLightSRGBBaseColor());
 
-		mLightTextureCtrl->setEnabled(TRUE);
-		mLightTextureCtrl->setValid(TRUE);
-		mLightTextureCtrl->setImageAssetID(volobjp->getLightTextureID());
+        mLightTextureCtrl->setEnabled(TRUE);
+        mLightTextureCtrl->setValid(TRUE);
+        mLightTextureCtrl->setImageAssetID(volobjp->getLightTextureID());
 
-		mLightIntensity->setEnabled(true);
+        mLightIntensity->setEnabled(true);
         mLightRadius->setEnabled(true);
         mLightFalloff->setEnabled(true);
 
-		mLightFOV->setEnabled(true);
+        mLightFOV->setEnabled(true);
         mLightFocus->setEnabled(true);
         mLightAmbiance->setEnabled(true);
-		
-		mLightIntensity->setValue(volobjp->getLightIntensity());
+
+        mLightIntensity->setValue(volobjp->getLightIntensity());
         mLightRadius->setValue(volobjp->getLightRadius());
         mLightFalloff->setValue(volobjp->getLightFalloff());
 
-		LLVector3 params = volobjp->getSpotLightParams();
+        LLVector3 params = volobjp->getSpotLightParams();
         mLightFOV->setValue(params.mV[0]);
         mLightFocus->setValue(params.mV[1]);
         mLightAmbiance->setValue(params.mV[2]);
 
-		mLightSavedColor = volobjp->getLightSRGBBaseColor();
-	}
-	else
-	{
+        mLightSavedColor = volobjp->getLightSRGBBaseColor();
+    }
+    else
+    {
         mLightIntensity->clear();
         mLightRadius->clear();
         mLightFalloff->clear();
 
-		mLightColorSwatch->setEnabled( FALSE );
-		mLightColorSwatch->setValid( FALSE );
+        mLightColorSwatch->setEnabled( FALSE );
+        mLightColorSwatch->setValid( FALSE );
 
-		mLightTextureCtrl->setEnabled(FALSE);
-		mLightTextureCtrl->setValid(FALSE);
+        mLightTextureCtrl->setEnabled(FALSE);
+        mLightTextureCtrl->setValid(FALSE);
 
         if (objectp->isAttachment())
         {
@@ -406,14 +406,14 @@ void LLPanelVolume::getState( )
             mLightTextureCtrl->setImmediateFilterPermMask(PERM_NONE);
         }
 
-		mLightIntensity->setEnabled(false);
+        mLightIntensity->setEnabled(false);
         mLightRadius->setEnabled(false);
         mLightFalloff->setEnabled(false);
 
-		mLightFOV->setEnabled(false);
+        mLightFOV->setEnabled(false);
         mLightFocus->setEnabled(false);
         mLightAmbiance->setEnabled(false);
-	}
+    }
 
     // Reflection Probe
     BOOL is_probe = volobjp && volobjp->isReflectionProbe();
@@ -448,7 +448,7 @@ void LLPanelVolume::getState( )
             volume_type = "Sphere";
         }
 
-//		std::string update_type = "Static";
+//      std::string update_type = "Static";
 //
 //        if (volobjp->getReflectionProbeIsDynamic() && !volobjp->getReflectionProbeIsMirror())
 //        {
@@ -460,10 +460,10 @@ void LLPanelVolume::getState( )
 //
 //        }
 //        else if (volobjp->getReflectionProbeIsDynamic() && volobjp->getReflectionProbeIsMirror())
-//		{
-//			update_type = "Dynamic Mirror";
-//		}
-//		
+//      {
+//          update_type = "Dynamic Mirror";
+//      }
+//
         bool is_mirror = volobjp->getReflectionProbeIsMirror();
 
         getChildView("Probe Ambiance")->setEnabled(!is_mirror);
@@ -477,12 +477,12 @@ void LLPanelVolume::getState( )
     }
 
     // Animated Mesh
-	BOOL is_animated_mesh = single_root_volume && root_volobjp && root_volobjp->isAnimatedObject();
+    BOOL is_animated_mesh = single_root_volume && root_volobjp && root_volobjp->isAnimatedObject();
     mCheckAnimesh->setValue(is_animated_mesh);
     BOOL enabled_animated_object_box = FALSE;
     if (root_volobjp && root_volobjp == volobjp)
     {
-        enabled_animated_object_box = single_root_volume && root_volobjp && root_volobjp->canBeAnimatedObject() && editable; 
+        enabled_animated_object_box = single_root_volume && root_volobjp && root_volobjp->canBeAnimatedObject() && editable;
 #if 0
         if (!enabled_animated_object_box)
         {
@@ -495,7 +495,7 @@ void LLPanelVolume::getState( )
             }
         }
 #endif
-        if (enabled_animated_object_box && !is_animated_mesh && 
+        if (enabled_animated_object_box && !is_animated_mesh &&
             root_volobjp->isAttachment() && !gAgentAvatarp->canAttachMoreAnimatedObjects())
         {
             // Turning this attachment animated would cause us to exceed the limit.
@@ -503,42 +503,42 @@ void LLPanelVolume::getState( )
         }
     }
     mCheckAnimesh->setEnabled(enabled_animated_object_box);
-	
-	//refresh any bakes
-	if (root_volobjp)
-	{
-		root_volobjp->refreshBakeTexture();
 
-		LLViewerObject::const_child_list_t& child_list = root_volobjp->getChildren();
+    //refresh any bakes
+    if (root_volobjp)
+    {
+        root_volobjp->refreshBakeTexture();
+
+        LLViewerObject::const_child_list_t& child_list = root_volobjp->getChildren();
         for (LLViewerObject* objectp : child_list)
-		{
-			if (objectp)
-			{
-				objectp->refreshBakeTexture();
-			}
-		}
-
-		if (gAgentAvatarp)
-		{
-			gAgentAvatarp->updateMeshVisibility();
-		}
-	}
-
-	// Flexible properties
-	BOOL is_flexible = volobjp && volobjp->isFlexible();
+        {
+            if (objectp)
+            {
+                objectp->refreshBakeTexture();
+            }
+        }
+
+        if (gAgentAvatarp)
+        {
+            gAgentAvatarp->updateMeshVisibility();
+        }
+    }
+
+    // Flexible properties
+    BOOL is_flexible = volobjp && volobjp->isFlexible();
     mCheckFlexible1D->setValue(is_flexible);
-	if (is_flexible || (volobjp && volobjp->canBeFlexible()))
-	{
+    if (is_flexible || (volobjp && volobjp->canBeFlexible()))
+    {
         mCheckFlexible1D->setEnabled(editable && single_volume && volobjp && !volobjp->isMesh() && !objectp->isPermanentEnforced());
-	}
-	else
-	{
+    }
+    else
+    {
         mCheckFlexible1D->setEnabled(false);
-	}
-	if (is_flexible && editable && single_volume)
-	{
+    }
+    if (is_flexible && editable && single_volume)
+    {
         mSpinSections->setVisible(true);
-		mSpinGravity->setVisible(true);
+        mSpinGravity->setVisible(true);
         mSpinTension->setVisible(true);
         mSpinFriction->setVisible(true);
         mSpinWind->setVisible(true);
@@ -546,7 +546,7 @@ void LLPanelVolume::getState( )
         mSpinForceY->setVisible(true);
         mSpinForceZ->setVisible(true);
 
-		mSpinSections->setEnabled(true);
+        mSpinSections->setEnabled(true);
         mSpinGravity->setEnabled(true);
         mSpinTension->setEnabled(true);
         mSpinFriction->setEnabled(true);
@@ -555,9 +555,9 @@ void LLPanelVolume::getState( )
         mSpinForceY->setEnabled(true);
         mSpinForceZ->setEnabled(true);
 
-		LLFlexibleObjectData *attributes = (LLFlexibleObjectData *)objectp->getFlexibleObjectData();
-		
-		mSpinSections->setValue((F32) attributes->getSimulateLOD());
+        LLFlexibleObjectData *attributes = (LLFlexibleObjectData *)objectp->getFlexibleObjectData();
+
+        mSpinSections->setValue((F32) attributes->getSimulateLOD());
         mSpinGravity->setValue(attributes->getGravity());
         mSpinTension->setValue(attributes->getTension());
         mSpinFriction->setValue(attributes->getAirFriction());
@@ -565,19 +565,19 @@ void LLPanelVolume::getState( )
         mSpinForceX->setValue(attributes->getUserForce().mV[VX]);
         mSpinForceY->setValue(attributes->getUserForce().mV[VY]);
         mSpinForceZ->setValue(attributes->getUserForce().mV[VZ]);
-	}
-	else
-	{
+    }
+    else
+    {
         mSpinSections->clear();
         mSpinGravity->clear();
         mSpinTension->clear();
-		mSpinFriction->clear();
-		mSpinWind->clear();
-		mSpinForceX->clear();
+        mSpinFriction->clear();
+        mSpinWind->clear();
+        mSpinForceX->clear();
         mSpinForceY->clear();
         mSpinForceZ->clear();
 
-		mSpinSections->setEnabled(false);
+        mSpinSections->setEnabled(false);
         mSpinGravity->setEnabled(false);
         mSpinTension->setEnabled(false);
         mSpinFriction->setEnabled(false);
@@ -585,98 +585,98 @@ void LLPanelVolume::getState( )
         mSpinForceX->setEnabled(false);
         mSpinForceY->setEnabled(false);
         mSpinForceZ->setEnabled(false);
-	}
-	
-	// Material properties
-
-	// Update material part
-	// slightly inefficient - materials are unique per object, not per TE
-	U8 material_code = 0;
-	struct f : public LLSelectedTEGetFunctor<U8>
-	{
-		U8 get(LLViewerObject* object, S32 te)
-		{
-			return object->getMaterial();
-		}
-	} func;
-	bool material_same = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, material_code );
-	std::string LEGACY_FULLBRIGHT_DESC = LLTrans::getString("Fullbright");
-	if (editable && single_volume && material_same)
-	{
-		mComboMaterial->setEnabled( TRUE );
-		if (material_code == LL_MCODE_LIGHT)
-		{
-			if (mComboMaterial->getItemCount() == mComboMaterialItemCount)
-			{
-				mComboMaterial->add(LEGACY_FULLBRIGHT_DESC);
-			}
-			mComboMaterial->setSimple(LEGACY_FULLBRIGHT_DESC);
-		}
-		else
-		{
-			if (mComboMaterial->getItemCount() != mComboMaterialItemCount)
-			{
-				mComboMaterial->remove(LEGACY_FULLBRIGHT_DESC);
-			}
-			
-			mComboMaterial->setSimple(std::string(LLMaterialTable::basic.getName(material_code)));
-		}
-	}
-	else
-	{
-		mComboMaterial->setEnabled( FALSE );
-	}
-
-	// Physics properties
-	
-	mSpinPhysicsGravity->set(objectp->getPhysicsGravity());
-	mSpinPhysicsGravity->setEnabled(editable);
-
-	mSpinPhysicsFriction->set(objectp->getPhysicsFriction());
-	mSpinPhysicsFriction->setEnabled(editable);
-	
-	mSpinPhysicsDensity->set(objectp->getPhysicsDensity());
-	mSpinPhysicsDensity->setEnabled(editable);
-	
-	mSpinPhysicsRestitution->set(objectp->getPhysicsRestitution());
-	mSpinPhysicsRestitution->setEnabled(editable);
-
-	// update the physics shape combo to include allowed physics shapes
-	mComboPhysicsShapeType->removeall();
-	mComboPhysicsShapeType->add(getString("None"), LLSD(1));
-
-	BOOL isMesh = FALSE;
-	LLSculptParams *sculpt_params = (LLSculptParams *)objectp->getSculptParams();
-	if (sculpt_params)
-	{
-		U8 sculpt_type = sculpt_params->getSculptType();
-		U8 sculpt_stitching = sculpt_type & LL_SCULPT_TYPE_MASK;
-		isMesh = (sculpt_stitching == LL_SCULPT_TYPE_MESH);
-	}
-
-	if(isMesh && objectp)
-	{
-		const LLVolumeParams &volume_params = objectp->getVolume()->getParams();
-		LLUUID mesh_id = volume_params.getSculptID();
-		if(gMeshRepo.hasPhysicsShape(mesh_id))
-		{
-			// if a mesh contains an uploaded or decomposed physics mesh,
-			// allow 'Prim'
-			mComboPhysicsShapeType->add(getString("Prim"), LLSD(0));			
-		}
-	}
-	else
-	{
-		// simple prims always allow physics shape prim
-		mComboPhysicsShapeType->add(getString("Prim"), LLSD(0));	
-	}
-
-	mComboPhysicsShapeType->add(getString("Convex Hull"), LLSD(2));	
-	mComboPhysicsShapeType->setValue(LLSD(objectp->getPhysicsShapeType()));
-	mComboPhysicsShapeType->setEnabled(editable && !objectp->isPermanentEnforced() && ((root_objectp == NULL) || !root_objectp->isPermanentEnforced()));
-
-	mObject = objectp;
-	mRootObject = root_objectp;
+    }
+
+    // Material properties
+
+    // Update material part
+    // slightly inefficient - materials are unique per object, not per TE
+    U8 material_code = 0;
+    struct f : public LLSelectedTEGetFunctor<U8>
+    {
+        U8 get(LLViewerObject* object, S32 te)
+        {
+            return object->getMaterial();
+        }
+    } func;
+    bool material_same = LLSelectMgr::getInstance()->getSelection()->getSelectedTEValue( &func, material_code );
+    std::string LEGACY_FULLBRIGHT_DESC = LLTrans::getString("Fullbright");
+    if (editable && single_volume && material_same)
+    {
+        mComboMaterial->setEnabled( TRUE );
+        if (material_code == LL_MCODE_LIGHT)
+        {
+            if (mComboMaterial->getItemCount() == mComboMaterialItemCount)
+            {
+                mComboMaterial->add(LEGACY_FULLBRIGHT_DESC);
+            }
+            mComboMaterial->setSimple(LEGACY_FULLBRIGHT_DESC);
+        }
+        else
+        {
+            if (mComboMaterial->getItemCount() != mComboMaterialItemCount)
+            {
+                mComboMaterial->remove(LEGACY_FULLBRIGHT_DESC);
+            }
+
+            mComboMaterial->setSimple(std::string(LLMaterialTable::basic.getName(material_code)));
+        }
+    }
+    else
+    {
+        mComboMaterial->setEnabled( FALSE );
+    }
+
+    // Physics properties
+
+    mSpinPhysicsGravity->set(objectp->getPhysicsGravity());
+    mSpinPhysicsGravity->setEnabled(editable);
+
+    mSpinPhysicsFriction->set(objectp->getPhysicsFriction());
+    mSpinPhysicsFriction->setEnabled(editable);
+
+    mSpinPhysicsDensity->set(objectp->getPhysicsDensity());
+    mSpinPhysicsDensity->setEnabled(editable);
+
+    mSpinPhysicsRestitution->set(objectp->getPhysicsRestitution());
+    mSpinPhysicsRestitution->setEnabled(editable);
+
+    // update the physics shape combo to include allowed physics shapes
+    mComboPhysicsShapeType->removeall();
+    mComboPhysicsShapeType->add(getString("None"), LLSD(1));
+
+    BOOL isMesh = FALSE;
+    LLSculptParams *sculpt_params = (LLSculptParams *)objectp->getSculptParams();
+    if (sculpt_params)
+    {
+        U8 sculpt_type = sculpt_params->getSculptType();
+        U8 sculpt_stitching = sculpt_type & LL_SCULPT_TYPE_MASK;
+        isMesh = (sculpt_stitching == LL_SCULPT_TYPE_MESH);
+    }
+
+    if(isMesh && objectp)
+    {
+        const LLVolumeParams &volume_params = objectp->getVolume()->getParams();
+        LLUUID mesh_id = volume_params.getSculptID();
+        if(gMeshRepo.hasPhysicsShape(mesh_id))
+        {
+            // if a mesh contains an uploaded or decomposed physics mesh,
+            // allow 'Prim'
+            mComboPhysicsShapeType->add(getString("Prim"), LLSD(0));
+        }
+    }
+    else
+    {
+        // simple prims always allow physics shape prim
+        mComboPhysicsShapeType->add(getString("Prim"), LLSD(0));
+    }
+
+    mComboPhysicsShapeType->add(getString("Convex Hull"), LLSD(2));
+    mComboPhysicsShapeType->setValue(LLSD(objectp->getPhysicsShapeType()));
+    mComboPhysicsShapeType->setEnabled(editable && !objectp->isPermanentEnforced() && ((root_objectp == NULL) || !root_objectp->isPermanentEnforced()));
+
+    mObject = objectp;
+    mRootObject = root_objectp;
 
     mBtnCopyFeatures->setEnabled(editable&& single_volume && volobjp); // Note: physics doesn't need to be limited by single volume
     mBtnPasteFeatures->setEnabled(editable&& single_volume && volobjp && mClipboardParams.has("features"));
@@ -689,70 +689,70 @@ void LLPanelVolume::getState( )
 // static
 bool LLPanelVolume::precommitValidate( const LLSD& data )
 {
-	// TODO: Richard will fill this in later.  
-	return TRUE; // FALSE means that validation failed and new value should not be commited.
+    // TODO: Richard will fill this in later.
+    return TRUE; // FALSE means that validation failed and new value should not be commited.
 }
 
 
 void LLPanelVolume::refresh()
 {
-	getState();
-	if (mObject.notNull() && mObject->isDead())
-	{
-		mObject = NULL;
-	}
-
-	if (mRootObject.notNull() && mRootObject->isDead())
-	{
-		mRootObject = NULL;
-	}
-
-	bool enable_mesh = false;
-
-	LLSD sim_features;
-	LLViewerRegion *region = gAgent.getRegion();
-	if(region)
-	{
-		LLSD sim_features;
-		region->getSimulatorFeatures(sim_features);		 
-		enable_mesh = sim_features.has("PhysicsShapeTypes");
-	}
+    getState();
+    if (mObject.notNull() && mObject->isDead())
+    {
+        mObject = NULL;
+    }
+
+    if (mRootObject.notNull() && mRootObject->isDead())
+    {
+        mRootObject = NULL;
+    }
+
+    bool enable_mesh = false;
+
+    LLSD sim_features;
+    LLViewerRegion *region = gAgent.getRegion();
+    if(region)
+    {
+        LLSD sim_features;
+        region->getSimulatorFeatures(sim_features);
+        enable_mesh = sim_features.has("PhysicsShapeTypes");
+    }
     mLabelPhysicsShapeType->setVisible(enable_mesh);
     mComboPhysicsShapeType->setVisible(enable_mesh);
     mSpinPhysicsGravity->setVisible(enable_mesh);
     mSpinPhysicsFriction->setVisible(enable_mesh);
     mSpinPhysicsDensity->setVisible(enable_mesh);
     mSpinPhysicsRestitution->setVisible(enable_mesh);
-	
+
     /* TODO: add/remove individual physics shape types as per the PhysicsShapeTypes simulator features */
 }
 
 
 void LLPanelVolume::draw()
 {
-	LLPanel::draw();
+    LLPanel::draw();
 }
 
 // virtual
 void LLPanelVolume::clearCtrls()
 {
-	LLPanel::clearCtrls();
+    LLPanel::clearCtrls();
 
-	mLabelSelectSingle->setEnabled(false);
+    mLabelSelectSingle->setEnabled(false);
     mLabelSelectSingle->setVisible(true);
-	mLabelEditObject->setEnabled(false);
+    mLabelEditObject->setEnabled(false);
     mLabelEditObject->setVisible(false);
     mCheckLight->setEnabled(false);
 
-	mLightColorSwatch->setEnabled( FALSE );
-	mLightColorSwatch->setValid( FALSE );
-	mLightTextureCtrl->setEnabled( FALSE );
-	mLightTextureCtrl->setValid( FALSE );
+    mLightColorSwatch->setEnabled( FALSE );
+    mLightColorSwatch->setValid( FALSE );
+    mLightTextureCtrl->setEnabled( FALSE );
+    mLightTextureCtrl->setValid( FALSE );
 
-	mLightIntensity->setEnabled(false);
+    mLightIntensity->setEnabled(false);
     mLightRadius->setEnabled(false);
     mLightFalloff->setEnabled(false);
-	mLightFOV->setEnabled(false);
+    mLightFOV->setEnabled(false);
     mLightFocus->setEnabled(false);
     mLightAmbiance->setEnabled(false);
 
@@ -765,20 +765,20 @@ void LLPanelVolume::clearCtrls()
     mCheckAnimesh->setEnabled(false);
     mCheckFlexible1D->setEnabled(false);
     mSpinSections->setEnabled(false);
-	mSpinGravity->setEnabled(false);
+    mSpinGravity->setEnabled(false);
     mSpinTension->setEnabled(false);
-	mSpinFriction->setEnabled(false);
-	mSpinWind->setEnabled(false);
-	mSpinForceX->setEnabled(false);
+    mSpinFriction->setEnabled(false);
+    mSpinWind->setEnabled(false);
+    mSpinForceX->setEnabled(false);
     mSpinForceY->setEnabled(false);
     mSpinForceZ->setEnabled(false);
 
-	mSpinPhysicsGravity->setEnabled(FALSE);
-	mSpinPhysicsFriction->setEnabled(FALSE);
-	mSpinPhysicsDensity->setEnabled(FALSE);
-	mSpinPhysicsRestitution->setEnabled(FALSE);
+    mSpinPhysicsGravity->setEnabled(FALSE);
+    mSpinPhysicsFriction->setEnabled(FALSE);
+    mSpinPhysicsDensity->setEnabled(FALSE);
+    mSpinPhysicsRestitution->setEnabled(FALSE);
 
-	mComboMaterial->setEnabled( FALSE );
+    mComboMaterial->setEnabled( FALSE );
 }
 
 //
@@ -787,16 +787,16 @@ void LLPanelVolume::clearCtrls()
 
 void LLPanelVolume::sendIsLight()
 {
-	LLViewerObject* objectp = mObject;
-	if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
-	{
-		return;
-	}	
-	LLVOVolume *volobjp = (LLVOVolume *)objectp;
-	
-	BOOL value = mCheckLight->get();
-	volobjp->setIsLight(value);
-	LL_INFOS() << "update light sent" << LL_ENDL;
+    LLViewerObject* objectp = mObject;
+    if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
+    {
+        return;
+    }
+    LLVOVolume *volobjp = (LLVOVolume *)objectp;
+
+    BOOL value = mCheckLight->get();
+    volobjp->setIsLight(value);
+    LL_INFOS() << "update light sent" << LL_ENDL;
 }
 
 void notify_cant_select_reflection_probe()
@@ -882,92 +882,92 @@ void LLPanelVolume::doSendIsReflectionProbe(const LLSD & notification, const LLS
 
 void LLPanelVolume::sendIsFlexible()
 {
-	LLViewerObject* objectp = mObject;
-	if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
-	{
-		return;
-	}	
-	LLVOVolume *volobjp = (LLVOVolume *)objectp;
-	
-	BOOL is_flexible = mCheckFlexible1D->getValue();
-	//BOOL is_flexible = mCheckFlexible1D->get();
-
-	if (is_flexible)
-	{
-		//LLFirstUse::useFlexible();
-
-		if (objectp->getClickAction() == CLICK_ACTION_SIT)
-		{
-			LLSelectMgr::getInstance()->selectionSetClickAction(CLICK_ACTION_NONE);
-		}
-
-	}
-
-	if (volobjp->setIsFlexible(is_flexible))
-	{
-		mObject->sendShapeUpdate();
-		LLSelectMgr::getInstance()->selectionUpdatePhantom(volobjp->flagPhantom());
-	}
-
-	LL_INFOS() << "update flexible sent" << LL_ENDL;
+    LLViewerObject* objectp = mObject;
+    if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
+    {
+        return;
+    }
+    LLVOVolume *volobjp = (LLVOVolume *)objectp;
+
+    BOOL is_flexible = mCheckFlexible1D->getValue();
+    //BOOL is_flexible = mCheckFlexible1D->get();
+
+    if (is_flexible)
+    {
+        //LLFirstUse::useFlexible();
+
+        if (objectp->getClickAction() == CLICK_ACTION_SIT)
+        {
+            LLSelectMgr::getInstance()->selectionSetClickAction(CLICK_ACTION_NONE);
+        }
+
+    }
+
+    if (volobjp->setIsFlexible(is_flexible))
+    {
+        mObject->sendShapeUpdate();
+        LLSelectMgr::getInstance()->selectionUpdatePhantom(volobjp->flagPhantom());
+    }
+
+    LL_INFOS() << "update flexible sent" << LL_ENDL;
 }
 
 void LLPanelVolume::sendPhysicsShapeType(LLUICtrl* ctrl, void* userdata)
 {
-	U8 type = ctrl->getValue().asInteger();
-	LLSelectMgr::getInstance()->selectionSetPhysicsType(type);
+    U8 type = ctrl->getValue().asInteger();
+    LLSelectMgr::getInstance()->selectionSetPhysicsType(type);
 
-	refreshCost();
+    refreshCost();
 }
 
 void LLPanelVolume::sendPhysicsGravity(LLUICtrl* ctrl, void* userdata)
 {
-	F32 val = ctrl->getValue().asReal();
-	LLSelectMgr::getInstance()->selectionSetGravity(val);
+    F32 val = ctrl->getValue().asReal();
+    LLSelectMgr::getInstance()->selectionSetGravity(val);
 }
 
 void LLPanelVolume::sendPhysicsFriction(LLUICtrl* ctrl, void* userdata)
 {
-	F32 val = ctrl->getValue().asReal();
-	LLSelectMgr::getInstance()->selectionSetFriction(val);
+    F32 val = ctrl->getValue().asReal();
+    LLSelectMgr::getInstance()->selectionSetFriction(val);
 }
 
 void LLPanelVolume::sendPhysicsRestitution(LLUICtrl* ctrl, void* userdata)
 {
-	F32 val = ctrl->getValue().asReal();
-	LLSelectMgr::getInstance()->selectionSetRestitution(val);
+    F32 val = ctrl->getValue().asReal();
+    LLSelectMgr::getInstance()->selectionSetRestitution(val);
 }
 
 void LLPanelVolume::sendPhysicsDensity(LLUICtrl* ctrl, void* userdata)
 {
-	F32 val = ctrl->getValue().asReal();
-	LLSelectMgr::getInstance()->selectionSetDensity(val);
+    F32 val = ctrl->getValue().asReal();
+    LLSelectMgr::getInstance()->selectionSetDensity(val);
 }
 
 void LLPanelVolume::refreshCost()
 {
-	LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
-	
-	if (obj)
-	{
-		obj->getObjectCost();
-	}
+    LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
+
+    if (obj)
+    {
+        obj->getObjectCost();
+    }
 }
 
 void LLPanelVolume::onLightCancelColor(const LLSD& data)
 {
-	mLightColorSwatch->setColor(mLightSavedColor);
-	onLightSelectColor(data);
+    mLightColorSwatch->setColor(mLightSavedColor);
+    onLightSelectColor(data);
 }
 
 void LLPanelVolume::onLightCancelTexture(const LLSD& data)
 {
-	LLVOVolume *volobjp = (LLVOVolume *) mObject.get();
+    LLVOVolume *volobjp = (LLVOVolume *) mObject.get();
 
-	if (volobjp)
-	{
-		// Cancel the light texture as requested
-		// NORSPEC-292
+    if (volobjp)
+    {
+        // Cancel the light texture as requested
+        // NORSPEC-292
         //
         // Texture picker triggers cancel both in case of actual cancel and in case of
         // selection of "None" texture.
@@ -982,34 +982,34 @@ void LLPanelVolume::onLightCancelTexture(const LLSD& data)
             mLightFocus->setValue(spot_params.mV[1]);
             mLightAmbiance->setValue(spot_params.mV[2]);
         }
-	}
+    }
 }
 
 void LLPanelVolume::onLightSelectColor(const LLSD& data)
 {
-	LLViewerObject* objectp = mObject;
-	if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
-	{
-		return;
-	}	
-	LLVOVolume *volobjp = (LLVOVolume *)objectp;
-
-	LLColor4	clr = mLightColorSwatch->get();
-	LLColor3	clr3( clr );
-	volobjp->setLightSRGBColor(clr3);
-	mLightSavedColor = clr;
+    LLViewerObject* objectp = mObject;
+    if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
+    {
+        return;
+    }
+    LLVOVolume *volobjp = (LLVOVolume *)objectp;
+
+    LLColor4    clr = mLightColorSwatch->get();
+    LLColor3    clr3( clr );
+    volobjp->setLightSRGBColor(clr3);
+    mLightSavedColor = clr;
 }
 
 void LLPanelVolume::onLightSelectTexture(const LLSD& data)
 {
-	if (mObject.isNull() || (mObject->getPCode() != LL_PCODE_VOLUME))
-	{
-		return;
-	}	
-	LLVOVolume *volobjp = (LLVOVolume *) mObject.get();
-
-	LLUUID id = mLightTextureCtrl->getImageAssetID();
-	setLightTextureID(id, mLightTextureCtrl->getImageItemID(), volobjp);
+    if (mObject.isNull() || (mObject->getPCode() != LL_PCODE_VOLUME))
+    {
+        return;
+    }
+    LLVOVolume *volobjp = (LLVOVolume *) mObject.get();
+
+    LLUUID id = mLightTextureCtrl->getImageAssetID();
+    setLightTextureID(id, mLightTextureCtrl->getImageItemID(), volobjp);
 }
 
 void LLPanelVolume::onCopyFeatures()
@@ -1535,94 +1535,94 @@ void LLPanelVolume::onFeaturesSelect(bool success, LLViewerObject* obj, const LL
 // static
 void LLPanelVolume::onCommitMaterial( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelVolume* self = (LLPanelVolume*)userdata;
-	LLComboBox* box = (LLComboBox*) ctrl;
-
-	if (box)
-	{
-		// apply the currently selected material to the object
-		const std::string& material_name = box->getSimple();
-		std::string LEGACY_FULLBRIGHT_DESC = LLTrans::getString("Fullbright");
-		if (material_name != LEGACY_FULLBRIGHT_DESC)
-		{
-			U8 material_code = LLMaterialTable::basic.getMCode(material_name);
-			if (self)
-			{
-				LLViewerObject* objectp = self->mObject;
-				if (objectp)
-				{
-					objectp->setPhysicsGravity(DEFAULT_GRAVITY_MULTIPLIER);
-					objectp->setPhysicsFriction(LLMaterialTable::basic.getFriction(material_code));
-					//currently density is always set to 1000 serverside regardless of chosen material,
-					//actual material density should be used here, if this behavior change
-					objectp->setPhysicsDensity(DEFAULT_DENSITY);
-					objectp->setPhysicsRestitution(LLMaterialTable::basic.getRestitution(material_code));
-				}
-			}
-			LLSelectMgr::getInstance()->selectionSetMaterial(material_code);
-		}
-	}
+    LLPanelVolume* self = (LLPanelVolume*)userdata;
+    LLComboBox* box = (LLComboBox*) ctrl;
+
+    if (box)
+    {
+        // apply the currently selected material to the object
+        const std::string& material_name = box->getSimple();
+        std::string LEGACY_FULLBRIGHT_DESC = LLTrans::getString("Fullbright");
+        if (material_name != LEGACY_FULLBRIGHT_DESC)
+        {
+            U8 material_code = LLMaterialTable::basic.getMCode(material_name);
+            if (self)
+            {
+                LLViewerObject* objectp = self->mObject;
+                if (objectp)
+                {
+                    objectp->setPhysicsGravity(DEFAULT_GRAVITY_MULTIPLIER);
+                    objectp->setPhysicsFriction(LLMaterialTable::basic.getFriction(material_code));
+                    //currently density is always set to 1000 serverside regardless of chosen material,
+                    //actual material density should be used here, if this behavior change
+                    objectp->setPhysicsDensity(DEFAULT_DENSITY);
+                    objectp->setPhysicsRestitution(LLMaterialTable::basic.getRestitution(material_code));
+                }
+            }
+            LLSelectMgr::getInstance()->selectionSetMaterial(material_code);
+        }
+    }
 }
 
 // static
 void LLPanelVolume::onCommitLight( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelVolume* self = (LLPanelVolume*) userdata;
-	LLViewerObject* objectp = self->mObject;
-	if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
-	{
-		return;
-	}	
-	LLVOVolume *volobjp = (LLVOVolume *)objectp;
-	
-	
-	volobjp->setLightIntensity((F32) self->mLightIntensity->getValue().asReal());
+    LLPanelVolume* self = (LLPanelVolume*) userdata;
+    LLViewerObject* objectp = self->mObject;
+    if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
+    {
+        return;
+    }
+    LLVOVolume *volobjp = (LLVOVolume *)objectp;
+
+
+    volobjp->setLightIntensity((F32) self->mLightIntensity->getValue().asReal());
     volobjp->setLightRadius((F32) self->mLightRadius->getValue().asReal());
     volobjp->setLightFalloff((F32) self->mLightFalloff->getValue().asReal());
 
-	LLColor4	clr = self->mLightColorSwatch->get();
-	volobjp->setLightSRGBColor(LLColor3(clr));
+    LLColor4    clr = self->mLightColorSwatch->get();
+    volobjp->setLightSRGBColor(LLColor3(clr));
 
-	{
-		LLUUID id = self->mLightTextureCtrl->getImageAssetID();
+    {
+        LLUUID id = self->mLightTextureCtrl->getImageAssetID();
         LLUUID item_id = self->mLightTextureCtrl->getImageItemID();
-		if (id.notNull())
-		{
-			if (!volobjp->isLightSpotlight())
-			{ //this commit is making this a spot light, set UI to default params
+        if (id.notNull())
+        {
+            if (!volobjp->isLightSpotlight())
+            { //this commit is making this a spot light, set UI to default params
                 setLightTextureID(id, item_id, volobjp);
-				LLVector3 spot_params = volobjp->getSpotLightParams();
+                LLVector3 spot_params = volobjp->getSpotLightParams();
                 self->mLightFOV->setValue(spot_params.mV[0]);
                 self->mLightFocus->setValue(spot_params.mV[1]);
                 self->mLightAmbiance->setValue(spot_params.mV[2]);
-			}
-			else
-			{ //modifying existing params, this time volobjp won't change params on its own.
+            }
+            else
+            { //modifying existing params, this time volobjp won't change params on its own.
                 if (volobjp->getLightTextureID() != id)
                 {
                     setLightTextureID(id, item_id, volobjp);
                 }
 
-				LLVector3 spot_params;
+                LLVector3 spot_params;
                 spot_params.mV[0] = (F32) self->mLightFOV->getValue().asReal();
                 spot_params.mV[1] = (F32) self->mLightFocus->getValue().asReal();
                 spot_params.mV[2] = (F32) self->mLightAmbiance->getValue().asReal();
-				volobjp->setSpotLightParams(spot_params);
-			}
-		}
-		else if (volobjp->isLightSpotlight())
-		{ //no longer a spot light
-			setLightTextureID(id, item_id, volobjp);
-			//self->mLightFOV->setEnabled(FALSE);
-			//self->mLightFocus->setEnabled(FALSE);
-			//self->mLightAmbiance->setEnabled(FALSE);
-		}
-	}
-
-	
+                volobjp->setSpotLightParams(spot_params);
+            }
+        }
+        else if (volobjp->isLightSpotlight())
+        { //no longer a spot light
+            setLightTextureID(id, item_id, volobjp);
+            //self->mLightFOV->setEnabled(FALSE);
+            //self->mLightFocus->setEnabled(FALSE);
+            //self->mLightAmbiance->setEnabled(FALSE);
+        }
+    }
+
+
 }
 
-//static 
+//static
 void LLPanelVolume::onCommitProbe(LLUICtrl* ctrl, void* userdata)
 {
     LLPanelVolume* self = (LLPanelVolume*)userdata;
@@ -1672,7 +1672,7 @@ void LLPanelVolume::onCommitProbe(LLUICtrl* ctrl, void* userdata)
             profile = LL_PCODE_PROFILE_SQUARE;
             path = LL_PCODE_PATH_LINE;
         }
-        
+
         LLVolumeParams params;
         params.getProfileParams().setCurveType(profile);
         params.getPathParams().setCurveType(path);
@@ -1684,8 +1684,8 @@ void LLPanelVolume::onCommitProbe(LLUICtrl* ctrl, void* userdata)
 // static
 void LLPanelVolume::onCommitIsLight( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelVolume* self = (LLPanelVolume*) userdata;
-	self->sendIsLight();
+    LLPanelVolume* self = (LLPanelVolume*) userdata;
+    self->sendIsLight();
 }
 
 // static
@@ -1710,7 +1710,7 @@ void LLPanelVolume::setLightTextureID(const LLUUID &asset_id, const LLUUID &item
         if (item && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()))
         {
             LLToolDragAndDrop::handleDropMaterialProtections(volobjp, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null);
-        }    
+        }
         volobjp->setLightTextureID(asset_id);
     }
 }
@@ -1728,46 +1728,46 @@ void LLPanelVolume::onCommitIsReflectionProbe(LLUICtrl* ctrl, void* userdata)
 // static
 void LLPanelVolume::onCommitFlexible( LLUICtrl* ctrl, void* userdata )
 {
-	LLPanelVolume* self = (LLPanelVolume*) userdata;
-	LLViewerObject* objectp = self->mObject;
-	if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
-	{
-		return;
-	}
-	
-	LLFlexibleObjectData *attributes = (LLFlexibleObjectData *)objectp->getFlexibleObjectData();
-	if (attributes)
-	{
-		LLFlexibleObjectData new_attributes;
-		new_attributes = *attributes;
-
-
-		new_attributes.setSimulateLOD(self->mSpinSections->getValue().asInteger());  //(S32)self->mSpinSections->get());
-		new_attributes.setGravity((F32)self->mSpinGravity->getValue().asReal());
-		new_attributes.setTension((F32)self->mSpinTension->getValue().asReal());
-		new_attributes.setAirFriction((F32)self->mSpinFriction->getValue().asReal());
-		new_attributes.setWindSensitivity((F32)self->mSpinWind->getValue().asReal());
-		F32 fx = (F32)self->mSpinForceX->getValue().asReal();
+    LLPanelVolume* self = (LLPanelVolume*) userdata;
+    LLViewerObject* objectp = self->mObject;
+    if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
+    {
+        return;
+    }
+
+    LLFlexibleObjectData *attributes = (LLFlexibleObjectData *)objectp->getFlexibleObjectData();
+    if (attributes)
+    {
+        LLFlexibleObjectData new_attributes;
+        new_attributes = *attributes;
+
+
+        new_attributes.setSimulateLOD(self->mSpinSections->getValue().asInteger());  //(S32)self->mSpinSections->get());
+        new_attributes.setGravity((F32)self->mSpinGravity->getValue().asReal());
+        new_attributes.setTension((F32)self->mSpinTension->getValue().asReal());
+        new_attributes.setAirFriction((F32)self->mSpinFriction->getValue().asReal());
+        new_attributes.setWindSensitivity((F32)self->mSpinWind->getValue().asReal());
+        F32 fx = (F32)self->mSpinForceX->getValue().asReal();
         F32       fy = (F32) self->mSpinForceY->getValue().asReal();
         F32       fz = (F32) self->mSpinForceZ->getValue().asReal();
-		LLVector3 force(fx,fy,fz);
+        LLVector3 force(fx,fy,fz);
 
-		new_attributes.setUserForce(force);
-		objectp->setParameterEntry(LLNetworkData::PARAMS_FLEXIBLE, new_attributes, true);
-	}
+        new_attributes.setUserForce(force);
+        objectp->setParameterEntry(LLNetworkData::PARAMS_FLEXIBLE, new_attributes, true);
+    }
 
-	// Values may fail validation
-	self->refresh();
+    // Values may fail validation
+    self->refresh();
 }
 
 void LLPanelVolume::onCommitAnimatedMeshCheckbox(LLUICtrl *, void*)
 {
-	LLViewerObject* objectp = mObject;
-	if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
-	{
-		return;
+    LLViewerObject* objectp = mObject;
+    if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
+    {
+        return;
     }
-	LLVOVolume *volobjp = (LLVOVolume *)objectp;
+    LLVOVolume *volobjp = (LLVOVolume *)objectp;
     BOOL        animated_mesh = mCheckAnimesh->getValue();
     U32 flags = volobjp->getExtendedMeshFlags();
     U32 new_flags = flags;
@@ -1784,47 +1784,47 @@ void LLPanelVolume::onCommitAnimatedMeshCheckbox(LLUICtrl *, void*)
         volobjp->setExtendedMeshFlags(new_flags);
     }
 
-	//refresh any bakes
-	if (volobjp)
-	{
-		volobjp->refreshBakeTexture();
+    //refresh any bakes
+    if (volobjp)
+    {
+        volobjp->refreshBakeTexture();
 
-		LLViewerObject::const_child_list_t& child_list = volobjp->getChildren();
+        LLViewerObject::const_child_list_t& child_list = volobjp->getChildren();
         for (LLViewerObject* objectp : child_list)
-		{
-			if (objectp)
-			{
-				objectp->refreshBakeTexture();
-			}
-		}
-
-		if (gAgentAvatarp)
-		{
-			gAgentAvatarp->updateMeshVisibility();
-		}
-	}
+        {
+            if (objectp)
+            {
+                objectp->refreshBakeTexture();
+            }
+        }
+
+        if (gAgentAvatarp)
+        {
+            gAgentAvatarp->updateMeshVisibility();
+        }
+    }
 }
 
 void LLPanelVolume::onCommitIsFlexible(LLUICtrl *, void*)
 {
-	if (mObject->flagObjectPermanent())
-	{
-		LLNotificationsUtil::add("PathfindingLinksets_ChangeToFlexiblePath", LLSD(), LLSD(), boost::bind(&LLPanelVolume::handleResponseChangeToFlexible, this, _1, _2));
-	}
-	else
-	{
-		sendIsFlexible();
-	}
+    if (mObject->flagObjectPermanent())
+    {
+        LLNotificationsUtil::add("PathfindingLinksets_ChangeToFlexiblePath", LLSD(), LLSD(), boost::bind(&LLPanelVolume::handleResponseChangeToFlexible, this, _1, _2));
+    }
+    else
+    {
+        sendIsFlexible();
+    }
 }
 
 void LLPanelVolume::handleResponseChangeToFlexible(const LLSD &pNotification, const LLSD &pResponse)
 {
-	if (LLNotificationsUtil::getSelectedOption(pNotification, pResponse) == 0)
-	{
-		sendIsFlexible();
-	}
-	else
-	{
+    if (LLNotificationsUtil::getSelectedOption(pNotification, pResponse) == 0)
+    {
+        sendIsFlexible();
+    }
+    else
+    {
         mCheckFlexible1D->setValue(FALSE);
-	}
+    }
 }
diff --git a/indra/newview/llreflectionmap.cpp b/indra/newview/llreflectionmap.cpp
index dc5286246761dce84434392ba7581a2e83464d74..99993f26b4588bb81374616cecc2657fc67a780e 100644
--- a/indra/newview/llreflectionmap.cpp
+++ b/indra/newview/llreflectionmap.cpp
@@ -56,7 +56,7 @@ void LLReflectionMap::update(U32 resolution, U32 face, bool force_dynamic, F32 n
     llassert(mCubeArray.notNull());
     llassert(mCubeIndex != -1);
     //llassert(LLPipeline::sRenderDeferred);
-    
+
     // make sure we don't walk off the edge of the render target
     while (resolution > gPipeline.mRT->deferredScreen.getWidth() ||
         resolution > gPipeline.mRT->deferredScreen.getHeight())
@@ -65,7 +65,7 @@ void LLReflectionMap::update(U32 resolution, U32 face, bool force_dynamic, F32 n
     }
 
     F32 clip = (near_clip > 0) ? near_clip : getNearClip();
-    
+
     gViewerWindow->cubeSnapshot(LLVector3(mOrigin), mCubeArray, mCubeIndex, face, clip, getIsDynamic() || force_dynamic, useClipPlane, clipPlane);
 }
 
@@ -145,7 +145,7 @@ void LLReflectionMap::autoAdjustOrigin()
             LLVector3 origin(fp);
             F32 height = LLWorld::instance().resolveLandHeightAgent(origin) + 2.f;
             fp[2] = llmax(fp[2], height);
-            
+
             // make sure radius encompasses all objects
             LLSimdScalar r2 = 0.0;
             for (int i = 0; i < 8; ++i)
@@ -165,7 +165,7 @@ void LLReflectionMap::autoAdjustOrigin()
 
             // make sure near clip doesn't poke through ground
             fp[2] = llmax(fp[2], height+mRadius*0.5f);
-            
+
         }
     }
     else if (mViewerObject && !mViewerObject->isDead())
@@ -238,7 +238,7 @@ bool LLReflectionMap::getIsDynamic()
 {
     static LLCachedControl<S32> sProbeDetail(gSavedSettings, "RenderReflectionProbeDetail", -1);
     if (sProbeDetail > (S32) LLReflectionMapManager::DetailLevel::STATIC_ONLY &&
-        mViewerObject && 
+        mViewerObject &&
         mViewerObject->getVolume())
     {
         return ((LLVOVolume*)mViewerObject)->getReflectionProbeIsDynamic();
@@ -248,7 +248,7 @@ bool LLReflectionMap::getIsDynamic()
 }
 
 bool LLReflectionMap::getBox(LLMatrix4& box)
-{ 
+{
     if (mViewerObject)
     {
         LLVolume* volume = mViewerObject->getVolume();
@@ -258,10 +258,10 @@ bool LLReflectionMap::getBox(LLMatrix4& box)
 
             if (vobjp->getReflectionProbeIsBox())
             {
-				LLVector3 s = vobjp->getScale().scaledVec(LLVector3(0.5f, 0.5f, 0.5f));
-				mRadius = s.magVec();
-				if (vobjp->mDrawable != nullptr)
-				{
+                LLVector3 s = vobjp->getScale().scaledVec(LLVector3(0.5f, 0.5f, 0.5f));
+                mRadius = s.magVec();
+                if (vobjp->mDrawable != nullptr)
+                {
                     // object to agent space (no scale)
                     LLMatrix4a scale;
                     scale.setIdentity();
@@ -270,14 +270,14 @@ bool LLReflectionMap::getBox(LLMatrix4& box)
 
                     // construct object to camera space (with scale)
                     LLMatrix4a mv = gGLModelView;
-					mv.mul(vobjp->mDrawable->getWorldMatrix());
-					mv.mul(scale);
+                    mv.mul(vobjp->mDrawable->getWorldMatrix());
+                    mv.mul(scale);
 
-                    // inverse is camera space to object unit cube 
-					mv.invert();
-					box = LLMatrix4(mv);
+                    // inverse is camera space to object unit cube
+                    mv.invert();
+                    box = LLMatrix4(mv);
                     return true;
-				}
+                }
             }
         }
     }
@@ -338,7 +338,7 @@ void LLReflectionMap::doOcclusion(const LLVector4a& eye)
         mOccluded = false;
         return;
     }
-    
+
     if (mOcclusionQuery == 0)
     { // no query was previously issued, allocate one and issue
         LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("rmdo - glGenQueries");
diff --git a/indra/newview/llselectmgr.cpp b/indra/newview/llselectmgr.cpp
index c4b383c33c9f6e3a574bc3b677280249c58889b1..5664417b25713f5d6713f79db71c4f309d853550 100644
--- a/indra/newview/llselectmgr.cpp
+++ b/indra/newview/llselectmgr.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llselectmgr.cpp
  * @brief A manager for selected objects and faces.
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- *  
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -126,26 +126,26 @@ const S32 MAX_OBJECTS_PER_PACKET = 254;
 BOOL LLSelectMgr::sRectSelectInclusive = TRUE;
 BOOL LLSelectMgr::sRenderHiddenSelections = TRUE;
 BOOL LLSelectMgr::sRenderLightRadius = FALSE;
-F32	LLSelectMgr::sHighlightThickness = 0.f;
-F32	LLSelectMgr::sHighlightUScale = 0.f;
-F32	LLSelectMgr::sHighlightVScale = 0.f;
-F32	LLSelectMgr::sHighlightAlpha = 0.f;
-F32	LLSelectMgr::sHighlightAlphaTest = 0.f;
-F32	LLSelectMgr::sHighlightUAnim = 0.f;
-F32	LLSelectMgr::sHighlightVAnim = 0.f;
+F32 LLSelectMgr::sHighlightThickness = 0.f;
+F32 LLSelectMgr::sHighlightUScale = 0.f;
+F32 LLSelectMgr::sHighlightVScale = 0.f;
+F32 LLSelectMgr::sHighlightAlpha = 0.f;
+F32 LLSelectMgr::sHighlightAlphaTest = 0.f;
+F32 LLSelectMgr::sHighlightUAnim = 0.f;
+F32 LLSelectMgr::sHighlightVAnim = 0.f;
 
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 // struct LLDeRezInfo
 //
-// Used to keep track of important derez info. 
+// Used to keep track of important derez info.
 //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 struct LLDeRezInfo
 {
-	EDeRezDestination mDestination;
-	LLUUID mDestinationID;
-	LLDeRezInfo(EDeRezDestination dest, const LLUUID& dest_id) :
-		mDestination(dest), mDestinationID(dest_id) {}
+    EDeRezDestination mDestination;
+    LLUUID mDestinationID;
+    LLDeRezInfo(EDeRezDestination dest, const LLUUID& dest_id) :
+        mDestination(dest), mDestinationID(dest_id) {}
 };
 
 //
@@ -206,7 +206,7 @@ LLSelectionCallbackData::LLSelectionCallbackData()
 
 void LLSelectMgr::cleanupGlobals()
 {
-	LLSelectMgr::getInstance()->clearSelections();
+    LLSelectMgr::getInstance()->clearSelections();
 }
 
 //-----------------------------------------------------------------------------
@@ -218,38 +218,38 @@ LLSelectMgr::LLSelectMgr()
    mAllowSelectAvatar( LLCachedControl<bool>(gSavedSettings, "AllowSelectAvatar", FALSE)),
    mDebugSelectMgr(LLCachedControl<bool>(gSavedSettings, "DebugSelectMgr", FALSE))
 {
-	mTEMode = FALSE;
-	mTextureChannel = LLRender::DIFFUSE_MAP;
-	mLastCameraPos.clearVec();
+    mTEMode = FALSE;
+    mTextureChannel = LLRender::DIFFUSE_MAP;
+    mLastCameraPos.clearVec();
 
-	sHighlightThickness	= gSavedSettings.getF32("SelectionHighlightThickness");
-	sHighlightUScale	= gSavedSettings.getF32("SelectionHighlightUScale");
-	sHighlightVScale	= gSavedSettings.getF32("SelectionHighlightVScale");
-	sHighlightAlpha		= gSavedSettings.getF32("SelectionHighlightAlpha") * 2;
-	sHighlightAlphaTest	= gSavedSettings.getF32("SelectionHighlightAlphaTest");
-	sHighlightUAnim		= gSavedSettings.getF32("SelectionHighlightUAnim");
-	sHighlightVAnim		= gSavedSettings.getF32("SelectionHighlightVAnim");
+    sHighlightThickness = gSavedSettings.getF32("SelectionHighlightThickness");
+    sHighlightUScale    = gSavedSettings.getF32("SelectionHighlightUScale");
+    sHighlightVScale    = gSavedSettings.getF32("SelectionHighlightVScale");
+    sHighlightAlpha     = gSavedSettings.getF32("SelectionHighlightAlpha") * 2;
+    sHighlightAlphaTest = gSavedSettings.getF32("SelectionHighlightAlphaTest");
+    sHighlightUAnim     = gSavedSettings.getF32("SelectionHighlightUAnim");
+    sHighlightVAnim     = gSavedSettings.getF32("SelectionHighlightVAnim");
 
-	sSilhouetteParentColor = LLUIColorTable::instance().getColor("SilhouetteParentColor");
-	sSilhouetteChildColor = LLUIColorTable::instance().getColor("SilhouetteChildColor");
-	sHighlightParentColor = LLUIColorTable::instance().getColor("HighlightParentColor");
-	sHighlightChildColor = LLUIColorTable::instance().getColor("HighlightChildColor");
-	sHighlightInspectColor = LLUIColorTable::instance().getColor("HighlightInspectColor");
-	sContextSilhouetteColor = LLUIColorTable::instance().getColor("ContextSilhouetteColor");
+    sSilhouetteParentColor = LLUIColorTable::instance().getColor("SilhouetteParentColor");
+    sSilhouetteChildColor = LLUIColorTable::instance().getColor("SilhouetteChildColor");
+    sHighlightParentColor = LLUIColorTable::instance().getColor("HighlightParentColor");
+    sHighlightChildColor = LLUIColorTable::instance().getColor("HighlightChildColor");
+    sHighlightInspectColor = LLUIColorTable::instance().getColor("HighlightInspectColor");
+    sContextSilhouetteColor = LLUIColorTable::instance().getColor("ContextSilhouetteColor");
 
-	sRenderLightRadius = gSavedSettings.getBOOL("RenderLightRadius");
-	
-	mRenderSilhouettes = TRUE;
+    sRenderLightRadius = gSavedSettings.getBOOL("RenderLightRadius");
 
-	mGridMode = GRID_MODE_WORLD;
-	gSavedSettings.setS32("GridMode", (S32)GRID_MODE_WORLD);
+    mRenderSilhouettes = TRUE;
 
-	mSelectedObjects = new LLObjectSelection();
-	mHoverObjects = new LLObjectSelection();
-	mHighlightedObjects = new LLObjectSelection();
+    mGridMode = GRID_MODE_WORLD;
+    gSavedSettings.setS32("GridMode", (S32)GRID_MODE_WORLD);
 
-	mForceSelection = FALSE;
-	mShowSelection = FALSE;
+    mSelectedObjects = new LLObjectSelection();
+    mHoverObjects = new LLObjectSelection();
+    mHighlightedObjects = new LLObjectSelection();
+
+    mForceSelection = FALSE;
+    mShowSelection = FALSE;
 }
 
 
@@ -258,47 +258,47 @@ LLSelectMgr::LLSelectMgr()
 //-----------------------------------------------------------------------------
 LLSelectMgr::~LLSelectMgr()
 {
-	clearSelections();
+    clearSelections();
 }
 
 void LLSelectMgr::clearSelections()
 {
-	mHoverObjects->deleteAllNodes();
-	mSelectedObjects->deleteAllNodes();
-	mHighlightedObjects->deleteAllNodes();
-	mRectSelectedObjects.clear();
-	mGridObjects.deleteAllNodes();
+    mHoverObjects->deleteAllNodes();
+    mSelectedObjects->deleteAllNodes();
+    mHighlightedObjects->deleteAllNodes();
+    mRectSelectedObjects.clear();
+    mGridObjects.deleteAllNodes();
 
-	LLPipeline::setRenderHighlightTextureChannel(LLRender::DIFFUSE_MAP);
+    LLPipeline::setRenderHighlightTextureChannel(LLRender::DIFFUSE_MAP);
 }
 
 void LLSelectMgr::update()
 {
-	mSelectedObjects->cleanupNodes();
+    mSelectedObjects->cleanupNodes();
 }
 
 void LLSelectMgr::updateEffects()
 {
-	//keep reference grid objects active
-	struct f : public LLSelectedObjectFunctor
-	{
-		virtual bool apply(LLViewerObject* object)
-		{
-			LLDrawable* drawable = object->mDrawable;
-			if (drawable)
-			{
-				gPipeline.markMoved(drawable);
-			}
-			return true;
-		}
-	} func;
-	mGridObjects.applyToObjects(&func);
-
-	if (mEffectsTimer.getElapsedTimeF32() > 1.f)
-	{
-		mSelectedObjects->updateEffects();
-		mEffectsTimer.reset();
-	}
+    //keep reference grid objects active
+    struct f : public LLSelectedObjectFunctor
+    {
+        virtual bool apply(LLViewerObject* object)
+        {
+            LLDrawable* drawable = object->mDrawable;
+            if (drawable)
+            {
+                gPipeline.markMoved(drawable);
+            }
+            return true;
+        }
+    } func;
+    mGridObjects.applyToObjects(&func);
+
+    if (mEffectsTimer.getElapsedTimeF32() > 1.f)
+    {
+        mSelectedObjects->updateEffects();
+        mEffectsTimer.reset();
+    }
 }
 
 void LLSelectMgr::resetObjectOverrides()
@@ -339,31 +339,31 @@ void LLSelectMgr::resetObjectOverrides(LLObjectSelectionHandle selected_handle)
 
 void LLSelectMgr::overrideObjectUpdates()
 {
-	//override any position updates from simulator on objects being edited
-	struct f : public LLSelectedNodeFunctor
-	{
-		virtual bool apply(LLSelectNode* selectNode)
-		{
-			LLViewerObject* object = selectNode->getObject();
-			if (object && object->permMove() && !object->isPermanentEnforced())
-			{
-				if (!selectNode->mLastPositionLocal.isExactlyZero())
-				{
-					object->setPosition(selectNode->mLastPositionLocal);
-				}
-				if (selectNode->mLastRotation != LLQuaternion())
-				{
-					object->setRotation(selectNode->mLastRotation);
-				}
-				if (!selectNode->mLastScale.isExactlyZero())
-				{
-					object->setScale(selectNode->mLastScale);
-				}
-			}
-			return true;
-		}
-	} func;
-	getSelection()->applyToNodes(&func);
+    //override any position updates from simulator on objects being edited
+    struct f : public LLSelectedNodeFunctor
+    {
+        virtual bool apply(LLSelectNode* selectNode)
+        {
+            LLViewerObject* object = selectNode->getObject();
+            if (object && object->permMove() && !object->isPermanentEnforced())
+            {
+                if (!selectNode->mLastPositionLocal.isExactlyZero())
+                {
+                    object->setPosition(selectNode->mLastPositionLocal);
+                }
+                if (selectNode->mLastRotation != LLQuaternion())
+                {
+                    object->setRotation(selectNode->mLastRotation);
+                }
+                if (!selectNode->mLastScale.isExactlyZero())
+                {
+                    object->setScale(selectNode->mLastScale);
+                }
+            }
+            return true;
+        }
+    } func;
+    getSelection()->applyToNodes(&func);
 }
 
 void LLSelectMgr::resetAvatarOverrides()
@@ -397,7 +397,7 @@ void LLSelectMgr::overrideAvatarUpdates()
     }
 
     // remove selected avatars from this list,
-    // but set object overrides to make sure avatar won't snap back 
+    // but set object overrides to make sure avatar won't snap back
     struct f : public LLSelectedNodeFunctor
     {
         f(LLSelectMgr* p) : mManager(p) {}
@@ -458,62 +458,62 @@ void LLSelectMgr::overrideAvatarUpdates()
 //-----------------------------------------------------------------------------
 LLObjectSelectionHandle LLSelectMgr::selectObjectOnly(LLViewerObject* object, S32 face, S32 gltf_node, S32 gltf_primitive)
 {
-	llassert( object );
-
-	//remember primary object
-	mSelectedObjects->mPrimaryObject = object;
-
-	// Don't add an object that is already in the list
-	if (object->isSelected() ) {
-		// make sure point at position is updated
-		updatePointAt();
-		gEditMenuHandler = this;
-		return NULL;
-	}
-
-	if (!canSelectObject(object))
-	{
-		//make_ui_sound("UISndInvalidOp");
-		return NULL;
-	}
-
-	// LL_INFOS() << "Adding object to selected object list" << LL_ENDL;
-
-	// Place it in the list and tag it.
-	// This will refresh dialogs.
-	addAsIndividual(object, face, TRUE, gltf_node, gltf_primitive);
-
-	// Stop the object from moving (this anticipates changes on the
-	// simulator in LLTask::userSelect)
-	// *FIX: shouldn't zero out these either
-	object->setVelocity(LLVector3::zero);
-	object->setAcceleration(LLVector3::zero);
-	//object->setAngularVelocity(LLVector3::zero);
-	object->resetRot();
-
-	// Always send to simulator, so you get a copy of the 
-	// permissions structure back.
-	gMessageSystem->newMessageFast(_PREHASH_ObjectSelect);
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID() );
-	LLViewerRegion* regionp = object->getRegion();
-	gMessageSystem->sendReliable( regionp->getHost());
-
-	updatePointAt();
-	updateSelectionCenter();
-	saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
-
-	// have selection manager handle edit menu immediately after 
-	// user selects an object
-	if (mSelectedObjects->getObjectCount())
-	{
-		gEditMenuHandler = this;
-	}
-
-	return mSelectedObjects;
+    llassert( object );
+
+    //remember primary object
+    mSelectedObjects->mPrimaryObject = object;
+
+    // Don't add an object that is already in the list
+    if (object->isSelected() ) {
+        // make sure point at position is updated
+        updatePointAt();
+        gEditMenuHandler = this;
+        return NULL;
+    }
+
+    if (!canSelectObject(object))
+    {
+        //make_ui_sound("UISndInvalidOp");
+        return NULL;
+    }
+
+    // LL_INFOS() << "Adding object to selected object list" << LL_ENDL;
+
+    // Place it in the list and tag it.
+    // This will refresh dialogs.
+    addAsIndividual(object, face, TRUE, gltf_node, gltf_primitive);
+
+    // Stop the object from moving (this anticipates changes on the
+    // simulator in LLTask::userSelect)
+    // *FIX: shouldn't zero out these either
+    object->setVelocity(LLVector3::zero);
+    object->setAcceleration(LLVector3::zero);
+    //object->setAngularVelocity(LLVector3::zero);
+    object->resetRot();
+
+    // Always send to simulator, so you get a copy of the
+    // permissions structure back.
+    gMessageSystem->newMessageFast(_PREHASH_ObjectSelect);
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID() );
+    LLViewerRegion* regionp = object->getRegion();
+    gMessageSystem->sendReliable( regionp->getHost());
+
+    updatePointAt();
+    updateSelectionCenter();
+    saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+
+    // have selection manager handle edit menu immediately after
+    // user selects an object
+    if (mSelectedObjects->getObjectCount())
+    {
+        gEditMenuHandler = this;
+    }
+
+    return mSelectedObjects;
 }
 
 //-----------------------------------------------------------------------------
@@ -521,149 +521,149 @@ LLObjectSelectionHandle LLSelectMgr::selectObjectOnly(LLViewerObject* object, S3
 //-----------------------------------------------------------------------------
 LLObjectSelectionHandle LLSelectMgr::selectObjectAndFamily(LLViewerObject* obj, BOOL add_to_end, BOOL ignore_select_owned)
 {
-	llassert( obj );
-
-	//remember primary object
-	mSelectedObjects->mPrimaryObject = obj;
-
-	// This may be incorrect if things weren't family selected before... - djs 07/08/02
-	// Don't add an object that is already in the list
-	if (obj->isSelected() ) 
-	{
-		// make sure pointat position is updated
-		updatePointAt();
-		gEditMenuHandler = this;
-		return NULL;
-	}
-
-	if (!canSelectObject(obj,ignore_select_owned))
-	{
-		//make_ui_sound("UISndInvalidOp");
-		return NULL;
-	}
-
-	// Since we're selecting a family, start at the root, but
-	// don't include an avatar.
-	LLViewerObject* root = obj;
-	
-	while(!root->isAvatar() && root->getParent())
-	{
-		LLViewerObject* parent = (LLViewerObject*)root->getParent();
-		if (parent->isAvatar())
-		{
-			break;
-		}
-		root = parent;
-	}
-
-	// Collect all of the objects
-	std::vector<LLViewerObject*> objects;
-
-	root->addThisAndNonJointChildren(objects);
-	addAsFamily(objects, add_to_end);
-
-	updateSelectionCenter();
-	saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
-	updatePointAt();
-
-	dialog_refresh_all();
-
-	// Always send to simulator, so you get a copy of the permissions
-	// structure back.
-	sendSelect();
-
-	// Stop the object from moving (this anticipates changes on the
-	// simulator in LLTask::userSelect)
-	root->setVelocity(LLVector3::zero);
-	root->setAcceleration(LLVector3::zero);
-	//root->setAngularVelocity(LLVector3::zero);
-	root->resetRot();
-
-	// leave component mode
-	if (ALControlCache::EditLinkedParts)
-	{
-		gSavedSettings.setBOOL("EditLinkedParts", FALSE);
-		promoteSelectionToRoot();
-	}
-
-	// have selection manager handle edit menu immediately after 
-	// user selects an object
-	if (mSelectedObjects->getObjectCount())
-	{
-		gEditMenuHandler = this;
-	}
-
-	return mSelectedObjects;
+    llassert( obj );
+
+    //remember primary object
+    mSelectedObjects->mPrimaryObject = obj;
+
+    // This may be incorrect if things weren't family selected before... - djs 07/08/02
+    // Don't add an object that is already in the list
+    if (obj->isSelected() )
+    {
+        // make sure pointat position is updated
+        updatePointAt();
+        gEditMenuHandler = this;
+        return NULL;
+    }
+
+    if (!canSelectObject(obj,ignore_select_owned))
+    {
+        //make_ui_sound("UISndInvalidOp");
+        return NULL;
+    }
+
+    // Since we're selecting a family, start at the root, but
+    // don't include an avatar.
+    LLViewerObject* root = obj;
+
+    while(!root->isAvatar() && root->getParent())
+    {
+        LLViewerObject* parent = (LLViewerObject*)root->getParent();
+        if (parent->isAvatar())
+        {
+            break;
+        }
+        root = parent;
+    }
+
+    // Collect all of the objects
+    std::vector<LLViewerObject*> objects;
+
+    root->addThisAndNonJointChildren(objects);
+    addAsFamily(objects, add_to_end);
+
+    updateSelectionCenter();
+    saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+    updatePointAt();
+
+    dialog_refresh_all();
+
+    // Always send to simulator, so you get a copy of the permissions
+    // structure back.
+    sendSelect();
+
+    // Stop the object from moving (this anticipates changes on the
+    // simulator in LLTask::userSelect)
+    root->setVelocity(LLVector3::zero);
+    root->setAcceleration(LLVector3::zero);
+    //root->setAngularVelocity(LLVector3::zero);
+    root->resetRot();
+
+    // leave component mode
+    if (ALControlCache::EditLinkedParts)
+    {
+        gSavedSettings.setBOOL("EditLinkedParts", FALSE);
+        promoteSelectionToRoot();
+    }
+
+    // have selection manager handle edit menu immediately after
+    // user selects an object
+    if (mSelectedObjects->getObjectCount())
+    {
+        gEditMenuHandler = this;
+    }
+
+    return mSelectedObjects;
 }
 
 //-----------------------------------------------------------------------------
 // Select the object, parents and children.
 //-----------------------------------------------------------------------------
 LLObjectSelectionHandle LLSelectMgr::selectObjectAndFamily(const std::vector<LLViewerObject*>& object_list,
-														   BOOL send_to_sim)
-{
-	// Collect all of the objects, children included
-	std::vector<LLViewerObject*> objects;
-
-	//clear primary object (no primary object)
-	mSelectedObjects->mPrimaryObject = NULL;
-
-	if (object_list.size() < 1)
-	{
-		return NULL;
-	}
-	
-	// NOTE -- we add the objects in REVERSE ORDER 
-	// to preserve the order in the mSelectedObjects list
-	for (std::vector<LLViewerObject*>::const_reverse_iterator riter = object_list.rbegin();
-		 riter != object_list.rend(); ++riter)
-	{
-		LLViewerObject *object = *riter;
-
-		llassert( object );
-
-		if (!canSelectObject(object)) continue;
-
-		object->addThisAndNonJointChildren(objects);
-		addAsFamily(objects);
-
-		// Stop the object from moving (this anticipates changes on the
-		// simulator in LLTask::userSelect)
-		object->setVelocity(LLVector3::zero);
-		object->setAcceleration(LLVector3::zero);
-		//object->setAngularVelocity(LLVector3::zero);
-		object->resetRot();
-	}
-
-	updateSelectionCenter();
-	saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
-	updatePointAt();
-	dialog_refresh_all();
-
-	// Almost always send to simulator, so you get a copy of the permissions
-	// structure back.
-	// JC: The one case where you don't want to do this is if you're selecting
-	// all the objects on a sim.
-	if (send_to_sim)
-	{
-		sendSelect();
-	}
-
-	// leave component mode
-	if (ALControlCache::EditLinkedParts)
-	{		
-		gSavedSettings.setBOOL("EditLinkedParts", FALSE);
-		promoteSelectionToRoot();
-	}
-
-	// have selection manager handle edit menu immediately after 
-	// user selects an object
-	if (mSelectedObjects->getObjectCount())
-	{
-		gEditMenuHandler = this;
-	}
-
-	return mSelectedObjects;
+                                                           BOOL send_to_sim)
+{
+    // Collect all of the objects, children included
+    std::vector<LLViewerObject*> objects;
+
+    //clear primary object (no primary object)
+    mSelectedObjects->mPrimaryObject = NULL;
+
+    if (object_list.size() < 1)
+    {
+        return NULL;
+    }
+
+    // NOTE -- we add the objects in REVERSE ORDER
+    // to preserve the order in the mSelectedObjects list
+    for (std::vector<LLViewerObject*>::const_reverse_iterator riter = object_list.rbegin();
+         riter != object_list.rend(); ++riter)
+    {
+        LLViewerObject *object = *riter;
+
+        llassert( object );
+
+        if (!canSelectObject(object)) continue;
+
+        object->addThisAndNonJointChildren(objects);
+        addAsFamily(objects);
+
+        // Stop the object from moving (this anticipates changes on the
+        // simulator in LLTask::userSelect)
+        object->setVelocity(LLVector3::zero);
+        object->setAcceleration(LLVector3::zero);
+        //object->setAngularVelocity(LLVector3::zero);
+        object->resetRot();
+    }
+
+    updateSelectionCenter();
+    saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+    updatePointAt();
+    dialog_refresh_all();
+
+    // Almost always send to simulator, so you get a copy of the permissions
+    // structure back.
+    // JC: The one case where you don't want to do this is if you're selecting
+    // all the objects on a sim.
+    if (send_to_sim)
+    {
+        sendSelect();
+    }
+
+    // leave component mode
+    if (ALControlCache::EditLinkedParts)
+    {
+        gSavedSettings.setBOOL("EditLinkedParts", FALSE);
+        promoteSelectionToRoot();
+    }
+
+    // have selection manager handle edit menu immediately after
+    // user selects an object
+    if (mSelectedObjects->getObjectCount())
+    {
+        gEditMenuHandler = this;
+    }
+
+    return mSelectedObjects;
 }
 
 // Use for when the simulator kills an object.  This version also
@@ -672,139 +672,139 @@ LLObjectSelectionHandle LLSelectMgr::selectObjectAndFamily(const std::vector<LLV
 // Caller needs to call dialog_refresh_all if necessary.
 BOOL LLSelectMgr::removeObjectFromSelections(const LLUUID &id)
 {
-	BOOL object_found = FALSE;
-	LLTool *tool = NULL;
-
-	tool = LLToolMgr::getInstance()->getCurrentTool();
-
-	// It's possible that the tool is editing an object that is not selected
-	LLViewerObject* tool_editing_object = tool->getEditingObject();
-	if( tool_editing_object && tool_editing_object->mID == id)
-	{
-		tool->stopEditing();
-		object_found = TRUE;
-	}
-
-	// Iterate through selected objects list and kill the object
-	if( !object_found )
-	{
-		for (LLObjectSelection::iterator iter = getSelection()->begin();
-			 iter != getSelection()->end(); )
-		{
-			LLObjectSelection::iterator curiter = iter++;
-			LLViewerObject* object = (*curiter)->getObject();
-			if (object->mID == id)
-			{
-				if (tool)
-				{
-					tool->stopEditing();
-				}
-
-				// lose the selection, don't tell simulator, it knows
-				deselectObjectAndFamily(object, FALSE);
-				object_found = TRUE;
-				break; // must break here, may have removed multiple objects from list
-			}
-			else if (object->isAvatar() && object->getParent() && ((LLViewerObject*)object->getParent())->mID == id)
-			{
-				// It's possible the item being removed has an avatar sitting on it
-				// So remove the avatar that is sitting on the object.
-				deselectObjectAndFamily(object, FALSE);
-				break; // must break here, may have removed multiple objects from list
-			}
-		}
-	}
-
-	return object_found;
+    BOOL object_found = FALSE;
+    LLTool *tool = NULL;
+
+    tool = LLToolMgr::getInstance()->getCurrentTool();
+
+    // It's possible that the tool is editing an object that is not selected
+    LLViewerObject* tool_editing_object = tool->getEditingObject();
+    if( tool_editing_object && tool_editing_object->mID == id)
+    {
+        tool->stopEditing();
+        object_found = TRUE;
+    }
+
+    // Iterate through selected objects list and kill the object
+    if( !object_found )
+    {
+        for (LLObjectSelection::iterator iter = getSelection()->begin();
+             iter != getSelection()->end(); )
+        {
+            LLObjectSelection::iterator curiter = iter++;
+            LLViewerObject* object = (*curiter)->getObject();
+            if (object->mID == id)
+            {
+                if (tool)
+                {
+                    tool->stopEditing();
+                }
+
+                // lose the selection, don't tell simulator, it knows
+                deselectObjectAndFamily(object, FALSE);
+                object_found = TRUE;
+                break; // must break here, may have removed multiple objects from list
+            }
+            else if (object->isAvatar() && object->getParent() && ((LLViewerObject*)object->getParent())->mID == id)
+            {
+                // It's possible the item being removed has an avatar sitting on it
+                // So remove the avatar that is sitting on the object.
+                deselectObjectAndFamily(object, FALSE);
+                break; // must break here, may have removed multiple objects from list
+            }
+        }
+    }
+
+    return object_found;
 }
 
 bool LLSelectMgr::linkObjects()
 {
-	if (!selectGetAllRootsValid())
-	{
-		LLNotificationsUtil::add("UnableToLinkWhileDownloading");
-		return true;
-	}
-
-	S32 object_count = getSelection()->getObjectCount();
-	S32 max_objects = LLWorld::getInstance()->getRegionMaxLinkObjects();
-	if (object_count > max_objects + 1)
-	{
-		LLSD args;
-		args["COUNT"] = llformat("%d", object_count);
-		int max = max_objects + 1;
-		args["MAX"] = llformat("%d", max);
-		LLNotificationsUtil::add("UnableToLinkObjects", args);
-		return true;
-	}
-
-	if (getSelection()->getRootObjectCount() < 2)
-	{
-		LLNotificationsUtil::add("CannotLinkIncompleteSet");
-		return true;
-	}
-
-	if (!selectGetRootsModify())
-	{
-		LLNotificationsUtil::add("CannotLinkModify");
-		return true;
-	}
-
-	if (!selectGetRootsNonPermanentEnforced())
-	{
-		LLNotificationsUtil::add("CannotLinkPermanent");
-		return true;
-	}
-
-	LLUUID owner_id;
-	std::string owner_name;
-	if (!selectGetOwner(owner_id, owner_name))
-	{
-		// we don't actually care if you're the owner, but novices are
-		// the most likely to be stumped by this one, so offer the
-		// easiest and most likely solution.
-		LLNotificationsUtil::add("CannotLinkDifferentOwners");
-		return true;
-	}
-
-	if (!selectGetSameRegion())
-	{
-		LLNotificationsUtil::add("CannotLinkAcrossRegions");
-		return true;
-	}
-
-	sendLink();
-
-	return true;
+    if (!selectGetAllRootsValid())
+    {
+        LLNotificationsUtil::add("UnableToLinkWhileDownloading");
+        return true;
+    }
+
+    S32 object_count = getSelection()->getObjectCount();
+    S32 max_objects = LLWorld::getInstance()->getRegionMaxLinkObjects();
+    if (object_count > max_objects + 1)
+    {
+        LLSD args;
+        args["COUNT"] = llformat("%d", object_count);
+        int max = max_objects + 1;
+        args["MAX"] = llformat("%d", max);
+        LLNotificationsUtil::add("UnableToLinkObjects", args);
+        return true;
+    }
+
+    if (getSelection()->getRootObjectCount() < 2)
+    {
+        LLNotificationsUtil::add("CannotLinkIncompleteSet");
+        return true;
+    }
+
+    if (!selectGetRootsModify())
+    {
+        LLNotificationsUtil::add("CannotLinkModify");
+        return true;
+    }
+
+    if (!selectGetRootsNonPermanentEnforced())
+    {
+        LLNotificationsUtil::add("CannotLinkPermanent");
+        return true;
+    }
+
+    LLUUID owner_id;
+    std::string owner_name;
+    if (!selectGetOwner(owner_id, owner_name))
+    {
+        // we don't actually care if you're the owner, but novices are
+        // the most likely to be stumped by this one, so offer the
+        // easiest and most likely solution.
+        LLNotificationsUtil::add("CannotLinkDifferentOwners");
+        return true;
+    }
+
+    if (!selectGetSameRegion())
+    {
+        LLNotificationsUtil::add("CannotLinkAcrossRegions");
+        return true;
+    }
+
+    sendLink();
+
+    return true;
 }
 
 bool LLSelectMgr::unlinkObjects()
 {
-	S32 min_objects_for_confirm = gSavedSettings.getS32("MinObjectsForUnlinkConfirm");
-	S32 unlink_object_count = mSelectedObjects->getObjectCount(); // clears out nodes with NULL objects
-	if (unlink_object_count >= min_objects_for_confirm
-		&& unlink_object_count > mSelectedObjects->getRootObjectCount())
-	{
-		// total count > root count means that there are childer inside and that there are linksets that will be unlinked
-		LLNotificationsUtil::add("ConfirmUnlink", LLSD(), LLSD(), boost::bind(&LLSelectMgr::confirmUnlinkObjects, this, _1, _2));
-		return true;
-	}
+    S32 min_objects_for_confirm = gSavedSettings.getS32("MinObjectsForUnlinkConfirm");
+    S32 unlink_object_count = mSelectedObjects->getObjectCount(); // clears out nodes with NULL objects
+    if (unlink_object_count >= min_objects_for_confirm
+        && unlink_object_count > mSelectedObjects->getRootObjectCount())
+    {
+        // total count > root count means that there are childer inside and that there are linksets that will be unlinked
+        LLNotificationsUtil::add("ConfirmUnlink", LLSD(), LLSD(), boost::bind(&LLSelectMgr::confirmUnlinkObjects, this, _1, _2));
+        return true;
+    }
 
-	sendDelink();
-	return true;
+    sendDelink();
+    return true;
 }
 
 void LLSelectMgr::confirmUnlinkObjects(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	// if Cancel pressed
-	if (option == 1)
-	{
-		return;
-	}
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    // if Cancel pressed
+    if (option == 1)
+    {
+        return;
+    }
 
-	sendDelink();
-	return;
+    sendDelink();
+    return;
 }
 
 // in order to link, all objects must have the same owner, and the
@@ -821,177 +821,177 @@ void LLSelectMgr::confirmUnlinkObjects(const LLSD& notification, const LLSD& res
 // triangle count cannot exceed the designated limit.
 bool LLSelectMgr::enableLinkObjects()
 {
-	bool new_value = false;
-	// check if there are at least 2 objects selected, and that the
-	// user can modify at least one of the selected objects.
-
-	// in component mode, can't link
-	if (!ALControlCache::EditLinkedParts)
-	{
-		if(selectGetAllRootsValid() && getSelection()->getRootObjectCount() >= 2)
-		{
-			struct f : public LLSelectedObjectFunctor
-			{
-				virtual bool apply(LLViewerObject* object)
-				{
-					LLViewerObject *root_object = (object == NULL) ? NULL : object->getRootEdit();
-					return object->permModify() && !object->isPermanentEnforced() &&
-						((root_object == NULL) || !root_object->isPermanentEnforced());
-				}
-			} func;
-			const bool firstonly = true;
-			new_value = getSelection()->applyToRootObjects(&func, firstonly);
-		}
-	}
+    bool new_value = false;
+    // check if there are at least 2 objects selected, and that the
+    // user can modify at least one of the selected objects.
+
+    // in component mode, can't link
+    if (!ALControlCache::EditLinkedParts)
+    {
+        if(selectGetAllRootsValid() && getSelection()->getRootObjectCount() >= 2)
+        {
+            struct f : public LLSelectedObjectFunctor
+            {
+                virtual bool apply(LLViewerObject* object)
+                {
+                    LLViewerObject *root_object = (object == NULL) ? NULL : object->getRootEdit();
+                    return object->permModify() && !object->isPermanentEnforced() &&
+                        ((root_object == NULL) || !root_object->isPermanentEnforced());
+                }
+            } func;
+            const bool firstonly = true;
+            new_value = getSelection()->applyToRootObjects(&func, firstonly);
+        }
+    }
     if (!getSelection()->checkAnimatedObjectLinkable())
     {
         new_value = false;
     }
 // [RLVa:KB] - Checked: 2011-03-19 (RLVa-1.3.0f) | Modified: RLVa-0.2.0g
-	if ( (new_value) && ((rlv_handler_t::isEnabled()) && (!RlvActions::canStand())) )
-	{
-		// Allow only if the avie isn't sitting on any of the selected objects
-		LLObjectSelectionHandle hSel = getSelection();
-		RlvSelectIsSittingOn f(gAgentAvatarp);
-		if (hSel->getFirstRootNode(&f, TRUE) != NULL)
-			new_value = false;
-	}
+    if ( (new_value) && ((rlv_handler_t::isEnabled()) && (!RlvActions::canStand())) )
+    {
+        // Allow only if the avie isn't sitting on any of the selected objects
+        LLObjectSelectionHandle hSel = getSelection();
+        RlvSelectIsSittingOn f(gAgentAvatarp);
+        if (hSel->getFirstRootNode(&f, TRUE) != NULL)
+            new_value = false;
+    }
 // [/RLVa:KB]
-	return new_value;
+    return new_value;
 }
 
 bool LLSelectMgr::enableUnlinkObjects()
 {
-	LLViewerObject* first_editable_object = getSelection()->getFirstEditableObject();
-	LLViewerObject *root_object = (first_editable_object == NULL) ? NULL : first_editable_object->getRootEdit();
+    LLViewerObject* first_editable_object = getSelection()->getFirstEditableObject();
+    LLViewerObject *root_object = (first_editable_object == NULL) ? NULL : first_editable_object->getRootEdit();
 
-	bool new_value = selectGetAllRootsValid() &&
-		first_editable_object &&
-		!first_editable_object->isAttachment() && !first_editable_object->isPermanentEnforced() &&
-		((root_object == NULL) || !root_object->isPermanentEnforced());
+    bool new_value = selectGetAllRootsValid() &&
+        first_editable_object &&
+        !first_editable_object->isAttachment() && !first_editable_object->isPermanentEnforced() &&
+        ((root_object == NULL) || !root_object->isPermanentEnforced());
 // [RLVa:KB] - Checked: 2011-03-19 (RLVa-1.3.0f) | Modified: RLVa-0.2.0g
-	if ( (new_value) && ((rlv_handler_t::isEnabled()) && (!RlvActions::canStand())) )
-	{
-		// Allow only if the avie isn't sitting on any of the selected objects
-		LLObjectSelectionHandle hSel = getSelection();
-		RlvSelectIsSittingOn f(gAgentAvatarp);
-		if (hSel->getFirstRootNode(&f, TRUE) != NULL)
-			new_value = false;
-	}
+    if ( (new_value) && ((rlv_handler_t::isEnabled()) && (!RlvActions::canStand())) )
+    {
+        // Allow only if the avie isn't sitting on any of the selected objects
+        LLObjectSelectionHandle hSel = getSelection();
+        RlvSelectIsSittingOn f(gAgentAvatarp);
+        if (hSel->getFirstRootNode(&f, TRUE) != NULL)
+            new_value = false;
+    }
 // [/RLVa:KB]
-	return new_value;
+    return new_value;
 }
 
 void LLSelectMgr::deselectObjectAndFamily(LLViewerObject* object, BOOL send_to_sim, BOOL include_entire_object)
 {
-	// bail if nothing selected or if object wasn't selected in the first place
-	if(!object) return;
-	if(!object->isSelected()) return;
-
-	// Collect all of the objects, and remove them
-	std::vector<LLViewerObject*> objects;
-
-	if (include_entire_object)
-	{
-		// Since we're selecting a family, start at the root, but
-		// don't include an avatar.
-		LLViewerObject* root = object;
-	
-		while(!root->isAvatar() && root->getParent())
-		{
-			LLViewerObject* parent = (LLViewerObject*)root->getParent();
-			if (parent->isAvatar())
-			{
-				break;
-			}
-			root = parent;
-		}
-	
-		object = root;
-	}
-	else
-	{
-		object = (LLViewerObject*)object->getRoot();
-	}
-
-	object->addThisAndAllChildren(objects);
-	remove(objects);
-
-	if (!send_to_sim) return;
-
-	//-----------------------------------------------------------
-	// Inform simulator of deselection
-	//-----------------------------------------------------------
-	LLViewerRegion* regionp = object->getRegion();
-
-	BOOL start_new_message = TRUE;
-	S32 select_count = 0;
-
-	LLMessageSystem* msg = gMessageSystem;
-	for (U32 i = 0; i < objects.size(); i++)
-	{
-		if (start_new_message)
-		{
-			msg->newMessageFast(_PREHASH_ObjectDeselect);
-			msg->nextBlockFast(_PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-			msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-			select_count++;
-			start_new_message = FALSE;
-		}
-
-		msg->nextBlockFast(_PREHASH_ObjectData);
-		msg->addU32Fast(_PREHASH_ObjectLocalID, (objects[i])->getLocalID());
-		select_count++;
-
-		// Zap the angular velocity, as the sim will set it to zero
-		objects[i]->setAngularVelocity( 0,0,0 );
-		objects[i]->setVelocity( 0,0,0 );
-
-		if(msg->isSendFullFast(nullptr) || select_count >= MAX_OBJECTS_PER_PACKET)
-		{
-			msg->sendReliable(regionp->getHost() );
-			select_count = 0;
-			start_new_message = TRUE;
-		}
-	}
-
-	if (!start_new_message)
-	{
-		msg->sendReliable(regionp->getHost() );
-	}
-
-	updatePointAt();
-	updateSelectionCenter();
+    // bail if nothing selected or if object wasn't selected in the first place
+    if(!object) return;
+    if(!object->isSelected()) return;
+
+    // Collect all of the objects, and remove them
+    std::vector<LLViewerObject*> objects;
+
+    if (include_entire_object)
+    {
+        // Since we're selecting a family, start at the root, but
+        // don't include an avatar.
+        LLViewerObject* root = object;
+
+        while(!root->isAvatar() && root->getParent())
+        {
+            LLViewerObject* parent = (LLViewerObject*)root->getParent();
+            if (parent->isAvatar())
+            {
+                break;
+            }
+            root = parent;
+        }
+
+        object = root;
+    }
+    else
+    {
+        object = (LLViewerObject*)object->getRoot();
+    }
+
+    object->addThisAndAllChildren(objects);
+    remove(objects);
+
+    if (!send_to_sim) return;
+
+    //-----------------------------------------------------------
+    // Inform simulator of deselection
+    //-----------------------------------------------------------
+    LLViewerRegion* regionp = object->getRegion();
+
+    BOOL start_new_message = TRUE;
+    S32 select_count = 0;
+
+    LLMessageSystem* msg = gMessageSystem;
+    for (U32 i = 0; i < objects.size(); i++)
+    {
+        if (start_new_message)
+        {
+            msg->newMessageFast(_PREHASH_ObjectDeselect);
+            msg->nextBlockFast(_PREHASH_AgentData);
+            msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+            msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+            select_count++;
+            start_new_message = FALSE;
+        }
+
+        msg->nextBlockFast(_PREHASH_ObjectData);
+        msg->addU32Fast(_PREHASH_ObjectLocalID, (objects[i])->getLocalID());
+        select_count++;
+
+        // Zap the angular velocity, as the sim will set it to zero
+        objects[i]->setAngularVelocity( 0,0,0 );
+        objects[i]->setVelocity( 0,0,0 );
+
+        if(msg->isSendFullFast(nullptr) || select_count >= MAX_OBJECTS_PER_PACKET)
+        {
+            msg->sendReliable(regionp->getHost() );
+            select_count = 0;
+            start_new_message = TRUE;
+        }
+    }
+
+    if (!start_new_message)
+    {
+        msg->sendReliable(regionp->getHost() );
+    }
+
+    updatePointAt();
+    updateSelectionCenter();
 }
 
 void LLSelectMgr::deselectObjectOnly(LLViewerObject* object, BOOL send_to_sim)
 {
-	// bail if nothing selected or if object wasn't selected in the first place
-	if (!object) return;
-	if (!object->isSelected() ) return;
+    // bail if nothing selected or if object wasn't selected in the first place
+    if (!object) return;
+    if (!object->isSelected() ) return;
 
-	// Zap the angular velocity, as the sim will set it to zero
-	object->setAngularVelocity( 0,0,0 );
-	object->setVelocity( 0,0,0 );
+    // Zap the angular velocity, as the sim will set it to zero
+    object->setAngularVelocity( 0,0,0 );
+    object->setVelocity( 0,0,0 );
 
-	if (send_to_sim)
-	{
-		LLViewerRegion* region = object->getRegion();
-		gMessageSystem->newMessageFast(_PREHASH_ObjectDeselect);
-		gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-		gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-		gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-		gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID() );
-		gMessageSystem->sendReliable(region->getHost());
-	}
+    if (send_to_sim)
+    {
+        LLViewerRegion* region = object->getRegion();
+        gMessageSystem->newMessageFast(_PREHASH_ObjectDeselect);
+        gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+        gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+        gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+        gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID() );
+        gMessageSystem->sendReliable(region->getHost());
+    }
 
-	// This will refresh dialogs.
-	remove( object );
+    // This will refresh dialogs.
+    remove( object );
 
-	updatePointAt();
-	updateSelectionCenter();
+    updatePointAt();
+    updateSelectionCenter();
 }
 
 
@@ -1001,50 +1001,50 @@ void LLSelectMgr::deselectObjectOnly(LLViewerObject* object, BOOL send_to_sim)
 
 void LLSelectMgr::addAsFamily(std::vector<LLViewerObject*>& objects, BOOL add_to_end)
 {
-	for (LLViewerObject* objectp : objects)
-	{
-		// Can't select yourself
-		if (objectp->mID == gAgentID
-			&& !mAllowSelectAvatar)
-		{
-			continue;
-		}
-
-		if (!objectp->isSelected())
-		{
-			LLSelectNode *nodep = new LLSelectNode(objectp, TRUE);
-			if (add_to_end)
-			{
-				mSelectedObjects->addNodeAtEnd(nodep);
-			}
-			else
-			{
-				mSelectedObjects->addNode(nodep);
-			}
-			objectp->setSelected(TRUE);
-
-			if (objectp->getNumTEs() > 0)
-			{
-				nodep->selectAllTEs(TRUE);
-				objectp->setAllTESelected(true);
-			}
-			else
-			{
-				// object has no faces, so don't mess with faces
-			}
-		}
-		else
-		{
-			// we want this object to be selected for real
-			// so clear transient flag
-			LLSelectNode* select_node = mSelectedObjects->findNode(objectp);
-			if (select_node)
-			{
-				select_node->setTransient(FALSE);
-			}
-		}
-	}
-	saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+    for (LLViewerObject* objectp : objects)
+    {
+        // Can't select yourself
+        if (objectp->mID == gAgentID
+            && !mAllowSelectAvatar)
+        {
+            continue;
+        }
+
+        if (!objectp->isSelected())
+        {
+            LLSelectNode *nodep = new LLSelectNode(objectp, TRUE);
+            if (add_to_end)
+            {
+                mSelectedObjects->addNodeAtEnd(nodep);
+            }
+            else
+            {
+                mSelectedObjects->addNode(nodep);
+            }
+            objectp->setSelected(TRUE);
+
+            if (objectp->getNumTEs() > 0)
+            {
+                nodep->selectAllTEs(TRUE);
+                objectp->setAllTESelected(true);
+            }
+            else
+            {
+                // object has no faces, so don't mess with faces
+            }
+        }
+        else
+        {
+            // we want this object to be selected for real
+            // so clear transient flag
+            LLSelectNode* select_node = mSelectedObjects->findNode(objectp);
+            if (select_node)
+            {
+                select_node->setTransient(FALSE);
+            }
+        }
+    }
+    saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
 }
 
 //-----------------------------------------------------------------------------
@@ -1052,439 +1052,439 @@ void LLSelectMgr::addAsFamily(std::vector<LLViewerObject*>& objects, BOOL add_to
 //-----------------------------------------------------------------------------
 void LLSelectMgr::addAsIndividual(LLViewerObject *objectp, S32 face, BOOL undoable, S32 gltf_node, S32 gltf_primitive)
 {
-	// check to see if object is already in list
-	LLSelectNode *nodep = mSelectedObjects->findNode(objectp);
-
-	// if not in list, add it
-	if (!nodep)
-	{
-		nodep = new LLSelectNode(objectp, TRUE);
-		mSelectedObjects->addNode(nodep);
-		llassert_always(nodep->getObject());
-	}
-	else
-	{
-		// make this a full-fledged selection
-		nodep->setTransient(FALSE);
-		// Move it to the front of the list
-		mSelectedObjects->moveNodeToFront(nodep);
-	}
-
-	// Make sure the object is tagged as selected
-	objectp->setSelected( TRUE );
-
-	// And make sure we don't consider it as part of a family
-	nodep->mIndividualSelection = TRUE;
-
-	// Handle face selection
-	if (objectp->getNumTEs() <= 0)
-	{
-		// object has no faces, so don't do anything
-	}
-	else if (face == SELECT_ALL_TES)
-	{
-		nodep->selectAllTEs(TRUE);
-		objectp->setAllTESelected(true);
-	}
-	else if (0 <= face && face < SELECT_MAX_TES)
-	{
-		nodep->selectTE(face, TRUE);
-		objectp->setTESelected(face, true);
-	}
-	else
-	{
-		LL_ERRS() << "LLSelectMgr::add face " << face << " out-of-range" << LL_ENDL;
-		return;
-	}
+    // check to see if object is already in list
+    LLSelectNode *nodep = mSelectedObjects->findNode(objectp);
+
+    // if not in list, add it
+    if (!nodep)
+    {
+        nodep = new LLSelectNode(objectp, TRUE);
+        mSelectedObjects->addNode(nodep);
+        llassert_always(nodep->getObject());
+    }
+    else
+    {
+        // make this a full-fledged selection
+        nodep->setTransient(FALSE);
+        // Move it to the front of the list
+        mSelectedObjects->moveNodeToFront(nodep);
+    }
+
+    // Make sure the object is tagged as selected
+    objectp->setSelected( TRUE );
+
+    // And make sure we don't consider it as part of a family
+    nodep->mIndividualSelection = TRUE;
+
+    // Handle face selection
+    if (objectp->getNumTEs() <= 0)
+    {
+        // object has no faces, so don't do anything
+    }
+    else if (face == SELECT_ALL_TES)
+    {
+        nodep->selectAllTEs(TRUE);
+        objectp->setAllTESelected(true);
+    }
+    else if (0 <= face && face < SELECT_MAX_TES)
+    {
+        nodep->selectTE(face, TRUE);
+        objectp->setTESelected(face, true);
+    }
+    else
+    {
+        LL_ERRS() << "LLSelectMgr::add face " << face << " out-of-range" << LL_ENDL;
+        return;
+    }
 
     // Handle glTF node selection
     if (gltf_node >= 0)
     {
         nodep->selectGLTFNode(gltf_node, gltf_primitive, TRUE);
-     
+
     }
 
-	saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
-	updateSelectionCenter();
-	dialog_refresh_all();
+    saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+    updateSelectionCenter();
+    dialog_refresh_all();
 }
 
 
 LLObjectSelectionHandle LLSelectMgr::setHoverObject(LLViewerObject *objectp, S32 face)
 {
-	if (!objectp)
-	{
-		mHoverObjects->deleteAllNodes();
-		return NULL;
-	}
-
-	// Can't select yourself
-	if (objectp->mID == gAgentID)
-	{
-		mHoverObjects->deleteAllNodes();
-		return NULL;
-	}
-
-	// Can't select land
-	if (objectp->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH)
-	{
-		mHoverObjects->deleteAllNodes();
-		return NULL;
-	}
-
-	mHoverObjects->mPrimaryObject = objectp; 
-
-	objectp = objectp->getRootEdit();
-
-	// is the requested object the same as the existing hover object root?
-	// NOTE: there is only ever one linked set in mHoverObjects
-	if (mHoverObjects->getFirstRootObject() != objectp) 
-	{
-
-		// Collect all of the objects
-		std::vector<LLViewerObject*> objects;
-		objectp = objectp->getRootEdit();
-		objectp->addThisAndNonJointChildren(objects);
-
-		mHoverObjects->deleteAllNodes();
-		for (LLViewerObject* cur_objectp : objects)
-		{
-			if(!cur_objectp || cur_objectp->isDead())
-			{
-				continue;
-			}
-			LLSelectNode* nodep = new LLSelectNode(cur_objectp, FALSE);
-			nodep->selectTE(face, TRUE);
-			mHoverObjects->addNodeAtEnd(nodep);
-		}
-
-		requestObjectPropertiesFamily(objectp);
-	}
-
-	return mHoverObjects;
+    if (!objectp)
+    {
+        mHoverObjects->deleteAllNodes();
+        return NULL;
+    }
+
+    // Can't select yourself
+    if (objectp->mID == gAgentID)
+    {
+        mHoverObjects->deleteAllNodes();
+        return NULL;
+    }
+
+    // Can't select land
+    if (objectp->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH)
+    {
+        mHoverObjects->deleteAllNodes();
+        return NULL;
+    }
+
+    mHoverObjects->mPrimaryObject = objectp;
+
+    objectp = objectp->getRootEdit();
+
+    // is the requested object the same as the existing hover object root?
+    // NOTE: there is only ever one linked set in mHoverObjects
+    if (mHoverObjects->getFirstRootObject() != objectp)
+    {
+
+        // Collect all of the objects
+        std::vector<LLViewerObject*> objects;
+        objectp = objectp->getRootEdit();
+        objectp->addThisAndNonJointChildren(objects);
+
+        mHoverObjects->deleteAllNodes();
+        for (LLViewerObject* cur_objectp : objects)
+        {
+            if(!cur_objectp || cur_objectp->isDead())
+            {
+                continue;
+            }
+            LLSelectNode* nodep = new LLSelectNode(cur_objectp, FALSE);
+            nodep->selectTE(face, TRUE);
+            mHoverObjects->addNodeAtEnd(nodep);
+        }
+
+        requestObjectPropertiesFamily(objectp);
+    }
+
+    return mHoverObjects;
 }
 
 LLSelectNode *LLSelectMgr::getHoverNode()
 {
-	return mHoverObjects->getFirstRootNode();
+    return mHoverObjects->getFirstRootNode();
 }
 
 LLSelectNode *LLSelectMgr::getPrimaryHoverNode()
 {
-	return mHoverObjects->mSelectNodeMap[mHoverObjects->mPrimaryObject];
+    return mHoverObjects->mSelectNodeMap[mHoverObjects->mPrimaryObject];
 }
 
 void LLSelectMgr::highlightObjectOnly(LLViewerObject* objectp)
 {
-	if (!objectp)
-	{
-		return;
-	}
+    if (!objectp)
+    {
+        return;
+    }
+
+    if (objectp->getPCode() != LL_PCODE_VOLUME)
+    {
+        return;
+    }
 
-	if (objectp->getPCode() != LL_PCODE_VOLUME)
-	{
-		return;
-	}
-	
     if ((gSavedSettings.getBOOL("SelectCopyOnly") && !objectp->permCopy())
-		|| (gSavedSettings.getBOOL("SelectOwnedOnly") && !objectp->permYouOwner())
+        || (gSavedSettings.getBOOL("SelectOwnedOnly") && !objectp->permYouOwner())
         || (gSavedSettings.getBOOL("SelectMovableOnly") && (!objectp->permMove() || objectp->isPermanentEnforced())))
-	{
-		// only select my own objects
-		return;
-	}
+    {
+        // only select my own objects
+        return;
+    }
 
-	mRectSelectedObjects.insert(objectp);
+    mRectSelectedObjects.insert(objectp);
 }
 
 void LLSelectMgr::highlightObjectAndFamily(LLViewerObject* objectp)
 {
-	if (!objectp)
-	{
-		return;
-	}
+    if (!objectp)
+    {
+        return;
+    }
 
-	LLViewerObject* root_obj = (LLViewerObject*)objectp->getRoot();
+    LLViewerObject* root_obj = (LLViewerObject*)objectp->getRoot();
 
-	highlightObjectOnly(root_obj);
+    highlightObjectOnly(root_obj);
 
-	LLViewerObject::const_child_list_t& child_list = root_obj->getChildren();
-	for (LLViewerObject* child : child_list)
-	{
-		highlightObjectOnly(child);
-	}
+    LLViewerObject::const_child_list_t& child_list = root_obj->getChildren();
+    for (LLViewerObject* child : child_list)
+    {
+        highlightObjectOnly(child);
+    }
 }
 
 // Note that this ignores the "select owned only" flag
 // It's also more efficient than calling the single-object version over and over.
 void LLSelectMgr::highlightObjectAndFamily(const std::vector<LLViewerObject*>& objects)
 {
-	for (LLViewerObject* object : objects)
-	{
-		if (!object)
-		{
-			continue;
-		}
-		if (object->getPCode() != LL_PCODE_VOLUME)
-		{
-			continue;
-		}
+    for (LLViewerObject* object : objects)
+    {
+        if (!object)
+        {
+            continue;
+        }
+        if (object->getPCode() != LL_PCODE_VOLUME)
+        {
+            continue;
+        }
 
-		LLViewerObject* root = (LLViewerObject*)object->getRoot();
-		mRectSelectedObjects.insert(root);
+        LLViewerObject* root = (LLViewerObject*)object->getRoot();
+        mRectSelectedObjects.insert(root);
 
-		LLViewerObject::const_child_list_t& child_list = root->getChildren();
-		for (LLViewerObject* child : child_list)
-		{
-			mRectSelectedObjects.insert(child);
-		}
-	}
+        LLViewerObject::const_child_list_t& child_list = root->getChildren();
+        for (LLViewerObject* child : child_list)
+        {
+            mRectSelectedObjects.insert(child);
+        }
+    }
 }
 
 void LLSelectMgr::unhighlightObjectOnly(LLViewerObject* objectp)
 {
-	if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
-	{
-		return;
-	}
+    if (!objectp || (objectp->getPCode() != LL_PCODE_VOLUME))
+    {
+        return;
+    }
 
-	mRectSelectedObjects.erase(objectp);
+    mRectSelectedObjects.erase(objectp);
 }
 
 void LLSelectMgr::unhighlightObjectAndFamily(LLViewerObject* objectp)
 {
-	if (!objectp)
-	{
-		return;
-	}
+    if (!objectp)
+    {
+        return;
+    }
 
-	LLViewerObject* root_obj = (LLViewerObject*)objectp->getRoot();
+    LLViewerObject* root_obj = (LLViewerObject*)objectp->getRoot();
 
-	unhighlightObjectOnly(root_obj);
+    unhighlightObjectOnly(root_obj);
 
-	LLViewerObject::const_child_list_t& child_list = root_obj->getChildren();
-	for (LLViewerObject* child : child_list)
-	{
-		unhighlightObjectOnly(child);
-	}
+    LLViewerObject::const_child_list_t& child_list = root_obj->getChildren();
+    for (LLViewerObject* child : child_list)
+    {
+        unhighlightObjectOnly(child);
+    }
 }
 
 
 void LLSelectMgr::unhighlightAll()
 {
-	mRectSelectedObjects.clear();
-	mHighlightedObjects->deleteAllNodes();
+    mRectSelectedObjects.clear();
+    mHighlightedObjects->deleteAllNodes();
 }
 
 LLObjectSelectionHandle LLSelectMgr::selectHighlightedObjects()
 {
-	if (!mHighlightedObjects->getNumNodes())
-	{
-		return NULL;
-	}
+    if (!mHighlightedObjects->getNumNodes())
+    {
+        return NULL;
+    }
+
+    //clear primary object
+    mSelectedObjects->mPrimaryObject = NULL;
 
-	//clear primary object
-	mSelectedObjects->mPrimaryObject = NULL;
+    for (LLObjectSelection::iterator iter = getHighlightedObjects()->begin();
+         iter != getHighlightedObjects()->end(); )
+    {
+        LLObjectSelection::iterator curiter = iter++;
 
-	for (LLObjectSelection::iterator iter = getHighlightedObjects()->begin();
-		 iter != getHighlightedObjects()->end(); )
-	{
-		LLObjectSelection::iterator curiter = iter++;
-	
-		LLSelectNode *nodep = *curiter;
-		LLViewerObject* objectp = nodep->getObject();
+        LLSelectNode *nodep = *curiter;
+        LLViewerObject* objectp = nodep->getObject();
 
-		if (!canSelectObject(objectp))
-		{
-			continue;
-		}
+        if (!canSelectObject(objectp))
+        {
+            continue;
+        }
 
-		// already selected
-		if (objectp->isSelected())
-		{
-			continue;
-		}
+        // already selected
+        if (objectp->isSelected())
+        {
+            continue;
+        }
 
-		LLSelectNode* new_nodep = new LLSelectNode(*nodep);
-		mSelectedObjects->addNode(new_nodep);
+        LLSelectNode* new_nodep = new LLSelectNode(*nodep);
+        mSelectedObjects->addNode(new_nodep);
 
-		// flag this object as selected
-		objectp->setSelected(TRUE);
-		objectp->setAllTESelected(true);
+        // flag this object as selected
+        objectp->setSelected(TRUE);
+        objectp->setAllTESelected(true);
 
-		mSelectedObjects->mSelectType = getSelectTypeForObject(objectp);
+        mSelectedObjects->mSelectType = getSelectTypeForObject(objectp);
 
-		// request properties on root objects
-		if (objectp->isRootEdit())
-		{
-			requestObjectPropertiesFamily(objectp);
-		}
-	}
+        // request properties on root objects
+        if (objectp->isRootEdit())
+        {
+            requestObjectPropertiesFamily(objectp);
+        }
+    }
 
-	// pack up messages to let sim know these objects are selected
-	sendSelect();
-	unhighlightAll();
-	updateSelectionCenter();
-	saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
-	updatePointAt();
+    // pack up messages to let sim know these objects are selected
+    sendSelect();
+    unhighlightAll();
+    updateSelectionCenter();
+    saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+    updatePointAt();
 
-	if (mSelectedObjects->getObjectCount())
-	{
-		gEditMenuHandler = this;
-	}
+    if (mSelectedObjects->getObjectCount())
+    {
+        gEditMenuHandler = this;
+    }
 
-	return mSelectedObjects;
+    return mSelectedObjects;
 }
 
 void LLSelectMgr::deselectHighlightedObjects()
 {
-	BOOL select_linked_set = !ALControlCache::EditLinkedParts;
-	for (LLViewerObject* objectp : mRectSelectedObjects)
-	{
-		if (!select_linked_set)
-		{
-			deselectObjectOnly(objectp);
-		}
-		else
-		{
-			LLViewerObject* root_object = (LLViewerObject*)objectp->getRoot();
-			if (root_object->isSelected())
-			{
-				deselectObjectAndFamily(root_object);
-			}
-		}
-	}
-
-	unhighlightAll();
+    BOOL select_linked_set = !ALControlCache::EditLinkedParts;
+    for (LLViewerObject* objectp : mRectSelectedObjects)
+    {
+        if (!select_linked_set)
+        {
+            deselectObjectOnly(objectp);
+        }
+        else
+        {
+            LLViewerObject* root_object = (LLViewerObject*)objectp->getRoot();
+            if (root_object->isSelected())
+            {
+                deselectObjectAndFamily(root_object);
+            }
+        }
+    }
+
+    unhighlightAll();
 }
 
 void LLSelectMgr::addGridObject(LLViewerObject* objectp)
 {
-	LLSelectNode* nodep = new LLSelectNode(objectp, FALSE);
-	mGridObjects.addNodeAtEnd(nodep);
+    LLSelectNode* nodep = new LLSelectNode(objectp, FALSE);
+    mGridObjects.addNodeAtEnd(nodep);
 
-	LLViewerObject::const_child_list_t& child_list = objectp->getChildren();
-	for (LLViewerObject* child : child_list)
-	{
-		nodep = new LLSelectNode(child, FALSE);
-		mGridObjects.addNodeAtEnd(nodep);
-	}
+    LLViewerObject::const_child_list_t& child_list = objectp->getChildren();
+    for (LLViewerObject* child : child_list)
+    {
+        nodep = new LLSelectNode(child, FALSE);
+        mGridObjects.addNodeAtEnd(nodep);
+    }
 }
 
 void LLSelectMgr::clearGridObjects()
 {
-	mGridObjects.deleteAllNodes();
+    mGridObjects.deleteAllNodes();
 }
 
 void LLSelectMgr::setGridMode(EGridMode mode)
 {
-	mGridMode = mode;
-	gSavedSettings.setS32("GridMode", mode);
-	updateSelectionCenter();
+    mGridMode = mode;
+    gSavedSettings.setS32("GridMode", mode);
+    updateSelectionCenter();
 }
 
 void LLSelectMgr::getGrid(LLVector3& origin, LLQuaternion &rotation, LLVector3 &scale, bool for_snap_guides)
 {
-	mGridObjects.cleanupNodes();
-	
-	LLViewerObject* first_grid_object = mGridObjects.getFirstObject();
-
-	if (mGridMode == GRID_MODE_LOCAL && mSelectedObjects->getObjectCount())
-	{
-		//LLViewerObject* root = getSelectedParentObject(mSelectedObjects->getFirstObject());
-		mGridOrigin = mSavedSelectionBBox.getCenterAgent();
-		mGridScale = mSavedSelectionBBox.getExtentLocal() * 0.5f;
-
-		// DEV-12570 Just taking the saved selection box rotation prevents
-		// wild rotations of linked sets while in local grid mode
-		//if(mSelectedObjects->getObjectCount() < 2 || !root || root->mDrawable.isNull())
-		{
-			mGridRotation = mSavedSelectionBBox.getRotation();
-		}
-		/*else //set to the root object
-		{
-			mGridRotation = root->getRenderRotation();			
-		}*/
-	}
-	else if (mGridMode == GRID_MODE_REF_OBJECT && first_grid_object && first_grid_object->mDrawable.notNull())
-	{
-		LLSelectNode *node = mSelectedObjects->findNode(first_grid_object);
-		if (!for_snap_guides && node)
-		{
-			mGridRotation = node->mSavedRotation;
-		}
-		else
-		{
-			mGridRotation = first_grid_object->getRenderRotation();
-		}
-
-		LLVector4a min_extents(F32_MAX);
-		LLVector4a max_extents(-F32_MAX);
-		BOOL grid_changed = FALSE;
-		for (LLSelectNode* nodep : mGridObjects)
-		{
-			LLViewerObject* object = nodep->getObject();
-			LLDrawable* drawable = object->mDrawable;
-			if (drawable)
-			{
-				const LLVector4a* ext = drawable->getSpatialExtents();
-				update_min_max(min_extents, max_extents, ext[0]);
-				update_min_max(min_extents, max_extents, ext[1]);
-				grid_changed = TRUE;
-			}
-		}
-		if (grid_changed)
-		{
-			LLVector4a center, size;
-			center.setAdd(min_extents, max_extents);
-			center.mul(0.5f);
-			size.setSub(max_extents, min_extents);
-			size.mul(0.5f);
-
-			LLDrawable* drawable = first_grid_object->mDrawable;
-			if (drawable && drawable->isActive())
-			{
-				first_grid_object->getRenderMatrix().affineTransform(center,center);
-			}
-			mGridOrigin.set(center.getF32ptr());
-			mGridScale.set(size.getF32ptr());
-		}
-	}
-	else // GRID_MODE_WORLD or just plain default
-	{
-		const BOOL non_root_ok = TRUE;
-		LLViewerObject* first_object = mSelectedObjects->getFirstRootObject(non_root_ok);
-
-		mGridOrigin.clearVec();
-		mGridRotation.loadIdentity();
-
-		mSelectedObjects->mSelectType = getSelectTypeForObject( first_object );
-
-		switch (mSelectedObjects->mSelectType)
-		{
-		case SELECT_TYPE_ATTACHMENT:
-			if (first_object && first_object->getRootEdit()->mDrawable.notNull())
-			{
-				// this means this object *has* to be an attachment
-				LLXform* attachment_point_xform = first_object->getRootEdit()->mDrawable->mXform.getParent();
-				mGridOrigin = attachment_point_xform->getWorldPosition();
-				mGridRotation = attachment_point_xform->getWorldRotation();
-				mGridScale = LLVector3(1.f, 1.f, 1.f) * ALControlCache::GridResolution;
-			}
-			break;
-		case SELECT_TYPE_HUD:
-			mGridScale = LLVector3(1.f, 1.f, 1.f) * llmin(ALControlCache::GridResolution, 0.5f);
-			break;
-		case SELECT_TYPE_WORLD:
-			mGridScale = LLVector3(1.f, 1.f, 1.f) * ALControlCache::GridResolution;
-			break;
-		}
-	}
-	llassert(mGridOrigin.isFinite());
-
-	origin = mGridOrigin;
-	rotation = mGridRotation;
-	scale = mGridScale;
+    mGridObjects.cleanupNodes();
+
+    LLViewerObject* first_grid_object = mGridObjects.getFirstObject();
+
+    if (mGridMode == GRID_MODE_LOCAL && mSelectedObjects->getObjectCount())
+    {
+        //LLViewerObject* root = getSelectedParentObject(mSelectedObjects->getFirstObject());
+        mGridOrigin = mSavedSelectionBBox.getCenterAgent();
+        mGridScale = mSavedSelectionBBox.getExtentLocal() * 0.5f;
+
+        // DEV-12570 Just taking the saved selection box rotation prevents
+        // wild rotations of linked sets while in local grid mode
+        //if(mSelectedObjects->getObjectCount() < 2 || !root || root->mDrawable.isNull())
+        {
+            mGridRotation = mSavedSelectionBBox.getRotation();
+        }
+        /*else //set to the root object
+        {
+            mGridRotation = root->getRenderRotation();
+        }*/
+    }
+    else if (mGridMode == GRID_MODE_REF_OBJECT && first_grid_object && first_grid_object->mDrawable.notNull())
+    {
+        LLSelectNode *node = mSelectedObjects->findNode(first_grid_object);
+        if (!for_snap_guides && node)
+        {
+            mGridRotation = node->mSavedRotation;
+        }
+        else
+        {
+            mGridRotation = first_grid_object->getRenderRotation();
+        }
+
+        LLVector4a min_extents(F32_MAX);
+        LLVector4a max_extents(-F32_MAX);
+        BOOL grid_changed = FALSE;
+        for (LLSelectNode* nodep : mGridObjects)
+        {
+            LLViewerObject* object = nodep->getObject();
+            LLDrawable* drawable = object->mDrawable;
+            if (drawable)
+            {
+                const LLVector4a* ext = drawable->getSpatialExtents();
+                update_min_max(min_extents, max_extents, ext[0]);
+                update_min_max(min_extents, max_extents, ext[1]);
+                grid_changed = TRUE;
+            }
+        }
+        if (grid_changed)
+        {
+            LLVector4a center, size;
+            center.setAdd(min_extents, max_extents);
+            center.mul(0.5f);
+            size.setSub(max_extents, min_extents);
+            size.mul(0.5f);
+
+            LLDrawable* drawable = first_grid_object->mDrawable;
+            if (drawable && drawable->isActive())
+            {
+                first_grid_object->getRenderMatrix().affineTransform(center,center);
+            }
+            mGridOrigin.set(center.getF32ptr());
+            mGridScale.set(size.getF32ptr());
+        }
+    }
+    else // GRID_MODE_WORLD or just plain default
+    {
+        const BOOL non_root_ok = TRUE;
+        LLViewerObject* first_object = mSelectedObjects->getFirstRootObject(non_root_ok);
+
+        mGridOrigin.clearVec();
+        mGridRotation.loadIdentity();
+
+        mSelectedObjects->mSelectType = getSelectTypeForObject( first_object );
+
+        switch (mSelectedObjects->mSelectType)
+        {
+        case SELECT_TYPE_ATTACHMENT:
+            if (first_object && first_object->getRootEdit()->mDrawable.notNull())
+            {
+                // this means this object *has* to be an attachment
+                LLXform* attachment_point_xform = first_object->getRootEdit()->mDrawable->mXform.getParent();
+                mGridOrigin = attachment_point_xform->getWorldPosition();
+                mGridRotation = attachment_point_xform->getWorldRotation();
+                mGridScale = LLVector3(1.f, 1.f, 1.f) * ALControlCache::GridResolution;
+            }
+            break;
+        case SELECT_TYPE_HUD:
+            mGridScale = LLVector3(1.f, 1.f, 1.f) * llmin(ALControlCache::GridResolution, 0.5f);
+            break;
+        case SELECT_TYPE_WORLD:
+            mGridScale = LLVector3(1.f, 1.f, 1.f) * ALControlCache::GridResolution;
+            break;
+        }
+    }
+    llassert(mGridOrigin.isFinite());
+
+    origin = mGridOrigin;
+    rotation = mGridRotation;
+    scale = mGridScale;
 }
 
 //-----------------------------------------------------------------------------
@@ -1493,18 +1493,18 @@ void LLSelectMgr::getGrid(LLVector3& origin, LLQuaternion &rotation, LLVector3 &
 
 void LLSelectMgr::remove(std::vector<LLViewerObject*>& objects)
 {
-	for (LLViewerObject* objectp : objects)
-	{
-		LLSelectNode* nodep = mSelectedObjects->findNode(objectp);
-		if (nodep)
-		{
-			objectp->setSelected(FALSE);
-			mSelectedObjects->removeNode(nodep);
-			nodep = NULL;
-		}
-	}
-	updateSelectionCenter();
-	dialog_refresh_all();
+    for (LLViewerObject* objectp : objects)
+    {
+        LLSelectNode* nodep = mSelectedObjects->findNode(objectp);
+        if (nodep)
+        {
+            objectp->setSelected(FALSE);
+            mSelectedObjects->removeNode(nodep);
+            nodep = NULL;
+        }
+    }
+    updateSelectionCenter();
+    dialog_refresh_all();
 }
 
 
@@ -1513,59 +1513,59 @@ void LLSelectMgr::remove(std::vector<LLViewerObject*>& objects)
 //-----------------------------------------------------------------------------
 void LLSelectMgr::remove(LLViewerObject *objectp, S32 te, BOOL undoable)
 {
-	// get object node (and verify it is in the selected list)
-	LLSelectNode *nodep = mSelectedObjects->findNode(objectp);
-	if (!nodep)
-	{
-		return;
-	}
-
-	// if face = all, remove object from list
-	if ((objectp->getNumTEs() <= 0) || (te == SELECT_ALL_TES))
-	{
-		// Remove all faces (or the object doesn't have faces) so remove the node
-		mSelectedObjects->removeNode(nodep);
-		nodep = NULL;
-		objectp->setSelected( FALSE );
-	}
-	else if (0 <= te && te < SELECT_MAX_TES)
-	{
-		// ...valid face, check to see if it was on
-		if (nodep->isTESelected(te))
-		{
-			nodep->selectTE(te, FALSE);
-			objectp->setTESelected(te, false);
-		}
-		else
-		{
-			LL_ERRS() << "LLSelectMgr::remove - tried to remove TE " << te << " that wasn't selected" << LL_ENDL;
-			return;
-		}
-
-		// ...check to see if this operation turned off all faces
-		BOOL found = FALSE;
-		for (S32 i = 0; i < nodep->getObject()->getNumTEs(); i++)
-		{
-			found = found || nodep->isTESelected(i);
-		}
-
-		// ...all faces now turned off, so remove
-		if (!found)
-		{
-			mSelectedObjects->removeNode(nodep);
-			nodep = NULL;
-			objectp->setSelected( FALSE );
-			// *FIXME: Doesn't update simulator that object is no longer selected
-		}
-	}
-	else
-	{
-		// ...out of range face
-		LL_ERRS() << "LLSelectMgr::remove - TE " << te << " out of range" << LL_ENDL;
-	}
-
-	updateSelectionCenter();
-	dialog_refresh_all();
+    // get object node (and verify it is in the selected list)
+    LLSelectNode *nodep = mSelectedObjects->findNode(objectp);
+    if (!nodep)
+    {
+        return;
+    }
+
+    // if face = all, remove object from list
+    if ((objectp->getNumTEs() <= 0) || (te == SELECT_ALL_TES))
+    {
+        // Remove all faces (or the object doesn't have faces) so remove the node
+        mSelectedObjects->removeNode(nodep);
+        nodep = NULL;
+        objectp->setSelected( FALSE );
+    }
+    else if (0 <= te && te < SELECT_MAX_TES)
+    {
+        // ...valid face, check to see if it was on
+        if (nodep->isTESelected(te))
+        {
+            nodep->selectTE(te, FALSE);
+            objectp->setTESelected(te, false);
+        }
+        else
+        {
+            LL_ERRS() << "LLSelectMgr::remove - tried to remove TE " << te << " that wasn't selected" << LL_ENDL;
+            return;
+        }
+
+        // ...check to see if this operation turned off all faces
+        BOOL found = FALSE;
+        for (S32 i = 0; i < nodep->getObject()->getNumTEs(); i++)
+        {
+            found = found || nodep->isTESelected(i);
+        }
+
+        // ...all faces now turned off, so remove
+        if (!found)
+        {
+            mSelectedObjects->removeNode(nodep);
+            nodep = NULL;
+            objectp->setSelected( FALSE );
+            // *FIXME: Doesn't update simulator that object is no longer selected
+        }
+    }
+    else
+    {
+        // ...out of range face
+        LL_ERRS() << "LLSelectMgr::remove - TE " << te << " out of range" << LL_ENDL;
+    }
+
+    updateSelectionCenter();
+    dialog_refresh_all();
 }
 
 
@@ -1574,17 +1574,17 @@ void LLSelectMgr::remove(LLViewerObject *objectp, S32 te, BOOL undoable)
 //-----------------------------------------------------------------------------
 void LLSelectMgr::removeAll()
 {
-	for (LLObjectSelection::iterator iter = mSelectedObjects->begin();
-		 iter != mSelectedObjects->end(); iter++ )
-	{
-		LLViewerObject *objectp = (*iter)->getObject();
-		objectp->setSelected( FALSE );
-	}
+    for (LLObjectSelection::iterator iter = mSelectedObjects->begin();
+         iter != mSelectedObjects->end(); iter++ )
+    {
+        LLViewerObject *objectp = (*iter)->getObject();
+        objectp->setSelected( FALSE );
+    }
+
+    mSelectedObjects->deleteAllNodes();
 
-	mSelectedObjects->deleteAllNodes();
-	
-	updateSelectionCenter();
-	dialog_refresh_all();
+    updateSelectionCenter();
+    dialog_refresh_all();
 }
 
 //-----------------------------------------------------------------------------
@@ -1592,40 +1592,40 @@ void LLSelectMgr::removeAll()
 //-----------------------------------------------------------------------------
 void LLSelectMgr::promoteSelectionToRoot()
 {
-	std::set<LLViewerObject*> selection_set;
+    std::set<LLViewerObject*> selection_set;
 
-	BOOL selection_changed = FALSE;
+    BOOL selection_changed = FALSE;
+
+    for (LLObjectSelection::iterator iter = getSelection()->begin();
+         iter != getSelection()->end(); )
+    {
+        LLObjectSelection::iterator curiter = iter++;
+        LLSelectNode* nodep = *curiter;
+        LLViewerObject* object = nodep->getObject();
 
-	for (LLObjectSelection::iterator iter = getSelection()->begin();
-		 iter != getSelection()->end(); )
-	{
-		LLObjectSelection::iterator curiter = iter++;
-		LLSelectNode* nodep = *curiter;
-		LLViewerObject* object = nodep->getObject();
+        if (nodep->mIndividualSelection)
+        {
+            selection_changed = TRUE;
+        }
 
-		if (nodep->mIndividualSelection)
-		{
-			selection_changed = TRUE;
-		}
+        LLViewerObject* parentp = object;
+        while(parentp->getParent() && !(parentp->isRootEdit()))
+        {
+            parentp = (LLViewerObject*)parentp->getParent();
+        }
 
-		LLViewerObject* parentp = object;
-		while(parentp->getParent() && !(parentp->isRootEdit()))
-		{
-			parentp = (LLViewerObject*)parentp->getParent();
-		}
-	
-		selection_set.insert(parentp);
-	}
+        selection_set.insert(parentp);
+    }
 
-	if (selection_changed)
-	{
-		deselectAll();
+    if (selection_changed)
+    {
+        deselectAll();
 
-		for (LLViewerObject* object : selection_set)
-		{
-			selectObjectAndFamily(object);
-		}
-	}
+        for (LLViewerObject* object : selection_set)
+        {
+            selectObjectAndFamily(object);
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1633,22 +1633,22 @@ void LLSelectMgr::promoteSelectionToRoot()
 //-----------------------------------------------------------------------------
 void LLSelectMgr::demoteSelectionToIndividuals()
 {
-	std::vector<LLViewerObject*> objects;
+    std::vector<LLViewerObject*> objects;
 
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		object->addThisAndNonJointChildren(objects);
-	}
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        object->addThisAndNonJointChildren(objects);
+    }
 
-	if (!objects.empty())
-	{
-		deselectAll();
-		for (LLViewerObject* objectp : objects)
-		{
-			selectObjectOnly(objectp);
-		}
-	}
+    if (!objects.empty())
+    {
+        deselectAll();
+        for (LLViewerObject* objectp : objects)
+        {
+            selectObjectOnly(objectp);
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1656,54 +1656,54 @@ void LLSelectMgr::demoteSelectionToIndividuals()
 //-----------------------------------------------------------------------------
 void LLSelectMgr::dump()
 {
-	LL_INFOS() << "Selection Manager: " << mSelectedObjects->getNumNodes() << " items" << LL_ENDL;
+    LL_INFOS() << "Selection Manager: " << mSelectedObjects->getNumNodes() << " items" << LL_ENDL;
 
-	LL_INFOS() << "TE mode " << mTEMode << LL_ENDL;
+    LL_INFOS() << "TE mode " << mTEMode << LL_ENDL;
 
-	S32 count = 0;
-	for (LLObjectSelection::iterator iter = getSelection()->begin();
-		 iter != getSelection()->end(); iter++ )
-	{
-		LLViewerObject* objectp = (*iter)->getObject();
-		LL_INFOS() << "Object " << count << " type " << LLPrimitive::pCodeToString(objectp->getPCode()) << LL_ENDL;
+    S32 count = 0;
+    for (LLObjectSelection::iterator iter = getSelection()->begin();
+         iter != getSelection()->end(); iter++ )
+    {
+        LLViewerObject* objectp = (*iter)->getObject();
+        LL_INFOS() << "Object " << count << " type " << LLPrimitive::pCodeToString(objectp->getPCode()) << LL_ENDL;
 // [SL:KB] - Patch: World-Derender | Checked: 2014-08-10 (Catznip-3.7)
-		LL_INFOS() << "  isRoot " << objectp->isRoot() << LL_ENDL;
-		LL_INFOS() << "  idLocal " << objectp->getLocalID() << LL_ENDL;
-		LL_INFOS() << "  idGlobal " << objectp->getID() << LL_ENDL;
+        LL_INFOS() << "  isRoot " << objectp->isRoot() << LL_ENDL;
+        LL_INFOS() << "  idLocal " << objectp->getLocalID() << LL_ENDL;
+        LL_INFOS() << "  idGlobal " << objectp->getID() << LL_ENDL;
 // [/SL:KB]
-		LL_INFOS() << "  hasLSL " << objectp->flagScripted() << LL_ENDL;
-		LL_INFOS() << "  hasTouch " << objectp->flagHandleTouch() << LL_ENDL;
-		LL_INFOS() << "  hasMoney " << objectp->flagTakesMoney() << LL_ENDL;
-		LL_INFOS() << "  getposition " << objectp->getPosition() << LL_ENDL;
-		LL_INFOS() << "  getpositionAgent " << objectp->getPositionAgent() << LL_ENDL;
-		LL_INFOS() << "  getpositionRegion " << objectp->getPositionRegion() << LL_ENDL;
-		LL_INFOS() << "  getpositionGlobal " << objectp->getPositionGlobal() << LL_ENDL;
-		LLDrawable* drawablep = objectp->mDrawable;
-		LL_INFOS() << "  " << (drawablep&& drawablep->isVisible() ? "visible" : "invisible") << LL_ENDL;
-		LL_INFOS() << "  " << (drawablep&& drawablep->isState(LLDrawable::FORCE_INVISIBLE) ? "force_invisible" : "") << LL_ENDL;
-		count++;
-	}
-
-	// Face iterator
-	for (LLObjectSelection::iterator iter = getSelection()->begin();
-		 iter != getSelection()->end(); iter++ )
-	{
-		LLSelectNode* node = *iter;
-		LLViewerObject* objectp = node->getObject();
-		if (!objectp)
-			continue;
-		for (S32 te = 0; te < objectp->getNumTEs(); ++te )
-		{
-			if (node->isTESelected(te))
-			{
-				LL_INFOS() << "Object " << objectp << " te " << te << LL_ENDL;
-			}
-		}
-	}
-
-	LL_INFOS() << mHighlightedObjects->getNumNodes() << " objects currently highlighted." << LL_ENDL;
-
-	LL_INFOS() << "Center global " << mSelectionCenterGlobal << LL_ENDL;
+        LL_INFOS() << "  hasLSL " << objectp->flagScripted() << LL_ENDL;
+        LL_INFOS() << "  hasTouch " << objectp->flagHandleTouch() << LL_ENDL;
+        LL_INFOS() << "  hasMoney " << objectp->flagTakesMoney() << LL_ENDL;
+        LL_INFOS() << "  getposition " << objectp->getPosition() << LL_ENDL;
+        LL_INFOS() << "  getpositionAgent " << objectp->getPositionAgent() << LL_ENDL;
+        LL_INFOS() << "  getpositionRegion " << objectp->getPositionRegion() << LL_ENDL;
+        LL_INFOS() << "  getpositionGlobal " << objectp->getPositionGlobal() << LL_ENDL;
+        LLDrawable* drawablep = objectp->mDrawable;
+        LL_INFOS() << "  " << (drawablep&& drawablep->isVisible() ? "visible" : "invisible") << LL_ENDL;
+        LL_INFOS() << "  " << (drawablep&& drawablep->isState(LLDrawable::FORCE_INVISIBLE) ? "force_invisible" : "") << LL_ENDL;
+        count++;
+    }
+
+    // Face iterator
+    for (LLObjectSelection::iterator iter = getSelection()->begin();
+         iter != getSelection()->end(); iter++ )
+    {
+        LLSelectNode* node = *iter;
+        LLViewerObject* objectp = node->getObject();
+        if (!objectp)
+            continue;
+        for (S32 te = 0; te < objectp->getNumTEs(); ++te )
+        {
+            if (node->isTESelected(te))
+            {
+                LL_INFOS() << "Object " << objectp << " te " << te << LL_ENDL;
+            }
+        }
+    }
+
+    LL_INFOS() << mHighlightedObjects->getNumNodes() << " objects currently highlighted." << LL_ENDL;
+
+    LL_INFOS() << "Center global " << mSelectionCenterGlobal << LL_ENDL;
 }
 
 //-----------------------------------------------------------------------------
@@ -1711,7 +1711,7 @@ void LLSelectMgr::dump()
 //-----------------------------------------------------------------------------
 void LLSelectMgr::cleanup()
 {
-	mSilhouetteImagep = NULL;
+    mSilhouetteImagep = NULL;
 }
 
 
@@ -1721,53 +1721,53 @@ void LLSelectMgr::cleanup()
 
 struct LLSelectMgrSendFunctor : public LLSelectedObjectFunctor
 {
-	virtual bool apply(LLViewerObject* object)
-	{
-		if (object->permModify())
-		{
-			object->sendTEUpdate();
-		}
-		return true;
-	}
+    virtual bool apply(LLViewerObject* object)
+    {
+        if (object->permModify())
+        {
+            object->sendTEUpdate();
+        }
+        return true;
+    }
 };
 
 void LLObjectSelection::applyNoCopyTextureToTEs(LLViewerInventoryItem* item)
 {
-	if (!item)
-	{
-		return;
-	}
-	LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(item->getAssetUUID());
-
-	for (LLSelectNode* node : begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if (!object)
-		{
-			continue;
-		}
-
-		S32 num_tes = llmin((S32)object->getNumTEs(), (S32)object->getNumFaces());
-		bool texture_copied = false;
+    if (!item)
+    {
+        return;
+    }
+    LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(item->getAssetUUID());
+
+    for (LLSelectNode* node : begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if (!object)
+        {
+            continue;
+        }
+
+        S32 num_tes = llmin((S32)object->getNumTEs(), (S32)object->getNumFaces());
+        bool texture_copied = false;
         bool updated = false;
-		for (S32 te = 0; te < num_tes; ++te)
-		{
-			if (node->isTESelected(te))
-			{
-				//(no-copy) textures must be moved to the object's inventory only once
-				// without making any copies
-				if (!texture_copied)
-				{
-					LLToolDragAndDrop::handleDropMaterialProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null);
-					texture_copied = true;
-				}
-
-				// apply texture for the selected faces
-				add(LLStatViewer::EDIT_TEXTURE, 1);
-				object->setTEImage(te, image);
+        for (S32 te = 0; te < num_tes; ++te)
+        {
+            if (node->isTESelected(te))
+            {
+                //(no-copy) textures must be moved to the object's inventory only once
+                // without making any copies
+                if (!texture_copied)
+                {
+                    LLToolDragAndDrop::handleDropMaterialProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null);
+                    texture_copied = true;
+                }
+
+                // apply texture for the selected faces
+                add(LLStatViewer::EDIT_TEXTURE, 1);
+                object->setTEImage(te, image);
                 updated = true;
-			}
-		}
+            }
+        }
 
         if (updated) // not nessesary? sendTEUpdate update supposed to be done by sendfunc
         {
@@ -1776,7 +1776,7 @@ void LLObjectSelection::applyNoCopyTextureToTEs(LLViewerInventoryItem* item)
             // send the update to the simulator
             object->sendTEUpdate();
         }
-	}
+    }
 }
 
 bool LLObjectSelection::applyRestrictedPbrMaterialToTEs(LLViewerInventoryItem* item)
@@ -1818,7 +1818,7 @@ bool LLObjectSelection::applyRestrictedPbrMaterialToTEs(LLViewerInventoryItem* i
                 if (!material_copied)
                 {
                     // Applying the material is not possible for this object given the current inventory
-					material_copied_all_faces = false;
+                    material_copied_all_faces = false;
                     break;
                 }
 
@@ -1842,30 +1842,30 @@ bool LLObjectSelection::applyRestrictedPbrMaterialToTEs(LLViewerInventoryItem* i
 // *TODO: re-arch texture applying out of lltooldraganddrop
 bool LLSelectMgr::selectionSetImage(const LLUUID& imageid)
 {
-	// First for (no copy) textures and multiple object selection
-	LLViewerInventoryItem* item = gInventory.getItem(imageid);
-	if(item 
-		&& !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID())
-		&& (mSelectedObjects->getNumNodes() > 1) )
-	{
+    // First for (no copy) textures and multiple object selection
+    LLViewerInventoryItem* item = gInventory.getItem(imageid);
+    if(item
+        && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID())
+        && (mSelectedObjects->getNumNodes() > 1) )
+    {
          LL_DEBUGS() << "Attempted to apply no-copy texture " << imageid
              << " to multiple objects" << LL_ENDL;
 
         LLNotificationsUtil::add("FailedToApplyTextureNoCopyToMultiple");
         return false;
-	}
-
-	struct f : public LLSelectedTEFunctor
-	{
-		LLViewerInventoryItem* mItem;
-		LLUUID mImageID;
-		f(LLViewerInventoryItem* item, const LLUUID& id) : mItem(item), mImageID(id) {}
-		bool apply(LLViewerObject* objectp, S32 te)
-		{
-		    if(!objectp || !objectp->permModify())
-		    {
-		        return false;
-		    }
+    }
+
+    struct f : public LLSelectedTEFunctor
+    {
+        LLViewerInventoryItem* mItem;
+        LLUUID mImageID;
+        f(LLViewerInventoryItem* item, const LLUUID& id) : mItem(item), mImageID(id) {}
+        bool apply(LLViewerObject* objectp, S32 te)
+        {
+            if(!objectp || !objectp->permModify())
+            {
+                return false;
+            }
 
             // Might be better to run willObjectAcceptInventory
             if (mItem && objectp->isAttachment())
@@ -1880,61 +1880,61 @@ bool LLSelectMgr::selectionSetImage(const LLUUID& imageid)
                 }
             }
 
-		    if (mItem)
-			{
+            if (mItem)
+            {
                 LLToolDragAndDrop::dropTextureOneFace(objectp,
                                                       te,
                                                       mItem,
                                                       LLToolDragAndDrop::SOURCE_AGENT,
                                                       LLUUID::null,
                                                       false);
-			}
-			else // not an inventory item
-			{
-				// Texture picker defaults aren't inventory items
-				// * Don't need to worry about permissions for them
-				// * Can just apply the texture and be done with it.
-				objectp->setTEImage(te, LLViewerTextureManager::getFetchedTexture(mImageID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE));
-			}
-
-			return true;
-		}
-	};
-
-	if (item && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()))
-	{
-		getSelection()->applyNoCopyTextureToTEs(item);
-	}
-	else
-	{
-		f setfunc(item, imageid);
-		getSelection()->applyToTEs(&setfunc);
-	}
-
-
-	struct g : public LLSelectedObjectFunctor
-	{
-		LLViewerInventoryItem* mItem;
-		g(LLViewerInventoryItem* item) : mItem(item) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (!mItem)
-			{
-				object->sendTEUpdate();
-				if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
-				{
-					// 1 particle effect per object				
-					LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
-					effectp->setSourceObject(gAgentAvatarp);
-					effectp->setTargetObject(object);
-					effectp->setDuration(LL_HUD_DUR_SHORT);
-					effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-				}
-			}
-			return true;
-		}
-	} sendfunc(item);
-	getSelection()->applyToObjects(&sendfunc);
+            }
+            else // not an inventory item
+            {
+                // Texture picker defaults aren't inventory items
+                // * Don't need to worry about permissions for them
+                // * Can just apply the texture and be done with it.
+                objectp->setTEImage(te, LLViewerTextureManager::getFetchedTexture(mImageID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE));
+            }
+
+            return true;
+        }
+    };
+
+    if (item && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()))
+    {
+        getSelection()->applyNoCopyTextureToTEs(item);
+    }
+    else
+    {
+        f setfunc(item, imageid);
+        getSelection()->applyToTEs(&setfunc);
+    }
+
+
+    struct g : public LLSelectedObjectFunctor
+    {
+        LLViewerInventoryItem* mItem;
+        g(LLViewerInventoryItem* item) : mItem(item) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (!mItem)
+            {
+                object->sendTEUpdate();
+                if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
+                {
+                    // 1 particle effect per object
+                    LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
+                    effectp->setSourceObject(gAgentAvatarp);
+                    effectp->setTargetObject(object);
+                    effectp->setDuration(LL_HUD_DUR_SHORT);
+                    effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+                }
+            }
+            return true;
+        }
+    } sendfunc(item);
+    getSelection()->applyToObjects(&sendfunc);
 
     return true;
 }
@@ -2038,7 +2038,7 @@ bool LLSelectMgr::selectionSetGLTFMaterial(const LLUUID& mat_id)
 
             if (!mItem)
             {
-                // 1 particle effect per object				
+                // 1 particle effect per object
                 LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
                 effectp->setSourceObject(gAgentAvatarp);
                 effectp->setTargetObject(object);
@@ -2063,23 +2063,23 @@ bool LLSelectMgr::selectionSetGLTFMaterial(const LLUUID& mat_id)
 //-----------------------------------------------------------------------------
 void LLSelectMgr::selectionSetColor(const LLColor4 &color)
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		LLColor4 mColor;
-		f(const LLColor4& c) : mColor(c) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				object->setTEColor(te, mColor);
-			}
-			return true;
-		}
-	} setfunc(color);
-	getSelection()->applyToTEs(&setfunc);
-	
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedTEFunctor
+    {
+        LLColor4 mColor;
+        f(const LLColor4& c) : mColor(c) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                object->setTEColor(te, mColor);
+            }
+            return true;
+        }
+    } setfunc(color);
+    getSelection()->applyToTEs(&setfunc);
+
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 //-----------------------------------------------------------------------------
@@ -2087,26 +2087,26 @@ void LLSelectMgr::selectionSetColor(const LLColor4 &color)
 //-----------------------------------------------------------------------------
 void LLSelectMgr::selectionSetColorOnly(const LLColor4 &color)
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		LLColor4 mColor;
-		f(const LLColor4& c) : mColor(c) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				LLColor4 prev_color = object->getTE(te)->getColor();
-				mColor.mV[VALPHA] = prev_color.mV[VALPHA];
-				// update viewer side color in anticipation of update from simulator
-				object->setTEColor(te, mColor);
-			}
-			return true;
-		}
-	} setfunc(color);
-	getSelection()->applyToTEs(&setfunc);
-	
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedTEFunctor
+    {
+        LLColor4 mColor;
+        f(const LLColor4& c) : mColor(c) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                LLColor4 prev_color = object->getTE(te)->getColor();
+                mColor.mV[VALPHA] = prev_color.mV[VALPHA];
+                // update viewer side color in anticipation of update from simulator
+                object->setTEColor(te, mColor);
+            }
+            return true;
+        }
+    } setfunc(color);
+    getSelection()->applyToTEs(&setfunc);
+
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 //-----------------------------------------------------------------------------
@@ -2114,125 +2114,125 @@ void LLSelectMgr::selectionSetColorOnly(const LLColor4 &color)
 //-----------------------------------------------------------------------------
 void LLSelectMgr::selectionSetAlphaOnly(const F32 alpha)
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		F32 mAlpha;
-		f(const F32& a) : mAlpha(a) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				LLColor4 prev_color = object->getTE(te)->getColor();
-				prev_color.mV[VALPHA] = mAlpha;
-				// update viewer side color in anticipation of update from simulator
-				object->setTEColor(te, prev_color);
-			}
-			return true;
-		}
-	} setfunc(alpha);
-	getSelection()->applyToTEs(&setfunc);
-	
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
-}
-
-void LLSelectMgr::selectionRevertColors()
-{
-	struct f : public LLSelectedTEFunctor
-	{
-		LLObjectSelectionHandle mSelectedObjects;
-		f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				LLSelectNode* nodep = mSelectedObjects->findNode(object);
-				if (nodep && te < (S32)nodep->mSavedColors.size())
-				{
-					LLColor4 color = nodep->mSavedColors[te];
-					// update viewer side color in anticipation of update from simulator
-					object->setTEColor(te, color);
-				}
-			}
-			return true;
-		}
-	} setfunc(mSelectedObjects);
-	getSelection()->applyToTEs(&setfunc);
-	
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
-}
+    struct f : public LLSelectedTEFunctor
+    {
+        F32 mAlpha;
+        f(const F32& a) : mAlpha(a) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                LLColor4 prev_color = object->getTE(te)->getColor();
+                prev_color.mV[VALPHA] = mAlpha;
+                // update viewer side color in anticipation of update from simulator
+                object->setTEColor(te, prev_color);
+            }
+            return true;
+        }
+    } setfunc(alpha);
+    getSelection()->applyToTEs(&setfunc);
+
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
+}
+
+void LLSelectMgr::selectionRevertColors()
+{
+    struct f : public LLSelectedTEFunctor
+    {
+        LLObjectSelectionHandle mSelectedObjects;
+        f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                LLSelectNode* nodep = mSelectedObjects->findNode(object);
+                if (nodep && te < (S32)nodep->mSavedColors.size())
+                {
+                    LLColor4 color = nodep->mSavedColors[te];
+                    // update viewer side color in anticipation of update from simulator
+                    object->setTEColor(te, color);
+                }
+            }
+            return true;
+        }
+    } setfunc(mSelectedObjects);
+    getSelection()->applyToTEs(&setfunc);
+
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
+}
 
 void LLSelectMgr::selectionRevertShinyColors()
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		LLObjectSelectionHandle mSelectedObjects;
-		f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				LLSelectNode* nodep = mSelectedObjects->findNode(object);
-				if (nodep && te < (S32)nodep->mSavedShinyColors.size())
-				{
-					LLColor4 color = nodep->mSavedShinyColors[te];
-					// update viewer side color in anticipation of update from simulator
-					LLMaterialPtr old_mat = object->getTE(te)->getMaterialParams();
-					if (!old_mat.isNull())
-					{
-						LLMaterialPtr new_mat = gFloaterTools->getPanelFace()->createDefaultMaterial(old_mat);
-						new_mat->setSpecularLightColor(color);
-						object->getTE(te)->setMaterialParams(new_mat);
-						LLMaterialMgr::getInstance()->put(object->getID(), te, *new_mat);
-					}
-				}
-			}
-			return true;
-		}
-	} setfunc(mSelectedObjects);
-	getSelection()->applyToTEs(&setfunc);
-
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedTEFunctor
+    {
+        LLObjectSelectionHandle mSelectedObjects;
+        f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                LLSelectNode* nodep = mSelectedObjects->findNode(object);
+                if (nodep && te < (S32)nodep->mSavedShinyColors.size())
+                {
+                    LLColor4 color = nodep->mSavedShinyColors[te];
+                    // update viewer side color in anticipation of update from simulator
+                    LLMaterialPtr old_mat = object->getTE(te)->getMaterialParams();
+                    if (!old_mat.isNull())
+                    {
+                        LLMaterialPtr new_mat = gFloaterTools->getPanelFace()->createDefaultMaterial(old_mat);
+                        new_mat->setSpecularLightColor(color);
+                        object->getTE(te)->setMaterialParams(new_mat);
+                        LLMaterialMgr::getInstance()->put(object->getID(), te, *new_mat);
+                    }
+                }
+            }
+            return true;
+        }
+    } setfunc(mSelectedObjects);
+    getSelection()->applyToTEs(&setfunc);
+
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 BOOL LLSelectMgr::selectionRevertTextures()
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		LLObjectSelectionHandle mSelectedObjects;
-		f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				LLSelectNode* nodep = mSelectedObjects->findNode(object);
-				if (nodep && te < (S32)nodep->mSavedTextures.size())
-				{
-					LLUUID id = nodep->mSavedTextures[te];
-					// update textures on viewer side
-					if (id.isNull())
-					{
-						// this was probably a no-copy texture, leave image as-is
-						return FALSE;
-					}
-					else
-					{
-						object->setTEImage(te, LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE));
-
-					}
-				}
-			}
-			return true;
-		}
-	} setfunc(mSelectedObjects);
-	BOOL revert_successful = getSelection()->applyToTEs(&setfunc);
-	
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
-
-	return revert_successful;
+    struct f : public LLSelectedTEFunctor
+    {
+        LLObjectSelectionHandle mSelectedObjects;
+        f(LLObjectSelectionHandle sel) : mSelectedObjects(sel) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                LLSelectNode* nodep = mSelectedObjects->findNode(object);
+                if (nodep && te < (S32)nodep->mSavedTextures.size())
+                {
+                    LLUUID id = nodep->mSavedTextures[te];
+                    // update textures on viewer side
+                    if (id.isNull())
+                    {
+                        // this was probably a no-copy texture, leave image as-is
+                        return FALSE;
+                    }
+                    else
+                    {
+                        object->setTEImage(te, LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE));
+
+                    }
+                }
+            }
+            return true;
+        }
+    } setfunc(mSelectedObjects);
+    BOOL revert_successful = getSelection()->applyToTEs(&setfunc);
+
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
+
+    return revert_successful;
 }
 
 void LLSelectMgr::selectionRevertGLTFMaterials()
@@ -2263,7 +2263,7 @@ void LLSelectMgr::selectionRevertGLTFMaterials()
                 {
                     // Restore overrides and base material
                     LLGLTFMaterialList::queueApply(objectp, te, asset_id, nodep->mSavedGLTFOverrideMaterials[te]);
-                } 
+                }
                 else
                 {
                     //blank override out
@@ -2279,23 +2279,23 @@ void LLSelectMgr::selectionRevertGLTFMaterials()
 
 void LLSelectMgr::selectionSetBumpmap(U8 bumpmap, const LLUUID &image_id)
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		U8 mBump;
-		f(const U8& b) : mBump(b) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				// update viewer side color in anticipation of update from simulator
-				object->setTEBumpmap(te, mBump);
-			}
-			return true;
-		}
-	} setfunc(bumpmap);
+    struct f : public LLSelectedTEFunctor
+    {
+        U8 mBump;
+        f(const U8& b) : mBump(b) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                // update viewer side color in anticipation of update from simulator
+                object->setTEBumpmap(te, mBump);
+            }
+            return true;
+        }
+    } setfunc(bumpmap);
 
     LLViewerInventoryItem* item = gInventory.getItem(image_id);
-    if(item 
+    if(item
         && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID())
         && (mSelectedObjects->getNumNodes() > 1) )
     {
@@ -2321,53 +2321,53 @@ void LLSelectMgr::selectionSetBumpmap(U8 bumpmap, const LLUUID &image_id)
         LLToolDragAndDrop::handleDropMaterialProtections(object, item, LLToolDragAndDrop::SOURCE_AGENT, LLUUID::null);
     }
     getSelection()->applyToTEs(&setfunc);
-	
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
+
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 void LLSelectMgr::selectionSetTexGen(U8 texgen)
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		U8 mTexgen;
-		f(const U8& t) : mTexgen(t) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				// update viewer side color in anticipation of update from simulator
-				object->setTETexGen(te, mTexgen);
-			}
-			return true;
-		}
-	} setfunc(texgen);
-	getSelection()->applyToTEs(&setfunc);
+    struct f : public LLSelectedTEFunctor
+    {
+        U8 mTexgen;
+        f(const U8& t) : mTexgen(t) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                // update viewer side color in anticipation of update from simulator
+                object->setTETexGen(te, mTexgen);
+            }
+            return true;
+        }
+    } setfunc(texgen);
+    getSelection()->applyToTEs(&setfunc);
 
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 
 void LLSelectMgr::selectionSetShiny(U8 shiny, const LLUUID &image_id)
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		U8 mShiny;
-		f(const U8& t) : mShiny(t) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				// update viewer side color in anticipation of update from simulator
-				object->setTEShiny(te, mShiny);
-			}
-			return true;
-		}
-	} setfunc(shiny);
+    struct f : public LLSelectedTEFunctor
+    {
+        U8 mShiny;
+        f(const U8& t) : mShiny(t) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                // update viewer side color in anticipation of update from simulator
+                object->setTEShiny(te, mShiny);
+            }
+            return true;
+        }
+    } setfunc(shiny);
 
     LLViewerInventoryItem* item = gInventory.getItem(image_id);
-    if(item 
+    if(item
         && !item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID())
         && (mSelectedObjects->getNumNodes() > 1) )
     {
@@ -2394,235 +2394,235 @@ void LLSelectMgr::selectionSetShiny(U8 shiny, const LLUUID &image_id)
     }
     getSelection()->applyToTEs(&setfunc);
 
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 void LLSelectMgr::selectionSetFullbright(U8 fullbright)
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		U8 mFullbright;
-		f(const U8& t) : mFullbright(t) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				// update viewer side color in anticipation of update from simulator
-				object->setTEFullbright(te, mFullbright);
-			}
-			return true;
-		}
-	} setfunc(fullbright);
-	getSelection()->applyToTEs(&setfunc);
-
-	struct g : public LLSelectedObjectFunctor
-	{
-		U8 mFullbright;
-		g(const U8& t) : mFullbright(t) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->sendTEUpdate();
-				if (mFullbright)
-				{
-					U8 material = object->getMaterial();
-					U8 mcode = material & LL_MCODE_MASK;
-					if (mcode == LL_MCODE_LIGHT)
-					{
-						mcode = LL_MCODE_GLASS;
-						material = (material & ~LL_MCODE_MASK) | mcode;
-						object->setMaterial(material);
-						object->sendMaterialUpdate();
-					}
-				}
-			}
-			return true;
-		}
-	} sendfunc(fullbright);
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedTEFunctor
+    {
+        U8 mFullbright;
+        f(const U8& t) : mFullbright(t) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                // update viewer side color in anticipation of update from simulator
+                object->setTEFullbright(te, mFullbright);
+            }
+            return true;
+        }
+    } setfunc(fullbright);
+    getSelection()->applyToTEs(&setfunc);
+
+    struct g : public LLSelectedObjectFunctor
+    {
+        U8 mFullbright;
+        g(const U8& t) : mFullbright(t) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->sendTEUpdate();
+                if (mFullbright)
+                {
+                    U8 material = object->getMaterial();
+                    U8 mcode = material & LL_MCODE_MASK;
+                    if (mcode == LL_MCODE_LIGHT)
+                    {
+                        mcode = LL_MCODE_GLASS;
+                        material = (material & ~LL_MCODE_MASK) | mcode;
+                        object->setMaterial(material);
+                        object->sendMaterialUpdate();
+                    }
+                }
+            }
+            return true;
+        }
+    } sendfunc(fullbright);
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 // This function expects media_data to be a map containing relevant
 // media data name/value pairs (e.g. home_url, etc.)
 void LLSelectMgr::selectionSetMedia(U8 media_type, const LLSD &media_data)
-{	
-	struct f : public LLSelectedTEFunctor
-	{
-		U8 mMediaFlags;
-		const LLSD &mMediaData;
-		f(const U8& t, const LLSD& d) : mMediaFlags(t), mMediaData(d) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			if (object->permModify())
-			{
-				// If we are adding media, then check the current state of the
-				// media data on this face.  
-				//  - If it does not have media, AND we are NOT setting the HOME URL, then do NOT add media to this
-				// face.
-				//  - If it does not have media, and we ARE setting the HOME URL, add media to this face.
-				//  - If it does already have media, add/update media to/on this face
-				// If we are removing media, just do it (ignore the passed-in LLSD).
-				if (mMediaFlags & LLTextureEntry::MF_HAS_MEDIA)
-				{
-					llassert(mMediaData.isMap());
-					const LLTextureEntry *texture_entry = object->getTE(te);
-					if (!mMediaData.isMap() ||
-						((NULL != texture_entry) && !texture_entry->hasMedia() && !mMediaData.has(LLMediaEntry::HOME_URL_KEY)))
-					{
-						// skip adding/updating media
-					}
-					else {
-						// Add/update media
-						object->setTEMediaFlags(te, mMediaFlags);
-						LLVOVolume *vo = object->asVolume();
-						llassert(NULL != vo);
-						if (NULL != vo) 
-						{
-							vo->syncMediaData(te, mMediaData, true/*merge*/, true/*ignore_agent*/);
-						}
-					}
-				}
-				else
-				{
-					// delete media (or just set the flags)
-					object->setTEMediaFlags(te, mMediaFlags);
-				}
-			}
-			return true;
-		}
-	} setfunc(media_type, media_data);
-	getSelection()->applyToTEs(&setfunc);
-	
-	struct f2 : public LLSelectedObjectFunctor
-	{
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->sendTEUpdate();
-				LLVOVolume *vo = object->asVolume();
-				llassert(NULL != vo);
-				// It's okay to skip this object if hasMedia() is false...
-				// the sendTEUpdate() above would remove all media data if it were
-				// there.
+{
+    struct f : public LLSelectedTEFunctor
+    {
+        U8 mMediaFlags;
+        const LLSD &mMediaData;
+        f(const U8& t, const LLSD& d) : mMediaFlags(t), mMediaData(d) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+            if (object->permModify())
+            {
+                // If we are adding media, then check the current state of the
+                // media data on this face.
+                //  - If it does not have media, AND we are NOT setting the HOME URL, then do NOT add media to this
+                // face.
+                //  - If it does not have media, and we ARE setting the HOME URL, add media to this face.
+                //  - If it does already have media, add/update media to/on this face
+                // If we are removing media, just do it (ignore the passed-in LLSD).
+                if (mMediaFlags & LLTextureEntry::MF_HAS_MEDIA)
+                {
+                    llassert(mMediaData.isMap());
+                    const LLTextureEntry *texture_entry = object->getTE(te);
+                    if (!mMediaData.isMap() ||
+                        ((NULL != texture_entry) && !texture_entry->hasMedia() && !mMediaData.has(LLMediaEntry::HOME_URL_KEY)))
+                    {
+                        // skip adding/updating media
+                    }
+                    else {
+                        // Add/update media
+                        object->setTEMediaFlags(te, mMediaFlags);
+                        LLVOVolume *vo = object->asVolume();
+                        llassert(NULL != vo);
+                        if (NULL != vo)
+                        {
+                            vo->syncMediaData(te, mMediaData, true/*merge*/, true/*ignore_agent*/);
+                        }
+                    }
+                }
+                else
+                {
+                    // delete media (or just set the flags)
+                    object->setTEMediaFlags(te, mMediaFlags);
+                }
+            }
+            return true;
+        }
+    } setfunc(media_type, media_data);
+    getSelection()->applyToTEs(&setfunc);
+
+    struct f2 : public LLSelectedObjectFunctor
+    {
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->sendTEUpdate();
+                LLVOVolume *vo = object->asVolume();
+                llassert(NULL != vo);
+                // It's okay to skip this object if hasMedia() is false...
+                // the sendTEUpdate() above would remove all media data if it were
+                // there.
                 if (NULL != vo && vo->hasMedia())
                 {
                     // Send updated media data FOR THE ENTIRE OBJECT
                     vo->sendMediaDataUpdate();
                 }
-			}
-			return true;
-		}
-	} func2;
-	mSelectedObjects->applyToObjects( &func2 );
+            }
+            return true;
+        }
+    } func2;
+    mSelectedObjects->applyToObjects( &func2 );
 }
 
 void LLSelectMgr::selectionSetGlow(F32 glow)
 {
-	struct f1 : public LLSelectedTEFunctor
-	{
-		F32 mGlow;
-		f1(F32 glow) : mGlow(glow) {};
-		bool apply(LLViewerObject* object, S32 face)
-		{
-			if (object->permModify())
-			{
-				// update viewer side color in anticipation of update from simulator
-				object->setTEGlow(face, mGlow);
-			}
-			return true;
-		}
-	} func1(glow);
-	mSelectedObjects->applyToTEs( &func1 );
-
-	struct f2 : public LLSelectedObjectFunctor
-	{
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->sendTEUpdate();
-			}
-			return true;
-		}
-	} func2;
-	mSelectedObjects->applyToObjects( &func2 );
+    struct f1 : public LLSelectedTEFunctor
+    {
+        F32 mGlow;
+        f1(F32 glow) : mGlow(glow) {};
+        bool apply(LLViewerObject* object, S32 face)
+        {
+            if (object->permModify())
+            {
+                // update viewer side color in anticipation of update from simulator
+                object->setTEGlow(face, mGlow);
+            }
+            return true;
+        }
+    } func1(glow);
+    mSelectedObjects->applyToTEs( &func1 );
+
+    struct f2 : public LLSelectedObjectFunctor
+    {
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->sendTEUpdate();
+            }
+            return true;
+        }
+    } func2;
+    mSelectedObjects->applyToObjects( &func2 );
 }
 
 void LLSelectMgr::selectionSetMaterialParams(LLSelectedTEMaterialFunctor* material_func, int te)
 {
-	struct f1 : public LLSelectedTEFunctor
-	{
-		LLMaterialPtr mMaterial;
-		f1(LLSelectedTEMaterialFunctor* material_func, int te) : _material_func(material_func), _specific_te(te) {}
+    struct f1 : public LLSelectedTEFunctor
+    {
+        LLMaterialPtr mMaterial;
+        f1(LLSelectedTEMaterialFunctor* material_func, int te) : _material_func(material_func), _specific_te(te) {}
 
-		bool apply(LLViewerObject* object, S32 te)
-		{
+        bool apply(LLViewerObject* object, S32 te)
+        {
             if (_specific_te == -1 || (te == _specific_te))
             {
-			    if (object && object->permModify() && _material_func)
-			    {
-				    LLTextureEntry* tep = object->getTE(te);
-				    if (tep)
-				    {
-					    LLMaterialPtr current_material = tep->getMaterialParams();
-					    _material_func->apply(object, te, tep, current_material);
-				    }
-			    }
+                if (object && object->permModify() && _material_func)
+                {
+                    LLTextureEntry* tep = object->getTE(te);
+                    if (tep)
+                    {
+                        LLMaterialPtr current_material = tep->getMaterialParams();
+                        _material_func->apply(object, te, tep, current_material);
+                    }
+                }
             }
-			return true;
-		}
+            return true;
+        }
 
-		LLSelectedTEMaterialFunctor* _material_func;
+        LLSelectedTEMaterialFunctor* _material_func;
         int _specific_te;
-	} func1(material_func, te);
-	mSelectedObjects->applyToTEs( &func1 );
-
-	struct f2 : public LLSelectedObjectFunctor
-	{
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->sendTEUpdate();
-			}
-			return true;
-		}
-	} func2;
-	mSelectedObjects->applyToObjects( &func2 );
+    } func1(material_func, te);
+    mSelectedObjects->applyToTEs( &func1 );
+
+    struct f2 : public LLSelectedObjectFunctor
+    {
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->sendTEUpdate();
+            }
+            return true;
+        }
+    } func2;
+    mSelectedObjects->applyToObjects( &func2 );
 }
 
 void LLSelectMgr::selectionRemoveMaterial()
 {
-	struct f1 : public LLSelectedTEFunctor
-	{
-		bool apply(LLViewerObject* object, S32 face)
-		{
-			if (object->permModify())
-			{
-			        LL_DEBUGS("Materials") << "Removing material from object " << object->getID() << " face " << face << LL_ENDL;
-				LLMaterialMgr::getInstance()->remove(object->getID(),face);
-				object->setTEMaterialParams(face, NULL);
-			}
-			return true;
-		}
-	} func1;
-	mSelectedObjects->applyToTEs( &func1 );
-
-	struct f2 : public LLSelectedObjectFunctor
-	{
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->sendTEUpdate();
-			}
-			return true;
-		}
-	} func2;
-	mSelectedObjects->applyToObjects( &func2 );
+    struct f1 : public LLSelectedTEFunctor
+    {
+        bool apply(LLViewerObject* object, S32 face)
+        {
+            if (object->permModify())
+            {
+                    LL_DEBUGS("Materials") << "Removing material from object " << object->getID() << " face " << face << LL_ENDL;
+                LLMaterialMgr::getInstance()->remove(object->getID(),face);
+                object->setTEMaterialParams(face, NULL);
+            }
+            return true;
+        }
+    } func1;
+    mSelectedObjects->applyToTEs( &func1 );
+
+    struct f2 : public LLSelectedObjectFunctor
+    {
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->sendTEUpdate();
+            }
+            return true;
+        }
+    } func2;
+    mSelectedObjects->applyToObjects( &func2 );
 }
 
 
@@ -2631,15 +2631,15 @@ void LLSelectMgr::selectionRemoveMaterial()
 //-----------------------------------------------------------------------------
 LLPermissions* LLSelectMgr::findObjectPermissions(const LLViewerObject* object)
 {
-	for (LLSelectNode* nodep : getSelection()->valid_begin_end())
-	{
-		if (nodep->getObject() == object)
-		{
-			return nodep->mPermissions;
-		}
-	}
+    for (LLSelectNode* nodep : getSelection()->valid_begin_end())
+    {
+        if (nodep->getObject() == object)
+        {
+            return nodep->mPermissions;
+        }
+    }
 
-	return NULL;
+    return NULL;
 }
 
 
@@ -2648,115 +2648,115 @@ LLPermissions* LLSelectMgr::findObjectPermissions(const LLViewerObject* object)
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectionGetGlow(F32 *glow)
 {
-	BOOL identical;
-	F32 lglow = 0.f;
-	struct f1 : public LLSelectedTEGetFunctor<F32>
-	{
-		F32 get(LLViewerObject* object, S32 face)
-		{
-			return object->getTE(face)->getGlow();
-		}
-	} func;
-	identical = mSelectedObjects->getSelectedTEValue( &func, lglow );
+    BOOL identical;
+    F32 lglow = 0.f;
+    struct f1 : public LLSelectedTEGetFunctor<F32>
+    {
+        F32 get(LLViewerObject* object, S32 face)
+        {
+            return object->getTE(face)->getGlow();
+        }
+    } func;
+    identical = mSelectedObjects->getSelectedTEValue( &func, lglow );
 
-	*glow = lglow;
-	return identical;
+    *glow = lglow;
+    return identical;
 }
 
 
 void LLSelectMgr::selectionSetPhysicsType(U8 type)
 {
-	struct f : public LLSelectedObjectFunctor
-	{
-		U8 mType;
-		f(const U8& t) : mType(t) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->setPhysicsShapeType(mType);
-				object->updateFlags(TRUE);
-			}
-			return true;
-		}
-	} sendfunc(type);
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedObjectFunctor
+    {
+        U8 mType;
+        f(const U8& t) : mType(t) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->setPhysicsShapeType(mType);
+                object->updateFlags(TRUE);
+            }
+            return true;
+        }
+    } sendfunc(type);
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 void LLSelectMgr::selectionSetFriction(F32 friction)
 {
-	struct f : public LLSelectedObjectFunctor
-	{
-		F32 mFriction;
-		f(const F32& friction) : mFriction(friction) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->setPhysicsFriction(mFriction);
-				object->updateFlags(TRUE);
-			}
-			return true;
-		}
-	} sendfunc(friction);
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedObjectFunctor
+    {
+        F32 mFriction;
+        f(const F32& friction) : mFriction(friction) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->setPhysicsFriction(mFriction);
+                object->updateFlags(TRUE);
+            }
+            return true;
+        }
+    } sendfunc(friction);
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 void LLSelectMgr::selectionSetGravity(F32 gravity )
 {
-	struct f : public LLSelectedObjectFunctor
-	{
-		F32 mGravity;
-		f(const F32& gravity) : mGravity(gravity) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->setPhysicsGravity(mGravity);
-				object->updateFlags(TRUE);
-			}
-			return true;
-		}
-	} sendfunc(gravity);
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedObjectFunctor
+    {
+        F32 mGravity;
+        f(const F32& gravity) : mGravity(gravity) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->setPhysicsGravity(mGravity);
+                object->updateFlags(TRUE);
+            }
+            return true;
+        }
+    } sendfunc(gravity);
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 void LLSelectMgr::selectionSetDensity(F32 density )
 {
-	struct f : public LLSelectedObjectFunctor
-	{
-		F32 mDensity;
-		f(const F32& density ) : mDensity(density) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->setPhysicsDensity(mDensity);
-				object->updateFlags(TRUE);
-			}
-			return true;
-		}
-	} sendfunc(density);
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedObjectFunctor
+    {
+        F32 mDensity;
+        f(const F32& density ) : mDensity(density) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->setPhysicsDensity(mDensity);
+                object->updateFlags(TRUE);
+            }
+            return true;
+        }
+    } sendfunc(density);
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 void LLSelectMgr::selectionSetRestitution(F32 restitution)
 {
-	struct f : public LLSelectedObjectFunctor
-	{
-		F32 mRestitution;
-		f(const F32& restitution ) : mRestitution(restitution) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				object->setPhysicsRestitution(mRestitution);
-				object->updateFlags(TRUE);
-			}
-			return true;
-		}
-	} sendfunc(restitution);
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedObjectFunctor
+    {
+        F32 mRestitution;
+        f(const F32& restitution ) : mRestitution(restitution) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                object->setPhysicsRestitution(mRestitution);
+                object->updateFlags(TRUE);
+            }
+            return true;
+        }
+    } sendfunc(restitution);
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 
@@ -2765,138 +2765,138 @@ void LLSelectMgr::selectionSetRestitution(F32 restitution)
 //-----------------------------------------------------------------------------
 void LLSelectMgr::selectionSetMaterial(U8 material)
 {
-	struct f : public LLSelectedObjectFunctor
-	{
-		U8 mMaterial;
-		f(const U8& t) : mMaterial(t) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				U8 cur_material = object->getMaterial();
-				U8 material = mMaterial | (cur_material & ~LL_MCODE_MASK);
-				object->setMaterial(material);
-				object->sendMaterialUpdate();
-			}
-			return true;
-		}
-	} sendfunc(material);
-	getSelection()->applyToObjects(&sendfunc);
+    struct f : public LLSelectedObjectFunctor
+    {
+        U8 mMaterial;
+        f(const U8& t) : mMaterial(t) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                U8 cur_material = object->getMaterial();
+                U8 material = mMaterial | (cur_material & ~LL_MCODE_MASK);
+                object->setMaterial(material);
+                object->sendMaterialUpdate();
+            }
+            return true;
+        }
+    } sendfunc(material);
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 // TRUE if all selected objects have this PCode
 BOOL LLSelectMgr::selectionAllPCode(LLPCode code)
 {
-	struct f : public LLSelectedObjectFunctor
-	{
-		LLPCode mCode;
-		f(const LLPCode& t) : mCode(t) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->getPCode() != mCode)
-			{
-				return FALSE;
-			}
-			return true;
-		}
-	} func(code);
-	BOOL res = getSelection()->applyToObjects(&func);
-	return res;
+    struct f : public LLSelectedObjectFunctor
+    {
+        LLPCode mCode;
+        f(const LLPCode& t) : mCode(t) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->getPCode() != mCode)
+            {
+                return FALSE;
+            }
+            return true;
+        }
+    } func(code);
+    BOOL res = getSelection()->applyToObjects(&func);
+    return res;
 }
 
 bool LLSelectMgr::selectionGetIncludeInSearch(bool* include_in_search_out)
 {
-	LLViewerObject *object = mSelectedObjects->getFirstRootObject();
-	if (!object) return FALSE;
+    LLViewerObject *object = mSelectedObjects->getFirstRootObject();
+    if (!object) return FALSE;
 
-	bool include_in_search = object->getIncludeInSearch();
+    bool include_in_search = object->getIncludeInSearch();
 
-	bool identical = true;
+    bool identical = true;
 
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
 
-		if ( include_in_search != object->getIncludeInSearch())
-		{
-			identical = false;
-			break;
-		}
-	}
+        if ( include_in_search != object->getIncludeInSearch())
+        {
+            identical = false;
+            break;
+        }
+    }
 
-	*include_in_search_out = include_in_search;
-	return identical;
+    *include_in_search_out = include_in_search;
+    return identical;
 }
 
 void LLSelectMgr::selectionSetIncludeInSearch(bool include_in_search)
 {
-	LLViewerObject* object = NULL;
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		object = node->getObject();
-		object->setIncludeInSearch(include_in_search);
-	}
-	sendListToRegions(
-		"ObjectIncludeInSearch",
-		packAgentAndSessionID,
-		packObjectIncludeInSearch, 
+    LLViewerObject* object = NULL;
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        object = node->getObject();
+        object->setIncludeInSearch(include_in_search);
+    }
+    sendListToRegions(
+        "ObjectIncludeInSearch",
+        packAgentAndSessionID,
+        packObjectIncludeInSearch,
         logNoOp,
-		&include_in_search,
-		SEND_ONLY_ROOTS);
+        &include_in_search,
+        SEND_ONLY_ROOTS);
 }
 
 BOOL LLSelectMgr::selectionGetClickAction(U8 *out_action)
 {
-	LLViewerObject *object = mSelectedObjects->getFirstObject();
-	if (!object)
-	{
-		return FALSE;
-	}
-	
-	U8 action = object->getClickAction();
-	*out_action = action;
-
-	struct f : public LLSelectedObjectFunctor
-	{
-		U8 mAction;
-		f(const U8& t) : mAction(t) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			if ( mAction != object->getClickAction())
-			{
-				return false;
-			}
-			return true;
-		}
-	} func(action);
-	BOOL res = getSelection()->applyToObjects(&func);
-	return res;
-}
-
-void LLSelectMgr::selectionSetClickAction(U8 action)
-{
-	struct f : public LLSelectedObjectFunctor
-	{
-		U8 mAction;
-		f(const U8& t) : mAction(t) {}
-		virtual bool apply(LLViewerObject* object)
-		{
-			object->setClickAction(mAction);
-			return true;
-		}
-	} func(action);
-	getSelection()->applyToObjects(&func);
-
-	sendListToRegions("ObjectClickAction",
-					  packAgentAndSessionID,
-					  packObjectClickAction, 
-                      logNoOp,
-					  &action,
-					  SEND_INDIVIDUALS);
-}
+    LLViewerObject *object = mSelectedObjects->getFirstObject();
+    if (!object)
+    {
+        return FALSE;
+    }
 
+    U8 action = object->getClickAction();
+    *out_action = action;
 
-//-----------------------------------------------------------------------------
+    struct f : public LLSelectedObjectFunctor
+    {
+        U8 mAction;
+        f(const U8& t) : mAction(t) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            if ( mAction != object->getClickAction())
+            {
+                return false;
+            }
+            return true;
+        }
+    } func(action);
+    BOOL res = getSelection()->applyToObjects(&func);
+    return res;
+}
+
+void LLSelectMgr::selectionSetClickAction(U8 action)
+{
+    struct f : public LLSelectedObjectFunctor
+    {
+        U8 mAction;
+        f(const U8& t) : mAction(t) {}
+        virtual bool apply(LLViewerObject* object)
+        {
+            object->setClickAction(mAction);
+            return true;
+        }
+    } func(action);
+    getSelection()->applyToObjects(&func);
+
+    sendListToRegions("ObjectClickAction",
+                      packAgentAndSessionID,
+                      packObjectClickAction,
+                      logNoOp,
+                      &action,
+                      SEND_INDIVIDUALS);
+}
+
+
+//-----------------------------------------------------------------------------
 // godlike requests
 //-----------------------------------------------------------------------------
 
@@ -2904,54 +2904,54 @@ typedef std::pair<const std::string, const std::string> godlike_request_t;
 
 void LLSelectMgr::sendGodlikeRequest(const std::string& request, const std::string& param)
 {
-	// If the agent is neither godlike nor an estate owner, the server
-	// will reject the request.
-	const char* message_type;
-	if (gAgent.isGodlike())
-	{
-		message_type = _PREHASH_GodlikeMessage;
-	}
-	else
-	{
-		message_type = _PREHASH_EstateOwnerMessage;
-	}
-
-	godlike_request_t data(request, param);
-	if(!mSelectedObjects->getRootObjectCount())
-	{
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(message_type);
-		LLSelectMgr::packGodlikeHead(&data);
-		gAgent.sendReliableMessage();
-	}
-	else
-	{
-		sendListToRegions(message_type, packGodlikeHead, packObjectIDAsParam, logNoOp, &data, SEND_ONLY_ROOTS);
-	}
+    // If the agent is neither godlike nor an estate owner, the server
+    // will reject the request.
+    const char* message_type;
+    if (gAgent.isGodlike())
+    {
+        message_type = _PREHASH_GodlikeMessage;
+    }
+    else
+    {
+        message_type = _PREHASH_EstateOwnerMessage;
+    }
+
+    godlike_request_t data(request, param);
+    if(!mSelectedObjects->getRootObjectCount())
+    {
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(message_type);
+        LLSelectMgr::packGodlikeHead(&data);
+        gAgent.sendReliableMessage();
+    }
+    else
+    {
+        sendListToRegions(message_type, packGodlikeHead, packObjectIDAsParam, logNoOp, &data, SEND_ONLY_ROOTS);
+    }
 }
 
 void LLSelectMgr::packGodlikeHead(void* user_data)
 {
-	LLMessageSystem* msg = gMessageSystem;
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null);
-	godlike_request_t* data = (godlike_request_t*)user_data;
-	msg->nextBlockFast(_PREHASH_MethodData);
-	msg->addStringFast(_PREHASH_Method, data->first);
-	msg->addUUIDFast(_PREHASH_Invoice, LLUUID::null);
-
-	// The parameters used to be restricted to either string or
-	// integer. This mimics that behavior under the new 'string-only'
-	// parameter list by not packing a string if there wasn't one
-	// specified. The object ids will be packed in the
-	// packObjectIDAsParam() method.
-	if(data->second.size() > 0)
-	{
-		msg->nextBlockFast(_PREHASH_ParamList);
-		msg->addStringFast(_PREHASH_Parameter, data->second);
-	}
+    LLMessageSystem* msg = gMessageSystem;
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null);
+    godlike_request_t* data = (godlike_request_t*)user_data;
+    msg->nextBlockFast(_PREHASH_MethodData);
+    msg->addStringFast(_PREHASH_Method, data->first);
+    msg->addUUIDFast(_PREHASH_Invoice, LLUUID::null);
+
+    // The parameters used to be restricted to either string or
+    // integer. This mimics that behavior under the new 'string-only'
+    // parameter list by not packing a string if there wasn't one
+    // specified. The object ids will be packed in the
+    // packObjectIDAsParam() method.
+    if(data->second.size() > 0)
+    {
+        msg->nextBlockFast(_PREHASH_ParamList);
+        msg->addStringFast(_PREHASH_Parameter, data->second);
+    }
 }
 
 // static
@@ -2974,9 +2974,9 @@ void LLSelectMgr::logDetachRequest(LLSelectNode* node, void *)
 // static
 void LLSelectMgr::packObjectIDAsParam(LLSelectNode* node, void *)
 {
-	std::string buf = llformat("%u", node->getObject()->getLocalID());
-	gMessageSystem->nextBlockFast(_PREHASH_ParamList);
-	gMessageSystem->addStringFast(_PREHASH_Parameter, buf);
+    std::string buf = llformat("%u", node->getObject()->getLocalID());
+    gMessageSystem->nextBlockFast(_PREHASH_ParamList);
+    gMessageSystem->addStringFast(_PREHASH_Parameter, buf);
 }
 
 //-----------------------------------------------------------------------------
@@ -2984,34 +2984,34 @@ void LLSelectMgr::packObjectIDAsParam(LLSelectNode* node, void *)
 //-----------------------------------------------------------------------------
 void LLSelectMgr::selectionTexScaleAutofit(F32 repeats_per_meter)
 {
-	struct f : public LLSelectedTEFunctor
-	{
-		F32 mRepeatsPerMeter;
-		f(const F32& t) : mRepeatsPerMeter(t) {}
-		bool apply(LLViewerObject* object, S32 te)
-		{
-			
-			if (object->permModify())
-			{
-				// Compute S,T to axis mapping
-				U32 s_axis, t_axis;
-				if (!LLPrimitive::getTESTAxes(te, &s_axis, &t_axis))
-				{
-					return TRUE;
-				}
+    struct f : public LLSelectedTEFunctor
+    {
+        F32 mRepeatsPerMeter;
+        f(const F32& t) : mRepeatsPerMeter(t) {}
+        bool apply(LLViewerObject* object, S32 te)
+        {
+
+            if (object->permModify())
+            {
+                // Compute S,T to axis mapping
+                U32 s_axis, t_axis;
+                if (!LLPrimitive::getTESTAxes(te, &s_axis, &t_axis))
+                {
+                    return TRUE;
+                }
 
-				F32 new_s = object->getScale().mV[s_axis] * mRepeatsPerMeter;
-				F32 new_t = object->getScale().mV[t_axis] * mRepeatsPerMeter;
+                F32 new_s = object->getScale().mV[s_axis] * mRepeatsPerMeter;
+                F32 new_t = object->getScale().mV[t_axis] * mRepeatsPerMeter;
 
-				object->setTEScale(te, new_s, new_t);
-			}
-			return true;
-		}
-	} setfunc(repeats_per_meter);
-	getSelection()->applyToTEs(&setfunc);
+                object->setTEScale(te, new_s, new_t);
+            }
+            return true;
+        }
+    } setfunc(repeats_per_meter);
+    getSelection()->applyToTEs(&setfunc);
 
-	LLSelectMgrSendFunctor sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
+    LLSelectMgrSendFunctor sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
 }
 
 
@@ -3024,111 +3024,111 @@ void LLSelectMgr::selectionTexScaleAutofit(F32 repeats_per_meter)
 //-----------------------------------------------------------------------------
 void LLSelectMgr::adjustTexturesByScale(BOOL send_to_sim, BOOL stretch)
 {
-	for (LLSelectNode* selectNode : getSelection()->begin_end())
-	{
-		LLViewerObject* object = selectNode->getObject();
-
-		if (!object)
-		{
-			continue;
-		}
-		
-		if (!object->permModify())
-		{
-			continue;
-		}
-
-		if (object->getNumTEs() == 0)
-		{
-			continue;
-		}
-
-		BOOL send = FALSE;
-		
-		for (U8 te_num = 0; te_num < object->getNumTEs(); te_num++)
-		{
-			const LLTextureEntry* tep = object->getTE(te_num);
-
-			BOOL planar = tep->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR;
-			if (planar == stretch)
-			{
-				// Figure out how S,T changed with scale operation
-				U32 s_axis, t_axis;
-				if (!LLPrimitive::getTESTAxes(te_num, &s_axis, &t_axis))
-				{
-					continue;
-				}
-				
-				LLVector3 object_scale = object->getScale();
-				LLVector3 diffuse_scale_ratio  = selectNode->mTextureScaleRatios[te_num]; 
-
-				// We like these to track together. NORSPEC-96
-				//
-				LLVector3 normal_scale_ratio   = diffuse_scale_ratio; 
-				LLVector3 specular_scale_ratio = diffuse_scale_ratio; 
-				
-				// Apply new scale to face
-				if (planar)
-				{
-					F32 diffuse_scale_s = diffuse_scale_ratio.mV[s_axis]/object_scale.mV[s_axis];
-					F32 diffuse_scale_t = diffuse_scale_ratio.mV[t_axis]/object_scale.mV[t_axis];
-
-					F32 normal_scale_s = normal_scale_ratio.mV[s_axis]/object_scale.mV[s_axis];
-					F32 normal_scale_t = normal_scale_ratio.mV[t_axis]/object_scale.mV[t_axis];
-
-					F32 specular_scale_s = specular_scale_ratio.mV[s_axis]/object_scale.mV[s_axis];
-					F32 specular_scale_t = specular_scale_ratio.mV[t_axis]/object_scale.mV[t_axis];
-
-					object->setTEScale(te_num, diffuse_scale_s, diffuse_scale_t);
-
-					LLTextureEntry* tep = object->getTE(te_num);
-
-					if (tep && !tep->getMaterialParams().isNull())
-					{
-						LLMaterialPtr orig = tep->getMaterialParams();
-						LLMaterialPtr p = gFloaterTools->getPanelFace()->createDefaultMaterial(orig);
-						p->setNormalRepeat(normal_scale_s, normal_scale_t);
-						p->setSpecularRepeat(specular_scale_s, specular_scale_t);
-
-						LLMaterialMgr::getInstance()->put(object->getID(), te_num, *p);
-					}
-				}
-				else
-				{
-
-					F32 diffuse_scale_s = diffuse_scale_ratio.mV[s_axis]*object_scale.mV[s_axis];
-					F32 diffuse_scale_t = diffuse_scale_ratio.mV[t_axis]*object_scale.mV[t_axis];
-
-					F32 normal_scale_s = normal_scale_ratio.mV[s_axis]*object_scale.mV[s_axis];
-					F32 normal_scale_t = normal_scale_ratio.mV[t_axis]*object_scale.mV[t_axis];
-
-					F32 specular_scale_s = specular_scale_ratio.mV[s_axis]*object_scale.mV[s_axis];
-					F32 specular_scale_t = specular_scale_ratio.mV[t_axis]*object_scale.mV[t_axis];
-
-					object->setTEScale(te_num, diffuse_scale_s,diffuse_scale_t);
-
-					LLTextureEntry* tep = object->getTE(te_num);
-
-					if (tep && !tep->getMaterialParams().isNull())
-					{
-						LLMaterialPtr orig = tep->getMaterialParams();
-						LLMaterialPtr p = gFloaterTools->getPanelFace()->createDefaultMaterial(orig);
-
-						p->setNormalRepeat(normal_scale_s, normal_scale_t);
-						p->setSpecularRepeat(specular_scale_s, specular_scale_t);
-
-						LLMaterialMgr::getInstance()->put(object->getID(), te_num, *p);
-					}
-				}
-				send = send_to_sim;
-			}
-		}
-
-		if (send)
-		{
-			object->sendTEUpdate();
-		}
-	}		
+    for (LLSelectNode* selectNode : getSelection()->begin_end())
+    {
+        LLViewerObject* object = selectNode->getObject();
+
+        if (!object)
+        {
+            continue;
+        }
+
+        if (!object->permModify())
+        {
+            continue;
+        }
+
+        if (object->getNumTEs() == 0)
+        {
+            continue;
+        }
+
+        BOOL send = FALSE;
+
+        for (U8 te_num = 0; te_num < object->getNumTEs(); te_num++)
+        {
+            const LLTextureEntry* tep = object->getTE(te_num);
+
+            BOOL planar = tep->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR;
+            if (planar == stretch)
+            {
+                // Figure out how S,T changed with scale operation
+                U32 s_axis, t_axis;
+                if (!LLPrimitive::getTESTAxes(te_num, &s_axis, &t_axis))
+                {
+                    continue;
+                }
+
+                LLVector3 object_scale = object->getScale();
+                LLVector3 diffuse_scale_ratio  = selectNode->mTextureScaleRatios[te_num];
+
+                // We like these to track together. NORSPEC-96
+                //
+                LLVector3 normal_scale_ratio   = diffuse_scale_ratio;
+                LLVector3 specular_scale_ratio = diffuse_scale_ratio;
+
+                // Apply new scale to face
+                if (planar)
+                {
+                    F32 diffuse_scale_s = diffuse_scale_ratio.mV[s_axis]/object_scale.mV[s_axis];
+                    F32 diffuse_scale_t = diffuse_scale_ratio.mV[t_axis]/object_scale.mV[t_axis];
+
+                    F32 normal_scale_s = normal_scale_ratio.mV[s_axis]/object_scale.mV[s_axis];
+                    F32 normal_scale_t = normal_scale_ratio.mV[t_axis]/object_scale.mV[t_axis];
+
+                    F32 specular_scale_s = specular_scale_ratio.mV[s_axis]/object_scale.mV[s_axis];
+                    F32 specular_scale_t = specular_scale_ratio.mV[t_axis]/object_scale.mV[t_axis];
+
+                    object->setTEScale(te_num, diffuse_scale_s, diffuse_scale_t);
+
+                    LLTextureEntry* tep = object->getTE(te_num);
+
+                    if (tep && !tep->getMaterialParams().isNull())
+                    {
+                        LLMaterialPtr orig = tep->getMaterialParams();
+                        LLMaterialPtr p = gFloaterTools->getPanelFace()->createDefaultMaterial(orig);
+                        p->setNormalRepeat(normal_scale_s, normal_scale_t);
+                        p->setSpecularRepeat(specular_scale_s, specular_scale_t);
+
+                        LLMaterialMgr::getInstance()->put(object->getID(), te_num, *p);
+                    }
+                }
+                else
+                {
+
+                    F32 diffuse_scale_s = diffuse_scale_ratio.mV[s_axis]*object_scale.mV[s_axis];
+                    F32 diffuse_scale_t = diffuse_scale_ratio.mV[t_axis]*object_scale.mV[t_axis];
+
+                    F32 normal_scale_s = normal_scale_ratio.mV[s_axis]*object_scale.mV[s_axis];
+                    F32 normal_scale_t = normal_scale_ratio.mV[t_axis]*object_scale.mV[t_axis];
+
+                    F32 specular_scale_s = specular_scale_ratio.mV[s_axis]*object_scale.mV[s_axis];
+                    F32 specular_scale_t = specular_scale_ratio.mV[t_axis]*object_scale.mV[t_axis];
+
+                    object->setTEScale(te_num, diffuse_scale_s,diffuse_scale_t);
+
+                    LLTextureEntry* tep = object->getTE(te_num);
+
+                    if (tep && !tep->getMaterialParams().isNull())
+                    {
+                        LLMaterialPtr orig = tep->getMaterialParams();
+                        LLMaterialPtr p = gFloaterTools->getPanelFace()->createDefaultMaterial(orig);
+
+                        p->setNormalRepeat(normal_scale_s, normal_scale_t);
+                        p->setSpecularRepeat(specular_scale_s, specular_scale_t);
+
+                        LLMaterialMgr::getInstance()->put(object->getID(), te_num, *p);
+                    }
+                }
+                send = send_to_sim;
+            }
+        }
+
+        if (send)
+        {
+            object->sendTEUpdate();
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -3137,14 +3137,14 @@ void LLSelectMgr::adjustTexturesByScale(BOOL send_to_sim, BOOL stretch)
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetAllRootsValid()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 
@@ -3154,14 +3154,14 @@ BOOL LLSelectMgr::selectGetAllRootsValid()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetAllValid()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3172,15 +3172,15 @@ BOOL LLSelectMgr::selectGetAllValid()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetAllValidAndObjectsFound()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3189,19 +3189,19 @@ BOOL LLSelectMgr::selectGetAllValidAndObjectsFound()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetModify()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-		if( !object->permModify() )
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+        if( !object->permModify() )
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3210,20 +3210,20 @@ BOOL LLSelectMgr::selectGetModify()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetRootsModify()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-		if( !object->permModify() )
-		{
-			return FALSE;
-		}
-	}
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+        if( !object->permModify() )
+        {
+            return FALSE;
+        }
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3242,8 +3242,8 @@ BOOL LLSelectMgr::selectGetSameRegion()
     }
     LLViewerRegion* current_region = object->getRegion();
 
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
         object = node->getObject();
         if (!node->mValid || !object || current_region != object->getRegion())
         {
@@ -3260,19 +3260,19 @@ BOOL LLSelectMgr::selectGetSameRegion()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetNonPermanentEnforced()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-		if( object->isPermanentEnforced())
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+        if( object->isPermanentEnforced())
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3281,20 +3281,20 @@ BOOL LLSelectMgr::selectGetNonPermanentEnforced()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetRootsNonPermanentEnforced()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-		if( object->isPermanentEnforced())
-		{
-			return FALSE;
-		}
-	}
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+        if( object->isPermanentEnforced())
+        {
+            return FALSE;
+        }
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3302,19 +3302,19 @@ BOOL LLSelectMgr::selectGetRootsNonPermanentEnforced()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetPermanent()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-		if( !object->flagObjectPermanent())
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+        if( !object->flagObjectPermanent())
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3323,20 +3323,20 @@ BOOL LLSelectMgr::selectGetPermanent()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetRootsPermanent()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-		if( !object->flagObjectPermanent())
-		{
-			return FALSE;
-		}
-	}
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+        if( !object->flagObjectPermanent())
+        {
+            return FALSE;
+        }
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3344,19 +3344,19 @@ BOOL LLSelectMgr::selectGetRootsPermanent()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetCharacter()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-		if( !object->flagCharacter())
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+        if( !object->flagCharacter())
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3365,20 +3365,20 @@ BOOL LLSelectMgr::selectGetCharacter()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetRootsCharacter()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-		if( !object->flagCharacter())
-		{
-			return FALSE;
-		}
-	}
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+        if( !object->flagCharacter())
+        {
+            return FALSE;
+        }
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3386,19 +3386,19 @@ BOOL LLSelectMgr::selectGetRootsCharacter()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetNonPathfinding()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-		if( object->flagObjectPermanent() || object->flagCharacter())
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+        if( object->flagObjectPermanent() || object->flagCharacter())
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3407,20 +3407,20 @@ BOOL LLSelectMgr::selectGetNonPathfinding()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetRootsNonPathfinding()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-		if( object->flagObjectPermanent() || object->flagCharacter())
-		{
-			return FALSE;
-		}
-	}
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+        if( object->flagObjectPermanent() || object->flagCharacter())
+        {
+            return FALSE;
+        }
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3428,19 +3428,19 @@ BOOL LLSelectMgr::selectGetRootsNonPathfinding()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetNonPermanent()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-		if( object->flagObjectPermanent())
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+        if( object->flagObjectPermanent())
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3449,20 +3449,20 @@ BOOL LLSelectMgr::selectGetNonPermanent()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetRootsNonPermanent()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-		if( object->flagObjectPermanent())
-		{
-			return FALSE;
-		}
-	}
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+        if( object->flagObjectPermanent())
+        {
+            return FALSE;
+        }
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3470,72 +3470,72 @@ BOOL LLSelectMgr::selectGetRootsNonPermanent()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetNonCharacter()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-		if( object->flagCharacter())
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+        if( object->flagCharacter())
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
-// selectGetRootsNonCharacter() - return TRUE if all root objects are not 
+// selectGetRootsNonCharacter() - return TRUE if all root objects are not
 // character
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetRootsNonCharacter()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-		if( object->flagCharacter())
-		{
-			return FALSE;
-		}
-	}
-
-	return TRUE;
-}
-
-
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+        if( object->flagCharacter())
+        {
+            return FALSE;
+        }
+    }
+
+    return TRUE;
+}
+
+
 //-----------------------------------------------------------------------------
 // selectGetEditableLinksets() - return TRUE if all objects are editable
 //                               pathfinding linksets
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetEditableLinksets()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-		if (object->flagUsePhysics() ||
-			object->flagTemporaryOnRez() ||
-			object->flagCharacter() ||
-			object->flagVolumeDetect() ||
-			object->flagAnimSource() ||
-			(object->getRegion() != gAgent.getRegion()) ||
-			(!gAgent.isGodlike() && 
-			!gAgent.canManageEstate() &&
-			!object->permYouOwner() &&
-			!object->permMove()))
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+        if (object->flagUsePhysics() ||
+            object->flagTemporaryOnRez() ||
+            object->flagCharacter() ||
+            object->flagVolumeDetect() ||
+            object->flagAnimSource() ||
+            (object->getRegion() != gAgent.getRegion()) ||
+            (!gAgent.isGodlike() &&
+            !gAgent.canManageEstate() &&
+            !object->permYouOwner() &&
+            !object->permMove()))
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3544,20 +3544,20 @@ BOOL LLSelectMgr::selectGetEditableLinksets()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetViewableCharacters()
 {
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !object || !node->mValid )
-		{
-			return FALSE;
-		}
-		if( !object->flagCharacter() ||
-			(object->getRegion() != gAgent.getRegion()))
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !object || !node->mValid )
+        {
+            return FALSE;
+        }
+        if( !object->flagCharacter() ||
+            (object->getRegion() != gAgent.getRegion()))
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3566,19 +3566,19 @@ BOOL LLSelectMgr::selectGetViewableCharacters()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetRootsTransfer()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-		if(!object->permTransfer())
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+        if(!object->permTransfer())
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3587,84 +3587,84 @@ BOOL LLSelectMgr::selectGetRootsTransfer()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetRootsCopy()
 {
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if( !node->mValid )
-		{
-			return FALSE;
-		}
-		if(!object->permCopy())
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if( !node->mValid )
+        {
+            return FALSE;
+        }
+        if(!object->permCopy())
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 struct LLSelectGetFirstTest
 {
-	LLSelectGetFirstTest() : mIdentical(true), mFirst(true)	{ }
-	virtual ~LLSelectGetFirstTest() { }
-
-	// returns false to break out of the iteration.
-	bool checkMatchingNode(LLSelectNode* node)
-	{
-		if (!node || !node->mValid)
-		{
-			return false;
-		}
-
-		if (mFirst)
-		{
-			mFirstValue = getValueFromNode(node);
-			mFirst = false;
-		}
-		else
-		{
-			if ( mFirstValue != getValueFromNode(node) )
-			{
-				mIdentical = false;
-				// stop testing once we know not all selected are identical.
-				return false;
-			}
-		}
-		// continue testing.
-		return true;
-	}
-
-	bool mIdentical;
-	LLUUID mFirstValue;
+    LLSelectGetFirstTest() : mIdentical(true), mFirst(true) { }
+    virtual ~LLSelectGetFirstTest() { }
+
+    // returns false to break out of the iteration.
+    bool checkMatchingNode(LLSelectNode* node)
+    {
+        if (!node || !node->mValid)
+        {
+            return false;
+        }
+
+        if (mFirst)
+        {
+            mFirstValue = getValueFromNode(node);
+            mFirst = false;
+        }
+        else
+        {
+            if ( mFirstValue != getValueFromNode(node) )
+            {
+                mIdentical = false;
+                // stop testing once we know not all selected are identical.
+                return false;
+            }
+        }
+        // continue testing.
+        return true;
+    }
+
+    bool mIdentical;
+    LLUUID mFirstValue;
 
 protected:
-	virtual const LLUUID& getValueFromNode(LLSelectNode* node) = 0;
+    virtual const LLUUID& getValueFromNode(LLSelectNode* node) = 0;
 
 private:
-	bool mFirst;
+    bool mFirst;
 };
 
 void LLSelectMgr::getFirst(LLSelectGetFirstTest* test)
 {
-	if (ALControlCache::EditLinkedParts)
-	{
-		for (LLSelectNode* nodep : getSelection()->valid_begin_end())
-		{
-			if (!test->checkMatchingNode(nodep))
-			{
-				break;
-			}
-		}
-	}
-	else
-	{
-		for (LLSelectNode* nodep : getSelection()->root_object_begin_end())
-		{
-			if (!test->checkMatchingNode(nodep))
-			{
-				break;
-			}
-		}
-	}
+    if (ALControlCache::EditLinkedParts)
+    {
+        for (LLSelectNode* nodep : getSelection()->valid_begin_end())
+        {
+            if (!test->checkMatchingNode(nodep))
+            {
+                break;
+            }
+        }
+    }
+    else
+    {
+        for (LLSelectNode* nodep : getSelection()->root_object_begin_end())
+        {
+            if (!test->checkMatchingNode(nodep))
+            {
+                break;
+            }
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -3674,35 +3674,35 @@ void LLSelectMgr::getFirst(LLSelectGetFirstTest* test)
 struct LLSelectGetFirstCreator : public LLSelectGetFirstTest
 {
 protected:
-	virtual const LLUUID& getValueFromNode(LLSelectNode* node)
-	{
-		return node->mPermissions->getCreator();
-	}
+    virtual const LLUUID& getValueFromNode(LLSelectNode* node)
+    {
+        return node->mPermissions->getCreator();
+    }
 };
 
 BOOL LLSelectMgr::selectGetCreator(LLUUID& result_id, std::string& name)
 {
-	LLSelectGetFirstCreator test;
-	getFirst(&test);
+    LLSelectGetFirstCreator test;
+    getFirst(&test);
+
+    if (test.mFirstValue.isNull())
+    {
+        name = LLTrans::getString("AvatarNameNobody");
+        return FALSE;
+    }
 
-	if (test.mFirstValue.isNull())
-	{
-		name = LLTrans::getString("AvatarNameNobody");
-		return FALSE;
-	}
-	
-	result_id = test.mFirstValue;
-	
-	if (test.mIdentical)
-	{
-		name = LLSLURL("agent", test.mFirstValue, "inspect").getSLURLString();
-	}
-	else
-	{
-		name = LLTrans::getString("AvatarNameMultiple");
-	}
+    result_id = test.mFirstValue;
 
-	return test.mIdentical;
+    if (test.mIdentical)
+    {
+        name = LLSLURL("agent", test.mFirstValue, "inspect").getSLURLString();
+    }
+    else
+    {
+        name = LLTrans::getString("AvatarNameMultiple");
+    }
+
+    return test.mIdentical;
 }
 
 //-----------------------------------------------------------------------------
@@ -3712,44 +3712,44 @@ BOOL LLSelectMgr::selectGetCreator(LLUUID& result_id, std::string& name)
 struct LLSelectGetFirstOwner : public LLSelectGetFirstTest
 {
 protected:
-	virtual const LLUUID& getValueFromNode(LLSelectNode* node)
-	{
-		// Don't use 'getOwnership' since we return a reference, not a copy.
-		// Will return LLUUID::null if unowned (which is not allowed and should never happen.)
-		return node->mPermissions->isGroupOwned() ? node->mPermissions->getGroup() : node->mPermissions->getOwner();
-	}
+    virtual const LLUUID& getValueFromNode(LLSelectNode* node)
+    {
+        // Don't use 'getOwnership' since we return a reference, not a copy.
+        // Will return LLUUID::null if unowned (which is not allowed and should never happen.)
+        return node->mPermissions->isGroupOwned() ? node->mPermissions->getGroup() : node->mPermissions->getOwner();
+    }
 };
 
 BOOL LLSelectMgr::selectGetOwner(LLUUID& result_id, std::string& name)
 {
-	LLSelectGetFirstOwner test;
-	getFirst(&test);
-
-	if (test.mFirstValue.isNull())
-	{
-		return FALSE;
-	}
-
-	result_id = test.mFirstValue;
-	
-	if (test.mIdentical)
-	{
-		bool group_owned = selectIsGroupOwned();
-		if (group_owned)
-		{
-			name = LLSLURL("group", test.mFirstValue, "inspect").getSLURLString();
-		}
-		else
-		{
-			name = LLSLURL("agent", test.mFirstValue, "inspect").getSLURLString();
-		}
-	}
-	else
-	{
-		name = LLTrans::getString("AvatarNameMultiple");
-	}
-
-	return test.mIdentical;
+    LLSelectGetFirstOwner test;
+    getFirst(&test);
+
+    if (test.mFirstValue.isNull())
+    {
+        return FALSE;
+    }
+
+    result_id = test.mFirstValue;
+
+    if (test.mIdentical)
+    {
+        bool group_owned = selectIsGroupOwned();
+        if (group_owned)
+        {
+            name = LLSLURL("group", test.mFirstValue, "inspect").getSLURLString();
+        }
+        else
+        {
+            name = LLSLURL("agent", test.mFirstValue, "inspect").getSLURLString();
+        }
+    }
+    else
+    {
+        name = LLTrans::getString("AvatarNameMultiple");
+    }
+
+    return test.mIdentical;
 }
 
 //-----------------------------------------------------------------------------
@@ -3759,34 +3759,34 @@ BOOL LLSelectMgr::selectGetOwner(LLUUID& result_id, std::string& name)
 struct LLSelectGetFirstLastOwner : public LLSelectGetFirstTest
 {
 protected:
-	virtual const LLUUID& getValueFromNode(LLSelectNode* node)
-	{
-		return node->mPermissions->getLastOwner();
-	}
+    virtual const LLUUID& getValueFromNode(LLSelectNode* node)
+    {
+        return node->mPermissions->getLastOwner();
+    }
 };
 
 BOOL LLSelectMgr::selectGetLastOwner(LLUUID& result_id, std::string& name)
 {
-	LLSelectGetFirstLastOwner test;
-	getFirst(&test);
+    LLSelectGetFirstLastOwner test;
+    getFirst(&test);
+
+    if (test.mFirstValue.isNull())
+    {
+        return FALSE;
+    }
 
-	if (test.mFirstValue.isNull())
-	{
-		return FALSE;
-	}
+    result_id = test.mFirstValue;
 
-	result_id = test.mFirstValue;
-	
-	if (test.mIdentical)
-	{
-		name = LLSLURL("agent", test.mFirstValue, "inspect").getSLURLString();
-	}
-	else
-	{
-		name.assign( "" );
-	}
+    if (test.mIdentical)
+    {
+        name = LLSLURL("agent", test.mFirstValue, "inspect").getSLURLString();
+    }
+    else
+    {
+        name.assign( "" );
+    }
 
-	return test.mIdentical;
+    return test.mIdentical;
 }
 
 //-----------------------------------------------------------------------------
@@ -3796,45 +3796,45 @@ BOOL LLSelectMgr::selectGetLastOwner(LLUUID& result_id, std::string& name)
 struct LLSelectGetFirstGroup : public LLSelectGetFirstTest
 {
 protected:
-	virtual const LLUUID& getValueFromNode(LLSelectNode* node)
-	{
-		return node->mPermissions->getGroup();
-	}
+    virtual const LLUUID& getValueFromNode(LLSelectNode* node)
+    {
+        return node->mPermissions->getGroup();
+    }
 };
 
 BOOL LLSelectMgr::selectGetGroup(LLUUID& result_id)
 {
-	LLSelectGetFirstGroup test;
-	getFirst(&test);
+    LLSelectGetFirstGroup test;
+    getFirst(&test);
 
-	result_id = test.mFirstValue;
-	return test.mIdentical;
+    result_id = test.mFirstValue;
+    return test.mIdentical;
 }
 
 //-----------------------------------------------------------------------------
 // selectIsGroupOwned()
-// Only operates on root nodes unless editing linked parts.  
+// Only operates on root nodes unless editing linked parts.
 // Returns TRUE if the first selected is group owned.
 //-----------------------------------------------------------------------------
 struct LLSelectGetFirstGroupOwner : public LLSelectGetFirstTest
 {
 protected:
-	virtual const LLUUID& getValueFromNode(LLSelectNode* node)
-	{
-		if (node->mPermissions->isGroupOwned())
-		{
-			return node->mPermissions->getGroup();
-		}
-		return LLUUID::null;
-	}
+    virtual const LLUUID& getValueFromNode(LLSelectNode* node)
+    {
+        if (node->mPermissions->isGroupOwned())
+        {
+            return node->mPermissions->getGroup();
+        }
+        return LLUUID::null;
+    }
 };
 
 BOOL LLSelectMgr::selectIsGroupOwned()
 {
-	LLSelectGetFirstGroupOwner test;
-	getFirst(&test);
+    LLSelectGetFirstGroupOwner test;
+    getFirst(&test);
 
-	return test.mFirstValue.notNull() ? TRUE : FALSE;
+    return test.mFirstValue.notNull() ? TRUE : FALSE;
 }
 
 //-----------------------------------------------------------------------------
@@ -3848,259 +3848,259 @@ BOOL LLSelectMgr::selectIsGroupOwned()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::selectGetPerm(U8 which_perm, U32* mask_on, U32* mask_off)
 {
-	U32 mask;
-	U32 mask_and	= 0xffffffff;
-	U32 mask_or		= 0x00000000;
-	BOOL all_valid	= FALSE;
-
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		if (!node->mValid)
-		{
-			all_valid = FALSE;
-			break;
-		}
-
-		all_valid = TRUE;
-		
-		switch( which_perm )
-		{
-		case PERM_BASE:
-			mask = node->mPermissions->getMaskBase();
-			break;
-		case PERM_OWNER:
-			mask = node->mPermissions->getMaskOwner();
-			break;
-		case PERM_GROUP:
-			mask = node->mPermissions->getMaskGroup();
-			break;
-		case PERM_EVERYONE:
-			mask = node->mPermissions->getMaskEveryone();
-			break;
-		case PERM_NEXT_OWNER:
-			mask = node->mPermissions->getMaskNextOwner();
-			break;
-		default:
-			mask = 0x0;
-			break;
-		}
-		mask_and &= mask;
-		mask_or	 |= mask;
-	}
-
-	if (all_valid)
-	{
-		// ...TRUE through all ANDs means all TRUE
-		*mask_on  = mask_and;
-
-		// ...FALSE through all ORs means all FALSE
-		*mask_off = ~mask_or;
-		return TRUE;
-	}
-	else
-	{
-		*mask_on  = 0;
-		*mask_off = 0;
-		return FALSE;
-	}
+    U32 mask;
+    U32 mask_and    = 0xffffffff;
+    U32 mask_or     = 0x00000000;
+    BOOL all_valid  = FALSE;
+
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        if (!node->mValid)
+        {
+            all_valid = FALSE;
+            break;
+        }
+
+        all_valid = TRUE;
+
+        switch( which_perm )
+        {
+        case PERM_BASE:
+            mask = node->mPermissions->getMaskBase();
+            break;
+        case PERM_OWNER:
+            mask = node->mPermissions->getMaskOwner();
+            break;
+        case PERM_GROUP:
+            mask = node->mPermissions->getMaskGroup();
+            break;
+        case PERM_EVERYONE:
+            mask = node->mPermissions->getMaskEveryone();
+            break;
+        case PERM_NEXT_OWNER:
+            mask = node->mPermissions->getMaskNextOwner();
+            break;
+        default:
+            mask = 0x0;
+            break;
+        }
+        mask_and &= mask;
+        mask_or  |= mask;
+    }
+
+    if (all_valid)
+    {
+        // ...TRUE through all ANDs means all TRUE
+        *mask_on  = mask_and;
+
+        // ...FALSE through all ORs means all FALSE
+        *mask_off = ~mask_or;
+        return TRUE;
+    }
+    else
+    {
+        *mask_on  = 0;
+        *mask_off = 0;
+        return FALSE;
+    }
 }
 
 
 
 BOOL LLSelectMgr::selectGetPermissions(LLPermissions& result_perm)
 {
-	BOOL first = TRUE;
-	LLPermissions perm;
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		if (!node->mValid)
-		{
-			return FALSE;
-		}
+    BOOL first = TRUE;
+    LLPermissions perm;
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        if (!node->mValid)
+        {
+            return FALSE;
+        }
 
-		if (first)
-		{
-			perm = *(node->mPermissions);
-			first = FALSE;
-		}
-		else
-		{
-			perm.accumulate(*(node->mPermissions));
-		}
-	}
+        if (first)
+        {
+            perm = *(node->mPermissions);
+            first = FALSE;
+        }
+        else
+        {
+            perm.accumulate(*(node->mPermissions));
+        }
+    }
 
-	result_perm = perm;
+    result_perm = perm;
 
-	return TRUE;
+    return TRUE;
 }
 
 
 void LLSelectMgr::selectDelete()
 {
 // [RLVa:KB] - Checked: 2010-03-23 (RLVa-1.2.0e) | Added: RLVa-1.2.0a
-	if ( (rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn()) )
-	{
-		make_ui_sound("UISndInvalidOp");
-		if (!gFloaterTools->getVisible())
-			deselectAll();
-		return;
-	}
+    if ( (rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn()) )
+    {
+        make_ui_sound("UISndInvalidOp");
+        if (!gFloaterTools->getVisible())
+            deselectAll();
+        return;
+    }
 // [/RLVa:KB]
 
-	S32 deleteable_count = 0;
-
-	BOOL locked_but_deleteable_object = FALSE;
-	BOOL no_copy_but_deleteable_object = FALSE;
-	BOOL all_owned_by_you = TRUE;
-
-	for (LLSelectNode* node : getSelection()->begin_end())
-	{
-		LLViewerObject* obj = node->getObject();
-
-		if( obj->isAttachment() )
-		{
-			continue;
-		}
-
-		deleteable_count++;
-
-		// Check to see if you can delete objects which are locked.
-		if(!obj->permMove())
-		{
-			locked_but_deleteable_object = TRUE;
-		}
-		if(!obj->permCopy())
-		{
-			no_copy_but_deleteable_object = TRUE;
-		}
-		if(!obj->permYouOwner())
-		{
-			all_owned_by_you = FALSE;
-		}
-	}
-
-	if( 0 == deleteable_count )
-	{
-		make_ui_sound("UISndInvalidOp");
-		return;
-	}
-
-	LLNotification::Params params("ConfirmObjectDeleteLock");
-	params.functor.function(boost::bind(&LLSelectMgr::confirmDelete, _1, _2, getSelection()));
-
-	if(locked_but_deleteable_object ||
-	   no_copy_but_deleteable_object ||
-	   !all_owned_by_you)
-	{
-		// convert any transient pie-menu selections to full selection so this operation
-		// has some context
-		// NOTE: if user cancels delete operation, this will potentially leave objects selected outside of build mode
-		// but this is ok, if not ideal
-		convertTransient();
-
-		//This is messy, but needed to get all english our of the UI.
-		if(locked_but_deleteable_object && !no_copy_but_deleteable_object && all_owned_by_you)
-		{
-			//Locked only
-			params.name("ConfirmObjectDeleteLock");
-		}
-		else if(!locked_but_deleteable_object && no_copy_but_deleteable_object && all_owned_by_you)
-		{
-			//No Copy only
-			params.name("ConfirmObjectDeleteNoCopy");
-		}
-		else if(!locked_but_deleteable_object && !no_copy_but_deleteable_object && !all_owned_by_you)
-		{
-			//not owned only
-			params.name("ConfirmObjectDeleteNoOwn");
-		}
-		else if(locked_but_deleteable_object && no_copy_but_deleteable_object && all_owned_by_you)
-		{
-			//locked and no copy
-			params.name("ConfirmObjectDeleteLockNoCopy");
-		}
-		else if(locked_but_deleteable_object && !no_copy_but_deleteable_object && !all_owned_by_you)
-		{
-			//locked and not owned
-			params.name("ConfirmObjectDeleteLockNoOwn");
-		}
-		else if(!locked_but_deleteable_object && no_copy_but_deleteable_object && !all_owned_by_you)
-		{
-			//no copy and not owned
-			params.name("ConfirmObjectDeleteNoCopyNoOwn");
-		}
-		else
-		{
-			//locked, no copy and not owned
-			params.name("ConfirmObjectDeleteLockNoCopyNoOwn");
-		}
-		
-		LLNotifications::instance().add(params);
-	}
-	else
-	{
-		LLNotifications::instance().forceResponse(params, 0);
-	}
+    S32 deleteable_count = 0;
+
+    BOOL locked_but_deleteable_object = FALSE;
+    BOOL no_copy_but_deleteable_object = FALSE;
+    BOOL all_owned_by_you = TRUE;
+
+    for (LLSelectNode* node : getSelection()->begin_end())
+    {
+        LLViewerObject* obj = node->getObject();
+
+        if( obj->isAttachment() )
+        {
+            continue;
+        }
+
+        deleteable_count++;
+
+        // Check to see if you can delete objects which are locked.
+        if(!obj->permMove())
+        {
+            locked_but_deleteable_object = TRUE;
+        }
+        if(!obj->permCopy())
+        {
+            no_copy_but_deleteable_object = TRUE;
+        }
+        if(!obj->permYouOwner())
+        {
+            all_owned_by_you = FALSE;
+        }
+    }
+
+    if( 0 == deleteable_count )
+    {
+        make_ui_sound("UISndInvalidOp");
+        return;
+    }
+
+    LLNotification::Params params("ConfirmObjectDeleteLock");
+    params.functor.function(boost::bind(&LLSelectMgr::confirmDelete, _1, _2, getSelection()));
+
+    if(locked_but_deleteable_object ||
+       no_copy_but_deleteable_object ||
+       !all_owned_by_you)
+    {
+        // convert any transient pie-menu selections to full selection so this operation
+        // has some context
+        // NOTE: if user cancels delete operation, this will potentially leave objects selected outside of build mode
+        // but this is ok, if not ideal
+        convertTransient();
+
+        //This is messy, but needed to get all english our of the UI.
+        if(locked_but_deleteable_object && !no_copy_but_deleteable_object && all_owned_by_you)
+        {
+            //Locked only
+            params.name("ConfirmObjectDeleteLock");
+        }
+        else if(!locked_but_deleteable_object && no_copy_but_deleteable_object && all_owned_by_you)
+        {
+            //No Copy only
+            params.name("ConfirmObjectDeleteNoCopy");
+        }
+        else if(!locked_but_deleteable_object && !no_copy_but_deleteable_object && !all_owned_by_you)
+        {
+            //not owned only
+            params.name("ConfirmObjectDeleteNoOwn");
+        }
+        else if(locked_but_deleteable_object && no_copy_but_deleteable_object && all_owned_by_you)
+        {
+            //locked and no copy
+            params.name("ConfirmObjectDeleteLockNoCopy");
+        }
+        else if(locked_but_deleteable_object && !no_copy_but_deleteable_object && !all_owned_by_you)
+        {
+            //locked and not owned
+            params.name("ConfirmObjectDeleteLockNoOwn");
+        }
+        else if(!locked_but_deleteable_object && no_copy_but_deleteable_object && !all_owned_by_you)
+        {
+            //no copy and not owned
+            params.name("ConfirmObjectDeleteNoCopyNoOwn");
+        }
+        else
+        {
+            //locked, no copy and not owned
+            params.name("ConfirmObjectDeleteLockNoCopyNoOwn");
+        }
+
+        LLNotifications::instance().add(params);
+    }
+    else
+    {
+        LLNotifications::instance().forceResponse(params, 0);
+    }
 }
 
 // static
 bool LLSelectMgr::confirmDelete(const LLSD& notification, const LLSD& response, LLObjectSelectionHandle handle)
 {
-	S32 option = LLNotification::getSelectedOption(notification, response);
-	if (!handle->getObjectCount())
-	{
-		LL_WARNS() << "Nothing to delete!" << LL_ENDL;
-		return false;
-	}
-
-	switch(option)
-	{
-	case 0:
-		{
-			// TODO: Make sure you have delete permissions on all of them.
-			const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-			// attempt to derez into the trash.
-			LLDeRezInfo info(DRD_TRASH, trash_id);
-			LLSelectMgr::getInstance()->sendListToRegions("DeRezObject",
+    S32 option = LLNotification::getSelectedOption(notification, response);
+    if (!handle->getObjectCount())
+    {
+        LL_WARNS() << "Nothing to delete!" << LL_ENDL;
+        return false;
+    }
+
+    switch(option)
+    {
+    case 0:
+        {
+            // TODO: Make sure you have delete permissions on all of them.
+            const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+            // attempt to derez into the trash.
+            LLDeRezInfo info(DRD_TRASH, trash_id);
+            LLSelectMgr::getInstance()->sendListToRegions("DeRezObject",
                                                           packDeRezHeader,
                                                           packObjectLocalID,
                                                           logNoOp,
                                                           (void*) &info,
                                                           SEND_ONLY_ROOTS);
-			// VEFFECT: Delete Object - one effect for all deletes
-			if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral") && (LLSelectMgr::getInstance()->mSelectedObjects->mSelectType != SELECT_TYPE_HUD))
-			{
-				LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
-				effectp->setPositionGlobal( LLSelectMgr::getInstance()->getSelectionCenterGlobal() );
-				effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-				F32 duration = 0.5f;
-				duration += LLSelectMgr::getInstance()->mSelectedObjects->getObjectCount() / 64.f;
-				effectp->setDuration(duration);
-			}
-
-			gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
-
-			// Keep track of how many objects have been deleted.
-			add(LLStatViewer::DELETE_OBJECT, LLSelectMgr::getInstance()->mSelectedObjects->getObjectCount());
-		}
-		break;
-	case 1:
-	default:
-		break;
-	}
-	return false;
+            // VEFFECT: Delete Object - one effect for all deletes
+            if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral") && (LLSelectMgr::getInstance()->mSelectedObjects->mSelectType != SELECT_TYPE_HUD))
+            {
+                LLHUDEffectSpiral *effectp = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
+                effectp->setPositionGlobal( LLSelectMgr::getInstance()->getSelectionCenterGlobal() );
+                effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+                F32 duration = 0.5f;
+                duration += LLSelectMgr::getInstance()->mSelectedObjects->getObjectCount() / 64.f;
+                effectp->setDuration(duration);
+            }
+
+            gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
+
+            // Keep track of how many objects have been deleted.
+            add(LLStatViewer::DELETE_OBJECT, LLSelectMgr::getInstance()->mSelectedObjects->getObjectCount());
+        }
+        break;
+    case 1:
+    default:
+        break;
+    }
+    return false;
 }
 
 
 void LLSelectMgr::selectForceDelete()
 {
-	sendListToRegions(
-		"ObjectDelete",
-		packDeleteHeader,
-		packObjectLocalID,
+    sendListToRegions(
+        "ObjectDelete",
+        packDeleteHeader,
+        packObjectLocalID,
         logNoOp,
-		(void*)TRUE,
-		SEND_ONLY_ROOTS);
+        (void*)TRUE,
+        SEND_ONLY_ROOTS);
 }
 
 BOOL LLSelectMgr::selectGetEditMoveLinksetPermissions(bool &move, bool &modify)
@@ -4109,8 +4109,8 @@ BOOL LLSelectMgr::selectGetEditMoveLinksetPermissions(bool &move, bool &modify)
     modify = true;
     bool selecting_linked_set = !ALControlCache::EditLinkedParts;
 
-	for (LLSelectNode* nodep : getSelection()->begin_end())
-	{
+    for (LLSelectNode* nodep : getSelection()->begin_end())
+    {
         LLViewerObject* object = nodep->getObject();
         if (!object || !nodep->mValid)
         {
@@ -4128,12 +4128,12 @@ BOOL LLSelectMgr::selectGetEditMoveLinksetPermissions(bool &move, bool &modify)
             this_object_movable = true;
 
 // [RLVa:KB] - Checked: 2010-03-31 (RLVa-1.2.0c) | Modified: RLVa-0.2.0g
-			if ( (rlv_handler_t::isEnabled()) &&
-				 ((gRlvHandler.hasBehaviour(RLV_BHVR_UNSIT)) || (gRlvHandler.hasBehaviour(RLV_BHVR_SITTP))) )
-			{
-				if ((isAgentAvatarValid()) && (gAgentAvatarp->isSitting()) && (gAgentAvatarp->getRoot() == object->getRootEdit()))
-					this_object_movable = false;
-			}
+            if ( (rlv_handler_t::isEnabled()) &&
+                 ((gRlvHandler.hasBehaviour(RLV_BHVR_UNSIT)) || (gRlvHandler.hasBehaviour(RLV_BHVR_SITTP))) )
+            {
+                if ((isAgentAvatarValid()) && (gAgentAvatarp->isSitting()) && (gAgentAvatarp->getRoot() == object->getRootEdit()))
+                    this_object_movable = false;
+            }
 // [/RLVa:KB]
         }
         move = move && this_object_movable;
@@ -4144,147 +4144,147 @@ BOOL LLSelectMgr::selectGetEditMoveLinksetPermissions(bool &move, bool &modify)
 }
 
 void LLSelectMgr::selectGetAggregateSaleInfo(U32 &num_for_sale,
-											 BOOL &is_for_sale_mixed, 
-											 BOOL &is_sale_price_mixed,
-											 S32 &total_sale_price,
-											 S32 &individual_sale_price)
-{
-	num_for_sale = 0;
-	is_for_sale_mixed = FALSE;
-	is_sale_price_mixed = FALSE;
-	total_sale_price = 0;
-	individual_sale_price = 0;
-
-
-	// Empty set.
-	auto selection = getSelection();
-	if (selection->root_begin() == selection->root_end())
-		return;
-	
-	LLSelectNode *node = *(selection->root_begin());
-	const BOOL first_node_for_sale = node->mSaleInfo.isForSale();
-	const S32 first_node_sale_price = node->mSaleInfo.getSalePrice();
-	
-	for (LLSelectNode* node : selection->root_begin_end())
-	{
-		const BOOL node_for_sale = node->mSaleInfo.isForSale();
-		const S32 node_sale_price = node->mSaleInfo.getSalePrice();
-		
-		// Set mixed if the fields don't match the first node's fields.
-		if (node_for_sale != first_node_for_sale) 
-			is_for_sale_mixed = TRUE;
-		if (node_sale_price != first_node_sale_price)
-			is_sale_price_mixed = TRUE;
-		
-		if (node_for_sale)
-		{
-			total_sale_price += node_sale_price;
-			num_for_sale ++;
-		}
-	}
-	
-	individual_sale_price = first_node_sale_price;
-	if (is_for_sale_mixed)
-	{
-		is_sale_price_mixed = TRUE;
-		individual_sale_price = 0;
-	}
-}
-
-// returns TRUE if all nodes are valid. method also stores an
-// accumulated sale info.
-BOOL LLSelectMgr::selectGetSaleInfo(LLSaleInfo& result_sale_info)
+                                             BOOL &is_for_sale_mixed,
+                                             BOOL &is_sale_price_mixed,
+                                             S32 &total_sale_price,
+                                             S32 &individual_sale_price)
 {
-	BOOL first = TRUE;
-	LLSaleInfo sale_info;
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		if (!node->mValid)
-		{
-			return FALSE;
-		}
+    num_for_sale = 0;
+    is_for_sale_mixed = FALSE;
+    is_sale_price_mixed = FALSE;
+    total_sale_price = 0;
+    individual_sale_price = 0;
 
-		if (first)
-		{
-			sale_info = node->mSaleInfo;
-			first = FALSE;
-		}
-		else
-		{
-			sale_info.accumulate(node->mSaleInfo);
-		}
-	}
 
-	result_sale_info = sale_info;
+    // Empty set.
+    auto selection = getSelection();
+    if (selection->root_begin() == selection->root_end())
+        return;
 
-	return TRUE;
-}
+    LLSelectNode *node = *(selection->root_begin());
+    const BOOL first_node_for_sale = node->mSaleInfo.isForSale();
+    const S32 first_node_sale_price = node->mSaleInfo.getSalePrice();
 
-BOOL LLSelectMgr::selectGetAggregatePermissions(LLAggregatePermissions& result_perm)
-{
-	BOOL first = TRUE;
-	LLAggregatePermissions perm;
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		if (!node->mValid)
-		{
-			return FALSE;
-		}
+    for (LLSelectNode* node : selection->root_begin_end())
+    {
+        const BOOL node_for_sale = node->mSaleInfo.isForSale();
+        const S32 node_sale_price = node->mSaleInfo.getSalePrice();
 
-		if (first)
-		{
-			perm = node->mAggregatePerm;
-			first = FALSE;
-		}
-		else
-		{
-			perm.aggregate(node->mAggregatePerm);
-		}
-	}
+        // Set mixed if the fields don't match the first node's fields.
+        if (node_for_sale != first_node_for_sale)
+            is_for_sale_mixed = TRUE;
+        if (node_sale_price != first_node_sale_price)
+            is_sale_price_mixed = TRUE;
 
-	result_perm = perm;
+        if (node_for_sale)
+        {
+            total_sale_price += node_sale_price;
+            num_for_sale ++;
+        }
+    }
 
-	return TRUE;
+    individual_sale_price = first_node_sale_price;
+    if (is_for_sale_mixed)
+    {
+        is_sale_price_mixed = TRUE;
+        individual_sale_price = 0;
+    }
 }
 
-BOOL LLSelectMgr::selectGetAggregateTexturePermissions(LLAggregatePermissions& result_perm)
+// returns TRUE if all nodes are valid. method also stores an
+// accumulated sale info.
+BOOL LLSelectMgr::selectGetSaleInfo(LLSaleInfo& result_sale_info)
 {
-	BOOL first = TRUE;
-	LLAggregatePermissions perm;
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		if (!node->mValid)
-		{
-			return FALSE;
-		}
+    BOOL first = TRUE;
+    LLSaleInfo sale_info;
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        if (!node->mValid)
+        {
+            return FALSE;
+        }
 
-		LLAggregatePermissions t_perm = node->getObject()->permYouOwner() ? node->mAggregateTexturePermOwner : node->mAggregateTexturePerm;
-		if (first)
-		{
-			perm = t_perm;
-			first = FALSE;
-		}
-		else
-		{
-			perm.aggregate(t_perm);
-		}
-	}
+        if (first)
+        {
+            sale_info = node->mSaleInfo;
+            first = FALSE;
+        }
+        else
+        {
+            sale_info.accumulate(node->mSaleInfo);
+        }
+    }
 
-	result_perm = perm;
+    result_sale_info = sale_info;
 
-	return TRUE;
+    return TRUE;
 }
 
-BOOL LLSelectMgr::isMovableAvatarSelected()
+BOOL LLSelectMgr::selectGetAggregatePermissions(LLAggregatePermissions& result_perm)
 {
-	if (mAllowSelectAvatar && getSelection()->getObjectCount() == 1)
-	{
-        // nothing but avatar should be selected, so check that
-        // there is only one selected object and it is a root
-        LLViewerObject* obj = getSelection()->getFirstRootObject();
-		return obj && obj->isAvatar() && getSelection()->getFirstMoveableNode(TRUE);
-	}
-	return FALSE;
+    BOOL first = TRUE;
+    LLAggregatePermissions perm;
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        if (!node->mValid)
+        {
+            return FALSE;
+        }
+
+        if (first)
+        {
+            perm = node->mAggregatePerm;
+            first = FALSE;
+        }
+        else
+        {
+            perm.aggregate(node->mAggregatePerm);
+        }
+    }
+
+    result_perm = perm;
+
+    return TRUE;
+}
+
+BOOL LLSelectMgr::selectGetAggregateTexturePermissions(LLAggregatePermissions& result_perm)
+{
+    BOOL first = TRUE;
+    LLAggregatePermissions perm;
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        if (!node->mValid)
+        {
+            return FALSE;
+        }
+
+        LLAggregatePermissions t_perm = node->getObject()->permYouOwner() ? node->mAggregateTexturePermOwner : node->mAggregateTexturePerm;
+        if (first)
+        {
+            perm = t_perm;
+            first = FALSE;
+        }
+        else
+        {
+            perm.aggregate(t_perm);
+        }
+    }
+
+    result_perm = perm;
+
+    return TRUE;
+}
+
+BOOL LLSelectMgr::isMovableAvatarSelected()
+{
+    if (mAllowSelectAvatar && getSelection()->getObjectCount() == 1)
+    {
+        // nothing but avatar should be selected, so check that
+        // there is only one selected object and it is a root
+        LLViewerObject* obj = getSelection()->getFirstRootObject();
+        return obj && obj->isAvatar() && getSelection()->getFirstMoveableNode(TRUE);
+    }
+    return FALSE;
 }
 
 //--------------------------------------------------------------------
@@ -4296,114 +4296,114 @@ BOOL LLSelectMgr::isMovableAvatarSelected()
 // messages.
 struct LLDuplicateData
 {
-	LLVector3	offset;
-	U32			flags;
+    LLVector3   offset;
+    U32         flags;
 };
 
 void LLSelectMgr::selectDuplicate(const LLVector3& offset, BOOL select_copy)
 {
-//	if (mSelectedObjects->isAttachment())
+//  if (mSelectedObjects->isAttachment())
 // [RLVa:KB] - Checked: 2010-03-24 (RLVa-1.2.0e) | Added: RLVa-1.2.0a
-	if ( (mSelectedObjects->isAttachment()) || ((rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn())) )
+    if ( (mSelectedObjects->isAttachment()) || ((rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn())) )
 // [/RLVa:KB]
-	{
-		//RN: do not duplicate attachments
-		make_ui_sound("UISndInvalidOp");
-		return;
-	}
-	if (!canDuplicate())
-	{
-		LLSelectNode* node = getSelection()->getFirstRootNode(NULL, true);
-		if (node)
-		{
-			LLSD args;
-			args["OBJ_NAME"] = node->mName;
-			LLNotificationsUtil::add("NoCopyPermsNoObject", args);
-			return;
-		}
-	}
-	LLDuplicateData	data;
-
-	data.offset = offset;
-	data.flags = (select_copy ? FLAGS_CREATE_SELECTED : 0x0);
-
-	sendListToRegions("ObjectDuplicate", packDuplicateHeader, packDuplicate, logNoOp, &data, SEND_ONLY_ROOTS);
-
-	if (select_copy)
-	{
-		// the new copy will be coming in selected
-		deselectAll();
-	}
-	else
-	{
-		for (LLSelectNode* node : getSelection()->root_begin_end())
-		{
-			node->mDuplicated = TRUE;
-			node->mDuplicatePos = node->getObject()->getPositionGlobal();
-			node->mDuplicateRot = node->getObject()->getRotation();
-		}
-	}
+    {
+        //RN: do not duplicate attachments
+        make_ui_sound("UISndInvalidOp");
+        return;
+    }
+    if (!canDuplicate())
+    {
+        LLSelectNode* node = getSelection()->getFirstRootNode(NULL, true);
+        if (node)
+        {
+            LLSD args;
+            args["OBJ_NAME"] = node->mName;
+            LLNotificationsUtil::add("NoCopyPermsNoObject", args);
+            return;
+        }
+    }
+    LLDuplicateData data;
+
+    data.offset = offset;
+    data.flags = (select_copy ? FLAGS_CREATE_SELECTED : 0x0);
+
+    sendListToRegions("ObjectDuplicate", packDuplicateHeader, packDuplicate, logNoOp, &data, SEND_ONLY_ROOTS);
+
+    if (select_copy)
+    {
+        // the new copy will be coming in selected
+        deselectAll();
+    }
+    else
+    {
+        for (LLSelectNode* node : getSelection()->root_begin_end())
+        {
+            node->mDuplicated = TRUE;
+            node->mDuplicatePos = node->getObject()->getPositionGlobal();
+            node->mDuplicateRot = node->getObject()->getRotation();
+        }
+    }
 }
 
 void LLSelectMgr::repeatDuplicate()
 {
-	if (mSelectedObjects->isAttachment())
-	{
-		//RN: do not duplicate attachments
-		make_ui_sound("UISndInvalidOp");
-		return;
-	}
-
-	std::vector<LLViewerObject*> non_duplicated_objects;
-
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		if (!node->mDuplicated)
-		{
-			non_duplicated_objects.push_back(node->getObject());
-		}
-	}
-
-	// make sure only previously duplicated objects are selected
-	for (LLViewerObject* objectp : non_duplicated_objects)
-	{
-		deselectObjectAndFamily(objectp);
-	}
-	
-	// duplicate objects in place
-	LLDuplicateData	data;
-
-	data.offset = LLVector3::zero;
-	data.flags = 0x0;
-
-	sendListToRegions("ObjectDuplicate", packDuplicateHeader, packDuplicate, logNoOp, &data, SEND_ONLY_ROOTS);
-
-	// move current selection based on delta from duplication position and update duplication position
-	for (LLSelectNode* node : getSelection()->root_begin_end())
-	{
-		if (node->mDuplicated)
-		{
-			LLQuaternion cur_rot = node->getObject()->getRotation();
-			LLQuaternion rot_delta = (~node->mDuplicateRot * cur_rot);
-			LLQuaternion new_rot = cur_rot * rot_delta;
-			LLVector3d cur_pos = node->getObject()->getPositionGlobal();
-			LLVector3d new_pos = cur_pos + ((cur_pos - node->mDuplicatePos) * rot_delta);
-
-			node->mDuplicatePos = node->getObject()->getPositionGlobal();
-			node->mDuplicateRot = node->getObject()->getRotation();
-			node->getObject()->setPositionGlobal(new_pos);
-			node->getObject()->setRotation(new_rot);
-		}
-	}
-
-	sendMultipleUpdate(UPD_ROTATION | UPD_POSITION);
-}
-
-// static 
+    if (mSelectedObjects->isAttachment())
+    {
+        //RN: do not duplicate attachments
+        make_ui_sound("UISndInvalidOp");
+        return;
+    }
+
+    std::vector<LLViewerObject*> non_duplicated_objects;
+
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        if (!node->mDuplicated)
+        {
+            non_duplicated_objects.push_back(node->getObject());
+        }
+    }
+
+    // make sure only previously duplicated objects are selected
+    for (LLViewerObject* objectp : non_duplicated_objects)
+    {
+        deselectObjectAndFamily(objectp);
+    }
+
+    // duplicate objects in place
+    LLDuplicateData data;
+
+    data.offset = LLVector3::zero;
+    data.flags = 0x0;
+
+    sendListToRegions("ObjectDuplicate", packDuplicateHeader, packDuplicate, logNoOp, &data, SEND_ONLY_ROOTS);
+
+    // move current selection based on delta from duplication position and update duplication position
+    for (LLSelectNode* node : getSelection()->root_begin_end())
+    {
+        if (node->mDuplicated)
+        {
+            LLQuaternion cur_rot = node->getObject()->getRotation();
+            LLQuaternion rot_delta = (~node->mDuplicateRot * cur_rot);
+            LLQuaternion new_rot = cur_rot * rot_delta;
+            LLVector3d cur_pos = node->getObject()->getPositionGlobal();
+            LLVector3d new_pos = cur_pos + ((cur_pos - node->mDuplicatePos) * rot_delta);
+
+            node->mDuplicatePos = node->getObject()->getPositionGlobal();
+            node->mDuplicateRot = node->getObject()->getRotation();
+            node->getObject()->setPositionGlobal(new_pos);
+            node->getObject()->setRotation(new_rot);
+        }
+    }
+
+    sendMultipleUpdate(UPD_ROTATION | UPD_POSITION);
+}
+
+// static
 void LLSelectMgr::packDuplicate( LLSelectNode* node, void *duplicate_data )
 {
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
 }
 
 
@@ -4415,71 +4415,71 @@ void LLSelectMgr::packDuplicate( LLSelectNode* node, void *duplicate_data )
 // ray.
 struct LLDuplicateOnRayData
 {
-	LLVector3	mRayStartRegion;
-	LLVector3	mRayEndRegion;
-	BOOL		mBypassRaycast;
-	BOOL		mRayEndIsIntersection;
-	LLUUID		mRayTargetID;
-	BOOL		mCopyCenters;
-	BOOL		mCopyRotates;
-	U32			mFlags;
+    LLVector3   mRayStartRegion;
+    LLVector3   mRayEndRegion;
+    BOOL        mBypassRaycast;
+    BOOL        mRayEndIsIntersection;
+    LLUUID      mRayTargetID;
+    BOOL        mCopyCenters;
+    BOOL        mCopyRotates;
+    U32         mFlags;
 };
 
 void LLSelectMgr::selectDuplicateOnRay(const LLVector3 &ray_start_region,
-									   const LLVector3 &ray_end_region,
-									   BOOL bypass_raycast,
-									   BOOL ray_end_is_intersection,
-									   const LLUUID &ray_target_id,
-									   BOOL copy_centers,
-									   BOOL copy_rotates,
-									   BOOL select_copy)
-{
-	if (mSelectedObjects->isAttachment())
-	{
-		// do not duplicate attachments
-		make_ui_sound("UISndInvalidOp");
-		return;
-	}
-	
-	LLDuplicateOnRayData	data;
-
-	data.mRayStartRegion	= ray_start_region;
-	data.mRayEndRegion		= ray_end_region;
-	data.mBypassRaycast		= bypass_raycast;
-	data.mRayEndIsIntersection = ray_end_is_intersection;
-	data.mRayTargetID		= ray_target_id;
-	data.mCopyCenters		= copy_centers;
-	data.mCopyRotates		= copy_rotates;
-	data.mFlags				= (select_copy ? FLAGS_CREATE_SELECTED : 0x0);
-
-	sendListToRegions("ObjectDuplicateOnRay", 
+                                       const LLVector3 &ray_end_region,
+                                       BOOL bypass_raycast,
+                                       BOOL ray_end_is_intersection,
+                                       const LLUUID &ray_target_id,
+                                       BOOL copy_centers,
+                                       BOOL copy_rotates,
+                                       BOOL select_copy)
+{
+    if (mSelectedObjects->isAttachment())
+    {
+        // do not duplicate attachments
+        make_ui_sound("UISndInvalidOp");
+        return;
+    }
+
+    LLDuplicateOnRayData    data;
+
+    data.mRayStartRegion    = ray_start_region;
+    data.mRayEndRegion      = ray_end_region;
+    data.mBypassRaycast     = bypass_raycast;
+    data.mRayEndIsIntersection = ray_end_is_intersection;
+    data.mRayTargetID       = ray_target_id;
+    data.mCopyCenters       = copy_centers;
+    data.mCopyRotates       = copy_rotates;
+    data.mFlags             = (select_copy ? FLAGS_CREATE_SELECTED : 0x0);
+
+    sendListToRegions("ObjectDuplicateOnRay",
                       packDuplicateOnRayHead, packObjectLocalID, logNoOp, &data, SEND_ONLY_ROOTS);
 
-	if (select_copy)
-	{
-		// the new copy will be coming in selected
-		deselectAll();
-	}
+    if (select_copy)
+    {
+        // the new copy will be coming in selected
+        deselectAll();
+    }
 }
 
 // static
 void LLSelectMgr::packDuplicateOnRayHead(void *user_data)
 {
-	LLMessageSystem *msg = gMessageSystem;
-	LLDuplicateOnRayData *data = (LLDuplicateOnRayData *)user_data;
+    LLMessageSystem *msg = gMessageSystem;
+    LLDuplicateOnRayData *data = (LLDuplicateOnRayData *)user_data;
 
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
-	msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupForRezzing() );
-	msg->addVector3Fast(_PREHASH_RayStart, data->mRayStartRegion );
-	msg->addVector3Fast(_PREHASH_RayEnd, data->mRayEndRegion );
-	msg->addBOOLFast(_PREHASH_BypassRaycast, data->mBypassRaycast );
-	msg->addBOOLFast(_PREHASH_RayEndIsIntersection, data->mRayEndIsIntersection );
-	msg->addBOOLFast(_PREHASH_CopyCenters, data->mCopyCenters );
-	msg->addBOOLFast(_PREHASH_CopyRotates, data->mCopyRotates );
-	msg->addUUIDFast(_PREHASH_RayTargetID, data->mRayTargetID );
-	msg->addU32Fast(_PREHASH_DuplicateFlags, data->mFlags );
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
+    msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupForRezzing() );
+    msg->addVector3Fast(_PREHASH_RayStart, data->mRayStartRegion );
+    msg->addVector3Fast(_PREHASH_RayEnd, data->mRayEndRegion );
+    msg->addBOOLFast(_PREHASH_BypassRaycast, data->mBypassRaycast );
+    msg->addBOOLFast(_PREHASH_RayEndIsIntersection, data->mRayEndIsIntersection );
+    msg->addBOOLFast(_PREHASH_CopyCenters, data->mCopyCenters );
+    msg->addBOOLFast(_PREHASH_CopyRotates, data->mCopyRotates );
+    msg->addUUIDFast(_PREHASH_RayTargetID, data->mRayTargetID );
+    msg->addU32Fast(_PREHASH_DuplicateFlags, data->mFlags );
 }
 
 
@@ -4490,61 +4490,61 @@ void LLSelectMgr::packDuplicateOnRayHead(void *user_data)
 
 void LLSelectMgr::sendMultipleUpdate(U32 type)
 {
-	if (type == UPD_NONE) return;
-	// send individual updates when selecting textures or individual objects
-	ESendType send_type = (!ALControlCache::EditLinkedParts && !getTEMode()) ? SEND_ONLY_ROOTS : SEND_ROOTS_FIRST;
-	if (send_type == SEND_ONLY_ROOTS)
-	{
-		// tell simulator to apply to whole linked sets
-		type |= UPD_LINKED_SETS;
-	}
-
-	sendListToRegions(
-		"MultipleObjectUpdate",
-		packAgentAndSessionID,
-		packMultipleUpdate,
+    if (type == UPD_NONE) return;
+    // send individual updates when selecting textures or individual objects
+    ESendType send_type = (!ALControlCache::EditLinkedParts && !getTEMode()) ? SEND_ONLY_ROOTS : SEND_ROOTS_FIRST;
+    if (send_type == SEND_ONLY_ROOTS)
+    {
+        // tell simulator to apply to whole linked sets
+        type |= UPD_LINKED_SETS;
+    }
+
+    sendListToRegions(
+        "MultipleObjectUpdate",
+        packAgentAndSessionID,
+        packMultipleUpdate,
         logNoOp,
-		&type,
-		send_type);
+        &type,
+        send_type);
 }
 
 // static
 void LLSelectMgr::packMultipleUpdate(LLSelectNode* node, void *user_data)
 {
-	LLViewerObject* object = node->getObject();
-	U32	*type32 = (U32 *)user_data;
-	U8 type = (U8)*type32;
-	U8	data[256];
-
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID,	object->getLocalID() );
-	gMessageSystem->addU8Fast(_PREHASH_Type, type );
-
-	S32 offset = 0;
-
-	// JC: You MUST pack the data in this order.  The receiving
-	// routine process_multiple_update_message on simulator will
-	// extract them in this order.
-
-	if (type & UPD_POSITION)
-	{
-		htolememcpy(&data[offset], &(object->getPosition().mV), MVT_LLVector3, 12); 
-		offset += 12;
-	}
-	if (type & UPD_ROTATION)
-	{
-		LLQuaternion quat = object->getRotation();
-		LLVector3 vec = quat.packToVector3();
-		htolememcpy(&data[offset], &(vec.mV), MVT_LLQuaternion, 12); 
-		offset += 12;
-	}
-	if (type & UPD_SCALE)
-	{
-		//LL_INFOS() << "Sending object scale " << object->getScale() << LL_ENDL;
-		htolememcpy(&data[offset], &(object->getScale().mV), MVT_LLVector3, 12); 
-		offset += 12;
-	}
-	gMessageSystem->addBinaryDataFast(_PREHASH_Data, data, offset);
+    LLViewerObject* object = node->getObject();
+    U32 *type32 = (U32 *)user_data;
+    U8 type = (U8)*type32;
+    U8  data[256];
+
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID,  object->getLocalID() );
+    gMessageSystem->addU8Fast(_PREHASH_Type, type );
+
+    S32 offset = 0;
+
+    // JC: You MUST pack the data in this order.  The receiving
+    // routine process_multiple_update_message on simulator will
+    // extract them in this order.
+
+    if (type & UPD_POSITION)
+    {
+        htolememcpy(&data[offset], &(object->getPosition().mV), MVT_LLVector3, 12);
+        offset += 12;
+    }
+    if (type & UPD_ROTATION)
+    {
+        LLQuaternion quat = object->getRotation();
+        LLVector3 vec = quat.packToVector3();
+        htolememcpy(&data[offset], &(vec.mV), MVT_LLQuaternion, 12);
+        offset += 12;
+    }
+    if (type & UPD_SCALE)
+    {
+        //LL_INFOS() << "Sending object scale " << object->getScale() << LL_ENDL;
+        htolememcpy(&data[offset], &(object->getScale().mV), MVT_LLVector3, 12);
+        offset += 12;
+    }
+    gMessageSystem->addBinaryDataFast(_PREHASH_Data, data, offset);
 }
 
 //------------------------------------------------------------------------
@@ -4552,36 +4552,36 @@ void LLSelectMgr::packMultipleUpdate(LLSelectNode* node, void *user_data)
 //------------------------------------------------------------------------
 struct LLOwnerData
 {
-	LLUUID	owner_id;
-	LLUUID	group_id;
-	BOOL	override;
+    LLUUID  owner_id;
+    LLUUID  group_id;
+    BOOL    override;
 };
 
 void LLSelectMgr::sendOwner(const LLUUID& owner_id,
-							const LLUUID& group_id,
-							BOOL override)
+                            const LLUUID& group_id,
+                            BOOL override)
 {
-	LLOwnerData data;
+    LLOwnerData data;
 
-	data.owner_id = owner_id;
-	data.group_id = group_id;
-	data.override = override;
+    data.owner_id = owner_id;
+    data.group_id = group_id;
+    data.override = override;
 
-	sendListToRegions("ObjectOwner", packOwnerHead, packObjectLocalID, logNoOp, &data, SEND_ONLY_ROOTS);
+    sendListToRegions("ObjectOwner", packOwnerHead, packObjectLocalID, logNoOp, &data, SEND_ONLY_ROOTS);
 }
 
 // static
 void LLSelectMgr::packOwnerHead(void *user_data)
 {
-	LLOwnerData *data = (LLOwnerData *)user_data;
+    LLOwnerData *data = (LLOwnerData *)user_data;
 
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
-	gMessageSystem->nextBlockFast(_PREHASH_HeaderData);
-	gMessageSystem->addBOOLFast(_PREHASH_Override, data->override);
-	gMessageSystem->addUUIDFast(_PREHASH_OwnerID, data->owner_id);
-	gMessageSystem->addUUIDFast(_PREHASH_GroupID, data->group_id);
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
+    gMessageSystem->nextBlockFast(_PREHASH_HeaderData);
+    gMessageSystem->addBOOLFast(_PREHASH_Override, data->override);
+    gMessageSystem->addUUIDFast(_PREHASH_OwnerID, data->owner_id);
+    gMessageSystem->addUUIDFast(_PREHASH_GroupID, data->group_id);
 }
 
 //------------------------------------------------------------------------
@@ -4590,8 +4590,8 @@ void LLSelectMgr::packOwnerHead(void *user_data)
 
 void LLSelectMgr::sendGroup(const LLUUID& group_id)
 {
-	LLUUID local_group_id(group_id);
-	sendListToRegions("ObjectGroup", packAgentAndSessionAndGroupID, packObjectLocalID, logNoOp, &local_group_id, SEND_ONLY_ROOTS);
+    LLUUID local_group_id(group_id);
+    sendListToRegions("ObjectGroup", packAgentAndSessionAndGroupID, packObjectLocalID, logNoOp, &local_group_id, SEND_ONLY_ROOTS);
 }
 
 
@@ -4601,9 +4601,9 @@ void LLSelectMgr::sendGroup(const LLUUID& group_id)
 
 struct LLBuyData
 {
-	std::vector<LLViewerObject*> mObjectsSent;
-	LLUUID mCategoryID;
-	LLSaleInfo mSaleInfo;
+    std::vector<LLViewerObject*> mObjectsSent;
+    LLUUID mCategoryID;
+    LLSaleInfo mSaleInfo;
 };
 
 // *NOTE: does not work for multiple object buy, which UI does not
@@ -4612,26 +4612,26 @@ struct LLBuyData
 // info -as displayed in the UI- for every item.
 void LLSelectMgr::sendBuy(const LLUUID& buyer_id, const LLUUID& category_id, const LLSaleInfo sale_info)
 {
-	LLBuyData buy;
-	buy.mCategoryID = category_id;
-	buy.mSaleInfo = sale_info;
-	sendListToRegions("ObjectBuy", packAgentGroupAndCatID, packBuyObjectIDs, logNoOp, &buy, SEND_ONLY_ROOTS);
+    LLBuyData buy;
+    buy.mCategoryID = category_id;
+    buy.mSaleInfo = sale_info;
+    sendListToRegions("ObjectBuy", packAgentGroupAndCatID, packBuyObjectIDs, logNoOp, &buy, SEND_ONLY_ROOTS);
 }
 
 // static
 void LLSelectMgr::packBuyObjectIDs(LLSelectNode* node, void* data)
 {
-	LLBuyData* buy = (LLBuyData*)data;
+    LLBuyData* buy = (LLBuyData*)data;
 
-	LLViewerObject* object = node->getObject();
-	if (std::find(buy->mObjectsSent.begin(), buy->mObjectsSent.end(), object) == buy->mObjectsSent.end())
-	{
-		buy->mObjectsSent.push_back(object);
-		gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-		gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID() );
-		gMessageSystem->addU8Fast(_PREHASH_SaleType, buy->mSaleInfo.getSaleType());
-		gMessageSystem->addS32Fast(_PREHASH_SalePrice, buy->mSaleInfo.getSalePrice());
-	}
+    LLViewerObject* object = node->getObject();
+    if (std::find(buy->mObjectsSent.begin(), buy->mObjectsSent.end(), object) == buy->mObjectsSent.end())
+    {
+        buy->mObjectsSent.push_back(object);
+        gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+        gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID() );
+        gMessageSystem->addU8Fast(_PREHASH_SaleType, buy->mSaleInfo.getSaleType());
+        gMessageSystem->addS32Fast(_PREHASH_SalePrice, buy->mSaleInfo.getSalePrice());
+    }
 }
 
 //------------------------------------------------------------------------
@@ -4640,37 +4640,37 @@ void LLSelectMgr::packBuyObjectIDs(LLSelectNode* node, void* data)
 
 struct LLPermData
 {
-	U8 mField;
-	BOOL mSet;
-	U32 mMask;
-	BOOL mOverride;
+    U8 mField;
+    BOOL mSet;
+    U32 mMask;
+    BOOL mOverride;
 };
 
 // TODO: Make this able to fail elegantly.
 void LLSelectMgr::selectionSetObjectPermissions(U8 field,
-									   BOOL set,
-									   U32 mask,
-									   BOOL override)
+                                       BOOL set,
+                                       U32 mask,
+                                       BOOL override)
 {
-	LLPermData data;
+    LLPermData data;
 
-	data.mField = field;
-	data.mSet = set;
-	data.mMask = mask;
-	data.mOverride = override;
+    data.mField = field;
+    data.mSet = set;
+    data.mMask = mask;
+    data.mOverride = override;
 
-	sendListToRegions("ObjectPermissions", packPermissionsHead, packPermissions, logNoOp, &data, SEND_ONLY_ROOTS);
+    sendListToRegions("ObjectPermissions", packPermissionsHead, packPermissions, logNoOp, &data, SEND_ONLY_ROOTS);
 }
 
 void LLSelectMgr::packPermissionsHead(void* user_data)
 {
-	LLPermData* data = (LLPermData*)user_data;
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->nextBlockFast(_PREHASH_HeaderData);
-	gMessageSystem->addBOOLFast(_PREHASH_Override, data->mOverride);
-}	
+    LLPermData* data = (LLPermData*)user_data;
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->nextBlockFast(_PREHASH_HeaderData);
+    gMessageSystem->addBOOLFast(_PREHASH_Override, data->mOverride);
+}
 
 
 // Now that you've added a bunch of objects, send a select message
@@ -4678,235 +4678,235 @@ void LLSelectMgr::packPermissionsHead(void* user_data)
 /*
 void LLSelectMgr::sendSelect()
 {
-	LL_ERRS() << "Not implemented" << LL_ENDL;
+    LL_ERRS() << "Not implemented" << LL_ENDL;
 }
 */
 
 void LLSelectMgr::deselectAll()
 {
-	if (!mSelectedObjects->getNumNodes())
-	{
-		return;
-	}
-		
-	// Zap the angular velocity, as the sim will set it to zero
-	for (LLSelectNode* node : mSelectedObjects->begin_end())
-	{
-		LLViewerObject *objectp = node->getObject();
-		objectp->setAngularVelocity( 0,0,0 );
-		objectp->setVelocity( 0,0,0 );
-	}
-
-	sendListToRegions(
-		"ObjectDeselect",
-		packAgentAndSessionID,
-		packObjectLocalID,
+    if (!mSelectedObjects->getNumNodes())
+    {
+        return;
+    }
+
+    // Zap the angular velocity, as the sim will set it to zero
+    for (LLSelectNode* node : mSelectedObjects->begin_end())
+    {
+        LLViewerObject *objectp = node->getObject();
+        objectp->setAngularVelocity( 0,0,0 );
+        objectp->setVelocity( 0,0,0 );
+    }
+
+    sendListToRegions(
+        "ObjectDeselect",
+        packAgentAndSessionID,
+        packObjectLocalID,
         logNoOp,
-		NULL,
-		SEND_INDIVIDUALS);
+        NULL,
+        SEND_INDIVIDUALS);
+
+    removeAll();
 
-	removeAll();
-	
-	mLastSentSelectionCenterGlobal.clearVec();
+    mLastSentSelectionCenterGlobal.clearVec();
 
-	updatePointAt();
+    updatePointAt();
 }
 
 void LLSelectMgr::deselectAllForStandingUp()
 {
-	/*
-	This function is similar deselectAll() except for the first if statement
-	which was removed. This is needed as a workaround for DEV-2854
-	*/
-
-	// Zap the angular velocity, as the sim will set it to zero
-	for (LLSelectNode* node : mSelectedObjects->begin_end())
-	{
-		LLViewerObject *objectp = node->getObject();
-		objectp->setAngularVelocity( 0,0,0 );
-		objectp->setVelocity( 0,0,0 );
-	}
-
-	sendListToRegions(
-		"ObjectDeselect",
-		packAgentAndSessionID,
-		packObjectLocalID,
+    /*
+    This function is similar deselectAll() except for the first if statement
+    which was removed. This is needed as a workaround for DEV-2854
+    */
+
+    // Zap the angular velocity, as the sim will set it to zero
+    for (LLSelectNode* node : mSelectedObjects->begin_end())
+    {
+        LLViewerObject *objectp = node->getObject();
+        objectp->setAngularVelocity( 0,0,0 );
+        objectp->setVelocity( 0,0,0 );
+    }
+
+    sendListToRegions(
+        "ObjectDeselect",
+        packAgentAndSessionID,
+        packObjectLocalID,
         logNoOp,
-		NULL,
-		SEND_INDIVIDUALS);
+        NULL,
+        SEND_INDIVIDUALS);
+
+    removeAll();
 
-	removeAll();
-	
-	mLastSentSelectionCenterGlobal.clearVec();
+    mLastSentSelectionCenterGlobal.clearVec();
 
-	updatePointAt();
+    updatePointAt();
 }
 
 void LLSelectMgr::deselectUnused()
 {
-	// no more outstanding references to this selection
-	if (mSelectedObjects->getNumRefs() == 1)
-	{
-		deselectAll();
-	}
+    // no more outstanding references to this selection
+    if (mSelectedObjects->getNumRefs() == 1)
+    {
+        deselectAll();
+    }
 }
 
 void LLSelectMgr::convertTransient()
 {
-	for (LLSelectNode* nodep : mSelectedObjects->begin_end())
-	{
-		nodep->setTransient(FALSE);
-	}
+    for (LLSelectNode* nodep : mSelectedObjects->begin_end())
+    {
+        nodep->setTransient(FALSE);
+    }
 }
 
 void LLSelectMgr::deselectAllIfTooFar()
 {
 // [RLVa:KB] - @edit*
-	// Continuously verify the selection as soon as there is at least one prim we shouldn't be able to edit
-	if ( !mSelectedObjects->isEmpty() && RlvActions::isRlvEnabled() && !RlvActions::canEdit(ERlvCheckType::All) )
-	{
-		struct NotTransientOrFocusedMediaOrEditable : public LLSelectedNodeFunctor
-		{
-			bool apply(LLSelectNode* pNode)
-			{
-				const LLViewerObject* pObj = pNode->getObject();
-				return (!pNode->isTransient()) && (pObj) && (!RlvActions::canEdit(pObj)) && (pObj->getID() != LLViewerMediaFocus::getInstance()->getFocusedObjectID());
-			}
-		} f;
-		if (mSelectedObjects->getFirstRootNode(&f, TRUE))
-			deselectAll();
-	}
+    // Continuously verify the selection as soon as there is at least one prim we shouldn't be able to edit
+    if ( !mSelectedObjects->isEmpty() && RlvActions::isRlvEnabled() && !RlvActions::canEdit(ERlvCheckType::All) )
+    {
+        struct NotTransientOrFocusedMediaOrEditable : public LLSelectedNodeFunctor
+        {
+            bool apply(LLSelectNode* pNode)
+            {
+                const LLViewerObject* pObj = pNode->getObject();
+                return (!pNode->isTransient()) && (pObj) && (!RlvActions::canEdit(pObj)) && (pObj->getID() != LLViewerMediaFocus::getInstance()->getFocusedObjectID());
+            }
+        } f;
+        if (mSelectedObjects->getFirstRootNode(&f, TRUE))
+            deselectAll();
+    }
 // [/RLVa:KB]
 
-	if (mSelectedObjects->isEmpty() || mSelectedObjects->mSelectType == SELECT_TYPE_HUD)
-	{
-		return;
-	}
+    if (mSelectedObjects->isEmpty() || mSelectedObjects->mSelectType == SELECT_TYPE_HUD)
+    {
+        return;
+    }
 
 // [RLVa:KB] - Checked: RLVa-1.2.0
-	// [Fall-back code] Don't allow an active selection (except for HUD attachments - see above) when @interact restricted
-	if (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT))
-	{
-		deselectAll();
-		return;
-	}
+    // [Fall-back code] Don't allow an active selection (except for HUD attachments - see above) when @interact restricted
+    if (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT))
+    {
+        deselectAll();
+        return;
+    }
 // [/RLVa:KB]
 
-	// HACK: Don't deselect when we're navigating to rate an object's
-	// owner or creator.  JC
-	if (gMenuObject->getVisible())
-	{
-		return;
-	}
+    // HACK: Don't deselect when we're navigating to rate an object's
+    // owner or creator.  JC
+    if (gMenuObject->getVisible())
+    {
+        return;
+    }
 
-	LLVector3d selectionCenter = getSelectionCenterGlobal();
-//	if (gSavedSettings.getBOOL("LimitSelectDistance")
+    LLVector3d selectionCenter = getSelectionCenterGlobal();
+//  if (gSavedSettings.getBOOL("LimitSelectDistance")
 // [RLVa:KB] - Checked: 2010-04-11 (RLVa-1.2.0e) | Modified: RLVa-0.2.0f
-	static RlvCachedBehaviourModifier<float> s_nFartouchDist(RLV_MODIFIER_FARTOUCHDIST);
+    static RlvCachedBehaviourModifier<float> s_nFartouchDist(RLV_MODIFIER_FARTOUCHDIST);
 
-	BOOL fRlvFartouch = gRlvHandler.hasBehaviour(RLV_BHVR_FARTOUCH) && LLToolMgr::instance().inEdit();
-	if ( (ALControlCache::LimitSelectDistance || (fRlvFartouch) )
+    BOOL fRlvFartouch = gRlvHandler.hasBehaviour(RLV_BHVR_FARTOUCH) && LLToolMgr::instance().inEdit();
+    if ( (ALControlCache::LimitSelectDistance || (fRlvFartouch) )
 // [/RLVa:KB]
-		&& (!mSelectedObjects->getPrimaryObject() || !mSelectedObjects->getPrimaryObject()->isAvatar())
-		&& (mSelectedObjects->getPrimaryObject() != LLViewerMediaFocus::getInstance()->getFocusedObject())
-		&& !mSelectedObjects->isAttachment()
-		&& !selectionCenter.isExactlyZero())
-	{
-//		F32 deselect_dist = ALControlCache::MaxSelectDistance;
+        && (!mSelectedObjects->getPrimaryObject() || !mSelectedObjects->getPrimaryObject()->isAvatar())
+        && (mSelectedObjects->getPrimaryObject() != LLViewerMediaFocus::getInstance()->getFocusedObject())
+        && !mSelectedObjects->isAttachment()
+        && !selectionCenter.isExactlyZero())
+    {
+//      F32 deselect_dist = ALControlCache::MaxSelectDistance;
 // [RLVa:KB] - Checked: 2010-04-11 (RLVa-1.2.0e) | Modified: RLVa-0.2.0f
-		F32 deselect_dist = (!fRlvFartouch) ? ALControlCache::MaxSelectDistance : s_nFartouchDist;
+        F32 deselect_dist = (!fRlvFartouch) ? ALControlCache::MaxSelectDistance : s_nFartouchDist;
 // [/RLVa:KB]
-		F32 deselect_dist_sq = deselect_dist * deselect_dist;
+        F32 deselect_dist_sq = deselect_dist * deselect_dist;
 
-		LLVector3d select_delta = gAgent.getPositionGlobal() - selectionCenter;
-		F32 select_dist_sq = (F32) select_delta.magVecSquared();
+        LLVector3d select_delta = gAgent.getPositionGlobal() - selectionCenter;
+        F32 select_dist_sq = (F32) select_delta.magVecSquared();
 
-		if (select_dist_sq > deselect_dist_sq)
-		{
-			if (mDebugSelectMgr)
-			{
-				LL_INFOS() << "Selection manager: auto-deselecting, select_dist = " << (F32) sqrt(select_dist_sq) << LL_ENDL;
-				LL_INFOS() << "agent pos global = " << gAgent.getPositionGlobal() << LL_ENDL;
-				LL_INFOS() << "selection pos global = " << selectionCenter << LL_ENDL;
-			}
+        if (select_dist_sq > deselect_dist_sq)
+        {
+            if (mDebugSelectMgr)
+            {
+                LL_INFOS() << "Selection manager: auto-deselecting, select_dist = " << (F32) sqrt(select_dist_sq) << LL_ENDL;
+                LL_INFOS() << "agent pos global = " << gAgent.getPositionGlobal() << LL_ENDL;
+                LL_INFOS() << "selection pos global = " << selectionCenter << LL_ENDL;
+            }
 
-			deselectAll();
-		}
-	}
+            deselectAll();
+        }
+    }
 }
 
 
 void LLSelectMgr::selectionSetObjectName(const std::string& name)
 {
-	std::string name_copy(name);
+    std::string name_copy(name);
 
-	// we only work correctly if 1 object is selected.
-	if(mSelectedObjects->getRootObjectCount() >= 1)
-	{
-		sendListToRegions("ObjectName",
-						  packAgentAndSessionID,
-						  packObjectName,
+    // we only work correctly if 1 object is selected.
+    if(mSelectedObjects->getRootObjectCount() >= 1)
+    {
+        sendListToRegions("ObjectName",
+                          packAgentAndSessionID,
+                          packObjectName,
                           logNoOp,
-						  (void*)(&name_copy),
-						  SEND_ONLY_ROOTS);
-	}
-	else if(mSelectedObjects->getObjectCount() >= 1)
-	{
-		sendListToRegions("ObjectName",
-						  packAgentAndSessionID,
-						  packObjectName,
+                          (void*)(&name_copy),
+                          SEND_ONLY_ROOTS);
+    }
+    else if(mSelectedObjects->getObjectCount() >= 1)
+    {
+        sendListToRegions("ObjectName",
+                          packAgentAndSessionID,
+                          packObjectName,
                           logNoOp,
-						  (void*)(&name_copy),
-						  SEND_INDIVIDUALS);
-	}
+                          (void*)(&name_copy),
+                          SEND_INDIVIDUALS);
+    }
 }
 
 void LLSelectMgr::selectionSetObjectDescription(const std::string& desc)
 {
-	std::string desc_copy(desc);
+    std::string desc_copy(desc);
 
-	// we only work correctly if 1 object is selected.
-	if(mSelectedObjects->getRootObjectCount() >= 1)
-	{
-		sendListToRegions("ObjectDescription",
-						  packAgentAndSessionID,
-						  packObjectDescription,
+    // we only work correctly if 1 object is selected.
+    if(mSelectedObjects->getRootObjectCount() >= 1)
+    {
+        sendListToRegions("ObjectDescription",
+                          packAgentAndSessionID,
+                          packObjectDescription,
                           logNoOp,
-						  (void*)(&desc_copy),
-						  SEND_ONLY_ROOTS);
-	}
-	else if(mSelectedObjects->getObjectCount() >= 1)
-	{
-		sendListToRegions("ObjectDescription",
-						  packAgentAndSessionID,
-						  packObjectDescription,
+                          (void*)(&desc_copy),
+                          SEND_ONLY_ROOTS);
+    }
+    else if(mSelectedObjects->getObjectCount() >= 1)
+    {
+        sendListToRegions("ObjectDescription",
+                          packAgentAndSessionID,
+                          packObjectDescription,
                           logNoOp,
-						  (void*)(&desc_copy),
-						  SEND_INDIVIDUALS);
-	}
+                          (void*)(&desc_copy),
+                          SEND_INDIVIDUALS);
+    }
 }
 
 void LLSelectMgr::selectionSetObjectCategory(const LLCategory& category)
 {
-	// for now, we only want to be able to set one root category at
-	// a time.
-	if(mSelectedObjects->getRootObjectCount() != 1) return;
-	sendListToRegions("ObjectCategory",
-					  packAgentAndSessionID,
-					  packObjectCategory,
+    // for now, we only want to be able to set one root category at
+    // a time.
+    if(mSelectedObjects->getRootObjectCount() != 1) return;
+    sendListToRegions("ObjectCategory",
+                      packAgentAndSessionID,
+                      packObjectCategory,
                       logNoOp,
-					  (void*)(&category),
-					  SEND_ONLY_ROOTS);
+                      (void*)(&category),
+                      SEND_ONLY_ROOTS);
 }
 
 void LLSelectMgr::selectionSetObjectSaleInfo(const LLSaleInfo& sale_info)
 {
-	sendListToRegions("ObjectSaleInfo",
-					  packAgentAndSessionID,
-					  packObjectSaleInfo,
+    sendListToRegions("ObjectSaleInfo",
+                      packAgentAndSessionID,
+                      packObjectSaleInfo,
                       logNoOp,
-					  (void*)(&sale_info),
-					  SEND_ONLY_ROOTS);
+                      (void*)(&sale_info),
+                      SEND_ONLY_ROOTS);
 }
 
 //----------------------------------------------------------------------
@@ -4920,80 +4920,80 @@ void LLSelectMgr::sendAttach(U8 attachment_point, bool replace)
 
 void LLSelectMgr::sendAttach(LLObjectSelectionHandle selection_handle, U8 attachment_point, bool replace)
 {
-	if (selection_handle.isNull())
-	{
-		return;
-	}
-
-	LLViewerObject* attach_object = selection_handle->getFirstRootObject();
-
-	if (!attach_object || !isAgentAvatarValid() || selection_handle->mSelectType != SELECT_TYPE_WORLD)
-	{
-		return;
-	}
-
-	BOOL build_mode = LLToolMgr::getInstance()->inEdit();
-	// Special case: Attach to default location for this object.
-	if (0 == attachment_point ||
-		get_if_there(gAgentAvatarp->mAttachmentPoints, (S32)attachment_point, (LLViewerJointAttachment*)NULL))
-	{
-		if (!replace || attachment_point != 0)
-		{
-			// If we know the attachment point then we got here by clicking an
-			// "Attach to..." context menu item, so we should add, not replace.
-			attachment_point |= ATTACHMENT_ADD;
-		}
-
-		sendListToRegions(
-			selection_handle,
-			"ObjectAttach",
-			packAgentIDAndSessionAndAttachment, 
-			packObjectIDAndRotation, 
+    if (selection_handle.isNull())
+    {
+        return;
+    }
+
+    LLViewerObject* attach_object = selection_handle->getFirstRootObject();
+
+    if (!attach_object || !isAgentAvatarValid() || selection_handle->mSelectType != SELECT_TYPE_WORLD)
+    {
+        return;
+    }
+
+    BOOL build_mode = LLToolMgr::getInstance()->inEdit();
+    // Special case: Attach to default location for this object.
+    if (0 == attachment_point ||
+        get_if_there(gAgentAvatarp->mAttachmentPoints, (S32)attachment_point, (LLViewerJointAttachment*)NULL))
+    {
+        if (!replace || attachment_point != 0)
+        {
+            // If we know the attachment point then we got here by clicking an
+            // "Attach to..." context menu item, so we should add, not replace.
+            attachment_point |= ATTACHMENT_ADD;
+        }
+
+        sendListToRegions(
+            selection_handle,
+            "ObjectAttach",
+            packAgentIDAndSessionAndAttachment,
+            packObjectIDAndRotation,
             logAttachmentRequest,
-			&attachment_point, 
-			SEND_ONLY_ROOTS );
-		if (!build_mode)
-		{
-			// After "ObjectAttach" server will unsubscribe us from properties updates
-			// so either deselect objects or resend selection after attach packet reaches server
-			// In case of build_mode LLPanelObjectInventory::refresh() will deal with selection
-			// Still unsubscribe even in case selection_handle is not current selection
-			deselectAll();
-		}
-	}
+            &attachment_point,
+            SEND_ONLY_ROOTS );
+        if (!build_mode)
+        {
+            // After "ObjectAttach" server will unsubscribe us from properties updates
+            // so either deselect objects or resend selection after attach packet reaches server
+            // In case of build_mode LLPanelObjectInventory::refresh() will deal with selection
+            // Still unsubscribe even in case selection_handle is not current selection
+            deselectAll();
+        }
+    }
 }
 
 void LLSelectMgr::sendDetach()
 {
-	if (!mSelectedObjects->getNumNodes() || mSelectedObjects->mSelectType == SELECT_TYPE_WORLD)
-	{
-		return;
-	}
+    if (!mSelectedObjects->getNumNodes() || mSelectedObjects->mSelectType == SELECT_TYPE_WORLD)
+    {
+        return;
+    }
 
-	sendListToRegions(
-		"ObjectDetach",
-		packAgentAndSessionID,
-		packObjectLocalID,
+    sendListToRegions(
+        "ObjectDetach",
+        packAgentAndSessionID,
+        packObjectLocalID,
         logDetachRequest,
-		NULL,
-		SEND_ONLY_ROOTS );
+        NULL,
+        SEND_ONLY_ROOTS );
 }
 
 
 void LLSelectMgr::sendDropAttachment()
 {
-	if (!mSelectedObjects->getNumNodes() || mSelectedObjects->mSelectType == SELECT_TYPE_WORLD)
-	{
-		return;
-	}
+    if (!mSelectedObjects->getNumNodes() || mSelectedObjects->mSelectType == SELECT_TYPE_WORLD)
+    {
+        return;
+    }
 
-	sendListToRegions(
-		"ObjectDrop",
-		packAgentAndSessionID,
-		packObjectLocalID,
+    sendListToRegions(
+        "ObjectDrop",
+        packAgentAndSessionID,
+        packObjectLocalID,
         logDetachRequest,
-		NULL,
-		SEND_ONLY_ROOTS);
+        NULL,
+        SEND_ONLY_ROOTS);
 }
 
 //----------------------------------------------------------------------
@@ -5002,56 +5002,56 @@ void LLSelectMgr::sendDropAttachment()
 
 void LLSelectMgr::sendLink()
 {
-	if (!mSelectedObjects->getNumNodes())
-	{
-		return;
-	}
+    if (!mSelectedObjects->getNumNodes())
+    {
+        return;
+    }
 
-	sendListToRegions(
-		"ObjectLink",
-		packAgentAndSessionID,
-		packObjectLocalID,
+    sendListToRegions(
+        "ObjectLink",
+        packAgentAndSessionID,
+        packObjectLocalID,
         logNoOp,
-		NULL,
-		SEND_ONLY_ROOTS);
+        NULL,
+        SEND_ONLY_ROOTS);
 }
 
 void LLSelectMgr::sendDelink()
 {
-	if (!mSelectedObjects->getNumNodes())
-	{
-		return;
-	}
-
-	struct f : public LLSelectedObjectFunctor
-	{ //on delink, any modifyable object should
-		f() {}
-
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (object->permModify())
-			{
-				if (object->getPhysicsShapeType() == LLViewerObject::PHYSICS_SHAPE_NONE)
-				{
-					object->setPhysicsShapeType(LLViewerObject::PHYSICS_SHAPE_CONVEX_HULL);
-					object->updateFlags();
-				}
-			}
-			return true;
-		}
-	} sendfunc;
-	getSelection()->applyToObjects(&sendfunc);
-
-
-	// Delink needs to send individuals so you can unlink a single object from
-	// a linked set.
-	sendListToRegions(
-		"ObjectDelink",
-		packAgentAndSessionID,
-		packObjectLocalID,
+    if (!mSelectedObjects->getNumNodes())
+    {
+        return;
+    }
+
+    struct f : public LLSelectedObjectFunctor
+    { //on delink, any modifyable object should
+        f() {}
+
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (object->permModify())
+            {
+                if (object->getPhysicsShapeType() == LLViewerObject::PHYSICS_SHAPE_NONE)
+                {
+                    object->setPhysicsShapeType(LLViewerObject::PHYSICS_SHAPE_CONVEX_HULL);
+                    object->updateFlags();
+                }
+            }
+            return true;
+        }
+    } sendfunc;
+    getSelection()->applyToObjects(&sendfunc);
+
+
+    // Delink needs to send individuals so you can unlink a single object from
+    // a linked set.
+    sendListToRegions(
+        "ObjectDelink",
+        packAgentAndSessionID,
+        packObjectLocalID,
         logNoOp,
-		NULL,
-		SEND_INDIVIDUALS);
+        NULL,
+        SEND_INDIVIDUALS);
 }
 
 
@@ -5062,118 +5062,118 @@ void LLSelectMgr::sendDelink()
 /*
 void LLSelectMgr::sendHinge(U8 type)
 {
-	if (!mSelectedObjects->getNumNodes())
-	{
-		return;
-	}
+    if (!mSelectedObjects->getNumNodes())
+    {
+        return;
+    }
 
-	sendListToRegions(
-		"ObjectHinge",
-		packHingeHead,
-		packObjectLocalID,
-		&type,
-		SEND_ONLY_ROOTS);
+    sendListToRegions(
+        "ObjectHinge",
+        packHingeHead,
+        packObjectLocalID,
+        &type,
+        SEND_ONLY_ROOTS);
 }
 
 
 void LLSelectMgr::sendDehinge()
 {
-	if (!mSelectedObjects->getNumNodes())
-	{
-		return;
-	}
-
-	sendListToRegions(
-		"ObjectDehinge",
-		packAgentAndSessionID,
-		packObjectLocalID,
-		NULL,
-		SEND_ONLY_ROOTS);
+    if (!mSelectedObjects->getNumNodes())
+    {
+        return;
+    }
+
+    sendListToRegions(
+        "ObjectDehinge",
+        packAgentAndSessionID,
+        packObjectLocalID,
+        NULL,
+        SEND_ONLY_ROOTS);
 }*/
 
 void LLSelectMgr::sendSelect()
 {
-	if (!mSelectedObjects->getNumNodes())
-	{
-		return;
-	}
+    if (!mSelectedObjects->getNumNodes())
+    {
+        return;
+    }
 
-	sendListToRegions(
-		"ObjectSelect",
-		packAgentAndSessionID,
-		packObjectLocalID,
+    sendListToRegions(
+        "ObjectSelect",
+        packAgentAndSessionID,
+        packObjectLocalID,
         logNoOp,
-		NULL,
-		SEND_INDIVIDUALS);
+        NULL,
+        SEND_INDIVIDUALS);
 }
 
 // static
 void LLSelectMgr::packHingeHead(void *user_data)
 {
-	U8	*type = (U8 *)user_data;
+    U8  *type = (U8 *)user_data;
 
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
-	gMessageSystem->nextBlockFast(_PREHASH_JointType);
-	gMessageSystem->addU8Fast(_PREHASH_Type, *type );
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID() );
+    gMessageSystem->nextBlockFast(_PREHASH_JointType);
+    gMessageSystem->addU8Fast(_PREHASH_Type, *type );
 }
 
 
 void LLSelectMgr::selectionDump()
 {
-	struct f : public LLSelectedObjectFunctor
-	{
-		virtual bool apply(LLViewerObject* object)
-		{
-			object->dump();
-			return true;
-		}
-	} func;
-	getSelection()->applyToObjects(&func);	
+    struct f : public LLSelectedObjectFunctor
+    {
+        virtual bool apply(LLViewerObject* object)
+        {
+            object->dump();
+            return true;
+        }
+    } func;
+    getSelection()->applyToObjects(&func);
 }
 
 void LLSelectMgr::saveSelectedObjectColors()
 {
-	struct f : public LLSelectedNodeFunctor
-	{
-		virtual bool apply(LLSelectNode* node)
-		{
-			node->saveColors();
-			return true;
-		}
-	} func;
-	getSelection()->applyToNodes(&func);	
+    struct f : public LLSelectedNodeFunctor
+    {
+        virtual bool apply(LLSelectNode* node)
+        {
+            node->saveColors();
+            return true;
+        }
+    } func;
+    getSelection()->applyToNodes(&func);
 }
 
 void LLSelectMgr::saveSelectedShinyColors()
 {
-	struct f : public LLSelectedNodeFunctor
-	{
-		virtual bool apply(LLSelectNode* node)
-		{
-			node->saveShinyColors();
-			return true;
-		}
-	} func;
-	getSelection()->applyToNodes(&func);
+    struct f : public LLSelectedNodeFunctor
+    {
+        virtual bool apply(LLSelectNode* node)
+        {
+            node->saveShinyColors();
+            return true;
+        }
+    } func;
+    getSelection()->applyToNodes(&func);
 }
 
 void LLSelectMgr::saveSelectedObjectTextures()
 {
-	// invalidate current selection so we update saved textures
-	struct f : public LLSelectedNodeFunctor
-	{
-		virtual bool apply(LLSelectNode* node)
-		{
-			node->mValid = FALSE;
-			return true;
-		}
-	} func;
-	getSelection()->applyToNodes(&func);	
+    // invalidate current selection so we update saved textures
+    struct f : public LLSelectedNodeFunctor
+    {
+        virtual bool apply(LLSelectNode* node)
+        {
+            node->mValid = FALSE;
+            return true;
+        }
+    } func;
+    getSelection()->applyToNodes(&func);
 
-	// request object properties message to get updated permissions data
-	sendSelect();
+    // request object properties message to get updated permissions data
+    sendSelect();
 }
 
 
@@ -5181,24 +5181,24 @@ void LLSelectMgr::saveSelectedObjectTextures()
 // also need to know to which simulator to send update message
 void LLSelectMgr::saveSelectedObjectTransform(EActionType action_type)
 {
-	if (mSelectedObjects->isEmpty())
-	{
-		// nothing selected, so nothing to save
-		return;
-	}
-
-	struct f : public LLSelectedNodeFunctor
-	{
-		EActionType mActionType;
-		LLSelectMgr* mManager;
-		f(EActionType a, LLSelectMgr* p) : mActionType(a), mManager(p) {}
-		virtual bool apply(LLSelectNode* selectNode)
-		{
-			LLViewerObject*	object = selectNode->getObject();
-			if (!object)
-			{
-				return true; // skip
-			}
+    if (mSelectedObjects->isEmpty())
+    {
+        // nothing selected, so nothing to save
+        return;
+    }
+
+    struct f : public LLSelectedNodeFunctor
+    {
+        EActionType mActionType;
+        LLSelectMgr* mManager;
+        f(EActionType a, LLSelectMgr* p) : mActionType(a), mManager(p) {}
+        virtual bool apply(LLSelectNode* selectNode)
+        {
+            LLViewerObject* object = selectNode->getObject();
+            if (!object)
+            {
+                return true; // skip
+            }
 
             if (selectNode->mSelectedGLTFNode != -1)
             {
@@ -5250,235 +5250,235 @@ void LLSelectMgr::saveSelectedObjectTransform(EActionType action_type)
                 selectNode->mSavedScale = object->getScale();
                 selectNode->saveTextureScaleRatios(mManager->mTextureChannel);
             }
-			return true;
-		}
-	} func(action_type, this);
-	getSelection()->applyToNodes(&func);	
-	
-	mSavedSelectionBBox = getBBoxOfSelection();
+            return true;
+        }
+    } func(action_type, this);
+    getSelection()->applyToNodes(&func);
+
+    mSavedSelectionBBox = getBBoxOfSelection();
 }
 
 struct LLSelectMgrApplyFlags : public LLSelectedObjectFunctor
 {
-	LLSelectMgrApplyFlags(U32 flags, BOOL state) : mFlags(flags), mState(state) {}
-	U32 mFlags;
-	BOOL mState;
-	virtual bool apply(LLViewerObject* object)
-	{
-		if ( object->permModify())
-		{
-			if (object->isRoot()) 		// don't send for child objects
-			{
-				object->setFlags( mFlags, mState);
-			}
-			else if (FLAGS_WORLD & mFlags && ((LLViewerObject*)object->getRoot())->isSelected())
-			{
-				// FLAGS_WORLD are shared by all items in linkset
-				object->setFlagsWithoutUpdate(FLAGS_WORLD & mFlags, mState);
-			}
-		};
-		return true;
-	}
-};
-
-void LLSelectMgr::selectionUpdatePhysics(BOOL physics)
-{
-	LLSelectMgrApplyFlags func(	FLAGS_USE_PHYSICS, physics);
-	getSelection()->applyToObjects(&func);	
-}
-
+    LLSelectMgrApplyFlags(U32 flags, BOOL state) : mFlags(flags), mState(state) {}
+    U32 mFlags;
+    BOOL mState;
+    virtual bool apply(LLViewerObject* object)
+    {
+        if ( object->permModify())
+        {
+            if (object->isRoot())       // don't send for child objects
+            {
+                object->setFlags( mFlags, mState);
+            }
+            else if (FLAGS_WORLD & mFlags && ((LLViewerObject*)object->getRoot())->isSelected())
+            {
+                // FLAGS_WORLD are shared by all items in linkset
+                object->setFlagsWithoutUpdate(FLAGS_WORLD & mFlags, mState);
+            }
+        };
+        return true;
+    }
+};
+
+void LLSelectMgr::selectionUpdatePhysics(BOOL physics)
+{
+    LLSelectMgrApplyFlags func( FLAGS_USE_PHYSICS, physics);
+    getSelection()->applyToObjects(&func);
+}
+
 void LLSelectMgr::selectionUpdateTemporary(BOOL is_temporary)
 {
-	LLSelectMgrApplyFlags func(	FLAGS_TEMPORARY_ON_REZ, is_temporary);
-	getSelection()->applyToObjects(&func);	
+    LLSelectMgrApplyFlags func( FLAGS_TEMPORARY_ON_REZ, is_temporary);
+    getSelection()->applyToObjects(&func);
 }
 
 void LLSelectMgr::selectionUpdatePhantom(BOOL is_phantom)
 {
-	LLSelectMgrApplyFlags func(	FLAGS_PHANTOM, is_phantom);
-	getSelection()->applyToObjects(&func);	
+    LLSelectMgrApplyFlags func( FLAGS_PHANTOM, is_phantom);
+    getSelection()->applyToObjects(&func);
 }
 
 //----------------------------------------------------------------------
 // Helpful packing functions for sendObjectMessage()
 //----------------------------------------------------------------------
 
-// static 
+// static
 void LLSelectMgr::packAgentIDAndSessionAndAttachment( void *user_data)
 {
-	U8 *attachment_point = (U8*)user_data;
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->addU8Fast(_PREHASH_AttachmentPoint, *attachment_point);
+    U8 *attachment_point = (U8*)user_data;
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->addU8Fast(_PREHASH_AttachmentPoint, *attachment_point);
 }
 
 // static
-void LLSelectMgr::packAgentID(	void *user_data)
+void LLSelectMgr::packAgentID(  void *user_data)
 {
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
 }
 
 // static
 void LLSelectMgr::packAgentAndSessionID(void* user_data)
 {
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
 }
 
 // static
 void LLSelectMgr::packAgentAndGroupID(void* user_data)
 {
-	LLOwnerData *data = (LLOwnerData *)user_data;
+    LLOwnerData *data = (LLOwnerData *)user_data;
 
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, data->owner_id );
-	gMessageSystem->addUUIDFast(_PREHASH_GroupID, data->group_id );
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, data->owner_id );
+    gMessageSystem->addUUIDFast(_PREHASH_GroupID, data->group_id );
 }
 
 // static
 void LLSelectMgr::packAgentAndSessionAndGroupID(void* user_data)
 {
-	LLUUID* group_idp = (LLUUID*) user_data;
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->addUUIDFast(_PREHASH_GroupID, *group_idp);
+    LLUUID* group_idp = (LLUUID*) user_data;
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->addUUIDFast(_PREHASH_GroupID, *group_idp);
 }
 
 // static
 void LLSelectMgr::packDuplicateHeader(void* data)
 {
-	LLUUID group_id(gAgent.getGroupForRezzing());
-	packAgentAndSessionAndGroupID(&group_id);
+    LLUUID group_id(gAgent.getGroupForRezzing());
+    packAgentAndSessionAndGroupID(&group_id);
 
-	LLDuplicateData* dup_data = (LLDuplicateData*) data;
+    LLDuplicateData* dup_data = (LLDuplicateData*) data;
 
-	gMessageSystem->nextBlockFast(_PREHASH_SharedData);
-	gMessageSystem->addVector3Fast(_PREHASH_Offset, dup_data->offset);
-	gMessageSystem->addU32Fast(_PREHASH_DuplicateFlags, dup_data->flags);
+    gMessageSystem->nextBlockFast(_PREHASH_SharedData);
+    gMessageSystem->addVector3Fast(_PREHASH_Offset, dup_data->offset);
+    gMessageSystem->addU32Fast(_PREHASH_DuplicateFlags, dup_data->flags);
 }
 
 // static
 void LLSelectMgr::packDeleteHeader(void* userdata)
 {
-	BOOL force = (BOOL)(intptr_t)userdata;
+    BOOL force = (BOOL)(intptr_t)userdata;
 
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->addBOOLFast(_PREHASH_Force, force);
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->addBOOLFast(_PREHASH_Force, force);
 }
 
 // static
 void LLSelectMgr::packAgentGroupAndCatID(void* user_data)
 {
-	LLBuyData* buy = (LLBuyData*)user_data;
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
-	gMessageSystem->addUUIDFast(_PREHASH_CategoryID, buy->mCategoryID);
+    LLBuyData* buy = (LLBuyData*)user_data;
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
+    gMessageSystem->addUUIDFast(_PREHASH_CategoryID, buy->mCategoryID);
 }
 
 //static
 void LLSelectMgr::packDeRezHeader(void* user_data)
 {
-	LLDeRezInfo* info = (LLDeRezInfo*)user_data;
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->nextBlockFast(_PREHASH_AgentBlock);
-	gMessageSystem->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
-	gMessageSystem->addU8Fast(_PREHASH_Destination, (U8)info->mDestination);
-	gMessageSystem->addUUIDFast(_PREHASH_DestinationID, info->mDestinationID);
-	LLUUID tid;
-	tid.generate();
-	gMessageSystem->addUUIDFast(_PREHASH_TransactionID, tid);
-	const U8 PACKET = 1;
-	gMessageSystem->addU8Fast(_PREHASH_PacketCount, PACKET);
-	gMessageSystem->addU8Fast(_PREHASH_PacketNumber, PACKET);
-}
-
-// static 
+    LLDeRezInfo* info = (LLDeRezInfo*)user_data;
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->nextBlockFast(_PREHASH_AgentBlock);
+    gMessageSystem->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
+    gMessageSystem->addU8Fast(_PREHASH_Destination, (U8)info->mDestination);
+    gMessageSystem->addUUIDFast(_PREHASH_DestinationID, info->mDestinationID);
+    LLUUID tid;
+    tid.generate();
+    gMessageSystem->addUUIDFast(_PREHASH_TransactionID, tid);
+    const U8 PACKET = 1;
+    gMessageSystem->addU8Fast(_PREHASH_PacketCount, PACKET);
+    gMessageSystem->addU8Fast(_PREHASH_PacketNumber, PACKET);
+}
+
+// static
 void LLSelectMgr::packObjectID(LLSelectNode* node, void *user_data)
 {
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addUUIDFast(_PREHASH_ObjectID, node->getObject()->mID );
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addUUIDFast(_PREHASH_ObjectID, node->getObject()->mID );
 }
 
 void LLSelectMgr::packObjectIDAndRotation(LLSelectNode* node, void *user_data)
 {
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID() );
-	gMessageSystem->addQuatFast(_PREHASH_Rotation, node->getObject()->getRotation());
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID() );
+    gMessageSystem->addQuatFast(_PREHASH_Rotation, node->getObject()->getRotation());
 }
 
 void LLSelectMgr::packObjectClickAction(LLSelectNode* node, void *user_data)
 {
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID() );
-	gMessageSystem->addU8Fast(_PREHASH_ClickAction, node->getObject()->getClickAction());
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID() );
+    gMessageSystem->addU8Fast(_PREHASH_ClickAction, node->getObject()->getClickAction());
 }
 
 void LLSelectMgr::packObjectIncludeInSearch(LLSelectNode* node, void *user_data)
 {
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID() );
-	gMessageSystem->addBOOLFast(_PREHASH_IncludeInSearch, node->getObject()->getIncludeInSearch());
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID() );
+    gMessageSystem->addBOOLFast(_PREHASH_IncludeInSearch, node->getObject()->getIncludeInSearch());
 }
 
 // static
 void LLSelectMgr::packObjectLocalID(LLSelectNode* node, void *)
 {
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
 }
 
 // static
 void LLSelectMgr::packObjectName(LLSelectNode* node, void* user_data)
 {
-	const std::string* name = (const std::string*)user_data;
-	if(!name->empty())
-	{
-		gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-		gMessageSystem->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
-		gMessageSystem->addStringFast(_PREHASH_Name, *name);
-	}
+    const std::string* name = (const std::string*)user_data;
+    if(!name->empty())
+    {
+        gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+        gMessageSystem->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
+        gMessageSystem->addStringFast(_PREHASH_Name, *name);
+    }
 }
 
 // static
 void LLSelectMgr::packObjectDescription(LLSelectNode* node, void* user_data)
 {
-	const std::string* desc = (const std::string*)user_data;
-	if(desc)
-	{	// Empty (non-null, but zero length) descriptions are OK
-		gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-		gMessageSystem->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
-		gMessageSystem->addStringFast(_PREHASH_Description, *desc);
-	}
+    const std::string* desc = (const std::string*)user_data;
+    if(desc)
+    {   // Empty (non-null, but zero length) descriptions are OK
+        gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+        gMessageSystem->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
+        gMessageSystem->addStringFast(_PREHASH_Description, *desc);
+    }
 }
 
 // static
 void LLSelectMgr::packObjectCategory(LLSelectNode* node, void* user_data)
 {
-	LLCategory* category = (LLCategory*)user_data;
-	if(!category) return;
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
-	category->packMessage(gMessageSystem);
+    LLCategory* category = (LLCategory*)user_data;
+    if(!category) return;
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
+    category->packMessage(gMessageSystem);
 }
 
 // static
 void LLSelectMgr::packObjectSaleInfo(LLSelectNode* node, void* user_data)
 {
-	LLSaleInfo* sale_info = (LLSaleInfo*)user_data;
-	if(!sale_info) return;
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
-	sale_info->packMessage(gMessageSystem);
+    LLSaleInfo* sale_info = (LLSaleInfo*)user_data;
+    if(!sale_info) return;
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_LocalID, node->getObject()->getLocalID());
+    sale_info->packMessage(gMessageSystem);
 }
 
 // static
@@ -5491,46 +5491,46 @@ void LLSelectMgr::packShape(LLSelectNode* node, void *user_data)
 {
 }
 
-// static 
+// static
 void LLSelectMgr::packPermissions(LLSelectNode* node, void *user_data)
 {
-	LLPermData *data = (LLPermData *)user_data;
+    LLPermData *data = (LLPermData *)user_data;
 
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, node->getObject()->getLocalID());
 
-	gMessageSystem->addU8Fast(_PREHASH_Field,	data->mField);
-	gMessageSystem->addU8Fast(_PREHASH_Set,		data->mSet);
-	gMessageSystem->addU32Fast(_PREHASH_Mask,		data->mMask);
+    gMessageSystem->addU8Fast(_PREHASH_Field,   data->mField);
+    gMessageSystem->addU8Fast(_PREHASH_Set,     data->mSet);
+    gMessageSystem->addU32Fast(_PREHASH_Mask,       data->mMask);
 }
 
 // Utility function to send some information to every region containing
 // an object on the selection list.  We want to do this to reduce the total
 // number of packets sent by the viewer.
 void LLSelectMgr::sendListToRegions(const std::string& message_name,
-									void (*pack_header)(void *user_data), 
-									void (*pack_body)(LLSelectNode* node, void *user_data), 
-									void (*log_func)(LLSelectNode* node, void *user_data), 
-									void *user_data,
-									ESendType send_type)
+                                    void (*pack_header)(void *user_data),
+                                    void (*pack_body)(LLSelectNode* node, void *user_data),
+                                    void (*log_func)(LLSelectNode* node, void *user_data),
+                                    void *user_data,
+                                    ESendType send_type)
 {
     sendListToRegions(mSelectedObjects, message_name, pack_header, pack_body, log_func, user_data, send_type);
 }
 void LLSelectMgr::sendListToRegions(LLObjectSelectionHandle selected_handle,
-									const std::string& message_name,
-									void (*pack_header)(void *user_data), 
-									void (*pack_body)(LLSelectNode* node, void *user_data), 
-									void (*log_func)(LLSelectNode* node, void *user_data), 
-									void *user_data,
-									ESendType send_type)
+                                    const std::string& message_name,
+                                    void (*pack_header)(void *user_data),
+                                    void (*pack_body)(LLSelectNode* node, void *user_data),
+                                    void (*log_func)(LLSelectNode* node, void *user_data),
+                                    void *user_data,
+                                    ESendType send_type)
 {
-	LLSelectNode* node;
-	LLSelectNode* linkset_root = NULL;
-	LLViewerRegion*	last_region;
-	LLViewerRegion*	current_region;
-	S32 objects_in_this_packet = 0;
+    LLSelectNode* node;
+    LLSelectNode* linkset_root = NULL;
+    LLViewerRegion* last_region;
+    LLViewerRegion* current_region;
+    S32 objects_in_this_packet = 0;
 
-	bool link_operation = message_name == "ObjectLink";
+    bool link_operation = message_name == "ObjectLink";
 
     if (mAllowSelectAvatar)
     {
@@ -5554,164 +5554,164 @@ void LLSelectMgr::sendListToRegions(LLObjectSelectionHandle selected_handle,
         resetObjectOverrides(selected_handle);
     }
 
-	std::queue<LLSelectNode*> nodes_to_send;
-
-	struct push_all : public LLSelectedNodeFunctor
-	{
-		std::queue<LLSelectNode*>& nodes_to_send;
-		push_all(std::queue<LLSelectNode*>& n) : nodes_to_send(n) {}
-		virtual bool apply(LLSelectNode* node)
-		{
-			if (node->getObject())
-			{
-				nodes_to_send.push(node);
-			}
-			return true;
-		}
-	};
-	struct push_some : public LLSelectedNodeFunctor
-	{
-		std::queue<LLSelectNode*>& nodes_to_send;
-		bool mRoots;
-		push_some(std::queue<LLSelectNode*>& n, bool roots) : nodes_to_send(n), mRoots(roots) {}
-		virtual bool apply(LLSelectNode* node)
-		{
-			if (node->getObject())
-			{
-				BOOL is_root = node->getObject()->isRootEdit();
-				if ((mRoots && is_root) || (!mRoots && !is_root))
-				{
-					nodes_to_send.push(node);
-				}
-			}
-			return true;
-		}
-	};
-	struct push_all  pushall(nodes_to_send);
-	struct push_some pushroots(nodes_to_send, TRUE);
-	struct push_some pushnonroots(nodes_to_send, FALSE);
-	
-	switch(send_type)
-	{
-	  case SEND_ONLY_ROOTS:
-		  if(message_name == "ObjectBuy")
-			selected_handle->applyToRootNodes(&pushroots);
-		  else
-			selected_handle->applyToRootNodes(&pushall);
-		  
-		break;
-	  case SEND_INDIVIDUALS:
-		selected_handle->applyToNodes(&pushall);
-		break;
-	  case SEND_ROOTS_FIRST:
-		// first roots...
-		selected_handle->applyToNodes(&pushroots);
-		// then children...
-		selected_handle->applyToNodes(&pushnonroots);
-		break;
-	  case SEND_CHILDREN_FIRST:
-		// first children...
-		selected_handle->applyToNodes(&pushnonroots);
-		// then roots...
-		selected_handle->applyToNodes(&pushroots);
-		break;
-
-	default:
-		LL_ERRS() << "Bad send type " << send_type << " passed to SendListToRegions()" << LL_ENDL;
-	}
-
-	// bail if nothing selected
-	if (nodes_to_send.empty())
-	{
-		return;
-	}
-	
-	node = nodes_to_send.front();
-	nodes_to_send.pop();
-
-	// cache last region information
-	current_region = node->getObject()->getRegion();
-
-	// Start duplicate message
-	// CRO: this isn't 
-	gMessageSystem->newMessage(message_name.c_str());
-	(*pack_header)(user_data);
-
-	// For each object
-	while (node != NULL)
-	{
-		// remember the last region, look up the current one
-		last_region = current_region;
-		current_region = node->getObject()->getRegion();
-
-		// if to same simulator and message not too big
-		if ((current_region == last_region)
-			&& (! gMessageSystem->isSendFullFast(nullptr))
-			&& (objects_in_this_packet < MAX_OBJECTS_PER_PACKET))
-		{
-			if (link_operation && linkset_root == NULL)
-			{
-				// linksets over 254 will be split into multiple messages,
-				// but we need to provide same root for all messages or we will get separate linksets
-				linkset_root = node;
-			}
-			// add another instance of the body of the data
-			(*pack_body)(node, user_data);
+    std::queue<LLSelectNode*> nodes_to_send;
+
+    struct push_all : public LLSelectedNodeFunctor
+    {
+        std::queue<LLSelectNode*>& nodes_to_send;
+        push_all(std::queue<LLSelectNode*>& n) : nodes_to_send(n) {}
+        virtual bool apply(LLSelectNode* node)
+        {
+            if (node->getObject())
+            {
+                nodes_to_send.push(node);
+            }
+            return true;
+        }
+    };
+    struct push_some : public LLSelectedNodeFunctor
+    {
+        std::queue<LLSelectNode*>& nodes_to_send;
+        bool mRoots;
+        push_some(std::queue<LLSelectNode*>& n, bool roots) : nodes_to_send(n), mRoots(roots) {}
+        virtual bool apply(LLSelectNode* node)
+        {
+            if (node->getObject())
+            {
+                BOOL is_root = node->getObject()->isRootEdit();
+                if ((mRoots && is_root) || (!mRoots && !is_root))
+                {
+                    nodes_to_send.push(node);
+                }
+            }
+            return true;
+        }
+    };
+    struct push_all  pushall(nodes_to_send);
+    struct push_some pushroots(nodes_to_send, TRUE);
+    struct push_some pushnonroots(nodes_to_send, FALSE);
+
+    switch(send_type)
+    {
+      case SEND_ONLY_ROOTS:
+          if(message_name == "ObjectBuy")
+            selected_handle->applyToRootNodes(&pushroots);
+          else
+            selected_handle->applyToRootNodes(&pushall);
+
+        break;
+      case SEND_INDIVIDUALS:
+        selected_handle->applyToNodes(&pushall);
+        break;
+      case SEND_ROOTS_FIRST:
+        // first roots...
+        selected_handle->applyToNodes(&pushroots);
+        // then children...
+        selected_handle->applyToNodes(&pushnonroots);
+        break;
+      case SEND_CHILDREN_FIRST:
+        // first children...
+        selected_handle->applyToNodes(&pushnonroots);
+        // then roots...
+        selected_handle->applyToNodes(&pushroots);
+        break;
+
+    default:
+        LL_ERRS() << "Bad send type " << send_type << " passed to SendListToRegions()" << LL_ENDL;
+    }
+
+    // bail if nothing selected
+    if (nodes_to_send.empty())
+    {
+        return;
+    }
+
+    node = nodes_to_send.front();
+    nodes_to_send.pop();
+
+    // cache last region information
+    current_region = node->getObject()->getRegion();
+
+    // Start duplicate message
+    // CRO: this isn't
+    gMessageSystem->newMessage(message_name.c_str());
+    (*pack_header)(user_data);
+
+    // For each object
+    while (node != NULL)
+    {
+        // remember the last region, look up the current one
+        last_region = current_region;
+        current_region = node->getObject()->getRegion();
+
+        // if to same simulator and message not too big
+        if ((current_region == last_region)
+            && (! gMessageSystem->isSendFullFast(nullptr))
+            && (objects_in_this_packet < MAX_OBJECTS_PER_PACKET))
+        {
+            if (link_operation && linkset_root == NULL)
+            {
+                // linksets over 254 will be split into multiple messages,
+                // but we need to provide same root for all messages or we will get separate linksets
+                linkset_root = node;
+            }
+            // add another instance of the body of the data
+            (*pack_body)(node, user_data);
             // do any related logging
             (*log_func)(node, user_data);
-			++objects_in_this_packet;
-
-			// and on to the next object
-			if(nodes_to_send.empty())
-			{
-				node = NULL;
-			}
-			else
-			{
-				node = nodes_to_send.front();
-				nodes_to_send.pop();
-			}
-		}
-		else
-		{
-			// otherwise send current message and start new one
-			gMessageSystem->sendReliable( last_region->getHost());
-			objects_in_this_packet = 0;
-
-			gMessageSystem->newMessage(message_name.c_str());
-			(*pack_header)(user_data);
-
-			if (linkset_root != NULL)
-			{
-				if (current_region != last_region)
-				{
-					// root should be in one region with the child, reset it
-					linkset_root = NULL;
-				}
-				else
-				{
-					// add root instance into new message
-					(*pack_body)(linkset_root, user_data);
-					++objects_in_this_packet;
-				}
-			}
-
-			// don't move to the next object, we still need to add the
-			// body data. 
-		}
-	}
-
-	// flush messages
-	if (gMessageSystem->getCurrentSendTotal() > 0)
-	{
-		gMessageSystem->sendReliable( current_region->getHost());
-	}
-	else
-	{
-		gMessageSystem->clearMessage();
-	}
-
-	// LL_INFOS() << "sendListToRegions " << message_name << " obj " << objects_sent << " pkt " << packets_sent << LL_ENDL;
+            ++objects_in_this_packet;
+
+            // and on to the next object
+            if(nodes_to_send.empty())
+            {
+                node = NULL;
+            }
+            else
+            {
+                node = nodes_to_send.front();
+                nodes_to_send.pop();
+            }
+        }
+        else
+        {
+            // otherwise send current message and start new one
+            gMessageSystem->sendReliable( last_region->getHost());
+            objects_in_this_packet = 0;
+
+            gMessageSystem->newMessage(message_name.c_str());
+            (*pack_header)(user_data);
+
+            if (linkset_root != NULL)
+            {
+                if (current_region != last_region)
+                {
+                    // root should be in one region with the child, reset it
+                    linkset_root = NULL;
+                }
+                else
+                {
+                    // add root instance into new message
+                    (*pack_body)(linkset_root, user_data);
+                    ++objects_in_this_packet;
+                }
+            }
+
+            // don't move to the next object, we still need to add the
+            // body data.
+        }
+    }
+
+    // flush messages
+    if (gMessageSystem->getCurrentSendTotal() > 0)
+    {
+        gMessageSystem->sendReliable( current_region->getHost());
+    }
+    else
+    {
+        gMessageSystem->clearMessage();
+    }
+
+    // LL_INFOS() << "sendListToRegions " << message_name << " obj " << objects_sent << " pkt " << packets_sent << LL_ENDL;
 }
 
 
@@ -5721,165 +5721,165 @@ void LLSelectMgr::sendListToRegions(LLObjectSelectionHandle selected_handle,
 
 void LLSelectMgr::requestObjectPropertiesFamily(LLViewerObject* object)
 {
-	LLMessageSystem* msg = gMessageSystem;
+    LLMessageSystem* msg = gMessageSystem;
 
-	msg->newMessageFast(_PREHASH_RequestObjectPropertiesFamily);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_ObjectData);
-	msg->addU32Fast(_PREHASH_RequestFlags, 0x0 );
-	msg->addUUIDFast(_PREHASH_ObjectID, object->mID );
+    msg->newMessageFast(_PREHASH_RequestObjectPropertiesFamily);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_ObjectData);
+    msg->addU32Fast(_PREHASH_RequestFlags, 0x0 );
+    msg->addUUIDFast(_PREHASH_ObjectID, object->mID );
 
-	LLViewerRegion* regionp = object->getRegion();
-	msg->sendReliable( regionp->getHost() );
+    LLViewerRegion* regionp = object->getRegion();
+    msg->sendReliable( regionp->getHost() );
 }
 
 
 // static
 void LLSelectMgr::processObjectProperties(LLMessageSystem* msg, void** user_data)
 {
-	S32 i;
-	S32 count = msg->getNumberOfBlocksFast(_PREHASH_ObjectData);
-	for (i = 0; i < count; i++)
-	{
-		LLUUID id;
-		msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, id, i);
-
-		LLUUID creator_id;
-		LLUUID owner_id;
-		LLUUID group_id;
-		LLUUID last_owner_id;
-		U64 creation_date;
-		U32 base_mask, owner_mask, group_mask, everyone_mask, next_owner_mask;
-		LLSaleInfo sale_info;
-		LLCategory category;
-		LLAggregatePermissions ag_perms;
-		LLAggregatePermissions ag_texture_perms;
-		LLAggregatePermissions ag_texture_perms_owner;
-		
-		msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_CreatorID, creator_id, i);
-		msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_OwnerID, owner_id, i);
-		msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_GroupID, group_id, i);
-		msg->getU64Fast(_PREHASH_ObjectData, _PREHASH_CreationDate, creation_date, i);
-		msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_BaseMask, base_mask, i);
-		msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_OwnerMask, owner_mask, i);
-		msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_GroupMask, group_mask, i);
-		msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_EveryoneMask, everyone_mask, i);
-		msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_NextOwnerMask, next_owner_mask, i);
-		sale_info.unpackMultiMessage(msg, _PREHASH_ObjectData, i);
-
-		ag_perms.unpackMessage(msg, _PREHASH_ObjectData, _PREHASH_AggregatePerms, i);
-		ag_texture_perms.unpackMessage(msg, _PREHASH_ObjectData, _PREHASH_AggregatePermTextures, i);
-		ag_texture_perms_owner.unpackMessage(msg, _PREHASH_ObjectData, _PREHASH_AggregatePermTexturesOwner, i);
-		category.unpackMultiMessage(msg, _PREHASH_ObjectData, i);
-
-		S16 inv_serial = 0;
-		msg->getS16Fast(_PREHASH_ObjectData, _PREHASH_InventorySerial, inv_serial, i);
-
-		LLUUID item_id;
-		msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ItemID, item_id, i);
-		LLUUID folder_id;
-		msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_FolderID, folder_id, i);
-		LLUUID from_task_id;
-		msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_FromTaskID, from_task_id, i);
-
-		msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_LastOwnerID, last_owner_id, i);
-
-		std::string name;
-		msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Name, name, i);
-		std::string desc;
-		msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Description, desc, i);
-
-		std::string touch_name;
-		msg->getStringFast(_PREHASH_ObjectData, _PREHASH_TouchName, touch_name, i);
-		std::string sit_name;
-		msg->getStringFast(_PREHASH_ObjectData, _PREHASH_SitName, sit_name, i);
-
-		//unpack TE IDs
-		uuid_vec_t texture_ids;
-		S32 size = msg->getSizeFast(_PREHASH_ObjectData, i, _PREHASH_TextureID);
-		if (size > 0)
-		{
-			S8 packed_buffer[SELECT_MAX_TES * UUID_BYTES];
-			msg->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextureID, packed_buffer, 0, i, SELECT_MAX_TES * UUID_BYTES);
-
-			for (S32 buf_offset = 0; buf_offset < size; buf_offset += UUID_BYTES)
-			{
-				LLUUID tid;
-				memcpy(tid.mData, packed_buffer + buf_offset, UUID_BYTES);		/* Flawfinder: ignore */
-				texture_ids.push_back(tid);
-			}
-		}
-
-
-		// Iterate through nodes at end, since it can be on both the regular AND hover list
-		struct f : public LLSelectedNodeFunctor
-		{
-			LLUUID mID;
-			f(const LLUUID& id) : mID(id) {}
-			virtual bool apply(LLSelectNode* node)
-			{
-				return (node->getObject() && node->getObject()->mID == mID);
-			}
-		} func(id);
-		LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstNode(&func);
-
-		if (!node)
-		{
-			LL_WARNS() << "Couldn't find object " << id << " selected." << LL_ENDL;
-		}
-		else
-		{
+    S32 i;
+    S32 count = msg->getNumberOfBlocksFast(_PREHASH_ObjectData);
+    for (i = 0; i < count; i++)
+    {
+        LLUUID id;
+        msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, id, i);
+
+        LLUUID creator_id;
+        LLUUID owner_id;
+        LLUUID group_id;
+        LLUUID last_owner_id;
+        U64 creation_date;
+        U32 base_mask, owner_mask, group_mask, everyone_mask, next_owner_mask;
+        LLSaleInfo sale_info;
+        LLCategory category;
+        LLAggregatePermissions ag_perms;
+        LLAggregatePermissions ag_texture_perms;
+        LLAggregatePermissions ag_texture_perms_owner;
+
+        msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_CreatorID, creator_id, i);
+        msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_OwnerID, owner_id, i);
+        msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_GroupID, group_id, i);
+        msg->getU64Fast(_PREHASH_ObjectData, _PREHASH_CreationDate, creation_date, i);
+        msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_BaseMask, base_mask, i);
+        msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_OwnerMask, owner_mask, i);
+        msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_GroupMask, group_mask, i);
+        msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_EveryoneMask, everyone_mask, i);
+        msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_NextOwnerMask, next_owner_mask, i);
+        sale_info.unpackMultiMessage(msg, _PREHASH_ObjectData, i);
+
+        ag_perms.unpackMessage(msg, _PREHASH_ObjectData, _PREHASH_AggregatePerms, i);
+        ag_texture_perms.unpackMessage(msg, _PREHASH_ObjectData, _PREHASH_AggregatePermTextures, i);
+        ag_texture_perms_owner.unpackMessage(msg, _PREHASH_ObjectData, _PREHASH_AggregatePermTexturesOwner, i);
+        category.unpackMultiMessage(msg, _PREHASH_ObjectData, i);
+
+        S16 inv_serial = 0;
+        msg->getS16Fast(_PREHASH_ObjectData, _PREHASH_InventorySerial, inv_serial, i);
+
+        LLUUID item_id;
+        msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ItemID, item_id, i);
+        LLUUID folder_id;
+        msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_FolderID, folder_id, i);
+        LLUUID from_task_id;
+        msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_FromTaskID, from_task_id, i);
+
+        msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_LastOwnerID, last_owner_id, i);
+
+        std::string name;
+        msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Name, name, i);
+        std::string desc;
+        msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Description, desc, i);
+
+        std::string touch_name;
+        msg->getStringFast(_PREHASH_ObjectData, _PREHASH_TouchName, touch_name, i);
+        std::string sit_name;
+        msg->getStringFast(_PREHASH_ObjectData, _PREHASH_SitName, sit_name, i);
+
+        //unpack TE IDs
+        uuid_vec_t texture_ids;
+        S32 size = msg->getSizeFast(_PREHASH_ObjectData, i, _PREHASH_TextureID);
+        if (size > 0)
+        {
+            S8 packed_buffer[SELECT_MAX_TES * UUID_BYTES];
+            msg->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextureID, packed_buffer, 0, i, SELECT_MAX_TES * UUID_BYTES);
+
+            for (S32 buf_offset = 0; buf_offset < size; buf_offset += UUID_BYTES)
+            {
+                LLUUID tid;
+                memcpy(tid.mData, packed_buffer + buf_offset, UUID_BYTES);      /* Flawfinder: ignore */
+                texture_ids.push_back(tid);
+            }
+        }
+
+
+        // Iterate through nodes at end, since it can be on both the regular AND hover list
+        struct f : public LLSelectedNodeFunctor
+        {
+            LLUUID mID;
+            f(const LLUUID& id) : mID(id) {}
+            virtual bool apply(LLSelectNode* node)
+            {
+                return (node->getObject() && node->getObject()->mID == mID);
+            }
+        } func(id);
+        LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstNode(&func);
+
+        if (!node)
+        {
+            LL_WARNS() << "Couldn't find object " << id << " selected." << LL_ENDL;
+        }
+        else
+        {
             // save texture data as soon as we get texture perms first time
             bool save_textures = !node->mValid;
-			if (node->mInventorySerial != inv_serial && node->getObject())
-			{
-				node->getObject()->dirtyInventory();
+            if (node->mInventorySerial != inv_serial && node->getObject())
+            {
+                node->getObject()->dirtyInventory();
 
                 // Even if this isn't object's first udpate, inventory changed
                 // and some of the applied textures might have been in inventory
                 // so update texture list.
                 save_textures = true;
-			}
-
-			if (save_textures)
-			{
-				BOOL can_copy = FALSE;
-				BOOL can_transfer = FALSE;
-
-				LLAggregatePermissions::EValue value = LLAggregatePermissions::AP_NONE;
-				if(node->getObject()->permYouOwner())
-				{
-					value = ag_texture_perms_owner.getValue(PERM_COPY);
-					if (value == LLAggregatePermissions::AP_EMPTY || value == LLAggregatePermissions::AP_ALL)
-					{
-						can_copy = TRUE;
-					}
-					value = ag_texture_perms_owner.getValue(PERM_TRANSFER);
-					if (value == LLAggregatePermissions::AP_EMPTY || value == LLAggregatePermissions::AP_ALL)
-					{
-						can_transfer = TRUE;
-					}
-				}
-				else
-				{
-					value = ag_texture_perms.getValue(PERM_COPY);
-					if (value == LLAggregatePermissions::AP_EMPTY || value == LLAggregatePermissions::AP_ALL)
-					{
-						can_copy = TRUE;
-					}
-					value = ag_texture_perms.getValue(PERM_TRANSFER);
-					if (value == LLAggregatePermissions::AP_EMPTY || value == LLAggregatePermissions::AP_ALL)
-					{
-						can_transfer = TRUE;
-					}
-				}
-
-				if (can_copy && can_transfer)
-				{
-					node->saveTextures(texture_ids);
-				}
+            }
+
+            if (save_textures)
+            {
+                BOOL can_copy = FALSE;
+                BOOL can_transfer = FALSE;
+
+                LLAggregatePermissions::EValue value = LLAggregatePermissions::AP_NONE;
+                if(node->getObject()->permYouOwner())
+                {
+                    value = ag_texture_perms_owner.getValue(PERM_COPY);
+                    if (value == LLAggregatePermissions::AP_EMPTY || value == LLAggregatePermissions::AP_ALL)
+                    {
+                        can_copy = TRUE;
+                    }
+                    value = ag_texture_perms_owner.getValue(PERM_TRANSFER);
+                    if (value == LLAggregatePermissions::AP_EMPTY || value == LLAggregatePermissions::AP_ALL)
+                    {
+                        can_transfer = TRUE;
+                    }
+                }
+                else
+                {
+                    value = ag_texture_perms.getValue(PERM_COPY);
+                    if (value == LLAggregatePermissions::AP_EMPTY || value == LLAggregatePermissions::AP_ALL)
+                    {
+                        can_copy = TRUE;
+                    }
+                    value = ag_texture_perms.getValue(PERM_TRANSFER);
+                    if (value == LLAggregatePermissions::AP_EMPTY || value == LLAggregatePermissions::AP_ALL)
+                    {
+                        can_transfer = TRUE;
+                    }
+                }
+
+                if (can_copy && can_transfer)
+                {
+                    node->saveTextures(texture_ids);
+                }
 
                 if (can_copy && can_transfer && node->getObject()->getVolume())
                 {
@@ -5910,720 +5910,720 @@ void LLSelectMgr::processObjectProperties(LLMessageSystem* msg, void** user_data
                     // might need to be moved to LLGLTFMaterialOverrideDispatchHandler
                     node->saveGLTFMaterials(material_ids, override_materials);
                 }
-			}
-
-			node->mValid = TRUE;
-			node->mPermissions->init(creator_id, owner_id,
-									 last_owner_id, group_id);
-			node->mPermissions->initMasks(base_mask, owner_mask, everyone_mask, group_mask, next_owner_mask);
-			node->mCreationDate = creation_date;
-			node->mItemID = item_id;
-			node->mFolderID = folder_id;
-			node->mFromTaskID = from_task_id;
-			node->mName.assign(name);
-			node->mDescription.assign(desc);
-			node->mSaleInfo = sale_info;
-			node->mAggregatePerm = ag_perms;
-			node->mAggregateTexturePerm = ag_texture_perms;
-			node->mAggregateTexturePermOwner = ag_texture_perms_owner;
-			node->mCategory = category;
-			node->mInventorySerial = inv_serial;
-			node->mSitName.assign(sit_name);
-			node->mTouchName.assign(touch_name);
-		}
-	}
-
-	dialog_refresh_all();
-
-	// hack for left-click buy object
-	LLToolPie::selectionPropertiesReceived();
+            }
+
+            node->mValid = TRUE;
+            node->mPermissions->init(creator_id, owner_id,
+                                     last_owner_id, group_id);
+            node->mPermissions->initMasks(base_mask, owner_mask, everyone_mask, group_mask, next_owner_mask);
+            node->mCreationDate = creation_date;
+            node->mItemID = item_id;
+            node->mFolderID = folder_id;
+            node->mFromTaskID = from_task_id;
+            node->mName.assign(name);
+            node->mDescription.assign(desc);
+            node->mSaleInfo = sale_info;
+            node->mAggregatePerm = ag_perms;
+            node->mAggregateTexturePerm = ag_texture_perms;
+            node->mAggregateTexturePermOwner = ag_texture_perms_owner;
+            node->mCategory = category;
+            node->mInventorySerial = inv_serial;
+            node->mSitName.assign(sit_name);
+            node->mTouchName.assign(touch_name);
+        }
+    }
+
+    dialog_refresh_all();
+
+    // hack for left-click buy object
+    LLToolPie::selectionPropertiesReceived();
 }
 
 // static
 void LLSelectMgr::processObjectPropertiesFamily(LLMessageSystem* msg, void** user_data)
 {
-	LLUUID id;
-
-	U32 request_flags;
-	LLUUID owner_id;
-	LLUUID group_id;
-	U32 base_mask, owner_mask, group_mask, everyone_mask, next_owner_mask;
-	LLSaleInfo sale_info;
-	LLCategory category;
-	
-	msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_RequestFlags,	request_flags );
-	msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID,		id );
-	msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_OwnerID,		owner_id );
-	msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_GroupID,		group_id );
-	msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_BaseMask,		base_mask );
-	msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_OwnerMask,		owner_mask );
-	msg->getU32Fast(_PREHASH_ObjectData,_PREHASH_GroupMask,		group_mask );
-	msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_EveryoneMask,	everyone_mask );
-	msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_NextOwnerMask, next_owner_mask);
-	sale_info.unpackMessage(msg, _PREHASH_ObjectData);
-	category.unpackMessage(msg, _PREHASH_ObjectData);
-
-	LLUUID last_owner_id;
-	msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_LastOwnerID, last_owner_id );
-
-	// unpack name & desc
-	std::string name;
-	msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Name, name);
-
-	std::string desc;
-	msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Description, desc);
-
-	// the reporter widget askes the server for info about picked objects
-	if (request_flags & COMPLAINT_REPORT_REQUEST )
-	{
-		LLFloaterReporter *reporterp = LLFloaterReg::findTypedInstance<LLFloaterReporter>("reporter");
-		if (reporterp)
-		{
-			LLAvatarName av_name;
-			LLAvatarNameCache::get(owner_id, &av_name);
-			reporterp->setPickedObjectProperties(name, av_name.getUserName(), owner_id);
-		}
-	}
-	else if (request_flags & OBJECT_PAY_REQUEST)
-	{
-		// check if the owner of the paid object is muted
-		LLMuteList::getInstance()->autoRemove(owner_id, LLMuteList::AR_MONEY);
-	}
-
-	// Now look through all of the hovered nodes
-	struct f : public LLSelectedNodeFunctor
-	{
-		LLUUID mID;
-		f(const LLUUID& id) : mID(id) {}
-		virtual bool apply(LLSelectNode* node)
-		{
-			return (node->getObject() && node->getObject()->mID == mID);
-		}
-	} func(id);
-	LLSelectNode* node = LLSelectMgr::getInstance()->mHoverObjects->getFirstNode(&func);
-
-	if (node)
-	{
-		node->mValid = TRUE;
-		node->mPermissions->init(LLUUID::null, owner_id,
-								 last_owner_id, group_id);
-		node->mPermissions->initMasks(base_mask, owner_mask, everyone_mask, group_mask, next_owner_mask);
-		node->mSaleInfo = sale_info;
-		node->mCategory = category;
-		node->mName.assign(name);
-		node->mDescription.assign(desc);
-	}
-
-	dialog_refresh_all();
+    LLUUID id;
+
+    U32 request_flags;
+    LLUUID owner_id;
+    LLUUID group_id;
+    U32 base_mask, owner_mask, group_mask, everyone_mask, next_owner_mask;
+    LLSaleInfo sale_info;
+    LLCategory category;
+
+    msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_RequestFlags, request_flags );
+    msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID,        id );
+    msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_OwnerID,     owner_id );
+    msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_GroupID,     group_id );
+    msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_BaseMask,     base_mask );
+    msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_OwnerMask,        owner_mask );
+    msg->getU32Fast(_PREHASH_ObjectData,_PREHASH_GroupMask,     group_mask );
+    msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_EveryoneMask, everyone_mask );
+    msg->getU32Fast(_PREHASH_ObjectData, _PREHASH_NextOwnerMask, next_owner_mask);
+    sale_info.unpackMessage(msg, _PREHASH_ObjectData);
+    category.unpackMessage(msg, _PREHASH_ObjectData);
+
+    LLUUID last_owner_id;
+    msg->getUUIDFast(_PREHASH_ObjectData, _PREHASH_LastOwnerID, last_owner_id );
+
+    // unpack name & desc
+    std::string name;
+    msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Name, name);
+
+    std::string desc;
+    msg->getStringFast(_PREHASH_ObjectData, _PREHASH_Description, desc);
+
+    // the reporter widget askes the server for info about picked objects
+    if (request_flags & COMPLAINT_REPORT_REQUEST )
+    {
+        LLFloaterReporter *reporterp = LLFloaterReg::findTypedInstance<LLFloaterReporter>("reporter");
+        if (reporterp)
+        {
+            LLAvatarName av_name;
+            LLAvatarNameCache::get(owner_id, &av_name);
+            reporterp->setPickedObjectProperties(name, av_name.getUserName(), owner_id);
+        }
+    }
+    else if (request_flags & OBJECT_PAY_REQUEST)
+    {
+        // check if the owner of the paid object is muted
+        LLMuteList::getInstance()->autoRemove(owner_id, LLMuteList::AR_MONEY);
+    }
+
+    // Now look through all of the hovered nodes
+    struct f : public LLSelectedNodeFunctor
+    {
+        LLUUID mID;
+        f(const LLUUID& id) : mID(id) {}
+        virtual bool apply(LLSelectNode* node)
+        {
+            return (node->getObject() && node->getObject()->mID == mID);
+        }
+    } func(id);
+    LLSelectNode* node = LLSelectMgr::getInstance()->mHoverObjects->getFirstNode(&func);
+
+    if (node)
+    {
+        node->mValid = TRUE;
+        node->mPermissions->init(LLUUID::null, owner_id,
+                                 last_owner_id, group_id);
+        node->mPermissions->initMasks(base_mask, owner_mask, everyone_mask, group_mask, next_owner_mask);
+        node->mSaleInfo = sale_info;
+        node->mCategory = category;
+        node->mName.assign(name);
+        node->mDescription.assign(desc);
+    }
+
+    dialog_refresh_all();
 }
 
 
 // static
 void LLSelectMgr::processForceObjectSelect(LLMessageSystem* msg, void**)
 {
-	BOOL reset_list;
-	msg->getBOOLFast(_PREHASH_Header, _PREHASH_ResetList, reset_list);
+    BOOL reset_list;
+    msg->getBOOLFast(_PREHASH_Header, _PREHASH_ResetList, reset_list);
 
-	if (reset_list)
-	{
-		LLSelectMgr::getInstance()->deselectAll();
-	}
-
-	LLUUID full_id;
-	S32 local_id;
-	LLViewerObject* object;
-	std::vector<LLViewerObject*> objects;
-	S32 i;
-	S32 block_count = msg->getNumberOfBlocksFast(_PREHASH_Data);
+    if (reset_list)
+    {
+        LLSelectMgr::getInstance()->deselectAll();
+    }
 
-	for (i = 0; i < block_count; i++)
-	{
-		msg->getS32Fast(_PREHASH_Data, _PREHASH_LocalID, local_id, i);
+    LLUUID full_id;
+    S32 local_id;
+    LLViewerObject* object;
+    std::vector<LLViewerObject*> objects;
+    S32 i;
+    S32 block_count = msg->getNumberOfBlocksFast(_PREHASH_Data);
 
-		gObjectList.getUUIDFromLocal(full_id, 
-									 local_id, 
-									 msg->getSenderIP(),
-									 msg->getSenderPort());
-		object = gObjectList.findObject(full_id);
-		if (object)
-		{
-			objects.push_back(object);
-		}
-	}
+    for (i = 0; i < block_count; i++)
+    {
+        msg->getS32Fast(_PREHASH_Data, _PREHASH_LocalID, local_id, i);
+
+        gObjectList.getUUIDFromLocal(full_id,
+                                     local_id,
+                                     msg->getSenderIP(),
+                                     msg->getSenderPort());
+        object = gObjectList.findObject(full_id);
+        if (object)
+        {
+            objects.push_back(object);
+        }
+    }
 
-	// Don't select, just highlight
-	LLSelectMgr::getInstance()->highlightObjectAndFamily(objects);
+    // Don't select, just highlight
+    LLSelectMgr::getInstance()->highlightObjectAndFamily(objects);
 }
 
 void LLSelectMgr::updateSilhouettes()
 {
-	S32 num_sils_genned = 0;
-
-	LLVector3d	cameraPos = gAgentCamera.getCameraPositionGlobal();
-	F32 currentCameraZoom = gAgentCamera.getCurrentCameraBuildOffset();
-
-	if (!mSilhouetteImagep)
-	{
-		mSilhouetteImagep = LLViewerTextureManager::getFetchedTextureFromFile("silhouette.j2c", FTT_LOCAL_FILE, TRUE, LLGLTexture::BOOST_UI);
-	}
-
-	mHighlightedObjects->cleanupNodes();
-
-	if((cameraPos - mLastCameraPos).magVecSquared() > SILHOUETTE_UPDATE_THRESHOLD_SQUARED * currentCameraZoom * currentCameraZoom)
-	{
-		struct f : public LLSelectedObjectFunctor
-		{
-			virtual bool apply(LLViewerObject* object)
-			{
-				object->setChanged(LLXform::SILHOUETTE);
-				return true;
-			}
-		} func;
-		getSelection()->applyToObjects(&func);	
-		
-		mLastCameraPos = gAgentCamera.getCameraPositionGlobal();
-	}
-	
-	std::vector<LLViewerObject*> changed_objects;
-
-	updateSelectionSilhouette(mSelectedObjects, num_sils_genned, changed_objects);
-	if (mRectSelectedObjects.size() > 0)
-	{
-		//gGLSPipelineSelection.set();
-
-		//mSilhouetteImagep->bindTexture();
-		//glAlphaFunc(GL_GREATER, sHighlightAlphaTest);
-
-		std::set<LLViewerObject*> roots;
-
-		// sync mHighlightedObjects with mRectSelectedObjects since the latter is rebuilt every frame and former
-		// persists from frame to frame to avoid regenerating object silhouettes
-		// mHighlightedObjects includes all siblings of rect selected objects
-
-		BOOL select_linked_set = !ALControlCache::EditLinkedParts;
-
-		// generate list of roots from current object selection
-		for (LLViewerObject* objectp : mRectSelectedObjects)
-		{
-			if (select_linked_set)
-			{
-				LLViewerObject *rootp = (LLViewerObject*)objectp->getRoot();
-				roots.insert(rootp);
-			}
-			else
-			{
-				roots.insert(objectp);
-			}
-		}
-
-		// remove highlight nodes not in roots list
-		std::vector<LLSelectNode*> remove_these_nodes;
-		std::vector<LLViewerObject*> remove_these_roots;
-
-		for (LLSelectNode* node : mHighlightedObjects->begin_end())
-		{
-			LLViewerObject* objectp = node->getObject();
-			if (!objectp)
-				continue;
-			if (objectp->isRoot() || !select_linked_set)
-			{
-				if (roots.count(objectp) == 0)
-				{
-					remove_these_nodes.push_back(node);
-				}
-				else
-				{
-					remove_these_roots.push_back(objectp);
-				}
-			}
-			else
-			{
-				LLViewerObject* rootp = (LLViewerObject*)objectp->getRoot();
-
-				if (roots.count(rootp) == 0)
-				{
-					remove_these_nodes.push_back(node);
-				}
-			}
-		}
-
-		// remove all highlight nodes no longer in rectangle selection
-		for (LLSelectNode* nodep : remove_these_nodes)
-		{
-			mHighlightedObjects->removeNode(nodep);
-		}
-
-		// remove all root objects already being highlighted
-		for (LLViewerObject* objectp : remove_these_roots)
-		{
-			roots.erase(objectp);
-		}
-
-		// add all new objects in rectangle selection
-		for (LLViewerObject* objectp : roots)
-		{
-			if (!canSelectObject(objectp))
-			{
-				continue;
-			}
-
-			LLSelectNode* rect_select_root_node = new LLSelectNode(objectp, TRUE);
-			rect_select_root_node->selectAllTEs(TRUE);
-
-			if (!select_linked_set)
-			{
-				rect_select_root_node->mIndividualSelection = TRUE;
-			}
-			else
-			{
-				LLViewerObject::const_child_list_t& child_list = objectp->getChildren();
-				for (LLViewerObject* child_objectp : child_list)
-				{
-					if (!canSelectObject(child_objectp))
-					{
-						continue;
-					}
-
-					LLSelectNode* rect_select_node = new LLSelectNode(child_objectp, TRUE);
-					rect_select_node->selectAllTEs(TRUE);
-					mHighlightedObjects->addNodeAtEnd(rect_select_node);
-				}
-			}
-
-			// Add the root last, to preserve order for link operations.
-			mHighlightedObjects->addNodeAtEnd(rect_select_root_node);
-		}
-
-		num_sils_genned	= 0;
-
-		// render silhouettes for highlighted objects
-		const auto& viewer_cam_origin = LLViewerCamera::instance().getOrigin();
-		//BOOL subtracting_from_selection = (gKeyboard->currentMask(TRUE) == MASK_CONTROL);
-		for (S32 pass = 0; pass < 2; pass++)
-		{
-			for (LLSelectNode* node :mHighlightedObjects->begin_end())
-			{
-				LLViewerObject* objectp = node->getObject();
-				if (!objectp)
-					continue;
-				
-				// do roots first, then children so that root flags are cleared ASAP
-				BOOL roots_only = (pass == 0);
-				BOOL is_root = objectp->isRootEdit();
-				if (roots_only != is_root)
-				{
-					continue;
-				}
-
-				if (!node->mSilhouetteExists 
-					|| objectp->isChanged(LLXform::SILHOUETTE)
-					|| (objectp->getParent() && objectp->getParent()->isChanged(LLXform::SILHOUETTE)))
-				{
-					if (num_sils_genned++ < MAX_SILS_PER_FRAME)
-					{
-						generateSilhouette(node, viewer_cam_origin);
-						changed_objects.push_back(objectp);			
-					}
-					else if (objectp->isAttachment() && objectp->getRootEdit()->mDrawable.notNull())
-					{
-						//RN: hack for orthogonal projection of HUD attachments
-						LLViewerJointAttachment* attachment_pt = (LLViewerJointAttachment*)objectp->getRootEdit()->mDrawable->getParent();
-						if (attachment_pt && attachment_pt->getIsHUDAttachment())
-						{
-							LLVector3 camera_pos = LLVector3(-10000.f, 0.f, 0.f);
-							generateSilhouette(node, camera_pos);
-						}
-					}
-				}
-				//LLColor4 highlight_color;
-				//
-				//if (subtracting_from_selection)
-				//{
-				//	node->renderOneSilhouette(LLColor4::red);
-				//}
-				//else if (!objectp->isSelected())
-				//{
-				//	highlight_color = objectp->isRoot() ? sHighlightParentColor : sHighlightChildColor;
-				//	node->renderOneSilhouette(highlight_color);
-				//}
-			}
-		}
-		//mSilhouetteImagep->unbindTexture(0, GL_TEXTURE_2D);
-	}
-	else
-	{
-		mHighlightedObjects->deleteAllNodes();
-	}
-
-	for (LLViewerObject* objectp : changed_objects)
-	{
-		// clear flags after traversing node list (as child objects need to refer to parent flags, etc)
-		objectp->clearChanged(LLXform::MOVED | LLXform::SILHOUETTE);
-	}
-}
+    S32 num_sils_genned = 0;
 
-void LLSelectMgr::updateSelectionSilhouette(LLObjectSelectionHandle object_handle, S32& num_sils_genned, std::vector<LLViewerObject*>& changed_objects)
-{
-	if (object_handle->getNumNodes())
-	{
-		//gGLSPipelineSelection.set();
-
-		//mSilhouetteImagep->bindTexture();
-		//glAlphaFunc(GL_GREATER, sHighlightAlphaTest);
-		const auto& viewer_cam_origin = LLViewerCamera::instance().getOrigin();
-		for (S32 pass = 0; pass < 2; pass++)
-		{
-			for (LLSelectNode* node : object_handle->begin_end())
-			{
-				LLViewerObject* objectp = node->getObject();
-				if (!objectp)
-					continue;
-				// do roots first, then children so that root flags are cleared ASAP
-				BOOL roots_only = (pass == 0);
-				BOOL is_root = (objectp->isRootEdit());
-				if (roots_only != is_root || objectp->mDrawable.isNull())
-				{
-					continue;
-				}
-
-				if (!node->mSilhouetteExists 
-					|| objectp->isChanged(LLXform::SILHOUETTE)
-					|| (objectp->getParent() && objectp->getParent()->isChanged(LLXform::SILHOUETTE)))
-				{
-					if (num_sils_genned++ < MAX_SILS_PER_FRAME)// && objectp->mDrawable->isVisible())
-					{
-						generateSilhouette(node, viewer_cam_origin);
-						changed_objects.push_back(objectp);
-					}
-					else if (objectp->isAttachment())
-					{
-						//RN: hack for orthogonal projection of HUD attachments
-						LLViewerJointAttachment* attachment_pt = (LLViewerJointAttachment*)objectp->getRootEdit()->mDrawable->getParent();
-						if (attachment_pt && attachment_pt->getIsHUDAttachment())
-						{
-							LLVector3 camera_pos = LLVector3(-10000.f, 0.f, 0.f);
-							generateSilhouette(node, camera_pos);
-						}
-					}
-				}
-			}
-		}
-	}
-}
-void LLSelectMgr::renderSilhouettes(BOOL for_hud)
-{
-	if (!mRenderSilhouettes || !mRenderHighlightSelections)
-	{
-		return;
-	}
-
-	gGL.getTexUnit(0)->bind(mSilhouetteImagep);
-	LLGLSPipelineSelection gls_select;
-	LLGLEnable blend(GL_BLEND);
-	LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
-
-	if (isAgentAvatarValid() && for_hud)
-	{
-		LLBBox hud_bbox = gAgentAvatarp->getHUDBBox();
-
-		F32 cur_zoom = gAgentCamera.mHUDCurZoom;
-
-		// set up transform to encompass bounding box of HUD
-		gGL.matrixMode(LLRender::MM_PROJECTION);
-		gGL.pushMatrix();
-		gGL.loadIdentity();
-		F32 depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
-		auto& viewerCamera = LLViewerCamera::instance();
-		gGL.ortho(-0.5f * viewerCamera.getAspect(), 0.5f * viewerCamera.getAspect(), -0.5f, 0.5f, 0.f, depth);
-
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-		gGL.pushMatrix();
-		gGL.pushUIMatrix();
-		gGL.loadUIIdentity();
-		gGL.loadIdentity();
-		gGL.loadMatrix(OGL_TO_CFR_ROTATION_4A);		// Load Cory's favorite reference frame
-		gGL.translatef(-hud_bbox.getCenterLocal().mV[VX] + (depth *0.5f), 0.f, 0.f);
-		gGL.scalef(cur_zoom, cur_zoom, cur_zoom);
-	}
-
-	bool wireframe_selection = (gFloaterTools && gFloaterTools->getVisible()) || LLSelectMgr::sRenderHiddenSelections;
-	F32 fogCfx = (F32)llclamp((getSelectionCenterGlobal() - gAgentCamera.getCameraPositionGlobal()).magVec() / (getBBoxOfSelection().getExtentLocal().magVec() * 4), 0.0, 1.0);
-
-	LLColor4 sParentColor = sSilhouetteParentColor;
-	sParentColor.mV[3] = LLSelectMgr::sHighlightAlpha;
-	LLColor4 sChildColor = sSilhouetteChildColor;
-	sChildColor.mV[3] = LLSelectMgr::sHighlightAlpha;
-
-	auto renderMeshSelection_f = [fogCfx, wireframe_selection](LLSelectNode* node, LLViewerObject* objectp, LLColor4 hlColor)
-	{
-		LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-
-		if (shader)
-		{
-			gDebugProgram.bind();
-		}
-
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-		gGL.pushMatrix();
-
-		BOOL is_hud_object = objectp->isHUDAttachment();
-
-		if (!is_hud_object)
-		{
-			gGL.loadIdentity();
-			gGL.multMatrix(gGLModelView);
-		}
-
-		if (objectp->mDrawable->isActive())
-		{
-			gGL.multMatrix(objectp->getRenderMatrix());
-		}
-		else if (!is_hud_object)
-		{
-			LLVector3 trans = objectp->getRegion()->getOriginAgent();
-			gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);
-		}
-
-		bool bRenderHidenSelection = node->isTransient() ? false : LLSelectMgr::sRenderHiddenSelections;
-
-
-		LLVOVolume* vobj = objectp->mDrawable->getVOVolume();
-		if (vobj)
-		{
-			LLVertexBuffer::unbind();
-			gGL.pushMatrix();
-			gGL.multMatrix(vobj->getRelativeXform());
-
-			if (objectp->mDrawable->isState(LLDrawable::RIGGED))
-			{
-				vobj->updateRiggedVolume(true);
-			}
-		}
-
-		glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
-		S32 num_tes = llmin((S32)objectp->getNumTEs(), (S32)objectp->getNumFaces()); // avatars have TEs but no faces
-		for (S32 te = 0; te < num_tes; ++te)
-		{
-			if (node->isTESelected(te))
-			{
-				objectp->mDrawable->getFace(te)->renderOneWireframe(hlColor, fogCfx, wireframe_selection, bRenderHidenSelection, nullptr != shader);
-			}
-		}
-
-		gGL.popMatrix();
-		gGL.popMatrix();
-
-		gGL.setLineWidth(1.f);
-		glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
-		if (shader)
-		{
-			shader->bind();
-		}
-	};
-
-	if (mSelectedObjects->getNumNodes())
-	{
-		LLUUID inspect_item_id= LLUUID::null;
-		LLFloaterInspect* inspect_instance = LLFloaterReg::findTypedInstance<LLFloaterInspect>("inspect");
-		if(inspect_instance && inspect_instance->getVisible())
-		{
-			inspect_item_id = inspect_instance->getSelectedUUID();
-		}
-		else
-		{
-			LLSidepanelTaskInfo *panel_task_info = LLSidepanelTaskInfo::getActivePanel();
-			if (panel_task_info)
-			{
-				inspect_item_id = panel_task_info->getSelectedUUID();
-			}
-		}
-
-		LLUUID focus_item_id = LLViewerMediaFocus::getInstance()->getFocusedObjectID();
-		{
-			for (LLSelectNode* node : mSelectedObjects->begin_end())
-			{                
-                if (getTEMode() && !node->hasSelectedTE())
-                    continue;
+    LLVector3d  cameraPos = gAgentCamera.getCameraPositionGlobal();
+    F32 currentCameraZoom = gAgentCamera.getCurrentCameraBuildOffset();
 
-				LLViewerObject* objectp = node->getObject();
-				if (!objectp)
-					continue;
+    if (!mSilhouetteImagep)
+    {
+        mSilhouetteImagep = LLViewerTextureManager::getFetchedTextureFromFile("silhouette.j2c", FTT_LOCAL_FILE, TRUE, LLGLTexture::BOOST_UI);
+    }
 
-                if (objectp->mDrawable 
-                    && objectp->mDrawable->getVOVolume() 
-                    && objectp->mDrawable->getVOVolume()->isMesh())
+    mHighlightedObjects->cleanupNodes();
+
+    if((cameraPos - mLastCameraPos).magVecSquared() > SILHOUETTE_UPDATE_THRESHOLD_SQUARED * currentCameraZoom * currentCameraZoom)
+    {
+        struct f : public LLSelectedObjectFunctor
+        {
+            virtual bool apply(LLViewerObject* object)
+            {
+                object->setChanged(LLXform::SILHOUETTE);
+                return true;
+            }
+        } func;
+        getSelection()->applyToObjects(&func);
+
+        mLastCameraPos = gAgentCamera.getCameraPositionGlobal();
+    }
+
+    std::vector<LLViewerObject*> changed_objects;
+
+    updateSelectionSilhouette(mSelectedObjects, num_sils_genned, changed_objects);
+    if (mRectSelectedObjects.size() > 0)
+    {
+        //gGLSPipelineSelection.set();
+
+        //mSilhouetteImagep->bindTexture();
+        //glAlphaFunc(GL_GREATER, sHighlightAlphaTest);
+
+        std::set<LLViewerObject*> roots;
+
+        // sync mHighlightedObjects with mRectSelectedObjects since the latter is rebuilt every frame and former
+        // persists from frame to frame to avoid regenerating object silhouettes
+        // mHighlightedObjects includes all siblings of rect selected objects
+
+        BOOL select_linked_set = !ALControlCache::EditLinkedParts;
+
+        // generate list of roots from current object selection
+        for (LLViewerObject* objectp : mRectSelectedObjects)
+        {
+            if (select_linked_set)
+            {
+                LLViewerObject *rootp = (LLViewerObject*)objectp->getRoot();
+                roots.insert(rootp);
+            }
+            else
+            {
+                roots.insert(objectp);
+            }
+        }
+
+        // remove highlight nodes not in roots list
+        std::vector<LLSelectNode*> remove_these_nodes;
+        std::vector<LLViewerObject*> remove_these_roots;
+
+        for (LLSelectNode* node : mHighlightedObjects->begin_end())
+        {
+            LLViewerObject* objectp = node->getObject();
+            if (!objectp)
+                continue;
+            if (objectp->isRoot() || !select_linked_set)
+            {
+                if (roots.count(objectp) == 0)
                 {
-                    LLColor4 hlColor = objectp->isRootEdit() ? sParentColor : sChildColor;
-                    if (objectp->getID() == inspect_item_id)
-                    {
-                        hlColor = sHighlightInspectColor;
-                    }
-                    else if (node->isTransient())
-                    {
-                        hlColor = sContextSilhouetteColor.get() * 0.5f;
-                    }
-                    renderMeshSelection_f(node, objectp, hlColor);
+                    remove_these_nodes.push_back(node);
                 }
                 else
                 {
-                    if (objectp->isHUDAttachment() != for_hud)
+                    remove_these_roots.push_back(objectp);
+                }
+            }
+            else
+            {
+                LLViewerObject* rootp = (LLViewerObject*)objectp->getRoot();
+
+                if (roots.count(rootp) == 0)
+                {
+                    remove_these_nodes.push_back(node);
+                }
+            }
+        }
+
+        // remove all highlight nodes no longer in rectangle selection
+        for (LLSelectNode* nodep : remove_these_nodes)
+        {
+            mHighlightedObjects->removeNode(nodep);
+        }
+
+        // remove all root objects already being highlighted
+        for (LLViewerObject* objectp : remove_these_roots)
+        {
+            roots.erase(objectp);
+        }
+
+        // add all new objects in rectangle selection
+        for (LLViewerObject* objectp : roots)
+        {
+            if (!canSelectObject(objectp))
+            {
+                continue;
+            }
+
+            LLSelectNode* rect_select_root_node = new LLSelectNode(objectp, TRUE);
+            rect_select_root_node->selectAllTEs(TRUE);
+
+            if (!select_linked_set)
+            {
+                rect_select_root_node->mIndividualSelection = TRUE;
+            }
+            else
+            {
+                LLViewerObject::const_child_list_t& child_list = objectp->getChildren();
+                for (LLViewerObject* child_objectp : child_list)
+                {
+                    if (!canSelectObject(child_objectp))
                     {
                         continue;
                     }
-                    if (objectp->getID() == focus_item_id)
-                    {
-                        node->renderOneSilhouette(gFocusMgr.getFocusColor());
-                    }
-                    else if (objectp->getID() == inspect_item_id)
-                    {
-                        node->renderOneSilhouette(sHighlightInspectColor);
-                    }
-                    else if (node->isTransient())
-                    {
-                        BOOL oldHidden = LLSelectMgr::sRenderHiddenSelections;
-                        LLSelectMgr::sRenderHiddenSelections = FALSE;
-                        node->renderOneSilhouette(sContextSilhouetteColor.get() * 0.5f);
-                        LLSelectMgr::sRenderHiddenSelections = oldHidden;
-                    }
-                    else if (objectp->isRootEdit())
-                    {
-                        node->renderOneSilhouette(sSilhouetteParentColor);
-                    }
-                    else
-                    {
-                        node->renderOneSilhouette(sSilhouetteChildColor);
-                    }
+
+                    LLSelectNode* rect_select_node = new LLSelectNode(child_objectp, TRUE);
+                    rect_select_node->selectAllTEs(TRUE);
+                    mHighlightedObjects->addNodeAtEnd(rect_select_node);
                 }
-			} //for all selected node's
-		} //for pass
-	}
-
-	if (mHighlightedObjects->getNumNodes())
-	{
-		// render silhouettes for highlighted objects
-		BOOL subtracting_from_selection = (gKeyboard->currentMask(TRUE) == MASK_CONTROL);
-		for (S32 pass = 0; pass < 2; pass++)
-		{
-			for (LLSelectNode* node : mHighlightedObjects->begin_end())
-			{
-				LLViewerObject* objectp = node->getObject();
-				if (!objectp)
-					continue;
-				if (objectp->isHUDAttachment() != for_hud)
-				{
-					continue;
-				}
-				
-				LLColor4 highlight_color = objectp->isRoot() ? sHighlightParentColor : sHighlightChildColor;
-				if (objectp->mDrawable
-					&& objectp->mDrawable->getVOVolume()
-					&& objectp->mDrawable->getVOVolume()->isMesh())
-				{
-					renderMeshSelection_f(node, objectp, subtracting_from_selection ? LLColor4::red : highlight_color);
-				}
-				else if (subtracting_from_selection)
-				{
-					node->renderOneSilhouette(LLColor4::red);
-				}
-				else if (!objectp->isSelected())
-				{
-					node->renderOneSilhouette(highlight_color);
-				}
-			}
-		}
-	}
-
-	if (isAgentAvatarValid() && for_hud)
-	{
-		gGL.matrixMode(LLRender::MM_PROJECTION);
-		gGL.popMatrix();
-
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-		gGL.popMatrix();
-		gGL.popUIMatrix();
-		stop_glerror();
-	}
-
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-}
+            }
 
-void LLSelectMgr::generateSilhouette(LLSelectNode* nodep, const LLVector3& view_point)
-{
-	LLViewerObject* objectp = nodep->getObject();
+            // Add the root last, to preserve order for link operations.
+            mHighlightedObjects->addNodeAtEnd(rect_select_root_node);
+        }
 
-	if (objectp && objectp->getPCode() == LL_PCODE_VOLUME)
-	{
-		((LLVOVolume*)objectp)->generateSilhouette(nodep, view_point);
-	}
-}
+        num_sils_genned = 0;
 
-//
-// Utility classes
-//
+        // render silhouettes for highlighted objects
+        const auto& viewer_cam_origin = LLViewerCamera::instance().getOrigin();
+        //BOOL subtracting_from_selection = (gKeyboard->currentMask(TRUE) == MASK_CONTROL);
+        for (S32 pass = 0; pass < 2; pass++)
+        {
+            for (LLSelectNode* node :mHighlightedObjects->begin_end())
+            {
+                LLViewerObject* objectp = node->getObject();
+                if (!objectp)
+                    continue;
+
+                // do roots first, then children so that root flags are cleared ASAP
+                BOOL roots_only = (pass == 0);
+                BOOL is_root = objectp->isRootEdit();
+                if (roots_only != is_root)
+                {
+                    continue;
+                }
+
+                if (!node->mSilhouetteExists
+                    || objectp->isChanged(LLXform::SILHOUETTE)
+                    || (objectp->getParent() && objectp->getParent()->isChanged(LLXform::SILHOUETTE)))
+                {
+                    if (num_sils_genned++ < MAX_SILS_PER_FRAME)
+                    {
+                        generateSilhouette(node, viewer_cam_origin);
+                        changed_objects.push_back(objectp);
+                    }
+                    else if (objectp->isAttachment() && objectp->getRootEdit()->mDrawable.notNull())
+                    {
+                        //RN: hack for orthogonal projection of HUD attachments
+                        LLViewerJointAttachment* attachment_pt = (LLViewerJointAttachment*)objectp->getRootEdit()->mDrawable->getParent();
+                        if (attachment_pt && attachment_pt->getIsHUDAttachment())
+                        {
+                            LLVector3 camera_pos = LLVector3(-10000.f, 0.f, 0.f);
+                            generateSilhouette(node, camera_pos);
+                        }
+                    }
+                }
+                //LLColor4 highlight_color;
+                //
+                //if (subtracting_from_selection)
+                //{
+                //  node->renderOneSilhouette(LLColor4::red);
+                //}
+                //else if (!objectp->isSelected())
+                //{
+                //  highlight_color = objectp->isRoot() ? sHighlightParentColor : sHighlightChildColor;
+                //  node->renderOneSilhouette(highlight_color);
+                //}
+            }
+        }
+        //mSilhouetteImagep->unbindTexture(0, GL_TEXTURE_2D);
+    }
+    else
+    {
+        mHighlightedObjects->deleteAllNodes();
+    }
+
+    for (LLViewerObject* objectp : changed_objects)
+    {
+        // clear flags after traversing node list (as child objects need to refer to parent flags, etc)
+        objectp->clearChanged(LLXform::MOVED | LLXform::SILHOUETTE);
+    }
+}
+
+void LLSelectMgr::updateSelectionSilhouette(LLObjectSelectionHandle object_handle, S32& num_sils_genned, std::vector<LLViewerObject*>& changed_objects)
+{
+    if (object_handle->getNumNodes())
+    {
+        //gGLSPipelineSelection.set();
+
+        //mSilhouetteImagep->bindTexture();
+        //glAlphaFunc(GL_GREATER, sHighlightAlphaTest);
+        const auto& viewer_cam_origin = LLViewerCamera::instance().getOrigin();
+        for (S32 pass = 0; pass < 2; pass++)
+        {
+            for (LLSelectNode* node : object_handle->begin_end())
+            {
+                LLViewerObject* objectp = node->getObject();
+                if (!objectp)
+                    continue;
+                // do roots first, then children so that root flags are cleared ASAP
+                BOOL roots_only = (pass == 0);
+                BOOL is_root = (objectp->isRootEdit());
+                if (roots_only != is_root || objectp->mDrawable.isNull())
+                {
+                    continue;
+                }
+
+                if (!node->mSilhouetteExists
+                    || objectp->isChanged(LLXform::SILHOUETTE)
+                    || (objectp->getParent() && objectp->getParent()->isChanged(LLXform::SILHOUETTE)))
+                {
+                    if (num_sils_genned++ < MAX_SILS_PER_FRAME)// && objectp->mDrawable->isVisible())
+                    {
+                        generateSilhouette(node, viewer_cam_origin);
+                        changed_objects.push_back(objectp);
+                    }
+                    else if (objectp->isAttachment())
+                    {
+                        //RN: hack for orthogonal projection of HUD attachments
+                        LLViewerJointAttachment* attachment_pt = (LLViewerJointAttachment*)objectp->getRootEdit()->mDrawable->getParent();
+                        if (attachment_pt && attachment_pt->getIsHUDAttachment())
+                        {
+                            LLVector3 camera_pos = LLVector3(-10000.f, 0.f, 0.f);
+                            generateSilhouette(node, camera_pos);
+                        }
+                    }
+                }
+            }
+        }
+    }
+}
+void LLSelectMgr::renderSilhouettes(BOOL for_hud)
+{
+    if (!mRenderSilhouettes || !mRenderHighlightSelections)
+    {
+        return;
+    }
+
+    gGL.getTexUnit(0)->bind(mSilhouetteImagep);
+    LLGLSPipelineSelection gls_select;
+    LLGLEnable blend(GL_BLEND);
+    LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
+
+    if (isAgentAvatarValid() && for_hud)
+    {
+        LLBBox hud_bbox = gAgentAvatarp->getHUDBBox();
+
+        F32 cur_zoom = gAgentCamera.mHUDCurZoom;
+
+        // set up transform to encompass bounding box of HUD
+        gGL.matrixMode(LLRender::MM_PROJECTION);
+        gGL.pushMatrix();
+        gGL.loadIdentity();
+        F32 depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
+        auto& viewerCamera = LLViewerCamera::instance();
+        gGL.ortho(-0.5f * viewerCamera.getAspect(), 0.5f * viewerCamera.getAspect(), -0.5f, 0.5f, 0.f, depth);
+
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+        gGL.pushMatrix();
+        gGL.pushUIMatrix();
+        gGL.loadUIIdentity();
+        gGL.loadIdentity();
+        gGL.loadMatrix(OGL_TO_CFR_ROTATION_4A);     // Load Cory's favorite reference frame
+        gGL.translatef(-hud_bbox.getCenterLocal().mV[VX] + (depth *0.5f), 0.f, 0.f);
+        gGL.scalef(cur_zoom, cur_zoom, cur_zoom);
+    }
+
+    bool wireframe_selection = (gFloaterTools && gFloaterTools->getVisible()) || LLSelectMgr::sRenderHiddenSelections;
+    F32 fogCfx = (F32)llclamp((getSelectionCenterGlobal() - gAgentCamera.getCameraPositionGlobal()).magVec() / (getBBoxOfSelection().getExtentLocal().magVec() * 4), 0.0, 1.0);
+
+    LLColor4 sParentColor = sSilhouetteParentColor;
+    sParentColor.mV[3] = LLSelectMgr::sHighlightAlpha;
+    LLColor4 sChildColor = sSilhouetteChildColor;
+    sChildColor.mV[3] = LLSelectMgr::sHighlightAlpha;
+
+    auto renderMeshSelection_f = [fogCfx, wireframe_selection](LLSelectNode* node, LLViewerObject* objectp, LLColor4 hlColor)
+    {
+        LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
+
+        if (shader)
+        {
+            gDebugProgram.bind();
+        }
+
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+        gGL.pushMatrix();
+
+        BOOL is_hud_object = objectp->isHUDAttachment();
+
+        if (!is_hud_object)
+        {
+            gGL.loadIdentity();
+            gGL.multMatrix(gGLModelView);
+        }
+
+        if (objectp->mDrawable->isActive())
+        {
+            gGL.multMatrix(objectp->getRenderMatrix());
+        }
+        else if (!is_hud_object)
+        {
+            LLVector3 trans = objectp->getRegion()->getOriginAgent();
+            gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);
+        }
+
+        bool bRenderHidenSelection = node->isTransient() ? false : LLSelectMgr::sRenderHiddenSelections;
+
+
+        LLVOVolume* vobj = objectp->mDrawable->getVOVolume();
+        if (vobj)
+        {
+            LLVertexBuffer::unbind();
+            gGL.pushMatrix();
+            gGL.multMatrix(vobj->getRelativeXform());
+
+            if (objectp->mDrawable->isState(LLDrawable::RIGGED))
+            {
+                vobj->updateRiggedVolume(true);
+            }
+        }
+
+        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
+        S32 num_tes = llmin((S32)objectp->getNumTEs(), (S32)objectp->getNumFaces()); // avatars have TEs but no faces
+        for (S32 te = 0; te < num_tes; ++te)
+        {
+            if (node->isTESelected(te))
+            {
+                objectp->mDrawable->getFace(te)->renderOneWireframe(hlColor, fogCfx, wireframe_selection, bRenderHidenSelection, nullptr != shader);
+            }
+        }
+
+        gGL.popMatrix();
+        gGL.popMatrix();
+
+        gGL.setLineWidth(1.f);
+        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+
+        if (shader)
+        {
+            shader->bind();
+        }
+    };
+
+    if (mSelectedObjects->getNumNodes())
+    {
+        LLUUID inspect_item_id= LLUUID::null;
+        LLFloaterInspect* inspect_instance = LLFloaterReg::findTypedInstance<LLFloaterInspect>("inspect");
+        if(inspect_instance && inspect_instance->getVisible())
+        {
+            inspect_item_id = inspect_instance->getSelectedUUID();
+        }
+        else
+        {
+            LLSidepanelTaskInfo *panel_task_info = LLSidepanelTaskInfo::getActivePanel();
+            if (panel_task_info)
+            {
+                inspect_item_id = panel_task_info->getSelectedUUID();
+            }
+        }
+
+        LLUUID focus_item_id = LLViewerMediaFocus::getInstance()->getFocusedObjectID();
+        {
+            for (LLSelectNode* node : mSelectedObjects->begin_end())
+            {
+                if (getTEMode() && !node->hasSelectedTE())
+                    continue;
+
+                LLViewerObject* objectp = node->getObject();
+                if (!objectp)
+                    continue;
+
+                if (objectp->mDrawable
+                    && objectp->mDrawable->getVOVolume()
+                    && objectp->mDrawable->getVOVolume()->isMesh())
+                {
+                    LLColor4 hlColor = objectp->isRootEdit() ? sParentColor : sChildColor;
+                    if (objectp->getID() == inspect_item_id)
+                    {
+                        hlColor = sHighlightInspectColor;
+                    }
+                    else if (node->isTransient())
+                    {
+                        hlColor = sContextSilhouetteColor.get() * 0.5f;
+                    }
+                    renderMeshSelection_f(node, objectp, hlColor);
+                }
+                else
+                {
+                    if (objectp->isHUDAttachment() != for_hud)
+                    {
+                        continue;
+                    }
+                    if (objectp->getID() == focus_item_id)
+                    {
+                        node->renderOneSilhouette(gFocusMgr.getFocusColor());
+                    }
+                    else if (objectp->getID() == inspect_item_id)
+                    {
+                        node->renderOneSilhouette(sHighlightInspectColor);
+                    }
+                    else if (node->isTransient())
+                    {
+                        BOOL oldHidden = LLSelectMgr::sRenderHiddenSelections;
+                        LLSelectMgr::sRenderHiddenSelections = FALSE;
+                        node->renderOneSilhouette(sContextSilhouetteColor.get() * 0.5f);
+                        LLSelectMgr::sRenderHiddenSelections = oldHidden;
+                    }
+                    else if (objectp->isRootEdit())
+                    {
+                        node->renderOneSilhouette(sSilhouetteParentColor);
+                    }
+                    else
+                    {
+                        node->renderOneSilhouette(sSilhouetteChildColor);
+                    }
+                }
+            } //for all selected node's
+        } //for pass
+    }
+
+    if (mHighlightedObjects->getNumNodes())
+    {
+        // render silhouettes for highlighted objects
+        BOOL subtracting_from_selection = (gKeyboard->currentMask(TRUE) == MASK_CONTROL);
+        for (S32 pass = 0; pass < 2; pass++)
+        {
+            for (LLSelectNode* node : mHighlightedObjects->begin_end())
+            {
+                LLViewerObject* objectp = node->getObject();
+                if (!objectp)
+                    continue;
+                if (objectp->isHUDAttachment() != for_hud)
+                {
+                    continue;
+                }
+
+                LLColor4 highlight_color = objectp->isRoot() ? sHighlightParentColor : sHighlightChildColor;
+                if (objectp->mDrawable
+                    && objectp->mDrawable->getVOVolume()
+                    && objectp->mDrawable->getVOVolume()->isMesh())
+                {
+                    renderMeshSelection_f(node, objectp, subtracting_from_selection ? LLColor4::red : highlight_color);
+                }
+                else if (subtracting_from_selection)
+                {
+                    node->renderOneSilhouette(LLColor4::red);
+                }
+                else if (!objectp->isSelected())
+                {
+                    node->renderOneSilhouette(highlight_color);
+                }
+            }
+        }
+    }
+
+    if (isAgentAvatarValid() && for_hud)
+    {
+        gGL.matrixMode(LLRender::MM_PROJECTION);
+        gGL.popMatrix();
+
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+        gGL.popMatrix();
+        gGL.popUIMatrix();
+        stop_glerror();
+    }
+
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+}
+
+void LLSelectMgr::generateSilhouette(LLSelectNode* nodep, const LLVector3& view_point)
+{
+    LLViewerObject* objectp = nodep->getObject();
+
+    if (objectp && objectp->getPCode() == LL_PCODE_VOLUME)
+    {
+        ((LLVOVolume*)objectp)->generateSilhouette(nodep, view_point);
+    }
+}
+
+//
+// Utility classes
+//
 LLSelectNode::LLSelectNode(LLViewerObject* object, BOOL glow)
-:	mObject(object),
-	mIndividualSelection(FALSE),
-	mTransient(FALSE),
-	mValid(FALSE),
-	mPermissions(new LLPermissions()),
-	mInventorySerial(0),
-	mSilhouetteExists(FALSE),
-	mDuplicated(FALSE),
-	mTESelectMask(0),
-	mLastTESelected(0),
-	mName(LLStringUtil::null),
-	mDescription(LLStringUtil::null),
-	mTouchName(LLStringUtil::null),
-	mSitName(LLStringUtil::null),
-	mCreationDate(0)
-{
-	saveColors();
-	saveShinyColors();
+:   mObject(object),
+    mIndividualSelection(FALSE),
+    mTransient(FALSE),
+    mValid(FALSE),
+    mPermissions(new LLPermissions()),
+    mInventorySerial(0),
+    mSilhouetteExists(FALSE),
+    mDuplicated(FALSE),
+    mTESelectMask(0),
+    mLastTESelected(0),
+    mName(LLStringUtil::null),
+    mDescription(LLStringUtil::null),
+    mTouchName(LLStringUtil::null),
+    mSitName(LLStringUtil::null),
+    mCreationDate(0)
+{
+    saveColors();
+    saveShinyColors();
 }
 
 LLSelectNode::LLSelectNode(const LLSelectNode& nodep)
 {
-	mTESelectMask = nodep.mTESelectMask;
-	mLastTESelected = nodep.mLastTESelected;
-
-	mIndividualSelection = nodep.mIndividualSelection;
-
-	mValid = nodep.mValid;
-	mTransient		= nodep.mTransient;
-	mPermissions = new LLPermissions(*nodep.mPermissions);
-	mSaleInfo = nodep.mSaleInfo;;
-	mAggregatePerm = nodep.mAggregatePerm;
-	mAggregateTexturePerm = nodep.mAggregateTexturePerm;
-	mAggregateTexturePermOwner = nodep.mAggregateTexturePermOwner;
-	mName = nodep.mName;
-	mDescription = nodep.mDescription;
-	mCategory = nodep.mCategory;
-	mInventorySerial = 0;
-	mSavedPositionLocal = nodep.mSavedPositionLocal;
-	mSavedPositionGlobal = nodep.mSavedPositionGlobal;
-	mSavedScale = nodep.mSavedScale;
-	mSavedRotation = nodep.mSavedRotation;
-	mDuplicated = nodep.mDuplicated;
-	mDuplicatePos = nodep.mDuplicatePos;
-	mDuplicateRot = nodep.mDuplicateRot;
-	mItemID = nodep.mItemID;
-	mFolderID = nodep.mFolderID;
-	mFromTaskID = nodep.mFromTaskID;
-	mTouchName = nodep.mTouchName;
-	mSitName = nodep.mSitName;
-	mCreationDate = nodep.mCreationDate;
-
-	mSilhouetteVertices = nodep.mSilhouetteVertices;
-	mSilhouetteNormals = nodep.mSilhouetteNormals;
-	mSilhouetteExists = nodep.mSilhouetteExists;
-	mObject = nodep.mObject;
-
-	mSavedColors = nodep.mSavedColors;
-	mSavedShinyColors = nodep.mSavedShinyColors;
-	
-	saveTextures(nodep.mSavedTextures);
+    mTESelectMask = nodep.mTESelectMask;
+    mLastTESelected = nodep.mLastTESelected;
+
+    mIndividualSelection = nodep.mIndividualSelection;
+
+    mValid = nodep.mValid;
+    mTransient      = nodep.mTransient;
+    mPermissions = new LLPermissions(*nodep.mPermissions);
+    mSaleInfo = nodep.mSaleInfo;;
+    mAggregatePerm = nodep.mAggregatePerm;
+    mAggregateTexturePerm = nodep.mAggregateTexturePerm;
+    mAggregateTexturePermOwner = nodep.mAggregateTexturePermOwner;
+    mName = nodep.mName;
+    mDescription = nodep.mDescription;
+    mCategory = nodep.mCategory;
+    mInventorySerial = 0;
+    mSavedPositionLocal = nodep.mSavedPositionLocal;
+    mSavedPositionGlobal = nodep.mSavedPositionGlobal;
+    mSavedScale = nodep.mSavedScale;
+    mSavedRotation = nodep.mSavedRotation;
+    mDuplicated = nodep.mDuplicated;
+    mDuplicatePos = nodep.mDuplicatePos;
+    mDuplicateRot = nodep.mDuplicateRot;
+    mItemID = nodep.mItemID;
+    mFolderID = nodep.mFolderID;
+    mFromTaskID = nodep.mFromTaskID;
+    mTouchName = nodep.mTouchName;
+    mSitName = nodep.mSitName;
+    mCreationDate = nodep.mCreationDate;
+
+    mSilhouetteVertices = nodep.mSilhouetteVertices;
+    mSilhouetteNormals = nodep.mSilhouetteNormals;
+    mSilhouetteExists = nodep.mSilhouetteExists;
+    mObject = nodep.mObject;
+
+    mSavedColors = nodep.mSavedColors;
+    mSavedShinyColors = nodep.mSavedShinyColors;
+
+    saveTextures(nodep.mSavedTextures);
     saveGLTFMaterials(nodep.mSavedGLTFMaterialIds, nodep.mSavedGLTFOverrideMaterials);
 }
 
@@ -6646,445 +6646,445 @@ LLSelectNode::~LLSelectNode()
         }
     }
 
-    delete mPermissions;
-	mPermissions = NULL;
+    delete mPermissions;
+    mPermissions = NULL;
+}
+
+void LLSelectNode::selectAllTEs(BOOL b)
+{
+    mTESelectMask = b ? TE_SELECT_MASK_ALL : 0x0;
+    mLastTESelected = 0;
+}
+
+void LLSelectNode::selectTE(S32 te_index, BOOL selected)
+{
+    if (te_index < 0 || te_index >= SELECT_MAX_TES)
+    {
+        return;
+    }
+    S32 mask = 0x1 << te_index;
+    if(selected)
+    {
+        mTESelectMask |= mask;
+    }
+    else
+    {
+        mTESelectMask &= ~mask;
+    }
+    mLastTESelected = te_index;
+}
+
+void LLSelectNode::selectGLTFNode(S32 node_index, S32 primitive_index, bool selected)
+{
+    if (node_index < 0)
+    {
+        return;
+    }
+
+    mSelectedGLTFNode = node_index;
+    mSelectedGLTFPrimitive = primitive_index;
+}
+
+BOOL LLSelectNode::isTESelected(S32 te_index) const
+{
+    if (te_index < 0 || te_index >= mObject->getNumTEs())
+    {
+        return FALSE;
+    }
+    return (mTESelectMask & (0x1 << te_index)) != 0;
+}
+
+S32 LLSelectNode::getLastSelectedTE() const
+{
+    if (!isTESelected(mLastTESelected))
+    {
+        return -1;
+    }
+    return mLastTESelected;
+}
+
+LLViewerObject* LLSelectNode::getObject() const
+{
+    if (!mObject)
+    {
+        return NULL;
+    }
+    else if (mObject->isDead())
+    {
+        mObject = nullptr;
+    }
+    return mObject;
+}
+
+void LLSelectNode::setObject(LLViewerObject* object)
+{
+    mObject = object;
+}
+
+void LLSelectNode::saveColors()
+{
+    if (mObject.notNull())
+    {
+        mSavedColors.clear();
+        for (S32 i = 0; i < mObject->getNumTEs(); i++)
+        {
+            const LLTextureEntry* tep = mObject->getTE(i);
+            mSavedColors.push_back(tep->getColor());
+        }
+    }
+}
+
+void LLSelectNode::saveShinyColors()
+{
+    if (mObject.notNull())
+    {
+        mSavedShinyColors.clear();
+        for (S32 i = 0; i < mObject->getNumTEs(); i++)
+        {
+            const LLMaterialPtr mat = mObject->getTE(i)->getMaterialParams();
+            if (!mat.isNull())
+            {
+                mSavedShinyColors.push_back(mat->getSpecularLightColor());
+            }
+            else
+            {
+                mSavedShinyColors.push_back(LLColor4::white);
+            }
+        }
+    }
+}
+
+void LLSelectNode::saveTextures(const uuid_vec_t& textures)
+{
+    if (mObject.notNull())
+    {
+        mSavedTextures = textures;
+    }
+}
+
+void LLSelectNode::saveGLTFMaterials(const uuid_vec_t& materials, const gltf_materials_vec_t& override_materials)
+{
+    if (mObject.notNull())
+    {
+        mSavedGLTFMaterialIds.clear();
+        mSavedGLTFOverrideMaterials.clear();
+
+        for (uuid_vec_t::const_iterator materials_it = materials.begin();
+            materials_it != materials.end(); ++materials_it)
+        {
+            mSavedGLTFMaterialIds.push_back(*materials_it);
+        }
+
+        for (gltf_materials_vec_t::const_iterator mat_it = override_materials.begin();
+            mat_it != override_materials.end(); ++mat_it)
+        {
+            mSavedGLTFOverrideMaterials.push_back(*mat_it);
+        }
+    }
+}
+
+void LLSelectNode::saveTextureScaleRatios(LLRender::eTexIndex index_to_query)
+{
+    mTextureScaleRatios.clear();
+
+    if (mObject.notNull())
+    {
+
+        LLVector3 scale = mObject->getScale();
+
+        for (U8 i = 0; i < mObject->getNumTEs(); i++)
+        {
+            F32 diffuse_s = 1.0f;
+            F32 diffuse_t = 1.0f;
+
+            LLVector3 v;
+            const LLTextureEntry* tep = mObject->getTE(i);
+            if (!tep)
+                continue;
+
+            U32 s_axis = VX;
+            U32 t_axis = VY;
+            LLPrimitive::getTESTAxes(i, &s_axis, &t_axis);
+
+            tep->getScale(&diffuse_s,&diffuse_t);
+
+            if (tep->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR)
+            {
+                v.mV[s_axis] = diffuse_s*scale.mV[s_axis];
+                v.mV[t_axis] = diffuse_t*scale.mV[t_axis];
+                mTextureScaleRatios.push_back(v);
+            }
+            else
+            {
+                v.mV[s_axis] = diffuse_s/scale.mV[s_axis];
+                v.mV[t_axis] = diffuse_t/scale.mV[t_axis];
+                mTextureScaleRatios.push_back(v);
+            }
+        }
+    }
+}
+
+
+// This implementation should be similar to LLTask::allowOperationOnTask
+BOOL LLSelectNode::allowOperationOnNode(PermissionBit op, U64 group_proxy_power) const
+{
+    // Extract ownership.
+    BOOL object_is_group_owned = FALSE;
+    LLUUID object_owner_id;
+    mPermissions->getOwnership(object_owner_id, object_is_group_owned);
+
+    // Operations on invalid or public objects is not allowed.
+    if (!mObject || (mObject->isDead()) || !mPermissions->isOwned())
+    {
+        return FALSE;
+    }
+
+    // The transfer permissions can never be given through proxy.
+    if (PERM_TRANSFER == op)
+    {
+        // The owner of an agent-owned object can transfer to themselves.
+        if ( !object_is_group_owned
+            && (gAgent.getID() == object_owner_id) )
+        {
+            return TRUE;
+        }
+        else
+        {
+            // Otherwise check aggregate permissions.
+            return mObject->permTransfer();
+        }
+    }
+
+    if (PERM_MOVE == op
+        || PERM_MODIFY == op)
+    {
+        // only owners can move or modify their attachments
+        // no proxy allowed.
+        if (mObject->isAttachment() && object_owner_id != gAgent.getID())
+        {
+            return FALSE;
+        }
+    }
+
+    // Calculate proxy_agent_id and group_id to use for permissions checks.
+    // proxy_agent_id may be set to the object owner through group powers.
+    // group_id can only be set to the object's group, if the agent is in that group.
+    LLUUID group_id = LLUUID::null;
+    LLUUID proxy_agent_id = gAgent.getID();
+
+    // Gods can always operate.
+    if (gAgent.isGodlike())
+    {
+        return TRUE;
+    }
+
+    // Check if the agent is in the same group as the object.
+    LLUUID object_group_id = mPermissions->getGroup();
+    if (object_group_id.notNull() &&
+        gAgent.isInGroup(object_group_id))
+    {
+        // Assume the object's group during this operation.
+        group_id = object_group_id;
+    }
+
+    // Only allow proxy powers for PERM_COPY if the actual agent can
+    // receive the item (ie has PERM_TRANSFER permissions).
+    // NOTE: op == PERM_TRANSFER has already been handled, but if
+    // that ever changes we need to BLOCK proxy powers for PERM_TRANSFER.  DK 03/28/06
+    if (PERM_COPY != op || mPermissions->allowTransferTo(gAgent.getID()))
+    {
+        // Check if the agent can assume ownership through group proxy or agent-granted proxy.
+        if (   ( object_is_group_owned
+                && gAgent.hasPowerInGroup(object_owner_id, group_proxy_power))
+                // Only allow proxy for move, modify, and copy.
+                || ( (PERM_MOVE == op || PERM_MODIFY == op || PERM_COPY == op)
+                    && (!object_is_group_owned
+                        && gAgent.isGrantedProxy(*mPermissions))))
+        {
+            // This agent is able to assume the ownership role for this operation.
+            proxy_agent_id = object_owner_id;
+        }
+    }
+
+    // We now have max ownership information.
+    if (PERM_OWNER == op)
+    {
+        // This this was just a check for ownership, we can now return the answer.
+        return (proxy_agent_id == object_owner_id ? TRUE : FALSE);
+    }
+
+    // check permissions to see if the agent can operate
+    return (mPermissions->allowOperationBy(op, proxy_agent_id, group_id));
 }
 
-void LLSelectNode::selectAllTEs(BOOL b)
+//-----------------------------------------------------------------------------
+// renderOneSilhouette()
+//-----------------------------------------------------------------------------
+void LLSelectNode::renderOneSilhouette(const LLColor4 &color)
 {
-	mTESelectMask = b ? TE_SELECT_MASK_ALL : 0x0;
-	mLastTESelected = 0;
-}
+    LLViewerObject* objectp = getObject();
+    if (!objectp)
+    {
+        return;
+    }
 
-void LLSelectNode::selectTE(S32 te_index, BOOL selected)
-{
-	if (te_index < 0 || te_index >= SELECT_MAX_TES)
-	{
-		return;
-	}
-	S32 mask = 0x1 << te_index;
-	if(selected)
-	{	
-		mTESelectMask |= mask;
-	}
-	else
-	{
-		mTESelectMask &= ~mask;
-	}
-	mLastTESelected = te_index;
-}
+    LLDrawable* drawable = objectp->mDrawable;
+    if(!drawable)
+    {
+        return;
+    }
 
-void LLSelectNode::selectGLTFNode(S32 node_index, S32 primitive_index, bool selected)
-{
-    if (node_index < 0)
+    LLVOVolume* vobj = drawable->getVOVolume();
+    if (vobj && vobj->isMesh())
     {
+        //This check (if(...)) with assert here just for ensure that this situation will not happens, and can be removed later. For example on the next release.
+        llassert(!"renderOneWireframe() was removed SL-10194");
         return;
     }
 
-    mSelectedGLTFNode = node_index;
-    mSelectedGLTFPrimitive = primitive_index;
-}
+    if (!mSilhouetteExists)
+    {
+        return;
+    }
 
-BOOL LLSelectNode::isTESelected(S32 te_index) const
-{
-	if (te_index < 0 || te_index >= mObject->getNumTEs())
-	{
-		return FALSE;
-	}
-	return (mTESelectMask & (0x1 << te_index)) != 0;
-}
+    BOOL is_hud_object = objectp->isHUDAttachment();
 
-S32 LLSelectNode::getLastSelectedTE() const
-{
-	if (!isTESelected(mLastTESelected))
-	{
-		return -1;
-	}
-	return mLastTESelected;
-}
+    if (mSilhouetteVertices.size() == 0 || mSilhouetteNormals.size() != mSilhouetteVertices.size())
+    {
+        return;
+    }
 
-LLViewerObject* LLSelectNode::getObject() const
-{
-	if (!mObject)
-	{
-		return NULL;
-	}
-	else if (mObject->isDead())
-	{
-		mObject = nullptr;
-	}
-	return mObject;
-}
 
-void LLSelectNode::setObject(LLViewerObject* object)
-{
-	mObject = object;
-}
+    LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
 
-void LLSelectNode::saveColors()
-{
-	if (mObject.notNull())
-	{
-		mSavedColors.clear();
-		for (S32 i = 0; i < mObject->getNumTEs(); i++)
-		{
-			const LLTextureEntry* tep = mObject->getTE(i);
-			mSavedColors.push_back(tep->getColor());
-		}
-	}
-}
+    if (shader)
+    { //use UI program for selection highlights (texture color modulated by vertex color)
+        gUIProgram.bind();
+    }
 
-void LLSelectNode::saveShinyColors()
-{
-	if (mObject.notNull())
-	{
-		mSavedShinyColors.clear();
-		for (S32 i = 0; i < mObject->getNumTEs(); i++)
-		{
-			const LLMaterialPtr mat = mObject->getTE(i)->getMaterialParams();
-			if (!mat.isNull())
-			{
-				mSavedShinyColors.push_back(mat->getSpecularLightColor());
-			}
-			else
-			{
-				mSavedShinyColors.push_back(LLColor4::white);
-			}
-		}
-	}
-}
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+    gGL.pushUIMatrix();
+    gGL.loadUIIdentity();
 
-void LLSelectNode::saveTextures(const uuid_vec_t& textures)
-{
-	if (mObject.notNull())
-	{
-		mSavedTextures = textures;
-	}
-}
+    if (!is_hud_object)
+    {
+        gGL.loadIdentity();
+        gGL.multMatrix(gGLModelView);
+    }
 
-void LLSelectNode::saveGLTFMaterials(const uuid_vec_t& materials, const gltf_materials_vec_t& override_materials)
-{
-    if (mObject.notNull())
+
+    if (drawable->isActive())
     {
-        mSavedGLTFMaterialIds.clear();
-        mSavedGLTFOverrideMaterials.clear();
+        gGL.multMatrix(objectp->getRenderMatrix());
+    }
 
-        for (uuid_vec_t::const_iterator materials_it = materials.begin();
-            materials_it != materials.end(); ++materials_it)
+    LLVolume *volume = objectp->getVolume();
+    if (volume)
+    {
+        auto& viewerCamera = LLViewerCamera::instance();
+
+        F32 silhouette_thickness;
+        if (isAgentAvatarValid() && is_hud_object)
         {
-            mSavedGLTFMaterialIds.push_back(*materials_it);
+            silhouette_thickness = LLSelectMgr::sHighlightThickness / gAgentCamera.mHUDCurZoom;
         }
-
-        for (gltf_materials_vec_t::const_iterator mat_it = override_materials.begin();
-            mat_it != override_materials.end(); ++mat_it)
+        else
         {
-            mSavedGLTFOverrideMaterials.push_back(*mat_it);
+            LLVector3 view_vector = viewerCamera.getOrigin() - objectp->getRenderPosition();
+            silhouette_thickness = view_vector.magVec() * LLSelectMgr::sHighlightThickness * (viewerCamera.getView() / viewerCamera.getDefaultFOV());
         }
-    }
-}
-
-void LLSelectNode::saveTextureScaleRatios(LLRender::eTexIndex index_to_query)
-{
-	mTextureScaleRatios.clear();
-
-	if (mObject.notNull())
-	{
-		
-		LLVector3 scale = mObject->getScale();
-
-		for (U8 i = 0; i < mObject->getNumTEs(); i++)
-		{
-			F32 diffuse_s = 1.0f;
-			F32 diffuse_t = 1.0f;
-			
-			LLVector3 v;
-			const LLTextureEntry* tep = mObject->getTE(i);
-			if (!tep)
-				continue;
-
-			U32 s_axis = VX;
-			U32 t_axis = VY;
-			LLPrimitive::getTESTAxes(i, &s_axis, &t_axis);
-
-			tep->getScale(&diffuse_s,&diffuse_t);
-
-			if (tep->getTexGen() == LLTextureEntry::TEX_GEN_PLANAR)
-			{
-				v.mV[s_axis] = diffuse_s*scale.mV[s_axis];
-				v.mV[t_axis] = diffuse_t*scale.mV[t_axis];
-				mTextureScaleRatios.push_back(v);
-			}
-			else
-			{
-				v.mV[s_axis] = diffuse_s/scale.mV[s_axis];
-				v.mV[t_axis] = diffuse_t/scale.mV[t_axis];
-				mTextureScaleRatios.push_back(v);
-			}
-		}
-	}
-}
+        F32 animationTime = (F32)LLFrameTimer::getElapsedSeconds();
 
+        F32 u_coord = fmod(animationTime * LLSelectMgr::sHighlightUAnim, 1.f);
+        F32 v_coord = 1.f - fmod(animationTime * LLSelectMgr::sHighlightVAnim, 1.f);
+        F32 u_divisor = 1.f / ((F32)(mSilhouetteVertices.size() - 1));
 
-// This implementation should be similar to LLTask::allowOperationOnTask
-BOOL LLSelectNode::allowOperationOnNode(PermissionBit op, U64 group_proxy_power) const
-{
-	// Extract ownership.
-	BOOL object_is_group_owned = FALSE;
-	LLUUID object_owner_id;
-	mPermissions->getOwnership(object_owner_id, object_is_group_owned);
-
-	// Operations on invalid or public objects is not allowed.
-	if (!mObject || (mObject->isDead()) || !mPermissions->isOwned())
-	{
-		return FALSE;
-	}
-
-	// The transfer permissions can never be given through proxy.
-	if (PERM_TRANSFER == op)
-	{
-		// The owner of an agent-owned object can transfer to themselves.
-		if ( !object_is_group_owned 
-			&& (gAgent.getID() == object_owner_id) )
-		{
-			return TRUE;
-		}
-		else
-		{
-			// Otherwise check aggregate permissions.
-			return mObject->permTransfer();
-		}
-	}
-
-	if (PERM_MOVE == op
-		|| PERM_MODIFY == op)
-	{
-		// only owners can move or modify their attachments
-		// no proxy allowed.
-		if (mObject->isAttachment() && object_owner_id != gAgent.getID())
-		{
-			return FALSE;
-		}
-	}
-
-	// Calculate proxy_agent_id and group_id to use for permissions checks.
-	// proxy_agent_id may be set to the object owner through group powers.
-	// group_id can only be set to the object's group, if the agent is in that group.
-	LLUUID group_id = LLUUID::null;
-	LLUUID proxy_agent_id = gAgent.getID();
-
-	// Gods can always operate.
-	if (gAgent.isGodlike())
-	{
-		return TRUE;
-	}
-
-	// Check if the agent is in the same group as the object.
-	LLUUID object_group_id = mPermissions->getGroup();
-	if (object_group_id.notNull() &&
-		gAgent.isInGroup(object_group_id))
-	{
-		// Assume the object's group during this operation.
-		group_id = object_group_id;
-	}
-
-	// Only allow proxy powers for PERM_COPY if the actual agent can
-	// receive the item (ie has PERM_TRANSFER permissions).
-	// NOTE: op == PERM_TRANSFER has already been handled, but if
-	// that ever changes we need to BLOCK proxy powers for PERM_TRANSFER.  DK 03/28/06
-	if (PERM_COPY != op || mPermissions->allowTransferTo(gAgent.getID()))
-	{
-		// Check if the agent can assume ownership through group proxy or agent-granted proxy.
-		if (   ( object_is_group_owned 
-				&& gAgent.hasPowerInGroup(object_owner_id, group_proxy_power))
-				// Only allow proxy for move, modify, and copy.
-				|| ( (PERM_MOVE == op || PERM_MODIFY == op || PERM_COPY == op)
-					&& (!object_is_group_owned
-						&& gAgent.isGrantedProxy(*mPermissions))))
-		{
-			// This agent is able to assume the ownership role for this operation.
-			proxy_agent_id = object_owner_id;
-		}
-	}
-	
-	// We now have max ownership information.
-	if (PERM_OWNER == op)
-	{
-		// This this was just a check for ownership, we can now return the answer.
-		return (proxy_agent_id == object_owner_id ? TRUE : FALSE);
-	}
-
-	// check permissions to see if the agent can operate
-	return (mPermissions->allowOperationBy(op, proxy_agent_id, group_id));
-}
+        if (LLSelectMgr::sRenderHiddenSelections) // && gFloaterTools && gFloaterTools->getVisible())
+        {
+            gGL.flush();
+            gGL.blendFunc(LLRender::BF_SOURCE_COLOR, LLRender::BF_ONE);
 
-//-----------------------------------------------------------------------------
-// renderOneSilhouette()
-//-----------------------------------------------------------------------------
-void LLSelectNode::renderOneSilhouette(const LLColor4 &color)
-{
-	LLViewerObject* objectp = getObject();
-	if (!objectp)
-	{
-		return;
-	}
-
-	LLDrawable* drawable = objectp->mDrawable;
-	if(!drawable)
-	{
-		return;
-	}
-
-	LLVOVolume* vobj = drawable->getVOVolume();
-	if (vobj && vobj->isMesh())
-	{
-		//This check (if(...)) with assert here just for ensure that this situation will not happens, and can be removed later. For example on the next release.
-		llassert(!"renderOneWireframe() was removed SL-10194");
-		return;
-	}
-
-	if (!mSilhouetteExists)
-	{
-		return;
-	}
-
-	BOOL is_hud_object = objectp->isHUDAttachment();
-	
-	if (mSilhouetteVertices.size() == 0 || mSilhouetteNormals.size() != mSilhouetteVertices.size())
-	{
-		return;
-	}
-
-
-	LLGLSLShader* shader = LLGLSLShader::sCurBoundShaderPtr;
-
-	if (shader)
-	{ //use UI program for selection highlights (texture color modulated by vertex color)
-		gUIProgram.bind();
-	}
-
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-	gGL.pushUIMatrix();
-	gGL.loadUIIdentity();
-
-	if (!is_hud_object)
-	{
-		gGL.loadIdentity();
-		gGL.multMatrix(gGLModelView);
-	}
-	
-	
-	if (drawable->isActive())
-	{
-		gGL.multMatrix(objectp->getRenderMatrix());
-	}
-
-	LLVolume *volume = objectp->getVolume();
-	if (volume)
-	{
-		auto& viewerCamera = LLViewerCamera::instance();
-
-		F32 silhouette_thickness;
-		if (isAgentAvatarValid() && is_hud_object)
-		{
-			silhouette_thickness = LLSelectMgr::sHighlightThickness / gAgentCamera.mHUDCurZoom;
-		}
-		else
-		{
-			LLVector3 view_vector = viewerCamera.getOrigin() - objectp->getRenderPosition();
-			silhouette_thickness = view_vector.magVec() * LLSelectMgr::sHighlightThickness * (viewerCamera.getView() / viewerCamera.getDefaultFOV());
-		}		
-		F32 animationTime = (F32)LLFrameTimer::getElapsedSeconds();
-
-		F32 u_coord = fmod(animationTime * LLSelectMgr::sHighlightUAnim, 1.f);
-		F32 v_coord = 1.f - fmod(animationTime * LLSelectMgr::sHighlightVAnim, 1.f);
-		F32 u_divisor = 1.f / ((F32)(mSilhouetteVertices.size() - 1));
-
-		if (LLSelectMgr::sRenderHiddenSelections) // && gFloaterTools && gFloaterTools->getVisible())
-		{
-			gGL.flush();
-			gGL.blendFunc(LLRender::BF_SOURCE_COLOR, LLRender::BF_ONE);
-			
             LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE, GL_GEQUAL);
             gGL.flush();
-			gGL.begin(LLRender::LINES);
-			{
-				gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], 0.4f);
-
-				for(S32 i = 0; i < mSilhouetteVertices.size(); i += 2)
-				{
-					u_coord += u_divisor * LLSelectMgr::sHighlightUScale;
-					gGL.texCoord2f( u_coord, v_coord );
-					gGL.vertex3fv( mSilhouetteVertices[i].mV);
-					u_coord += u_divisor * LLSelectMgr::sHighlightUScale;
-					gGL.texCoord2f( u_coord, v_coord );
-					gGL.vertex3fv(mSilhouetteVertices[i+1].mV);
-				}
-			}
+            gGL.begin(LLRender::LINES);
+            {
+                gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], 0.4f);
+
+                for(S32 i = 0; i < mSilhouetteVertices.size(); i += 2)
+                {
+                    u_coord += u_divisor * LLSelectMgr::sHighlightUScale;
+                    gGL.texCoord2f( u_coord, v_coord );
+                    gGL.vertex3fv( mSilhouetteVertices[i].mV);
+                    u_coord += u_divisor * LLSelectMgr::sHighlightUScale;
+                    gGL.texCoord2f( u_coord, v_coord );
+                    gGL.vertex3fv(mSilhouetteVertices[i+1].mV);
+                }
+            }
             gGL.end();
-			u_coord = fmod(animationTime * LLSelectMgr::sHighlightUAnim, 1.f);
-		}
-
-		gGL.flush();
-		gGL.setSceneBlendType(LLRender::BT_ALPHA);
-		gGL.begin(LLRender::TRIANGLES);
-		{
-			for(S32 i = 0; i < mSilhouetteVertices.size(); i+=2)
-			{
-				if (!mSilhouetteNormals[i].isFinite() ||
-					!mSilhouetteNormals[i+1].isFinite())
-				{ //skip skewed segments
-					continue;
-				}
-
-				LLVector3 v[4];
-				LLVector2 tc[4];
-				v[0] = mSilhouetteVertices[i] + (mSilhouetteNormals[i] * silhouette_thickness);
-				tc[0].set(u_coord, v_coord + LLSelectMgr::sHighlightVScale);
-
-				v[1] = mSilhouetteVertices[i];
-				tc[1].set(u_coord, v_coord);
-
-				u_coord += u_divisor * LLSelectMgr::sHighlightUScale;
-
-				v[2] = mSilhouetteVertices[i+1] + (mSilhouetteNormals[i+1] * silhouette_thickness);
-				tc[2].set(u_coord, v_coord + LLSelectMgr::sHighlightVScale);
-				
-				v[3] = mSilhouetteVertices[i+1];
-				tc[3].set(u_coord,v_coord);
-
-				gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], 0.0f); //LLSelectMgr::sHighlightAlpha);
-				gGL.texCoord2fv(tc[0].mV);
-				gGL.vertex3fv( v[0].mV ); 
-				
-				gGL.color4f(color.mV[VRED]*2, color.mV[VGREEN]*2, color.mV[VBLUE]*2, LLSelectMgr::sHighlightAlpha);
-				gGL.texCoord2fv( tc[1].mV );
-				gGL.vertex3fv( v[1].mV );
-
-				gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], 0.0f); //LLSelectMgr::sHighlightAlpha);
-				gGL.texCoord2fv( tc[2].mV );
-				gGL.vertex3fv( v[2].mV );
-
-				gGL.vertex3fv( v[2].mV );
-
-				gGL.color4f(color.mV[VRED]*2, color.mV[VGREEN]*2, color.mV[VBLUE]*2, LLSelectMgr::sHighlightAlpha);
-				gGL.texCoord2fv( tc[1].mV );
-				gGL.vertex3fv( v[1].mV );
-
-				gGL.texCoord2fv( tc[3].mV );
-				gGL.vertex3fv( v[3].mV );			
-			}
-		}
-		gGL.end();
-		gGL.flush();
-	}
-	gGL.popMatrix();
-	gGL.popUIMatrix();
-
-	if (shader)
-	{
-		shader->bind();
-	}
+            u_coord = fmod(animationTime * LLSelectMgr::sHighlightUAnim, 1.f);
+        }
+
+        gGL.flush();
+        gGL.setSceneBlendType(LLRender::BT_ALPHA);
+        gGL.begin(LLRender::TRIANGLES);
+        {
+            for(S32 i = 0; i < mSilhouetteVertices.size(); i+=2)
+            {
+                if (!mSilhouetteNormals[i].isFinite() ||
+                    !mSilhouetteNormals[i+1].isFinite())
+                { //skip skewed segments
+                    continue;
+                }
+
+                LLVector3 v[4];
+                LLVector2 tc[4];
+                v[0] = mSilhouetteVertices[i] + (mSilhouetteNormals[i] * silhouette_thickness);
+                tc[0].set(u_coord, v_coord + LLSelectMgr::sHighlightVScale);
+
+                v[1] = mSilhouetteVertices[i];
+                tc[1].set(u_coord, v_coord);
+
+                u_coord += u_divisor * LLSelectMgr::sHighlightUScale;
+
+                v[2] = mSilhouetteVertices[i+1] + (mSilhouetteNormals[i+1] * silhouette_thickness);
+                tc[2].set(u_coord, v_coord + LLSelectMgr::sHighlightVScale);
+
+                v[3] = mSilhouetteVertices[i+1];
+                tc[3].set(u_coord,v_coord);
+
+                gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], 0.0f); //LLSelectMgr::sHighlightAlpha);
+                gGL.texCoord2fv(tc[0].mV);
+                gGL.vertex3fv( v[0].mV );
+
+                gGL.color4f(color.mV[VRED]*2, color.mV[VGREEN]*2, color.mV[VBLUE]*2, LLSelectMgr::sHighlightAlpha);
+                gGL.texCoord2fv( tc[1].mV );
+                gGL.vertex3fv( v[1].mV );
+
+                gGL.color4f(color.mV[VRED], color.mV[VGREEN], color.mV[VBLUE], 0.0f); //LLSelectMgr::sHighlightAlpha);
+                gGL.texCoord2fv( tc[2].mV );
+                gGL.vertex3fv( v[2].mV );
+
+                gGL.vertex3fv( v[2].mV );
+
+                gGL.color4f(color.mV[VRED]*2, color.mV[VGREEN]*2, color.mV[VBLUE]*2, LLSelectMgr::sHighlightAlpha);
+                gGL.texCoord2fv( tc[1].mV );
+                gGL.vertex3fv( v[1].mV );
+
+                gGL.texCoord2fv( tc[3].mV );
+                gGL.vertex3fv( v[3].mV );
+            }
+        }
+        gGL.end();
+        gGL.flush();
+    }
+    gGL.popMatrix();
+    gGL.popUIMatrix();
+
+    if (shader)
+    {
+        shader->bind();
+    }
 }
 
 //
@@ -7094,69 +7094,69 @@ void LLSelectNode::renderOneSilhouette(const LLColor4 &color)
 // *DEPRECATED: See header comment.
 void dialog_refresh_all()
 {
-	// This is the easiest place to fire the update signal, as it will
-	// make cleaning up the functions below easier.  Also, sometimes entities
-	// outside the selection manager change properties of selected objects
-	// and call into this function.  Yuck.
-	LLSelectMgr::getInstance()->mUpdateSignal();
+    // This is the easiest place to fire the update signal, as it will
+    // make cleaning up the functions below easier.  Also, sometimes entities
+    // outside the selection manager change properties of selected objects
+    // and call into this function.  Yuck.
+    LLSelectMgr::getInstance()->mUpdateSignal();
 
-	// *TODO: Eliminate all calls into outside classes below, make those
-	// objects register with the update signal.
+    // *TODO: Eliminate all calls into outside classes below, make those
+    // objects register with the update signal.
 
-	gFloaterTools->dirty();
+    gFloaterTools->dirty();
 
-	gMenuObject->needsArrange();
+    gMenuObject->needsArrange();
 
-	if( gMenuAttachmentSelf->getVisible() )
-	{
-		gMenuAttachmentSelf->arrange();
-	}
-	if( gMenuAttachmentOther->getVisible() )
-	{
-		gMenuAttachmentOther->arrange();
-	}
+    if( gMenuAttachmentSelf->getVisible() )
+    {
+        gMenuAttachmentSelf->arrange();
+    }
+    if( gMenuAttachmentOther->getVisible() )
+    {
+        gMenuAttachmentOther->arrange();
+    }
 
-	LLFloaterInspect* inspect_instance = LLFloaterReg::findTypedInstance<LLFloaterInspect>("inspect");
-	if(inspect_instance)
-	{
-		inspect_instance->dirty();
-	}
+    LLFloaterInspect* inspect_instance = LLFloaterReg::findTypedInstance<LLFloaterInspect>("inspect");
+    if(inspect_instance)
+    {
+        inspect_instance->dirty();
+    }
 
-	LLSidepanelTaskInfo *panel_task_info = LLSidepanelTaskInfo::getActivePanel();
-	if (panel_task_info)
-	{
-		panel_task_info->dirty();
-	}
+    LLSidepanelTaskInfo *panel_task_info = LLSidepanelTaskInfo::getActivePanel();
+    if (panel_task_info)
+    {
+        panel_task_info->dirty();
+    }
 }
 
 S32 get_family_count(LLViewerObject *parent)
 {
-	if (!parent)
-	{
-		LL_WARNS() << "Trying to get_family_count on null parent!" << LL_ENDL;
-		return 1;
-	}
-	S32 count = 1;	// for this object
-	const LLViewerObject::const_child_list_t& child_list = parent->getChildren();
-	for (LLViewerObject* child : child_list)
-	{
-		if (!child)
-		{
-			LL_WARNS() << "Family object has NULL child!  Show Doug." << LL_ENDL;
-		}
-		else if (child->isDead())
-		{
-			LL_WARNS() << "Family object has dead child object.  Show Doug." << LL_ENDL;
-		}
-		else
-		{
-			if (LLSelectMgr::getInstance()->canSelectObject(child))
-			{
-				count += get_family_count( child );
-			}
-		}
-	}
-	return count;
+    if (!parent)
+    {
+        LL_WARNS() << "Trying to get_family_count on null parent!" << LL_ENDL;
+        return 1;
+    }
+    S32 count = 1;  // for this object
+    const LLViewerObject::const_child_list_t& child_list = parent->getChildren();
+    for (LLViewerObject* child : child_list)
+    {
+        if (!child)
+        {
+            LL_WARNS() << "Family object has NULL child!  Show Doug." << LL_ENDL;
+        }
+        else if (child->isDead())
+        {
+            LL_WARNS() << "Family object has dead child object.  Show Doug." << LL_ENDL;
+        }
+        else
+        {
+            if (LLSelectMgr::getInstance()->canSelectObject(child))
+            {
+                count += get_family_count( child );
+            }
+        }
+    }
+    return count;
 }
 
 //-----------------------------------------------------------------------------
@@ -7167,104 +7167,104 @@ S32 get_family_count(LLViewerObject *parent)
 // -----------------------------------------------------------------------------
 void LLSelectMgr::updateSelectionCenter()
 {
-	const F32 MOVE_SELECTION_THRESHOLD = 1.f;		//  Movement threshold in meters for updating selection
-													//  center (tractor beam)
+    const F32 MOVE_SELECTION_THRESHOLD = 1.f;       //  Movement threshold in meters for updating selection
+                                                    //  center (tractor beam)
 
     // override any avatar updates received
     // Works only if avatar was repositioned
     // and edit floater is visible
     overrideAvatarUpdates();
-	//override any object updates received
-	//for selected objects
-	overrideObjectUpdates();
-
-	LLViewerObject* object = mSelectedObjects->getFirstObject();
-	if (!object)
-	{
-		// nothing selected, probably grabbing
-		// Ignore by setting to avatar origin.
-		mSelectionCenterGlobal.clearVec();
-		mShowSelection = FALSE;
-		mSelectionBBox = LLBBox(); 
-		resetAgentHUDZoom();
-	}
-	else
-	{
-		mSelectedObjects->mSelectType = getSelectTypeForObject(object);
-
-		if (mSelectedObjects->mSelectType != SELECT_TYPE_HUD && isAgentAvatarValid())
-		{
-			// reset hud ZOOM
-			resetAgentHUDZoom();
-		}
-
-		mShowSelection = FALSE;
-		LLBBox bbox;
-
-		// have stuff selected
-		LLVector3d select_center;
-		// keep a list of jointed objects for showing the joint HUDEffects
-
-		// Initialize the bounding box to the root prim, so the BBox orientation 
-		// matches the root prim's (affecting the orientation of the manipulators). 
-		bbox.addBBoxAgent( (mSelectedObjects->getFirstRootObject(TRUE))->getBoundingBoxAgent() ); 
-	                 
-		for (LLSelectNode* node : mSelectedObjects->begin_end())
-		{
-			LLViewerObject* object = node->getObject();
-			if (!object)
-				continue;
-			
-			LLViewerObject *root = object->getRootEdit();
-			if (mSelectedObjects->mSelectType == SELECT_TYPE_WORLD && // not an attachment
-				!root->isChild(gAgentAvatarp) && // not the object you're sitting on
-				!object->isAvatar()) // not another avatar
-			{
-				mShowSelection = TRUE;
-			}
-
-			bbox.addBBoxAgent( object->getBoundingBoxAgent() );
-		}
-		
-		LLVector3 bbox_center_agent = bbox.getCenterAgent();
-		mSelectionCenterGlobal = gAgent.getPosGlobalFromAgent(bbox_center_agent);
-		mSelectionBBox = bbox;
-
-	}
-	
-	if (gAgentID.notNull())
-	{
-		LLTool		*tool = LLToolMgr::getInstance()->getCurrentTool();
-		if (mShowSelection)
-		{
-			LLVector3d select_center_global;
-
-			if( tool->isEditing() )
-			{
-				select_center_global = tool->getEditingPointGlobal();
-			}
-			else
-			{
-				select_center_global = mSelectionCenterGlobal;
-			}
-
-			// Send selection center if moved beyond threshold (used to animate tractor beam)	
-			LLVector3d diff;
-			diff = select_center_global - mLastSentSelectionCenterGlobal;
-
-			if ( diff.magVecSquared() > MOVE_SELECTION_THRESHOLD*MOVE_SELECTION_THRESHOLD )
-			{
-				//  Transmit updated selection center 
-				mLastSentSelectionCenterGlobal = select_center_global;
-			}
-		}
-	}
-
-	// give up edit menu if no objects selected
-	if (gEditMenuHandler == this && mSelectedObjects->getObjectCount() == 0)
-	{
-		gEditMenuHandler = NULL;
-	}
+    //override any object updates received
+    //for selected objects
+    overrideObjectUpdates();
+
+    LLViewerObject* object = mSelectedObjects->getFirstObject();
+    if (!object)
+    {
+        // nothing selected, probably grabbing
+        // Ignore by setting to avatar origin.
+        mSelectionCenterGlobal.clearVec();
+        mShowSelection = FALSE;
+        mSelectionBBox = LLBBox();
+        resetAgentHUDZoom();
+    }
+    else
+    {
+        mSelectedObjects->mSelectType = getSelectTypeForObject(object);
+
+        if (mSelectedObjects->mSelectType != SELECT_TYPE_HUD && isAgentAvatarValid())
+        {
+            // reset hud ZOOM
+            resetAgentHUDZoom();
+        }
+
+        mShowSelection = FALSE;
+        LLBBox bbox;
+
+        // have stuff selected
+        LLVector3d select_center;
+        // keep a list of jointed objects for showing the joint HUDEffects
+
+        // Initialize the bounding box to the root prim, so the BBox orientation
+        // matches the root prim's (affecting the orientation of the manipulators).
+        bbox.addBBoxAgent( (mSelectedObjects->getFirstRootObject(TRUE))->getBoundingBoxAgent() );
+
+        for (LLSelectNode* node : mSelectedObjects->begin_end())
+        {
+            LLViewerObject* object = node->getObject();
+            if (!object)
+                continue;
+
+            LLViewerObject *root = object->getRootEdit();
+            if (mSelectedObjects->mSelectType == SELECT_TYPE_WORLD && // not an attachment
+                !root->isChild(gAgentAvatarp) && // not the object you're sitting on
+                !object->isAvatar()) // not another avatar
+            {
+                mShowSelection = TRUE;
+            }
+
+            bbox.addBBoxAgent( object->getBoundingBoxAgent() );
+        }
+
+        LLVector3 bbox_center_agent = bbox.getCenterAgent();
+        mSelectionCenterGlobal = gAgent.getPosGlobalFromAgent(bbox_center_agent);
+        mSelectionBBox = bbox;
+
+    }
+
+    if (gAgentID.notNull())
+    {
+        LLTool      *tool = LLToolMgr::getInstance()->getCurrentTool();
+        if (mShowSelection)
+        {
+            LLVector3d select_center_global;
+
+            if( tool->isEditing() )
+            {
+                select_center_global = tool->getEditingPointGlobal();
+            }
+            else
+            {
+                select_center_global = mSelectionCenterGlobal;
+            }
+
+            // Send selection center if moved beyond threshold (used to animate tractor beam)
+            LLVector3d diff;
+            diff = select_center_global - mLastSentSelectionCenterGlobal;
+
+            if ( diff.magVecSquared() > MOVE_SELECTION_THRESHOLD*MOVE_SELECTION_THRESHOLD )
+            {
+                //  Transmit updated selection center
+                mLastSentSelectionCenterGlobal = select_center_global;
+            }
+        }
+    }
+
+    // give up edit menu if no objects selected
+    if (gEditMenuHandler == this && mSelectedObjects->getObjectCount() == 0)
+    {
+        gEditMenuHandler = NULL;
+    }
 
     pauseAssociatedAvatars();
 }
@@ -7285,7 +7285,7 @@ void LLSelectMgr::pauseAssociatedAvatars()
         LLViewerObject* object = node->getObject();
         if (!object)
             continue;
-			
+
         mSelectedObjects->mSelectType = getSelectTypeForObject(object);
 
         LLVOAvatar* parent_av = NULL;
@@ -7313,40 +7313,40 @@ void LLSelectMgr::pauseAssociatedAvatars()
 
 void LLSelectMgr::updatePointAt()
 {
-	if (mShowSelection)
-	{
-		if (mSelectedObjects->getObjectCount())
-		{					
-			LLVector3 select_offset;
-			const LLPickInfo& pick = gViewerWindow->getLastPick();
-			LLViewerObject *click_object = pick.getObject();
-			if (click_object && click_object->isSelected())
-			{
-				// clicked on another object in our selection group, use that as target
-				select_offset.setVec(pick.mObjectOffset);
-				select_offset.rotVec(~click_object->getRenderRotation());
-		
-				gAgentCamera.setPointAt(POINTAT_TARGET_SELECT, click_object, select_offset);
-				gAgentCamera.setLookAt(LOOKAT_TARGET_SELECT, click_object, select_offset);
-			}
-			else
-			{
-				// didn't click on an object this time, revert to pointing at center of first object
-				gAgentCamera.setPointAt(POINTAT_TARGET_SELECT, mSelectedObjects->getFirstObject());
-				gAgentCamera.setLookAt(LOOKAT_TARGET_SELECT, mSelectedObjects->getFirstObject());
-			}
-		}
-		else
-		{
-			gAgentCamera.setPointAt(POINTAT_TARGET_CLEAR);
-			gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
-		}
-	}
-	else
-	{
-		gAgentCamera.setPointAt(POINTAT_TARGET_CLEAR);
-		gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
-	}
+    if (mShowSelection)
+    {
+        if (mSelectedObjects->getObjectCount())
+        {
+            LLVector3 select_offset;
+            const LLPickInfo& pick = gViewerWindow->getLastPick();
+            LLViewerObject *click_object = pick.getObject();
+            if (click_object && click_object->isSelected())
+            {
+                // clicked on another object in our selection group, use that as target
+                select_offset.setVec(pick.mObjectOffset);
+                select_offset.rotVec(~click_object->getRenderRotation());
+
+                gAgentCamera.setPointAt(POINTAT_TARGET_SELECT, click_object, select_offset);
+                gAgentCamera.setLookAt(LOOKAT_TARGET_SELECT, click_object, select_offset);
+            }
+            else
+            {
+                // didn't click on an object this time, revert to pointing at center of first object
+                gAgentCamera.setPointAt(POINTAT_TARGET_SELECT, mSelectedObjects->getFirstObject());
+                gAgentCamera.setLookAt(LOOKAT_TARGET_SELECT, mSelectedObjects->getFirstObject());
+            }
+        }
+        else
+        {
+            gAgentCamera.setPointAt(POINTAT_TARGET_CLEAR);
+            gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
+        }
+    }
+    else
+    {
+        gAgentCamera.setPointAt(POINTAT_TARGET_CLEAR);
+        gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -7354,7 +7354,7 @@ void LLSelectMgr::updatePointAt()
 //-----------------------------------------------------------------------------
 LLBBox LLSelectMgr::getBBoxOfSelection() const
 {
-	return mSelectionBBox;
+    return mSelectionBBox;
 }
 
 
@@ -7363,8 +7363,8 @@ LLBBox LLSelectMgr::getBBoxOfSelection() const
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::canUndo() const
 {
-	// Can edit or can move
-	return const_cast<LLSelectMgr*>(this)->mSelectedObjects->getFirstUndoEnabledObject() != NULL; // HACK: casting away constness - MG;
+    // Can edit or can move
+    return const_cast<LLSelectMgr*>(this)->mSelectedObjects->getFirstUndoEnabledObject() != NULL; // HACK: casting away constness - MG;
 }
 
 //-----------------------------------------------------------------------------
@@ -7372,9 +7372,9 @@ BOOL LLSelectMgr::canUndo() const
 //-----------------------------------------------------------------------------
 void LLSelectMgr::undo()
 {
-	BOOL select_linked_set = !ALControlCache::EditLinkedParts;
-	LLUUID group_id(gAgent.getGroupID());
-	sendListToRegions("Undo", packAgentAndSessionAndGroupID, packObjectID, logNoOp, &group_id, select_linked_set ? SEND_ONLY_ROOTS : SEND_CHILDREN_FIRST);
+    BOOL select_linked_set = !ALControlCache::EditLinkedParts;
+    LLUUID group_id(gAgent.getGroupID());
+    sendListToRegions("Undo", packAgentAndSessionAndGroupID, packObjectID, logNoOp, &group_id, select_linked_set ? SEND_ONLY_ROOTS : SEND_CHILDREN_FIRST);
 }
 
 //-----------------------------------------------------------------------------
@@ -7382,7 +7382,7 @@ void LLSelectMgr::undo()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::canRedo() const
 {
-	return const_cast<LLSelectMgr*>(this)->mSelectedObjects->getFirstEditableObject() != NULL; // HACK: casting away constness - MG
+    return const_cast<LLSelectMgr*>(this)->mSelectedObjects->getFirstEditableObject() != NULL; // HACK: casting away constness - MG
 }
 
 //-----------------------------------------------------------------------------
@@ -7390,9 +7390,9 @@ BOOL LLSelectMgr::canRedo() const
 //-----------------------------------------------------------------------------
 void LLSelectMgr::redo()
 {
-	BOOL select_linked_set = !ALControlCache::EditLinkedParts;
-	LLUUID group_id(gAgent.getGroupID());
-	sendListToRegions("Redo", packAgentAndSessionAndGroupID, packObjectID, logNoOp, &group_id, select_linked_set ? SEND_ONLY_ROOTS : SEND_CHILDREN_FIRST);
+    BOOL select_linked_set = !ALControlCache::EditLinkedParts;
+    LLUUID group_id(gAgent.getGroupID());
+    sendListToRegions("Redo", packAgentAndSessionAndGroupID, packObjectID, logNoOp, &group_id, select_linked_set ? SEND_ONLY_ROOTS : SEND_CHILDREN_FIRST);
 }
 
 //-----------------------------------------------------------------------------
@@ -7400,25 +7400,25 @@ void LLSelectMgr::redo()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::canDoDelete() const
 {
-	bool can_delete = false;
-	// This function is "logically const" - it does not change state in
-	// a way visible outside the selection manager.
-	LLSelectMgr* self = const_cast<LLSelectMgr*>(this);
-	LLViewerObject* obj = self->mSelectedObjects->getFirstDeleteableObject();
-	// Note: Can only delete root objects (see getFirstDeleteableObject() for more info)
-	if (obj!= NULL)
-	{
-		// all the faces needs to be selected
-		if(self->mSelectedObjects->contains(obj,SELECT_ALL_TES ))
-		{
-			can_delete = true;
-		}
-	}
+    bool can_delete = false;
+    // This function is "logically const" - it does not change state in
+    // a way visible outside the selection manager.
+    LLSelectMgr* self = const_cast<LLSelectMgr*>(this);
+    LLViewerObject* obj = self->mSelectedObjects->getFirstDeleteableObject();
+    // Note: Can only delete root objects (see getFirstDeleteableObject() for more info)
+    if (obj!= NULL)
+    {
+        // all the faces needs to be selected
+        if(self->mSelectedObjects->contains(obj,SELECT_ALL_TES ))
+        {
+            can_delete = true;
+        }
+    }
 // [RLVa:KB] - Checked: 2010-03-23 (RLVa-1.2.0e) | Added: RLVa-1.2.0a
-	can_delete &= (!rlv_handler_t::isEnabled()) || (rlvCanDeleteOrReturn());
+    can_delete &= (!rlv_handler_t::isEnabled()) || (rlvCanDeleteOrReturn());
 // [/RLVa:KB]
 
-	return can_delete;
+    return can_delete;
 }
 
 //-----------------------------------------------------------------------------
@@ -7426,7 +7426,7 @@ BOOL LLSelectMgr::canDoDelete() const
 //-----------------------------------------------------------------------------
 void LLSelectMgr::doDelete()
 {
-	selectDelete();
+    selectDelete();
 }
 
 //-----------------------------------------------------------------------------
@@ -7434,7 +7434,7 @@ void LLSelectMgr::doDelete()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::canDeselect() const
 {
-	return !mSelectedObjects->isEmpty();
+    return !mSelectedObjects->isEmpty();
 }
 
 //-----------------------------------------------------------------------------
@@ -7442,18 +7442,18 @@ BOOL LLSelectMgr::canDeselect() const
 //-----------------------------------------------------------------------------
 void LLSelectMgr::deselect()
 {
-	deselectAll();
+    deselectAll();
 }
 //-----------------------------------------------------------------------------
 // canDuplicate()
 //-----------------------------------------------------------------------------
 BOOL LLSelectMgr::canDuplicate() const
 {
-//	return const_cast<LLSelectMgr*>(this)->mSelectedObjects->getFirstCopyableObject() != NULL; // HACK: casting away constness - MG
+//  return const_cast<LLSelectMgr*>(this)->mSelectedObjects->getFirstCopyableObject() != NULL; // HACK: casting away constness - MG
 // [RLVa:KB] - Checked: 2010-03-24 (RLVa-1.2.0e) | Added: RLVa-1.2.0a
-	return 
-		(const_cast<LLSelectMgr*>(this)->mSelectedObjects->getFirstCopyableObject() != NULL) &&
-		( (!rlv_handler_t::isEnabled()) || (rlvCanDeleteOrReturn()) );
+    return
+        (const_cast<LLSelectMgr*>(this)->mSelectedObjects->getFirstCopyableObject() != NULL) &&
+        ( (!rlv_handler_t::isEnabled()) || (rlvCanDeleteOrReturn()) );
 // [/RLVa:KB]
 }
 //-----------------------------------------------------------------------------
@@ -7461,110 +7461,110 @@ BOOL LLSelectMgr::canDuplicate() const
 //-----------------------------------------------------------------------------
 void LLSelectMgr::duplicate()
 {
-	LLVector3 offset(0.5f, 0.5f, 0.f);
-	selectDuplicate(offset, TRUE);
+    LLVector3 offset(0.5f, 0.5f, 0.f);
+    selectDuplicate(offset, TRUE);
 }
 
 ESelectType LLSelectMgr::getSelectTypeForObject(LLViewerObject* object)
 {
-	if (!object)
-	{
-		return SELECT_TYPE_WORLD;
-	}
-	if (object->isHUDAttachment())
-	{
-		return SELECT_TYPE_HUD;
-	}
-	else if (object->isAttachment())
-	{
-		return SELECT_TYPE_ATTACHMENT;
-	}
-	else
-	{
-		return SELECT_TYPE_WORLD;
-	}
+    if (!object)
+    {
+        return SELECT_TYPE_WORLD;
+    }
+    if (object->isHUDAttachment())
+    {
+        return SELECT_TYPE_HUD;
+    }
+    else if (object->isAttachment())
+    {
+        return SELECT_TYPE_ATTACHMENT;
+    }
+    else
+    {
+        return SELECT_TYPE_WORLD;
+    }
 }
 
 void LLSelectMgr::validateSelection()
 {
-	struct f : public LLSelectedObjectFunctor
-	{
-		virtual bool apply(LLViewerObject* object)
-		{
-			if (!instance().canSelectObject(object))
-			{
-				instance().deselectObjectOnly(object);
-			}
-			return true;
-		}
-	} func;
-	getSelection()->applyToObjects(&func);	
+    struct f : public LLSelectedObjectFunctor
+    {
+        virtual bool apply(LLViewerObject* object)
+        {
+            if (!instance().canSelectObject(object))
+            {
+                instance().deselectObjectOnly(object);
+            }
+            return true;
+        }
+    } func;
+    getSelection()->applyToObjects(&func);
 }
 
 BOOL LLSelectMgr::canSelectObject(LLViewerObject* object, BOOL ignore_select_owned)
 {
-	// Never select dead objects
-	if (!object || object->isDead())
-	{
-		return FALSE;
-	}
+    // Never select dead objects
+    if (!object || object->isDead())
+    {
+        return FALSE;
+    }
 
-	if (mForceSelection)
-	{
-		return TRUE;
-	}
+    if (mForceSelection)
+    {
+        return TRUE;
+    }
 
-	if(!ignore_select_owned)
-	{
-		if ((gSavedSettings.getBOOL("SelectCopyOnly") && !object->permCopy()) ||
-			(gSavedSettings.getBOOL("SelectOwnedOnly") && !object->permYouOwner()) ||
-				(gSavedSettings.getBOOL("SelectMovableOnly") && (!object->permMove() ||  object->isPermanentEnforced())))
-		{
-			// only select my own objects
-			return FALSE;
-		}
-	}
+    if(!ignore_select_owned)
+    {
+        if ((gSavedSettings.getBOOL("SelectCopyOnly") && !object->permCopy()) ||
+            (gSavedSettings.getBOOL("SelectOwnedOnly") && !object->permYouOwner()) ||
+                (gSavedSettings.getBOOL("SelectMovableOnly") && (!object->permMove() ||  object->isPermanentEnforced())))
+        {
+            // only select my own objects
+            return FALSE;
+        }
+    }
 
-	// Can't select orphans
-	if (object->isOrphaned()) return FALSE;
+    // Can't select orphans
+    if (object->isOrphaned()) return FALSE;
 
-	// Can't select avatars
-	if (object->isAvatar()) return FALSE;
+    // Can't select avatars
+    if (object->isAvatar()) return FALSE;
 
-	// Can't select land
-	if (object->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH) return FALSE;
+    // Can't select land
+    if (object->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH) return FALSE;
 
-	ESelectType selection_type = getSelectTypeForObject(object);
-	if (mSelectedObjects->getObjectCount() > 0 && mSelectedObjects->mSelectType != selection_type) return FALSE;
+    ESelectType selection_type = getSelectTypeForObject(object);
+    if (mSelectedObjects->getObjectCount() > 0 && mSelectedObjects->mSelectType != selection_type) return FALSE;
 
-	return TRUE;
+    return TRUE;
 }
 
-BOOL LLSelectMgr::setForceSelection(BOOL force) 
-{ 
-	std::swap(mForceSelection,force); 
-	return force; 
+BOOL LLSelectMgr::setForceSelection(BOOL force)
+{
+    std::swap(mForceSelection,force);
+    return force;
 }
 
 void LLSelectMgr::resetAgentHUDZoom()
 {
-	if (gAgentCamera.mHUDTargetZoom != 1)
-	{
-		gAgentCamera.mHUDTargetZoom = 1.f;
-		gAgentCamera.mHUDCurZoom = 1.f;
-	}
+    if (gAgentCamera.mHUDTargetZoom != 1)
+    {
+        gAgentCamera.mHUDTargetZoom = 1.f;
+        gAgentCamera.mHUDCurZoom = 1.f;
+    }
 }
 
 void LLSelectMgr::getAgentHUDZoom(F32 &target_zoom, F32 &current_zoom) const
 {
-	target_zoom = gAgentCamera.mHUDTargetZoom;
-	current_zoom = gAgentCamera.mHUDCurZoom;
+    target_zoom = gAgentCamera.mHUDTargetZoom;
+    current_zoom = gAgentCamera.mHUDCurZoom;
 }
 
 void LLSelectMgr::setAgentHUDZoom(F32 target_zoom, F32 current_zoom)
 {
-	gAgentCamera.mHUDTargetZoom = target_zoom;
-	gAgentCamera.mHUDCurZoom = current_zoom;
+    gAgentCamera.mHUDTargetZoom = target_zoom;
+    gAgentCamera.mHUDCurZoom = current_zoom;
 }
 
 /////////////////////////////////////////////////////////////////////////////
@@ -7572,45 +7572,45 @@ void LLSelectMgr::setAgentHUDZoom(F32 target_zoom, F32 current_zoom)
 /////////////////////////////////////////////////////////////////////////////
 bool LLObjectSelection::is_root::operator()(LLSelectNode *node)
 {
-	LLViewerObject* object = node->getObject();
-	return (object != NULL) && !node->mIndividualSelection && (object->isRootEdit());
+    LLViewerObject* object = node->getObject();
+    return (object != NULL) && !node->mIndividualSelection && (object->isRootEdit());
 }
 
 bool LLObjectSelection::is_valid_root::operator()(LLSelectNode *node)
 {
-	LLViewerObject* object = node->getObject();
-	return (object != NULL) && node->mValid && !node->mIndividualSelection && (object->isRootEdit());
+    LLViewerObject* object = node->getObject();
+    return (object != NULL) && node->mValid && !node->mIndividualSelection && (object->isRootEdit());
 }
 
 bool LLObjectSelection::is_root_object::operator()(LLSelectNode *node)
 {
-	LLViewerObject* object = node->getObject();
-	return (object != NULL) && (object->isRootEdit());
+    LLViewerObject* object = node->getObject();
+    return (object != NULL) && (object->isRootEdit());
 }
 
-LLObjectSelection::LLObjectSelection() : 
-	LLRefCount(),
-	mSelectType(SELECT_TYPE_WORLD)
+LLObjectSelection::LLObjectSelection() :
+    LLRefCount(),
+    mSelectType(SELECT_TYPE_WORLD)
 {
 }
 
 LLObjectSelection::~LLObjectSelection()
 {
-	deleteAllNodes();
+    deleteAllNodes();
 }
 
 void LLObjectSelection::cleanupNodes()
 {
-	for (list_t::iterator iter = mList.begin(); iter != mList.end(); )
-	{
-		list_t::iterator curiter = iter++;
-		LLSelectNode* node = *curiter;
-		if (node->getObject() == NULL || node->getObject()->isDead())
-		{
-			mList.erase(curiter);
-			delete node;
-		}
-	}
+    for (list_t::iterator iter = mList.begin(); iter != mList.end(); )
+    {
+        list_t::iterator curiter = iter++;
+        LLSelectNode* node = *curiter;
+        if (node->getObject() == NULL || node->getObject()->isDead())
+        {
+            mList.erase(curiter);
+            delete node;
+        }
+    }
 }
 
 void LLObjectSelection::updateEffects()
@@ -7619,56 +7619,56 @@ void LLObjectSelection::updateEffects()
 
 S32 LLObjectSelection::getNumNodes()
 {
-	return mList.size();
+    return mList.size();
 }
 
 void LLObjectSelection::addNode(LLSelectNode *nodep)
 {
-	llassert_always(nodep->getObject() && !nodep->getObject()->isDead());
-	mList.push_front(nodep);
-	mSelectNodeMap[nodep->getObject()] = nodep;
+    llassert_always(nodep->getObject() && !nodep->getObject()->isDead());
+    mList.push_front(nodep);
+    mSelectNodeMap[nodep->getObject()] = nodep;
 }
 
 void LLObjectSelection::addNodeAtEnd(LLSelectNode *nodep)
 {
-	llassert_always(nodep->getObject() && !nodep->getObject()->isDead());
-	mList.push_back(nodep);
-	mSelectNodeMap[nodep->getObject()] = nodep;
+    llassert_always(nodep->getObject() && !nodep->getObject()->isDead());
+    mList.push_back(nodep);
+    mSelectNodeMap[nodep->getObject()] = nodep;
 }
 
 void LLObjectSelection::moveNodeToFront(LLSelectNode *nodep)
 {
-	mList.remove(nodep);
-	mList.push_front(nodep);
+    mList.remove(nodep);
+    mList.push_front(nodep);
 }
 
 void LLObjectSelection::removeNode(LLSelectNode *nodep)
 {
-	mSelectNodeMap.erase(nodep->getObject());
-	if (nodep->getObject() == mPrimaryObject.get())
-	{
-		mPrimaryObject = NULL;
-	}
-	nodep->setObject(NULL); // Will get erased in cleanupNodes()
-	mList.remove(nodep);
+    mSelectNodeMap.erase(nodep->getObject());
+    if (nodep->getObject() == mPrimaryObject.get())
+    {
+        mPrimaryObject = NULL;
+    }
+    nodep->setObject(NULL); // Will get erased in cleanupNodes()
+    mList.remove(nodep);
 }
 
 void LLObjectSelection::deleteAllNodes()
 {
-	std::for_each(mList.begin(), mList.end(), DeletePointer());
-	mList.clear();
-	mSelectNodeMap.clear();
-	mPrimaryObject = NULL;
+    std::for_each(mList.begin(), mList.end(), DeletePointer());
+    mList.clear();
+    mSelectNodeMap.clear();
+    mPrimaryObject = NULL;
 }
 
 LLSelectNode* LLObjectSelection::findNode(LLViewerObject* objectp)
 {
-	std::map<LLPointer<LLViewerObject>, LLSelectNode*>::iterator found_it = mSelectNodeMap.find(objectp);
-	if (found_it != mSelectNodeMap.end())
-	{
-		return found_it->second;
-	}
-	return NULL;
+    std::map<LLPointer<LLViewerObject>, LLSelectNode*>::iterator found_it = mSelectNodeMap.find(objectp);
+    if (found_it != mSelectNodeMap.end())
+    {
+        return found_it->second;
+    }
+    return NULL;
 }
 
 //-----------------------------------------------------------------------------
@@ -7676,7 +7676,7 @@ LLSelectNode* LLObjectSelection::findNode(LLViewerObject* objectp)
 //-----------------------------------------------------------------------------
 BOOL LLObjectSelection::isEmpty() const
 {
-	return (mList.size() == 0);
+    return (mList.size() == 0);
 }
 
 
@@ -7685,114 +7685,114 @@ BOOL LLObjectSelection::isEmpty() const
 //-----------------------------------------------------------------------------
 S32 LLObjectSelection::getObjectCount()
 {
-	cleanupNodes();
-	S32 count = mList.size();
+    cleanupNodes();
+    S32 count = mList.size();
 
-	return count;
+    return count;
 }
 
 F32 LLObjectSelection::getSelectedObjectCost()
 {
-	cleanupNodes();
-	F32 cost = 0.f;
+    cleanupNodes();
+    F32 cost = 0.f;
+
+    for (LLSelectNode* node : mList)
+    {
+        LLViewerObject* object = node->getObject();
 
-	for (LLSelectNode* node : mList)
-	{
-		LLViewerObject* object = node->getObject();
-		
-		if (object)
-		{
-			cost += object->getObjectCost();
-		}
-	}
+        if (object)
+        {
+            cost += object->getObjectCost();
+        }
+    }
 
-	return cost;
+    return cost;
 }
 
 F32 LLObjectSelection::getSelectedLinksetCost()
 {
-	cleanupNodes();
-	F32 cost = 0.f;
+    cleanupNodes();
+    F32 cost = 0.f;
+
+    std::set<LLViewerObject*> me_roots;
 
-	std::set<LLViewerObject*> me_roots;
+    for (LLSelectNode* node : mList)
+    {
+        LLViewerObject* object = node->getObject();
 
-	for (LLSelectNode* node : mList)
-	{
-		LLViewerObject* object = node->getObject();
-		
-		if (object && !object->isAttachment())
-		{
-			LLViewerObject* root = static_cast<LLViewerObject*>(object->getRoot());
-			if (root)
-			{
-				if (me_roots.find(root) == me_roots.end())
-				{
-					me_roots.insert(root);
-					cost += root->getLinksetCost();
-				}
-			}
-		}
-	}
+        if (object && !object->isAttachment())
+        {
+            LLViewerObject* root = static_cast<LLViewerObject*>(object->getRoot());
+            if (root)
+            {
+                if (me_roots.find(root) == me_roots.end())
+                {
+                    me_roots.insert(root);
+                    cost += root->getLinksetCost();
+                }
+            }
+        }
+    }
 
-	return cost;
+    return cost;
 }
 
 F32 LLObjectSelection::getSelectedPhysicsCost()
 {
-	cleanupNodes();
-	F32 cost = 0.f;
+    cleanupNodes();
+    F32 cost = 0.f;
+
+    for (LLSelectNode* node : mList)
+    {
+        LLViewerObject* object = node->getObject();
 
-	for (LLSelectNode* node : mList)
-	{
-		LLViewerObject* object = node->getObject();
-		
-		if (object)
-		{
-			cost += object->getPhysicsCost();
-		}
-	}
+        if (object)
+        {
+            cost += object->getPhysicsCost();
+        }
+    }
 
-	return cost;
+    return cost;
 }
 
 F32 LLObjectSelection::getSelectedLinksetPhysicsCost()
 {
-	cleanupNodes();
-	F32 cost = 0.f;
+    cleanupNodes();
+    F32 cost = 0.f;
+
+    std::set<LLViewerObject*> me_roots;
 
-	std::set<LLViewerObject*> me_roots;
+    for (LLSelectNode* node : mList)
+    {
+        LLViewerObject* object = node->getObject();
 
-	for (LLSelectNode* node : mList)
-	{
-		LLViewerObject* object = node->getObject();
-		
-		if (object)
-		{
-			LLViewerObject* root = static_cast<LLViewerObject*>(object->getRoot());
-			if (root)
-			{
-				if (me_roots.find(root) == me_roots.end())
-				{
-					me_roots.insert(root);
-					cost += root->getLinksetPhysicsCost();
-				}
-			}
-		}
-	}
+        if (object)
+        {
+            LLViewerObject* root = static_cast<LLViewerObject*>(object->getRoot());
+            if (root)
+            {
+                if (me_roots.find(root) == me_roots.end())
+                {
+                    me_roots.insert(root);
+                    cost += root->getLinksetPhysicsCost();
+                }
+            }
+        }
+    }
 
-	return cost;
+    return cost;
 }
 
 F32 LLObjectSelection::getSelectedObjectStreamingCost(S32* total_bytes, S32* visible_bytes)
 {
-	F32 cost = 0.f;
-	for (LLSelectNode* node : mList)
-	{
-		LLViewerObject* object = node->getObject();
-		
-		if (object)
-		{
-			cost += object->getStreamingCost();
+    F32 cost = 0.f;
+    for (LLSelectNode* node : mList)
+    {
+        LLViewerObject* object = node->getObject();
+
+        if (object)
+        {
+            cost += object->getStreamingCost();
 
             S32 bytes = 0;
             S32 visible = 0;
@@ -7802,37 +7802,37 @@ F32 LLObjectSelection::getSelectedObjectStreamingCost(S32* total_bytes, S32* vis
                 bytes = costs.getSizeTotal();
                 visible = costs.getSizeByLOD(object->getLOD());
             }
-			if (total_bytes)
-			{
-				*total_bytes += bytes;
-			}
+            if (total_bytes)
+            {
+                *total_bytes += bytes;
+            }
 
-			if (visible_bytes)
-			{
-				*visible_bytes += visible;
-			}
-		}
-	}
+            if (visible_bytes)
+            {
+                *visible_bytes += visible;
+            }
+        }
+    }
 
-	return cost;
+    return cost;
 }
 
 U32 LLObjectSelection::getSelectedObjectTriangleCount(S32* vcount)
 {
-	U32 count = 0;
-	for (LLSelectNode* node : mList)
-	{
-		LLViewerObject* object = node->getObject();
-		
-		if (object)
-		{
-			S32 vt = 0;
-			count += object->getTriangleCount(&vt);
-			*vcount += vt;
-		}
-	}
+    U32 count = 0;
+    for (LLSelectNode* node : mList)
+    {
+        LLViewerObject* object = node->getObject();
+
+        if (object)
+        {
+            S32 vt = 0;
+            count += object->getTriangleCount(&vt);
+            *vcount += vt;
+        }
+    }
 
-	return count;
+    return count;
 }
 
 S32 LLObjectSelection::getSelectedObjectRenderCost()
@@ -7842,56 +7842,56 @@ S32 LLObjectSelection::getSelectedObjectRenderCost()
        typedef std::set<LLUUID> uuid_list_t;
        uuid_list_t computed_objects;
 
-	   // add render cost of complete linksets first, to get accurate texture counts
+       // add render cost of complete linksets first, to get accurate texture counts
        for (LLSelectNode* node : mList)
        {
                LLVOVolume* object = (LLVOVolume*)node->getObject();
 
                if (object && object->isRootEdit())
                {
-				   cost += object->getRenderCost(textures);
-				   computed_objects.insert(object->getID());
-
-				   LLViewerObject::const_child_list_t& children = object->getChildren();
-				   for (LLViewerObject* child_obj : children)
-				   {
-					   LLVOVolume *child = child_obj ? child_obj->asVolume() : nullptr;
-					   if (child)
-					   {
-						   cost += child->getRenderCost(textures);
-						   computed_objects.insert(child->getID());
-					   }
-				   }
-
-				   for (LLVOVolume::texture_cost_t::iterator iter = textures.begin(); iter != textures.end(); ++iter)
-				   {
-					   // add the cost of each individual texture in the linkset
-					   cost += LLVOVolume::getTextureCost(*iter);
-				   }
-
-				   textures.clear();
+                   cost += object->getRenderCost(textures);
+                   computed_objects.insert(object->getID());
+
+                   LLViewerObject::const_child_list_t& children = object->getChildren();
+                   for (LLViewerObject* child_obj : children)
+                   {
+                       LLVOVolume *child = child_obj ? child_obj->asVolume() : nullptr;
+                       if (child)
+                       {
+                           cost += child->getRenderCost(textures);
+                           computed_objects.insert(child->getID());
+                       }
+                   }
+
+                   for (LLVOVolume::texture_cost_t::iterator iter = textures.begin(); iter != textures.end(); ++iter)
+                   {
+                       // add the cost of each individual texture in the linkset
+                       cost += LLVOVolume::getTextureCost(*iter);
+                   }
+
+                   textures.clear();
                }
        }
-	
-	   // add any partial linkset objects, texture cost may be slightly misleading
-	   for (LLSelectNode* node : mList)
-	   {
-			LLVOVolume* object = (LLVOVolume*)node->getObject();
-
-			if (object && computed_objects.find(object->getID()) == computed_objects.end()  )
-			{
-					cost += object->getRenderCost(textures);
-					computed_objects.insert(object->getID());
-			}
-
-			for (LLVOVolume::texture_cost_t::iterator iter = textures.begin(); iter != textures.end(); ++iter)
-			{
-				// add the cost of each individual texture in the linkset
-				cost += LLVOVolume::getTextureCost(*iter);
-			}
-
-			textures.clear();
-		}
+
+       // add any partial linkset objects, texture cost may be slightly misleading
+       for (LLSelectNode* node : mList)
+       {
+            LLVOVolume* object = (LLVOVolume*)node->getObject();
+
+            if (object && computed_objects.find(object->getID()) == computed_objects.end()  )
+            {
+                    cost += object->getRenderCost(textures);
+                    computed_objects.insert(object->getID());
+            }
+
+            for (LLVOVolume::texture_cost_t::iterator iter = textures.begin(); iter != textures.end(); ++iter)
+            {
+                // add the cost of each individual texture in the linkset
+                cost += LLVOVolume::getTextureCost(*iter);
+            }
+
+            textures.clear();
+        }
 
        return cost;
 }
@@ -7901,22 +7901,22 @@ S32 LLObjectSelection::getSelectedObjectRenderCost()
 //-----------------------------------------------------------------------------
 S32 LLObjectSelection::getTECount()
 {
-	S32 count = 0;
-	for (LLSelectNode* node : begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if (!object)
-			continue;
-		S32 num_tes = object->getNumTEs();
-		for (S32 te = 0; te < num_tes; te++)
-		{
-			if (node->isTESelected(te))
-			{
-				++count;
-			}
-		}
-	}
-	return count;
+    S32 count = 0;
+    for (LLSelectNode* node : begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if (!object)
+            continue;
+        S32 num_tes = object->getNumTEs();
+        for (S32 te = 0; te < num_tes; te++)
+        {
+            if (node->isTESelected(te))
+            {
+                ++count;
+            }
+        }
+    }
+    return count;
 }
 
 //-----------------------------------------------------------------------------
@@ -7924,27 +7924,27 @@ S32 LLObjectSelection::getTECount()
 //-----------------------------------------------------------------------------
 S32 LLObjectSelection::getRootObjectCount()
 {
-	S32 count = 0;
-	for (auto begin_it = root_begin(), end_it = root_end(); begin_it != end_it; ++begin_it)
-	{
-		++count;
-	}
-	return count;
+    S32 count = 0;
+    for (auto begin_it = root_begin(), end_it = root_end(); begin_it != end_it; ++begin_it)
+    {
+        ++count;
+    }
+    return count;
 }
 
 bool LLObjectSelection::applyToObjects(LLSelectedObjectFunctor* func)
 {
-	bool result = true;
-	for (iterator iter = begin(); iter != end(); )
-	{
-		iterator nextiter = iter++;
-		LLViewerObject* object = (*nextiter)->getObject();
-		if (!object)
-			continue;
-		bool r = func->apply(object);
-		result = result && r;
-	}
-	return result;
+    bool result = true;
+    for (iterator iter = begin(); iter != end(); )
+    {
+        iterator nextiter = iter++;
+        LLViewerObject* object = (*nextiter)->getObject();
+        if (!object)
+            continue;
+        bool r = func->apply(object);
+        result = result && r;
+    }
+    return result;
 }
 
 bool LLObjectSelection::checkAnimatedObjectEstTris()
@@ -7952,19 +7952,19 @@ bool LLObjectSelection::checkAnimatedObjectEstTris()
     F32 est_tris = 0;
     F32 max_tris = 0;
     S32 anim_count = 0;
-	for (LLSelectNode* node : root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if (!object)
-			continue;
+    for (LLSelectNode* node : root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if (!object)
+            continue;
         if (object->isAnimatedObject())
         {
             anim_count++;
         }
         est_tris += object->recursiveGetEstTrianglesMax();
         max_tris = llmax((F32)max_tris,(F32)object->getAnimatedObjectMaxTris());
-	}
-	return anim_count==0 || est_tris <= max_tris;
+    }
+    return anim_count==0 || est_tris <= max_tris;
 }
 
 bool LLObjectSelection::checkAnimatedObjectLinkable()
@@ -7974,99 +7974,99 @@ bool LLObjectSelection::checkAnimatedObjectLinkable()
 
 bool LLObjectSelection::applyToRootObjects(LLSelectedObjectFunctor* func, bool firstonly)
 {
-	bool result = firstonly ? false : true;
-	for (root_iterator iter = root_begin(); iter != root_end(); )
-	{
-		root_iterator nextiter = iter++;
-		LLViewerObject* object = (*nextiter)->getObject();
-		if (!object)
-			continue;
-		bool r = func->apply(object);
-		if (firstonly && r)
-			return true;
-		else
-			result = result && r;
-	}
-	return result;
+    bool result = firstonly ? false : true;
+    for (root_iterator iter = root_begin(); iter != root_end(); )
+    {
+        root_iterator nextiter = iter++;
+        LLViewerObject* object = (*nextiter)->getObject();
+        if (!object)
+            continue;
+        bool r = func->apply(object);
+        if (firstonly && r)
+            return true;
+        else
+            result = result && r;
+    }
+    return result;
 }
 
 bool LLObjectSelection::applyToTEs(LLSelectedTEFunctor* func, bool firstonly)
 {
-	bool result = firstonly ? false : true;
-	for (iterator iter = begin(); iter != end(); )
-	{
-		iterator nextiter = iter++;
-		LLSelectNode* node = *nextiter;
-		LLViewerObject* object = (*nextiter)->getObject();
-		if (!object)
-			continue;
-		S32 num_tes = llmin((S32)object->getNumTEs(), (S32)object->getNumFaces()); // avatars have TEs but no faces
-		for (S32 te = 0; te < num_tes; ++te)
-		{
-			if (node->isTESelected(te))
-			{
-				bool r = func->apply(object, te);
-				if (firstonly && r)
-					return true;
-				else
-					result = result && r;
-			}
-		}
-	}
-	return result;
+    bool result = firstonly ? false : true;
+    for (iterator iter = begin(); iter != end(); )
+    {
+        iterator nextiter = iter++;
+        LLSelectNode* node = *nextiter;
+        LLViewerObject* object = (*nextiter)->getObject();
+        if (!object)
+            continue;
+        S32 num_tes = llmin((S32)object->getNumTEs(), (S32)object->getNumFaces()); // avatars have TEs but no faces
+        for (S32 te = 0; te < num_tes; ++te)
+        {
+            if (node->isTESelected(te))
+            {
+                bool r = func->apply(object, te);
+                if (firstonly && r)
+                    return true;
+                else
+                    result = result && r;
+            }
+        }
+    }
+    return result;
 }
 
 bool LLObjectSelection::applyToNodes(LLSelectedNodeFunctor *func, bool firstonly)
 {
-	bool result = firstonly ? false : true;
-	for (iterator iter = begin(); iter != end(); )
-	{
-		iterator nextiter = iter++;
-		LLSelectNode* node = *nextiter;
-		bool r = func->apply(node);
-		if (firstonly && r)
-			return true;
-		else
-			result = result && r;
-	}
-	return result;
+    bool result = firstonly ? false : true;
+    for (iterator iter = begin(); iter != end(); )
+    {
+        iterator nextiter = iter++;
+        LLSelectNode* node = *nextiter;
+        bool r = func->apply(node);
+        if (firstonly && r)
+            return true;
+        else
+            result = result && r;
+    }
+    return result;
 }
 
 bool LLObjectSelection::applyToRootNodes(LLSelectedNodeFunctor *func, bool firstonly)
 {
-	bool result = firstonly ? false : true;
-	for (root_iterator iter = root_begin(); iter != root_end(); )
-	{
-		root_iterator nextiter = iter++;
-		LLSelectNode* node = *nextiter;
-		bool r = func->apply(node);
-		if (firstonly && r)
-			return true;
-		else
-			result = result && r;
-	}
-	return result;
+    bool result = firstonly ? false : true;
+    for (root_iterator iter = root_begin(); iter != root_end(); )
+    {
+        root_iterator nextiter = iter++;
+        LLSelectNode* node = *nextiter;
+        bool r = func->apply(node);
+        if (firstonly && r)
+            return true;
+        else
+            result = result && r;
+    }
+    return result;
 }
 
 BOOL LLObjectSelection::isMultipleTESelected()
 {
-	BOOL te_selected = FALSE;
-	// ...all faces
-	for (LLSelectNode* nodep : begin_end())
-	{
-		for (S32 i = 0; i < SELECT_MAX_TES; i++)
-		{
-			if(nodep->isTESelected(i))
-			{
-				if(te_selected)
-				{
-					return TRUE;
-				}
-				te_selected = TRUE;
-			}
-		}
-	}
-	return FALSE;
+    BOOL te_selected = FALSE;
+    // ...all faces
+    for (LLSelectNode* nodep : begin_end())
+    {
+        for (S32 i = 0; i < SELECT_MAX_TES; i++)
+        {
+            if(nodep->isTESelected(i))
+            {
+                if(te_selected)
+                {
+                    return TRUE;
+                }
+                te_selected = TRUE;
+            }
+        }
+    }
+    return FALSE;
 }
 
 //-----------------------------------------------------------------------------
@@ -8074,7 +8074,7 @@ BOOL LLObjectSelection::isMultipleTESelected()
 //-----------------------------------------------------------------------------
 BOOL LLObjectSelection::contains(LLViewerObject* object)
 {
-	return findNode(object) != NULL;
+    return findNode(object) != NULL;
 }
 
 
@@ -8083,47 +8083,47 @@ BOOL LLObjectSelection::contains(LLViewerObject* object)
 //-----------------------------------------------------------------------------
 BOOL LLObjectSelection::contains(LLViewerObject* object, S32 te)
 {
-	if (te == SELECT_ALL_TES)
-	{
-		// ...all faces
-		for (LLSelectNode* nodep : begin_end())
-		{
-			if (nodep->getObject() == object)
-			{
-				// Optimization
-				if (nodep->getTESelectMask() == TE_SELECT_MASK_ALL)
-				{
-					return TRUE;
-				}
-
-				BOOL all_selected = TRUE;
-				for (S32 i = 0; i < object->getNumTEs(); i++)
-				{
-					all_selected = all_selected && nodep->isTESelected(i);
-				}
-				return all_selected;
-			}
-		}
-		return FALSE;
-	}
-	else
-	{
-		// ...one face
-		for (LLSelectNode* nodep : begin_end())
-		{
-			if (nodep->getObject() == object && nodep->isTESelected(te))
-			{
-				return TRUE;
-			}
-		}
-		return FALSE;
-	}
+    if (te == SELECT_ALL_TES)
+    {
+        // ...all faces
+        for (LLSelectNode* nodep : begin_end())
+        {
+            if (nodep->getObject() == object)
+            {
+                // Optimization
+                if (nodep->getTESelectMask() == TE_SELECT_MASK_ALL)
+                {
+                    return TRUE;
+                }
+
+                BOOL all_selected = TRUE;
+                for (S32 i = 0; i < object->getNumTEs(); i++)
+                {
+                    all_selected = all_selected && nodep->isTESelected(i);
+                }
+                return all_selected;
+            }
+        }
+        return FALSE;
+    }
+    else
+    {
+        // ...one face
+        for (LLSelectNode* nodep : begin_end())
+        {
+            if (nodep->getObject() == object && nodep->isTESelected(te))
+            {
+                return TRUE;
+            }
+        }
+        return FALSE;
+    }
 }
 
 // returns TRUE is any node is currenly worn as an attachment
 BOOL LLObjectSelection::isAttachment()
 {
-	return (mSelectType == SELECT_TYPE_ATTACHMENT || mSelectType == SELECT_TYPE_HUD);
+    return (mSelectType == SELECT_TYPE_ATTACHMENT || mSelectType == SELECT_TYPE_HUD);
 }
 
 //-----------------------------------------------------------------------------
@@ -8131,19 +8131,19 @@ BOOL LLObjectSelection::isAttachment()
 //-----------------------------------------------------------------------------
 LLViewerObject* getSelectedParentObject(LLViewerObject *object)
 {
-	LLViewerObject *parent;
-	while (object && (parent = (LLViewerObject*)object->getParent()))
-	{
-		if (parent->isSelected())
-		{
-			object = parent;
-		}
-		else
-		{
-			break;
-		}
-	}
-	return object;
+    LLViewerObject *parent;
+    while (object && (parent = (LLViewerObject*)object->getParent()))
+    {
+        if (parent->isSelected())
+        {
+            object = parent;
+        }
+        else
+        {
+            break;
+        }
+    }
+    return object;
 }
 
 //-----------------------------------------------------------------------------
@@ -8151,31 +8151,31 @@ LLViewerObject* getSelectedParentObject(LLViewerObject *object)
 //-----------------------------------------------------------------------------
 LLSelectNode* LLObjectSelection::getFirstNode(LLSelectedNodeFunctor* func)
 {
-	for (LLSelectNode* node : begin_end())
-	{
-		if (func == NULL || func->apply(node))
-		{
-			return node;
-		}
-	}
-	return NULL;
+    for (LLSelectNode* node : begin_end())
+    {
+        if (func == NULL || func->apply(node))
+        {
+            return node;
+        }
+    }
+    return NULL;
 }
 
 LLSelectNode* LLObjectSelection::getFirstRootNode(LLSelectedNodeFunctor* func, BOOL non_root_ok)
 {
-	for (LLSelectNode* node : root_begin_end())
-	{
-		if (func == NULL || func->apply(node))
-		{
-			return node;
-		}
-	}
-	if (non_root_ok)
-	{
-		// Get non root
-		return getFirstNode(func);
-	}
-	return NULL;
+    for (LLSelectNode* node : root_begin_end())
+    {
+        if (func == NULL || func->apply(node))
+        {
+            return node;
+        }
+    }
+    if (non_root_ok)
+    {
+        // Get non root
+        return getFirstNode(func);
+    }
+    return NULL;
 }
 
 
@@ -8184,16 +8184,16 @@ LLSelectNode* LLObjectSelection::getFirstRootNode(LLSelectedNodeFunctor* func, B
 //-----------------------------------------------------------------------------
 LLViewerObject* LLObjectSelection::getFirstSelectedObject(LLSelectedNodeFunctor* func, BOOL get_parent)
 {
-	LLSelectNode* res = getFirstNode(func);
-	if (res && get_parent)
-	{
-		return getSelectedParentObject(res->getObject());
-	}
-	else if (res)
-	{
-		return res->getObject();
-	}
-	return NULL;
+    LLSelectNode* res = getFirstNode(func);
+    if (res && get_parent)
+    {
+        return getSelectedParentObject(res->getObject());
+    }
+    else if (res)
+    {
+        return res->getObject();
+    }
+    return NULL;
 }
 
 //-----------------------------------------------------------------------------
@@ -8201,8 +8201,8 @@ LLViewerObject* LLObjectSelection::getFirstSelectedObject(LLSelectedNodeFunctor*
 //-----------------------------------------------------------------------------
 LLViewerObject* LLObjectSelection::getFirstObject()
 {
-	LLSelectNode* res = getFirstNode(NULL);
-	return res ? res->getObject() : NULL;
+    LLSelectNode* res = getFirstNode(NULL);
+    return res ? res->getObject() : NULL;
 }
 
 //-----------------------------------------------------------------------------
@@ -8210,8 +8210,8 @@ LLViewerObject* LLObjectSelection::getFirstObject()
 //-----------------------------------------------------------------------------
 LLViewerObject* LLObjectSelection::getFirstRootObject(BOOL non_root_ok)
 {
-	LLSelectNode* res = getFirstRootNode(NULL, non_root_ok);
-	return res ? res->getObject() : NULL;
+    LLSelectNode* res = getFirstRootNode(NULL, non_root_ok);
+    return res ? res->getObject() : NULL;
 }
 
 //-----------------------------------------------------------------------------
@@ -8219,16 +8219,16 @@ LLViewerObject* LLObjectSelection::getFirstRootObject(BOOL non_root_ok)
 //-----------------------------------------------------------------------------
 LLSelectNode* LLObjectSelection::getFirstMoveableNode(BOOL get_root_first)
 {
-	struct f : public LLSelectedNodeFunctor
-	{
-		bool apply(LLSelectNode* node)
-		{
-			LLViewerObject* obj = node->getObject();
-			return obj && obj->permMove() && !obj->isPermanentEnforced();
-		}
-	} func;
-	LLSelectNode* res = get_root_first ? getFirstRootNode(&func, TRUE) : getFirstNode(&func);
-	return res;
+    struct f : public LLSelectedNodeFunctor
+    {
+        bool apply(LLSelectNode* node)
+        {
+            LLViewerObject* obj = node->getObject();
+            return obj && obj->permMove() && !obj->isPermanentEnforced();
+        }
+    } func;
+    LLSelectNode* res = get_root_first ? getFirstRootNode(&func, TRUE) : getFirstNode(&func);
+    return res;
 }
 
 //-----------------------------------------------------------------------------
@@ -8236,15 +8236,15 @@ LLSelectNode* LLObjectSelection::getFirstMoveableNode(BOOL get_root_first)
 //-----------------------------------------------------------------------------
 LLViewerObject* LLObjectSelection::getFirstCopyableObject(BOOL get_parent)
 {
-	struct f : public LLSelectedNodeFunctor
-	{
-		bool apply(LLSelectNode* node)
-		{
-			LLViewerObject* obj = node->getObject();
-			return obj && obj->permCopy() && !obj->isAttachment();
-		}
-	} func;
-	return getFirstSelectedObject(&func, get_parent);
+    struct f : public LLSelectedNodeFunctor
+    {
+        bool apply(LLSelectNode* node)
+        {
+            LLViewerObject* obj = node->getObject();
+            return obj && obj->permCopy() && !obj->isAttachment();
+        }
+    } func;
+    return getFirstSelectedObject(&func, get_parent);
 }
 
 //-----------------------------------------------------------------------------
@@ -8252,31 +8252,31 @@ LLViewerObject* LLObjectSelection::getFirstCopyableObject(BOOL get_parent)
 //-----------------------------------------------------------------------------
 LLViewerObject* LLObjectSelection::getFirstDeleteableObject()
 {
-	//RN: don't currently support deletion of child objects, as that requires separating them first
-	// then derezzing to trash
-	
-	struct f : public LLSelectedNodeFunctor
-	{
-		bool apply(LLSelectNode* node)
-		{
-			LLViewerObject* obj = node->getObject();
-			// you can delete an object if you are the owner
-			// or you have permission to modify it.
-			if( obj && !obj->isPermanentEnforced() &&
-				( (obj->permModify()) ||
-				(obj->permYouOwner()) ||
-				(!obj->permAnyOwner())	))		// public
-			{
-				if( !obj->isAttachment() )
-				{
-					return true;
-				}
-			}
-			return false;
-		}
-	} func;
-	LLSelectNode* node = getFirstNode(&func);
-	return node ? node->getObject() : NULL;
+    //RN: don't currently support deletion of child objects, as that requires separating them first
+    // then derezzing to trash
+
+    struct f : public LLSelectedNodeFunctor
+    {
+        bool apply(LLSelectNode* node)
+        {
+            LLViewerObject* obj = node->getObject();
+            // you can delete an object if you are the owner
+            // or you have permission to modify it.
+            if( obj && !obj->isPermanentEnforced() &&
+                ( (obj->permModify()) ||
+                (obj->permYouOwner()) ||
+                (!obj->permAnyOwner())  ))      // public
+            {
+                if( !obj->isAttachment() )
+                {
+                    return true;
+                }
+            }
+            return false;
+        }
+    } func;
+    LLSelectNode* node = getFirstNode(&func);
+    return node ? node->getObject() : NULL;
 }
 
 //-----------------------------------------------------------------------------
@@ -8284,15 +8284,15 @@ LLViewerObject* LLObjectSelection::getFirstDeleteableObject()
 //-----------------------------------------------------------------------------
 LLViewerObject* LLObjectSelection::getFirstEditableObject(BOOL get_parent)
 {
-	struct f : public LLSelectedNodeFunctor
-	{
-		bool apply(LLSelectNode* node)
-		{
-			LLViewerObject* obj = node->getObject();
-			return obj && obj->permModify();
-		}
-	} func;
-	return getFirstSelectedObject(&func, get_parent);
+    struct f : public LLSelectedNodeFunctor
+    {
+        bool apply(LLSelectNode* node)
+        {
+            LLViewerObject* obj = node->getObject();
+            return obj && obj->permModify();
+        }
+    } func;
+    return getFirstSelectedObject(&func, get_parent);
 }
 
 //-----------------------------------------------------------------------------
@@ -8300,15 +8300,15 @@ LLViewerObject* LLObjectSelection::getFirstEditableObject(BOOL get_parent)
 //-----------------------------------------------------------------------------
 LLViewerObject* LLObjectSelection::getFirstMoveableObject(BOOL get_parent)
 {
-	struct f : public LLSelectedNodeFunctor
-	{
-		bool apply(LLSelectNode* node)
-		{
-			LLViewerObject* obj = node->getObject();
-			return obj && obj->permMove() && !obj->isPermanentEnforced();
-		}
-	} func;
-	return getFirstSelectedObject(&func, get_parent);
+    struct f : public LLSelectedNodeFunctor
+    {
+        bool apply(LLSelectNode* node)
+        {
+            LLViewerObject* obj = node->getObject();
+            return obj && obj->permMove() && !obj->isPermanentEnforced();
+        }
+    } func;
+    return getFirstSelectedObject(&func, get_parent);
 }
 
 //-----------------------------------------------------------------------------
@@ -8333,197 +8333,197 @@ LLViewerObject* LLObjectSelection::getFirstUndoEnabledObject(BOOL get_parent)
 bool LLSelectMgr::selectionMove(const LLVector3& displ,
                                   F32 roll, F32 pitch, F32 yaw, U32 update_type)
 {
-	if (update_type == UPD_NONE)
-	{
-		return false;
-	}
-	
-	LLVector3 displ_global;
-	bool update_success = true;
-	bool update_position = update_type & UPD_POSITION;
-	bool update_rotation = update_type & UPD_ROTATION;
-	const bool noedit_linked_parts = !ALControlCache::EditLinkedParts;
-	
-	LLObjectSelectionHandle selection = getSelection();
-
-	if (update_position)
-	{
-		// calculate the distance of the object closest to the camera origin
-		F32 min_dist_squared = F32_MAX; // value will be overridden in the loop
-		
-		const auto& origin = LLViewerCamera::getInstance()->getOrigin();
-
-		LLVector3 obj_pos;
-		for (LLSelectNode* nodep : selection->root_begin_end())
-		{
-			obj_pos = nodep->getObject()->getPositionEdit();
-			
-			F32 obj_dist_squared = dist_vec_squared(obj_pos, origin);
-			if (obj_dist_squared < min_dist_squared)
-			{
-				min_dist_squared = obj_dist_squared;
-			}
-		}
-		
-		// factor the distance into the displacement vector. This will get us
-		// equally visible movements for both close and far away selections.
-		F32 min_dist = sqrt((F32) sqrtf(min_dist_squared)) / 2;
-		displ_global.setVec(displ.mV[0] * min_dist,
-							displ.mV[1] * min_dist,
-							displ.mV[2] * min_dist);
-
-		// equates to: Displ_global = Displ * M_cam_axes_in_global_frame
-		displ_global = LLViewerCamera::getInstance()->rotateToAbsolute(displ_global);
-	}
-
-	LLQuaternion new_rot;
-	if (update_rotation)
-	{
-		// let's calculate the rotation around each camera axes 
-		LLQuaternion qx(roll, LLViewerCamera::getInstance()->getAtAxis());
-		LLQuaternion qy(pitch, LLViewerCamera::getInstance()->getLeftAxis());
-		LLQuaternion qz(yaw, LLViewerCamera::getInstance()->getUpAxis());
-		new_rot.setQuat(qx * qy * qz);
-	}
-	
-	LLViewerObject *obj;
-	S32 obj_count = getSelection()->getObjectCount();
-	for (LLSelectNode* nodep : selection->root_begin_end())
-	{
-		obj = nodep->getObject();
-		bool enable_pos = false, enable_rot = false;
-		bool perm_move = obj->permMove() && !obj->isPermanentEnforced();
-		bool perm_mod = obj->permModify();
-		
-		LLVector3d sel_center(getSelectionCenterGlobal());
-		
-		if (update_rotation)
-		{
-			enable_rot = perm_move 
-				&& ((perm_mod && !obj->isAttachment()) || noedit_linked_parts);
-
-			if (enable_rot)
-			{
-				int children_count = obj->getChildren().size();
-				if (obj_count > 1 && children_count > 0)
-				{
-					// for linked sets, rotate around the group center
-					const LLVector3 t(obj->getPositionGlobal() - sel_center);
-
-					// Ra = T x R x T^-1
-					LLMatrix4 mt;	mt.setTranslation(t);
-					const LLMatrix4 mnew_rot(new_rot);
-					LLMatrix4 mt_1;	mt_1.setTranslation(-t);
-					mt *= mnew_rot;
-					mt *= mt_1;
-					
-					// Rfin = Rcur * Ra
-					obj->setRotation(obj->getRotationEdit() * mt.quaternion());
-					displ_global += mt.getTranslation();
-				}
-				else
-				{
-					obj->setRotation(obj->getRotationEdit() * new_rot);
-				}
-			}
-			else
-			{
-				update_success = false;
-			}
-		}
-
-		if (update_position)
-		{
-			// establish if object can be moved or not
-			enable_pos = perm_move && !obj->isAttachment() 
-			&& (perm_mod || noedit_linked_parts);
-			
-			if (enable_pos)
-			{
-				obj->setPosition(obj->getPositionEdit() + displ_global);
-			}
-			else
-			{
-				update_success = false;
-			}
-		}
-		
-		if (enable_pos && enable_rot && obj->mDrawable.notNull())
-		{
-			gPipeline.markMoved(obj->mDrawable, TRUE);
-		}
-	}
-	
-	if (update_position && update_success && obj_count > 1)
-	{
-		updateSelectionCenter();
-	}
-	
-	return update_success;
+    if (update_type == UPD_NONE)
+    {
+        return false;
+    }
+
+    LLVector3 displ_global;
+    bool update_success = true;
+    bool update_position = update_type & UPD_POSITION;
+    bool update_rotation = update_type & UPD_ROTATION;
+    const bool noedit_linked_parts = !ALControlCache::EditLinkedParts;
+
+    LLObjectSelectionHandle selection = getSelection();
+
+    if (update_position)
+    {
+        // calculate the distance of the object closest to the camera origin
+        F32 min_dist_squared = F32_MAX; // value will be overridden in the loop
+
+        const auto& origin = LLViewerCamera::getInstance()->getOrigin();
+
+        LLVector3 obj_pos;
+        for (LLSelectNode* nodep : selection->root_begin_end())
+        {
+            obj_pos = nodep->getObject()->getPositionEdit();
+
+            F32 obj_dist_squared = dist_vec_squared(obj_pos, origin);
+            if (obj_dist_squared < min_dist_squared)
+            {
+                min_dist_squared = obj_dist_squared;
+            }
+        }
+
+        // factor the distance into the displacement vector. This will get us
+        // equally visible movements for both close and far away selections.
+        F32 min_dist = sqrt((F32) sqrtf(min_dist_squared)) / 2;
+        displ_global.setVec(displ.mV[0] * min_dist,
+                            displ.mV[1] * min_dist,
+                            displ.mV[2] * min_dist);
+
+        // equates to: Displ_global = Displ * M_cam_axes_in_global_frame
+        displ_global = LLViewerCamera::getInstance()->rotateToAbsolute(displ_global);
+    }
+
+    LLQuaternion new_rot;
+    if (update_rotation)
+    {
+        // let's calculate the rotation around each camera axes
+        LLQuaternion qx(roll, LLViewerCamera::getInstance()->getAtAxis());
+        LLQuaternion qy(pitch, LLViewerCamera::getInstance()->getLeftAxis());
+        LLQuaternion qz(yaw, LLViewerCamera::getInstance()->getUpAxis());
+        new_rot.setQuat(qx * qy * qz);
+    }
+
+    LLViewerObject *obj;
+    S32 obj_count = getSelection()->getObjectCount();
+    for (LLSelectNode* nodep : selection->root_begin_end())
+    {
+        obj = nodep->getObject();
+        bool enable_pos = false, enable_rot = false;
+        bool perm_move = obj->permMove() && !obj->isPermanentEnforced();
+        bool perm_mod = obj->permModify();
+
+        LLVector3d sel_center(getSelectionCenterGlobal());
+
+        if (update_rotation)
+        {
+            enable_rot = perm_move
+                && ((perm_mod && !obj->isAttachment()) || noedit_linked_parts);
+
+            if (enable_rot)
+            {
+                int children_count = obj->getChildren().size();
+                if (obj_count > 1 && children_count > 0)
+                {
+                    // for linked sets, rotate around the group center
+                    const LLVector3 t(obj->getPositionGlobal() - sel_center);
+
+                    // Ra = T x R x T^-1
+                    LLMatrix4 mt;   mt.setTranslation(t);
+                    const LLMatrix4 mnew_rot(new_rot);
+                    LLMatrix4 mt_1; mt_1.setTranslation(-t);
+                    mt *= mnew_rot;
+                    mt *= mt_1;
+
+                    // Rfin = Rcur * Ra
+                    obj->setRotation(obj->getRotationEdit() * mt.quaternion());
+                    displ_global += mt.getTranslation();
+                }
+                else
+                {
+                    obj->setRotation(obj->getRotationEdit() * new_rot);
+                }
+            }
+            else
+            {
+                update_success = false;
+            }
+        }
+
+        if (update_position)
+        {
+            // establish if object can be moved or not
+            enable_pos = perm_move && !obj->isAttachment()
+            && (perm_mod || noedit_linked_parts);
+
+            if (enable_pos)
+            {
+                obj->setPosition(obj->getPositionEdit() + displ_global);
+            }
+            else
+            {
+                update_success = false;
+            }
+        }
+
+        if (enable_pos && enable_rot && obj->mDrawable.notNull())
+        {
+            gPipeline.markMoved(obj->mDrawable, TRUE);
+        }
+    }
+
+    if (update_position && update_success && obj_count > 1)
+    {
+        updateSelectionCenter();
+    }
+
+    return update_success;
 }
 
 void LLSelectMgr::sendSelectionMove()
 {
-	LLSelectNode *node = mSelectedObjects->getFirstRootNode();
-	if (node == NULL)
-	{
-		return;
-	}
-	
-	//saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
-	
-	U32 update_type = UPD_POSITION | UPD_ROTATION;
-	LLViewerRegion *last_region, *curr_region = node->getObject()->getRegion();
-	S32 objects_in_this_packet = 0;
-
-	// apply to linked objects if unable to select their individual parts 
-	if (!ALControlCache::EditLinkedParts && !getTEMode())
-	{
-		// tell simulator to apply to whole linked sets
-		update_type |= UPD_LINKED_SETS;
-	}
-
-	// prepare first bulk message
-	gMessageSystem->newMessageFast(_PREHASH_MultipleObjectUpdate);
-	packAgentAndSessionID(&update_type);
-
-	LLViewerObject *obj = NULL;
-	for (LLSelectNode* nodep : getSelection()->root_begin_end())
-	{
-		obj = nodep->getObject();
-
-		// note: following code adapted from sendListToRegions() (@3924)
-		last_region = curr_region;
-		curr_region = obj->getRegion();
-
-		// if not simulator or message too big
-		if (curr_region != last_region
-			|| gMessageSystem->isSendFullFast(nullptr)
-			|| objects_in_this_packet >= MAX_OBJECTS_PER_PACKET)
-		{
-			// send sim the current message and start new one
-			gMessageSystem->sendReliable(last_region->getHost());
-			objects_in_this_packet = 0;
-			gMessageSystem->newMessageFast(_PREHASH_MultipleObjectUpdate);
-			packAgentAndSessionID(&update_type);
-		}
-
-		// add another instance of the body of data
-		packMultipleUpdate(nodep, &update_type);
-		++objects_in_this_packet;
-	}
-
-	// flush remaining messages
-	if (gMessageSystem->getCurrentSendTotal() > 0)
-	{
-		gMessageSystem->sendReliable(curr_region->getHost());
-	}
-	else
-	{
-		gMessageSystem->clearMessage();
-	}
-
-	//saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+    LLSelectNode *node = mSelectedObjects->getFirstRootNode();
+    if (node == NULL)
+    {
+        return;
+    }
+
+    //saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
+
+    U32 update_type = UPD_POSITION | UPD_ROTATION;
+    LLViewerRegion *last_region, *curr_region = node->getObject()->getRegion();
+    S32 objects_in_this_packet = 0;
+
+    // apply to linked objects if unable to select their individual parts
+    if (!ALControlCache::EditLinkedParts && !getTEMode())
+    {
+        // tell simulator to apply to whole linked sets
+        update_type |= UPD_LINKED_SETS;
+    }
+
+    // prepare first bulk message
+    gMessageSystem->newMessageFast(_PREHASH_MultipleObjectUpdate);
+    packAgentAndSessionID(&update_type);
+
+    LLViewerObject *obj = NULL;
+    for (LLSelectNode* nodep : getSelection()->root_begin_end())
+    {
+        obj = nodep->getObject();
+
+        // note: following code adapted from sendListToRegions() (@3924)
+        last_region = curr_region;
+        curr_region = obj->getRegion();
+
+        // if not simulator or message too big
+        if (curr_region != last_region
+            || gMessageSystem->isSendFullFast(nullptr)
+            || objects_in_this_packet >= MAX_OBJECTS_PER_PACKET)
+        {
+            // send sim the current message and start new one
+            gMessageSystem->sendReliable(last_region->getHost());
+            objects_in_this_packet = 0;
+            gMessageSystem->newMessageFast(_PREHASH_MultipleObjectUpdate);
+            packAgentAndSessionID(&update_type);
+        }
+
+        // add another instance of the body of data
+        packMultipleUpdate(nodep, &update_type);
+        ++objects_in_this_packet;
+    }
+
+    // flush remaining messages
+    if (gMessageSystem->getCurrentSendTotal() > 0)
+    {
+        gMessageSystem->sendReliable(curr_region->getHost());
+    }
+    else
+    {
+        gMessageSystem->clearMessage();
+    }
+
+    //saveSelectedObjectTransform(SELECT_ACTION_TYPE_PICK);
 }
 
 template<>
diff --git a/indra/newview/llselectmgr.h b/indra/newview/llselectmgr.h
index 9a550f163d98116d1ffe70372af459f3e1aec965..d4afaefed4d40401a157e26b466345ad732097ee 100644
--- a/indra/newview/llselectmgr.h
+++ b/indra/newview/llselectmgr.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llselectmgr.h
  * @brief A manager for selected objects and TEs.
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -42,7 +42,7 @@
 #include "llbbox.h"
 #include "llpermissions.h"
 #include "llcontrol.h"
-#include "llviewerobject.h"	// LLObjectSelection::getSelectedTEValue template
+#include "llviewerobject.h" // LLObjectSelection::getSelectedTEValue template
 #include "llmaterial.h"
 
 #include <deque>
@@ -55,30 +55,30 @@ class LLColor4;
 class LLVector3;
 class LLSelectNode;
 
-const U8 UPD_NONE      		= 0x00;
-const U8 UPD_POSITION  		= 0x01;
-const U8 UPD_ROTATION  		= 0x02;
-const U8 UPD_SCALE     		= 0x04;
-const U8 UPD_LINKED_SETS 	= 0x08;
-const U8 UPD_UNIFORM 		= 0x10;	// used with UPD_SCALE
+const U8 UPD_NONE           = 0x00;
+const U8 UPD_POSITION       = 0x01;
+const U8 UPD_ROTATION       = 0x02;
+const U8 UPD_SCALE          = 0x04;
+const U8 UPD_LINKED_SETS    = 0x08;
+const U8 UPD_UNIFORM        = 0x10; // used with UPD_SCALE
 
 // This is used by the DeRezObject message to determine where to put
 // derezed tasks.
 enum EDeRezDestination
 {
-	DRD_SAVE_INTO_AGENT_INVENTORY = 0,
-	DRD_ACQUIRE_TO_AGENT_INVENTORY = 1,		// try to leave copy in world
-	DRD_SAVE_INTO_TASK_INVENTORY = 2,
-	DRD_ATTACHMENT = 3,
-	DRD_TAKE_INTO_AGENT_INVENTORY = 4,		// delete from world
-	DRD_FORCE_TO_GOD_INVENTORY = 5,			// force take copy
-	DRD_TRASH = 6,
-	DRD_ATTACHMENT_TO_INV = 7,
-	DRD_ATTACHMENT_EXISTS = 8,
-	DRD_RETURN_TO_OWNER = 9,				// back to owner's inventory
-	DRD_RETURN_TO_LAST_OWNER = 10,			// deeded object back to last owner's inventory
-
-	DRD_COUNT = 11
+    DRD_SAVE_INTO_AGENT_INVENTORY = 0,
+    DRD_ACQUIRE_TO_AGENT_INVENTORY = 1,     // try to leave copy in world
+    DRD_SAVE_INTO_TASK_INVENTORY = 2,
+    DRD_ATTACHMENT = 3,
+    DRD_TAKE_INTO_AGENT_INVENTORY = 4,      // delete from world
+    DRD_FORCE_TO_GOD_INVENTORY = 5,         // force take copy
+    DRD_TRASH = 6,
+    DRD_ATTACHMENT_TO_INV = 7,
+    DRD_ATTACHMENT_EXISTS = 8,
+    DRD_RETURN_TO_OWNER = 9,                // back to owner's inventory
+    DRD_RETURN_TO_LAST_OWNER = 10,          // deeded object back to last owner's inventory
+
+    DRD_COUNT = 11
 };
 
 
@@ -91,8 +91,8 @@ const S32 SELECT_MAX_TES = 32;
 // the operation was successful.
 struct LLSelectedObjectFunctor
 {
-	virtual ~LLSelectedObjectFunctor() {};
-	virtual bool apply(LLViewerObject* object) = 0;
+    virtual ~LLSelectedObjectFunctor() {};
+    virtual bool apply(LLViewerObject* object) = 0;
 };
 
 // Do something to all select nodes in the selection manager.
@@ -101,63 +101,63 @@ struct LLSelectedObjectFunctor
 // the operation was successful.
 struct LLSelectedNodeFunctor
 {
-	virtual ~LLSelectedNodeFunctor() {};
-	virtual bool apply(LLSelectNode* node) = 0;
+    virtual ~LLSelectedNodeFunctor() {};
+    virtual bool apply(LLSelectNode* node) = 0;
 };
 
 struct LLSelectedTEFunctor
 {
-	virtual ~LLSelectedTEFunctor() {};
-	virtual bool apply(LLViewerObject* object, S32 face) = 0;
+    virtual ~LLSelectedTEFunctor() {};
+    virtual bool apply(LLViewerObject* object, S32 face) = 0;
 };
 
 struct LLSelectedTEMaterialFunctor
 {
-	virtual ~LLSelectedTEMaterialFunctor() {};
-	virtual LLMaterialPtr apply(LLViewerObject* object, S32 face, LLTextureEntry* tep, LLMaterialPtr& current_material) = 0;
+    virtual ~LLSelectedTEMaterialFunctor() {};
+    virtual LLMaterialPtr apply(LLViewerObject* object, S32 face, LLTextureEntry* tep, LLMaterialPtr& current_material) = 0;
 };
 
 template <typename T> struct LLSelectedTEGetFunctor
 {
-	virtual ~LLSelectedTEGetFunctor() {};
-	virtual T get(LLViewerObject* object, S32 te) = 0;
+    virtual ~LLSelectedTEGetFunctor() {};
+    virtual T get(LLViewerObject* object, S32 te) = 0;
 };
 
 template <typename T> struct LLCheckIdenticalFunctor
 {
-	static bool same(const T& a, const T& b, const T& tolerance);
+    static bool same(const T& a, const T& b, const T& tolerance);
 };
 
 typedef enum e_send_type
 {
-	SEND_ONLY_ROOTS,
-	SEND_INDIVIDUALS,
-	SEND_ROOTS_FIRST, // useful for serial undos on linked sets
-	SEND_CHILDREN_FIRST // useful for serial transforms of linked sets
+    SEND_ONLY_ROOTS,
+    SEND_INDIVIDUALS,
+    SEND_ROOTS_FIRST, // useful for serial undos on linked sets
+    SEND_CHILDREN_FIRST // useful for serial transforms of linked sets
 } ESendType;
 
 typedef enum e_grid_mode
 {
-	GRID_MODE_WORLD,
-	GRID_MODE_LOCAL,
-	GRID_MODE_REF_OBJECT
+    GRID_MODE_WORLD,
+    GRID_MODE_LOCAL,
+    GRID_MODE_REF_OBJECT
 } EGridMode;
 
 typedef enum e_action_type
 {
-	SELECT_ACTION_TYPE_BEGIN,
-	SELECT_ACTION_TYPE_PICK,
-	SELECT_ACTION_TYPE_MOVE,
-	SELECT_ACTION_TYPE_ROTATE,
-	SELECT_ACTION_TYPE_SCALE,
-	NUM_ACTION_TYPES
+    SELECT_ACTION_TYPE_BEGIN,
+    SELECT_ACTION_TYPE_PICK,
+    SELECT_ACTION_TYPE_MOVE,
+    SELECT_ACTION_TYPE_ROTATE,
+    SELECT_ACTION_TYPE_SCALE,
+    NUM_ACTION_TYPES
 }EActionType;
 
 typedef enum e_selection_type
 {
-	SELECT_TYPE_WORLD,
-	SELECT_TYPE_ATTACHMENT,
-	SELECT_TYPE_HUD
+    SELECT_TYPE_WORLD,
+    SELECT_TYPE_ATTACHMENT,
+    SELECT_TYPE_HUD
 }ESelectType;
 
 typedef std::vector<LLPointer<LLGLTFMaterial> > gltf_materials_vec_t;
@@ -168,29 +168,29 @@ const S32 TE_SELECT_MASK_ALL = 0xFFFFFFFF;
 class LLSelectNode
 {
 public:
-	LLSelectNode(LLViewerObject* object, BOOL do_glow);
-	LLSelectNode(const LLSelectNode& nodep);
-	~LLSelectNode();
+    LLSelectNode(LLViewerObject* object, BOOL do_glow);
+    LLSelectNode(const LLSelectNode& nodep);
+    ~LLSelectNode();
 
-	void selectAllTEs(BOOL b);
-	void selectTE(S32 te_index, BOOL selected);
+    void selectAllTEs(BOOL b);
+    void selectTE(S32 te_index, BOOL selected);
     void selectGLTFNode(S32 node_index, S32 primitive_index, bool selected);
-	BOOL isTESelected(S32 te_index) const;
-	bool hasSelectedTE() const { return TE_SELECT_MASK_ALL & mTESelectMask; }
-	S32 getLastSelectedTE() const;
-	S32 getLastOperatedTE() const { return mLastTESelected; }
-	S32 getTESelectMask() { return mTESelectMask; }
-	void renderOneSilhouette(const LLColor4 &color);
-	void setTransient(BOOL transient) { mTransient = transient; }
-	BOOL isTransient() const { return mTransient; }
-	LLViewerObject* getObject() const;
-	void setObject(LLViewerObject* object);
-	// *NOTE: invalidate stored textures and colors when # faces change
+    BOOL isTESelected(S32 te_index) const;
+    bool hasSelectedTE() const { return TE_SELECT_MASK_ALL & mTESelectMask; }
+    S32 getLastSelectedTE() const;
+    S32 getLastOperatedTE() const { return mLastTESelected; }
+    S32 getTESelectMask() { return mTESelectMask; }
+    void renderOneSilhouette(const LLColor4 &color);
+    void setTransient(BOOL transient) { mTransient = transient; }
+    BOOL isTransient() const { return mTransient; }
+    LLViewerObject* getObject() const;
+    void setObject(LLViewerObject* object);
+    // *NOTE: invalidate stored textures and colors when # faces change
     // Used by tools floater's color/texture pickers to restore changes
-	void saveColors();
-	void saveShinyColors();
-	void saveTextures(const uuid_vec_t& textures);
-	void saveTextureScaleRatios(LLRender::eTexIndex index_to_query);
+    void saveColors();
+    void saveShinyColors();
+    void saveTextures(const uuid_vec_t& textures);
+    void saveTextureScaleRatios(LLRender::eTexIndex index_to_query);
 
     // GLTF materials are applied to objects by ids,
     // overrides get applied on top of materials resulting in
@@ -199,203 +199,203 @@ class LLSelectNode
     // overrides get applied in live material editor
     void saveGLTFMaterials(const uuid_vec_t& materials, const gltf_materials_vec_t& override_materials);
 
-	BOOL allowOperationOnNode(PermissionBit op, U64 group_proxy_power) const;
+    BOOL allowOperationOnNode(PermissionBit op, U64 group_proxy_power) const;
 
 public:
-	BOOL			mIndividualSelection;		// For root objects and objects individually selected
-
-	BOOL			mTransient;
-	BOOL			mValid;				// is extra information valid?
-	LLPermissions*	mPermissions;
-	LLSaleInfo		mSaleInfo;
-	LLAggregatePermissions mAggregatePerm;
-	LLAggregatePermissions mAggregateTexturePerm;
-	LLAggregatePermissions mAggregateTexturePermOwner;
-	std::string		mName;
-	std::string		mDescription;
-	LLCategory		mCategory;
-	S16				mInventorySerial;
-	LLVector3		mSavedPositionLocal;	// for interactively modifying object position
-	LLVector3		mLastPositionLocal;
-    LLVector3		mLastMoveLocal;
-	LLVector3d		mSavedPositionGlobal;	// for interactively modifying object position
-	LLVector3		mSavedScale;			// for interactively modifying object scale
-	LLVector3		mLastScale;
-	LLQuaternion	mSavedRotation;			// for interactively modifying object rotation
-	LLQuaternion	mLastRotation;
-	BOOL			mDuplicated;
-	LLVector3d		mDuplicatePos;
-	LLQuaternion	mDuplicateRot;
-	LLUUID			mItemID;
-	LLUUID			mFolderID;
-	LLUUID			mFromTaskID;
-	std::string		mTouchName;
-	std::string		mSitName;
-	U64				mCreationDate;
-	std::vector<LLColor4>	mSavedColors;
-	std::vector<LLColor4>	mSavedShinyColors;
-	uuid_vec_t		mSavedTextures;
-    uuid_vec_t		mSavedGLTFMaterialIds;
+    BOOL            mIndividualSelection;       // For root objects and objects individually selected
+
+    BOOL            mTransient;
+    BOOL            mValid;             // is extra information valid?
+    LLPermissions*  mPermissions;
+    LLSaleInfo      mSaleInfo;
+    LLAggregatePermissions mAggregatePerm;
+    LLAggregatePermissions mAggregateTexturePerm;
+    LLAggregatePermissions mAggregateTexturePermOwner;
+    std::string     mName;
+    std::string     mDescription;
+    LLCategory      mCategory;
+    S16             mInventorySerial;
+    LLVector3       mSavedPositionLocal;    // for interactively modifying object position
+    LLVector3       mLastPositionLocal;
+    LLVector3       mLastMoveLocal;
+    LLVector3d      mSavedPositionGlobal;   // for interactively modifying object position
+    LLVector3       mSavedScale;            // for interactively modifying object scale
+    LLVector3       mLastScale;
+    LLQuaternion    mSavedRotation;         // for interactively modifying object rotation
+    LLQuaternion    mLastRotation;
+    BOOL            mDuplicated;
+    LLVector3d      mDuplicatePos;
+    LLQuaternion    mDuplicateRot;
+    LLUUID          mItemID;
+    LLUUID          mFolderID;
+    LLUUID          mFromTaskID;
+    std::string     mTouchName;
+    std::string     mSitName;
+    U64             mCreationDate;
+    std::vector<LLColor4>   mSavedColors;
+    std::vector<LLColor4>   mSavedShinyColors;
+    uuid_vec_t      mSavedTextures;
+    uuid_vec_t      mSavedGLTFMaterialIds;
     gltf_materials_vec_t mSavedGLTFOverrideMaterials;
-	std::vector<LLVector3>  mTextureScaleRatios;
-	std::vector<LLVector3>	mSilhouetteVertices;	// array of vertices to render silhouette of object
-	std::vector<LLVector3>	mSilhouetteNormals;	// array of normals to render silhouette of object
-	BOOL					mSilhouetteExists;	// need to generate silhouette?
+    std::vector<LLVector3>  mTextureScaleRatios;
+    std::vector<LLVector3>  mSilhouetteVertices;    // array of vertices to render silhouette of object
+    std::vector<LLVector3>  mSilhouetteNormals; // array of normals to render silhouette of object
+    BOOL                    mSilhouetteExists;  // need to generate silhouette?
     S32             mSelectedGLTFNode = -1;
     S32             mSelectedGLTFPrimitive = -1;
 
 protected:
-	mutable LLPointer<LLViewerObject>	mObject;
-	S32				mTESelectMask;
-	S32				mLastTESelected;
-    
+    mutable LLPointer<LLViewerObject>   mObject;
+    S32             mTESelectMask;
+    S32             mLastTESelected;
+
 };
 
 class LLObjectSelection : public LLRefCount
 {
-	friend class LLSelectMgr;
-	friend class LLSafeHandle<LLObjectSelection>;
-	friend class LLSelectionCallbackData;
+    friend class LLSelectMgr;
+    friend class LLSafeHandle<LLObjectSelection>;
+    friend class LLSelectionCallbackData;
 
 protected:
-	~LLObjectSelection();
+    ~LLObjectSelection();
 
 public:
-	typedef std::list<LLSelectNode*> list_t;
-	template <typename IT>
-	struct create_range_for
-	{
-		create_range_for() = delete;
-		create_range_for(list_t& inlist) : _list(inlist) {};
-		auto begin() { return IT(_list.begin(), _list.end()); }
-		auto end() { return IT(_list.end(), _list.end()); }
-		list_t& _list;
-	};
-
-	// Iterators
-	struct is_non_null
-	{
-		bool operator()(LLSelectNode* node)
-		{
-			return (node->getObject() != NULL);
-		}
-	};
-	typedef boost::filter_iterator<is_non_null, list_t::iterator > iterator;
-	iterator begin() { return iterator(mList.begin(), mList.end()); }
-	iterator end() { return iterator(mList.end(), mList.end()); }
-	auto begin_end() { return create_range_for<iterator>(mList); }
-
-	struct is_valid
-	{
-		bool operator()(LLSelectNode* node)
-		{
-			return (node->getObject() != NULL) && node->mValid;
-		}
-	};
-	typedef boost::filter_iterator<is_valid, list_t::iterator > valid_iterator;
-	valid_iterator valid_begin() { return valid_iterator(mList.begin(), mList.end()); }
-	valid_iterator valid_end() { return valid_iterator(mList.end(), mList.end()); }
-	auto valid_begin_end() { return create_range_for<valid_iterator>(mList); }
-
-	struct is_root
-	{
-		bool operator()(LLSelectNode* node);
-	};
-	typedef boost::filter_iterator<is_root, list_t::iterator > root_iterator;
-	root_iterator root_begin() { return root_iterator(mList.begin(), mList.end()); }
-	root_iterator root_end() { return root_iterator(mList.end(), mList.end()); }
-	auto root_begin_end() { return create_range_for<root_iterator>(mList); }
-
-	struct is_valid_root
-	{
-		bool operator()(LLSelectNode* node);
-	};
-	typedef boost::filter_iterator<is_valid_root, list_t::iterator > valid_root_iterator;
-	valid_root_iterator valid_root_begin() { return valid_root_iterator(mList.begin(), mList.end()); }
-	valid_root_iterator valid_root_end() { return valid_root_iterator(mList.end(), mList.end()); }
-	auto valid_root_begin_end() { return create_range_for<valid_root_iterator>(mList); }
-
-	struct is_root_object
-	{
-		bool operator()(LLSelectNode* node);
-	};
-	typedef boost::filter_iterator<is_root_object, list_t::iterator > root_object_iterator;
-	root_object_iterator root_object_begin() { return root_object_iterator(mList.begin(), mList.end()); }
-	root_object_iterator root_object_end() { return root_object_iterator(mList.end(), mList.end()); }
-	auto root_object_begin_end() { return create_range_for<root_object_iterator>(mList); }
+    typedef std::list<LLSelectNode*> list_t;
+    template <typename IT>
+    struct create_range_for
+    {
+        create_range_for() = delete;
+        create_range_for(list_t& inlist) : _list(inlist) {};
+        auto begin() { return IT(_list.begin(), _list.end()); }
+        auto end() { return IT(_list.end(), _list.end()); }
+        list_t& _list;
+    };
+
+    // Iterators
+    struct is_non_null
+    {
+        bool operator()(LLSelectNode* node)
+        {
+            return (node->getObject() != NULL);
+        }
+    };
+    typedef boost::filter_iterator<is_non_null, list_t::iterator > iterator;
+    iterator begin() { return iterator(mList.begin(), mList.end()); }
+    iterator end() { return iterator(mList.end(), mList.end()); }
+    auto begin_end() { return create_range_for<iterator>(mList); }
+
+    struct is_valid
+    {
+        bool operator()(LLSelectNode* node)
+        {
+            return (node->getObject() != NULL) && node->mValid;
+        }
+    };
+    typedef boost::filter_iterator<is_valid, list_t::iterator > valid_iterator;
+    valid_iterator valid_begin() { return valid_iterator(mList.begin(), mList.end()); }
+    valid_iterator valid_end() { return valid_iterator(mList.end(), mList.end()); }
+    auto valid_begin_end() { return create_range_for<valid_iterator>(mList); }
+
+    struct is_root
+    {
+        bool operator()(LLSelectNode* node);
+    };
+    typedef boost::filter_iterator<is_root, list_t::iterator > root_iterator;
+    root_iterator root_begin() { return root_iterator(mList.begin(), mList.end()); }
+    root_iterator root_end() { return root_iterator(mList.end(), mList.end()); }
+    auto root_begin_end() { return create_range_for<root_iterator>(mList); }
+
+    struct is_valid_root
+    {
+        bool operator()(LLSelectNode* node);
+    };
+    typedef boost::filter_iterator<is_valid_root, list_t::iterator > valid_root_iterator;
+    valid_root_iterator valid_root_begin() { return valid_root_iterator(mList.begin(), mList.end()); }
+    valid_root_iterator valid_root_end() { return valid_root_iterator(mList.end(), mList.end()); }
+    auto valid_root_begin_end() { return create_range_for<valid_root_iterator>(mList); }
+
+    struct is_root_object
+    {
+        bool operator()(LLSelectNode* node);
+    };
+    typedef boost::filter_iterator<is_root_object, list_t::iterator > root_object_iterator;
+    root_object_iterator root_object_begin() { return root_object_iterator(mList.begin(), mList.end()); }
+    root_object_iterator root_object_end() { return root_object_iterator(mList.end(), mList.end()); }
+    auto root_object_begin_end() { return create_range_for<root_object_iterator>(mList); }
 
 public:
-	LLObjectSelection();
-
-	void updateEffects();
-
-	BOOL isEmpty() const;
-
-	LLSelectNode*	getFirstNode(LLSelectedNodeFunctor* func = NULL);
-	LLSelectNode*	getFirstRootNode(LLSelectedNodeFunctor* func = NULL, BOOL non_root_ok = FALSE);
-	LLViewerObject* getFirstSelectedObject(LLSelectedNodeFunctor* func, BOOL get_parent = FALSE);
-	LLViewerObject*	getFirstObject();
-	LLViewerObject*	getFirstRootObject(BOOL non_root_ok = FALSE);
-	
-	LLSelectNode*	getFirstMoveableNode(BOOL get_root_first = FALSE);
-
-	LLViewerObject*	getFirstEditableObject(BOOL get_parent = FALSE);
-	LLViewerObject*	getFirstCopyableObject(BOOL get_parent = FALSE);
-	LLViewerObject* getFirstDeleteableObject();
-	LLViewerObject*	getFirstMoveableObject(BOOL get_parent = FALSE);
-	LLViewerObject*	getFirstUndoEnabledObject(BOOL get_parent = FALSE);
-
-	/// Return the object that lead to this selection, possible a child
-	LLViewerObject* getPrimaryObject() { return mPrimaryObject; }
-
-	// iterate through texture entries
-	template <typename T> bool getSelectedTEValue(LLSelectedTEGetFunctor<T>* func, T& res, bool has_tolerance = false, T tolerance = T());
-	template <typename T> bool isMultipleTEValue(LLSelectedTEGetFunctor<T>* func, const T& ignore_value);
-	
-	S32 getNumNodes();
-	LLSelectNode* findNode(LLViewerObject* objectp);
-
-	// count members
-	S32 getObjectCount();
-	F32 getSelectedObjectCost();
-	F32 getSelectedLinksetCost();
-	F32 getSelectedPhysicsCost();
-	F32 getSelectedLinksetPhysicsCost();
-	S32 getSelectedObjectRenderCost();
-	
-	F32 getSelectedObjectStreamingCost(S32* total_bytes = NULL, S32* visible_bytes = NULL);
-	U32 getSelectedObjectTriangleCount(S32* vcount = NULL);
-
-	S32 getTECount();
-	S32 getRootObjectCount();
-
-	BOOL isMultipleTESelected();
-	BOOL contains(LLViewerObject* object);
-	BOOL contains(LLViewerObject* object, S32 te);
-
-	// returns TRUE is any node is currenly worn as an attachment
-	BOOL isAttachment();
+    LLObjectSelection();
+
+    void updateEffects();
+
+    BOOL isEmpty() const;
+
+    LLSelectNode*   getFirstNode(LLSelectedNodeFunctor* func = NULL);
+    LLSelectNode*   getFirstRootNode(LLSelectedNodeFunctor* func = NULL, BOOL non_root_ok = FALSE);
+    LLViewerObject* getFirstSelectedObject(LLSelectedNodeFunctor* func, BOOL get_parent = FALSE);
+    LLViewerObject* getFirstObject();
+    LLViewerObject* getFirstRootObject(BOOL non_root_ok = FALSE);
+
+    LLSelectNode*   getFirstMoveableNode(BOOL get_root_first = FALSE);
+
+    LLViewerObject* getFirstEditableObject(BOOL get_parent = FALSE);
+    LLViewerObject* getFirstCopyableObject(BOOL get_parent = FALSE);
+    LLViewerObject* getFirstDeleteableObject();
+    LLViewerObject* getFirstMoveableObject(BOOL get_parent = FALSE);
+    LLViewerObject* getFirstUndoEnabledObject(BOOL get_parent = FALSE);
+
+    /// Return the object that lead to this selection, possible a child
+    LLViewerObject* getPrimaryObject() { return mPrimaryObject; }
+
+    // iterate through texture entries
+    template <typename T> bool getSelectedTEValue(LLSelectedTEGetFunctor<T>* func, T& res, bool has_tolerance = false, T tolerance = T());
+    template <typename T> bool isMultipleTEValue(LLSelectedTEGetFunctor<T>* func, const T& ignore_value);
+
+    S32 getNumNodes();
+    LLSelectNode* findNode(LLViewerObject* objectp);
+
+    // count members
+    S32 getObjectCount();
+    F32 getSelectedObjectCost();
+    F32 getSelectedLinksetCost();
+    F32 getSelectedPhysicsCost();
+    F32 getSelectedLinksetPhysicsCost();
+    S32 getSelectedObjectRenderCost();
+
+    F32 getSelectedObjectStreamingCost(S32* total_bytes = NULL, S32* visible_bytes = NULL);
+    U32 getSelectedObjectTriangleCount(S32* vcount = NULL);
+
+    S32 getTECount();
+    S32 getRootObjectCount();
+
+    BOOL isMultipleTESelected();
+    BOOL contains(LLViewerObject* object);
+    BOOL contains(LLViewerObject* object, S32 te);
+
+    // returns TRUE is any node is currenly worn as an attachment
+    BOOL isAttachment();
 
     bool checkAnimatedObjectEstTris();
     bool checkAnimatedObjectLinkable();
-    
-	// Apply functors to various subsets of the selected objects
-	// If firstonly is FALSE, returns the AND of all apply() calls.
-	// Else returns TRUE immediately if any apply() call succeeds (i.e. OR with early exit)
-	bool applyToRootObjects(LLSelectedObjectFunctor* func, bool firstonly = false);
-	bool applyToObjects(LLSelectedObjectFunctor* func);
-	bool applyToTEs(LLSelectedTEFunctor* func, bool firstonly = false);
-	bool applyToRootNodes(LLSelectedNodeFunctor* func, bool firstonly = false);
-	bool applyToNodes(LLSelectedNodeFunctor* func, bool firstonly = false);
-
-	/*
-	 * Used to apply (no-copy) textures to the selected object or
-	 * selected face/faces of the object.
-	 * This method moves (no-copy) texture to the object's inventory
-	 * and doesn't make copy of the texture for each face.
-	 * Then this only texture is used for all selected faces.
-	 */
-	void applyNoCopyTextureToTEs(LLViewerInventoryItem* item);
+
+    // Apply functors to various subsets of the selected objects
+    // If firstonly is FALSE, returns the AND of all apply() calls.
+    // Else returns TRUE immediately if any apply() call succeeds (i.e. OR with early exit)
+    bool applyToRootObjects(LLSelectedObjectFunctor* func, bool firstonly = false);
+    bool applyToObjects(LLSelectedObjectFunctor* func);
+    bool applyToTEs(LLSelectedTEFunctor* func, bool firstonly = false);
+    bool applyToRootNodes(LLSelectedNodeFunctor* func, bool firstonly = false);
+    bool applyToNodes(LLSelectedNodeFunctor* func, bool firstonly = false);
+
+    /*
+     * Used to apply (no-copy) textures to the selected object or
+     * selected face/faces of the object.
+     * This method moves (no-copy) texture to the object's inventory
+     * and doesn't make copy of the texture for each face.
+     * Then this only texture is used for all selected faces.
+     */
+    void applyNoCopyTextureToTEs(LLViewerInventoryItem* item);
     /*
      * Multi-purpose function for applying PBR materials to the
      * selected object or faces, any combination of copy/mod/transfer
@@ -408,24 +408,24 @@ class LLObjectSelection : public LLRefCount
      */
     bool applyRestrictedPbrMaterialToTEs(LLViewerInventoryItem* item);
 
-	ESelectType getSelectType() const { return mSelectType; }
+    ESelectType getSelectType() const { return mSelectType; }
 
 private:
-	void addNode(LLSelectNode *nodep);
-	void addNodeAtEnd(LLSelectNode *nodep);
-	void moveNodeToFront(LLSelectNode *nodep);
-	void removeNode(LLSelectNode *nodep);
-	void deleteAllNodes();
-	void cleanupNodes();
+    void addNode(LLSelectNode *nodep);
+    void addNodeAtEnd(LLSelectNode *nodep);
+    void moveNodeToFront(LLSelectNode *nodep);
+    void removeNode(LLSelectNode *nodep);
+    void deleteAllNodes();
+    void cleanupNodes();
 
 
 private:
-	list_t mList;
-	const LLObjectSelection &operator=(const LLObjectSelection &);
+    list_t mList;
+    const LLObjectSelection &operator=(const LLObjectSelection &);
 
-	LLPointer<LLViewerObject> mPrimaryObject;
-	std::map<LLPointer<LLViewerObject>, LLSelectNode*> mSelectNodeMap;
-	ESelectType mSelectType;
+    LLPointer<LLViewerObject> mPrimaryObject;
+    std::map<LLPointer<LLViewerObject>, LLSelectNode*> mSelectNodeMap;
+    ESelectType mSelectType;
 };
 
 typedef LLSafeHandle<LLObjectSelection> LLObjectSelectionHandle;
@@ -443,70 +443,70 @@ class LLSelectionCallbackData
 {
 public:
     LLSelectionCallbackData();
-    LLObjectSelectionHandle	getSelection() { return mSelectedObjects; }
+    LLObjectSelectionHandle getSelection() { return mSelectedObjects; }
 private:
-    LLObjectSelectionHandle					mSelectedObjects;
+    LLObjectSelectionHandle                 mSelectedObjects;
 };
 
 class LLSelectMgr final : public LLEditMenuHandler, public LLSimpleton<LLSelectMgr>
 {
 public:
-	static BOOL					sRectSelectInclusive;	// do we need to surround an object to pick it?
-	static BOOL					sRenderHiddenSelections;	// do we show selection silhouettes that are occluded?
-	static BOOL					sRenderLightRadius;	// do we show the radius of selected lights?
-
-	static F32					sHighlightThickness;
-	static F32					sHighlightUScale;
-	static F32					sHighlightVScale;
-	static F32					sHighlightAlpha;
-	static F32					sHighlightAlphaTest;
-	static F32					sHighlightUAnim;
-	static F32					sHighlightVAnim;
-	LLUIColor				sSilhouetteParentColor;
-	LLUIColor				sSilhouetteChildColor;
-	LLUIColor				sHighlightParentColor;
-	LLUIColor				sHighlightChildColor;
-	LLUIColor				sHighlightInspectColor;
-	LLUIColor				sContextSilhouetteColor;
-
-	LLCachedControl<bool>					mHideSelectedObjects;
-	LLCachedControl<bool>					mRenderHighlightSelections;
-	LLCachedControl<bool>					mAllowSelectAvatar;
-	LLCachedControl<bool>					mDebugSelectMgr;
+    static BOOL                 sRectSelectInclusive;   // do we need to surround an object to pick it?
+    static BOOL                 sRenderHiddenSelections;    // do we show selection silhouettes that are occluded?
+    static BOOL                 sRenderLightRadius; // do we show the radius of selected lights?
+
+    static F32                  sHighlightThickness;
+    static F32                  sHighlightUScale;
+    static F32                  sHighlightVScale;
+    static F32                  sHighlightAlpha;
+    static F32                  sHighlightAlphaTest;
+    static F32                  sHighlightUAnim;
+    static F32                  sHighlightVAnim;
+    LLUIColor               sSilhouetteParentColor;
+    LLUIColor               sSilhouetteChildColor;
+    LLUIColor               sHighlightParentColor;
+    LLUIColor               sHighlightChildColor;
+    LLUIColor               sHighlightInspectColor;
+    LLUIColor               sContextSilhouetteColor;
+
+    LLCachedControl<bool>                   mHideSelectedObjects;
+    LLCachedControl<bool>                   mRenderHighlightSelections;
+    LLCachedControl<bool>                   mAllowSelectAvatar;
+    LLCachedControl<bool>                   mDebugSelectMgr;
 
 public:
     LLSelectMgr();
     ~LLSelectMgr();
 
-	static void cleanupGlobals();
+    static void cleanupGlobals();
 
-	// LLEditMenuHandler interface
-	virtual BOOL canUndo() const override;
-	virtual void undo() override;
+    // LLEditMenuHandler interface
+    virtual BOOL canUndo() const override;
+    virtual void undo() override;
 
-	virtual BOOL canRedo() const override;
-	virtual void redo() override;
+    virtual BOOL canRedo() const override;
+    virtual void redo() override;
 
-	virtual BOOL canDoDelete() const override;
-	virtual void doDelete() override;
+    virtual BOOL canDoDelete() const override;
+    virtual void doDelete() override;
 
-	virtual void deselect() override;
-	virtual BOOL canDeselect() const override;
+    virtual void deselect() override;
+    virtual BOOL canDeselect() const override;
 
-	virtual void duplicate();
-	virtual BOOL canDuplicate() const;
+    virtual void duplicate();
+    virtual BOOL canDuplicate() const;
 
-	void clearSelections();
-	void update();
-	void updateEffects(); // Update HUD effects
+    void clearSelections();
+    void update();
+    void updateEffects(); // Update HUD effects
 
-	// When we edit object's position/rotation/scale we set local
-	// overrides and ignore any updates (override received valeus).
-	// When we send data to server, we send local values and reset
-	// overrides
-	void resetObjectOverrides();
-	void resetObjectOverrides(LLObjectSelectionHandle selected_handle);
-	void overrideObjectUpdates();
+    // When we edit object's position/rotation/scale we set local
+    // overrides and ignore any updates (override received valeus).
+    // When we send data to server, we send local values and reset
+    // overrides
+    void resetObjectOverrides();
+    void resetObjectOverrides(LLObjectSelectionHandle selected_handle);
+    void overrideObjectUpdates();
 
     void resetAvatarOverrides();
     void overrideAvatarUpdates();
@@ -532,431 +532,431 @@ class LLSelectMgr final : public LLEditMenuHandler, public LLSimpleton<LLSelectM
 public:
 
 
-	// Returns the previous value of mForceSelection
-	BOOL setForceSelection(BOOL force);
+    // Returns the previous value of mForceSelection
+    BOOL setForceSelection(BOOL force);
 
-	////////////////////////////////////////////////////////////////
-	// Selection methods
-	////////////////////////////////////////////////////////////////
+    ////////////////////////////////////////////////////////////////
+    // Selection methods
+    ////////////////////////////////////////////////////////////////
 
-	////////////////////////////////////////////////////////////////
-	// Add
-	////////////////////////////////////////////////////////////////
+    ////////////////////////////////////////////////////////////////
+    // Add
+    ////////////////////////////////////////////////////////////////
 
-	// This method is meant to select an object, and then select all
-	// of the ancestors and descendants. This should be the normal behavior.
-	//
-	// *NOTE: You must hold on to the object selection handle, otherwise
-	// the objects will be automatically deselected in 1 frame.
-	LLObjectSelectionHandle selectObjectAndFamily(LLViewerObject* object, BOOL add_to_end = FALSE, BOOL ignore_select_owned = FALSE);
+    // This method is meant to select an object, and then select all
+    // of the ancestors and descendants. This should be the normal behavior.
+    //
+    // *NOTE: You must hold on to the object selection handle, otherwise
+    // the objects will be automatically deselected in 1 frame.
+    LLObjectSelectionHandle selectObjectAndFamily(LLViewerObject* object, BOOL add_to_end = FALSE, BOOL ignore_select_owned = FALSE);
 
-	// For when you want just a child object.
+    // For when you want just a child object.
     LLObjectSelectionHandle selectObjectOnly(LLViewerObject* object, S32 face = SELECT_ALL_TES, S32 gltf_node = -1, S32 gltf_primitive = -1);
 
-	// Same as above, but takes a list of objects.  Used by rectangle select.
-	LLObjectSelectionHandle selectObjectAndFamily(const std::vector<LLViewerObject*>& object_list, BOOL send_to_sim = TRUE);
+    // Same as above, but takes a list of objects.  Used by rectangle select.
+    LLObjectSelectionHandle selectObjectAndFamily(const std::vector<LLViewerObject*>& object_list, BOOL send_to_sim = TRUE);
 
-	// converts all objects currently highlighted to a selection, and returns it
-	LLObjectSelectionHandle selectHighlightedObjects();
+    // converts all objects currently highlighted to a selection, and returns it
+    LLObjectSelectionHandle selectHighlightedObjects();
 
-	LLObjectSelectionHandle setHoverObject(LLViewerObject *objectp, S32 face = -1);
-	LLSelectNode *getHoverNode();
-	LLSelectNode *getPrimaryHoverNode();
+    LLObjectSelectionHandle setHoverObject(LLViewerObject *objectp, S32 face = -1);
+    LLSelectNode *getHoverNode();
+    LLSelectNode *getPrimaryHoverNode();
 
-	void highlightObjectOnly(LLViewerObject *objectp);
-	void highlightObjectAndFamily(LLViewerObject *objectp);
-	void highlightObjectAndFamily(const std::vector<LLViewerObject*>& list);
-
-	////////////////////////////////////////////////////////////////
-	// Remove
-	////////////////////////////////////////////////////////////////
-
-	void deselectObjectOnly(LLViewerObject* object, BOOL send_to_sim = TRUE);
-	void deselectObjectAndFamily(LLViewerObject* object, BOOL send_to_sim = TRUE, BOOL include_entire_object = FALSE);
-
-	// Send deselect messages to simulator, then clear the list
-	void deselectAll();
-	void deselectAllForStandingUp();
-
-	// deselect only if nothing else currently referencing the selection
-	void deselectUnused();
-
-	// Deselect if the selection center is too far away from the agent.
-	void deselectAllIfTooFar();
-
-	// Removes all highlighted objects from current selection
-	void deselectHighlightedObjects();
-
-	void unhighlightObjectOnly(LLViewerObject *objectp);
-	void unhighlightObjectAndFamily(LLViewerObject *objectp);
-	void unhighlightAll();
-
-	BOOL removeObjectFromSelections(const LLUUID &id);
-
-	////////////////////////////////////////////////////////////////
-	// Selection editing
-	////////////////////////////////////////////////////////////////
-	bool linkObjects();
-
-	bool unlinkObjects();
-
-	void confirmUnlinkObjects(const LLSD& notification, const LLSD& response);
-
-	bool enableLinkObjects();
-
-	bool enableUnlinkObjects();
-
-	////////////////////////////////////////////////////////////////
-	// Selection accessors
-	////////////////////////////////////////////////////////////////
-	LLObjectSelectionHandle	getHoverObjects() { return mHoverObjects; }
-	LLObjectSelectionHandle	getSelection() { return mSelectedObjects; }
-	// right now this just renders the selection with root/child colors instead of a single color
-	LLObjectSelectionHandle	getEditSelection() { convertTransient(); return mSelectedObjects; }
-	LLObjectSelectionHandle	getHighlightedObjects() { return mHighlightedObjects; }
-
-	////////////////////////////////////////////////////////////////
-	// Grid manipulation
-	////////////////////////////////////////////////////////////////
-	void			addGridObject(LLViewerObject* objectp);
-	void			clearGridObjects();
-	void			setGridMode(EGridMode mode);
-	EGridMode		getGridMode() { return mGridMode; }
-	void			getGrid(LLVector3& origin, LLQuaternion& rotation, LLVector3 &scale, bool for_snap_guides = false);
-
-	BOOL getTEMode() const { return mTEMode; }
-	void setTEMode(BOOL b) { mTEMode = b; }
-
-	BOOL shouldShowSelection() const { return mShowSelection; }
-
-	LLBBox getBBoxOfSelection() const;
-	LLBBox getSavedBBoxOfSelection() const { return mSavedSelectionBBox; }
-
-	void dump();
-	void cleanup();
-
-	void updateSilhouettes();
-	void renderSilhouettes(BOOL for_hud);
-	void enableSilhouette(BOOL enable) { mRenderSilhouettes = enable; }
-	
-	////////////////////////////////////////////////////////////////
-	// Utility functions that operate on the current selection
-	////////////////////////////////////////////////////////////////
-	void saveSelectedObjectTransform(EActionType action_type);
-	void saveSelectedObjectColors();
-	void saveSelectedShinyColors();
-	void saveSelectedObjectTextures();
-
-	void selectionUpdatePhysics(BOOL use_physics);
-	void selectionUpdateTemporary(BOOL is_temporary);
-	void selectionUpdatePhantom(BOOL is_ghost);
-	void selectionDump();
-
-	BOOL selectionAllPCode(LLPCode code);		// all objects have this PCode
-	BOOL selectionGetClickAction(U8 *out_action);
-	bool selectionGetIncludeInSearch(bool* include_in_search_out); // true if all selected objects have same
-	BOOL selectionGetGlow(F32 *glow);
-
-	void selectionSetPhysicsType(U8 type);
-	void selectionSetGravity(F32 gravity);
-	void selectionSetFriction(F32 friction);
-	void selectionSetDensity(F32 density);
-	void selectionSetRestitution(F32 restitution);
-	void selectionSetMaterial(U8 material);
-	bool selectionSetImage(const LLUUID& imageid); // could be item or asset id
+    void highlightObjectOnly(LLViewerObject *objectp);
+    void highlightObjectAndFamily(LLViewerObject *objectp);
+    void highlightObjectAndFamily(const std::vector<LLViewerObject*>& list);
+
+    ////////////////////////////////////////////////////////////////
+    // Remove
+    ////////////////////////////////////////////////////////////////
+
+    void deselectObjectOnly(LLViewerObject* object, BOOL send_to_sim = TRUE);
+    void deselectObjectAndFamily(LLViewerObject* object, BOOL send_to_sim = TRUE, BOOL include_entire_object = FALSE);
+
+    // Send deselect messages to simulator, then clear the list
+    void deselectAll();
+    void deselectAllForStandingUp();
+
+    // deselect only if nothing else currently referencing the selection
+    void deselectUnused();
+
+    // Deselect if the selection center is too far away from the agent.
+    void deselectAllIfTooFar();
+
+    // Removes all highlighted objects from current selection
+    void deselectHighlightedObjects();
+
+    void unhighlightObjectOnly(LLViewerObject *objectp);
+    void unhighlightObjectAndFamily(LLViewerObject *objectp);
+    void unhighlightAll();
+
+    BOOL removeObjectFromSelections(const LLUUID &id);
+
+    ////////////////////////////////////////////////////////////////
+    // Selection editing
+    ////////////////////////////////////////////////////////////////
+    bool linkObjects();
+
+    bool unlinkObjects();
+
+    void confirmUnlinkObjects(const LLSD& notification, const LLSD& response);
+
+    bool enableLinkObjects();
+
+    bool enableUnlinkObjects();
+
+    ////////////////////////////////////////////////////////////////
+    // Selection accessors
+    ////////////////////////////////////////////////////////////////
+    LLObjectSelectionHandle getHoverObjects() { return mHoverObjects; }
+    LLObjectSelectionHandle getSelection() { return mSelectedObjects; }
+    // right now this just renders the selection with root/child colors instead of a single color
+    LLObjectSelectionHandle getEditSelection() { convertTransient(); return mSelectedObjects; }
+    LLObjectSelectionHandle getHighlightedObjects() { return mHighlightedObjects; }
+
+    ////////////////////////////////////////////////////////////////
+    // Grid manipulation
+    ////////////////////////////////////////////////////////////////
+    void            addGridObject(LLViewerObject* objectp);
+    void            clearGridObjects();
+    void            setGridMode(EGridMode mode);
+    EGridMode       getGridMode() { return mGridMode; }
+    void            getGrid(LLVector3& origin, LLQuaternion& rotation, LLVector3 &scale, bool for_snap_guides = false);
+
+    BOOL getTEMode() const { return mTEMode; }
+    void setTEMode(BOOL b) { mTEMode = b; }
+
+    BOOL shouldShowSelection() const { return mShowSelection; }
+
+    LLBBox getBBoxOfSelection() const;
+    LLBBox getSavedBBoxOfSelection() const { return mSavedSelectionBBox; }
+
+    void dump();
+    void cleanup();
+
+    void updateSilhouettes();
+    void renderSilhouettes(BOOL for_hud);
+    void enableSilhouette(BOOL enable) { mRenderSilhouettes = enable; }
+
+    ////////////////////////////////////////////////////////////////
+    // Utility functions that operate on the current selection
+    ////////////////////////////////////////////////////////////////
+    void saveSelectedObjectTransform(EActionType action_type);
+    void saveSelectedObjectColors();
+    void saveSelectedShinyColors();
+    void saveSelectedObjectTextures();
+
+    void selectionUpdatePhysics(BOOL use_physics);
+    void selectionUpdateTemporary(BOOL is_temporary);
+    void selectionUpdatePhantom(BOOL is_ghost);
+    void selectionDump();
+
+    BOOL selectionAllPCode(LLPCode code);       // all objects have this PCode
+    BOOL selectionGetClickAction(U8 *out_action);
+    bool selectionGetIncludeInSearch(bool* include_in_search_out); // true if all selected objects have same
+    BOOL selectionGetGlow(F32 *glow);
+
+    void selectionSetPhysicsType(U8 type);
+    void selectionSetGravity(F32 gravity);
+    void selectionSetFriction(F32 friction);
+    void selectionSetDensity(F32 density);
+    void selectionSetRestitution(F32 restitution);
+    void selectionSetMaterial(U8 material);
+    bool selectionSetImage(const LLUUID& imageid); // could be item or asset id
     bool selectionSetGLTFMaterial(const LLUUID& mat_id); // material id only
-	void selectionSetColor(const LLColor4 &color);
-	void selectionSetColorOnly(const LLColor4 &color); // Set only the RGB channels
-	void selectionSetAlphaOnly(const F32 alpha); // Set only the alpha channel
-	void selectionRevertColors();
-	void selectionRevertShinyColors();
-	BOOL selectionRevertTextures();
+    void selectionSetColor(const LLColor4 &color);
+    void selectionSetColorOnly(const LLColor4 &color); // Set only the RGB channels
+    void selectionSetAlphaOnly(const F32 alpha); // Set only the alpha channel
+    void selectionRevertColors();
+    void selectionRevertShinyColors();
+    BOOL selectionRevertTextures();
     void selectionRevertGLTFMaterials();
-	void selectionSetBumpmap( U8 bumpmap, const LLUUID &image_id );
-	void selectionSetTexGen( U8 texgen );
-	void selectionSetShiny( U8 shiny, const LLUUID &image_id );
-	void selectionSetFullbright( U8 fullbright );
-	void selectionSetMedia( U8 media_type, const LLSD &media_data );
-	void selectionSetClickAction(U8 action);
-	void selectionSetIncludeInSearch(bool include_in_search);
-	void selectionSetGlow(const F32 glow);
-	void selectionSetMaterialParams(LLSelectedTEMaterialFunctor* material_func, int specific_te = -1);
-	void selectionRemoveMaterial();
-
-	void selectionSetObjectPermissions(U8 perm_field, BOOL set, U32 perm_mask, BOOL override = FALSE);
-	void selectionSetObjectName(const std::string& name);
-	void selectionSetObjectDescription(const std::string& desc);
-	void selectionSetObjectCategory(const LLCategory& category);
-	void selectionSetObjectSaleInfo(const LLSaleInfo& sale_info);
-
-	void selectionTexScaleAutofit(F32 repeats_per_meter);
-	void adjustTexturesByScale(BOOL send_to_sim, BOOL stretch);
-
-	bool selectionMove(const LLVector3& displ, F32 rx, F32 ry, F32 rz,
-					   U32 update_type);
-	void sendSelectionMove();
-
-	void sendGodlikeRequest(const std::string& request, const std::string& parameter);
-
-
-	// will make sure all selected object meet current criteria, or deselect them otherwise
-	void validateSelection();
-
-	// returns TRUE if it is possible to select this object
-	BOOL canSelectObject(LLViewerObject* object, BOOL ignore_select_owned = FALSE);
-
-	// Returns TRUE if the viewer has information on all selected objects
-	BOOL selectGetAllRootsValid();
-	BOOL selectGetAllValid();
-	BOOL selectGetAllValidAndObjectsFound();
-
-	// returns TRUE if you can modify all selected objects. 
-	BOOL selectGetRootsModify();
-	BOOL selectGetModify();
-
-	// returns TRUE if all objects are in same region
-	BOOL selectGetSameRegion();
-
-	// returns TRUE if is all objects are non-permanent-enforced
-	BOOL selectGetRootsNonPermanentEnforced();
-	BOOL selectGetNonPermanentEnforced();
-
-	// returns TRUE if is all objects are permanent
-	BOOL selectGetRootsPermanent();
-	BOOL selectGetPermanent();
-
-	// returns TRUE if is all objects are character
-	BOOL selectGetRootsCharacter();
-	BOOL selectGetCharacter();
-
-	// returns TRUE if is all objects are not permanent
-	BOOL selectGetRootsNonPathfinding();
-	BOOL selectGetNonPathfinding();
-
-	// returns TRUE if is all objects are not permanent
-	BOOL selectGetRootsNonPermanent();
-	BOOL selectGetNonPermanent();
-
-	// returns TRUE if is all objects are not character
-	BOOL selectGetRootsNonCharacter();
-	BOOL selectGetNonCharacter();
-
-	BOOL selectGetEditableLinksets();
-	BOOL selectGetViewableCharacters();
-
-	// returns TRUE if selected objects can be transferred.
-	BOOL selectGetRootsTransfer();
-
-	// returns TRUE if selected objects can be copied.
-	BOOL selectGetRootsCopy();
-	
-	BOOL selectGetCreator(LLUUID& id, std::string& name);					// TRUE if all have same creator, returns id
-	BOOL selectGetOwner(LLUUID& id, std::string& name);					// TRUE if all objects have same owner, returns id
-	BOOL selectGetLastOwner(LLUUID& id, std::string& name);				// TRUE if all objects have same owner, returns id
-
-	// returns TRUE if all are the same. id is stuffed with
-	// the value found if available.
-	BOOL selectGetGroup(LLUUID& id); 
-	BOOL selectGetPerm(	U8 which_perm, U32* mask_on, U32* mask_off);	// TRUE if all have data, returns two masks, each indicating which bits are all on and all off
-
-	BOOL selectIsGroupOwned();											// TRUE if all root objects have valid data and are group owned.
-
-	// returns TRUE if all the nodes are valid. Accumulates
-	// permissions in the parameter.
-	BOOL selectGetPermissions(LLPermissions& perm);
-
-	// returns TRUE if all the nodes are valid. Depends onto "edit linked" state
-	// Children in linksets are a bit special - they require not only move permission
-	// but also modify if "edit linked" is set, since you move them relative to parent
-	BOOL selectGetEditMoveLinksetPermissions(bool &move, bool &modify);
-	
-	// Get a bunch of useful sale information for the object(s) selected.
-	// "_mixed" is true if not all objects have the same setting.
-	void selectGetAggregateSaleInfo(U32 &num_for_sale,
-									BOOL &is_for_sale_mixed, 
-									BOOL &is_sale_price_mixed,
-									S32 &total_sale_price,
-									S32 &individual_sale_price);
-
-	// returns TRUE if all nodes are valid. 
-	BOOL selectGetCategory(LLCategory& category);
-	
-	// returns TRUE if all nodes are valid. method also stores an
-	// accumulated sale info.
-	BOOL selectGetSaleInfo(LLSaleInfo& sale_info);
-
-	// returns TRUE if all nodes are valid. fills passed in object
-	// with the aggregate permissions of the selection.
-	BOOL selectGetAggregatePermissions(LLAggregatePermissions& ag_perm);
-
-	// returns TRUE if all nodes are valid. fills passed in object
-	// with the aggregate permissions for texture inventory items of the selection.
-	BOOL selectGetAggregateTexturePermissions(LLAggregatePermissions& ag_perm);
-
-	LLPermissions* findObjectPermissions(const LLViewerObject* object);
-
-	BOOL isMovableAvatarSelected();
-
-	void selectDelete();							// Delete on simulator
-	void selectForceDelete();			// just delete, no into trash
-	void selectDuplicate(const LLVector3& offset, BOOL select_copy);	// Duplicate on simulator
-	void repeatDuplicate();
-	void selectDuplicateOnRay(const LLVector3 &ray_start_region,
-								const LLVector3 &ray_end_region,
-								BOOL bypass_raycast,
-								BOOL ray_end_is_intersection,
-								const LLUUID &ray_target_id,
-								BOOL copy_centers,
-								BOOL copy_rotates,
-								BOOL select_copy);
-
-	void sendMultipleUpdate(U32 type);	// Position, rotation, scale all in one
-	void sendOwner(const LLUUID& owner_id, const LLUUID& group_id, BOOL override = FALSE);
-	void sendGroup(const LLUUID& group_id);
-
-	// Category ID is the UUID of the folder you want to contain the purchase.
-	// *NOTE: sale_info check doesn't work for multiple object buy,
-	// which UI does not currently support sale info is used for
-	// verification only, if it doesn't match region info then sale is
-	// canceled
-	void sendBuy(const LLUUID& buyer_id, const LLUUID& category_id, const LLSaleInfo sale_info);
-	void sendAttach(U8 attachment_point, bool replace);
-	void sendAttach(LLObjectSelectionHandle selection_handle, U8 attachment_point, bool replace);
-	void sendDetach();
-	void sendDropAttachment();
-	void sendLink();
-	void sendDelink();
-	//void sendHinge(U8 type);
-	//void sendDehinge();
-	void sendSelect();
-
-	void requestObjectPropertiesFamily(LLViewerObject* object);	// asks sim for creator, permissions, resources, etc.
-	static void processObjectProperties(LLMessageSystem *mesgsys, void **user_data);
-	static void processObjectPropertiesFamily(LLMessageSystem *mesgsys, void **user_data);
-	static void processForceObjectSelect(LLMessageSystem* msg, void**);
-
-	void requestGodInfo();
-
-	LLVector3d		getSelectionCenterGlobal() const	{ return mSelectionCenterGlobal; }
-	void			updateSelectionCenter();
+    void selectionSetBumpmap( U8 bumpmap, const LLUUID &image_id );
+    void selectionSetTexGen( U8 texgen );
+    void selectionSetShiny( U8 shiny, const LLUUID &image_id );
+    void selectionSetFullbright( U8 fullbright );
+    void selectionSetMedia( U8 media_type, const LLSD &media_data );
+    void selectionSetClickAction(U8 action);
+    void selectionSetIncludeInSearch(bool include_in_search);
+    void selectionSetGlow(const F32 glow);
+    void selectionSetMaterialParams(LLSelectedTEMaterialFunctor* material_func, int specific_te = -1);
+    void selectionRemoveMaterial();
+
+    void selectionSetObjectPermissions(U8 perm_field, BOOL set, U32 perm_mask, BOOL override = FALSE);
+    void selectionSetObjectName(const std::string& name);
+    void selectionSetObjectDescription(const std::string& desc);
+    void selectionSetObjectCategory(const LLCategory& category);
+    void selectionSetObjectSaleInfo(const LLSaleInfo& sale_info);
+
+    void selectionTexScaleAutofit(F32 repeats_per_meter);
+    void adjustTexturesByScale(BOOL send_to_sim, BOOL stretch);
+
+    bool selectionMove(const LLVector3& displ, F32 rx, F32 ry, F32 rz,
+                       U32 update_type);
+    void sendSelectionMove();
+
+    void sendGodlikeRequest(const std::string& request, const std::string& parameter);
+
+
+    // will make sure all selected object meet current criteria, or deselect them otherwise
+    void validateSelection();
+
+    // returns TRUE if it is possible to select this object
+    BOOL canSelectObject(LLViewerObject* object, BOOL ignore_select_owned = FALSE);
+
+    // Returns TRUE if the viewer has information on all selected objects
+    BOOL selectGetAllRootsValid();
+    BOOL selectGetAllValid();
+    BOOL selectGetAllValidAndObjectsFound();
+
+    // returns TRUE if you can modify all selected objects.
+    BOOL selectGetRootsModify();
+    BOOL selectGetModify();
+
+    // returns TRUE if all objects are in same region
+    BOOL selectGetSameRegion();
+
+    // returns TRUE if is all objects are non-permanent-enforced
+    BOOL selectGetRootsNonPermanentEnforced();
+    BOOL selectGetNonPermanentEnforced();
+
+    // returns TRUE if is all objects are permanent
+    BOOL selectGetRootsPermanent();
+    BOOL selectGetPermanent();
+
+    // returns TRUE if is all objects are character
+    BOOL selectGetRootsCharacter();
+    BOOL selectGetCharacter();
+
+    // returns TRUE if is all objects are not permanent
+    BOOL selectGetRootsNonPathfinding();
+    BOOL selectGetNonPathfinding();
+
+    // returns TRUE if is all objects are not permanent
+    BOOL selectGetRootsNonPermanent();
+    BOOL selectGetNonPermanent();
+
+    // returns TRUE if is all objects are not character
+    BOOL selectGetRootsNonCharacter();
+    BOOL selectGetNonCharacter();
+
+    BOOL selectGetEditableLinksets();
+    BOOL selectGetViewableCharacters();
+
+    // returns TRUE if selected objects can be transferred.
+    BOOL selectGetRootsTransfer();
+
+    // returns TRUE if selected objects can be copied.
+    BOOL selectGetRootsCopy();
+
+    BOOL selectGetCreator(LLUUID& id, std::string& name);                   // TRUE if all have same creator, returns id
+    BOOL selectGetOwner(LLUUID& id, std::string& name);                 // TRUE if all objects have same owner, returns id
+    BOOL selectGetLastOwner(LLUUID& id, std::string& name);             // TRUE if all objects have same owner, returns id
+
+    // returns TRUE if all are the same. id is stuffed with
+    // the value found if available.
+    BOOL selectGetGroup(LLUUID& id);
+    BOOL selectGetPerm( U8 which_perm, U32* mask_on, U32* mask_off);    // TRUE if all have data, returns two masks, each indicating which bits are all on and all off
+
+    BOOL selectIsGroupOwned();                                          // TRUE if all root objects have valid data and are group owned.
+
+    // returns TRUE if all the nodes are valid. Accumulates
+    // permissions in the parameter.
+    BOOL selectGetPermissions(LLPermissions& perm);
+
+    // returns TRUE if all the nodes are valid. Depends onto "edit linked" state
+    // Children in linksets are a bit special - they require not only move permission
+    // but also modify if "edit linked" is set, since you move them relative to parent
+    BOOL selectGetEditMoveLinksetPermissions(bool &move, bool &modify);
+
+    // Get a bunch of useful sale information for the object(s) selected.
+    // "_mixed" is true if not all objects have the same setting.
+    void selectGetAggregateSaleInfo(U32 &num_for_sale,
+                                    BOOL &is_for_sale_mixed,
+                                    BOOL &is_sale_price_mixed,
+                                    S32 &total_sale_price,
+                                    S32 &individual_sale_price);
+
+    // returns TRUE if all nodes are valid.
+    BOOL selectGetCategory(LLCategory& category);
+
+    // returns TRUE if all nodes are valid. method also stores an
+    // accumulated sale info.
+    BOOL selectGetSaleInfo(LLSaleInfo& sale_info);
+
+    // returns TRUE if all nodes are valid. fills passed in object
+    // with the aggregate permissions of the selection.
+    BOOL selectGetAggregatePermissions(LLAggregatePermissions& ag_perm);
+
+    // returns TRUE if all nodes are valid. fills passed in object
+    // with the aggregate permissions for texture inventory items of the selection.
+    BOOL selectGetAggregateTexturePermissions(LLAggregatePermissions& ag_perm);
+
+    LLPermissions* findObjectPermissions(const LLViewerObject* object);
+
+    BOOL isMovableAvatarSelected();
+
+    void selectDelete();                            // Delete on simulator
+    void selectForceDelete();           // just delete, no into trash
+    void selectDuplicate(const LLVector3& offset, BOOL select_copy);    // Duplicate on simulator
+    void repeatDuplicate();
+    void selectDuplicateOnRay(const LLVector3 &ray_start_region,
+                                const LLVector3 &ray_end_region,
+                                BOOL bypass_raycast,
+                                BOOL ray_end_is_intersection,
+                                const LLUUID &ray_target_id,
+                                BOOL copy_centers,
+                                BOOL copy_rotates,
+                                BOOL select_copy);
+
+    void sendMultipleUpdate(U32 type);  // Position, rotation, scale all in one
+    void sendOwner(const LLUUID& owner_id, const LLUUID& group_id, BOOL override = FALSE);
+    void sendGroup(const LLUUID& group_id);
+
+    // Category ID is the UUID of the folder you want to contain the purchase.
+    // *NOTE: sale_info check doesn't work for multiple object buy,
+    // which UI does not currently support sale info is used for
+    // verification only, if it doesn't match region info then sale is
+    // canceled
+    void sendBuy(const LLUUID& buyer_id, const LLUUID& category_id, const LLSaleInfo sale_info);
+    void sendAttach(U8 attachment_point, bool replace);
+    void sendAttach(LLObjectSelectionHandle selection_handle, U8 attachment_point, bool replace);
+    void sendDetach();
+    void sendDropAttachment();
+    void sendLink();
+    void sendDelink();
+    //void sendHinge(U8 type);
+    //void sendDehinge();
+    void sendSelect();
+
+    void requestObjectPropertiesFamily(LLViewerObject* object); // asks sim for creator, permissions, resources, etc.
+    static void processObjectProperties(LLMessageSystem *mesgsys, void **user_data);
+    static void processObjectPropertiesFamily(LLMessageSystem *mesgsys, void **user_data);
+    static void processForceObjectSelect(LLMessageSystem* msg, void**);
+
+    void requestGodInfo();
+
+    LLVector3d      getSelectionCenterGlobal() const    { return mSelectionCenterGlobal; }
+    void            updateSelectionCenter();
 
     void pauseAssociatedAvatars();
 
-	void resetAgentHUDZoom();
-	void setAgentHUDZoom(F32 target_zoom, F32 current_zoom);
-	void getAgentHUDZoom(F32 &target_zoom, F32 &current_zoom) const;
+    void resetAgentHUDZoom();
+    void setAgentHUDZoom(F32 target_zoom, F32 current_zoom);
+    void getAgentHUDZoom(F32 &target_zoom, F32 &current_zoom) const;
 
-	void updatePointAt();
+    void updatePointAt();
 
-	// Internal list maintenance functions. TODO: Make these private!
-	void remove(std::vector<LLViewerObject*>& objects);
-	void remove(LLViewerObject* object, S32 te = SELECT_ALL_TES, BOOL undoable = TRUE);
-	void removeAll();
-	void addAsIndividual(LLViewerObject* object, S32 te = SELECT_ALL_TES, BOOL undoable = TRUE, S32 gltf_node = -1, S32 gltf_primitive = -1);
-	void promoteSelectionToRoot();
-	void demoteSelectionToIndividuals();
+    // Internal list maintenance functions. TODO: Make these private!
+    void remove(std::vector<LLViewerObject*>& objects);
+    void remove(LLViewerObject* object, S32 te = SELECT_ALL_TES, BOOL undoable = TRUE);
+    void removeAll();
+    void addAsIndividual(LLViewerObject* object, S32 te = SELECT_ALL_TES, BOOL undoable = TRUE, S32 gltf_node = -1, S32 gltf_primitive = -1);
+    void promoteSelectionToRoot();
+    void demoteSelectionToIndividuals();
 
 private:
-	void convertTransient(); // converts temporarily selected objects to full-fledged selections
-	ESelectType getSelectTypeForObject(LLViewerObject* object);
-	void addAsFamily(std::vector<LLViewerObject*>& objects, BOOL add_to_end = FALSE);
-	void generateSilhouette(LLSelectNode *nodep, const LLVector3& view_point);
-	void updateSelectionSilhouette(LLObjectSelectionHandle object_handle, S32& num_sils_genned, std::vector<LLViewerObject*>& changed_objects);
-	// Send one message to each region containing an object on selection list.
-	void sendListToRegions(	const std::string& message_name,
-							void (*pack_header)(void *user_data), 
-							void (*pack_body)(LLSelectNode* node, void *user_data), 
-							void (*log_func)(LLSelectNode* node, void *user_data), 
-							void *user_data,
-							ESendType send_type);
-	void sendListToRegions(	LLObjectSelectionHandle selected_handle,
-							const std::string& message_name,
-							void (*pack_header)(void *user_data),
-							void (*pack_body)(LLSelectNode* node, void *user_data),
-							void (*log_func)(LLSelectNode* node, void *user_data),
-							void *user_data,
-							ESendType send_type);
-
-
-	static void packAgentID(	void *);
-	static void packAgentAndSessionID(void* user_data);
-	static void packAgentAndGroupID(void* user_data);
-	static void packAgentAndSessionAndGroupID(void* user_data);
-	static void packAgentIDAndSessionAndAttachment(void*);
-	static void packAgentGroupAndCatID(void*);
-	static void packDeleteHeader(void* userdata);
-	static void packDeRezHeader(void* user_data);
-	static void packObjectID(	LLSelectNode* node, void *);
-	static void packObjectIDAsParam(LLSelectNode* node, void *);
-	static void packObjectIDAndRotation(LLSelectNode* node, void *);
-	static void packObjectLocalID(LLSelectNode* node, void *);
-	static void packObjectClickAction(LLSelectNode* node, void* data);
-	static void packObjectIncludeInSearch(LLSelectNode* node, void* data);
-	static void packObjectName(LLSelectNode* node, void* user_data);
-	static void packObjectDescription(LLSelectNode* node, void* user_data);
-	static void packObjectCategory(LLSelectNode* node, void* user_data);
-	static void packObjectSaleInfo(LLSelectNode* node, void* user_data);
-	static void packBuyObjectIDs(LLSelectNode* node, void* user_data);
-	static void packDuplicate(	LLSelectNode* node, void *duplicate_data);
-	static void packDuplicateHeader(void*);
-	static void packDuplicateOnRayHead(void *user_data);
-	static void packPermissions(LLSelectNode* node, void *user_data);
-	static void packDeselect(	LLSelectNode* node, void *user_data);
-	static void packMultipleUpdate(LLSelectNode* node, void *user_data);
-	static void packPhysics(LLSelectNode* node, void *user_data);
-	static void packShape(LLSelectNode* node, void *user_data);
-	static void packOwnerHead(void *user_data);
-	static void packHingeHead(void *user_data);
-	static void packPermissionsHead(void* user_data);
-	static void packGodlikeHead(void* user_data);
+    void convertTransient(); // converts temporarily selected objects to full-fledged selections
+    ESelectType getSelectTypeForObject(LLViewerObject* object);
+    void addAsFamily(std::vector<LLViewerObject*>& objects, BOOL add_to_end = FALSE);
+    void generateSilhouette(LLSelectNode *nodep, const LLVector3& view_point);
+    void updateSelectionSilhouette(LLObjectSelectionHandle object_handle, S32& num_sils_genned, std::vector<LLViewerObject*>& changed_objects);
+    // Send one message to each region containing an object on selection list.
+    void sendListToRegions( const std::string& message_name,
+                            void (*pack_header)(void *user_data),
+                            void (*pack_body)(LLSelectNode* node, void *user_data),
+                            void (*log_func)(LLSelectNode* node, void *user_data),
+                            void *user_data,
+                            ESendType send_type);
+    void sendListToRegions( LLObjectSelectionHandle selected_handle,
+                            const std::string& message_name,
+                            void (*pack_header)(void *user_data),
+                            void (*pack_body)(LLSelectNode* node, void *user_data),
+                            void (*log_func)(LLSelectNode* node, void *user_data),
+                            void *user_data,
+                            ESendType send_type);
+
+
+    static void packAgentID(    void *);
+    static void packAgentAndSessionID(void* user_data);
+    static void packAgentAndGroupID(void* user_data);
+    static void packAgentAndSessionAndGroupID(void* user_data);
+    static void packAgentIDAndSessionAndAttachment(void*);
+    static void packAgentGroupAndCatID(void*);
+    static void packDeleteHeader(void* userdata);
+    static void packDeRezHeader(void* user_data);
+    static void packObjectID(   LLSelectNode* node, void *);
+    static void packObjectIDAsParam(LLSelectNode* node, void *);
+    static void packObjectIDAndRotation(LLSelectNode* node, void *);
+    static void packObjectLocalID(LLSelectNode* node, void *);
+    static void packObjectClickAction(LLSelectNode* node, void* data);
+    static void packObjectIncludeInSearch(LLSelectNode* node, void* data);
+    static void packObjectName(LLSelectNode* node, void* user_data);
+    static void packObjectDescription(LLSelectNode* node, void* user_data);
+    static void packObjectCategory(LLSelectNode* node, void* user_data);
+    static void packObjectSaleInfo(LLSelectNode* node, void* user_data);
+    static void packBuyObjectIDs(LLSelectNode* node, void* user_data);
+    static void packDuplicate(  LLSelectNode* node, void *duplicate_data);
+    static void packDuplicateHeader(void*);
+    static void packDuplicateOnRayHead(void *user_data);
+    static void packPermissions(LLSelectNode* node, void *user_data);
+    static void packDeselect(   LLSelectNode* node, void *user_data);
+    static void packMultipleUpdate(LLSelectNode* node, void *user_data);
+    static void packPhysics(LLSelectNode* node, void *user_data);
+    static void packShape(LLSelectNode* node, void *user_data);
+    static void packOwnerHead(void *user_data);
+    static void packHingeHead(void *user_data);
+    static void packPermissionsHead(void* user_data);
+    static void packGodlikeHead(void* user_data);
     static void logNoOp(LLSelectNode* node, void *user_data);
     static void logAttachmentRequest(LLSelectNode* node, void *user_data);
     static void logDetachRequest(LLSelectNode* node, void *user_data);
-	static bool confirmDelete(const LLSD& notification, const LLSD& response, LLObjectSelectionHandle handle);
+    static bool confirmDelete(const LLSD& notification, const LLSD& response, LLObjectSelectionHandle handle);
 
-	// Get the first ID that matches test and whether or not all ids are identical in selected objects.
-	void getFirst(LLSelectGetFirstTest* test);
+    // Get the first ID that matches test and whether or not all ids are identical in selected objects.
+    void getFirst(LLSelectGetFirstTest* test);
 
 public:
-	// Observer/callback support for when object selection changes or
-	// properties are received/updated
-	typedef boost::signals2::signal< void ()> update_signal_t;
-	update_signal_t mUpdateSignal;
+    // Observer/callback support for when object selection changes or
+    // properties are received/updated
+    typedef boost::signals2::signal< void ()> update_signal_t;
+    update_signal_t mUpdateSignal;
 
 private:
-	LLPointer<LLViewerTexture>				mSilhouetteImagep;
-	LLObjectSelectionHandle					mSelectedObjects;
-	LLObjectSelectionHandle					mHoverObjects;
-	LLObjectSelectionHandle					mHighlightedObjects;
-	std::set<LLPointer<LLViewerObject> >	mRectSelectedObjects;
-	
-	LLObjectSelection		mGridObjects;
-	LLQuaternion			mGridRotation;
-	LLVector3				mGridOrigin;
-	LLVector3				mGridScale;
-	EGridMode				mGridMode;
-
-	BOOL					mTEMode;			// render te
-	LLRender::eTexIndex	mTextureChannel; // diff, norm, or spec, depending on UI editing mode
-	LLVector3d				mSelectionCenterGlobal;
-	LLBBox					mSelectionBBox;
-
-	LLVector3d				mLastSentSelectionCenterGlobal;
-	BOOL					mShowSelection; // do we send the selection center name value and do we animate this selection?
-	LLVector3d				mLastCameraPos;		// camera position from last generation of selection silhouette
-	BOOL					mRenderSilhouettes;	// do we render the silhouette
-	LLBBox					mSavedSelectionBBox;
-
-	LLFrameTimer			mEffectsTimer;
-	BOOL					mForceSelection;
-
-    std::vector<LLAnimPauseRequest>	mPauseRequests;
+    LLPointer<LLViewerTexture>              mSilhouetteImagep;
+    LLObjectSelectionHandle                 mSelectedObjects;
+    LLObjectSelectionHandle                 mHoverObjects;
+    LLObjectSelectionHandle                 mHighlightedObjects;
+    std::set<LLPointer<LLViewerObject> >    mRectSelectedObjects;
+
+    LLObjectSelection       mGridObjects;
+    LLQuaternion            mGridRotation;
+    LLVector3               mGridOrigin;
+    LLVector3               mGridScale;
+    EGridMode               mGridMode;
+
+    BOOL                    mTEMode;            // render te
+    LLRender::eTexIndex mTextureChannel; // diff, norm, or spec, depending on UI editing mode
+    LLVector3d              mSelectionCenterGlobal;
+    LLBBox                  mSelectionBBox;
+
+    LLVector3d              mLastSentSelectionCenterGlobal;
+    BOOL                    mShowSelection; // do we send the selection center name value and do we animate this selection?
+    LLVector3d              mLastCameraPos;     // camera position from last generation of selection silhouette
+    BOOL                    mRenderSilhouettes; // do we render the silhouette
+    LLBBox                  mSavedSelectionBBox;
+
+    LLFrameTimer            mEffectsTimer;
+    BOOL                    mForceSelection;
+
+    std::vector<LLAnimPauseRequest> mPauseRequests;
 };
 
 // *DEPRECATED: For callbacks or observers, use
 // LLSelectMgr::getInstance()->mUpdateSignal.connect( callback )
 // Update subscribers to the selection list
-void dialog_refresh_all();		
+void dialog_refresh_all();
 
 // Templates
 //-----------------------------------------------------------------------------
@@ -964,113 +964,113 @@ void dialog_refresh_all();
 //-----------------------------------------------------------------------------
 template <typename T> bool LLObjectSelection::getSelectedTEValue(LLSelectedTEGetFunctor<T>* func, T& res, bool has_tolerance, T tolerance)
 {
-	bool have_first = false;
-	bool have_selected = false;
-	T selected_value = T();
-
-	// Now iterate through all TEs to test for sameness
-	bool identical = TRUE;
-	for (iterator iter = begin(); iter != end(); iter++)
-	{
-		LLSelectNode* node = *iter;
-		LLViewerObject* object = node->getObject();
-		S32 selected_te = -1;
-		if (object == getPrimaryObject())
-		{
-			selected_te = node->getLastSelectedTE();
-		}
-		for (S32 te = 0; te < object->getNumTEs(); ++te)
-		{
-			if (!node->isTESelected(te))
-			{
-				continue;
-			}
-			T value = func->get(object, te);
-			if (!have_first)
-			{
-				have_first = true;
-				if (!have_selected)
-				{
-					selected_value = value;
-				}
-			}
-			else
-			{
-				if ( value != selected_value )
-				{
+    bool have_first = false;
+    bool have_selected = false;
+    T selected_value = T();
+
+    // Now iterate through all TEs to test for sameness
+    bool identical = TRUE;
+    for (iterator iter = begin(); iter != end(); iter++)
+    {
+        LLSelectNode* node = *iter;
+        LLViewerObject* object = node->getObject();
+        S32 selected_te = -1;
+        if (object == getPrimaryObject())
+        {
+            selected_te = node->getLastSelectedTE();
+        }
+        for (S32 te = 0; te < object->getNumTEs(); ++te)
+        {
+            if (!node->isTESelected(te))
+            {
+                continue;
+            }
+            T value = func->get(object, te);
+            if (!have_first)
+            {
+                have_first = true;
+                if (!have_selected)
+                {
+                    selected_value = value;
+                }
+            }
+            else
+            {
+                if ( value != selected_value )
+                {
                     if (!has_tolerance)
                     {
-					    identical = false;
+                        identical = false;
                     }
                     else if (!LLCheckIdenticalFunctor<T>::same(value, selected_value, tolerance))
                     {
                         identical = false;
                     }
-				}
-				if (te == selected_te)
-				{
-					selected_value = value;
-					have_selected = true;
-				}
-			}
-		}
-		if (!identical && have_selected)
-		{
-			break;
-		}
-	}
-	if (have_first || have_selected)
-	{
-		res = selected_value;
-	}
-	return identical;
+                }
+                if (te == selected_te)
+                {
+                    selected_value = value;
+                    have_selected = true;
+                }
+            }
+        }
+        if (!identical && have_selected)
+        {
+            break;
+        }
+    }
+    if (have_first || have_selected)
+    {
+        res = selected_value;
+    }
+    return identical;
 }
 
 // Templates
 //-----------------------------------------------------------------------------
-// isMultipleTEValue iterate through all TEs and test for uniqueness 
-// with certain return value ignored when performing the test. 
+// isMultipleTEValue iterate through all TEs and test for uniqueness
+// with certain return value ignored when performing the test.
 // e.g. when testing if the selection has a unique non-empty homeurl :
-// you can set ignore_value = "" and it will only compare among the non-empty  
+// you can set ignore_value = "" and it will only compare among the non-empty
 // homeUrls and ignore the empty ones.
 //-----------------------------------------------------------------------------
 template <typename T> bool LLObjectSelection::isMultipleTEValue(LLSelectedTEGetFunctor<T>* func, const T& ignore_value)
 {
-	bool have_first = false;
-	T selected_value = T();
-	
-	// Now iterate through all TEs to test for sameness
-	bool unique = TRUE;
-	for (iterator iter = begin(); iter != end(); iter++)
-	{
-		LLSelectNode* node = *iter;
-		LLViewerObject* object = node->getObject();
-		for (S32 te = 0; te < object->getNumTEs(); ++te)
-		{
-			if (!node->isTESelected(te))
-			{
-				continue;
-			}
-			T value = func->get(object, te);
-			if(value == ignore_value)
-			{
-				continue;
-			}
-			if (!have_first)
-			{
-				have_first = true;
-			}
-			else
-			{
-				if (value !=selected_value  )
-				{
-					unique = false;
-					return !unique;
-				}
-			}
-		}
-	}
-	return !unique;
+    bool have_first = false;
+    T selected_value = T();
+
+    // Now iterate through all TEs to test for sameness
+    bool unique = TRUE;
+    for (iterator iter = begin(); iter != end(); iter++)
+    {
+        LLSelectNode* node = *iter;
+        LLViewerObject* object = node->getObject();
+        for (S32 te = 0; te < object->getNumTEs(); ++te)
+        {
+            if (!node->isTESelected(te))
+            {
+                continue;
+            }
+            T value = func->get(object, te);
+            if(value == ignore_value)
+            {
+                continue;
+            }
+            if (!have_first)
+            {
+                have_first = true;
+            }
+            else
+            {
+                if (value !=selected_value  )
+                {
+                    unique = false;
+                    return !unique;
+                }
+            }
+        }
+    }
+    return !unique;
 }
 
 
diff --git a/indra/newview/llsettingsvo.cpp b/indra/newview/llsettingsvo.cpp
index 012c5969e9dbfe8c713a9c33252c3dea78558d54..ccf4775a03acb9680da84c21f0038b5891718fa3 100644
--- a/indra/newview/llsettingsvo.cpp
+++ b/indra/newview/llsettingsvo.cpp
@@ -74,7 +74,7 @@
 extern BOOL gCubeSnapshot;
 
 //=========================================================================
-namespace 
+namespace
 {
     LLSD ensure_array_4(LLSD in, F32 fill);
     LLSD read_legacy_preset_data(const std::string &name, const std::string& path, LLSD  &messages);
@@ -187,7 +187,7 @@ void LLSettingsVOBase::onInventoryItemCreated(const LLUUID &inventoryId, LLSetti
         }
     }
     if (!settings)
-    {   // The item was created as new with no settings passed in.  Simulator should have given it the default for the type... check ID, 
+    {   // The item was created as new with no settings passed in.  Simulator should have given it the default for the type... check ID,
         // no need to upload asset.
         LLUUID asset_id;
         if (pitem)
@@ -248,11 +248,11 @@ void LLSettingsVOBase::updateInventoryItem(const LLSettingsBase::ptr_t &settings
         }
     }
 
-    std::stringstream buffer; 
+    std::stringstream buffer;
     LLSD settingdata(settings->getSettings());
     LLSDSerialize::serialize(settingdata, buffer, LLSDSerialize::LLSD_NOTATION);
 
-    LLResourceUploadInfo::ptr_t uploadInfo = std::make_shared<LLBufferedAssetUploadInfo>(inv_item_id, LLAssetType::AT_SETTINGS, buffer.str(), 
+    LLResourceUploadInfo::ptr_t uploadInfo = std::make_shared<LLBufferedAssetUploadInfo>(inv_item_id, LLAssetType::AT_SETTINGS, buffer.str(),
         [settings, callback](LLUUID itemId, LLUUID newAssetId, LLUUID newItemId, LLSD response)
         {
             LLSettingsVOBase::onAgentAssetUploadComplete(itemId, newAssetId, newItemId, response, settings, callback);
@@ -315,7 +315,7 @@ void LLSettingsVOBase::onTaskAssetUploadComplete(LLUUID itemId, LLUUID taskId, L
 void LLSettingsVOBase::getSettingsAsset(const LLUUID &assetId, LLSettingsVOBase::asset_download_fn callback)
 {
     gAssetStorage->getAssetData(assetId, LLAssetType::AT_SETTINGS,
-        [callback](const LLUUID &asset_id, LLAssetType::EType, void *, S32 status, LLExtStat ext_status) 
+        [callback](const LLUUID &asset_id, LLAssetType::EType, void *, S32 status, LLExtStat ext_status)
             { onAssetDownloadComplete(asset_id, status, ext_status, callback); },
         nullptr, true);
 
@@ -505,7 +505,7 @@ LLSettingsSky::ptr_t LLSettingsVOSky::buildFromLegacyPreset(const std::string &n
 
     if (!llsd_equals(oldsettings, oldsettings))
     {
-        LL_WARNS("SKY") << "Conversion to/from legacy does not match!\n" 
+        LL_WARNS("SKY") << "Conversion to/from legacy does not match!\n"
             << "Old: " << oldsettings
             << "new: " << oldsettings << LL_ENDL;
     }
@@ -603,7 +603,7 @@ LLSD LLSettingsVOSky::convertToLegacy(const LLSettingsSky::ptr_t &psky, bool isA
 {
     LLSD legacy(LLSD::emptyMap());
     LLSD settings = psky->getSettings();
-    
+
     convertAtmosphericsToLegacy(legacy, settings);
 
     legacy[SETTING_CLOUD_COLOR] = ensure_array_4(settings[SETTING_CLOUD_COLOR], 1.0);
@@ -612,15 +612,15 @@ LLSD LLSettingsVOSky::convertToLegacy(const LLSettingsSky::ptr_t &psky, bool isA
     legacy[SETTING_CLOUD_SCALE] = llsd::array(settings[SETTING_CLOUD_SCALE], LLSD::Real(0.0), LLSD::Real(0.0), LLSD::Real(1.0));
     legacy[SETTING_CLOUD_SCROLL_RATE] = settings[SETTING_CLOUD_SCROLL_RATE];
     legacy[SETTING_LEGACY_ENABLE_CLOUD_SCROLL] = llsd::array(LLSD::Boolean(!is_approx_zero(settings[SETTING_CLOUD_SCROLL_RATE][0].asReal())),
-        LLSD::Boolean(!is_approx_zero(settings[SETTING_CLOUD_SCROLL_RATE][1].asReal())));     
-    legacy[SETTING_CLOUD_SHADOW] = llsd::array(settings[SETTING_CLOUD_SHADOW].asReal(), 0.0f, 0.0f, 1.0f);    
+        LLSD::Boolean(!is_approx_zero(settings[SETTING_CLOUD_SCROLL_RATE][1].asReal())));
+    legacy[SETTING_CLOUD_SHADOW] = llsd::array(settings[SETTING_CLOUD_SHADOW].asReal(), 0.0f, 0.0f, 1.0f);
     legacy[SETTING_GAMMA] = llsd::array(settings[SETTING_GAMMA], 0.0f, 0.0f, 1.0f);
     legacy[SETTING_GLOW] = ensure_array_4(settings[SETTING_GLOW], 1.0);
     legacy[SETTING_LIGHT_NORMAL] = ensure_array_4(psky->getLightDirection().getValue(), 0.0f);
     legacy[SETTING_MAX_Y] = llsd::array(settings[SETTING_MAX_Y], 0.0f, 0.0f, 1.0f);
     legacy[SETTING_STAR_BRIGHTNESS] = settings[SETTING_STAR_BRIGHTNESS].asReal() / 250.0f; // convert from 0-500 -> 0-2 ala pre-FS-compat changes
     legacy[SETTING_SUNLIGHT_COLOR] = ensure_array_4(settings[SETTING_SUNLIGHT_COLOR], 1.0f);
-    
+
     LLVector3 dir = psky->getLightDirection();
 
     F32 phi     = asin(dir.mV[2]);
@@ -635,17 +635,17 @@ LLSD LLSettingsVOSky::convertToLegacy(const LLSettingsSky::ptr_t &psky, bool isA
     {
         theta += F_PI * 2;
     }
-    
+
     if (theta > 4 * F_PI)
     {
         theta = fmod(theta, 2 * F_PI);
     }
-    
+
     while (phi < -F_PI)
     {
         phi += 2 * F_PI;
     }
-    
+
     if (phi > 3 * F_PI)
     {
         phi = F_PI + fmod(phi - F_PI, 2 * F_PI);
@@ -653,8 +653,8 @@ LLSD LLSettingsVOSky::convertToLegacy(const LLSettingsSky::ptr_t &psky, bool isA
 
     legacy[SETTING_LEGACY_EAST_ANGLE] = theta;
     legacy[SETTING_LEGACY_SUN_ANGLE]  = phi;
- 
-   return legacy;    
+
+   return legacy;
 }
 
 //-------------------------------------------------------------------------
@@ -671,11 +671,11 @@ void LLSettingsVOSky::updateSettings()
     // Since WL scales everything by 2, there should always be at least a 2:1 brightness ratio
     // between sunlight and point lights in windlight to normalize point lights.
     //
-    // After some A/B comparison of relesae vs EEP, tweak to allow strength to fall below 2 
+    // After some A/B comparison of relesae vs EEP, tweak to allow strength to fall below 2
     // at night, for better match. (mSceneLightStrength is a divisor, so lower value means brighter
     // local lights)
     static LLCachedControl<F32> render_sun_dyn_range(gSavedSettings, "RenderSunDynamicRange");
-	F32 sun_dynamic_range = llmax(render_sun_dyn_range(), 0.0001f);
+    F32 sun_dynamic_range = llmax(render_sun_dyn_range(), 0.0001f);
     mSceneLightStrength = 2.0f * (0.75f + sun_dynamic_range * dp);
 
     gSky.setSunAndMoonDirectionsCFR(sun_direction, moon_direction);
@@ -696,11 +696,11 @@ void LLSettingsVOSky::applySpecial(void *ptarget, bool force)
     bool irradiance_pass = gCubeSnapshot && !gPipeline.mReflectionMapManager.isRadiancePass();
 
     LLShaderUniforms* shader = &((LLShaderUniforms*)ptarget)[LLGLSLShader::SG_DEFAULT];
-	{        
+    {
         shader->uniform3fv(LLViewerShaderMgr::LIGHTNORM, light_direction);
         shader->uniform3fv(LLShaderMgr::WL_CAMPOSLOCAL, LLViewerCamera::getInstance()->getOrigin());
-	} 
-    
+    }
+
     shader = &((LLShaderUniforms*)ptarget)[LLGLSLShader::SG_SKY];
 
     shader->uniform3fv(LLViewerShaderMgr::LIGHTNORM, light_direction);
@@ -762,13 +762,13 @@ void LLSettingsVOSky::applySpecial(void *ptarget, bool force)
             shader->uniform1f(LLShaderMgr::SKY_HDR_SCALE, sqrtf(g)*2.0); // use a modifier here so 1.0 maps to the "most desirable" default and the maximum value doesn't go off the rails
         }
         else if (psky->canAutoAdjust() && should_auto_adjust)
-        { // auto-adjust legacy sky to take advantage of probe ambiance 
+        { // auto-adjust legacy sky to take advantage of probe ambiance
             shader->uniform3fv(LLShaderMgr::AMBIENT, (ambient * auto_adjust_ambient_scale).mV);
             shader->uniform1f(LLShaderMgr::SKY_HDR_SCALE, auto_adjust_hdr_scale);
             LLColor3 blue_horizon = getBlueHorizon() * auto_adjust_blue_horizon_scale;
             LLColor3 blue_density = getBlueDensity() * auto_adjust_blue_density_scale;
             sun_light_color = sun_light_color * auto_adjust_sun_color_scale;
-            
+
             shader->uniform3fv(LLShaderMgr::SUNLIGHT_COLOR, sun_light_color.mV);
             shader->uniform3fv(LLShaderMgr::BLUE_DENSITY, blue_density.mV);
             shader->uniform3fv(LLShaderMgr::BLUE_HORIZON, blue_horizon.mV);
@@ -788,7 +788,7 @@ void LLSettingsVOSky::applySpecial(void *ptarget, bool force)
     shader->uniform1f(LLShaderMgr::SUN_MOON_GLOW_FACTOR, getSunMoonGlowFactor());
     shader->uniform1f(LLShaderMgr::DENSITY_MULTIPLIER, getDensityMultiplier());
     shader->uniform1f(LLShaderMgr::DISTANCE_MULTIPLIER, getDistanceMultiplier());
-    
+
     shader->uniform1f(LLShaderMgr::GAMMA, g);
 }
 
@@ -812,7 +812,7 @@ const LLSettingsSky::parammapping_t& LLSettingsVOSky::getParameterMap() const
 
         // Following values are always present, so we can just zero these ones, but used values from defaults()
         LLSD sky_defaults = LLSettingsSky::defaults();
-        
+
         param_map[SETTING_CLOUD_POS_DENSITY2] = DefaultParam(LLShaderMgr::CLOUD_POS_DENSITY2, sky_defaults[SETTING_CLOUD_POS_DENSITY2]);
         param_map[SETTING_CLOUD_SCALE] = DefaultParam(LLShaderMgr::CLOUD_SCALE, sky_defaults[SETTING_CLOUD_SCALE]);
         param_map[SETTING_CLOUD_SHADOW] = DefaultParam(LLShaderMgr::CLOUD_SHADOW, sky_defaults[SETTING_CLOUD_SHADOW]);
@@ -875,7 +875,7 @@ LLSettingsWater::ptr_t LLSettingsVOWater::buildFromLegacyPreset(const std::strin
         return LLSettingsWater::ptr_t();
     }
 
-    newsettings[SETTING_NAME] = name; 
+    newsettings[SETTING_NAME] = name;
     const auto& validations = LLSettingsWater::validationList();
     LLSD results = LLSettingsWater::settingValidation(newsettings, validations);
     if (!results["success"].asBoolean())
@@ -973,7 +973,7 @@ LLSD LLSettingsVOWater::convertToLegacy(const LLSettingsWater::ptr_t &pwater)
     legacy[SETTING_LEGACY_SCALE_BELOW] = settings[SETTING_SCALE_BELOW];
     legacy[SETTING_LEGACY_WAVE1_DIR] = settings[SETTING_WAVE1_DIR];
     legacy[SETTING_LEGACY_WAVE2_DIR] = settings[SETTING_WAVE2_DIR];
-    
+
     return legacy;
 }
 //-------------------------------------------------------------------------
@@ -986,8 +986,8 @@ void LLSettingsVOWater::applySpecial(void *ptarget, bool force)
 
     auto group = LLGLSLShader::SG_ANY;
     LLShaderUniforms* shader = &((LLShaderUniforms*)ptarget)[group];
-    
-	{
+
+    {
         F32 water_height = gAgent.getRegion() ? gAgent.getRegion()->getWaterHeight() : DEFAULT_WATER_HEIGHT;
 
         if (LLViewerCamera::instance().cameraUnderWater())
@@ -1158,7 +1158,7 @@ LLSettingsDay::ptr_t LLSettingsVODay::buildFromLegacyPreset(const std::string &n
     std::set<std::string> notfound;
 
     // expected and correct folder sctructure is to have
-    // three folders in widnlight's root: days, water, skies 
+    // three folders in widnlight's root: days, water, skies
     std::string base_path(gDirUtilp->getDirName(path));
     std::string water_path(base_path);
     std::string sky_path(base_path);
@@ -1249,7 +1249,7 @@ LLSettingsDay::ptr_t LLSettingsVODay::buildFromLegacyPreset(const std::string &n
 
     if (!llsd_equals(oldsettings, testsettings))
     {
-        LL_WARNS("DAYCYCLE") << "Conversion to/from legacy does not match!\n" 
+        LL_WARNS("DAYCYCLE") << "Conversion to/from legacy does not match!\n"
             << "Old: " << oldsettings
             << "new: " << testsettings << LL_ENDL;
     }
@@ -1284,7 +1284,7 @@ LLSettingsDay::ptr_t LLSettingsVODay::buildFromLegacyMessage(const LLUUID &regio
     {
         std::string newname = "sky:" + (*itm).first;
         LLSD newsettings = LLSettingsSky::translateLegacySettings((*itm).second);
-        
+
         newsettings[SETTING_NAME] = newname;
         frames[newname] = newsettings;
 
@@ -1323,7 +1323,7 @@ LLSettingsDay::ptr_t LLSettingsVODay::buildFromLegacyMessage(const LLUUID &regio
     }
 
     LLSettingsDay::ptr_t dayp = std::make_shared<LLSettingsVODay>(newsettings);
-    
+
     if (dayp)
     {
         // true for validation - either validate here, or when cloning for floater.
@@ -1473,34 +1473,34 @@ LLSD LLSettingsVODay::convertToLegacy(const LLSettingsVODay::ptr_t &pday)
 
     if (!pwater)
         pwater = LLSettingsVOWater::buildDefaultWater();
-    
+
     LLSD llsdwater = LLSettingsVOWater::convertToLegacy(pwater);
-    
+
     CycleTrack_t &tracksky = pday->getCycleTrack(1);   // first sky track
     std::map<std::string, LLSettingsSky::ptr_t> skys;
-    
+
     LLSD llsdcycle(LLSD::emptyArray());
-    
+
     for(CycleTrack_t::iterator it = tracksky.begin(); it != tracksky.end(); ++it)
     {
         size_t hash = (*it).second->getHash();
         std::stringstream name;
-        
+
         name << hash;
-        
+
         skys[name.str()] = std::static_pointer_cast<LLSettingsSky>((*it).second);
-        
+
         F32 frame = ((tracksky.size() == 1) && (it == tracksky.begin())) ? -1.0f : (*it).first;
         llsdcycle.append( llsd::array(LLSD::Real(frame), name.str()) );
     }
 
     LLSD llsdskylist(LLSD::emptyMap());
-    
+
     for (std::map<std::string, LLSettingsSky::ptr_t>::iterator its = skys.begin(); its != skys.end(); ++its)
     {
         LLSD llsdsky = LLSettingsVOSky::convertToLegacy((*its).second, false);
         llsdsky[SETTING_NAME] = (*its).first;
-        
+
         llsdskylist[(*its).first] = llsdsky;
     }
 
diff --git a/indra/newview/llspatialpartition.cpp b/indra/newview/llspatialpartition.cpp
index 69ae74e85dae92df54727a63c550049cefa765e6..874ab4d651a4b0b22111b40bcac8e03f414d4cfd 100644
--- a/indra/newview/llspatialpartition.cpp
+++ b/indra/newview/llspatialpartition.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llspatialpartition.cpp
  * @brief LLSpatialGroup class implementation and supporting functions
  *
  * $LicenseInfo:firstyear=2003&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -73,131 +73,131 @@ static F32 sCurMaxTexPriority = 1.f;
 void sg_assert(BOOL expr)
 {
 #if LL_OCTREE_PARANOIA_CHECK
-	if (!expr)
-	{
-		LL_ERRS() << "Octree invalid!" << LL_ENDL;
-	}
+    if (!expr)
+    {
+        LL_ERRS() << "Octree invalid!" << LL_ENDL;
+    }
 #endif
 }
 
 //returns:
-//	0 if sphere and AABB are not intersecting 
-//	1 if they are
-//	2 if AABB is entirely inside sphere
+//  0 if sphere and AABB are not intersecting
+//  1 if they are
+//  2 if AABB is entirely inside sphere
 
 S32 LLSphereAABB(const LLVector3& center, const LLVector3& size, const LLVector3& pos, const F32 &rad)
 {
-	S32 ret = 2;
-
-	LLVector3 min = center - size;
-	LLVector3 max = center + size;
-	for (U32 i = 0; i < 3; i++)
-	{
-		if (min.mV[i] > pos.mV[i] + rad ||
-			max.mV[i] < pos.mV[i] - rad)
-		{	//totally outside
-			return 0;
-		}
-		
-		if (min.mV[i] < pos.mV[i] - rad ||
-			max.mV[i] > pos.mV[i] + rad)
-		{	//intersecting
-			ret = 1;
-		}
-	}
-
-	return ret;
+    S32 ret = 2;
+
+    LLVector3 min = center - size;
+    LLVector3 max = center + size;
+    for (U32 i = 0; i < 3; i++)
+    {
+        if (min.mV[i] > pos.mV[i] + rad ||
+            max.mV[i] < pos.mV[i] - rad)
+        {   //totally outside
+            return 0;
+        }
+
+        if (min.mV[i] < pos.mV[i] - rad ||
+            max.mV[i] > pos.mV[i] + rad)
+        {   //intersecting
+            ret = 1;
+        }
+    }
+
+    return ret;
 }
 
 LLSpatialGroup::~LLSpatialGroup()
 {
-	/*if (sNoDelete)
-	{
-		LL_ERRS() << "Illegal deletion of LLSpatialGroup!" << LL_ENDL;
-	}*/
+    /*if (sNoDelete)
+    {
+        LL_ERRS() << "Illegal deletion of LLSpatialGroup!" << LL_ENDL;
+    }*/
+
+    if (gDebugGL)
+    {
+        gPipeline.checkReferences(this);
+    }
 
-	if (gDebugGL)
-	{
-		gPipeline.checkReferences(this);
-	}
+    if (hasState(DEAD))
+    {
+        sZombieGroups--;
+    }
 
-	if (hasState(DEAD))
-	{
-		sZombieGroups--;
-	}
-	
-	sNodeCount--;
+    sNodeCount--;
 
-	clearDrawMap();
+    clearDrawMap();
 }
 
 void LLSpatialGroup::clearDrawMap()
 {
-	mDrawMap.clear();
+    mDrawMap.clear();
 }
 
-BOOL LLSpatialGroup::isHUDGroup() 
+BOOL LLSpatialGroup::isHUDGroup()
 {
-	return getSpatialPartition() && getSpatialPartition()->isHUDPartition() ; 
+    return getSpatialPartition() && getSpatialPartition()->isHUDPartition() ;
 }
 
 void LLSpatialGroup::validate()
 {
-	ll_assert_aligned(this,64);
+    ll_assert_aligned(this,64);
 #if LL_OCTREE_PARANOIA_CHECK
 
-	sg_assert(!isState(DIRTY));
-	sg_assert(!isDead());
-
-	LLVector4a myMin;
-	myMin.setSub(mBounds[0], mBounds[1]);
-	LLVector4a myMax;
-	myMax.setAdd(mBounds[0], mBounds[1]);
-
-	validateDrawMap();
-
-	for (element_iter i = getDataBegin(); i != getDataEnd(); ++i)
-	{
-		LLDrawable* drawable = *i;
-		sg_assert(drawable->getSpatialGroup() == this);
-		if (drawable->getSpatialBridge())
-		{
-			sg_assert(drawable->getSpatialBridge() == getSpatialPartition()->asBridge());
-		}
-
-		/*if (drawable->isSpatialBridge())
-		{
-			LLSpatialPartition* part = drawable->asPartition();
-			if (!part)
-			{
-				LL_ERRS() << "Drawable reports it is a spatial bridge but not a partition." << LL_ENDL;
-			}
-			LLSpatialGroup* group = (LLSpatialGroup*) part->mOctree->getListener(0);
-			group->validate();
-		}*/
-	}
-
-	for (U32 i = 0; i < mOctreeNode->getChildCount(); ++i)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) mOctreeNode->getChild(i)->getListener(0);
-
-		group->validate();
-		
-		//ensure all children are enclosed in this node
-		LLVector4a center = group->mBounds[0];
-		LLVector4a size = group->mBounds[1];
-		
-		LLVector4a min;
-		min.setSub(center, size);
-		LLVector4a max;
-		max.setAdd(center, size);
-		
-		for (U32 j = 0; j < 3; j++)
-		{
-			sg_assert(min[j] >= myMin[j]-0.02f);
-			sg_assert(max[j] <= myMax[j]+0.02f);
-		}
-	}
+    sg_assert(!isState(DIRTY));
+    sg_assert(!isDead());
+
+    LLVector4a myMin;
+    myMin.setSub(mBounds[0], mBounds[1]);
+    LLVector4a myMax;
+    myMax.setAdd(mBounds[0], mBounds[1]);
+
+    validateDrawMap();
+
+    for (element_iter i = getDataBegin(); i != getDataEnd(); ++i)
+    {
+        LLDrawable* drawable = *i;
+        sg_assert(drawable->getSpatialGroup() == this);
+        if (drawable->getSpatialBridge())
+        {
+            sg_assert(drawable->getSpatialBridge() == getSpatialPartition()->asBridge());
+        }
+
+        /*if (drawable->isSpatialBridge())
+        {
+            LLSpatialPartition* part = drawable->asPartition();
+            if (!part)
+            {
+                LL_ERRS() << "Drawable reports it is a spatial bridge but not a partition." << LL_ENDL;
+            }
+            LLSpatialGroup* group = (LLSpatialGroup*) part->mOctree->getListener(0);
+            group->validate();
+        }*/
+    }
+
+    for (U32 i = 0; i < mOctreeNode->getChildCount(); ++i)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) mOctreeNode->getChild(i)->getListener(0);
+
+        group->validate();
+
+        //ensure all children are enclosed in this node
+        LLVector4a center = group->mBounds[0];
+        LLVector4a size = group->mBounds[1];
+
+        LLVector4a min;
+        min.setSub(center, size);
+        LLVector4a max;
+        max.setAdd(center, size);
+
+        for (U32 j = 0; j < 3; j++)
+        {
+            sg_assert(min[j] >= myMin[j]-0.02f);
+            sg_assert(max[j] <= myMax[j]+0.02f);
+        }
+    }
 
 #endif
 }
@@ -205,195 +205,195 @@ void LLSpatialGroup::validate()
 void LLSpatialGroup::validateDrawMap()
 {
 #if LL_OCTREE_PARANOIA_CHECK
-	for (draw_map_t::iterator i = mDrawMap.begin(); i != mDrawMap.end(); ++i)
-	{
-		LLSpatialGroup::drawmap_elem_t& draw_vec = i->second;
-		for (drawmap_elem_t::iterator j = draw_vec.begin(); j != draw_vec.end(); ++j)
-		{
-			LLDrawInfo& params = **j;
-		
-			params.validate();
-		}
-	}
+    for (draw_map_t::iterator i = mDrawMap.begin(); i != mDrawMap.end(); ++i)
+    {
+        LLSpatialGroup::drawmap_elem_t& draw_vec = i->second;
+        for (drawmap_elem_t::iterator j = draw_vec.begin(); j != draw_vec.end(); ++j)
+        {
+            LLDrawInfo& params = **j;
+
+            params.validate();
+        }
+    }
 #endif
 }
 
 BOOL LLSpatialGroup::updateInGroup(LLDrawable *drawablep, BOOL immediate)
 {
     LL_PROFILE_ZONE_SCOPED;
-	drawablep->updateSpatialExtents();
-
-	OctreeNode* parent = mOctreeNode->getOctParent();
-	
-	if (mOctreeNode->isInside(drawablep->getPositionGroup()) && 
-		(mOctreeNode->contains(drawablep->getEntry()) ||
-		 (drawablep->getBinRadius() > mOctreeNode->getSize()[0] &&
-				parent && parent->getElementCount() >= gOctreeMaxCapacity)))
-	{
-		unbound();
-		setState(OBJECT_DIRTY);
-		//setState(GEOM_DIRTY);
-		return TRUE;
-	}
-		
-	return FALSE;
+    drawablep->updateSpatialExtents();
+
+    OctreeNode* parent = mOctreeNode->getOctParent();
+
+    if (mOctreeNode->isInside(drawablep->getPositionGroup()) &&
+        (mOctreeNode->contains(drawablep->getEntry()) ||
+         (drawablep->getBinRadius() > mOctreeNode->getSize()[0] &&
+                parent && parent->getElementCount() >= gOctreeMaxCapacity)))
+    {
+        unbound();
+        setState(OBJECT_DIRTY);
+        //setState(GEOM_DIRTY);
+        return TRUE;
+    }
+
+    return FALSE;
 }
 
 void LLSpatialGroup::expandExtents(const LLVector4a* addingExtents, const LLXformMatrix& currentTransform)
 {
-	// Get coordinates of the adding extents
-	const LLVector4a& min = addingExtents[0];
-	const LLVector4a& max = addingExtents[1];
-
-	// Get coordinates of all corners of the bounding box
-	LLVector3 corners[] =
-	{
-		LLVector3(min[0], min[1], min[2]),
-		LLVector3(min[0], min[1], max[2]),
-		LLVector3(min[0], max[1], min[2]),
-		LLVector3(min[0], max[1], max[2]),
-		LLVector3(max[0], min[1], min[2]),
-		LLVector3(max[0], min[1], max[2]),
-		LLVector3(max[0], max[1], min[2]),
-		LLVector3(max[0], max[1], max[2])
-	};
-
-	// New extents (to be expanded)
-	LLVector3 extents[] =
-	{
-		LLVector3(mExtents[0].getF32ptr()),
-		LLVector3(mExtents[1].getF32ptr())
-	};
-
-	LLQuaternion backwardRotation = ~currentTransform.getWorldRotation();
-	for (LLVector3& corner : corners)
-	{
-		// Make coordinates relative to the current position
-		corner -= currentTransform.getWorldPosition();
-		// Rotate coordinates backward to the current rotation
-		corner.rotVec(backwardRotation);
-		// Expand root extents on the current corner
-		for (int j = 0; j < 3; ++j)
-		{
-			if (corner[j] < extents[0][j])
-				extents[0][j] = corner[j];
-			if (corner[j] > extents[1][j])
-				extents[1][j] = corner[j];
-		}
-	}
-
-	// Set new expanded extents
-	mExtents[0].load3(extents[0].mV);
-	mExtents[1].load3(extents[1].mV);
-
-	// Calculate new center and size
-	mBounds[0].setAdd(mExtents[0], mExtents[1]);
-	mBounds[0].mul(0.5f);
-	mBounds[1].setSub(mExtents[0], mExtents[1]);
-	mBounds[1].mul(0.5f);
+    // Get coordinates of the adding extents
+    const LLVector4a& min = addingExtents[0];
+    const LLVector4a& max = addingExtents[1];
+
+    // Get coordinates of all corners of the bounding box
+    LLVector3 corners[] =
+    {
+        LLVector3(min[0], min[1], min[2]),
+        LLVector3(min[0], min[1], max[2]),
+        LLVector3(min[0], max[1], min[2]),
+        LLVector3(min[0], max[1], max[2]),
+        LLVector3(max[0], min[1], min[2]),
+        LLVector3(max[0], min[1], max[2]),
+        LLVector3(max[0], max[1], min[2]),
+        LLVector3(max[0], max[1], max[2])
+    };
+
+    // New extents (to be expanded)
+    LLVector3 extents[] =
+    {
+        LLVector3(mExtents[0].getF32ptr()),
+        LLVector3(mExtents[1].getF32ptr())
+    };
+
+    LLQuaternion backwardRotation = ~currentTransform.getWorldRotation();
+    for (LLVector3& corner : corners)
+    {
+        // Make coordinates relative to the current position
+        corner -= currentTransform.getWorldPosition();
+        // Rotate coordinates backward to the current rotation
+        corner.rotVec(backwardRotation);
+        // Expand root extents on the current corner
+        for (int j = 0; j < 3; ++j)
+        {
+            if (corner[j] < extents[0][j])
+                extents[0][j] = corner[j];
+            if (corner[j] > extents[1][j])
+                extents[1][j] = corner[j];
+        }
+    }
+
+    // Set new expanded extents
+    mExtents[0].load3(extents[0].mV);
+    mExtents[1].load3(extents[1].mV);
+
+    // Calculate new center and size
+    mBounds[0].setAdd(mExtents[0], mExtents[1]);
+    mBounds[0].mul(0.5f);
+    mBounds[1].setSub(mExtents[0], mExtents[1]);
+    mBounds[1].mul(0.5f);
 }
 
 BOOL LLSpatialGroup::addObject(LLDrawable *drawablep)
 {
-	if(!drawablep)
-	{
-		return FALSE;
-	}
-	{
-		drawablep->setGroup(this);
-		setState(OBJECT_DIRTY | GEOM_DIRTY);
-		setOcclusionState(LLSpatialGroup::DISCARD_QUERY, LLSpatialGroup::STATE_MODE_ALL_CAMERAS);
-		gPipeline.markRebuild(this);
-		if (drawablep->isSpatialBridge())
-		{
-			mBridgeList.push_back((LLSpatialBridge*) drawablep);
-		}
-		if (drawablep->getRadius() > 1.f)
-		{
-			setState(IMAGE_DIRTY);
-		}
-	}
-
-	return TRUE;
+    if(!drawablep)
+    {
+        return FALSE;
+    }
+    {
+        drawablep->setGroup(this);
+        setState(OBJECT_DIRTY | GEOM_DIRTY);
+        setOcclusionState(LLSpatialGroup::DISCARD_QUERY, LLSpatialGroup::STATE_MODE_ALL_CAMERAS);
+        gPipeline.markRebuild(this);
+        if (drawablep->isSpatialBridge())
+        {
+            mBridgeList.push_back((LLSpatialBridge*) drawablep);
+        }
+        if (drawablep->getRadius() > 1.f)
+        {
+            setState(IMAGE_DIRTY);
+        }
+    }
+
+    return TRUE;
 }
 
 void LLSpatialGroup::rebuildGeom()
 {
-	if (!isDead())
-	{
-		getSpatialPartition()->rebuildGeom(this);
+    if (!isDead())
+    {
+        getSpatialPartition()->rebuildGeom(this);
 
-		if (hasState(LLSpatialGroup::MESH_DIRTY))
-		{
-			gPipeline.markMeshDirty(this);
-		}
-	}
+        if (hasState(LLSpatialGroup::MESH_DIRTY))
+        {
+            gPipeline.markMeshDirty(this);
+        }
+    }
 }
 
 void LLSpatialGroup::rebuildMesh()
 {
-	if (!isDead())
-	{
-		getSpatialPartition()->rebuildMesh(this);
-	}
+    if (!isDead())
+    {
+        getSpatialPartition()->rebuildMesh(this);
+    }
 }
 
 void LLSpatialPartition::rebuildGeom(LLSpatialGroup* group)
 {
-	if (group->isDead() || !group->hasState(LLSpatialGroup::GEOM_DIRTY))
-	{
-		return;
-	}
-
-	if (group->changeLOD())
-	{
-		group->mLastUpdateDistance = group->mDistance;
-		group->mLastUpdateViewAngle = group->mViewAngle;
-	}
-	
+    if (group->isDead() || !group->hasState(LLSpatialGroup::GEOM_DIRTY))
+    {
+        return;
+    }
+
+    if (group->changeLOD())
+    {
+        group->mLastUpdateDistance = group->mDistance;
+        group->mLastUpdateViewAngle = group->mViewAngle;
+    }
+
     LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL;
 
-	group->clearDrawMap();
-	
-	//get geometry count
-	U32 index_count = 0;
-	U32 vertex_count = 0;
+    group->clearDrawMap();
+
+    //get geometry count
+    U32 index_count = 0;
+    U32 vertex_count = 0;
 
     addGeometryCount(group, vertex_count, index_count);
-	
-	if (vertex_count > 0 && index_count > 0)
-	{ //create vertex buffer containing volume geometry for this node
-		{
-			group->mBuilt = 1.f;
-			if (group->mVertexBuffer.isNull() || 
+
+    if (vertex_count > 0 && index_count > 0)
+    { //create vertex buffer containing volume geometry for this node
+        {
+            group->mBuilt = 1.f;
+            if (group->mVertexBuffer.isNull() ||
                 group->mVertexBuffer->getNumVerts() != vertex_count ||
                 group->mVertexBuffer->getNumVerts() != index_count)
-			{
-				group->mVertexBuffer = new LLVertexBuffer(mVertexDataMask);
-				if (!group->mVertexBuffer->allocateBuffer(vertex_count, index_count))
-				{
-					LL_WARNS() << "Failed to allocate Vertex Buffer on rebuild to "
-						<< vertex_count << " vertices and "
-						<< index_count << " indices" << LL_ENDL;
-					group->mVertexBuffer = NULL;
-					group->mBufferMap.clear();
-				}
-			}
-		}
-
-		if (group->mVertexBuffer)
-		{
-			getGeometry(group);
-		}
-	}
-	else
-	{
-		group->mVertexBuffer = NULL;
-		group->mBufferMap.clear();
-	}
-
-	group->mLastUpdateTime = gFrameTimeSeconds;
-	group->clearState(LLSpatialGroup::GEOM_DIRTY);
+            {
+                group->mVertexBuffer = new LLVertexBuffer(mVertexDataMask);
+                if (!group->mVertexBuffer->allocateBuffer(vertex_count, index_count))
+                {
+                    LL_WARNS() << "Failed to allocate Vertex Buffer on rebuild to "
+                        << vertex_count << " vertices and "
+                        << index_count << " indices" << LL_ENDL;
+                    group->mVertexBuffer = NULL;
+                    group->mBufferMap.clear();
+                }
+            }
+        }
+
+        if (group->mVertexBuffer)
+        {
+            getGeometry(group);
+        }
+    }
+    else
+    {
+        group->mVertexBuffer = NULL;
+        group->mBufferMap.clear();
+    }
+
+    group->mLastUpdateTime = gFrameTimeSeconds;
+    group->clearState(LLSpatialGroup::GEOM_DIRTY);
 }
 
 
@@ -404,198 +404,198 @@ void LLSpatialPartition::rebuildMesh(LLSpatialGroup* group)
 
 LLSpatialGroup* LLSpatialGroup::getParent()
 {
-	return (LLSpatialGroup*)LLViewerOctreeGroup::getParent();
-	}
+    return (LLSpatialGroup*)LLViewerOctreeGroup::getParent();
+    }
 
 BOOL LLSpatialGroup::removeObject(LLDrawable *drawablep, BOOL from_octree)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
-
-	if(!drawablep)
-	{
-		return FALSE;
-	}
-
-	unbound();
-	if (mOctreeNode && !from_octree)
-	{
-		drawablep->setGroup(NULL);
-	}
-	else
-	{
-		drawablep->setGroup(NULL);
-		setState(GEOM_DIRTY);
-		gPipeline.markRebuild(this);
-
-		if (drawablep->isSpatialBridge())
-		{
-			for (bridge_list_t::iterator i = mBridgeList.begin(); i != mBridgeList.end(); ++i)
-			{
-				if (*i == drawablep)
-				{
-					mBridgeList.erase(i);
-					break;
-				}
-			}
-		}
-
-		if (getElementCount() == 0)
-		{ //delete draw map on last element removal since a rebuild might never happen
-			clearDrawMap();
-		}
-	}
-	return TRUE;
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
+
+    if(!drawablep)
+    {
+        return FALSE;
+    }
+
+    unbound();
+    if (mOctreeNode && !from_octree)
+    {
+        drawablep->setGroup(NULL);
+    }
+    else
+    {
+        drawablep->setGroup(NULL);
+        setState(GEOM_DIRTY);
+        gPipeline.markRebuild(this);
+
+        if (drawablep->isSpatialBridge())
+        {
+            for (bridge_list_t::iterator i = mBridgeList.begin(); i != mBridgeList.end(); ++i)
+            {
+                if (*i == drawablep)
+                {
+                    mBridgeList.erase(i);
+                    break;
+                }
+            }
+        }
+
+        if (getElementCount() == 0)
+        { //delete draw map on last element removal since a rebuild might never happen
+            clearDrawMap();
+        }
+    }
+    return TRUE;
 }
 
 void LLSpatialGroup::shift(const LLVector4a &offset)
 {
-	LLVector4a t = mOctreeNode->getCenter();
-	t.add(offset);	
-	mOctreeNode->setCenter(t);
-	mOctreeNode->updateMinMax();
-	mBounds[0].add(offset);
-	mExtents[0].add(offset);
-	mExtents[1].add(offset);
-	mObjectBounds[0].add(offset);
-	mObjectExtents[0].add(offset);
-	mObjectExtents[1].add(offset);
-
-	if (!getSpatialPartition()->mRenderByGroup && 
-		getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_TREE &&
-		getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_TERRAIN &&
-		getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_BRIDGE &&
-		getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_AVATAR &&
-		getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_CONTROL_AV)
-	{
-		setState(GEOM_DIRTY);
-		gPipeline.markRebuild(this);
-	}
+    LLVector4a t = mOctreeNode->getCenter();
+    t.add(offset);
+    mOctreeNode->setCenter(t);
+    mOctreeNode->updateMinMax();
+    mBounds[0].add(offset);
+    mExtents[0].add(offset);
+    mExtents[1].add(offset);
+    mObjectBounds[0].add(offset);
+    mObjectExtents[0].add(offset);
+    mObjectExtents[1].add(offset);
+
+    if (!getSpatialPartition()->mRenderByGroup &&
+        getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_TREE &&
+        getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_TERRAIN &&
+        getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_BRIDGE &&
+        getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_AVATAR &&
+        getSpatialPartition()->mPartitionType != LLViewerRegion::PARTITION_CONTROL_AV)
+    {
+        setState(GEOM_DIRTY);
+        gPipeline.markRebuild(this);
+    }
 }
 
 class LLSpatialSetState : public OctreeTraveler
 {
 public:
-	U32 mState;
-	LLSpatialSetState(U32 state) : mState(state) { }
-	virtual void visit(const OctreeNode* branch) { ((LLSpatialGroup*) branch->getListener(0))->setState(mState); }	
+    U32 mState;
+    LLSpatialSetState(U32 state) : mState(state) { }
+    virtual void visit(const OctreeNode* branch) { ((LLSpatialGroup*) branch->getListener(0))->setState(mState); }
 };
 
 class LLSpatialSetStateDiff : public LLSpatialSetState
 {
 public:
-	LLSpatialSetStateDiff(U32 state) : LLSpatialSetState(state) { }
-
-	virtual void traverse(const OctreeNode* n)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) n->getListener(0);
-		
-		if (!group->hasState(mState))
-		{
-			OctreeTraveler::traverse(n);
-		}
-	}
+    LLSpatialSetStateDiff(U32 state) : LLSpatialSetState(state) { }
+
+    virtual void traverse(const OctreeNode* n)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) n->getListener(0);
+
+        if (!group->hasState(mState))
+        {
+            OctreeTraveler::traverse(n);
+        }
+    }
 };
 
-void LLSpatialGroup::setState(U32 state, S32 mode) 
-{
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
-
-	llassert(state <= LLSpatialGroup::STATE_MASK);
-	
-	if (mode > STATE_MODE_SINGLE)
-	{
-		if (mode == STATE_MODE_DIFF)
-		{
-			LLSpatialSetStateDiff setter(state);
-			setter.traverse(mOctreeNode);
-		}
-		else
-		{
-			LLSpatialSetState setter(state);
-			setter.traverse(mOctreeNode);
-		}
-	}
-	else
-	{
-		mState |= state;
-	}
+void LLSpatialGroup::setState(U32 state, S32 mode)
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
+
+    llassert(state <= LLSpatialGroup::STATE_MASK);
+
+    if (mode > STATE_MODE_SINGLE)
+    {
+        if (mode == STATE_MODE_DIFF)
+        {
+            LLSpatialSetStateDiff setter(state);
+            setter.traverse(mOctreeNode);
+        }
+        else
+        {
+            LLSpatialSetState setter(state);
+            setter.traverse(mOctreeNode);
+        }
+    }
+    else
+    {
+        mState |= state;
+    }
 }
 
 class LLSpatialClearState : public OctreeTraveler
 {
 public:
-	U32 mState;
-	LLSpatialClearState(U32 state) : mState(state) { }
-	virtual void visit(const OctreeNode* branch) { ((LLSpatialGroup*) branch->getListener(0))->clearState(mState); }
+    U32 mState;
+    LLSpatialClearState(U32 state) : mState(state) { }
+    virtual void visit(const OctreeNode* branch) { ((LLSpatialGroup*) branch->getListener(0))->clearState(mState); }
 };
 
 class LLSpatialClearStateDiff : public LLSpatialClearState
 {
 public:
-	LLSpatialClearStateDiff(U32 state) : LLSpatialClearState(state) { }
-
-	virtual void traverse(const OctreeNode* n)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) n->getListener(0);
-		
-		if (group->hasState(mState))
-		{
-			OctreeTraveler::traverse(n);
-		}
-	}
+    LLSpatialClearStateDiff(U32 state) : LLSpatialClearState(state) { }
+
+    virtual void traverse(const OctreeNode* n)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) n->getListener(0);
+
+        if (group->hasState(mState))
+        {
+            OctreeTraveler::traverse(n);
+        }
+    }
 };
 
 void LLSpatialGroup::clearState(U32 state, S32 mode)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
-
-	llassert(state <= LLSpatialGroup::STATE_MASK);
-
-	if (mode > STATE_MODE_SINGLE)
-	{
-		if (mode == STATE_MODE_DIFF)
-		{
-			LLSpatialClearStateDiff clearer(state);
-			clearer.traverse(mOctreeNode);
-		}
-		else
-		{
-			LLSpatialClearState clearer(state);
-			clearer.traverse(mOctreeNode);
-		}
-	}
-	else
-	{
-		mState &= ~state;
-	}
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
+
+    llassert(state <= LLSpatialGroup::STATE_MASK);
+
+    if (mode > STATE_MODE_SINGLE)
+    {
+        if (mode == STATE_MODE_DIFF)
+        {
+            LLSpatialClearStateDiff clearer(state);
+            clearer.traverse(mOctreeNode);
+        }
+        else
+        {
+            LLSpatialClearState clearer(state);
+            clearer.traverse(mOctreeNode);
+        }
+    }
+    else
+    {
+        mState &= ~state;
+    }
 }
 
 //======================================
-//		Octree Listener Implementation
+//      Octree Listener Implementation
 //======================================
 
 LLSpatialGroup::LLSpatialGroup(OctreeNode* node, LLSpatialPartition* part) : LLOcclusionCullingGroup(node, part),
-	mObjectBoxSize(1.f),
-	mGeometryBytes(0),
-	mSurfaceArea(0.f),
-	mBuilt(0.f),
-	mVertexBuffer(NULL), 
-	mDistance(0.f),
-	mDepth(0.f),
-	mLastUpdateDistance(-1.f), 
-	mLastUpdateTime(gFrameTimeSeconds)
-{
-	ll_assert_aligned(this,16);
-	
-	sNodeCount++;
-
-	mViewAngle.splat(0.f);
-	mLastUpdateViewAngle.splat(-1.f);
-
-	sg_assert(mOctreeNode->getListenerCount() == 0);
-	setState(SG_INITIAL_STATE_MASK);
-	gPipeline.markRebuild(this);
-    
+    mObjectBoxSize(1.f),
+    mGeometryBytes(0),
+    mSurfaceArea(0.f),
+    mBuilt(0.f),
+    mVertexBuffer(NULL),
+    mDistance(0.f),
+    mDepth(0.f),
+    mLastUpdateDistance(-1.f),
+    mLastUpdateTime(gFrameTimeSeconds)
+{
+    ll_assert_aligned(this,16);
+
+    sNodeCount++;
+
+    mViewAngle.splat(0.f);
+    mLastUpdateViewAngle.splat(-1.f);
+
+    sg_assert(mOctreeNode->getListenerCount() == 0);
+    setState(SG_INITIAL_STATE_MASK);
+    gPipeline.markRebuild(this);
+
     // let the reflection map manager know about this spatial group
     mReflectionProbe = gPipeline.mReflectionMapManager.registerSpatialGroup(this);
 
@@ -605,141 +605,141 @@ LLSpatialGroup::LLSpatialGroup(OctreeNode* node, LLSpatialPartition* part) : LLO
 
 void LLSpatialGroup::updateDistance(LLCamera &camera)
 {
-	if (LLViewerCamera::sCurCameraID != LLViewerCamera::CAMERA_WORLD)
-	{
-		LL_WARNS() << "Attempted to update distance for camera other than world camera!" << LL_ENDL;
+    if (LLViewerCamera::sCurCameraID != LLViewerCamera::CAMERA_WORLD)
+    {
+        LL_WARNS() << "Attempted to update distance for camera other than world camera!" << LL_ENDL;
         llassert(false);
-		return;
-	}
+        return;
+    }
 
-	if (gShiftFrame)
-	{
-		return;
-	}
+    if (gShiftFrame)
+    {
+        return;
+    }
 
 #if !LL_RELEASE_FOR_DOWNLOAD
-	if (hasState(LLSpatialGroup::OBJECT_DIRTY))
-	{
-		LL_ERRS() << "Spatial group dirty on distance update." << LL_ENDL;
-	}
+    if (hasState(LLSpatialGroup::OBJECT_DIRTY))
+    {
+        LL_ERRS() << "Spatial group dirty on distance update." << LL_ENDL;
+    }
 #endif
-	if (!isEmpty())
-	{
-		mRadius = getSpatialPartition()->mRenderByGroup ? mObjectBounds[1].getLength3().getF32() :
-						(F32) mOctreeNode->getSize().getLength3().getF32();
-		mDistance = getSpatialPartition()->calcDistance(this, camera);
-		mPixelArea = getSpatialPartition()->calcPixelArea(this, camera);
-	}
+    if (!isEmpty())
+    {
+        mRadius = getSpatialPartition()->mRenderByGroup ? mObjectBounds[1].getLength3().getF32() :
+                        (F32) mOctreeNode->getSize().getLength3().getF32();
+        mDistance = getSpatialPartition()->calcDistance(this, camera);
+        mPixelArea = getSpatialPartition()->calcPixelArea(this, camera);
+    }
 }
 
 F32 LLSpatialPartition::calcDistance(LLSpatialGroup* group, LLCamera& camera)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
-
-	LLVector4a eye;
-	LLVector4a origin;
-	origin.load3(camera.getOrigin().mV);
-
-	eye.setSub(group->mObjectBounds[0], origin);
-
-	F32 dist = 0.f;
-
-	if (group->mDrawMap.find(LLRenderPass::PASS_ALPHA) != group->mDrawMap.end())
-	{
-		LLVector4a v = eye;
-
-		dist = eye.getLength3().getF32();
-		eye.normalize3fast();
-
-		if (!group->hasState(LLSpatialGroup::ALPHA_DIRTY))
-		{
-			if (!group->getSpatialPartition()->isBridge())
-			{
-				LLVector4a view_angle = eye;
-
-				LLVector4a diff;
-				diff.setSub(view_angle, group->mLastUpdateViewAngle);
-
-				if (diff.getLength3().getF32() > 0.64f)
-				{
-					group->mViewAngle = view_angle;
-					group->mLastUpdateViewAngle = view_angle;
-					//for occasional alpha sorting within the group
-					//NOTE: If there is a trivial way to detect that alpha sorting here would not change the render order,
-					//not setting this node to dirty would be a very good thing
-					group->setState(LLSpatialGroup::ALPHA_DIRTY);
-					gPipeline.markRebuild(group);
-				}
-			}
-		}
-
-		//calculate depth of node for alpha sorting
-
-		LLVector3 at = camera.getAtAxis();
-
-		LLVector4a ata;
-		ata.load3(at.mV);
-
-		LLVector4a t = ata;
-		//front of bounding box
-		t.mul(0.25f);
-		t.mul(group->mObjectBounds[1]);
-		v.sub(t);
-		
-		group->mDepth = v.dot3(ata).getF32();
-	}
-	else
-	{
-		dist = eye.getLength3().getF32();
-	}
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
+
+    LLVector4a eye;
+    LLVector4a origin;
+    origin.load3(camera.getOrigin().mV);
+
+    eye.setSub(group->mObjectBounds[0], origin);
+
+    F32 dist = 0.f;
+
+    if (group->mDrawMap.find(LLRenderPass::PASS_ALPHA) != group->mDrawMap.end())
+    {
+        LLVector4a v = eye;
+
+        dist = eye.getLength3().getF32();
+        eye.normalize3fast();
+
+        if (!group->hasState(LLSpatialGroup::ALPHA_DIRTY))
+        {
+            if (!group->getSpatialPartition()->isBridge())
+            {
+                LLVector4a view_angle = eye;
+
+                LLVector4a diff;
+                diff.setSub(view_angle, group->mLastUpdateViewAngle);
+
+                if (diff.getLength3().getF32() > 0.64f)
+                {
+                    group->mViewAngle = view_angle;
+                    group->mLastUpdateViewAngle = view_angle;
+                    //for occasional alpha sorting within the group
+                    //NOTE: If there is a trivial way to detect that alpha sorting here would not change the render order,
+                    //not setting this node to dirty would be a very good thing
+                    group->setState(LLSpatialGroup::ALPHA_DIRTY);
+                    gPipeline.markRebuild(group);
+                }
+            }
+        }
+
+        //calculate depth of node for alpha sorting
+
+        LLVector3 at = camera.getAtAxis();
+
+        LLVector4a ata;
+        ata.load3(at.mV);
+
+        LLVector4a t = ata;
+        //front of bounding box
+        t.mul(0.25f);
+        t.mul(group->mObjectBounds[1]);
+        v.sub(t);
+
+        group->mDepth = v.dot3(ata).getF32();
+    }
+    else
+    {
+        dist = eye.getLength3().getF32();
+    }
 
 #ifdef SHOW_DEBUG
-    LL_DEBUGS("RiggedBox") << "calcDistance, group " << group << " camera " << origin << " obj bounds " 
-                           << group->mObjectBounds[0] << ", " << group->mObjectBounds[1] 
+    LL_DEBUGS("RiggedBox") << "calcDistance, group " << group << " camera " << origin << " obj bounds "
+                           << group->mObjectBounds[0] << ", " << group->mObjectBounds[1]
                            << " dist " << dist << " radius " << group->mRadius << LL_ENDL;
 #endif
 
-	if (dist < 16.f)
-	{
-		dist /= 16.f;
-		dist *= dist;
-		dist *= 16.f;
-	}
+    if (dist < 16.f)
+    {
+        dist /= 16.f;
+        dist *= dist;
+        dist *= 16.f;
+    }
 
-	return dist;
+    return dist;
 }
 
 F32 LLSpatialPartition::calcPixelArea(LLSpatialGroup* group, LLCamera& camera)
 {
-	return LLPipeline::calcPixelArea(group->mObjectBounds[0], group->mObjectBounds[1], camera);
+    return LLPipeline::calcPixelArea(group->mObjectBounds[0], group->mObjectBounds[1], camera);
 }
 
 F32 LLSpatialGroup::getUpdateUrgency() const
 {
-	if (!isVisible())
-	{
-		return 0.f;
-	}
-	else
-	{
-		F32 time = gFrameTimeSeconds-mLastUpdateTime+4.f;
-		return time + (mObjectBounds[1].dot3(mObjectBounds[1]).getF32()+1.f)/mDistance;
-	}
+    if (!isVisible())
+    {
+        return 0.f;
+    }
+    else
+    {
+        F32 time = gFrameTimeSeconds-mLastUpdateTime+4.f;
+        return time + (mObjectBounds[1].dot3(mObjectBounds[1]).getF32()+1.f)/mDistance;
+    }
 }
 
 BOOL LLSpatialGroup::changeLOD()
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
 
-	if (hasState(ALPHA_DIRTY | OBJECT_DIRTY))
-	{
-		//a rebuild is going to happen, update distance and LoD
-		return TRUE;
-	}
+    if (hasState(ALPHA_DIRTY | OBJECT_DIRTY))
+    {
+        //a rebuild is going to happen, update distance and LoD
+        return TRUE;
+    }
 
-	if (getSpatialPartition()->mSlopRatio > 0.f)
-	{
-		F32 ratio = (mDistance - mLastUpdateDistance)/(llmax(mLastUpdateDistance, mRadius));
+    if (getSpatialPartition()->mSlopRatio > 0.f)
+    {
+        F32 ratio = (mDistance - mLastUpdateDistance)/(llmax(mLastUpdateDistance, mRadius));
 
         // MAINT-8264 - this check is not robust if it needs to work
         // for bounding boxes much larger than the actual enclosed
@@ -753,87 +753,87 @@ BOOL LLSpatialGroup::changeLOD()
         // was large only due to another error, so this logic did not
         // need to be changed.
 
-		if (fabsf(ratio) >= getSpatialPartition()->mSlopRatio)
-		{
+        if (fabsf(ratio) >= getSpatialPartition()->mSlopRatio)
+        {
 #ifdef SHOW_DEBUG
             LL_DEBUGS("RiggedBox") << "changeLOD true because of ratio compare "
                                    << fabsf(ratio) << " " << getSpatialPartition()->mSlopRatio << LL_ENDL;
             LL_DEBUGS("RiggedBox") << "sg " << this << "\nmDistance " << mDistance
                                    << " mLastUpdateDistance " << mLastUpdateDistance
                                    << " mRadius " << mRadius
-                                   << " fab ratio " << fabsf(ratio) 
+                                   << " fab ratio " << fabsf(ratio)
                                    << " slop " << getSpatialPartition()->mSlopRatio << LL_ENDL;
 #endif
-       
-			return TRUE;
-		}
-	}
-	
-	if (needsUpdate())
-	{
-		return TRUE;
-	}
-	
-	return FALSE;
+
+            return TRUE;
+        }
+    }
+
+    if (needsUpdate())
+    {
+        return TRUE;
+    }
+
+    return FALSE;
 }
 
 void LLSpatialGroup::handleInsertion(const TreeNode* node, LLViewerOctreeEntry* entry)
 {
-	addObject((LLDrawable*)entry->getDrawable());
-	unbound();
-	setState(OBJECT_DIRTY);
+    addObject((LLDrawable*)entry->getDrawable());
+    unbound();
+    setState(OBJECT_DIRTY);
 }
 
 void LLSpatialGroup::handleRemoval(const TreeNode* node, LLViewerOctreeEntry* entry)
 {
-	removeObject((LLDrawable*)entry->getDrawable(), TRUE);
-	LLViewerOctreeGroup::handleRemoval(node, entry);
+    removeObject((LLDrawable*)entry->getDrawable(), TRUE);
+    LLViewerOctreeGroup::handleRemoval(node, entry);
 }
 
 void LLSpatialGroup::handleDestruction(const TreeNode* node)
 {
-	if(isDead())
-	{
-		return;
-	}
-	setState(DEAD);	
-
-	for (element_iter i = getDataBegin(), i_end = getDataEnd(); i != i_end; ++i)
-	{
-		LLViewerOctreeEntry* entry = *i;
-
-		if (entry->getGroup() == this)
-		{
-			if(entry->hasDrawable())
-			{
-				((LLDrawable*)entry->getDrawable())->setGroup(NULL);
-			}
-		}
-	}
-	
-	clearDrawMap();
-	mVertexBuffer = NULL;
-	mBufferMap.clear();
-	sZombieGroups++;
-	mOctreeNode = NULL;
+    if(isDead())
+    {
+        return;
+    }
+    setState(DEAD);
+
+    for (element_iter i = getDataBegin(), i_end = getDataEnd(); i != i_end; ++i)
+    {
+        LLViewerOctreeEntry* entry = *i;
+
+        if (entry->getGroup() == this)
+        {
+            if(entry->hasDrawable())
+            {
+                ((LLDrawable*)entry->getDrawable())->setGroup(NULL);
+            }
+        }
+    }
+
+    clearDrawMap();
+    mVertexBuffer = NULL;
+    mBufferMap.clear();
+    sZombieGroups++;
+    mOctreeNode = NULL;
 }
 
-void LLSpatialGroup::handleChildAddition(const OctreeNode* parent, OctreeNode* child) 
+void LLSpatialGroup::handleChildAddition(const OctreeNode* parent, OctreeNode* child)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL
 
-	if (child->getListenerCount() == 0)
-	{
-		new LLSpatialGroup(child, getSpatialPartition());
-	}
-	else
-	{
-		OCT_ERRS << "LLSpatialGroup redundancy detected." << LL_ENDL;
-	}
+    if (child->getListenerCount() == 0)
+    {
+        new LLSpatialGroup(child, getSpatialPartition());
+    }
+    else
+    {
+        OCT_ERRS << "LLSpatialGroup redundancy detected." << LL_ENDL;
+    }
 
-	unbound();
+    unbound();
 
-	assert_states_valid(this);
+    assert_states_valid(this);
 }
 
 //virtual
@@ -874,41 +874,41 @@ void LLSpatialGroup::rebound()
 
 void LLSpatialGroup::destroyGLState(bool keep_occlusion)
 {
-	setState(LLSpatialGroup::GEOM_DIRTY | LLSpatialGroup::IMAGE_DIRTY);
-
-	if (!keep_occlusion)
-	{ //going to need a rebuild
-		gPipeline.markRebuild(this);
-	}
-
-	mLastUpdateTime = gFrameTimeSeconds;
-	mVertexBuffer = NULL;
-	mBufferMap.clear();
-
-	clearDrawMap();
-
-	if (!keep_occlusion)
-	{
-		releaseOcclusionQueryObjectNames();
-	}
-
-
-	for (LLSpatialGroup::element_iter i = getDataBegin(), i_end = getDataEnd(); i != i_end; ++i)
-	{
-		LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
-		if(!drawable)
-		{
-			continue;
-		}
-		for (S32 j = 0, j_end = drawable->getNumFaces(); j < j_end; ++j)
-		{
-			LLFace* facep = drawable->getFace(j);
-			if (facep)
-			{
-				facep->clearVertexBuffer();
-			}
-		}
-	}
+    setState(LLSpatialGroup::GEOM_DIRTY | LLSpatialGroup::IMAGE_DIRTY);
+
+    if (!keep_occlusion)
+    { //going to need a rebuild
+        gPipeline.markRebuild(this);
+    }
+
+    mLastUpdateTime = gFrameTimeSeconds;
+    mVertexBuffer = NULL;
+    mBufferMap.clear();
+
+    clearDrawMap();
+
+    if (!keep_occlusion)
+    {
+        releaseOcclusionQueryObjectNames();
+    }
+
+
+    for (LLSpatialGroup::element_iter i = getDataBegin(), i_end = getDataEnd(); i != i_end; ++i)
+    {
+        LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
+        if(!drawable)
+        {
+            continue;
+        }
+        for (S32 j = 0, j_end = drawable->getNumFaces(); j < j_end; ++j)
+        {
+            LLFace* facep = drawable->getFace(j);
+            if (facep)
+            {
+                facep->clearVertexBuffer();
+            }
+        }
+    }
 }
 
 //==============================================
@@ -916,14 +916,14 @@ void LLSpatialGroup::destroyGLState(bool keep_occlusion)
 LLSpatialPartition::LLSpatialPartition(U32 data_mask, BOOL render_by_group, LLViewerRegion* regionp)
 : mRenderByGroup(render_by_group), mBridge(NULL)
 {
-	mRegionp = regionp;		
-	mPartitionType = LLViewerRegion::PARTITION_NONE;
-	mVertexDataMask = data_mask;
-	mDepthMask = FALSE;
-	mSlopRatio = 0.25f;
-	mInfiniteFarClip = FALSE;
+    mRegionp = regionp;
+    mPartitionType = LLViewerRegion::PARTITION_NONE;
+    mVertexDataMask = data_mask;
+    mDepthMask = FALSE;
+    mSlopRatio = 0.25f;
+    mInfiniteFarClip = FALSE;
 
-	new LLSpatialGroup(mOctree, this);
+    new LLSpatialGroup(mOctree, this);
 }
 
 
@@ -935,391 +935,391 @@ LLSpatialPartition::~LLSpatialPartition()
 LLSpatialGroup *LLSpatialPartition::put(LLDrawable *drawablep, BOOL was_visible)
 {
     LL_PROFILE_ZONE_SCOPED;
-	drawablep->updateSpatialExtents();
-
-	//keep drawable from being garbage collected
-	LLPointer<LLDrawable> ptr = drawablep;
-		
-	if(!drawablep->getGroup())
-	{
-	assert_octree_valid(mOctree);
-		mOctree->insert(drawablep->getEntry());
-	assert_octree_valid(mOctree);
-	}	
-	
-	LLSpatialGroup* group = drawablep->getSpatialGroup();
-	//llassert(group != NULL);
-
-	if (group && was_visible && group->isOcclusionState(LLSpatialGroup::QUERY_PENDING))
-	{
-		group->setOcclusionState(LLSpatialGroup::DISCARD_QUERY, LLSpatialGroup::STATE_MODE_ALL_CAMERAS);
-	}
-
-	return group;
+    drawablep->updateSpatialExtents();
+
+    //keep drawable from being garbage collected
+    LLPointer<LLDrawable> ptr = drawablep;
+
+    if(!drawablep->getGroup())
+    {
+    assert_octree_valid(mOctree);
+        mOctree->insert(drawablep->getEntry());
+    assert_octree_valid(mOctree);
+    }
+
+    LLSpatialGroup* group = drawablep->getSpatialGroup();
+    //llassert(group != NULL);
+
+    if (group && was_visible && group->isOcclusionState(LLSpatialGroup::QUERY_PENDING))
+    {
+        group->setOcclusionState(LLSpatialGroup::DISCARD_QUERY, LLSpatialGroup::STATE_MODE_ALL_CAMERAS);
+    }
+
+    return group;
 }
 
 BOOL LLSpatialPartition::remove(LLDrawable *drawablep, LLSpatialGroup *curp)
 {
     LL_PROFILE_ZONE_SCOPED;
-	if (!curp->removeObject(drawablep))
-	{
-		OCT_ERRS << "Failed to remove drawable from octree!" << LL_ENDL;
-	}
-	else
-	{
-		drawablep->setGroup(NULL);
-	}
-
-	assert_octree_valid(mOctree);
-	
-	return TRUE;
-}
+    if (!curp->removeObject(drawablep))
+    {
+        OCT_ERRS << "Failed to remove drawable from octree!" << LL_ENDL;
+    }
+    else
+    {
+        drawablep->setGroup(NULL);
+    }
+
+    assert_octree_valid(mOctree);
+
+    return TRUE;
+}
 
 void LLSpatialPartition::move(LLDrawable *drawablep, LLSpatialGroup *curp, BOOL immediate)
 {
     LL_PROFILE_ZONE_SCOPED;
-	// sanity check submitted by open source user bushing Spatula
-	// who was seeing crashing here. (See VWR-424 reported by Bunny Mayne)
-	if (!drawablep)
-	{
-		OCT_ERRS << "LLSpatialPartition::move was passed a bad drawable." << LL_ENDL;
-		return;
-	}
-		
-	BOOL was_visible = curp ? curp->isVisible() : FALSE;
-
-	if (curp && curp->getSpatialPartition() != this)
-	{
-		//keep drawable from being garbage collected
-		LLPointer<LLDrawable> ptr = drawablep;
-		if (curp->getSpatialPartition()->remove(drawablep, curp))
-		{
-			put(drawablep, was_visible);
-			return;
-		}
-		else
-		{
-			OCT_ERRS << "Drawable lost between spatial partitions on outbound transition." << LL_ENDL;
-		}
-	}
-		
-	if (curp && curp->updateInGroup(drawablep, immediate))
-	{
-		// Already updated, don't need to do anything
-		assert_octree_valid(mOctree);
-		return;
-	}
-
-	//keep drawable from being garbage collected
-	LLPointer<LLDrawable> ptr = drawablep;
-	if (curp && !remove(drawablep, curp))
-	{
-		OCT_ERRS << "Move couldn't find existing spatial group!" << LL_ENDL;
-	}
-
-	put(drawablep, was_visible);
+    // sanity check submitted by open source user bushing Spatula
+    // who was seeing crashing here. (See VWR-424 reported by Bunny Mayne)
+    if (!drawablep)
+    {
+        OCT_ERRS << "LLSpatialPartition::move was passed a bad drawable." << LL_ENDL;
+        return;
+    }
+
+    BOOL was_visible = curp ? curp->isVisible() : FALSE;
+
+    if (curp && curp->getSpatialPartition() != this)
+    {
+        //keep drawable from being garbage collected
+        LLPointer<LLDrawable> ptr = drawablep;
+        if (curp->getSpatialPartition()->remove(drawablep, curp))
+        {
+            put(drawablep, was_visible);
+            return;
+        }
+        else
+        {
+            OCT_ERRS << "Drawable lost between spatial partitions on outbound transition." << LL_ENDL;
+        }
+    }
+
+    if (curp && curp->updateInGroup(drawablep, immediate))
+    {
+        // Already updated, don't need to do anything
+        assert_octree_valid(mOctree);
+        return;
+    }
+
+    //keep drawable from being garbage collected
+    LLPointer<LLDrawable> ptr = drawablep;
+    if (curp && !remove(drawablep, curp))
+    {
+        OCT_ERRS << "Move couldn't find existing spatial group!" << LL_ENDL;
+    }
+
+    put(drawablep, was_visible);
 }
 
 class LLSpatialShift : public OctreeTraveler
 {
 public:
-	const LLVector4a& mOffset;
+    const LLVector4a& mOffset;
 
-	LLSpatialShift(const LLVector4a& offset) : mOffset(offset) { }
-	virtual void visit(const OctreeNode* branch) 
-	{ 
-		((LLSpatialGroup*) branch->getListener(0))->shift(mOffset); 
-	}
+    LLSpatialShift(const LLVector4a& offset) : mOffset(offset) { }
+    virtual void visit(const OctreeNode* branch)
+    {
+        ((LLSpatialGroup*) branch->getListener(0))->shift(mOffset);
+    }
 };
 
 void LLSpatialPartition::shift(const LLVector4a &offset)
 { //shift octree node bounding boxes by offset
-	LLSpatialShift shifter(offset);
-	shifter.traverse(mOctree);
+    LLSpatialShift shifter(offset);
+    shifter.traverse(mOctree);
 }
 
 class LLOctreeCull : public LLViewerOctreeCull
 {
 public:
-	LLOctreeCull(LLCamera* camera) : LLViewerOctreeCull(camera) {}
+    LLOctreeCull(LLCamera* camera) : LLViewerOctreeCull(camera) {}
 
-	virtual bool earlyFail(LLViewerOctreeGroup* base_group)
-	{
+    virtual bool earlyFail(LLViewerOctreeGroup* base_group)
+    {
         if (LLPipeline::sReflectionRender)
         {
             return false;
         }
 
-		LLSpatialGroup* group = (LLSpatialGroup*)base_group;
-		group->checkOcclusion();
-
-		if (group->getOctreeNode()->getParent() &&	//never occlusion cull the root node
-		  	LLPipeline::sUseOcclusion &&			//ignore occlusion if disabled
-			group->isOcclusionState(LLSpatialGroup::OCCLUDED))
-		{
-			gPipeline.markOccluder(group);
-			return true;
-		}
-		
-		return false;
-	}
-	
-	virtual S32 frustumCheck(const LLViewerOctreeGroup* group)
-	{
-		S32 res = AABBInFrustumNoFarClipGroupBounds(group);
-		if (res != 0)
-		{
-			res = llmin(res, AABBSphereIntersectGroupExtents(group));
-		}
-		return res;
-	}
-
-	virtual S32 frustumCheckObjects(const LLViewerOctreeGroup* group)
-	{
-		S32 res = AABBInFrustumNoFarClipObjectBounds(group);
-		if (res != 0)
-		{
-			res = llmin(res, AABBSphereIntersectObjectExtents(group));
-		}
-		return res;
-	}
-
-	virtual void processGroup(LLViewerOctreeGroup* base_group)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*)base_group;
-		/*if (group->needsUpdate() ||
-			group->getVisible(LLViewerCamera::sCurCameraID) < LLDrawable::getCurrentFrame() - 1)
-		{
-			group->doOcclusion(mCamera);
-		}*/
-		gPipeline.markNotCulled(group, *mCamera);
-	}
+        LLSpatialGroup* group = (LLSpatialGroup*)base_group;
+        group->checkOcclusion();
+
+        if (group->getOctreeNode()->getParent() &&  //never occlusion cull the root node
+            LLPipeline::sUseOcclusion &&            //ignore occlusion if disabled
+            group->isOcclusionState(LLSpatialGroup::OCCLUDED))
+        {
+            gPipeline.markOccluder(group);
+            return true;
+        }
+
+        return false;
+    }
+
+    virtual S32 frustumCheck(const LLViewerOctreeGroup* group)
+    {
+        S32 res = AABBInFrustumNoFarClipGroupBounds(group);
+        if (res != 0)
+        {
+            res = llmin(res, AABBSphereIntersectGroupExtents(group));
+        }
+        return res;
+    }
+
+    virtual S32 frustumCheckObjects(const LLViewerOctreeGroup* group)
+    {
+        S32 res = AABBInFrustumNoFarClipObjectBounds(group);
+        if (res != 0)
+        {
+            res = llmin(res, AABBSphereIntersectObjectExtents(group));
+        }
+        return res;
+    }
+
+    virtual void processGroup(LLViewerOctreeGroup* base_group)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*)base_group;
+        /*if (group->needsUpdate() ||
+            group->getVisible(LLViewerCamera::sCurCameraID) < LLDrawable::getCurrentFrame() - 1)
+        {
+            group->doOcclusion(mCamera);
+        }*/
+        gPipeline.markNotCulled(group, *mCamera);
+    }
 };
 
 class LLOctreeCullNoFarClip : public LLOctreeCull
 {
-public: 
-	LLOctreeCullNoFarClip(LLCamera* camera) 
-		: LLOctreeCull(camera) { }
+public:
+    LLOctreeCullNoFarClip(LLCamera* camera)
+        : LLOctreeCull(camera) { }
 
-	virtual S32 frustumCheck(const LLViewerOctreeGroup* group)
-	{
-		return AABBInFrustumNoFarClipGroupBounds(group);
-	}
+    virtual S32 frustumCheck(const LLViewerOctreeGroup* group)
+    {
+        return AABBInFrustumNoFarClipGroupBounds(group);
+    }
 
-	virtual S32 frustumCheckObjects(const LLViewerOctreeGroup* group)
-	{
-		S32 res = AABBInFrustumNoFarClipObjectBounds(group);
-		return res;
-	}
+    virtual S32 frustumCheckObjects(const LLViewerOctreeGroup* group)
+    {
+        S32 res = AABBInFrustumNoFarClipObjectBounds(group);
+        return res;
+    }
 };
 
 class LLOctreeCullShadow : public LLOctreeCull
 {
 public:
-	LLOctreeCullShadow(LLCamera* camera)
-		: LLOctreeCull(camera) { }
-
-	virtual S32 frustumCheck(const LLViewerOctreeGroup* group)
-	{
-		return AABBInFrustumGroupBounds(group);
-	}
-
-	virtual S32 frustumCheckObjects(const LLViewerOctreeGroup* group)
-	{
-		return AABBInFrustumObjectBounds(group);
-	}
+    LLOctreeCullShadow(LLCamera* camera)
+        : LLOctreeCull(camera) { }
+
+    virtual S32 frustumCheck(const LLViewerOctreeGroup* group)
+    {
+        return AABBInFrustumGroupBounds(group);
+    }
+
+    virtual S32 frustumCheckObjects(const LLViewerOctreeGroup* group)
+    {
+        return AABBInFrustumObjectBounds(group);
+    }
 };
 
 class LLOctreeCullVisExtents: public LLOctreeCullShadow
 {
 public:
-	LLOctreeCullVisExtents(LLCamera* camera, LLVector4a& min, LLVector4a& max)
-		: LLOctreeCullShadow(camera), mMin(min), mMax(max), mEmpty(TRUE) { }
-
-	virtual bool earlyFail(LLViewerOctreeGroup* base_group)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*)base_group;
-
-		if (group->getOctreeNode()->getParent() &&	//never occlusion cull the root node
-			LLPipeline::sUseOcclusion &&			//ignore occlusion if disabled
-			group->isOcclusionState(LLSpatialGroup::OCCLUDED))
-		{
-			return true;
-		}
-		
-		return false;
-	}
-
-	virtual void traverse(const OctreeNode* n)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) n->getListener(0);
-
-		if (earlyFail(group))
-		{
-			return;
-		}
-		
-		if ((mRes && group->hasState(LLSpatialGroup::SKIP_FRUSTUM_CHECK)) ||
-			mRes == 2)
-		{	//don't need to do frustum check
-			OctreeTraveler::traverse(n);
-		}
-		else
-		{  
-			mRes = frustumCheck(group);
-				
-			if (mRes)
-			{ //at least partially in, run on down
-				OctreeTraveler::traverse(n);
-			}
-
-			mRes = 0;
-		}
-	}
-
-	virtual void processGroup(LLViewerOctreeGroup* base_group)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*)base_group;
-		
-		llassert(!group->hasState(LLSpatialGroup::DIRTY) && !group->isEmpty());
-		
-		if (mRes < 2)
-		{
-			if (AABBInFrustumObjectBounds(group) > 0)
-			{
-				mEmpty = FALSE;
-				const LLVector4a* exts = group->getObjectExtents();
-				update_min_max(mMin, mMax, exts[0]);
-				update_min_max(mMin, mMax, exts[1]);
-			}
-		}
-		else
-		{
-			mEmpty = FALSE;
-			const LLVector4a* exts = group->getExtents();
-			update_min_max(mMin, mMax, exts[0]);
-			update_min_max(mMin, mMax, exts[1]);
-		}
-	}
-
-	BOOL mEmpty;
-	LLVector4a& mMin;
-	LLVector4a& mMax;
+    LLOctreeCullVisExtents(LLCamera* camera, LLVector4a& min, LLVector4a& max)
+        : LLOctreeCullShadow(camera), mMin(min), mMax(max), mEmpty(TRUE) { }
+
+    virtual bool earlyFail(LLViewerOctreeGroup* base_group)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*)base_group;
+
+        if (group->getOctreeNode()->getParent() &&  //never occlusion cull the root node
+            LLPipeline::sUseOcclusion &&            //ignore occlusion if disabled
+            group->isOcclusionState(LLSpatialGroup::OCCLUDED))
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+    virtual void traverse(const OctreeNode* n)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) n->getListener(0);
+
+        if (earlyFail(group))
+        {
+            return;
+        }
+
+        if ((mRes && group->hasState(LLSpatialGroup::SKIP_FRUSTUM_CHECK)) ||
+            mRes == 2)
+        {   //don't need to do frustum check
+            OctreeTraveler::traverse(n);
+        }
+        else
+        {
+            mRes = frustumCheck(group);
+
+            if (mRes)
+            { //at least partially in, run on down
+                OctreeTraveler::traverse(n);
+            }
+
+            mRes = 0;
+        }
+    }
+
+    virtual void processGroup(LLViewerOctreeGroup* base_group)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*)base_group;
+
+        llassert(!group->hasState(LLSpatialGroup::DIRTY) && !group->isEmpty());
+
+        if (mRes < 2)
+        {
+            if (AABBInFrustumObjectBounds(group) > 0)
+            {
+                mEmpty = FALSE;
+                const LLVector4a* exts = group->getObjectExtents();
+                update_min_max(mMin, mMax, exts[0]);
+                update_min_max(mMin, mMax, exts[1]);
+            }
+        }
+        else
+        {
+            mEmpty = FALSE;
+            const LLVector4a* exts = group->getExtents();
+            update_min_max(mMin, mMax, exts[0]);
+            update_min_max(mMin, mMax, exts[1]);
+        }
+    }
+
+    BOOL mEmpty;
+    LLVector4a& mMin;
+    LLVector4a& mMax;
 };
 
 class LLOctreeCullDetectVisible: public LLOctreeCullShadow
 {
 public:
-	LLOctreeCullDetectVisible(LLCamera* camera)
-		: LLOctreeCullShadow(camera), mResult(FALSE) { }
-
-	virtual bool earlyFail(LLViewerOctreeGroup* base_group)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*)base_group;
-
-		if (mResult || //already found a node, don't check any more
-			(group->getOctreeNode()->getParent() &&	//never occlusion cull the root node
-			 LLPipeline::sUseOcclusion &&			//ignore occlusion if disabled
-			 group->isOcclusionState(LLSpatialGroup::OCCLUDED)))
-		{
-			return true;
-		}
-		
-		return false;
-	}
-
-	virtual void processGroup(LLViewerOctreeGroup* base_group)
-	{
-		if (base_group->isVisible())
-		{
-			mResult = TRUE;
-		}
-	}
-
-	BOOL mResult;
+    LLOctreeCullDetectVisible(LLCamera* camera)
+        : LLOctreeCullShadow(camera), mResult(FALSE) { }
+
+    virtual bool earlyFail(LLViewerOctreeGroup* base_group)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*)base_group;
+
+        if (mResult || //already found a node, don't check any more
+            (group->getOctreeNode()->getParent() && //never occlusion cull the root node
+             LLPipeline::sUseOcclusion &&           //ignore occlusion if disabled
+             group->isOcclusionState(LLSpatialGroup::OCCLUDED)))
+        {
+            return true;
+        }
+
+        return false;
+    }
+
+    virtual void processGroup(LLViewerOctreeGroup* base_group)
+    {
+        if (base_group->isVisible())
+        {
+            mResult = TRUE;
+        }
+    }
+
+    BOOL mResult;
 };
 
 class LLOctreeSelect : public LLOctreeCull
 {
 public:
-	LLOctreeSelect(LLCamera* camera, std::vector<LLDrawable*>* results)
-		: LLOctreeCull(camera), mResults(results) { }
-
-	virtual bool earlyFail(LLViewerOctreeGroup* group) { return false; }
-	virtual void preprocess(LLViewerOctreeGroup* group) { }
-
-	virtual void processGroup(LLViewerOctreeGroup* base_group)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*)base_group;
-		OctreeNode* branch = group->getOctreeNode();
-
-		for (OctreeNode::const_element_iter i = branch->getDataBegin(), i_end = branch->getDataEnd(); i != i_end; ++i)
-		{
-			LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
-			if(!drawable)
-		{
-				continue;
-			}
-			if (!drawable->isDead())
-			{
-				if (drawable->isSpatialBridge())
-				{
-					drawable->setVisible(*mCamera, mResults, TRUE);
-				}
-				else
-				{
-					mResults->push_back(drawable);
-				}
-			}		
-		}
-	}
-	
-	std::vector<LLDrawable*>* mResults;
+    LLOctreeSelect(LLCamera* camera, std::vector<LLDrawable*>* results)
+        : LLOctreeCull(camera), mResults(results) { }
+
+    virtual bool earlyFail(LLViewerOctreeGroup* group) { return false; }
+    virtual void preprocess(LLViewerOctreeGroup* group) { }
+
+    virtual void processGroup(LLViewerOctreeGroup* base_group)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*)base_group;
+        OctreeNode* branch = group->getOctreeNode();
+
+        for (OctreeNode::const_element_iter i = branch->getDataBegin(), i_end = branch->getDataEnd(); i != i_end; ++i)
+        {
+            LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
+            if(!drawable)
+        {
+                continue;
+            }
+            if (!drawable->isDead())
+            {
+                if (drawable->isSpatialBridge())
+                {
+                    drawable->setVisible(*mCamera, mResults, TRUE);
+                }
+                else
+                {
+                    mResults->push_back(drawable);
+                }
+            }
+        }
+    }
+
+    std::vector<LLDrawable*>* mResults;
 };
 
 void drawBox(const LLVector3& c, const LLVector3& r)
 {
-	LLVertexBuffer::unbind();
-
-	gGL.begin(LLRender::TRIANGLE_STRIP);
-	//left front
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV);
-	//right front
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,-1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,1))).mV);
-	//right back
- 	gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,-1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,1))).mV);
-	//left back
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,-1,-1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,-1,1))).mV);
-	//left front
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV);
-	gGL.end();
-	
-	//bottom
-	gGL.begin(LLRender::TRIANGLE_STRIP);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,-1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,-1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,-1,-1))).mV);
-	gGL.end();
-
-	//top
-	gGL.begin(LLRender::TRIANGLE_STRIP);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,1))).mV);
-	gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,-1,1))).mV);
-	gGL.end();	
+    LLVertexBuffer::unbind();
+
+    gGL.begin(LLRender::TRIANGLE_STRIP);
+    //left front
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV);
+    //right front
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,-1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,1))).mV);
+    //right back
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,-1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,1))).mV);
+    //left back
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,-1,-1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,-1,1))).mV);
+    //left front
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV);
+    gGL.end();
+
+    //bottom
+    gGL.begin(LLRender::TRIANGLE_STRIP);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,-1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,-1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,-1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,-1,-1))).mV);
+    gGL.end();
+
+    //top
+    gGL.begin(LLRender::TRIANGLE_STRIP);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(1,1,1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,1,1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(1,-1,1))).mV);
+    gGL.vertex3fv((c+r.scaledVec(LLVector3(-1,-1,1))).mV);
+    gGL.end();
 }
 
 void drawBox(const LLVector4a& c, const LLVector4a& r)
 {
-	drawBox(reinterpret_cast<const LLVector3&>(c), reinterpret_cast<const LLVector3&>(r));
+    drawBox(reinterpret_cast<const LLVector3&>(c), reinterpret_cast<const LLVector3&>(r));
 }
 
 void drawBoxOutline(const LLVector3& pos, const LLVector3& size)
@@ -1327,53 +1327,53 @@ void drawBoxOutline(const LLVector3& pos, const LLVector3& size)
     if (!pos.isFinite() || !size.isFinite())
         return;
 
-	LLVector3 v1 = size.scaledVec(LLVector3( 1, 1,1));
-	LLVector3 v2 = size.scaledVec(LLVector3(-1, 1,1));
-	LLVector3 v3 = size.scaledVec(LLVector3(-1,-1,1));
-	LLVector3 v4 = size.scaledVec(LLVector3( 1,-1,1));
-
-	gGL.begin(LLRender::LINES); 
-	
-	//top
-	gGL.vertex3fv((pos+v1).mV);
-	gGL.vertex3fv((pos+v2).mV);
-	gGL.vertex3fv((pos+v2).mV);
-	gGL.vertex3fv((pos+v3).mV);
-	gGL.vertex3fv((pos+v3).mV);
-	gGL.vertex3fv((pos+v4).mV);
-	gGL.vertex3fv((pos+v4).mV);
-	gGL.vertex3fv((pos+v1).mV);
-	
-	//bottom
-	gGL.vertex3fv((pos-v1).mV);
-	gGL.vertex3fv((pos-v2).mV);
-	gGL.vertex3fv((pos-v2).mV);
-	gGL.vertex3fv((pos-v3).mV);
-	gGL.vertex3fv((pos-v3).mV);
-	gGL.vertex3fv((pos-v4).mV);
-	gGL.vertex3fv((pos-v4).mV);
-	gGL.vertex3fv((pos-v1).mV);
-	
-	//right
-	gGL.vertex3fv((pos+v1).mV);
-	gGL.vertex3fv((pos-v3).mV);
-			
-	gGL.vertex3fv((pos+v4).mV);
-	gGL.vertex3fv((pos-v2).mV);
-
-	//left
-	gGL.vertex3fv((pos+v2).mV);
-	gGL.vertex3fv((pos-v4).mV);
-
-	gGL.vertex3fv((pos+v3).mV);
-	gGL.vertex3fv((pos-v1).mV);
-
-	gGL.end();
+    LLVector3 v1 = size.scaledVec(LLVector3( 1, 1,1));
+    LLVector3 v2 = size.scaledVec(LLVector3(-1, 1,1));
+    LLVector3 v3 = size.scaledVec(LLVector3(-1,-1,1));
+    LLVector3 v4 = size.scaledVec(LLVector3( 1,-1,1));
+
+    gGL.begin(LLRender::LINES);
+
+    //top
+    gGL.vertex3fv((pos+v1).mV);
+    gGL.vertex3fv((pos+v2).mV);
+    gGL.vertex3fv((pos+v2).mV);
+    gGL.vertex3fv((pos+v3).mV);
+    gGL.vertex3fv((pos+v3).mV);
+    gGL.vertex3fv((pos+v4).mV);
+    gGL.vertex3fv((pos+v4).mV);
+    gGL.vertex3fv((pos+v1).mV);
+
+    //bottom
+    gGL.vertex3fv((pos-v1).mV);
+    gGL.vertex3fv((pos-v2).mV);
+    gGL.vertex3fv((pos-v2).mV);
+    gGL.vertex3fv((pos-v3).mV);
+    gGL.vertex3fv((pos-v3).mV);
+    gGL.vertex3fv((pos-v4).mV);
+    gGL.vertex3fv((pos-v4).mV);
+    gGL.vertex3fv((pos-v1).mV);
+
+    //right
+    gGL.vertex3fv((pos+v1).mV);
+    gGL.vertex3fv((pos-v3).mV);
+
+    gGL.vertex3fv((pos+v4).mV);
+    gGL.vertex3fv((pos-v2).mV);
+
+    //left
+    gGL.vertex3fv((pos+v2).mV);
+    gGL.vertex3fv((pos-v4).mV);
+
+    gGL.vertex3fv((pos+v3).mV);
+    gGL.vertex3fv((pos-v1).mV);
+
+    gGL.end();
 }
 
 void drawBoxOutline(const LLVector4a& pos, const LLVector4a& size)
 {
-	drawBoxOutline(reinterpret_cast<const LLVector3&>(pos), reinterpret_cast<const LLVector3&>(size));
+    drawBoxOutline(reinterpret_cast<const LLVector3&>(pos), reinterpret_cast<const LLVector3&>(size));
 }
 
 
@@ -1384,49 +1384,49 @@ void LLSpatialPartition::restoreGL()
 BOOL LLSpatialPartition::getVisibleExtents(LLCamera& camera, LLVector3& visMin, LLVector3& visMax)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL;
-	LLVector4a visMina, visMaxa;
-	visMina.load3(visMin.mV);
-	visMaxa.load3(visMax.mV);
+    LLVector4a visMina, visMaxa;
+    visMina.load3(visMin.mV);
+    visMaxa.load3(visMax.mV);
 
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) mOctree->getListener(0);
-		group->rebound();
-	}
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) mOctree->getListener(0);
+        group->rebound();
+    }
 
-	LLOctreeCullVisExtents vis(&camera, visMina, visMaxa);
-	vis.traverse(mOctree);
+    LLOctreeCullVisExtents vis(&camera, visMina, visMaxa);
+    vis.traverse(mOctree);
 
-	visMin.set(visMina.getF32ptr());
-	visMax.set(visMaxa.getF32ptr());
-	return vis.mEmpty;
+    visMin.set(visMina.getF32ptr());
+    visMax.set(visMaxa.getF32ptr());
+    return vis.mEmpty;
 }
 
 BOOL LLSpatialPartition::visibleObjectsInFrustum(LLCamera& camera)
 {
-	LLOctreeCullDetectVisible vis(&camera);
-	vis.traverse(mOctree);
-	return vis.mResult;
+    LLOctreeCullDetectVisible vis(&camera);
+    vis.traverse(mOctree);
+    return vis.mResult;
 }
 
 S32 LLSpatialPartition::cull(LLCamera &camera, std::vector<LLDrawable *>* results, BOOL for_select)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL;
 #if LL_OCTREE_PARANOIA_CHECK
-	((LLSpatialGroup*)mOctree->getListener(0))->checkStates();
+    ((LLSpatialGroup*)mOctree->getListener(0))->checkStates();
 #endif
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) mOctree->getListener(0);
-		group->rebound();
-	}
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) mOctree->getListener(0);
+        group->rebound();
+    }
 
 #if LL_OCTREE_PARANOIA_CHECK
-	((LLSpatialGroup*)mOctree->getListener(0))->validate();
+    ((LLSpatialGroup*)mOctree->getListener(0))->validate();
 #endif
 
-		LLOctreeSelect selecter(&camera, results);
-		selecter.traverse(mOctree);
-	
-	return 0;
+        LLOctreeSelect selecter(&camera, results);
+        selecter.traverse(mOctree);
+
+    return 0;
 }
 
 extern BOOL gCubeSnapshot;
@@ -1435,13 +1435,13 @@ S32 LLSpatialPartition::cull(LLCamera &camera, bool do_occlusion)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_SPATIAL;
 #if LL_OCTREE_PARANOIA_CHECK
-	((LLSpatialGroup*)mOctree->getListener(0))->checkStates();
+    ((LLSpatialGroup*)mOctree->getListener(0))->checkStates();
 #endif
-	LLSpatialGroup* group = (LLSpatialGroup*) mOctree->getListener(0);
-	group->rebound();
+    LLSpatialGroup* group = (LLSpatialGroup*) mOctree->getListener(0);
+    group->rebound();
 
 #if LL_OCTREE_PARANOIA_CHECK
-	((LLSpatialGroup*)mOctree->getListener(0))->validate();
+    ((LLSpatialGroup*)mOctree->getListener(0))->validate();
 #endif
 
     if (LLPipeline::sShadowRender)
@@ -1459,132 +1459,132 @@ S32 LLSpatialPartition::cull(LLCamera &camera, bool do_occlusion)
         LLOctreeCull culler(&camera);
         culler.traverse(mOctree);
     }
-	
-	return 0;
+
+    return 0;
 }
 
 void pushVerts(LLDrawInfo* params)
 {
-	LLRenderPass::applyModelMatrix(*params);
-	params->mVertexBuffer->setBuffer();
-	params->mVertexBuffer->drawRange(LLRender::TRIANGLES,
-								params->mStart, params->mEnd, params->mCount, params->mOffset);
+    LLRenderPass::applyModelMatrix(*params);
+    params->mVertexBuffer->setBuffer();
+    params->mVertexBuffer->drawRange(LLRender::TRIANGLES,
+                                params->mStart, params->mEnd, params->mCount, params->mOffset);
 }
 
 void pushVerts(LLSpatialGroup* group)
 {
-	LLDrawInfo* params = NULL;
+    LLDrawInfo* params = NULL;
 
-	for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
-	{
-		for (LLSpatialGroup::drawmap_elem_t::iterator j = i->second.begin(); j != i->second.end(); ++j) 
-		{
-			params = *j;
-			pushVerts(params);
-		}
-	}
+    for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
+    {
+        for (LLSpatialGroup::drawmap_elem_t::iterator j = i->second.begin(); j != i->second.end(); ++j)
+        {
+            params = *j;
+            pushVerts(params);
+        }
+    }
 }
 
 void pushVerts(LLFace* face)
 {
-	if (face)
-	{
-		llassert(face->verify());
+    if (face)
+    {
+        llassert(face->verify());
         face->renderIndexed();
-	}
+    }
 }
 
 void pushVerts(LLDrawable* drawable)
 {
-	for (S32 i = 0, i_end = drawable->getNumFaces(); i < i_end; ++i)
-	{
-		pushVerts(drawable->getFace(i));
-	}
+    for (S32 i = 0, i_end = drawable->getNumFaces(); i < i_end; ++i)
+    {
+        pushVerts(drawable->getFace(i));
+    }
 }
 
 void pushVerts(LLVolume* volume)
 {
-	LLVertexBuffer::unbind();
-	for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i)
-	{
-		const LLVolumeFace& face = volume->getVolumeFace(i);
-		LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mPositions, NULL, face.mNumIndices, face.mIndices);
-	}
+    LLVertexBuffer::unbind();
+    for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i)
+    {
+        const LLVolumeFace& face = volume->getVolumeFace(i);
+        LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mPositions, NULL, face.mNumIndices, face.mIndices);
+    }
 }
 
 void pushBufferVerts(LLVertexBuffer* buffer)
 {
-	if (buffer)
-	{
-		buffer->setBuffer();
-		buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0);
-	}
+    if (buffer)
+    {
+        buffer->setBuffer();
+        buffer->drawRange(LLRender::TRIANGLES, 0, buffer->getNumVerts()-1, buffer->getNumIndices(), 0);
+    }
 }
 
 void pushBufferVerts(LLSpatialGroup* group, bool push_alpha = true)
 {
-	if (group->getSpatialPartition()->mRenderByGroup)
-	{
-		if (!group->mDrawMap.empty())
-		{
-			LLDrawInfo* params = *(group->mDrawMap.begin()->second.begin());
-			LLRenderPass::applyModelMatrix(*params);
-		
-			if (push_alpha)
-			{
-				pushBufferVerts(group->mVertexBuffer);
-			}
-
-			for (LLSpatialGroup::buffer_map_t::iterator i = group->mBufferMap.begin(); i != group->mBufferMap.end(); ++i)
-			{
-				for (LLSpatialGroup::buffer_texture_map_t::iterator j = i->second.begin(); j != i->second.end(); ++j)
-				{
-					for (LLSpatialGroup::buffer_list_t::iterator k = j->second.begin(); k != j->second.end(); ++k)
-					{
-						pushBufferVerts(*k);
-					}
-				}
-			}
-		}
-	}
-	/*else
-	{
-		//const LLVector4a* bounds = group->getBounds();
-		//drawBox(bounds[0], bounds[1]);
-	}*/
+    if (group->getSpatialPartition()->mRenderByGroup)
+    {
+        if (!group->mDrawMap.empty())
+        {
+            LLDrawInfo* params = *(group->mDrawMap.begin()->second.begin());
+            LLRenderPass::applyModelMatrix(*params);
+
+            if (push_alpha)
+            {
+                pushBufferVerts(group->mVertexBuffer);
+            }
+
+            for (LLSpatialGroup::buffer_map_t::iterator i = group->mBufferMap.begin(); i != group->mBufferMap.end(); ++i)
+            {
+                for (LLSpatialGroup::buffer_texture_map_t::iterator j = i->second.begin(); j != i->second.end(); ++j)
+                {
+                    for (LLSpatialGroup::buffer_list_t::iterator k = j->second.begin(); k != j->second.end(); ++k)
+                    {
+                        pushBufferVerts(*k);
+                    }
+                }
+            }
+        }
+    }
+    /*else
+    {
+        //const LLVector4a* bounds = group->getBounds();
+        //drawBox(bounds[0], bounds[1]);
+    }*/
 }
 
 void pushVertsColorCoded(LLSpatialGroup* group)
 {
-	LLDrawInfo* params = NULL;
-
-	static const LLColor4 colors[] = {
-		LLColor4::green,
-		LLColor4::green1,
-		LLColor4::green2,
-		LLColor4::green3,
-		LLColor4::green4,
-		LLColor4::green5,
-		LLColor4::green6
-	};
-		
-	static const U32 col_count = LL_ARRAY_SIZE(colors);
-
-	U32 col = 0;
-
-	for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
-	{
-		for (LLSpatialGroup::drawmap_elem_t::iterator j = i->second.begin(); j != i->second.end(); ++j) 
-		{
-			params = *j;
-			LLRenderPass::applyModelMatrix(*params);
-			gGL.diffuseColor4f(colors[col].mV[0], colors[col].mV[1], colors[col].mV[2], 0.5f);
-			params->mVertexBuffer->setBuffer();
-			params->mVertexBuffer->drawRange(LLRender::TRIANGLES,
-				params->mStart, params->mEnd, params->mCount, params->mOffset);
-			col = (col+1)%col_count;
-		}
-	}
+    LLDrawInfo* params = NULL;
+
+    static const LLColor4 colors[] = {
+        LLColor4::green,
+        LLColor4::green1,
+        LLColor4::green2,
+        LLColor4::green3,
+        LLColor4::green4,
+        LLColor4::green5,
+        LLColor4::green6
+    };
+
+    static const U32 col_count = LL_ARRAY_SIZE(colors);
+
+    U32 col = 0;
+
+    for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
+    {
+        for (LLSpatialGroup::drawmap_elem_t::iterator j = i->second.begin(); j != i->second.end(); ++j)
+        {
+            params = *j;
+            LLRenderPass::applyModelMatrix(*params);
+            gGL.diffuseColor4f(colors[col].mV[0], colors[col].mV[1], colors[col].mV[2], 0.5f);
+            params->mVertexBuffer->setBuffer();
+            params->mVertexBuffer->drawRange(LLRender::TRIANGLES,
+                params->mStart, params->mEnd, params->mCount, params->mOffset);
+            col = (col+1)%col_count;
+        }
+    }
 }
 
 // return false if drawable is rigged and:
@@ -1638,7 +1638,7 @@ bool check_rigged_group(LLDrawable* drawable)
                     last_draw_index = face->getDrawOrderIndex();
                 }
             }
-            
+
             if (child->mDrawable->getSpatialGroup() != group)
             {
                 LL_WARNS() << "[child->mDrawable->getSpatialGroup() != group] is true"
@@ -1654,49 +1654,49 @@ bool check_rigged_group(LLDrawable* drawable)
 
 void renderOctree(LLSpatialGroup* group)
 {
-	//render solid object bounding box, color
-	//coded by buffer usage and activity
-	gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
-	LLVector4 col;
-	if (group->mBuilt > 0.f)
-	{
-		group->mBuilt -= 2.f * gFrameIntervalSeconds.value();
-		col.setVec(0.1f,0.1f,1,0.1f);
-		
-		{
-			LLGLDepthTest gl_depth(FALSE, FALSE);
-			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
-			gGL.diffuseColor4f(1,0,0,group->mBuilt);
-			gGL.flush();
-			gGL.setLineWidth(5.f);
-
-			const LLVector4a* bounds = group->getObjectBounds();
-			drawBoxOutline(bounds[0], bounds[1]);
-			gGL.flush();
-			gGL.setLineWidth(1.f);
-			gGL.flush();
+    //render solid object bounding box, color
+    //coded by buffer usage and activity
+    gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
+    LLVector4 col;
+    if (group->mBuilt > 0.f)
+    {
+        group->mBuilt -= 2.f * gFrameIntervalSeconds.value();
+        col.setVec(0.1f,0.1f,1,0.1f);
+
+        {
+            LLGLDepthTest gl_depth(FALSE, FALSE);
+            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
+            gGL.diffuseColor4f(1,0,0,group->mBuilt);
+            gGL.flush();
+            gGL.setLineWidth(5.f);
+
+            const LLVector4a* bounds = group->getObjectBounds();
+            drawBoxOutline(bounds[0], bounds[1]);
+            gGL.flush();
+            gGL.setLineWidth(1.f);
+            gGL.flush();
 
             LLVOAvatar* lastAvatar = nullptr;
             U64 lastMeshId = 0;
 
-			for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
-			{
-				LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
-				if(!drawable || drawable->getNumFaces() == 0)
-				{
-					continue;
-				}
+            for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
+            {
+                LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
+                if(!drawable || drawable->getNumFaces() == 0)
+                {
+                    continue;
+                }
 
                 llassert(check_rigged_group(drawable));
 
-				if (!group->getSpatialPartition()->isBridge())
-				{
-					gGL.pushMatrix();
-					LLVector3 trans = drawable->getRegion()->getOriginAgent();
-					gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);
-				}
-				
+                if (!group->getSpatialPartition()->isBridge())
+                {
+                    gGL.pushMatrix();
+                    LLVector3 trans = drawable->getRegion()->getOriginAgent();
+                    gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);
+                }
+
                 LLFace* face = drawable->getFace(0);
                 bool rigged = face->isState(LLFace::RIGGED);
                 gDebugProgram.bind(rigged);
@@ -1718,11 +1718,11 @@ void renderOctree(LLSpatialGroup* group)
                         lastMeshId = face->mSkinInfo->mHash;
                     }
                 }
-				for (S32 j = 0, j_end = drawable->getNumFaces(); j < j_end; ++j)
-				{
-					LLFace* face = drawable->getFace(j);
-					if (face && face->getVertexBuffer())
-					{
+                for (S32 j = 0, j_end = drawable->getNumFaces(); j < j_end; ++j)
+                {
+                    LLFace* face = drawable->getFace(j);
+                    if (face && face->getVertexBuffer())
+                    {
                         LLVOVolume* vol = drawable->getVOVolume();
 
                         if (gFrameTimeSeconds - face->mLastUpdateTime < 0.5f)
@@ -1752,40 +1752,40 @@ void renderOctree(LLSpatialGroup* group)
                             continue;
                         }
 
-						face->getVertexBuffer()->setBuffer();
-						face->getVertexBuffer()->draw(LLRender::TRIANGLES, face->getIndicesCount(), face->getIndicesStart());
-					}
-				}
+                        face->getVertexBuffer()->setBuffer();
+                        face->getVertexBuffer()->draw(LLRender::TRIANGLES, face->getIndicesCount(), face->getIndicesStart());
+                    }
+                }
 
                 if (rigged)
                 {
                     gGL.popMatrix();
                 }
 
-				if (!group->getSpatialPartition()->isBridge())
-				{
-					gGL.popMatrix();
-				}
-			}
-			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+                if (!group->getSpatialPartition()->isBridge())
+                {
+                    gGL.popMatrix();
+                }
+            }
+            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
             gDebugProgram.bind(); // make sure non-rigged variant is bound
-			gGL.diffuseColor4f(1,1,1,1);
-		}
-	}
+            gGL.diffuseColor4f(1,1,1,1);
+        }
+    }
 
-	gGL.diffuseColor4fv(col.mV);
-	LLVector4a fudge;
-	fudge.splat(0.001f);
+    gGL.diffuseColor4fv(col.mV);
+    LLVector4a fudge;
+    fudge.splat(0.001f);
 
-	gGL.setSceneBlendType(LLRender::BT_ALPHA);
+    gGL.setSceneBlendType(LLRender::BT_ALPHA);
 
-	{
-		//draw opaque outline
-		gGL.diffuseColor4f(0,1,1,1);
+    {
+        //draw opaque outline
+        gGL.diffuseColor4f(0,1,1,1);
 
-		const LLVector4a* bounds = group->getBounds();
-		drawBoxOutline(bounds[0], bounds[1]);
-	}
+        const LLVector4a* bounds = group->getBounds();
+        drawBoxOutline(bounds[0], bounds[1]);
+    }
 }
 
 std::set<LLSpatialGroup*> visible_selected_groups;
@@ -1794,264 +1794,264 @@ std::set<LLSpatialGroup*> visible_selected_groups;
 
 void renderXRay(LLSpatialGroup* group, LLCamera* camera)
 {
-	BOOL render_objects = (!LLPipeline::sUseOcclusion || !group->isOcclusionState(LLSpatialGroup::OCCLUDED)) && group->isVisible() &&
-							!group->isEmpty();
-	
-	if (render_objects)
-	{
-		pushBufferVerts(group, false);
-
-		bool selected = false;
-
-		for (LLSpatialGroup::element_iter iter = group->getDataBegin(), iter_end = group->getDataEnd(); iter != iter_end; ++iter)
-		{
-			LLDrawable* drawable = (LLDrawable*)(*iter)->getDrawable();
-			if (drawable->getVObj().notNull() && drawable->getVObj()->isSelected())
-			{
-				selected = true;
-				break;
-			}
-		}
-
-		if (selected)
-		{ //store for rendering occlusion volume as overlay
-
-			if (!group->getSpatialPartition()->isBridge())
-			{
-				visible_selected_groups.insert(group);
-			}
-			else
-			{
-				visible_selected_groups.insert(group->getSpatialPartition()->asBridge()->getSpatialGroup());
-			}
-		}
-	}
+    BOOL render_objects = (!LLPipeline::sUseOcclusion || !group->isOcclusionState(LLSpatialGroup::OCCLUDED)) && group->isVisible() &&
+                            !group->isEmpty();
+
+    if (render_objects)
+    {
+        pushBufferVerts(group, false);
+
+        bool selected = false;
+
+        for (LLSpatialGroup::element_iter iter = group->getDataBegin(), iter_end = group->getDataEnd(); iter != iter_end; ++iter)
+        {
+            LLDrawable* drawable = (LLDrawable*)(*iter)->getDrawable();
+            if (drawable->getVObj().notNull() && drawable->getVObj()->isSelected())
+            {
+                selected = true;
+                break;
+            }
+        }
+
+        if (selected)
+        { //store for rendering occlusion volume as overlay
+
+            if (!group->getSpatialPartition()->isBridge())
+            {
+                visible_selected_groups.insert(group);
+            }
+            else
+            {
+                visible_selected_groups.insert(group->getSpatialPartition()->asBridge()->getSpatialGroup());
+            }
+        }
+    }
 }
 
 void renderCrossHairs(LLVector3 position, F32 size, LLColor4 color)
 {
-	gGL.color4fv(color.mV);
-	gGL.begin(LLRender::LINES);
-	{
-		gGL.vertex3fv((position - LLVector3(size, 0.f, 0.f)).mV);
-		gGL.vertex3fv((position + LLVector3(size, 0.f, 0.f)).mV);
-		gGL.vertex3fv((position - LLVector3(0.f, size, 0.f)).mV);
-		gGL.vertex3fv((position + LLVector3(0.f, size, 0.f)).mV);
-		gGL.vertex3fv((position - LLVector3(0.f, 0.f, size)).mV);
-		gGL.vertex3fv((position + LLVector3(0.f, 0.f, size)).mV);
-	}
-	gGL.end();
+    gGL.color4fv(color.mV);
+    gGL.begin(LLRender::LINES);
+    {
+        gGL.vertex3fv((position - LLVector3(size, 0.f, 0.f)).mV);
+        gGL.vertex3fv((position + LLVector3(size, 0.f, 0.f)).mV);
+        gGL.vertex3fv((position - LLVector3(0.f, size, 0.f)).mV);
+        gGL.vertex3fv((position + LLVector3(0.f, size, 0.f)).mV);
+        gGL.vertex3fv((position - LLVector3(0.f, 0.f, size)).mV);
+        gGL.vertex3fv((position + LLVector3(0.f, 0.f, size)).mV);
+    }
+    gGL.end();
 }
 
 void renderUpdateType(LLDrawable* drawablep)
 {
-	LLViewerObject* vobj = drawablep->getVObj();
-	if (!vobj || OUT_UNKNOWN == vobj->getLastUpdateType())
-	{
-		return;
-	}
-	LLGLEnable blend(GL_BLEND);
-	switch (vobj->getLastUpdateType())
-	{
-	case OUT_FULL:
-		gGL.diffuseColor4f(0,1,0,0.5f);
-		break;
-	case OUT_TERSE_IMPROVED:
-		gGL.diffuseColor4f(0,1,1,0.5f);
-		break;
-	case OUT_FULL_COMPRESSED:
-		if (vobj->getLastUpdateCached())
-		{
-			gGL.diffuseColor4f(1,0,0,0.5f);
-		}
-		else
-		{
-			gGL.diffuseColor4f(1,1,0,0.5f);
-		}
-		break;
-	case OUT_FULL_CACHED:
-		gGL.diffuseColor4f(0,0,1,0.5f);
-		break;
-	default:
-		LL_WARNS() << "Unknown update_type " << vobj->getLastUpdateType() << LL_ENDL;
-		break;
-	};
-	S32 num_faces = drawablep->getNumFaces();
-	if (num_faces)
-	{
-		for (S32 i = 0; i < num_faces; ++i)
-		{
-			pushVerts(drawablep->getFace(i));
-		}
-	}
-}
-
-void renderBoundingBox(LLDrawable* drawable, BOOL set_color = TRUE)
-{
-	if (set_color)
-	{
-		if (drawable->isSpatialBridge())
-		{
-			gGL.diffuseColor4f(1,0.5f,0,1); // orange
-		}
-		else if (drawable->getVOVolume())
-		{ 
-            if (drawable->isRoot())
-			{
-				gGL.diffuseColor4f(1,1,0,1); // yellow
-			}
-			else
-			{
-				gGL.diffuseColor4f(0,1,0,1); // green
-			}
-		}
-		else if (drawable->getVObj())
-		{
-			switch (drawable->getVObj()->getPCode())
-			{
-				case LLViewerObject::LL_VO_SURFACE_PATCH:
-                    	gGL.diffuseColor4f(0,1,1,1); // cyan
-						break;
-				case LLViewerObject::LL_VO_CLOUDS:
-						// no longer used
-						break;
-				case LLViewerObject::LL_VO_PART_GROUP:
-				case LLViewerObject::LL_VO_HUD_PART_GROUP:
-                    	gGL.diffuseColor4f(0,0,1,1); // blue
-						break;
-				case LLViewerObject::LL_VO_VOID_WATER:
-				case LLViewerObject::LL_VO_WATER:
-                    	gGL.diffuseColor4f(0,0.5f,1,1); // medium blue
-						break;
-				case LL_PCODE_LEGACY_TREE:
-                    	gGL.diffuseColor4f(0,0.5f,0,1); // dark green
-						break;
-				default:
-						auto avatarp = drawable->getVObj()->asAvatar();
-						if (avatarp && avatarp->isControlAvatar())
-						{
-							LLControlAvatar* cav = static_cast<LLControlAvatar*>(avatarp);
-							bool has_pos_constraint = (cav->mPositionConstraintFixup != LLVector3());
-							bool has_scale_constraint = (cav->mScaleConstraintFixup != 1.0f);
-							if (has_pos_constraint || has_scale_constraint)
-							{
-								gGL.diffuseColor4f(1,0,0,1); 
-							}
-							else
-							{
-								gGL.diffuseColor4f(0,1,0.5,1); 
-							}
-						}
-						else
-						{
-							gGL.diffuseColor4f(1,0,1,1); // magenta
-						}
-						break;
-			}
-		}
-		else 
-		{
-			gGL.diffuseColor4f(1,0,0,1);
-		}
-	}
-
-	const LLVector4a* ext;
-	LLVector4a pos, size;
-
-	if (drawable->getVOVolume())
-	{
-		//render face bounding boxes
-		for (S32 i = 0; i < drawable->getNumFaces(); i++)
-		{
-			LLFace* facep = drawable->getFace(i);
-			if (facep)
-			{
-				ext = facep->mExtents;
-
-				pos.setAdd(ext[0], ext[1]);
-				pos.mul(0.5f);
-				size.setSub(ext[1], ext[0]);
-				size.mul(0.5f);
-		
-				drawBoxOutline(pos,size);
-			}
-		}
-	}
-
-	//render drawable bounding box
-	ext = drawable->getSpatialExtents();
-
-	pos.setAdd(ext[0], ext[1]);
-	pos.mul(0.5f);
-	size.setSub(ext[1], ext[0]);
-	size.mul(0.5f);
-	
-	LLViewerObject* vobj = drawable->getVObj();
-	if (vobj && vobj->onActiveList())
-	{
-		gGL.flush();
-		gGL.setLineWidth(llmax(4.f*sinf(gFrameTimeSeconds*2.f)+1.f, 1.f));
-		//gGL.setLineWidth(4.f*(sinf(gFrameTimeSeconds*2.f)*0.25f+0.75f));
-		stop_glerror();
-		drawBoxOutline(pos,size);
-		gGL.flush();
-		gGL.setLineWidth(1.f);
-	}
-	else
-	{
-		drawBoxOutline(pos,size);
-	}
-}
-// *TODO: LLDrawables which are not part of LLVOVolumes fall into a different
-// code path which uses a shader - it was tested to be faster than mapping a
-// vertex buffer in the terrain case. Consider using it for LLVOVolumes as well
-// to simplify and speed up this debug code. Alternatively, a compute shader is
-// likely faster. -Cosmic,2023-09-28
-void renderNormals(LLDrawable *drawablep)
-{
-    if (!drawablep->isVisible())
+    LLViewerObject* vobj = drawablep->getVObj();
+    if (!vobj || OUT_UNKNOWN == vobj->getLastUpdateType())
+    {
         return;
-
-    LLVertexBuffer::unbind();
-
-	LLViewerObject* obj = drawablep->getVObj();
-    LLVOVolume *vol = drawablep->getVOVolume();
-
-	if (obj)
+    }
+    LLGLEnable blend(GL_BLEND);
+    switch (vobj->getLastUpdateType())
     {
-		LLGLEnable blend(GL_BLEND);
-        LLGLDepthTest gl_depth(GL_TRUE, GL_FALSE);
-
-        // Drawable's normals & tangents are stored in model space, i.e. before any scaling is applied.
-        //
-        // SL-13490, using pos + normal to compute the 2nd vertex of a normal line segment doesn't
-        // work when there's a non-uniform scale in the mix. Normals require MVP-inverse-transpose
-        // transform. We get that effect here by pre-applying the inverse scale (twice, because
-        // one forward scale will be re-applied via the MVP in the vertex shader)
-
-        LLVector4a inv_scale;
-		float scale_len;
-        if (vol)
+    case OUT_FULL:
+        gGL.diffuseColor4f(0,1,0,0.5f);
+        break;
+    case OUT_TERSE_IMPROVED:
+        gGL.diffuseColor4f(0,1,1,0.5f);
+        break;
+    case OUT_FULL_COMPRESSED:
+        if (vobj->getLastUpdateCached())
         {
-            LLVector3  scale_v3 = vol->getScale();
-            LLVector4a obj_scale(scale_v3.mV[VX], scale_v3.mV[VY], scale_v3.mV[VZ]);
-            obj_scale.normalize3();
-
-            // Create inverse-scale vector for normals
-            inv_scale.set(1.0 / scale_v3.mV[VX], 1.0 / scale_v3.mV[VY], 1.0 / scale_v3.mV[VZ], 0.0);
-            inv_scale.mul(inv_scale);  // Squared, to apply inverse scale twice
-
-            inv_scale.normalize3fast();
-			scale_len = scale_v3.length();
+            gGL.diffuseColor4f(1,0,0,0.5f);
         }
         else
         {
-			inv_scale.set(1.0, 1.0, 1.0, 0.0);
-			scale_len = 1.0;
+            gGL.diffuseColor4f(1,1,0,0.5f);
         }
-
-        gGL.pushMatrix();
-        if (vol)
+        break;
+    case OUT_FULL_CACHED:
+        gGL.diffuseColor4f(0,0,1,0.5f);
+        break;
+    default:
+        LL_WARNS() << "Unknown update_type " << vobj->getLastUpdateType() << LL_ENDL;
+        break;
+    };
+    S32 num_faces = drawablep->getNumFaces();
+    if (num_faces)
+    {
+        for (S32 i = 0; i < num_faces; ++i)
+        {
+            pushVerts(drawablep->getFace(i));
+        }
+    }
+}
+
+void renderBoundingBox(LLDrawable* drawable, BOOL set_color = TRUE)
+{
+    if (set_color)
+    {
+        if (drawable->isSpatialBridge())
+        {
+            gGL.diffuseColor4f(1,0.5f,0,1); // orange
+        }
+        else if (drawable->getVOVolume())
+        {
+            if (drawable->isRoot())
+            {
+                gGL.diffuseColor4f(1,1,0,1); // yellow
+            }
+            else
+            {
+                gGL.diffuseColor4f(0,1,0,1); // green
+            }
+        }
+        else if (drawable->getVObj())
+        {
+            switch (drawable->getVObj()->getPCode())
+            {
+                case LLViewerObject::LL_VO_SURFACE_PATCH:
+                        gGL.diffuseColor4f(0,1,1,1); // cyan
+                        break;
+                case LLViewerObject::LL_VO_CLOUDS:
+                        // no longer used
+                        break;
+                case LLViewerObject::LL_VO_PART_GROUP:
+                case LLViewerObject::LL_VO_HUD_PART_GROUP:
+                        gGL.diffuseColor4f(0,0,1,1); // blue
+                        break;
+                case LLViewerObject::LL_VO_VOID_WATER:
+                case LLViewerObject::LL_VO_WATER:
+                        gGL.diffuseColor4f(0,0.5f,1,1); // medium blue
+                        break;
+                case LL_PCODE_LEGACY_TREE:
+                        gGL.diffuseColor4f(0,0.5f,0,1); // dark green
+                        break;
+                default:
+                        auto avatarp = drawable->getVObj()->asAvatar();
+                        if (avatarp && avatarp->isControlAvatar())
+                        {
+                            LLControlAvatar* cav = static_cast<LLControlAvatar*>(avatarp);
+                            bool has_pos_constraint = (cav->mPositionConstraintFixup != LLVector3());
+                            bool has_scale_constraint = (cav->mScaleConstraintFixup != 1.0f);
+                            if (has_pos_constraint || has_scale_constraint)
+                            {
+                                gGL.diffuseColor4f(1,0,0,1);
+                            }
+                            else
+                            {
+                                gGL.diffuseColor4f(0,1,0.5,1);
+                            }
+                        }
+                        else
+                        {
+                            gGL.diffuseColor4f(1,0,1,1); // magenta
+                        }
+                        break;
+            }
+        }
+        else
+        {
+            gGL.diffuseColor4f(1,0,0,1);
+        }
+    }
+
+    const LLVector4a* ext;
+    LLVector4a pos, size;
+
+    if (drawable->getVOVolume())
+    {
+        //render face bounding boxes
+        for (S32 i = 0; i < drawable->getNumFaces(); i++)
+        {
+            LLFace* facep = drawable->getFace(i);
+            if (facep)
+            {
+                ext = facep->mExtents;
+
+                pos.setAdd(ext[0], ext[1]);
+                pos.mul(0.5f);
+                size.setSub(ext[1], ext[0]);
+                size.mul(0.5f);
+
+                drawBoxOutline(pos,size);
+            }
+        }
+    }
+
+    //render drawable bounding box
+    ext = drawable->getSpatialExtents();
+
+    pos.setAdd(ext[0], ext[1]);
+    pos.mul(0.5f);
+    size.setSub(ext[1], ext[0]);
+    size.mul(0.5f);
+
+    LLViewerObject* vobj = drawable->getVObj();
+    if (vobj && vobj->onActiveList())
+    {
+        gGL.flush();
+        gGL.setLineWidth(llmax(4.f*sinf(gFrameTimeSeconds*2.f)+1.f, 1.f));
+        //gGL.setLineWidth(4.f*(sinf(gFrameTimeSeconds*2.f)*0.25f+0.75f));
+        stop_glerror();
+        drawBoxOutline(pos,size);
+        gGL.flush();
+        gGL.setLineWidth(1.f);
+    }
+    else
+    {
+        drawBoxOutline(pos,size);
+    }
+}
+// *TODO: LLDrawables which are not part of LLVOVolumes fall into a different
+// code path which uses a shader - it was tested to be faster than mapping a
+// vertex buffer in the terrain case. Consider using it for LLVOVolumes as well
+// to simplify and speed up this debug code. Alternatively, a compute shader is
+// likely faster. -Cosmic,2023-09-28
+void renderNormals(LLDrawable *drawablep)
+{
+    if (!drawablep->isVisible())
+        return;
+
+    LLVertexBuffer::unbind();
+
+    LLViewerObject* obj = drawablep->getVObj();
+    LLVOVolume *vol = drawablep->getVOVolume();
+
+    if (obj)
+    {
+        LLGLEnable blend(GL_BLEND);
+        LLGLDepthTest gl_depth(GL_TRUE, GL_FALSE);
+
+        // Drawable's normals & tangents are stored in model space, i.e. before any scaling is applied.
+        //
+        // SL-13490, using pos + normal to compute the 2nd vertex of a normal line segment doesn't
+        // work when there's a non-uniform scale in the mix. Normals require MVP-inverse-transpose
+        // transform. We get that effect here by pre-applying the inverse scale (twice, because
+        // one forward scale will be re-applied via the MVP in the vertex shader)
+
+        LLVector4a inv_scale;
+        float scale_len;
+        if (vol)
+        {
+            LLVector3  scale_v3 = vol->getScale();
+            LLVector4a obj_scale(scale_v3.mV[VX], scale_v3.mV[VY], scale_v3.mV[VZ]);
+            obj_scale.normalize3();
+
+            // Create inverse-scale vector for normals
+            inv_scale.set(1.0 / scale_v3.mV[VX], 1.0 / scale_v3.mV[VY], 1.0 / scale_v3.mV[VZ], 0.0);
+            inv_scale.mul(inv_scale);  // Squared, to apply inverse scale twice
+
+            inv_scale.normalize3fast();
+            scale_len = scale_v3.length();
+        }
+        else
+        {
+            inv_scale.set(1.0, 1.0, 1.0, 0.0);
+            scale_len = 1.0;
+        }
+
+        gGL.pushMatrix();
+        if (vol)
         {
             gGL.multMatrix(vol->getRelativeXform());
         }
@@ -2063,7 +2063,7 @@ void renderNormals(LLDrawable *drawablep)
         float draw_length = gSavedSettings.getF32("RenderDebugNormalScale") / scale_len;
 
         std::vector<LLVolumeFace>* faces = nullptr;
-		std::vector<LLFace*>* drawable_faces = nullptr;
+        std::vector<LLFace*>* drawable_faces = nullptr;
         if (vol)
         {
             LLVolume* volume = vol->getVolume();
@@ -2071,67 +2071,67 @@ void renderNormals(LLDrawable *drawablep)
         }
         else
         {
-			drawable_faces = &drawablep->getFaces();
+            drawable_faces = &drawablep->getFaces();
         }
 
-		if (faces)
-		{
-			for (auto it = faces->begin(); it != faces->end(); ++it)
-			{
-				const LLVolumeFace& face = *it;
-
-				gGL.flush();
-				gGL.diffuseColor4f(1, 1, 0, 1);
-				gGL.begin(LLRender::LINES);
-				for (S32 j = 0; j < face.mNumVertices; ++j)
-				{
-					LLVector4a n, p;
-
-					n.setMul(face.mNormals[j], 1.0);
-					n.mul(inv_scale);  // Pre-scale normal, so it's left with an inverse-transpose xform after MVP
-					n.normalize3fast();
-					n.mul(draw_length);
-					p.setAdd(face.mPositions[j], n);
-
-					gGL.vertex3fv(face.mPositions[j].getF32ptr());
-					gGL.vertex3fv(p.getF32ptr());
-				}
-				gGL.end();
-
-				// Tangents are simple vectors and do not require reorientation via pre-scaling
-				if (face.mTangents)
-				{
-					gGL.flush();
-					gGL.diffuseColor4f(0, 1, 1, 1);
-					gGL.begin(LLRender::LINES);
-					for (S32 j = 0; j < face.mNumVertices; ++j)
-					{
-						LLVector4a t, p;
-
-						t.setMul(face.mTangents[j], 1.0f);
-						t.normalize3fast();
-						t.mul(draw_length);
-						p.setAdd(face.mPositions[j], t);
-
-						gGL.vertex3fv(face.mPositions[j].getF32ptr());
-						gGL.vertex3fv(p.getF32ptr());
-					}
-					gGL.end();
-				}
-			}
-		}
-		else if (drawable_faces)
-		{
-			// *HACK: Prepare to restore previous shader as other debug code depends on a simpler shader being present
-			llassert(LLGLSLShader::sCurBoundShaderPtr == &gDebugProgram);
-			LLGLSLShader* prev_shader = LLGLSLShader::sCurBoundShaderPtr;
+        if (faces)
+        {
+            for (auto it = faces->begin(); it != faces->end(); ++it)
+            {
+                const LLVolumeFace& face = *it;
+
+                gGL.flush();
+                gGL.diffuseColor4f(1, 1, 0, 1);
+                gGL.begin(LLRender::LINES);
+                for (S32 j = 0; j < face.mNumVertices; ++j)
+                {
+                    LLVector4a n, p;
+
+                    n.setMul(face.mNormals[j], 1.0);
+                    n.mul(inv_scale);  // Pre-scale normal, so it's left with an inverse-transpose xform after MVP
+                    n.normalize3fast();
+                    n.mul(draw_length);
+                    p.setAdd(face.mPositions[j], n);
+
+                    gGL.vertex3fv(face.mPositions[j].getF32ptr());
+                    gGL.vertex3fv(p.getF32ptr());
+                }
+                gGL.end();
+
+                // Tangents are simple vectors and do not require reorientation via pre-scaling
+                if (face.mTangents)
+                {
+                    gGL.flush();
+                    gGL.diffuseColor4f(0, 1, 1, 1);
+                    gGL.begin(LLRender::LINES);
+                    for (S32 j = 0; j < face.mNumVertices; ++j)
+                    {
+                        LLVector4a t, p;
+
+                        t.setMul(face.mTangents[j], 1.0f);
+                        t.normalize3fast();
+                        t.mul(draw_length);
+                        p.setAdd(face.mPositions[j], t);
+
+                        gGL.vertex3fv(face.mPositions[j].getF32ptr());
+                        gGL.vertex3fv(p.getF32ptr());
+                    }
+                    gGL.end();
+                }
+            }
+        }
+        else if (drawable_faces)
+        {
+            // *HACK: Prepare to restore previous shader as other debug code depends on a simpler shader being present
+            llassert(LLGLSLShader::sCurBoundShaderPtr == &gDebugProgram);
+            LLGLSLShader* prev_shader = LLGLSLShader::sCurBoundShaderPtr;
             for (auto it = drawable_faces->begin(); it != drawable_faces->end(); ++it)
             {
                 LLFace* facep = *it;
                 LLFace& face = **it;
                 LLVertexBuffer* buf = face.getVertexBuffer();
                 if (!buf) { continue; }
-				U32 mask_vn = LLVertexBuffer::TYPE_VERTEX | LLVertexBuffer::TYPE_NORMAL;
+                U32 mask_vn = LLVertexBuffer::TYPE_VERTEX | LLVertexBuffer::TYPE_NORMAL;
                 if ((buf->getTypeMask() & mask_vn) != mask_vn) { continue; }
 
                 LLGLSLShader* shader;
@@ -2154,11 +2154,11 @@ void renderNormals(LLDrawable *drawablep)
                 // *NOTE: For terrain normal debug, this seems to also include vertices for water, which is technically not part of the terrain. Should fix that at some point.
                 buf->drawRange(LLRender::TRIANGLES, face.getGeomIndex(), face.getGeomIndex() + face.getGeomCount()-1, face.getIndicesCount(), face.getIndicesStart());
             }
-			if (prev_shader)
-			{
-				prev_shader->bind();
-			}
-		}
+            if (prev_shader)
+            {
+                prev_shader->bind();
+            }
+        }
 
         gGL.popMatrix();
     }
@@ -2166,295 +2166,295 @@ void renderNormals(LLDrawable *drawablep)
 
 S32 get_physics_detail(const LLVolumeParams& volume_params, const LLVector3& scale)
 {
-	const S32 DEFAULT_DETAIL = 1;
-	const F32 LARGE_THRESHOLD = 5.f;
-	const F32 MEGA_THRESHOLD = 25.f;
+    const S32 DEFAULT_DETAIL = 1;
+    const F32 LARGE_THRESHOLD = 5.f;
+    const F32 MEGA_THRESHOLD = 25.f;
 
-	S32 detail = DEFAULT_DETAIL;
-	F32 avg_scale = (scale[0]+scale[1]+scale[2])/3.f;
+    S32 detail = DEFAULT_DETAIL;
+    F32 avg_scale = (scale[0]+scale[1]+scale[2])/3.f;
 
-	if (avg_scale > LARGE_THRESHOLD)
-	{
-		detail += 1;
-		if (avg_scale > MEGA_THRESHOLD)
-		{
-			detail += 1;
-		}
-	}
+    if (avg_scale > LARGE_THRESHOLD)
+    {
+        detail += 1;
+        if (avg_scale > MEGA_THRESHOLD)
+        {
+            detail += 1;
+        }
+    }
 
-	return detail;
+    return detail;
 }
 
 void renderMeshBaseHull(LLVOVolume* volume, U32 data_mask, LLColor4& color)
 {
-	LLUUID mesh_id = volume->getVolume()->getParams().getSculptID();
-	LLModel::Decomposition* decomp = gMeshRepo.getDecomposition(mesh_id);
+    LLUUID mesh_id = volume->getVolume()->getParams().getSculptID();
+    LLModel::Decomposition* decomp = gMeshRepo.getDecomposition(mesh_id);
 
-	const LLVector3 center(0,0,0);
-	const LLVector3 size(0.25f,0.25f,0.25f);
+    const LLVector3 center(0,0,0);
+    const LLVector3 size(0.25f,0.25f,0.25f);
 
-	if (decomp)
-	{		
-		if (!decomp->mBaseHullMesh.empty())
-		{
+    if (decomp)
+    {
+        if (!decomp->mBaseHullMesh.empty())
+        {
             gGL.diffuseColor4fv(color.mV);
-			LLVertexBuffer::drawArrays(LLRender::TRIANGLES, decomp->mBaseHullMesh.mPositions);
-		}
-		else
-		{
-			gMeshRepo.buildPhysicsMesh(*decomp);
-			gGL.diffuseColor4f(0,1,1,1);
-			drawBoxOutline(center, size);
-		}
-
-	}
-	else
-	{
-		gGL.diffuseColor3f(1,0,1);
-		drawBoxOutline(center, size);
-	}
+            LLVertexBuffer::drawArrays(LLRender::TRIANGLES, decomp->mBaseHullMesh.mPositions);
+        }
+        else
+        {
+            gMeshRepo.buildPhysicsMesh(*decomp);
+            gGL.diffuseColor4f(0,1,1,1);
+            drawBoxOutline(center, size);
+        }
+
+    }
+    else
+    {
+        gGL.diffuseColor3f(1,0,1);
+        drawBoxOutline(center, size);
+    }
 }
 
 void render_hull(LLModel::PhysicsMesh& mesh, const LLColor4& color)
 {
     gGL.diffuseColor4fv(color.mV);
-	LLVertexBuffer::drawArrays(LLRender::TRIANGLES, mesh.mPositions);
+    LLVertexBuffer::drawArrays(LLRender::TRIANGLES, mesh.mPositions);
 }
 
 void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume, bool wireframe)
 {
-	U8 physics_type = volume->getPhysicsShapeType();
+    U8 physics_type = volume->getPhysicsShapeType();
 
-	if (physics_type == LLViewerObject::PHYSICS_SHAPE_NONE || volume->isFlexible())
-	{
-		return;
-	}
+    if (physics_type == LLViewerObject::PHYSICS_SHAPE_NONE || volume->isFlexible())
+    {
+        return;
+    }
 
-	//not allowed to return at this point without rendering *something*
+    //not allowed to return at this point without rendering *something*
 
-	F32 threshold = gSavedSettings.getF32("ObjectCostHighThreshold");
-	F32 cost = volume->getObjectCost();
+    F32 threshold = gSavedSettings.getF32("ObjectCostHighThreshold");
+    F32 cost = volume->getObjectCost();
 
-	LLColor4 low = gSavedSettings.getColor4("ObjectCostLowColor");
-	LLColor4 mid = gSavedSettings.getColor4("ObjectCostMidColor");
-	LLColor4 high = gSavedSettings.getColor4("ObjectCostHighColor");
+    LLColor4 low = gSavedSettings.getColor4("ObjectCostLowColor");
+    LLColor4 mid = gSavedSettings.getColor4("ObjectCostMidColor");
+    LLColor4 high = gSavedSettings.getColor4("ObjectCostHighColor");
 
-	F32 normalizedCost = 1.f - exp( -(cost / threshold) );
+    F32 normalizedCost = 1.f - exp( -(cost / threshold) );
 
-	LLColor4 color;
-	if ( normalizedCost <= 0.5f )
-	{
-		color = lerp( low, mid, 2.f * normalizedCost );
-	}
-	else
-	{
-		color = lerp( mid, high, 2.f * ( normalizedCost - 0.5f ) );
-	}
+    LLColor4 color;
+    if ( normalizedCost <= 0.5f )
+    {
+        color = lerp( low, mid, 2.f * normalizedCost );
+    }
+    else
+    {
+        color = lerp( mid, high, 2.f * ( normalizedCost - 0.5f ) );
+    }
 
     if (wireframe)
     {
         color = color * 0.5f;
     }
 
-	U32 data_mask = LLVertexBuffer::MAP_VERTEX;
+    U32 data_mask = LLVertexBuffer::MAP_VERTEX;
+
+    LLVolumeParams volume_params = volume->getVolume()->getParams();
 
-	LLVolumeParams volume_params = volume->getVolume()->getParams();
+    LLPhysicsVolumeParams physics_params(volume_params,
+        physics_type == LLViewerObject::PHYSICS_SHAPE_CONVEX_HULL);
 
-	LLPhysicsVolumeParams physics_params(volume_params, 
-		physics_type == LLViewerObject::PHYSICS_SHAPE_CONVEX_HULL); 
+    LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification physics_spec;
 
-	LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification physics_spec;
+    //<FS:Beq> FIRE-23053 Physics shape display fixes
+    //  LLPhysicsShapeBuilderUtil::determinePhysicsShape(physics_params, volume->getScale(), physics_spec);
+    LLUUID mesh_id;
+    LLModel::Decomposition* decomp = nullptr;
+    bool hasConvexDecomp = FALSE;
 
-	//<FS:Beq> FIRE-23053 Physics shape display fixes
-	// 	LLPhysicsShapeBuilderUtil::determinePhysicsShape(physics_params, volume->getScale(), physics_spec);
-	LLUUID mesh_id;
-	LLModel::Decomposition* decomp = nullptr;
-	bool hasConvexDecomp = FALSE;
+    // If we are a mesh and the mesh has a hul decomp (is analysed) then set hasDecomp to true
+    if (volume->isMesh()){
+        mesh_id = volume_params.getSculptID();
+        decomp = gMeshRepo.getDecomposition(mesh_id);
+        if (decomp && !decomp->mHull.empty()){ hasConvexDecomp = TRUE; }
+    }
+
+    LLPhysicsShapeBuilderUtil::determinePhysicsShape(physics_params, volume->getScale(), hasConvexDecomp, physics_spec);
+    //</FS:Beq>
 
-	// If we are a mesh and the mesh has a hul decomp (is analysed) then set hasDecomp to true
-	if (volume->isMesh()){
-		mesh_id = volume_params.getSculptID();
-		decomp = gMeshRepo.getDecomposition(mesh_id);
-		if (decomp && !decomp->mHull.empty()){ hasConvexDecomp = TRUE; }
-	}
+    U32 type = physics_spec.getType();
 
-	LLPhysicsShapeBuilderUtil::determinePhysicsShape(physics_params, volume->getScale(), hasConvexDecomp, physics_spec);
-	//</FS:Beq>
+    LLVector3 center(0,0,0);
+    LLVector3 size(0.25f,0.25f,0.25f);
 
-	U32 type = physics_spec.getType();
+    gGL.pushMatrix();
+    gGL.multMatrix(volume->getRelativeXform());
 
-	LLVector3 center(0,0,0);
-	LLVector3 size(0.25f,0.25f,0.25f);
+    if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::USER_MESH)
+    {
+        //<FS:Beq> FIRE-23053 Physics shape display fixes
+        //LLUUID mesh_id = volume->getVolume()->getParams().getSculptID();
+        //LLModel::Decomposition* decomp = gMeshRepo.getDecomposition(mesh_id);
+        //</FS:Beq>
 
-	gGL.pushMatrix();
-	gGL.multMatrix(volume->getRelativeXform());
-		
-	if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::USER_MESH)
-	{
-		//<FS:Beq> FIRE-23053 Physics shape display fixes
-		//LLUUID mesh_id = volume->getVolume()->getParams().getSculptID();
-		//LLModel::Decomposition* decomp = gMeshRepo.getDecomposition(mesh_id);
-		//</FS:Beq>
+        if (decomp)
+        { //render a physics based mesh
 
-		if (decomp)
-		{ //render a physics based mesh
-			
-			gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+            gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
 
-			if (!decomp->mHull.empty())
-			{ //decomposition exists, use that
+            if (!decomp->mHull.empty())
+            { //decomposition exists, use that
 
-				if (decomp->mMesh.empty())
-				{
-					gMeshRepo.buildPhysicsMesh(*decomp);
-				}
+                if (decomp->mMesh.empty())
+                {
+                    gMeshRepo.buildPhysicsMesh(*decomp);
+                }
 
-				for (U32 i = 0; i < decomp->mMesh.size(); ++i)
-				{		
-					render_hull(decomp->mMesh[i], color);
-				}
-			}
-			else if (!decomp->mPhysicsShapeMesh.empty())
-			{ 
-				//decomp has physics mesh, render that mesh
+                for (U32 i = 0; i < decomp->mMesh.size(); ++i)
+                {
+                    render_hull(decomp->mMesh[i], color);
+                }
+            }
+            else if (!decomp->mPhysicsShapeMesh.empty())
+            {
+                //decomp has physics mesh, render that mesh
                 gGL.diffuseColor4fv(color.mV);
 
                 LLVertexBuffer::drawArrays(LLRender::TRIANGLES, decomp->mPhysicsShapeMesh.mPositions);
-			}
-			else
-			{ //no mesh or decomposition, render base hull
-				renderMeshBaseHull(volume, data_mask, color);
-
-				if (decomp->mPhysicsShapeMesh.empty())
-				{
-					//attempt to fetch physics shape mesh if available
-					gMeshRepo.fetchPhysicsShape(mesh_id);
-				}
-			}
-		}
-		else
-		{	
-			gGL.diffuseColor3f(1,1,0);
-			drawBoxOutline(center, size);
-		}
-	}
-	else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::USER_CONVEX ||
-		type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::PRIM_CONVEX)
-	{
-		if (volume->isMesh())
-		{
-			renderMeshBaseHull(volume, data_mask, color);
-		}
-		else
-		{
-			LLVolumeParams volume_params = volume->getVolume()->getParams();
-			S32 detail = get_physics_detail(volume_params, volume->getScale());
-			LLVolume* phys_volume = LLPrimitive::sVolumeManager->refVolume(volume_params, detail);
-
-			if (!phys_volume->mHullPoints)
-			{ //build convex hull
-				std::vector<LLVector3> pos;
-				std::vector<U16> index;
-
-				S32 index_offset = 0;
-
-				for (S32 i = 0; i < phys_volume->getNumVolumeFaces(); ++i)
-				{
-					const LLVolumeFace& face = phys_volume->getVolumeFace(i);
-					if (index_offset + face.mNumVertices > 65535)
-					{
-						continue;
-					}
-
-					for (S32 j = 0; j < face.mNumVertices; ++j)
-					{
-						pos.push_back(LLVector3(face.mPositions[j].getF32ptr()));
-					}
-
-					for (S32 j = 0; j < face.mNumIndices; ++j)
-					{
-						index.push_back(face.mIndices[j]+index_offset);
-					}
-
-					index_offset += face.mNumVertices;
-				}
-
-				if (!pos.empty() && !index.empty() && LLConvexDecomposition::isFunctional())
-				{
-					LLCDMeshData mesh;
-					mesh.mIndexBase = &index[0];
-					mesh.mVertexBase = pos[0].mV;
-					mesh.mNumVertices = pos.size();
-					mesh.mVertexStrideBytes = 12;
-					mesh.mIndexStrideBytes = 6;
-					mesh.mIndexType = LLCDMeshData::INT_16;
-
-					mesh.mNumTriangles = index.size()/3;
-					
-					LLCDMeshData res;
-
-					LLConvexDecomposition::getInstance()->generateSingleHullMeshFromMesh( &mesh, &res );
-
-					//copy res into phys_volume
-					phys_volume->mHullPoints = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*res.mNumVertices);
-					phys_volume->mNumHullPoints = res.mNumVertices;
-
-					S32 idx_size = (res.mNumTriangles*3*2+0xF) & ~0xF;
-					phys_volume->mHullIndices = (U16*) ll_aligned_malloc_16(idx_size);
-					phys_volume->mNumHullIndices = res.mNumTriangles*3;
-
-					const F32* v = res.mVertexBase;
-
-					for (S32 i = 0; i < res.mNumVertices; ++i)
-					{
-						F32* p = (F32*) ((U8*)v+i*res.mVertexStrideBytes);
-						phys_volume->mHullPoints[i].load3(p);
-					}
-
-					if (res.mIndexType == LLCDMeshData::INT_16)
-					{
-						for (S32 i = 0; i < res.mNumTriangles; ++i)
-						{
-							U16* idx = (U16*) (((U8*)res.mIndexBase)+i*res.mIndexStrideBytes);
-
-							phys_volume->mHullIndices[i*3+0] = idx[0];
-							phys_volume->mHullIndices[i*3+1] = idx[1];
-							phys_volume->mHullIndices[i*3+2] = idx[2];
-						}
-					}
-					else
-					{
-						for (S32 i = 0; i < res.mNumTriangles; ++i)
-						{
-							U32* idx = (U32*) (((U8*)res.mIndexBase)+i*res.mIndexStrideBytes);
-
-							phys_volume->mHullIndices[i*3+0] = (U16) idx[0];
-							phys_volume->mHullIndices[i*3+1] = (U16) idx[1];
-							phys_volume->mHullIndices[i*3+2] = (U16) idx[2];
-						}
-					}
-				}
-			}
-
-			if (phys_volume->mHullPoints && phys_volume->mHullIndices && phys_volume->mNumHullPoints > 0 && phys_volume->mNumHullIndices > 0)
-			{
-				//render hull
+            }
+            else
+            { //no mesh or decomposition, render base hull
+                renderMeshBaseHull(volume, data_mask, color);
+
+                if (decomp->mPhysicsShapeMesh.empty())
+                {
+                    //attempt to fetch physics shape mesh if available
+                    gMeshRepo.fetchPhysicsShape(mesh_id);
+                }
+            }
+        }
+        else
+        {
+            gGL.diffuseColor3f(1,1,0);
+            drawBoxOutline(center, size);
+        }
+    }
+    else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::USER_CONVEX ||
+        type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::PRIM_CONVEX)
+    {
+        if (volume->isMesh())
+        {
+            renderMeshBaseHull(volume, data_mask, color);
+        }
+        else
+        {
+            LLVolumeParams volume_params = volume->getVolume()->getParams();
+            S32 detail = get_physics_detail(volume_params, volume->getScale());
+            LLVolume* phys_volume = LLPrimitive::sVolumeManager->refVolume(volume_params, detail);
+
+            if (!phys_volume->mHullPoints)
+            { //build convex hull
+                std::vector<LLVector3> pos;
+                std::vector<U16> index;
+
+                S32 index_offset = 0;
+
+                for (S32 i = 0; i < phys_volume->getNumVolumeFaces(); ++i)
+                {
+                    const LLVolumeFace& face = phys_volume->getVolumeFace(i);
+                    if (index_offset + face.mNumVertices > 65535)
+                    {
+                        continue;
+                    }
+
+                    for (S32 j = 0; j < face.mNumVertices; ++j)
+                    {
+                        pos.push_back(LLVector3(face.mPositions[j].getF32ptr()));
+                    }
+
+                    for (S32 j = 0; j < face.mNumIndices; ++j)
+                    {
+                        index.push_back(face.mIndices[j]+index_offset);
+                    }
+
+                    index_offset += face.mNumVertices;
+                }
+
+                if (!pos.empty() && !index.empty() && LLConvexDecomposition::isFunctional())
+                {
+                    LLCDMeshData mesh;
+                    mesh.mIndexBase = &index[0];
+                    mesh.mVertexBase = pos[0].mV;
+                    mesh.mNumVertices = pos.size();
+                    mesh.mVertexStrideBytes = 12;
+                    mesh.mIndexStrideBytes = 6;
+                    mesh.mIndexType = LLCDMeshData::INT_16;
+
+                    mesh.mNumTriangles = index.size()/3;
+
+                    LLCDMeshData res;
+
+                    LLConvexDecomposition::getInstance()->generateSingleHullMeshFromMesh( &mesh, &res );
+
+                    //copy res into phys_volume
+                    phys_volume->mHullPoints = (LLVector4a*) ll_aligned_malloc_16(sizeof(LLVector4a)*res.mNumVertices);
+                    phys_volume->mNumHullPoints = res.mNumVertices;
+
+                    S32 idx_size = (res.mNumTriangles*3*2+0xF) & ~0xF;
+                    phys_volume->mHullIndices = (U16*) ll_aligned_malloc_16(idx_size);
+                    phys_volume->mNumHullIndices = res.mNumTriangles*3;
+
+                    const F32* v = res.mVertexBase;
+
+                    for (S32 i = 0; i < res.mNumVertices; ++i)
+                    {
+                        F32* p = (F32*) ((U8*)v+i*res.mVertexStrideBytes);
+                        phys_volume->mHullPoints[i].load3(p);
+                    }
+
+                    if (res.mIndexType == LLCDMeshData::INT_16)
+                    {
+                        for (S32 i = 0; i < res.mNumTriangles; ++i)
+                        {
+                            U16* idx = (U16*) (((U8*)res.mIndexBase)+i*res.mIndexStrideBytes);
+
+                            phys_volume->mHullIndices[i*3+0] = idx[0];
+                            phys_volume->mHullIndices[i*3+1] = idx[1];
+                            phys_volume->mHullIndices[i*3+2] = idx[2];
+                        }
+                    }
+                    else
+                    {
+                        for (S32 i = 0; i < res.mNumTriangles; ++i)
+                        {
+                            U32* idx = (U32*) (((U8*)res.mIndexBase)+i*res.mIndexStrideBytes);
+
+                            phys_volume->mHullIndices[i*3+0] = (U16) idx[0];
+                            phys_volume->mHullIndices[i*3+1] = (U16) idx[1];
+                            phys_volume->mHullIndices[i*3+2] = (U16) idx[2];
+                        }
+                    }
+                }
+            }
+
+            if (phys_volume->mHullPoints && phys_volume->mHullIndices && phys_volume->mNumHullPoints > 0 && phys_volume->mNumHullIndices > 0)
+            {
+                //render hull
                 gGL.diffuseColor4fv(color.mV);
 
                 LLVertexBuffer::unbind();
-				LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices);
-			}
-			else
-			{
-				gGL.diffuseColor4f(1,0,1,1);
-				drawBoxOutline(center, size);
-			}
-
-			LLPrimitive::sVolumeManager->unrefVolume(phys_volume);
-		}
-	}
-	else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::BOX)
-	{
+                LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices);
+            }
+            else
+            {
+                gGL.diffuseColor4f(1,0,1,1);
+                drawBoxOutline(center, size);
+            }
+
+            LLPrimitive::sVolumeManager->unrefVolume(phys_volume);
+        }
+    }
+    else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::BOX)
+    {
         if (!wireframe)
         {
             LLVector3 center = physics_spec.getCenter();
@@ -2465,9 +2465,9 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume, bool wireframe
             gGL.diffuseColor4fv(color.mV);
             drawBox(center, scale);
         }
-	}
-	else if	(type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::SPHERE)
-	{
+    }
+    else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::SPHERE)
+    {
         if (!wireframe)
         {
             LLVolumeParams volume_params;
@@ -2482,9 +2482,9 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume, bool wireframe
             pushVerts(sphere);
             LLPrimitive::sVolumeManager->unrefVolume(sphere);
         }
-	}
-	else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::CYLINDER)
-	{
+    }
+    else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::CYLINDER)
+    {
         if (!wireframe)
         {
             LLVolumeParams volume_params;
@@ -2499,241 +2499,241 @@ void renderPhysicsShape(LLDrawable* drawable, LLVOVolume* volume, bool wireframe
             pushVerts(cylinder);
             LLPrimitive::sVolumeManager->unrefVolume(cylinder);
         }
-	}
-	else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::PRIM_MESH)
-	{
-		LLVolumeParams volume_params = volume->getVolume()->getParams();
-		S32 detail = get_physics_detail(volume_params, volume->getScale());
+    }
+    else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::PRIM_MESH)
+    {
+        LLVolumeParams volume_params = volume->getVolume()->getParams();
+        S32 detail = get_physics_detail(volume_params, volume->getScale());
 
-		LLVolume* phys_volume = LLPrimitive::sVolumeManager->refVolume(volume_params, detail);
+        LLVolume* phys_volume = LLPrimitive::sVolumeManager->refVolume(volume_params, detail);
 
         gGL.diffuseColor4fv(color.mV);
-		pushVerts(phys_volume);
+        pushVerts(phys_volume);
 
-		LLPrimitive::sVolumeManager->unrefVolume(phys_volume);
-	}
-	else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::PRIM_CONVEX)
-	{
-		LLVolumeParams volume_params = volume->getVolume()->getParams();
-		S32 detail = get_physics_detail(volume_params, volume->getScale());
+        LLPrimitive::sVolumeManager->unrefVolume(phys_volume);
+    }
+    else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::PRIM_CONVEX)
+    {
+        LLVolumeParams volume_params = volume->getVolume()->getParams();
+        S32 detail = get_physics_detail(volume_params, volume->getScale());
 
-		LLVolume* phys_volume = LLPrimitive::sVolumeManager->refVolume(volume_params, detail);
+        LLVolume* phys_volume = LLPrimitive::sVolumeManager->refVolume(volume_params, detail);
 
-		if (phys_volume->mHullPoints && phys_volume->mHullIndices)
-		{
+        if (phys_volume->mHullPoints && phys_volume->mHullIndices)
+        {
 
             gGL.diffuseColor4fv(color.mV);
 
-			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-			LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices);
-
-		}
-		else
-		{
-			gGL.diffuseColor3f(1,0,1);
-			drawBoxOutline(center, size);
-			gMeshRepo.buildHull(volume_params, detail);
-		}
-		LLPrimitive::sVolumeManager->unrefVolume(phys_volume);
-	}
-	else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::SCULPT)
-	{
-		//TODO: implement sculpted prim physics display
-	}
-	else 
-	{
-		LL_ERRS() << "Unhandled type" << LL_ENDL;
-	}
-
-	gGL.popMatrix();
+            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+            LLVertexBuffer::drawElements(LLRender::TRIANGLES, phys_volume->mHullPoints, NULL, phys_volume->mNumHullIndices, phys_volume->mHullIndices);
+
+        }
+        else
+        {
+            gGL.diffuseColor3f(1,0,1);
+            drawBoxOutline(center, size);
+            gMeshRepo.buildHull(volume_params, detail);
+        }
+        LLPrimitive::sVolumeManager->unrefVolume(phys_volume);
+    }
+    else if (type == LLPhysicsShapeBuilderUtil::PhysicsShapeSpecification::SCULPT)
+    {
+        //TODO: implement sculpted prim physics display
+    }
+    else
+    {
+        LL_ERRS() << "Unhandled type" << LL_ENDL;
+    }
+
+    gGL.popMatrix();
 }
 
 void renderPhysicsShapes(LLSpatialGroup* group, bool wireframe)
 {
-	for (OctreeNode::const_element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
-	{
-		LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
-		if(!drawable)
-	{
-			continue;
-		}
-
-		if (drawable->isSpatialBridge())
-		{
-			LLSpatialBridge* bridge = drawable->asPartition()->asBridge();
-
-			if (bridge)
-			{
-				gGL.pushMatrix();
-				gGL.multMatrix(bridge->mDrawable->getRenderMatrix());
-				bridge->renderPhysicsShapes(wireframe);
-				gGL.popMatrix();
-			}
-		}
-		else
-		{
-			LLVOVolume* volume = drawable->getVOVolume();
-			if (volume && !volume->isAttachment() && volume->getPhysicsShapeType() != LLViewerObject::PHYSICS_SHAPE_NONE )
-			{
-				if (!group->getSpatialPartition()->isBridge())
-				{
-					gGL.pushMatrix();
-					LLVector3 trans = drawable->getRegion()->getOriginAgent();
-					gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);
-					renderPhysicsShape(drawable, volume, wireframe);
-					gGL.popMatrix();
-				}
-				else
-				{
-					renderPhysicsShape(drawable, volume, wireframe);
-				}
-			}
-			else
-			{
-#if 0 
-				LLViewerObject* object = drawable->getVObj();
-				if (object && object->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH)
-				{
-					gGL.pushMatrix();
-					gGL.multMatrix(object->getRegion()->mRenderMatrix);
-					//push face vertices for terrain
-					for (S32 i = 0; i < drawable->getNumFaces(); ++i)
-					{
-						LLFace* face = drawable->getFace(i);
-						if (face)
-						{
-							LLVertexBuffer* buff = face->getVertexBuffer();
-							if (buff)
-							{
-								glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
-								buff->setBuffer();
-								gGL.diffuseColor4f(0.2f, 0.5f, 0.3f, 0.5f);
-								buff->draw(LLRender::TRIANGLES, buff->getNumIndices(), 0);
-									
-								gGL.diffuseColor4f(0.2f, 1.f, 0.3f, 0.75f);
-								glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-								buff->draw(LLRender::TRIANGLES, buff->getNumIndices(), 0);
-							}
-						}
-					}
-					gGL.popMatrix();
-				}
+    for (OctreeNode::const_element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
+    {
+        LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
+        if(!drawable)
+    {
+            continue;
+        }
+
+        if (drawable->isSpatialBridge())
+        {
+            LLSpatialBridge* bridge = drawable->asPartition()->asBridge();
+
+            if (bridge)
+            {
+                gGL.pushMatrix();
+                gGL.multMatrix(bridge->mDrawable->getRenderMatrix());
+                bridge->renderPhysicsShapes(wireframe);
+                gGL.popMatrix();
+            }
+        }
+        else
+        {
+            LLVOVolume* volume = drawable->getVOVolume();
+            if (volume && !volume->isAttachment() && volume->getPhysicsShapeType() != LLViewerObject::PHYSICS_SHAPE_NONE )
+            {
+                if (!group->getSpatialPartition()->isBridge())
+                {
+                    gGL.pushMatrix();
+                    LLVector3 trans = drawable->getRegion()->getOriginAgent();
+                    gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);
+                    renderPhysicsShape(drawable, volume, wireframe);
+                    gGL.popMatrix();
+                }
+                else
+                {
+                    renderPhysicsShape(drawable, volume, wireframe);
+                }
+            }
+            else
+            {
+#if 0
+                LLViewerObject* object = drawable->getVObj();
+                if (object && object->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH)
+                {
+                    gGL.pushMatrix();
+                    gGL.multMatrix(object->getRegion()->mRenderMatrix);
+                    //push face vertices for terrain
+                    for (S32 i = 0; i < drawable->getNumFaces(); ++i)
+                    {
+                        LLFace* face = drawable->getFace(i);
+                        if (face)
+                        {
+                            LLVertexBuffer* buff = face->getVertexBuffer();
+                            if (buff)
+                            {
+                                glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
+                                buff->setBuffer();
+                                gGL.diffuseColor4f(0.2f, 0.5f, 0.3f, 0.5f);
+                                buff->draw(LLRender::TRIANGLES, buff->getNumIndices(), 0);
+
+                                gGL.diffuseColor4f(0.2f, 1.f, 0.3f, 0.75f);
+                                glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+                                buff->draw(LLRender::TRIANGLES, buff->getNumIndices(), 0);
+                            }
+                        }
+                    }
+                    gGL.popMatrix();
+                }
 #endif
-			}
-		}
-	}
+            }
+        }
+    }
 }
 
 void renderTexturePriority(LLDrawable* drawable)
 {
-	for (int face=0; face<drawable->getNumFaces(); ++face)
-	{
-		LLFace *facep = drawable->getFace(face);
-		
-		LLVector4 cold(0,0,0.25f);
-		LLVector4 hot(1,0.25f,0.25f);
-	
-		LLVector4 boost_cold(0,0,0,0);
-		LLVector4 boost_hot(0,1,0,1);
-		
-		LLGLDisable blend(GL_BLEND);
-		
-		//LLViewerTexture* imagep = facep->getTexture();
-		//if (imagep)
-		if (facep)
-		{
-				
-			//F32 vsize = imagep->mMaxVirtualSize;
-			F32 vsize = facep->getPixelArea();
-
-			if (vsize > sCurMaxTexPriority)
-			{
-				sCurMaxTexPriority = vsize;
-			}
-			
-			F32 t = vsize/sLastMaxTexPriority;
-			
-			LLVector4 col = lerp(cold, hot, t);
-			gGL.diffuseColor4fv(col.mV);
-		}
-		//else
-		//{
-		//	gGL.diffuseColor4f(1,0,1,1);
-		//}
-		
-		LLVector4a center;
-		center.setAdd(facep->mExtents[1],facep->mExtents[0]);
-		center.mul(0.5f);
-		LLVector4a size;
-		size.setSub(facep->mExtents[1],facep->mExtents[0]);
-		size.mul(0.5f);
-		size.add(LLVector4a(0.01f));
-		drawBox(center, size);
-		
-		/*S32 boost = imagep->getBoostLevel();
-		if (boost>LLGLTexture::BOOST_NONE)
-		{
-			F32 t = (F32) boost / (F32) (LLGLTexture::BOOST_MAX_LEVEL-1);
-			LLVector4 col = lerp(boost_cold, boost_hot, t);
-			LLGLEnable blend_on(GL_BLEND);
-			gGL.blendFunc(GL_SRC_ALPHA, GL_ONE);
-			gGL.diffuseColor4fv(col.mV);
-			drawBox(center, size);
-			gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-		}*/
-	}
+    for (int face=0; face<drawable->getNumFaces(); ++face)
+    {
+        LLFace *facep = drawable->getFace(face);
+
+        LLVector4 cold(0,0,0.25f);
+        LLVector4 hot(1,0.25f,0.25f);
+
+        LLVector4 boost_cold(0,0,0,0);
+        LLVector4 boost_hot(0,1,0,1);
+
+        LLGLDisable blend(GL_BLEND);
+
+        //LLViewerTexture* imagep = facep->getTexture();
+        //if (imagep)
+        if (facep)
+        {
+
+            //F32 vsize = imagep->mMaxVirtualSize;
+            F32 vsize = facep->getPixelArea();
+
+            if (vsize > sCurMaxTexPriority)
+            {
+                sCurMaxTexPriority = vsize;
+            }
+
+            F32 t = vsize/sLastMaxTexPriority;
+
+            LLVector4 col = lerp(cold, hot, t);
+            gGL.diffuseColor4fv(col.mV);
+        }
+        //else
+        //{
+        //  gGL.diffuseColor4f(1,0,1,1);
+        //}
+
+        LLVector4a center;
+        center.setAdd(facep->mExtents[1],facep->mExtents[0]);
+        center.mul(0.5f);
+        LLVector4a size;
+        size.setSub(facep->mExtents[1],facep->mExtents[0]);
+        size.mul(0.5f);
+        size.add(LLVector4a(0.01f));
+        drawBox(center, size);
+
+        /*S32 boost = imagep->getBoostLevel();
+        if (boost>LLGLTexture::BOOST_NONE)
+        {
+            F32 t = (F32) boost / (F32) (LLGLTexture::BOOST_MAX_LEVEL-1);
+            LLVector4 col = lerp(boost_cold, boost_hot, t);
+            LLGLEnable blend_on(GL_BLEND);
+            gGL.blendFunc(GL_SRC_ALPHA, GL_ONE);
+            gGL.diffuseColor4fv(col.mV);
+            drawBox(center, size);
+            gGL.blendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+        }*/
+    }
 }
 
 void renderPoints(LLDrawable* drawablep)
 {
-	LLGLDepthTest depth(GL_FALSE, GL_FALSE);
-	if (drawablep->getNumFaces())
-	{
-		gGL.begin(LLRender::POINTS);
-		gGL.diffuseColor3f(1,1,1);
-		for (S32 i = 0; i < drawablep->getNumFaces(); i++)
-		{
-			LLFace * face = drawablep->getFace(i);
-			if (face)
-			{
-				gGL.vertex3fv(face->mCenterLocal.mV);
-			}
-		}
-		gGL.end();
-	}
+    LLGLDepthTest depth(GL_FALSE, GL_FALSE);
+    if (drawablep->getNumFaces())
+    {
+        gGL.begin(LLRender::POINTS);
+        gGL.diffuseColor3f(1,1,1);
+        for (S32 i = 0; i < drawablep->getNumFaces(); i++)
+        {
+            LLFace * face = drawablep->getFace(i);
+            if (face)
+            {
+                gGL.vertex3fv(face->mCenterLocal.mV);
+            }
+        }
+        gGL.end();
+    }
 }
 
 void renderTextureAnim(LLDrawInfo* params)
 {
-	if (!params->mTextureMatrix)
-	{
-		return;
-	}
-	
-	LLGLEnable blend(GL_BLEND);
-	gGL.diffuseColor4f(1,1,0,0.5f);
-	pushVerts(params);
+    if (!params->mTextureMatrix)
+    {
+        return;
+    }
+
+    LLGLEnable blend(GL_BLEND);
+    gGL.diffuseColor4f(1,1,0,0.5f);
+    pushVerts(params);
 }
 
 void renderBatchSize(LLDrawInfo* params)
 {
-	LLGLEnable offset(GL_POLYGON_OFFSET_FILL);
-	glPolygonOffset(-1.f, 1.f);
+    LLGLEnable offset(GL_POLYGON_OFFSET_FILL);
+    glPolygonOffset(-1.f, 1.f);
     LLGLSLShader* old_shader = LLGLSLShader::sCurBoundShaderPtr;
     bool bind = false;
     if (params->mAvatar)
-    { 
+    {
         gGL.pushMatrix();
         gGL.loadMatrix(gGLModelView);
         bind = true;
         old_shader->mRiggedVariant->bind();
         LLRenderPass::uploadMatrixPalette(*params);
     }
-	
-    
+
+
     gGL.diffuseColor4ubv(params->getDebugColor().mV);
-	pushVerts(params);
+    pushVerts(params);
 
     if (bind)
     {
@@ -2744,220 +2744,220 @@ void renderBatchSize(LLDrawInfo* params)
 
 void renderTexelDensity(LLDrawable* drawable)
 {
-	if (LLViewerTexture::sDebugTexelsMode == LLViewerTexture::DEBUG_TEXELS_OFF
-		|| LLViewerTexture::sCheckerBoardImagep.isNull())
-	{
-		return;
-	}
-
-	LLGLEnable _(GL_BLEND);
-	
-	LLMatrix4 checkerboard_matrix;
-	S32 discard_level = -1;
-
-	for (S32 f = 0; f < drawable->getNumFaces(); f++)
-	{
-		LLFace* facep = drawable->getFace(f);
-		LLVertexBuffer* buffer = facep->getVertexBuffer();
-		LLViewerTexture* texturep = facep->getTexture();
-
-		if (texturep == NULL) continue;
-
-		switch(LLViewerTexture::sDebugTexelsMode)
-		{
-		case LLViewerTexture::DEBUG_TEXELS_CURRENT:
-			discard_level = -1;
-			break;
-		case LLViewerTexture::DEBUG_TEXELS_DESIRED:
-			{
-				LLViewerFetchedTexture* fetched_texturep = dynamic_cast<LLViewerFetchedTexture*>(texturep);
-				discard_level = fetched_texturep ? fetched_texturep->getDesiredDiscardLevel() : -1;
-				break;
-			}
-		default:
-		case LLViewerTexture::DEBUG_TEXELS_FULL:
-			discard_level = 0;
-			break;
-		}
-
-		checkerboard_matrix.initScale(LLVector3(texturep->getWidth(discard_level) / 8, texturep->getHeight(discard_level) / 8, 1.f));
-
-		gGL.getTexUnit(0)->bind(LLViewerTexture::sCheckerBoardImagep, TRUE);
-		gGL.matrixMode(LLRender::MM_TEXTURE);
-		gGL.loadMatrix((GLfloat*)&checkerboard_matrix.mMatrix);
-
-		if (buffer && (facep->getGeomCount() >= 3))
-		{
-			buffer->setBuffer();
-			U16 start = facep->getGeomStart();
-			U16 end = start + facep->getGeomCount()-1;
-			U32 count = facep->getIndicesCount();
-			U16 offset = facep->getIndicesStart();
-			buffer->drawRange(LLRender::TRIANGLES, start, end, count, offset);
-		}
-
-		gGL.loadIdentity();
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-	}
-
-	//S32 num_textures = llmax(1, (S32)params->mTextureList.size());
-
-	//for (S32 i = 0; i < num_textures; i++)
-	//{
-	//	LLViewerTexture* texturep = params->mTextureList.empty() ? params->mTexture.get() : params->mTextureList[i].get();
-	//	if (texturep == NULL) continue;
-
-	//	LLMatrix4 checkboard_matrix;
-	//	S32 discard_level = -1;
-	//	switch(LLViewerTexture::sDebugTexelsMode)
-	//	{
-	//	case LLViewerTexture::DEBUG_TEXELS_CURRENT:
-	//		discard_level = -1;
-	//		break;
-	//	case LLViewerTexture::DEBUG_TEXELS_DESIRED:
-	//		{
-	//			LLViewerFetchedTexture* fetched_texturep = dynamic_cast<LLViewerFetchedTexture*>(texturep);
-	//			discard_level = fetched_texturep ? fetched_texturep->getDesiredDiscardLevel() : -1;
-	//			break;
-	//		}
-	//	default:
-	//	case LLViewerTexture::DEBUG_TEXELS_FULL:
-	//		discard_level = 0;
-	//		break;
-	//	}
-
-	//	checkboard_matrix.initScale(LLVector3(texturep->getWidth(discard_level) / 8, texturep->getHeight(discard_level) / 8, 1.f));
-	//	gGL.getTexUnit(i)->activate();
-
-	//	glMatrixMode(GL_TEXTURE);
-	//	glPushMatrix();
-	//	glLoadIdentity();
-	//	//gGL.matrixMode(LLRender::MM_TEXTURE);
-	//	glLoadMatrixf((GLfloat*) checkboard_matrix.mMatrix);
-
-	//	gGL.getTexUnit(i)->bind(LLViewerTexture::sCheckerBoardImagep, TRUE);
-
-	//	pushVerts(params, LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL );
-
-	//	glPopMatrix();
-	//	glMatrixMode(GL_MODELVIEW);
-	//	//gGL.matrixMode(LLRender::MM_MODELVIEW);
-	//}
+    if (LLViewerTexture::sDebugTexelsMode == LLViewerTexture::DEBUG_TEXELS_OFF
+        || LLViewerTexture::sCheckerBoardImagep.isNull())
+    {
+        return;
+    }
+
+    LLGLEnable _(GL_BLEND);
+
+    LLMatrix4 checkerboard_matrix;
+    S32 discard_level = -1;
+
+    for (S32 f = 0; f < drawable->getNumFaces(); f++)
+    {
+        LLFace* facep = drawable->getFace(f);
+        LLVertexBuffer* buffer = facep->getVertexBuffer();
+        LLViewerTexture* texturep = facep->getTexture();
+
+        if (texturep == NULL) continue;
+
+        switch(LLViewerTexture::sDebugTexelsMode)
+        {
+        case LLViewerTexture::DEBUG_TEXELS_CURRENT:
+            discard_level = -1;
+            break;
+        case LLViewerTexture::DEBUG_TEXELS_DESIRED:
+            {
+                LLViewerFetchedTexture* fetched_texturep = dynamic_cast<LLViewerFetchedTexture*>(texturep);
+                discard_level = fetched_texturep ? fetched_texturep->getDesiredDiscardLevel() : -1;
+                break;
+            }
+        default:
+        case LLViewerTexture::DEBUG_TEXELS_FULL:
+            discard_level = 0;
+            break;
+        }
+
+        checkerboard_matrix.initScale(LLVector3(texturep->getWidth(discard_level) / 8, texturep->getHeight(discard_level) / 8, 1.f));
+
+        gGL.getTexUnit(0)->bind(LLViewerTexture::sCheckerBoardImagep, TRUE);
+        gGL.matrixMode(LLRender::MM_TEXTURE);
+        gGL.loadMatrix((GLfloat*)&checkerboard_matrix.mMatrix);
+
+        if (buffer && (facep->getGeomCount() >= 3))
+        {
+            buffer->setBuffer();
+            U16 start = facep->getGeomStart();
+            U16 end = start + facep->getGeomCount()-1;
+            U32 count = facep->getIndicesCount();
+            U16 offset = facep->getIndicesStart();
+            buffer->drawRange(LLRender::TRIANGLES, start, end, count, offset);
+        }
+
+        gGL.loadIdentity();
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+    }
+
+    //S32 num_textures = llmax(1, (S32)params->mTextureList.size());
+
+    //for (S32 i = 0; i < num_textures; i++)
+    //{
+    //  LLViewerTexture* texturep = params->mTextureList.empty() ? params->mTexture.get() : params->mTextureList[i].get();
+    //  if (texturep == NULL) continue;
+
+    //  LLMatrix4 checkboard_matrix;
+    //  S32 discard_level = -1;
+    //  switch(LLViewerTexture::sDebugTexelsMode)
+    //  {
+    //  case LLViewerTexture::DEBUG_TEXELS_CURRENT:
+    //      discard_level = -1;
+    //      break;
+    //  case LLViewerTexture::DEBUG_TEXELS_DESIRED:
+    //      {
+    //          LLViewerFetchedTexture* fetched_texturep = dynamic_cast<LLViewerFetchedTexture*>(texturep);
+    //          discard_level = fetched_texturep ? fetched_texturep->getDesiredDiscardLevel() : -1;
+    //          break;
+    //      }
+    //  default:
+    //  case LLViewerTexture::DEBUG_TEXELS_FULL:
+    //      discard_level = 0;
+    //      break;
+    //  }
+
+    //  checkboard_matrix.initScale(LLVector3(texturep->getWidth(discard_level) / 8, texturep->getHeight(discard_level) / 8, 1.f));
+    //  gGL.getTexUnit(i)->activate();
+
+    //  glMatrixMode(GL_TEXTURE);
+    //  glPushMatrix();
+    //  glLoadIdentity();
+    //  //gGL.matrixMode(LLRender::MM_TEXTURE);
+    //  glLoadMatrixf((GLfloat*) checkboard_matrix.mMatrix);
+
+    //  gGL.getTexUnit(i)->bind(LLViewerTexture::sCheckerBoardImagep, TRUE);
+
+    //  pushVerts(params, LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_NORMAL );
+
+    //  glPopMatrix();
+    //  glMatrixMode(GL_MODELVIEW);
+    //  //gGL.matrixMode(LLRender::MM_MODELVIEW);
+    //}
 }
 
 
 void renderLights(LLDrawable* drawablep)
 {
-	if (!drawablep->isLight())
-	{
-		return;
-	}
-
-	if (drawablep->getNumFaces())
-	{
-		LLGLEnable blend(GL_BLEND);
-		gGL.diffuseColor4f(0,1,1,0.5f);
-
-		for (S32 i = 0; i < drawablep->getNumFaces(); i++)
-		{
-			LLFace * face = drawablep->getFace(i);
-			if (face)
-			{
-				pushVerts(face);
-			}
-		}
-
-		const LLVector4a* ext = drawablep->getSpatialExtents();
-
-		LLVector4a pos;
-		pos.setAdd(ext[0], ext[1]);
-		pos.mul(0.5f);
-		LLVector4a size;
-		size.setSub(ext[1], ext[0]);
-		size.mul(0.5f);
-
-		{
-			LLGLDepthTest depth(GL_FALSE, GL_TRUE);
-			gGL.diffuseColor4f(1,1,1,1);
-			drawBoxOutline(pos, size);
-		}
-
-		gGL.diffuseColor4f(1,1,0,1);
-		F32 rad = drawablep->getVOVolume()->getLightRadius();
-		drawBoxOutline(pos, LLVector4a(rad));
-	}
+    if (!drawablep->isLight())
+    {
+        return;
+    }
+
+    if (drawablep->getNumFaces())
+    {
+        LLGLEnable blend(GL_BLEND);
+        gGL.diffuseColor4f(0,1,1,0.5f);
+
+        for (S32 i = 0; i < drawablep->getNumFaces(); i++)
+        {
+            LLFace * face = drawablep->getFace(i);
+            if (face)
+            {
+                pushVerts(face);
+            }
+        }
+
+        const LLVector4a* ext = drawablep->getSpatialExtents();
+
+        LLVector4a pos;
+        pos.setAdd(ext[0], ext[1]);
+        pos.mul(0.5f);
+        LLVector4a size;
+        size.setSub(ext[1], ext[0]);
+        size.mul(0.5f);
+
+        {
+            LLGLDepthTest depth(GL_FALSE, GL_TRUE);
+            gGL.diffuseColor4f(1,1,1,1);
+            drawBoxOutline(pos, size);
+        }
+
+        gGL.diffuseColor4f(1,1,0,1);
+        F32 rad = drawablep->getVOVolume()->getLightRadius();
+        drawBoxOutline(pos, LLVector4a(rad));
+    }
 }
 
 class LLRenderOctreeRaycast : public LLOctreeTriangleRayIntersect
 {
 public:
-	LLRenderOctreeRaycast(const LLVector4a& start, const LLVector4a& dir, F32* closest_t)
-		: LLOctreeTriangleRayIntersect(start, dir, nullptr, closest_t, NULL, NULL, NULL, NULL)
-	{
+    LLRenderOctreeRaycast(const LLVector4a& start, const LLVector4a& dir, F32* closest_t)
+        : LLOctreeTriangleRayIntersect(start, dir, nullptr, closest_t, NULL, NULL, NULL, NULL)
+    {
 
-	}
+    }
 
     void visit(const LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>* branch)
-	{
-		LLVolumeOctreeListener* vl = (LLVolumeOctreeListener*) branch->getListener(0);
-
-		LLVector3 center, size;
-		
-		if (branch->isEmpty())
-		{
-			gGL.diffuseColor3f(1.f,0.2f,0.f);
-			center.set(branch->getCenter().getF32ptr());
-			size.set(branch->getSize().getF32ptr());
-		}
-		else
-		{
-			gGL.diffuseColor3f(0.75f, 1.f, 0.f);
-			center.set(vl->mBounds[0].getF32ptr());
-			size.set(vl->mBounds[1].getF32ptr());
-		}
-
-		drawBoxOutline(center, size);
-		
-		for (U32 i = 0; i < 2; i++)
-		{
-			LLGLDepthTest depth(GL_TRUE, GL_FALSE, i == 1 ? GL_LEQUAL : GL_GREATER);
-
-			if (i == 1)
-			{
-				gGL.diffuseColor4f(0,1,1,0.5f);
-			}
-			else
-			{
-				gGL.diffuseColor4f(0,0.5f,0.5f, 0.25f);
-				drawBoxOutline(center, size);
-			}
-			
-			if (i == 1)
-			{
-				gGL.flush();
-				gGL.setLineWidth(3.f);
-			}
-
-			gGL.begin(LLRender::TRIANGLES);
+    {
+        LLVolumeOctreeListener* vl = (LLVolumeOctreeListener*) branch->getListener(0);
+
+        LLVector3 center, size;
+
+        if (branch->isEmpty())
+        {
+            gGL.diffuseColor3f(1.f,0.2f,0.f);
+            center.set(branch->getCenter().getF32ptr());
+            size.set(branch->getSize().getF32ptr());
+        }
+        else
+        {
+            gGL.diffuseColor3f(0.75f, 1.f, 0.f);
+            center.set(vl->mBounds[0].getF32ptr());
+            size.set(vl->mBounds[1].getF32ptr());
+        }
+
+        drawBoxOutline(center, size);
+
+        for (U32 i = 0; i < 2; i++)
+        {
+            LLGLDepthTest depth(GL_TRUE, GL_FALSE, i == 1 ? GL_LEQUAL : GL_GREATER);
+
+            if (i == 1)
+            {
+                gGL.diffuseColor4f(0,1,1,0.5f);
+            }
+            else
+            {
+                gGL.diffuseColor4f(0,0.5f,0.5f, 0.25f);
+                drawBoxOutline(center, size);
+            }
+
+            if (i == 1)
+            {
+                gGL.flush();
+                gGL.setLineWidth(3.f);
+            }
+
+            gGL.begin(LLRender::TRIANGLES);
             for (LLOctreeNode<LLVolumeTriangle, LLVolumeTriangle*>::const_element_iter iter = branch->getDataBegin(), end = branch->getDataEnd();
-					iter != end;
-					++iter)
-			{
-				const LLVolumeTriangle* tri = *iter;
-				
-				gGL.vertex3fv(tri->mV[0]->getF32ptr());
-				gGL.vertex3fv(tri->mV[1]->getF32ptr());
-				gGL.vertex3fv(tri->mV[2]->getF32ptr());
-			}	
-			gGL.end();
-
-			if (i == 1)
-			{
-				gGL.flush();
-				gGL.setLineWidth(1.f);
-			}
-		}
-	}
+                    iter != end;
+                    ++iter)
+            {
+                const LLVolumeTriangle* tri = *iter;
+
+                gGL.vertex3fv(tri->mV[0]->getF32ptr());
+                gGL.vertex3fv(tri->mV[1]->getF32ptr());
+                gGL.vertex3fv(tri->mV[2]->getF32ptr());
+            }
+            gGL.end();
+
+            if (i == 1)
+            {
+                gGL.flush();
+                gGL.setLineWidth(1.f);
+            }
+        }
+    }
 };
 
 void renderOctreeRaycast(const LLVector4a& start, const LLVector4a& end, const LLVolumeOctree* octree)
@@ -2969,161 +2969,161 @@ void renderOctreeRaycast(const LLVector4a& start, const LLVector4a& end, const L
 
 void renderRaycast(LLDrawable* drawablep)
 {
-	if (drawablep->getNumFaces())
-	{
-		LLGLEnable blend(GL_BLEND);
-		gGL.diffuseColor4f(0,1,1,0.5f);
-
-		LLVOVolume* vobj = drawablep->getVOVolume();
-		if (vobj && !vobj->isDead())
-		{
-			//glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-			//pushVerts(drawablep->getFace(gDebugRaycastFaceHit), LLVertexBuffer::MAP_VERTEX);
-			//glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
-			LLVolume* volume = vobj->getVolume();
-
-			bool transform = true;
-			if (drawablep->isState(LLDrawable::RIGGED))
-			{
-				volume = vobj->getRiggedVolume();
-				transform = false;
-			}
-
-			if (volume)
-			{
-				LLVector3 trans = drawablep->getRegion()->getOriginAgent();
-				
-				for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i)
-				{
-					const LLVolumeFace& face = volume->getVolumeFace(i);
-					
-					gGL.pushMatrix();
-					gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);					
-					gGL.multMatrix(vobj->getRelativeXform());
-
-					LLVector4a start, end;
-					if (transform)
-					{
-						LLVector3 v_start(gDebugRaycastStart.getF32ptr());
-						LLVector3 v_end(gDebugRaycastEnd.getF32ptr());
-
-						v_start = vobj->agentPositionToVolume(v_start);
-						v_end = vobj->agentPositionToVolume(v_end);
-
-						start.load3(v_start.mV);
-						end.load3(v_end.mV);
-					}
-					else
-					{
-						start = gDebugRaycastStart;
-						end = gDebugRaycastEnd;
-					}
-
-					LLVector4a dir;
-					dir.setSub(end, start);
-
-					gGL.flush();
-					glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
-					{
-						//render face positions
-						//gGL.diffuseColor4f(0.f, 1.f, 1.f, 0.5f);
-						//LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mPositions, NULL, face.mNumIndices, face.mIndices);
-					}
-					
-					if (!volume->isUnique())
-					{
+    if (drawablep->getNumFaces())
+    {
+        LLGLEnable blend(GL_BLEND);
+        gGL.diffuseColor4f(0,1,1,0.5f);
+
+        LLVOVolume* vobj = drawablep->getVOVolume();
+        if (vobj && !vobj->isDead())
+        {
+            //glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+            //pushVerts(drawablep->getFace(gDebugRaycastFaceHit), LLVertexBuffer::MAP_VERTEX);
+            //glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+
+            LLVolume* volume = vobj->getVolume();
+
+            bool transform = true;
+            if (drawablep->isState(LLDrawable::RIGGED))
+            {
+                volume = vobj->getRiggedVolume();
+                transform = false;
+            }
+
+            if (volume)
+            {
+                LLVector3 trans = drawablep->getRegion()->getOriginAgent();
+
+                for (S32 i = 0; i < volume->getNumVolumeFaces(); ++i)
+                {
+                    const LLVolumeFace& face = volume->getVolumeFace(i);
+
+                    gGL.pushMatrix();
+                    gGL.translatef(trans.mV[0], trans.mV[1], trans.mV[2]);
+                    gGL.multMatrix(vobj->getRelativeXform());
+
+                    LLVector4a start, end;
+                    if (transform)
+                    {
+                        LLVector3 v_start(gDebugRaycastStart.getF32ptr());
+                        LLVector3 v_end(gDebugRaycastEnd.getF32ptr());
+
+                        v_start = vobj->agentPositionToVolume(v_start);
+                        v_end = vobj->agentPositionToVolume(v_end);
+
+                        start.load3(v_start.mV);
+                        end.load3(v_end.mV);
+                    }
+                    else
+                    {
+                        start = gDebugRaycastStart;
+                        end = gDebugRaycastEnd;
+                    }
+
+                    LLVector4a dir;
+                    dir.setSub(end, start);
+
+                    gGL.flush();
+                    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+
+                    {
+                        //render face positions
+                        //gGL.diffuseColor4f(0.f, 1.f, 1.f, 0.5f);
+                        //LLVertexBuffer::drawElements(LLRender::TRIANGLES, face.mPositions, NULL, face.mNumIndices, face.mIndices);
+                    }
+
+                    if (!volume->isUnique())
+                    {
                         if (!face.getOctree())
-						{
-							((LLVolumeFace*) &face)->createOctree(); 
-						}
+                        {
+                            ((LLVolumeFace*) &face)->createOctree();
+                        }
 
                         renderOctreeRaycast(start, end, face.getOctree());
-					}
-
-					gGL.popMatrix();		
-					glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-				}
-			}
-		}
-		else if (drawablep->isAvatar())
-		{
-			if (drawablep->getVObj() == gDebugRaycastObject)
-			{
-				LLGLDepthTest depth(GL_FALSE);
-				LLVOAvatar* av = (LLVOAvatar*) drawablep->getVObj().get();
-				av->renderCollisionVolumes();
-			}
-		}
-
-		if (drawablep->getVObj() == gDebugRaycastObject)
-		{
-			// draw intersection point
-			gGL.pushMatrix();
-			gGL.loadMatrix(gGLModelView);
-			LLVector3 translate(gDebugRaycastIntersection.getF32ptr());
-			gGL.translatef(translate.mV[0], translate.mV[1], translate.mV[2]);
-			LLCoordFrame orient;
-			LLVector4a debug_binormal;
-			
-			debug_binormal.setCross3(gDebugRaycastNormal, gDebugRaycastTangent);
-			debug_binormal.mul(gDebugRaycastTangent.getF32ptr()[3]);
-
-			LLVector3 normal(gDebugRaycastNormal.getF32ptr());
-			LLVector3 binormal(debug_binormal.getF32ptr());
-						
-			orient.lookDir(normal, binormal);
-			LLMatrix4 rotation;
-			orient.getRotMatrixToParent(rotation);
-			gGL.multMatrix((float*)rotation.mMatrix);
-			
-			gGL.diffuseColor4f(1,0,0,0.5f);
-			drawBox(LLVector3(0, 0, 0), LLVector3(0.1f, 0.022f, 0.022f));
-			gGL.diffuseColor4f(0,1,0,0.5f);
-			drawBox(LLVector3(0, 0, 0), LLVector3(0.021f, 0.1f, 0.021f));
-			gGL.diffuseColor4f(0,0,1,0.5f);
-			drawBox(LLVector3(0, 0, 0), LLVector3(0.02f, 0.02f, 0.1f));
-			gGL.popMatrix();
-
-			// draw bounding box of prim
-			const LLVector4a* ext = drawablep->getSpatialExtents();
-
-			LLVector4a pos;
-			pos.setAdd(ext[0], ext[1]);
-			pos.mul(0.5f);
-			LLVector4a size;
-			size.setSub(ext[1], ext[0]);
-			size.mul(0.5f);
-
-			LLGLDepthTest depth(GL_FALSE, GL_TRUE);
-			gGL.diffuseColor4f(0,0.5f,0.5f,1);
-			drawBoxOutline(pos, size);		
-		}
-	}
+                    }
+
+                    gGL.popMatrix();
+                    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+                }
+            }
+        }
+        else if (drawablep->isAvatar())
+        {
+            if (drawablep->getVObj() == gDebugRaycastObject)
+            {
+                LLGLDepthTest depth(GL_FALSE);
+                LLVOAvatar* av = (LLVOAvatar*) drawablep->getVObj().get();
+                av->renderCollisionVolumes();
+            }
+        }
+
+        if (drawablep->getVObj() == gDebugRaycastObject)
+        {
+            // draw intersection point
+            gGL.pushMatrix();
+            gGL.loadMatrix(gGLModelView);
+            LLVector3 translate(gDebugRaycastIntersection.getF32ptr());
+            gGL.translatef(translate.mV[0], translate.mV[1], translate.mV[2]);
+            LLCoordFrame orient;
+            LLVector4a debug_binormal;
+
+            debug_binormal.setCross3(gDebugRaycastNormal, gDebugRaycastTangent);
+            debug_binormal.mul(gDebugRaycastTangent.getF32ptr()[3]);
+
+            LLVector3 normal(gDebugRaycastNormal.getF32ptr());
+            LLVector3 binormal(debug_binormal.getF32ptr());
+
+            orient.lookDir(normal, binormal);
+            LLMatrix4 rotation;
+            orient.getRotMatrixToParent(rotation);
+            gGL.multMatrix((float*)rotation.mMatrix);
+
+            gGL.diffuseColor4f(1,0,0,0.5f);
+            drawBox(LLVector3(0, 0, 0), LLVector3(0.1f, 0.022f, 0.022f));
+            gGL.diffuseColor4f(0,1,0,0.5f);
+            drawBox(LLVector3(0, 0, 0), LLVector3(0.021f, 0.1f, 0.021f));
+            gGL.diffuseColor4f(0,0,1,0.5f);
+            drawBox(LLVector3(0, 0, 0), LLVector3(0.02f, 0.02f, 0.1f));
+            gGL.popMatrix();
+
+            // draw bounding box of prim
+            const LLVector4a* ext = drawablep->getSpatialExtents();
+
+            LLVector4a pos;
+            pos.setAdd(ext[0], ext[1]);
+            pos.mul(0.5f);
+            LLVector4a size;
+            size.setSub(ext[1], ext[0]);
+            size.mul(0.5f);
+
+            LLGLDepthTest depth(GL_FALSE, GL_TRUE);
+            gGL.diffuseColor4f(0,0.5f,0.5f,1);
+            drawBoxOutline(pos, size);
+        }
+    }
 }
 
 
 void renderAvatarCollisionVolumes(LLVOAvatar* avatar)
 {
-	avatar->renderCollisionVolumes();
+    avatar->renderCollisionVolumes();
 }
 
 void renderAvatarBones(LLVOAvatar* avatar)
 {
-	avatar->renderBones();
+    avatar->renderBones();
 }
 
 void renderAgentTarget(LLVOAvatar* avatar)
 {
-	// render these for self only (why, i don't know)
-	if (avatar->isSelf())
-	{
-		renderCrossHairs(avatar->getPositionAgent(), 0.2f, LLColor4(1, 0, 0, 0.8f));
-		renderCrossHairs(avatar->mDrawable->getPositionAgent(), 0.2f, LLColor4(0, 1, 0, 0.8f));
-		renderCrossHairs(avatar->mRoot->getWorldPosition(), 0.2f, LLColor4(1, 1, 1, 0.8f));
-		renderCrossHairs(avatar->mPelvisp->getWorldPosition(), 0.2f, LLColor4(0, 0, 1, 0.8f));
-	}
+    // render these for self only (why, i don't know)
+    if (avatar->isSelf())
+    {
+        renderCrossHairs(avatar->getPositionAgent(), 0.2f, LLColor4(1, 0, 0, 0.8f));
+        renderCrossHairs(avatar->mDrawable->getPositionAgent(), 0.2f, LLColor4(0, 1, 0, 0.8f));
+        renderCrossHairs(avatar->mRoot->getWorldPosition(), 0.2f, LLColor4(1, 1, 1, 0.8f));
+        renderCrossHairs(avatar->mPelvisp->getWorldPosition(), 0.2f, LLColor4(0, 0, 1, 0.8f));
+    }
 }
 
 static void setTextureAreaDebugText(LLDrawable* drawablep)
@@ -3165,686 +3165,686 @@ static void setTextureAreaDebugText(LLDrawable* drawablep)
                         {
                             str << llformat("\nS - %.2f", sqrtf(imagep->getMaxVirtualSize()));
                         }
-
-                        str << "\n\n";
+
+                        str << "\n\n";
+                    }
+
+                    vobjp->setDebugText(str.str());
+                }
+            }
+        }
+        else
+        {
+            vobjp->setDebugText(".");
+        }
+    }
+}
+
+class LLOctreeRenderNonOccluded : public OctreeTraveler
+{
+public:
+    LLCamera* mCamera;
+    LLOctreeRenderNonOccluded(LLCamera* camera): mCamera(camera) {}
+
+    virtual void traverse(const OctreeNode* node)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
+
+        const LLVector4a* bounds = group->getBounds();
+        if (!mCamera || mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1]))
+        {
+            node->accept(this);
+            stop_glerror();
+
+            for (U32 i = 0; i < node->getChildCount(); i++)
+            {
+                traverse(node->getChild(i));
+                stop_glerror();
+            }
+
+            //draw tight fit bounding boxes for spatial group
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCTREE))
+            {
+                group->rebuildGeom();
+                group->rebuildMesh();
+
+                renderOctree(group);
+                stop_glerror();
+            }
+        }
+    }
+
+    virtual void visit(const OctreeNode* branch)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) branch->getListener(0);
+        const LLVector4a* bounds = group->getBounds();
+        if (group->hasState(LLSpatialGroup::GEOM_DIRTY) || (mCamera && !mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1])))
+        {
+            return;
+        }
+
+        group->rebuildGeom();
+        group->rebuildMesh();
+
+        if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_BBOXES))
+        {
+            if (!group->isEmpty())
+            {
+                gGL.diffuseColor3f(0,0,1);
+                const LLVector4a* obj_bounds = group->getObjectBounds();
+                drawBoxOutline(obj_bounds[0], obj_bounds[1]);
+            }
+        }
+
+        for (OctreeNode::const_element_iter i = branch->getDataBegin(), i_end = branch->getDataEnd(); i != i_end; ++i)
+        {
+            LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
+            if(!drawable || drawable->isDead())
+        {
+                continue;
+            }
+
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_BBOXES))
+            {
+                renderBoundingBox(drawable);
+            }
+
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_NORMALS))
+            {
+                renderNormals(drawable);
+            }
+
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_AREA))
+            {
+                setTextureAreaDebugText(drawable);
+            }
+
+            /*if (drawable->getVOVolume() && gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY))
+            {
+                renderTexturePriority(drawable);
+            }*/
+
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_POINTS))
+            {
+                renderPoints(drawable);
+            }
+
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_LIGHTS))
+            {
+                renderLights(drawable);
+            }
+
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST))
+            {
+                renderRaycast(drawable);
+            }
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_UPDATE_TYPE))
+            {
+                renderUpdateType(drawable);
+            }
+            if(gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY))
+            {
+                renderTexelDensity(drawable);
+            }
+
+            LLViewerObject* vobjp = drawable->getVObj();
+            LLVOAvatar* avatar = vobjp ? vobjp->asAvatar() : nullptr;
+            if (avatar)
+            {
+                if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_AVATAR_VOLUME))
+                {
+                    renderAvatarCollisionVolumes(avatar);
+                }
+
+                if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_AVATAR_JOINTS))
+                {
+                    renderAvatarBones(avatar);
+                }
+
+                if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_AGENT_TARGET))
+                {
+                    renderAgentTarget(avatar);
+                }
+            }
+
+#if 0
+            if (gDebugGL)
+            {
+                for (U32 i = 0; i < drawable->getNumFaces(); ++i)
+                {
+                    LLFace* facep = drawable->getFace(i);
+                    if (facep)
+                    {
+                        U8 index = facep->getTextureIndex();
+                        if (facep->mDrawInfo)
+                        {
+                            if (index < FACE_DO_NOT_BATCH_TEXTURES)
+                            {
+                                if (facep->mDrawInfo->mTextureList.size() <= index)
+                                {
+                                    LL_ERRS() << "Face texture index out of bounds." << LL_ENDL;
+                                }
+                                else if (facep->mDrawInfo->mTextureList[index] != facep->getTexture())
+                                {
+                                    LL_ERRS() << "Face texture index incorrect." << LL_ENDL;
+                                }
+                            }
+                        }
                     }
-
-                    vobjp->setDebugText(str.str());
                 }
             }
+#endif
         }
-        else
+
+        for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
         {
-            vobjp->setDebugText(".");
+            LLSpatialGroup::drawmap_elem_t& draw_vec = i->second;
+            for (LLSpatialGroup::drawmap_elem_t::iterator j = draw_vec.begin(); j != draw_vec.end(); ++j)
+            {
+                LLDrawInfo* draw_info = *j;
+                if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_ANIM))
+                {
+                    renderTextureAnim(draw_info);
+                }
+                if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_BATCH_SIZE))
+                {
+                    renderBatchSize(draw_info);
+                }
+            }
         }
     }
-}
+};
 
-class LLOctreeRenderNonOccluded : public OctreeTraveler
+class LLOctreeRenderXRay : public OctreeTraveler
 {
 public:
-	LLCamera* mCamera;
-	LLOctreeRenderNonOccluded(LLCamera* camera): mCamera(camera) {}
-	
-	virtual void traverse(const OctreeNode* node)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
-		
-		const LLVector4a* bounds = group->getBounds();
-		if (!mCamera || mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1]))
-		{
-			node->accept(this);
-			stop_glerror();
-
-			for (U32 i = 0; i < node->getChildCount(); i++)
-			{
-				traverse(node->getChild(i));
-				stop_glerror();
-			}
-			
-			//draw tight fit bounding boxes for spatial group
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCTREE))
-			{	
-				group->rebuildGeom();
-				group->rebuildMesh();
-
-				renderOctree(group);
-				stop_glerror();
-			}
-		}
-	}
-
-	virtual void visit(const OctreeNode* branch)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) branch->getListener(0);
-		const LLVector4a* bounds = group->getBounds();
-		if (group->hasState(LLSpatialGroup::GEOM_DIRTY) || (mCamera && !mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1])))
-		{
-			return;
-		}
-
-		group->rebuildGeom();
-		group->rebuildMesh();
-
-		if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_BBOXES))
-		{
-			if (!group->isEmpty())
-			{
-				gGL.diffuseColor3f(0,0,1);
-				const LLVector4a* obj_bounds = group->getObjectBounds();
-				drawBoxOutline(obj_bounds[0], obj_bounds[1]);
-			}
-		}
-
-		for (OctreeNode::const_element_iter i = branch->getDataBegin(), i_end = branch->getDataEnd(); i != i_end; ++i)
-		{
-			LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
-			if(!drawable || drawable->isDead())
-		{
-				continue;
-			}
-					
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_BBOXES))
-			{
-				renderBoundingBox(drawable);			
-			}
-
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_NORMALS))
-			{
-				renderNormals(drawable);
-			}
-			
-            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_AREA))
+    LLCamera* mCamera;
+    LLOctreeRenderXRay(LLCamera* camera): mCamera(camera) {}
+
+    virtual void traverse(const OctreeNode* node)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
+
+        const LLVector4a* bounds = group->getBounds();
+        if (!mCamera || mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1]))
+        {
+            node->accept(this);
+            stop_glerror();
+
+            for (U32 i = 0; i < node->getChildCount(); i++)
             {
-                setTextureAreaDebugText(drawable);
+                traverse(node->getChild(i));
+                stop_glerror();
             }
 
-			/*if (drawable->getVOVolume() && gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY))
-			{
-				renderTexturePriority(drawable);
-			}*/
-
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_POINTS))
-			{
-				renderPoints(drawable);
-			}
-
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_LIGHTS))
-			{
-				renderLights(drawable);
-			}
-
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST))
-			{
-				renderRaycast(drawable);
-			}
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_UPDATE_TYPE))
-			{
-				renderUpdateType(drawable);
-			}
-			if(gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY))
-			{
-				renderTexelDensity(drawable);
-			}
-
-			LLViewerObject* vobjp = drawable->getVObj();
-			LLVOAvatar* avatar = vobjp ? vobjp->asAvatar() : nullptr;
-			if (avatar)
-			{
-				if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_AVATAR_VOLUME))
-				{
-					renderAvatarCollisionVolumes(avatar);
-				}
-
-				if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_AVATAR_JOINTS))
-				{
-					renderAvatarBones(avatar);
-				}
-
-				if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_AGENT_TARGET))
-				{
-					renderAgentTarget(avatar);
-				}
-			}
-			
-#if 0
-			if (gDebugGL)
-			{
-				for (U32 i = 0; i < drawable->getNumFaces(); ++i)
-				{
-					LLFace* facep = drawable->getFace(i);
-					if (facep)
-					{
-						U8 index = facep->getTextureIndex();
-						if (facep->mDrawInfo)
-						{
-							if (index < FACE_DO_NOT_BATCH_TEXTURES)
-							{
-								if (facep->mDrawInfo->mTextureList.size() <= index)
-								{
-									LL_ERRS() << "Face texture index out of bounds." << LL_ENDL;
-								}
-								else if (facep->mDrawInfo->mTextureList[index] != facep->getTexture())
-								{
-									LL_ERRS() << "Face texture index incorrect." << LL_ENDL;
-								}
-							}
-						}
-					}
-				}
-			}
-#endif
-		}
-		
-		for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
-		{
-			LLSpatialGroup::drawmap_elem_t& draw_vec = i->second;	
-			for (LLSpatialGroup::drawmap_elem_t::iterator j = draw_vec.begin(); j != draw_vec.end(); ++j)	
-			{
-				LLDrawInfo* draw_info = *j;
-				if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_ANIM))
-				{
-					renderTextureAnim(draw_info);
-				}
-				if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_BATCH_SIZE))
-				{
-					renderBatchSize(draw_info);
-				}
-			}
-		}
-	}
-};
+            //render visibility wireframe
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCCLUSION))
+            {
+                group->rebuildGeom();
+                group->rebuildMesh();
+
+                gGL.flush();
+                gGL.pushMatrix();
+                gGLLastMatrix = NULL;
+                gGL.loadMatrix(gGLModelView);
+                renderXRay(group, mCamera);
+                stop_glerror();
+                gGLLastMatrix = NULL;
+                gGL.popMatrix();
+            }
+        }
+    }
 
-class LLOctreeRenderXRay : public OctreeTraveler
-{
-public:
-	LLCamera* mCamera;
-	LLOctreeRenderXRay(LLCamera* camera): mCamera(camera) {}
-	
-	virtual void traverse(const OctreeNode* node)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
-		
-		const LLVector4a* bounds = group->getBounds();
-		if (!mCamera || mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1]))
-		{
-			node->accept(this);
-			stop_glerror();
-
-			for (U32 i = 0; i < node->getChildCount(); i++)
-			{
-				traverse(node->getChild(i));
-				stop_glerror();
-			}
-			
-			//render visibility wireframe
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCCLUSION))
-			{
-				group->rebuildGeom();
-				group->rebuildMesh();
-
-				gGL.flush();
-				gGL.pushMatrix();
-				gGLLastMatrix = NULL;
-				gGL.loadMatrix(gGLModelView);
-				renderXRay(group, mCamera);
-				stop_glerror();
-				gGLLastMatrix = NULL;
-				gGL.popMatrix();
-			}
-		}
-	}
-
-	virtual void visit(const OctreeNode* node) {}
+    virtual void visit(const OctreeNode* node) {}
 
 };
 
 class LLOctreeRenderPhysicsShapes : public OctreeTraveler
 {
 public:
-	LLCamera* mCamera;
+    LLCamera* mCamera;
     bool mWireframe;
 
-	LLOctreeRenderPhysicsShapes(LLCamera* camera, bool wireframe): mCamera(camera), mWireframe(wireframe) {}
-	
-	virtual void traverse(const OctreeNode* node)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
-		
-		const LLVector4a* bounds = group->getBounds();
-		if (!mCamera || mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1]))
-		{
-			node->accept(this);
-			stop_glerror();
-
-			for (U32 i = 0; i < node->getChildCount(); i++)
-			{
-				traverse(node->getChild(i));
-				stop_glerror();
-			}
-			
-			group->rebuildGeom();
-			group->rebuildMesh();
-
-			renderPhysicsShapes(group, mWireframe);
-		}
-	}
-
-	virtual void visit(const OctreeNode* branch)
-	{
-		
-	}
+    LLOctreeRenderPhysicsShapes(LLCamera* camera, bool wireframe): mCamera(camera), mWireframe(wireframe) {}
+
+    virtual void traverse(const OctreeNode* node)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
+
+        const LLVector4a* bounds = group->getBounds();
+        if (!mCamera || mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1]))
+        {
+            node->accept(this);
+            stop_glerror();
+
+            for (U32 i = 0; i < node->getChildCount(); i++)
+            {
+                traverse(node->getChild(i));
+                stop_glerror();
+            }
+
+            group->rebuildGeom();
+            group->rebuildMesh();
+
+            renderPhysicsShapes(group, mWireframe);
+        }
+    }
+
+    virtual void visit(const OctreeNode* branch)
+    {
+
+    }
 };
 
 class LLOctreePushBBoxVerts : public OctreeTraveler
 {
 public:
-	LLCamera* mCamera;
-	LLOctreePushBBoxVerts(LLCamera* camera): mCamera(camera) {}
-	
-	virtual void traverse(const OctreeNode* node)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
-		
-		const LLVector4a* bounds = group->getBounds();
-		if (!mCamera || mCamera->AABBInFrustum(bounds[0], bounds[1]))
-		{
-			node->accept(this);
-
-			for (U32 i = 0; i < node->getChildCount(); i++)
-			{
-				traverse(node->getChild(i));
-			}
-		}
-	}
-
-	virtual void visit(const OctreeNode* branch)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) branch->getListener(0);
-
-		const LLVector4a* bounds = group->getBounds();
-		if (group->hasState(LLSpatialGroup::GEOM_DIRTY) || (mCamera && !mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1])))
-		{
-			return;
-		}
-
-		for (OctreeNode::const_element_iter i = branch->getDataBegin(), i_end = branch->getDataEnd(); i != i_end; ++i)
-		{
-			LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
-			if(!drawable)
-		{
-				continue;
-			}
-			renderBoundingBox(drawable, FALSE);			
-		}
-	}
+    LLCamera* mCamera;
+    LLOctreePushBBoxVerts(LLCamera* camera): mCamera(camera) {}
+
+    virtual void traverse(const OctreeNode* node)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
+
+        const LLVector4a* bounds = group->getBounds();
+        if (!mCamera || mCamera->AABBInFrustum(bounds[0], bounds[1]))
+        {
+            node->accept(this);
+
+            for (U32 i = 0; i < node->getChildCount(); i++)
+            {
+                traverse(node->getChild(i));
+            }
+        }
+    }
+
+    virtual void visit(const OctreeNode* branch)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) branch->getListener(0);
+
+        const LLVector4a* bounds = group->getBounds();
+        if (group->hasState(LLSpatialGroup::GEOM_DIRTY) || (mCamera && !mCamera->AABBInFrustumNoFarClip(bounds[0], bounds[1])))
+        {
+            return;
+        }
+
+        for (OctreeNode::const_element_iter i = branch->getDataBegin(), i_end = branch->getDataEnd(); i != i_end; ++i)
+        {
+            LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
+            if(!drawable)
+        {
+                continue;
+            }
+            renderBoundingBox(drawable, FALSE);
+        }
+    }
 };
 
 void LLSpatialPartition::renderIntersectingBBoxes(LLCamera* camera)
 {
-	LLOctreePushBBoxVerts pusher(camera);
-	pusher.traverse(mOctree);
+    LLOctreePushBBoxVerts pusher(camera);
+    pusher.traverse(mOctree);
 }
 
 class LLOctreeStateCheck : public OctreeTraveler
 {
 public:
-	U32 mInheritedMask[LLViewerCamera::NUM_CAMERAS];
-
-	LLOctreeStateCheck()
-	{ 
-		for (U32 i = 0; i < LLViewerCamera::NUM_CAMERAS; i++)
-		{
-			mInheritedMask[i] = 0;
-		}
-	}
-
-	virtual void traverse(const OctreeNode* node)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
-		
-		node->accept(this);
-
-
-		U32 temp[LLViewerCamera::NUM_CAMERAS];
-
-		for (U32 i = 0; i < LLViewerCamera::NUM_CAMERAS; i++)
-		{
-			temp[i] = mInheritedMask[i];
-			mInheritedMask[i] |= group->mOcclusionState[i] & LLSpatialGroup::OCCLUDED; 
-		}
-
-		for (U32 i = 0; i < node->getChildCount(); i++)
-		{
-			traverse(node->getChild(i));
-		}
-
-		for (U32 i = 0; i < LLViewerCamera::NUM_CAMERAS; i++)
-		{
-			mInheritedMask[i] = temp[i];
-		}
-	}
-	
-
-	virtual void visit(const OctreeNode* state)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) state->getListener(0);
-
-		for (U32 i = 0; i < LLViewerCamera::NUM_CAMERAS; i++)
-		{
-			if (mInheritedMask[i] && !(group->mOcclusionState[i] & mInheritedMask[i]))
-			{
-				LL_ERRS() << "Spatial group failed inherited mask test." << LL_ENDL;
-			}
-		}
-
-		if (group->hasState(LLSpatialGroup::DIRTY))
-		{
-			assert_parent_state(group, LLSpatialGroup::DIRTY);
-		}
-	}
-
-	void assert_parent_state(LLSpatialGroup* group, U32 state)
-	{
-		LLSpatialGroup* parent = group->getParent();
-		while (parent)
-		{
-			if (!parent->hasState(state))
-			{
-				LL_ERRS() << "Spatial group failed parent state check." << LL_ENDL;
-			}
-			parent = parent->getParent();
-		}
-	}	
+    U32 mInheritedMask[LLViewerCamera::NUM_CAMERAS];
+
+    LLOctreeStateCheck()
+    {
+        for (U32 i = 0; i < LLViewerCamera::NUM_CAMERAS; i++)
+        {
+            mInheritedMask[i] = 0;
+        }
+    }
+
+    virtual void traverse(const OctreeNode* node)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
+
+        node->accept(this);
+
+
+        U32 temp[LLViewerCamera::NUM_CAMERAS];
+
+        for (U32 i = 0; i < LLViewerCamera::NUM_CAMERAS; i++)
+        {
+            temp[i] = mInheritedMask[i];
+            mInheritedMask[i] |= group->mOcclusionState[i] & LLSpatialGroup::OCCLUDED;
+        }
+
+        for (U32 i = 0; i < node->getChildCount(); i++)
+        {
+            traverse(node->getChild(i));
+        }
+
+        for (U32 i = 0; i < LLViewerCamera::NUM_CAMERAS; i++)
+        {
+            mInheritedMask[i] = temp[i];
+        }
+    }
+
+
+    virtual void visit(const OctreeNode* state)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) state->getListener(0);
+
+        for (U32 i = 0; i < LLViewerCamera::NUM_CAMERAS; i++)
+        {
+            if (mInheritedMask[i] && !(group->mOcclusionState[i] & mInheritedMask[i]))
+            {
+                LL_ERRS() << "Spatial group failed inherited mask test." << LL_ENDL;
+            }
+        }
+
+        if (group->hasState(LLSpatialGroup::DIRTY))
+        {
+            assert_parent_state(group, LLSpatialGroup::DIRTY);
+        }
+    }
+
+    void assert_parent_state(LLSpatialGroup* group, U32 state)
+    {
+        LLSpatialGroup* parent = group->getParent();
+        while (parent)
+        {
+            if (!parent->hasState(state))
+            {
+                LL_ERRS() << "Spatial group failed parent state check." << LL_ENDL;
+            }
+            parent = parent->getParent();
+        }
+    }
 };
 
 
 void LLSpatialPartition::renderPhysicsShapes(bool wireframe)
 {
-	LLSpatialBridge* bridge = asBridge();
-	LLCamera* camera = LLViewerCamera::getInstance();
-	
-	if (bridge)
-	{
-		camera = NULL;
-	}
-
-	gGL.flush();
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	LLOctreeRenderPhysicsShapes render_physics(camera, wireframe);
-	render_physics.traverse(mOctree);
-	gGL.flush();
+    LLSpatialBridge* bridge = asBridge();
+    LLCamera* camera = LLViewerCamera::getInstance();
+
+    if (bridge)
+    {
+        camera = NULL;
+    }
+
+    gGL.flush();
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    LLOctreeRenderPhysicsShapes render_physics(camera, wireframe);
+    render_physics.traverse(mOctree);
+    gGL.flush();
 }
 
 void LLSpatialPartition::renderDebug()
 {
-	if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCTREE |
-									  LLPipeline::RENDER_DEBUG_OCCLUSION |
-									  LLPipeline::RENDER_DEBUG_LIGHTS |
-									  LLPipeline::RENDER_DEBUG_BATCH_SIZE |
-									  LLPipeline::RENDER_DEBUG_UPDATE_TYPE |
-									  LLPipeline::RENDER_DEBUG_BBOXES |
-									  LLPipeline::RENDER_DEBUG_NORMALS |
-									  LLPipeline::RENDER_DEBUG_POINTS |
+    if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCTREE |
+                                      LLPipeline::RENDER_DEBUG_OCCLUSION |
+                                      LLPipeline::RENDER_DEBUG_LIGHTS |
+                                      LLPipeline::RENDER_DEBUG_BATCH_SIZE |
+                                      LLPipeline::RENDER_DEBUG_UPDATE_TYPE |
+                                      LLPipeline::RENDER_DEBUG_BBOXES |
+                                      LLPipeline::RENDER_DEBUG_NORMALS |
+                                      LLPipeline::RENDER_DEBUG_POINTS |
                                       LLPipeline::RENDER_DEBUG_TEXTURE_AREA |
-									  LLPipeline::RENDER_DEBUG_TEXTURE_ANIM |
-									  LLPipeline::RENDER_DEBUG_RAYCAST |
-									  LLPipeline::RENDER_DEBUG_AVATAR_VOLUME |
-									  LLPipeline::RENDER_DEBUG_AVATAR_JOINTS |
-									  LLPipeline::RENDER_DEBUG_AGENT_TARGET |
-									  LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA |
-									  LLPipeline::RENDER_DEBUG_TEXEL_DENSITY))
-	{
-		return;
-	}
-	
-	gDebugProgram.bind();
-
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY))
-	{
-		//sLastMaxTexPriority = lerp(sLastMaxTexPriority, sCurMaxTexPriority, gFrameIntervalSeconds);
-		sLastMaxTexPriority = (F32) LLViewerCamera::getInstance()->getScreenPixelArea();
-		sCurMaxTexPriority = 0.f;
-	}
-
-	LLGLDisable cullface(GL_CULL_FACE);
-	LLGLEnable blend(GL_BLEND);
-	gGL.setSceneBlendType(LLRender::BT_ALPHA);
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	gPipeline.disableLights();
-
-	LLSpatialBridge* bridge = asBridge();
-	LLCamera* camera = LLViewerCamera::getInstance();
-	
-	if (bridge)
-	{
-		camera = NULL;
-	}
-
-	LLOctreeStateCheck checker;
-	checker.traverse(mOctree);
-
-	LLOctreeRenderNonOccluded render_debug(camera);
-	render_debug.traverse(mOctree);
-
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCCLUSION))
-	{
-		{
-			LLGLEnable cull(GL_CULL_FACE);
-			
-			LLGLEnable blend(GL_BLEND);
-			LLGLDepthTest depth_under(GL_TRUE, GL_FALSE, GL_GREATER);
-			glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-			gGL.diffuseColor4f(0.5f, 0.0f, 0, 0.25f);
-
-			LLGLEnable offset(GL_POLYGON_OFFSET_LINE);
-			glPolygonOffset(-1.f, -1.f);
-
-			LLOctreeRenderXRay xray(camera);
-			xray.traverse(mOctree);
-
-			glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-		}
-	}
-	gDebugProgram.unbind();
+                                      LLPipeline::RENDER_DEBUG_TEXTURE_ANIM |
+                                      LLPipeline::RENDER_DEBUG_RAYCAST |
+                                      LLPipeline::RENDER_DEBUG_AVATAR_VOLUME |
+                                      LLPipeline::RENDER_DEBUG_AVATAR_JOINTS |
+                                      LLPipeline::RENDER_DEBUG_AGENT_TARGET |
+                                      LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA |
+                                      LLPipeline::RENDER_DEBUG_TEXEL_DENSITY))
+    {
+        return;
+    }
+
+    gDebugProgram.bind();
+
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY))
+    {
+        //sLastMaxTexPriority = lerp(sLastMaxTexPriority, sCurMaxTexPriority, gFrameIntervalSeconds);
+        sLastMaxTexPriority = (F32) LLViewerCamera::getInstance()->getScreenPixelArea();
+        sCurMaxTexPriority = 0.f;
+    }
+
+    LLGLDisable cullface(GL_CULL_FACE);
+    LLGLEnable blend(GL_BLEND);
+    gGL.setSceneBlendType(LLRender::BT_ALPHA);
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    gPipeline.disableLights();
+
+    LLSpatialBridge* bridge = asBridge();
+    LLCamera* camera = LLViewerCamera::getInstance();
+
+    if (bridge)
+    {
+        camera = NULL;
+    }
+
+    LLOctreeStateCheck checker;
+    checker.traverse(mOctree);
+
+    LLOctreeRenderNonOccluded render_debug(camera);
+    render_debug.traverse(mOctree);
+
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCCLUSION))
+    {
+        {
+            LLGLEnable cull(GL_CULL_FACE);
+
+            LLGLEnable blend(GL_BLEND);
+            LLGLDepthTest depth_under(GL_TRUE, GL_FALSE, GL_GREATER);
+            glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+            gGL.diffuseColor4f(0.5f, 0.0f, 0, 0.25f);
+
+            LLGLEnable offset(GL_POLYGON_OFFSET_LINE);
+            glPolygonOffset(-1.f, -1.f);
+
+            LLOctreeRenderXRay xray(camera);
+            xray.traverse(mOctree);
+
+            glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+        }
+    }
+    gDebugProgram.unbind();
 }
 
 void LLSpatialGroup::drawObjectBox(LLColor4 col)
 {
-	gGL.diffuseColor4fv(col.mV);
-	LLVector4a size;
-	size = mObjectBounds[1];
-	size.mul(1.01f);
-	size.add(LLVector4a(0.001f));
-	drawBox(mObjectBounds[0], size);
+    gGL.diffuseColor4fv(col.mV);
+    LLVector4a size;
+    size = mObjectBounds[1];
+    size.mul(1.01f);
+    size.add(LLVector4a(0.001f));
+    drawBox(mObjectBounds[0], size);
 }
 
-bool LLSpatialPartition::isHUDPartition() 
-{ 
-	return mPartitionType == LLViewerRegion::PARTITION_HUD ;
-} 
+bool LLSpatialPartition::isHUDPartition()
+{
+    return mPartitionType == LLViewerRegion::PARTITION_HUD ;
+}
 
 BOOL LLSpatialPartition::isVisible(const LLVector3& v)
 {
-	if (!LLViewerCamera::getInstance()->sphereInFrustum(v, 4.0f))
-	{
-		return FALSE;
-	}
+    if (!LLViewerCamera::getInstance()->sphereInFrustum(v, 4.0f))
+    {
+        return FALSE;
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 LL_ALIGN_PREFIX(16)
 class LLOctreeIntersect : public LLOctreeTraveler<LLViewerOctreeEntry, LLPointer<LLViewerOctreeEntry>>
 {
 public:
-	LL_ALIGN_16(LLVector4a mStart);
-	LL_ALIGN_16(LLVector4a mEnd);
-
-	S32       *mFaceHit;
-	LLVector4a *mIntersection;
-	LLVector2 *mTexCoord;
-	LLVector4a *mNormal;
-	LLVector4a *mTangent;
-	LLDrawable* mHit;
-	BOOL mPickTransparent;
-	BOOL mPickRigged;
+    LL_ALIGN_16(LLVector4a mStart);
+    LL_ALIGN_16(LLVector4a mEnd);
+
+    S32       *mFaceHit;
+    LLVector4a *mIntersection;
+    LLVector2 *mTexCoord;
+    LLVector4a *mNormal;
+    LLVector4a *mTangent;
+    LLDrawable* mHit;
+    BOOL mPickTransparent;
+    BOOL mPickRigged;
     BOOL mPickUnselectable;
     BOOL mPickReflectionProbe;
 
-	LLOctreeIntersect(const LLVector4a& start, const LLVector4a& end, BOOL pick_transparent, BOOL pick_rigged, BOOL pick_unselectable, BOOL pick_reflection_probe,
-					  S32* face_hit, LLVector4a* intersection, LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent)
-		: mStart(start),
-		  mEnd(end),
-		  mFaceHit(face_hit),
-		  mIntersection(intersection),
-		  mTexCoord(tex_coord),
-		  mNormal(normal),
-		  mTangent(tangent),
-		  mHit(NULL),
-		  mPickTransparent(pick_transparent),
-		  mPickRigged(pick_rigged),
+    LLOctreeIntersect(const LLVector4a& start, const LLVector4a& end, BOOL pick_transparent, BOOL pick_rigged, BOOL pick_unselectable, BOOL pick_reflection_probe,
+                      S32* face_hit, LLVector4a* intersection, LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent)
+        : mStart(start),
+          mEnd(end),
+          mFaceHit(face_hit),
+          mIntersection(intersection),
+          mTexCoord(tex_coord),
+          mNormal(normal),
+          mTangent(tangent),
+          mHit(NULL),
+          mPickTransparent(pick_transparent),
+          mPickRigged(pick_rigged),
           mPickUnselectable(pick_unselectable),
           mPickReflectionProbe(pick_reflection_probe)
-	{
-	}
-	
-	virtual void visit(const OctreeNode* branch) 
-	{	
-		for (OctreeNode::const_element_iter i = branch->getDataBegin(), i_end = branch->getDataEnd(); i != i_end; ++i)
-		{
-			check(*i);
-		}
-	}
-
-	virtual LLDrawable* check(const OctreeNode* node)
-	{
-		node->accept(this);
-	
-		for (U32 i = 0; i < node->getChildCount(); i++)
-		{
-			const OctreeNode* child = node->getChild(i);
-			LLVector3 res;
-
-			LLSpatialGroup* group = (LLSpatialGroup*) child->getListener(0);
-			
-			LLVector4a size;
-			LLVector4a center;
-			
-			const LLVector4a* bounds = group->getBounds();
-			size = bounds[1];
-			center = bounds[0];
-			
-			LLVector4a local_start = mStart;
-			LLVector4a local_end   = mEnd;
-
-			if (group->getSpatialPartition()->isBridge())
-			{
-				LLMatrix4a local_matrix4a = group->getSpatialPartition()->asBridge()->mDrawable->getRenderMatrix();
-				local_matrix4a.invert();
-
-				local_matrix4a.affineTransform(mStart, local_start);
-				local_matrix4a.affineTransform(mEnd, local_end);
-			}
-
-			if (LLLineSegmentBoxIntersect(local_start, local_end, center, size))
-			{
-				check(child);
-			}
-		}	
-
-		return mHit;
-	}
-
-	virtual bool check(LLViewerOctreeEntry* entry)
-	{	
-		LLDrawable* drawable = (LLDrawable*)entry->getDrawable();
-	
-		if (!drawable || !gPipeline.hasRenderType(drawable->getRenderType()) || !drawable->isVisible())
-		{
-			return false;
-		}
-
-		if (drawable->isSpatialBridge())
-		{
-			LLSpatialPartition *part = drawable->asPartition();
-			LLSpatialBridge* bridge = part->asBridge();
-			if (bridge && gPipeline.hasRenderType(bridge->mDrawableType))
-			{
-				check(part->mOctree);
-			}
-		}
-		else
-		{
-			LLViewerObject* vobj = drawable->getVObj();
+    {
+    }
+
+    virtual void visit(const OctreeNode* branch)
+    {
+        for (OctreeNode::const_element_iter i = branch->getDataBegin(), i_end = branch->getDataEnd(); i != i_end; ++i)
+        {
+            check(*i);
+        }
+    }
+
+    virtual LLDrawable* check(const OctreeNode* node)
+    {
+        node->accept(this);
+
+        for (U32 i = 0; i < node->getChildCount(); i++)
+        {
+            const OctreeNode* child = node->getChild(i);
+            LLVector3 res;
+
+            LLSpatialGroup* group = (LLSpatialGroup*) child->getListener(0);
+
+            LLVector4a size;
+            LLVector4a center;
+
+            const LLVector4a* bounds = group->getBounds();
+            size = bounds[1];
+            center = bounds[0];
+
+            LLVector4a local_start = mStart;
+            LLVector4a local_end   = mEnd;
+
+            if (group->getSpatialPartition()->isBridge())
+            {
+                LLMatrix4a local_matrix4a = group->getSpatialPartition()->asBridge()->mDrawable->getRenderMatrix();
+                local_matrix4a.invert();
+
+                local_matrix4a.affineTransform(mStart, local_start);
+                local_matrix4a.affineTransform(mEnd, local_end);
+            }
+
+            if (LLLineSegmentBoxIntersect(local_start, local_end, center, size))
+            {
+                check(child);
+            }
+        }
+
+        return mHit;
+    }
+
+    virtual bool check(LLViewerOctreeEntry* entry)
+    {
+        LLDrawable* drawable = (LLDrawable*)entry->getDrawable();
+
+        if (!drawable || !gPipeline.hasRenderType(drawable->getRenderType()) || !drawable->isVisible())
+        {
+            return false;
+        }
+
+        if (drawable->isSpatialBridge())
+        {
+            LLSpatialPartition *part = drawable->asPartition();
+            LLSpatialBridge* bridge = part->asBridge();
+            if (bridge && gPipeline.hasRenderType(bridge->mDrawableType))
+            {
+                check(part->mOctree);
+            }
+        }
+        else
+        {
+            LLViewerObject* vobj = drawable->getVObj();
 
             if (vobj &&
                 (!vobj->isReflectionProbe() || mPickReflectionProbe))
-			{
-				if (vobj->getClickAction() == CLICK_ACTION_IGNORE && !LLFloater::isVisible(gFloaterTools))
-				{
-					return false;
-				}
-
-				LLVector4a intersection;
-				bool skip_check = false;
-				if (vobj->isAvatar())
-				{
-					LLVOAvatar* avatar = (LLVOAvatar*) vobj;
-					if ((mPickRigged) || ((avatar->isSelf()) && (LLFloater::isVisible(gFloaterTools))))
-					{
-						LLViewerObject* hit = avatar->lineSegmentIntersectRiggedAttachments(mStart, mEnd, -1, mPickTransparent, mPickRigged, mPickUnselectable, mFaceHit, &intersection, mTexCoord, mNormal, mTangent);
-						if (hit)
-						{
-							mEnd = intersection;
-							if (mIntersection)
-							{
-								*mIntersection = intersection;
-							}
-							
-							mHit = hit->mDrawable;
-							skip_check = true;
-						}
-
-					}
-				}
-
-				if (!skip_check && vobj->lineSegmentIntersect(mStart, mEnd, -1, 
+            {
+                if (vobj->getClickAction() == CLICK_ACTION_IGNORE && !LLFloater::isVisible(gFloaterTools))
+                {
+                    return false;
+                }
+
+                LLVector4a intersection;
+                bool skip_check = false;
+                if (vobj->isAvatar())
+                {
+                    LLVOAvatar* avatar = (LLVOAvatar*) vobj;
+                    if ((mPickRigged) || ((avatar->isSelf()) && (LLFloater::isVisible(gFloaterTools))))
+                    {
+                        LLViewerObject* hit = avatar->lineSegmentIntersectRiggedAttachments(mStart, mEnd, -1, mPickTransparent, mPickRigged, mPickUnselectable, mFaceHit, &intersection, mTexCoord, mNormal, mTangent);
+                        if (hit)
+                        {
+                            mEnd = intersection;
+                            if (mIntersection)
+                            {
+                                *mIntersection = intersection;
+                            }
+
+                            mHit = hit->mDrawable;
+                            skip_check = true;
+                        }
+
+                    }
+                }
+
+                if (!skip_check && vobj->lineSegmentIntersect(mStart, mEnd, -1,
                     (mPickReflectionProbe && vobj->isReflectionProbe()) ? TRUE : mPickTransparent, // always pick transparent when picking selection probe
                     mPickRigged, mPickUnselectable, mFaceHit, &intersection, mTexCoord, mNormal, mTangent))
-				{
-					mEnd = intersection;  // shorten ray so we only find CLOSER hits
-					if (mIntersection)
-					{
-						*mIntersection = intersection;
-					}
-					
-					mHit = vobj->mDrawable;
-				}
-			}
-		}
-				
-		return false;
-	}
+                {
+                    mEnd = intersection;  // shorten ray so we only find CLOSER hits
+                    if (mIntersection)
+                    {
+                        *mIntersection = intersection;
+                    }
+
+                    mHit = vobj->mDrawable;
+                }
+            }
+        }
+
+        return false;
+    }
 } LL_ALIGN_POSTFIX(16);
 
 LLDrawable* LLSpatialPartition::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
-													 BOOL pick_transparent,
-													 BOOL pick_rigged,
+                                                     BOOL pick_transparent,
+                                                     BOOL pick_rigged,
                                                      BOOL pick_unselectable,
                                                      BOOL pick_reflection_probe,
-													 S32* face_hit,                   // return the face hit
-													 LLVector4a* intersection,         // return the intersection point
-													 LLVector2* tex_coord,            // return the texture coordinates of the intersection point
-													 LLVector4a* normal,               // return the surface normal at the intersection point
-													 LLVector4a* tangent			// return the surface tangent at the intersection point
-	)
+                                                     S32* face_hit,                   // return the face hit
+                                                     LLVector4a* intersection,         // return the intersection point
+                                                     LLVector2* tex_coord,            // return the texture coordinates of the intersection point
+                                                     LLVector4a* normal,               // return the surface normal at the intersection point
+                                                     LLVector4a* tangent            // return the surface tangent at the intersection point
+    )
 
 {
-	LLOctreeIntersect intersect(start, end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe, face_hit, intersection, tex_coord, normal, tangent);
-	LLDrawable* drawable = intersect.check(mOctree);
+    LLOctreeIntersect intersect(start, end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe, face_hit, intersection, tex_coord, normal, tangent);
+    LLDrawable* drawable = intersect.check(mOctree);
 
-	return drawable;
+    return drawable;
 }
 
 LLDrawable* LLSpatialGroup::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
@@ -3856,7 +3856,7 @@ LLDrawable* LLSpatialGroup::lineSegmentIntersect(const LLVector4a& start, const
     LLVector4a* intersection,         // return the intersection point
     LLVector2* tex_coord,            // return the texture coordinates of the intersection point
     LLVector4a* normal,               // return the surface normal at the intersection point
-    LLVector4a* tangent			// return the surface tangent at the intersection point
+    LLVector4a* tangent         // return the surface tangent at the intersection point
 )
 
 {
@@ -3866,32 +3866,32 @@ LLDrawable* LLSpatialGroup::lineSegmentIntersect(const LLVector4a& start, const
     return drawable;
 }
 
-LLDrawInfo::LLDrawInfo(U16 start, U16 end, U32 count, U32 offset, 
-					   LLViewerTexture* texture, LLVertexBuffer* buffer,
-					   bool fullbright, U8 bump)
-:	mVertexBuffer(buffer),
-	mTexture(texture),
-	mStart(start),
-	mEnd(end),
-	mCount(count),
-	mOffset(offset), 
-	mFullbright(fullbright),
-	mBump(bump),
-	mBlendFuncSrc(LLRender::BF_SOURCE_ALPHA),
-	mBlendFuncDst(LLRender::BF_ONE_MINUS_SOURCE_ALPHA),
-	mHasGlow(false),
-	mEnvIntensity(0.0f),
-	mAlphaMaskCutoff(0.5f)
-{
-	mVertexBuffer->validateRange(mStart, mEnd, mCount, mOffset);
+LLDrawInfo::LLDrawInfo(U16 start, U16 end, U32 count, U32 offset,
+                       LLViewerTexture* texture, LLVertexBuffer* buffer,
+                       bool fullbright, U8 bump)
+:   mVertexBuffer(buffer),
+    mTexture(texture),
+    mStart(start),
+    mEnd(end),
+    mCount(count),
+    mOffset(offset),
+    mFullbright(fullbright),
+    mBump(bump),
+    mBlendFuncSrc(LLRender::BF_SOURCE_ALPHA),
+    mBlendFuncDst(LLRender::BF_ONE_MINUS_SOURCE_ALPHA),
+    mHasGlow(false),
+    mEnvIntensity(0.0f),
+    mAlphaMaskCutoff(0.5f)
+{
+    mVertexBuffer->validateRange(mStart, mEnd, mCount, mOffset);
 }
 
-LLDrawInfo::~LLDrawInfo()	
+LLDrawInfo::~LLDrawInfo()
 {
-	if (gDebugGL)
-	{
-		gPipeline.checkReferences(this);
-	}
+    if (gDebugGL)
+    {
+        gPipeline.checkReferences(this);
+    }
 }
 
 LLColor4U LLDrawInfo::getDebugColor() const
@@ -3904,13 +3904,13 @@ LLColor4U LLDrawInfo::getDebugColor() const
     *((U32*) color.mV) = hash.getCRC();
 
     color.mV[3] = 200;
-    
+
     return color;
 }
 
 void LLDrawInfo::validate()
 {
-	mVertexBuffer->validateRange(mStart, mEnd, mCount, mOffset);
+    mVertexBuffer->validateRange(mStart, mEnd, mCount, mOffset);
 }
 
 U64 LLDrawInfo::getSkinHash()
@@ -3918,110 +3918,110 @@ U64 LLDrawInfo::getSkinHash()
     return mSkinInfo ? mSkinInfo->mHash : 0;
 }
 
-LLCullResult::LLCullResult() 
+LLCullResult::LLCullResult()
 {
-	mVisibleGroupsAllocated = 0;
-	mAlphaGroupsAllocated = 0;
+    mVisibleGroupsAllocated = 0;
+    mAlphaGroupsAllocated = 0;
     mRiggedAlphaGroupsAllocated = 0;
-	mOcclusionGroupsAllocated = 0;
-	mDrawableGroupsAllocated = 0;
-	mVisibleListAllocated = 0;
-	mVisibleBridgeAllocated = 0;
-
-	mVisibleGroups.clear();
-	mVisibleGroups.push_back(NULL);
-	mVisibleGroupsEnd = &mVisibleGroups[0];
-	mAlphaGroups.clear();
-	mAlphaGroups.push_back(NULL);
-	mAlphaGroupsEnd = &mAlphaGroups[0];
+    mOcclusionGroupsAllocated = 0;
+    mDrawableGroupsAllocated = 0;
+    mVisibleListAllocated = 0;
+    mVisibleBridgeAllocated = 0;
+
+    mVisibleGroups.clear();
+    mVisibleGroups.push_back(NULL);
+    mVisibleGroupsEnd = &mVisibleGroups[0];
+    mAlphaGroups.clear();
+    mAlphaGroups.push_back(NULL);
+    mAlphaGroupsEnd = &mAlphaGroups[0];
     mRiggedAlphaGroups.clear();
     mRiggedAlphaGroups.push_back(NULL);
     mRiggedAlphaGroupsEnd = &mRiggedAlphaGroups[0];
-	mOcclusionGroups.clear();
-	mOcclusionGroups.push_back(NULL);
-	mOcclusionGroupsEnd = &mOcclusionGroups[0];
-	mDrawableGroups.clear();
-	mDrawableGroups.push_back(NULL);
-	mDrawableGroupsEnd = &mDrawableGroups[0];
-	mVisibleList.clear();
-	mVisibleList.push_back(NULL);
-	mVisibleListEnd = &mVisibleList[0];
-	mVisibleBridge.clear();
-	mVisibleBridge.push_back(NULL);
-	mVisibleBridgeEnd = &mVisibleBridge[0];
-
-	for (U32 i = 0; i < LLRenderPass::NUM_RENDER_TYPES; i++)
-	{
-		mRenderMap[i].clear();
-		mRenderMap[i].push_back(NULL);
-		mRenderMapEnd[i] = &mRenderMap[i][0];
-		mRenderMapAllocated[i] = 0;
-	}
-
-	clear();
+    mOcclusionGroups.clear();
+    mOcclusionGroups.push_back(NULL);
+    mOcclusionGroupsEnd = &mOcclusionGroups[0];
+    mDrawableGroups.clear();
+    mDrawableGroups.push_back(NULL);
+    mDrawableGroupsEnd = &mDrawableGroups[0];
+    mVisibleList.clear();
+    mVisibleList.push_back(NULL);
+    mVisibleListEnd = &mVisibleList[0];
+    mVisibleBridge.clear();
+    mVisibleBridge.push_back(NULL);
+    mVisibleBridgeEnd = &mVisibleBridge[0];
+
+    for (U32 i = 0; i < LLRenderPass::NUM_RENDER_TYPES; i++)
+    {
+        mRenderMap[i].clear();
+        mRenderMap[i].push_back(NULL);
+        mRenderMapEnd[i] = &mRenderMap[i][0];
+        mRenderMapAllocated[i] = 0;
+    }
+
+    clear();
 }
 
-template <class T, class V> 
+template <class T, class V>
 void LLCullResult::pushBack(T& head, U32& count, V* val)
 {
-	head[count] = val;
-	head.push_back(NULL);
-	count++;
+    head[count] = val;
+    head.push_back(NULL);
+    count++;
 }
 
 void LLCullResult::clear()
 {
-	mVisibleGroupsSize = 0;
-	mVisibleGroupsEnd = &mVisibleGroups[0];
+    mVisibleGroupsSize = 0;
+    mVisibleGroupsEnd = &mVisibleGroups[0];
 
-	mAlphaGroupsSize = 0;
-	mAlphaGroupsEnd = &mAlphaGroups[0];
+    mAlphaGroupsSize = 0;
+    mAlphaGroupsEnd = &mAlphaGroups[0];
 
     mRiggedAlphaGroupsSize = 0;
     mRiggedAlphaGroupsEnd = &mRiggedAlphaGroups[0];
 
-	mOcclusionGroupsSize = 0;
-	mOcclusionGroupsEnd = &mOcclusionGroups[0];
+    mOcclusionGroupsSize = 0;
+    mOcclusionGroupsEnd = &mOcclusionGroups[0];
 
-	mDrawableGroupsSize = 0;
-	mDrawableGroupsEnd = &mDrawableGroups[0];
+    mDrawableGroupsSize = 0;
+    mDrawableGroupsEnd = &mDrawableGroups[0];
 
-	mVisibleListSize = 0;
-	mVisibleListEnd = &mVisibleList[0];
+    mVisibleListSize = 0;
+    mVisibleListEnd = &mVisibleList[0];
 
-	mVisibleBridgeSize = 0;
-	mVisibleBridgeEnd = &mVisibleBridge[0];
+    mVisibleBridgeSize = 0;
+    mVisibleBridgeEnd = &mVisibleBridge[0];
 
 
-	for (U32 i = 0; i < LLRenderPass::NUM_RENDER_TYPES; i++)
-	{
-		for (U32 j = 0; j < mRenderMapSize[i]; j++)
-		{
-			mRenderMap[i][j] = 0;
-		}
-		mRenderMapSize[i] = 0;
-		mRenderMapEnd[i] = &(mRenderMap[i][0]);
-	}
+    for (U32 i = 0; i < LLRenderPass::NUM_RENDER_TYPES; i++)
+    {
+        for (U32 j = 0; j < mRenderMapSize[i]; j++)
+        {
+            mRenderMap[i][j] = 0;
+        }
+        mRenderMapSize[i] = 0;
+        mRenderMapEnd[i] = &(mRenderMap[i][0]);
+    }
 }
 
 LLCullResult::sg_iterator LLCullResult::beginVisibleGroups()
 {
-	return &mVisibleGroups[0];
+    return &mVisibleGroups[0];
 }
 
 LLCullResult::sg_iterator LLCullResult::endVisibleGroups()
 {
-	return mVisibleGroupsEnd;
+    return mVisibleGroupsEnd;
 }
 
 LLCullResult::sg_iterator LLCullResult::beginAlphaGroups()
 {
-	return &mAlphaGroups[0];
+    return &mAlphaGroups[0];
 }
 
 LLCullResult::sg_iterator LLCullResult::endAlphaGroups()
 {
-	return mAlphaGroupsEnd;
+    return mAlphaGroupsEnd;
 }
 
 LLCullResult::sg_iterator LLCullResult::beginRiggedAlphaGroups()
@@ -4036,80 +4036,80 @@ LLCullResult::sg_iterator LLCullResult::endRiggedAlphaGroups()
 
 LLCullResult::sg_iterator LLCullResult::beginOcclusionGroups()
 {
-	return &mOcclusionGroups[0];
+    return &mOcclusionGroups[0];
 }
 
 LLCullResult::sg_iterator LLCullResult::endOcclusionGroups()
 {
-	return mOcclusionGroupsEnd;
+    return mOcclusionGroupsEnd;
 }
 
 LLCullResult::sg_iterator LLCullResult::beginDrawableGroups()
 {
-	return &mDrawableGroups[0];
+    return &mDrawableGroups[0];
 }
 
 LLCullResult::sg_iterator LLCullResult::endDrawableGroups()
 {
-	return mDrawableGroupsEnd;
+    return mDrawableGroupsEnd;
 }
 
 LLCullResult::drawable_iterator LLCullResult::beginVisibleList()
 {
-	return &mVisibleList[0];
+    return &mVisibleList[0];
 }
 
 LLCullResult::drawable_iterator LLCullResult::endVisibleList()
 {
-	return mVisibleListEnd;
+    return mVisibleListEnd;
 }
 
 LLCullResult::bridge_iterator LLCullResult::beginVisibleBridge()
 {
-	return &mVisibleBridge[0];
+    return &mVisibleBridge[0];
 }
 
 LLCullResult::bridge_iterator LLCullResult::endVisibleBridge()
 {
-	return mVisibleBridgeEnd;
+    return mVisibleBridgeEnd;
 }
 
 LLCullResult::drawinfo_iterator LLCullResult::beginRenderMap(U32 type)
 {
-	return &mRenderMap[type][0];
+    return &mRenderMap[type][0];
 }
 
 LLCullResult::drawinfo_iterator LLCullResult::endRenderMap(U32 type)
 {
-	return mRenderMapEnd[type];
+    return mRenderMapEnd[type];
 }
 
 void LLCullResult::pushVisibleGroup(LLSpatialGroup* group)
 {
-	if (mVisibleGroupsSize < mVisibleGroupsAllocated)
-	{
-		mVisibleGroups[mVisibleGroupsSize] = group;
-	}
-	else
-	{
-		pushBack(mVisibleGroups, mVisibleGroupsAllocated, group);
-	}
-	++mVisibleGroupsSize;
-	mVisibleGroupsEnd = &mVisibleGroups[mVisibleGroupsSize];
+    if (mVisibleGroupsSize < mVisibleGroupsAllocated)
+    {
+        mVisibleGroups[mVisibleGroupsSize] = group;
+    }
+    else
+    {
+        pushBack(mVisibleGroups, mVisibleGroupsAllocated, group);
+    }
+    ++mVisibleGroupsSize;
+    mVisibleGroupsEnd = &mVisibleGroups[mVisibleGroupsSize];
 }
 
 void LLCullResult::pushAlphaGroup(LLSpatialGroup* group)
 {
-	if (mAlphaGroupsSize < mAlphaGroupsAllocated)
-	{
-		mAlphaGroups[mAlphaGroupsSize] = group;
-	}
-	else
-	{
-		pushBack(mAlphaGroups, mAlphaGroupsAllocated, group);
-	}
-	++mAlphaGroupsSize;
-	mAlphaGroupsEnd = &mAlphaGroups[mAlphaGroupsSize];
+    if (mAlphaGroupsSize < mAlphaGroupsAllocated)
+    {
+        mAlphaGroups[mAlphaGroupsSize] = group;
+    }
+    else
+    {
+        pushBack(mAlphaGroups, mAlphaGroupsAllocated, group);
+    }
+    ++mAlphaGroupsSize;
+    mAlphaGroupsEnd = &mAlphaGroups[mAlphaGroupsSize];
 }
 
 void LLCullResult::pushRiggedAlphaGroup(LLSpatialGroup* group)
@@ -4128,16 +4128,16 @@ void LLCullResult::pushRiggedAlphaGroup(LLSpatialGroup* group)
 
 void LLCullResult::pushOcclusionGroup(LLSpatialGroup* group)
 {
-	if (mOcclusionGroupsSize < mOcclusionGroupsAllocated)
-	{
-		mOcclusionGroups[mOcclusionGroupsSize] = group;
-	}
-	else
-	{
-		pushBack(mOcclusionGroups, mOcclusionGroupsAllocated, group);
-	}
-	++mOcclusionGroupsSize;
-	mOcclusionGroupsEnd = &mOcclusionGroups[mOcclusionGroupsSize];
+    if (mOcclusionGroupsSize < mOcclusionGroupsAllocated)
+    {
+        mOcclusionGroups[mOcclusionGroupsSize] = group;
+    }
+    else
+    {
+        pushBack(mOcclusionGroups, mOcclusionGroupsAllocated, group);
+    }
+    ++mOcclusionGroupsSize;
+    mOcclusionGroupsEnd = &mOcclusionGroups[mOcclusionGroupsSize];
 }
 
 void LLCullResult::pushDrawableGroup(LLSpatialGroup* group)
@@ -4146,16 +4146,16 @@ void LLCullResult::pushDrawableGroup(LLSpatialGroup* group)
     // group must NOT be in the drawble groups list already
     llassert(std::find(&mDrawableGroups[0], mDrawableGroupsEnd, group) == mDrawableGroupsEnd);
 #endif
-	if (mDrawableGroupsSize < mDrawableGroupsAllocated)
-	{
-		mDrawableGroups[mDrawableGroupsSize] = group;
-	}
-	else
-	{
-		pushBack(mDrawableGroups, mDrawableGroupsAllocated, group);
-	}
-	++mDrawableGroupsSize;
-	mDrawableGroupsEnd = &mDrawableGroups[mDrawableGroupsSize];
+    if (mDrawableGroupsSize < mDrawableGroupsAllocated)
+    {
+        mDrawableGroups[mDrawableGroupsSize] = group;
+    }
+    else
+    {
+        pushBack(mDrawableGroups, mDrawableGroupsAllocated, group);
+    }
+    ++mDrawableGroupsSize;
+    mDrawableGroupsEnd = &mDrawableGroups[mDrawableGroupsSize];
 }
 
 void LLCullResult::pushDrawable(LLDrawable* drawable)
@@ -4164,56 +4164,56 @@ void LLCullResult::pushDrawable(LLDrawable* drawable)
     // drawable must NOT be in the visible list already
     llassert(std::find(&mVisibleList[0], mVisibleListEnd, drawable) == mVisibleListEnd);
 #endif
-	if (mVisibleListSize < mVisibleListAllocated)
-	{
-		mVisibleList[mVisibleListSize] = drawable;
-	}
-	else
-	{
-		pushBack(mVisibleList, mVisibleListAllocated, drawable);
-	}
-	++mVisibleListSize;
-	mVisibleListEnd = &mVisibleList[mVisibleListSize];
+    if (mVisibleListSize < mVisibleListAllocated)
+    {
+        mVisibleList[mVisibleListSize] = drawable;
+    }
+    else
+    {
+        pushBack(mVisibleList, mVisibleListAllocated, drawable);
+    }
+    ++mVisibleListSize;
+    mVisibleListEnd = &mVisibleList[mVisibleListSize];
 }
 
 void LLCullResult::pushBridge(LLSpatialBridge* bridge)
 {
-	if (mVisibleBridgeSize < mVisibleBridgeAllocated)
-	{
-		mVisibleBridge[mVisibleBridgeSize] = bridge;
-	}
-	else
-	{
-		pushBack(mVisibleBridge, mVisibleBridgeAllocated, bridge);
-	}
-	++mVisibleBridgeSize;
-	mVisibleBridgeEnd = &mVisibleBridge[mVisibleBridgeSize];
+    if (mVisibleBridgeSize < mVisibleBridgeAllocated)
+    {
+        mVisibleBridge[mVisibleBridgeSize] = bridge;
+    }
+    else
+    {
+        pushBack(mVisibleBridge, mVisibleBridgeAllocated, bridge);
+    }
+    ++mVisibleBridgeSize;
+    mVisibleBridgeEnd = &mVisibleBridge[mVisibleBridgeSize];
 }
 
 void LLCullResult::pushDrawInfo(U32 type, LLDrawInfo* draw_info)
 {
-	if (mRenderMapSize[type] < mRenderMapAllocated[type])
-	{
-		mRenderMap[type][mRenderMapSize[type]] = draw_info;
-	}
-	else
-	{
-		pushBack(mRenderMap[type], mRenderMapAllocated[type], draw_info);
-	}
-	++mRenderMapSize[type];
-	mRenderMapEnd[type] = &(mRenderMap[type][mRenderMapSize[type]]);
+    if (mRenderMapSize[type] < mRenderMapAllocated[type])
+    {
+        mRenderMap[type][mRenderMapSize[type]] = draw_info;
+    }
+    else
+    {
+        pushBack(mRenderMap[type], mRenderMapAllocated[type], draw_info);
+    }
+    ++mRenderMapSize[type];
+    mRenderMapEnd[type] = &(mRenderMap[type][mRenderMapSize[type]]);
 }
 
 
 void LLCullResult::assertDrawMapsEmpty()
 {
-	for (U32 i = 0; i < LLRenderPass::NUM_RENDER_TYPES; i++)
-	{
-		if (mRenderMapSize[i] != 0)
-		{
-			LL_ERRS() << "Stale LLDrawInfo's in LLCullResult!"
-				<< " (mRenderMapSize[" << i << "] = " << mRenderMapSize[i] << ")" << LL_ENDL;
-		}
-	}
+    for (U32 i = 0; i < LLRenderPass::NUM_RENDER_TYPES; i++)
+    {
+        if (mRenderMapSize[i] != 0)
+        {
+            LL_ERRS() << "Stale LLDrawInfo's in LLCullResult!"
+                << " (mRenderMapSize[" << i << "] = " << mRenderMapSize[i] << ")" << LL_ENDL;
+        }
+    }
 }
 
diff --git a/indra/newview/llsurface.cpp b/indra/newview/llsurface.cpp
index 418b0f4ca41cf337a61c672ac4b348112ae98145..f1a369b2c6de9888b181c62bc2ce1ebb655d4655 100644
--- a/indra/newview/llsurface.cpp
+++ b/indra/newview/llsurface.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llsurface.cpp
  * @brief Implementation of LLSurface class
  *
  * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -66,82 +66,82 @@ S32 LLSurface::sTextureSize = 256;
 // ---------------- LLSurface:: Public Members ---------------
 
 LLSurface::LLSurface(U32 type, LLViewerRegion *regionp) :
-	mGridsPerEdge(0),
-	mOOGridsPerEdge(0.f),
-	mPatchesPerEdge(0),
-	mNumberOfPatches(0),
-	mType(type),
-	mDetailTextureScale(0.f),
-	mOriginGlobal(0.0, 0.0, 0.0),
-	mSTexturep(NULL),
-	mWaterTexturep(NULL),
-	mGridsPerPatchEdge(0),
-	mMetersPerGrid(1.0f),
-	mMetersPerEdge(1.0f),
-	mRegionp(regionp)
+    mGridsPerEdge(0),
+    mOOGridsPerEdge(0.f),
+    mPatchesPerEdge(0),
+    mNumberOfPatches(0),
+    mType(type),
+    mDetailTextureScale(0.f),
+    mOriginGlobal(0.0, 0.0, 0.0),
+    mSTexturep(NULL),
+    mWaterTexturep(NULL),
+    mGridsPerPatchEdge(0),
+    mMetersPerGrid(1.0f),
+    mMetersPerEdge(1.0f),
+    mRegionp(regionp)
 {
-	// Surface data
-	mSurfaceZ = NULL;
-	mNorm = NULL;
+    // Surface data
+    mSurfaceZ = NULL;
+    mNorm = NULL;
 
-	// Patch data
-	mPatchList = NULL;
+    // Patch data
+    mPatchList = NULL;
 
-	// One of each for each camera
-	mVisiblePatchCount = 0;
+    // One of each for each camera
+    mVisiblePatchCount = 0;
 
-	mHasZData = FALSE;
-	// "uninitialized" min/max z
-	mMinZ = 10000.f;
-	mMaxZ = -10000.f;
+    mHasZData = FALSE;
+    // "uninitialized" min/max z
+    mMinZ = 10000.f;
+    mMaxZ = -10000.f;
 
-	mWaterObjp = NULL;
+    mWaterObjp = NULL;
 
-	// In here temporarily.
-	mSurfacePatchUpdateCount = 0;
+    // In here temporarily.
+    mSurfacePatchUpdateCount = 0;
 
-	for (S32 i = 0; i < 8; i++)
-	{
-		mNeighbors[i] = NULL;
-	}
+    for (S32 i = 0; i < 8; i++)
+    {
+        mNeighbors[i] = NULL;
+    }
 }
 
 
 LLSurface::~LLSurface()
 {
-	delete [] mSurfaceZ;
-	mSurfaceZ = NULL;
-
-	delete [] mNorm;
-
-	mGridsPerEdge = 0;
-	mGridsPerPatchEdge = 0;
-	mPatchesPerEdge = 0;
-	mNumberOfPatches = 0;
-	destroyPatchData();
-
-	LLDrawPoolTerrain *poolp = (LLDrawPoolTerrain*) gPipeline.findPool(LLDrawPool::POOL_TERRAIN, mSTexturep);
-	if (!poolp)
-	{
-		LL_WARNS() << "No pool for terrain on destruction!" << LL_ENDL;
-	}
-	else if (poolp->mReferences.empty())
-	{
-		gPipeline.removePool(poolp);
-		// Don't enable this until we blitz the draw pool for it as well.  -- djs
-		if (mSTexturep)
-		{
-			mSTexturep = NULL;
-		}
-		if (mWaterTexturep)
-		{
-			mWaterTexturep = NULL;
-		}
-	}
-	else
-	{
-		LL_ERRS() << "Terrain pool not empty!" << LL_ENDL;
-	}
+    delete [] mSurfaceZ;
+    mSurfaceZ = NULL;
+
+    delete [] mNorm;
+
+    mGridsPerEdge = 0;
+    mGridsPerPatchEdge = 0;
+    mPatchesPerEdge = 0;
+    mNumberOfPatches = 0;
+    destroyPatchData();
+
+    LLDrawPoolTerrain *poolp = (LLDrawPoolTerrain*) gPipeline.findPool(LLDrawPool::POOL_TERRAIN, mSTexturep);
+    if (!poolp)
+    {
+        LL_WARNS() << "No pool for terrain on destruction!" << LL_ENDL;
+    }
+    else if (poolp->mReferences.empty())
+    {
+        gPipeline.removePool(poolp);
+        // Don't enable this until we blitz the draw pool for it as well.  -- djs
+        if (mSTexturep)
+        {
+            mSTexturep = NULL;
+        }
+        if (mWaterTexturep)
+        {
+            mWaterTexturep = NULL;
+        }
+    }
+    else
+    {
+        LL_ERRS() << "Terrain pool not empty!" << LL_ENDL;
+    }
 }
 
 void LLSurface::initClasses()
@@ -150,593 +150,593 @@ void LLSurface::initClasses()
 
 void LLSurface::setRegion(LLViewerRegion *regionp)
 {
-	mRegionp = regionp;
-	mWaterObjp = NULL; // depends on regionp, needs recreating
+    mRegionp = regionp;
+    mWaterObjp = NULL; // depends on regionp, needs recreating
 }
 
 // Assumes that arguments are powers of 2, and that
-// grids_per_edge / grids_per_patch_edge = power of 2 
+// grids_per_edge / grids_per_patch_edge = power of 2
 void LLSurface::create(const S32 grids_per_edge,
-					   const S32 grids_per_patch_edge,
-					   const LLVector3d &origin_global,
-					   const F32 width) 
+                       const S32 grids_per_patch_edge,
+                       const LLVector3d &origin_global,
+                       const F32 width)
 {
-	// Initialize various constants for the surface
-	mGridsPerEdge = grids_per_edge + 1;  // Add 1 for the east and north buffer
-	mOOGridsPerEdge = 1.f / mGridsPerEdge;
-	mGridsPerPatchEdge = grids_per_patch_edge;
-	mPatchesPerEdge = (mGridsPerEdge - 1) / mGridsPerPatchEdge;
-	mNumberOfPatches = mPatchesPerEdge * mPatchesPerEdge;
-	mMetersPerGrid = width / ((F32)(mGridsPerEdge - 1));
-	mMetersPerEdge = mMetersPerGrid * (mGridsPerEdge - 1);
-	sTextureSize = width;
-
-	mOriginGlobal.setVec(origin_global);
-
-	mPVArray.create(mGridsPerEdge, mGridsPerPatchEdge, LLWorld::getInstance()->getRegionScale());
-
-	S32 number_of_grids = mGridsPerEdge * mGridsPerEdge;
-
-	/////////////////////////////////////
-	//
-	// Initialize data arrays for surface
-	///
-	mSurfaceZ = new F32[number_of_grids];
-	mNorm = new LLVector3[number_of_grids];
-
-	// Reset the surface to be a flat square grid
-	for(S32 i=0; i < number_of_grids; i++) 
-	{
-		// Surface is flat and zero
-		// Normals all point up
-		mSurfaceZ[i] = 0.0f;
-		mNorm[i].setVec(0.f, 0.f, 1.f);
-	}
+    // Initialize various constants for the surface
+    mGridsPerEdge = grids_per_edge + 1;  // Add 1 for the east and north buffer
+    mOOGridsPerEdge = 1.f / mGridsPerEdge;
+    mGridsPerPatchEdge = grids_per_patch_edge;
+    mPatchesPerEdge = (mGridsPerEdge - 1) / mGridsPerPatchEdge;
+    mNumberOfPatches = mPatchesPerEdge * mPatchesPerEdge;
+    mMetersPerGrid = width / ((F32)(mGridsPerEdge - 1));
+    mMetersPerEdge = mMetersPerGrid * (mGridsPerEdge - 1);
+    sTextureSize = width;
+
+    mOriginGlobal.setVec(origin_global);
+
+    mPVArray.create(mGridsPerEdge, mGridsPerPatchEdge, LLWorld::getInstance()->getRegionScale());
+
+    S32 number_of_grids = mGridsPerEdge * mGridsPerEdge;
+
+    /////////////////////////////////////
+    //
+    // Initialize data arrays for surface
+    ///
+    mSurfaceZ = new F32[number_of_grids];
+    mNorm = new LLVector3[number_of_grids];
+
+    // Reset the surface to be a flat square grid
+    for(S32 i=0; i < number_of_grids; i++)
+    {
+        // Surface is flat and zero
+        // Normals all point up
+        mSurfaceZ[i] = 0.0f;
+        mNorm[i].setVec(0.f, 0.f, 1.f);
+    }
 
 
-	mVisiblePatchCount = 0;
+    mVisiblePatchCount = 0;
 
 
-	///////////////////////
-	//
-	// Initialize textures
-	//
+    ///////////////////////
+    //
+    // Initialize textures
+    //
 
-	initTextures();
+    initTextures();
 
-	// Has to be done after texture initialization
-	createPatchData();
+    // Has to be done after texture initialization
+    createPatchData();
 }
 
 LLViewerTexture* LLSurface::getSTexture()
 {
-	if (mSTexturep.notNull() && !mSTexturep->hasGLTexture())
-	{
-		createSTexture();
-	}
-	return mSTexturep;
+    if (mSTexturep.notNull() && !mSTexturep->hasGLTexture())
+    {
+        createSTexture();
+    }
+    return mSTexturep;
 }
 
 LLViewerTexture* LLSurface::getWaterTexture()
 {
-	if (mWaterTexturep.notNull() && !mWaterTexturep->hasGLTexture())
-	{
-		createWaterTexture();
-	}
-	return mWaterTexturep;
+    if (mWaterTexturep.notNull() && !mWaterTexturep->hasGLTexture())
+    {
+        createWaterTexture();
+    }
+    return mWaterTexturep;
 }
 
 void LLSurface::createSTexture()
 {
-	if (!mSTexturep)
-	{
-		// Fill with dummy gray data.	
-		// GL NOT ACTIVE HERE
-		LLPointer<LLImageRaw> raw = new LLImageRaw(sTextureSize, sTextureSize, 3);
-		U8 *default_texture = raw->getData();
-		for (S32 i = 0; i < sTextureSize; i++)
-		{
-			for (S32 j = 0; j < sTextureSize; j++)
-			{
-				*(default_texture + (i*sTextureSize + j)*3) = 128;
-				*(default_texture + (i*sTextureSize + j)*3 + 1) = 128;
-				*(default_texture + (i*sTextureSize + j)*3 + 2) = 128;
-			}
-		}
-
-		mSTexturep = LLViewerTextureManager::getLocalTexture(raw.get(), FALSE);
-		mSTexturep->dontDiscard();
-		gGL.getTexUnit(0)->bind(mSTexturep);
-		mSTexturep->setAddressMode(LLTexUnit::TAM_CLAMP);		
-	}
+    if (!mSTexturep)
+    {
+        // Fill with dummy gray data.
+        // GL NOT ACTIVE HERE
+        LLPointer<LLImageRaw> raw = new LLImageRaw(sTextureSize, sTextureSize, 3);
+        U8 *default_texture = raw->getData();
+        for (S32 i = 0; i < sTextureSize; i++)
+        {
+            for (S32 j = 0; j < sTextureSize; j++)
+            {
+                *(default_texture + (i*sTextureSize + j)*3) = 128;
+                *(default_texture + (i*sTextureSize + j)*3 + 1) = 128;
+                *(default_texture + (i*sTextureSize + j)*3 + 2) = 128;
+            }
+        }
+
+        mSTexturep = LLViewerTextureManager::getLocalTexture(raw.get(), FALSE);
+        mSTexturep->dontDiscard();
+        gGL.getTexUnit(0)->bind(mSTexturep);
+        mSTexturep->setAddressMode(LLTexUnit::TAM_CLAMP);
+    }
 }
 
 void LLSurface::createWaterTexture()
 {
-	if (!mWaterTexturep)
-	{
-		// Create the water texture
-		LLPointer<LLImageRaw> raw = new LLImageRaw(sTextureSize/2, sTextureSize/2, 4);
-		U8 *default_texture = raw->getData();
-		for (S32 i = 0; i < sTextureSize/2; i++)
-		{
-			for (S32 j = 0; j < sTextureSize/2; j++)
-			{
-				*(default_texture + (i*sTextureSize/2 + j)*4) = MAX_WATER_COLOR.mV[0];
-				*(default_texture + (i*sTextureSize/2 + j)*4 + 1) = MAX_WATER_COLOR.mV[1];
-				*(default_texture + (i*sTextureSize/2 + j)*4 + 2) = MAX_WATER_COLOR.mV[2];
-				*(default_texture + (i*sTextureSize/2 + j)*4 + 3) = MAX_WATER_COLOR.mV[3];
-			}
-		}		
-		
-		mWaterTexturep = LLViewerTextureManager::getLocalTexture(raw.get(), FALSE);
-		mWaterTexturep->dontDiscard();
-		gGL.getTexUnit(0)->bind(mWaterTexturep);
-		mWaterTexturep->setAddressMode(LLTexUnit::TAM_CLAMP);
-	}
+    if (!mWaterTexturep)
+    {
+        // Create the water texture
+        LLPointer<LLImageRaw> raw = new LLImageRaw(sTextureSize/2, sTextureSize/2, 4);
+        U8 *default_texture = raw->getData();
+        for (S32 i = 0; i < sTextureSize/2; i++)
+        {
+            for (S32 j = 0; j < sTextureSize/2; j++)
+            {
+                *(default_texture + (i*sTextureSize/2 + j)*4) = MAX_WATER_COLOR.mV[0];
+                *(default_texture + (i*sTextureSize/2 + j)*4 + 1) = MAX_WATER_COLOR.mV[1];
+                *(default_texture + (i*sTextureSize/2 + j)*4 + 2) = MAX_WATER_COLOR.mV[2];
+                *(default_texture + (i*sTextureSize/2 + j)*4 + 3) = MAX_WATER_COLOR.mV[3];
+            }
+        }
+
+        mWaterTexturep = LLViewerTextureManager::getLocalTexture(raw.get(), FALSE);
+        mWaterTexturep->dontDiscard();
+        gGL.getTexUnit(0)->bind(mWaterTexturep);
+        mWaterTexturep->setAddressMode(LLTexUnit::TAM_CLAMP);
+    }
 }
 
 void LLSurface::initTextures()
 {
-	///////////////////////
-	//
-	// Main surface texture
-	//
-	createSTexture();
-
-	///////////////////////
-	//
-	// Water texture
-	//
-	if (gSavedSettings.getBOOL("RenderWater") )
-	{
-		createWaterTexture();
-		mWaterObjp = (LLVOWater *)gObjectList.createObjectViewer(LLViewerObject::LL_VO_WATER, mRegionp);
-		gPipeline.createObject(mWaterObjp);
-		LLVector3d water_pos_global = from_region_handle(mRegionp->getHandle());
-		water_pos_global += LLVector3d(mRegionp->getWidth()/2.0, mRegionp->getWidth()/2.0, DEFAULT_WATER_HEIGHT);
-		mWaterObjp->setPositionGlobal(water_pos_global);
-	}
+    ///////////////////////
+    //
+    // Main surface texture
+    //
+    createSTexture();
+
+    ///////////////////////
+    //
+    // Water texture
+    //
+    if (gSavedSettings.getBOOL("RenderWater") )
+    {
+        createWaterTexture();
+        mWaterObjp = (LLVOWater *)gObjectList.createObjectViewer(LLViewerObject::LL_VO_WATER, mRegionp);
+        gPipeline.createObject(mWaterObjp);
+        LLVector3d water_pos_global = from_region_handle(mRegionp->getHandle());
+        water_pos_global += LLVector3d(mRegionp->getWidth()/2.0, mRegionp->getWidth()/2.0, DEFAULT_WATER_HEIGHT);
+        mWaterObjp->setPositionGlobal(water_pos_global);
+    }
 }
 
 
-void LLSurface::setOriginGlobal(const LLVector3d &origin_global) 
+void LLSurface::setOriginGlobal(const LLVector3d &origin_global)
 {
-	LLVector3d new_origin_global;
-	mOriginGlobal = origin_global;
-	LLSurfacePatch *patchp;
-	S32 i, j;
-	// Need to update the southwest corners of the patches
-	for (j=0; j<mPatchesPerEdge; j++) 
-	{
-		for (i=0; i<mPatchesPerEdge; i++) 
-		{
-			patchp = getPatch(i, j);
-
-			new_origin_global = patchp->getOriginGlobal();
-			
-			new_origin_global.mdV[0] = mOriginGlobal.mdV[0] + i * mMetersPerGrid * mGridsPerPatchEdge;
-			new_origin_global.mdV[1] = mOriginGlobal.mdV[1] + j * mMetersPerGrid * mGridsPerPatchEdge;
-			patchp->setOriginGlobal(new_origin_global);
-		}
-	}
-
-	// Hack!
-	if (mWaterObjp.notNull() && mWaterObjp->mDrawable.notNull())
-	{
-		const F64 x = origin_global.mdV[VX] + (F64)mRegionp->getWidth() / 2.0;
-		const F64 y = origin_global.mdV[VY] + (F64)mRegionp->getWidth() / 2.0;
-		const F64 z = mWaterObjp->getPositionGlobal().mdV[VZ];
-
-		LLVector3d water_origin_global(x, y, z);
-
-		mWaterObjp->setPositionGlobal(water_origin_global);
-	}
+    LLVector3d new_origin_global;
+    mOriginGlobal = origin_global;
+    LLSurfacePatch *patchp;
+    S32 i, j;
+    // Need to update the southwest corners of the patches
+    for (j=0; j<mPatchesPerEdge; j++)
+    {
+        for (i=0; i<mPatchesPerEdge; i++)
+        {
+            patchp = getPatch(i, j);
+
+            new_origin_global = patchp->getOriginGlobal();
+
+            new_origin_global.mdV[0] = mOriginGlobal.mdV[0] + i * mMetersPerGrid * mGridsPerPatchEdge;
+            new_origin_global.mdV[1] = mOriginGlobal.mdV[1] + j * mMetersPerGrid * mGridsPerPatchEdge;
+            patchp->setOriginGlobal(new_origin_global);
+        }
+    }
+
+    // Hack!
+    if (mWaterObjp.notNull() && mWaterObjp->mDrawable.notNull())
+    {
+        const F64 x = origin_global.mdV[VX] + (F64)mRegionp->getWidth() / 2.0;
+        const F64 y = origin_global.mdV[VY] + (F64)mRegionp->getWidth() / 2.0;
+        const F64 z = mWaterObjp->getPositionGlobal().mdV[VZ];
+
+        LLVector3d water_origin_global(x, y, z);
+
+        mWaterObjp->setPositionGlobal(water_origin_global);
+    }
 }
 
 void LLSurface::getNeighboringRegions( std::vector<LLViewerRegion*>& uniqueRegions )
 {
-	S32 i;
-	for (i = 0; i < 8; i++)
-	{
-		if ( mNeighbors[i] != NULL )
-		{
-			uniqueRegions.push_back( mNeighbors[i]->getRegion() );
-		}
-	}	
+    S32 i;
+    for (i = 0; i < 8; i++)
+    {
+        if ( mNeighbors[i] != NULL )
+        {
+            uniqueRegions.push_back( mNeighbors[i]->getRegion() );
+        }
+    }
 }
 
 
 void LLSurface::getNeighboringRegionsStatus( std::vector<S32>& regions )
 {
-	S32 i;
-	for (i = 0; i < 8; i++)
-	{
-		if ( mNeighbors[i] != NULL )
-		{
-			regions.push_back( i );
-		}
-	}	
+    S32 i;
+    for (i = 0; i < 8; i++)
+    {
+        if ( mNeighbors[i] != NULL )
+        {
+            regions.push_back( i );
+        }
+    }
 }
 
 void LLSurface::connectNeighbor(LLSurface *neighborp, U32 direction)
 {
-	S32 i;
-	LLSurfacePatch *patchp, *neighbor_patchp;
-	S32 neighborPatchesPerEdge = neighborp->mPatchesPerEdge;
-
-	mNeighbors[direction] = neighborp;
-	neighborp->mNeighbors[gDirOpposite[direction]] = this;
-
-	S32 ppe[2];
-	S32 own_offset[2] = {0, 0};
-	S32 neighbor_offset[2] = {0, 0};
-	U32 own_xpos, own_ypos, neighbor_xpos, neighbor_ypos;
-
-	ppe[0] = (mPatchesPerEdge < neighborPatchesPerEdge) ? mPatchesPerEdge : neighborPatchesPerEdge; // used for x
-	ppe[1] = ppe[0]; // used for y
-
-	from_region_handle(mRegionp->getHandle(), &own_xpos, &own_ypos);
-	from_region_handle(neighborp->getRegion()->getHandle(), &neighbor_xpos, &neighbor_ypos);
-
-	if(own_ypos >= neighbor_ypos)
-	{
-		neighbor_offset[1] = (own_ypos - neighbor_ypos) / mGridsPerPatchEdge;
-		ppe[1] = llmin(mPatchesPerEdge, neighborPatchesPerEdge-neighbor_offset[1]);
-	}
-	else
-	{
-		own_offset[1] = (neighbor_ypos - own_ypos) / mGridsPerPatchEdge;
-		ppe[1] = llmin(mPatchesPerEdge-own_offset[1], neighborPatchesPerEdge);
-	}
-
-	if(own_xpos >= neighbor_xpos)
-	{
-		neighbor_offset[0] = (own_xpos - neighbor_xpos) / mGridsPerPatchEdge;
-		ppe[0] = llmin(mPatchesPerEdge, neighborPatchesPerEdge-neighbor_offset[0]);
-	}
-	else
-	{
-		own_offset[0] = (neighbor_xpos - own_xpos) / mGridsPerPatchEdge;
-		ppe[0] = llmin(mPatchesPerEdge-own_offset[0], neighborPatchesPerEdge);
-	}
-	// Connect patches
-	if (NORTHEAST == direction)
-	{
-		patchp = getPatch(mPatchesPerEdge - 1, mPatchesPerEdge - 1);
-		neighbor_patchp = neighborp->getPatch(neighbor_offset[0], neighbor_offset[1]);
-
-		patchp->connectNeighbor(neighbor_patchp, direction);
-		neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
-
-		patchp->updateNorthEdge(); // Only update one of north or east.
-		patchp->dirtyZ();
-	}
-	else if (NORTHWEST == direction)
-	{
-		S32 off = mPatchesPerEdge + neighbor_offset[1] - own_offset[1];
-		patchp = getPatch(0, mPatchesPerEdge - 1);
-		neighbor_patchp = neighborp->getPatch(neighbor_offset[0] - 1, off); //neighborPatchesPerEdge - 1
-		if (!neighbor_patchp)
-		{
-			mNeighbors[direction] = NULL;
-			return;
-		}
-
-		patchp->connectNeighbor(neighbor_patchp, direction);
-		neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
-	}
-	else if (SOUTHWEST == direction)
-	{
-		patchp = getPatch(0, 0);
-		neighbor_patchp = neighborp->getPatch(neighbor_offset[0] - 1, neighbor_offset[1] - 1);
-		if (!neighbor_patchp)
-		{
-			mNeighbors[direction] = NULL;
-			return;
-		}
-
-		patchp->connectNeighbor(neighbor_patchp, direction);
-		neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
-
-		neighbor_patchp->updateEastEdge(); // Only update one of north or east.
-		neighbor_patchp->dirtyZ();
-	}
-	else if (SOUTHEAST == direction)
-	{
-		S32 off = mPatchesPerEdge + neighbor_offset[0] - own_offset[0];
-		patchp = getPatch(mPatchesPerEdge - 1, 0);
-		neighbor_patchp = neighborp->getPatch(off, neighbor_offset[1] - 1); //0
-		if (!neighbor_patchp)
-		{
-			mNeighbors[direction] = NULL;
-			return;
-		}
-
-		patchp->connectNeighbor(neighbor_patchp, direction);
-		neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
-	}
-	else if (EAST == direction)
-	{
-		// Do east/west connections, first
-		for (i = 0; i < ppe[1]; i++)
-		{
-			patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]);
-			neighbor_patchp = neighborp->getPatch(0, i + neighbor_offset[1]);
-
-			patchp->connectNeighbor(neighbor_patchp, direction);
-			neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
-
-			patchp->updateEastEdge();
-			patchp->dirtyZ();
-		}
-
-		// Now do northeast/southwest connections
-		for (i = 0; i < ppe[1] - 1; i++)
-		{
-			patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]);
-			neighbor_patchp = neighborp->getPatch(0, i+1 + neighbor_offset[1]);
-
-			patchp->connectNeighbor(neighbor_patchp, NORTHEAST);
-			neighbor_patchp->connectNeighbor(patchp, SOUTHWEST);
-		}
-		// Now do southeast/northwest connections
-		for (i = 1; i < ppe[1]; i++)
-		{
-			patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]);
-			neighbor_patchp = neighborp->getPatch(0, i-1 + neighbor_offset[1]);
-
-			patchp->connectNeighbor(neighbor_patchp, SOUTHEAST);
-			neighbor_patchp->connectNeighbor(patchp, NORTHWEST);
-		}
-	}
-	else if (NORTH == direction)
-	{
-		// Do north/south connections, first
-		for (i = 0; i < ppe[0]; i++)
-		{
-			patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1);
-			neighbor_patchp = neighborp->getPatch(i + neighbor_offset[0], 0);
-
-			patchp->connectNeighbor(neighbor_patchp, direction);
-			neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
-
-			patchp->updateNorthEdge();
-			patchp->dirtyZ();
-		}
-
-		// Do northeast/southwest connections
-		for (i = 0; i < ppe[0] - 1; i++)
-		{
-			patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1);
-			neighbor_patchp = neighborp->getPatch(i+1 + neighbor_offset[0], 0);
-
-			patchp->connectNeighbor(neighbor_patchp, NORTHEAST);
-			neighbor_patchp->connectNeighbor(patchp, SOUTHWEST);
-		}
-		// Do southeast/northwest connections
-		for (i = 1; i < ppe[0]; i++)
-		{
-			patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1);
-			neighbor_patchp = neighborp->getPatch(i-1 + neighbor_offset[0], 0);
-
-			patchp->connectNeighbor(neighbor_patchp, NORTHWEST);
-			neighbor_patchp->connectNeighbor(patchp, SOUTHEAST);
-		}
-	}
-	else if (WEST == direction)
-	{
-		// Do east/west connections, first
-		for (i = 0; i < ppe[1]; i++)
-		{
-			patchp = getPatch(0, i + own_offset[1]);
-			neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i + neighbor_offset[1]);
-			if (!neighbor_patchp) continue;
-
-			patchp->connectNeighbor(neighbor_patchp, direction);
-			neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
-
-			neighbor_patchp->updateEastEdge();
-			neighbor_patchp->dirtyZ();
-		}
-
-		// Now do northeast/southwest connections
-		for (i = 1; i < ppe[1]; i++)
-		{
-			patchp = getPatch(0, i + own_offset[1]);
-			neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i - 1 + neighbor_offset[1]);
-			if (!neighbor_patchp) continue;
-
-			patchp->connectNeighbor(neighbor_patchp, SOUTHWEST);
-			neighbor_patchp->connectNeighbor(patchp, NORTHEAST);
-		}
-
-		// Now do northwest/southeast connections
-		for (i = 0; i < ppe[1] - 1; i++)
-		{
-			patchp = getPatch(0, i + own_offset[1]);
-			neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i + 1 + neighbor_offset[1]);
-			if (!neighbor_patchp) continue;
-
-			patchp->connectNeighbor(neighbor_patchp, NORTHWEST);
-			neighbor_patchp->connectNeighbor(patchp, SOUTHEAST);
-		}
-	}
-	else if (SOUTH == direction)
-	{
-		// Do north/south connections, first
-		for (i = 0; i < ppe[0]; i++)
-		{
-			patchp = getPatch(i + own_offset[0], 0);
-			neighbor_patchp = neighborp->getPatch(i + neighbor_offset[0], neighborPatchesPerEdge - 1);
-			if (!neighbor_patchp) continue;
-
-			patchp->connectNeighbor(neighbor_patchp, direction);
-			neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
-
-			neighbor_patchp->updateNorthEdge();
-			neighbor_patchp->dirtyZ();
-		}
-
-		// Now do northeast/southwest connections
-		for (i = 1; i < ppe[0]; i++)
-		{
-			patchp = getPatch(i + own_offset[0], 0);
-			neighbor_patchp = neighborp->getPatch(i - 1 + neighbor_offset[0], neighborPatchesPerEdge - 1);
-
-			patchp->connectNeighbor(neighbor_patchp, SOUTHWEST);
-			neighbor_patchp->connectNeighbor(patchp, NORTHEAST);
-		}
-		// Now do northeast/southwest connections
-		for (i = 0; i < ppe[0] - 1; i++)
-		{
-			patchp = getPatch(i + own_offset[0], 0);
-			neighbor_patchp = neighborp->getPatch(i + 1 + neighbor_offset[0], neighborPatchesPerEdge - 1);
-
-			patchp->connectNeighbor(neighbor_patchp, SOUTHEAST);
-			neighbor_patchp->connectNeighbor(patchp, NORTHWEST);
-		}
-	}		
+    S32 i;
+    LLSurfacePatch *patchp, *neighbor_patchp;
+    S32 neighborPatchesPerEdge = neighborp->mPatchesPerEdge;
+
+    mNeighbors[direction] = neighborp;
+    neighborp->mNeighbors[gDirOpposite[direction]] = this;
+
+    S32 ppe[2];
+    S32 own_offset[2] = {0, 0};
+    S32 neighbor_offset[2] = {0, 0};
+    U32 own_xpos, own_ypos, neighbor_xpos, neighbor_ypos;
+
+    ppe[0] = (mPatchesPerEdge < neighborPatchesPerEdge) ? mPatchesPerEdge : neighborPatchesPerEdge; // used for x
+    ppe[1] = ppe[0]; // used for y
+
+    from_region_handle(mRegionp->getHandle(), &own_xpos, &own_ypos);
+    from_region_handle(neighborp->getRegion()->getHandle(), &neighbor_xpos, &neighbor_ypos);
+
+    if(own_ypos >= neighbor_ypos)
+    {
+        neighbor_offset[1] = (own_ypos - neighbor_ypos) / mGridsPerPatchEdge;
+        ppe[1] = llmin(mPatchesPerEdge, neighborPatchesPerEdge-neighbor_offset[1]);
+    }
+    else
+    {
+        own_offset[1] = (neighbor_ypos - own_ypos) / mGridsPerPatchEdge;
+        ppe[1] = llmin(mPatchesPerEdge-own_offset[1], neighborPatchesPerEdge);
+    }
+
+    if(own_xpos >= neighbor_xpos)
+    {
+        neighbor_offset[0] = (own_xpos - neighbor_xpos) / mGridsPerPatchEdge;
+        ppe[0] = llmin(mPatchesPerEdge, neighborPatchesPerEdge-neighbor_offset[0]);
+    }
+    else
+    {
+        own_offset[0] = (neighbor_xpos - own_xpos) / mGridsPerPatchEdge;
+        ppe[0] = llmin(mPatchesPerEdge-own_offset[0], neighborPatchesPerEdge);
+    }
+    // Connect patches
+    if (NORTHEAST == direction)
+    {
+        patchp = getPatch(mPatchesPerEdge - 1, mPatchesPerEdge - 1);
+        neighbor_patchp = neighborp->getPatch(neighbor_offset[0], neighbor_offset[1]);
+
+        patchp->connectNeighbor(neighbor_patchp, direction);
+        neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
+
+        patchp->updateNorthEdge(); // Only update one of north or east.
+        patchp->dirtyZ();
+    }
+    else if (NORTHWEST == direction)
+    {
+        S32 off = mPatchesPerEdge + neighbor_offset[1] - own_offset[1];
+        patchp = getPatch(0, mPatchesPerEdge - 1);
+        neighbor_patchp = neighborp->getPatch(neighbor_offset[0] - 1, off); //neighborPatchesPerEdge - 1
+        if (!neighbor_patchp)
+        {
+            mNeighbors[direction] = NULL;
+            return;
+        }
+
+        patchp->connectNeighbor(neighbor_patchp, direction);
+        neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
+    }
+    else if (SOUTHWEST == direction)
+    {
+        patchp = getPatch(0, 0);
+        neighbor_patchp = neighborp->getPatch(neighbor_offset[0] - 1, neighbor_offset[1] - 1);
+        if (!neighbor_patchp)
+        {
+            mNeighbors[direction] = NULL;
+            return;
+        }
+
+        patchp->connectNeighbor(neighbor_patchp, direction);
+        neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
+
+        neighbor_patchp->updateEastEdge(); // Only update one of north or east.
+        neighbor_patchp->dirtyZ();
+    }
+    else if (SOUTHEAST == direction)
+    {
+        S32 off = mPatchesPerEdge + neighbor_offset[0] - own_offset[0];
+        patchp = getPatch(mPatchesPerEdge - 1, 0);
+        neighbor_patchp = neighborp->getPatch(off, neighbor_offset[1] - 1); //0
+        if (!neighbor_patchp)
+        {
+            mNeighbors[direction] = NULL;
+            return;
+        }
+
+        patchp->connectNeighbor(neighbor_patchp, direction);
+        neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
+    }
+    else if (EAST == direction)
+    {
+        // Do east/west connections, first
+        for (i = 0; i < ppe[1]; i++)
+        {
+            patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]);
+            neighbor_patchp = neighborp->getPatch(0, i + neighbor_offset[1]);
+
+            patchp->connectNeighbor(neighbor_patchp, direction);
+            neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
+
+            patchp->updateEastEdge();
+            patchp->dirtyZ();
+        }
+
+        // Now do northeast/southwest connections
+        for (i = 0; i < ppe[1] - 1; i++)
+        {
+            patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]);
+            neighbor_patchp = neighborp->getPatch(0, i+1 + neighbor_offset[1]);
+
+            patchp->connectNeighbor(neighbor_patchp, NORTHEAST);
+            neighbor_patchp->connectNeighbor(patchp, SOUTHWEST);
+        }
+        // Now do southeast/northwest connections
+        for (i = 1; i < ppe[1]; i++)
+        {
+            patchp = getPatch(mPatchesPerEdge - 1, i + own_offset[1]);
+            neighbor_patchp = neighborp->getPatch(0, i-1 + neighbor_offset[1]);
+
+            patchp->connectNeighbor(neighbor_patchp, SOUTHEAST);
+            neighbor_patchp->connectNeighbor(patchp, NORTHWEST);
+        }
+    }
+    else if (NORTH == direction)
+    {
+        // Do north/south connections, first
+        for (i = 0; i < ppe[0]; i++)
+        {
+            patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1);
+            neighbor_patchp = neighborp->getPatch(i + neighbor_offset[0], 0);
+
+            patchp->connectNeighbor(neighbor_patchp, direction);
+            neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
+
+            patchp->updateNorthEdge();
+            patchp->dirtyZ();
+        }
+
+        // Do northeast/southwest connections
+        for (i = 0; i < ppe[0] - 1; i++)
+        {
+            patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1);
+            neighbor_patchp = neighborp->getPatch(i+1 + neighbor_offset[0], 0);
+
+            patchp->connectNeighbor(neighbor_patchp, NORTHEAST);
+            neighbor_patchp->connectNeighbor(patchp, SOUTHWEST);
+        }
+        // Do southeast/northwest connections
+        for (i = 1; i < ppe[0]; i++)
+        {
+            patchp = getPatch(i + own_offset[0], mPatchesPerEdge - 1);
+            neighbor_patchp = neighborp->getPatch(i-1 + neighbor_offset[0], 0);
+
+            patchp->connectNeighbor(neighbor_patchp, NORTHWEST);
+            neighbor_patchp->connectNeighbor(patchp, SOUTHEAST);
+        }
+    }
+    else if (WEST == direction)
+    {
+        // Do east/west connections, first
+        for (i = 0; i < ppe[1]; i++)
+        {
+            patchp = getPatch(0, i + own_offset[1]);
+            neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i + neighbor_offset[1]);
+            if (!neighbor_patchp) continue;
+
+            patchp->connectNeighbor(neighbor_patchp, direction);
+            neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
+
+            neighbor_patchp->updateEastEdge();
+            neighbor_patchp->dirtyZ();
+        }
+
+        // Now do northeast/southwest connections
+        for (i = 1; i < ppe[1]; i++)
+        {
+            patchp = getPatch(0, i + own_offset[1]);
+            neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i - 1 + neighbor_offset[1]);
+            if (!neighbor_patchp) continue;
+
+            patchp->connectNeighbor(neighbor_patchp, SOUTHWEST);
+            neighbor_patchp->connectNeighbor(patchp, NORTHEAST);
+        }
+
+        // Now do northwest/southeast connections
+        for (i = 0; i < ppe[1] - 1; i++)
+        {
+            patchp = getPatch(0, i + own_offset[1]);
+            neighbor_patchp = neighborp->getPatch(neighborPatchesPerEdge - 1, i + 1 + neighbor_offset[1]);
+            if (!neighbor_patchp) continue;
+
+            patchp->connectNeighbor(neighbor_patchp, NORTHWEST);
+            neighbor_patchp->connectNeighbor(patchp, SOUTHEAST);
+        }
+    }
+    else if (SOUTH == direction)
+    {
+        // Do north/south connections, first
+        for (i = 0; i < ppe[0]; i++)
+        {
+            patchp = getPatch(i + own_offset[0], 0);
+            neighbor_patchp = neighborp->getPatch(i + neighbor_offset[0], neighborPatchesPerEdge - 1);
+            if (!neighbor_patchp) continue;
+
+            patchp->connectNeighbor(neighbor_patchp, direction);
+            neighbor_patchp->connectNeighbor(patchp, gDirOpposite[direction]);
+
+            neighbor_patchp->updateNorthEdge();
+            neighbor_patchp->dirtyZ();
+        }
+
+        // Now do northeast/southwest connections
+        for (i = 1; i < ppe[0]; i++)
+        {
+            patchp = getPatch(i + own_offset[0], 0);
+            neighbor_patchp = neighborp->getPatch(i - 1 + neighbor_offset[0], neighborPatchesPerEdge - 1);
+
+            patchp->connectNeighbor(neighbor_patchp, SOUTHWEST);
+            neighbor_patchp->connectNeighbor(patchp, NORTHEAST);
+        }
+        // Now do northeast/southwest connections
+        for (i = 0; i < ppe[0] - 1; i++)
+        {
+            patchp = getPatch(i + own_offset[0], 0);
+            neighbor_patchp = neighborp->getPatch(i + 1 + neighbor_offset[0], neighborPatchesPerEdge - 1);
+
+            patchp->connectNeighbor(neighbor_patchp, SOUTHEAST);
+            neighbor_patchp->connectNeighbor(patchp, NORTHWEST);
+        }
+    }
 }
 
 void LLSurface::disconnectNeighbor(LLSurface *surfacep)
 {
-	S32 i;
-	for (i = 0; i < 8; i++)
-	{
-		if (surfacep == mNeighbors[i])
-		{
-			mNeighbors[i] = NULL;
-		}
-	}
-
-	// Iterate through surface patches, removing any connectivity to removed surface.
-	for (i = 0; i < mNumberOfPatches; i++)
-	{
-		(mPatchList + i)->disconnectNeighbor(surfacep);
-	}
+    S32 i;
+    for (i = 0; i < 8; i++)
+    {
+        if (surfacep == mNeighbors[i])
+        {
+            mNeighbors[i] = NULL;
+        }
+    }
+
+    // Iterate through surface patches, removing any connectivity to removed surface.
+    for (i = 0; i < mNumberOfPatches; i++)
+    {
+        (mPatchList + i)->disconnectNeighbor(surfacep);
+    }
 }
 
 
 void LLSurface::disconnectAllNeighbors()
 {
-	S32 i;
-	for (i = 0; i < 8; i++)
-	{
-		if (mNeighbors[i])
-		{
-			mNeighbors[i]->disconnectNeighbor(this);
-			mNeighbors[i] = NULL;
-		}
-	}
+    S32 i;
+    for (i = 0; i < 8; i++)
+    {
+        if (mNeighbors[i])
+        {
+            mNeighbors[i]->disconnectNeighbor(this);
+            mNeighbors[i] = NULL;
+        }
+    }
 }
 
 
 
 const LLVector3d &LLSurface::getOriginGlobal() const
 {
-	return mOriginGlobal;
+    return mOriginGlobal;
 }
 
 LLVector3 LLSurface::getOriginAgent() const
 {
-	return gAgent.getPosAgentFromGlobal(mOriginGlobal);
+    return gAgent.getPosAgentFromGlobal(mOriginGlobal);
 }
 
 F32 LLSurface::getMetersPerGrid() const
 {
-	return mMetersPerGrid;
+    return mMetersPerGrid;
 }
 
 S32 LLSurface::getGridsPerEdge() const
 {
-	return mGridsPerEdge;
+    return mGridsPerEdge;
 }
 
 S32 LLSurface::getPatchesPerEdge() const
 {
-	return mPatchesPerEdge;
+    return mPatchesPerEdge;
 }
 
 S32 LLSurface::getGridsPerPatchEdge() const
 {
-	return mGridsPerPatchEdge;
+    return mGridsPerPatchEdge;
 }
 
 void LLSurface::moveZ(const S32 x, const S32 y, const F32 delta)
 {
-	llassert(x >= 0);
-	llassert(y >= 0);
-	llassert(x < mGridsPerEdge);
-	llassert(y < mGridsPerEdge);
-	mSurfaceZ[x + y*mGridsPerEdge] += delta;
+    llassert(x >= 0);
+    llassert(y >= 0);
+    llassert(x < mGridsPerEdge);
+    llassert(y < mGridsPerEdge);
+    mSurfaceZ[x + y*mGridsPerEdge] += delta;
 }
 
 
-void LLSurface::updatePatchVisibilities(LLAgent &agent) 
+void LLSurface::updatePatchVisibilities(LLAgent &agent)
 {
-	if (gShiftFrame)
-	{
-		return;
-	}
-
-	LLVector3 pos_region = mRegionp->getPosRegionFromGlobal(gAgentCamera.getCameraPositionGlobal());
-
-	LLSurfacePatch *patchp;
-	
-	mVisiblePatchCount = 0;
-	for (S32 i=0; i<mNumberOfPatches; i++) 
-	{
-		patchp = mPatchList + i;
-
-		patchp->updateVisibility();
-		if (patchp->getVisible())
-		{
-			mVisiblePatchCount++;
-			patchp->updateCameraDistanceRegion(pos_region);
-		}
-	}
+    if (gShiftFrame)
+    {
+        return;
+    }
+
+    LLVector3 pos_region = mRegionp->getPosRegionFromGlobal(gAgentCamera.getCameraPositionGlobal());
+
+    LLSurfacePatch *patchp;
+
+    mVisiblePatchCount = 0;
+    for (S32 i=0; i<mNumberOfPatches; i++)
+    {
+        patchp = mPatchList + i;
+
+        patchp->updateVisibility();
+        if (patchp->getVisible())
+        {
+            mVisiblePatchCount++;
+            patchp->updateCameraDistanceRegion(pos_region);
+        }
+    }
 }
 
 template<bool PBR>
 bool LLSurface::idleUpdate(F32 max_update_time)
 {
-	if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_TERRAIN))
-	{
-		return false;
-	}
-	
-	// Perform idle time update of non-critical stuff.
-	// In this case, texture and normal updates.
-	LLTimer update_timer;
-	bool did_update = false;
-
-	// If the Z height data has changed, we need to rebuild our
-	// property line vertex arrays.
-	if (!mDirtyPatchList.empty())
-	{
-		getRegion()->dirtyHeights();
-	}
-
-	// Always call updateNormals() / updateVerticalStats()
-	//  every frame to avoid artifacts
-	for(std::set<LLSurfacePatch *>::iterator iter = mDirtyPatchList.begin();
-		iter != mDirtyPatchList.end(); )
-	{
-		std::set<LLSurfacePatch *>::iterator curiter = iter++;
-		LLSurfacePatch *patchp = *curiter;
-		patchp->updateNormals<PBR>();
-		patchp->updateVerticalStats();
-		if (max_update_time == 0.f || update_timer.getElapsedTimeF32() < max_update_time)
-		{
-			if (patchp->updateTexture())
-			{
-				did_update = true;
-				patchp->clearDirty();
-				mDirtyPatchList.erase(curiter);
-			}
-		}
-	}
+    if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_TERRAIN))
+    {
+        return false;
+    }
+
+    // Perform idle time update of non-critical stuff.
+    // In this case, texture and normal updates.
+    LLTimer update_timer;
+    bool did_update = false;
+
+    // If the Z height data has changed, we need to rebuild our
+    // property line vertex arrays.
+    if (!mDirtyPatchList.empty())
+    {
+        getRegion()->dirtyHeights();
+    }
+
+    // Always call updateNormals() / updateVerticalStats()
+    //  every frame to avoid artifacts
+    for(std::set<LLSurfacePatch *>::iterator iter = mDirtyPatchList.begin();
+        iter != mDirtyPatchList.end(); )
+    {
+        std::set<LLSurfacePatch *>::iterator curiter = iter++;
+        LLSurfacePatch *patchp = *curiter;
+        patchp->updateNormals<PBR>();
+        patchp->updateVerticalStats();
+        if (max_update_time == 0.f || update_timer.getElapsedTimeF32() < max_update_time)
+        {
+            if (patchp->updateTexture())
+            {
+                did_update = true;
+                patchp->clearDirty();
+                mDirtyPatchList.erase(curiter);
+            }
+        }
+    }
 
     if (did_update)
     {
@@ -744,84 +744,84 @@ bool LLSurface::idleUpdate(F32 max_update_time)
         mRegionp->updateReflectionProbes();
     }
 
-	return did_update;
+    return did_update;
 }
 
 template bool LLSurface::idleUpdate</*PBR=*/false>(F32 max_update_time);
 template bool LLSurface::idleUpdate</*PBR=*/true>(F32 max_update_time);
 
-void LLSurface::decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL b_large_patch) 
+void LLSurface::decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL b_large_patch)
 {
 
-	LLPatchHeader  ph;
-	S32 j, i;
-	S32 patch[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
-	LLSurfacePatch *patchp;
-
-	init_patch_decompressor(gopp->patch_size);
-	gopp->stride = mGridsPerEdge;
-	set_group_of_patch_header(gopp);
-
-	while (1)
-	{
-		decode_patch_header(bitpack, &ph, b_large_patch);
-		if (ph.quant_wbits == END_OF_PATCHES)
-		{
-			break;
-		}
-
-		if (b_large_patch)
-		{
-			i = ph.patchids >> 16; //x
-			j = ph.patchids & 0xFFFF; //y
-		}
-		else
-		{
-			i = ph.patchids >> 5; //x
-			j = ph.patchids & 0x1F; //y
-		}
-
-		if ((i >= mPatchesPerEdge) || (j >= mPatchesPerEdge))
-		{
-			LL_WARNS() << "Received invalid terrain packet - patch header patch ID incorrect!" 
-				<< " patches per edge " << mPatchesPerEdge
-				<< " i " << i
-				<< " j " << j
-				<< " dc_offset " << ph.dc_offset
-				<< " range " << (S32)ph.range
-				<< " quant_wbits " << (S32)ph.quant_wbits
-				<< " patchids " << (S32)ph.patchids
-				<< LL_ENDL;
-			return;
-		}
-
-		patchp = &mPatchList[j*mPatchesPerEdge + i];
-
-
-		decode_patch(bitpack, patch);
-		decompress_patch(patchp->getDataZ(), patch, &ph);
-
-		// Update edges for neighbors.  Need to guarantee that this gets done before we generate vertical stats.
-		patchp->updateNorthEdge();
-		patchp->updateEastEdge();
-		if (patchp->getNeighborPatch(WEST))
-		{
-			patchp->getNeighborPatch(WEST)->updateEastEdge();
-		}
-		if (patchp->getNeighborPatch(SOUTHWEST))
-		{
-			patchp->getNeighborPatch(SOUTHWEST)->updateEastEdge();
-			patchp->getNeighborPatch(SOUTHWEST)->updateNorthEdge();
-		}
-		if (patchp->getNeighborPatch(SOUTH))
-		{
-			patchp->getNeighborPatch(SOUTH)->updateNorthEdge();
-		}
-
-		// Dirty patch statistics, and flag that the patch has data.
-		patchp->dirtyZ();
-		patchp->setHasReceivedData();
-	}
+    LLPatchHeader  ph;
+    S32 j, i;
+    S32 patch[LARGE_PATCH_SIZE*LARGE_PATCH_SIZE];
+    LLSurfacePatch *patchp;
+
+    init_patch_decompressor(gopp->patch_size);
+    gopp->stride = mGridsPerEdge;
+    set_group_of_patch_header(gopp);
+
+    while (1)
+    {
+        decode_patch_header(bitpack, &ph, b_large_patch);
+        if (ph.quant_wbits == END_OF_PATCHES)
+        {
+            break;
+        }
+
+        if (b_large_patch)
+        {
+            i = ph.patchids >> 16; //x
+            j = ph.patchids & 0xFFFF; //y
+        }
+        else
+        {
+            i = ph.patchids >> 5; //x
+            j = ph.patchids & 0x1F; //y
+        }
+
+        if ((i >= mPatchesPerEdge) || (j >= mPatchesPerEdge))
+        {
+            LL_WARNS() << "Received invalid terrain packet - patch header patch ID incorrect!"
+                << " patches per edge " << mPatchesPerEdge
+                << " i " << i
+                << " j " << j
+                << " dc_offset " << ph.dc_offset
+                << " range " << (S32)ph.range
+                << " quant_wbits " << (S32)ph.quant_wbits
+                << " patchids " << (S32)ph.patchids
+                << LL_ENDL;
+            return;
+        }
+
+        patchp = &mPatchList[j*mPatchesPerEdge + i];
+
+
+        decode_patch(bitpack, patch);
+        decompress_patch(patchp->getDataZ(), patch, &ph);
+
+        // Update edges for neighbors.  Need to guarantee that this gets done before we generate vertical stats.
+        patchp->updateNorthEdge();
+        patchp->updateEastEdge();
+        if (patchp->getNeighborPatch(WEST))
+        {
+            patchp->getNeighborPatch(WEST)->updateEastEdge();
+        }
+        if (patchp->getNeighborPatch(SOUTHWEST))
+        {
+            patchp->getNeighborPatch(SOUTHWEST)->updateEastEdge();
+            patchp->getNeighborPatch(SOUTHWEST)->updateNorthEdge();
+        }
+        if (patchp->getNeighborPatch(SOUTH))
+        {
+            patchp->getNeighborPatch(SOUTH)->updateNorthEdge();
+        }
+
+        // Dirty patch statistics, and flag that the patch has data.
+        patchp->dirtyZ();
+        patchp->setHasReceivedData();
+    }
 }
 
 
@@ -829,157 +829,157 @@ void LLSurface::decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL
 // "position" is region-local
 BOOL LLSurface::containsPosition(const LLVector3 &position)
 {
-	if (position.mV[VX] < 0.0f  ||  position.mV[VX] > mMetersPerEdge ||
-		position.mV[VY] < 0.0f  ||  position.mV[VY] > mMetersPerEdge)
-	{
-		return FALSE;
-	}
-	return TRUE;
+    if (position.mV[VX] < 0.0f  ||  position.mV[VX] > mMetersPerEdge ||
+        position.mV[VY] < 0.0f  ||  position.mV[VY] > mMetersPerEdge)
+    {
+        return FALSE;
+    }
+    return TRUE;
 }
 
 
 F32 LLSurface::resolveHeightRegion(const F32 x, const F32 y) const
 {
-	F32 height = 0.0f;
-	F32 oometerspergrid = 1.f/mMetersPerGrid;
-
-	// Check to see if v is actually above surface 
-	// We use (mGridsPerEdge-1) below rather than (mGridsPerEdge) 
-	// becuase of the east and north buffers 
-
-	if (x >= 0.f  &&  
-		x <= mMetersPerEdge  &&
-		y >= 0.f  &&  
-		y <= mMetersPerEdge)
-	{
-		const S32 left   = llfloor(x * oometerspergrid);
-		const S32 bottom = llfloor(y * oometerspergrid);
-
-		// Don't walk off the edge of the array!
-		const S32 right  = ( left+1   < (S32)mGridsPerEdge-1 ? left+1   : left );
-		const S32 top    = ( bottom+1 < (S32)mGridsPerEdge-1 ? bottom+1 : bottom );
-
-		// Figure out if v is in first or second triangle of the square
-		// and calculate the slopes accordingly
-		//    |       |
-		// -(i,j+1)---(i+1,j+1)--   
-		//    |  1   /  |          ^
-		//    |    /  2 |          |
-		//    |  /      |          j
-		// --(i,j)----(i+1,j)--
-		//    |       |
-		// 
-		//      i ->
-		// where N = mGridsPerEdge
-
-		const F32 left_bottom  = getZ( left,  bottom );
-		const F32 right_bottom = getZ( right, bottom );
-		const F32 left_top     = getZ( left,  top );
-		const F32 right_top    = getZ( right, top );
-
-		// dx and dy are incremental steps from (mSurface + k)
-		F32 dx = x - left   * mMetersPerGrid;
-		F32 dy = y - bottom * mMetersPerGrid;
-
-		if (dy > dx) 
-		{
-			// triangle 1
-			dy *= left_top  - left_bottom;
-			dx *= right_top - left_top;
-		}
-		else 
-		{
-			// triangle 2
-			dx *= right_bottom - left_bottom;
-			dy *= right_top    - right_bottom;
-		}
-		height = left_bottom + (dx + dy) * oometerspergrid;
-	}
-	return height;
+    F32 height = 0.0f;
+    F32 oometerspergrid = 1.f/mMetersPerGrid;
+
+    // Check to see if v is actually above surface
+    // We use (mGridsPerEdge-1) below rather than (mGridsPerEdge)
+    // becuase of the east and north buffers
+
+    if (x >= 0.f  &&
+        x <= mMetersPerEdge  &&
+        y >= 0.f  &&
+        y <= mMetersPerEdge)
+    {
+        const S32 left   = llfloor(x * oometerspergrid);
+        const S32 bottom = llfloor(y * oometerspergrid);
+
+        // Don't walk off the edge of the array!
+        const S32 right  = ( left+1   < (S32)mGridsPerEdge-1 ? left+1   : left );
+        const S32 top    = ( bottom+1 < (S32)mGridsPerEdge-1 ? bottom+1 : bottom );
+
+        // Figure out if v is in first or second triangle of the square
+        // and calculate the slopes accordingly
+        //    |       |
+        // -(i,j+1)---(i+1,j+1)--
+        //    |  1   /  |          ^
+        //    |    /  2 |          |
+        //    |  /      |          j
+        // --(i,j)----(i+1,j)--
+        //    |       |
+        //
+        //      i ->
+        // where N = mGridsPerEdge
+
+        const F32 left_bottom  = getZ( left,  bottom );
+        const F32 right_bottom = getZ( right, bottom );
+        const F32 left_top     = getZ( left,  top );
+        const F32 right_top    = getZ( right, top );
+
+        // dx and dy are incremental steps from (mSurface + k)
+        F32 dx = x - left   * mMetersPerGrid;
+        F32 dy = y - bottom * mMetersPerGrid;
+
+        if (dy > dx)
+        {
+            // triangle 1
+            dy *= left_top  - left_bottom;
+            dx *= right_top - left_top;
+        }
+        else
+        {
+            // triangle 2
+            dx *= right_bottom - left_bottom;
+            dy *= right_top    - right_bottom;
+        }
+        height = left_bottom + (dx + dy) * oometerspergrid;
+    }
+    return height;
 }
 
 
 F32 LLSurface::resolveHeightGlobal(const LLVector3d& v) const
 {
-	if (!mRegionp)
-	{
-		return 0.f;
-	}
-	
-	LLVector3 pos_region = mRegionp->getPosRegionFromGlobal(v);
-
-	return resolveHeightRegion(pos_region);
+    if (!mRegionp)
+    {
+        return 0.f;
+    }
+
+    LLVector3 pos_region = mRegionp->getPosRegionFromGlobal(v);
+
+    return resolveHeightRegion(pos_region);
 }
 
 
 LLVector3 LLSurface::resolveNormalGlobal(const LLVector3d& pos_global) const
 {
-	if (!mSurfaceZ)
-	{
-		// Hmm.  Uninitialized surface!
-		return LLVector3::z_axis;
-	}
-	//
-	// Returns the vector normal to a surface at location specified by vector v
-	//
-	F32 oometerspergrid = 1.f/mMetersPerGrid;
-	LLVector3 normal;
-	F32 dzx, dzy;
-
-	if (pos_global.mdV[VX] >= mOriginGlobal.mdV[VX]  &&  
-		pos_global.mdV[VX] < mOriginGlobal.mdV[VX] + mMetersPerEdge  &&
-		pos_global.mdV[VY] >= mOriginGlobal.mdV[VY]  &&  
-		pos_global.mdV[VY] < mOriginGlobal.mdV[VY] + mMetersPerEdge)
-	{
-		U32 i, j, k;
-		F32 dx, dy;
-		i = (U32) ((pos_global.mdV[VX] - mOriginGlobal.mdV[VX]) * oometerspergrid);
-		j = (U32) ((pos_global.mdV[VY] - mOriginGlobal.mdV[VY]) * oometerspergrid );
-		k = i + j*mGridsPerEdge;
-
-		// Figure out if v is in first or second triangle of the square
-		// and calculate the slopes accordingly
-		//    |       |
-		// -(k+N)---(k+1+N)--   
-		//    |  1 /  |          ^
-		//    |   / 2 |          |
-		//    |  /    |          j
-		// --(k)----(k+1)--
-		//    |       |
-		// 
-		//      i ->
-		// where N = mGridsPerEdge
-
-		// dx and dy are incremental steps from (mSurface + k)
-		dx = (F32)(pos_global.mdV[VX] - i*mMetersPerGrid - mOriginGlobal.mdV[VX]);
-		dy = (F32)(pos_global.mdV[VY] - j*mMetersPerGrid - mOriginGlobal.mdV[VY]);
-		if (dy > dx) 
-		{  // triangle 1
-			dzx = *(mSurfaceZ + k + 1 + mGridsPerEdge) - *(mSurfaceZ + k + mGridsPerEdge);
-			dzy = *(mSurfaceZ + k) - *(mSurfaceZ + k + mGridsPerEdge);
-			normal.setVec(-dzx,dzy,1);
-		}
-		else 
-		{	// triangle 2
-			dzx = *(mSurfaceZ + k) - *(mSurfaceZ + k + 1);
-			dzy = *(mSurfaceZ + k + 1 + mGridsPerEdge) - *(mSurfaceZ + k + 1);
-			normal.setVec(dzx,-dzy,1);
-		}
-	}
-	normal.normVec();
-	return normal;
+    if (!mSurfaceZ)
+    {
+        // Hmm.  Uninitialized surface!
+        return LLVector3::z_axis;
+    }
+    //
+    // Returns the vector normal to a surface at location specified by vector v
+    //
+    F32 oometerspergrid = 1.f/mMetersPerGrid;
+    LLVector3 normal;
+    F32 dzx, dzy;
+
+    if (pos_global.mdV[VX] >= mOriginGlobal.mdV[VX]  &&
+        pos_global.mdV[VX] < mOriginGlobal.mdV[VX] + mMetersPerEdge  &&
+        pos_global.mdV[VY] >= mOriginGlobal.mdV[VY]  &&
+        pos_global.mdV[VY] < mOriginGlobal.mdV[VY] + mMetersPerEdge)
+    {
+        U32 i, j, k;
+        F32 dx, dy;
+        i = (U32) ((pos_global.mdV[VX] - mOriginGlobal.mdV[VX]) * oometerspergrid);
+        j = (U32) ((pos_global.mdV[VY] - mOriginGlobal.mdV[VY]) * oometerspergrid );
+        k = i + j*mGridsPerEdge;
+
+        // Figure out if v is in first or second triangle of the square
+        // and calculate the slopes accordingly
+        //    |       |
+        // -(k+N)---(k+1+N)--
+        //    |  1 /  |          ^
+        //    |   / 2 |          |
+        //    |  /    |          j
+        // --(k)----(k+1)--
+        //    |       |
+        //
+        //      i ->
+        // where N = mGridsPerEdge
+
+        // dx and dy are incremental steps from (mSurface + k)
+        dx = (F32)(pos_global.mdV[VX] - i*mMetersPerGrid - mOriginGlobal.mdV[VX]);
+        dy = (F32)(pos_global.mdV[VY] - j*mMetersPerGrid - mOriginGlobal.mdV[VY]);
+        if (dy > dx)
+        {  // triangle 1
+            dzx = *(mSurfaceZ + k + 1 + mGridsPerEdge) - *(mSurfaceZ + k + mGridsPerEdge);
+            dzy = *(mSurfaceZ + k) - *(mSurfaceZ + k + mGridsPerEdge);
+            normal.setVec(-dzx,dzy,1);
+        }
+        else
+        {   // triangle 2
+            dzx = *(mSurfaceZ + k) - *(mSurfaceZ + k + 1);
+            dzy = *(mSurfaceZ + k + 1 + mGridsPerEdge) - *(mSurfaceZ + k + 1);
+            normal.setVec(dzx,-dzy,1);
+        }
+    }
+    normal.normVec();
+    return normal;
 
 
 }
 
 LLSurfacePatch *LLSurface::resolvePatchRegion(const F32 x, const F32 y) const
 {
-// x and y should be region-local coordinates. 
+// x and y should be region-local coordinates.
 // If x and y are outside of the surface, then the returned
 // index will be for the nearest boundary patch.
 //
 // 12      | 13| 14|       15
-//         |   |   |    
+//         |   |   |
 //     +---+---+---+---+
 //     | 12| 13| 14| 15|
 // ----+---+---+---+---+-----
@@ -989,393 +989,393 @@ LLSurfacePatch *LLSurface::resolvePatchRegion(const F32 x, const F32 y) const
 // ----+---+---+---+---+-----
 //     | 0 | 1 | 2 | 3 |
 //     +---+---+---+---+
-//         |   |   |    
+//         |   |   |
 // 0       | 1 | 2 |        3
 //
 
 // When x and y are not region-local do the following first
 
-	S32 i, j;
-	if (x < 0.0f)
-	{
-		i = 0;
-	}
-	else if (x >= mMetersPerEdge)
-	{
-		i = mPatchesPerEdge - 1;
-	}
-	else
-	{
-		i = (U32) (x / (mMetersPerGrid * mGridsPerPatchEdge));
-	}
-
-	if (y < 0.0f)
-	{
-		j = 0;
-	}
-	else if (y >= mMetersPerEdge)
-	{
-		j = mPatchesPerEdge - 1;
-	}
-	else
-	{
-		j = (U32) (y / (mMetersPerGrid * mGridsPerPatchEdge));
-	}
-
-	// *NOTE: Super paranoia code follows.
-	S32 index = i + j * mPatchesPerEdge;
-	if((index < 0) || (index >= mNumberOfPatches))
-	{
-		if(0 == mNumberOfPatches)
-		{
-			LL_WARNS() << "No patches for current region!" << LL_ENDL;
-			return NULL;
-		}
-		S32 old_index = index;
-		index = llclamp(old_index, 0, (mNumberOfPatches - 1));
-		LL_WARNS() << "Clamping out of range patch index " << old_index
-				<< " to " << index << LL_ENDL;
-	}
-	return &(mPatchList[index]);
+    S32 i, j;
+    if (x < 0.0f)
+    {
+        i = 0;
+    }
+    else if (x >= mMetersPerEdge)
+    {
+        i = mPatchesPerEdge - 1;
+    }
+    else
+    {
+        i = (U32) (x / (mMetersPerGrid * mGridsPerPatchEdge));
+    }
+
+    if (y < 0.0f)
+    {
+        j = 0;
+    }
+    else if (y >= mMetersPerEdge)
+    {
+        j = mPatchesPerEdge - 1;
+    }
+    else
+    {
+        j = (U32) (y / (mMetersPerGrid * mGridsPerPatchEdge));
+    }
+
+    // *NOTE: Super paranoia code follows.
+    S32 index = i + j * mPatchesPerEdge;
+    if((index < 0) || (index >= mNumberOfPatches))
+    {
+        if(0 == mNumberOfPatches)
+        {
+            LL_WARNS() << "No patches for current region!" << LL_ENDL;
+            return NULL;
+        }
+        S32 old_index = index;
+        index = llclamp(old_index, 0, (mNumberOfPatches - 1));
+        LL_WARNS() << "Clamping out of range patch index " << old_index
+                << " to " << index << LL_ENDL;
+    }
+    return &(mPatchList[index]);
 }
 
 
 LLSurfacePatch *LLSurface::resolvePatchRegion(const LLVector3 &pos_region) const
 {
-	return resolvePatchRegion(pos_region.mV[VX], pos_region.mV[VY]);
+    return resolvePatchRegion(pos_region.mV[VX], pos_region.mV[VY]);
 }
 
 
 LLSurfacePatch *LLSurface::resolvePatchGlobal(const LLVector3d &pos_global) const
 {
-	llassert(mRegionp);
-	LLVector3 pos_region = mRegionp->getPosRegionFromGlobal(pos_global);
-	return resolvePatchRegion(pos_region);
+    llassert(mRegionp);
+    LLVector3 pos_region = mRegionp->getPosRegionFromGlobal(pos_global);
+    return resolvePatchRegion(pos_region);
 }
 
 
-std::ostream& operator<<(std::ostream &s, const LLSurface &S) 
+std::ostream& operator<<(std::ostream &s, const LLSurface &S)
 {
-	s << "{ \n";
-	s << "  mGridsPerEdge = " << S.mGridsPerEdge - 1 << " + 1\n";
-	s << "  mGridsPerPatchEdge = " << S.mGridsPerPatchEdge << "\n";
-	s << "  mPatchesPerEdge = " << S.mPatchesPerEdge << "\n";
-	s << "  mOriginGlobal = " << S.mOriginGlobal << "\n";
-	s << "  mMetersPerGrid = " << S.mMetersPerGrid << "\n";
-	s << "  mVisiblePatchCount = " << S.mVisiblePatchCount << "\n";
-	s << "}";
-	return s;
+    s << "{ \n";
+    s << "  mGridsPerEdge = " << S.mGridsPerEdge - 1 << " + 1\n";
+    s << "  mGridsPerPatchEdge = " << S.mGridsPerPatchEdge << "\n";
+    s << "  mPatchesPerEdge = " << S.mPatchesPerEdge << "\n";
+    s << "  mOriginGlobal = " << S.mOriginGlobal << "\n";
+    s << "  mMetersPerGrid = " << S.mMetersPerGrid << "\n";
+    s << "  mVisiblePatchCount = " << S.mVisiblePatchCount << "\n";
+    s << "}";
+    return s;
 }
 
 
 // ---------------- LLSurface:: Protected ----------------
 
-void LLSurface::createPatchData() 
+void LLSurface::createPatchData()
 {
-	// Assumes mGridsPerEdge, mGridsPerPatchEdge, and mPatchesPerEdge have been properly set
-	// TODO -- check for create() called when surface is not empty
-	S32 i, j;
-	LLSurfacePatch *patchp;
-
-	// Allocate memory
-	mPatchList = new LLSurfacePatch[mNumberOfPatches];
-
-	// One of each for each camera
-	mVisiblePatchCount = mNumberOfPatches;
-
-	for (j=0; j<mPatchesPerEdge; j++) 
-	{
-		for (i=0; i<mPatchesPerEdge; i++) 
-		{
-			patchp = getPatch(i, j);
-			patchp->setSurface(this);
-		}
-	}
-
-	for (j=0; j<mPatchesPerEdge; j++) 
-	{
-		for (i=0; i<mPatchesPerEdge; i++) 
-		{
-			patchp = getPatch(i, j);
-			patchp->mHasReceivedData = FALSE;
-			patchp->mSTexUpdate = TRUE;
-
-			S32 data_offset = i * mGridsPerPatchEdge + j * mGridsPerPatchEdge * mGridsPerEdge;
-
-			patchp->setDataZ(mSurfaceZ + data_offset);
-			patchp->setDataNorm(mNorm + data_offset);
-
-
-			// We make each patch point to its neighbors so we can do resolution checking 
-			// when butting up different resolutions.  Patches that don't have neighbors
-			// somewhere will point to NULL on that side.
-			if (i < mPatchesPerEdge-1)  
-			{
-				patchp->setNeighborPatch(EAST,getPatch(i+1, j));
-			}
-			else 
-			{
-				patchp->setNeighborPatch(EAST, NULL);
-			}
-
-			if (j < mPatchesPerEdge-1)  
-			{
-				patchp->setNeighborPatch(NORTH, getPatch(i, j+1));
-			}
-			else 
-			{
-				patchp->setNeighborPatch(NORTH, NULL);
-			}
-
-			if (i > 0) 
-			{
-				patchp->setNeighborPatch(WEST, getPatch(i - 1, j));
-			}
-			else 
-			{
-				patchp->setNeighborPatch(WEST, NULL);
-			}
-
-			if (j > 0)  
-			{
-				patchp->setNeighborPatch(SOUTH, getPatch(i, j-1));
-			}
-			else 
-			{
-				patchp->setNeighborPatch(SOUTH, NULL);
-			}
-
-			if (i < (mPatchesPerEdge-1)  &&  j < (mPatchesPerEdge-1)) 
-			{
-				patchp->setNeighborPatch(NORTHEAST, getPatch(i + 1, j + 1));
-			}
-			else 
-			{
-				patchp->setNeighborPatch(NORTHEAST, NULL);		
-			}
-
-			if (i > 0  &&  j < (mPatchesPerEdge-1)) 
-			{
-				patchp->setNeighborPatch(NORTHWEST, getPatch(i - 1, j + 1));
-			}
-			else 
-			{
-				patchp->setNeighborPatch(NORTHWEST, NULL);
-			}
-
-			if (i > 0  &&  j > 0) 
-			{
-				patchp->setNeighborPatch(SOUTHWEST, getPatch(i - 1, j - 1));
-			}
-			else 
-			{
-				patchp->setNeighborPatch(SOUTHWEST, NULL);
-			}
-
-			if (i < (mPatchesPerEdge-1)  &&  j > 0) 
-			{
-				patchp->setNeighborPatch(SOUTHEAST, getPatch(i + 1, j - 1));
-			}
-			else 
-			{
-				patchp->setNeighborPatch(SOUTHEAST, NULL);
-			}
-
-			LLVector3d origin_global;
-			origin_global.mdV[0] = mOriginGlobal.mdV[0] + i * mMetersPerGrid * mGridsPerPatchEdge;
-			origin_global.mdV[1] = mOriginGlobal.mdV[0] + j * mMetersPerGrid * mGridsPerPatchEdge;
-			origin_global.mdV[2] = 0.f;
-			patchp->setOriginGlobal(origin_global);
-		}
-	}
+    // Assumes mGridsPerEdge, mGridsPerPatchEdge, and mPatchesPerEdge have been properly set
+    // TODO -- check for create() called when surface is not empty
+    S32 i, j;
+    LLSurfacePatch *patchp;
+
+    // Allocate memory
+    mPatchList = new LLSurfacePatch[mNumberOfPatches];
+
+    // One of each for each camera
+    mVisiblePatchCount = mNumberOfPatches;
+
+    for (j=0; j<mPatchesPerEdge; j++)
+    {
+        for (i=0; i<mPatchesPerEdge; i++)
+        {
+            patchp = getPatch(i, j);
+            patchp->setSurface(this);
+        }
+    }
+
+    for (j=0; j<mPatchesPerEdge; j++)
+    {
+        for (i=0; i<mPatchesPerEdge; i++)
+        {
+            patchp = getPatch(i, j);
+            patchp->mHasReceivedData = FALSE;
+            patchp->mSTexUpdate = TRUE;
+
+            S32 data_offset = i * mGridsPerPatchEdge + j * mGridsPerPatchEdge * mGridsPerEdge;
+
+            patchp->setDataZ(mSurfaceZ + data_offset);
+            patchp->setDataNorm(mNorm + data_offset);
+
+
+            // We make each patch point to its neighbors so we can do resolution checking
+            // when butting up different resolutions.  Patches that don't have neighbors
+            // somewhere will point to NULL on that side.
+            if (i < mPatchesPerEdge-1)
+            {
+                patchp->setNeighborPatch(EAST,getPatch(i+1, j));
+            }
+            else
+            {
+                patchp->setNeighborPatch(EAST, NULL);
+            }
+
+            if (j < mPatchesPerEdge-1)
+            {
+                patchp->setNeighborPatch(NORTH, getPatch(i, j+1));
+            }
+            else
+            {
+                patchp->setNeighborPatch(NORTH, NULL);
+            }
+
+            if (i > 0)
+            {
+                patchp->setNeighborPatch(WEST, getPatch(i - 1, j));
+            }
+            else
+            {
+                patchp->setNeighborPatch(WEST, NULL);
+            }
+
+            if (j > 0)
+            {
+                patchp->setNeighborPatch(SOUTH, getPatch(i, j-1));
+            }
+            else
+            {
+                patchp->setNeighborPatch(SOUTH, NULL);
+            }
+
+            if (i < (mPatchesPerEdge-1)  &&  j < (mPatchesPerEdge-1))
+            {
+                patchp->setNeighborPatch(NORTHEAST, getPatch(i + 1, j + 1));
+            }
+            else
+            {
+                patchp->setNeighborPatch(NORTHEAST, NULL);
+            }
+
+            if (i > 0  &&  j < (mPatchesPerEdge-1))
+            {
+                patchp->setNeighborPatch(NORTHWEST, getPatch(i - 1, j + 1));
+            }
+            else
+            {
+                patchp->setNeighborPatch(NORTHWEST, NULL);
+            }
+
+            if (i > 0  &&  j > 0)
+            {
+                patchp->setNeighborPatch(SOUTHWEST, getPatch(i - 1, j - 1));
+            }
+            else
+            {
+                patchp->setNeighborPatch(SOUTHWEST, NULL);
+            }
+
+            if (i < (mPatchesPerEdge-1)  &&  j > 0)
+            {
+                patchp->setNeighborPatch(SOUTHEAST, getPatch(i + 1, j - 1));
+            }
+            else
+            {
+                patchp->setNeighborPatch(SOUTHEAST, NULL);
+            }
+
+            LLVector3d origin_global;
+            origin_global.mdV[0] = mOriginGlobal.mdV[0] + i * mMetersPerGrid * mGridsPerPatchEdge;
+            origin_global.mdV[1] = mOriginGlobal.mdV[0] + j * mMetersPerGrid * mGridsPerPatchEdge;
+            origin_global.mdV[2] = 0.f;
+            patchp->setOriginGlobal(origin_global);
+        }
+    }
 }
 
 
 void LLSurface::destroyPatchData()
 {
-	// Delete all of the cached patch data for these patches.
+    // Delete all of the cached patch data for these patches.
 
-	delete [] mPatchList;
-	mPatchList = NULL;
-	mVisiblePatchCount = 0;
+    delete [] mPatchList;
+    mPatchList = NULL;
+    mVisiblePatchCount = 0;
 }
 
 
 void LLSurface::setTextureSize(const S32 texture_size)
 {
-	sTextureSize = texture_size;
+    sTextureSize = texture_size;
 }
 
 
 U32 LLSurface::getRenderLevel(const U32 render_stride) const
 {
-	return mPVArray.mRenderLevelp[render_stride];
+    return mPVArray.mRenderLevelp[render_stride];
 }
 
 
 U32 LLSurface::getRenderStride(const U32 render_level) const
 {
-	return mPVArray.mRenderStridep[render_level];
+    return mPVArray.mRenderStridep[render_level];
 }
 
 
 LLSurfacePatch *LLSurface::getPatch(const S32 x, const S32 y) const
 {
-	if ((x < 0) || (x >= mPatchesPerEdge))
-	{
-		LL_WARNS() << "Asking for patch out of bounds" << LL_ENDL;
-		return NULL;
-	}
-	if ((y < 0) || (y >= mPatchesPerEdge))
-	{
-		LL_WARNS() << "Asking for patch out of bounds" << LL_ENDL;
-		return NULL;
-	}
-
-	return mPatchList + x + y*mPatchesPerEdge;
+    if ((x < 0) || (x >= mPatchesPerEdge))
+    {
+        LL_WARNS() << "Asking for patch out of bounds" << LL_ENDL;
+        return NULL;
+    }
+    if ((y < 0) || (y >= mPatchesPerEdge))
+    {
+        LL_WARNS() << "Asking for patch out of bounds" << LL_ENDL;
+        return NULL;
+    }
+
+    return mPatchList + x + y*mPatchesPerEdge;
 }
 
 
 void LLSurface::dirtyAllPatches()
 {
-	S32 i;
-	for (i = 0; i < mNumberOfPatches; i++)
-	{
-		mPatchList[i].dirtyZ();
-	}
+    S32 i;
+    for (i = 0; i < mNumberOfPatches; i++)
+    {
+        mPatchList[i].dirtyZ();
+    }
 }
 
 void LLSurface::dirtySurfacePatch(LLSurfacePatch *patchp)
 {
-	// Put surface patch on dirty surface patch list
-	mDirtyPatchList.insert(patchp);
+    // Put surface patch on dirty surface patch list
+    mDirtyPatchList.insert(patchp);
 }
 
 
 void LLSurface::setWaterHeight(F32 height)
 {
-	if (!mWaterObjp.isNull())
-	{
-		LLVector3 water_pos_region = mWaterObjp->getPositionRegion();
-		bool changed = water_pos_region.mV[VZ] != height;
-		water_pos_region.mV[VZ] = height;
-		mWaterObjp->setPositionRegion(water_pos_region);
-		if (changed)
-		{
-			LLWorld::getInstance()->updateWaterObjects();
-		}
-	}
-	else
-	{
-		LL_WARNS() << "LLSurface::setWaterHeight with no water object!" << LL_ENDL;
-	}
+    if (!mWaterObjp.isNull())
+    {
+        LLVector3 water_pos_region = mWaterObjp->getPositionRegion();
+        bool changed = water_pos_region.mV[VZ] != height;
+        water_pos_region.mV[VZ] = height;
+        mWaterObjp->setPositionRegion(water_pos_region);
+        if (changed)
+        {
+            LLWorld::getInstance()->updateWaterObjects();
+        }
+    }
+    else
+    {
+        LL_WARNS() << "LLSurface::setWaterHeight with no water object!" << LL_ENDL;
+    }
 }
 
 F32 LLSurface::getWaterHeight() const
 {
-	if (!mWaterObjp.isNull())
-	{
-		// we have a water object, the usual case
-		return mWaterObjp->getPositionRegion().mV[VZ];
-	}
-	else
-	{
-		return DEFAULT_WATER_HEIGHT;
-	}
+    if (!mWaterObjp.isNull())
+    {
+        // we have a water object, the usual case
+        return mWaterObjp->getPositionRegion().mV[VZ];
+    }
+    else
+    {
+        return DEFAULT_WATER_HEIGHT;
+    }
 }
 
 
 BOOL LLSurface::generateWaterTexture(const F32 x, const F32 y,
-									 const F32 width, const F32 height)
+                                     const F32 width, const F32 height)
 {
-	LL_PROFILE_ZONE_SCOPED
-	if (!getWaterTexture())
-	{
-		return FALSE;
-	}
-
-	S32 tex_width = mWaterTexturep->getWidth();
-	S32 tex_height = mWaterTexturep->getHeight();
-	S32 tex_comps = mWaterTexturep->getComponents();
-	S32 tex_stride = tex_width * tex_comps;
-	LLPointer<LLImageRaw> raw = new LLImageRaw(tex_width, tex_height, tex_comps);
-	U8 *rawp = raw->getData();
-
-	F32 scale = getRegion()->getWidth() * getMetersPerGrid() / (F32)tex_width;
-	F32 scale_inv = 1.f / scale;
-
-	S32 x_begin, y_begin, x_end, y_end;
-
-	x_begin = ll_round(x * scale_inv);
-	y_begin = ll_round(y * scale_inv);
-	x_end = ll_round((x + width) * scale_inv);
-	y_end = ll_round((y + width) * scale_inv);
-
-	if (x_end > tex_width)
-	{
-		x_end = tex_width;
-	}
-	if (y_end > tex_width)
-	{
-		y_end = tex_width;
-	}
-
-	// OK, for now, just have the composition value equal the height at the point.
-	LLVector3 location;
-	LLColor4U coloru;
-
-	const F32 WATER_HEIGHT = getWaterHeight();
-
-	S32 i, j, offset;
-	for (j = y_begin; j < y_end; j++)
-	{
-		for (i = x_begin; i < x_end; i++)
-		{
-			//F32 nv[2];
-			//nv[0] = i/256.f;
-			//nv[1] = j/256.f;
-			// const S32 modulation = noise2(nv)*40;
-			offset = j*tex_stride + i*tex_comps;
-			location.mV[VX] = i*scale;
-			location.mV[VY] = j*scale;
-
-			// Sample multiple points
-			const F32 height = resolveHeightRegion(location);
-
-			if (height > WATER_HEIGHT)
-			{
-				// Above water...
-				coloru = MAX_WATER_COLOR;
-				coloru.mV[3] = ABOVE_WATERLINE_ALPHA;
-				*(rawp + offset++) = coloru.mV[0];
-				*(rawp + offset++) = coloru.mV[1];
-				*(rawp + offset++) = coloru.mV[2];
-				*(rawp + offset++) = coloru.mV[3];
-			}
-			else
-			{
-				// Want non-linear curve for transparency gradient
-				coloru = MAX_WATER_COLOR;
-				const F32 frac = 1.f - 2.f/(2.f - (height - WATER_HEIGHT));
-				S32 alpha = 64 + ll_round((255-64)*frac);
-
-				alpha = llmin(ll_round((F32)MAX_WATER_COLOR.mV[3]), alpha);
-				alpha = llmax(64, alpha);
-
-				coloru.mV[3] = alpha;
-				*(rawp + offset++) = coloru.mV[0];
-				*(rawp + offset++) = coloru.mV[1];
-				*(rawp + offset++) = coloru.mV[2];
-				*(rawp + offset++) = coloru.mV[3];
-			}
-		}
-	}
-
-	if (!mWaterTexturep->hasGLTexture())
-	{
-		mWaterTexturep->createGLTexture(0, raw);
-	}
-
-	mWaterTexturep->setSubImage(raw, x_begin, y_begin, x_end - x_begin, y_end - y_begin);
-	return TRUE;
+    LL_PROFILE_ZONE_SCOPED
+    if (!getWaterTexture())
+    {
+        return FALSE;
+    }
+
+    S32 tex_width = mWaterTexturep->getWidth();
+    S32 tex_height = mWaterTexturep->getHeight();
+    S32 tex_comps = mWaterTexturep->getComponents();
+    S32 tex_stride = tex_width * tex_comps;
+    LLPointer<LLImageRaw> raw = new LLImageRaw(tex_width, tex_height, tex_comps);
+    U8 *rawp = raw->getData();
+
+    F32 scale = getRegion()->getWidth() * getMetersPerGrid() / (F32)tex_width;
+    F32 scale_inv = 1.f / scale;
+
+    S32 x_begin, y_begin, x_end, y_end;
+
+    x_begin = ll_round(x * scale_inv);
+    y_begin = ll_round(y * scale_inv);
+    x_end = ll_round((x + width) * scale_inv);
+    y_end = ll_round((y + width) * scale_inv);
+
+    if (x_end > tex_width)
+    {
+        x_end = tex_width;
+    }
+    if (y_end > tex_width)
+    {
+        y_end = tex_width;
+    }
+
+    // OK, for now, just have the composition value equal the height at the point.
+    LLVector3 location;
+    LLColor4U coloru;
+
+    const F32 WATER_HEIGHT = getWaterHeight();
+
+    S32 i, j, offset;
+    for (j = y_begin; j < y_end; j++)
+    {
+        for (i = x_begin; i < x_end; i++)
+        {
+            //F32 nv[2];
+            //nv[0] = i/256.f;
+            //nv[1] = j/256.f;
+            // const S32 modulation = noise2(nv)*40;
+            offset = j*tex_stride + i*tex_comps;
+            location.mV[VX] = i*scale;
+            location.mV[VY] = j*scale;
+
+            // Sample multiple points
+            const F32 height = resolveHeightRegion(location);
+
+            if (height > WATER_HEIGHT)
+            {
+                // Above water...
+                coloru = MAX_WATER_COLOR;
+                coloru.mV[3] = ABOVE_WATERLINE_ALPHA;
+                *(rawp + offset++) = coloru.mV[0];
+                *(rawp + offset++) = coloru.mV[1];
+                *(rawp + offset++) = coloru.mV[2];
+                *(rawp + offset++) = coloru.mV[3];
+            }
+            else
+            {
+                // Want non-linear curve for transparency gradient
+                coloru = MAX_WATER_COLOR;
+                const F32 frac = 1.f - 2.f/(2.f - (height - WATER_HEIGHT));
+                S32 alpha = 64 + ll_round((255-64)*frac);
+
+                alpha = llmin(ll_round((F32)MAX_WATER_COLOR.mV[3]), alpha);
+                alpha = llmax(64, alpha);
+
+                coloru.mV[3] = alpha;
+                *(rawp + offset++) = coloru.mV[0];
+                *(rawp + offset++) = coloru.mV[1];
+                *(rawp + offset++) = coloru.mV[2];
+                *(rawp + offset++) = coloru.mV[3];
+            }
+        }
+    }
+
+    if (!mWaterTexturep->hasGLTexture())
+    {
+        mWaterTexturep->createGLTexture(0, raw);
+    }
+
+    mWaterTexturep->setSubImage(raw, x_begin, y_begin, x_end - x_begin, y_end - y_begin);
+    return TRUE;
 }
diff --git a/indra/newview/llsurface.h b/indra/newview/llsurface.h
index b7b47d2a1c2e6de2ba587c973e7e6fdf26158f21..093b1412713dd536c43469f7111c4da014addbb2 100644
--- a/indra/newview/llsurface.h
+++ b/indra/newview/llsurface.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llsurface.h
  * @brief Description of LLSurface class
  *
  * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -52,9 +52,9 @@ static const U8 NORTH_EDGE = 0x02;
 static const U8 WEST_EDGE  = 0x04;
 static const U8 SOUTH_EDGE = 0x08;
 
-static const S32 ONE_MORE_THAN_NEIGHBOR	= 1;
-static const S32 EQUAL_TO_NEIGHBOR 		= 0;
-static const S32 ONE_LESS_THAN_NEIGHBOR	= -1;
+static const S32 ONE_MORE_THAN_NEIGHBOR = 1;
+static const S32 EQUAL_TO_NEIGHBOR      = 0;
+static const S32 ONE_LESS_THAN_NEIGHBOR = -1;
 
 const S32 ABOVE_WATERLINE_ALPHA = 32;  // The alpha of water when the land elevation is above the waterline.
 
@@ -63,166 +63,166 @@ class LLSurfacePatch;
 class LLBitPack;
 class LLGroupHeader;
 
-class LLSurface 
+class LLSurface
 {
 public:
-	LLSurface(U32 type, LLViewerRegion *regionp = NULL);
-	virtual ~LLSurface();
+    LLSurface(U32 type, LLViewerRegion *regionp = NULL);
+    virtual ~LLSurface();
 
-	static void initClasses(); // Do class initialization for LLSurface and its child classes.
+    static void initClasses(); // Do class initialization for LLSurface and its child classes.
 
-	void create(const S32 surface_grid_width,
-				const S32 surface_patch_width,
-				const LLVector3d &origin_global,
-				const F32 width);	// Allocates and initializes surface
+    void create(const S32 surface_grid_width,
+                const S32 surface_patch_width,
+                const LLVector3d &origin_global,
+                const F32 width);   // Allocates and initializes surface
 
-	void setRegion(LLViewerRegion *regionp);
+    void setRegion(LLViewerRegion *regionp);
 
-	void setOriginGlobal(const LLVector3d &origin_global);
+    void setOriginGlobal(const LLVector3d &origin_global);
 
-	void connectNeighbor(LLSurface *neighborp, U32 direction);
-	void disconnectNeighbor(LLSurface *neighborp);
-	void disconnectAllNeighbors();
+    void connectNeighbor(LLSurface *neighborp, U32 direction);
+    void disconnectNeighbor(LLSurface *neighborp);
+    void disconnectAllNeighbors();
 
-	virtual void decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL b_large_patch);
-	virtual void updatePatchVisibilities(LLAgent &agent);
+    virtual void decompressDCTPatch(LLBitPack &bitpack, LLGroupHeader *gopp, BOOL b_large_patch);
+    virtual void updatePatchVisibilities(LLAgent &agent);
 
-	inline F32 getZ(const U32 k) const				{ return mSurfaceZ[k]; }
-	inline F32 getZ(const S32 i, const S32 j) const	{ return mSurfaceZ[i + j*mGridsPerEdge]; }
+    inline F32 getZ(const U32 k) const              { return mSurfaceZ[k]; }
+    inline F32 getZ(const S32 i, const S32 j) const { return mSurfaceZ[i + j*mGridsPerEdge]; }
 
-	LLVector3 getOriginAgent() const;
-	const LLVector3d &getOriginGlobal() const;
-	F32 getMetersPerGrid() const;
-	S32 getGridsPerEdge() const; 
-	S32 getPatchesPerEdge() const;
-	S32 getGridsPerPatchEdge() const;
-	U32 getRenderStride(const U32 render_level) const;
-	U32 getRenderLevel(const U32 render_stride) const;
+    LLVector3 getOriginAgent() const;
+    const LLVector3d &getOriginGlobal() const;
+    F32 getMetersPerGrid() const;
+    S32 getGridsPerEdge() const;
+    S32 getPatchesPerEdge() const;
+    S32 getGridsPerPatchEdge() const;
+    U32 getRenderStride(const U32 render_level) const;
+    U32 getRenderLevel(const U32 render_stride) const;
 
-	// Returns the height of the surface immediately above (or below) location,
-	// or if location is not above surface returns zero.
-	F32 resolveHeightRegion(const F32 x, const F32 y) const;
-	F32 resolveHeightRegion(const LLVector3 &location) const
-			{ return resolveHeightRegion( location.mV[VX], location.mV[VY] ); }
-	F32 resolveHeightGlobal(const LLVector3d &position_global) const;
-	LLVector3 resolveNormalGlobal(const LLVector3d& v) const;				//  Returns normal to surface
+    // Returns the height of the surface immediately above (or below) location,
+    // or if location is not above surface returns zero.
+    F32 resolveHeightRegion(const F32 x, const F32 y) const;
+    F32 resolveHeightRegion(const LLVector3 &location) const
+            { return resolveHeightRegion( location.mV[VX], location.mV[VY] ); }
+    F32 resolveHeightGlobal(const LLVector3d &position_global) const;
+    LLVector3 resolveNormalGlobal(const LLVector3d& v) const;               //  Returns normal to surface
 
-	LLSurfacePatch *resolvePatchRegion(const F32 x, const F32 y) const;
-	LLSurfacePatch *resolvePatchRegion(const LLVector3 &position_region) const;
-	LLSurfacePatch *resolvePatchGlobal(const LLVector3d &position_global) const;
+    LLSurfacePatch *resolvePatchRegion(const F32 x, const F32 y) const;
+    LLSurfacePatch *resolvePatchRegion(const LLVector3 &position_region) const;
+    LLSurfacePatch *resolvePatchGlobal(const LLVector3d &position_global) const;
 
-	// Update methods (called during idle, normally)
+    // Update methods (called during idle, normally)
     template<bool PBR>
-	bool idleUpdate(F32 max_update_time);
+    bool idleUpdate(F32 max_update_time);
+
+    BOOL containsPosition(const LLVector3 &position);
 
-	BOOL containsPosition(const LLVector3 &position);
+    void moveZ(const S32 x, const S32 y, const F32 delta);
 
-	void moveZ(const S32 x, const S32 y, const F32 delta);	
+    LLViewerRegion *getRegion() const               { return mRegionp; }
 
-	LLViewerRegion *getRegion() const				{ return mRegionp; }
+    F32 getMinZ() const                             { return mMinZ; }
+    F32 getMaxZ() const                             { return mMaxZ; }
 
-	F32 getMinZ() const								{ return mMinZ; }
-	F32 getMaxZ() const								{ return mMaxZ; }
+    void setWaterHeight(F32 height);
+    F32 getWaterHeight() const;
 
-	void setWaterHeight(F32 height);
-	F32 getWaterHeight() const;
+    LLViewerTexture *getSTexture();
+    LLViewerTexture *getWaterTexture();
+    BOOL hasZData() const                           { return mHasZData; }
 
-	LLViewerTexture *getSTexture();
-	LLViewerTexture *getWaterTexture();
-	BOOL hasZData() const							{ return mHasZData; }
+    void dirtyAllPatches(); // Use this to dirty all patches when changing terrain parameters
 
-	void dirtyAllPatches();	// Use this to dirty all patches when changing terrain parameters
+    void dirtySurfacePatch(LLSurfacePatch *patchp);
+    LLVOWater *getWaterObj()                        { return mWaterObjp; }
 
-	void dirtySurfacePatch(LLSurfacePatch *patchp);
-	LLVOWater *getWaterObj()						{ return mWaterObjp; }
+    static void setTextureSize(const S32 texture_size);
 
-	static void setTextureSize(const S32 texture_size);
+    friend class LLSurfacePatch;
+    friend std::ostream& operator<<(std::ostream &s, const LLSurface &S);
+
+    void getNeighboringRegions( std::vector<LLViewerRegion*>& uniqueRegions );
+    void getNeighboringRegionsStatus( std::vector<S32>& regions );
 
-	friend class LLSurfacePatch;
-	friend std::ostream& operator<<(std::ostream &s, const LLSurface &S);
-	
-	void getNeighboringRegions( std::vector<LLViewerRegion*>& uniqueRegions );
-	void getNeighboringRegionsStatus( std::vector<S32>& regions );
-	
 public:
-	// Number of grid points on one side of a region, including +1 buffer for
-	// north and east edge.
-	S32 mGridsPerEdge;
+    // Number of grid points on one side of a region, including +1 buffer for
+    // north and east edge.
+    S32 mGridsPerEdge;
+
+    F32 mOOGridsPerEdge;            // Inverse of grids per edge
 
-	F32 mOOGridsPerEdge;			// Inverse of grids per edge
+    S32 mPatchesPerEdge;            // Number of patches on one side of a region
+    S32 mNumberOfPatches;           // Total number of patches
 
-	S32 mPatchesPerEdge;			// Number of patches on one side of a region
-	S32 mNumberOfPatches;			// Total number of patches
 
+    // Each surface points at 8 neighbors (or NULL)
+    // +---+---+---+
+    // |NW | N | NE|
+    // +---+---+---+
+    // | W | 0 | E |
+    // +---+---+---+
+    // |SW | S | SE|
+    // +---+---+---+
+    LLSurface *mNeighbors[8]; // Adjacent patches
 
-	// Each surface points at 8 neighbors (or NULL)
-	// +---+---+---+
-	// |NW | N | NE|
-	// +---+---+---+
-	// | W | 0 | E |
-	// +---+---+---+
-	// |SW | S | SE|
-	// +---+---+---+
-	LLSurface *mNeighbors[8]; // Adjacent patches
+    U32 mType;              // Useful for identifying derived classes
 
-	U32 mType;				// Useful for identifying derived classes
-	
-	F32 mDetailTextureScale;	//  Number of times to repeat detail texture across this surface 
+    F32 mDetailTextureScale;    //  Number of times to repeat detail texture across this surface
 
 protected:
-	void createSTexture();
-	void createWaterTexture();
-	void initTextures();
-	void initWater();
+    void createSTexture();
+    void createWaterTexture();
+    void initTextures();
+    void initWater();
 
 
-	void createPatchData();		// Allocates memory for patches.
-	void destroyPatchData();    // Deallocates memory for patches.
+    void createPatchData();     // Allocates memory for patches.
+    void destroyPatchData();    // Deallocates memory for patches.
 
-	BOOL generateWaterTexture(const F32 x, const F32 y,
-						const F32 width, const F32 height);		// Generate texture from composition values.
+    BOOL generateWaterTexture(const F32 x, const F32 y,
+                        const F32 width, const F32 height);     // Generate texture from composition values.
 
-	//F32 updateTexture(LLSurfacePatch *ppatch);
-	
-	LLSurfacePatch *getPatch(const S32 x, const S32 y) const;
+    //F32 updateTexture(LLSurfacePatch *ppatch);
+
+    LLSurfacePatch *getPatch(const S32 x, const S32 y) const;
 
 protected:
-	LLVector3d	mOriginGlobal;		// In absolute frame
-	LLSurfacePatch *mPatchList;		// Array of all patches
+    LLVector3d  mOriginGlobal;      // In absolute frame
+    LLSurfacePatch *mPatchList;     // Array of all patches
 
-	// Array of grid data, mGridsPerEdge * mGridsPerEdge
-	F32 *mSurfaceZ;
+    // Array of grid data, mGridsPerEdge * mGridsPerEdge
+    F32 *mSurfaceZ;
 
-	// Array of grid normals, mGridsPerEdge * mGridsPerEdge
-	LLVector3 *mNorm;
+    // Array of grid normals, mGridsPerEdge * mGridsPerEdge
+    LLVector3 *mNorm;
 
-	std::set<LLSurfacePatch *> mDirtyPatchList;
+    std::set<LLSurfacePatch *> mDirtyPatchList;
 
 
-	// The textures should never be directly initialized - use the setter methods!
-	LLPointer<LLViewerTexture> mSTexturep;		// Texture for surface
-	LLPointer<LLViewerTexture> mWaterTexturep;	// Water texture
+    // The textures should never be directly initialized - use the setter methods!
+    LLPointer<LLViewerTexture> mSTexturep;      // Texture for surface
+    LLPointer<LLViewerTexture> mWaterTexturep;  // Water texture
 
-	LLPointer<LLVOWater>	mWaterObjp;
+    LLPointer<LLVOWater>    mWaterObjp;
 
-	// When we want multiple cameras we'll need one of each these for each camera
-	S32 mVisiblePatchCount;
+    // When we want multiple cameras we'll need one of each these for each camera
+    S32 mVisiblePatchCount;
 
-	U32			mGridsPerPatchEdge;			// Number of grid points on a side of a patch
-	F32			mMetersPerGrid;				// Converts (i,j) indecies to distance
-	F32			mMetersPerEdge;				// = mMetersPerGrid * (mGridsPerEdge-1)
+    U32         mGridsPerPatchEdge;         // Number of grid points on a side of a patch
+    F32         mMetersPerGrid;             // Converts (i,j) indecies to distance
+    F32         mMetersPerEdge;             // = mMetersPerGrid * (mGridsPerEdge-1)
 
-	LLPatchVertexArray mPVArray;
+    LLPatchVertexArray mPVArray;
 
-	BOOL		mHasZData;				// We've received any patch data for this surface.
-	F32			mMinZ;					// min z for this region (during the session)
-	F32			mMaxZ;					// max z for this region (during the session)
+    BOOL        mHasZData;              // We've received any patch data for this surface.
+    F32         mMinZ;                  // min z for this region (during the session)
+    F32         mMaxZ;                  // max z for this region (during the session)
 
-	S32			mSurfacePatchUpdateCount;					// Number of frames since last update.
+    S32         mSurfacePatchUpdateCount;                   // Number of frames since last update.
 
 private:
-	LLViewerRegion *mRegionp; // Patch whose coordinate system this surface is using.
-	static S32	sTextureSize;				// Size of the surface texture
+    LLViewerRegion *mRegionp; // Patch whose coordinate system this surface is using.
+    static S32  sTextureSize;               // Size of the surface texture
 };
 
 extern template bool LLSurface::idleUpdate</*PBR=*/false>(F32 max_update_time);
@@ -232,33 +232,33 @@ extern template bool LLSurface::idleUpdate</*PBR=*/true>(F32 max_update_time);
 
 //        .   __.
 //     Z /|\   /| Y                                 North
-//        |   / 
+//        |   /
 //        |  /             |<----------------- mGridsPerSurfaceEdge --------------->|
 //        | /              __________________________________________________________
 //        |/______\ X     /_______________________________________________________  /
-//                /      /      /      /      /      /      /      /M*M-2 /M*M-1 / /  
-//                      /______/______/______/______/______/______/______/______/ /  
-//                     /      /      /      /      /      /      /      /      / /  
-//                    /______/______/______/______/______/______/______/______/ /  
-//                   /      /      /      /      /      /      /      /      / /  
-//                  /______/______/______/______/______/______/______/______/ /  
-//      West       /      /      /      /      /      /      /      /      / /  
+//                /      /      /      /      /      /      /      /M*M-2 /M*M-1 / /
+//                      /______/______/______/______/______/______/______/______/ /
+//                     /      /      /      /      /      /      /      /      / /
+//                    /______/______/______/______/______/______/______/______/ /
+//                   /      /      /      /      /      /      /      /      / /
+//                  /______/______/______/______/______/______/______/______/ /
+//      West       /      /      /      /      /      /      /      /      / /
 //                /______/______/______/______/______/______/______/______/ /     East
-//               /...   /      /      /      /      /      /      /      / /  
-//              /______/______/______/______/______/______/______/______/ /  
-//       _.    / 2M   /      /      /      /      /      /      /      / /  
-//       /|   /______/______/______/______/______/______/______/______/ /  
-//      /    / M    / M+1  / M+2  / ...  /      /      /      / 2M-1 / /   
-//     j    /______/______/______/______/______/______/______/______/ /   
-//         / 0    / 1    / 2    / ...  /      /      /      / M-1  / /   
-//        /______/______/______/______/______/______/______/______/_/   
+//               /...   /      /      /      /      /      /      /      / /
+//              /______/______/______/______/______/______/______/______/ /
+//       _.    / 2M   /      /      /      /      /      /      /      / /
+//       /|   /______/______/______/______/______/______/______/______/ /
+//      /    / M    / M+1  / M+2  / ...  /      /      /      / 2M-1 / /
+//     j    /______/______/______/______/______/______/______/______/ /
+//         / 0    / 1    / 2    / ...  /      /      /      / M-1  / /
+//        /______/______/______/______/______/______/______/______/_/
 //                                South             |<-L->|
 //             i -->
 //
 // where M = mSurfPatchWidth
 // and L = mPatchGridWidth
-// 
+//
 // Notice that mGridsPerSurfaceEdge = a power of two + 1
-// This provides a buffer on the east and north edges that will allow us to 
+// This provides a buffer on the east and north edges that will allow us to
 // fill the cracks between adjacent surfaces when rendering.
 #endif
diff --git a/indra/newview/llsurfacepatch.cpp b/indra/newview/llsurfacepatch.cpp
index e6ccf592f85b517e216d8edd107669b3c132db0c..f8ad1a0713f760e4cc0824973f2338fc85211d4d 100644
--- a/indra/newview/llsurfacepatch.cpp
+++ b/indra/newview/llsurfacepatch.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llsurfacepatch.cpp
  * @brief LLSurfacePatch class implementation
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -47,198 +47,198 @@ extern bool gShiftFrame;
 extern U64MicrosecondsImplicit gFrameTime;
 extern LLPipeline gPipeline;
 
-LLSurfacePatch::LLSurfacePatch() 
-:	mHasReceivedData(FALSE),
-	mSTexUpdate(FALSE),
-	mDirty(FALSE),
-	mDirtyZStats(TRUE),
-	mHeightsGenerated(FALSE),
-	mDataOffset(0),
-	mDataZ(NULL),
-	mDataNorm(NULL),
-	mVObjp(NULL),
-	mOriginRegion(0.f, 0.f, 0.f),
-	mCenterRegion(0.f, 0.f, 0.f),
-	mMinZ(0.f),
-	mMaxZ(0.f),
-	mMeanZ(0.f),
-	mRadius(0.f),
-	mMinComposition(0.f),
-	mMaxComposition(0.f),
-	mMeanComposition(0.f),
-	// This flag is used to communicate between adjacent surfaces and is
-	// set to non-zero values by higher classes.  
-	mConnectedEdge(NO_EDGE),
-	mLastUpdateTime(0),
-	mSurfacep(NULL)
-{	
-	S32 i;
-	for (i = 0; i < 8; i++)
-	{
-		setNeighborPatch(i, NULL);
-	}
-	for (i = 0; i < 9; i++)
-	{
-		mNormalsInvalid[i] = TRUE;
-	}
+LLSurfacePatch::LLSurfacePatch()
+:   mHasReceivedData(FALSE),
+    mSTexUpdate(FALSE),
+    mDirty(FALSE),
+    mDirtyZStats(TRUE),
+    mHeightsGenerated(FALSE),
+    mDataOffset(0),
+    mDataZ(NULL),
+    mDataNorm(NULL),
+    mVObjp(NULL),
+    mOriginRegion(0.f, 0.f, 0.f),
+    mCenterRegion(0.f, 0.f, 0.f),
+    mMinZ(0.f),
+    mMaxZ(0.f),
+    mMeanZ(0.f),
+    mRadius(0.f),
+    mMinComposition(0.f),
+    mMaxComposition(0.f),
+    mMeanComposition(0.f),
+    // This flag is used to communicate between adjacent surfaces and is
+    // set to non-zero values by higher classes.
+    mConnectedEdge(NO_EDGE),
+    mLastUpdateTime(0),
+    mSurfacep(NULL)
+{
+    S32 i;
+    for (i = 0; i < 8; i++)
+    {
+        setNeighborPatch(i, NULL);
+    }
+    for (i = 0; i < 9; i++)
+    {
+        mNormalsInvalid[i] = TRUE;
+    }
 }
 
 
 LLSurfacePatch::~LLSurfacePatch()
 {
-	mVObjp = NULL;
+    mVObjp = NULL;
 }
 
 
 void LLSurfacePatch::dirty()
 {
-	// These are outside of the loop in case we're still waiting for a dirty from the
-	// texture being updated...
-	if (mVObjp)
-	{
-		mVObjp->dirtyGeom();
-	}
-	else
-	{
-		LL_WARNS("Terrain") << "No viewer object for this surface patch!" << LL_ENDL;
-	}
-
-	mDirtyZStats = TRUE;
-	mHeightsGenerated = FALSE;
-	
-	if (!mDirty)
-	{
-		mDirty = TRUE;
-		mSurfacep->dirtySurfacePatch(this);
-	}
+    // These are outside of the loop in case we're still waiting for a dirty from the
+    // texture being updated...
+    if (mVObjp)
+    {
+        mVObjp->dirtyGeom();
+    }
+    else
+    {
+        LL_WARNS("Terrain") << "No viewer object for this surface patch!" << LL_ENDL;
+    }
+
+    mDirtyZStats = TRUE;
+    mHeightsGenerated = FALSE;
+
+    if (!mDirty)
+    {
+        mDirty = TRUE;
+        mSurfacep->dirtySurfacePatch(this);
+    }
 }
 
 
 void LLSurfacePatch::setSurface(LLSurface *surfacep)
 {
-	mSurfacep = surfacep;
-	if (mVObjp == (LLVOSurfacePatch *)NULL)
-	{
-		llassert(mSurfacep->mType == 'l');
-
-		mVObjp = (LLVOSurfacePatch *)gObjectList.createObjectViewer(LLViewerObject::LL_VO_SURFACE_PATCH, mSurfacep->getRegion());
-		mVObjp->setPatch(this);
-		mVObjp->setPositionRegion(mCenterRegion);
-		gPipeline.createObject(mVObjp);
-	}
-} 
+    mSurfacep = surfacep;
+    if (mVObjp == (LLVOSurfacePatch *)NULL)
+    {
+        llassert(mSurfacep->mType == 'l');
+
+        mVObjp = (LLVOSurfacePatch *)gObjectList.createObjectViewer(LLViewerObject::LL_VO_SURFACE_PATCH, mSurfacep->getRegion());
+        mVObjp->setPatch(this);
+        mVObjp->setPositionRegion(mCenterRegion);
+        gPipeline.createObject(mVObjp);
+    }
+}
 
 void LLSurfacePatch::disconnectNeighbor(LLSurface *surfacep)
 {
-	U32 i;
-	for (i = 0; i < 8; i++)
-	{
-		if (getNeighborPatch(i))
-		{
-			if (getNeighborPatch(i)->mSurfacep == surfacep)
-			{
-				setNeighborPatch(i, NULL);
-				mNormalsInvalid[i] = TRUE;
-			}
-		}
-	}
-
-	// Clean up connected edges
-	if (getNeighborPatch(EAST))
-	{
-		if (getNeighborPatch(EAST)->mSurfacep == surfacep)
-		{
-			mConnectedEdge &= ~EAST_EDGE;
-		}
-	}
-	if (getNeighborPatch(NORTH))
-	{
-		if (getNeighborPatch(NORTH)->mSurfacep == surfacep)
-		{
-			mConnectedEdge &= ~NORTH_EDGE;
-		}
-	}
-	if (getNeighborPatch(WEST))
-	{
-		if (getNeighborPatch(WEST)->mSurfacep == surfacep)
-		{
-			mConnectedEdge &= ~WEST_EDGE;
-		}
-	}
-	if (getNeighborPatch(SOUTH))
-	{
-		if (getNeighborPatch(SOUTH)->mSurfacep == surfacep)
-		{
-			mConnectedEdge &= ~SOUTH_EDGE;
-		}
-	}
+    U32 i;
+    for (i = 0; i < 8; i++)
+    {
+        if (getNeighborPatch(i))
+        {
+            if (getNeighborPatch(i)->mSurfacep == surfacep)
+            {
+                setNeighborPatch(i, NULL);
+                mNormalsInvalid[i] = TRUE;
+            }
+        }
+    }
+
+    // Clean up connected edges
+    if (getNeighborPatch(EAST))
+    {
+        if (getNeighborPatch(EAST)->mSurfacep == surfacep)
+        {
+            mConnectedEdge &= ~EAST_EDGE;
+        }
+    }
+    if (getNeighborPatch(NORTH))
+    {
+        if (getNeighborPatch(NORTH)->mSurfacep == surfacep)
+        {
+            mConnectedEdge &= ~NORTH_EDGE;
+        }
+    }
+    if (getNeighborPatch(WEST))
+    {
+        if (getNeighborPatch(WEST)->mSurfacep == surfacep)
+        {
+            mConnectedEdge &= ~WEST_EDGE;
+        }
+    }
+    if (getNeighborPatch(SOUTH))
+    {
+        if (getNeighborPatch(SOUTH)->mSurfacep == surfacep)
+        {
+            mConnectedEdge &= ~SOUTH_EDGE;
+        }
+    }
 }
 
 LLVector3 LLSurfacePatch::getPointAgent(const U32 x, const U32 y) const
 {
-	U32 surface_stride = mSurfacep->getGridsPerEdge();
-	U32 point_offset = x + y*surface_stride;
-	LLVector3 pos;
-	pos = getOriginAgent();
-	pos.mV[VX] += x	* mSurfacep->getMetersPerGrid();
-	pos.mV[VY] += y * mSurfacep->getMetersPerGrid();
-	pos.mV[VZ] = *(mDataZ + point_offset);
-	return pos;
+    U32 surface_stride = mSurfacep->getGridsPerEdge();
+    U32 point_offset = x + y*surface_stride;
+    LLVector3 pos;
+    pos = getOriginAgent();
+    pos.mV[VX] += x * mSurfacep->getMetersPerGrid();
+    pos.mV[VY] += y * mSurfacep->getMetersPerGrid();
+    pos.mV[VZ] = *(mDataZ + point_offset);
+    return pos;
 }
 
 LLVector2 LLSurfacePatch::getTexCoords(const U32 x, const U32 y) const
 {
-	U32 surface_stride = mSurfacep->getGridsPerEdge();
-	U32 point_offset = x + y*surface_stride;
-	LLVector3 pos, rel_pos;
-	pos = getOriginAgent();
-	pos.mV[VX] += x	* mSurfacep->getMetersPerGrid();
-	pos.mV[VY] += y * mSurfacep->getMetersPerGrid();
-	pos.mV[VZ] = *(mDataZ + point_offset);
-	rel_pos = pos - mSurfacep->getOriginAgent();
-	rel_pos *= 1.f/surface_stride;
-	return LLVector2(rel_pos.mV[VX], rel_pos.mV[VY]);
+    U32 surface_stride = mSurfacep->getGridsPerEdge();
+    U32 point_offset = x + y*surface_stride;
+    LLVector3 pos, rel_pos;
+    pos = getOriginAgent();
+    pos.mV[VX] += x * mSurfacep->getMetersPerGrid();
+    pos.mV[VY] += y * mSurfacep->getMetersPerGrid();
+    pos.mV[VZ] = *(mDataZ + point_offset);
+    rel_pos = pos - mSurfacep->getOriginAgent();
+    rel_pos *= 1.f/surface_stride;
+    return LLVector2(rel_pos.mV[VX], rel_pos.mV[VY]);
 }
 
 
 void LLSurfacePatch::eval(const U32 x, const U32 y, const U32 stride, LLVector3 *vertex, LLVector3 *normal,
-						  LLVector2 *tex0, LLVector2 *tex1)
+                          LLVector2 *tex0, LLVector2 *tex1)
 {
-	if (!mSurfacep || !mSurfacep->getRegion() || !mSurfacep->getGridsPerEdge() || !mVObjp)
-	{
-		return; // failsafe
-	}
-	llassert_always(vertex && normal && tex0 && tex1);
-	
-	U32 surface_stride = mSurfacep->getGridsPerEdge();
-	U32 point_offset = x + y*surface_stride;
-
-	*normal = getNormal(x, y);
-
-	LLVector3 pos_agent = getOriginAgent();
-	pos_agent.mV[VX] += x * mSurfacep->getMetersPerGrid();
-	pos_agent.mV[VY] += y * mSurfacep->getMetersPerGrid();
-	pos_agent.mV[VZ]  = *(mDataZ + point_offset);
-	*vertex     = pos_agent-mVObjp->getRegion()->getOriginAgent();
-
-	LLVector3 rel_pos = pos_agent - mSurfacep->getOriginAgent();
-	// *NOTE: Only PBR terrain uses the UVs right now. Texture terrain just ignores it.
+    if (!mSurfacep || !mSurfacep->getRegion() || !mSurfacep->getGridsPerEdge() || !mVObjp)
+    {
+        return; // failsafe
+    }
+    llassert_always(vertex && normal && tex0 && tex1);
+
+    U32 surface_stride = mSurfacep->getGridsPerEdge();
+    U32 point_offset = x + y*surface_stride;
+
+    *normal = getNormal(x, y);
+
+    LLVector3 pos_agent = getOriginAgent();
+    pos_agent.mV[VX] += x * mSurfacep->getMetersPerGrid();
+    pos_agent.mV[VY] += y * mSurfacep->getMetersPerGrid();
+    pos_agent.mV[VZ]  = *(mDataZ + point_offset);
+    *vertex     = pos_agent-mVObjp->getRegion()->getOriginAgent();
+
+    LLVector3 rel_pos = pos_agent - mSurfacep->getOriginAgent();
+    // *NOTE: Only PBR terrain uses the UVs right now. Texture terrain just ignores it.
     // *NOTE: In the future, UVs and horizontal position will no longer have a 1:1 relationship for PBR terrain
-	LLVector3 tex_pos = rel_pos;
-	tex0->mV[0]  = tex_pos.mV[0];
-	tex0->mV[1]  = tex_pos.mV[1];
-	tex1->mV[0] = mSurfacep->getRegion()->getCompositionXY(llfloor(mOriginRegion.mV[0])+x, llfloor(mOriginRegion.mV[1])+y);
+    LLVector3 tex_pos = rel_pos;
+    tex0->mV[0]  = tex_pos.mV[0];
+    tex0->mV[1]  = tex_pos.mV[1];
+    tex1->mV[0] = mSurfacep->getRegion()->getCompositionXY(llfloor(mOriginRegion.mV[0])+x, llfloor(mOriginRegion.mV[1])+y);
 
-	const F32 xyScale = 4.9215f*7.f; //0.93284f;
-	const F32 xyScaleInv = (1.f / xyScale)*(0.2222222222f);
+    const F32 xyScale = 4.9215f*7.f; //0.93284f;
+    const F32 xyScaleInv = (1.f / xyScale)*(0.2222222222f);
 
-	F32 vec[3] = {
+    F32 vec[3] = {
                     (F32)fmod((F32)(mOriginGlobal.mdV[0] + x)*xyScaleInv, 256.f),
                     (F32)fmod((F32)(mOriginGlobal.mdV[1] + y)*xyScaleInv, 256.f),
-					0.f
-				};
-	F32 rand_val = llclamp(noise2(vec)* 0.75f + 0.5f, 0.f, 1.f);
-	tex1->mV[1] = rand_val;
+                    0.f
+                };
+    F32 rand_val = llclamp(noise2(vec)* 0.75f + 0.5f, 0.f, 1.f);
+    tex1->mV[1] = rand_val;
 
 
 }
@@ -247,134 +247,134 @@ void LLSurfacePatch::eval(const U32 x, const U32 y, const U32 stride, LLVector3
 template<>
 void LLSurfacePatch::calcNormal</*PBR=*/false>(const U32 x, const U32 y, const U32 stride)
 {
-	U32 patch_width = mSurfacep->mPVArray.mPatchWidth;
-	U32 surface_stride = mSurfacep->getGridsPerEdge();
-
-	const F32 mpg = mSurfacep->getMetersPerGrid() * stride;
-
-	S32 poffsets[2][2][3];
-	poffsets[0][0][0] = x - stride;
-	poffsets[0][0][1] = y - stride;
-	poffsets[0][0][2] = surface_stride;
-
-	poffsets[0][1][0] = x - stride;
-	poffsets[0][1][1] = y + stride;
-	poffsets[0][1][2] = surface_stride;
-
-	poffsets[1][0][0] = x + stride;
-	poffsets[1][0][1] = y - stride;
-	poffsets[1][0][2] = surface_stride;
-
-	poffsets[1][1][0] = x + stride;
-	poffsets[1][1][1] = y + stride;
-	poffsets[1][1][2] = surface_stride;
-
-	const LLSurfacePatch *ppatches[2][2];
-
-	// LLVector3 p1, p2, p3, p4;
-
-	ppatches[0][0] = this;
-	ppatches[0][1] = this;
-	ppatches[1][0] = this;
-	ppatches[1][1] = this;
-
-	U32 i, j;
-	for (i = 0; i < 2; i++)
-	{
-		for (j = 0; j < 2; j++)
-		{
-			if (poffsets[i][j][0] < 0)
-			{
-				if (!ppatches[i][j]->getNeighborPatch(WEST))
-				{
-					poffsets[i][j][0] = 0;
-				}
-				else
-				{
-					ppatches[i][j] = ppatches[i][j]->getNeighborPatch(WEST);
-					poffsets[i][j][0] += patch_width;
-					poffsets[i][j][2] = ppatches[i][j]->getSurface()->getGridsPerEdge();
-				}
-			}
-			if (poffsets[i][j][1] < 0)
-			{
-				if (!ppatches[i][j]->getNeighborPatch(SOUTH))
-				{
-					poffsets[i][j][1] = 0;
-				}
-				else
-				{
-					ppatches[i][j] = ppatches[i][j]->getNeighborPatch(SOUTH);
-					poffsets[i][j][1] += patch_width;
-					poffsets[i][j][2] = ppatches[i][j]->getSurface()->getGridsPerEdge();
-				}
-			}
-			if (poffsets[i][j][0] >= (S32)patch_width)
-			{
-				if (!ppatches[i][j]->getNeighborPatch(EAST))
-				{
-					poffsets[i][j][0] = patch_width - 1;
-				}
-				else
-				{
-					ppatches[i][j] = ppatches[i][j]->getNeighborPatch(EAST);
-					poffsets[i][j][0] -= patch_width;
-					poffsets[i][j][2] = ppatches[i][j]->getSurface()->getGridsPerEdge();
-				}
-			}
-			if (poffsets[i][j][1] >= (S32)patch_width)
-			{
-				if (!ppatches[i][j]->getNeighborPatch(NORTH))
-				{
-					poffsets[i][j][1] = patch_width - 1;
-				}
-				else
-				{
-					ppatches[i][j] = ppatches[i][j]->getNeighborPatch(NORTH);
-					poffsets[i][j][1] -= patch_width;
-					poffsets[i][j][2] = ppatches[i][j]->getSurface()->getGridsPerEdge();
-				}
-			}
-		}
-	}
-
-	LLVector3 p00(-mpg,-mpg,
-				  *(ppatches[0][0]->mDataZ
-				  + poffsets[0][0][0]
-				  + poffsets[0][0][1]*poffsets[0][0][2]));
-	LLVector3 p01(-mpg,+mpg,
-				  *(ppatches[0][1]->mDataZ
-				  + poffsets[0][1][0]
-				  + poffsets[0][1][1]*poffsets[0][1][2]));
-	LLVector3 p10(+mpg,-mpg,
-				  *(ppatches[1][0]->mDataZ
-				  + poffsets[1][0][0]
-				  + poffsets[1][0][1]*poffsets[1][0][2]));
-	LLVector3 p11(+mpg,+mpg,
-				  *(ppatches[1][1]->mDataZ
-				  + poffsets[1][1][0]
-				  + poffsets[1][1][1]*poffsets[1][1][2]));
-
-	LLVector3 c1 = p11 - p00;
-	LLVector3 c2 = p01 - p10;
-
-	LLVector3 normal = c1;
-	normal %= c2;
-	normal.normVec();
-
-	llassert(mDataNorm);
-	*(mDataNorm + surface_stride * y + x) = normal;
+    U32 patch_width = mSurfacep->mPVArray.mPatchWidth;
+    U32 surface_stride = mSurfacep->getGridsPerEdge();
+
+    const F32 mpg = mSurfacep->getMetersPerGrid() * stride;
+
+    S32 poffsets[2][2][3];
+    poffsets[0][0][0] = x - stride;
+    poffsets[0][0][1] = y - stride;
+    poffsets[0][0][2] = surface_stride;
+
+    poffsets[0][1][0] = x - stride;
+    poffsets[0][1][1] = y + stride;
+    poffsets[0][1][2] = surface_stride;
+
+    poffsets[1][0][0] = x + stride;
+    poffsets[1][0][1] = y - stride;
+    poffsets[1][0][2] = surface_stride;
+
+    poffsets[1][1][0] = x + stride;
+    poffsets[1][1][1] = y + stride;
+    poffsets[1][1][2] = surface_stride;
+
+    const LLSurfacePatch *ppatches[2][2];
+
+    // LLVector3 p1, p2, p3, p4;
+
+    ppatches[0][0] = this;
+    ppatches[0][1] = this;
+    ppatches[1][0] = this;
+    ppatches[1][1] = this;
+
+    U32 i, j;
+    for (i = 0; i < 2; i++)
+    {
+        for (j = 0; j < 2; j++)
+        {
+            if (poffsets[i][j][0] < 0)
+            {
+                if (!ppatches[i][j]->getNeighborPatch(WEST))
+                {
+                    poffsets[i][j][0] = 0;
+                }
+                else
+                {
+                    ppatches[i][j] = ppatches[i][j]->getNeighborPatch(WEST);
+                    poffsets[i][j][0] += patch_width;
+                    poffsets[i][j][2] = ppatches[i][j]->getSurface()->getGridsPerEdge();
+                }
+            }
+            if (poffsets[i][j][1] < 0)
+            {
+                if (!ppatches[i][j]->getNeighborPatch(SOUTH))
+                {
+                    poffsets[i][j][1] = 0;
+                }
+                else
+                {
+                    ppatches[i][j] = ppatches[i][j]->getNeighborPatch(SOUTH);
+                    poffsets[i][j][1] += patch_width;
+                    poffsets[i][j][2] = ppatches[i][j]->getSurface()->getGridsPerEdge();
+                }
+            }
+            if (poffsets[i][j][0] >= (S32)patch_width)
+            {
+                if (!ppatches[i][j]->getNeighborPatch(EAST))
+                {
+                    poffsets[i][j][0] = patch_width - 1;
+                }
+                else
+                {
+                    ppatches[i][j] = ppatches[i][j]->getNeighborPatch(EAST);
+                    poffsets[i][j][0] -= patch_width;
+                    poffsets[i][j][2] = ppatches[i][j]->getSurface()->getGridsPerEdge();
+                }
+            }
+            if (poffsets[i][j][1] >= (S32)patch_width)
+            {
+                if (!ppatches[i][j]->getNeighborPatch(NORTH))
+                {
+                    poffsets[i][j][1] = patch_width - 1;
+                }
+                else
+                {
+                    ppatches[i][j] = ppatches[i][j]->getNeighborPatch(NORTH);
+                    poffsets[i][j][1] -= patch_width;
+                    poffsets[i][j][2] = ppatches[i][j]->getSurface()->getGridsPerEdge();
+                }
+            }
+        }
+    }
+
+    LLVector3 p00(-mpg,-mpg,
+                  *(ppatches[0][0]->mDataZ
+                  + poffsets[0][0][0]
+                  + poffsets[0][0][1]*poffsets[0][0][2]));
+    LLVector3 p01(-mpg,+mpg,
+                  *(ppatches[0][1]->mDataZ
+                  + poffsets[0][1][0]
+                  + poffsets[0][1][1]*poffsets[0][1][2]));
+    LLVector3 p10(+mpg,-mpg,
+                  *(ppatches[1][0]->mDataZ
+                  + poffsets[1][0][0]
+                  + poffsets[1][0][1]*poffsets[1][0][2]));
+    LLVector3 p11(+mpg,+mpg,
+                  *(ppatches[1][1]->mDataZ
+                  + poffsets[1][1][0]
+                  + poffsets[1][1][1]*poffsets[1][1][2]));
+
+    LLVector3 c1 = p11 - p00;
+    LLVector3 c2 = p01 - p10;
+
+    LLVector3 normal = c1;
+    normal %= c2;
+    normal.normVec();
+
+    llassert(mDataNorm);
+    *(mDataNorm + surface_stride * y + x) = normal;
 }
 
 template<>
 void LLSurfacePatch::calcNormal</*PBR=*/true>(const U32 x, const U32 y, const U32 stride)
 {
-	llassert(mDataNorm);
+    llassert(mDataNorm);
     constexpr U32 index = 0;
 
-	const U32 surface_stride = mSurfacep->getGridsPerEdge();
-	LLVector3& normal_out = *(mDataNorm + surface_stride * y + x);
-	calcNormalFlat(normal_out, x, y, index);
+    const U32 surface_stride = mSurfacep->getGridsPerEdge();
+    LLVector3& normal_out = *(mDataNorm + surface_stride * y + x);
+    calcNormalFlat(normal_out, x, y, index);
 }
 
 // Calculate the flat normal of a triangle whose least coordinate is specified by the given x,y values.
@@ -383,120 +383,120 @@ void LLSurfacePatch::calcNormalFlat(LLVector3& normal_out, const U32 x, const U3
 {
     llassert(index == 0 || index == 1);
 
-	U32 patch_width = mSurfacep->mPVArray.mPatchWidth;
-	U32 surface_stride = mSurfacep->getGridsPerEdge();
+    U32 patch_width = mSurfacep->mPVArray.mPatchWidth;
+    U32 surface_stride = mSurfacep->getGridsPerEdge();
 
     // Vertex stride is always 1 because we want the flat surface of the current triangle face
     constexpr U32 stride = 1;
 
-	const F32 mpg = mSurfacep->getMetersPerGrid() * stride;
-
-	S32 poffsets[2][2][2];
-	poffsets[0][0][0] = x;
-	poffsets[0][0][1] = y;
-
-	poffsets[0][1][0] = x;
-	poffsets[0][1][1] = y + stride;
-
-	poffsets[1][0][0] = x + stride;
-	poffsets[1][0][1] = y;
-
-	poffsets[1][1][0] = x + stride;
-	poffsets[1][1][1] = y + stride;
-
-	const LLSurfacePatch *ppatches[2][2];
-
-	// LLVector3 p1, p2, p3, p4;
-
-	ppatches[0][0] = this;
-	ppatches[0][1] = this;
-	ppatches[1][0] = this;
-	ppatches[1][1] = this;
-
-	U32 i, j;
-	for (i = 0; i < 2; i++)
-	{
-		for (j = 0; j < 2; j++)
-		{
-			if (poffsets[i][j][0] < 0)
-			{
-				if (!ppatches[i][j]->getNeighborPatch(WEST))
-				{
-					poffsets[i][j][0] = 0;
-				}
-				else
-				{
-					poffsets[i][j][0] += patch_width;
-					ppatches[i][j] = ppatches[i][j]->getNeighborPatch(WEST);
-				}
-			}
-			if (poffsets[i][j][1] < 0)
-			{
-				if (!ppatches[i][j]->getNeighborPatch(SOUTH))
-				{
-					poffsets[i][j][1] = 0;
-				}
-				else
-				{
-					poffsets[i][j][1] += patch_width;
-					ppatches[i][j] = ppatches[i][j]->getNeighborPatch(SOUTH);
-				}
-			}
-			if (poffsets[i][j][0] >= (S32)patch_width)
-			{
-				if (!ppatches[i][j]->getNeighborPatch(EAST))
-				{
-					poffsets[i][j][0] = patch_width - 1;
-				}
-				else
-				{
-					poffsets[i][j][0] -= patch_width;
-					ppatches[i][j] = ppatches[i][j]->getNeighborPatch(EAST);
-				}
-			}
-			if (poffsets[i][j][1] >= (S32)patch_width)
-			{
-				if (!ppatches[i][j]->getNeighborPatch(NORTH))
-				{
-					poffsets[i][j][1] = patch_width - 1;
-				}
-				else
-				{
-					poffsets[i][j][1] -= patch_width;
-					ppatches[i][j] = ppatches[i][j]->getNeighborPatch(NORTH);
-				}
-			}
-		}
-	}
-
-	LLVector3 p00(-mpg,-mpg,
-				  *(ppatches[0][0]->mDataZ
-				  + poffsets[0][0][0]
-				  + poffsets[0][0][1]*surface_stride));
-	LLVector3 p01(-mpg,+mpg,
-				  *(ppatches[0][1]->mDataZ
-				  + poffsets[0][1][0]
-				  + poffsets[0][1][1]*surface_stride));
-	LLVector3 p10(+mpg,-mpg,
-				  *(ppatches[1][0]->mDataZ
-				  + poffsets[1][0][0]
-				  + poffsets[1][0][1]*surface_stride));
-	LLVector3 p11(+mpg,+mpg,
-				  *(ppatches[1][1]->mDataZ
-				  + poffsets[1][1][0]
-				  + poffsets[1][1][1]*surface_stride));
-    
+    const F32 mpg = mSurfacep->getMetersPerGrid() * stride;
+
+    S32 poffsets[2][2][2];
+    poffsets[0][0][0] = x;
+    poffsets[0][0][1] = y;
+
+    poffsets[0][1][0] = x;
+    poffsets[0][1][1] = y + stride;
+
+    poffsets[1][0][0] = x + stride;
+    poffsets[1][0][1] = y;
+
+    poffsets[1][1][0] = x + stride;
+    poffsets[1][1][1] = y + stride;
+
+    const LLSurfacePatch *ppatches[2][2];
+
+    // LLVector3 p1, p2, p3, p4;
+
+    ppatches[0][0] = this;
+    ppatches[0][1] = this;
+    ppatches[1][0] = this;
+    ppatches[1][1] = this;
+
+    U32 i, j;
+    for (i = 0; i < 2; i++)
+    {
+        for (j = 0; j < 2; j++)
+        {
+            if (poffsets[i][j][0] < 0)
+            {
+                if (!ppatches[i][j]->getNeighborPatch(WEST))
+                {
+                    poffsets[i][j][0] = 0;
+                }
+                else
+                {
+                    poffsets[i][j][0] += patch_width;
+                    ppatches[i][j] = ppatches[i][j]->getNeighborPatch(WEST);
+                }
+            }
+            if (poffsets[i][j][1] < 0)
+            {
+                if (!ppatches[i][j]->getNeighborPatch(SOUTH))
+                {
+                    poffsets[i][j][1] = 0;
+                }
+                else
+                {
+                    poffsets[i][j][1] += patch_width;
+                    ppatches[i][j] = ppatches[i][j]->getNeighborPatch(SOUTH);
+                }
+            }
+            if (poffsets[i][j][0] >= (S32)patch_width)
+            {
+                if (!ppatches[i][j]->getNeighborPatch(EAST))
+                {
+                    poffsets[i][j][0] = patch_width - 1;
+                }
+                else
+                {
+                    poffsets[i][j][0] -= patch_width;
+                    ppatches[i][j] = ppatches[i][j]->getNeighborPatch(EAST);
+                }
+            }
+            if (poffsets[i][j][1] >= (S32)patch_width)
+            {
+                if (!ppatches[i][j]->getNeighborPatch(NORTH))
+                {
+                    poffsets[i][j][1] = patch_width - 1;
+                }
+                else
+                {
+                    poffsets[i][j][1] -= patch_width;
+                    ppatches[i][j] = ppatches[i][j]->getNeighborPatch(NORTH);
+                }
+            }
+        }
+    }
+
+    LLVector3 p00(-mpg,-mpg,
+                  *(ppatches[0][0]->mDataZ
+                  + poffsets[0][0][0]
+                  + poffsets[0][0][1]*surface_stride));
+    LLVector3 p01(-mpg,+mpg,
+                  *(ppatches[0][1]->mDataZ
+                  + poffsets[0][1][0]
+                  + poffsets[0][1][1]*surface_stride));
+    LLVector3 p10(+mpg,-mpg,
+                  *(ppatches[1][0]->mDataZ
+                  + poffsets[1][0][0]
+                  + poffsets[1][0][1]*surface_stride));
+    LLVector3 p11(+mpg,+mpg,
+                  *(ppatches[1][1]->mDataZ
+                  + poffsets[1][1][0]
+                  + poffsets[1][1][1]*surface_stride));
+
     // Triangle index / coordinate convention
     // for a single surface patch
     //
     // p01          p11
     //
-    // ^   ._____. 
-    // |   |\    | 
-    // |   | \ 1 | 
-    // |   |  \  | 
-    //     | 0 \ | 
-    // y   |____\| 
+    // ^   ._____.
+    // |   |\    |
+    // |   | \ 1 |
+    // |   |  \  |
+    //     | 0 \ |
+    // y   |____\|
     //
     // p00  x --->  p10
     //
@@ -522,288 +522,288 @@ void LLSurfacePatch::calcNormalFlat(LLVector3& normal_out, const U32 x, const U3
         normal.normVec();
     }
 
-	llassert(&normal_out);
-	normal_out = normal;
+    llassert(&normal_out);
+    normal_out = normal;
 }
 
 const LLVector3 &LLSurfacePatch::getNormal(const U32 x, const U32 y) const
 {
-	U32 surface_stride = mSurfacep->getGridsPerEdge();
-	llassert(mDataNorm);
-	return *(mDataNorm + surface_stride * y + x);
+    U32 surface_stride = mSurfacep->getGridsPerEdge();
+    llassert(mDataNorm);
+    return *(mDataNorm + surface_stride * y + x);
 }
 
 
 void LLSurfacePatch::updateCameraDistanceRegion(const LLVector3 &pos_region)
 {
-	if (LLPipeline::sDynamicLOD)
-	{
-		if (!gShiftFrame)
-		{
-			LLVector3 dv = pos_region;
-			dv -= mCenterRegion;
-			mVisInfo.mDistance = llmax(0.f, (F32)(dv.magVec() - mRadius))/
-				llmax(LLVOSurfacePatch::sLODFactor, 0.1f);
-		}
-	}
-	else
-	{
-		mVisInfo.mDistance = 0.f;
-	}
+    if (LLPipeline::sDynamicLOD)
+    {
+        if (!gShiftFrame)
+        {
+            LLVector3 dv = pos_region;
+            dv -= mCenterRegion;
+            mVisInfo.mDistance = llmax(0.f, (F32)(dv.magVec() - mRadius))/
+                llmax(LLVOSurfacePatch::sLODFactor, 0.1f);
+        }
+    }
+    else
+    {
+        mVisInfo.mDistance = 0.f;
+    }
 }
 
 F32 LLSurfacePatch::getDistance() const
 {
-	return mVisInfo.mDistance;
+    return mVisInfo.mDistance;
 }
 
 
 // Called when a patch has changed its height field
 // data.
-void LLSurfacePatch::updateVerticalStats() 
+void LLSurfacePatch::updateVerticalStats()
 {
-	if (!mDirtyZStats)
-	{
-		return;
-	}
-
-	U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
-	U32 grids_per_edge = mSurfacep->getGridsPerEdge();
-	F32 meters_per_grid = mSurfacep->getMetersPerGrid();
-
-	U32 i, j, k;
-	F32 z, total;
-
-	llassert(mDataZ);
-	z = *(mDataZ);
-
-	mMinZ = z;
-	mMaxZ = z;
-
-	k = 0;
-	total = 0.0f;
-
-	// Iterate to +1 because we need to do the edges correctly.
-	for (j=0; j<(grids_per_patch_edge+1); j++) 
-	{
-		for (i=0; i<(grids_per_patch_edge+1); i++) 
-		{
-			z = *(mDataZ + i + j*grids_per_edge);
-
-			if (z < mMinZ)
-			{
-				mMinZ = z;
-			}
-			if (z > mMaxZ)
-			{
-				mMaxZ = z;
-			}
-			total += z;
-			k++;
-		}
-	}
-	mMeanZ = total / (F32) k;
-	mCenterRegion.mV[VZ] = 0.5f * (mMinZ + mMaxZ);
-
-	LLVector3 diam_vec(meters_per_grid*grids_per_patch_edge,
-						meters_per_grid*grids_per_patch_edge,
-						mMaxZ - mMinZ);
-	mRadius = diam_vec.magVec() * 0.5f;
-
-	mSurfacep->mMaxZ = llmax(mMaxZ, mSurfacep->mMaxZ);
-	mSurfacep->mMinZ = llmin(mMinZ, mSurfacep->mMinZ);
-	mSurfacep->mHasZData = TRUE;
-	mSurfacep->getRegion()->calculateCenterGlobal();
-
-	if (mVObjp)
-	{
-		mVObjp->dirtyPatch();
-	}
-	mDirtyZStats = FALSE;
+    if (!mDirtyZStats)
+    {
+        return;
+    }
+
+    U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
+    U32 grids_per_edge = mSurfacep->getGridsPerEdge();
+    F32 meters_per_grid = mSurfacep->getMetersPerGrid();
+
+    U32 i, j, k;
+    F32 z, total;
+
+    llassert(mDataZ);
+    z = *(mDataZ);
+
+    mMinZ = z;
+    mMaxZ = z;
+
+    k = 0;
+    total = 0.0f;
+
+    // Iterate to +1 because we need to do the edges correctly.
+    for (j=0; j<(grids_per_patch_edge+1); j++)
+    {
+        for (i=0; i<(grids_per_patch_edge+1); i++)
+        {
+            z = *(mDataZ + i + j*grids_per_edge);
+
+            if (z < mMinZ)
+            {
+                mMinZ = z;
+            }
+            if (z > mMaxZ)
+            {
+                mMaxZ = z;
+            }
+            total += z;
+            k++;
+        }
+    }
+    mMeanZ = total / (F32) k;
+    mCenterRegion.mV[VZ] = 0.5f * (mMinZ + mMaxZ);
+
+    LLVector3 diam_vec(meters_per_grid*grids_per_patch_edge,
+                        meters_per_grid*grids_per_patch_edge,
+                        mMaxZ - mMinZ);
+    mRadius = diam_vec.magVec() * 0.5f;
+
+    mSurfacep->mMaxZ = llmax(mMaxZ, mSurfacep->mMaxZ);
+    mSurfacep->mMinZ = llmin(mMinZ, mSurfacep->mMinZ);
+    mSurfacep->mHasZData = TRUE;
+    mSurfacep->getRegion()->calculateCenterGlobal();
+
+    if (mVObjp)
+    {
+        mVObjp->dirtyPatch();
+    }
+    mDirtyZStats = FALSE;
 }
 
 
 template<bool PBR>
-void LLSurfacePatch::updateNormals() 
+void LLSurfacePatch::updateNormals()
 {
-	if (mSurfacep->mType == 'w')
-	{
-		return;
-	}
-	U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
-	U32 grids_per_edge = mSurfacep->getGridsPerEdge();
-
-	BOOL dirty_patch = FALSE;
-
-	U32 i, j;
-	// update the east edge
-	if (mNormalsInvalid[EAST] || mNormalsInvalid[NORTHEAST] || mNormalsInvalid[SOUTHEAST])
-	{
-		for (j = 0; j <= grids_per_patch_edge; j++)
-		{
-			calcNormal<PBR>(grids_per_patch_edge, j, 2);
-			calcNormal<PBR>(grids_per_patch_edge - 1, j, 2);
-			calcNormal<PBR>(grids_per_patch_edge - 2, j, 2);
-		}
-
-		dirty_patch = TRUE;
-	}
-
-	// update the north edge
-	if (mNormalsInvalid[NORTHEAST] || mNormalsInvalid[NORTH] || mNormalsInvalid[NORTHWEST])
-	{
-		for (i = 0; i <= grids_per_patch_edge; i++)
-		{
-			calcNormal<PBR>(i, grids_per_patch_edge, 2);
-			calcNormal<PBR>(i, grids_per_patch_edge - 1, 2);
-			calcNormal<PBR>(i, grids_per_patch_edge - 2, 2);
-		}
-
-		dirty_patch = TRUE;
-	}
-
-	// update the west edge
-	if (mNormalsInvalid[NORTHWEST] || mNormalsInvalid[WEST] || mNormalsInvalid[SOUTHWEST])
-	{
-		if (!getNeighborPatch(NORTH) && getNeighborPatch(NORTHWEST) && getNeighborPatch(NORTHWEST)->getHasReceivedData())
-		{
-			*(mDataZ + grids_per_patch_edge*grids_per_edge) = *(getNeighborPatch(NORTHWEST)->mDataZ + grids_per_patch_edge);
-		}
-
-		for (j = 0; j < grids_per_patch_edge; j++)
-		{
-			calcNormal<PBR>(0, j, 2);
-			calcNormal<PBR>(1, j, 2);
-		}
-		dirty_patch = TRUE;
-	}
-
-	// update the south edge
-	if (mNormalsInvalid[SOUTHWEST] || mNormalsInvalid[SOUTH] || mNormalsInvalid[SOUTHEAST])
-	{
-		if (!getNeighborPatch(EAST) && getNeighborPatch(SOUTHEAST) && getNeighborPatch(SOUTHEAST)->getHasReceivedData())
-		{
-			*(mDataZ + grids_per_patch_edge) = *(getNeighborPatch(SOUTHEAST)->mDataZ + grids_per_patch_edge * getNeighborPatch(SOUTHEAST)->getSurface()->getGridsPerEdge());
-		}
-
-		for (i = 0; i < grids_per_patch_edge; i++)
-		{
-			calcNormal<PBR>(i, 0, 2);
-			calcNormal<PBR>(i, 1, 2);
-		}
-		dirty_patch = TRUE;
-	}
-
-	// Invalidating the northeast corner is different, because depending on what the adjacent neighbors are,
-	// we'll want to do different things.
-	if (mNormalsInvalid[NORTHEAST])
-	{
-		if (!getNeighborPatch(NORTHEAST))
-		{
-			if (!getNeighborPatch(NORTH))
-			{
-				if (!getNeighborPatch(EAST))
-				{
-					// No north or east neighbors.  Pull from the diagonal in your own patch.
-					*(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
-						*(mDataZ + grids_per_patch_edge - 1 + (grids_per_patch_edge - 1)*grids_per_edge);
-				}
-				else
-				{
-					if (getNeighborPatch(EAST)->getHasReceivedData())
-					{
-						// East, but not north.  Pull from your east neighbor's northwest point.
-						*(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
-							*(getNeighborPatch(EAST)->mDataZ + (getNeighborPatch(EAST)->getSurface()->getGridsPerPatchEdge() - 1)
-							*getNeighborPatch(EAST)->getSurface()->getGridsPerEdge());
-					}
-					else
-					{
-						*(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
-							*(mDataZ + grids_per_patch_edge - 1 + (grids_per_patch_edge - 1)*grids_per_edge);
-					}
-				}
-			}
-			else
-			{
-				// We have a north.
-				if (getNeighborPatch(EAST))
-				{
-					// North and east neighbors, but not northeast.
-					// Pull from diagonal in your own patch.
-					*(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
-						*(mDataZ + grids_per_patch_edge - 1 + (grids_per_patch_edge - 1)*grids_per_edge);
-				}
-				else
-				{
-					if (getNeighborPatch(NORTH)->getHasReceivedData())
-					{
-						// North, but not east.  Pull from your north neighbor's southeast corner.
-						*(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
-							*(getNeighborPatch(NORTH)->mDataZ + (getNeighborPatch(NORTH)->getSurface()->getGridsPerPatchEdge() - 1));
-					}
-					else
-					{
-						*(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
-							*(mDataZ + grids_per_patch_edge - 1 + (grids_per_patch_edge - 1)*grids_per_edge);
-					}
-				}
-			}
-		}
-		else if (getNeighborPatch(NORTHEAST)->mSurfacep != mSurfacep)
-		{
-			if (
-				(!getNeighborPatch(NORTH) || (getNeighborPatch(NORTH)->mSurfacep != mSurfacep))
-				&&
-				(!getNeighborPatch(EAST) || (getNeighborPatch(EAST)->mSurfacep != mSurfacep)))
-			{
-				U32 own_xpos, own_ypos, neighbor_xpos, neighbor_ypos;
-				S32 own_offset = 0, neighbor_offset = 0;
-				from_region_handle(mSurfacep->getRegion()->getHandle(), &own_xpos, &own_ypos);
-				from_region_handle(getNeighborPatch(NORTHEAST)->mSurfacep->getRegion()->getHandle(), &neighbor_xpos, &neighbor_ypos);
-				if (own_ypos >= neighbor_ypos)
-					neighbor_offset = own_ypos - neighbor_ypos;
-				else
-					own_offset = neighbor_ypos - own_ypos;
-
-				*(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
-					*(getNeighborPatch(NORTHEAST)->mDataZ + (grids_per_edge + neighbor_offset - own_offset - 1) * getNeighborPatch(NORTHEAST)->getSurface()->getGridsPerEdge());
-			}
-		}
-		else
-		{
-			// We've got a northeast patch in the same surface.
-			// The z and normals will be handled by that patch.
-		}
-		calcNormal<PBR>(grids_per_patch_edge, grids_per_patch_edge, 2);
-		calcNormal<PBR>(grids_per_patch_edge, grids_per_patch_edge - 1, 2);
-		calcNormal<PBR>(grids_per_patch_edge - 1, grids_per_patch_edge, 2);
-		calcNormal<PBR>(grids_per_patch_edge - 1, grids_per_patch_edge - 1, 2);
-		dirty_patch = TRUE;
-	}
-
-	// update the middle normals
-	if (mNormalsInvalid[MIDDLE])
-	{
-		for (j=2; j < grids_per_patch_edge - 2; j++)
-		{
-			for (i=2; i < grids_per_patch_edge - 2; i++)
-			{
-				calcNormal<PBR>(i, j, 2);
-			}
-		}
-		dirty_patch = TRUE;
-	}
-
-	if (dirty_patch)
-	{
-		mSurfacep->dirtySurfacePatch(this);
-	}
-
-	for (i = 0; i < 9; i++)
-	{
-		mNormalsInvalid[i] = FALSE;
-	}
+    if (mSurfacep->mType == 'w')
+    {
+        return;
+    }
+    U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
+    U32 grids_per_edge = mSurfacep->getGridsPerEdge();
+
+    BOOL dirty_patch = FALSE;
+
+    U32 i, j;
+    // update the east edge
+    if (mNormalsInvalid[EAST] || mNormalsInvalid[NORTHEAST] || mNormalsInvalid[SOUTHEAST])
+    {
+        for (j = 0; j <= grids_per_patch_edge; j++)
+        {
+            calcNormal<PBR>(grids_per_patch_edge, j, 2);
+            calcNormal<PBR>(grids_per_patch_edge - 1, j, 2);
+            calcNormal<PBR>(grids_per_patch_edge - 2, j, 2);
+        }
+
+        dirty_patch = TRUE;
+    }
+
+    // update the north edge
+    if (mNormalsInvalid[NORTHEAST] || mNormalsInvalid[NORTH] || mNormalsInvalid[NORTHWEST])
+    {
+        for (i = 0; i <= grids_per_patch_edge; i++)
+        {
+            calcNormal<PBR>(i, grids_per_patch_edge, 2);
+            calcNormal<PBR>(i, grids_per_patch_edge - 1, 2);
+            calcNormal<PBR>(i, grids_per_patch_edge - 2, 2);
+        }
+
+        dirty_patch = TRUE;
+    }
+
+    // update the west edge
+    if (mNormalsInvalid[NORTHWEST] || mNormalsInvalid[WEST] || mNormalsInvalid[SOUTHWEST])
+    {
+        if (!getNeighborPatch(NORTH) && getNeighborPatch(NORTHWEST) && getNeighborPatch(NORTHWEST)->getHasReceivedData())
+        {
+            *(mDataZ + grids_per_patch_edge*grids_per_edge) = *(getNeighborPatch(NORTHWEST)->mDataZ + grids_per_patch_edge);
+        }
+
+        for (j = 0; j < grids_per_patch_edge; j++)
+        {
+            calcNormal<PBR>(0, j, 2);
+            calcNormal<PBR>(1, j, 2);
+        }
+        dirty_patch = TRUE;
+    }
+
+    // update the south edge
+    if (mNormalsInvalid[SOUTHWEST] || mNormalsInvalid[SOUTH] || mNormalsInvalid[SOUTHEAST])
+    {
+        if (!getNeighborPatch(EAST) && getNeighborPatch(SOUTHEAST) && getNeighborPatch(SOUTHEAST)->getHasReceivedData())
+        {
+            *(mDataZ + grids_per_patch_edge) = *(getNeighborPatch(SOUTHEAST)->mDataZ + grids_per_patch_edge * getNeighborPatch(SOUTHEAST)->getSurface()->getGridsPerEdge());
+        }
+
+        for (i = 0; i < grids_per_patch_edge; i++)
+        {
+            calcNormal<PBR>(i, 0, 2);
+            calcNormal<PBR>(i, 1, 2);
+        }
+        dirty_patch = TRUE;
+    }
+
+    // Invalidating the northeast corner is different, because depending on what the adjacent neighbors are,
+    // we'll want to do different things.
+    if (mNormalsInvalid[NORTHEAST])
+    {
+        if (!getNeighborPatch(NORTHEAST))
+        {
+            if (!getNeighborPatch(NORTH))
+            {
+                if (!getNeighborPatch(EAST))
+                {
+                    // No north or east neighbors.  Pull from the diagonal in your own patch.
+                    *(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
+                        *(mDataZ + grids_per_patch_edge - 1 + (grids_per_patch_edge - 1)*grids_per_edge);
+                }
+                else
+                {
+                    if (getNeighborPatch(EAST)->getHasReceivedData())
+                    {
+                        // East, but not north.  Pull from your east neighbor's northwest point.
+                        *(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
+                            *(getNeighborPatch(EAST)->mDataZ + (getNeighborPatch(EAST)->getSurface()->getGridsPerPatchEdge() - 1)
+                            *getNeighborPatch(EAST)->getSurface()->getGridsPerEdge());
+                    }
+                    else
+                    {
+                        *(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
+                            *(mDataZ + grids_per_patch_edge - 1 + (grids_per_patch_edge - 1)*grids_per_edge);
+                    }
+                }
+            }
+            else
+            {
+                // We have a north.
+                if (getNeighborPatch(EAST))
+                {
+                    // North and east neighbors, but not northeast.
+                    // Pull from diagonal in your own patch.
+                    *(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
+                        *(mDataZ + grids_per_patch_edge - 1 + (grids_per_patch_edge - 1)*grids_per_edge);
+                }
+                else
+                {
+                    if (getNeighborPatch(NORTH)->getHasReceivedData())
+                    {
+                        // North, but not east.  Pull from your north neighbor's southeast corner.
+                        *(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
+                            *(getNeighborPatch(NORTH)->mDataZ + (getNeighborPatch(NORTH)->getSurface()->getGridsPerPatchEdge() - 1));
+                    }
+                    else
+                    {
+                        *(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
+                            *(mDataZ + grids_per_patch_edge - 1 + (grids_per_patch_edge - 1)*grids_per_edge);
+                    }
+                }
+            }
+        }
+        else if (getNeighborPatch(NORTHEAST)->mSurfacep != mSurfacep)
+        {
+            if (
+                (!getNeighborPatch(NORTH) || (getNeighborPatch(NORTH)->mSurfacep != mSurfacep))
+                &&
+                (!getNeighborPatch(EAST) || (getNeighborPatch(EAST)->mSurfacep != mSurfacep)))
+            {
+                U32 own_xpos, own_ypos, neighbor_xpos, neighbor_ypos;
+                S32 own_offset = 0, neighbor_offset = 0;
+                from_region_handle(mSurfacep->getRegion()->getHandle(), &own_xpos, &own_ypos);
+                from_region_handle(getNeighborPatch(NORTHEAST)->mSurfacep->getRegion()->getHandle(), &neighbor_xpos, &neighbor_ypos);
+                if (own_ypos >= neighbor_ypos)
+                    neighbor_offset = own_ypos - neighbor_ypos;
+                else
+                    own_offset = neighbor_ypos - own_ypos;
+
+                *(mDataZ + grids_per_patch_edge + grids_per_patch_edge*grids_per_edge) =
+                    *(getNeighborPatch(NORTHEAST)->mDataZ + (grids_per_edge + neighbor_offset - own_offset - 1) * getNeighborPatch(NORTHEAST)->getSurface()->getGridsPerEdge());
+            }
+        }
+        else
+        {
+            // We've got a northeast patch in the same surface.
+            // The z and normals will be handled by that patch.
+        }
+        calcNormal<PBR>(grids_per_patch_edge, grids_per_patch_edge, 2);
+        calcNormal<PBR>(grids_per_patch_edge, grids_per_patch_edge - 1, 2);
+        calcNormal<PBR>(grids_per_patch_edge - 1, grids_per_patch_edge, 2);
+        calcNormal<PBR>(grids_per_patch_edge - 1, grids_per_patch_edge - 1, 2);
+        dirty_patch = TRUE;
+    }
+
+    // update the middle normals
+    if (mNormalsInvalid[MIDDLE])
+    {
+        for (j=2; j < grids_per_patch_edge - 2; j++)
+        {
+            for (i=2; i < grids_per_patch_edge - 2; i++)
+            {
+                calcNormal<PBR>(i, j, 2);
+            }
+        }
+        dirty_patch = TRUE;
+    }
+
+    if (dirty_patch)
+    {
+        mSurfacep->dirtySurfacePatch(this);
+    }
+
+    for (i = 0; i < 9; i++)
+    {
+        mNormalsInvalid[i] = FALSE;
+    }
 }
 
 template void LLSurfacePatch::updateNormals</*PBR=*/false>();
@@ -811,425 +811,425 @@ template void LLSurfacePatch::updateNormals</*PBR=*/true>();
 
 void LLSurfacePatch::updateEastEdge()
 {
-	U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
-	U32 grids_per_edge = mSurfacep->getGridsPerEdge();
-
-	U32 grids_per_edge_east = grids_per_edge;
-
-	U32 j, k, h;
-	F32 *west_surface, *east_surface;
-
-	if (!getNeighborPatch(EAST))
-	{
-		west_surface = mDataZ + grids_per_patch_edge;
-		east_surface = mDataZ + grids_per_patch_edge - 1;
-	}
-	else if (mConnectedEdge & EAST_EDGE)
-	{
-		west_surface = mDataZ + grids_per_patch_edge;
-		east_surface = getNeighborPatch(EAST)->mDataZ;
-		grids_per_edge_east = getNeighborPatch(EAST)->getSurface()->getGridsPerEdge();
-	}
-	else
-	{
-		return;
-	}
-
-	// If patchp is on the east edge of its surface, then we update the east
-	// side buffer
-	for (j=0; j < grids_per_patch_edge; j++)
-	{
-		k = j * grids_per_edge;
-		h = j * grids_per_edge_east;
-		*(west_surface + k) = *(east_surface + h);	// update buffer Z
-	}
+    U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
+    U32 grids_per_edge = mSurfacep->getGridsPerEdge();
+
+    U32 grids_per_edge_east = grids_per_edge;
+
+    U32 j, k, h;
+    F32 *west_surface, *east_surface;
+
+    if (!getNeighborPatch(EAST))
+    {
+        west_surface = mDataZ + grids_per_patch_edge;
+        east_surface = mDataZ + grids_per_patch_edge - 1;
+    }
+    else if (mConnectedEdge & EAST_EDGE)
+    {
+        west_surface = mDataZ + grids_per_patch_edge;
+        east_surface = getNeighborPatch(EAST)->mDataZ;
+        grids_per_edge_east = getNeighborPatch(EAST)->getSurface()->getGridsPerEdge();
+    }
+    else
+    {
+        return;
+    }
+
+    // If patchp is on the east edge of its surface, then we update the east
+    // side buffer
+    for (j=0; j < grids_per_patch_edge; j++)
+    {
+        k = j * grids_per_edge;
+        h = j * grids_per_edge_east;
+        *(west_surface + k) = *(east_surface + h);  // update buffer Z
+    }
 }
 
 
 void LLSurfacePatch::updateNorthEdge()
 {
-	U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
-	U32 grids_per_edge = mSurfacep->getGridsPerEdge();
-
-	U32 i;
-	F32 *south_surface, *north_surface;
-
-	if (!getNeighborPatch(NORTH))
-	{
-		south_surface = mDataZ + grids_per_patch_edge*grids_per_edge;
-		north_surface = mDataZ + (grids_per_patch_edge - 1) * grids_per_edge;
-	}
-	else if (mConnectedEdge & NORTH_EDGE)
-	{
-		south_surface = mDataZ + grids_per_patch_edge*grids_per_edge;
-		north_surface = getNeighborPatch(NORTH)->mDataZ;
-	}
-	else
-	{
-		return;
-	}
-
-	// Update patchp's north edge ...
-	for (i=0; i<grids_per_patch_edge; i++)
-	{
-		*(south_surface + i) = *(north_surface + i);	// update buffer Z
-	}
+    U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
+    U32 grids_per_edge = mSurfacep->getGridsPerEdge();
+
+    U32 i;
+    F32 *south_surface, *north_surface;
+
+    if (!getNeighborPatch(NORTH))
+    {
+        south_surface = mDataZ + grids_per_patch_edge*grids_per_edge;
+        north_surface = mDataZ + (grids_per_patch_edge - 1) * grids_per_edge;
+    }
+    else if (mConnectedEdge & NORTH_EDGE)
+    {
+        south_surface = mDataZ + grids_per_patch_edge*grids_per_edge;
+        north_surface = getNeighborPatch(NORTH)->mDataZ;
+    }
+    else
+    {
+        return;
+    }
+
+    // Update patchp's north edge ...
+    for (i=0; i<grids_per_patch_edge; i++)
+    {
+        *(south_surface + i) = *(north_surface + i);    // update buffer Z
+    }
 }
 
 
 BOOL LLSurfacePatch::updateTexture()
 {
-	if (mSTexUpdate)		//  Update texture as needed
-	{
-		F32 meters_per_grid = getSurface()->getMetersPerGrid();
-		F32 grids_per_patch_edge = (F32)getSurface()->getGridsPerPatchEdge();
-
-		if ((!getNeighborPatch(EAST) || getNeighborPatch(EAST)->getHasReceivedData())
-			&& (!getNeighborPatch(WEST) || getNeighborPatch(WEST)->getHasReceivedData())
-			&& (!getNeighborPatch(SOUTH) || getNeighborPatch(SOUTH)->getHasReceivedData())
-			&& (!getNeighborPatch(NORTH) || getNeighborPatch(NORTH)->getHasReceivedData()))
-		{
-			LLViewerRegion *regionp = getSurface()->getRegion();
-			LLVector3d origin_region = getOriginGlobal() - getSurface()->getOriginGlobal();
-
-			// Have to figure out a better way to deal with these edge conditions...
-			LLVLComposition* comp = regionp->getComposition();
-			if (!mHeightsGenerated)
-			{
-				F32 patch_size = meters_per_grid*(grids_per_patch_edge+1);
-				if (comp->generateHeights((F32)origin_region[VX], (F32)origin_region[VY],
-										  patch_size, patch_size))
-				{
-					mHeightsGenerated = TRUE;
-				}
-				else
-				{
-					return FALSE;
-				}
-			}
-			
-			if (comp->generateComposition())
-			{
-				if (mVObjp)
-				{
-					mVObjp->dirtyGeom();
-					gPipeline.markGLRebuild(mVObjp);
-					return !mSTexUpdate;
-				}
-			}
-		}
-		return FALSE;
-	}
-	else
-	{
-		return TRUE;
-	}
+    if (mSTexUpdate)        //  Update texture as needed
+    {
+        F32 meters_per_grid = getSurface()->getMetersPerGrid();
+        F32 grids_per_patch_edge = (F32)getSurface()->getGridsPerPatchEdge();
+
+        if ((!getNeighborPatch(EAST) || getNeighborPatch(EAST)->getHasReceivedData())
+            && (!getNeighborPatch(WEST) || getNeighborPatch(WEST)->getHasReceivedData())
+            && (!getNeighborPatch(SOUTH) || getNeighborPatch(SOUTH)->getHasReceivedData())
+            && (!getNeighborPatch(NORTH) || getNeighborPatch(NORTH)->getHasReceivedData()))
+        {
+            LLViewerRegion *regionp = getSurface()->getRegion();
+            LLVector3d origin_region = getOriginGlobal() - getSurface()->getOriginGlobal();
+
+            // Have to figure out a better way to deal with these edge conditions...
+            LLVLComposition* comp = regionp->getComposition();
+            if (!mHeightsGenerated)
+            {
+                F32 patch_size = meters_per_grid*(grids_per_patch_edge+1);
+                if (comp->generateHeights((F32)origin_region[VX], (F32)origin_region[VY],
+                                          patch_size, patch_size))
+                {
+                    mHeightsGenerated = TRUE;
+                }
+                else
+                {
+                    return FALSE;
+                }
+            }
+
+            if (comp->generateComposition())
+            {
+                if (mVObjp)
+                {
+                    mVObjp->dirtyGeom();
+                    gPipeline.markGLRebuild(mVObjp);
+                    return !mSTexUpdate;
+                }
+            }
+        }
+        return FALSE;
+    }
+    else
+    {
+        return TRUE;
+    }
 }
 
 void LLSurfacePatch::updateGL()
 {
-	LL_PROFILE_ZONE_SCOPED
-	F32 meters_per_grid = getSurface()->getMetersPerGrid();
-	F32 grids_per_patch_edge = (F32)getSurface()->getGridsPerPatchEdge();
-
-	LLViewerRegion *regionp = getSurface()->getRegion();
-	LLVector3d origin_region = getOriginGlobal() - getSurface()->getOriginGlobal();
-
-	LLVLComposition* comp = regionp->getComposition();
-	
-	updateCompositionStats();
-	F32 tex_patch_size = meters_per_grid*grids_per_patch_edge;
-	if (comp->generateMinimapTileLand((F32)origin_region[VX], (F32)origin_region[VY],
-							  tex_patch_size, tex_patch_size))
-	{
-		mSTexUpdate = FALSE;
-
-		// Also generate the water texture
-		mSurfacep->generateWaterTexture((F32)origin_region.mdV[VX], (F32)origin_region.mdV[VY],
-										tex_patch_size, tex_patch_size);
-	}
+    LL_PROFILE_ZONE_SCOPED
+    F32 meters_per_grid = getSurface()->getMetersPerGrid();
+    F32 grids_per_patch_edge = (F32)getSurface()->getGridsPerPatchEdge();
+
+    LLViewerRegion *regionp = getSurface()->getRegion();
+    LLVector3d origin_region = getOriginGlobal() - getSurface()->getOriginGlobal();
+
+    LLVLComposition* comp = regionp->getComposition();
+
+    updateCompositionStats();
+    F32 tex_patch_size = meters_per_grid*grids_per_patch_edge;
+    if (comp->generateMinimapTileLand((F32)origin_region[VX], (F32)origin_region[VY],
+                              tex_patch_size, tex_patch_size))
+    {
+        mSTexUpdate = FALSE;
+
+        // Also generate the water texture
+        mSurfacep->generateWaterTexture((F32)origin_region.mdV[VX], (F32)origin_region.mdV[VY],
+                                        tex_patch_size, tex_patch_size);
+    }
 }
 
 void LLSurfacePatch::dirtyZ()
 {
-	mSTexUpdate = TRUE;
-
-	// Invalidate all normals in this patch
-	U32 i;
-	for (i = 0; i < 9; i++)
-	{
-		mNormalsInvalid[i] = TRUE;
-	}
-
-	// Invalidate normals in this and neighboring patches
-	for (i = 0; i < 8; i++)
-	{
-		if (getNeighborPatch(i))
-		{
-			getNeighborPatch(i)->mNormalsInvalid[gDirOpposite[i]] = TRUE;
-			getNeighborPatch(i)->dirty();
-			if (i < 4)
-			{
-				getNeighborPatch(i)->mNormalsInvalid[gDirAdjacent[gDirOpposite[i]][0]] = TRUE;
-				getNeighborPatch(i)->mNormalsInvalid[gDirAdjacent[gDirOpposite[i]][1]] = TRUE;
-			}
-		}
-	}
-
-	dirty();
-	mLastUpdateTime = gFrameTime;
+    mSTexUpdate = TRUE;
+
+    // Invalidate all normals in this patch
+    U32 i;
+    for (i = 0; i < 9; i++)
+    {
+        mNormalsInvalid[i] = TRUE;
+    }
+
+    // Invalidate normals in this and neighboring patches
+    for (i = 0; i < 8; i++)
+    {
+        if (getNeighborPatch(i))
+        {
+            getNeighborPatch(i)->mNormalsInvalid[gDirOpposite[i]] = TRUE;
+            getNeighborPatch(i)->dirty();
+            if (i < 4)
+            {
+                getNeighborPatch(i)->mNormalsInvalid[gDirAdjacent[gDirOpposite[i]][0]] = TRUE;
+                getNeighborPatch(i)->mNormalsInvalid[gDirAdjacent[gDirOpposite[i]][1]] = TRUE;
+            }
+        }
+    }
+
+    dirty();
+    mLastUpdateTime = gFrameTime;
 }
 
 
 const U64 &LLSurfacePatch::getLastUpdateTime() const
 {
-	return mLastUpdateTime;
+    return mLastUpdateTime;
 }
 
 F32 LLSurfacePatch::getMaxZ() const
 {
-	return mMaxZ;
+    return mMaxZ;
 }
 
 F32 LLSurfacePatch::getMinZ() const
 {
-	return mMinZ;
+    return mMinZ;
 }
 
 void LLSurfacePatch::setOriginGlobal(const LLVector3d &origin_global)
 {
-	mOriginGlobal = origin_global;
+    mOriginGlobal = origin_global;
+
+    LLVector3 origin_region;
+    origin_region.setVec(mOriginGlobal - mSurfacep->getOriginGlobal());
 
-	LLVector3 origin_region;
-	origin_region.setVec(mOriginGlobal - mSurfacep->getOriginGlobal());
+    mOriginRegion = origin_region;
+    mCenterRegion.mV[VX] = origin_region.mV[VX] + 0.5f*mSurfacep->getGridsPerPatchEdge()*mSurfacep->getMetersPerGrid();
+    mCenterRegion.mV[VY] = origin_region.mV[VY] + 0.5f*mSurfacep->getGridsPerPatchEdge()*mSurfacep->getMetersPerGrid();
 
-	mOriginRegion = origin_region;
-	mCenterRegion.mV[VX] = origin_region.mV[VX] + 0.5f*mSurfacep->getGridsPerPatchEdge()*mSurfacep->getMetersPerGrid();
-	mCenterRegion.mV[VY] = origin_region.mV[VY] + 0.5f*mSurfacep->getGridsPerPatchEdge()*mSurfacep->getMetersPerGrid();
+    mVisInfo.mbIsVisible = FALSE;
+    mVisInfo.mDistance = 512.0f;
+    mVisInfo.mRenderLevel = 0;
+    mVisInfo.mRenderStride = mSurfacep->getGridsPerPatchEdge();
 
-	mVisInfo.mbIsVisible = FALSE;
-	mVisInfo.mDistance = 512.0f;
-	mVisInfo.mRenderLevel = 0;
-	mVisInfo.mRenderStride = mSurfacep->getGridsPerPatchEdge();
-	
 }
 
 void LLSurfacePatch::connectNeighbor(LLSurfacePatch *neighbor_patchp, const U32 direction)
 {
-	llassert(neighbor_patchp);
-	if (!neighbor_patchp) return;
-	mNormalsInvalid[direction] = TRUE;
-	neighbor_patchp->mNormalsInvalid[gDirOpposite[direction]] = TRUE;
-
-	setNeighborPatch(direction, neighbor_patchp);
-	neighbor_patchp->setNeighborPatch(gDirOpposite[direction], this);
-
-	if (EAST == direction)
-	{
-		mConnectedEdge |= EAST_EDGE;
-		neighbor_patchp->mConnectedEdge |= WEST_EDGE;
-	}
-	else if (NORTH == direction)
-	{
-		mConnectedEdge |= NORTH_EDGE;
-		neighbor_patchp->mConnectedEdge |= SOUTH_EDGE;
-	}
-	else if (WEST == direction)
-	{
-		mConnectedEdge |= WEST_EDGE;
-		neighbor_patchp->mConnectedEdge |= EAST_EDGE;
-	}
-	else if (SOUTH == direction)
-	{
-		mConnectedEdge |= SOUTH_EDGE;
-		neighbor_patchp->mConnectedEdge |= NORTH_EDGE;
-	}
+    llassert(neighbor_patchp);
+    if (!neighbor_patchp) return;
+    mNormalsInvalid[direction] = TRUE;
+    neighbor_patchp->mNormalsInvalid[gDirOpposite[direction]] = TRUE;
+
+    setNeighborPatch(direction, neighbor_patchp);
+    neighbor_patchp->setNeighborPatch(gDirOpposite[direction], this);
+
+    if (EAST == direction)
+    {
+        mConnectedEdge |= EAST_EDGE;
+        neighbor_patchp->mConnectedEdge |= WEST_EDGE;
+    }
+    else if (NORTH == direction)
+    {
+        mConnectedEdge |= NORTH_EDGE;
+        neighbor_patchp->mConnectedEdge |= SOUTH_EDGE;
+    }
+    else if (WEST == direction)
+    {
+        mConnectedEdge |= WEST_EDGE;
+        neighbor_patchp->mConnectedEdge |= EAST_EDGE;
+    }
+    else if (SOUTH == direction)
+    {
+        mConnectedEdge |= SOUTH_EDGE;
+        neighbor_patchp->mConnectedEdge |= NORTH_EDGE;
+    }
 }
 
 void LLSurfacePatch::updateVisibility()
 {
-	if (mVObjp.isNull())
-	{
-		return;
-	}
-
-	const F32 DEFAULT_DELTA_ANGLE 	= (0.15f);
-	U32 old_render_stride, max_render_stride;
-	U32 new_render_level;
-	F32 stride_per_distance = DEFAULT_DELTA_ANGLE / mSurfacep->getMetersPerGrid();
-	U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
-
-	LLVector4a center;
-	center.load3( (mCenterRegion + mSurfacep->getOriginAgent()).mV);
-	LLVector4a radius;
-	radius.splat(mRadius);
-
-	// sphere in frustum on global coordinates
-	if (LLViewerCamera::getInstance()->AABBInFrustumNoFarClip(center, radius))
-	{
-		// We now need to calculate the render stride based on patchp's distance 
-		// from LLCamera render_stride is governed by a relation something like this...
-		//
-		//                       delta_angle * patch.distance
-		// render_stride <=  ----------------------------------------
-		//                           mMetersPerGrid
-		//
-		// where 'delta_angle' is the desired solid angle of the average polgon on a patch.
-		//
-		// Any render_stride smaller than the RHS would be 'satisfactory'.  Smaller 
-		// strides give more resolution, but efficiency suggests that we use the largest 
-		// of the render_strides that obey the relation.  Flexibility is achieved by 
-		// modulating 'delta_angle' until we have an acceptable number of triangles.
-	
-		old_render_stride = mVisInfo.mRenderStride;
-
-		// Calculate the render_stride using information in agent
-		max_render_stride = lltrunc(mVisInfo.mDistance * stride_per_distance);
-		max_render_stride = llmin(max_render_stride , 2*grids_per_patch_edge);
-
-		// We only use render_strides that are powers of two, so we use look-up tables to figure out
-		// the render_level and corresponding render_stride
-		new_render_level = mVisInfo.mRenderLevel = mSurfacep->getRenderLevel(max_render_stride);
-		mVisInfo.mRenderStride = mSurfacep->getRenderStride(new_render_level);
-
-		if ((mVisInfo.mRenderStride != old_render_stride)) 
-			// The reason we check !mbIsVisible is because non-visible patches normals 
-			// are not updated when their data is changed.  When this changes we can get 
-			// rid of mbIsVisible altogether.
-		{
-			if (mVObjp)
-			{
-				mVObjp->dirtyGeom();
-				LLSurfacePatch* neighbor = getNeighborPatch(WEST);
-				if (neighbor && neighbor->mVObjp.notNull())
-				{
-					neighbor->mVObjp->dirtyGeom();
-				}
-				neighbor = getNeighborPatch(SOUTH);
-				if (neighbor && neighbor->mVObjp.notNull())
-				{
-					neighbor->mVObjp->dirtyGeom();
-				}
-			}
-		}
-		mVisInfo.mbIsVisible = TRUE;
-	}
-	else
-	{
-		mVisInfo.mbIsVisible = FALSE;
-	}
+    if (mVObjp.isNull())
+    {
+        return;
+    }
+
+    const F32 DEFAULT_DELTA_ANGLE   = (0.15f);
+    U32 old_render_stride, max_render_stride;
+    U32 new_render_level;
+    F32 stride_per_distance = DEFAULT_DELTA_ANGLE / mSurfacep->getMetersPerGrid();
+    U32 grids_per_patch_edge = mSurfacep->getGridsPerPatchEdge();
+
+    LLVector4a center;
+    center.load3( (mCenterRegion + mSurfacep->getOriginAgent()).mV);
+    LLVector4a radius;
+    radius.splat(mRadius);
+
+    // sphere in frustum on global coordinates
+    if (LLViewerCamera::getInstance()->AABBInFrustumNoFarClip(center, radius))
+    {
+        // We now need to calculate the render stride based on patchp's distance
+        // from LLCamera render_stride is governed by a relation something like this...
+        //
+        //                       delta_angle * patch.distance
+        // render_stride <=  ----------------------------------------
+        //                           mMetersPerGrid
+        //
+        // where 'delta_angle' is the desired solid angle of the average polgon on a patch.
+        //
+        // Any render_stride smaller than the RHS would be 'satisfactory'.  Smaller
+        // strides give more resolution, but efficiency suggests that we use the largest
+        // of the render_strides that obey the relation.  Flexibility is achieved by
+        // modulating 'delta_angle' until we have an acceptable number of triangles.
+
+        old_render_stride = mVisInfo.mRenderStride;
+
+        // Calculate the render_stride using information in agent
+        max_render_stride = lltrunc(mVisInfo.mDistance * stride_per_distance);
+        max_render_stride = llmin(max_render_stride , 2*grids_per_patch_edge);
+
+        // We only use render_strides that are powers of two, so we use look-up tables to figure out
+        // the render_level and corresponding render_stride
+        new_render_level = mVisInfo.mRenderLevel = mSurfacep->getRenderLevel(max_render_stride);
+        mVisInfo.mRenderStride = mSurfacep->getRenderStride(new_render_level);
+
+        if ((mVisInfo.mRenderStride != old_render_stride))
+            // The reason we check !mbIsVisible is because non-visible patches normals
+            // are not updated when their data is changed.  When this changes we can get
+            // rid of mbIsVisible altogether.
+        {
+            if (mVObjp)
+            {
+                mVObjp->dirtyGeom();
+                LLSurfacePatch* neighbor = getNeighborPatch(WEST);
+                if (neighbor && neighbor->mVObjp.notNull())
+                {
+                    neighbor->mVObjp->dirtyGeom();
+                }
+                neighbor = getNeighborPatch(SOUTH);
+                if (neighbor && neighbor->mVObjp.notNull())
+                {
+                    neighbor->mVObjp->dirtyGeom();
+                }
+            }
+        }
+        mVisInfo.mbIsVisible = TRUE;
+    }
+    else
+    {
+        mVisInfo.mbIsVisible = FALSE;
+    }
 }
 
 
 const LLVector3d &LLSurfacePatch::getOriginGlobal() const
 {
-	return mOriginGlobal;
+    return mOriginGlobal;
 }
 
 LLVector3 LLSurfacePatch::getOriginAgent() const
 {
-	return gAgent.getPosAgentFromGlobal(mOriginGlobal);
+    return gAgent.getPosAgentFromGlobal(mOriginGlobal);
 }
 
 BOOL LLSurfacePatch::getVisible() const
 {
-	return mVisInfo.mbIsVisible;
+    return mVisInfo.mbIsVisible;
 }
 
 U32 LLSurfacePatch::getRenderStride() const
 {
-	return mVisInfo.mRenderStride;
+    return mVisInfo.mRenderStride;
 }
 
 S32 LLSurfacePatch::getRenderLevel() const
 {
-	return mVisInfo.mRenderLevel;
+    return mVisInfo.mRenderLevel;
 }
 
 void LLSurfacePatch::setHasReceivedData()
 {
-	mHasReceivedData = TRUE;
+    mHasReceivedData = TRUE;
 }
 
 BOOL LLSurfacePatch::getHasReceivedData() const
 {
-	return mHasReceivedData;
+    return mHasReceivedData;
 }
 
 const LLVector3 &LLSurfacePatch::getCenterRegion() const
 {
-	return mCenterRegion;
+    return mCenterRegion;
 }
 
 
 void LLSurfacePatch::updateCompositionStats()
 {
-	LLViewerLayer *vlp = mSurfacep->getRegion()->getComposition();
-
-	F32 x, y, width, height, mpg, min, mean, max;
-
-	LLVector3 origin = getOriginAgent() - mSurfacep->getOriginAgent();
-	mpg = mSurfacep->getMetersPerGrid();
-	x = origin.mV[VX];
-	y = origin.mV[VY];
-	width = mpg*(mSurfacep->getGridsPerPatchEdge()+1);
-	height = mpg*(mSurfacep->getGridsPerPatchEdge()+1);
-
-	mean = 0.f;
-	min = vlp->getValueScaled(x, y);
-	max= min;
-	U32 count = 0;
-	F32 i, j;
-	for (j = 0; j < height; j += mpg)
-	{
-		for (i = 0; i < width; i += mpg)
-		{
-			F32 comp = vlp->getValueScaled(x + i, y + j);
-			mean += comp;
-			min = llmin(min, comp);
-			max = llmax(max, comp);
-			count++;
-		}
-	}
-	mean /= count;
-
-	mMinComposition = min;
-	mMeanComposition = mean;
-	mMaxComposition = max;
+    LLViewerLayer *vlp = mSurfacep->getRegion()->getComposition();
+
+    F32 x, y, width, height, mpg, min, mean, max;
+
+    LLVector3 origin = getOriginAgent() - mSurfacep->getOriginAgent();
+    mpg = mSurfacep->getMetersPerGrid();
+    x = origin.mV[VX];
+    y = origin.mV[VY];
+    width = mpg*(mSurfacep->getGridsPerPatchEdge()+1);
+    height = mpg*(mSurfacep->getGridsPerPatchEdge()+1);
+
+    mean = 0.f;
+    min = vlp->getValueScaled(x, y);
+    max= min;
+    U32 count = 0;
+    F32 i, j;
+    for (j = 0; j < height; j += mpg)
+    {
+        for (i = 0; i < width; i += mpg)
+        {
+            F32 comp = vlp->getValueScaled(x + i, y + j);
+            mean += comp;
+            min = llmin(min, comp);
+            max = llmax(max, comp);
+            count++;
+        }
+    }
+    mean /= count;
+
+    mMinComposition = min;
+    mMeanComposition = mean;
+    mMaxComposition = max;
 }
 
 F32 LLSurfacePatch::getMeanComposition() const
 {
-	return mMeanComposition;
+    return mMeanComposition;
 }
 
 F32 LLSurfacePatch::getMinComposition() const
 {
-	return mMinComposition;
+    return mMinComposition;
 }
 
 F32 LLSurfacePatch::getMaxComposition() const
 {
-	return mMaxComposition;
+    return mMaxComposition;
 }
 
 void LLSurfacePatch::setNeighborPatch(const U32 direction, LLSurfacePatch *neighborp)
 {
-	mNeighborPatches[direction] = neighborp;
-	mNormalsInvalid[direction] = TRUE;
-	if (direction < 4)
-	{
-		mNormalsInvalid[gDirAdjacent[direction][0]] = TRUE;
-		mNormalsInvalid[gDirAdjacent[direction][1]] = TRUE;
-	}
+    mNeighborPatches[direction] = neighborp;
+    mNormalsInvalid[direction] = TRUE;
+    if (direction < 4)
+    {
+        mNormalsInvalid[gDirAdjacent[direction][0]] = TRUE;
+        mNormalsInvalid[gDirAdjacent[direction][1]] = TRUE;
+    }
 }
 
 LLSurfacePatch *LLSurfacePatch::getNeighborPatch(const U32 direction) const
 {
-	return mNeighborPatches[direction];
+    return mNeighborPatches[direction];
 }
 
 void LLSurfacePatch::clearVObj()
 {
-	mVObjp = NULL;
+    mVObjp = NULL;
 }
diff --git a/indra/newview/llsurfacepatch.h b/indra/newview/llsurfacepatch.h
index 3d57e9c33114f952f66fa1a30098702263b52f95..4e69c5b88df1e524341c223c1a1ef7f93b193abb 100644
--- a/indra/newview/llsurfacepatch.h
+++ b/indra/newview/llsurfacepatch.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llsurfacepatch.h
  * @brief LLSurfacePatch class definition
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -37,71 +37,71 @@ class LLVector2;
 class LLColor4U;
 class LLAgent;
 
-// A patch shouldn't know about its visibility since that really depends on the 
+// A patch shouldn't know about its visibility since that really depends on the
 // camera that is looking (or not looking) at it.  So, anything about a patch
 // that is specific to a camera should be in the class below.
 class LLPatchVisibilityInfo
 {
 public:
-	LLPatchVisibilityInfo() :
-		mbIsVisible(FALSE),
-		mDistance(0.f),
-		mRenderLevel(0),
-		mRenderStride(0) { };
-	~LLPatchVisibilityInfo() = default;
-
-	BOOL mbIsVisible;
-	F32 mDistance;			// Distance from camera
-	S32 mRenderLevel;
-	U32 mRenderStride;
+    LLPatchVisibilityInfo() :
+        mbIsVisible(FALSE),
+        mDistance(0.f),
+        mRenderLevel(0),
+        mRenderStride(0) { };
+    ~LLPatchVisibilityInfo() = default;
+
+    BOOL mbIsVisible;
+    F32 mDistance;          // Distance from camera
+    S32 mRenderLevel;
+    U32 mRenderStride;
 };
 
 
 
-class LLSurfacePatch 
+class LLSurfacePatch
 {
 public:
-	LLSurfacePatch();
-	~LLSurfacePatch();
+    LLSurfacePatch();
+    ~LLSurfacePatch();
 
-	void reset(const U32 id);
-	void connectNeighbor(LLSurfacePatch *neighborp, const U32 direction);
-	void disconnectNeighbor(LLSurface *surfacep);
+    void reset(const U32 id);
+    void connectNeighbor(LLSurfacePatch *neighborp, const U32 direction);
+    void disconnectNeighbor(LLSurface *surfacep);
 
-	void setNeighborPatch(const U32 direction, LLSurfacePatch *neighborp);
-	LLSurfacePatch *getNeighborPatch(const U32 direction) const;
+    void setNeighborPatch(const U32 direction, LLSurfacePatch *neighborp);
+    LLSurfacePatch *getNeighborPatch(const U32 direction) const;
 
-	void colorPatch(const U8 r, const U8 g, const U8 b);
+    void colorPatch(const U8 r, const U8 g, const U8 b);
 
-	BOOL updateTexture();
+    BOOL updateTexture();
 
-	void updateVerticalStats();
-	void updateCompositionStats();
+    void updateVerticalStats();
+    void updateCompositionStats();
     template<bool PBR>
-	void updateNormals();
-
-	void updateEastEdge();
-	void updateNorthEdge();
-
-	void updateCameraDistanceRegion( const LLVector3 &pos_region);
-	void updateVisibility();
-	void updateGL();
-
-	void dirtyZ(); // Dirty the z values of this patch
-	void setHasReceivedData();
-	BOOL getHasReceivedData() const;
-
-	F32 getDistance() const;
-	F32 getMaxZ() const;
-	F32 getMinZ() const;
-	F32 getMeanComposition() const;
-	F32 getMinComposition() const;
-	F32 getMaxComposition() const;
-	const LLVector3 &getCenterRegion() const;
-	const U64 &getLastUpdateTime() const;
-	LLSurface *getSurface() const { return mSurfacep; }
-	LLVector3 getPointAgent(const U32 x, const U32 y) const; // get the point at the offset.
-	LLVector2 getTexCoords(const U32 x, const U32 y) const;
+    void updateNormals();
+
+    void updateEastEdge();
+    void updateNorthEdge();
+
+    void updateCameraDistanceRegion( const LLVector3 &pos_region);
+    void updateVisibility();
+    void updateGL();
+
+    void dirtyZ(); // Dirty the z values of this patch
+    void setHasReceivedData();
+    BOOL getHasReceivedData() const;
+
+    F32 getDistance() const;
+    F32 getMaxZ() const;
+    F32 getMinZ() const;
+    F32 getMeanComposition() const;
+    F32 getMinComposition() const;
+    F32 getMaxComposition() const;
+    const LLVector3 &getCenterRegion() const;
+    const U64 &getLastUpdateTime() const;
+    LLSurface *getSurface() const { return mSurfacep; }
+    LLVector3 getPointAgent(const U32 x, const U32 y) const; // get the point at the offset.
+    LLVector2 getTexCoords(const U32 x, const U32 y) const;
 
     // Per-vertex normals
     // *TODO: PBR=true is a test implementation solely for proof-of-concept.
@@ -109,86 +109,86 @@ class LLSurfacePatch
     // this function. If we decide to keep calcNormalFlat, remove index as it
     // is a debug parameter for testing.
     template<bool PBR>
-	void calcNormal(const U32 x, const U32 y, const U32 stride);
-	const LLVector3 &getNormal(const U32 x, const U32 y) const;
+    void calcNormal(const U32 x, const U32 y, const U32 stride);
+    const LLVector3 &getNormal(const U32 x, const U32 y) const;
 
     // Per-triangle normals for flat edges
-	void calcNormalFlat(LLVector3& normal_out, const U32 x, const U32 y, const U32 index /* 0 or 1 */);
+    void calcNormalFlat(LLVector3& normal_out, const U32 x, const U32 y, const U32 index /* 0 or 1 */);
+
+    void eval(const U32 x, const U32 y, const U32 stride,
+                LLVector3 *vertex, LLVector3 *normal, LLVector2 *tex0, LLVector2 *tex1);
+
+
 
-	void eval(const U32 x, const U32 y, const U32 stride,
-				LLVector3 *vertex, LLVector3 *normal, LLVector2 *tex0, LLVector2 *tex1);
-	
-	
+    LLVector3 getOriginAgent() const;
+    const LLVector3d &getOriginGlobal() const;
+    void setOriginGlobal(const LLVector3d &origin_global);
 
-	LLVector3 getOriginAgent() const;
-	const LLVector3d &getOriginGlobal() const;
-	void setOriginGlobal(const LLVector3d &origin_global);
-	
-	// connectivity -- each LLPatch points at 5 neighbors (or NULL)
-	// +---+---+---+
-	// |   | 2 | 5 |
-	// +---+---+---+
-	// | 3 | 0 | 1 |
-	// +---+---+---+
-	// | 6 | 4 |   |
-	// +---+---+---+
+    // connectivity -- each LLPatch points at 5 neighbors (or NULL)
+    // +---+---+---+
+    // |   | 2 | 5 |
+    // +---+---+---+
+    // | 3 | 0 | 1 |
+    // +---+---+---+
+    // | 6 | 4 |   |
+    // +---+---+---+
 
 
-	BOOL getVisible() const;
-	U32 getRenderStride() const;
-	S32 getRenderLevel() const;
+    BOOL getVisible() const;
+    U32 getRenderStride() const;
+    S32 getRenderLevel() const;
 
-	void setSurface(LLSurface *surfacep);
-	void setDataZ(F32 *data_z)					{ mDataZ = data_z; }
-	void setDataNorm(LLVector3 *data_norm)		{ mDataNorm = data_norm; }
-	F32 *getDataZ() const						{ return mDataZ; }
+    void setSurface(LLSurface *surfacep);
+    void setDataZ(F32 *data_z)                  { mDataZ = data_z; }
+    void setDataNorm(LLVector3 *data_norm)      { mDataNorm = data_norm; }
+    F32 *getDataZ() const                       { return mDataZ; }
 
-	void dirty();			// Mark this surface patch as dirty...
-	void clearDirty()							{ mDirty = FALSE; }
+    void dirty();           // Mark this surface patch as dirty...
+    void clearDirty()                           { mDirty = FALSE; }
 
-	void clearVObj();
+    void clearVObj();
 
 public:
-	BOOL mHasReceivedData;	// has the patch EVER received height data?
-	BOOL mSTexUpdate;		// Does the surface texture need to be updated?
+    BOOL mHasReceivedData;  // has the patch EVER received height data?
+    BOOL mSTexUpdate;       // Does the surface texture need to be updated?
 
 protected:
-	LLSurfacePatch *mNeighborPatches[8]; // Adjacent patches
-	BOOL mNormalsInvalid[9];  // Which normals are invalid
+    LLSurfacePatch *mNeighborPatches[8]; // Adjacent patches
+    BOOL mNormalsInvalid[9];  // Which normals are invalid
 
-	BOOL mDirty;
-	BOOL mDirtyZStats;
-	BOOL mHeightsGenerated;
+    BOOL mDirty;
+    BOOL mDirtyZStats;
+    BOOL mHeightsGenerated;
 
-	U32 mDataOffset;
-	F32 *mDataZ;
-	LLVector3 *mDataNorm;
+    U32 mDataOffset;
+    F32 *mDataZ;
+    LLVector3 *mDataNorm;
 
-	// Pointer to the LLVOSurfacePatch object which is used in the new renderer.
-	LLPointer<LLVOSurfacePatch> mVObjp;
+    // Pointer to the LLVOSurfacePatch object which is used in the new renderer.
+    LLPointer<LLVOSurfacePatch> mVObjp;
 
-	// All of the camera-dependent stuff should be in its own class...
-	LLPatchVisibilityInfo mVisInfo;
+    // All of the camera-dependent stuff should be in its own class...
+    LLPatchVisibilityInfo mVisInfo;
 
-	// pointers to beginnings of patch data fields
-	LLVector3d mOriginGlobal;
-	LLVector3 mOriginRegion;
+    // pointers to beginnings of patch data fields
+    LLVector3d mOriginGlobal;
+    LLVector3 mOriginRegion;
 
 
-	// height field stats
-	LLVector3 mCenterRegion; // Center in region-local coords
-	F32 mMinZ, mMaxZ, mMeanZ;
-	F32 mRadius;
+    // height field stats
+    LLVector3 mCenterRegion; // Center in region-local coords
+    F32 mMinZ, mMaxZ, mMeanZ;
+    F32 mRadius;
 
-	F32 mMinComposition;
-	F32 mMaxComposition;
-	F32 mMeanComposition;
+    F32 mMinComposition;
+    F32 mMaxComposition;
+    F32 mMeanComposition;
 
-	U8 mConnectedEdge;		// This flag is non-zero iff patch is on at least one edge 
-							// of LLSurface that is "connected" to another LLSurface
-	U64 mLastUpdateTime;	// Time patch was last updated
+    U8 mConnectedEdge;      // This flag is non-zero iff patch is on at least one edge
+                            // of LLSurface that is "connected" to another LLSurface
+    U64 mLastUpdateTime;    // Time patch was last updated
 
-	LLSurface *mSurfacep; // Pointer to "parent" surface
+    LLSurface *mSurfacep; // Pointer to "parent" surface
 };
 
 extern template void LLSurfacePatch::updateNormals</*PBR=*/false>();
diff --git a/indra/newview/lltexturectrl.cpp b/indra/newview/lltexturectrl.cpp
index cff9f8608d1ae29d1300025c46c29d77e57df2d4..7b3176ae505847d12dd61d5cca05c4fdd434c40a 100644
--- a/indra/newview/lltexturectrl.cpp
+++ b/indra/newview/lltexturectrl.cpp
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file lltexturectrl.cpp
  * @author Richard Nelson, James Cook
  * @brief LLTextureCtrl class implementation including related functions
@@ -6,21 +6,21 @@
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -46,7 +46,7 @@
 #include "llmaterialeditor.h"
 #include "llui.h"
 #include "llviewerinventory.h"
-#include "llviewermenufile.h"	// LLFilePickerReplyThread
+#include "llviewermenufile.h"   // LLFilePickerReplyThread
 #include "llpermissions.h"
 #include "llpreviewtexture.h"
 #include "llassetstorage.h"
@@ -78,7 +78,7 @@ bool get_is_predefined_texture(LLUUID asset_id)
         || asset_id == DEFAULT_OBJECT_NORMAL
         || asset_id == BLANK_OBJECT_NORMAL
         || asset_id == IMG_WHITE
-		|| asset_id == IMG_INVISIBLE
+        || asset_id == IMG_INVISIBLE
         || asset_id == LLUUID(SCULPT_DEFAULT_TEXTURE))
     {
         return true;
@@ -96,7 +96,7 @@ LLUUID get_copy_free_item_by_asset_id(LLUUID asset_id, bool no_trans_perm)
         items,
         LLInventoryModel::INCLUDE_TRASH,
         asset_id_matches);
-    
+
     LLUUID res;
     if (items.size())
     {
@@ -134,56 +134,56 @@ bool get_can_copy_texture(LLUUID asset_id)
 
 S32 LLFloaterTexturePicker::sLastPickerMode = 0;
 
-LLFloaterTexturePicker::LLFloaterTexturePicker(	
-	LLView* owner,
-	LLUUID image_asset_id,
-	LLUUID default_image_asset_id,
-	LLUUID transparent_image_asset_id,
-	LLUUID blank_image_asset_id,
-	BOOL tentative,
-	BOOL allow_no_texture,
-	const std::string& label,
-	PermissionMask immediate_filter_perm_mask,
-	PermissionMask dnd_filter_perm_mask,
-	BOOL can_apply_immediately,
-	LLUIImagePtr fallback_image,
+LLFloaterTexturePicker::LLFloaterTexturePicker(
+    LLView* owner,
+    LLUUID image_asset_id,
+    LLUUID default_image_asset_id,
+    LLUUID transparent_image_asset_id,
+    LLUUID blank_image_asset_id,
+    BOOL tentative,
+    BOOL allow_no_texture,
+    const std::string& label,
+    PermissionMask immediate_filter_perm_mask,
+    PermissionMask dnd_filter_perm_mask,
+    BOOL can_apply_immediately,
+    LLUIImagePtr fallback_image,
     EPickInventoryType pick_type)
-:	LLFloater(LLSD()),
-	mOwner( owner ),
-	mImageAssetID( image_asset_id ),
-	mOriginalImageAssetID(image_asset_id),
-	mFallbackImage(fallback_image),
-	mDefaultImageAssetID(default_image_asset_id),
-	mTransparentImageAssetID(transparent_image_asset_id),
-	mBlankImageAssetID(blank_image_asset_id),
-	mTentative(tentative),
-	mAllowNoTexture(allow_no_texture),
-	mLabel(label),
-	mTentativeLabel(NULL),
-	mResolutionLabel(NULL),
-	mActive( TRUE ),
-	mFilterEdit(NULL),
-	mImmediateFilterPermMask(immediate_filter_perm_mask),
-	mDnDFilterPermMask(dnd_filter_perm_mask),
-	mContextConeOpacity(0.f),
-	mSelectedItemPinned( FALSE ),
-	mCanApply(true),
-	mCanPreview(true),
+:   LLFloater(LLSD()),
+    mOwner( owner ),
+    mImageAssetID( image_asset_id ),
+    mOriginalImageAssetID(image_asset_id),
+    mFallbackImage(fallback_image),
+    mDefaultImageAssetID(default_image_asset_id),
+    mTransparentImageAssetID(transparent_image_asset_id),
+    mBlankImageAssetID(blank_image_asset_id),
+    mTentative(tentative),
+    mAllowNoTexture(allow_no_texture),
+    mLabel(label),
+    mTentativeLabel(NULL),
+    mResolutionLabel(NULL),
+    mActive( TRUE ),
+    mFilterEdit(NULL),
+    mImmediateFilterPermMask(immediate_filter_perm_mask),
+    mDnDFilterPermMask(dnd_filter_perm_mask),
+    mContextConeOpacity(0.f),
+    mSelectedItemPinned( FALSE ),
+    mCanApply(true),
+    mCanPreview(true),
     mLimitsSet(false),
     mMaxDim(S32_MAX),
     mMinDim(0),
-	mPreviewSettingChanged(false),
-	mOnFloaterCommitCallback(NULL),
-	mOnFloaterCloseCallback(NULL),
-	mSetImageAssetIDCallback(NULL),
-	mOnUpdateImageStatsCallback(NULL),
-	mBakeTextureEnabled(FALSE),
+    mPreviewSettingChanged(false),
+    mOnFloaterCommitCallback(NULL),
+    mOnFloaterCloseCallback(NULL),
+    mSetImageAssetIDCallback(NULL),
+    mOnUpdateImageStatsCallback(NULL),
+    mBakeTextureEnabled(FALSE),
     mInventoryPickType(pick_type)
 {
-	mCanApplyImmediately = can_apply_immediately;
-	buildFromFile("floater_texture_ctrl.xml");
-	setCanMinimize(FALSE);
-	setCanCollapse(FALSE);
+    mCanApplyImmediately = can_apply_immediately;
+    buildFromFile("floater_texture_ctrl.xml");
+    setCanMinimize(FALSE);
+    setCanCollapse(FALSE);
 }
 
 LLFloaterTexturePicker::~LLFloaterTexturePicker()
@@ -192,27 +192,27 @@ LLFloaterTexturePicker::~LLFloaterTexturePicker()
 
 void LLFloaterTexturePicker::setImageID(const LLUUID& image_id, bool set_selection /*=true*/)
 {
-	if( ((mImageAssetID != image_id) || mTentative) && mActive)
-	{
-		mNoCopyTextureSelected = FALSE;
-		mViewModel->setDirty(); // *TODO: shouldn't we be using setValue() here?
-		mImageAssetID = image_id; 
-
-		if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
-		{
-			if ( mBakeTextureEnabled && mModeSelector->getValue().asInteger() != 2)
-			{
-				mModeSelector->selectByValue(2);
-				onModeSelect(0,this);
-			}
-		}
-		else
-		{
-			if (mModeSelector->getValue().asInteger() == 2)
-			{
-				mModeSelector->selectByValue(0);
-				onModeSelect(0,this);
-			}
+    if( ((mImageAssetID != image_id) || mTentative) && mActive)
+    {
+        mNoCopyTextureSelected = FALSE;
+        mViewModel->setDirty(); // *TODO: shouldn't we be using setValue() here?
+        mImageAssetID = image_id;
+
+        if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
+        {
+            if ( mBakeTextureEnabled && mModeSelector->getValue().asInteger() != 2)
+            {
+                mModeSelector->selectByValue(2);
+                onModeSelect(0,this);
+            }
+        }
+        else
+        {
+            if (mModeSelector->getValue().asInteger() == 2)
+            {
+                mModeSelector->selectByValue(0);
+                onModeSelect(0,this);
+            }
 
             LLUUID item_id;
             LLFolderView* root_folder = mInventoryPanel->getRootFolder();
@@ -238,27 +238,27 @@ void LLFloaterTexturePicker::setImageID(const LLUUID& image_id, bool set_selecti
             {
                 item_id = findItemID(mImageAssetID, FALSE);
             }
-			if (item_id.isNull())
-			{
-				mInventoryPanel->getRootFolder()->clearSelection();
-			}
-			else
-			{
-				LLInventoryItem* itemp = gInventory.getItem(item_id);
-				if (itemp && !itemp->getPermissions().allowCopyBy(gAgent.getID()))
-				{
-					// no copy texture
-					getChild<LLUICtrl>("apply_immediate_check")->setValue(FALSE);
-					mNoCopyTextureSelected = TRUE;
-				}
-			}
-
-			if (set_selection)
-			{
-				mInventoryPanel->setSelection(item_id, TAKE_FOCUS_NO);
-			}
-		}
-	}
+            if (item_id.isNull())
+            {
+                mInventoryPanel->getRootFolder()->clearSelection();
+            }
+            else
+            {
+                LLInventoryItem* itemp = gInventory.getItem(item_id);
+                if (itemp && !itemp->getPermissions().allowCopyBy(gAgent.getID()))
+                {
+                    // no copy texture
+                    getChild<LLUICtrl>("apply_immediate_check")->setValue(FALSE);
+                    mNoCopyTextureSelected = TRUE;
+                }
+            }
+
+            if (set_selection)
+            {
+                mInventoryPanel->setSelection(item_id, TAKE_FOCUS_NO);
+            }
+        }
+    }
 }
 
 void LLFloaterTexturePicker::setImageIDFromItem(const LLInventoryItem* itemp, bool set_selection)
@@ -272,18 +272,18 @@ void LLFloaterTexturePicker::setImageIDFromItem(const LLInventoryItem* itemp, bo
     setImageID(asset_id, set_selection);
 }
 
-void LLFloaterTexturePicker::setActive( BOOL active )					
+void LLFloaterTexturePicker::setActive( BOOL active )
 {
-	if (!active && getChild<LLUICtrl>("Pipette")->getValue().asBoolean())
-	{
-		stopUsingPipette();
-	}
-	mActive = active; 
+    if (!active && getChild<LLUICtrl>("Pipette")->getValue().asBoolean())
+    {
+        stopUsingPipette();
+    }
+    mActive = active;
 }
 
 void LLFloaterTexturePicker::setCanApplyImmediately(BOOL b)
 {
-	mCanApplyImmediately = b;
+    mCanApplyImmediately = b;
 
     LLUICtrl *apply_checkbox = getChild<LLUICtrl>("apply_immediate_check");
     apply_checkbox->setValue(mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview"));
@@ -292,10 +292,10 @@ void LLFloaterTexturePicker::setCanApplyImmediately(BOOL b)
 
 void LLFloaterTexturePicker::stopUsingPipette()
 {
-	if (LLToolMgr::getInstance()->getCurrentTool() == LLToolPipette::getInstance())
-	{
-		LLToolMgr::getInstance()->clearTransientTool();
-	}
+    if (LLToolMgr::getInstance()->getCurrentTool() == LLToolPipette::getInstance())
+    {
+        LLToolMgr::getInstance()->clearTransientTool();
+    }
 }
 
 bool LLFloaterTexturePicker::updateImageStats()
@@ -353,13 +353,13 @@ bool LLFloaterTexturePicker::updateImageStats()
             mResolutionLabel->setTextArg("[DIMENSIONS]", std::string(""));
         }
     }
-	else if (mTexturep.notNull())
-	{
-		//RN: have we received header data for this image?
+    else if (mTexturep.notNull())
+    {
+        //RN: have we received header data for this image?
         S32 width = mTexturep->getFullWidth();
         S32 height = mTexturep->getFullHeight();
-		if (width > 0 && height > 0)
-		{
+        if (width > 0 && height > 0)
+        {
             if ((mLimitsSet && (width != height))
                 || width < mMinDim
                 || width > mMaxDim
@@ -381,16 +381,16 @@ bool LLFloaterTexturePicker::updateImageStats()
             {
                 mOnUpdateImageStatsCallback(mTexturep);
             }
-		}
-		else
-		{
-			mResolutionLabel->setTextArg("[DIMENSIONS]", std::string("[? x ?]"));
-		}
-	}
-	else
-	{
-		mResolutionLabel->setTextArg("[DIMENSIONS]", std::string(""));
-	}
+        }
+        else
+        {
+            mResolutionLabel->setTextArg("[DIMENSIONS]", std::string("[? x ?]"));
+        }
+    }
+    else
+    {
+        mResolutionLabel->setTextArg("[DIMENSIONS]", std::string(""));
+    }
     mResolutionLabel->setVisible(result);
     mResolutionWarning->setVisible(!result);
 
@@ -409,16 +409,16 @@ bool LLFloaterTexturePicker::updateImageStats()
 }
 
 // virtual
-BOOL LLFloaterTexturePicker::handleDragAndDrop( 
-		S32 x, S32 y, MASK mask,
-		BOOL drop,
-		EDragAndDropType cargo_type, void *cargo_data, 
-		EAcceptance *accept,
-		std::string& tooltip_msg)
+BOOL LLFloaterTexturePicker::handleDragAndDrop(
+        S32 x, S32 y, MASK mask,
+        BOOL drop,
+        EDragAndDropType cargo_type, void *cargo_data,
+        EAcceptance *accept,
+        std::string& tooltip_msg)
 {
-	BOOL handled = FALSE;
+    BOOL handled = FALSE;
 
-	bool is_mesh = cargo_type == DAD_MESH;
+    bool is_mesh = cargo_type == DAD_MESH;
     bool is_texture = cargo_type == DAD_TEXTURE;
     bool is_material = cargo_type == DAD_MATERIAL;
 
@@ -436,83 +436,83 @@ BOOL LLFloaterTexturePicker::handleDragAndDrop(
         allow_dnd = is_texture || is_mesh || is_material;
     }
 
-	if (allow_dnd)
-	{
-		LLInventoryItem *item = (LLInventoryItem *)cargo_data;
-
-		BOOL copy = item->getPermissions().allowCopyBy(gAgent.getID());
-		BOOL mod = item->getPermissions().allowModifyBy(gAgent.getID());
-		BOOL xfer = item->getPermissions().allowOperationBy(PERM_TRANSFER,
-															gAgent.getID());
-
-		PermissionMask item_perm_mask = 0;
-		if (copy) item_perm_mask |= PERM_COPY;
-		if (mod)  item_perm_mask |= PERM_MODIFY;
-		if (xfer) item_perm_mask |= PERM_TRANSFER;
-		
-		PermissionMask filter_perm_mask = mDnDFilterPermMask;
-		if ( (item_perm_mask & filter_perm_mask) == filter_perm_mask )
-		{
-			if (drop)
-			{
+    if (allow_dnd)
+    {
+        LLInventoryItem *item = (LLInventoryItem *)cargo_data;
+
+        BOOL copy = item->getPermissions().allowCopyBy(gAgent.getID());
+        BOOL mod = item->getPermissions().allowModifyBy(gAgent.getID());
+        BOOL xfer = item->getPermissions().allowOperationBy(PERM_TRANSFER,
+                                                            gAgent.getID());
+
+        PermissionMask item_perm_mask = 0;
+        if (copy) item_perm_mask |= PERM_COPY;
+        if (mod)  item_perm_mask |= PERM_MODIFY;
+        if (xfer) item_perm_mask |= PERM_TRANSFER;
+
+        PermissionMask filter_perm_mask = mDnDFilterPermMask;
+        if ( (item_perm_mask & filter_perm_mask) == filter_perm_mask )
+        {
+            if (drop)
+            {
                 setImageIDFromItem(item);
-				commitIfImmediateSet();
-			}
+                commitIfImmediateSet();
+            }
 
-			*accept = ACCEPT_YES_SINGLE;
-		}
-		else
-		{
-			*accept = ACCEPT_NO;
-		}
-	}
-	else
-	{
-		*accept = ACCEPT_NO;
-	}
+            *accept = ACCEPT_YES_SINGLE;
+        }
+        else
+        {
+            *accept = ACCEPT_NO;
+        }
+    }
+    else
+    {
+        *accept = ACCEPT_NO;
+    }
 
-	handled = TRUE;
-	LL_DEBUGS("UserInput") << "dragAndDrop handled by LLFloaterTexturePicker " << getName() << LL_ENDL;
+    handled = TRUE;
+    LL_DEBUGS("UserInput") << "dragAndDrop handled by LLFloaterTexturePicker " << getName() << LL_ENDL;
 
-	return handled;
+    return handled;
 }
 
 BOOL LLFloaterTexturePicker::handleKeyHere(KEY key, MASK mask)
 {
-	LLFolderView* root_folder = mInventoryPanel->getRootFolder();
-
-	if (root_folder && mFilterEdit)
-	{
-		if (mFilterEdit->hasFocus() 
-			&& (key == KEY_RETURN || key == KEY_DOWN) 
-			&& mask == MASK_NONE)
-		{
-			if (!root_folder->getCurSelectedItem())
-			{
-				LLFolderViewItem* itemp =    mInventoryPanel->getItemByID(gInventory.getRootFolderID());
-				if (itemp)
-				{
-					root_folder->setSelection(itemp, FALSE, FALSE);
-				}
-			}
-			root_folder->scrollToShowSelection();
-			
-			// move focus to inventory proper
-			mInventoryPanel->setFocus(TRUE);
-			
-			// treat this as a user selection of the first filtered result
-			commitIfImmediateSet();
-			
-			return TRUE;
-		}
-		
-		if (mInventoryPanel->hasFocus() && key == KEY_UP)
-		{
-			mFilterEdit->focusFirstItem(TRUE);
-		}
-	}
-
-	return LLFloater::handleKeyHere(key, mask);
+    LLFolderView* root_folder = mInventoryPanel->getRootFolder();
+
+    if (root_folder && mFilterEdit)
+    {
+        if (mFilterEdit->hasFocus()
+            && (key == KEY_RETURN || key == KEY_DOWN)
+            && mask == MASK_NONE)
+        {
+            if (!root_folder->getCurSelectedItem())
+            {
+                LLFolderViewItem* itemp =    mInventoryPanel->getItemByID(gInventory.getRootFolderID());
+                if (itemp)
+                {
+                    root_folder->setSelection(itemp, FALSE, FALSE);
+                }
+            }
+            root_folder->scrollToShowSelection();
+
+            // move focus to inventory proper
+            mInventoryPanel->setFocus(TRUE);
+
+            // treat this as a user selection of the first filtered result
+            commitIfImmediateSet();
+
+            return TRUE;
+        }
+
+        if (mInventoryPanel->hasFocus() && key == KEY_UP)
+        {
+            mFilterEdit->focusFirstItem(TRUE);
+        }
+    }
+
+    return LLFloater::handleKeyHere(key, mask);
 }
 
 void LLFloaterTexturePicker::onOpen(const LLSD& key)
@@ -526,11 +526,11 @@ void LLFloaterTexturePicker::onOpen(const LLSD& key)
 
 void LLFloaterTexturePicker::onClose(bool app_quitting)
 {
-	if (mOwner && mOnFloaterCloseCallback)
-	{
-		mOnFloaterCloseCallback();
-	}
-	stopUsingPipette();
+    if (mOwner && mOnFloaterCloseCallback)
+    {
+        mOnFloaterCloseCallback();
+    }
+    stopUsingPipette();
     sLastPickerMode = mModeSelector->getValue().asInteger();
     // *NOTE: Vertex buffer for sphere preview is still cached
     mGLTFPreview = nullptr;
@@ -539,32 +539,32 @@ void LLFloaterTexturePicker::onClose(bool app_quitting)
 // virtual
 BOOL LLFloaterTexturePicker::postBuild()
 {
-	LLFloater::postBuild();
-
-	if (mInventoryPickType == PICK_MATERIAL)
-	{
-		setTitle(getString("pick_material"));
-	}
-	else if (!mLabel.empty())
-	{
-		std::string pick = getString("pick title");
-
-		setTitle(pick + mLabel);
-	}
-	else
-	{
-		setTitle(getString("pick_texture"));
-	}
-	mTentativeLabel = getChild<LLTextBox>("Multiple");
-
-	mResolutionLabel = getChild<LLTextBox>("size_lbl");
+    LLFloater::postBuild();
+
+    if (mInventoryPickType == PICK_MATERIAL)
+    {
+        setTitle(getString("pick_material"));
+    }
+    else if (!mLabel.empty())
+    {
+        std::string pick = getString("pick title");
+
+        setTitle(pick + mLabel);
+    }
+    else
+    {
+        setTitle(getString("pick_texture"));
+    }
+    mTentativeLabel = getChild<LLTextBox>("Multiple");
+
+    mResolutionLabel = getChild<LLTextBox>("size_lbl");
     mResolutionWarning = getChild<LLTextBox>("over_limit_lbl");
 
 
     mDefaultBtn = getChild<LLButton>("Default");
     mNoneBtn = getChild<LLButton>("None");
     mBlankBtn = getChild<LLButton>("Blank");
-	mTransparentBtn = getChild<LLButton>("Transparent");
+    mTransparentBtn = getChild<LLButton>("Transparent");
     mPipetteBtn = getChild<LLButton>("Pipette");
     mSelectBtn = getChild<LLButton>("Select");
     mCancelBtn = getChild<LLButton>("Cancel");
@@ -580,71 +580,71 @@ BOOL LLFloaterTexturePicker::postBuild()
     mFilterEdit = getChild<LLFilterEditor>("inventory search editor");
     mFilterEdit->setCommitCallback(boost::bind(&LLFloaterTexturePicker::onFilterEdit, this, _2));
 
-	mInventoryPanel = getChild<LLInventoryPanel>("inventory panel");
+    mInventoryPanel = getChild<LLInventoryPanel>("inventory panel");
 
-	mModeSelector = getChild<LLComboBox>("mode_selection");
-	mModeSelector->setCommitCallback(onModeSelect, this);
-	mModeSelector->selectByValue(0);
+    mModeSelector = getChild<LLComboBox>("mode_selection");
+    mModeSelector->setCommitCallback(onModeSelect, this);
+    mModeSelector->selectByValue(0);
 
-	if(mInventoryPanel)
-	{
+    if(mInventoryPanel)
+    {
         // to avoid having to make an assumption about which option is
         // selected at startup, we call the same function that is triggered
         // when a texture/materials/both choice is made and let it take care
         // of setting the filters
         refreshInventoryFilter();
 
-		mInventoryPanel->setFilterPermMask(mImmediateFilterPermMask);
-		mInventoryPanel->setSelectCallback(boost::bind(&LLFloaterTexturePicker::onSelectionChange, this, _1, _2));
-		mInventoryPanel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
+        mInventoryPanel->setFilterPermMask(mImmediateFilterPermMask);
+        mInventoryPanel->setSelectCallback(boost::bind(&LLFloaterTexturePicker::onSelectionChange, this, _1, _2));
+        mInventoryPanel->setShowFolderState(LLInventoryFilter::SHOW_NON_EMPTY_FOLDERS);
 
-		// Disable auto selecting first filtered item because it takes away
-		// selection from the item set by LLTextureCtrl owning this floater.
-		mInventoryPanel->getRootFolder()->setAutoSelectOverride(TRUE);
+        // Disable auto selecting first filtered item because it takes away
+        // selection from the item set by LLTextureCtrl owning this floater.
+        mInventoryPanel->getRootFolder()->setAutoSelectOverride(TRUE);
 
-		// Commented out to scroll to currently selected texture. See EXT-5403.
-		// // store this filter as the default one
-		// mInventoryPanel->getRootFolder()->getFilter().markDefault();
+        // Commented out to scroll to currently selected texture. See EXT-5403.
+        // // store this filter as the default one
+        // mInventoryPanel->getRootFolder()->getFilter().markDefault();
 
-		// Commented out to stop opening all folders with textures
-		// mInventoryPanel->openDefaultFolderForType(LLFolderType::FT_TEXTURE);
+        // Commented out to stop opening all folders with textures
+        // mInventoryPanel->openDefaultFolderForType(LLFolderType::FT_TEXTURE);
 
-		// don't put keyboard focus on selected item, because the selection callback
-		// will assume that this was user input
+        // don't put keyboard focus on selected item, because the selection callback
+        // will assume that this was user input
 
-		if(!mImageAssetID.isNull() || mInventoryPickType == PICK_MATERIAL)
-		{
-			mInventoryPanel->setSelection(findItemID(mImageAssetID, FALSE), TAKE_FOCUS_NO);
-		}
-	}
+        if(!mImageAssetID.isNull() || mInventoryPickType == PICK_MATERIAL)
+        {
+            mInventoryPanel->setSelection(findItemID(mImageAssetID, FALSE), TAKE_FOCUS_NO);
+        }
+    }
 
-	childSetAction("l_add_btn", LLFloaterTexturePicker::onBtnAdd, this);
-	childSetAction("l_rem_btn", LLFloaterTexturePicker::onBtnRemove, this);
-	childSetAction("l_upl_btn", LLFloaterTexturePicker::onBtnUpload, this);
+    childSetAction("l_add_btn", LLFloaterTexturePicker::onBtnAdd, this);
+    childSetAction("l_rem_btn", LLFloaterTexturePicker::onBtnRemove, this);
+    childSetAction("l_upl_btn", LLFloaterTexturePicker::onBtnUpload, this);
 
-	mLocalScrollCtrl = getChild<LLScrollListCtrl>("l_name_list");
-	mLocalScrollCtrl->setCommitCallback(onLocalScrollCommit, this);
+    mLocalScrollCtrl = getChild<LLScrollListCtrl>("l_name_list");
+    mLocalScrollCtrl->setCommitCallback(onLocalScrollCommit, this);
     refreshLocalList();
 
     getChild<LLLineEditor>("uuid_editor")->setCommitCallback(boost::bind(&onApplyUUID, this));
     getChild<LLButton>("apply_uuid_btn")->setClickedCallback(boost::bind(&onApplyUUID, this));
 
-	mNoCopyTextureSelected = FALSE;
+    mNoCopyTextureSelected = FALSE;
 
-	getChild<LLUICtrl>("apply_immediate_check")->setValue(mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview"));
-	childSetCommitCallback("apply_immediate_check", onApplyImmediateCheck, this);
+    getChild<LLUICtrl>("apply_immediate_check")->setValue(mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview"));
+    childSetCommitCallback("apply_immediate_check", onApplyImmediateCheck, this);
     getChildView("apply_immediate_check")->setEnabled(mCanApplyImmediately);
 
-	getChild<LLUICtrl>("Pipette")->setCommitCallback( boost::bind(&LLFloaterTexturePicker::onBtnPipette, this));
-	childSetAction("Cancel", LLFloaterTexturePicker::onBtnCancel,this);
-	childSetAction("Select", LLFloaterTexturePicker::onBtnSelect,this);
+    getChild<LLUICtrl>("Pipette")->setCommitCallback( boost::bind(&LLFloaterTexturePicker::onBtnPipette, this));
+    childSetAction("Cancel", LLFloaterTexturePicker::onBtnCancel,this);
+    childSetAction("Select", LLFloaterTexturePicker::onBtnSelect,this);
 
-	mSavedFolderState.setApply(FALSE);
+    mSavedFolderState.setApply(FALSE);
 
-	getChild<LLComboBox>("l_bake_use_texture_combo_box")->setCommitCallback(onBakeTextureSelect, this);
+    getChild<LLComboBox>("l_bake_use_texture_combo_box")->setCommitCallback(onBakeTextureSelect, this);
 
-	setBakeTextureEnabled(TRUE);
-	return TRUE;
+    setBakeTextureEnabled(TRUE);
+    return TRUE;
 }
 
 // virtual
@@ -655,18 +655,18 @@ void LLFloaterTexturePicker::draw()
 
     // This is going to spam mOnUpdateImageStatsCallback,
     // either move elsewhere or fix to cause update once per image
-	bool valid_dims = updateImageStats();
+    bool valid_dims = updateImageStats();
 
-	// if we're inactive, gray out "apply immediate" checkbox
-	getChildView("show_folders_check")->setEnabled(mActive && mCanApplyImmediately && !mNoCopyTextureSelected);
-	mSelectBtn->setEnabled(mActive && mCanApply && valid_dims);
-	mPipetteBtn->setEnabled(mActive);
+    // if we're inactive, gray out "apply immediate" checkbox
+    getChildView("show_folders_check")->setEnabled(mActive && mCanApplyImmediately && !mNoCopyTextureSelected);
+    mSelectBtn->setEnabled(mActive && mCanApply && valid_dims);
+    mPipetteBtn->setEnabled(mActive);
     mPipetteBtn->setValue(LLToolMgr::getInstance()->getCurrentTool() == LLToolPipette::getInstance());
 
-	//BOOL allow_copy = FALSE;
-	if( mOwner ) 
-	{
-		mTexturep = NULL;
+    //BOOL allow_copy = FALSE;
+    if( mOwner )
+    {
+        mTexturep = NULL;
         LLPointer<LLFetchedGLTFMaterial> old_material = mGLTFMaterial;
         mGLTFMaterial = NULL;
         if (mImageAssetID.notNull())
@@ -705,7 +705,7 @@ void LLFloaterTexturePicker::draw()
                     if (obj)
                     {
                         LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(mImageAssetID);
-						texture = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
+                        texture = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
                     }
                 }
 
@@ -719,34 +719,34 @@ void LLFloaterTexturePicker::draw()
             }
         }
 
-		if (mTentativeLabel)
-		{
-			mTentativeLabel->setVisible( FALSE  );
-		}
+        if (mTentativeLabel)
+        {
+            mTentativeLabel->setVisible( FALSE  );
+        }
 
-		mDefaultBtn->setEnabled(mImageAssetID != mDefaultImageAssetID || mTentative);
+        mDefaultBtn->setEnabled(mImageAssetID != mDefaultImageAssetID || mTentative);
         mTransparentBtn->setEnabled((mImageAssetID != mTransparentImageAssetID && mTransparentImageAssetID.notNull()) || mTentative);
-		mBlankBtn->setEnabled((mImageAssetID != mBlankImageAssetID && mBlankImageAssetID.notNull()) || mTentative);
-		mNoneBtn->setEnabled(mAllowNoTexture && (!mImageAssetID.isNull() || mTentative));
+        mBlankBtn->setEnabled((mImageAssetID != mBlankImageAssetID && mBlankImageAssetID.notNull()) || mTentative);
+        mNoneBtn->setEnabled(mAllowNoTexture && (!mImageAssetID.isNull() || mTentative));
 
-		LLFloater::draw();
+        LLFloater::draw();
 
-		if( isMinimized() )
-		{
-			return;
-		}
+        if( isMinimized() )
+        {
+            return;
+        }
 
-		// Border
-		LLRect border = getChildView("preview_widget")->getRect();
-		gl_rect_2d( border, LLColor4::black, FALSE );
+        // Border
+        LLRect border = getChildView("preview_widget")->getRect();
+        gl_rect_2d( border, LLColor4::black, FALSE );
 
 
-		// Interior
-		LLRect interior = border;
-		interior.stretch( -1 ); 
+        // Interior
+        LLRect interior = border;
+        interior.stretch( -1 );
 
-		// If the floater is focused, don't apply its alpha to the texture (STORM-677).
-		const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
+        // If the floater is focused, don't apply its alpha to the texture (STORM-677).
+        const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
         LLViewerTexture* preview;
         if (mGLTFMaterial)
         {
@@ -757,66 +757,66 @@ void LLFloaterTexturePicker::draw()
             preview = mTexturep.get();
         }
 
-		if( preview )
-		{
+        if( preview )
+        {
             preview->addTextureStats( (F32)(interior.getWidth() * interior.getHeight()) );
-			if( preview->getComponents() == 4 )
-			{
-				gl_rect_2d_checkerboard( interior, alpha );
-			}
-
-			gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), preview, UI_VERTEX_COLOR % alpha );
-		}
-		else if (!mFallbackImage.isNull())
-		{
-			mFallbackImage->draw(interior, UI_VERTEX_COLOR % alpha);
-		}
-		else
-		{
-			gl_rect_2d( interior, LLColor4::grey % alpha, TRUE );
-
-			// Draw X
-			gl_draw_x(interior, LLColor4::black );
-		}
-
-		// Draw Tentative Label over the image
-		if( mTentative && !mViewModel->isDirty() )
-		{
-			mTentativeLabel->setVisible( TRUE );
-			drawChild(mTentativeLabel);
-		}
-
-		if (mSelectedItemPinned) return;
-
-		LLFolderView* folder_view = mInventoryPanel->getRootFolder();
-		if (!folder_view) return;
-
-		LLFolderViewFilter& filter = static_cast<LLFolderViewModelInventory*>(folder_view->getFolderViewModel())->getFilter();
-
-		bool is_filter_active = folder_view->getViewModelItem()->getLastFilterGeneration() < filter.getCurrentGeneration() &&
-				filter.isNotDefault();
-
-		// After inventory panel filter is applied we have to update
-		// constraint rect for the selected item because of folder view
-		// AutoSelectOverride set to TRUE. We force PinningSelectedItem
-		// flag to FALSE state and setting filter "dirty" to update
-		// scroll container to show selected item (see LLFolderView::doIdle()).
-		if (!is_filter_active && !mSelectedItemPinned)
-		{
-			folder_view->setPinningSelectedItem(mSelectedItemPinned);
-			folder_view->getViewModelItem()->dirtyFilter();
-			mSelectedItemPinned = TRUE;
-		}
-	}
+            if( preview->getComponents() == 4 )
+            {
+                gl_rect_2d_checkerboard( interior, alpha );
+            }
+
+            gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), preview, UI_VERTEX_COLOR % alpha );
+        }
+        else if (!mFallbackImage.isNull())
+        {
+            mFallbackImage->draw(interior, UI_VERTEX_COLOR % alpha);
+        }
+        else
+        {
+            gl_rect_2d( interior, LLColor4::grey % alpha, TRUE );
+
+            // Draw X
+            gl_draw_x(interior, LLColor4::black );
+        }
+
+        // Draw Tentative Label over the image
+        if( mTentative && !mViewModel->isDirty() )
+        {
+            mTentativeLabel->setVisible( TRUE );
+            drawChild(mTentativeLabel);
+        }
+
+        if (mSelectedItemPinned) return;
+
+        LLFolderView* folder_view = mInventoryPanel->getRootFolder();
+        if (!folder_view) return;
+
+        LLFolderViewFilter& filter = static_cast<LLFolderViewModelInventory*>(folder_view->getFolderViewModel())->getFilter();
+
+        bool is_filter_active = folder_view->getViewModelItem()->getLastFilterGeneration() < filter.getCurrentGeneration() &&
+                filter.isNotDefault();
+
+        // After inventory panel filter is applied we have to update
+        // constraint rect for the selected item because of folder view
+        // AutoSelectOverride set to TRUE. We force PinningSelectedItem
+        // flag to FALSE state and setting filter "dirty" to update
+        // scroll container to show selected item (see LLFolderView::doIdle()).
+        if (!is_filter_active && !mSelectedItemPinned)
+        {
+            folder_view->setPinningSelectedItem(mSelectedItemPinned);
+            folder_view->getViewModelItem()->dirtyFilter();
+            mSelectedItemPinned = TRUE;
+        }
+    }
 }
 
 const LLUUID& LLFloaterTexturePicker::findItemID(const LLUUID& asset_id, BOOL copyable_only, BOOL ignore_library)
 {
-	if (asset_id.isNull())
-	{
+    if (asset_id.isNull())
+    {
         // null asset id means, no material or texture assigned
         return LLUUID::null;
-	}
+    }
 
     LLUUID loockup_id = asset_id;
     if (mInventoryPickType == PICK_MATERIAL && loockup_id == BLANK_MATERIAL_ASSET_ID)
@@ -825,8 +825,8 @@ const LLUUID& LLFloaterTexturePicker::findItemID(const LLUUID& asset_id, BOOL co
         loockup_id = LLUUID::null;
     }
 
-	LLViewerInventoryCategory::cat_array_t cats;
-	LLViewerInventoryItem::item_array_t items;
+    LLViewerInventoryCategory::cat_array_t cats;
+    LLViewerInventoryItem::item_array_t items;
 
     if (loockup_id.isNull())
     {
@@ -850,44 +850,44 @@ const LLUUID& LLFloaterTexturePicker::findItemID(const LLUUID& asset_id, BOOL co
     }
 
 
-	if (items.size())
-	{
-		// search for copyable version first
-		for (S32 i = 0; i < items.size(); i++)
-		{
-			LLInventoryItem* itemp = items[i];
-			LLPermissions item_permissions = itemp->getPermissions();
-			if (item_permissions.allowCopyBy(gAgent.getID(), gAgent.getGroupID()))
-			{
-				if(!ignore_library || !gInventory.isObjectDescendentOf(itemp->getUUID(),gInventory.getLibraryRootFolderID()))
-				{
-					return itemp->getUUID();
-				}
-			}
-		}
-		// otherwise just return first instance, unless copyable requested
-		if (copyable_only)
-		{
-			return LLUUID::null;
-		}
-		else
-		{
-			if(!ignore_library || !gInventory.isObjectDescendentOf(items[0]->getUUID(),gInventory.getLibraryRootFolderID()))
-			{
-				return items[0]->getUUID();
-			}
-		}
-	}
-
-	return LLUUID::null;
+    if (items.size())
+    {
+        // search for copyable version first
+        for (S32 i = 0; i < items.size(); i++)
+        {
+            LLInventoryItem* itemp = items[i];
+            LLPermissions item_permissions = itemp->getPermissions();
+            if (item_permissions.allowCopyBy(gAgent.getID(), gAgent.getGroupID()))
+            {
+                if(!ignore_library || !gInventory.isObjectDescendentOf(itemp->getUUID(),gInventory.getLibraryRootFolderID()))
+                {
+                    return itemp->getUUID();
+                }
+            }
+        }
+        // otherwise just return first instance, unless copyable requested
+        if (copyable_only)
+        {
+            return LLUUID::null;
+        }
+        else
+        {
+            if(!ignore_library || !gInventory.isObjectDescendentOf(items[0]->getUUID(),gInventory.getLibraryRootFolderID()))
+            {
+                return items[0]->getUUID();
+            }
+        }
+    }
+
+    return LLUUID::null;
 }
 
 void LLFloaterTexturePicker::commitIfImmediateSet()
 {
-	if (!mNoCopyTextureSelected && mCanApply)
-	{
+    if (!mNoCopyTextureSelected && mCanApply)
+    {
         commitCallback(LLTextureCtrl::TEXTURE_CHANGE);
-	}
+    }
 }
 
 void LLFloaterTexturePicker::commitCallback(LLTextureCtrl::ETexturePickOp op)
@@ -969,22 +969,22 @@ void LLFloaterTexturePicker::commitCallback(LLTextureCtrl::ETexturePickOp op)
 }
 void LLFloaterTexturePicker::commitCancel()
 {
-	if (!mNoCopyTextureSelected && mOnFloaterCommitCallback && mCanApply)
-	{
-		mOnFloaterCommitCallback(LLTextureCtrl::TEXTURE_CANCEL, PICKER_UNKNOWN, mOriginalImageAssetID, LLUUID::null, LLUUID::null);
-	}
+    if (!mNoCopyTextureSelected && mOnFloaterCommitCallback && mCanApply)
+    {
+        mOnFloaterCommitCallback(LLTextureCtrl::TEXTURE_CANCEL, PICKER_UNKNOWN, mOriginalImageAssetID, LLUUID::null, LLUUID::null);
+    }
 }
 
 // static
 void LLFloaterTexturePicker::onBtnSetToDefault(void* userdata)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
-	self->setCanApply(true, true);
-	if (self->mOwner)
-	{
-		self->setImageID( self->getDefaultImageAssetID() );
-	}
-	self->commitIfImmediateSet();
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
+    self->setCanApply(true, true);
+    if (self->mOwner)
+    {
+        self->setImageID( self->getDefaultImageAssetID() );
+    }
+    self->commitIfImmediateSet();
 }
 
 // static
@@ -999,19 +999,19 @@ void LLFloaterTexturePicker::onBtnTransparent(void* userdata)
 // static
 void LLFloaterTexturePicker::onBtnBlank(void* userdata)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
-	self->setCanApply(true, true);
-	self->setImageID( self->getBlankImageAssetID() );
-	self->commitIfImmediateSet();
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
+    self->setCanApply(true, true);
+    self->setImageID( self->getBlankImageAssetID() );
+    self->commitIfImmediateSet();
 }
 
 
 // static
 void LLFloaterTexturePicker::onBtnNone(void* userdata)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
     self->setCanApply(true, true);
-	self->setImageID( LLUUID::null );
+    self->setImageID( LLUUID::null );
     self->commitIfImmediateSet();
 }
 
@@ -1019,52 +1019,52 @@ void LLFloaterTexturePicker::onBtnNone(void* userdata)
 // static
 void LLFloaterTexturePicker::onBtnRevert(void* userdata)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
-	self->setImageID( self->mOriginalImageAssetID );
-	// TODO: Change this to tell the owner to cancel.  It needs to be
-	// smart enough to restore multi-texture selections.
-	self->mOwner->onFloaterCommit();
-	self->mViewModel->resetDirty();
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
+    self->setImageID( self->mOriginalImageAssetID );
+    // TODO: Change this to tell the owner to cancel.  It needs to be
+    // smart enough to restore multi-texture selections.
+    self->mOwner->onFloaterCommit();
+    self->mViewModel->resetDirty();
 }*/
 
 // static
 void LLFloaterTexturePicker::onBtnCancel(void* userdata)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
-	self->setImageID( self->mOriginalImageAssetID );
-	if (self->mOnFloaterCommitCallback)
-	{
-		self->mOnFloaterCommitCallback(LLTextureCtrl::TEXTURE_CANCEL, PICKER_UNKNOWN, self->mOriginalImageAssetID, LLUUID::null, LLUUID::null);
-	}
-	self->mViewModel->resetDirty();
-	self->closeFloater();
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
+    self->setImageID( self->mOriginalImageAssetID );
+    if (self->mOnFloaterCommitCallback)
+    {
+        self->mOnFloaterCommitCallback(LLTextureCtrl::TEXTURE_CANCEL, PICKER_UNKNOWN, self->mOriginalImageAssetID, LLUUID::null, LLUUID::null);
+    }
+    self->mViewModel->resetDirty();
+    self->closeFloater();
 }
 
 // static
 void LLFloaterTexturePicker::onBtnSelect(void* userdata)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;	
-	if (self->mOnFloaterCommitCallback)
-	{
-		self->commitCallback(LLTextureCtrl::TEXTURE_SELECT);
-	}
-	self->closeFloater();
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
+    if (self->mOnFloaterCommitCallback)
+    {
+        self->commitCallback(LLTextureCtrl::TEXTURE_SELECT);
+    }
+    self->closeFloater();
 }
 
 void LLFloaterTexturePicker::onBtnPipette()
 {
-	BOOL pipette_active = getChild<LLUICtrl>("Pipette")->getValue().asBoolean();
-	pipette_active = !pipette_active;
-	if (pipette_active)
-	{
-		LLToolMgr::getInstance()->clearTransientTool();
-		LLToolPipette::getInstance()->setToolSelectCallback(boost::bind(&LLFloaterTexturePicker::onTextureSelect, this, _1, _3));
-		LLToolMgr::getInstance()->setTransientTool(LLToolPipette::getInstance());
-	}
-	else
-	{
-		LLToolMgr::getInstance()->clearTransientTool();
-	}
+    BOOL pipette_active = getChild<LLUICtrl>("Pipette")->getValue().asBoolean();
+    pipette_active = !pipette_active;
+    if (pipette_active)
+    {
+        LLToolMgr::getInstance()->clearTransientTool();
+        LLToolPipette::getInstance()->setToolSelectCallback(boost::bind(&LLFloaterTexturePicker::onTextureSelect, this, _1, _3));
+        LLToolMgr::getInstance()->setTransientTool(LLToolPipette::getInstance());
+    }
+    else
+    {
+        LLToolMgr::getInstance()->clearTransientTool();
+    }
 }
 
 // static
@@ -1081,40 +1081,40 @@ void LLFloaterTexturePicker::onApplyUUID(void* userdata)
 
 void LLFloaterTexturePicker::onSelectionChange(const std::deque<LLFolderViewItem*> &items, BOOL user_action)
 {
-	if (items.size())
-	{
-		LLFolderViewItem* first_item = items.front();
-		LLInventoryItem* itemp = gInventory.getItem(static_cast<LLFolderViewModelItemInventory*>(first_item->getViewModelItem())->getUUID());
-		mNoCopyTextureSelected = FALSE;
-		if (itemp)
-		{
-			if (!mTextureSelectedCallback.empty())
-			{
-				mTextureSelectedCallback(itemp);
-			}
-			if (!itemp->getPermissions().allowCopyBy(gAgent.getID()))
-			{
-				mNoCopyTextureSelected = TRUE;
-			}
+    if (items.size())
+    {
+        LLFolderViewItem* first_item = items.front();
+        LLInventoryItem* itemp = gInventory.getItem(static_cast<LLFolderViewModelItemInventory*>(first_item->getViewModelItem())->getUUID());
+        mNoCopyTextureSelected = FALSE;
+        if (itemp)
+        {
+            if (!mTextureSelectedCallback.empty())
+            {
+                mTextureSelectedCallback(itemp);
+            }
+            if (!itemp->getPermissions().allowCopyBy(gAgent.getID()))
+            {
+                mNoCopyTextureSelected = TRUE;
+            }
             setImageIDFromItem(itemp, false);
-			mViewModel->setDirty(); // *TODO: shouldn't we be using setValue() here?
-
-			if(!mPreviewSettingChanged)
-			{
-				mCanPreview = mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview");
-			}
-			else
-			{
-				mPreviewSettingChanged = false;
-			}
-
-			if (user_action && mCanPreview)
-			{
-				// only commit intentional selections, not implicit ones
-				commitIfImmediateSet();
-			}
-		}
-	}
+            mViewModel->setDirty(); // *TODO: shouldn't we be using setValue() here?
+
+            if(!mPreviewSettingChanged)
+            {
+                mCanPreview = mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview");
+            }
+            else
+            {
+                mPreviewSettingChanged = false;
+            }
+
+            if (user_action && mCanPreview)
+            {
+                // only commit intentional selections, not implicit ones
+                commitIfImmediateSet();
+            }
+        }
+    }
 }
 
 // static
@@ -1146,18 +1146,18 @@ void LLFloaterTexturePicker::onBtnAdd(void* userdata)
 // static
 void LLFloaterTexturePicker::onBtnRemove(void* userdata)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
-	std::vector<LLScrollListItem*> selected_items = self->mLocalScrollCtrl->getAllSelected();
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
+    std::vector<LLScrollListItem*> selected_items = self->mLocalScrollCtrl->getAllSelected();
 
-	if (!selected_items.empty())
-	{
+    if (!selected_items.empty())
+    {
 
-		for(std::vector<LLScrollListItem*>::iterator iter = selected_items.begin();
-			iter != selected_items.end(); iter++)
-		{
-			LLScrollListItem* list_item = *iter;
-			if (list_item)
-			{
+        for(std::vector<LLScrollListItem*>::iterator iter = selected_items.begin();
+            iter != selected_items.end(); iter++)
+        {
+            LLScrollListItem* list_item = *iter;
+            if (list_item)
+            {
                 LLSD data = list_item->getValue();
                 LLUUID tracking_id = data["id"];
                 S32 asset_type = data["type"].asInteger();
@@ -1170,28 +1170,28 @@ void LLFloaterTexturePicker::onBtnRemove(void* userdata)
                 {
                     LLLocalBitmapMgr::getInstance()->delUnit(tracking_id);
                 }
-			}
-		}
+            }
+        }
 
-		self->getChild<LLButton>("l_rem_btn")->setEnabled(false);
-		self->getChild<LLButton>("l_upl_btn")->setEnabled(false);
+        self->getChild<LLButton>("l_rem_btn")->setEnabled(false);
+        self->getChild<LLButton>("l_upl_btn")->setEnabled(false);
         self->refreshLocalList();
-	}
+    }
 }
 
 // static
 void LLFloaterTexturePicker::onBtnUpload(void* userdata)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
-	std::vector<LLScrollListItem*> selected_items = self->mLocalScrollCtrl->getAllSelected();
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
+    std::vector<LLScrollListItem*> selected_items = self->mLocalScrollCtrl->getAllSelected();
 
-	if (selected_items.empty())
-	{
-		return;
-	}
+    if (selected_items.empty())
+    {
+        return;
+    }
 
-	/* currently only allows uploading one by one, picks the first item from the selection list.  (not the vector!)
-	   in the future, it might be a good idea to check the vector size and if more than one units is selected - opt for multi-image upload. */
+    /* currently only allows uploading one by one, picks the first item from the selection list.  (not the vector!)
+       in the future, it might be a good idea to check the vector size and if more than one units is selected - opt for multi-image upload. */
 
     LLSD data = self->mLocalScrollCtrl->getFirstSelected()->getValue();
     LLUUID tracking_id = data["id"];
@@ -1220,16 +1220,16 @@ void LLFloaterTexturePicker::onBtnUpload(void* userdata)
 //static
 void LLFloaterTexturePicker::onLocalScrollCommit(LLUICtrl* ctrl, void* userdata)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
-	std::vector<LLScrollListItem*> selected_items = self->mLocalScrollCtrl->getAllSelected();
-	bool has_selection = !selected_items.empty();
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*) userdata;
+    std::vector<LLScrollListItem*> selected_items = self->mLocalScrollCtrl->getAllSelected();
+    bool has_selection = !selected_items.empty();
 
-	self->getChild<LLButton>("l_rem_btn")->setEnabled(has_selection);
-	self->getChild<LLButton>("l_upl_btn")->setEnabled(has_selection && (selected_items.size() < 2));
-	/* since multiple-localbitmap upload is not implemented, upl button gets disabled if more than one is selected. */
+    self->getChild<LLButton>("l_rem_btn")->setEnabled(has_selection);
+    self->getChild<LLButton>("l_upl_btn")->setEnabled(has_selection && (selected_items.size() < 2));
+    /* since multiple-localbitmap upload is not implemented, upl button gets disabled if more than one is selected. */
 
-	if (has_selection)
-	{
+    if (has_selection)
+    {
         LLSD data = self->mLocalScrollCtrl->getFirstSelected()->getValue();
         LLUUID tracking_id = data["id"];
         S32 asset_type = data["type"].asInteger();
@@ -1244,114 +1244,114 @@ void LLFloaterTexturePicker::onLocalScrollCommit(LLUICtrl* ctrl, void* userdata)
             inworld_id = LLLocalBitmapMgr::getInstance()->getWorldID(tracking_id);
         }
 
-		if (self->mSetImageAssetIDCallback)
-		{
-			self->mSetImageAssetIDCallback(inworld_id);
-		}
+        if (self->mSetImageAssetIDCallback)
+        {
+            self->mSetImageAssetIDCallback(inworld_id);
+        }
 
-		if (self->childGetValue("apply_immediate_check").asBoolean())
-		{
-			if (self->mOnFloaterCommitCallback)
-			{
-				self->mOnFloaterCommitCallback(LLTextureCtrl::TEXTURE_CHANGE, PICKER_LOCAL, inworld_id, LLUUID::null, tracking_id);
-			}
-		}
-	}
+        if (self->childGetValue("apply_immediate_check").asBoolean())
+        {
+            if (self->mOnFloaterCommitCallback)
+            {
+                self->mOnFloaterCommitCallback(LLTextureCtrl::TEXTURE_CHANGE, PICKER_LOCAL, inworld_id, LLUUID::null, tracking_id);
+            }
+        }
+    }
 }
 
 // static
 void LLFloaterTexturePicker::onApplyImmediateCheck(LLUICtrl* ctrl, void *user_data)
 {
-	LLFloaterTexturePicker* picker = (LLFloaterTexturePicker*)user_data;
+    LLFloaterTexturePicker* picker = (LLFloaterTexturePicker*)user_data;
 
-	LLCheckBoxCtrl* check_box = (LLCheckBoxCtrl*)ctrl;
-	gSavedSettings.setBOOL("TextureLivePreview", check_box->get());
+    LLCheckBoxCtrl* check_box = (LLCheckBoxCtrl*)ctrl;
+    gSavedSettings.setBOOL("TextureLivePreview", check_box->get());
 
-	picker->commitIfImmediateSet();
+    picker->commitIfImmediateSet();
 }
 
 //static
 void LLFloaterTexturePicker::onBakeTextureSelect(LLUICtrl* ctrl, void *user_data)
 {
-	LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)user_data;
-	LLComboBox* combo_box = (LLComboBox*)ctrl;
-
-	S8 type = combo_box->getValue().asInteger();
-	
-	LLUUID imageID = self->mDefaultImageAssetID;
-	if (type == 0)
-	{
-		imageID = IMG_USE_BAKED_HEAD;
-	}
-	else if (type == 1)
-	{
-		imageID = IMG_USE_BAKED_UPPER;
-	}
-	else if (type == 2)
-	{
-		imageID = IMG_USE_BAKED_LOWER;
-	}
-	else if (type == 3)
-	{
-		imageID = IMG_USE_BAKED_EYES;
-	}
-	else if (type == 4)
-	{
-		imageID = IMG_USE_BAKED_SKIRT;
-	}
-	else if (type == 5)
-	{
-		imageID = IMG_USE_BAKED_HAIR;
-	}
-	else if (type == 6)
-	{
-		imageID = IMG_USE_BAKED_LEFTARM;
-	}
-	else if (type == 7)
-	{
-		imageID = IMG_USE_BAKED_LEFTLEG;
-	}
-	else if (type == 8)
-	{
-		imageID = IMG_USE_BAKED_AUX1;
-	}
-	else if (type == 9)
-	{
-		imageID = IMG_USE_BAKED_AUX2;
-	}
-	else if (type == 10)
-	{
-		imageID = IMG_USE_BAKED_AUX3;
-	}
-
-	self->setImageID(imageID);
-	self->mViewModel->setDirty(); // *TODO: shouldn't we be using setValue() here?
-
-	if (!self->mPreviewSettingChanged)
-	{
-		self->mCanPreview = self->mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview");
-	}
-	else
-	{
-		self->mPreviewSettingChanged = false;
-	}
-
-	if (self->mCanPreview)
-	{
-		// only commit intentional selections, not implicit ones
-		self->commitIfImmediateSet();
-	}
+    LLFloaterTexturePicker* self = (LLFloaterTexturePicker*)user_data;
+    LLComboBox* combo_box = (LLComboBox*)ctrl;
+
+    S8 type = combo_box->getValue().asInteger();
+
+    LLUUID imageID = self->mDefaultImageAssetID;
+    if (type == 0)
+    {
+        imageID = IMG_USE_BAKED_HEAD;
+    }
+    else if (type == 1)
+    {
+        imageID = IMG_USE_BAKED_UPPER;
+    }
+    else if (type == 2)
+    {
+        imageID = IMG_USE_BAKED_LOWER;
+    }
+    else if (type == 3)
+    {
+        imageID = IMG_USE_BAKED_EYES;
+    }
+    else if (type == 4)
+    {
+        imageID = IMG_USE_BAKED_SKIRT;
+    }
+    else if (type == 5)
+    {
+        imageID = IMG_USE_BAKED_HAIR;
+    }
+    else if (type == 6)
+    {
+        imageID = IMG_USE_BAKED_LEFTARM;
+    }
+    else if (type == 7)
+    {
+        imageID = IMG_USE_BAKED_LEFTLEG;
+    }
+    else if (type == 8)
+    {
+        imageID = IMG_USE_BAKED_AUX1;
+    }
+    else if (type == 9)
+    {
+        imageID = IMG_USE_BAKED_AUX2;
+    }
+    else if (type == 10)
+    {
+        imageID = IMG_USE_BAKED_AUX3;
+    }
+
+    self->setImageID(imageID);
+    self->mViewModel->setDirty(); // *TODO: shouldn't we be using setValue() here?
+
+    if (!self->mPreviewSettingChanged)
+    {
+        self->mCanPreview = self->mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview");
+    }
+    else
+    {
+        self->mPreviewSettingChanged = false;
+    }
+
+    if (self->mCanPreview)
+    {
+        // only commit intentional selections, not implicit ones
+        self->commitIfImmediateSet();
+    }
 }
 
 void LLFloaterTexturePicker::setCanApply(bool can_preview, bool can_apply, bool inworld_image)
 {
-	mSelectBtn->setEnabled(can_apply);
-	getChildRef<LLUICtrl>("preview_disabled").setVisible(!can_preview && inworld_image);
-	getChildRef<LLUICtrl>("apply_immediate_check").setVisible(can_preview);
+    mSelectBtn->setEnabled(can_apply);
+    getChildRef<LLUICtrl>("preview_disabled").setVisible(!can_preview && inworld_image);
+    getChildRef<LLUICtrl>("apply_immediate_check").setVisible(can_preview);
 
-	mCanApply = can_apply;
-	mCanPreview = can_preview ? (mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview")) : false;
-	mPreviewSettingChanged = true;
+    mCanApply = can_apply;
+    mCanPreview = can_preview ? (mCanApplyImmediately && gSavedSettings.getBOOL("TextureLivePreview")) : false;
+    mPreviewSettingChanged = true;
 }
 
 void LLFloaterTexturePicker::setMinDimentionsLimits(S32 min_dim)
@@ -1365,36 +1365,36 @@ void LLFloaterTexturePicker::setMinDimentionsLimits(S32 min_dim)
 
 void LLFloaterTexturePicker::onFilterEdit(const std::string& search_string )
 {
-	std::string upper_case_search_string = search_string;
-	LLStringUtil::toUpper(upper_case_search_string);
-
-	if (upper_case_search_string.empty())
-	{
-		if (mInventoryPanel->getFilterSubString().empty())
-		{
-			// current filter and new filter empty, do nothing
-			return;
-		}
-
-		mSavedFolderState.setApply(TRUE);
-		mInventoryPanel->getRootFolder()->applyFunctorRecursively(mSavedFolderState);
-		// add folder with current item to list of previously opened folders
-		LLOpenFoldersWithSelection opener;
-		mInventoryPanel->getRootFolder()->applyFunctorRecursively(opener);
-		mInventoryPanel->getRootFolder()->scrollToShowSelection();
-
-	}
-	else if (mInventoryPanel->getFilterSubString().empty())
-	{
-		// first letter in search term, save existing folder open state
-		if (!mInventoryPanel->getFilter().isNotDefault())
-		{
-			mSavedFolderState.setApply(FALSE);
-			mInventoryPanel->getRootFolder()->applyFunctorRecursively(mSavedFolderState);
-		}
-	}
-
-	mInventoryPanel->setFilterSubString(search_string);
+    std::string upper_case_search_string = search_string;
+    LLStringUtil::toUpper(upper_case_search_string);
+
+    if (upper_case_search_string.empty())
+    {
+        if (mInventoryPanel->getFilterSubString().empty())
+        {
+            // current filter and new filter empty, do nothing
+            return;
+        }
+
+        mSavedFolderState.setApply(TRUE);
+        mInventoryPanel->getRootFolder()->applyFunctorRecursively(mSavedFolderState);
+        // add folder with current item to list of previously opened folders
+        LLOpenFoldersWithSelection opener;
+        mInventoryPanel->getRootFolder()->applyFunctorRecursively(opener);
+        mInventoryPanel->getRootFolder()->scrollToShowSelection();
+
+    }
+    else if (mInventoryPanel->getFilterSubString().empty())
+    {
+        // first letter in search term, save existing folder open state
+        if (!mInventoryPanel->getFilter().isNotDefault())
+        {
+            mSavedFolderState.setApply(FALSE);
+            mInventoryPanel->getRootFolder()->applyFunctorRecursively(mSavedFolderState);
+        }
+    }
+
+    mInventoryPanel->setFilterSubString(search_string);
 }
 
 void LLFloaterTexturePicker::changeMode()
@@ -1527,24 +1527,24 @@ void LLFloaterTexturePicker::setLocalTextureEnabled(BOOL enabled)
 
 void LLFloaterTexturePicker::setBakeTextureEnabled(BOOL enabled)
 {
-	BOOL changed = (enabled != mBakeTextureEnabled);
+    BOOL changed = (enabled != mBakeTextureEnabled);
+
+    mBakeTextureEnabled = enabled;
+    mModeSelector->setEnabledByValue(2, enabled);
 
-	mBakeTextureEnabled = enabled;
-	mModeSelector->setEnabledByValue(2, enabled);
+    if (!mBakeTextureEnabled && (mModeSelector->getValue().asInteger() == 2))
+    {
+        mModeSelector->selectByValue(0);
+    }
 
-	if (!mBakeTextureEnabled && (mModeSelector->getValue().asInteger() == 2))
-	{
-		mModeSelector->selectByValue(0);
-	}
-	
-	if (changed && mBakeTextureEnabled && LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
-	{
-		if (mModeSelector->getValue().asInteger() != 2)
-		{
-			mModeSelector->selectByValue(2);
-		}
-	}
-	onModeSelect(0, this);
+    if (changed && mBakeTextureEnabled && LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
+    {
+        if (mModeSelector->getValue().asInteger() != 2)
+        {
+            mModeSelector->selectByValue(2);
+        }
+    }
+    onModeSelect(0, this);
 }
 
 void LLFloaterTexturePicker::setInventoryPickType(EPickInventoryType type)
@@ -1567,13 +1567,13 @@ void LLFloaterTexturePicker::setInventoryPickType(EPickInventoryType type)
     {
         setTitle(getString("pick_material"));
     }
-	else if (!mLabel.empty())
-	{
-		std::string pick = getString("pick title");
+    else if (!mLabel.empty())
+    {
+        std::string pick = getString("pick title");
 
-		setTitle(pick + mLabel);
-	}
-	else
+        setTitle(pick + mLabel);
+    }
+    else
     {
         setTitle(getString("pick_texture"));
     }
@@ -1635,40 +1635,40 @@ void LLFloaterTexturePicker::onPickerCallback(const std::vector<std::string>& fi
 
 void LLFloaterTexturePicker::onTextureSelect(bool success, const LLTextureEntry& te )
 {
-	if (success)
-	{
-		LLUUID inventory_item_id = findItemID(te.getID(), TRUE);
-		if (inventory_item_id.notNull())
-		{
-			LLToolPipette::getInstance()->setResult(TRUE, "");
-			if (mInventoryPickType == PICK_MATERIAL)
-			{
-				// tes have no data about material ids
-				// Plus gltf materials are layered with overrides,
-				// which mean that end result might have no id.
-				LL_WARNS() << "tes have no data about material ids" << LL_ENDL;
-			}
-			else
-			{
-				setImageID(te.getID());
-			}
-
-			mNoCopyTextureSelected = FALSE;
-			LLInventoryItem* itemp = gInventory.getItem(inventory_item_id);
-
-			if (itemp && !itemp->getPermissions().allowCopyBy(gAgent.getID()))
-			{
-				// no copy texture
-				mNoCopyTextureSelected = TRUE;
-			}
-
-			commitIfImmediateSet();
-		}
-		else
-		{
-			LLToolPipette::getInstance()->setResult(FALSE, LLTrans::getString("InventoryNoTexture"));
-		}
-	}
+    if (success)
+    {
+        LLUUID inventory_item_id = findItemID(te.getID(), TRUE);
+        if (inventory_item_id.notNull())
+        {
+            LLToolPipette::getInstance()->setResult(TRUE, "");
+            if (mInventoryPickType == PICK_MATERIAL)
+            {
+                // tes have no data about material ids
+                // Plus gltf materials are layered with overrides,
+                // which mean that end result might have no id.
+                LL_WARNS() << "tes have no data about material ids" << LL_ENDL;
+            }
+            else
+            {
+                setImageID(te.getID());
+            }
+
+            mNoCopyTextureSelected = FALSE;
+            LLInventoryItem* itemp = gInventory.getItem(inventory_item_id);
+
+            if (itemp && !itemp->getPermissions().allowCopyBy(gAgent.getID()))
+            {
+                // no copy texture
+                mNoCopyTextureSelected = TRUE;
+            }
+
+            commitIfImmediateSet();
+        }
+        else
+        {
+            LLToolPipette::getInstance()->setResult(FALSE, LLTrans::getString("InventoryNoTexture"));
+        }
+    }
 }
 
 ///////////////////////////////////////////////////////////////////////
@@ -1677,108 +1677,108 @@ void LLFloaterTexturePicker::onTextureSelect(bool success, const LLTextureEntry&
 static LLDefaultChildRegistry::Register<LLTextureCtrl> r("texture_picker");
 
 LLTextureCtrl::LLTextureCtrl(const LLTextureCtrl::Params& p)
-:	LLUICtrl(p),
-	mDragCallback(NULL),
-	mDropCallback(NULL),
-	mOnCancelCallback(NULL),
-	mOnCloseCallback(NULL),
-	mOnSelectCallback(NULL),
-	mBorderColor( p.border_color() ),
-	mAllowNoTexture( p.allow_no_texture ),
-	mAllowLocalTexture( TRUE ),
-	mImmediateFilterPermMask( PERM_NONE ),
-	mCanApplyImmediately( FALSE ),
-	mNeedsRawImageData( FALSE ),
-	mValid( TRUE ),
-	mShowLoadingPlaceholder( TRUE ),
-	mOpenTexPreview(false),
+:   LLUICtrl(p),
+    mDragCallback(NULL),
+    mDropCallback(NULL),
+    mOnCancelCallback(NULL),
+    mOnCloseCallback(NULL),
+    mOnSelectCallback(NULL),
+    mBorderColor( p.border_color() ),
+    mAllowNoTexture( p.allow_no_texture ),
+    mAllowLocalTexture( TRUE ),
+    mImmediateFilterPermMask( PERM_NONE ),
+    mCanApplyImmediately( FALSE ),
+    mNeedsRawImageData( FALSE ),
+    mValid( TRUE ),
+    mShowLoadingPlaceholder( TRUE ),
+    mOpenTexPreview(false),
     mBakeTextureEnabled(true),
     mInventoryPickType(p.pick_type),
-	mImageAssetID(p.image_id),
-	mDefaultImageAssetID(p.default_image_id),
-	mDefaultImageName(p.default_image_name),
-	mFallbackImage(p.fallback_image)
-{
-	setTransparentImageAssetID( IMG_INVISIBLE );
-
-	// Default of defaults is white image for diff tex
-	//
-	setBlankImageAssetID(IMG_WHITE);
-
-	setAllowNoTexture(p.allow_no_texture);
-	setCanApplyImmediately(p.can_apply_immediately);
-	mCommitOnSelection = !p.no_commit_on_selection;
-
-	LLTextBox::Params params(p.caption_text);
-	params.name(p.label);
-	params.rect(LLRect( 0, BTN_HEIGHT_SMALL, getRect().getWidth(), 0 ));
-	params.initial_value(p.label());
-	params.follows.flags(FOLLOWS_LEFT | FOLLOWS_RIGHT | FOLLOWS_BOTTOM);
-	mCaption = LLUICtrlFactory::create<LLTextBox> (params);
-	addChild( mCaption );
-
-	S32 image_top = getRect().getHeight();
-	S32 image_bottom = BTN_HEIGHT_SMALL;
-	S32 image_middle = (image_top + image_bottom) / 2;
-	S32 line_height = LLFontGL::getFontSansSerifSmall()->getLineHeight();
-
-	LLTextBox::Params tentative_label_p(p.multiselect_text);
-	tentative_label_p.name("Multiple");
-	tentative_label_p.rect(LLRect (0, image_middle + line_height / 2, getRect().getWidth(), image_middle - line_height / 2 ));
-	tentative_label_p.follows.flags(FOLLOWS_ALL);
-	mTentativeLabel = LLUICtrlFactory::create<LLTextBox> (tentative_label_p);
-
-	// It is no longer possible to associate a style with a textbox, so it has to be done in this fashion
-	LLStyle::Params style_params;
-	style_params.color = LLColor4::white;
-
-	mTentativeLabel->setText(LLTrans::getString("multiple_textures"), style_params);
-	mTentativeLabel->setHAlign(LLFontGL::HCENTER);
-	addChild( mTentativeLabel );
-
-	LLRect border_rect = getLocalRect();
-	border_rect.mBottom += BTN_HEIGHT_SMALL;
-	LLViewBorder::Params vbparams(p.border);
-	vbparams.name("border");
-	vbparams.rect(border_rect);
-	mBorder = LLUICtrlFactory::create<LLViewBorder> (vbparams);
-	addChild(mBorder);
-
-	mLoadingPlaceholderString = LLTrans::getString("texture_loading");
+    mImageAssetID(p.image_id),
+    mDefaultImageAssetID(p.default_image_id),
+    mDefaultImageName(p.default_image_name),
+    mFallbackImage(p.fallback_image)
+{
+    setTransparentImageAssetID( IMG_INVISIBLE );
+
+    // Default of defaults is white image for diff tex
+    //
+    setBlankImageAssetID(IMG_WHITE);
+
+    setAllowNoTexture(p.allow_no_texture);
+    setCanApplyImmediately(p.can_apply_immediately);
+    mCommitOnSelection = !p.no_commit_on_selection;
+
+    LLTextBox::Params params(p.caption_text);
+    params.name(p.label);
+    params.rect(LLRect( 0, BTN_HEIGHT_SMALL, getRect().getWidth(), 0 ));
+    params.initial_value(p.label());
+    params.follows.flags(FOLLOWS_LEFT | FOLLOWS_RIGHT | FOLLOWS_BOTTOM);
+    mCaption = LLUICtrlFactory::create<LLTextBox> (params);
+    addChild( mCaption );
+
+    S32 image_top = getRect().getHeight();
+    S32 image_bottom = BTN_HEIGHT_SMALL;
+    S32 image_middle = (image_top + image_bottom) / 2;
+    S32 line_height = LLFontGL::getFontSansSerifSmall()->getLineHeight();
+
+    LLTextBox::Params tentative_label_p(p.multiselect_text);
+    tentative_label_p.name("Multiple");
+    tentative_label_p.rect(LLRect (0, image_middle + line_height / 2, getRect().getWidth(), image_middle - line_height / 2 ));
+    tentative_label_p.follows.flags(FOLLOWS_ALL);
+    mTentativeLabel = LLUICtrlFactory::create<LLTextBox> (tentative_label_p);
+
+    // It is no longer possible to associate a style with a textbox, so it has to be done in this fashion
+    LLStyle::Params style_params;
+    style_params.color = LLColor4::white;
+
+    mTentativeLabel->setText(LLTrans::getString("multiple_textures"), style_params);
+    mTentativeLabel->setHAlign(LLFontGL::HCENTER);
+    addChild( mTentativeLabel );
+
+    LLRect border_rect = getLocalRect();
+    border_rect.mBottom += BTN_HEIGHT_SMALL;
+    LLViewBorder::Params vbparams(p.border);
+    vbparams.name("border");
+    vbparams.rect(border_rect);
+    mBorder = LLUICtrlFactory::create<LLViewBorder> (vbparams);
+    addChild(mBorder);
+
+    mLoadingPlaceholderString = LLTrans::getString("texture_loading");
 }
 
 LLTextureCtrl::~LLTextureCtrl()
 {
-	closeDependentFloater();
+    closeDependentFloater();
 }
 
 void LLTextureCtrl::setShowLoadingPlaceholder(BOOL showLoadingPlaceholder)
 {
-	mShowLoadingPlaceholder = showLoadingPlaceholder;
+    mShowLoadingPlaceholder = showLoadingPlaceholder;
 }
 
 void LLTextureCtrl::setCaption(const std::string& caption)
 {
-	mCaption->setText( caption );
+    mCaption->setText( caption );
 }
 
 void LLTextureCtrl::setCanApplyImmediately(BOOL b)
 {
-	mCanApplyImmediately = b; 
-	LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
-	if( floaterp )
-	{
-		floaterp->setCanApplyImmediately(b);
-	}
+    mCanApplyImmediately = b;
+    LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
+    if( floaterp )
+    {
+        floaterp->setCanApplyImmediately(b);
+    }
 }
 
 void LLTextureCtrl::setCanApply(bool can_preview, bool can_apply)
 {
-	LLFloaterTexturePicker* floaterp = dynamic_cast<LLFloaterTexturePicker*>(mFloaterHandle.get());
-	if( floaterp )
-	{
-		floaterp->setCanApply(can_preview, can_apply);
-	}
+    LLFloaterTexturePicker* floaterp = dynamic_cast<LLFloaterTexturePicker*>(mFloaterHandle.get());
+    if( floaterp )
+    {
+        floaterp->setCanApply(can_preview, can_apply);
+    }
 }
 
 void LLTextureCtrl::setImmediateFilterPermMask(PermissionMask mask)
@@ -1792,7 +1792,7 @@ void LLTextureCtrl::setImmediateFilterPermMask(PermissionMask mask)
     }
 }
 
-void LLTextureCtrl::setFilterPermissionMasks(PermissionMask mask) 
+void LLTextureCtrl::setFilterPermissionMasks(PermissionMask mask)
 {
     setImmediateFilterPermMask(mask);
     setDnDFilterPermMask(mask);
@@ -1811,177 +1811,177 @@ void LLTextureCtrl::onVisibilityChange(BOOL new_visibility)
     }
 }
 
-void LLTextureCtrl::setVisible( BOOL visible ) 
+void LLTextureCtrl::setVisible( BOOL visible )
 {
-	if( !visible )
-	{
-		closeDependentFloater();
-	}
-	LLUICtrl::setVisible( visible );
+    if( !visible )
+    {
+        closeDependentFloater();
+    }
+    LLUICtrl::setVisible( visible );
 }
 
 void LLTextureCtrl::setEnabled( BOOL enabled )
 {
-	LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
-	if( floaterp )
-	{
-		floaterp->setActive(enabled);
-	}
-	if( enabled )
-	{
-		std::string tooltip;
-		if (floaterp) tooltip = floaterp->getString("choose_picture");
-		setToolTip( tooltip );
-	}
-	else
-	{
-		setToolTip( std::string() );
-		// *TODO: would be better to keep floater open and show
-		// disabled state.
-		closeDependentFloater();
-	}
-
-	mCaption->setEnabled( enabled );
-
-	LLView::setEnabled( enabled );
+    LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
+    if( floaterp )
+    {
+        floaterp->setActive(enabled);
+    }
+    if( enabled )
+    {
+        std::string tooltip;
+        if (floaterp) tooltip = floaterp->getString("choose_picture");
+        setToolTip( tooltip );
+    }
+    else
+    {
+        setToolTip( std::string() );
+        // *TODO: would be better to keep floater open and show
+        // disabled state.
+        closeDependentFloater();
+    }
+
+    mCaption->setEnabled( enabled );
+
+    LLView::setEnabled( enabled );
 }
 
 void LLTextureCtrl::setValid(BOOL valid )
 {
-	mValid = valid;
-	if (!valid)
-	{
-		LLFloaterTexturePicker* pickerp = (LLFloaterTexturePicker*)mFloaterHandle.get();
-		if (pickerp)
-		{
-			pickerp->setActive(FALSE);
-		}
-	}
+    mValid = valid;
+    if (!valid)
+    {
+        LLFloaterTexturePicker* pickerp = (LLFloaterTexturePicker*)mFloaterHandle.get();
+        if (pickerp)
+        {
+            pickerp->setActive(FALSE);
+        }
+    }
 }
 
 
 // virtual
 void LLTextureCtrl::clear()
 {
-	setImageAssetID(LLUUID::null);
+    setImageAssetID(LLUUID::null);
 }
 
 void LLTextureCtrl::setLabel(const std::string& label)
 {
-	mLabel = label;
-	mCaption->setText(label);
+    mLabel = label;
+    mCaption->setText(label);
 }
 
 void LLTextureCtrl::showPicker(BOOL take_focus)
 {
-	// show hourglass cursor when loading inventory window
-	// because inventory construction is slooow
-	getWindow()->setCursor(UI_CURSOR_WAIT);
-	LLFloater* floaterp = mFloaterHandle.get();
-
-	// Show the dialog
-	if( floaterp )
-	{
-		floaterp->openFloater();
-	}
-	else
-	{
-		floaterp = new LLFloaterTexturePicker(
-			this,
-			getImageAssetID(),
-			getDefaultImageAssetID(),
-			getTransparentImageAssetID(),
-			getBlankImageAssetID(),
-			getTentative(),
-			getAllowNoTexture(),
-			mLabel,
-			mImmediateFilterPermMask,
-			mDnDFilterPermMask,
-			mCanApplyImmediately,
-			mFallbackImage,
-			mInventoryPickType);
-		mFloaterHandle = floaterp->getHandle();
-
-		LLFloaterTexturePicker* texture_floaterp = dynamic_cast<LLFloaterTexturePicker*>(floaterp);
-		if (texture_floaterp && mOnTextureSelectedCallback)
-		{
-			texture_floaterp->setTextureSelectedCallback(mOnTextureSelectedCallback);
-		}
-		if (texture_floaterp && mOnCloseCallback)
-		{
-			texture_floaterp->setOnFloaterCloseCallback(boost::bind(&LLTextureCtrl::onFloaterClose, this));
-		}
-		if (texture_floaterp)
-		{
-			texture_floaterp->setOnFloaterCommitCallback(boost::bind(&LLTextureCtrl::onFloaterCommit, this, _1, _2, _3, _4, _5));
-		}
-		if (texture_floaterp)
-		{
-			texture_floaterp->setSetImageAssetIDCallback(boost::bind(&LLTextureCtrl::setImageAssetID, this, _1));
-
-			texture_floaterp->setBakeTextureEnabled(mBakeTextureEnabled);
-		}
-
-		LLFloater* root_floater = gFloaterView->getParentFloater(this);
-		if (root_floater)
-			root_floater->addDependentFloater(floaterp);
-		floaterp->openFloater();
-	}
-
-	LLFloaterTexturePicker* picker_floater = dynamic_cast<LLFloaterTexturePicker*>(floaterp);
-	if (picker_floater)
-	{
-		picker_floater->setLocalTextureEnabled(mAllowLocalTexture);
-	}
-
-	if (take_focus)
-	{
-		floaterp->setFocus(TRUE);
-	}
+    // show hourglass cursor when loading inventory window
+    // because inventory construction is slooow
+    getWindow()->setCursor(UI_CURSOR_WAIT);
+    LLFloater* floaterp = mFloaterHandle.get();
+
+    // Show the dialog
+    if( floaterp )
+    {
+        floaterp->openFloater();
+    }
+    else
+    {
+        floaterp = new LLFloaterTexturePicker(
+            this,
+            getImageAssetID(),
+            getDefaultImageAssetID(),
+            getTransparentImageAssetID(),
+            getBlankImageAssetID(),
+            getTentative(),
+            getAllowNoTexture(),
+            mLabel,
+            mImmediateFilterPermMask,
+            mDnDFilterPermMask,
+            mCanApplyImmediately,
+            mFallbackImage,
+            mInventoryPickType);
+        mFloaterHandle = floaterp->getHandle();
+
+        LLFloaterTexturePicker* texture_floaterp = dynamic_cast<LLFloaterTexturePicker*>(floaterp);
+        if (texture_floaterp && mOnTextureSelectedCallback)
+        {
+            texture_floaterp->setTextureSelectedCallback(mOnTextureSelectedCallback);
+        }
+        if (texture_floaterp && mOnCloseCallback)
+        {
+            texture_floaterp->setOnFloaterCloseCallback(boost::bind(&LLTextureCtrl::onFloaterClose, this));
+        }
+        if (texture_floaterp)
+        {
+            texture_floaterp->setOnFloaterCommitCallback(boost::bind(&LLTextureCtrl::onFloaterCommit, this, _1, _2, _3, _4, _5));
+        }
+        if (texture_floaterp)
+        {
+            texture_floaterp->setSetImageAssetIDCallback(boost::bind(&LLTextureCtrl::setImageAssetID, this, _1));
+
+            texture_floaterp->setBakeTextureEnabled(mBakeTextureEnabled);
+        }
+
+        LLFloater* root_floater = gFloaterView->getParentFloater(this);
+        if (root_floater)
+            root_floater->addDependentFloater(floaterp);
+        floaterp->openFloater();
+    }
+
+    LLFloaterTexturePicker* picker_floater = dynamic_cast<LLFloaterTexturePicker*>(floaterp);
+    if (picker_floater)
+    {
+        picker_floater->setLocalTextureEnabled(mAllowLocalTexture);
+    }
+
+    if (take_focus)
+    {
+        floaterp->setFocus(TRUE);
+    }
 }
 
 
 void LLTextureCtrl::closeDependentFloater()
 {
-	LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
-	if( floaterp && floaterp->isInVisibleChain())
-	{
-		floaterp->setOwner(NULL);
-		floaterp->setVisible(FALSE);
-		floaterp->closeFloater();
-	}
+    LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
+    if( floaterp && floaterp->isInVisibleChain())
+    {
+        floaterp->setOwner(NULL);
+        floaterp->setVisible(FALSE);
+        floaterp->closeFloater();
+    }
 }
 
 // Allow us to download textures quickly when floater is shown
 class LLTextureFetchDescendentsObserver : public LLInventoryFetchDescendentsObserver
 {
 public:
-	virtual void done()
-	{
-		// We need to find textures in all folders, so get the main
-		// background download going.
-		LLInventoryModelBackgroundFetch::instance().start();
-		gInventory.removeObserver(this);
-		delete this;
-	}
+    virtual void done()
+    {
+        // We need to find textures in all folders, so get the main
+        // background download going.
+        LLInventoryModelBackgroundFetch::instance().start();
+        gInventory.removeObserver(this);
+        delete this;
+    }
 };
 
 BOOL LLTextureCtrl::handleHover(S32 x, S32 y, MASK mask)
 {
-	getWindow()->setCursor(mBorder->parentPointInView(x,y) ? UI_CURSOR_HAND : UI_CURSOR_ARROW);
-	return TRUE;
+    getWindow()->setCursor(mBorder->parentPointInView(x,y) ? UI_CURSOR_HAND : UI_CURSOR_ARROW);
+    return TRUE;
 }
 
 
 BOOL LLTextureCtrl::handleMouseDown(S32 x, S32 y, MASK mask)
 {
-	BOOL handled = LLUICtrl::handleMouseDown( x, y , mask );
+    BOOL handled = LLUICtrl::handleMouseDown( x, y , mask );
 
-	if (!handled && mBorder->parentPointInView(x, y))
-	{
-		if (!mOpenTexPreview)
-		{
-			showPicker(FALSE);
+    if (!handled && mBorder->parentPointInView(x, y))
+    {
+        if (!mOpenTexPreview)
+        {
+            showPicker(FALSE);
             if (mInventoryPickType == PICK_MATERIAL)
             {
                 //grab materials first...
@@ -1992,48 +1992,48 @@ BOOL LLTextureCtrl::handleMouseDown(S32 x, S32 y, MASK mask)
                 //grab textures first...
                 LLInventoryModelBackgroundFetch::instance().start(gInventory.findCategoryUUIDForType(LLFolderType::FT_TEXTURE));
             }
-			//...then start full inventory fetch.
+            //...then start full inventory fetch.
             if (!LLInventoryModelBackgroundFetch::instance().inventoryFetchStarted())
             {
                 LLInventoryModelBackgroundFetch::instance().start();
             }
-			handled = TRUE;
-		}
-		else
-		{
-			if (getImageAssetID().notNull())
-			{
-				LLPreviewTexture* preview_texture = LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", getValue());
-				if (preview_texture && !preview_texture->isDependent())
-				{
-					LLFloater* root_floater = gFloaterView->getParentFloater(this);
-					if (root_floater)
-					{
-						root_floater->addDependentFloater(preview_texture);
-						preview_texture->hideCtrlButtons();
-					}
-				}
-			}
-		}
-	}
-
-	return handled;
+            handled = TRUE;
+        }
+        else
+        {
+            if (getImageAssetID().notNull())
+            {
+                LLPreviewTexture* preview_texture = LLFloaterReg::showTypedInstance<LLPreviewTexture>("preview_texture", getValue());
+                if (preview_texture && !preview_texture->isDependent())
+                {
+                    LLFloater* root_floater = gFloaterView->getParentFloater(this);
+                    if (root_floater)
+                    {
+                        root_floater->addDependentFloater(preview_texture);
+                        preview_texture->hideCtrlButtons();
+                    }
+                }
+            }
+        }
+    }
+
+    return handled;
 }
 
 void LLTextureCtrl::onFloaterClose()
 {
-	LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
+    LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
 
-	if (floaterp)
-	{
-		if (mOnCloseCallback)
-		{
-			mOnCloseCallback(this,LLSD());
-		}
-		floaterp->setOwner(NULL);
-	}
+    if (floaterp)
+    {
+        if (mOnCloseCallback)
+        {
+            mOnCloseCallback(this,LLSD());
+        }
+        floaterp->setOwner(NULL);
+    }
 
-	mFloaterHandle.markDead();
+    mFloaterHandle.markDead();
 }
 
 void LLTextureCtrl::onFloaterCommit(ETexturePickOp op, LLPickerSource source, const LLUUID& asset_id, const LLUUID& inv_id, const LLUUID& tracking_id)
@@ -2041,18 +2041,18 @@ void LLTextureCtrl::onFloaterCommit(ETexturePickOp op, LLPickerSource source, co
     LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
 
     if( floaterp && getEnabled())
-	{
-		if (op == TEXTURE_CANCEL)
-			mViewModel->resetDirty();
-		// If the "no_commit_on_selection" parameter is set
-		// we get dirty only when user presses OK in the picker
-		// (i.e. op == TEXTURE_SELECT) or texture changes via DnD.
-		else if (mCommitOnSelection || op == TEXTURE_SELECT)
-			mViewModel->setDirty(); // *TODO: shouldn't we be using setValue() here?
-			
-		if(floaterp->isDirty() || asset_id.notNull()) // mModelView->setDirty does not work.
-		{
-			setTentative( FALSE );
+    {
+        if (op == TEXTURE_CANCEL)
+            mViewModel->resetDirty();
+        // If the "no_commit_on_selection" parameter is set
+        // we get dirty only when user presses OK in the picker
+        // (i.e. op == TEXTURE_SELECT) or texture changes via DnD.
+        else if (mCommitOnSelection || op == TEXTURE_SELECT)
+            mViewModel->setDirty(); // *TODO: shouldn't we be using setValue() here?
+
+        if(floaterp->isDirty() || asset_id.notNull()) // mModelView->setDirty does not work.
+        {
+            setTentative( FALSE );
 
             switch(source)
             {
@@ -2081,76 +2081,76 @@ void LLTextureCtrl::onFloaterCommit(ETexturePickOp op, LLPickerSource source, co
 
             LL_DEBUGS() << "mImageAssetID: " << mImageAssetID << ", mImageItemID: " << mImageItemID << LL_ENDL;
 
-			if (op == TEXTURE_SELECT && mOnSelectCallback)
-			{
+            if (op == TEXTURE_SELECT && mOnSelectCallback)
+            {
                 mOnSelectCallback(this, LLSD());
-			}
-			else if (op == TEXTURE_CANCEL && mOnCancelCallback)
-			{
-				mOnCancelCallback( this, LLSD() );
-			}
-			else
-			{
-				// If the "no_commit_on_selection" parameter is set
-				// we commit only when user presses OK in the picker
-				// (i.e. op == TEXTURE_SELECT) or texture changes via DnD.
+            }
+            else if (op == TEXTURE_CANCEL && mOnCancelCallback)
+            {
+                mOnCancelCallback( this, LLSD() );
+            }
+            else
+            {
+                // If the "no_commit_on_selection" parameter is set
+                // we commit only when user presses OK in the picker
+                // (i.e. op == TEXTURE_SELECT) or texture changes via DnD.
                 if (mCommitOnSelection || op == TEXTURE_SELECT)
                 {
                     onCommit();
                 }
-			}
-		}
-	}
+            }
+        }
+    }
 }
 
 void LLTextureCtrl::setOnTextureSelectedCallback(texture_selected_callback cb)
 {
-	mOnTextureSelectedCallback = cb;
-	LLFloaterTexturePicker* floaterp = dynamic_cast<LLFloaterTexturePicker*>(mFloaterHandle.get());
-	if (floaterp)
-	{
-		floaterp->setTextureSelectedCallback(cb);
-	}
+    mOnTextureSelectedCallback = cb;
+    LLFloaterTexturePicker* floaterp = dynamic_cast<LLFloaterTexturePicker*>(mFloaterHandle.get());
+    if (floaterp)
+    {
+        floaterp->setTextureSelectedCallback(cb);
+    }
 }
 
-void	LLTextureCtrl::setImageAssetName(const std::string& name)
+void    LLTextureCtrl::setImageAssetName(const std::string& name)
 {
-	LLPointer<LLUIImage> imagep = LLUI::getUIImage(name);
-	if(imagep)
-	{
-		LLViewerFetchedTexture* pTexture = dynamic_cast<LLViewerFetchedTexture*>(imagep->getImage().get());
-		if(pTexture)
-		{
-			LLUUID id = pTexture->getID();
-			setImageAssetID(id);
-		}
-	}
+    LLPointer<LLUIImage> imagep = LLUI::getUIImage(name);
+    if(imagep)
+    {
+        LLViewerFetchedTexture* pTexture = dynamic_cast<LLViewerFetchedTexture*>(imagep->getImage().get());
+        if(pTexture)
+        {
+            LLUUID id = pTexture->getID();
+            setImageAssetID(id);
+        }
+    }
 }
 
 void LLTextureCtrl::setImageAssetID( const LLUUID& asset_id )
 {
-	if( mImageAssetID != asset_id )
-	{
-		mImageItemID.setNull();
-		mImageAssetID = asset_id;
+    if( mImageAssetID != asset_id )
+    {
+        mImageItemID.setNull();
+        mImageAssetID = asset_id;
         mLocalTrackingID.setNull();
-		LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
-		if( floaterp && getEnabled() )
-		{
-			floaterp->setImageID( asset_id );
-			floaterp->resetDirty();
-		}
-	}
+        LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
+        if( floaterp && getEnabled() )
+        {
+            floaterp->setImageID( asset_id );
+            floaterp->resetDirty();
+        }
+    }
 }
 
 void LLTextureCtrl::setBakeTextureEnabled(bool enabled)
 {
     mBakeTextureEnabled = enabled;
-	LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
-	if (floaterp)
-	{
-		floaterp->setBakeTextureEnabled(enabled);
-	}
+    LLFloaterTexturePicker* floaterp = (LLFloaterTexturePicker*)mFloaterHandle.get();
+    if (floaterp)
+    {
+        floaterp->setBakeTextureEnabled(enabled);
+    }
 }
 
 void LLTextureCtrl::setInventoryPickType(EPickInventoryType type)
@@ -2164,16 +2164,16 @@ void LLTextureCtrl::setInventoryPickType(EPickInventoryType type)
 }
 
 BOOL LLTextureCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask,
-					  BOOL drop, EDragAndDropType cargo_type, void *cargo_data,
-					  EAcceptance *accept,
-					  std::string& tooltip_msg)
+                      BOOL drop, EDragAndDropType cargo_type, void *cargo_data,
+                      EAcceptance *accept,
+                      std::string& tooltip_msg)
 {
-	BOOL handled = FALSE;
+    BOOL handled = FALSE;
 
-	// this downcast may be invalid - but if the second test below
-	// returns true, then the cast was valid, and we can perform
-	// the third test without problems.
-	LLInventoryItem* item = (LLInventoryItem*)cargo_data; 
+    // this downcast may be invalid - but if the second test below
+    // returns true, then the cast was valid, and we can perform
+    // the third test without problems.
+    LLInventoryItem* item = (LLInventoryItem*)cargo_data;
 
     bool is_mesh = cargo_type == DAD_MESH;
     bool is_texture = cargo_type == DAD_TEXTURE;
@@ -2193,66 +2193,66 @@ BOOL LLTextureCtrl::handleDragAndDrop(S32 x, S32 y, MASK mask,
         allow_dnd = is_texture || is_mesh || is_material;
     }
 
-	if (getEnabled() && allow_dnd && allowDrop(item, cargo_type, tooltip_msg))
-	{
-		if (drop)
-		{
-			if(doDrop(item))
-			{
-				if (!mCommitOnSelection)
-					mViewModel->setDirty();
+    if (getEnabled() && allow_dnd && allowDrop(item, cargo_type, tooltip_msg))
+    {
+        if (drop)
+        {
+            if(doDrop(item))
+            {
+                if (!mCommitOnSelection)
+                    mViewModel->setDirty();
 
-				// This removes the 'Multiple' overlay, since
-				// there is now only one texture selected.
-				setTentative( FALSE ); 
-				onCommit();
-			}
-		}
+                // This removes the 'Multiple' overlay, since
+                // there is now only one texture selected.
+                setTentative( FALSE );
+                onCommit();
+            }
+        }
 
-		*accept = ACCEPT_YES_SINGLE;
-	}
-	else
-	{
-		*accept = ACCEPT_NO;
-	}
+        *accept = ACCEPT_YES_SINGLE;
+    }
+    else
+    {
+        *accept = ACCEPT_NO;
+    }
 
-	handled = TRUE;
-	LL_DEBUGS("UserInput") << "dragAndDrop handled by LLTextureCtrl " << getName() << LL_ENDL;
+    handled = TRUE;
+    LL_DEBUGS("UserInput") << "dragAndDrop handled by LLTextureCtrl " << getName() << LL_ENDL;
 
-	return handled;
+    return handled;
 }
 
 void LLTextureCtrl::draw()
 {
-	mBorder->setKeyboardFocusHighlight(hasFocus());
+    mBorder->setKeyboardFocusHighlight(hasFocus());
 
     LLPointer<LLViewerTexture> preview = NULL;
 
-	if (!mValid)
-	{
-		mTexturep = NULL;
+    if (!mValid)
+    {
+        mTexturep = NULL;
         mGLTFMaterial = NULL;
         mGLTFPreview = NULL;
-	}
-	else if (!mImageAssetID.isNull())
-	{
-		if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
-		{
-			LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
-			if (obj)
-			{
-				LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(mImageAssetID);
-				mTexturep = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
-				mGLTFMaterial = NULL;
-				mGLTFPreview = NULL;
+    }
+    else if (!mImageAssetID.isNull())
+    {
+        if (LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(mImageAssetID))
+        {
+            LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
+            if (obj)
+            {
+                LLViewerTexture* viewerTexture = obj->getBakedTextureForMagicId(mImageAssetID);
+                mTexturep = viewerTexture ? dynamic_cast<LLViewerFetchedTexture*>(viewerTexture) : NULL;
+                mGLTFMaterial = NULL;
+                mGLTFPreview = NULL;
 
                 preview = mTexturep;
-			}
-			
-		}
+            }
+
+        }
 
-		if (preview.isNull())
-		{
+        if (preview.isNull())
+        {
             LLPointer<LLFetchedGLTFMaterial> old_material = mGLTFMaterial;
             mGLTFMaterial = NULL;
             mTexturep = NULL;
@@ -2280,151 +2280,151 @@ void LLTextureCtrl::draw()
             }
             else
             {
-				mTexturep = LLViewerTextureManager::getFetchedTexture(mImageAssetID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
-				mTexturep->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
-				mTexturep->forceToSaveRawImage(0);
+                mTexturep = LLViewerTextureManager::getFetchedTexture(mImageAssetID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+                mTexturep->setBoostLevel(LLGLTexture::BOOST_PREVIEW);
+                mTexturep->forceToSaveRawImage(0);
 
-				preview = mTexturep;
+                preview = mTexturep;
             }
-		}
-	}
-	else//mImageAssetID == LLUUID::null
-	{
-		mTexturep = NULL; 
+        }
+    }
+    else//mImageAssetID == LLUUID::null
+    {
+        mTexturep = NULL;
         mGLTFMaterial = NULL;
         mGLTFPreview = NULL;
-	}
-	
-	// Border
-	LLRect border( 0, getRect().getHeight(), getRect().getWidth(), BTN_HEIGHT_SMALL );
-	gl_rect_2d( border, mBorderColor.get(), FALSE );
-
-	// Interior
-	LLRect interior = border;
-	interior.stretch( -1 ); 
-
-	// If we're in a focused floater, don't apply the floater's alpha to the texture (STORM-677).
-	const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
-	if( preview )
-	{
-		if( preview->getComponents() == 4 )
-		{
-			gl_rect_2d_checkerboard( interior, alpha );
-		}
-		
-		gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), preview, UI_VERTEX_COLOR % alpha);
+    }
+
+    // Border
+    LLRect border( 0, getRect().getHeight(), getRect().getWidth(), BTN_HEIGHT_SMALL );
+    gl_rect_2d( border, mBorderColor.get(), FALSE );
+
+    // Interior
+    LLRect interior = border;
+    interior.stretch( -1 );
+
+    // If we're in a focused floater, don't apply the floater's alpha to the texture (STORM-677).
+    const F32 alpha = getTransparencyType() == TT_ACTIVE ? 1.0f : getCurrentTransparency();
+    if( preview )
+    {
+        if( preview->getComponents() == 4 )
+        {
+            gl_rect_2d_checkerboard( interior, alpha );
+        }
+
+        gl_draw_scaled_image( interior.mLeft, interior.mBottom, interior.getWidth(), interior.getHeight(), preview, UI_VERTEX_COLOR % alpha);
         preview->addTextureStats( (F32)(interior.getWidth() * interior.getHeight()) );
-	}
-	else if (!mFallbackImage.isNull())
-	{
-		mFallbackImage->draw(interior, UI_VERTEX_COLOR % alpha);
-	}
-	else
-	{
-		gl_rect_2d( interior, LLColor4::grey % alpha, TRUE );
-
-		// Draw X
-		gl_draw_x( interior, LLColor4::black );
-	}
-
-	mTentativeLabel->setVisible( getTentative() );
-
-	// Show "Loading..." string on the top left corner while this texture is loading.
-	// Using the discard level, do not show the string if the texture is almost but not 
-	// fully loaded.
-	if (mTexturep.notNull() &&
-		(!mTexturep->isFullyLoaded()) &&
-		(mShowLoadingPlaceholder == TRUE))
-	{
-		U32 v_offset = 25;
-		LLFontGL* font = LLFontGL::getFontSansSerif();
-
-		// Don't show as loaded if the texture is almost fully loaded (i.e. discard1) unless god
-		if ((mTexturep->getDiscardLevel() > 1) || gAgent.isGodlike())
-		{
-			font->renderUTF8(
-				mLoadingPlaceholderString, 
-				0,
-				llfloor(interior.mLeft+3), 
-				llfloor(interior.mTop-v_offset),
-				LLColor4::white,
-				LLFontGL::LEFT,
-				LLFontGL::BASELINE,
-				LLFontGL::DROP_SHADOW);
-		}
-
-		// Optionally show more detailed information.
-		if (ALControlCache::DebugAvatarRezTime)
-		{
-			LLFontGL* font = LLFontGL::getFontSansSerif();
-			std::string tdesc;
-			// Show what % the texture has loaded (0 to 100%, 100 is highest), and what level of detail (5 to 0, 0 is best).
-
-			v_offset += 12;
-			tdesc = llformat("  PK  : %d%%", U32(mTexturep->getDownloadProgress()*100.0));
-			font->renderUTF8(tdesc, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset),
-							 LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW);
-
-			v_offset += 12;
-			tdesc = llformat("  LVL: %d", mTexturep->getDiscardLevel());
-			font->renderUTF8(tdesc, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset),
-							 LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW);
-
-			v_offset += 12;
-			tdesc = llformat("  ID  : %s...", (mImageAssetID.asString().substr(0,7)).c_str());
-			font->renderUTF8(tdesc, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset),
-							 LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW);
-		}
-	}
-
-	LLUICtrl::draw();
+    }
+    else if (!mFallbackImage.isNull())
+    {
+        mFallbackImage->draw(interior, UI_VERTEX_COLOR % alpha);
+    }
+    else
+    {
+        gl_rect_2d( interior, LLColor4::grey % alpha, TRUE );
+
+        // Draw X
+        gl_draw_x( interior, LLColor4::black );
+    }
+
+    mTentativeLabel->setVisible( getTentative() );
+
+    // Show "Loading..." string on the top left corner while this texture is loading.
+    // Using the discard level, do not show the string if the texture is almost but not
+    // fully loaded.
+    if (mTexturep.notNull() &&
+        (!mTexturep->isFullyLoaded()) &&
+        (mShowLoadingPlaceholder == TRUE))
+    {
+        U32 v_offset = 25;
+        LLFontGL* font = LLFontGL::getFontSansSerif();
+
+        // Don't show as loaded if the texture is almost fully loaded (i.e. discard1) unless god
+        if ((mTexturep->getDiscardLevel() > 1) || gAgent.isGodlike())
+        {
+            font->renderUTF8(
+                mLoadingPlaceholderString,
+                0,
+                llfloor(interior.mLeft+3),
+                llfloor(interior.mTop-v_offset),
+                LLColor4::white,
+                LLFontGL::LEFT,
+                LLFontGL::BASELINE,
+                LLFontGL::DROP_SHADOW);
+        }
+
+        // Optionally show more detailed information.
+        if (ALControlCache::DebugAvatarRezTime)
+        {
+            LLFontGL* font = LLFontGL::getFontSansSerif();
+            std::string tdesc;
+            // Show what % the texture has loaded (0 to 100%, 100 is highest), and what level of detail (5 to 0, 0 is best).
+
+            v_offset += 12;
+            tdesc = llformat("  PK  : %d%%", U32(mTexturep->getDownloadProgress()*100.0));
+            font->renderUTF8(tdesc, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset),
+                             LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW);
+
+            v_offset += 12;
+            tdesc = llformat("  LVL: %d", mTexturep->getDiscardLevel());
+            font->renderUTF8(tdesc, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset),
+                             LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW);
+
+            v_offset += 12;
+            tdesc = llformat("  ID  : %s...", (mImageAssetID.asString().substr(0,7)).c_str());
+            font->renderUTF8(tdesc, 0, llfloor(interior.mLeft+3), llfloor(interior.mTop-v_offset),
+                             LLColor4::white, LLFontGL::LEFT, LLFontGL::BASELINE, LLFontGL::DROP_SHADOW);
+        }
+    }
+
+    LLUICtrl::draw();
 }
 
 BOOL LLTextureCtrl::allowDrop(LLInventoryItem* item, EDragAndDropType cargo_type, std::string& tooltip_msg)
 {
-	BOOL copy = item->getPermissions().allowCopyBy(gAgent.getID());
-	BOOL mod = item->getPermissions().allowModifyBy(gAgent.getID());
-	BOOL xfer = item->getPermissions().allowOperationBy(PERM_TRANSFER,
-														gAgent.getID());
-
-	PermissionMask item_perm_mask = 0;
-	if (copy) item_perm_mask |= PERM_COPY;
-	if (mod)  item_perm_mask |= PERM_MODIFY;
-	if (xfer) item_perm_mask |= PERM_TRANSFER;
-	
-	PermissionMask filter_perm_mask = mImmediateFilterPermMask;
-	if ( (item_perm_mask & filter_perm_mask) == filter_perm_mask )
-	{
-		if(mDragCallback)
-		{
-			return mDragCallback(this, item);
-		}
-		else
-		{
-			return TRUE;
-		}
-	}
-	else
-	{
+    BOOL copy = item->getPermissions().allowCopyBy(gAgent.getID());
+    BOOL mod = item->getPermissions().allowModifyBy(gAgent.getID());
+    BOOL xfer = item->getPermissions().allowOperationBy(PERM_TRANSFER,
+                                                        gAgent.getID());
+
+    PermissionMask item_perm_mask = 0;
+    if (copy) item_perm_mask |= PERM_COPY;
+    if (mod)  item_perm_mask |= PERM_MODIFY;
+    if (xfer) item_perm_mask |= PERM_TRANSFER;
+
+    PermissionMask filter_perm_mask = mImmediateFilterPermMask;
+    if ( (item_perm_mask & filter_perm_mask) == filter_perm_mask )
+    {
+        if(mDragCallback)
+        {
+            return mDragCallback(this, item);
+        }
+        else
+        {
+            return TRUE;
+        }
+    }
+    else
+    {
         PermissionMask mask = PERM_COPY | PERM_TRANSFER;
         if ((filter_perm_mask & mask) == mask
             && cargo_type == DAD_TEXTURE)
         {
             tooltip_msg.assign(LLTrans::getString("TooltipTextureRestrictedDrop"));
         }
-		return FALSE;
-	}
+        return FALSE;
+    }
 }
 
 BOOL LLTextureCtrl::doDrop(LLInventoryItem* item)
 {
-	// call the callback if it exists.
-	if(mDropCallback)
-	{
-		// if it returns TRUE, we return TRUE, and therefore the
-		// commit is called above.
-		return mDropCallback(this, item);
-	}
+    // call the callback if it exists.
+    if(mDropCallback)
+    {
+        // if it returns TRUE, we return TRUE, and therefore the
+        // commit is called above.
+        return mDropCallback(this, item);
+    }
 
     // no callback installed, so just set the image ids and carry on.
     LLUUID asset_id = item->getAssetUUID();
@@ -2435,29 +2435,29 @@ BOOL LLTextureCtrl::doDrop(LLInventoryItem* item)
         asset_id = BLANK_MATERIAL_ASSET_ID;
     }
 
-	setImageAssetID(asset_id);
-	mImageItemID = item->getUUID();
-	return TRUE;
+    setImageAssetID(asset_id);
+    mImageItemID = item->getUUID();
+    return TRUE;
 }
 
 BOOL LLTextureCtrl::handleUnicodeCharHere(llwchar uni_char)
 {
-	if( ' ' == uni_char )
-	{
-		showPicker(TRUE);
-		return TRUE;
-	}
-	return LLUICtrl::handleUnicodeCharHere(uni_char);
+    if( ' ' == uni_char )
+    {
+        showPicker(TRUE);
+        return TRUE;
+    }
+    return LLUICtrl::handleUnicodeCharHere(uni_char);
 }
 
 void LLTextureCtrl::setValue( const LLSD& value )
 {
-	setImageAssetID(value.asUUID());
+    setImageAssetID(value.asUUID());
 }
 
 LLSD LLTextureCtrl::getValue() const
 {
-	return LLSD(getImageAssetID());
+    return LLSD(getImageAssetID());
 }
 
 namespace LLInitParam
diff --git a/indra/newview/lltexturectrl.h b/indra/newview/lltexturectrl.h
index 92678a2fa792309f5caec2ec9b6a67f7730fc4c7..04422e740337bea149ff7d37eca7838a2aa76011 100644
--- a/indra/newview/lltexturectrl.h
+++ b/indra/newview/lltexturectrl.h
@@ -1,5 +1,5 @@
 
-/** 
+/**
  * @file lltexturectrl.h
  * @author Richard Nelson, James Cook
  * @brief LLTextureCtrl class header file including related functions
@@ -7,21 +7,21 @@
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -74,10 +74,10 @@ typedef enum e_pick_inventory_type
 namespace LLInitParam
 {
     template<>
-	struct TypeValues<EPickInventoryType> : public TypeValuesHelper<EPickInventoryType>
-	{
-		static void declareValues();
-	};
+    struct TypeValues<EPickInventoryType> : public TypeValuesHelper<EPickInventoryType>
+    {
+        static void declareValues();
+    };
 }
 
 enum LLPickerSource
@@ -96,56 +96,56 @@ class LLTextureCtrl
 : public LLUICtrl
 {
 public:
-	typedef enum e_texture_pick_op
-	{
-		TEXTURE_CHANGE,
-		TEXTURE_SELECT,
-		TEXTURE_CANCEL
-	} ETexturePickOp;
+    typedef enum e_texture_pick_op
+    {
+        TEXTURE_CHANGE,
+        TEXTURE_SELECT,
+        TEXTURE_CANCEL
+    } ETexturePickOp;
 
 public:
-	struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
-	{
-		Optional<LLUUID>		image_id;
-		Optional<LLUUID>		default_image_id;
-		Optional<std::string>	default_image_name;
+    struct Params : public LLInitParam::Block<Params, LLUICtrl::Params>
+    {
+        Optional<LLUUID>        image_id;
+        Optional<LLUUID>        default_image_id;
+        Optional<std::string>   default_image_name;
         Optional<EPickInventoryType> pick_type;
-		Optional<bool>			allow_no_texture;
-		Optional<bool>			can_apply_immediately;
-		Optional<bool>			no_commit_on_selection; // alternative mode: commit occurs and the widget gets dirty
-														// only on DnD or when OK is pressed in the picker
-		Optional<S32>			label_width;
-		Optional<LLUIColor>		border_color;
-		Optional<LLUIImage*>	fallback_image;
-		
-		Optional<LLTextBox::Params>	multiselect_text,
-									caption_text;
-
-		Optional<LLViewBorder::Params> border;
-
-		Params()
-		:	image_id("image"),
-			default_image_id("default_image_id"),
-			default_image_name("default_image_name"),
+        Optional<bool>          allow_no_texture;
+        Optional<bool>          can_apply_immediately;
+        Optional<bool>          no_commit_on_selection; // alternative mode: commit occurs and the widget gets dirty
+                                                        // only on DnD or when OK is pressed in the picker
+        Optional<S32>           label_width;
+        Optional<LLUIColor>     border_color;
+        Optional<LLUIImage*>    fallback_image;
+
+        Optional<LLTextBox::Params> multiselect_text,
+                                    caption_text;
+
+        Optional<LLViewBorder::Params> border;
+
+        Params()
+        :   image_id("image"),
+            default_image_id("default_image_id"),
+            default_image_name("default_image_name"),
             pick_type("pick_type", PICK_TEXTURE),
-			allow_no_texture("allow_no_texture", false),
-			can_apply_immediately("can_apply_immediately"),
-			no_commit_on_selection("no_commit_on_selection", false),
-		    label_width("label_width", -1),
-			border_color("border_color"),
-			fallback_image("fallback_image"),
-			multiselect_text("multiselect_text"),
-			caption_text("caption_text"),
-			border("border")
-		{}
-	};
+            allow_no_texture("allow_no_texture", false),
+            can_apply_immediately("can_apply_immediately"),
+            no_commit_on_selection("no_commit_on_selection", false),
+            label_width("label_width", -1),
+            border_color("border_color"),
+            fallback_image("fallback_image"),
+            multiselect_text("multiselect_text"),
+            caption_text("caption_text"),
+            border("border")
+        {}
+    };
 protected:
-	LLTextureCtrl(const Params&);
-	friend class LLUICtrlFactory;
+    LLTextureCtrl(const Params&);
+    friend class LLUICtrlFactory;
 public:
-	virtual ~LLTextureCtrl();
+    virtual ~LLTextureCtrl();
 
-	// LLView interface
+    // LLView interface
 
     BOOL handleMouseDown(S32 x, S32 y, MASK mask) override;
     BOOL handleDragAndDrop(S32 x, S32 y, MASK mask,
@@ -170,80 +170,80 @@ class LLTextureCtrl
     void setValue(const LLSD& value) override;
     LLSD getValue() const override;
 
-	// LLTextureCtrl interface
-	void			showPicker(BOOL take_focus);
-	bool			isPickerShown() { return !mFloaterHandle.isDead(); }
-	void			setLabel(const std::string& label);
-	void			setLabelWidth(S32 label_width) {mLabelWidth =label_width;}	
-	const std::string&	getLabel() const							{ return mLabel; }
+    // LLTextureCtrl interface
+    void            showPicker(BOOL take_focus);
+    bool            isPickerShown() { return !mFloaterHandle.isDead(); }
+    void            setLabel(const std::string& label);
+    void            setLabelWidth(S32 label_width) {mLabelWidth =label_width;}
+    const std::string&  getLabel() const                            { return mLabel; }
 
-	void			setAllowNoTexture( BOOL b )					{ mAllowNoTexture = b; }
-	bool			getAllowNoTexture() const					{ return mAllowNoTexture; }
+    void            setAllowNoTexture( BOOL b )                 { mAllowNoTexture = b; }
+    bool            getAllowNoTexture() const                   { return mAllowNoTexture; }
 
-	void			setAllowLocalTexture(BOOL b)					{ mAllowLocalTexture = b; }
-	BOOL			getAllowLocalTexture() const					{ return mAllowLocalTexture; }
+    void            setAllowLocalTexture(BOOL b)                    { mAllowLocalTexture = b; }
+    BOOL            getAllowLocalTexture() const                    { return mAllowLocalTexture; }
 
-	const LLUUID&	getImageItemID() { return mImageItemID; }
+    const LLUUID&   getImageItemID() { return mImageItemID; }
 
-	virtual void	setImageAssetName(const std::string& name);
-	
-	void			setImageAssetID(const LLUUID &image_asset_id);
-	const LLUUID&	getImageAssetID() const						{ return mImageAssetID; }
+    virtual void    setImageAssetName(const std::string& name);
 
-	void			setDefaultImageAssetID( const LLUUID& id )	{ mDefaultImageAssetID = id; }
-	const LLUUID&	getDefaultImageAssetID() const { return mDefaultImageAssetID; }
+    void            setImageAssetID(const LLUUID &image_asset_id);
+    const LLUUID&   getImageAssetID() const                     { return mImageAssetID; }
 
-	const std::string&	getDefaultImageName() const					{ return mDefaultImageName; }
+    void            setDefaultImageAssetID( const LLUUID& id )  { mDefaultImageAssetID = id; }
+    const LLUUID&   getDefaultImageAssetID() const { return mDefaultImageAssetID; }
 
-	void			setBlankImageAssetID( const LLUUID& id )	{ mBlankImageAssetID = id; }
-	const LLUUID&	getBlankImageAssetID() const { return mBlankImageAssetID; }
+    const std::string&  getDefaultImageName() const                 { return mDefaultImageName; }
 
-	void			setOpenTexPreview(bool open_preview) { mOpenTexPreview = open_preview; }
+    void            setBlankImageAssetID( const LLUUID& id )    { mBlankImageAssetID = id; }
+    const LLUUID&   getBlankImageAssetID() const { return mBlankImageAssetID; }
 
-	void			setTransparentImageAssetID( const LLUUID& id )	{ mTransparentImageAssetID = id; }
-	const LLUUID&	getTransparentImageAssetID() const { return mTransparentImageAssetID; }
+    void            setOpenTexPreview(bool open_preview) { mOpenTexPreview = open_preview; }
 
-	void			setCaption(const std::string& caption);
-	void			setCanApplyImmediately(BOOL b);
+    void            setTransparentImageAssetID( const LLUUID& id )  { mTransparentImageAssetID = id; }
+    const LLUUID&   getTransparentImageAssetID() const { return mTransparentImageAssetID; }
 
-	void			setCanApply(bool can_preview, bool can_apply);
+    void            setCaption(const std::string& caption);
+    void            setCanApplyImmediately(BOOL b);
 
-	void			setImmediateFilterPermMask(PermissionMask mask);
-	void			setDnDFilterPermMask(PermissionMask mask)
-						{ mDnDFilterPermMask = mask; }
-	PermissionMask	getImmediateFilterPermMask() { return mImmediateFilterPermMask; }
+    void            setCanApply(bool can_preview, bool can_apply);
+
+    void            setImmediateFilterPermMask(PermissionMask mask);
+    void            setDnDFilterPermMask(PermissionMask mask)
+                        { mDnDFilterPermMask = mask; }
+    PermissionMask  getImmediateFilterPermMask() { return mImmediateFilterPermMask; }
     void setFilterPermissionMasks(PermissionMask mask);
 
-	void			closeDependentFloater();
+    void            closeDependentFloater();
 
-	void			onFloaterClose();
-    void			onFloaterCommit(ETexturePickOp op,
+    void            onFloaterClose();
+    void            onFloaterCommit(ETexturePickOp op,
                                     LLPickerSource source,
                                     const LLUUID& local_id,
                                     const LLUUID& inv_id,
                                     const LLUUID& tracking_id);
 
-	// This call is returned when a drag is detected. Your callback
-	// should return TRUE if the drag is acceptable.
-	void setDragCallback(drag_n_drop_callback cb)	{ mDragCallback = cb; }
+    // This call is returned when a drag is detected. Your callback
+    // should return TRUE if the drag is acceptable.
+    void setDragCallback(drag_n_drop_callback cb)   { mDragCallback = cb; }
+
+    // This callback is called when the drop happens. Return TRUE if
+    // the drop happened - resulting in an on commit callback, but not
+    // necessariliy any other change.
+    void setDropCallback(drag_n_drop_callback cb)   { mDropCallback = cb; }
 
-	// This callback is called when the drop happens. Return TRUE if
-	// the drop happened - resulting in an on commit callback, but not
-	// necessariliy any other change.
-	void setDropCallback(drag_n_drop_callback cb)	{ mDropCallback = cb; }
-	
-	void setOnCancelCallback(commit_callback_t cb)	{ mOnCancelCallback = cb; }
-	void setOnCloseCallback(commit_callback_t cb)	{ mOnCloseCallback = cb; }
-	void setOnSelectCallback(commit_callback_t cb)	{ mOnSelectCallback = cb; }
+    void setOnCancelCallback(commit_callback_t cb)  { mOnCancelCallback = cb; }
+    void setOnCloseCallback(commit_callback_t cb)   { mOnCloseCallback = cb; }
+    void setOnSelectCallback(commit_callback_t cb)  { mOnSelectCallback = cb; }
 
-	/*
-	 * callback for changing texture selection in inventory list of texture floater
-	 */
-	void setOnTextureSelectedCallback(texture_selected_callback cb);
+    /*
+     * callback for changing texture selection in inventory list of texture floater
+     */
+    void setOnTextureSelectedCallback(texture_selected_callback cb);
 
-	void setShowLoadingPlaceholder(BOOL showLoadingPlaceholder);
+    void setShowLoadingPlaceholder(BOOL showLoadingPlaceholder);
 
-	LLViewerFetchedTexture* getTexture() { return mTexturep; }
+    LLViewerFetchedTexture* getTexture() { return mTexturep; }
 
     void setBakeTextureEnabled(bool enabled);
     bool getBakeTextureEnabled() const { return mBakeTextureEnabled; }
@@ -255,46 +255,46 @@ class LLTextureCtrl
     LLUUID getLocalTrackingID() { return mLocalTrackingID; }
 
 private:
-	BOOL allowDrop(LLInventoryItem* item, EDragAndDropType cargo_type, std::string& tooltip_msg);
-	BOOL doDrop(LLInventoryItem* item);
+    BOOL allowDrop(LLInventoryItem* item, EDragAndDropType cargo_type, std::string& tooltip_msg);
+    BOOL doDrop(LLInventoryItem* item);
 
 private:
-	drag_n_drop_callback	 	mDragCallback;
-	drag_n_drop_callback	 	mDropCallback;
-	commit_callback_t		 	mOnCancelCallback;
-	commit_callback_t		 	mOnSelectCallback;
-	commit_callback_t		 	mOnCloseCallback;
-	texture_selected_callback	mOnTextureSelectedCallback;
-	LLPointer<LLViewerFetchedTexture> mTexturep;
-	LLPointer<LLFetchedGLTFMaterial> mGLTFMaterial;
-	LLPointer<LLViewerTexture> mGLTFPreview;
-	LLUIColor				 	mBorderColor;
-	LLUUID					 	mImageItemID;
-	LLUUID					 	mImageAssetID;
-	LLUUID					 	mDefaultImageAssetID;
-	LLUUID					 	mBlankImageAssetID;
-	LLUUID					 	mTransparentImageAssetID;
-    LLUUID						mLocalTrackingID;
-	LLUIImagePtr				mFallbackImage;
-	std::string					mDefaultImageName;
-	LLHandle<LLFloater>			mFloaterHandle;
-	LLTextBox*				 	mTentativeLabel;
-	LLTextBox*				 	mCaption;
-	std::string				 	mLabel;
-	BOOL					 	mAllowNoTexture; // If true, the user can select "none" as an option
-	BOOL						mAllowLocalTexture;
-	PermissionMask			 	mImmediateFilterPermMask;
-	PermissionMask				mDnDFilterPermMask;
-	BOOL					 	mCanApplyImmediately;
-	BOOL					 	mCommitOnSelection;
-	BOOL					 	mNeedsRawImageData;
-	LLViewBorder*			 	mBorder;
-	BOOL					 	mValid;
-	BOOL					 	mShowLoadingPlaceholder;
-	std::string				 	mLoadingPlaceholderString;
-	S32						 	mLabelWidth;
-	bool						mOpenTexPreview;
-	bool						mBakeTextureEnabled;
+    drag_n_drop_callback        mDragCallback;
+    drag_n_drop_callback        mDropCallback;
+    commit_callback_t           mOnCancelCallback;
+    commit_callback_t           mOnSelectCallback;
+    commit_callback_t           mOnCloseCallback;
+    texture_selected_callback   mOnTextureSelectedCallback;
+    LLPointer<LLViewerFetchedTexture> mTexturep;
+    LLPointer<LLFetchedGLTFMaterial> mGLTFMaterial;
+    LLPointer<LLViewerTexture> mGLTFPreview;
+    LLUIColor                   mBorderColor;
+    LLUUID                      mImageItemID;
+    LLUUID                      mImageAssetID;
+    LLUUID                      mDefaultImageAssetID;
+    LLUUID                      mBlankImageAssetID;
+    LLUUID                      mTransparentImageAssetID;
+    LLUUID                      mLocalTrackingID;
+    LLUIImagePtr                mFallbackImage;
+    std::string                 mDefaultImageName;
+    LLHandle<LLFloater>         mFloaterHandle;
+    LLTextBox*                  mTentativeLabel;
+    LLTextBox*                  mCaption;
+    std::string                 mLabel;
+    BOOL                        mAllowNoTexture; // If true, the user can select "none" as an option
+    BOOL                        mAllowLocalTexture;
+    PermissionMask              mImmediateFilterPermMask;
+    PermissionMask              mDnDFilterPermMask;
+    BOOL                        mCanApplyImmediately;
+    BOOL                        mCommitOnSelection;
+    BOOL                        mNeedsRawImageData;
+    LLViewBorder*               mBorder;
+    BOOL                        mValid;
+    BOOL                        mShowLoadingPlaceholder;
+    std::string                 mLoadingPlaceholderString;
+    S32                         mLabelWidth;
+    bool                        mOpenTexPreview;
+    bool                        mBakeTextureEnabled;
     EPickInventoryType mInventoryPickType;
 };
 
@@ -308,94 +308,94 @@ typedef std::function<void(LLPointer<LLViewerTexture> texture)> set_on_update_im
 class LLFloaterTexturePicker final : public LLFloater
 {
 public:
-	LLFloaterTexturePicker(
-		LLView* owner,
-		LLUUID image_asset_id,
-		LLUUID default_image_asset_id,
-		LLUUID transparent_image_asset_id,
-		LLUUID blank_image_asset_id,
-		BOOL tentative,
-		BOOL allow_no_texture,
-		const std::string& label,
-		PermissionMask immediate_filter_perm_mask,
-		PermissionMask dnd_filter_perm_mask,
-		BOOL can_apply_immediately,
-		LLUIImagePtr fallback_image_name,
-		EPickInventoryType pick_type);
-
-	virtual ~LLFloaterTexturePicker();
-
-	// LLView overrides
-	/*virtual*/ BOOL	handleDragAndDrop(S32 x, S32 y, MASK mask,
-		BOOL drop, EDragAndDropType cargo_type, void *cargo_data,
-		EAcceptance *accept,
-		std::string& tooltip_msg);
-	/*virtual*/ void	draw();
-	/*virtual*/ BOOL	handleKeyHere(KEY key, MASK mask);
-
-	// LLFloater overrides
-	/*virtual*/ BOOL    postBuild();
-    /*virtual*/ void	onOpen(const LLSD& key);
-	/*virtual*/ void	onClose(bool app_settings);
-
-	// New functions
-	void setImageID(const LLUUID& image_asset_id, bool set_selection = true);
-	bool updateImageStats(); // true if within limits
-	const LLUUID&	getAssetID() { return mImageAssetID; }
-	const LLUUID&	findItemID(const LLUUID& asset_id, BOOL copyable_only, BOOL ignore_library = FALSE);
-	void			setCanApplyImmediately(BOOL b);
-
-	void			setActive(BOOL active);
-
-	LLView*			getOwner() const { return mOwner; }
-	void			setOwner(LLView* owner) { mOwner = owner; }
-	void			stopUsingPipette();
-
-	void commitIfImmediateSet();
+    LLFloaterTexturePicker(
+        LLView* owner,
+        LLUUID image_asset_id,
+        LLUUID default_image_asset_id,
+        LLUUID transparent_image_asset_id,
+        LLUUID blank_image_asset_id,
+        BOOL tentative,
+        BOOL allow_no_texture,
+        const std::string& label,
+        PermissionMask immediate_filter_perm_mask,
+        PermissionMask dnd_filter_perm_mask,
+        BOOL can_apply_immediately,
+        LLUIImagePtr fallback_image_name,
+        EPickInventoryType pick_type);
+
+    virtual ~LLFloaterTexturePicker();
+
+    // LLView overrides
+    /*virtual*/ BOOL    handleDragAndDrop(S32 x, S32 y, MASK mask,
+        BOOL drop, EDragAndDropType cargo_type, void *cargo_data,
+        EAcceptance *accept,
+        std::string& tooltip_msg);
+    /*virtual*/ void    draw();
+    /*virtual*/ BOOL    handleKeyHere(KEY key, MASK mask);
+
+    // LLFloater overrides
+    /*virtual*/ BOOL    postBuild();
+    /*virtual*/ void    onOpen(const LLSD& key);
+    /*virtual*/ void    onClose(bool app_settings);
+
+    // New functions
+    void setImageID(const LLUUID& image_asset_id, bool set_selection = true);
+    bool updateImageStats(); // true if within limits
+    const LLUUID&   getAssetID() { return mImageAssetID; }
+    const LLUUID&   findItemID(const LLUUID& asset_id, BOOL copyable_only, BOOL ignore_library = FALSE);
+    void            setCanApplyImmediately(BOOL b);
+
+    void            setActive(BOOL active);
+
+    LLView*         getOwner() const { return mOwner; }
+    void            setOwner(LLView* owner) { mOwner = owner; }
+    void            stopUsingPipette();
+
+    void commitIfImmediateSet();
     void commitCallback(LLTextureCtrl::ETexturePickOp op);
-	void commitCancel();
+    void commitCancel();
 
-	void onFilterEdit(const std::string& search_string);
+    void onFilterEdit(const std::string& search_string);
 
-	void setCanApply(bool can_preview, bool can_apply, bool inworld_image = true);
+    void setCanApply(bool can_preview, bool can_apply, bool inworld_image = true);
     void setMinDimentionsLimits(S32 min_dim);
-	void setTextureSelectedCallback(const texture_selected_callback& cb) { mTextureSelectedCallback = cb; }
-	void setOnFloaterCloseCallback(const floater_close_callback& cb) { mOnFloaterCloseCallback = cb; }
-	void setOnFloaterCommitCallback(const floater_commit_callback& cb) { mOnFloaterCommitCallback = cb; }
-	void setSetImageAssetIDCallback(const set_image_asset_id_callback& cb) { mSetImageAssetIDCallback = cb; }
-	void setOnUpdateImageStatsCallback(const set_on_update_image_stats_callback& cb) { mOnUpdateImageStatsCallback = cb; }
-	const LLUUID& getDefaultImageAssetID() { return mDefaultImageAssetID; }
+    void setTextureSelectedCallback(const texture_selected_callback& cb) { mTextureSelectedCallback = cb; }
+    void setOnFloaterCloseCallback(const floater_close_callback& cb) { mOnFloaterCloseCallback = cb; }
+    void setOnFloaterCommitCallback(const floater_commit_callback& cb) { mOnFloaterCommitCallback = cb; }
+    void setSetImageAssetIDCallback(const set_image_asset_id_callback& cb) { mSetImageAssetIDCallback = cb; }
+    void setOnUpdateImageStatsCallback(const set_on_update_image_stats_callback& cb) { mOnUpdateImageStatsCallback = cb; }
+    const LLUUID& getDefaultImageAssetID() { return mDefaultImageAssetID; }
     const LLUUID& getTransparentImageAssetID() { return mTransparentImageAssetID; }
-	const LLUUID& getBlankImageAssetID() { return mBlankImageAssetID; }
-
-	static void		onBtnSetToDefault(void* userdata);
-	static void		onBtnSelect(void* userdata);
-	static void		onBtnCancel(void* userdata);
-	void			onBtnPipette();
-	//static void		onBtnRevert( void* userdata );
-    static void		onBtnTransparent(void* userdata);
-	static void		onBtnBlank(void* userdata);
-	static void		onBtnNone(void* userdata);
-    static void		onApplyUUID(void* userdata);
-	void			onSelectionChange(const std::deque<LLFolderViewItem*> &items, BOOL user_action);
-	static void		onApplyImmediateCheck(LLUICtrl* ctrl, void* userdata);
-	void			onTextureSelect(bool success, const LLTextureEntry& te);
-
-	static void		onModeSelect(LLUICtrl* ctrl, void *userdata);
-	static void		onBtnAdd(void* userdata);
-	static void		onBtnRemove(void* userdata);
-	static void		onBtnUpload(void* userdata);
-	static void		onLocalScrollCommit(LLUICtrl* ctrl, void* userdata);
-
-	static void		onBakeTextureSelect(LLUICtrl* ctrl, void *userdata);
-
-	void 			setLocalTextureEnabled(BOOL enabled);
-	void 			setBakeTextureEnabled(BOOL enabled);
+    const LLUUID& getBlankImageAssetID() { return mBlankImageAssetID; }
+
+    static void     onBtnSetToDefault(void* userdata);
+    static void     onBtnSelect(void* userdata);
+    static void     onBtnCancel(void* userdata);
+    void            onBtnPipette();
+    //static void       onBtnRevert( void* userdata );
+    static void     onBtnTransparent(void* userdata);
+    static void     onBtnBlank(void* userdata);
+    static void     onBtnNone(void* userdata);
+    static void     onApplyUUID(void* userdata);
+    void            onSelectionChange(const std::deque<LLFolderViewItem*> &items, BOOL user_action);
+    static void     onApplyImmediateCheck(LLUICtrl* ctrl, void* userdata);
+    void            onTextureSelect(bool success, const LLTextureEntry& te);
+
+    static void     onModeSelect(LLUICtrl* ctrl, void *userdata);
+    static void     onBtnAdd(void* userdata);
+    static void     onBtnRemove(void* userdata);
+    static void     onBtnUpload(void* userdata);
+    static void     onLocalScrollCommit(LLUICtrl* ctrl, void* userdata);
+
+    static void     onBakeTextureSelect(LLUICtrl* ctrl, void *userdata);
+
+    void            setLocalTextureEnabled(BOOL enabled);
+    void            setBakeTextureEnabled(BOOL enabled);
 
     void setInventoryPickType(EPickInventoryType type);
     void setImmediateFilterPermMask(PermissionMask mask);
 
-    static void		onPickerCallback(const std::vector<std::string>& filenames, LLHandle<LLFloater> handle);
+    static void     onPickerCallback(const std::vector<std::string>& filenames, LLHandle<LLFloater> handle);
 
 protected:
     void changeMode();
@@ -403,67 +403,67 @@ class LLFloaterTexturePicker final : public LLFloater
     void refreshInventoryFilter();
     void setImageIDFromItem(const LLInventoryItem* itemp, bool set_selection = true);
 
-	LLPointer<LLViewerTexture> mTexturep;
+    LLPointer<LLViewerTexture> mTexturep;
     LLPointer<LLFetchedGLTFMaterial> mGLTFMaterial;
     LLPointer<LLViewerTexture> mGLTFPreview;
-	LLView*				mOwner;
-
-	LLUUID				mImageAssetID; // Currently selected texture
-	LLUIImagePtr		mFallbackImage; // What to show if currently selected texture is null.
-	LLUUID				mDefaultImageAssetID;
-    LLUUID				mTransparentImageAssetID;
-	LLUUID				mBlankImageAssetID;
-	BOOL				mTentative;
-	BOOL				mAllowNoTexture;
-	LLUUID				mSpecialCurrentImageAssetID;  // Used when the asset id has no corresponding texture in the user's inventory.
-	LLUUID				mOriginalImageAssetID;
-
-	std::string			mLabel;
-
-	LLTextBox*			mTentativeLabel;
-	LLTextBox*			mResolutionLabel;
+    LLView*             mOwner;
+
+    LLUUID              mImageAssetID; // Currently selected texture
+    LLUIImagePtr        mFallbackImage; // What to show if currently selected texture is null.
+    LLUUID              mDefaultImageAssetID;
+    LLUUID              mTransparentImageAssetID;
+    LLUUID              mBlankImageAssetID;
+    BOOL                mTentative;
+    BOOL                mAllowNoTexture;
+    LLUUID              mSpecialCurrentImageAssetID;  // Used when the asset id has no corresponding texture in the user's inventory.
+    LLUUID              mOriginalImageAssetID;
+
+    std::string         mLabel;
+
+    LLTextBox*          mTentativeLabel;
+    LLTextBox*          mResolutionLabel;
     LLTextBox*          mResolutionWarning;
 
-	std::string			mPendingName;
-	BOOL				mActive;
-
-	LLFilterEditor*		mFilterEdit;
-	LLInventoryPanel*	mInventoryPanel;
-	PermissionMask		mImmediateFilterPermMask;
-	PermissionMask		mDnDFilterPermMask;
-	BOOL				mCanApplyImmediately;
-	BOOL				mNoCopyTextureSelected;
-	F32					mContextConeOpacity;
-	LLSaveFolderState	mSavedFolderState;
-	BOOL				mSelectedItemPinned;
-
-	LLComboBox*			mModeSelector;
-	LLScrollListCtrl*	mLocalScrollCtrl;
+    std::string         mPendingName;
+    BOOL                mActive;
+
+    LLFilterEditor*     mFilterEdit;
+    LLInventoryPanel*   mInventoryPanel;
+    PermissionMask      mImmediateFilterPermMask;
+    PermissionMask      mDnDFilterPermMask;
+    BOOL                mCanApplyImmediately;
+    BOOL                mNoCopyTextureSelected;
+    F32                 mContextConeOpacity;
+    LLSaveFolderState   mSavedFolderState;
+    BOOL                mSelectedItemPinned;
+
+    LLComboBox*         mModeSelector;
+    LLScrollListCtrl*   mLocalScrollCtrl;
     LLButton*           mDefaultBtn;
     LLButton*           mNoneBtn;
     LLButton*           mBlankBtn;
-	LLButton*			mTransparentBtn;
+    LLButton*           mTransparentBtn;
     LLButton*           mPipetteBtn;
     LLButton*           mSelectBtn;
     LLButton*           mCancelBtn;
 
 private:
-	bool mCanApply;
-	bool mCanPreview;
-	bool mPreviewSettingChanged;
+    bool mCanApply;
+    bool mCanPreview;
+    bool mPreviewSettingChanged;
     bool mLimitsSet;
     S32 mMaxDim;
     S32 mMinDim;
     EPickInventoryType mInventoryPickType;
 
 
-	texture_selected_callback mTextureSelectedCallback;
-	floater_close_callback mOnFloaterCloseCallback;
-	floater_commit_callback mOnFloaterCommitCallback;
-	set_image_asset_id_callback mSetImageAssetIDCallback;
-	set_on_update_image_stats_callback mOnUpdateImageStatsCallback;
+    texture_selected_callback mTextureSelectedCallback;
+    floater_close_callback mOnFloaterCloseCallback;
+    floater_commit_callback mOnFloaterCommitCallback;
+    set_image_asset_id_callback mSetImageAssetIDCallback;
+    set_on_update_image_stats_callback mOnUpdateImageStatsCallback;
 
-	BOOL mBakeTextureEnabled;
+    BOOL mBakeTextureEnabled;
 
     static S32 sLastPickerMode;
 };
diff --git a/indra/newview/lltooldraganddrop.cpp b/indra/newview/lltooldraganddrop.cpp
index e4e7f06034e45bff93e440b46510fb1246a0a9e6..946483ff7702956d8fc26ce3d5a39a3cb655cbde 100644
--- a/indra/newview/lltooldraganddrop.cpp
+++ b/indra/newview/lltooldraganddrop.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lltooldraganddrop.cpp
  * @brief LLToolDragAndDrop class implementation
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -73,1125 +73,1125 @@
 class LLNoPreferredType : public LLInventoryCollectFunctor
 {
 public:
-	LLNoPreferredType() {}
-	virtual ~LLNoPreferredType() {}
-	virtual bool operator()(LLInventoryCategory* cat,
-							LLInventoryItem* item)
-	{
-		if (cat && (cat->getPreferredType() == LLFolderType::FT_NONE))
-		{
-			return true;
-		}
-		return false;
-	}
+    LLNoPreferredType() {}
+    virtual ~LLNoPreferredType() {}
+    virtual bool operator()(LLInventoryCategory* cat,
+                            LLInventoryItem* item)
+    {
+        if (cat && (cat->getPreferredType() == LLFolderType::FT_NONE))
+        {
+            return true;
+        }
+        return false;
+    }
 };
 
 class LLNoPreferredTypeOrItem : public LLInventoryCollectFunctor
 {
 public:
-	LLNoPreferredTypeOrItem() {}
-	virtual ~LLNoPreferredTypeOrItem() {}
-	virtual bool operator()(LLInventoryCategory* cat,
-							LLInventoryItem* item)
-	{
-		if (item) return true;
-		if (cat && (cat->getPreferredType() == LLFolderType::FT_NONE))
-		{
-			return true;
-		}
-		return false;
-	}
+    LLNoPreferredTypeOrItem() {}
+    virtual ~LLNoPreferredTypeOrItem() {}
+    virtual bool operator()(LLInventoryCategory* cat,
+                            LLInventoryItem* item)
+    {
+        if (item) return true;
+        if (cat && (cat->getPreferredType() == LLFolderType::FT_NONE))
+        {
+            return true;
+        }
+        return false;
+    }
 };
 
 class LLDroppableItem : public LLInventoryCollectFunctor
 {
 public:
-	LLDroppableItem(BOOL is_transfer) :
-		mCountLosing(0), mIsTransfer(is_transfer) {}
-	virtual ~LLDroppableItem() {}
-	virtual bool operator()(LLInventoryCategory* cat,
-							LLInventoryItem* item);
-	S32 countNoCopy() const { return mCountLosing; }
+    LLDroppableItem(BOOL is_transfer) :
+        mCountLosing(0), mIsTransfer(is_transfer) {}
+    virtual ~LLDroppableItem() {}
+    virtual bool operator()(LLInventoryCategory* cat,
+                            LLInventoryItem* item);
+    S32 countNoCopy() const { return mCountLosing; }
 
 protected:
-	S32 mCountLosing;
-	BOOL mIsTransfer;
+    S32 mCountLosing;
+    BOOL mIsTransfer;
 };
 
 bool LLDroppableItem::operator()(LLInventoryCategory* cat,
-				 LLInventoryItem* item)
-{
-	bool allowed = false;
-	if (item)
-	{
-		allowed = itemTransferCommonlyAllowed(item);
-
-		if (allowed
-		   && mIsTransfer
-		   && !item->getPermissions().allowOperationBy(PERM_TRANSFER,
-							       gAgent.getID()))
-		{
-			allowed = false;
-		}
-		if (allowed && !item->getPermissions().allowCopyBy(gAgent.getID()))
-		{
-			++mCountLosing;
-		}
-	}
-	return allowed;
+                 LLInventoryItem* item)
+{
+    bool allowed = false;
+    if (item)
+    {
+        allowed = itemTransferCommonlyAllowed(item);
+
+        if (allowed
+           && mIsTransfer
+           && !item->getPermissions().allowOperationBy(PERM_TRANSFER,
+                                   gAgent.getID()))
+        {
+            allowed = false;
+        }
+        if (allowed && !item->getPermissions().allowCopyBy(gAgent.getID()))
+        {
+            ++mCountLosing;
+        }
+    }
+    return allowed;
 }
 
 class LLDropCopyableItems : public LLInventoryCollectFunctor
 {
 public:
-	LLDropCopyableItems() {}
-	virtual ~LLDropCopyableItems() {}
-	virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item);
+    LLDropCopyableItems() {}
+    virtual ~LLDropCopyableItems() {}
+    virtual bool operator()(LLInventoryCategory* cat, LLInventoryItem* item);
 };
 
 
 bool LLDropCopyableItems::operator()(
-	LLInventoryCategory* cat,
-	LLInventoryItem* item)
-{
-	bool allowed = false;
-	if (item)
-	{
-		allowed = itemTransferCommonlyAllowed(item);
-		if (allowed &&
-		   !item->getPermissions().allowCopyBy(gAgent.getID()))
-		{
-			// whoops, can't copy it - don't allow it.
-			allowed = false;
-		}
-	}
-	return allowed;
-}
-
-// Starts a fetch on folders and items.  This is really not used 
+    LLInventoryCategory* cat,
+    LLInventoryItem* item)
+{
+    bool allowed = false;
+    if (item)
+    {
+        allowed = itemTransferCommonlyAllowed(item);
+        if (allowed &&
+           !item->getPermissions().allowCopyBy(gAgent.getID()))
+        {
+            // whoops, can't copy it - don't allow it.
+            allowed = false;
+        }
+    }
+    return allowed;
+}
+
+// Starts a fetch on folders and items.  This is really not used
 // as an observer in the traditional sense; we're just using it to
 // request a fetch and we don't care about when/if the response arrives.
 class LLCategoryFireAndForget : public LLInventoryFetchComboObserver
 {
 public:
-	LLCategoryFireAndForget(const uuid_vec_t& folder_ids,
-							const uuid_vec_t& item_ids) :
-		LLInventoryFetchComboObserver(folder_ids, item_ids)
-	{}
-	~LLCategoryFireAndForget() {}
-	virtual void done()
-	{
-		/* no-op: it's fire n forget right? */
-		LL_DEBUGS() << "LLCategoryFireAndForget::done()" << LL_ENDL;
-	}
+    LLCategoryFireAndForget(const uuid_vec_t& folder_ids,
+                            const uuid_vec_t& item_ids) :
+        LLInventoryFetchComboObserver(folder_ids, item_ids)
+    {}
+    ~LLCategoryFireAndForget() {}
+    virtual void done()
+    {
+        /* no-op: it's fire n forget right? */
+        LL_DEBUGS() << "LLCategoryFireAndForget::done()" << LL_ENDL;
+    }
 };
 
 class LLCategoryDropObserver : public LLInventoryFetchItemsObserver
 {
 public:
-	LLCategoryDropObserver(
-		const uuid_vec_t& ids,
-		const LLUUID& obj_id, LLToolDragAndDrop::ESource src) :
-		LLInventoryFetchItemsObserver(ids),
-		mObjectID(obj_id),
-		mSource(src)
-	{}
-	~LLCategoryDropObserver() {}
-	virtual void done();
+    LLCategoryDropObserver(
+        const uuid_vec_t& ids,
+        const LLUUID& obj_id, LLToolDragAndDrop::ESource src) :
+        LLInventoryFetchItemsObserver(ids),
+        mObjectID(obj_id),
+        mSource(src)
+    {}
+    ~LLCategoryDropObserver() {}
+    virtual void done();
 
 protected:
-	LLUUID mObjectID;
-	LLToolDragAndDrop::ESource mSource;
+    LLUUID mObjectID;
+    LLToolDragAndDrop::ESource mSource;
 };
 
 void LLCategoryDropObserver::done()
 {
-	gInventory.removeObserver(this);
-	LLViewerObject* dst_obj = gObjectList.findObject(mObjectID);
-	if (dst_obj)
-	{
-		// *FIX: coalesce these...
- 		LLInventoryItem* item = NULL;
-  		uuid_vec_t::iterator it = mComplete.begin();
-  		uuid_vec_t::iterator end = mComplete.end();
-  		for(; it < end; ++it)
-  		{
- 			item = gInventory.getItem(*it);
- 			if (item)
- 			{
- 				LLToolDragAndDrop::dropInventory(
- 					dst_obj,
- 					item,
- 					mSource,
- 					LLUUID::null);
- 			}
-  		}
-	}
-	delete this;
+    gInventory.removeObserver(this);
+    LLViewerObject* dst_obj = gObjectList.findObject(mObjectID);
+    if (dst_obj)
+    {
+        // *FIX: coalesce these...
+        LLInventoryItem* item = NULL;
+        uuid_vec_t::iterator it = mComplete.begin();
+        uuid_vec_t::iterator end = mComplete.end();
+        for(; it < end; ++it)
+        {
+            item = gInventory.getItem(*it);
+            if (item)
+            {
+                LLToolDragAndDrop::dropInventory(
+                    dst_obj,
+                    item,
+                    mSource,
+                    LLUUID::null);
+            }
+        }
+    }
+    delete this;
 }
 
 S32 LLToolDragAndDrop::sOperationId = 0;
 
 LLToolDragAndDrop::DragAndDropEntry::DragAndDropEntry(dragOrDrop3dImpl f_none,
-													  dragOrDrop3dImpl f_self,
-													  dragOrDrop3dImpl f_avatar,
-													  dragOrDrop3dImpl f_object,
-													  dragOrDrop3dImpl f_land) :
-	LLDictionaryEntry("")
+                                                      dragOrDrop3dImpl f_self,
+                                                      dragOrDrop3dImpl f_avatar,
+                                                      dragOrDrop3dImpl f_object,
+                                                      dragOrDrop3dImpl f_land) :
+    LLDictionaryEntry("")
 {
-	mFunctions[DT_NONE] = f_none;
-	mFunctions[DT_SELF] = f_self;
-	mFunctions[DT_AVATAR] = f_avatar;
-	mFunctions[DT_OBJECT] = f_object;
-	mFunctions[DT_LAND] = f_land;
+    mFunctions[DT_NONE] = f_none;
+    mFunctions[DT_SELF] = f_self;
+    mFunctions[DT_AVATAR] = f_avatar;
+    mFunctions[DT_OBJECT] = f_object;
+    mFunctions[DT_LAND] = f_land;
 }
 
 LLToolDragAndDrop::dragOrDrop3dImpl LLToolDragAndDrop::LLDragAndDropDictionary::get(EDragAndDropType dad_type, LLToolDragAndDrop::EDropTarget drop_target)
 {
-	const DragAndDropEntry *entry = lookup(dad_type);
-	if (entry)
-	{
-		return (entry->mFunctions[(U8)drop_target]);
-	}
-	return &LLToolDragAndDrop::dad3dNULL;
+    const DragAndDropEntry *entry = lookup(dad_type);
+    if (entry)
+    {
+        return (entry->mFunctions[(U8)drop_target]);
+    }
+    return &LLToolDragAndDrop::dad3dNULL;
 }
 
 LLToolDragAndDrop::LLDragAndDropDictionary::LLDragAndDropDictionary()
 {
- 	//       										 DT_NONE                         DT_SELF                                        DT_AVATAR                   					DT_OBJECT                       					DT_LAND		
-	//      										|-------------------------------|----------------------------------------------|-----------------------------------------------|---------------------------------------------------|--------------------------------|
-	addEntry(DAD_NONE, 			new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dNULL,						&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_TEXTURE, 		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dGiveInventory,			&LLToolDragAndDrop::dad3dTextureObject,				&LLToolDragAndDrop::dad3dNULL));
+    //                                               DT_NONE                         DT_SELF                                        DT_AVATAR                                       DT_OBJECT                                           DT_LAND
+    //                                              |-------------------------------|----------------------------------------------|-----------------------------------------------|---------------------------------------------------|--------------------------------|
+    addEntry(DAD_NONE,          new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dNULL,                      &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_TEXTURE,       new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dTextureObject,             &LLToolDragAndDrop::dad3dNULL));
     addEntry(DAD_MATERIAL,      new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dMaterialObject,            &LLToolDragAndDrop::dad3dNULL));
-    addEntry(DAD_SOUND, 		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dGiveInventory,			&LLToolDragAndDrop::dad3dUpdateInventory,			&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_CALLINGCARD, 	new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dGiveInventory, 		&LLToolDragAndDrop::dad3dUpdateInventory, 			&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_LANDMARK, 		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, 					&LLToolDragAndDrop::dad3dGiveInventory, 		&LLToolDragAndDrop::dad3dUpdateInventory, 			&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_SCRIPT, 		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, 					&LLToolDragAndDrop::dad3dGiveInventory, 		&LLToolDragAndDrop::dad3dRezScript, 				&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_CLOTHING, 		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dWearItem, 				&LLToolDragAndDrop::dad3dGiveInventory, 		&LLToolDragAndDrop::dad3dUpdateInventory, 			&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_OBJECT, 		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dRezAttachmentFromInv,	&LLToolDragAndDrop::dad3dGiveInventoryObject,	&LLToolDragAndDrop::dad3dRezObjectOnObject, 		&LLToolDragAndDrop::dad3dRezObjectOnLand));
-	addEntry(DAD_NOTECARD, 		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL, 					&LLToolDragAndDrop::dad3dGiveInventory, 		&LLToolDragAndDrop::dad3dUpdateInventory, 			&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_CATEGORY,		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dWearCategory,			&LLToolDragAndDrop::dad3dGiveInventoryCategory,	&LLToolDragAndDrop::dad3dRezCategoryOnObject,		&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_ROOT_CATEGORY, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dNULL,						&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_BODYPART, 		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dWearItem,				&LLToolDragAndDrop::dad3dGiveInventory,			&LLToolDragAndDrop::dad3dUpdateInventory,			&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_ANIMATION, 	new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dGiveInventory,			&LLToolDragAndDrop::dad3dUpdateInventory,			&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_GESTURE, 		new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dActivateGesture,		&LLToolDragAndDrop::dad3dGiveInventory,			&LLToolDragAndDrop::dad3dUpdateInventory,			&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_LINK, 			new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dNULL,						&LLToolDragAndDrop::dad3dNULL));
-	addEntry(DAD_MESH, 			new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL,	&LLToolDragAndDrop::dad3dNULL,					&LLToolDragAndDrop::dad3dGiveInventory,			&LLToolDragAndDrop::dad3dMeshObject,				&LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_SOUND,         new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dUpdateInventory,           &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_CALLINGCARD,   new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dUpdateInventory,           &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_LANDMARK,      new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dUpdateInventory,           &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_SCRIPT,        new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dRezScript,                 &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_CLOTHING,      new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dWearItem,              &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dUpdateInventory,           &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_OBJECT,        new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dRezAttachmentFromInv,  &LLToolDragAndDrop::dad3dGiveInventoryObject,   &LLToolDragAndDrop::dad3dRezObjectOnObject,         &LLToolDragAndDrop::dad3dRezObjectOnLand));
+    addEntry(DAD_NOTECARD,      new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dUpdateInventory,           &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_CATEGORY,      new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dWearCategory,          &LLToolDragAndDrop::dad3dGiveInventoryCategory, &LLToolDragAndDrop::dad3dRezCategoryOnObject,       &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_ROOT_CATEGORY, new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dNULL,                      &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_BODYPART,      new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dWearItem,              &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dUpdateInventory,           &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_ANIMATION,     new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dUpdateInventory,           &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_GESTURE,       new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dActivateGesture,       &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dUpdateInventory,           &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_LINK,          new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dNULL,                      &LLToolDragAndDrop::dad3dNULL));
+    addEntry(DAD_MESH,          new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dMeshObject,                &LLToolDragAndDrop::dad3dNULL));
     addEntry(DAD_SETTINGS,      new DragAndDropEntry(&LLToolDragAndDrop::dad3dNULL, &LLToolDragAndDrop::dad3dNULL,                  &LLToolDragAndDrop::dad3dGiveInventory,         &LLToolDragAndDrop::dad3dUpdateInventory,           &LLToolDragAndDrop::dad3dNULL));
-    
+
     // TODO: animation on self could play it?  edit it?
-	// TODO: gesture on self could play it?  edit it?
+    // TODO: gesture on self could play it?  edit it?
 };
 
 LLToolDragAndDrop::LLToolDragAndDrop()
-:	LLTool(std::string("draganddrop"), NULL),
-	mCargoCount(0),
-	mDragStartX(0),
-	mDragStartY(0),
-	mSource(SOURCE_AGENT),
-	mCursor(UI_CURSOR_NO),
-	mLastAccept(ACCEPT_NO),
-	mDrop(FALSE),
-	mCurItemIndex(0)
+:   LLTool(std::string("draganddrop"), NULL),
+    mCargoCount(0),
+    mDragStartX(0),
+    mDragStartY(0),
+    mSource(SOURCE_AGENT),
+    mCursor(UI_CURSOR_NO),
+    mLastAccept(ACCEPT_NO),
+    mDrop(FALSE),
+    mCurItemIndex(0)
 {
 
 }
 
 void LLToolDragAndDrop::setDragStart(S32 x, S32 y)
 {
-	mDragStartX = x;
-	mDragStartY = y;
+    mDragStartX = x;
+    mDragStartY = y;
 }
 
 BOOL LLToolDragAndDrop::isOverThreshold(S32 x,S32 y)
 {
-	S32 mouse_delta_x = x - mDragStartX;
-	S32 mouse_delta_y = y - mDragStartY;
-	
+    S32 mouse_delta_x = x - mDragStartX;
+    S32 mouse_delta_y = y - mDragStartY;
+
     return (mouse_delta_x * mouse_delta_x) + (mouse_delta_y * mouse_delta_y) > DRAG_N_DROP_DISTANCE_THRESHOLD * DRAG_N_DROP_DISTANCE_THRESHOLD;
 }
 
 void LLToolDragAndDrop::beginDrag(EDragAndDropType type,
-								  const LLUUID& cargo_id,
-								  ESource source,
-								  const LLUUID& source_id,
-								  const LLUUID& object_id)
-{
-	if (type == DAD_NONE)
-	{
-		LL_WARNS() << "Attempted to start drag without a cargo type" << LL_ENDL;
-		return;
-	}
-	mCargoTypes.clear();
-	mCargoTypes.push_back(type);
-	mCargoIDs.clear();
-	mCargoIDs.push_back(cargo_id);
-	mSource = source;
-	mSourceID = source_id;
-	mObjectID = object_id;
-
-	setMouseCapture( TRUE );
-	LLToolMgr::getInstance()->setTransientTool( this );
-	mCursor = UI_CURSOR_NO;
-	if ((mCargoTypes[0] == DAD_CATEGORY)
-	   && ((mSource == SOURCE_AGENT) || (mSource == SOURCE_LIBRARY)))
-	{
-		LLInventoryCategory* cat = gInventory.getCategory(cargo_id);
-		// go ahead and fire & forget the descendents if we are not
-		// dragging a protected folder.
-		if (cat)
-		{
-			LLViewerInventoryCategory::cat_array_t cats;
-			LLViewerInventoryItem::item_array_t items;
-			LLNoPreferredTypeOrItem is_not_preferred;
-			uuid_vec_t folder_ids;
-			uuid_vec_t item_ids;
-			if (is_not_preferred(cat, NULL))
-			{
-				folder_ids.push_back(cargo_id);
-			}
-			gInventory.collectDescendentsIf(
-				cargo_id,
-				cats,
-				items,
-				LLInventoryModel::EXCLUDE_TRASH,
-				is_not_preferred);
-			S32 count = cats.size();
-			S32 i;
-			for(i = 0; i < count; ++i)
-			{
-				folder_ids.push_back(cats.at(i)->getUUID());
-			}
-			count = items.size();
-			for(i = 0; i < count; ++i)
-			{
-				item_ids.push_back(items.at(i)->getUUID());
-			}
-			if (!folder_ids.empty() || !item_ids.empty())
-			{
-				LLCategoryFireAndForget *fetcher = new LLCategoryFireAndForget(folder_ids, item_ids);
-				fetcher->startFetch();
-				delete fetcher;
-			}
-		}
-	}
+                                  const LLUUID& cargo_id,
+                                  ESource source,
+                                  const LLUUID& source_id,
+                                  const LLUUID& object_id)
+{
+    if (type == DAD_NONE)
+    {
+        LL_WARNS() << "Attempted to start drag without a cargo type" << LL_ENDL;
+        return;
+    }
+    mCargoTypes.clear();
+    mCargoTypes.push_back(type);
+    mCargoIDs.clear();
+    mCargoIDs.push_back(cargo_id);
+    mSource = source;
+    mSourceID = source_id;
+    mObjectID = object_id;
+
+    setMouseCapture( TRUE );
+    LLToolMgr::getInstance()->setTransientTool( this );
+    mCursor = UI_CURSOR_NO;
+    if ((mCargoTypes[0] == DAD_CATEGORY)
+       && ((mSource == SOURCE_AGENT) || (mSource == SOURCE_LIBRARY)))
+    {
+        LLInventoryCategory* cat = gInventory.getCategory(cargo_id);
+        // go ahead and fire & forget the descendents if we are not
+        // dragging a protected folder.
+        if (cat)
+        {
+            LLViewerInventoryCategory::cat_array_t cats;
+            LLViewerInventoryItem::item_array_t items;
+            LLNoPreferredTypeOrItem is_not_preferred;
+            uuid_vec_t folder_ids;
+            uuid_vec_t item_ids;
+            if (is_not_preferred(cat, NULL))
+            {
+                folder_ids.push_back(cargo_id);
+            }
+            gInventory.collectDescendentsIf(
+                cargo_id,
+                cats,
+                items,
+                LLInventoryModel::EXCLUDE_TRASH,
+                is_not_preferred);
+            S32 count = cats.size();
+            S32 i;
+            for(i = 0; i < count; ++i)
+            {
+                folder_ids.push_back(cats.at(i)->getUUID());
+            }
+            count = items.size();
+            for(i = 0; i < count; ++i)
+            {
+                item_ids.push_back(items.at(i)->getUUID());
+            }
+            if (!folder_ids.empty() || !item_ids.empty())
+            {
+                LLCategoryFireAndForget *fetcher = new LLCategoryFireAndForget(folder_ids, item_ids);
+                fetcher->startFetch();
+                delete fetcher;
+            }
+        }
+    }
 }
 
 void LLToolDragAndDrop::beginMultiDrag(
-	const std::vector<EDragAndDropType> types,
-	const uuid_vec_t& cargo_ids,
-	ESource source,
-	const LLUUID& source_id)
-{
-	// assert on public api is evil
-	//llassert( type != DAD_NONE );
-
-	std::vector<EDragAndDropType>::const_iterator types_it;
-	for (types_it = types.begin(); types_it != types.end(); ++types_it)
-	{
-		if (DAD_NONE == *types_it)
-		{
-			LL_WARNS() << "Attempted to start drag without a cargo type" << LL_ENDL;
-			return;
-		}
-	}
-	mCargoTypes = types;
-	mCargoIDs = cargo_ids;
-	mSource = source;
-	mSourceID = source_id;
-
-	setMouseCapture( TRUE );
-	LLToolMgr::getInstance()->setTransientTool( this );
-	mCursor = UI_CURSOR_NO;
-	if ((mSource == SOURCE_AGENT) || (mSource == SOURCE_LIBRARY))
-	{
-		// find categories (i.e. inventory folders) in the cargo.
-		LLInventoryCategory* cat = NULL;
-		S32 count = llmin(cargo_ids.size(), types.size());
-		std::set<LLUUID> cat_ids;
-		for(S32 i = 0; i < count; ++i)
-		{
-			cat = gInventory.getCategory(cargo_ids[i]);
-			if (cat)
-			{
-				LLViewerInventoryCategory::cat_array_t cats;
-				LLViewerInventoryItem::item_array_t items;
-				LLNoPreferredType is_not_preferred;
-				if (is_not_preferred(cat, NULL))
-				{
-					cat_ids.insert(cat->getUUID());
-				}
-				gInventory.collectDescendentsIf(
-					cat->getUUID(),
-					cats,
-					items,
-					LLInventoryModel::EXCLUDE_TRASH,
-					is_not_preferred);
-				S32 cat_count = cats.size();
-				for(S32 i = 0; i < cat_count; ++i)
-				{
-					cat_ids.insert(cat->getUUID());
-				}
-			}
-		}
-		if (!cat_ids.empty())
-		{
-			uuid_vec_t folder_ids;
-			uuid_vec_t item_ids;
-			std::back_insert_iterator<uuid_vec_t> copier(folder_ids);
-			std::copy(cat_ids.begin(), cat_ids.end(), copier);
-			LLCategoryFireAndForget fetcher(folder_ids, item_ids);
-		}
-	}
+    const std::vector<EDragAndDropType> types,
+    const uuid_vec_t& cargo_ids,
+    ESource source,
+    const LLUUID& source_id)
+{
+    // assert on public api is evil
+    //llassert( type != DAD_NONE );
+
+    std::vector<EDragAndDropType>::const_iterator types_it;
+    for (types_it = types.begin(); types_it != types.end(); ++types_it)
+    {
+        if (DAD_NONE == *types_it)
+        {
+            LL_WARNS() << "Attempted to start drag without a cargo type" << LL_ENDL;
+            return;
+        }
+    }
+    mCargoTypes = types;
+    mCargoIDs = cargo_ids;
+    mSource = source;
+    mSourceID = source_id;
+
+    setMouseCapture( TRUE );
+    LLToolMgr::getInstance()->setTransientTool( this );
+    mCursor = UI_CURSOR_NO;
+    if ((mSource == SOURCE_AGENT) || (mSource == SOURCE_LIBRARY))
+    {
+        // find categories (i.e. inventory folders) in the cargo.
+        LLInventoryCategory* cat = NULL;
+        S32 count = llmin(cargo_ids.size(), types.size());
+        std::set<LLUUID> cat_ids;
+        for(S32 i = 0; i < count; ++i)
+        {
+            cat = gInventory.getCategory(cargo_ids[i]);
+            if (cat)
+            {
+                LLViewerInventoryCategory::cat_array_t cats;
+                LLViewerInventoryItem::item_array_t items;
+                LLNoPreferredType is_not_preferred;
+                if (is_not_preferred(cat, NULL))
+                {
+                    cat_ids.insert(cat->getUUID());
+                }
+                gInventory.collectDescendentsIf(
+                    cat->getUUID(),
+                    cats,
+                    items,
+                    LLInventoryModel::EXCLUDE_TRASH,
+                    is_not_preferred);
+                S32 cat_count = cats.size();
+                for(S32 i = 0; i < cat_count; ++i)
+                {
+                    cat_ids.insert(cat->getUUID());
+                }
+            }
+        }
+        if (!cat_ids.empty())
+        {
+            uuid_vec_t folder_ids;
+            uuid_vec_t item_ids;
+            std::back_insert_iterator<uuid_vec_t> copier(folder_ids);
+            std::copy(cat_ids.begin(), cat_ids.end(), copier);
+            LLCategoryFireAndForget fetcher(folder_ids, item_ids);
+        }
+    }
 }
 
 void LLToolDragAndDrop::endDrag()
 {
-	mEndDragSignal();
-	LLSelectMgr::getInstance()->unhighlightAll();
-	setMouseCapture(FALSE);
+    mEndDragSignal();
+    LLSelectMgr::getInstance()->unhighlightAll();
+    setMouseCapture(FALSE);
 }
 
 void LLToolDragAndDrop::onMouseCaptureLost()
 {
-	// Called whenever the drag ends or if mouse capture is simply lost
-	LLToolMgr::getInstance()->clearTransientTool();
-	mCargoTypes.clear();
-	mCargoIDs.clear();
-	mSource = SOURCE_AGENT;
-	mSourceID.setNull();
-	mObjectID.setNull();
-	mCustomMsg.clear();
+    // Called whenever the drag ends or if mouse capture is simply lost
+    LLToolMgr::getInstance()->clearTransientTool();
+    mCargoTypes.clear();
+    mCargoIDs.clear();
+    mSource = SOURCE_AGENT;
+    mSourceID.setNull();
+    mObjectID.setNull();
+    mCustomMsg.clear();
 }
 
 BOOL LLToolDragAndDrop::handleMouseUp( S32 x, S32 y, MASK mask )
 {
-	if (hasMouseCapture())
-	{
-		EAcceptance acceptance = ACCEPT_NO;
-		dragOrDrop( x, y, mask, TRUE, &acceptance );
-		endDrag();
-	}
-	return TRUE;
+    if (hasMouseCapture())
+    {
+        EAcceptance acceptance = ACCEPT_NO;
+        dragOrDrop( x, y, mask, TRUE, &acceptance );
+        endDrag();
+    }
+    return TRUE;
 }
 
 ECursorType LLToolDragAndDrop::acceptanceToCursor( EAcceptance acceptance )
 {
-	switch (acceptance)
-	{
-	case ACCEPT_YES_MULTI:
-		if (mCargoIDs.size() > 1)
-		{
-			mCursor = UI_CURSOR_ARROWDRAGMULTI;
-		}
-		else
-		{
-			mCursor = UI_CURSOR_ARROWDRAG;
-		}
-		break;
-	case ACCEPT_YES_SINGLE:
-		if (mCargoIDs.size() > 1)
-		{
-			mToolTipMsg = LLTrans::getString("TooltipMustSingleDrop");
-			mCursor = UI_CURSOR_NO;
-		}
-		else
-		{
-			mCursor = UI_CURSOR_ARROWDRAG;
-		}
-		break;
-
-	case ACCEPT_NO_LOCKED:
-		mCursor = UI_CURSOR_NOLOCKED;
-		break;
-
-	case ACCEPT_NO_CUSTOM:
-		mToolTipMsg = mCustomMsg;
-		mCursor = UI_CURSOR_NO;
-		break;
-
-
-	case ACCEPT_NO:
-		mCursor = UI_CURSOR_NO;
-		break;
-
-	case ACCEPT_YES_COPY_MULTI:
-		if (mCargoIDs.size() > 1)
-		{
-			mCursor = UI_CURSOR_ARROWCOPYMULTI;
-		}
-		else
-		{
-			mCursor = UI_CURSOR_ARROWCOPY;
-		}
-		break;
-	case ACCEPT_YES_COPY_SINGLE:
-		if (mCargoIDs.size() > 1)
-		{
-			mToolTipMsg = LLTrans::getString("TooltipMustSingleDrop");
-			mCursor = UI_CURSOR_NO;
-		}
-		else
-		{
-			mCursor = UI_CURSOR_ARROWCOPY;
-		}
-		break;
-	case ACCEPT_POSTPONED:
-		break;
-	default:
-		llassert( FALSE );
-	}
-
-	return mCursor;
+    switch (acceptance)
+    {
+    case ACCEPT_YES_MULTI:
+        if (mCargoIDs.size() > 1)
+        {
+            mCursor = UI_CURSOR_ARROWDRAGMULTI;
+        }
+        else
+        {
+            mCursor = UI_CURSOR_ARROWDRAG;
+        }
+        break;
+    case ACCEPT_YES_SINGLE:
+        if (mCargoIDs.size() > 1)
+        {
+            mToolTipMsg = LLTrans::getString("TooltipMustSingleDrop");
+            mCursor = UI_CURSOR_NO;
+        }
+        else
+        {
+            mCursor = UI_CURSOR_ARROWDRAG;
+        }
+        break;
+
+    case ACCEPT_NO_LOCKED:
+        mCursor = UI_CURSOR_NOLOCKED;
+        break;
+
+    case ACCEPT_NO_CUSTOM:
+        mToolTipMsg = mCustomMsg;
+        mCursor = UI_CURSOR_NO;
+        break;
+
+
+    case ACCEPT_NO:
+        mCursor = UI_CURSOR_NO;
+        break;
+
+    case ACCEPT_YES_COPY_MULTI:
+        if (mCargoIDs.size() > 1)
+        {
+            mCursor = UI_CURSOR_ARROWCOPYMULTI;
+        }
+        else
+        {
+            mCursor = UI_CURSOR_ARROWCOPY;
+        }
+        break;
+    case ACCEPT_YES_COPY_SINGLE:
+        if (mCargoIDs.size() > 1)
+        {
+            mToolTipMsg = LLTrans::getString("TooltipMustSingleDrop");
+            mCursor = UI_CURSOR_NO;
+        }
+        else
+        {
+            mCursor = UI_CURSOR_ARROWCOPY;
+        }
+        break;
+    case ACCEPT_POSTPONED:
+        break;
+    default:
+        llassert( FALSE );
+    }
+
+    return mCursor;
 }
 
 BOOL LLToolDragAndDrop::handleHover( S32 x, S32 y, MASK mask )
 {
-	EAcceptance acceptance = ACCEPT_NO;
-	dragOrDrop( x, y, mask, FALSE, &acceptance );
+    EAcceptance acceptance = ACCEPT_NO;
+    dragOrDrop( x, y, mask, FALSE, &acceptance );
 
-	ECursorType cursor = acceptanceToCursor(acceptance);
-	gViewerWindow->getWindow()->setCursor( cursor );
+    ECursorType cursor = acceptanceToCursor(acceptance);
+    gViewerWindow->getWindow()->setCursor( cursor );
 
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("UserInput") << "hover handled by LLToolDragAndDrop" << LL_ENDL;
+    LL_DEBUGS("UserInput") << "hover handled by LLToolDragAndDrop" << LL_ENDL;
 #endif
-	return TRUE;
+    return TRUE;
 }
 
 BOOL LLToolDragAndDrop::handleKey(KEY key, MASK mask)
 {
-	if (key == KEY_ESCAPE)
-	{
-		// cancel drag and drop operation
-		endDrag();
-		return TRUE;
-	}
+    if (key == KEY_ESCAPE)
+    {
+        // cancel drag and drop operation
+        endDrag();
+        return TRUE;
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 BOOL LLToolDragAndDrop::handleToolTip(S32 x, S32 y, MASK mask)
 {
     const F32 DRAG_N_DROP_TOOLTIP_DELAY = 0.10000000149f;
-	if (!mToolTipMsg.empty())
-	{
-		LLToolTipMgr::instance().unblockToolTips();
-		LLToolTipMgr::instance().show(LLToolTip::Params()
-			.message(mToolTipMsg)
+    if (!mToolTipMsg.empty())
+    {
+        LLToolTipMgr::instance().unblockToolTips();
+        LLToolTipMgr::instance().show(LLToolTip::Params()
+            .message(mToolTipMsg)
             .delay_time(DRAG_N_DROP_TOOLTIP_DELAY));
-		return TRUE;
-	}
-	return FALSE;
+        return TRUE;
+    }
+    return FALSE;
 }
 
 void LLToolDragAndDrop::handleDeselect()
 {
-	mToolTipMsg.clear();
-	mCustomMsg.clear();
+    mToolTipMsg.clear();
+    mCustomMsg.clear();
 
-	LLToolTipMgr::instance().blockToolTips();
+    LLToolTipMgr::instance().blockToolTips();
 }
 
 // protected
-void LLToolDragAndDrop::dragOrDrop( S32 x, S32 y, MASK mask, BOOL drop, 
-								   EAcceptance* acceptance)
-{
-	*acceptance = ACCEPT_YES_MULTI;
-
-	BOOL handled = FALSE;
-
-	LLView* top_view = gFocusMgr.getTopCtrl();
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-
-	mToolTipMsg.clear();
-
-	// Increment the operation id for every drop
-	if (drop)
-	{
-		sOperationId++;
-	}
-
-	// For people drag and drop we don't need an actual inventory object,
-	// instead we need the current cargo id, which should be a person id.
-	bool is_uuid_dragged = (mSource == SOURCE_PEOPLE);
-
-	if (top_view)
-	{
-		handled = TRUE;
-
-		for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
-		{
-			S32 local_x, local_y;
-			top_view->screenPointToLocal( x, y, &local_x, &local_y );
-			EAcceptance item_acceptance = ACCEPT_NO;
-
-			LLInventoryObject* cargo = locateInventory(item, cat);
-			if (cargo)
-			{
-				handled = handled && top_view->handleDragAndDrop(local_x, local_y, mask, FALSE,
-													mCargoTypes[mCurItemIndex],
-													(void*)cargo,
-													&item_acceptance,
-													mToolTipMsg);
-			}
-			else if (is_uuid_dragged)
-			{
-				handled = handled && top_view->handleDragAndDrop(local_x, local_y, mask, FALSE,
-													mCargoTypes[mCurItemIndex],
-													(void*)&mCargoIDs[mCurItemIndex],
-													&item_acceptance,
-													mToolTipMsg);
-			}
-			if (handled)
-			{
-				// use sort order to determine priority of acceptance
-				*acceptance = (EAcceptance)llmin((U32)item_acceptance, (U32)*acceptance);
-			}
-		}
-
-		// all objects passed, go ahead and perform drop if necessary
-		if (handled && drop && (U32)*acceptance >= ACCEPT_YES_COPY_SINGLE)
-		{
-			if ((U32)*acceptance < ACCEPT_YES_COPY_MULTI &&
-			    mCargoIDs.size() > 1)
-			{
-				// tried to give multi-cargo to a single-acceptor - refuse and return.
-				*acceptance = ACCEPT_NO;
-				return;
-			}
-
-			for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
-			{
-				S32 local_x, local_y;
-				EAcceptance item_acceptance;
-				top_view->screenPointToLocal( x, y, &local_x, &local_y );
-
-				LLInventoryObject* cargo = locateInventory(item, cat);
-				if (cargo)
-				{
-					handled = handled && top_view->handleDragAndDrop(local_x, local_y, mask, TRUE,
-														mCargoTypes[mCurItemIndex],
-														(void*)cargo,
-														&item_acceptance,
-														mToolTipMsg);
-				}
-				else if (is_uuid_dragged)
-				{
-					handled = handled && top_view->handleDragAndDrop(local_x, local_y, mask, FALSE,
-														mCargoTypes[mCurItemIndex],
-														(void*)&mCargoIDs[mCurItemIndex],
-														&item_acceptance,
-														mToolTipMsg);
-				}
-			}
-		}
-		if (handled)
-		{
-			mLastAccept = (EAcceptance)*acceptance;
-		}
-	}
-
-	if (!handled)
-	{
-		handled = TRUE;
-
-		LLRootView* root_view = gViewerWindow->getRootView();
-
-		for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
-		{
-			EAcceptance item_acceptance = ACCEPT_NO;
-
-			LLInventoryObject* cargo = locateInventory(item, cat);
-
-			// fix for EXT-3191
-			if (cargo)
-			{
-				handled = handled && root_view->handleDragAndDrop(x, y, mask, FALSE,
-													mCargoTypes[mCurItemIndex],
-													(void*)cargo,
-													&item_acceptance,
-													mToolTipMsg);
-			}
-			else if (is_uuid_dragged)
-			{
-				handled = handled && root_view->handleDragAndDrop(x, y, mask, FALSE,
-													mCargoTypes[mCurItemIndex],
-													(void*)&mCargoIDs[mCurItemIndex],
-													&item_acceptance,
-													mToolTipMsg);
-			}
-			if (handled)
-			{
-				// use sort order to determine priority of acceptance
-				*acceptance = (EAcceptance)llmin((U32)item_acceptance, (U32)*acceptance);
-			}
-		}
-		// all objects passed, go ahead and perform drop if necessary
-		if (handled && drop && (U32)*acceptance > ACCEPT_NO_LOCKED)
-		{	
-			if ((U32)*acceptance < ACCEPT_YES_COPY_MULTI &&
-			    mCargoIDs.size() > 1)
-			{
-				// tried to give multi-cargo to a single-acceptor - refuse and return.
-				*acceptance = ACCEPT_NO;
-				return;
-			}
-
-			for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
-			{
-				EAcceptance item_acceptance;
-
-				LLInventoryObject* cargo = locateInventory(item, cat);
-				if (cargo)
-				{
-					handled = handled && root_view->handleDragAndDrop(x, y, mask, TRUE,
-											  mCargoTypes[mCurItemIndex],
-											  (void*)cargo,
-											  &item_acceptance,
-											  mToolTipMsg);
-				}
-				else if (is_uuid_dragged)
-				{
-					handled = handled && root_view->handleDragAndDrop(x, y, mask, TRUE,
-											  mCargoTypes[mCurItemIndex],
-											  (void*)&mCargoIDs[mCurItemIndex],
-											  &item_acceptance,
-											  mToolTipMsg);
-				}
-			}
-		}
-
-		if (handled)
-		{
-			mLastAccept = (EAcceptance)*acceptance;
-		}
-	}
-
-	if (!handled)
-	{
-		// Disallow drag and drop to 3D from the marketplace
-        const LLUUID marketplacelistings_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MARKETPLACE_LISTINGS);
-		if (marketplacelistings_id.notNull())
-		{
-			for (S32 item_index = 0; item_index < (S32)mCargoIDs.size(); item_index++)
-			{
-				if (gInventory.isObjectDescendentOf(mCargoIDs[item_index], marketplacelistings_id))
-				{
-					*acceptance = ACCEPT_NO;
-					mToolTipMsg = LLTrans::getString("TooltipOutboxDragToWorld");
-					return;
-				}
-			}
-		}
-		
-		dragOrDrop3D( x, y, mask, drop, acceptance );
-	}
-}
-
-void LLToolDragAndDrop::dragOrDrop3D( S32 x, S32 y, MASK mask, BOOL drop, EAcceptance* acceptance )
+void LLToolDragAndDrop::dragOrDrop( S32 x, S32 y, MASK mask, BOOL drop,
+                                   EAcceptance* acceptance)
 {
-	mDrop = drop;
-	if (mDrop)
-	{
-		// don't allow drag and drop onto rigged or transparent objects
-		pick(gViewerWindow->pickImmediate(x, y, FALSE, FALSE));
-	}
-	else
-	{
-		// don't allow drag and drop onto transparent objects
-		gViewerWindow->pickAsync(x, y, mask, pickCallback, FALSE, FALSE);
-	}
+    *acceptance = ACCEPT_YES_MULTI;
 
-	*acceptance = mLastAccept;
-}
+    BOOL handled = FALSE;
 
-void LLToolDragAndDrop::pickCallback(const LLPickInfo& pick_info)
-{
-	if (getInstance() != NULL)
-	{
-		getInstance()->pick(pick_info);
-	}
-}
+    LLView* top_view = gFocusMgr.getTopCtrl();
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
 
-void LLToolDragAndDrop::pick(const LLPickInfo& pick_info)
-{
-	EDropTarget target = DT_NONE;
-	S32	hit_face = -1;
-
-	LLViewerObject* hit_obj = pick_info.getObject();
-	LLSelectMgr::getInstance()->unhighlightAll();
-	bool highlight_object = false;
-	// Treat attachments as part of the avatar they are attached to.
-	if (hit_obj != NULL)
-	{
-		// don't allow drag and drop on grass, trees, etc.
-		if (pick_info.mPickType == LLPickInfo::PICK_FLORA)
-		{
-			mCursor = UI_CURSOR_NO;
-			gViewerWindow->getWindow()->setCursor( mCursor );
-			return;
-		}
-
-		if (hit_obj->isAttachment() && !hit_obj->isHUDAttachment())
-		{
-			LLVOAvatar* avatar = LLVOAvatar::findAvatarFromAttachment( hit_obj );
-			if (!avatar)
-			{
-				mLastAccept = ACCEPT_NO;
-				mCursor = UI_CURSOR_NO;
-				gViewerWindow->getWindow()->setCursor( mCursor );
-				return;
-			}
-			hit_obj = avatar;
-		}
-
-		if (hit_obj->isAvatar())
-		{
-			if (((LLVOAvatar*) hit_obj)->isSelf())
-			{
-				target = DT_SELF;
-				hit_face = -1;
-			}
-			else
-			{
-				target = DT_AVATAR;
-				hit_face = -1;
-			}
-		}
-		else
-		{
-			target = DT_OBJECT;
-			hit_face = pick_info.mObjectFace;
-			highlight_object = true;
-		}
-	}
-	else if (pick_info.mPickType == LLPickInfo::PICK_LAND)
-	{
-		target = DT_LAND;
-		hit_face = -1;
-	}
-
-	mLastAccept = ACCEPT_YES_MULTI;
-
-	for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
-	{
-		const S32 item_index = mCurItemIndex;
-		const EDragAndDropType dad_type = mCargoTypes[item_index];
-		// Call the right implementation function
-		mLastAccept = (EAcceptance)llmin(
-			(U32)mLastAccept,
-			(U32)callMemberFunction(*this, 
-									LLDragAndDropDictionary::instance().get(dad_type, target))
-				(hit_obj, hit_face, pick_info.mKeyMask, FALSE));
-	}
-
-	if (mDrop && ((U32)mLastAccept >= ACCEPT_YES_COPY_SINGLE))
-	{
-		// if target allows multi-drop or there is only one item being dropped, go ahead
-		if ((mLastAccept >= ACCEPT_YES_COPY_MULTI) || (mCargoIDs.size() == 1))
-		{
-			// Target accepts multi, or cargo is a single-drop
-			for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
-			{
-				const S32 item_index = mCurItemIndex;
-				const EDragAndDropType dad_type = mCargoTypes[item_index];
-				// Call the right implementation function
-				callMemberFunction(*this, LLDragAndDropDictionary::instance().get(dad_type, target))
-					(hit_obj, hit_face, pick_info.mKeyMask, TRUE);
-			}
-		}
-		else
-		{
-			// Target does not accept multi, but cargo is multi
-			mLastAccept = ACCEPT_NO;
-		}
-	}
-
-	if (highlight_object && mLastAccept > ACCEPT_NO_LOCKED)
-	{
-		// if any item being dragged will be applied to the object under our cursor
-		// highlight that object
-		for (S32 i = 0; i < (S32)mCargoIDs.size(); i++)
-		{
-			if (mCargoTypes[i] != DAD_OBJECT || (pick_info.mKeyMask & MASK_CONTROL))
-			{
-				LLSelectMgr::getInstance()->highlightObjectAndFamily(hit_obj);
-				break;
-			}
-		}
-	}
-	ECursorType cursor = acceptanceToCursor( mLastAccept );
-	gViewerWindow->getWindow()->setCursor( cursor );
-
-	mLastHitPos = pick_info.mPosGlobal;
-	mLastCameraPos = gAgentCamera.getCameraPositionGlobal();
-}
+    mToolTipMsg.clear();
 
-// static
-BOOL LLToolDragAndDrop::handleDropMaterialProtections(LLViewerObject* hit_obj,
-													 LLInventoryItem* item,
-													 LLToolDragAndDrop::ESource source,
-													 const LLUUID& src_id)
-{
-	if (!item) return FALSE;
-
-	// Always succeed if....
-	// material is from the library 
-	// or already in the contents of the object
-	if (SOURCE_LIBRARY == source)
-	{
-		// dropping a material from the library always just works.
-		return TRUE;
-	}
-
-	// In case the inventory has not been loaded (e.g. due to some recent operation
-	// causing a dirty inventory) and we can do an update, stall the user
-	// while fetching the inventory.
-	//
-	// Fetch if inventory is dirty and listener is present (otherwise we will not receive update)
-	if (hit_obj->isInventoryDirty() && hit_obj->hasInventoryListeners())
-	{
-		hit_obj->requestInventory();
-		LLSD args;
-        if (LLAssetType::AT_MATERIAL == item->getType())
+    // Increment the operation id for every drop
+    if (drop)
+    {
+        sOperationId++;
+    }
+
+    // For people drag and drop we don't need an actual inventory object,
+    // instead we need the current cargo id, which should be a person id.
+    bool is_uuid_dragged = (mSource == SOURCE_PEOPLE);
+
+    if (top_view)
+    {
+        handled = TRUE;
+
+        for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
         {
-            args["ERROR_MESSAGE"] = "Unable to add material.\nPlease wait a few seconds and try again.";
+            S32 local_x, local_y;
+            top_view->screenPointToLocal( x, y, &local_x, &local_y );
+            EAcceptance item_acceptance = ACCEPT_NO;
+
+            LLInventoryObject* cargo = locateInventory(item, cat);
+            if (cargo)
+            {
+                handled = handled && top_view->handleDragAndDrop(local_x, local_y, mask, FALSE,
+                                                    mCargoTypes[mCurItemIndex],
+                                                    (void*)cargo,
+                                                    &item_acceptance,
+                                                    mToolTipMsg);
+            }
+            else if (is_uuid_dragged)
+            {
+                handled = handled && top_view->handleDragAndDrop(local_x, local_y, mask, FALSE,
+                                                    mCargoTypes[mCurItemIndex],
+                                                    (void*)&mCargoIDs[mCurItemIndex],
+                                                    &item_acceptance,
+                                                    mToolTipMsg);
+            }
+            if (handled)
+            {
+                // use sort order to determine priority of acceptance
+                *acceptance = (EAcceptance)llmin((U32)item_acceptance, (U32)*acceptance);
+            }
         }
-        else
+
+        // all objects passed, go ahead and perform drop if necessary
+        if (handled && drop && (U32)*acceptance >= ACCEPT_YES_COPY_SINGLE)
         {
-            args["ERROR_MESSAGE"] = "Unable to add texture.\nPlease wait a few seconds and try again.";
+            if ((U32)*acceptance < ACCEPT_YES_COPY_MULTI &&
+                mCargoIDs.size() > 1)
+            {
+                // tried to give multi-cargo to a single-acceptor - refuse and return.
+                *acceptance = ACCEPT_NO;
+                return;
+            }
+
+            for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
+            {
+                S32 local_x, local_y;
+                EAcceptance item_acceptance;
+                top_view->screenPointToLocal( x, y, &local_x, &local_y );
+
+                LLInventoryObject* cargo = locateInventory(item, cat);
+                if (cargo)
+                {
+                    handled = handled && top_view->handleDragAndDrop(local_x, local_y, mask, TRUE,
+                                                        mCargoTypes[mCurItemIndex],
+                                                        (void*)cargo,
+                                                        &item_acceptance,
+                                                        mToolTipMsg);
+                }
+                else if (is_uuid_dragged)
+                {
+                    handled = handled && top_view->handleDragAndDrop(local_x, local_y, mask, FALSE,
+                                                        mCargoTypes[mCurItemIndex],
+                                                        (void*)&mCargoIDs[mCurItemIndex],
+                                                        &item_acceptance,
+                                                        mToolTipMsg);
+                }
+            }
         }
-		LLNotificationsUtil::add("ErrorMessage", args);
-		return FALSE;
-	}
-    // Make sure to verify both id and type since 'null'
-    // is a shared default for some asset types.
-    if (hit_obj->getInventoryItemByAsset(item->getAssetUUID(), item->getType()))
-	{
-		// if the asset is already in the object's inventory 
-		// then it can always be added to a side.
-		// This saves some work if the task's inventory is already loaded
-		// and ensures that the asset item is only added once.
-		return TRUE;
-	}
-	
-	LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
-	if (!item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()))
-	{
-		// Check that we can add the material as inventory to the object
-		if (willObjectAcceptInventory(hit_obj,item) < ACCEPT_YES_COPY_SINGLE )
-		{
-			return FALSE;
-		}
-		// make sure the object has the material in it's inventory.
-		if (SOURCE_AGENT == source)
-		{
-			// Remove the material from local inventory. The server
-			// will actually remove the item from agent inventory.
-			gInventory.deleteObject(item->getUUID());
-			gInventory.notifyObservers();
-		}
-		else if (SOURCE_WORLD == source)
-		{
-			// *FIX: if the objects are in different regions, and the
-			// source region has crashed, you can bypass these
-			// permissions.
-			LLViewerObject* src_obj = gObjectList.findObject(src_id);
-			if (src_obj)
-			{
-				src_obj->removeInventory(item->getUUID());
-			}
-			else
-			{
-				LL_WARNS() << "Unable to find source object." << LL_ENDL;
-				return FALSE;
-			}
-		}
-		// Add the asset item to the target object's inventory.
-        if (LLAssetType::AT_TEXTURE == new_item->getType()
-            || LLAssetType::AT_MATERIAL == new_item->getType())
+        if (handled)
         {
-            hit_obj->updateMaterialInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
+            mLastAccept = (EAcceptance)*acceptance;
         }
-		else
-		{
-			hit_obj->updateInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
-		}
-		// Force the object to update and refetch its inventory so it has this asset.
-		hit_obj->dirtyInventory();
-		hit_obj->requestInventory();
-		// TODO: Check to see if adding the item was successful; if not, then
-		// we should return false here. This will requre a separate listener
-		// since without listener, we have no way to receive update
-	}
-	else if (!item->getPermissions().allowOperationBy(PERM_TRANSFER,
-													 gAgent.getID()))
-	{
-		// Check that we can add the asset as inventory to the object
-		if (willObjectAcceptInventory(hit_obj,item) < ACCEPT_YES_COPY_SINGLE )
-		{
-			return FALSE;
-		}
-		// *FIX: may want to make sure agent can paint hit_obj.
-
-		// Add the asset item to the target object's inventory.
-		if (LLAssetType::AT_TEXTURE == new_item->getType()
-            || LLAssetType::AT_MATERIAL == new_item->getType())
-		{
-			hit_obj->updateMaterialInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
-		}
-		else
-		{
-			hit_obj->updateInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
-		}
-		// Force the object to update and refetch its inventory so it has this asset.
-		hit_obj->dirtyInventory();
-		hit_obj->requestInventory();
-		// TODO: Check to see if adding the item was successful; if not, then
-		// we should return false here. This will requre a separate listener
-		// since without listener, we have no way to receive update
-	}
-	else if (LLAssetType::AT_MATERIAL == new_item->getType() &&
-             !item->getPermissions().allowOperationBy(PERM_MODIFY, gAgent.getID()))
-	{
-		// Check that we can add the material as inventory to the object
-		if (willObjectAcceptInventory(hit_obj,item) < ACCEPT_YES_COPY_SINGLE )
-		{
-			return FALSE;
-		}
-		// *FIX: may want to make sure agent can paint hit_obj.
-
-		// Add the material item to the target object's inventory.
-        hit_obj->updateMaterialInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
-
-		// Force the object to update and refetch its inventory so it has this material.
-		hit_obj->dirtyInventory();
-		hit_obj->requestInventory();
-		// TODO: Check to see if adding the item was successful; if not, then
-		// we should return false here. This will requre a separate listener
-		// since without listener, we have no way to receive update
-	}
-	return TRUE;
-}
-
-void set_texture_to_material(LLViewerObject* hit_obj,
-                             S32 hit_face,
-                             const LLUUID& asset_id,
-                             LLGLTFMaterial::TextureInfo drop_channel)
-{
-    LLTextureEntry* te = hit_obj->getTE(hit_face);
-    if (!te)
-    {
-        return;
-    }
-
-    const LLUUID base_mat_id = hit_obj->getRenderMaterialID(hit_face);
-    if (base_mat_id.isNull())
-    {
-        return;
     }
 
-    if (hit_obj->isInventoryDirty() && hit_obj->hasInventoryListeners())
+    if (!handled)
     {
-        hit_obj->requestInventory();
-        return;
-    }
+        handled = TRUE;
 
-    LLViewerInventoryItem* mat_item = hit_obj->getInventoryItemByAsset(base_mat_id);
-    if (mat_item && !mat_item->getPermissions().allowModifyBy(gAgentID))
-    {
-        return;
-    }
+        LLRootView* root_view = gViewerWindow->getRootView();
 
-    LLPointer<LLGLTFMaterial> material = te->getGLTFMaterialOverride();
+        for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
+        {
+            EAcceptance item_acceptance = ACCEPT_NO;
 
-    // make a copy to not invalidate existing
-    // material for multiple objects
-    if (material.isNull())
-    {
-        // Start with a material override which does not make any changes
-        material = new LLGLTFMaterial();
-    }
-    else
-    {
-        material = new LLGLTFMaterial(*material);
-    }
+            LLInventoryObject* cargo = locateInventory(item, cat);
 
-    switch (drop_channel)
-    {
-        case LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR:
-        default:
+            // fix for EXT-3191
+            if (cargo)
             {
-                material->setBaseColorId(asset_id);
+                handled = handled && root_view->handleDragAndDrop(x, y, mask, FALSE,
+                                                    mCargoTypes[mCurItemIndex],
+                                                    (void*)cargo,
+                                                    &item_acceptance,
+                                                    mToolTipMsg);
             }
-            break;
-
-        case LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS:
+            else if (is_uuid_dragged)
             {
-                material->setOcclusionRoughnessMetallicId(asset_id);
+                handled = handled && root_view->handleDragAndDrop(x, y, mask, FALSE,
+                                                    mCargoTypes[mCurItemIndex],
+                                                    (void*)&mCargoIDs[mCurItemIndex],
+                                                    &item_acceptance,
+                                                    mToolTipMsg);
             }
-            break;
-
-        case LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE:
+            if (handled)
             {
-                material->setEmissiveId(asset_id);
+                // use sort order to determine priority of acceptance
+                *acceptance = (EAcceptance)llmin((U32)item_acceptance, (U32)*acceptance);
+            }
+        }
+        // all objects passed, go ahead and perform drop if necessary
+        if (handled && drop && (U32)*acceptance > ACCEPT_NO_LOCKED)
+        {
+            if ((U32)*acceptance < ACCEPT_YES_COPY_MULTI &&
+                mCargoIDs.size() > 1)
+            {
+                // tried to give multi-cargo to a single-acceptor - refuse and return.
+                *acceptance = ACCEPT_NO;
+                return;
             }
-            break;
 
-        case LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL:
+            for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
             {
-                material->setNormalId(asset_id);
+                EAcceptance item_acceptance;
+
+                LLInventoryObject* cargo = locateInventory(item, cat);
+                if (cargo)
+                {
+                    handled = handled && root_view->handleDragAndDrop(x, y, mask, TRUE,
+                                              mCargoTypes[mCurItemIndex],
+                                              (void*)cargo,
+                                              &item_acceptance,
+                                              mToolTipMsg);
+                }
+                else if (is_uuid_dragged)
+                {
+                    handled = handled && root_view->handleDragAndDrop(x, y, mask, TRUE,
+                                              mCargoTypes[mCurItemIndex],
+                                              (void*)&mCargoIDs[mCurItemIndex],
+                                              &item_acceptance,
+                                              mToolTipMsg);
+                }
             }
-            break;
-    }
-    LLGLTFMaterialList::queueModify(hit_obj, hit_face, material);
-}
+        }
 
-void LLToolDragAndDrop::dropTextureAllFaces(LLViewerObject* hit_obj,
-											LLInventoryItem* item,
-											LLToolDragAndDrop::ESource source,
-											const LLUUID& src_id,
-                                            bool remove_pbr)
-{
-	if (!item)
-	{
-		LL_WARNS() << "LLToolDragAndDrop::dropTextureAllFaces no texture item." << LL_ENDL;
-		return;
-	}
-    S32 num_faces = hit_obj->getNumTEs();
-    bool has_non_pbr_faces = false;
-    for (S32 face = 0; face < num_faces; face++)
-    {
-        if (hit_obj->getRenderMaterialID(face).isNull())
+        if (handled)
         {
-            has_non_pbr_faces = true;
-            break;
+            mLastAccept = (EAcceptance)*acceptance;
         }
     }
 
-    if (has_non_pbr_faces || remove_pbr)
+    if (!handled)
     {
-        BOOL res = handleDropMaterialProtections(hit_obj, item, source, src_id);
-        if (!res)
+        // Disallow drag and drop to 3D from the marketplace
+        const LLUUID marketplacelistings_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MARKETPLACE_LISTINGS);
+        if (marketplacelistings_id.notNull())
         {
-            return;
+            for (S32 item_index = 0; item_index < (S32)mCargoIDs.size(); item_index++)
+            {
+                if (gInventory.isObjectDescendentOf(mCargoIDs[item_index], marketplacelistings_id))
+                {
+                    *acceptance = ACCEPT_NO;
+                    mToolTipMsg = LLTrans::getString("TooltipOutboxDragToWorld");
+                    return;
+                }
+            }
         }
-    }
-	LLUUID asset_id = item->getAssetUUID();
 
-    // Overrides require textures to be copy and transfer free
-    LLPermissions item_permissions = item->getPermissions();
-    bool allow_adding_to_override = item_permissions.allowOperationBy(PERM_COPY, gAgent.getID());
-    allow_adding_to_override &= item_permissions.allowOperationBy(PERM_TRANSFER, gAgent.getID());
+        dragOrDrop3D( x, y, mask, drop, acceptance );
+    }
+}
 
-	LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(asset_id);
-	add(LLStatViewer::EDIT_TEXTURE, 1);
-	for( S32 face = 0; face < num_faces; face++ )
-	{
-        if (remove_pbr)
-        {
+void LLToolDragAndDrop::dragOrDrop3D( S32 x, S32 y, MASK mask, BOOL drop, EAcceptance* acceptance )
+{
+    mDrop = drop;
+    if (mDrop)
+    {
+        // don't allow drag and drop onto rigged or transparent objects
+        pick(gViewerWindow->pickImmediate(x, y, FALSE, FALSE));
+    }
+    else
+    {
+        // don't allow drag and drop onto transparent objects
+        gViewerWindow->pickAsync(x, y, mask, pickCallback, FALSE, FALSE);
+    }
+
+    *acceptance = mLastAccept;
+}
+
+void LLToolDragAndDrop::pickCallback(const LLPickInfo& pick_info)
+{
+    if (getInstance() != NULL)
+    {
+        getInstance()->pick(pick_info);
+    }
+}
+
+void LLToolDragAndDrop::pick(const LLPickInfo& pick_info)
+{
+    EDropTarget target = DT_NONE;
+    S32 hit_face = -1;
+
+    LLViewerObject* hit_obj = pick_info.getObject();
+    LLSelectMgr::getInstance()->unhighlightAll();
+    bool highlight_object = false;
+    // Treat attachments as part of the avatar they are attached to.
+    if (hit_obj != NULL)
+    {
+        // don't allow drag and drop on grass, trees, etc.
+        if (pick_info.mPickType == LLPickInfo::PICK_FLORA)
+        {
+            mCursor = UI_CURSOR_NO;
+            gViewerWindow->getWindow()->setCursor( mCursor );
+            return;
+        }
+
+        if (hit_obj->isAttachment() && !hit_obj->isHUDAttachment())
+        {
+            LLVOAvatar* avatar = LLVOAvatar::findAvatarFromAttachment( hit_obj );
+            if (!avatar)
+            {
+                mLastAccept = ACCEPT_NO;
+                mCursor = UI_CURSOR_NO;
+                gViewerWindow->getWindow()->setCursor( mCursor );
+                return;
+            }
+            hit_obj = avatar;
+        }
+
+        if (hit_obj->isAvatar())
+        {
+            if (((LLVOAvatar*) hit_obj)->isSelf())
+            {
+                target = DT_SELF;
+                hit_face = -1;
+            }
+            else
+            {
+                target = DT_AVATAR;
+                hit_face = -1;
+            }
+        }
+        else
+        {
+            target = DT_OBJECT;
+            hit_face = pick_info.mObjectFace;
+            highlight_object = true;
+        }
+    }
+    else if (pick_info.mPickType == LLPickInfo::PICK_LAND)
+    {
+        target = DT_LAND;
+        hit_face = -1;
+    }
+
+    mLastAccept = ACCEPT_YES_MULTI;
+
+    for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
+    {
+        const S32 item_index = mCurItemIndex;
+        const EDragAndDropType dad_type = mCargoTypes[item_index];
+        // Call the right implementation function
+        mLastAccept = (EAcceptance)llmin(
+            (U32)mLastAccept,
+            (U32)callMemberFunction(*this,
+                                    LLDragAndDropDictionary::instance().get(dad_type, target))
+                (hit_obj, hit_face, pick_info.mKeyMask, FALSE));
+    }
+
+    if (mDrop && ((U32)mLastAccept >= ACCEPT_YES_COPY_SINGLE))
+    {
+        // if target allows multi-drop or there is only one item being dropped, go ahead
+        if ((mLastAccept >= ACCEPT_YES_COPY_MULTI) || (mCargoIDs.size() == 1))
+        {
+            // Target accepts multi, or cargo is a single-drop
+            for (mCurItemIndex = 0; mCurItemIndex < (S32)mCargoIDs.size(); mCurItemIndex++)
+            {
+                const S32 item_index = mCurItemIndex;
+                const EDragAndDropType dad_type = mCargoTypes[item_index];
+                // Call the right implementation function
+                callMemberFunction(*this, LLDragAndDropDictionary::instance().get(dad_type, target))
+                    (hit_obj, hit_face, pick_info.mKeyMask, TRUE);
+            }
+        }
+        else
+        {
+            // Target does not accept multi, but cargo is multi
+            mLastAccept = ACCEPT_NO;
+        }
+    }
+
+    if (highlight_object && mLastAccept > ACCEPT_NO_LOCKED)
+    {
+        // if any item being dragged will be applied to the object under our cursor
+        // highlight that object
+        for (S32 i = 0; i < (S32)mCargoIDs.size(); i++)
+        {
+            if (mCargoTypes[i] != DAD_OBJECT || (pick_info.mKeyMask & MASK_CONTROL))
+            {
+                LLSelectMgr::getInstance()->highlightObjectAndFamily(hit_obj);
+                break;
+            }
+        }
+    }
+    ECursorType cursor = acceptanceToCursor( mLastAccept );
+    gViewerWindow->getWindow()->setCursor( cursor );
+
+    mLastHitPos = pick_info.mPosGlobal;
+    mLastCameraPos = gAgentCamera.getCameraPositionGlobal();
+}
+
+// static
+BOOL LLToolDragAndDrop::handleDropMaterialProtections(LLViewerObject* hit_obj,
+                                                     LLInventoryItem* item,
+                                                     LLToolDragAndDrop::ESource source,
+                                                     const LLUUID& src_id)
+{
+    if (!item) return FALSE;
+
+    // Always succeed if....
+    // material is from the library
+    // or already in the contents of the object
+    if (SOURCE_LIBRARY == source)
+    {
+        // dropping a material from the library always just works.
+        return TRUE;
+    }
+
+    // In case the inventory has not been loaded (e.g. due to some recent operation
+    // causing a dirty inventory) and we can do an update, stall the user
+    // while fetching the inventory.
+    //
+    // Fetch if inventory is dirty and listener is present (otherwise we will not receive update)
+    if (hit_obj->isInventoryDirty() && hit_obj->hasInventoryListeners())
+    {
+        hit_obj->requestInventory();
+        LLSD args;
+        if (LLAssetType::AT_MATERIAL == item->getType())
+        {
+            args["ERROR_MESSAGE"] = "Unable to add material.\nPlease wait a few seconds and try again.";
+        }
+        else
+        {
+            args["ERROR_MESSAGE"] = "Unable to add texture.\nPlease wait a few seconds and try again.";
+        }
+        LLNotificationsUtil::add("ErrorMessage", args);
+        return FALSE;
+    }
+    // Make sure to verify both id and type since 'null'
+    // is a shared default for some asset types.
+    if (hit_obj->getInventoryItemByAsset(item->getAssetUUID(), item->getType()))
+    {
+        // if the asset is already in the object's inventory
+        // then it can always be added to a side.
+        // This saves some work if the task's inventory is already loaded
+        // and ensures that the asset item is only added once.
+        return TRUE;
+    }
+
+    LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
+    if (!item->getPermissions().allowOperationBy(PERM_COPY, gAgent.getID()))
+    {
+        // Check that we can add the material as inventory to the object
+        if (willObjectAcceptInventory(hit_obj,item) < ACCEPT_YES_COPY_SINGLE )
+        {
+            return FALSE;
+        }
+        // make sure the object has the material in it's inventory.
+        if (SOURCE_AGENT == source)
+        {
+            // Remove the material from local inventory. The server
+            // will actually remove the item from agent inventory.
+            gInventory.deleteObject(item->getUUID());
+            gInventory.notifyObservers();
+        }
+        else if (SOURCE_WORLD == source)
+        {
+            // *FIX: if the objects are in different regions, and the
+            // source region has crashed, you can bypass these
+            // permissions.
+            LLViewerObject* src_obj = gObjectList.findObject(src_id);
+            if (src_obj)
+            {
+                src_obj->removeInventory(item->getUUID());
+            }
+            else
+            {
+                LL_WARNS() << "Unable to find source object." << LL_ENDL;
+                return FALSE;
+            }
+        }
+        // Add the asset item to the target object's inventory.
+        if (LLAssetType::AT_TEXTURE == new_item->getType()
+            || LLAssetType::AT_MATERIAL == new_item->getType())
+        {
+            hit_obj->updateMaterialInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
+        }
+        else
+        {
+            hit_obj->updateInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
+        }
+        // Force the object to update and refetch its inventory so it has this asset.
+        hit_obj->dirtyInventory();
+        hit_obj->requestInventory();
+        // TODO: Check to see if adding the item was successful; if not, then
+        // we should return false here. This will requre a separate listener
+        // since without listener, we have no way to receive update
+    }
+    else if (!item->getPermissions().allowOperationBy(PERM_TRANSFER,
+                                                     gAgent.getID()))
+    {
+        // Check that we can add the asset as inventory to the object
+        if (willObjectAcceptInventory(hit_obj,item) < ACCEPT_YES_COPY_SINGLE )
+        {
+            return FALSE;
+        }
+        // *FIX: may want to make sure agent can paint hit_obj.
+
+        // Add the asset item to the target object's inventory.
+        if (LLAssetType::AT_TEXTURE == new_item->getType()
+            || LLAssetType::AT_MATERIAL == new_item->getType())
+        {
+            hit_obj->updateMaterialInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
+        }
+        else
+        {
+            hit_obj->updateInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
+        }
+        // Force the object to update and refetch its inventory so it has this asset.
+        hit_obj->dirtyInventory();
+        hit_obj->requestInventory();
+        // TODO: Check to see if adding the item was successful; if not, then
+        // we should return false here. This will requre a separate listener
+        // since without listener, we have no way to receive update
+    }
+    else if (LLAssetType::AT_MATERIAL == new_item->getType() &&
+             !item->getPermissions().allowOperationBy(PERM_MODIFY, gAgent.getID()))
+    {
+        // Check that we can add the material as inventory to the object
+        if (willObjectAcceptInventory(hit_obj,item) < ACCEPT_YES_COPY_SINGLE )
+        {
+            return FALSE;
+        }
+        // *FIX: may want to make sure agent can paint hit_obj.
+
+        // Add the material item to the target object's inventory.
+        hit_obj->updateMaterialInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
+
+        // Force the object to update and refetch its inventory so it has this material.
+        hit_obj->dirtyInventory();
+        hit_obj->requestInventory();
+        // TODO: Check to see if adding the item was successful; if not, then
+        // we should return false here. This will requre a separate listener
+        // since without listener, we have no way to receive update
+    }
+    return TRUE;
+}
+
+void set_texture_to_material(LLViewerObject* hit_obj,
+                             S32 hit_face,
+                             const LLUUID& asset_id,
+                             LLGLTFMaterial::TextureInfo drop_channel)
+{
+    LLTextureEntry* te = hit_obj->getTE(hit_face);
+    if (!te)
+    {
+        return;
+    }
+
+    const LLUUID base_mat_id = hit_obj->getRenderMaterialID(hit_face);
+    if (base_mat_id.isNull())
+    {
+        return;
+    }
+
+    if (hit_obj->isInventoryDirty() && hit_obj->hasInventoryListeners())
+    {
+        hit_obj->requestInventory();
+        return;
+    }
+
+    LLViewerInventoryItem* mat_item = hit_obj->getInventoryItemByAsset(base_mat_id);
+    if (mat_item && !mat_item->getPermissions().allowModifyBy(gAgentID))
+    {
+        return;
+    }
+
+    LLPointer<LLGLTFMaterial> material = te->getGLTFMaterialOverride();
+
+    // make a copy to not invalidate existing
+    // material for multiple objects
+    if (material.isNull())
+    {
+        // Start with a material override which does not make any changes
+        material = new LLGLTFMaterial();
+    }
+    else
+    {
+        material = new LLGLTFMaterial(*material);
+    }
+
+    switch (drop_channel)
+    {
+        case LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR:
+        default:
+            {
+                material->setBaseColorId(asset_id);
+            }
+            break;
+
+        case LLGLTFMaterial::GLTF_TEXTURE_INFO_METALLIC_ROUGHNESS:
+            {
+                material->setOcclusionRoughnessMetallicId(asset_id);
+            }
+            break;
+
+        case LLGLTFMaterial::GLTF_TEXTURE_INFO_EMISSIVE:
+            {
+                material->setEmissiveId(asset_id);
+            }
+            break;
+
+        case LLGLTFMaterial::GLTF_TEXTURE_INFO_NORMAL:
+            {
+                material->setNormalId(asset_id);
+            }
+            break;
+    }
+    LLGLTFMaterialList::queueModify(hit_obj, hit_face, material);
+}
+
+void LLToolDragAndDrop::dropTextureAllFaces(LLViewerObject* hit_obj,
+                                            LLInventoryItem* item,
+                                            LLToolDragAndDrop::ESource source,
+                                            const LLUUID& src_id,
+                                            bool remove_pbr)
+{
+    if (!item)
+    {
+        LL_WARNS() << "LLToolDragAndDrop::dropTextureAllFaces no texture item." << LL_ENDL;
+        return;
+    }
+    S32 num_faces = hit_obj->getNumTEs();
+    bool has_non_pbr_faces = false;
+    for (S32 face = 0; face < num_faces; face++)
+    {
+        if (hit_obj->getRenderMaterialID(face).isNull())
+        {
+            has_non_pbr_faces = true;
+            break;
+        }
+    }
+
+    if (has_non_pbr_faces || remove_pbr)
+    {
+        BOOL res = handleDropMaterialProtections(hit_obj, item, source, src_id);
+        if (!res)
+        {
+            return;
+        }
+    }
+    LLUUID asset_id = item->getAssetUUID();
+
+    // Overrides require textures to be copy and transfer free
+    LLPermissions item_permissions = item->getPermissions();
+    bool allow_adding_to_override = item_permissions.allowOperationBy(PERM_COPY, gAgent.getID());
+    allow_adding_to_override &= item_permissions.allowOperationBy(PERM_TRANSFER, gAgent.getID());
+
+    LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(asset_id);
+    add(LLStatViewer::EDIT_TEXTURE, 1);
+    for( S32 face = 0; face < num_faces; face++ )
+    {
+        if (remove_pbr)
+        {
             hit_obj->setRenderMaterialID(face, LLUUID::null);
             hit_obj->setTEImage(face, image);
             dialog_refresh_all();
@@ -1206,11 +1206,11 @@ void LLToolDragAndDrop::dropTextureAllFaces(LLViewerObject* hit_obj,
         {
             set_texture_to_material(hit_obj, face, asset_id, LLGLTFMaterial::GLTF_TEXTURE_INFO_BASE_COLOR);
         }
-	}
+    }
 
-	// send the update to the simulator
+    // send the update to the simulator
     LLGLTFMaterialList::flushUpdates(nullptr);
-	hit_obj->sendTEUpdate();
+    hit_obj->sendTEUpdate();
 }
 
 void LLToolDragAndDrop::dropMaterial(LLViewerObject* hit_obj,
@@ -1334,34 +1334,34 @@ void LLToolDragAndDrop::dropMaterialAllFaces(LLViewerObject* hit_obj,
 
 
 void LLToolDragAndDrop::dropMesh(LLViewerObject* hit_obj,
-								 LLInventoryItem* item,
-								 LLToolDragAndDrop::ESource source,
-								 const LLUUID& src_id)
-{
-	if (!item)
-	{
-		LL_WARNS() << "no inventory item." << LL_ENDL;
-		return;
-	}
-	LLUUID asset_id = item->getAssetUUID();
-	BOOL success = handleDropMaterialProtections(hit_obj, item, source, src_id);
-	if(!success)
-	{
-		return;
-	}
-
-	LLSculptParams sculpt_params;
-	sculpt_params.setSculptTexture(asset_id, LL_SCULPT_TYPE_MESH);
-	hit_obj->setParameterEntry(LLNetworkData::PARAMS_SCULPT, sculpt_params, TRUE);
-	
-	dialog_refresh_all();
-}
-
-void LLToolDragAndDrop::dropTexture(LLViewerObject* hit_obj,
-                                    S32 hit_face,
-                                    LLInventoryItem* item,
-                                    ESource source,
-                                    const LLUUID& src_id,
+                                 LLInventoryItem* item,
+                                 LLToolDragAndDrop::ESource source,
+                                 const LLUUID& src_id)
+{
+    if (!item)
+    {
+        LL_WARNS() << "no inventory item." << LL_ENDL;
+        return;
+    }
+    LLUUID asset_id = item->getAssetUUID();
+    BOOL success = handleDropMaterialProtections(hit_obj, item, source, src_id);
+    if(!success)
+    {
+        return;
+    }
+
+    LLSculptParams sculpt_params;
+    sculpt_params.setSculptTexture(asset_id, LL_SCULPT_TYPE_MESH);
+    hit_obj->setParameterEntry(LLNetworkData::PARAMS_SCULPT, sculpt_params, TRUE);
+
+    dialog_refresh_all();
+}
+
+void LLToolDragAndDrop::dropTexture(LLViewerObject* hit_obj,
+                                    S32 hit_face,
+                                    LLInventoryItem* item,
+                                    ESource source,
+                                    const LLUUID& src_id,
                                     bool all_faces,
                                     bool remove_pbr,
                                     S32 tex_channel)
@@ -1459,19 +1459,19 @@ void LLToolDragAndDrop::dropTexture(LLViewerObject* hit_obj,
 }
 
 void LLToolDragAndDrop::dropTextureOneFace(LLViewerObject* hit_obj,
-										   S32 hit_face,
-										   LLInventoryItem* item,
-										   LLToolDragAndDrop::ESource source,
-										   const LLUUID& src_id,
+                                           S32 hit_face,
+                                           LLInventoryItem* item,
+                                           LLToolDragAndDrop::ESource source,
+                                           const LLUUID& src_id,
                                            bool remove_pbr,
                                            S32 tex_channel)
 {
-	if (hit_face == -1) return;
-	if (!item)
-	{
-		LL_WARNS() << "LLToolDragAndDrop::dropTextureOneFace no texture item." << LL_ENDL;
-		return;
-	}
+    if (hit_face == -1) return;
+    if (!item)
+    {
+        LL_WARNS() << "LLToolDragAndDrop::dropTextureOneFace no texture item." << LL_ENDL;
+        return;
+    }
 
     LLUUID asset_id = item->getAssetUUID();
 
@@ -1495,635 +1495,635 @@ void LLToolDragAndDrop::dropTextureOneFace(LLViewerObject* hit_obj,
         }
         return;
     }
-	BOOL success = handleDropMaterialProtections(hit_obj, item, source, src_id);
-	if (!success)
-	{
-		return;
-	}
+    BOOL success = handleDropMaterialProtections(hit_obj, item, source, src_id);
+    if (!success)
+    {
+        return;
+    }
     if (remove_pbr)
     {
         hit_obj->setRenderMaterialID(hit_face, LLUUID::null);
     }
 
-	// update viewer side image in anticipation of update from simulator
-	LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(asset_id);
-	add(LLStatViewer::EDIT_TEXTURE, 1);
+    // update viewer side image in anticipation of update from simulator
+    LLViewerTexture* image = LLViewerTextureManager::getFetchedTexture(asset_id);
+    add(LLStatViewer::EDIT_TEXTURE, 1);
 
-	LLTextureEntry* tep = hit_obj->getTE(hit_face);
+    LLTextureEntry* tep = hit_obj->getTE(hit_face);
 
-	LLPanelFace* panel_face = gFloaterTools->getPanelFace();
+    LLPanelFace* panel_face = gFloaterTools->getPanelFace();
 
-	if (gFloaterTools->getVisible() && panel_face)
-	{
+    if (gFloaterTools->getVisible() && panel_face)
+    {
         tex_channel = (tex_channel > -1) ? tex_channel : panel_face->getTextureDropChannel();
         switch (tex_channel)
-		{
+        {
 
-		case 0:
-		default:
-			{
-				hit_obj->setTEImage(hit_face, image);
-			}
-			break;
+        case 0:
+        default:
+            {
+                hit_obj->setTEImage(hit_face, image);
+            }
+            break;
 
-		case 1:
+        case 1:
             if (tep)
-			{
-				LLMaterialPtr old_mat = tep->getMaterialParams();
-				LLMaterialPtr new_mat = panel_face->createDefaultMaterial(old_mat);
-				new_mat->setNormalID(asset_id);
-				tep->setMaterialParams(new_mat);
-				hit_obj->setTENormalMap(hit_face, asset_id);
-				LLMaterialMgr::getInstance()->put(hit_obj->getID(), hit_face, *new_mat);
-			}
-			break;
-
-		case 2:
+            {
+                LLMaterialPtr old_mat = tep->getMaterialParams();
+                LLMaterialPtr new_mat = panel_face->createDefaultMaterial(old_mat);
+                new_mat->setNormalID(asset_id);
+                tep->setMaterialParams(new_mat);
+                hit_obj->setTENormalMap(hit_face, asset_id);
+                LLMaterialMgr::getInstance()->put(hit_obj->getID(), hit_face, *new_mat);
+            }
+            break;
+
+        case 2:
             if (tep)
-			{
-				LLMaterialPtr old_mat = tep->getMaterialParams();
-				LLMaterialPtr new_mat = panel_face->createDefaultMaterial(old_mat);
-				new_mat->setSpecularID(asset_id);
-				tep->setMaterialParams(new_mat);
-				hit_obj->setTESpecularMap(hit_face, asset_id);
-				LLMaterialMgr::getInstance()->put(hit_obj->getID(), hit_face, *new_mat);
-			}
-			break;
-		}
-	}
-	else
-	{
-		hit_obj->setTEImage(hit_face, image);
-	}
-	
-	dialog_refresh_all();
-
-	// send the update to the simulator
-	hit_obj->sendTEUpdate();
+            {
+                LLMaterialPtr old_mat = tep->getMaterialParams();
+                LLMaterialPtr new_mat = panel_face->createDefaultMaterial(old_mat);
+                new_mat->setSpecularID(asset_id);
+                tep->setMaterialParams(new_mat);
+                hit_obj->setTESpecularMap(hit_face, asset_id);
+                LLMaterialMgr::getInstance()->put(hit_obj->getID(), hit_face, *new_mat);
+            }
+            break;
+        }
+    }
+    else
+    {
+        hit_obj->setTEImage(hit_face, image);
+    }
+
+    dialog_refresh_all();
+
+    // send the update to the simulator
+    hit_obj->sendTEUpdate();
 }
 
 
 void LLToolDragAndDrop::dropScript(LLViewerObject* hit_obj,
-								   LLInventoryItem* item,
-								   BOOL active,
-								   ESource source,
-								   const LLUUID& src_id)
-{
-	// *HACK: In order to resolve SL-22177, we need to block drags
-	// from notecards and objects onto other objects.
-	if ((SOURCE_WORLD == LLToolDragAndDrop::getInstance()->mSource)
-	   || (SOURCE_NOTECARD == LLToolDragAndDrop::getInstance()->mSource))
-	{
-		LL_WARNS() << "Call to LLToolDragAndDrop::dropScript() from world"
-			<< " or notecard." << LL_ENDL;
-		return;
-	}
-	if (hit_obj && item)
-	{
-		LLPointer<LLViewerInventoryItem> new_script = new LLViewerInventoryItem(item);
-		if (!item->getPermissions().allowCopyBy(gAgent.getID()))
-		{
-			if (SOURCE_AGENT == source)
-			{
-				// Remove the script from local inventory. The server
-				// will actually remove the item from agent inventory.
-				gInventory.deleteObject(item->getUUID());
-				gInventory.notifyObservers();
-			}
-			else if (SOURCE_WORLD == source)
-			{
-				// *FIX: if the objects are in different regions, and
-				// the source region has crashed, you can bypass
-				// these permissions.
-				LLViewerObject* src_obj = gObjectList.findObject(src_id);
-				if (src_obj)
-				{
-					src_obj->removeInventory(item->getUUID());
-				}
-				else
-				{
-					LL_WARNS() << "Unable to find source object." << LL_ENDL;
-					return;
-				}
-			}
-		}
-		hit_obj->saveScript(new_script, active, true);
-		gFloaterTools->dirty();
-
-		// VEFFECT: SetScript
-		if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
-		{
-			LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
-			effectp->setSourceObject(gAgentAvatarp);
-			effectp->setTargetObject(hit_obj);
-			effectp->setDuration(LL_HUD_DUR_SHORT);
-			effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-		}
-	}
+                                   LLInventoryItem* item,
+                                   BOOL active,
+                                   ESource source,
+                                   const LLUUID& src_id)
+{
+    // *HACK: In order to resolve SL-22177, we need to block drags
+    // from notecards and objects onto other objects.
+    if ((SOURCE_WORLD == LLToolDragAndDrop::getInstance()->mSource)
+       || (SOURCE_NOTECARD == LLToolDragAndDrop::getInstance()->mSource))
+    {
+        LL_WARNS() << "Call to LLToolDragAndDrop::dropScript() from world"
+            << " or notecard." << LL_ENDL;
+        return;
+    }
+    if (hit_obj && item)
+    {
+        LLPointer<LLViewerInventoryItem> new_script = new LLViewerInventoryItem(item);
+        if (!item->getPermissions().allowCopyBy(gAgent.getID()))
+        {
+            if (SOURCE_AGENT == source)
+            {
+                // Remove the script from local inventory. The server
+                // will actually remove the item from agent inventory.
+                gInventory.deleteObject(item->getUUID());
+                gInventory.notifyObservers();
+            }
+            else if (SOURCE_WORLD == source)
+            {
+                // *FIX: if the objects are in different regions, and
+                // the source region has crashed, you can bypass
+                // these permissions.
+                LLViewerObject* src_obj = gObjectList.findObject(src_id);
+                if (src_obj)
+                {
+                    src_obj->removeInventory(item->getUUID());
+                }
+                else
+                {
+                    LL_WARNS() << "Unable to find source object." << LL_ENDL;
+                    return;
+                }
+            }
+        }
+        hit_obj->saveScript(new_script, active, true);
+        gFloaterTools->dirty();
+
+        // VEFFECT: SetScript
+        if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
+        {
+            LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
+            effectp->setSourceObject(gAgentAvatarp);
+            effectp->setTargetObject(hit_obj);
+            effectp->setDuration(LL_HUD_DUR_SHORT);
+            effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+        }
+    }
 }
 
 void LLToolDragAndDrop::dropObject(LLViewerObject* raycast_target,
-				   BOOL bypass_sim_raycast,
-				   BOOL from_task_inventory,
-				   BOOL remove_from_inventory)
+                   BOOL bypass_sim_raycast,
+                   BOOL from_task_inventory,
+                   BOOL remove_from_inventory)
 {
-	LLViewerRegion* regionp = LLWorld::getInstance()->getRegionFromPosGlobal(mLastHitPos);
-	if (!regionp)
-	{
-		LL_WARNS() << "Couldn't find region to rez object" << LL_ENDL;
-		return;
-	}
+    LLViewerRegion* regionp = LLWorld::getInstance()->getRegionFromPosGlobal(mLastHitPos);
+    if (!regionp)
+    {
+        LL_WARNS() << "Couldn't find region to rez object" << LL_ENDL;
+        return;
+    }
 
 
 // [RLVa:KB] - Checked: 2010-03-23 (RLVa-1.2.0e) | Modified: RLVa-1.2.0a
-	// Fallback in case there's a new code path that leads here (see behaviour notes)
-	if ( (rlv_handler_t::isEnabled()) && ((gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) || (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT))) )
-	{
-		return;
-	}
+    // Fallback in case there's a new code path that leads here (see behaviour notes)
+    if ( (rlv_handler_t::isEnabled()) && ((gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) || (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT))) )
+    {
+        return;
+    }
 // [/RLVa:KB]
 
-	//LL_INFOS() << "Rezzing object" << LL_ENDL;
-	make_ui_sound("UISndObjectRezIn");
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return;
-	
-	//if (regionp
-	//	&& (regionp->getRegionFlag(REGION_FLAGS_SANDBOX)))
-	//{
-	//	LLFirstUse::useSandbox();
-	//}
-	// check if it cannot be copied, and mark as remove if it is -
-	// this will remove the object from inventory after rez. Only
-	// bother with this check if we would not normally remove from
-	// inventory.
-	if (!remove_from_inventory
-		&& !item->getPermissions().allowCopyBy(gAgent.getID()))
-	{
-		remove_from_inventory = TRUE;
-	}
-
-	// Limit raycast to a single object.  
-	// Speeds up server raycast + avoid problems with server ray
-	// hitting objects that were clipped by the near plane or culled
-	// on the viewer.
-	LLUUID ray_target_id;
-	if (raycast_target)
-	{
-		ray_target_id = raycast_target->getID();
-	}
-	else
-	{
-		ray_target_id.setNull();
-	}
-
-	// Check if it's in the trash.
-	bool is_in_trash = false;
-	const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-	if (gInventory.isObjectDescendentOf(item->getUUID(), trash_id))
-	{
-		is_in_trash = true;
-	}
-
-	LLUUID source_id = from_task_inventory ? mSourceID : LLUUID::null;
-
-	// Select the object only if we're editing.
-	BOOL rez_selected = LLToolMgr::getInstance()->inEdit();
-
-
-	LLVector3 ray_start = regionp->getPosRegionFromGlobal(mLastCameraPos);
-	LLVector3 ray_end   = regionp->getPosRegionFromGlobal(mLastHitPos);
-	// currently the ray's end point is an approximation,
-	// and is sometimes too short (causing failure.)  so we
-	// double the ray's length:
-	if (bypass_sim_raycast == FALSE)
-	{
-		LLVector3 ray_direction = ray_start - ray_end;
-		ray_end = ray_end - ray_direction;
-	}
-	
-	
-	// Message packing code should be it's own uninterrupted block
-	LLMessageSystem* msg = gMessageSystem;
-	if (mSource == SOURCE_NOTECARD)
-	{
-		msg->newMessageFast(_PREHASH_RezObjectFromNotecard);
-	}
-	else
-	{
-		msg->newMessageFast(_PREHASH_RezObject);
-	}
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID,  gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID,  gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupForRezzing());
-
-	msg->nextBlockFast(_PREHASH_RezData);
-	// if it's being rezzed from task inventory, we need to enable
-	// saving it back into the task inventory.
-	// *FIX: We can probably compress this to a single byte, since I
-	// think folderid == mSourceID. This will be a later
-	// optimization.
-	msg->addUUIDFast(_PREHASH_FromTaskID, source_id);
-	msg->addU8Fast(_PREHASH_BypassRaycast, (U8) bypass_sim_raycast);
-	msg->addVector3Fast(_PREHASH_RayStart, ray_start);
-	msg->addVector3Fast(_PREHASH_RayEnd, ray_end);
-	msg->addUUIDFast(_PREHASH_RayTargetID, ray_target_id );
-	msg->addBOOLFast(_PREHASH_RayEndIsIntersection, FALSE);
-	msg->addBOOLFast(_PREHASH_RezSelected, rez_selected);
-	msg->addBOOLFast(_PREHASH_RemoveItem, remove_from_inventory);
-
-	// deal with permissions slam logic
-	pack_permissions_slam(msg, item->getFlags(), item->getPermissions());
-
-	LLUUID folder_id = item->getParentUUID();
-	if ((SOURCE_LIBRARY == mSource) || (is_in_trash))
-	{
-		// since it's coming from the library or trash, we want to not
-		// 'take' it back to the same place.
-		item->setParent(LLUUID::null);
-		// *TODO this code isn't working - the parent (FolderID) is still
-		// set when the object is "taken".  so code on the "take" side is
-		// checking for trash and library as well (llviewermenu.cpp)
-	}
-	if (mSource == SOURCE_NOTECARD)
-	{
-		msg->nextBlockFast(_PREHASH_NotecardData);
-		msg->addUUIDFast(_PREHASH_NotecardItemID, mSourceID);
-		msg->addUUIDFast(_PREHASH_ObjectID, mObjectID);
-		msg->nextBlockFast(_PREHASH_InventoryData);
-		msg->addUUIDFast(_PREHASH_ItemID, item->getUUID());
-	}
-	else
-	{
-		msg->nextBlockFast(_PREHASH_InventoryData);
-		item->packMessage(msg);
-	}
-	msg->sendReliable(regionp->getHost());
-	// back out the change. no actual internal changes take place.
-	item->setParent(folder_id); 
-
-	// If we're going to select it, get ready for the incoming
-	// selected object.
-	if (rez_selected)
-	{
-		LLSelectMgr::getInstance()->deselectAll();
-		gViewerWindow->getWindow()->incBusyCount();
-	}
-
-	if (remove_from_inventory)
-	{
-		// Delete it from inventory immediately so that users cannot
-		// easily bypass copy protection in laggy situations. If the
-		// rez fails, we will put it back on the server.
-		gInventory.deleteObject(item->getUUID());
-		gInventory.notifyObservers();
-	}
-
-	// VEFFECT: DropObject
-	if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
-	{
-		LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
-		effectp->setSourceObject(gAgentAvatarp);
-		effectp->setPositionGlobal(mLastHitPos);
-		effectp->setDuration(LL_HUD_DUR_SHORT);
-		effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-	}
-
-	add(LLStatViewer::OBJECT_REZ, 1);
+    //LL_INFOS() << "Rezzing object" << LL_ENDL;
+    make_ui_sound("UISndObjectRezIn");
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return;
+
+    //if (regionp
+    //  && (regionp->getRegionFlag(REGION_FLAGS_SANDBOX)))
+    //{
+    //  LLFirstUse::useSandbox();
+    //}
+    // check if it cannot be copied, and mark as remove if it is -
+    // this will remove the object from inventory after rez. Only
+    // bother with this check if we would not normally remove from
+    // inventory.
+    if (!remove_from_inventory
+        && !item->getPermissions().allowCopyBy(gAgent.getID()))
+    {
+        remove_from_inventory = TRUE;
+    }
+
+    // Limit raycast to a single object.
+    // Speeds up server raycast + avoid problems with server ray
+    // hitting objects that were clipped by the near plane or culled
+    // on the viewer.
+    LLUUID ray_target_id;
+    if (raycast_target)
+    {
+        ray_target_id = raycast_target->getID();
+    }
+    else
+    {
+        ray_target_id.setNull();
+    }
+
+    // Check if it's in the trash.
+    bool is_in_trash = false;
+    const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+    if (gInventory.isObjectDescendentOf(item->getUUID(), trash_id))
+    {
+        is_in_trash = true;
+    }
+
+    LLUUID source_id = from_task_inventory ? mSourceID : LLUUID::null;
+
+    // Select the object only if we're editing.
+    BOOL rez_selected = LLToolMgr::getInstance()->inEdit();
+
+
+    LLVector3 ray_start = regionp->getPosRegionFromGlobal(mLastCameraPos);
+    LLVector3 ray_end   = regionp->getPosRegionFromGlobal(mLastHitPos);
+    // currently the ray's end point is an approximation,
+    // and is sometimes too short (causing failure.)  so we
+    // double the ray's length:
+    if (bypass_sim_raycast == FALSE)
+    {
+        LLVector3 ray_direction = ray_start - ray_end;
+        ray_end = ray_end - ray_direction;
+    }
+
+
+    // Message packing code should be it's own uninterrupted block
+    LLMessageSystem* msg = gMessageSystem;
+    if (mSource == SOURCE_NOTECARD)
+    {
+        msg->newMessageFast(_PREHASH_RezObjectFromNotecard);
+    }
+    else
+    {
+        msg->newMessageFast(_PREHASH_RezObject);
+    }
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID,  gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID,  gAgent.getSessionID());
+    msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupForRezzing());
+
+    msg->nextBlockFast(_PREHASH_RezData);
+    // if it's being rezzed from task inventory, we need to enable
+    // saving it back into the task inventory.
+    // *FIX: We can probably compress this to a single byte, since I
+    // think folderid == mSourceID. This will be a later
+    // optimization.
+    msg->addUUIDFast(_PREHASH_FromTaskID, source_id);
+    msg->addU8Fast(_PREHASH_BypassRaycast, (U8) bypass_sim_raycast);
+    msg->addVector3Fast(_PREHASH_RayStart, ray_start);
+    msg->addVector3Fast(_PREHASH_RayEnd, ray_end);
+    msg->addUUIDFast(_PREHASH_RayTargetID, ray_target_id );
+    msg->addBOOLFast(_PREHASH_RayEndIsIntersection, FALSE);
+    msg->addBOOLFast(_PREHASH_RezSelected, rez_selected);
+    msg->addBOOLFast(_PREHASH_RemoveItem, remove_from_inventory);
+
+    // deal with permissions slam logic
+    pack_permissions_slam(msg, item->getFlags(), item->getPermissions());
+
+    LLUUID folder_id = item->getParentUUID();
+    if ((SOURCE_LIBRARY == mSource) || (is_in_trash))
+    {
+        // since it's coming from the library or trash, we want to not
+        // 'take' it back to the same place.
+        item->setParent(LLUUID::null);
+        // *TODO this code isn't working - the parent (FolderID) is still
+        // set when the object is "taken".  so code on the "take" side is
+        // checking for trash and library as well (llviewermenu.cpp)
+    }
+    if (mSource == SOURCE_NOTECARD)
+    {
+        msg->nextBlockFast(_PREHASH_NotecardData);
+        msg->addUUIDFast(_PREHASH_NotecardItemID, mSourceID);
+        msg->addUUIDFast(_PREHASH_ObjectID, mObjectID);
+        msg->nextBlockFast(_PREHASH_InventoryData);
+        msg->addUUIDFast(_PREHASH_ItemID, item->getUUID());
+    }
+    else
+    {
+        msg->nextBlockFast(_PREHASH_InventoryData);
+        item->packMessage(msg);
+    }
+    msg->sendReliable(regionp->getHost());
+    // back out the change. no actual internal changes take place.
+    item->setParent(folder_id);
+
+    // If we're going to select it, get ready for the incoming
+    // selected object.
+    if (rez_selected)
+    {
+        LLSelectMgr::getInstance()->deselectAll();
+        gViewerWindow->getWindow()->incBusyCount();
+    }
+
+    if (remove_from_inventory)
+    {
+        // Delete it from inventory immediately so that users cannot
+        // easily bypass copy protection in laggy situations. If the
+        // rez fails, we will put it back on the server.
+        gInventory.deleteObject(item->getUUID());
+        gInventory.notifyObservers();
+    }
+
+    // VEFFECT: DropObject
+    if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
+    {
+        LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
+        effectp->setSourceObject(gAgentAvatarp);
+        effectp->setPositionGlobal(mLastHitPos);
+        effectp->setDuration(LL_HUD_DUR_SHORT);
+        effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+    }
+
+    add(LLStatViewer::OBJECT_REZ, 1);
 }
 
 void LLToolDragAndDrop::dropInventory(LLViewerObject* hit_obj,
-									  LLInventoryItem* item,
-									  LLToolDragAndDrop::ESource source,
-									  const LLUUID& src_id)
-{
-	// *HACK: In order to resolve SL-22177, we need to block drags
-	// from notecards and objects onto other objects.
-	if ((SOURCE_WORLD == LLToolDragAndDrop::getInstance()->mSource)
-	   || (SOURCE_NOTECARD == LLToolDragAndDrop::getInstance()->mSource))
-	{
-		LL_WARNS() << "Call to LLToolDragAndDrop::dropInventory() from world"
-			<< " or notecard." << LL_ENDL;
-		return;
-	}
-
-	LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
-	time_t creation_date = time_corrected();
-	new_item->setCreationDate(creation_date);
-
-	if (!item->getPermissions().allowCopyBy(gAgent.getID()))
-	{
-		if (SOURCE_AGENT == source)
-		{
-			// Remove the inventory item from local inventory. The
-			// server will actually remove the item from agent
-			// inventory.
-			gInventory.deleteObject(item->getUUID());
-			gInventory.notifyObservers();
-		}
-		else if (SOURCE_WORLD == source)
-		{
-			// *FIX: if the objects are in different regions, and the
-			// source region has crashed, you can bypass these
-			// permissions.
-			LLViewerObject* src_obj = gObjectList.findObject(src_id);
-			if (src_obj)
-			{
-				src_obj->removeInventory(item->getUUID());
-			}
-			else
-			{
-				LL_WARNS() << "Unable to find source object." << LL_ENDL;
-				return;
-			}
-		}
-	}
-	hit_obj->updateInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
-	if (LLFloaterReg::instanceVisible("build"))
-	{
-		// *FIX: only show this if panel not expanded?
-		LLFloaterReg::showInstance("build", "Content");
-	}
-
-	// VEFFECT: AddToInventory
-	if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
-	{
-		LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
-		effectp->setSourceObject(gAgentAvatarp);
-		effectp->setTargetObject(hit_obj);
-		effectp->setDuration(LL_HUD_DUR_SHORT);
-		effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-	}
-	gFloaterTools->dirty();
+                                      LLInventoryItem* item,
+                                      LLToolDragAndDrop::ESource source,
+                                      const LLUUID& src_id)
+{
+    // *HACK: In order to resolve SL-22177, we need to block drags
+    // from notecards and objects onto other objects.
+    if ((SOURCE_WORLD == LLToolDragAndDrop::getInstance()->mSource)
+       || (SOURCE_NOTECARD == LLToolDragAndDrop::getInstance()->mSource))
+    {
+        LL_WARNS() << "Call to LLToolDragAndDrop::dropInventory() from world"
+            << " or notecard." << LL_ENDL;
+        return;
+    }
+
+    LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem(item);
+    time_t creation_date = time_corrected();
+    new_item->setCreationDate(creation_date);
+
+    if (!item->getPermissions().allowCopyBy(gAgent.getID()))
+    {
+        if (SOURCE_AGENT == source)
+        {
+            // Remove the inventory item from local inventory. The
+            // server will actually remove the item from agent
+            // inventory.
+            gInventory.deleteObject(item->getUUID());
+            gInventory.notifyObservers();
+        }
+        else if (SOURCE_WORLD == source)
+        {
+            // *FIX: if the objects are in different regions, and the
+            // source region has crashed, you can bypass these
+            // permissions.
+            LLViewerObject* src_obj = gObjectList.findObject(src_id);
+            if (src_obj)
+            {
+                src_obj->removeInventory(item->getUUID());
+            }
+            else
+            {
+                LL_WARNS() << "Unable to find source object." << LL_ENDL;
+                return;
+            }
+        }
+    }
+    hit_obj->updateInventory(new_item, TASK_INVENTORY_ITEM_KEY, true);
+    if (LLFloaterReg::instanceVisible("build"))
+    {
+        // *FIX: only show this if panel not expanded?
+        LLFloaterReg::showInstance("build", "Content");
+    }
+
+    // VEFFECT: AddToInventory
+    if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
+    {
+        LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
+        effectp->setSourceObject(gAgentAvatarp);
+        effectp->setTargetObject(hit_obj);
+        effectp->setDuration(LL_HUD_DUR_SHORT);
+        effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+    }
+    gFloaterTools->dirty();
 }
 
 // accessor that looks at permissions, copyability, and names of
 // inventory items to determine if a drop would be ok.
 EAcceptance LLToolDragAndDrop::willObjectAcceptInventory(LLViewerObject* obj, LLInventoryItem* item, EDragAndDropType type)
 {
-	// check the basics
-	if (!item || !obj) return ACCEPT_NO;
-	// HACK: downcast
-	LLViewerInventoryItem* vitem = (LLViewerInventoryItem*)item;
-	if (!vitem->isFinished() && (type != DAD_CATEGORY)
-	&& !(gInventory.isObjectDescendentOf(vitem->getUUID(), gLocalInventory)))
-	{
-		// Note: for DAD_CATEGORY we assume that folder version check passed and folder 
-		// is complete, meaning that items inside are up to date. 
-		// (isFinished() == false) at the moment shows that item was loaded from cache.
-		// Library or agent inventory only.
-		return ACCEPT_NO;
-	}
-	if (vitem->getIsLinkType()) return ACCEPT_NO; // No giving away links
-
-	// deny attempts to drop from an object onto itself. This is to
-	// help make sure that drops that are from an object to an object
-	// don't have to worry about order of evaluation. Think of this
-	// like check for self in assignment.
-	if(obj->getID() == item->getParentUUID())
-	{
-		return ACCEPT_NO;
-	}
-	
-	//BOOL copy = (perm.allowCopyBy(gAgent.getID(),
-	//							  gAgent.getGroupID())
-	//			 && (obj->mPermModify || obj->mFlagAllowInventoryAdd));
-	BOOL worn = FALSE;
-	LLVOAvatarSelf* my_avatar = NULL;
-	switch(item->getType())
-	{
-	case LLAssetType::AT_OBJECT:
-		my_avatar = gAgentAvatarp;
-		if(my_avatar && my_avatar->isWearingAttachment(item->getUUID()))
-		{
-				worn = TRUE;
-		}
-		break;
-	case LLAssetType::AT_BODYPART:
-	case LLAssetType::AT_CLOTHING:
-		if(gAgentWearables.isWearingItem(item->getUUID()))
-		{
-			worn = TRUE;
-		}
-		break;
-	case LLAssetType::AT_CALLINGCARD:
-		// Calling Cards in object are disabled for now
-		// because of incomplete LSL support. See STORM-1117.
-		return ACCEPT_NO;
-	default:
-			break;
-	}
-	const LLPermissions& perm = item->getPermissions();
-	BOOL modify = (obj->permModify() || obj->flagAllowInventoryAdd());
-	BOOL transfer = FALSE;
-	if((obj->permYouOwner() && (perm.getOwner() == gAgent.getID()))
-	   || perm.allowOperationBy(PERM_TRANSFER, gAgent.getID()))
-	{
-		transfer = TRUE;
-	}
-	BOOL volume = (LL_PCODE_VOLUME == obj->getPCode());
-	BOOL attached = obj->isAttachment();
-	BOOL unrestricted = ((perm.getMaskBase() & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED) ? TRUE : FALSE;
+    // check the basics
+    if (!item || !obj) return ACCEPT_NO;
+    // HACK: downcast
+    LLViewerInventoryItem* vitem = (LLViewerInventoryItem*)item;
+    if (!vitem->isFinished() && (type != DAD_CATEGORY)
+    && !(gInventory.isObjectDescendentOf(vitem->getUUID(), gLocalInventory)))
+    {
+        // Note: for DAD_CATEGORY we assume that folder version check passed and folder
+        // is complete, meaning that items inside are up to date.
+        // (isFinished() == false) at the moment shows that item was loaded from cache.
+        // Library or agent inventory only.
+        return ACCEPT_NO;
+    }
+    if (vitem->getIsLinkType()) return ACCEPT_NO; // No giving away links
+
+    // deny attempts to drop from an object onto itself. This is to
+    // help make sure that drops that are from an object to an object
+    // don't have to worry about order of evaluation. Think of this
+    // like check for self in assignment.
+    if(obj->getID() == item->getParentUUID())
+    {
+        return ACCEPT_NO;
+    }
+
+    //BOOL copy = (perm.allowCopyBy(gAgent.getID(),
+    //                            gAgent.getGroupID())
+    //           && (obj->mPermModify || obj->mFlagAllowInventoryAdd));
+    BOOL worn = FALSE;
+    LLVOAvatarSelf* my_avatar = NULL;
+    switch(item->getType())
+    {
+    case LLAssetType::AT_OBJECT:
+        my_avatar = gAgentAvatarp;
+        if(my_avatar && my_avatar->isWearingAttachment(item->getUUID()))
+        {
+                worn = TRUE;
+        }
+        break;
+    case LLAssetType::AT_BODYPART:
+    case LLAssetType::AT_CLOTHING:
+        if(gAgentWearables.isWearingItem(item->getUUID()))
+        {
+            worn = TRUE;
+        }
+        break;
+    case LLAssetType::AT_CALLINGCARD:
+        // Calling Cards in object are disabled for now
+        // because of incomplete LSL support. See STORM-1117.
+        return ACCEPT_NO;
+    default:
+            break;
+    }
+    const LLPermissions& perm = item->getPermissions();
+    BOOL modify = (obj->permModify() || obj->flagAllowInventoryAdd());
+    BOOL transfer = FALSE;
+    if((obj->permYouOwner() && (perm.getOwner() == gAgent.getID()))
+       || perm.allowOperationBy(PERM_TRANSFER, gAgent.getID()))
+    {
+        transfer = TRUE;
+    }
+    BOOL volume = (LL_PCODE_VOLUME == obj->getPCode());
+    BOOL attached = obj->isAttachment();
+    BOOL unrestricted = ((perm.getMaskBase() & PERM_ITEM_UNRESTRICTED) == PERM_ITEM_UNRESTRICTED) ? TRUE : FALSE;
 
 // [RLVa:KB] - Checked: 2010-03-31 (RLVa-1.2.0c) | Modified: RLVa-1.0.0c
-	if (rlv_handler_t::isEnabled())
-	{
-		const LLViewerObject* pObjRoot = obj->getRootEdit();
-		if (gRlvAttachmentLocks.isLockedAttachment(pObjRoot))
-		{
-			return ACCEPT_NO_LOCKED;		// Disallow inventory drops on a locked attachment
-		}
-		else if ( (gRlvHandler.hasBehaviour(RLV_BHVR_UNSIT)) || (gRlvHandler.hasBehaviour(RLV_BHVR_SITTP)) )
-		{
-			if ( (isAgentAvatarValid()) && (gAgentAvatarp->isSitting()) && (gAgentAvatarp->getRoot() == pObjRoot) )
-				return ACCEPT_NO_LOCKED;	// ... or on a linkset the avie is sitting on under @unsit=n/@sittp=n
-		}
-	}
+    if (rlv_handler_t::isEnabled())
+    {
+        const LLViewerObject* pObjRoot = obj->getRootEdit();
+        if (gRlvAttachmentLocks.isLockedAttachment(pObjRoot))
+        {
+            return ACCEPT_NO_LOCKED;        // Disallow inventory drops on a locked attachment
+        }
+        else if ( (gRlvHandler.hasBehaviour(RLV_BHVR_UNSIT)) || (gRlvHandler.hasBehaviour(RLV_BHVR_SITTP)) )
+        {
+            if ( (isAgentAvatarValid()) && (gAgentAvatarp->isSitting()) && (gAgentAvatarp->getRoot() == pObjRoot) )
+                return ACCEPT_NO_LOCKED;    // ... or on a linkset the avie is sitting on under @unsit=n/@sittp=n
+        }
+    }
 // [/RLVa:KB]
 
-	if(attached && !unrestricted)
-	{
+    if(attached && !unrestricted)
+    {
         // Attachments are in world and in inventory simultaneously,
         // at the moment server doesn't support such a situation.
-		return ACCEPT_NO_LOCKED;
-	}
-	else if(modify && transfer && volume && !worn)
-	{
-		return ACCEPT_YES_MULTI;
-	}
-	else if(!modify)
-	{
-		return ACCEPT_NO_LOCKED;
-	}
-	return ACCEPT_NO;
+        return ACCEPT_NO_LOCKED;
+    }
+    else if(modify && transfer && volume && !worn)
+    {
+        return ACCEPT_YES_MULTI;
+    }
+    else if(!modify)
+    {
+        return ACCEPT_NO_LOCKED;
+    }
+    return ACCEPT_NO;
 }
 
 
 static void give_inventory_cb(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	// if Cancel pressed
-	if (option == 1)
-	{
-		return;
-	}
-
-	LLSD payload = notification["payload"];
-	const LLUUID& session_id = payload["session_id"];
-	const LLUUID& agent_id = payload["agent_id"];
-	LLViewerInventoryItem * inv_item =  gInventory.getItem(payload["item_id"]);
-	LLViewerInventoryCategory * inv_cat =  gInventory.getCategory(payload["item_id"]);
-	if (NULL == inv_item && NULL == inv_cat)
-	{
-		llassert( FALSE );
-		return;
-	}
-	bool successfully_shared;
-	if (inv_item)
-	{
-		successfully_shared = LLGiveInventory::doGiveInventoryItem(agent_id, inv_item, session_id);
-	}
-	else
-	{
-		successfully_shared = LLGiveInventory::doGiveInventoryCategory(agent_id, inv_cat, session_id);
-	}
-	if (successfully_shared)
-	{
-		if ("avatarpicker" == payload["d&d_dest"].asString())
-		{
-			LLFloaterReg::hideInstance("avatar_picker");
-		}
-		LLNotificationsUtil::add("ItemsShared");
-	}
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    // if Cancel pressed
+    if (option == 1)
+    {
+        return;
+    }
+
+    LLSD payload = notification["payload"];
+    const LLUUID& session_id = payload["session_id"];
+    const LLUUID& agent_id = payload["agent_id"];
+    LLViewerInventoryItem * inv_item =  gInventory.getItem(payload["item_id"]);
+    LLViewerInventoryCategory * inv_cat =  gInventory.getCategory(payload["item_id"]);
+    if (NULL == inv_item && NULL == inv_cat)
+    {
+        llassert( FALSE );
+        return;
+    }
+    bool successfully_shared;
+    if (inv_item)
+    {
+        successfully_shared = LLGiveInventory::doGiveInventoryItem(agent_id, inv_item, session_id);
+    }
+    else
+    {
+        successfully_shared = LLGiveInventory::doGiveInventoryCategory(agent_id, inv_cat, session_id);
+    }
+    if (successfully_shared)
+    {
+        if ("avatarpicker" == payload["d&d_dest"].asString())
+        {
+            LLFloaterReg::hideInstance("avatar_picker");
+        }
+        LLNotificationsUtil::add("ItemsShared");
+    }
 }
 
 static void show_object_sharing_confirmation(const std::string name,
-					   LLInventoryObject* inv_item,
-					   const LLSD& dest,
-					   const LLUUID& dest_agent,
-					   const LLUUID& session_id = LLUUID::null)
-{
-	if (!inv_item)
-	{
-		llassert(NULL != inv_item);
-		return;
-	}
-	LLSD substitutions;
-	substitutions["RESIDENTS"] = name;
-	substitutions["ITEMS"] = inv_item->getName();
-	LLSD payload;
-	payload["agent_id"] = dest_agent;
-	payload["item_id"] = inv_item->getUUID();
-	payload["session_id"] = session_id;
-	payload["d&d_dest"] = dest.asString();
-	LLNotificationsUtil::add("ShareItemsConfirmation", substitutions, payload, &give_inventory_cb);
+                       LLInventoryObject* inv_item,
+                       const LLSD& dest,
+                       const LLUUID& dest_agent,
+                       const LLUUID& session_id = LLUUID::null)
+{
+    if (!inv_item)
+    {
+        llassert(NULL != inv_item);
+        return;
+    }
+    LLSD substitutions;
+    substitutions["RESIDENTS"] = name;
+    substitutions["ITEMS"] = inv_item->getName();
+    LLSD payload;
+    payload["agent_id"] = dest_agent;
+    payload["item_id"] = inv_item->getUUID();
+    payload["session_id"] = session_id;
+    payload["d&d_dest"] = dest.asString();
+    LLNotificationsUtil::add("ShareItemsConfirmation", substitutions, payload, &give_inventory_cb);
 }
 
 static void get_name_cb(const LLUUID& id,
-						const LLAvatarName& av_name,
-						LLInventoryObject* inv_obj,
-						const LLSD& dest,
-						const LLUUID& dest_agent)
+                        const LLAvatarName& av_name,
+                        LLInventoryObject* inv_obj,
+                        const LLSD& dest,
+                        const LLUUID& dest_agent)
 {
-	show_object_sharing_confirmation(av_name.getUserName(),
-								     inv_obj,
-								     dest,
-						  		     id,
-								     LLUUID::null);
+    show_object_sharing_confirmation(av_name.getUserName(),
+                                     inv_obj,
+                                     dest,
+                                     id,
+                                     LLUUID::null);
 }
 
 // function used as drag-and-drop handler for simple agent give inventory requests
 //static
 bool LLToolDragAndDrop::handleGiveDragAndDrop(LLUUID dest_agent, LLUUID session_id, BOOL drop,
-											  EDragAndDropType cargo_type,
-											  void* cargo_data,
-											  EAcceptance* accept,
-											  const LLSD& dest)
+                                              EDragAndDropType cargo_type,
+                                              void* cargo_data,
+                                              EAcceptance* accept,
+                                              const LLSD& dest)
 {
 // [RLVa:KB] - @share
-	if ( (RlvActions::isRlvEnabled()) && (!RlvActions::canGiveInventory(dest_agent)) )
-	{
-		*accept = ACCEPT_NO_LOCKED;
-		return true;
-	}
+    if ( (RlvActions::isRlvEnabled()) && (!RlvActions::canGiveInventory(dest_agent)) )
+    {
+        *accept = ACCEPT_NO_LOCKED;
+        return true;
+    }
 // [/RLVa:KB]
 
-	// check the type
-	switch(cargo_type)
-	{
-	case DAD_TEXTURE:
-	case DAD_SOUND:
-	case DAD_LANDMARK:
-	case DAD_SCRIPT:
-	case DAD_OBJECT:
-	case DAD_NOTECARD:
-	case DAD_CLOTHING:
-	case DAD_BODYPART:
-	case DAD_ANIMATION:
-	case DAD_GESTURE:
-	case DAD_CALLINGCARD:
-	case DAD_MESH:
-	case DAD_CATEGORY:
+    // check the type
+    switch(cargo_type)
+    {
+    case DAD_TEXTURE:
+    case DAD_SOUND:
+    case DAD_LANDMARK:
+    case DAD_SCRIPT:
+    case DAD_OBJECT:
+    case DAD_NOTECARD:
+    case DAD_CLOTHING:
+    case DAD_BODYPART:
+    case DAD_ANIMATION:
+    case DAD_GESTURE:
+    case DAD_CALLINGCARD:
+    case DAD_MESH:
+    case DAD_CATEGORY:
     case DAD_SETTINGS:
     case DAD_MATERIAL:
-	{
-		LLInventoryObject* inv_obj = (LLInventoryObject*)cargo_data;
-		if(gInventory.getCategory(inv_obj->getUUID()) || (gInventory.getItem(inv_obj->getUUID())
-			&& LLGiveInventory::isInventoryGiveAcceptable(dynamic_cast<LLInventoryItem*>(inv_obj))))
-		{
-			// *TODO: get multiple object transfers working
-			*accept = ACCEPT_YES_COPY_SINGLE;
-			if(drop)
-			{
-				LLIMModel::LLIMSession * session = LLIMModel::instance().findIMSession(session_id);
-
-				// If no IM session found get the destination agent's name by id.
-				if (NULL == session)
-				{
-					LLAvatarName av_name;
-
-					// If destination agent's name is found in cash proceed to showing the confirmation dialog.
-					// Otherwise set up a callback to show the dialog when the name arrives.
-					if (LLAvatarNameCache::get(dest_agent, &av_name))
-					{
-						show_object_sharing_confirmation(av_name.getUserName(), inv_obj, dest, dest_agent, LLUUID::null);
-					}
-					else
-					{
-						LLAvatarNameCache::get(dest_agent, boost::bind(&get_name_cb, _1, _2, inv_obj, dest, dest_agent));
-					}
-
-					return true;
-				}
-				std::string dest_name = session->mName;
-				LLAvatarName av_name;
-				if(LLAvatarNameCache::get(dest_agent, &av_name))
-				{
-					dest_name = av_name.getCompleteName();
-				}
-				// If an IM session with destination agent is found item offer will be logged in this session.
-				show_object_sharing_confirmation(dest_name, inv_obj, dest, dest_agent, session_id);
-			}
-		}
-		else
-		{
-			// It's not in the user's inventory (it's probably
-			// in an object's contents), so disallow dragging
-			// it here.  You can't give something you don't
-			// yet have.
-			*accept = ACCEPT_NO;
-		}
-		break;
-	}
-	default:
-		*accept = ACCEPT_NO;
-		break;
-	}
-
-	return TRUE;
+    {
+        LLInventoryObject* inv_obj = (LLInventoryObject*)cargo_data;
+        if(gInventory.getCategory(inv_obj->getUUID()) || (gInventory.getItem(inv_obj->getUUID())
+            && LLGiveInventory::isInventoryGiveAcceptable(dynamic_cast<LLInventoryItem*>(inv_obj))))
+        {
+            // *TODO: get multiple object transfers working
+            *accept = ACCEPT_YES_COPY_SINGLE;
+            if(drop)
+            {
+                LLIMModel::LLIMSession * session = LLIMModel::instance().findIMSession(session_id);
+
+                // If no IM session found get the destination agent's name by id.
+                if (NULL == session)
+                {
+                    LLAvatarName av_name;
+
+                    // If destination agent's name is found in cash proceed to showing the confirmation dialog.
+                    // Otherwise set up a callback to show the dialog when the name arrives.
+                    if (LLAvatarNameCache::get(dest_agent, &av_name))
+                    {
+                        show_object_sharing_confirmation(av_name.getUserName(), inv_obj, dest, dest_agent, LLUUID::null);
+                    }
+                    else
+                    {
+                        LLAvatarNameCache::get(dest_agent, boost::bind(&get_name_cb, _1, _2, inv_obj, dest, dest_agent));
+                    }
+
+                    return true;
+                }
+                std::string dest_name = session->mName;
+                LLAvatarName av_name;
+                if(LLAvatarNameCache::get(dest_agent, &av_name))
+                {
+                    dest_name = av_name.getCompleteName();
+                }
+                // If an IM session with destination agent is found item offer will be logged in this session.
+                show_object_sharing_confirmation(dest_name, inv_obj, dest, dest_agent, session_id);
+            }
+        }
+        else
+        {
+            // It's not in the user's inventory (it's probably
+            // in an object's contents), so disallow dragging
+            // it here.  You can't give something you don't
+            // yet have.
+            *accept = ACCEPT_NO;
+        }
+        break;
+    }
+    default:
+        *accept = ACCEPT_NO;
+        break;
+    }
+
+    return TRUE;
 }
 
 
@@ -2133,313 +2133,313 @@ bool LLToolDragAndDrop::handleGiveDragAndDrop(LLUUID dest_agent, LLUUID session_
 ///
 
 EAcceptance LLToolDragAndDrop::dad3dNULL(
-	LLViewerObject*, S32, MASK, BOOL)
+    LLViewerObject*, S32, MASK, BOOL)
 {
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dNULL()" << LL_ENDL;
-	return ACCEPT_NO;
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dNULL()" << LL_ENDL;
+    return ACCEPT_NO;
 }
 
 EAcceptance LLToolDragAndDrop::dad3dRezAttachmentFromInv(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezAttachmentFromInv()" << LL_ENDL;
-	// must be in the user's inventory
-	if(mSource != SOURCE_AGENT && mSource != SOURCE_LIBRARY)
-	{
-		return ACCEPT_NO;
-	}
-
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-
-	// must not be in the trash
-	const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-	if( gInventory.isObjectDescendentOf( item->getUUID(), trash_id ) )
-	{
-		return ACCEPT_NO;
-	}
-
-	// must not be already wearing it
-	LLVOAvatarSelf* avatar = gAgentAvatarp;
-	if( !avatar || avatar->isWearingAttachment(item->getUUID()) )
-	{
-		return ACCEPT_NO;
-	}
-
-	const LLUUID &outbox_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OUTBOX);
-	if(outbox_id.notNull() && gInventory.isObjectDescendentOf(item->getUUID(), outbox_id))
-	{
-		// Legacy
-		return ACCEPT_NO;
-	}
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezAttachmentFromInv()" << LL_ENDL;
+    // must be in the user's inventory
+    if(mSource != SOURCE_AGENT && mSource != SOURCE_LIBRARY)
+    {
+        return ACCEPT_NO;
+    }
+
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+
+    // must not be in the trash
+    const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+    if( gInventory.isObjectDescendentOf( item->getUUID(), trash_id ) )
+    {
+        return ACCEPT_NO;
+    }
+
+    // must not be already wearing it
+    LLVOAvatarSelf* avatar = gAgentAvatarp;
+    if( !avatar || avatar->isWearingAttachment(item->getUUID()) )
+    {
+        return ACCEPT_NO;
+    }
+
+    const LLUUID &outbox_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OUTBOX);
+    if(outbox_id.notNull() && gInventory.isObjectDescendentOf(item->getUUID(), outbox_id))
+    {
+        // Legacy
+        return ACCEPT_NO;
+    }
 
 // [RLVa:KB] - Checked: 2013-02-13 (RLVa-1.4.8)
-	bool fReplace = !(mask & MASK_CONTROL);
-	if ( (rlv_handler_t::isEnabled()) && (!rlvPredCanWearItem(item, (fReplace) ? RLV_WEAR_REPLACE : RLV_WEAR_ADD)) )
-	{
-		return ACCEPT_NO_LOCKED;
-	}
+    bool fReplace = !(mask & MASK_CONTROL);
+    if ( (rlv_handler_t::isEnabled()) && (!rlvPredCanWearItem(item, (fReplace) ? RLV_WEAR_REPLACE : RLV_WEAR_ADD)) )
+    {
+        return ACCEPT_NO_LOCKED;
+    }
 // [/RLVa:KB]
 
-	if( drop )
-	{
-		if(mSource == SOURCE_LIBRARY)
-		{
-//			LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(rez_attachment_cb, _1, (LLViewerJointAttachment*)0));
+    if( drop )
+    {
+        if(mSource == SOURCE_LIBRARY)
+        {
+//          LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(rez_attachment_cb, _1, (LLViewerJointAttachment*)0));
 // [SL:KB] - Patch: Appearance-DnDWear | Checked: 2010-09-28 (Catznip-2.2)
-			// Make this behave consistent with dad3dWearItem
-			LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(rez_attachment_cb, _1, (LLViewerJointAttachment*)0, fReplace));
+            // Make this behave consistent with dad3dWearItem
+            LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(boost::bind(rez_attachment_cb, _1, (LLViewerJointAttachment*)0, fReplace));
 // [/SL:KB]
-			copy_inventory_item(
-				gAgent.getID(),
-				item->getPermissions().getOwner(),
-				item->getUUID(),
-				LLUUID::null,
-				std::string(),
-				cb);
-		}
-		else
-		{
+            copy_inventory_item(
+                gAgent.getID(),
+                item->getPermissions().getOwner(),
+                item->getUUID(),
+                LLUUID::null,
+                std::string(),
+                cb);
+        }
+        else
+        {
 // [SL:KB] - Patch: Appearance-DnDWear | Checked: 2010-09-28 (Catznip-2.2)
-			// Make this behave consistent with dad3dWearItem
-			rez_attachment(item, 0, !(mask & MASK_CONTROL));
+            // Make this behave consistent with dad3dWearItem
+            rez_attachment(item, 0, !(mask & MASK_CONTROL));
 // [/SL:KB]
-//			rez_attachment(item, 0);
-		}
-	}
-	return ACCEPT_YES_SINGLE;
+//          rez_attachment(item, 0);
+        }
+    }
+    return ACCEPT_YES_SINGLE;
 }
 
 
 EAcceptance LLToolDragAndDrop::dad3dRezObjectOnLand(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
 {
 // [RLVa:KB] - Checked: 2010-03-23 (RLVa-1.2.0e) | Modified: RLVa-1.1.0l
-	// RELEASE-RLVa: [SL-2.2.0] Make sure the code below is the only code path to LLToolDragAndDrop::dad3dRezFromObjectOnLand()
-	if ( (rlv_handler_t::isEnabled()) && ((gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) || (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT))) )
-	{
-		return ACCEPT_NO_LOCKED;
-	}
+    // RELEASE-RLVa: [SL-2.2.0] Make sure the code below is the only code path to LLToolDragAndDrop::dad3dRezFromObjectOnLand()
+    if ( (rlv_handler_t::isEnabled()) && ((gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) || (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT))) )
+    {
+        return ACCEPT_NO_LOCKED;
+    }
 // [/RLVa:KB]
 
-	if (mSource == SOURCE_WORLD)
-	{
-		return dad3dRezFromObjectOnLand(obj, face, mask, drop);
-	}
-
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezObjectOnLand()" << LL_ENDL;
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-
-	LLVOAvatarSelf* my_avatar = gAgentAvatarp;
-	if( !my_avatar || my_avatar->isWearingAttachment( item->getUUID() ) )
-	{
-		return ACCEPT_NO;
-	}
-
-	EAcceptance accept;
-	BOOL remove_inventory;
-
-	// Get initial settings based on shift key
-	if (mask & MASK_SHIFT)
-	{
-		// For now, always make copy
-		//accept = ACCEPT_YES_SINGLE;
-		//remove_inventory = TRUE;
-		accept = ACCEPT_YES_COPY_SINGLE;
-		remove_inventory = FALSE;
-	}
-	else
-	{
-		accept = ACCEPT_YES_COPY_SINGLE;
-		remove_inventory = FALSE;
-	}
-
-	// check if the item can be copied. If not, send that to the sim
-	// which will remove the inventory item.
-	if(!item->getPermissions().allowCopyBy(gAgent.getID()))
-	{
-		accept = ACCEPT_YES_SINGLE;
-		remove_inventory = TRUE;
-	}
-
-	// Check if it's in the trash.
-	const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-	if(gInventory.isObjectDescendentOf(item->getUUID(), trash_id))
-	{
-		accept = ACCEPT_YES_SINGLE;
-	}
-
-	if(drop)
-	{
-		dropObject(obj, TRUE, FALSE, remove_inventory);
-	}
-
-	return accept;
+    if (mSource == SOURCE_WORLD)
+    {
+        return dad3dRezFromObjectOnLand(obj, face, mask, drop);
+    }
+
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezObjectOnLand()" << LL_ENDL;
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+
+    LLVOAvatarSelf* my_avatar = gAgentAvatarp;
+    if( !my_avatar || my_avatar->isWearingAttachment( item->getUUID() ) )
+    {
+        return ACCEPT_NO;
+    }
+
+    EAcceptance accept;
+    BOOL remove_inventory;
+
+    // Get initial settings based on shift key
+    if (mask & MASK_SHIFT)
+    {
+        // For now, always make copy
+        //accept = ACCEPT_YES_SINGLE;
+        //remove_inventory = TRUE;
+        accept = ACCEPT_YES_COPY_SINGLE;
+        remove_inventory = FALSE;
+    }
+    else
+    {
+        accept = ACCEPT_YES_COPY_SINGLE;
+        remove_inventory = FALSE;
+    }
+
+    // check if the item can be copied. If not, send that to the sim
+    // which will remove the inventory item.
+    if(!item->getPermissions().allowCopyBy(gAgent.getID()))
+    {
+        accept = ACCEPT_YES_SINGLE;
+        remove_inventory = TRUE;
+    }
+
+    // Check if it's in the trash.
+    const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+    if(gInventory.isObjectDescendentOf(item->getUUID(), trash_id))
+    {
+        accept = ACCEPT_YES_SINGLE;
+    }
+
+    if(drop)
+    {
+        dropObject(obj, TRUE, FALSE, remove_inventory);
+    }
+
+    return accept;
 }
 
 EAcceptance LLToolDragAndDrop::dad3dRezObjectOnObject(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
 {
 // [RLVa:KB] - Checked: 2010-03-23 (RLVa-1.2.0e) | Modified: RLVa-1.1.0l
-	// NOTE: if (mask & MASK_CONTROL) then it's a drop rather than a rez, so we let that pass through when @rez=n restricted
-	// (but not when @interact=n restricted unless the drop target is a HUD attachment)
-	// RELEASE-RLVa: [SL-2.2.0] Make sure the code below is the only code path to LLToolDragAndDrop::dad3dRezFromObjectOnObject()
-	if ( (rlv_handler_t::isEnabled()) &&
-		 ( ( (gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) && ((mask & MASK_CONTROL) == 0) ) ||
-		   ( (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT)) && (((mask & MASK_CONTROL) == 0) || (!obj->isHUDAttachment())) ) ) )
-	{
-		return ACCEPT_NO_LOCKED;
-	}
+    // NOTE: if (mask & MASK_CONTROL) then it's a drop rather than a rez, so we let that pass through when @rez=n restricted
+    // (but not when @interact=n restricted unless the drop target is a HUD attachment)
+    // RELEASE-RLVa: [SL-2.2.0] Make sure the code below is the only code path to LLToolDragAndDrop::dad3dRezFromObjectOnObject()
+    if ( (rlv_handler_t::isEnabled()) &&
+         ( ( (gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) && ((mask & MASK_CONTROL) == 0) ) ||
+           ( (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT)) && (((mask & MASK_CONTROL) == 0) || (!obj->isHUDAttachment())) ) ) )
+    {
+        return ACCEPT_NO_LOCKED;
+    }
 // [/RLVa:KB]
 
-	// handle objects coming from object inventory
-	if (mSource == SOURCE_WORLD)
-	{
-		return dad3dRezFromObjectOnObject(obj, face, mask, drop);
-	}
-
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezObjectOnObject()" << LL_ENDL;
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-	LLVOAvatarSelf* my_avatar = gAgentAvatarp;
-	if( !my_avatar || my_avatar->isWearingAttachment( item->getUUID() ) )
-	{
-		return ACCEPT_NO;
-	}
-
-	if((mask & MASK_CONTROL))
-	{
-		// *HACK: In order to resolve SL-22177, we need to block drags
-		// from notecards and objects onto other objects.
-		if(mSource == SOURCE_NOTECARD)
-		{
-			return ACCEPT_NO;
-		}
-
-		EAcceptance rv = willObjectAcceptInventory(obj, item);
-		if(drop && (ACCEPT_YES_SINGLE <= rv))
-		{
-			dropInventory(obj, item, mSource, mSourceID);
-		}
-		return rv;
-	}
-	
-	EAcceptance accept;
-	BOOL remove_inventory;
-
-	if (mask & MASK_SHIFT)
-	{
-		// For now, always make copy
-		//accept = ACCEPT_YES_SINGLE;
-		//remove_inventory = TRUE;
-		accept = ACCEPT_YES_COPY_SINGLE;
-		remove_inventory = FALSE;
-	}
-	else
-	{
-		accept = ACCEPT_YES_COPY_SINGLE;
-		remove_inventory = FALSE;
-	}
-	
-	// check if the item can be copied. If not, send that to the sim
-	// which will remove the inventory item.
-	if(!item->getPermissions().allowCopyBy(gAgent.getID()))
-	{
-		accept = ACCEPT_YES_SINGLE;
-		remove_inventory = TRUE;
-	}
-
-	// Check if it's in the trash.
-	const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-	if(gInventory.isObjectDescendentOf(item->getUUID(), trash_id))
-	{
-		accept = ACCEPT_YES_SINGLE;
-		remove_inventory = TRUE;
-	}
-
-	if(drop)
-	{
-		dropObject(obj, FALSE, FALSE, remove_inventory);
-	}
-
-	return accept;
+    // handle objects coming from object inventory
+    if (mSource == SOURCE_WORLD)
+    {
+        return dad3dRezFromObjectOnObject(obj, face, mask, drop);
+    }
+
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezObjectOnObject()" << LL_ENDL;
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+    LLVOAvatarSelf* my_avatar = gAgentAvatarp;
+    if( !my_avatar || my_avatar->isWearingAttachment( item->getUUID() ) )
+    {
+        return ACCEPT_NO;
+    }
+
+    if((mask & MASK_CONTROL))
+    {
+        // *HACK: In order to resolve SL-22177, we need to block drags
+        // from notecards and objects onto other objects.
+        if(mSource == SOURCE_NOTECARD)
+        {
+            return ACCEPT_NO;
+        }
+
+        EAcceptance rv = willObjectAcceptInventory(obj, item);
+        if(drop && (ACCEPT_YES_SINGLE <= rv))
+        {
+            dropInventory(obj, item, mSource, mSourceID);
+        }
+        return rv;
+    }
+
+    EAcceptance accept;
+    BOOL remove_inventory;
+
+    if (mask & MASK_SHIFT)
+    {
+        // For now, always make copy
+        //accept = ACCEPT_YES_SINGLE;
+        //remove_inventory = TRUE;
+        accept = ACCEPT_YES_COPY_SINGLE;
+        remove_inventory = FALSE;
+    }
+    else
+    {
+        accept = ACCEPT_YES_COPY_SINGLE;
+        remove_inventory = FALSE;
+    }
+
+    // check if the item can be copied. If not, send that to the sim
+    // which will remove the inventory item.
+    if(!item->getPermissions().allowCopyBy(gAgent.getID()))
+    {
+        accept = ACCEPT_YES_SINGLE;
+        remove_inventory = TRUE;
+    }
+
+    // Check if it's in the trash.
+    const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+    if(gInventory.isObjectDescendentOf(item->getUUID(), trash_id))
+    {
+        accept = ACCEPT_YES_SINGLE;
+        remove_inventory = TRUE;
+    }
+
+    if(drop)
+    {
+        dropObject(obj, FALSE, FALSE, remove_inventory);
+    }
+
+    return accept;
 }
 
-EAcceptance LLToolDragAndDrop::dad3dRezScript(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezScript()" << LL_ENDL;
-
-	// *HACK: In order to resolve SL-22177, we need to block drags
-	// from notecards and objects onto other objects.
-	if((SOURCE_WORLD == mSource) || (SOURCE_NOTECARD == mSource))
-	{
-		return ACCEPT_NO;
-	}
-
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || (!item->isFinished() && !(gInventory.isObjectDescendentOf(item->getUUID(), gLocalInventory)))) return ACCEPT_NO;
-	EAcceptance rv = willObjectAcceptInventory(obj, item);
-	if(drop && (ACCEPT_YES_SINGLE <= rv))
-	{
-		// rez in the script active by default, rez in inactive if the
-		// control key is being held down.
-		BOOL active = ((mask & MASK_CONTROL) == 0);
-	
-		LLViewerObject* root_object = obj;
-		if (obj && obj->getParent())
-		{
-			LLViewerObject* parent_obj = (LLViewerObject*)obj->getParent();
-			if (!parent_obj->isAvatar())
-			{
-				root_object = parent_obj;
-			}
-		}
-
-		dropScript(root_object, item, active, mSource, mSourceID);
-	}	
-	return rv;
+EAcceptance LLToolDragAndDrop::dad3dRezScript(
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezScript()" << LL_ENDL;
+
+    // *HACK: In order to resolve SL-22177, we need to block drags
+    // from notecards and objects onto other objects.
+    if((SOURCE_WORLD == mSource) || (SOURCE_NOTECARD == mSource))
+    {
+        return ACCEPT_NO;
+    }
+
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || (!item->isFinished() && !(gInventory.isObjectDescendentOf(item->getUUID(), gLocalInventory)))) return ACCEPT_NO;
+    EAcceptance rv = willObjectAcceptInventory(obj, item);
+    if(drop && (ACCEPT_YES_SINGLE <= rv))
+    {
+        // rez in the script active by default, rez in inactive if the
+        // control key is being held down.
+        BOOL active = ((mask & MASK_CONTROL) == 0);
+
+        LLViewerObject* root_object = obj;
+        if (obj && obj->getParent())
+        {
+            LLViewerObject* parent_obj = (LLViewerObject*)obj->getParent();
+            if (!parent_obj->isAvatar())
+            {
+                root_object = parent_obj;
+            }
+        }
+
+        dropScript(root_object, item, active, mSource, mSourceID);
+    }
+    return rv;
 }
 
 EAcceptance LLToolDragAndDrop::dad3dApplyToObject(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop, EDragAndDropType cargo_type)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dApplyToObject()" << LL_ENDL;
-
-	// *HACK: In order to resolve SL-22177, we need to block drags
-	// from notecards and objects onto other objects.
-	if((SOURCE_WORLD == mSource) || (SOURCE_NOTECARD == mSource))
-	{
-		return ACCEPT_NO;
-	}
-	
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if( !item || (!item->isFinished() && !(gInventory.isObjectDescendentOf(item->getUUID(), gLocalInventory))) ) return ACCEPT_NO;
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop, EDragAndDropType cargo_type)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dApplyToObject()" << LL_ENDL;
+
+    // *HACK: In order to resolve SL-22177, we need to block drags
+    // from notecards and objects onto other objects.
+    if((SOURCE_WORLD == mSource) || (SOURCE_NOTECARD == mSource))
+    {
+        return ACCEPT_NO;
+    }
+
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if( !item || (!item->isFinished() && !(gInventory.isObjectDescendentOf(item->getUUID(), gLocalInventory))) ) return ACCEPT_NO;
     LLPermissions item_permissions = item->getPermissions();
-	EAcceptance rv = willObjectAcceptInventory(obj, item);
-	if((mask & MASK_CONTROL))
-	{
-		if((ACCEPT_YES_SINGLE <= rv) && drop)
-		{
-			dropInventory(obj, item, mSource, mSourceID);
-		}
-		return rv;
-	}
-	if(!obj->permModify())
-	{
-		return ACCEPT_NO_LOCKED;
-	}
+    EAcceptance rv = willObjectAcceptInventory(obj, item);
+    if((mask & MASK_CONTROL))
+    {
+        if((ACCEPT_YES_SINGLE <= rv) && drop)
+        {
+            dropInventory(obj, item, mSource, mSourceID);
+        }
+        return rv;
+    }
+    if(!obj->permModify())
+    {
+        return ACCEPT_NO_LOCKED;
+    }
 
     if (cargo_type == DAD_TEXTURE && (mask & MASK_ALT) == 0)
     {
@@ -2471,10 +2471,10 @@ EAcceptance LLToolDragAndDrop::dad3dApplyToObject(
         }
     }
 
-	if(drop && (ACCEPT_YES_SINGLE <= rv))
-	{
-		if (cargo_type == DAD_TEXTURE)
-		{
+    if(drop && (ACCEPT_YES_SINGLE <= rv))
+    {
+        if (cargo_type == DAD_TEXTURE)
+        {
             bool all_faces = mask & MASK_SHIFT;
             bool remove_pbr = mask & MASK_ALT;
             if (item_permissions.allowOperationBy(PERM_COPY, gAgent.getID()))
@@ -2496,7 +2496,7 @@ EAcceptance LLToolDragAndDrop::dad3dApplyToObject(
                                              dropTexture(obj, face, item, source, source_id, all_faces, remove_pbr);
                                          });
             }
-		}
+        }
         else if (cargo_type == DAD_MATERIAL)
         {
             bool all_faces = mask & MASK_SHIFT;
@@ -2520,35 +2520,35 @@ EAcceptance LLToolDragAndDrop::dad3dApplyToObject(
                                          });
             }
         }
-		else if (cargo_type == DAD_MESH)
-		{
-			dropMesh(obj, item, mSource, mSourceID);
-		}
-		else
-		{
-			LL_WARNS() << "unsupported asset type" << LL_ENDL;
-		}
-		
-		// VEFFECT: SetTexture
-		if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
-		{
-			LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
-			effectp->setSourceObject(gAgentAvatarp);
-			effectp->setTargetObject(obj);
-			effectp->setDuration(LL_HUD_DUR_SHORT);
-			effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-		}
-	}
-
-	// enable multi-drop, although last texture will win
-	return ACCEPT_YES_MULTI;
+        else if (cargo_type == DAD_MESH)
+        {
+            dropMesh(obj, item, mSource, mSourceID);
+        }
+        else
+        {
+            LL_WARNS() << "unsupported asset type" << LL_ENDL;
+        }
+
+        // VEFFECT: SetTexture
+        if (!gSavedSettings.getBOOL("AlchemyPointAtPrivate"))
+        {
+            LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM, TRUE);
+            effectp->setSourceObject(gAgentAvatarp);
+            effectp->setTargetObject(obj);
+            effectp->setDuration(LL_HUD_DUR_SHORT);
+            effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+        }
+    }
+
+    // enable multi-drop, although last texture will win
+    return ACCEPT_YES_MULTI;
 }
 
 
 EAcceptance LLToolDragAndDrop::dad3dTextureObject(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
 {
-	return dad3dApplyToObject(obj, face, mask, drop, DAD_TEXTURE);
+    return dad3dApplyToObject(obj, face, mask, drop, DAD_TEXTURE);
 }
 
 EAcceptance LLToolDragAndDrop::dad3dMaterialObject(
@@ -2558,534 +2558,534 @@ EAcceptance LLToolDragAndDrop::dad3dMaterialObject(
 }
 
 EAcceptance LLToolDragAndDrop::dad3dMeshObject(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
 {
-	return dad3dApplyToObject(obj, face, mask, drop, DAD_MESH);
+    return dad3dApplyToObject(obj, face, mask, drop, DAD_MESH);
 }
 
 EAcceptance LLToolDragAndDrop::dad3dWearItem(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dWearItem()" << LL_ENDL;
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-
-	if(mSource == SOURCE_AGENT || mSource == SOURCE_LIBRARY)
-	{
-		// it's in the agent inventory
-		const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-		if( gInventory.isObjectDescendentOf( item->getUUID(), trash_id ) )
-		{
-			return ACCEPT_NO;
-		}
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dWearItem()" << LL_ENDL;
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+
+    if(mSource == SOURCE_AGENT || mSource == SOURCE_LIBRARY)
+    {
+        // it's in the agent inventory
+        const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+        if( gInventory.isObjectDescendentOf( item->getUUID(), trash_id ) )
+        {
+            return ACCEPT_NO;
+        }
 
 // [RLVa:KB] - Checked: 2013-02-13 (RLVa-1.4.8)
-		bool fReplace = (!(mask & MASK_CONTROL)) || (LLAssetType::AT_BODYPART == item->getType());	// Body parts should always replace
-		if ( (rlv_handler_t::isEnabled()) && (!rlvPredCanWearItem(item, (fReplace) ? RLV_WEAR_REPLACE : RLV_WEAR_ADD)) )
-		{
-			return ACCEPT_NO_LOCKED;
-		}
+        bool fReplace = (!(mask & MASK_CONTROL)) || (LLAssetType::AT_BODYPART == item->getType());  // Body parts should always replace
+        if ( (rlv_handler_t::isEnabled()) && (!rlvPredCanWearItem(item, (fReplace) ? RLV_WEAR_REPLACE : RLV_WEAR_ADD)) )
+        {
+            return ACCEPT_NO_LOCKED;
+        }
 // [/RLVa:KB]
 
-		if( drop )
-		{
-			// TODO: investigate wearables may not be loaded at this point EXT-8231
+        if( drop )
+        {
+            // TODO: investigate wearables may not be loaded at this point EXT-8231
 
 // [RLVa:KB] - Checked: 2013-02-13 (RLVa-1.4.8)
-			LLAppearanceMgr::instance().wearItemOnAvatar(item->getUUID(), true, fReplace);
+            LLAppearanceMgr::instance().wearItemOnAvatar(item->getUUID(), true, fReplace);
 // [/RLVa:KB]
-//			LLAppearanceMgr::instance().wearItemOnAvatar(item->getUUID(),true, !(mask & MASK_CONTROL));
-		}
-		return ACCEPT_YES_MULTI;
-	}
-	else
-	{
-		// TODO: copy/move item to avatar's inventory and then wear it.
-		return ACCEPT_NO;
-	}
+//          LLAppearanceMgr::instance().wearItemOnAvatar(item->getUUID(),true, !(mask & MASK_CONTROL));
+        }
+        return ACCEPT_YES_MULTI;
+    }
+    else
+    {
+        // TODO: copy/move item to avatar's inventory and then wear it.
+        return ACCEPT_NO;
+    }
 }
 
 EAcceptance LLToolDragAndDrop::dad3dActivateGesture(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dActivateGesture()" << LL_ENDL;
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-
-	if(mSource == SOURCE_AGENT || mSource == SOURCE_LIBRARY)
-	{
-		// it's in the agent inventory
-		const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-		if( gInventory.isObjectDescendentOf( item->getUUID(), trash_id ) )
-		{
-			return ACCEPT_NO;
-		}
-
-		if( drop )
-		{
-			if(mSource == SOURCE_LIBRARY)
-			{
-				// create item based on that one, and put it on if that
-				// was a success.
-				LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(activate_gesture_cb);
-				copy_inventory_item(
-					gAgent.getID(),
-					item->getPermissions().getOwner(),
-					item->getUUID(),
-					LLUUID::null,
-					std::string(),
-					cb);
-			}
-			else
-			{
-				LLGestureMgr::instance().activateGesture(item->getUUID());
-				gInventory.updateItem(item);
-				gInventory.notifyObservers();
-			}
-		}
-		return ACCEPT_YES_MULTI;
-	}
-	else
-	{
-		return ACCEPT_NO;
-	}
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dActivateGesture()" << LL_ENDL;
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+
+    if(mSource == SOURCE_AGENT || mSource == SOURCE_LIBRARY)
+    {
+        // it's in the agent inventory
+        const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+        if( gInventory.isObjectDescendentOf( item->getUUID(), trash_id ) )
+        {
+            return ACCEPT_NO;
+        }
+
+        if( drop )
+        {
+            if(mSource == SOURCE_LIBRARY)
+            {
+                // create item based on that one, and put it on if that
+                // was a success.
+                LLPointer<LLInventoryCallback> cb = new LLBoostFuncInventoryCallback(activate_gesture_cb);
+                copy_inventory_item(
+                    gAgent.getID(),
+                    item->getPermissions().getOwner(),
+                    item->getUUID(),
+                    LLUUID::null,
+                    std::string(),
+                    cb);
+            }
+            else
+            {
+                LLGestureMgr::instance().activateGesture(item->getUUID());
+                gInventory.updateItem(item);
+                gInventory.notifyObservers();
+            }
+        }
+        return ACCEPT_YES_MULTI;
+    }
+    else
+    {
+        return ACCEPT_NO;
+    }
 }
 
 EAcceptance LLToolDragAndDrop::dad3dWearCategory(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dWearCategory()" << LL_ENDL;
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* category;
-	locateInventory(item, category);
-	if(!category) return ACCEPT_NO;
-
-	if (drop)
-	{
-		// TODO: investigate wearables may not be loaded at this point EXT-8231
-	}
-
-	U32 max_items = gSavedSettings.getU32("WearFolderLimit");
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	LLFindWearablesEx not_worn(/*is_worn=*/ false, /*include_body_parts=*/ false);
-	gInventory.collectDescendentsIf(category->getUUID(),
-		cats,
-		items,
-		LLInventoryModel::EXCLUDE_TRASH,
-		not_worn);
-	if (items.size() > max_items)
-	{
-		LLStringUtil::format_map_t args;
-		args["AMOUNT"] = llformat("%d", max_items);
-		mCustomMsg = LLTrans::getString("TooltipTooManyWearables",args);
-		return ACCEPT_NO_CUSTOM;
-	}
-
-	if(mSource == SOURCE_AGENT)
-	{
-		const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-		if( gInventory.isObjectDescendentOf( category->getUUID(), trash_id ) )
-		{
-			return ACCEPT_NO;
-		}
-
-		const LLUUID &outbox_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OUTBOX);
-		if(outbox_id.notNull() && gInventory.isObjectDescendentOf(category->getUUID(), outbox_id))
-		{
-			// Legacy
-			return ACCEPT_NO;
-		}
-
-		if(drop)
-		{
-			BOOL append = ( (mask & MASK_SHIFT) ? TRUE : FALSE );
-			LLAppearanceMgr::instance().wearInventoryCategory(category, false, append);
-		}
-		return ACCEPT_YES_MULTI;
-	}
-	else if(mSource == SOURCE_LIBRARY)
-	{
-		if(drop)
-		{
-			LLAppearanceMgr::instance().wearInventoryCategory(category, true, false);
-		}
-		return ACCEPT_YES_MULTI;
-	}
-	else
-	{
-		// TODO: copy/move category to avatar's inventory and then wear it.
-		return ACCEPT_NO;
-	}
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dWearCategory()" << LL_ENDL;
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* category;
+    locateInventory(item, category);
+    if(!category) return ACCEPT_NO;
+
+    if (drop)
+    {
+        // TODO: investigate wearables may not be loaded at this point EXT-8231
+    }
+
+    U32 max_items = gSavedSettings.getU32("WearFolderLimit");
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    LLFindWearablesEx not_worn(/*is_worn=*/ false, /*include_body_parts=*/ false);
+    gInventory.collectDescendentsIf(category->getUUID(),
+        cats,
+        items,
+        LLInventoryModel::EXCLUDE_TRASH,
+        not_worn);
+    if (items.size() > max_items)
+    {
+        LLStringUtil::format_map_t args;
+        args["AMOUNT"] = llformat("%d", max_items);
+        mCustomMsg = LLTrans::getString("TooltipTooManyWearables",args);
+        return ACCEPT_NO_CUSTOM;
+    }
+
+    if(mSource == SOURCE_AGENT)
+    {
+        const LLUUID trash_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+        if( gInventory.isObjectDescendentOf( category->getUUID(), trash_id ) )
+        {
+            return ACCEPT_NO;
+        }
+
+        const LLUUID &outbox_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OUTBOX);
+        if(outbox_id.notNull() && gInventory.isObjectDescendentOf(category->getUUID(), outbox_id))
+        {
+            // Legacy
+            return ACCEPT_NO;
+        }
+
+        if(drop)
+        {
+            BOOL append = ( (mask & MASK_SHIFT) ? TRUE : FALSE );
+            LLAppearanceMgr::instance().wearInventoryCategory(category, false, append);
+        }
+        return ACCEPT_YES_MULTI;
+    }
+    else if(mSource == SOURCE_LIBRARY)
+    {
+        if(drop)
+        {
+            LLAppearanceMgr::instance().wearInventoryCategory(category, true, false);
+        }
+        return ACCEPT_YES_MULTI;
+    }
+    else
+    {
+        // TODO: copy/move category to avatar's inventory and then wear it.
+        return ACCEPT_NO;
+    }
 }
 
 
 EAcceptance LLToolDragAndDrop::dad3dUpdateInventory(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dadUpdateInventory()" << LL_ENDL;
-
-	// *HACK: In order to resolve SL-22177, we need to block drags
-	// from notecards and objects onto other objects.
-	if((SOURCE_WORLD == mSource) || (SOURCE_NOTECARD == mSource))
-	{
-		return ACCEPT_NO;
-	}
-
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-	LLViewerObject* root_object = obj;
-	if (obj && obj->getParent())
-	{
-		LLViewerObject* parent_obj = (LLViewerObject*)obj->getParent();
-		if (!parent_obj->isAvatar())
-		{
-			root_object = parent_obj;
-		}
-	}
-
-	EAcceptance rv = willObjectAcceptInventory(root_object, item);
-	if(root_object && drop && (ACCEPT_YES_COPY_SINGLE <= rv))
-	{
-		dropInventory(root_object, item, mSource, mSourceID);
-	}
-	return rv;
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dadUpdateInventory()" << LL_ENDL;
+
+    // *HACK: In order to resolve SL-22177, we need to block drags
+    // from notecards and objects onto other objects.
+    if((SOURCE_WORLD == mSource) || (SOURCE_NOTECARD == mSource))
+    {
+        return ACCEPT_NO;
+    }
+
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+    LLViewerObject* root_object = obj;
+    if (obj && obj->getParent())
+    {
+        LLViewerObject* parent_obj = (LLViewerObject*)obj->getParent();
+        if (!parent_obj->isAvatar())
+        {
+            root_object = parent_obj;
+        }
+    }
+
+    EAcceptance rv = willObjectAcceptInventory(root_object, item);
+    if(root_object && drop && (ACCEPT_YES_COPY_SINGLE <= rv))
+    {
+        dropInventory(root_object, item, mSource, mSourceID);
+    }
+    return rv;
 }
 
 BOOL LLToolDragAndDrop::dadUpdateInventory(LLViewerObject* obj, BOOL drop)
 {
-	EAcceptance rv = dad3dUpdateInventory(obj, -1, MASK_NONE, drop);
-	return (rv >= ACCEPT_YES_COPY_SINGLE);
+    EAcceptance rv = dad3dUpdateInventory(obj, -1, MASK_NONE, drop);
+    return (rv >= ACCEPT_YES_COPY_SINGLE);
 }
 
 EAcceptance LLToolDragAndDrop::dad3dUpdateInventoryCategory(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dUpdateInventoryCategory()" << LL_ENDL;
-	if (obj == NULL)
-	{
-		LL_WARNS() << "obj is NULL; aborting func with ACCEPT_NO" << LL_ENDL;
-		return ACCEPT_NO;
-	}
-
-	if ((mSource != SOURCE_AGENT) && (mSource != SOURCE_LIBRARY))
-	{
-		return ACCEPT_NO;
-	}
-	if (obj->isAttachment())
-	{
-		return ACCEPT_NO_LOCKED;
-	}
-
-	LLViewerInventoryItem* item = NULL;
-	LLViewerInventoryCategory* cat = NULL;
-	locateInventory(item, cat);
-	if (!cat) 
-	{
-		return ACCEPT_NO;
-	}
-
-	// Find all the items in the category
-	LLDroppableItem droppable(!obj->permYouOwner());
-	LLInventoryModel::cat_array_t cats;
-	LLInventoryModel::item_array_t items;
-	gInventory.collectDescendentsIf(cat->getUUID(),
-					cats,
-					items,
-					LLInventoryModel::EXCLUDE_TRASH,
-					droppable);
-	cats.push_back(cat);
- 	if (droppable.countNoCopy() > 0)
- 	{
- 		LL_WARNS() << "*** Need to confirm this step" << LL_ENDL;
- 	}
-	LLViewerObject* root_object = obj;
-	if (obj->getParent())
-	{
-		LLViewerObject* parent_obj = (LLViewerObject*)obj->getParent();
-		if (!parent_obj->isAvatar())
-		{
-			root_object = parent_obj;
-		}
-	}
-
-	EAcceptance rv = ACCEPT_NO;
-
-	// Check for accept
-	for (LLInventoryModel::cat_array_t::const_iterator cat_iter = cats.begin();
-		 cat_iter != cats.end();
-		 ++cat_iter)
-	{
-		const LLViewerInventoryCategory *cat = (*cat_iter);
-		rv = gInventory.isCategoryComplete(cat->getUUID()) ? ACCEPT_YES_MULTI : ACCEPT_NO;
-		if(rv < ACCEPT_YES_SINGLE)
-		{
-			LL_DEBUGS() << "Category " << cat->getUUID() << "is not complete." << LL_ENDL;
-			break;
-		}
-	}
-	if (ACCEPT_YES_COPY_SINGLE <= rv)
-	{
-		for (LLInventoryModel::item_array_t::const_iterator item_iter = items.begin();
-			 item_iter != items.end();
-			 ++item_iter)
-		{
-			LLViewerInventoryItem *item = (*item_iter);
-			/*
-			// Pass the base objects, not the links.
-			if (item && item->getIsLinkType())
-			{
-				item = item->getLinkedItem();
-				(*item_iter) = item;
-			}
-			*/
-			rv = willObjectAcceptInventory(root_object, item, DAD_CATEGORY);
-			if (rv < ACCEPT_YES_COPY_SINGLE)
-			{
-				LL_DEBUGS() << "Object will not accept " << item->getUUID() << LL_ENDL;
-				break;
-			}
-		}
-	}
-
-	// If every item is accepted, send it on
-	if (drop && (ACCEPT_YES_COPY_SINGLE <= rv))
-	{
-		uuid_vec_t ids;
-		for (LLInventoryModel::item_array_t::const_iterator item_iter = items.begin();
-			 item_iter != items.end();
-			 ++item_iter)
-		{
-			const LLViewerInventoryItem *item = (*item_iter);
-			ids.push_back(item->getUUID());
-		}
-		LLCategoryDropObserver* dropper = new LLCategoryDropObserver(ids, obj->getID(), mSource);
-		dropper->startFetch();
-		if (dropper->isFinished())
-		{
-			dropper->done();
-		}
-		else
-		{
-			gInventory.addObserver(dropper);
-		}
-	}
-	return rv;
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dUpdateInventoryCategory()" << LL_ENDL;
+    if (obj == NULL)
+    {
+        LL_WARNS() << "obj is NULL; aborting func with ACCEPT_NO" << LL_ENDL;
+        return ACCEPT_NO;
+    }
+
+    if ((mSource != SOURCE_AGENT) && (mSource != SOURCE_LIBRARY))
+    {
+        return ACCEPT_NO;
+    }
+    if (obj->isAttachment())
+    {
+        return ACCEPT_NO_LOCKED;
+    }
+
+    LLViewerInventoryItem* item = NULL;
+    LLViewerInventoryCategory* cat = NULL;
+    locateInventory(item, cat);
+    if (!cat)
+    {
+        return ACCEPT_NO;
+    }
+
+    // Find all the items in the category
+    LLDroppableItem droppable(!obj->permYouOwner());
+    LLInventoryModel::cat_array_t cats;
+    LLInventoryModel::item_array_t items;
+    gInventory.collectDescendentsIf(cat->getUUID(),
+                    cats,
+                    items,
+                    LLInventoryModel::EXCLUDE_TRASH,
+                    droppable);
+    cats.push_back(cat);
+    if (droppable.countNoCopy() > 0)
+    {
+        LL_WARNS() << "*** Need to confirm this step" << LL_ENDL;
+    }
+    LLViewerObject* root_object = obj;
+    if (obj->getParent())
+    {
+        LLViewerObject* parent_obj = (LLViewerObject*)obj->getParent();
+        if (!parent_obj->isAvatar())
+        {
+            root_object = parent_obj;
+        }
+    }
+
+    EAcceptance rv = ACCEPT_NO;
+
+    // Check for accept
+    for (LLInventoryModel::cat_array_t::const_iterator cat_iter = cats.begin();
+         cat_iter != cats.end();
+         ++cat_iter)
+    {
+        const LLViewerInventoryCategory *cat = (*cat_iter);
+        rv = gInventory.isCategoryComplete(cat->getUUID()) ? ACCEPT_YES_MULTI : ACCEPT_NO;
+        if(rv < ACCEPT_YES_SINGLE)
+        {
+            LL_DEBUGS() << "Category " << cat->getUUID() << "is not complete." << LL_ENDL;
+            break;
+        }
+    }
+    if (ACCEPT_YES_COPY_SINGLE <= rv)
+    {
+        for (LLInventoryModel::item_array_t::const_iterator item_iter = items.begin();
+             item_iter != items.end();
+             ++item_iter)
+        {
+            LLViewerInventoryItem *item = (*item_iter);
+            /*
+            // Pass the base objects, not the links.
+            if (item && item->getIsLinkType())
+            {
+                item = item->getLinkedItem();
+                (*item_iter) = item;
+            }
+            */
+            rv = willObjectAcceptInventory(root_object, item, DAD_CATEGORY);
+            if (rv < ACCEPT_YES_COPY_SINGLE)
+            {
+                LL_DEBUGS() << "Object will not accept " << item->getUUID() << LL_ENDL;
+                break;
+            }
+        }
+    }
+
+    // If every item is accepted, send it on
+    if (drop && (ACCEPT_YES_COPY_SINGLE <= rv))
+    {
+        uuid_vec_t ids;
+        for (LLInventoryModel::item_array_t::const_iterator item_iter = items.begin();
+             item_iter != items.end();
+             ++item_iter)
+        {
+            const LLViewerInventoryItem *item = (*item_iter);
+            ids.push_back(item->getUUID());
+        }
+        LLCategoryDropObserver* dropper = new LLCategoryDropObserver(ids, obj->getID(), mSource);
+        dropper->startFetch();
+        if (dropper->isFinished())
+        {
+            dropper->done();
+        }
+        else
+        {
+            gInventory.addObserver(dropper);
+        }
+    }
+    return rv;
 }
 
 
 EAcceptance LLToolDragAndDrop::dad3dRezCategoryOnObject(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
 {
-	if ((mask & MASK_CONTROL))
-	{
-		return dad3dUpdateInventoryCategory(obj, face, mask, drop);
-	}
-	else
-	{
-		return ACCEPT_NO;
-	}
+    if ((mask & MASK_CONTROL))
+    {
+        return dad3dUpdateInventoryCategory(obj, face, mask, drop);
+    }
+    else
+    {
+        return ACCEPT_NO;
+    }
 }
 
 
 BOOL LLToolDragAndDrop::dadUpdateInventoryCategory(LLViewerObject* obj,
-												   BOOL drop)
+                                                   BOOL drop)
 {
-	EAcceptance rv = dad3dUpdateInventoryCategory(obj, -1, MASK_NONE, drop);
-	return (rv >= ACCEPT_YES_COPY_SINGLE);
+    EAcceptance rv = dad3dUpdateInventoryCategory(obj, -1, MASK_NONE, drop);
+    return (rv >= ACCEPT_YES_COPY_SINGLE);
 }
 
 EAcceptance LLToolDragAndDrop::dad3dGiveInventoryObject(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dGiveInventoryObject()" << LL_ENDL;
-
-	// item has to be in agent inventory.
-	if(mSource != SOURCE_AGENT) return ACCEPT_NO;
-
-	// find the item now.
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-	if(!item->getPermissions().allowOperationBy(PERM_TRANSFER, gAgent.getID()))
-	{
-		// cannot give away no-transfer objects
-		return ACCEPT_NO;
-	}
-	LLVOAvatarSelf* avatar = gAgentAvatarp;
-	if(avatar && avatar->isWearingAttachment( item->getUUID() ) )
-	{
-		// You can't give objects that are attached to you
-		return ACCEPT_NO;
-	}
-	if( obj && avatar )
-	{
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dGiveInventoryObject()" << LL_ENDL;
+
+    // item has to be in agent inventory.
+    if(mSource != SOURCE_AGENT) return ACCEPT_NO;
+
+    // find the item now.
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+    if(!item->getPermissions().allowOperationBy(PERM_TRANSFER, gAgent.getID()))
+    {
+        // cannot give away no-transfer objects
+        return ACCEPT_NO;
+    }
+    LLVOAvatarSelf* avatar = gAgentAvatarp;
+    if(avatar && avatar->isWearingAttachment( item->getUUID() ) )
+    {
+        // You can't give objects that are attached to you
+        return ACCEPT_NO;
+    }
+    if( obj && avatar )
+    {
 // [RLVa:KB] - @share
-		if ( (obj) && (RlvActions::isRlvEnabled()) && (!RlvActions::canGiveInventory(obj->getID())) )
-		{
-			return ACCEPT_NO_LOCKED;
-		}
+        if ( (obj) && (RlvActions::isRlvEnabled()) && (!RlvActions::canGiveInventory(obj->getID())) )
+        {
+            return ACCEPT_NO_LOCKED;
+        }
 // [/RLVa:KB]
-		if(drop)
-		{
-			LLGiveInventory::doGiveInventoryItem(obj->getID(), item );
-		}
-		// *TODO: deal with all the issues surrounding multi-object
-		// inventory transfers.
-		return ACCEPT_YES_SINGLE;
-	}
-	return ACCEPT_NO;
+        if(drop)
+        {
+            LLGiveInventory::doGiveInventoryItem(obj->getID(), item );
+        }
+        // *TODO: deal with all the issues surrounding multi-object
+        // inventory transfers.
+        return ACCEPT_YES_SINGLE;
+    }
+    return ACCEPT_NO;
 }
 
 
 EAcceptance LLToolDragAndDrop::dad3dGiveInventory(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dGiveInventory()" << LL_ENDL;
-	// item has to be in agent inventory.
-	if(mSource != SOURCE_AGENT) return ACCEPT_NO;
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-	if (!LLGiveInventory::isInventoryGiveAcceptable(item))
-	{
-		return ACCEPT_NO;
-	}
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dGiveInventory()" << LL_ENDL;
+    // item has to be in agent inventory.
+    if(mSource != SOURCE_AGENT) return ACCEPT_NO;
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+    if (!LLGiveInventory::isInventoryGiveAcceptable(item))
+    {
+        return ACCEPT_NO;
+    }
 // [RLVa:KB] - @share
-	if ( (obj) && (RlvActions::isRlvEnabled()) && (!RlvActions::canGiveInventory(obj->getID())) )
-	{
-		return ACCEPT_NO_LOCKED;
-	}
+    if ( (obj) && (RlvActions::isRlvEnabled()) && (!RlvActions::canGiveInventory(obj->getID())) )
+    {
+        return ACCEPT_NO_LOCKED;
+    }
 // [/RLVa:KB]
-	if (drop && obj)
-	{
-		LLGiveInventory::doGiveInventoryItem(obj->getID(), item);
-	}
-	// *TODO: deal with all the issues surrounding multi-object
-	// inventory transfers.
-	return ACCEPT_YES_SINGLE;
+    if (drop && obj)
+    {
+        LLGiveInventory::doGiveInventoryItem(obj->getID(), item);
+    }
+    // *TODO: deal with all the issues surrounding multi-object
+    // inventory transfers.
+    return ACCEPT_YES_SINGLE;
 }
 
 EAcceptance LLToolDragAndDrop::dad3dGiveInventoryCategory(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
 {
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dGiveInventoryCategory()" << LL_ENDL;
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dGiveInventoryCategory()" << LL_ENDL;
 // [RLVa:KB] - @share
-	if ( (obj) && (RlvActions::isRlvEnabled()) && (!RlvActions::canGiveInventory(obj->getID())) )
-	{
-		return ACCEPT_NO_LOCKED;
-	}
+    if ( (obj) && (RlvActions::isRlvEnabled()) && (!RlvActions::canGiveInventory(obj->getID())) )
+    {
+        return ACCEPT_NO_LOCKED;
+    }
 // [/RLVa:KB]
-	if(drop && obj)
-	{
-		LLViewerInventoryItem* item;
-		LLViewerInventoryCategory* cat;
-		locateInventory(item, cat);
-		if(!cat) return ACCEPT_NO;
-		LLGiveInventory::doGiveInventoryCategory(obj->getID(), cat);
-	}
-	// *TODO: deal with all the issues surrounding multi-object
-	// inventory transfers.
-	return ACCEPT_YES_SINGLE;
+    if(drop && obj)
+    {
+        LLViewerInventoryItem* item;
+        LLViewerInventoryCategory* cat;
+        locateInventory(item, cat);
+        if(!cat) return ACCEPT_NO;
+        LLGiveInventory::doGiveInventoryCategory(obj->getID(), cat);
+    }
+    // *TODO: deal with all the issues surrounding multi-object
+    // inventory transfers.
+    return ACCEPT_YES_SINGLE;
 }
 
 
 EAcceptance LLToolDragAndDrop::dad3dRezFromObjectOnLand(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezFromObjectOnLand()" << LL_ENDL;
-	LLViewerInventoryItem* item = NULL;
-	LLViewerInventoryCategory* cat = NULL;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-
-	if(!gAgent.allowOperation(PERM_COPY, item->getPermissions())
-		|| !item->getPermissions().allowTransferTo(LLUUID::null))
-	{
-		return ACCEPT_NO_LOCKED;
-	}
-	if(drop)
-	{
-		dropObject(obj, TRUE, TRUE, FALSE);
-	}
-	return ACCEPT_YES_SINGLE;
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezFromObjectOnLand()" << LL_ENDL;
+    LLViewerInventoryItem* item = NULL;
+    LLViewerInventoryCategory* cat = NULL;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+
+    if(!gAgent.allowOperation(PERM_COPY, item->getPermissions())
+        || !item->getPermissions().allowTransferTo(LLUUID::null))
+    {
+        return ACCEPT_NO_LOCKED;
+    }
+    if(drop)
+    {
+        dropObject(obj, TRUE, TRUE, FALSE);
+    }
+    return ACCEPT_YES_SINGLE;
 }
 
 EAcceptance LLToolDragAndDrop::dad3dRezFromObjectOnObject(
-	LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
-{
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezFromObjectOnObject()" << LL_ENDL;
-	LLViewerInventoryItem* item;
-	LLViewerInventoryCategory* cat;
-	locateInventory(item, cat);
-	if (!item || !item->isFinished()) return ACCEPT_NO;
-	if((mask & MASK_CONTROL))
-	{
-		// *HACK: In order to resolve SL-22177, we need to block drags
-		// from notecards and objects onto other objects.
-		return ACCEPT_NO;
-
-		// *HACK: uncomment this when appropriate
-		//EAcceptance rv = willObjectAcceptInventory(obj, item);
-		//if(drop && (ACCEPT_YES_SINGLE <= rv))
-		//{
-		//	dropInventory(obj, item, mSource, mSourceID);
-		//}
-		//return rv;
-	}
-	if(!item->getPermissions().allowCopyBy(gAgent.getID(),
-										   gAgent.getGroupID())
-	   || !item->getPermissions().allowTransferTo(LLUUID::null))
-	{
-		return ACCEPT_NO_LOCKED;
-	}
-	if(drop)
-	{
-		dropObject(obj, FALSE, TRUE, FALSE);
-	}
-	return ACCEPT_YES_SINGLE;
+    LLViewerObject* obj, S32 face, MASK mask, BOOL drop)
+{
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dRezFromObjectOnObject()" << LL_ENDL;
+    LLViewerInventoryItem* item;
+    LLViewerInventoryCategory* cat;
+    locateInventory(item, cat);
+    if (!item || !item->isFinished()) return ACCEPT_NO;
+    if((mask & MASK_CONTROL))
+    {
+        // *HACK: In order to resolve SL-22177, we need to block drags
+        // from notecards and objects onto other objects.
+        return ACCEPT_NO;
+
+        // *HACK: uncomment this when appropriate
+        //EAcceptance rv = willObjectAcceptInventory(obj, item);
+        //if(drop && (ACCEPT_YES_SINGLE <= rv))
+        //{
+        //  dropInventory(obj, item, mSource, mSourceID);
+        //}
+        //return rv;
+    }
+    if(!item->getPermissions().allowCopyBy(gAgent.getID(),
+                                           gAgent.getGroupID())
+       || !item->getPermissions().allowTransferTo(LLUUID::null))
+    {
+        return ACCEPT_NO_LOCKED;
+    }
+    if(drop)
+    {
+        dropObject(obj, FALSE, TRUE, FALSE);
+    }
+    return ACCEPT_YES_SINGLE;
 }
 
 EAcceptance LLToolDragAndDrop::dad3dCategoryOnLand(
-	LLViewerObject *obj, S32 face, MASK mask, BOOL drop)
-{
-	return ACCEPT_NO;
-	/*
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dCategoryOnLand()" << LL_ENDL;
-	LLInventoryItem* item;
-	LLInventoryCategory* cat;
-	locateInventory(item, cat);
-	if(!cat) return ACCEPT_NO;
-	EAcceptance rv = ACCEPT_NO;
-
-	// find all the items in the category
-	LLViewerInventoryCategory::cat_array_t cats;
-	LLViewerInventoryItem::item_array_t items;
-	LLDropCopyableItems droppable;
-	gInventory.collectDescendentsIf(cat->getUUID(),
-									cats,
-									items,
-									LLInventoryModel::EXCLUDE_TRASH,
-									droppable);
-	if(items.size() > 0)
-	{
-		rv = ACCEPT_YES_SINGLE;
-	}
-	if((rv >= ACCEPT_YES_COPY_SINGLE) && drop)
-	{
-		createContainer(items, cat->getName());
-		return ACCEPT_NO;
-	}
-	return rv;
-	*/
+    LLViewerObject *obj, S32 face, MASK mask, BOOL drop)
+{
+    return ACCEPT_NO;
+    /*
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dCategoryOnLand()" << LL_ENDL;
+    LLInventoryItem* item;
+    LLInventoryCategory* cat;
+    locateInventory(item, cat);
+    if(!cat) return ACCEPT_NO;
+    EAcceptance rv = ACCEPT_NO;
+
+    // find all the items in the category
+    LLViewerInventoryCategory::cat_array_t cats;
+    LLViewerInventoryItem::item_array_t items;
+    LLDropCopyableItems droppable;
+    gInventory.collectDescendentsIf(cat->getUUID(),
+                                    cats,
+                                    items,
+                                    LLInventoryModel::EXCLUDE_TRASH,
+                                    droppable);
+    if(items.size() > 0)
+    {
+        rv = ACCEPT_YES_SINGLE;
+    }
+    if((rv >= ACCEPT_YES_COPY_SINGLE) && drop)
+    {
+        createContainer(items, cat->getName());
+        return ACCEPT_NO;
+    }
+    return rv;
+    */
 }
 
 
@@ -3093,163 +3093,163 @@ EAcceptance LLToolDragAndDrop::dad3dCategoryOnLand(
 // This shortcuts alot of steps to make a basic object
 // w/ an inventory and a special permissions set
 EAcceptance LLToolDragAndDrop::dad3dAssetOnLand(
-	LLViewerObject *obj, S32 face, MASK mask, BOOL drop)
-{
-	return ACCEPT_NO;
-	/*
-	LL_DEBUGS() << "LLToolDragAndDrop::dad3dAssetOnLand()" << LL_ENDL;
-	LLViewerInventoryCategory::cat_array_t cats;
-	LLViewerInventoryItem::item_array_t items;
-	LLViewerInventoryItem::item_array_t copyable_items;
-	locateMultipleInventory(items, cats);
-	if(!items.size()) return ACCEPT_NO;
-	EAcceptance rv = ACCEPT_NO;
-	for (S32 i = 0; i < items.size(); i++)
-	{
-		LLInventoryItem* item = items[i];
-		if(item->getPermissions().allowCopyBy(gAgent.getID()))
-		{
-			copyable_items.push_back(item);
-			rv = ACCEPT_YES_SINGLE;
-		}
-	}
-
-	if((rv >= ACCEPT_YES_COPY_SINGLE) && drop)
-	{
-		createContainer(copyable_items, NULL);
-	}
-
-	return rv;
-	*/
+    LLViewerObject *obj, S32 face, MASK mask, BOOL drop)
+{
+    return ACCEPT_NO;
+    /*
+    LL_DEBUGS() << "LLToolDragAndDrop::dad3dAssetOnLand()" << LL_ENDL;
+    LLViewerInventoryCategory::cat_array_t cats;
+    LLViewerInventoryItem::item_array_t items;
+    LLViewerInventoryItem::item_array_t copyable_items;
+    locateMultipleInventory(items, cats);
+    if(!items.size()) return ACCEPT_NO;
+    EAcceptance rv = ACCEPT_NO;
+    for (S32 i = 0; i < items.size(); i++)
+    {
+        LLInventoryItem* item = items[i];
+        if(item->getPermissions().allowCopyBy(gAgent.getID()))
+        {
+            copyable_items.push_back(item);
+            rv = ACCEPT_YES_SINGLE;
+        }
+    }
+
+    if((rv >= ACCEPT_YES_COPY_SINGLE) && drop)
+    {
+        createContainer(copyable_items, NULL);
+    }
+
+    return rv;
+    */
 }
 
 LLInventoryObject* LLToolDragAndDrop::locateInventory(
-	LLViewerInventoryItem*& item,
-	LLViewerInventoryCategory*& cat)
-{
-	item = NULL;
-	cat = NULL;
-
-	if (mCargoIDs.empty()
-		|| (mSource == SOURCE_PEOPLE)) ///< There is no inventory item for people drag and drop.
-	{
-		return NULL;
-	}
-
-	if((mSource == SOURCE_AGENT) || (mSource == SOURCE_LIBRARY))
-	{
-		// The object should be in user inventory.
-		item = (LLViewerInventoryItem*)gInventory.getItem(mCargoIDs[mCurItemIndex]);
-		cat = (LLViewerInventoryCategory*)gInventory.getCategory(mCargoIDs[mCurItemIndex]);
-	}
-	else if(mSource == SOURCE_WORLD)
-	{
-		// This object is in some task inventory somewhere.
-		LLViewerObject* obj = gObjectList.findObject(mSourceID);
-		if(obj)
-		{
-			if((mCargoTypes[mCurItemIndex] == DAD_CATEGORY)
-			   || (mCargoTypes[mCurItemIndex] == DAD_ROOT_CATEGORY))
-			{
-				cat = (LLViewerInventoryCategory*)obj->getInventoryObject(mCargoIDs[mCurItemIndex]);
-			}
-			else
-			{
-			   item = (LLViewerInventoryItem*)obj->getInventoryObject(mCargoIDs[mCurItemIndex]);
-			}
-		}
-	}
-	else if(mSource == SOURCE_NOTECARD)
-	{
-		LLPreviewNotecard* preview = LLFloaterReg::findTypedInstance<LLPreviewNotecard>("preview_notecard", mSourceID);
-		if(preview)
-		{
-			item = (LLViewerInventoryItem*)preview->getDragItem();
-		}
-	}
-	else if(mSource == SOURCE_VIEWER)
-	{
-		item = (LLViewerInventoryItem*)gToolBarView->getDragItem();
-	}
-
-	if(item) return item;
-	if(cat) return cat;
-	return NULL;
+    LLViewerInventoryItem*& item,
+    LLViewerInventoryCategory*& cat)
+{
+    item = NULL;
+    cat = NULL;
+
+    if (mCargoIDs.empty()
+        || (mSource == SOURCE_PEOPLE)) ///< There is no inventory item for people drag and drop.
+    {
+        return NULL;
+    }
+
+    if((mSource == SOURCE_AGENT) || (mSource == SOURCE_LIBRARY))
+    {
+        // The object should be in user inventory.
+        item = (LLViewerInventoryItem*)gInventory.getItem(mCargoIDs[mCurItemIndex]);
+        cat = (LLViewerInventoryCategory*)gInventory.getCategory(mCargoIDs[mCurItemIndex]);
+    }
+    else if(mSource == SOURCE_WORLD)
+    {
+        // This object is in some task inventory somewhere.
+        LLViewerObject* obj = gObjectList.findObject(mSourceID);
+        if(obj)
+        {
+            if((mCargoTypes[mCurItemIndex] == DAD_CATEGORY)
+               || (mCargoTypes[mCurItemIndex] == DAD_ROOT_CATEGORY))
+            {
+                cat = (LLViewerInventoryCategory*)obj->getInventoryObject(mCargoIDs[mCurItemIndex]);
+            }
+            else
+            {
+               item = (LLViewerInventoryItem*)obj->getInventoryObject(mCargoIDs[mCurItemIndex]);
+            }
+        }
+    }
+    else if(mSource == SOURCE_NOTECARD)
+    {
+        LLPreviewNotecard* preview = LLFloaterReg::findTypedInstance<LLPreviewNotecard>("preview_notecard", mSourceID);
+        if(preview)
+        {
+            item = (LLViewerInventoryItem*)preview->getDragItem();
+        }
+    }
+    else if(mSource == SOURCE_VIEWER)
+    {
+        item = (LLViewerInventoryItem*)gToolBarView->getDragItem();
+    }
+
+    if(item) return item;
+    if(cat) return cat;
+    return NULL;
 }
 
 /*
 LLInventoryObject* LLToolDragAndDrop::locateMultipleInventory(LLViewerInventoryCategory::cat_array_t& cats,
-															  LLViewerInventoryItem::item_array_t& items)
-{
-	if(mCargoIDs.size() == 0) return NULL;
-	if((mSource == SOURCE_AGENT) || (mSource == SOURCE_LIBRARY))
-	{
-		// The object should be in user inventory.
-		for (S32 i = 0; i < mCargoIDs.size(); i++)
-		{
-			LLInventoryItem* item = gInventory.getItem(mCargoIDs[i]);
-			if (item)
-			{
-				items.push_back(item);
-			}
-			LLInventoryCategory* category = gInventory.getCategory(mCargoIDs[i]);
-			if (category)
-			{
-				cats.push_back(category);
-			}
-		}
-	}
-	else if(mSource == SOURCE_WORLD)
-	{
-		// This object is in some task inventory somewhere.
-		LLViewerObject* obj = gObjectList.findObject(mSourceID);
-		if(obj)
-		{
-			if((mCargoType == DAD_CATEGORY)
-			   || (mCargoType == DAD_ROOT_CATEGORY))
-			{
-				// The object should be in user inventory.
-				for (S32 i = 0; i < mCargoIDs.size(); i++)
-				{
-					LLInventoryCategory* category = (LLInventoryCategory*)obj->getInventoryObject(mCargoIDs[i]);
-					if (category)
-					{
-						cats.push_back(category);
-					}
-				}
-			}
-			else
-			{
-				for (S32 i = 0; i < mCargoIDs.size(); i++)
-				{
-					LLInventoryItem* item = (LLInventoryItem*)obj->getInventoryObject(mCargoIDs[i]);
-					if (item)
-					{
-						items.push_back(item);
-					}
-				}
-			}
-		}
-	}
-	else if(mSource == SOURCE_NOTECARD)
-	{
-		LLPreviewNotecard* card;
-		card = (LLPreviewNotecard*)LLPreview::find(mSourceID);
-		if(card)
-		{
-			items.push_back((LLInventoryItem*)card->getDragItem());
-		}
-	}
-	if(items.size()) return items[0];
-	if(cats.size()) return cats[0];
-	return NULL;
+                                                              LLViewerInventoryItem::item_array_t& items)
+{
+    if(mCargoIDs.size() == 0) return NULL;
+    if((mSource == SOURCE_AGENT) || (mSource == SOURCE_LIBRARY))
+    {
+        // The object should be in user inventory.
+        for (S32 i = 0; i < mCargoIDs.size(); i++)
+        {
+            LLInventoryItem* item = gInventory.getItem(mCargoIDs[i]);
+            if (item)
+            {
+                items.push_back(item);
+            }
+            LLInventoryCategory* category = gInventory.getCategory(mCargoIDs[i]);
+            if (category)
+            {
+                cats.push_back(category);
+            }
+        }
+    }
+    else if(mSource == SOURCE_WORLD)
+    {
+        // This object is in some task inventory somewhere.
+        LLViewerObject* obj = gObjectList.findObject(mSourceID);
+        if(obj)
+        {
+            if((mCargoType == DAD_CATEGORY)
+               || (mCargoType == DAD_ROOT_CATEGORY))
+            {
+                // The object should be in user inventory.
+                for (S32 i = 0; i < mCargoIDs.size(); i++)
+                {
+                    LLInventoryCategory* category = (LLInventoryCategory*)obj->getInventoryObject(mCargoIDs[i]);
+                    if (category)
+                    {
+                        cats.push_back(category);
+                    }
+                }
+            }
+            else
+            {
+                for (S32 i = 0; i < mCargoIDs.size(); i++)
+                {
+                    LLInventoryItem* item = (LLInventoryItem*)obj->getInventoryObject(mCargoIDs[i]);
+                    if (item)
+                    {
+                        items.push_back(item);
+                    }
+                }
+            }
+        }
+    }
+    else if(mSource == SOURCE_NOTECARD)
+    {
+        LLPreviewNotecard* card;
+        card = (LLPreviewNotecard*)LLPreview::find(mSourceID);
+        if(card)
+        {
+            items.push_back((LLInventoryItem*)card->getDragItem());
+        }
+    }
+    if(items.size()) return items[0];
+    if(cats.size()) return cats[0];
+    return NULL;
 }
 */
 
 // void LLToolDragAndDrop::createContainer(LLViewerInventoryItem::item_array_t &items, const char* preferred_name )
 // {
-// 	LL_WARNS() << "LLToolDragAndDrop::createContainer()" << LL_ENDL;
-// 	return;
+//  LL_WARNS() << "LLToolDragAndDrop::createContainer()" << LL_ENDL;
+//  return;
 // }
 
 
@@ -3257,13 +3257,13 @@ LLInventoryObject* LLToolDragAndDrop::locateMultipleInventory(LLViewerInventoryC
 
 void pack_permissions_slam(LLMessageSystem* msg, U32 flags, const LLPermissions& perms)
 {
-	// CRUFT -- the server no longer pays attention to this data
-	U32 group_mask		= perms.getMaskGroup();
-	U32 everyone_mask	= perms.getMaskEveryone();
-	U32 next_owner_mask	= perms.getMaskNextOwner();
-	
-	msg->addU32Fast(_PREHASH_ItemFlags, flags);
-	msg->addU32Fast(_PREHASH_GroupMask, group_mask);
-	msg->addU32Fast(_PREHASH_EveryoneMask, everyone_mask);
-	msg->addU32Fast(_PREHASH_NextOwnerMask, next_owner_mask);
+    // CRUFT -- the server no longer pays attention to this data
+    U32 group_mask      = perms.getMaskGroup();
+    U32 everyone_mask   = perms.getMaskEveryone();
+    U32 next_owner_mask = perms.getMaskNextOwner();
+
+    msg->addU32Fast(_PREHASH_ItemFlags, flags);
+    msg->addU32Fast(_PREHASH_GroupMask, group_mask);
+    msg->addU32Fast(_PREHASH_EveryoneMask, everyone_mask);
+    msg->addU32Fast(_PREHASH_NextOwnerMask, next_owner_mask);
 }
diff --git a/indra/newview/lltoolselect.cpp b/indra/newview/lltoolselect.cpp
index 9e5aa06e2182daffd81c983e133593dc606641b3..40419ba4394d9770448d5f71020e9a75cc923094 100644
--- a/indra/newview/lltoolselect.cpp
+++ b/indra/newview/lltoolselect.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file lltoolselect.cpp
  * @brief LLToolSelect class implementation
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -42,8 +42,8 @@
 #include "llviewercamera.h"
 #include "llviewermenu.h"
 #include "llviewerobject.h"
-#include "llviewerobjectlist.h" 
-#include "llviewerregion.h" 
+#include "llviewerobjectlist.h"
+#include "llviewerregion.h"
 #include "llviewerwindow.h"
 #include "llvoavatarself.h"
 #include "llworld.h"
@@ -60,277 +60,277 @@ const F32 SELECTION_ROTATION_TRESHOLD = 0.1f;
 const F32 SELECTION_SITTING_ROTATION_TRESHOLD = 3.2f; //radian
 
 LLToolSelect::LLToolSelect( LLToolComposite* composite )
-:	LLTool( std::string("Select"), composite ),
-	mIgnoreGroup( FALSE )
+:   LLTool( std::string("Select"), composite ),
+    mIgnoreGroup( FALSE )
 {
  }
 
 // True if you selected an object.
 BOOL LLToolSelect::handleMouseDown(S32 x, S32 y, MASK mask)
 {
-	// do immediate pick query
+    // do immediate pick query
     BOOL pick_rigged = false; //gSavedSettings.getBOOL("AnimatedObjectsAllowLeftClick");
     BOOL pick_transparent = gSavedSettings.getBOOL("SelectInvisibleObjects");
     BOOL pick_reflection_probe = gSavedSettings.getBOOL("SelectReflectionProbes");
 
-	mPick = gViewerWindow->pickImmediate(x, y, pick_transparent, pick_rigged, FALSE, TRUE, pick_reflection_probe);
+    mPick = gViewerWindow->pickImmediate(x, y, pick_transparent, pick_rigged, FALSE, TRUE, pick_reflection_probe);
 
-	// Pass mousedown to agent
-	LLTool::handleMouseDown(x, y, mask);
+    // Pass mousedown to agent
+    LLTool::handleMouseDown(x, y, mask);
 
-	return mPick.getObject().notNull();
+    return mPick.getObject().notNull();
 }
 
 
 // static
 LLObjectSelectionHandle LLToolSelect::handleObjectSelection(const LLPickInfo& pick, BOOL ignore_group, BOOL temp_select, BOOL select_root)
 {
-	LLViewerObject* object = pick.getObject();
-	if (select_root)
-	{
-		object = object->getRootEdit();
-	}
+    LLViewerObject* object = pick.getObject();
+    if (select_root)
+    {
+        object = object->getRootEdit();
+    }
 
 // [RLVa:KB] - Checked: RLVa-2.1.0
-	if ( (object) && (RlvActions::isRlvEnabled()) )
-	{
-		if (!RlvActions::canEdit(object))
-		{
-			if (!temp_select)
-				return LLSelectMgr::getInstance()->getSelection();
-			else if (LLToolMgr::instance().inBuildMode())
-				LLToolMgr::instance().leaveBuildMode();
-		}
-
-		if ( (RlvActions::hasBehaviour(RLV_BHVR_FARTOUCH)) && ( (!object->isAttachment()) || (!object->permYouOwner())) )
-		{
-			static RlvCachedBehaviourModifier<float> s_nFartouchDist(RLV_MODIFIER_FARTOUCHDIST);
-			float nFartouchDistSq = s_nFartouchDist * s_nFartouchDist;
-
-			// User is allowed to edit/select this object if it's within their current fartouch distance
-			if (dist_vec_squared(gAgent.getPositionAgent(), object->getPositionRegion()) > nFartouchDistSq)
-			{
-				// The object is out of range but we'll still allow them a temporary select (e.g. context menu) if the surface point is within range
-				if (dist_vec_squared(gAgent.getPositionAgent(), pick.mIntersection) > 1.5f * 1.5f)
-				{
-					// Even the surface point is out of range so deny them the hit
-					if ( (LLFloaterReg::instanceVisible("build")) && (pick.mKeyMask != MASK_SHIFT) && (pick.mKeyMask != MASK_CONTROL) )
-						LLSelectMgr::getInstance()->deselectAll();
-					return LLSelectMgr::getInstance()->getSelection();
-				}
-				else if (LLToolMgr::instance().inBuildMode())
-				{
-					// Allow the selection but keep it temporary by pulling them out of build mode when they click too far
-					LLToolMgr::instance().leaveBuildMode();
-				}
-			}
-		}
-	}
+    if ( (object) && (RlvActions::isRlvEnabled()) )
+    {
+        if (!RlvActions::canEdit(object))
+        {
+            if (!temp_select)
+                return LLSelectMgr::getInstance()->getSelection();
+            else if (LLToolMgr::instance().inBuildMode())
+                LLToolMgr::instance().leaveBuildMode();
+        }
+
+        if ( (RlvActions::hasBehaviour(RLV_BHVR_FARTOUCH)) && ( (!object->isAttachment()) || (!object->permYouOwner())) )
+        {
+            static RlvCachedBehaviourModifier<float> s_nFartouchDist(RLV_MODIFIER_FARTOUCHDIST);
+            float nFartouchDistSq = s_nFartouchDist * s_nFartouchDist;
+
+            // User is allowed to edit/select this object if it's within their current fartouch distance
+            if (dist_vec_squared(gAgent.getPositionAgent(), object->getPositionRegion()) > nFartouchDistSq)
+            {
+                // The object is out of range but we'll still allow them a temporary select (e.g. context menu) if the surface point is within range
+                if (dist_vec_squared(gAgent.getPositionAgent(), pick.mIntersection) > 1.5f * 1.5f)
+                {
+                    // Even the surface point is out of range so deny them the hit
+                    if ( (LLFloaterReg::instanceVisible("build")) && (pick.mKeyMask != MASK_SHIFT) && (pick.mKeyMask != MASK_CONTROL) )
+                        LLSelectMgr::getInstance()->deselectAll();
+                    return LLSelectMgr::getInstance()->getSelection();
+                }
+                else if (LLToolMgr::instance().inBuildMode())
+                {
+                    // Allow the selection but keep it temporary by pulling them out of build mode when they click too far
+                    LLToolMgr::instance().leaveBuildMode();
+                }
+            }
+        }
+    }
 // [/RLVa:KB]
 
-	bool select_copy = gSavedSettings.getBOOL("SelectCopyOnly");
-	BOOL select_owned = gSavedSettings.getBOOL("SelectOwnedOnly");
-	BOOL select_movable = gSavedSettings.getBOOL("SelectMovableOnly");
+    bool select_copy = gSavedSettings.getBOOL("SelectCopyOnly");
+    BOOL select_owned = gSavedSettings.getBOOL("SelectOwnedOnly");
+    BOOL select_movable = gSavedSettings.getBOOL("SelectMovableOnly");
 
     // *NOTE: These settings must be cleaned up at bottom of function.
-	if (temp_select || LLSelectMgr::getInstance()->mAllowSelectAvatar)
-	{
-		gSavedSettings.setBOOL("SelectCopyOnly", FALSE);
-		gSavedSettings.setBOOL("SelectOwnedOnly", FALSE);
-		gSavedSettings.setBOOL("SelectMovableOnly", FALSE);
-    	LLSelectMgr::getInstance()->setForceSelection(TRUE);
-	}
-
-	BOOL extend_select = (pick.mKeyMask == MASK_SHIFT) || (pick.mKeyMask == MASK_CONTROL);
-
-	// If no object, check for icon, then just deselect
-	if (!object)
-	{
-		LLHUDIcon* last_hit_hud_icon = pick.mHUDIcon;
-
-		if (last_hit_hud_icon && last_hit_hud_icon->getSourceObject())
-		{
-			LLFloaterScriptDebug::show(last_hit_hud_icon->getSourceObject()->getID());
-		}
-		else if (!extend_select)
-		{
-			LLSelectMgr::getInstance()->deselectAll();
-		}
-	}
-	else
-	{
-		BOOL already_selected = object->isSelected();
-
-		if (already_selected &&
-			object->getNumTEs() > 0 &&
-			!LLSelectMgr::getInstance()->getSelection()->contains(object,SELECT_ALL_TES))
-		{
-			const LLTextureEntry* tep = object->getTE(pick.mObjectFace);
-			if (tep && !tep->isSelected() && !LLViewerMediaFocus::getInstance()->getFocusedObjectID().isNull())
-			{
-				// we were interacting with media and clicked on non selected face, drop media focus
-				LLViewerMediaFocus::getInstance()->clearFocus();
-				// selection was removed and zoom preserved by clearFocus(), continue with regular selection
-				already_selected = false;
-				extend_select = true;
-			}
-		}
-
-		if ( extend_select )
-		{
-			if ( already_selected )
-			{
-				if ( ignore_group )
-				{
-					LLSelectMgr::getInstance()->deselectObjectOnly(object);
-				}
-				else
-				{
-					LLSelectMgr::getInstance()->deselectObjectAndFamily(object, TRUE, TRUE);
-				}
-			}
-			else
-			{
-				if ( ignore_group )
-				{
-					LLSelectMgr::getInstance()->selectObjectOnly(object, SELECT_ALL_TES);
-				}
-				else
-				{
-					LLSelectMgr::getInstance()->selectObjectAndFamily(object);
-				}
-			}
-		}
-		else
-		{
-			// Save the current zoom values because deselect resets them.
-			F32 target_zoom;
-			F32 current_zoom;
-			LLSelectMgr::getInstance()->getAgentHUDZoom(target_zoom, current_zoom);
-
-			// JC - Change behavior to make it easier to select children
-			// of linked sets. 9/3/2002
-			if( !already_selected || ignore_group)
-			{
-				// ...lose current selection in favor of just this object
-				LLSelectMgr::getInstance()->deselectAll();
-			}
-
-			if ( ignore_group )
-			{
-				LLSelectMgr::getInstance()->selectObjectOnly(object, SELECT_ALL_TES, pick.mGLTFNodeIndex, pick.mGLTFPrimitiveIndex);
-			}
-			else
-			{
-				LLSelectMgr::getInstance()->selectObjectAndFamily(object);
-			}
-
-			// restore the zoom to the previously stored values.
-			LLSelectMgr::getInstance()->setAgentHUDZoom(target_zoom, current_zoom);
-		}
-
-		static LLCachedControl<bool> disablePointAt(gSavedSettings, "AlchemyPointAtPrivate", false);
-		if (!disablePointAt && !gAgentCamera.getFocusOnAvatar() &&										// if camera not glued to avatar
-			LLVOAvatar::findAvatarFromAttachment(object) != gAgentAvatarp &&	// and it's not one of your attachments
-			object != gAgentAvatarp)									// and it's not you
-		{
-			// have avatar turn to face the selected object(s)
-			LLVector3d selection_center = LLSelectMgr::getInstance()->getSelectionCenterGlobal();
-			selection_center = selection_center - gAgent.getPositionGlobal();
-			LLVector3 selection_dir;
-			selection_dir.setVec(selection_center);
-			selection_dir.mV[VZ] = 0.f;
-			selection_dir.normVec();
-			if (!object->isAvatar() && gAgent.getAtAxis() * selection_dir < 0.6f)
-			{
-				LLQuaternion target_rot;
-				target_rot.shortestArc(LLVector3::x_axis, selection_dir);
-				gAgent.startAutoPilotGlobal(gAgent.getPositionGlobal(),
-											"",
-											&target_rot,
-											NULL,
-											NULL,
-											MAX_FAR_CLIP /*stop_distance, don't care since we are looking, not moving*/,
-											gAgentAvatarp->isSitting() ? SELECTION_SITTING_ROTATION_TRESHOLD : SELECTION_ROTATION_TRESHOLD);
-			}
-		}
-
-		if (temp_select)
-		{
-			if (!already_selected)
-			{
-				LLViewerObject* root_object = (LLViewerObject*)object->getRootEdit();
-				LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-
-				// this is just a temporary selection
-				LLSelectNode* select_node = selection->findNode(root_object);
-				if (select_node)
-				{
-					select_node->setTransient(TRUE);
-				}
-
-				LLViewerObject::const_child_list_t& child_list = root_object->getChildren();
-				for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
-					 iter != child_list.end(); iter++)
-				{
-					LLViewerObject* child = *iter;
-					select_node = selection->findNode(child);
-					if (select_node)
-					{
-						select_node->setTransient(TRUE);
-					}
-				}
-
-			}
-		} //if(temp_select)
-	} //if(!object)
-
-	// Cleanup temp select settings above.
-	if (temp_select ||LLSelectMgr::getInstance()->mAllowSelectAvatar)
-	{
-		gSavedSettings.setBOOL("SelectCopyOnly", select_copy);
-		gSavedSettings.setBOOL("SelectOwnedOnly", select_owned);
-		gSavedSettings.setBOOL("SelectMovableOnly", select_movable);
-		LLSelectMgr::getInstance()->setForceSelection(FALSE);
-	}
-
-	return LLSelectMgr::getInstance()->getSelection();
+    if (temp_select || LLSelectMgr::getInstance()->mAllowSelectAvatar)
+    {
+        gSavedSettings.setBOOL("SelectCopyOnly", FALSE);
+        gSavedSettings.setBOOL("SelectOwnedOnly", FALSE);
+        gSavedSettings.setBOOL("SelectMovableOnly", FALSE);
+        LLSelectMgr::getInstance()->setForceSelection(TRUE);
+    }
+
+    BOOL extend_select = (pick.mKeyMask == MASK_SHIFT) || (pick.mKeyMask == MASK_CONTROL);
+
+    // If no object, check for icon, then just deselect
+    if (!object)
+    {
+        LLHUDIcon* last_hit_hud_icon = pick.mHUDIcon;
+
+        if (last_hit_hud_icon && last_hit_hud_icon->getSourceObject())
+        {
+            LLFloaterScriptDebug::show(last_hit_hud_icon->getSourceObject()->getID());
+        }
+        else if (!extend_select)
+        {
+            LLSelectMgr::getInstance()->deselectAll();
+        }
+    }
+    else
+    {
+        BOOL already_selected = object->isSelected();
+
+        if (already_selected &&
+            object->getNumTEs() > 0 &&
+            !LLSelectMgr::getInstance()->getSelection()->contains(object,SELECT_ALL_TES))
+        {
+            const LLTextureEntry* tep = object->getTE(pick.mObjectFace);
+            if (tep && !tep->isSelected() && !LLViewerMediaFocus::getInstance()->getFocusedObjectID().isNull())
+            {
+                // we were interacting with media and clicked on non selected face, drop media focus
+                LLViewerMediaFocus::getInstance()->clearFocus();
+                // selection was removed and zoom preserved by clearFocus(), continue with regular selection
+                already_selected = false;
+                extend_select = true;
+            }
+        }
+
+        if ( extend_select )
+        {
+            if ( already_selected )
+            {
+                if ( ignore_group )
+                {
+                    LLSelectMgr::getInstance()->deselectObjectOnly(object);
+                }
+                else
+                {
+                    LLSelectMgr::getInstance()->deselectObjectAndFamily(object, TRUE, TRUE);
+                }
+            }
+            else
+            {
+                if ( ignore_group )
+                {
+                    LLSelectMgr::getInstance()->selectObjectOnly(object, SELECT_ALL_TES);
+                }
+                else
+                {
+                    LLSelectMgr::getInstance()->selectObjectAndFamily(object);
+                }
+            }
+        }
+        else
+        {
+            // Save the current zoom values because deselect resets them.
+            F32 target_zoom;
+            F32 current_zoom;
+            LLSelectMgr::getInstance()->getAgentHUDZoom(target_zoom, current_zoom);
+
+            // JC - Change behavior to make it easier to select children
+            // of linked sets. 9/3/2002
+            if( !already_selected || ignore_group)
+            {
+                // ...lose current selection in favor of just this object
+                LLSelectMgr::getInstance()->deselectAll();
+            }
+
+            if ( ignore_group )
+            {
+                LLSelectMgr::getInstance()->selectObjectOnly(object, SELECT_ALL_TES, pick.mGLTFNodeIndex, pick.mGLTFPrimitiveIndex);
+            }
+            else
+            {
+                LLSelectMgr::getInstance()->selectObjectAndFamily(object);
+            }
+
+            // restore the zoom to the previously stored values.
+            LLSelectMgr::getInstance()->setAgentHUDZoom(target_zoom, current_zoom);
+        }
+
+        static LLCachedControl<bool> disablePointAt(gSavedSettings, "AlchemyPointAtPrivate", false);
+        if (!disablePointAt && !gAgentCamera.getFocusOnAvatar() &&                                      // if camera not glued to avatar
+            LLVOAvatar::findAvatarFromAttachment(object) != gAgentAvatarp &&    // and it's not one of your attachments
+            object != gAgentAvatarp)                                    // and it's not you
+        {
+            // have avatar turn to face the selected object(s)
+            LLVector3d selection_center = LLSelectMgr::getInstance()->getSelectionCenterGlobal();
+            selection_center = selection_center - gAgent.getPositionGlobal();
+            LLVector3 selection_dir;
+            selection_dir.setVec(selection_center);
+            selection_dir.mV[VZ] = 0.f;
+            selection_dir.normVec();
+            if (!object->isAvatar() && gAgent.getAtAxis() * selection_dir < 0.6f)
+            {
+                LLQuaternion target_rot;
+                target_rot.shortestArc(LLVector3::x_axis, selection_dir);
+                gAgent.startAutoPilotGlobal(gAgent.getPositionGlobal(),
+                                            "",
+                                            &target_rot,
+                                            NULL,
+                                            NULL,
+                                            MAX_FAR_CLIP /*stop_distance, don't care since we are looking, not moving*/,
+                                            gAgentAvatarp->isSitting() ? SELECTION_SITTING_ROTATION_TRESHOLD : SELECTION_ROTATION_TRESHOLD);
+            }
+        }
+
+        if (temp_select)
+        {
+            if (!already_selected)
+            {
+                LLViewerObject* root_object = (LLViewerObject*)object->getRootEdit();
+                LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+
+                // this is just a temporary selection
+                LLSelectNode* select_node = selection->findNode(root_object);
+                if (select_node)
+                {
+                    select_node->setTransient(TRUE);
+                }
+
+                LLViewerObject::const_child_list_t& child_list = root_object->getChildren();
+                for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
+                     iter != child_list.end(); iter++)
+                {
+                    LLViewerObject* child = *iter;
+                    select_node = selection->findNode(child);
+                    if (select_node)
+                    {
+                        select_node->setTransient(TRUE);
+                    }
+                }
+
+            }
+        } //if(temp_select)
+    } //if(!object)
+
+    // Cleanup temp select settings above.
+    if (temp_select ||LLSelectMgr::getInstance()->mAllowSelectAvatar)
+    {
+        gSavedSettings.setBOOL("SelectCopyOnly", select_copy);
+        gSavedSettings.setBOOL("SelectOwnedOnly", select_owned);
+        gSavedSettings.setBOOL("SelectMovableOnly", select_movable);
+        LLSelectMgr::getInstance()->setForceSelection(FALSE);
+    }
+
+    return LLSelectMgr::getInstance()->getSelection();
 }
 
 BOOL LLToolSelect::handleMouseUp(S32 x, S32 y, MASK mask)
 {
-	mIgnoreGroup = ALControlCache::EditLinkedParts;
+    mIgnoreGroup = ALControlCache::EditLinkedParts;
 
-	handleObjectSelection(mPick, mIgnoreGroup, FALSE);
+    handleObjectSelection(mPick, mIgnoreGroup, FALSE);
 
-	return LLTool::handleMouseUp(x, y, mask);
+    return LLTool::handleMouseUp(x, y, mask);
 }
 
 void LLToolSelect::handleDeselect()
 {
-	if(	hasMouseCapture() )
-	{
-		setMouseCapture( FALSE );  // Calls onMouseCaptureLost() indirectly
-	}
+    if( hasMouseCapture() )
+    {
+        setMouseCapture( FALSE );  // Calls onMouseCaptureLost() indirectly
+    }
 }
 
 
 void LLToolSelect::stopEditing()
 {
-	if(	hasMouseCapture() )
-	{
-		setMouseCapture( FALSE );  // Calls onMouseCaptureLost() indirectly
-	}
+    if( hasMouseCapture() )
+    {
+        setMouseCapture( FALSE );  // Calls onMouseCaptureLost() indirectly
+    }
 }
 
 void LLToolSelect::onMouseCaptureLost()
 {
-	// Finish drag
+    // Finish drag
 
-	LLSelectMgr::getInstance()->enableSilhouette(TRUE);
+    LLSelectMgr::getInstance()->enableSilhouette(TRUE);
 
-	// Clean up drag-specific variables
-	mIgnoreGroup = FALSE;
+    // Clean up drag-specific variables
+    mIgnoreGroup = FALSE;
 }
 
 
diff --git a/indra/newview/lltranslate.cpp b/indra/newview/lltranslate.cpp
index eefe15ff2962af816937a98e0b50244dfa450955..09ab514ce75681ff837c945cfc0bb78427288804 100644
--- a/indra/newview/lltranslate.cpp
+++ b/indra/newview/lltranslate.cpp
@@ -5,21 +5,21 @@
  * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -357,22 +357,22 @@ class LLGoogleTranslationHandler : public LLTranslationAPIHandler
 //-------------------------------------------------------------------------
 // virtual
 std::string LLGoogleTranslationHandler::getTranslateURL(
-	const std::string &from_lang,
-	const std::string &to_lang,
-	const std::string &text) const
+    const std::string &from_lang,
+    const std::string &to_lang,
+    const std::string &text) const
 {
-	std::string url = std::string("https://www.googleapis.com/language/translate/v2?key=")
-		+ getAPIKey() + "&q=" + LLURI::escape(text) + "&target=" + to_lang;
-	if (!from_lang.empty())
-	{
-		url += "&source=" + from_lang;
-	}
+    std::string url = std::string("https://www.googleapis.com/language/translate/v2?key=")
+        + getAPIKey() + "&q=" + LLURI::escape(text) + "&target=" + to_lang;
+    if (!from_lang.empty())
+    {
+        url += "&source=" + from_lang;
+    }
     return url;
 }
 
 // virtual
 std::string LLGoogleTranslationHandler::getKeyVerificationURL(
-	const LLSD& key) const
+    const LLSD& key) const
 {
     std::string url = std::string("https://www.googleapis.com/language/translate/v2/languages?key=")
         + key.asString() +"&target=en";
@@ -389,14 +389,14 @@ bool LLGoogleTranslationHandler::checkVerificationResponse(
 
 // virtual
 bool LLGoogleTranslationHandler::parseResponse(
-	const LLSD& http_response,
-	int& status,
-	const std::string& body,
-	std::string& translation,
-	std::string& detected_lang,
-	std::string& err_msg) const
+    const LLSD& http_response,
+    int& status,
+    const std::string& body,
+    std::string& translation,
+    std::string& detected_lang,
+    std::string& err_msg) const
 {
-	const std::string& text = !body.empty() ? body : http_response["error_body"].asStringRef();
+    const std::string& text = !body.empty() ? body : http_response["error_body"].asStringRef();
     boost::system::error_code ec;
     boost::json::value root = boost::json::parse(text, ec);
     if (ec.failed())
@@ -405,33 +405,33 @@ bool LLGoogleTranslationHandler::parseResponse(
         return false;
     }
 
-	if (status != HTTP_OK)
-	{
-		// Request failed. Extract error message from the response.
-		parseErrorResponse(root, status, err_msg);
-		return false;
-	}
+    if (status != HTTP_OK)
+    {
+        // Request failed. Extract error message from the response.
+        parseErrorResponse(root, status, err_msg);
+        return false;
+    }
 
-	// Request succeeded, extract translation from the response.
-	return parseTranslation(root, translation, detected_lang);
+    // Request succeeded, extract translation from the response.
+    return parseTranslation(root, translation, detected_lang);
 }
 
 // virtual
 bool LLGoogleTranslationHandler::isConfigured() const
 {
-	return !getAPIKey().empty();
+    return !getAPIKey().empty();
 }
 
 // static
 void LLGoogleTranslationHandler::parseErrorResponse(
-	const boost::json::value& root,
-	int& status,
-	std::string& err_msg)
+    const boost::json::value& root,
+    int& status,
+    std::string& err_msg)
 {
     boost::system::error_code ec;
     auto message = root.find_pointer("/data/message", ec);
     auto code = root.find_pointer("/data/code", ec);
-    if (!message || !code) 
+    if (!message || !code)
     {
         return;
     }
@@ -449,9 +449,9 @@ void LLGoogleTranslationHandler::parseErrorResponse(
 
 // static
 bool LLGoogleTranslationHandler::parseTranslation(
-	const boost::json::value& root,
-	std::string& translation,
-	std::string& detected_lang)
+    const boost::json::value& root,
+    std::string& translation,
+    std::string& detected_lang)
 {
     boost::system::error_code ec;
     auto translated_text = root.find_pointer("/data/translations/0/translatedText", ec);
@@ -473,17 +473,17 @@ bool LLGoogleTranslationHandler::parseTranslation(
         detected_lang = lang_val ? lang_val.value() : "";
     }
 
-	return true;
+    return true;
 }
 
 // static
 std::string LLGoogleTranslationHandler::getAPIKey()
 {
     static LLCachedControl<std::string> google_key(gSavedSettings, "GoogleTranslateAPIKey");
-	return google_key;
+    return google_key;
 }
 
-/*virtual*/ 
+/*virtual*/
 void LLGoogleTranslationHandler::verifyKey(const LLSD &key, LLTranslate::KeyVerificationResult_fn fnc)
 {
     LLCoros::instance().launch("Google /Verify Key", boost::bind(&LLTranslationAPIHandler::verifyKeyCoro,
@@ -583,9 +583,9 @@ class LLAzureTranslationHandler : public LLTranslationAPIHandler
 //-------------------------------------------------------------------------
 // virtual
 std::string LLAzureTranslationHandler::getTranslateURL(
-	const std::string &from_lang,
-	const std::string &to_lang,
-	const std::string &text) const
+    const std::string &from_lang,
+    const std::string &to_lang,
+    const std::string &text) const
 {
     std::string url;
     LLSD key = getAPIKey();
@@ -606,7 +606,7 @@ std::string LLAzureTranslationHandler::getTranslateURL(
 
 // virtual
 std::string LLAzureTranslationHandler::getKeyVerificationURL(
-	const LLSD& key) const
+    const LLSD& key) const
 {
     std::string url;
     if (key.isMap())
@@ -667,18 +667,18 @@ bool LLAzureTranslationHandler::checkVerificationResponse(
 // virtual
 bool LLAzureTranslationHandler::parseResponse(
     const LLSD& http_response,
-	int& status,
-	const std::string& body,
-	std::string& translation,
-	std::string& detected_lang,
-	std::string& err_msg) const
+    int& status,
+    const std::string& body,
+    std::string& translation,
+    std::string& detected_lang,
+    std::string& err_msg) const
 {
-	if (status != HTTP_OK)
-	{
+    if (status != HTTP_OK)
+    {
         if (http_response.has("error_body"))
             err_msg = parseErrorResponse(http_response["error_body"].asString());
-		return false;
-	}
+        return false;
+    }
 
     //Example:
     // "[{\"detectedLanguage\":{\"language\":\"en\",\"score\":1.0},\"translations\":[{\"text\":\"Hello, what is your name?\",\"to\":\"en\"}]}]"
@@ -713,7 +713,7 @@ bool LLAzureTranslationHandler::parseResponse(
 // virtual
 bool LLAzureTranslationHandler::isConfigured() const
 {
-	return getAPIKey().isMap();
+    return getAPIKey().isMap();
 }
 
 //static
@@ -731,7 +731,7 @@ std::string LLAzureTranslationHandler::parseErrorResponse(
     }
 
     auto err_msg = root.find_pointer("/error/message", ec);
-    if (!err_msg) 
+    if (!err_msg)
     {
         return {};
     }
@@ -748,19 +748,19 @@ std::string LLAzureTranslationHandler::parseErrorResponse(
 LLSD LLAzureTranslationHandler::getAPIKey()
 {
     static LLCachedControl<LLSD> azure_key(gSavedSettings, "AzureTranslateAPIKey");
-	return azure_key;
+    return azure_key;
 }
 
 // static
 std::string LLAzureTranslationHandler::getAPILanguageCode(const std::string& lang)
 {
-	return lang == "zh" ? "zh-CHT" : lang; // treat Chinese as Traditional Chinese
+    return lang == "zh" ? "zh-CHT" : lang; // treat Chinese as Traditional Chinese
 }
 
 /*virtual*/
 void LLAzureTranslationHandler::verifyKey(const LLSD &key, LLTranslate::KeyVerificationResult_fn fnc)
 {
-    LLCoros::instance().launch("Azure /Verify Key", boost::bind(&LLTranslationAPIHandler::verifyKeyCoro, 
+    LLCoros::instance().launch("Azure /Verify Key", boost::bind(&LLTranslationAPIHandler::verifyKeyCoro,
         this, LLTranslate::SERVICE_AZURE, key, fnc));
 }
 /*virtual*/
@@ -1004,7 +1004,7 @@ std::string LLDeepLTranslationHandler::parseErrorResponse(
     boost::system::error_code ec;
     boost::json::value root = boost::json::parse(body, ec);
     if (ec.failed())
-    {   
+    {
         return {};
     }
 
@@ -1101,10 +1101,10 @@ LLSD LLDeepLTranslationHandler::verifyAndSuspend(LLCoreHttpUtil::HttpCoroutineAd
 
 //=========================================================================
 LLTranslate::LLTranslate():
-	mCharsSeen(0),
-	mCharsSent(0),
-	mFailureCount(0),
-	mSuccessCount(0)
+    mCharsSeen(0),
+    mCharsSent(0),
+    mFailureCount(0),
+    mSuccessCount(0)
 {
 }
 
@@ -1205,68 +1205,68 @@ void LLTranslate::verifyKey(EService service, const LLSD &key, KeyVerificationRe
 //static
 std::string LLTranslate::getTranslateLanguage()
 {
-	std::string language = gSavedSettings.getString("TranslateLanguage");
-	if (language.empty() || language == "default")
-	{
-		language = LLUI::getLanguage();
-	}
-	language = language.substr(0,2);
-	return language;
+    std::string language = gSavedSettings.getString("TranslateLanguage");
+    if (language.empty() || language == "default")
+    {
+        language = LLUI::getLanguage();
+    }
+    language = language.substr(0,2);
+    return language;
 }
 
 // static
 bool LLTranslate::isTranslationConfigured()
 {
-	return getPreferredHandler().isConfigured();
+    return getPreferredHandler().isConfigured();
 }
 
 void LLTranslate::logCharsSeen(size_t count)
 {
-	mCharsSeen += count;
+    mCharsSeen += count;
 }
 
 void LLTranslate::logCharsSent(size_t count)
 {
-	mCharsSent += count;
+    mCharsSent += count;
 }
 
 void LLTranslate::logSuccess(S32 count)
 {
-	mSuccessCount += count;
+    mSuccessCount += count;
 }
 
 void LLTranslate::logFailure(S32 count)
 {
-	mFailureCount += count;
+    mFailureCount += count;
 }
 
 LLSD LLTranslate::asLLSD() const
 {
-	LLSD res;
-	bool on = gSavedSettings.getBOOL("TranslateChat");
-	res["on"] = on;
-	res["chars_seen"] = (S32) mCharsSeen;
-	if (on)
-	{
-		res["chars_sent"] = (S32) mCharsSent;
-		res["success_count"] = mSuccessCount;
-		res["failure_count"] = mFailureCount;
-		res["language"] = getTranslateLanguage();  
-		res["service"] = gSavedSettings.getString("TranslationService");
-	}
-	return res;
+    LLSD res;
+    bool on = gSavedSettings.getBOOL("TranslateChat");
+    res["on"] = on;
+    res["chars_seen"] = (S32) mCharsSeen;
+    if (on)
+    {
+        res["chars_sent"] = (S32) mCharsSent;
+        res["success_count"] = mSuccessCount;
+        res["failure_count"] = mFailureCount;
+        res["language"] = getTranslateLanguage();
+        res["service"] = gSavedSettings.getString("TranslationService");
+    }
+    return res;
 }
 
 // static
 LLTranslationAPIHandler& LLTranslate::getPreferredHandler()
 {
-	EService service = SERVICE_AZURE;
+    EService service = SERVICE_AZURE;
 
-	std::string service_str = gSavedSettings.getString("TranslationService");
-	if (service_str == "google")
-	{
-		service = SERVICE_GOOGLE;
-	}
+    std::string service_str = gSavedSettings.getString("TranslationService");
+    if (service_str == "google")
+    {
+        service = SERVICE_GOOGLE;
+    }
     if (service_str == "azure")
     {
         service = SERVICE_AZURE;
@@ -1276,14 +1276,14 @@ LLTranslationAPIHandler& LLTranslate::getPreferredHandler()
         service = SERVICE_DEEPL;
     }
 
-	return getHandler(service);
+    return getHandler(service);
 }
 
 // static
 LLTranslationAPIHandler& LLTranslate::getHandler(EService service)
 {
-	static LLGoogleTranslationHandler google;
-	static LLAzureTranslationHandler azure;
+    static LLGoogleTranslationHandler google;
+    static LLAzureTranslationHandler azure;
     static LLDeepLTranslationHandler deepl;
 
     switch (service)
diff --git a/indra/newview/llviewerassetupload.cpp b/indra/newview/llviewerassetupload.cpp
index a4db974fc60408ffb8571da8c43800bbc77c17cf..d83503bb91b4302bdc8e7bd95bc40aa99dfa1c38 100644
--- a/indra/newview/llviewerassetupload.cpp
+++ b/indra/newview/llviewerassetupload.cpp
@@ -85,9 +85,9 @@ LLResourceUploadInfo::LLResourceUploadInfo(LLTransactionID transactId,
 { }
 
 
-LLResourceUploadInfo::LLResourceUploadInfo(std::string name, 
-        std::string description, S32 compressionInfo, 
-        LLFolderType::EType destinationType, LLInventoryType::EType inventoryType, 
+LLResourceUploadInfo::LLResourceUploadInfo(std::string name,
+        std::string description, S32 compressionInfo,
+        LLFolderType::EType destinationType, LLInventoryType::EType inventoryType,
         U32 nextOWnerPerms, U32 groupPerms, U32 everyonePerms, S32 expectedCost, bool showInventory) :
     mName(name),
     mDescription(description),
@@ -104,7 +104,7 @@ LLResourceUploadInfo::LLResourceUploadInfo(std::string name,
     mFolderId(LLUUID::null),
     mItemId(LLUUID::null),
     mAssetId(LLAssetID::null)
-{ 
+{
     mTransactionId.generate();
 }
 
@@ -315,39 +315,39 @@ std::string LLResourceUploadInfo::getDisplayName() const
 
 bool LLResourceUploadInfo::findAssetTypeOfExtension(const std::string& exten, LLAssetType::EType& asset_type)
 {
-	U32 codec;
-	return findAssetTypeAndCodecOfExtension(exten, asset_type, codec);
+    U32 codec;
+    return findAssetTypeAndCodecOfExtension(exten, asset_type, codec);
 }
 
 // static
 bool LLResourceUploadInfo::findAssetTypeAndCodecOfExtension(const std::string& exten, LLAssetType::EType& asset_type, U32& codec)
 {
-	bool succ = false;
-	std::string exten_lc(exten);
-	LLStringUtil::toLower(exten_lc);
-	codec = LLImageBase::getCodecFromExtension(exten_lc);
-	if (codec != IMG_CODEC_INVALID)
-	{
-		asset_type = LLAssetType::AT_TEXTURE; 
-		succ = true;
-	}
-	else if (exten_lc == "wav")
-	{
-		asset_type = LLAssetType::AT_SOUND; 
-		succ = true;
-	}
-	else if (exten_lc == "anim")
-	{
-		asset_type = LLAssetType::AT_ANIMATION; 
-		succ = true;
-	}
-	else if (exten_lc == "bvh")
-	{
-		asset_type = LLAssetType::AT_ANIMATION;
-		succ = true;
-	}
-
-	return succ;
+    bool succ = false;
+    std::string exten_lc(exten);
+    LLStringUtil::toLower(exten_lc);
+    codec = LLImageBase::getCodecFromExtension(exten_lc);
+    if (codec != IMG_CODEC_INVALID)
+    {
+        asset_type = LLAssetType::AT_TEXTURE;
+        succ = true;
+    }
+    else if (exten_lc == "wav")
+    {
+        asset_type = LLAssetType::AT_SOUND;
+        succ = true;
+    }
+    else if (exten_lc == "anim")
+    {
+        asset_type = LLAssetType::AT_ANIMATION;
+        succ = true;
+    }
+    else if (exten_lc == "bvh")
+    {
+        asset_type = LLAssetType::AT_ANIMATION;
+        succ = true;
+    }
+
+    return succ;
 }
 
 //=========================================================================
@@ -389,8 +389,8 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile()
     std::string exten = gDirUtilp->getExtension(getFileName());
 
     LLAssetType::EType assetType = LLAssetType::AT_NONE;
-	U32 codec = IMG_CODEC_INVALID;
-	bool found_type = findAssetTypeAndCodecOfExtension(exten, assetType, codec);
+    U32 codec = IMG_CODEC_INVALID;
+    bool found_type = findAssetTypeAndCodecOfExtension(exten, assetType, codec);
 
     std::string errorMessage;
     std::string errorLabel;
@@ -496,53 +496,53 @@ LLSD LLNewFileResourceUploadInfo::exportTempFile()
     }
     else if (exten == "anim")
     {
-		// Default unless everything succeeds
-		errorLabel = "ProblemWithFile";
-		error = true;
+        // Default unless everything succeeds
+        errorLabel = "ProblemWithFile";
+        error = true;
 
         // read from getFileName()
-		LLAPRFile infile;
-		infile.open(getFileName(),LL_APR_RB);
-		if (!infile.getFileHandle())
-		{
-			LL_WARNS() << "Couldn't open file for reading: " << getFileName() << LL_ENDL;
-			errorMessage = llformat("Failed to open animation file %s\n", getFileName().c_str());
-		}
-		else
-		{
-			S32 size = LLAPRFile::size(getFileName());
-			U8* buffer = new U8[size];
-			S32 size_read = infile.read(buffer,size);
-			if (size_read != size)
-			{
-				errorMessage = llformat("Failed to read animation file %s: wanted %d bytes, got %d\n", getFileName().c_str(), size, size_read);
-			}
-			else
-			{
-				LLDataPackerBinaryBuffer dp(buffer, size);
-				LLKeyframeMotion *motionp = new LLKeyframeMotion(getAssetId());
-				motionp->setCharacter(gAgentAvatarp);
-				if (motionp->deserialize(dp, getAssetId(), false))
-				{
-					// write to temp file
-					bool succ = motionp->dumpToFile(filename);
-					if (succ)
-					{
-						assetType = LLAssetType::AT_ANIMATION;
-						errorLabel = "";
-						error = false;
-					}
-					else
-					{
-						errorMessage = "Failed saving temporary animation file";
-					}
-				}
-				else
-				{
-					errorMessage = "Failed reading animation file";
-				}
-			}
-		}
+        LLAPRFile infile;
+        infile.open(getFileName(),LL_APR_RB);
+        if (!infile.getFileHandle())
+        {
+            LL_WARNS() << "Couldn't open file for reading: " << getFileName() << LL_ENDL;
+            errorMessage = llformat("Failed to open animation file %s\n", getFileName().c_str());
+        }
+        else
+        {
+            S32 size = LLAPRFile::size(getFileName());
+            U8* buffer = new U8[size];
+            S32 size_read = infile.read(buffer,size);
+            if (size_read != size)
+            {
+                errorMessage = llformat("Failed to read animation file %s: wanted %d bytes, got %d\n", getFileName().c_str(), size, size_read);
+            }
+            else
+            {
+                LLDataPackerBinaryBuffer dp(buffer, size);
+                LLKeyframeMotion *motionp = new LLKeyframeMotion(getAssetId());
+                motionp->setCharacter(gAgentAvatarp);
+                if (motionp->deserialize(dp, getAssetId(), false))
+                {
+                    // write to temp file
+                    bool succ = motionp->dumpToFile(filename);
+                    if (succ)
+                    {
+                        assetType = LLAssetType::AT_ANIMATION;
+                        errorLabel = "";
+                        error = false;
+                    }
+                    else
+                    {
+                        errorMessage = "Failed saving temporary animation file";
+                    }
+                }
+                else
+                {
+                    errorMessage = "Failed reading animation file";
+                }
+            }
+        }
     }
     else
     {
@@ -637,10 +637,10 @@ LLSD LLNewBufferedResourceUploadInfo::exportTempFile()
 {
     std::string filename = gDirUtilp->getTempFilename();
 
-    // copy buffer to the cache for upload    
+    // copy buffer to the cache for upload
     LLFileSystem file(getAssetId(), getAssetType(), LLFileSystem::APPEND);
     file.write((U8*) mBuffer.c_str(), mBuffer.size());
-        
+
     return LLSD();
 }
 
@@ -869,8 +869,8 @@ LLSD LLScriptAssetUpload::generatePostBody()
 LLUUID LLViewerAssetUpload::EnqueueInventoryUpload(const std::string &url, const LLResourceUploadInfo::ptr_t &uploadInfo)
 {
     std::string procName("LLViewerAssetUpload::AssetInventoryUploadCoproc(");
-    
-    LLUUID queueId = LLCoprocedureManager::instance().enqueueCoprocedure("Upload", 
+
+    LLUUID queueId = LLCoprocedureManager::instance().enqueueCoprocedure("Upload",
         procName + LLAssetType::lookup(uploadInfo->getAssetType()) + ")",
         boost::bind(&LLViewerAssetUpload::AssetInventoryUploadCoproc, _1, _2, url, uploadInfo));
 
@@ -879,7 +879,7 @@ LLUUID LLViewerAssetUpload::EnqueueInventoryUpload(const std::string &url, const
 
 //=========================================================================
 /*static*/
-void LLViewerAssetUpload::AssetInventoryUploadCoproc(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter, 
+void LLViewerAssetUpload::AssetInventoryUploadCoproc(LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t &httpAdapter,
     const LLUUID &id, std::string url, LLResourceUploadInfo::ptr_t uploadInfo)
 {
     LLCore::HttpRequest::ptr_t httpRequest(std::make_shared<LLCore::HttpRequest>());
@@ -1051,7 +1051,7 @@ void LLViewerAssetUpload::HandleUploadError(LLCore::HttpStatus status, LLSD &res
         // ex: do not trigger snapshot floater when failing material texture
 
 // [SL:KB] - Patch: Build-ScriptRecover | Checked: Catznip-4.0
-		uploadInfo->callUploadErrorCb();
+        uploadInfo->callUploadErrorCb();
 // [/SL:KB]
         return;
     }
diff --git a/indra/newview/llviewercamera.cpp b/indra/newview/llviewercamera.cpp
index 25beba7bd0ca54826e36270a8ef7933afcfbaa3a..cbdbcce59958ef96c39df2a7babaed3bb2c4b625 100644
--- a/indra/newview/llviewercamera.cpp
+++ b/indra/newview/llviewercamera.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewercamera.cpp
  * @brief LLViewerCamera class implementation
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -52,7 +52,7 @@
 #include "llgl.h"
 #include "llglheaders.h"
 #include "llquaternion.h"
-#include "llwindow.h"			// getPixelAspectRatio()
+#include "llwindow.h"           // getPixelAspectRatio()
 #include "lltracerecording.h"
 #include "llenvironment.h"
 
@@ -66,18 +66,18 @@ LLViewerCamera::eCameraID LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_
 
 LLViewerCamera::LLViewerCamera() : LLCamera()
 {
-	calcProjection(getFar());
-	mCameraFOVDefault = DEFAULT_FIELD_OF_VIEW;
-	mPrevCameraFOVDefault = DEFAULT_FIELD_OF_VIEW;
-	mSavedFOVDefault = DEFAULT_FIELD_OF_VIEW;
-	mCosHalfCameraFOV = cosf(mCameraFOVDefault * 0.5f);
-	mPixelMeterRatio = 0.f;
-	mScreenPixelArea = 0;
-	mZoomFactor = 1.f;
-	mZoomSubregion = 1;
-	mAverageSpeed = 0.f;
-	mAverageAngularSpeed = 0.f;
-	gSavedSettings.getControl("CameraAngle")->getCommitSignal()->connect(boost::bind(&LLViewerCamera::updateCameraAngle, this, _2));
+    calcProjection(getFar());
+    mCameraFOVDefault = DEFAULT_FIELD_OF_VIEW;
+    mPrevCameraFOVDefault = DEFAULT_FIELD_OF_VIEW;
+    mSavedFOVDefault = DEFAULT_FIELD_OF_VIEW;
+    mCosHalfCameraFOV = cosf(mCameraFOVDefault * 0.5f);
+    mPixelMeterRatio = 0.f;
+    mScreenPixelArea = 0;
+    mZoomFactor = 1.f;
+    mZoomSubregion = 1;
+    mAverageSpeed = 0.f;
+    mAverageAngularSpeed = 0.f;
+    gSavedSettings.getControl("CameraAngle")->getCommitSignal()->connect(boost::bind(&LLViewerCamera::updateCameraAngle, this, _2));
 }
 
 void LLViewerCamera::updateCameraLocation(const LLVector3 &center, const LLVector3 &up_direction, const LLVector3 &point_of_interest)
@@ -116,50 +116,50 @@ void LLViewerCamera::updateCameraLocation(const LLVector3 &center, const LLVecto
         }
     }
 
-	setOriginAndLookAt(origin, up_direction, point_of_interest);
+    setOriginAndLookAt(origin, up_direction, point_of_interest);
+
+    mVelocityDir = origin - last_position ;
+    F32 dpos = mVelocityDir.normVec() ;
+    LLQuaternion rotation;
+    rotation.shortestArc(last_axis, getAtAxis());
 
-	mVelocityDir = origin - last_position ; 
-	F32 dpos = mVelocityDir.normVec() ;
-	LLQuaternion rotation;
-	rotation.shortestArc(last_axis, getAtAxis());
+    F32 x, y, z;
+    F32 drot;
+    rotation.getAngleAxis(&drot, &x, &y, &z);
 
-	F32 x, y, z;
-	F32 drot;
-	rotation.getAngleAxis(&drot, &x, &y, &z);
+    add(sVelocityStat, dpos);
+    add(sAngularVelocityStat, drot);
 
-	add(sVelocityStat, dpos);
-	add(sAngularVelocityStat, drot);
-	
-	mAverageSpeed = LLTrace::get_frame_recording().getPeriodMeanPerSec(sVelocityStat, 50);
-	mAverageAngularSpeed = LLTrace::get_frame_recording().getPeriodMeanPerSec(sAngularVelocityStat);
-	mCosHalfCameraFOV = cosf(0.5f * getView() * llmax(1.0f, getAspect()));
+    mAverageSpeed = LLTrace::get_frame_recording().getPeriodMeanPerSec(sVelocityStat, 50);
+    mAverageAngularSpeed = LLTrace::get_frame_recording().getPeriodMeanPerSec(sAngularVelocityStat);
+    mCosHalfCameraFOV = cosf(0.5f * getView() * llmax(1.0f, getAspect()));
 
-	// update pixel meter ratio using default fov, not modified one
-	mPixelMeterRatio = getViewHeightInPixels()/ (2.f*tanf(mCameraFOVDefault*0.5));
-	// update screen pixel area
-	mScreenPixelArea =(S32)((F32)getViewHeightInPixels() * ((F32)getViewHeightInPixels() * getAspect()));
+    // update pixel meter ratio using default fov, not modified one
+    mPixelMeterRatio = getViewHeightInPixels()/ (2.f*tanf(mCameraFOVDefault*0.5));
+    // update screen pixel area
+    mScreenPixelArea =(S32)((F32)getViewHeightInPixels() * ((F32)getViewHeightInPixels() * getAspect()));
 }
 
 const LLMatrix4a &LLViewerCamera::getProjection() const
 {
-	calcProjection(getFar());
-	return mProjectionMatrix;
+    calcProjection(getFar());
+    return mProjectionMatrix;
 
 }
 
 const LLMatrix4a &LLViewerCamera::getModelview() const
 {
-	LLMatrix4 modelview;
-	getMatrixToLocal(modelview);
-	LLMatrix4a modelviewa;
-	modelviewa.loadu((F32*)modelview.mMatrix);
-	mModelviewMatrix.setMul(OGL_TO_CFR_ROTATION_4A, modelviewa);
-	return mModelviewMatrix;
+    LLMatrix4 modelview;
+    getMatrixToLocal(modelview);
+    LLMatrix4a modelviewa;
+    modelviewa.loadu((F32*)modelview.mMatrix);
+    mModelviewMatrix.setMul(OGL_TO_CFR_ROTATION_4A, modelviewa);
+    return mModelviewMatrix;
 }
 
 void LLViewerCamera::calcProjection(const F32 far_distance) const
 {
-	mProjectionMatrix = ALGLMath::genPersp( getView()*RAD_TO_DEG, getAspect(), getNear(), far_distance );
+    mProjectionMatrix = ALGLMath::genPersp( getView()*RAD_TO_DEG, getAspect(), getNear(), far_distance );
 }
 
 // Sets up opengl state for 3D drawing.  If for selection, also
@@ -170,192 +170,192 @@ void LLViewerCamera::calcProjection(const F32 far_distance) const
 //static
 void LLViewerCamera::updateFrustumPlanes(LLCamera& camera, BOOL ortho, BOOL zflip, BOOL no_hacks)
 {
-	LLVector3 frust[8];
-
-	const LLMatrix4a& modelview = get_current_modelview();
-	const LLMatrix4a& projection = get_current_projection();
-
-	LLRect view_port(gGLViewport[0], gGLViewport[1] + gGLViewport[3], gGLViewport[0] + gGLViewport[2], gGLViewport[1]);
-
-	if (no_hacks)
-	{
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 0.f), modelview, projection, view_port, frust[0]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 0.f), modelview, projection, view_port, frust[1]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 0.f), modelview, projection, view_port, frust[2]);
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 0.f), modelview, projection, view_port, frust[3]);
-
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 1.f), modelview, projection, view_port, frust[4]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 1.f), modelview, projection, view_port, frust[5]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 1.f), modelview, projection, view_port, frust[6]);
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 1.f), modelview, projection, view_port, frust[7]);
-	}
-	else if (zflip)
-	{
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 0.f), modelview, projection, view_port, frust[0]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 0.f), modelview, projection, view_port, frust[1]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 0.f), modelview, projection, view_port, frust[2]);
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 0.f), modelview, projection, view_port, frust[3]);
-
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 1.f), modelview, projection, view_port, frust[4]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 1.f), modelview, projection, view_port, frust[5]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 1.f), modelview, projection, view_port, frust[6]);
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 1.f), modelview, projection, view_port, frust[7]);
-
-		for (U32 i = 0; i < 4; i++)
-		{
-			frust[i+4] = frust[i+4]-frust[i];
-			frust[i+4].normVec();
-			frust[i+4] = frust[i] + frust[i+4]*camera.getFar();
-		}
-	}
-	else
-	{
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 0.f), modelview, projection, view_port, frust[0]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 0.f), modelview, projection, view_port, frust[1]);
-		ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 0.f), modelview, projection, view_port, frust[2]);
-		ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 0.f), modelview, projection, view_port, frust[3]);
-		
-		if (ortho)
-		{
-			LLVector3 far_shift = camera.getAtAxis()*camera.getFar()*2.f; 
-			for (U32 i = 0; i < 4; i++)
-			{
-				frust[i+4] = frust[i] + far_shift;
-			}
-		}
-		else
-		{
-			for (U32 i = 0; i < 4; i++)
-			{
-				LLVector3 vec = frust[i] - camera.getOrigin();
-				vec.normVec();
-				frust[i+4] = camera.getOrigin() + vec*camera.getFar();
-			}
-		}
-	}
-
-	camera.calcAgentFrustumPlanes(frust);
+    LLVector3 frust[8];
+
+    const LLMatrix4a& modelview = get_current_modelview();
+    const LLMatrix4a& projection = get_current_projection();
+
+    LLRect view_port(gGLViewport[0], gGLViewport[1] + gGLViewport[3], gGLViewport[0] + gGLViewport[2], gGLViewport[1]);
+
+    if (no_hacks)
+    {
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 0.f), modelview, projection, view_port, frust[0]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 0.f), modelview, projection, view_port, frust[1]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 0.f), modelview, projection, view_port, frust[2]);
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 0.f), modelview, projection, view_port, frust[3]);
+
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 1.f), modelview, projection, view_port, frust[4]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 1.f), modelview, projection, view_port, frust[5]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 1.f), modelview, projection, view_port, frust[6]);
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 1.f), modelview, projection, view_port, frust[7]);
+    }
+    else if (zflip)
+    {
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 0.f), modelview, projection, view_port, frust[0]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 0.f), modelview, projection, view_port, frust[1]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 0.f), modelview, projection, view_port, frust[2]);
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 0.f), modelview, projection, view_port, frust[3]);
+
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 1.f), modelview, projection, view_port, frust[4]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 1.f), modelview, projection, view_port, frust[5]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 1.f), modelview, projection, view_port, frust[6]);
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 1.f), modelview, projection, view_port, frust[7]);
+
+        for (U32 i = 0; i < 4; i++)
+        {
+            frust[i+4] = frust[i+4]-frust[i];
+            frust[i+4].normVec();
+            frust[i+4] = frust[i] + frust[i+4]*camera.getFar();
+        }
+    }
+    else
+    {
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mBottom, 0.f), modelview, projection, view_port, frust[0]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mBottom, 0.f), modelview, projection, view_port, frust[1]);
+        ALGLMath::unprojectf(LLVector3(view_port.mRight, view_port.mTop, 0.f), modelview, projection, view_port, frust[2]);
+        ALGLMath::unprojectf(LLVector3(view_port.mLeft, view_port.mTop, 0.f), modelview, projection, view_port, frust[3]);
+
+        if (ortho)
+        {
+            LLVector3 far_shift = camera.getAtAxis()*camera.getFar()*2.f;
+            for (U32 i = 0; i < 4; i++)
+            {
+                frust[i+4] = frust[i] + far_shift;
+            }
+        }
+        else
+        {
+            for (U32 i = 0; i < 4; i++)
+            {
+                LLVector3 vec = frust[i] - camera.getOrigin();
+                vec.normVec();
+                frust[i+4] = camera.getOrigin() + vec*camera.getFar();
+            }
+        }
+    }
+
+    camera.calcAgentFrustumPlanes(frust);
 }
 
 void LLViewerCamera::setPerspective(BOOL for_selection,
-									S32 x, S32 y_from_bot, S32 width, S32 height,
-									BOOL limit_select_distance,
-									F32 z_near, F32 z_far)
+                                    S32 x, S32 y_from_bot, S32 width, S32 height,
+                                    BOOL limit_select_distance,
+                                    F32 z_near, F32 z_far)
 {
-	F32 fov_y, aspect;
-	fov_y = RAD_TO_DEG * getView();
-	BOOL z_default_far = FALSE;
-	if (z_far <= 0)
-	{
-		z_default_far = TRUE;
-		z_far = getFar();
-	}
-	if (z_near <= 0)
-	{
-		z_near = getNear();
-	}
-	aspect = getAspect();
-
-	// Load camera view matrix
-	gGL.matrixMode(LLRender::MM_PROJECTION);
-	gGL.loadIdentity();
-
-	LLMatrix4a proj_mat;
-	proj_mat.setIdentity();
-
-	if (for_selection)
-	{
-		// make a tiny little viewport
-		// anything drawn into this viewport will be "selected"
-
-		const LLRect& rect = gViewerWindow->getWorldViewRectRaw();
-		
-		const F32 scale_x = rect.getWidth() / F32(width);
-		const F32 scale_y = rect.getHeight() / F32(height);
-		const F32 trans_x = scale_x + (2.f * (rect.mLeft - x)) / F32(width) - 1.f;
-		const F32 trans_y = scale_y + (2.f * (rect.mBottom - y_from_bot)) / F32(height) - 1.f;
-
-		//Generate a pick matrix
-		proj_mat.applyScale_affine(scale_x, scale_y, 1.f);
-		proj_mat.setTranslate_affine(LLVector3(trans_x, trans_y, 0.f));
-
-		if (limit_select_distance)
-		{
-			// ...select distance from control
-			z_far = ALControlCache::MaxSelectDistance;
-		}
-		else
-		{
-			z_far = gAgentCamera.mDrawDistance;
-		}
+    F32 fov_y, aspect;
+    fov_y = RAD_TO_DEG * getView();
+    BOOL z_default_far = FALSE;
+    if (z_far <= 0)
+    {
+        z_default_far = TRUE;
+        z_far = getFar();
+    }
+    if (z_near <= 0)
+    {
+        z_near = getNear();
+    }
+    aspect = getAspect();
+
+    // Load camera view matrix
+    gGL.matrixMode(LLRender::MM_PROJECTION);
+    gGL.loadIdentity();
+
+    LLMatrix4a proj_mat;
+    proj_mat.setIdentity();
+
+    if (for_selection)
+    {
+        // make a tiny little viewport
+        // anything drawn into this viewport will be "selected"
+
+        const LLRect& rect = gViewerWindow->getWorldViewRectRaw();
+
+        const F32 scale_x = rect.getWidth() / F32(width);
+        const F32 scale_y = rect.getHeight() / F32(height);
+        const F32 trans_x = scale_x + (2.f * (rect.mLeft - x)) / F32(width) - 1.f;
+        const F32 trans_y = scale_y + (2.f * (rect.mBottom - y_from_bot)) / F32(height) - 1.f;
+
+        //Generate a pick matrix
+        proj_mat.applyScale_affine(scale_x, scale_y, 1.f);
+        proj_mat.setTranslate_affine(LLVector3(trans_x, trans_y, 0.f));
+
+        if (limit_select_distance)
+        {
+            // ...select distance from control
+            z_far = ALControlCache::MaxSelectDistance;
+        }
+        else
+        {
+            z_far = gAgentCamera.mDrawDistance;
+        }
 
 // [RLVa:KB] - Checked: RLVa-2.0.0
-		if (RlvActions::hasBehaviour(RLV_BHVR_FARTOUCH))
-			z_far = RlvActions::getModifierValue<float>(RLV_MODIFIER_FARTOUCHDIST);
+        if (RlvActions::hasBehaviour(RLV_BHVR_FARTOUCH))
+            z_far = RlvActions::getModifierValue<float>(RLV_MODIFIER_FARTOUCHDIST);
 // [/RLVa:KB]
-	}
-	else
-	{
-		// Only override the far clip if it's not passed in explicitly.
-		if (z_default_far)
-		{
-			z_far = MAX_FAR_CLIP;
-		}
-		glViewport(x, y_from_bot, width, height);
-		gGLViewport[0] = x;
-		gGLViewport[1] = y_from_bot;
-		gGLViewport[2] = width;
-		gGLViewport[3] = height;
-	}
-	
-	if (mZoomFactor > 1.f)
-	{
-		float offset = mZoomFactor - 1.f;
-		int pos_y = mZoomSubregion / llceil(mZoomFactor);
-		int pos_x = mZoomSubregion - (pos_y*llceil(mZoomFactor));
-
-		proj_mat.applyTranslation_affine(offset - (F32)pos_x * 2.f, offset - (F32)pos_y * 2.f, 0.f);
-		proj_mat.applyScale_affine(mZoomFactor,mZoomFactor,1.f);
-	}
-
-	calcProjection(z_far); // Update the projection matrix cache
-
-	proj_mat.mul(ALGLMath::genPersp(fov_y,aspect,z_near,z_far));
-	
-	gGL.loadMatrix(proj_mat);
-	
-	set_current_projection(proj_mat);
-
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-
-	LLMatrix4a ogl_matrix;
-	getOpenGLTransform(ogl_matrix.getF32ptr());
-
-	LLMatrix4a modelview;
-	modelview.setMul(OGL_TO_CFR_ROTATION_4A, ogl_matrix);
-	
-	gGL.loadMatrix(modelview);
-	
-	if (for_selection && (width > 1 || height > 1))
-	{
-		// NB: as of this writing, i believe the code below is broken (doesn't take into account the world view, assumes entire window)
-		// however, it is also unused (the GL matricies are used for selection, (see LLCamera::sphereInFrustum())) and so i'm not
-		// comfortable hacking on it.
-		calculateFrustumPlanesFromWindow((F32)(x - width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f,
-								(F32)(y_from_bot - height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f,
-								(F32)(x + width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f,
-								(F32)(y_from_bot + height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f);
-
-	}
-
-	// if not picking and not doing a snapshot, cache various GL matrices
-	if (!for_selection && mZoomFactor == 1.f)
-	{
-		// Save GL matrices for access elsewhere in code, especially project_world_to_screen
-		set_current_modelview(modelview);
-	}
-
-	updateFrustumPlanes(*this);
+    }
+    else
+    {
+        // Only override the far clip if it's not passed in explicitly.
+        if (z_default_far)
+        {
+            z_far = MAX_FAR_CLIP;
+        }
+        glViewport(x, y_from_bot, width, height);
+        gGLViewport[0] = x;
+        gGLViewport[1] = y_from_bot;
+        gGLViewport[2] = width;
+        gGLViewport[3] = height;
+    }
+
+    if (mZoomFactor > 1.f)
+    {
+        float offset = mZoomFactor - 1.f;
+        int pos_y = mZoomSubregion / llceil(mZoomFactor);
+        int pos_x = mZoomSubregion - (pos_y*llceil(mZoomFactor));
+
+        proj_mat.applyTranslation_affine(offset - (F32)pos_x * 2.f, offset - (F32)pos_y * 2.f, 0.f);
+        proj_mat.applyScale_affine(mZoomFactor,mZoomFactor,1.f);
+    }
+
+    calcProjection(z_far); // Update the projection matrix cache
+
+    proj_mat.mul(ALGLMath::genPersp(fov_y,aspect,z_near,z_far));
+
+    gGL.loadMatrix(proj_mat);
+
+    set_current_projection(proj_mat);
+
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+
+    LLMatrix4a ogl_matrix;
+    getOpenGLTransform(ogl_matrix.getF32ptr());
+
+    LLMatrix4a modelview;
+    modelview.setMul(OGL_TO_CFR_ROTATION_4A, ogl_matrix);
+
+    gGL.loadMatrix(modelview);
+
+    if (for_selection && (width > 1 || height > 1))
+    {
+        // NB: as of this writing, i believe the code below is broken (doesn't take into account the world view, assumes entire window)
+        // however, it is also unused (the GL matricies are used for selection, (see LLCamera::sphereInFrustum())) and so i'm not
+        // comfortable hacking on it.
+        calculateFrustumPlanesFromWindow((F32)(x - width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f,
+                                (F32)(y_from_bot - height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f,
+                                (F32)(x + width / 2) / (F32)gViewerWindow->getWindowWidthScaled() - 0.5f,
+                                (F32)(y_from_bot + height / 2) / (F32)gViewerWindow->getWindowHeightScaled() - 0.5f);
+
+    }
+
+    // if not picking and not doing a snapshot, cache various GL matrices
+    if (!for_selection && mZoomFactor == 1.f)
+    {
+        // Save GL matrices for access elsewhere in code, especially project_world_to_screen
+        set_current_modelview(modelview);
+    }
+
+    updateFrustumPlanes(*this);
 }
 
 
@@ -363,10 +363,10 @@ void LLViewerCamera::setPerspective(BOOL for_selection,
 // screen coordinates to the agent's region.
 void LLViewerCamera::projectScreenToPosAgent(const S32 screen_x, const S32 screen_y, LLVector3* pos_agent) const
 {
-	ALGLMath::unprojectf(
-		LLVector3(screen_x, screen_y, 0.f), get_current_modelview(), get_current_projection(),
-		LLRect(gGLViewport[0], gGLViewport[1] + gGLViewport[3], gGLViewport[0] + gGLViewport[2], gGLViewport[1]),
-		*pos_agent);
+    ALGLMath::unprojectf(
+        LLVector3(screen_x, screen_y, 0.f), get_current_modelview(), get_current_projection(),
+        LLRect(gGLViewport[0], gGLViewport[1] + gGLViewport[3], gGLViewport[0] + gGLViewport[2], gGLViewport[1]),
+        *pos_agent);
 }
 
 // Uses the last GL matrices set in set_perspective to project a point from
@@ -374,296 +374,296 @@ void LLViewerCamera::projectScreenToPosAgent(const S32 screen_x, const S32 scree
 // the current window.
 BOOL LLViewerCamera::projectPosAgentToScreen(const LLVector3 &pos_agent, LLCoordGL &out_point, const BOOL clamp) const
 {
-	BOOL in_front = TRUE;
-	LLVector3 window_coordinates;
-
-	LLVector3 dir_to_point = pos_agent - getOrigin();
-	dir_to_point /= dir_to_point.magVec();
-
-	if (dir_to_point * getAtAxis() < 0.f)
-	{
-		if (clamp)
-		{
-			return FALSE;
-		}
-		else
-		{
-			in_front = FALSE;
-		}
-	}
-
-	const LLMatrix4a& modelview = get_current_modelview();
-	const LLMatrix4a& projection = get_current_projection();
-	const LLRect& world_view_rect = gViewerWindow->getWorldViewRectRaw();
-
-	if (ALGLMath::projectf(pos_agent, modelview, projection, world_view_rect, window_coordinates))
-	{
-		F32 &x = window_coordinates.mV[VX];
-		F32 &y = window_coordinates.mV[VY];
-
-		// convert screen coordinates to virtual UI coordinates
-		x /= gViewerWindow->getDisplayScale().mV[VX];
-		y /= gViewerWindow->getDisplayScale().mV[VY];
-
-		// should now have the x,y coords of grab_point in screen space
-		LLRect world_rect = gViewerWindow->getWorldViewRectScaled();
-
-		// convert to pixel coordinates
-		S32 int_x = lltrunc(x);
-		S32 int_y = lltrunc(y);
-
-		BOOL valid = TRUE;
-
-		if (clamp)
-		{
-			if (int_x < world_rect.mLeft)
-			{
-				out_point.mX = world_rect.mLeft;
-				valid = FALSE;
-			}
-			else if (int_x > world_rect.mRight)
-			{
-				out_point.mX = world_rect.mRight;
-				valid = FALSE;
-			}
-			else
-			{
-				out_point.mX = int_x;
-			}
-
-			if (int_y < world_rect.mBottom)
-			{
-				out_point.mY = world_rect.mBottom;
-				valid = FALSE;
-			}
-			else if (int_y > world_rect.mTop)
-			{
-				out_point.mY = world_rect.mTop;
-				valid = FALSE;
-			}
-			else
-			{
-				out_point.mY = int_y;
-			}
-			return valid;
-		}
-		else
-		{
-			out_point.mX = int_x;
-			out_point.mY = int_y;
-
-			if (int_x < world_rect.mLeft)
-			{
-				valid = FALSE;
-			}
-			else if (int_x > world_rect.mRight)
-			{
-				valid = FALSE;
-			}
-			if (int_y < world_rect.mBottom)
-			{
-				valid = FALSE;
-			}
-			else if (int_y > world_rect.mTop)
-			{
-				valid = FALSE;
-			}
-
-			return in_front && valid;
-		}
-	}
-	else
-	{
-		return FALSE;
-	}
+    BOOL in_front = TRUE;
+    LLVector3 window_coordinates;
+
+    LLVector3 dir_to_point = pos_agent - getOrigin();
+    dir_to_point /= dir_to_point.magVec();
+
+    if (dir_to_point * getAtAxis() < 0.f)
+    {
+        if (clamp)
+        {
+            return FALSE;
+        }
+        else
+        {
+            in_front = FALSE;
+        }
+    }
+
+    const LLMatrix4a& modelview = get_current_modelview();
+    const LLMatrix4a& projection = get_current_projection();
+    const LLRect& world_view_rect = gViewerWindow->getWorldViewRectRaw();
+
+    if (ALGLMath::projectf(pos_agent, modelview, projection, world_view_rect, window_coordinates))
+    {
+        F32 &x = window_coordinates.mV[VX];
+        F32 &y = window_coordinates.mV[VY];
+
+        // convert screen coordinates to virtual UI coordinates
+        x /= gViewerWindow->getDisplayScale().mV[VX];
+        y /= gViewerWindow->getDisplayScale().mV[VY];
+
+        // should now have the x,y coords of grab_point in screen space
+        LLRect world_rect = gViewerWindow->getWorldViewRectScaled();
+
+        // convert to pixel coordinates
+        S32 int_x = lltrunc(x);
+        S32 int_y = lltrunc(y);
+
+        BOOL valid = TRUE;
+
+        if (clamp)
+        {
+            if (int_x < world_rect.mLeft)
+            {
+                out_point.mX = world_rect.mLeft;
+                valid = FALSE;
+            }
+            else if (int_x > world_rect.mRight)
+            {
+                out_point.mX = world_rect.mRight;
+                valid = FALSE;
+            }
+            else
+            {
+                out_point.mX = int_x;
+            }
+
+            if (int_y < world_rect.mBottom)
+            {
+                out_point.mY = world_rect.mBottom;
+                valid = FALSE;
+            }
+            else if (int_y > world_rect.mTop)
+            {
+                out_point.mY = world_rect.mTop;
+                valid = FALSE;
+            }
+            else
+            {
+                out_point.mY = int_y;
+            }
+            return valid;
+        }
+        else
+        {
+            out_point.mX = int_x;
+            out_point.mY = int_y;
+
+            if (int_x < world_rect.mLeft)
+            {
+                valid = FALSE;
+            }
+            else if (int_x > world_rect.mRight)
+            {
+                valid = FALSE;
+            }
+            if (int_y < world_rect.mBottom)
+            {
+                valid = FALSE;
+            }
+            else if (int_y > world_rect.mTop)
+            {
+                valid = FALSE;
+            }
+
+            return in_front && valid;
+        }
+    }
+    else
+    {
+        return FALSE;
+    }
 }
 
 // Uses the last GL matrices set in set_perspective to project a point from
 // the agent's region space to the nearest edge in screen coordinates.
 // Returns TRUE if projection succeeds.
 BOOL LLViewerCamera::projectPosAgentToScreenEdge(const LLVector3 &pos_agent,
-												LLCoordGL &out_point) const
+                                                LLCoordGL &out_point) const
 {
-	LLVector3 dir_to_point = pos_agent - getOrigin();
-	dir_to_point /= dir_to_point.magVec();
-
-	BOOL in_front = TRUE;
-	if (dir_to_point * getAtAxis() < 0.f)
-	{
-		in_front = FALSE;
-	}
-
-	const LLMatrix4a& modelview = get_current_modelview();
-	const LLMatrix4a& projection = get_current_projection();
-
-	const LLRect& world_view_rect = gViewerWindow->getWorldViewRectRaw();
-	LLVector3 window_coordinates;
-
-	if (ALGLMath::projectf(pos_agent, modelview, projection, world_view_rect, window_coordinates))
-	{
-		F32 &x = window_coordinates.mV[VX];
-		F32 &y = window_coordinates.mV[VY];
-
-		x /= gViewerWindow->getDisplayScale().mV[VX];
-		y /= gViewerWindow->getDisplayScale().mV[VY];
-		// should now have the x,y coords of grab_point in screen space
-		const LLRect& world_rect = gViewerWindow->getWorldViewRectScaled();
-
-		// ...sanity check
-		S32 int_x = lltrunc(x);
-		S32 int_y = lltrunc(y);
-
-		// find the center
-		GLdouble center_x = (GLdouble)world_rect.getCenterX();
-		GLdouble center_y = (GLdouble)world_rect.getCenterY();
-
-		if (x == center_x  &&  y == center_y)
-		{
-			// can't project to edge from exact center
-			return FALSE;
-		}
-
-		// find the line from center to local
-		GLdouble line_x = x - center_x;
-		GLdouble line_y = y - center_y;
-
-		int_x = lltrunc(center_x);
-		int_y = lltrunc(center_y);
-
-
-		if (0.f == line_x)
-		{
-			// the slope of the line is undefined
-			if (line_y > 0.f)
-			{
-				int_y = world_rect.mTop;
-			}
-			else
-			{
-				int_y = world_rect.mBottom;
-			}
-		}
-		else if (0 == world_rect.getWidth())
-		{
-			// the diagonal slope of the view is undefined
-			if (y < world_rect.mBottom)
-			{
-				int_y = world_rect.mBottom;
-			}
-			else if ( y > world_rect.mTop)
-			{
-				int_y = world_rect.mTop;
-			}
-		}
-		else
-		{
-			F32 line_slope = (F32)(line_y / line_x);
-			F32 rect_slope = ((F32)world_rect.getHeight()) / ((F32)world_rect.getWidth());
-
-			if (fabs(line_slope) > rect_slope)
-			{
-				if (line_y < 0.f)
-				{
-					// bottom
-					int_y = world_rect.mBottom;
-				}
-				else
-				{
-					// top
-					int_y = world_rect.mTop;
-				}
-				int_x = lltrunc(((GLdouble)int_y - center_y) / line_slope + center_x);
-			}
-			else if (fabs(line_slope) < rect_slope)
-			{
-				if (line_x < 0.f)
-				{
-					// left
-					int_x = world_rect.mLeft;
-				}
-				else
-				{
-					// right
-					int_x = world_rect.mRight;
-				}
-				int_y = lltrunc(((GLdouble)int_x - center_x) * line_slope + center_y);
-			}
-			else
-			{
-				// exactly parallel ==> push to the corners
-				if (line_x > 0.f)
-				{
-					int_x = world_rect.mRight;
-				}
-				else
-				{
-					int_x = world_rect.mLeft;
-				}
-				if (line_y > 0.0f)
-				{
-					int_y = world_rect.mTop;
-				}
-				else
-				{
-					int_y = world_rect.mBottom;
-				}
-			}
-		}
-		if (!in_front)
-		{
-			int_x = world_rect.mLeft + world_rect.mRight - int_x;
-			int_y = world_rect.mBottom + world_rect.mTop - int_y;
-		}
-
-		out_point.mX = int_x + world_rect.mLeft;
-		out_point.mY = int_y + world_rect.mBottom;
-		return TRUE;
-	}
-	return FALSE;
+    LLVector3 dir_to_point = pos_agent - getOrigin();
+    dir_to_point /= dir_to_point.magVec();
+
+    BOOL in_front = TRUE;
+    if (dir_to_point * getAtAxis() < 0.f)
+    {
+        in_front = FALSE;
+    }
+
+    const LLMatrix4a& modelview = get_current_modelview();
+    const LLMatrix4a& projection = get_current_projection();
+
+    const LLRect& world_view_rect = gViewerWindow->getWorldViewRectRaw();
+    LLVector3 window_coordinates;
+
+    if (ALGLMath::projectf(pos_agent, modelview, projection, world_view_rect, window_coordinates))
+    {
+        F32 &x = window_coordinates.mV[VX];
+        F32 &y = window_coordinates.mV[VY];
+
+        x /= gViewerWindow->getDisplayScale().mV[VX];
+        y /= gViewerWindow->getDisplayScale().mV[VY];
+        // should now have the x,y coords of grab_point in screen space
+        const LLRect& world_rect = gViewerWindow->getWorldViewRectScaled();
+
+        // ...sanity check
+        S32 int_x = lltrunc(x);
+        S32 int_y = lltrunc(y);
+
+        // find the center
+        GLdouble center_x = (GLdouble)world_rect.getCenterX();
+        GLdouble center_y = (GLdouble)world_rect.getCenterY();
+
+        if (x == center_x  &&  y == center_y)
+        {
+            // can't project to edge from exact center
+            return FALSE;
+        }
+
+        // find the line from center to local
+        GLdouble line_x = x - center_x;
+        GLdouble line_y = y - center_y;
+
+        int_x = lltrunc(center_x);
+        int_y = lltrunc(center_y);
+
+
+        if (0.f == line_x)
+        {
+            // the slope of the line is undefined
+            if (line_y > 0.f)
+            {
+                int_y = world_rect.mTop;
+            }
+            else
+            {
+                int_y = world_rect.mBottom;
+            }
+        }
+        else if (0 == world_rect.getWidth())
+        {
+            // the diagonal slope of the view is undefined
+            if (y < world_rect.mBottom)
+            {
+                int_y = world_rect.mBottom;
+            }
+            else if ( y > world_rect.mTop)
+            {
+                int_y = world_rect.mTop;
+            }
+        }
+        else
+        {
+            F32 line_slope = (F32)(line_y / line_x);
+            F32 rect_slope = ((F32)world_rect.getHeight()) / ((F32)world_rect.getWidth());
+
+            if (fabs(line_slope) > rect_slope)
+            {
+                if (line_y < 0.f)
+                {
+                    // bottom
+                    int_y = world_rect.mBottom;
+                }
+                else
+                {
+                    // top
+                    int_y = world_rect.mTop;
+                }
+                int_x = lltrunc(((GLdouble)int_y - center_y) / line_slope + center_x);
+            }
+            else if (fabs(line_slope) < rect_slope)
+            {
+                if (line_x < 0.f)
+                {
+                    // left
+                    int_x = world_rect.mLeft;
+                }
+                else
+                {
+                    // right
+                    int_x = world_rect.mRight;
+                }
+                int_y = lltrunc(((GLdouble)int_x - center_x) * line_slope + center_y);
+            }
+            else
+            {
+                // exactly parallel ==> push to the corners
+                if (line_x > 0.f)
+                {
+                    int_x = world_rect.mRight;
+                }
+                else
+                {
+                    int_x = world_rect.mLeft;
+                }
+                if (line_y > 0.0f)
+                {
+                    int_y = world_rect.mTop;
+                }
+                else
+                {
+                    int_y = world_rect.mBottom;
+                }
+            }
+        }
+        if (!in_front)
+        {
+            int_x = world_rect.mLeft + world_rect.mRight - int_x;
+            int_y = world_rect.mBottom + world_rect.mTop - int_y;
+        }
+
+        out_point.mX = int_x + world_rect.mLeft;
+        out_point.mY = int_y + world_rect.mBottom;
+        return TRUE;
+    }
+    return FALSE;
 }
 
 
 void LLViewerCamera::getPixelVectors(const LLVector3 &pos_agent, LLVector3 &up, LLVector3 &right)
 {
-	LLVector3 to_vec = pos_agent - getOrigin();
+    LLVector3 to_vec = pos_agent - getOrigin();
 
-	F32 at_dist = to_vec * getAtAxis();
+    F32 at_dist = to_vec * getAtAxis();
 
-	F32 height_meters = at_dist* (F32)tan(getView()/2.f);
-	F32 height_pixels = getViewHeightInPixels()/2.f;
+    F32 height_meters = at_dist* (F32)tan(getView()/2.f);
+    F32 height_pixels = getViewHeightInPixels()/2.f;
 
-	F32 pixel_aspect = gViewerWindow->getWindow()->getPixelAspectRatio();
+    F32 pixel_aspect = gViewerWindow->getWindow()->getPixelAspectRatio();
 
-	F32 meters_per_pixel = height_meters / height_pixels;
-	up = getUpAxis() * meters_per_pixel * gViewerWindow->getDisplayScale().mV[VY];
-	right = -1.f * pixel_aspect * meters_per_pixel * getLeftAxis() * gViewerWindow->getDisplayScale().mV[VX];
+    F32 meters_per_pixel = height_meters / height_pixels;
+    up = getUpAxis() * meters_per_pixel * gViewerWindow->getDisplayScale().mV[VY];
+    right = -1.f * pixel_aspect * meters_per_pixel * getLeftAxis() * gViewerWindow->getDisplayScale().mV[VX];
 }
 
 LLVector3 LLViewerCamera::roundToPixel(const LLVector3 &pos_agent)
 {
-	F32 dist = (pos_agent - getOrigin()).magVec();
-	// Convert to screen space and back, preserving the depth.
-	LLCoordGL screen_point;
-	if (!projectPosAgentToScreen(pos_agent, screen_point, FALSE))
-	{
-		// Off the screen, just return the original position.
-		return pos_agent;
-	}
-
-	LLVector3 ray_dir;
-
-	projectScreenToPosAgent(screen_point.mX, screen_point.mY, &ray_dir);
-	ray_dir -= getOrigin();
-	ray_dir.normVec();
-
-	LLVector3 pos_agent_rounded = getOrigin() + ray_dir*dist;
-
-	/*
-	LLVector3 pixel_x, pixel_y;
-	getPixelVectors(pos_agent_rounded, pixel_y, pixel_x);
-	pos_agent_rounded += 0.5f*pixel_x, 0.5f*pixel_y;
-	*/
-	return pos_agent_rounded;
+    F32 dist = (pos_agent - getOrigin()).magVec();
+    // Convert to screen space and back, preserving the depth.
+    LLCoordGL screen_point;
+    if (!projectPosAgentToScreen(pos_agent, screen_point, FALSE))
+    {
+        // Off the screen, just return the original position.
+        return pos_agent;
+    }
+
+    LLVector3 ray_dir;
+
+    projectScreenToPosAgent(screen_point.mX, screen_point.mY, &ray_dir);
+    ray_dir -= getOrigin();
+    ray_dir.normVec();
+
+    LLVector3 pos_agent_rounded = getOrigin() + ray_dir*dist;
+
+    /*
+    LLVector3 pixel_x, pixel_y;
+    getPixelVectors(pos_agent_rounded, pixel_y, pixel_x);
+    pos_agent_rounded += 0.5f*pixel_x, 0.5f*pixel_y;
+    */
+    return pos_agent_rounded;
 }
 
 BOOL LLViewerCamera::cameraUnderWater() const
@@ -681,67 +681,67 @@ BOOL LLViewerCamera::cameraUnderWater() const
         regionp = gAgent.getRegion();
     }
 
-	if(!regionp)
-	{
-		return FALSE ;
-	}
+    if(!regionp)
+    {
+        return FALSE ;
+    }
 
-	return getOrigin().mV[VZ] < regionp->getWaterHeight();
+    return getOrigin().mV[VZ] < regionp->getWaterHeight();
 }
 
 BOOL LLViewerCamera::areVertsVisible(LLViewerObject* volumep, BOOL all_verts)
 {
-	S32 i, num_faces;
-	LLDrawable* drawablep = volumep->mDrawable;
-
-	if (!drawablep)
-	{
-		return FALSE;
-	}
-
-	LLVolume* volume = volumep->getVolume();
-	if (!volume)
-	{
-		return FALSE;
-	}
-
-	LLVOVolume* vo_volume = (LLVOVolume*) volumep;
-
-	vo_volume->updateRelativeXform();
-	
-	LLMatrix4 render_mat(vo_volume->getRenderRotation(), LLVector4(vo_volume->getRenderPosition()));
-
-	LLMatrix4a render_mata;
-	render_mata.loadu(render_mat);
-	const LLMatrix4a& mata = vo_volume->getRelativeXform();;
-
-	num_faces = volume->getNumVolumeFaces();
-	for (i = 0; i < num_faces; i++)
-	{
-		const LLVolumeFace& face = volume->getVolumeFace(i);
-				
-		for (U32 v = 0; v < face.mNumVertices; v++)
-		{
-			const LLVector4a& src_vec = face.mPositions[v];
-			LLVector4a vec;
-			mata.affineTransform(src_vec, vec);
-
-			if (drawablep->isActive())
-			{
-				LLVector4a t = vec;
-				render_mata.affineTransform(t, vec);
-			}
-
-			BOOL in_frustum = pointInFrustum(LLVector3(vec.getF32ptr())) > 0;
-
-			if (( !in_frustum && all_verts) ||
-				 (in_frustum && !all_verts))
-			{
-				return !all_verts;
-			}
-		}
-	}
-	return all_verts;
+    S32 i, num_faces;
+    LLDrawable* drawablep = volumep->mDrawable;
+
+    if (!drawablep)
+    {
+        return FALSE;
+    }
+
+    LLVolume* volume = volumep->getVolume();
+    if (!volume)
+    {
+        return FALSE;
+    }
+
+    LLVOVolume* vo_volume = (LLVOVolume*) volumep;
+
+    vo_volume->updateRelativeXform();
+
+    LLMatrix4 render_mat(vo_volume->getRenderRotation(), LLVector4(vo_volume->getRenderPosition()));
+
+    LLMatrix4a render_mata;
+    render_mata.loadu(render_mat);
+    const LLMatrix4a& mata = vo_volume->getRelativeXform();;
+
+    num_faces = volume->getNumVolumeFaces();
+    for (i = 0; i < num_faces; i++)
+    {
+        const LLVolumeFace& face = volume->getVolumeFace(i);
+
+        for (U32 v = 0; v < face.mNumVertices; v++)
+        {
+            const LLVector4a& src_vec = face.mPositions[v];
+            LLVector4a vec;
+            mata.affineTransform(src_vec, vec);
+
+            if (drawablep->isActive())
+            {
+                LLVector4a t = vec;
+                render_mata.affineTransform(t, vec);
+            }
+
+            BOOL in_frustum = pointInFrustum(LLVector3(vec.getF32ptr())) > 0;
+
+            if (( !in_frustum && all_verts) ||
+                 (in_frustum && !all_verts))
+            {
+                return !all_verts;
+            }
+        }
+    }
+    return all_verts;
 }
 
 extern BOOL gCubeSnapshot;
@@ -751,29 +751,29 @@ extern BOOL gCubeSnapshot;
 {
     llassert(!gCubeSnapshot);
 
-	F32 old_fov = getView();
+    F32 old_fov = getView();
 
-	// cap the FoV
-	vertical_fov_rads = llclamp(vertical_fov_rads, getMinView(), getMaxView());
+    // cap the FoV
+    vertical_fov_rads = llclamp(vertical_fov_rads, getMinView(), getMaxView());
 
-	if (vertical_fov_rads == old_fov) return;
+    if (vertical_fov_rads == old_fov) return;
 
-	// send the new value to the simulator
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_AgentFOV);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addU32Fast(_PREHASH_CircuitCode, gMessageSystem->mOurCircuitCode);
+    // send the new value to the simulator
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_AgentFOV);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addU32Fast(_PREHASH_CircuitCode, gMessageSystem->mOurCircuitCode);
 
-	msg->nextBlockFast(_PREHASH_FOVBlock);
-	msg->addU32Fast(_PREHASH_GenCounter, 0);
-	msg->addF32Fast(_PREHASH_VerticalAngle, vertical_fov_rads);
+    msg->nextBlockFast(_PREHASH_FOVBlock);
+    msg->addU32Fast(_PREHASH_GenCounter, 0);
+    msg->addF32Fast(_PREHASH_VerticalAngle, vertical_fov_rads);
 
-	gAgent.sendReliableMessage();
+    gAgent.sendReliableMessage();
 
-	// sync the camera with the new value
-	LLCamera::setView(vertical_fov_rads); // call base implementation
+    // sync the camera with the new value
+    LLCamera::setView(vertical_fov_rads); // call base implementation
 }
 
 void LLViewerCamera::setViewNoBroadcast(F32 vertical_fov_rads)
@@ -781,43 +781,43 @@ void LLViewerCamera::setViewNoBroadcast(F32 vertical_fov_rads)
     LLCamera::setView(vertical_fov_rads);
 }
 
-void LLViewerCamera::setDefaultFOV(F32 vertical_fov_rads) 
+void LLViewerCamera::setDefaultFOV(F32 vertical_fov_rads)
 {
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	F32 nCamFOVMin, nCamFOVMax;
-	if ( (RlvActions::isRlvEnabled()) && (RlvActions::getCameraFOVLimits(nCamFOVMin, nCamFOVMax)) )
-		vertical_fov_rads = llclamp(vertical_fov_rads, nCamFOVMin, nCamFOVMax);
+    F32 nCamFOVMin, nCamFOVMax;
+    if ( (RlvActions::isRlvEnabled()) && (RlvActions::getCameraFOVLimits(nCamFOVMin, nCamFOVMax)) )
+        vertical_fov_rads = llclamp(vertical_fov_rads, nCamFOVMin, nCamFOVMax);
 // [/RLVa:KB]
 
-	vertical_fov_rads = llclamp(vertical_fov_rads, getMinView(), getMaxView());
-	setView(vertical_fov_rads);
-	mCameraFOVDefault = vertical_fov_rads; 
-	mCosHalfCameraFOV = cosf(mCameraFOVDefault * 0.5f);
+    vertical_fov_rads = llclamp(vertical_fov_rads, getMinView(), getMaxView());
+    setView(vertical_fov_rads);
+    mCameraFOVDefault = vertical_fov_rads;
+    mCosHalfCameraFOV = cosf(mCameraFOVDefault * 0.5f);
 }
 
 BOOL LLViewerCamera::isDefaultFOVChanged()
 {
-	if(mPrevCameraFOVDefault != mCameraFOVDefault)
-	{
-		mPrevCameraFOVDefault = mCameraFOVDefault;
-		return !gSavedSettings.getBOOL("IgnoreFOVZoomForLODs");
-	}
-	return FALSE;
+    if(mPrevCameraFOVDefault != mCameraFOVDefault)
+    {
+        mPrevCameraFOVDefault = mCameraFOVDefault;
+        return !gSavedSettings.getBOOL("IgnoreFOVZoomForLODs");
+    }
+    return FALSE;
 }
 
 void LLViewerCamera::loadDefaultFOV()
 {
-	setView(mSavedFOVDefault);
-	mSavedFOVLoaded = true;
-	mCameraFOVDefault = mSavedFOVDefault; 
-	mCosHalfCameraFOV = cosf(mCameraFOVDefault * 0.5f);
+    setView(mSavedFOVDefault);
+    mSavedFOVLoaded = true;
+    mCameraFOVDefault = mSavedFOVDefault;
+    mCosHalfCameraFOV = cosf(mCameraFOVDefault * 0.5f);
 }
 
 
 // static
 void LLViewerCamera::updateCameraAngle( void* user_data, const LLSD& value)
 {
-	LLViewerCamera* self=(LLViewerCamera*)user_data;
-	self->setDefaultFOV(value.asReal());	
+    LLViewerCamera* self=(LLViewerCamera*)user_data;
+    self->setDefaultFOV(value.asReal());
 }
 
diff --git a/indra/newview/llviewercontrol.cpp b/indra/newview/llviewercontrol.cpp
index 6f8a9147797936a75c968801339876e4f7ba3961..9043f960b3392e2de93cf7cf5a50f600b10b2e33 100644
--- a/indra/newview/llviewercontrol.cpp
+++ b/indra/newview/llviewercontrol.cpp
@@ -1,4 +1,4 @@
-/** 
+/**
  * @file llviewercontrol.cpp
  * @brief Viewer configuration
  * @author Richard Nelson
@@ -6,21 +6,21 @@
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -30,7 +30,7 @@
 #include "llviewercontrol.h"
 
 // Library includes
-#include "llwindow.h"	// getGamma()
+#include "llwindow.h"   // getGamma()
 
 // For Listeners
 #include "llaudioengine.h"
@@ -89,15 +89,15 @@
 #include <boost/algorithm/string.hpp>
 
 #ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-BOOL 				gHackGodmode = FALSE;
+BOOL                gHackGodmode = FALSE;
 #endif
 
 // Should you contemplate changing the name "Global", please first grep for
 // that string literal. There are at least a couple other places in the C++
 // code that assume the LLControlGroup named "Global" is gSavedSettings.
-LLControlGroup gSavedSettings("Global");	// saved at end of session
+LLControlGroup gSavedSettings("Global");    // saved at end of session
 LLControlGroup gSavedPerAccountSettings("PerAccount"); // saved at end of session
-LLControlGroup gCrashSettings("CrashSettings");	// saved at end of session
+LLControlGroup gCrashSettings("CrashSettings"); // saved at end of session
 LLControlGroup gWarningSettings("Warnings"); // persists ignored dialogs/warnings
 LLControlGroup gSkinSettings("SkinUI"); // [AL:CR] read only settings tied to skin selection
 
@@ -111,8 +111,8 @@ extern BOOL gDebugGL;
 
 static bool handleRenderAvatarMouselookChanged(const LLSD& newvalue)
 {
-	LLVOAvatar::sVisibleInFirstPerson = newvalue.asBoolean();
-	return true;
+    LLVOAvatar::sVisibleInFirstPerson = newvalue.asBoolean();
+    return true;
 }
 
 static bool handleRenderFarClipChanged(const LLSD& newvalue)
@@ -120,9 +120,9 @@ static bool handleRenderFarClipChanged(const LLSD& newvalue)
     if (LLStartUp::getStartupState() >= STATE_STARTED)
     {
         F32 draw_distance = (F32)newvalue.asReal();
-	gAgentCamera.mDrawDistance = draw_distance;
-	LLWorld::getInstance()->setLandFarClip(draw_distance);
-	return true;
+    gAgentCamera.mDrawDistance = draw_distance;
+    LLWorld::getInstance()->setLandFarClip(draw_distance);
+    return true;
     }
     return false;
 }
@@ -134,7 +134,7 @@ static bool handleTerrainScaleChanged(const LLSD& newvalue)
     {
         LLDrawPoolTerrain::sDetailScale = F32(1.0 / scale);
     }
-	return true;
+    return true;
 }
 
 static bool handlePBRTerrainScaleChanged(const LLSD& newvalue)
@@ -144,7 +144,7 @@ static bool handlePBRTerrainScaleChanged(const LLSD& newvalue)
     {
         LLDrawPoolTerrain::sPBRDetailScale = F32(1.0 / scale);
     }
-	return true;
+    return true;
 }
 
 static bool handleDebugAvatarJointsChanged(const LLSD& newvalue)
@@ -156,19 +156,19 @@ static bool handleDebugAvatarJointsChanged(const LLSD& newvalue)
 
 static bool handleAvatarHoverOffsetChanged(const LLSD& newvalue)
 {
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->setHoverIfRegionEnabled();
-	}
-	return true;
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->setHoverIfRegionEnabled();
+    }
+    return true;
 }
 
 
 static bool handleSetShaderChanged(const LLSD& newvalue)
 {
-	// changing shader level may invalidate existing cached bump maps, as the shader type determines the format of the bump map it expects - clear and repopulate the bump cache
-	gBumpImageList.destroyGL();
-	gBumpImageList.restoreGL();
+    // changing shader level may invalidate existing cached bump maps, as the shader type determines the format of the bump map it expects - clear and repopulate the bump cache
+    gBumpImageList.destroyGL();
+    gBumpImageList.restoreGL();
 
     if (gPipeline.isInit())
     {
@@ -176,9 +176,9 @@ static bool handleSetShaderChanged(const LLSD& newvalue)
         LLPipeline::refreshCachedSettings();
     }
 
-	// else, leave terrain detail as is
-	LLViewerShaderMgr::instance()->setShaders();
-	return true;
+    // else, leave terrain detail as is
+    LLViewerShaderMgr::instance()->setShaders();
+    return true;
 }
 
 static bool handleRenderPerfTestChanged(const LLSD& newvalue)
@@ -195,10 +195,10 @@ static bool handleRenderPerfTestChanged(const LLSD& newvalue)
                                                                          LLPipeline::RENDER_TYPE_HUD,
                                                                          LLPipeline::RENDER_TYPE_CLOUDS,
                                                                          LLPipeline::RENDER_TYPE_HUD_PARTICLES,
-                                                                         LLPipeline::END_RENDER_TYPES); 
+                                                                         LLPipeline::END_RENDER_TYPES);
                gPipeline.setRenderDebugFeatureControl(LLPipeline::RENDER_DEBUG_FEATURE_UI, false);
        }
-       else 
+       else
        {
                gPipeline.setRenderTypeMask(LLPipeline::RENDER_TYPE_WL_SKY,
                                                                          LLPipeline::RENDER_TYPE_TERRAIN,
@@ -218,62 +218,62 @@ static bool handleRenderPerfTestChanged(const LLSD& newvalue)
 
 bool handleRenderTransparentWaterChanged(const LLSD& newvalue)
 {
-	if (gPipeline.isInit())
-	{
-		gPipeline.updateRenderTransparentWater();
-		gPipeline.releaseGLBuffers();
-		gPipeline.createGLBuffers();
-		LLViewerShaderMgr::instance()->setShaders();
-	}
-	LLWorld::getInstance()->updateWaterObjects();
-	return true;
+    if (gPipeline.isInit())
+    {
+        gPipeline.updateRenderTransparentWater();
+        gPipeline.releaseGLBuffers();
+        gPipeline.createGLBuffers();
+        LLViewerShaderMgr::instance()->setShaders();
+    }
+    LLWorld::getInstance()->updateWaterObjects();
+    return true;
 }
 
 
 static bool handleShadowsResized(const LLSD& newvalue)
 {
-	gPipeline.requestResizeShadowTexture();
-	return true;
+    gPipeline.requestResizeShadowTexture();
+    return true;
 }
 
 static bool handleWindowResized(const LLSD& newvalue)
 {
-	gPipeline.requestResizeScreenTexture();
-	return true;
+    gPipeline.requestResizeScreenTexture();
+    return true;
 }
 
 static bool handleReleaseGLBufferChanged(const LLSD& newvalue)
 {
-	if (gPipeline.isInit())
-	{
-		gPipeline.releaseGLBuffers();
-		gPipeline.createGLBuffers();
-	}
-	return true;
+    if (gPipeline.isInit())
+    {
+        gPipeline.releaseGLBuffers();
+        gPipeline.createGLBuffers();
+    }
+    return true;
 }
 
 static bool handleLUTBufferChanged(const LLSD& newvalue)
 {
-	if (gPipeline.isInit())
-	{
-		gPipeline.releaseLUTBuffers();
-		gPipeline.createLUTBuffers();
-	}
-	return true;
+    if (gPipeline.isInit())
+    {
+        gPipeline.releaseLUTBuffers();
+        gPipeline.createLUTBuffers();
+    }
+    return true;
 }
 
 static bool handleAnisotropicFilteringChanged(const LLSD& newval)
 {
-	F32 val = newval.asReal();
-	LLRender::sAnisotropicFilteringLevel = val;
-	LLImageGL::dirtyTexOptions();
-	return true;
+    F32 val = newval.asReal();
+    LLRender::sAnisotropicFilteringLevel = val;
+    LLImageGL::dirtyTexOptions();
+    return true;
 }
 
 static bool validateAnisotropicFiltering(const LLSD& val)
 {
-	F32 filter_level = val.asInteger();
-	return filter_level == 0 || filter_level == 2 || filter_level == 4 || filter_level == 8 || filter_level == 16;
+    F32 filter_level = val.asInteger();
+    return filter_level == 0 || filter_level == 2 || filter_level == 4 || filter_level == 8 || filter_level == 16;
 }
 
 static bool handleVSyncChanged(const LLSD& newvalue)
@@ -295,62 +295,62 @@ static bool handleVSyncChanged(const LLSD& newvalue)
 
 static bool handleVolumeLODChanged(const LLSD& newvalue)
 {
-	LLVOVolume::sLODFactor = llclamp((F32) newvalue.asReal(), 0.01f, MAX_LOD_FACTOR);
-	LLVOVolume::sDistanceFactor = 1.f-LLVOVolume::sLODFactor * 0.1f;
-	return true;
+    LLVOVolume::sLODFactor = llclamp((F32) newvalue.asReal(), 0.01f, MAX_LOD_FACTOR);
+    LLVOVolume::sDistanceFactor = 1.f-LLVOVolume::sLODFactor * 0.1f;
+    return true;
 }
 
 static bool handleAvatarLODChanged(const LLSD& newvalue)
 {
-	LLVOAvatar::sLODFactor = llclamp((F32) newvalue.asReal(), 0.f, MAX_AVATAR_LOD_FACTOR);
-	return true;
+    LLVOAvatar::sLODFactor = llclamp((F32) newvalue.asReal(), 0.f, MAX_AVATAR_LOD_FACTOR);
+    return true;
 }
 
 static bool handleAvatarPhysicsLODChanged(const LLSD& newvalue)
 {
-	LLVOAvatar::sPhysicsLODFactor = llclamp((F32) newvalue.asReal(), 0.f, MAX_AVATAR_LOD_FACTOR);
-	return true;
+    LLVOAvatar::sPhysicsLODFactor = llclamp((F32) newvalue.asReal(), 0.f, MAX_AVATAR_LOD_FACTOR);
+    return true;
 }
 
 static bool handleTerrainLODChanged(const LLSD& newvalue)
 {
-		LLVOSurfacePatch::sLODFactor = (F32)newvalue.asReal();
-		//sqaure lod factor to get exponential range of [0,4] and keep
-		//a value of 1 in the middle of the detail slider for consistency
-		//with other detail sliders (see panel_preferences_graphics1.xml)
-		LLVOSurfacePatch::sLODFactor *= LLVOSurfacePatch::sLODFactor;
-		return true;
+        LLVOSurfacePatch::sLODFactor = (F32)newvalue.asReal();
+        //sqaure lod factor to get exponential range of [0,4] and keep
+        //a value of 1 in the middle of the detail slider for consistency
+        //with other detail sliders (see panel_preferences_graphics1.xml)
+        LLVOSurfacePatch::sLODFactor *= LLVOSurfacePatch::sLODFactor;
+        return true;
 }
 
 static bool handleTreeLODChanged(const LLSD& newvalue)
 {
-	LLVOTree::sTreeFactor = (F32) newvalue.asReal();
-	return true;
+    LLVOTree::sTreeFactor = (F32) newvalue.asReal();
+    return true;
 }
 
 static bool handleFlexLODChanged(const LLSD& newvalue)
 {
-	LLVolumeImplFlexible::sUpdateFactor = (F32) newvalue.asReal();
-	return true;
+    LLVolumeImplFlexible::sUpdateFactor = (F32) newvalue.asReal();
+    return true;
 }
 
 static bool handleGammaChanged(const LLSD& newvalue)
 {
-	F32 gamma = (F32) newvalue.asReal();
-	if (gamma == 0.0f)
-	{
-		gamma = 1.0f; // restore normal gamma
-	}
-	if (gViewerWindow && gViewerWindow->getWindow() && gamma != gViewerWindow->getWindow()->getGamma())
-	{
-		// Only save it if it's changed
-		if (!gViewerWindow->getWindow()->setGamma(gamma))
-		{
-			LL_WARNS() << "setGamma failed!" << LL_ENDL;
-		}
-	}
+    F32 gamma = (F32) newvalue.asReal();
+    if (gamma == 0.0f)
+    {
+        gamma = 1.0f; // restore normal gamma
+    }
+    if (gViewerWindow && gViewerWindow->getWindow() && gamma != gViewerWindow->getWindow()->getGamma())
+    {
+        // Only save it if it's changed
+        if (!gViewerWindow->getWindow()->setGamma(gamma))
+        {
+            LL_WARNS() << "setGamma failed!" << LL_ENDL;
+        }
+    }
 
-	return true;
+    return true;
 }
 
 const F32 MAX_USER_FOG_RATIO = 10.f;
@@ -358,88 +358,88 @@ const F32 MIN_USER_FOG_RATIO = 0.5f;
 
 static bool handleFogRatioChanged(const LLSD& newvalue)
 {
-	F32 fog_ratio = llmax(MIN_USER_FOG_RATIO, llmin((F32) newvalue.asReal(), MAX_USER_FOG_RATIO));
-	gSky.setFogRatio(fog_ratio);
-	return true;
+    F32 fog_ratio = llmax(MIN_USER_FOG_RATIO, llmin((F32) newvalue.asReal(), MAX_USER_FOG_RATIO));
+    gSky.setFogRatio(fog_ratio);
+    return true;
 }
 
 static bool handleMaxPartCountChanged(const LLSD& newvalue)
 {
-	LLViewerPartSim::setMaxPartCount(newvalue.asInteger());
-	return true;
+    LLViewerPartSim::setMaxPartCount(newvalue.asInteger());
+    return true;
 }
 
 static bool handleChatFontSizeChanged(const LLSD& newvalue)
 {
-	if(gConsole)
-	{
-		gConsole->setFontSize(newvalue.asInteger());
-	}
+    if(gConsole)
+    {
+        gConsole->setFontSize(newvalue.asInteger());
+    }
 
-	LLViewerChat::signalChatFontChanged();
-	LLFloaterIMSessionTab::processChatHistoryStyleUpdate(false);
+    LLViewerChat::signalChatFontChanged();
+    LLFloaterIMSessionTab::processChatHistoryStyleUpdate(false);
 
-	return true;
+    return true;
 }
 
 static bool handleConsoleMaxLinesChanged(const LLSD& newvalue)
 {
-	if(gConsole)
-	{
-		gConsole->setMaxLines(newvalue.asInteger());
-	}
-	return true;
+    if(gConsole)
+    {
+        gConsole->setMaxLines(newvalue.asInteger());
+    }
+    return true;
 }
 
 static void handleAudioVolumeChanged(const LLSD& newvalue)
 {
-	audio_update_volume(true);
+    audio_update_volume(true);
 }
 
 static bool handleJoystickChanged(const LLSD& newvalue)
 {
-	LLViewerJoystick::getInstance()->setCameraNeedsUpdate(TRUE);
-	return true;
+    LLViewerJoystick::getInstance()->setCameraNeedsUpdate(TRUE);
+    return true;
 }
 
 static bool handleUseOcclusionChanged(const LLSD& newvalue)
 {
-	LLPipeline::sUseOcclusion = (newvalue.asBoolean()
-		&& LLFeatureManager::getInstance()->isFeatureAvailable("UseOcclusion") && !gUseWireframe) ? 2 : 0;
-	return true;
+    LLPipeline::sUseOcclusion = (newvalue.asBoolean()
+        && LLFeatureManager::getInstance()->isFeatureAvailable("UseOcclusion") && !gUseWireframe) ? 2 : 0;
+    return true;
 }
 
 static bool handleUploadBakedTexOldChanged(const LLSD& newvalue)
 {
-	LLPipeline::sForceOldBakedUpload = newvalue.asBoolean();
-	return true;
+    LLPipeline::sForceOldBakedUpload = newvalue.asBoolean();
+    return true;
 }
 
 
 static bool handleWLSkyDetailChanged(const LLSD&)
 {
-	if (gSky.mVOWLSkyp.notNull())
-	{
-		gSky.mVOWLSkyp->updateGeometry(gSky.mVOWLSkyp->mDrawable);
-	}
-	return true;
+    if (gSky.mVOWLSkyp.notNull())
+    {
+        gSky.mVOWLSkyp->updateGeometry(gSky.mVOWLSkyp->mDrawable);
+    }
+    return true;
 }
 
 static bool handleRepartition(const LLSD&)
 {
-	if (gPipeline.isInit())
-	{
-		gOctreeMaxCapacity = gSavedSettings.getU32("OctreeMaxNodeCapacity");
-		gOctreeMinSize = gSavedSettings.getF32("OctreeMinimumNodeSize");
-		gObjectList.repartitionObjects();
-	}
-	return true;
+    if (gPipeline.isInit())
+    {
+        gOctreeMaxCapacity = gSavedSettings.getU32("OctreeMaxNodeCapacity");
+        gOctreeMinSize = gSavedSettings.getF32("OctreeMinimumNodeSize");
+        gObjectList.repartitionObjects();
+    }
+    return true;
 }
 
 static bool handleRenderDynamicLODChanged(const LLSD& newvalue)
 {
-	LLPipeline::sDynamicLOD = newvalue.asBoolean();
-	return true;
+    LLPipeline::sDynamicLOD = newvalue.asBoolean();
+    return true;
 }
 
 static bool handleReflectionProbeDetailChanged(const LLSD& newvalue)
@@ -470,161 +470,161 @@ static bool handleHeroProbeResolutionChanged(const LLSD &newvalue)
 
 static bool handleRenderDebugPipelineChanged(const LLSD& newvalue)
 {
-	gDebugPipeline = newvalue.asBoolean();
-	return true;
+    gDebugPipeline = newvalue.asBoolean();
+    return true;
 }
 
 static bool handleRenderResolutionDivisorChanged(const LLSD&)
 {
-	gResizeScreenTexture = TRUE;
-	return true;
+    gResizeScreenTexture = TRUE;
+    return true;
 }
 
 static bool handleDebugViewsChanged(const LLSD& newvalue)
 {
-	LLView::sDebugRects = newvalue.asBoolean();
-	return true;
+    LLView::sDebugRects = newvalue.asBoolean();
+    return true;
 }
 
 static bool handleLogFileChanged(const LLSD& newvalue)
 {
-	std::string log_filename = newvalue.asString();
-	LLFile::remove(log_filename);
-	LLError::logToFile(log_filename);
-	return true;
+    std::string log_filename = newvalue.asString();
+    LLFile::remove(log_filename);
+    LLError::logToFile(log_filename);
+    return true;
 }
 
 bool handleHideGroupTitleChanged(const LLSD& newvalue)
 {
-	gAgent.setHideGroupTitle(newvalue);
-	return true;
+    gAgent.setHideGroupTitle(newvalue);
+    return true;
 }
 
 bool handleEffectColorChanged(const LLSD& newvalue)
 {
-	gAgent.setEffectColor(LLColor4(newvalue));
-	return true;
+    gAgent.setEffectColor(LLColor4(newvalue));
+    return true;
 }
 
 bool handleHighResSnapshotChanged(const LLSD& newvalue)
 {
-	// High Res Snapshot active, must uncheck RenderUIInSnapshot
-	if (newvalue.asBoolean())
-	{
-		gSavedSettings.setBOOL( "RenderUIInSnapshot", FALSE );
-	}
-	return true;
+    // High Res Snapshot active, must uncheck RenderUIInSnapshot
+    if (newvalue.asBoolean())
+    {
+        gSavedSettings.setBOOL( "RenderUIInSnapshot", FALSE );
+    }
+    return true;
 }
 
 bool handleVoiceClientPrefsChanged(const LLSD& newvalue)
 {
-	if (LLVoiceClient::instanceExists())
-	{
-		LLVoiceClient::getInstance()->updateSettings();
-	}
-	return true;
+    if (LLVoiceClient::instanceExists())
+    {
+        LLVoiceClient::getInstance()->updateSettings();
+    }
+    return true;
 }
 
 bool handleVelocityInterpolate(const LLSD& newvalue)
 {
-	LLMessageSystem* msg = gMessageSystem;
-	if ( newvalue.asBoolean() )
-	{
-		msg->newMessageFast(_PREHASH_VelocityInterpolateOn);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		gAgent.sendReliableMessage();
-		LL_INFOS() << "Velocity Interpolation On" << LL_ENDL;
-	}
-	else
-	{
-		msg->newMessageFast(_PREHASH_VelocityInterpolateOff);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		gAgent.sendReliableMessage();
-		LL_INFOS() << "Velocity Interpolation Off" << LL_ENDL;
-	}
-	return true;
+    LLMessageSystem* msg = gMessageSystem;
+    if ( newvalue.asBoolean() )
+    {
+        msg->newMessageFast(_PREHASH_VelocityInterpolateOn);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        gAgent.sendReliableMessage();
+        LL_INFOS() << "Velocity Interpolation On" << LL_ENDL;
+    }
+    else
+    {
+        msg->newMessageFast(_PREHASH_VelocityInterpolateOff);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        gAgent.sendReliableMessage();
+        LL_INFOS() << "Velocity Interpolation Off" << LL_ENDL;
+    }
+    return true;
 }
 
 bool handleForceShowGrid(const LLSD& newvalue)
 {
-	LLPanelLogin::updateLocationSelectorsVisibility();
-	return true;
+    LLPanelLogin::updateLocationSelectorsVisibility();
+    return true;
 }
 
 bool handleLoginLocationChanged()
 {
-	/*
-	 * This connects the default preference setting to the state of the login
-	 * panel if it is displayed; if you open the preferences panel before
-	 * logging in, and change the default login location there, the login
-	 * panel immediately changes to match your new preference.
-	 */
-	std::string new_login_location = gSavedSettings.getString("LoginLocation");
-	LL_DEBUGS("AppInit")<<new_login_location<<LL_ENDL;
-	LLStartUp::setStartSLURL(LLSLURL(new_login_location));
-	return true;
+    /*
+     * This connects the default preference setting to the state of the login
+     * panel if it is displayed; if you open the preferences panel before
+     * logging in, and change the default login location there, the login
+     * panel immediately changes to match your new preference.
+     */
+    std::string new_login_location = gSavedSettings.getString("LoginLocation");
+    LL_DEBUGS("AppInit")<<new_login_location<<LL_ENDL;
+    LLStartUp::setStartSLURL(LLSLURL(new_login_location));
+    return true;
 }
 
 bool handleSpellCheckChanged()
 {
-	if (gSavedSettings.getBOOL("SpellCheck"))
-	{
-		std::list<std::string> dict_list;
-		std::string dict_setting = gSavedSettings.getString("SpellCheckDictionary");
-		boost::split(dict_list, dict_setting, boost::is_any_of(std::string(",")));
-		if (!dict_list.empty())
-		{
-			LLSpellChecker::setUseSpellCheck(dict_list.front());
-			dict_list.pop_front();
-			LLSpellChecker::instance().setSecondaryDictionaries(dict_list);
-			return true;
-		}
-	}
-	LLSpellChecker::setUseSpellCheck(LLStringUtil::null);
-	return true;
+    if (gSavedSettings.getBOOL("SpellCheck"))
+    {
+        std::list<std::string> dict_list;
+        std::string dict_setting = gSavedSettings.getString("SpellCheckDictionary");
+        boost::split(dict_list, dict_setting, boost::is_any_of(std::string(",")));
+        if (!dict_list.empty())
+        {
+            LLSpellChecker::setUseSpellCheck(dict_list.front());
+            dict_list.pop_front();
+            LLSpellChecker::instance().setSecondaryDictionaries(dict_list);
+            return true;
+        }
+    }
+    LLSpellChecker::setUseSpellCheck(LLStringUtil::null);
+    return true;
 }
 
 bool toggle_agent_pause(const LLSD& newvalue)
 {
-	if ( newvalue.asBoolean() )
-	{
-		send_agent_pause();
-	}
-	else
-	{
-		send_agent_resume();
-	}
-	return true;
+    if ( newvalue.asBoolean() )
+    {
+        send_agent_pause();
+    }
+    else
+    {
+        send_agent_resume();
+    }
+    return true;
 }
 
 bool toggle_show_navigation_panel(const LLSD& newvalue)
 {
-	bool value = newvalue.asBoolean();
+    bool value = newvalue.asBoolean();
 
-	LLNavigationBar::getInstance()->setVisible(value);
-	gSavedSettings.setBOOL("ShowMiniLocationPanel", !value);
+    LLNavigationBar::getInstance()->setVisible(value);
+    gSavedSettings.setBOOL("ShowMiniLocationPanel", !value);
     gViewerWindow->reshapeStatusBarContainer();
-	return true;
+    return true;
 }
 
 bool toggle_show_mini_location_panel(const LLSD& newvalue)
 {
-	bool value = newvalue.asBoolean();
+    bool value = newvalue.asBoolean();
 
-	LLPanelTopInfoBar::getInstance()->setVisible(value);
-	gSavedSettings.setBOOL("ShowNavbarNavigationPanel", !value);
+    LLPanelTopInfoBar::getInstance()->setVisible(value);
+    gSavedSettings.setBOOL("ShowNavbarNavigationPanel", !value);
 
-	return true;
+    return true;
 }
 
 bool toggle_show_object_render_cost(const LLSD& newvalue)
 {
-	LLFloaterTools::sShowObjectCost = newvalue.asBoolean();
-	return true;
+    LLFloaterTools::sShowObjectCost = newvalue.asBoolean();
+    return true;
 }
 
 void handleTargetFPSChanged(const LLSD& newValue)
@@ -808,10 +808,10 @@ void settings_setup_listeners()
     setting_setup_signal_listener(gSavedSettings, "RenderFogRatio", handleFogRatioChanged);
     setting_setup_signal_listener(gSavedSettings, "RenderMaxPartCount", handleMaxPartCountChanged);
     setting_setup_signal_listener(gSavedSettings, "RenderDynamicLOD", handleRenderDynamicLODChanged);
-	setting_setup_signal_listener(gSavedSettings, "RenderAutoMaskAlphaUseRMSE", handleSetShaderChanged);
-	setting_setup_signal_listener(gSavedSettings, "RenderAutoMaskAlphaMaxRMSE", handleSetShaderChanged);
-	setting_setup_signal_listener(gSavedSettings, "RenderAutoMaskAlphaMaxMid", handleSetShaderChanged);
-	setting_setup_signal_listener(gSavedSettings, "RenderVSyncEnable", handleVSyncChanged);
+    setting_setup_signal_listener(gSavedSettings, "RenderAutoMaskAlphaUseRMSE", handleSetShaderChanged);
+    setting_setup_signal_listener(gSavedSettings, "RenderAutoMaskAlphaMaxRMSE", handleSetShaderChanged);
+    setting_setup_signal_listener(gSavedSettings, "RenderAutoMaskAlphaMaxMid", handleSetShaderChanged);
+    setting_setup_signal_listener(gSavedSettings, "RenderVSyncEnable", handleVSyncChanged);
     setting_setup_signal_listener(gSavedSettings, "RenderDeferredNoise", handleReleaseGLBufferChanged);
     setting_setup_signal_listener(gSavedSettings, "RenderDebugPipeline", handleRenderDebugPipelineChanged);
     setting_setup_signal_listener(gSavedSettings, "RenderResolutionDivisor", handleRenderResolutionDivisorChanged);
@@ -824,7 +824,7 @@ void settings_setup_listeners()
     setting_setup_signal_listener(gSavedSettings, "RenderShadowDetail", handleSetShaderChanged);
     setting_setup_signal_listener(gSavedSettings, "RenderDeferredSSAO", handleSetShaderChanged);
 // [SL:KB] - Patch: Settings-RenderResolutionMultiplier | Checked: Catznip-5.4
-	setting_setup_signal_listener(gSavedSettings, "RenderResolutionMultiplier", handleRenderResolutionDivisorChanged);
+    setting_setup_signal_listener(gSavedSettings, "RenderResolutionMultiplier", handleRenderResolutionDivisorChanged);
 // [/SL:KB]
     setting_setup_signal_listener(gSavedSettings, "RenderPerformanceTest", handleRenderPerfTestChanged);
     setting_setup_signal_listener(gSavedSettings, "ChatFontName", handleChatFontSizeChanged);
@@ -903,7 +903,7 @@ void settings_setup_listeners()
     setting_setup_signal_listener(gSavedSettings, "VoiceInputAudioDevice", handleVoiceClientPrefsChanged);
     setting_setup_signal_listener(gSavedSettings, "VoiceOutputAudioDevice", handleVoiceClientPrefsChanged);
     setting_setup_signal_listener(gSavedSettings, "AudioLevelMic", handleVoiceClientPrefsChanged);
-    setting_setup_signal_listener(gSavedSettings, "LipSyncEnabled", handleVoiceClientPrefsChanged);	
+    setting_setup_signal_listener(gSavedSettings, "LipSyncEnabled", handleVoiceClientPrefsChanged);
     setting_setup_signal_listener(gSavedSettings, "VelocityInterpolate", handleVelocityInterpolate);
     setting_setup_signal_listener(gSavedSettings, "QAMode", show_debug_menus);
     setting_setup_signal_listener(gSavedSettings, "UseDebugMenus", show_debug_menus);
@@ -935,11 +935,11 @@ void settings_setup_listeners()
 
     setting_setup_signal_listener(gSavedPerAccountSettings, "AvatarHoverOffsetZ", handleAvatarHoverOffsetChanged);
 // [RLVa:KB] - Checked: 2015-12-27 (RLVa-1.5.0)
-	setting_setup_signal_listener(gSavedSettings, std::string(RlvSettingNames::Main), RlvSettings::onChangedSettingMain);
+    setting_setup_signal_listener(gSavedSettings, std::string(RlvSettingNames::Main), RlvSettings::onChangedSettingMain);
 // [/RLVa:KB]
-	setting_setup_signal_listener(gSavedSettings, "AlchemyHudTextFadeDistance", LLHUDText::onFadeSettingsChanged);
-	setting_setup_signal_listener(gSavedSettings, "AlchemyHudTextFadeRange", LLHUDText::onFadeSettingsChanged);
-	setting_setup_signal_listener(gSavedSettings, "RenderAnisotropicLevel", handleAnisotropicFilteringChanged);
+    setting_setup_signal_listener(gSavedSettings, "AlchemyHudTextFadeDistance", LLHUDText::onFadeSettingsChanged);
+    setting_setup_signal_listener(gSavedSettings, "AlchemyHudTextFadeRange", LLHUDText::onFadeSettingsChanged);
+    setting_setup_signal_listener(gSavedSettings, "RenderAnisotropicLevel", handleAnisotropicFilteringChanged);
     gSavedSettings.getControl("RenderAnisotropicLevel")->getValidateSignal()->connect(boost::bind(&validateAnisotropicFiltering, _2));
 
     setting_setup_signal_listener(gSavedSettings, "NameTagShowUsernames", handleNameTagOptionChanged);
@@ -971,19 +971,19 @@ DECL_LLCC(LLSD, test_llsd);
 void test_cached_control()
 {
 #define do { TEST_LLCC(T, V) if((T)mySetting_##T != V) LL_ERRS() << "Fail "#T << LL_ENDL; } while(0)
-	TEST_LLCC(U32, 666);
-	TEST_LLCC(S32, (S32)-666);
-	TEST_LLCC(F32, (F32)-666.666);
-	TEST_LLCC(bool, true);
-	TEST_LLCC(BOOL, FALSE);
-	if((std::string)mySetting_string != "Default String Value") LL_ERRS() << "Fail string" << LL_ENDL;
-	TEST_LLCC(LLVector3, LLVector3(1.0f, 2.0f, 3.0f));
-	TEST_LLCC(LLVector3d, LLVector3d(6.0f, 5.0f, 4.0f));
-	TEST_LLCC(LLRect, LLRect(0, 0, 100, 500));
-	TEST_LLCC(LLColor4, LLColor4(0.0f, 0.5f, 1.0f));
-	TEST_LLCC(LLColor3, LLColor3(1.0f, 0.f, 0.5f));
-	TEST_LLCC(LLColor4U, LLColor4U(255, 200, 100, 255));
-//There's no LLSD comparsion for LLCC yet. TEST_LLCC(LLSD, test_llsd); 
+    TEST_LLCC(U32, 666);
+    TEST_LLCC(S32, (S32)-666);
+    TEST_LLCC(F32, (F32)-666.666);
+    TEST_LLCC(bool, true);
+    TEST_LLCC(BOOL, FALSE);
+    if((std::string)mySetting_string != "Default String Value") LL_ERRS() << "Fail string" << LL_ENDL;
+    TEST_LLCC(LLVector3, LLVector3(1.0f, 2.0f, 3.0f));
+    TEST_LLCC(LLVector3d, LLVector3d(6.0f, 5.0f, 4.0f));
+    TEST_LLCC(LLRect, LLRect(0, 0, 100, 500));
+    TEST_LLCC(LLColor4, LLColor4(0.0f, 0.5f, 1.0f));
+    TEST_LLCC(LLColor3, LLColor3(1.0f, 0.f, 0.5f));
+    TEST_LLCC(LLColor4U, LLColor4U(255, 200, 100, 255));
+//There's no LLSD comparsion for LLCC yet. TEST_LLCC(LLSD, test_llsd);
 }
 #endif // TEST_CACHED_CONTROL
 
diff --git a/indra/newview/llviewerdisplay.cpp b/indra/newview/llviewerdisplay.cpp
index 57454bf5dd88ba025751cecb067df5be26e1baf2..a89cccba122989184eccb89dcaf8091bd716e5a1 100644
--- a/indra/newview/llviewerdisplay.cpp
+++ b/indra/newview/llviewerdisplay.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewerdisplay.cpp
  * @brief LLViewerDisplay class implementation
  *
  * $LicenseInfo:firstyear=2004&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -95,10 +95,10 @@ extern bool gShiftFrame;
 LLPointer<LLViewerTexture> gDisconnectedImagep = NULL;
 
 // used to toggle renderer back on after teleport
-BOOL		 gTeleportDisplay = FALSE;
+BOOL         gTeleportDisplay = FALSE;
 LLFrameTimer gTeleportDisplayTimer;
 LLFrameTimer gTeleportArrivalTimer;
-const F32		RESTORE_GL_TIME = 5.f;	// Wait this long while reloading textures before we raise the curtain
+const F32       RESTORE_GL_TIME = 5.f;  // Wait this long while reloading textures before we raise the curtain
 
 BOOL gForceRenderLandFence = FALSE;
 BOOL gDisplaySwapBuffers = FALSE;
@@ -133,85 +133,85 @@ void render_disconnected_background();
 
 void display_startup()
 {
-	if (   !gViewerWindow
-		|| !gViewerWindow->getActive()
-		|| !gViewerWindow->getWindow()->getVisible() 
-		|| gViewerWindow->getWindow()->getMinimized()
-		|| gNonInteractive)
-	{
-		return; 
-	}
-
-	gPipeline.updateGL();
-
-	// Written as branch to appease GCC which doesn't like different
-	// pointer types across ternary ops
-	//
-	if (!LLViewerFetchedTexture::sWhiteImagep.isNull())
-	{
-	LLTexUnit::sWhiteTexture = LLViewerFetchedTexture::sWhiteImagep->getTexName();
-	}
-
-	LLGLSDefault gls_default;
-
-	// Required for HTML update in login screen
-	static S32 frame_count = 0;
-
-	LLGLState::checkStates();
-
-	if (frame_count++ > 1) // make sure we have rendered a frame first
-	{
-		LLViewerDynamicTexture::updateAllInstances();
-	}
+    if (   !gViewerWindow
+        || !gViewerWindow->getActive()
+        || !gViewerWindow->getWindow()->getVisible()
+        || gViewerWindow->getWindow()->getMinimized()
+        || gNonInteractive)
+    {
+        return;
+    }
+
+    gPipeline.updateGL();
+
+    // Written as branch to appease GCC which doesn't like different
+    // pointer types across ternary ops
+    //
+    if (!LLViewerFetchedTexture::sWhiteImagep.isNull())
+    {
+    LLTexUnit::sWhiteTexture = LLViewerFetchedTexture::sWhiteImagep->getTexName();
+    }
+
+    LLGLSDefault gls_default;
+
+    // Required for HTML update in login screen
+    static S32 frame_count = 0;
+
+    LLGLState::checkStates();
+
+    if (frame_count++ > 1) // make sure we have rendered a frame first
+    {
+        LLViewerDynamicTexture::updateAllInstances();
+    }
     else
     {
         LL_DEBUGS("Window") << "First display_startup frame" << LL_ENDL;
     }
 
-	LLGLState::checkStates();
+    LLGLState::checkStates();
 
     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // | GL_STENCIL_BUFFER_BIT);
-	LLGLSUIDefault gls_ui;
-	gPipeline.disableLights();
+    LLGLSUIDefault gls_ui;
+    gPipeline.disableLights();
 
-	if (gViewerWindow)
-	gViewerWindow->setup2DRender();
-	if (gViewerWindow)
-	gViewerWindow->draw();
-	gGL.flush();
+    if (gViewerWindow)
+    gViewerWindow->setup2DRender();
+    if (gViewerWindow)
+    gViewerWindow->draw();
+    gGL.flush();
 
-	LLVertexBuffer::unbind();
+    LLVertexBuffer::unbind();
 
-	LLGLState::checkStates();
+    LLGLState::checkStates();
 
-	if (gViewerWindow && gViewerWindow->getWindow())
-	gViewerWindow->getWindow()->swapBuffers();
+    if (gViewerWindow && gViewerWindow->getWindow())
+    gViewerWindow->getWindow()->swapBuffers();
 
-	glClear(GL_DEPTH_BUFFER_BIT);
+    glClear(GL_DEPTH_BUFFER_BIT);
 }
 
 void display_update_camera()
 {
     LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Update Camera");
-	// TODO: cut draw distance down if customizing avatar?
-	// TODO: cut draw distance on per-parcel basis?
+    // TODO: cut draw distance down if customizing avatar?
+    // TODO: cut draw distance on per-parcel basis?
 
-	// Cut draw distance in half when customizing avatar,
-	// but on the viewer only.
-	F32 final_far = gAgentCamera.mDrawDistance;
+    // Cut draw distance in half when customizing avatar,
+    // but on the viewer only.
+    F32 final_far = gAgentCamera.mDrawDistance;
     if (gCubeSnapshot)
     {
-		static LLCachedControl<F32> ref_probe_draw_dist(gSavedSettings, "RenderReflectionProbeDrawDistance", 64);
+        static LLCachedControl<F32> ref_probe_draw_dist(gSavedSettings, "RenderReflectionProbeDrawDistance", 64);
         final_far = ref_probe_draw_dist;
     }
     else if (CAMERA_MODE_CUSTOMIZE_AVATAR == gAgentCamera.getCameraMode())
-        
-	{
-		final_far *= 0.5f;
-	}
-	LLViewerCamera::getInstance()->setFar(final_far);
-	gViewerWindow->setup3DRender();
-	
+
+    {
+        final_far *= 0.5f;
+    }
+    LLViewerCamera::getInstance()->setFar(final_far);
+    gViewerWindow->setup3DRender();
+
     if (!gCubeSnapshot)
     {
         // Update land visibility too
@@ -222,30 +222,30 @@ void display_update_camera()
 // Write some stats to LL_INFOS()
 void display_stats()
 {
-	LL_PROFILE_ZONE_SCOPED
+    LL_PROFILE_ZONE_SCOPED
     const F32 FPS_LOG_FREQUENCY = 10.f;
     if (gRecentFPSTime.getElapsedTimeF32() >= FPS_LOG_FREQUENCY)
-	{
-		LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("DS - FPS");
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("DS - FPS");
         F32 fps = gRecentFrameCount / FPS_LOG_FREQUENCY;
-		LL_INFOS() << llformat("FPS: %.02f", fps) << LL_ENDL;
-		gRecentFrameCount = 0;
-		gRecentFPSTime.reset();
-	}
-	static const LLCachedControl<F32> mem_log_freq(gSavedSettings, "MemoryLogFrequency");
-	if (mem_log_freq > 0.f && gRecentMemoryTime.getElapsedTimeF32() >= mem_log_freq)
-	{
-		LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("DS - Memory");
-		gMemoryAllocated = U64Bytes(LLMemory::getCurrentRSS());
-		U32Megabytes memory = gMemoryAllocated;
-		LL_INFOS() << "MEMORY: " << memory << LL_ENDL;
-		LLMemory::logMemoryInfo(TRUE) ;
-		gRecentMemoryTime.reset();
-	}
+        LL_INFOS() << llformat("FPS: %.02f", fps) << LL_ENDL;
+        gRecentFrameCount = 0;
+        gRecentFPSTime.reset();
+    }
+    static const LLCachedControl<F32> mem_log_freq(gSavedSettings, "MemoryLogFrequency");
+    if (mem_log_freq > 0.f && gRecentMemoryTime.getElapsedTimeF32() >= mem_log_freq)
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("DS - Memory");
+        gMemoryAllocated = U64Bytes(LLMemory::getCurrentRSS());
+        U32Megabytes memory = gMemoryAllocated;
+        LL_INFOS() << "MEMORY: " << memory << LL_ENDL;
+        LLMemory::logMemoryInfo(TRUE) ;
+        gRecentMemoryTime.reset();
+    }
     const F32 ASSET_STORAGE_LOG_FREQUENCY = 60.f;
     if (gAssetStorageLogTime.getElapsedTimeF32() >= ASSET_STORAGE_LOG_FREQUENCY)
     {
-		LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("DS - Asset Storage");
+        LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("DS - Asset Storage");
         gAssetStorageLogTime.reset();
         gAssetStorage->logAssetStorageInfo();
     }
@@ -278,149 +278,149 @@ static std::string STR_DISPLAY_DONE("Display:Done");
 
 static void update_tp_display(bool minimized)
 {
-	static LLCachedControl<F32> teleport_arrival_delay(gSavedSettings, "TeleportArrivalDelay");
-	static LLCachedControl<F32> teleport_local_delay(gSavedSettings, "TeleportLocalDelay");
-
-	S32 attach_count = 0;
-	if (isAgentAvatarValid())
-	{
-		attach_count = gAgentAvatarp->getAttachmentCount();
-	}
-	F32 teleport_save_time = TELEPORT_EXPIRY + TELEPORT_EXPIRY_PER_ATTACHMENT * attach_count;
-	F32 teleport_elapsed = gTeleportDisplayTimer.getElapsedTimeF32();
-	F32 teleport_percent = teleport_elapsed * (100.f / teleport_save_time);
-	if (gAgent.getTeleportState() != LLAgent::TELEPORT_START && teleport_percent > 100.f)
-	{
-		// Give up.  Don't keep the UI locked forever.
-		LL_WARNS("Teleport") << "Giving up on teleport. elapsed time " << teleport_elapsed << " exceeds max time " << teleport_save_time << LL_ENDL;
-		gAgent.setTeleportState(LLAgent::TELEPORT_NONE);
-		gAgent.setTeleportMessage(std::string());
-	}
-
-	LLFloaterProgressView* pProgFloater = LLFloaterReg::getTypedInstance<LLFloaterProgressView>("progress_view");
-
-	// Make sure the TP progress panel gets hidden in case the viewer window
-	// is minimized *during* a TP. HB
-	if (minimized)
-	{
-		pProgFloater->setShowProgress(FALSE);
-	}
-
-	const std::string& message = gAgent.getTeleportMessage();
-	switch (gAgent.getTeleportState())
-	{
-		case LLAgent::TELEPORT_PENDING:
-		{
-			gTeleportDisplayTimer.reset();
-			const std::string& msg = LLAgent::sTeleportProgressMessages["pending"];
-			if (!minimized)
-			{
-				pProgFloater->setShowProgress(TRUE);
-				pProgFloater->setProgressPercent(llmin(teleport_percent, 0.0f));
-				pProgFloater->setProgressString(msg);
-			}
-			gAgent.setTeleportMessage(msg);
-			break;
-		}
-
-		case LLAgent::TELEPORT_START:
-		{
-			// Transition to REQUESTED.  Viewer has sent some kind
-			// of TeleportRequest to the source simulator
-			gTeleportDisplayTimer.reset();
-			const std::string& msg = LLAgent::sTeleportProgressMessages["requesting"];
-			LL_INFOS("Teleport") << "A teleport request has been sent, setting state to TELEPORT_REQUESTED" << LL_ENDL;
-			gAgent.setTeleportState(LLAgent::TELEPORT_REQUESTED);
-			gAgent.setTeleportMessage(msg);
-			if (!minimized)
-			{
-				pProgFloater->setShowProgress(TRUE);
-				pProgFloater->setProgressPercent(llmin(teleport_percent, 0.0f));
-				pProgFloater->setProgressString(msg);
-				//pProgFloater->setProgressMessage(gAgent.mMOTD);
-			}
-			break;
-		}
-
-		case LLAgent::TELEPORT_REQUESTED:
-			// Waiting for source simulator to respond
-			if (!minimized)
-			{
-				pProgFloater->setProgressPercent(llmin(teleport_percent, 37.5f));
-				pProgFloater->setProgressString(message);
-			}
-			break;
-
-		case LLAgent::TELEPORT_MOVING:
-			// Viewer has received destination location from source simulator
-			if (!minimized)
-			{
-				pProgFloater->setProgressPercent(llmin(teleport_percent, 75.f));
-				pProgFloater->setProgressString(message);
-			}
-			break;
-
-		case LLAgent::TELEPORT_START_ARRIVAL:
-			// Transition to ARRIVING.  Viewer has received avatar update, etc.,
-			// from destination simulator
-			gTeleportArrivalTimer.reset();
-			LL_INFOS("Teleport") << "Changing state to TELEPORT_ARRIVING" << LL_ENDL;
-			gAgent.setTeleportState(LLAgent::TELEPORT_ARRIVING);
-			gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages["arriving"]);
-			gAgent.sheduleTeleportIM();
-			gTextureList.mForceResetTextureStats = TRUE;
-			gAgentCamera.resetView(TRUE, TRUE);			
-			if (!minimized)
-			{
-				pProgFloater->setProgressCancelButtonVisible(FALSE, LLTrans::getString("Cancel"));
-				pProgFloater->setProgressPercent(75.f);
-			}
-			break;
-
-		case LLAgent::TELEPORT_ARRIVING:
-		// Make the user wait while content "pre-caches"
-		{
-			F32 arrival_fraction = (gTeleportArrivalTimer.getElapsedTimeF32() / teleport_arrival_delay());
-			if (arrival_fraction > 1.f)
-			{
-				arrival_fraction = 1.f;
-				//LLFirstUse::useTeleport();
-				LL_INFOS("Teleport") << "arrival_fraction is " << arrival_fraction << " changing state to TELEPORT_NONE" << LL_ENDL;
-				gAgent.setTeleportState(LLAgent::TELEPORT_NONE);
-			}
-			if (!minimized)
-			{
-				pProgFloater->setProgressCancelButtonVisible(FALSE, LLTrans::getString("Cancel"));
-				pProgFloater->setProgressPercent(arrival_fraction * 25.f + 75.f);
-				pProgFloater->setProgressString(message);
-			}
-			break;
-		}
-
-		case LLAgent::TELEPORT_LOCAL:
-		// Short delay when teleporting in the same sim (progress screen active but not shown - did not
-		// fall-through from TELEPORT_START)
-		{
-			if (gTeleportDisplayTimer.getElapsedTimeF32() > teleport_local_delay())
-			{
-				//LLFirstUse::useTeleport();
-				LL_INFOS("Teleport") << "State is local and gTeleportDisplayTimer " << gTeleportDisplayTimer.getElapsedTimeF32()
-									 << " exceeds teleport_local_delete " << teleport_local_delay
-									 << "; setting state to TELEPORT_NONE"
-									 << LL_ENDL;
-				gAgent.setTeleportState(LLAgent::TELEPORT_NONE);
-			}
-			break;
-		}
-
-		case LLAgent::TELEPORT_NONE:
-			// No teleport in progress
-			pProgFloater->setShowProgress(FALSE);
+    static LLCachedControl<F32> teleport_arrival_delay(gSavedSettings, "TeleportArrivalDelay");
+    static LLCachedControl<F32> teleport_local_delay(gSavedSettings, "TeleportLocalDelay");
+
+    S32 attach_count = 0;
+    if (isAgentAvatarValid())
+    {
+        attach_count = gAgentAvatarp->getAttachmentCount();
+    }
+    F32 teleport_save_time = TELEPORT_EXPIRY + TELEPORT_EXPIRY_PER_ATTACHMENT * attach_count;
+    F32 teleport_elapsed = gTeleportDisplayTimer.getElapsedTimeF32();
+    F32 teleport_percent = teleport_elapsed * (100.f / teleport_save_time);
+    if (gAgent.getTeleportState() != LLAgent::TELEPORT_START && teleport_percent > 100.f)
+    {
+        // Give up.  Don't keep the UI locked forever.
+        LL_WARNS("Teleport") << "Giving up on teleport. elapsed time " << teleport_elapsed << " exceeds max time " << teleport_save_time << LL_ENDL;
+        gAgent.setTeleportState(LLAgent::TELEPORT_NONE);
+        gAgent.setTeleportMessage(std::string());
+    }
+
+    LLFloaterProgressView* pProgFloater = LLFloaterReg::getTypedInstance<LLFloaterProgressView>("progress_view");
+
+    // Make sure the TP progress panel gets hidden in case the viewer window
+    // is minimized *during* a TP. HB
+    if (minimized)
+    {
+        pProgFloater->setShowProgress(FALSE);
+    }
+
+    const std::string& message = gAgent.getTeleportMessage();
+    switch (gAgent.getTeleportState())
+    {
+        case LLAgent::TELEPORT_PENDING:
+        {
+            gTeleportDisplayTimer.reset();
+            const std::string& msg = LLAgent::sTeleportProgressMessages["pending"];
+            if (!minimized)
+            {
+                pProgFloater->setShowProgress(TRUE);
+                pProgFloater->setProgressPercent(llmin(teleport_percent, 0.0f));
+                pProgFloater->setProgressString(msg);
+            }
+            gAgent.setTeleportMessage(msg);
+            break;
+        }
+
+        case LLAgent::TELEPORT_START:
+        {
+            // Transition to REQUESTED.  Viewer has sent some kind
+            // of TeleportRequest to the source simulator
+            gTeleportDisplayTimer.reset();
+            const std::string& msg = LLAgent::sTeleportProgressMessages["requesting"];
+            LL_INFOS("Teleport") << "A teleport request has been sent, setting state to TELEPORT_REQUESTED" << LL_ENDL;
+            gAgent.setTeleportState(LLAgent::TELEPORT_REQUESTED);
+            gAgent.setTeleportMessage(msg);
+            if (!minimized)
+            {
+                pProgFloater->setShowProgress(TRUE);
+                pProgFloater->setProgressPercent(llmin(teleport_percent, 0.0f));
+                pProgFloater->setProgressString(msg);
+                //pProgFloater->setProgressMessage(gAgent.mMOTD);
+            }
+            break;
+        }
+
+        case LLAgent::TELEPORT_REQUESTED:
+            // Waiting for source simulator to respond
+            if (!minimized)
+            {
+                pProgFloater->setProgressPercent(llmin(teleport_percent, 37.5f));
+                pProgFloater->setProgressString(message);
+            }
+            break;
+
+        case LLAgent::TELEPORT_MOVING:
+            // Viewer has received destination location from source simulator
+            if (!minimized)
+            {
+                pProgFloater->setProgressPercent(llmin(teleport_percent, 75.f));
+                pProgFloater->setProgressString(message);
+            }
+            break;
+
+        case LLAgent::TELEPORT_START_ARRIVAL:
+            // Transition to ARRIVING.  Viewer has received avatar update, etc.,
+            // from destination simulator
+            gTeleportArrivalTimer.reset();
+            LL_INFOS("Teleport") << "Changing state to TELEPORT_ARRIVING" << LL_ENDL;
+            gAgent.setTeleportState(LLAgent::TELEPORT_ARRIVING);
+            gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages["arriving"]);
+            gAgent.sheduleTeleportIM();
+            gTextureList.mForceResetTextureStats = TRUE;
+            gAgentCamera.resetView(TRUE, TRUE);
+            if (!minimized)
+            {
+                pProgFloater->setProgressCancelButtonVisible(FALSE, LLTrans::getString("Cancel"));
+                pProgFloater->setProgressPercent(75.f);
+            }
+            break;
+
+        case LLAgent::TELEPORT_ARRIVING:
+        // Make the user wait while content "pre-caches"
+        {
+            F32 arrival_fraction = (gTeleportArrivalTimer.getElapsedTimeF32() / teleport_arrival_delay());
+            if (arrival_fraction > 1.f)
+            {
+                arrival_fraction = 1.f;
+                //LLFirstUse::useTeleport();
+                LL_INFOS("Teleport") << "arrival_fraction is " << arrival_fraction << " changing state to TELEPORT_NONE" << LL_ENDL;
+                gAgent.setTeleportState(LLAgent::TELEPORT_NONE);
+            }
+            if (!minimized)
+            {
+                pProgFloater->setProgressCancelButtonVisible(FALSE, LLTrans::getString("Cancel"));
+                pProgFloater->setProgressPercent(arrival_fraction * 25.f + 75.f);
+                pProgFloater->setProgressString(message);
+            }
+            break;
+        }
+
+        case LLAgent::TELEPORT_LOCAL:
+        // Short delay when teleporting in the same sim (progress screen active but not shown - did not
+        // fall-through from TELEPORT_START)
+        {
+            if (gTeleportDisplayTimer.getElapsedTimeF32() > teleport_local_delay())
+            {
+                //LLFirstUse::useTeleport();
+                LL_INFOS("Teleport") << "State is local and gTeleportDisplayTimer " << gTeleportDisplayTimer.getElapsedTimeF32()
+                                     << " exceeds teleport_local_delete " << teleport_local_delay
+                                     << "; setting state to TELEPORT_NONE"
+                                     << LL_ENDL;
+                gAgent.setTeleportState(LLAgent::TELEPORT_NONE);
+            }
+            break;
+        }
+
+        case LLAgent::TELEPORT_NONE:
+            // No teleport in progress
+            pProgFloater->setShowProgress(FALSE);
 // [SL:KB] - Patch: Appearance-TeleportAttachKill | Checked: Catznip-4.0
-			LLViewerParcelMgr::getInstance()->onTeleportDone();
+            LLViewerParcelMgr::getInstance()->onTeleportDone();
 // [/SL:KB]
-			gTeleportDisplay = FALSE;
-	}
+            gTeleportDisplay = FALSE;
+    }
 }
 
 // Paint the display!
@@ -429,526 +429,526 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot)
     LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Render");
 
     LLPerfStats::RecordSceneTime T (LLPerfStats::StatType_t::RENDER_DISPLAY); // render time capture - This is the main stat for overall rendering.
-    
-	if (gWindowResized)
-	{ //skip render on frames where window has been resized
-		LL_DEBUGS("Window") << "Resizing window" << LL_ENDL;
+
+    if (gWindowResized)
+    { //skip render on frames where window has been resized
+        LL_DEBUGS("Window") << "Resizing window" << LL_ENDL;
         LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Resize Window");
-		gGL.flush();
-		glClear(GL_COLOR_BUFFER_BIT);
-		gViewerWindow->getWindow()->swapBuffers();
-		LLPipeline::refreshCachedSettings();
-		gPipeline.resizeScreenTexture();
-		gResizeScreenTexture = FALSE;
-		gWindowResized = FALSE;
-		return;
-	}
+        gGL.flush();
+        glClear(GL_COLOR_BUFFER_BIT);
+        gViewerWindow->getWindow()->swapBuffers();
+        LLPipeline::refreshCachedSettings();
+        gPipeline.resizeScreenTexture();
+        gResizeScreenTexture = FALSE;
+        gWindowResized = FALSE;
+        return;
+    }
 
     if (gResizeShadowTexture)
-	{ //skip render on frames where window has been resized
-		gPipeline.resizeShadowTexture();
-		gResizeShadowTexture = FALSE;
-	}
-
-	gSnapshot = for_snapshot;
-
-	if (LLPipeline::sRenderDeferred)
-	{ //hack to make sky show up in deferred snapshots
-		for_snapshot = FALSE;
-	}
-
-	LLGLSDefault gls_default;
-	LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE, GL_LEQUAL);
-	
-	LLVertexBuffer::unbind();
-
-	LLGLState::checkStates();
-	
-	gPipeline.disableLights();
-
-	// Don't draw if the window is hidden or minimized.
-	// In fact, must explicitly check the minimized state before drawing.
-	// Attempting to draw into a minimized window causes a GL error. JC
-	if (   !gViewerWindow->getActive()
-		|| !gViewerWindow->getWindow()->getVisible() 
-		|| gViewerWindow->getWindow()->getMinimized() 
-		|| gNonInteractive)
-	{
-		// Clean up memory the pools may have allocated
-		if (rebuild)
-		{
-			stop_glerror();
-			gPipeline.rebuildPools();
-			stop_glerror();
-		}
-
-		LLHUDObject::renderAllForTimer();
-
-		stop_glerror();
-		gViewerWindow->returnEmptyPicks();
-		stop_glerror();
-
-		// We still need to update the teleport progress (to get changes done
-		// in TP states, else the sim does not get the messages signaling the
-		// agent's arrival). This fixes BUG-230616. HB
-		if (gTeleportDisplay)
-		{
-			// true = minimized, do not show/update the TP screen. HB
-			update_tp_display(true);
-		}
-		return; 
-	}
-
-	gViewerWindow->checkSettings();
-	
-	{
+    { //skip render on frames where window has been resized
+        gPipeline.resizeShadowTexture();
+        gResizeShadowTexture = FALSE;
+    }
+
+    gSnapshot = for_snapshot;
+
+    if (LLPipeline::sRenderDeferred)
+    { //hack to make sky show up in deferred snapshots
+        for_snapshot = FALSE;
+    }
+
+    LLGLSDefault gls_default;
+    LLGLDepthTest gls_depth(GL_TRUE, GL_TRUE, GL_LEQUAL);
+
+    LLVertexBuffer::unbind();
+
+    LLGLState::checkStates();
+
+    gPipeline.disableLights();
+
+    // Don't draw if the window is hidden or minimized.
+    // In fact, must explicitly check the minimized state before drawing.
+    // Attempting to draw into a minimized window causes a GL error. JC
+    if (   !gViewerWindow->getActive()
+        || !gViewerWindow->getWindow()->getVisible()
+        || gViewerWindow->getWindow()->getMinimized()
+        || gNonInteractive)
+    {
+        // Clean up memory the pools may have allocated
+        if (rebuild)
+        {
+            stop_glerror();
+            gPipeline.rebuildPools();
+            stop_glerror();
+        }
+
+        LLHUDObject::renderAllForTimer();
+
+        stop_glerror();
+        gViewerWindow->returnEmptyPicks();
+        stop_glerror();
+
+        // We still need to update the teleport progress (to get changes done
+        // in TP states, else the sim does not get the messages signaling the
+        // agent's arrival). This fixes BUG-230616. HB
+        if (gTeleportDisplay)
+        {
+            // true = minimized, do not show/update the TP screen. HB
+            update_tp_display(true);
+        }
+        return;
+    }
+
+    gViewerWindow->checkSettings();
+
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Picking");
-		gViewerWindow->performPick();
-	}
-	
-	LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_CHECK_STATES);
-	LLGLState::checkStates();
-	
-	//////////////////////////////////////////////////////////
-	//
-	// Logic for forcing window updates if we're in drone mode.
-	//
-
-	// *TODO: Investigate running display() during gHeadlessClient.  See if this early exit is needed DK 2011-02-18
-	if (gHeadlessClient) 
-	{
+        gViewerWindow->performPick();
+    }
+
+    LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_CHECK_STATES);
+    LLGLState::checkStates();
+
+    //////////////////////////////////////////////////////////
+    //
+    // Logic for forcing window updates if we're in drone mode.
+    //
+
+    // *TODO: Investigate running display() during gHeadlessClient.  See if this early exit is needed DK 2011-02-18
+    if (gHeadlessClient)
+    {
 #if LL_WINDOWS
-		static F32 last_update_time = 0.f;
-		if ((gFrameTimeSeconds - last_update_time) > 1.f)
-		{
-			InvalidateRect((HWND)gViewerWindow->getPlatformWindow(), NULL, FALSE);
-			last_update_time = gFrameTimeSeconds;
-		}
+        static F32 last_update_time = 0.f;
+        if ((gFrameTimeSeconds - last_update_time) > 1.f)
+        {
+            InvalidateRect((HWND)gViewerWindow->getPlatformWindow(), NULL, FALSE);
+            last_update_time = gFrameTimeSeconds;
+        }
 #elif LL_DARWIN
-		// MBW -- Do something clever here.
+        // MBW -- Do something clever here.
 #endif
-		// Not actually rendering, don't bother.
-		return;
-	}
-
-
-	//
-	// Bail out if we're in the startup state and don't want to try to
-	// render the world.
-	//
-	if (LLStartUp::getStartupState() < STATE_PRECACHE)
-	{
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_STARTUP);
-		display_startup();
-		return;
-	}
-
-
-	if (gShaderProfileFrame)
-	{
-		LLGLSLShader::initProfile();
-	}
-
-	//LLGLState::verify(FALSE);
-
-	/////////////////////////////////////////////////
-	//
-	// Update GL Texture statistics (used for discard logic?)
-	//
-
-	LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_TEXTURE_STATS);
-	stop_glerror();
-
-	LLImageGL::updateStats(gFrameTimeSeconds);
-	
-	static const LLCachedControl<S32> av_name_tag_mode(gSavedSettings, "AvatarNameTagMode");
-	static const LLCachedControl<bool> name_tag_show_grp_title(gSavedSettings, "NameTagShowGroupTitles");
-
-	LLVOAvatar::sRenderName = (ALCinematicMode::isEnabled() ? 0 : (S32)av_name_tag_mode);;
-	LLVOAvatar::sRenderGroupTitles = (name_tag_show_grp_title && av_name_tag_mode);
-	
-	gPipeline.mBackfaceCull = TRUE;
-	gFrameCount++;
-	gRecentFrameCount++;
-	if (gFocusMgr.getAppHasFocus())
-	{
-		gForegroundFrameCount++;
-	}
-
-	//////////////////////////////////////////////////////////
-	//
-	// Display start screen if we're teleporting, and skip render
-	//
-
-	if (gTeleportDisplay)
-	{
+        // Not actually rendering, don't bother.
+        return;
+    }
+
+
+    //
+    // Bail out if we're in the startup state and don't want to try to
+    // render the world.
+    //
+    if (LLStartUp::getStartupState() < STATE_PRECACHE)
+    {
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_STARTUP);
+        display_startup();
+        return;
+    }
+
+
+    if (gShaderProfileFrame)
+    {
+        LLGLSLShader::initProfile();
+    }
+
+    //LLGLState::verify(FALSE);
+
+    /////////////////////////////////////////////////
+    //
+    // Update GL Texture statistics (used for discard logic?)
+    //
+
+    LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_TEXTURE_STATS);
+    stop_glerror();
+
+    LLImageGL::updateStats(gFrameTimeSeconds);
+
+    static const LLCachedControl<S32> av_name_tag_mode(gSavedSettings, "AvatarNameTagMode");
+    static const LLCachedControl<bool> name_tag_show_grp_title(gSavedSettings, "NameTagShowGroupTitles");
+
+    LLVOAvatar::sRenderName = (ALCinematicMode::isEnabled() ? 0 : (S32)av_name_tag_mode);;
+    LLVOAvatar::sRenderGroupTitles = (name_tag_show_grp_title && av_name_tag_mode);
+
+    gPipeline.mBackfaceCull = TRUE;
+    gFrameCount++;
+    gRecentFrameCount++;
+    if (gFocusMgr.getAppHasFocus())
+    {
+        gForegroundFrameCount++;
+    }
+
+    //////////////////////////////////////////////////////////
+    //
+    // Display start screen if we're teleporting, and skip render
+    //
+
+    if (gTeleportDisplay)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Teleport Display");
-		LLAppViewer::instance()->pingMainloopTimeout("Display:Teleport");
-		// Note: false = not minimized, do update the TP screen. HB
-		update_tp_display(false);
-	}
+        LLAppViewer::instance()->pingMainloopTimeout("Display:Teleport");
+        // Note: false = not minimized, do update the TP screen. HB
+        update_tp_display(false);
+    }
     else if(LLAppViewer::instance()->logoutRequestSent())
-	{
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_LOGOUT);
-		F32 percent_done = gLogoutTimer.getElapsedTimeF32() * 100.f / gLogoutMaxTime;
-		if (percent_done > 100.f)
-		{
-			percent_done = 100.f;
-		}
-
-		if( LLApp::isExiting() )
-		{
-			percent_done = 100.f;
-		}
-		
-		gViewerWindow->setProgressPercent( percent_done );
-		gViewerWindow->setProgressMessage(LLStringUtil::null);
-	}
-	else
-	if (gRestoreGL)
-	{
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RESTOREGL);
-		F32 percent_done = gRestoreGLTimer.getElapsedTimeF32() * 100.f / RESTORE_GL_TIME;
-		if( percent_done > 100.f )
-		{
-			gViewerWindow->setShowProgress(FALSE);
-			gRestoreGL = FALSE;
-		}
-		else
-		{
-
-			if( LLApp::isExiting() )
-			{
-				percent_done = 100.f;
-			}
-			
-			gViewerWindow->setProgressPercent( percent_done );
-		}
-		gViewerWindow->setProgressMessage(LLStringUtil::null);
-	}
-
-	//////////////////////////
-	//
-	// Prepare for the next frame
-	//
-
-	/////////////////////////////
-	//
-	// Update the camera
-	//
-	//
-
-	LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_CAMERA);
+    {
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_LOGOUT);
+        F32 percent_done = gLogoutTimer.getElapsedTimeF32() * 100.f / gLogoutMaxTime;
+        if (percent_done > 100.f)
+        {
+            percent_done = 100.f;
+        }
+
+        if( LLApp::isExiting() )
+        {
+            percent_done = 100.f;
+        }
+
+        gViewerWindow->setProgressPercent( percent_done );
+        gViewerWindow->setProgressMessage(LLStringUtil::null);
+    }
+    else
+    if (gRestoreGL)
+    {
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RESTOREGL);
+        F32 percent_done = gRestoreGLTimer.getElapsedTimeF32() * 100.f / RESTORE_GL_TIME;
+        if( percent_done > 100.f )
+        {
+            gViewerWindow->setShowProgress(FALSE);
+            gRestoreGL = FALSE;
+        }
+        else
+        {
+
+            if( LLApp::isExiting() )
+            {
+                percent_done = 100.f;
+            }
+
+            gViewerWindow->setProgressPercent( percent_done );
+        }
+        gViewerWindow->setProgressMessage(LLStringUtil::null);
+    }
+
+    //////////////////////////
+    //
+    // Prepare for the next frame
+    //
+
+    /////////////////////////////
+    //
+    // Update the camera
+    //
+    //
+
+    LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_CAMERA);
     if (LLViewerCamera::instanceExists())
     {
         LLViewerCamera::getInstance()->setZoomParameters(zoom_factor, subfield);
         LLViewerCamera::getInstance()->setNear(MIN_NEAR_PLANE);
     }
 
-	//////////////////////////
-	//
-	// clear the next buffer
-	// (must follow dynamic texture writing since that uses the frame buffer)
-	//
-
-	if (gDisconnected)
-	{
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_DISCONNECTED);
-		render_ui();
-		swap();
-	}
-	
-	//////////////////////////
-	//
-	// Set rendering options
-	//
-	//
-	LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDER_SETUP);
-	stop_glerror();
-
-	///////////////////////////////////////
-	//
-	// Slam lighting parameters back to our defaults.
-	// Note that these are not the same as GL defaults...
-
-	stop_glerror();
-	gGL.setAmbientLightColor(LLColor4::white);
-	stop_glerror();
-			
-	/////////////////////////////////////
-	//
-	// Render
-	//
-	// Actually push all of our triangles to the screen.
-	//
-
-	// do render-to-texture stuff here
-	if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_DYNAMIC_TEXTURES))
-	{
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_DYN_TEX);
+    //////////////////////////
+    //
+    // clear the next buffer
+    // (must follow dynamic texture writing since that uses the frame buffer)
+    //
+
+    if (gDisconnected)
+    {
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_DISCONNECTED);
+        render_ui();
+        swap();
+    }
+
+    //////////////////////////
+    //
+    // Set rendering options
+    //
+    //
+    LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDER_SETUP);
+    stop_glerror();
+
+    ///////////////////////////////////////
+    //
+    // Slam lighting parameters back to our defaults.
+    // Note that these are not the same as GL defaults...
+
+    stop_glerror();
+    gGL.setAmbientLightColor(LLColor4::white);
+    stop_glerror();
+
+    /////////////////////////////////////
+    //
+    // Render
+    //
+    // Actually push all of our triangles to the screen.
+    //
+
+    // do render-to-texture stuff here
+    if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_DYNAMIC_TEXTURES))
+    {
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_DYN_TEX);
         LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Update Dynamic Textures");
-		if (LLViewerDynamicTexture::updateAllInstances())
-		{
-			gGL.setColorMask(true, true);
-			glClear(GL_DEPTH_BUFFER_BIT);
-		}
-	}
-
-	gViewerWindow->setup3DViewport();
-
-	gPipeline.resetFrameStats();	// Reset per-frame statistics.
-	
-	if (!gDisconnected)
-	{
-		// Render mirrors and associated hero probes before we render the rest of the scene.
-		// This ensures the scene state in the hero probes are exactly the same as the rest of the scene before we render it.
+        if (LLViewerDynamicTexture::updateAllInstances())
+        {
+            gGL.setColorMask(true, true);
+            glClear(GL_DEPTH_BUFFER_BIT);
+        }
+    }
+
+    gViewerWindow->setup3DViewport();
+
+    gPipeline.resetFrameStats();    // Reset per-frame statistics.
+
+    if (!gDisconnected)
+    {
+        // Render mirrors and associated hero probes before we render the rest of the scene.
+        // This ensures the scene state in the hero probes are exactly the same as the rest of the scene before we render it.
         if (gPipeline.RenderMirrors && !gSnapshot && (gPipeline.RenderHeroProbeUpdateRate == 0 || (gFrameCount % gPipeline.RenderHeroProbeUpdateRate) == 0))
         {
             LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Update hero probes");
             gPipeline.mHeroProbeManager.update();
         }
 
-		LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("display - 1");
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_UPDATE);
-		if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD))
-		{ //don't draw hud objects in this frame
-			gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
-		}
-
-		if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD_PARTICLES))
-		{ //don't draw hud particles in this frame
-			gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD_PARTICLES);
-		}
-
-		stop_glerror();
-		display_update_camera();
-		stop_glerror();
-				
-		{
+        LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("display - 1");
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_UPDATE);
+        if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD))
+        { //don't draw hud objects in this frame
+            gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
+        }
+
+        if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD_PARTICLES))
+        { //don't draw hud particles in this frame
+            gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD_PARTICLES);
+        }
+
+        stop_glerror();
+        display_update_camera();
+        stop_glerror();
+
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Env Update");
             // update all the sky/atmospheric/water settings
             LLEnvironment::instance().update(LLViewerCamera::getInstance());
-		}
+        }
 
-		// *TODO: merge these two methods
-		{
+        // *TODO: merge these two methods
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("HUD Update");
-			LLHUDManager::getInstance()->updateEffects();
-			LLHUDObject::updateAll();
-			stop_glerror();
-		}
+            LLHUDManager::getInstance()->updateEffects();
+            LLHUDObject::updateAll();
+            stop_glerror();
+        }
 
-		{
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Update Geom");
-			const F32 max_geom_update_time = 0.005f*10.f*gFrameIntervalSeconds.value(); // 50 ms/second update time
-			gPipeline.createObjects(max_geom_update_time);
-			gPipeline.processPartitionQ();
-			gPipeline.updateGeom(max_geom_update_time);
-			stop_glerror();
-		}
-
-		gPipeline.updateGL();
-
-		stop_glerror();
-
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_CULL);
-		
-		//Increment drawable frame counter
-		LLDrawable::incrementVisible();
-
-		LLSpatialGroup::sNoDelete = TRUE;
-		LLTexUnit::sWhiteTexture = LLViewerFetchedTexture::sWhiteImagep->getTexName();
-
-		S32 occlusion = LLPipeline::sUseOcclusion;
-		if (gDepthDirty)
-		{ //depth buffer is invalid, don't overwrite occlusion state
-			LLPipeline::sUseOcclusion = llmin(occlusion, 1);
-		}
-		gDepthDirty = FALSE;
-
-		LLGLState::checkStates();
-
-		static LLCullResult result;
-		LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
-		LLPipeline::sUnderWaterRender = LLViewerCamera::getInstance()->cameraUnderWater();
-		gPipeline.updateCull(*LLViewerCamera::getInstance(), result);
-		stop_glerror();
-
-		LLGLState::checkStates();
-		
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_SWAP);
-		
-		{ 
-			LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("display - 2")
-			if (gResizeScreenTexture)
-			{
-				gPipeline.resizeScreenTexture();
+            const F32 max_geom_update_time = 0.005f*10.f*gFrameIntervalSeconds.value(); // 50 ms/second update time
+            gPipeline.createObjects(max_geom_update_time);
+            gPipeline.processPartitionQ();
+            gPipeline.updateGeom(max_geom_update_time);
+            stop_glerror();
+        }
+
+        gPipeline.updateGL();
+
+        stop_glerror();
+
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_CULL);
+
+        //Increment drawable frame counter
+        LLDrawable::incrementVisible();
+
+        LLSpatialGroup::sNoDelete = TRUE;
+        LLTexUnit::sWhiteTexture = LLViewerFetchedTexture::sWhiteImagep->getTexName();
+
+        S32 occlusion = LLPipeline::sUseOcclusion;
+        if (gDepthDirty)
+        { //depth buffer is invalid, don't overwrite occlusion state
+            LLPipeline::sUseOcclusion = llmin(occlusion, 1);
+        }
+        gDepthDirty = FALSE;
+
+        LLGLState::checkStates();
+
+        static LLCullResult result;
+        LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
+        LLPipeline::sUnderWaterRender = LLViewerCamera::getInstance()->cameraUnderWater();
+        gPipeline.updateCull(*LLViewerCamera::getInstance(), result);
+        stop_glerror();
+
+        LLGLState::checkStates();
+
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_SWAP);
+
+        {
+            LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("display - 2")
+            if (gResizeScreenTexture)
+            {
+                gPipeline.resizeScreenTexture();
                 gResizeScreenTexture = FALSE;
-			}
+            }
 
-			gGL.setColorMask(true, true);
-			glClearColor(0,0,0,0);
+            gGL.setColorMask(true, true);
+            glClearColor(0,0,0,0);
 
-			LLGLState::checkStates();
+            LLGLState::checkStates();
 
-			if (!for_snapshot)
-			{
+            if (!for_snapshot)
+            {
                 if (gFrameCount > 1 && !for_snapshot)
-                { //for some reason, ATI 4800 series will error out if you 
+                { //for some reason, ATI 4800 series will error out if you
                   //try to generate a shadow before the first frame is through
                     gPipeline.generateSunShadow(*LLViewerCamera::getInstance());
                 }
 
-				LLVertexBuffer::unbind();
+                LLVertexBuffer::unbind();
 
-				LLGLState::checkStates();
+                LLGLState::checkStates();
 
-				LLMatrix4a proj = get_current_projection();
-				LLMatrix4a mod = get_current_modelview();
-				glViewport(0,0,512,512);
+                LLMatrix4a proj = get_current_projection();
+                LLMatrix4a mod = get_current_modelview();
+                glViewport(0,0,512,512);
 
-				LLVOAvatar::updateImpostors();
+                LLVOAvatar::updateImpostors();
 
-				set_current_projection(proj);
-				set_current_modelview(mod);
-				gGL.matrixMode(LLRender::MM_PROJECTION);
-				gGL.loadMatrix(proj);
-				gGL.matrixMode(LLRender::MM_MODELVIEW);
-				gGL.loadMatrix(mod);
-				gViewerWindow->setup3DViewport();
+                set_current_projection(proj);
+                set_current_modelview(mod);
+                gGL.matrixMode(LLRender::MM_PROJECTION);
+                gGL.loadMatrix(proj);
+                gGL.matrixMode(LLRender::MM_MODELVIEW);
+                gGL.loadMatrix(mod);
+                gViewerWindow->setup3DViewport();
 
-				LLGLState::checkStates();
-			}
+                LLGLState::checkStates();
+            }
             glClear(GL_DEPTH_BUFFER_BIT);
-		}
-
-		//////////////////////////////////////
-		//
-		// Update images, using the image stats generated during object update/culling
-		//
-		// Can put objects onto the retextured list.
-		//
-		// Doing this here gives hardware occlusion queries extra time to complete
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_UPDATE_IMAGES);
-		
-		{
+        }
+
+        //////////////////////////////////////
+        //
+        // Update images, using the image stats generated during object update/culling
+        //
+        // Can put objects onto the retextured list.
+        //
+        // Doing this here gives hardware occlusion queries extra time to complete
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_UPDATE_IMAGES);
+
+        {
             LL_PROFILE_ZONE_NAMED("Update Images");
-			
-			{
+
+            {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Class");
-				LLViewerTexture::updateClass();
-			}
+                LLViewerTexture::updateClass();
+            }
 
-			{
+            {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Image Update Bump");
-				gBumpImageList.updateImages();  // must be called before gTextureList version so that it's textures are thrown out first.
-			}
+                gBumpImageList.updateImages();  // must be called before gTextureList version so that it's textures are thrown out first.
+            }
 
-			{
+            {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("List");
-				F32 max_image_decode_time = 0.050f*gFrameIntervalSeconds.value(); // 50 ms/second decode time
-				max_image_decode_time = llclamp(max_image_decode_time, 0.002f, 0.005f ); // min 2ms/frame, max 5ms/frame)
-				gTextureList.updateImages(max_image_decode_time);
-			}
+                F32 max_image_decode_time = 0.050f*gFrameIntervalSeconds.value(); // 50 ms/second decode time
+                max_image_decode_time = llclamp(max_image_decode_time, 0.002f, 0.005f ); // min 2ms/frame, max 5ms/frame)
+                gTextureList.updateImages(max_image_decode_time);
+            }
 
-			{
+            {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("GLTF Materials Cleanup");
-				//remove dead gltf materials
+                //remove dead gltf materials
                 gGLTFMaterialList.flushMaterials();
-			}
-		}
-
-		LLGLState::checkStates();
-
-		///////////////////////////////////
-		//
-		// StateSort
-		//
-		// Responsible for taking visible objects, and adding them to the appropriate draw orders.
-		// In the case of alpha objects, z-sorts them first.
-		// Also creates special lists for outlines and selected face rendering.
-		//
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_STATE_SORT);
-		{
-			LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("display - 4")
-			LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
-			gPipeline.stateSort(*LLViewerCamera::getInstance(), result);
-			stop_glerror();
-				
-			if (rebuild)
-			{
-				//////////////////////////////////////
-				//
-				// rebuildPools
-				//
-				//
-				gPipeline.rebuildPools();
-				stop_glerror();
-			}
-		}
-
-		LLSceneMonitor::getInstance()->fetchQueryResult();
-		
-		LLGLState::checkStates();
-
-		LLPipeline::sUseOcclusion = occlusion;
-
-		{
-			LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_SKY);
-			LL_PROFILE_ZONE_NAMED_CATEGORY_ENVIRONMENT("update sky"); //LL_RECORD_BLOCK_TIME(FTM_UPDATE_SKY);	
-			gSky.updateSky();
-		}
-
-		if(gUseWireframe)
-		{
-			glClearColor(0.5f, 0.5f, 0.5f, 0.f);
-			glClear(GL_COLOR_BUFFER_BIT);
-		}
-
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDER_START);
-		
-		//// render frontmost floater opaque for occlusion culling purposes
-		//LLFloater* frontmost_floaterp = gFloaterView->getFrontmost();
-		//// assumes frontmost floater with focus is opaque
-		//if (frontmost_floaterp && gFocusMgr.childHasKeyboardFocus(frontmost_floaterp))
-		//{
-		//	gGL.matrixMode(LLRender::MM_MODELVIEW);
-		//	gGL.pushMatrix();
-		//	{
-		//		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-		//		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
-		//		gGL.loadIdentity();
-
-		//		LLRect floater_rect = frontmost_floaterp->calcScreenRect();
-		//		// deflate by one pixel so rounding errors don't occlude outside of floater extents
-		//		floater_rect.stretch(-1);
-		//		LLRectf floater_3d_rect((F32)floater_rect.mLeft / (F32)gViewerWindow->getWindowWidthScaled(), 
-		//								(F32)floater_rect.mTop / (F32)gViewerWindow->getWindowHeightScaled(),
-		//								(F32)floater_rect.mRight / (F32)gViewerWindow->getWindowWidthScaled(),
-		//								(F32)floater_rect.mBottom / (F32)gViewerWindow->getWindowHeightScaled());
-		//		floater_3d_rect.translate(-0.5f, -0.5f);
-		//		gGL.translatef(0.f, 0.f, -vwrCamera.getNear());
-		//		gGL.scalef(vwrCamera.getNear() * vwrCamera.getAspect() / sinf(vwrCamera.getView()), vwrCamera.getNear() / sinf(vwrCamera.getView()), 1.f);
-		//		gGL.color4fv(LLColor4::white.mV);
-		//		gGL.begin(LLVertexBuffer::QUADS);
-		//		{
-		//			gGL.vertex3f(floater_3d_rect.mLeft, floater_3d_rect.mBottom, 0.f);
-		//			gGL.vertex3f(floater_3d_rect.mLeft, floater_3d_rect.mTop, 0.f);
-		//			gGL.vertex3f(floater_3d_rect.mRight, floater_3d_rect.mTop, 0.f);
-		//			gGL.vertex3f(floater_3d_rect.mRight, floater_3d_rect.mBottom, 0.f);
-		//		}
-		//		gGL.end();
-		//		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-		//	}
-		//	gGL.popMatrix();
-		//}
-
-		LLPipeline::sUnderWaterRender = LLViewerCamera::getInstance()->cameraUnderWater() ? TRUE : FALSE;
-
-		LLGLState::checkStates();
-
-		stop_glerror();
+            }
+        }
+
+        LLGLState::checkStates();
+
+        ///////////////////////////////////
+        //
+        // StateSort
+        //
+        // Responsible for taking visible objects, and adding them to the appropriate draw orders.
+        // In the case of alpha objects, z-sorts them first.
+        // Also creates special lists for outlines and selected face rendering.
+        //
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_STATE_SORT);
+        {
+            LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("display - 4")
+            LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
+            gPipeline.stateSort(*LLViewerCamera::getInstance(), result);
+            stop_glerror();
+
+            if (rebuild)
+            {
+                //////////////////////////////////////
+                //
+                // rebuildPools
+                //
+                //
+                gPipeline.rebuildPools();
+                stop_glerror();
+            }
+        }
+
+        LLSceneMonitor::getInstance()->fetchQueryResult();
+
+        LLGLState::checkStates();
+
+        LLPipeline::sUseOcclusion = occlusion;
+
+        {
+            LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_SKY);
+            LL_PROFILE_ZONE_NAMED_CATEGORY_ENVIRONMENT("update sky"); //LL_RECORD_BLOCK_TIME(FTM_UPDATE_SKY);
+            gSky.updateSky();
+        }
+
+        if(gUseWireframe)
+        {
+            glClearColor(0.5f, 0.5f, 0.5f, 0.f);
+            glClear(GL_COLOR_BUFFER_BIT);
+        }
+
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDER_START);
+
+        //// render frontmost floater opaque for occlusion culling purposes
+        //LLFloater* frontmost_floaterp = gFloaterView->getFrontmost();
+        //// assumes frontmost floater with focus is opaque
+        //if (frontmost_floaterp && gFocusMgr.childHasKeyboardFocus(frontmost_floaterp))
+        //{
+        //  gGL.matrixMode(LLRender::MM_MODELVIEW);
+        //  gGL.pushMatrix();
+        //  {
+        //      gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+
+        //      glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
+        //      gGL.loadIdentity();
+
+        //      LLRect floater_rect = frontmost_floaterp->calcScreenRect();
+        //      // deflate by one pixel so rounding errors don't occlude outside of floater extents
+        //      floater_rect.stretch(-1);
+        //      LLRectf floater_3d_rect((F32)floater_rect.mLeft / (F32)gViewerWindow->getWindowWidthScaled(),
+        //                              (F32)floater_rect.mTop / (F32)gViewerWindow->getWindowHeightScaled(),
+        //                              (F32)floater_rect.mRight / (F32)gViewerWindow->getWindowWidthScaled(),
+        //                              (F32)floater_rect.mBottom / (F32)gViewerWindow->getWindowHeightScaled());
+        //      floater_3d_rect.translate(-0.5f, -0.5f);
+        //      gGL.translatef(0.f, 0.f, -vwrCamera.getNear());
+        //      gGL.scalef(vwrCamera.getNear() * vwrCamera.getAspect() / sinf(vwrCamera.getView()), vwrCamera.getNear() / sinf(vwrCamera.getView()), 1.f);
+        //      gGL.color4fv(LLColor4::white.mV);
+        //      gGL.begin(LLVertexBuffer::QUADS);
+        //      {
+        //          gGL.vertex3f(floater_3d_rect.mLeft, floater_3d_rect.mBottom, 0.f);
+        //          gGL.vertex3f(floater_3d_rect.mLeft, floater_3d_rect.mTop, 0.f);
+        //          gGL.vertex3f(floater_3d_rect.mRight, floater_3d_rect.mTop, 0.f);
+        //          gGL.vertex3f(floater_3d_rect.mRight, floater_3d_rect.mBottom, 0.f);
+        //      }
+        //      gGL.end();
+        //      glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+        //  }
+        //  gGL.popMatrix();
+        //}
+
+        LLPipeline::sUnderWaterRender = LLViewerCamera::getInstance()->cameraUnderWater() ? TRUE : FALSE;
+
+        LLGLState::checkStates();
+
+        stop_glerror();
 
         gGL.setColorMask(true, true);
 
@@ -968,96 +968,96 @@ void display(BOOL rebuild, F32 zoom_factor, int subfield, BOOL for_snapshot)
 
         gGL.setColorMask(true, false);
 
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDER_GEOM);
-		
-		if (!(LLAppViewer::instance()->logoutRequestSent() && LLAppViewer::instance()->hasSavedFinalSnapshot())
-				&& !gRestoreGL)
-		{
-			LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("display - 5")
-			LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
-
-			static LLCachedControl<bool> renderDepthPrePass(gSavedSettings, "RenderDepthPrePass");
-			if (renderDepthPrePass)
-			{
-				gGL.setColorMask(false, false);
-
-				static const U32 types[] = { 
-					LLRenderPass::PASS_SIMPLE, 
-					LLRenderPass::PASS_FULLBRIGHT, 
-					LLRenderPass::PASS_SHINY 
-				};
-
-				U32 num_types = LL_ARRAY_SIZE(types);
-				gOcclusionProgram.bind();
-				for (U32 i = 0; i < num_types; i++)
-				{
-					gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, FALSE);
-				}
-
-				gOcclusionProgram.unbind();
-
-			}
-
-			gGL.setColorMask(true, true);
-			gPipeline.renderGeomDeferred(*LLViewerCamera::getInstance(), true);
-		}
-
-		{
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDER_GEOM);
+
+        if (!(LLAppViewer::instance()->logoutRequestSent() && LLAppViewer::instance()->hasSavedFinalSnapshot())
+                && !gRestoreGL)
+        {
+            LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("display - 5")
+            LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
+
+            static LLCachedControl<bool> renderDepthPrePass(gSavedSettings, "RenderDepthPrePass");
+            if (renderDepthPrePass)
+            {
+                gGL.setColorMask(false, false);
+
+                static const U32 types[] = {
+                    LLRenderPass::PASS_SIMPLE,
+                    LLRenderPass::PASS_FULLBRIGHT,
+                    LLRenderPass::PASS_SHINY
+                };
+
+                U32 num_types = LL_ARRAY_SIZE(types);
+                gOcclusionProgram.bind();
+                for (U32 i = 0; i < num_types; i++)
+                {
+                    gPipeline.renderObjects(types[i], LLVertexBuffer::MAP_VERTEX, FALSE);
+                }
+
+                gOcclusionProgram.unbind();
+
+            }
+
+            gGL.setColorMask(true, true);
+            gPipeline.renderGeomDeferred(*LLViewerCamera::getInstance(), true);
+        }
+
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Texture Unbind");
-			for (U32 i = 0; i < gGLManager.mNumTextureImageUnits; i++)
-			{ //dummy cleanup of any currently bound textures
-				if (gGL.getTexUnit(i)->getCurrType() != LLTexUnit::TT_NONE)
-				{
-					gGL.getTexUnit(i)->unbind(gGL.getTexUnit(i)->getCurrType());
-					gGL.getTexUnit(i)->disable();
-				}
-			}
-		}
-
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDER_FLUSH);
+            for (U32 i = 0; i < gGLManager.mNumTextureImageUnits; i++)
+            { //dummy cleanup of any currently bound textures
+                if (gGL.getTexUnit(i)->getCurrType() != LLTexUnit::TT_NONE)
+                {
+                    gGL.getTexUnit(i)->unbind(gGL.getTexUnit(i)->getCurrType());
+                    gGL.getTexUnit(i)->disable();
+                }
+            }
+        }
+
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDER_FLUSH);
 
         LLRenderTarget &rt = (gPipeline.sRenderDeferred ? gPipeline.mRT->deferredScreen : gPipeline.mRT->screen);
         rt.flush();
 
         if (LLPipeline::sRenderDeferred)
         {
-			gPipeline.renderDeferredLighting();
-		}
-
-		LLPipeline::sUnderWaterRender = FALSE;
-
-		{
-			//capture the frame buffer.
-			LLSceneMonitor::getInstance()->capture();
-		}
-
-		LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDERUI);
-		if (!for_snapshot)
-		{
-			render_ui();
-			swap();
-		}
-
-		
-		LLSpatialGroup::sNoDelete = FALSE;
-		gPipeline.clearReferences();
-	}
-
-	LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_FRAME_STATS);
-	
-	stop_glerror();
-
-	display_stats();
-				
-	LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_DONE);
-
-	gShiftFrame = false;
-
-	if (gShaderProfileFrame)
-	{
-		gShaderProfileFrame = FALSE;
-		LLGLSLShader::finishProfile();
-	}
+            gPipeline.renderDeferredLighting();
+        }
+
+        LLPipeline::sUnderWaterRender = FALSE;
+
+        {
+            //capture the frame buffer.
+            LLSceneMonitor::getInstance()->capture();
+        }
+
+        LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_RENDERUI);
+        if (!for_snapshot)
+        {
+            render_ui();
+            swap();
+        }
+
+
+        LLSpatialGroup::sNoDelete = FALSE;
+        gPipeline.clearReferences();
+    }
+
+    LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_FRAME_STATS);
+
+    stop_glerror();
+
+    display_stats();
+
+    LLAppViewer::instance()->pingMainloopTimeout(STR_DISPLAY_DONE);
+
+    gShiftFrame = false;
+
+    if (gShaderProfileFrame)
+    {
+        gShaderProfileFrame = FALSE;
+        LLGLSLShader::finishProfile();
+    }
 }
 
 // WIP simplified copy of display() that does minimal work
@@ -1104,7 +1104,7 @@ void display_cube_face()
     }
 
     LLSpatialGroup::sNoDelete = TRUE;
-        
+
     S32 occlusion = LLPipeline::sUseOcclusion;
     LLPipeline::sUseOcclusion = 1; // occlusion data is from main camera point of view, don't read or write it during cube snapshots
     //gDepthDirty = TRUE; //let "real" render pipe know it can't trust the depth buffer for occlusion data
@@ -1118,7 +1118,7 @@ void display_cube_face()
 
     glClearColor(0, 0, 0, 0);
     gPipeline.generateSunShadow(*LLViewerCamera::getInstance());
-        
+
     glClear(GL_DEPTH_BUFFER_BIT); // | GL_STENCIL_BUFFER_BIT);
 
     {
@@ -1136,7 +1136,7 @@ void display_cube_face()
             stop_glerror();
         }
     }
-    
+
     LLPipeline::sUseOcclusion = occlusion;
 
     LLAppViewer::instance()->pingMainloopTimeout("Display:RenderStart");
@@ -1155,13 +1155,13 @@ void display_cube_face()
         glClearColor(1, 0, 1, 1);
     }
     gPipeline.mRT->deferredScreen.clear();
-        
+
     LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
 
     gPipeline.renderGeomDeferred(*LLViewerCamera::getInstance());
 
     gPipeline.mRT->deferredScreen.flush();
-       
+
     gPipeline.renderDeferredLighting();
 
     LLPipeline::sUnderWaterRender = FALSE;
@@ -1177,203 +1177,203 @@ void render_hud_attachments()
 {
     LLPerfStats::RecordSceneTime T ( LLPerfStats::StatType_t::RENDER_HUDS); // render time capture - Primary contributor to HUDs (though these end up in render batches)
     gGL.matrixMode(LLRender::MM_PROJECTION);
-	gGL.pushMatrix();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.pushMatrix();
-		
-	LLMatrix4a current_proj = get_current_projection();
-	LLMatrix4a current_mod = get_current_modelview();
-
-	// clamp target zoom level to reasonable values
-//	gAgentCamera.mHUDTargetZoom = llclamp(gAgentCamera.mHUDTargetZoom, 0.1f, 1.f);
+    gGL.pushMatrix();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+
+    LLMatrix4a current_proj = get_current_projection();
+    LLMatrix4a current_mod = get_current_modelview();
+
+    // clamp target zoom level to reasonable values
+//  gAgentCamera.mHUDTargetZoom = llclamp(gAgentCamera.mHUDTargetZoom, 0.1f, 1.f);
 // [RLVa:KB] - Checked: 2010-08-22 (RLVa-1.2.1a) | Modified: RLVa-1.0.0c
-	gAgentCamera.mHUDTargetZoom = llclamp(gAgentCamera.mHUDTargetZoom, (!gRlvAttachmentLocks.hasLockedHUD()) ? 0.1f : 0.85f, 1.f);
+    gAgentCamera.mHUDTargetZoom = llclamp(gAgentCamera.mHUDTargetZoom, (!gRlvAttachmentLocks.hasLockedHUD()) ? 0.1f : 0.85f, 1.f);
 // [/RLVa:KB]
 
-	// smoothly interpolate current zoom level
-	gAgentCamera.mHUDCurZoom = ll_lerp(gAgentCamera.mHUDCurZoom, gAgentCamera.getAgentHUDTargetZoom(), LLSmoothInterpolation::getInterpolant(0.03f));
-
-	if (!ALCinematicMode::isEnabled() && LLPipeline::sShowHUDAttachments && !gDisconnected && setup_hud_matrices())
-	{
-		LLPipeline::sRenderingHUDs = TRUE;
-		LLCamera hud_cam = LLViewerCamera::instance();
-		hud_cam.setOrigin(-1.f,0,0);
-		hud_cam.setAxes(LLVector3(1,0,0), LLVector3(0,1,0), LLVector3(0,0,1));
-		LLViewerCamera::updateFrustumPlanes(hud_cam, TRUE);
-
-		static LLCachedControl<bool> renderHUDParticles(gSavedSettings, "RenderHUDParticles");
-		bool render_particles = (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES) && renderHUDParticles);
-		
-		//only render hud objects
-		gPipeline.pushRenderTypeMask();
-		
-		// turn off everything
-		gPipeline.andRenderTypeMask(LLPipeline::END_RENDER_TYPES);
-		// turn on HUD
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
-		// turn on HUD particles
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD_PARTICLES);
-
-		// if particles are off, turn off hud-particles as well
-		if (!render_particles)
-		{
-			// turn back off HUD particles
-			gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD_PARTICLES);
-		}
-
-		bool has_ui = gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI);
-		if (has_ui)
-		{
-			gPipeline.toggleRenderDebugFeature(LLPipeline::RENDER_DEBUG_FEATURE_UI);
-		}
-
-		S32 use_occlusion = LLPipeline::sUseOcclusion;
-		LLPipeline::sUseOcclusion = 0;
-				
-		//cull, sort, and render hud objects
-		static LLCullResult result;
-		LLSpatialGroup::sNoDelete = TRUE;
-
-		LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
-		gPipeline.updateCull(hud_cam, result);
+    // smoothly interpolate current zoom level
+    gAgentCamera.mHUDCurZoom = ll_lerp(gAgentCamera.mHUDCurZoom, gAgentCamera.getAgentHUDTargetZoom(), LLSmoothInterpolation::getInterpolant(0.03f));
+
+    if (!ALCinematicMode::isEnabled() && LLPipeline::sShowHUDAttachments && !gDisconnected && setup_hud_matrices())
+    {
+        LLPipeline::sRenderingHUDs = TRUE;
+        LLCamera hud_cam = LLViewerCamera::instance();
+        hud_cam.setOrigin(-1.f,0,0);
+        hud_cam.setAxes(LLVector3(1,0,0), LLVector3(0,1,0), LLVector3(0,0,1));
+        LLViewerCamera::updateFrustumPlanes(hud_cam, TRUE);
+
+        static LLCachedControl<bool> renderHUDParticles(gSavedSettings, "RenderHUDParticles");
+        bool render_particles = (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_PARTICLES) && renderHUDParticles);
+
+        //only render hud objects
+        gPipeline.pushRenderTypeMask();
+
+        // turn off everything
+        gPipeline.andRenderTypeMask(LLPipeline::END_RENDER_TYPES);
+        // turn on HUD
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
+        // turn on HUD particles
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD_PARTICLES);
+
+        // if particles are off, turn off hud-particles as well
+        if (!render_particles)
+        {
+            // turn back off HUD particles
+            gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD_PARTICLES);
+        }
+
+        bool has_ui = gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI);
+        if (has_ui)
+        {
+            gPipeline.toggleRenderDebugFeature(LLPipeline::RENDER_DEBUG_FEATURE_UI);
+        }
+
+        S32 use_occlusion = LLPipeline::sUseOcclusion;
+        LLPipeline::sUseOcclusion = 0;
+
+        //cull, sort, and render hud objects
+        static LLCullResult result;
+        LLSpatialGroup::sNoDelete = TRUE;
+
+        LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
+        gPipeline.updateCull(hud_cam, result);
 
         // Toggle render types
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_BUMP);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_SIMPLE);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_VOLUME);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_ALPHA);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_BUMP);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_SIMPLE);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_VOLUME);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_ALPHA);
         gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_ALPHA_PRE_WATER);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_ALPHA_MASK);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_FULLBRIGHT);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_ALPHA_MASK);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_FULLBRIGHT);
         gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_GLTF_PBR);
         gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_GLTF_PBR_ALPHA_MASK);
 
         // Toggle render passes
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_ALPHA);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_BUMP);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_MATERIAL);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_SHINY);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_INVISIBLE);
-		gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_ALPHA);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_BUMP);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_MATERIAL);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_SHINY);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_INVISIBLE);
+        gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY);
         gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_GLTF_PBR);
         gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_ALPHA_MASK);
-		
-		gPipeline.stateSort(hud_cam, result);
-
-		gPipeline.renderGeomPostDeferred(hud_cam);
-
-		LLSpatialGroup::sNoDelete = FALSE;
-		//gPipeline.clearReferences();
-
-		render_hud_elements();
-
-		//restore type mask
-		gPipeline.popRenderTypeMask();
-
-		if (has_ui)
-		{
-			gPipeline.toggleRenderDebugFeature(LLPipeline::RENDER_DEBUG_FEATURE_UI);
-		}
-		LLPipeline::sUseOcclusion = use_occlusion;
-		LLPipeline::sRenderingHUDs = FALSE;
-	}
-	gGL.matrixMode(LLRender::MM_PROJECTION);
-	gGL.popMatrix();
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.popMatrix();
-	
-	set_current_projection(current_proj);
-	set_current_modelview(current_mod);
+
+        gPipeline.stateSort(hud_cam, result);
+
+        gPipeline.renderGeomPostDeferred(hud_cam);
+
+        LLSpatialGroup::sNoDelete = FALSE;
+        //gPipeline.clearReferences();
+
+        render_hud_elements();
+
+        //restore type mask
+        gPipeline.popRenderTypeMask();
+
+        if (has_ui)
+        {
+            gPipeline.toggleRenderDebugFeature(LLPipeline::RENDER_DEBUG_FEATURE_UI);
+        }
+        LLPipeline::sUseOcclusion = use_occlusion;
+        LLPipeline::sRenderingHUDs = FALSE;
+    }
+    gGL.matrixMode(LLRender::MM_PROJECTION);
+    gGL.popMatrix();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.popMatrix();
+
+    set_current_projection(current_proj);
+    set_current_modelview(current_mod);
 }
 
 LLRect get_whole_screen_region()
 {
-	LLRect whole_screen = gViewerWindow->getWorldViewRectScaled();
-	
-	// apply camera zoom transform (for high res screenshots)
-	auto& vwrCamera = LLViewerCamera::instance();
-	F32 zoom_factor = vwrCamera.getZoomFactor();
-	S16 sub_region = vwrCamera.getZoomSubRegion();
-	if (zoom_factor > 1.f)
-	{
-		S32 num_horizontal_tiles = llceil(zoom_factor);
-		S32 tile_width = ll_round((F32)gViewerWindow->getWorldViewWidthScaled() / zoom_factor);
-		S32 tile_height = ll_round((F32)gViewerWindow->getWorldViewHeightScaled() / zoom_factor);
-		int tile_y = sub_region / num_horizontal_tiles;
-		int tile_x = sub_region - (tile_y * num_horizontal_tiles);
-			
-		whole_screen.setLeftTopAndSize(tile_x * tile_width, gViewerWindow->getWorldViewHeightScaled() - (tile_y * tile_height), tile_width, tile_height);
-	}
-	return whole_screen;
+    LLRect whole_screen = gViewerWindow->getWorldViewRectScaled();
+
+    // apply camera zoom transform (for high res screenshots)
+    auto& vwrCamera = LLViewerCamera::instance();
+    F32 zoom_factor = vwrCamera.getZoomFactor();
+    S16 sub_region = vwrCamera.getZoomSubRegion();
+    if (zoom_factor > 1.f)
+    {
+        S32 num_horizontal_tiles = llceil(zoom_factor);
+        S32 tile_width = ll_round((F32)gViewerWindow->getWorldViewWidthScaled() / zoom_factor);
+        S32 tile_height = ll_round((F32)gViewerWindow->getWorldViewHeightScaled() / zoom_factor);
+        int tile_y = sub_region / num_horizontal_tiles;
+        int tile_x = sub_region - (tile_y * num_horizontal_tiles);
+
+        whole_screen.setLeftTopAndSize(tile_x * tile_width, gViewerWindow->getWorldViewHeightScaled() - (tile_y * tile_height), tile_width, tile_height);
+    }
+    return whole_screen;
 }
 
 bool get_hud_matrices(const LLRect& screen_region, LLMatrix4a &proj, LLMatrix4a &model)
 {
-	if (isAgentAvatarValid() && gAgentAvatarp->hasHUDAttachment())
-	{
-		auto& vwrCamera = LLViewerCamera::instance();
-		F32 zoom_level = gAgentCamera.mHUDCurZoom;
-		LLBBox hud_bbox = gAgentAvatarp->getHUDBBox();
-		
-		F32 hud_depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
-		proj = ALGLMath::genOrtho(-0.5f * vwrCamera.getAspect(), 0.5f * vwrCamera.getAspect(), -0.5f, 0.5f, 0.f, hud_depth);
-		proj.getRow<2>().copyComponent<2>(LLVector4a(-0.01f));
-
-		F32 aspect_ratio = LLViewerCamera::getInstance()->getAspect();
-		
-		F32 scale_x = (F32)gViewerWindow->getWorldViewWidthScaled() / (F32)screen_region.getWidth();
-		F32 scale_y = (F32)gViewerWindow->getWorldViewHeightScaled() / (F32)screen_region.getHeight();
-
-		proj.applyTranslation_affine(
-			clamp_rescale((F32)(screen_region.getCenterX() - screen_region.mLeft), 0.f, (F32)gViewerWindow->getWorldViewWidthScaled(), 0.5f * scale_x * aspect_ratio, -0.5f * scale_x * aspect_ratio),
-			clamp_rescale((F32)(screen_region.getCenterY() - screen_region.mBottom), 0.f, (F32)gViewerWindow->getWorldViewHeightScaled(), 0.5f * scale_y, -0.5f * scale_y),
-			0.f);
-		proj.applyScale_affine(scale_x, scale_y, 1.f);
-
-		model = OGL_TO_CFR_ROTATION_4A;
-		model.applyTranslation_affine(LLVector3(-hud_bbox.getCenterLocal().mV[VX] + (hud_depth * 0.5f), 0.f, 0.f));
-		model.applyScale_affine(zoom_level);
-
-		return TRUE;
-	}
-	else
-	{
-		return FALSE;
-	}
+    if (isAgentAvatarValid() && gAgentAvatarp->hasHUDAttachment())
+    {
+        auto& vwrCamera = LLViewerCamera::instance();
+        F32 zoom_level = gAgentCamera.mHUDCurZoom;
+        LLBBox hud_bbox = gAgentAvatarp->getHUDBBox();
+
+        F32 hud_depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
+        proj = ALGLMath::genOrtho(-0.5f * vwrCamera.getAspect(), 0.5f * vwrCamera.getAspect(), -0.5f, 0.5f, 0.f, hud_depth);
+        proj.getRow<2>().copyComponent<2>(LLVector4a(-0.01f));
+
+        F32 aspect_ratio = LLViewerCamera::getInstance()->getAspect();
+
+        F32 scale_x = (F32)gViewerWindow->getWorldViewWidthScaled() / (F32)screen_region.getWidth();
+        F32 scale_y = (F32)gViewerWindow->getWorldViewHeightScaled() / (F32)screen_region.getHeight();
+
+        proj.applyTranslation_affine(
+            clamp_rescale((F32)(screen_region.getCenterX() - screen_region.mLeft), 0.f, (F32)gViewerWindow->getWorldViewWidthScaled(), 0.5f * scale_x * aspect_ratio, -0.5f * scale_x * aspect_ratio),
+            clamp_rescale((F32)(screen_region.getCenterY() - screen_region.mBottom), 0.f, (F32)gViewerWindow->getWorldViewHeightScaled(), 0.5f * scale_y, -0.5f * scale_y),
+            0.f);
+        proj.applyScale_affine(scale_x, scale_y, 1.f);
+
+        model = OGL_TO_CFR_ROTATION_4A;
+        model.applyTranslation_affine(LLVector3(-hud_bbox.getCenterLocal().mV[VX] + (hud_depth * 0.5f), 0.f, 0.f));
+        model.applyScale_affine(zoom_level);
+
+        return TRUE;
+    }
+    else
+    {
+        return FALSE;
+    }
 }
 
 bool get_hud_matrices(LLMatrix4a &proj, LLMatrix4a &model)
 {
-	LLRect whole_screen = get_whole_screen_region();
-	return get_hud_matrices(whole_screen, proj, model);
+    LLRect whole_screen = get_whole_screen_region();
+    return get_hud_matrices(whole_screen, proj, model);
 }
 
 bool setup_hud_matrices()
 {
-	LLRect whole_screen = get_whole_screen_region();
-	return setup_hud_matrices(whole_screen);
+    LLRect whole_screen = get_whole_screen_region();
+    return setup_hud_matrices(whole_screen);
 }
 
 bool setup_hud_matrices(const LLRect& screen_region)
 {
-	LLMatrix4a proj, model;
-	bool result = get_hud_matrices(screen_region, proj, model);
-	if (!result) return result;
-	
-	// set up transform to keep HUD objects in front of camera
-	gGL.matrixMode(LLRender::MM_PROJECTION);
-	gGL.loadMatrix(proj);
-	set_current_projection(proj);
-	
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.loadMatrix(model);
-	set_current_modelview(model);
-	return TRUE;
+    LLMatrix4a proj, model;
+    bool result = get_hud_matrices(screen_region, proj, model);
+    if (!result) return result;
+
+    // set up transform to keep HUD objects in front of camera
+    gGL.matrixMode(LLRender::MM_PROJECTION);
+    gGL.loadMatrix(proj);
+    set_current_projection(proj);
+
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.loadMatrix(model);
+    set_current_modelview(model);
+    return TRUE;
 }
 
 void render_ui(F32 zoom_factor, int subfield)
@@ -1381,51 +1381,51 @@ void render_ui(F32 zoom_factor, int subfield)
     LLPerfStats::RecordSceneTime T ( LLPerfStats::StatType_t::RENDER_UI ); // render time capture - Primary UI stat can have HUD time overlap (TODO)
     LL_PROFILE_ZONE_SCOPED_CATEGORY_UI; //LL_RECORD_BLOCK_TIME(FTM_RENDER_UI);
     LL_PROFILE_GPU_ZONE("ui");
-	LLGLState::checkStates();
-	
-	LLMatrix4a saved_view = get_current_modelview();
-
-	if (!gSnapshot)
-	{
-		gGL.pushMatrix();
-		gGL.loadMatrix(gGLLastModelView);
-		set_current_modelview(get_last_modelview());
-	}
-	
-	if(LLSceneMonitor::getInstance()->needsUpdate())
-	{
-		gGL.pushMatrix();
-		gViewerWindow->setup2DRender();
-		LLSceneMonitor::getInstance()->compare();
-		gViewerWindow->setup3DRender();
-		gGL.popMatrix();
-	}
+    LLGLState::checkStates();
+
+    LLMatrix4a saved_view = get_current_modelview();
+
+    if (!gSnapshot)
+    {
+        gGL.pushMatrix();
+        gGL.loadMatrix(gGLLastModelView);
+        set_current_modelview(get_last_modelview());
+    }
+
+    if(LLSceneMonitor::getInstance()->needsUpdate())
+    {
+        gGL.pushMatrix();
+        gViewerWindow->setup2DRender();
+        LLSceneMonitor::getInstance()->compare();
+        gViewerWindow->setup3DRender();
+        gGL.popMatrix();
+    }
 
     // apply gamma correction and post effects
     gPipeline.renderFinalize();
 
-	{
+    {
         LLGLState::checkStates();
 
 
         LL_PROFILE_ZONE_NAMED_CATEGORY_UI("HUD");
-		render_hud_elements();
+        render_hud_elements();
         LLGLState::checkStates();
 // [RLVa:KB] - Checked: RLVa-2.2 (@setoverlay)
-		if (RlvActions::hasBehaviour(RLV_BHVR_SETOVERLAY))
-		{
-			LLVfxManager::instance().runEffect(EVisualEffect::RlvOverlay);
-		}
+        if (RlvActions::hasBehaviour(RLV_BHVR_SETOVERLAY))
+        {
+            LLVfxManager::instance().runEffect(EVisualEffect::RlvOverlay);
+        }
 // [/RLVa:KB]
-		render_hud_attachments();
+        render_hud_attachments();
 
         LLGLState::checkStates();
 
-		LLGLSDefault gls_default;
-		LLGLSUIDefault gls_ui;
-		{
-			gPipeline.disableLights();
-		}
+        LLGLSDefault gls_default;
+        LLGLSUIDefault gls_ui;
+        {
+            gPipeline.disableLights();
+        }
 
         bool render_ui = gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI);
         if (render_ui)
@@ -1453,13 +1453,13 @@ void render_ui(F32 zoom_factor, int subfield)
         gViewerWindow->setup2DRender();
         gViewerWindow->updateDebugText();
         gViewerWindow->drawDebugText();
-	}
+    }
 
-	if (!gSnapshot)
-	{
-		set_current_modelview(saved_view);
-		gGL.popMatrix();
-	}
+    if (!gSnapshot)
+    {
+        set_current_modelview(saved_view);
+        gGL.popMatrix();
+    }
 }
 
 void swap()
@@ -1467,113 +1467,113 @@ void swap()
     LLPerfStats::RecordSceneTime T ( LLPerfStats::StatType_t::RENDER_SWAP ); // render time capture - Swap buffer time - can signify excessive data transfer to/from GPU
     LL_PROFILE_ZONE_NAMED_CATEGORY_DISPLAY("Swap");
     LL_PROFILE_GPU_ZONE("swap");
-	if (gDisplaySwapBuffers)
-	{
-		gViewerWindow->getWindow()->swapBuffers();
-	}
-	gDisplaySwapBuffers = TRUE;
+    if (gDisplaySwapBuffers)
+    {
+        gViewerWindow->getWindow()->swapBuffers();
+    }
+    gDisplaySwapBuffers = TRUE;
 }
 
 void renderCoordinateAxes()
 {
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.begin(LLRender::LINES);
-		gGL.color3f(1.0f, 0.0f, 0.0f);   // i direction = X-Axis = red
-		gGL.vertex3f(0.0f, 0.0f, 0.0f);
-		gGL.vertex3f(2.0f, 0.0f, 0.0f);
-		gGL.vertex3f(3.0f, 0.0f, 0.0f);
-		gGL.vertex3f(5.0f, 0.0f, 0.0f);
-		gGL.vertex3f(6.0f, 0.0f, 0.0f);
-		gGL.vertex3f(8.0f, 0.0f, 0.0f);
-		// Make an X
-		gGL.vertex3f(11.0f, 1.0f, 1.0f);
-		gGL.vertex3f(11.0f, -1.0f, -1.0f);
-		gGL.vertex3f(11.0f, 1.0f, -1.0f);
-		gGL.vertex3f(11.0f, -1.0f, 1.0f);
-
-		gGL.color3f(0.0f, 1.0f, 0.0f);   // j direction = Y-Axis = green
-		gGL.vertex3f(0.0f, 0.0f, 0.0f);
-		gGL.vertex3f(0.0f, 2.0f, 0.0f);
-		gGL.vertex3f(0.0f, 3.0f, 0.0f);
-		gGL.vertex3f(0.0f, 5.0f, 0.0f);
-		gGL.vertex3f(0.0f, 6.0f, 0.0f);
-		gGL.vertex3f(0.0f, 8.0f, 0.0f);
-		// Make a Y
-		gGL.vertex3f(1.0f, 11.0f, 1.0f);
-		gGL.vertex3f(0.0f, 11.0f, 0.0f);
-		gGL.vertex3f(-1.0f, 11.0f, 1.0f);
-		gGL.vertex3f(0.0f, 11.0f, 0.0f);
-		gGL.vertex3f(0.0f, 11.0f, 0.0f);
-		gGL.vertex3f(0.0f, 11.0f, -1.0f);
-
-		gGL.color3f(0.0f, 0.0f, 1.0f);   // Z-Axis = blue
-		gGL.vertex3f(0.0f, 0.0f, 0.0f);
-		gGL.vertex3f(0.0f, 0.0f, 2.0f);
-		gGL.vertex3f(0.0f, 0.0f, 3.0f);
-		gGL.vertex3f(0.0f, 0.0f, 5.0f);
-		gGL.vertex3f(0.0f, 0.0f, 6.0f);
-		gGL.vertex3f(0.0f, 0.0f, 8.0f);
-		// Make a Z
-		gGL.vertex3f(-1.0f, 1.0f, 11.0f);
-		gGL.vertex3f(1.0f, 1.0f, 11.0f);
-		gGL.vertex3f(1.0f, 1.0f, 11.0f);
-		gGL.vertex3f(-1.0f, -1.0f, 11.0f);
-		gGL.vertex3f(-1.0f, -1.0f, 11.0f);
-		gGL.vertex3f(1.0f, -1.0f, 11.0f);
-	gGL.end();
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.begin(LLRender::LINES);
+        gGL.color3f(1.0f, 0.0f, 0.0f);   // i direction = X-Axis = red
+        gGL.vertex3f(0.0f, 0.0f, 0.0f);
+        gGL.vertex3f(2.0f, 0.0f, 0.0f);
+        gGL.vertex3f(3.0f, 0.0f, 0.0f);
+        gGL.vertex3f(5.0f, 0.0f, 0.0f);
+        gGL.vertex3f(6.0f, 0.0f, 0.0f);
+        gGL.vertex3f(8.0f, 0.0f, 0.0f);
+        // Make an X
+        gGL.vertex3f(11.0f, 1.0f, 1.0f);
+        gGL.vertex3f(11.0f, -1.0f, -1.0f);
+        gGL.vertex3f(11.0f, 1.0f, -1.0f);
+        gGL.vertex3f(11.0f, -1.0f, 1.0f);
+
+        gGL.color3f(0.0f, 1.0f, 0.0f);   // j direction = Y-Axis = green
+        gGL.vertex3f(0.0f, 0.0f, 0.0f);
+        gGL.vertex3f(0.0f, 2.0f, 0.0f);
+        gGL.vertex3f(0.0f, 3.0f, 0.0f);
+        gGL.vertex3f(0.0f, 5.0f, 0.0f);
+        gGL.vertex3f(0.0f, 6.0f, 0.0f);
+        gGL.vertex3f(0.0f, 8.0f, 0.0f);
+        // Make a Y
+        gGL.vertex3f(1.0f, 11.0f, 1.0f);
+        gGL.vertex3f(0.0f, 11.0f, 0.0f);
+        gGL.vertex3f(-1.0f, 11.0f, 1.0f);
+        gGL.vertex3f(0.0f, 11.0f, 0.0f);
+        gGL.vertex3f(0.0f, 11.0f, 0.0f);
+        gGL.vertex3f(0.0f, 11.0f, -1.0f);
+
+        gGL.color3f(0.0f, 0.0f, 1.0f);   // Z-Axis = blue
+        gGL.vertex3f(0.0f, 0.0f, 0.0f);
+        gGL.vertex3f(0.0f, 0.0f, 2.0f);
+        gGL.vertex3f(0.0f, 0.0f, 3.0f);
+        gGL.vertex3f(0.0f, 0.0f, 5.0f);
+        gGL.vertex3f(0.0f, 0.0f, 6.0f);
+        gGL.vertex3f(0.0f, 0.0f, 8.0f);
+        // Make a Z
+        gGL.vertex3f(-1.0f, 1.0f, 11.0f);
+        gGL.vertex3f(1.0f, 1.0f, 11.0f);
+        gGL.vertex3f(1.0f, 1.0f, 11.0f);
+        gGL.vertex3f(-1.0f, -1.0f, 11.0f);
+        gGL.vertex3f(-1.0f, -1.0f, 11.0f);
+        gGL.vertex3f(1.0f, -1.0f, 11.0f);
+    gGL.end();
 }
 
 
-void draw_axes() 
+void draw_axes()
 {
-	LLGLSUIDefault gls_ui;
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	// A vertical white line at origin
-	LLVector3 v = gAgent.getPositionAgent();
-	gGL.begin(LLRender::LINES);
-		gGL.color3f(1.0f, 1.0f, 1.0f); 
-		gGL.vertex3f(0.0f, 0.0f, 0.0f);
-		gGL.vertex3f(0.0f, 0.0f, 40.0f);
-	gGL.end();
-	// Some coordinate axes
-	gGL.pushMatrix();
-		gGL.translatef( v.mV[VX], v.mV[VY], v.mV[VZ] );
-		renderCoordinateAxes();
-	gGL.popMatrix();
+    LLGLSUIDefault gls_ui;
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    // A vertical white line at origin
+    LLVector3 v = gAgent.getPositionAgent();
+    gGL.begin(LLRender::LINES);
+        gGL.color3f(1.0f, 1.0f, 1.0f);
+        gGL.vertex3f(0.0f, 0.0f, 0.0f);
+        gGL.vertex3f(0.0f, 0.0f, 40.0f);
+    gGL.end();
+    // Some coordinate axes
+    gGL.pushMatrix();
+        gGL.translatef( v.mV[VX], v.mV[VY], v.mV[VZ] );
+        renderCoordinateAxes();
+    gGL.popMatrix();
 }
 
 void render_ui_3d()
 {
-	LLGLSPipeline gls_pipeline;
-
-	//////////////////////////////////////
-	//
-	// Render 3D UI elements
-	// NOTE: zbuffer is cleared before we get here by LLDrawPoolHUD,
-	//		 so 3d elements requiring Z buffer are moved to LLDrawPoolHUD
-	//
-
-	/////////////////////////////////////////////////////////////
-	//
-	// Render 2.5D elements (2D elements in the world)
-	// Stuff without z writes
-	//
-
-	// Debugging stuff goes before the UI.
-
-	stop_glerror();
-	
-	gUIProgram.bind();
+    LLGLSPipeline gls_pipeline;
+
+    //////////////////////////////////////
+    //
+    // Render 3D UI elements
+    // NOTE: zbuffer is cleared before we get here by LLDrawPoolHUD,
+    //       so 3d elements requiring Z buffer are moved to LLDrawPoolHUD
+    //
+
+    /////////////////////////////////////////////////////////////
+    //
+    // Render 2.5D elements (2D elements in the world)
+    // Stuff without z writes
+    //
+
+    // Debugging stuff goes before the UI.
+
+    stop_glerror();
+
+    gUIProgram.bind();
     gGL.color4f(1, 1, 1, 1);
 
-	// Coordinate axes
-	static LLCachedControl<bool> showAxes(gSavedSettings, "ShowAxes");
-	if (showAxes)
-	{
-		draw_axes();
-	}
+    // Coordinate axes
+    static LLCachedControl<bool> showAxes(gSavedSettings, "ShowAxes");
+    if (showAxes)
+    {
+        draw_axes();
+    }
 
-	gViewerWindow->renderSelections(FALSE, FALSE, TRUE); // Non HUD call in render_hud_elements
+    gViewerWindow->renderSelections(FALSE, FALSE, TRUE); // Non HUD call in render_hud_elements
 
     if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
     {
@@ -1583,206 +1583,206 @@ void render_ui_3d()
         gSky.addSunMoonBeacons();
     }
 
-	stop_glerror();
+    stop_glerror();
 }
 
 void render_ui_2d()
 {
-	LLGLSUIDefault gls_ui;
+    LLGLSUIDefault gls_ui;
 
-	/////////////////////////////////////////////////////////////
-	//
-	// Render 2D UI elements that overlay the world (no z compare)
+    /////////////////////////////////////////////////////////////
+    //
+    // Render 2D UI elements that overlay the world (no z compare)
 
-	//  Disable wireframe mode below here, as this is HUD/menus
-	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
+    //  Disable wireframe mode below here, as this is HUD/menus
+    glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
 
-	//  Menu overlays, HUD, etc
-	gViewerWindow->setup2DRender();
+    //  Menu overlays, HUD, etc
+    gViewerWindow->setup2DRender();
 
-	auto& vwrCamera = LLViewerCamera::instance();
-	F32 zoom_factor = vwrCamera.getZoomFactor();
-	S16 sub_region = vwrCamera.getZoomSubRegion();
+    auto& vwrCamera = LLViewerCamera::instance();
+    F32 zoom_factor = vwrCamera.getZoomFactor();
+    S16 sub_region = vwrCamera.getZoomSubRegion();
 
-	if (zoom_factor > 1.f)
-	{
-		//decompose subregion number to x and y values
-		int pos_y = sub_region / llceil(zoom_factor);
-		int pos_x = sub_region - (pos_y*llceil(zoom_factor));
-		// offset for this tile
-		LLFontGL::sCurOrigin.mX -= ll_round((F32)gViewerWindow->getWindowWidthScaled() * (F32)pos_x / zoom_factor);
-		LLFontGL::sCurOrigin.mY -= ll_round((F32)gViewerWindow->getWindowHeightScaled() * (F32)pos_y / zoom_factor);
-	}
+    if (zoom_factor > 1.f)
+    {
+        //decompose subregion number to x and y values
+        int pos_y = sub_region / llceil(zoom_factor);
+        int pos_x = sub_region - (pos_y*llceil(zoom_factor));
+        // offset for this tile
+        LLFontGL::sCurOrigin.mX -= ll_round((F32)gViewerWindow->getWindowWidthScaled() * (F32)pos_x / zoom_factor);
+        LLFontGL::sCurOrigin.mY -= ll_round((F32)gViewerWindow->getWindowHeightScaled() * (F32)pos_y / zoom_factor);
+    }
 
-	stop_glerror();
+    stop_glerror();
 
-	// render outline for HUD
-	if (isAgentAvatarValid() && gAgentCamera.mHUDCurZoom < 0.98f)
-	{
+    // render outline for HUD
+    if (isAgentAvatarValid() && gAgentCamera.mHUDCurZoom < 0.98f)
+    {
         gUIProgram.bind();
-		gGL.pushMatrix();
-		S32 half_width = (gViewerWindow->getWorldViewWidthScaled() / 2);
-		S32 half_height = (gViewerWindow->getWorldViewHeightScaled() / 2);
-		gGL.scalef(LLUI::getScaleFactor().mV[0], LLUI::getScaleFactor().mV[1], 1.f);
-		gGL.translatef((F32)half_width, (F32)half_height, 0.f);
-		F32 zoom = gAgentCamera.mHUDCurZoom;
-		gGL.scalef(zoom,zoom,1.f);
-		gGL.color4fv(LLColor4::white.mV);
-		gl_rect_2d(-half_width, half_height, half_width, -half_height, FALSE);
-		gGL.popMatrix();
+        gGL.pushMatrix();
+        S32 half_width = (gViewerWindow->getWorldViewWidthScaled() / 2);
+        S32 half_height = (gViewerWindow->getWorldViewHeightScaled() / 2);
+        gGL.scalef(LLUI::getScaleFactor().mV[0], LLUI::getScaleFactor().mV[1], 1.f);
+        gGL.translatef((F32)half_width, (F32)half_height, 0.f);
+        F32 zoom = gAgentCamera.mHUDCurZoom;
+        gGL.scalef(zoom,zoom,1.f);
+        gGL.color4fv(LLColor4::white.mV);
+        gl_rect_2d(-half_width, half_height, half_width, -half_height, FALSE);
+        gGL.popMatrix();
         gUIProgram.unbind();
-		stop_glerror();
-	}
-	
-
-	if (LLPipeline::RenderUIBuffer)
-	{
-		if (LLView::sIsRectDirty)
-		{
+        stop_glerror();
+    }
+
+
+    if (LLPipeline::RenderUIBuffer)
+    {
+        if (LLView::sIsRectDirty)
+        {
             LLView::sIsRectDirty = false;
-			LLRect t_rect;
+            LLRect t_rect;
 
-			gPipeline.mRT->uiScreen.bindTarget();
-			gGL.setColorMask(true, true);
-			{
-				static const S32 pad = 8;
+            gPipeline.mRT->uiScreen.bindTarget();
+            gGL.setColorMask(true, true);
+            {
+                static const S32 pad = 8;
 
                 LLView::sDirtyRect.mLeft -= pad;
                 LLView::sDirtyRect.mRight += pad;
                 LLView::sDirtyRect.mBottom -= pad;
                 LLView::sDirtyRect.mTop += pad;
 
-				LLGLEnable scissor(GL_SCISSOR_TEST);
-				static LLRect last_rect = LLView::sDirtyRect;
+                LLGLEnable scissor(GL_SCISSOR_TEST);
+                static LLRect last_rect = LLView::sDirtyRect;
+
+                //union with last rect to avoid mouse poop
+                last_rect.unionWith(LLView::sDirtyRect);
 
-				//union with last rect to avoid mouse poop
-				last_rect.unionWith(LLView::sDirtyRect);
-								
-				t_rect = LLView::sDirtyRect;
+                t_rect = LLView::sDirtyRect;
                 LLView::sDirtyRect = last_rect;
-				last_rect = t_rect;
+                last_rect = t_rect;
+
+                last_rect.mLeft = LLRect::tCoordType(last_rect.mLeft / LLUI::getScaleFactor().mV[0]);
+                last_rect.mRight = LLRect::tCoordType(last_rect.mRight / LLUI::getScaleFactor().mV[0]);
+                last_rect.mTop = LLRect::tCoordType(last_rect.mTop / LLUI::getScaleFactor().mV[1]);
+                last_rect.mBottom = LLRect::tCoordType(last_rect.mBottom / LLUI::getScaleFactor().mV[1]);
 
-				last_rect.mLeft = LLRect::tCoordType(last_rect.mLeft / LLUI::getScaleFactor().mV[0]);
-				last_rect.mRight = LLRect::tCoordType(last_rect.mRight / LLUI::getScaleFactor().mV[0]);
-				last_rect.mTop = LLRect::tCoordType(last_rect.mTop / LLUI::getScaleFactor().mV[1]);
-				last_rect.mBottom = LLRect::tCoordType(last_rect.mBottom / LLUI::getScaleFactor().mV[1]);
+                //LLRect clip_rect(last_rect);
 
-				//LLRect clip_rect(last_rect);
-				
-				glClear(GL_COLOR_BUFFER_BIT);
+                glClear(GL_COLOR_BUFFER_BIT);
 
-				gViewerWindow->draw();
-			}
+                gViewerWindow->draw();
+            }
 
-			gPipeline.mRT->uiScreen.flush();
-			gGL.setColorMask(true, false);
+            gPipeline.mRT->uiScreen.flush();
+            gGL.setColorMask(true, false);
 
             LLView::sDirtyRect = t_rect;
-		}
-
-		LLGLDisable cull(GL_CULL_FACE);
-		LLGLDisable blend(GL_BLEND);
-		S32 width = gViewerWindow->getWindowWidthScaled();
-		S32 height = gViewerWindow->getWindowHeightScaled();
-		gGL.getTexUnit(0)->bind(&gPipeline.mRT->uiScreen);
-		gGL.begin(LLRender::TRIANGLE_STRIP);
-		gGL.color4f(1,1,1,1);
-		gGL.texCoord2f(0, 0);			gGL.vertex2i(0, 0);
-		gGL.texCoord2f(width, 0);		gGL.vertex2i(width, 0);
-		gGL.texCoord2f(0, height);		gGL.vertex2i(0, height);
-		gGL.texCoord2f(width, height);	gGL.vertex2i(width, height);
-		gGL.end();
-	}
-	else
-	{
-		gViewerWindow->draw();
-	}
-
-
-
-	// reset current origin for font rendering, in case of tiling render
-	LLFontGL::sCurOrigin.set(0, 0);
+        }
+
+        LLGLDisable cull(GL_CULL_FACE);
+        LLGLDisable blend(GL_BLEND);
+        S32 width = gViewerWindow->getWindowWidthScaled();
+        S32 height = gViewerWindow->getWindowHeightScaled();
+        gGL.getTexUnit(0)->bind(&gPipeline.mRT->uiScreen);
+        gGL.begin(LLRender::TRIANGLE_STRIP);
+        gGL.color4f(1,1,1,1);
+        gGL.texCoord2f(0, 0);           gGL.vertex2i(0, 0);
+        gGL.texCoord2f(width, 0);       gGL.vertex2i(width, 0);
+        gGL.texCoord2f(0, height);      gGL.vertex2i(0, height);
+        gGL.texCoord2f(width, height);  gGL.vertex2i(width, height);
+        gGL.end();
+    }
+    else
+    {
+        gViewerWindow->draw();
+    }
+
+
+
+    // reset current origin for font rendering, in case of tiling render
+    LLFontGL::sCurOrigin.set(0, 0);
 }
 
 void render_disconnected_background()
 {
-	gUIProgram.bind();
-
-	gGL.color4f(1,1,1,1);
-	if (!gDisconnectedImagep && gDisconnected)
-	{
-		LL_INFOS() << "Loading last bitmap..." << LL_ENDL;
-
-		std::string temp_str;
-		temp_str = gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter() + LLStartUp::getScreenLastFilename();
-
-		LLPointer<LLImagePNG> image_png = new LLImagePNG;
-		if( !image_png->load(temp_str) )
-		{
-			//LL_INFOS() << "Bitmap load failed" << LL_ENDL;
-			return;
-		}
-		
-		LLPointer<LLImageRaw> raw = new LLImageRaw;
-		if (!image_png->decode(raw, 0.0f))
-		{
-			LL_INFOS() << "Bitmap decode failed" << LL_ENDL;
-			gDisconnectedImagep = NULL;
-			return;
-		}
-
-		U8 *rawp = raw->getData();
-		S32 npixels = (S32)image_png->getWidth()*(S32)image_png->getHeight();
-		for (S32 i = 0; i < npixels; i++)
-		{
-			S32 sum = 0;
-			sum = *rawp + *(rawp+1) + *(rawp+2);
-			sum /= 3;
-			*rawp = ((S32)sum*6 + *rawp)/7;
-			rawp++;
-			*rawp = ((S32)sum*6 + *rawp)/7;
-			rawp++;
-			*rawp = ((S32)sum*6 + *rawp)/7;
-			rawp++;
-		}
-
-		
-		raw->expandToPowerOfTwo();
-		gDisconnectedImagep = LLViewerTextureManager::getLocalTexture(raw.get(), FALSE );
-		gStartTexture = gDisconnectedImagep;
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	}
-
-	// Make sure the progress view always fills the entire window.
-	S32 width = gViewerWindow->getWindowWidthScaled();
-	S32 height = gViewerWindow->getWindowHeightScaled();
-
-	if (gDisconnectedImagep)
-	{
-		LLGLSUIDefault gls_ui;
-		gViewerWindow->setup2DRender();
-		gGL.pushMatrix();
-		{
-			// scale ui to reflect UIScaleFactor
-			// this can't be done in setup2DRender because it requires a
-			// pushMatrix/popMatrix pair
-			const LLVector2& display_scale = gViewerWindow->getDisplayScale();
-			gGL.scalef(display_scale.mV[VX], display_scale.mV[VY], 1.f);
-
-			gGL.getTexUnit(0)->bind(gDisconnectedImagep);
-			gGL.color4f(1.f, 1.f, 1.f, 1.f);
-			gl_rect_2d_simple_tex(width, height);
-			gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-		}
-		gGL.popMatrix();
-	}
-	gGL.flush();
-
-	gUIProgram.unbind();
+    gUIProgram.bind();
+
+    gGL.color4f(1,1,1,1);
+    if (!gDisconnectedImagep && gDisconnected)
+    {
+        LL_INFOS() << "Loading last bitmap..." << LL_ENDL;
+
+        std::string temp_str;
+        temp_str = gDirUtilp->getLindenUserDir() + gDirUtilp->getDirDelimiter() + LLStartUp::getScreenLastFilename();
+
+        LLPointer<LLImagePNG> image_png = new LLImagePNG;
+        if( !image_png->load(temp_str) )
+        {
+            //LL_INFOS() << "Bitmap load failed" << LL_ENDL;
+            return;
+        }
+
+        LLPointer<LLImageRaw> raw = new LLImageRaw;
+        if (!image_png->decode(raw, 0.0f))
+        {
+            LL_INFOS() << "Bitmap decode failed" << LL_ENDL;
+            gDisconnectedImagep = NULL;
+            return;
+        }
+
+        U8 *rawp = raw->getData();
+        S32 npixels = (S32)image_png->getWidth()*(S32)image_png->getHeight();
+        for (S32 i = 0; i < npixels; i++)
+        {
+            S32 sum = 0;
+            sum = *rawp + *(rawp+1) + *(rawp+2);
+            sum /= 3;
+            *rawp = ((S32)sum*6 + *rawp)/7;
+            rawp++;
+            *rawp = ((S32)sum*6 + *rawp)/7;
+            rawp++;
+            *rawp = ((S32)sum*6 + *rawp)/7;
+            rawp++;
+        }
+
+
+        raw->expandToPowerOfTwo();
+        gDisconnectedImagep = LLViewerTextureManager::getLocalTexture(raw.get(), FALSE );
+        gStartTexture = gDisconnectedImagep;
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    }
+
+    // Make sure the progress view always fills the entire window.
+    S32 width = gViewerWindow->getWindowWidthScaled();
+    S32 height = gViewerWindow->getWindowHeightScaled();
+
+    if (gDisconnectedImagep)
+    {
+        LLGLSUIDefault gls_ui;
+        gViewerWindow->setup2DRender();
+        gGL.pushMatrix();
+        {
+            // scale ui to reflect UIScaleFactor
+            // this can't be done in setup2DRender because it requires a
+            // pushMatrix/popMatrix pair
+            const LLVector2& display_scale = gViewerWindow->getDisplayScale();
+            gGL.scalef(display_scale.mV[VX], display_scale.mV[VY], 1.f);
+
+            gGL.getTexUnit(0)->bind(gDisconnectedImagep);
+            gGL.color4f(1.f, 1.f, 1.f, 1.f);
+            gl_rect_2d_simple_tex(width, height);
+            gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+        }
+        gGL.popMatrix();
+    }
+    gGL.flush();
+
+    gUIProgram.unbind();
 }
 
 void display_cleanup()
 {
-	gDisconnectedImagep = NULL;
+    gDisconnectedImagep = NULL;
 }
 
diff --git a/indra/newview/llviewermenu.cpp b/indra/newview/llviewermenu.cpp
index 48a28ffe0f43962c1bcc63aa7a8b7e5e6bd97a40..4da296410d31dc0aa5ef923b52d1e7cbb00e5076 100644
--- a/indra/newview/llviewermenu.cpp
+++ b/indra/newview/llviewermenu.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewermenu.cpp
  * @brief Builds menus out of items.
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2014, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -30,7 +30,7 @@
 #include "vld.h"
 #endif
 
-#include "llviewermenu.h" 
+#include "llviewermenu.h"
 
 // linden library includes
 #include "llavatarnamecache.h"  // IDEVO (I Are Not Men!)
@@ -128,7 +128,7 @@
 #include "llviewerdisplay.h" //for gWindowResized
 #include "llviewergenericmessage.h"
 #include "llviewerhelp.h"
-#include "llviewermenufile.h"	// init_menu_file()
+#include "llviewermenufile.h"   // init_menu_file()
 #include "llviewermessage.h"
 #include "llviewernetwork.h"
 #include "llviewerobjectlist.h"
@@ -179,7 +179,7 @@ void handle_test_load_url(void*);
 //
 // Evil hackish imported globals
 
-//extern BOOL	gHideSelectedObjects;
+//extern BOOL   gHideSelectedObjects;
 //extern BOOL gAllowSelectAvatar;
 //extern BOOL gDebugAvatarRotation;
 extern BOOL gDebugClicks;
@@ -193,20 +193,20 @@ extern BOOL gShaderProfileFrame;
 // Globals
 //
 
-LLMenuBarGL		*gMenuBarView = NULL;
-LLViewerMenuHolderGL	*gMenuHolder = NULL;
-LLMenuGL		*gPopupMenuView = NULL;
-LLMenuGL		*gEditMenu = NULL;
-LLMenuBarGL		*gLoginMenuBarView = NULL;
+LLMenuBarGL     *gMenuBarView = NULL;
+LLViewerMenuHolderGL    *gMenuHolder = NULL;
+LLMenuGL        *gPopupMenuView = NULL;
+LLMenuGL        *gEditMenu = NULL;
+LLMenuBarGL     *gLoginMenuBarView = NULL;
 
 // Pie menus
-LLContextMenu	*gMenuAvatarSelf	= NULL;
-LLContextMenu	*gMenuAvatarOther = NULL;
-LLContextMenu	*gMenuObject = NULL;
-LLContextMenu	*gMenuAttachmentSelf = NULL;
-LLContextMenu	*gMenuAttachmentOther = NULL;
-LLContextMenu	*gMenuLand	= NULL;
-LLContextMenu	*gMenuMuteParticle = NULL;
+LLContextMenu   *gMenuAvatarSelf    = NULL;
+LLContextMenu   *gMenuAvatarOther = NULL;
+LLContextMenu   *gMenuObject = NULL;
+LLContextMenu   *gMenuAttachmentSelf = NULL;
+LLContextMenu   *gMenuAttachmentOther = NULL;
+LLContextMenu   *gMenuLand  = NULL;
+LLContextMenu   *gMenuMuteParticle = NULL;
 
 const std::string SAVE_INTO_TASK_INVENTORY("Save Object Back to Object Contents");
 
@@ -304,7 +304,7 @@ void handle_force_parcel_owner_to_me(void*);
 void handle_force_parcel_to_content(void*);
 void handle_claim_public_land(void*);
 
-void handle_god_request_avatar_geometry(void *);	// Hack for easy testing of new avatar geometry
+void handle_god_request_avatar_geometry(void *);    // Hack for easy testing of new avatar geometry
 void reload_vertex_shader(void *);
 void handle_disconnect_viewer(void *);
 
@@ -364,12 +364,12 @@ void menu_toggle_attached_particles(void* user_data);
 class LLMenuParcelObserver : public LLParcelObserver
 {
 public:
-	LLMenuParcelObserver();
-	~LLMenuParcelObserver();
+    LLMenuParcelObserver();
+    ~LLMenuParcelObserver();
     void changed() override;
 private:
-	LLHandle<LLUICtrl> mLandBuyHandle;
-	LLHandle<LLUICtrl> mLandBuyPassHandle;
+    LLHandle<LLUICtrl> mLandBuyHandle;
+    LLHandle<LLUICtrl> mLandBuyPassHandle;
 };
 
 static LLMenuParcelObserver* gMenuParcelObserver = NULL;
@@ -378,29 +378,29 @@ static LLUIListener sUIListener;
 
 LLMenuParcelObserver::LLMenuParcelObserver()
 {
-	mLandBuyHandle = gMenuLand->getChild<LLMenuItemCallGL>("Land Buy")->getHandle();
-	mLandBuyPassHandle = gMenuLand->getChild<LLMenuItemCallGL>("Land Buy Pass")->getHandle();
-	LLViewerParcelMgr::getInstance()->addObserver(this);
+    mLandBuyHandle = gMenuLand->getChild<LLMenuItemCallGL>("Land Buy")->getHandle();
+    mLandBuyPassHandle = gMenuLand->getChild<LLMenuItemCallGL>("Land Buy Pass")->getHandle();
+    LLViewerParcelMgr::getInstance()->addObserver(this);
 }
 
 LLMenuParcelObserver::~LLMenuParcelObserver()
 {
-	LLViewerParcelMgr::getInstance()->removeObserver(this);
+    LLViewerParcelMgr::getInstance()->removeObserver(this);
 }
 
 void LLMenuParcelObserver::changed()
 {
-	if (!mLandBuyPassHandle.isDead())
-	{
-		LLParcel *parcel = LLViewerParcelMgr::getInstance()->getParcelSelection()->getParcel();
-		static_cast<LLMenuItemCallGL*>(mLandBuyPassHandle.get())->setEnabled(LLPanelLandGeneral::enableBuyPass(NULL) && !(parcel->getOwnerID() == gAgent.getID()));
-	}
-	
-	if (!mLandBuyHandle.isDead())
-	{
-		BOOL buyable = enable_buy_land(NULL);
-		static_cast<LLMenuItemCallGL*>(mLandBuyHandle.get())->setEnabled(buyable);
-	}
+    if (!mLandBuyPassHandle.isDead())
+    {
+        LLParcel *parcel = LLViewerParcelMgr::getInstance()->getParcelSelection()->getParcel();
+        static_cast<LLMenuItemCallGL*>(mLandBuyPassHandle.get())->setEnabled(LLPanelLandGeneral::enableBuyPass(NULL) && !(parcel->getOwnerID() == gAgent.getID()));
+    }
+
+    if (!mLandBuyHandle.isDead())
+    {
+        BOOL buyable = enable_buy_land(NULL);
+        static_cast<LLMenuItemCallGL*>(mLandBuyHandle.get())->setEnabled(buyable);
+    }
 }
 
 
@@ -421,47 +421,47 @@ void initialize_menus();
 class LLSLMMenuUpdater
 {
 public:
-	LLSLMMenuUpdater();
-	~LLSLMMenuUpdater() = default;
+    LLSLMMenuUpdater();
+    ~LLSLMMenuUpdater() = default;
 
-	void setMerchantMenu();
-	void checkMerchantStatus(bool force);
+    void setMerchantMenu();
+    void checkMerchantStatus(bool force);
 
 private:
-	LLHandle<LLView> mMarketplaceListingsItem;
+    LLHandle<LLView> mMarketplaceListingsItem;
 };
 
 static LLSLMMenuUpdater* gSLMMenuUpdater = NULL;
 
 LLSLMMenuUpdater::LLSLMMenuUpdater()
 {
-	mMarketplaceListingsItem = gMenuHolder->getChild<LLView>("MarketplaceListings")->getHandle();
+    mMarketplaceListingsItem = gMenuHolder->getChild<LLView>("MarketplaceListings")->getHandle();
 }
 void LLSLMMenuUpdater::setMerchantMenu()
 {
-	// All other cases (new merchant, not merchant, migrated merchant): show the new Marketplace Listings menu and enable the tool
-	bool in_sl = LLGridManager::getInstance()->isInSecondlife();
-	if(!mMarketplaceListingsItem.isDead())
-	{
-		mMarketplaceListingsItem.get()->setVisible((BOOL)in_sl);
-	}
+    // All other cases (new merchant, not merchant, migrated merchant): show the new Marketplace Listings menu and enable the tool
+    bool in_sl = LLGridManager::getInstance()->isInSecondlife();
+    if(!mMarketplaceListingsItem.isDead())
+    {
+        mMarketplaceListingsItem.get()->setVisible((BOOL)in_sl);
+    }
     LLCommand* command = LLCommandManager::instance().getCommand("marketplacelistings");
     gToolBarView->enableCommand(command->id(), in_sl);
 
-	if(in_sl)
-	{
-	    const LLUUID marketplacelistings_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MARKETPLACE_LISTINGS);
-	    if (marketplacelistings_id.isNull())
-	    {
-	        U32 mkt_status = LLMarketplaceData::instance().getSLMStatus();
-	        bool is_merchant = (mkt_status == MarketplaceStatusCodes::MARKET_PLACE_MERCHANT) || (mkt_status == MarketplaceStatusCodes::MARKET_PLACE_MIGRATED_MERCHANT);
-	        if (is_merchant)
-	        {
-	            gInventory.ensureCategoryForTypeExists(LLFolderType::FT_MARKETPLACE_LISTINGS);
-	            LL_WARNS("SLM") << "Creating the marketplace listings folder for a merchant" << LL_ENDL;
-	        }
-	    }
-	}
+    if(in_sl)
+    {
+        const LLUUID marketplacelistings_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_MARKETPLACE_LISTINGS);
+        if (marketplacelistings_id.isNull())
+        {
+            U32 mkt_status = LLMarketplaceData::instance().getSLMStatus();
+            bool is_merchant = (mkt_status == MarketplaceStatusCodes::MARKET_PLACE_MERCHANT) || (mkt_status == MarketplaceStatusCodes::MARKET_PLACE_MIGRATED_MERCHANT);
+            if (is_merchant)
+            {
+                gInventory.ensureCategoryForTypeExists(LLFolderType::FT_MARKETPLACE_LISTINGS);
+                LL_WARNS("SLM") << "Creating the marketplace listings folder for a merchant" << LL_ENDL;
+            }
+        }
+    }
 }
 
 void LLSLMMenuUpdater::checkMerchantStatus(bool force)
@@ -472,19 +472,19 @@ void LLSLMMenuUpdater::checkMerchantStatus(bool force)
         LLMarketplaceData::instance().setSLMStatus(MarketplaceStatusCodes::MARKET_PLACE_NOT_INITIALIZED);
     }
     // Hide SLM related menu item
-	if(!mMarketplaceListingsItem.isDead())
-	{
-		mMarketplaceListingsItem.get()->setVisible(FALSE);
-	}
+    if(!mMarketplaceListingsItem.isDead())
+    {
+        mMarketplaceListingsItem.get()->setVisible(FALSE);
+    }
     // Also disable the toolbar button for Marketplace Listings
     LLCommand* command = LLCommandManager::instance().getCommand("marketplacelistings");
     gToolBarView->enableCommand(command->id(), false);
 
     if (!gAgent.getRegionCapability("DirectDelivery").empty())
     {
-    	// Launch an SLM test connection to get the merchant status
-		LLMarketplaceData::instance().initializeSLM([&](){ setMerchantMenu();});
-	}
+        // Launch an SLM test connection to get the merchant status
+        LLMarketplaceData::instance().initializeSLM([&](){ setMerchantMenu();});
+    }
 }
 
 void set_merchant_SLM_menu()
@@ -499,131 +499,131 @@ void check_merchant_status(bool force)
 
 void init_menus()
 {
-	// Initialize actions
-	initialize_menus();
-
-	///
-	/// Popup menu
-	///
-	/// The popup menu is now populated by the show_context_menu()
-	/// method.
-	
-	LLMenuGL::Params menu_params;
-	menu_params.name = "Popup";
-	menu_params.visible = false;
-	gPopupMenuView = LLUICtrlFactory::create<LLMenuGL>(menu_params);
-	gMenuHolder->addChild( gPopupMenuView );
-
-	///
-	/// Context menus
-	///
-
-	const widget_registry_t& registry =
-		LLViewerMenuHolderGL::child_registry_t::instance();
-	gEditMenu = LLUICtrlFactory::createFromFile<LLMenuGL>("menu_edit.xml", gMenuHolder, registry);
-	gMenuAvatarSelf = LLUICtrlFactory::createFromFile<LLContextMenu>(
-		"menu_avatar_self.xml", gMenuHolder, registry);
-	gMenuAvatarOther = LLUICtrlFactory::createFromFile<LLContextMenu>(
-		"menu_avatar_other.xml", gMenuHolder, registry);
-
-	gDetachScreenPieMenu = gMenuHolder->getChild<LLContextMenu>("Object Detach HUD", true);
-	gDetachPieMenu = gMenuHolder->getChild<LLContextMenu>("Object Detach", true);
-
-	gMenuObject = LLUICtrlFactory::createFromFile<LLContextMenu>(
-		"menu_object.xml", gMenuHolder, registry);
-
-	gAttachScreenPieMenu = gMenuHolder->getChild<LLContextMenu>("Object Attach HUD");
-	gAttachPieMenu = gMenuHolder->getChild<LLContextMenu>("Object Attach");
-
-	gMenuAttachmentSelf = LLUICtrlFactory::createFromFile<LLContextMenu>(
-		"menu_attachment_self.xml", gMenuHolder, registry);
-	gMenuAttachmentOther = LLUICtrlFactory::createFromFile<LLContextMenu>(
-		"menu_attachment_other.xml", gMenuHolder, registry);
-
-	gDetachHUDAttSelfMenu = gMenuHolder->getChild<LLContextMenu>("Detach Self HUD", true);
-	gDetachAttSelfMenu = gMenuHolder->getChild<LLContextMenu>("Detach Self", true);
-
-	gMenuLand = LLUICtrlFactory::createFromFile<LLContextMenu>(
-		"menu_land.xml", gMenuHolder, registry);
-
-	gMenuMuteParticle = LLUICtrlFactory::createFromFile<LLContextMenu>(
-		"menu_mute_particle.xml", gMenuHolder, registry);
-
-	///
-	/// set up the colors
-	///
-	LLColor4 color;
-
-	LLColor4 context_menu_color = LLUIColorTable::instance().getColor("MenuPopupBgColor");
-	
-	gMenuAvatarSelf->setBackgroundColor( context_menu_color );
-	gMenuAvatarOther->setBackgroundColor( context_menu_color );
-	gMenuObject->setBackgroundColor( context_menu_color );
-	gMenuAttachmentSelf->setBackgroundColor( context_menu_color );
-	gMenuAttachmentOther->setBackgroundColor( context_menu_color );
-
-	gMenuLand->setBackgroundColor( context_menu_color );
-
-	color = LLUIColorTable::instance().getColor( "MenuPopupBgColor" );
-	gPopupMenuView->setBackgroundColor( color );
-
-	// If we are not in production, use a different color to make it apparent.
-	if (LLGridManager::getInstance()->isInSLBeta())
-	{
-		color = LLUIColorTable::instance().getColor("MenuNonProductionBgColor");
-	}
-	else
-	{
-		color = LLUIColorTable::instance().getColor("MenuBarBgColor");
-	}
-
-	LLView* menu_bar_holder = gViewerWindow->getRootView()->getChildView("menu_bar_holder");
-
-	gMenuBarView = LLUICtrlFactory::getInstance()->createFromFile<LLMenuBarGL>("menu_viewer.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
-	gMenuBarView->setRect(LLRect(0, menu_bar_holder->getRect().mTop, 0, menu_bar_holder->getRect().mTop - MENU_BAR_HEIGHT));
-	gMenuBarView->setBackgroundColor( color );
-
-	menu_bar_holder->addChild(gMenuBarView);
-  
-    gViewerWindow->setMenuBackgroundColor(false, 
+    // Initialize actions
+    initialize_menus();
+
+    ///
+    /// Popup menu
+    ///
+    /// The popup menu is now populated by the show_context_menu()
+    /// method.
+
+    LLMenuGL::Params menu_params;
+    menu_params.name = "Popup";
+    menu_params.visible = false;
+    gPopupMenuView = LLUICtrlFactory::create<LLMenuGL>(menu_params);
+    gMenuHolder->addChild( gPopupMenuView );
+
+    ///
+    /// Context menus
+    ///
+
+    const widget_registry_t& registry =
+        LLViewerMenuHolderGL::child_registry_t::instance();
+    gEditMenu = LLUICtrlFactory::createFromFile<LLMenuGL>("menu_edit.xml", gMenuHolder, registry);
+    gMenuAvatarSelf = LLUICtrlFactory::createFromFile<LLContextMenu>(
+        "menu_avatar_self.xml", gMenuHolder, registry);
+    gMenuAvatarOther = LLUICtrlFactory::createFromFile<LLContextMenu>(
+        "menu_avatar_other.xml", gMenuHolder, registry);
+
+    gDetachScreenPieMenu = gMenuHolder->getChild<LLContextMenu>("Object Detach HUD", true);
+    gDetachPieMenu = gMenuHolder->getChild<LLContextMenu>("Object Detach", true);
+
+    gMenuObject = LLUICtrlFactory::createFromFile<LLContextMenu>(
+        "menu_object.xml", gMenuHolder, registry);
+
+    gAttachScreenPieMenu = gMenuHolder->getChild<LLContextMenu>("Object Attach HUD");
+    gAttachPieMenu = gMenuHolder->getChild<LLContextMenu>("Object Attach");
+
+    gMenuAttachmentSelf = LLUICtrlFactory::createFromFile<LLContextMenu>(
+        "menu_attachment_self.xml", gMenuHolder, registry);
+    gMenuAttachmentOther = LLUICtrlFactory::createFromFile<LLContextMenu>(
+        "menu_attachment_other.xml", gMenuHolder, registry);
+
+    gDetachHUDAttSelfMenu = gMenuHolder->getChild<LLContextMenu>("Detach Self HUD", true);
+    gDetachAttSelfMenu = gMenuHolder->getChild<LLContextMenu>("Detach Self", true);
+
+    gMenuLand = LLUICtrlFactory::createFromFile<LLContextMenu>(
+        "menu_land.xml", gMenuHolder, registry);
+
+    gMenuMuteParticle = LLUICtrlFactory::createFromFile<LLContextMenu>(
+        "menu_mute_particle.xml", gMenuHolder, registry);
+
+    ///
+    /// set up the colors
+    ///
+    LLColor4 color;
+
+    LLColor4 context_menu_color = LLUIColorTable::instance().getColor("MenuPopupBgColor");
+
+    gMenuAvatarSelf->setBackgroundColor( context_menu_color );
+    gMenuAvatarOther->setBackgroundColor( context_menu_color );
+    gMenuObject->setBackgroundColor( context_menu_color );
+    gMenuAttachmentSelf->setBackgroundColor( context_menu_color );
+    gMenuAttachmentOther->setBackgroundColor( context_menu_color );
+
+    gMenuLand->setBackgroundColor( context_menu_color );
+
+    color = LLUIColorTable::instance().getColor( "MenuPopupBgColor" );
+    gPopupMenuView->setBackgroundColor( color );
+
+    // If we are not in production, use a different color to make it apparent.
+    if (LLGridManager::getInstance()->isInSLBeta())
+    {
+        color = LLUIColorTable::instance().getColor("MenuNonProductionBgColor");
+    }
+    else
+    {
+        color = LLUIColorTable::instance().getColor("MenuBarBgColor");
+    }
+
+    LLView* menu_bar_holder = gViewerWindow->getRootView()->getChildView("menu_bar_holder");
+
+    gMenuBarView = LLUICtrlFactory::getInstance()->createFromFile<LLMenuBarGL>("menu_viewer.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+    gMenuBarView->setRect(LLRect(0, menu_bar_holder->getRect().mTop, 0, menu_bar_holder->getRect().mTop - MENU_BAR_HEIGHT));
+    gMenuBarView->setBackgroundColor( color );
+
+    menu_bar_holder->addChild(gMenuBarView);
+
+    gViewerWindow->setMenuBackgroundColor(false,
         LLGridManager::getInstance()->isInSLBeta());
 
-	// *TODO:Also fix cost in llfolderview.cpp for Inventory menus
-	const std::string sound_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getSoundUploadCost());
-	const std::string animation_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getAnimationUploadCost());
-	gMenuHolder->childSetLabelArg("Upload Sound", "[COST]", sound_upload_cost_str);
-	gMenuHolder->childSetLabelArg("Upload Animation", "[COST]", animation_upload_cost_str);
-	
-	gAttachSubMenu = gMenuBarView->findChildMenuByName("Attach Object", TRUE);
-	gDetachSubMenu = gMenuBarView->findChildMenuByName("Detach Object", TRUE);
+    // *TODO:Also fix cost in llfolderview.cpp for Inventory menus
+    const std::string sound_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getSoundUploadCost());
+    const std::string animation_upload_cost_str = fmt::to_string(LLAgentBenefitsMgr::current().getAnimationUploadCost());
+    gMenuHolder->childSetLabelArg("Upload Sound", "[COST]", sound_upload_cost_str);
+    gMenuHolder->childSetLabelArg("Upload Animation", "[COST]", animation_upload_cost_str);
+
+    gAttachSubMenu = gMenuBarView->findChildMenuByName("Attach Object", TRUE);
+    gDetachSubMenu = gMenuBarView->findChildMenuByName("Detach Object", TRUE);
+
+    gDetachAvatarMenu = gMenuHolder->getChild<LLMenuGL>("Avatar Detach", true);
+    gDetachHUDAvatarMenu = gMenuHolder->getChild<LLMenuGL>("Avatar Detach HUD", true);
 
-	gDetachAvatarMenu = gMenuHolder->getChild<LLMenuGL>("Avatar Detach", true);
-	gDetachHUDAvatarMenu = gMenuHolder->getChild<LLMenuGL>("Avatar Detach HUD", true);
+    // Don't display the Memory console menu if the feature is turned off
+    LLMenuItemCheckGL *memoryMenu = gMenuBarView->getChild<LLMenuItemCheckGL>("Memory", TRUE);
+    if (memoryMenu)
+    {
+        memoryMenu->setVisible(FALSE);
+    }
 
-	// Don't display the Memory console menu if the feature is turned off
-	LLMenuItemCheckGL *memoryMenu = gMenuBarView->getChild<LLMenuItemCheckGL>("Memory", TRUE);
-	if (memoryMenu)
-	{
-		memoryMenu->setVisible(FALSE);
-	}
+    gMenuBarView->createJumpKeys();
 
-	gMenuBarView->createJumpKeys();
+    // Let land based option enable when parcel changes
+    gMenuParcelObserver = new LLMenuParcelObserver();
 
-	// Let land based option enable when parcel changes
-	gMenuParcelObserver = new LLMenuParcelObserver();
+    gSLMMenuUpdater = new LLSLMMenuUpdater();
 
-	gSLMMenuUpdater = new LLSLMMenuUpdater();
+    gLoginMenuBarView = LLUICtrlFactory::getInstance()->createFromFile<LLMenuBarGL>("menu_login.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+    gLoginMenuBarView->arrangeAndClear();
+    LLRect menuBarRect = gLoginMenuBarView->getRect();
+    menuBarRect.setLeftTopAndSize(0, menu_bar_holder->getRect().getHeight(), menuBarRect.getWidth(), menuBarRect.getHeight());
+    gLoginMenuBarView->setRect(menuBarRect);
+    gLoginMenuBarView->setBackgroundColor( color );
+    menu_bar_holder->addChild(gLoginMenuBarView);
 
-	gLoginMenuBarView = LLUICtrlFactory::getInstance()->createFromFile<LLMenuBarGL>("menu_login.xml", gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
-	gLoginMenuBarView->arrangeAndClear();
-	LLRect menuBarRect = gLoginMenuBarView->getRect();
-	menuBarRect.setLeftTopAndSize(0, menu_bar_holder->getRect().getHeight(), menuBarRect.getWidth(), menuBarRect.getHeight());
-	gLoginMenuBarView->setRect(menuBarRect);
-	gLoginMenuBarView->setBackgroundColor( color );
-	menu_bar_holder->addChild(gLoginMenuBarView);
-	
-	// tooltips are on top of EVERYTHING, including menus
-	gViewerWindow->getRootView()->sendChildToFront(gToolTipView);
+    // tooltips are on top of EVERYTHING, including menus
+    gViewerWindow->getRootView()->sendChildToFront(gToolTipView);
 }
 
 ///////////////////
@@ -633,62 +633,62 @@ void init_menus()
 
 class LLAdvancedToggleConsole : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string console_type = userdata.asString();
-		if ("texture" == console_type)
-		{
-			toggle_visibility( (void*)gTextureView );
-		}
-		else if ("debug" == console_type)
-		{
-			toggle_visibility( (void*)static_cast<LLUICtrl*>(gDebugView->mDebugConsolep));
-		}
-		else if ("fast timers" == console_type)
-		{
-			LLFloaterReg::toggleInstance("block_timers");
-		}
-		else if ("scene view" == console_type)
-		{
-			toggle_visibility( (void*)gSceneView);
-		}
-		else if ("scene monitor" == console_type)
-		{
-			toggle_visibility( (void*)gSceneMonitorView);
-		}
-
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string console_type = userdata.asString();
+        if ("texture" == console_type)
+        {
+            toggle_visibility( (void*)gTextureView );
+        }
+        else if ("debug" == console_type)
+        {
+            toggle_visibility( (void*)static_cast<LLUICtrl*>(gDebugView->mDebugConsolep));
+        }
+        else if ("fast timers" == console_type)
+        {
+            LLFloaterReg::toggleInstance("block_timers");
+        }
+        else if ("scene view" == console_type)
+        {
+            toggle_visibility( (void*)gSceneView);
+        }
+        else if ("scene monitor" == console_type)
+        {
+            toggle_visibility( (void*)gSceneMonitorView);
+        }
+
+        return true;
+    }
 };
 class LLAdvancedCheckConsole : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string console_type = userdata.asString();
-		bool new_value = false;
-		if ("texture" == console_type)
-		{
-			new_value = get_visibility( (void*)gTextureView );
-		}
-		else if ("debug" == console_type)
-		{
-			new_value = get_visibility( (void*)((LLView*)gDebugView->mDebugConsolep) );
-		}
-		else if ("fast timers" == console_type)
-		{
-			new_value = LLFloaterReg::instanceVisible("block_timers");
-		}
-		else if ("scene view" == console_type)
-		{
-			new_value = get_visibility( (void*) gSceneView);
-		}
-		else if ("scene monitor" == console_type)
-		{
-			new_value = get_visibility( (void*) gSceneMonitorView);
-		}
-		
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string console_type = userdata.asString();
+        bool new_value = false;
+        if ("texture" == console_type)
+        {
+            new_value = get_visibility( (void*)gTextureView );
+        }
+        else if ("debug" == console_type)
+        {
+            new_value = get_visibility( (void*)((LLView*)gDebugView->mDebugConsolep) );
+        }
+        else if ("fast timers" == console_type)
+        {
+            new_value = LLFloaterReg::instanceVisible("block_timers");
+        }
+        else if ("scene view" == console_type)
+        {
+            new_value = get_visibility( (void*) gSceneView);
+        }
+        else if ("scene monitor" == console_type)
+        {
+            new_value = get_visibility( (void*) gSceneMonitorView);
+        }
+
+        return new_value;
+    }
 };
 
 
@@ -699,24 +699,24 @@ class LLAdvancedCheckConsole : public view_listener_t
 
 class LLAdvancedDumpInfoToConsole : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gDebugView->mDebugConsolep->setVisible(TRUE);
-		std::string info_type = userdata.asString();
-		if ("region" == info_type)
-		{
-			handle_region_dump_settings(NULL);
-		}
-		else if ("group" == info_type)
-		{
-			handle_dump_group_info(NULL);
-		}
-		else if ("capabilities" == info_type)
-		{
-			handle_dump_capabilities_info(NULL);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gDebugView->mDebugConsolep->setVisible(TRUE);
+        std::string info_type = userdata.asString();
+        if ("region" == info_type)
+        {
+            handle_region_dump_settings(NULL);
+        }
+        else if ("group" == info_type)
+        {
+            handle_dump_group_info(NULL);
+        }
+        else if ("capabilities" == info_type)
+        {
+            handle_dump_capabilities_info(NULL);
+        }
+        return true;
+    }
 };
 
 
@@ -727,54 +727,54 @@ class LLAdvancedDumpInfoToConsole : public view_listener_t
 
 class LLAdvancedToggleHUDInfo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string info_type = userdata.asString();
-
-		if ("camera" == info_type)
-		{
-			gDisplayCameraPos = !(gDisplayCameraPos);
-		}
-		else if ("wind" == info_type)
-		{
-			gDisplayWindInfo = !(gDisplayWindInfo);
-		}
-		else if ("fov" == info_type)
-		{
-			gDisplayFOV = !(gDisplayFOV);
-		}
-		else if ("badge" == info_type)
-		{
-			gDisplayBadge = !(gDisplayBadge);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string info_type = userdata.asString();
+
+        if ("camera" == info_type)
+        {
+            gDisplayCameraPos = !(gDisplayCameraPos);
+        }
+        else if ("wind" == info_type)
+        {
+            gDisplayWindInfo = !(gDisplayWindInfo);
+        }
+        else if ("fov" == info_type)
+        {
+            gDisplayFOV = !(gDisplayFOV);
+        }
+        else if ("badge" == info_type)
+        {
+            gDisplayBadge = !(gDisplayBadge);
+        }
+        return true;
+    }
 };
 
 class LLAdvancedCheckHUDInfo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string info_type = userdata.asString();
-		bool new_value = false;
-		if ("camera" == info_type)
-		{
-			new_value = gDisplayCameraPos;
-		}
-		else if ("wind" == info_type)
-		{
-			new_value = gDisplayWindInfo;
-		}
-		else if ("fov" == info_type)
-		{
-			new_value = gDisplayFOV;
-		}
-		else if ("badge" == info_type)
-		{
-			new_value = gDisplayBadge;
-		}
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string info_type = userdata.asString();
+        bool new_value = false;
+        if ("camera" == info_type)
+        {
+            new_value = gDisplayCameraPos;
+        }
+        else if ("wind" == info_type)
+        {
+            new_value = gDisplayWindInfo;
+        }
+        else if ("fov" == info_type)
+        {
+            new_value = gDisplayFOV;
+        }
+        else if ("badge" == info_type)
+        {
+            new_value = gDisplayBadge;
+        }
+        return new_value;
+    }
 };
 
 
@@ -784,11 +784,11 @@ class LLAdvancedCheckHUDInfo : public view_listener_t
 
 class LLAdvancedClearGroupCache : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLGroupMgr::debugClearAllGroups(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLGroupMgr::debugClearAllGroups(NULL);
+        return true;
+    }
 };
 
 
@@ -799,18 +799,18 @@ class LLAdvancedClearGroupCache : public view_listener_t
 /////////////////
 U32 render_type_from_string(std::string render_type)
 {
-	if ("simple" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_SIMPLE;
-	}
+    if ("simple" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_SIMPLE;
+    }
     if ("materials" == render_type)
     {
         return LLPipeline::RENDER_TYPE_MATERIALS;
     }
-	else if ("alpha" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_ALPHA;
-	}
+    else if ("alpha" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_ALPHA;
+    }
     else if ("alpha_mask" == render_type)
     {
         return LLPipeline::RENDER_TYPE_ALPHA_MASK;
@@ -827,89 +827,89 @@ U32 render_type_from_string(std::string render_type)
     {
         return LLPipeline::RENDER_TYPE_GLOW;
     }
-	else if ("tree" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_TREE;
-	}
-	else if ("character" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_AVATAR;
-	}
-	else if ("controlAV" == render_type) // Animesh
-	{
-		return LLPipeline::RENDER_TYPE_CONTROL_AV;
-	}
-	else if ("surfacePatch" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_TERRAIN;
-	}
-	else if ("sky" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_SKY;
-	}
-	else if ("water" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_WATER;
-	}
-	else if ("volume" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_VOLUME;
-	}
-	else if ("grass" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_GRASS;
-	}
-	else if ("clouds" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_CLOUDS;
-	}
-	else if ("particles" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_PARTICLES;
-	}
-	else if ("bump" == render_type)
-	{
-		return LLPipeline::RENDER_TYPE_BUMP;
-	}
-    else if ("pbr" == render_type) 
+    else if ("tree" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_TREE;
+    }
+    else if ("character" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_AVATAR;
+    }
+    else if ("controlAV" == render_type) // Animesh
+    {
+        return LLPipeline::RENDER_TYPE_CONTROL_AV;
+    }
+    else if ("surfacePatch" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_TERRAIN;
+    }
+    else if ("sky" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_SKY;
+    }
+    else if ("water" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_WATER;
+    }
+    else if ("volume" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_VOLUME;
+    }
+    else if ("grass" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_GRASS;
+    }
+    else if ("clouds" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_CLOUDS;
+    }
+    else if ("particles" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_PARTICLES;
+    }
+    else if ("bump" == render_type)
+    {
+        return LLPipeline::RENDER_TYPE_BUMP;
+    }
+    else if ("pbr" == render_type)
     {
         return LLPipeline::RENDER_TYPE_GLTF_PBR;
     }
-	else
-	{
-		return 0;
-	}
+    else
+    {
+        return 0;
+    }
 }
 
 
 class LLAdvancedToggleRenderType : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		U32 render_type = render_type_from_string( userdata.asString() );
-		if ( render_type != 0 )
-		{
-			LLPipeline::toggleRenderTypeControl( render_type );
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        U32 render_type = render_type_from_string( userdata.asString() );
+        if ( render_type != 0 )
+        {
+            LLPipeline::toggleRenderTypeControl( render_type );
+        }
+        return true;
+    }
 };
 
 
 class LLAdvancedCheckRenderType : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		U32 render_type = render_type_from_string( userdata.asString() );
-		bool new_value = false;
+    bool handleEvent(const LLSD& userdata)
+    {
+        U32 render_type = render_type_from_string( userdata.asString() );
+        bool new_value = false;
 
-		if ( render_type != 0 )
-		{
-			new_value = LLPipeline::hasRenderTypeControl( render_type );
-		}
+        if ( render_type != 0 )
+        {
+            new_value = LLPipeline::hasRenderTypeControl( render_type );
+        }
 
-		return new_value;
-	}
+        return new_value;
+    }
 };
 
 
@@ -917,140 +917,140 @@ class LLAdvancedCheckRenderType : public view_listener_t
 // FEATURE //
 /////////////
 U32 feature_from_string(std::string feature)
-{ 
-	if ("ui" == feature)
-	{ 
-		return LLPipeline::RENDER_DEBUG_FEATURE_UI;
-	}
-	else if ("selected" == feature)
-	{
-		return LLPipeline::RENDER_DEBUG_FEATURE_SELECTED;
-	}
-	else if ("highlighted" == feature)
-	{
-		return LLPipeline::RENDER_DEBUG_FEATURE_HIGHLIGHTED;
-	}
-	else if ("dynamic textures" == feature)
-	{
-		return LLPipeline::RENDER_DEBUG_FEATURE_DYNAMIC_TEXTURES;
-	}
-	else if ("foot shadows" == feature)
-	{
-		return LLPipeline::RENDER_DEBUG_FEATURE_FOOT_SHADOWS;
-	}
-	else if ("fog" == feature)
-	{
-		return LLPipeline::RENDER_DEBUG_FEATURE_FOG;
-	}
-	else if ("fr info" == feature)
-	{
-		return LLPipeline::RENDER_DEBUG_FEATURE_FR_INFO;
-	}
-	else if ("flexible" == feature)
-	{
-		return LLPipeline::RENDER_DEBUG_FEATURE_FLEXIBLE;
-	}
-	else
-	{
-		return 0;
-	}
+{
+    if ("ui" == feature)
+    {
+        return LLPipeline::RENDER_DEBUG_FEATURE_UI;
+    }
+    else if ("selected" == feature)
+    {
+        return LLPipeline::RENDER_DEBUG_FEATURE_SELECTED;
+    }
+    else if ("highlighted" == feature)
+    {
+        return LLPipeline::RENDER_DEBUG_FEATURE_HIGHLIGHTED;
+    }
+    else if ("dynamic textures" == feature)
+    {
+        return LLPipeline::RENDER_DEBUG_FEATURE_DYNAMIC_TEXTURES;
+    }
+    else if ("foot shadows" == feature)
+    {
+        return LLPipeline::RENDER_DEBUG_FEATURE_FOOT_SHADOWS;
+    }
+    else if ("fog" == feature)
+    {
+        return LLPipeline::RENDER_DEBUG_FEATURE_FOG;
+    }
+    else if ("fr info" == feature)
+    {
+        return LLPipeline::RENDER_DEBUG_FEATURE_FR_INFO;
+    }
+    else if ("flexible" == feature)
+    {
+        return LLPipeline::RENDER_DEBUG_FEATURE_FLEXIBLE;
+    }
+    else
+    {
+        return 0;
+    }
 };
 
 
 class LLAdvancedToggleFeature : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		U32 feature = feature_from_string( userdata.asString() );
-		if ( feature != 0 )
-		{
-			LLPipeline::toggleRenderDebugFeature( feature );
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        U32 feature = feature_from_string( userdata.asString() );
+        if ( feature != 0 )
+        {
+            LLPipeline::toggleRenderDebugFeature( feature );
+        }
+        return true;
+    }
 };
 
 class LLAdvancedCheckFeature : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
+    bool handleEvent(const LLSD& userdata)
 {
-	U32 feature = feature_from_string( userdata.asString() );
-	bool new_value = false;
+    U32 feature = feature_from_string( userdata.asString() );
+    bool new_value = false;
 
-	if ( feature != 0 )
-	{
-		new_value = LLPipeline::toggleRenderDebugFeatureControl( feature );
-	}
+    if ( feature != 0 )
+    {
+        new_value = LLPipeline::toggleRenderDebugFeatureControl( feature );
+    }
 
-	return new_value;
+    return new_value;
 }
 };
 
 class LLAdvancedCheckDisplayTextureDensity : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string mode = userdata.asString();
-		if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY))
-		{
-			return mode == "none";
-		}
-		if (mode == "current")
-		{
-			return LLViewerTexture::sDebugTexelsMode == LLViewerTexture::DEBUG_TEXELS_CURRENT;
-		}
-		else if (mode == "desired")
-		{
-			return LLViewerTexture::sDebugTexelsMode == LLViewerTexture::DEBUG_TEXELS_DESIRED;
-		}
-		else if (mode == "full")
-		{
-			return LLViewerTexture::sDebugTexelsMode == LLViewerTexture::DEBUG_TEXELS_FULL;
-		}
-		return false;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string mode = userdata.asString();
+        if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY))
+        {
+            return mode == "none";
+        }
+        if (mode == "current")
+        {
+            return LLViewerTexture::sDebugTexelsMode == LLViewerTexture::DEBUG_TEXELS_CURRENT;
+        }
+        else if (mode == "desired")
+        {
+            return LLViewerTexture::sDebugTexelsMode == LLViewerTexture::DEBUG_TEXELS_DESIRED;
+        }
+        else if (mode == "full")
+        {
+            return LLViewerTexture::sDebugTexelsMode == LLViewerTexture::DEBUG_TEXELS_FULL;
+        }
+        return false;
+    }
 };
 
 class LLAdvancedSetDisplayTextureDensity : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string mode = userdata.asString();
-		if (mode == "none")
-		{
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY) == TRUE) 
-			{
-				gPipeline.toggleRenderDebug(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY);
-			}
-			LLViewerTexture::sDebugTexelsMode = LLViewerTexture::DEBUG_TEXELS_OFF;
-		}
-		else if (mode == "current")
-		{
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY) == FALSE) 
-			{
-				gPipeline.toggleRenderDebug(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY);
-			}
-			LLViewerTexture::sDebugTexelsMode = LLViewerTexture::DEBUG_TEXELS_CURRENT;
-		}
-		else if (mode == "desired")
-		{
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY) == FALSE) 
-			{
-				gPipeline.toggleRenderDebug(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY);
-			}
-			gPipeline.setRenderDebugFeatureControl(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY, true);
-			LLViewerTexture::sDebugTexelsMode = LLViewerTexture::DEBUG_TEXELS_DESIRED;
-		}
-		else if (mode == "full")
-		{
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY) == FALSE) 
-			{
-				gPipeline.toggleRenderDebug(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY);
-			}
-			LLViewerTexture::sDebugTexelsMode = LLViewerTexture::DEBUG_TEXELS_FULL;
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string mode = userdata.asString();
+        if (mode == "none")
+        {
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY) == TRUE)
+            {
+                gPipeline.toggleRenderDebug(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY);
+            }
+            LLViewerTexture::sDebugTexelsMode = LLViewerTexture::DEBUG_TEXELS_OFF;
+        }
+        else if (mode == "current")
+        {
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY) == FALSE)
+            {
+                gPipeline.toggleRenderDebug(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY);
+            }
+            LLViewerTexture::sDebugTexelsMode = LLViewerTexture::DEBUG_TEXELS_CURRENT;
+        }
+        else if (mode == "desired")
+        {
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY) == FALSE)
+            {
+                gPipeline.toggleRenderDebug(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY);
+            }
+            gPipeline.setRenderDebugFeatureControl(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY, true);
+            LLViewerTexture::sDebugTexelsMode = LLViewerTexture::DEBUG_TEXELS_DESIRED;
+        }
+        else if (mode == "full")
+        {
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY) == FALSE)
+            {
+                gPipeline.toggleRenderDebug(LLPipeline::RENDER_DEBUG_TEXEL_DENSITY);
+            }
+            LLViewerTexture::sDebugTexelsMode = LLViewerTexture::DEBUG_TEXELS_FULL;
+        }
+        return true;
+    }
 };
 
 
@@ -1059,197 +1059,197 @@ class LLAdvancedSetDisplayTextureDensity : public view_listener_t
 //////////////////
 U64 info_display_from_string(std::string info_display)
 {
-	if ("verify" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_VERIFY;
-	}
-	else if ("bboxes" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_BBOXES;
-	}
-	else if ("normals" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_NORMALS;
-	}
-	else if ("points" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_POINTS;
-	}
-	else if ("octree" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_OCTREE;
-	}
+    if ("verify" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_VERIFY;
+    }
+    else if ("bboxes" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_BBOXES;
+    }
+    else if ("normals" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_NORMALS;
+    }
+    else if ("points" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_POINTS;
+    }
+    else if ("octree" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_OCTREE;
+    }
     else if ("nodes" == info_display)
     {
         return LLPipeline::RENDER_DEBUG_NODES;
     }
-	else if ("shadow frusta" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA;
-	}
-	else if ("physics shapes" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_PHYSICS_SHAPES;
-	}
-	else if ("occlusion" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_OCCLUSION;
-	}
-	else if ("render batches" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_BATCH_SIZE;
-	}
-	else if ("update type" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_UPDATE_TYPE;
-	}
-	else if ("texture anim" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_TEXTURE_ANIM;
-	}
-	else if ("texture priority" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY;
-	}
-	else if ("texture area" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_TEXTURE_AREA;
-	}
-	else if ("face area" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_FACE_AREA;
-	}
-	else if ("lod info" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_LOD_INFO;
-	}
-	else if ("lights" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_LIGHTS;
-	}
-	else if ("particles" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_PARTICLES;
-	}
-	else if ("composition" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_COMPOSITION;
-	}
-	else if ("avatardrawinfo" == info_display)
-	{
-		return (LLPipeline::RENDER_DEBUG_AVATAR_DRAW_INFO);
-	}
-	else if ("glow" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_GLOW;
-	}
-	else if ("collision skeleton" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_AVATAR_VOLUME;
-	}
-	else if ("joints" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_AVATAR_JOINTS;
-	}
-	else if ("raycast" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_RAYCAST;
-	}
-	else if ("agent target" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_AGENT_TARGET;
-	}
-	else if ("sculpt" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_SCULPTED;
-	}
-	else if ("wind vectors" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_WIND_VECTORS;
-	}
-	else if ("texel density" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_TEXEL_DENSITY;
-	}
-	else if ("triangle count" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_TRIANGLE_COUNT;
-	}
-	else if ("impostors" == info_display)
-	{
-		return LLPipeline::RENDER_DEBUG_IMPOSTORS;
-	}
-    else if ("reflection probes" == info_display)
+    else if ("shadow frusta" == info_display)
     {
-        return LLPipeline::RENDER_DEBUG_REFLECTION_PROBES;
+        return LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA;
     }
-    else if ("probe updates" == info_display)
+    else if ("physics shapes" == info_display)
     {
-        return LLPipeline::RENDER_DEBUG_PROBE_UPDATES;
+        return LLPipeline::RENDER_DEBUG_PHYSICS_SHAPES;
     }
-	else
-	{
-		LL_WARNS() << "unrecognized feature name '" << info_display << "'" << LL_ENDL;
-		return 0;
-	}
-};
-
-class LLAdvancedToggleInfoDisplay : public view_listener_t
-{
-	bool handleEvent(const LLSD& userdata)
-	{
-		U64 info_display = info_display_from_string( userdata.asString() );
-
-		LL_INFOS("ViewerMenu") << "toggle " << userdata.asString() << LL_ENDL;
-		
-		if ( info_display != 0 )
-		{
-			LLPipeline::toggleRenderDebug( info_display );
-		}
-
-		return true;
-	}
-};
-
-
-class LLAdvancedCheckInfoDisplay : public view_listener_t
-{
-	bool handleEvent(const LLSD& userdata)
-	{
-		U64 info_display = info_display_from_string( userdata.asString() );
-		bool new_value = false;
-
-		if ( info_display != 0 )
-		{
-			new_value = LLPipeline::toggleRenderDebugControl( info_display );
-		}
-
-		return new_value;
-	}
-};
-
-
-///////////////////////////
-//// RANDOMIZE FRAMERATE //
-///////////////////////////
-
-
+    else if ("occlusion" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_OCCLUSION;
+    }
+    else if ("render batches" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_BATCH_SIZE;
+    }
+    else if ("update type" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_UPDATE_TYPE;
+    }
+    else if ("texture anim" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_TEXTURE_ANIM;
+    }
+    else if ("texture priority" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY;
+    }
+    else if ("texture area" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_TEXTURE_AREA;
+    }
+    else if ("face area" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_FACE_AREA;
+    }
+    else if ("lod info" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_LOD_INFO;
+    }
+    else if ("lights" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_LIGHTS;
+    }
+    else if ("particles" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_PARTICLES;
+    }
+    else if ("composition" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_COMPOSITION;
+    }
+    else if ("avatardrawinfo" == info_display)
+    {
+        return (LLPipeline::RENDER_DEBUG_AVATAR_DRAW_INFO);
+    }
+    else if ("glow" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_GLOW;
+    }
+    else if ("collision skeleton" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_AVATAR_VOLUME;
+    }
+    else if ("joints" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_AVATAR_JOINTS;
+    }
+    else if ("raycast" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_RAYCAST;
+    }
+    else if ("agent target" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_AGENT_TARGET;
+    }
+    else if ("sculpt" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_SCULPTED;
+    }
+    else if ("wind vectors" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_WIND_VECTORS;
+    }
+    else if ("texel density" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_TEXEL_DENSITY;
+    }
+    else if ("triangle count" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_TRIANGLE_COUNT;
+    }
+    else if ("impostors" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_IMPOSTORS;
+    }
+    else if ("reflection probes" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_REFLECTION_PROBES;
+    }
+    else if ("probe updates" == info_display)
+    {
+        return LLPipeline::RENDER_DEBUG_PROBE_UPDATES;
+    }
+    else
+    {
+        LL_WARNS() << "unrecognized feature name '" << info_display << "'" << LL_ENDL;
+        return 0;
+    }
+};
+
+class LLAdvancedToggleInfoDisplay : public view_listener_t
+{
+    bool handleEvent(const LLSD& userdata)
+    {
+        U64 info_display = info_display_from_string( userdata.asString() );
+
+        LL_INFOS("ViewerMenu") << "toggle " << userdata.asString() << LL_ENDL;
+
+        if ( info_display != 0 )
+        {
+            LLPipeline::toggleRenderDebug( info_display );
+        }
+
+        return true;
+    }
+};
+
+
+class LLAdvancedCheckInfoDisplay : public view_listener_t
+{
+    bool handleEvent(const LLSD& userdata)
+    {
+        U64 info_display = info_display_from_string( userdata.asString() );
+        bool new_value = false;
+
+        if ( info_display != 0 )
+        {
+            new_value = LLPipeline::toggleRenderDebugControl( info_display );
+        }
+
+        return new_value;
+    }
+};
+
+
+///////////////////////////
+//// RANDOMIZE FRAMERATE //
+///////////////////////////
+
+
 class LLAdvancedToggleRandomizeFramerate : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gRandomizeFramerate = !(gRandomizeFramerate);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gRandomizeFramerate = !(gRandomizeFramerate);
+        return true;
+    }
 };
 
 class LLAdvancedCheckRandomizeFramerate : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gRandomizeFramerate;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gRandomizeFramerate;
+        return new_value;
+    }
 };
 
 ///////////////////////////
@@ -1259,36 +1259,36 @@ class LLAdvancedCheckRandomizeFramerate : public view_listener_t
 
 class LLAdvancedTogglePeriodicSlowFrame : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gPeriodicSlowFrame = !(gPeriodicSlowFrame);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gPeriodicSlowFrame = !(gPeriodicSlowFrame);
+        return true;
+    }
 };
 
 class LLAdvancedCheckPeriodicSlowFrame : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gPeriodicSlowFrame;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gPeriodicSlowFrame;
+        return new_value;
+    }
 };
 
 
 ///////////////////////////
 // SELECTED TEXTURE INFO //
-// 
+//
 ///////////////////////////
 
 
 class LLAdvancedSelectedTextureInfo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_selected_texture_info(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_selected_texture_info(NULL);
+        return true;
+    }
 };
 
 //////////////////////
@@ -1297,50 +1297,50 @@ class LLAdvancedSelectedTextureInfo : public view_listener_t
 
 class LLAdvancedToggleWireframe : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 // [RLVa:KB] - @detach and @viewwireframe
-		const bool fRlvCanViewWireframe = RlvActions::canViewWireframe();
-		if ( (!gUseWireframe) && (!fRlvCanViewWireframe) )
-			RlvUtil::notifyBlocked(RlvStringKeys::Blocked::Wireframe);
-		set_use_wireframe( (!gUseWireframe) && (fRlvCanViewWireframe) );
-		return true;
-	}
+        const bool fRlvCanViewWireframe = RlvActions::canViewWireframe();
+        if ( (!gUseWireframe) && (!fRlvCanViewWireframe) )
+            RlvUtil::notifyBlocked(RlvStringKeys::Blocked::Wireframe);
+        set_use_wireframe( (!gUseWireframe) && (fRlvCanViewWireframe) );
+        return true;
+    }
 };
 
 // Called from rlvhandler.cpp
 void set_use_wireframe(bool useWireframe)
-	{
-		if (gUseWireframe == useWireframe)
-			return;
+    {
+        if (gUseWireframe == useWireframe)
+            return;
 
-		gUseWireframe = useWireframe;
+        gUseWireframe = useWireframe;
 // [/RLVa:KB]
-//		gUseWireframe = !(gUseWireframe);
+//      gUseWireframe = !(gUseWireframe);
 
-//		return true;
-	}
+//      return true;
+    }
 //};
 
 class LLAdvancedCheckWireframe : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return gUseWireframe;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return gUseWireframe;
+    }
 };
-	
+
 
 //////////////////////////
 // DUMP SCRIPTED CAMERA //
 //////////////////////////
-	
+
 class LLAdvancedDumpScriptedCamera : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_dump_followcam(NULL);
-		return true;
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_dump_followcam(NULL);
+        return true;
 }
 };
 
@@ -1353,11 +1353,11 @@ class LLAdvancedDumpScriptedCamera : public view_listener_t
 
 class LLAdvancedDumpRegionObjectCache : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_dump_region_object_cache(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_dump_region_object_cache(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedToggleInterestList360Mode : public view_listener_t
@@ -1368,22 +1368,22 @@ class LLAdvancedToggleInterestList360Mode : public view_listener_t
         // Toggle the mode - regions will get updated
         if (gAgent.getInterestListMode() == LLViewerRegion::IL_MODE_360)
         {
-			gAgent.changeInterestListMode(LLViewerRegion::IL_MODE_DEFAULT);
-		}
-		else
-		{
-			gAgent.changeInterestListMode(LLViewerRegion::IL_MODE_360);
-		}
+            gAgent.changeInterestListMode(LLViewerRegion::IL_MODE_DEFAULT);
+        }
+        else
+        {
+            gAgent.changeInterestListMode(LLViewerRegion::IL_MODE_360);
+        }
         return true;
     }
 };
 
 class LLAdvancedCheckInterestList360Mode : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return (gAgent.getInterestListMode() == LLViewerRegion::IL_MODE_360);
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return (gAgent.getInterestListMode() == LLViewerRegion::IL_MODE_360);
+    }
 };
 
 class LLAdvancedToggleStatsRecorder : public view_listener_t
@@ -1391,13 +1391,13 @@ class LLAdvancedToggleStatsRecorder : public view_listener_t
     bool handleEvent(const LLSD &userdata)
     {
         if (LLViewerStatsRecorder::instance().isEnabled())
-		{	// Turn off both recording and logging
-			LLViewerStatsRecorder::instance().enableObjectStatsRecording(false);
-		}
-		else
-		{	// Turn on both recording and logging
-			LLViewerStatsRecorder::instance().enableObjectStatsRecording(true, true);
-		}
+        {   // Turn off both recording and logging
+            LLViewerStatsRecorder::instance().enableObjectStatsRecording(false);
+        }
+        else
+        {   // Turn on both recording and logging
+            LLViewerStatsRecorder::instance().enableObjectStatsRecording(true, true);
+        }
         return true;
     }
 };
@@ -1405,7 +1405,7 @@ class LLAdvancedToggleStatsRecorder : public view_listener_t
 class LLAdvancedCheckStatsRecorder : public view_listener_t
 {
     bool handleEvent(const LLSD &userdata)
-    {	// Use the logging state as the indicator of whether the stats recorder is on
+    {   // Use the logging state as the indicator of whether the stats recorder is on
         return LLViewerStatsRecorder::instance().isLogging();
     }
 };
@@ -1413,7 +1413,7 @@ class LLAdvancedCheckStatsRecorder : public view_listener_t
 class LLAdvancedResetInterestLists : public view_listener_t
 {
     bool handleEvent(const LLSD &userdata)
-    {	// Reset all region interest lists
+    {   // Reset all region interest lists
         handle_reset_interest_lists(NULL);
         return true;
     }
@@ -1421,12 +1421,12 @@ class LLAdvancedResetInterestLists : public view_listener_t
 
 
 class LLAdvancedBuyCurrencyTest : public view_listener_t
-	{
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_buy_currency_test(NULL);
-		return true;
-	}
+    {
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_buy_currency_test(NULL);
+        return true;
+    }
 };
 
 
@@ -1437,11 +1437,11 @@ class LLAdvancedBuyCurrencyTest : public view_listener_t
 
 class LLAdvancedDumpSelectMgr : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		dump_select_mgr(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        dump_select_mgr(NULL);
+        return true;
+    }
 };
 
 
@@ -1453,11 +1453,11 @@ class LLAdvancedDumpSelectMgr : public view_listener_t
 
 class LLAdvancedDumpInventory : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		dump_inventory(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        dump_inventory(NULL);
+        return true;
+    }
 };
 
 
@@ -1469,11 +1469,11 @@ class LLAdvancedDumpInventory : public view_listener_t
 
 class LLAdvancedPrintSelectedObjectInfo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		print_object_info(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        print_object_info(NULL);
+        return true;
+    }
 };
 
 
@@ -1485,11 +1485,11 @@ class LLAdvancedPrintSelectedObjectInfo : public view_listener_t
 
 class LLAdvancedPrintAgentInfo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		print_agent_nvpairs(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        print_agent_nvpairs(NULL);
+        return true;
+    }
 };
 
 //////////////////
@@ -1499,20 +1499,20 @@ class LLAdvancedPrintAgentInfo : public view_listener_t
 
 class LLAdvancedToggleDebugClicks : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gDebugClicks = !(gDebugClicks);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gDebugClicks = !(gDebugClicks);
+        return true;
+    }
 };
 
 class LLAdvancedCheckDebugClicks : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gDebugClicks;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gDebugClicks;
+        return new_value;
+    }
 };
 
 
@@ -1524,20 +1524,20 @@ class LLAdvancedCheckDebugClicks : public view_listener_t
 
 class LLAdvancedToggleDebugViews : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLView::sDebugRects = !(LLView::sDebugRects);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLView::sDebugRects = !(LLView::sDebugRects);
+        return true;
+    }
 };
 
 class LLAdvancedCheckDebugViews : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLView::sDebugRects;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLView::sDebugRects;
+        return new_value;
+    }
 };
 
 
@@ -1549,19 +1549,19 @@ class LLAdvancedCheckDebugViews : public view_listener_t
 
 class LLAdvancedToggleDebugUnicode : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLView::sDebugUnicode = !(LLView::sDebugUnicode);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLView::sDebugUnicode = !(LLView::sDebugUnicode);
+        return true;
+    }
 };
 
 class LLAdvancedCheckDebugUnicode : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return LLView::sDebugUnicode;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return LLView::sDebugUnicode;
+    }
 };
 
 
@@ -1573,20 +1573,20 @@ class LLAdvancedCheckDebugUnicode : public view_listener_t
 
 class LLAdvancedToggleDebugCamera : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLView::sDebugCamera = !(LLView::sDebugCamera);
-		LLFloaterCamera::onDebugCameraToggled();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLView::sDebugCamera = !(LLView::sDebugCamera);
+        LLFloaterCamera::onDebugCameraToggled();
+        return true;
+    }
 };
 
 class LLAdvancedCheckDebugCamera : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return LLView::sDebugCamera;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return LLView::sDebugCamera;
+    }
 };
 
 
@@ -1598,20 +1598,20 @@ class LLAdvancedCheckDebugCamera : public view_listener_t
 
 class LLAdvancedToggleXUINameTooltips : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		toggle_show_xui_names(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        toggle_show_xui_names(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedCheckXUINameTooltips : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = check_show_xui_names(NULL);
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = check_show_xui_names(NULL);
+        return new_value;
+    }
 };
 
 
@@ -1623,20 +1623,20 @@ class LLAdvancedCheckXUINameTooltips : public view_listener_t
 
 class LLAdvancedToggleDebugMouseEvents : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLView::sDebugMouseHandling = !(LLView::sDebugMouseHandling);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLView::sDebugMouseHandling = !(LLView::sDebugMouseHandling);
+        return true;
+    }
 };
 
 class LLAdvancedCheckDebugMouseEvents : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLView::sDebugMouseHandling;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLView::sDebugMouseHandling;
+        return new_value;
+    }
 };
 
 
@@ -1648,22 +1648,22 @@ class LLAdvancedCheckDebugMouseEvents : public view_listener_t
 
 class LLAdvancedToggleDebugKeys : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLView::sDebugKeys = !(LLView::sDebugKeys);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLView::sDebugKeys = !(LLView::sDebugKeys);
+        return true;
+    }
 };
-	
+
 class LLAdvancedCheckDebugKeys : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLView::sDebugKeys;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLView::sDebugKeys;
+        return new_value;
+    }
 };
-	
+
 
 
 ///////////////////////
@@ -1673,30 +1673,30 @@ class LLAdvancedCheckDebugKeys : public view_listener_t
 
 class LLAdvancedToggleDebugWindowProc : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gDebugWindowProc = !(gDebugWindowProc);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gDebugWindowProc = !(gDebugWindowProc);
+        return true;
+    }
 };
 
 class LLAdvancedCheckDebugWindowProc : public view_listener_t
-	{
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gDebugWindowProc;
-		return new_value;
-	}
+    {
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gDebugWindowProc;
+        return new_value;
+    }
 };
 
 // ------------------------------XUI MENU ---------------------------
 
 class LLAdvancedSendTestIms : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLIMModel::instance().testMessages();
-		return true;
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLIMModel::instance().testMessages();
+        return true;
 }
 };
 
@@ -1708,20 +1708,20 @@ class LLAdvancedSendTestIms : public view_listener_t
 
 class LLAdvancedToggleXUINames : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		toggle_show_xui_names(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        toggle_show_xui_names(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedCheckXUINames : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = check_show_xui_names(NULL);
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = check_show_xui_names(NULL);
+        return new_value;
+    }
 };
 
 
@@ -1732,73 +1732,73 @@ class LLAdvancedCheckXUINames : public view_listener_t
 
 class LLAdvancedGrabBakedTexture : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string texture_type = userdata.asString();
-		if ("iris" == texture_type)
-		{
-			handle_grab_baked_texture( (void*)BAKED_EYES );
-		}
-		else if ("head" == texture_type)
-		{
-			handle_grab_baked_texture( (void*)BAKED_HEAD );
-		}
-		else if ("upper" == texture_type)
-		{
-			handle_grab_baked_texture( (void*)BAKED_UPPER );
-		}
-		else if ("lower" == texture_type)
-		{
-			handle_grab_baked_texture( (void*)BAKED_LOWER );
-		}
-		else if ("skirt" == texture_type)
-		{
-			handle_grab_baked_texture( (void*)BAKED_SKIRT );
-		}
-		else if ("hair" == texture_type)
-		{
-			handle_grab_baked_texture( (void*)BAKED_HAIR );
-		}
-
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string texture_type = userdata.asString();
+        if ("iris" == texture_type)
+        {
+            handle_grab_baked_texture( (void*)BAKED_EYES );
+        }
+        else if ("head" == texture_type)
+        {
+            handle_grab_baked_texture( (void*)BAKED_HEAD );
+        }
+        else if ("upper" == texture_type)
+        {
+            handle_grab_baked_texture( (void*)BAKED_UPPER );
+        }
+        else if ("lower" == texture_type)
+        {
+            handle_grab_baked_texture( (void*)BAKED_LOWER );
+        }
+        else if ("skirt" == texture_type)
+        {
+            handle_grab_baked_texture( (void*)BAKED_SKIRT );
+        }
+        else if ("hair" == texture_type)
+        {
+            handle_grab_baked_texture( (void*)BAKED_HAIR );
+        }
+
+        return true;
+    }
 };
 
 class LLAdvancedEnableGrabBakedTexture : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-{
-		std::string texture_type = userdata.asString();
-		bool new_value = false;
-
-		if ("iris" == texture_type)
-		{
-			new_value = enable_grab_baked_texture( (void*)BAKED_EYES );
-		}
-		else if ("head" == texture_type)
-		{
-			new_value = enable_grab_baked_texture( (void*)BAKED_HEAD );
-		}
-		else if ("upper" == texture_type)
-		{
-			new_value = enable_grab_baked_texture( (void*)BAKED_UPPER );
-		}
-		else if ("lower" == texture_type)
-		{
-			new_value = enable_grab_baked_texture( (void*)BAKED_LOWER );
-		}
-		else if ("skirt" == texture_type)
-		{
-			new_value = enable_grab_baked_texture( (void*)BAKED_SKIRT );
-		}
-		else if ("hair" == texture_type)
-		{
-			new_value = enable_grab_baked_texture( (void*)BAKED_HAIR );
-		}
-	
-		return new_value;
-}
-};
+    bool handleEvent(const LLSD& userdata)
+{
+        std::string texture_type = userdata.asString();
+        bool new_value = false;
+
+        if ("iris" == texture_type)
+        {
+            new_value = enable_grab_baked_texture( (void*)BAKED_EYES );
+        }
+        else if ("head" == texture_type)
+        {
+            new_value = enable_grab_baked_texture( (void*)BAKED_HEAD );
+        }
+        else if ("upper" == texture_type)
+        {
+            new_value = enable_grab_baked_texture( (void*)BAKED_UPPER );
+        }
+        else if ("lower" == texture_type)
+        {
+            new_value = enable_grab_baked_texture( (void*)BAKED_LOWER );
+        }
+        else if ("skirt" == texture_type)
+        {
+            new_value = enable_grab_baked_texture( (void*)BAKED_SKIRT );
+        }
+        else if ("hair" == texture_type)
+        {
+            new_value = enable_grab_baked_texture( (void*)BAKED_HAIR );
+        }
+
+        return new_value;
+}
+};
 
 ///////////////////////
 // APPEARANCE TO XML //
@@ -1807,8 +1807,8 @@ class LLAdvancedEnableGrabBakedTexture : public view_listener_t
 
 class LLAdvancedEnableAppearanceToXML : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
         LLViewerObject *obj = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
         if (obj && obj->isAnimatedObject() && obj->getControlAvatar())
         {
@@ -1823,18 +1823,18 @@ class LLAdvancedEnableAppearanceToXML : public view_listener_t
             // This has to be a non-control avatar, because control avs are invisible and unclickable.
             return gSavedSettings.getBOOL("DebugAvatarAppearanceMessage");
         }
-		else
-		{
-			return false;
-		}
-	}
+        else
+        {
+            return false;
+        }
+    }
 };
 
 class LLAdvancedAppearanceToXML : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string emptyname;
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string emptyname;
         LLViewerObject *obj = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
         LLVOAvatar *avatar = NULL;
         if (obj)
@@ -1857,14 +1857,14 @@ class LLAdvancedAppearanceToXML : public view_listener_t
         else
         {
             // If no selection, use the self avatar.
-			avatar = gAgentAvatarp;
+            avatar = gAgentAvatarp;
         }
         if (avatar)
         {
             avatar->dumpArchetypeXML(emptyname);
         }
-		return true;
-	}
+        return true;
+    }
 };
 
 
@@ -1876,44 +1876,44 @@ class LLAdvancedAppearanceToXML : public view_listener_t
 
 class LLAdvancedToggleCharacterGeometry : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_god_request_avatar_geometry(NULL);
-		return true;
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_god_request_avatar_geometry(NULL);
+        return true;
 }
 };
 
 
-	/////////////////////////////
+    /////////////////////////////
 // TEST MALE / TEST FEMALE //
 /////////////////////////////
 
 class LLAdvancedTestMale : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_test_male(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_test_male(NULL);
+        return true;
+    }
 };
 
 
 class LLAdvancedTestFemale : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_test_female(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_test_female(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedForceParamsToDefault : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLAgent::clearVisualParams(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLAgent::clearVisualParams(NULL);
+        return true;
+    }
 };
 
 
@@ -1922,47 +1922,47 @@ class LLAdvancedForceParamsToDefault : public view_listener_t
 //////////////////////////
 
 // Utility function to set all AV time factors to the same global value
-static void set_all_animation_time_factors(F32	time_factor)
+static void set_all_animation_time_factors(F32  time_factor)
 {
-	LLMotionController::setCurrentTimeFactor(time_factor);
-	for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
-		iter != LLCharacter::sInstances.end(); ++iter)
-	{
-		(*iter)->setAnimTimeFactor(time_factor);
-	}
+    LLMotionController::setCurrentTimeFactor(time_factor);
+    for (std::vector<LLCharacter*>::iterator iter = LLCharacter::sInstances.begin();
+        iter != LLCharacter::sInstances.end(); ++iter)
+    {
+        (*iter)->setAnimTimeFactor(time_factor);
+    }
 }
 
 class LLAdvancedAnimTenFaster : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		//LL_INFOS() << "LLAdvancedAnimTenFaster" << LL_ENDL;
-		F32 time_factor = LLMotionController::getCurrentTimeFactor();
-		time_factor = llmin(time_factor + 0.1f, 2.f);	// Upper limit is 200% speed
-		set_all_animation_time_factors(time_factor);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        //LL_INFOS() << "LLAdvancedAnimTenFaster" << LL_ENDL;
+        F32 time_factor = LLMotionController::getCurrentTimeFactor();
+        time_factor = llmin(time_factor + 0.1f, 2.f);   // Upper limit is 200% speed
+        set_all_animation_time_factors(time_factor);
+        return true;
+    }
 };
 
 class LLAdvancedAnimTenSlower : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		//LL_INFOS() << "LLAdvancedAnimTenSlower" << LL_ENDL;
-		F32 time_factor = LLMotionController::getCurrentTimeFactor();
-		time_factor = llmax(time_factor - 0.1f, 0.1f);	// Lower limit is at 10% of normal speed
-		set_all_animation_time_factors(time_factor);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        //LL_INFOS() << "LLAdvancedAnimTenSlower" << LL_ENDL;
+        F32 time_factor = LLMotionController::getCurrentTimeFactor();
+        time_factor = llmax(time_factor - 0.1f, 0.1f);  // Lower limit is at 10% of normal speed
+        set_all_animation_time_factors(time_factor);
+        return true;
+    }
 };
 
 class LLAdvancedAnimResetAll : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		set_all_animation_time_factors(1.f);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        set_all_animation_time_factors(1.f);
+        return true;
+    }
 };
 
 
@@ -1973,11 +1973,11 @@ class LLAdvancedAnimResetAll : public view_listener_t
 
 class LLAdvancedReloadVertexShader : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		reload_vertex_shader(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        reload_vertex_shader(NULL);
+        return true;
+    }
 };
 
 
@@ -1989,20 +1989,20 @@ class LLAdvancedReloadVertexShader : public view_listener_t
 
 class LLAdvancedToggleAnimationInfo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar::sShowAnimationDebug = !(LLVOAvatar::sShowAnimationDebug);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar::sShowAnimationDebug = !(LLVOAvatar::sShowAnimationDebug);
+        return true;
+    }
 };
 
 class LLAdvancedCheckAnimationInfo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLVOAvatar::sShowAnimationDebug;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLVOAvatar::sShowAnimationDebug;
+        return new_value;
+    }
 };
 
 
@@ -2013,20 +2013,20 @@ class LLAdvancedCheckAnimationInfo : public view_listener_t
 
 class LLAdvancedToggleShowLookAt : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLHUDEffectLookAt::sDebugLookAt = !(LLHUDEffectLookAt::sDebugLookAt);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLHUDEffectLookAt::sDebugLookAt = !(LLHUDEffectLookAt::sDebugLookAt);
+        return true;
+    }
 };
 
 class LLAdvancedCheckShowLookAt : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLHUDEffectLookAt::sDebugLookAt;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLHUDEffectLookAt::sDebugLookAt;
+        return new_value;
+    }
 };
 
 
@@ -2038,20 +2038,20 @@ class LLAdvancedCheckShowLookAt : public view_listener_t
 
 class LLAdvancedToggleShowPointAt : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLHUDEffectPointAt::sDebugPointAt = !(LLHUDEffectPointAt::sDebugPointAt);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLHUDEffectPointAt::sDebugPointAt = !(LLHUDEffectPointAt::sDebugPointAt);
+        return true;
+    }
 };
 
 class LLAdvancedCheckShowPointAt : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLHUDEffectPointAt::sDebugPointAt;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLHUDEffectPointAt::sDebugPointAt;
+        return new_value;
+    }
 };
 
 
@@ -2063,20 +2063,20 @@ class LLAdvancedCheckShowPointAt : public view_listener_t
 
 class LLAdvancedToggleDebugJointUpdates : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar::sJointDebug = !(LLVOAvatar::sJointDebug);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar::sJointDebug = !(LLVOAvatar::sJointDebug);
+        return true;
+    }
 };
 
 class LLAdvancedCheckDebugJointUpdates : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLVOAvatar::sJointDebug;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLVOAvatar::sJointDebug;
+        return new_value;
+    }
 };
 
 
@@ -2088,20 +2088,20 @@ class LLAdvancedCheckDebugJointUpdates : public view_listener_t
 
 class LLAdvancedToggleDisableLOD : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLViewerJoint::sDisableLOD = !(LLViewerJoint::sDisableLOD);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLViewerJoint::sDisableLOD = !(LLViewerJoint::sDisableLOD);
+        return true;
+    }
 };
-		
+
 class LLAdvancedCheckDisableLOD : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLViewerJoint::sDisableLOD;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLViewerJoint::sDisableLOD;
+        return new_value;
+    }
 };
 
 
@@ -2113,20 +2113,20 @@ class LLAdvancedCheckDisableLOD : public view_listener_t
 
 class LLAdvancedToggleDebugCharacterVis : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar::sDebugInvisible = !(LLVOAvatar::sDebugInvisible);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar::sDebugInvisible = !(LLVOAvatar::sDebugInvisible);
+        return true;
+    }
 };
 
 class LLAdvancedCheckDebugCharacterVis : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLVOAvatar::sDebugInvisible;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLVOAvatar::sDebugInvisible;
+        return new_value;
+    }
 };
 
 
@@ -2134,39 +2134,39 @@ class LLAdvancedCheckDebugCharacterVis : public view_listener_t
 // DUMP ATTACHMENTS //
 //////////////////////
 
-	
+
 class LLAdvancedDumpAttachments : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_dump_attachments(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_dump_attachments(NULL);
+        return true;
+    }
 };
 
 
-	
+
 /////////////////////
 // REBAKE TEXTURES //
 /////////////////////
-	
-	
+
+
 class LLAdvancedRebakeTextures : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_rebake_textures(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_rebake_textures(NULL);
+        return true;
+    }
 };
-	
-	
+
+
 // [SL:KB] - Patch: Appearance-PhantomAttach | Checked: Catznip-5.0
 void handle_refresh_attachments()
 {
-	if (isAgentAvatarValid())
-		gAgentAvatarp->rebuildAttachments();
-	LLAttachmentsMgr::instance().refreshAttachments();
+    if (isAgentAvatarValid())
+        gAgentAvatarp->rebuildAttachments();
+    LLAttachmentsMgr::instance().refreshAttachments();
 }
 // [/SL:KB]
 
@@ -2178,14 +2178,14 @@ void handle_refresh_attachments()
 
 class LLAdvancedDebugAvatarTextures : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (gAgent.isGodlike())
-		{
-			handle_debug_avatar_textures(NULL);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (gAgent.isGodlike())
+        {
+            handle_debug_avatar_textures(NULL);
+        }
+        return true;
+    }
 };
 
 ////////////////////////////////
@@ -2195,17 +2195,17 @@ class LLAdvancedDebugAvatarTextures : public view_listener_t
 
 class LLAdvancedDumpAvatarLocalTextures : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 #ifndef LL_RELEASE_FOR_DOWNLOAD
-		handle_dump_avatar_local_textures(NULL);
+        handle_dump_avatar_local_textures(NULL);
 #endif
-		return true;
-	}
+        return true;
+    }
 };
 
 #endif
-	
+
 /////////////////
 // MESSAGE LOG //
 /////////////////
@@ -2213,20 +2213,20 @@ class LLAdvancedDumpAvatarLocalTextures : public view_listener_t
 
 class LLAdvancedEnableMessageLog : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_viewer_enable_message_log(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_viewer_enable_message_log(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedDisableMessageLog : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_viewer_disable_message_log(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_viewer_disable_message_log(NULL);
+        return true;
+    }
 };
 
 /////////////////
@@ -2236,11 +2236,11 @@ class LLAdvancedDisableMessageLog : public view_listener_t
 
 class LLAdvancedDropPacket : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gMessageSystem->mPacketRing.dropPackets(1);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gMessageSystem->mPacketRing.dropPackets(1);
+        return true;
+    }
 };
 
 //////////////////////
@@ -2250,8 +2250,8 @@ class LLAdvancedDropPacket : public view_listener_t
 
 class LLAdvancedPurgeDiskCache : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
         LL::WorkQueue::ptr_t main_queue = LL::WorkQueue::getInstance("mainloop");
         LL::WorkQueue::ptr_t general_queue = LL::WorkQueue::getInstance("General");
         llassert_always(main_queue);
@@ -2265,8 +2265,8 @@ class LLAdvancedPurgeDiskCache : public view_listener_t
             },
             [](){}); // Callback to main thread is empty as there is nothing left to do
 
-		return true;
-	}
+        return true;
+    }
 };
 
 
@@ -2277,12 +2277,12 @@ class LLAdvancedPurgeDiskCache : public view_listener_t
 
 class LLAdvancedPurgeShaderCache : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLViewerShaderMgr::instance()->clearShaderCache();
-		LLViewerShaderMgr::instance()->setShaders();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLViewerShaderMgr::instance()->clearShaderCache();
+        LLViewerShaderMgr::instance()->setShaders();
+        return true;
+    }
 };
 
 /////////////////////
@@ -2292,11 +2292,11 @@ class LLAdvancedPurgeShaderCache : public view_listener_t
 
 class LLAdvancedRebuildTerrain : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
         gPipeline.rebuildTerrain();
-		return true;
-	}
+        return true;
+    }
 };
 
 ////////////////////
@@ -2306,34 +2306,34 @@ class LLAdvancedRebuildTerrain : public view_listener_t
 
 class LLAdvancedViewerEventRecorder : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 #if AL_VIEWER_EVENT_RECORDER
-		std::string command = userdata.asString();
-		if ("start playback" == command)
-		{
-			LL_INFOS() << "Event Playback starting" << LL_ENDL;
-			LLViewerEventRecorder::instance().playbackRecording();
-			LL_INFOS() << "Event Playback completed" << LL_ENDL;
-		}
-		else if ("stop playback" == command)
-		{
-			// Future
-		}
-		else if ("start recording" == command)
-		{
-			LLViewerEventRecorder::instance().setEventLoggingOn();
-			LL_INFOS() << "Event recording started" << LL_ENDL;
-		}
-		else if ("stop recording" == command)
-		{
-			LLViewerEventRecorder::instance().setEventLoggingOff();
-			LL_INFOS() << "Event recording stopped" << LL_ENDL;
-		} 
+        std::string command = userdata.asString();
+        if ("start playback" == command)
+        {
+            LL_INFOS() << "Event Playback starting" << LL_ENDL;
+            LLViewerEventRecorder::instance().playbackRecording();
+            LL_INFOS() << "Event Playback completed" << LL_ENDL;
+        }
+        else if ("stop playback" == command)
+        {
+            // Future
+        }
+        else if ("start recording" == command)
+        {
+            LLViewerEventRecorder::instance().setEventLoggingOn();
+            LL_INFOS() << "Event recording started" << LL_ENDL;
+        }
+        else if ("stop recording" == command)
+        {
+            LLViewerEventRecorder::instance().setEventLoggingOff();
+            LL_INFOS() << "Event recording stopped" << LL_ENDL;
+        }
 #endif
 
-		return true;
-	}		
+        return true;
+    }
 };
 
 
@@ -2346,29 +2346,29 @@ class LLAdvancedViewerEventRecorder : public view_listener_t
 
 class LLAdvancedAgentPilot : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string command = userdata.asString();
-		if ("start playback" == command)
-		{
-			gAgentPilot.setNumRuns(-1);
-			gAgentPilot.startPlayback();
-		}
-		else if ("stop playback" == command)
-		{
-			gAgentPilot.stopPlayback();
-		}
-		else if ("start record" == command)
-		{
-			gAgentPilot.startRecord();
-		}
-		else if ("stop record" == command)
-		{
-			gAgentPilot.stopRecord();
-		}
-
-		return true;
-	}		
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string command = userdata.asString();
+        if ("start playback" == command)
+        {
+            gAgentPilot.setNumRuns(-1);
+            gAgentPilot.startPlayback();
+        }
+        else if ("stop playback" == command)
+        {
+            gAgentPilot.stopPlayback();
+        }
+        else if ("start record" == command)
+        {
+            gAgentPilot.startRecord();
+        }
+        else if ("stop record" == command)
+        {
+            gAgentPilot.stopRecord();
+        }
+
+        return true;
+    }
 };
 
 
@@ -2380,20 +2380,20 @@ class LLAdvancedAgentPilot : public view_listener_t
 
 class LLAdvancedToggleAgentPilotLoop : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gAgentPilot.setLoop(!gAgentPilot.getLoop());
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gAgentPilot.setLoop(!gAgentPilot.getLoop());
+        return true;
+    }
 };
 
 class LLAdvancedCheckAgentPilotLoop : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gAgentPilot.getLoop();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gAgentPilot.getLoop();
+        return new_value;
+    }
 };
 
 
@@ -2404,20 +2404,20 @@ class LLAdvancedCheckAgentPilotLoop : public view_listener_t
 
 class LLAdvancedToggleShowObjectUpdates : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gShowObjectUpdates = !(gShowObjectUpdates);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gShowObjectUpdates = !(gShowObjectUpdates);
+        return true;
+    }
 };
 
 class LLAdvancedCheckShowObjectUpdates : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gShowObjectUpdates;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gShowObjectUpdates;
+        return new_value;
+    }
 };
 
 
@@ -2429,11 +2429,11 @@ class LLAdvancedCheckShowObjectUpdates : public view_listener_t
 
 class LLAdvancedCompressImage : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_compress_image(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_compress_image(NULL);
+        return true;
+    }
 };
 
 
@@ -2459,20 +2459,20 @@ class LLAdvancedCompressFileTest : public view_listener_t
 
 class LLAdvancedShowDebugSettings : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLFloaterReg::showInstance("settings_debug",userdata);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLFloaterReg::showInstance("settings_debug",userdata);
+        return true;
+    }
 };
 
 class LLAdvancedToggleDebugSettings : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLFloaterReg::toggleInstanceOrBringToFront("settings_debug",userdata);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLFloaterReg::toggleInstanceOrBringToFront("settings_debug",userdata);
+        return true;
+    }
 };
 
 
@@ -2482,40 +2482,40 @@ class LLAdvancedToggleDebugSettings : public view_listener_t
 
 class LLAdvancedEnableViewAdminOptions : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		// Don't enable in god mode since the admin menu is shown anyway.
-		// Only enable if the user has set the appropriate debug setting.
-		bool new_value = !gAgent.getAgentAccess().isGodlikeWithoutAdminMenuFakery() && gSavedSettings.getBOOL("AdminMenu");
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        // Don't enable in god mode since the admin menu is shown anyway.
+        // Only enable if the user has set the appropriate debug setting.
+        bool new_value = !gAgent.getAgentAccess().isGodlikeWithoutAdminMenuFakery() && gSavedSettings.getBOOL("AdminMenu");
+        return new_value;
+    }
 };
 
 class LLAdvancedToggleViewAdminOptions : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_admin_override_toggle(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_admin_override_toggle(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedToggleVisualLeakDetector : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_visual_leak_detector_toggle(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_visual_leak_detector_toggle(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedCheckViewAdminOptions : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = check_admin_override(NULL) || gAgent.isGodlike();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = check_admin_override(NULL) || gAgent.isGodlike();
+        return new_value;
+    }
 };
 
 //////////////////
@@ -2525,20 +2525,20 @@ class LLAdvancedCheckViewAdminOptions : public view_listener_t
 
 class LLAdvancedRequestAdminStatus : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_god_mode(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_god_mode(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedLeaveAdminStatus : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_leave_god_mode(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_leave_god_mode(NULL);
+        return true;
+    }
 };
 
 //////////////////////////
@@ -2547,20 +2547,20 @@ class LLAdvancedLeaveAdminStatus : public view_listener_t
 
 class LLAdvancedForceErrorBreakpoint : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{		
-		force_error_breakpoint(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        force_error_breakpoint(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedForceErrorLlerror : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		force_error_llerror(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        force_error_llerror(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedForceErrorLlerrorMsg: public view_listener_t
@@ -2574,11 +2574,11 @@ class LLAdvancedForceErrorLlerrorMsg: public view_listener_t
 
 class LLAdvancedForceErrorBadMemoryAccess : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		force_error_bad_memory_access(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        force_error_bad_memory_access(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedForceErrorBadMemoryAccessCoro : public view_listener_t
@@ -2599,20 +2599,20 @@ class LLAdvancedForceErrorBadMemoryAccessCoro : public view_listener_t
 
 class LLAdvancedForceErrorInfiniteLoop : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		force_error_infinite_loop(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        force_error_infinite_loop(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedForceErrorSoftwareException : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		force_error_software_exception(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        force_error_software_exception(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedForceOSException: public view_listener_t
@@ -2642,11 +2642,11 @@ class LLAdvancedForceErrorSoftwareExceptionCoro : public view_listener_t
 
 class LLAdvancedForceErrorDriverCrash : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		force_error_driver_crash(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        force_error_driver_crash(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedForceErrorCoroutineCrash : public view_listener_t
@@ -2669,10 +2669,10 @@ class LLAdvancedForceErrorThreadCrash : public view_listener_t
 
 class LLAdvancedForceErrorDisconnectViewer : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_disconnect_viewer(NULL);
-		return true;
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_disconnect_viewer(NULL);
+        return true;
 }
 };
 
@@ -2681,29 +2681,29 @@ class LLAdvancedForceErrorDisconnectViewer : public view_listener_t
 
 class LLAdvancedHandleToggleHackedGodmode : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_toggle_hacked_godmode(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_toggle_hacked_godmode(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedCheckToggleHackedGodmode : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		check_toggle_hacked_godmode(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        check_toggle_hacked_godmode(NULL);
+        return true;
+    }
 };
 
 class LLAdvancedEnableToggleHackedGodmode : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = enable_toggle_hacked_godmode(NULL);
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = enable_toggle_hacked_godmode(NULL);
+        return new_value;
+    }
 };
 #endif
 
@@ -2720,21 +2720,21 @@ class LLAdvancedEnableToggleHackedGodmode : public view_listener_t
 
 class LLDevelopCheckLoggingLevel : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		U32 level = userdata.asInteger();
-		return (static_cast<LLError::ELevel>(level) == LLError::getDefaultLevel());
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        U32 level = userdata.asInteger();
+        return (static_cast<LLError::ELevel>(level) == LLError::getDefaultLevel());
+    }
 };
 
 class LLDevelopSetLoggingLevel : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		U32 level = userdata.asInteger();
-		LLError::setDefaultLevel(static_cast<LLError::ELevel>(level));
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        U32 level = userdata.asInteger();
+        LLError::setDefaultLevel(static_cast<LLError::ELevel>(level));
+        return true;
+    }
 };
 
 //////////////////
@@ -2744,100 +2744,100 @@ class LLDevelopSetLoggingLevel : public view_listener_t
 // Admin > Object
 class LLAdminForceTakeCopy : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		force_take_copy(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        force_take_copy(NULL);
+        return true;
+    }
 };
 
 class LLAdminHandleObjectOwnerSelf : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_object_owner_self(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_object_owner_self(NULL);
+        return true;
+    }
 };
 class LLAdminHandleObjectOwnerPermissive : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_object_owner_permissive(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_object_owner_permissive(NULL);
+        return true;
+    }
 };
 
 class LLAdminHandleForceDelete : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_force_delete(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_force_delete(NULL);
+        return true;
+    }
 };
 
 class LLAdminHandleObjectLock : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_object_lock(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_object_lock(NULL);
+        return true;
+    }
 };
 
 class LLAdminHandleObjectAssetIDs: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_object_asset_ids(NULL);
-		return true;
-	}	
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_object_asset_ids(NULL);
+        return true;
+    }
 };
 
 //Admin >Parcel
 class LLAdminHandleForceParcelOwnerToMe: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_force_parcel_owner_to_me(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_force_parcel_owner_to_me(NULL);
+        return true;
+    }
 };
 class LLAdminHandleForceParcelToContent: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_force_parcel_to_content(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_force_parcel_to_content(NULL);
+        return true;
+    }
 };
 class LLAdminHandleClaimPublicLand: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_claim_public_land(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_claim_public_land(NULL);
+        return true;
+    }
 };
 
 // Admin > Region
 class LLAdminHandleRegionDumpTempAssetData: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_region_dump_temp_asset_data(NULL);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_region_dump_temp_asset_data(NULL);
+        return true;
+    }
 };
 //Admin (Top Level)
 
 class LLAdminOnSaveState: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLPanelRegionTools::onSaveState(NULL);
-		return true;
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLPanelRegionTools::onSaveState(NULL);
+        return true;
 }
 };
 
@@ -2847,41 +2847,41 @@ class LLAdminOnSaveState: public view_listener_t
 //-----------------------------------------------------------------------------
 void cleanup_menus()
 {
-	delete gSLMMenuUpdater;
-	gSLMMenuUpdater = nullptr;
+    delete gSLMMenuUpdater;
+    gSLMMenuUpdater = nullptr;
 
-	delete gMenuParcelObserver;
-	gMenuParcelObserver = NULL;
+    delete gMenuParcelObserver;
+    gMenuParcelObserver = NULL;
 
-	delete gMenuAvatarSelf;
-	gMenuAvatarSelf = NULL;
+    delete gMenuAvatarSelf;
+    gMenuAvatarSelf = NULL;
 
-	delete gMenuAvatarOther;
-	gMenuAvatarOther = NULL;
+    delete gMenuAvatarOther;
+    gMenuAvatarOther = NULL;
 
-	delete gMenuObject;
-	gMenuObject = NULL;
+    delete gMenuObject;
+    gMenuObject = NULL;
 
-	delete gMenuAttachmentSelf;
-	gMenuAttachmentSelf = NULL;
+    delete gMenuAttachmentSelf;
+    gMenuAttachmentSelf = NULL;
 
-	delete gMenuAttachmentOther;
-	gMenuAttachmentOther = NULL;
+    delete gMenuAttachmentOther;
+    gMenuAttachmentOther = NULL;
 
-	delete gMenuLand;
-	gMenuLand = NULL;
+    delete gMenuLand;
+    gMenuLand = NULL;
 
-	delete gMenuMuteParticle;
-	gMenuMuteParticle = NULL;
+    delete gMenuMuteParticle;
+    gMenuMuteParticle = NULL;
 
-	delete gMenuBarView;
-	gMenuBarView = NULL;
+    delete gMenuBarView;
+    gMenuBarView = NULL;
 
-	delete gPopupMenuView;
-	gPopupMenuView = NULL;
+    delete gPopupMenuView;
+    gPopupMenuView = NULL;
 
-	delete gMenuHolder;
-	gMenuHolder = NULL;
+    delete gMenuHolder;
+    gMenuHolder = NULL;
 }
 
 //-----------------------------------------------------------------------------
@@ -2890,49 +2890,49 @@ void cleanup_menus()
 
 class LLObjectReportAbuse : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-		if (objectp)
-		{
-			LLFloaterReporter::showFromObject(objectp->getID());
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+        if (objectp)
+        {
+            LLFloaterReporter::showFromObject(objectp->getID());
+        }
+        return true;
+    }
 };
 
 // Enabled it you clicked an object
 class LLObjectEnableReportAbuse : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLSelectMgr::getInstance()->getSelection()->getObjectCount() != 0;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLSelectMgr::getInstance()->getSelection()->getObjectCount() != 0;
+        return new_value;
+    }
 };
 
 
 void handle_object_touch()
 {
-	LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-	if (!object) return;
+    LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+    if (!object) return;
 
-	LLPickInfo pick = LLToolPie::getInstance()->getPick();
+    LLPickInfo pick = LLToolPie::getInstance()->getPick();
 
 // [RLVa:KB] - Checked: 2010-04-11 (RLVa-1.2.0e) | Modified: RLVa-1.1.0l
-	// NOTE: fallback code since we really shouldn't be getting an active selection if we can't touch this
-	if ( (RlvActions::isRlvEnabled()) && (!RlvActions::canTouch(object, pick.mObjectOffset)) )
-	{
-		RLV_ASSERT(false);
-		return;
-	}
+    // NOTE: fallback code since we really shouldn't be getting an active selection if we can't touch this
+    if ( (RlvActions::isRlvEnabled()) && (!RlvActions::canTouch(object, pick.mObjectOffset)) )
+    {
+        RLV_ASSERT(false);
+        return;
+    }
 // [/RLVa:KB]
 
-	// *NOTE: Hope the packets arrive safely and in order or else
-	// there will be some problems.
-	// *TODO: Just fix this bad assumption.
-	send_ObjectGrab_message(object, pick, LLVector3::zero);
-	send_ObjectDeGrab_message(object, pick);
+    // *NOTE: Hope the packets arrive safely and in order or else
+    // there will be some problems.
+    // *TODO: Just fix this bad assumption.
+    send_ObjectGrab_message(object, pick, LLVector3::zero);
+    send_ObjectDeGrab_message(object, pick);
 }
 
 void handle_object_show_original()
@@ -2965,87 +2965,87 @@ void handle_object_show_original()
 
 static void init_default_item_label(LLUICtrl* ctrl)
 {
-	const std::string& item_name = ctrl->getName();
-	auto it = sDefaultItemLabels.find(item_name);
-	if (it == sDefaultItemLabels.end())
-	{
-		// *NOTE: This will not work for items of type LLMenuItemCheckGL because they return boolean value
-		//       (doesn't seem to matter much ATM).
-		LLStringExplicit default_label = ctrl->getValue().asString();
-		if (!default_label.empty())
-		{
-			sDefaultItemLabels.emplace(item_name, default_label);
-		}
-	}
+    const std::string& item_name = ctrl->getName();
+    auto it = sDefaultItemLabels.find(item_name);
+    if (it == sDefaultItemLabels.end())
+    {
+        // *NOTE: This will not work for items of type LLMenuItemCheckGL because they return boolean value
+        //       (doesn't seem to matter much ATM).
+        LLStringExplicit default_label = ctrl->getValue().asString();
+        if (!default_label.empty())
+        {
+            sDefaultItemLabels.emplace(item_name, default_label);
+        }
+    }
 }
 
 static LLStringExplicit get_default_item_label(const std::string& item_name)
 {
-	LLStringExplicit res("");
-	auto it = sDefaultItemLabels.find(item_name);
-	if (it != sDefaultItemLabels.end())
-	{
-		res = it->second;
-	}
+    LLStringExplicit res("");
+    auto it = sDefaultItemLabels.find(item_name);
+    if (it != sDefaultItemLabels.end())
+    {
+        res = it->second;
+    }
 
-	return res;
+    return res;
 }
 
 
 bool enable_object_touch(LLUICtrl* ctrl)
 {
-	bool new_value = false;
-	LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-	if (obj)
-	{
-		LLViewerObject* parent = (LLViewerObject*)obj->getParent();
-		new_value = obj->flagHandleTouch() || (parent && parent->flagHandleTouch());
-	}
+    bool new_value = false;
+    LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+    if (obj)
+    {
+        LLViewerObject* parent = (LLViewerObject*)obj->getParent();
+        new_value = obj->flagHandleTouch() || (parent && parent->flagHandleTouch());
+    }
 
 // [RLVa:KB] - Checked: 2010-11-12 (RLVa-1.2.1g) | Added: RLVa-1.2.1g
-	if ( (RlvActions::isRlvEnabled()) && (new_value) )
-	{
-		// RELEASE-RLVa: [RLVa-1.2.1] Make sure this stays in sync with handle_object_touch()
-		new_value = RlvActions::canTouch(obj, LLToolPie::getInstance()->getPick().mObjectOffset);
-	}
+    if ( (RlvActions::isRlvEnabled()) && (new_value) )
+    {
+        // RELEASE-RLVa: [RLVa-1.2.1] Make sure this stays in sync with handle_object_touch()
+        new_value = RlvActions::canTouch(obj, LLToolPie::getInstance()->getPick().mObjectOffset);
+    }
 // [/RLVa:KB]
 
-	init_default_item_label(ctrl);
+    init_default_item_label(ctrl);
 
-	// Update label based on the node touch name if available.
-	LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
-	if (node && node->mValid && !node->mTouchName.empty())
-	{
-		ctrl->setValue(node->mTouchName);
-	}
-	else
-	{
-		ctrl->setValue(get_default_item_label(ctrl->getName()));
-	}
+    // Update label based on the node touch name if available.
+    LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
+    if (node && node->mValid && !node->mTouchName.empty())
+    {
+        ctrl->setValue(node->mTouchName);
+    }
+    else
+    {
+        ctrl->setValue(get_default_item_label(ctrl->getName()));
+    }
 
-	return new_value;
+    return new_value;
 };
 
 //void label_touch(std::string& label, void*)
 //{
-//	LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
-//	if (node && node->mValid && !node->mTouchName.empty())
-//	{
-//		label.assign(node->mTouchName);
-//	}
-//	else
-//	{
-//		label.assign("Touch");
-//	}
+//  LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
+//  if (node && node->mValid && !node->mTouchName.empty())
+//  {
+//      label.assign(node->mTouchName);
+//  }
+//  else
+//  {
+//      label.assign("Touch");
+//  }
 //}
 
 void handle_object_open()
 {
 // [RLVa:KB] - Checked: 2010-04-11 (RLVa-1.2.0e) | Added: RLVa-1.2.0e
-	if (enable_object_open())
-		LLFloaterReg::showInstance("openobject");
+    if (enable_object_open())
+        LLFloaterReg::showInstance("openobject");
 // [/RLVa:KB]
-//	LLFloaterReg::showInstance("openobject");
+//  LLFloaterReg::showInstance("openobject");
 }
 
 bool enable_object_inspect()
@@ -3100,67 +3100,67 @@ bool enable_object_edit_gltf_material()
 
 bool enable_object_open()
 {
-	// Look for contents in root object, which is all the LLFloaterOpenObject
-	// understands.
-	LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-	if (!obj) return false;
+    // Look for contents in root object, which is all the LLFloaterOpenObject
+    // understands.
+    LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+    if (!obj) return false;
 
-	LLViewerObject* root = obj->getRootEdit();
-	if (!root) return false;
+    LLViewerObject* root = obj->getRootEdit();
+    if (!root) return false;
 
-	return root->allowOpen();
+    return root->allowOpen();
 }
 
 
 class LLViewJoystickFlycam : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_toggle_flycam();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_toggle_flycam();
+        return true;
+    }
 };
 
 class LLViewCheckJoystickFlycam : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLViewerJoystick::getInstance()->getOverrideCamera();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLViewerJoystick::getInstance()->getOverrideCamera();
+        return new_value;
+    }
 };
 
 void handle_toggle_flycam()
 {
-	LLViewerJoystick::getInstance()->toggleFlycam();
+    LLViewerJoystick::getInstance()->toggleFlycam();
 }
 
 class LLObjectBuild : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (gAgentCamera.getFocusOnAvatar() && !LLToolMgr::getInstance()->inEdit() && gSavedSettings.getBOOL("EditCameraMovement") )
-		{
-			// zoom in if we're looking at the avatar
-			gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
-			gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
-			gAgentCamera.cameraZoomIn(0.666f);
-			gAgentCamera.cameraOrbitOver( 30.f * DEG_TO_RAD );
-			gViewerWindow->moveCursorToCenter();
-		}
-		else if ( gSavedSettings.getBOOL("EditCameraMovement") )
-		{
-			gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
-			gViewerWindow->moveCursorToCenter();
-		}
-
-		LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
-		LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolCompCreate::getInstance() );
-
-		// Could be first use
-		//LLFirstUse::useBuild();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (gAgentCamera.getFocusOnAvatar() && !LLToolMgr::getInstance()->inEdit() && gSavedSettings.getBOOL("EditCameraMovement") )
+        {
+            // zoom in if we're looking at the avatar
+            gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
+            gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
+            gAgentCamera.cameraZoomIn(0.666f);
+            gAgentCamera.cameraOrbitOver( 30.f * DEG_TO_RAD );
+            gViewerWindow->moveCursorToCenter();
+        }
+        else if ( gSavedSettings.getBOOL("EditCameraMovement") )
+        {
+            gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
+            gViewerWindow->moveCursorToCenter();
+        }
+
+        LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
+        LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolCompCreate::getInstance() );
+
+        // Could be first use
+        //LLFirstUse::useBuild();
+        return true;
+    }
 };
 
 void update_camera()
@@ -3199,17 +3199,17 @@ void handle_object_edit()
 {
     update_camera();
 
-	LLFloaterReg::showInstance("build");
-	
-	LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
-	gFloaterTools->setEditTool( LLToolCompTranslate::getInstance() );
-	
-	LLViewerJoystick::getInstance()->moveObjects(true);
-	LLViewerJoystick::getInstance()->setNeedsReset(true);
-	
-	// Could be first use
-	//LLFirstUse::useBuild();
-	return;
+    LLFloaterReg::showInstance("build");
+
+    LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
+    gFloaterTools->setEditTool( LLToolCompTranslate::getInstance() );
+
+    LLViewerJoystick::getInstance()->moveObjects(true);
+    LLViewerJoystick::getInstance()->setNeedsReset(true);
+
+    // Could be first use
+    //LLFirstUse::useBuild();
+    return;
 }
 
 void handle_object_edit_gltf_material()
@@ -3231,71 +3231,71 @@ void handle_object_edit_gltf_material()
 
 void handle_attachment_edit(const LLUUID& inv_item_id)
 {
-	if (isAgentAvatarValid())
-	{
-		if (LLViewerObject* attached_obj = gAgentAvatarp->getWornAttachment(inv_item_id))
-		{
-			LLSelectMgr::getInstance()->deselectAll();
-			LLSelectMgr::getInstance()->selectObjectAndFamily(attached_obj);
+    if (isAgentAvatarValid())
+    {
+        if (LLViewerObject* attached_obj = gAgentAvatarp->getWornAttachment(inv_item_id))
+        {
+            LLSelectMgr::getInstance()->deselectAll();
+            LLSelectMgr::getInstance()->selectObjectAndFamily(attached_obj);
 
-			handle_object_edit();
-		}
-	}
+            handle_object_edit();
+        }
+    }
 }
 
 void handle_attachment_touch(const LLUUID& inv_item_id)
 {
-	if ( (isAgentAvatarValid()) && (enable_attachment_touch(inv_item_id)) )
-	{
-		if (LLViewerObject* attach_obj = gAgentAvatarp->getWornAttachment(gInventory.getLinkedItemID(inv_item_id)))
-		{
-			LLSelectMgr::getInstance()->deselectAll();
-
-			LLObjectSelectionHandle sel = LLSelectMgr::getInstance()->selectObjectAndFamily(attach_obj);
-			if (!LLToolMgr::getInstance()->inBuildMode())
-			{
-				struct SetTransient : public LLSelectedNodeFunctor
-				{
-					bool apply(LLSelectNode* node)
-					{
-						node->setTransient(TRUE);
-						return true;
-					}
-				} f;
-				sel->applyToNodes(&f);
-			}
-
-			handle_object_touch();
-		}
-	}
+    if ( (isAgentAvatarValid()) && (enable_attachment_touch(inv_item_id)) )
+    {
+        if (LLViewerObject* attach_obj = gAgentAvatarp->getWornAttachment(gInventory.getLinkedItemID(inv_item_id)))
+        {
+            LLSelectMgr::getInstance()->deselectAll();
+
+            LLObjectSelectionHandle sel = LLSelectMgr::getInstance()->selectObjectAndFamily(attach_obj);
+            if (!LLToolMgr::getInstance()->inBuildMode())
+            {
+                struct SetTransient : public LLSelectedNodeFunctor
+                {
+                    bool apply(LLSelectNode* node)
+                    {
+                        node->setTransient(TRUE);
+                        return true;
+                    }
+                } f;
+                sel->applyToNodes(&f);
+            }
+
+            handle_object_touch();
+        }
+    }
 }
 
 bool enable_attachment_touch(const LLUUID& inv_item_id)
 {
-	if (isAgentAvatarValid())
-	{
-		const LLViewerObject* attach_obj = gAgentAvatarp->getWornAttachment(gInventory.getLinkedItemID(inv_item_id));
+    if (isAgentAvatarValid())
+    {
+        const LLViewerObject* attach_obj = gAgentAvatarp->getWornAttachment(gInventory.getLinkedItemID(inv_item_id));
 // [RLVa:KB] - @touch*
-		return (attach_obj) && (attach_obj->flagHandleTouch()) && (!RlvActions::isRlvEnabled() || RlvActions::canTouch(attach_obj));
+        return (attach_obj) && (attach_obj->flagHandleTouch()) && (!RlvActions::isRlvEnabled() || RlvActions::canTouch(attach_obj));
 // [/RLVa:KB]
-//		return (attach_obj) && (attach_obj->flagHandleTouch());
-	}
-	return false;
+//      return (attach_obj) && (attach_obj->flagHandleTouch());
+    }
+    return false;
 }
 
 void handle_object_inspect()
 {
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	LLViewerObject* selected_objectp = selection->getFirstRootObject();
-	if (selected_objectp)
-	{
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    LLViewerObject* selected_objectp = selection->getFirstRootObject();
+    if (selected_objectp)
+    {
         LLFloaterReg::showInstance("task_properties");
-	}
-	
-	/*
-	// Old floater properties
-	LLFloaterReg::showInstance("inspect", LLSD());
-	*/
+    }
+
+    /*
+    // Old floater properties
+    LLFloaterReg::showInstance("inspect", LLSD());
+    */
 }
 
 //---------------------------------------------------------------------------
@@ -3303,145 +3303,145 @@ void handle_object_inspect()
 //---------------------------------------------------------------------------
 class LLLandBuild : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLViewerParcelMgr::getInstance()->deselectLand();
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLViewerParcelMgr::getInstance()->deselectLand();
 
-		if (gAgentCamera.getFocusOnAvatar() && !LLToolMgr::getInstance()->inEdit() && gSavedSettings.getBOOL("EditCameraMovement") )
-		{
-			// zoom in if we're looking at the avatar
-			gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
-			gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
-			gAgentCamera.cameraZoomIn(0.666f);
-			gAgentCamera.cameraOrbitOver( 30.f * DEG_TO_RAD );
-			gViewerWindow->moveCursorToCenter();
-		}
-		else if ( gSavedSettings.getBOOL("EditCameraMovement")  )
-		{
-			// otherwise just move focus
-			gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
-			gViewerWindow->moveCursorToCenter();
-		}
+        if (gAgentCamera.getFocusOnAvatar() && !LLToolMgr::getInstance()->inEdit() && gSavedSettings.getBOOL("EditCameraMovement") )
+        {
+            // zoom in if we're looking at the avatar
+            gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
+            gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
+            gAgentCamera.cameraZoomIn(0.666f);
+            gAgentCamera.cameraOrbitOver( 30.f * DEG_TO_RAD );
+            gViewerWindow->moveCursorToCenter();
+        }
+        else if ( gSavedSettings.getBOOL("EditCameraMovement")  )
+        {
+            // otherwise just move focus
+            gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
+            gViewerWindow->moveCursorToCenter();
+        }
 
 
-		LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
-		LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolCompCreate::getInstance() );
+        LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
+        LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolCompCreate::getInstance() );
 
-		// Could be first use
-		//LLFirstUse::useBuild();
-		return true;
-	}
+        // Could be first use
+        //LLFirstUse::useBuild();
+        return true;
+    }
 };
 
 class LLLandBuyPass : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLPanelLandGeneral::onClickBuyPass((void *)FALSE);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLPanelLandGeneral::onClickBuyPass((void *)FALSE);
+        return true;
+    }
 };
 
 class LLLandEnableBuyPass : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLPanelLandGeneral::enableBuyPass(NULL);
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLPanelLandGeneral::enableBuyPass(NULL);
+        return new_value;
+    }
 };
 
 // BUG: Should really check if CLICK POINT is in a parcel where you can build.
 BOOL enable_land_build(void*)
 {
-	if (gAgent.isGodlike()) return TRUE;
-	if (gAgent.inPrelude()) return FALSE;
+    if (gAgent.isGodlike()) return TRUE;
+    if (gAgent.inPrelude()) return FALSE;
 
-	BOOL can_build = FALSE;
-	LLParcel* agent_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
-	if (agent_parcel)
-	{
-		can_build = agent_parcel->getAllowModify();
-	}
-	return can_build;
+    BOOL can_build = FALSE;
+    LLParcel* agent_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
+    if (agent_parcel)
+    {
+        can_build = agent_parcel->getAllowModify();
+    }
+    return can_build;
 }
 
 // BUG: Should really check if OBJECT is in a parcel where you can build.
 BOOL enable_object_build(void*)
 {
-	if (gAgent.isGodlike()) return TRUE;
-	if (gAgent.inPrelude()) return FALSE;
+    if (gAgent.isGodlike()) return TRUE;
+    if (gAgent.inPrelude()) return FALSE;
 
-	BOOL can_build = FALSE;
-	LLParcel* agent_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
-	if (agent_parcel)
-	{
-		can_build = agent_parcel->getAllowModify();
-	}
-	return can_build;
+    BOOL can_build = FALSE;
+    LLParcel* agent_parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
+    if (agent_parcel)
+    {
+        can_build = agent_parcel->getAllowModify();
+    }
+    return can_build;
 }
 
 bool enable_object_edit()
 {
-	if (!isAgentAvatarValid()) return false;
-	
-	// *HACK:  The new "prelude" Help Islands have a build sandbox area,
-	// so users need the Edit and Create pie menu options when they are
-	// there.  Eventually this needs to be replaced with code that only 
-	// lets you edit objects if you have permission to do so (edit perms,
-	// group edit, god).  See also lltoolbar.cpp.  JC
-	bool enable = true;
-	if (gAgent.inPrelude())
-	{
-		enable = LLViewerParcelMgr::getInstance()->allowAgentBuild()
-			|| LLSelectMgr::getInstance()->getSelection()->isAttachment();
-	} 
-	else if (LLSelectMgr::getInstance()->selectGetAllValidAndObjectsFound())
-	{
+    if (!isAgentAvatarValid()) return false;
+
+    // *HACK:  The new "prelude" Help Islands have a build sandbox area,
+    // so users need the Edit and Create pie menu options when they are
+    // there.  Eventually this needs to be replaced with code that only
+    // lets you edit objects if you have permission to do so (edit perms,
+    // group edit, god).  See also lltoolbar.cpp.  JC
+    bool enable = true;
+    if (gAgent.inPrelude())
+    {
+        enable = LLViewerParcelMgr::getInstance()->allowAgentBuild()
+            || LLSelectMgr::getInstance()->getSelection()->isAttachment();
+    }
+    else if (LLSelectMgr::getInstance()->selectGetAllValidAndObjectsFound())
+    {
 // [RLVa:KB] - @edit*
-		if (RlvActions::isRlvEnabled() && !RlvActions::canEdit(ERlvCheckType::All))
-		{
-			LLObjectSelectionHandle hSel = LLSelectMgr::getInstance()->getSelection();
-			RlvSelectIsEditable f;
-			enable = (hSel.notNull()) && (!hSel->getFirstRootNode(&f, true));
-		}
-		else
-		{
-			enable = true;
-		}
+        if (RlvActions::isRlvEnabled() && !RlvActions::canEdit(ERlvCheckType::All))
+        {
+            LLObjectSelectionHandle hSel = LLSelectMgr::getInstance()->getSelection();
+            RlvSelectIsEditable f;
+            enable = (hSel.notNull()) && (!hSel->getFirstRootNode(&f, true));
+        }
+        else
+        {
+            enable = true;
+        }
 // [/RLVa:KB]
-//		enable = true;
-	}
+//      enable = true;
+    }
 
-	return enable;
+    return enable;
 }
 
 bool enable_mute_particle()
 {
-	const LLPickInfo& pick = LLToolPie::getInstance()->getPick();
+    const LLPickInfo& pick = LLToolPie::getInstance()->getPick();
 
-	return pick.mParticleOwnerID.notNull() && pick.mParticleOwnerID != gAgent.getID();
+    return pick.mParticleOwnerID.notNull() && pick.mParticleOwnerID != gAgent.getID();
 }
 
 // mutually exclusive - show either edit option or build in menu
 bool enable_object_build()
 {
-	return !enable_object_edit();
+    return !enable_object_edit();
 }
 
 bool enable_object_select_in_pathfinding_linksets()
 {
-	return LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion() && LLSelectMgr::getInstance()->selectGetEditableLinksets();
+    return LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion() && LLSelectMgr::getInstance()->selectGetEditableLinksets();
 }
 
 bool visible_object_select_in_pathfinding_linksets()
 {
-	return LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion();
+    return LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion();
 }
 
 bool enable_object_select_in_pathfinding_characters()
 {
-	return LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion() &&  LLSelectMgr::getInstance()->selectGetViewableCharacters();
+    return LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion() &&  LLSelectMgr::getInstance()->selectGetViewableCharacters();
 }
 
 bool enable_os_exception()
@@ -3455,43 +3455,43 @@ bool enable_os_exception()
 
 class LLSelfRemoveAllAttachments : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLAppearanceMgr::instance().removeAllAttachmentsFromAvatar();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLAppearanceMgr::instance().removeAllAttachmentsFromAvatar();
+        return true;
+    }
 };
 
 class LLSelfEnableRemoveAllAttachments : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = false;
-		if (isAgentAvatarValid())
-		{
-			for (LLVOAvatar::attachment_map_t::iterator iter = gAgentAvatarp->mAttachmentPoints.begin(); 
-				 iter != gAgentAvatarp->mAttachmentPoints.end(); )
-			{
-				LLVOAvatar::attachment_map_t::iterator curiter = iter++;
-				LLViewerJointAttachment* attachment = curiter->second;
-//				if (attachment->getNumObjects() > 0)
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = false;
+        if (isAgentAvatarValid())
+        {
+            for (LLVOAvatar::attachment_map_t::iterator iter = gAgentAvatarp->mAttachmentPoints.begin();
+                 iter != gAgentAvatarp->mAttachmentPoints.end(); )
+            {
+                LLVOAvatar::attachment_map_t::iterator curiter = iter++;
+                LLViewerJointAttachment* attachment = curiter->second;
+//              if (attachment->getNumObjects() > 0)
 // [RLVa:KB] - Checked: 2010-03-04 (RLVa-1.2.0a) | Added: RLVa-1.2.0a
-				if ( (attachment->getNumObjects() > 0) && ((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(attachment))) )
+                if ( (attachment->getNumObjects() > 0) && ((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(attachment))) )
 // [/RLVa:KB]
-				{
-					new_value = true;
-					break;
-				}
-			}
-		}
-		return new_value;
-	}
+                {
+                    new_value = true;
+                    break;
+                }
+            }
+        }
+        return new_value;
+    }
 };
 
 BOOL enable_has_attachments(void*)
 {
 
-	return FALSE;
+    return FALSE;
 }
 
 //---------------------------------------------------------------------------
@@ -3499,236 +3499,236 @@ BOOL enable_has_attachments(void*)
 //---------------------------------------------------------------------------
 //void handle_follow(void *userdata)
 //{
-//	// follow a given avatar by ID
-//	LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-//	if (objectp)
-//	{
-//		gAgent.startFollowPilot(objectp->getID());
-//	}
+//  // follow a given avatar by ID
+//  LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+//  if (objectp)
+//  {
+//      gAgent.startFollowPilot(objectp->getID());
+//  }
 //}
 
 bool enable_object_mute()
 {
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	LLViewerObject* object = selection->getPrimaryObject();
-	if (!object) return false;
-
-	LLVOAvatar* avatar = find_avatar_from_object(object); 
-	if (avatar)
-	{
-		// It's an avatar
-		bool is_linden = LLMuteList::isLinden(avatar->getFullname());
-		bool is_self = avatar->isSelf();
-//		return !is_linden && !is_self;
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    LLViewerObject* object = selection->getPrimaryObject();
+    if (!object) return false;
+
+    LLVOAvatar* avatar = find_avatar_from_object(object);
+    if (avatar)
+    {
+        // It's an avatar
+        bool is_linden = LLMuteList::isLinden(avatar->getFullname());
+        bool is_self = avatar->isSelf();
+//      return !is_linden && !is_self;
 // [RLVa:KB] - Checked: RLVa-1.2.1
-		return !is_linden && !is_self && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID()));
+        return !is_linden && !is_self && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID()));
 // [/RLVa:KB]
-	}
-	else
-	{
-		// Just a regular object
-		return selection->contains( object, SELECT_ALL_TES ) &&
-			   !LLMuteList::getInstance()->isMuted(object->getID());
-	}
+    }
+    else
+    {
+        // Just a regular object
+        return selection->contains( object, SELECT_ALL_TES ) &&
+               !LLMuteList::getInstance()->isMuted(object->getID());
+    }
 }
 
 bool enable_object_unmute()
 {
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	LLViewerObject* object = selection->getPrimaryObject();
-	if (!object) return false;
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    LLViewerObject* object = selection->getPrimaryObject();
+    if (!object) return false;
 
-	LLVOAvatar* avatar = find_avatar_from_object(object); 
-	if (avatar)
-	{
-		// It's an avatar
-		bool is_linden = LLMuteList::isLinden(avatar->getFullname());
-		bool is_self = avatar->isSelf();
-		return !is_linden && !is_self;
-	}
-	else
-	{
-		// Just a regular object
-		return selection->contains( object, SELECT_ALL_TES ) &&
-			   LLMuteList::getInstance()->isMuted(object->getID());;
-	}
+    LLVOAvatar* avatar = find_avatar_from_object(object);
+    if (avatar)
+    {
+        // It's an avatar
+        bool is_linden = LLMuteList::isLinden(avatar->getFullname());
+        bool is_self = avatar->isSelf();
+        return !is_linden && !is_self;
+    }
+    else
+    {
+        // Just a regular object
+        return selection->contains( object, SELECT_ALL_TES ) &&
+               LLMuteList::getInstance()->isMuted(object->getID());;
+    }
 }
 
 
 // 0 = normal, 1 = always, 2 = never
 class LLAvatarCheckImpostorMode : public view_listener_t
-{	
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-		if (!object) return false;
-
-		LLVOAvatar* avatar = find_avatar_from_object(object); 
-		if (!avatar) return false;
-		
-		U32 mode = userdata.asInteger();
-		switch (mode) 
-		{
-			case 0:
-				return (avatar->getVisualMuteSettings() == LLVOAvatar::AV_RENDER_NORMALLY);
-			case 1:
-				return (avatar->getVisualMuteSettings() == LLVOAvatar::AV_DO_NOT_RENDER);
-			case 2:
-				return (avatar->getVisualMuteSettings() == LLVOAvatar::AV_ALWAYS_RENDER);
+{
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+        if (!object) return false;
+
+        LLVOAvatar* avatar = find_avatar_from_object(object);
+        if (!avatar) return false;
+
+        U32 mode = userdata.asInteger();
+        switch (mode)
+        {
+            case 0:
+                return (avatar->getVisualMuteSettings() == LLVOAvatar::AV_RENDER_NORMALLY);
+            case 1:
+                return (avatar->getVisualMuteSettings() == LLVOAvatar::AV_DO_NOT_RENDER);
+            case 2:
+                return (avatar->getVisualMuteSettings() == LLVOAvatar::AV_ALWAYS_RENDER);
             case 4:
                 return (avatar->getVisualMuteSettings() != LLVOAvatar::AV_RENDER_NORMALLY);
-			default:
-				return false;
-		}
-	}	// handleEvent()
+            default:
+                return false;
+        }
+    }   // handleEvent()
 };
 
 // 0 = normal, 1 = always, 2 = never
 class LLAvatarSetImpostorMode : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-		if (!object) return false;
-
-		LLVOAvatar* avatar = find_avatar_from_object(object); 
-		if (!avatar) return false;
-		
-		U32 mode = userdata.asInteger();
-		switch (mode) 
-		{
-			case 0:
-				avatar->setVisualMuteSettings(LLVOAvatar::AV_RENDER_NORMALLY);
-				break;
-			case 1:
-				avatar->setVisualMuteSettings(LLVOAvatar::AV_DO_NOT_RENDER);
-				break;
-			case 2:
-				avatar->setVisualMuteSettings(LLVOAvatar::AV_ALWAYS_RENDER);
-				break;
-			default:
-				return false;
-		}
-
-		LLVOAvatar::cullAvatarsByPixelArea();
-		return true;
-	}	// handleEvent()
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+        if (!object) return false;
+
+        LLVOAvatar* avatar = find_avatar_from_object(object);
+        if (!avatar) return false;
+
+        U32 mode = userdata.asInteger();
+        switch (mode)
+        {
+            case 0:
+                avatar->setVisualMuteSettings(LLVOAvatar::AV_RENDER_NORMALLY);
+                break;
+            case 1:
+                avatar->setVisualMuteSettings(LLVOAvatar::AV_DO_NOT_RENDER);
+                break;
+            case 2:
+                avatar->setVisualMuteSettings(LLVOAvatar::AV_ALWAYS_RENDER);
+                break;
+            default:
+                return false;
+        }
+
+        LLVOAvatar::cullAvatarsByPixelArea();
+        return true;
+    }   // handleEvent()
 };
 
 
 class LLObjectMute : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-		if (!object) return true;
-		
-		LLUUID id;
-		std::string name;
-		LLMute::EType type;
-		LLVOAvatar* avatar = find_avatar_from_object(object); 
-		if (avatar)
-		{
-			avatar->mNeedsImpostorUpdate = TRUE;
-			avatar->mLastImpostorUpdateReason = 9;
-
-			id = avatar->getID();
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+        if (!object) return true;
+
+        LLUUID id;
+        std::string name;
+        LLMute::EType type;
+        LLVOAvatar* avatar = find_avatar_from_object(object);
+        if (avatar)
+        {
+            avatar->mNeedsImpostorUpdate = TRUE;
+            avatar->mLastImpostorUpdateReason = 9;
+
+            id = avatar->getID();
 // [RLVa:KB] - Checked: RLVa-1.0.0
-			if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, id))
-				return true;
+            if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, id))
+                return true;
 // [/RLVa:KB]
 
-			LLNameValue *firstname = avatar->getNVPair("FirstName");
-			LLNameValue *lastname = avatar->getNVPair("LastName");
-			if (firstname && lastname)
-			{
-				name = LLCacheName::buildFullName(
-					firstname->getString(), lastname->getString());
-			}
-			
-			type = LLMute::AGENT;
-		}
-		else
-		{
-			// it's an object
-			id = object->getID();
-
-			LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
-			if (node)
-			{
-				name = node->mName;
-			}
-			
-			type = LLMute::OBJECT;
-		}
-		
-		LLMute mute(id, name, type);
-		if (LLMuteList::getInstance()->isMuted(mute.mID))
-		{
-			LLMuteList::getInstance()->remove(mute);
-		}
-		else
-		{
-			LLMuteList::getInstance()->add(mute);
-			LLFloaterBlocked::showMuteAndSelect(mute.mID);
-			//LLPanelBlockedList::showPanelAndSelect(mute.mID);
-		}
-		
-		return true;
-	}
+            LLNameValue *firstname = avatar->getNVPair("FirstName");
+            LLNameValue *lastname = avatar->getNVPair("LastName");
+            if (firstname && lastname)
+            {
+                name = LLCacheName::buildFullName(
+                    firstname->getString(), lastname->getString());
+            }
+
+            type = LLMute::AGENT;
+        }
+        else
+        {
+            // it's an object
+            id = object->getID();
+
+            LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
+            if (node)
+            {
+                name = node->mName;
+            }
+
+            type = LLMute::OBJECT;
+        }
+
+        LLMute mute(id, name, type);
+        if (LLMuteList::getInstance()->isMuted(mute.mID))
+        {
+            LLMuteList::getInstance()->remove(mute);
+        }
+        else
+        {
+            LLMuteList::getInstance()->add(mute);
+            LLFloaterBlocked::showMuteAndSelect(mute.mID);
+            //LLPanelBlockedList::showPanelAndSelect(mute.mID);
+        }
+
+        return true;
+    }
 };
 
 bool handle_go_to()
 {
-	// try simulator autopilot
-	std::vector<std::string> strings;
-	std::string val;
-	LLVector3d pos = LLToolPie::getInstance()->getPick().mPosGlobal;
-	val = llformat("%g", pos.mdV[VX]);
-	strings.push_back(val);
-	val = llformat("%g", pos.mdV[VY]);
-	strings.push_back(val);
-	val = llformat("%g", pos.mdV[VZ]);
-	strings.push_back(val);
-	send_generic_message("autopilot", strings);
-
-	LLViewerParcelMgr::getInstance()->deselectLand();
-
-	if (isAgentAvatarValid() && !gSavedSettings.getBOOL("AutoPilotLocksCamera"))
-	{
-		gAgentCamera.setFocusGlobal(gAgentCamera.getFocusTargetGlobal(), gAgentAvatarp->getID());
-	}
-	else 
-	{
-		// Snap camera back to behind avatar
-		gAgentCamera.setFocusOnAvatar(TRUE, ANIMATE);
-	}
-
-	// Could be first use
-	//LLFirstUse::useGoTo();
-	return true;
+    // try simulator autopilot
+    std::vector<std::string> strings;
+    std::string val;
+    LLVector3d pos = LLToolPie::getInstance()->getPick().mPosGlobal;
+    val = llformat("%g", pos.mdV[VX]);
+    strings.push_back(val);
+    val = llformat("%g", pos.mdV[VY]);
+    strings.push_back(val);
+    val = llformat("%g", pos.mdV[VZ]);
+    strings.push_back(val);
+    send_generic_message("autopilot", strings);
+
+    LLViewerParcelMgr::getInstance()->deselectLand();
+
+    if (isAgentAvatarValid() && !gSavedSettings.getBOOL("AutoPilotLocksCamera"))
+    {
+        gAgentCamera.setFocusGlobal(gAgentCamera.getFocusTargetGlobal(), gAgentAvatarp->getID());
+    }
+    else
+    {
+        // Snap camera back to behind avatar
+        gAgentCamera.setFocusOnAvatar(TRUE, ANIMATE);
+    }
+
+    // Could be first use
+    //LLFirstUse::useGoTo();
+    return true;
 }
 
 class LLGoToObject : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return handle_go_to();
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return handle_go_to();
+    }
 };
 
 class LLAvatarReportAbuse : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
-		if(avatar)
-		{
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
+        if(avatar)
+        {
 
-			ALAvatarActions::reportAbuse(avatar->getID());
-		}
-		return true;
-	}
+            ALAvatarActions::reportAbuse(avatar->getID());
+        }
+        return true;
+    }
 };
 
 
@@ -3737,165 +3737,165 @@ class LLAvatarReportAbuse : public view_listener_t
 //---------------------------------------------------------------------------
 bool callback_freeze(const LLSD& notification, const LLSD& response)
 {
-	LLUUID avatar_id = notification["payload"]["avatar_id"].asUUID();
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-
-	if (0 == option || 1 == option)
-	{
-		U32 flags = 0x0;
-		if (1 == option)
-		{
-			// unfreeze
-			flags |= 0x1;
-		}
-
-		LLMessageSystem* msg = gMessageSystem;
-		LLViewerObject* avatar = gObjectList.findObject(avatar_id);
-
-		if (avatar)
-		{
-			msg->newMessage("FreezeUser");
-			msg->nextBlock("AgentData");
-			msg->addUUID("AgentID", gAgent.getID());
-			msg->addUUID("SessionID", gAgent.getSessionID());
-			msg->nextBlock("Data");
-			msg->addUUID("TargetID", avatar_id );
-			msg->addU32("Flags", flags );
-			msg->sendReliable( avatar->getRegion()->getHost() );
-		}
-	}
-	return false;
+    LLUUID avatar_id = notification["payload"]["avatar_id"].asUUID();
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+
+    if (0 == option || 1 == option)
+    {
+        U32 flags = 0x0;
+        if (1 == option)
+        {
+            // unfreeze
+            flags |= 0x1;
+        }
+
+        LLMessageSystem* msg = gMessageSystem;
+        LLViewerObject* avatar = gObjectList.findObject(avatar_id);
+
+        if (avatar)
+        {
+            msg->newMessage("FreezeUser");
+            msg->nextBlock("AgentData");
+            msg->addUUID("AgentID", gAgent.getID());
+            msg->addUUID("SessionID", gAgent.getSessionID());
+            msg->nextBlock("Data");
+            msg->addUUID("TargetID", avatar_id );
+            msg->addU32("Flags", flags );
+            msg->sendReliable( avatar->getRegion()->getHost() );
+        }
+    }
+    return false;
 }
 
 
 void handle_avatar_freeze(const LLSD& avatar_id)
 {
-	// Use avatar_id if available, otherwise default to right-click avatar
-	LLVOAvatar* avatar = NULL;
-	if (avatar_id.asUUID().notNull())
-	{
-		avatar = find_avatar_from_object(avatar_id.asUUID());
-	}
-	else
-	{
-		avatar = find_avatar_from_object(
-			LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
-	}
+    // Use avatar_id if available, otherwise default to right-click avatar
+    LLVOAvatar* avatar = NULL;
+    if (avatar_id.asUUID().notNull())
+    {
+        avatar = find_avatar_from_object(avatar_id.asUUID());
+    }
+    else
+    {
+        avatar = find_avatar_from_object(
+            LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
+    }
 
-	if (avatar)
-	{
-		ALAvatarActions::parcelFreeze(avatar->getID());
-	}
+    if (avatar)
+    {
+        ALAvatarActions::parcelFreeze(avatar->getID());
+    }
 }
 
 class LLAvatarVisibleDebug : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return gAgent.isGodlike();
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return gAgent.isGodlike();
+    }
 };
 
 class LLAvatarDebug : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
-		if( avatar )
-		{
-			if (avatar->isSelf())
-			{
-				((LLVOAvatarSelf *)avatar)->dumpLocalTextures();
-			}
-			LL_INFOS() << "Dumping temporary asset data to simulator logs for avatar " << avatar->getID() << LL_ENDL;
-			std::vector<std::string> strings;
-			strings.push_back(avatar->getID().asString());
-			LLUUID invoice;
-			send_generic_message("dumptempassetdata", strings, invoice);
-			LLFloaterReg::showInstance( "avatar_textures", LLSD(avatar->getID()) );
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
+        if( avatar )
+        {
+            if (avatar->isSelf())
+            {
+                ((LLVOAvatarSelf *)avatar)->dumpLocalTextures();
+            }
+            LL_INFOS() << "Dumping temporary asset data to simulator logs for avatar " << avatar->getID() << LL_ENDL;
+            std::vector<std::string> strings;
+            strings.push_back(avatar->getID().asString());
+            LLUUID invoice;
+            send_generic_message("dumptempassetdata", strings, invoice);
+            LLFloaterReg::showInstance( "avatar_textures", LLSD(avatar->getID()) );
+        }
+        return true;
+    }
 };
 
 bool callback_eject(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (2 == option)
-	{
-		// Cancel button.
-		return false;
-	}
-	LLUUID avatar_id = notification["payload"]["avatar_id"].asUUID();
-	bool ban_enabled = notification["payload"]["ban_enabled"].asBoolean();
-
-	if (0 == option)
-	{
-		// Eject button
-		LLMessageSystem* msg = gMessageSystem;
-		LLViewerObject* avatar = gObjectList.findObject(avatar_id);
-
-		if (avatar)
-		{
-			U32 flags = 0x0;
-			msg->newMessage("EjectUser");
-			msg->nextBlock("AgentData");
-			msg->addUUID("AgentID", gAgent.getID() );
-			msg->addUUID("SessionID", gAgent.getSessionID() );
-			msg->nextBlock("Data");
-			msg->addUUID("TargetID", avatar_id );
-			msg->addU32("Flags", flags );
-			msg->sendReliable( avatar->getRegion()->getHost() );
-		}
-	}
-	else if (ban_enabled)
-	{
-		// This is tricky. It is similar to say if it is not an 'Eject' button,
-		// and it is also not an 'Cancle' button, and ban_enabled==ture, 
-		// it should be the 'Eject and Ban' button.
-		LLMessageSystem* msg = gMessageSystem;
-		LLViewerObject* avatar = gObjectList.findObject(avatar_id);
-
-		if (avatar)
-		{
-			U32 flags = 0x1;
-			msg->newMessage("EjectUser");
-			msg->nextBlock("AgentData");
-			msg->addUUID("AgentID", gAgent.getID() );
-			msg->addUUID("SessionID", gAgent.getSessionID() );
-			msg->nextBlock("Data");
-			msg->addUUID("TargetID", avatar_id );
-			msg->addU32("Flags", flags );
-			msg->sendReliable( avatar->getRegion()->getHost() );
-		}
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (2 == option)
+    {
+        // Cancel button.
+        return false;
+    }
+    LLUUID avatar_id = notification["payload"]["avatar_id"].asUUID();
+    bool ban_enabled = notification["payload"]["ban_enabled"].asBoolean();
+
+    if (0 == option)
+    {
+        // Eject button
+        LLMessageSystem* msg = gMessageSystem;
+        LLViewerObject* avatar = gObjectList.findObject(avatar_id);
+
+        if (avatar)
+        {
+            U32 flags = 0x0;
+            msg->newMessage("EjectUser");
+            msg->nextBlock("AgentData");
+            msg->addUUID("AgentID", gAgent.getID() );
+            msg->addUUID("SessionID", gAgent.getSessionID() );
+            msg->nextBlock("Data");
+            msg->addUUID("TargetID", avatar_id );
+            msg->addU32("Flags", flags );
+            msg->sendReliable( avatar->getRegion()->getHost() );
+        }
+    }
+    else if (ban_enabled)
+    {
+        // This is tricky. It is similar to say if it is not an 'Eject' button,
+        // and it is also not an 'Cancle' button, and ban_enabled==ture,
+        // it should be the 'Eject and Ban' button.
+        LLMessageSystem* msg = gMessageSystem;
+        LLViewerObject* avatar = gObjectList.findObject(avatar_id);
+
+        if (avatar)
+        {
+            U32 flags = 0x1;
+            msg->newMessage("EjectUser");
+            msg->nextBlock("AgentData");
+            msg->addUUID("AgentID", gAgent.getID() );
+            msg->addUUID("SessionID", gAgent.getSessionID() );
+            msg->nextBlock("Data");
+            msg->addUUID("TargetID", avatar_id );
+            msg->addU32("Flags", flags );
+            msg->sendReliable( avatar->getRegion()->getHost() );
+        }
+    }
+    return false;
 }
 
 void handle_avatar_eject(const LLSD& avatar_id)
 {
-	// Use avatar_id if available, otherwise default to right-click avatar
-	LLVOAvatar* avatar = NULL;
-	if (avatar_id.asUUID().notNull())
-	{
-		avatar = find_avatar_from_object(avatar_id.asUUID());
-	}
-	else
-	{
-		avatar = find_avatar_from_object(
-			LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
-	}
+    // Use avatar_id if available, otherwise default to right-click avatar
+    LLVOAvatar* avatar = NULL;
+    if (avatar_id.asUUID().notNull())
+    {
+        avatar = find_avatar_from_object(avatar_id.asUUID());
+    }
+    else
+    {
+        avatar = find_avatar_from_object(
+            LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
+    }
 
-	if (avatar)
-	{
-		ALAvatarActions::parcelEject(avatar->getID());
-	}
+    if (avatar)
+    {
+        ALAvatarActions::parcelEject(avatar->getID());
+    }
 }
 
 bool my_profile_visible()
 {
-	LLFloater* floaterp = LLAvatarActions::findProfileFloater(gAgentID);
-	return floaterp && floaterp->isInVisibleChain();
+    LLFloater* floaterp = LLAvatarActions::findProfileFloater(gAgentID);
+    return floaterp && floaterp->isInVisibleChain();
 }
 
 bool picks_tab_visible()
@@ -3905,184 +3905,184 @@ bool picks_tab_visible()
 
 bool enable_freeze_eject(const LLSD& avatar_id)
 {
-	// Use avatar_id if available, otherwise default to right-click avatar
-	LLVOAvatar* avatar = NULL;
-	if (avatar_id.asUUID().notNull())
-	{
-		avatar = find_avatar_from_object(avatar_id.asUUID());
-	}
-	else
-	{
-		avatar = find_avatar_from_object(
-			LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
-	}
-	if (!avatar) return false;
+    // Use avatar_id if available, otherwise default to right-click avatar
+    LLVOAvatar* avatar = NULL;
+    if (avatar_id.asUUID().notNull())
+    {
+        avatar = find_avatar_from_object(avatar_id.asUUID());
+    }
+    else
+    {
+        avatar = find_avatar_from_object(
+            LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
+    }
+    if (!avatar) return false;
 
-	// Gods can always freeze
-	if (gAgent.isGodlike()) return true;
+    // Gods can always freeze
+    if (gAgent.isGodlike()) return true;
 
-	return ALAvatarActions::canFreezeEject(avatar->getID());
+    return ALAvatarActions::canFreezeEject(avatar->getID());
 }
 
 bool callback_leave_group(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option == 0)
-	{
-		LLMessageSystem *msg = gMessageSystem;
-
-		msg->newMessageFast(_PREHASH_LeaveGroupRequest);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_GroupData);
-		msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID() );
-		gAgent.sendReliableMessage();
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option == 0)
+    {
+        LLMessageSystem *msg = gMessageSystem;
+
+        msg->newMessageFast(_PREHASH_LeaveGroupRequest);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        msg->nextBlockFast(_PREHASH_GroupData);
+        msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID() );
+        gAgent.sendReliableMessage();
+    }
+    return false;
 }
 
 void append_aggregate(std::string& string, const LLAggregatePermissions& ag_perm, PermissionBit bit, const char* txt)
 {
-	LLAggregatePermissions::EValue val = ag_perm.getValue(bit);
-	std::string buffer;
-	switch(val)
-	{
-	  case LLAggregatePermissions::AP_NONE:
-		buffer = llformat( "* %s None\n", txt);
-		break;
-	  case LLAggregatePermissions::AP_SOME:
-		buffer = llformat( "* %s Some\n", txt);
-		break;
-	  case LLAggregatePermissions::AP_ALL:
-		buffer = llformat( "* %s All\n", txt);
-		break;
-	  case LLAggregatePermissions::AP_EMPTY:
-	  default:
-		break;
-	}
-	string.append(buffer);
+    LLAggregatePermissions::EValue val = ag_perm.getValue(bit);
+    std::string buffer;
+    switch(val)
+    {
+      case LLAggregatePermissions::AP_NONE:
+        buffer = llformat( "* %s None\n", txt);
+        break;
+      case LLAggregatePermissions::AP_SOME:
+        buffer = llformat( "* %s Some\n", txt);
+        break;
+      case LLAggregatePermissions::AP_ALL:
+        buffer = llformat( "* %s All\n", txt);
+        break;
+      case LLAggregatePermissions::AP_EMPTY:
+      default:
+        break;
+    }
+    string.append(buffer);
 }
 
 bool enable_buy_object()
 {
     // In order to buy, there must only be 1 purchaseable object in
     // the selection manager.
-	if(LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() != 1) return false;
+    if(LLSelectMgr::getInstance()->getSelection()->getRootObjectCount() != 1) return false;
     LLViewerObject* obj = NULL;
     LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
-	if(node)
+    if(node)
     {
         obj = node->getObject();
         if(!obj) return false;
 
-		if( for_sale_selection(node) )
-		{
+        if( for_sale_selection(node) )
+        {
 // [RLVa:KB] - @buy
-			if (!RlvActions::canBuyObject(obj->getID()))
-				return false;
+            if (!RlvActions::canBuyObject(obj->getID()))
+                return false;
 // [/RLVa:KB]
 
-			// *NOTE: Is this needed?  This checks to see if anyone owns the
-			// object, dating back to when we had "public" objects owned by
-			// no one.  JC
-			if(obj->permAnyOwner()) return true;
-		}
+            // *NOTE: Is this needed?  This checks to see if anyone owns the
+            // object, dating back to when we had "public" objects owned by
+            // no one.  JC
+            if(obj->permAnyOwner()) return true;
+        }
     }
-	return false;
+    return false;
 }
 
 // Note: This will only work if the selected object's data has been
 // received by the viewer and cached in the selection manager.
 void handle_buy_object(LLSaleInfo sale_info)
 {
-	if(!LLSelectMgr::getInstance()->selectGetAllRootsValid())
-	{
-		LLNotificationsUtil::add("UnableToBuyWhileDownloading");
-		return;
-	}
+    if(!LLSelectMgr::getInstance()->selectGetAllRootsValid())
+    {
+        LLNotificationsUtil::add("UnableToBuyWhileDownloading");
+        return;
+    }
 
-	LLUUID owner_id;
-	std::string owner_name;
-	BOOL owners_identical = LLSelectMgr::getInstance()->selectGetOwner(owner_id, owner_name);
-	if (!owners_identical)
-	{
-		LLNotificationsUtil::add("CannotBuyObjectsFromDifferentOwners");
-		return;
-	}
+    LLUUID owner_id;
+    std::string owner_name;
+    BOOL owners_identical = LLSelectMgr::getInstance()->selectGetOwner(owner_id, owner_name);
+    if (!owners_identical)
+    {
+        LLNotificationsUtil::add("CannotBuyObjectsFromDifferentOwners");
+        return;
+    }
 
-	LLPermissions perm;
-	BOOL valid = LLSelectMgr::getInstance()->selectGetPermissions(perm);
-	LLAggregatePermissions ag_perm;
-	valid &= LLSelectMgr::getInstance()->selectGetAggregatePermissions(ag_perm);
-	if(!valid || !sale_info.isForSale() || !perm.allowTransferTo(gAgent.getID()))
-	{
-		LLNotificationsUtil::add("ObjectNotForSale");
-		return;
-	}
+    LLPermissions perm;
+    BOOL valid = LLSelectMgr::getInstance()->selectGetPermissions(perm);
+    LLAggregatePermissions ag_perm;
+    valid &= LLSelectMgr::getInstance()->selectGetAggregatePermissions(ag_perm);
+    if(!valid || !sale_info.isForSale() || !perm.allowTransferTo(gAgent.getID()))
+    {
+        LLNotificationsUtil::add("ObjectNotForSale");
+        return;
+    }
 
-	LLFloaterBuy::show(sale_info);
+    LLFloaterBuy::show(sale_info);
 }
 
 
 void handle_buy_contents(LLSaleInfo sale_info)
 {
-	LLFloaterBuyContents::show(sale_info);
+    LLFloaterBuyContents::show(sale_info);
 }
 
 void handle_region_dump_temp_asset_data(void*)
 {
-	LL_INFOS() << "Dumping temporary asset data to simulator logs" << LL_ENDL;
-	std::vector<std::string> strings;
-	LLUUID invoice;
-	send_generic_message("dumptempassetdata", strings, invoice);
+    LL_INFOS() << "Dumping temporary asset data to simulator logs" << LL_ENDL;
+    std::vector<std::string> strings;
+    LLUUID invoice;
+    send_generic_message("dumptempassetdata", strings, invoice);
 }
 
 void handle_region_clear_temp_asset_data(void*)
 {
-	LL_INFOS() << "Clearing temporary asset data" << LL_ENDL;
-	std::vector<std::string> strings;
-	LLUUID invoice;
-	send_generic_message("cleartempassetdata", strings, invoice);
+    LL_INFOS() << "Clearing temporary asset data" << LL_ENDL;
+    std::vector<std::string> strings;
+    LLUUID invoice;
+    send_generic_message("cleartempassetdata", strings, invoice);
 }
 
 void handle_region_dump_settings(void*)
 {
-	LLViewerRegion* regionp = gAgent.getRegion();
-	if (regionp)
-	{
-		LL_INFOS() << "Damage:    " << (regionp->getAllowDamage() ? "on" : "off") << LL_ENDL;
-		LL_INFOS() << "Landmark:  " << (regionp->getAllowLandmark() ? "on" : "off") << LL_ENDL;
-		LL_INFOS() << "SetHome:   " << (regionp->getAllowSetHome() ? "on" : "off") << LL_ENDL;
-		LL_INFOS() << "ResetHome: " << (regionp->getResetHomeOnTeleport() ? "on" : "off") << LL_ENDL;
-		LL_INFOS() << "SunFixed:  " << (regionp->getSunFixed() ? "on" : "off") << LL_ENDL;
-		LL_INFOS() << "BlockFly:  " << (regionp->getBlockFly() ? "on" : "off") << LL_ENDL;
-		LL_INFOS() << "AllowP2P:  " << (regionp->getAllowDirectTeleport() ? "on" : "off") << LL_ENDL;
-		LL_INFOS() << "Water:     " << (regionp->getWaterHeight()) << LL_ENDL;
-	}
+    LLViewerRegion* regionp = gAgent.getRegion();
+    if (regionp)
+    {
+        LL_INFOS() << "Damage:    " << (regionp->getAllowDamage() ? "on" : "off") << LL_ENDL;
+        LL_INFOS() << "Landmark:  " << (regionp->getAllowLandmark() ? "on" : "off") << LL_ENDL;
+        LL_INFOS() << "SetHome:   " << (regionp->getAllowSetHome() ? "on" : "off") << LL_ENDL;
+        LL_INFOS() << "ResetHome: " << (regionp->getResetHomeOnTeleport() ? "on" : "off") << LL_ENDL;
+        LL_INFOS() << "SunFixed:  " << (regionp->getSunFixed() ? "on" : "off") << LL_ENDL;
+        LL_INFOS() << "BlockFly:  " << (regionp->getBlockFly() ? "on" : "off") << LL_ENDL;
+        LL_INFOS() << "AllowP2P:  " << (regionp->getAllowDirectTeleport() ? "on" : "off") << LL_ENDL;
+        LL_INFOS() << "Water:     " << (regionp->getWaterHeight()) << LL_ENDL;
+    }
 }
 
 void handle_dump_group_info(void *)
 {
-	gAgent.dumpGroupInfo();
+    gAgent.dumpGroupInfo();
 }
 
 void handle_dump_capabilities_info(void *)
 {
-	LLViewerRegion* regionp = gAgent.getRegion();
-	if (regionp)
-	{
-		regionp->logActiveCapabilities();
-	}
+    LLViewerRegion* regionp = gAgent.getRegion();
+    if (regionp)
+    {
+        regionp->logActiveCapabilities();
+    }
 }
 
 void handle_dump_region_object_cache(void*)
 {
-	LLViewerRegion* regionp = gAgent.getRegion();
-	if (regionp)
-	{
-		regionp->dumpCache();
-	}
+    LLViewerRegion* regionp = gAgent.getRegion();
+    if (regionp)
+    {
+        regionp->dumpCache();
+    }
 }
 
 void handle_reset_interest_lists(void *)
@@ -4103,220 +4103,220 @@ void handle_reset_interest_lists(void *)
 
 void handle_dump_focus()
 {
-	LLUICtrl *ctrl = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
+    LLUICtrl *ctrl = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
 
-	LL_INFOS() << "Keyboard focus " << (ctrl ? ctrl->getName() : "(none)") << LL_ENDL;
+    LL_INFOS() << "Keyboard focus " << (ctrl ? ctrl->getName() : "(none)") << LL_ENDL;
 }
 
 bool enable_standup_self()
 {
 // [RLVa:KB] - Checked: 2010-04-01 (RLVa-1.2.0c) | Modified: RLVa-1.0.0g
-	return isAgentAvatarValid() && gAgentAvatarp->isSitting() && RlvActions::canStand();
+    return isAgentAvatarValid() && gAgentAvatarp->isSitting() && RlvActions::canStand();
 // [/RLVa:KB]
-//	return isAgentAvatarValid() && gAgentAvatarp->isSitting();
+//  return isAgentAvatarValid() && gAgentAvatarp->isSitting();
 }
 
 bool show_sitdown_self()
 {
-	return isAgentAvatarValid() && !gAgentAvatarp->isSitting();
+    return isAgentAvatarValid() && !gAgentAvatarp->isSitting();
 }
 
 bool enable_sitdown_self()
 {
 // [RLVa:KB] - Checked: 2010-08-28 (RLVa-1.2.1a) | Added: RLVa-1.2.1a
-	return show_sitdown_self() && !gAgentAvatarp->isEditingAppearance() && !gAgent.getFlying() && !gRlvHandler.hasBehaviour(RLV_BHVR_SIT);
+    return show_sitdown_self() && !gAgentAvatarp->isEditingAppearance() && !gAgent.getFlying() && !gRlvHandler.hasBehaviour(RLV_BHVR_SIT);
 // [/RLVa:KB]
-//	return show_sitdown_self() && !gAgentAvatarp->isEditingAppearance() && !gAgent.getFlying();
+//  return show_sitdown_self() && !gAgentAvatarp->isEditingAppearance() && !gAgent.getFlying();
 }
 
 class LLSelfToggleSitStand : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (isAgentAvatarValid())
-		{
-			if (gAgentAvatarp->isSitting())
-			{
-				gAgent.standUp();
-			}
-			else
-			{
-				gAgent.sitDown();
-			}
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (isAgentAvatarValid())
+        {
+            if (gAgentAvatarp->isSitting())
+            {
+                gAgent.standUp();
+            }
+            else
+            {
+                gAgent.sitDown();
+            }
+        }
+        return true;
+    }
 };
 
 bool enable_sit_stand()
 {
-	return enable_sitdown_self() || enable_standup_self();
+    return enable_sitdown_self() || enable_standup_self();
 }
 
 bool enable_fly_land()
 {
-	return gAgent.getFlying() || LLAgent::enableFlying();
+    return gAgent.getFlying() || LLAgent::enableFlying();
 }
 
 class LLCheckPanelPeopleTab : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-		{
-			std::string panel_name = userdata.asString();
+    bool handleEvent(const LLSD& userdata)
+        {
+            std::string panel_name = userdata.asString();
 
-			LLPanel *panel = LLFloaterSidePanelContainer::getPanel("people", panel_name);
-			if(panel && panel->isInVisibleChain())
-			{
-				return true;
-			}
-			return false;
-		}
+            LLPanel *panel = LLFloaterSidePanelContainer::getPanel("people", panel_name);
+            if(panel && panel->isInVisibleChain())
+            {
+                return true;
+            }
+            return false;
+        }
 };
 // Toggle one of "People" panel tabs in side tray.
 class LLTogglePanelPeopleTab : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string panel_name = userdata.asString();
-
-		LLSD param;
-		param["people_panel_tab_name"] = panel_name;
-
-		if (   panel_name == "friends_panel"
-			|| panel_name == "groups_panel"
-			|| panel_name == "nearby_panel"
-			|| panel_name == "blocked_panel")
-		{
-			return togglePeoplePanel(panel_name, param);
-		}
-		else
-		{
-			return false;
-		}
-	}
-
-	static bool togglePeoplePanel(const std::string& panel_name, const LLSD& param)
-	{
-		LLPanel	*panel = LLFloaterSidePanelContainer::getPanel("people", panel_name);
-		if(!panel)
-			return false;
-
-		if (panel->isInVisibleChain())
-		{
-			LLFloaterReg::hideInstance("people");
-		}
-		else
-		{
-			LLFloaterSidePanelContainer::showPanel("people", "panel_people", param) ;
-		}
-
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string panel_name = userdata.asString();
+
+        LLSD param;
+        param["people_panel_tab_name"] = panel_name;
+
+        if (   panel_name == "friends_panel"
+            || panel_name == "groups_panel"
+            || panel_name == "nearby_panel"
+            || panel_name == "blocked_panel")
+        {
+            return togglePeoplePanel(panel_name, param);
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    static bool togglePeoplePanel(const std::string& panel_name, const LLSD& param)
+    {
+        LLPanel *panel = LLFloaterSidePanelContainer::getPanel("people", panel_name);
+        if(!panel)
+            return false;
+
+        if (panel->isInVisibleChain())
+        {
+            LLFloaterReg::hideInstance("people");
+        }
+        else
+        {
+            LLFloaterSidePanelContainer::showPanel("people", "panel_people", param) ;
+        }
+
+        return true;
+    }
 };
 
 BOOL check_admin_override(void*)
 {
-	return gAgent.getAdminOverride();
+    return gAgent.getAdminOverride();
 }
 
 void handle_admin_override_toggle(void*)
 {
-	gAgent.setAdminOverride(!gAgent.getAdminOverride());
+    gAgent.setAdminOverride(!gAgent.getAdminOverride());
 
-	// The above may have affected which debug menus are visible
-	show_debug_menus();
+    // The above may have affected which debug menus are visible
+    show_debug_menus();
 }
 
 void handle_visual_leak_detector_toggle(void*)
 {
-	static bool vld_enabled = false;
+    static bool vld_enabled = false;
 
-	if ( vld_enabled )
-	{
+    if ( vld_enabled )
+    {
 #ifdef INCLUDE_VLD
-		// only works for debug builds (hard coded into vld.h)
+        // only works for debug builds (hard coded into vld.h)
 #ifdef _DEBUG
-		// start with Visual Leak Detector turned off
-		VLDDisable();
+        // start with Visual Leak Detector turned off
+        VLDDisable();
 #endif // _DEBUG
 #endif // INCLUDE_VLD
-		vld_enabled = false;
-	}
-	else
-	{
+        vld_enabled = false;
+    }
+    else
+    {
 #ifdef INCLUDE_VLD
-		// only works for debug builds (hard coded into vld.h)
-	#ifdef _DEBUG
-		// start with Visual Leak Detector turned off
-		VLDEnable();
-	#endif // _DEBUG
+        // only works for debug builds (hard coded into vld.h)
+    #ifdef _DEBUG
+        // start with Visual Leak Detector turned off
+        VLDEnable();
+    #endif // _DEBUG
 #endif // INCLUDE_VLD
 
-		vld_enabled = true;
-	};
+        vld_enabled = true;
+    };
 }
 
 void handle_god_mode(void*)
 {
-	gAgent.requestEnterGodMode();
+    gAgent.requestEnterGodMode();
 }
 
 void handle_leave_god_mode(void*)
 {
-	gAgent.requestLeaveGodMode();
+    gAgent.requestLeaveGodMode();
 }
 
 void set_god_level(U8 god_level)
 {
-	U8 old_god_level = gAgent.getGodLevel();
-	gAgent.setGodLevel( god_level );
-	LLViewerParcelMgr::getInstance()->notifyObservers();
+    U8 old_god_level = gAgent.getGodLevel();
+    gAgent.setGodLevel( god_level );
+    LLViewerParcelMgr::getInstance()->notifyObservers();
 
-	// God mode changes region visibility
-	LLWorldMap::getInstance()->reloadItems(true);
+    // God mode changes region visibility
+    LLWorldMap::getInstance()->reloadItems(true);
 
-	// inventory in items may change in god mode
-	gObjectList.dirtyAllObjectInventory();
+    // inventory in items may change in god mode
+    gObjectList.dirtyAllObjectInventory();
 
         if(gViewerWindow)
         {
             gViewerWindow->setMenuBackgroundColor(god_level > GOD_NOT,
             LLGridManager::getInstance()->isInSLBeta());
         }
-    
+
         LLSD args;
-	if(god_level > GOD_NOT)
-	{
-		args["LEVEL"] = llformat("%d",(S32)god_level);
-		LLNotificationsUtil::add("EnteringGodMode", args);
-	}
-	else
-	{
-		args["LEVEL"] = llformat("%d",(S32)old_god_level);
-		LLNotificationsUtil::add("LeavingGodMode", args);
-	}
-
-	// changing god-level can affect which menus we see
-	show_debug_menus();
-
-	// changing god-level can invalidate search results
-	LLFloaterSearch *search = dynamic_cast<LLFloaterSearch*>(LLFloaterReg::getInstance("search"));
-	if (search)
-	{
-		search->godLevelChanged(god_level);
-	}
+    if(god_level > GOD_NOT)
+    {
+        args["LEVEL"] = llformat("%d",(S32)god_level);
+        LLNotificationsUtil::add("EnteringGodMode", args);
+    }
+    else
+    {
+        args["LEVEL"] = llformat("%d",(S32)old_god_level);
+        LLNotificationsUtil::add("LeavingGodMode", args);
+    }
+
+    // changing god-level can affect which menus we see
+    show_debug_menus();
+
+    // changing god-level can invalidate search results
+    LLFloaterSearch *search = dynamic_cast<LLFloaterSearch*>(LLFloaterReg::getInstance("search"));
+    if (search)
+    {
+        search->godLevelChanged(god_level);
+    }
 }
 
 #ifdef TOGGLE_HACKED_GODLIKE_VIEWER
 void handle_toggle_hacked_godmode(void*)
 {
-	gHackGodmode = !gHackGodmode;
-	set_god_level(gHackGodmode ? GOD_MAINTENANCE : GOD_NOT);
+    gHackGodmode = !gHackGodmode;
+    set_god_level(gHackGodmode ? GOD_MAINTENANCE : GOD_NOT);
 }
 
 BOOL check_toggle_hacked_godmode(void*)
 {
-	return gHackGodmode;
+    return gHackGodmode;
 }
 
 bool enable_toggle_hacked_godmode(void*)
@@ -4327,190 +4327,190 @@ bool enable_toggle_hacked_godmode(void*)
 
 void process_grant_godlike_powers(LLMessageSystem* msg, void**)
 {
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	LLUUID session_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
-	if((agent_id == gAgent.getID()) && (session_id == gAgent.getSessionID()))
-	{
-		U8 god_level;
-		msg->getU8Fast(_PREHASH_GrantData, _PREHASH_GodLevel, god_level);
-		set_god_level(god_level);
-	}
-	else
-	{
-		LL_WARNS() << "Grant godlike for wrong agent " << agent_id << LL_ENDL;
-	}
+    LLUUID agent_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+    LLUUID session_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
+    if((agent_id == gAgent.getID()) && (session_id == gAgent.getSessionID()))
+    {
+        U8 god_level;
+        msg->getU8Fast(_PREHASH_GrantData, _PREHASH_GodLevel, god_level);
+        set_god_level(god_level);
+    }
+    else
+    {
+        LL_WARNS() << "Grant godlike for wrong agent " << agent_id << LL_ENDL;
+    }
 }
 
 /*
 class LLHaveCallingcard : public LLInventoryCollectFunctor
 {
 public:
-	LLHaveCallingcard(const LLUUID& agent_id);
-	virtual ~LLHaveCallingcard() {}
-	virtual bool operator()(LLInventoryCategory* cat,
-							LLInventoryItem* item);
-	BOOL isThere() const { return mIsThere;}
+    LLHaveCallingcard(const LLUUID& agent_id);
+    virtual ~LLHaveCallingcard() {}
+    virtual bool operator()(LLInventoryCategory* cat,
+                            LLInventoryItem* item);
+    BOOL isThere() const { return mIsThere;}
 protected:
-	LLUUID mID;
-	BOOL mIsThere;
+    LLUUID mID;
+    BOOL mIsThere;
 };
 
 LLHaveCallingcard::LLHaveCallingcard(const LLUUID& agent_id) :
-	mID(agent_id),
-	mIsThere(FALSE)
+    mID(agent_id),
+    mIsThere(FALSE)
 {
 }
 
 bool LLHaveCallingcard::operator()(LLInventoryCategory* cat,
-								   LLInventoryItem* item)
-{
-	if(item)
-	{
-		if((item->getType() == LLAssetType::AT_CALLINGCARD)
-		   && (item->getCreatorUUID() == mID))
-		{
-			mIsThere = TRUE;
-		}
-	}
-	return FALSE;
+                                   LLInventoryItem* item)
+{
+    if(item)
+    {
+        if((item->getType() == LLAssetType::AT_CALLINGCARD)
+           && (item->getCreatorUUID() == mID))
+        {
+            mIsThere = TRUE;
+        }
+    }
+    return FALSE;
 }
 */
 
 // Enable a menu item when you don't have someone's card.
 class LLAvatarEnableAddFriend : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
-//		bool new_value = avatar && !LLAvatarActions::isFriend(avatar->getID());
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
+//      bool new_value = avatar && !LLAvatarActions::isFriend(avatar->getID());
 // [RLVa:KB] - Checked: RLVa-1.2.0
-		bool new_value = avatar && !LLAvatarActions::isFriend(avatar->getID()) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID()));
+        bool new_value = avatar && !LLAvatarActions::isFriend(avatar->getID()) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID()));
 // [/RLVa:KB]
-		return new_value;
-	}
+        return new_value;
+    }
 };
 
 void request_friendship(const LLUUID& dest_id)
 {
-	LLViewerObject* dest = gObjectList.findObject(dest_id);
-	if(dest && dest->isAvatar())
-	{
-		std::string full_name;
-		LLNameValue* nvfirst = dest->getNVPair("FirstName");
-		LLNameValue* nvlast = dest->getNVPair("LastName");
-		if(nvfirst && nvlast)
-		{
-			full_name = LLCacheName::buildFullName(
-				nvfirst->getString(), nvlast->getString());
-		}
-		if (!full_name.empty())
-		{
-			LLAvatarActions::requestFriendshipDialog(dest_id, full_name);
-		}
-		else
-		{
-			LLNotificationsUtil::add("CantOfferFriendship");
-		}
-	}
+    LLViewerObject* dest = gObjectList.findObject(dest_id);
+    if(dest && dest->isAvatar())
+    {
+        std::string full_name;
+        LLNameValue* nvfirst = dest->getNVPair("FirstName");
+        LLNameValue* nvlast = dest->getNVPair("LastName");
+        if(nvfirst && nvlast)
+        {
+            full_name = LLCacheName::buildFullName(
+                nvfirst->getString(), nvlast->getString());
+        }
+        if (!full_name.empty())
+        {
+            LLAvatarActions::requestFriendshipDialog(dest_id, full_name);
+        }
+        else
+        {
+            LLNotificationsUtil::add("CantOfferFriendship");
+        }
+    }
 }
 
 
 class LLEditEnableCustomizeAvatar : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-//		bool new_value = gAgentWearables.areWearablesLoaded();
+    bool handleEvent(const LLSD& userdata)
+    {
+//      bool new_value = gAgentWearables.areWearablesLoaded();
 // [RLVa:KB] - Checked: 2010-04-01 (RLVa-1.2.0c) | Modified: RLVa-1.0.0g
-		bool new_value = gAgentWearables.areWearablesLoaded() && ((!rlv_handler_t::isEnabled()) || (RlvActions::canStand()));
+        bool new_value = gAgentWearables.areWearablesLoaded() && ((!rlv_handler_t::isEnabled()) || (RlvActions::canStand()));
 // [/RLVa:KB]
-		return new_value;
-	}
+        return new_value;
+    }
 };
 
 class LLEnableEditShape : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return gAgentWearables.isWearableModifiable(LLWearableType::WT_SHAPE, 0);
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return gAgentWearables.isWearableModifiable(LLWearableType::WT_SHAPE, 0);
+    }
 };
 
 class LLEnableHoverHeight : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return gAgent.getRegion() && gAgent.getRegion()->avatarHoverHeightEnabled();
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return gAgent.getRegion() && gAgent.getRegion()->avatarHoverHeightEnabled();
+    }
 };
 
 class LLEnableEditPhysics : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		//return gAgentWearables.isWearableModifiable(LLWearableType::WT_SHAPE, 0);
-		return TRUE;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        //return gAgentWearables.isWearableModifiable(LLWearableType::WT_SHAPE, 0);
+        return TRUE;
+    }
 };
 
 bool is_object_sittable()
 {
 // [RLVa:KB] - Checked: 2010-03-06 (RLVa-1.2.0c) | Added: RLVa-1.1.0j
-	// RELEASE-RLVa: [SL-2.2.0] Make sure we're examining the same object that handle_sit_or_stand() will request a sit for
-	if (rlv_handler_t::isEnabled())
-	{
-		const LLPickInfo& pick = LLToolPie::getInstance()->getPick();
-		if ( (pick.mObjectID.notNull()) && (!RlvActions::canSit(pick.getObject(), pick.mObjectOffset)) )
-			return false;
-	}
+    // RELEASE-RLVa: [SL-2.2.0] Make sure we're examining the same object that handle_sit_or_stand() will request a sit for
+    if (rlv_handler_t::isEnabled())
+    {
+        const LLPickInfo& pick = LLToolPie::getInstance()->getPick();
+        if ( (pick.mObjectID.notNull()) && (!RlvActions::canSit(pick.getObject(), pick.mObjectOffset)) )
+            return false;
+    }
 // [/RLVa:KB]
 
-	LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+    LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
 
-	if (object && object->getPCode() == LL_PCODE_VOLUME)
-	{
-		return true;
-	}
-	else
-	{
-		return false;
-	}
+    if (object && object->getPCode() == LL_PCODE_VOLUME)
+    {
+        return true;
+    }
+    else
+    {
+        return false;
+    }
 }
 
 // only works on pie menu
 void handle_object_sit(LLViewerObject *object, const LLVector3 &offset)
 {
-	// get object selection offset 
+    // get object selection offset
 
-//	if (object && object->getPCode() == LL_PCODE_VOLUME)
+//  if (object && object->getPCode() == LL_PCODE_VOLUME)
 // [RLVa:KB] - Checked: 2010-03-06 (RLVa-1.2.0c) | Modified: RLVa-1.2.0c
-	if ( (object && object->getPCode() == LL_PCODE_VOLUME) && 
-		 ((!rlv_handler_t::isEnabled()) || (RlvActions::canSit(object, offset))) )
+    if ( (object && object->getPCode() == LL_PCODE_VOLUME) &&
+         ((!rlv_handler_t::isEnabled()) || (RlvActions::canSit(object, offset))) )
 // [/RLVa:KB]
-	{
+    {
 // [RLVa:KB] - Checked: 2010-08-29 (RLVa-1.2.1c) | Added: RLVa-1.2.1c
-		if ( (gRlvHandler.hasBehaviour(RLV_BHVR_STANDTP)) && (isAgentAvatarValid()) )
-		{
-			if (gAgentAvatarp->isSitting())
-			{
-				gAgent.standUp();
-				return;
-			}
-			gRlvHandler.setSitSource(gAgent.getPositionGlobal());
-		}
+        if ( (gRlvHandler.hasBehaviour(RLV_BHVR_STANDTP)) && (isAgentAvatarValid()) )
+        {
+            if (gAgentAvatarp->isSitting())
+            {
+                gAgent.standUp();
+                return;
+            }
+            gRlvHandler.setSitSource(gAgent.getPositionGlobal());
+        }
 // [/RLVa:KB]
 
-		gMessageSystem->newMessageFast(_PREHASH_AgentRequestSit);
-		gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-		gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		gMessageSystem->nextBlockFast(_PREHASH_TargetObject);
-		gMessageSystem->addUUIDFast(_PREHASH_TargetID, object->mID);
-		gMessageSystem->addVector3Fast(_PREHASH_Offset, offset);
+        gMessageSystem->newMessageFast(_PREHASH_AgentRequestSit);
+        gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+        gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        gMessageSystem->nextBlockFast(_PREHASH_TargetObject);
+        gMessageSystem->addUUIDFast(_PREHASH_TargetID, object->mID);
+        gMessageSystem->addVector3Fast(_PREHASH_Offset, offset);
 
-		object->getRegion()->sendReliableMessage();
-	}
+        object->getRegion()->sendReliableMessage();
+    }
 }
 
 void handle_object_sit_or_stand()
@@ -4545,12 +4545,12 @@ void handle_object_sit(const LLUUID& object_id)
 
 void near_sit_down_point(BOOL success, void *)
 {
-	if (success)
-	{
-		gAgent.setFlying(FALSE);
-		gAgent.clearControlFlags(AGENT_CONTROL_STAND_UP); // might have been set by autopilot
-		gAgent.setControlFlags(AGENT_CONTROL_SIT_ON_GROUND);
-	}
+    if (success)
+    {
+        gAgent.setFlying(FALSE);
+        gAgent.clearControlFlags(AGENT_CONTROL_STAND_UP); // might have been set by autopilot
+        gAgent.setControlFlags(AGENT_CONTROL_SIT_ON_GROUND);
+    }
 }
 
 class LLLandSit : public view_listener_t
@@ -4558,8 +4558,8 @@ class LLLandSit : public view_listener_t
     bool handleEvent(const LLSD& userdata)
     {
 // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.2.1f) | Modified: RLVa-1.2.1f
-		if ( (rlv_handler_t::isEnabled()) && ((!RlvActions::canStand()) || (gRlvHandler.hasBehaviour(RLV_BHVR_SIT))) )
-			return true;
+        if ( (rlv_handler_t::isEnabled()) && ((!RlvActions::canStand()) || (gRlvHandler.hasBehaviour(RLV_BHVR_SIT))) )
+            return true;
 // [/RLVa:KB]
 
         if (gAgent.isSitting())
@@ -4603,128 +4603,128 @@ void reset_view_final( BOOL proceed );
 
 void handle_reset_view()
 {
-	if (gAgentCamera.cameraCustomizeAvatar())
-	{
-		// switching to outfit selector should automagically save any currently edited wearable
-		LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "my_outfits"));
-	}
-	gAgentCamera.setFocusOnAvatar(TRUE, FALSE, FALSE);
-	reset_view_final( TRUE );
-	LLFloaterCamera::resetCameraMode();
+    if (gAgentCamera.cameraCustomizeAvatar())
+    {
+        // switching to outfit selector should automagically save any currently edited wearable
+        LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "my_outfits"));
+    }
+    gAgentCamera.setFocusOnAvatar(TRUE, FALSE, FALSE);
+    reset_view_final( TRUE );
+    LLFloaterCamera::resetCameraMode();
 
 // [SL:KB] - Patch: Appearance-RefreshAttachments | Checked: Catznip-5.3
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->rebuildAttachments();
-	}
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->rebuildAttachments();
+    }
 // [/SL:KB]
 }
 
 class LLViewResetView : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		handle_reset_view();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        handle_reset_view();
+        return true;
+    }
 };
 
 // Note: extra parameters allow this function to be called from dialog.
-void reset_view_final( BOOL proceed ) 
+void reset_view_final( BOOL proceed )
 {
-	if( !proceed )
-	{
-		return;
-	}
+    if( !proceed )
+    {
+        return;
+    }
 
-	gAgentCamera.resetView(TRUE, TRUE);
-	gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
+    gAgentCamera.resetView(TRUE, TRUE);
+    gAgentCamera.setLookAt(LOOKAT_TARGET_CLEAR);
 }
 
 class LLViewLookAtLastChatter : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gAgentCamera.lookAtLastChat();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gAgentCamera.lookAtLastChat();
+        return true;
+    }
 };
 
 class LLViewMouselook : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (!gAgentCamera.cameraMouselook())
-		{
-			gAgentCamera.changeCameraToMouselook();
-		}
-		else
-		{
-			gAgentCamera.changeCameraToDefault();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (!gAgentCamera.cameraMouselook())
+        {
+            gAgentCamera.changeCameraToMouselook();
+        }
+        else
+        {
+            gAgentCamera.changeCameraToDefault();
+        }
+        return true;
+    }
 };
 
 class LLViewDefaultUISize : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gSavedSettings.setF32("UIScaleFactor", 1.0f);
-		gSavedSettings.setBOOL("UIAutoScale", FALSE);	
-		gViewerWindow->reshape(gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw());
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gSavedSettings.setF32("UIScaleFactor", 1.0f);
+        gSavedSettings.setBOOL("UIAutoScale", FALSE);
+        gViewerWindow->reshape(gViewerWindow->getWindowWidthRaw(), gViewerWindow->getWindowHeightRaw());
+        return true;
+    }
 };
 
 class LLViewToggleUI : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if(gAgentCamera.getCameraMode() != CAMERA_MODE_MOUSELOOK)
-		{
-			LLNotification::Params params("ConfirmHideUI");
-			params.functor.function(boost::bind(&LLViewToggleUI::confirm, this, _1, _2));
-			LLSD substitutions;
+    bool handleEvent(const LLSD& userdata)
+    {
+        if(gAgentCamera.getCameraMode() != CAMERA_MODE_MOUSELOOK)
+        {
+            LLNotification::Params params("ConfirmHideUI");
+            params.functor.function(boost::bind(&LLViewToggleUI::confirm, this, _1, _2));
+            LLSD substitutions;
 #if LL_DARWIN
-			substitutions["SHORTCUT"] = "Cmd+Shift+U";
+            substitutions["SHORTCUT"] = "Cmd+Shift+U";
 #else
-			substitutions["SHORTCUT"] = "Ctrl+Shift+U";
+            substitutions["SHORTCUT"] = "Ctrl+Shift+U";
 #endif
-			params.substitutions = substitutions;
-			if (!gSavedSettings.getBOOL("HideUIControls"))
-			{
-				// hiding, so show notification
-				LLNotifications::instance().add(params);
-			}
-			else
-			{
-				LLNotifications::instance().forceResponse(params, 0);
-			}
-		}
-		return true;
-	}
-
-	void confirm(const LLSD& notification, const LLSD& response)
-	{
-		S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-
-		if (option == 0) // OK
-		{
-			bool hide_ui = gSavedSettings.getBOOL("HideUIControls");
-			gViewerWindow->setUIVisibility(hide_ui);
-			LLPanelStandStopFlying::getInstance()->setVisible(hide_ui);
-			gSavedSettings.setBOOL("HideUIControls",!hide_ui);
-		}
-	}
+            params.substitutions = substitutions;
+            if (!gSavedSettings.getBOOL("HideUIControls"))
+            {
+                // hiding, so show notification
+                LLNotifications::instance().add(params);
+            }
+            else
+            {
+                LLNotifications::instance().forceResponse(params, 0);
+            }
+        }
+        return true;
+    }
+
+    void confirm(const LLSD& notification, const LLSD& response)
+    {
+        S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+
+        if (option == 0) // OK
+        {
+            bool hide_ui = gSavedSettings.getBOOL("HideUIControls");
+            gViewerWindow->setUIVisibility(hide_ui);
+            LLPanelStandStopFlying::getInstance()->setVisible(hide_ui);
+            gSavedSettings.setBOOL("HideUIControls",!hide_ui);
+        }
+    }
 };
 
 void handle_duplicate_in_place(void*)
 {
-	LL_INFOS() << "handle_duplicate_in_place" << LL_ENDL;
+    LL_INFOS() << "handle_duplicate_in_place" << LL_ENDL;
 
-	LLVector3 offset(0.f, 0.f, 0.f);
-	LLSelectMgr::getInstance()->selectDuplicate(offset, TRUE);
+    LLVector3 offset(0.f, 0.f, 0.f);
+    LLSelectMgr::getInstance()->selectDuplicate(offset, TRUE);
 }
 
 
@@ -4733,121 +4733,121 @@ void handle_duplicate_in_place(void*)
  * No longer able to support viewer side manipulations in this way
  *
 void god_force_inv_owner_permissive(LLViewerObject* object,
-									LLInventoryObject::object_list_t* inventory,
-									S32 serial_num,
-									void*)
-{
-	typedef std::vector<LLPointer<LLViewerInventoryItem> > item_array_t;
-	item_array_t items;
-
-	LLInventoryObject::object_list_t::const_iterator inv_it = inventory->begin();
-	LLInventoryObject::object_list_t::const_iterator inv_end = inventory->end();
-	for ( ; inv_it != inv_end; ++inv_it)
-	{
-		if(((*inv_it)->getType() != LLAssetType::AT_CATEGORY))
-		{
-			LLInventoryObject* obj = *inv_it;
-			LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem((LLViewerInventoryItem*)obj);
-			LLPermissions perm(new_item->getPermissions());
-			perm.setMaskBase(PERM_ALL);
-			perm.setMaskOwner(PERM_ALL);
-			new_item->setPermissions(perm);
-			items.push_back(new_item);
-		}
-	}
-	item_array_t::iterator end = items.end();
-	item_array_t::iterator it;
-	for(it = items.begin(); it != end; ++it)
-	{
-		// since we have the inventory item in the callback, it should not
-		// invalidate iteration through the selection manager.
-		object->updateInventory((*it), TASK_INVENTORY_ITEM_KEY, false);
-	}
+                                    LLInventoryObject::object_list_t* inventory,
+                                    S32 serial_num,
+                                    void*)
+{
+    typedef std::vector<LLPointer<LLViewerInventoryItem> > item_array_t;
+    item_array_t items;
+
+    LLInventoryObject::object_list_t::const_iterator inv_it = inventory->begin();
+    LLInventoryObject::object_list_t::const_iterator inv_end = inventory->end();
+    for ( ; inv_it != inv_end; ++inv_it)
+    {
+        if(((*inv_it)->getType() != LLAssetType::AT_CATEGORY))
+        {
+            LLInventoryObject* obj = *inv_it;
+            LLPointer<LLViewerInventoryItem> new_item = new LLViewerInventoryItem((LLViewerInventoryItem*)obj);
+            LLPermissions perm(new_item->getPermissions());
+            perm.setMaskBase(PERM_ALL);
+            perm.setMaskOwner(PERM_ALL);
+            new_item->setPermissions(perm);
+            items.push_back(new_item);
+        }
+    }
+    item_array_t::iterator end = items.end();
+    item_array_t::iterator it;
+    for(it = items.begin(); it != end; ++it)
+    {
+        // since we have the inventory item in the callback, it should not
+        // invalidate iteration through the selection manager.
+        object->updateInventory((*it), TASK_INVENTORY_ITEM_KEY, false);
+    }
 }
 */
 
 void handle_object_owner_permissive(void*)
 {
-	// only send this if they're a god.
-	if(gAgent.isGodlike())
-	{
-		// do the objects.
-		LLSelectMgr::getInstance()->selectionSetObjectPermissions(PERM_BASE, TRUE, PERM_ALL, TRUE);
-		LLSelectMgr::getInstance()->selectionSetObjectPermissions(PERM_OWNER, TRUE, PERM_ALL, TRUE);
-	}
+    // only send this if they're a god.
+    if(gAgent.isGodlike())
+    {
+        // do the objects.
+        LLSelectMgr::getInstance()->selectionSetObjectPermissions(PERM_BASE, TRUE, PERM_ALL, TRUE);
+        LLSelectMgr::getInstance()->selectionSetObjectPermissions(PERM_OWNER, TRUE, PERM_ALL, TRUE);
+    }
 }
 
 void handle_object_owner_self(void*)
 {
-	// only send this if they're a god.
-	if(gAgent.isGodlike())
-	{
-		LLSelectMgr::getInstance()->sendOwner(gAgent.getID(), gAgent.getGroupID(), TRUE);
-	}
+    // only send this if they're a god.
+    if(gAgent.isGodlike())
+    {
+        LLSelectMgr::getInstance()->sendOwner(gAgent.getID(), gAgent.getGroupID(), TRUE);
+    }
 }
 
 // Shortcut to set owner permissions to not editable.
 void handle_object_lock(void*)
 {
-	LLSelectMgr::getInstance()->selectionSetObjectPermissions(PERM_OWNER, FALSE, PERM_MODIFY);
+    LLSelectMgr::getInstance()->selectionSetObjectPermissions(PERM_OWNER, FALSE, PERM_MODIFY);
 }
 
 void handle_object_asset_ids(void*)
 {
-	// only send this if they're a god.
-	if (gAgent.isGodlike())
-	{
-		LLSelectMgr::getInstance()->sendGodlikeRequest("objectinfo", "assetids");
-	}
+    // only send this if they're a god.
+    if (gAgent.isGodlike())
+    {
+        LLSelectMgr::getInstance()->sendGodlikeRequest("objectinfo", "assetids");
+    }
 }
 
 void handle_force_parcel_owner_to_me(void*)
 {
-	LLViewerParcelMgr::getInstance()->sendParcelGodForceOwner( gAgent.getID() );
+    LLViewerParcelMgr::getInstance()->sendParcelGodForceOwner( gAgent.getID() );
 }
 
 void handle_force_parcel_to_content(void*)
 {
-	LLViewerParcelMgr::getInstance()->sendParcelGodForceToContent();
+    LLViewerParcelMgr::getInstance()->sendParcelGodForceToContent();
 }
 
 void handle_claim_public_land(void*)
 {
-	if (LLViewerParcelMgr::getInstance()->getSelectionRegion() != gAgent.getRegion())
-	{
-		LLNotificationsUtil::add("ClaimPublicLand");
-		return;
-	}
-
-	LLVector3d west_south_global;
-	LLVector3d east_north_global;
-	LLViewerParcelMgr::getInstance()->getSelection(west_south_global, east_north_global);
-	LLVector3 west_south = gAgent.getPosAgentFromGlobal(west_south_global);
-	LLVector3 east_north = gAgent.getPosAgentFromGlobal(east_north_global);
-
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessage("GodlikeMessage");
-	msg->nextBlock("AgentData");
-	msg->addUUID("AgentID", gAgent.getID());
-	msg->addUUID("SessionID", gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
-	msg->nextBlock("MethodData");
-	msg->addString("Method", "claimpublicland");
-	msg->addUUID("Invoice", LLUUID::null);
-	std::string buffer;
-	buffer = llformat( "%f", west_south.mV[VX]);
-	msg->nextBlock("ParamList");
-	msg->addString("Parameter", buffer);
-	buffer = llformat( "%f", west_south.mV[VY]);
-	msg->nextBlock("ParamList");
-	msg->addString("Parameter", buffer);
-	buffer = llformat( "%f", east_north.mV[VX]);
-	msg->nextBlock("ParamList");
-	msg->addString("Parameter", buffer);
-	buffer = llformat( "%f", east_north.mV[VY]);
-	msg->nextBlock("ParamList");
-	msg->addString("Parameter", buffer);
-	gAgent.sendReliableMessage();
+    if (LLViewerParcelMgr::getInstance()->getSelectionRegion() != gAgent.getRegion())
+    {
+        LLNotificationsUtil::add("ClaimPublicLand");
+        return;
+    }
+
+    LLVector3d west_south_global;
+    LLVector3d east_north_global;
+    LLViewerParcelMgr::getInstance()->getSelection(west_south_global, east_north_global);
+    LLVector3 west_south = gAgent.getPosAgentFromGlobal(west_south_global);
+    LLVector3 east_north = gAgent.getPosAgentFromGlobal(east_north_global);
+
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessage("GodlikeMessage");
+    msg->nextBlock("AgentData");
+    msg->addUUID("AgentID", gAgent.getID());
+    msg->addUUID("SessionID", gAgent.getSessionID());
+    msg->addUUIDFast(_PREHASH_TransactionID, LLUUID::null); //not used
+    msg->nextBlock("MethodData");
+    msg->addString("Method", "claimpublicland");
+    msg->addUUID("Invoice", LLUUID::null);
+    std::string buffer;
+    buffer = llformat( "%f", west_south.mV[VX]);
+    msg->nextBlock("ParamList");
+    msg->addString("Parameter", buffer);
+    buffer = llformat( "%f", west_south.mV[VY]);
+    msg->nextBlock("ParamList");
+    msg->addString("Parameter", buffer);
+    buffer = llformat( "%f", east_north.mV[VX]);
+    msg->nextBlock("ParamList");
+    msg->addString("Parameter", buffer);
+    buffer = llformat( "%f", east_north.mV[VY]);
+    msg->nextBlock("ParamList");
+    msg->addString("Parameter", buffer);
+    gAgent.sendReliableMessage();
 }
 
 
@@ -4855,303 +4855,303 @@ void handle_claim_public_land(void*)
 // HACK for easily testing new avatar geometry
 void handle_god_request_avatar_geometry(void *)
 {
-	if (gAgent.isGodlike())
-	{
-		LLSelectMgr::getInstance()->sendGodlikeRequest("avatar toggle", "");
-	}
+    if (gAgent.isGodlike())
+    {
+        LLSelectMgr::getInstance()->sendGodlikeRequest("avatar toggle", "");
+    }
 }
 
 static bool get_derezzable_objects(
-	EDeRezDestination dest,
-	std::string& error,
-	LLViewerRegion*& first_region,
-	std::vector<LLViewerObjectPtr>* derez_objectsp,
-	bool only_check = false)
-{
-	bool found = false;
-
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	
-	if (derez_objectsp)
-		derez_objectsp->reserve(selection->getRootObjectCount());
-
-	// Check conditions that we can't deal with, building a list of
-	// everything that we'll actually be derezzing.
-	for (LLObjectSelection::valid_root_iterator iter = selection->valid_root_begin();
-		 iter != selection->valid_root_end(); iter++)
-	{
-		LLSelectNode* node = *iter;
-		LLViewerObject* object = node->getObject();
-		LLViewerRegion* region = object->getRegion();
-		if (!first_region)
-		{
-			first_region = region;
-		}
-		else
-		{
-			if(region != first_region)
-			{
-				// Derez doesn't work at all if the some of the objects
-				// are in regions besides the first object selected.
-				
-				// ...crosses region boundaries
-				error = "AcquireErrorObjectSpan";
-				break;
-			}
-		}
-		if (object->isAvatar())
-		{
-			// ...don't acquire avatars
-			continue;
-		}
-
-		// If AssetContainers are being sent back, they will appear as 
-		// boxes in the owner's inventory.
-		if (object->getNVPair("AssetContainer")
-			&& dest != DRD_RETURN_TO_OWNER)
-		{
-			// this object is an asset container, derez its contents, not it
-			LL_WARNS() << "Attempt to derez deprecated AssetContainer object type not supported." << LL_ENDL;
-			/*
-			object->requestInventory(container_inventory_arrived, 
-				(void *)(BOOL)(DRD_TAKE_INTO_AGENT_INVENTORY == dest));
-			*/
-			continue;
-		}
-		BOOL can_derez_current = FALSE;
-		switch(dest)
-		{
-		case DRD_TAKE_INTO_AGENT_INVENTORY:
-		case DRD_TRASH:
-			if (!object->isPermanentEnforced() &&
-				((node->mPermissions->allowTransferTo(gAgent.getID()) && object->permModify())
-				|| (node->allowOperationOnNode(PERM_OWNER, GP_OBJECT_MANIPULATE))))
-			{
-				can_derez_current = TRUE;
-			}
-			break;
-
-		case DRD_RETURN_TO_OWNER:
-			if(!object->isAttachment())
-			{
-				can_derez_current = TRUE;
-			}
-			break;
-
-		default:
-			if((node->mPermissions->allowTransferTo(gAgent.getID())
-				&& object->permCopy())
-			   || gAgent.isGodlike())
-			{
-				can_derez_current = TRUE;
-			}
-			break;
-		}
-		if(can_derez_current)
-		{
-			found = true;
-
-			if (only_check)
-				// one found, no need to traverse to the end
-				break;
-
-			if (derez_objectsp)
-				derez_objectsp->push_back(object);
-
-		}
-	}
-
-	return found;
+    EDeRezDestination dest,
+    std::string& error,
+    LLViewerRegion*& first_region,
+    std::vector<LLViewerObjectPtr>* derez_objectsp,
+    bool only_check = false)
+{
+    bool found = false;
+
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+
+    if (derez_objectsp)
+        derez_objectsp->reserve(selection->getRootObjectCount());
+
+    // Check conditions that we can't deal with, building a list of
+    // everything that we'll actually be derezzing.
+    for (LLObjectSelection::valid_root_iterator iter = selection->valid_root_begin();
+         iter != selection->valid_root_end(); iter++)
+    {
+        LLSelectNode* node = *iter;
+        LLViewerObject* object = node->getObject();
+        LLViewerRegion* region = object->getRegion();
+        if (!first_region)
+        {
+            first_region = region;
+        }
+        else
+        {
+            if(region != first_region)
+            {
+                // Derez doesn't work at all if the some of the objects
+                // are in regions besides the first object selected.
+
+                // ...crosses region boundaries
+                error = "AcquireErrorObjectSpan";
+                break;
+            }
+        }
+        if (object->isAvatar())
+        {
+            // ...don't acquire avatars
+            continue;
+        }
+
+        // If AssetContainers are being sent back, they will appear as
+        // boxes in the owner's inventory.
+        if (object->getNVPair("AssetContainer")
+            && dest != DRD_RETURN_TO_OWNER)
+        {
+            // this object is an asset container, derez its contents, not it
+            LL_WARNS() << "Attempt to derez deprecated AssetContainer object type not supported." << LL_ENDL;
+            /*
+            object->requestInventory(container_inventory_arrived,
+                (void *)(BOOL)(DRD_TAKE_INTO_AGENT_INVENTORY == dest));
+            */
+            continue;
+        }
+        BOOL can_derez_current = FALSE;
+        switch(dest)
+        {
+        case DRD_TAKE_INTO_AGENT_INVENTORY:
+        case DRD_TRASH:
+            if (!object->isPermanentEnforced() &&
+                ((node->mPermissions->allowTransferTo(gAgent.getID()) && object->permModify())
+                || (node->allowOperationOnNode(PERM_OWNER, GP_OBJECT_MANIPULATE))))
+            {
+                can_derez_current = TRUE;
+            }
+            break;
+
+        case DRD_RETURN_TO_OWNER:
+            if(!object->isAttachment())
+            {
+                can_derez_current = TRUE;
+            }
+            break;
+
+        default:
+            if((node->mPermissions->allowTransferTo(gAgent.getID())
+                && object->permCopy())
+               || gAgent.isGodlike())
+            {
+                can_derez_current = TRUE;
+            }
+            break;
+        }
+        if(can_derez_current)
+        {
+            found = true;
+
+            if (only_check)
+                // one found, no need to traverse to the end
+                break;
+
+            if (derez_objectsp)
+                derez_objectsp->push_back(object);
+
+        }
+    }
+
+    return found;
 }
 
 static bool can_derez(EDeRezDestination dest)
 {
-	LLViewerRegion* first_region = NULL;
-	std::string error;
-	return get_derezzable_objects(dest, error, first_region, NULL, true);
+    LLViewerRegion* first_region = NULL;
+    std::string error;
+    return get_derezzable_objects(dest, error, first_region, NULL, true);
 }
 
 static void derez_objects(
-	EDeRezDestination dest,
-	const LLUUID& dest_id,
-	LLViewerRegion*& first_region,
-	std::string& error,
-	std::vector<LLViewerObjectPtr>* objectsp)
-{
-	std::vector<LLViewerObjectPtr> derez_objects;
-
-	if (!objectsp) // if objects to derez not specified
-	{
-		// get them from selection
-		if (!get_derezzable_objects(dest, error, first_region, &derez_objects, false))
-		{
-			LL_WARNS() << "No objects to derez" << LL_ENDL;
-			return;
-		}
-
-		objectsp = &derez_objects;
-	}
-
-
-	if(gAgentCamera.cameraMouselook())
-	{
-		gAgentCamera.changeCameraToDefault();
-	}
-
-	// This constant is based on (1200 - HEADER_SIZE) / 4 bytes per
-	// root.  I lopped off a few (33) to provide a bit
-	// pad. HEADER_SIZE is currently 67 bytes, most of which is UUIDs.
-	// This gives us a maximum of 63500 root objects - which should
-	// satisfy anybody.
-	const S32 MAX_ROOTS_PER_PACKET = 250;
-	const S32 MAX_PACKET_COUNT = 254;
-	F32 packets = ceil((F32)objectsp->size() / (F32)MAX_ROOTS_PER_PACKET);
-	if(packets > (F32)MAX_PACKET_COUNT)
-	{
-		error = "AcquireErrorTooManyObjects";
-	}
-
-	if(error.empty() && objectsp->size() > 0)
-	{
-		U8 d = (U8)dest;
-		LLUUID tid;
-		tid.generate();
-		U8 packet_count = (U8)packets;
-		S32 object_index = 0;
-		S32 objects_in_packet = 0;
-		LLMessageSystem* msg = gMessageSystem;
-		for(U8 packet_number = 0;
-			packet_number < packet_count;
-			++packet_number)
-		{
-			msg->newMessageFast(_PREHASH_DeRezObject);
-			msg->nextBlockFast(_PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-			msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-			msg->nextBlockFast(_PREHASH_AgentBlock);
-			msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
-			msg->addU8Fast(_PREHASH_Destination, d);	
-			msg->addUUIDFast(_PREHASH_DestinationID, dest_id);
-			msg->addUUIDFast(_PREHASH_TransactionID, tid);
-			msg->addU8Fast(_PREHASH_PacketCount, packet_count);
-			msg->addU8Fast(_PREHASH_PacketNumber, packet_number);
-			objects_in_packet = 0;
-			while((object_index < objectsp->size())
-				  && (objects_in_packet++ < MAX_ROOTS_PER_PACKET))
-
-			{
-				LLViewerObject* object = objectsp->at(object_index++);
-				msg->nextBlockFast(_PREHASH_ObjectData);
-				msg->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
-				if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral"))
-				{
-					// VEFFECT: DerezObject
-					LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
-					effectp->setPositionGlobal(object->getPositionGlobal());
-					effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-				}
-			}
-			msg->sendReliable(first_region->getHost());
-		}
-		make_ui_sound("UISndObjectRezOut");
-
-		// Busy count decremented by inventory update, so only increment
-		// if will be causing an update.
-		if (dest != DRD_RETURN_TO_OWNER)
-		{
-			gViewerWindow->getWindow()->incBusyCount();
-		}
-	}
-	else if(!error.empty())
-	{
-		LLNotificationsUtil::add(error);
-	}
+    EDeRezDestination dest,
+    const LLUUID& dest_id,
+    LLViewerRegion*& first_region,
+    std::string& error,
+    std::vector<LLViewerObjectPtr>* objectsp)
+{
+    std::vector<LLViewerObjectPtr> derez_objects;
+
+    if (!objectsp) // if objects to derez not specified
+    {
+        // get them from selection
+        if (!get_derezzable_objects(dest, error, first_region, &derez_objects, false))
+        {
+            LL_WARNS() << "No objects to derez" << LL_ENDL;
+            return;
+        }
+
+        objectsp = &derez_objects;
+    }
+
+
+    if(gAgentCamera.cameraMouselook())
+    {
+        gAgentCamera.changeCameraToDefault();
+    }
+
+    // This constant is based on (1200 - HEADER_SIZE) / 4 bytes per
+    // root.  I lopped off a few (33) to provide a bit
+    // pad. HEADER_SIZE is currently 67 bytes, most of which is UUIDs.
+    // This gives us a maximum of 63500 root objects - which should
+    // satisfy anybody.
+    const S32 MAX_ROOTS_PER_PACKET = 250;
+    const S32 MAX_PACKET_COUNT = 254;
+    F32 packets = ceil((F32)objectsp->size() / (F32)MAX_ROOTS_PER_PACKET);
+    if(packets > (F32)MAX_PACKET_COUNT)
+    {
+        error = "AcquireErrorTooManyObjects";
+    }
+
+    if(error.empty() && objectsp->size() > 0)
+    {
+        U8 d = (U8)dest;
+        LLUUID tid;
+        tid.generate();
+        U8 packet_count = (U8)packets;
+        S32 object_index = 0;
+        S32 objects_in_packet = 0;
+        LLMessageSystem* msg = gMessageSystem;
+        for(U8 packet_number = 0;
+            packet_number < packet_count;
+            ++packet_number)
+        {
+            msg->newMessageFast(_PREHASH_DeRezObject);
+            msg->nextBlockFast(_PREHASH_AgentData);
+            msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+            msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+            msg->nextBlockFast(_PREHASH_AgentBlock);
+            msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
+            msg->addU8Fast(_PREHASH_Destination, d);
+            msg->addUUIDFast(_PREHASH_DestinationID, dest_id);
+            msg->addUUIDFast(_PREHASH_TransactionID, tid);
+            msg->addU8Fast(_PREHASH_PacketCount, packet_count);
+            msg->addU8Fast(_PREHASH_PacketNumber, packet_number);
+            objects_in_packet = 0;
+            while((object_index < objectsp->size())
+                  && (objects_in_packet++ < MAX_ROOTS_PER_PACKET))
+
+            {
+                LLViewerObject* object = objectsp->at(object_index++);
+                msg->nextBlockFast(_PREHASH_ObjectData);
+                msg->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
+                if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral"))
+                {
+                    // VEFFECT: DerezObject
+                    LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
+                    effectp->setPositionGlobal(object->getPositionGlobal());
+                    effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+                }
+            }
+            msg->sendReliable(first_region->getHost());
+        }
+        make_ui_sound("UISndObjectRezOut");
+
+        // Busy count decremented by inventory update, so only increment
+        // if will be causing an update.
+        if (dest != DRD_RETURN_TO_OWNER)
+        {
+            gViewerWindow->getWindow()->incBusyCount();
+        }
+    }
+    else if(!error.empty())
+    {
+        LLNotificationsUtil::add(error);
+    }
 }
 
 static void derez_objects(EDeRezDestination dest, const LLUUID& dest_id)
 {
-	LLViewerRegion* first_region = NULL;
-	std::string error;
-	derez_objects(dest, dest_id, first_region, error, NULL);
+    LLViewerRegion* first_region = NULL;
+    std::string error;
+    derez_objects(dest, dest_id, first_region, error, NULL);
 }
 
 void handle_take_copy()
 {
-	if (LLSelectMgr::getInstance()->getSelection()->isEmpty()) return;
+    if (LLSelectMgr::getInstance()->getSelection()->isEmpty()) return;
 
 // [RLVa:KB] - Checked: 2010-03-07 (RLVa-1.2.0c) | Modified: RLVa-1.2.0a
-	if ( (rlv_handler_t::isEnabled()) && (!RlvActions::canStand()) )
-	{
-		// Allow only if the avie isn't sitting on any of the selected objects
-		LLObjectSelectionHandle hSel = LLSelectMgr::getInstance()->getSelection();
-		RlvSelectIsSittingOn f(gAgentAvatarp);
-		if ( (hSel.notNull()) && (hSel->getFirstRootNode(&f, TRUE) != NULL) )
-			return;
-	}
+    if ( (rlv_handler_t::isEnabled()) && (!RlvActions::canStand()) )
+    {
+        // Allow only if the avie isn't sitting on any of the selected objects
+        LLObjectSelectionHandle hSel = LLSelectMgr::getInstance()->getSelection();
+        RlvSelectIsSittingOn f(gAgentAvatarp);
+        if ( (hSel.notNull()) && (hSel->getFirstRootNode(&f, TRUE) != NULL) )
+            return;
+    }
 // [/RLVa:KB]
 
-	const LLUUID category_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OBJECT);
-	derez_objects(DRD_ACQUIRE_TO_AGENT_INVENTORY, category_id);
+    const LLUUID category_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OBJECT);
+    derez_objects(DRD_ACQUIRE_TO_AGENT_INVENTORY, category_id);
 }
 
 void handle_link_objects()
 {
-	if (LLSelectMgr::getInstance()->getSelection()->isEmpty())
-	{
-		LLFloaterReg::toggleInstanceOrBringToFront("places");
-	}
-	else
-	{
-		LLSelectMgr::getInstance()->linkObjects();
-	}
+    if (LLSelectMgr::getInstance()->getSelection()->isEmpty())
+    {
+        LLFloaterReg::toggleInstanceOrBringToFront("places");
+    }
+    else
+    {
+        LLSelectMgr::getInstance()->linkObjects();
+    }
 }
 
 // You can return an object to its owner if it is on your land.
 class LLObjectReturn : public view_listener_t
 {
 public:
-	LLObjectReturn() : mFirstRegion(NULL) {}
+    LLObjectReturn() : mFirstRegion(NULL) {}
 
 private:
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (LLSelectMgr::getInstance()->getSelection()->isEmpty()) return true;
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (LLSelectMgr::getInstance()->getSelection()->isEmpty()) return true;
 // [RLVa:KB] - Checked: 2010-03-24 (RLVa-1.4.0a) | Modified: RLVa-1.0.0b
-		if ( (rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn()) ) return true;
+        if ( (rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn()) ) return true;
 // [/RLVa:KB]
 
-		mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
+        mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
 
-		// Save selected objects, so that we still know what to return after the confirmation dialog resets selection.
-		get_derezzable_objects(DRD_RETURN_TO_OWNER, mError, mFirstRegion, &mReturnableObjects);
+        // Save selected objects, so that we still know what to return after the confirmation dialog resets selection.
+        get_derezzable_objects(DRD_RETURN_TO_OWNER, mError, mFirstRegion, &mReturnableObjects);
 
-		LLNotificationsUtil::add("ReturnToOwner", LLSD(), LLSD(), boost::bind(&LLObjectReturn::onReturnToOwner, this, _1, _2));
-		return true;
-	}
+        LLNotificationsUtil::add("ReturnToOwner", LLSD(), LLSD(), boost::bind(&LLObjectReturn::onReturnToOwner, this, _1, _2));
+        return true;
+    }
 
-	bool onReturnToOwner(const LLSD& notification, const LLSD& response)
-	{
-		S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-		if (0 == option)
-		{
-			// Ignore category ID for this derez destination.
-			derez_objects(DRD_RETURN_TO_OWNER, LLUUID::null, mFirstRegion, mError, &mReturnableObjects);
-		}
+    bool onReturnToOwner(const LLSD& notification, const LLSD& response)
+    {
+        S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+        if (0 == option)
+        {
+            // Ignore category ID for this derez destination.
+            derez_objects(DRD_RETURN_TO_OWNER, LLUUID::null, mFirstRegion, mError, &mReturnableObjects);
+        }
 
-		mReturnableObjects.clear();
-		mError.clear();
-		mFirstRegion = NULL;
+        mReturnableObjects.clear();
+        mError.clear();
+        mFirstRegion = NULL;
 
-		// drop reference to current selection
-		mObjectSelection = NULL;
-		return false;
-	}
+        // drop reference to current selection
+        mObjectSelection = NULL;
+        return false;
+    }
 
-	LLObjectSelectionHandle mObjectSelection;
+    LLObjectSelectionHandle mObjectSelection;
 
-	std::vector<LLViewerObjectPtr> mReturnableObjects;
-	std::string mError;
-	LLViewerRegion* mFirstRegion;
+    std::vector<LLViewerObjectPtr> mReturnableObjects;
+    std::string mError;
+    LLViewerRegion* mFirstRegion;
 };
 
 
@@ -5159,195 +5159,195 @@ class LLObjectReturn : public view_listener_t
 // over land you own.
 class LLObjectEnableReturn : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (LLSelectMgr::getInstance()->getSelection()->isEmpty())
-		{
-			// Do not enable if nothing selected
-			return false;
-		}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (LLSelectMgr::getInstance()->getSelection()->isEmpty())
+        {
+            // Do not enable if nothing selected
+            return false;
+        }
 // [RLVa:KB] - Checked: 2011-05-28 (RLVa-1.4.0a) | Modified: RLVa-1.4.0a
-		if ( (rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn()) )
-		{
-			return false;
-		}
+        if ( (rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn()) )
+        {
+            return false;
+        }
 // [/RLVa:KB]
 #ifdef HACKED_GODLIKE_VIEWER
-		bool new_value = true;
+        bool new_value = true;
 #else
-		bool new_value = false;
-		if (gAgent.isGodlike())
-		{
-			new_value = true;
-		}
-		else
-		{
-			new_value = can_derez(DRD_RETURN_TO_OWNER);
-		}
+        bool new_value = false;
+        if (gAgent.isGodlike())
+        {
+            new_value = true;
+        }
+        else
+        {
+            new_value = can_derez(DRD_RETURN_TO_OWNER);
+        }
 #endif
-		return new_value;
-	}
+        return new_value;
+    }
 };
 
 void force_take_copy(void*)
 {
-	if (LLSelectMgr::getInstance()->getSelection()->isEmpty()) return;
-	const LLUUID category_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OBJECT);
-	derez_objects(DRD_FORCE_TO_GOD_INVENTORY, category_id);
+    if (LLSelectMgr::getInstance()->getSelection()->isEmpty()) return;
+    const LLUUID category_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OBJECT);
+    derez_objects(DRD_FORCE_TO_GOD_INVENTORY, category_id);
 }
 
 void handle_take()
 {
-	// we want to use the folder this was derezzed from if it's
-	// available. Otherwise, derez to the normal place.
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-//	if(LLSelectMgr::getInstance()->getSelection()->isEmpty())
+    // we want to use the folder this was derezzed from if it's
+    // available. Otherwise, derez to the normal place.
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+//  if(LLSelectMgr::getInstance()->getSelection()->isEmpty())
 // [RLVa:KB] - Checked: 2010-03-24 (RLVa-1.2.0e) | Modified: RLVa-1.0.0b
-	if ( (selection->isEmpty()) || ((rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn())) )
+    if ( (selection->isEmpty()) || ((rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn())) )
 // [/RLVa:KB]
-	{
-		return;
-	}
-
-	BOOL you_own_everything = TRUE;
-	BOOL locked_but_takeable_object = FALSE;
-	LLUUID category_id;
-	
-	for (LLSelectNode* node : selection->root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if(object)
-		{
-			if(!object->permYouOwner())
-			{
-				you_own_everything = FALSE;
-			}
-
-			if(!object->permMove())
-			{
-				locked_but_takeable_object = TRUE;
-			}
-		}
-		if(node->mFolderID.notNull())
-		{
-			if(category_id.isNull())
-			{
-				category_id = node->mFolderID;
-			}
-			else if(category_id != node->mFolderID)
-			{
-				// we have found two potential destinations. break out
-				// now and send to the default location.
-				category_id.setNull();
-				break;
-			}
-		}
-	}
-	if(category_id.notNull())
-	{
-		// there is an unambiguous destination. See if this agent has
-		// such a location and it is not in the trash or library
-		if(!gInventory.getCategory(category_id))
-		{
-			// nope, set to NULL.
-			category_id.setNull();
-		}
-		if(category_id.notNull())
-		{
-		        // check trash
-			const LLUUID trash = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-			if(category_id == trash || gInventory.isObjectDescendentOf(category_id, trash))
-			{
-				category_id.setNull();
-			}
-
-			// check library
-			if(gInventory.isObjectDescendentOf(category_id, gInventory.getLibraryRootFolderID()))
-			{
-				category_id.setNull();
-			}
-
-			// check inbox
-			const LLUUID inbox_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_INBOX);
-			if (category_id == inbox_id || gInventory.isObjectDescendentOf(category_id, inbox_id))
-			{
-				category_id.setNull();
-			}
-		}
-	}
-	if(category_id.isNull())
-	{
-		category_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OBJECT);
-	}
-	LLSD payload;
-	payload["folder_id"] = category_id;
-
-	LLNotification::Params params("ConfirmObjectTakeLock");
-	params.payload(payload);
-	// MAINT-290
-	// Reason: Showing the confirmation dialog resets object selection,	thus there is nothing to derez.
-	// Fix: pass selection to the confirm_take, so that selection doesn't "die" after confirmation dialog is opened
-	params.functor.function(boost::bind(confirm_take, _1, _2, selection));
-
-	if(locked_but_takeable_object ||
-	   !you_own_everything)
-	{
-		if(locked_but_takeable_object && you_own_everything)
-		{
-			params.name("ConfirmObjectTakeLock");
-		}
-		else if(!locked_but_takeable_object && !you_own_everything)
-		{
-			params.name("ConfirmObjectTakeNoOwn");
-		}
-		else
-		{
-			params.name("ConfirmObjectTakeLockNoOwn");
-		}
-	
-		LLNotifications::instance().add(params);
-	}
-	else
-	{
-		LLNotifications::instance().forceResponse(params, 0);
-	}
+    {
+        return;
+    }
+
+    BOOL you_own_everything = TRUE;
+    BOOL locked_but_takeable_object = FALSE;
+    LLUUID category_id;
+
+    for (LLSelectNode* node : selection->root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if(object)
+        {
+            if(!object->permYouOwner())
+            {
+                you_own_everything = FALSE;
+            }
+
+            if(!object->permMove())
+            {
+                locked_but_takeable_object = TRUE;
+            }
+        }
+        if(node->mFolderID.notNull())
+        {
+            if(category_id.isNull())
+            {
+                category_id = node->mFolderID;
+            }
+            else if(category_id != node->mFolderID)
+            {
+                // we have found two potential destinations. break out
+                // now and send to the default location.
+                category_id.setNull();
+                break;
+            }
+        }
+    }
+    if(category_id.notNull())
+    {
+        // there is an unambiguous destination. See if this agent has
+        // such a location and it is not in the trash or library
+        if(!gInventory.getCategory(category_id))
+        {
+            // nope, set to NULL.
+            category_id.setNull();
+        }
+        if(category_id.notNull())
+        {
+                // check trash
+            const LLUUID trash = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+            if(category_id == trash || gInventory.isObjectDescendentOf(category_id, trash))
+            {
+                category_id.setNull();
+            }
+
+            // check library
+            if(gInventory.isObjectDescendentOf(category_id, gInventory.getLibraryRootFolderID()))
+            {
+                category_id.setNull();
+            }
+
+            // check inbox
+            const LLUUID inbox_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_INBOX);
+            if (category_id == inbox_id || gInventory.isObjectDescendentOf(category_id, inbox_id))
+            {
+                category_id.setNull();
+            }
+        }
+    }
+    if(category_id.isNull())
+    {
+        category_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_OBJECT);
+    }
+    LLSD payload;
+    payload["folder_id"] = category_id;
+
+    LLNotification::Params params("ConfirmObjectTakeLock");
+    params.payload(payload);
+    // MAINT-290
+    // Reason: Showing the confirmation dialog resets object selection, thus there is nothing to derez.
+    // Fix: pass selection to the confirm_take, so that selection doesn't "die" after confirmation dialog is opened
+    params.functor.function(boost::bind(confirm_take, _1, _2, selection));
+
+    if(locked_but_takeable_object ||
+       !you_own_everything)
+    {
+        if(locked_but_takeable_object && you_own_everything)
+        {
+            params.name("ConfirmObjectTakeLock");
+        }
+        else if(!locked_but_takeable_object && !you_own_everything)
+        {
+            params.name("ConfirmObjectTakeNoOwn");
+        }
+        else
+        {
+            params.name("ConfirmObjectTakeLockNoOwn");
+        }
+
+        LLNotifications::instance().add(params);
+    }
+    else
+    {
+        LLNotifications::instance().forceResponse(params, 0);
+    }
 }
 
 void handle_object_show_inspector()
 {
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	LLViewerObject* objectp = selection->getFirstRootObject(TRUE);
- 	if (!objectp)
- 	{
- 		return;
- 	}
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    LLViewerObject* objectp = selection->getFirstRootObject(TRUE);
+    if (!objectp)
+    {
+        return;
+    }
 
-	LLSD params;
-	params["object_id"] = objectp->getID();
-	LLFloaterReg::showInstance("inspect_object", params);
+    LLSD params;
+    params["object_id"] = objectp->getID();
+    LLFloaterReg::showInstance("inspect_object", params);
 }
 
 void handle_avatar_show_inspector()
 {
-	LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
-	if(avatar)
-	{
-		LLSD params;
-		params["avatar_id"] = avatar->getID();
-		LLFloaterReg::showInstance("inspect_avatar", params);
-	}
+    LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
+    if(avatar)
+    {
+        LLSD params;
+        params["avatar_id"] = avatar->getID();
+        LLFloaterReg::showInstance("inspect_avatar", params);
+    }
 }
 
 
 
 bool confirm_take(const LLSD& notification, const LLSD& response, LLObjectSelectionHandle selection_handle)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if(enable_take() && (option == 0))
-	{
-		derez_objects(DRD_TAKE_INTO_AGENT_INVENTORY, notification["payload"]["folder_id"].asUUID());
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if(enable_take() && (option == 0))
+    {
+        derez_objects(DRD_TAKE_INTO_AGENT_INVENTORY, notification["payload"]["folder_id"].asUUID());
+    }
+    return false;
 }
 
 // You can take an item when it is public and transferrable, or when
@@ -5355,102 +5355,102 @@ bool confirm_take(const LLSD& notification, const LLSD& response, LLObjectSelect
 // one item selected can be copied to inventory.
 BOOL enable_take()
 {
-//	if (sitting_on_selection())
+//  if (sitting_on_selection())
 // [RLVa:KB] - Checked: 2010-03-24 (RLVa-1.2.0e) | Modified: RLVa-1.0.0b
-	if ( (sitting_on_selection()) || ((rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn())) )
+    if ( (sitting_on_selection()) || ((rlv_handler_t::isEnabled()) && (!rlvCanDeleteOrReturn())) )
 // [/RLVa:KB]
-	{
-		return FALSE;
-	}
-
-	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->valid_root_begin_end())
-	{
-		LLViewerObject* object = node->getObject();
-		if (object->isAvatar())
-		{
-			// ...don't acquire avatars
-			continue;
-		}
+    {
+        return FALSE;
+    }
+
+    for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->valid_root_begin_end())
+    {
+        LLViewerObject* object = node->getObject();
+        if (object->isAvatar())
+        {
+            // ...don't acquire avatars
+            continue;
+        }
 
 #ifdef HACKED_GODLIKE_VIEWER
-		return TRUE;
+        return TRUE;
 #else
 # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-		if (LLGridManager::getInstance()->isInSLBeta()
+        if (LLGridManager::getInstance()->isInSLBeta()
             && gAgent.isGodlike())
-		{
-			return TRUE;
-		}
+        {
+            return TRUE;
+        }
 # endif
-		if(!object->isPermanentEnforced() &&
-			((node->mPermissions->allowTransferTo(gAgent.getID())
-			&& object->permModify())
-			|| (node->mPermissions->getOwner() == gAgent.getID())))
-		{
-			return !object->isAttachment();
-		}
+        if(!object->isPermanentEnforced() &&
+            ((node->mPermissions->allowTransferTo(gAgent.getID())
+            && object->permModify())
+            || (node->mPermissions->getOwner() == gAgent.getID())))
+        {
+            return !object->isAttachment();
+        }
 #endif
-	}
-	return FALSE;
+    }
+    return FALSE;
 }
 
 
 void handle_buy_or_take()
 {
-	if (LLSelectMgr::getInstance()->getSelection()->isEmpty())
-	{
-		return;
-	}
-
-	if (is_selection_buy_not_take())
-	{
-		S32 total_price = selection_price();
-
-		if (total_price <= gStatusBar->getBalance() || total_price == 0)
-		{
-			handle_buy();
-		}
-		else
-		{
-			LLStringUtil::format_map_t args;
-			args["AMOUNT"] = llformat("%d", total_price);
-			LLBuyCurrencyHTML::openCurrencyFloater( LLTrans::getString( "this_object_costs", args ), total_price );
-		}
-	}
-	else
-	{
-		handle_take();
-	}
+    if (LLSelectMgr::getInstance()->getSelection()->isEmpty())
+    {
+        return;
+    }
+
+    if (is_selection_buy_not_take())
+    {
+        S32 total_price = selection_price();
+
+        if (total_price <= gStatusBar->getBalance() || total_price == 0)
+        {
+            handle_buy();
+        }
+        else
+        {
+            LLStringUtil::format_map_t args;
+            args["AMOUNT"] = llformat("%d", total_price);
+            LLBuyCurrencyHTML::openCurrencyFloater( LLTrans::getString( "this_object_costs", args ), total_price );
+        }
+    }
+    else
+    {
+        handle_take();
+    }
 }
 
 bool visible_buy_object()
 {
-	return is_selection_buy_not_take() && enable_buy_object();
+    return is_selection_buy_not_take() && enable_buy_object();
 }
 
 bool visible_take_object()
 {
-	return !is_selection_buy_not_take() && enable_take();
+    return !is_selection_buy_not_take() && enable_take();
 }
 
 bool tools_visible_buy_object()
 {
-	return is_selection_buy_not_take();
+    return is_selection_buy_not_take();
 }
 
 bool tools_visible_take_object()
 {
-	return !is_selection_buy_not_take();
+    return !is_selection_buy_not_take();
 }
 
 class LLToolsEnableBuyOrTake : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool is_buy = is_selection_buy_not_take();
-		bool new_value = is_buy ? enable_buy_object() : enable_take();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool is_buy = is_selection_buy_not_take();
+        bool new_value = is_buy ? enable_buy_object() : enable_take();
+        return new_value;
+    }
 };
 
 // This is a small helper function to determine if we have a buy or a
@@ -5471,254 +5471,254 @@ class LLToolsEnableBuyOrTake : public view_listener_t
 //                FALSE if selection is a 'take'
 BOOL is_selection_buy_not_take()
 {
-	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
-	{
-		LLViewerObject* obj = node->getObject();
-		if(obj && !(obj->permYouOwner()) && (node->mSaleInfo.isForSale()))
-		{
+    for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
+    {
+        LLViewerObject* obj = node->getObject();
+        if(obj && !(obj->permYouOwner()) && (node->mSaleInfo.isForSale()))
+        {
 // [RLVa:KB] - @buy
-			if (!RlvActions::canBuyObject(obj->getID()))
-				continue;
+            if (!RlvActions::canBuyObject(obj->getID()))
+                continue;
 // [/RLVa:KB]
 
-			// you do not own the object and it is for sale, thus,
-			// it's a buy
-			return TRUE;
-		}
-	}
-	return FALSE;
+            // you do not own the object and it is for sale, thus,
+            // it's a buy
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 S32 selection_price()
 {
-	S32 total_price = 0;
-	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
-	{
-		LLViewerObject* obj = node->getObject();
-		if(obj && !(obj->permYouOwner()) && (node->mSaleInfo.isForSale()))
-		{
-			// you do not own the object and it is for sale.
-			// Add its price.
-			total_price += node->mSaleInfo.getSalePrice();
-		}
-	}
+    S32 total_price = 0;
+    for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
+    {
+        LLViewerObject* obj = node->getObject();
+        if(obj && !(obj->permYouOwner()) && (node->mSaleInfo.isForSale()))
+        {
+            // you do not own the object and it is for sale.
+            // Add its price.
+            total_price += node->mSaleInfo.getSalePrice();
+        }
+    }
 
-	return total_price;
+    return total_price;
 }
 /*
 bool callback_show_buy_currency(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (0 == option)
-	{
-		LL_INFOS() << "Loading page " << LLNotifications::instance().getGlobalString("BUY_CURRENCY_URL") << LL_ENDL;
-		LLWeb::loadURL(LLNotifications::instance().getGlobalString("BUY_CURRENCY_URL"));
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (0 == option)
+    {
+        LL_INFOS() << "Loading page " << LLNotifications::instance().getGlobalString("BUY_CURRENCY_URL") << LL_ENDL;
+        LLWeb::loadURL(LLNotifications::instance().getGlobalString("BUY_CURRENCY_URL"));
+    }
+    return false;
 }
 */
 
 void show_buy_currency(const char* extra)
 {
-	// Don't show currency web page for branded clients.
+    // Don't show currency web page for branded clients.
 /*
-	std::ostringstream mesg;
-	if (extra != NULL)
-	{	
-		mesg << extra << "\n \n";
-	}
-	mesg << "Go to " << LLNotifications::instance().getGlobalString("BUY_CURRENCY_URL")<< "\nfor information on purchasing currency?";
+    std::ostringstream mesg;
+    if (extra != NULL)
+    {
+        mesg << extra << "\n \n";
+    }
+    mesg << "Go to " << LLNotifications::instance().getGlobalString("BUY_CURRENCY_URL")<< "\nfor information on purchasing currency?";
 */
-	LLSD args;
-	if (extra != NULL)
-	{
-		args["EXTRA"] = extra;
-	}
-	LLNotificationsUtil::add("PromptGoToCurrencyPage", args);//, LLSD(), callback_show_buy_currency);
+    LLSD args;
+    if (extra != NULL)
+    {
+        args["EXTRA"] = extra;
+    }
+    LLNotificationsUtil::add("PromptGoToCurrencyPage", args);//, LLSD(), callback_show_buy_currency);
 }
 
 void handle_buy()
 {
-	if (LLSelectMgr::getInstance()->getSelection()->isEmpty()) return;
+    if (LLSelectMgr::getInstance()->getSelection()->isEmpty()) return;
 
-	LLSaleInfo sale_info;
-	BOOL valid = LLSelectMgr::getInstance()->selectGetSaleInfo(sale_info);
-	if (!valid) return;
+    LLSaleInfo sale_info;
+    BOOL valid = LLSelectMgr::getInstance()->selectGetSaleInfo(sale_info);
+    if (!valid) return;
 
-	S32 price = sale_info.getSalePrice();
-	
-	if (price > 0 && price > gStatusBar->getBalance())
-	{
-		LLStringUtil::format_map_t args;
-		args["AMOUNT"] = llformat("%d", price);
-		LLBuyCurrencyHTML::openCurrencyFloater( LLTrans::getString("this_object_costs", args), price );
-		return;
-	}
+    S32 price = sale_info.getSalePrice();
 
-	if (sale_info.getSaleType() == LLSaleInfo::FS_CONTENTS)
-	{
-		handle_buy_contents(sale_info);
-	}
-	else
-	{
-		handle_buy_object(sale_info);
-	}
+    if (price > 0 && price > gStatusBar->getBalance())
+    {
+        LLStringUtil::format_map_t args;
+        args["AMOUNT"] = llformat("%d", price);
+        LLBuyCurrencyHTML::openCurrencyFloater( LLTrans::getString("this_object_costs", args), price );
+        return;
+    }
+
+    if (sale_info.getSaleType() == LLSaleInfo::FS_CONTENTS)
+    {
+        handle_buy_contents(sale_info);
+    }
+    else
+    {
+        handle_buy_object(sale_info);
+    }
 }
 
 bool anyone_copy_selection(LLSelectNode* nodep)
 {
-	bool perm_copy = (bool)(nodep->getObject()->permCopy());
-	bool all_copy = (bool)(nodep->mPermissions->getMaskEveryone() & PERM_COPY);
-	return perm_copy && all_copy;
+    bool perm_copy = (bool)(nodep->getObject()->permCopy());
+    bool all_copy = (bool)(nodep->mPermissions->getMaskEveryone() & PERM_COPY);
+    return perm_copy && all_copy;
 }
 
 bool for_sale_selection(LLSelectNode* nodep)
 {
-	return nodep->mSaleInfo.isForSale()
-		&& nodep->mPermissions->getMaskOwner() & PERM_TRANSFER
-		&& (nodep->mPermissions->getMaskOwner() & PERM_COPY
-			|| nodep->mSaleInfo.getSaleType() != LLSaleInfo::FS_COPY);
+    return nodep->mSaleInfo.isForSale()
+        && nodep->mPermissions->getMaskOwner() & PERM_TRANSFER
+        && (nodep->mPermissions->getMaskOwner() & PERM_COPY
+            || nodep->mSaleInfo.getSaleType() != LLSaleInfo::FS_COPY);
 }
 
 BOOL sitting_on_selection()
 {
-	LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
-	if (!node)
-	{
-		return FALSE;
-	}
+    LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
+    if (!node)
+    {
+        return FALSE;
+    }
 
-	if (!node->mValid)
-	{
-		return FALSE;
-	}
+    if (!node->mValid)
+    {
+        return FALSE;
+    }
 
-	LLViewerObject* root_object = node->getObject();
-	if (!root_object)
-	{
-		return FALSE;
-	}
+    LLViewerObject* root_object = node->getObject();
+    if (!root_object)
+    {
+        return FALSE;
+    }
 
-	// Need to determine if avatar is sitting on this object
-	if (!isAgentAvatarValid()) return FALSE;
+    // Need to determine if avatar is sitting on this object
+    if (!isAgentAvatarValid()) return FALSE;
 
-	return (gAgentAvatarp->isSitting() && gAgentAvatarp->getRoot() == root_object);
+    return (gAgentAvatarp->isSitting() && gAgentAvatarp->getRoot() == root_object);
 }
 
 class LLToolsSaveToObjectInventory : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
-		if(node && (node->mValid) && (!node->mFromTaskID.isNull()))
-		{
-			// *TODO: check to see if the fromtaskid object exists.
-			derez_objects(DRD_SAVE_INTO_TASK_INVENTORY, node->mFromTaskID);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
+        if(node && (node->mValid) && (!node->mFromTaskID.isNull()))
+        {
+            // *TODO: check to see if the fromtaskid object exists.
+            derez_objects(DRD_SAVE_INTO_TASK_INVENTORY, node->mFromTaskID);
+        }
+        return true;
+    }
 };
 
 class LLToolsEnablePathfinding : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return (LLPathfindingManager::getInstance() != NULL) && LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion();
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return (LLPathfindingManager::getInstance() != NULL) && LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion();
+    }
 };
 
 class LLToolsEnablePathfindingView : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return (LLPathfindingManager::getInstance() != NULL) && LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion() && LLPathfindingManager::getInstance()->isPathfindingViewEnabled();
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return (LLPathfindingManager::getInstance() != NULL) && LLPathfindingManager::getInstance()->isPathfindingEnabledForCurrentRegion() && LLPathfindingManager::getInstance()->isPathfindingViewEnabled();
+    }
 };
 
 class LLToolsDoPathfindingRebakeRegion : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool hasPathfinding = (LLPathfindingManager::getInstance() != NULL);
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool hasPathfinding = (LLPathfindingManager::getInstance() != NULL);
 
-		if (hasPathfinding)
-		{
-			LLMenuOptionPathfindingRebakeNavmesh::getInstance()->sendRequestRebakeNavmesh();
-		}
+        if (hasPathfinding)
+        {
+            LLMenuOptionPathfindingRebakeNavmesh::getInstance()->sendRequestRebakeNavmesh();
+        }
 
-		return hasPathfinding;
-	}
+        return hasPathfinding;
+    }
 };
 
 class LLToolsEnablePathfindingRebakeRegion : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool returnValue = false;
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool returnValue = false;
 
         if (LLNavigationBar::instanceExists())
         {
             returnValue = LLNavigationBar::getInstance()->isRebakeNavMeshAvailable();
         }
-		return returnValue;
-	}
+        return returnValue;
+    }
 };
 
 // Round the position of all root objects to the grid
 class LLToolsSnapObjectXY : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		F64 snap_size = (F64)ALControlCache::GridResolution;
-
-		for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
-		{
-			LLViewerObject* obj = node->getObject();
-			if (obj->permModify())
-			{
-				LLVector3d pos_global = obj->getPositionGlobal();
-				F64 round_x = fmod(pos_global.mdV[VX], snap_size);
-				if (round_x < snap_size * 0.5)
-				{
-					// closer to round down
-					pos_global.mdV[VX] -= round_x;
-				}
-				else
-				{
-					// closer to round up
-					pos_global.mdV[VX] -= round_x;
-					pos_global.mdV[VX] += snap_size;
-				}
-
-				F64 round_y = fmod(pos_global.mdV[VY], snap_size);
-				if (round_y < snap_size * 0.5)
-				{
-					pos_global.mdV[VY] -= round_y;
-				}
-				else
-				{
-					pos_global.mdV[VY] -= round_y;
-					pos_global.mdV[VY] += snap_size;
-				}
-
-				obj->setPositionGlobal(pos_global, FALSE);
-			}
-		}
-		LLSelectMgr::getInstance()->sendMultipleUpdate(UPD_POSITION);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        F64 snap_size = (F64)ALControlCache::GridResolution;
+
+        for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->root_begin_end())
+        {
+            LLViewerObject* obj = node->getObject();
+            if (obj->permModify())
+            {
+                LLVector3d pos_global = obj->getPositionGlobal();
+                F64 round_x = fmod(pos_global.mdV[VX], snap_size);
+                if (round_x < snap_size * 0.5)
+                {
+                    // closer to round down
+                    pos_global.mdV[VX] -= round_x;
+                }
+                else
+                {
+                    // closer to round up
+                    pos_global.mdV[VX] -= round_x;
+                    pos_global.mdV[VX] += snap_size;
+                }
+
+                F64 round_y = fmod(pos_global.mdV[VY], snap_size);
+                if (round_y < snap_size * 0.5)
+                {
+                    pos_global.mdV[VY] -= round_y;
+                }
+                else
+                {
+                    pos_global.mdV[VY] -= round_y;
+                    pos_global.mdV[VY] += snap_size;
+                }
+
+                obj->setPositionGlobal(pos_global, FALSE);
+            }
+        }
+        LLSelectMgr::getInstance()->sendMultipleUpdate(UPD_POSITION);
+        return true;
+    }
 };
 
 // Determine if the option to cycle between linked prims is shown
 class LLToolsEnableSelectNextPart : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
         bool new_value = (!LLSelectMgr::getInstance()->getSelection()->isEmpty()
                           && (ALControlCache::EditLinkedParts
                               || LLToolFace::getInstance() == LLToolMgr::getInstance()->getCurrentTool()));
-		return new_value;
-	}
+        return new_value;
+    }
 };
 
 // Cycle selection through linked children or/and faces in selected object.
@@ -5793,61 +5793,61 @@ class LLToolsSelectNextPartFace : public view_listener_t
             }
         }
 
-		S32 object_count = LLSelectMgr::getInstance()->getSelection()->getObjectCount();
-		if (cycle_linked && object_count && restart_face_on_part)
-		{
-			LLViewerObject* selected = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
-			if (selected && selected->getRootEdit())
-			{
-				LLViewerObject::child_list_t children = selected->getRootEdit()->getChildren();
-				children.push_front(selected->getRootEdit());	// need root in the list too
-
-				for (LLViewerObject::child_list_t::iterator iter = children.begin(); iter != children.end(); ++iter)
-				{
-					if ((*iter)->isSelected())
-					{
-						if (object_count > 1 && (fwd || prev))	// multiple selection, find first or last selected if not include
-						{
-							to_select = *iter;
-							if (fwd)
-							{
-								// stop searching if going forward; repeat to get last hit if backward
-								break;
-							}
-						}
-						else if ((object_count == 1) || (ifwd || iprev))	// single selection or include
-						{
-							if (fwd || ifwd)
-							{
-								++iter;
-								while (iter != children.end() && ((*iter)->isAvatar() || (ifwd && (*iter)->isSelected())))
-								{
-									++iter;	// skip sitting avatars and selected if include
-								}
-							}
-							else // backward
-							{
-								iter = (iter == children.begin() ? children.end() : iter);
-								--iter;
-								while (iter != children.begin() && ((*iter)->isAvatar() || (iprev && (*iter)->isSelected())))
-								{
-									--iter;	// skip sitting avatars and selected if include
-								}
-							}
-							iter = (iter == children.end() ? children.begin() : iter);
-							to_select = *iter;
-							break;
-						}
-					}
-				}
-			}
-		}
+        S32 object_count = LLSelectMgr::getInstance()->getSelection()->getObjectCount();
+        if (cycle_linked && object_count && restart_face_on_part)
+        {
+            LLViewerObject* selected = LLSelectMgr::getInstance()->getSelection()->getFirstObject();
+            if (selected && selected->getRootEdit())
+            {
+                LLViewerObject::child_list_t children = selected->getRootEdit()->getChildren();
+                children.push_front(selected->getRootEdit());   // need root in the list too
+
+                for (LLViewerObject::child_list_t::iterator iter = children.begin(); iter != children.end(); ++iter)
+                {
+                    if ((*iter)->isSelected())
+                    {
+                        if (object_count > 1 && (fwd || prev))  // multiple selection, find first or last selected if not include
+                        {
+                            to_select = *iter;
+                            if (fwd)
+                            {
+                                // stop searching if going forward; repeat to get last hit if backward
+                                break;
+                            }
+                        }
+                        else if ((object_count == 1) || (ifwd || iprev))    // single selection or include
+                        {
+                            if (fwd || ifwd)
+                            {
+                                ++iter;
+                                while (iter != children.end() && ((*iter)->isAvatar() || (ifwd && (*iter)->isSelected())))
+                                {
+                                    ++iter; // skip sitting avatars and selected if include
+                                }
+                            }
+                            else // backward
+                            {
+                                iter = (iter == children.begin() ? children.end() : iter);
+                                --iter;
+                                while (iter != children.begin() && ((*iter)->isAvatar() || (iprev && (*iter)->isSelected())))
+                                {
+                                    --iter; // skip sitting avatars and selected if include
+                                }
+                            }
+                            iter = (iter == children.end() ? children.begin() : iter);
+                            to_select = *iter;
+                            break;
+                        }
+                    }
+                }
+            }
+        }
 
         if (to_select)
         {
             if (gFocusMgr.childHasKeyboardFocus(gFloaterTools))
             {
-                gFocusMgr.setKeyboardFocus(NULL);	// force edit toolbox to commit any changes
+                gFocusMgr.setKeyboardFocus(NULL);   // force edit toolbox to commit any changes
             }
             if (fwd || prev)
             {
@@ -5875,504 +5875,504 @@ class LLToolsSelectNextPartFace : public view_listener_t
             }
             return true;
         }
-		return true;
-	}
+        return true;
+    }
 };
 
 class LLToolsStopAllAnimations : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gAgent.stopCurrentAnimations();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gAgent.stopCurrentAnimations();
+        return true;
+    }
 };
 
 class LLToolsReleaseKeys : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 // [RLVa:KB] - Checked: 2010-04-19 (RLVa-1.2.0f) | Modified: RLVa-1.0.5a
-		if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
-			return true;
+        if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
+            return true;
 // [/RLVa:KB]
 
-		gAgent.forceReleaseControls();
-		return true;
-	}
+        gAgent.forceReleaseControls();
+        return true;
+    }
 };
 
 class LLToolsEnableReleaseKeys : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 // [RLVa:KB] - Checked: 2010-04-19 (RLVa-1.2.0f) | Modified: RLVa-1.0.5a
-		return (gAgent.anyControlGrabbed()) && 
-			( (!rlv_handler_t::isEnabled()) || (!gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) );
+        return (gAgent.anyControlGrabbed()) &&
+            ( (!rlv_handler_t::isEnabled()) || (!gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) );
 // [/RLVa:KB]
-//		return gAgent.anyControlGrabbed();
-	}
+//      return gAgent.anyControlGrabbed();
+    }
 };
 
 
 class LLEditEnableCut : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canCut();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canCut();
+        return new_value;
+    }
 };
 
 class LLEditCut : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if( LLEditMenuHandler::gEditMenuHandler )
-		{
-			LLEditMenuHandler::gEditMenuHandler->cut();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if( LLEditMenuHandler::gEditMenuHandler )
+        {
+            LLEditMenuHandler::gEditMenuHandler->cut();
+        }
+        return true;
+    }
 };
 
 class LLEditEnableCopy : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canCopy();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canCopy();
+        return new_value;
+    }
 };
 
 class LLEditCopy : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if( LLEditMenuHandler::gEditMenuHandler )
-		{
-			LLEditMenuHandler::gEditMenuHandler->copy();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if( LLEditMenuHandler::gEditMenuHandler )
+        {
+            LLEditMenuHandler::gEditMenuHandler->copy();
+        }
+        return true;
+    }
 };
 
 class LLEditEnablePaste : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canPaste();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canPaste();
+        return new_value;
+    }
 };
 
 class LLEditPaste : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if( LLEditMenuHandler::gEditMenuHandler )
-		{
-			LLEditMenuHandler::gEditMenuHandler->paste();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if( LLEditMenuHandler::gEditMenuHandler )
+        {
+            LLEditMenuHandler::gEditMenuHandler->paste();
+        }
+        return true;
+    }
 };
 
 class LLEditEnableDelete : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canDoDelete();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canDoDelete();
+        return new_value;
+    }
 };
 
 class LLEditDelete : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		// If a text field can do a deletion, it gets precedence over deleting
-		// an object in the world.
-		if( LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canDoDelete())
-		{
-			LLEditMenuHandler::gEditMenuHandler->doDelete();
-		}
+    bool handleEvent(const LLSD& userdata)
+    {
+        // If a text field can do a deletion, it gets precedence over deleting
+        // an object in the world.
+        if( LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canDoDelete())
+        {
+            LLEditMenuHandler::gEditMenuHandler->doDelete();
+        }
 
-		// and close any pie/context menus when done
-		gMenuHolder->hideMenus();
+        // and close any pie/context menus when done
+        gMenuHolder->hideMenus();
 
-		// When deleting an object we may not actually be done
-		// Keep selection so we know what to delete when confirmation is needed about the delete
-		gMenuObject->hide();
-		return true;
-	}
+        // When deleting an object we may not actually be done
+        // Keep selection so we know what to delete when confirmation is needed about the delete
+        gMenuObject->hide();
+        return true;
+    }
 };
 
 void handle_spellcheck_replace_with_suggestion(const LLUICtrl* ctrl, const LLSD& param)
 {
-	const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
-	LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
-	if ( (!spellcheck_handler) || (!spellcheck_handler->getSpellCheck()) )
-	{
-		return;
-	}
+    const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
+    LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
+    if ( (!spellcheck_handler) || (!spellcheck_handler->getSpellCheck()) )
+    {
+        return;
+    }
 
-	U32 index = 0;
-	if ( (!LLStringUtil::convertToU32(param.asString(), index)) || (index >= spellcheck_handler->getSuggestionCount()) )
-	{
-		return;
-	}
+    U32 index = 0;
+    if ( (!LLStringUtil::convertToU32(param.asString(), index)) || (index >= spellcheck_handler->getSuggestionCount()) )
+    {
+        return;
+    }
 
-	spellcheck_handler->replaceWithSuggestion(index);
+    spellcheck_handler->replaceWithSuggestion(index);
 }
 
 bool visible_spellcheck_suggestion(LLUICtrl* ctrl, const LLSD& param)
 {
-	LLMenuItemGL* item = dynamic_cast<LLMenuItemGL*>(ctrl);
-	const LLContextMenu* menu = (item) ? dynamic_cast<const LLContextMenu*>(item->getParent()) : NULL;
-	const LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<const LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
-	if ( (!spellcheck_handler) || (!spellcheck_handler->getSpellCheck()) )
-	{
-		return false;
-	}
+    LLMenuItemGL* item = dynamic_cast<LLMenuItemGL*>(ctrl);
+    const LLContextMenu* menu = (item) ? dynamic_cast<const LLContextMenu*>(item->getParent()) : NULL;
+    const LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<const LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
+    if ( (!spellcheck_handler) || (!spellcheck_handler->getSpellCheck()) )
+    {
+        return false;
+    }
 
-	U32 index = 0;
-	if ( (!LLStringUtil::convertToU32(param.asString(), index)) || (index >= spellcheck_handler->getSuggestionCount()) )
-	{
-		return false;
-	}
+    U32 index = 0;
+    if ( (!LLStringUtil::convertToU32(param.asString(), index)) || (index >= spellcheck_handler->getSuggestionCount()) )
+    {
+        return false;
+    }
 
-	item->setLabel(spellcheck_handler->getSuggestion(index));
-	return true;
+    item->setLabel(spellcheck_handler->getSuggestion(index));
+    return true;
 }
 
 void handle_spellcheck_add_to_dictionary(const LLUICtrl* ctrl)
 {
-	const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
-	LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
-	if ( (spellcheck_handler) && (spellcheck_handler->canAddToDictionary()) )
-	{
-		spellcheck_handler->addToDictionary();
-	}
+    const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
+    LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
+    if ( (spellcheck_handler) && (spellcheck_handler->canAddToDictionary()) )
+    {
+        spellcheck_handler->addToDictionary();
+    }
 }
 
 bool enable_spellcheck_add_to_dictionary(const LLUICtrl* ctrl)
 {
-	const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
-	const LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<const LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
-	return (spellcheck_handler) && (spellcheck_handler->canAddToDictionary());
+    const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
+    const LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<const LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
+    return (spellcheck_handler) && (spellcheck_handler->canAddToDictionary());
 }
 
 void handle_spellcheck_add_to_ignore(const LLUICtrl* ctrl)
 {
-	const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
-	LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
-	if ( (spellcheck_handler) && (spellcheck_handler->canAddToIgnore()) )
-	{
-		spellcheck_handler->addToIgnore();
-	}
+    const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
+    LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
+    if ( (spellcheck_handler) && (spellcheck_handler->canAddToIgnore()) )
+    {
+        spellcheck_handler->addToIgnore();
+    }
 }
 
 bool enable_spellcheck_add_to_ignore(const LLUICtrl* ctrl)
 {
-	const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
-	const LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<const LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
-	return (spellcheck_handler) && (spellcheck_handler->canAddToIgnore());
+    const LLContextMenu* menu = dynamic_cast<const LLContextMenu*>(ctrl->getParent());
+    const LLSpellCheckMenuHandler* spellcheck_handler = (menu) ? dynamic_cast<const LLSpellCheckMenuHandler*>(menu->getSpawningView()) : NULL;
+    return (spellcheck_handler) && (spellcheck_handler->canAddToIgnore());
 }
 
 bool enable_object_return()
 {
-	return (!LLSelectMgr::getInstance()->getSelection()->isEmpty() &&
-		(gAgent.isGodlike() || can_derez(DRD_RETURN_TO_OWNER)));
+    return (!LLSelectMgr::getInstance()->getSelection()->isEmpty() &&
+        (gAgent.isGodlike() || can_derez(DRD_RETURN_TO_OWNER)));
 }
 
 bool enable_object_delete()
 {
-	bool new_value = 
+    bool new_value =
 #ifdef HACKED_GODLIKE_VIEWER
-	TRUE;
+    TRUE;
 #else
 # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-	(LLGridManager::getInstance()->isInSLBeta()
+    (LLGridManager::getInstance()->isInSLBeta()
      && gAgent.isGodlike()) ||
 # endif
-	LLSelectMgr::getInstance()->canDoDelete();
+    LLSelectMgr::getInstance()->canDoDelete();
 #endif
-	return new_value;
+    return new_value;
 }
 
 class LLObjectsReturnPackage
 {
 public:
-	LLObjectsReturnPackage() : mObjectSelection(), mReturnableObjects(), mError(),	mFirstRegion(NULL) {};
-	~LLObjectsReturnPackage()
-	{
-		mObjectSelection.clear();
-		mReturnableObjects.clear();
-		mError.clear();
-		mFirstRegion = NULL;
-	};
+    LLObjectsReturnPackage() : mObjectSelection(), mReturnableObjects(), mError(),  mFirstRegion(NULL) {};
+    ~LLObjectsReturnPackage()
+    {
+        mObjectSelection.clear();
+        mReturnableObjects.clear();
+        mError.clear();
+        mFirstRegion = NULL;
+    };
 
-	LLObjectSelectionHandle mObjectSelection;
-	std::vector<LLViewerObjectPtr> mReturnableObjects;
-	std::string mError;
-	LLViewerRegion *mFirstRegion;
+    LLObjectSelectionHandle mObjectSelection;
+    std::vector<LLViewerObjectPtr> mReturnableObjects;
+    std::string mError;
+    LLViewerRegion *mFirstRegion;
 };
 
 static void return_objects(LLObjectsReturnPackage *objectsReturnPackage, const LLSD& notification, const LLSD& response)
 {
-	if (LLNotificationsUtil::getSelectedOption(notification, response) == 0)
-	{
-		// Ignore category ID for this derez destination.
-		derez_objects(DRD_RETURN_TO_OWNER, LLUUID::null, objectsReturnPackage->mFirstRegion, objectsReturnPackage->mError, &objectsReturnPackage->mReturnableObjects);
-	}
+    if (LLNotificationsUtil::getSelectedOption(notification, response) == 0)
+    {
+        // Ignore category ID for this derez destination.
+        derez_objects(DRD_RETURN_TO_OWNER, LLUUID::null, objectsReturnPackage->mFirstRegion, objectsReturnPackage->mError, &objectsReturnPackage->mReturnableObjects);
+    }
 
-	delete objectsReturnPackage;
+    delete objectsReturnPackage;
 }
 
 void handle_object_return()
 {
-	if (!LLSelectMgr::getInstance()->getSelection()->isEmpty())
-	{
-		LLObjectsReturnPackage *objectsReturnPackage = new LLObjectsReturnPackage();
-		objectsReturnPackage->mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
+    if (!LLSelectMgr::getInstance()->getSelection()->isEmpty())
+    {
+        LLObjectsReturnPackage *objectsReturnPackage = new LLObjectsReturnPackage();
+        objectsReturnPackage->mObjectSelection = LLSelectMgr::getInstance()->getEditSelection();
 
-		// Save selected objects, so that we still know what to return after the confirmation dialog resets selection.
-		get_derezzable_objects(DRD_RETURN_TO_OWNER, objectsReturnPackage->mError, objectsReturnPackage->mFirstRegion, &objectsReturnPackage->mReturnableObjects);
+        // Save selected objects, so that we still know what to return after the confirmation dialog resets selection.
+        get_derezzable_objects(DRD_RETURN_TO_OWNER, objectsReturnPackage->mError, objectsReturnPackage->mFirstRegion, &objectsReturnPackage->mReturnableObjects);
 
-		LLNotificationsUtil::add("ReturnToOwner", LLSD(), LLSD(), boost::bind(&return_objects, objectsReturnPackage, _1, _2));
-	}
+        LLNotificationsUtil::add("ReturnToOwner", LLSD(), LLSD(), boost::bind(&return_objects, objectsReturnPackage, _1, _2));
+    }
 }
 
 void handle_object_delete()
 {
 
-		if (LLSelectMgr::getInstance())
-		{
-			LLSelectMgr::getInstance()->doDelete();
-		}
+        if (LLSelectMgr::getInstance())
+        {
+            LLSelectMgr::getInstance()->doDelete();
+        }
 
-		// and close any pie/context menus when done
-		gMenuHolder->hideMenus();
+        // and close any pie/context menus when done
+        gMenuHolder->hideMenus();
 
-		// When deleting an object we may not actually be done
-		// Keep selection so we know what to delete when confirmation is needed about the delete
-		gMenuObject->hide();
-		return;
+        // When deleting an object we may not actually be done
+        // Keep selection so we know what to delete when confirmation is needed about the delete
+        gMenuObject->hide();
+        return;
 }
 
 void handle_force_delete(void*)
 {
-	LLSelectMgr::getInstance()->selectForceDelete();
+    LLSelectMgr::getInstance()->selectForceDelete();
 }
 
 // [SL:KB] - Patch: World-Derender | Checked: 2012-06-08 (Catznip-3.3)
 void handle_view_blocked(const LLSD& sdParam)
 {
-	if (LLVOAvatar* pAvatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject()))
-	{
-		std::string strParam = sdParam.asString();
-		if (BLOCKED_TAB_NAME == strParam)
-			strParam = BLOCKED_PARAM_NAME;
-		else if (DERENDER_TAB_NAME == strParam)
-			strParam = DERENDER_PARAM_NAME;
-		else if (EXCEPTION_TAB_NAME == strParam)
-			strParam = EXCEPTION_PARAM_NAME;
-
-		LLFloaterReg::showInstance("blocked", LLSD().with(strParam, pAvatar->getID()));
-	}
-	else
-	{
-		LLFloaterReg::showInstance("blocked", sdParam);
-	}
+    if (LLVOAvatar* pAvatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject()))
+    {
+        std::string strParam = sdParam.asString();
+        if (BLOCKED_TAB_NAME == strParam)
+            strParam = BLOCKED_PARAM_NAME;
+        else if (DERENDER_TAB_NAME == strParam)
+            strParam = DERENDER_PARAM_NAME;
+        else if (EXCEPTION_TAB_NAME == strParam)
+            strParam = EXCEPTION_PARAM_NAME;
+
+        LLFloaterReg::showInstance("blocked", LLSD().with(strParam, pAvatar->getID()));
+    }
+    else
+    {
+        LLFloaterReg::showInstance("blocked", sdParam);
+    }
 }
 
 void handle_object_derender(const LLSD& sdParam)
 {
-	std::vector<LLUUID> idList;
-	if (LLDerenderList::instance().addSelection("persistent" == sdParam.asString(), &idList))
-	{
-		LLFloaterReg::showInstance("blocked", LLSD().with("derender_to_select", idList.front()));
-	}
+    std::vector<LLUUID> idList;
+    if (LLDerenderList::instance().addSelection("persistent" == sdParam.asString(), &idList))
+    {
+        LLFloaterReg::showInstance("blocked", LLSD().with("derender_to_select", idList.front()));
+    }
 }
 
 bool enable_object_derender()
 {
-	return LLDerenderList::canAddSelection();
+    return LLDerenderList::canAddSelection();
 }
 // [/SL:KB]
 
 class LLViewEnableJoystickFlycam : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = (gSavedSettings.getBOOL("JoystickEnabled") && gSavedSettings.getBOOL("JoystickFlycamEnabled"));
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = (gSavedSettings.getBOOL("JoystickEnabled") && gSavedSettings.getBOOL("JoystickFlycamEnabled"));
+        return new_value;
+    }
 };
 
 class LLViewEnableLastChatter : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		// *TODO: add check that last chatter is in range
-		bool new_value = (gAgentCamera.cameraThirdPerson() && gAgent.getLastChatter().notNull());
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        // *TODO: add check that last chatter is in range
+        bool new_value = (gAgentCamera.cameraThirdPerson() && gAgent.getLastChatter().notNull());
+        return new_value;
+    }
 };
 
 class LLEditEnableDeselect : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canDeselect();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canDeselect();
+        return new_value;
+    }
 };
 
 class LLEditDeselect : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if( LLEditMenuHandler::gEditMenuHandler )
-		{
-			LLEditMenuHandler::gEditMenuHandler->deselect();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if( LLEditMenuHandler::gEditMenuHandler )
+        {
+            LLEditMenuHandler::gEditMenuHandler->deselect();
+        }
+        return true;
+    }
 };
 
 class LLEditEnableSelectAll : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canSelectAll();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canSelectAll();
+        return new_value;
+    }
 };
 
 
 class LLEditSelectAll : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if( LLEditMenuHandler::gEditMenuHandler )
-		{
-			LLEditMenuHandler::gEditMenuHandler->selectAll();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if( LLEditMenuHandler::gEditMenuHandler )
+        {
+            LLEditMenuHandler::gEditMenuHandler->selectAll();
+        }
+        return true;
+    }
 };
 
 
 class LLEditEnableUndo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canUndo();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canUndo();
+        return new_value;
+    }
 };
 
 class LLEditUndo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if( LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canUndo() )
-		{
-			LLEditMenuHandler::gEditMenuHandler->undo();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if( LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canUndo() )
+        {
+            LLEditMenuHandler::gEditMenuHandler->undo();
+        }
+        return true;
+    }
 };
 
 class LLEditEnableRedo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canRedo();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canRedo();
+        return new_value;
+    }
 };
 
 class LLEditRedo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if( LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canRedo() )
-		{
-			LLEditMenuHandler::gEditMenuHandler->redo();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if( LLEditMenuHandler::gEditMenuHandler && LLEditMenuHandler::gEditMenuHandler->canRedo() )
+        {
+            LLEditMenuHandler::gEditMenuHandler->redo();
+        }
+        return true;
+    }
 };
 
 
 
 void print_object_info(void*)
 {
-	LLSelectMgr::getInstance()->selectionDump();
+    LLSelectMgr::getInstance()->selectionDump();
 }
 
 void print_agent_nvpairs(void*)
 {
-	LLViewerObject *objectp;
+    LLViewerObject *objectp;
 
-	LL_INFOS() << "Agent Name Value Pairs" << LL_ENDL;
+    LL_INFOS() << "Agent Name Value Pairs" << LL_ENDL;
 
-	objectp = gObjectList.findObject(gAgentID);
-	if (objectp)
-	{
-		objectp->printNameValuePairs();
-	}
-	else
-	{
-		LL_INFOS() << "Can't find agent object" << LL_ENDL;
-	}
+    objectp = gObjectList.findObject(gAgentID);
+    if (objectp)
+    {
+        objectp->printNameValuePairs();
+    }
+    else
+    {
+        LL_INFOS() << "Can't find agent object" << LL_ENDL;
+    }
 
-	LL_INFOS() << "Camera at " << gAgentCamera.getCameraPositionGlobal() << LL_ENDL;
+    LL_INFOS() << "Camera at " << gAgentCamera.getCameraPositionGlobal() << LL_ENDL;
 }
 
 void show_debug_menus()
 {
-	// this might get called at login screen where there is no menu so only toggle it if one exists
-	if ( gMenuBarView )
-	{
-		BOOL debug = gSavedSettings.getBOOL("UseDebugMenus");
-		BOOL qamode = gSavedSettings.getBOOL("QAMode");
+    // this might get called at login screen where there is no menu so only toggle it if one exists
+    if ( gMenuBarView )
+    {
+        BOOL debug = gSavedSettings.getBOOL("UseDebugMenus");
+        BOOL qamode = gSavedSettings.getBOOL("QAMode");
 
-		gMenuBarView->setItemVisible("Advanced", debug);
-// 		gMenuBarView->setItemEnabled("Advanced", debug); // Don't disable Advanced keyboard shortcuts when hidden
+        gMenuBarView->setItemVisible("Advanced", debug);
+//      gMenuBarView->setItemEnabled("Advanced", debug); // Don't disable Advanced keyboard shortcuts when hidden
 
 // [RLVa:KB] - Checked: 2011-08-16 (RLVa-1.4.0b) | Modified: RLVa-1.4.0b
-		// NOTE: this is supposed to execute whether RLVa is enabled or not
-		rlvMenuToggleVisible();
+        // NOTE: this is supposed to execute whether RLVa is enabled or not
+        rlvMenuToggleVisible();
 // [/RLVa:KB]
-		
-		gMenuBarView->setItemVisible("Debug", qamode);
-		gMenuBarView->setItemEnabled("Debug", qamode);
-
-		gMenuBarView->setItemVisible("Develop", qamode);
-		gMenuBarView->setItemEnabled("Develop", qamode);
-
-		// Server ('Admin') menu hidden when not in godmode.
-		const bool show_server_menu = (gAgent.getGodLevel() > GOD_NOT || (debug && gAgent.getAdminOverride()));
-		gMenuBarView->setItemVisible("Admin", show_server_menu);
-		gMenuBarView->setItemEnabled("Admin", show_server_menu);
-	}
-	if (gLoginMenuBarView)
-	{
-		BOOL debug = gSavedSettings.getBOOL("UseDebugMenus");
-		gLoginMenuBarView->setItemVisible("Debug", debug);
-		gLoginMenuBarView->setItemEnabled("Debug", debug);
-	}
+
+        gMenuBarView->setItemVisible("Debug", qamode);
+        gMenuBarView->setItemEnabled("Debug", qamode);
+
+        gMenuBarView->setItemVisible("Develop", qamode);
+        gMenuBarView->setItemEnabled("Develop", qamode);
+
+        // Server ('Admin') menu hidden when not in godmode.
+        const bool show_server_menu = (gAgent.getGodLevel() > GOD_NOT || (debug && gAgent.getAdminOverride()));
+        gMenuBarView->setItemVisible("Admin", show_server_menu);
+        gMenuBarView->setItemEnabled("Admin", show_server_menu);
+    }
+    if (gLoginMenuBarView)
+    {
+        BOOL debug = gSavedSettings.getBOOL("UseDebugMenus");
+        gLoginMenuBarView->setItemVisible("Debug", debug);
+        gLoginMenuBarView->setItemEnabled("Debug", debug);
+    }
 }
 
 void toggle_debug_menus(void*)
 {
-	BOOL visible = ! gSavedSettings.getBOOL("UseDebugMenus");
-	gSavedSettings.setBOOL("UseDebugMenus", visible);
-	show_debug_menus();
+    BOOL visible = ! gSavedSettings.getBOOL("UseDebugMenus");
+    gSavedSettings.setBOOL("UseDebugMenus", visible);
+    show_debug_menus();
 }
 
 
@@ -6383,182 +6383,182 @@ void toggle_debug_menus(void*)
 
 // void handle_export_selected( void * )
 // {
-// 	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-// 	if (selection->isEmpty())
-// 	{
-// 		return;
-// 	}
-// 	LL_INFOS() << "Exporting selected objects:" << LL_ENDL;
-
-// 	gExporterRequestID.generate();
-// 	gExportDirectory = "";
-
-// 	LLMessageSystem* msg = gMessageSystem;
-// 	msg->newMessageFast(_PREHASH_ObjectExportSelected);
-// 	msg->nextBlockFast(_PREHASH_AgentData);
-// 	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-// 	msg->addUUIDFast(_PREHASH_RequestID, gExporterRequestID);
-// 	msg->addS16Fast(_PREHASH_VolumeDetail, 4);
-
-// 	for (LLObjectSelection::root_iterator iter = selection->root_begin();
-// 		 iter != selection->root_end(); iter++)
-// 	{
-// 		LLSelectNode* node = *iter;
-// 		LLViewerObject* object = node->getObject();
-// 		msg->nextBlockFast(_PREHASH_ObjectData);
-// 		msg->addUUIDFast(_PREHASH_ObjectID, object->getID());
-// 		LL_INFOS() << "Object: " << object->getID() << LL_ENDL;
-// 	}
-// 	msg->sendReliable(gAgent.getRegion()->getHost());
-
-// 	gExportDialog = LLUploadDialog::modalUploadDialog("Exporting selected objects...");
+//  LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+//  if (selection->isEmpty())
+//  {
+//      return;
+//  }
+//  LL_INFOS() << "Exporting selected objects:" << LL_ENDL;
+
+//  gExporterRequestID.generate();
+//  gExportDirectory = "";
+
+//  LLMessageSystem* msg = gMessageSystem;
+//  msg->newMessageFast(_PREHASH_ObjectExportSelected);
+//  msg->nextBlockFast(_PREHASH_AgentData);
+//  msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+//  msg->addUUIDFast(_PREHASH_RequestID, gExporterRequestID);
+//  msg->addS16Fast(_PREHASH_VolumeDetail, 4);
+
+//  for (LLObjectSelection::root_iterator iter = selection->root_begin();
+//       iter != selection->root_end(); iter++)
+//  {
+//      LLSelectNode* node = *iter;
+//      LLViewerObject* object = node->getObject();
+//      msg->nextBlockFast(_PREHASH_ObjectData);
+//      msg->addUUIDFast(_PREHASH_ObjectID, object->getID());
+//      LL_INFOS() << "Object: " << object->getID() << LL_ENDL;
+//  }
+//  msg->sendReliable(gAgent.getRegion()->getHost());
+
+//  gExportDialog = LLUploadDialog::modalUploadDialog("Exporting selected objects...");
 // }
 //
 
 class LLCommunicateNearbyChat : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLFloaterIMContainer* im_box = LLFloaterIMContainer::getInstance();
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLFloaterIMContainer* im_box = LLFloaterIMContainer::getInstance();
         LLFloaterIMNearbyChat* floater_nearby = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
-        if (floater_nearby->isInVisibleChain() && !floater_nearby->isTornOff() 
+        if (floater_nearby->isInVisibleChain() && !floater_nearby->isTornOff()
             && im_box->getSelectedSession() == LLUUID() && im_box->getConversationListItemSize() > 1)
-		{
-			im_box->selectNextorPreviousConversation(false);
-		}
-		else
-		{
-			LLFloaterReg::toggleInstanceOrBringToFront("nearby_chat");
-		}
-		return true;
-	}
+        {
+            im_box->selectNextorPreviousConversation(false);
+        }
+        else
+        {
+            LLFloaterReg::toggleInstanceOrBringToFront("nearby_chat");
+        }
+        return true;
+    }
 };
 
 class LLWorldSetHomeLocation : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		// we just send the message and let the server check for failure cases
-		// server will echo back a "Home position set." alert if it succeeds
-		// and the home location screencapture happens when that alert is recieved
-		gAgent.setStartPosition(START_LOCATION_ID_HOME);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        // we just send the message and let the server check for failure cases
+        // server will echo back a "Home position set." alert if it succeeds
+        // and the home location screencapture happens when that alert is recieved
+        gAgent.setStartPosition(START_LOCATION_ID_HOME);
+        return true;
+    }
 };
 
 class LLWorldLindenHome : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string url = LLFloaterLandHoldings::sHasLindenHome ? LLTrans::getString("lindenhomes_my_home_url") : LLTrans::getString("lindenhomes_get_home_url");
-		LLWeb::loadURL(url);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string url = LLFloaterLandHoldings::sHasLindenHome ? LLTrans::getString("lindenhomes_my_home_url") : LLTrans::getString("lindenhomes_get_home_url");
+        LLWeb::loadURL(url);
+        return true;
+    }
 };
 
 class LLWorldTeleportHome : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gAgent.teleportHome();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gAgent.teleportHome();
+        return true;
+    }
 };
 
 class LLWorldAlwaysRun : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		// as well as altering the default walk-vs-run state,
-		// we also change the *current* walk-vs-run state.
-		if (gAgent.getAlwaysRun())
-		{
-			gAgent.clearAlwaysRun();
-//			gAgent.clearRunning();
-			LLNotifications::instance().add("AlwaysRunDisabled" , LLSD(), LLSD());
-		}
-		else
-		{
-			gAgent.setAlwaysRun();
-//			gAgent.setRunning();
-			LLNotifications::instance().add("AlwaysRunEnabled", LLSD(), LLSD());
-		}
-
-		// tell the simulator.
-//		gAgent.sendWalkRun(gAgent.getAlwaysRun());
-
-		// Update Movement Controls according to AlwaysRun mode
-		LLFloaterMove::setAlwaysRunMode(gAgent.getAlwaysRun());
-
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        // as well as altering the default walk-vs-run state,
+        // we also change the *current* walk-vs-run state.
+        if (gAgent.getAlwaysRun())
+        {
+            gAgent.clearAlwaysRun();
+//          gAgent.clearRunning();
+            LLNotifications::instance().add("AlwaysRunDisabled" , LLSD(), LLSD());
+        }
+        else
+        {
+            gAgent.setAlwaysRun();
+//          gAgent.setRunning();
+            LLNotifications::instance().add("AlwaysRunEnabled", LLSD(), LLSD());
+        }
+
+        // tell the simulator.
+//      gAgent.sendWalkRun(gAgent.getAlwaysRun());
+
+        // Update Movement Controls according to AlwaysRun mode
+        LLFloaterMove::setAlwaysRunMode(gAgent.getAlwaysRun());
+
+        return true;
+    }
 };
 
 class LLWorldCheckAlwaysRun : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gAgent.getAlwaysRun();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gAgent.getAlwaysRun();
+        return new_value;
+    }
 };
 
 class LLWorldSetAway : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (gAgent.getAFK())
-		{
-			gAgent.clearAFK();
-		}
-		else
-		{
-			gAgent.setAFK();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (gAgent.getAFK())
+        {
+            gAgent.clearAFK();
+        }
+        else
+        {
+            gAgent.setAFK();
+        }
+        return true;
+    }
 };
 
 class LLWorldSetDoNotDisturb : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (gAgent.isDoNotDisturb())
-		{
-			gAgent.setDoNotDisturb(false);
-		}
-		else
-		{
-			gAgent.setDoNotDisturb(true);
-			LLNotificationsUtil::add("DoNotDisturbModeSet");
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (gAgent.isDoNotDisturb())
+        {
+            gAgent.setDoNotDisturb(false);
+        }
+        else
+        {
+            gAgent.setDoNotDisturb(true);
+            LLNotificationsUtil::add("DoNotDisturbModeSet");
+        }
+        return true;
+    }
 };
 class LLWorldSetRejectTeleportOffers : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (gAgent.isRejectTeleportOffers())
-		{
-			gAgent.setRejectTeleportOffers(false);
-		}
-		else
-		{
-			gAgent.setRejectTeleportOffers(true);
-			LLNotificationsUtil::add("RejectTeleportOffersModeSet");
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (gAgent.isRejectTeleportOffers())
+        {
+            gAgent.setRejectTeleportOffers(false);
+        }
+        else
+        {
+            gAgent.setRejectTeleportOffers(true);
+            LLNotificationsUtil::add("RejectTeleportOffersModeSet");
+        }
+        return true;
+    }
 };
 
 class LLWorldGetRejectTeleportOffers : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gAgent.isRejectTeleportOffers();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gAgent.isRejectTeleportOffers();
+        return new_value;
+    }
 };
 class LLWorldSetRejectFriendshipRequests : public view_listener_t
 {
@@ -6588,157 +6588,157 @@ class LLWorldGetRejectFriendshipRequests : public view_listener_t
 
 class LLWorldCreateLandmark : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.4.5) | Added: RLVa-1.0.0
-		if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC))
-			return true;
+        if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC))
+            return true;
 // [/RLVa:KB]
 
-		LLFloaterReg::showInstance("add_landmark");
+        LLFloaterReg::showInstance("add_landmark");
 
-		return true;
-	}
+        return true;
+    }
 };
 
 class LLWorldPlaceProfile : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 // [RLVa:KB] - Checked: 2012-02-08 (RLVa-1.4.5) | Added: RLVa-1.4.5
-		if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC))
-			return true;
+        if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC))
+            return true;
 // [/RLVa:KB]
 
-		LLFloaterSidePanelContainer::showPanel("places", LLSD().with("type", "agent"));
+        LLFloaterSidePanelContainer::showPanel("places", LLSD().with("type", "agent"));
 
-		return true;
-	}
+        return true;
+    }
 };
 
 // [RLVa:KB] - Checked: 2012-02-08 (RLVa-1.4.5) | Added: RLVa-1.4.5
 bool enable_place_profile()
 {
-	return LLFloaterSidePanelContainer::canShowPanel("places", LLSD().with("type", "agent"));
+    return LLFloaterSidePanelContainer::canShowPanel("places", LLSD().with("type", "agent"));
 }
 // [/RLVa:KB]
 
 void handle_look_at_selection(const LLSD& param)
 {
-	const F32 PADDING_FACTOR = 1.75f;
-	BOOL zoom = (param.asString() == "zoom");
-	if (!LLSelectMgr::getInstance()->getSelection()->isEmpty())
-	{
-		gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
-
-		LLBBox selection_bbox = LLSelectMgr::getInstance()->getBBoxOfSelection();
-		F32 angle_of_view = llmax(0.1f, LLViewerCamera::getInstance()->getAspect() > 1.f ? LLViewerCamera::getInstance()->getView() * LLViewerCamera::getInstance()->getAspect() : LLViewerCamera::getInstance()->getView());
-		F32 distance = selection_bbox.getExtentLocal().magVec() * PADDING_FACTOR / atan(angle_of_view);
-
-		LLVector3 obj_to_cam = LLViewerCamera::getInstance()->getOrigin() - selection_bbox.getCenterAgent();
-		obj_to_cam.normVec();
-
-		LLUUID object_id;
-		if (LLSelectMgr::getInstance()->getSelection()->getPrimaryObject())
-		{
-			object_id = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject()->mID;
-		}
-		if (zoom)
-		{
-			// Make sure we are not increasing the distance between the camera and object
-			LLVector3d orig_distance = gAgentCamera.getCameraPositionGlobal() - LLSelectMgr::getInstance()->getSelectionCenterGlobal();
-			distance = llmin(distance, (F32) orig_distance.length());
-				
-			gAgentCamera.setCameraPosAndFocusGlobal(LLSelectMgr::getInstance()->getSelectionCenterGlobal() + LLVector3d(obj_to_cam * distance), 
-										LLSelectMgr::getInstance()->getSelectionCenterGlobal(), 
-										object_id );
-			
-		}
-		else
-		{
-			gAgentCamera.setFocusGlobal( LLSelectMgr::getInstance()->getSelectionCenterGlobal(), object_id );
-		}	
-	}
+    const F32 PADDING_FACTOR = 1.75f;
+    BOOL zoom = (param.asString() == "zoom");
+    if (!LLSelectMgr::getInstance()->getSelection()->isEmpty())
+    {
+        gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
+
+        LLBBox selection_bbox = LLSelectMgr::getInstance()->getBBoxOfSelection();
+        F32 angle_of_view = llmax(0.1f, LLViewerCamera::getInstance()->getAspect() > 1.f ? LLViewerCamera::getInstance()->getView() * LLViewerCamera::getInstance()->getAspect() : LLViewerCamera::getInstance()->getView());
+        F32 distance = selection_bbox.getExtentLocal().magVec() * PADDING_FACTOR / atan(angle_of_view);
+
+        LLVector3 obj_to_cam = LLViewerCamera::getInstance()->getOrigin() - selection_bbox.getCenterAgent();
+        obj_to_cam.normVec();
+
+        LLUUID object_id;
+        if (LLSelectMgr::getInstance()->getSelection()->getPrimaryObject())
+        {
+            object_id = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject()->mID;
+        }
+        if (zoom)
+        {
+            // Make sure we are not increasing the distance between the camera and object
+            LLVector3d orig_distance = gAgentCamera.getCameraPositionGlobal() - LLSelectMgr::getInstance()->getSelectionCenterGlobal();
+            distance = llmin(distance, (F32) orig_distance.length());
+
+            gAgentCamera.setCameraPosAndFocusGlobal(LLSelectMgr::getInstance()->getSelectionCenterGlobal() + LLVector3d(obj_to_cam * distance),
+                                        LLSelectMgr::getInstance()->getSelectionCenterGlobal(),
+                                        object_id );
+
+        }
+        else
+        {
+            gAgentCamera.setFocusGlobal( LLSelectMgr::getInstance()->getSelectionCenterGlobal(), object_id );
+        }
+    }
 }
 
 void handle_zoom_to_object(LLUUID object_id)
 {
-	LLViewerObject* object = gObjectList.findObject(object_id);
+    LLViewerObject* object = gObjectList.findObject(object_id);
 
-	if (object)
-	{
-		gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
+    if (object)
+    {
+        gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
 
-		LLVector3d object_center_global=object->getPositionGlobal();
+        LLVector3d object_center_global=object->getPositionGlobal();
 
-		LLVector3d focus_z_offset=LLVector3d(0.0f, 0.0f, 0.6f);
+        LLVector3d focus_z_offset=LLVector3d(0.0f, 0.0f, 0.6f);
 
-		LLVector3d eye_offset(2.5f, 0.0f, 1.0f);
-		eye_offset = eye_offset*object->getRotationRegion();
+        LLVector3d eye_offset(2.5f, 0.0f, 1.0f);
+        eye_offset = eye_offset*object->getRotationRegion();
 
-		gAgentCamera.setCameraPosAndFocusGlobal(object_center_global+eye_offset, 
-										object_center_global + focus_z_offset, 
-											object_id );
-	}
+        gAgentCamera.setCameraPosAndFocusGlobal(object_center_global+eye_offset,
+                                        object_center_global + focus_z_offset,
+                                            object_id );
+    }
 }
 
 class LLAvatarInviteToGroup : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
-//		if(avatar)
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
+//      if(avatar)
 // [RLVa:KB] - Checked: RLVa-1.2.0
-		if ( (avatar) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
+        if ( (avatar) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
 // [/RLVa:KB]
-		{
-			LLAvatarActions::inviteToGroup(avatar->getID());
-		}
-		return true;
-	}
+        {
+            LLAvatarActions::inviteToGroup(avatar->getID());
+        }
+        return true;
+    }
 };
 
 class LLAvatarAddFriend : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
-//		if(avatar && !LLAvatarActions::isFriend(avatar->getID()))
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
+//      if(avatar && !LLAvatarActions::isFriend(avatar->getID()))
 // [RLVa:KB] - Checked: RLVa-1.2.0
-		if ( (avatar && !LLAvatarActions::isFriend(avatar->getID())) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
+        if ( (avatar && !LLAvatarActions::isFriend(avatar->getID())) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
 // [/RLVa:KB]
-		{
-			request_friendship(avatar->getID());
-		}
-		return true;
-	}
+        {
+            request_friendship(avatar->getID());
+        }
+        return true;
+    }
 };
 
 
 class LLAvatarToggleMyProfile : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLFloater* instance = LLAvatarActions::findProfileFloater(gAgent.getID());
-		if (LLFloater::isMinimized(instance))
-		{
-			instance->setMinimized(FALSE);
-			instance->setFocus(TRUE);
-		}
-		else if (!LLFloater::isShown(instance))
-		{
-			LLAvatarActions::showProfile(gAgent.getID());
-		}
-		else if (!instance->hasFocus() && !instance->getIsChrome())
-		{
-			instance->setFocus(TRUE);
-		}
-		else
-		{
-			instance->closeFloater();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLFloater* instance = LLAvatarActions::findProfileFloater(gAgent.getID());
+        if (LLFloater::isMinimized(instance))
+        {
+            instance->setMinimized(FALSE);
+            instance->setFocus(TRUE);
+        }
+        else if (!LLFloater::isShown(instance))
+        {
+            LLAvatarActions::showProfile(gAgent.getID());
+        }
+        else if (!instance->hasFocus() && !instance->getIsChrome())
+        {
+            instance->setFocus(TRUE);
+        }
+        else
+        {
+            instance->closeFloater();
+        }
+        return true;
+    }
 };
 
 class LLAvatarTogglePicks : public view_listener_t
@@ -6766,40 +6766,40 @@ class LLAvatarTogglePicks : public view_listener_t
 
 class LLAvatarToggleSearch : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLFloater* instance = LLFloaterReg::findInstance("search");
-		if (LLFloater::isMinimized(instance))
-		{
-			instance->setMinimized(FALSE);
-			instance->setFocus(TRUE);
-		}
-		else if (!LLFloater::isShown(instance))
-		{
-			LLFloaterReg::showInstance("search");
-		}
-		else if (!instance->hasFocus() && !instance->getIsChrome())
-		{
-			instance->setFocus(TRUE);
-		}
-		else
-		{
-			instance->closeFloater();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLFloater* instance = LLFloaterReg::findInstance("search");
+        if (LLFloater::isMinimized(instance))
+        {
+            instance->setMinimized(FALSE);
+            instance->setFocus(TRUE);
+        }
+        else if (!LLFloater::isShown(instance))
+        {
+            LLFloaterReg::showInstance("search");
+        }
+        else if (!instance->hasFocus() && !instance->getIsChrome())
+        {
+            instance->setFocus(TRUE);
+        }
+        else
+        {
+            instance->closeFloater();
+        }
+        return true;
+    }
 };
 
 class LLAvatarResetSkeleton: public view_listener_t
 {
     bool handleEvent(const LLSD& userdata)
     {
-		LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
-		if(avatar)
+        LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
+        if(avatar)
         {
             avatar->resetSkeleton(false);
 // [SL:KB] - Patch: Appearance-RefreshAttachments | Checked: Catznip-5.3
-			avatar->rebuildAttachments();
+            avatar->rebuildAttachments();
 // [/SL:KB]
         }
         return true;
@@ -6822,210 +6822,210 @@ class LLAvatarEnableResetSkeleton: public view_listener_t
 
 class LLAvatarResetSkeletonAndAnimations : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
-		if (avatar)
-		{
-			avatar->resetSkeleton(true);
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
+        if (avatar)
+        {
+            avatar->resetSkeleton(true);
 // [SL:KB] - Patch: Appearance-RefreshAttachments | Checked: Catznip-5.3
-			avatar->rebuildAttachments();
+            avatar->rebuildAttachments();
 // [/SL:KB]
-		}
-		return true;
-	}
+        }
+        return true;
+    }
 };
 
 class LLAvatarResetSelfSkeletonAndAnimations : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
-		if (avatar)
-		{
-			avatar->resetSkeleton(true);
-		}
-		else
-		{
-			gAgentAvatarp->resetSkeleton(true);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
+        if (avatar)
+        {
+            avatar->resetSkeleton(true);
+        }
+        else
+        {
+            gAgentAvatarp->resetSkeleton(true);
+        }
+        return true;
+    }
 };
 
 
 class LLAvatarAddContact : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
-//		if(avatar)
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
+//      if(avatar)
 // [RLVa:KB] - Checked: RLVa-1.2.0
-		if ( (avatar) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
+        if ( (avatar) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
 // [/RLVa:KB]
-		{
-			create_inventory_callingcard(avatar->getID());
-		}
-		return true;
-	}
+        {
+            create_inventory_callingcard(avatar->getID());
+        }
+        return true;
+    }
 };
 
 bool complete_give_money(const LLSD& notification, const LLSD& response, LLObjectSelectionHandle selection)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option == 0)
-	{
-		gAgent.setDoNotDisturb(false);
-	}
-
-	LLViewerObject* objectp = selection->getPrimaryObject();
-
-	// Show avatar's name if paying attachment
-	if (objectp && objectp->isAttachment())
-	{
-		while (objectp && !objectp->isAvatar())
-		{
-			objectp = (LLViewerObject*)objectp->getParent();
-		}
-	}
-
-	if (objectp)
-	{
-		if (objectp->isAvatar())
-		{
-			const bool is_group = false;
-			LLFloaterPayUtil::payDirectly(&give_money,
-									  objectp->getID(),
-									  is_group);
-		}
-		else
-		{
-			LLFloaterPayUtil::payViaObject(&give_money, selection);
-		}
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option == 0)
+    {
+        gAgent.setDoNotDisturb(false);
+    }
+
+    LLViewerObject* objectp = selection->getPrimaryObject();
+
+    // Show avatar's name if paying attachment
+    if (objectp && objectp->isAttachment())
+    {
+        while (objectp && !objectp->isAvatar())
+        {
+            objectp = (LLViewerObject*)objectp->getParent();
+        }
+    }
+
+    if (objectp)
+    {
+        if (objectp->isAvatar())
+        {
+            const bool is_group = false;
+            LLFloaterPayUtil::payDirectly(&give_money,
+                                      objectp->getID(),
+                                      is_group);
+        }
+        else
+        {
+            LLFloaterPayUtil::payViaObject(&give_money, selection);
+        }
+    }
+    return false;
 }
 
 void handle_give_money_dialog()
 {
-	LLNotification::Params params("DoNotDisturbModePay");
-	params.functor.function(boost::bind(complete_give_money, _1, _2, LLSelectMgr::getInstance()->getSelection()));
+    LLNotification::Params params("DoNotDisturbModePay");
+    params.functor.function(boost::bind(complete_give_money, _1, _2, LLSelectMgr::getInstance()->getSelection()));
 
-	if (gAgent.isDoNotDisturb())
-	{
-		// warn users of being in do not disturb mode during a transaction
-		LLNotifications::instance().add(params);
-	}
-	else
-	{
-		LLNotifications::instance().forceResponse(params, 1);
-	}
+    if (gAgent.isDoNotDisturb())
+    {
+        // warn users of being in do not disturb mode during a transaction
+        LLNotifications::instance().add(params);
+    }
+    else
+    {
+        LLNotifications::instance().forceResponse(params, 1);
+    }
 }
 
 bool enable_pay_avatar()
 {
-	LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-	LLVOAvatar* avatar = find_avatar_from_object(obj);
-//	return (avatar != NULL);
+    LLViewerObject* obj = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+    LLVOAvatar* avatar = find_avatar_from_object(obj);
+//  return (avatar != NULL);
 // [RLVa:KB] - @shownames and @pay
-	return (avatar != NULL) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) && (RlvActions::canPayAvatar(avatar->getID()));
+    return (avatar != NULL) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) && (RlvActions::canPayAvatar(avatar->getID()));
 // [/RLVa:KB]
 }
 
 bool enable_pay_object()
 {
-	LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-	if( object )
-	{
-		LLViewerObject *parent = (LLViewerObject *)object->getParent();
-		if((object->flagTakesMoney()) || (parent && parent->flagTakesMoney()))
-		{
+    LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+    if( object )
+    {
+        LLViewerObject *parent = (LLViewerObject *)object->getParent();
+        if((object->flagTakesMoney()) || (parent && parent->flagTakesMoney()))
+        {
 // [RLVa:KB] - @buy
-			return RlvActions::canBuyObject(object->getID());
+            return RlvActions::canBuyObject(object->getID());
 // [/RLVa:KB]
-//			return true;
-		}
-	}
-	return false;
+//          return true;
+        }
+    }
+    return false;
 }
 
 bool enable_object_stand_up()
 {
-	// 'Object Stand Up' menu item is enabled when agent is sitting on selection
-//	return sitting_on_selection();
+    // 'Object Stand Up' menu item is enabled when agent is sitting on selection
+//  return sitting_on_selection();
 // [RLVa:KB] - Checked: 2010-07-24 (RLVa-1.2.0g) | Added: RLVa-1.2.0g
-	return sitting_on_selection() && ( (!rlv_handler_t::isEnabled()) || (RlvActions::canStand()) );
+    return sitting_on_selection() && ( (!rlv_handler_t::isEnabled()) || (RlvActions::canStand()) );
 // [/RLVa:KB]
 }
 
 bool enable_object_sit(LLUICtrl* ctrl)
 {
-	// 'Object Sit' menu item is enabled when agent is not sitting on selection
-	bool sitting_on_sel = sitting_on_selection();
-	if (!sitting_on_sel)
-	{
-		// init default labels
-		init_default_item_label(ctrl);
-
-		// Update label
-		LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
-		if (node && node->mValid && !node->mSitName.empty())
-		{
-			ctrl->setValue(node->mSitName);
-		}
-		else
-		{
-			ctrl->setValue(get_default_item_label(ctrl->getName()));
-		}
-	}
+    // 'Object Sit' menu item is enabled when agent is not sitting on selection
+    bool sitting_on_sel = sitting_on_selection();
+    if (!sitting_on_sel)
+    {
+        // init default labels
+        init_default_item_label(ctrl);
+
+        // Update label
+        LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
+        if (node && node->mValid && !node->mSitName.empty())
+        {
+            ctrl->setValue(node->mSitName);
+        }
+        else
+        {
+            ctrl->setValue(get_default_item_label(ctrl->getName()));
+        }
+    }
 
 // [RLVa:KB] - Checked: 2010-04-01 (RLVa-1.2.0c) | Modified: RLVa-1.2.0c
-		// RELEASE-RLVA: [SL-2.2.0] Make this match what happens in handle_object_sit_or_stand()
-		if (rlv_handler_t::isEnabled())
-		{
-			const LLPickInfo& pick = LLToolPie::getInstance()->getPick();
-			if (pick.mObjectID.notNull())
-				sitting_on_sel = !RlvActions::canSit(pick.getObject(), pick.mObjectOffset);
-		}
+        // RELEASE-RLVA: [SL-2.2.0] Make this match what happens in handle_object_sit_or_stand()
+        if (rlv_handler_t::isEnabled())
+        {
+            const LLPickInfo& pick = LLToolPie::getInstance()->getPick();
+            if (pick.mObjectID.notNull())
+                sitting_on_sel = !RlvActions::canSit(pick.getObject(), pick.mObjectOffset);
+        }
 // [/RLVa:KB]
 
-	return !sitting_on_sel && is_object_sittable();
+    return !sitting_on_sel && is_object_sittable();
 }
 
 void dump_select_mgr(void*)
 {
-	LLSelectMgr::getInstance()->dump();
+    LLSelectMgr::getInstance()->dump();
 }
 
 void dump_inventory(void*)
 {
-	gInventory.dumpInventory();
+    gInventory.dumpInventory();
 }
 
 
 void handle_dump_followcam(void*)
 {
-	LLFollowCamMgr::getInstance()->dump();
+    LLFollowCamMgr::getInstance()->dump();
 }
 
 void handle_viewer_enable_message_log(void*)
 {
-	gMessageSystem->startLogging();
+    gMessageSystem->startLogging();
 }
 
 void handle_viewer_disable_message_log(void*)
 {
-	gMessageSystem->stopLogging();
+    gMessageSystem->stopLogging();
 }
 
 void handle_customize_avatar()
 {
-	LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "my_outfits"));
+    LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "my_outfits"));
 }
 
 void handle_edit_outfit()
 {
-	LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "edit_outfit"));
+    LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "edit_outfit"));
 }
 
 void handle_now_wearing()
@@ -7042,228 +7042,228 @@ void handle_now_wearing()
 
 void handle_edit_shape()
 {
-	LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "edit_shape"));
+    LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "edit_shape"));
 }
 
 void handle_hover_height()
 {
-	LLFloaterReg::showInstance("edit_hover_height");
+    LLFloaterReg::showInstance("edit_hover_height");
 }
 
 void handle_edit_physics()
 {
-	LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "edit_physics"));
+    LLFloaterSidePanelContainer::showPanel("appearance", LLSD().with("type", "edit_physics"));
 }
 
 void handle_report_abuse()
 {
-	// Prevent menu from appearing in screen shot.
-	gMenuHolder->hideMenus();
-	LLFloaterReporter::showFromMenu(COMPLAINT_REPORT);
+    // Prevent menu from appearing in screen shot.
+    gMenuHolder->hideMenus();
+    LLFloaterReporter::showFromMenu(COMPLAINT_REPORT);
 }
 
 void handle_buy_currency()
 {
-	LLBuyCurrencyHTML::openCurrencyFloater();
+    LLBuyCurrencyHTML::openCurrencyFloater();
 }
 
 class LLFloaterVisible : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string floater_name = userdata.asString();
-		bool new_value = false;
-		{
-			new_value = LLFloaterReg::instanceVisible(floater_name);
-		}
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string floater_name = userdata.asString();
+        bool new_value = false;
+        {
+            new_value = LLFloaterReg::instanceVisible(floater_name);
+        }
+        return new_value;
+    }
 };
 
 class LLShowHelp : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string help_topic = userdata.asString();
-		LLViewerHelp* vhelp = LLViewerHelp::getInstance();
-		vhelp->showTopic(help_topic);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string help_topic = userdata.asString();
+        LLViewerHelp* vhelp = LLViewerHelp::getInstance();
+        vhelp->showTopic(help_topic);
+        return true;
+    }
 };
 
 class LLToggleHelp : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLFloater* help_browser = (LLFloaterReg::findInstance("help_browser"));
-		if (help_browser && help_browser->isInVisibleChain())
-		{
-			help_browser->closeFloater();
-		}
-		else
-		{
-			std::string help_topic = userdata.asString();
-			LLViewerHelp* vhelp = LLViewerHelp::getInstance();
-			vhelp->showTopic(help_topic);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLFloater* help_browser = (LLFloaterReg::findInstance("help_browser"));
+        if (help_browser && help_browser->isInVisibleChain())
+        {
+            help_browser->closeFloater();
+        }
+        else
+        {
+            std::string help_topic = userdata.asString();
+            LLViewerHelp* vhelp = LLViewerHelp::getInstance();
+            vhelp->showTopic(help_topic);
+        }
+        return true;
+    }
 };
 
 class LLToggleSpeak : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVoiceClient::getInstance()->toggleUserPTTState();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVoiceClient::getInstance()->toggleUserPTTState();
+        return true;
+    }
 };
 class LLShowSidetrayPanel : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string floater_name = userdata.asString();
-
-		LLPanel* panel = LLFloaterSidePanelContainer::getPanel(floater_name);
-		if (panel)
-		{
-			if (panel->isInVisibleChain())
-			{
-				LLFloaterReg::getInstance(floater_name)->closeFloater();
-			}
-			else
-			{
-				LLFloaterReg::getInstance(floater_name)->openFloater();
-			}
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string floater_name = userdata.asString();
+
+        LLPanel* panel = LLFloaterSidePanelContainer::getPanel(floater_name);
+        if (panel)
+        {
+            if (panel->isInVisibleChain())
+            {
+                LLFloaterReg::getInstance(floater_name)->closeFloater();
+            }
+            else
+            {
+                LLFloaterReg::getInstance(floater_name)->openFloater();
+            }
+        }
+        return true;
+    }
 };
 
 class LLSidetrayPanelVisible : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string floater_name = userdata.asString();
-		// Toggle the panel
-		if (LLFloaterReg::getInstance(floater_name)->isInVisibleChain())
-		{
-			return true;
-		}
-		else
-		{
-			return false;
-		}
-		
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string floater_name = userdata.asString();
+        // Toggle the panel
+        if (LLFloaterReg::getInstance(floater_name)->isInVisibleChain())
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
+
+    }
 };
 
 
 bool callback_show_url(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (0 == option)
-	{
-		LLWeb::loadURL(notification["payload"]["url"].asString());
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (0 == option)
+    {
+        LLWeb::loadURL(notification["payload"]["url"].asString());
+    }
+    return false;
 }
 
 class LLPromptShowURL : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string param = userdata.asString();
-		std::string::size_type offset = param.find(",");
-		if (offset != param.npos)
-		{
-			std::string alert = param.substr(0, offset);
-			std::string url = param.substr(offset+1);
-
-			if (LLWeb::useExternalBrowser(url))
-			{ 
-    			LLSD payload;
-    			payload["url"] = url;
-    			LLNotificationsUtil::add(alert, LLSD(), payload, callback_show_url);
-			}
-			else
-			{
-		        LLWeb::loadURL(url);
-			}
-		}
-		else
-		{
-			LL_INFOS() << "PromptShowURL invalid parameters! Expecting \"ALERT,URL\"." << LL_ENDL;
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string param = userdata.asString();
+        std::string::size_type offset = param.find(",");
+        if (offset != param.npos)
+        {
+            std::string alert = param.substr(0, offset);
+            std::string url = param.substr(offset+1);
+
+            if (LLWeb::useExternalBrowser(url))
+            {
+                LLSD payload;
+                payload["url"] = url;
+                LLNotificationsUtil::add(alert, LLSD(), payload, callback_show_url);
+            }
+            else
+            {
+                LLWeb::loadURL(url);
+            }
+        }
+        else
+        {
+            LL_INFOS() << "PromptShowURL invalid parameters! Expecting \"ALERT,URL\"." << LL_ENDL;
+        }
+        return true;
+    }
 };
 
 bool callback_show_file(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (0 == option)
-	{
-		LLWeb::loadURL(notification["payload"]["url"]);
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (0 == option)
+    {
+        LLWeb::loadURL(notification["payload"]["url"]);
+    }
+    return false;
 }
 
 class LLPromptShowFile : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string param = userdata.asString();
-		std::string::size_type offset = param.find(",");
-		if (offset != param.npos)
-		{
-			std::string alert = param.substr(0, offset);
-			std::string file = param.substr(offset+1);
-
-			LLSD payload;
-			payload["url"] = file;
-			LLNotificationsUtil::add(alert, LLSD(), payload, callback_show_file);
-		}
-		else
-		{
-			LL_INFOS() << "PromptShowFile invalid parameters! Expecting \"ALERT,FILE\"." << LL_ENDL;
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string param = userdata.asString();
+        std::string::size_type offset = param.find(",");
+        if (offset != param.npos)
+        {
+            std::string alert = param.substr(0, offset);
+            std::string file = param.substr(offset+1);
+
+            LLSD payload;
+            payload["url"] = file;
+            LLNotificationsUtil::add(alert, LLSD(), payload, callback_show_file);
+        }
+        else
+        {
+            LL_INFOS() << "PromptShowFile invalid parameters! Expecting \"ALERT,FILE\"." << LL_ENDL;
+        }
+        return true;
+    }
 };
 
 class LLShowAgentProfile : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLUUID agent_id;
-		if (userdata.asString() == "agent")
-		{
-			agent_id = gAgent.getID();
-		}
-		else if (userdata.asString() == "hit object")
-		{
-			LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-			if (objectp)
-			{
-				agent_id = objectp->getID();
-			}
-		}
-		else
-		{
-			agent_id = userdata.asUUID();
-		}
-
-		LLVOAvatar* avatar = find_avatar_from_object(agent_id);
-//		if (avatar)
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLUUID agent_id;
+        if (userdata.asString() == "agent")
+        {
+            agent_id = gAgent.getID();
+        }
+        else if (userdata.asString() == "hit object")
+        {
+            LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+            if (objectp)
+            {
+                agent_id = objectp->getID();
+            }
+        }
+        else
+        {
+            agent_id = userdata.asUUID();
+        }
+
+        LLVOAvatar* avatar = find_avatar_from_object(agent_id);
+//      if (avatar)
 // [RLVa:KB] - Checked: RLVa-1.2.0
-		if ( (avatar) && ((RlvActions::canShowName(RlvActions::SNC_DEFAULT, agent_id)) || (gAgent.getID() == agent_id)) )
+        if ( (avatar) && ((RlvActions::canShowName(RlvActions::SNC_DEFAULT, agent_id)) || (gAgent.getID() == agent_id)) )
 // [/RLVa:KB]
-		{
-			LLAvatarActions::showProfile(avatar->getID());
-		}
-		return true;
-	}
+        {
+            LLAvatarActions::showProfile(avatar->getID());
+        }
+        return true;
+    }
 };
 
 class LLShowAgentProfilePicks : public view_listener_t
@@ -7277,178 +7277,178 @@ class LLShowAgentProfilePicks : public view_listener_t
 
 class LLToggleAgentProfile : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLUUID agent_id;
-		if (userdata.asString() == "agent")
-		{
-			agent_id = gAgent.getID();
-		}
-		else if (userdata.asString() == "hit object")
-		{
-			LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-			if (objectp)
-			{
-				agent_id = objectp->getID();
-			}
-		}
-		else
-		{
-			agent_id = userdata.asUUID();
-		}
-
-		LLVOAvatar* avatar = find_avatar_from_object(agent_id);
-		if (avatar)
-		{
-			if (!LLAvatarActions::profileVisible(avatar->getID()))
-			{
-				LLAvatarActions::showProfile(avatar->getID());
-			}
-			else
-			{
-				LLAvatarActions::hideProfile(avatar->getID());
-			}
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLUUID agent_id;
+        if (userdata.asString() == "agent")
+        {
+            agent_id = gAgent.getID();
+        }
+        else if (userdata.asString() == "hit object")
+        {
+            LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+            if (objectp)
+            {
+                agent_id = objectp->getID();
+            }
+        }
+        else
+        {
+            agent_id = userdata.asUUID();
+        }
+
+        LLVOAvatar* avatar = find_avatar_from_object(agent_id);
+        if (avatar)
+        {
+            if (!LLAvatarActions::profileVisible(avatar->getID()))
+            {
+                LLAvatarActions::showProfile(avatar->getID());
+            }
+            else
+            {
+                LLAvatarActions::hideProfile(avatar->getID());
+            }
+        }
+        return true;
+    }
 };
 
 class LLLandEdit : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		if (gAgentCamera.getFocusOnAvatar() && gSavedSettings.getBOOL("EditCameraMovement") )
-		{
-			// zoom in if we're looking at the avatar
-			gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
-			gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
+    bool handleEvent(const LLSD& userdata)
+    {
+        if (gAgentCamera.getFocusOnAvatar() && gSavedSettings.getBOOL("EditCameraMovement") )
+        {
+            // zoom in if we're looking at the avatar
+            gAgentCamera.setFocusOnAvatar(FALSE, ANIMATE);
+            gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
 
-			gAgentCamera.cameraOrbitOver( F_PI * 0.25f );
-			gViewerWindow->moveCursorToCenter();
-		}
-		else if ( gSavedSettings.getBOOL("EditCameraMovement") )
-		{
-			gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
-			gViewerWindow->moveCursorToCenter();
-		}
+            gAgentCamera.cameraOrbitOver( F_PI * 0.25f );
+            gViewerWindow->moveCursorToCenter();
+        }
+        else if ( gSavedSettings.getBOOL("EditCameraMovement") )
+        {
+            gAgentCamera.setFocusGlobal(LLToolPie::getInstance()->getPick());
+            gViewerWindow->moveCursorToCenter();
+        }
 
 
-		LLViewerParcelMgr::getInstance()->selectParcelAt( LLToolPie::getInstance()->getPick().mPosGlobal );
+        LLViewerParcelMgr::getInstance()->selectParcelAt( LLToolPie::getInstance()->getPick().mPosGlobal );
 
-		LLFloaterReg::showInstance("build");
+        LLFloaterReg::showInstance("build");
 
-		// Switch to land edit toolset
-		LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolSelectLand::getInstance() );
-		return true;
-	}
+        // Switch to land edit toolset
+        LLToolMgr::getInstance()->getCurrentToolset()->selectTool( LLToolSelectLand::getInstance() );
+        return true;
+    }
 };
 
 class LLMuteParticle : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLUUID id = LLToolPie::getInstance()->getPick().mParticleOwnerID;
-		
-		if (id.notNull())
-		{
-			LLAvatarName av_name;
-			LLAvatarNameCache::get(id, &av_name);
-
-			LLMute mute(id, av_name.getUserName(), LLMute::AGENT);
-			if (LLMuteList::getInstance()->isMuted(mute.mID))
-			{
-				LLMuteList::getInstance()->remove(mute);
-			}
-			else
-			{
-				LLMuteList::getInstance()->add(mute);
-				LLFloaterBlocked::showMuteAndSelect(mute.mID);
-				//LLPanelBlockedList::showPanelAndSelect(mute.mID);
-			}
-		}
-
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLUUID id = LLToolPie::getInstance()->getPick().mParticleOwnerID;
+
+        if (id.notNull())
+        {
+            LLAvatarName av_name;
+            LLAvatarNameCache::get(id, &av_name);
+
+            LLMute mute(id, av_name.getUserName(), LLMute::AGENT);
+            if (LLMuteList::getInstance()->isMuted(mute.mID))
+            {
+                LLMuteList::getInstance()->remove(mute);
+            }
+            else
+            {
+                LLMuteList::getInstance()->add(mute);
+                LLFloaterBlocked::showMuteAndSelect(mute.mID);
+                //LLPanelBlockedList::showPanelAndSelect(mute.mID);
+            }
+        }
+
+        return true;
+    }
 };
 
 class LLWorldEnableBuyLand : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLViewerParcelMgr::getInstance()->canAgentBuyParcel(
-								LLViewerParcelMgr::getInstance()->selectionEmpty()
-									? LLViewerParcelMgr::getInstance()->getAgentParcel()
-									: LLViewerParcelMgr::getInstance()->getParcelSelection()->getParcel(),
-								false);
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLViewerParcelMgr::getInstance()->canAgentBuyParcel(
+                                LLViewerParcelMgr::getInstance()->selectionEmpty()
+                                    ? LLViewerParcelMgr::getInstance()->getAgentParcel()
+                                    : LLViewerParcelMgr::getInstance()->getParcelSelection()->getParcel(),
+                                false);
+        return new_value;
+    }
 };
 
 BOOL enable_buy_land(void*)
 {
-	return LLViewerParcelMgr::getInstance()->canAgentBuyParcel(
-				LLViewerParcelMgr::getInstance()->getParcelSelection()->getParcel(), false);
+    return LLViewerParcelMgr::getInstance()->canAgentBuyParcel(
+                LLViewerParcelMgr::getInstance()->getParcelSelection()->getParcel(), false);
 }
 
 void handle_buy_land()
 {
-	LLViewerParcelMgr* vpm = LLViewerParcelMgr::getInstance();
-	if (vpm->selectionEmpty())
-	{
-		vpm->selectParcelAt(gAgent.getPositionGlobal());
-	}
-	vpm->startBuyLand();
+    LLViewerParcelMgr* vpm = LLViewerParcelMgr::getInstance();
+    if (vpm->selectionEmpty())
+    {
+        vpm->selectParcelAt(gAgent.getPositionGlobal());
+    }
+    vpm->startBuyLand();
 }
 
 class LLObjectAttachToAvatar : public view_listener_t
 {
 public:
-	LLObjectAttachToAvatar(bool replace) : mReplace(replace) {}
-	static void setObjectSelection(LLObjectSelectionHandle selection) { sObjectSelection = selection; }
+    LLObjectAttachToAvatar(bool replace) : mReplace(replace) {}
+    static void setObjectSelection(LLObjectSelectionHandle selection) { sObjectSelection = selection; }
 
 private:
-	bool handleEvent(const LLSD& userdata)
-	{
-		setObjectSelection(LLSelectMgr::getInstance()->getSelection());
-		LLViewerObject* selectedObject = sObjectSelection->getFirstRootObject();
-		if (selectedObject)
-		{
-			S32 index = userdata.asInteger();
-			LLViewerJointAttachment* attachment_point = NULL;
-			if (index > 0)
-				attachment_point = get_if_there(gAgentAvatarp->mAttachmentPoints, index, (LLViewerJointAttachment*)NULL);
+    bool handleEvent(const LLSD& userdata)
+    {
+        setObjectSelection(LLSelectMgr::getInstance()->getSelection());
+        LLViewerObject* selectedObject = sObjectSelection->getFirstRootObject();
+        if (selectedObject)
+        {
+            S32 index = userdata.asInteger();
+            LLViewerJointAttachment* attachment_point = NULL;
+            if (index > 0)
+                attachment_point = get_if_there(gAgentAvatarp->mAttachmentPoints, index, (LLViewerJointAttachment*)NULL);
 
 // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.2.1f) | Modified: RLVa-1.2.1f
-			// RELEASE-RLVa: [SL-2.2.0] If 'index != 0' then the object will be "add attached" [see LLSelectMgr::sendAttach()]
-			if ( (rlv_handler_t::isEnabled()) &&
-				 ( ((!index) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY))) ||		    // Can't wear on default
-				   ((index) && ((RLV_WEAR_ADD & gRlvAttachmentLocks.canAttach(attachment_point)) == 0)) ||	// or non-attachable attachpt
-				   (gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) ) )											    // Attach on object == "Take"
-			{
-				setObjectSelection(NULL); // Clear the selection or it'll get stuck
-				return true;
-			}
+            // RELEASE-RLVa: [SL-2.2.0] If 'index != 0' then the object will be "add attached" [see LLSelectMgr::sendAttach()]
+            if ( (rlv_handler_t::isEnabled()) &&
+                 ( ((!index) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY))) ||            // Can't wear on default
+                   ((index) && ((RLV_WEAR_ADD & gRlvAttachmentLocks.canAttach(attachment_point)) == 0)) ||  // or non-attachable attachpt
+                   (gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) ) )                                             // Attach on object == "Take"
+            {
+                setObjectSelection(NULL); // Clear the selection or it'll get stuck
+                return true;
+            }
 // [/RLVa:KB]
 
-			confirmReplaceAttachment(0, attachment_point);
-		}
-		return true;
-	}
+            confirmReplaceAttachment(0, attachment_point);
+        }
+        return true;
+    }
 
-	static void onNearAttachObject(BOOL success, void *user_data);
-	void confirmReplaceAttachment(S32 option, LLViewerJointAttachment* attachment_point);
-	class CallbackData : public LLSelectionCallbackData
-	{
-	public:
-		CallbackData(LLViewerJointAttachment* point, bool replace) : LLSelectionCallbackData(), mAttachmentPoint(point), mReplace(replace) {}
+    static void onNearAttachObject(BOOL success, void *user_data);
+    void confirmReplaceAttachment(S32 option, LLViewerJointAttachment* attachment_point);
+    class CallbackData : public LLSelectionCallbackData
+    {
+    public:
+        CallbackData(LLViewerJointAttachment* point, bool replace) : LLSelectionCallbackData(), mAttachmentPoint(point), mReplace(replace) {}
 
-		LLViewerJointAttachment*	mAttachmentPoint;
-		bool						mReplace;
-	};
+        LLViewerJointAttachment*    mAttachmentPoint;
+        bool                        mReplace;
+    };
 
 protected:
-	static LLObjectSelectionHandle sObjectSelection;
-	bool mReplace;
+    static LLObjectSelectionHandle sObjectSelection;
+    bool mReplace;
 };
 
 LLObjectSelectionHandle LLObjectAttachToAvatar::sObjectSelection;
@@ -7456,243 +7456,243 @@ LLObjectSelectionHandle LLObjectAttachToAvatar::sObjectSelection;
 // static
 void LLObjectAttachToAvatar::onNearAttachObject(BOOL success, void *user_data)
 {
-	if (!user_data) return;
-	CallbackData* cb_data = static_cast<CallbackData*>(user_data);
-
-	if (success)
-	{
-		const LLViewerJointAttachment *attachment = cb_data->mAttachmentPoint;
-		
-		U8 attachment_id = 0;
-		if (attachment)
-		{
-			for (LLVOAvatar::attachment_map_t::const_iterator iter = gAgentAvatarp->mAttachmentPoints.begin();
-				 iter != gAgentAvatarp->mAttachmentPoints.end(); ++iter)
-			{
-				if (iter->second == attachment)
-				{
-					attachment_id = iter->first;
-					break;
-				}
-			}
-		}
-		else
-		{
-			// interpret 0 as "default location"
-			attachment_id = 0;
-		}
-		LLSelectMgr::getInstance()->sendAttach(cb_data->getSelection(), attachment_id, cb_data->mReplace);
-	}
-	LLObjectAttachToAvatar::setObjectSelection(NULL);
-
-	delete cb_data;
+    if (!user_data) return;
+    CallbackData* cb_data = static_cast<CallbackData*>(user_data);
+
+    if (success)
+    {
+        const LLViewerJointAttachment *attachment = cb_data->mAttachmentPoint;
+
+        U8 attachment_id = 0;
+        if (attachment)
+        {
+            for (LLVOAvatar::attachment_map_t::const_iterator iter = gAgentAvatarp->mAttachmentPoints.begin();
+                 iter != gAgentAvatarp->mAttachmentPoints.end(); ++iter)
+            {
+                if (iter->second == attachment)
+                {
+                    attachment_id = iter->first;
+                    break;
+                }
+            }
+        }
+        else
+        {
+            // interpret 0 as "default location"
+            attachment_id = 0;
+        }
+        LLSelectMgr::getInstance()->sendAttach(cb_data->getSelection(), attachment_id, cb_data->mReplace);
+    }
+    LLObjectAttachToAvatar::setObjectSelection(NULL);
+
+    delete cb_data;
 }
 
 // static
 void LLObjectAttachToAvatar::confirmReplaceAttachment(S32 option, LLViewerJointAttachment* attachment_point)
 {
-	if (option == 0/*YES*/)
-	{
-		LLViewerObject* selectedObject = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject();
-		if (selectedObject)
-		{
-			const F32 MIN_STOP_DISTANCE = 1.f;	// meters
-			const F32 ARM_LENGTH = 0.5f;		// meters
-			const F32 SCALE_FUDGE = 1.5f;
-
-			F32 stop_distance = SCALE_FUDGE * selectedObject->getMaxScale() + ARM_LENGTH;
-			if (stop_distance < MIN_STOP_DISTANCE)
-			{
-				stop_distance = MIN_STOP_DISTANCE;
-			}
-
-			LLVector3 walkToSpot = selectedObject->getPositionAgent();
-			
-			// make sure we stop in front of the object
-			LLVector3 delta = walkToSpot - gAgent.getPositionAgent();
-			delta.normVec();
-			delta = delta * 0.5f;
-			walkToSpot -= delta;
-
-			// The callback will be called even if avatar fails to get close enough to the object, so we won't get a memory leak.
-			CallbackData* user_data = new CallbackData(attachment_point, mReplace);
-			gAgent.startAutoPilotGlobal(gAgent.getPosGlobalFromAgent(walkToSpot), "Attach", NULL, onNearAttachObject, user_data, stop_distance);
-			gAgentCamera.clearFocusObject();
-		}
-	}
+    if (option == 0/*YES*/)
+    {
+        LLViewerObject* selectedObject = LLSelectMgr::getInstance()->getSelection()->getFirstRootObject();
+        if (selectedObject)
+        {
+            const F32 MIN_STOP_DISTANCE = 1.f;  // meters
+            const F32 ARM_LENGTH = 0.5f;        // meters
+            const F32 SCALE_FUDGE = 1.5f;
+
+            F32 stop_distance = SCALE_FUDGE * selectedObject->getMaxScale() + ARM_LENGTH;
+            if (stop_distance < MIN_STOP_DISTANCE)
+            {
+                stop_distance = MIN_STOP_DISTANCE;
+            }
+
+            LLVector3 walkToSpot = selectedObject->getPositionAgent();
+
+            // make sure we stop in front of the object
+            LLVector3 delta = walkToSpot - gAgent.getPositionAgent();
+            delta.normVec();
+            delta = delta * 0.5f;
+            walkToSpot -= delta;
+
+            // The callback will be called even if avatar fails to get close enough to the object, so we won't get a memory leak.
+            CallbackData* user_data = new CallbackData(attachment_point, mReplace);
+            gAgent.startAutoPilotGlobal(gAgent.getPosGlobalFromAgent(walkToSpot), "Attach", NULL, onNearAttachObject, user_data, stop_distance);
+            gAgentCamera.clearFocusObject();
+        }
+    }
 }
 
 void callback_attachment_drop(const LLSD& notification, const LLSD& response)
 {
-	// Ensure user confirmed the drop
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0) return;
-
-	// Called when the user clicked on an object attached to them
-	// and selected "Drop".
-	LLUUID object_id = notification["payload"]["object_id"].asUUID();
-	LLViewerObject *object = gObjectList.findObject(object_id);
-	
-	if (!object)
-	{
-		LL_WARNS() << "handle_drop_attachment() - no object to drop" << LL_ENDL;
-		return;
-	}
-
-	LLViewerObject *parent = (LLViewerObject*)object->getParent();
-	while (parent)
-	{
-		if(parent->isAvatar())
-		{
-			break;
-		}
-		object = parent;
-		parent = (LLViewerObject*)parent->getParent();
-	}
-
-	if (!object)
-	{
-		LL_WARNS() << "handle_detach() - no object to detach" << LL_ENDL;
-		return;
-	}
-
-	if (object->isAvatar())
-	{
-		LL_WARNS() << "Trying to detach avatar from avatar." << LL_ENDL;
-		return;
-	}
-	
-	// reselect the object
-	LLSelectMgr::getInstance()->selectObjectAndFamily(object);
-
-	LLSelectMgr::getInstance()->sendDropAttachment();
-
-	return;
+    // Ensure user confirmed the drop
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option != 0) return;
+
+    // Called when the user clicked on an object attached to them
+    // and selected "Drop".
+    LLUUID object_id = notification["payload"]["object_id"].asUUID();
+    LLViewerObject *object = gObjectList.findObject(object_id);
+
+    if (!object)
+    {
+        LL_WARNS() << "handle_drop_attachment() - no object to drop" << LL_ENDL;
+        return;
+    }
+
+    LLViewerObject *parent = (LLViewerObject*)object->getParent();
+    while (parent)
+    {
+        if(parent->isAvatar())
+        {
+            break;
+        }
+        object = parent;
+        parent = (LLViewerObject*)parent->getParent();
+    }
+
+    if (!object)
+    {
+        LL_WARNS() << "handle_detach() - no object to detach" << LL_ENDL;
+        return;
+    }
+
+    if (object->isAvatar())
+    {
+        LL_WARNS() << "Trying to detach avatar from avatar." << LL_ENDL;
+        return;
+    }
+
+    // reselect the object
+    LLSelectMgr::getInstance()->selectObjectAndFamily(object);
+
+    LLSelectMgr::getInstance()->sendDropAttachment();
+
+    return;
 }
 
 class LLAttachmentDrop : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 // [RLVa:KB] - Checked: 2010-03-15 (RLVa-1.2.0e) | Modified: RLVa-1.0.5
-		if (rlv_handler_t::isEnabled())
-		{
-			if (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE))
-			{
-				// NOTE: copy/paste of the code in enable_detach()
-				LLObjectSelectionHandle hSelect = LLSelectMgr::getInstance()->getSelection();
-				RlvSelectHasLockedAttach f;
-				if ( (hSelect->isAttachment()) && (hSelect->getFirstRootNode(&f, FALSE) != NULL) )
-					return true;
-			}
-			if (gRlvHandler.hasBehaviour(RLV_BHVR_REZ))
-			{
-				return true;
-			}
-		}
+        if (rlv_handler_t::isEnabled())
+        {
+            if (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE))
+            {
+                // NOTE: copy/paste of the code in enable_detach()
+                LLObjectSelectionHandle hSelect = LLSelectMgr::getInstance()->getSelection();
+                RlvSelectHasLockedAttach f;
+                if ( (hSelect->isAttachment()) && (hSelect->getFirstRootNode(&f, FALSE) != NULL) )
+                    return true;
+            }
+            if (gRlvHandler.hasBehaviour(RLV_BHVR_REZ))
+            {
+                return true;
+            }
+        }
 // [/RLVa:KB]
 
-		LLSD payload;
-		LLViewerObject *object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+        LLSD payload;
+        LLViewerObject *object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
 
-		if (object) 
-		{
-			payload["object_id"] = object->getID();
-		}
-		else
-		{
-			LL_WARNS() << "Drop object not found" << LL_ENDL;
-			return true;
-		}
+        if (object)
+        {
+            payload["object_id"] = object->getID();
+        }
+        else
+        {
+            LL_WARNS() << "Drop object not found" << LL_ENDL;
+            return true;
+        }
 
-		LLNotificationsUtil::add("AttachmentDrop", LLSD(), payload, &callback_attachment_drop);
-		return true;
-	}
+        LLNotificationsUtil::add("AttachmentDrop", LLSD(), payload, &callback_attachment_drop);
+        return true;
+    }
 };
 
 // called from avatar pie menu
 class LLAttachmentDetachFromPoint : public view_listener_t
 {
-	bool handleEvent(const LLSD& user_data)
-	{
-		uuid_vec_t ids_to_remove;
-		const LLViewerJointAttachment *attachment = get_if_there(gAgentAvatarp->mAttachmentPoints, user_data.asInteger(), (LLViewerJointAttachment*)NULL);
-//		if (attachment->getNumObjects() > 0)
+    bool handleEvent(const LLSD& user_data)
+    {
+        uuid_vec_t ids_to_remove;
+        const LLViewerJointAttachment *attachment = get_if_there(gAgentAvatarp->mAttachmentPoints, user_data.asInteger(), (LLViewerJointAttachment*)NULL);
+//      if (attachment->getNumObjects() > 0)
 // [RLVa:KB] - Checked: 2010-03-04 (RLVa-1.2.0a) | Added: RLVa-1.2.0a
-		if ( (attachment->getNumObjects() > 0) && ((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(attachment))) )
+        if ( (attachment->getNumObjects() > 0) && ((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(attachment))) )
 // [/RLVa:KB]
-		{
+        {
             for (LLViewerObject* attached_object : attachment->mAttachedObjects)
             {
                 // [RLVa:KB] - Checked: 2010-03-04 (RLVa-1.2.0a) | Added: RLVa-1.2.0a
-				if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.isLockedAttachment(attached_object)) )
-					continue;
-				ids_to_remove.push_back(attached_object->getAttachmentItemID());
+                if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.isLockedAttachment(attached_object)) )
+                    continue;
+                ids_to_remove.push_back(attached_object->getAttachmentItemID());
 // [/RLVa:KB]
-			}
+            }
+        }
+        if (!ids_to_remove.empty())
+        {
+            LLAppearanceMgr::instance().removeItemsFromAvatar(ids_to_remove);
         }
-		if (!ids_to_remove.empty())
-		{
-			LLAppearanceMgr::instance().removeItemsFromAvatar(ids_to_remove);
-		}
-		return true;
-	}
+        return true;
+    }
 };
 
 static bool onEnableAttachmentLabel(LLUICtrl* ctrl, const LLSD& data)
 {
 // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.2.1f) | Modified: RLVa-1.2.1f
-	// RELEASE-RLVa: [SL-2.2.0] When attaching to a specific point the object will be "add attached" [see LLSelectMgr::sendAttach()]
-	bool fRlvEnable = true;
+    // RELEASE-RLVa: [SL-2.2.0] When attaching to a specific point the object will be "add attached" [see LLSelectMgr::sendAttach()]
+    bool fRlvEnable = true;
 // [/RLVa:KB]
-	std::string label;
-	LLMenuItemGL* menu = dynamic_cast<LLMenuItemGL*>(ctrl);
-	if (menu)
-	{
-		const LLViewerJointAttachment *attachment = get_if_there(gAgentAvatarp->mAttachmentPoints, data["index"].asInteger(), (LLViewerJointAttachment*)NULL);
-		if (attachment)
-		{
-			label = data["label"].asString();
+    std::string label;
+    LLMenuItemGL* menu = dynamic_cast<LLMenuItemGL*>(ctrl);
+    if (menu)
+    {
+        const LLViewerJointAttachment *attachment = get_if_there(gAgentAvatarp->mAttachmentPoints, data["index"].asInteger(), (LLViewerJointAttachment*)NULL);
+        if (attachment)
+        {
+            label = data["label"].asString();
             for (const LLViewerObject* attached_object : attachment->mAttachedObjects)
             {
-				if (attached_object)
-				{
-					LLViewerInventoryItem* itemp = gInventory.getItem(attached_object->getAttachmentItemID());
-					if (itemp)
-					{
-						label += std::string(" (") + itemp->getName() + std::string(")");
-						break;
-					}
-				}
-			}
-		}
+                if (attached_object)
+                {
+                    LLViewerInventoryItem* itemp = gInventory.getItem(attached_object->getAttachmentItemID());
+                    if (itemp)
+                    {
+                        label += std::string(" (") + itemp->getName() + std::string(")");
+                        break;
+                    }
+                }
+            }
+        }
 
 // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.2.1f) | Modified: RLVa-1.2.1f
-		if (rlv_handler_t::isEnabled())
-			fRlvEnable = (!gRlvAttachmentLocks.isLockedAttachmentPoint(attachment, RLV_LOCK_ADD));
+        if (rlv_handler_t::isEnabled())
+            fRlvEnable = (!gRlvAttachmentLocks.isLockedAttachmentPoint(attachment, RLV_LOCK_ADD));
 // [/RLVa:KB]
 
-		menu->setLabel(label);
-	}
-//	return true;
+        menu->setLabel(label);
+    }
+//  return true;
 // [RLVa:KB] - Checked: 2010-02-27 (RLVa-1.2.0a) | Added: RLVa-1.2.0a
-	return fRlvEnable;
+    return fRlvEnable;
 // [/RLVa:KB]
 }
 
 class LLAttachmentDetach : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		// Called when the user clicked on an object attached to them
-		// and selected "Detach".
+    bool handleEvent(const LLSD& userdata)
+    {
+        // Called when the user clicked on an object attached to them
+        // and selected "Detach".
         LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
         LLViewerObject *object = selection->getPrimaryObject();
-		if (!object)
-		{
-			LL_WARNS() << "handle_detach() - no object to detach" << LL_ENDL;
-			return true;
-		}
+        if (!object)
+        {
+            LL_WARNS() << "handle_detach() - no object to detach" << LL_ENDL;
+            return true;
+        }
 
         struct f: public LLSelectedObjectFunctor
         {
@@ -7711,15 +7711,15 @@ class LLAttachmentDetach : public view_listener_t
                 }
 
                 LLViewerObject* parent = (LLViewerObject*)objectp->getParent();
-		while (parent)
-		{
-			if(parent->isAvatar())
-			{
-				break;
-			}
+        while (parent)
+        {
+            if(parent->isAvatar())
+            {
+                break;
+            }
                     objectp = parent;
-			parent = (LLViewerObject*)parent->getParent();
-		}
+            parent = (LLViewerObject*)parent->getParent();
+        }
 
                 // std::set to avoid dupplicate 'roots' from linksets
                 mRemoveSet.insert(objectp->getAttachmentItemID());
@@ -7734,36 +7734,36 @@ class LLAttachmentDetach : public view_listener_t
         selection->applyToObjects(&func);
 
         if (func.mAvatarsInSelection)
-		{
+        {
             // Not possible under normal circumstances
             // Either avatar selection is ON or has to do with animeshes
             // Better stop this than mess something
             LL_WARNS() << "Trying to detach avatar from avatar." << LL_ENDL;
-			return true;
-		}
+            return true;
+        }
 
         if (func.mRemoveSet.empty())
-		{
+        {
             LL_WARNS() << "handle_detach() - no valid attachments in selection to detach" << LL_ENDL;
-			return true;
-		}
+            return true;
+        }
 
 // [RLVa:KB] - Checked: 2010-03-15 (RLVa-1.2.0a) | Modified: RLVa-1.0.5
-		// NOTE: copy/paste of the code in enable_detach()
-		if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
-		{
-			LLObjectSelectionHandle hSelect = LLSelectMgr::getInstance()->getSelection();
-			RlvSelectHasLockedAttach f;
-			if ( (hSelect->isAttachment()) && (hSelect->getFirstRootNode(&f, FALSE) != NULL) )
-				return true;
-		}
+        // NOTE: copy/paste of the code in enable_detach()
+        if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
+        {
+            LLObjectSelectionHandle hSelect = LLSelectMgr::getInstance()->getSelection();
+            RlvSelectHasLockedAttach f;
+            if ( (hSelect->isAttachment()) && (hSelect->getFirstRootNode(&f, FALSE) != NULL) )
+                return true;
+        }
 // [/RLVa:KB]
 
         uuid_vec_t detach_list(func.mRemoveSet.begin(), func.mRemoveSet.end());
         LLAppearanceMgr::instance().removeItemsFromAvatar(detach_list);
 
-		return true;
-	}
+        return true;
+    }
 };
 
 //Adding an observer for a Jira 2422 and needs to be a fetch observer
@@ -7771,127 +7771,127 @@ class LLAttachmentDetach : public view_listener_t
 class LLWornItemFetchedObserver : public LLInventoryFetchItemsObserver
 {
 public:
-	LLWornItemFetchedObserver(const LLUUID& worn_item_id) :
-		LLInventoryFetchItemsObserver(worn_item_id)
-	{}
-	virtual ~LLWornItemFetchedObserver() {}
+    LLWornItemFetchedObserver(const LLUUID& worn_item_id) :
+        LLInventoryFetchItemsObserver(worn_item_id)
+    {}
+    virtual ~LLWornItemFetchedObserver() {}
 
 protected:
-	virtual void done()
-	{
-		gMenuAttachmentSelf->buildDrawLabels();
-		gInventory.removeObserver(this);
-		delete this;
-	}
+    virtual void done()
+    {
+        gMenuAttachmentSelf->buildDrawLabels();
+        gInventory.removeObserver(this);
+        delete this;
+    }
 };
 
 // You can only drop items on parcels where you can build.
 class LLAttachmentEnableDrop : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		BOOL can_build   = gAgent.isGodlike() || (LLViewerParcelMgr::getInstance()->allowAgentBuild());
+    bool handleEvent(const LLSD& userdata)
+    {
+        BOOL can_build   = gAgent.isGodlike() || (LLViewerParcelMgr::getInstance()->allowAgentBuild());
 
-		//Add an inventory observer to only allow dropping the newly attached item
-		//once it exists in your inventory.  Look at Jira 2422.
-		//-jwolk
+        //Add an inventory observer to only allow dropping the newly attached item
+        //once it exists in your inventory.  Look at Jira 2422.
+        //-jwolk
 
-		// A bug occurs when you wear/drop an item before it actively is added to your inventory
-		// if this is the case (you're on a slow sim, etc.) a copy of the object,
-		// well, a newly created object with the same properties, is placed
-		// in your inventory.  Therefore, we disable the drop option until the
-		// item is in your inventory
+        // A bug occurs when you wear/drop an item before it actively is added to your inventory
+        // if this is the case (you're on a slow sim, etc.) a copy of the object,
+        // well, a newly created object with the same properties, is placed
+        // in your inventory.  Therefore, we disable the drop option until the
+        // item is in your inventory
 
-		LLViewerObject*              object         = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-		LLViewerJointAttachment*     attachment     = NULL;
-		LLInventoryItem*             item           = NULL;
+        LLViewerObject*              object         = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+        LLViewerJointAttachment*     attachment     = NULL;
+        LLInventoryItem*             item           = NULL;
 
-		// Do not enable drop if all faces of object are not enabled
-		if (object && LLSelectMgr::getInstance()->getSelection()->contains(object,SELECT_ALL_TES ))
-		{
-    		S32 attachmentID  = ATTACHMENT_ID_FROM_STATE(object->getAttachmentState());
-			attachment = get_if_there(gAgentAvatarp->mAttachmentPoints, attachmentID, (LLViewerJointAttachment*)NULL);
+        // Do not enable drop if all faces of object are not enabled
+        if (object && LLSelectMgr::getInstance()->getSelection()->contains(object,SELECT_ALL_TES ))
+        {
+            S32 attachmentID  = ATTACHMENT_ID_FROM_STATE(object->getAttachmentState());
+            attachment = get_if_there(gAgentAvatarp->mAttachmentPoints, attachmentID, (LLViewerJointAttachment*)NULL);
 
-			if (attachment)
-			{
+            if (attachment)
+            {
                 for (LLViewerObject* attached_object : attachment->mAttachedObjects)
                 {
-					// make sure item is in your inventory (it could be a delayed attach message being sent from the sim)
-					// so check to see if the item is in the inventory already
+                    // make sure item is in your inventory (it could be a delayed attach message being sent from the sim)
+                    // so check to see if the item is in the inventory already
                     item = gInventory.getItem(attached_object->getAttachmentItemID());
-					if (!item)
-					{
-						// Item does not exist, make an observer to enable the pie menu 
-						// when the item finishes fetching worst case scenario 
-						// if a fetch is already out there (being sent from a slow sim)
-						// we refetch and there are 2 fetches
-						LLWornItemFetchedObserver* worn_item_fetched = new LLWornItemFetchedObserver(attached_object->getAttachmentItemID());		
-						worn_item_fetched->startFetch();
-						gInventory.addObserver(worn_item_fetched);
-					}
-				}
-			}
-		}
-		
-		//now check to make sure that the item is actually in the inventory before we enable dropping it
-//		bool new_value = enable_detach() && can_build && item;
+                    if (!item)
+                    {
+                        // Item does not exist, make an observer to enable the pie menu
+                        // when the item finishes fetching worst case scenario
+                        // if a fetch is already out there (being sent from a slow sim)
+                        // we refetch and there are 2 fetches
+                        LLWornItemFetchedObserver* worn_item_fetched = new LLWornItemFetchedObserver(attached_object->getAttachmentItemID());
+                        worn_item_fetched->startFetch();
+                        gInventory.addObserver(worn_item_fetched);
+                    }
+                }
+            }
+        }
+
+        //now check to make sure that the item is actually in the inventory before we enable dropping it
+//      bool new_value = enable_detach() && can_build && item;
 // [RLVa:KB] - Checked: 2010-03-24 (RLVa-1.0.0b) | Modified: RLVa-1.0.0b
-		bool new_value = enable_detach() && can_build && item && (!gRlvHandler.hasBehaviour(RLV_BHVR_REZ));
+        bool new_value = enable_detach() && can_build && item && (!gRlvHandler.hasBehaviour(RLV_BHVR_REZ));
 // [/RLVa:KB]
 
-		return new_value;
-	}
+        return new_value;
+    }
 };
 
 BOOL enable_detach(const LLSD&)
 {
-	LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-	
-	// Only enable detach if all faces of object are selected
-	if (!object ||
-		!object->isAttachment() ||
-		!LLSelectMgr::getInstance()->getSelection()->contains(object,SELECT_ALL_TES ))
-	{
-		return FALSE;
-	}
-
-	// Find the avatar who owns this attachment
-	LLViewerObject* avatar = object;
-	while (avatar)
-	{
-		// ...if it's you, good to detach
-		if (avatar->getID() == gAgent.getID())
-		{
+    LLViewerObject* object = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+
+    // Only enable detach if all faces of object are selected
+    if (!object ||
+        !object->isAttachment() ||
+        !LLSelectMgr::getInstance()->getSelection()->contains(object,SELECT_ALL_TES ))
+    {
+        return FALSE;
+    }
+
+    // Find the avatar who owns this attachment
+    LLViewerObject* avatar = object;
+    while (avatar)
+    {
+        // ...if it's you, good to detach
+        if (avatar->getID() == gAgent.getID())
+        {
 // [RLVa:KB] - Checked: 2010-03-15 (RLVa-1.2.0a) | Modified: RLVa-1.0.5
-			// NOTE: this code is reused as-is in LLAttachmentDetach::handleEvent() and LLAttachmentDrop::handleEvent()
-			//       so any changes here should be reflected there as well
-
-			// RELEASE-RLVa: [SL-2.2.0] LLSelectMgr::sendDetach() and LLSelectMgr::sendDropAttachment() call sendListToRegions with
-			//                          SEND_ONLY_ROOTS so we only need to examine the roots which saves us time
-			if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
-			{
-				LLObjectSelectionHandle hSelect = LLSelectMgr::getInstance()->getSelection();
-				RlvSelectHasLockedAttach f;
-				if ( (hSelect->isAttachment()) && (hSelect->getFirstRootNode(&f, FALSE) != NULL) )
-					return FALSE;
-			}
+            // NOTE: this code is reused as-is in LLAttachmentDetach::handleEvent() and LLAttachmentDrop::handleEvent()
+            //       so any changes here should be reflected there as well
+
+            // RELEASE-RLVa: [SL-2.2.0] LLSelectMgr::sendDetach() and LLSelectMgr::sendDropAttachment() call sendListToRegions with
+            //                          SEND_ONLY_ROOTS so we only need to examine the roots which saves us time
+            if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
+            {
+                LLObjectSelectionHandle hSelect = LLSelectMgr::getInstance()->getSelection();
+                RlvSelectHasLockedAttach f;
+                if ( (hSelect->isAttachment()) && (hSelect->getFirstRootNode(&f, FALSE) != NULL) )
+                    return FALSE;
+            }
 // [/RLVa:KB]
-			return TRUE;
-		}
+            return TRUE;
+        }
 
-		avatar = (LLViewerObject*)avatar->getParent();
-	}
+        avatar = (LLViewerObject*)avatar->getParent();
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 class LLAttachmentEnableDetach : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = enable_detach();
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = enable_detach();
+        return new_value;
+    }
 };
 
 // Used to tell if the selected object can be attached to your avatar.
@@ -7901,425 +7901,425 @@ BOOL object_selected_and_point_valid(const LLSD& sdParam)
 // [/RLVa:KB]
 {
 // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.2.1f) | Modified: RLVa-1.2.1f
-	if (rlv_handler_t::isEnabled())
-	{
-		if (!isAgentAvatarValid())
-			return FALSE;
-
-		// RELEASE-RLVa: [SL-2.2.0] Look at the caller graph for this function on every new release
-		//   - object_is_wearable() => dead code [sdParam == 0 => default attach point => OK!]
-		//   - enabler set up in LLVOAvatarSelf::buildMenus() => Rezzed prim / Put On / "Attach To" [sdParam == idxAttachPt]
-		//   - "Object.EnableWear" enable => Rezzed prim / Put On / "Wear" or "Add" [sdParam blank]
-		// RELEASE-RLVa: [SL-2.2.0] If 'idxAttachPt != 0' then the object will be "add attached" [see LLSelectMgr::sendAttach()]
-		const LLViewerJointAttachment* pAttachPt = 
-			get_if_there(gAgentAvatarp->mAttachmentPoints, sdParam.asInteger(), (LLViewerJointAttachment*)NULL);
-		if ( ((!pAttachPt) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY))) ||		// Can't wear on default attach point
-			 ((pAttachPt) && ((RLV_WEAR_ADD & gRlvAttachmentLocks.canAttach(pAttachPt)) == 0)) ||	// or non-attachable attach point
-			 (gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) )												// Attach on object == "Take"
-		{
-			return FALSE;
-		}
-	}
+    if (rlv_handler_t::isEnabled())
+    {
+        if (!isAgentAvatarValid())
+            return FALSE;
+
+        // RELEASE-RLVa: [SL-2.2.0] Look at the caller graph for this function on every new release
+        //   - object_is_wearable() => dead code [sdParam == 0 => default attach point => OK!]
+        //   - enabler set up in LLVOAvatarSelf::buildMenus() => Rezzed prim / Put On / "Attach To" [sdParam == idxAttachPt]
+        //   - "Object.EnableWear" enable => Rezzed prim / Put On / "Wear" or "Add" [sdParam blank]
+        // RELEASE-RLVa: [SL-2.2.0] If 'idxAttachPt != 0' then the object will be "add attached" [see LLSelectMgr::sendAttach()]
+        const LLViewerJointAttachment* pAttachPt =
+            get_if_there(gAgentAvatarp->mAttachmentPoints, sdParam.asInteger(), (LLViewerJointAttachment*)NULL);
+        if ( ((!pAttachPt) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY))) ||      // Can't wear on default attach point
+             ((pAttachPt) && ((RLV_WEAR_ADD & gRlvAttachmentLocks.canAttach(pAttachPt)) == 0)) ||   // or non-attachable attach point
+             (gRlvHandler.hasBehaviour(RLV_BHVR_REZ)) )                                             // Attach on object == "Take"
+        {
+            return FALSE;
+        }
+    }
 // [/RLVa:KB]
 
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	for (LLObjectSelection::root_iterator iter = selection->root_begin();
-		 iter != selection->root_end(); iter++)
-	{
-		LLSelectNode* node = *iter;
-		LLViewerObject* object = node->getObject();
-		LLViewerObject::const_child_list_t& child_list = object->getChildren();
-		for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
-			 iter != child_list.end(); iter++)
-		{
-			LLViewerObject* child = *iter;
-			if (child->isAvatar())
-			{
-				return FALSE;
-			}
-		}
-	}
-
-	return (selection->getRootObjectCount() == 1) && 
-		(selection->getFirstRootObject()->getPCode() == LL_PCODE_VOLUME) && 
-		selection->getFirstRootObject()->permYouOwner() &&
-		selection->getFirstRootObject()->flagObjectMove() &&
-		!selection->getFirstRootObject()->flagObjectPermanent() &&
-		!((LLViewerObject*)selection->getFirstRootObject()->getRoot())->isAvatar() && 
-		(selection->getFirstRootObject()->getNVPair("AssetContainer") == NULL);
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    for (LLObjectSelection::root_iterator iter = selection->root_begin();
+         iter != selection->root_end(); iter++)
+    {
+        LLSelectNode* node = *iter;
+        LLViewerObject* object = node->getObject();
+        LLViewerObject::const_child_list_t& child_list = object->getChildren();
+        for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
+             iter != child_list.end(); iter++)
+        {
+            LLViewerObject* child = *iter;
+            if (child->isAvatar())
+            {
+                return FALSE;
+            }
+        }
+    }
+
+    return (selection->getRootObjectCount() == 1) &&
+        (selection->getFirstRootObject()->getPCode() == LL_PCODE_VOLUME) &&
+        selection->getFirstRootObject()->permYouOwner() &&
+        selection->getFirstRootObject()->flagObjectMove() &&
+        !selection->getFirstRootObject()->flagObjectPermanent() &&
+        !((LLViewerObject*)selection->getFirstRootObject()->getRoot())->isAvatar() &&
+        (selection->getFirstRootObject()->getNVPair("AssetContainer") == NULL);
 }
 
 BOOL object_is_wearable()
 {
-	if (!isAgentAvatarValid())
-	{
-		return FALSE;
-	}
-//	if (!object_selected_and_point_valid())
+    if (!isAgentAvatarValid())
+    {
+        return FALSE;
+    }
+//  if (!object_selected_and_point_valid())
 // [RLVa:KB] - Checked: 2010-03-16 (RLVa-1.2.0a) | Added: RLVa-1.2.0a
-	if (!object_selected_and_point_valid(LLSD(0)))
+    if (!object_selected_and_point_valid(LLSD(0)))
 // [/RLVa:KB]
-	{
-		return FALSE;
-	}
-	if (sitting_on_selection())
-	{
-		return FALSE;
-	}
+    {
+        return FALSE;
+    }
+    if (sitting_on_selection())
+    {
+        return FALSE;
+    }
     if (!gAgentAvatarp->canAttachMoreObjects())
     {
         return FALSE;
     }
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-	for (LLSelectNode* node : selection->valid_root_begin_end())
-	{
-		if (node->mPermissions->getOwner() == gAgent.getID())
-		{
-			return TRUE;
-		}
-	}
-	return FALSE;
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+    for (LLSelectNode* node : selection->valid_root_begin_end())
+    {
+        if (node->mPermissions->getOwner() == gAgent.getID())
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 class LLAttachmentPointFilled : public view_listener_t
 {
-	bool handleEvent(const LLSD& user_data)
-	{
-		bool enable = false;
-		LLVOAvatar::attachment_map_t::iterator found_it = gAgentAvatarp->mAttachmentPoints.find(user_data.asInteger());
-		if (found_it != gAgentAvatarp->mAttachmentPoints.end())
-		{
-//			enable = found_it->second->getNumObjects() > 0;
+    bool handleEvent(const LLSD& user_data)
+    {
+        bool enable = false;
+        LLVOAvatar::attachment_map_t::iterator found_it = gAgentAvatarp->mAttachmentPoints.find(user_data.asInteger());
+        if (found_it != gAgentAvatarp->mAttachmentPoints.end())
+        {
+//          enable = found_it->second->getNumObjects() > 0;
 // [RLVa:KB] - Checked: 2010-03-04 (RLVa-1.2.0a) | Added: RLVa-1.2.0a
-			// Enable the option if there is at least one attachment on this attachment point that can be detached
-			enable = (found_it->second->getNumObjects() > 0) && 
-				((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(found_it->second)));
+            // Enable the option if there is at least one attachment on this attachment point that can be detached
+            enable = (found_it->second->getNumObjects() > 0) &&
+                ((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(found_it->second)));
 // [/RLVa:KB]
-		}
-		return enable;
-	}
+        }
+        return enable;
+    }
 };
 
 class LLAvatarSendIM : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
-//		if(avatar)
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
+//      if(avatar)
 // [RLVa:KB] - Checked: RLVa-1.2.0
-		if ( (avatar) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
+        if ( (avatar) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
 // [/RLVa:KB]
-		{
-			LLAvatarActions::startIM(avatar->getID());
-		}
-		return true;
-	}
+        {
+            LLAvatarActions::startIM(avatar->getID());
+        }
+        return true;
+    }
 };
 
 class LLAvatarCall : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
-//		if(avatar)
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLVOAvatar* avatar = find_avatar_from_object( LLSelectMgr::getInstance()->getSelection()->getPrimaryObject() );
+//      if(avatar)
 // [RLVa:KB] - Checked: RLVa-1.2.0
-		if ( (avatar) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
+        if ( (avatar) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, avatar->getID())) )
 // [/RLVa:KB]
-		{
-			LLAvatarActions::startCall(avatar->getID());
-		}
-		return true;
-	}
+        {
+            LLAvatarActions::startCall(avatar->getID());
+        }
+        return true;
+    }
 };
 
 // [RLVa:KB] - Checked: RLVa-1.2.1
 bool enable_avatar_call()
 {
-	if (RlvActions::isRlvEnabled())
-	{
-		const LLVOAvatar* pAvatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
-		if ((!pAvatar) || (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, pAvatar->getID())))
-			return false;
-	}
-	return LLAvatarActions::canCall();
+    if (RlvActions::isRlvEnabled())
+    {
+        const LLVOAvatar* pAvatar = find_avatar_from_object(LLSelectMgr::getInstance()->getSelection()->getPrimaryObject());
+        if ((!pAvatar) || (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, pAvatar->getID())))
+            return false;
+    }
+    return LLAvatarActions::canCall();
 }
 // [/RLVa:KB]
 
 namespace
 {
-	struct QueueObjects : public LLSelectedNodeFunctor
-	{
-		BOOL scripted;
-		BOOL modifiable;
-		LLFloaterScriptQueue* mQueue;
-		QueueObjects(LLFloaterScriptQueue* q) : mQueue(q), scripted(FALSE), modifiable(FALSE) {}
-		virtual bool apply(LLSelectNode* node)
-		{
-			LLViewerObject* obj = node->getObject();
-			if (!obj)
-			{
-				return true;
-			}
-			scripted = obj->flagScripted();
-			modifiable = obj->permModify();
-
-			if( scripted && modifiable )
-			{
-				mQueue->addObject(obj->getID(), node->mName);
-				return false;
-			}
-			else
-			{
-				return true; // fail: stop applying
-			}
-		}
-	};
+    struct QueueObjects : public LLSelectedNodeFunctor
+    {
+        BOOL scripted;
+        BOOL modifiable;
+        LLFloaterScriptQueue* mQueue;
+        QueueObjects(LLFloaterScriptQueue* q) : mQueue(q), scripted(FALSE), modifiable(FALSE) {}
+        virtual bool apply(LLSelectNode* node)
+        {
+            LLViewerObject* obj = node->getObject();
+            if (!obj)
+            {
+                return true;
+            }
+            scripted = obj->flagScripted();
+            modifiable = obj->permModify();
+
+            if( scripted && modifiable )
+            {
+                mQueue->addObject(obj->getID(), node->mName);
+                return false;
+            }
+            else
+            {
+                return true; // fail: stop applying
+            }
+        }
+    };
 }
 
 bool queue_actions(LLFloaterScriptQueue* q, const std::string& msg)
 {
-	QueueObjects func(q);
-	LLSelectMgr *mgr = LLSelectMgr::getInstance();
-	LLObjectSelectionHandle selectHandle = mgr->getSelection();
-	bool fail = selectHandle->applyToNodes(&func);
-	if(fail)
-	{
-		if ( !func.scripted )
-		{
-			std::string noscriptmsg = std::string("Cannot") + msg + "SelectObjectsNoScripts";
-			LLNotificationsUtil::add(noscriptmsg);
-		}
-		else if ( !func.modifiable )
-		{
-			std::string nomodmsg = std::string("Cannot") + msg + "SelectObjectsNoPermission";
-			LLNotificationsUtil::add(nomodmsg);
-		}
-		else
-		{
-			LL_ERRS() << "Bad logic." << LL_ENDL;
-		}
-		q->closeFloater();
-	}
-	else
-	{
-		if (!q->start())
-		{
-			LL_WARNS() << "Unexpected script compile failure." << LL_ENDL;
-		}
-	}
-	return !fail;
+    QueueObjects func(q);
+    LLSelectMgr *mgr = LLSelectMgr::getInstance();
+    LLObjectSelectionHandle selectHandle = mgr->getSelection();
+    bool fail = selectHandle->applyToNodes(&func);
+    if(fail)
+    {
+        if ( !func.scripted )
+        {
+            std::string noscriptmsg = std::string("Cannot") + msg + "SelectObjectsNoScripts";
+            LLNotificationsUtil::add(noscriptmsg);
+        }
+        else if ( !func.modifiable )
+        {
+            std::string nomodmsg = std::string("Cannot") + msg + "SelectObjectsNoPermission";
+            LLNotificationsUtil::add(nomodmsg);
+        }
+        else
+        {
+            LL_ERRS() << "Bad logic." << LL_ENDL;
+        }
+        q->closeFloater();
+    }
+    else
+    {
+        if (!q->start())
+        {
+            LL_WARNS() << "Unexpected script compile failure." << LL_ENDL;
+        }
+    }
+    return !fail;
 }
 
 class LLToolsSelectedScriptAction : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 // [RLVa:KB] - Checked: 2010-04-19 (RLVa-1.2.0f) | Modified: RLVa-1.0.5a
-		// We'll allow resetting the scripts of objects on a non-attachable attach point since they wouldn't be able to circumvent anything
-		if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
-		{
-			LLObjectSelectionHandle hSel = LLSelectMgr::getInstance()->getSelection();
-			RlvSelectHasLockedAttach f;
-			if ( (hSel->isAttachment()) && (hSel->getFirstNode(&f) != NULL) )
-				return true;
-		}
+        // We'll allow resetting the scripts of objects on a non-attachable attach point since they wouldn't be able to circumvent anything
+        if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
+        {
+            LLObjectSelectionHandle hSel = LLSelectMgr::getInstance()->getSelection();
+            RlvSelectHasLockedAttach f;
+            if ( (hSel->isAttachment()) && (hSel->getFirstNode(&f) != NULL) )
+                return true;
+        }
 // [/RLVa:KB]
 
-		std::string action = userdata.asString();
-		bool mono = false;
-		std::string msg, name;
-		std::string title;
-		if (action == "compile mono")
-		{
-			name = "compile_queue";
-			mono = true;
-			msg = "Recompile";
-			title = LLTrans::getString("CompileQueueTitle");
-		}
-		if (action == "compile lsl")
-		{
-			name = "compile_queue";
-			msg = "Recompile";
-			title = LLTrans::getString("CompileQueueTitle");
-		}
-		else if (action == "reset")
-		{
-			name = "reset_queue";
-			msg = "Reset";
-			title = LLTrans::getString("ResetQueueTitle");
-		}
-		else if (action == "start")
-		{
-			name = "start_queue";
-			msg = "SetRunning";
-			title = LLTrans::getString("RunQueueTitle");
-		}
-		else if (action == "stop")
-		{
-			name = "stop_queue";
-			msg = "SetRunningNot";
-			title = LLTrans::getString("NotRunQueueTitle");
-		}
-		else if (action == "delete")
-		{
-			name = "delete_queue";
-			msg = "Delete";
-			title = LLTrans::getString("DeleteQueueTitle");
-		}
-		LLUUID id; id.generate();
-		
-		LLFloaterScriptQueue* queue =LLFloaterReg::getTypedInstance<LLFloaterScriptQueue>(name, LLSD(id));
-		if (queue)
-		{
-			queue->setMono(mono);
-			if (queue_actions(queue, msg))
-			{
-				queue->setTitle(title);
-			}			
-		}
-		else
-		{
-			LL_WARNS() << "Failed to generate LLFloaterScriptQueue with action: " << action << LL_ENDL;
-		}
-		return true;
-	}
+        std::string action = userdata.asString();
+        bool mono = false;
+        std::string msg, name;
+        std::string title;
+        if (action == "compile mono")
+        {
+            name = "compile_queue";
+            mono = true;
+            msg = "Recompile";
+            title = LLTrans::getString("CompileQueueTitle");
+        }
+        if (action == "compile lsl")
+        {
+            name = "compile_queue";
+            msg = "Recompile";
+            title = LLTrans::getString("CompileQueueTitle");
+        }
+        else if (action == "reset")
+        {
+            name = "reset_queue";
+            msg = "Reset";
+            title = LLTrans::getString("ResetQueueTitle");
+        }
+        else if (action == "start")
+        {
+            name = "start_queue";
+            msg = "SetRunning";
+            title = LLTrans::getString("RunQueueTitle");
+        }
+        else if (action == "stop")
+        {
+            name = "stop_queue";
+            msg = "SetRunningNot";
+            title = LLTrans::getString("NotRunQueueTitle");
+        }
+        else if (action == "delete")
+        {
+            name = "delete_queue";
+            msg = "Delete";
+            title = LLTrans::getString("DeleteQueueTitle");
+        }
+        LLUUID id; id.generate();
+
+        LLFloaterScriptQueue* queue =LLFloaterReg::getTypedInstance<LLFloaterScriptQueue>(name, LLSD(id));
+        if (queue)
+        {
+            queue->setMono(mono);
+            if (queue_actions(queue, msg))
+            {
+                queue->setTitle(title);
+            }
+        }
+        else
+        {
+            LL_WARNS() << "Failed to generate LLFloaterScriptQueue with action: " << action << LL_ENDL;
+        }
+        return true;
+    }
 };
 
 void handle_selected_texture_info(void*)
 {
-	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->valid_begin_end())
-	{
-   		std::string msg;
-   		msg.assign("Texture info for: ");
-   		msg.append(node->mName);
-	   
-   		U8 te_count = node->getObject()->getNumTEs();
-   		// map from texture ID to list of faces using it
-   		typedef std::map< LLUUID, std::vector<U8> > map_t;
-   		map_t faces_per_texture;
-   		for (U8 i = 0; i < te_count; i++)
-   		{
-   			if (!node->isTESelected(i)) continue;
-	   
-   			LLViewerTexture* img = node->getObject()->getTEImage(i);
-   			LLUUID image_id = img->getID();
-   			faces_per_texture[image_id].push_back(i);
-   		}
-   		// Per-texture, dump which faces are using it.
-   		map_t::iterator it;
-   		for (it = faces_per_texture.begin(); it != faces_per_texture.end(); ++it)
-   		{
-   			U8 te = it->second[0];
-   			LLViewerTexture* img = node->getObject()->getTEImage(te);
-   			S32 height = img->getHeight();
-   			S32 width = img->getWidth();
-   			S32 components = img->getComponents();
-   			msg.append(llformat("\n%dx%d %s on face ",
-   								width,
-   								height,
-   								(components == 4 ? "alpha" : "opaque")));
-   			for (U8 i = 0; i < it->second.size(); ++i)
-   			{
-   				msg.append( llformat("%d ", (S32)(it->second[i])));
-   			}
-   		}
-   		LLSD args;
-   		args["MESSAGE"] = msg;
-   		LLNotificationsUtil::add("SystemMessage", args);
-	}
+    for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->valid_begin_end())
+    {
+        std::string msg;
+        msg.assign("Texture info for: ");
+        msg.append(node->mName);
+
+        U8 te_count = node->getObject()->getNumTEs();
+        // map from texture ID to list of faces using it
+        typedef std::map< LLUUID, std::vector<U8> > map_t;
+        map_t faces_per_texture;
+        for (U8 i = 0; i < te_count; i++)
+        {
+            if (!node->isTESelected(i)) continue;
+
+            LLViewerTexture* img = node->getObject()->getTEImage(i);
+            LLUUID image_id = img->getID();
+            faces_per_texture[image_id].push_back(i);
+        }
+        // Per-texture, dump which faces are using it.
+        map_t::iterator it;
+        for (it = faces_per_texture.begin(); it != faces_per_texture.end(); ++it)
+        {
+            U8 te = it->second[0];
+            LLViewerTexture* img = node->getObject()->getTEImage(te);
+            S32 height = img->getHeight();
+            S32 width = img->getWidth();
+            S32 components = img->getComponents();
+            msg.append(llformat("\n%dx%d %s on face ",
+                                width,
+                                height,
+                                (components == 4 ? "alpha" : "opaque")));
+            for (U8 i = 0; i < it->second.size(); ++i)
+            {
+                msg.append( llformat("%d ", (S32)(it->second[i])));
+            }
+        }
+        LLSD args;
+        args["MESSAGE"] = msg;
+        LLNotificationsUtil::add("SystemMessage", args);
+    }
 }
 
 void handle_selected_material_info()
 {
-	for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->valid_begin_end())
-	{
-		std::string msg;
-		msg.assign("Material info for: \n");
-		msg.append(node->mName);
-		
-		U8 te_count = node->getObject()->getNumTEs();
-		// map from material ID to list of faces using it
-		typedef std::map<LLMaterialID, std::vector<U8> > map_t;
-		map_t faces_per_material;
-		for (U8 i = 0; i < te_count; i++)
-		{
-			if (!node->isTESelected(i)) continue;
-	
-			const LLMaterialID& material_id = node->getObject()->getTE(i)->getMaterialID();
-			faces_per_material[material_id].push_back(i);
-		}
-		// Per-material, dump which faces are using it.
-		map_t::iterator it;
-		for (it = faces_per_material.begin(); it != faces_per_material.end(); ++it)
-		{
-			const LLMaterialID& material_id = it->first;
-			msg += llformat("%s on face ", material_id.asString().c_str());
-			for (U8 i = 0; i < it->second.size(); ++i)
-			{
-				msg.append( llformat("%d ", (S32)(it->second[i])));
-			}
-			msg.append("\n");
-		}
-
-		LLSD args;
-		args["MESSAGE"] = msg;
-		LLNotificationsUtil::add("SystemMessage", args);
-	}
+    for (LLSelectNode* node : LLSelectMgr::getInstance()->getSelection()->valid_begin_end())
+    {
+        std::string msg;
+        msg.assign("Material info for: \n");
+        msg.append(node->mName);
+
+        U8 te_count = node->getObject()->getNumTEs();
+        // map from material ID to list of faces using it
+        typedef std::map<LLMaterialID, std::vector<U8> > map_t;
+        map_t faces_per_material;
+        for (U8 i = 0; i < te_count; i++)
+        {
+            if (!node->isTESelected(i)) continue;
+
+            const LLMaterialID& material_id = node->getObject()->getTE(i)->getMaterialID();
+            faces_per_material[material_id].push_back(i);
+        }
+        // Per-material, dump which faces are using it.
+        map_t::iterator it;
+        for (it = faces_per_material.begin(); it != faces_per_material.end(); ++it)
+        {
+            const LLMaterialID& material_id = it->first;
+            msg += llformat("%s on face ", material_id.asString().c_str());
+            for (U8 i = 0; i < it->second.size(); ++i)
+            {
+                msg.append( llformat("%d ", (S32)(it->second[i])));
+            }
+            msg.append("\n");
+        }
+
+        LLSD args;
+        args["MESSAGE"] = msg;
+        LLNotificationsUtil::add("SystemMessage", args);
+    }
 }
 
 void handle_test_male(void*)
 {
 // [RLVa:KB] - Checked: 2010-03-19 (RLVa-1.2.0c) | Modified: RLVa-1.2.0a
-	// TODO-RLVa: [RLVa-1.2.1] Is there any reason to still block this?
-	if ( (rlv_handler_t::isEnabled()) && 
-		 ((gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) || (gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY))) )
-	{
-		return;
-	}
+    // TODO-RLVa: [RLVa-1.2.1] Is there any reason to still block this?
+    if ( (rlv_handler_t::isEnabled()) &&
+         ((gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) || (gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY))) )
+    {
+        return;
+    }
 // [/RLVa:KB]
 
-	LLAppearanceMgr::instance().wearOutfitByName("Male Shape & Outfit");
-	//gGestureList.requestResetFromServer( TRUE );
+    LLAppearanceMgr::instance().wearOutfitByName("Male Shape & Outfit");
+    //gGestureList.requestResetFromServer( TRUE );
 }
 
 void handle_test_female(void*)
 {
 // [RLVa:KB] - Checked: 2010-03-19 (RLVa-1.2.0c) | Modified: RLVa-1.2.0a
-	// TODO-RLVa: [RLVa-1.2.1] Is there any reason to still block this?
-	if ( (rlv_handler_t::isEnabled()) && 
-		 ((gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) || (gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY))) )
-	{
-		return;
-	}
+    // TODO-RLVa: [RLVa-1.2.1] Is there any reason to still block this?
+    if ( (rlv_handler_t::isEnabled()) &&
+         ((gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_ANY)) || (gRlvWearableLocks.hasLockedWearableType(RLV_LOCK_ANY))) )
+    {
+        return;
+    }
 // [/RLVa:KB]
 
-	LLAppearanceMgr::instance().wearOutfitByName("Female Shape & Outfit");
-	//gGestureList.requestResetFromServer( FALSE );
+    LLAppearanceMgr::instance().wearOutfitByName("Female Shape & Outfit");
+    //gGestureList.requestResetFromServer( FALSE );
 }
 
 void handle_dump_attachments(void*)
 {
-	if(!isAgentAvatarValid()) return;
+    if(!isAgentAvatarValid()) return;
 
-	for (const auto& attach_pair : gAgentAvatarp->mAttachmentPoints)
-	{
+    for (const auto& attach_pair : gAgentAvatarp->mAttachmentPoints)
+    {
         LLViewerJointAttachment* attachment = attach_pair.second;
-		S32 key = attach_pair.first;
+        S32 key = attach_pair.first;
         for (LLViewerObject * attached_object : attachment->mAttachedObjects)
-		{
-			BOOL visible = (attached_object != NULL &&
-							attached_object->mDrawable.notNull() && 
-							!attached_object->mDrawable->isRenderType(0));
-			LLVector3 pos;
-			if (visible) pos = attached_object->mDrawable->getPosition();
-			LL_INFOS() << "ATTACHMENT " << key << ": item_id=" << attached_object->getAttachmentItemID()
-					<< (attached_object ? " present " : " absent ")
-					<< (visible ? "visible " : "invisible ")
-					<<  " at " << pos
-					<< " and " << (visible ? attached_object->getPosition() : LLVector3::zero)
-					<< LL_ENDL;
-		}
-	}
+        {
+            BOOL visible = (attached_object != NULL &&
+                            attached_object->mDrawable.notNull() &&
+                            !attached_object->mDrawable->isRenderType(0));
+            LLVector3 pos;
+            if (visible) pos = attached_object->mDrawable->getPosition();
+            LL_INFOS() << "ATTACHMENT " << key << ": item_id=" << attached_object->getAttachmentItemID()
+                    << (attached_object ? " present " : " absent ")
+                    << (visible ? "visible " : "invisible ")
+                    <<  " at " << pos
+                    << " and " << (visible ? attached_object->getPosition() : LLVector3::zero)
+                    << LL_ENDL;
+        }
+    }
 }
 
 
@@ -8328,96 +8328,96 @@ class LLToggleControl : public view_listener_t
 {
 protected:
 
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string control_name = userdata.asString();
-		BOOL checked = gSavedSettings.getBOOL( control_name );
-		gSavedSettings.setBOOL( control_name, !checked );
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string control_name = userdata.asString();
+        BOOL checked = gSavedSettings.getBOOL( control_name );
+        gSavedSettings.setBOOL( control_name, !checked );
+        return true;
+    }
 };
 
 class LLCheckControl : public view_listener_t
 {
-	bool handleEvent( const LLSD& userdata)
-	{
-		std::string callback_data = userdata.asString();
-		bool new_value = gSavedSettings.getBOOL(callback_data);
-		return new_value;
-	}
+    bool handleEvent( const LLSD& userdata)
+    {
+        std::string callback_data = userdata.asString();
+        bool new_value = gSavedSettings.getBOOL(callback_data);
+        return new_value;
+    }
 };
 
 class LLResetControl : public view_listener_t
 {
 protected:
 
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string control_name = userdata.asString();
-		auto ctrlp = gSavedSettings.getControl(control_name);
-		if (ctrlp)
-		{
-			ctrlp->resetToDefault(true);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string control_name = userdata.asString();
+        auto ctrlp = gSavedSettings.getControl(control_name);
+        if (ctrlp)
+        {
+            ctrlp->resetToDefault(true);
+        }
+        return true;
+    }
 };
 
 // not so generic
 
 class LLAdvancedCheckRenderShadowOption: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string control_name = userdata.asString();
-		S32 current_shadow_level = gSavedSettings.getS32(control_name);
-		if (current_shadow_level == 0) // is off
-		{
-			return false;
-		}
-		else // is on
-		{
-			return true;
-		}
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string control_name = userdata.asString();
+        S32 current_shadow_level = gSavedSettings.getS32(control_name);
+        if (current_shadow_level == 0) // is off
+        {
+            return false;
+        }
+        else // is on
+        {
+            return true;
+        }
+    }
 };
 
 class LLAdvancedClickRenderShadowOption: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string control_name = userdata.asString();
-		S32 current_shadow_level = gSavedSettings.getS32(control_name);
-		if (current_shadow_level == 0) // upgrade to level 2
-		{
-			gSavedSettings.setS32(control_name, 2);
-		}
-		else // downgrade to level 0
-		{
-			gSavedSettings.setS32(control_name, 0);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string control_name = userdata.asString();
+        S32 current_shadow_level = gSavedSettings.getS32(control_name);
+        if (current_shadow_level == 0) // upgrade to level 2
+        {
+            gSavedSettings.setS32(control_name, 2);
+        }
+        else // downgrade to level 0
+        {
+            gSavedSettings.setS32(control_name, 0);
+        }
+        return true;
+    }
 };
 
 class LLAdvancedClickRenderProfile: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gShaderProfileFrame = TRUE;
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gShaderProfileFrame = TRUE;
+        return true;
+    }
 };
 
 F32 gpu_benchmark();
 
 class LLAdvancedClickRenderBenchmark: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gpu_benchmark();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gpu_benchmark();
+        return true;
+    }
 };
 
 void hdri_preview();
@@ -8447,316 +8447,316 @@ class LLAdvancedClickGLTFScenePreview : public view_listener_t
 // these are used in the gl menus to set control values that require shader recompilation
 class LLToggleShaderControl : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
         std::string control_name = userdata.asString();
-		BOOL checked = gSavedSettings.getBOOL( control_name );
-		gSavedSettings.setBOOL( control_name, !checked );
+        BOOL checked = gSavedSettings.getBOOL( control_name );
+        gSavedSettings.setBOOL( control_name, !checked );
         LLPipeline::refreshCachedSettings();
         LLViewerShaderMgr::instance()->setShaders();
-		return !checked;
-	}
+        return !checked;
+    }
 };
 
 void menu_toggle_attached_lights(void* user_data)
 {
-	LLPipeline::sRenderAttachedLights = gSavedSettings.getBOOL("RenderAttachedLights");
+    LLPipeline::sRenderAttachedLights = gSavedSettings.getBOOL("RenderAttachedLights");
 }
 
 void menu_toggle_attached_particles(void* user_data)
 {
-	LLPipeline::sRenderAttachedParticles = gSavedSettings.getBOOL("RenderAttachedParticles");
+    LLPipeline::sRenderAttachedParticles = gSavedSettings.getBOOL("RenderAttachedParticles");
 }
 
 class LLAdvancedHandleAttachedLightParticles: public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string control_name = userdata.asString();
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string control_name = userdata.asString();
 
-		// toggle the control
-		gSavedSettings.setBOOL(control_name,
-				       !gSavedSettings.getBOOL(control_name));
+        // toggle the control
+        gSavedSettings.setBOOL(control_name,
+                       !gSavedSettings.getBOOL(control_name));
 
-		// update internal flags
-		if (control_name == "RenderAttachedLights")
-		{
-			menu_toggle_attached_lights(NULL);
-		}
-		else if (control_name == "RenderAttachedParticles")
-		{
-			menu_toggle_attached_particles(NULL);
-		}
-		return true;
-	}
+        // update internal flags
+        if (control_name == "RenderAttachedLights")
+        {
+            menu_toggle_attached_lights(NULL);
+        }
+        else if (control_name == "RenderAttachedParticles")
+        {
+            menu_toggle_attached_particles(NULL);
+        }
+        return true;
+    }
 };
 
 class LLSomethingSelected : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = !(LLSelectMgr::getInstance()->getSelection()->isEmpty());
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = !(LLSelectMgr::getInstance()->getSelection()->isEmpty());
+        return new_value;
+    }
 };
 
 class LLSomethingSelectedNoHUD : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-		bool new_value = !(selection->isEmpty()) && !(selection->getSelectType() == SELECT_TYPE_HUD);
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+        bool new_value = !(selection->isEmpty()) && !(selection->getSelectType() == SELECT_TYPE_HUD);
+        return new_value;
+    }
 };
 
 static bool is_editable_selected()
 {
-	LLObjectSelectionHandle hSelection = LLSelectMgr::getInstance()->getSelection();
-	// [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.2.1f) | Modified: RLVa-1.0.5a
-	// RELEASE-RLVa: [SL-2.2.0] Check that this still isn't called by anything but script actions in the Build menu
-	if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
-	{
-		// NOTE: this is called for 5 different menu items so we'll trade accuracy for efficiency and only
-		//       examine root nodes (LLToolsSelectedScriptAction::handleEvent() will catch what we miss)
-		RlvSelectHasLockedAttach f;
-		if ( (hSelection->isAttachment()) && (hSelection->getFirstRootNode(&f)) )
-		{
-			return false;
-		}
-	}
+    LLObjectSelectionHandle hSelection = LLSelectMgr::getInstance()->getSelection();
+    // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.2.1f) | Modified: RLVa-1.0.5a
+    // RELEASE-RLVa: [SL-2.2.0] Check that this still isn't called by anything but script actions in the Build menu
+    if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedAttachmentPoint(RLV_LOCK_REMOVE)) )
+    {
+        // NOTE: this is called for 5 different menu items so we'll trade accuracy for efficiency and only
+        //       examine root nodes (LLToolsSelectedScriptAction::handleEvent() will catch what we miss)
+        RlvSelectHasLockedAttach f;
+        if ( (hSelection->isAttachment()) && (hSelection->getFirstRootNode(&f)) )
+        {
+            return false;
+        }
+    }
 // [/RLVa:KB]
 
-	return (hSelection->getFirstEditableObject() != NULL);
+    return (hSelection->getFirstEditableObject() != NULL);
 }
 
 class LLEditableSelected : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return is_editable_selected();
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return is_editable_selected();
+    }
 };
 
 class LLEditableSelectedMono : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = false;
-		LLViewerRegion* region = gAgent.getRegion();
-		if(region && gMenuHolder)
-		{
-			bool have_cap = (! region->getCapability("UpdateScriptTask").empty());
-			new_value = is_editable_selected() && have_cap;
-		}
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = false;
+        LLViewerRegion* region = gAgent.getRegion();
+        if(region && gMenuHolder)
+        {
+            bool have_cap = (! region->getCapability("UpdateScriptTask").empty());
+            new_value = is_editable_selected() && have_cap;
+        }
+        return new_value;
+    }
 };
 
 bool enable_object_take_copy()
 {
-	bool all_valid = false;
-	LLSelectMgr* select_mgr = LLSelectMgr::getInstance();
-	{
-		if (select_mgr->getSelection()->getRootObjectCount() > 0)
-		{
-		all_valid = true;
+    bool all_valid = false;
+    LLSelectMgr* select_mgr = LLSelectMgr::getInstance();
+    {
+        if (select_mgr->getSelection()->getRootObjectCount() > 0)
+        {
+        all_valid = true;
 #ifndef HACKED_GODLIKE_VIEWER
 # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-		if (!LLGridManager::getInstance()->isInSLBeta()
+        if (!LLGridManager::getInstance()->isInSLBeta()
             || !gAgent.isGodlike())
 # endif
-		{
-			struct f : public LLSelectedObjectFunctor
-			{
-				virtual bool apply(LLViewerObject* obj)
-				{
-//					return (!obj->permCopy() || obj->isAttachment());
+        {
+            struct f : public LLSelectedObjectFunctor
+            {
+                virtual bool apply(LLViewerObject* obj)
+                {
+//                  return (!obj->permCopy() || obj->isAttachment());
 // [RLVa:KB] - Checked: 2010-04-01 (RLVa-1.2.0c) | Modified: RLVa-1.0.0g
-					return (!obj->permCopy() || obj->isAttachment()) || 
-						( (gRlvHandler.hasBehaviour(RLV_BHVR_UNSIT)) && (isAgentAvatarValid()) && (gAgentAvatarp->getRoot() == obj) );
+                    return (!obj->permCopy() || obj->isAttachment()) ||
+                        ( (gRlvHandler.hasBehaviour(RLV_BHVR_UNSIT)) && (isAgentAvatarValid()) && (gAgentAvatarp->getRoot() == obj) );
 // [/RLVa:KB]
-				}
-			} func;
-			const bool firstonly = true;
-			bool any_invalid = select_mgr->getSelection()->applyToRootObjects(&func, firstonly);
-			all_valid = !any_invalid;
-		}
+                }
+            } func;
+            const bool firstonly = true;
+            bool any_invalid = select_mgr->getSelection()->applyToRootObjects(&func, firstonly);
+            all_valid = !any_invalid;
+        }
 #endif // HACKED_GODLIKE_VIEWER
-		}
-	}
+        }
+    }
 
-	return all_valid;
+    return all_valid;
 }
 
 
 class LLHasAsset : public LLInventoryCollectFunctor
 {
 public:
-	LLHasAsset(const LLUUID& id) : mAssetID(id), mHasAsset(FALSE) {}
-	virtual ~LLHasAsset() {}
-	virtual bool operator()(LLInventoryCategory* cat,
-							LLInventoryItem* item);
-	BOOL hasAsset() const { return mHasAsset; }
+    LLHasAsset(const LLUUID& id) : mAssetID(id), mHasAsset(FALSE) {}
+    virtual ~LLHasAsset() {}
+    virtual bool operator()(LLInventoryCategory* cat,
+                            LLInventoryItem* item);
+    BOOL hasAsset() const { return mHasAsset; }
 
 protected:
-	LLUUID mAssetID;
-	BOOL mHasAsset;
+    LLUUID mAssetID;
+    BOOL mHasAsset;
 };
 
 bool LLHasAsset::operator()(LLInventoryCategory* cat,
-							LLInventoryItem* item)
+                            LLInventoryItem* item)
 {
-	if(item && item->getAssetUUID() == mAssetID)
-	{
-		mHasAsset = TRUE;
-	}
-	return FALSE;
+    if(item && item->getAssetUUID() == mAssetID)
+    {
+        mHasAsset = TRUE;
+    }
+    return FALSE;
 }
 
 
 BOOL enable_save_into_task_inventory(void*)
 {
-	LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
-	if(node && (node->mValid) && (!node->mFromTaskID.isNull()))
-	{
-		// *TODO: check to see if the fromtaskid object exists.
-		LLViewerObject* obj = node->getObject();
-		if( obj && !obj->isAttachment() )
-		{
-			return TRUE;
-		}
-	}
-	return FALSE;
+    LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstRootNode();
+    if(node && (node->mValid) && (!node->mFromTaskID.isNull()))
+    {
+        // *TODO: check to see if the fromtaskid object exists.
+        LLViewerObject* obj = node->getObject();
+        if( obj && !obj->isAttachment() )
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 class LLToolsEnableSaveToObjectInventory : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = enable_save_into_task_inventory(NULL);
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = enable_save_into_task_inventory(NULL);
+        return new_value;
+    }
 };
 
 class LLToggleHowTo : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLFloaterReg::toggleInstanceOrBringToFront("guidebook");
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLFloaterReg::toggleInstanceOrBringToFront("guidebook");
+        return true;
+    }
 };
 
 class LLViewEnableMouselook : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		// You can't go directly from customize avatar to mouselook.
-		// TODO: write code with appropriate dialogs to handle this transition.
-		bool new_value = (CAMERA_MODE_CUSTOMIZE_AVATAR != gAgentCamera.getCameraMode() && !LLPipeline::FreezeTime);
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        // You can't go directly from customize avatar to mouselook.
+        // TODO: write code with appropriate dialogs to handle this transition.
+        bool new_value = (CAMERA_MODE_CUSTOMIZE_AVATAR != gAgentCamera.getCameraMode() && !LLPipeline::FreezeTime);
+        return new_value;
+    }
 };
 
 class LLToolsEnableToolNotPie : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = ( LLToolMgr::getInstance()->getBaseTool() != LLToolPie::getInstance() );
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = ( LLToolMgr::getInstance()->getBaseTool() != LLToolPie::getInstance() );
+        return new_value;
+    }
 };
 
 class LLWorldEnableCreateLandmark : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-//		return !LLLandmarkActions::landmarkAlreadyExists();
+    bool handleEvent(const LLSD& userdata)
+    {
+//      return !LLLandmarkActions::landmarkAlreadyExists();
 // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.4.5) | Added: RLVa-1.2.1
-		return (!LLLandmarkActions::landmarkAlreadyExists()) && (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC));
+        return (!LLLandmarkActions::landmarkAlreadyExists()) && (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC));
 // [/RLVa:KB]
-	}
+    }
 };
 
 class LLWorldEnableSetHomeLocation : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gAgent.isGodlike() || 
-			(gAgent.getRegion() && gAgent.getRegion()->getAllowSetHome());
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gAgent.isGodlike() ||
+            (gAgent.getRegion() && gAgent.getRegion()->getAllowSetHome());
+        return new_value;
+    }
 };
 
 class LLWorldEnableTeleportHome : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLViewerRegion* regionp = gAgent.getRegion();
-		bool agent_on_prelude = (regionp && regionp->isPrelude());
-		bool enable_teleport_home = gAgent.isGodlike() || !agent_on_prelude;
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLViewerRegion* regionp = gAgent.getRegion();
+        bool agent_on_prelude = (regionp && regionp->isPrelude());
+        bool enable_teleport_home = gAgent.isGodlike() || !agent_on_prelude;
 // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.2.1f) | Modified: RLVa-1.2.1f
-		enable_teleport_home &= 
-			(!rlv_handler_t::isEnabled()) || ((!gRlvHandler.hasBehaviour(RLV_BHVR_TPLM)) && (!gRlvHandler.hasBehaviour(RLV_BHVR_TPLOC)));
+        enable_teleport_home &=
+            (!rlv_handler_t::isEnabled()) || ((!gRlvHandler.hasBehaviour(RLV_BHVR_TPLM)) && (!gRlvHandler.hasBehaviour(RLV_BHVR_TPLOC)));
 // [/RLVa:KB]
-		return enable_teleport_home;
-	}
+        return enable_teleport_home;
+    }
 };
 
 BOOL enable_god_full(void*)
 {
-	return gAgent.getGodLevel() >= GOD_FULL;
+    return gAgent.getGodLevel() >= GOD_FULL;
 }
 
 BOOL enable_god_liaison(void*)
 {
-	return gAgent.getGodLevel() >= GOD_LIAISON;
+    return gAgent.getGodLevel() >= GOD_LIAISON;
 }
 
 bool is_god_customer_service()
 {
-	return gAgent.getGodLevel() >= GOD_CUSTOMER_SERVICE;
+    return gAgent.getGodLevel() >= GOD_CUSTOMER_SERVICE;
 }
 
 BOOL enable_god_basic(void*)
 {
-	return gAgent.getGodLevel() > GOD_NOT;
+    return gAgent.getGodLevel() > GOD_NOT;
 }
 
 
 void toggle_show_xui_names(void *)
 {
-	gSavedSettings.setBOOL("DebugShowXUINames", !gSavedSettings.getBOOL("DebugShowXUINames"));
+    gSavedSettings.setBOOL("DebugShowXUINames", !gSavedSettings.getBOOL("DebugShowXUINames"));
 }
 
 BOOL check_show_xui_names(void *)
 {
-	return gSavedSettings.getBOOL("DebugShowXUINames");
+    return gSavedSettings.getBOOL("DebugShowXUINames");
 }
 
 class LLToolsSelectOnlyMyObjects : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		BOOL cur_val = gSavedSettings.getBOOL("SelectOwnedOnly");
+    bool handleEvent(const LLSD& userdata)
+    {
+        BOOL cur_val = gSavedSettings.getBOOL("SelectOwnedOnly");
 
-		gSavedSettings.setBOOL("SelectOwnedOnly", ! cur_val );
+        gSavedSettings.setBOOL("SelectOwnedOnly", ! cur_val );
 
-		return true;
-	}
+        return true;
+    }
 };
 
 class LLToolsSelectOnlyMovableObjects : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		BOOL cur_val = gSavedSettings.getBOOL("SelectMovableOnly");
+    bool handleEvent(const LLSD& userdata)
+    {
+        BOOL cur_val = gSavedSettings.getBOOL("SelectMovableOnly");
 
-		gSavedSettings.setBOOL("SelectMovableOnly", ! cur_val );
+        gSavedSettings.setBOOL("SelectMovableOnly", ! cur_val );
 
-		return true;
-	}
+        return true;
+    }
 };
 
 class LLToolsSelectInvisibleObjects : public view_listener_t
@@ -8785,166 +8785,166 @@ class LLToolsSelectReflectionProbes: public view_listener_t
 
 class LLToolsSelectBySurrounding : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLSelectMgr::sRectSelectInclusive = !LLSelectMgr::sRectSelectInclusive;
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLSelectMgr::sRectSelectInclusive = !LLSelectMgr::sRectSelectInclusive;
 
-		gSavedSettings.setBOOL("RectangleSelectInclusive", LLSelectMgr::sRectSelectInclusive);
-		return true;
-	}
+        gSavedSettings.setBOOL("RectangleSelectInclusive", LLSelectMgr::sRectSelectInclusive);
+        return true;
+    }
 };
 
 class LLToolsShowSelectionLightRadius : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		// TomY TODO merge these
-		LLSelectMgr::sRenderLightRadius = !LLSelectMgr::sRenderLightRadius;
+    bool handleEvent(const LLSD& userdata)
+    {
+        // TomY TODO merge these
+        LLSelectMgr::sRenderLightRadius = !LLSelectMgr::sRenderLightRadius;
 
-		gSavedSettings.setBOOL("RenderLightRadius", LLSelectMgr::sRenderLightRadius);
-		return true;
-	}
+        gSavedSettings.setBOOL("RenderLightRadius", LLSelectMgr::sRenderLightRadius);
+        return true;
+    }
 };
 
 class LLToolsEditLinkedParts : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		BOOL select_individuals = !gSavedSettings.getBOOL("EditLinkedParts");
-		gSavedSettings.setBOOL( "EditLinkedParts", select_individuals );
-		if (select_individuals)
-		{
-			LLSelectMgr::getInstance()->demoteSelectionToIndividuals();
-		}
-		else
-		{
-			LLSelectMgr::getInstance()->promoteSelectionToRoot();
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        BOOL select_individuals = !gSavedSettings.getBOOL("EditLinkedParts");
+        gSavedSettings.setBOOL( "EditLinkedParts", select_individuals );
+        if (select_individuals)
+        {
+            LLSelectMgr::getInstance()->demoteSelectionToIndividuals();
+        }
+        else
+        {
+            LLSelectMgr::getInstance()->promoteSelectionToRoot();
+        }
+        return true;
+    }
 };
 
 void reload_vertex_shader(void *)
 {
-	//THIS WOULD BE AN AWESOME PLACE TO RELOAD SHADERS... just a thought	- DaveP
+    //THIS WOULD BE AN AWESOME PLACE TO RELOAD SHADERS... just a thought    - DaveP
 }
 
 void handle_dump_avatar_local_textures(void*)
 {
-	gAgentAvatarp->dumpLocalTextures();
+    gAgentAvatarp->dumpLocalTextures();
 }
 
 void handle_dump_timers()
 {
-	LLTrace::BlockTimer::dumpCurTimes();
+    LLTrace::BlockTimer::dumpCurTimes();
 }
 
 void handle_debug_avatar_textures(void*)
 {
-	LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
-	if (objectp)
-	{
-		LLFloaterReg::showInstance( "avatar_textures", LLSD(objectp->getID()) );
-	}
+    LLViewerObject* objectp = LLSelectMgr::getInstance()->getSelection()->getPrimaryObject();
+    if (objectp)
+    {
+        LLFloaterReg::showInstance( "avatar_textures", LLSD(objectp->getID()) );
+    }
 }
 
 void handle_grab_baked_texture(void* data)
 {
-	EBakedTextureIndex baked_tex_index = (EBakedTextureIndex)((intptr_t)data);
-	if (!isAgentAvatarValid()) return;
-
-	const LLUUID& asset_id = gAgentAvatarp->grabBakedTexture(baked_tex_index);
-	LL_INFOS("texture") << "Adding baked texture " << asset_id << " to inventory." << LL_ENDL;
-	LLAssetType::EType asset_type = LLAssetType::AT_TEXTURE;
-	LLInventoryType::EType inv_type = LLInventoryType::IT_TEXTURE;
-	const LLUUID folder_id = gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(asset_type));
-	if(folder_id.notNull())
-	{
-		std::string name;
-		name = "Baked " + LLAvatarAppearance::getDictionary()->getBakedTexture(baked_tex_index)->mNameCapitalized + " Texture";
-
-		LLUUID item_id;
-		item_id.generate();
-		LLPermissions perm;
-		perm.init(gAgentID,
-				  gAgentID,
-				  LLUUID::null,
-				  LLUUID::null);
-		U32 next_owner_perm = PERM_MOVE | PERM_TRANSFER;
-		perm.initMasks(PERM_ALL,
-					   PERM_ALL,
-					   PERM_NONE,
-					   PERM_NONE,
-					   next_owner_perm);
-		time_t creation_date_now = time_corrected();
-		LLPointer<LLViewerInventoryItem> item
-			= new LLViewerInventoryItem(item_id,
-										folder_id,
-										perm,
-										asset_id,
-										asset_type,
-										inv_type,
-										name,
-										LLStringUtil::null,
-										LLSaleInfo::DEFAULT,
-										LLInventoryItemFlags::II_FLAGS_NONE,
-										creation_date_now);
-
-		item->updateServer(TRUE);
-		gInventory.updateItem(item);
-		gInventory.notifyObservers();
-
-		// Show the preview panel for textures to let
-		// user know that the image is now in inventory.
-		LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
-		if(active_panel)
-		{
-			LLFocusableElement* focus_ctrl = gFocusMgr.getKeyboardFocus();
-
-			active_panel->setSelection(item_id, TAKE_FOCUS_NO);
-			active_panel->openSelected();
-			//LLFloaterInventory::dumpSelectionInformation((void*)view);
-			// restore keyboard focus
-			gFocusMgr.setKeyboardFocus(focus_ctrl);
-		}
-	}
-	else
-	{
-		LL_WARNS() << "Can't find a folder to put it in" << LL_ENDL;
-	}
+    EBakedTextureIndex baked_tex_index = (EBakedTextureIndex)((intptr_t)data);
+    if (!isAgentAvatarValid()) return;
+
+    const LLUUID& asset_id = gAgentAvatarp->grabBakedTexture(baked_tex_index);
+    LL_INFOS("texture") << "Adding baked texture " << asset_id << " to inventory." << LL_ENDL;
+    LLAssetType::EType asset_type = LLAssetType::AT_TEXTURE;
+    LLInventoryType::EType inv_type = LLInventoryType::IT_TEXTURE;
+    const LLUUID folder_id = gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(asset_type));
+    if(folder_id.notNull())
+    {
+        std::string name;
+        name = "Baked " + LLAvatarAppearance::getDictionary()->getBakedTexture(baked_tex_index)->mNameCapitalized + " Texture";
+
+        LLUUID item_id;
+        item_id.generate();
+        LLPermissions perm;
+        perm.init(gAgentID,
+                  gAgentID,
+                  LLUUID::null,
+                  LLUUID::null);
+        U32 next_owner_perm = PERM_MOVE | PERM_TRANSFER;
+        perm.initMasks(PERM_ALL,
+                       PERM_ALL,
+                       PERM_NONE,
+                       PERM_NONE,
+                       next_owner_perm);
+        time_t creation_date_now = time_corrected();
+        LLPointer<LLViewerInventoryItem> item
+            = new LLViewerInventoryItem(item_id,
+                                        folder_id,
+                                        perm,
+                                        asset_id,
+                                        asset_type,
+                                        inv_type,
+                                        name,
+                                        LLStringUtil::null,
+                                        LLSaleInfo::DEFAULT,
+                                        LLInventoryItemFlags::II_FLAGS_NONE,
+                                        creation_date_now);
+
+        item->updateServer(TRUE);
+        gInventory.updateItem(item);
+        gInventory.notifyObservers();
+
+        // Show the preview panel for textures to let
+        // user know that the image is now in inventory.
+        LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
+        if(active_panel)
+        {
+            LLFocusableElement* focus_ctrl = gFocusMgr.getKeyboardFocus();
+
+            active_panel->setSelection(item_id, TAKE_FOCUS_NO);
+            active_panel->openSelected();
+            //LLFloaterInventory::dumpSelectionInformation((void*)view);
+            // restore keyboard focus
+            gFocusMgr.setKeyboardFocus(focus_ctrl);
+        }
+    }
+    else
+    {
+        LL_WARNS() << "Can't find a folder to put it in" << LL_ENDL;
+    }
 }
 
 BOOL enable_grab_baked_texture(void* data)
 {
-	EBakedTextureIndex index = (EBakedTextureIndex)((intptr_t)data);
-	if (isAgentAvatarValid())
-	{
-		return gAgentAvatarp->canGrabBakedTexture(index);
-	}
-	return FALSE;
+    EBakedTextureIndex index = (EBakedTextureIndex)((intptr_t)data);
+    if (isAgentAvatarValid())
+    {
+        return gAgentAvatarp->canGrabBakedTexture(index);
+    }
+    return FALSE;
 }
 
 // Returns a pointer to the avatar give the UUID of the avatar OR of an attachment the avatar is wearing.
 // Returns NULL on failure.
 LLVOAvatar* find_avatar_from_object( LLViewerObject* object )
 {
-	if (object)
-	{
-		if( object->isAttachment() )
-		{
-			do
-			{
-				object = (LLViewerObject*) object->getParent();
-			}
-			while( object && !object->isAvatar() );
-		}
-		else if( !object->isAvatar() )
-		{
-			object = NULL;
-		}
-	}
+    if (object)
+    {
+        if( object->isAttachment() )
+        {
+            do
+            {
+                object = (LLViewerObject*) object->getParent();
+            }
+            while( object && !object->isAvatar() );
+        }
+        else if( !object->isAvatar() )
+        {
+            object = NULL;
+        }
+    }
 
-	return (LLVOAvatar*) object;
+    return (LLVOAvatar*) object;
 }
 
 
@@ -8952,13 +8952,13 @@ LLVOAvatar* find_avatar_from_object( LLViewerObject* object )
 // Returns NULL on failure.
 LLVOAvatar* find_avatar_from_object( const LLUUID& object_id )
 {
-	return find_avatar_from_object( gObjectList.findObject(object_id) );
+    return find_avatar_from_object( gObjectList.findObject(object_id) );
 }
 
 
 void handle_disconnect_viewer(void *)
 {
-	LLAppViewer::instance()->forceDisconnect(LLTrans::getString("TestingDisconnect"));
+    LLAppViewer::instance()->forceDisconnect(LLTrans::getString("TestingDisconnect"));
 }
 
 void force_error_breakpoint(void *)
@@ -9013,30 +9013,30 @@ void force_error_thread_crash(void *)
 
 class LLToolsUseSelectionForGrid : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLSelectMgr::getInstance()->clearGridObjects();
-		struct f : public LLSelectedObjectFunctor
-		{
-			virtual bool apply(LLViewerObject* objectp)
-			{
-				LLSelectMgr::getInstance()->addGridObject(objectp);
-				return true;
-			}
-		} func;
-		LLSelectMgr::getInstance()->getSelection()->applyToRootObjects(&func);
-		LLSelectMgr::getInstance()->setGridMode(GRID_MODE_REF_OBJECT);
-		LLFloaterTools::setGridMode((S32)GRID_MODE_REF_OBJECT);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLSelectMgr::getInstance()->clearGridObjects();
+        struct f : public LLSelectedObjectFunctor
+        {
+            virtual bool apply(LLViewerObject* objectp)
+            {
+                LLSelectMgr::getInstance()->addGridObject(objectp);
+                return true;
+            }
+        } func;
+        LLSelectMgr::getInstance()->getSelection()->applyToRootObjects(&func);
+        LLSelectMgr::getInstance()->setGridMode(GRID_MODE_REF_OBJECT);
+        LLFloaterTools::setGridMode((S32)GRID_MODE_REF_OBJECT);
+        return true;
+    }
 };
 
 void handle_test_load_url(void*)
 {
-	LLWeb::loadURL("");
-	LLWeb::loadURL("hacker://www.google.com/");
-	LLWeb::loadURL("http");
-	LLWeb::loadURL("http://www.google.com/");
+    LLWeb::loadURL("");
+    LLWeb::loadURL("hacker://www.google.com/");
+    LLWeb::loadURL("http");
+    LLWeb::loadURL("http://www.google.com/");
 }
 
 //
@@ -9050,86 +9050,86 @@ LLViewerMenuHolderGL::LLViewerMenuHolderGL(const LLViewerMenuHolderGL::Params& p
 
 BOOL LLViewerMenuHolderGL::hideMenus()
 {
-	BOOL handled = FALSE;
-	
-	if (LLMenuHolderGL::hideMenus())
-	{
-		handled = TRUE;
-	}
+    BOOL handled = FALSE;
 
-	// drop pie menu selection
-	mParcelSelection = NULL;
-	mObjectSelection = NULL;
+    if (LLMenuHolderGL::hideMenus())
+    {
+        handled = TRUE;
+    }
 
-	if (gMenuBarView)
-	{
-		gMenuBarView->clearHoverItem();
-		gMenuBarView->resetMenuTrigger();
-	}
+    // drop pie menu selection
+    mParcelSelection = NULL;
+    mObjectSelection = NULL;
+
+    if (gMenuBarView)
+    {
+        gMenuBarView->clearHoverItem();
+        gMenuBarView->resetMenuTrigger();
+    }
 
-	return handled;
+    return handled;
 }
 
-void LLViewerMenuHolderGL::setParcelSelection(LLSafeHandle<LLParcelSelection> selection) 
-{ 
-	mParcelSelection = selection; 
+void LLViewerMenuHolderGL::setParcelSelection(LLSafeHandle<LLParcelSelection> selection)
+{
+    mParcelSelection = selection;
 }
 
-void LLViewerMenuHolderGL::setObjectSelection(LLSafeHandle<LLObjectSelection> selection) 
-{ 
-	mObjectSelection = selection; 
+void LLViewerMenuHolderGL::setObjectSelection(LLSafeHandle<LLObjectSelection> selection)
+{
+    mObjectSelection = selection;
 }
 
 
 const LLRect LLViewerMenuHolderGL::getMenuRect() const
 {
-	return LLRect(0, getRect().getHeight() - MENU_BAR_HEIGHT, getRect().getWidth(), STATUS_BAR_HEIGHT);
+    return LLRect(0, getRect().getHeight() - MENU_BAR_HEIGHT, getRect().getWidth(), STATUS_BAR_HEIGHT);
 }
 
 void handle_web_browser_test(const LLSD& param)
 {
-	std::string url = param.asString();
-	if (url.empty())
-	{
-		url = "about:blank";
-	}
-	LLWeb::loadURLInternal(url);
+    std::string url = param.asString();
+    if (url.empty())
+    {
+        url = "about:blank";
+    }
+    LLWeb::loadURLInternal(url);
 }
 
 bool callback_clear_cache_immediately(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if ( option == 0 ) // YES
-	{
-		//clear cache
-		LLAppViewer::instance()->purgeCacheImmediate();
-	}
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if ( option == 0 ) // YES
+    {
+        //clear cache
+        LLAppViewer::instance()->purgeCacheImmediate();
+    }
 
-	return false;
+    return false;
 }
 
 void handle_cache_clear_immediately()
 {
-	LLNotificationsUtil::add("ConfirmClearCache", LLSD(), LLSD(), callback_clear_cache_immediately);
+    LLNotificationsUtil::add("ConfirmClearCache", LLSD(), LLSD(), callback_clear_cache_immediately);
 }
 
 void handle_web_content_test(const LLSD& param)
 {
-	std::string url = param.asString();
-	LLWeb::loadURLInternal(url, LLStringUtil::null, LLStringUtil::null, true);
+    std::string url = param.asString();
+    LLWeb::loadURLInternal(url, LLStringUtil::null, LLStringUtil::null, true);
 }
 
 void handle_show_url(const LLSD& param)
 {
-	std::string url = param.asString();
-	if (LLWeb::useExternalBrowser(url))
-	{
-		LLWeb::loadURLExternal(url);
-	}
-	else
-	{
-		LLWeb::loadURLInternal(url);
-	}
+    std::string url = param.asString();
+    if (LLWeb::useExternalBrowser(url))
+    {
+        LLWeb::loadURLExternal(url);
+    }
+    else
+    {
+        LLWeb::loadURLInternal(url);
+    }
 
 }
 
@@ -9141,427 +9141,427 @@ void handle_report_bug(const LLSD& param)
 
 void handle_buy_currency_test(void*)
 {
-	std::string url =
-		"http://sarahd-sl-13041.webdev.lindenlab.com/app/lindex/index.php?agent_id=[AGENT_ID]&secure_session_id=[SESSION_ID]&lang=[LANGUAGE]";
+    std::string url =
+        "http://sarahd-sl-13041.webdev.lindenlab.com/app/lindex/index.php?agent_id=[AGENT_ID]&secure_session_id=[SESSION_ID]&lang=[LANGUAGE]";
 
-	LLStringUtil::format_map_t replace;
-	replace["[AGENT_ID]"] = gAgent.getID().asString();
-	replace["[SESSION_ID]"] = gAgent.getSecureSessionID().asString();
-	replace["[LANGUAGE]"] = LLUI::getLanguage();
-	LLStringUtil::format(url, replace);
+    LLStringUtil::format_map_t replace;
+    replace["[AGENT_ID]"] = gAgent.getID().asString();
+    replace["[SESSION_ID]"] = gAgent.getSecureSessionID().asString();
+    replace["[LANGUAGE]"] = LLUI::getLanguage();
+    LLStringUtil::format(url, replace);
 
-	LL_INFOS() << "buy currency url " << url << LL_ENDL;
+    LL_INFOS() << "buy currency url " << url << LL_ENDL;
 
-	LLFloaterReg::showInstance("buy_currency_html", LLSD(url));
+    LLFloaterReg::showInstance("buy_currency_html", LLSD(url));
 }
 
 // SUNSHINE CLEANUP - is only the request update at the end needed now?
 void handle_rebake_textures(void*)
 {
-	if (!isAgentAvatarValid()) return;
+    if (!isAgentAvatarValid()) return;
 
-	// Slam pending upload count to "unstick" things
-	bool slam_for_debug = true;
-	gAgentAvatarp->forceBakeAllTextures(slam_for_debug);
-	if (gAgent.getRegion() && gAgent.getRegion()->getCentralBakeVersion())
-	{
+    // Slam pending upload count to "unstick" things
+    bool slam_for_debug = true;
+    gAgentAvatarp->forceBakeAllTextures(slam_for_debug);
+    if (gAgent.getRegion() && gAgent.getRegion()->getCentralBakeVersion())
+    {
 // [SL:KB] - Patch: Appearance-Misc | Checked: 2015-06-27 (Catznip-3.7)
-		LLAppearanceMgr::instance().syncCofVersionAndRefresh();
+        LLAppearanceMgr::instance().syncCofVersionAndRefresh();
 // [/SL:KB]
-		LLAppearanceMgr::instance().requestServerAppearanceUpdate();
-	}
+        LLAppearanceMgr::instance().requestServerAppearanceUpdate();
+    }
 }
 
 void toggle_visibility(void* user_data)
 {
-	LLView* viewp = (LLView*)user_data;
-	viewp->setVisible(!viewp->getVisible());
+    LLView* viewp = (LLView*)user_data;
+    viewp->setVisible(!viewp->getVisible());
 }
 
 BOOL get_visibility(void* user_data)
 {
-	LLView* viewp = (LLView*)user_data;
-	return viewp->getVisible();
+    LLView* viewp = (LLView*)user_data;
+    return viewp->getVisible();
 }
 
 class LLViewShowHoverTips : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gSavedSettings.setBOOL("ShowHoverTips", !gSavedSettings.getBOOL("ShowHoverTips"));
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gSavedSettings.setBOOL("ShowHoverTips", !gSavedSettings.getBOOL("ShowHoverTips"));
+        return true;
+    }
 };
 
 class LLViewCheckShowHoverTips : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = gSavedSettings.getBOOL("ShowHoverTips");
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = gSavedSettings.getBOOL("ShowHoverTips");
+        return new_value;
+    }
 };
 
 class LLViewHighlightTransparent : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-//		LLDrawPoolAlpha::sShowDebugAlpha = !LLDrawPoolAlpha::sShowDebugAlpha;
+    bool handleEvent(const LLSD& userdata)
+    {
+//      LLDrawPoolAlpha::sShowDebugAlpha = !LLDrawPoolAlpha::sShowDebugAlpha;
 // [RLVa:KB] - @edit and @viewtransparent
-		LLDrawPoolAlpha::sShowDebugAlpha = (!LLDrawPoolAlpha::sShowDebugAlpha) && (RlvActions::canHighlightTransparent());
+        LLDrawPoolAlpha::sShowDebugAlpha = (!LLDrawPoolAlpha::sShowDebugAlpha) && (RlvActions::canHighlightTransparent());
 // [/RLVa:KB]
         // invisible objects skip building their render batches unless sShowDebugAlpha is true, so rebuild batches whenever toggling this flag
-        gPipeline.rebuildDrawInfo(); 
-		return true;
-	}
+        gPipeline.rebuildDrawInfo();
+        return true;
+    }
 };
 
 class LLViewHighlightTransparentProbe : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		gSavedSettings.setBOOL("RenderReflectionProbeShowTransparent", !gSavedSettings.getBOOL("RenderReflectionProbeShowTransparent"));
-		// invisible objects skip building their render batches unless sShowDebugAlpha is true, so rebuild batches whenever toggling this flag
-		gPipeline.rebuildDrawInfo();
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        gSavedSettings.setBOOL("RenderReflectionProbeShowTransparent", !gSavedSettings.getBOOL("RenderReflectionProbeShowTransparent"));
+        // invisible objects skip building their render batches unless sShowDebugAlpha is true, so rebuild batches whenever toggling this flag
+        gPipeline.rebuildDrawInfo();
+        return true;
+    }
 };
 
 class LLViewCheckHighlightTransparent : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLDrawPoolAlpha::sShowDebugAlpha;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLDrawPoolAlpha::sShowDebugAlpha;
+        return new_value;
+    }
 };
 
 class LLViewBeaconWidth : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string width = userdata.asString();
-		if(width == "1")
-		{
-			gSavedSettings.setS32("DebugBeaconLineWidth", 1);
-		}
-		else if(width == "4")
-		{
-			gSavedSettings.setS32("DebugBeaconLineWidth", 4);
-		}
-		else if(width == "16")
-		{
-			gSavedSettings.setS32("DebugBeaconLineWidth", 16);
-		}
-		else if(width == "32")
-		{
-			gSavedSettings.setS32("DebugBeaconLineWidth", 32);
-		}
-
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string width = userdata.asString();
+        if(width == "1")
+        {
+            gSavedSettings.setS32("DebugBeaconLineWidth", 1);
+        }
+        else if(width == "4")
+        {
+            gSavedSettings.setS32("DebugBeaconLineWidth", 4);
+        }
+        else if(width == "16")
+        {
+            gSavedSettings.setS32("DebugBeaconLineWidth", 16);
+        }
+        else if(width == "32")
+        {
+            gSavedSettings.setS32("DebugBeaconLineWidth", 32);
+        }
+
+        return true;
+    }
 };
 
 
 class LLViewToggleBeacon : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string beacon = userdata.asString();
-		if (beacon == "scriptsbeacon")
-		{
-			LLPipeline::toggleRenderScriptedBeacons();
-			gSavedSettings.setBOOL( "scriptsbeacon", LLPipeline::getRenderScriptedBeacons() );
-			// toggle the other one off if it's on
-			if (LLPipeline::getRenderScriptedBeacons() && LLPipeline::getRenderScriptedTouchBeacons())
-			{
-				LLPipeline::toggleRenderScriptedTouchBeacons();
-				gSavedSettings.setBOOL( "scripttouchbeacon", LLPipeline::getRenderScriptedTouchBeacons() );
-			}
-		}
-		else if (beacon == "physicalbeacon")
-		{
-			LLPipeline::toggleRenderPhysicalBeacons();
-			gSavedSettings.setBOOL( "physicalbeacon", LLPipeline::getRenderPhysicalBeacons() );
-		}
-		else if (beacon == "moapbeacon")
-		{
-			LLPipeline::toggleRenderMOAPBeacons();
-			gSavedSettings.setBOOL( "moapbeacon", LLPipeline::getRenderMOAPBeacons() );
-		}
-		else if (beacon == "soundsbeacon")
-		{
-			LLPipeline::toggleRenderSoundBeacons();
-			gSavedSettings.setBOOL( "soundsbeacon", LLPipeline::getRenderSoundBeacons() );
-		}
-		else if (beacon == "particlesbeacon")
-		{
-			LLPipeline::toggleRenderParticleBeacons();
-			gSavedSettings.setBOOL( "particlesbeacon", LLPipeline::getRenderParticleBeacons() );
-		}
-		else if (beacon == "scripttouchbeacon")
-		{
-			LLPipeline::toggleRenderScriptedTouchBeacons();
-			gSavedSettings.setBOOL( "scripttouchbeacon", LLPipeline::getRenderScriptedTouchBeacons() );
-			// toggle the other one off if it's on
-			if (LLPipeline::getRenderScriptedBeacons() && LLPipeline::getRenderScriptedTouchBeacons())
-			{
-				LLPipeline::toggleRenderScriptedBeacons();
-				gSavedSettings.setBOOL( "scriptsbeacon", LLPipeline::getRenderScriptedBeacons() );
-			}
-		}
-		else if (beacon == "sunbeacon")
-		{
-			gSavedSettings.setBOOL("sunbeacon", !gSavedSettings.getBOOL("sunbeacon"));
-		}
-		else if (beacon == "moonbeacon")
-		{
-			gSavedSettings.setBOOL("moonbeacon", !gSavedSettings.getBOOL("moonbeacon"));
-		}
-		else if (beacon == "renderbeacons")
-		{
-			LLPipeline::toggleRenderBeacons();
-			gSavedSettings.setBOOL( "renderbeacons", LLPipeline::getRenderBeacons() );
-			// toggle the other one on if it's not
-			if (!LLPipeline::getRenderBeacons() && !LLPipeline::getRenderHighlights())
-			{
-				LLPipeline::toggleRenderHighlights();
-				gSavedSettings.setBOOL( "renderhighlights", LLPipeline::getRenderHighlights() );
-			}
-		}
-		else if (beacon == "renderhighlights")
-		{
-			LLPipeline::toggleRenderHighlights();
-			gSavedSettings.setBOOL( "renderhighlights", LLPipeline::getRenderHighlights() );
-			// toggle the other one on if it's not
-			if (!LLPipeline::getRenderBeacons() && !LLPipeline::getRenderHighlights())
-			{
-				LLPipeline::toggleRenderBeacons();
-				gSavedSettings.setBOOL( "renderbeacons", LLPipeline::getRenderBeacons() );
-			}
-		}
-
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string beacon = userdata.asString();
+        if (beacon == "scriptsbeacon")
+        {
+            LLPipeline::toggleRenderScriptedBeacons();
+            gSavedSettings.setBOOL( "scriptsbeacon", LLPipeline::getRenderScriptedBeacons() );
+            // toggle the other one off if it's on
+            if (LLPipeline::getRenderScriptedBeacons() && LLPipeline::getRenderScriptedTouchBeacons())
+            {
+                LLPipeline::toggleRenderScriptedTouchBeacons();
+                gSavedSettings.setBOOL( "scripttouchbeacon", LLPipeline::getRenderScriptedTouchBeacons() );
+            }
+        }
+        else if (beacon == "physicalbeacon")
+        {
+            LLPipeline::toggleRenderPhysicalBeacons();
+            gSavedSettings.setBOOL( "physicalbeacon", LLPipeline::getRenderPhysicalBeacons() );
+        }
+        else if (beacon == "moapbeacon")
+        {
+            LLPipeline::toggleRenderMOAPBeacons();
+            gSavedSettings.setBOOL( "moapbeacon", LLPipeline::getRenderMOAPBeacons() );
+        }
+        else if (beacon == "soundsbeacon")
+        {
+            LLPipeline::toggleRenderSoundBeacons();
+            gSavedSettings.setBOOL( "soundsbeacon", LLPipeline::getRenderSoundBeacons() );
+        }
+        else if (beacon == "particlesbeacon")
+        {
+            LLPipeline::toggleRenderParticleBeacons();
+            gSavedSettings.setBOOL( "particlesbeacon", LLPipeline::getRenderParticleBeacons() );
+        }
+        else if (beacon == "scripttouchbeacon")
+        {
+            LLPipeline::toggleRenderScriptedTouchBeacons();
+            gSavedSettings.setBOOL( "scripttouchbeacon", LLPipeline::getRenderScriptedTouchBeacons() );
+            // toggle the other one off if it's on
+            if (LLPipeline::getRenderScriptedBeacons() && LLPipeline::getRenderScriptedTouchBeacons())
+            {
+                LLPipeline::toggleRenderScriptedBeacons();
+                gSavedSettings.setBOOL( "scriptsbeacon", LLPipeline::getRenderScriptedBeacons() );
+            }
+        }
+        else if (beacon == "sunbeacon")
+        {
+            gSavedSettings.setBOOL("sunbeacon", !gSavedSettings.getBOOL("sunbeacon"));
+        }
+        else if (beacon == "moonbeacon")
+        {
+            gSavedSettings.setBOOL("moonbeacon", !gSavedSettings.getBOOL("moonbeacon"));
+        }
+        else if (beacon == "renderbeacons")
+        {
+            LLPipeline::toggleRenderBeacons();
+            gSavedSettings.setBOOL( "renderbeacons", LLPipeline::getRenderBeacons() );
+            // toggle the other one on if it's not
+            if (!LLPipeline::getRenderBeacons() && !LLPipeline::getRenderHighlights())
+            {
+                LLPipeline::toggleRenderHighlights();
+                gSavedSettings.setBOOL( "renderhighlights", LLPipeline::getRenderHighlights() );
+            }
+        }
+        else if (beacon == "renderhighlights")
+        {
+            LLPipeline::toggleRenderHighlights();
+            gSavedSettings.setBOOL( "renderhighlights", LLPipeline::getRenderHighlights() );
+            // toggle the other one on if it's not
+            if (!LLPipeline::getRenderBeacons() && !LLPipeline::getRenderHighlights())
+            {
+                LLPipeline::toggleRenderBeacons();
+                gSavedSettings.setBOOL( "renderbeacons", LLPipeline::getRenderBeacons() );
+            }
+        }
+
+        return true;
+    }
 };
 
 class LLViewCheckBeaconEnabled : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string beacon = userdata.asString();
-		bool new_value = false;
-		if (beacon == "scriptsbeacon")
-		{
-			new_value = gSavedSettings.getBOOL( "scriptsbeacon");
-			LLPipeline::setRenderScriptedBeacons(new_value);
-		}
-		else if (beacon == "moapbeacon")
-		{
-			new_value = gSavedSettings.getBOOL( "moapbeacon");
-			LLPipeline::setRenderMOAPBeacons(new_value);
-		}
-		else if (beacon == "physicalbeacon")
-		{
-			new_value = gSavedSettings.getBOOL( "physicalbeacon");
-			LLPipeline::setRenderPhysicalBeacons(new_value);
-		}
-		else if (beacon == "soundsbeacon")
-		{
-			new_value = gSavedSettings.getBOOL( "soundsbeacon");
-			LLPipeline::setRenderSoundBeacons(new_value);
-		}
-		else if (beacon == "particlesbeacon")
-		{
-			new_value = gSavedSettings.getBOOL( "particlesbeacon");
-			LLPipeline::setRenderParticleBeacons(new_value);
-		}
-		else if (beacon == "scripttouchbeacon")
-		{
-			new_value = gSavedSettings.getBOOL( "scripttouchbeacon");
-			LLPipeline::setRenderScriptedTouchBeacons(new_value);
-		}
-		else if (beacon == "renderbeacons")
-		{
-			new_value = gSavedSettings.getBOOL( "renderbeacons");
-			LLPipeline::setRenderBeacons(new_value);
-		}
-		else if (beacon == "renderhighlights")
-		{
-			new_value = gSavedSettings.getBOOL( "renderhighlights");
-			LLPipeline::setRenderHighlights(new_value);
-		}
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string beacon = userdata.asString();
+        bool new_value = false;
+        if (beacon == "scriptsbeacon")
+        {
+            new_value = gSavedSettings.getBOOL( "scriptsbeacon");
+            LLPipeline::setRenderScriptedBeacons(new_value);
+        }
+        else if (beacon == "moapbeacon")
+        {
+            new_value = gSavedSettings.getBOOL( "moapbeacon");
+            LLPipeline::setRenderMOAPBeacons(new_value);
+        }
+        else if (beacon == "physicalbeacon")
+        {
+            new_value = gSavedSettings.getBOOL( "physicalbeacon");
+            LLPipeline::setRenderPhysicalBeacons(new_value);
+        }
+        else if (beacon == "soundsbeacon")
+        {
+            new_value = gSavedSettings.getBOOL( "soundsbeacon");
+            LLPipeline::setRenderSoundBeacons(new_value);
+        }
+        else if (beacon == "particlesbeacon")
+        {
+            new_value = gSavedSettings.getBOOL( "particlesbeacon");
+            LLPipeline::setRenderParticleBeacons(new_value);
+        }
+        else if (beacon == "scripttouchbeacon")
+        {
+            new_value = gSavedSettings.getBOOL( "scripttouchbeacon");
+            LLPipeline::setRenderScriptedTouchBeacons(new_value);
+        }
+        else if (beacon == "renderbeacons")
+        {
+            new_value = gSavedSettings.getBOOL( "renderbeacons");
+            LLPipeline::setRenderBeacons(new_value);
+        }
+        else if (beacon == "renderhighlights")
+        {
+            new_value = gSavedSettings.getBOOL( "renderhighlights");
+            LLPipeline::setRenderHighlights(new_value);
+        }
+        return new_value;
+    }
 };
 
 class LLViewToggleRenderType : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string type = userdata.asString();
-		if (type == "hideparticles")
-		{
-			LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string type = userdata.asString();
+        if (type == "hideparticles")
+        {
+            LLPipeline::toggleRenderType(LLPipeline::RENDER_TYPE_PARTICLES);
+        }
+        return true;
+    }
 };
 
 class LLViewCheckRenderType : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string type = userdata.asString();
-		bool new_value = false;
-		if (type == "hideparticles")
-		{
-			new_value = LLPipeline::toggleRenderTypeControlNegated(LLPipeline::RENDER_TYPE_PARTICLES);
-		}
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string type = userdata.asString();
+        bool new_value = false;
+        if (type == "hideparticles")
+        {
+            new_value = LLPipeline::toggleRenderTypeControlNegated(LLPipeline::RENDER_TYPE_PARTICLES);
+        }
+        return new_value;
+    }
 };
 
 class LLViewStatusAway : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return (gAgent.isInitialized() && gAgent.getAFK());
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return (gAgent.isInitialized() && gAgent.getAFK());
+    }
 };
 
 class LLViewStatusDoNotDisturb : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		return (gAgent.isInitialized() && gAgent.isDoNotDisturb());
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        return (gAgent.isInitialized() && gAgent.isDoNotDisturb());
+    }
 };
 
 class LLViewShowHUDAttachments : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 // [RLVa:KB] - Checked: 2010-04-19 (RLVa-1.2.1a) | Modified: RLVa-1.0.0c
-		if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedHUD()) && (LLPipeline::sShowHUDAttachments) )
-			return true;
+        if ( (rlv_handler_t::isEnabled()) && (gRlvAttachmentLocks.hasLockedHUD()) && (LLPipeline::sShowHUDAttachments) )
+            return true;
 // [/RLVa:KB]
 
-		LLPipeline::sShowHUDAttachments = !LLPipeline::sShowHUDAttachments;
-		return true;
-	}
+        LLPipeline::sShowHUDAttachments = !LLPipeline::sShowHUDAttachments;
+        return true;
+    }
 };
 
 class LLViewCheckHUDAttachments : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool new_value = LLPipeline::sShowHUDAttachments;
-		return new_value;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool new_value = LLPipeline::sShowHUDAttachments;
+        return new_value;
+    }
 };
 
 class LLEditEnableTakeOff : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string clothing = userdata.asString();
-		LLWearableType::EType type = LLWearableType::getInstance()->typeNameToType(clothing);
-//		if (type >= LLWearableType::WT_SHAPE && type < LLWearableType::WT_COUNT)
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string clothing = userdata.asString();
+        LLWearableType::EType type = LLWearableType::getInstance()->typeNameToType(clothing);
+//      if (type >= LLWearableType::WT_SHAPE && type < LLWearableType::WT_COUNT)
 // [RLVa:KB] - Checked: 2010-03-20 (RLVa-1.2.0c) | Modified: RLVa-1.2.0a
-		// NOTE: see below - enable if there is at least one wearable on this type that can be removed
-		if ( (type >= LLWearableType::WT_SHAPE && type < LLWearableType::WT_COUNT) && 
-			 ((!rlv_handler_t::isEnabled()) || (gRlvWearableLocks.canRemove(type))) )
+        // NOTE: see below - enable if there is at least one wearable on this type that can be removed
+        if ( (type >= LLWearableType::WT_SHAPE && type < LLWearableType::WT_COUNT) &&
+             ((!rlv_handler_t::isEnabled()) || (gRlvWearableLocks.canRemove(type))) )
 // [/RLVa:KB]
-		{
-			return LLAgentWearables::selfHasWearable(type);
-		}
-		return false;
-	}
+        {
+            return LLAgentWearables::selfHasWearable(type);
+        }
+        return false;
+    }
 };
 
 class LLEditTakeOff : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string clothing = userdata.asString();
-		if (clothing == "all")
-			LLAppearanceMgr::instance().removeAllClothesFromAvatar();
-		else
-		{
-			LLWearableType::EType type = LLWearableType::getInstance()->typeNameToType(clothing);
-			if (type >= LLWearableType::WT_SHAPE 
-				&& type < LLWearableType::WT_COUNT
-				&& (gAgentWearables.getWearableCount(type) > 0))
-			{
-				// MULTI-WEARABLES: assuming user wanted to remove top shirt.
-				U32 wearable_index = gAgentWearables.getWearableCount(type) - 1;
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string clothing = userdata.asString();
+        if (clothing == "all")
+            LLAppearanceMgr::instance().removeAllClothesFromAvatar();
+        else
+        {
+            LLWearableType::EType type = LLWearableType::getInstance()->typeNameToType(clothing);
+            if (type >= LLWearableType::WT_SHAPE
+                && type < LLWearableType::WT_COUNT
+                && (gAgentWearables.getWearableCount(type) > 0))
+            {
+                // MULTI-WEARABLES: assuming user wanted to remove top shirt.
+                U32 wearable_index = gAgentWearables.getWearableCount(type) - 1;
 
 // [RLVa:KB] - Checked: 2010-06-09 (RLVa-1.2.0g) | Added: RLVa-1.2.0g
-				if ( (rlv_handler_t::isEnabled()) && (gRlvWearableLocks.hasLockedWearable(type)) )
-				{
-					// We'll use the first wearable we come across that can be removed (moving from top to bottom)
-					for (; wearable_index >= 0; wearable_index--)
-					{
-						const LLViewerWearable* pWearable = gAgentWearables.getViewerWearable(type, wearable_index);
-						if (!gRlvWearableLocks.isLockedWearable(pWearable))
-							break;
-					}
-					if (wearable_index < 0)
-						return true;	// No wearable found that can be removed
-				}
+                if ( (rlv_handler_t::isEnabled()) && (gRlvWearableLocks.hasLockedWearable(type)) )
+                {
+                    // We'll use the first wearable we come across that can be removed (moving from top to bottom)
+                    for (; wearable_index >= 0; wearable_index--)
+                    {
+                        const LLViewerWearable* pWearable = gAgentWearables.getViewerWearable(type, wearable_index);
+                        if (!gRlvWearableLocks.isLockedWearable(pWearable))
+                            break;
+                    }
+                    if (wearable_index < 0)
+                        return true;    // No wearable found that can be removed
+                }
 // [/RLVa:KB]
 
-				LLUUID item_id = gAgentWearables.getWearableItemID(type,wearable_index);
-				LLAppearanceMgr::instance().removeItemFromAvatar(item_id);
-			}
-				
-		}
-		return true;
-	}
+                LLUUID item_id = gAgentWearables.getWearableItemID(type,wearable_index);
+                LLAppearanceMgr::instance().removeItemFromAvatar(item_id);
+            }
+
+        }
+        return true;
+    }
 };
 
 class LLToolsSelectTool : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string tool_name = userdata.asString();
-		if (tool_name == "focus")
-		{
-			LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(1);
-		}
-		else if (tool_name == "move")
-		{
-			LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(2);
-		}
-		else if (tool_name == "edit")
-		{
-			LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(3);
-		}
-		else if (tool_name == "create")
-		{
-			LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(4);
-		}
-		else if (tool_name == "land")
-		{
-			LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(5);
-		}
-
-		// Note: if floater is not visible LLViewerWindow::updateLayout() will
-		// attempt to open it, but it won't bring it to front or de-minimize.
-		if (gFloaterTools && (gFloaterTools->isMinimized() || !gFloaterTools->isShown() || !gFloaterTools->isFrontmost()))
-		{
-			gFloaterTools->setMinimized(FALSE);
-			gFloaterTools->openFloater();
-			gFloaterTools->setVisibleAndFrontmost(TRUE);
-		}
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string tool_name = userdata.asString();
+        if (tool_name == "focus")
+        {
+            LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(1);
+        }
+        else if (tool_name == "move")
+        {
+            LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(2);
+        }
+        else if (tool_name == "edit")
+        {
+            LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(3);
+        }
+        else if (tool_name == "create")
+        {
+            LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(4);
+        }
+        else if (tool_name == "land")
+        {
+            LLToolMgr::getInstance()->getCurrentToolset()->selectToolByIndex(5);
+        }
+
+        // Note: if floater is not visible LLViewerWindow::updateLayout() will
+        // attempt to open it, but it won't bring it to front or de-minimize.
+        if (gFloaterTools && (gFloaterTools->isMinimized() || !gFloaterTools->isShown() || !gFloaterTools->isFrontmost()))
+        {
+            gFloaterTools->setMinimized(FALSE);
+            gFloaterTools->openFloater();
+            gFloaterTools->setVisibleAndFrontmost(TRUE);
+        }
+        return true;
+    }
 };
 
 /// WINDLIGHT callbacks
 class LLWorldEnvSettings : public view_listener_t
-{	
+{
     void defocusEnvFloaters()
     {
         //currently there is only one instance of each floater
@@ -9576,185 +9576,185 @@ class LLWorldEnvSettings : public view_listener_t
         }
     }
 
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 // [RLVa:KB] - @setenv
-		if (!RlvActions::canChangeEnvironment())
-			return true;
+        if (!RlvActions::canChangeEnvironment())
+            return true;
 // [/RLVa:KB]
 
-		std::string event_name = userdata.asString();
-		
-		if (event_name == "sunrise")
-		{
+        std::string event_name = userdata.asString();
+
+        if (event_name == "sunrise")
+        {
             LLEnvironment::instance().setEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::KNOWN_SKY_SUNRISE, LLEnvironment::TRANSITION_INSTANT);
             LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::TRANSITION_INSTANT);
             defocusEnvFloaters();
-		}
-		else if (event_name == "noon")
-		{
+        }
+        else if (event_name == "noon")
+        {
             LLEnvironment::instance().setEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::KNOWN_SKY_MIDDAY, LLEnvironment::TRANSITION_INSTANT);
             LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::TRANSITION_INSTANT);
             defocusEnvFloaters();
-		}
+        }
         else if (event_name == "legacy noon")
         {
             LLEnvironment::instance().setEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::KNOWN_SKY_LEGACY_MIDDAY, LLEnvironment::TRANSITION_INSTANT);
             LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::TRANSITION_INSTANT);
             defocusEnvFloaters();
         }
-		else if (event_name == "sunset")
-		{
+        else if (event_name == "sunset")
+        {
             LLEnvironment::instance().setEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::KNOWN_SKY_SUNSET, LLEnvironment::TRANSITION_INSTANT);
             LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::TRANSITION_INSTANT);
             defocusEnvFloaters();
-		}
-		else if (event_name == "midnight")
-		{
+        }
+        else if (event_name == "midnight")
+        {
             LLEnvironment::instance().setEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::KNOWN_SKY_MIDNIGHT, LLEnvironment::TRANSITION_INSTANT);
             LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::TRANSITION_INSTANT);
             defocusEnvFloaters();
-		}
+        }
         else if (event_name == "region")
-		{
+        {
             // reset probe data when reverting back to region sky setting
             gPipeline.mReflectionMapManager.reset();
 
             LLEnvironment::instance().clearEnvironment(LLEnvironment::ENV_LOCAL);
             LLEnvironment::instance().setSelectedEnvironment(LLEnvironment::ENV_LOCAL, LLEnvironment::TRANSITION_INSTANT);
             defocusEnvFloaters();
-		}
+        }
         else if (event_name == "pause_clouds")
         {
             if (LLEnvironment::instance().isCloudScrollPaused())
                 LLEnvironment::instance().resumeCloudScroll();
-		else
+        else
                 LLEnvironment::instance().pauseCloudScroll();
         }
         else if (event_name == "adjust_tool")
-		{
+        {
             LLFloaterReg::showInstance("env_adjust_snapshot");
         }
         else if (event_name == "my_environs")
         {
             LLFloaterReg::showInstance("my_environments");
-		}
+        }
 
-		return true;
-	}
+        return true;
+    }
 };
 
 class LLWorldEnableEnvSettings : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool result = false;
-		std::string event_name = userdata.asString();
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool result = false;
+        std::string event_name = userdata.asString();
 
         if (event_name == "pause_clouds")
-		{
+        {
             return LLEnvironment::instance().isCloudScrollPaused();
-		}
+        }
 
         LLSettingsSky::ptr_t sky = LLEnvironment::instance().getEnvironmentFixedSky(LLEnvironment::ENV_LOCAL);
 
-		if (!sky)
-		{
-			return (event_name == "region");
-		}
+        if (!sky)
+        {
+            return (event_name == "region");
+        }
 
         std::string skyname = (sky) ? sky->getName() : "";
         LLUUID skyid = (sky) ? sky->getAssetId() : LLUUID::null;
 
-		if (event_name == "sunrise")
-			{
+        if (event_name == "sunrise")
+            {
             result = (skyid == LLEnvironment::KNOWN_SKY_SUNRISE);
-			}
-		else if (event_name == "noon")
-			{
+            }
+        else if (event_name == "noon")
+            {
             result = (skyid == LLEnvironment::KNOWN_SKY_MIDDAY);
-			}
+            }
         else if (event_name == "legacy noon")
         {
             result = (skyid == LLEnvironment::KNOWN_SKY_LEGACY_MIDDAY);
         }
-		else if (event_name == "sunset")
-			{
+        else if (event_name == "sunset")
+            {
             result = (skyid == LLEnvironment::KNOWN_SKY_SUNSET);
-			}
-		else if (event_name == "midnight")
-			{
+            }
+        else if (event_name == "midnight")
+            {
             result = (skyid == LLEnvironment::KNOWN_SKY_MIDNIGHT);
-			}
-		else if (event_name == "region")
-			{
-				return false;
-			}
-			else
-			{
-			LL_WARNS() << "Unknown time-of-day item:  " << event_name << LL_ENDL;
-		}
-		return result;
-	}
+            }
+        else if (event_name == "region")
+            {
+                return false;
+            }
+            else
+            {
+            LL_WARNS() << "Unknown time-of-day item:  " << event_name << LL_ENDL;
+        }
+        return result;
+    }
 };
 
 class LLWorldEnvPreset : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::string item = userdata.asString();
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::string item = userdata.asString();
 
-		if (item == "new_water")
-		{
+        if (item == "new_water")
+        {
             LLFloaterReg::showInstance("env_fixed_environmentent_water", "new");
-		}
-		else if (item == "edit_water")
-		{
+        }
+        else if (item == "edit_water")
+        {
             LLFloaterReg::showInstance("env_fixed_environmentent_water", "edit");
-		}
-		else if (item == "new_sky")
-		{
+        }
+        else if (item == "new_sky")
+        {
             LLFloaterReg::showInstance("env_fixed_environmentent_sky", "new");
-		}
-		else if (item == "edit_sky")
-		{
+        }
+        else if (item == "edit_sky")
+        {
             LLFloaterReg::showInstance("env_fixed_environmentent_sky", "edit");
-		}
-		else if (item == "new_day_cycle")
-		{
+        }
+        else if (item == "new_day_cycle")
+        {
+            LLFloaterReg::showInstance("env_edit_extdaycycle", LLSDMap("edit_context", "inventory"));
+        }
+        else if (item == "edit_day_cycle")
+        {
             LLFloaterReg::showInstance("env_edit_extdaycycle", LLSDMap("edit_context", "inventory"));
-		}
-		else if (item == "edit_day_cycle")
-		{
-			LLFloaterReg::showInstance("env_edit_extdaycycle", LLSDMap("edit_context", "inventory"));
-		}
-		else
-		{
-			LL_WARNS() << "Unknown item selected" << LL_ENDL;
-		}
+        }
+        else
+        {
+            LL_WARNS() << "Unknown item selected" << LL_ENDL;
+        }
 
-		return true;
-	}
+        return true;
+    }
 };
 
 class LLWorldEnableEnvPreset : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
+    bool handleEvent(const LLSD& userdata)
+    {
 
-		return false;
-	}
+        return false;
+    }
 };
 
 
 /// Post-Process callbacks
 class LLWorldPostProcess : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		LLFloaterReg::showInstance("env_post_process");
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        LLFloaterReg::showInstance("env_post_process");
+        return true;
+    }
 };
 
 class LLWorldCheckBanLines : public view_listener_t
@@ -9778,734 +9778,734 @@ class LLWorldShowBanLines : public view_listener_t
 
 void handle_flush_name_caches()
 {
-	if (gCacheName) gCacheName->clear();
+    if (gCacheName) gCacheName->clear();
 }
 
 class LLUploadCostCalculator : public view_listener_t
 {
-	std::string mCostStr;
-
-	bool handleEvent(const LLSD& userdata)
-	{
-		std::vector<std::string> fields;
-		std::string str = userdata.asString(); 
-		boost::split(fields, str, boost::is_any_of(","));
-		if (fields.size()<1)
-		{
-			return false;
-		}
-		std::string menu_name = fields[0];
-		std::string asset_type_str = "texture";
-		if (fields.size()>1)
-		{
-			asset_type_str = fields[1];
-		}
-		LL_DEBUGS("Benefits") << "userdata " << userdata << " menu_name " << menu_name << " asset_type_str " << asset_type_str << LL_ENDL;
-		calculateCost(asset_type_str);
-		gMenuHolder->childSetLabelArg(menu_name, "[COST]", mCostStr);
-
-		return true;
-	}
-
-	void calculateCost(const std::string& asset_type_str);
+    std::string mCostStr;
+
+    bool handleEvent(const LLSD& userdata)
+    {
+        std::vector<std::string> fields;
+        std::string str = userdata.asString();
+        boost::split(fields, str, boost::is_any_of(","));
+        if (fields.size()<1)
+        {
+            return false;
+        }
+        std::string menu_name = fields[0];
+        std::string asset_type_str = "texture";
+        if (fields.size()>1)
+        {
+            asset_type_str = fields[1];
+        }
+        LL_DEBUGS("Benefits") << "userdata " << userdata << " menu_name " << menu_name << " asset_type_str " << asset_type_str << LL_ENDL;
+        calculateCost(asset_type_str);
+        gMenuHolder->childSetLabelArg(menu_name, "[COST]", mCostStr);
+
+        return true;
+    }
+
+    void calculateCost(const std::string& asset_type_str);
 
 public:
-	LLUploadCostCalculator()
-	{
-	}
+    LLUploadCostCalculator()
+    {
+    }
 };
 
 class LLUpdateMembershipLabel : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		const std::string label_str =  LLAgentBenefitsMgr::isCurrent("Base") ? LLTrans::getString("MembershipUpgradeText") : LLTrans::getString("MembershipPremiumText");
-		gMenuHolder->childSetLabelArg("Membership", "[Membership]", label_str);
+    bool handleEvent(const LLSD& userdata)
+    {
+        const std::string label_str =  LLAgentBenefitsMgr::isCurrent("Base") ? LLTrans::getString("MembershipUpgradeText") : LLTrans::getString("MembershipPremiumText");
+        gMenuHolder->childSetLabelArg("Membership", "[Membership]", label_str);
 
-		return true;
-	}
+        return true;
+    }
 };
 
 void handle_voice_morphing_subscribe()
 {
-	LLWeb::loadURL(LLTrans::getString("voice_morphing_url"));
+    LLWeb::loadURL(LLTrans::getString("voice_morphing_url"));
 }
 
 void handle_premium_voice_morphing_subscribe()
 {
-	LLWeb::loadURL(LLTrans::getString("premium_voice_morphing_url"));
+    LLWeb::loadURL(LLTrans::getString("premium_voice_morphing_url"));
 }
 
 class LLToggleUIHints : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata)
-	{
-		bool ui_hints_enabled = gSavedSettings.getBOOL("EnableUIHints");
-		// toggle
-		ui_hints_enabled = !ui_hints_enabled;
-		gSavedSettings.setBOOL("EnableUIHints", ui_hints_enabled);
-		return true;
-	}
+    bool handleEvent(const LLSD& userdata)
+    {
+        bool ui_hints_enabled = gSavedSettings.getBOOL("EnableUIHints");
+        // toggle
+        ui_hints_enabled = !ui_hints_enabled;
+        gSavedSettings.setBOOL("EnableUIHints", ui_hints_enabled);
+        return true;
+    }
 };
 
 void LLUploadCostCalculator::calculateCost(const std::string& asset_type_str)
 {
-	S32 upload_cost = -1;
+    S32 upload_cost = -1;
 
-	if (asset_type_str == "texture")
-	{
+    if (asset_type_str == "texture")
+    {
         // This use minimal texture cost to allow bulk and
         // texture upload menu options to be visible
-		upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost();
-	}
-	else if (asset_type_str == "animation")
-	{
-		upload_cost = LLAgentBenefitsMgr::current().getAnimationUploadCost();
-	}
-	else if (asset_type_str == "sound")
-	{
-		upload_cost = LLAgentBenefitsMgr::current().getSoundUploadCost();
-	}
-	if (upload_cost < 0)
-	{
-		LL_WARNS() << "Unable to find upload cost for asset_type_str " << asset_type_str << LL_ENDL;
-	}
-	mCostStr = fmt::to_string(upload_cost);
+        upload_cost = LLAgentBenefitsMgr::current().getTextureUploadCost();
+    }
+    else if (asset_type_str == "animation")
+    {
+        upload_cost = LLAgentBenefitsMgr::current().getAnimationUploadCost();
+    }
+    else if (asset_type_str == "sound")
+    {
+        upload_cost = LLAgentBenefitsMgr::current().getSoundUploadCost();
+    }
+    if (upload_cost < 0)
+    {
+        LL_WARNS() << "Unable to find upload cost for asset_type_str " << asset_type_str << LL_ENDL;
+    }
+    mCostStr = fmt::to_string(upload_cost);
 }
 
 void show_navbar_context_menu(LLView* ctrl, S32 x, S32 y)
 {
-	static LLMenuGL*	show_navbar_context_menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_hide_navbar.xml",
-			gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
-	if(gMenuHolder->hasVisibleMenu())
-	{
-		gMenuHolder->hideMenus();
-	}
-	show_navbar_context_menu->buildDrawLabels();
-	show_navbar_context_menu->updateParent(LLMenuGL::sMenuContainer);
-	LLMenuGL::showPopup(ctrl, show_navbar_context_menu, x, y);
+    static LLMenuGL*    show_navbar_context_menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_hide_navbar.xml",
+            gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+    if(gMenuHolder->hasVisibleMenu())
+    {
+        gMenuHolder->hideMenus();
+    }
+    show_navbar_context_menu->buildDrawLabels();
+    show_navbar_context_menu->updateParent(LLMenuGL::sMenuContainer);
+    LLMenuGL::showPopup(ctrl, show_navbar_context_menu, x, y);
 }
 
 void show_topinfobar_context_menu(LLView* ctrl, S32 x, S32 y)
 {
-	static LLMenuGL* show_topbarinfo_context_menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_topinfobar.xml",
-			gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
-
-	LLMenuItemGL* landmark_item = show_topbarinfo_context_menu->getChild<LLMenuItemGL>("Landmark");
-	if (!LLLandmarkActions::landmarkAlreadyExists())
-	{
-		landmark_item->setLabel(LLTrans::getString("AddLandmarkNavBarMenu"));
-	}
-	else
-	{
-		landmark_item->setLabel(LLTrans::getString("EditLandmarkNavBarMenu"));
-	}
+    static LLMenuGL* show_topbarinfo_context_menu = LLUICtrlFactory::getInstance()->createFromFile<LLMenuGL>("menu_topinfobar.xml",
+            gMenuHolder, LLViewerMenuHolderGL::child_registry_t::instance());
+
+    LLMenuItemGL* landmark_item = show_topbarinfo_context_menu->getChild<LLMenuItemGL>("Landmark");
+    if (!LLLandmarkActions::landmarkAlreadyExists())
+    {
+        landmark_item->setLabel(LLTrans::getString("AddLandmarkNavBarMenu"));
+    }
+    else
+    {
+        landmark_item->setLabel(LLTrans::getString("EditLandmarkNavBarMenu"));
+    }
 // [RLVa:KB] - Checked: 2012-02-07 (RLVa-1.4.5) | Added: RLVa-1.4.5
-	landmark_item->setEnabled(!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC));
+    landmark_item->setEnabled(!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC));
 // [/RLVa:KB]
 
-	if(gMenuHolder->hasVisibleMenu())
-	{
-		gMenuHolder->hideMenus();
-	}
+    if(gMenuHolder->hasVisibleMenu())
+    {
+        gMenuHolder->hideMenus();
+    }
 
-	show_topbarinfo_context_menu->buildDrawLabels();
-	show_topbarinfo_context_menu->updateParent(LLMenuGL::sMenuContainer);
-	LLMenuGL::showPopup(ctrl, show_topbarinfo_context_menu, x, y);
+    show_topbarinfo_context_menu->buildDrawLabels();
+    show_topbarinfo_context_menu->updateParent(LLMenuGL::sMenuContainer);
+    LLMenuGL::showPopup(ctrl, show_topbarinfo_context_menu, x, y);
 }
 
 namespace
 {
-	bool always_disable_menu()
-	{
-		return false;
-	}
+    bool always_disable_menu()
+    {
+        return false;
+    }
 }
 
 void initialize_edit_menu()
 {
-	view_listener_t::addMenu(new LLEditUndo(), "Edit.Undo");
-	view_listener_t::addMenu(new LLEditRedo(), "Edit.Redo");
-	view_listener_t::addMenu(new LLEditCut(), "Edit.Cut");
-	view_listener_t::addMenu(new LLEditCopy(), "Edit.Copy");
-	view_listener_t::addMenu(new LLEditPaste(), "Edit.Paste");
-	view_listener_t::addMenu(new LLEditDelete(), "Edit.Delete");
-	view_listener_t::addMenu(new LLEditSelectAll(), "Edit.SelectAll");
-	view_listener_t::addMenu(new LLEditDeselect(), "Edit.Deselect");
-	view_listener_t::addMenu(new LLEditTakeOff(), "Edit.TakeOff");
-	view_listener_t::addMenu(new LLEditEnableUndo(), "Edit.EnableUndo");
-	view_listener_t::addMenu(new LLEditEnableRedo(), "Edit.EnableRedo");
-	view_listener_t::addMenu(new LLEditEnableCut(), "Edit.EnableCut");
-	view_listener_t::addMenu(new LLEditEnableCopy(), "Edit.EnableCopy");
-	view_listener_t::addMenu(new LLEditEnablePaste(), "Edit.EnablePaste");
-	view_listener_t::addMenu(new LLEditEnableDelete(), "Edit.EnableDelete");
-	view_listener_t::addMenu(new LLEditEnableSelectAll(), "Edit.EnableSelectAll");
-	view_listener_t::addMenu(new LLEditEnableDeselect(), "Edit.EnableDeselect");
+    view_listener_t::addMenu(new LLEditUndo(), "Edit.Undo");
+    view_listener_t::addMenu(new LLEditRedo(), "Edit.Redo");
+    view_listener_t::addMenu(new LLEditCut(), "Edit.Cut");
+    view_listener_t::addMenu(new LLEditCopy(), "Edit.Copy");
+    view_listener_t::addMenu(new LLEditPaste(), "Edit.Paste");
+    view_listener_t::addMenu(new LLEditDelete(), "Edit.Delete");
+    view_listener_t::addMenu(new LLEditSelectAll(), "Edit.SelectAll");
+    view_listener_t::addMenu(new LLEditDeselect(), "Edit.Deselect");
+    view_listener_t::addMenu(new LLEditTakeOff(), "Edit.TakeOff");
+    view_listener_t::addMenu(new LLEditEnableUndo(), "Edit.EnableUndo");
+    view_listener_t::addMenu(new LLEditEnableRedo(), "Edit.EnableRedo");
+    view_listener_t::addMenu(new LLEditEnableCut(), "Edit.EnableCut");
+    view_listener_t::addMenu(new LLEditEnableCopy(), "Edit.EnableCopy");
+    view_listener_t::addMenu(new LLEditEnablePaste(), "Edit.EnablePaste");
+    view_listener_t::addMenu(new LLEditEnableDelete(), "Edit.EnableDelete");
+    view_listener_t::addMenu(new LLEditEnableSelectAll(), "Edit.EnableSelectAll");
+    view_listener_t::addMenu(new LLEditEnableDeselect(), "Edit.EnableDeselect");
 
 }
 
 void initialize_spellcheck_menu()
 {
-	LLUICtrl::CommitCallbackRegistry::Registrar& commit = LLUICtrl::CommitCallbackRegistry::currentRegistrar();
-	LLUICtrl::EnableCallbackRegistry::Registrar& enable = LLUICtrl::EnableCallbackRegistry::currentRegistrar();
+    LLUICtrl::CommitCallbackRegistry::Registrar& commit = LLUICtrl::CommitCallbackRegistry::currentRegistrar();
+    LLUICtrl::EnableCallbackRegistry::Registrar& enable = LLUICtrl::EnableCallbackRegistry::currentRegistrar();
 
-	commit.add("SpellCheck.ReplaceWithSuggestion", boost::bind(&handle_spellcheck_replace_with_suggestion, _1, _2));
-	enable.add("SpellCheck.VisibleSuggestion", boost::bind(&visible_spellcheck_suggestion, _1, _2));
-	commit.add("SpellCheck.AddToDictionary", boost::bind(&handle_spellcheck_add_to_dictionary, _1));
-	enable.add("SpellCheck.EnableAddToDictionary", boost::bind(&enable_spellcheck_add_to_dictionary, _1));
-	commit.add("SpellCheck.AddToIgnore", boost::bind(&handle_spellcheck_add_to_ignore, _1));
-	enable.add("SpellCheck.EnableAddToIgnore", boost::bind(&enable_spellcheck_add_to_ignore, _1));
+    commit.add("SpellCheck.ReplaceWithSuggestion", boost::bind(&handle_spellcheck_replace_with_suggestion, _1, _2));
+    enable.add("SpellCheck.VisibleSuggestion", boost::bind(&visible_spellcheck_suggestion, _1, _2));
+    commit.add("SpellCheck.AddToDictionary", boost::bind(&handle_spellcheck_add_to_dictionary, _1));
+    enable.add("SpellCheck.EnableAddToDictionary", boost::bind(&enable_spellcheck_add_to_dictionary, _1));
+    commit.add("SpellCheck.AddToIgnore", boost::bind(&handle_spellcheck_add_to_ignore, _1));
+    enable.add("SpellCheck.EnableAddToIgnore", boost::bind(&enable_spellcheck_add_to_ignore, _1));
 }
 
 void initialize_menus()
 {
-	// A parameterized event handler used as ctrl-8/9/0 zoom controls below.
-	class LLZoomer : public view_listener_t
-	{
-	public:
-		// The "mult" parameter says whether "val" is a multiplier or used to set the value.
-		LLZoomer(F32 val, bool mult=true) : mVal(val), mMult(mult) {}
-		bool handleEvent(const LLSD& userdata)
-		{
-			F32 new_fov_rad = mMult ? LLViewerCamera::getInstance()->getDefaultFOV() * mVal : mVal;
-			LLViewerCamera::getInstance()->setDefaultFOV(new_fov_rad);
-			gSavedSettings.setF32("CameraAngle", LLViewerCamera::getInstance()->getView()); // setView may have clamped it.
-			return true;
-		}
-	private:
-		F32 mVal;
-		bool mMult;
-	};
-	
-	LLUICtrl::EnableCallbackRegistry::Registrar& enable = LLUICtrl::EnableCallbackRegistry::currentRegistrar();
-	LLUICtrl::CommitCallbackRegistry::Registrar& commit = LLUICtrl::CommitCallbackRegistry::currentRegistrar();
-	
-	// Generic enable and visible
-	// Don't prepend MenuName.Foo because these can be used in any menu.
-	enable.add("IsGodCustomerService", boost::bind(&is_god_customer_service));
+    // A parameterized event handler used as ctrl-8/9/0 zoom controls below.
+    class LLZoomer : public view_listener_t
+    {
+    public:
+        // The "mult" parameter says whether "val" is a multiplier or used to set the value.
+        LLZoomer(F32 val, bool mult=true) : mVal(val), mMult(mult) {}
+        bool handleEvent(const LLSD& userdata)
+        {
+            F32 new_fov_rad = mMult ? LLViewerCamera::getInstance()->getDefaultFOV() * mVal : mVal;
+            LLViewerCamera::getInstance()->setDefaultFOV(new_fov_rad);
+            gSavedSettings.setF32("CameraAngle", LLViewerCamera::getInstance()->getView()); // setView may have clamped it.
+            return true;
+        }
+    private:
+        F32 mVal;
+        bool mMult;
+    };
+
+    LLUICtrl::EnableCallbackRegistry::Registrar& enable = LLUICtrl::EnableCallbackRegistry::currentRegistrar();
+    LLUICtrl::CommitCallbackRegistry::Registrar& commit = LLUICtrl::CommitCallbackRegistry::currentRegistrar();
+
+    // Generic enable and visible
+    // Don't prepend MenuName.Foo because these can be used in any menu.
+    enable.add("IsGodCustomerService", boost::bind(&is_god_customer_service));
 
 #if AL_VIEWER_EVENT_RECORDER
-	enable.add("displayViewerEventRecorderMenuItems",boost::bind(&LLViewerEventRecorder::displayViewerEventRecorderMenuItems,&LLViewerEventRecorder::instance()));
+    enable.add("displayViewerEventRecorderMenuItems",boost::bind(&LLViewerEventRecorder::displayViewerEventRecorderMenuItems,&LLViewerEventRecorder::instance()));
 #else
-	enable.add("displayViewerEventRecorderMenuItems", boost::bind(&always_disable_menu));
+    enable.add("displayViewerEventRecorderMenuItems", boost::bind(&always_disable_menu));
 #endif
 
-	view_listener_t::addEnable(new LLUploadCostCalculator(), "Upload.CalculateCosts");
+    view_listener_t::addEnable(new LLUploadCostCalculator(), "Upload.CalculateCosts");
 
-	view_listener_t::addEnable(new LLUpdateMembershipLabel(), "Membership.UpdateLabel");
+    view_listener_t::addEnable(new LLUpdateMembershipLabel(), "Membership.UpdateLabel");
 
-	enable.add("Conversation.IsConversationLoggingAllowed", boost::bind(&LLFloaterIMContainer::isConversationLoggingAllowed));
+    enable.add("Conversation.IsConversationLoggingAllowed", boost::bind(&LLFloaterIMContainer::isConversationLoggingAllowed));
 
-	// Agent
-	commit.add("Agent.toggleFlying", boost::bind(&LLAgent::toggleFlying));
-	enable.add("Agent.enableFlyLand", boost::bind(&enable_fly_land));
-	commit.add("Agent.PressMicrophone", boost::bind(&LLAgent::pressMicrophone, _2));
-	commit.add("Agent.ReleaseMicrophone", boost::bind(&LLAgent::releaseMicrophone, _2));
-	commit.add("Agent.ToggleMicrophone", boost::bind(&LLAgent::toggleMicrophone, _2));
-	enable.add("Agent.IsMicrophoneOn", boost::bind(&LLAgent::isMicrophoneOn, _2));
-	enable.add("Agent.IsActionAllowed", boost::bind(&LLAgent::isActionAllowed, _2));
+    // Agent
+    commit.add("Agent.toggleFlying", boost::bind(&LLAgent::toggleFlying));
+    enable.add("Agent.enableFlyLand", boost::bind(&enable_fly_land));
+    commit.add("Agent.PressMicrophone", boost::bind(&LLAgent::pressMicrophone, _2));
+    commit.add("Agent.ReleaseMicrophone", boost::bind(&LLAgent::releaseMicrophone, _2));
+    commit.add("Agent.ToggleMicrophone", boost::bind(&LLAgent::toggleMicrophone, _2));
+    enable.add("Agent.IsMicrophoneOn", boost::bind(&LLAgent::isMicrophoneOn, _2));
+    enable.add("Agent.IsActionAllowed", boost::bind(&LLAgent::isActionAllowed, _2));
 
-	// File menu
-	init_menu_file();
+    // File menu
+    init_menu_file();
 
-	view_listener_t::addMenu(new LLEditEnableTakeOff(), "Edit.EnableTakeOff");
-	view_listener_t::addMenu(new LLEditEnableCustomizeAvatar(), "Edit.EnableCustomizeAvatar");
-	view_listener_t::addMenu(new LLEnableEditShape(), "Edit.EnableEditShape");
-	view_listener_t::addMenu(new LLEnableHoverHeight(), "Edit.EnableHoverHeight");
-	view_listener_t::addMenu(new LLEnableEditPhysics(), "Edit.EnableEditPhysics");
-	commit.add("CustomizeAvatar", boost::bind(&handle_customize_avatar));
+    view_listener_t::addMenu(new LLEditEnableTakeOff(), "Edit.EnableTakeOff");
+    view_listener_t::addMenu(new LLEditEnableCustomizeAvatar(), "Edit.EnableCustomizeAvatar");
+    view_listener_t::addMenu(new LLEnableEditShape(), "Edit.EnableEditShape");
+    view_listener_t::addMenu(new LLEnableHoverHeight(), "Edit.EnableHoverHeight");
+    view_listener_t::addMenu(new LLEnableEditPhysics(), "Edit.EnableEditPhysics");
+    commit.add("CustomizeAvatar", boost::bind(&handle_customize_avatar));
     commit.add("NowWearing", boost::bind(&handle_now_wearing));
-	commit.add("EditOutfit", boost::bind(&handle_edit_outfit));
-	commit.add("EditShape", boost::bind(&handle_edit_shape));
-	commit.add("HoverHeight", boost::bind(&handle_hover_height));
-	commit.add("EditPhysics", boost::bind(&handle_edit_physics));
-
-	// View menu
-	view_listener_t::addMenu(new LLViewMouselook(), "View.Mouselook");
-	view_listener_t::addMenu(new LLViewJoystickFlycam(), "View.JoystickFlycam");
-	view_listener_t::addMenu(new LLViewResetView(), "View.ResetView");
-	view_listener_t::addMenu(new LLViewLookAtLastChatter(), "View.LookAtLastChatter");
-	view_listener_t::addMenu(new LLViewShowHoverTips(), "View.ShowHoverTips");
-	view_listener_t::addMenu(new LLViewHighlightTransparent(), "View.HighlightTransparent");
-	view_listener_t::addMenu(new LLViewHighlightTransparentProbe(), "View.HighlightTransparentProbe");
-	view_listener_t::addMenu(new LLViewToggleRenderType(), "View.ToggleRenderType");
-	view_listener_t::addMenu(new LLViewShowHUDAttachments(), "View.ShowHUDAttachments");
-	view_listener_t::addMenu(new LLZoomer(1.2f), "View.ZoomOut");
-	view_listener_t::addMenu(new LLZoomer(1/1.2f), "View.ZoomIn");
-	view_listener_t::addMenu(new LLZoomer(DEFAULT_FIELD_OF_VIEW, false), "View.ZoomDefault");
-	view_listener_t::addMenu(new LLViewDefaultUISize(), "View.DefaultUISize");
-	view_listener_t::addMenu(new LLViewToggleUI(), "View.ToggleUI");
-
-	view_listener_t::addMenu(new LLViewEnableMouselook(), "View.EnableMouselook");
-	view_listener_t::addMenu(new LLViewEnableJoystickFlycam(), "View.EnableJoystickFlycam");
-	view_listener_t::addMenu(new LLViewEnableLastChatter(), "View.EnableLastChatter");
-
-	view_listener_t::addMenu(new LLViewCheckJoystickFlycam(), "View.CheckJoystickFlycam");
-	view_listener_t::addMenu(new LLViewCheckShowHoverTips(), "View.CheckShowHoverTips");
-	view_listener_t::addMenu(new LLViewCheckHighlightTransparent(), "View.CheckHighlightTransparent");
-	view_listener_t::addMenu(new LLViewCheckRenderType(), "View.CheckRenderType");
-	view_listener_t::addMenu(new LLViewStatusAway(), "View.Status.CheckAway");
-	view_listener_t::addMenu(new LLViewStatusDoNotDisturb(), "View.Status.CheckDoNotDisturb");
-	view_listener_t::addMenu(new LLWorldGetRejectTeleportOffers(), "World.GetRejectTeleportOffers");
-	view_listener_t::addMenu(new LLWorldGetRejectFriendshipRequests(), "World.GetRejectFriendshipRequests");
-	view_listener_t::addMenu(new LLViewCheckHUDAttachments(), "View.CheckHUDAttachments");
+    commit.add("EditOutfit", boost::bind(&handle_edit_outfit));
+    commit.add("EditShape", boost::bind(&handle_edit_shape));
+    commit.add("HoverHeight", boost::bind(&handle_hover_height));
+    commit.add("EditPhysics", boost::bind(&handle_edit_physics));
+
+    // View menu
+    view_listener_t::addMenu(new LLViewMouselook(), "View.Mouselook");
+    view_listener_t::addMenu(new LLViewJoystickFlycam(), "View.JoystickFlycam");
+    view_listener_t::addMenu(new LLViewResetView(), "View.ResetView");
+    view_listener_t::addMenu(new LLViewLookAtLastChatter(), "View.LookAtLastChatter");
+    view_listener_t::addMenu(new LLViewShowHoverTips(), "View.ShowHoverTips");
+    view_listener_t::addMenu(new LLViewHighlightTransparent(), "View.HighlightTransparent");
+    view_listener_t::addMenu(new LLViewHighlightTransparentProbe(), "View.HighlightTransparentProbe");
+    view_listener_t::addMenu(new LLViewToggleRenderType(), "View.ToggleRenderType");
+    view_listener_t::addMenu(new LLViewShowHUDAttachments(), "View.ShowHUDAttachments");
+    view_listener_t::addMenu(new LLZoomer(1.2f), "View.ZoomOut");
+    view_listener_t::addMenu(new LLZoomer(1/1.2f), "View.ZoomIn");
+    view_listener_t::addMenu(new LLZoomer(DEFAULT_FIELD_OF_VIEW, false), "View.ZoomDefault");
+    view_listener_t::addMenu(new LLViewDefaultUISize(), "View.DefaultUISize");
+    view_listener_t::addMenu(new LLViewToggleUI(), "View.ToggleUI");
+
+    view_listener_t::addMenu(new LLViewEnableMouselook(), "View.EnableMouselook");
+    view_listener_t::addMenu(new LLViewEnableJoystickFlycam(), "View.EnableJoystickFlycam");
+    view_listener_t::addMenu(new LLViewEnableLastChatter(), "View.EnableLastChatter");
+
+    view_listener_t::addMenu(new LLViewCheckJoystickFlycam(), "View.CheckJoystickFlycam");
+    view_listener_t::addMenu(new LLViewCheckShowHoverTips(), "View.CheckShowHoverTips");
+    view_listener_t::addMenu(new LLViewCheckHighlightTransparent(), "View.CheckHighlightTransparent");
+    view_listener_t::addMenu(new LLViewCheckRenderType(), "View.CheckRenderType");
+    view_listener_t::addMenu(new LLViewStatusAway(), "View.Status.CheckAway");
+    view_listener_t::addMenu(new LLViewStatusDoNotDisturb(), "View.Status.CheckDoNotDisturb");
+    view_listener_t::addMenu(new LLWorldGetRejectTeleportOffers(), "World.GetRejectTeleportOffers");
+    view_listener_t::addMenu(new LLWorldGetRejectFriendshipRequests(), "World.GetRejectFriendshipRequests");
+    view_listener_t::addMenu(new LLViewCheckHUDAttachments(), "View.CheckHUDAttachments");
 // [SL:KB] - Patch: World-RenderExceptions | Checked: Catznip-5.2
-	commit.add("View.Blocked", boost::bind(&handle_view_blocked, _2));
+    commit.add("View.Blocked", boost::bind(&handle_view_blocked, _2));
 // [/SL:KB]
-	
-	//Communicate Nearby chat
-	view_listener_t::addMenu(new LLCommunicateNearbyChat(), "Communicate.NearbyChat");
-
-	// Communicate > Voice morphing > Subscribe...
-	commit.add("Communicate.VoiceMorphing.Subscribe", boost::bind(&handle_voice_morphing_subscribe));
-	// Communicate > Voice morphing > Premium perk...
-	commit.add("Communicate.VoiceMorphing.PremiumPerk", boost::bind(&handle_premium_voice_morphing_subscribe));
-	LLVivoxVoiceClient * voice_clientp = LLVivoxVoiceClient::getInstance();
-	enable.add("Communicate.VoiceMorphing.NoVoiceMorphing.Check"
-		, boost::bind(&LLVivoxVoiceClient::onCheckVoiceEffect, voice_clientp, "NoVoiceMorphing"));
-	commit.add("Communicate.VoiceMorphing.NoVoiceMorphing.Click"
-		, boost::bind(&LLVivoxVoiceClient::onClickVoiceEffect, voice_clientp, "NoVoiceMorphing"));
-
-	// World menu
-	view_listener_t::addMenu(new LLWorldAlwaysRun(), "World.AlwaysRun");
-	view_listener_t::addMenu(new LLWorldCreateLandmark(), "World.CreateLandmark");
-	view_listener_t::addMenu(new LLWorldPlaceProfile(), "World.PlaceProfile");
-	view_listener_t::addMenu(new LLWorldSetHomeLocation(), "World.SetHomeLocation");
-	view_listener_t::addMenu(new LLWorldTeleportHome(), "World.TeleportHome");
-	view_listener_t::addMenu(new LLWorldSetAway(), "World.SetAway");
-	view_listener_t::addMenu(new LLWorldSetDoNotDisturb(), "World.SetDoNotDisturb");
-	view_listener_t::addMenu(new LLWorldSetRejectTeleportOffers(), "World.SetRejectTeleportOffers");
-	view_listener_t::addMenu(new LLWorldSetRejectFriendshipRequests(), "World.SetRejectFriendshipRequests");
-
-	view_listener_t::addMenu(new LLWorldLindenHome(), "World.LindenHome");
-
-	view_listener_t::addMenu(new LLWorldEnableCreateLandmark(), "World.EnableCreateLandmark");
+
+    //Communicate Nearby chat
+    view_listener_t::addMenu(new LLCommunicateNearbyChat(), "Communicate.NearbyChat");
+
+    // Communicate > Voice morphing > Subscribe...
+    commit.add("Communicate.VoiceMorphing.Subscribe", boost::bind(&handle_voice_morphing_subscribe));
+    // Communicate > Voice morphing > Premium perk...
+    commit.add("Communicate.VoiceMorphing.PremiumPerk", boost::bind(&handle_premium_voice_morphing_subscribe));
+    LLVivoxVoiceClient * voice_clientp = LLVivoxVoiceClient::getInstance();
+    enable.add("Communicate.VoiceMorphing.NoVoiceMorphing.Check"
+        , boost::bind(&LLVivoxVoiceClient::onCheckVoiceEffect, voice_clientp, "NoVoiceMorphing"));
+    commit.add("Communicate.VoiceMorphing.NoVoiceMorphing.Click"
+        , boost::bind(&LLVivoxVoiceClient::onClickVoiceEffect, voice_clientp, "NoVoiceMorphing"));
+
+    // World menu
+    view_listener_t::addMenu(new LLWorldAlwaysRun(), "World.AlwaysRun");
+    view_listener_t::addMenu(new LLWorldCreateLandmark(), "World.CreateLandmark");
+    view_listener_t::addMenu(new LLWorldPlaceProfile(), "World.PlaceProfile");
+    view_listener_t::addMenu(new LLWorldSetHomeLocation(), "World.SetHomeLocation");
+    view_listener_t::addMenu(new LLWorldTeleportHome(), "World.TeleportHome");
+    view_listener_t::addMenu(new LLWorldSetAway(), "World.SetAway");
+    view_listener_t::addMenu(new LLWorldSetDoNotDisturb(), "World.SetDoNotDisturb");
+    view_listener_t::addMenu(new LLWorldSetRejectTeleportOffers(), "World.SetRejectTeleportOffers");
+    view_listener_t::addMenu(new LLWorldSetRejectFriendshipRequests(), "World.SetRejectFriendshipRequests");
+
+    view_listener_t::addMenu(new LLWorldLindenHome(), "World.LindenHome");
+
+    view_listener_t::addMenu(new LLWorldEnableCreateLandmark(), "World.EnableCreateLandmark");
 // [RLVa:KB]
-	enable.add("World.EnablePlaceProfile", boost::bind(&enable_place_profile));
+    enable.add("World.EnablePlaceProfile", boost::bind(&enable_place_profile));
 // [/RLVa:KB]
-	view_listener_t::addMenu(new LLWorldEnableSetHomeLocation(), "World.EnableSetHomeLocation");
-	view_listener_t::addMenu(new LLWorldEnableTeleportHome(), "World.EnableTeleportHome");
-	view_listener_t::addMenu(new LLWorldEnableBuyLand(), "World.EnableBuyLand");
-
-	view_listener_t::addMenu(new LLWorldCheckAlwaysRun(), "World.CheckAlwaysRun");
-	
-	view_listener_t::addMenu(new LLWorldEnvSettings(), "World.EnvSettings");
-	view_listener_t::addMenu(new LLWorldEnableEnvSettings(), "World.EnableEnvSettings");
-	view_listener_t::addMenu(new LLWorldEnvPreset(), "World.EnvPreset");
-	view_listener_t::addMenu(new LLWorldEnableEnvPreset(), "World.EnableEnvPreset");
-	view_listener_t::addMenu(new LLWorldPostProcess(), "World.PostProcess");
+    view_listener_t::addMenu(new LLWorldEnableSetHomeLocation(), "World.EnableSetHomeLocation");
+    view_listener_t::addMenu(new LLWorldEnableTeleportHome(), "World.EnableTeleportHome");
+    view_listener_t::addMenu(new LLWorldEnableBuyLand(), "World.EnableBuyLand");
+
+    view_listener_t::addMenu(new LLWorldCheckAlwaysRun(), "World.CheckAlwaysRun");
+
+    view_listener_t::addMenu(new LLWorldEnvSettings(), "World.EnvSettings");
+    view_listener_t::addMenu(new LLWorldEnableEnvSettings(), "World.EnableEnvSettings");
+    view_listener_t::addMenu(new LLWorldEnvPreset(), "World.EnvPreset");
+    view_listener_t::addMenu(new LLWorldEnableEnvPreset(), "World.EnableEnvPreset");
+    view_listener_t::addMenu(new LLWorldPostProcess(), "World.PostProcess");
     view_listener_t::addMenu(new LLWorldCheckBanLines() , "World.CheckBanLines");
     view_listener_t::addMenu(new LLWorldShowBanLines() , "World.ShowBanLines");
 
-	// Tools menu
-	view_listener_t::addMenu(new LLToolsSelectTool(), "Tools.SelectTool");
-	view_listener_t::addMenu(new LLToolsSelectOnlyMyObjects(), "Tools.SelectOnlyMyObjects");
-	view_listener_t::addMenu(new LLToolsSelectOnlyMovableObjects(), "Tools.SelectOnlyMovableObjects");
+    // Tools menu
+    view_listener_t::addMenu(new LLToolsSelectTool(), "Tools.SelectTool");
+    view_listener_t::addMenu(new LLToolsSelectOnlyMyObjects(), "Tools.SelectOnlyMyObjects");
+    view_listener_t::addMenu(new LLToolsSelectOnlyMovableObjects(), "Tools.SelectOnlyMovableObjects");
     view_listener_t::addMenu(new LLToolsSelectInvisibleObjects(), "Tools.SelectInvisibleObjects");
     view_listener_t::addMenu(new LLToolsSelectReflectionProbes(), "Tools.SelectReflectionProbes");
-	view_listener_t::addMenu(new LLToolsSelectBySurrounding(), "Tools.SelectBySurrounding");
-	view_listener_t::addMenu(new LLToolsShowSelectionLightRadius(), "Tools.ShowSelectionLightRadius");
-	view_listener_t::addMenu(new LLToolsEditLinkedParts(), "Tools.EditLinkedParts");
-	view_listener_t::addMenu(new LLToolsSnapObjectXY(), "Tools.SnapObjectXY");
-	view_listener_t::addMenu(new LLToolsUseSelectionForGrid(), "Tools.UseSelectionForGrid");
-	view_listener_t::addMenu(new LLToolsSelectNextPartFace(), "Tools.SelectNextPart");
-	commit.add("Tools.Link", boost::bind(&handle_link_objects));
-	commit.add("Tools.Unlink", boost::bind(&LLSelectMgr::unlinkObjects, LLSelectMgr::getInstance()));
-	view_listener_t::addMenu(new LLToolsStopAllAnimations(), "Tools.StopAllAnimations");
-	view_listener_t::addMenu(new LLToolsReleaseKeys(), "Tools.ReleaseKeys");
-	view_listener_t::addMenu(new LLToolsEnableReleaseKeys(), "Tools.EnableReleaseKeys");	
-	commit.add("Tools.LookAtSelection", boost::bind(&handle_look_at_selection, _2));
-	commit.add("Tools.BuyOrTake", boost::bind(&handle_buy_or_take));
-	commit.add("Tools.TakeCopy", boost::bind(&handle_take_copy));
-	view_listener_t::addMenu(new LLToolsSaveToObjectInventory(), "Tools.SaveToObjectInventory");
-	view_listener_t::addMenu(new LLToolsSelectedScriptAction(), "Tools.SelectedScriptAction");
-
-	view_listener_t::addMenu(new LLToolsEnableToolNotPie(), "Tools.EnableToolNotPie");
-	view_listener_t::addMenu(new LLToolsEnableSelectNextPart(), "Tools.EnableSelectNextPart");
-	enable.add("Tools.EnableLink", boost::bind(&LLSelectMgr::enableLinkObjects, LLSelectMgr::getInstance()));
-	enable.add("Tools.EnableUnlink", boost::bind(&LLSelectMgr::enableUnlinkObjects, LLSelectMgr::getInstance()));
-	view_listener_t::addMenu(new LLToolsEnableBuyOrTake(), "Tools.EnableBuyOrTake");
-	enable.add("Tools.EnableTakeCopy", boost::bind(&enable_object_take_copy));
-	enable.add("Tools.VisibleBuyObject", boost::bind(&tools_visible_buy_object));
-	enable.add("Tools.VisibleTakeObject", boost::bind(&tools_visible_take_object));
-	view_listener_t::addMenu(new LLToolsEnableSaveToObjectInventory(), "Tools.EnableSaveToObjectInventory");
-
-	view_listener_t::addMenu(new LLToolsEnablePathfinding(), "Tools.EnablePathfinding");
-	view_listener_t::addMenu(new LLToolsEnablePathfindingView(), "Tools.EnablePathfindingView");
-	view_listener_t::addMenu(new LLToolsDoPathfindingRebakeRegion(), "Tools.DoPathfindingRebakeRegion");
-	view_listener_t::addMenu(new LLToolsEnablePathfindingRebakeRegion(), "Tools.EnablePathfindingRebakeRegion");
-
-	// Help menu
-	// most items use the ShowFloater method
-	view_listener_t::addMenu(new LLToggleHowTo(), "Help.ToggleHowTo");
-
-	// Advanced menu
-	view_listener_t::addMenu(new LLAdvancedToggleConsole(), "Advanced.ToggleConsole");
-	view_listener_t::addMenu(new LLAdvancedCheckConsole(), "Advanced.CheckConsole");
-	view_listener_t::addMenu(new LLAdvancedDumpInfoToConsole(), "Advanced.DumpInfoToConsole");
-	
-	// Advanced > HUD Info
-	view_listener_t::addMenu(new LLAdvancedToggleHUDInfo(), "Advanced.ToggleHUDInfo");
-	view_listener_t::addMenu(new LLAdvancedCheckHUDInfo(), "Advanced.CheckHUDInfo");
-
-	// Advanced Other Settings	
-	view_listener_t::addMenu(new LLAdvancedClearGroupCache(), "Advanced.ClearGroupCache");
-	
-	// Advanced > Render > Types
-	view_listener_t::addMenu(new LLAdvancedToggleRenderType(), "Advanced.ToggleRenderType");
-	view_listener_t::addMenu(new LLAdvancedCheckRenderType(), "Advanced.CheckRenderType");
-
-	//// Advanced > Render > Features
-	view_listener_t::addMenu(new LLAdvancedToggleFeature(), "Advanced.ToggleFeature");
-	view_listener_t::addMenu(new LLAdvancedCheckFeature(), "Advanced.CheckFeature");
-
-	view_listener_t::addMenu(new LLAdvancedCheckDisplayTextureDensity(), "Advanced.CheckDisplayTextureDensity");
-	view_listener_t::addMenu(new LLAdvancedSetDisplayTextureDensity(), "Advanced.SetDisplayTextureDensity");
-
-	// Advanced > Render > Info Displays
-	view_listener_t::addMenu(new LLAdvancedToggleInfoDisplay(), "Advanced.ToggleInfoDisplay");
-	view_listener_t::addMenu(new LLAdvancedCheckInfoDisplay(), "Advanced.CheckInfoDisplay");
-	view_listener_t::addMenu(new LLAdvancedSelectedTextureInfo(), "Advanced.SelectedTextureInfo");
-	commit.add("Advanced.SelectedMaterialInfo", boost::bind(&handle_selected_material_info));
-	view_listener_t::addMenu(new LLAdvancedToggleWireframe(), "Advanced.ToggleWireframe");
-	view_listener_t::addMenu(new LLAdvancedCheckWireframe(), "Advanced.CheckWireframe");
-	// Develop > Render
-	view_listener_t::addMenu(new LLAdvancedToggleRandomizeFramerate(), "Advanced.ToggleRandomizeFramerate");
-	view_listener_t::addMenu(new LLAdvancedCheckRandomizeFramerate(), "Advanced.CheckRandomizeFramerate");
-	view_listener_t::addMenu(new LLAdvancedTogglePeriodicSlowFrame(), "Advanced.TogglePeriodicSlowFrame");
-	view_listener_t::addMenu(new LLAdvancedCheckPeriodicSlowFrame(), "Advanced.CheckPeriodicSlowFrame");
-	view_listener_t::addMenu(new LLAdvancedHandleAttachedLightParticles(), "Advanced.HandleAttachedLightParticles");
-	view_listener_t::addMenu(new LLAdvancedCheckRenderShadowOption(), "Advanced.CheckRenderShadowOption");
-	view_listener_t::addMenu(new LLAdvancedClickRenderShadowOption(), "Advanced.ClickRenderShadowOption");
-	view_listener_t::addMenu(new LLAdvancedClickRenderProfile(), "Advanced.ClickRenderProfile");
-	view_listener_t::addMenu(new LLAdvancedClickRenderBenchmark(), "Advanced.ClickRenderBenchmark");
+    view_listener_t::addMenu(new LLToolsSelectBySurrounding(), "Tools.SelectBySurrounding");
+    view_listener_t::addMenu(new LLToolsShowSelectionLightRadius(), "Tools.ShowSelectionLightRadius");
+    view_listener_t::addMenu(new LLToolsEditLinkedParts(), "Tools.EditLinkedParts");
+    view_listener_t::addMenu(new LLToolsSnapObjectXY(), "Tools.SnapObjectXY");
+    view_listener_t::addMenu(new LLToolsUseSelectionForGrid(), "Tools.UseSelectionForGrid");
+    view_listener_t::addMenu(new LLToolsSelectNextPartFace(), "Tools.SelectNextPart");
+    commit.add("Tools.Link", boost::bind(&handle_link_objects));
+    commit.add("Tools.Unlink", boost::bind(&LLSelectMgr::unlinkObjects, LLSelectMgr::getInstance()));
+    view_listener_t::addMenu(new LLToolsStopAllAnimations(), "Tools.StopAllAnimations");
+    view_listener_t::addMenu(new LLToolsReleaseKeys(), "Tools.ReleaseKeys");
+    view_listener_t::addMenu(new LLToolsEnableReleaseKeys(), "Tools.EnableReleaseKeys");
+    commit.add("Tools.LookAtSelection", boost::bind(&handle_look_at_selection, _2));
+    commit.add("Tools.BuyOrTake", boost::bind(&handle_buy_or_take));
+    commit.add("Tools.TakeCopy", boost::bind(&handle_take_copy));
+    view_listener_t::addMenu(new LLToolsSaveToObjectInventory(), "Tools.SaveToObjectInventory");
+    view_listener_t::addMenu(new LLToolsSelectedScriptAction(), "Tools.SelectedScriptAction");
+
+    view_listener_t::addMenu(new LLToolsEnableToolNotPie(), "Tools.EnableToolNotPie");
+    view_listener_t::addMenu(new LLToolsEnableSelectNextPart(), "Tools.EnableSelectNextPart");
+    enable.add("Tools.EnableLink", boost::bind(&LLSelectMgr::enableLinkObjects, LLSelectMgr::getInstance()));
+    enable.add("Tools.EnableUnlink", boost::bind(&LLSelectMgr::enableUnlinkObjects, LLSelectMgr::getInstance()));
+    view_listener_t::addMenu(new LLToolsEnableBuyOrTake(), "Tools.EnableBuyOrTake");
+    enable.add("Tools.EnableTakeCopy", boost::bind(&enable_object_take_copy));
+    enable.add("Tools.VisibleBuyObject", boost::bind(&tools_visible_buy_object));
+    enable.add("Tools.VisibleTakeObject", boost::bind(&tools_visible_take_object));
+    view_listener_t::addMenu(new LLToolsEnableSaveToObjectInventory(), "Tools.EnableSaveToObjectInventory");
+
+    view_listener_t::addMenu(new LLToolsEnablePathfinding(), "Tools.EnablePathfinding");
+    view_listener_t::addMenu(new LLToolsEnablePathfindingView(), "Tools.EnablePathfindingView");
+    view_listener_t::addMenu(new LLToolsDoPathfindingRebakeRegion(), "Tools.DoPathfindingRebakeRegion");
+    view_listener_t::addMenu(new LLToolsEnablePathfindingRebakeRegion(), "Tools.EnablePathfindingRebakeRegion");
+
+    // Help menu
+    // most items use the ShowFloater method
+    view_listener_t::addMenu(new LLToggleHowTo(), "Help.ToggleHowTo");
+
+    // Advanced menu
+    view_listener_t::addMenu(new LLAdvancedToggleConsole(), "Advanced.ToggleConsole");
+    view_listener_t::addMenu(new LLAdvancedCheckConsole(), "Advanced.CheckConsole");
+    view_listener_t::addMenu(new LLAdvancedDumpInfoToConsole(), "Advanced.DumpInfoToConsole");
+
+    // Advanced > HUD Info
+    view_listener_t::addMenu(new LLAdvancedToggleHUDInfo(), "Advanced.ToggleHUDInfo");
+    view_listener_t::addMenu(new LLAdvancedCheckHUDInfo(), "Advanced.CheckHUDInfo");
+
+    // Advanced Other Settings
+    view_listener_t::addMenu(new LLAdvancedClearGroupCache(), "Advanced.ClearGroupCache");
+
+    // Advanced > Render > Types
+    view_listener_t::addMenu(new LLAdvancedToggleRenderType(), "Advanced.ToggleRenderType");
+    view_listener_t::addMenu(new LLAdvancedCheckRenderType(), "Advanced.CheckRenderType");
+
+    //// Advanced > Render > Features
+    view_listener_t::addMenu(new LLAdvancedToggleFeature(), "Advanced.ToggleFeature");
+    view_listener_t::addMenu(new LLAdvancedCheckFeature(), "Advanced.CheckFeature");
+
+    view_listener_t::addMenu(new LLAdvancedCheckDisplayTextureDensity(), "Advanced.CheckDisplayTextureDensity");
+    view_listener_t::addMenu(new LLAdvancedSetDisplayTextureDensity(), "Advanced.SetDisplayTextureDensity");
+
+    // Advanced > Render > Info Displays
+    view_listener_t::addMenu(new LLAdvancedToggleInfoDisplay(), "Advanced.ToggleInfoDisplay");
+    view_listener_t::addMenu(new LLAdvancedCheckInfoDisplay(), "Advanced.CheckInfoDisplay");
+    view_listener_t::addMenu(new LLAdvancedSelectedTextureInfo(), "Advanced.SelectedTextureInfo");
+    commit.add("Advanced.SelectedMaterialInfo", boost::bind(&handle_selected_material_info));
+    view_listener_t::addMenu(new LLAdvancedToggleWireframe(), "Advanced.ToggleWireframe");
+    view_listener_t::addMenu(new LLAdvancedCheckWireframe(), "Advanced.CheckWireframe");
+    // Develop > Render
+    view_listener_t::addMenu(new LLAdvancedToggleRandomizeFramerate(), "Advanced.ToggleRandomizeFramerate");
+    view_listener_t::addMenu(new LLAdvancedCheckRandomizeFramerate(), "Advanced.CheckRandomizeFramerate");
+    view_listener_t::addMenu(new LLAdvancedTogglePeriodicSlowFrame(), "Advanced.TogglePeriodicSlowFrame");
+    view_listener_t::addMenu(new LLAdvancedCheckPeriodicSlowFrame(), "Advanced.CheckPeriodicSlowFrame");
+    view_listener_t::addMenu(new LLAdvancedHandleAttachedLightParticles(), "Advanced.HandleAttachedLightParticles");
+    view_listener_t::addMenu(new LLAdvancedCheckRenderShadowOption(), "Advanced.CheckRenderShadowOption");
+    view_listener_t::addMenu(new LLAdvancedClickRenderShadowOption(), "Advanced.ClickRenderShadowOption");
+    view_listener_t::addMenu(new LLAdvancedClickRenderProfile(), "Advanced.ClickRenderProfile");
+    view_listener_t::addMenu(new LLAdvancedClickRenderBenchmark(), "Advanced.ClickRenderBenchmark");
     view_listener_t::addMenu(new LLAdvancedClickHDRIPreview(), "Advanced.ClickHDRIPreview");
     view_listener_t::addMenu(new LLAdvancedClickGLTFScenePreview(), "Advanced.ClickGLTFScenePreview");
-	view_listener_t::addMenu(new LLAdvancedPurgeShaderCache(), "Advanced.ClearShaderCache");
+    view_listener_t::addMenu(new LLAdvancedPurgeShaderCache(), "Advanced.ClearShaderCache");
     view_listener_t::addMenu(new LLAdvancedRebuildTerrain(), "Advanced.RebuildTerrain");
 
-	#ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-	view_listener_t::addMenu(new LLAdvancedHandleToggleHackedGodmode(), "Advanced.HandleToggleHackedGodmode");
-	view_listener_t::addMenu(new LLAdvancedCheckToggleHackedGodmode(), "Advanced.CheckToggleHackedGodmode");
-	view_listener_t::addMenu(new LLAdvancedEnableToggleHackedGodmode(), "Advanced.EnableToggleHackedGodmode");
-	#endif
+    #ifdef TOGGLE_HACKED_GODLIKE_VIEWER
+    view_listener_t::addMenu(new LLAdvancedHandleToggleHackedGodmode(), "Advanced.HandleToggleHackedGodmode");
+    view_listener_t::addMenu(new LLAdvancedCheckToggleHackedGodmode(), "Advanced.CheckToggleHackedGodmode");
+    view_listener_t::addMenu(new LLAdvancedEnableToggleHackedGodmode(), "Advanced.EnableToggleHackedGodmode");
+    #endif
 
-	// Advanced > World
-	view_listener_t::addMenu(new LLAdvancedDumpScriptedCamera(), "Advanced.DumpScriptedCamera");
-	view_listener_t::addMenu(new LLAdvancedDumpRegionObjectCache(), "Advanced.DumpRegionObjectCache");
+    // Advanced > World
+    view_listener_t::addMenu(new LLAdvancedDumpScriptedCamera(), "Advanced.DumpScriptedCamera");
+    view_listener_t::addMenu(new LLAdvancedDumpRegionObjectCache(), "Advanced.DumpRegionObjectCache");
     view_listener_t::addMenu(new LLAdvancedToggleStatsRecorder(), "Advanced.ToggleStatsRecorder");
     view_listener_t::addMenu(new LLAdvancedCheckStatsRecorder(), "Advanced.CheckStatsRecorder");
     view_listener_t::addMenu(new LLAdvancedToggleInterestList360Mode(), "Advanced.ToggleInterestList360Mode");
     view_listener_t::addMenu(new LLAdvancedCheckInterestList360Mode(), "Advanced.CheckInterestList360Mode");
     view_listener_t::addMenu(new LLAdvancedResetInterestLists(), "Advanced.ResetInterestLists");
 
-	// Advanced > UI
-	commit.add("Advanced.WebBrowserTest", boost::bind(&handle_web_browser_test,	_2));	// sigh! this one opens the MEDIA browser
-	commit.add("Advanced.WebContentTest", boost::bind(&handle_web_content_test, _2));	// this one opens the Web Content floater
-	commit.add("Advanced.ShowURL", boost::bind(&handle_show_url, _2));
-	commit.add("Advanced.ReportBug", boost::bind(&handle_report_bug, _2));
-	view_listener_t::addMenu(new LLAdvancedBuyCurrencyTest(), "Advanced.BuyCurrencyTest");
-	view_listener_t::addMenu(new LLAdvancedDumpSelectMgr(), "Advanced.DumpSelectMgr");
-	view_listener_t::addMenu(new LLAdvancedDumpInventory(), "Advanced.DumpInventory");
-	commit.add("Advanced.DumpTimers", boost::bind(&handle_dump_timers) );
-	commit.add("Advanced.DumpFocusHolder", boost::bind(&handle_dump_focus) );
-	view_listener_t::addMenu(new LLAdvancedPrintSelectedObjectInfo(), "Advanced.PrintSelectedObjectInfo");
-	view_listener_t::addMenu(new LLAdvancedPrintAgentInfo(), "Advanced.PrintAgentInfo");
-	view_listener_t::addMenu(new LLAdvancedToggleDebugClicks(), "Advanced.ToggleDebugClicks");
-	view_listener_t::addMenu(new LLAdvancedCheckDebugClicks(), "Advanced.CheckDebugClicks");
-	view_listener_t::addMenu(new LLAdvancedCheckDebugViews(), "Advanced.CheckDebugViews");
-	view_listener_t::addMenu(new LLAdvancedToggleDebugViews(), "Advanced.ToggleDebugViews");
-	view_listener_t::addMenu(new LLAdvancedCheckDebugUnicode(), "Advanced.CheckDebugUnicode");
-	view_listener_t::addMenu(new LLAdvancedToggleDebugUnicode(), "Advanced.ToggleDebugUnicode");
-	view_listener_t::addMenu(new LLAdvancedCheckDebugCamera(), "Advanced.CheckDebugCamera");
-	view_listener_t::addMenu(new LLAdvancedToggleDebugCamera(), "Advanced.ToggleDebugCamera");
-	view_listener_t::addMenu(new LLAdvancedToggleXUINameTooltips(), "Advanced.ToggleXUINameTooltips");
-	view_listener_t::addMenu(new LLAdvancedCheckXUINameTooltips(), "Advanced.CheckXUINameTooltips");
-	view_listener_t::addMenu(new LLAdvancedToggleDebugMouseEvents(), "Advanced.ToggleDebugMouseEvents");
-	view_listener_t::addMenu(new LLAdvancedCheckDebugMouseEvents(), "Advanced.CheckDebugMouseEvents");
-	view_listener_t::addMenu(new LLAdvancedToggleDebugKeys(), "Advanced.ToggleDebugKeys");
-	view_listener_t::addMenu(new LLAdvancedCheckDebugKeys(), "Advanced.CheckDebugKeys");
-	view_listener_t::addMenu(new LLAdvancedToggleDebugWindowProc(), "Advanced.ToggleDebugWindowProc");
-	view_listener_t::addMenu(new LLAdvancedCheckDebugWindowProc(), "Advanced.CheckDebugWindowProc");
-
-	// Advanced > XUI
-	commit.add("Advanced.ReloadColorSettings", boost::bind(&LLUIColorTable::loadFromSettings, LLUIColorTable::getInstance()));
-	view_listener_t::addMenu(new LLAdvancedToggleXUINames(), "Advanced.ToggleXUINames");
-	view_listener_t::addMenu(new LLAdvancedCheckXUINames(), "Advanced.CheckXUINames");
-	view_listener_t::addMenu(new LLAdvancedSendTestIms(), "Advanced.SendTestIMs");
-	commit.add("Advanced.FlushNameCaches", boost::bind(&handle_flush_name_caches));
-
-	// Advanced > Character > Grab Baked Texture
-	view_listener_t::addMenu(new LLAdvancedGrabBakedTexture(), "Advanced.GrabBakedTexture");
-	view_listener_t::addMenu(new LLAdvancedEnableGrabBakedTexture(), "Advanced.EnableGrabBakedTexture");
-
-	// Advanced > Character > Character Tests
-	view_listener_t::addMenu(new LLAdvancedAppearanceToXML(), "Advanced.AppearanceToXML");
-	view_listener_t::addMenu(new LLAdvancedEnableAppearanceToXML(), "Advanced.EnableAppearanceToXML");
-	view_listener_t::addMenu(new LLAdvancedToggleCharacterGeometry(), "Advanced.ToggleCharacterGeometry");
-
-	view_listener_t::addMenu(new LLAdvancedTestMale(), "Advanced.TestMale");
-	view_listener_t::addMenu(new LLAdvancedTestFemale(), "Advanced.TestFemale");
-	
-	// Advanced > Character > Animation Speed
-	view_listener_t::addMenu(new LLAdvancedAnimTenFaster(), "Advanced.AnimTenFaster");
-	view_listener_t::addMenu(new LLAdvancedAnimTenSlower(), "Advanced.AnimTenSlower");
-	view_listener_t::addMenu(new LLAdvancedAnimResetAll(), "Advanced.AnimResetAll");
-
-	// Advanced > Character (toplevel)
-	view_listener_t::addMenu(new LLAdvancedForceParamsToDefault(), "Advanced.ForceParamsToDefault");
-	view_listener_t::addMenu(new LLAdvancedReloadVertexShader(), "Advanced.ReloadVertexShader");
-	view_listener_t::addMenu(new LLAdvancedToggleAnimationInfo(), "Advanced.ToggleAnimationInfo");
-	view_listener_t::addMenu(new LLAdvancedCheckAnimationInfo(), "Advanced.CheckAnimationInfo");
-	view_listener_t::addMenu(new LLAdvancedToggleShowLookAt(), "Advanced.ToggleShowLookAt");
-	view_listener_t::addMenu(new LLAdvancedCheckShowLookAt(), "Advanced.CheckShowLookAt");
-	view_listener_t::addMenu(new LLAdvancedToggleShowPointAt(), "Advanced.ToggleShowPointAt");
-	view_listener_t::addMenu(new LLAdvancedCheckShowPointAt(), "Advanced.CheckShowPointAt");
-	view_listener_t::addMenu(new LLAdvancedToggleDebugJointUpdates(), "Advanced.ToggleDebugJointUpdates");
-	view_listener_t::addMenu(new LLAdvancedCheckDebugJointUpdates(), "Advanced.CheckDebugJointUpdates");
-	view_listener_t::addMenu(new LLAdvancedToggleDisableLOD(), "Advanced.ToggleDisableLOD");
-	view_listener_t::addMenu(new LLAdvancedCheckDisableLOD(), "Advanced.CheckDisableLOD");
-	view_listener_t::addMenu(new LLAdvancedToggleDebugCharacterVis(), "Advanced.ToggleDebugCharacterVis");
-	view_listener_t::addMenu(new LLAdvancedCheckDebugCharacterVis(), "Advanced.CheckDebugCharacterVis");
-	view_listener_t::addMenu(new LLAdvancedDumpAttachments(), "Advanced.DumpAttachments");
-	view_listener_t::addMenu(new LLAdvancedRebakeTextures(), "Advanced.RebakeTextures");
+    // Advanced > UI
+    commit.add("Advanced.WebBrowserTest", boost::bind(&handle_web_browser_test, _2));   // sigh! this one opens the MEDIA browser
+    commit.add("Advanced.WebContentTest", boost::bind(&handle_web_content_test, _2));   // this one opens the Web Content floater
+    commit.add("Advanced.ShowURL", boost::bind(&handle_show_url, _2));
+    commit.add("Advanced.ReportBug", boost::bind(&handle_report_bug, _2));
+    view_listener_t::addMenu(new LLAdvancedBuyCurrencyTest(), "Advanced.BuyCurrencyTest");
+    view_listener_t::addMenu(new LLAdvancedDumpSelectMgr(), "Advanced.DumpSelectMgr");
+    view_listener_t::addMenu(new LLAdvancedDumpInventory(), "Advanced.DumpInventory");
+    commit.add("Advanced.DumpTimers", boost::bind(&handle_dump_timers) );
+    commit.add("Advanced.DumpFocusHolder", boost::bind(&handle_dump_focus) );
+    view_listener_t::addMenu(new LLAdvancedPrintSelectedObjectInfo(), "Advanced.PrintSelectedObjectInfo");
+    view_listener_t::addMenu(new LLAdvancedPrintAgentInfo(), "Advanced.PrintAgentInfo");
+    view_listener_t::addMenu(new LLAdvancedToggleDebugClicks(), "Advanced.ToggleDebugClicks");
+    view_listener_t::addMenu(new LLAdvancedCheckDebugClicks(), "Advanced.CheckDebugClicks");
+    view_listener_t::addMenu(new LLAdvancedCheckDebugViews(), "Advanced.CheckDebugViews");
+    view_listener_t::addMenu(new LLAdvancedToggleDebugViews(), "Advanced.ToggleDebugViews");
+    view_listener_t::addMenu(new LLAdvancedCheckDebugUnicode(), "Advanced.CheckDebugUnicode");
+    view_listener_t::addMenu(new LLAdvancedToggleDebugUnicode(), "Advanced.ToggleDebugUnicode");
+    view_listener_t::addMenu(new LLAdvancedCheckDebugCamera(), "Advanced.CheckDebugCamera");
+    view_listener_t::addMenu(new LLAdvancedToggleDebugCamera(), "Advanced.ToggleDebugCamera");
+    view_listener_t::addMenu(new LLAdvancedToggleXUINameTooltips(), "Advanced.ToggleXUINameTooltips");
+    view_listener_t::addMenu(new LLAdvancedCheckXUINameTooltips(), "Advanced.CheckXUINameTooltips");
+    view_listener_t::addMenu(new LLAdvancedToggleDebugMouseEvents(), "Advanced.ToggleDebugMouseEvents");
+    view_listener_t::addMenu(new LLAdvancedCheckDebugMouseEvents(), "Advanced.CheckDebugMouseEvents");
+    view_listener_t::addMenu(new LLAdvancedToggleDebugKeys(), "Advanced.ToggleDebugKeys");
+    view_listener_t::addMenu(new LLAdvancedCheckDebugKeys(), "Advanced.CheckDebugKeys");
+    view_listener_t::addMenu(new LLAdvancedToggleDebugWindowProc(), "Advanced.ToggleDebugWindowProc");
+    view_listener_t::addMenu(new LLAdvancedCheckDebugWindowProc(), "Advanced.CheckDebugWindowProc");
+
+    // Advanced > XUI
+    commit.add("Advanced.ReloadColorSettings", boost::bind(&LLUIColorTable::loadFromSettings, LLUIColorTable::getInstance()));
+    view_listener_t::addMenu(new LLAdvancedToggleXUINames(), "Advanced.ToggleXUINames");
+    view_listener_t::addMenu(new LLAdvancedCheckXUINames(), "Advanced.CheckXUINames");
+    view_listener_t::addMenu(new LLAdvancedSendTestIms(), "Advanced.SendTestIMs");
+    commit.add("Advanced.FlushNameCaches", boost::bind(&handle_flush_name_caches));
+
+    // Advanced > Character > Grab Baked Texture
+    view_listener_t::addMenu(new LLAdvancedGrabBakedTexture(), "Advanced.GrabBakedTexture");
+    view_listener_t::addMenu(new LLAdvancedEnableGrabBakedTexture(), "Advanced.EnableGrabBakedTexture");
+
+    // Advanced > Character > Character Tests
+    view_listener_t::addMenu(new LLAdvancedAppearanceToXML(), "Advanced.AppearanceToXML");
+    view_listener_t::addMenu(new LLAdvancedEnableAppearanceToXML(), "Advanced.EnableAppearanceToXML");
+    view_listener_t::addMenu(new LLAdvancedToggleCharacterGeometry(), "Advanced.ToggleCharacterGeometry");
+
+    view_listener_t::addMenu(new LLAdvancedTestMale(), "Advanced.TestMale");
+    view_listener_t::addMenu(new LLAdvancedTestFemale(), "Advanced.TestFemale");
+
+    // Advanced > Character > Animation Speed
+    view_listener_t::addMenu(new LLAdvancedAnimTenFaster(), "Advanced.AnimTenFaster");
+    view_listener_t::addMenu(new LLAdvancedAnimTenSlower(), "Advanced.AnimTenSlower");
+    view_listener_t::addMenu(new LLAdvancedAnimResetAll(), "Advanced.AnimResetAll");
+
+    // Advanced > Character (toplevel)
+    view_listener_t::addMenu(new LLAdvancedForceParamsToDefault(), "Advanced.ForceParamsToDefault");
+    view_listener_t::addMenu(new LLAdvancedReloadVertexShader(), "Advanced.ReloadVertexShader");
+    view_listener_t::addMenu(new LLAdvancedToggleAnimationInfo(), "Advanced.ToggleAnimationInfo");
+    view_listener_t::addMenu(new LLAdvancedCheckAnimationInfo(), "Advanced.CheckAnimationInfo");
+    view_listener_t::addMenu(new LLAdvancedToggleShowLookAt(), "Advanced.ToggleShowLookAt");
+    view_listener_t::addMenu(new LLAdvancedCheckShowLookAt(), "Advanced.CheckShowLookAt");
+    view_listener_t::addMenu(new LLAdvancedToggleShowPointAt(), "Advanced.ToggleShowPointAt");
+    view_listener_t::addMenu(new LLAdvancedCheckShowPointAt(), "Advanced.CheckShowPointAt");
+    view_listener_t::addMenu(new LLAdvancedToggleDebugJointUpdates(), "Advanced.ToggleDebugJointUpdates");
+    view_listener_t::addMenu(new LLAdvancedCheckDebugJointUpdates(), "Advanced.CheckDebugJointUpdates");
+    view_listener_t::addMenu(new LLAdvancedToggleDisableLOD(), "Advanced.ToggleDisableLOD");
+    view_listener_t::addMenu(new LLAdvancedCheckDisableLOD(), "Advanced.CheckDisableLOD");
+    view_listener_t::addMenu(new LLAdvancedToggleDebugCharacterVis(), "Advanced.ToggleDebugCharacterVis");
+    view_listener_t::addMenu(new LLAdvancedCheckDebugCharacterVis(), "Advanced.CheckDebugCharacterVis");
+    view_listener_t::addMenu(new LLAdvancedDumpAttachments(), "Advanced.DumpAttachments");
+    view_listener_t::addMenu(new LLAdvancedRebakeTextures(), "Advanced.RebakeTextures");
 // [SL:KB] - Patch: Appearance-PhantomAttach | Checked: Catznip-5.0
-	commit.add("Advanced.RefreshAttachments", boost::bind(&handle_refresh_attachments));
+    commit.add("Advanced.RefreshAttachments", boost::bind(&handle_refresh_attachments));
 // [/SL:KB]
-	view_listener_t::addMenu(new LLAdvancedDebugAvatarTextures(), "Advanced.DebugAvatarTextures");
-	view_listener_t::addMenu(new LLAdvancedDumpAvatarLocalTextures(), "Advanced.DumpAvatarLocalTextures");
-	// Advanced > Network
-	view_listener_t::addMenu(new LLAdvancedEnableMessageLog(), "Advanced.EnableMessageLog");
-	view_listener_t::addMenu(new LLAdvancedDisableMessageLog(), "Advanced.DisableMessageLog");
-	view_listener_t::addMenu(new LLAdvancedDropPacket(), "Advanced.DropPacket");
+    view_listener_t::addMenu(new LLAdvancedDebugAvatarTextures(), "Advanced.DebugAvatarTextures");
+    view_listener_t::addMenu(new LLAdvancedDumpAvatarLocalTextures(), "Advanced.DumpAvatarLocalTextures");
+    // Advanced > Network
+    view_listener_t::addMenu(new LLAdvancedEnableMessageLog(), "Advanced.EnableMessageLog");
+    view_listener_t::addMenu(new LLAdvancedDisableMessageLog(), "Advanced.DisableMessageLog");
+    view_listener_t::addMenu(new LLAdvancedDropPacket(), "Advanced.DropPacket");
 
     // Advanced > Cache
     view_listener_t::addMenu(new LLAdvancedPurgeDiskCache(), "Advanced.PurgeDiskCache");
 
-	// Advanced > Recorder
-	view_listener_t::addMenu(new LLAdvancedAgentPilot(), "Advanced.AgentPilot");
-	view_listener_t::addMenu(new LLAdvancedToggleAgentPilotLoop(), "Advanced.ToggleAgentPilotLoop");
-	view_listener_t::addMenu(new LLAdvancedCheckAgentPilotLoop(), "Advanced.CheckAgentPilotLoop");
-	view_listener_t::addMenu(new LLAdvancedViewerEventRecorder(), "Advanced.EventRecorder");
+    // Advanced > Recorder
+    view_listener_t::addMenu(new LLAdvancedAgentPilot(), "Advanced.AgentPilot");
+    view_listener_t::addMenu(new LLAdvancedToggleAgentPilotLoop(), "Advanced.ToggleAgentPilotLoop");
+    view_listener_t::addMenu(new LLAdvancedCheckAgentPilotLoop(), "Advanced.CheckAgentPilotLoop");
+    view_listener_t::addMenu(new LLAdvancedViewerEventRecorder(), "Advanced.EventRecorder");
 
-	// Advanced > Debugging
-	view_listener_t::addMenu(new LLAdvancedForceErrorBreakpoint(), "Advanced.ForceErrorBreakpoint");
-	view_listener_t::addMenu(new LLAdvancedForceErrorLlerror(), "Advanced.ForceErrorLlerror");
+    // Advanced > Debugging
+    view_listener_t::addMenu(new LLAdvancedForceErrorBreakpoint(), "Advanced.ForceErrorBreakpoint");
+    view_listener_t::addMenu(new LLAdvancedForceErrorLlerror(), "Advanced.ForceErrorLlerror");
     view_listener_t::addMenu(new LLAdvancedForceErrorLlerrorMsg(), "Advanced.ForceErrorLlerrorMsg");
-	view_listener_t::addMenu(new LLAdvancedForceErrorBadMemoryAccess(), "Advanced.ForceErrorBadMemoryAccess");
-	view_listener_t::addMenu(new LLAdvancedForceErrorBadMemoryAccessCoro(), "Advanced.ForceErrorBadMemoryAccessCoro");
-	view_listener_t::addMenu(new LLAdvancedForceErrorInfiniteLoop(), "Advanced.ForceErrorInfiniteLoop");
-	view_listener_t::addMenu(new LLAdvancedForceErrorSoftwareException(), "Advanced.ForceErrorSoftwareException");
+    view_listener_t::addMenu(new LLAdvancedForceErrorBadMemoryAccess(), "Advanced.ForceErrorBadMemoryAccess");
+    view_listener_t::addMenu(new LLAdvancedForceErrorBadMemoryAccessCoro(), "Advanced.ForceErrorBadMemoryAccessCoro");
+    view_listener_t::addMenu(new LLAdvancedForceErrorInfiniteLoop(), "Advanced.ForceErrorInfiniteLoop");
+    view_listener_t::addMenu(new LLAdvancedForceErrorSoftwareException(), "Advanced.ForceErrorSoftwareException");
     view_listener_t::addMenu(new LLAdvancedForceOSException(), "Advanced.ForceErrorOSException");
-	view_listener_t::addMenu(new LLAdvancedForceErrorSoftwareExceptionCoro(), "Advanced.ForceErrorSoftwareExceptionCoro");
-	view_listener_t::addMenu(new LLAdvancedForceErrorDriverCrash(), "Advanced.ForceErrorDriverCrash");
+    view_listener_t::addMenu(new LLAdvancedForceErrorSoftwareExceptionCoro(), "Advanced.ForceErrorSoftwareExceptionCoro");
+    view_listener_t::addMenu(new LLAdvancedForceErrorDriverCrash(), "Advanced.ForceErrorDriverCrash");
     view_listener_t::addMenu(new LLAdvancedForceErrorCoroutineCrash(), "Advanced.ForceErrorCoroutineCrash");
     view_listener_t::addMenu(new LLAdvancedForceErrorThreadCrash(), "Advanced.ForceErrorThreadCrash");
-	view_listener_t::addMenu(new LLAdvancedForceErrorDisconnectViewer(), "Advanced.ForceErrorDisconnectViewer");
+    view_listener_t::addMenu(new LLAdvancedForceErrorDisconnectViewer(), "Advanced.ForceErrorDisconnectViewer");
 
-	// Advanced (toplevel)
-	view_listener_t::addMenu(new LLAdvancedToggleShowObjectUpdates(), "Advanced.ToggleShowObjectUpdates");
-	view_listener_t::addMenu(new LLAdvancedCheckShowObjectUpdates(), "Advanced.CheckShowObjectUpdates");
-	view_listener_t::addMenu(new LLAdvancedCompressImage(), "Advanced.CompressImage");
+    // Advanced (toplevel)
+    view_listener_t::addMenu(new LLAdvancedToggleShowObjectUpdates(), "Advanced.ToggleShowObjectUpdates");
+    view_listener_t::addMenu(new LLAdvancedCheckShowObjectUpdates(), "Advanced.CheckShowObjectUpdates");
+    view_listener_t::addMenu(new LLAdvancedCompressImage(), "Advanced.CompressImage");
     view_listener_t::addMenu(new LLAdvancedCompressFileTest(), "Advanced.CompressFileTest");
-	view_listener_t::addMenu(new LLAdvancedShowDebugSettings(), "Advanced.ShowDebugSettings");
-	view_listener_t::addMenu(new LLAdvancedShowDebugSettings(), "Advanced.ToggleDebugSettings");
-	view_listener_t::addMenu(new LLAdvancedEnableViewAdminOptions(), "Advanced.EnableViewAdminOptions");
-	view_listener_t::addMenu(new LLAdvancedToggleViewAdminOptions(), "Advanced.ToggleViewAdminOptions");
-	view_listener_t::addMenu(new LLAdvancedCheckViewAdminOptions(), "Advanced.CheckViewAdminOptions");
-	view_listener_t::addMenu(new LLAdvancedToggleVisualLeakDetector(), "Advanced.ToggleVisualLeakDetector");
-
-	view_listener_t::addMenu(new LLAdvancedRequestAdminStatus(), "Advanced.RequestAdminStatus");
-	view_listener_t::addMenu(new LLAdvancedLeaveAdminStatus(), "Advanced.LeaveAdminStatus");
-
-	// Develop >Set logging level
-	view_listener_t::addMenu(new LLDevelopCheckLoggingLevel(), "Develop.CheckLoggingLevel");
-	view_listener_t::addMenu(new LLDevelopSetLoggingLevel(), "Develop.SetLoggingLevel");
-	
-	//Develop (clear cache immediately)
-	commit.add("Develop.ClearCache", boost::bind(&handle_cache_clear_immediately) );
-
-	// Develop (Fonts debugging)
-	commit.add("Develop.Fonts.Dump", boost::bind(&LLFontGL::dumpFonts));
-	commit.add("Develop.Fonts.DumpTextures", boost::bind(&LLFontGL::dumpFontTextures));
-
-	// Admin >Object
-	view_listener_t::addMenu(new LLAdminForceTakeCopy(), "Admin.ForceTakeCopy");
-	view_listener_t::addMenu(new LLAdminHandleObjectOwnerSelf(), "Admin.HandleObjectOwnerSelf");
-	view_listener_t::addMenu(new LLAdminHandleObjectOwnerPermissive(), "Admin.HandleObjectOwnerPermissive");
-	view_listener_t::addMenu(new LLAdminHandleForceDelete(), "Admin.HandleForceDelete");
-	view_listener_t::addMenu(new LLAdminHandleObjectLock(), "Admin.HandleObjectLock");
-	view_listener_t::addMenu(new LLAdminHandleObjectAssetIDs(), "Admin.HandleObjectAssetIDs");
-
-	// Admin >Parcel 
-	view_listener_t::addMenu(new LLAdminHandleForceParcelOwnerToMe(), "Admin.HandleForceParcelOwnerToMe");
-	view_listener_t::addMenu(new LLAdminHandleForceParcelToContent(), "Admin.HandleForceParcelToContent");
-	view_listener_t::addMenu(new LLAdminHandleClaimPublicLand(), "Admin.HandleClaimPublicLand");
-
-	// Admin >Region
-	view_listener_t::addMenu(new LLAdminHandleRegionDumpTempAssetData(), "Admin.HandleRegionDumpTempAssetData");
-	// Admin top level
-	view_listener_t::addMenu(new LLAdminOnSaveState(), "Admin.OnSaveState");
-
-	// Self context menu
-	view_listener_t::addMenu(new LLSelfToggleSitStand(), "Self.ToggleSitStand");
-	enable.add("Self.EnableSitStand", boost::bind(&enable_sit_stand));
-	view_listener_t::addMenu(new LLSelfRemoveAllAttachments(), "Self.RemoveAllAttachments");
-
-	view_listener_t::addMenu(new LLSelfEnableRemoveAllAttachments(), "Self.EnableRemoveAllAttachments");
-
-	// we don't use boost::bind directly to delay side tray construction
-	view_listener_t::addMenu( new LLTogglePanelPeopleTab(), "SideTray.PanelPeopleTab");
-	view_listener_t::addMenu( new LLCheckPanelPeopleTab(), "SideTray.CheckPanelPeopleTab");
-
-	 // Avatar pie menu
-	view_listener_t::addMenu(new LLAvatarCheckImpostorMode(), "Avatar.CheckImpostorMode");
-	view_listener_t::addMenu(new LLAvatarSetImpostorMode(), "Avatar.SetImpostorMode");
-	view_listener_t::addMenu(new LLObjectMute(), "Avatar.Mute");
-	view_listener_t::addMenu(new LLAvatarAddFriend(), "Avatar.AddFriend");
-	view_listener_t::addMenu(new LLAvatarAddContact(), "Avatar.AddContact");
-	commit.add("Avatar.Freeze", boost::bind(&handle_avatar_freeze, LLSD()));
-	view_listener_t::addMenu(new LLAvatarDebug(), "Avatar.Debug");
-	view_listener_t::addMenu(new LLAvatarVisibleDebug(), "Avatar.VisibleDebug");
-	view_listener_t::addMenu(new LLAvatarInviteToGroup(), "Avatar.InviteToGroup");
-	commit.add("Avatar.Eject", boost::bind(&handle_avatar_eject, LLSD()));
-	commit.add("Avatar.ShowInspector", boost::bind(&handle_avatar_show_inspector));
-	view_listener_t::addMenu(new LLAvatarSendIM(), "Avatar.SendIM");
-	view_listener_t::addMenu(new LLAvatarCall(), "Avatar.Call");
-//	enable.add("Avatar.EnableCall", boost::bind(&LLAvatarActions::canCall));
+    view_listener_t::addMenu(new LLAdvancedShowDebugSettings(), "Advanced.ShowDebugSettings");
+    view_listener_t::addMenu(new LLAdvancedShowDebugSettings(), "Advanced.ToggleDebugSettings");
+    view_listener_t::addMenu(new LLAdvancedEnableViewAdminOptions(), "Advanced.EnableViewAdminOptions");
+    view_listener_t::addMenu(new LLAdvancedToggleViewAdminOptions(), "Advanced.ToggleViewAdminOptions");
+    view_listener_t::addMenu(new LLAdvancedCheckViewAdminOptions(), "Advanced.CheckViewAdminOptions");
+    view_listener_t::addMenu(new LLAdvancedToggleVisualLeakDetector(), "Advanced.ToggleVisualLeakDetector");
+
+    view_listener_t::addMenu(new LLAdvancedRequestAdminStatus(), "Advanced.RequestAdminStatus");
+    view_listener_t::addMenu(new LLAdvancedLeaveAdminStatus(), "Advanced.LeaveAdminStatus");
+
+    // Develop >Set logging level
+    view_listener_t::addMenu(new LLDevelopCheckLoggingLevel(), "Develop.CheckLoggingLevel");
+    view_listener_t::addMenu(new LLDevelopSetLoggingLevel(), "Develop.SetLoggingLevel");
+
+    //Develop (clear cache immediately)
+    commit.add("Develop.ClearCache", boost::bind(&handle_cache_clear_immediately) );
+
+    // Develop (Fonts debugging)
+    commit.add("Develop.Fonts.Dump", boost::bind(&LLFontGL::dumpFonts));
+    commit.add("Develop.Fonts.DumpTextures", boost::bind(&LLFontGL::dumpFontTextures));
+
+    // Admin >Object
+    view_listener_t::addMenu(new LLAdminForceTakeCopy(), "Admin.ForceTakeCopy");
+    view_listener_t::addMenu(new LLAdminHandleObjectOwnerSelf(), "Admin.HandleObjectOwnerSelf");
+    view_listener_t::addMenu(new LLAdminHandleObjectOwnerPermissive(), "Admin.HandleObjectOwnerPermissive");
+    view_listener_t::addMenu(new LLAdminHandleForceDelete(), "Admin.HandleForceDelete");
+    view_listener_t::addMenu(new LLAdminHandleObjectLock(), "Admin.HandleObjectLock");
+    view_listener_t::addMenu(new LLAdminHandleObjectAssetIDs(), "Admin.HandleObjectAssetIDs");
+
+    // Admin >Parcel
+    view_listener_t::addMenu(new LLAdminHandleForceParcelOwnerToMe(), "Admin.HandleForceParcelOwnerToMe");
+    view_listener_t::addMenu(new LLAdminHandleForceParcelToContent(), "Admin.HandleForceParcelToContent");
+    view_listener_t::addMenu(new LLAdminHandleClaimPublicLand(), "Admin.HandleClaimPublicLand");
+
+    // Admin >Region
+    view_listener_t::addMenu(new LLAdminHandleRegionDumpTempAssetData(), "Admin.HandleRegionDumpTempAssetData");
+    // Admin top level
+    view_listener_t::addMenu(new LLAdminOnSaveState(), "Admin.OnSaveState");
+
+    // Self context menu
+    view_listener_t::addMenu(new LLSelfToggleSitStand(), "Self.ToggleSitStand");
+    enable.add("Self.EnableSitStand", boost::bind(&enable_sit_stand));
+    view_listener_t::addMenu(new LLSelfRemoveAllAttachments(), "Self.RemoveAllAttachments");
+
+    view_listener_t::addMenu(new LLSelfEnableRemoveAllAttachments(), "Self.EnableRemoveAllAttachments");
+
+    // we don't use boost::bind directly to delay side tray construction
+    view_listener_t::addMenu( new LLTogglePanelPeopleTab(), "SideTray.PanelPeopleTab");
+    view_listener_t::addMenu( new LLCheckPanelPeopleTab(), "SideTray.CheckPanelPeopleTab");
+
+     // Avatar pie menu
+    view_listener_t::addMenu(new LLAvatarCheckImpostorMode(), "Avatar.CheckImpostorMode");
+    view_listener_t::addMenu(new LLAvatarSetImpostorMode(), "Avatar.SetImpostorMode");
+    view_listener_t::addMenu(new LLObjectMute(), "Avatar.Mute");
+    view_listener_t::addMenu(new LLAvatarAddFriend(), "Avatar.AddFriend");
+    view_listener_t::addMenu(new LLAvatarAddContact(), "Avatar.AddContact");
+    commit.add("Avatar.Freeze", boost::bind(&handle_avatar_freeze, LLSD()));
+    view_listener_t::addMenu(new LLAvatarDebug(), "Avatar.Debug");
+    view_listener_t::addMenu(new LLAvatarVisibleDebug(), "Avatar.VisibleDebug");
+    view_listener_t::addMenu(new LLAvatarInviteToGroup(), "Avatar.InviteToGroup");
+    commit.add("Avatar.Eject", boost::bind(&handle_avatar_eject, LLSD()));
+    commit.add("Avatar.ShowInspector", boost::bind(&handle_avatar_show_inspector));
+    view_listener_t::addMenu(new LLAvatarSendIM(), "Avatar.SendIM");
+    view_listener_t::addMenu(new LLAvatarCall(), "Avatar.Call");
+//  enable.add("Avatar.EnableCall", boost::bind(&LLAvatarActions::canCall));
 // [RLVa:KB] - Checked: 2010-08-25 (RLVa-1.2.1b) | Added: RLVa-1.2.1b
-	enable.add("Avatar.EnableCall", boost::bind(&enable_avatar_call));
+    enable.add("Avatar.EnableCall", boost::bind(&enable_avatar_call));
 // [/RLVa:KB]
-	view_listener_t::addMenu(new LLAvatarReportAbuse(), "Avatar.ReportAbuse");
-	view_listener_t::addMenu(new LLAvatarToggleMyProfile(), "Avatar.ToggleMyProfile");
-	view_listener_t::addMenu(new LLAvatarTogglePicks(), "Avatar.TogglePicks");
-	view_listener_t::addMenu(new LLAvatarToggleSearch(), "Avatar.ToggleSearch");
-	view_listener_t::addMenu(new LLAvatarResetSkeleton(), "Avatar.ResetSkeleton");
-	view_listener_t::addMenu(new LLAvatarEnableResetSkeleton(), "Avatar.EnableResetSkeleton");
-	view_listener_t::addMenu(new LLAvatarResetSkeletonAndAnimations(), "Avatar.ResetSkeletonAndAnimations");
-	view_listener_t::addMenu(new LLAvatarResetSelfSkeletonAndAnimations(), "Avatar.ResetSelfSkeletonAndAnimations");
-	enable.add("Avatar.IsMyProfileOpen", boost::bind(&my_profile_visible));
+    view_listener_t::addMenu(new LLAvatarReportAbuse(), "Avatar.ReportAbuse");
+    view_listener_t::addMenu(new LLAvatarToggleMyProfile(), "Avatar.ToggleMyProfile");
+    view_listener_t::addMenu(new LLAvatarTogglePicks(), "Avatar.TogglePicks");
+    view_listener_t::addMenu(new LLAvatarToggleSearch(), "Avatar.ToggleSearch");
+    view_listener_t::addMenu(new LLAvatarResetSkeleton(), "Avatar.ResetSkeleton");
+    view_listener_t::addMenu(new LLAvatarEnableResetSkeleton(), "Avatar.EnableResetSkeleton");
+    view_listener_t::addMenu(new LLAvatarResetSkeletonAndAnimations(), "Avatar.ResetSkeletonAndAnimations");
+    view_listener_t::addMenu(new LLAvatarResetSelfSkeletonAndAnimations(), "Avatar.ResetSelfSkeletonAndAnimations");
+    enable.add("Avatar.IsMyProfileOpen", boost::bind(&my_profile_visible));
     enable.add("Avatar.IsPicksTabOpen", boost::bind(&picks_tab_visible));
 
-	commit.add("Avatar.OpenMarketplace", boost::bind(&LLWeb::loadURL, gSavedSettings.getString("MarketplaceURL"), LLStringUtil::null, LLStringUtil::null));
-	
-	view_listener_t::addMenu(new LLAvatarEnableAddFriend(), "Avatar.EnableAddFriend");
-	enable.add("Avatar.EnableFreezeEject", boost::bind(&enable_freeze_eject, _2));
-
-	// Object pie menu
-	view_listener_t::addMenu(new LLObjectBuild(), "Object.Build");
-	commit.add("Object.Touch", boost::bind(&handle_object_touch));
-	commit.add("Object.ShowOriginal", boost::bind(&handle_object_show_original));
-	commit.add("Object.SitOrStand", boost::bind(&handle_object_sit_or_stand));
-	commit.add("Object.Delete", boost::bind(&handle_object_delete));
+    commit.add("Avatar.OpenMarketplace", boost::bind(&LLWeb::loadURL, gSavedSettings.getString("MarketplaceURL"), LLStringUtil::null, LLStringUtil::null));
+
+    view_listener_t::addMenu(new LLAvatarEnableAddFriend(), "Avatar.EnableAddFriend");
+    enable.add("Avatar.EnableFreezeEject", boost::bind(&enable_freeze_eject, _2));
+
+    // Object pie menu
+    view_listener_t::addMenu(new LLObjectBuild(), "Object.Build");
+    commit.add("Object.Touch", boost::bind(&handle_object_touch));
+    commit.add("Object.ShowOriginal", boost::bind(&handle_object_show_original));
+    commit.add("Object.SitOrStand", boost::bind(&handle_object_sit_or_stand));
+    commit.add("Object.Delete", boost::bind(&handle_object_delete));
 // [SL:KB] - Patch: World-Derender | Checked: 2011-12-15 (Catznip-3.2)
-	commit.add("Object.Derender", boost::bind(&handle_object_derender, _2));
-	enable.add("Object.EnableDerender", boost::bind(&enable_object_derender));
+    commit.add("Object.Derender", boost::bind(&handle_object_derender, _2));
+    enable.add("Object.EnableDerender", boost::bind(&enable_object_derender));
 // [/SL:KB]
-	view_listener_t::addMenu(new LLObjectAttachToAvatar(true), "Object.AttachToAvatar");
-	view_listener_t::addMenu(new LLObjectAttachToAvatar(false), "Object.AttachAddToAvatar");
-	view_listener_t::addMenu(new LLObjectReturn(), "Object.Return");
-	commit.add("Object.Duplicate", boost::bind(&LLSelectMgr::duplicate, LLSelectMgr::getInstance()));
-	view_listener_t::addMenu(new LLObjectReportAbuse(), "Object.ReportAbuse");
-	view_listener_t::addMenu(new LLObjectMute(), "Object.Mute");
-
-	enable.add("Object.VisibleTake", boost::bind(&visible_take_object));
-	enable.add("Object.VisibleBuy", boost::bind(&visible_buy_object));
-
-	commit.add("Object.Buy", boost::bind(&handle_buy));
-	commit.add("Object.Edit", boost::bind(&handle_object_edit));
+    view_listener_t::addMenu(new LLObjectAttachToAvatar(true), "Object.AttachToAvatar");
+    view_listener_t::addMenu(new LLObjectAttachToAvatar(false), "Object.AttachAddToAvatar");
+    view_listener_t::addMenu(new LLObjectReturn(), "Object.Return");
+    commit.add("Object.Duplicate", boost::bind(&LLSelectMgr::duplicate, LLSelectMgr::getInstance()));
+    view_listener_t::addMenu(new LLObjectReportAbuse(), "Object.ReportAbuse");
+    view_listener_t::addMenu(new LLObjectMute(), "Object.Mute");
+
+    enable.add("Object.VisibleTake", boost::bind(&visible_take_object));
+    enable.add("Object.VisibleBuy", boost::bind(&visible_buy_object));
+
+    commit.add("Object.Buy", boost::bind(&handle_buy));
+    commit.add("Object.Edit", boost::bind(&handle_object_edit));
     commit.add("Object.EditGLTFMaterial", boost::bind(&handle_object_edit_gltf_material));
-	commit.add("Object.Inspect", boost::bind(&handle_object_inspect));
-	commit.add("Object.Open", boost::bind(&handle_object_open));
-	commit.add("Object.Take", boost::bind(&handle_take));
-	commit.add("Object.ShowInspector", boost::bind(&handle_object_show_inspector));
+    commit.add("Object.Inspect", boost::bind(&handle_object_inspect));
+    commit.add("Object.Open", boost::bind(&handle_object_open));
+    commit.add("Object.Take", boost::bind(&handle_take));
+    commit.add("Object.ShowInspector", boost::bind(&handle_object_show_inspector));
     enable.add("Object.EnableInspect", boost::bind(&enable_object_inspect));
     enable.add("Object.EnableEditGLTFMaterial", boost::bind(&enable_object_edit_gltf_material));
-	enable.add("Object.EnableOpen", boost::bind(&enable_object_open));
-	enable.add("Object.EnableTouch", boost::bind(&enable_object_touch, _1));
-	enable.add("Object.EnableDelete", boost::bind(&enable_object_delete));
-	enable.add("Object.EnableWear", boost::bind(&object_is_wearable));
-
-	enable.add("Object.EnableStandUp", boost::bind(&enable_object_stand_up));
-	enable.add("Object.EnableSit", boost::bind(&enable_object_sit, _1));
-
-	view_listener_t::addMenu(new LLObjectEnableReturn(), "Object.EnableReturn");
-	enable.add("Object.EnableDuplicate", boost::bind(&LLSelectMgr::canDuplicate, LLSelectMgr::getInstance()));
-	view_listener_t::addMenu(new LLObjectEnableReportAbuse(), "Object.EnableReportAbuse");
-
-	enable.add("Avatar.EnableMute", boost::bind(&enable_object_mute));
-	enable.add("Object.EnableMute", boost::bind(&enable_object_mute));
-	enable.add("Object.EnableUnmute", boost::bind(&enable_object_unmute));
-	enable.add("Object.EnableBuy", boost::bind(&enable_buy_object));
-	commit.add("Object.ZoomIn", boost::bind(&handle_look_at_selection, "zoom"));
-
-	// Attachment pie menu
-	enable.add("Attachment.Label", boost::bind(&onEnableAttachmentLabel, _1, _2));
-	view_listener_t::addMenu(new LLAttachmentDrop(), "Attachment.Drop");
-	view_listener_t::addMenu(new LLAttachmentDetachFromPoint(), "Attachment.DetachFromPoint");
-	view_listener_t::addMenu(new LLAttachmentDetach(), "Attachment.Detach");
-	view_listener_t::addMenu(new LLAttachmentPointFilled(), "Attachment.PointFilled");
-	view_listener_t::addMenu(new LLAttachmentEnableDrop(), "Attachment.EnableDrop");
-	view_listener_t::addMenu(new LLAttachmentEnableDetach(), "Attachment.EnableDetach");
-
-	// Land pie menu
-	view_listener_t::addMenu(new LLLandBuild(), "Land.Build");
-	view_listener_t::addMenu(new LLLandSit(), "Land.Sit");
+    enable.add("Object.EnableOpen", boost::bind(&enable_object_open));
+    enable.add("Object.EnableTouch", boost::bind(&enable_object_touch, _1));
+    enable.add("Object.EnableDelete", boost::bind(&enable_object_delete));
+    enable.add("Object.EnableWear", boost::bind(&object_is_wearable));
+
+    enable.add("Object.EnableStandUp", boost::bind(&enable_object_stand_up));
+    enable.add("Object.EnableSit", boost::bind(&enable_object_sit, _1));
+
+    view_listener_t::addMenu(new LLObjectEnableReturn(), "Object.EnableReturn");
+    enable.add("Object.EnableDuplicate", boost::bind(&LLSelectMgr::canDuplicate, LLSelectMgr::getInstance()));
+    view_listener_t::addMenu(new LLObjectEnableReportAbuse(), "Object.EnableReportAbuse");
+
+    enable.add("Avatar.EnableMute", boost::bind(&enable_object_mute));
+    enable.add("Object.EnableMute", boost::bind(&enable_object_mute));
+    enable.add("Object.EnableUnmute", boost::bind(&enable_object_unmute));
+    enable.add("Object.EnableBuy", boost::bind(&enable_buy_object));
+    commit.add("Object.ZoomIn", boost::bind(&handle_look_at_selection, "zoom"));
+
+    // Attachment pie menu
+    enable.add("Attachment.Label", boost::bind(&onEnableAttachmentLabel, _1, _2));
+    view_listener_t::addMenu(new LLAttachmentDrop(), "Attachment.Drop");
+    view_listener_t::addMenu(new LLAttachmentDetachFromPoint(), "Attachment.DetachFromPoint");
+    view_listener_t::addMenu(new LLAttachmentDetach(), "Attachment.Detach");
+    view_listener_t::addMenu(new LLAttachmentPointFilled(), "Attachment.PointFilled");
+    view_listener_t::addMenu(new LLAttachmentEnableDrop(), "Attachment.EnableDrop");
+    view_listener_t::addMenu(new LLAttachmentEnableDetach(), "Attachment.EnableDetach");
+
+    // Land pie menu
+    view_listener_t::addMenu(new LLLandBuild(), "Land.Build");
+    view_listener_t::addMenu(new LLLandSit(), "Land.Sit");
     view_listener_t::addMenu(new LLLandCanSit(), "Land.CanSit");
-	view_listener_t::addMenu(new LLLandBuyPass(), "Land.BuyPass");
-	view_listener_t::addMenu(new LLLandEdit(), "Land.Edit");
-
-	// Particle muting
-	view_listener_t::addMenu(new LLMuteParticle(), "Particle.Mute");
-
-	view_listener_t::addMenu(new LLLandEnableBuyPass(), "Land.EnableBuyPass");
-	commit.add("Land.Buy", boost::bind(&handle_buy_land));
-
-	// Generic actions
-	commit.add("ReportAbuse", boost::bind(&handle_report_abuse));
-	commit.add("BuyCurrency", boost::bind(&handle_buy_currency));
-	view_listener_t::addMenu(new LLShowHelp(), "ShowHelp");
-	view_listener_t::addMenu(new LLToggleHelp(), "ToggleHelp");
-	view_listener_t::addMenu(new LLToggleSpeak(), "ToggleSpeak");
-	view_listener_t::addMenu(new LLPromptShowURL(), "PromptShowURL");
-	view_listener_t::addMenu(new LLShowAgentProfile(), "ShowAgentProfile");
+    view_listener_t::addMenu(new LLLandBuyPass(), "Land.BuyPass");
+    view_listener_t::addMenu(new LLLandEdit(), "Land.Edit");
+
+    // Particle muting
+    view_listener_t::addMenu(new LLMuteParticle(), "Particle.Mute");
+
+    view_listener_t::addMenu(new LLLandEnableBuyPass(), "Land.EnableBuyPass");
+    commit.add("Land.Buy", boost::bind(&handle_buy_land));
+
+    // Generic actions
+    commit.add("ReportAbuse", boost::bind(&handle_report_abuse));
+    commit.add("BuyCurrency", boost::bind(&handle_buy_currency));
+    view_listener_t::addMenu(new LLShowHelp(), "ShowHelp");
+    view_listener_t::addMenu(new LLToggleHelp(), "ToggleHelp");
+    view_listener_t::addMenu(new LLToggleSpeak(), "ToggleSpeak");
+    view_listener_t::addMenu(new LLPromptShowURL(), "PromptShowURL");
+    view_listener_t::addMenu(new LLShowAgentProfile(), "ShowAgentProfile");
     view_listener_t::addMenu(new LLShowAgentProfilePicks(), "ShowAgentProfilePicks");
-	view_listener_t::addMenu(new LLToggleAgentProfile(), "ToggleAgentProfile");
-	view_listener_t::addMenu(new LLToggleControl(), "ToggleControl");
+    view_listener_t::addMenu(new LLToggleAgentProfile(), "ToggleAgentProfile");
+    view_listener_t::addMenu(new LLToggleControl(), "ToggleControl");
     view_listener_t::addMenu(new LLToggleShaderControl(), "ToggleShaderControl");
-	view_listener_t::addMenu(new LLCheckControl(), "CheckControl");
-	view_listener_t::addMenu(new LLResetControl(), "ResetControl");
-	view_listener_t::addMenu(new LLGoToObject(), "GoToObject");
-	commit.add("PayObject", boost::bind(&handle_give_money_dialog));
-
-	commit.add("Inventory.NewWindow", boost::bind(&LLPanelMainInventory::newWindow));
-
-	enable.add("EnablePayObject", boost::bind(&enable_pay_object));
-	enable.add("EnablePayAvatar", boost::bind(&enable_pay_avatar));
-	enable.add("EnableEdit", boost::bind(&enable_object_edit));
-	enable.add("EnableMuteParticle", boost::bind(&enable_mute_particle));
-	enable.add("VisibleBuild", boost::bind(&enable_object_build));
-	commit.add("Pathfinding.Linksets.Select", boost::bind(&LLFloaterPathfindingLinksets::openLinksetsWithSelectedObjects));
-	enable.add("EnableSelectInPathfindingLinksets", boost::bind(&enable_object_select_in_pathfinding_linksets));
-	enable.add("VisibleSelectInPathfindingLinksets", boost::bind(&visible_object_select_in_pathfinding_linksets));
-	commit.add("Pathfinding.Characters.Select", boost::bind(&LLFloaterPathfindingCharacters::openCharactersWithSelectedObjects));
-	enable.add("EnableSelectInPathfindingCharacters", boost::bind(&enable_object_select_in_pathfinding_characters));
+    view_listener_t::addMenu(new LLCheckControl(), "CheckControl");
+    view_listener_t::addMenu(new LLResetControl(), "ResetControl");
+    view_listener_t::addMenu(new LLGoToObject(), "GoToObject");
+    commit.add("PayObject", boost::bind(&handle_give_money_dialog));
+
+    commit.add("Inventory.NewWindow", boost::bind(&LLPanelMainInventory::newWindow));
+
+    enable.add("EnablePayObject", boost::bind(&enable_pay_object));
+    enable.add("EnablePayAvatar", boost::bind(&enable_pay_avatar));
+    enable.add("EnableEdit", boost::bind(&enable_object_edit));
+    enable.add("EnableMuteParticle", boost::bind(&enable_mute_particle));
+    enable.add("VisibleBuild", boost::bind(&enable_object_build));
+    commit.add("Pathfinding.Linksets.Select", boost::bind(&LLFloaterPathfindingLinksets::openLinksetsWithSelectedObjects));
+    enable.add("EnableSelectInPathfindingLinksets", boost::bind(&enable_object_select_in_pathfinding_linksets));
+    enable.add("VisibleSelectInPathfindingLinksets", boost::bind(&visible_object_select_in_pathfinding_linksets));
+    commit.add("Pathfinding.Characters.Select", boost::bind(&LLFloaterPathfindingCharacters::openCharactersWithSelectedObjects));
+    enable.add("EnableSelectInPathfindingCharacters", boost::bind(&enable_object_select_in_pathfinding_characters));
     enable.add("Advanced.EnableErrorOSException", boost::bind(&enable_os_exception));
 
-	view_listener_t::addMenu(new LLFloaterVisible(), "FloaterVisible");
-	view_listener_t::addMenu(new LLShowSidetrayPanel(), "ShowSidetrayPanel");
-	view_listener_t::addMenu(new LLSidetrayPanelVisible(), "SidetrayPanelVisible");
-	view_listener_t::addMenu(new LLSomethingSelected(), "SomethingSelected");
-	view_listener_t::addMenu(new LLSomethingSelectedNoHUD(), "SomethingSelectedNoHUD");
-	view_listener_t::addMenu(new LLEditableSelected(), "EditableSelected");
-	view_listener_t::addMenu(new LLEditableSelectedMono(), "EditableSelectedMono");
-	view_listener_t::addMenu(new LLToggleUIHints(), "ToggleUIHints");
+    view_listener_t::addMenu(new LLFloaterVisible(), "FloaterVisible");
+    view_listener_t::addMenu(new LLShowSidetrayPanel(), "ShowSidetrayPanel");
+    view_listener_t::addMenu(new LLSidetrayPanelVisible(), "SidetrayPanelVisible");
+    view_listener_t::addMenu(new LLSomethingSelected(), "SomethingSelected");
+    view_listener_t::addMenu(new LLSomethingSelectedNoHUD(), "SomethingSelectedNoHUD");
+    view_listener_t::addMenu(new LLEditableSelected(), "EditableSelected");
+    view_listener_t::addMenu(new LLEditableSelectedMono(), "EditableSelectedMono");
+    view_listener_t::addMenu(new LLToggleUIHints(), "ToggleUIHints");
 
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	enable.add("RLV.MainToggleVisible", boost::bind(&rlvMenuMainToggleVisible, _1));
-	enable.add("RLV.CanShowName", boost::bind(&rlvMenuCanShowName));
-	enable.add("RLV.EnableIfNot", boost::bind(&rlvMenuEnableIfNot, _2));
+    enable.add("RLV.MainToggleVisible", boost::bind(&rlvMenuMainToggleVisible, _1));
+    enable.add("RLV.CanShowName", boost::bind(&rlvMenuCanShowName));
+    enable.add("RLV.EnableIfNot", boost::bind(&rlvMenuEnableIfNot, _2));
 // [/RLVa:KB]
 
-	ALViewerMenu::initialize_menus();
+    ALViewerMenu::initialize_menus();
 }
diff --git a/indra/newview/llviewermenufile.cpp b/indra/newview/llviewermenufile.cpp
index ca2d4fa7e91eee93907efdd16b08ccbb79badb70..9e3ff8f648f6e55f049d39fd9c59ba348a9bd9dd 100644
--- a/indra/newview/llviewermenufile.cpp
+++ b/indra/newview/llviewermenufile.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewermenufile.cpp
  * @brief "File" menu in the main menu bar.
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -48,17 +48,17 @@
 #include "llimagejpeg.h"
 #include "llimagetga.h"
 #include "llimagewebp.h"
-#include "llinventorymodel.h"	// gInventory
+#include "llinventorymodel.h"   // gInventory
 #include "llpluginclassmedia.h"
 #include "llresourcedata.h"
 #include "llstatusbar.h"
 #include "lltinygltfhelper.h"
 #include "lltoast.h"
-#include "llviewercontrol.h"	// gSavedSettings
+#include "llviewercontrol.h"    // gSavedSettings
 #include "llviewertexturelist.h"
 #include "lluictrlfactory.h"
 #include "llviewerinventory.h"
-#include "llviewermenu.h"	// gMenuHolder
+#include "llviewermenu.h"   // gMenuHolder
 #include "llviewerparcelmgr.h"
 #include "llviewerregion.h"
 #include "llviewerstats.h"
@@ -84,24 +84,24 @@
 
 class LLFileEnableUpload : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
         return true;
-	}
+    }
 };
 
 class LLFileEnableUploadModel : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		LLFloaterModelPreview* fmp = (LLFloaterModelPreview*) LLFloaterReg::findInstance("upload_model");
-		if (fmp && fmp->isModelLoading())
-		{
-			return false;
-		}
-
-		return true;
-	}
+        LLFloaterModelPreview* fmp = (LLFloaterModelPreview*) LLFloaterReg::findInstance("upload_model");
+        if (fmp && fmp->isModelLoading())
+        {
+            return false;
+        }
+
+        return true;
+    }
 };
 
 class LLFileEnableUploadMaterial : public view_listener_t
@@ -119,19 +119,19 @@ class LLFileEnableUploadMaterial : public view_listener_t
 
 class LLMeshEnabled : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		static const LLCachedControl<bool> mesh_enabled(gSavedSettings, "MeshEnabled", true);
-		return mesh_enabled;
-	}
+        static const LLCachedControl<bool> mesh_enabled(gSavedSettings, "MeshEnabled", true);
+        return mesh_enabled;
+    }
 };
 
 class LLMeshUploadVisible : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		return gMeshRepo.meshUploadEnabled();
-	}
+        return gMeshRepo.meshUploadEnabled();
+    }
 };
 
 LLMutex* LLFilePickerThread::sMutex = NULL;
@@ -141,51 +141,51 @@ void LLFilePickerThread::getFile()
 {
 #if (LL_WINDOWS && !LL_NFD) || (LL_LINUX && LL_NFD)
     // Todo: get rid of LLFilePickerThread and make this modeless
-	start();
+    start();
 #elif LL_DARWIN
     runModeless();
 #else
-	run();
+    run();
 #endif
 }
 
-//virtual 
+//virtual
 void LLFilePickerThread::run()
 {
 #if (LL_WINDOWS && !LL_NFD) || (LL_LINUX && LL_NFD)
-	bool blocking = false;
+    bool blocking = false;
 #else
-	bool blocking = true; // modal
+    bool blocking = true; // modal
 #endif
 
-	LLFilePicker picker;
-
-	if (mIsSaveDialog)
-	{
-		if (picker.getSaveFile(mSaveFilter, mProposedName, blocking))
-		{
-			mResponses.push_back(picker.getFirstFile());
-		}
-	}
-	else
-	{
-		bool result = mIsGetMultiple ? picker.getMultipleOpenFiles(mLoadFilter, blocking) : picker.getOpenFile(mLoadFilter, blocking);
-		if (result)
-		{
-			std::string filename = picker.getFirstFile(); // consider copying mFiles directly
-			do
-			{
-				mResponses.push_back(filename);
-				filename = picker.getNextFile();
-			}
-			while (mIsGetMultiple && !filename.empty());
-		}
-	}
-
-	{
-		LLMutexLock lock(sMutex);
-		sDeadQ.push(this);
-	}
+    LLFilePicker picker;
+
+    if (mIsSaveDialog)
+    {
+        if (picker.getSaveFile(mSaveFilter, mProposedName, blocking))
+        {
+            mResponses.push_back(picker.getFirstFile());
+        }
+    }
+    else
+    {
+        bool result = mIsGetMultiple ? picker.getMultipleOpenFiles(mLoadFilter, blocking) : picker.getOpenFile(mLoadFilter, blocking);
+        if (result)
+        {
+            std::string filename = picker.getFirstFile(); // consider copying mFiles directly
+            do
+            {
+                mResponses.push_back(filename);
+                filename = picker.getNextFile();
+            }
+            while (mIsGetMultiple && !filename.empty());
+        }
+    }
+
+    {
+        LLMutexLock lock(sMutex);
+        sDeadQ.push(this);
+    }
 }
 
 void LLFilePickerThread::runModeless()
@@ -208,7 +208,7 @@ void LLFilePickerThread::runModeless()
     {
         result = picker.getOpenFileModeless(mLoadFilter, modelessVectorCallback, this);
     }
-    
+
     if (!result)
     {
         LLMutexLock lock(sMutex);
@@ -225,7 +225,7 @@ void LLFilePickerThread::modelessStringCallback(bool success,
     {
         picker->mResponses.push_back(response);
     }
-    
+
     {
         LLMutexLock lock(sMutex);
         sDeadQ.push(picker);
@@ -257,7 +257,7 @@ void LLFilePickerThread::modelessVectorCallback(bool success,
             }
         }
     }
-    
+
     {
         LLMutexLock lock(sMutex);
         sDeadQ.push(picker);
@@ -267,66 +267,66 @@ void LLFilePickerThread::modelessVectorCallback(bool success,
 //static
 void LLFilePickerThread::initClass()
 {
-	sMutex = new LLMutex();
+    sMutex = new LLMutex();
 }
 
 //static
 void LLFilePickerThread::cleanupClass()
 {
-	clearDead();
-	
-	delete sMutex;
-	sMutex = NULL;
+    clearDead();
+
+    delete sMutex;
+    sMutex = NULL;
 }
 
 //static
 void LLFilePickerThread::clearDead()
 {
-	if (!sDeadQ.empty())
-	{
-		LLMutexLock lock(sMutex);
-		while (!sDeadQ.empty())
-		{
-			LLFilePickerThread* thread = sDeadQ.front();
-			thread->notify(thread->mResponses);
-			delete thread;
-			sDeadQ.pop();
-		}
-	}
+    if (!sDeadQ.empty())
+    {
+        LLMutexLock lock(sMutex);
+        while (!sDeadQ.empty())
+        {
+            LLFilePickerThread* thread = sDeadQ.front();
+            thread->notify(thread->mResponses);
+            delete thread;
+            sDeadQ.pop();
+        }
+    }
 }
 
 LLFilePickerReplyThread::LLFilePickerReplyThread(const file_picked_signal_t::slot_type& cb, LLFilePicker::ELoadFilter filter, bool get_multiple, const file_picked_signal_t::slot_type& failure_cb)
-	: LLFilePickerThread(filter, get_multiple),
-	mLoadFilter(filter),
-	mSaveFilter(LLFilePicker::FFSAVE_ALL),
-	mFilePickedSignal(NULL),
-	mFailureSignal(NULL)
+    : LLFilePickerThread(filter, get_multiple),
+    mLoadFilter(filter),
+    mSaveFilter(LLFilePicker::FFSAVE_ALL),
+    mFilePickedSignal(NULL),
+    mFailureSignal(NULL)
 {
-	mFilePickedSignal = new file_picked_signal_t();
-	mFilePickedSignal->connect(cb);
+    mFilePickedSignal = new file_picked_signal_t();
+    mFilePickedSignal->connect(cb);
 
-	mFailureSignal = new file_picked_signal_t();
-	mFailureSignal->connect(failure_cb);
+    mFailureSignal = new file_picked_signal_t();
+    mFailureSignal->connect(failure_cb);
 }
 
 LLFilePickerReplyThread::LLFilePickerReplyThread(const file_picked_signal_t::slot_type& cb, LLFilePicker::ESaveFilter filter, const std::string &proposed_name, const file_picked_signal_t::slot_type& failure_cb)
-	: LLFilePickerThread(filter, proposed_name),
-	mLoadFilter(LLFilePicker::FFLOAD_ALL),
-	mSaveFilter(filter),
-	mFilePickedSignal(NULL),
-	mFailureSignal(NULL)
+    : LLFilePickerThread(filter, proposed_name),
+    mLoadFilter(LLFilePicker::FFLOAD_ALL),
+    mSaveFilter(filter),
+    mFilePickedSignal(NULL),
+    mFailureSignal(NULL)
 {
-	mFilePickedSignal = new file_picked_signal_t();
-	mFilePickedSignal->connect(cb);
+    mFilePickedSignal = new file_picked_signal_t();
+    mFilePickedSignal->connect(cb);
 
-	mFailureSignal = new file_picked_signal_t();
-	mFailureSignal->connect(failure_cb);
+    mFailureSignal = new file_picked_signal_t();
+    mFailureSignal->connect(failure_cb);
 }
 
 LLFilePickerReplyThread::~LLFilePickerReplyThread()
 {
-	delete mFilePickedSignal;
-	delete mFailureSignal;
+    delete mFilePickedSignal;
+    delete mFailureSignal;
 }
 
 void LLFilePickerReplyThread::startPicker(const file_picked_signal_t::slot_type & cb, LLFilePicker::ELoadFilter filter, bool get_multiple, const file_picked_signal_t::slot_type & failure_cb)
@@ -341,20 +341,20 @@ void LLFilePickerReplyThread::startPicker(const file_picked_signal_t::slot_type
 
 void LLFilePickerReplyThread::notify(const std::vector<std::string>& filenames)
 {
-	if (filenames.empty())
-	{
-		if (mFailureSignal)
-		{
-			(*mFailureSignal)(filenames, mLoadFilter, mSaveFilter);
-		}
-	}
-	else
-	{
-		if (mFilePickedSignal)
-		{
-			(*mFilePickedSignal)(filenames, mLoadFilter, mSaveFilter);
-		}
-	}
+    if (filenames.empty())
+    {
+        if (mFailureSignal)
+        {
+            (*mFailureSignal)(filenames, mLoadFilter, mSaveFilter);
+        }
+    }
+    else
+    {
+        if (mFilePickedSignal)
+        {
+            (*mFilePickedSignal)(filenames, mLoadFilter, mSaveFilter);
+        }
+    }
 }
 
 
@@ -391,169 +391,169 @@ static std::string MATERIAL_EXTENSIONS = "gltf glb";
 
 std::string build_extensions_string(LLFilePicker::ELoadFilter filter)
 {
-	switch(filter)
-	{
+    switch(filter)
+    {
 #if LL_WINDOWS
-	case LLFilePicker::FFLOAD_IMAGE:
-		return IMAGE_EXTENSIONS;
-	case LLFilePicker::FFLOAD_WAV:
-		return SOUND_EXTENSIONS;
-	case LLFilePicker::FFLOAD_ANIM:
-		return ANIM_EXTENSIONS;
-	case LLFilePicker::FFLOAD_SLOBJECT:
-		return SLOBJECT_EXTENSIONS;
-	case LLFilePicker::FFLOAD_MODEL:
-		return MODEL_EXTENSIONS;
+    case LLFilePicker::FFLOAD_IMAGE:
+        return IMAGE_EXTENSIONS;
+    case LLFilePicker::FFLOAD_WAV:
+        return SOUND_EXTENSIONS;
+    case LLFilePicker::FFLOAD_ANIM:
+        return ANIM_EXTENSIONS;
+    case LLFilePicker::FFLOAD_SLOBJECT:
+        return SLOBJECT_EXTENSIONS;
+    case LLFilePicker::FFLOAD_MODEL:
+        return MODEL_EXTENSIONS;
     case LLFilePicker::FFLOAD_MATERIAL:
         return MATERIAL_EXTENSIONS;
-	case LLFilePicker::FFLOAD_XML:
-	    return XML_EXTENSIONS;
+    case LLFilePicker::FFLOAD_XML:
+        return XML_EXTENSIONS;
     case LLFilePicker::FFLOAD_ALL:
     case LLFilePicker::FFLOAD_EXE:
-		return ALL_FILE_EXTENSIONS;
+        return ALL_FILE_EXTENSIONS;
 #endif
     default:
-	return ALL_FILE_EXTENSIONS;
-	}
+    return ALL_FILE_EXTENSIONS;
+    }
 }
 
 
 const bool check_file_extension(const std::string& filename, LLFilePicker::ELoadFilter type)
 {
-	std::string ext = gDirUtilp->getExtension(filename);
-
-	//strincmp doesn't like NULL pointers
-	if (ext.empty())
-	{
-		std::string short_name = gDirUtilp->getBaseFileName(filename);
-
-		// No extension
-		LLSD args;
-		args["FILE"] = short_name;
-		LLNotificationsUtil::add("NoFileExtension", args);
-		return false;
-	}
-	else
-	{
-		//so there is an extension
-		//loop over the valid extensions and compare to see
-		//if the extension is valid
-
-		//now grab the set of valid file extensions
-		std::string valid_extensions = build_extensions_string(type);
-
-		BOOL ext_valid = FALSE;
-
-		typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
-		boost::char_separator<char> sep(" ");
-		tokenizer tokens(valid_extensions, sep);
-		tokenizer::iterator token_iter;
-
-		//now loop over all valid file extensions
-		//and compare them to the extension of the file
-		//to be uploaded
-		for (token_iter = tokens.begin();
-			token_iter != tokens.end() && ext_valid != TRUE;
-			++token_iter)
-		{
-			const std::string& cur_token = *token_iter;
-
-			if (cur_token == ext || cur_token == "*.*")
-			{
-				//valid extension
-				//or the acceptable extension is any
-				ext_valid = TRUE;
-			}
-		}//end for (loop over all tokens)
-
-		if (ext_valid == FALSE)
-		{
-			//should only get here if the extension exists
-			//but is invalid
-			LLSD args;
-			args["EXTENSION"] = ext;
-			args["VALIDS"] = valid_extensions;
-			LLNotificationsUtil::add("InvalidFileExtension", args);
-			return false;
-		}
-	}//end else (non-null extension)
-	return true;
+    std::string ext = gDirUtilp->getExtension(filename);
+
+    //strincmp doesn't like NULL pointers
+    if (ext.empty())
+    {
+        std::string short_name = gDirUtilp->getBaseFileName(filename);
+
+        // No extension
+        LLSD args;
+        args["FILE"] = short_name;
+        LLNotificationsUtil::add("NoFileExtension", args);
+        return false;
+    }
+    else
+    {
+        //so there is an extension
+        //loop over the valid extensions and compare to see
+        //if the extension is valid
+
+        //now grab the set of valid file extensions
+        std::string valid_extensions = build_extensions_string(type);
+
+        BOOL ext_valid = FALSE;
+
+        typedef boost::tokenizer<boost::char_separator<char> > tokenizer;
+        boost::char_separator<char> sep(" ");
+        tokenizer tokens(valid_extensions, sep);
+        tokenizer::iterator token_iter;
+
+        //now loop over all valid file extensions
+        //and compare them to the extension of the file
+        //to be uploaded
+        for (token_iter = tokens.begin();
+            token_iter != tokens.end() && ext_valid != TRUE;
+            ++token_iter)
+        {
+            const std::string& cur_token = *token_iter;
+
+            if (cur_token == ext || cur_token == "*.*")
+            {
+                //valid extension
+                //or the acceptable extension is any
+                ext_valid = TRUE;
+            }
+        }//end for (loop over all tokens)
+
+        if (ext_valid == FALSE)
+        {
+            //should only get here if the extension exists
+            //but is invalid
+            LLSD args;
+            args["EXTENSION"] = ext;
+            args["VALIDS"] = valid_extensions;
+            LLNotificationsUtil::add("InvalidFileExtension", args);
+            return false;
+        }
+    }//end else (non-null extension)
+    return true;
 }
 
 const void upload_single_file(const std::vector<std::string>& filenames, LLFilePicker::ELoadFilter type)
 {
-	std::string filename = filenames[0];
-	if (!check_file_extension(filename, type)) return;
-	
-	if (!filename.empty())
-	{
-		if (type == LLFilePicker::FFLOAD_WAV)
-		{
-			// pre-qualify wavs to make sure the format is acceptable
-			std::string error_msg;
-			if (check_for_invalid_wav_formats(filename, error_msg))
-			{
-				LL_INFOS() << error_msg << ": " << filename << LL_ENDL;
-				LLSD args;
-				args["FILE"] = filename;
-				LLNotificationsUtil::add(error_msg, args);
-				return;
-			}
-		}
-
-		std::string floater_name;
-
-		switch (type)
-		{
-		case LLFilePicker::FFLOAD_ANIM:
-		{
-			std::string filename_lc(filename);
-			LLStringUtil::toLower(filename_lc);
-			floater_name = (filename_lc.rfind(".anim") != std::string::npos) ? "upload_anim_anim" : "upload_anim_bvh";
-		}
-		break;
-		case LLFilePicker::FFLOAD_IMAGE:
-			floater_name = "upload_image";
-			break;
-		case LLFilePicker::FFLOAD_WAV:
-			floater_name = "upload_sound";
-			break;
-		case LLFilePicker::FFLOAD_MODEL:
-			if (LLFloaterModelPreview* pFloaterModelPreview = LLFloaterReg::getTypedInstance<LLFloaterModelPreview>("upload_model"))
-				pFloaterModelPreview->loadModel(LLModel::LOD_HIGH, filename);
-			return;
-		case LLFilePicker::FFLOAD_GLTF:
-			LLMaterialEditor::loadMaterialFromFile(filename, -1);
-			return;
-		default:
-			break;
-		}
-
-		if (!floater_name.empty())
-		{
-			LLFloaterReg::showInstance(floater_name, LLSD(filename));
-		}
-	}
-	return;
+    std::string filename = filenames[0];
+    if (!check_file_extension(filename, type)) return;
+
+    if (!filename.empty())
+    {
+        if (type == LLFilePicker::FFLOAD_WAV)
+        {
+            // pre-qualify wavs to make sure the format is acceptable
+            std::string error_msg;
+            if (check_for_invalid_wav_formats(filename, error_msg))
+            {
+                LL_INFOS() << error_msg << ": " << filename << LL_ENDL;
+                LLSD args;
+                args["FILE"] = filename;
+                LLNotificationsUtil::add(error_msg, args);
+                return;
+            }
+        }
+
+        std::string floater_name;
+
+        switch (type)
+        {
+        case LLFilePicker::FFLOAD_ANIM:
+        {
+            std::string filename_lc(filename);
+            LLStringUtil::toLower(filename_lc);
+            floater_name = (filename_lc.rfind(".anim") != std::string::npos) ? "upload_anim_anim" : "upload_anim_bvh";
+        }
+        break;
+        case LLFilePicker::FFLOAD_IMAGE:
+            floater_name = "upload_image";
+            break;
+        case LLFilePicker::FFLOAD_WAV:
+            floater_name = "upload_sound";
+            break;
+        case LLFilePicker::FFLOAD_MODEL:
+            if (LLFloaterModelPreview* pFloaterModelPreview = LLFloaterReg::getTypedInstance<LLFloaterModelPreview>("upload_model"))
+                pFloaterModelPreview->loadModel(LLModel::LOD_HIGH, filename);
+            return;
+        case LLFilePicker::FFLOAD_GLTF:
+            LLMaterialEditor::loadMaterialFromFile(filename, -1);
+            return;
+        default:
+            break;
+        }
+
+        if (!floater_name.empty())
+        {
+            LLFloaterReg::showInstance(floater_name, LLSD(filename));
+        }
+    }
+    return;
 }
 
 void do_bulk_upload(std::vector<std::string> filenames)
 {
-	for (std::vector<std::string>::const_iterator in_iter = filenames.begin(); in_iter != filenames.end(); ++in_iter)
-	{
-		std::string filename = (*in_iter);
-		
-		std::string name = gDirUtilp->getBaseFileName(filename, true);
-		std::string asset_name = name;
-		LLStringUtil::replaceNonstandardASCII(asset_name, '?');
-		LLStringUtil::replaceChar(asset_name, '|', '?');
-		LLStringUtil::stripNonprintable(asset_name);
-		LLStringUtil::trim(asset_name);
-
-		std::string ext = gDirUtilp->getExtension(filename);
-		LLAssetType::EType asset_type;
-		U32 codec;
-		S32 expected_upload_cost = 0;
+    for (std::vector<std::string>::const_iterator in_iter = filenames.begin(); in_iter != filenames.end(); ++in_iter)
+    {
+        std::string filename = (*in_iter);
+
+        std::string name = gDirUtilp->getBaseFileName(filename, true);
+        std::string asset_name = name;
+        LLStringUtil::replaceNonstandardASCII(asset_name, '?');
+        LLStringUtil::replaceChar(asset_name, '|', '?');
+        LLStringUtil::stripNonprintable(asset_name);
+        LLStringUtil::trim(asset_name);
+
+        std::string ext = gDirUtilp->getExtension(filename);
+        LLAssetType::EType asset_type;
+        U32 codec;
+        S32 expected_upload_cost = 0;
 
         if (LLResourceUploadInfo::findAssetTypeAndCodecOfExtension(ext, asset_type, codec))
         {
@@ -610,31 +610,31 @@ void do_bulk_upload(std::vector<std::string> filenames)
 
 void do_bulk_upload(std::vector<std::string> filenames, const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (option != 0)
-	{
-		// Cancel upload
-		return;
-	}
-
-	do_bulk_upload(filenames);
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (option != 0)
+    {
+        // Cancel upload
+        return;
+    }
+
+    do_bulk_upload(filenames);
 }
 
 bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S32& total_cost, S32& file_count)
 {
-	total_cost = 0;
-	file_count = 0;
-	for (std::vector<std::string>::const_iterator in_iter = filenames.begin(); in_iter != filenames.end(); ++in_iter)
-	{
-		std::string filename = (*in_iter);
-		std::string ext = gDirUtilp->getExtension(filename);
-
-		LLAssetType::EType asset_type;
-		U32 codec;
-		S32 cost;
-
-		if (LLResourceUploadInfo::findAssetTypeAndCodecOfExtension(ext, asset_type, codec))
-		{
+    total_cost = 0;
+    file_count = 0;
+    for (std::vector<std::string>::const_iterator in_iter = filenames.begin(); in_iter != filenames.end(); ++in_iter)
+    {
+        std::string filename = (*in_iter);
+        std::string ext = gDirUtilp->getExtension(filename);
+
+        LLAssetType::EType asset_type;
+        U32 codec;
+        S32 cost;
+
+        if (LLResourceUploadInfo::findAssetTypeAndCodecOfExtension(ext, asset_type, codec))
+        {
             if (asset_type == LLAssetType::AT_TEXTURE)
             {
                 LLPointer<LLImageFormatted> image_frmted = LLImageFormatted::createFromType(codec);
@@ -690,89 +690,89 @@ bool get_bulk_upload_expected_cost(const std::vector<std::string>& filenames, S3
                 }
             }
         }
-	}
-	
+    }
+
     return file_count > 0;
 }
 
 const void upload_bulk(const std::vector<std::string>& filenames, LLFilePicker::ELoadFilter type)
 {
-	// TODO:
-	// Check user balance for entire cost
-	// Charge user entire cost
-	// Loop, uploading
-	// If an upload fails, refund the user for that one
-	//
-	// Also fix single upload to charge first, then refund
-
-	// FIXME PREMIUM what about known types that can't be bulk uploaded
-	// (bvh)? These will fail in the item by item upload but won't be
-	// mentioned in the notification.
-	std::vector<std::string> filtered_filenames;
-	for (std::vector<std::string>::const_iterator in_iter = filenames.begin(); in_iter != filenames.end(); ++in_iter)
-	{
-		const std::string& filename = *in_iter;
-		if (check_file_extension(filename, type))
-		{
-			filtered_filenames.push_back(filename);
-		}
-	}
-
-	S32 expected_upload_cost;
-	S32 expected_upload_count;
-	if (get_bulk_upload_expected_cost(filtered_filenames, expected_upload_cost, expected_upload_count))
-	{
-		static LLCachedControl<bool> sPowerfulWizard(gSavedSettings, "AlchemyPowerfulWizard", false);
-		if (sPowerfulWizard && expected_upload_cost == 0)
-		{
-			do_bulk_upload(filtered_filenames);
-		}
-		else
-		{
-			LLSD args;
-			args["COST"] = expected_upload_cost;
-			args["COUNT"] = expected_upload_count;
-
-			std::string strUploadList;
-			for (const std::string& filename : filtered_filenames)
-				strUploadList += gDirUtilp->getBaseFileName(filename) + "\n";
-			args["FILES"] = strUploadList;
-
-			LLNotificationsUtil::add("BulkUploadCostConfirmation", args, LLSD(), boost::bind(do_bulk_upload, filtered_filenames, _1, _2));
-		}
-
-		if (filtered_filenames.size() > expected_upload_count)
-		{
-			LLNotificationsUtil::add("BulkUploadIncompatibleFiles");
-		}
-	}
-	else
-	{
-		LLNotificationsUtil::add("BulkUploadNoCompatibleFiles");
-	}
+    // TODO:
+    // Check user balance for entire cost
+    // Charge user entire cost
+    // Loop, uploading
+    // If an upload fails, refund the user for that one
+    //
+    // Also fix single upload to charge first, then refund
+
+    // FIXME PREMIUM what about known types that can't be bulk uploaded
+    // (bvh)? These will fail in the item by item upload but won't be
+    // mentioned in the notification.
+    std::vector<std::string> filtered_filenames;
+    for (std::vector<std::string>::const_iterator in_iter = filenames.begin(); in_iter != filenames.end(); ++in_iter)
+    {
+        const std::string& filename = *in_iter;
+        if (check_file_extension(filename, type))
+        {
+            filtered_filenames.push_back(filename);
+        }
+    }
+
+    S32 expected_upload_cost;
+    S32 expected_upload_count;
+    if (get_bulk_upload_expected_cost(filtered_filenames, expected_upload_cost, expected_upload_count))
+    {
+        static LLCachedControl<bool> sPowerfulWizard(gSavedSettings, "AlchemyPowerfulWizard", false);
+        if (sPowerfulWizard && expected_upload_cost == 0)
+        {
+            do_bulk_upload(filtered_filenames);
+        }
+        else
+        {
+            LLSD args;
+            args["COST"] = expected_upload_cost;
+            args["COUNT"] = expected_upload_count;
+
+            std::string strUploadList;
+            for (const std::string& filename : filtered_filenames)
+                strUploadList += gDirUtilp->getBaseFileName(filename) + "\n";
+            args["FILES"] = strUploadList;
+
+            LLNotificationsUtil::add("BulkUploadCostConfirmation", args, LLSD(), boost::bind(do_bulk_upload, filtered_filenames, _1, _2));
+        }
+
+        if (filtered_filenames.size() > expected_upload_count)
+        {
+            LLNotificationsUtil::add("BulkUploadIncompatibleFiles");
+        }
+    }
+    else
+    {
+        LLNotificationsUtil::add("BulkUploadNoCompatibleFiles");
+    }
 
 }
 
 class LLFileUploadImage : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		if (gAgentCamera.cameraMouselook())
-		{
-			gAgentCamera.changeCameraToDefault();
-		}
-		LLFilePickerReplyThread::startPicker(boost::bind(&upload_single_file, _1, _2), LLFilePicker::FFLOAD_IMAGE, false);
-		return true;
-	}
+        if (gAgentCamera.cameraMouselook())
+        {
+            gAgentCamera.changeCameraToDefault();
+        }
+        LLFilePickerReplyThread::startPicker(boost::bind(&upload_single_file, _1, _2), LLFilePicker::FFLOAD_IMAGE, false);
+        return true;
+    }
 };
 
 class LLFileUploadModel : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
         LLFloaterModelPreview::showModelPreview();
         return TRUE;
-	}
+    }
 };
 
 class LLFileUploadMaterial : public view_listener_t
@@ -786,216 +786,216 @@ class LLFileUploadMaterial : public view_listener_t
 
 class LLFileUploadSound : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		if (gAgentCamera.cameraMouselook())
-		{
-			gAgentCamera.changeCameraToDefault();
-		}
-		LLFilePickerReplyThread::startPicker(boost::bind(&upload_single_file, _1, _2), LLFilePicker::FFLOAD_WAV, false);
-		return true;
-	}
+        if (gAgentCamera.cameraMouselook())
+        {
+            gAgentCamera.changeCameraToDefault();
+        }
+        LLFilePickerReplyThread::startPicker(boost::bind(&upload_single_file, _1, _2), LLFilePicker::FFLOAD_WAV, false);
+        return true;
+    }
 };
 
 class LLFileUploadAnim : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		if (gAgentCamera.cameraMouselook())
-		{
-			gAgentCamera.changeCameraToDefault();
-		}
-		LLFilePickerReplyThread::startPicker(boost::bind(&upload_single_file, _1, _2), LLFilePicker::FFLOAD_ANIM, false);
-		return true;
-	}
+        if (gAgentCamera.cameraMouselook())
+        {
+            gAgentCamera.changeCameraToDefault();
+        }
+        LLFilePickerReplyThread::startPicker(boost::bind(&upload_single_file, _1, _2), LLFilePicker::FFLOAD_ANIM, false);
+        return true;
+    }
 };
 
 class LLFileUploadBulk : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		if (gAgentCamera.cameraMouselook())
-		{
-			gAgentCamera.changeCameraToDefault();
-		}
-		LLFilePickerReplyThread::startPicker(boost::bind(&upload_bulk, _1, _2), LLFilePicker::FFLOAD_ALL, true);
-		return true;
-	}
+        if (gAgentCamera.cameraMouselook())
+        {
+            gAgentCamera.changeCameraToDefault();
+        }
+        LLFilePickerReplyThread::startPicker(boost::bind(&upload_bulk, _1, _2), LLFilePicker::FFLOAD_ALL, true);
+        return true;
+    }
 };
 
-void upload_error(const std::string& error_message, const std::string& label, const std::string& filename, const LLSD& args) 
+void upload_error(const std::string& error_message, const std::string& label, const std::string& filename, const LLSD& args)
 {
-	LL_WARNS() << error_message << LL_ENDL;
-	LLNotificationsUtil::add(label, args);
-	if(LLFile::remove(filename) == -1)
-	{
-		LL_DEBUGS() << "unable to remove temp file" << LL_ENDL;
-	}
-	LLFilePicker::instance().reset();						
+    LL_WARNS() << error_message << LL_ENDL;
+    LLNotificationsUtil::add(label, args);
+    if(LLFile::remove(filename) == -1)
+    {
+        LL_DEBUGS() << "unable to remove temp file" << LL_ENDL;
+    }
+    LLFilePicker::instance().reset();
 }
 
 class LLFileEnableCloseWindow : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		bool frontmost_fl_exists = (NULL != gFloaterView->getFrontmostClosableFloater());
-		bool frontmost_snapshot_fl_exists = (NULL != gSnapshotFloaterView->getFrontmostClosableFloater());
+        bool frontmost_fl_exists = (NULL != gFloaterView->getFrontmostClosableFloater());
+        bool frontmost_snapshot_fl_exists = (NULL != gSnapshotFloaterView->getFrontmostClosableFloater());
 
-		return !LLNotificationsUI::LLToast::isAlertToastShown() && (frontmost_fl_exists || frontmost_snapshot_fl_exists);
-	}
+        return !LLNotificationsUI::LLToast::isAlertToastShown() && (frontmost_fl_exists || frontmost_snapshot_fl_exists);
+    }
 };
 
 class LLFileCloseWindow : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		bool frontmost_fl_exists = (NULL != gFloaterView->getFrontmostClosableFloater());
-		LLFloater* snapshot_floater = gSnapshotFloaterView->getFrontmostClosableFloater();
-
-		if(snapshot_floater && (!frontmost_fl_exists || snapshot_floater->hasFocus()))
-		{
-			snapshot_floater->closeFloater();
-			if (gFocusMgr.getKeyboardFocus() == NULL)
-			{
-				gFloaterView->focusFrontFloater();
-			}
-		}
-		else
-		{
-			LLFloater::closeFrontmostFloater();
-		}
-		if (gMenuHolder) gMenuHolder->hideMenus();
-		return true;
-	}
+        bool frontmost_fl_exists = (NULL != gFloaterView->getFrontmostClosableFloater());
+        LLFloater* snapshot_floater = gSnapshotFloaterView->getFrontmostClosableFloater();
+
+        if(snapshot_floater && (!frontmost_fl_exists || snapshot_floater->hasFocus()))
+        {
+            snapshot_floater->closeFloater();
+            if (gFocusMgr.getKeyboardFocus() == NULL)
+            {
+                gFloaterView->focusFrontFloater();
+            }
+        }
+        else
+        {
+            LLFloater::closeFrontmostFloater();
+        }
+        if (gMenuHolder) gMenuHolder->hideMenus();
+        return true;
+    }
 };
 
 class LLFileEnableCloseAllWindows : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		LLFloaterSnapshot* floater_snapshot = LLFloaterSnapshot::findInstance();
-		bool is_floaters_snapshot_opened = (floater_snapshot && floater_snapshot->isInVisibleChain());
-		bool open_children = gFloaterView->allChildrenClosed() && !is_floaters_snapshot_opened;
-		return !open_children && !LLNotificationsUI::LLToast::isAlertToastShown();
-	}
+        LLFloaterSnapshot* floater_snapshot = LLFloaterSnapshot::findInstance();
+        bool is_floaters_snapshot_opened = (floater_snapshot && floater_snapshot->isInVisibleChain());
+        bool open_children = gFloaterView->allChildrenClosed() && !is_floaters_snapshot_opened;
+        return !open_children && !LLNotificationsUI::LLToast::isAlertToastShown();
+    }
 };
 
 class LLFileCloseAllWindows : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		bool app_quitting = false;
-		gFloaterView->closeAllChildren(app_quitting);
-		LLFloaterSnapshot* floater_snapshot = LLFloaterSnapshot::findInstance();
-		if (floater_snapshot)
-			floater_snapshot->closeFloater(app_quitting);
-		if (gMenuHolder) gMenuHolder->hideMenus();
-		return true;
-	}
+        bool app_quitting = false;
+        gFloaterView->closeAllChildren(app_quitting);
+        LLFloaterSnapshot* floater_snapshot = LLFloaterSnapshot::findInstance();
+        if (floater_snapshot)
+            floater_snapshot->closeFloater(app_quitting);
+        if (gMenuHolder) gMenuHolder->hideMenus();
+        return true;
+    }
 };
 
 class LLFileTakeSnapshotToDisk : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		LLPointer<LLImageRaw> raw = new LLImageRaw;
-
-		S32 width = gViewerWindow->getWindowWidthRaw();
-		S32 height = gViewerWindow->getWindowHeightRaw();
-
-		BOOL render_ui = gSavedSettings.getBOOL("RenderUIInSnapshot");
-		BOOL render_hud = gSavedSettings.getBOOL("RenderHUDInSnapshot");
-		BOOL render_no_post = gSavedSettings.getBOOL("RenderSnapshotNoPost");
-
-		BOOL high_res = gSavedSettings.getBOOL("HighResSnapshot");
-		if (high_res)
-		{
-			width *= 2;
-			height *= 2;
-			// not compatible with UI/HUD
-			render_ui = false;
-			render_hud = false;
-		}
-
-		if (gViewerWindow->rawSnapshot(raw,
-									   width,
-									   height,
-									   TRUE,
-									   FALSE,
-									   render_ui,
-									   render_hud,
-									   FALSE,
-									   render_no_post,
-									   LLSnapshotModel::SNAPSHOT_TYPE_COLOR,
-									   high_res ? S32_MAX : MAX_SNAPSHOT_IMAGE_SIZE)) //per side
-		{
-			LLPointer<LLImageFormatted> formatted;
+        LLPointer<LLImageRaw> raw = new LLImageRaw;
+
+        S32 width = gViewerWindow->getWindowWidthRaw();
+        S32 height = gViewerWindow->getWindowHeightRaw();
+
+        BOOL render_ui = gSavedSettings.getBOOL("RenderUIInSnapshot");
+        BOOL render_hud = gSavedSettings.getBOOL("RenderHUDInSnapshot");
+        BOOL render_no_post = gSavedSettings.getBOOL("RenderSnapshotNoPost");
+
+        BOOL high_res = gSavedSettings.getBOOL("HighResSnapshot");
+        if (high_res)
+        {
+            width *= 2;
+            height *= 2;
+            // not compatible with UI/HUD
+            render_ui = false;
+            render_hud = false;
+        }
+
+        if (gViewerWindow->rawSnapshot(raw,
+                                       width,
+                                       height,
+                                       TRUE,
+                                       FALSE,
+                                       render_ui,
+                                       render_hud,
+                                       FALSE,
+                                       render_no_post,
+                                       LLSnapshotModel::SNAPSHOT_TYPE_COLOR,
+                                       high_res ? S32_MAX : MAX_SNAPSHOT_IMAGE_SIZE)) //per side
+        {
+            LLPointer<LLImageFormatted> formatted;
             LLSnapshotModel::ESnapshotFormat fmt = (LLSnapshotModel::ESnapshotFormat) gSavedSettings.getS32("SnapshotFormat");
-			switch (fmt)
-			{
-			case LLSnapshotModel::SNAPSHOT_FORMAT_JPEG:
-				formatted = new LLImageJPEG(gSavedSettings.getS32("SnapshotQuality"));
-				break;
-			default:
-				LL_WARNS() << "Unknown local snapshot format: " << fmt << LL_ENDL;
-			case LLSnapshotModel::SNAPSHOT_FORMAT_PNG:
-				formatted = new LLImagePNG;
-				break;
-			case LLSnapshotModel::SNAPSHOT_FORMAT_BMP:
-				formatted = new LLImageBMP;
-				break;
-			case LLSnapshotModel::SNAPSHOT_FORMAT_WEBP:
-				formatted = new LLImageWebP;
-				break;
-			}
-			formatted->enableOverSize() ;
-			formatted->encode(raw, 0);
-			formatted->disableOverSize() ;
-			LLSnapshotLivePreview::saveLocal(formatted);
-		}
-		return true;
-	}
+            switch (fmt)
+            {
+            case LLSnapshotModel::SNAPSHOT_FORMAT_JPEG:
+                formatted = new LLImageJPEG(gSavedSettings.getS32("SnapshotQuality"));
+                break;
+            default:
+                LL_WARNS() << "Unknown local snapshot format: " << fmt << LL_ENDL;
+            case LLSnapshotModel::SNAPSHOT_FORMAT_PNG:
+                formatted = new LLImagePNG;
+                break;
+            case LLSnapshotModel::SNAPSHOT_FORMAT_BMP:
+                formatted = new LLImageBMP;
+                break;
+            case LLSnapshotModel::SNAPSHOT_FORMAT_WEBP:
+                formatted = new LLImageWebP;
+                break;
+            }
+            formatted->enableOverSize() ;
+            formatted->encode(raw, 0);
+            formatted->disableOverSize() ;
+            LLSnapshotLivePreview::saveLocal(formatted);
+        }
+        return true;
+    }
 };
 
 class LLFileQuit : public view_listener_t
 {
-	bool handleEvent(const LLSD& userdata) override
+    bool handleEvent(const LLSD& userdata) override
     {
-		LLAppViewer::instance()->userQuit();
-		return true;
-	}
+        LLAppViewer::instance()->userQuit();
+        return true;
+    }
 };
 
 
 void handle_compress_image(void*)
 {
-	LLFilePicker& picker = LLFilePicker::instance();
-	if (picker.getMultipleOpenFiles(LLFilePicker::FFLOAD_IMAGE))
-	{
-		std::string infile = picker.getFirstFile();
-		while (!infile.empty())
-		{
-			std::string outfile = infile + ".j2c";
-
-			LL_INFOS() << "Input:  " << infile << LL_ENDL;
-			LL_INFOS() << "Output: " << outfile << LL_ENDL;
-
-			BOOL success;
-
-			success = LLViewerTextureList::createUploadFile(infile, outfile, IMG_CODEC_TGA);
-
-			if (success)
-			{
-				LL_INFOS() << "Compression complete" << LL_ENDL;
-			}
-			else
-			{
+    LLFilePicker& picker = LLFilePicker::instance();
+    if (picker.getMultipleOpenFiles(LLFilePicker::FFLOAD_IMAGE))
+    {
+        std::string infile = picker.getFirstFile();
+        while (!infile.empty())
+        {
+            std::string outfile = infile + ".j2c";
+
+            LL_INFOS() << "Input:  " << infile << LL_ENDL;
+            LL_INFOS() << "Output: " << outfile << LL_ENDL;
+
+            BOOL success;
+
+            success = LLViewerTextureList::createUploadFile(infile, outfile, IMG_CODEC_TGA);
+
+            if (success)
+            {
+                LL_INFOS() << "Compression complete" << LL_ENDL;
+            }
+            else
+            {
                 LL_INFOS() << "Compression failed: " << LLImage::getLastThreadError() << LL_ENDL;
-			}
+            }
 
-			infile = picker.getNextFile();
-		}
-	}
+            infile = picker.getNextFile();
+        }
+    }
 }
 
 // No convinient check in LLFile, and correct way would be something
@@ -1003,7 +1003,7 @@ void handle_compress_image(void*)
 // so doing dirty, but OS independent fopen and fseek
 size_t get_file_size(std::string &filename)
 {
-    LLFILE* file = LLFile::fopen(filename, "rb");		/*Flawfinder: ignore*/
+    LLFILE* file = LLFile::fopen(filename, "rb");       /*Flawfinder: ignore*/
     if (!file)
     {
         LL_WARNS() << "Error opening " << filename << LL_ENDL;
@@ -1088,21 +1088,21 @@ void handle_compress_file_test(void*)
 
 
 LLUUID upload_new_resource(
-	const std::string& src_filename,
-	std::string name,
-	std::string desc,
-	S32 compression_info,
-	LLFolderType::EType destination_folder_type,
-	LLInventoryType::EType inv_type,
-	U32 next_owner_perms,
-	U32 group_perms,
-	U32 everyone_perms,
-	const std::string& display_name,
-	LLAssetStorage::LLStoreAssetCallback callback,
-	S32 expected_upload_cost,
-	void *userdata,
-	bool show_inventory)
-{	
+    const std::string& src_filename,
+    std::string name,
+    std::string desc,
+    S32 compression_info,
+    LLFolderType::EType destination_folder_type,
+    LLInventoryType::EType inv_type,
+    U32 next_owner_perms,
+    U32 group_perms,
+    U32 everyone_perms,
+    const std::string& display_name,
+    LLAssetStorage::LLStoreAssetCallback callback,
+    S32 expected_upload_cost,
+    void *userdata,
+    bool show_inventory)
+{
 
     LLResourceUploadInfo::ptr_t uploadInfo(std::make_shared<LLNewFileResourceUploadInfo>(
         src_filename,
@@ -1116,127 +1116,127 @@ LLUUID upload_new_resource(
 }
 
 void upload_done_callback(
-	const LLUUID& uuid,
-	void* user_data,
-	S32 result,
-	LLExtStat ext_status) // StoreAssetData callback (fixed)
+    const LLUUID& uuid,
+    void* user_data,
+    S32 result,
+    LLExtStat ext_status) // StoreAssetData callback (fixed)
 {
-	LLResourceData* data = (LLResourceData*)user_data;
-	S32 expected_upload_cost = data ? data->mExpectedUploadCost : 0;
-	//LLAssetType::EType pref_loc = data->mPreferredLocation;
-	BOOL is_balance_sufficient = TRUE;
-
-	if(data)
-	{
-		if (result >= 0)
-		{
-			LLFolderType::EType dest_loc = (data->mPreferredLocation == LLFolderType::FT_NONE) ? LLFolderType::assetTypeToFolderType(data->mAssetInfo.mType) : data->mPreferredLocation;
-			
-			if (LLAssetType::AT_SOUND == data->mAssetInfo.mType ||
-			    LLAssetType::AT_TEXTURE == data->mAssetInfo.mType ||
-			    LLAssetType::AT_ANIMATION == data->mAssetInfo.mType)
-			{
-				// Charge the user for the upload.
-				LLViewerRegion* region = gAgent.getRegion();
-				
-				if(!(can_afford_transaction(expected_upload_cost)))
-				{
-					LLBuyCurrencyHTML::openCurrencyFloater( "", expected_upload_cost );
-					is_balance_sufficient = FALSE;
-				}
-				else if(region)
-				{
-					// Charge user for upload
-					gStatusBar->debitBalance(expected_upload_cost);
-					
-					LLMessageSystem* msg = gMessageSystem;
-					msg->newMessageFast(_PREHASH_MoneyTransferRequest);
-					msg->nextBlockFast(_PREHASH_AgentData);
-					msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-					msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-					msg->nextBlockFast(_PREHASH_MoneyData);
-					msg->addUUIDFast(_PREHASH_SourceID, gAgent.getID());
-					msg->addUUIDFast(_PREHASH_DestID, LLUUID::null);
-					msg->addU8Fast(_PREHASH_Flags, 0);
-					// we tell the sim how much we were expecting to pay so it
-					// can respond to any discrepancy
-					msg->addS32Fast(_PREHASH_Amount, expected_upload_cost);
-					msg->addU8Fast(_PREHASH_AggregatePermNextOwner, (U8)LLAggregatePermissions::AP_EMPTY);
-					msg->addU8Fast(_PREHASH_AggregatePermInventory, (U8)LLAggregatePermissions::AP_EMPTY);
-					msg->addS32Fast(_PREHASH_TransactionType, TRANS_UPLOAD_CHARGE);
-					msg->addStringFast(_PREHASH_Description, NULL);
-					msg->sendReliable(region->getHost());
-				}
-			}
-
-			if(is_balance_sufficient)
-			{
-				// Actually add the upload to inventory
-				LL_INFOS() << "Adding " << uuid << " to inventory." << LL_ENDL;
-				const LLUUID folder_id = gInventory.findCategoryUUIDForType(dest_loc);
-				if(folder_id.notNull())
-				{
-					U32 next_owner_perms = data->mNextOwnerPerm;
-					if(PERM_NONE == next_owner_perms)
-					{
-						next_owner_perms = PERM_MOVE | PERM_TRANSFER;
-					}
-					create_inventory_item(gAgent.getID(), gAgent.getSessionID(),
-							      folder_id, data->mAssetInfo.mTransactionID, data->mAssetInfo.getName(),
-							      data->mAssetInfo.getDescription(), data->mAssetInfo.mType,
+    LLResourceData* data = (LLResourceData*)user_data;
+    S32 expected_upload_cost = data ? data->mExpectedUploadCost : 0;
+    //LLAssetType::EType pref_loc = data->mPreferredLocation;
+    BOOL is_balance_sufficient = TRUE;
+
+    if(data)
+    {
+        if (result >= 0)
+        {
+            LLFolderType::EType dest_loc = (data->mPreferredLocation == LLFolderType::FT_NONE) ? LLFolderType::assetTypeToFolderType(data->mAssetInfo.mType) : data->mPreferredLocation;
+
+            if (LLAssetType::AT_SOUND == data->mAssetInfo.mType ||
+                LLAssetType::AT_TEXTURE == data->mAssetInfo.mType ||
+                LLAssetType::AT_ANIMATION == data->mAssetInfo.mType)
+            {
+                // Charge the user for the upload.
+                LLViewerRegion* region = gAgent.getRegion();
+
+                if(!(can_afford_transaction(expected_upload_cost)))
+                {
+                    LLBuyCurrencyHTML::openCurrencyFloater( "", expected_upload_cost );
+                    is_balance_sufficient = FALSE;
+                }
+                else if(region)
+                {
+                    // Charge user for upload
+                    gStatusBar->debitBalance(expected_upload_cost);
+
+                    LLMessageSystem* msg = gMessageSystem;
+                    msg->newMessageFast(_PREHASH_MoneyTransferRequest);
+                    msg->nextBlockFast(_PREHASH_AgentData);
+                    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+                    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+                    msg->nextBlockFast(_PREHASH_MoneyData);
+                    msg->addUUIDFast(_PREHASH_SourceID, gAgent.getID());
+                    msg->addUUIDFast(_PREHASH_DestID, LLUUID::null);
+                    msg->addU8Fast(_PREHASH_Flags, 0);
+                    // we tell the sim how much we were expecting to pay so it
+                    // can respond to any discrepancy
+                    msg->addS32Fast(_PREHASH_Amount, expected_upload_cost);
+                    msg->addU8Fast(_PREHASH_AggregatePermNextOwner, (U8)LLAggregatePermissions::AP_EMPTY);
+                    msg->addU8Fast(_PREHASH_AggregatePermInventory, (U8)LLAggregatePermissions::AP_EMPTY);
+                    msg->addS32Fast(_PREHASH_TransactionType, TRANS_UPLOAD_CHARGE);
+                    msg->addStringFast(_PREHASH_Description, NULL);
+                    msg->sendReliable(region->getHost());
+                }
+            }
+
+            if(is_balance_sufficient)
+            {
+                // Actually add the upload to inventory
+                LL_INFOS() << "Adding " << uuid << " to inventory." << LL_ENDL;
+                const LLUUID folder_id = gInventory.findCategoryUUIDForType(dest_loc);
+                if(folder_id.notNull())
+                {
+                    U32 next_owner_perms = data->mNextOwnerPerm;
+                    if(PERM_NONE == next_owner_perms)
+                    {
+                        next_owner_perms = PERM_MOVE | PERM_TRANSFER;
+                    }
+                    create_inventory_item(gAgent.getID(), gAgent.getSessionID(),
+                                  folder_id, data->mAssetInfo.mTransactionID, data->mAssetInfo.getName(),
+                                  data->mAssetInfo.getDescription(), data->mAssetInfo.mType,
                                   data->mInventoryType, NO_INV_SUBTYPE, next_owner_perms,
-							      LLPointer<LLInventoryCallback>(NULL));
-				}
-				else
-				{
-					LL_WARNS() << "Can't find a folder to put it in" << LL_ENDL;
-				}
-			}
-		}
-		else // 	if(result >= 0)
-		{
-			LLSD args;
-			args["FILE"] = LLInventoryType::lookupHumanReadable(data->mInventoryType);
-			args["REASON"] = std::string(LLAssetStorage::getErrorString(result));
-			LLNotificationsUtil::add("CannotUploadReason", args);
-		}
-
-		delete data;
-		data = NULL;
-	}
-
-	LLUploadDialog::modalUploadFinished();
-
-	// *NOTE: This is a pretty big hack. What this does is check the
-	// file picker if there are any more pending uploads. If so,
-	// upload that file.
-	const std::string& next_file = LLFilePicker::instance().getNextFile();
-	if(is_balance_sufficient && !next_file.empty())
-	{
-		std::string asset_name = gDirUtilp->getBaseFileName(next_file, true);
-		LLStringUtil::replaceNonstandardASCII( asset_name, '?' );
-		LLStringUtil::replaceChar(asset_name, '|', '?');
-		LLStringUtil::stripNonprintable(asset_name);
-		LLStringUtil::trim(asset_name);
-
-		std::string display_name = LLStringUtil::null;
-		LLAssetStorage::LLStoreAssetCallback callback;
-		void *userdata = NULL;
-		upload_new_resource(
-			next_file,
-			asset_name,
-			asset_name,	// file
-			0,
-			LLFolderType::FT_NONE,
-			LLInventoryType::IT_NONE,
-			LLFloaterPerms::getNextOwnerPerms("Uploads"),
-			LLFloaterPerms::getGroupPerms("Uploads"),
-			LLFloaterPerms::getEveryonePerms("Uploads"),
-			display_name,
-			callback,
-			expected_upload_cost, // assuming next in a group of uploads is of roughly the same type, i.e. same upload cost
-			userdata);
-	}
+                                  LLPointer<LLInventoryCallback>(NULL));
+                }
+                else
+                {
+                    LL_WARNS() << "Can't find a folder to put it in" << LL_ENDL;
+                }
+            }
+        }
+        else //     if(result >= 0)
+        {
+            LLSD args;
+            args["FILE"] = LLInventoryType::lookupHumanReadable(data->mInventoryType);
+            args["REASON"] = std::string(LLAssetStorage::getErrorString(result));
+            LLNotificationsUtil::add("CannotUploadReason", args);
+        }
+
+        delete data;
+        data = NULL;
+    }
+
+    LLUploadDialog::modalUploadFinished();
+
+    // *NOTE: This is a pretty big hack. What this does is check the
+    // file picker if there are any more pending uploads. If so,
+    // upload that file.
+    const std::string& next_file = LLFilePicker::instance().getNextFile();
+    if(is_balance_sufficient && !next_file.empty())
+    {
+        std::string asset_name = gDirUtilp->getBaseFileName(next_file, true);
+        LLStringUtil::replaceNonstandardASCII( asset_name, '?' );
+        LLStringUtil::replaceChar(asset_name, '|', '?');
+        LLStringUtil::stripNonprintable(asset_name);
+        LLStringUtil::trim(asset_name);
+
+        std::string display_name = LLStringUtil::null;
+        LLAssetStorage::LLStoreAssetCallback callback;
+        void *userdata = NULL;
+        upload_new_resource(
+            next_file,
+            asset_name,
+            asset_name, // file
+            0,
+            LLFolderType::FT_NONE,
+            LLInventoryType::IT_NONE,
+            LLFloaterPerms::getNextOwnerPerms("Uploads"),
+            LLFloaterPerms::getGroupPerms("Uploads"),
+            LLFloaterPerms::getEveryonePerms("Uploads"),
+            display_name,
+            callback,
+            expected_upload_cost, // assuming next in a group of uploads is of roughly the same type, i.e. same upload cost
+            userdata);
+    }
 }
 
 void upload_new_resource(
@@ -1244,90 +1244,90 @@ void upload_new_resource(
     LLAssetStorage::LLStoreAssetCallback callback,
     void *userdata)
 {
-	if(gDisconnected)
-	{
-		return ;
-	}
+    if(gDisconnected)
+    {
+        return ;
+    }
 
 //     uploadInfo->setAssetType(assetType);
 //     uploadInfo->setTransactionId(tid);
 
 
-	std::string url = gAgent.getRegionCapability("NewFileAgentInventory");
+    std::string url = gAgent.getRegionCapability("NewFileAgentInventory");
 
-	if ( !url.empty() )
-	{
+    if ( !url.empty() )
+    {
         LLViewerAssetUpload::EnqueueInventoryUpload(url, uploadInfo);
-	}
-	else
-	{
+    }
+    else
+    {
         uploadInfo->prepareUpload();
         uploadInfo->logPreparedUpload();
 
-		LL_INFOS() << "NewAgentInventory capability not found, new agent inventory via asset system." << LL_ENDL;
-		// check for adequate funds
-		// TODO: do this check on the sim
-		if (LLAssetType::AT_SOUND == uploadInfo->getAssetType() ||
+        LL_INFOS() << "NewAgentInventory capability not found, new agent inventory via asset system." << LL_ENDL;
+        // check for adequate funds
+        // TODO: do this check on the sim
+        if (LLAssetType::AT_SOUND == uploadInfo->getAssetType() ||
             LLAssetType::AT_TEXTURE == uploadInfo->getAssetType() ||
             LLAssetType::AT_ANIMATION == uploadInfo->getAssetType())
-		{
-			S32 balance = gStatusBar->getBalance();
-			if (balance < uploadInfo->getExpectedUploadCost())
-			{
-				// insufficient funds, bail on this upload
+        {
+            S32 balance = gStatusBar->getBalance();
+            if (balance < uploadInfo->getExpectedUploadCost())
+            {
+                // insufficient funds, bail on this upload
                 LLBuyCurrencyHTML::openCurrencyFloater("", uploadInfo->getExpectedUploadCost());
-				return;
-			}
-		}
+                return;
+            }
+        }
 
-		LLResourceData* data = new LLResourceData;
-		data->mAssetInfo.mTransactionID = uploadInfo->getTransactionId();
-		data->mAssetInfo.mUuid = uploadInfo->getAssetId();
+        LLResourceData* data = new LLResourceData;
+        data->mAssetInfo.mTransactionID = uploadInfo->getTransactionId();
+        data->mAssetInfo.mUuid = uploadInfo->getAssetId();
         data->mAssetInfo.mType = uploadInfo->getAssetType();
-		data->mAssetInfo.mCreatorID = gAgentID;
-		data->mInventoryType = uploadInfo->getInventoryType();
-		data->mNextOwnerPerm = uploadInfo->getNextOwnerPerms();
-		data->mExpectedUploadCost = uploadInfo->getExpectedUploadCost();
-		data->mUserData = userdata;
-		data->mAssetInfo.setName(uploadInfo->getName());
-		data->mAssetInfo.setDescription(uploadInfo->getDescription());
-		data->mPreferredLocation = uploadInfo->getDestinationFolderType();
-
-		LLAssetStorage::LLStoreAssetCallback asset_callback = &upload_done_callback;
-		if (callback)
-		{
-			asset_callback = callback;
-		}
-		gAssetStorage->storeAssetData(
-			data->mAssetInfo.mTransactionID,
-			data->mAssetInfo.mType,
-			asset_callback,
-			(void*)data,
-			FALSE);
-	}
+        data->mAssetInfo.mCreatorID = gAgentID;
+        data->mInventoryType = uploadInfo->getInventoryType();
+        data->mNextOwnerPerm = uploadInfo->getNextOwnerPerms();
+        data->mExpectedUploadCost = uploadInfo->getExpectedUploadCost();
+        data->mUserData = userdata;
+        data->mAssetInfo.setName(uploadInfo->getName());
+        data->mAssetInfo.setDescription(uploadInfo->getDescription());
+        data->mPreferredLocation = uploadInfo->getDestinationFolderType();
+
+        LLAssetStorage::LLStoreAssetCallback asset_callback = &upload_done_callback;
+        if (callback)
+        {
+            asset_callback = callback;
+        }
+        gAssetStorage->storeAssetData(
+            data->mAssetInfo.mTransactionID,
+            data->mAssetInfo.mType,
+            asset_callback,
+            (void*)data,
+            FALSE);
+    }
 }
 
 
 void init_menu_file()
 {
-	view_listener_t::addCommit(new LLFileUploadImage(), "File.UploadImage");
-	view_listener_t::addCommit(new LLFileUploadSound(), "File.UploadSound");
-	view_listener_t::addCommit(new LLFileUploadAnim(), "File.UploadAnim");
-	view_listener_t::addCommit(new LLFileUploadModel(), "File.UploadModel");
+    view_listener_t::addCommit(new LLFileUploadImage(), "File.UploadImage");
+    view_listener_t::addCommit(new LLFileUploadSound(), "File.UploadSound");
+    view_listener_t::addCommit(new LLFileUploadAnim(), "File.UploadAnim");
+    view_listener_t::addCommit(new LLFileUploadModel(), "File.UploadModel");
     view_listener_t::addCommit(new LLFileUploadMaterial(), "File.UploadMaterial");
-	view_listener_t::addCommit(new LLFileUploadBulk(), "File.UploadBulk");
-	view_listener_t::addCommit(new LLFileCloseWindow(), "File.CloseWindow");
-	view_listener_t::addCommit(new LLFileCloseAllWindows(), "File.CloseAllWindows");
-	view_listener_t::addEnable(new LLFileEnableCloseWindow(), "File.EnableCloseWindow");
-	view_listener_t::addEnable(new LLFileEnableCloseAllWindows(), "File.EnableCloseAllWindows");
-	view_listener_t::addCommit(new LLFileTakeSnapshotToDisk(), "File.TakeSnapshotToDisk");
-	view_listener_t::addCommit(new LLFileQuit(), "File.Quit");
-
-	view_listener_t::addEnable(new LLFileEnableUpload(), "File.EnableUpload");
-	view_listener_t::addEnable(new LLFileEnableUploadModel(), "File.EnableUploadModel");
+    view_listener_t::addCommit(new LLFileUploadBulk(), "File.UploadBulk");
+    view_listener_t::addCommit(new LLFileCloseWindow(), "File.CloseWindow");
+    view_listener_t::addCommit(new LLFileCloseAllWindows(), "File.CloseAllWindows");
+    view_listener_t::addEnable(new LLFileEnableCloseWindow(), "File.EnableCloseWindow");
+    view_listener_t::addEnable(new LLFileEnableCloseAllWindows(), "File.EnableCloseAllWindows");
+    view_listener_t::addCommit(new LLFileTakeSnapshotToDisk(), "File.TakeSnapshotToDisk");
+    view_listener_t::addCommit(new LLFileQuit(), "File.Quit");
+
+    view_listener_t::addEnable(new LLFileEnableUpload(), "File.EnableUpload");
+    view_listener_t::addEnable(new LLFileEnableUploadModel(), "File.EnableUploadModel");
     view_listener_t::addEnable(new LLFileEnableUploadMaterial(), "File.EnableUploadMaterial");
-	view_listener_t::addMenu(new LLMeshEnabled(), "File.MeshEnabled");
-	view_listener_t::addMenu(new LLMeshUploadVisible(), "File.VisibleUploadModel");
+    view_listener_t::addMenu(new LLMeshEnabled(), "File.MeshEnabled");
+    view_listener_t::addMenu(new LLMeshUploadVisible(), "File.VisibleUploadModel");
 
-	// "File.SaveTexture" moved to llpanelmaininventory so that it can be properly handled.
+    // "File.SaveTexture" moved to llpanelmaininventory so that it can be properly handled.
 }
diff --git a/indra/newview/llviewermessage.cpp b/indra/newview/llviewermessage.cpp
index a3029bc745311ade5e2d83cf8dd0147e497eb99c..18f31b09062cebd62b15fe48d0fa4f85d5f160c1 100644
--- a/indra/newview/llviewermessage.cpp
+++ b/indra/newview/llviewermessage.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewermessage.cpp
  * @brief Dumping ground for viewer-side message system callbacks.
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -29,9 +29,9 @@
 
 // Linden libraries
 #include "llanimationstates.h"
-#include "llaudioengine.h" 
+#include "llaudioengine.h"
 #include "llavataractions.h"
-#include "llavatarnamecache.h"		// IDEVO HACK
+#include "llavatarnamecache.h"      // IDEVO HACK
 #include "lleconomy.h"
 #include "lleventtimer.h"
 #include "llfloatercreatelandmark.h"
@@ -93,7 +93,7 @@
 #include "lltrans.h"
 #include "lltranslate.h"
 #include "llviewerfoldertype.h"
-#include "llvoavatar.h"				// IDEVO HACK
+#include "llvoavatar.h"             // IDEVO HACK
 #include "lluri.h"
 #include "llviewergenericmessage.h"
 #include "llviewermenu.h"
@@ -146,8 +146,8 @@ const F32 CAMERA_POSITION_THRESHOLD_SQUARED = 0.001f * 0.001f;
 
 // Determine how quickly residents' scripts can issue question dialogs
 // Allow bursts of up to 5 dialogs in 10 seconds. 10*2=20 seconds recovery if throttle kicks in
-static const U32 LLREQUEST_PERMISSION_THROTTLE_LIMIT	= 5;     // requests
-static const F32 LLREQUEST_PERMISSION_THROTTLE_INTERVAL	= 10.0f; // seconds
+static const U32 LLREQUEST_PERMISSION_THROTTLE_LIMIT    = 5;     // requests
+static const F32 LLREQUEST_PERMISSION_THROTTLE_INTERVAL = 10.0f; // seconds
 
 extern BOOL gDebugClicks;
 extern bool gShiftFrame;
@@ -164,9 +164,9 @@ const U32 OFFER_THROTTLE_MAX_COUNT=5; //number of items per time period
 const F32 OFFER_THROTTLE_TIME=10.f; //time period in seconds
 
 // Agent Update Flags (U8)
-const U8 AU_FLAGS_NONE      		= 0x00;
-const U8 AU_FLAGS_HIDETITLE      	= 0x01;
-const U8 AU_FLAGS_CLIENT_AUTOPILOT	= 0x02;
+const U8 AU_FLAGS_NONE              = 0x00;
+const U8 AU_FLAGS_HIDETITLE         = 0x01;
+const U8 AU_FLAGS_CLIENT_AUTOPILOT  = 0x02;
 
 void accept_friendship_coro(std::string url, LLSD notification)
 {
@@ -263,24 +263,24 @@ void decline_friendship_coro(std::string url, LLSD notification, S32 option)
 
 bool friendship_offer_callback(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	LLMessageSystem* msg = gMessageSystem;
-	const LLSD& payload = notification["payload"];
-	LLNotificationPtr notification_ptr = LLNotifications::instance().find(notification["id"].asUUID());
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    LLMessageSystem* msg = gMessageSystem;
+    const LLSD& payload = notification["payload"];
+    LLNotificationPtr notification_ptr = LLNotifications::instance().find(notification["id"].asUUID());
 
     // this will be skipped if the user offering friendship is blocked
     if (notification_ptr)
     {
-	    switch(option)
-	    {
-	    case 0:
-	    {
-		    // accept
-		    LLAvatarTracker::formFriendship(payload["from_id"]);
+        switch(option)
+        {
+        case 0:
+        {
+            // accept
+            LLAvatarTracker::formFriendship(payload["from_id"]);
 
-		    const LLUUID fid = gInventory.findCategoryUUIDForType(LLFolderType::FT_CALLINGCARD);
+            const LLUUID fid = gInventory.findCategoryUUIDForType(LLFolderType::FT_CALLINGCARD);
 
-		    // This will also trigger an onlinenotification if the user is online
+            // This will also trigger an onlinenotification if the user is online
             std::string url = gAgent.getRegionCapability("AcceptFriendship");
             LL_DEBUGS("Friendship") << "Cap string: " << url << LL_ENDL;
             if (!url.empty() && payload.has("online") && payload["online"].asBoolean() == false)
@@ -311,14 +311,14 @@ bool friendship_offer_callback(const LLSD& notification, const LLSD& response)
             {
                 LL_WARNS("Friendship") << "Failed to accept friendship offer, neither capability nor transaction id are accessible" << LL_ENDL;
             }
-		    break;
-	    }
-	    case 1: // Decline
-	    // fall-through
-	    case 2: // Send IM - decline and start IM session
-		    {
-			    // decline
-			    // We no longer notify other viewers, but we DO still send
+            break;
+        }
+        case 1: // Decline
+        // fall-through
+        case 2: // Send IM - decline and start IM session
+            {
+                // decline
+                // We no longer notify other viewers, but we DO still send
                 // the rejection to the simulator to delete the pending userop.
                 std::string url = gAgent.getRegionCapability("DeclineFriendship");
                 LL_DEBUGS("Friendship") << "Cap string: " << url << LL_ENDL;
@@ -354,35 +354,35 @@ bool friendship_offer_callback(const LLSD& notification, const LLSD& response)
                 {
                     LL_WARNS("Friendship") << "Failed to decline friendship offer, neither capability nor transaction id are accessible" << LL_ENDL;
                 }
-	    }
-	    default:
-		    // close button probably, possibly timed out
-		    break;
-	    }
-
-		// TODO: this set of calls has undesirable behavior under Windows OS (CHUI-985):
-		// here appears three additional toasts instead one modified
-		// need investigation and fix
-
-	    // LLNotificationFormPtr modified_form(new LLNotificationForm(*notification_ptr->getForm()));
-	    // modified_form->setElementEnabled("Accept", false);
-	    // modified_form->setElementEnabled("Decline", false);
-	    // notification_ptr->updateForm(modified_form);
+        }
+        default:
+            // close button probably, possibly timed out
+            break;
+        }
+
+        // TODO: this set of calls has undesirable behavior under Windows OS (CHUI-985):
+        // here appears three additional toasts instead one modified
+        // need investigation and fix
+
+        // LLNotificationFormPtr modified_form(new LLNotificationForm(*notification_ptr->getForm()));
+        // modified_form->setElementEnabled("Accept", false);
+        // modified_form->setElementEnabled("Decline", false);
+        // notification_ptr->updateForm(modified_form);
 // [SL:KB] - Patch: UI-Notifications | Checked: 2013-05-09 (Catznip-3.5)
-//		// Assume that any offer notification with "getCanBeStored() == true" is the result of RLVa routing it to the notifcation syswell
-//		/*const*/ LLNotificationsUI::LLScreenChannel* pChannel = LLNotificationsUI::LLChannelManager::instance().getNotificationScreenChannel();
-//		/*const*/ LLNotificationsUI::LLToast* pToast = (pChannel) ? pChannel->getToastByNotificationID(notification["id"].asUUID()) : NULL;
-//		if ( (!pToast) || (!pToast->getCanBeStored()) )
-//		{
+//      // Assume that any offer notification with "getCanBeStored() == true" is the result of RLVa routing it to the notifcation syswell
+//      /*const*/ LLNotificationsUI::LLScreenChannel* pChannel = LLNotificationsUI::LLChannelManager::instance().getNotificationScreenChannel();
+//      /*const*/ LLNotificationsUI::LLToast* pToast = (pChannel) ? pChannel->getToastByNotificationID(notification["id"].asUUID()) : NULL;
+//      if ( (!pToast) || (!pToast->getCanBeStored()) )
+//      {
 // [/SL:KB]
-//			notification_ptr->repost();
+//          notification_ptr->repost();
 // [SL:KB] - Patch: UI-Notifications | Checked: 2013-05-09 (Catznip-3.5)
-//		}
+//      }
 // [/SL:KB]
 
     }
 
-	return false;
+    return false;
 }
 static LLNotificationFunctorRegistration friendship_offer_callback_reg("OfferFriendship", friendship_offer_callback);
 static LLNotificationFunctorRegistration friendship_offer_callback_reg_nm("OfferFriendshipNoMessage", friendship_offer_callback);
@@ -391,139 +391,139 @@ static LLNotificationFunctorRegistration friendship_offer_callback_reg_nm("Offer
 //
 
 void give_money(const LLUUID& uuid, LLViewerRegion* region, S32 amount, BOOL is_group,
-				S32 trx_type, const std::string& desc)
-{
-	if(0 == amount || !region) return;
-	amount = abs(amount);
-	LL_INFOS("Messaging") << "give_money(" << uuid << "," << amount << ")"<< LL_ENDL;
-	if(can_afford_transaction(amount))
-	{
-		if (uuid.isNull())
-		{
-			LL_WARNS() << "Failed to send L$ gift to to Null UUID." << LL_ENDL;
-			return;
-		}
-//		gStatusBar->debitBalance(amount);
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_MoneyTransferRequest);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+                S32 trx_type, const std::string& desc)
+{
+    if(0 == amount || !region) return;
+    amount = abs(amount);
+    LL_INFOS("Messaging") << "give_money(" << uuid << "," << amount << ")"<< LL_ENDL;
+    if(can_afford_transaction(amount))
+    {
+        if (uuid.isNull())
+        {
+            LL_WARNS() << "Failed to send L$ gift to to Null UUID." << LL_ENDL;
+            return;
+        }
+//      gStatusBar->debitBalance(amount);
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_MoneyTransferRequest);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_MoneyData);
-		msg->addUUIDFast(_PREHASH_SourceID, gAgent.getID() );
-		msg->addUUIDFast(_PREHASH_DestID, uuid);
-		msg->addU8Fast(_PREHASH_Flags, pack_transaction_flags(FALSE, is_group));
-		msg->addS32Fast(_PREHASH_Amount, amount);
-		msg->addU8Fast(_PREHASH_AggregatePermNextOwner, (U8)LLAggregatePermissions::AP_EMPTY);
-		msg->addU8Fast(_PREHASH_AggregatePermInventory, (U8)LLAggregatePermissions::AP_EMPTY);
-		msg->addS32Fast(_PREHASH_TransactionType, trx_type );
-		msg->addStringFast(_PREHASH_Description, desc);
-		msg->sendReliable(region->getHost());
-	}
-	else
-	{
-		LLStringUtil::format_map_t args;
-		args["AMOUNT"] = llformat("%d", amount);
-		LLBuyCurrencyHTML::openCurrencyFloater( LLTrans::getString("giving", args), amount );
-	}
+        msg->nextBlockFast(_PREHASH_MoneyData);
+        msg->addUUIDFast(_PREHASH_SourceID, gAgent.getID() );
+        msg->addUUIDFast(_PREHASH_DestID, uuid);
+        msg->addU8Fast(_PREHASH_Flags, pack_transaction_flags(FALSE, is_group));
+        msg->addS32Fast(_PREHASH_Amount, amount);
+        msg->addU8Fast(_PREHASH_AggregatePermNextOwner, (U8)LLAggregatePermissions::AP_EMPTY);
+        msg->addU8Fast(_PREHASH_AggregatePermInventory, (U8)LLAggregatePermissions::AP_EMPTY);
+        msg->addS32Fast(_PREHASH_TransactionType, trx_type );
+        msg->addStringFast(_PREHASH_Description, desc);
+        msg->sendReliable(region->getHost());
+    }
+    else
+    {
+        LLStringUtil::format_map_t args;
+        args["AMOUNT"] = llformat("%d", amount);
+        LLBuyCurrencyHTML::openCurrencyFloater( LLTrans::getString("giving", args), amount );
+    }
 }
 
 void send_complete_agent_movement(const LLHost& sim_host)
 {
-	LL_DEBUGS("Teleport", "Messaging") << "Sending CompleteAgentMovement to sim_host " << sim_host << LL_ENDL;
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_CompleteAgentMovement);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addU32Fast(_PREHASH_CircuitCode, msg->mOurCircuitCode);
-	msg->sendReliable(sim_host);
+    LL_DEBUGS("Teleport", "Messaging") << "Sending CompleteAgentMovement to sim_host " << sim_host << LL_ENDL;
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_CompleteAgentMovement);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addU32Fast(_PREHASH_CircuitCode, msg->mOurCircuitCode);
+    msg->sendReliable(sim_host);
 }
 
 void process_logout_reply(LLMessageSystem* msg, void**)
 {
-	// The server has told us it's ok to quit.
-	LL_DEBUGS("Messaging") << "process_logout_reply" << LL_ENDL;
-
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	LLUUID session_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
-	if((agent_id != gAgent.getID()) || (session_id != gAgent.getSessionID()))
-	{
-		LL_WARNS("Messaging") << "Bogus Logout Reply" << LL_ENDL;
-	}
-
-	LLInventoryModel::update_map_t parents;
-	S32 count = msg->getNumberOfBlocksFast( _PREHASH_InventoryData );
-	for(S32 i = 0; i < count; ++i)
-	{
-		LLUUID item_id;
-		msg->getUUIDFast(_PREHASH_InventoryData, _PREHASH_ItemID, item_id, i);
-
-		if( (1 == count) && item_id.isNull() )
-		{
-			// Detect dummy item.  Indicates an empty list.
-			break;
-		}
-
-		// We do not need to track the asset ids, just account for an
-		// updated inventory version.
-		LL_INFOS("Messaging") << "process_logout_reply itemID=" << item_id << LL_ENDL;
-		LLInventoryItem* item = gInventory.getItem( item_id );
-		if( item )
-		{
-			parents[item->getParentUUID()] = 0;
-			gInventory.addChangedMask(LLInventoryObserver::INTERNAL, item_id);
-		}
-		else
-		{
-			LL_INFOS("Messaging") << "process_logout_reply item not found: " << item_id << LL_ENDL;
-		}
-	}
+    // The server has told us it's ok to quit.
+    LL_DEBUGS("Messaging") << "process_logout_reply" << LL_ENDL;
+
+    LLUUID agent_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+    LLUUID session_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
+    if((agent_id != gAgent.getID()) || (session_id != gAgent.getSessionID()))
+    {
+        LL_WARNS("Messaging") << "Bogus Logout Reply" << LL_ENDL;
+    }
+
+    LLInventoryModel::update_map_t parents;
+    S32 count = msg->getNumberOfBlocksFast( _PREHASH_InventoryData );
+    for(S32 i = 0; i < count; ++i)
+    {
+        LLUUID item_id;
+        msg->getUUIDFast(_PREHASH_InventoryData, _PREHASH_ItemID, item_id, i);
+
+        if( (1 == count) && item_id.isNull() )
+        {
+            // Detect dummy item.  Indicates an empty list.
+            break;
+        }
+
+        // We do not need to track the asset ids, just account for an
+        // updated inventory version.
+        LL_INFOS("Messaging") << "process_logout_reply itemID=" << item_id << LL_ENDL;
+        LLInventoryItem* item = gInventory.getItem( item_id );
+        if( item )
+        {
+            parents[item->getParentUUID()] = 0;
+            gInventory.addChangedMask(LLInventoryObserver::INTERNAL, item_id);
+        }
+        else
+        {
+            LL_INFOS("Messaging") << "process_logout_reply item not found: " << item_id << LL_ENDL;
+        }
+    }
     LLAppViewer::instance()->forceQuit();
 }
 
 void process_layer_data(LLMessageSystem *mesgsys, void **user_data)
 {
-	LLViewerRegion *regionp = LLWorld::getInstance()->getRegion(mesgsys->getSender());
-
-	LL_DEBUGS_ONCE("SceneLoadTiming") << "Received layer data" << LL_ENDL;
-
-	if(!regionp)
-	{
-		LL_WARNS() << "Invalid region for layer data." << LL_ENDL;
-		return;
-	}
-	S32 size;
-	S8 type;
-
-	mesgsys->getS8Fast(_PREHASH_LayerID, _PREHASH_Type, type);
-	size = mesgsys->getSizeFast(_PREHASH_LayerData, _PREHASH_Data);
-	if (0 == size)
-	{
-		LL_WARNS("Messaging") << "Layer data has zero size." << LL_ENDL;
-		return;
-	}
-	if (size < 0)
-	{
-		// getSizeFast() is probably trying to tell us about an error
-		LL_WARNS("Messaging") << "getSizeFast() returned negative result: "
-			<< size
-			<< LL_ENDL;
-		return;
-	}
-	U8 *datap = new U8[size];
-	mesgsys->getBinaryDataFast(_PREHASH_LayerData, _PREHASH_Data, datap, size);
-	LLVLData *vl_datap = new LLVLData(regionp, type, datap, size);
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gVLManager.addLayerData(vl_datap, (S32Bytes)mesgsys->getReceiveCompressedSize());
-	}
-	else
-	{
-		gVLManager.addLayerData(vl_datap, (S32Bytes)mesgsys->getReceiveSize());
-	}
+    LLViewerRegion *regionp = LLWorld::getInstance()->getRegion(mesgsys->getSender());
+
+    LL_DEBUGS_ONCE("SceneLoadTiming") << "Received layer data" << LL_ENDL;
+
+    if(!regionp)
+    {
+        LL_WARNS() << "Invalid region for layer data." << LL_ENDL;
+        return;
+    }
+    S32 size;
+    S8 type;
+
+    mesgsys->getS8Fast(_PREHASH_LayerID, _PREHASH_Type, type);
+    size = mesgsys->getSizeFast(_PREHASH_LayerData, _PREHASH_Data);
+    if (0 == size)
+    {
+        LL_WARNS("Messaging") << "Layer data has zero size." << LL_ENDL;
+        return;
+    }
+    if (size < 0)
+    {
+        // getSizeFast() is probably trying to tell us about an error
+        LL_WARNS("Messaging") << "getSizeFast() returned negative result: "
+            << size
+            << LL_ENDL;
+        return;
+    }
+    U8 *datap = new U8[size];
+    mesgsys->getBinaryDataFast(_PREHASH_LayerData, _PREHASH_Data, datap, size);
+    LLVLData *vl_datap = new LLVLData(regionp, type, datap, size);
+    if (mesgsys->getReceiveCompressedSize())
+    {
+        gVLManager.addLayerData(vl_datap, (S32Bytes)mesgsys->getReceiveCompressedSize());
+    }
+    else
+    {
+        gVLManager.addLayerData(vl_datap, (S32Bytes)mesgsys->getReceiveSize());
+    }
 }
 
 // S32 exported_object_count = 0;
@@ -543,223 +543,223 @@ void process_layer_data(LLMessageSystem *mesgsys, void **user_data)
 
 // void export_complete()
 // {
-// 		LLUploadDialog::modalUploadFinished();
-// 		gExporterRequestID.setNull();
-// 		gExportDirectory = "";
-
-// 		LLFILE* fXML = LLFile::fopen(gExportedFile, "rb");		/* Flawfinder: ignore */
-// 		fseek(fXML, 0, SEEK_END);
-// 		long length = ftell(fXML);
-// 		fseek(fXML, 0, SEEK_SET);
-// 		U8 *buffer = new U8[length + 1];
-// 		size_t nread = fread(buffer, 1, length, fXML);
-// 		if (nread < (size_t) length)
-// 		{
-// 			LL_WARNS("Messaging") << "Short read" << LL_ENDL;
-// 		}
-// 		buffer[nread] = '\0';
-// 		fclose(fXML);
-
-// 		char *pos = (char *)buffer;
-// 		while ((pos = strstr(pos+1, "<sl:image ")) != 0)
-// 		{
-// 			char *pos_check = strstr(pos, "checksum=\"");
-
-// 			if (pos_check)
-// 			{
-// 				char *pos_uuid = strstr(pos_check, "\">");
-
-// 				if (pos_uuid)
-// 				{
-// 					char image_uuid_str[UUID_STR_SIZE];		/* Flawfinder: ignore */
-// 					memcpy(image_uuid_str, pos_uuid+2, UUID_STR_SIZE-1);		/* Flawfinder: ignore */
-// 					image_uuid_str[UUID_STR_SIZE-1] = 0;
-					
-// 					LLUUID image_uuid(image_uuid_str);
-
-// 					LL_INFOS("Messaging") << "Found UUID: " << image_uuid << LL_ENDL;
-
-// 					std::map<LLUUID, std::string>::iterator itor = gImageChecksums.find(image_uuid);
-// 					if (itor != gImageChecksums.end())
-// 					{
-// 						LL_INFOS("Messaging") << "Replacing with checksum: " << itor->second << LL_ENDL;
-// 						if (!itor->second.empty())
-// 						{
-// 							memcpy(&pos_check[10], itor->second.c_str(), 32);		/* Flawfinder: ignore */
-// 						}
-// 					}
-// 				}
-// 			}
-// 		}
-
-// 		LLFILE* fXMLOut = LLFile::fopen(gExportedFile, "wb");		/* Flawfinder: ignore */
-// 		if (fwrite(buffer, 1, length, fXMLOut) != length)
-// 		{
-// 			LL_WARNS("Messaging") << "Short write" << LL_ENDL;
-// 		}
-// 		fclose(fXMLOut);
-
-// 		delete [] buffer;
+//      LLUploadDialog::modalUploadFinished();
+//      gExporterRequestID.setNull();
+//      gExportDirectory = "";
+
+//      LLFILE* fXML = LLFile::fopen(gExportedFile, "rb");      /* Flawfinder: ignore */
+//      fseek(fXML, 0, SEEK_END);
+//      long length = ftell(fXML);
+//      fseek(fXML, 0, SEEK_SET);
+//      U8 *buffer = new U8[length + 1];
+//      size_t nread = fread(buffer, 1, length, fXML);
+//      if (nread < (size_t) length)
+//      {
+//          LL_WARNS("Messaging") << "Short read" << LL_ENDL;
+//      }
+//      buffer[nread] = '\0';
+//      fclose(fXML);
+
+//      char *pos = (char *)buffer;
+//      while ((pos = strstr(pos+1, "<sl:image ")) != 0)
+//      {
+//          char *pos_check = strstr(pos, "checksum=\"");
+
+//          if (pos_check)
+//          {
+//              char *pos_uuid = strstr(pos_check, "\">");
+
+//              if (pos_uuid)
+//              {
+//                  char image_uuid_str[UUID_STR_SIZE];     /* Flawfinder: ignore */
+//                  memcpy(image_uuid_str, pos_uuid+2, UUID_STR_SIZE-1);        /* Flawfinder: ignore */
+//                  image_uuid_str[UUID_STR_SIZE-1] = 0;
+
+//                  LLUUID image_uuid(image_uuid_str);
+
+//                  LL_INFOS("Messaging") << "Found UUID: " << image_uuid << LL_ENDL;
+
+//                  std::map<LLUUID, std::string>::iterator itor = gImageChecksums.find(image_uuid);
+//                  if (itor != gImageChecksums.end())
+//                  {
+//                      LL_INFOS("Messaging") << "Replacing with checksum: " << itor->second << LL_ENDL;
+//                      if (!itor->second.empty())
+//                      {
+//                          memcpy(&pos_check[10], itor->second.c_str(), 32);       /* Flawfinder: ignore */
+//                      }
+//                  }
+//              }
+//          }
+//      }
+
+//      LLFILE* fXMLOut = LLFile::fopen(gExportedFile, "wb");       /* Flawfinder: ignore */
+//      if (fwrite(buffer, 1, length, fXMLOut) != length)
+//      {
+//          LL_WARNS("Messaging") << "Short write" << LL_ENDL;
+//      }
+//      fclose(fXMLOut);
+
+//      delete [] buffer;
 // }
 
 
 // void exported_item_complete(const LLTSCode status, void *user_data)
 // {
-// 	//std::string *filename = (std::string *)user_data;
-
-// 	if (status < LLTS_OK)
-// 	{
-// 		LL_WARNS("Messaging") << "Export failed!" << LL_ENDL;
-// 	}
-// 	else
-// 	{
-// 		++current_object_count;
-// 		if (current_image_count == exported_image_count && current_object_count == exported_object_count)
-// 		{
-// 			LL_INFOS("Messaging") << "*** Export complete ***" << LL_ENDL;
-
-// 			export_complete();
-// 		}
-// 		else
-// 		{
-// 			gExportDialog->setMessage(llformat("Exported %d/%d object files, %d/%d textures.", current_object_count, exported_object_count, current_image_count, exported_image_count));
-// 		}
-// 	}
+//  //std::string *filename = (std::string *)user_data;
+
+//  if (status < LLTS_OK)
+//  {
+//      LL_WARNS("Messaging") << "Export failed!" << LL_ENDL;
+//  }
+//  else
+//  {
+//      ++current_object_count;
+//      if (current_image_count == exported_image_count && current_object_count == exported_object_count)
+//      {
+//          LL_INFOS("Messaging") << "*** Export complete ***" << LL_ENDL;
+
+//          export_complete();
+//      }
+//      else
+//      {
+//          gExportDialog->setMessage(llformat("Exported %d/%d object files, %d/%d textures.", current_object_count, exported_object_count, current_image_count, exported_image_count));
+//      }
+//  }
 // }
 
 // struct exported_image_info
 // {
-// 	LLUUID image_id;
-// 	std::string filename;
-// 	U32 image_num;
+//  LLUUID image_id;
+//  std::string filename;
+//  U32 image_num;
 // };
 
 // void exported_j2c_complete(const LLTSCode status, void *user_data)
 // {
-// 	exported_image_info *info = (exported_image_info *)user_data;
-// 	LLUUID image_id = info->image_id;
-// 	U32 image_num = info->image_num;
-// 	std::string filename = info->filename;
-// 	delete info;
-
-// 	if (status < LLTS_OK)
-// 	{
-// 		LL_WARNS("Messaging") << "Image download failed!" << LL_ENDL;
-// 	}
-// 	else
-// 	{
-// 		LLFILE* fIn = LLFile::fopen(filename, "rb");		/* Flawfinder: ignore */
-// 		if (fIn) 
-// 		{
-// 			LLPointer<LLImageJ2C> ImageUtility = new LLImageJ2C;
-// 			LLPointer<LLImageTGA> TargaUtility = new LLImageTGA;
-
-// 			fseek(fIn, 0, SEEK_END);
-// 			S32 length = ftell(fIn);
-// 			fseek(fIn, 0, SEEK_SET);
-// 			U8 *buffer = ImageUtility->allocateData(length);
-// 			if (fread(buffer, 1, length, fIn) != length)
-// 			{
-// 				LL_WARNS("Messaging") << "Short read" << LL_ENDL;
-// 			}
-// 			fclose(fIn);
-// 			LLFile::remove(filename);
-
-// 			// Convert to TGA
-// 			LLPointer<LLImageRaw> image = new LLImageRaw();
-
-// 			ImageUtility->updateData();
-// 			ImageUtility->decode(image, 100000.0f);
-			
-// 			TargaUtility->encode(image);
-// 			U8 *data = TargaUtility->getData();
-// 			S32 data_size = TargaUtility->getDataSize();
-
-// 			std::string file_path = gDirUtilp->getDirName(filename);
-			
-// 			std::string output_file = llformat("%s/image-%03d.tga", file_path.c_str(), image_num);//filename;
-// 			//S32 name_len = output_file.length();
-// 			//strcpy(&output_file[name_len-3], "tga");
-// 			LLFILE* fOut = LLFile::fopen(output_file, "wb");		/* Flawfinder: ignore */
-// 			char md5_hash_string[33];		/* Flawfinder: ignore */
-// 			strcpy(md5_hash_string, "00000000000000000000000000000000");		/* Flawfinder: ignore */
-// 			if (fOut)
-// 			{
-// 				if (fwrite(data, 1, data_size, fOut) != data_size)
-// 				{
-// 					LL_WARNS("Messaging") << "Short write" << LL_ENDL;
-// 				}
-// 				fseek(fOut, 0, SEEK_SET);
-// 				fclose(fOut);
-// 				fOut = LLFile::fopen(output_file, "rb");		/* Flawfinder: ignore */
-// 				LLMD5 my_md5_hash(fOut);
-// 				my_md5_hash.hex_digest(md5_hash_string);
-// 			}
-
-// 			gImageChecksums.insert(std::pair<LLUUID, std::string>(image_id, md5_hash_string));
-// 		}
-// 	}
-
-// 	++current_image_count;
-// 	if (current_image_count == exported_image_count && current_object_count == exported_object_count)
-// 	{
-// 		LL_INFOS("Messaging") << "*** Export textures complete ***" << LL_ENDL;
-// 			export_complete();
-// 	}
-// 	else
-// 	{
-// 		gExportDialog->setMessage(llformat("Exported %d/%d object files, %d/%d textures.", current_object_count, exported_object_count, current_image_count, exported_image_count));
-// 	}
+//  exported_image_info *info = (exported_image_info *)user_data;
+//  LLUUID image_id = info->image_id;
+//  U32 image_num = info->image_num;
+//  std::string filename = info->filename;
+//  delete info;
+
+//  if (status < LLTS_OK)
+//  {
+//      LL_WARNS("Messaging") << "Image download failed!" << LL_ENDL;
+//  }
+//  else
+//  {
+//      LLFILE* fIn = LLFile::fopen(filename, "rb");        /* Flawfinder: ignore */
+//      if (fIn)
+//      {
+//          LLPointer<LLImageJ2C> ImageUtility = new LLImageJ2C;
+//          LLPointer<LLImageTGA> TargaUtility = new LLImageTGA;
+
+//          fseek(fIn, 0, SEEK_END);
+//          S32 length = ftell(fIn);
+//          fseek(fIn, 0, SEEK_SET);
+//          U8 *buffer = ImageUtility->allocateData(length);
+//          if (fread(buffer, 1, length, fIn) != length)
+//          {
+//              LL_WARNS("Messaging") << "Short read" << LL_ENDL;
+//          }
+//          fclose(fIn);
+//          LLFile::remove(filename);
+
+//          // Convert to TGA
+//          LLPointer<LLImageRaw> image = new LLImageRaw();
+
+//          ImageUtility->updateData();
+//          ImageUtility->decode(image, 100000.0f);
+
+//          TargaUtility->encode(image);
+//          U8 *data = TargaUtility->getData();
+//          S32 data_size = TargaUtility->getDataSize();
+
+//          std::string file_path = gDirUtilp->getDirName(filename);
+
+//          std::string output_file = llformat("%s/image-%03d.tga", file_path.c_str(), image_num);//filename;
+//          //S32 name_len = output_file.length();
+//          //strcpy(&output_file[name_len-3], "tga");
+//          LLFILE* fOut = LLFile::fopen(output_file, "wb");        /* Flawfinder: ignore */
+//          char md5_hash_string[33];       /* Flawfinder: ignore */
+//          strcpy(md5_hash_string, "00000000000000000000000000000000");        /* Flawfinder: ignore */
+//          if (fOut)
+//          {
+//              if (fwrite(data, 1, data_size, fOut) != data_size)
+//              {
+//                  LL_WARNS("Messaging") << "Short write" << LL_ENDL;
+//              }
+//              fseek(fOut, 0, SEEK_SET);
+//              fclose(fOut);
+//              fOut = LLFile::fopen(output_file, "rb");        /* Flawfinder: ignore */
+//              LLMD5 my_md5_hash(fOut);
+//              my_md5_hash.hex_digest(md5_hash_string);
+//          }
+
+//          gImageChecksums.insert(std::pair<LLUUID, std::string>(image_id, md5_hash_string));
+//      }
+//  }
+
+//  ++current_image_count;
+//  if (current_image_count == exported_image_count && current_object_count == exported_object_count)
+//  {
+//      LL_INFOS("Messaging") << "*** Export textures complete ***" << LL_ENDL;
+//          export_complete();
+//  }
+//  else
+//  {
+//      gExportDialog->setMessage(llformat("Exported %d/%d object files, %d/%d textures.", current_object_count, exported_object_count, current_image_count, exported_image_count));
+//  }
 //}
 
 void process_derez_ack(LLMessageSystem*, void**)
 {
-	if(gViewerWindow) gViewerWindow->getWindow()->decBusyCount();
+    if(gViewerWindow) gViewerWindow->getWindow()->decBusyCount();
 }
 
 void process_places_reply(LLMessageSystem* msg, void** data)
 {
-	LLUUID query_id;
+    LLUUID query_id;
 
-	msg->getUUID("AgentData", "QueryID", query_id);
-	if (query_id.isNull())
-	{
-		LLFloaterLandHoldings::processPlacesReply(msg, data);
-	}
-	else if(gAgent.isInGroup(query_id))
-	{
-		LLPanelGroupLandMoney::processPlacesReply(msg, data);
-	}
-	else
-	{
-		LL_WARNS("Messaging") << "Got invalid PlacesReply message" << LL_ENDL;
-	}
+    msg->getUUID("AgentData", "QueryID", query_id);
+    if (query_id.isNull())
+    {
+        LLFloaterLandHoldings::processPlacesReply(msg, data);
+    }
+    else if(gAgent.isInGroup(query_id))
+    {
+        LLPanelGroupLandMoney::processPlacesReply(msg, data);
+    }
+    else
+    {
+        LL_WARNS("Messaging") << "Got invalid PlacesReply message" << LL_ENDL;
+    }
 }
 
 void send_sound_trigger(const LLUUID& sound_id, F32 gain)
 {
-	if (sound_id.isNull() || gAgent.getRegion() == NULL)
-	{
-		// disconnected agent or zero guids don't get sent (no sound)
-		return;
-	}
+    if (sound_id.isNull() || gAgent.getRegion() == NULL)
+    {
+        // disconnected agent or zero guids don't get sent (no sound)
+        return;
+    }
 
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_SoundTrigger);
-	msg->nextBlockFast(_PREHASH_SoundData);
-	msg->addUUIDFast(_PREHASH_SoundID, sound_id);
-	// Client untrusted, ids set on sim
-	msg->addUUIDFast(_PREHASH_OwnerID, LLUUID::null );
-	msg->addUUIDFast(_PREHASH_ObjectID, LLUUID::null );
-	msg->addUUIDFast(_PREHASH_ParentID, LLUUID::null );
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_SoundTrigger);
+    msg->nextBlockFast(_PREHASH_SoundData);
+    msg->addUUIDFast(_PREHASH_SoundID, sound_id);
+    // Client untrusted, ids set on sim
+    msg->addUUIDFast(_PREHASH_OwnerID, LLUUID::null );
+    msg->addUUIDFast(_PREHASH_ObjectID, LLUUID::null );
+    msg->addUUIDFast(_PREHASH_ParentID, LLUUID::null );
 
-	msg->addU64Fast(_PREHASH_Handle, gAgent.getRegion()->getHandle());
+    msg->addU64Fast(_PREHASH_Handle, gAgent.getRegion()->getHandle());
 
-	LLVector3 position = gAgent.getPositionAgent();
-	msg->addVector3Fast(_PREHASH_Position, position);
-	msg->addF32Fast(_PREHASH_Gain, gain);
+    LLVector3 position = gAgent.getPositionAgent();
+    msg->addVector3Fast(_PREHASH_Position, position);
+    msg->addF32Fast(_PREHASH_Gain, gain);
 
-	gAgent.sendMessage();
+    gAgent.sendMessage();
 }
 
 static LLSD sSavedGroupInvite;
@@ -882,122 +882,122 @@ void send_join_group_response(LLUUID group_id, LLUUID transaction_id, bool accep
 
 bool join_group_response(const LLSD& notification, const LLSD& response)
 {
-//	A bit of variable saving and restoring is used to deal with the case where your group list is full and you
-//	receive an invitation to another group.  The data from that invitation is stored in the sSaved
-//	variables.  If you then drop a group and click on the Join button the stored data is restored and used
-//	to join the group.
-	LLSD notification_adjusted = notification;
-	LLSD response_adjusted = response;
-
-	std::string action = notification["name"];
-
-//	Storing all the information by group id allows for the rare case of being at your maximum
-//	group count and receiving more than one invitation.
-	std::string id = notification_adjusted["payload"]["group_id"].asString();
-
-	if ("JoinGroup" == action || "JoinGroupCanAfford" == action)
-	{
-		sSavedGroupInvite[id] = notification;
-		sSavedResponse[id] = response;
-	}
-	else if ("JoinedTooManyGroupsMember" == action)
-	{
-		S32 opt = LLNotificationsUtil::getSelectedOption(notification, response);
-		if (0 == opt) // Join button pressed
-		{
-			notification_adjusted = sSavedGroupInvite[id];
-			response_adjusted = sSavedResponse[id];
-		}
-	}
-
-	S32 option = LLNotificationsUtil::getSelectedOption(notification_adjusted, response_adjusted);
-	bool accept_invite = false;
-
-	LLUUID group_id = notification_adjusted["payload"]["group_id"].asUUID();
-	LLUUID transaction_id = notification_adjusted["payload"]["transaction_id"].asUUID();
-	std::string name = notification_adjusted["payload"]["name"].asString();
-	std::string message = notification_adjusted["payload"]["message"].asString();
-	S32 fee = notification_adjusted["payload"]["fee"].asInteger();
-	U8 use_offline_cap = notification_adjusted["payload"]["use_offline_cap"].asInteger();
-
-	if (option == 2 && !group_id.isNull())
-	{
-		LLGroupActions::show(group_id);
-		LLSD args;
-		args["MESSAGE"] = message;
-		LLNotificationsUtil::add("JoinGroup", args, notification_adjusted["payload"]);
-		return false;
-	}
-
-	if(option == 0 && !group_id.isNull())
-	{
-		// check for promotion or demotion.
-		S32 max_groups = LLAgentBenefitsMgr::current().getGroupMembershipLimit();
-		if(gAgent.isInGroup(group_id)) ++max_groups;
-
-		if(gAgent.mGroups.size() < max_groups)
-		{
-			accept_invite = true;
-		}
-		else
-		{
-			LLSD args;
-			args["NAME"] = name;
-			LLNotificationsUtil::add("JoinedTooManyGroupsMember", args, notification_adjusted["payload"]);
-			return false;
-		}
-	}
-	send_join_group_response(group_id, transaction_id, accept_invite, fee, use_offline_cap, notification_adjusted["payload"]);
-
-	sSavedGroupInvite[id] = LLSD::emptyMap();
-	sSavedResponse[id] = LLSD::emptyMap();
-
-	return false;
+//  A bit of variable saving and restoring is used to deal with the case where your group list is full and you
+//  receive an invitation to another group.  The data from that invitation is stored in the sSaved
+//  variables.  If you then drop a group and click on the Join button the stored data is restored and used
+//  to join the group.
+    LLSD notification_adjusted = notification;
+    LLSD response_adjusted = response;
+
+    std::string action = notification["name"];
+
+//  Storing all the information by group id allows for the rare case of being at your maximum
+//  group count and receiving more than one invitation.
+    std::string id = notification_adjusted["payload"]["group_id"].asString();
+
+    if ("JoinGroup" == action || "JoinGroupCanAfford" == action)
+    {
+        sSavedGroupInvite[id] = notification;
+        sSavedResponse[id] = response;
+    }
+    else if ("JoinedTooManyGroupsMember" == action)
+    {
+        S32 opt = LLNotificationsUtil::getSelectedOption(notification, response);
+        if (0 == opt) // Join button pressed
+        {
+            notification_adjusted = sSavedGroupInvite[id];
+            response_adjusted = sSavedResponse[id];
+        }
+    }
+
+    S32 option = LLNotificationsUtil::getSelectedOption(notification_adjusted, response_adjusted);
+    bool accept_invite = false;
+
+    LLUUID group_id = notification_adjusted["payload"]["group_id"].asUUID();
+    LLUUID transaction_id = notification_adjusted["payload"]["transaction_id"].asUUID();
+    std::string name = notification_adjusted["payload"]["name"].asString();
+    std::string message = notification_adjusted["payload"]["message"].asString();
+    S32 fee = notification_adjusted["payload"]["fee"].asInteger();
+    U8 use_offline_cap = notification_adjusted["payload"]["use_offline_cap"].asInteger();
+
+    if (option == 2 && !group_id.isNull())
+    {
+        LLGroupActions::show(group_id);
+        LLSD args;
+        args["MESSAGE"] = message;
+        LLNotificationsUtil::add("JoinGroup", args, notification_adjusted["payload"]);
+        return false;
+    }
+
+    if(option == 0 && !group_id.isNull())
+    {
+        // check for promotion or demotion.
+        S32 max_groups = LLAgentBenefitsMgr::current().getGroupMembershipLimit();
+        if(gAgent.isInGroup(group_id)) ++max_groups;
+
+        if(gAgent.mGroups.size() < max_groups)
+        {
+            accept_invite = true;
+        }
+        else
+        {
+            LLSD args;
+            args["NAME"] = name;
+            LLNotificationsUtil::add("JoinedTooManyGroupsMember", args, notification_adjusted["payload"]);
+            return false;
+        }
+    }
+    send_join_group_response(group_id, transaction_id, accept_invite, fee, use_offline_cap, notification_adjusted["payload"]);
+
+    sSavedGroupInvite[id] = LLSD::emptyMap();
+    sSavedResponse[id] = LLSD::emptyMap();
+
+    return false;
 }
 
 static void highlight_inventory_objects_in_panel(const std::vector<LLUUID>& items, LLInventoryPanel *inventory_panel)
 {
-	if (NULL == inventory_panel) return;
-
-	for (std::vector<LLUUID>::const_iterator item_iter = items.begin();
-		item_iter != items.end();
-		++item_iter)
-	{
-		const LLUUID& item_id = (*item_iter);
-		if(!highlight_offered_object(item_id))
-		{
-			continue;
-		}
-
-		LLInventoryObject* item = gInventory.getObject(item_id);
-		llassert(item);
-		if (!item) {
-			continue;
-		}
-
-		LL_DEBUGS("Inventory_Move") << "Highlighting inventory item: " << item->getName() << ", " << item_id  << LL_ENDL;
-		LLFolderView* fv = inventory_panel->getRootFolder();
-		if (fv)
-		{
-			LLFolderViewItem* fv_item = inventory_panel->getItemByID(item_id);
-			if (fv_item)
-			{
-				LLFolderViewItem* fv_folder = fv_item->getParentFolder();
-				if (fv_folder)
-				{
-					// Parent folders can be different in case of 2 consecutive drag and drop
-					// operations when the second one is started before the first one completes.
-					LL_DEBUGS("Inventory_Move") << "Open folder: " << fv_folder->getName() << LL_ENDL;
-					fv_folder->setOpen(TRUE);
-					if (fv_folder->isSelected())
-					{
-						fv->changeSelection(fv_folder, FALSE);
-					}
-				}
-				fv->changeSelection(fv_item, TRUE);
-			}
-		}
-	}
+    if (NULL == inventory_panel) return;
+
+    for (std::vector<LLUUID>::const_iterator item_iter = items.begin();
+        item_iter != items.end();
+        ++item_iter)
+    {
+        const LLUUID& item_id = (*item_iter);
+        if(!highlight_offered_object(item_id))
+        {
+            continue;
+        }
+
+        LLInventoryObject* item = gInventory.getObject(item_id);
+        llassert(item);
+        if (!item) {
+            continue;
+        }
+
+        LL_DEBUGS("Inventory_Move") << "Highlighting inventory item: " << item->getName() << ", " << item_id  << LL_ENDL;
+        LLFolderView* fv = inventory_panel->getRootFolder();
+        if (fv)
+        {
+            LLFolderViewItem* fv_item = inventory_panel->getItemByID(item_id);
+            if (fv_item)
+            {
+                LLFolderViewItem* fv_folder = fv_item->getParentFolder();
+                if (fv_folder)
+                {
+                    // Parent folders can be different in case of 2 consecutive drag and drop
+                    // operations when the second one is started before the first one completes.
+                    LL_DEBUGS("Inventory_Move") << "Open folder: " << fv_folder->getName() << LL_ENDL;
+                    fv_folder->setOpen(TRUE);
+                    if (fv_folder->isSelected())
+                    {
+                        fv->changeSelection(fv_folder, FALSE);
+                    }
+                }
+                fv->changeSelection(fv_item, TRUE);
+            }
+        }
+    }
 }
 
 static LLNotificationFunctorRegistration jgr_1("JoinGroup", join_group_response);
@@ -1010,21 +1010,21 @@ static LLNotificationFunctorRegistration jgr_3("JoinGroupCanAfford", join_group_
 //-----------------------------------------------------------------------------
 /*virtual*/ void LLOpenAgentOffer::startFetch()
 {
-	for (uuid_vec_t::const_iterator it = mIDs.begin(); it < mIDs.end(); ++it)
-	{
-		LLViewerInventoryCategory* cat = gInventory.getCategory(*it);
-		if (cat)
-		{
-			mComplete.push_back((*it));
-		}
-	}
-	LLInventoryFetchItemsObserver::startFetch();
+    for (uuid_vec_t::const_iterator it = mIDs.begin(); it < mIDs.end(); ++it)
+    {
+        LLViewerInventoryCategory* cat = gInventory.getCategory(*it);
+        if (cat)
+        {
+            mComplete.push_back((*it));
+        }
+    }
+    LLInventoryFetchItemsObserver::startFetch();
 }
 /*virtual*/ void LLOpenAgentOffer::done()
 {
-	open_inventory_offer(mComplete, mFromName, mIsManuallyAccepted);
-	gInventory.removeObserver(this);
-	delete this;
+    open_inventory_offer(mComplete, mFromName, mIsManuallyAccepted);
+    gInventory.removeObserver(this);
+    delete this;
 }
 
 /**
@@ -1036,117 +1036,117 @@ static LLNotificationFunctorRegistration jgr_3("JoinGroupCanAfford", join_group_
 class LLViewerInventoryMoveFromWorldObserver : public LLInventoryAddItemByAssetObserver
 {
 public:
-	LLViewerInventoryMoveFromWorldObserver()
-		: LLInventoryAddItemByAssetObserver()
-	{
+    LLViewerInventoryMoveFromWorldObserver()
+        : LLInventoryAddItemByAssetObserver()
+    {
 
-	}
+    }
 
-	void setMoveIntoFolderID(const LLUUID& into_folder_uuid) {mMoveIntoFolderID = into_folder_uuid; }
+    void setMoveIntoFolderID(const LLUUID& into_folder_uuid) {mMoveIntoFolderID = into_folder_uuid; }
 
 private:
-	/*virtual */void onAssetAdded(const LLUUID& asset_id)
-	{
-		// Store active Inventory panel.
-		if (LLInventoryPanel::getActiveInventoryPanel())
-		{
-			mActivePanel = LLInventoryPanel::getActiveInventoryPanel()->getHandle();
-		}
-
-		// Store selected items (without destination folder)
-		mSelectedItems.clear();
-		if (LLInventoryPanel::getActiveInventoryPanel())
-		{
-			std::set<LLFolderViewItem*> selection =    LLInventoryPanel::getActiveInventoryPanel()->getRootFolder()->getSelectionList();
-			for (std::set<LLFolderViewItem*>::iterator it = selection.begin(),    end_it = selection.end();
-				it != end_it;
-				++it)
-			{
-				mSelectedItems.insert(static_cast<LLFolderViewModelItemInventory*>((*it)->getViewModelItem())->getUUID());
-			}
-		}
-		mSelectedItems.erase(mMoveIntoFolderID);
-	}
-
-	/**
-	 * Selects added inventory items watched by their Asset UUIDs if selection was not changed since
-	 * all items were started to watch (dropped into a folder).
-	 */
-	void done()
-	{
-		LLInventoryPanel* active_panel = dynamic_cast<LLInventoryPanel*>(mActivePanel.get());
-
-		// if selection is not changed since watch started lets hightlight new items.
-		if (active_panel && !isSelectionChanged())
-		{
-			LL_DEBUGS("Inventory_Move") << "Selecting new items..." << LL_ENDL;
-			active_panel->clearSelection();
-			highlight_inventory_objects_in_panel(mAddedItems, active_panel);
-		}
-	}
-
-	/**
-	 * Returns true if selected inventory items were changed since moved inventory items were started to watch.
-	 */
-	bool isSelectionChanged()
-	{	
-		LLInventoryPanel* active_panel = LLInventoryPanel::getActiveInventoryPanel();
-
-		if (NULL == active_panel)
-		{
-			return true;
-		}
-
-		// get selected items (without destination folder)
-		selected_items_t selected_items;
- 		
-		std::set<LLFolderViewItem*> selection = active_panel->getRootFolder()->getSelectionList();
-		for (std::set<LLFolderViewItem*>::iterator it = selection.begin(),    end_it = selection.end();
-			it != end_it;
-			++it)
-		{
-			selected_items.insert(static_cast<LLFolderViewModelItemInventory*>((*it)->getViewModelItem())->getUUID());
-		}
-		selected_items.erase(mMoveIntoFolderID);
-
-		// compare stored & current sets of selected items
-		selected_items_t different_items;
-		std::set_symmetric_difference(mSelectedItems.begin(), mSelectedItems.end(),
-			selected_items.begin(), selected_items.end(), std::inserter(different_items, different_items.begin()));
-
-		LL_DEBUGS("Inventory_Move") << "Selected firstly: " << mSelectedItems.size()
-			<< ", now: " << selected_items.size() << ", difference: " << different_items.size() << LL_ENDL;
-
-		return different_items.size() > 0;
-	}
-
-	LLHandle<LLPanel> mActivePanel;
-	typedef std::set<LLUUID> selected_items_t;
-	selected_items_t mSelectedItems;
-
-	/**
-	 * UUID of FolderViewFolder into which watched items are moved.
-	 *
-	 * Destination FolderViewFolder becomes selected while mouse hovering (when dragged items are dropped).
-	 * 
-	 * If mouse is moved out it set unselected and number of selected items is changed 
-	 * even if selected items in Inventory stay the same.
-	 * So, it is used to update stored selection list.
-	 *
-	 * @see onAssetAdded()
-	 * @see isSelectionChanged()
-	 */
-	LLUUID mMoveIntoFolderID;
+    /*virtual */void onAssetAdded(const LLUUID& asset_id)
+    {
+        // Store active Inventory panel.
+        if (LLInventoryPanel::getActiveInventoryPanel())
+        {
+            mActivePanel = LLInventoryPanel::getActiveInventoryPanel()->getHandle();
+        }
+
+        // Store selected items (without destination folder)
+        mSelectedItems.clear();
+        if (LLInventoryPanel::getActiveInventoryPanel())
+        {
+            std::set<LLFolderViewItem*> selection =    LLInventoryPanel::getActiveInventoryPanel()->getRootFolder()->getSelectionList();
+            for (std::set<LLFolderViewItem*>::iterator it = selection.begin(),    end_it = selection.end();
+                it != end_it;
+                ++it)
+            {
+                mSelectedItems.insert(static_cast<LLFolderViewModelItemInventory*>((*it)->getViewModelItem())->getUUID());
+            }
+        }
+        mSelectedItems.erase(mMoveIntoFolderID);
+    }
+
+    /**
+     * Selects added inventory items watched by their Asset UUIDs if selection was not changed since
+     * all items were started to watch (dropped into a folder).
+     */
+    void done()
+    {
+        LLInventoryPanel* active_panel = dynamic_cast<LLInventoryPanel*>(mActivePanel.get());
+
+        // if selection is not changed since watch started lets hightlight new items.
+        if (active_panel && !isSelectionChanged())
+        {
+            LL_DEBUGS("Inventory_Move") << "Selecting new items..." << LL_ENDL;
+            active_panel->clearSelection();
+            highlight_inventory_objects_in_panel(mAddedItems, active_panel);
+        }
+    }
+
+    /**
+     * Returns true if selected inventory items were changed since moved inventory items were started to watch.
+     */
+    bool isSelectionChanged()
+    {
+        LLInventoryPanel* active_panel = LLInventoryPanel::getActiveInventoryPanel();
+
+        if (NULL == active_panel)
+        {
+            return true;
+        }
+
+        // get selected items (without destination folder)
+        selected_items_t selected_items;
+
+        std::set<LLFolderViewItem*> selection = active_panel->getRootFolder()->getSelectionList();
+        for (std::set<LLFolderViewItem*>::iterator it = selection.begin(),    end_it = selection.end();
+            it != end_it;
+            ++it)
+        {
+            selected_items.insert(static_cast<LLFolderViewModelItemInventory*>((*it)->getViewModelItem())->getUUID());
+        }
+        selected_items.erase(mMoveIntoFolderID);
+
+        // compare stored & current sets of selected items
+        selected_items_t different_items;
+        std::set_symmetric_difference(mSelectedItems.begin(), mSelectedItems.end(),
+            selected_items.begin(), selected_items.end(), std::inserter(different_items, different_items.begin()));
+
+        LL_DEBUGS("Inventory_Move") << "Selected firstly: " << mSelectedItems.size()
+            << ", now: " << selected_items.size() << ", difference: " << different_items.size() << LL_ENDL;
+
+        return different_items.size() > 0;
+    }
+
+    LLHandle<LLPanel> mActivePanel;
+    typedef std::set<LLUUID> selected_items_t;
+    selected_items_t mSelectedItems;
+
+    /**
+     * UUID of FolderViewFolder into which watched items are moved.
+     *
+     * Destination FolderViewFolder becomes selected while mouse hovering (when dragged items are dropped).
+     *
+     * If mouse is moved out it set unselected and number of selected items is changed
+     * even if selected items in Inventory stay the same.
+     * So, it is used to update stored selection list.
+     *
+     * @see onAssetAdded()
+     * @see isSelectionChanged()
+     */
+    LLUUID mMoveIntoFolderID;
 };
 
 LLViewerInventoryMoveFromWorldObserver* gInventoryMoveObserver = NULL;
 
 void set_dad_inventory_item(LLInventoryItem* inv_item, const LLUUID& into_folder_uuid)
 {
-	start_new_inventory_observer();
+    start_new_inventory_observer();
 
-	gInventoryMoveObserver->setMoveIntoFolderID(into_folder_uuid);
-	gInventoryMoveObserver->watchAsset(inv_item->getAssetUUID());
+    gInventoryMoveObserver->setMoveIntoFolderID(into_folder_uuid);
+    gInventoryMoveObserver->watchAsset(inv_item->getAssetUUID());
 }
 
 
@@ -1160,138 +1160,138 @@ class LLViewerInventoryMoveObserver : public LLInventoryObserver
 {
 public:
 
-	LLViewerInventoryMoveObserver(const LLUUID& object_id)
-		: LLInventoryObserver()
-		, mObjectID(object_id)
-	{
-		if (LLInventoryPanel::getActiveInventoryPanel())
-		{
-			mActivePanel = LLInventoryPanel::getActiveInventoryPanel()->getHandle();
-		}
-	}
-
-	virtual ~LLViewerInventoryMoveObserver() {}
-	virtual void changed(U32 mask);
-	
+    LLViewerInventoryMoveObserver(const LLUUID& object_id)
+        : LLInventoryObserver()
+        , mObjectID(object_id)
+    {
+        if (LLInventoryPanel::getActiveInventoryPanel())
+        {
+            mActivePanel = LLInventoryPanel::getActiveInventoryPanel()->getHandle();
+        }
+    }
+
+    virtual ~LLViewerInventoryMoveObserver() {}
+    virtual void changed(U32 mask);
+
 private:
-	LLUUID mObjectID;
-	LLHandle<LLPanel> mActivePanel;
+    LLUUID mObjectID;
+    LLHandle<LLPanel> mActivePanel;
 
 };
 
 void LLViewerInventoryMoveObserver::changed(U32 mask)
 {
-	LLInventoryPanel* active_panel = dynamic_cast<LLInventoryPanel*>(mActivePanel.get());
-
-	if (NULL == active_panel)
-	{
-		gInventory.removeObserver(this);
-		return;
-	}
-
-	if((mask & (LLInventoryObserver::STRUCTURE)) != 0)
-	{
-		const std::set<LLUUID>& changed_items = gInventory.getChangedIDs();
-
-		std::set<LLUUID>::const_iterator id_it = changed_items.begin();
-		std::set<LLUUID>::const_iterator id_end = changed_items.end();
-		for (;id_it != id_end; ++id_it)
-		{
-			if ((*id_it) == mObjectID)
-			{
-				active_panel->clearSelection();			
-				std::vector<LLUUID> items;
-				items.push_back(mObjectID);
-				highlight_inventory_objects_in_panel(items, active_panel);
-				active_panel->getRootFolder()->scrollToShowSelection();
-				
-				gInventory.removeObserver(this);
-				break;
-			}
-		}
-	}
+    LLInventoryPanel* active_panel = dynamic_cast<LLInventoryPanel*>(mActivePanel.get());
+
+    if (NULL == active_panel)
+    {
+        gInventory.removeObserver(this);
+        return;
+    }
+
+    if((mask & (LLInventoryObserver::STRUCTURE)) != 0)
+    {
+        const std::set<LLUUID>& changed_items = gInventory.getChangedIDs();
+
+        std::set<LLUUID>::const_iterator id_it = changed_items.begin();
+        std::set<LLUUID>::const_iterator id_end = changed_items.end();
+        for (;id_it != id_end; ++id_it)
+        {
+            if ((*id_it) == mObjectID)
+            {
+                active_panel->clearSelection();
+                std::vector<LLUUID> items;
+                items.push_back(mObjectID);
+                highlight_inventory_objects_in_panel(items, active_panel);
+                active_panel->getRootFolder()->scrollToShowSelection();
+
+                gInventory.removeObserver(this);
+                break;
+            }
+        }
+    }
 }
 
 void set_dad_inbox_object(const LLUUID& object_id)
 {
-	LLViewerInventoryMoveObserver* move_observer = new LLViewerInventoryMoveObserver(object_id);
-	gInventory.addObserver(move_observer);
+    LLViewerInventoryMoveObserver* move_observer = new LLViewerInventoryMoveObserver(object_id);
+    gInventory.addObserver(move_observer);
 }
 
-//unlike the FetchObserver for AgentOffer, we only make one 
+//unlike the FetchObserver for AgentOffer, we only make one
 //instance of the AddedObserver for TaskOffers
-//and it never dies.  We do this because we don't know the UUID of 
-//task offers until they are accepted, so we don't wouldn't 
+//and it never dies.  We do this because we don't know the UUID of
+//task offers until they are accepted, so we don't wouldn't
 //know what to watch for, so instead we just watch for all additions.
 class LLOpenTaskOffer : public LLInventoryAddedObserver
 {
 protected:
-	/*virtual*/ void done()
-	{
-		uuid_vec_t added;
-		for(uuid_set_t::const_iterator it = gInventory.getAddedIDs().begin(); it != gInventory.getAddedIDs().end(); ++it)
-		{
-			added.push_back(*it);
-		}
-		for (uuid_vec_t::iterator it = added.begin(); it != added.end();)
-		{
-			const LLUUID& item_uuid = *it;
-			bool was_moved = false;
-			LLInventoryObject* added_object = gInventory.getObject(item_uuid);
-			if (added_object)
-			{
-				// cast to item to get Asset UUID
-				LLInventoryItem* added_item = dynamic_cast<LLInventoryItem*>(added_object);
-				if (added_item)
-				{
-					const LLUUID& asset_uuid = added_item->getAssetUUID();
-					if (gInventoryMoveObserver->isAssetWatched(asset_uuid))
-					{
-						LL_DEBUGS("Inventory_Move") << "Found asset UUID: " << asset_uuid << LL_ENDL;
-						was_moved = true;
-					}
-				}
-			}
-
-			if (was_moved)
-			{
-				it = added.erase(it);
-			}
-			else ++it;
-		}
-
-		if (gSavedSettings.getBOOL("ShowNewInventory"))
-		{
-			open_inventory_offer(added, "");
-		}
-		else if (!added.empty() && gSavedSettings.getBOOL("ShowInInventory") && highlight_offered_object(added.back()))
-		{
-			LLInventoryPanel::openInventoryPanelAndSetSelection(TRUE, added.back());
-		}
-	}
+    /*virtual*/ void done()
+    {
+        uuid_vec_t added;
+        for(uuid_set_t::const_iterator it = gInventory.getAddedIDs().begin(); it != gInventory.getAddedIDs().end(); ++it)
+        {
+            added.push_back(*it);
+        }
+        for (uuid_vec_t::iterator it = added.begin(); it != added.end();)
+        {
+            const LLUUID& item_uuid = *it;
+            bool was_moved = false;
+            LLInventoryObject* added_object = gInventory.getObject(item_uuid);
+            if (added_object)
+            {
+                // cast to item to get Asset UUID
+                LLInventoryItem* added_item = dynamic_cast<LLInventoryItem*>(added_object);
+                if (added_item)
+                {
+                    const LLUUID& asset_uuid = added_item->getAssetUUID();
+                    if (gInventoryMoveObserver->isAssetWatched(asset_uuid))
+                    {
+                        LL_DEBUGS("Inventory_Move") << "Found asset UUID: " << asset_uuid << LL_ENDL;
+                        was_moved = true;
+                    }
+                }
+            }
+
+            if (was_moved)
+            {
+                it = added.erase(it);
+            }
+            else ++it;
+        }
+
+        if (gSavedSettings.getBOOL("ShowNewInventory"))
+        {
+            open_inventory_offer(added, "");
+        }
+        else if (!added.empty() && gSavedSettings.getBOOL("ShowInInventory") && highlight_offered_object(added.back()))
+        {
+            LLInventoryPanel::openInventoryPanelAndSetSelection(TRUE, added.back());
+        }
+    }
  };
 
 class LLOpenTaskGroupOffer : public LLInventoryAddedObserver
 {
 protected:
-	/*virtual*/ void done()
-	{
-		uuid_vec_t added;
-		for(uuid_set_t::const_iterator it = gInventory.getAddedIDs().begin(); it != gInventory.getAddedIDs().end(); ++it)
-		{
-			added.push_back(*it);
-		}
-		if (gSavedSettings.getBOOL("ShowNewInventory"))
-		{
-			open_inventory_offer(added, "group_offer");
-		}
-		else if (!added.empty() && gSavedSettings.getBOOL("ShowInInventory"))
-		{
-			LLInventoryPanel::openInventoryPanelAndSetSelection(TRUE, added.back());
-		}
-		gInventory.removeObserver(this);
-		delete this;
-	}
+    /*virtual*/ void done()
+    {
+        uuid_vec_t added;
+        for(uuid_set_t::const_iterator it = gInventory.getAddedIDs().begin(); it != gInventory.getAddedIDs().end(); ++it)
+        {
+            added.push_back(*it);
+        }
+        if (gSavedSettings.getBOOL("ShowNewInventory"))
+        {
+            open_inventory_offer(added, "group_offer");
+        }
+        else if (!added.empty() && gSavedSettings.getBOOL("ShowInInventory"))
+        {
+            LLInventoryPanel::openInventoryPanelAndSetSelection(TRUE, added.back());
+        }
+        gInventory.removeObserver(this);
+        delete this;
+    }
 };
 
 //one global instance to bind them
@@ -1299,337 +1299,337 @@ LLOpenTaskOffer* gNewInventoryObserver=NULL;
 class LLNewInventoryHintObserver : public LLInventoryAddedObserver
 {
 protected:
-	/*virtual*/ void done()
-	{
-		LLFirstUse::newInventory();
-	}
+    /*virtual*/ void done()
+    {
+        LLFirstUse::newInventory();
+    }
 };
 
 LLNewInventoryHintObserver* gNewInventoryHintObserver=NULL;
 
 void start_new_inventory_observer()
 {
-	if (!gNewInventoryObserver) //task offer observer 
-	{
-		// Observer is deleted by gInventory
-		gNewInventoryObserver = new LLOpenTaskOffer;
-		gInventory.addObserver(gNewInventoryObserver);
-	}
+    if (!gNewInventoryObserver) //task offer observer
+    {
+        // Observer is deleted by gInventory
+        gNewInventoryObserver = new LLOpenTaskOffer;
+        gInventory.addObserver(gNewInventoryObserver);
+    }
 
-	if (!gInventoryMoveObserver) //inventory move from the world observer 
-	{
-		// Observer is deleted by gInventory
-		gInventoryMoveObserver = new LLViewerInventoryMoveFromWorldObserver;
-		gInventory.addObserver(gInventoryMoveObserver);
-	}
+    if (!gInventoryMoveObserver) //inventory move from the world observer
+    {
+        // Observer is deleted by gInventory
+        gInventoryMoveObserver = new LLViewerInventoryMoveFromWorldObserver;
+        gInventory.addObserver(gInventoryMoveObserver);
+    }
 
-	if (!gNewInventoryHintObserver)
-	{
-		// Observer is deleted by gInventory
-		gNewInventoryHintObserver = new LLNewInventoryHintObserver();
-		gInventory.addObserver(gNewInventoryHintObserver);
-	}
+    if (!gNewInventoryHintObserver)
+    {
+        // Observer is deleted by gInventory
+        gNewInventoryHintObserver = new LLNewInventoryHintObserver();
+        gInventory.addObserver(gNewInventoryHintObserver);
+    }
 }
 
 class LLDiscardAgentOffer : public LLInventoryFetchItemsObserver
 {
-	LOG_CLASS(LLDiscardAgentOffer);
+    LOG_CLASS(LLDiscardAgentOffer);
 
 public:
-	LLDiscardAgentOffer(const LLUUID& folder_id, const LLUUID& object_id) :
-		LLInventoryFetchItemsObserver(object_id),
-		mFolderID(folder_id),
-		mObjectID(object_id) {}
-
-	virtual void done()
-	{
-		LL_DEBUGS("Messaging") << "LLDiscardAgentOffer::done()" << LL_ENDL;
-
-		// We're invoked from LLInventoryModel::notifyObservers().
-		// If we now try to remove the inventory item, it will cause a nested
-		// notifyObservers() call, which won't work.
-		// So defer moving the item to trash until viewer gets idle (in a moment).
-		// Use removeObject() rather than removeItem() because at this level,
-		// the object could be either an item or a folder.
-		LLAppViewer::instance()->addOnIdleCallback(boost::bind(&LLInventoryModel::removeObject, &gInventory, mObjectID));
-		gInventory.removeObserver(this);
-		delete this;
-	}
+    LLDiscardAgentOffer(const LLUUID& folder_id, const LLUUID& object_id) :
+        LLInventoryFetchItemsObserver(object_id),
+        mFolderID(folder_id),
+        mObjectID(object_id) {}
+
+    virtual void done()
+    {
+        LL_DEBUGS("Messaging") << "LLDiscardAgentOffer::done()" << LL_ENDL;
+
+        // We're invoked from LLInventoryModel::notifyObservers().
+        // If we now try to remove the inventory item, it will cause a nested
+        // notifyObservers() call, which won't work.
+        // So defer moving the item to trash until viewer gets idle (in a moment).
+        // Use removeObject() rather than removeItem() because at this level,
+        // the object could be either an item or a folder.
+        LLAppViewer::instance()->addOnIdleCallback(boost::bind(&LLInventoryModel::removeObject, &gInventory, mObjectID));
+        gInventory.removeObserver(this);
+        delete this;
+    }
 
 protected:
-	LLUUID mFolderID;
-	LLUUID mObjectID;
+    LLUUID mFolderID;
+    LLUUID mObjectID;
 };
 
 
 //Returns TRUE if we are OK, FALSE if we are throttled
-//Set check_only true if you want to know the throttle status 
+//Set check_only true if you want to know the throttle status
 //without registering a hit
 bool check_offer_throttle(const std::string& from_name, bool check_only)
 {
-	static U32 throttle_count;
-	static bool throttle_logged;
-	LLChat chat;
-	std::string log_message;
-
-	//if (!gSavedSettings.getBOOL("ShowNewInventory"))
-	//	return false;
-
-	if (check_only)
-	{
-		return gThrottleTimer.hasExpired();
-	}
-	
-	if(gThrottleTimer.checkExpirationAndReset(OFFER_THROTTLE_TIME))
-	{
-		LL_DEBUGS("Messaging") << "Throttle Expired" << LL_ENDL;
-		throttle_count=1;
-		throttle_logged=false;
-		return true;
-	}
-	else //has not expired
-	{
-		LL_DEBUGS("Messaging") << "Throttle Not Expired, Count: " << throttle_count << LL_ENDL;
-		// When downloading the initial inventory we get a lot of new items
-		// coming in and can't tell that from spam.
-		if (LLStartUp::getStartupState() >= STATE_STARTED
-			&& throttle_count >= OFFER_THROTTLE_MAX_COUNT)
-		{
-			if (!throttle_logged)
-			{
-				// Use the name of the last item giver, who is probably the person
-				// spamming you.
-
-				LLStringUtil::format_map_t arg;
-				std::string log_msg;
-				std::ostringstream time ;
-				time<<OFFER_THROTTLE_TIME;
-
-				arg["APP_NAME"] = LLAppViewer::instance()->getSecondLifeTitle();
-				arg["TIME"] = time.str();
-
-				if (!from_name.empty())
-				{
-					arg["FROM_NAME"] = from_name;
-					log_msg = LLTrans::getString("ItemsComingInTooFastFrom", arg);
-				}
-				else
-				{
-					log_msg = LLTrans::getString("ItemsComingInTooFast", arg);
-				}
-				
-				//this is kinda important, so actually put it on screen
-				LLSD args;
-				args["MESSAGE"] = log_msg;
-				LLNotificationsUtil::add("SystemMessage", args);
-
-				throttle_logged=true;
-			}
-			return false;
-		}
-		else
-		{
-			throttle_count++;
-			return true;
-		}
-	}
-}
- 
-// Return "true" if we have a preview method for that asset type, "false" otherwise
-bool check_asset_previewable(const LLAssetType::EType asset_type)
-{
-	return	(asset_type == LLAssetType::AT_NOTECARD)  || 
-			(asset_type == LLAssetType::AT_LANDMARK)  ||
-			(asset_type == LLAssetType::AT_TEXTURE)   ||
-			(asset_type == LLAssetType::AT_ANIMATION) ||
-			(asset_type == LLAssetType::AT_SCRIPT)    ||
-			(asset_type == LLAssetType::AT_SOUND) ||
-            (asset_type == LLAssetType::AT_MATERIAL);
-}
+    static U32 throttle_count;
+    static bool throttle_logged;
+    LLChat chat;
+    std::string log_message;
 
-void open_inventory_offer(const uuid_vec_t& objects, const std::string& from_name, bool manual_offer /* = false*/)
-{
-	for (uuid_vec_t::const_iterator obj_iter = objects.begin();
-		 obj_iter != objects.end();
-		 ++obj_iter)
-	{
-		const LLUUID& obj_id = (*obj_iter);
-		if(!highlight_offered_object(obj_id))
-		{
-			const LLViewerInventoryCategory *parent = gInventory.getFirstNondefaultParent(obj_id);
-			if (parent && (parent->getPreferredType() == LLFolderType::FT_TRASH))
-			{
-				gInventory.checkTrashOverflow();
-			}
-			continue;
-		}
-
-		const LLInventoryObject *obj = gInventory.getObject(obj_id);
-		if (!obj)
-		{
-			LL_WARNS() << "Cannot find object [ itemID:" << obj_id << " ] to open." << LL_ENDL;
-			continue;
-		}
-
-		const LLAssetType::EType asset_type = obj->getActualType();
-
-		// Either an inventory item or a category.
-		const LLInventoryItem* item = dynamic_cast<const LLInventoryItem*>(obj);
-		if (item && check_asset_previewable(asset_type))
-		{
-			////////////////////////////////////////////////////////////////////////////////
-			// Special handling for various types.
-			if (check_offer_throttle(from_name, false)) // If we are throttled, don't display
-			{
-				LL_DEBUGS("Messaging") << "Highlighting inventory item: " << item->getUUID()  << LL_ENDL;
-				// If we opened this ourselves, focus it
-				const BOOL take_focus = from_name.empty() ? TAKE_FOCUS_YES : TAKE_FOCUS_NO;
-				switch(asset_type)
-				{
-					case LLAssetType::AT_NOTECARD:
-					{
-						LLFloaterReg::showInstance("preview_notecard", LLSD(obj_id), take_focus);
-						break;
-					}
-					case LLAssetType::AT_LANDMARK:
-					{
-						LLInventoryCategory* parent_folder = gInventory.getCategory(item->getParentUUID());
-						if ("inventory_handler" == from_name)
-						{
-							LLFloaterSidePanelContainer::showPanel("places", LLSD().with("type", "landmark").with("id", item->getUUID()));
-						}
-						else if("group_offer" == from_name)
-						{
-							// "group_offer" is passed by LLOpenTaskGroupOffer
-							// Notification about added landmark will be generated under the "from_name.empty()" called from LLOpenTaskOffer::done().
-							LLSD args;
-							args["type"] = "landmark";
-							args["id"] = obj_id;
-							LLFloaterSidePanelContainer::showPanel("places", args);
-
-							continue;
-						}
-						else if(from_name.empty())
-						{
-							std::string folder_name;
-							if (parent_folder)
-							{
-								// Localize folder name.
-								// *TODO: share this code?
-								folder_name = parent_folder->getName();
-								if (LLFolderType::lookupIsProtectedType(parent_folder->getPreferredType()))
-								{
-									LLTrans::findString(folder_name, "InvFolder " + folder_name);
-								}
-							}
-							else
-							{
-								 folder_name = LLTrans::getString("Unknown");
-							}
-
-							// we receive a message from LLOpenTaskOffer, it mean that new landmark has been added.
-							LLSD args;
-							args["LANDMARK_NAME"] = item->getName();
-							args["FOLDER_NAME"] = folder_name;
-							LLNotificationsUtil::add("LandmarkCreated", args);
-						}
-					}
-					break;
-					case LLAssetType::AT_TEXTURE:
-					{
-						LLFloaterReg::showInstance("preview_texture", LLSD(obj_id), take_focus);
-						break;
-					}
-					case LLAssetType::AT_ANIMATION:
-						LLFloaterReg::showInstance("preview_anim", LLSD(obj_id), take_focus);
-						break;
-					case LLAssetType::AT_SCRIPT:
-						LLFloaterReg::showInstance("preview_script", LLSD(obj_id), take_focus);
-						break;
-					case LLAssetType::AT_SOUND:
-						LLFloaterReg::showInstance("preview_sound", LLSD(obj_id), take_focus);
-						break;
-                    case LLAssetType::AT_MATERIAL:
-                        // Explicitly do nothing -- we don't want to open the material editor every time you add a material to inventory
-                        break;
-					default:
-						LL_DEBUGS("Messaging") << "No preview method for previewable asset type : " << LLAssetType::lookupHumanReadable(asset_type)  << LL_ENDL;
-						break;
-				}
-			}
-		}
-
-		////////////////////////////////////////////////////////////////////////////////
-        static LLUICachedControl<bool> find_original_new_floater("FindOriginalOpenWindow", false);
-        //show in a new single-folder window
-        if(find_original_new_floater && !from_name.empty())
+    //if (!gSavedSettings.getBOOL("ShowNewInventory"))
+    //  return false;
+
+    if (check_only)
+    {
+        return gThrottleTimer.hasExpired();
+    }
+
+    if(gThrottleTimer.checkExpirationAndReset(OFFER_THROTTLE_TIME))
+    {
+        LL_DEBUGS("Messaging") << "Throttle Expired" << LL_ENDL;
+        throttle_count=1;
+        throttle_logged=false;
+        return true;
+    }
+    else //has not expired
+    {
+        LL_DEBUGS("Messaging") << "Throttle Not Expired, Count: " << throttle_count << LL_ENDL;
+        // When downloading the initial inventory we get a lot of new items
+        // coming in and can't tell that from spam.
+        if (LLStartUp::getStartupState() >= STATE_STARTED
+            && throttle_count >= OFFER_THROTTLE_MAX_COUNT)
         {
-            const LLInventoryObject *obj = gInventory.getObject(obj_id);
-            if (obj && obj->getParentUUID().notNull())
+            if (!throttle_logged)
             {
-                if (obj->getActualType() == LLAssetType::AT_CATEGORY)
+                // Use the name of the last item giver, who is probably the person
+                // spamming you.
+
+                LLStringUtil::format_map_t arg;
+                std::string log_msg;
+                std::ostringstream time ;
+                time<<OFFER_THROTTLE_TIME;
+
+                arg["APP_NAME"] = LLAppViewer::instance()->getSecondLifeTitle();
+                arg["TIME"] = time.str();
+
+                if (!from_name.empty())
                 {
-                    LLPanelMainInventory::newFolderWindow(obj_id);
+                    arg["FROM_NAME"] = from_name;
+                    log_msg = LLTrans::getString("ItemsComingInTooFastFrom", arg);
                 }
                 else
                 {
-                    LLPanelMainInventory::newFolderWindow(obj->getParentUUID(), obj_id);
+                    log_msg = LLTrans::getString("ItemsComingInTooFast", arg);
                 }
+
+                //this is kinda important, so actually put it on screen
+                LLSD args;
+                args["MESSAGE"] = log_msg;
+                LLNotificationsUtil::add("SystemMessage", args);
+
+                throttle_logged=true;
             }
+            return false;
         }
         else
         {
-            // Highlight item
-// [ALCHEMY]
-//            bool show_in_inventory = gSavedSettings.get<bool>("ShowInInventory");
-//            bool auto_open =
-//                show_in_inventory && // don't open if ShowInInventory is FALSE
-//                !from_name.empty();  // don't open if it's not from anyone
-//
-//            // SL-20419 : Don't change active tab if floater is visible
-//           LLFloater* instance = LLFloaterReg::findInstance("inventory");
-//            bool use_main_panel = instance && instance->getVisible();
-//
-//            if (auto_open)
-//            {
-//                LLFloaterReg::showInstance("inventory");
-//            }
-//
-//            LLInventoryPanel::openInventoryPanelAndSetSelection(auto_open, obj_id, use_main_panel);
-            const BOOL auto_open = gSavedSettings.getBOOL("ShowInInventory") || (manual_offer && !check_asset_previewable(asset_type));
-            if(auto_open)
-            {
-                LLFloaterReg::showInstance("inventory");
-            }
-            if (auto_open) LLInventoryPanel::openInventoryPanelAndSetSelection(auto_open, obj_id, true);
+            throttle_count++;
+            return true;
         }
-	}
+    }
 }
 
-bool highlight_offered_object(const LLUUID& obj_id)
-{
-	const LLInventoryObject* obj = gInventory.getObject(obj_id);
-	if(!obj)
-	{
-		LL_WARNS("Messaging") << "Unable to show inventory item: " << obj_id << LL_ENDL;
-		return false;
-	}
-
-	////////////////////////////////////////////////////////////////////////////////
-	// Don't highlight if it's in certain "quiet" folders which don't need UI
-	// notification (e.g. trash, cof, lost-and-found).
-	if(!gAgent.getAFK())
-	{
-		const LLViewerInventoryCategory *parent = gInventory.getFirstNondefaultParent(obj_id);
-		if (parent)
-		{
-			const LLFolderType::EType parent_type = parent->getPreferredType();
-			if (LLViewerFolderType::lookupIsQuietType(parent_type))
-			{
-				return false;
-			}
-		}
-	}
+// Return "true" if we have a preview method for that asset type, "false" otherwise
+bool check_asset_previewable(const LLAssetType::EType asset_type)
+{
+    return  (asset_type == LLAssetType::AT_NOTECARD)  ||
+            (asset_type == LLAssetType::AT_LANDMARK)  ||
+            (asset_type == LLAssetType::AT_TEXTURE)   ||
+            (asset_type == LLAssetType::AT_ANIMATION) ||
+            (asset_type == LLAssetType::AT_SCRIPT)    ||
+            (asset_type == LLAssetType::AT_SOUND) ||
+            (asset_type == LLAssetType::AT_MATERIAL);
+}
+
+void open_inventory_offer(const uuid_vec_t& objects, const std::string& from_name, bool manual_offer /* = false*/)
+{
+    for (uuid_vec_t::const_iterator obj_iter = objects.begin();
+         obj_iter != objects.end();
+         ++obj_iter)
+    {
+        const LLUUID& obj_id = (*obj_iter);
+        if(!highlight_offered_object(obj_id))
+        {
+            const LLViewerInventoryCategory *parent = gInventory.getFirstNondefaultParent(obj_id);
+            if (parent && (parent->getPreferredType() == LLFolderType::FT_TRASH))
+            {
+                gInventory.checkTrashOverflow();
+            }
+            continue;
+        }
+
+        const LLInventoryObject *obj = gInventory.getObject(obj_id);
+        if (!obj)
+        {
+            LL_WARNS() << "Cannot find object [ itemID:" << obj_id << " ] to open." << LL_ENDL;
+            continue;
+        }
+
+        const LLAssetType::EType asset_type = obj->getActualType();
+
+        // Either an inventory item or a category.
+        const LLInventoryItem* item = dynamic_cast<const LLInventoryItem*>(obj);
+        if (item && check_asset_previewable(asset_type))
+        {
+            ////////////////////////////////////////////////////////////////////////////////
+            // Special handling for various types.
+            if (check_offer_throttle(from_name, false)) // If we are throttled, don't display
+            {
+                LL_DEBUGS("Messaging") << "Highlighting inventory item: " << item->getUUID()  << LL_ENDL;
+                // If we opened this ourselves, focus it
+                const BOOL take_focus = from_name.empty() ? TAKE_FOCUS_YES : TAKE_FOCUS_NO;
+                switch(asset_type)
+                {
+                    case LLAssetType::AT_NOTECARD:
+                    {
+                        LLFloaterReg::showInstance("preview_notecard", LLSD(obj_id), take_focus);
+                        break;
+                    }
+                    case LLAssetType::AT_LANDMARK:
+                    {
+                        LLInventoryCategory* parent_folder = gInventory.getCategory(item->getParentUUID());
+                        if ("inventory_handler" == from_name)
+                        {
+                            LLFloaterSidePanelContainer::showPanel("places", LLSD().with("type", "landmark").with("id", item->getUUID()));
+                        }
+                        else if("group_offer" == from_name)
+                        {
+                            // "group_offer" is passed by LLOpenTaskGroupOffer
+                            // Notification about added landmark will be generated under the "from_name.empty()" called from LLOpenTaskOffer::done().
+                            LLSD args;
+                            args["type"] = "landmark";
+                            args["id"] = obj_id;
+                            LLFloaterSidePanelContainer::showPanel("places", args);
+
+                            continue;
+                        }
+                        else if(from_name.empty())
+                        {
+                            std::string folder_name;
+                            if (parent_folder)
+                            {
+                                // Localize folder name.
+                                // *TODO: share this code?
+                                folder_name = parent_folder->getName();
+                                if (LLFolderType::lookupIsProtectedType(parent_folder->getPreferredType()))
+                                {
+                                    LLTrans::findString(folder_name, "InvFolder " + folder_name);
+                                }
+                            }
+                            else
+                            {
+                                 folder_name = LLTrans::getString("Unknown");
+                            }
+
+                            // we receive a message from LLOpenTaskOffer, it mean that new landmark has been added.
+                            LLSD args;
+                            args["LANDMARK_NAME"] = item->getName();
+                            args["FOLDER_NAME"] = folder_name;
+                            LLNotificationsUtil::add("LandmarkCreated", args);
+                        }
+                    }
+                    break;
+                    case LLAssetType::AT_TEXTURE:
+                    {
+                        LLFloaterReg::showInstance("preview_texture", LLSD(obj_id), take_focus);
+                        break;
+                    }
+                    case LLAssetType::AT_ANIMATION:
+                        LLFloaterReg::showInstance("preview_anim", LLSD(obj_id), take_focus);
+                        break;
+                    case LLAssetType::AT_SCRIPT:
+                        LLFloaterReg::showInstance("preview_script", LLSD(obj_id), take_focus);
+                        break;
+                    case LLAssetType::AT_SOUND:
+                        LLFloaterReg::showInstance("preview_sound", LLSD(obj_id), take_focus);
+                        break;
+                    case LLAssetType::AT_MATERIAL:
+                        // Explicitly do nothing -- we don't want to open the material editor every time you add a material to inventory
+                        break;
+                    default:
+                        LL_DEBUGS("Messaging") << "No preview method for previewable asset type : " << LLAssetType::lookupHumanReadable(asset_type)  << LL_ENDL;
+                        break;
+                }
+            }
+        }
+
+        ////////////////////////////////////////////////////////////////////////////////
+        static LLUICachedControl<bool> find_original_new_floater("FindOriginalOpenWindow", false);
+        //show in a new single-folder window
+        if(find_original_new_floater && !from_name.empty())
+        {
+            const LLInventoryObject *obj = gInventory.getObject(obj_id);
+            if (obj && obj->getParentUUID().notNull())
+            {
+                if (obj->getActualType() == LLAssetType::AT_CATEGORY)
+                {
+                    LLPanelMainInventory::newFolderWindow(obj_id);
+                }
+                else
+                {
+                    LLPanelMainInventory::newFolderWindow(obj->getParentUUID(), obj_id);
+                }
+            }
+        }
+        else
+        {
+            // Highlight item
+// [ALCHEMY]
+//            bool show_in_inventory = gSavedSettings.get<bool>("ShowInInventory");
+//            bool auto_open =
+//                show_in_inventory && // don't open if ShowInInventory is FALSE
+//                !from_name.empty();  // don't open if it's not from anyone
+//
+//            // SL-20419 : Don't change active tab if floater is visible
+//           LLFloater* instance = LLFloaterReg::findInstance("inventory");
+//            bool use_main_panel = instance && instance->getVisible();
+//
+//            if (auto_open)
+//            {
+//                LLFloaterReg::showInstance("inventory");
+//            }
+//
+//            LLInventoryPanel::openInventoryPanelAndSetSelection(auto_open, obj_id, use_main_panel);
+            const BOOL auto_open = gSavedSettings.getBOOL("ShowInInventory") || (manual_offer && !check_asset_previewable(asset_type));
+            if(auto_open)
+            {
+                LLFloaterReg::showInstance("inventory");
+            }
+            if (auto_open) LLInventoryPanel::openInventoryPanelAndSetSelection(auto_open, obj_id, true);
+        }
+    }
+}
+
+bool highlight_offered_object(const LLUUID& obj_id)
+{
+    const LLInventoryObject* obj = gInventory.getObject(obj_id);
+    if(!obj)
+    {
+        LL_WARNS("Messaging") << "Unable to show inventory item: " << obj_id << LL_ENDL;
+        return false;
+    }
+
+    ////////////////////////////////////////////////////////////////////////////////
+    // Don't highlight if it's in certain "quiet" folders which don't need UI
+    // notification (e.g. trash, cof, lost-and-found).
+    if(!gAgent.getAFK())
+    {
+        const LLViewerInventoryCategory *parent = gInventory.getFirstNondefaultParent(obj_id);
+        if (parent)
+        {
+            const LLFolderType::EType parent_type = parent->getPreferredType();
+            if (LLViewerFolderType::lookupIsQuietType(parent_type))
+            {
+                return false;
+            }
+        }
+    }
 
     if (obj->getType() == LLAssetType::AT_LANDMARK)
     {
@@ -1642,41 +1642,41 @@ bool highlight_offered_object(const LLUUID& obj_id)
         }
     }
 
-	return true;
+    return true;
 }
 
 void inventory_offer_mute_callback(const LLUUID& blocked_id,
-								   const std::string& full_name,
-								   bool is_group)
-{
-	// *NOTE: blocks owner if the offer came from an object
-	LLMute::EType mute_type = is_group ? LLMute::GROUP : LLMute::AGENT;
-
-	LLMute mute(blocked_id, full_name, mute_type);
-	if (LLMuteList::getInstance()->add(mute))
-	{
-		LLFloaterBlocked::showMuteAndSelect(blocked_id);
-		//LLPanelBlockedList::showPanelAndSelect(blocked_id);
-	}
-
-	// purge the message queue of any previously queued inventory offers from the same source.
-	class OfferMatcher : public LLNotificationsUI::LLScreenChannel::Matcher
-	{
-	public:
-		OfferMatcher(const LLUUID& to_block) : blocked_id(to_block) {}
-		bool matches(const LLNotificationPtr notification) const
-		{
-			if(notification->getName() == "ObjectGiveItem" 
-				|| notification->getName() == "OwnObjectGiveItem"
-				|| notification->getName() == "UserGiveItem")
-			{
-				return (notification->getPayload()["from_id"].asUUID() == blocked_id);
-			}
-			return FALSE;
-		}
-	private:
-		const LLUUID& blocked_id;
-	};
+                                   const std::string& full_name,
+                                   bool is_group)
+{
+    // *NOTE: blocks owner if the offer came from an object
+    LLMute::EType mute_type = is_group ? LLMute::GROUP : LLMute::AGENT;
+
+    LLMute mute(blocked_id, full_name, mute_type);
+    if (LLMuteList::getInstance()->add(mute))
+    {
+        LLFloaterBlocked::showMuteAndSelect(blocked_id);
+        //LLPanelBlockedList::showPanelAndSelect(blocked_id);
+    }
+
+    // purge the message queue of any previously queued inventory offers from the same source.
+    class OfferMatcher : public LLNotificationsUI::LLScreenChannel::Matcher
+    {
+    public:
+        OfferMatcher(const LLUUID& to_block) : blocked_id(to_block) {}
+        bool matches(const LLNotificationPtr notification) const
+        {
+            if(notification->getName() == "ObjectGiveItem"
+                || notification->getName() == "OwnObjectGiveItem"
+                || notification->getName() == "UserGiveItem")
+            {
+                return (notification->getPayload()["from_id"].asUUID() == blocked_id);
+            }
+            return FALSE;
+        }
+    private:
+        const LLUUID& blocked_id;
+    };
 
     LLNotificationsUI::LLChannelManager::getInstance()->killToastsFromChannel(
         LLNotificationsUI::NOTIFICATION_CHANNEL_UUID,
@@ -1705,687 +1705,687 @@ LLOfferInfo::LLOfferInfo()
 
 LLOfferInfo::LLOfferInfo(const LLSD& sd)
 {
-	mIM = (EInstantMessage)sd["im_type"].asInteger();
-	mFromID = sd["from_id"].asUUID();
-	mFromGroup = sd["from_group"].asBoolean();
-	mFromObject = sd["from_object"].asBoolean();
-	mTransactionID = sd["transaction_id"].asUUID();
-	mFolderID = sd["folder_id"].asUUID();
-	mObjectID = sd["object_id"].asUUID();
-	mType = LLAssetType::lookup(sd["type"].asString().c_str());
-	mFromName = sd["from_name"].asString();
-	mDesc = sd["description"].asString();
-	mHost = LLHost(sd["sender"].asString());
-	mPersist = sd["persist"].asBoolean();
+    mIM = (EInstantMessage)sd["im_type"].asInteger();
+    mFromID = sd["from_id"].asUUID();
+    mFromGroup = sd["from_group"].asBoolean();
+    mFromObject = sd["from_object"].asBoolean();
+    mTransactionID = sd["transaction_id"].asUUID();
+    mFolderID = sd["folder_id"].asUUID();
+    mObjectID = sd["object_id"].asUUID();
+    mType = LLAssetType::lookup(sd["type"].asString().c_str());
+    mFromName = sd["from_name"].asString();
+    mDesc = sd["description"].asString();
+    mHost = LLHost(sd["sender"].asString());
+    mPersist = sd["persist"].asBoolean();
 }
 
 LLOfferInfo::LLOfferInfo(const LLOfferInfo& info)
 {
-	mIM = info.mIM;
-	mFromID = info.mFromID;
-	mFromGroup = info.mFromGroup;
-	mFromObject = info.mFromObject;
-	mTransactionID = info.mTransactionID;
-	mFolderID = info.mFolderID;
-	mObjectID = info.mObjectID;
-	mType = info.mType;
-	mFromName = info.mFromName;
-	mDesc = info.mDesc;
-	mHost = info.mHost;
-	mPersist = info.mPersist;
+    mIM = info.mIM;
+    mFromID = info.mFromID;
+    mFromGroup = info.mFromGroup;
+    mFromObject = info.mFromObject;
+    mTransactionID = info.mTransactionID;
+    mFolderID = info.mFolderID;
+    mObjectID = info.mObjectID;
+    mType = info.mType;
+    mFromName = info.mFromName;
+    mDesc = info.mDesc;
+    mHost = info.mHost;
+    mPersist = info.mPersist;
 }
 
 LLSD LLOfferInfo::asLLSD()
 {
-	LLSD sd;
+    LLSD sd;
     sd["responder_type"] = mResponderType;
-	sd["im_type"] = mIM;
-	sd["from_id"] = mFromID;
-	sd["from_group"] = mFromGroup;
-	sd["from_object"] = mFromObject;
-	sd["transaction_id"] = mTransactionID;
-	sd["folder_id"] = mFolderID;
-	sd["object_id"] = mObjectID;
-	sd["type"] = LLAssetType::lookup(mType);
-	sd["from_name"] = mFromName;
-	sd["description"] = mDesc;
-	sd["sender"] = mHost.getIPandPort();
-	sd["persist"] = mPersist;
-	return sd;
+    sd["im_type"] = mIM;
+    sd["from_id"] = mFromID;
+    sd["from_group"] = mFromGroup;
+    sd["from_object"] = mFromObject;
+    sd["transaction_id"] = mTransactionID;
+    sd["folder_id"] = mFolderID;
+    sd["object_id"] = mObjectID;
+    sd["type"] = LLAssetType::lookup(mType);
+    sd["from_name"] = mFromName;
+    sd["description"] = mDesc;
+    sd["sender"] = mHost.getIPandPort();
+    sd["persist"] = mPersist;
+    return sd;
 }
 
 void LLOfferInfo::fromLLSD(const LLSD& params)
 {
-	*this = params;
+    *this = params;
 }
 
 void LLOfferInfo::sendReceiveResponse(bool accept, const LLUUID &destination_folder_id)
 {
-	if(IM_INVENTORY_OFFERED == mIM)
-	{
-		// add buddy to recent people list
-//		LLRecentPeople::instance().add(mFromID);
+    if(IM_INVENTORY_OFFERED == mIM)
+    {
+        // add buddy to recent people list
+//      LLRecentPeople::instance().add(mFromID);
 // [RLVa:KB] - Checked: RLVa-2.0.1
-		// RELEASE-RLVa: [RLVa-2.0.1] Make sure this stays in sync with the condition in inventory_offer_handler()
-		bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
-			(RlvActions::canShowName(RlvActions::SNC_DEFAULT, mFromID)) || (!RlvUtil::isNearbyAgent(mFromID)) || (RlvUIEnabler::hasOpenIM(mFromID)) || (RlvUIEnabler::hasOpenProfile(mFromID));
-		if (fRlvCanShowName)
-			LLRecentPeople::instance().add(mFromID);
+        // RELEASE-RLVa: [RLVa-2.0.1] Make sure this stays in sync with the condition in inventory_offer_handler()
+        bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
+            (RlvActions::canShowName(RlvActions::SNC_DEFAULT, mFromID)) || (!RlvUtil::isNearbyAgent(mFromID)) || (RlvUIEnabler::hasOpenIM(mFromID)) || (RlvUIEnabler::hasOpenProfile(mFromID));
+        if (fRlvCanShowName)
+            LLRecentPeople::instance().add(mFromID);
 // [/RLVa:KB]
-	}
-
-	if (mTransactionID.isNull())
-	{
-		// Not provided, message won't work
-		return;
-	}
-
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_ImprovedInstantMessage);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_MessageBlock);
-	msg->addBOOLFast(_PREHASH_FromGroup, FALSE);
-	msg->addUUIDFast(_PREHASH_ToAgentID, mFromID);
-	msg->addU8Fast(_PREHASH_Offline, IM_ONLINE);
-	msg->addUUIDFast(_PREHASH_ID, mTransactionID);
-	msg->addU32Fast(_PREHASH_Timestamp, NO_TIMESTAMP); // no timestamp necessary
-	std::string name;
-	LLAgentUI::buildFullname(name);
-	msg->addStringFast(_PREHASH_FromAgentName, name);
-	msg->addStringFast(_PREHASH_Message, ""); 
-	msg->addU32Fast(_PREHASH_ParentEstateID, 0);
-	msg->addUUIDFast(_PREHASH_RegionID, LLUUID::null);
-	msg->addVector3Fast(_PREHASH_Position, gAgent.getPositionAgent());
-
-	// ACCEPT. The math for the dialog works, because the accept
-	// for inventory_offered, task_inventory_offer or
-	// group_notice_inventory is 1 greater than the offer integer value.
-	// Generates IM_INVENTORY_ACCEPTED, IM_TASK_INVENTORY_ACCEPTED, 
-	// or IM_GROUP_NOTICE_INVENTORY_ACCEPTED
-	// Decline for inventory_offered, task_inventory_offer or
-	// group_notice_inventory is 2 greater than the offer integer value.
-
-	EInstantMessage im = mIM;
-	if (mIM == IM_GROUP_NOTICE_REQUESTED)
-	{
-		// Request has no responder dialogs
-		im = IM_GROUP_NOTICE;
-	}
-
-	if (accept)
-	{
-		msg->addU8Fast(_PREHASH_Dialog, (U8)(im + 1));
-		msg->addBinaryDataFast(_PREHASH_BinaryBucket, &(destination_folder_id.mData),
-								sizeof(destination_folder_id.mData));
-	}
-	else
-	{
-		msg->addU8Fast(_PREHASH_Dialog, (U8)(im + 2));
-		msg->addBinaryDataFast(_PREHASH_BinaryBucket, EMPTY_BINARY_BUCKET, EMPTY_BINARY_BUCKET_SIZE);
-	}
-	// send the message
-	msg->sendReliable(mHost);
-
-	// transaction id is usable only once
-	// Note: a bit of a hack, clicking group notice attachment will not close notice
-	// so we reset no longer usable transaction id to know not to send message again
-	// Once capabilities for responses will be implemented LLOfferInfo will have to
-	// remember that it already responded in another way and ignore IOR_DECLINE
-	mTransactionID.setNull();
+    }
+
+    if (mTransactionID.isNull())
+    {
+        // Not provided, message won't work
+        return;
+    }
+
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_ImprovedInstantMessage);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_MessageBlock);
+    msg->addBOOLFast(_PREHASH_FromGroup, FALSE);
+    msg->addUUIDFast(_PREHASH_ToAgentID, mFromID);
+    msg->addU8Fast(_PREHASH_Offline, IM_ONLINE);
+    msg->addUUIDFast(_PREHASH_ID, mTransactionID);
+    msg->addU32Fast(_PREHASH_Timestamp, NO_TIMESTAMP); // no timestamp necessary
+    std::string name;
+    LLAgentUI::buildFullname(name);
+    msg->addStringFast(_PREHASH_FromAgentName, name);
+    msg->addStringFast(_PREHASH_Message, "");
+    msg->addU32Fast(_PREHASH_ParentEstateID, 0);
+    msg->addUUIDFast(_PREHASH_RegionID, LLUUID::null);
+    msg->addVector3Fast(_PREHASH_Position, gAgent.getPositionAgent());
+
+    // ACCEPT. The math for the dialog works, because the accept
+    // for inventory_offered, task_inventory_offer or
+    // group_notice_inventory is 1 greater than the offer integer value.
+    // Generates IM_INVENTORY_ACCEPTED, IM_TASK_INVENTORY_ACCEPTED,
+    // or IM_GROUP_NOTICE_INVENTORY_ACCEPTED
+    // Decline for inventory_offered, task_inventory_offer or
+    // group_notice_inventory is 2 greater than the offer integer value.
+
+    EInstantMessage im = mIM;
+    if (mIM == IM_GROUP_NOTICE_REQUESTED)
+    {
+        // Request has no responder dialogs
+        im = IM_GROUP_NOTICE;
+    }
+
+    if (accept)
+    {
+        msg->addU8Fast(_PREHASH_Dialog, (U8)(im + 1));
+        msg->addBinaryDataFast(_PREHASH_BinaryBucket, &(destination_folder_id.mData),
+                                sizeof(destination_folder_id.mData));
+    }
+    else
+    {
+        msg->addU8Fast(_PREHASH_Dialog, (U8)(im + 2));
+        msg->addBinaryDataFast(_PREHASH_BinaryBucket, EMPTY_BINARY_BUCKET, EMPTY_BINARY_BUCKET_SIZE);
+    }
+    // send the message
+    msg->sendReliable(mHost);
+
+    // transaction id is usable only once
+    // Note: a bit of a hack, clicking group notice attachment will not close notice
+    // so we reset no longer usable transaction id to know not to send message again
+    // Once capabilities for responses will be implemented LLOfferInfo will have to
+    // remember that it already responded in another way and ignore IOR_DECLINE
+    mTransactionID.setNull();
 }
 
 void LLOfferInfo::handleRespond(const LLSD& notification, const LLSD& response)
 {
-	initRespondFunctionMap();
+    initRespondFunctionMap();
 
-	const std::string name = notification["name"].asString();
-	if(mRespondFunctions.find(name) == mRespondFunctions.end())
-	{
-		LL_WARNS() << "Unexpected notification name : " << name << LL_ENDL;
-		llassert(!"Unexpected notification name");
-		return;
-	}
+    const std::string name = notification["name"].asString();
+    if(mRespondFunctions.find(name) == mRespondFunctions.end())
+    {
+        LL_WARNS() << "Unexpected notification name : " << name << LL_ENDL;
+        llassert(!"Unexpected notification name");
+        return;
+    }
 
-	mRespondFunctions[name](notification, response);
+    mRespondFunctions[name](notification, response);
 }
 
 bool LLOfferInfo::inventory_offer_callback(const LLSD& notification, const LLSD& response)
 {
-	LLChat chat;
-	std::string log_message;
-	S32 button = LLNotificationsUtil::getSelectedOption(notification, response);
-
-	LLInventoryObserver* opener = NULL;
-	LLViewerInventoryCategory* catp = NULL;
-	catp = (LLViewerInventoryCategory*)gInventory.getCategory(mObjectID);
-	LLViewerInventoryItem* itemp = NULL;
-	if(!catp)
-	{
-		itemp = (LLViewerInventoryItem*)gInventory.getItem(mObjectID);
-	}
-	 
-	LLNotificationPtr notification_ptr = LLNotifications::instance().find(notification["id"].asUUID());
-	
-	// For muting, we need to add the mute, then decline the offer.
-	// This must be done here because:
-	// * callback may be called immediately,
-	// * adding the mute sends a message,
-	// * we can't build two messages at once.
-	if (IOR_MUTE == button) // Block
-	{
-		if (notification_ptr != NULL)
-		{
-			if (mFromGroup)
-			{
-				gCacheName->getGroup(mFromID, boost::bind(&inventory_offer_mute_callback, _1, _2, _3));
-			}
-			else
-			{
-				LLAvatarNameCache::get(mFromID, boost::bind(&inventory_offer_mute_avatar_callback, _1, _2));
-			}
-		}
-	}
-
-	std::string from_string; // Used in the pop-up.
-	std::string chatHistory_string;  // Used in chat history.
-	
-	// TODO: when task inventory offers can also be handled the new way, migrate the code that sets these strings here:
-	from_string = chatHistory_string = mFromName;
-
-	// accept goes to proper folder, decline gets accepted to trash, muted gets declined
-	bool accept_to_trash = true;
-
-	LLNotificationFormPtr modified_form(notification_ptr ? new LLNotificationForm(*notification_ptr->getForm()) : new LLNotificationForm());
-
-	switch(button)
-	{
-	case IOR_SHOW:
-		// we will want to open this item when it comes back.
-		LL_DEBUGS("Messaging") << "Initializing an opener for tid: " << mTransactionID
-				 << LL_ENDL;
-		switch (mIM)
-		{
-		case IM_INVENTORY_OFFERED:
-			{
-				// This is an offer from an agent. In this case, the back
-				// end has already copied the items into your inventory,
-				// so we can fetch it out of our inventory.
+    LLChat chat;
+    std::string log_message;
+    S32 button = LLNotificationsUtil::getSelectedOption(notification, response);
+
+    LLInventoryObserver* opener = NULL;
+    LLViewerInventoryCategory* catp = NULL;
+    catp = (LLViewerInventoryCategory*)gInventory.getCategory(mObjectID);
+    LLViewerInventoryItem* itemp = NULL;
+    if(!catp)
+    {
+        itemp = (LLViewerInventoryItem*)gInventory.getItem(mObjectID);
+    }
+
+    LLNotificationPtr notification_ptr = LLNotifications::instance().find(notification["id"].asUUID());
+
+    // For muting, we need to add the mute, then decline the offer.
+    // This must be done here because:
+    // * callback may be called immediately,
+    // * adding the mute sends a message,
+    // * we can't build two messages at once.
+    if (IOR_MUTE == button) // Block
+    {
+        if (notification_ptr != NULL)
+        {
+            if (mFromGroup)
+            {
+                gCacheName->getGroup(mFromID, boost::bind(&inventory_offer_mute_callback, _1, _2, _3));
+            }
+            else
+            {
+                LLAvatarNameCache::get(mFromID, boost::bind(&inventory_offer_mute_avatar_callback, _1, _2));
+            }
+        }
+    }
+
+    std::string from_string; // Used in the pop-up.
+    std::string chatHistory_string;  // Used in chat history.
+
+    // TODO: when task inventory offers can also be handled the new way, migrate the code that sets these strings here:
+    from_string = chatHistory_string = mFromName;
+
+    // accept goes to proper folder, decline gets accepted to trash, muted gets declined
+    bool accept_to_trash = true;
+
+    LLNotificationFormPtr modified_form(notification_ptr ? new LLNotificationForm(*notification_ptr->getForm()) : new LLNotificationForm());
+
+    switch(button)
+    {
+    case IOR_SHOW:
+        // we will want to open this item when it comes back.
+        LL_DEBUGS("Messaging") << "Initializing an opener for tid: " << mTransactionID
+                 << LL_ENDL;
+        switch (mIM)
+        {
+        case IM_INVENTORY_OFFERED:
+            {
+                // This is an offer from an agent. In this case, the back
+                // end has already copied the items into your inventory,
+                // so we can fetch it out of our inventory.
 // [RLVa:KB] - Checked: 2010-04-18 (RLVa-1.2.0)
-				if ( (rlv_handler_t::isEnabled()) && (!RlvSettings::getForbidGiveToRLV()) && (LLAssetType::AT_CATEGORY == mType) && (mDesc.find(RLV_PUTINV_PREFIX) == 0) )
-				{
-					RlvGiveToRLVAgentOffer* pOfferObserver = new RlvGiveToRLVAgentOffer(mObjectID);
-					pOfferObserver->startFetch();
-					if (pOfferObserver->isFinished())
-						pOfferObserver->done();
-					else
-						gInventory.addObserver(pOfferObserver);
-				}
+                if ( (rlv_handler_t::isEnabled()) && (!RlvSettings::getForbidGiveToRLV()) && (LLAssetType::AT_CATEGORY == mType) && (mDesc.find(RLV_PUTINV_PREFIX) == 0) )
+                {
+                    RlvGiveToRLVAgentOffer* pOfferObserver = new RlvGiveToRLVAgentOffer(mObjectID);
+                    pOfferObserver->startFetch();
+                    if (pOfferObserver->isFinished())
+                        pOfferObserver->done();
+                    else
+                        gInventory.addObserver(pOfferObserver);
+                }
 // [/RLVa:KB]
 
-				{
-					LLOpenAgentOffer* open_agent_offer = new LLOpenAgentOffer(mObjectID, from_string, true);
-					open_agent_offer->startFetch();
-					if(catp || (itemp && itemp->isFinished()))
-					{
-						open_agent_offer->done();
-					}
-					else
-					{
-						opener = open_agent_offer;
-					}
-				}
-			}
-			break;
-		case IM_GROUP_NOTICE:
-		case IM_GROUP_NOTICE_REQUESTED:
-			opener = new LLOpenTaskGroupOffer;
-			sendReceiveResponse(true, mFolderID);
-			break;
-		case IM_TASK_INVENTORY_OFFERED:
-			// This is an offer from a task or group.
-			// We don't use a new instance of an opener
-			// We instead use the singular observer gOpenTaskOffer
-			// Since it already exists, we don't need to actually do anything
-			break;
-		default:
-			LL_WARNS("Messaging") << "inventory_offer_callback: unknown offer type" << LL_ENDL;
-			break;
-		}
-
-		if (modified_form != NULL)
-		{
-			modified_form->setElementEnabled("Show", false);
-		}
-		break;
-		// end switch (mIM)
-			
-	case IOR_ACCEPT:
-		//don't spam them if they are getting flooded
-		if (check_offer_throttle(mFromName, true))
-		{
-			log_message = chatHistory_string + " " + LLTrans::getString("InvOfferGaveYou") + " " + getSanitizedDescription() + LLTrans::getString(".");
-			LLSD args;
-			args["MESSAGE"] = log_message;
-			LLNotificationsUtil::add("SystemMessageTip", args);
-		}
-
-		break;
-
-	case IOR_MUTE:
-		if (modified_form != NULL)
-		{
-			modified_form->setElementEnabled("Mute", false);
-		}
-		accept_to_trash = false; // for notices, but IOR_MUTE normally doesn't happen for notices
-		// MUTE falls through to decline
-	case IOR_DECLINE:
-		{
-			{
-				LLStringUtil::format_map_t log_message_args;
-				log_message_args["DESC"] = mDesc;
-				log_message_args["NAME"] = mFromName;
-				log_message = LLTrans::getString("InvOfferDecline", log_message_args);
-			}
-			chat.mText = log_message;
-			if( LLMuteList::getInstance()->isMuted(mFromID ) && ! LLMuteList::isLinden(mFromName) )  // muting for SL-42269
-			{
-				chat.mMuted = TRUE;
-				accept_to_trash = false; // will send decline message
-			}
-
-			// *NOTE dzaporozhan
-			// Disabled logging to old chat floater to fix crash in group notices - EXT-4149
-			// LLFloaterChat::addChatHistory(chat);
-			
-			if (mObjectID.notNull()) //make sure we can discard
-			{
-				LLDiscardAgentOffer* discard_agent_offer = new LLDiscardAgentOffer(mFolderID, mObjectID);
-				discard_agent_offer->startFetch();
-				if ((catp && gInventory.isCategoryComplete(mObjectID)) || (itemp && itemp->isFinished()))
-				{
-					discard_agent_offer->done();
-				}
-				else
-				{
-					opener = discard_agent_offer;
-				}
-			}
-			else if (mIM == IM_GROUP_NOTICE)
-			{
-				// group notice needs to request object to trash so that user will see it later
-				// Note: muted agent offers go to trash, not sure if we should do same for notices
-				LLUUID trash = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-				sendReceiveResponse(accept_to_trash, trash);
-			}
-
-			if (modified_form != NULL)
-			{
-				modified_form->setElementEnabled("Show", false);
-				modified_form->setElementEnabled("Discard", false);
-			}
-
-			break;
-		}
-	default:
-		// close button probably
-		// In case of agent offers item has already been fetched and is in your inventory, we simply won't highlight it
-		// OR delete it if the notification gets killed, since we don't want that to be a vector for 
-		// losing inventory offers.
-		if (mIM == IM_GROUP_NOTICE)
-		{
-			LLUUID trash = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-			sendReceiveResponse(true, trash);
-		}
-		break;
-	}
-
-	if(opener)
-	{
-		gInventory.addObserver(opener);
-	}
-
-	if(!mPersist)
-	{
-		delete this;
-	}
-
-	return false;
+                {
+                    LLOpenAgentOffer* open_agent_offer = new LLOpenAgentOffer(mObjectID, from_string, true);
+                    open_agent_offer->startFetch();
+                    if(catp || (itemp && itemp->isFinished()))
+                    {
+                        open_agent_offer->done();
+                    }
+                    else
+                    {
+                        opener = open_agent_offer;
+                    }
+                }
+            }
+            break;
+        case IM_GROUP_NOTICE:
+        case IM_GROUP_NOTICE_REQUESTED:
+            opener = new LLOpenTaskGroupOffer;
+            sendReceiveResponse(true, mFolderID);
+            break;
+        case IM_TASK_INVENTORY_OFFERED:
+            // This is an offer from a task or group.
+            // We don't use a new instance of an opener
+            // We instead use the singular observer gOpenTaskOffer
+            // Since it already exists, we don't need to actually do anything
+            break;
+        default:
+            LL_WARNS("Messaging") << "inventory_offer_callback: unknown offer type" << LL_ENDL;
+            break;
+        }
+
+        if (modified_form != NULL)
+        {
+            modified_form->setElementEnabled("Show", false);
+        }
+        break;
+        // end switch (mIM)
+
+    case IOR_ACCEPT:
+        //don't spam them if they are getting flooded
+        if (check_offer_throttle(mFromName, true))
+        {
+            log_message = chatHistory_string + " " + LLTrans::getString("InvOfferGaveYou") + " " + getSanitizedDescription() + LLTrans::getString(".");
+            LLSD args;
+            args["MESSAGE"] = log_message;
+            LLNotificationsUtil::add("SystemMessageTip", args);
+        }
+
+        break;
+
+    case IOR_MUTE:
+        if (modified_form != NULL)
+        {
+            modified_form->setElementEnabled("Mute", false);
+        }
+        accept_to_trash = false; // for notices, but IOR_MUTE normally doesn't happen for notices
+        // MUTE falls through to decline
+    case IOR_DECLINE:
+        {
+            {
+                LLStringUtil::format_map_t log_message_args;
+                log_message_args["DESC"] = mDesc;
+                log_message_args["NAME"] = mFromName;
+                log_message = LLTrans::getString("InvOfferDecline", log_message_args);
+            }
+            chat.mText = log_message;
+            if( LLMuteList::getInstance()->isMuted(mFromID ) && ! LLMuteList::isLinden(mFromName) )  // muting for SL-42269
+            {
+                chat.mMuted = TRUE;
+                accept_to_trash = false; // will send decline message
+            }
+
+            // *NOTE dzaporozhan
+            // Disabled logging to old chat floater to fix crash in group notices - EXT-4149
+            // LLFloaterChat::addChatHistory(chat);
+
+            if (mObjectID.notNull()) //make sure we can discard
+            {
+                LLDiscardAgentOffer* discard_agent_offer = new LLDiscardAgentOffer(mFolderID, mObjectID);
+                discard_agent_offer->startFetch();
+                if ((catp && gInventory.isCategoryComplete(mObjectID)) || (itemp && itemp->isFinished()))
+                {
+                    discard_agent_offer->done();
+                }
+                else
+                {
+                    opener = discard_agent_offer;
+                }
+            }
+            else if (mIM == IM_GROUP_NOTICE)
+            {
+                // group notice needs to request object to trash so that user will see it later
+                // Note: muted agent offers go to trash, not sure if we should do same for notices
+                LLUUID trash = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+                sendReceiveResponse(accept_to_trash, trash);
+            }
+
+            if (modified_form != NULL)
+            {
+                modified_form->setElementEnabled("Show", false);
+                modified_form->setElementEnabled("Discard", false);
+            }
+
+            break;
+        }
+    default:
+        // close button probably
+        // In case of agent offers item has already been fetched and is in your inventory, we simply won't highlight it
+        // OR delete it if the notification gets killed, since we don't want that to be a vector for
+        // losing inventory offers.
+        if (mIM == IM_GROUP_NOTICE)
+        {
+            LLUUID trash = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+            sendReceiveResponse(true, trash);
+        }
+        break;
+    }
+
+    if(opener)
+    {
+        gInventory.addObserver(opener);
+    }
+
+    if(!mPersist)
+    {
+        delete this;
+    }
+
+    return false;
 }
 
 bool LLOfferInfo::inventory_task_offer_callback(const LLSD& notification, const LLSD& response)
 {
-	LLChat chat;
-	std::string log_message;
-	S32 button = LLNotification::getSelectedOption(notification, response);
-	
-	// For muting, we need to add the mute, then decline the offer.
-	// This must be done here because:
-	// * callback may be called immediately,
-	// * adding the mute sends a message,
-	// * we can't build two messages at once.
-	if (2 == button)
-	{
-		LLNotificationPtr notification_ptr = LLNotifications::instance().find(notification["id"].asUUID());
-
-		llassert(notification_ptr != NULL);
-		if (notification_ptr != NULL)
-		{
-			if (mFromGroup)
-			{
-				gCacheName->getGroup(mFromID, boost::bind(&inventory_offer_mute_callback, _1, _2, _3));
-			}
-			else
-			{
-				LLAvatarNameCache::get(mFromID, boost::bind(&inventory_offer_mute_avatar_callback, _1, _2));
-			}
-		}
-	}
-
-	std::string from_string; // Used in the pop-up.
-	std::string chatHistory_string;  // Used in chat history.
-
-	if (mFromObject == TRUE)
-	{
-		if (mFromGroup)
-		{
-			std::string group_name;
-			if (gCacheName->getGroupName(mFromID, group_name))
-			{
-				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+"'" 
-				+ mFromName + LLTrans::getString("'") +" " + LLTrans::getString("InvOfferOwnedByGroup") 
-				+ " "+ "'" + group_name + "'";
-				
-				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByGroup") 
-				+ " " + group_name + "'";
-			}
-			else
-			{
-				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+"'"
-				+ mFromName +"'"+ " " + LLTrans::getString("InvOfferOwnedByUnknownGroup");
-				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByUnknownGroup");
-			}
-		}
-		else
-		{
+    LLChat chat;
+    std::string log_message;
+    S32 button = LLNotification::getSelectedOption(notification, response);
+
+    // For muting, we need to add the mute, then decline the offer.
+    // This must be done here because:
+    // * callback may be called immediately,
+    // * adding the mute sends a message,
+    // * we can't build two messages at once.
+    if (2 == button)
+    {
+        LLNotificationPtr notification_ptr = LLNotifications::instance().find(notification["id"].asUUID());
+
+        llassert(notification_ptr != NULL);
+        if (notification_ptr != NULL)
+        {
+            if (mFromGroup)
+            {
+                gCacheName->getGroup(mFromID, boost::bind(&inventory_offer_mute_callback, _1, _2, _3));
+            }
+            else
+            {
+                LLAvatarNameCache::get(mFromID, boost::bind(&inventory_offer_mute_avatar_callback, _1, _2));
+            }
+        }
+    }
+
+    std::string from_string; // Used in the pop-up.
+    std::string chatHistory_string;  // Used in chat history.
+
+    if (mFromObject == TRUE)
+    {
+        if (mFromGroup)
+        {
+            std::string group_name;
+            if (gCacheName->getGroupName(mFromID, group_name))
+            {
+                from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+"'"
+                + mFromName + LLTrans::getString("'") +" " + LLTrans::getString("InvOfferOwnedByGroup")
+                + " "+ "'" + group_name + "'";
+
+                chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByGroup")
+                + " " + group_name + "'";
+            }
+            else
+            {
+                from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+"'"
+                + mFromName +"'"+ " " + LLTrans::getString("InvOfferOwnedByUnknownGroup");
+                chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByUnknownGroup");
+            }
+        }
+        else
+        {
 /*
-			LLAvatarName av_name;
-			if (LLAvatarNameCache::get(mFromID, &av_name))
-			{
-				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+ LLTrans::getString("'") + mFromName 
-					+ LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedBy") + av_name.getUserName();
-				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedBy") + " " + av_name.getUserName();
-			}
-			else
-			{
-				from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+LLTrans::getString("'") 
-				+ mFromName + LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedByUnknownUser");
-				chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByUnknownUser");
-			}
+            LLAvatarName av_name;
+            if (LLAvatarNameCache::get(mFromID, &av_name))
+            {
+                from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+ LLTrans::getString("'") + mFromName
+                    + LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedBy") + av_name.getUserName();
+                chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedBy") + " " + av_name.getUserName();
+            }
+            else
+            {
+                from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+LLTrans::getString("'")
+                + mFromName + LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedByUnknownUser");
+                chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedByUnknownUser");
+            }
 */
 // [SL:KB] - Checked: 2010-11-02 (RLVa-1.2.2a) | Added: RLVa-1.2.2a
-			std::string name_slurl = LLSLURL("agent", mFromID, "about").getSLURLString();
+            std::string name_slurl = LLSLURL("agent", mFromID, "about").getSLURLString();
 
 // [RLVa:KB] - Checked: RLVa-2.0.1
-			// RELEASE-RLVa: [RLVa-2.0.1] Make sure this stays in sync with the condition in inventory_offer_handler()
-			bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
-				(RlvActions::canShowName(RlvActions::SNC_DEFAULT, mFromID)) || (!RlvUtil::isNearbyAgent(mFromID)) || (RlvUIEnabler::hasOpenIM(mFromID)) || (RlvUIEnabler::hasOpenProfile(mFromID));
-			if (!fRlvCanShowName)
-				name_slurl = LLSLURL("agent", mFromID, "rlvanonym").getSLURLString();
+            // RELEASE-RLVa: [RLVa-2.0.1] Make sure this stays in sync with the condition in inventory_offer_handler()
+            bool fRlvCanShowName = (!RlvActions::isRlvEnabled()) ||
+                (RlvActions::canShowName(RlvActions::SNC_DEFAULT, mFromID)) || (!RlvUtil::isNearbyAgent(mFromID)) || (RlvUIEnabler::hasOpenIM(mFromID)) || (RlvUIEnabler::hasOpenProfile(mFromID));
+            if (!fRlvCanShowName)
+                name_slurl = LLSLURL("agent", mFromID, "rlvanonym").getSLURLString();
 // [/RLVa:KB]
 
-			from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+ LLTrans::getString("'") + mFromName 
-				+ LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedBy") + name_slurl;
-			chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedBy") + " " + name_slurl;
+            from_string = LLTrans::getString("InvOfferAnObjectNamed") + " "+ LLTrans::getString("'") + mFromName
+                + LLTrans::getString("'")+" " + LLTrans::getString("InvOfferOwnedBy") + name_slurl;
+            chatHistory_string = mFromName + " " + LLTrans::getString("InvOfferOwnedBy") + " " + name_slurl;
 // [/SL:KB]
-		}
-	}
-	else
-	{
-		from_string = chatHistory_string = mFromName;
-	}
-	
-	LLUUID destination;
-	bool accept = true;
-
-	// If user accepted, accept to proper folder, if user discarded, accept to trash.
-	switch(button)
-	{
-		case IOR_ACCEPT:
+        }
+    }
+    else
+    {
+        from_string = chatHistory_string = mFromName;
+    }
+
+    LLUUID destination;
+    bool accept = true;
+
+    // If user accepted, accept to proper folder, if user discarded, accept to trash.
+    switch(button)
+    {
+        case IOR_ACCEPT:
 // [RLVa:KB] - Checked: 2010-09-23 (RLVa-1.2.1)
-			// Only treat the offer as 'Give to #RLV' if:
-			//   - the user has enabled the feature
-			//   - the inventory offer came from a script (and specifies a folder)
-			//   - the name starts with the prefix - mDesc format: '[OBJECTNAME]'  ( http://slurl.com/... )
-			if ( (rlv_handler_t::isEnabled()) && (IM_TASK_INVENTORY_OFFERED == mIM) && (LLAssetType::AT_CATEGORY == mType) && (mDesc.find(RLV_PUTINV_PREFIX) == 1) )
-			{
-				if (!RlvSettings::getForbidGiveToRLV())
-				{
-					const LLUUID& idRlvRoot = RlvInventory::instance().getSharedRootID();
-					if (idRlvRoot.notNull())
-						mFolderID = idRlvRoot;
-
-					// "accepted_in_rlv" is sent from RlvGiveToRLVTaskOffer *after* we have the folder
-					RlvGiveToRLVTaskOffer* pOfferObserver = new RlvGiveToRLVTaskOffer(mTransactionID);
-					gInventory.addObserver(pOfferObserver);
-				}
-				else
-				{
-					std::string::size_type idxToken = mDesc.find("'  ( http://");
-					if (std::string::npos != idxToken)
-					{
-						RlvBehaviourNotifyHandler::sendNotification("accepted_in_inv inv_offer " + mDesc.substr(1, idxToken - 1));
-					}
-				}
-			}
+            // Only treat the offer as 'Give to #RLV' if:
+            //   - the user has enabled the feature
+            //   - the inventory offer came from a script (and specifies a folder)
+            //   - the name starts with the prefix - mDesc format: '[OBJECTNAME]'  ( http://slurl.com/... )
+            if ( (rlv_handler_t::isEnabled()) && (IM_TASK_INVENTORY_OFFERED == mIM) && (LLAssetType::AT_CATEGORY == mType) && (mDesc.find(RLV_PUTINV_PREFIX) == 1) )
+            {
+                if (!RlvSettings::getForbidGiveToRLV())
+                {
+                    const LLUUID& idRlvRoot = RlvInventory::instance().getSharedRootID();
+                    if (idRlvRoot.notNull())
+                        mFolderID = idRlvRoot;
+
+                    // "accepted_in_rlv" is sent from RlvGiveToRLVTaskOffer *after* we have the folder
+                    RlvGiveToRLVTaskOffer* pOfferObserver = new RlvGiveToRLVTaskOffer(mTransactionID);
+                    gInventory.addObserver(pOfferObserver);
+                }
+                else
+                {
+                    std::string::size_type idxToken = mDesc.find("'  ( http://");
+                    if (std::string::npos != idxToken)
+                    {
+                        RlvBehaviourNotifyHandler::sendNotification("accepted_in_inv inv_offer " + mDesc.substr(1, idxToken - 1));
+                    }
+                }
+            }
 // [/RLVa:KB]
 
-			destination = mFolderID;
-			//don't spam user if flooded
-			if (check_offer_throttle(mFromName, true))
-			{
-				log_message = chatHistory_string + " " + LLTrans::getString("InvOfferGaveYou") + " " + getSanitizedDescription() + LLTrans::getString(".");
-				LLSD args;
-				args["MESSAGE"] = log_message;
-				LLNotificationsUtil::add("SystemMessageTip", args);
-			}
-			break;
-		case IOR_MUTE:
-			// MUTE falls through to decline
-			accept = false;
-		case IOR_DECLINE:
-		default:
-			// close button probably (or any of the fall-throughs from above)
-			destination = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
-			if (accept && LLMuteList::getInstance()->isMuted(mFromID, mFromName))
-			{
-				// Note: muted offers are usually declined automatically,
-				// but user can mute object after receiving message
-				accept = false;
-			}
+            destination = mFolderID;
+            //don't spam user if flooded
+            if (check_offer_throttle(mFromName, true))
+            {
+                log_message = chatHistory_string + " " + LLTrans::getString("InvOfferGaveYou") + " " + getSanitizedDescription() + LLTrans::getString(".");
+                LLSD args;
+                args["MESSAGE"] = log_message;
+                LLNotificationsUtil::add("SystemMessageTip", args);
+            }
+            break;
+        case IOR_MUTE:
+            // MUTE falls through to decline
+            accept = false;
+        case IOR_DECLINE:
+        default:
+            // close button probably (or any of the fall-throughs from above)
+            destination = gInventory.findCategoryUUIDForType(LLFolderType::FT_TRASH);
+            if (accept && LLMuteList::getInstance()->isMuted(mFromID, mFromName))
+            {
+                // Note: muted offers are usually declined automatically,
+                // but user can mute object after receiving message
+                accept = false;
+            }
 
 // [RLVa:KB] - Checked: 2010-09-23 (RLVa-1.2.1e) | Added: RLVa-1.2.1e
-			if ( (rlv_handler_t::isEnabled()) && 
-				 (IM_TASK_INVENTORY_OFFERED == mIM) && (LLAssetType::AT_CATEGORY == mType) && (mDesc.find(RLV_PUTINV_PREFIX) == 1) )
-			{
-				std::string::size_type idxToken = mDesc.find("'  ( http://");
-				if (std::string::npos != idxToken)
-					RlvBehaviourNotifyHandler::sendNotification("declined inv_offer " + mDesc.substr(1, idxToken - 1));
-			}
+            if ( (rlv_handler_t::isEnabled()) &&
+                 (IM_TASK_INVENTORY_OFFERED == mIM) && (LLAssetType::AT_CATEGORY == mType) && (mDesc.find(RLV_PUTINV_PREFIX) == 1) )
+            {
+                std::string::size_type idxToken = mDesc.find("'  ( http://");
+                if (std::string::npos != idxToken)
+                    RlvBehaviourNotifyHandler::sendNotification("declined inv_offer " + mDesc.substr(1, idxToken - 1));
+            }
 // [/RLVa:KB]
 
-			break;
-	}
+            break;
+    }
 
-	sendReceiveResponse(accept, destination);
+    sendReceiveResponse(accept, destination);
 
-	if(!mPersist)
-	{
-		delete this;
-	}
-	return false;
+    if(!mPersist)
+    {
+        delete this;
+    }
+    return false;
 }
 
 std::string LLOfferInfo::getSanitizedDescription()
 {
-	// currently we get description from server as: 'Object' ( Location )
-	// object name shouldn't be shown as a hyperlink
-	std::string description = mDesc;
+    // currently we get description from server as: 'Object' ( Location )
+    // object name shouldn't be shown as a hyperlink
+    std::string description = mDesc;
 
-	std::size_t start = mDesc.find_first_of("'");
-	std::size_t end = mDesc.find_last_of("'");
-	if ((start != std::string::npos) && (end != std::string::npos))
-	{
-		description.insert(start, "<nolink>");
-		description.insert(end + 8, "</nolink>");
-	}
-	return description;
+    std::size_t start = mDesc.find_first_of("'");
+    std::size_t end = mDesc.find_last_of("'");
+    if ((start != std::string::npos) && (end != std::string::npos))
+    {
+        description.insert(start, "<nolink>");
+        description.insert(end + 8, "</nolink>");
+    }
+    return description;
 }
 
 
 void LLOfferInfo::initRespondFunctionMap()
 {
-	if(mRespondFunctions.empty())
-	{
-		mRespondFunctions["ObjectGiveItem"] = boost::bind(&LLOfferInfo::inventory_task_offer_callback, this, _1, _2);
-		mRespondFunctions["OwnObjectGiveItem"] = boost::bind(&LLOfferInfo::inventory_task_offer_callback, this, _1, _2);
-		mRespondFunctions["UserGiveItem"] = boost::bind(&LLOfferInfo::inventory_offer_callback, this, _1, _2);
-	}
+    if(mRespondFunctions.empty())
+    {
+        mRespondFunctions["ObjectGiveItem"] = boost::bind(&LLOfferInfo::inventory_task_offer_callback, this, _1, _2);
+        mRespondFunctions["OwnObjectGiveItem"] = boost::bind(&LLOfferInfo::inventory_task_offer_callback, this, _1, _2);
+        mRespondFunctions["UserGiveItem"] = boost::bind(&LLOfferInfo::inventory_offer_callback, this, _1, _2);
+    }
 }
 
 bool lure_callback(const LLSD& notification, const LLSD& response)
 {
-	S32 option = 0;
-	if (response.isInteger()) 
-	{
-		option = response.asInteger();
-	}
-	else
-	{
-		option = LLNotificationsUtil::getSelectedOption(notification, response);
-	}
-	
-	LLUUID from_id = notification["payload"]["from_id"].asUUID();
-	LLUUID lure_id = notification["payload"]["lure_id"].asUUID();
-	BOOL godlike = notification["payload"]["godlike"].asBoolean();
-
-	switch(option)
-	{
-	case 0:
-		{
-			// accept
-			gAgent.teleportViaLure(lure_id, godlike);
-		}
-		break;
-	case 1:
-	default:
-		// decline
-		send_simple_im(from_id,
-					   LLStringUtil::null,
-					   IM_LURE_DECLINED,
-					   lure_id);
-		break;
-	}
-
-	LLNotificationPtr notification_ptr = LLNotifications::instance().find(notification["id"].asUUID());
-
-	if (notification_ptr)
-	{
-		LLNotificationFormPtr modified_form(new LLNotificationForm(*notification_ptr->getForm()));
-		modified_form->setElementEnabled("Teleport", false);
-		modified_form->setElementEnabled("Cancel", false);
-		notification_ptr->updateForm(modified_form);
+    S32 option = 0;
+    if (response.isInteger())
+    {
+        option = response.asInteger();
+    }
+    else
+    {
+        option = LLNotificationsUtil::getSelectedOption(notification, response);
+    }
+
+    LLUUID from_id = notification["payload"]["from_id"].asUUID();
+    LLUUID lure_id = notification["payload"]["lure_id"].asUUID();
+    BOOL godlike = notification["payload"]["godlike"].asBoolean();
+
+    switch(option)
+    {
+    case 0:
+        {
+            // accept
+            gAgent.teleportViaLure(lure_id, godlike);
+        }
+        break;
+    case 1:
+    default:
+        // decline
+        send_simple_im(from_id,
+                       LLStringUtil::null,
+                       IM_LURE_DECLINED,
+                       lure_id);
+        break;
+    }
+
+    LLNotificationPtr notification_ptr = LLNotifications::instance().find(notification["id"].asUUID());
+
+    if (notification_ptr)
+    {
+        LLNotificationFormPtr modified_form(new LLNotificationForm(*notification_ptr->getForm()));
+        modified_form->setElementEnabled("Teleport", false);
+        modified_form->setElementEnabled("Cancel", false);
+        notification_ptr->updateForm(modified_form);
 
 // [SL:KB] - Patch: UI-Notifications | Checked: 2013-05-09 (Catznip-3.5)
-		// Assume that any offer notification with "getCanBeStored() == true" is the result of RLVa routing it to the notifcation syswell
-		/*const*/ LLNotificationsUI::LLScreenChannel* pChannel = LLNotificationsUI::LLChannelManager::instance().getNotificationScreenChannel();
-		/*const*/ LLNotificationsUI::LLToast* pToast = (pChannel) ? pChannel->getToastByNotificationID(notification["id"].asUUID()) : NULL;
-		if ( (!pToast) || (!pToast->getCanBeStored()) )
-		{
+        // Assume that any offer notification with "getCanBeStored() == true" is the result of RLVa routing it to the notifcation syswell
+        /*const*/ LLNotificationsUI::LLScreenChannel* pChannel = LLNotificationsUI::LLChannelManager::instance().getNotificationScreenChannel();
+        /*const*/ LLNotificationsUI::LLToast* pToast = (pChannel) ? pChannel->getToastByNotificationID(notification["id"].asUUID()) : NULL;
+        if ( (!pToast) || (!pToast->getCanBeStored()) )
+        {
 // [/SL:KB]
-			notification_ptr->repost();
+            notification_ptr->repost();
 // [SL:KB] - Patch: UI-Notifications | Checked: 2013-05-09 (Catznip-3.5)
-		}
+        }
 // [/SL:KB]
-	}
+    }
 
-	return false;
+    return false;
 }
 static LLNotificationFunctorRegistration lure_callback_reg("TeleportOffered", lure_callback);
 
 bool mature_lure_callback(const LLSD& notification, const LLSD& response)
 {
-	S32 option = 0;
-	if (response.isInteger()) 
-	{
-		option = response.asInteger();
-	}
-	else
-	{
-		option = LLNotificationsUtil::getSelectedOption(notification, response);
-	}
-	
-	LLUUID from_id = notification["payload"]["from_id"].asUUID();
-	LLUUID lure_id = notification["payload"]["lure_id"].asUUID();
-	BOOL godlike = notification["payload"]["godlike"].asBoolean();
-	U8 region_access = static_cast<U8>(notification["payload"]["region_maturity"].asInteger());
-
-	switch(option)
-	{
-	case 0:
-		{
-			// accept
-			gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(region_access));
-			gAgent.setMaturityRatingChangeDuringTeleport(region_access);
-			gAgent.teleportViaLure(lure_id, godlike);
-		}
-		break;
-	case 1:
-	default:
-		// decline
-		send_simple_im(from_id,
-					   LLStringUtil::null,
-					   IM_LURE_DECLINED,
-					   lure_id);
-		break;
-	}
-	return false;
+    S32 option = 0;
+    if (response.isInteger())
+    {
+        option = response.asInteger();
+    }
+    else
+    {
+        option = LLNotificationsUtil::getSelectedOption(notification, response);
+    }
+
+    LLUUID from_id = notification["payload"]["from_id"].asUUID();
+    LLUUID lure_id = notification["payload"]["lure_id"].asUUID();
+    BOOL godlike = notification["payload"]["godlike"].asBoolean();
+    U8 region_access = static_cast<U8>(notification["payload"]["region_maturity"].asInteger());
+
+    switch(option)
+    {
+    case 0:
+        {
+            // accept
+            gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(region_access));
+            gAgent.setMaturityRatingChangeDuringTeleport(region_access);
+            gAgent.teleportViaLure(lure_id, godlike);
+        }
+        break;
+    case 1:
+    default:
+        // decline
+        send_simple_im(from_id,
+                       LLStringUtil::null,
+                       IM_LURE_DECLINED,
+                       lure_id);
+        break;
+    }
+    return false;
 }
 static LLNotificationFunctorRegistration mature_lure_callback_reg("TeleportOffered_MaturityExceeded", mature_lure_callback);
 
 bool goto_url_callback(const LLSD& notification, const LLSD& response)
 {
-	std::string url = notification["payload"]["url"].asString();
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if(1 == option)
-	{
-		LLWeb::loadURL(url);
-	}
-	return false;
+    std::string url = notification["payload"]["url"].asString();
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if(1 == option)
+    {
+        LLWeb::loadURL(url);
+    }
+    return false;
 }
 static LLNotificationFunctorRegistration goto_url_callback_reg("GotoURL", goto_url_callback);
 
 bool inspect_remote_object_callback(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	if (0 == option)
-	{
-		LLFloaterReg::showInstance("inspect_remote_object", notification["payload"]);
-	}
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    if (0 == option)
+    {
+        LLFloaterReg::showInstance("inspect_remote_object", notification["payload"]);
+    }
+    return false;
 }
 static LLNotificationFunctorRegistration inspect_remote_object_callback_reg("ServerObjectMessage", inspect_remote_object_callback);
 
 class LLPostponedServerObjectNotification: public LLPostponedNotification
 {
 protected:
-	/* virtual */
-	void modifyNotificationParams()
-	{
-		LLSD payload = mParams.payload;
-		mParams.payload = payload;
-	}
+    /* virtual */
+    void modifyNotificationParams()
+    {
+        LLSD payload = mParams.payload;
+        mParams.payload = payload;
+    }
 };
 
 void process_improved_im(LLMessageSystem *msg, void **user_data)
@@ -2415,7 +2415,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
     msg->getU8Fast(_PREHASH_MessageBlock, _PREHASH_Dialog, d);
     msg->getUUIDFast(_PREHASH_MessageBlock, _PREHASH_ID, session_id);
     msg->getU32Fast(_PREHASH_MessageBlock, _PREHASH_Timestamp, timestamp);
-    //msg->getDataFast(_PREHASH_MessageBlock, _PREHASH_Count,		&count);
+    //msg->getDataFast(_PREHASH_MessageBlock, _PREHASH_Count,       &count);
     msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_FromAgentName, agentName);
     msg->getStringFast(_PREHASH_MessageBlock, _PREHASH_Message, message);
     msg->getU32Fast(_PREHASH_MessageBlock, _PREHASH_ParentEstateID, parent_estate_id);
@@ -2427,7 +2427,7 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
     LLHost sender = msg->getSender();
 
     LLIMProcessing::processNewMessage(
-		std::move(from_id),
+        std::move(from_id),
         from_group,
         std::move(to_id),
         offline,
@@ -2446,169 +2446,169 @@ void process_improved_im(LLMessageSystem *msg, void **user_data)
 
 void send_do_not_disturb_message (LLMessageSystem* msg, const LLUUID& from_id, const LLUUID& session_id)
 {
-	if (gAgent.isDoNotDisturb())
-	{
-		std::string my_name;
-		LLAgentUI::buildFullname(my_name);
-		std::string response = gSavedPerAccountSettings.getString("DoNotDisturbModeResponse");
-		pack_instant_message(
-			msg,
-			gAgent.getID(),
-			FALSE,
-			gAgent.getSessionID(),
-			from_id,
-			my_name,
-			response,
-			IM_ONLINE,
-			IM_DO_NOT_DISTURB_AUTO_RESPONSE,
-			session_id);
-		gAgent.sendReliableMessage();
-	}
+    if (gAgent.isDoNotDisturb())
+    {
+        std::string my_name;
+        LLAgentUI::buildFullname(my_name);
+        std::string response = gSavedPerAccountSettings.getString("DoNotDisturbModeResponse");
+        pack_instant_message(
+            msg,
+            gAgent.getID(),
+            FALSE,
+            gAgent.getSessionID(),
+            from_id,
+            my_name,
+            response,
+            IM_ONLINE,
+            IM_DO_NOT_DISTURB_AUTO_RESPONSE,
+            session_id);
+        gAgent.sendReliableMessage();
+    }
 }
 
 void send_rejecting_tp_offers_message (LLMessageSystem* msg, const LLUUID& from_id, const LLUUID& session_id)
 {
-	std::string my_name;
-	LLAgentUI::buildFullname(my_name);
-	std::string response = gSavedPerAccountSettings.getString("ALRejectTeleportOffersResponse");
-	pack_instant_message(
-		msg,
-		gAgent.getID(),
-		FALSE,
-		gAgent.getSessionID(),
-		from_id,
-		my_name,
-		response,
-		IM_ONLINE,
-		IM_DO_NOT_DISTURB_AUTO_RESPONSE,
-		session_id);
-	gAgent.sendReliableMessage();
+    std::string my_name;
+    LLAgentUI::buildFullname(my_name);
+    std::string response = gSavedPerAccountSettings.getString("ALRejectTeleportOffersResponse");
+    pack_instant_message(
+        msg,
+        gAgent.getID(),
+        FALSE,
+        gAgent.getSessionID(),
+        from_id,
+        my_name,
+        response,
+        IM_ONLINE,
+        IM_DO_NOT_DISTURB_AUTO_RESPONSE,
+        session_id);
+    gAgent.sendReliableMessage();
 }
 
 void send_rejecting_friendship_requests_message (LLMessageSystem* msg, const LLUUID& from_id, const LLUUID& session_id)
 {
-	if (gAgent.getRejectFriendshipRequests())
-	{
-		std::string my_name;
-		LLAgentUI::buildFullname(my_name);
-		std::string response = gSavedPerAccountSettings.getString("ALRejectFriendshipRequestsResponse");
-		pack_instant_message(
-			msg,
-			gAgent.getID(),
-			FALSE,
-			gAgent.getSessionID(),
-			from_id,
-			my_name,
-			response,
-			IM_ONLINE,
-			IM_DO_NOT_DISTURB_AUTO_RESPONSE,
-			session_id);
-		gAgent.sendReliableMessage();
-	}
+    if (gAgent.getRejectFriendshipRequests())
+    {
+        std::string my_name;
+        LLAgentUI::buildFullname(my_name);
+        std::string response = gSavedPerAccountSettings.getString("ALRejectFriendshipRequestsResponse");
+        pack_instant_message(
+            msg,
+            gAgent.getID(),
+            FALSE,
+            gAgent.getSessionID(),
+            from_id,
+            my_name,
+            response,
+            IM_ONLINE,
+            IM_DO_NOT_DISTURB_AUTO_RESPONSE,
+            session_id);
+        gAgent.sendReliableMessage();
+    }
 }
 
 bool callingcard_offer_callback(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	LLUUID fid;
-	LLMessageSystem* msg = gMessageSystem;
-	switch(option)
-	{
-	case 0:
-		// accept
-		msg->newMessageFast(_PREHASH_AcceptCallingCard);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_TransactionBlock);
-		msg->addUUIDFast(_PREHASH_TransactionID, notification["payload"]["transaction_id"].asUUID());
-		fid = gInventory.findCategoryUUIDForType(LLFolderType::FT_CALLINGCARD);
-		msg->nextBlockFast(_PREHASH_FolderData);
-		msg->addUUIDFast(_PREHASH_FolderID, fid);
-		msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
-		break;
-	case 1:
-		// decline		
-		msg->newMessageFast(_PREHASH_DeclineCallingCard);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_TransactionBlock);
-		msg->addUUIDFast(_PREHASH_TransactionID, notification["payload"]["transaction_id"].asUUID());
-		msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
-		send_do_not_disturb_message(msg, notification["payload"]["source_id"].asUUID());
-		break;
-	default:
-		// close button probably, possibly timed out
-		break;
-	}
-
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    LLUUID fid;
+    LLMessageSystem* msg = gMessageSystem;
+    switch(option)
+    {
+    case 0:
+        // accept
+        msg->newMessageFast(_PREHASH_AcceptCallingCard);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        msg->nextBlockFast(_PREHASH_TransactionBlock);
+        msg->addUUIDFast(_PREHASH_TransactionID, notification["payload"]["transaction_id"].asUUID());
+        fid = gInventory.findCategoryUUIDForType(LLFolderType::FT_CALLINGCARD);
+        msg->nextBlockFast(_PREHASH_FolderData);
+        msg->addUUIDFast(_PREHASH_FolderID, fid);
+        msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
+        break;
+    case 1:
+        // decline
+        msg->newMessageFast(_PREHASH_DeclineCallingCard);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        msg->nextBlockFast(_PREHASH_TransactionBlock);
+        msg->addUUIDFast(_PREHASH_TransactionID, notification["payload"]["transaction_id"].asUUID());
+        msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
+        send_do_not_disturb_message(msg, notification["payload"]["source_id"].asUUID());
+        break;
+    default:
+        // close button probably, possibly timed out
+        break;
+    }
+
+    return false;
 }
 static LLNotificationFunctorRegistration callingcard_offer_cb_reg("OfferCallingCard", callingcard_offer_callback);
 
 void process_offer_callingcard(LLMessageSystem* msg, void**)
 {
-	// someone has offered to form a friendship
-	LL_DEBUGS("Messaging") << "callingcard offer" << LL_ENDL;
-
-	LLUUID source_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, source_id);
-	LLUUID tid;
-	msg->getUUIDFast(_PREHASH_AgentBlock, _PREHASH_TransactionID, tid);
-
-	LLSD payload;
-	payload["transaction_id"] = tid;
-	payload["source_id"] = source_id;
-	payload["sender"] = msg->getSender().getIPandPort();
-
-	LLViewerObject* source = gObjectList.findObject(source_id);
-	LLSD args;
-	std::string source_name;
-	if(source && source->isAvatar())
-	{
-		LLNameValue* nvfirst = source->getNVPair("FirstName");
-		LLNameValue* nvlast  = source->getNVPair("LastName");
-		if (nvfirst && nvlast)
-		{
-			source_name = LLCacheName::buildFullName(
-				nvfirst->getString(), nvlast->getString());
-		}
-	}
-
-	if(!source_name.empty())
-	{
-		if (gAgent.isDoNotDisturb() 
-			|| LLMuteList::getInstance()->isMuted(source_id, source_name, LLMute::flagTextChat))
-		{
-			// automatically decline offer
-			LLNotifications::instance().forceResponse(LLNotification::Params("OfferCallingCard").payload(payload), 1);
-		}
-		else
-		{
-			args["NAME"] = source_name;
-			LLNotificationsUtil::add("OfferCallingCard", args, payload);
-		}
-	}
-	else
-	{
-		LL_WARNS("Messaging") << "Calling card offer from an unknown source." << LL_ENDL;
-	}
+    // someone has offered to form a friendship
+    LL_DEBUGS("Messaging") << "callingcard offer" << LL_ENDL;
+
+    LLUUID source_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, source_id);
+    LLUUID tid;
+    msg->getUUIDFast(_PREHASH_AgentBlock, _PREHASH_TransactionID, tid);
+
+    LLSD payload;
+    payload["transaction_id"] = tid;
+    payload["source_id"] = source_id;
+    payload["sender"] = msg->getSender().getIPandPort();
+
+    LLViewerObject* source = gObjectList.findObject(source_id);
+    LLSD args;
+    std::string source_name;
+    if(source && source->isAvatar())
+    {
+        LLNameValue* nvfirst = source->getNVPair("FirstName");
+        LLNameValue* nvlast  = source->getNVPair("LastName");
+        if (nvfirst && nvlast)
+        {
+            source_name = LLCacheName::buildFullName(
+                nvfirst->getString(), nvlast->getString());
+        }
+    }
+
+    if(!source_name.empty())
+    {
+        if (gAgent.isDoNotDisturb()
+            || LLMuteList::getInstance()->isMuted(source_id, source_name, LLMute::flagTextChat))
+        {
+            // automatically decline offer
+            LLNotifications::instance().forceResponse(LLNotification::Params("OfferCallingCard").payload(payload), 1);
+        }
+        else
+        {
+            args["NAME"] = source_name;
+            LLNotificationsUtil::add("OfferCallingCard", args, payload);
+        }
+    }
+    else
+    {
+        LL_WARNS("Messaging") << "Calling card offer from an unknown source." << LL_ENDL;
+    }
 }
 
 void process_accept_callingcard(LLMessageSystem* msg, void**)
 {
-	LLNotificationsUtil::add("CallingCardAccepted");
+    LLNotificationsUtil::add("CallingCardAccepted");
 }
 
 void process_decline_callingcard(LLMessageSystem* msg, void**)
 {
-	LLNotificationsUtil::add("CallingCardDeclined");
+    LLNotificationsUtil::add("CallingCardDeclined");
 }
 
 void translateSuccess(LLChat chat, LLSD toastArgs, std::string originalMsg, std::string expectLang, std::string translation, const std::string detected_language)
 {
-    // filter out non-interesting responses  
+    // filter out non-interesting responses
     if (!translation.empty()
         && ((detected_language.empty()) || (expectLang != detected_language))
         && (LLStringUtil::compareInsensitive(translation, originalMsg) != 0))
@@ -2616,7 +2616,7 @@ void translateSuccess(LLChat chat, LLSD toastArgs, std::string originalMsg, std:
         chat.mText += " (" + LLTranslate::removeNoTranslateTags(translation) + ")";
     }
 
-	LLTranslate::instance().logSuccess(1);
+    LLTranslate::instance().logSuccess(1);
     LLNotificationsUI::LLNotificationManager::instance().onChat(chat, toastArgs);
 }
 
@@ -2626,597 +2626,597 @@ void translateFailure(LLChat chat, LLSD toastArgs, int status, const std::string
     LLStringUtil::replaceString(msg, "\n", " "); // we want one-line error messages
     chat.mText += " (" + msg + ")";
 
-	LLTranslate::instance().logFailure(1);
-    LLNotificationsUI::LLNotificationManager::instance().onChat(chat, toastArgs);
-}
+    LLTranslate::instance().logFailure(1);
+    LLNotificationsUI::LLNotificationManager::instance().onChat(chat, toastArgs);
+}
+
+
+void process_chat_from_simulator(LLMessageSystem *msg, void **user_data)
+{
+    if (gNonInteractive)
+    {
+        return;
+    }
+    LLChat  chat;
+    std::string     mesg;
+    std::string     from_name;
+    U8          source_temp;
+    U8          type_temp;
+    U8          audible_temp;
+    LLColor4    color(1.0f, 1.0f, 1.0f, 1.0f);
+    LLUUID      from_id;
+    LLUUID      owner_id;
+    LLViewerObject* chatter;
+
+    msg->getStringFast(_PREHASH_ChatData, _PREHASH_FromName, from_name);
+
+    msg->getUUIDFast(_PREHASH_ChatData, _PREHASH_SourceID, from_id);
+    chat.mFromID = from_id;
+
+    // Object owner for objects
+    msg->getUUIDFast(_PREHASH_ChatData, _PREHASH_OwnerID, owner_id);
+
+    msg->getU8Fast(_PREHASH_ChatData, _PREHASH_SourceType, source_temp);
+    chat.mSourceType = (EChatSourceType)source_temp;
+
+    msg->getU8Fast(_PREHASH_ChatData, _PREHASH_ChatType, type_temp);
+    chat.mChatType = (EChatType)type_temp;
+
+    msg->getU8Fast(_PREHASH_ChatData, _PREHASH_Audible, audible_temp);
+    chat.mAudible = (EChatAudible)audible_temp;
+
+    chat.mTime = LLFrameTimer::getElapsedSeconds();
+
+    // IDEVO Correct for new-style "Resident" names
+    if (chat.mSourceType == CHAT_SOURCE_AGENT)
+    {
+        // I don't know if it's OK to change this here, if
+        // anything downstream does lookups by name, for instance
+
+        LLAvatarName av_name;
+        if (LLAvatarNameCache::get(from_id, &av_name))
+        {
+            chat.mFromName = av_name.getCompleteName();
+        }
+        else
+        {
+            chat.mFromName = LLCacheName::cleanFullName(from_name);
+        }
+    }
+    else
+    {
+        // make sure that we don't have an empty or all-whitespace name
+        LLStringUtil::trim(from_name);
+        static const LLCachedControl<bool> sMarkUnnamedObjects(gSavedSettings, "AlchemyChatMarkUnnamedObjects", true);
+        if (sMarkUnnamedObjects && from_name.empty())
+        {
+            from_name = LLTrans::getString("Unnamed");
+        }
+        chat.mFromName = from_name;
+    }
+
+    BOOL is_do_not_disturb = gAgent.isDoNotDisturb();
+
+    BOOL is_muted = FALSE;
+    BOOL is_linden = FALSE;
+    is_muted = LLMuteList::getInstance()->isMuted(
+        from_id,
+        from_name,
+        LLMute::flagTextChat)
+        || LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagTextChat);
+    is_linden = chat.mSourceType != CHAT_SOURCE_OBJECT &&
+        LLMuteList::isLinden(from_name);
+
+    if (is_muted && (chat.mSourceType == CHAT_SOURCE_OBJECT))
+    {
+        return;
+    }
+
+    BOOL is_audible = (CHAT_AUDIBLE_FULLY == chat.mAudible);
+    chatter = gObjectList.findObject(from_id);
+    if (chatter)
+    {
+        chat.mPosAgent = chatter->getPositionAgent();
+
+        // Make swirly things only for talking objects. (not script debug messages, though)
+//      if (chat.mSourceType == CHAT_SOURCE_OBJECT
+//          && chat.mChatType != CHAT_TYPE_DEBUG_MSG
+//          && gSavedSettings.getBOOL("EffectScriptChatParticles") )
+// [RLVa:KB] - Checked: 2010-03-09 (RLVa-1.2.0b) | Modified: RLVa-1.0.0g
+        if ( ((chat.mSourceType == CHAT_SOURCE_OBJECT) && (chat.mChatType != CHAT_TYPE_DEBUG_MSG)) &&
+             (gSavedSettings.getBOOL("EffectScriptChatParticles")) &&
+             ((!rlv_handler_t::isEnabled()) || (CHAT_TYPE_OWNER != chat.mChatType)) )
+// [/RLVa:KB]
+        {
+            LLPointer<LLViewerPartSourceChat> psc = new LLViewerPartSourceChat(chatter->getPositionAgent());
+            psc->setSourceObject(chatter);
+            psc->setColor(color);
+            //We set the particles to be owned by the object's owner,
+            //just in case they should be muted by the mute list
+            psc->setOwnerUUID(owner_id);
+            LLViewerPartSim::getInstance()->addPartSource(psc);
+        }
+
+        // record last audible utterance
+        if (is_audible
+            && (is_linden || (!is_muted && !is_do_not_disturb)))
+        {
+            if (chat.mChatType != CHAT_TYPE_START
+                && chat.mChatType != CHAT_TYPE_STOP)
+            {
+                gAgent.heardChat(chat.mFromID);
+            }
+        }
+    }
+
+    if (is_audible)
+    {
+        //BOOL visible_in_chat_bubble = FALSE;
+
+        color.setVec(1.f,1.f,1.f,1.f);
+        msg->getStringFast(_PREHASH_ChatData, _PREHASH_Message, mesg);
+
+// [RLVa:KB] - Checked: 2010-04-23 (RLVa-1.2.0f) | Modified: RLVa-1.2.0f
+        if ( (rlv_handler_t::isEnabled()) && (CHAT_TYPE_START != chat.mChatType) && (CHAT_TYPE_STOP != chat.mChatType) )
+        {
+            // NOTE: chatter can be NULL (may not have rezzed yet, or could be another avie's HUD attachment)
+            BOOL is_attachment = (chatter) ? chatter->isAttachment() : FALSE;
+            BOOL is_owned_by_me = (chatter) ? chatter->permYouOwner() : FALSE;
+
+            // Filtering "rules":
+            //   avatar  => filter all avie text (unless it's this avie or they're an exemption)
+            //   objects => filter everything except attachments this avie owns (never filter llOwnerSay or llRegionSayTo chat)
+            if ( ( (CHAT_SOURCE_AGENT == chat.mSourceType) && (from_id != gAgent.getID()) ) ||
+                 ( (CHAT_SOURCE_OBJECT == chat.mSourceType) && ((!is_owned_by_me) || (!is_attachment)) &&
+                   (CHAT_TYPE_OWNER != chat.mChatType) && (CHAT_TYPE_DIRECT != chat.mChatType) ) )
+            {
+                bool fIsEmote = RlvUtil::isEmote(mesg);
+                if ((!fIsEmote) &&
+                    (((gRlvHandler.hasBehaviour(RLV_BHVR_RECVCHAT)) && (!gRlvHandler.isException(RLV_BHVR_RECVCHAT, from_id))) ||
+                     ((gRlvHandler.hasBehaviour(RLV_BHVR_RECVCHATFROM)) && (gRlvHandler.isException(RLV_BHVR_RECVCHATFROM, from_id))) ))
+                {
+                    if ( (gRlvHandler.filterChat(mesg, false)) && (!gSavedSettings.get<bool>(RlvSettingNames::ShowEllipsis)) )
+                        return;
+                }
+                else if ((fIsEmote) &&
+                         (((gRlvHandler.hasBehaviour(RLV_BHVR_RECVEMOTE)) && (!gRlvHandler.isException(RLV_BHVR_RECVEMOTE, from_id))) ||
+                          ((gRlvHandler.hasBehaviour(RLV_BHVR_RECVEMOTEFROM)) && (gRlvHandler.isException(RLV_BHVR_RECVEMOTEFROM, from_id))) ))
+                {
+                    if (!gSavedSettings.get<bool>(RlvSettingNames::ShowEllipsis))
+                        return;
+                    mesg = "/me ...";
+                }
+            }
+
+            // Filtering "rules":
+            //   avatar => filter only their name (unless it's this avie)
+            //   other  => filter everything
+            if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT))
+            {
+                if (CHAT_SOURCE_AGENT != chat.mSourceType)
+                {
+                    RlvUtil::filterNames(chat.mFromName);
+                }
+                else if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, chat.mFromID))
+                {
+                    chat.mFromName = RlvStrings::getAnonym(chat.mFromName);
+                    chat.mRlvNamesFiltered = TRUE;
+                }
+            }
+
+            // Create an "objectim" URL for objects if we're either @shownames or @showloc restricted
+            // (we need to do this now because we won't be have enough information to do it later on)
+            if ( (CHAT_SOURCE_OBJECT == chat.mSourceType) &&
+                 ( (!RlvActions::canShowName(RlvActions::SNC_DEFAULT)) || (!RlvActions::canShowLocation()) ) )
+            {
+                LLSD sdQuery;
+                sdQuery["name"] = chat.mFromName;
+                sdQuery["owner"] = owner_id;
+
+                if ( (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, owner_id)) && (!is_owned_by_me) )
+                    sdQuery["rlv_shownames"] = true;
+
+                const LLViewerRegion* pRegion = LLWorld::getInstance()->getRegionFromPosAgent(chat.mPosAgent);
+                if (pRegion)
+                    sdQuery["slurl"] = LLSLURL(pRegion->getName(), chat.mPosAgent).getLocationString();
+
+                chat.mURL = LLSLURL("objectim", from_id, LLURI::mapToQueryString(sdQuery)).getSLURLString();
+            }
+        }
+// [/RLVa:KB]
+
+        BOOL ircstyle = FALSE;
+
+        // Look for IRC-style emotes here so chatbubbles work
+        std::string prefix = mesg.substr(0, 4);
+        if (prefix == "/me " || prefix == "/me'")
+        {
+            ircstyle = TRUE;
+        }
+        chat.mText = mesg;
+
+        // Look for the start of typing so we can put "..." in the bubbles.
+        if (CHAT_TYPE_START == chat.mChatType)
+        {
+            LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, TRUE);
+
+            // Might not have the avatar constructed yet, eg on login.
+            if (chatter && chatter->isAvatar())
+            {
+                ((LLVOAvatar*)chatter)->startTyping();
+            }
+            return;
+        }
+        else if (CHAT_TYPE_STOP == chat.mChatType)
+        {
+            LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE);
+
+            // Might not have the avatar constructed yet, eg on login.
+            if (chatter && chatter->isAvatar())
+            {
+                ((LLVOAvatar*)chatter)->stopTyping();
+            }
+            return;
+        }
+
+        // Look for IRC-style emotes
+        if (ircstyle)
+        {
+            // set CHAT_STYLE_IRC to avoid adding Avatar Name as author of message. See EXT-656
+            chat.mChatStyle = CHAT_STYLE_IRC;
+
+            // Do nothing, ircstyle is fixed above for chat bubbles
+        }
+        else
+        {
+            chat.mText = "";
+            switch(chat.mChatType)
+            {
+            case CHAT_TYPE_WHISPER:
+                chat.mText = LLTrans::getString("whisper") + " ";
+                break;
+            case CHAT_TYPE_OWNER:
+// [RLVa:KB] - Checked: 2010-02-XX (RLVa-1.2.0a) | Modified: RLVa-1.1.0f
+                // TODO-RLVa: [RLVa-1.2.0] consider rewriting this before a RLVa-1.2.0 release
+                if ( (rlv_handler_t::isEnabled()) && (mesg.length() > 3) && (RLV_CMD_PREFIX == mesg[0]) && (CHAT_TYPE_OWNER == chat.mChatType) &&
+                     ((!chatter) || (!chatter->isAttachment()) || (!chatter->isTempAttachment()) || (RlvSettings::getEnableTemporaryAttachments())) )
+                {
+                    mesg.erase(0, 1);
+                    LLStringUtil::toLower(mesg);
+
+                    std::string strExecuted, strFailed, strRetained, *pstr;
+
+                    boost_tokenizer tokens(mesg, boost::char_separator<char>(",", "", boost::drop_empty_tokens));
+                    for (boost_tokenizer::iterator itToken = tokens.begin(); itToken != tokens.end(); ++itToken)
+                    {
+                        std::string strCmd = *itToken;
+
+                        ERlvCmdRet eRet = gRlvHandler.processCommand(from_id, strCmd, true);
+                        if ( (RlvSettings::getDebug()) &&
+                             ( (!RlvSettings::getDebugHideUnsetDup()) ||
+                               ((RLV_RET_SUCCESS_UNSET != eRet) && (RLV_RET_SUCCESS_DUPLICATE != eRet)) ) )
+                        {
+                            if ( RLV_RET_SUCCESS == (eRet & RLV_RET_SUCCESS) )
+                                pstr = &strExecuted;
+                            else if ( RLV_RET_FAILED == (eRet & RLV_RET_FAILED) )
+                                pstr = &strFailed;
+                            else if (RLV_RET_RETAINED == eRet)
+                                pstr = &strRetained;
+                            else
+                            {
+                                RLV_ASSERT(false);
+                                pstr = &strFailed;
+                            }
+
+                            const char* pstrSuffix = RlvStrings::getStringFromReturnCode(eRet);
+                            if (pstrSuffix)
+                                strCmd.append(" (").append(pstrSuffix).append(")");
+
+                            if (!pstr->empty())
+                                pstr->push_back(',');
+                            pstr->append(strCmd);
+                        }
+                    }
+
+                    if (RlvForceWear::instanceExists())
+                        RlvForceWear::instance().done();
+
+                    if ( (!RlvSettings::getDebug()) || ((strExecuted.empty()) && (strFailed.empty()) && (strRetained.empty())) )
+                        return;
+
+                    // Silly people want comprehensive debug messages, blah :p
+                    if ( (!strExecuted.empty()) && (strFailed.empty()) && (strRetained.empty()) )
+                    {
+                        chat.mText = " executes: @";
+                        mesg = strExecuted;
+                    }
+                    else if ( (strExecuted.empty()) && (!strFailed.empty()) && (strRetained.empty()) )
+                    {
+                        chat.mText = " failed: @";
+                        mesg = strFailed;
+                    }
+                    else if ( (strExecuted.empty()) && (strFailed.empty()) && (!strRetained.empty()) )
+                    {
+                        chat.mText = " retained: @";
+                        mesg = strRetained;
+                    }
+                    else
+                    {
+                        chat.mText = ": @";
+                        if (!strExecuted.empty())
+                            mesg += "\n    - executed: @" + strExecuted;
+                        if (!strFailed.empty())
+                            mesg += "\n    - failed: @" + strFailed;
+                        if (!strRetained.empty())
+                            mesg += "\n    - retained: @" + strRetained;
+                    }
+
+                    break;
+                }
+// [/RLVa:KB]
+// [RLVa:KB] - Checked: 2010-03-09 (RLVa-1.2.0b) | Modified: RLVa-1.0.0g
+                // Copy/paste from above
+                if  ( (rlv_handler_t::isEnabled()) && (chatter) && (chat.mSourceType == CHAT_SOURCE_OBJECT) &&
+                      (gSavedSettings.getBOOL("EffectScriptChatParticles")) )
+                {
+                    LLPointer<LLViewerPartSourceChat> psc = new LLViewerPartSourceChat(chatter->getPositionAgent());
+                    psc->setSourceObject(chatter);
+                    psc->setColor(color);
+                    //We set the particles to be owned by the object's owner,
+                    //just in case they should be muted by the mute list
+                    psc->setOwnerUUID(owner_id);
+                    LLViewerPartSim::getInstance()->addPartSource(psc);
+                }
+// [/RLVa:KB]
+            case CHAT_TYPE_DEBUG_MSG:
+            case CHAT_TYPE_NORMAL:
+            case CHAT_TYPE_DIRECT:
+                break;
+            case CHAT_TYPE_SHOUT:
+                chat.mText = LLTrans::getString("shout") + " ";
+                break;
+            case CHAT_TYPE_START:
+            case CHAT_TYPE_STOP:
+                LL_WARNS("Messaging") << "Got chat type start/stop in main chat processing." << LL_ENDL;
+                break;
+            default:
+                LL_WARNS("Messaging") << "Unknown type " << chat.mChatType << " in chat!" << LL_ENDL;
+                break;
+            }
+
+            chat.mText += mesg;
+        }
 
+        // We have a real utterance now, so can stop showing "..." and proceed.
+        if (chatter && chatter->isAvatar())
+        {
+            LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE);
+            ((LLVOAvatar*)chatter)->stopTyping();
 
-void process_chat_from_simulator(LLMessageSystem *msg, void **user_data)
-{
-	if (gNonInteractive)
-	{
-		return;
-	}
-	LLChat	chat;
-	std::string		mesg;
-	std::string		from_name;
-	U8			source_temp;
-	U8			type_temp;
-	U8			audible_temp;
-	LLColor4	color(1.0f, 1.0f, 1.0f, 1.0f);
-	LLUUID		from_id;
-	LLUUID		owner_id;
-	LLViewerObject*	chatter;
-
-	msg->getStringFast(_PREHASH_ChatData, _PREHASH_FromName, from_name);
-	
-	msg->getUUIDFast(_PREHASH_ChatData, _PREHASH_SourceID, from_id);
-	chat.mFromID = from_id;
-	
-	// Object owner for objects
-	msg->getUUIDFast(_PREHASH_ChatData, _PREHASH_OwnerID, owner_id);
-
-	msg->getU8Fast(_PREHASH_ChatData, _PREHASH_SourceType, source_temp);
-	chat.mSourceType = (EChatSourceType)source_temp;
-
-	msg->getU8Fast(_PREHASH_ChatData, _PREHASH_ChatType, type_temp);
-	chat.mChatType = (EChatType)type_temp;
-
-	msg->getU8Fast(_PREHASH_ChatData, _PREHASH_Audible, audible_temp);
-	chat.mAudible = (EChatAudible)audible_temp;
-	
-	chat.mTime = LLFrameTimer::getElapsedSeconds();
-	
-	// IDEVO Correct for new-style "Resident" names
-	if (chat.mSourceType == CHAT_SOURCE_AGENT)
-	{
-		// I don't know if it's OK to change this here, if 
-		// anything downstream does lookups by name, for instance
-		
-		LLAvatarName av_name;
-		if (LLAvatarNameCache::get(from_id, &av_name))
-		{
-			chat.mFromName = av_name.getCompleteName();
-		}
-		else
-		{
-			chat.mFromName = LLCacheName::cleanFullName(from_name);
-		}
-	}
-	else
-	{
-		// make sure that we don't have an empty or all-whitespace name
-		LLStringUtil::trim(from_name);
-		static const LLCachedControl<bool> sMarkUnnamedObjects(gSavedSettings, "AlchemyChatMarkUnnamedObjects", true);
-		if (sMarkUnnamedObjects && from_name.empty())
-		{
-			from_name = LLTrans::getString("Unnamed");
-		}
-		chat.mFromName = from_name;
-	}
-
-	BOOL is_do_not_disturb = gAgent.isDoNotDisturb();
-
-	BOOL is_muted = FALSE;
-	BOOL is_linden = FALSE;
-	is_muted = LLMuteList::getInstance()->isMuted(
-		from_id,
-		from_name,
-		LLMute::flagTextChat) 
-		|| LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagTextChat);
-	is_linden = chat.mSourceType != CHAT_SOURCE_OBJECT &&
-		LLMuteList::isLinden(from_name);
-
-	if (is_muted && (chat.mSourceType == CHAT_SOURCE_OBJECT))
-	{
-		return;
-	}
-
-	BOOL is_audible = (CHAT_AUDIBLE_FULLY == chat.mAudible);
-	chatter = gObjectList.findObject(from_id);
-	if (chatter)
-	{
-		chat.mPosAgent = chatter->getPositionAgent();
-
-		// Make swirly things only for talking objects. (not script debug messages, though)
-//		if (chat.mSourceType == CHAT_SOURCE_OBJECT 
-//			&& chat.mChatType != CHAT_TYPE_DEBUG_MSG
-//			&& gSavedSettings.getBOOL("EffectScriptChatParticles") )
-// [RLVa:KB] - Checked: 2010-03-09 (RLVa-1.2.0b) | Modified: RLVa-1.0.0g
-		if ( ((chat.mSourceType == CHAT_SOURCE_OBJECT) && (chat.mChatType != CHAT_TYPE_DEBUG_MSG)) && 
-			 (gSavedSettings.getBOOL("EffectScriptChatParticles")) &&
-			 ((!rlv_handler_t::isEnabled()) || (CHAT_TYPE_OWNER != chat.mChatType)) )
-// [/RLVa:KB]
-		{
-			LLPointer<LLViewerPartSourceChat> psc = new LLViewerPartSourceChat(chatter->getPositionAgent());
-			psc->setSourceObject(chatter);
-			psc->setColor(color);
-			//We set the particles to be owned by the object's owner, 
-			//just in case they should be muted by the mute list
-			psc->setOwnerUUID(owner_id);
-			LLViewerPartSim::getInstance()->addPartSource(psc);
-		}
-
-		// record last audible utterance
-		if (is_audible
-			&& (is_linden || (!is_muted && !is_do_not_disturb)))
-		{
-			if (chat.mChatType != CHAT_TYPE_START 
-				&& chat.mChatType != CHAT_TYPE_STOP)
-			{
-				gAgent.heardChat(chat.mFromID);
-			}
-		}
-	}
-
-	if (is_audible)
-	{
-		//BOOL visible_in_chat_bubble = FALSE;
-
-		color.setVec(1.f,1.f,1.f,1.f);
-		msg->getStringFast(_PREHASH_ChatData, _PREHASH_Message, mesg);
+            if (!is_muted && !is_do_not_disturb)
+            {
+                //visible_in_chat_bubble = gSavedSettings.getBOOL("UseChatBubbles");
+                std::string formated_msg = "";
+                LLViewerChat::formatChatMsg(chat, formated_msg);
+                LLChat chat_bubble = chat;
+                chat_bubble.mText = formated_msg;
+                ((LLVOAvatar*)chatter)->addChat(chat_bubble);
+            }
+        }
 
-// [RLVa:KB] - Checked: 2010-04-23 (RLVa-1.2.0f) | Modified: RLVa-1.2.0f
-		if ( (rlv_handler_t::isEnabled()) && (CHAT_TYPE_START != chat.mChatType) && (CHAT_TYPE_STOP != chat.mChatType) )
-		{
-			// NOTE: chatter can be NULL (may not have rezzed yet, or could be another avie's HUD attachment)
-			BOOL is_attachment = (chatter) ? chatter->isAttachment() : FALSE;
-			BOOL is_owned_by_me = (chatter) ? chatter->permYouOwner() : FALSE;
-
-			// Filtering "rules":
-			//   avatar  => filter all avie text (unless it's this avie or they're an exemption)
-			//   objects => filter everything except attachments this avie owns (never filter llOwnerSay or llRegionSayTo chat)
-			if ( ( (CHAT_SOURCE_AGENT == chat.mSourceType) && (from_id != gAgent.getID()) ) || 
-				 ( (CHAT_SOURCE_OBJECT == chat.mSourceType) && ((!is_owned_by_me) || (!is_attachment)) && 
-				   (CHAT_TYPE_OWNER != chat.mChatType) && (CHAT_TYPE_DIRECT != chat.mChatType) ) )
-			{
-				bool fIsEmote = RlvUtil::isEmote(mesg);
-				if ((!fIsEmote) &&
-					(((gRlvHandler.hasBehaviour(RLV_BHVR_RECVCHAT)) && (!gRlvHandler.isException(RLV_BHVR_RECVCHAT, from_id))) ||
-					 ((gRlvHandler.hasBehaviour(RLV_BHVR_RECVCHATFROM)) && (gRlvHandler.isException(RLV_BHVR_RECVCHATFROM, from_id))) ))
-				{
-					if ( (gRlvHandler.filterChat(mesg, false)) && (!gSavedSettings.get<bool>(RlvSettingNames::ShowEllipsis)) )
-						return;
-				}
-				else if ((fIsEmote) &&
-					     (((gRlvHandler.hasBehaviour(RLV_BHVR_RECVEMOTE)) && (!gRlvHandler.isException(RLV_BHVR_RECVEMOTE, from_id))) ||
-					      ((gRlvHandler.hasBehaviour(RLV_BHVR_RECVEMOTEFROM)) && (gRlvHandler.isException(RLV_BHVR_RECVEMOTEFROM, from_id))) ))
- 				{
-					if (!gSavedSettings.get<bool>(RlvSettingNames::ShowEllipsis))
-						return;
-					mesg = "/me ...";
-				}
-			}
-
-			// Filtering "rules":
-			//   avatar => filter only their name (unless it's this avie)
-			//   other  => filter everything
-			if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT))
-			{
-				if (CHAT_SOURCE_AGENT != chat.mSourceType)
-				{
-					RlvUtil::filterNames(chat.mFromName);
-				}
-				else if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, chat.mFromID))
-				{
-					chat.mFromName = RlvStrings::getAnonym(chat.mFromName);
-					chat.mRlvNamesFiltered = TRUE;
-				}
-			}
-
-			// Create an "objectim" URL for objects if we're either @shownames or @showloc restricted
-			// (we need to do this now because we won't be have enough information to do it later on)
-			if ( (CHAT_SOURCE_OBJECT == chat.mSourceType) &&
-			     ( (!RlvActions::canShowName(RlvActions::SNC_DEFAULT)) || (!RlvActions::canShowLocation()) ) )
-			{
-				LLSD sdQuery;
-				sdQuery["name"] = chat.mFromName;
-				sdQuery["owner"] = owner_id;
-
-				if ( (!RlvActions::canShowName(RlvActions::SNC_DEFAULT, owner_id)) && (!is_owned_by_me) )
-					sdQuery["rlv_shownames"] = true;
-
-				const LLViewerRegion* pRegion = LLWorld::getInstance()->getRegionFromPosAgent(chat.mPosAgent);
-				if (pRegion)
-					sdQuery["slurl"] = LLSLURL(pRegion->getName(), chat.mPosAgent).getLocationString();
-
-				chat.mURL = LLSLURL("objectim", from_id, LLURI::mapToQueryString(sdQuery)).getSLURLString();
-			}
-		}
-// [/RLVa:KB]
+        if (chatter)
+        {
+            chat.mPosAgent = chatter->getPositionAgent();
+        }
 
-		BOOL ircstyle = FALSE;
-
-		// Look for IRC-style emotes here so chatbubbles work
-		std::string prefix = mesg.substr(0, 4);
-		if (prefix == "/me " || prefix == "/me'")
-		{
-			ircstyle = TRUE;
-		}
-		chat.mText = mesg;
-
-		// Look for the start of typing so we can put "..." in the bubbles.
-		if (CHAT_TYPE_START == chat.mChatType)
-		{
-			LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, TRUE);
-
-			// Might not have the avatar constructed yet, eg on login.
-			if (chatter && chatter->isAvatar())
-			{
-				((LLVOAvatar*)chatter)->startTyping();
-			}
-			return;
-		}
-		else if (CHAT_TYPE_STOP == chat.mChatType)
-		{
-			LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE);
-
-			// Might not have the avatar constructed yet, eg on login.
-			if (chatter && chatter->isAvatar())
-			{
-				((LLVOAvatar*)chatter)->stopTyping();
-			}
-			return;
-		}
-
-		// Look for IRC-style emotes
-		if (ircstyle)
-		{
-			// set CHAT_STYLE_IRC to avoid adding Avatar Name as author of message. See EXT-656
-			chat.mChatStyle = CHAT_STYLE_IRC;
-
-			// Do nothing, ircstyle is fixed above for chat bubbles
-		}
-		else
-		{
-			chat.mText = "";
-			switch(chat.mChatType)
-			{
-			case CHAT_TYPE_WHISPER:
-				chat.mText = LLTrans::getString("whisper") + " ";
-				break;
-			case CHAT_TYPE_OWNER:
-// [RLVa:KB] - Checked: 2010-02-XX (RLVa-1.2.0a) | Modified: RLVa-1.1.0f
-				// TODO-RLVa: [RLVa-1.2.0] consider rewriting this before a RLVa-1.2.0 release
-				if ( (rlv_handler_t::isEnabled()) && (mesg.length() > 3) && (RLV_CMD_PREFIX == mesg[0]) && (CHAT_TYPE_OWNER == chat.mChatType) &&
-					 ((!chatter) || (!chatter->isAttachment()) || (!chatter->isTempAttachment()) || (RlvSettings::getEnableTemporaryAttachments())) )
-				{
-					mesg.erase(0, 1);
-					LLStringUtil::toLower(mesg);
-
-					std::string strExecuted, strFailed, strRetained, *pstr;
-
-					boost_tokenizer tokens(mesg, boost::char_separator<char>(",", "", boost::drop_empty_tokens));
-					for (boost_tokenizer::iterator itToken = tokens.begin(); itToken != tokens.end(); ++itToken)
-					{
-						std::string strCmd = *itToken;
-
-						ERlvCmdRet eRet = gRlvHandler.processCommand(from_id, strCmd, true);
-						if ( (RlvSettings::getDebug()) &&
-							 ( (!RlvSettings::getDebugHideUnsetDup()) || 
-							   ((RLV_RET_SUCCESS_UNSET != eRet) && (RLV_RET_SUCCESS_DUPLICATE != eRet)) ) )
-						{
-							if ( RLV_RET_SUCCESS == (eRet & RLV_RET_SUCCESS) )	
-								pstr = &strExecuted;
-							else if ( RLV_RET_FAILED == (eRet & RLV_RET_FAILED) )
-								pstr = &strFailed;
-							else if (RLV_RET_RETAINED == eRet)
-								pstr = &strRetained;
-							else
-							{
-								RLV_ASSERT(false);
-								pstr = &strFailed;
-							}
-
-							const char* pstrSuffix = RlvStrings::getStringFromReturnCode(eRet);
-							if (pstrSuffix)
-								strCmd.append(" (").append(pstrSuffix).append(")");
-
-							if (!pstr->empty())
-								pstr->push_back(',');
-							pstr->append(strCmd);
-						}
-					}
-
-					if (RlvForceWear::instanceExists())
-						RlvForceWear::instance().done();
-
-					if ( (!RlvSettings::getDebug()) || ((strExecuted.empty()) && (strFailed.empty()) && (strRetained.empty())) )
-						return;
-
-					// Silly people want comprehensive debug messages, blah :p
-					if ( (!strExecuted.empty()) && (strFailed.empty()) && (strRetained.empty()) )
-					{
-						chat.mText = " executes: @";
-						mesg = strExecuted;
-					}
-					else if ( (strExecuted.empty()) && (!strFailed.empty()) && (strRetained.empty()) )
-					{
-						chat.mText = " failed: @";
-						mesg = strFailed;
-					}
-					else if ( (strExecuted.empty()) && (strFailed.empty()) && (!strRetained.empty()) )
-					{
-						chat.mText = " retained: @";
-						mesg = strRetained;
-					}
-					else
-					{
-						chat.mText = ": @";
-						if (!strExecuted.empty())
-							mesg += "\n    - executed: @" + strExecuted;
-						if (!strFailed.empty())
-							mesg += "\n    - failed: @" + strFailed;
-						if (!strRetained.empty())
-							mesg += "\n    - retained: @" + strRetained;
-					}
-
-					break;
-				}
-// [/RLVa:KB]
-// [RLVa:KB] - Checked: 2010-03-09 (RLVa-1.2.0b) | Modified: RLVa-1.0.0g
-				// Copy/paste from above
-				if  ( (rlv_handler_t::isEnabled()) && (chatter) && (chat.mSourceType == CHAT_SOURCE_OBJECT) &&
-					  (gSavedSettings.getBOOL("EffectScriptChatParticles")) )
-				{
-					LLPointer<LLViewerPartSourceChat> psc = new LLViewerPartSourceChat(chatter->getPositionAgent());
-					psc->setSourceObject(chatter);
-					psc->setColor(color);
-					//We set the particles to be owned by the object's owner, 
-					//just in case they should be muted by the mute list
-					psc->setOwnerUUID(owner_id);
-					LLViewerPartSim::getInstance()->addPartSource(psc);
-				}
-// [/RLVa:KB]
-			case CHAT_TYPE_DEBUG_MSG:
-			case CHAT_TYPE_NORMAL:
-			case CHAT_TYPE_DIRECT:
-				break;
-			case CHAT_TYPE_SHOUT:
-				chat.mText = LLTrans::getString("shout") + " ";
-				break;
-			case CHAT_TYPE_START:
-			case CHAT_TYPE_STOP:
-				LL_WARNS("Messaging") << "Got chat type start/stop in main chat processing." << LL_ENDL;
-				break;
-			default:
-				LL_WARNS("Messaging") << "Unknown type " << chat.mChatType << " in chat!" << LL_ENDL;
-				break;
-			}
-
-			chat.mText += mesg;
-		}
-		
-		// We have a real utterance now, so can stop showing "..." and proceed.
-		if (chatter && chatter->isAvatar())
-		{
-			LLLocalSpeakerMgr::getInstance()->setSpeakerTyping(from_id, FALSE);
-			((LLVOAvatar*)chatter)->stopTyping();
-			
-			if (!is_muted && !is_do_not_disturb)
-			{
-				//visible_in_chat_bubble = gSavedSettings.getBOOL("UseChatBubbles");
-				std::string formated_msg = "";
-				LLViewerChat::formatChatMsg(chat, formated_msg);
-				LLChat chat_bubble = chat;
-				chat_bubble.mText = formated_msg;
-				((LLVOAvatar*)chatter)->addChat(chat_bubble);
-			}
-		}
-		
-		if (chatter)
-		{
-			chat.mPosAgent = chatter->getPositionAgent();
-		}
-
-		// truth table:
-		// LINDEN	BUSY	MUTED	OWNED_BY_YOU	TASK		DISPLAY		STORE IN HISTORY
-		// F		F		F		F				*			Yes			Yes
-		// F		F		F		T				*			Yes			Yes
-		// F		F		T		F				*			No			No
-		// F		F		T		T				*			No			No
-		// F		T		F		F				*			No			Yes
-		// F		T		F		T				*			Yes			Yes
-		// F		T		T		F				*			No			No
-		// F		T		T		T				*			No			No
-		// T		*		*		*				F			Yes			Yes
-
-		chat.mMuted = is_muted && !is_linden;
-
-		// pass owner_id to chat so that we can display the remote
-		// object inspect for an object that is chatting with you
-		LLSD args;
-		chat.mOwnerID = owner_id;
-
-		LLTranslate::instance().logCharsSeen(mesg.size());
-		if (gSavedSettings.getBOOL("TranslateChat") && chat.mSourceType != CHAT_SOURCE_SYSTEM)
-		{
-			if (chat.mChatStyle == CHAT_STYLE_IRC)
-			{
-				mesg = mesg.substr(4, std::string::npos);
-			}
-			const std::string from_lang = ""; // leave empty to trigger autodetect
-			const std::string to_lang = LLTranslate::getTranslateLanguage();
-
-			LLTranslate::instance().logCharsSent(mesg.size());
+        // truth table:
+        // LINDEN   BUSY    MUTED   OWNED_BY_YOU    TASK        DISPLAY     STORE IN HISTORY
+        // F        F       F       F               *           Yes         Yes
+        // F        F       F       T               *           Yes         Yes
+        // F        F       T       F               *           No          No
+        // F        F       T       T               *           No          No
+        // F        T       F       F               *           No          Yes
+        // F        T       F       T               *           Yes         Yes
+        // F        T       T       F               *           No          No
+        // F        T       T       T               *           No          No
+        // T        *       *       *               F           Yes         Yes
+
+        chat.mMuted = is_muted && !is_linden;
+
+        // pass owner_id to chat so that we can display the remote
+        // object inspect for an object that is chatting with you
+        LLSD args;
+        chat.mOwnerID = owner_id;
+
+        LLTranslate::instance().logCharsSeen(mesg.size());
+        if (gSavedSettings.getBOOL("TranslateChat") && chat.mSourceType != CHAT_SOURCE_SYSTEM)
+        {
+            if (chat.mChatStyle == CHAT_STYLE_IRC)
+            {
+                mesg = mesg.substr(4, std::string::npos);
+            }
+            const std::string from_lang = ""; // leave empty to trigger autodetect
+            const std::string to_lang = LLTranslate::getTranslateLanguage();
+
+            LLTranslate::instance().logCharsSent(mesg.size());
             LLTranslate::translateMessage(from_lang, to_lang, mesg,
                 boost::bind(&translateSuccess, chat, args, mesg, from_lang, _1, _2),
                 boost::bind(&translateFailure, chat, args, _1, _2));
 
-		}
-		else
-		{
-			LLNotificationsUI::LLNotificationManager::instance().onChat(chat, args);
-		}
+        }
+        else
+        {
+            LLNotificationsUI::LLNotificationManager::instance().onChat(chat, args);
+        }
 
-		// don't call notification for debug messages from not owned objects
-		if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
-		{
-			if (gAgentID != chat.mOwnerID)
-			{
-				return;
-			}
-		}
+        // don't call notification for debug messages from not owned objects
+        if (chat.mChatType == CHAT_TYPE_DEBUG_MSG)
+        {
+            if (gAgentID != chat.mOwnerID)
+            {
+                return;
+            }
+        }
 
-		if (mesg != "")
-		{
-			LLSD msg_notify = LLSD(LLSD::emptyMap());
-			msg_notify["session_id"] = LLUUID();
-			msg_notify["from_id"] = chat.mFromID;
-			msg_notify["source_type"] = chat.mSourceType;
-			on_new_message(msg_notify);
-		}
+        if (mesg != "")
+        {
+            LLSD msg_notify = LLSD(LLSD::emptyMap());
+            msg_notify["session_id"] = LLUUID();
+            msg_notify["from_id"] = chat.mFromID;
+            msg_notify["source_type"] = chat.mSourceType;
+            on_new_message(msg_notify);
+        }
 
-	}
+    }
 }
 
 
 // Simulator we're on is informing the viewer that the agent
-// is starting to teleport (perhaps to another sim, perhaps to the 
-// same sim). If we initiated the teleport process by sending some kind 
-// of TeleportRequest, then this info is redundant, but if the sim 
-// initiated the teleport (via a script call, being killed, etc.) 
+// is starting to teleport (perhaps to another sim, perhaps to the
+// same sim). If we initiated the teleport process by sending some kind
+// of TeleportRequest, then this info is redundant, but if the sim
+// initiated the teleport (via a script call, being killed, etc.)
 // then this info is news to us.
 void process_teleport_start(LLMessageSystem *msg, void**)
 {
-	// on teleport, don't tell them about destination guide anymore
-	LLFirstUse::notUsingDestinationGuide(false);
-	U32 teleport_flags = 0x0;
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
+    // on teleport, don't tell them about destination guide anymore
+    LLFirstUse::notUsingDestinationGuide(false);
+    U32 teleport_flags = 0x0;
+    msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
 
-	if (gAgent.getTeleportState() == LLAgent::TELEPORT_MOVING)
-	{
-		// Race condition?
-		LL_WARNS("Messaging") << "Got TeleportStart, but teleport already in progress. TeleportFlags=" << teleport_flags << LL_ENDL;
-	}
+    if (gAgent.getTeleportState() == LLAgent::TELEPORT_MOVING)
+    {
+        // Race condition?
+        LL_WARNS("Messaging") << "Got TeleportStart, but teleport already in progress. TeleportFlags=" << teleport_flags << LL_ENDL;
+    }
 
-	LL_DEBUGS("Messaging") << "Got TeleportStart with TeleportFlags=" << teleport_flags << ". gTeleportDisplay: " << gTeleportDisplay << ", gAgent.mTeleportState: " << gAgent.getTeleportState() << LL_ENDL;
+    LL_DEBUGS("Messaging") << "Got TeleportStart with TeleportFlags=" << teleport_flags << ". gTeleportDisplay: " << gTeleportDisplay << ", gAgent.mTeleportState: " << gAgent.getTeleportState() << LL_ENDL;
 
-	// *NOTE: The server sends two StartTeleport packets when you are teleporting to a LM
-	LLViewerMessage::getInstance()->mTeleportStartedSignal();
+    // *NOTE: The server sends two StartTeleport packets when you are teleporting to a LM
+    LLViewerMessage::getInstance()->mTeleportStartedSignal();
 
-//	if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL)
+//  if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL)
 // [RLVa:KB] - Checked: 2010-04-07 (RLVa-1.2.0d) | Added: RLVa-0.2.0b
-	if ( (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL) || (!gRlvHandler.getCanCancelTp()) )
+    if ( (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL) || (!gRlvHandler.getCanCancelTp()) )
 // [/RLVa:KB]
-	{
-		gViewerWindow->setProgressCancelButtonVisible(FALSE);
-	}
-	else
-	{
-		gViewerWindow->setProgressCancelButtonVisible(TRUE, LLTrans::getString("Cancel"));
-	}
-
-	// Freeze the UI and show progress bar
-	// Note: could add data here to differentiate between normal teleport and death.
-
-	if( gAgent.getTeleportState() == LLAgent::TELEPORT_NONE )
-	{
-		gTeleportDisplay = TRUE;
-		gAgent.setTeleportState( LLAgent::TELEPORT_START );
-		make_ui_sound("UISndTeleportOut");
-		
-		LL_INFOS("Messaging") << "Teleport initiated by remote TeleportStart message with TeleportFlags: " <<  teleport_flags << LL_ENDL;
-
-		// Don't call LLFirstUse::useTeleport here because this could be
-		// due to being killed, which would send you home, not to a Telehub
-	}
+    {
+        gViewerWindow->setProgressCancelButtonVisible(FALSE);
+    }
+    else
+    {
+        gViewerWindow->setProgressCancelButtonVisible(TRUE, LLTrans::getString("Cancel"));
+    }
+
+    // Freeze the UI and show progress bar
+    // Note: could add data here to differentiate between normal teleport and death.
+
+    if( gAgent.getTeleportState() == LLAgent::TELEPORT_NONE )
+    {
+        gTeleportDisplay = TRUE;
+        gAgent.setTeleportState( LLAgent::TELEPORT_START );
+        make_ui_sound("UISndTeleportOut");
+
+        LL_INFOS("Messaging") << "Teleport initiated by remote TeleportStart message with TeleportFlags: " <<  teleport_flags << LL_ENDL;
+
+        // Don't call LLFirstUse::useTeleport here because this could be
+        // due to being killed, which would send you home, not to a Telehub
+    }
 }
 
 boost::signals2::connection LLViewerMessage::setTeleportStartedCallback(teleport_started_callback_t cb)
 {
-	return mTeleportStartedSignal.connect(cb);
+    return mTeleportStartedSignal.connect(cb);
 }
 
 void process_teleport_progress(LLMessageSystem* msg, void**)
 {
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	if((gAgent.getID() != agent_id)
-	   || (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE))
-	{
-		LL_WARNS("Messaging") << "Unexpected teleport progress message." << LL_ENDL;
-		return;
-	}
-	U32 teleport_flags = 0x0;
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
-//	if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL)
+    LLUUID agent_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+    if((gAgent.getID() != agent_id)
+       || (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE))
+    {
+        LL_WARNS("Messaging") << "Unexpected teleport progress message." << LL_ENDL;
+        return;
+    }
+    U32 teleport_flags = 0x0;
+    msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
+//  if (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL)
 // [RLVa:KB] - Checked: 2010-04-07 (RLVa-1.2.0d) | Added: RLVa-0.2.0b
-	if ( (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL) || (!gRlvHandler.getCanCancelTp()) )
+    if ( (teleport_flags & TELEPORT_FLAGS_DISABLE_CANCEL) || (!gRlvHandler.getCanCancelTp()) )
 // [/RLVa:KB]
-	{
-		gViewerWindow->setProgressCancelButtonVisible(FALSE);
-	}
-	else
-	{
-		gViewerWindow->setProgressCancelButtonVisible(TRUE, LLTrans::getString("Cancel"));
-	}
-	std::string buffer;
-	msg->getStringFast(_PREHASH_Info, _PREHASH_Message, buffer);
-	LL_DEBUGS("Messaging") << "teleport progress: " << buffer << " flags: " << teleport_flags << LL_ENDL;
-
-	//Sorta hacky...default to using simulator raw messages
-	//if we don't find the coresponding mapping in our progress mappings
-	std::string message = buffer;
-
-	if (LLAgent::sTeleportProgressMessages.find(buffer) != 
-		LLAgent::sTeleportProgressMessages.end() )
-	{
-		message = LLAgent::sTeleportProgressMessages[buffer];
-	}
-
-	gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages[message]);
+    {
+        gViewerWindow->setProgressCancelButtonVisible(FALSE);
+    }
+    else
+    {
+        gViewerWindow->setProgressCancelButtonVisible(TRUE, LLTrans::getString("Cancel"));
+    }
+    std::string buffer;
+    msg->getStringFast(_PREHASH_Info, _PREHASH_Message, buffer);
+    LL_DEBUGS("Messaging") << "teleport progress: " << buffer << " flags: " << teleport_flags << LL_ENDL;
+
+    //Sorta hacky...default to using simulator raw messages
+    //if we don't find the coresponding mapping in our progress mappings
+    std::string message = buffer;
+
+    if (LLAgent::sTeleportProgressMessages.find(buffer) !=
+        LLAgent::sTeleportProgressMessages.end() )
+    {
+        message = LLAgent::sTeleportProgressMessages[buffer];
+    }
+
+    gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages[message]);
 }
 
 class LLFetchInWelcomeArea : public LLInventoryFetchDescendentsObserver
 {
 public:
-	LLFetchInWelcomeArea(const uuid_vec_t &ids) :
-		LLInventoryFetchDescendentsObserver(ids)
-	{}
-	virtual void done()
-	{
-		LLIsType is_landmark(LLAssetType::AT_LANDMARK);
-		LLIsType is_card(LLAssetType::AT_CALLINGCARD);
-
-		LLInventoryModel::cat_array_t	card_cats;
-		LLInventoryModel::item_array_t	card_items;
-		LLInventoryModel::cat_array_t	land_cats;
-		LLInventoryModel::item_array_t	land_items;
-
-		uuid_vec_t::iterator it = mComplete.begin();
-		uuid_vec_t::iterator end = mComplete.end();
-		for(; it != end; ++it)
-		{
-			gInventory.collectDescendentsIf(
-				(*it),
-				land_cats,
-				land_items,
-				LLInventoryModel::EXCLUDE_TRASH,
-				is_landmark);
-			gInventory.collectDescendentsIf(
-				(*it),
-				card_cats,
-				card_items,
-				LLInventoryModel::EXCLUDE_TRASH,
-				is_card);
-		}
-
-		gInventory.removeObserver(this);
-		delete this;
-	}
+    LLFetchInWelcomeArea(const uuid_vec_t &ids) :
+        LLInventoryFetchDescendentsObserver(ids)
+    {}
+    virtual void done()
+    {
+        LLIsType is_landmark(LLAssetType::AT_LANDMARK);
+        LLIsType is_card(LLAssetType::AT_CALLINGCARD);
+
+        LLInventoryModel::cat_array_t   card_cats;
+        LLInventoryModel::item_array_t  card_items;
+        LLInventoryModel::cat_array_t   land_cats;
+        LLInventoryModel::item_array_t  land_items;
+
+        uuid_vec_t::iterator it = mComplete.begin();
+        uuid_vec_t::iterator end = mComplete.end();
+        for(; it != end; ++it)
+        {
+            gInventory.collectDescendentsIf(
+                (*it),
+                land_cats,
+                land_items,
+                LLInventoryModel::EXCLUDE_TRASH,
+                is_landmark);
+            gInventory.collectDescendentsIf(
+                (*it),
+                card_cats,
+                card_items,
+                LLInventoryModel::EXCLUDE_TRASH,
+                is_card);
+        }
+
+        gInventory.removeObserver(this);
+        delete this;
+    }
 };
 
 
 
-class LLPostTeleportNotifiers : public LLEventTimer 
+class LLPostTeleportNotifiers : public LLEventTimer
 {
 public:
-	LLPostTeleportNotifiers();
-	virtual ~LLPostTeleportNotifiers();
+    LLPostTeleportNotifiers();
+    virtual ~LLPostTeleportNotifiers();
 
-	//function to be called at the supplied frequency
-	virtual BOOL tick();
+    //function to be called at the supplied frequency
+    virtual BOOL tick();
 };
 
 LLPostTeleportNotifiers::LLPostTeleportNotifiers() : LLEventTimer( 2.0 )
@@ -3229,34 +3229,34 @@ LLPostTeleportNotifiers::~LLPostTeleportNotifiers()
 
 BOOL LLPostTeleportNotifiers::tick()
 {
-	BOOL all_done = FALSE;
-	if ( gAgent.getTeleportState() == LLAgent::TELEPORT_NONE )
-	{
-		// get callingcards and landmarks available to the user arriving.
-		uuid_vec_t folders;
-		const LLUUID callingcard_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_CALLINGCARD);
-		if(callingcard_id.notNull()) 
-			folders.push_back(callingcard_id);
-		const LLUUID folder_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK);
-		if(folder_id.notNull()) 
-			folders.push_back(folder_id);
-		if(!folders.empty())
-		{
-			LLFetchInWelcomeArea* fetcher = new LLFetchInWelcomeArea(folders);
-			fetcher->startFetch();
-			if(fetcher->isFinished())
-			{
-				fetcher->done();
-			}
-			else
-			{
-				gInventory.addObserver(fetcher);
-			}
-		}
-		all_done = TRUE;
-	}
-
-	return all_done;
+    BOOL all_done = FALSE;
+    if ( gAgent.getTeleportState() == LLAgent::TELEPORT_NONE )
+    {
+        // get callingcards and landmarks available to the user arriving.
+        uuid_vec_t folders;
+        const LLUUID callingcard_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_CALLINGCARD);
+        if(callingcard_id.notNull())
+            folders.push_back(callingcard_id);
+        const LLUUID folder_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK);
+        if(folder_id.notNull())
+            folders.push_back(folder_id);
+        if(!folders.empty())
+        {
+            LLFetchInWelcomeArea* fetcher = new LLFetchInWelcomeArea(folders);
+            fetcher->startFetch();
+            if(fetcher->isFinished())
+            {
+                fetcher->done();
+            }
+            else
+            {
+                gInventory.addObserver(fetcher);
+            }
+        }
+        all_done = TRUE;
+    }
+
+    return all_done;
 }
 
 
@@ -3265,14 +3265,14 @@ BOOL LLPostTeleportNotifiers::tick()
 // We're going to pretend to be a new agent
 void process_teleport_finish(LLMessageSystem* msg, void**)
 {
-	LL_DEBUGS("Teleport","Messaging") << "Received TeleportFinish message" << LL_ENDL;
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
-	if (agent_id != gAgent.getID())
-	{
-		LL_WARNS("Teleport","Messaging") << "Got teleport notification for wrong agent " << agent_id << " expected " << gAgent.getID() << ", ignoring!" << LL_ENDL;
-		return;
-	}
+    LL_DEBUGS("Teleport","Messaging") << "Received TeleportFinish message" << LL_ENDL;
+    LLUUID agent_id;
+    msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
+    if (agent_id != gAgent.getID())
+    {
+        LL_WARNS("Teleport","Messaging") << "Got teleport notification for wrong agent " << agent_id << " expected " << gAgent.getID() << ", ignoring!" << LL_ENDL;
+        return;
+    }
 
     if (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE)
     {
@@ -3280,7 +3280,7 @@ void process_teleport_finish(LLMessageSystem* msg, void**)
         {
             // Server either ignored teleport cancel message or did not receive it in time.
             // This message can't be ignored since teleport is complete at server side
-			LL_INFOS("Teleport") << "Restoring canceled teleport request" << LL_ENDL;
+            LL_INFOS("Teleport") << "Restoring canceled teleport request" << LL_ENDL;
             gAgent.restoreCanceledTeleportRequest();
         }
         else
@@ -3297,644 +3297,644 @@ void process_teleport_finish(LLMessageSystem* msg, void**)
     {
         LL_WARNS("Teleport","Messaging") << "Teleport message in the middle of other teleport" << LL_ENDL;
     }
-	
-	// Teleport is finished; it can't be cancelled now.
-	gViewerWindow->setProgressCancelButtonVisible(FALSE);
-
-	// Do teleport effect for where you're leaving
-	// VEFFECT: TeleportStart
-	if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral"))
-	{
-		LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
-		effectp->setPositionGlobal(gAgent.getPositionGlobal());
-		effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-		LLHUDManager::getInstance()->sendEffects();
-	}
-
-	U32 location_id;
-	U32 sim_ip;
-	U16 sim_port;
-	LLVector3 pos, look_at;
-	U64 region_handle;
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
-	msg->getIPAddrFast(_PREHASH_Info, _PREHASH_SimIP, sim_ip);
-	msg->getIPPortFast(_PREHASH_Info, _PREHASH_SimPort, sim_port);
-	//msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
-	//msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
-	msg->getU64Fast(_PREHASH_Info, _PREHASH_RegionHandle, region_handle);
-	U32 teleport_flags;
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
-
-	std::string seedCap;
-	msg->getStringFast(_PREHASH_Info, _PREHASH_SeedCapability, seedCap);
-
-	LL_DEBUGS("Teleport") << "TeleportFinish message params are:"
-						  << " sim_ip " << sim_ip
-						  << " sim_port " << sim_port
-						  << " region_handle " << region_handle
-						  << " teleport_flags " << teleport_flags
-						  << " seedCap " << seedCap
-						  << LL_ENDL;
-	
-	// update home location if we are teleporting out of prelude - specific to teleporting to welcome area 
-	if((teleport_flags & TELEPORT_FLAGS_SET_HOME_TO_TARGET)
-	   && (!gAgent.isGodlike()))
-	{
-		gAgent.setHomePosRegion(region_handle, pos);
-
-		// Create a timer that will send notices when teleporting is all finished.  Since this is 
-		// based on the LLEventTimer class, it will be managed by that class and not orphaned or leaked.
-		new LLPostTeleportNotifiers();
-	}
-
-	LLHost sim_host(sim_ip, sim_port);
-
-	// Viewer trusts the simulator.
-	gMessageSystem->enableCircuit(sim_host, TRUE);
-	if (LLGridManager::getInstance()->isInOpenSim())
-	{
-		U32 region_size_x = 256;
-		msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeX, region_size_x);
-		U32 region_size_y = 256;
-		msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeY, region_size_y);
-		LLWorld::getInstance()->setRegionSize(region_size_x, region_size_y);
-	}
-	LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host);
+
+    // Teleport is finished; it can't be cancelled now.
+    gViewerWindow->setProgressCancelButtonVisible(FALSE);
+
+    // Do teleport effect for where you're leaving
+    // VEFFECT: TeleportStart
+    if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral"))
+    {
+        LLHUDEffectSpiral* effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
+        effectp->setPositionGlobal(gAgent.getPositionGlobal());
+        effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+        LLHUDManager::getInstance()->sendEffects();
+    }
+
+    U32 location_id;
+    U32 sim_ip;
+    U16 sim_port;
+    LLVector3 pos, look_at;
+    U64 region_handle;
+    msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
+    msg->getIPAddrFast(_PREHASH_Info, _PREHASH_SimIP, sim_ip);
+    msg->getIPPortFast(_PREHASH_Info, _PREHASH_SimPort, sim_port);
+    //msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
+    //msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
+    msg->getU64Fast(_PREHASH_Info, _PREHASH_RegionHandle, region_handle);
+    U32 teleport_flags;
+    msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
+
+    std::string seedCap;
+    msg->getStringFast(_PREHASH_Info, _PREHASH_SeedCapability, seedCap);
+
+    LL_DEBUGS("Teleport") << "TeleportFinish message params are:"
+                          << " sim_ip " << sim_ip
+                          << " sim_port " << sim_port
+                          << " region_handle " << region_handle
+                          << " teleport_flags " << teleport_flags
+                          << " seedCap " << seedCap
+                          << LL_ENDL;
+
+    // update home location if we are teleporting out of prelude - specific to teleporting to welcome area
+    if((teleport_flags & TELEPORT_FLAGS_SET_HOME_TO_TARGET)
+       && (!gAgent.isGodlike()))
+    {
+        gAgent.setHomePosRegion(region_handle, pos);
+
+        // Create a timer that will send notices when teleporting is all finished.  Since this is
+        // based on the LLEventTimer class, it will be managed by that class and not orphaned or leaked.
+        new LLPostTeleportNotifiers();
+    }
+
+    LLHost sim_host(sim_ip, sim_port);
+
+    // Viewer trusts the simulator.
+    gMessageSystem->enableCircuit(sim_host, TRUE);
+    if (LLGridManager::getInstance()->isInOpenSim())
+    {
+        U32 region_size_x = 256;
+        msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeX, region_size_x);
+        U32 region_size_y = 256;
+        msg->getU32Fast(_PREHASH_Info, _PREHASH_RegionSizeY, region_size_y);
+        LLWorld::getInstance()->setRegionSize(region_size_x, region_size_y);
+    }
+    LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host);
 
 /*
-	// send camera update to new region
-	gAgentCamera.updateCamera();
-
-	// likewise make sure the camera is behind the avatar
-	gAgentCamera.resetView(TRUE);
-	LLVector3 shift_vector = regionp->getPosRegionFromGlobal(gAgent.getRegion()->getOriginGlobal());
-	gAgent.setRegion(regionp);
-	gObjectList.shiftObjects(shift_vector);
-
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->clearChatText();
-		gAgentCamera.slamLookAt(look_at);
-	}
-	gAgent.setPositionAgent(pos);
-	gAssetStorage->setUpstream(sim);
-	gCacheName->setUpstream(sim);
+    // send camera update to new region
+    gAgentCamera.updateCamera();
+
+    // likewise make sure the camera is behind the avatar
+    gAgentCamera.resetView(TRUE);
+    LLVector3 shift_vector = regionp->getPosRegionFromGlobal(gAgent.getRegion()->getOriginGlobal());
+    gAgent.setRegion(regionp);
+    gObjectList.shiftObjects(shift_vector);
+
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->clearChatText();
+        gAgentCamera.slamLookAt(look_at);
+    }
+    gAgent.setPositionAgent(pos);
+    gAssetStorage->setUpstream(sim);
+    gCacheName->setUpstream(sim);
 */
 
-	// Make sure we're standing
-	gAgent.standUp();
+    // Make sure we're standing
+    gAgent.standUp();
 
-	// now, use the circuit info to tell simulator about us!
-	LL_INFOS("Teleport","Messaging") << "process_teleport_finish() sending UseCircuitCode to enable sim_host "
-			<< sim_host << " with code " << msg->mOurCircuitCode << LL_ENDL;
-	msg->newMessageFast(_PREHASH_UseCircuitCode);
-	msg->nextBlockFast(_PREHASH_CircuitCode);
-	msg->addU32Fast(_PREHASH_Code, msg->getOurCircuitCode());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_ID, gAgent.getID());
-	msg->sendReliable(sim_host);
+    // now, use the circuit info to tell simulator about us!
+    LL_INFOS("Teleport","Messaging") << "process_teleport_finish() sending UseCircuitCode to enable sim_host "
+            << sim_host << " with code " << msg->mOurCircuitCode << LL_ENDL;
+    msg->newMessageFast(_PREHASH_UseCircuitCode);
+    msg->nextBlockFast(_PREHASH_CircuitCode);
+    msg->addU32Fast(_PREHASH_Code, msg->getOurCircuitCode());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addUUIDFast(_PREHASH_ID, gAgent.getID());
+    msg->sendReliable(sim_host);
 
-	LL_INFOS("Teleport") << "Calling send_complete_agent_movement() and setting state to TELEPORT_MOVING" << LL_ENDL;
-	send_complete_agent_movement(sim_host);
-	gAgent.setTeleportState( LLAgent::TELEPORT_MOVING );
-	gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages["contacting"]);
+    LL_INFOS("Teleport") << "Calling send_complete_agent_movement() and setting state to TELEPORT_MOVING" << LL_ENDL;
+    send_complete_agent_movement(sim_host);
+    gAgent.setTeleportState( LLAgent::TELEPORT_MOVING );
+    gAgent.setTeleportMessage(LLAgent::sTeleportProgressMessages["contacting"]);
 
-	LL_DEBUGS("CrossingCaps") << "Calling setSeedCapability(). Seed cap == "
-			<< seedCap << LL_ENDL;
-	regionp->setSeedCapability(seedCap);
+    LL_DEBUGS("CrossingCaps") << "Calling setSeedCapability(). Seed cap == "
+            << seedCap << LL_ENDL;
+    regionp->setSeedCapability(seedCap);
 
-	// Don't send camera updates to the new region until we're
-	// actually there...
+    // Don't send camera updates to the new region until we're
+    // actually there...
 
 
-	// Now do teleport effect for where you're going.
-	// VEFFECT: TeleportEnd
-	if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral"))
-	{
-		auto effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
-		effectp->setPositionGlobal(gAgent.getPositionGlobal());
+    // Now do teleport effect for where you're going.
+    // VEFFECT: TeleportEnd
+    if (!gSavedSettings.getBOOL("AlchemyDisableEffectSpiral"))
+    {
+        auto effectp = (LLHUDEffectSpiral*)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_POINT, TRUE);
+        effectp->setPositionGlobal(gAgent.getPositionGlobal());
 
-		effectp->setColor(LLColor4U(gAgent.getEffectColor()));
-		LLHUDManager::getInstance()->sendEffects();
-	}
+        effectp->setColor(LLColor4U(gAgent.getEffectColor()));
+        LLHUDManager::getInstance()->sendEffects();
+    }
 
-//	gTeleportDisplay = TRUE;
-//	gTeleportDisplayTimer.reset();
-//	gViewerWindow->setShowProgress(TRUE);
+//  gTeleportDisplay = TRUE;
+//  gTeleportDisplayTimer.reset();
+//  gViewerWindow->setShowProgress(TRUE);
 }
 
 // stuff we have to do every time we get an AvatarInitComplete from a sim
 /*
 void process_avatar_init_complete(LLMessageSystem* msg, void**)
 {
-	LLVector3 agent_pos;
-	msg->getVector3Fast(_PREHASH_AvatarData, _PREHASH_Position, agent_pos);
-	agent_movement_complete(msg->getSender(), agent_pos);
+    LLVector3 agent_pos;
+    msg->getVector3Fast(_PREHASH_AvatarData, _PREHASH_Position, agent_pos);
+    agent_movement_complete(msg->getSender(), agent_pos);
 }
 */
 
 void process_agent_movement_complete(LLMessageSystem* msg, void**)
 {
-	LL_INFOS("Teleport","Messaging") << "Received ProcessAgentMovementComplete" << LL_ENDL;
-
-	gShiftFrame = true;
-	gAgentMovementCompleted = true;
-
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	LLUUID session_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
-	if((gAgent.getID() != agent_id) || (gAgent.getSessionID() != session_id))
-	{
-		LL_WARNS("Teleport", "Messaging") << "Incorrect agent or session id in process_agent_movement_complete()"
-										  << " agent " << agent_id << " expected " << gAgent.getID() 
-										  << " session " << session_id << " expected " << gAgent.getSessionID()
-										  << ", ignoring" << LL_ENDL;
-		return;
-	}
-
-	// *TODO: check timestamp to make sure the movement compleation
-	// makes sense.
-	LLVector3 agent_pos;
-	msg->getVector3Fast(_PREHASH_Data, _PREHASH_Position, agent_pos);
-	LLVector3 look_at;
-	msg->getVector3Fast(_PREHASH_Data, _PREHASH_LookAt, look_at);
-	U64 region_handle;
-	msg->getU64Fast(_PREHASH_Data, _PREHASH_RegionHandle, region_handle);
-	
-	std::string version_channel;
-	msg->getStringFast(_PREHASH_SimData, _PREHASH_ChannelVersion, version_channel);
-
-	if (!isAgentAvatarValid())
-	{
-		// Could happen if you were immediately god-teleported away on login,
-		// maybe other cases.  Continue, but warn.
-		LL_WARNS("Teleport", "Messaging") << "agent_movement_complete() with NULL avatarp." << LL_ENDL;
-	}
-
-	F32 x, y;
-	from_region_handle(region_handle, &x, &y);
-	LLViewerRegion* regionp = LLWorld::getInstance()->getRegionFromHandle(region_handle);
-	if (!regionp)
-	{
-		if (gAgent.getRegion())
-		{
-			LL_WARNS("Teleport", "Messaging") << "current region origin "
-											  << gAgent.getRegion()->getOriginGlobal() << " id " << gAgent.getRegion()->getRegionID() << LL_ENDL;
-		}
-
-		LL_WARNS("Teleport", "Messaging") << "Agent being sent to invalid home region: " 
-										  << x << ":" << y 
-										  << " current pos " << gAgent.getPositionGlobal()
-										  << ", calling forceDisconnect()"
-										  << LL_ENDL;
-		LLAppViewer::instance()->forceDisconnect(LLTrans::getString("SentToInvalidRegion"));
-		return;
-
-	}
-
-	LL_INFOS("Teleport","Messaging") << "Changing home region to region id " << regionp->getRegionID() << " handle " << region_handle << " == x,y " << x << "," << y << LL_ENDL;
-
-	// set our upstream host the new simulator and shuffle things as
-	// appropriate.
-	LLVector3 shift_vector = regionp->getPosRegionFromGlobal(
-		gAgent.getRegion()->getOriginGlobal());
-	gAgent.setRegion(regionp);
-	gObjectList.shiftObjects(shift_vector);
-
-	// Is this a really long jump?
-	if (shift_vector.length() > 2048.f * 256.f)
-	{
-		regionp->reInitPartitions();
-		gAgent.setRegion(regionp);
-		// Kill objects in the regions we left behind
-		for (LLViewerRegion* r : LLWorld::getInstance()->getRegionList())
-		{
-			if (r != regionp)
-			{
-				gObjectList.killObjects(r);
-			}
-		}
-	}
-
-	gAssetStorage->setUpstream(msg->getSender());
-	gCacheName->setUpstream(msg->getSender());
-	gViewerThrottle.sendToSim();
-	gViewerWindow->sendShapeToSim();
-
-	bool is_teleport = gAgent.getTeleportState() == LLAgent::TELEPORT_MOVING;
-
-	if( is_teleport )
-	{
-		if (gAgent.getTeleportKeepsLookAt())
-		{
-			// *NOTE: the LookAt data we get from the sim here doesn't
-			// seem to be useful, so get it from the camera instead
-			look_at = LLViewerCamera::getInstance()->getAtAxis();
-		}
-		// Force the camera back onto the agent, don't animate.
-		gAgentCamera.setFocusOnAvatar(TRUE, FALSE);
-		gAgentCamera.slamLookAt(look_at);
-		gAgentCamera.updateCamera();
-
-		LL_INFOS("Teleport") << "Agent movement complete, setting state to TELEPORT_START_ARRIVAL" << LL_ENDL;
-		gAgent.setTeleportState( LLAgent::TELEPORT_START_ARRIVAL );
-
-		if (isAgentAvatarValid())
-		{
-			// Set the new position
-			gAgentAvatarp->setPositionAgent(agent_pos);
-			gAgentAvatarp->clearChat();
-			gAgentAvatarp->slamPosition();
-		}
-	}
-	else
-	{
-		// This is initial log-in or a region crossing
-		LL_INFOS("Teleport") << "State is not TELEPORT_MOVING, so this is initial log-in or region crossing. "
-							 << "Setting state to TELEPORT_NONE" << LL_ENDL;
-		gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
-
-		if(LLStartUp::getStartupState() < STATE_STARTED)
-		{	// This is initial log-in, not a region crossing:
-			// Set the camera looking ahead of the AV so send_agent_update() below 
-			// will report the correct location to the server.
-			LLVector3 look_at_point = look_at;
-			look_at_point = agent_pos + look_at_point.rotVec(gAgent.getQuat());
-
-			static LLVector3 up_direction(0.0f, 0.0f, 1.0f);
-			LLViewerCamera::getInstance()->lookAt(agent_pos, look_at_point, up_direction);
-		}
-	}
-
-	if ( LLTracker::isTracking(NULL) )
-	{
-		// Check distance to beacon, if < 5m, remove beacon
-		LLVector3d beacon_pos = LLTracker::getTrackedPositionGlobal();
-		LLVector3 beacon_dir(agent_pos.mV[VX] - (F32)fmod(beacon_pos.mdV[VX], 256.0), agent_pos.mV[VY] - (F32)fmod(beacon_pos.mdV[VY], 256.0), 0);
-		if (beacon_dir.magVecSquared() < 25.f)
-		{
-			LLTracker::stopTracking(false);
-		}
-		else if ( is_teleport && !gAgent.getTeleportKeepsLookAt() && look_at.isExactlyZero())
-		{
-			//look at the beacon
-			LLVector3 global_agent_pos = agent_pos;
-			global_agent_pos[0] += x;
-			global_agent_pos[1] += y;
-			look_at = (LLVector3)beacon_pos - global_agent_pos;
-			look_at.normVec();
-			gAgentCamera.slamLookAt(look_at);
-		}
-	}
-
-	// TODO: Put back a check for flying status! DK 12/19/05
-	// Sim tells us whether the new position is off the ground
-	/*
-	if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
-	{
-		gAgent.setFlying(TRUE);
-	}
-	else
-	{
-		gAgent.setFlying(FALSE);
-	}
-	*/
-
-	send_agent_update(TRUE, TRUE);
-
-	//if (gAgent.getRegion()->getBlockFly())
-	//{
-	//	gAgent.setFlying(gAgent.canFly());
-	//}
-
-	// force simulator to recognize do not disturb state
-	if (gAgent.isDoNotDisturb())
-	{
-		gAgent.setDoNotDisturb(true);
-	}
-	else
-	{
-		gAgent.setDoNotDisturb(false);
-	}
-
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->mFootPlane.clearVec();
-	}
-	
-	// send walk-vs-run status
-//	gAgent.sendWalkRun(gAgent.getRunning() || gAgent.getAlwaysRun());
+    LL_INFOS("Teleport","Messaging") << "Received ProcessAgentMovementComplete" << LL_ENDL;
+
+    gShiftFrame = true;
+    gAgentMovementCompleted = true;
+
+    LLUUID agent_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+    LLUUID session_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
+    if((gAgent.getID() != agent_id) || (gAgent.getSessionID() != session_id))
+    {
+        LL_WARNS("Teleport", "Messaging") << "Incorrect agent or session id in process_agent_movement_complete()"
+                                          << " agent " << agent_id << " expected " << gAgent.getID()
+                                          << " session " << session_id << " expected " << gAgent.getSessionID()
+                                          << ", ignoring" << LL_ENDL;
+        return;
+    }
+
+    // *TODO: check timestamp to make sure the movement compleation
+    // makes sense.
+    LLVector3 agent_pos;
+    msg->getVector3Fast(_PREHASH_Data, _PREHASH_Position, agent_pos);
+    LLVector3 look_at;
+    msg->getVector3Fast(_PREHASH_Data, _PREHASH_LookAt, look_at);
+    U64 region_handle;
+    msg->getU64Fast(_PREHASH_Data, _PREHASH_RegionHandle, region_handle);
+
+    std::string version_channel;
+    msg->getStringFast(_PREHASH_SimData, _PREHASH_ChannelVersion, version_channel);
+
+    if (!isAgentAvatarValid())
+    {
+        // Could happen if you were immediately god-teleported away on login,
+        // maybe other cases.  Continue, but warn.
+        LL_WARNS("Teleport", "Messaging") << "agent_movement_complete() with NULL avatarp." << LL_ENDL;
+    }
+
+    F32 x, y;
+    from_region_handle(region_handle, &x, &y);
+    LLViewerRegion* regionp = LLWorld::getInstance()->getRegionFromHandle(region_handle);
+    if (!regionp)
+    {
+        if (gAgent.getRegion())
+        {
+            LL_WARNS("Teleport", "Messaging") << "current region origin "
+                                              << gAgent.getRegion()->getOriginGlobal() << " id " << gAgent.getRegion()->getRegionID() << LL_ENDL;
+        }
+
+        LL_WARNS("Teleport", "Messaging") << "Agent being sent to invalid home region: "
+                                          << x << ":" << y
+                                          << " current pos " << gAgent.getPositionGlobal()
+                                          << ", calling forceDisconnect()"
+                                          << LL_ENDL;
+        LLAppViewer::instance()->forceDisconnect(LLTrans::getString("SentToInvalidRegion"));
+        return;
+
+    }
+
+    LL_INFOS("Teleport","Messaging") << "Changing home region to region id " << regionp->getRegionID() << " handle " << region_handle << " == x,y " << x << "," << y << LL_ENDL;
+
+    // set our upstream host the new simulator and shuffle things as
+    // appropriate.
+    LLVector3 shift_vector = regionp->getPosRegionFromGlobal(
+        gAgent.getRegion()->getOriginGlobal());
+    gAgent.setRegion(regionp);
+    gObjectList.shiftObjects(shift_vector);
+
+    // Is this a really long jump?
+    if (shift_vector.length() > 2048.f * 256.f)
+    {
+        regionp->reInitPartitions();
+        gAgent.setRegion(regionp);
+        // Kill objects in the regions we left behind
+        for (LLViewerRegion* r : LLWorld::getInstance()->getRegionList())
+        {
+            if (r != regionp)
+            {
+                gObjectList.killObjects(r);
+            }
+        }
+    }
+
+    gAssetStorage->setUpstream(msg->getSender());
+    gCacheName->setUpstream(msg->getSender());
+    gViewerThrottle.sendToSim();
+    gViewerWindow->sendShapeToSim();
+
+    bool is_teleport = gAgent.getTeleportState() == LLAgent::TELEPORT_MOVING;
+
+    if( is_teleport )
+    {
+        if (gAgent.getTeleportKeepsLookAt())
+        {
+            // *NOTE: the LookAt data we get from the sim here doesn't
+            // seem to be useful, so get it from the camera instead
+            look_at = LLViewerCamera::getInstance()->getAtAxis();
+        }
+        // Force the camera back onto the agent, don't animate.
+        gAgentCamera.setFocusOnAvatar(TRUE, FALSE);
+        gAgentCamera.slamLookAt(look_at);
+        gAgentCamera.updateCamera();
+
+        LL_INFOS("Teleport") << "Agent movement complete, setting state to TELEPORT_START_ARRIVAL" << LL_ENDL;
+        gAgent.setTeleportState( LLAgent::TELEPORT_START_ARRIVAL );
+
+        if (isAgentAvatarValid())
+        {
+            // Set the new position
+            gAgentAvatarp->setPositionAgent(agent_pos);
+            gAgentAvatarp->clearChat();
+            gAgentAvatarp->slamPosition();
+        }
+    }
+    else
+    {
+        // This is initial log-in or a region crossing
+        LL_INFOS("Teleport") << "State is not TELEPORT_MOVING, so this is initial log-in or region crossing. "
+                             << "Setting state to TELEPORT_NONE" << LL_ENDL;
+        gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
+
+        if(LLStartUp::getStartupState() < STATE_STARTED)
+        {   // This is initial log-in, not a region crossing:
+            // Set the camera looking ahead of the AV so send_agent_update() below
+            // will report the correct location to the server.
+            LLVector3 look_at_point = look_at;
+            look_at_point = agent_pos + look_at_point.rotVec(gAgent.getQuat());
+
+            static LLVector3 up_direction(0.0f, 0.0f, 1.0f);
+            LLViewerCamera::getInstance()->lookAt(agent_pos, look_at_point, up_direction);
+        }
+    }
+
+    if ( LLTracker::isTracking(NULL) )
+    {
+        // Check distance to beacon, if < 5m, remove beacon
+        LLVector3d beacon_pos = LLTracker::getTrackedPositionGlobal();
+        LLVector3 beacon_dir(agent_pos.mV[VX] - (F32)fmod(beacon_pos.mdV[VX], 256.0), agent_pos.mV[VY] - (F32)fmod(beacon_pos.mdV[VY], 256.0), 0);
+        if (beacon_dir.magVecSquared() < 25.f)
+        {
+            LLTracker::stopTracking(false);
+        }
+        else if ( is_teleport && !gAgent.getTeleportKeepsLookAt() && look_at.isExactlyZero())
+        {
+            //look at the beacon
+            LLVector3 global_agent_pos = agent_pos;
+            global_agent_pos[0] += x;
+            global_agent_pos[1] += y;
+            look_at = (LLVector3)beacon_pos - global_agent_pos;
+            look_at.normVec();
+            gAgentCamera.slamLookAt(look_at);
+        }
+    }
+
+    // TODO: Put back a check for flying status! DK 12/19/05
+    // Sim tells us whether the new position is off the ground
+    /*
+    if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
+    {
+        gAgent.setFlying(TRUE);
+    }
+    else
+    {
+        gAgent.setFlying(FALSE);
+    }
+    */
+
+    send_agent_update(TRUE, TRUE);
+
+    //if (gAgent.getRegion()->getBlockFly())
+    //{
+    //  gAgent.setFlying(gAgent.canFly());
+    //}
+
+    // force simulator to recognize do not disturb state
+    if (gAgent.isDoNotDisturb())
+    {
+        gAgent.setDoNotDisturb(true);
+    }
+    else
+    {
+        gAgent.setDoNotDisturb(false);
+    }
+
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->mFootPlane.clearVec();
+    }
+
+    // send walk-vs-run status
+//  gAgent.sendWalkRun(gAgent.getRunning() || gAgent.getAlwaysRun());
 // [RLVa:KB] - Checked: 2011-05-11 (RLVa-1.3.0i) | Added: RLVa-1.3.0i
-	gAgent.sendWalkRun();
+    gAgent.sendWalkRun();
 // [/RLVa:KB]
 
-	// If the server version has changed, display an info box and offer
-	// to display the release notes, unless this is the initial log in.
-	if (gLastVersionChannel == version_channel)
-	{
-		return;
-	}
+    // If the server version has changed, display an info box and offer
+    // to display the release notes, unless this is the initial log in.
+    if (gLastVersionChannel == version_channel)
+    {
+        return;
+    }
+
+    gLastVersionChannel = version_channel;
+}
+
+void process_crossed_region(LLMessageSystem* msg, void**)
+{
+    LLUUID agent_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+    LLUUID session_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
+    if((gAgent.getID() != agent_id) || (gAgent.getSessionID() != session_id))
+    {
+        LL_WARNS("Messaging") << "Incorrect id in process_crossed_region()"
+                << LL_ENDL;
+        return;
+    }
+    LL_INFOS("Messaging") << "process_crossed_region()" << LL_ENDL;
+    gAgentAvatarp->resetRegionCrossingTimer();
+
+    U32 sim_ip;
+    msg->getIPAddrFast(_PREHASH_RegionData, _PREHASH_SimIP, sim_ip);
+    U16 sim_port;
+    msg->getIPPortFast(_PREHASH_RegionData, _PREHASH_SimPort, sim_port);
+    LLHost sim_host(sim_ip, sim_port);
+    U64 region_handle;
+    msg->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
+
+    std::string seedCap;
+    msg->getStringFast(_PREHASH_RegionData, _PREHASH_SeedCapability, seedCap);
+
+    send_complete_agent_movement(sim_host);
+
+    if (LLGridManager::getInstance()->isInOpenSim())
+    {
+        U32 region_size_x = 256;
+        msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeX, region_size_x);
+        U32 region_size_y = 256;
+        msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeY, region_size_y);
+        LLWorld::getInstance()->setRegionSize(region_size_x, region_size_y);
+    }
+    LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host);
+
+    LL_DEBUGS("CrossingCaps") << "Calling setSeedCapability from process_crossed_region(). Seed cap == "
+        << seedCap << LL_ENDL;
+    regionp->setSeedCapability(seedCap);
+}
+
+
+
+// Sends avatar and camera information to simulator.
+// Sent roughly once per frame, or 20 times per second, whichever is less often
+
+const F32 THRESHOLD_HEAD_ROT_QDOT = 0.9997f;    // ~= 2.5 degrees -- if its less than this we need to update head_rot
+const F32 MAX_HEAD_ROT_QDOT = 0.99999f;         // ~= 0.5 degrees -- if its greater than this then no need to update head_rot
+                                                // between these values we delay the updates (but no more than one second)
+
+void send_agent_update(BOOL force_send, BOOL send_reliable)
+{
+    LL_PROFILE_ZONE_SCOPED;
+    llassert(!gCubeSnapshot);
+
+    if (gAgent.getTeleportState() != LLAgent::TELEPORT_NONE)
+    {
+        // We don't care if they want to send an agent update, they're not allowed to until the simulator
+        // that's the target is ready to receive them (after avatar_init_complete is received)
+        return;
+    }
+
+    // We have already requested to log out.  Don't send agent updates.
+    if(LLAppViewer::instance()->logoutRequestSent())
+    {
+        return;
+    }
+
+    // no region to send update to
+    if(gAgent.getRegion() == NULL)
+    {
+        return;
+    }
+
+    const F32 TRANSLATE_THRESHOLD = 0.01f;
+
+    // NOTA BENE: This is (intentionally?) using the small angle sine approximation to test for rotation
+    //            Plus, there is an extra 0.5 in the mix since the perpendicular between last_camera_at and getAtAxis() bisects cam_rot_change
+    //            Thus, we're actually testing against 0.2 degrees
+    const F32 ROTATION_THRESHOLD = 0.1f * 2.f*F_PI/360.f;           //  Rotation thresh 0.2 deg, see note above
+
+    const U8 DUP_MSGS = 1;              //  HACK!  number of times to repeat data on motionless agent
+
+    //  Store data on last sent update so that if no changes, no send
+    static LLVector3 last_camera_pos_agent,
+                     last_camera_at,
+                     last_camera_left,
+                     last_camera_up;
+
+    static LLVector3 cam_center_chg,
+                     cam_rot_chg;
+
+    static LLQuaternion last_head_rot;
+    static U32 last_control_flags = 0;
+    static U8 last_render_state;
+    static U8 duplicate_count = 0;
+    static F32 head_rot_chg = 1.0;
+    static U8 last_flags;
+
+    LLMessageSystem *msg = gMessageSystem;
+    LLVector3       camera_pos_agent;               // local to avatar's region
+    U8              render_state;
+
+    LLQuaternion body_rotation = gAgent.getFrameAgent().getQuaternion();
+    LLQuaternion head_rotation = gAgent.getHeadRotation();
+
+    camera_pos_agent = gAgentCamera.getCameraPositionAgent();
+
+    render_state = gAgent.getRenderState();
+
+    U32     control_flag_change = 0;
+    U8      flag_change = 0;
+
+    cam_center_chg = last_camera_pos_agent - camera_pos_agent;
+    cam_rot_chg = last_camera_at - LLViewerCamera::getInstance()->getAtAxis();
+
+    // If a modifier key is held down, turn off
+    // LBUTTON and ML_LBUTTON so that using the camera (alt-key) doesn't
+    // trigger a control event.
+    U32 control_flags = gAgent.getControlFlags();
+
+    MASK    key_mask = gKeyboard->currentMask(TRUE);
+
+    if (key_mask & MASK_ALT || key_mask & MASK_CONTROL)
+    {
+        control_flags &= ~( AGENT_CONTROL_LBUTTON_DOWN |
+                            AGENT_CONTROL_ML_LBUTTON_DOWN );
+        control_flags |=    AGENT_CONTROL_LBUTTON_UP |
+                            AGENT_CONTROL_ML_LBUTTON_UP ;
+    }
+
+    control_flag_change = last_control_flags ^ control_flags;
+
+    U8 flags = AU_FLAGS_NONE;
+    if (gAgent.isGroupTitleHidden())
+    {
+        flags |= AU_FLAGS_HIDETITLE;
+    }
+    if (gAgent.getAutoPilot())
+    {
+        flags |= AU_FLAGS_CLIENT_AUTOPILOT;
+    }
+
+    flag_change = last_flags ^ flags;
+
+    head_rot_chg = dot(last_head_rot, head_rotation);
+
+    //static S32 msg_number = 0;        // Used for diagnostic log messages
+
+    if (force_send ||
+        (cam_center_chg.magVec() > TRANSLATE_THRESHOLD) ||
+        (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT) ||
+        (last_render_state != render_state) ||
+        (cam_rot_chg.magVec() > ROTATION_THRESHOLD) ||
+        control_flag_change != 0 ||
+        flag_change != 0)
+    {
+        /* Diagnotics to show why we send the AgentUpdate message.  Also un-commment the msg_number code above and below this block
+        msg_number += 1;
+        if (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT)
+        {
+            //LL_INFOS("Messaging") << "head rot " << head_rotation << LL_ENDL;
+            LL_INFOS("Messaging") << "msg " << msg_number << ", frame " << LLFrameTimer::getFrameCount() << ", head_rot_chg " << head_rot_chg << LL_ENDL;
+        }
+        if (cam_rot_chg.magVec() > ROTATION_THRESHOLD)
+        {
+            LL_INFOS("Messaging") << "msg " << msg_number << ", frame " << LLFrameTimer::getFrameCount() << ", cam rot " <<  cam_rot_chg.magVec() << LL_ENDL;
+        }
+        if (cam_center_chg.magVec() > TRANSLATE_THRESHOLD)
+        {
+            LL_INFOS("Messaging") << "msg " << msg_number << ", frame " << LLFrameTimer::getFrameCount() << ", cam center " << cam_center_chg.magVec() << LL_ENDL;
+        }
+//      if (drag_delta_chg.magVec() > TRANSLATE_THRESHOLD)
+//      {
+//          LL_INFOS("Messaging") << "drag delta " << drag_delta_chg.magVec() << LL_ENDL;
+//      }
+        if (control_flag_change)
+        {
+            LL_INFOS("Messaging") << "msg " << msg_number << ", frame " << LLFrameTimer::getFrameCount() << ", dcf = " << control_flag_change << LL_ENDL;
+        }
+*/
+
+        duplicate_count = 0;
+    }
+    else
+    {
+        duplicate_count++;
+
+        if (head_rot_chg < MAX_HEAD_ROT_QDOT  &&  duplicate_count < AGENT_UPDATES_PER_SECOND)
+        {
+            // The head_rotation is sent for updating things like attached guns.
+            // We only trigger a new update when head_rotation deviates beyond
+            // some threshold from the last update, however this can break fine
+            // adjustments when trying to aim an attached gun, so what we do here
+            // (where we would normally skip sending an update when nothing has changed)
+            // is gradually reduce the threshold to allow a better update to
+            // eventually get sent... should update to within 0.5 degrees in less
+            // than a second.
+            if (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT + (MAX_HEAD_ROT_QDOT - THRESHOLD_HEAD_ROT_QDOT) * duplicate_count / AGENT_UPDATES_PER_SECOND)
+            {
+                duplicate_count = 0;
+            }
+            else
+            {
+                return;
+            }
+        }
+        else
+        {
+            return;
+        }
+    }
+
+    if (duplicate_count < DUP_MSGS && !gDisconnected)
+    {
+        /* More diagnostics to count AgentUpdate messages
+        static S32 update_sec = 0;
+        static S32 update_count = 0;
+        static S32 max_update_count = 0;
+        S32 cur_sec = lltrunc( LLTimer::getTotalSeconds() );
+        update_count += 1;
+        if (cur_sec != update_sec)
+        {
+            if (update_sec != 0)
+            {
+                update_sec = cur_sec;
+                //msg_number = 0;
+                max_update_count = llmax(max_update_count, update_count);
+                LL_INFOS() << "Sent " << update_count << " AgentUpdate messages per second, max is " << max_update_count << LL_ENDL;
+            }
+            update_sec = cur_sec;
+            update_count = 0;
+        }
+        */
 
-	gLastVersionChannel = version_channel;
-}
+        // Build the message
+        msg->newMessageFast(_PREHASH_AgentUpdate);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        msg->addQuatFast(_PREHASH_BodyRotation, body_rotation);
+        msg->addQuatFast(_PREHASH_HeadRotation, head_rotation);
+        msg->addU8Fast(_PREHASH_State, render_state);
+        msg->addU8Fast(_PREHASH_Flags, flags);
 
-void process_crossed_region(LLMessageSystem* msg, void**)
-{
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	LLUUID session_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_SessionID, session_id);
-	if((gAgent.getID() != agent_id) || (gAgent.getSessionID() != session_id))
-	{
-		LL_WARNS("Messaging") << "Incorrect id in process_crossed_region()"
-				<< LL_ENDL;
-		return;
-	}
-	LL_INFOS("Messaging") << "process_crossed_region()" << LL_ENDL;
-	gAgentAvatarp->resetRegionCrossingTimer();
-
-	U32 sim_ip;
-	msg->getIPAddrFast(_PREHASH_RegionData, _PREHASH_SimIP, sim_ip);
-	U16 sim_port;
-	msg->getIPPortFast(_PREHASH_RegionData, _PREHASH_SimPort, sim_port);
-	LLHost sim_host(sim_ip, sim_port);
-	U64 region_handle;
-	msg->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
-	
-	std::string seedCap;
-	msg->getStringFast(_PREHASH_RegionData, _PREHASH_SeedCapability, seedCap);
-
-	send_complete_agent_movement(sim_host);
-
-	if (LLGridManager::getInstance()->isInOpenSim())
-	{
-		U32 region_size_x = 256;
-		msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeX, region_size_x);
-		U32 region_size_y = 256;
-		msg->getU32(_PREHASH_RegionData, _PREHASH_RegionSizeY, region_size_y);
-		LLWorld::getInstance()->setRegionSize(region_size_x, region_size_y);
-	}
-	LLViewerRegion* regionp = LLWorld::getInstance()->addRegion(region_handle, sim_host);
-
-	LL_DEBUGS("CrossingCaps") << "Calling setSeedCapability from process_crossed_region(). Seed cap == "
-		<< seedCap << LL_ENDL;
-	regionp->setSeedCapability(seedCap);
-}
+//      if (camera_pos_agent.mV[VY] > 255.f)
+//      {
+//          LL_INFOS("Messaging") << "Sending camera center " << camera_pos_agent << LL_ENDL;
+//      }
 
+        msg->addVector3Fast(_PREHASH_CameraCenter, camera_pos_agent);
+        msg->addVector3Fast(_PREHASH_CameraAtAxis, LLViewerCamera::getInstance()->getAtAxis());
+        msg->addVector3Fast(_PREHASH_CameraLeftAxis, LLViewerCamera::getInstance()->getLeftAxis());
+        msg->addVector3Fast(_PREHASH_CameraUpAxis, LLViewerCamera::getInstance()->getUpAxis());
+        msg->addF32Fast(_PREHASH_Far, gAgentCamera.mDrawDistance);
 
+        msg->addU32Fast(_PREHASH_ControlFlags, control_flags);
 
-// Sends avatar and camera information to simulator.
-// Sent roughly once per frame, or 20 times per second, whichever is less often
+        if (gDebugClicks)
+        {
+            if (control_flags & AGENT_CONTROL_LBUTTON_DOWN)
+            {
+                LL_INFOS("Messaging") << "AgentUpdate left button down" << LL_ENDL;
+            }
 
-const F32 THRESHOLD_HEAD_ROT_QDOT = 0.9997f;	// ~= 2.5 degrees -- if its less than this we need to update head_rot
-const F32 MAX_HEAD_ROT_QDOT = 0.99999f;			// ~= 0.5 degrees -- if its greater than this then no need to update head_rot
-												// between these values we delay the updates (but no more than one second)
+            if (control_flags & AGENT_CONTROL_LBUTTON_UP)
+            {
+                LL_INFOS("Messaging") << "AgentUpdate left button up" << LL_ENDL;
+            }
+        }
 
-void send_agent_update(BOOL force_send, BOOL send_reliable)
-{
-    LL_PROFILE_ZONE_SCOPED;
-    llassert(!gCubeSnapshot);
+        gAgent.enableControlFlagReset();
 
-	if (gAgent.getTeleportState() != LLAgent::TELEPORT_NONE)
-	{
-		// We don't care if they want to send an agent update, they're not allowed to until the simulator
-		// that's the target is ready to receive them (after avatar_init_complete is received)
-		return;
-	}
-
-	// We have already requested to log out.  Don't send agent updates.
-	if(LLAppViewer::instance()->logoutRequestSent())
-	{
-		return;
-	}
-
-	// no region to send update to
-	if(gAgent.getRegion() == NULL)
-	{
-		return;
-	}
-
-	const F32 TRANSLATE_THRESHOLD = 0.01f;
-
-	// NOTA BENE: This is (intentionally?) using the small angle sine approximation to test for rotation
-	//			  Plus, there is an extra 0.5 in the mix since the perpendicular between last_camera_at and getAtAxis() bisects cam_rot_change
-	//			  Thus, we're actually testing against 0.2 degrees
-	const F32 ROTATION_THRESHOLD = 0.1f * 2.f*F_PI/360.f;			//  Rotation thresh 0.2 deg, see note above
-
-	const U8 DUP_MSGS = 1;				//  HACK!  number of times to repeat data on motionless agent
-
-	//  Store data on last sent update so that if no changes, no send
-	static LLVector3 last_camera_pos_agent, 
-					 last_camera_at, 
-					 last_camera_left,
-					 last_camera_up;
-	
-	static LLVector3 cam_center_chg,
-					 cam_rot_chg;
-
-	static LLQuaternion last_head_rot;
-	static U32 last_control_flags = 0;
-	static U8 last_render_state;
-	static U8 duplicate_count = 0;
-	static F32 head_rot_chg = 1.0;
-	static U8 last_flags;
-
-	LLMessageSystem	*msg = gMessageSystem;
-	LLVector3		camera_pos_agent;				// local to avatar's region
-	U8				render_state;
-
-	LLQuaternion body_rotation = gAgent.getFrameAgent().getQuaternion();
-	LLQuaternion head_rotation = gAgent.getHeadRotation();
-
-	camera_pos_agent = gAgentCamera.getCameraPositionAgent();
-
-	render_state = gAgent.getRenderState();
-
-	U32		control_flag_change = 0;
-	U8		flag_change = 0;
-
-	cam_center_chg = last_camera_pos_agent - camera_pos_agent;
-	cam_rot_chg = last_camera_at - LLViewerCamera::getInstance()->getAtAxis();
-
-	// If a modifier key is held down, turn off
-	// LBUTTON and ML_LBUTTON so that using the camera (alt-key) doesn't
-	// trigger a control event.
-	U32 control_flags = gAgent.getControlFlags();
-
-	MASK	key_mask = gKeyboard->currentMask(TRUE);
-
-	if (key_mask & MASK_ALT || key_mask & MASK_CONTROL)
-	{
-		control_flags &= ~(	AGENT_CONTROL_LBUTTON_DOWN |
-							AGENT_CONTROL_ML_LBUTTON_DOWN );
-		control_flags |= 	AGENT_CONTROL_LBUTTON_UP |
-							AGENT_CONTROL_ML_LBUTTON_UP ;
-	}
-
-	control_flag_change = last_control_flags ^ control_flags;
-
-	U8 flags = AU_FLAGS_NONE;
-	if (gAgent.isGroupTitleHidden())
-	{
-		flags |= AU_FLAGS_HIDETITLE;
-	}
-	if (gAgent.getAutoPilot())
-	{
-		flags |= AU_FLAGS_CLIENT_AUTOPILOT;
-	}
-
-	flag_change = last_flags ^ flags;
-
-	head_rot_chg = dot(last_head_rot, head_rotation);
-
-	//static S32 msg_number = 0;		// Used for diagnostic log messages
-
-	if (force_send || 
-		(cam_center_chg.magVec() > TRANSLATE_THRESHOLD) || 
-		(head_rot_chg < THRESHOLD_HEAD_ROT_QDOT) ||	
-		(last_render_state != render_state) ||
-		(cam_rot_chg.magVec() > ROTATION_THRESHOLD) ||
-		control_flag_change != 0 ||
-		flag_change != 0)  
-	{
-		/* Diagnotics to show why we send the AgentUpdate message.  Also un-commment the msg_number code above and below this block
-		msg_number += 1;
-		if (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT)
-		{
-			//LL_INFOS("Messaging") << "head rot " << head_rotation << LL_ENDL;
-			LL_INFOS("Messaging") << "msg " << msg_number << ", frame " << LLFrameTimer::getFrameCount() << ", head_rot_chg " << head_rot_chg << LL_ENDL;
-		}
-		if (cam_rot_chg.magVec() > ROTATION_THRESHOLD) 
-		{
-			LL_INFOS("Messaging") << "msg " << msg_number << ", frame " << LLFrameTimer::getFrameCount() << ", cam rot " <<  cam_rot_chg.magVec() << LL_ENDL;
-		}
-		if (cam_center_chg.magVec() > TRANSLATE_THRESHOLD)
-		{
-			LL_INFOS("Messaging") << "msg " << msg_number << ", frame " << LLFrameTimer::getFrameCount() << ", cam center " << cam_center_chg.magVec() << LL_ENDL;
-		}
-//		if (drag_delta_chg.magVec() > TRANSLATE_THRESHOLD)
-//		{
-//			LL_INFOS("Messaging") << "drag delta " << drag_delta_chg.magVec() << LL_ENDL;
-//		}
-		if (control_flag_change)
-		{
-			LL_INFOS("Messaging") << "msg " << msg_number << ", frame " << LLFrameTimer::getFrameCount() << ", dcf = " << control_flag_change << LL_ENDL;
-		}
-*/
+        if (!send_reliable)
+        {
+            gAgent.sendMessage();
+        }
+        else
+        {
+            gAgent.sendReliableMessage();
+        }
 
-		duplicate_count = 0;
-	}
-	else
-	{
-		duplicate_count++;
-
-		if (head_rot_chg < MAX_HEAD_ROT_QDOT  &&  duplicate_count < AGENT_UPDATES_PER_SECOND)
-		{
-			// The head_rotation is sent for updating things like attached guns.
-			// We only trigger a new update when head_rotation deviates beyond
-			// some threshold from the last update, however this can break fine
-			// adjustments when trying to aim an attached gun, so what we do here
-			// (where we would normally skip sending an update when nothing has changed)
-			// is gradually reduce the threshold to allow a better update to 
-			// eventually get sent... should update to within 0.5 degrees in less 
-			// than a second.
-			if (head_rot_chg < THRESHOLD_HEAD_ROT_QDOT + (MAX_HEAD_ROT_QDOT - THRESHOLD_HEAD_ROT_QDOT) * duplicate_count / AGENT_UPDATES_PER_SECOND)
-			{
-				duplicate_count = 0;
-			}
-			else
-			{
-				return;
-			}
-		}
-		else
-		{
-			return;
-		}
-	}
-
-	if (duplicate_count < DUP_MSGS && !gDisconnected)
-	{
-		/* More diagnostics to count AgentUpdate messages
-		static S32 update_sec = 0;
-		static S32 update_count = 0;
-		static S32 max_update_count = 0;
-		S32 cur_sec = lltrunc( LLTimer::getTotalSeconds() );
-		update_count += 1;
-		if (cur_sec != update_sec)
-		{
-			if (update_sec != 0)
-			{
-				update_sec = cur_sec;
-				//msg_number = 0;
-				max_update_count = llmax(max_update_count, update_count);
-				LL_INFOS() << "Sent " << update_count << " AgentUpdate messages per second, max is " << max_update_count << LL_ENDL;
-			}
-			update_sec = cur_sec;
-			update_count = 0;
-		}
-		*/
-
-		// Build the message
-		msg->newMessageFast(_PREHASH_AgentUpdate);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->addQuatFast(_PREHASH_BodyRotation, body_rotation);
-		msg->addQuatFast(_PREHASH_HeadRotation, head_rotation);
-		msg->addU8Fast(_PREHASH_State, render_state);
-		msg->addU8Fast(_PREHASH_Flags, flags);
-
-//		if (camera_pos_agent.mV[VY] > 255.f)
-//		{
-//			LL_INFOS("Messaging") << "Sending camera center " << camera_pos_agent << LL_ENDL;
-//		}
-		
-		msg->addVector3Fast(_PREHASH_CameraCenter, camera_pos_agent);
-		msg->addVector3Fast(_PREHASH_CameraAtAxis, LLViewerCamera::getInstance()->getAtAxis());
-		msg->addVector3Fast(_PREHASH_CameraLeftAxis, LLViewerCamera::getInstance()->getLeftAxis());
-		msg->addVector3Fast(_PREHASH_CameraUpAxis, LLViewerCamera::getInstance()->getUpAxis());
-		msg->addF32Fast(_PREHASH_Far, gAgentCamera.mDrawDistance);
-		
-		msg->addU32Fast(_PREHASH_ControlFlags, control_flags);
-
-		if (gDebugClicks)
-		{
-			if (control_flags & AGENT_CONTROL_LBUTTON_DOWN)
-			{
-				LL_INFOS("Messaging") << "AgentUpdate left button down" << LL_ENDL;
-			}
-
-			if (control_flags & AGENT_CONTROL_LBUTTON_UP)
-			{
-				LL_INFOS("Messaging") << "AgentUpdate left button up" << LL_ENDL;
-			}
-		}
-
-		gAgent.enableControlFlagReset();
-
-		if (!send_reliable)
-		{
-			gAgent.sendMessage();
-		}
-		else
-		{
-			gAgent.sendReliableMessage();
-		}
-
-//		LL_DEBUGS("Messaging") << "agent " << avatar_pos_agent << " cam " << camera_pos_agent << LL_ENDL;
-
-		// Copy the old data 
-		last_head_rot = head_rotation;
-		last_render_state = render_state;
-		last_camera_pos_agent = camera_pos_agent;
-		last_camera_at = LLViewerCamera::getInstance()->getAtAxis();
-		last_camera_left = LLViewerCamera::getInstance()->getLeftAxis();
-		last_camera_up = LLViewerCamera::getInstance()->getUpAxis();
-		last_control_flags = control_flags;
-		last_flags = flags;
-	}
+//      LL_DEBUGS("Messaging") << "agent " << avatar_pos_agent << " cam " << camera_pos_agent << LL_ENDL;
+
+        // Copy the old data
+        last_head_rot = head_rotation;
+        last_render_state = render_state;
+        last_camera_pos_agent = camera_pos_agent;
+        last_camera_at = LLViewerCamera::getInstance()->getAtAxis();
+        last_camera_left = LLViewerCamera::getInstance()->getLeftAxis();
+        last_camera_up = LLViewerCamera::getInstance()->getUpAxis();
+        last_control_flags = control_flags;
+        last_flags = flags;
+    }
 }
 
 
@@ -4048,186 +4048,186 @@ void clear_expired_postponed_sounds()
 extern U32Bits gObjectData;
 
 void process_object_update(LLMessageSystem *mesgsys, void **user_data)
-{	
-	// Update the data counters
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gObjectData += (U32Bytes)mesgsys->getReceiveCompressedSize();
-	}
-	else
-	{
-		gObjectData += (U32Bytes)mesgsys->getReceiveSize();
-	}
-
-	// Update the object...
-	S32 old_num_objects = gObjectList.mNumNewObjects;
-	gObjectList.processObjectUpdate(mesgsys, user_data, OUT_FULL);
-	if (old_num_objects != gObjectList.mNumNewObjects)
-	{
-		update_attached_sounds();
-	}
+{
+    // Update the data counters
+    if (mesgsys->getReceiveCompressedSize())
+    {
+        gObjectData += (U32Bytes)mesgsys->getReceiveCompressedSize();
+    }
+    else
+    {
+        gObjectData += (U32Bytes)mesgsys->getReceiveSize();
+    }
+
+    // Update the object...
+    S32 old_num_objects = gObjectList.mNumNewObjects;
+    gObjectList.processObjectUpdate(mesgsys, user_data, OUT_FULL);
+    if (old_num_objects != gObjectList.mNumNewObjects)
+    {
+        update_attached_sounds();
+    }
 }
 
 void process_compressed_object_update(LLMessageSystem *mesgsys, void **user_data)
 {
-	// Update the data counters
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gObjectData += (U32Bytes)mesgsys->getReceiveCompressedSize();
-	}
-	else
-	{
-		gObjectData += (U32Bytes)mesgsys->getReceiveSize();
-	}
-
-	// Update the object...
-	S32 old_num_objects = gObjectList.mNumNewObjects;
-	gObjectList.processCompressedObjectUpdate(mesgsys, user_data, OUT_FULL_COMPRESSED);
-	if (old_num_objects != gObjectList.mNumNewObjects)
-	{
-		update_attached_sounds();
-	}
+    // Update the data counters
+    if (mesgsys->getReceiveCompressedSize())
+    {
+        gObjectData += (U32Bytes)mesgsys->getReceiveCompressedSize();
+    }
+    else
+    {
+        gObjectData += (U32Bytes)mesgsys->getReceiveSize();
+    }
+
+    // Update the object...
+    S32 old_num_objects = gObjectList.mNumNewObjects;
+    gObjectList.processCompressedObjectUpdate(mesgsys, user_data, OUT_FULL_COMPRESSED);
+    if (old_num_objects != gObjectList.mNumNewObjects)
+    {
+        update_attached_sounds();
+    }
 }
 
 void process_cached_object_update(LLMessageSystem *mesgsys, void **user_data)
 {
-	// Update the data counters
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gObjectData += (U32Bytes)mesgsys->getReceiveCompressedSize();
-	}
-	else
-	{
-		gObjectData += (U32Bytes)mesgsys->getReceiveSize();
-	}
+    // Update the data counters
+    if (mesgsys->getReceiveCompressedSize())
+    {
+        gObjectData += (U32Bytes)mesgsys->getReceiveCompressedSize();
+    }
+    else
+    {
+        gObjectData += (U32Bytes)mesgsys->getReceiveSize();
+    }
 
-	// Update the object...
-	gObjectList.processCachedObjectUpdate(mesgsys, user_data, OUT_FULL_CACHED);
+    // Update the object...
+    gObjectList.processCachedObjectUpdate(mesgsys, user_data, OUT_FULL_CACHED);
 }
 
 
 void process_terse_object_update_improved(LLMessageSystem *mesgsys, void **user_data)
 {
-	if (mesgsys->getReceiveCompressedSize())
-	{
-		gObjectData += (U32Bytes)mesgsys->getReceiveCompressedSize();
-	}
-	else
-	{
-		gObjectData += (U32Bytes)mesgsys->getReceiveSize();
-	}
+    if (mesgsys->getReceiveCompressedSize())
+    {
+        gObjectData += (U32Bytes)mesgsys->getReceiveCompressedSize();
+    }
+    else
+    {
+        gObjectData += (U32Bytes)mesgsys->getReceiveSize();
+    }
 
-	S32 old_num_objects = gObjectList.mNumNewObjects;
-	gObjectList.processCompressedObjectUpdate(mesgsys, user_data, OUT_TERSE_IMPROVED);
-	if (old_num_objects != gObjectList.mNumNewObjects)
-	{
-		update_attached_sounds();
-	}
+    S32 old_num_objects = gObjectList.mNumNewObjects;
+    gObjectList.processCompressedObjectUpdate(mesgsys, user_data, OUT_TERSE_IMPROVED);
+    if (old_num_objects != gObjectList.mNumNewObjects)
+    {
+        update_attached_sounds();
+    }
 }
 
 void process_kill_object(LLMessageSystem *mesgsys, void **user_data)
 {
     LL_PROFILE_ZONE_SCOPED;
 
-	LLUUID		id;
-
-	U32 ip = mesgsys->getSenderIP();
-	U32 port = mesgsys->getSenderPort();
-	LLViewerRegion* regionp = NULL;
-	{
-		LLHost host(ip, port);
-		regionp = LLWorld::getInstance()->getRegion(host);
-	}
-
-	bool delete_object = LLViewerRegion::sVOCacheCullingEnabled;
-	S32	num_objects = mesgsys->getNumberOfBlocksFast(_PREHASH_ObjectData);
-	for (S32 i = 0; i < num_objects; ++i)
-	{
-		U32	local_id;
-		mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, local_id, i);
-
-		gObjectList.getUUIDFromLocal(id, local_id, ip, port);
-		if (id.isNull())
-		{
-			LL_DEBUGS("Messaging") << "Unknown kill for local " << local_id << LL_ENDL;
-			continue;
-		}
-		else
-		{
-			LL_DEBUGS("Messaging") << "Kill message for local " << local_id << LL_ENDL;
-		}
-
-		if (id == gAgentID)
-		{
-			// never kill our avatar
-			continue;
-		}
-
-		LLViewerObject *objectp = gObjectList.findObject(id);
-		if (objectp)
-		{
+    LLUUID      id;
+
+    U32 ip = mesgsys->getSenderIP();
+    U32 port = mesgsys->getSenderPort();
+    LLViewerRegion* regionp = NULL;
+    {
+        LLHost host(ip, port);
+        regionp = LLWorld::getInstance()->getRegion(host);
+    }
+
+    bool delete_object = LLViewerRegion::sVOCacheCullingEnabled;
+    S32 num_objects = mesgsys->getNumberOfBlocksFast(_PREHASH_ObjectData);
+    for (S32 i = 0; i < num_objects; ++i)
+    {
+        U32 local_id;
+        mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_ID, local_id, i);
+
+        gObjectList.getUUIDFromLocal(id, local_id, ip, port);
+        if (id.isNull())
+        {
+            LL_DEBUGS("Messaging") << "Unknown kill for local " << local_id << LL_ENDL;
+            continue;
+        }
+        else
+        {
+            LL_DEBUGS("Messaging") << "Kill message for local " << local_id << LL_ENDL;
+        }
+
+        if (id == gAgentID)
+        {
+            // never kill our avatar
+            continue;
+        }
+
+        LLViewerObject *objectp = gObjectList.findObject(id);
+        if (objectp)
+        {
 // [SL:KB] - Patch: Appearance-TeleportAttachKill | Checked: Catznip-4.0
-			if ( (objectp->isAttachment()) && (!objectp->isTempAttachment()) && (LLAgent::TELEPORT_NONE != gAgent.getTeleportState()) &&
-				 (gAgentAvatarp) && (objectp->permYouOwner()) && (gSavedSettings.getBOOL("BlockAttachmentKillsOnTeleport")) )
-			{
-				//gAgentAvatarp->addPendingDetach(objectp->getRootEdit()->getID());
-				continue;
-			}
+            if ( (objectp->isAttachment()) && (!objectp->isTempAttachment()) && (LLAgent::TELEPORT_NONE != gAgent.getTeleportState()) &&
+                 (gAgentAvatarp) && (objectp->permYouOwner()) && (gSavedSettings.getBOOL("BlockAttachmentKillsOnTeleport")) )
+            {
+                //gAgentAvatarp->addPendingDetach(objectp->getRootEdit()->getID());
+                continue;
+            }
 // [/SL:KB]
 
-			// Display green bubble on kill
-			if ( gShowObjectUpdates )
-			{
-				LLColor4 color(0.f,1.f,0.f,1.f);
-				gPipeline.addDebugBlip(objectp->getPositionAgent(), color);
-				LL_DEBUGS("MessageBlip") << "Kill blip for local " << local_id << " at " << objectp->getPositionAgent() << LL_ENDL;
-			}
+            // Display green bubble on kill
+            if ( gShowObjectUpdates )
+            {
+                LLColor4 color(0.f,1.f,0.f,1.f);
+                gPipeline.addDebugBlip(objectp->getPositionAgent(), color);
+                LL_DEBUGS("MessageBlip") << "Kill blip for local " << local_id << " at " << objectp->getPositionAgent() << LL_ENDL;
+            }
 
-			// Do the kill
-			gObjectList.killObject(objectp);
-		}
+            // Do the kill
+            gObjectList.killObject(objectp);
+        }
 
-		if(delete_object)
-		{
-			regionp->killCacheEntry(local_id);
-		}
+        if(delete_object)
+        {
+            regionp->killCacheEntry(local_id);
+        }
 
-		// We should remove the object from selection after it is marked dead by gObjectList to make LLToolGrab,
+        // We should remove the object from selection after it is marked dead by gObjectList to make LLToolGrab,
         // which is using the object, release the mouse capture correctly when the object dies.
         // See LLToolGrab::handleHoverActive() and LLToolGrab::handleHoverNonPhysical().
-		LLSelectMgr::getInstance()->removeObjectFromSelections(id);
+        LLSelectMgr::getInstance()->removeObjectFromSelections(id);
 
-	}	// end for loop
+    }   // end for loop
 
     LLViewerStatsRecorder::instance().recordObjectKills(num_objects);
 }
 
 void process_time_synch(LLMessageSystem *mesgsys, void **user_data)
 {
-	LLVector3 sun_direction;
+    LLVector3 sun_direction;
     LLVector3 moon_direction;
-	LLVector3 sun_ang_velocity;
-	F32 phase;
-	U64	space_time_usec;
+    LLVector3 sun_ang_velocity;
+    F32 phase;
+    U64 space_time_usec;
 
     U32 seconds_per_day;
     U32 seconds_per_year;
 
-	// "SimulatorViewerTimeMessage"
-	mesgsys->getU64Fast(_PREHASH_TimeInfo, _PREHASH_UsecSinceStart, space_time_usec);
-	mesgsys->getU32Fast(_PREHASH_TimeInfo, _PREHASH_SecPerDay, seconds_per_day);
-	mesgsys->getU32Fast(_PREHASH_TimeInfo, _PREHASH_SecPerYear, seconds_per_year);
+    // "SimulatorViewerTimeMessage"
+    mesgsys->getU64Fast(_PREHASH_TimeInfo, _PREHASH_UsecSinceStart, space_time_usec);
+    mesgsys->getU32Fast(_PREHASH_TimeInfo, _PREHASH_SecPerDay, seconds_per_day);
+    mesgsys->getU32Fast(_PREHASH_TimeInfo, _PREHASH_SecPerYear, seconds_per_year);
 
-	// This should eventually be moved to an "UpdateHeavenlyBodies" message
-	mesgsys->getF32Fast(_PREHASH_TimeInfo, _PREHASH_SunPhase, phase);
-	mesgsys->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunDirection, sun_direction);
-	mesgsys->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunAngVelocity, sun_ang_velocity);
+    // This should eventually be moved to an "UpdateHeavenlyBodies" message
+    mesgsys->getF32Fast(_PREHASH_TimeInfo, _PREHASH_SunPhase, phase);
+    mesgsys->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunDirection, sun_direction);
+    mesgsys->getVector3Fast(_PREHASH_TimeInfo, _PREHASH_SunAngVelocity, sun_ang_velocity);
 
-	LLWorld::getInstance()->setSpaceTimeUSec(space_time_usec);
+    LLWorld::getInstance()->setSpaceTimeUSec(space_time_usec);
 
-	LL_DEBUGS("WindlightSync") << "Sun phase: " << phase << " rad = " << fmodf(phase / F_TWO_PI + 0.25, 1.f) * 24.f << " h" << LL_ENDL;
+    LL_DEBUGS("WindlightSync") << "Sun phase: " << phase << " rad = " << fmodf(phase / F_TWO_PI + 0.25, 1.f) * 24.f << " h" << LL_ENDL;
 
-	/* LAPRAS
+    /* LAPRAS
         We decode these parts of the message but ignore them
         as the real values are provided elsewhere. */
     (void)sun_direction, (void)moon_direction, (void)phase;
@@ -4235,393 +4235,393 @@ void process_time_synch(LLMessageSystem *mesgsys, void **user_data)
 
 void process_sound_trigger(LLMessageSystem *msg, void **)
 {
-	if (!gAudiop)
-	{
+    if (!gAudiop)
+    {
 #if !LL_LINUX
-		LL_WARNS("AudioEngine") << "LLAudioEngine instance doesn't exist!" << LL_ENDL;
+        LL_WARNS("AudioEngine") << "LLAudioEngine instance doesn't exist!" << LL_ENDL;
 #endif
-		return;
-	}
-
-	U64		region_handle = 0;
-	F32		gain = 0;
-	LLUUID	sound_id;
-	LLUUID	owner_id;
-	LLUUID	object_id;
-	LLUUID	parent_id;
-	LLVector3	pos_local;
-
-	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_SoundID, sound_id);
-	if (gAudiop && gAudiop->isCorruptSound(sound_id))
-		return;
-
-	if (ALAssetBlocklist::instance().isBlocked(sound_id))
-		return;
-
-	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_OwnerID, owner_id);
-	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ObjectID, object_id);
-
-	msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ParentID, parent_id);
-	msg->getU64Fast(_PREHASH_SoundData, _PREHASH_Handle, region_handle);
-	msg->getVector3Fast(_PREHASH_SoundData, _PREHASH_Position, pos_local);
-	msg->getF32Fast(_PREHASH_SoundData, _PREHASH_Gain, gain);
-
-	// adjust sound location to true global coords
-	LLVector3d	pos_global = from_region_handle(region_handle);
-	pos_global.mdV[VX] += pos_local.mV[VX];
-	pos_global.mdV[VY] += pos_local.mV[VY];
-	pos_global.mdV[VZ] += pos_local.mV[VZ];
-
-	// Don't play a trigger sound if you can't hear it due
-	// to parcel "local audio only" settings.
-	if (!LLViewerParcelMgr::getInstance()->canHearSound(pos_global)) return;
-
-	// Don't play sounds triggered by someone you muted.
-	if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
-	
-	// Don't play sounds from an object you muted
-	if (LLMuteList::getInstance()->isMuted(object_id)) return;
-
-	// Don't play sounds from an object whose parent you muted
-	if (parent_id.notNull()
-		&& LLMuteList::getInstance()->isMuted(parent_id))
-	{
-		return;
-	}
-
-	// Don't play sounds from a region with maturity above current agent maturity
-	if( !gAgent.canAccessMaturityInRegion( region_handle ) )
-	{
-		return;
-	}
-		
-	// Don't play sounds from gestures if they are not enabled.
-	// Do play sounds triggered by avatar, since muting your own
-	// gesture sounds and your own sounds played inworld from 
-	// Inventory can cause confusion.
-	if (object_id == owner_id
+        return;
+    }
+
+    U64     region_handle = 0;
+    F32     gain = 0;
+    LLUUID  sound_id;
+    LLUUID  owner_id;
+    LLUUID  object_id;
+    LLUUID  parent_id;
+    LLVector3   pos_local;
+
+    msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_SoundID, sound_id);
+    if (gAudiop && gAudiop->isCorruptSound(sound_id))
+        return;
+
+    if (ALAssetBlocklist::instance().isBlocked(sound_id))
+        return;
+
+    msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_OwnerID, owner_id);
+    msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ObjectID, object_id);
+
+    msg->getUUIDFast(_PREHASH_SoundData, _PREHASH_ParentID, parent_id);
+    msg->getU64Fast(_PREHASH_SoundData, _PREHASH_Handle, region_handle);
+    msg->getVector3Fast(_PREHASH_SoundData, _PREHASH_Position, pos_local);
+    msg->getF32Fast(_PREHASH_SoundData, _PREHASH_Gain, gain);
+
+    // adjust sound location to true global coords
+    LLVector3d  pos_global = from_region_handle(region_handle);
+    pos_global.mdV[VX] += pos_local.mV[VX];
+    pos_global.mdV[VY] += pos_local.mV[VY];
+    pos_global.mdV[VZ] += pos_local.mV[VZ];
+
+    // Don't play a trigger sound if you can't hear it due
+    // to parcel "local audio only" settings.
+    if (!LLViewerParcelMgr::getInstance()->canHearSound(pos_global)) return;
+
+    // Don't play sounds triggered by someone you muted.
+    if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
+
+    // Don't play sounds from an object you muted
+    if (LLMuteList::getInstance()->isMuted(object_id)) return;
+
+    // Don't play sounds from an object whose parent you muted
+    if (parent_id.notNull()
+        && LLMuteList::getInstance()->isMuted(parent_id))
+    {
+        return;
+    }
+
+    // Don't play sounds from a region with maturity above current agent maturity
+    if( !gAgent.canAccessMaturityInRegion( region_handle ) )
+    {
+        return;
+    }
+
+    // Don't play sounds from gestures if they are not enabled.
+    // Do play sounds triggered by avatar, since muting your own
+    // gesture sounds and your own sounds played inworld from
+    // Inventory can cause confusion.
+    if (object_id == owner_id
         && owner_id != gAgentID
         && !gSavedSettings.getBOOL("EnableGestureSounds"))
-	{
-		return;
-	}
+    {
+        return;
+    }
 
-	if ((LLMaterialTable::basic.isCollisionSound(sound_id) || LLMaterialTable::basic.getGroundCollisionSoundUUID(0) == sound_id) && !gSavedSettings.getBOOL("EnableCollisionSounds"))
-	{
-		return;
-	}
+    if ((LLMaterialTable::basic.isCollisionSound(sound_id) || LLMaterialTable::basic.getGroundCollisionSoundUUID(0) == sound_id) && !gSavedSettings.getBOOL("EnableCollisionSounds"))
+    {
+        return;
+    }
 
-	gAudiop->triggerSound(sound_id, owner_id, gain, LLAudioEngine::AUDIO_TYPE_SFX, pos_global, object_id);
+    gAudiop->triggerSound(sound_id, owner_id, gain, LLAudioEngine::AUDIO_TYPE_SFX, pos_global, object_id);
 }
 
 void process_preload_sound(LLMessageSystem *msg, void **user_data)
 {
-	if (!gAudiop)
-	{
+    if (!gAudiop)
+    {
 #if !LL_LINUX
-		LL_WARNS("AudioEngine") << "LLAudioEngine instance doesn't exist!" << LL_ENDL;
+        LL_WARNS("AudioEngine") << "LLAudioEngine instance doesn't exist!" << LL_ENDL;
 #endif
-		return;
-	}
+        return;
+    }
+
+    LLUUID sound_id;
+    LLUUID object_id;
+    LLUUID owner_id;
 
-	LLUUID sound_id;
-	LLUUID object_id;
-	LLUUID owner_id;
+    msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
+    if (gAudiop->isCorruptSound(sound_id))
+        return;
+
+    if (ALAssetBlocklist::instance().isBlocked(sound_id))
+        return;
 
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
-	if (gAudiop->isCorruptSound(sound_id))
-		return;
+    msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
+    msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
 
-	if (ALAssetBlocklist::instance().isBlocked(sound_id))
-		return;
+    LLViewerObject *objectp = gObjectList.findObject(object_id);
+    if (!objectp) return;
 
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
+    if (LLMuteList::getInstance()->isMuted(object_id)) return;
+    if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
 
-	LLViewerObject *objectp = gObjectList.findObject(object_id);
-	if (!objectp) return;
+    LLAudioSource *sourcep = objectp->getAudioSource(owner_id);
+    if (!sourcep) return;
 
-	if (LLMuteList::getInstance()->isMuted(object_id)) return;
-	if (LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagObjectSounds)) return;
-	
-	LLAudioSource *sourcep = objectp->getAudioSource(owner_id);
-	if (!sourcep) return;
-	
-	LLAudioData *datap = gAudiop->getAudioData(sound_id);
+    LLAudioData *datap = gAudiop->getAudioData(sound_id);
 
-	// Note that I don't actually do any loading of the
-	// audio data into a buffer at this point, as it won't actually
-	// help us out.
+    // Note that I don't actually do any loading of the
+    // audio data into a buffer at this point, as it won't actually
+    // help us out.
 
-	// Don't play sounds from a region with maturity above current agent maturity
-	LLVector3d pos_global = objectp->getPositionGlobal();
-	if (gAgent.canAccessMaturityAtGlobal(pos_global))
-	{
-		// Add audioData starts a transfer internally.
-		sourcep->addAudioData(datap, FALSE);
-	}
+    // Don't play sounds from a region with maturity above current agent maturity
+    LLVector3d pos_global = objectp->getPositionGlobal();
+    if (gAgent.canAccessMaturityAtGlobal(pos_global))
+    {
+        // Add audioData starts a transfer internally.
+        sourcep->addAudioData(datap, FALSE);
+    }
 }
 
 void process_attached_sound(LLMessageSystem *msg, void **user_data)
 {
-	F32 gain = 0;
-	LLUUID sound_id;
-	LLUUID object_id;
-	LLUUID owner_id;
-	U8 flags;
-
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
-	if (gAudiop && gAudiop->isCorruptSound(sound_id))
-		return;
-
-	if (ALAssetBlocklist::instance().isBlocked(sound_id))
-		return;
-
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
-	msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
-	msg->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
-	msg->getU8Fast(_PREHASH_DataBlock, _PREHASH_Flags, flags);
-
-	LLViewerObject *objectp = gObjectList.findObject(object_id);
-	if (objectp)
-	{
-		set_attached_sound(objectp, object_id, sound_id, owner_id, gain, flags);
-	}
-	else if (sound_id.notNull())
-	{
-		// we don't know about this object yet, probably it has yet to arrive
-		// std::map for dupplicate prevention.
-		postponed_sounds[object_id] = (PostponedSoundData(object_id, sound_id, owner_id, gain, flags));
-		clear_expired_postponed_sounds();
-	}
-	else
-	{
-		std::map<LLUUID, PostponedSoundData>::iterator iter = postponed_sounds.find(object_id);
-		if (iter != postponed_sounds.end())
-		{
-			postponed_sounds.erase(iter);
-		}
-	}
+    F32 gain = 0;
+    LLUUID sound_id;
+    LLUUID object_id;
+    LLUUID owner_id;
+    U8 flags;
+
+    msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_SoundID, sound_id);
+    if (gAudiop && gAudiop->isCorruptSound(sound_id))
+        return;
+
+    if (ALAssetBlocklist::instance().isBlocked(sound_id))
+        return;
+
+    msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_id);
+    msg->getUUIDFast(_PREHASH_DataBlock, _PREHASH_OwnerID, owner_id);
+    msg->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
+    msg->getU8Fast(_PREHASH_DataBlock, _PREHASH_Flags, flags);
+
+    LLViewerObject *objectp = gObjectList.findObject(object_id);
+    if (objectp)
+    {
+        set_attached_sound(objectp, object_id, sound_id, owner_id, gain, flags);
+    }
+    else if (sound_id.notNull())
+    {
+        // we don't know about this object yet, probably it has yet to arrive
+        // std::map for dupplicate prevention.
+        postponed_sounds[object_id] = (PostponedSoundData(object_id, sound_id, owner_id, gain, flags));
+        clear_expired_postponed_sounds();
+    }
+    else
+    {
+        std::map<LLUUID, PostponedSoundData>::iterator iter = postponed_sounds.find(object_id);
+        if (iter != postponed_sounds.end())
+        {
+            postponed_sounds.erase(iter);
+        }
+    }
 }
 
 void process_attached_sound_gain_change(LLMessageSystem *mesgsys, void **user_data)
 {
-	F32 gain = 0;
-	LLUUID object_guid;
-	LLViewerObject *objectp = NULL;
+    F32 gain = 0;
+    LLUUID object_guid;
+    LLViewerObject *objectp = NULL;
 
-	mesgsys->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_guid);
+    mesgsys->getUUIDFast(_PREHASH_DataBlock, _PREHASH_ObjectID, object_guid);
 
-	if (!((objectp = gObjectList.findObject(object_guid))))
-	{
-		// we don't know about this object, just bail
-		return;
-	}
+    if (!((objectp = gObjectList.findObject(object_guid))))
+    {
+        // we don't know about this object, just bail
+        return;
+    }
 
- 	mesgsys->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
+    mesgsys->getF32Fast(_PREHASH_DataBlock, _PREHASH_Gain, gain);
 
-	objectp->adjustAudioGain(gain);
+    objectp->adjustAudioGain(gain);
 }
 
 
 void process_health_message(LLMessageSystem *mesgsys, void **user_data)
 {
-	F32 health;
+    F32 health;
 
-	mesgsys->getF32Fast(_PREHASH_HealthData, _PREHASH_Health, health);
+    mesgsys->getF32Fast(_PREHASH_HealthData, _PREHASH_Health, health);
 
-	if (gStatusBar)
-	{
-		gStatusBar->setHealth((S32)health);
-	}
+    if (gStatusBar)
+    {
+        gStatusBar->setHealth((S32)health);
+    }
 }
 
 
 void process_sim_stats(LLMessageSystem *msg, void **user_data)
-{	
-	S32 count = msg->getNumberOfBlocksFast(_PREHASH_Stat);
-	for (S32 i = 0; i < count; ++i)
-	{
-		U32 stat_id;
-		F32 stat_value;
-		msg->getU32Fast(_PREHASH_Stat, _PREHASH_StatID, stat_id, i);
-		msg->getF32Fast(_PREHASH_Stat, _PREHASH_StatValue, stat_value, i);
-		auto measurementp = LLStatViewer::SimMeasurementSampler::getInstance((ESimStatID)stat_id);
-
-		if (measurementp )
-		{
-			measurementp->sample(stat_value);
-		}
-	}
-
-	//
-	// Various hacks that aren't statistics, but are being handled here.
-	//
-	U32 max_tasks_per_region;
-	U64 region_flags;
-	msg->getU32Fast(_PREHASH_Region, _PREHASH_ObjectCapacity, max_tasks_per_region);
-
-	if (msg->hasFast(_PREHASH_RegionInfo))
-	{
-		msg->getU64Fast(_PREHASH_RegionInfo, _PREHASH_RegionFlagsExtended, region_flags);
-	}
-	else
-	{
-		U32 flags = 0;
-		msg->getU32Fast(_PREHASH_Region, _PREHASH_RegionFlags, flags);
-		region_flags = flags;
-	}
-
-	LLViewerRegion* regionp = gAgent.getRegion();
-	if (regionp)
-	{
-		BOOL was_flying = gAgent.getFlying();
-		regionp->setRegionFlags(region_flags);
-		regionp->setMaxTasks(max_tasks_per_region);
-		// HACK: This makes agents drop from the sky if the region is 
-		// set to no fly while people are still in the sim.
-		if (was_flying && regionp->getBlockFly())
-		{
-			gAgent.setFlying(gAgent.canFly());
-		}
-	}
+{
+    S32 count = msg->getNumberOfBlocksFast(_PREHASH_Stat);
+    for (S32 i = 0; i < count; ++i)
+    {
+        U32 stat_id;
+        F32 stat_value;
+        msg->getU32Fast(_PREHASH_Stat, _PREHASH_StatID, stat_id, i);
+        msg->getF32Fast(_PREHASH_Stat, _PREHASH_StatValue, stat_value, i);
+        auto measurementp = LLStatViewer::SimMeasurementSampler::getInstance((ESimStatID)stat_id);
+
+        if (measurementp )
+        {
+            measurementp->sample(stat_value);
+        }
+    }
+
+    //
+    // Various hacks that aren't statistics, but are being handled here.
+    //
+    U32 max_tasks_per_region;
+    U64 region_flags;
+    msg->getU32Fast(_PREHASH_Region, _PREHASH_ObjectCapacity, max_tasks_per_region);
+
+    if (msg->hasFast(_PREHASH_RegionInfo))
+    {
+        msg->getU64Fast(_PREHASH_RegionInfo, _PREHASH_RegionFlagsExtended, region_flags);
+    }
+    else
+    {
+        U32 flags = 0;
+        msg->getU32Fast(_PREHASH_Region, _PREHASH_RegionFlags, flags);
+        region_flags = flags;
+    }
+
+    LLViewerRegion* regionp = gAgent.getRegion();
+    if (regionp)
+    {
+        BOOL was_flying = gAgent.getFlying();
+        regionp->setRegionFlags(region_flags);
+        regionp->setMaxTasks(max_tasks_per_region);
+        // HACK: This makes agents drop from the sky if the region is
+        // set to no fly while people are still in the sim.
+        if (was_flying && regionp->getBlockFly())
+        {
+            gAgent.setFlying(gAgent.canFly());
+        }
+    }
 }
 
 
 
 void process_avatar_animation(LLMessageSystem *mesgsys, void **user_data)
 {
-	LLUUID	animation_id;
-	LLUUID	uuid;
-	S32		anim_sequence_id;
-	LLVOAvatar *avatarp = NULL;
-	
-	mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
+    LLUUID  animation_id;
+    LLUUID  uuid;
+    S32     anim_sequence_id;
+    LLVOAvatar *avatarp = NULL;
+
+    mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
 
-	LLViewerObject *objp = gObjectList.findObject(uuid);
+    LLViewerObject *objp = gObjectList.findObject(uuid);
     if (objp)
     {
         avatarp =  objp->asAvatar();
     }
 
-	if (!avatarp)
-	{
-		// no agent by this ID...error?
-		LL_WARNS("Messaging") << "Received animation state for unknown avatar " << uuid << LL_ENDL;
-		return;
-	}
+    if (!avatarp)
+    {
+        // no agent by this ID...error?
+        LL_WARNS("Messaging") << "Received animation state for unknown avatar " << uuid << LL_ENDL;
+        return;
+    }
 
-	S32 num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationList);
-	S32 num_source_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationSourceList);
+    S32 num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationList);
+    S32 num_source_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationSourceList);
 
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Messaging", "Motion") << "Processing " << num_blocks << " Animations" << LL_ENDL;
+    LL_DEBUGS("Messaging", "Motion") << "Processing " << num_blocks << " Animations" << LL_ENDL;
 #endif
 
-	//clear animation flags
-	avatarp->mSignaledAnimations.clear();
-	
-	if (avatarp->isSelf())
-	{
-		LLUUID object_id;
-
-		for( S32 i = 0; i < num_blocks; i++ )
-		{
-			mesgsys->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID, animation_id, i);
-			mesgsys->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID, anim_sequence_id, i);
-
-			avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
-
-			// *HACK: Disabling flying mode if it has been enabled shortly before the agent
-			// stand up animation is signaled. In this case we don't get a signal to start
-			// flying animation from server, the AGENT_CONTROL_FLY flag remains set but the
-			// avatar does not play flying animation, so we switch flying mode off.
-			// See LLAgent::setFlying(). This may cause "Stop Flying" button to blink.
-			// See EXT-2781.
-			if (animation_id == ANIM_AGENT_STANDUP && gAgent.getFlying())
-			{
-				gAgent.setFlying(FALSE);
-			}
-
-			if (i < num_source_blocks)
-			{
-				mesgsys->getUUIDFast(_PREHASH_AnimationSourceList, _PREHASH_ObjectID, object_id, i);
-			
-				LLViewerObject* object = gObjectList.findObject(object_id);
-				if (object)
-				{
-					object->setFlagsWithoutUpdate(FLAGS_ANIM_SOURCE, TRUE);
-
-					BOOL anim_found = FALSE;
-					LLVOAvatar::AnimSourceIterator anim_it = avatarp->mAnimationSources.find(object_id);
-					for (;anim_it != avatarp->mAnimationSources.end(); ++anim_it)
-					{
-						if (anim_it->first != object_id)
-						{
-							// elements with the same key are always contiguous, bail if we went past the
-							// end of this object's animations
-							break;
-						}
-						if (anim_it->second == animation_id)
-						{
-							anim_found = TRUE;
-							break;
-						}
-					}
-
-					if (!anim_found)
-					{
-						avatarp->mAnimationSources.insert(LLVOAvatar::AnimationSourceMap::value_type(object_id, animation_id));
-					}
-				}
+    //clear animation flags
+    avatarp->mSignaledAnimations.clear();
+
+    if (avatarp->isSelf())
+    {
+        LLUUID object_id;
+
+        for( S32 i = 0; i < num_blocks; i++ )
+        {
+            mesgsys->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID, animation_id, i);
+            mesgsys->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID, anim_sequence_id, i);
+
+            avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
+
+            // *HACK: Disabling flying mode if it has been enabled shortly before the agent
+            // stand up animation is signaled. In this case we don't get a signal to start
+            // flying animation from server, the AGENT_CONTROL_FLY flag remains set but the
+            // avatar does not play flying animation, so we switch flying mode off.
+            // See LLAgent::setFlying(). This may cause "Stop Flying" button to blink.
+            // See EXT-2781.
+            if (animation_id == ANIM_AGENT_STANDUP && gAgent.getFlying())
+            {
+                gAgent.setFlying(FALSE);
+            }
+
+            if (i < num_source_blocks)
+            {
+                mesgsys->getUUIDFast(_PREHASH_AnimationSourceList, _PREHASH_ObjectID, object_id, i);
+
+                LLViewerObject* object = gObjectList.findObject(object_id);
+                if (object)
+                {
+                    object->setFlagsWithoutUpdate(FLAGS_ANIM_SOURCE, TRUE);
+
+                    BOOL anim_found = FALSE;
+                    LLVOAvatar::AnimSourceIterator anim_it = avatarp->mAnimationSources.find(object_id);
+                    for (;anim_it != avatarp->mAnimationSources.end(); ++anim_it)
+                    {
+                        if (anim_it->first != object_id)
+                        {
+                            // elements with the same key are always contiguous, bail if we went past the
+                            // end of this object's animations
+                            break;
+                        }
+                        if (anim_it->second == animation_id)
+                        {
+                            anim_found = TRUE;
+                            break;
+                        }
+                    }
+
+                    if (!anim_found)
+                    {
+                        avatarp->mAnimationSources.insert(LLVOAvatar::AnimationSourceMap::value_type(object_id, animation_id));
+                    }
+                }
 #ifdef SHOW_DEBUG
-				LL_DEBUGS("Messaging", "Motion") << "Anim sequence ID: " << anim_sequence_id
-									<< " Animation id: " << animation_id
-									<< " From block: " << object_id << LL_ENDL;
+                LL_DEBUGS("Messaging", "Motion") << "Anim sequence ID: " << anim_sequence_id
+                                    << " Animation id: " << animation_id
+                                    << " From block: " << object_id << LL_ENDL;
 #endif
-			}
+            }
 #ifdef SHOW_DEBUG
-			else
-			{
-				LL_DEBUGS("Messaging", "Motion") << "Anim sequence ID: " << anim_sequence_id
-									<< " Animation id: " << animation_id << LL_ENDL;
-			}
+            else
+            {
+                LL_DEBUGS("Messaging", "Motion") << "Anim sequence ID: " << anim_sequence_id
+                                    << " Animation id: " << animation_id << LL_ENDL;
+            }
 #endif
-		}
-	}
-	else
-	{
-		for( S32 i = 0; i < num_blocks; i++ )
-		{
-			mesgsys->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID, animation_id, i);
-			mesgsys->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID, anim_sequence_id, i);
-			avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
-		}
-	}
+        }
+    }
+    else
+    {
+        for( S32 i = 0; i < num_blocks; i++ )
+        {
+            mesgsys->getUUIDFast(_PREHASH_AnimationList, _PREHASH_AnimID, animation_id, i);
+            mesgsys->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID, anim_sequence_id, i);
+            avatarp->mSignaledAnimations[animation_id] = anim_sequence_id;
+        }
+    }
 
-	if (num_blocks)
-	{
-		avatarp->processAnimationStateChanges();
-	}
+    if (num_blocks)
+    {
+        avatarp->processAnimationStateChanges();
+    }
 }
 
 
 void process_object_animation(LLMessageSystem *mesgsys, void **user_data)
 {
-	LLUUID	animation_id;
-	LLUUID	uuid;
-	S32		anim_sequence_id;
-	
-	mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
+    LLUUID  animation_id;
+    LLUUID  uuid;
+    S32     anim_sequence_id;
+
+    mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
 
 #ifdef SHOW_DEBUG
     LL_DEBUGS("AnimatedObjectsNotify") << "Received animation state for object " << uuid << LL_ENDL;
 #endif
 
     signaled_animation_map_t signaled_anims;
-	S32 num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationList);
+    S32 num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_AnimationList);
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("AnimatedObjectsNotify") << "processing object animation requests, num_blocks " << num_blocks << " uuid " << uuid << LL_ENDL;
+    LL_DEBUGS("AnimatedObjectsNotify") << "processing object animation requests, num_blocks " << num_blocks << " uuid " << uuid << LL_ENDL;
 #endif
     for( S32 i = 0; i < num_blocks; i++ )
     {
@@ -4629,26 +4629,26 @@ void process_object_animation(LLMessageSystem *mesgsys, void **user_data)
         mesgsys->getS32Fast(_PREHASH_AnimationList, _PREHASH_AnimSequenceID, anim_sequence_id, i);
         signaled_anims[animation_id] = anim_sequence_id;
 #ifdef SHOW_DEBUG
-        LL_DEBUGS("AnimatedObjectsNotify") << "added signaled_anims animation request for object " 
+        LL_DEBUGS("AnimatedObjectsNotify") << "added signaled_anims animation request for object "
                                     << uuid << " animation id " << animation_id << LL_ENDL;
 #endif
     }
     LLObjectSignaledAnimationMap::instance().getMap()[uuid] = signaled_anims;
-    
+
     LLViewerObject *objp = gObjectList.findObject(uuid);
     if (!objp || objp->isDead())
     {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("AnimatedObjectsNotify") << "Received animation state for unknown object " << uuid << LL_ENDL;
+        LL_DEBUGS("AnimatedObjectsNotify") << "Received animation state for unknown object " << uuid << LL_ENDL;
 #endif
         return;
     }
-    
-	LLVOVolume *volp = objp->asVolume();
+
+    LLVOVolume *volp = objp->asVolume();
     if (!volp)
     {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("AnimatedObjectsNotify") << "Received animation state for non-volume object " << uuid << LL_ENDL;
+        LL_DEBUGS("AnimatedObjectsNotify") << "Received animation state for non-volume object " << uuid << LL_ENDL;
 #endif
         return;
     }
@@ -4656,7 +4656,7 @@ void process_object_animation(LLMessageSystem *mesgsys, void **user_data)
     if (!volp->isAnimatedObject())
     {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("AnimatedObjectsNotify") << "Received animation state for non-animated object " << uuid << LL_ENDL;
+        LL_DEBUGS("AnimatedObjectsNotify") << "Received animation state for non-animated object " << uuid << LL_ENDL;
 #endif
         return;
     }
@@ -4670,7 +4670,7 @@ void process_object_animation(LLMessageSystem *mesgsys, void **user_data)
 #endif
         return;
     }
-    
+
     if (!avatarp->mPlaying)
     {
         avatarp->mPlaying = true;
@@ -4680,323 +4680,323 @@ void process_object_animation(LLMessageSystem *mesgsys, void **user_data)
             avatarp->mRootVolp->recursiveMarkForUpdate();
         }
     }
-        
+
     avatarp->updateAnimations();
 }
 
 
 void process_avatar_appearance(LLMessageSystem *mesgsys, void **user_data)
 {
-	LLUUID uuid;
-	mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
+    LLUUID uuid;
+    mesgsys->getUUIDFast(_PREHASH_Sender, _PREHASH_ID, uuid);
 
-	LLVOAvatar* avatarp = (LLVOAvatar *)gObjectList.findObject(uuid);
-	if (avatarp)
-	{
-		avatarp->processAvatarAppearance( mesgsys );
-	}
-	else
-	{
-		LL_WARNS("Messaging") << "avatar_appearance sent for unknown avatar " << uuid << LL_ENDL;
-	}
+    LLVOAvatar* avatarp = (LLVOAvatar *)gObjectList.findObject(uuid);
+    if (avatarp)
+    {
+        avatarp->processAvatarAppearance( mesgsys );
+    }
+    else
+    {
+        LL_WARNS("Messaging") << "avatar_appearance sent for unknown avatar " << uuid << LL_ENDL;
+    }
 }
 
 void process_camera_constraint(LLMessageSystem *mesgsys, void **user_data)
 {
-	static LLCachedControl<bool> disable_sim_cam_constraint(gSavedSettings, "AlchemyIgnoreSimCameraConstraint", false);
-	LLVector4 cameraCollidePlane;
-	if(disable_sim_cam_constraint)
-	{
-		cameraCollidePlane.zeroVec();
-	}
-	else
-	{
-		mesgsys->getVector4Fast(_PREHASH_CameraCollidePlane, _PREHASH_Plane, cameraCollidePlane);
-	}
+    static LLCachedControl<bool> disable_sim_cam_constraint(gSavedSettings, "AlchemyIgnoreSimCameraConstraint", false);
+    LLVector4 cameraCollidePlane;
+    if(disable_sim_cam_constraint)
+    {
+        cameraCollidePlane.zeroVec();
+    }
+    else
+    {
+        mesgsys->getVector4Fast(_PREHASH_CameraCollidePlane, _PREHASH_Plane, cameraCollidePlane);
+    }
 
-	gAgentCamera.setCameraCollidePlane(cameraCollidePlane);
+    gAgentCamera.setCameraCollidePlane(cameraCollidePlane);
 }
 
 void near_sit_object(BOOL success, void *data)
 {
-	if (success)
-	{
-		// Send message to sit on object
-		gMessageSystem->newMessageFast(_PREHASH_AgentSit);
-		gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-		gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		gAgent.sendReliableMessage();
-	}
+    if (success)
+    {
+        // Send message to sit on object
+        gMessageSystem->newMessageFast(_PREHASH_AgentSit);
+        gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+        gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        gAgent.sendReliableMessage();
+    }
 }
 
 void process_avatar_sit_response(LLMessageSystem *mesgsys, void **user_data)
 {
-	LLVector3 sitPosition;
-	LLQuaternion sitRotation;
-	LLUUID sitObjectID;
-	BOOL use_autopilot;
-	mesgsys->getUUIDFast(_PREHASH_SitObject, _PREHASH_ID, sitObjectID);
-	mesgsys->getBOOLFast(_PREHASH_SitTransform, _PREHASH_AutoPilot, use_autopilot);
-	mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_SitPosition, sitPosition);
-	mesgsys->getQuatFast(_PREHASH_SitTransform, _PREHASH_SitRotation, sitRotation);
-	LLVector3 camera_eye;
-	mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraEyeOffset, camera_eye);
-	LLVector3 camera_at;
-	mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraAtOffset, camera_at);
-	BOOL force_mouselook;
-	mesgsys->getBOOLFast(_PREHASH_SitTransform, _PREHASH_ForceMouselook, force_mouselook);
-
-	if (isAgentAvatarValid() && dist_vec_squared(camera_eye, camera_at) > CAMERA_POSITION_THRESHOLD_SQUARED)
-	{
-		gAgentCamera.setSitCamera(sitObjectID, camera_eye, camera_at);
-	}
-	
-	gAgentCamera.setForceMouselook(force_mouselook);
-	// Forcing turning off flying here to prevent flying after pressing "Stand"
-	// to stand up from an object. See EXT-1655.
-	gAgent.setFlying(FALSE);
-
-	LLViewerObject* object = gObjectList.findObject(sitObjectID);
-	if (object)
-	{
-		LLVector3 sit_spot = object->getPositionAgent() + (sitPosition * object->getRotation());
-		if (!use_autopilot || (isAgentAvatarValid() && gAgentAvatarp->isSitting() && gAgentAvatarp->getRoot() == object->getRoot()))
-		{
-			//we're already sitting on this object, so don't autopilot
-		}
-		else
-		{
-			gAgent.startAutoPilotGlobal(gAgent.getPosGlobalFromAgent(sit_spot), "Sit", &sitRotation, near_sit_object, NULL, 0.5f);
-		}
-	}
-	else
-	{
-		LL_WARNS("Messaging") << "Received sit approval for unknown object " << sitObjectID << LL_ENDL;
-	}
+    LLVector3 sitPosition;
+    LLQuaternion sitRotation;
+    LLUUID sitObjectID;
+    BOOL use_autopilot;
+    mesgsys->getUUIDFast(_PREHASH_SitObject, _PREHASH_ID, sitObjectID);
+    mesgsys->getBOOLFast(_PREHASH_SitTransform, _PREHASH_AutoPilot, use_autopilot);
+    mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_SitPosition, sitPosition);
+    mesgsys->getQuatFast(_PREHASH_SitTransform, _PREHASH_SitRotation, sitRotation);
+    LLVector3 camera_eye;
+    mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraEyeOffset, camera_eye);
+    LLVector3 camera_at;
+    mesgsys->getVector3Fast(_PREHASH_SitTransform, _PREHASH_CameraAtOffset, camera_at);
+    BOOL force_mouselook;
+    mesgsys->getBOOLFast(_PREHASH_SitTransform, _PREHASH_ForceMouselook, force_mouselook);
+
+    if (isAgentAvatarValid() && dist_vec_squared(camera_eye, camera_at) > CAMERA_POSITION_THRESHOLD_SQUARED)
+    {
+        gAgentCamera.setSitCamera(sitObjectID, camera_eye, camera_at);
+    }
+
+    gAgentCamera.setForceMouselook(force_mouselook);
+    // Forcing turning off flying here to prevent flying after pressing "Stand"
+    // to stand up from an object. See EXT-1655.
+    gAgent.setFlying(FALSE);
+
+    LLViewerObject* object = gObjectList.findObject(sitObjectID);
+    if (object)
+    {
+        LLVector3 sit_spot = object->getPositionAgent() + (sitPosition * object->getRotation());
+        if (!use_autopilot || (isAgentAvatarValid() && gAgentAvatarp->isSitting() && gAgentAvatarp->getRoot() == object->getRoot()))
+        {
+            //we're already sitting on this object, so don't autopilot
+        }
+        else
+        {
+            gAgent.startAutoPilotGlobal(gAgent.getPosGlobalFromAgent(sit_spot), "Sit", &sitRotation, near_sit_object, NULL, 0.5f);
+        }
+    }
+    else
+    {
+        LL_WARNS("Messaging") << "Received sit approval for unknown object " << sitObjectID << LL_ENDL;
+    }
 }
 
 void process_clear_follow_cam_properties(LLMessageSystem *mesgsys, void **user_data)
 {
-	LLUUID		source_id;
+    LLUUID      source_id;
+
+    mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
+
+    LLFollowCamMgr::getInstance()->removeFollowCamParams(source_id);
+}
+
+void process_set_follow_cam_properties(LLMessageSystem *mesgsys, void **user_data)
+{
+    S32         type;
+    F32         value;
+    bool        settingPosition = false;
+    bool        settingFocus    = false;
+    bool        settingFocusOffset = false;
+    LLVector3   position;
+    LLVector3   focus;
+    LLVector3   focus_offset;
 
-	mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
+    LLUUID      source_id;
+
+    mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
+
+    LLViewerObject* objectp = gObjectList.findObject(source_id);
+    if (objectp)
+    {
+        objectp->setFlagsWithoutUpdate(FLAGS_CAMERA_SOURCE, TRUE);
+    }
+
+    S32 num_objects = mesgsys->getNumberOfBlocksFast(_PREHASH_CameraProperty);
+    for (S32 block_index = 0; block_index < num_objects; block_index++)
+    {
+        mesgsys->getS32Fast(_PREHASH_CameraProperty, _PREHASH_Type, type, block_index);
+        mesgsys->getF32Fast(_PREHASH_CameraProperty, _PREHASH_Value, value, block_index);
+        switch(type)
+        {
+        case FOLLOWCAM_PITCH:
+            LLFollowCamMgr::getInstance()->setPitch(source_id, value);
+            break;
+        case FOLLOWCAM_FOCUS_OFFSET_X:
+            focus_offset.mV[VX] = value;
+            settingFocusOffset = true;
+            break;
+        case FOLLOWCAM_FOCUS_OFFSET_Y:
+            focus_offset.mV[VY] = value;
+            settingFocusOffset = true;
+            break;
+        case FOLLOWCAM_FOCUS_OFFSET_Z:
+            focus_offset.mV[VZ] = value;
+            settingFocusOffset = true;
+            break;
+        case FOLLOWCAM_POSITION_LAG:
+            LLFollowCamMgr::getInstance()->setPositionLag(source_id, value);
+            break;
+        case FOLLOWCAM_FOCUS_LAG:
+            LLFollowCamMgr::getInstance()->setFocusLag(source_id, value);
+            break;
+        case FOLLOWCAM_DISTANCE:
+            LLFollowCamMgr::getInstance()->setDistance(source_id, value);
+            break;
+        case FOLLOWCAM_BEHINDNESS_ANGLE:
+            LLFollowCamMgr::getInstance()->setBehindnessAngle(source_id, value);
+            break;
+        case FOLLOWCAM_BEHINDNESS_LAG:
+            LLFollowCamMgr::getInstance()->setBehindnessLag(source_id, value);
+            break;
+        case FOLLOWCAM_POSITION_THRESHOLD:
+            LLFollowCamMgr::getInstance()->setPositionThreshold(source_id, value);
+            break;
+        case FOLLOWCAM_FOCUS_THRESHOLD:
+            LLFollowCamMgr::getInstance()->setFocusThreshold(source_id, value);
+            break;
+        case FOLLOWCAM_ACTIVE:
+            //if 1, set using followcam,.
+            LLFollowCamMgr::getInstance()->setCameraActive(source_id, value != 0.f);
+            break;
+        case FOLLOWCAM_POSITION_X:
+            settingPosition = true;
+            position.mV[ 0 ] = value;
+            break;
+        case FOLLOWCAM_POSITION_Y:
+            settingPosition = true;
+            position.mV[ 1 ] = value;
+            break;
+        case FOLLOWCAM_POSITION_Z:
+            settingPosition = true;
+            position.mV[ 2 ] = value;
+            break;
+        case FOLLOWCAM_FOCUS_X:
+            settingFocus = true;
+            focus.mV[ 0 ] = value;
+            break;
+        case FOLLOWCAM_FOCUS_Y:
+            settingFocus = true;
+            focus.mV[ 1 ] = value;
+            break;
+        case FOLLOWCAM_FOCUS_Z:
+            settingFocus = true;
+            focus.mV[ 2 ] = value;
+            break;
+        case FOLLOWCAM_POSITION_LOCKED:
+            LLFollowCamMgr::getInstance()->setPositionLocked(source_id, value != 0.f);
+            break;
+        case FOLLOWCAM_FOCUS_LOCKED:
+            LLFollowCamMgr::getInstance()->setFocusLocked(source_id, value != 0.f);
+            break;
+
+        default:
+            break;
+        }
+    }
 
-	LLFollowCamMgr::getInstance()->removeFollowCamParams(source_id);
+    if ( settingPosition )
+    {
+        LLFollowCamMgr::getInstance()->setPosition(source_id, position);
+    }
+    if ( settingFocus )
+    {
+        LLFollowCamMgr::getInstance()->setFocus(source_id, focus);
+    }
+    if ( settingFocusOffset )
+    {
+        LLFollowCamMgr::getInstance()->setFocusOffset(source_id, focus_offset);
+    }
 }
-
-void process_set_follow_cam_properties(LLMessageSystem *mesgsys, void **user_data)
-{
-	S32			type;
-	F32			value;
-	bool		settingPosition = false;
-	bool		settingFocus	= false;
-	bool		settingFocusOffset = false;
-	LLVector3	position;
-	LLVector3	focus;
-	LLVector3	focus_offset;
-
-	LLUUID		source_id;
-
-	mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_ObjectID, source_id);
-
-	LLViewerObject* objectp = gObjectList.findObject(source_id);
-	if (objectp)
-	{
-		objectp->setFlagsWithoutUpdate(FLAGS_CAMERA_SOURCE, TRUE);
-	}
-
-	S32 num_objects = mesgsys->getNumberOfBlocksFast(_PREHASH_CameraProperty);
-	for (S32 block_index = 0; block_index < num_objects; block_index++)
-	{
-		mesgsys->getS32Fast(_PREHASH_CameraProperty, _PREHASH_Type, type, block_index);
-		mesgsys->getF32Fast(_PREHASH_CameraProperty, _PREHASH_Value, value, block_index);
-		switch(type)
-		{
-		case FOLLOWCAM_PITCH:
-			LLFollowCamMgr::getInstance()->setPitch(source_id, value);
-			break;
-		case FOLLOWCAM_FOCUS_OFFSET_X:
-			focus_offset.mV[VX] = value;
-			settingFocusOffset = true;
-			break;
-		case FOLLOWCAM_FOCUS_OFFSET_Y:
-			focus_offset.mV[VY] = value;
-			settingFocusOffset = true;
-			break;
-		case FOLLOWCAM_FOCUS_OFFSET_Z:
-			focus_offset.mV[VZ] = value;
-			settingFocusOffset = true;
-			break;
-		case FOLLOWCAM_POSITION_LAG:
-			LLFollowCamMgr::getInstance()->setPositionLag(source_id, value);
-			break;
-		case FOLLOWCAM_FOCUS_LAG:
-			LLFollowCamMgr::getInstance()->setFocusLag(source_id, value);
-			break;
-		case FOLLOWCAM_DISTANCE:
-			LLFollowCamMgr::getInstance()->setDistance(source_id, value);
-			break;
-		case FOLLOWCAM_BEHINDNESS_ANGLE:
-			LLFollowCamMgr::getInstance()->setBehindnessAngle(source_id, value);
-			break;
-		case FOLLOWCAM_BEHINDNESS_LAG:
-			LLFollowCamMgr::getInstance()->setBehindnessLag(source_id, value);
-			break;
-		case FOLLOWCAM_POSITION_THRESHOLD:
-			LLFollowCamMgr::getInstance()->setPositionThreshold(source_id, value);
-			break;
-		case FOLLOWCAM_FOCUS_THRESHOLD:
-			LLFollowCamMgr::getInstance()->setFocusThreshold(source_id, value);
-			break;
-		case FOLLOWCAM_ACTIVE:
-			//if 1, set using followcam,. 
-			LLFollowCamMgr::getInstance()->setCameraActive(source_id, value != 0.f);
-			break;
-		case FOLLOWCAM_POSITION_X:
-			settingPosition = true;
-			position.mV[ 0 ] = value;
-			break;
-		case FOLLOWCAM_POSITION_Y:
-			settingPosition = true;
-			position.mV[ 1 ] = value;
-			break;
-		case FOLLOWCAM_POSITION_Z:
-			settingPosition = true;
-			position.mV[ 2 ] = value;
-			break;
-		case FOLLOWCAM_FOCUS_X:
-			settingFocus = true;
-			focus.mV[ 0 ] = value;
-			break;
-		case FOLLOWCAM_FOCUS_Y:
-			settingFocus = true;
-			focus.mV[ 1 ] = value;
-			break;
-		case FOLLOWCAM_FOCUS_Z:
-			settingFocus = true;
-			focus.mV[ 2 ] = value;
-			break;
-		case FOLLOWCAM_POSITION_LOCKED:
-			LLFollowCamMgr::getInstance()->setPositionLocked(source_id, value != 0.f);
-			break;
-		case FOLLOWCAM_FOCUS_LOCKED:
-			LLFollowCamMgr::getInstance()->setFocusLocked(source_id, value != 0.f);
-			break;
-
-		default:
-			break;
-		}
-	}
-
-	if ( settingPosition )
-	{
-		LLFollowCamMgr::getInstance()->setPosition(source_id, position);
-	}
-	if ( settingFocus )
-	{
-		LLFollowCamMgr::getInstance()->setFocus(source_id, focus);
-	}
-	if ( settingFocusOffset )
-	{
-		LLFollowCamMgr::getInstance()->setFocusOffset(source_id, focus_offset);
-	}
-}
-//end Ventrella 
+//end Ventrella
 
 
 // Culled from newsim lltask.cpp
 void process_name_value(LLMessageSystem *mesgsys, void **user_data)
 {
-	std::string	temp_str;
-	LLUUID	id;
-	S32		i, num_blocks;
+    std::string temp_str;
+    LLUUID  id;
+    S32     i, num_blocks;
 
-	mesgsys->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
+    mesgsys->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
 
-	LLViewerObject* object = gObjectList.findObject(id);
+    LLViewerObject* object = gObjectList.findObject(id);
 
-	if (object)
-	{
-		num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_NameValueData);
-		for (i = 0; i < num_blocks; i++)
-		{
-			mesgsys->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair, temp_str, i);
-			LL_INFOS("Messaging") << "Added to object Name Value: " << temp_str << LL_ENDL;
-			object->addNVPair(temp_str);
-		}
-	}
-	else
-	{
-		LL_INFOS("Messaging") << "Can't find object " << id << " to add name value pair" << LL_ENDL;
-	}
+    if (object)
+    {
+        num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_NameValueData);
+        for (i = 0; i < num_blocks; i++)
+        {
+            mesgsys->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair, temp_str, i);
+            LL_INFOS("Messaging") << "Added to object Name Value: " << temp_str << LL_ENDL;
+            object->addNVPair(temp_str);
+        }
+    }
+    else
+    {
+        LL_INFOS("Messaging") << "Can't find object " << id << " to add name value pair" << LL_ENDL;
+    }
 }
 
 void process_remove_name_value(LLMessageSystem *mesgsys, void **user_data)
 {
-	std::string	temp_str;
-	LLUUID	id;
-	S32		i, num_blocks;
+    std::string temp_str;
+    LLUUID  id;
+    S32     i, num_blocks;
 
-	mesgsys->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
+    mesgsys->getUUIDFast(_PREHASH_TaskData, _PREHASH_ID, id);
 
-	LLViewerObject* object = gObjectList.findObject(id);
+    LLViewerObject* object = gObjectList.findObject(id);
 
-	if (object)
-	{
-		num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_NameValueData);
-		for (i = 0; i < num_blocks; i++)
-		{
-			mesgsys->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair, temp_str, i);
-			LL_INFOS("Messaging") << "Removed from object Name Value: " << temp_str << LL_ENDL;
-			object->removeNVPair(temp_str);
-		}
-	}
-	else
-	{
-		LL_INFOS("Messaging") << "Can't find object " << id << " to remove name value pair" << LL_ENDL;
-	}
+    if (object)
+    {
+        num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_NameValueData);
+        for (i = 0; i < num_blocks; i++)
+        {
+            mesgsys->getStringFast(_PREHASH_NameValueData, _PREHASH_NVPair, temp_str, i);
+            LL_INFOS("Messaging") << "Removed from object Name Value: " << temp_str << LL_ENDL;
+            object->removeNVPair(temp_str);
+        }
+    }
+    else
+    {
+        LL_INFOS("Messaging") << "Can't find object " << id << " to remove name value pair" << LL_ENDL;
+    }
 }
 
 void process_kick_user(LLMessageSystem *msg, void** /*user_data*/)
 {
-	std::string message;
+    std::string message;
 
-	msg->getStringFast(_PREHASH_UserInfo, _PREHASH_Reason, message);
+    msg->getStringFast(_PREHASH_UserInfo, _PREHASH_Reason, message);
 
-	LLAppViewer::instance()->forceDisconnect(message);
+    LLAppViewer::instance()->forceDisconnect(message);
 }
 
 
 /*
 void process_user_list_reply(LLMessageSystem *msg, void **user_data)
 {
-	LLUserList::processUserListReply(msg, user_data);
-	return;
-	char	firstname[MAX_STRING+1];
-	char	lastname[MAX_STRING+1];
-	U8		status;
-	S32		user_count;
-
-	user_count = msg->getNumberOfBlocks("UserBlock");
-
-	for (S32 i = 0; i < user_count; i++)
-	{
-		msg->getData("UserBlock", i, "FirstName", firstname);
-		msg->getData("UserBlock", i, "LastName", lastname);
-		msg->getData("UserBlock", i, "Status", &status);
-
-		if (status & 0x01)
-		{
-			dialog_friends_add_friend(buffer, TRUE);
-		}
-		else
-		{
-			dialog_friends_add_friend(buffer, FALSE);
-		}
-	}
-
-	dialog_friends_done_adding();
+    LLUserList::processUserListReply(msg, user_data);
+    return;
+    char    firstname[MAX_STRING+1];
+    char    lastname[MAX_STRING+1];
+    U8      status;
+    S32     user_count;
+
+    user_count = msg->getNumberOfBlocks("UserBlock");
+
+    for (S32 i = 0; i < user_count; i++)
+    {
+        msg->getData("UserBlock", i, "FirstName", firstname);
+        msg->getData("UserBlock", i, "LastName", lastname);
+        msg->getData("UserBlock", i, "Status", &status);
+
+        if (status & 0x01)
+        {
+            dialog_friends_add_friend(buffer, TRUE);
+        }
+        else
+        {
+            dialog_friends_add_friend(buffer, FALSE);
+        }
+    }
+
+    dialog_friends_done_adding();
 }
 */
 
@@ -5004,163 +5004,163 @@ void process_user_list_reply(LLMessageSystem *msg, void **user_data)
 /*
 void process_time_dilation(LLMessageSystem *msg, void **user_data)
 {
-	// get the time_dilation
-	U16 foo;
-	msg->getData("TimeDilation", "TimeDilation", &foo);
-	F32 time_dilation = ((F32) foo) / 65535.f;
+    // get the time_dilation
+    U16 foo;
+    msg->getData("TimeDilation", "TimeDilation", &foo);
+    F32 time_dilation = ((F32) foo) / 65535.f;
 
-	// get the pointer to the right region
-	U32 ip = msg->getSenderIP();
-	U32 port = msg->getSenderPort();
-	LLViewerRegion *regionp = LLWorld::getInstance()->getRegion(ip, port);
-	if (regionp)
-	{
-		regionp->setTimeDilation(time_dilation);
-	}
+    // get the pointer to the right region
+    U32 ip = msg->getSenderIP();
+    U32 port = msg->getSenderPort();
+    LLViewerRegion *regionp = LLWorld::getInstance()->getRegion(ip, port);
+    if (regionp)
+    {
+        regionp->setTimeDilation(time_dilation);
+    }
 }
 */
 
 
 void process_money_balance_reply( LLMessageSystem* msg, void** )
 {
-	S32 balance = 0;
-	S32 credit = 0;
-	S32 committed = 0;
-	std::string desc;
-	LLUUID tid;
-
-	msg->getUUIDFast(_PREHASH_MoneyData, _PREHASH_TransactionID, tid);
-	msg->getS32Fast(_PREHASH_MoneyData, _PREHASH_MoneyBalance, balance);
-	msg->getS32Fast(_PREHASH_MoneyData, _PREHASH_SquareMetersCredit, credit);
-	msg->getS32Fast(_PREHASH_MoneyData, _PREHASH_SquareMetersCommitted, committed);
-	msg->getStringFast(_PREHASH_MoneyData, _PREHASH_Description, desc);
-	LL_INFOS("Messaging") << "L$, credit, committed: " << balance << " " << credit << " "
-			<< committed << LL_ENDL;
-    
-	if (gStatusBar)
-	{
-		gStatusBar->setBalance(balance);
-		gStatusBar->setLandCredit(credit);
-		gStatusBar->setLandCommitted(committed);
-	}
-
-	if (desc.empty()
-		|| !gSavedSettings.getBOOL("NotifyMoneyChange"))
-	{
-		// ...nothing to display
-		return;
-	}
-
-	// Suppress duplicate messages about the same transaction
-	static std::deque<LLUUID> recent;
-	if (std::find(recent.rbegin(), recent.rend(), tid) != recent.rend())
-	{
-		return;
-	}
-
-	// Once the 'recent' container gets large enough, chop some
-	// off the beginning.
-	const U32 MAX_LOOKBACK = 30;
-	const S32 POP_FRONT_SIZE = 12;
-	if(recent.size() > MAX_LOOKBACK)
-	{
-		LL_DEBUGS("Messaging") << "Removing oldest transaction records" << LL_ENDL;
-		recent.erase(recent.begin(), recent.begin() + POP_FRONT_SIZE);
-	}
-	//LL_DEBUGS("Messaging") << "Pushing back transaction " << tid << LL_ENDL;
-	recent.push_back(tid);
-
-	if (msg->hasFast(_PREHASH_TransactionInfo))
-	{
-		// ...message has extended info for localization
-		process_money_balance_reply_extended(msg);
-	}
-	else
-	{
-		// Only old dev grids will not supply the TransactionInfo block,
-		// so we can just use the hard-coded English string.
-		LLSD args;
-		args["MESSAGE"] = desc;
-		LLNotificationsUtil::add("SystemMessage", args);
-	}
+    S32 balance = 0;
+    S32 credit = 0;
+    S32 committed = 0;
+    std::string desc;
+    LLUUID tid;
+
+    msg->getUUIDFast(_PREHASH_MoneyData, _PREHASH_TransactionID, tid);
+    msg->getS32Fast(_PREHASH_MoneyData, _PREHASH_MoneyBalance, balance);
+    msg->getS32Fast(_PREHASH_MoneyData, _PREHASH_SquareMetersCredit, credit);
+    msg->getS32Fast(_PREHASH_MoneyData, _PREHASH_SquareMetersCommitted, committed);
+    msg->getStringFast(_PREHASH_MoneyData, _PREHASH_Description, desc);
+    LL_INFOS("Messaging") << "L$, credit, committed: " << balance << " " << credit << " "
+            << committed << LL_ENDL;
+
+    if (gStatusBar)
+    {
+        gStatusBar->setBalance(balance);
+        gStatusBar->setLandCredit(credit);
+        gStatusBar->setLandCommitted(committed);
+    }
+
+    if (desc.empty()
+        || !gSavedSettings.getBOOL("NotifyMoneyChange"))
+    {
+        // ...nothing to display
+        return;
+    }
+
+    // Suppress duplicate messages about the same transaction
+    static std::deque<LLUUID> recent;
+    if (std::find(recent.rbegin(), recent.rend(), tid) != recent.rend())
+    {
+        return;
+    }
+
+    // Once the 'recent' container gets large enough, chop some
+    // off the beginning.
+    const U32 MAX_LOOKBACK = 30;
+    const S32 POP_FRONT_SIZE = 12;
+    if(recent.size() > MAX_LOOKBACK)
+    {
+        LL_DEBUGS("Messaging") << "Removing oldest transaction records" << LL_ENDL;
+        recent.erase(recent.begin(), recent.begin() + POP_FRONT_SIZE);
+    }
+    //LL_DEBUGS("Messaging") << "Pushing back transaction " << tid << LL_ENDL;
+    recent.push_back(tid);
+
+    if (msg->hasFast(_PREHASH_TransactionInfo))
+    {
+        // ...message has extended info for localization
+        process_money_balance_reply_extended(msg);
+    }
+    else
+    {
+        // Only old dev grids will not supply the TransactionInfo block,
+        // so we can just use the hard-coded English string.
+        LLSD args;
+        args["MESSAGE"] = desc;
+        LLNotificationsUtil::add("SystemMessage", args);
+    }
 }
 
 static std::string reason_from_transaction_type(S32 transaction_type,
-												const std::string& item_desc)
-{
-	// *NOTE: The keys for the reason strings are unusual because
-	// an earlier version of the code used English language strings
-	// extracted from hard-coded server English descriptions.
-	// Keeping them so we don't have to re-localize them.
-	switch (transaction_type)
-	{
-		case TRANS_OBJECT_SALE:
-		{
-			LLStringUtil::format_map_t arg;
-			arg["ITEM"] = item_desc;
-			return LLTrans::getString("for item", arg);
-		}
-		case TRANS_LAND_SALE:
-			return LLTrans::getString("for a parcel of land");
-			
-		case TRANS_LAND_PASS_SALE:
-			return LLTrans::getString("for a land access pass");
-			
-		case TRANS_GROUP_LAND_DEED:
-			return LLTrans::getString("for deeding land");
-			
-		case TRANS_GROUP_CREATE:
-			return LLTrans::getString("to create a group");
-			
-		case TRANS_GROUP_JOIN:
-			return LLTrans::getString("to join a group");
-			
-		case TRANS_UPLOAD_CHARGE:
-			return LLTrans::getString("to upload");
-
-		case TRANS_CLASSIFIED_CHARGE:
-			return LLTrans::getString("to publish a classified ad");
-			
-		case TRANS_GIFT:
-			// Simulator returns "Payment" if no custom description has been entered
-			return (item_desc == "Payment" ? std::string() : item_desc);
-
-		// These have no reason to display, but are expected and should not
-		// generate warnings
-		case TRANS_PAY_OBJECT:
-		case TRANS_OBJECT_PAYS:
-			return std::string();
-
-		default:
-			LL_WARNS() << "Unknown transaction type " 
-				<< transaction_type << LL_ENDL;
-			return std::string();
-	}
+                                                const std::string& item_desc)
+{
+    // *NOTE: The keys for the reason strings are unusual because
+    // an earlier version of the code used English language strings
+    // extracted from hard-coded server English descriptions.
+    // Keeping them so we don't have to re-localize them.
+    switch (transaction_type)
+    {
+        case TRANS_OBJECT_SALE:
+        {
+            LLStringUtil::format_map_t arg;
+            arg["ITEM"] = item_desc;
+            return LLTrans::getString("for item", arg);
+        }
+        case TRANS_LAND_SALE:
+            return LLTrans::getString("for a parcel of land");
+
+        case TRANS_LAND_PASS_SALE:
+            return LLTrans::getString("for a land access pass");
+
+        case TRANS_GROUP_LAND_DEED:
+            return LLTrans::getString("for deeding land");
+
+        case TRANS_GROUP_CREATE:
+            return LLTrans::getString("to create a group");
+
+        case TRANS_GROUP_JOIN:
+            return LLTrans::getString("to join a group");
+
+        case TRANS_UPLOAD_CHARGE:
+            return LLTrans::getString("to upload");
+
+        case TRANS_CLASSIFIED_CHARGE:
+            return LLTrans::getString("to publish a classified ad");
+
+        case TRANS_GIFT:
+            // Simulator returns "Payment" if no custom description has been entered
+            return (item_desc == "Payment" ? std::string() : item_desc);
+
+        // These have no reason to display, but are expected and should not
+        // generate warnings
+        case TRANS_PAY_OBJECT:
+        case TRANS_OBJECT_PAYS:
+            return std::string();
+
+        default:
+            LL_WARNS() << "Unknown transaction type "
+                << transaction_type << LL_ENDL;
+            return std::string();
+    }
 }
 
 static void money_balance_group_notify(const LLUUID& group_id,
-									   const std::string& name,
-									   bool is_group,
-									   std::string notification,
-									   LLSD args,
-									   LLSD payload)
+                                       const std::string& name,
+                                       bool is_group,
+                                       std::string notification,
+                                       LLSD args,
+                                       LLSD payload)
 {
-	// Message uses name SLURLs, don't actually have to substitute in
-	// the name.  We're just making sure it's available.
-	// Notification is either PaymentReceived or PaymentSent
-	LLNotificationsUtil::add(notification, args, payload);
+    // Message uses name SLURLs, don't actually have to substitute in
+    // the name.  We're just making sure it's available.
+    // Notification is either PaymentReceived or PaymentSent
+    LLNotificationsUtil::add(notification, args, payload);
 }
 
 static void money_balance_avatar_notify(const LLUUID& agent_id,
-										const LLAvatarName& av_name,
-									   	std::string notification,
-									   	LLSD args,
-									   	LLSD payload)
+                                        const LLAvatarName& av_name,
+                                        std::string notification,
+                                        LLSD args,
+                                        LLSD payload)
 {
-	// Message uses name SLURLs, don't actually have to substitute in
-	// the name.  We're just making sure it's available.
-	// Notification is either PaymentReceived or PaymentSent
-	LLNotificationsUtil::add(notification, args, payload);
+    // Message uses name SLURLs, don't actually have to substitute in
+    // the name.  We're just making sure it's available.
+    // Notification is either PaymentReceived or PaymentSent
+    LLNotificationsUtil::add(notification, args, payload);
 }
 
 static void process_money_balance_reply_extended(LLMessageSystem* msg)
@@ -5169,516 +5169,516 @@ static void process_money_balance_reply_extended(LLMessageSystem* msg)
     // and agent ids for name lookup.
     S32 transaction_type = 0;
     LLUUID source_id;
-	BOOL is_source_group = FALSE;
+    BOOL is_source_group = FALSE;
     LLUUID dest_id;
-	BOOL is_dest_group = FALSE;
+    BOOL is_dest_group = FALSE;
     S32 amount = 0;
     std::string item_description;
-	BOOL success = FALSE;
+    BOOL success = FALSE;
 
     msg->getS32Fast(_PREHASH_TransactionInfo, _PREHASH_TransactionType, transaction_type);
     msg->getUUIDFast(_PREHASH_TransactionInfo, _PREHASH_SourceID, source_id);
-	msg->getBOOLFast(_PREHASH_TransactionInfo, _PREHASH_IsSourceGroup, is_source_group);
+    msg->getBOOLFast(_PREHASH_TransactionInfo, _PREHASH_IsSourceGroup, is_source_group);
     msg->getUUIDFast(_PREHASH_TransactionInfo, _PREHASH_DestID, dest_id);
-	msg->getBOOLFast(_PREHASH_TransactionInfo, _PREHASH_IsDestGroup, is_dest_group);
+    msg->getBOOLFast(_PREHASH_TransactionInfo, _PREHASH_IsDestGroup, is_dest_group);
     msg->getS32Fast(_PREHASH_TransactionInfo, _PREHASH_Amount, amount);
     msg->getStringFast(_PREHASH_TransactionInfo, _PREHASH_ItemDescription, item_description);
-	msg->getBOOLFast(_PREHASH_MoneyData, _PREHASH_TransactionSuccess, success);
-    LL_INFOS("Money") << "MoneyBalanceReply source " << source_id 
-		<< " dest " << dest_id
-		<< " type " << transaction_type
-		<< " item " << item_description << LL_ENDL;
-
-	if (source_id.isNull() && dest_id.isNull())
-	{
-		// this is a pure balance update, no notification required
-		return;
-	}
-
-	std::string source_slurl;
-	if (is_source_group)
-	{
-		source_slurl =
-			LLSLURL( "group", source_id, "inspect").getSLURLString();
-	}
-	else
-	{
-		source_slurl =
-			LLSLURL( "agent", source_id, "completename").getSLURLString();
-	}
-
-	std::string dest_slurl;
-	if (is_dest_group)
-	{
-		dest_slurl =
-			LLSLURL( "group", dest_id, "inspect").getSLURLString();
-	}
-	else
-	{
-		dest_slurl =
-			LLSLURL( "agent", dest_id, "completename").getSLURLString();
-	}
-
-	std::string reason =
-		reason_from_transaction_type(transaction_type, item_description);
-	
-	LLStringUtil::format_map_t args;
-	args["REASON"] = reason; // could be empty
-	args["AMOUNT"] = llformat("%d", amount);
-	
-	// Need to delay until name looked up, so need to know whether or not
-	// is group
-	bool is_name_group = false;
-	LLUUID name_id;
-	std::string message;
-	std::string notification;
-	LLSD final_args;
-	LLSD payload;
-	
-	bool you_paid_someone = (source_id == gAgentID);
-	std::string gift_suffix = (transaction_type == TRANS_GIFT ? "_gift" : "");
-	if (you_paid_someone)
-	{
-		if(!gSavedSettings.getBOOL("NotifyMoneySpend"))
-		{
-			return;
-		}
-		args["NAME"] = dest_slurl;
-		is_name_group = is_dest_group;
-		name_id = dest_id;
-		if (!reason.empty())
-		{
-			if (dest_id.notNull())
-			{
-				message = success ? LLTrans::getString("you_paid_ldollars" + gift_suffix, args) :
-									LLTrans::getString("you_paid_failure_ldollars" + gift_suffix, args);
-			}
-			else
-			{
-				// transaction fee to the system, eg, to create a group
-				message = success ? LLTrans::getString("you_paid_ldollars_no_name", args) :
-									LLTrans::getString("you_paid_failure_ldollars_no_name", args);
-			}
-		}
-		else
-		{
-			if (dest_id.notNull())
-			{
-				message = success ? LLTrans::getString("you_paid_ldollars_no_reason", args) :
-									LLTrans::getString("you_paid_failure_ldollars_no_reason", args);
-			}
-			else
-			{
-				// no target, no reason, you just paid money
-				message = success ? LLTrans::getString("you_paid_ldollars_no_info", args) :
-									LLTrans::getString("you_paid_failure_ldollars_no_info", args);
-			}
-		}
-		final_args["MESSAGE"] = message;
-		payload["dest_id"] = dest_id;
-		notification = success ? "PaymentSent" : "PaymentFailure";
-	}
-	else
-	{
-		// ...someone paid you
-		if(!gSavedSettings.getBOOL("NotifyMoneyReceived"))
-		{
-			return;
-		}
-		args["NAME"] = source_slurl;
-		is_name_group = is_source_group;
-		name_id = source_id;
-
-		if (!reason.empty() && !LLMuteList::getInstance()->isMuted(source_id))
-		{
-			message = LLTrans::getString("paid_you_ldollars" + gift_suffix, args);
-		}
-		else
-		{
-			message = LLTrans::getString("paid_you_ldollars_no_reason", args);
-		}
-		final_args["MESSAGE"] = message;
-
-		// make notification loggable
-		payload["from_id"] = source_id;
-		notification = "PaymentReceived";
-	}
-
-	// Despite using SLURLs, wait until the name is available before
-	// showing the notification, otherwise the UI layout is strange and
-	// the user sees a "Loading..." message
-	if (is_name_group)
-	{
-		gCacheName->getGroup(name_id,
-						boost::bind(&money_balance_group_notify,
-									_1, _2, _3,
-									notification, final_args, payload));
-	}
-	else 
-	{
-		LLAvatarNameCache::get(name_id, boost::bind(&money_balance_avatar_notify, _1, _2, notification, final_args, payload));										   
-	}
+    msg->getBOOLFast(_PREHASH_MoneyData, _PREHASH_TransactionSuccess, success);
+    LL_INFOS("Money") << "MoneyBalanceReply source " << source_id
+        << " dest " << dest_id
+        << " type " << transaction_type
+        << " item " << item_description << LL_ENDL;
+
+    if (source_id.isNull() && dest_id.isNull())
+    {
+        // this is a pure balance update, no notification required
+        return;
+    }
+
+    std::string source_slurl;
+    if (is_source_group)
+    {
+        source_slurl =
+            LLSLURL( "group", source_id, "inspect").getSLURLString();
+    }
+    else
+    {
+        source_slurl =
+            LLSLURL( "agent", source_id, "completename").getSLURLString();
+    }
+
+    std::string dest_slurl;
+    if (is_dest_group)
+    {
+        dest_slurl =
+            LLSLURL( "group", dest_id, "inspect").getSLURLString();
+    }
+    else
+    {
+        dest_slurl =
+            LLSLURL( "agent", dest_id, "completename").getSLURLString();
+    }
+
+    std::string reason =
+        reason_from_transaction_type(transaction_type, item_description);
+
+    LLStringUtil::format_map_t args;
+    args["REASON"] = reason; // could be empty
+    args["AMOUNT"] = llformat("%d", amount);
+
+    // Need to delay until name looked up, so need to know whether or not
+    // is group
+    bool is_name_group = false;
+    LLUUID name_id;
+    std::string message;
+    std::string notification;
+    LLSD final_args;
+    LLSD payload;
+
+    bool you_paid_someone = (source_id == gAgentID);
+    std::string gift_suffix = (transaction_type == TRANS_GIFT ? "_gift" : "");
+    if (you_paid_someone)
+    {
+        if(!gSavedSettings.getBOOL("NotifyMoneySpend"))
+        {
+            return;
+        }
+        args["NAME"] = dest_slurl;
+        is_name_group = is_dest_group;
+        name_id = dest_id;
+        if (!reason.empty())
+        {
+            if (dest_id.notNull())
+            {
+                message = success ? LLTrans::getString("you_paid_ldollars" + gift_suffix, args) :
+                                    LLTrans::getString("you_paid_failure_ldollars" + gift_suffix, args);
+            }
+            else
+            {
+                // transaction fee to the system, eg, to create a group
+                message = success ? LLTrans::getString("you_paid_ldollars_no_name", args) :
+                                    LLTrans::getString("you_paid_failure_ldollars_no_name", args);
+            }
+        }
+        else
+        {
+            if (dest_id.notNull())
+            {
+                message = success ? LLTrans::getString("you_paid_ldollars_no_reason", args) :
+                                    LLTrans::getString("you_paid_failure_ldollars_no_reason", args);
+            }
+            else
+            {
+                // no target, no reason, you just paid money
+                message = success ? LLTrans::getString("you_paid_ldollars_no_info", args) :
+                                    LLTrans::getString("you_paid_failure_ldollars_no_info", args);
+            }
+        }
+        final_args["MESSAGE"] = message;
+        payload["dest_id"] = dest_id;
+        notification = success ? "PaymentSent" : "PaymentFailure";
+    }
+    else
+    {
+        // ...someone paid you
+        if(!gSavedSettings.getBOOL("NotifyMoneyReceived"))
+        {
+            return;
+        }
+        args["NAME"] = source_slurl;
+        is_name_group = is_source_group;
+        name_id = source_id;
+
+        if (!reason.empty() && !LLMuteList::getInstance()->isMuted(source_id))
+        {
+            message = LLTrans::getString("paid_you_ldollars" + gift_suffix, args);
+        }
+        else
+        {
+            message = LLTrans::getString("paid_you_ldollars_no_reason", args);
+        }
+        final_args["MESSAGE"] = message;
+
+        // make notification loggable
+        payload["from_id"] = source_id;
+        notification = "PaymentReceived";
+    }
+
+    // Despite using SLURLs, wait until the name is available before
+    // showing the notification, otherwise the UI layout is strange and
+    // the user sees a "Loading..." message
+    if (is_name_group)
+    {
+        gCacheName->getGroup(name_id,
+                        boost::bind(&money_balance_group_notify,
+                                    _1, _2, _3,
+                                    notification, final_args, payload));
+    }
+    else
+    {
+        LLAvatarNameCache::get(name_id, boost::bind(&money_balance_avatar_notify, _1, _2, notification, final_args, payload));
+    }
 }
 
 bool handle_prompt_for_maturity_level_change_callback(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 
-	if (0 == option)
-	{
-		// set the preference to the maturity of the region we're calling
-		U8 preferredMaturity = static_cast<U8>(notification["payload"]["_region_access"].asInteger());
-		gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(preferredMaturity));
-	}
+    if (0 == option)
+    {
+        // set the preference to the maturity of the region we're calling
+        U8 preferredMaturity = static_cast<U8>(notification["payload"]["_region_access"].asInteger());
+        gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(preferredMaturity));
+    }
 
-	return false;
+    return false;
 }
 
 bool handle_prompt_for_maturity_level_change_and_reteleport_callback(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	
-	if (0 == option)
-	{
-		// set the preference to the maturity of the region we're calling
-		U8 preferredMaturity = static_cast<U8>(notification["payload"]["_region_access"].asInteger());
-		gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(preferredMaturity));
-		gAgent.setMaturityRatingChangeDuringTeleport(preferredMaturity);
-		gAgent.restartFailedTeleportRequest();
-	}
-	else
-	{
-		gAgent.clearTeleportRequest();
-	}
-	
-	return false;
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+
+    if (0 == option)
+    {
+        // set the preference to the maturity of the region we're calling
+        U8 preferredMaturity = static_cast<U8>(notification["payload"]["_region_access"].asInteger());
+        gSavedSettings.setU32("PreferredMaturity", static_cast<U32>(preferredMaturity));
+        gAgent.setMaturityRatingChangeDuringTeleport(preferredMaturity);
+        gAgent.restartFailedTeleportRequest();
+    }
+    else
+    {
+        gAgent.clearTeleportRequest();
+    }
+
+    return false;
 }
 
 // some of the server notifications need special handling. This is where we do that.
 bool handle_special_notification(std::string notificationID, LLSD& llsdBlock)
 {
-	bool returnValue = false;
-	if(llsdBlock.has("_region_access"))
-	{
-		U8 regionAccess = static_cast<U8>(llsdBlock["_region_access"].asInteger());
-		std::string regionMaturity = LLViewerRegion::accessToString(regionAccess);
-		LLStringUtil::toLower(regionMaturity);
-		llsdBlock["REGIONMATURITY"] = regionMaturity;
-		LLNotificationPtr maturityLevelNotification;
-		std::string notifySuffix = "_Notify";
-		if (regionAccess == SIM_ACCESS_MATURE)
-		{
-			if (gAgent.isTeen())
-			{
-				gAgent.clearTeleportRequest();
-				maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_AdultsOnlyContent", llsdBlock);
-				returnValue = true;
-
-				notifySuffix = "_NotifyAdultsOnly";
-			}
-			else if (gAgent.prefersPG())
-			{
-				maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_Change", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
-				returnValue = true;
-			}
-			else if (LLStringUtil::compareStrings(notificationID, "RegionEntryAccessBlocked") == 0)
-			{
-				maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_PreferencesOutOfSync", llsdBlock, llsdBlock);
-				returnValue = true;
-			}
-		}
-		else if (regionAccess == SIM_ACCESS_ADULT)
-		{
-			if (!gAgent.isAdult())
-			{
-				gAgent.clearTeleportRequest();
-				maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_AdultsOnlyContent", llsdBlock);
-				returnValue = true;
-
-				notifySuffix = "_NotifyAdultsOnly";
-			}
-			else if (gAgent.prefersPG() || gAgent.prefersMature())
-			{
-				maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_Change", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
-				returnValue = true;
-			}
-			else if (LLStringUtil::compareStrings(notificationID, "RegionEntryAccessBlocked") == 0)
-			{
-				maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_PreferencesOutOfSync", llsdBlock, llsdBlock);
-				returnValue = true;
-			}
-		}
-
-		if ((maturityLevelNotification == NULL) || maturityLevelNotification->isIgnored())
-		{
-			// Given a simple notification if no maturityLevelNotification is set or it is ignore
-			LLNotificationsUtil::add(notificationID + notifySuffix, llsdBlock);
-		}
-	}
-
-	return returnValue;
+    bool returnValue = false;
+    if(llsdBlock.has("_region_access"))
+    {
+        U8 regionAccess = static_cast<U8>(llsdBlock["_region_access"].asInteger());
+        std::string regionMaturity = LLViewerRegion::accessToString(regionAccess);
+        LLStringUtil::toLower(regionMaturity);
+        llsdBlock["REGIONMATURITY"] = regionMaturity;
+        LLNotificationPtr maturityLevelNotification;
+        std::string notifySuffix = "_Notify";
+        if (regionAccess == SIM_ACCESS_MATURE)
+        {
+            if (gAgent.isTeen())
+            {
+                gAgent.clearTeleportRequest();
+                maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_AdultsOnlyContent", llsdBlock);
+                returnValue = true;
+
+                notifySuffix = "_NotifyAdultsOnly";
+            }
+            else if (gAgent.prefersPG())
+            {
+                maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_Change", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
+                returnValue = true;
+            }
+            else if (LLStringUtil::compareStrings(notificationID, "RegionEntryAccessBlocked") == 0)
+            {
+                maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_PreferencesOutOfSync", llsdBlock, llsdBlock);
+                returnValue = true;
+            }
+        }
+        else if (regionAccess == SIM_ACCESS_ADULT)
+        {
+            if (!gAgent.isAdult())
+            {
+                gAgent.clearTeleportRequest();
+                maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_AdultsOnlyContent", llsdBlock);
+                returnValue = true;
+
+                notifySuffix = "_NotifyAdultsOnly";
+            }
+            else if (gAgent.prefersPG() || gAgent.prefersMature())
+            {
+                maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_Change", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
+                returnValue = true;
+            }
+            else if (LLStringUtil::compareStrings(notificationID, "RegionEntryAccessBlocked") == 0)
+            {
+                maturityLevelNotification = LLNotificationsUtil::add(notificationID+"_PreferencesOutOfSync", llsdBlock, llsdBlock);
+                returnValue = true;
+            }
+        }
+
+        if ((maturityLevelNotification == NULL) || maturityLevelNotification->isIgnored())
+        {
+            // Given a simple notification if no maturityLevelNotification is set or it is ignore
+            LLNotificationsUtil::add(notificationID + notifySuffix, llsdBlock);
+        }
+    }
+
+    return returnValue;
 }
 
 bool handle_trusted_experiences_notification(const LLSD& llsdBlock)
 {
-	if(llsdBlock.has("trusted_experiences"))
-	{
-		std::ostringstream str;
-		const LLSD& experiences = llsdBlock["trusted_experiences"];
-		LLSD::array_const_iterator it = experiences.beginArray();
-		for(/**/; it != experiences.endArray(); ++it)
-		{
-			str<<LLSLURL("experience", it->asUUID(), "profile").getSLURLString() << "\n";
-		}
-		std::string str_list = str.str();
-		if(!str_list.empty())
-		{
-			LLNotificationsUtil::add("TrustedExperiencesAvailable", LLSD::emptyMap().with("EXPERIENCE_LIST", (LLSD)str_list));
-			return true;
-		}
-	}
-	return false;
+    if(llsdBlock.has("trusted_experiences"))
+    {
+        std::ostringstream str;
+        const LLSD& experiences = llsdBlock["trusted_experiences"];
+        LLSD::array_const_iterator it = experiences.beginArray();
+        for(/**/; it != experiences.endArray(); ++it)
+        {
+            str<<LLSLURL("experience", it->asUUID(), "profile").getSLURLString() << "\n";
+        }
+        std::string str_list = str.str();
+        if(!str_list.empty())
+        {
+            LLNotificationsUtil::add("TrustedExperiencesAvailable", LLSD::emptyMap().with("EXPERIENCE_LIST", (LLSD)str_list));
+            return true;
+        }
+    }
+    return false;
 }
 
 // some of the server notifications need special handling. This is where we do that.
 bool handle_teleport_access_blocked(LLSD& llsdBlock, const std::string & notificationID, const std::string & defaultMessage)
 {
-	bool returnValue = false;
-	if(llsdBlock.has("_region_access"))
-	{
-		U8 regionAccess = static_cast<U8>(llsdBlock["_region_access"].asInteger());
-		std::string regionMaturity = LLViewerRegion::accessToString(regionAccess);
-		LLStringUtil::toLower(regionMaturity);
-		llsdBlock["REGIONMATURITY"] = regionMaturity;
-
-		LLNotificationPtr tp_failure_notification;
-		std::string notifySuffix;
-
-		if (notificationID == std::string("TeleportEntryAccessBlocked"))
-		{
-			notifySuffix = "_Notify";
-			if (regionAccess == SIM_ACCESS_MATURE)
-			{
-				if (gAgent.isTeen())
-				{
-					gAgent.clearTeleportRequest();
-					tp_failure_notification = LLNotificationsUtil::add(notificationID+"_AdultsOnlyContent", llsdBlock);
-					returnValue = true;
-
-					notifySuffix = "_NotifyAdultsOnly";
-				}
-				else if (gAgent.prefersPG())
-				{
-					if (gAgent.hasRestartableFailedTeleportRequest())
-					{
-						tp_failure_notification = LLNotificationsUtil::add(notificationID+"_ChangeAndReTeleport", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_and_reteleport_callback);
-						returnValue = true;
-					}
-					else
-					{
-						gAgent.clearTeleportRequest();
-						tp_failure_notification = LLNotificationsUtil::add(notificationID+"_Change", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
-						returnValue = true;
-					}
-				}
-				else
-				{
-					gAgent.clearTeleportRequest();
-					tp_failure_notification = LLNotificationsUtil::add(notificationID+"_PreferencesOutOfSync", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
-					returnValue = true;
-				}
-			}
-			else if (regionAccess == SIM_ACCESS_ADULT)
-			{
-				if (!gAgent.isAdult())
-				{
-					gAgent.clearTeleportRequest();
-					tp_failure_notification = LLNotificationsUtil::add(notificationID+"_AdultsOnlyContent", llsdBlock);
-					returnValue = true;
-
-					notifySuffix = "_NotifyAdultsOnly";
-				}
-				else if (gAgent.prefersPG() || gAgent.prefersMature())
-				{
-					if (gAgent.hasRestartableFailedTeleportRequest())
-					{
-						tp_failure_notification = LLNotificationsUtil::add(notificationID+"_ChangeAndReTeleport", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_and_reteleport_callback);
-						returnValue = true;
-					}
-					else
-					{
-						gAgent.clearTeleportRequest();
-						tp_failure_notification = LLNotificationsUtil::add(notificationID+"_Change", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
-						returnValue = true;
-					}
-				}
-				else
-				{
-					gAgent.clearTeleportRequest();
-					tp_failure_notification = LLNotificationsUtil::add(notificationID+"_PreferencesOutOfSync", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
-					returnValue = true;
-				}
-			}
-		}		// End of special handling for "TeleportEntryAccessBlocked"
-		else
-		{	// Normal case, no message munging
-			gAgent.clearTeleportRequest();
-			if (LLNotifications::getInstance()->templateExists(notificationID))
-			{
-				tp_failure_notification = LLNotificationsUtil::add(notificationID, llsdBlock, llsdBlock);
-			}
-			else
-			{
-				llsdBlock["MESSAGE"] = defaultMessage;
-				tp_failure_notification = LLNotificationsUtil::add("GenericAlertOK", llsdBlock);
-			}
-			returnValue = true;
-		}
-
-		if ((tp_failure_notification == NULL) || tp_failure_notification->isIgnored())
-		{
-			// Given a simple notification if no tp_failure_notification is set or it is ignore
-			LLNotificationsUtil::add(notificationID + notifySuffix, llsdBlock);
-		}
-	}
-
-	handle_trusted_experiences_notification(llsdBlock);
-	return returnValue;
+    bool returnValue = false;
+    if(llsdBlock.has("_region_access"))
+    {
+        U8 regionAccess = static_cast<U8>(llsdBlock["_region_access"].asInteger());
+        std::string regionMaturity = LLViewerRegion::accessToString(regionAccess);
+        LLStringUtil::toLower(regionMaturity);
+        llsdBlock["REGIONMATURITY"] = regionMaturity;
+
+        LLNotificationPtr tp_failure_notification;
+        std::string notifySuffix;
+
+        if (notificationID == std::string("TeleportEntryAccessBlocked"))
+        {
+            notifySuffix = "_Notify";
+            if (regionAccess == SIM_ACCESS_MATURE)
+            {
+                if (gAgent.isTeen())
+                {
+                    gAgent.clearTeleportRequest();
+                    tp_failure_notification = LLNotificationsUtil::add(notificationID+"_AdultsOnlyContent", llsdBlock);
+                    returnValue = true;
+
+                    notifySuffix = "_NotifyAdultsOnly";
+                }
+                else if (gAgent.prefersPG())
+                {
+                    if (gAgent.hasRestartableFailedTeleportRequest())
+                    {
+                        tp_failure_notification = LLNotificationsUtil::add(notificationID+"_ChangeAndReTeleport", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_and_reteleport_callback);
+                        returnValue = true;
+                    }
+                    else
+                    {
+                        gAgent.clearTeleportRequest();
+                        tp_failure_notification = LLNotificationsUtil::add(notificationID+"_Change", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
+                        returnValue = true;
+                    }
+                }
+                else
+                {
+                    gAgent.clearTeleportRequest();
+                    tp_failure_notification = LLNotificationsUtil::add(notificationID+"_PreferencesOutOfSync", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
+                    returnValue = true;
+                }
+            }
+            else if (regionAccess == SIM_ACCESS_ADULT)
+            {
+                if (!gAgent.isAdult())
+                {
+                    gAgent.clearTeleportRequest();
+                    tp_failure_notification = LLNotificationsUtil::add(notificationID+"_AdultsOnlyContent", llsdBlock);
+                    returnValue = true;
+
+                    notifySuffix = "_NotifyAdultsOnly";
+                }
+                else if (gAgent.prefersPG() || gAgent.prefersMature())
+                {
+                    if (gAgent.hasRestartableFailedTeleportRequest())
+                    {
+                        tp_failure_notification = LLNotificationsUtil::add(notificationID+"_ChangeAndReTeleport", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_and_reteleport_callback);
+                        returnValue = true;
+                    }
+                    else
+                    {
+                        gAgent.clearTeleportRequest();
+                        tp_failure_notification = LLNotificationsUtil::add(notificationID+"_Change", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
+                        returnValue = true;
+                    }
+                }
+                else
+                {
+                    gAgent.clearTeleportRequest();
+                    tp_failure_notification = LLNotificationsUtil::add(notificationID+"_PreferencesOutOfSync", llsdBlock, llsdBlock, handle_prompt_for_maturity_level_change_callback);
+                    returnValue = true;
+                }
+            }
+        }       // End of special handling for "TeleportEntryAccessBlocked"
+        else
+        {   // Normal case, no message munging
+            gAgent.clearTeleportRequest();
+            if (LLNotifications::getInstance()->templateExists(notificationID))
+            {
+                tp_failure_notification = LLNotificationsUtil::add(notificationID, llsdBlock, llsdBlock);
+            }
+            else
+            {
+                llsdBlock["MESSAGE"] = defaultMessage;
+                tp_failure_notification = LLNotificationsUtil::add("GenericAlertOK", llsdBlock);
+            }
+            returnValue = true;
+        }
+
+        if ((tp_failure_notification == NULL) || tp_failure_notification->isIgnored())
+        {
+            // Given a simple notification if no tp_failure_notification is set or it is ignore
+            LLNotificationsUtil::add(notificationID + notifySuffix, llsdBlock);
+        }
+    }
+
+    handle_trusted_experiences_notification(llsdBlock);
+    return returnValue;
 }
 
 bool attempt_standard_notification(LLMessageSystem* msgsystem)
 {
-	// if we have additional alert data
-	if (msgsystem->has(_PREHASH_AlertInfo) && msgsystem->getNumberOfBlocksFast(_PREHASH_AlertInfo) > 0)
-	{
-		// notification was specified using the new mechanism, so we can just handle it here
-		std::string notificationID;
-		msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, notificationID);
-
-		//SL-13824 skip notification when both joining a group and leaving a group
-		//remove this after server stops sending these messages  
-		if (notificationID == "JoinGroupSuccess" ||
-			notificationID == "GroupDepart")
-		{
-			return true;
-		}
-
-		if (!LLNotifications::getInstance()->templateExists(notificationID))
-		{
-			return false;
-		}
-
-		std::string llsdRaw;
-		LLSD llsdBlock;
-		msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, notificationID);
-		msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams, llsdRaw);
-		if (llsdRaw.length())
-		{
-			std::istringstream llsdData(llsdRaw);
-			if (!LLSDSerialize::deserialize(llsdBlock, llsdData, llsdRaw.length()))
-			{
-				LL_WARNS() << "attempt_standard_notification: Attempted to read notification parameter data into LLSD but failed:" << llsdRaw << LL_ENDL;
-			}
-		}
-
-
-		handle_trusted_experiences_notification(llsdBlock);
-		
-		if (
-			(notificationID == "RegionEntryAccessBlocked") ||
-			(notificationID == "LandClaimAccessBlocked") ||
-			(notificationID == "LandBuyAccessBlocked")
-
-		   )
-		{
-			/*---------------------------------------------------------------------
-			 (Commented so a grep will find the notification strings, since
-			 we construct them on the fly; if you add additional notifications,
-			 please update the comment.)
-			 
-			 Could throw any of the following notifications:
-			 
-				RegionEntryAccessBlocked
-				RegionEntryAccessBlocked_Notify
-				RegionEntryAccessBlocked_NotifyAdultsOnly
-				RegionEntryAccessBlocked_Change
-				RegionEntryAccessBlocked_AdultsOnlyContent
-				RegionEntryAccessBlocked_ChangeAndReTeleport
-				LandClaimAccessBlocked 
-				LandClaimAccessBlocked_Notify 
-				LandClaimAccessBlocked_NotifyAdultsOnly
-				LandClaimAccessBlocked_Change 
-				LandClaimAccessBlocked_AdultsOnlyContent 
-				LandBuyAccessBlocked
-				LandBuyAccessBlocked_Notify
-				LandBuyAccessBlocked_NotifyAdultsOnly
-				LandBuyAccessBlocked_Change
-				LandBuyAccessBlocked_AdultsOnlyContent
-			 
-			-----------------------------------------------------------------------*/ 
+    // if we have additional alert data
+    if (msgsystem->has(_PREHASH_AlertInfo) && msgsystem->getNumberOfBlocksFast(_PREHASH_AlertInfo) > 0)
+    {
+        // notification was specified using the new mechanism, so we can just handle it here
+        std::string notificationID;
+        msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, notificationID);
+
+        //SL-13824 skip notification when both joining a group and leaving a group
+        //remove this after server stops sending these messages
+        if (notificationID == "JoinGroupSuccess" ||
+            notificationID == "GroupDepart")
+        {
+            return true;
+        }
+
+        if (!LLNotifications::getInstance()->templateExists(notificationID))
+        {
+            return false;
+        }
+
+        std::string llsdRaw;
+        LLSD llsdBlock;
+        msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, notificationID);
+        msgsystem->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams, llsdRaw);
+        if (llsdRaw.length())
+        {
+            std::istringstream llsdData(llsdRaw);
+            if (!LLSDSerialize::deserialize(llsdBlock, llsdData, llsdRaw.length()))
+            {
+                LL_WARNS() << "attempt_standard_notification: Attempted to read notification parameter data into LLSD but failed:" << llsdRaw << LL_ENDL;
+            }
+        }
+
+
+        handle_trusted_experiences_notification(llsdBlock);
+
+        if (
+            (notificationID == "RegionEntryAccessBlocked") ||
+            (notificationID == "LandClaimAccessBlocked") ||
+            (notificationID == "LandBuyAccessBlocked")
+
+           )
+        {
+            /*---------------------------------------------------------------------
+             (Commented so a grep will find the notification strings, since
+             we construct them on the fly; if you add additional notifications,
+             please update the comment.)
+
+             Could throw any of the following notifications:
+
+                RegionEntryAccessBlocked
+                RegionEntryAccessBlocked_Notify
+                RegionEntryAccessBlocked_NotifyAdultsOnly
+                RegionEntryAccessBlocked_Change
+                RegionEntryAccessBlocked_AdultsOnlyContent
+                RegionEntryAccessBlocked_ChangeAndReTeleport
+                LandClaimAccessBlocked
+                LandClaimAccessBlocked_Notify
+                LandClaimAccessBlocked_NotifyAdultsOnly
+                LandClaimAccessBlocked_Change
+                LandClaimAccessBlocked_AdultsOnlyContent
+                LandBuyAccessBlocked
+                LandBuyAccessBlocked_Notify
+                LandBuyAccessBlocked_NotifyAdultsOnly
+                LandBuyAccessBlocked_Change
+                LandBuyAccessBlocked_AdultsOnlyContent
+
+            -----------------------------------------------------------------------*/
             static LLCachedControl<S32> ban_lines_mode(gSavedSettings , "ShowBanLines" , LLViewerParcelMgr::PARCEL_BAN_LINES_ON_COLLISION);
             if (ban_lines_mode == LLViewerParcelMgr::PARCEL_BAN_LINES_ON_COLLISION)
             {
-                LLViewerParcelMgr::getInstance()->resetCollisionTimer();
+                LLViewerParcelMgr::getInstance()->resetCollisionTimer();
+            }
+            if (handle_special_notification(notificationID, llsdBlock))
+            {
+                return true;
+            }
+        }
+        // HACK -- handle callbacks for specific alerts.
+        if( notificationID == "HomePositionSet" )
+        {
+            // save the home location image to disk
+            std::string snap_filename = gDirUtilp->getLindenUserDir();
+            snap_filename += gDirUtilp->getDirDelimiter();
+            snap_filename += LLStartUp::getScreenHomeFilename();
+            gViewerWindow->saveSnapshot(snap_filename,
+                                        gViewerWindow->getWindowWidthRaw(),
+                                        gViewerWindow->getWindowHeightRaw(),
+                                        FALSE, //UI
+                                        gSavedSettings.getBOOL("RenderHUDInSnapshot"),
+                                        FALSE,
+                                        LLSnapshotModel::SNAPSHOT_TYPE_COLOR,
+                                        LLSnapshotModel::SNAPSHOT_FORMAT_PNG);
+        }
+
+        if (notificationID == "RegionRestartMinutes" ||
+            notificationID == "RegionRestartSeconds")
+        {
+            S32 seconds;
+            if (notificationID == "RegionRestartMinutes")
+            {
+                seconds = 60 * static_cast<S32>(llsdBlock["MINUTES"].asInteger());
+            }
+            else
+            {
+                seconds = static_cast<S32>(llsdBlock["SECONDS"].asInteger());
+            }
+
+            LLFloaterRegionRestarting* floaterp = LLFloaterReg::findTypedInstance<LLFloaterRegionRestarting>("region_restarting");
+
+            if (floaterp)
+            {
+                LLFloaterRegionRestarting::updateTime(seconds);
             }
-			if (handle_special_notification(notificationID, llsdBlock))
-			{
-				return true;
-			}
-		}
-		// HACK -- handle callbacks for specific alerts.
-		if( notificationID == "HomePositionSet" )
-		{
-			// save the home location image to disk
-			std::string snap_filename = gDirUtilp->getLindenUserDir();
-			snap_filename += gDirUtilp->getDirDelimiter();
-			snap_filename += LLStartUp::getScreenHomeFilename();
-            gViewerWindow->saveSnapshot(snap_filename,
-                                        gViewerWindow->getWindowWidthRaw(),
-                                        gViewerWindow->getWindowHeightRaw(),
-                                        FALSE, //UI
-                                        gSavedSettings.getBOOL("RenderHUDInSnapshot"),
-                                        FALSE,
-                                        LLSnapshotModel::SNAPSHOT_TYPE_COLOR,
-                                        LLSnapshotModel::SNAPSHOT_FORMAT_PNG);
-		}
-		
-		if (notificationID == "RegionRestartMinutes" ||
-			notificationID == "RegionRestartSeconds")
-		{
-			S32 seconds;
-			if (notificationID == "RegionRestartMinutes")
-			{
-				seconds = 60 * static_cast<S32>(llsdBlock["MINUTES"].asInteger());
-			}
-			else
-			{
-				seconds = static_cast<S32>(llsdBlock["SECONDS"].asInteger());
-			}
-
-			LLFloaterRegionRestarting* floaterp = LLFloaterReg::findTypedInstance<LLFloaterRegionRestarting>("region_restarting");
-
-			if (floaterp)
-			{
-				LLFloaterRegionRestarting::updateTime(seconds);
-			}
-			else
-			{
-				LLSD params;
-				params["NAME"] = llsdBlock["NAME"];
-				params["SECONDS"] = (LLSD::Integer)seconds;
-				LLFloaterRegionRestarting* restarting_floater = dynamic_cast<LLFloaterRegionRestarting*>(LLFloaterReg::showInstance("region_restarting", params));
-				if(restarting_floater)
-				{
-					restarting_floater->center();
-				}
-			}
-
-			make_ui_sound("UISndRestart");
-		}
-        
+            else
+            {
+                LLSD params;
+                params["NAME"] = llsdBlock["NAME"];
+                params["SECONDS"] = (LLSD::Integer)seconds;
+                LLFloaterRegionRestarting* restarting_floater = dynamic_cast<LLFloaterRegionRestarting*>(LLFloaterReg::showInstance("region_restarting", params));
+                if(restarting_floater)
+                {
+                    restarting_floater->center();
+                }
+            }
+
+            make_ui_sound("UISndRestart");
+        }
+
         // Special Marketplace update notification
-		if (notificationID == "SLM_UPDATE_FOLDER")
+        if (notificationID == "SLM_UPDATE_FOLDER")
         {
             std::string state = llsdBlock["state"].asString();
             if (state == "deleted")
@@ -5717,28 +5717,28 @@ bool attempt_standard_notification(LLMessageSystem* msgsystem)
             }
         }
 
-		LLNotificationsUtil::add(notificationID, llsdBlock);
-		return true;
-	}	
-	return false;
+        LLNotificationsUtil::add(notificationID, llsdBlock);
+        return true;
+    }
+    return false;
 }
 
 
 static void process_special_alert_messages(const std::string & message)
 {
-	// Do special handling for alert messages.   This is a legacy hack, and any actual displayed
-	// text should be altered in the notifications.xml files.
-	if ( message == "You died and have been teleported to your home location")
-	{
-		add(LLStatViewer::KILLED, 1);
-	}
-	else if( message == "Home position set." )
-	{
-		// save the home location image to disk
-		std::string snap_filename = gDirUtilp->getLindenUserDir();
-		snap_filename += gDirUtilp->getDirDelimiter();
-		snap_filename += LLStartUp::getScreenHomeFilename();
-		gViewerWindow->saveSnapshot(snap_filename,
+    // Do special handling for alert messages.   This is a legacy hack, and any actual displayed
+    // text should be altered in the notifications.xml files.
+    if ( message == "You died and have been teleported to your home location")
+    {
+        add(LLStatViewer::KILLED, 1);
+    }
+    else if( message == "Home position set." )
+    {
+        // save the home location image to disk
+        std::string snap_filename = gDirUtilp->getLindenUserDir();
+        snap_filename += gDirUtilp->getDirDelimiter();
+        snap_filename += LLStartUp::getScreenHomeFilename();
+        gViewerWindow->saveSnapshot(snap_filename,
                                     gViewerWindow->getWindowWidthRaw(),
                                     gViewerWindow->getWindowHeightRaw(),
                                     FALSE,
@@ -5746,28 +5746,28 @@ static void process_special_alert_messages(const std::string & message)
                                     FALSE,
                                     LLSnapshotModel::SNAPSHOT_TYPE_COLOR,
                                     LLSnapshotModel::SNAPSHOT_FORMAT_PNG);
-	}
+    }
 }
 
 
 
 void process_agent_alert_message(LLMessageSystem* msgsystem, void** user_data)
 {
-	// make sure the cursor is back to the usual default since the
-	// alert is probably due to some kind of error.
-	gViewerWindow->getWindow()->resetBusyCount();
-	
-	std::string message;
-	msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, message);
+    // make sure the cursor is back to the usual default since the
+    // alert is probably due to some kind of error.
+    gViewerWindow->getWindow()->resetBusyCount();
+
+    std::string message;
+    msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, message);
 
-	process_special_alert_messages(message);
+    process_special_alert_messages(message);
 
-	if (!attempt_standard_notification(msgsystem))
-	{
-		BOOL modal = FALSE;
-		msgsystem->getBOOLFast(_PREHASH_AlertData, _PREHASH_Modal, modal);
-		process_alert_core(message, modal);
-	}
+    if (!attempt_standard_notification(msgsystem))
+    {
+        BOOL modal = FALSE;
+        msgsystem->getBOOLFast(_PREHASH_AlertData, _PREHASH_Modal, modal);
+        process_alert_core(message, modal);
+    }
 }
 
 // The only difference between this routine and the previous is the fact that
@@ -5777,18 +5777,18 @@ void process_agent_alert_message(LLMessageSystem* msgsystem, void** user_data)
 // So we can't handle the messages with the same handler.
 void process_alert_message(LLMessageSystem *msgsystem, void **user_data)
 {
-	// make sure the cursor is back to the usual default since the
-	// alert is probably due to some kind of error.
-	gViewerWindow->getWindow()->resetBusyCount();
-		
-	std::string message;
-	msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, message);
-	process_special_alert_messages(message);
+    // make sure the cursor is back to the usual default since the
+    // alert is probably due to some kind of error.
+    gViewerWindow->getWindow()->resetBusyCount();
+
+    std::string message;
+    msgsystem->getStringFast(_PREHASH_AlertData, _PREHASH_Message, message);
+    process_special_alert_messages(message);
 
-	if (!attempt_standard_notification(msgsystem))
-	{
-		BOOL modal = FALSE;
-		process_alert_core(message, modal);
+    if (!attempt_standard_notification(msgsystem))
+    {
+        BOOL modal = FALSE;
+        process_alert_core(message, modal);
 
         static LLCachedControl<S32> ban_lines_mode(gSavedSettings , "ShowBanLines" , LLViewerParcelMgr::PARCEL_BAN_LINES_ON_COLLISION);
         if (ban_lines_mode == LLViewerParcelMgr::PARCEL_BAN_LINES_ON_COLLISION
@@ -5796,357 +5796,357 @@ void process_alert_message(LLMessageSystem *msgsystem, void **user_data)
         {
             LLViewerParcelMgr::getInstance()->resetCollisionTimer();
         }
-	}
+    }
 }
 
 bool handle_not_age_verified_alert(const std::string &pAlertName)
 {
-	LLNotificationPtr notification = LLNotificationsUtil::add(pAlertName);
-	if ((notification == NULL) || notification->isIgnored())
-	{
-		LLNotificationsUtil::add(pAlertName + "_Notify");
-	}
+    LLNotificationPtr notification = LLNotificationsUtil::add(pAlertName);
+    if ((notification == NULL) || notification->isIgnored())
+    {
+        LLNotificationsUtil::add(pAlertName + "_Notify");
+    }
 
-	return true;
+    return true;
 }
 
 bool handle_special_alerts(const std::string &pAlertName)
 {
-	bool isHandled = false;
-	if (LLStringUtil::compareStrings(pAlertName, "NotAgeVerified") == 0)
-	{
-		
-		isHandled = handle_not_age_verified_alert(pAlertName);
-	}
+    bool isHandled = false;
+    if (LLStringUtil::compareStrings(pAlertName, "NotAgeVerified") == 0)
+    {
+
+        isHandled = handle_not_age_verified_alert(pAlertName);
+    }
 
-	return isHandled;
+    return isHandled;
 }
 
 void process_alert_core(const std::string& message, BOOL modal)
 {
-	const std::string ALERT_PREFIX("ALERT: ");
-	const std::string NOTIFY_PREFIX("NOTIFY: ");
-	if (message.find(ALERT_PREFIX) == 0)
-	{
-		// Allow the server to spawn a named alert so that server alerts can be
-		// translated out of English.
-		std::string alert_name(message.substr(ALERT_PREFIX.length()));
-		if (!handle_special_alerts(alert_name))
-		{
-		LLNotificationsUtil::add(alert_name);
-	}
-	}
-	else if (message.find(NOTIFY_PREFIX) == 0)
-	{
-		// Allow the server to spawn a named notification so that server notifications can be
-		// translated out of English.
-		std::string notify_name(message.substr(NOTIFY_PREFIX.length()));
-		LLNotificationsUtil::add(notify_name);
-	}
-	else if (message[0] == '/')
-	{
-		// System message is important, show in upper-right box not tip
-		std::string text(message.substr(1));
-		LLSD args;
-
-		// *NOTE: If the text from the server ever changes this line will need to be adjusted.
-		std::string restart_cancelled = "Region restart cancelled.";
-		if (text.substr(0, restart_cancelled.length()) == restart_cancelled)
-		{
-			LLFloaterRegionRestarting::close();
-		}
-
-			std::string new_msg =LLNotifications::instance().getGlobalString(text);
+    const std::string ALERT_PREFIX("ALERT: ");
+    const std::string NOTIFY_PREFIX("NOTIFY: ");
+    if (message.find(ALERT_PREFIX) == 0)
+    {
+        // Allow the server to spawn a named alert so that server alerts can be
+        // translated out of English.
+        std::string alert_name(message.substr(ALERT_PREFIX.length()));
+        if (!handle_special_alerts(alert_name))
+        {
+        LLNotificationsUtil::add(alert_name);
+    }
+    }
+    else if (message.find(NOTIFY_PREFIX) == 0)
+    {
+        // Allow the server to spawn a named notification so that server notifications can be
+        // translated out of English.
+        std::string notify_name(message.substr(NOTIFY_PREFIX.length()));
+        LLNotificationsUtil::add(notify_name);
+    }
+    else if (message[0] == '/')
+    {
+        // System message is important, show in upper-right box not tip
+        std::string text(message.substr(1));
+        LLSD args;
+
+        // *NOTE: If the text from the server ever changes this line will need to be adjusted.
+        std::string restart_cancelled = "Region restart cancelled.";
+        if (text.substr(0, restart_cancelled.length()) == restart_cancelled)
+        {
+            LLFloaterRegionRestarting::close();
+        }
+
+            std::string new_msg =LLNotifications::instance().getGlobalString(text);
 // [RLVa:KB] - Checked: RLVa-1.4.5
-			if ( (new_msg == text) && (RlvActions::isRlvEnabled()) )
-			{
-				if (!RlvActions::canShowLocation())
-					RlvUtil::filterLocation(new_msg);
-				if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT))
-					RlvUtil::filterNames(new_msg);
-			}
+            if ( (new_msg == text) && (RlvActions::isRlvEnabled()) )
+            {
+                if (!RlvActions::canShowLocation())
+                    RlvUtil::filterLocation(new_msg);
+                if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT))
+                    RlvUtil::filterNames(new_msg);
+            }
 // [/RLVa:KB]
-			args["MESSAGE"] = new_msg;
-			LLNotificationsUtil::add("SystemMessage", args);
-		}
-	else if (modal)
-	{
-		LLSD args;
-		std::string new_msg =LLNotifications::instance().getGlobalString(message);
+            args["MESSAGE"] = new_msg;
+            LLNotificationsUtil::add("SystemMessage", args);
+        }
+    else if (modal)
+    {
+        LLSD args;
+        std::string new_msg =LLNotifications::instance().getGlobalString(message);
 // [RLVa:KB] - Checked: RLVa-1.4.5
-		if ( (new_msg == message) && (RlvActions::isRlvEnabled()) )
-		{
-			if (!RlvActions::canShowLocation())
-				RlvUtil::filterLocation(new_msg);
-			if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT))
-				RlvUtil::filterNames(new_msg);
-		}
+        if ( (new_msg == message) && (RlvActions::isRlvEnabled()) )
+        {
+            if (!RlvActions::canShowLocation())
+                RlvUtil::filterLocation(new_msg);
+            if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT))
+                RlvUtil::filterNames(new_msg);
+        }
 // [/RLVa:KB]
-		args["ERROR_MESSAGE"] = new_msg;
-		LLNotificationsUtil::add("ErrorMessage", args);
-	}
-	else
-	{
-		// Hack fix for EXP-623 (blame fix on RN :)) to avoid a sim deploy
-		const std::string AUTOPILOT_CANCELED_MSG("Autopilot canceled");
-		if (message.find(AUTOPILOT_CANCELED_MSG) == std::string::npos )
-		{
-			LLSD args;
-			std::string new_msg =LLNotifications::instance().getGlobalString(message);
-
-			std::string localized_msg;
-			bool is_message_localized = LLTrans::findString(localized_msg, new_msg);
+        args["ERROR_MESSAGE"] = new_msg;
+        LLNotificationsUtil::add("ErrorMessage", args);
+    }
+    else
+    {
+        // Hack fix for EXP-623 (blame fix on RN :)) to avoid a sim deploy
+        const std::string AUTOPILOT_CANCELED_MSG("Autopilot canceled");
+        if (message.find(AUTOPILOT_CANCELED_MSG) == std::string::npos )
+        {
+            LLSD args;
+            std::string new_msg =LLNotifications::instance().getGlobalString(message);
+
+            std::string localized_msg;
+            bool is_message_localized = LLTrans::findString(localized_msg, new_msg);
 
 // [RLVa:KB] - Checked: RLVa-1.4.5
-			if ( (new_msg == message) && (RlvActions::isRlvEnabled()) )
-			{
-				if (!RlvActions::canShowLocation())
-					RlvUtil::filterLocation(new_msg);
-				if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT))
-					RlvUtil::filterNames(new_msg);
-			}
+            if ( (new_msg == message) && (RlvActions::isRlvEnabled()) )
+            {
+                if (!RlvActions::canShowLocation())
+                    RlvUtil::filterLocation(new_msg);
+                if (!RlvActions::canShowName(RlvActions::SNC_DEFAULT))
+                    RlvUtil::filterNames(new_msg);
+            }
 // [/RLVa:KB]
 
-			args["MESSAGE"] = is_message_localized ? localized_msg : new_msg;
-			LLNotificationsUtil::add("SystemMessageTip", args);
-		}
-	}
+            args["MESSAGE"] = is_message_localized ? localized_msg : new_msg;
+            LLNotificationsUtil::add("SystemMessageTip", args);
+        }
+    }
 }
 
-mean_collision_list_t				gMeanCollisionList;
-time_t								gLastDisplayedTime = 0;
+mean_collision_list_t               gMeanCollisionList;
+time_t                              gLastDisplayedTime = 0;
 
 void handle_show_mean_events(void *)
 {
-	LLFloaterReg::showInstance("bumps");
-	//LLFloaterBump::showInstance();
+    LLFloaterReg::showInstance("bumps");
+    //LLFloaterBump::showInstance();
 }
 
 void mean_name_callback(const LLUUID &id, const LLAvatarName& av_name)
 {
-	static const U32 max_collision_list_size = 20;
-	if (gMeanCollisionList.size() > max_collision_list_size)
-	{
-		mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
-		for (U32 i=0; i<max_collision_list_size; i++) iter++;
-		for_each(iter, gMeanCollisionList.end(), DeletePointer());
-		gMeanCollisionList.erase(iter, gMeanCollisionList.end());
-	}
-
-	for (mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
-		 iter != gMeanCollisionList.end(); ++iter)
-	{
-		LLMeanCollisionData *mcd = *iter;
-		if (mcd->mPerp == id)
-		{
-			mcd->mFullName = av_name.getUserName();
-		}
-	}
+    static const U32 max_collision_list_size = 20;
+    if (gMeanCollisionList.size() > max_collision_list_size)
+    {
+        mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
+        for (U32 i=0; i<max_collision_list_size; i++) iter++;
+        for_each(iter, gMeanCollisionList.end(), DeletePointer());
+        gMeanCollisionList.erase(iter, gMeanCollisionList.end());
+    }
+
+    for (mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
+         iter != gMeanCollisionList.end(); ++iter)
+    {
+        LLMeanCollisionData *mcd = *iter;
+        if (mcd->mPerp == id)
+        {
+            mcd->mFullName = av_name.getUserName();
+        }
+    }
 }
 
 void process_mean_collision_alert_message(LLMessageSystem *msgsystem, void **user_data)
 {
-	if (gAgent.inPrelude())
-	{
-		// In prelude, bumping is OK.  This dialog is rather confusing to 
-		// newbies, so we don't show it.  Drop the packet on the floor.
-		return;
-	}
-
-	// make sure the cursor is back to the usual default since the
-	// alert is probably due to some kind of error.
-	gViewerWindow->getWindow()->resetBusyCount();
-
-	LLUUID perp;
-	U32	   time;
-	U8	   u8type;
-	EMeanCollisionType	   type;
-	F32    mag;
-
-	S32 i, num = msgsystem->getNumberOfBlocksFast(_PREHASH_MeanCollision);
-
-	for (i = 0; i < num; i++)
-	{
-		msgsystem->getUUIDFast(_PREHASH_MeanCollision, _PREHASH_Perp, perp);
-		msgsystem->getU32Fast(_PREHASH_MeanCollision, _PREHASH_Time, time);
-		msgsystem->getF32Fast(_PREHASH_MeanCollision, _PREHASH_Mag, mag);
-		msgsystem->getU8Fast(_PREHASH_MeanCollision, _PREHASH_Type, u8type);
-
-		type = (EMeanCollisionType)u8type;
-
-		BOOL b_found = FALSE;
-
-		for (mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
-			 iter != gMeanCollisionList.end(); ++iter)
-		{
-			LLMeanCollisionData *mcd = *iter;
-			if ((mcd->mPerp == perp) && (mcd->mType == type))
-			{
-				mcd->mTime = time;
-				mcd->mMag = mag;
-				b_found = TRUE;
-				break;
-			}
-		}
-
-		if (!b_found)
-		{
-			LLMeanCollisionData *mcd = new LLMeanCollisionData(gAgentID, perp, time, type, mag);
-			gMeanCollisionList.push_front(mcd);
-			LLAvatarNameCache::get(perp, boost::bind(&mean_name_callback, _1, _2));
-		}
-	}
-	LLFloaterBump* bumps_floater = LLFloaterBump::getInstance();
-	if(bumps_floater && bumps_floater->isInVisibleChain())
-	{
-		bumps_floater->populateCollisionList();
-	}
+    if (gAgent.inPrelude())
+    {
+        // In prelude, bumping is OK.  This dialog is rather confusing to
+        // newbies, so we don't show it.  Drop the packet on the floor.
+        return;
+    }
+
+    // make sure the cursor is back to the usual default since the
+    // alert is probably due to some kind of error.
+    gViewerWindow->getWindow()->resetBusyCount();
+
+    LLUUID perp;
+    U32    time;
+    U8     u8type;
+    EMeanCollisionType     type;
+    F32    mag;
+
+    S32 i, num = msgsystem->getNumberOfBlocksFast(_PREHASH_MeanCollision);
+
+    for (i = 0; i < num; i++)
+    {
+        msgsystem->getUUIDFast(_PREHASH_MeanCollision, _PREHASH_Perp, perp);
+        msgsystem->getU32Fast(_PREHASH_MeanCollision, _PREHASH_Time, time);
+        msgsystem->getF32Fast(_PREHASH_MeanCollision, _PREHASH_Mag, mag);
+        msgsystem->getU8Fast(_PREHASH_MeanCollision, _PREHASH_Type, u8type);
+
+        type = (EMeanCollisionType)u8type;
+
+        BOOL b_found = FALSE;
+
+        for (mean_collision_list_t::iterator iter = gMeanCollisionList.begin();
+             iter != gMeanCollisionList.end(); ++iter)
+        {
+            LLMeanCollisionData *mcd = *iter;
+            if ((mcd->mPerp == perp) && (mcd->mType == type))
+            {
+                mcd->mTime = time;
+                mcd->mMag = mag;
+                b_found = TRUE;
+                break;
+            }
+        }
+
+        if (!b_found)
+        {
+            LLMeanCollisionData *mcd = new LLMeanCollisionData(gAgentID, perp, time, type, mag);
+            gMeanCollisionList.push_front(mcd);
+            LLAvatarNameCache::get(perp, boost::bind(&mean_name_callback, _1, _2));
+        }
+    }
+    LLFloaterBump* bumps_floater = LLFloaterBump::getInstance();
+    if(bumps_floater && bumps_floater->isInVisibleChain())
+    {
+        bumps_floater->populateCollisionList();
+    }
 }
 
 void process_frozen_message(LLMessageSystem *msgsystem, void **user_data)
 {
-	// make sure the cursor is back to the usual default since the
-	// alert is probably due to some kind of error.
-	gViewerWindow->getWindow()->resetBusyCount();
-	BOOL b_frozen;
-	
-	msgsystem->getBOOLFast(_PREHASH_FrozenData, _PREHASH_Data, b_frozen);
+    // make sure the cursor is back to the usual default since the
+    // alert is probably due to some kind of error.
+    gViewerWindow->getWindow()->resetBusyCount();
+    BOOL b_frozen;
 
-	// TODO: make being frozen change view
-	if (b_frozen)
-	{
-	}
-	else
-	{
-	}
+    msgsystem->getBOOLFast(_PREHASH_FrozenData, _PREHASH_Data, b_frozen);
+
+    // TODO: make being frozen change view
+    if (b_frozen)
+    {
+    }
+    else
+    {
+    }
 }
 
 // do some extra stuff once we get our economy data
 void process_economy_data(LLMessageSystem *msg, void** /*user_data*/)
 {
-	if (!LLGridManager::getInstance()->isInSecondlife())
-	{
-		LLGlobalEconomy::processEconomyData(msg, LLGlobalEconomy::getInstance());
-
-		const std::string texture_upload_cost_str = std::to_string(LLAgentBenefitsMgr::current().getTextureUploadCost());
-		const std::string sound_upload_cost_str = std::to_string(LLAgentBenefitsMgr::current().getSoundUploadCost());
-		const std::string animation_upload_cost_str = std::to_string(LLAgentBenefitsMgr::current().getAnimationUploadCost());
-		gMenuHolder->getChild<LLUICtrl>("Upload Image")->setLabelArg("[COST]",  texture_upload_cost_str);
-		gMenuHolder->getChild<LLUICtrl>("Upload Sound")->setLabelArg("[COST]",  sound_upload_cost_str);
-		gMenuHolder->getChild<LLUICtrl>("Upload Animation")->setLabelArg("[COST]", animation_upload_cost_str);
-	}
-	else
-	{
-		LL_DEBUGS("Benefits") << "Received economy data, not currently used" << LL_ENDL;
-	}
+    if (!LLGridManager::getInstance()->isInSecondlife())
+    {
+        LLGlobalEconomy::processEconomyData(msg, LLGlobalEconomy::getInstance());
+
+        const std::string texture_upload_cost_str = std::to_string(LLAgentBenefitsMgr::current().getTextureUploadCost());
+        const std::string sound_upload_cost_str = std::to_string(LLAgentBenefitsMgr::current().getSoundUploadCost());
+        const std::string animation_upload_cost_str = std::to_string(LLAgentBenefitsMgr::current().getAnimationUploadCost());
+        gMenuHolder->getChild<LLUICtrl>("Upload Image")->setLabelArg("[COST]",  texture_upload_cost_str);
+        gMenuHolder->getChild<LLUICtrl>("Upload Sound")->setLabelArg("[COST]",  sound_upload_cost_str);
+        gMenuHolder->getChild<LLUICtrl>("Upload Animation")->setLabelArg("[COST]", animation_upload_cost_str);
+    }
+    else
+    {
+        LL_DEBUGS("Benefits") << "Received economy data, not currently used" << LL_ENDL;
+    }
 }
 
 void notify_cautioned_script_question(const LLSD& notification, const LLSD& response, S32 orig_questions, BOOL granted)
 {
-	// only continue if at least some permissions were requested
-	if (orig_questions)
-	{
-		// check to see if the person we are asking
-
-		// "'[OBJECTNAME]', an object owned by '[OWNERNAME]', 
-		// located in [REGIONNAME] at [REGIONPOS], 
-		// has been <granted|denied> permission to: [PERMISSIONS]."
-
-		LLUIString notice(LLTrans::getString(granted ? "ScriptQuestionCautionChatGranted" : "ScriptQuestionCautionChatDenied"));
-
-		// always include the object name and owner name 
-		notice.setArg("[OBJECTNAME]", notification["payload"]["object_name"].asString());
-		notice.setArg("[OWNERNAME]", notification["payload"]["owner_name"].asString());
-
-		// try to lookup viewerobject that corresponds to the object that
-		// requested permissions (here, taskid->requesting object id)
-		BOOL foundpos = FALSE;
-		LLViewerObject* viewobj = gObjectList.findObject(notification["payload"]["task_id"].asUUID());
-		if (viewobj)
-		{
-			// found the viewerobject, get it's position in its region
-			LLVector3 objpos(viewobj->getPosition());
-			
-			// try to lookup the name of the region the object is in
-			LLViewerRegion* viewregion = viewobj->getRegion();
-			if (viewregion)
-			{
-				// got the region, so include the region and 3d coordinates of the object
-				notice.setArg("[REGIONNAME]", viewregion->getName());
-				std::string formatpos = llformat("%.1f, %.1f,%.1f", objpos[VX], objpos[VY], objpos[VZ]);
-				notice.setArg("[REGIONPOS]", formatpos);
-
-				foundpos = TRUE;
-			}
-		}
+    // only continue if at least some permissions were requested
+    if (orig_questions)
+    {
+        // check to see if the person we are asking
+
+        // "'[OBJECTNAME]', an object owned by '[OWNERNAME]',
+        // located in [REGIONNAME] at [REGIONPOS],
+        // has been <granted|denied> permission to: [PERMISSIONS]."
+
+        LLUIString notice(LLTrans::getString(granted ? "ScriptQuestionCautionChatGranted" : "ScriptQuestionCautionChatDenied"));
+
+        // always include the object name and owner name
+        notice.setArg("[OBJECTNAME]", notification["payload"]["object_name"].asString());
+        notice.setArg("[OWNERNAME]", notification["payload"]["owner_name"].asString());
+
+        // try to lookup viewerobject that corresponds to the object that
+        // requested permissions (here, taskid->requesting object id)
+        BOOL foundpos = FALSE;
+        LLViewerObject* viewobj = gObjectList.findObject(notification["payload"]["task_id"].asUUID());
+        if (viewobj)
+        {
+            // found the viewerobject, get it's position in its region
+            LLVector3 objpos(viewobj->getPosition());
+
+            // try to lookup the name of the region the object is in
+            LLViewerRegion* viewregion = viewobj->getRegion();
+            if (viewregion)
+            {
+                // got the region, so include the region and 3d coordinates of the object
+                notice.setArg("[REGIONNAME]", viewregion->getName());
+                std::string formatpos = llformat("%.1f, %.1f,%.1f", objpos[VX], objpos[VY], objpos[VZ]);
+                notice.setArg("[REGIONPOS]", formatpos);
+
+                foundpos = TRUE;
+            }
+        }
 
 // [RLVa:KB] - Checked: 2010-04-23 (RLVa-1.2.0g) | Modified: RLVa-1.0.0a
-		if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC))
-		{
-			notice.setArg("[REGIONNAME]", RlvStrings::getString(RlvStringKeys::Hidden::Region));
-			notice.setArg("[REGIONPOS]", RlvStrings::getString(RlvStringKeys::Hidden::Generic));
-		}
-		else if (!foundpos)
+        if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC))
+        {
+            notice.setArg("[REGIONNAME]", RlvStrings::getString(RlvStringKeys::Hidden::Region));
+            notice.setArg("[REGIONPOS]", RlvStrings::getString(RlvStringKeys::Hidden::Generic));
+        }
+        else if (!foundpos)
 // [/RLVa:KB]
-//		if (!foundpos)
-		{
-			// unable to determine location of the object
-			notice.setArg("[REGIONNAME]", "(unknown region)");
-			notice.setArg("[REGIONPOS]", "(unknown position)");
-		}
-
-		// check each permission that was requested, and list each 
-		// permission that has been flagged as a caution permission
-		BOOL caution = FALSE;
-		S32 count = 0;
-		std::string perms;
-		for (const script_perm_t& script_perm : SCRIPT_PERMISSIONS)
-		{
-//			if ((orig_questions & script_perm.permbit)
-//				&& script_perm.caution)
+//      if (!foundpos)
+        {
+            // unable to determine location of the object
+            notice.setArg("[REGIONNAME]", "(unknown region)");
+            notice.setArg("[REGIONPOS]", "(unknown position)");
+        }
+
+        // check each permission that was requested, and list each
+        // permission that has been flagged as a caution permission
+        BOOL caution = FALSE;
+        S32 count = 0;
+        std::string perms;
+        for (const script_perm_t& script_perm : SCRIPT_PERMISSIONS)
+        {
+//          if ((orig_questions & script_perm.permbit)
+//              && script_perm.caution)
 // [RLVa:KB] - Checked: 2012-07-28 (RLVa-1.4.7)
-			if ( (orig_questions & script_perm.permbit) &&
- 				 ((script_perm.caution) || (notification["payload"]["rlv_notify"].asBoolean())) )
+            if ( (orig_questions & script_perm.permbit) &&
+                 ((script_perm.caution) || (notification["payload"]["rlv_notify"].asBoolean())) )
 // [/RLVa:KB]
-			{
-				count++;
-				caution = TRUE;
+            {
+                count++;
+                caution = TRUE;
 
-				// add a comma before the permission description if it is not the first permission
-				// added to the list or the last permission to check
-				if (count > 1)
-				{
-					perms.append(", ");
-				}
+                // add a comma before the permission description if it is not the first permission
+                // added to the list or the last permission to check
+                if (count > 1)
+                {
+                    perms.append(", ");
+                }
 
-				perms.append(LLTrans::getString(script_perm.question));
-			}
-		}
+                perms.append(LLTrans::getString(script_perm.question));
+            }
+        }
 
-		notice.setArg("[PERMISSIONS]", perms);
+        notice.setArg("[PERMISSIONS]", perms);
 
-		// log a chat message as long as at least one requested permission
-		// is a caution permission
+        // log a chat message as long as at least one requested permission
+        // is a caution permission
 // [RLVa:KB] - Checked: 2012-07-28 (RLVa-1.4.7)
-		if (caution)
-		{
-			LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
-			if(nearby_chat)
-			{
-				LLChat chat_msg(notice.getString());
-				chat_msg.mFromName = SYSTEM_FROM;
-				chat_msg.mFromID = LLUUID::null;
-				chat_msg.mSourceType = CHAT_SOURCE_SYSTEM;
-				nearby_chat->addMessage(chat_msg);
-			}
-		}
+        if (caution)
+        {
+            LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::getTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
+            if(nearby_chat)
+            {
+                LLChat chat_msg(notice.getString());
+                chat_msg.mFromName = SYSTEM_FROM;
+                chat_msg.mFromID = LLUUID::null;
+                chat_msg.mSourceType = CHAT_SOURCE_SYSTEM;
+                nearby_chat->addMessage(chat_msg);
+            }
+        }
 // [/RLVa:KB]
-//		if (caution)
-//		{
-//			LLChat chat(notice.getString());
-//	//		LLFloaterChat::addChat(chat, FALSE, FALSE);
-//		}
-	}
+//      if (caution)
+//      {
+//          LLChat chat(notice.getString());
+//  //      LLFloaterChat::addChat(chat, FALSE, FALSE);
+//      }
+    }
 }
 
 void script_question_mute(const LLUUID& item_id, const std::string& object_name);
@@ -6163,107 +6163,107 @@ void experiencePermissionBlock(LLUUID experience, LLSD result)
 
 bool script_question_cb(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
-	LLMessageSystem *msg = gMessageSystem;
-	S32 orig = notification["payload"]["questions"].asInteger();
-	S32 new_questions = orig;
-
-	if (response["Details"])
-	{
-		// respawn notification...
-		LLNotificationsUtil::add(notification["name"], notification["substitutions"], notification["payload"]);
-
-		// ...with description on top
-		LLNotificationsUtil::add("DebitPermissionDetails");
-		return false;
-	}
-
-	LLUUID experience;
-	if(notification["payload"].has("experience"))
-	{
-		experience = notification["payload"]["experience"].asUUID();
-	}
-
-	// check whether permissions were granted or denied
-	BOOL allowed = TRUE;
-	// the "yes/accept" button is the first button in the template, making it button 0
-	// if any other button was clicked, the permissions were denied
-	if (option != 0)
-	{
-		new_questions = 0;
-		allowed = FALSE;
-	}	
-	else if(experience.notNull())
-	{
-		LLSD permission;
-		LLSD data;
-		permission["permission"]="Allow";
-
-		data[experience.asString()]=permission;
-		data["experience"]=experience;
-		LLEventPumps::instance().obtain("experience_permission").post(data);
-	}
-
-	LLUUID task_id = notification["payload"]["task_id"].asUUID();
-	LLUUID item_id = notification["payload"]["item_id"].asUUID();
-
-	// reply with the permissions granted or denied
-	msg->newMessageFast(_PREHASH_ScriptAnswerYes);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_Data);
-	msg->addUUIDFast(_PREHASH_TaskID, task_id);
-	msg->addUUIDFast(_PREHASH_ItemID, item_id);
-	msg->addS32Fast(_PREHASH_Questions, new_questions);
-	msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
-
-	// only log a chat message if caution prompts are enabled
-//	if (gSavedSettings.getBOOL("PermissionsCautionEnabled"))
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    LLMessageSystem *msg = gMessageSystem;
+    S32 orig = notification["payload"]["questions"].asInteger();
+    S32 new_questions = orig;
+
+    if (response["Details"])
+    {
+        // respawn notification...
+        LLNotificationsUtil::add(notification["name"], notification["substitutions"], notification["payload"]);
+
+        // ...with description on top
+        LLNotificationsUtil::add("DebitPermissionDetails");
+        return false;
+    }
+
+    LLUUID experience;
+    if(notification["payload"].has("experience"))
+    {
+        experience = notification["payload"]["experience"].asUUID();
+    }
+
+    // check whether permissions were granted or denied
+    BOOL allowed = TRUE;
+    // the "yes/accept" button is the first button in the template, making it button 0
+    // if any other button was clicked, the permissions were denied
+    if (option != 0)
+    {
+        new_questions = 0;
+        allowed = FALSE;
+    }
+    else if(experience.notNull())
+    {
+        LLSD permission;
+        LLSD data;
+        permission["permission"]="Allow";
+
+        data[experience.asString()]=permission;
+        data["experience"]=experience;
+        LLEventPumps::instance().obtain("experience_permission").post(data);
+    }
+
+    LLUUID task_id = notification["payload"]["task_id"].asUUID();
+    LLUUID item_id = notification["payload"]["item_id"].asUUID();
+
+    // reply with the permissions granted or denied
+    msg->newMessageFast(_PREHASH_ScriptAnswerYes);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_Data);
+    msg->addUUIDFast(_PREHASH_TaskID, task_id);
+    msg->addUUIDFast(_PREHASH_ItemID, item_id);
+    msg->addS32Fast(_PREHASH_Questions, new_questions);
+    msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
+
+    // only log a chat message if caution prompts are enabled
+//  if (gSavedSettings.getBOOL("PermissionsCautionEnabled"))
 // [RLVa:KB] - Checked: 2012-07-28 (RLVa-1.4.7)
-	if ( (gSavedSettings.getBOOL("PermissionsCautionEnabled")) || (notification["payload"]["rlv_notify"].asBoolean()) )
+    if ( (gSavedSettings.getBOOL("PermissionsCautionEnabled")) || (notification["payload"]["rlv_notify"].asBoolean()) )
 // [/RLVa:KB]
-	{
-		// log a chat message, if appropriate
-		notify_cautioned_script_question(notification, response, orig, allowed);
-	}
+    {
+        // log a chat message, if appropriate
+        notify_cautioned_script_question(notification, response, orig, allowed);
+    }
 
 // [RLVa:KB] - Checked: 2012-07-28 (RLVa-1.4.7)
-	if ( (allowed) && (notification["payload"].has("rlv_blocked")) )
-	{
-		RlvUtil::notifyBlocked(notification["payload"]["rlv_blocked"].asStringRef(), LLSD().with("OBJECT", notification["payload"]["object_name"]));
-	}
+    if ( (allowed) && (notification["payload"].has("rlv_blocked")) )
+    {
+        RlvUtil::notifyBlocked(notification["payload"]["rlv_blocked"].asStringRef(), LLSD().with("OBJECT", notification["payload"]["object_name"]));
+    }
 // [/RLVa:KB]
 
-	if ( response["Mute"] ) // mute
-	{
-		script_question_mute(task_id,notification["payload"]["object_name"].asString());
-	}
-	if ( response["BlockExperience"] )
-	{
-		if(experience.notNull())
-		{
-			LLViewerRegion* region = gAgent.getRegion();
-			if (!region)
-			    return false;
+    if ( response["Mute"] ) // mute
+    {
+        script_question_mute(task_id,notification["payload"]["object_name"].asString());
+    }
+    if ( response["BlockExperience"] )
+    {
+        if(experience.notNull())
+        {
+            LLViewerRegion* region = gAgent.getRegion();
+            if (!region)
+                return false;
 
             LLExperienceCache::instance().setExperiencePermission(experience, std::string("Block"), boost::bind(&experiencePermissionBlock, experience, _1));
 
-		}
+        }
 }
-	return false;
+    return false;
 }
 
 void script_question_mute(const LLUUID& task_id, const std::string& object_name)
 {
-	LLMuteList::getInstance()->add(LLMute(task_id, object_name, LLMute::OBJECT));
+    LLMuteList::getInstance()->add(LLMute(task_id, object_name, LLMute::OBJECT));
 
     // purge the message queue of any previously queued requests from the same source. DEV-4879
     class OfferMatcher : public LLNotificationsUI::LLScreenChannel::Matcher
     {
     public:
-    	OfferMatcher(const LLUUID& to_block) : blocked_id(to_block) {}
-      	bool matches(const LLNotificationPtr notification) const
+        OfferMatcher(const LLUUID& to_block) : blocked_id(to_block) {}
+        bool matches(const LLNotificationPtr notification) const
         {
             if (notification->getName() == "ScriptQuestionCaution"
                 || notification->getName() == "ScriptQuestion")
@@ -6287,210 +6287,210 @@ static LLNotificationFunctorRegistration script_question_cb_reg_3("ScriptQuestio
 
 void process_script_experience_details(const LLSD& experience_details, LLSD args, LLSD payload)
 {
-	if(experience_details[LLExperienceCache::PROPERTIES].asInteger() & LLExperienceCache::PROPERTY_GRID)
-	{
-		args["GRID_WIDE"] = LLTrans::getString("Grid-Scope");
-	}
-	else
-	{
-		args["GRID_WIDE"] = LLTrans::getString("Land-Scope");
-	}
-	args["EXPERIENCE"] = LLSLURL("experience", experience_details[LLExperienceCache::EXPERIENCE_ID].asUUID(), "profile").getSLURLString();
+    if(experience_details[LLExperienceCache::PROPERTIES].asInteger() & LLExperienceCache::PROPERTY_GRID)
+    {
+        args["GRID_WIDE"] = LLTrans::getString("Grid-Scope");
+    }
+    else
+    {
+        args["GRID_WIDE"] = LLTrans::getString("Land-Scope");
+    }
+    args["EXPERIENCE"] = LLSLURL("experience", experience_details[LLExperienceCache::EXPERIENCE_ID].asUUID(), "profile").getSLURLString();
 
-	LLNotificationsUtil::add("ScriptQuestionExperience", args, payload);
+    LLNotificationsUtil::add("ScriptQuestionExperience", args, payload);
 }
 
 void process_script_question(LLMessageSystem *msg, void **user_data)
 {
-	// *TODO: Translate owner name -> [FIRST] [LAST]
-
-	LLHost sender = msg->getSender();
-
-	LLUUID taskid;
-	LLUUID itemid;
-	S32		questions;
-	std::string object_name;
-	std::string owner_name;
-	LLUUID experienceid;
-
-	// taskid -> object key of object requesting permissions
-	msg->getUUIDFast(_PREHASH_Data, _PREHASH_TaskID, taskid );
-	// itemid -> script asset key of script requesting permissions
-	msg->getUUIDFast(_PREHASH_Data, _PREHASH_ItemID, itemid );
-	msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
-	msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectOwner, owner_name);
-	msg->getS32Fast(_PREHASH_Data, _PREHASH_Questions, questions );
-
-	if(msg->hasFast(_PREHASH_Experience))
-	{
-		msg->getUUIDFast(_PREHASH_Experience, _PREHASH_ExperienceID, experienceid);
-	}
-
-	// Special case. If the objects are owned by this agent, throttle per-object instead
-	// of per-owner. It's common for residents to reset a ton of scripts that re-request
-	// permissions, as with tier boxes. UUIDs can't be valid agent names and vice-versa,
-	// so we'll reuse the same namespace for both throttle types.
-	std::string throttle_name = owner_name;
-	std::string self_name;
-	LLAgentUI::buildFullname( self_name ); // does not include ' Resident'
-	std::string clean_owner_name = LLCacheName::cleanFullName(owner_name); // removes ' Resident'
-	if( clean_owner_name == self_name )
-	{
-		throttle_name = taskid.getString();
-	}
-	
-	// don't display permission requests if this object is muted
-	if (LLMuteList::getInstance()->isMuted(taskid)) return;
-	
-	// throttle excessive requests from any specific user's scripts
-	typedef LLKeyThrottle<std::string> LLStringThrottle;
-	static LLStringThrottle question_throttle( LLREQUEST_PERMISSION_THROTTLE_LIMIT, LLREQUEST_PERMISSION_THROTTLE_INTERVAL );
-
-	switch (question_throttle.noteAction(throttle_name))
-	{
-		case LLStringThrottle::THROTTLE_NEWLY_BLOCKED:
-			LL_INFOS("Messaging") << "process_script_question throttled"
-					<< " owner_name:" << owner_name
-					<< LL_ENDL;
-			// Fall through
-
-		case LLStringThrottle::THROTTLE_BLOCKED:
-			// Escape altogether until we recover
-			return;
-
-		case LLStringThrottle::THROTTLE_OK:
-			break;
-	}
-
-	std::string script_question;
-	if (questions)
-	{
-		bool caution = false;
-		S32 count = 0;
-		LLSD args;
-		args["OBJECTNAME"] = object_name;
-		args["NAME"] = clean_owner_name;
-		S32 known_questions = 0;
-		bool has_not_only_debit = questions ^ SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_DEBIT].permbit;
-		// check the received permission flags against each permission
-		for (const script_perm_t& script_perm : SCRIPT_PERMISSIONS)
-		{
-			if (questions & script_perm.permbit)
-			{
-				count++;
-				known_questions |= script_perm.permbit;
-				// check whether permission question should cause special caution dialog
-				caution |= (script_perm.caution);
-
-				if (("ScriptTakeMoney" == script_perm.question) && has_not_only_debit)
-					continue;
+    // *TODO: Translate owner name -> [FIRST] [LAST]
+
+    LLHost sender = msg->getSender();
+
+    LLUUID taskid;
+    LLUUID itemid;
+    S32     questions;
+    std::string object_name;
+    std::string owner_name;
+    LLUUID experienceid;
+
+    // taskid -> object key of object requesting permissions
+    msg->getUUIDFast(_PREHASH_Data, _PREHASH_TaskID, taskid );
+    // itemid -> script asset key of script requesting permissions
+    msg->getUUIDFast(_PREHASH_Data, _PREHASH_ItemID, itemid );
+    msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
+    msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectOwner, owner_name);
+    msg->getS32Fast(_PREHASH_Data, _PREHASH_Questions, questions );
+
+    if(msg->hasFast(_PREHASH_Experience))
+    {
+        msg->getUUIDFast(_PREHASH_Experience, _PREHASH_ExperienceID, experienceid);
+    }
+
+    // Special case. If the objects are owned by this agent, throttle per-object instead
+    // of per-owner. It's common for residents to reset a ton of scripts that re-request
+    // permissions, as with tier boxes. UUIDs can't be valid agent names and vice-versa,
+    // so we'll reuse the same namespace for both throttle types.
+    std::string throttle_name = owner_name;
+    std::string self_name;
+    LLAgentUI::buildFullname( self_name ); // does not include ' Resident'
+    std::string clean_owner_name = LLCacheName::cleanFullName(owner_name); // removes ' Resident'
+    if( clean_owner_name == self_name )
+    {
+        throttle_name = taskid.getString();
+    }
+
+    // don't display permission requests if this object is muted
+    if (LLMuteList::getInstance()->isMuted(taskid)) return;
+
+    // throttle excessive requests from any specific user's scripts
+    typedef LLKeyThrottle<std::string> LLStringThrottle;
+    static LLStringThrottle question_throttle( LLREQUEST_PERMISSION_THROTTLE_LIMIT, LLREQUEST_PERMISSION_THROTTLE_INTERVAL );
+
+    switch (question_throttle.noteAction(throttle_name))
+    {
+        case LLStringThrottle::THROTTLE_NEWLY_BLOCKED:
+            LL_INFOS("Messaging") << "process_script_question throttled"
+                    << " owner_name:" << owner_name
+                    << LL_ENDL;
+            // Fall through
+
+        case LLStringThrottle::THROTTLE_BLOCKED:
+            // Escape altogether until we recover
+            return;
+
+        case LLStringThrottle::THROTTLE_OK:
+            break;
+    }
+
+    std::string script_question;
+    if (questions)
+    {
+        bool caution = false;
+        S32 count = 0;
+        LLSD args;
+        args["OBJECTNAME"] = object_name;
+        args["NAME"] = clean_owner_name;
+        S32 known_questions = 0;
+        bool has_not_only_debit = questions ^ SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_DEBIT].permbit;
+        // check the received permission flags against each permission
+        for (const script_perm_t& script_perm : SCRIPT_PERMISSIONS)
+        {
+            if (questions & script_perm.permbit)
+            {
+                count++;
+                known_questions |= script_perm.permbit;
+                // check whether permission question should cause special caution dialog
+                caution |= (script_perm.caution);
+
+                if (("ScriptTakeMoney" == script_perm.question) && has_not_only_debit)
+                    continue;
 
                 if (LLTrans::getString(script_perm.question).empty())
                 {
                     continue;
                 }
 
-				script_question += "    " + LLTrans::getString(script_perm.question) + "\n";
-			}
-		}
-
-		args["QUESTIONS"] = script_question;
-
-		if (known_questions != questions)
-		{
-			// This is in addition to the normal dialog.
-			// Viewer got a request for not supported/implemented permission 
-			LL_WARNS("Messaging") << "Object \"" << object_name << "\" requested " << script_question
-								<< " permission. Permission is unknown and can't be granted. Item id: " << itemid
-								<< " taskid:" << taskid << LL_ENDL;
-		}
-		
-		if (known_questions)
-		{
-			LLSD payload;
-			payload["task_id"] = taskid;
-			payload["item_id"] = itemid;
-			payload["sender"] = sender.getIPandPort();
-			payload["questions"] = known_questions;
-			payload["object_name"] = object_name;
-			payload["owner_name"] = owner_name;
+                script_question += "    " + LLTrans::getString(script_perm.question) + "\n";
+            }
+        }
+
+        args["QUESTIONS"] = script_question;
+
+        if (known_questions != questions)
+        {
+            // This is in addition to the normal dialog.
+            // Viewer got a request for not supported/implemented permission
+            LL_WARNS("Messaging") << "Object \"" << object_name << "\" requested " << script_question
+                                << " permission. Permission is unknown and can't be granted. Item id: " << itemid
+                                << " taskid:" << taskid << LL_ENDL;
+        }
+
+        if (known_questions)
+        {
+            LLSD payload;
+            payload["task_id"] = taskid;
+            payload["item_id"] = itemid;
+            payload["sender"] = sender.getIPandPort();
+            payload["questions"] = known_questions;
+            payload["object_name"] = object_name;
+            payload["owner_name"] = owner_name;
 
 // [RLVa:KB] - Checked: 2012-07-28 (RLVa-1.4.7)
-			if (rlv_handler_t::isEnabled())
-			{
-				RlvUtil::filterScriptQuestions(questions, payload);
-
-				if ( (questions) && (gRlvHandler.hasBehaviour(RLV_BHVR_ACCEPTPERMISSION)) )
-				{
-					const LLViewerObject* pObj = gObjectList.findObject(taskid);
-					if (pObj)
-					{
-						if ( (pObj->permYouOwner()) && (!pObj->isAttachment()) )
-						{
- 							questions &= ~(SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_TAKE_CONTROLS].permbit | 
- 								SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_ATTACH].permbit);
-						}
-						else
-						{
-							questions &= ~(SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_TAKE_CONTROLS].permbit);
-						}
-						payload["rlv_notify"] = !pObj->permYouOwner();
-					}
-				}
-			}
-
-			if ( (!caution) && (!questions) )
-			{
-				LLNotifications::instance().forceResponse(
-					LLNotification::Params("ScriptQuestion").substitutions(args).payload(payload), 0/*YES*/);
-				return;
-			}
+            if (rlv_handler_t::isEnabled())
+            {
+                RlvUtil::filterScriptQuestions(questions, payload);
+
+                if ( (questions) && (gRlvHandler.hasBehaviour(RLV_BHVR_ACCEPTPERMISSION)) )
+                {
+                    const LLViewerObject* pObj = gObjectList.findObject(taskid);
+                    if (pObj)
+                    {
+                        if ( (pObj->permYouOwner()) && (!pObj->isAttachment()) )
+                        {
+                            questions &= ~(SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_TAKE_CONTROLS].permbit |
+                                SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_ATTACH].permbit);
+                        }
+                        else
+                        {
+                            questions &= ~(SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_TAKE_CONTROLS].permbit);
+                        }
+                        payload["rlv_notify"] = !pObj->permYouOwner();
+                    }
+                }
+            }
+
+            if ( (!caution) && (!questions) )
+            {
+                LLNotifications::instance().forceResponse(
+                    LLNotification::Params("ScriptQuestion").substitutions(args).payload(payload), 0/*YES*/);
+                return;
+            }
 // [/RLVa:KB]
 
-			// check whether cautions are even enabled or not
-			const char* notification = "ScriptQuestion";
-
-			if(caution && gSavedSettings.getBOOL("PermissionsCautionEnabled"))
-			{
-				args["FOOTERTEXT"] = (count > 1) ? LLTrans::getString("AdditionalPermissionsRequestHeader") + "\n\n" + script_question : "";
-				notification = "ScriptQuestionCaution";
-			}
-			else if(experienceid.notNull())
-			{
-				payload["experience"]=experienceid;
+            // check whether cautions are even enabled or not
+            const char* notification = "ScriptQuestion";
+
+            if(caution && gSavedSettings.getBOOL("PermissionsCautionEnabled"))
+            {
+                args["FOOTERTEXT"] = (count > 1) ? LLTrans::getString("AdditionalPermissionsRequestHeader") + "\n\n" + script_question : "";
+                notification = "ScriptQuestionCaution";
+            }
+            else if(experienceid.notNull())
+            {
+                payload["experience"]=experienceid;
                 LLExperienceCache::instance().get(experienceid, boost::bind(process_script_experience_details, _1, args, payload));
-				return;
-			}
+                return;
+            }
 
-			LLNotificationsUtil::add(notification, args, payload);
-		}
-	}
+            LLNotificationsUtil::add(notification, args, payload);
+        }
+    }
 }
 
 
 void process_derez_container(LLMessageSystem *msg, void**)
 {
-	LL_WARNS("Messaging") << "call to deprecated process_derez_container" << LL_ENDL;
+    LL_WARNS("Messaging") << "call to deprecated process_derez_container" << LL_ENDL;
 }
 
 void container_inventory_arrived(LLViewerObject* object,
-								 LLInventoryObject::object_list_t* inventory,
-								 S32 serial_num,
-								 void* data)
-{
-	LL_DEBUGS("Messaging") << "container_inventory_arrived()" << LL_ENDL;
-	if( gAgentCamera.cameraMouselook() )
-	{
-		gAgentCamera.changeCameraToDefault();
-	}
-
-	LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
-
-	if (inventory->size() > 2)
-	{
-		// create a new inventory category to put this in
-		LLUUID cat_id;
-		gInventory.createNewCategory(
+                                 LLInventoryObject::object_list_t* inventory,
+                                 S32 serial_num,
+                                 void* data)
+{
+    LL_DEBUGS("Messaging") << "container_inventory_arrived()" << LL_ENDL;
+    if( gAgentCamera.cameraMouselook() )
+    {
+        gAgentCamera.changeCameraToDefault();
+    }
+
+    LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
+
+    if (inventory->size() > 2)
+    {
+        // create a new inventory category to put this in
+        LLUUID cat_id;
+        gInventory.createNewCategory(
             gInventory.getRootFolderID(),
             LLFolderType::FT_NONE,
             LLTrans::getString("AcquiredItems"),
@@ -6523,589 +6523,589 @@ void container_inventory_arrived(LLViewerObject* object,
                     gInventory.updateItem(new_item);
                 }
             }
-            gInventory.notifyObservers();
+            gInventory.notifyObservers();
+
+            LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
+            if (active_panel)
+            {
+                active_panel->setSelection(new_cat_id, TAKE_FOCUS_NO);
+            }
+        });
+    }
+    else if (inventory->size() == 2)
+    {
+        // we're going to get one fake root category as well as the
+        // one actual object
+        LLInventoryObject::object_list_t::iterator it = inventory->begin();
+
+        if ((*it)->getType() == LLAssetType::AT_CATEGORY)
+        {
+            ++it;
+        }
+
+        LLInventoryItem* item = (LLInventoryItem*)((LLInventoryObject*)(*it));
+        const LLUUID category = gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(item->getType()));
+
+        LLUUID item_id;
+        item_id.generate();
+        time_t creation_date_utc = time_corrected();
+        LLPointer<LLViewerInventoryItem> new_item
+            = new LLViewerInventoryItem(item_id, category,
+                                        item->getPermissions(),
+                                        item->getAssetUUID(),
+                                        item->getType(),
+                                        item->getInventoryType(),
+                                        item->getName(),
+                                        item->getDescription(),
+                                        LLSaleInfo::DEFAULT,
+                                        item->getFlags(),
+                                        creation_date_utc);
+        new_item->updateServer(TRUE);
+        gInventory.updateItem(new_item);
+        gInventory.notifyObservers();
+        if(active_panel)
+        {
+            active_panel->setSelection(item_id, TAKE_FOCUS_NO);
+        }
+    }
+
+    // we've got the inventory, now delete this object if this was a take
+    BOOL delete_object = (BOOL)(intptr_t)data;
+    LLViewerRegion *region = gAgent.getRegion();
+    if (delete_object && region)
+    {
+        gMessageSystem->newMessageFast(_PREHASH_ObjectDelete);
+        gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+        gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        const U8 NO_FORCE = 0;
+        gMessageSystem->addU8Fast(_PREHASH_Force, NO_FORCE);
+        gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+        gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
+        gMessageSystem->sendReliable(region->getHost());
+    }
+}
+
+// method to format the time.
+std::string formatted_time(const time_t& the_time)
+{
+    std::string dateStr = "["+LLTrans::getString("LTimeWeek")+"] ["
+                        +LLTrans::getString("LTimeMonth")+"] ["
+                        +LLTrans::getString("LTimeDay")+"] ["
+                        +LLTrans::getString("LTimeHour")+"]:["
+                        +LLTrans::getString("LTimeMin")+"]:["
+                        +LLTrans::getString("LTimeSec")+"] ["
+                        +LLTrans::getString("LTimeYear")+"]";
+
+    LLSD substitution;
+    substitution["datetime"] = (S32) the_time;
+    LLStringUtil::format (dateStr, substitution);
+    return dateStr;
+}
+
+
+void process_teleport_failed(LLMessageSystem *msg, void**)
+{
+    LL_WARNS("Teleport","Messaging") << "Received TeleportFailed message" << LL_ENDL;
+
+    std::string message_id;     // Tag from server, like "RegionEntryAccessBlocked"
+    std::string big_reason;     // Actual message to display
+    LLSD args;
+
+    // Let the interested parties know that teleport failed.
+    LLViewerParcelMgr::getInstance()->onTeleportFailed();
+
+    // if we have additional alert data
+    if (msg->has(_PREHASH_AlertInfo) && msg->getSizeFast(_PREHASH_AlertInfo, _PREHASH_Message) > 0)
+    {
+        // Get the message ID
+        msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, message_id);
+        big_reason = LLAgent::sTeleportErrorMessages[message_id];
+        if ( big_reason.size() <= 0 )
+        {
+            // Nothing found in the map - use what the server returned in the original message block
+            msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, big_reason);
+        }
+        LL_WARNS("Teleport") << "AlertInfo message_id " << message_id << " reason: " << big_reason << LL_ENDL;
+
+        LLSD llsd_block;
+        std::string llsd_raw;
+        msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams, llsd_raw);
+        if (llsd_raw.length())
+        {
+            std::istringstream llsd_data(llsd_raw);
+            if (!LLSDSerialize::deserialize(llsd_block, llsd_data, llsd_raw.length()))
+            {
+                LL_WARNS("Teleport") << "process_teleport_failed: Attempted to read alert parameter data into LLSD but failed:" << llsd_raw << LL_ENDL;
+            }
+            else
+            {
+                LL_WARNS("Teleport") << "AlertInfo llsd block received: " << llsd_block << LL_ENDL;
+                if(llsd_block.has("REGION_NAME"))
+                {
+                    std::string region_name = llsd_block["REGION_NAME"].asString();
+                    if(!region_name.empty())
+                    {
+                        LLStringUtil::format_map_t name_args;
+                        name_args["[REGION_NAME]"] = region_name;
+                        LLStringUtil::format(big_reason, name_args);
+                    }
+                }
+                // change notification name in this special case
+                if (handle_teleport_access_blocked(llsd_block, message_id, args["REASON"]))
+                {
+                    if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
+                    {
+                        LL_WARNS("Teleport") << "called handle_teleport_access_blocked, setting state to TELEPORT_NONE" << LL_ENDL;
+                        gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
+                    }
+                    return;
+                }
+            }
+        }
+        args["REASON"] = big_reason;
+    }
+    else
+    {   // Extra message payload not found - use what the simulator sent
+        msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, message_id);
 
-            LLInventoryPanel *active_panel = LLInventoryPanel::getActiveInventoryPanel();
-            if (active_panel)
-            {
-                active_panel->setSelection(new_cat_id, TAKE_FOCUS_NO);
-            }
-        });
-	}
-	else if (inventory->size() == 2)
-	{
-		// we're going to get one fake root category as well as the
-		// one actual object
-		LLInventoryObject::object_list_t::iterator it = inventory->begin();
-
-		if ((*it)->getType() == LLAssetType::AT_CATEGORY)
-		{
-			++it;
-		}
-
-		LLInventoryItem* item = (LLInventoryItem*)((LLInventoryObject*)(*it));
-		const LLUUID category = gInventory.findCategoryUUIDForType(LLFolderType::assetTypeToFolderType(item->getType()));
-
-		LLUUID item_id;
-		item_id.generate();
-		time_t creation_date_utc = time_corrected();
-		LLPointer<LLViewerInventoryItem> new_item
-			= new LLViewerInventoryItem(item_id, category,
-										item->getPermissions(),
-										item->getAssetUUID(),
-										item->getType(),
-										item->getInventoryType(),
-										item->getName(),
-										item->getDescription(),
-										LLSaleInfo::DEFAULT,
-										item->getFlags(),
-										creation_date_utc);
-		new_item->updateServer(TRUE);
-		gInventory.updateItem(new_item);
-		gInventory.notifyObservers();
-		if(active_panel)
-		{
-			active_panel->setSelection(item_id, TAKE_FOCUS_NO);
-		}
-	}
-
-	// we've got the inventory, now delete this object if this was a take
-	BOOL delete_object = (BOOL)(intptr_t)data;
-	LLViewerRegion *region = gAgent.getRegion();
-	if (delete_object && region)
-	{
-		gMessageSystem->newMessageFast(_PREHASH_ObjectDelete);
-		gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-		gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		const U8 NO_FORCE = 0;
-		gMessageSystem->addU8Fast(_PREHASH_Force, NO_FORCE);
-		gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-		gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, object->getLocalID());
-		gMessageSystem->sendReliable(region->getHost());
-	}
+        big_reason = LLAgent::sTeleportErrorMessages[message_id];
+        if ( big_reason.size() > 0 )
+        {   // Substitute verbose reason from the local map
+            args["REASON"] = big_reason;
+        }
+        else
+        {   // Nothing found in the map - use what the server returned
+            args["REASON"] = message_id;
+        }
+    }
+    LL_WARNS("Teleport") << "Displaying CouldNotTeleportReason string, REASON= " << args["REASON"] << LL_ENDL;
+
+    LLNotificationsUtil::add("CouldNotTeleportReason", args);
+
+    if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
+    {
+        LL_WARNS("Teleport") << "End of process_teleport_failed(). Reason message arg is " << args["REASON"]
+                             << ". Setting state to TELEPORT_NONE" << LL_ENDL;
+        gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
+    }
 }
 
-// method to format the time.
-std::string formatted_time(const time_t& the_time)
+void process_teleport_local(LLMessageSystem *msg,void**)
 {
-	std::string dateStr = "["+LLTrans::getString("LTimeWeek")+"] ["
-						+LLTrans::getString("LTimeMonth")+"] ["
-						+LLTrans::getString("LTimeDay")+"] ["
-						+LLTrans::getString("LTimeHour")+"]:["
-						+LLTrans::getString("LTimeMin")+"]:["
-						+LLTrans::getString("LTimeSec")+"] ["
-						+LLTrans::getString("LTimeYear")+"]";
+    LL_INFOS("Teleport","Messaging") << "Received TeleportLocal message" << LL_ENDL;
 
-	LLSD substitution;
-	substitution["datetime"] = (S32) the_time;
-	LLStringUtil::format (dateStr, substitution);
-	return dateStr;
-}
+    LLUUID agent_id;
+    msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
+    if (agent_id != gAgent.getID())
+    {
+        LL_WARNS("Teleport", "Messaging") << "Got teleport notification for wrong agent " << agent_id << " expected " << gAgent.getID() << ", ignoring!" << LL_ENDL;
+        return;
+    }
 
+    U32 location_id;
+    LLVector3 pos, look_at;
+    U32 teleport_flags;
+    msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
+    msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
+    msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
+    msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
 
-void process_teleport_failed(LLMessageSystem *msg, void**)
-{
-	LL_WARNS("Teleport","Messaging") << "Received TeleportFailed message" << LL_ENDL;
-
-	std::string message_id;		// Tag from server, like "RegionEntryAccessBlocked"
-	std::string big_reason;		// Actual message to display
-	LLSD args;
-
-	// Let the interested parties know that teleport failed.
-	LLViewerParcelMgr::getInstance()->onTeleportFailed();
-
-	// if we have additional alert data
-	if (msg->has(_PREHASH_AlertInfo) && msg->getSizeFast(_PREHASH_AlertInfo, _PREHASH_Message) > 0)
-	{
-		// Get the message ID
-		msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_Message, message_id);
-		big_reason = LLAgent::sTeleportErrorMessages[message_id];
-		if ( big_reason.size() <= 0 )
-		{
-			// Nothing found in the map - use what the server returned in the original message block
-			msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, big_reason);
-		}
-		LL_WARNS("Teleport") << "AlertInfo message_id " << message_id << " reason: " << big_reason << LL_ENDL;
-
-		LLSD llsd_block;
-		std::string llsd_raw;
-		msg->getStringFast(_PREHASH_AlertInfo, _PREHASH_ExtraParams, llsd_raw);
-		if (llsd_raw.length())
-		{
-			std::istringstream llsd_data(llsd_raw);
-			if (!LLSDSerialize::deserialize(llsd_block, llsd_data, llsd_raw.length()))
-			{
-				LL_WARNS("Teleport") << "process_teleport_failed: Attempted to read alert parameter data into LLSD but failed:" << llsd_raw << LL_ENDL;
-			}
-			else
-			{
-				LL_WARNS("Teleport") << "AlertInfo llsd block received: " << llsd_block << LL_ENDL;
-				if(llsd_block.has("REGION_NAME"))
-				{
-					std::string region_name = llsd_block["REGION_NAME"].asString();
-					if(!region_name.empty())
-					{
-						LLStringUtil::format_map_t name_args;
-						name_args["[REGION_NAME]"] = region_name;
-						LLStringUtil::format(big_reason, name_args);
-					}
-				}
-				// change notification name in this special case
-				if (handle_teleport_access_blocked(llsd_block, message_id, args["REASON"]))
-				{
-					if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
-					{
-						LL_WARNS("Teleport") << "called handle_teleport_access_blocked, setting state to TELEPORT_NONE" << LL_ENDL;
-						gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
-					}
-					return;
-				}
-			}
-		}
-		args["REASON"] = big_reason;
-	}
-	else
-	{	// Extra message payload not found - use what the simulator sent
-		msg->getStringFast(_PREHASH_Info, _PREHASH_Reason, message_id);
-
-		big_reason = LLAgent::sTeleportErrorMessages[message_id];
-		if ( big_reason.size() > 0 )
-		{	// Substitute verbose reason from the local map
-			args["REASON"] = big_reason;
-		}
-		else
-		{	// Nothing found in the map - use what the server returned
-			args["REASON"] = message_id;
-		}
-	}
-	LL_WARNS("Teleport") << "Displaying CouldNotTeleportReason string, REASON= " << args["REASON"] << LL_ENDL;
-
-	LLNotificationsUtil::add("CouldNotTeleportReason", args);
-
-	if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
-	{
-		LL_WARNS("Teleport") << "End of process_teleport_failed(). Reason message arg is " << args["REASON"]
-							 << ". Setting state to TELEPORT_NONE" << LL_ENDL;
-		gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
-	}
-}
+    LL_INFOS("Teleport") << "Message params are location_id " << location_id << " teleport_flags " << teleport_flags << LL_ENDL;
+    if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
+    {
+        if( gAgent.getTeleportState() == LLAgent::TELEPORT_LOCAL )
+        {
+            // To prevent TeleportStart messages re-activating the progress screen right
+            // after tp, keep the teleport state and let progress screen clear it after a short delay
+            // (progress screen is active but not visible)  *TODO: remove when SVC-5290 is fixed
+            gTeleportDisplayTimer.reset();
+            gTeleportDisplay = TRUE;
+        }
+        else
+        {
+            LL_WARNS("Teleport") << "State is not TELEPORT_LOCAL: " << gAgent.getTeleportStateName()
+                                 << ", setting state to TELEPORT_NONE" << LL_ENDL;
+            gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
+        }
+    }
 
-void process_teleport_local(LLMessageSystem *msg,void**)
-{
-	LL_INFOS("Teleport","Messaging") << "Received TeleportLocal message" << LL_ENDL;
-	
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_Info, _PREHASH_AgentID, agent_id);
-	if (agent_id != gAgent.getID())
-	{
-		LL_WARNS("Teleport", "Messaging") << "Got teleport notification for wrong agent " << agent_id << " expected " << gAgent.getID() << ", ignoring!" << LL_ENDL;
-		return;
-	}
-
-	U32 location_id;
-	LLVector3 pos, look_at;
-	U32 teleport_flags;
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_LocationID, location_id);
-	msg->getVector3Fast(_PREHASH_Info, _PREHASH_Position, pos);
-	msg->getVector3Fast(_PREHASH_Info, _PREHASH_LookAt, look_at);
-	msg->getU32Fast(_PREHASH_Info, _PREHASH_TeleportFlags, teleport_flags);
-
-	LL_INFOS("Teleport") << "Message params are location_id " << location_id << " teleport_flags " << teleport_flags << LL_ENDL;
-	if( gAgent.getTeleportState() != LLAgent::TELEPORT_NONE )
-	{
-		if( gAgent.getTeleportState() == LLAgent::TELEPORT_LOCAL )
-		{
-			// To prevent TeleportStart messages re-activating the progress screen right
-			// after tp, keep the teleport state and let progress screen clear it after a short delay
-			// (progress screen is active but not visible)  *TODO: remove when SVC-5290 is fixed
-			gTeleportDisplayTimer.reset();
-			gTeleportDisplay = TRUE;
-		}
-		else
-		{
-			LL_WARNS("Teleport") << "State is not TELEPORT_LOCAL: " << gAgent.getTeleportStateName()
-								 << ", setting state to TELEPORT_NONE" << LL_ENDL;
-			gAgent.setTeleportState( LLAgent::TELEPORT_NONE );
-		}
-	}
-
-	// Sim tells us whether the new position is off the ground
-	if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
-	{
-		gAgent.setFlying(TRUE);
-	}
-	else
-	{
-		gAgent.setFlying(FALSE);
-	}
-
-	gAgent.setPositionAgent(pos);
-	gAgentCamera.slamLookAt(look_at);
-
-	if ( !(gAgent.getTeleportKeepsLookAt() && LLViewerJoystick::getInstance()->getOverrideCamera()) )
-	{
-		gAgentCamera.resetView(TRUE, TRUE);
-	}
-
-	// send camera update to new region
-	gAgentCamera.updateCamera();
-
-	send_agent_update(TRUE, TRUE);
-
-	// Let the interested parties know we've teleported.
-	// Vadim *HACK: Agent position seems to get reset (to render position?)
-	//              on each frame, so we have to pass the new position manually.
-	LLViewerParcelMgr::getInstance()->onTeleportFinished(true, gAgent.getPosGlobalFromAgent(pos));
+    // Sim tells us whether the new position is off the ground
+    if (teleport_flags & TELEPORT_FLAGS_IS_FLYING)
+    {
+        gAgent.setFlying(TRUE);
+    }
+    else
+    {
+        gAgent.setFlying(FALSE);
+    }
+
+    gAgent.setPositionAgent(pos);
+    gAgentCamera.slamLookAt(look_at);
+
+    if ( !(gAgent.getTeleportKeepsLookAt() && LLViewerJoystick::getInstance()->getOverrideCamera()) )
+    {
+        gAgentCamera.resetView(TRUE, TRUE);
+    }
+
+    // send camera update to new region
+    gAgentCamera.updateCamera();
+
+    send_agent_update(TRUE, TRUE);
+
+    // Let the interested parties know we've teleported.
+    // Vadim *HACK: Agent position seems to get reset (to render position?)
+    //              on each frame, so we have to pass the new position manually.
+    LLViewerParcelMgr::getInstance()->onTeleportFinished(true, gAgent.getPosGlobalFromAgent(pos));
 }
 
 void send_simple_im(const LLUUID& to_id,
-					const std::string& message,
-					EInstantMessage dialog,
-					const LLUUID& id)
-{
-	std::string my_name;
-	LLAgentUI::buildFullname(my_name);
-	send_improved_im(to_id,
-					 my_name,
-					 message,
-					 IM_ONLINE,
-					 dialog,
-					 id,
-					 NO_TIMESTAMP,
-					 (U8*)EMPTY_BINARY_BUCKET,
-					 EMPTY_BINARY_BUCKET_SIZE);
+                    const std::string& message,
+                    EInstantMessage dialog,
+                    const LLUUID& id)
+{
+    std::string my_name;
+    LLAgentUI::buildFullname(my_name);
+    send_improved_im(to_id,
+                     my_name,
+                     message,
+                     IM_ONLINE,
+                     dialog,
+                     id,
+                     NO_TIMESTAMP,
+                     (U8*)EMPTY_BINARY_BUCKET,
+                     EMPTY_BINARY_BUCKET_SIZE);
 }
 
 void send_group_notice(const LLUUID& group_id,
-					   const std::string& subject,
-					   const std::string& message,
-					   const LLInventoryItem* item)
-{
-	// Put this notice into an instant message form.
-	// This will mean converting the item to a binary bucket,
-	// and the subject/message into a single field.
-	std::string my_name;
-	LLAgentUI::buildFullname(my_name);
-
-	// Combine subject + message into a single string.
-	std::ostringstream subject_and_message;
-	// TODO: turn all existing |'s into ||'s in subject and message.
-	subject_and_message << subject << "|" << message;
-
-	// Create an empty binary bucket.
-	U8 bin_bucket[MAX_INVENTORY_BUFFER_SIZE];
-	U8* bucket_to_send = bin_bucket;
-	bin_bucket[0] = '\0';
-	S32 bin_bucket_size = EMPTY_BINARY_BUCKET_SIZE;
-	// If there is an item being sent, pack it into the binary bucket.
-	if (item)
-	{
-		LLSD item_def;
-		item_def["item_id"] = item->getUUID();
-		item_def["owner_id"] = item->getPermissions().getOwner();
-		std::ostringstream ostr;
-		LLSDSerialize::serialize(item_def, ostr, LLSDSerialize::LLSD_XML);
-		bin_bucket_size = ostr.str().copy(
-			(char*)bin_bucket, ostr.str().size());
-		bin_bucket[bin_bucket_size] = '\0';
-	}
-	else
-	{
-		bucket_to_send = (U8*) EMPTY_BINARY_BUCKET;
-	}
-   
-
-	send_improved_im(
-			group_id,
-			my_name,
-			subject_and_message.str(),
-			IM_ONLINE,
-			IM_GROUP_NOTICE,
-			LLUUID::null,
-			NO_TIMESTAMP,
-			bucket_to_send,
-			bin_bucket_size);
+                       const std::string& subject,
+                       const std::string& message,
+                       const LLInventoryItem* item)
+{
+    // Put this notice into an instant message form.
+    // This will mean converting the item to a binary bucket,
+    // and the subject/message into a single field.
+    std::string my_name;
+    LLAgentUI::buildFullname(my_name);
+
+    // Combine subject + message into a single string.
+    std::ostringstream subject_and_message;
+    // TODO: turn all existing |'s into ||'s in subject and message.
+    subject_and_message << subject << "|" << message;
+
+    // Create an empty binary bucket.
+    U8 bin_bucket[MAX_INVENTORY_BUFFER_SIZE];
+    U8* bucket_to_send = bin_bucket;
+    bin_bucket[0] = '\0';
+    S32 bin_bucket_size = EMPTY_BINARY_BUCKET_SIZE;
+    // If there is an item being sent, pack it into the binary bucket.
+    if (item)
+    {
+        LLSD item_def;
+        item_def["item_id"] = item->getUUID();
+        item_def["owner_id"] = item->getPermissions().getOwner();
+        std::ostringstream ostr;
+        LLSDSerialize::serialize(item_def, ostr, LLSDSerialize::LLSD_XML);
+        bin_bucket_size = ostr.str().copy(
+            (char*)bin_bucket, ostr.str().size());
+        bin_bucket[bin_bucket_size] = '\0';
+    }
+    else
+    {
+        bucket_to_send = (U8*) EMPTY_BINARY_BUCKET;
+    }
+
+
+    send_improved_im(
+            group_id,
+            my_name,
+            subject_and_message.str(),
+            IM_ONLINE,
+            IM_GROUP_NOTICE,
+            LLUUID::null,
+            NO_TIMESTAMP,
+            bucket_to_send,
+            bin_bucket_size);
 }
 
 void send_lures(const LLSD& notification, const LLSD& response)
 {
-	std::string text = response["message"].asString();
-	LLSLURL slurl;
-	LLAgentUI::buildSLURL(slurl);
-	text.append("\r\n").append(slurl.getSLURLString());
+    std::string text = response["message"].asString();
+    LLSLURL slurl;
+    LLAgentUI::buildSLURL(slurl);
+    text.append("\r\n").append(slurl.getSLURLString());
 
 // [RLVa:KB] - Checked: RLVa-2.0.0
-	// Filter the lure message if any of the recipients are IM-blocked
-	const LLSD& sdRecipients = notification["payload"]["ids"];
-	if ( (gRlvHandler.isEnabled()) && 
-	     (std::any_of(sdRecipients.beginArray(), sdRecipients.endArray(), [](const LLSD& id) { return !RlvActions::canStartIM(id.asUUID()) || !RlvActions::canSendIM(id.asUUID()); })) )
-	{
-		text = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
-	}
+    // Filter the lure message if any of the recipients are IM-blocked
+    const LLSD& sdRecipients = notification["payload"]["ids"];
+    if ( (gRlvHandler.isEnabled()) &&
+         (std::any_of(sdRecipients.beginArray(), sdRecipients.endArray(), [](const LLSD& id) { return !RlvActions::canStartIM(id.asUUID()) || !RlvActions::canSendIM(id.asUUID()); })) )
+    {
+        text = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
+    }
 // [/RLVa:KB]
 
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_StartLure);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_Info);
-	msg->addU8Fast(_PREHASH_LureType, (U8)0); // sim will fill this in.
-	msg->addStringFast(_PREHASH_Message, text);
-	for(const auto& llsd_val : notification["payload"]["ids"].asArray())
-	{
-		LLUUID target_id = llsd_val.asUUID();
-
-		msg->nextBlockFast(_PREHASH_TargetData);
-		msg->addUUIDFast(_PREHASH_TargetID, target_id);
-
-		// Record the offer.
-		{
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_StartLure);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_Info);
+    msg->addU8Fast(_PREHASH_LureType, (U8)0); // sim will fill this in.
+    msg->addStringFast(_PREHASH_Message, text);
+    for(const auto& llsd_val : notification["payload"]["ids"].asArray())
+    {
+        LLUUID target_id = llsd_val.asUUID();
+
+        msg->nextBlockFast(_PREHASH_TargetData);
+        msg->addUUIDFast(_PREHASH_TargetID, target_id);
+
+        // Record the offer.
+        {
 // [RLVa:KB] - Checked: RLVa-2.0.1
-			bool fRlvCanShowName = (!notification["payload"].has("rlv_shownames")) ? true : !notification["payload"]["rlv_shownames"].asBoolean();
+            bool fRlvCanShowName = (!notification["payload"].has("rlv_shownames")) ? true : !notification["payload"]["rlv_shownames"].asBoolean();
 // [/RLVa:KB]
-			LLAvatarName av_name;
-			LLAvatarNameCache::get(target_id, &av_name);  // for im log filenames
-			LLSD args;
+            LLAvatarName av_name;
+            LLAvatarNameCache::get(target_id, &av_name);  // for im log filenames
+            LLSD args;
 // [SL:KB] - Patch: Notification-Logging | Checked: 2012-08-23 (Catznip-3.3)
 // [RLVa:KB] - Checked: RLVa-2.0.1
-			args["TO_NAME"] = LLSLURL("agent", target_id, (fRlvCanShowName) ? "completename" : "rlvanonym").getSLURLString();;
+            args["TO_NAME"] = LLSLURL("agent", target_id, (fRlvCanShowName) ? "completename" : "rlvanonym").getSLURLString();;
 // [/RLVa:KB]
-//			args["TO_NAME"] = LLSLURL("agent", target_id, "completename").getSLURLString();;
+//          args["TO_NAME"] = LLSLURL("agent", target_id, "completename").getSLURLString();;
 // [/SL:KB]
-//			args["TO_NAME"] = LLSLURL("agent", target_id, "displayname").getSLURLString();;
+//          args["TO_NAME"] = LLSLURL("agent", target_id, "displayname").getSLURLString();;
 
-	
-			LLSD payload;
-				
-			//*TODO please rewrite all keys to the same case, lower or upper
-			payload["from_id"] = target_id;
-			payload["SUPPRESS_TOAST"] = true;
-			LLNotificationsUtil::add("TeleportOfferSent", args, payload);
 
-			// Add the recepient to the recent people list.
+            LLSD payload;
+
+            //*TODO please rewrite all keys to the same case, lower or upper
+            payload["from_id"] = target_id;
+            payload["SUPPRESS_TOAST"] = true;
+            LLNotificationsUtil::add("TeleportOfferSent", args, payload);
+
+            // Add the recepient to the recent people list.
 // [RLVa:KB] - Checked: RLVa-2.0.1
-			if (fRlvCanShowName)
-				LLRecentPeople::instance().add(target_id);
+            if (fRlvCanShowName)
+                LLRecentPeople::instance().add(target_id);
 // [/RLVa:KB]
-//			LLRecentPeople::instance().add(target_id);
-		}
-	}
-	gAgent.sendReliableMessage();
+//          LLRecentPeople::instance().add(target_id);
+        }
+    }
+    gAgent.sendReliableMessage();
 }
 
 bool handle_lure_callback(const LLSD& notification, const LLSD& response)
 {
-	static const unsigned OFFER_RECIPIENT_LIMIT = 250;
-	if(notification["payload"]["ids"].size() > OFFER_RECIPIENT_LIMIT) 
-	{
-		// More than OFFER_RECIPIENT_LIMIT targets will overload the message
-		// producing an llerror.
-		LLSD args;
-		args["OFFERS"] = LLSD::Integer(notification["payload"]["ids"].size());
-		args["LIMIT"] = static_cast<int>(OFFER_RECIPIENT_LIMIT);
-		LLNotificationsUtil::add("TooManyTeleportOffers", args);
-		return false;
-	}
+    static const unsigned OFFER_RECIPIENT_LIMIT = 250;
+    if(notification["payload"]["ids"].size() > OFFER_RECIPIENT_LIMIT)
+    {
+        // More than OFFER_RECIPIENT_LIMIT targets will overload the message
+        // producing an llerror.
+        LLSD args;
+        args["OFFERS"] = LLSD::Integer(notification["payload"]["ids"].size());
+        args["LIMIT"] = static_cast<int>(OFFER_RECIPIENT_LIMIT);
+        LLNotificationsUtil::add("TooManyTeleportOffers", args);
+        return false;
+    }
 
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 
-	if(0 == option)
-	{
-		send_lures(notification, response);
-	}
+    if(0 == option)
+    {
+        send_lures(notification, response);
+    }
 
-	return false;
+    return false;
 }
 
 void handle_lure(const LLUUID& invitee)
 {
-	std::vector<LLUUID> ids;
-	ids.push_back(invitee);
-	handle_lure(ids);
+    std::vector<LLUUID> ids;
+    ids.push_back(invitee);
+    handle_lure(ids);
 }
 
 // Prompt for a message to the invited user.
 void handle_lure(const uuid_vec_t& ids)
 {
-	if (ids.empty()) return;
+    if (ids.empty()) return;
 
-	if (!gAgent.getRegion()) return;
+    if (!gAgent.getRegion()) return;
 
-	LLSD edit_args;
+    LLSD edit_args;
 // [RLVa:KB] - Checked: 2010-04-07 (RLVa-1.2.0d) | Modified: RLVa-1.0.0a
-	edit_args["REGION"] = (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) ? gAgent.getRegion()->getName() : RlvStrings::getString(RlvStringKeys::Hidden::Generic);
+    edit_args["REGION"] = (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC)) ? gAgent.getRegion()->getName() : RlvStrings::getString(RlvStringKeys::Hidden::Generic);
 // [/RLVa:KB]
-//	edit_args["REGION"] = gAgent.getRegion()->getName();
+//  edit_args["REGION"] = gAgent.getRegion()->getName();
 
-	LLSD payload;
+    LLSD payload;
 // [RLVa:KB] - Checked: RLVa-2.0.1
-	bool fRlvShouldHideNames = false;
-	for (const LLUUID& idAgent : ids)
-	{
-		// Only allow offering teleports if everyone is a @tplure exception or able to map this avie under @showloc=n
-		if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC))
-		{
-			const LLRelationship* pBuddyInfo = LLAvatarTracker::instance().getBuddyInfo(idAgent);
-			if ( (!gRlvHandler.isException(RLV_BHVR_TPLURE, idAgent, ERlvExceptionCheck::Permissive)) &&
-				 ((!pBuddyInfo) || (!pBuddyInfo->isOnline()) || (!pBuddyInfo->isRightGrantedTo(LLRelationship::GRANT_MAP_LOCATION))) )
-			{
-				RlvUtil::notifyBlocked(RlvStringKeys::Blocked::TeleportOffer);
-				return;
-			}
-		}
-		fRlvShouldHideNames |= !RlvActions::canShowName(RlvActions::SNC_TELEPORTOFFER, idAgent);
-		payload["ids"].append(idAgent);
-	}
-	payload["rlv_shownames"] = fRlvShouldHideNames;
+    bool fRlvShouldHideNames = false;
+    for (const LLUUID& idAgent : ids)
+    {
+        // Only allow offering teleports if everyone is a @tplure exception or able to map this avie under @showloc=n
+        if (gRlvHandler.hasBehaviour(RLV_BHVR_SHOWLOC))
+        {
+            const LLRelationship* pBuddyInfo = LLAvatarTracker::instance().getBuddyInfo(idAgent);
+            if ( (!gRlvHandler.isException(RLV_BHVR_TPLURE, idAgent, ERlvExceptionCheck::Permissive)) &&
+                 ((!pBuddyInfo) || (!pBuddyInfo->isOnline()) || (!pBuddyInfo->isRightGrantedTo(LLRelationship::GRANT_MAP_LOCATION))) )
+            {
+                RlvUtil::notifyBlocked(RlvStringKeys::Blocked::TeleportOffer);
+                return;
+            }
+        }
+        fRlvShouldHideNames |= !RlvActions::canShowName(RlvActions::SNC_TELEPORTOFFER, idAgent);
+        payload["ids"].append(idAgent);
+    }
+    payload["rlv_shownames"] = fRlvShouldHideNames;
 // [/RLVa:KB]
-// 	for (std::vector<LLUUID>::const_iterator it = ids.begin();
-// 		it != ids.end();
-// 		++it)
-// 	{
-// 		payload["ids"].append(*it);
-// 	}
-	if (gAgent.isGodlike())
-	{
-		LLNotificationsUtil::add("OfferTeleportFromGod", edit_args, payload, handle_lure_callback);
-	}
-	else
-	{
-		LLNotificationsUtil::add("OfferTeleport", edit_args, payload, handle_lure_callback);
-	}
+//  for (std::vector<LLUUID>::const_iterator it = ids.begin();
+//      it != ids.end();
+//      ++it)
+//  {
+//      payload["ids"].append(*it);
+//  }
+    if (gAgent.isGodlike())
+    {
+        LLNotificationsUtil::add("OfferTeleportFromGod", edit_args, payload, handle_lure_callback);
+    }
+    else
+    {
+        LLNotificationsUtil::add("OfferTeleport", edit_args, payload, handle_lure_callback);
+    }
 }
 
 bool teleport_request_callback(const LLSD& notification, const LLSD& response)
 {
-	LLUUID from_id = notification["payload"]["from_id"].asUUID();
-	if(from_id.isNull())
-	{
-		LL_WARNS() << "from_id is NULL" << LL_ENDL;
-		return false;
-	}
-
-	LLAvatarName av_name;
-	LLAvatarNameCache::get(from_id, &av_name);
-
-	if(LLMuteList::getInstance()->isMuted(from_id) && !LLMuteList::isLinden(av_name.getUserName()))
-	{
-		return false;
-	}
-
-	S32 option = 0;
-	if (response.isInteger()) 
-	{
-		option = response.asInteger();
-	}
-	else
-	{
-		option = LLNotificationsUtil::getSelectedOption(notification, response);
-	}
-
-	switch(option)
-	{
-	// Yes
-	case 0:
-		{
-			LLSD dummy_notification;
-			dummy_notification["payload"]["ids"][0] = from_id;
-
-			LLSD dummy_response;
-			dummy_response["message"] = response["message"];
-
-			send_lures(dummy_notification, dummy_response);
-		}
-		break;
-
-	// No
-	case 1:
-	default:
-		break;
-	}
-
-	return false;
+    LLUUID from_id = notification["payload"]["from_id"].asUUID();
+    if(from_id.isNull())
+    {
+        LL_WARNS() << "from_id is NULL" << LL_ENDL;
+        return false;
+    }
+
+    LLAvatarName av_name;
+    LLAvatarNameCache::get(from_id, &av_name);
+
+    if(LLMuteList::getInstance()->isMuted(from_id) && !LLMuteList::isLinden(av_name.getUserName()))
+    {
+        return false;
+    }
+
+    S32 option = 0;
+    if (response.isInteger())
+    {
+        option = response.asInteger();
+    }
+    else
+    {
+        option = LLNotificationsUtil::getSelectedOption(notification, response);
+    }
+
+    switch(option)
+    {
+    // Yes
+    case 0:
+        {
+            LLSD dummy_notification;
+            dummy_notification["payload"]["ids"][0] = from_id;
+
+            LLSD dummy_response;
+            dummy_response["message"] = response["message"];
+
+            send_lures(dummy_notification, dummy_response);
+        }
+        break;
+
+    // No
+    case 1:
+    default:
+        break;
+    }
+
+    return false;
 }
 
 static LLNotificationFunctorRegistration teleport_request_callback_reg("TeleportRequest", teleport_request_callback);
 
 void send_improved_im(const LLUUID& to_id,
-							const std::string& name,
-							const std::string& message,
-							U8 offline,
-							EInstantMessage dialog,
-							const LLUUID& id,
-							U32 timestamp, 
-							const U8* binary_bucket,
-							S32 binary_bucket_size)
-{
-	pack_instant_message(
-		gMessageSystem,
-		gAgent.getID(),
-		FALSE,
-		gAgent.getSessionID(),
-		to_id,
-		name,
-		message,
-		offline,
-		dialog,
-		id,
-		0,
-		LLUUID::null,
-		gAgent.getPositionAgent(),
-		timestamp,
-		binary_bucket,
-		binary_bucket_size);
-	gAgent.sendReliableMessage();
+                            const std::string& name,
+                            const std::string& message,
+                            U8 offline,
+                            EInstantMessage dialog,
+                            const LLUUID& id,
+                            U32 timestamp,
+                            const U8* binary_bucket,
+                            S32 binary_bucket_size)
+{
+    pack_instant_message(
+        gMessageSystem,
+        gAgent.getID(),
+        FALSE,
+        gAgent.getSessionID(),
+        to_id,
+        name,
+        message,
+        offline,
+        dialog,
+        id,
+        0,
+        LLUUID::null,
+        gAgent.getPositionAgent(),
+        timestamp,
+        binary_bucket,
+        binary_bucket_size);
+    gAgent.sendReliableMessage();
 }
 
 
 void send_places_query(const LLUUID& query_id,
-					   const LLUUID& trans_id,
-					   const std::string& query_text,
-					   U32 query_flags,
-					   S32 category,
-					   const std::string& sim_name)
-{
-	LLMessageSystem* msg = gMessageSystem;
-
-	msg->newMessageFast(_PREHASH_PlacesQuery);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_QueryID, query_id);
-	msg->nextBlockFast(_PREHASH_TransactionData);
-	msg->addUUIDFast(_PREHASH_TransactionID, trans_id);
-	msg->nextBlockFast(_PREHASH_QueryData);
-	msg->addStringFast(_PREHASH_QueryText, query_text);
-	msg->addU32Fast(_PREHASH_QueryFlags, query_flags);
-	msg->addS8Fast(_PREHASH_Category, (S8)category);
-	msg->addStringFast(_PREHASH_SimName, sim_name);
-	gAgent.sendReliableMessage();
+                       const LLUUID& trans_id,
+                       const std::string& query_text,
+                       U32 query_flags,
+                       S32 category,
+                       const std::string& sim_name)
+{
+    LLMessageSystem* msg = gMessageSystem;
+
+    msg->newMessageFast(_PREHASH_PlacesQuery);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addUUIDFast(_PREHASH_QueryID, query_id);
+    msg->nextBlockFast(_PREHASH_TransactionData);
+    msg->addUUIDFast(_PREHASH_TransactionID, trans_id);
+    msg->nextBlockFast(_PREHASH_QueryData);
+    msg->addStringFast(_PREHASH_QueryText, query_text);
+    msg->addU32Fast(_PREHASH_QueryFlags, query_flags);
+    msg->addS8Fast(_PREHASH_Category, (S8)category);
+    msg->addStringFast(_PREHASH_SimName, sim_name);
+    gAgent.sendReliableMessage();
 }
 
 // Deprecated in favor of cap "UserInfo"
 void process_user_info_reply(LLMessageSystem* msg, void**)
 {
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	if(agent_id != gAgent.getID())
-	{
-		LL_WARNS("Messaging") << "process_user_info_reply - "
-				<< "wrong agent id." << LL_ENDL;
-	}
-	
-	BOOL im_via_email = FALSE;
-	if (!LLGridManager::instance().isInSecondlife())
-		msg->getBOOLFast(_PREHASH_UserData, _PREHASH_IMViaEMail, im_via_email);
-	std::string email;
-	msg->getStringFast(_PREHASH_UserData, _PREHASH_EMail, email);
-	std::string dir_visibility;
-	msg->getStringFast(_PREHASH_UserData, _PREHASH_DirectoryVisibility, dir_visibility);
+    LLUUID agent_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+    if(agent_id != gAgent.getID())
+    {
+        LL_WARNS("Messaging") << "process_user_info_reply - "
+                << "wrong agent id." << LL_ENDL;
+    }
+
+    BOOL im_via_email = FALSE;
+    if (!LLGridManager::instance().isInSecondlife())
+        msg->getBOOLFast(_PREHASH_UserData, _PREHASH_IMViaEMail, im_via_email);
+    std::string email;
+    msg->getStringFast(_PREHASH_UserData, _PREHASH_EMail, email);
+    std::string dir_visibility;
+    msg->getStringFast(_PREHASH_UserData, _PREHASH_DirectoryVisibility, dir_visibility);
 
     // For Message based user info information the is_verified is assumed to be false.
-	LLFloaterPreference::updateUserInfo(dir_visibility, im_via_email, false, email);   
-	LLFloaterSnapshot::setAgentEmail(email);
+    LLFloaterPreference::updateUserInfo(dir_visibility, im_via_email, false, email);
+    LLFloaterSnapshot::setAgentEmail(email);
 }
 
 
@@ -7118,149 +7118,149 @@ const char* SCRIPT_DIALOG_HEADER = "Script Dialog:\n";
 
 bool callback_script_dialog(const LLSD& notification, const LLSD& response)
 {
-	LLNotificationForm form(notification["form"]);
-
-	std::string rtn_text;
-	S32 button_idx;
-	button_idx = LLNotification::getSelectedOption(notification, response);
-	if (response[TEXTBOX_MAGIC_TOKEN].isDefined())
-	{
-		if (response[TEXTBOX_MAGIC_TOKEN].isString())
-			rtn_text = response[TEXTBOX_MAGIC_TOKEN].asString();
-		else
-			rtn_text.clear(); // bool marks empty string
-	}
-	else
-	{
-		rtn_text = LLNotification::getSelectedOptionName(response);
-	}
-
-	// Button -2 = Mute
-	// Button -1 = Ignore - no processing needed for this button
-	// Buttons 0 and above = dialog choices
-
-	if (-2 == button_idx)
-	{
-		std::string object_name = notification["payload"]["object_name"].asString();
-		LLUUID object_id = notification["payload"]["object_id"].asUUID();
-		LLMute mute(object_id, object_name, LLMute::OBJECT);
-		if (LLMuteList::getInstance()->add(mute))
-		{
-			// This call opens the sidebar, displays the block list, and highlights the newly blocked
-			// object in the list so the user can see that their block click has taken effect.
-			//LLPanelBlockedList::showPanelAndSelect(object_id);
-			LLFloaterBlocked::showMuteAndSelect(object_id);
-		}
-	}
+    LLNotificationForm form(notification["form"]);
+
+    std::string rtn_text;
+    S32 button_idx;
+    button_idx = LLNotification::getSelectedOption(notification, response);
+    if (response[TEXTBOX_MAGIC_TOKEN].isDefined())
+    {
+        if (response[TEXTBOX_MAGIC_TOKEN].isString())
+            rtn_text = response[TEXTBOX_MAGIC_TOKEN].asString();
+        else
+            rtn_text.clear(); // bool marks empty string
+    }
+    else
+    {
+        rtn_text = LLNotification::getSelectedOptionName(response);
+    }
+
+    // Button -2 = Mute
+    // Button -1 = Ignore - no processing needed for this button
+    // Buttons 0 and above = dialog choices
+
+    if (-2 == button_idx)
+    {
+        std::string object_name = notification["payload"]["object_name"].asString();
+        LLUUID object_id = notification["payload"]["object_id"].asUUID();
+        LLMute mute(object_id, object_name, LLMute::OBJECT);
+        if (LLMuteList::getInstance()->add(mute))
+        {
+            // This call opens the sidebar, displays the block list, and highlights the newly blocked
+            // object in the list so the user can see that their block click has taken effect.
+            //LLPanelBlockedList::showPanelAndSelect(object_id);
+            LLFloaterBlocked::showMuteAndSelect(object_id);
+        }
+    }
 
 // [RLVa:KB] - @sendchat and @sendchannel/sendchannelexcept
-	if ( (RlvActions::isRlvEnabled()) && (0 <= button_idx) )
-	{
-		const S32 nChannel = notification["payload"]["chat_channel"].asInteger();
-
-		// *TODO-RLVa: it's too late into the release cycle to block all script interactions so just take care of the nearby chat loophole for now
-		bool fBlock = (0 == nChannel) ? RlvActions::hasBehaviour(RLV_BHVR_SENDCHAT) : /*!RlvActions::canSendChannel(nChannel)*/false;
-		if (fBlock)
-		{
-			button_idx = -1;
-		}
-	}
+    if ( (RlvActions::isRlvEnabled()) && (0 <= button_idx) )
+    {
+        const S32 nChannel = notification["payload"]["chat_channel"].asInteger();
+
+        // *TODO-RLVa: it's too late into the release cycle to block all script interactions so just take care of the nearby chat loophole for now
+        bool fBlock = (0 == nChannel) ? RlvActions::hasBehaviour(RLV_BHVR_SENDCHAT) : /*!RlvActions::canSendChannel(nChannel)*/false;
+        if (fBlock)
+        {
+            button_idx = -1;
+        }
+    }
 // [/RLVa:KB]
 
-	if (0 <= button_idx)
-	{
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_ScriptDialogReply);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_Data);
-		msg->addUUIDFast(_PREHASH_ObjectID, notification["payload"]["object_id"].asUUID());
-		msg->addS32Fast(_PREHASH_ChatChannel, notification["payload"]["chat_channel"].asInteger());
-		msg->addS32Fast(_PREHASH_ButtonIndex, button_idx);
-		msg->addStringFast(_PREHASH_ButtonLabel, rtn_text);
-		msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
-	}
-
-	return false;
+    if (0 <= button_idx)
+    {
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_ScriptDialogReply);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        msg->nextBlockFast(_PREHASH_Data);
+        msg->addUUIDFast(_PREHASH_ObjectID, notification["payload"]["object_id"].asUUID());
+        msg->addS32Fast(_PREHASH_ChatChannel, notification["payload"]["chat_channel"].asInteger());
+        msg->addS32Fast(_PREHASH_ButtonIndex, button_idx);
+        msg->addStringFast(_PREHASH_ButtonLabel, rtn_text);
+        msg->sendReliable(LLHost(notification["payload"]["sender"].asString()));
+    }
+
+    return false;
 }
 static LLNotificationFunctorRegistration callback_script_dialog_reg_1("ScriptDialog", callback_script_dialog);
 static LLNotificationFunctorRegistration callback_script_dialog_reg_2("ScriptDialogGroup", callback_script_dialog);
 
 void process_script_dialog(LLMessageSystem* msg, void**)
 {
-	S32 i;
-	LLSD payload;
+    S32 i;
+    LLSD payload;
 
-	LLUUID object_id;
-	msg->getUUIDFast(_PREHASH_Data, _PREHASH_ObjectID, object_id);
+    LLUUID object_id;
+    msg->getUUIDFast(_PREHASH_Data, _PREHASH_ObjectID, object_id);
 
-//	For compability with OS grids first check for presence of extended packet before fetching data.
+//  For compability with OS grids first check for presence of extended packet before fetching data.
     LLUUID owner_id;
-	if (gMessageSystem->getNumberOfBlocksFast(_PREHASH_OwnerData) > 0)
-	{
-		msg->getUUIDFast(_PREHASH_OwnerData, _PREHASH_OwnerID, owner_id);
-	}
-
-	if (LLMuteList::getInstance()->isMuted(object_id) || LLMuteList::getInstance()->isMuted(owner_id))
-	{
-		return;
-	}
-
-	std::string message; 
-	std::string first_name;
-	std::string last_name;
-	std::string object_name;
-
-	S32 chat_channel;
-	msg->getStringFast(_PREHASH_Data, _PREHASH_FirstName, first_name);
-	msg->getStringFast(_PREHASH_Data, _PREHASH_LastName, last_name);
-	msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
-	msg->getStringFast(_PREHASH_Data, _PREHASH_Message, message);
-	msg->getS32Fast(_PREHASH_Data, _PREHASH_ChatChannel, chat_channel);
-
-		// unused for now
-	LLUUID image_id;
-	msg->getUUIDFast(_PREHASH_Data, _PREHASH_ImageID, image_id);
-
-	payload["sender"] = msg->getSender().getIPandPort();
-	payload["object_id"] = object_id;
-	payload["chat_channel"] = chat_channel;
-	payload["object_name"] = object_name;
-
-	// build up custom form
-	S32 button_count = msg->getNumberOfBlocksFast(_PREHASH_Buttons);
-	if (button_count > SCRIPT_DIALOG_MAX_BUTTONS)
-	{
-		LL_WARNS() << "Too many script dialog buttons - omitting some" << LL_ENDL;
-		button_count = SCRIPT_DIALOG_MAX_BUTTONS;
-	}
-
-	LLNotificationForm form;
-	for (i = 0; i < button_count; i++)
-	{
-		std::string tdesc;
-		msg->getStringFast(_PREHASH_Buttons, _PREHASH_ButtonLabel, tdesc, i);
-		form.addElement("button", std::string(tdesc));
-	}
-
-	LLSD args;
-	args["TITLE"] = object_name;
-	args["MESSAGE"] = message;
+    if (gMessageSystem->getNumberOfBlocksFast(_PREHASH_OwnerData) > 0)
+    {
+        msg->getUUIDFast(_PREHASH_OwnerData, _PREHASH_OwnerID, owner_id);
+    }
+
+    if (LLMuteList::getInstance()->isMuted(object_id) || LLMuteList::getInstance()->isMuted(owner_id))
+    {
+        return;
+    }
+
+    std::string message;
+    std::string first_name;
+    std::string last_name;
+    std::string object_name;
+
+    S32 chat_channel;
+    msg->getStringFast(_PREHASH_Data, _PREHASH_FirstName, first_name);
+    msg->getStringFast(_PREHASH_Data, _PREHASH_LastName, last_name);
+    msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
+    msg->getStringFast(_PREHASH_Data, _PREHASH_Message, message);
+    msg->getS32Fast(_PREHASH_Data, _PREHASH_ChatChannel, chat_channel);
+
+        // unused for now
+    LLUUID image_id;
+    msg->getUUIDFast(_PREHASH_Data, _PREHASH_ImageID, image_id);
+
+    payload["sender"] = msg->getSender().getIPandPort();
+    payload["object_id"] = object_id;
+    payload["chat_channel"] = chat_channel;
+    payload["object_name"] = object_name;
+
+    // build up custom form
+    S32 button_count = msg->getNumberOfBlocksFast(_PREHASH_Buttons);
+    if (button_count > SCRIPT_DIALOG_MAX_BUTTONS)
+    {
+        LL_WARNS() << "Too many script dialog buttons - omitting some" << LL_ENDL;
+        button_count = SCRIPT_DIALOG_MAX_BUTTONS;
+    }
+
+    LLNotificationForm form;
+    for (i = 0; i < button_count; i++)
+    {
+        std::string tdesc;
+        msg->getStringFast(_PREHASH_Buttons, _PREHASH_ButtonLabel, tdesc, i);
+        form.addElement("button", std::string(tdesc));
+    }
+
+    LLSD args;
+    args["TITLE"] = object_name;
+    args["MESSAGE"] = message;
     args["CHANNEL"] = chat_channel;
-	LLNotificationPtr notification;
-	if (!first_name.empty())
-	{
-		args["NAME"] = LLCacheName::buildFullName(first_name, last_name);
-		notification = LLNotifications::instance().add(
-			LLNotification::Params("ScriptDialog").substitutions(args).payload(payload).form_elements(form.asLLSD()));
-	}
-	else
-	{
-		args["GROUPNAME"] = last_name;
-		notification = LLNotifications::instance().add(
-			LLNotification::Params("ScriptDialogGroup").substitutions(args).payload(payload).form_elements(form.asLLSD()));
-	}
+    LLNotificationPtr notification;
+    if (!first_name.empty())
+    {
+        args["NAME"] = LLCacheName::buildFullName(first_name, last_name);
+        notification = LLNotifications::instance().add(
+            LLNotification::Params("ScriptDialog").substitutions(args).payload(payload).form_elements(form.asLLSD()));
+    }
+    else
+    {
+        args["GROUPNAME"] = last_name;
+        notification = LLNotifications::instance().add(
+            LLNotification::Params("ScriptDialogGroup").substitutions(args).payload(payload).form_elements(form.asLLSD()));
+    }
 }
 
 //---------------------------------------------------------------------------
@@ -7270,14 +7270,14 @@ std::vector<LLSD> gLoadUrlList;
 
 bool callback_load_url(const LLSD& notification, const LLSD& response)
 {
-	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
+    S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 
-	if (0 == option)
-	{
-		LLWeb::loadURL(notification["payload"]["url"].asString());
-	}
+    if (0 == option)
+    {
+        LLWeb::loadURL(notification["payload"]["url"].asString());
+    }
 
-	return false;
+    return false;
 }
 static LLNotificationFunctorRegistration callback_load_url_reg("LoadWebPage", callback_load_url);
 
@@ -7285,42 +7285,42 @@ static LLNotificationFunctorRegistration callback_load_url_reg("LoadWebPage", ca
 // Display confirmation dialog.
 void callback_load_url_name(const LLUUID& id, const std::string& full_name, bool is_group)
 {
-	std::vector<LLSD>::iterator it;
-	for (it = gLoadUrlList.begin(); it != gLoadUrlList.end(); )
-	{
-		LLSD load_url_info = *it;
-		if (load_url_info["owner_id"].asUUID() == id)
-		{
-			it = gLoadUrlList.erase(it);
-
-			std::string owner_name;
-			if (is_group)
-			{
-				owner_name = full_name + LLTrans::getString("Group");
-			}
-			else
-			{
-				owner_name = full_name;
-			}
-
-			// For legacy name-only mutes.
-			if (LLMuteList::getInstance()->isMuted(LLUUID::null, owner_name))
-			{
-				continue;
-			}
-			LLSD args;
-			args["URL"] = load_url_info["url"].asString();
-			args["MESSAGE"] = load_url_info["message"].asString();;
-			args["OBJECTNAME"] = load_url_info["object_name"].asString();
-			args["NAME_SLURL"] = LLSLURL(is_group ? "group" : "agent", id, "about").getSLURLString();
-
-			LLNotificationsUtil::add("LoadWebPage", args, load_url_info);
-		}
-		else
-		{
-			++it;
-		}
-	}
+    std::vector<LLSD>::iterator it;
+    for (it = gLoadUrlList.begin(); it != gLoadUrlList.end(); )
+    {
+        LLSD load_url_info = *it;
+        if (load_url_info["owner_id"].asUUID() == id)
+        {
+            it = gLoadUrlList.erase(it);
+
+            std::string owner_name;
+            if (is_group)
+            {
+                owner_name = full_name + LLTrans::getString("Group");
+            }
+            else
+            {
+                owner_name = full_name;
+            }
+
+            // For legacy name-only mutes.
+            if (LLMuteList::getInstance()->isMuted(LLUUID::null, owner_name))
+            {
+                continue;
+            }
+            LLSD args;
+            args["URL"] = load_url_info["url"].asString();
+            args["MESSAGE"] = load_url_info["message"].asString();;
+            args["OBJECTNAME"] = load_url_info["object_name"].asString();
+            args["NAME_SLURL"] = LLSLURL(is_group ? "group" : "agent", id, "about").getSLURLString();
+
+            LLNotificationsUtil::add("LoadWebPage", args, load_url_info);
+        }
+        else
+        {
+            ++it;
+        }
+    }
 }
 
 // We've got the name of the person who owns the object hurling the url.
@@ -7331,296 +7331,296 @@ void callback_load_url_avatar_name(const LLUUID& id, const LLAvatarName& av_name
 
 void process_load_url(LLMessageSystem* msg, void**)
 {
-	LLUUID object_id;
-	LLUUID owner_id;
-	BOOL owner_is_group;
-	char object_name[256];		/* Flawfinder: ignore */
-	char message[256];		/* Flawfinder: ignore */
-	char url[256];		/* Flawfinder: ignore */
-
-	msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, 256, object_name);
-	msg->getUUIDFast(  _PREHASH_Data, _PREHASH_ObjectID, object_id);
-	msg->getUUIDFast(  _PREHASH_Data, _PREHASH_OwnerID, owner_id);
-	msg->getBOOLFast(  _PREHASH_Data, _PREHASH_OwnerIsGroup, owner_is_group);
-	msg->getStringFast(_PREHASH_Data, _PREHASH_Message, 256, message);
-	msg->getStringFast(_PREHASH_Data, _PREHASH_URL, 256, url);
-
-	LLSD payload;
-	payload["object_id"] = object_id;
-	payload["owner_id"] = owner_id;
-	payload["owner_is_group"] = owner_is_group;
-	payload["object_name"] = object_name;
-	payload["message"] = message;
-	payload["url"] = url;
-
-	// URL is safety checked in load_url above
-
-	// Check if object or owner is muted
-	if (LLMuteList::getInstance()->isMuted(object_id, object_name) ||
-	    LLMuteList::getInstance()->isMuted(owner_id))
-	{
-		LL_INFOS("Messaging")<<"Ignoring load_url from muted object/owner."<<LL_ENDL;
-		return;
-	}
-
-	// Add to list of pending name lookups
-	gLoadUrlList.push_back(payload);
-
-	if (owner_is_group)
-	{
-		gCacheName->getGroup(owner_id, boost::bind(&callback_load_url_name, _1, _2, _3));
-	}
-	else
-	{
-		LLAvatarNameCache::get(owner_id, boost::bind(&callback_load_url_avatar_name, _1, _2));
-	}
+    LLUUID object_id;
+    LLUUID owner_id;
+    BOOL owner_is_group;
+    char object_name[256];      /* Flawfinder: ignore */
+    char message[256];      /* Flawfinder: ignore */
+    char url[256];      /* Flawfinder: ignore */
+
+    msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, 256, object_name);
+    msg->getUUIDFast(  _PREHASH_Data, _PREHASH_ObjectID, object_id);
+    msg->getUUIDFast(  _PREHASH_Data, _PREHASH_OwnerID, owner_id);
+    msg->getBOOLFast(  _PREHASH_Data, _PREHASH_OwnerIsGroup, owner_is_group);
+    msg->getStringFast(_PREHASH_Data, _PREHASH_Message, 256, message);
+    msg->getStringFast(_PREHASH_Data, _PREHASH_URL, 256, url);
+
+    LLSD payload;
+    payload["object_id"] = object_id;
+    payload["owner_id"] = owner_id;
+    payload["owner_is_group"] = owner_is_group;
+    payload["object_name"] = object_name;
+    payload["message"] = message;
+    payload["url"] = url;
+
+    // URL is safety checked in load_url above
+
+    // Check if object or owner is muted
+    if (LLMuteList::getInstance()->isMuted(object_id, object_name) ||
+        LLMuteList::getInstance()->isMuted(owner_id))
+    {
+        LL_INFOS("Messaging")<<"Ignoring load_url from muted object/owner."<<LL_ENDL;
+        return;
+    }
+
+    // Add to list of pending name lookups
+    gLoadUrlList.push_back(payload);
+
+    if (owner_is_group)
+    {
+        gCacheName->getGroup(owner_id, boost::bind(&callback_load_url_name, _1, _2, _3));
+    }
+    else
+    {
+        LLAvatarNameCache::get(owner_id, boost::bind(&callback_load_url_avatar_name, _1, _2));
+    }
 }
 
 
 void callback_download_complete(void** data, S32 result, LLExtStat ext_status)
 {
-	std::string* filepath = (std::string*)data;
-	LLSD args;
-	args["DOWNLOAD_PATH"] = *filepath;
-	LLNotificationsUtil::add("FinishedRawDownload", args);
-	delete filepath;
+    std::string* filepath = (std::string*)data;
+    LLSD args;
+    args["DOWNLOAD_PATH"] = *filepath;
+    LLNotificationsUtil::add("FinishedRawDownload", args);
+    delete filepath;
 }
 
 
 void process_initiate_download(LLMessageSystem* msg, void**)
 {
-	LLUUID agent_id;
-	msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
-	if (agent_id != gAgent.getID())
-	{
-		LL_WARNS("Messaging") << "Initiate download for wrong agent" << LL_ENDL;
-		return;
-	}
-
-	std::string sim_filename;
-	std::string viewer_filename;
-	msg->getStringFast(_PREHASH_FileData, _PREHASH_SimFilename, sim_filename);
-	msg->getStringFast(_PREHASH_FileData, _PREHASH_ViewerFilename, viewer_filename);
-
-	if (!gXferManager->validateFileForRequest(viewer_filename))
-	{
-		LL_WARNS() << "SECURITY: Unauthorized download to local file " << viewer_filename << LL_ENDL;
-		return;
-	}
-	gXferManager->requestFile(viewer_filename,
-		sim_filename,
-		LL_PATH_NONE,
-		msg->getSender(),
-		FALSE,	// don't delete remote
-		callback_download_complete,
-		(void**)new std::string(viewer_filename));
+    LLUUID agent_id;
+    msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id);
+    if (agent_id != gAgent.getID())
+    {
+        LL_WARNS("Messaging") << "Initiate download for wrong agent" << LL_ENDL;
+        return;
+    }
+
+    std::string sim_filename;
+    std::string viewer_filename;
+    msg->getStringFast(_PREHASH_FileData, _PREHASH_SimFilename, sim_filename);
+    msg->getStringFast(_PREHASH_FileData, _PREHASH_ViewerFilename, viewer_filename);
+
+    if (!gXferManager->validateFileForRequest(viewer_filename))
+    {
+        LL_WARNS() << "SECURITY: Unauthorized download to local file " << viewer_filename << LL_ENDL;
+        return;
+    }
+    gXferManager->requestFile(viewer_filename,
+        sim_filename,
+        LL_PATH_NONE,
+        msg->getSender(),
+        FALSE,  // don't delete remote
+        callback_download_complete,
+        (void**)new std::string(viewer_filename));
 }
 
 
 void process_script_teleport_request(LLMessageSystem* msg, void**)
 {
-	if (!gSavedSettings.getBOOL("ScriptsCanShowUI")) return;
+    if (!gSavedSettings.getBOOL("ScriptsCanShowUI")) return;
+
+    std::string object_name;
+    std::string sim_name;
+    LLVector3 pos;
+    LLVector3 look_at;
 
-	std::string object_name;
-	std::string sim_name;
-	LLVector3 pos;
-	LLVector3 look_at;
+    msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
+    msg->getStringFast(_PREHASH_Data, _PREHASH_SimName, sim_name);
+    msg->getVector3Fast(_PREHASH_Data, _PREHASH_SimPosition, pos);
+    msg->getVector3Fast(_PREHASH_Data, _PREHASH_LookAt, look_at);
 
-	msg->getStringFast(_PREHASH_Data, _PREHASH_ObjectName, object_name);
-	msg->getStringFast(_PREHASH_Data, _PREHASH_SimName, sim_name);
-	msg->getVector3Fast(_PREHASH_Data, _PREHASH_SimPosition, pos);
-	msg->getVector3Fast(_PREHASH_Data, _PREHASH_LookAt, look_at);
+    LLFloaterWorldMap* instance = LLFloaterWorldMap::getInstance();
+    if(instance)
+    {
+        LL_INFOS() << "Object named " << object_name
+            << " is offering TP to region "
+            << sim_name << " position " << pos
+            << LL_ENDL;
+
+        instance->trackURL(sim_name, (S32)pos.mV[VX], (S32)pos.mV[VY], (S32)pos.mV[VZ]);
+        LLFloaterReg::showInstance("world_map", "center");
+    }
 
-	LLFloaterWorldMap* instance = LLFloaterWorldMap::getInstance();
-	if(instance)
-	{
-		LL_INFOS() << "Object named " << object_name 
-			<< " is offering TP to region "
-			<< sim_name << " position " << pos
-			<< LL_ENDL;
+    // remove above two lines and replace with below line
+    // to re-enable parcel browser for llMapDestination()
+    // LLURLDispatcher::dispatch(LLSLURL::buildSLURL(sim_name, (S32)pos.mV[VX], (S32)pos.mV[VY], (S32)pos.mV[VZ]), FALSE);
 
-		instance->trackURL(sim_name, (S32)pos.mV[VX], (S32)pos.mV[VY], (S32)pos.mV[VZ]);
-		LLFloaterReg::showInstance("world_map", "center");
-	}
-	
-	// remove above two lines and replace with below line
-	// to re-enable parcel browser for llMapDestination()
-	// LLURLDispatcher::dispatch(LLSLURL::buildSLURL(sim_name, (S32)pos.mV[VX], (S32)pos.mV[VY], (S32)pos.mV[VZ]), FALSE);
-	
 }
 
 void process_covenant_reply(LLMessageSystem* msg, void**)
 {
-	LLUUID covenant_id, estate_owner_id;
-	std::string estate_name;
-	U32 covenant_timestamp;
-	msg->getUUIDFast(_PREHASH_Data, _PREHASH_CovenantID, covenant_id);
-	msg->getU32Fast(_PREHASH_Data, _PREHASH_CovenantTimestamp, covenant_timestamp);
-	msg->getStringFast(_PREHASH_Data, _PREHASH_EstateName, estate_name);
-	msg->getUUIDFast(_PREHASH_Data, _PREHASH_EstateOwnerID, estate_owner_id);
-
-	LLPanelEstateCovenant::updateEstateName(estate_name);
-	LLPanelLandCovenant::updateEstateName(estate_name);
-	LLPanelEstateInfo::updateEstateName(estate_name);
-	LLFloaterBuyLand::updateEstateName(estate_name);
-
-	std::string owner_name =
-		LLSLURL("agent", estate_owner_id, "inspect").getSLURLString();
-	LLPanelEstateCovenant::updateEstateOwnerName(owner_name);
-	LLPanelLandCovenant::updateEstateOwnerName(owner_name);
-	LLPanelEstateInfo::updateEstateOwnerName(owner_name);
-	LLFloaterBuyLand::updateEstateOwnerName(owner_name);
-
-	LLPanelPlaceProfile* panel = LLFloaterSidePanelContainer::getPanel<LLPanelPlaceProfile>("places", "panel_place_profile");
-	if (panel)
-	{
-		panel->updateEstateName(estate_name);
-		panel->updateEstateOwnerName(owner_name);
-	}
-
-	// standard message, not from system
-	std::string last_modified;
-	if (covenant_timestamp == 0)
-	{
-		last_modified = LLTrans::getString("covenant_last_modified")+LLTrans::getString("never_text");
-	}
-	else
-	{
-		last_modified = LLTrans::getString("covenant_last_modified")+"["
-						+LLTrans::getString("LTimeWeek")+"] ["
-						+LLTrans::getString("LTimeMonth")+"] ["
-						+LLTrans::getString("LTimeDay")+"] ["
-						+LLTrans::getString("LTimeHour")+"]:["
-						+LLTrans::getString("LTimeMin")+"]:["
-						+LLTrans::getString("LTimeSec")+"] ["
-						+LLTrans::getString("LTimeYear")+"]";
-		LLSD substitution;
-		substitution["datetime"] = (S32) covenant_timestamp;
-		LLStringUtil::format (last_modified, substitution);
-	}
-
-	LLPanelEstateCovenant::updateLastModified(last_modified);
-	LLPanelLandCovenant::updateLastModified(last_modified);
-	LLFloaterBuyLand::updateLastModified(last_modified);
-
-	// load the actual covenant asset data
-	const BOOL high_priority = TRUE;
-	if (covenant_id.notNull())
-	{
-		gAssetStorage->getEstateAsset(gAgent.getRegionHost(),
-									gAgent.getID(),
-									gAgent.getSessionID(),
-									covenant_id,
+    LLUUID covenant_id, estate_owner_id;
+    std::string estate_name;
+    U32 covenant_timestamp;
+    msg->getUUIDFast(_PREHASH_Data, _PREHASH_CovenantID, covenant_id);
+    msg->getU32Fast(_PREHASH_Data, _PREHASH_CovenantTimestamp, covenant_timestamp);
+    msg->getStringFast(_PREHASH_Data, _PREHASH_EstateName, estate_name);
+    msg->getUUIDFast(_PREHASH_Data, _PREHASH_EstateOwnerID, estate_owner_id);
+
+    LLPanelEstateCovenant::updateEstateName(estate_name);
+    LLPanelLandCovenant::updateEstateName(estate_name);
+    LLPanelEstateInfo::updateEstateName(estate_name);
+    LLFloaterBuyLand::updateEstateName(estate_name);
+
+    std::string owner_name =
+        LLSLURL("agent", estate_owner_id, "inspect").getSLURLString();
+    LLPanelEstateCovenant::updateEstateOwnerName(owner_name);
+    LLPanelLandCovenant::updateEstateOwnerName(owner_name);
+    LLPanelEstateInfo::updateEstateOwnerName(owner_name);
+    LLFloaterBuyLand::updateEstateOwnerName(owner_name);
+
+    LLPanelPlaceProfile* panel = LLFloaterSidePanelContainer::getPanel<LLPanelPlaceProfile>("places", "panel_place_profile");
+    if (panel)
+    {
+        panel->updateEstateName(estate_name);
+        panel->updateEstateOwnerName(owner_name);
+    }
+
+    // standard message, not from system
+    std::string last_modified;
+    if (covenant_timestamp == 0)
+    {
+        last_modified = LLTrans::getString("covenant_last_modified")+LLTrans::getString("never_text");
+    }
+    else
+    {
+        last_modified = LLTrans::getString("covenant_last_modified")+"["
+                        +LLTrans::getString("LTimeWeek")+"] ["
+                        +LLTrans::getString("LTimeMonth")+"] ["
+                        +LLTrans::getString("LTimeDay")+"] ["
+                        +LLTrans::getString("LTimeHour")+"]:["
+                        +LLTrans::getString("LTimeMin")+"]:["
+                        +LLTrans::getString("LTimeSec")+"] ["
+                        +LLTrans::getString("LTimeYear")+"]";
+        LLSD substitution;
+        substitution["datetime"] = (S32) covenant_timestamp;
+        LLStringUtil::format (last_modified, substitution);
+    }
+
+    LLPanelEstateCovenant::updateLastModified(last_modified);
+    LLPanelLandCovenant::updateLastModified(last_modified);
+    LLFloaterBuyLand::updateLastModified(last_modified);
+
+    // load the actual covenant asset data
+    const BOOL high_priority = TRUE;
+    if (covenant_id.notNull())
+    {
+        gAssetStorage->getEstateAsset(gAgent.getRegionHost(),
+                                    gAgent.getID(),
+                                    gAgent.getSessionID(),
+                                    covenant_id,
                                     LLAssetType::AT_NOTECARD,
-									ET_Covenant,
+                                    ET_Covenant,
                                     onCovenantLoadComplete,
-									NULL,
-									high_priority);
-	}
-	else
-	{
-		std::string covenant_text;
-		if (estate_owner_id.isNull())
-		{
-			// mainland
-			covenant_text = LLTrans::getString("RegionNoCovenant");
-		}
-		else
-		{
-			covenant_text = LLTrans::getString("RegionNoCovenantOtherOwner");
-		}
-		LLPanelEstateCovenant::updateCovenantText(covenant_text, covenant_id);
-		LLPanelLandCovenant::updateCovenantText(covenant_text);
-		LLFloaterBuyLand::updateCovenantText(covenant_text, covenant_id);
-		if (panel)
-		{
-			panel->updateCovenantText(covenant_text);
-		}
-	}
+                                    NULL,
+                                    high_priority);
+    }
+    else
+    {
+        std::string covenant_text;
+        if (estate_owner_id.isNull())
+        {
+            // mainland
+            covenant_text = LLTrans::getString("RegionNoCovenant");
+        }
+        else
+        {
+            covenant_text = LLTrans::getString("RegionNoCovenantOtherOwner");
+        }
+        LLPanelEstateCovenant::updateCovenantText(covenant_text, covenant_id);
+        LLPanelLandCovenant::updateCovenantText(covenant_text);
+        LLFloaterBuyLand::updateCovenantText(covenant_text, covenant_id);
+        if (panel)
+        {
+            panel->updateCovenantText(covenant_text);
+        }
+    }
 }
 
 void onCovenantLoadComplete(const LLUUID& asset_uuid,
-							LLAssetType::EType type,
-							void* user_data, S32 status, LLExtStat ext_status)
-{
-	LL_DEBUGS("Messaging") << "onCovenantLoadComplete()" << LL_ENDL;
-	std::string covenant_text;
-	if(0 == status)
-	{
-		LLFileSystem file(asset_uuid, type, LLFileSystem::READ);
-		
-		S32 file_length = file.getSize();
-		
-		std::vector<char> buffer(file_length+1);
-		file.read((U8*)&buffer[0], file_length);		
-		// put a EOS at the end
-		buffer[file_length] = '\0';
-		
-		if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) )
-		{
-			LLViewerTextEditor::Params params;
-			params.name("temp");
-			params.max_text_length(file_length+1);
-			LLViewerTextEditor * editor = LLUICtrlFactory::create<LLViewerTextEditor> (params);
-			if( !editor->importBuffer( &buffer[0], file_length+1 ) )
-			{
-				LL_WARNS("Messaging") << "Problem importing estate covenant." << LL_ENDL;
-				covenant_text = "Problem importing estate covenant.";
-			}
-			else
-			{
-				// Version 0 (just text, doesn't include version number)
-				covenant_text = editor->getText();
-			}
-			delete editor;
-		}
-		else
-		{
-			LL_WARNS("Messaging") << "Problem importing estate covenant: Covenant file format error." << LL_ENDL;
-			covenant_text = "Problem importing estate covenant: Covenant file format error.";
-		}
-	}
-	else
-	{
-		if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
-		    LL_ERR_FILE_EMPTY == status)
-		{
-			covenant_text = "Estate covenant notecard is missing from database.";
-		}
-		else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
-		{
-			covenant_text = "Insufficient permissions to view estate covenant.";
-		}
-		else
-		{
-			covenant_text = "Unable to load estate covenant at this time.";
-		}
-		
-		LL_WARNS("Messaging") << "Problem loading notecard: " << status << LL_ENDL;
-	}
-	LLPanelEstateCovenant::updateCovenantText(covenant_text, asset_uuid);
-	LLPanelLandCovenant::updateCovenantText(covenant_text);
-	LLFloaterBuyLand::updateCovenantText(covenant_text, asset_uuid);
-
-	LLPanelPlaceProfile* panel = LLFloaterSidePanelContainer::getPanel<LLPanelPlaceProfile>("places", "panel_place_profile");
-	if (panel)
-	{
-		panel->updateCovenantText(covenant_text);
-	}
+                            LLAssetType::EType type,
+                            void* user_data, S32 status, LLExtStat ext_status)
+{
+    LL_DEBUGS("Messaging") << "onCovenantLoadComplete()" << LL_ENDL;
+    std::string covenant_text;
+    if(0 == status)
+    {
+        LLFileSystem file(asset_uuid, type, LLFileSystem::READ);
+
+        S32 file_length = file.getSize();
+
+        std::vector<char> buffer(file_length+1);
+        file.read((U8*)&buffer[0], file_length);
+        // put a EOS at the end
+        buffer[file_length] = '\0';
+
+        if( (file_length > 19) && !strncmp( &buffer[0], "Linden text version", 19 ) )
+        {
+            LLViewerTextEditor::Params params;
+            params.name("temp");
+            params.max_text_length(file_length+1);
+            LLViewerTextEditor * editor = LLUICtrlFactory::create<LLViewerTextEditor> (params);
+            if( !editor->importBuffer( &buffer[0], file_length+1 ) )
+            {
+                LL_WARNS("Messaging") << "Problem importing estate covenant." << LL_ENDL;
+                covenant_text = "Problem importing estate covenant.";
+            }
+            else
+            {
+                // Version 0 (just text, doesn't include version number)
+                covenant_text = editor->getText();
+            }
+            delete editor;
+        }
+        else
+        {
+            LL_WARNS("Messaging") << "Problem importing estate covenant: Covenant file format error." << LL_ENDL;
+            covenant_text = "Problem importing estate covenant: Covenant file format error.";
+        }
+    }
+    else
+    {
+        if( LL_ERR_ASSET_REQUEST_NOT_IN_DATABASE == status ||
+            LL_ERR_FILE_EMPTY == status)
+        {
+            covenant_text = "Estate covenant notecard is missing from database.";
+        }
+        else if (LL_ERR_INSUFFICIENT_PERMISSIONS == status)
+        {
+            covenant_text = "Insufficient permissions to view estate covenant.";
+        }
+        else
+        {
+            covenant_text = "Unable to load estate covenant at this time.";
+        }
+
+        LL_WARNS("Messaging") << "Problem loading notecard: " << status << LL_ENDL;
+    }
+    LLPanelEstateCovenant::updateCovenantText(covenant_text, asset_uuid);
+    LLPanelLandCovenant::updateCovenantText(covenant_text);
+    LLFloaterBuyLand::updateCovenantText(covenant_text, asset_uuid);
+
+    LLPanelPlaceProfile* panel = LLFloaterSidePanelContainer::getPanel<LLPanelPlaceProfile>("places", "panel_place_profile");
+    if (panel)
+    {
+        panel->updateCovenantText(covenant_text);
+    }
 }
 
 
 void process_feature_disabled_message(LLMessageSystem* msg, void**)
 {
-	// Handle Blacklisted feature simulator response...
-	LLUUID	agentID;
-	LLUUID	transactionID;
-	std::string	messageText;
-	msg->getStringFast(_PREHASH_FailureInfo,_PREHASH_ErrorMessage, messageText,0);
-	msg->getUUIDFast(_PREHASH_FailureInfo,_PREHASH_AgentID,agentID);
-	msg->getUUIDFast(_PREHASH_FailureInfo,_PREHASH_TransactionID,transactionID);
-	
-	LL_WARNS("Messaging") << "Blacklisted Feature Response:" << messageText << LL_ENDL;
+    // Handle Blacklisted feature simulator response...
+    LLUUID  agentID;
+    LLUUID  transactionID;
+    std::string messageText;
+    msg->getStringFast(_PREHASH_FailureInfo,_PREHASH_ErrorMessage, messageText,0);
+    msg->getUUIDFast(_PREHASH_FailureInfo,_PREHASH_AgentID,agentID);
+    msg->getUUIDFast(_PREHASH_FailureInfo,_PREHASH_TransactionID,transactionID);
+
+    LL_WARNS("Messaging") << "Blacklisted Feature Response:" << messageText << LL_ENDL;
 }
 
 // ------------------------------------------------------------
@@ -7628,8 +7628,8 @@ void process_feature_disabled_message(LLMessageSystem* msg, void**)
 // ------------------------------------------------------------
 
 void invalid_message_callback(LLMessageSystem* msg,
-								   void*,
-								   EMessageException exception)
+                                   void*,
+                                   EMessageException exception)
 {
     LLAppViewer::instance()->badNetworkHandler();
 }
@@ -7639,8 +7639,8 @@ void invalid_message_callback(LLMessageSystem* msg,
 
 void LLOfferInfo::forceResponse(InventoryOfferResponse response)
 {
-	LLNotification::Params params("UserGiveItem");
-	params.functor.function(boost::bind(&LLOfferInfo::inventory_offer_callback, this, _1, _2));
-	LLNotifications::instance().forceResponse(params, response);
+    LLNotification::Params params("UserGiveItem");
+    params.functor.function(boost::bind(&LLOfferInfo::inventory_offer_callback, this, _1, _2));
+    LLNotifications::instance().forceResponse(params, response);
 }
 
diff --git a/indra/newview/llviewermessage.h b/indra/newview/llviewermessage.h
index e1768d3f9f79bd424d259f0c0cd5d50b7e83b8a5..e893aba59514c9d74d44ac91b4646ee2100ee0ec 100644
--- a/indra/newview/llviewermessage.h
+++ b/indra/newview/llviewermessage.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewermessage.h
  * @brief Message system callbacks for viewer.
  *
  * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -57,20 +57,20 @@ class LLViewerRegion;
 
 enum InventoryOfferResponse
 {
-	IOR_ACCEPT,
-	IOR_DECLINE,
-	IOR_MUTE,
-	IOR_SHOW
+    IOR_ACCEPT,
+    IOR_DECLINE,
+    IOR_MUTE,
+    IOR_SHOW
 };
 
 BOOL can_afford_transaction(S32 cost);
 void give_money(const LLUUID& uuid, LLViewerRegion* region, S32 amount, BOOL is_group = FALSE,
-				S32 trx_type = TRANS_GIFT, const std::string& desc = LLStringUtil::null);
+                S32 trx_type = TRANS_GIFT, const std::string& desc = LLStringUtil::null);
 void send_join_group_response(LLUUID group_id,
-							  LLUUID transaction_id,
-							  bool accept_invite,
-							  S32 fee,
-							  bool use_offline_cap);
+                              LLUUID transaction_id,
+                              bool accept_invite,
+                              S32 fee,
+                              bool use_offline_cap);
 
 void process_logout_reply(LLMessageSystem* msg, void**);
 void process_layer_data(LLMessageSystem *mesgsys, void **user_data);
@@ -89,12 +89,12 @@ void process_cached_object_update(LLMessageSystem *mesgsys, void **user_data);
 void process_terse_object_update_improved(LLMessageSystem *mesgsys, void **user_data);
 
 void send_simulator_throttle_settings(const LLHost &host);
-void process_kill_object(	LLMessageSystem *mesgsys, void **user_data);
-void process_time_synch(	LLMessageSystem *mesgsys, void **user_data);
+void process_kill_object(   LLMessageSystem *mesgsys, void **user_data);
+void process_time_synch(    LLMessageSystem *mesgsys, void **user_data);
 void process_sound_trigger(LLMessageSystem *mesgsys, void **user_data);
-void process_preload_sound(	LLMessageSystem *mesgsys, void **user_data);
-void process_attached_sound(	LLMessageSystem *mesgsys, void **user_data);
-void process_attached_sound_gain_change(	LLMessageSystem *mesgsys, void **user_data);
+void process_preload_sound( LLMessageSystem *mesgsys, void **user_data);
+void process_attached_sound(    LLMessageSystem *mesgsys, void **user_data);
+void process_attached_sound_gain_change(    LLMessageSystem *mesgsys, void **user_data);
 void process_energy_statistics(LLMessageSystem *mesgsys, void **user_data);
 void process_health_message(LLMessageSystem *mesgsys, void **user_data);
 void process_sim_stats(LLMessageSystem *mesgsys, void **user_data);
@@ -130,9 +130,9 @@ void process_frozen_message(LLMessageSystem* msg, void**);
 
 void process_derez_container(LLMessageSystem *msg, void**);
 void container_inventory_arrived(LLViewerObject* object,
-								 std::list<LLPointer<LLInventoryObject> >* inventory, //LLInventoryObject::object_list_t
-								 S32 serial_num,
-								 void* data);
+                                 std::list<LLPointer<LLInventoryObject> >* inventory, //LLInventoryObject::object_list_t
+                                 S32 serial_num,
+                                 void* data);
 
 // agent movement
 void send_complete_agent_movement(const LLHost& sim_host);
@@ -148,52 +148,52 @@ void process_teleport_local(LLMessageSystem *msg,void**);
 void process_user_sim_location_reply(LLMessageSystem *msg,void**);
 
 void send_simple_im(const LLUUID& to_id,
-					const std::string& message,
-					EInstantMessage dialog = IM_NOTHING_SPECIAL,
-					const LLUUID& id = LLUUID::null);
+                    const std::string& message,
+                    EInstantMessage dialog = IM_NOTHING_SPECIAL,
+                    const LLUUID& id = LLUUID::null);
 
 void send_group_notice(const LLUUID& group_id,
-					   const std::string& subject,
-					   const std::string& message,
-					   const LLInventoryItem* item);
+                       const std::string& subject,
+                       const std::string& message,
+                       const LLInventoryItem* item);
 
 void send_do_not_disturb_message (LLMessageSystem* msg, const LLUUID& from_id, const LLUUID& session_id = LLUUID::null);
 void send_rejecting_tp_offers_message (LLMessageSystem* msg, const LLUUID& from_id, const LLUUID& session_id = LLUUID::null); // <FS:PP> FIRE-1245: Option to block/reject teleport offers
-void send_rejecting_friendship_requests_message (LLMessageSystem* msg, const LLUUID& from_id, const LLUUID& session_id = LLUUID::null); 
+void send_rejecting_friendship_requests_message (LLMessageSystem* msg, const LLUUID& from_id, const LLUUID& session_id = LLUUID::null);
 
 void handle_lure(const LLUUID& invitee);
 void handle_lure(const uuid_vec_t& ids);
 
-// always from gAgent and 
+// always from gAgent and
 // routes through the gAgent's current simulator
 void send_improved_im(const LLUUID& to_id,
-					const std::string& name,
-					const std::string& message,
-					U8 offline = IM_ONLINE,
-					EInstantMessage dialog = IM_NOTHING_SPECIAL,
-					const LLUUID& id = LLUUID::null,
-					U32 timestamp = NO_TIMESTAMP, 
-					const U8* binary_bucket = (U8*)EMPTY_BINARY_BUCKET,
-					S32 binary_bucket_size = EMPTY_BINARY_BUCKET_SIZE);
+                    const std::string& name,
+                    const std::string& message,
+                    U8 offline = IM_ONLINE,
+                    EInstantMessage dialog = IM_NOTHING_SPECIAL,
+                    const LLUUID& id = LLUUID::null,
+                    U32 timestamp = NO_TIMESTAMP,
+                    const U8* binary_bucket = (U8*)EMPTY_BINARY_BUCKET,
+                    S32 binary_bucket_size = EMPTY_BINARY_BUCKET_SIZE);
 
 void process_user_info_reply(LLMessageSystem* msg, void**);
 
-// method to format the time. 
+// method to format the time.
 std::string formatted_time(const time_t& the_time);
 
 void send_places_query(const LLUUID& query_id,
-					   const LLUUID& trans_id,
-					   const std::string& query_text,
-					   U32 query_flags,
-					   S32 category, 
-					   const std::string& sim_name);
+                       const LLUUID& trans_id,
+                       const std::string& query_text,
+                       U32 query_flags,
+                       S32 category,
+                       const std::string& sim_name);
 void process_script_dialog(LLMessageSystem* msg, void**);
 void process_load_url(LLMessageSystem* msg, void**);
 void process_script_teleport_request(LLMessageSystem* msg, void**);
 void process_covenant_reply(LLMessageSystem* msg, void**);
 void onCovenantLoadComplete(const LLUUID& asset_uuid,
-							LLAssetType::EType type,
-							void* user_data, S32 status, LLExtStat ext_status);
+                            LLAssetType::EType type,
+                            void* user_data, S32 status, LLExtStat ext_status);
 
 // calling cards
 void process_offer_callingcard(LLMessageSystem* msg, void**);
@@ -217,74 +217,74 @@ void set_dad_inbox_object(const LLUUID& object_id);
 
 class LLViewerMessage : public  LLSingleton<LLViewerMessage>
 {
-	LLSINGLETON_EMPTY_CTOR(LLViewerMessage);
+    LLSINGLETON_EMPTY_CTOR(LLViewerMessage);
 public:
-	typedef boost::function<void()> teleport_started_callback_t;
-	typedef boost::signals2::signal<void()> teleport_started_signal_t;
-	boost::signals2::connection setTeleportStartedCallback(teleport_started_callback_t cb);
+    typedef boost::function<void()> teleport_started_callback_t;
+    typedef boost::signals2::signal<void()> teleport_started_signal_t;
+    boost::signals2::connection setTeleportStartedCallback(teleport_started_callback_t cb);
 
-	teleport_started_signal_t	mTeleportStartedSignal;
+    teleport_started_signal_t   mTeleportStartedSignal;
 };
 
 class LLOfferInfo : public LLNotificationResponderInterface
 {
 public:
-	LLOfferInfo();
-	LLOfferInfo(const LLSD& sd);
+    LLOfferInfo();
+    LLOfferInfo(const LLSD& sd);
 
-	LLOfferInfo(const LLOfferInfo& info);
+    LLOfferInfo(const LLOfferInfo& info);
 
-	void forceResponse(InventoryOfferResponse response);
+    void forceResponse(InventoryOfferResponse response);
 
     static std::string mResponderType;
-	EInstantMessage mIM;
-	LLUUID mFromID;
-	BOOL mFromGroup;
-	BOOL mFromObject;
-	LLUUID mTransactionID;
-	LLUUID mFolderID;
-	LLUUID mObjectID;
-	LLAssetType::EType mType;
-	std::string mFromName;
-	std::string mDesc;
-	LLHost mHost;
-	bool mPersist;
-
-	// LLNotificationResponderInterface implementation
-	/*virtual*/ LLSD asLLSD();
-	/*virtual*/ void fromLLSD(const LLSD& params);
-	/*virtual*/ void handleRespond(const LLSD& notification, const LLSD& response);
-
-	void send_auto_receive_response() { sendReceiveResponse(true, mFolderID); }
-
-	// TODO - replace all references with handleRespond()
-	bool inventory_offer_callback(const LLSD& notification, const LLSD& response);
-	bool inventory_task_offer_callback(const LLSD& notification, const LLSD& response);
+    EInstantMessage mIM;
+    LLUUID mFromID;
+    BOOL mFromGroup;
+    BOOL mFromObject;
+    LLUUID mTransactionID;
+    LLUUID mFolderID;
+    LLUUID mObjectID;
+    LLAssetType::EType mType;
+    std::string mFromName;
+    std::string mDesc;
+    LLHost mHost;
+    bool mPersist;
+
+    // LLNotificationResponderInterface implementation
+    /*virtual*/ LLSD asLLSD();
+    /*virtual*/ void fromLLSD(const LLSD& params);
+    /*virtual*/ void handleRespond(const LLSD& notification, const LLSD& response);
+
+    void send_auto_receive_response() { sendReceiveResponse(true, mFolderID); }
+
+    // TODO - replace all references with handleRespond()
+    bool inventory_offer_callback(const LLSD& notification, const LLSD& response);
+    bool inventory_task_offer_callback(const LLSD& notification, const LLSD& response);
 
 private:
 
-	void initRespondFunctionMap();
-	std::string getSanitizedDescription();
-	void sendReceiveResponse(bool accept, const LLUUID &destination_folder_id);
+    void initRespondFunctionMap();
+    std::string getSanitizedDescription();
+    void sendReceiveResponse(bool accept, const LLUUID &destination_folder_id);
 
-	typedef boost::function<bool (const LLSD&, const LLSD&)> respond_function_t;
-	typedef std::map<std::string, respond_function_t> respond_function_map_t;
+    typedef boost::function<bool (const LLSD&, const LLSD&)> respond_function_t;
+    typedef std::map<std::string, respond_function_t> respond_function_map_t;
 
-	respond_function_map_t mRespondFunctions;
+    respond_function_map_t mRespondFunctions;
 };
 
 class LLOpenAgentOffer : public LLInventoryFetchItemsObserver
 {
 public:
-	LLOpenAgentOffer(const LLUUID& object_id, const std::string& from_name, bool is_manual_accept) : 
-		LLInventoryFetchItemsObserver(object_id),
-		mFromName(from_name),
-		mIsManuallyAccepted(is_manual_accept) {}
-	/*virtual*/ void startFetch();
-	/*virtual*/ void done();
+    LLOpenAgentOffer(const LLUUID& object_id, const std::string& from_name, bool is_manual_accept) :
+        LLInventoryFetchItemsObserver(object_id),
+        mFromName(from_name),
+        mIsManuallyAccepted(is_manual_accept) {}
+    /*virtual*/ void startFetch();
+    /*virtual*/ void done();
 private:
-	std::string mFromName;
-	bool		mIsManuallyAccepted;
+    std::string mFromName;
+    bool        mIsManuallyAccepted;
 };
 
 void process_feature_disabled_message(LLMessageSystem* msg, void**);
diff --git a/indra/newview/llviewerobject.cpp b/indra/newview/llviewerobject.cpp
index 488f35b202dce6e1f75577d6dead549719633a71..326ebe7ed447a725fcbb17febb9813741794dc0b 100644
--- a/indra/newview/llviewerobject.cpp
+++ b/indra/newview/llviewerobject.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewerobject.cpp
  * @brief Base class for viewer objects
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -116,24 +116,24 @@
 
 //#define DEBUG_UPDATE_TYPE
 
-BOOL		LLViewerObject::sVelocityInterpolate = TRUE;
-BOOL		LLViewerObject::sPingInterpolate = TRUE; 
+BOOL        LLViewerObject::sVelocityInterpolate = TRUE;
+BOOL        LLViewerObject::sPingInterpolate = TRUE;
 
-U32			LLViewerObject::sNumZombieObjects = 0;
-S32			LLViewerObject::sNumObjects = 0;
-BOOL		LLViewerObject::sMapDebug = TRUE;
-LLColor4	LLViewerObject::sEditSelectColor(	1.0f, 1.f, 0.f, 0.3f);	// Edit OK
-LLColor4	LLViewerObject::sNoEditSelectColor(	1.0f, 0.f, 0.f, 0.3f);	// Can't edit
-S32			LLViewerObject::sAxisArrowLength(50);
+U32         LLViewerObject::sNumZombieObjects = 0;
+S32         LLViewerObject::sNumObjects = 0;
+BOOL        LLViewerObject::sMapDebug = TRUE;
+LLColor4    LLViewerObject::sEditSelectColor(   1.0f, 1.f, 0.f, 0.3f);  // Edit OK
+LLColor4    LLViewerObject::sNoEditSelectColor( 1.0f, 0.f, 0.f, 0.3f);  // Can't edit
+S32         LLViewerObject::sAxisArrowLength(50);
 
 
-BOOL		LLViewerObject::sPulseEnabled(FALSE);
-BOOL		LLViewerObject::sUseSharedDrawables(FALSE); // TRUE
+BOOL        LLViewerObject::sPulseEnabled(FALSE);
+BOOL        LLViewerObject::sUseSharedDrawables(FALSE); // TRUE
 
 // sMaxUpdateInterpolationTime must be greater than sPhaseOutUpdateInterpolationTime
-F64Seconds	LLViewerObject::sMaxUpdateInterpolationTime(3.0);		// For motion interpolation: after X seconds with no updates, don't predict object motion
-F64Seconds	LLViewerObject::sPhaseOutUpdateInterpolationTime(2.0);	// For motion interpolation: after Y seconds with no updates, taper off motion prediction
-F64Seconds	LLViewerObject::sMaxRegionCrossingInterpolationTime(1.0);// For motion interpolation: don't interpolate over this time on region crossing
+F64Seconds  LLViewerObject::sMaxUpdateInterpolationTime(3.0);       // For motion interpolation: after X seconds with no updates, don't predict object motion
+F64Seconds  LLViewerObject::sPhaseOutUpdateInterpolationTime(2.0);  // For motion interpolation: after Y seconds with no updates, taper off motion prediction
+F64Seconds  LLViewerObject::sMaxRegionCrossingInterpolationTime(1.0);// For motion interpolation: don't interpolate over this time on region crossing
 
 boost::unordered_flat_map<std::string, U32> LLViewerObject::sObjectDataMap;
 
@@ -159,195 +159,195 @@ LLViewerObject *LLViewerObject::createObject(const LLUUID &id, const LLPCode pco
     LL_DEBUGS("ObjectUpdate") << "creating " << id << LL_ENDL;
     dumpStack("ObjectUpdateStack");
 #endif
-    
-	LLViewerObject *res = NULL;
-
-	if (gNonInteractive
-		&& pcode != LL_PCODE_LEGACY_AVATAR
-		&& pcode != LL_VO_SURFACE_PATCH
-		&& pcode != LL_VO_WATER
-		&& pcode != LL_VO_VOID_WATER
-		&& pcode != LL_VO_WL_SKY
-		&& pcode != LL_VO_SKY
-		&& pcode != LL_VO_PART_GROUP
-		)
-	{
-		return res;
-	}
-	switch (pcode)
-	{
-	case LL_PCODE_VOLUME:
-	{
-		res = new LLVOVolume(id, pcode, regionp); break;
-		break;
-	}
-	case LL_PCODE_LEGACY_AVATAR:
-	{
-		if (id == gAgentID)
-		{
-			if (!gAgentAvatarp)
-			{
-				gAgentAvatarp = new LLVOAvatarSelf(id, pcode, regionp);
-				gAgentAvatarp->initInstance();
-				gAgentWearables.setAvatarObject(gAgentAvatarp);
-			}
-			else 
-			{
-				if (isAgentAvatarValid())
-				{
-					gAgentAvatarp->updateRegion(regionp);
-				}
-			}
-			res = gAgentAvatarp;
-		}
-		else if (flags & CO_FLAG_CONTROL_AVATAR)
-		{
+
+    LLViewerObject *res = NULL;
+
+    if (gNonInteractive
+        && pcode != LL_PCODE_LEGACY_AVATAR
+        && pcode != LL_VO_SURFACE_PATCH
+        && pcode != LL_VO_WATER
+        && pcode != LL_VO_VOID_WATER
+        && pcode != LL_VO_WL_SKY
+        && pcode != LL_VO_SKY
+        && pcode != LL_VO_PART_GROUP
+        )
+    {
+        return res;
+    }
+    switch (pcode)
+    {
+    case LL_PCODE_VOLUME:
+    {
+        res = new LLVOVolume(id, pcode, regionp); break;
+        break;
+    }
+    case LL_PCODE_LEGACY_AVATAR:
+    {
+        if (id == gAgentID)
+        {
+            if (!gAgentAvatarp)
+            {
+                gAgentAvatarp = new LLVOAvatarSelf(id, pcode, regionp);
+                gAgentAvatarp->initInstance();
+                gAgentWearables.setAvatarObject(gAgentAvatarp);
+            }
+            else
+            {
+                if (isAgentAvatarValid())
+                {
+                    gAgentAvatarp->updateRegion(regionp);
+                }
+            }
+            res = gAgentAvatarp;
+        }
+        else if (flags & CO_FLAG_CONTROL_AVATAR)
+        {
             LLControlAvatar *control_avatar = new LLControlAvatar(id, pcode, regionp);
-			control_avatar->initInstance();
-			res = control_avatar;
-		}
+            control_avatar->initInstance();
+            res = control_avatar;
+        }
         else if (flags & CO_FLAG_UI_AVATAR)
         {
             LLUIAvatar *ui_avatar = new LLUIAvatar(id, pcode, regionp);
             ui_avatar->initInstance();
             res = ui_avatar;
         }
-		else
-		{
-			LLVOAvatar *avatar = new LLVOAvatar(id, pcode, regionp); 
-			avatar->initInstance();
-			res = avatar;
-		}
-		break;
-	}
-	case LL_PCODE_LEGACY_GRASS:
-	  res = new LLVOGrass(id, pcode, regionp); break;
-	case LL_PCODE_LEGACY_PART_SYS:
-// 	  LL_WARNS() << "Creating old part sys!" << LL_ENDL;
-// 	  res = new LLVOPart(id, pcode, regionp); break;
-	  res = NULL; break;
-	case LL_PCODE_LEGACY_TREE:
-	  res = new LLVOTree(id, pcode, regionp); break;
-	case LL_PCODE_TREE_NEW:
-// 	  LL_WARNS() << "Creating new tree!" << LL_ENDL;
-// 	  res = new LLVOTree(id, pcode, regionp); break;
-	  res = NULL; break;
-	case LL_VO_SURFACE_PATCH:
-	  res = new LLVOSurfacePatch(id, pcode, regionp); break;
-	case LL_VO_SKY:
-	  res = new LLVOSky(id, pcode, regionp); break;
-	case LL_VO_VOID_WATER:
-		res = new LLVOVoidWater(id, pcode, regionp); break;
-	case LL_VO_WATER:
-		res = new LLVOWater(id, pcode, regionp); break;
-	case LL_VO_PART_GROUP:
-	  res = new LLVOPartGroup(id, pcode, regionp); break;
-	case LL_VO_HUD_PART_GROUP:
-	  res = new LLVOHUDPartGroup(id, pcode, regionp); break;
-	case LL_VO_WL_SKY:
-	  res = new LLVOWLSky(id, pcode, regionp); break;
-	default:
-	  LL_WARNS() << "Unknown object pcode " << (S32)pcode << LL_ENDL;
-	  res = NULL; break;
-	}
-
-	return res;
+        else
+        {
+            LLVOAvatar *avatar = new LLVOAvatar(id, pcode, regionp);
+            avatar->initInstance();
+            res = avatar;
+        }
+        break;
+    }
+    case LL_PCODE_LEGACY_GRASS:
+      res = new LLVOGrass(id, pcode, regionp); break;
+    case LL_PCODE_LEGACY_PART_SYS:
+//    LL_WARNS() << "Creating old part sys!" << LL_ENDL;
+//    res = new LLVOPart(id, pcode, regionp); break;
+      res = NULL; break;
+    case LL_PCODE_LEGACY_TREE:
+      res = new LLVOTree(id, pcode, regionp); break;
+    case LL_PCODE_TREE_NEW:
+//    LL_WARNS() << "Creating new tree!" << LL_ENDL;
+//    res = new LLVOTree(id, pcode, regionp); break;
+      res = NULL; break;
+    case LL_VO_SURFACE_PATCH:
+      res = new LLVOSurfacePatch(id, pcode, regionp); break;
+    case LL_VO_SKY:
+      res = new LLVOSky(id, pcode, regionp); break;
+    case LL_VO_VOID_WATER:
+        res = new LLVOVoidWater(id, pcode, regionp); break;
+    case LL_VO_WATER:
+        res = new LLVOWater(id, pcode, regionp); break;
+    case LL_VO_PART_GROUP:
+      res = new LLVOPartGroup(id, pcode, regionp); break;
+    case LL_VO_HUD_PART_GROUP:
+      res = new LLVOHUDPartGroup(id, pcode, regionp); break;
+    case LL_VO_WL_SKY:
+      res = new LLVOWLSky(id, pcode, regionp); break;
+    default:
+      LL_WARNS() << "Unknown object pcode " << (S32)pcode << LL_ENDL;
+      res = NULL; break;
+    }
+
+    return res;
 }
 
 LLViewerObject::LLViewerObject(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp, BOOL is_global)
-:	LLPrimitive(),
-	mChildList(),
-	mID(id),
-	mLocalID(0),
-	mTotalCRC(0),
-	mListIndex(-1),
-	mTEImages(NULL),
-	mTENormalMaps(NULL),
-	mTESpecularMaps(NULL),
-	mbCanSelect(TRUE),
-	mFlags(0),
-	mPhysicsShapeType(0),
-	mPhysicsGravity(0),
-	mPhysicsFriction(0),
-	mPhysicsDensity(0),
-	mPhysicsRestitution(0),
-	mDrawable(),
-	mCreateSelected(FALSE),
-	mRenderMedia(FALSE),
-	mBestUpdatePrecision(0),
-	mText(),
-	mHudText(""),
-	mHudTextColor(LLColor4::white),
+:   LLPrimitive(),
+    mChildList(),
+    mID(id),
+    mLocalID(0),
+    mTotalCRC(0),
+    mListIndex(-1),
+    mTEImages(NULL),
+    mTENormalMaps(NULL),
+    mTESpecularMaps(NULL),
+    mbCanSelect(TRUE),
+    mFlags(0),
+    mPhysicsShapeType(0),
+    mPhysicsGravity(0),
+    mPhysicsFriction(0),
+    mPhysicsDensity(0),
+    mPhysicsRestitution(0),
+    mDrawable(),
+    mCreateSelected(FALSE),
+    mRenderMedia(FALSE),
+    mBestUpdatePrecision(0),
+    mText(),
+    mHudText(""),
+    mHudTextColor(LLColor4::white),
     mControlAvatar(NULL),
-	mLastInterpUpdateSecs(0.f),
-	mLastMessageUpdateSecs(0.f),
-	mLatestRecvPacketID(0),
-	mRegionCrossExpire(0),
-	mData(NULL),
-	mAudioSourcep(NULL),
-	mAudioGain(1.f),
-	mSoundCutOffRadius(0.f),
-	mAppAngle(0.f),
-	mPixelArea(1024.f),
-	mInventory(NULL),
-	mInventorySerialNum(0),
-	mExpectedInventorySerialNum(0),
-	mInvRequestState(INVENTORY_REQUEST_STOPPED),
-	mInvRequestXFerId(0),
-	mInventoryDirty(FALSE),
-	mRegionp(regionp),
-	mDead(FALSE),
-	mOrphaned(FALSE),
-	mUserSelected(FALSE),
-	mOnActiveList(FALSE),
-	mOnMap(FALSE),
-	mStatic(FALSE),
-	mSeatCount(0),
-	mNumFaces(0),
-	mRotTime(0.f),
-	mAngularVelocityRot(),
-	mPreviousRotation(),
-	mAttachmentState(0),
-	mMedia(NULL),
-	mClickAction(0),
-	mObjectCost(0),
-	mLinksetCost(0),
-	mPhysicsCost(0),
-	mLinksetPhysicsCost(0.f),
-	mCostStale(true),
-	mPhysicsShapeUnknown(true),
-	mAttachmentItemID(LLUUID::null),
-	mLastUpdateType(OUT_UNKNOWN),
-	mLastUpdateCached(FALSE),
-	mExtraParameterList(LLNetworkData::PARAMS_MAX >> 4),
-	mCachedMuteListUpdateTime(0),
-	mCachedOwnerInMuteList(false),
-	mRiggedAttachedWarned(false)
-{
-	if (!is_global)
-	{
-		llassert(mRegionp);
-	}
-
-	LLPrimitive::init_primitive(pcode);
-
-	// CP: added 12/2/2005 - this was being initialised to 0, not the current frame time
-	mLastInterpUpdateSecs = LLFrameTimer::getElapsedSeconds();
-
-	mPositionRegion = LLVector3(0.f, 0.f, 0.f);
-
-	if (!is_global && mRegionp)
-	{
-		mPositionAgent = mRegionp->getOriginAgent();
-	}
-	resetRot();
-
-	LLViewerObject::sNumObjects++;
+    mLastInterpUpdateSecs(0.f),
+    mLastMessageUpdateSecs(0.f),
+    mLatestRecvPacketID(0),
+    mRegionCrossExpire(0),
+    mData(NULL),
+    mAudioSourcep(NULL),
+    mAudioGain(1.f),
+    mSoundCutOffRadius(0.f),
+    mAppAngle(0.f),
+    mPixelArea(1024.f),
+    mInventory(NULL),
+    mInventorySerialNum(0),
+    mExpectedInventorySerialNum(0),
+    mInvRequestState(INVENTORY_REQUEST_STOPPED),
+    mInvRequestXFerId(0),
+    mInventoryDirty(FALSE),
+    mRegionp(regionp),
+    mDead(FALSE),
+    mOrphaned(FALSE),
+    mUserSelected(FALSE),
+    mOnActiveList(FALSE),
+    mOnMap(FALSE),
+    mStatic(FALSE),
+    mSeatCount(0),
+    mNumFaces(0),
+    mRotTime(0.f),
+    mAngularVelocityRot(),
+    mPreviousRotation(),
+    mAttachmentState(0),
+    mMedia(NULL),
+    mClickAction(0),
+    mObjectCost(0),
+    mLinksetCost(0),
+    mPhysicsCost(0),
+    mLinksetPhysicsCost(0.f),
+    mCostStale(true),
+    mPhysicsShapeUnknown(true),
+    mAttachmentItemID(LLUUID::null),
+    mLastUpdateType(OUT_UNKNOWN),
+    mLastUpdateCached(FALSE),
+    mExtraParameterList(LLNetworkData::PARAMS_MAX >> 4),
+    mCachedMuteListUpdateTime(0),
+    mCachedOwnerInMuteList(false),
+    mRiggedAttachedWarned(false)
+{
+    if (!is_global)
+    {
+        llassert(mRegionp);
+    }
+
+    LLPrimitive::init_primitive(pcode);
+
+    // CP: added 12/2/2005 - this was being initialised to 0, not the current frame time
+    mLastInterpUpdateSecs = LLFrameTimer::getElapsedSeconds();
+
+    mPositionRegion = LLVector3(0.f, 0.f, 0.f);
+
+    if (!is_global && mRegionp)
+    {
+        mPositionAgent = mRegionp->getOriginAgent();
+    }
+    resetRot();
+
+    LLViewerObject::sNumObjects++;
 }
 
 LLViewerObject::~LLViewerObject()
 {
-	deleteTEImages();
+    deleteTEImages();
 
     // unhook from reflection probe manager
     if (mReflectionProbe.notNull())
@@ -356,18 +356,18 @@ LLViewerObject::~LLViewerObject()
         mReflectionProbe = nullptr;
     }
 
-	if(mInventory)
-	{
-		mInventory->clear();  // will deref and delete entries
-		delete mInventory;
-		mInventory = NULL;
-	}
+    if(mInventory)
+    {
+        mInventory->clear();  // will deref and delete entries
+        delete mInventory;
+        mInventory = NULL;
+    }
 
-	if (mPartSourcep)
-	{
-		mPartSourcep->setDead();
-		mPartSourcep = NULL;
-	}
+    if (mPartSourcep)
+    {
+        mPartSourcep->setDead();
+        mPartSourcep = NULL;
+    }
 
     if (mText)
     {
@@ -376,21 +376,21 @@ LLViewerObject::~LLViewerObject()
         mText = NULL;
     }
 
-	// Delete memory associated with extra parameters.
-	mExtraParameterList.clear();
+    // Delete memory associated with extra parameters.
+    mExtraParameterList.clear();
+
+    for_each(mNameValuePairs.begin(), mNameValuePairs.end(), DeletePairedPointer()) ;
+    mNameValuePairs.clear();
 
-	for_each(mNameValuePairs.begin(), mNameValuePairs.end(), DeletePairedPointer()) ;
-	mNameValuePairs.clear();
-	
-	delete[] mData;
-	mData = NULL;
+    delete[] mData;
+    mData = NULL;
 
-	delete mMedia;
-	mMedia = NULL;
+    delete mMedia;
+    mMedia = NULL;
 
-	sNumObjects--;
-	sNumZombieObjects--;
-	llassert(mChildList.size() == 0);
+    sNumObjects--;
+    sNumZombieObjects--;
+    llassert(mChildList.size() == 0);
     llassert(mControlAvatar.isNull()); // Should have been cleaned by now
     if (mControlAvatar.notNull())
     {
@@ -399,40 +399,40 @@ LLViewerObject::~LLViewerObject()
         LL_WARNS() << "Dead object owned a live control avatar" << LL_ENDL;
     }
 
-	clearInventoryListeners();
+    clearInventoryListeners();
 }
 
 void LLViewerObject::deleteTEImages()
 {
-	delete[] mTEImages;
-	mTEImages = NULL;
-	
-	if (mTENormalMaps != NULL)
-	{
-		delete[] mTENormalMaps;
-		mTENormalMaps = NULL;
-	}
-	
-	if (mTESpecularMaps != NULL)
-	{
-		delete[] mTESpecularMaps;
-		mTESpecularMaps = NULL;
-	}	
+    delete[] mTEImages;
+    mTEImages = NULL;
+
+    if (mTENormalMaps != NULL)
+    {
+        delete[] mTENormalMaps;
+        mTENormalMaps = NULL;
+    }
+
+    if (mTESpecularMaps != NULL)
+    {
+        delete[] mTESpecularMaps;
+        mTESpecularMaps = NULL;
+    }
 }
 
 void LLViewerObject::markDead()
 {
-	if (!mDead)
-	{
+    if (!mDead)
+    {
         LL_PROFILE_ZONE_SCOPED;
-		//LL_INFOS() << "Marking self " << mLocalID << " as dead." << LL_ENDL;
-		
-		// Root object of this hierarchy unlinks itself.
-		if (getParent())
-		{
-			((LLViewerObject *)getParent())->removeChild(this);
-		}
-		LLUUID mesh_id;
+        //LL_INFOS() << "Marking self " << mLocalID << " as dead." << LL_ENDL;
+
+        // Root object of this hierarchy unlinks itself.
+        if (getParent())
+        {
+            ((LLViewerObject *)getParent())->removeChild(this);
+        }
+        LLUUID mesh_id;
         {
             LLVOAvatar *av = getAvatar();
             if (av && LLVOAvatar::getRiggedMeshID(this,mesh_id))
@@ -446,83 +446,83 @@ void LLViewerObject::markDead()
             unlinkControlAvatar();
         }
 
-		// Mark itself as dead
-		mDead = TRUE;
-		if(mRegionp)
-		{
-			mRegionp->removeFromCreatedList(getLocalID()); 
-		}
-		gObjectList.cleanupReferences(this);
-
-		LLViewerObject *childp;
-		while (mChildList.size() > 0)
-		{
-			childp = mChildList.back();
-			if (childp->getPCode() != LL_PCODE_LEGACY_AVATAR)
-			{
-				//LL_INFOS() << "Marking child " << childp->getLocalID() << " as dead." << LL_ENDL;
-				childp->setParent(NULL); // LLViewerObject::markDead 1
-				childp->markDead();
-			}
-			else
-			{
-				// make sure avatar is no longer parented, 
-				// so we can properly set it's position
-				childp->setDrawableParent(NULL);
-				((LLVOAvatar*)childp)->getOffObject();
-				childp->setParent(NULL); // LLViewerObject::markDead 2
-			}
-			mChildList.pop_back();
-		}
-
-		if (mDrawable.notNull())
-		{
-			// Drawables are reference counted, mark as dead, then nuke the pointer.
-			mDrawable->markDead();
-			mDrawable = NULL;
-		}
-
-		if (mText)
-		{
-			mText->markDead();
-			mText = NULL;
-		}
-
-		if (mIcon)
-		{
-			mIcon->markDead();
-			mIcon = NULL;
-		}
-
-		if (mPartSourcep)
-		{
-			mPartSourcep->setDead();
-			mPartSourcep = NULL;
-		}
-
-		if (mAudioSourcep)
-		{
-			// Do some cleanup
-			if (gAudiop)
-			{
-				gAudiop->cleanupAudioSource(mAudioSourcep);
-			}
-			mAudioSourcep = NULL;
-		}
-
-		if (flagAnimSource())
-		{
-			if (isAgentAvatarValid())
-			{
-				// stop motions associated with this object
-				gAgentAvatarp->stopMotionFromSource(mID);
-			}
-		}
-
-		if (flagCameraSource())
-		{
-			LLFollowCamMgr::getInstance()->removeFollowCamParams(mID);
-		}
+        // Mark itself as dead
+        mDead = TRUE;
+        if(mRegionp)
+        {
+            mRegionp->removeFromCreatedList(getLocalID());
+        }
+        gObjectList.cleanupReferences(this);
+
+        LLViewerObject *childp;
+        while (mChildList.size() > 0)
+        {
+            childp = mChildList.back();
+            if (childp->getPCode() != LL_PCODE_LEGACY_AVATAR)
+            {
+                //LL_INFOS() << "Marking child " << childp->getLocalID() << " as dead." << LL_ENDL;
+                childp->setParent(NULL); // LLViewerObject::markDead 1
+                childp->markDead();
+            }
+            else
+            {
+                // make sure avatar is no longer parented,
+                // so we can properly set it's position
+                childp->setDrawableParent(NULL);
+                ((LLVOAvatar*)childp)->getOffObject();
+                childp->setParent(NULL); // LLViewerObject::markDead 2
+            }
+            mChildList.pop_back();
+        }
+
+        if (mDrawable.notNull())
+        {
+            // Drawables are reference counted, mark as dead, then nuke the pointer.
+            mDrawable->markDead();
+            mDrawable = NULL;
+        }
+
+        if (mText)
+        {
+            mText->markDead();
+            mText = NULL;
+        }
+
+        if (mIcon)
+        {
+            mIcon->markDead();
+            mIcon = NULL;
+        }
+
+        if (mPartSourcep)
+        {
+            mPartSourcep->setDead();
+            mPartSourcep = NULL;
+        }
+
+        if (mAudioSourcep)
+        {
+            // Do some cleanup
+            if (gAudiop)
+            {
+                gAudiop->cleanupAudioSource(mAudioSourcep);
+            }
+            mAudioSourcep = NULL;
+        }
+
+        if (flagAnimSource())
+        {
+            if (isAgentAvatarValid())
+            {
+                // stop motions associated with this object
+                gAgentAvatarp->stopMotionFromSource(mID);
+            }
+        }
+
+        if (flagCameraSource())
+        {
+            LLFollowCamMgr::getInstance()->removeFollowCamParams(mID);
+        }
 
         if (mReflectionProbe.notNull())
         {
@@ -530,242 +530,242 @@ void LLViewerObject::markDead()
             mReflectionProbe = nullptr;
         }
 
-		sNumZombieObjects++;
-	}
-}
-
-S32 LLViewerObject::getNumVisibleFaces() const 
-{ 
-	int v{0}; 
-	if(mDrawable.notNull())
-	{ 
-		for (int i = 0;i < mDrawable->getNumFaces();i++)
-		{
-			const LLFace* f = mDrawable->getFace(i);
-			if (f && f->getTextureEntry() && f->getTextureEntry()->getAlpha() != 0.0f)
-			{
-				v++;
-			}
-		} 
-	}
-	return v;
+        sNumZombieObjects++;
+    }
+}
+
+S32 LLViewerObject::getNumVisibleFaces() const
+{
+    int v{0};
+    if(mDrawable.notNull())
+    {
+        for (int i = 0;i < mDrawable->getNumFaces();i++)
+        {
+            const LLFace* f = mDrawable->getFace(i);
+            if (f && f->getTextureEntry() && f->getTextureEntry()->getAlpha() != 0.0f)
+            {
+                v++;
+            }
+        }
+    }
+    return v;
 };
 
 void LLViewerObject::dump() const
 {
-	LL_INFOS() << "Type: " << pCodeToString(mPrimitiveCode) << LL_ENDL;
-	LL_INFOS() << "Drawable: " << (LLDrawable *)mDrawable << LL_ENDL;
-	LL_INFOS() << "Update Age: " << LLFrameTimer::getElapsedSeconds() - mLastMessageUpdateSecs << LL_ENDL;
-
-	LL_INFOS() << "Parent: " << getParent() << LL_ENDL;
-	LL_INFOS() << "ID: " << mID << LL_ENDL;
-	LL_INFOS() << "LocalID: " << mLocalID << LL_ENDL;
-	LL_INFOS() << "PositionRegion: " << getPositionRegion() << LL_ENDL;
-	LL_INFOS() << "PositionAgent: " << getPositionAgent() << LL_ENDL;
-	LL_INFOS() << "PositionGlobal: " << getPositionGlobal() << LL_ENDL;
-	LL_INFOS() << "Velocity: " << getVelocity() << LL_ENDL;
-	if (mDrawable.notNull() && 
-		mDrawable->getNumFaces() && 
-		mDrawable->getFace(0))
-	{
-		LLFacePool *poolp = mDrawable->getFace(0)->getPool();
-		if (poolp)
-		{
-			LL_INFOS() << "Pool: " << poolp << LL_ENDL;
-			LL_INFOS() << "Pool reference count: " << poolp->mReferences.size() << LL_ENDL;
-		}
-	}
-	//LL_INFOS() << "BoxTree Min: " << mDrawable->getBox()->getMin() << LL_ENDL;
-	//LL_INFOS() << "BoxTree Max: " << mDrawable->getBox()->getMin() << LL_ENDL;
-	/*
-	LL_INFOS() << "Velocity: " << getVelocity() << LL_ENDL;
-	LL_INFOS() << "AnyOwner: " << permAnyOwner() << " YouOwner: " << permYouOwner() << " Edit: " << mPermEdit << LL_ENDL;
-	LL_INFOS() << "UsePhysics: " << flagUsePhysics() << " CanSelect " << mbCanSelect << " UserSelected " << mUserSelected << LL_ENDL;
-	LL_INFOS() << "AppAngle: " << mAppAngle << LL_ENDL;
-	LL_INFOS() << "PixelArea: " << mPixelArea << LL_ENDL;
-
-	char buffer[1000];
-	char *key;
-	for (key = mNameValuePairs.getFirstKey(); key; key = mNameValuePairs.getNextKey() )
-	{
-		mNameValuePairs[key]->printNameValue(buffer);
-		LL_INFOS() << buffer << LL_ENDL;
-	}
-	for (child_list_t::iterator iter = mChildList.begin();
-		 iter != mChildList.end(); iter++)
-	{
-		LLViewerObject* child = *iter;
-		LL_INFOS() << "  child " << child->getID() << LL_ENDL;
-	}
-	*/
+    LL_INFOS() << "Type: " << pCodeToString(mPrimitiveCode) << LL_ENDL;
+    LL_INFOS() << "Drawable: " << (LLDrawable *)mDrawable << LL_ENDL;
+    LL_INFOS() << "Update Age: " << LLFrameTimer::getElapsedSeconds() - mLastMessageUpdateSecs << LL_ENDL;
+
+    LL_INFOS() << "Parent: " << getParent() << LL_ENDL;
+    LL_INFOS() << "ID: " << mID << LL_ENDL;
+    LL_INFOS() << "LocalID: " << mLocalID << LL_ENDL;
+    LL_INFOS() << "PositionRegion: " << getPositionRegion() << LL_ENDL;
+    LL_INFOS() << "PositionAgent: " << getPositionAgent() << LL_ENDL;
+    LL_INFOS() << "PositionGlobal: " << getPositionGlobal() << LL_ENDL;
+    LL_INFOS() << "Velocity: " << getVelocity() << LL_ENDL;
+    if (mDrawable.notNull() &&
+        mDrawable->getNumFaces() &&
+        mDrawable->getFace(0))
+    {
+        LLFacePool *poolp = mDrawable->getFace(0)->getPool();
+        if (poolp)
+        {
+            LL_INFOS() << "Pool: " << poolp << LL_ENDL;
+            LL_INFOS() << "Pool reference count: " << poolp->mReferences.size() << LL_ENDL;
+        }
+    }
+    //LL_INFOS() << "BoxTree Min: " << mDrawable->getBox()->getMin() << LL_ENDL;
+    //LL_INFOS() << "BoxTree Max: " << mDrawable->getBox()->getMin() << LL_ENDL;
+    /*
+    LL_INFOS() << "Velocity: " << getVelocity() << LL_ENDL;
+    LL_INFOS() << "AnyOwner: " << permAnyOwner() << " YouOwner: " << permYouOwner() << " Edit: " << mPermEdit << LL_ENDL;
+    LL_INFOS() << "UsePhysics: " << flagUsePhysics() << " CanSelect " << mbCanSelect << " UserSelected " << mUserSelected << LL_ENDL;
+    LL_INFOS() << "AppAngle: " << mAppAngle << LL_ENDL;
+    LL_INFOS() << "PixelArea: " << mPixelArea << LL_ENDL;
+
+    char buffer[1000];
+    char *key;
+    for (key = mNameValuePairs.getFirstKey(); key; key = mNameValuePairs.getNextKey() )
+    {
+        mNameValuePairs[key]->printNameValue(buffer);
+        LL_INFOS() << buffer << LL_ENDL;
+    }
+    for (child_list_t::iterator iter = mChildList.begin();
+         iter != mChildList.end(); iter++)
+    {
+        LLViewerObject* child = *iter;
+        LL_INFOS() << "  child " << child->getID() << LL_ENDL;
+    }
+    */
 }
 
 void LLViewerObject::printNameValuePairs() const
 {
-	for (name_value_map_t::const_iterator iter = mNameValuePairs.begin();
-		 iter != mNameValuePairs.end(); iter++)
-	{
-		LLNameValue* nv = iter->second;
-		LL_INFOS() << nv->printNameValue() << LL_ENDL;
-	}
+    for (name_value_map_t::const_iterator iter = mNameValuePairs.begin();
+         iter != mNameValuePairs.end(); iter++)
+    {
+        LLNameValue* nv = iter->second;
+        LL_INFOS() << nv->printNameValue() << LL_ENDL;
+    }
 }
 
 void LLViewerObject::initVOClasses()
 {
-	// Initialized shared class stuff first.
-	LLVOAvatar::initClass();
-	LLVOTree::initClass();
-	LL_INFOS() << "Viewer Object size: " << sizeof(LLViewerObject) << LL_ENDL;
-	LLVOGrass::initClass();
-	LLVOWater::initClass();
-	LLVOVolume::initClass();
+    // Initialized shared class stuff first.
+    LLVOAvatar::initClass();
+    LLVOTree::initClass();
+    LL_INFOS() << "Viewer Object size: " << sizeof(LLViewerObject) << LL_ENDL;
+    LLVOGrass::initClass();
+    LLVOWater::initClass();
+    LLVOVolume::initClass();
 
-	initObjectDataMap();
+    initObjectDataMap();
 }
 
 void LLViewerObject::cleanupVOClasses()
 {
-	SUBSYSTEM_CLEANUP(LLVOGrass);
-	SUBSYSTEM_CLEANUP(LLVOWater);
-	SUBSYSTEM_CLEANUP(LLVOTree);
-	SUBSYSTEM_CLEANUP(LLVOAvatar);
-	SUBSYSTEM_CLEANUP(LLVOVolume);
+    SUBSYSTEM_CLEANUP(LLVOGrass);
+    SUBSYSTEM_CLEANUP(LLVOWater);
+    SUBSYSTEM_CLEANUP(LLVOTree);
+    SUBSYSTEM_CLEANUP(LLVOAvatar);
+    SUBSYSTEM_CLEANUP(LLVOVolume);
 
-	sObjectDataMap.clear();
+    sObjectDataMap.clear();
 }
 
 //object data map for compressed && !OUT_TERSE_IMPROVED
 //static
 void LLViewerObject::initObjectDataMap()
 {
-	U32 count = 0;
+    U32 count = 0;
 
-	sObjectDataMap["ID"] = count; //full id //LLUUID
-	count += sizeof(LLUUID);
+    sObjectDataMap["ID"] = count; //full id //LLUUID
+    count += sizeof(LLUUID);
 
-	sObjectDataMap["LocalID"] = count; //U32
-	count += sizeof(U32);
+    sObjectDataMap["LocalID"] = count; //U32
+    count += sizeof(U32);
 
-	sObjectDataMap["PCode"] = count;   //U8
-	count += sizeof(U8);
+    sObjectDataMap["PCode"] = count;   //U8
+    count += sizeof(U8);
 
-	sObjectDataMap["State"] = count;   //U8
-	count += sizeof(U8);
+    sObjectDataMap["State"] = count;   //U8
+    count += sizeof(U8);
 
-	sObjectDataMap["CRC"] = count;     //U32
-	count += sizeof(U32);
+    sObjectDataMap["CRC"] = count;     //U32
+    count += sizeof(U32);
 
-	sObjectDataMap["Material"] = count; //U8
-	count += sizeof(U8);
+    sObjectDataMap["Material"] = count; //U8
+    count += sizeof(U8);
 
-	sObjectDataMap["ClickAction"] = count; //U8
-	count += sizeof(U8);
+    sObjectDataMap["ClickAction"] = count; //U8
+    count += sizeof(U8);
 
-	sObjectDataMap["Scale"] = count; //LLVector3
-	count += sizeof(LLVector3);
+    sObjectDataMap["Scale"] = count; //LLVector3
+    count += sizeof(LLVector3);
 
-	sObjectDataMap["Pos"] = count;   //LLVector3
-	count += sizeof(LLVector3);
+    sObjectDataMap["Pos"] = count;   //LLVector3
+    count += sizeof(LLVector3);
 
-	sObjectDataMap["Rot"] = count;    //LLVector3
-	count += sizeof(LLVector3);
+    sObjectDataMap["Rot"] = count;    //LLVector3
+    count += sizeof(LLVector3);
 
-	sObjectDataMap["SpecialCode"] = count; //U32
-	count += sizeof(U32);
+    sObjectDataMap["SpecialCode"] = count; //U32
+    count += sizeof(U32);
 
-	sObjectDataMap["Owner"] = count; //LLUUID
-	count += sizeof(LLUUID);
+    sObjectDataMap["Owner"] = count; //LLUUID
+    count += sizeof(LLUUID);
 
-	sObjectDataMap["Omega"] = count; //LLVector3, when SpecialCode & 0x80 is set
-	count += sizeof(LLVector3);
+    sObjectDataMap["Omega"] = count; //LLVector3, when SpecialCode & 0x80 is set
+    count += sizeof(LLVector3);
 
-	//ParentID is after Omega if there is Omega, otherwise is after Owner
-	sObjectDataMap["ParentID"] = count;//U32, when SpecialCode & 0x20 is set
-	count += sizeof(U32);
+    //ParentID is after Omega if there is Omega, otherwise is after Owner
+    sObjectDataMap["ParentID"] = count;//U32, when SpecialCode & 0x20 is set
+    count += sizeof(U32);
 
-	//-------
-	//The rest items are not included here
-	//-------
+    //-------
+    //The rest items are not included here
+    //-------
 }
 
-//static 
+//static
 void LLViewerObject::unpackVector3(LLDataPackerBinaryBuffer* dp, LLVector3& value, std::string name)
 {
-	dp->shift(sObjectDataMap[name]);
-	dp->unpackVector3(value, name.c_str());
-	dp->reset();
+    dp->shift(sObjectDataMap[name]);
+    dp->unpackVector3(value, name.c_str());
+    dp->reset();
 }
 
-//static 
+//static
 void LLViewerObject::unpackUUID(LLDataPackerBinaryBuffer* dp, LLUUID& value, std::string name)
 {
-	dp->shift(sObjectDataMap[name]);
-	dp->unpackUUID(value, name.c_str());
-	dp->reset();
+    dp->shift(sObjectDataMap[name]);
+    dp->unpackUUID(value, name.c_str());
+    dp->reset();
 }
-	
-//static 
+
+//static
 void LLViewerObject::unpackU32(LLDataPackerBinaryBuffer* dp, U32& value, std::string name)
 {
-	dp->shift(sObjectDataMap[name]);
-	dp->unpackU32(value, name.c_str());
-	dp->reset();
+    dp->shift(sObjectDataMap[name]);
+    dp->unpackU32(value, name.c_str());
+    dp->reset();
 }
-	
-//static 
+
+//static
 void LLViewerObject::unpackU8(LLDataPackerBinaryBuffer* dp, U8& value, std::string name)
 {
-	dp->shift(sObjectDataMap[name]);
-	dp->unpackU8(value, name.c_str());
-	dp->reset();
+    dp->shift(sObjectDataMap[name]);
+    dp->unpackU8(value, name.c_str());
+    dp->reset();
 }
 
-//static 
+//static
 U32 LLViewerObject::unpackParentID(LLDataPackerBinaryBuffer* dp, U32& parent_id)
 {
-	dp->shift(sObjectDataMap["SpecialCode"]);
-	U32 value;
-	dp->unpackU32(value, "SpecialCode");
+    dp->shift(sObjectDataMap["SpecialCode"]);
+    U32 value;
+    dp->unpackU32(value, "SpecialCode");
 
-	parent_id = 0;
-	if(value & 0x20)
-	{
-		S32 offset = sObjectDataMap["ParentID"];
-		if(!(value & 0x80))
-		{
-			offset -= sizeof(LLVector3);
-		}
+    parent_id = 0;
+    if(value & 0x20)
+    {
+        S32 offset = sObjectDataMap["ParentID"];
+        if(!(value & 0x80))
+        {
+            offset -= sizeof(LLVector3);
+        }
 
-		dp->shift(offset);
-		dp->unpackU32(parent_id, "ParentID");
-	}
-	dp->reset();
+        dp->shift(offset);
+        dp->unpackU32(parent_id, "ParentID");
+    }
+    dp->reset();
 
-	return parent_id;
+    return parent_id;
 }
 
 // Replaces all name value pairs with data from \n delimited list
 // Does not update server
 void LLViewerObject::setNameValueList(const std::string& name_value_list)
 {
-	// Clear out the old
-	for_each(mNameValuePairs.begin(), mNameValuePairs.end(), DeletePairedPointer()) ;
-	mNameValuePairs.clear();
-
-	// Bring in the new
-	std::string::size_type length = name_value_list.length();
-	std::string::size_type start = 0;
-	while (start < length)
-	{
-		std::string::size_type end = name_value_list.find_first_of("\n", start);
-		if (end == std::string::npos) end = length;
-		if (end > start)
-		{
-			std::string tok = name_value_list.substr(start, end - start);
-			addNVPair(tok);
-		}
-		start = end+1;
-	}
+    // Clear out the old
+    for_each(mNameValuePairs.begin(), mNameValuePairs.end(), DeletePairedPointer()) ;
+    mNameValuePairs.clear();
+
+    // Bring in the new
+    std::string::size_type length = name_value_list.length();
+    std::string::size_type start = 0;
+    while (start < length)
+    {
+        std::string::size_type end = name_value_list.find_first_of("\n", start);
+        if (end == std::string::npos) end = length;
+        if (end > start)
+        {
+            std::string tok = name_value_list.substr(start, end - start);
+            addNVPair(tok);
+        }
+        start = end+1;
+    }
 }
 
 BOOL LLViewerObject::isAnySelected() const
@@ -780,183 +780,183 @@ BOOL LLViewerObject::isAnySelected() const
 
 void LLViewerObject::setSelected(BOOL sel)
 {
-	mUserSelected = sel;
-	resetRot();
+    mUserSelected = sel;
+    resetRot();
 
-	if (!sel)
-	{
-		setAllTESelected(false);
-	}
+    if (!sel)
+    {
+        setAllTESelected(false);
+    }
 }
 
 // This method returns true if the object is over land owned by the
 // agent.
 bool LLViewerObject::isReturnable()
 {
-	if (isAttachment())
-	{
-		return false;
-	}
-		
+    if (isAttachment())
+    {
+        return false;
+    }
+
 // [RLVa:KB] - Checked: 2011-05-28 (RLVa-1.4.0a) | Added: RLVa-1.4.0a
-	if ( (RlvActions::isRlvEnabled()) && (!rlvCanDeleteOrReturn(this)) )
-	{
-		return false;
-	}
+    if ( (RlvActions::isRlvEnabled()) && (!rlvCanDeleteOrReturn(this)) )
+    {
+        return false;
+    }
 // [/RLVa:KB]
-	std::vector<LLBBox> boxes;
-	boxes.push_back(LLBBox(getPositionRegion(), getRotationRegion(), getScale() * -0.5f, getScale() * 0.5f).getAxisAligned());
-	for (const LLViewerObject* child : mChildList)
-	{
-		boxes.push_back( LLBBox(child->getPositionRegion(), child->getRotationRegion(), child->getScale() * -0.5f, child->getScale() * 0.5f).getAxisAligned());
-	}
-
-	bool result = (mRegionp && mRegionp->objectIsReturnable(getPositionRegion(), boxes)) ? 1 : 0;
-	
-	if ( !result )
-	{		
-		//Get list of neighboring regions relative to this vo's region
-		std::vector<LLViewerRegion*> uniqueRegions;
-		mRegionp->getNeighboringRegions( uniqueRegions );
-	
-		//Build aabb's - for root and all children
-		std::vector<PotentialReturnableObject> returnables;
-		typedef std::vector<LLViewerRegion*>::iterator RegionIt;
-		RegionIt regionStart = uniqueRegions.begin();
-		RegionIt regionEnd   = uniqueRegions.end();
-		
-		for (; regionStart != regionEnd; ++regionStart )
-		{
-			LLViewerRegion* pTargetRegion = *regionStart;
-			//Add the root vo as there may be no children and we still want
-			//to test for any edge overlap
-			buildReturnablesForChildrenVO( returnables, this, pTargetRegion );
-			//Add it's children
-			for (LLViewerObject* pChild : mChildList)
-			{
-				buildReturnablesForChildrenVO( returnables, pChild, pTargetRegion );
-			}
-		}	
-	
-		//TBD#Eventually create a region -> box list map 
-		typedef std::vector<PotentialReturnableObject>::iterator ReturnablesIt;
-		ReturnablesIt retCurrentIt = returnables.begin();
-		ReturnablesIt retEndIt = returnables.end();
-	
-		for ( ; retCurrentIt !=retEndIt; ++retCurrentIt )
-		{
-			boxes.clear();
-			LLViewerRegion* pRegion = (*retCurrentIt).pRegion;
-			boxes.push_back( (*retCurrentIt).box );	
-			bool retResult = 	pRegion
-							 && pRegion->childrenObjectReturnable( boxes )
-							 && pRegion->canManageEstate();
-			if ( retResult )
-			{ 
-				result = true;
-				break;
-			}
-		}
-	}
-	return result;
+    std::vector<LLBBox> boxes;
+    boxes.push_back(LLBBox(getPositionRegion(), getRotationRegion(), getScale() * -0.5f, getScale() * 0.5f).getAxisAligned());
+    for (const LLViewerObject* child : mChildList)
+    {
+        boxes.push_back( LLBBox(child->getPositionRegion(), child->getRotationRegion(), child->getScale() * -0.5f, child->getScale() * 0.5f).getAxisAligned());
+    }
+
+    bool result = (mRegionp && mRegionp->objectIsReturnable(getPositionRegion(), boxes)) ? 1 : 0;
+
+    if ( !result )
+    {
+        //Get list of neighboring regions relative to this vo's region
+        std::vector<LLViewerRegion*> uniqueRegions;
+        mRegionp->getNeighboringRegions( uniqueRegions );
+
+        //Build aabb's - for root and all children
+        std::vector<PotentialReturnableObject> returnables;
+        typedef std::vector<LLViewerRegion*>::iterator RegionIt;
+        RegionIt regionStart = uniqueRegions.begin();
+        RegionIt regionEnd   = uniqueRegions.end();
+
+        for (; regionStart != regionEnd; ++regionStart )
+        {
+            LLViewerRegion* pTargetRegion = *regionStart;
+            //Add the root vo as there may be no children and we still want
+            //to test for any edge overlap
+            buildReturnablesForChildrenVO( returnables, this, pTargetRegion );
+            //Add it's children
+            for (LLViewerObject* pChild : mChildList)
+            {
+                buildReturnablesForChildrenVO( returnables, pChild, pTargetRegion );
+            }
+        }
+
+        //TBD#Eventually create a region -> box list map
+        typedef std::vector<PotentialReturnableObject>::iterator ReturnablesIt;
+        ReturnablesIt retCurrentIt = returnables.begin();
+        ReturnablesIt retEndIt = returnables.end();
+
+        for ( ; retCurrentIt !=retEndIt; ++retCurrentIt )
+        {
+            boxes.clear();
+            LLViewerRegion* pRegion = (*retCurrentIt).pRegion;
+            boxes.push_back( (*retCurrentIt).box );
+            bool retResult =    pRegion
+                             && pRegion->childrenObjectReturnable( boxes )
+                             && pRegion->canManageEstate();
+            if ( retResult )
+            {
+                result = true;
+                break;
+            }
+        }
+    }
+    return result;
 }
 
 void LLViewerObject::buildReturnablesForChildrenVO( std::vector<PotentialReturnableObject>& returnables, LLViewerObject* pChild, LLViewerRegion* pTargetRegion )
 {
-	if ( !pChild )
-	{
-		LL_ERRS()<<"child viewerobject is NULL "<<LL_ENDL;
-	}
-	
-	constructAndAddReturnable( returnables, pChild, pTargetRegion );
-	
-	//We want to handle any children VO's as well
-	for (LLViewerObject* pChildofChild : mChildList)
-	{
-		buildReturnablesForChildrenVO( returnables, pChildofChild, pTargetRegion );
-	}
+    if ( !pChild )
+    {
+        LL_ERRS()<<"child viewerobject is NULL "<<LL_ENDL;
+    }
+
+    constructAndAddReturnable( returnables, pChild, pTargetRegion );
+
+    //We want to handle any children VO's as well
+    for (LLViewerObject* pChildofChild : mChildList)
+    {
+        buildReturnablesForChildrenVO( returnables, pChildofChild, pTargetRegion );
+    }
 }
 
 void LLViewerObject::constructAndAddReturnable( std::vector<PotentialReturnableObject>& returnables, LLViewerObject* pChild, LLViewerRegion* pTargetRegion )
 {
-	
-	LLVector3 targetRegionPos;
-	targetRegionPos.setVec( pChild->getPositionGlobal() );	
-	
-	LLBBox childBBox = LLBBox( targetRegionPos, pChild->getRotationRegion(), pChild->getScale() * -0.5f, 
-							    pChild->getScale() * 0.5f).getAxisAligned();
-	
-	LLVector3 edgeA = targetRegionPos + childBBox.getMinLocal();
-	LLVector3 edgeB = targetRegionPos + childBBox.getMaxLocal();
-	
-	LLVector3d edgeAd, edgeBd;
-	edgeAd.setVec(edgeA);
-	edgeBd.setVec(edgeB);
-	
-	//Only add the box when either of the extents are in a neighboring region
-	if ( pTargetRegion->pointInRegionGlobal( edgeAd ) || pTargetRegion->pointInRegionGlobal( edgeBd ) )
-	{
-		PotentialReturnableObject returnableObj;
-		returnableObj.box		= childBBox;
-		returnableObj.pRegion	= pTargetRegion;
-		returnables.push_back( returnableObj );
-	}
+
+    LLVector3 targetRegionPos;
+    targetRegionPos.setVec( pChild->getPositionGlobal() );
+
+    LLBBox childBBox = LLBBox( targetRegionPos, pChild->getRotationRegion(), pChild->getScale() * -0.5f,
+                                pChild->getScale() * 0.5f).getAxisAligned();
+
+    LLVector3 edgeA = targetRegionPos + childBBox.getMinLocal();
+    LLVector3 edgeB = targetRegionPos + childBBox.getMaxLocal();
+
+    LLVector3d edgeAd, edgeBd;
+    edgeAd.setVec(edgeA);
+    edgeBd.setVec(edgeB);
+
+    //Only add the box when either of the extents are in a neighboring region
+    if ( pTargetRegion->pointInRegionGlobal( edgeAd ) || pTargetRegion->pointInRegionGlobal( edgeBd ) )
+    {
+        PotentialReturnableObject returnableObj;
+        returnableObj.box       = childBBox;
+        returnableObj.pRegion   = pTargetRegion;
+        returnables.push_back( returnableObj );
+    }
 }
 
 bool LLViewerObject::crossesParcelBounds()
 {
-	std::vector<LLBBox> boxes;
-	boxes.push_back(LLBBox(getPositionRegion(), getRotationRegion(), getScale() * -0.5f, getScale() * 0.5f).getAxisAligned());
-	for (const LLViewerObject* child : mChildList)
-	{
-		boxes.push_back(LLBBox(child->getPositionRegion(), child->getRotationRegion(), child->getScale() * -0.5f, child->getScale() * 0.5f).getAxisAligned());
-	}
+    std::vector<LLBBox> boxes;
+    boxes.push_back(LLBBox(getPositionRegion(), getRotationRegion(), getScale() * -0.5f, getScale() * 0.5f).getAxisAligned());
+    for (const LLViewerObject* child : mChildList)
+    {
+        boxes.push_back(LLBBox(child->getPositionRegion(), child->getRotationRegion(), child->getScale() * -0.5f, child->getScale() * 0.5f).getAxisAligned());
+    }
 
-	return mRegionp && mRegionp->objectsCrossParcel(boxes);
+    return mRegionp && mRegionp->objectsCrossParcel(boxes);
 }
 
 BOOL LLViewerObject::setParent(LLViewerObject* parent)
 {
-	if(mParent != parent)
-	{
-		LLViewerObject* old_parent = (LLViewerObject*)mParent ;		
-		BOOL ret = LLPrimitive::setParent(parent);
-		if(ret && old_parent && parent)
-		{
-			old_parent->removeChild(this) ;
-		}
-		return ret ;
-	}
+    if(mParent != parent)
+    {
+        LLViewerObject* old_parent = (LLViewerObject*)mParent ;
+        BOOL ret = LLPrimitive::setParent(parent);
+        if(ret && old_parent && parent)
+        {
+            old_parent->removeChild(this) ;
+        }
+        return ret ;
+    }
 
-	return FALSE ;
+    return FALSE ;
 }
 
 void LLViewerObject::addChild(LLViewerObject *childp)
 {
-	for (const LLViewerObject* child : mChildList)
-	{
-		if (child == childp)
-		{	//already has child
-			return;
-		}
-	}
-	
-	if (!isAvatar())
-	{
-		// propagate selection properties
-		childp->mbCanSelect = mbCanSelect;
-	}
-
-	if(childp->setParent(this))
-	{
-		mChildList.push_back(childp);
-		childp->afterReparent();
-
-		if (childp->isAvatar())
-		{
-			mSeatCount++;
-		}
-	}
+    for (const LLViewerObject* child : mChildList)
+    {
+        if (child == childp)
+        {   //already has child
+            return;
+        }
+    }
+
+    if (!isAvatar())
+    {
+        // propagate selection properties
+        childp->mbCanSelect = mbCanSelect;
+    }
+
+    if(childp->setParent(this))
+    {
+        mChildList.push_back(childp);
+        childp->afterReparent();
+
+        if (childp->isAvatar())
+        {
+            mSeatCount++;
+        }
+    }
 }
 
 void LLViewerObject::onReparent(LLViewerObject *old_parent, LLViewerObject *new_parent)
@@ -969,65 +969,65 @@ void LLViewerObject::afterReparent()
 
 void LLViewerObject::removeChild(LLViewerObject *childp)
 {
-	for (auto i = mChildList.begin(), end = mChildList.end(); i != end; ++i)
-	{
-		if (*i == childp)
-		{
-			if (!childp->isAvatar() && mDrawable.notNull() && mDrawable->isActive() && childp->mDrawable.notNull() && !isAvatar())
-			{
-				gPipeline.markRebuild(childp->mDrawable, LLDrawable::REBUILD_VOLUME);
-			}
-
-			mChildList.erase(i);
-
-			if(childp->getParent() == this)
-			{
-				childp->setParent(NULL);			
-			}
-
-			if (childp->isAvatar())
-			{
-				mSeatCount--;
-			}
-			break;
-		}
-	}
-	
-	if (childp->isSelected())
-	{
-		LLSelectMgr::getInstance()->deselectObjectAndFamily(childp);
-		BOOL add_to_end = TRUE;
-		LLSelectMgr::getInstance()->selectObjectAndFamily(childp, add_to_end);
-	}
+    for (auto i = mChildList.begin(), end = mChildList.end(); i != end; ++i)
+    {
+        if (*i == childp)
+        {
+            if (!childp->isAvatar() && mDrawable.notNull() && mDrawable->isActive() && childp->mDrawable.notNull() && !isAvatar())
+            {
+                gPipeline.markRebuild(childp->mDrawable, LLDrawable::REBUILD_VOLUME);
+            }
+
+            mChildList.erase(i);
+
+            if(childp->getParent() == this)
+            {
+                childp->setParent(NULL);
+            }
+
+            if (childp->isAvatar())
+            {
+                mSeatCount--;
+            }
+            break;
+        }
+    }
+
+    if (childp->isSelected())
+    {
+        LLSelectMgr::getInstance()->deselectObjectAndFamily(childp);
+        BOOL add_to_end = TRUE;
+        LLSelectMgr::getInstance()->selectObjectAndFamily(childp, add_to_end);
+    }
 }
 
 void LLViewerObject::addThisAndAllChildren(std::vector<LLViewerObject*>& objects)
 {
-	objects.push_back(this);
-	for (LLViewerObject* child : mChildList)
-	{
-		if (!child->isAvatar())
-		{
-			child->addThisAndAllChildren(objects);
-		}
-	}
+    objects.push_back(this);
+    for (LLViewerObject* child : mChildList)
+    {
+        if (!child->isAvatar())
+        {
+            child->addThisAndAllChildren(objects);
+        }
+    }
 }
 
 void LLViewerObject::addThisAndNonJointChildren(std::vector<LLViewerObject*>& objects)
 {
-	objects.push_back(this);
-	// don't add any attachments when temporarily selecting avatar
-	if (isAvatar())
-	{
-		return;
-	}
-	for (LLViewerObject* child : mChildList)
-	{
-		if ( (!child->isAvatar()))
-		{
-			child->addThisAndNonJointChildren(objects);
-		}
-	}
+    objects.push_back(this);
+    // don't add any attachments when temporarily selecting avatar
+    if (isAvatar())
+    {
+        return;
+    }
+    for (LLViewerObject* child : mChildList)
+    {
+        if ( (!child->isAvatar()))
+        {
+            child->addThisAndNonJointChildren(objects);
+        }
+    }
 }
 
 //BOOL LLViewerObject::isChild(LLViewerObject *childp) const
@@ -1035,80 +1035,80 @@ void LLViewerObject::addThisAndNonJointChildren(std::vector<LLViewerObject*>& ob
 BOOL LLViewerObject::isChild(const LLViewerObject *childp) const
 // [/RLVa:KB]
 {
-	for (const LLViewerObject* testchild : mChildList)
-	{
-		if (testchild == childp)
-			return TRUE;
-	}
-	return FALSE;
+    for (const LLViewerObject* testchild : mChildList)
+    {
+        if (testchild == childp)
+            return TRUE;
+    }
+    return FALSE;
 }
 
 // returns TRUE if at least one avatar is sitting on this object
 BOOL LLViewerObject::isSeat() const
 {
-	return mSeatCount > 0;
+    return mSeatCount > 0;
 }
 
 BOOL LLViewerObject::setDrawableParent(LLDrawable* parentp)
 {
-	if (mDrawable.isNull())
-	{
-		return FALSE;
-	}
-
-	BOOL ret = mDrawable->mXform.setParent(parentp ? &parentp->mXform : NULL);
-	if(!ret)
-	{
-		return FALSE ;
-	}
-	LLDrawable* old_parent = mDrawable->mParent;
-	mDrawable->mParent = parentp; 
-		
-	if (parentp && mDrawable->isActive())
-	{
-		parentp->makeActive();
-		parentp->setState(LLDrawable::ACTIVE_CHILD);
-	}
-
-	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
-	if(	(old_parent != parentp && old_parent)
-		|| (parentp && parentp->isActive()))
-	{
-		// *TODO we should not be relying on setDrawable parent to call markMoved
-		gPipeline.markMoved(mDrawable, FALSE);
-	}
-	else if (!mDrawable->isAvatar())
-	{
-		mDrawable->updateXform(TRUE);
-		/*if (!mDrawable->getSpatialGroup())
-		{
-			mDrawable->movePartition();
-		}*/
-	}
-	
-	return ret;
+    if (mDrawable.isNull())
+    {
+        return FALSE;
+    }
+
+    BOOL ret = mDrawable->mXform.setParent(parentp ? &parentp->mXform : NULL);
+    if(!ret)
+    {
+        return FALSE ;
+    }
+    LLDrawable* old_parent = mDrawable->mParent;
+    mDrawable->mParent = parentp;
+
+    if (parentp && mDrawable->isActive())
+    {
+        parentp->makeActive();
+        parentp->setState(LLDrawable::ACTIVE_CHILD);
+    }
+
+    gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
+    if( (old_parent != parentp && old_parent)
+        || (parentp && parentp->isActive()))
+    {
+        // *TODO we should not be relying on setDrawable parent to call markMoved
+        gPipeline.markMoved(mDrawable, FALSE);
+    }
+    else if (!mDrawable->isAvatar())
+    {
+        mDrawable->updateXform(TRUE);
+        /*if (!mDrawable->getSpatialGroup())
+        {
+            mDrawable->movePartition();
+        }*/
+    }
+
+    return ret;
 }
 
 // Show or hide particles, icon and HUD
 void LLViewerObject::hideExtraDisplayItems( BOOL hidden )
 {
-	if( mPartSourcep.notNull() )
-	{
-		LLViewerPartSourceScript *partSourceScript = mPartSourcep.get();
-		partSourceScript->setSuspended( hidden );
-	}
+    if( mPartSourcep.notNull() )
+    {
+        LLViewerPartSourceScript *partSourceScript = mPartSourcep.get();
+        partSourceScript->setSuspended( hidden );
+    }
 
-	if( mText.notNull() )
-	{
-		LLHUDText *hudText = mText.get();
-		hudText->setHidden( hidden );
-	}
+    if( mText.notNull() )
+    {
+        LLHUDText *hudText = mText.get();
+        hudText->setHidden( hidden );
+    }
 
-	if( mIcon.notNull() )
-	{
-		LLHUDIcon *hudIcon = mIcon.get();
-		hudIcon->setHidden( hidden );
-	}
+    if( mIcon.notNull() )
+    {
+        LLHUDIcon *hudIcon = mIcon.get();
+        hudIcon->setHidden( hidden );
+    }
 }
 
 U32 LLViewerObject::checkMediaURL(const std::string &media_url)
@@ -1133,9 +1133,9 @@ U32 LLViewerObject::checkMediaURL(const std::string &media_url)
         else if (mMedia->mMediaURL != media_url) // <-- This is an optimization.  If they are equal don't bother with below's test.
         {
             /*if (! (LLTextureEntry::getAgentIDFromMediaVersionString(media_url) == gAgent.getID() &&
-                   LLTextureEntry::getVersionFromMediaVersionString(media_url) == 
+                   LLTextureEntry::getVersionFromMediaVersionString(media_url) ==
                         LLTextureEntry::getVersionFromMediaVersionString(mMedia->mMediaURL) + 1))
-			*/
+            */
             {
                 // If the media URL is different and WE were not the one who
                 // changed it, mark dirty.
@@ -1153,1389 +1153,1389 @@ U32 LLViewerObject::checkMediaURL(const std::string &media_url)
 //static
 U32 LLViewerObject::extractSpatialExtents(LLDataPackerBinaryBuffer *dp, LLVector3& pos, LLVector3& scale, LLQuaternion& rot)
 {
-	U32	parent_id = 0;
-	LLViewerObject::unpackParentID(dp, parent_id);
+    U32 parent_id = 0;
+    LLViewerObject::unpackParentID(dp, parent_id);
+
+    LLViewerObject::unpackVector3(dp, scale, "Scale");
+    LLViewerObject::unpackVector3(dp, pos, "Pos");
 
-	LLViewerObject::unpackVector3(dp, scale, "Scale");
-	LLViewerObject::unpackVector3(dp, pos, "Pos");
-	
-	LLVector3 vec;
-	LLViewerObject::unpackVector3(dp, vec, "Rot");
-	rot.unpackFromVector3(vec);
-	
-	return parent_id;
+    LLVector3 vec;
+    LLViewerObject::unpackVector3(dp, vec, "Rot");
+    rot.unpackFromVector3(vec);
+
+    return parent_id;
 }
 
 U32 LLViewerObject::processUpdateMessage(LLMessageSystem *mesgsys,
-					 void **user_data,
-					 U32 block_num,
-					 const EObjectUpdateType update_type,
-					 LLDataPacker *dp)
+                     void **user_data,
+                     U32 block_num,
+                     const EObjectUpdateType update_type,
+                     LLDataPacker *dp)
 {
     LL_PROFILE_ZONE_SCOPED;
 #ifdef SHOW_DEBUG
-	LL_DEBUGS_ONCE("SceneLoadTiming") << "Received viewer object data" << LL_ENDL;
+    LL_DEBUGS_ONCE("SceneLoadTiming") << "Received viewer object data" << LL_ENDL;
 
     LL_DEBUGS("ObjectUpdate") << " mesgsys " << mesgsys << " dp " << dp << " id " << getID() << " update_type " << (S32) update_type << LL_ENDL;
     dumpStack("ObjectUpdateStack");
 #endif
 
-	U32 retval = 0x0;
-	
-	auto& worldInst = LLWorld::instance();
-
-	// If region is removed from the list it is also deleted.
-	if (!worldInst.isRegionListed(mRegionp))
-	{
-		LL_WARNS() << "Updating object in an invalid region" << LL_ENDL;
-		return retval;
-	}
-
-	// Coordinates of objects on simulators are region-local.
-	U64 region_handle = 0;	
-	
-	if(mesgsys != NULL)
-	{
-		mesgsys->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
-		LLViewerRegion* regionp = worldInst.getRegionFromHandle(region_handle);
-		if(regionp != mRegionp && regionp && mRegionp)//region cross
-		{
-			//this is the redundant position and region update, but it is necessary in case the viewer misses the following 
-			//position and region update messages from sim.
-			//this redundant update should not cause any problems.
-			LLVector3 delta_pos =  mRegionp->getOriginAgent() - regionp->getOriginAgent();
-			setPositionParent(getPosition() + delta_pos); //update to the new region position immediately.
-			setRegion(regionp) ; //change the region.
-		}
-		else
-		{
-			if(regionp != mRegionp)
-			{
-				if(mRegionp)
-				{
-					mRegionp->removeFromCreatedList(getLocalID()); 
-				}
-				if(regionp)
-				{
-					regionp->addToCreatedList(getLocalID()); 
-				}
-			}
-			mRegionp = regionp ;
-		}
-	}	
-	
-	if (!mRegionp)
-	{
-		U32 x, y;
-		from_region_handle(region_handle, &x, &y);
-
-		LL_ERRS() << "Object has invalid region " << x << ":" << y << "!" << LL_ENDL;
-		return retval;
-	}
-
-	F32 time_dilation = 1.f;
-	if(mesgsys != NULL)
-	{
-        U16 time_dilation16;
-        mesgsys->getU16Fast(_PREHASH_RegionData, _PREHASH_TimeDilation, time_dilation16);
-        time_dilation = ((F32) time_dilation16) / 65535.f;
-        mRegionp->setTimeDilation(time_dilation);
-	}
+    U32 retval = 0x0;
 
-	// this will be used to determine if we've really changed position
-	// Use getPosition, not getPositionRegion, since this is what we're comparing directly against.
-	LLVector3 test_pos_parent = getPosition();
+    auto& worldInst = LLWorld::instance();
 
-	// This needs to match the largest size below. See switch(length)
-	U8  data[MAX_OBJECT_BINARY_DATA_SIZE]; 
+    // If region is removed from the list it is also deleted.
+    if (!worldInst.isRegionListed(mRegionp))
+    {
+        LL_WARNS() << "Updating object in an invalid region" << LL_ENDL;
+        return retval;
+    }
 
-#ifdef LL_BIG_ENDIAN
-	U16 valswizzle[4];
-#endif
-	U16	*val;
-	const F32 size = mRegionp->getWidth();	
-	const F32 MAX_HEIGHT = worldInst.getRegionMaxHeight();
-	const F32 MIN_HEIGHT = worldInst.getRegionMinHeight();
-	S32 length;
-	S32	count;
-	S32 this_update_precision = 32;		// in bits
-
-	// Temporaries, because we need to compare w/ previous to set dirty flags...
-	LLVector3 new_pos_parent;
-	LLVector3 new_vel;
-	LLVector3 new_acc;
-	LLVector3 new_angv;
-	LLVector3 old_angv = getAngularVelocity();
-	LLQuaternion new_rot;
-	LLVector3 new_scale = getScale();
-
-	U32	parent_id = 0;
-	U8	material = 0;
-	U8 click_action = 0;
-	U32 crc = 0;
-
-	bool old_special_hover_cursor = specialHoverCursor();
-
-	LLViewerObject *cur_parentp = (LLViewerObject *)getParent();
-
-	if (cur_parentp)
-	{
-		parent_id = cur_parentp->mLocalID;
-	}
-
-	if (!dp)
-	{
-		switch(update_type)
-		{
-		case OUT_FULL:
-			{
-#ifdef DEBUG_UPDATE_TYPE
-				LL_INFOS() << "Full:" << getID() << LL_ENDL;
-#endif
-				//clear cost and linkset cost
-				setObjectCostStale();
-				if (isSelected())
-				{
-					gFloaterTools->dirty();
-				}
-
-				LLUUID audio_uuid;
-				LLUUID owner_id;	// only valid if audio_uuid or particle system is not null
-				F32    gain;
-				F32    cutoff;
-				U8     sound_flags;
-
-				mesgsys->getU32Fast( _PREHASH_ObjectData, _PREHASH_CRC, crc, block_num);
-				mesgsys->getU32Fast( _PREHASH_ObjectData, _PREHASH_ParentID, parent_id, block_num);
-				mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_Sound, audio_uuid, block_num );
-				// HACK: Owner id only valid if non-null sound id or particle system
-				mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_OwnerID, owner_id, block_num );
-				mesgsys->getF32Fast( _PREHASH_ObjectData, _PREHASH_Gain, gain, block_num );
-				mesgsys->getF32Fast(  _PREHASH_ObjectData, _PREHASH_Radius, cutoff, block_num );
-				mesgsys->getU8Fast(  _PREHASH_ObjectData, _PREHASH_Flags, sound_flags, block_num );
-				mesgsys->getU8Fast(  _PREHASH_ObjectData, _PREHASH_Material, material, block_num );
-				mesgsys->getU8Fast(  _PREHASH_ObjectData, _PREHASH_ClickAction, click_action, block_num); 
-				mesgsys->getVector3Fast(_PREHASH_ObjectData, _PREHASH_Scale, new_scale, block_num );
-				length = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_ObjectData);
-				mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_ObjectData, data, length, block_num, MAX_OBJECT_BINARY_DATA_SIZE);
-
-				mTotalCRC = crc;
-                // Might need to update mSourceMuted here to properly pick up new radius
-				mSoundCutOffRadius = cutoff;
-
-				// Owner ID used for sound muting or particle system muting
-				setAttachedSound(audio_uuid, owner_id, gain, sound_flags);
-
-				U8 old_material = getMaterial();
-				if (old_material != material)
-				{
-					setMaterial(material);
-					if (mDrawable.notNull())
-					{
-						gPipeline.markMoved(mDrawable, FALSE); // undamped
-					}
-				}
-				setClickAction(click_action);
-
-				count = 0;
-				LLVector4 collision_plane;
-				
-				switch(length)
-				{
-				case (60 + 16):
-					// pull out collision normal for avatar
-					htolememcpy(collision_plane.mV, &data[count], MVT_LLVector4, sizeof(LLVector4));
-					((LLVOAvatar*)this)->setFootPlane(collision_plane);
-					count += sizeof(LLVector4);
-					// fall through
-				case 60:
-					this_update_precision = 32;
-					// this is a terse update
-					// pos
-					htolememcpy(new_pos_parent.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-					count += sizeof(LLVector3);
-					// vel
-					htolememcpy((void*)getVelocity().mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-					count += sizeof(LLVector3);
-					// acc
-					htolememcpy((void*)getAcceleration().mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-					count += sizeof(LLVector3);
-					// theta
-					{
-						LLVector3 vec;
-						htolememcpy(vec.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-						new_rot.unpackFromVector3(vec);
-					}
-					count += sizeof(LLVector3);
-					// omega
-					htolememcpy((void*)new_angv.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-					if (new_angv.isExactlyZero())
-					{
-						// reset rotation time
-						resetRot();
-					}
-					setAngularVelocity(new_angv);
-#if LL_DARWIN
-					if (length == 76)
-					{
-						setAngularVelocity(LLVector3::zero);
-					}
-#endif
-					break;
-				case(32 + 16):
-					// pull out collision normal for avatar
-					htolememcpy(collision_plane.mV, &data[count], MVT_LLVector4, sizeof(LLVector4));
-					((LLVOAvatar*)this)->setFootPlane(collision_plane);
-					count += sizeof(LLVector4);
-					// fall through
-				case 32:
-					this_update_precision = 16;
-					test_pos_parent.quantize16(-0.5f*size, 1.5f*size, MIN_HEIGHT, MAX_HEIGHT);
-
-					// This is a terse 16 update, so treat data as an array of U16's.
-#ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6); 
-					val = valswizzle;
+    // Coordinates of objects on simulators are region-local.
+    U64 region_handle = 0;
+
+    if(mesgsys != NULL)
+    {
+        mesgsys->getU64Fast(_PREHASH_RegionData, _PREHASH_RegionHandle, region_handle);
+        LLViewerRegion* regionp = worldInst.getRegionFromHandle(region_handle);
+        if(regionp != mRegionp && regionp && mRegionp)//region cross
+        {
+            //this is the redundant position and region update, but it is necessary in case the viewer misses the following
+            //position and region update messages from sim.
+            //this redundant update should not cause any problems.
+            LLVector3 delta_pos =  mRegionp->getOriginAgent() - regionp->getOriginAgent();
+            setPositionParent(getPosition() + delta_pos); //update to the new region position immediately.
+            setRegion(regionp) ; //change the region.
+        }
+        else
+        {
+            if(regionp != mRegionp)
+            {
+                if(mRegionp)
+                {
+                    mRegionp->removeFromCreatedList(getLocalID());
+                }
+                if(regionp)
+                {
+                    regionp->addToCreatedList(getLocalID());
+                }
+            }
+            mRegionp = regionp ;
+        }
+    }
+
+    if (!mRegionp)
+    {
+        U32 x, y;
+        from_region_handle(region_handle, &x, &y);
+
+        LL_ERRS() << "Object has invalid region " << x << ":" << y << "!" << LL_ENDL;
+        return retval;
+    }
+
+    F32 time_dilation = 1.f;
+    if(mesgsys != NULL)
+    {
+        U16 time_dilation16;
+        mesgsys->getU16Fast(_PREHASH_RegionData, _PREHASH_TimeDilation, time_dilation16);
+        time_dilation = ((F32) time_dilation16) / 65535.f;
+        mRegionp->setTimeDilation(time_dilation);
+    }
+
+    // this will be used to determine if we've really changed position
+    // Use getPosition, not getPositionRegion, since this is what we're comparing directly against.
+    LLVector3 test_pos_parent = getPosition();
+
+    // This needs to match the largest size below. See switch(length)
+    U8  data[MAX_OBJECT_BINARY_DATA_SIZE];
+
+#ifdef LL_BIG_ENDIAN
+    U16 valswizzle[4];
+#endif
+    U16 *val;
+    const F32 size = mRegionp->getWidth();
+    const F32 MAX_HEIGHT = worldInst.getRegionMaxHeight();
+    const F32 MIN_HEIGHT = worldInst.getRegionMinHeight();
+    S32 length;
+    S32 count;
+    S32 this_update_precision = 32;     // in bits
+
+    // Temporaries, because we need to compare w/ previous to set dirty flags...
+    LLVector3 new_pos_parent;
+    LLVector3 new_vel;
+    LLVector3 new_acc;
+    LLVector3 new_angv;
+    LLVector3 old_angv = getAngularVelocity();
+    LLQuaternion new_rot;
+    LLVector3 new_scale = getScale();
+
+    U32 parent_id = 0;
+    U8  material = 0;
+    U8 click_action = 0;
+    U32 crc = 0;
+
+    bool old_special_hover_cursor = specialHoverCursor();
+
+    LLViewerObject *cur_parentp = (LLViewerObject *)getParent();
+
+    if (cur_parentp)
+    {
+        parent_id = cur_parentp->mLocalID;
+    }
+
+    if (!dp)
+    {
+        switch(update_type)
+        {
+        case OUT_FULL:
+            {
+#ifdef DEBUG_UPDATE_TYPE
+                LL_INFOS() << "Full:" << getID() << LL_ENDL;
+#endif
+                //clear cost and linkset cost
+                setObjectCostStale();
+                if (isSelected())
+                {
+                    gFloaterTools->dirty();
+                }
+
+                LLUUID audio_uuid;
+                LLUUID owner_id;    // only valid if audio_uuid or particle system is not null
+                F32    gain;
+                F32    cutoff;
+                U8     sound_flags;
+
+                mesgsys->getU32Fast( _PREHASH_ObjectData, _PREHASH_CRC, crc, block_num);
+                mesgsys->getU32Fast( _PREHASH_ObjectData, _PREHASH_ParentID, parent_id, block_num);
+                mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_Sound, audio_uuid, block_num );
+                // HACK: Owner id only valid if non-null sound id or particle system
+                mesgsys->getUUIDFast(_PREHASH_ObjectData, _PREHASH_OwnerID, owner_id, block_num );
+                mesgsys->getF32Fast( _PREHASH_ObjectData, _PREHASH_Gain, gain, block_num );
+                mesgsys->getF32Fast(  _PREHASH_ObjectData, _PREHASH_Radius, cutoff, block_num );
+                mesgsys->getU8Fast(  _PREHASH_ObjectData, _PREHASH_Flags, sound_flags, block_num );
+                mesgsys->getU8Fast(  _PREHASH_ObjectData, _PREHASH_Material, material, block_num );
+                mesgsys->getU8Fast(  _PREHASH_ObjectData, _PREHASH_ClickAction, click_action, block_num);
+                mesgsys->getVector3Fast(_PREHASH_ObjectData, _PREHASH_Scale, new_scale, block_num );
+                length = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_ObjectData);
+                mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_ObjectData, data, length, block_num, MAX_OBJECT_BINARY_DATA_SIZE);
+
+                mTotalCRC = crc;
+                // Might need to update mSourceMuted here to properly pick up new radius
+                mSoundCutOffRadius = cutoff;
+
+                // Owner ID used for sound muting or particle system muting
+                setAttachedSound(audio_uuid, owner_id, gain, sound_flags);
+
+                U8 old_material = getMaterial();
+                if (old_material != material)
+                {
+                    setMaterial(material);
+                    if (mDrawable.notNull())
+                    {
+                        gPipeline.markMoved(mDrawable, FALSE); // undamped
+                    }
+                }
+                setClickAction(click_action);
+
+                count = 0;
+                LLVector4 collision_plane;
+
+                switch(length)
+                {
+                case (60 + 16):
+                    // pull out collision normal for avatar
+                    htolememcpy(collision_plane.mV, &data[count], MVT_LLVector4, sizeof(LLVector4));
+                    ((LLVOAvatar*)this)->setFootPlane(collision_plane);
+                    count += sizeof(LLVector4);
+                    // fall through
+                case 60:
+                    this_update_precision = 32;
+                    // this is a terse update
+                    // pos
+                    htolememcpy(new_pos_parent.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                    count += sizeof(LLVector3);
+                    // vel
+                    htolememcpy((void*)getVelocity().mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                    count += sizeof(LLVector3);
+                    // acc
+                    htolememcpy((void*)getAcceleration().mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                    count += sizeof(LLVector3);
+                    // theta
+                    {
+                        LLVector3 vec;
+                        htolememcpy(vec.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                        new_rot.unpackFromVector3(vec);
+                    }
+                    count += sizeof(LLVector3);
+                    // omega
+                    htolememcpy((void*)new_angv.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                    if (new_angv.isExactlyZero())
+                    {
+                        // reset rotation time
+                        resetRot();
+                    }
+                    setAngularVelocity(new_angv);
+#if LL_DARWIN
+                    if (length == 76)
+                    {
+                        setAngularVelocity(LLVector3::zero);
+                    }
+#endif
+                    break;
+                case(32 + 16):
+                    // pull out collision normal for avatar
+                    htolememcpy(collision_plane.mV, &data[count], MVT_LLVector4, sizeof(LLVector4));
+                    ((LLVOAvatar*)this)->setFootPlane(collision_plane);
+                    count += sizeof(LLVector4);
+                    // fall through
+                case 32:
+                    this_update_precision = 16;
+                    test_pos_parent.quantize16(-0.5f*size, 1.5f*size, MIN_HEIGHT, MAX_HEIGHT);
+
+                    // This is a terse 16 update, so treat data as an array of U16's.
+#ifdef LL_BIG_ENDIAN
+                    htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
+                    val = valswizzle;
 #else
-					val = (U16 *) &data[count];
+                    val = (U16 *) &data[count];
 #endif
-					count += sizeof(U16)*3;
-					new_pos_parent.mV[VX] = U16_to_F32(val[VX], -0.5f*size, 1.5f*size);
-					new_pos_parent.mV[VY] = U16_to_F32(val[VY], -0.5f*size, 1.5f*size);
-					new_pos_parent.mV[VZ] = U16_to_F32(val[VZ], MIN_HEIGHT, MAX_HEIGHT);
+                    count += sizeof(U16)*3;
+                    new_pos_parent.mV[VX] = U16_to_F32(val[VX], -0.5f*size, 1.5f*size);
+                    new_pos_parent.mV[VY] = U16_to_F32(val[VY], -0.5f*size, 1.5f*size);
+                    new_pos_parent.mV[VZ] = U16_to_F32(val[VZ], MIN_HEIGHT, MAX_HEIGHT);
 
 #ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6); 
-					val = valswizzle;
+                    htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
+                    val = valswizzle;
 #else
-					val = (U16 *) &data[count];
+                    val = (U16 *) &data[count];
 #endif
-					count += sizeof(U16)*3;
-					setVelocity(LLVector3(U16_to_F32(val[VX], -size, size),
-													   U16_to_F32(val[VY], -size, size),
-													   U16_to_F32(val[VZ], -size, size)));
+                    count += sizeof(U16)*3;
+                    setVelocity(LLVector3(U16_to_F32(val[VX], -size, size),
+                                                       U16_to_F32(val[VY], -size, size),
+                                                       U16_to_F32(val[VZ], -size, size)));
 
 #ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6); 
-					val = valswizzle;
+                    htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
+                    val = valswizzle;
 #else
-					val = (U16 *) &data[count];
+                    val = (U16 *) &data[count];
 #endif
-					count += sizeof(U16)*3;
-					setAcceleration(LLVector3(U16_to_F32(val[VX], -size, size),
-														   U16_to_F32(val[VY], -size, size),
-														   U16_to_F32(val[VZ], -size, size)));
+                    count += sizeof(U16)*3;
+                    setAcceleration(LLVector3(U16_to_F32(val[VX], -size, size),
+                                                           U16_to_F32(val[VY], -size, size),
+                                                           U16_to_F32(val[VZ], -size, size)));
 
 #ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Quat, 4); 
-					val = valswizzle;
+                    htolememcpy(valswizzle, &data[count], MVT_U16Quat, 4);
+                    val = valswizzle;
 #else
-					val = (U16 *) &data[count];
+                    val = (U16 *) &data[count];
 #endif
-					count += sizeof(U16)*4;
-					new_rot.mQ[VX] = U16_to_F32(val[VX], -1.f, 1.f);
-					new_rot.mQ[VY] = U16_to_F32(val[VY], -1.f, 1.f);
-					new_rot.mQ[VZ] = U16_to_F32(val[VZ], -1.f, 1.f);
-					new_rot.mQ[VW] = U16_to_F32(val[VW], -1.f, 1.f);
+                    count += sizeof(U16)*4;
+                    new_rot.mQ[VX] = U16_to_F32(val[VX], -1.f, 1.f);
+                    new_rot.mQ[VY] = U16_to_F32(val[VY], -1.f, 1.f);
+                    new_rot.mQ[VZ] = U16_to_F32(val[VZ], -1.f, 1.f);
+                    new_rot.mQ[VW] = U16_to_F32(val[VW], -1.f, 1.f);
 
 #ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6); 
-					val = valswizzle;
+                    htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
+                    val = valswizzle;
 #else
-					val = (U16 *) &data[count];
+                    val = (U16 *) &data[count];
 #endif
-					new_angv.setVec(U16_to_F32(val[VX], -size, size),
-										U16_to_F32(val[VY], -size, size),
-										U16_to_F32(val[VZ], -size, size));
-					if (new_angv.isExactlyZero())
-					{
-						// reset rotation time
-						resetRot();
-					}
-					setAngularVelocity(new_angv);
-					break;
-
-				case 16:
-					this_update_precision = 8;
-					test_pos_parent.quantize8(-0.5f*size, 1.5f*size, MIN_HEIGHT, MAX_HEIGHT);
-					// this is a terse 8 update
-					new_pos_parent.mV[VX] = U8_to_F32(data[0], -0.5f*size, 1.5f*size);
-					new_pos_parent.mV[VY] = U8_to_F32(data[1], -0.5f*size, 1.5f*size);
-					new_pos_parent.mV[VZ] = U8_to_F32(data[2], MIN_HEIGHT, MAX_HEIGHT);
-
-					setVelocity(U8_to_F32(data[3], -size, size),
-								U8_to_F32(data[4], -size, size),
-								U8_to_F32(data[5], -size, size) );
-
-					setAcceleration(U8_to_F32(data[6], -size, size),
-									U8_to_F32(data[7], -size, size),
-									U8_to_F32(data[8], -size, size) );
-
-					new_rot.mQ[VX] = U8_to_F32(data[9], -1.f, 1.f);
-					new_rot.mQ[VY] = U8_to_F32(data[10], -1.f, 1.f);
-					new_rot.mQ[VZ] = U8_to_F32(data[11], -1.f, 1.f);
-					new_rot.mQ[VW] = U8_to_F32(data[12], -1.f, 1.f);
-
-					new_angv.setVec(U8_to_F32(data[13], -size, size),
-										U8_to_F32(data[14], -size, size),
-										U8_to_F32(data[15], -size, size) );
-					if (new_angv.isExactlyZero())
-					{
-						// reset rotation time
-						resetRot();
-					}
-					setAngularVelocity(new_angv);
-					break;
-				}
-
-				////////////////////////////////////////////////////
-				//
-				// Here we handle data specific to the full message.
-				//
-
-				U32 flags;
-				mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_UpdateFlags, flags, block_num);
-				// clear all but local flags
-				mFlags &= FLAGS_LOCAL;
-				mFlags |= flags;
-
-				U8 state;
-				mesgsys->getU8Fast(_PREHASH_ObjectData, _PREHASH_State, state, block_num );
-				mAttachmentState = state;
-
-				// ...new objects that should come in selected need to be added to the selected list
-				mCreateSelected = ((flags & FLAGS_CREATE_SELECTED) != 0);
-
-				// Set all name value pairs
-				S32 nv_size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_NameValue);
-				if (nv_size > 0)
-				{
-					std::string name_value_list;
-					mesgsys->getStringFast(_PREHASH_ObjectData, _PREHASH_NameValue, name_value_list, block_num);
-					setNameValueList(name_value_list);
-				}
-
-				// Clear out any existing generic data
-				if (mData)
-				{
-					delete [] mData;
-				}
-
-				// Check for appended generic data
-				S32 data_size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_Data);
-				if (data_size <= 0)
-				{
-					mData = NULL;
-				}
-				else
-				{
-					// ...has generic data
-					mData = new U8[data_size];
-					mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_Data, mData, data_size, block_num);
-				}
-
-				S32 text_size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_Text);
-				if (text_size > 1)
-				{
-					// Setup object text
-					if (!mText)
-					{
-					    initHudText();
-					}
-
-					std::string temp_string;
-					mesgsys->getStringFast(_PREHASH_ObjectData, _PREHASH_Text, temp_string, block_num );
-                    
-					LLColor4U coloru;
-					mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextColor, coloru.mV, 4, block_num);
-                        
-					// alpha was flipped so that it zero encoded better
-					coloru.mV[3] = 255 - coloru.mV[3];
-                    
-					mText->setColor(LLColor4(coloru));
-					mText->setString(temp_string);
+                    new_angv.setVec(U16_to_F32(val[VX], -size, size),
+                                        U16_to_F32(val[VY], -size, size),
+                                        U16_to_F32(val[VZ], -size, size));
+                    if (new_angv.isExactlyZero())
+                    {
+                        // reset rotation time
+                        resetRot();
+                    }
+                    setAngularVelocity(new_angv);
+                    break;
+
+                case 16:
+                    this_update_precision = 8;
+                    test_pos_parent.quantize8(-0.5f*size, 1.5f*size, MIN_HEIGHT, MAX_HEIGHT);
+                    // this is a terse 8 update
+                    new_pos_parent.mV[VX] = U8_to_F32(data[0], -0.5f*size, 1.5f*size);
+                    new_pos_parent.mV[VY] = U8_to_F32(data[1], -0.5f*size, 1.5f*size);
+                    new_pos_parent.mV[VZ] = U8_to_F32(data[2], MIN_HEIGHT, MAX_HEIGHT);
+
+                    setVelocity(U8_to_F32(data[3], -size, size),
+                                U8_to_F32(data[4], -size, size),
+                                U8_to_F32(data[5], -size, size) );
+
+                    setAcceleration(U8_to_F32(data[6], -size, size),
+                                    U8_to_F32(data[7], -size, size),
+                                    U8_to_F32(data[8], -size, size) );
+
+                    new_rot.mQ[VX] = U8_to_F32(data[9], -1.f, 1.f);
+                    new_rot.mQ[VY] = U8_to_F32(data[10], -1.f, 1.f);
+                    new_rot.mQ[VZ] = U8_to_F32(data[11], -1.f, 1.f);
+                    new_rot.mQ[VW] = U8_to_F32(data[12], -1.f, 1.f);
+
+                    new_angv.setVec(U8_to_F32(data[13], -size, size),
+                                        U8_to_F32(data[14], -size, size),
+                                        U8_to_F32(data[15], -size, size) );
+                    if (new_angv.isExactlyZero())
+                    {
+                        // reset rotation time
+                        resetRot();
+                    }
+                    setAngularVelocity(new_angv);
+                    break;
+                }
+
+                ////////////////////////////////////////////////////
+                //
+                // Here we handle data specific to the full message.
+                //
+
+                U32 flags;
+                mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_UpdateFlags, flags, block_num);
+                // clear all but local flags
+                mFlags &= FLAGS_LOCAL;
+                mFlags |= flags;
+
+                U8 state;
+                mesgsys->getU8Fast(_PREHASH_ObjectData, _PREHASH_State, state, block_num );
+                mAttachmentState = state;
+
+                // ...new objects that should come in selected need to be added to the selected list
+                mCreateSelected = ((flags & FLAGS_CREATE_SELECTED) != 0);
+
+                // Set all name value pairs
+                S32 nv_size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_NameValue);
+                if (nv_size > 0)
+                {
+                    std::string name_value_list;
+                    mesgsys->getStringFast(_PREHASH_ObjectData, _PREHASH_NameValue, name_value_list, block_num);
+                    setNameValueList(name_value_list);
+                }
+
+                // Clear out any existing generic data
+                if (mData)
+                {
+                    delete [] mData;
+                }
+
+                // Check for appended generic data
+                S32 data_size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_Data);
+                if (data_size <= 0)
+                {
+                    mData = NULL;
+                }
+                else
+                {
+                    // ...has generic data
+                    mData = new U8[data_size];
+                    mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_Data, mData, data_size, block_num);
+                }
+
+                S32 text_size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_Text);
+                if (text_size > 1)
+                {
+                    // Setup object text
+                    if (!mText)
+                    {
+                        initHudText();
+                    }
+
+                    std::string temp_string;
+                    mesgsys->getStringFast(_PREHASH_ObjectData, _PREHASH_Text, temp_string, block_num );
+
+                    LLColor4U coloru;
+                    mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextColor, coloru.mV, 4, block_num);
+
+                    // alpha was flipped so that it zero encoded better
+                    coloru.mV[3] = 255 - coloru.mV[3];
+
+                    mText->setColor(LLColor4(coloru));
+                    mText->setString(temp_string);
 // [RLVa:KB] - Checked: 2010-03-27 (RLVa-1.4.0a) | Added: RLVa-1.0.0f
-					if (RlvActions::isRlvEnabled())
-					{
-						mText->setObjectText(temp_string);
-					}
+                    if (RlvActions::isRlvEnabled())
+                    {
+                        mText->setObjectText(temp_string);
+                    }
 // [/RLVa:KB]
 
-					mHudText = temp_string;
-					mHudTextColor = LLColor4(coloru);
-
-					setChanged(MOVED | SILHOUETTE);
-				}
-				else
-				{
-					if (mText.notNull())
-					{
-						mText->markDead();
-						mText = NULL;
-					}
-					mHudText.clear();
-				}
-
-				std::string media_url;
-				mesgsys->getStringFast(_PREHASH_ObjectData, _PREHASH_MediaURL, media_url, block_num);
+                    mHudText = temp_string;
+                    mHudTextColor = LLColor4(coloru);
+
+                    setChanged(MOVED | SILHOUETTE);
+                }
+                else
+                {
+                    if (mText.notNull())
+                    {
+                        mText->markDead();
+                        mText = NULL;
+                    }
+                    mHudText.clear();
+                }
+
+                std::string media_url;
+                mesgsys->getStringFast(_PREHASH_ObjectData, _PREHASH_MediaURL, media_url, block_num);
                 retval |= checkMediaURL(media_url);
-                
-				//
-				// Unpack particle system data
-				//
-				unpackParticleSource(block_num, owner_id);
-
-				// Mark all extra parameters not used
-				for (auto& entry : mExtraParameterList)
-				{
-					if (entry.in_use) *entry.in_use = false;
-				}
-
-				// Unpack extra parameters
-				S32 size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_ExtraParams);
-				if (size > 0)
-				{
-					U8 *buffer = new U8[size];
-					mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_ExtraParams, buffer, size, block_num);
-					LLDataPackerBinaryBuffer dp(buffer, size);
-
-					U8 num_parameters;
-					dp.unpackU8(num_parameters, "num_params");
-					U8 param_block[MAX_OBJECT_PARAMS_SIZE];
-					for (U8 param=0; param<num_parameters; ++param)
-					{
-						U16 param_type;
-						S32 param_size;
-						dp.unpackU16(param_type, "param_type");
-						dp.unpackBinaryData(param_block, param_size, "param_data");
-						//LL_INFOS() << "Param type: " << param_type << ", Size: " << param_size << LL_ENDL;
-						LLDataPackerBinaryBuffer dp2(param_block, param_size);
-						unpackParameterEntry(param_type, &dp2);
-					}
-					delete[] buffer;
-				}
-
-				for (size_t i = 0; i < mExtraParameterList.size(); ++i)
-				{
-					auto& entry = mExtraParameterList[i];
-					if (entry.in_use && !*entry.in_use)
-					{
-						// Send an update message in case it was formerly in use
-						parameterChanged((i + 1) << 4, entry.data, FALSE, false);
-					}
-				}
-
-				break;
-			}
-
-		case OUT_TERSE_IMPROVED:
-			{
+
+                //
+                // Unpack particle system data
+                //
+                unpackParticleSource(block_num, owner_id);
+
+                // Mark all extra parameters not used
+                for (auto& entry : mExtraParameterList)
+                {
+                    if (entry.in_use) *entry.in_use = false;
+                }
+
+                // Unpack extra parameters
+                S32 size = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_ExtraParams);
+                if (size > 0)
+                {
+                    U8 *buffer = new U8[size];
+                    mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_ExtraParams, buffer, size, block_num);
+                    LLDataPackerBinaryBuffer dp(buffer, size);
+
+                    U8 num_parameters;
+                    dp.unpackU8(num_parameters, "num_params");
+                    U8 param_block[MAX_OBJECT_PARAMS_SIZE];
+                    for (U8 param=0; param<num_parameters; ++param)
+                    {
+                        U16 param_type;
+                        S32 param_size;
+                        dp.unpackU16(param_type, "param_type");
+                        dp.unpackBinaryData(param_block, param_size, "param_data");
+                        //LL_INFOS() << "Param type: " << param_type << ", Size: " << param_size << LL_ENDL;
+                        LLDataPackerBinaryBuffer dp2(param_block, param_size);
+                        unpackParameterEntry(param_type, &dp2);
+                    }
+                    delete[] buffer;
+                }
+
+                for (size_t i = 0; i < mExtraParameterList.size(); ++i)
+                {
+                    auto& entry = mExtraParameterList[i];
+                    if (entry.in_use && !*entry.in_use)
+                    {
+                        // Send an update message in case it was formerly in use
+                        parameterChanged((i + 1) << 4, entry.data, FALSE, false);
+                    }
+                }
+
+                break;
+            }
+
+        case OUT_TERSE_IMPROVED:
+            {
 #ifdef DEBUG_UPDATE_TYPE
-				LL_INFOS() << "TI:" << getID() << LL_ENDL;
+                LL_INFOS() << "TI:" << getID() << LL_ENDL;
 #endif
-				length = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_ObjectData);
-				mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_ObjectData, data, length, block_num, MAX_OBJECT_BINARY_DATA_SIZE);
-				count = 0;
-				LLVector4 collision_plane;
-				
-				switch(length)
-				{
-				case(60 + 16):
-					// pull out collision normal for avatar
-					htolememcpy(collision_plane.mV, &data[count], MVT_LLVector4, sizeof(LLVector4));
-					((LLVOAvatar*)this)->setFootPlane(collision_plane);
-					count += sizeof(LLVector4);
-					// fall through
-				case 60:
-					// this is a terse 32 update
-					// pos
-					this_update_precision = 32;
-					htolememcpy(new_pos_parent.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-					count += sizeof(LLVector3);
-					// vel
-					htolememcpy((void*)getVelocity().mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-					count += sizeof(LLVector3);
-					// acc
-					htolememcpy((void*)getAcceleration().mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-					count += sizeof(LLVector3);
-					// theta
-					{
-						LLVector3 vec;
-						htolememcpy(vec.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-						new_rot.unpackFromVector3(vec);
-					}
-					count += sizeof(LLVector3);
-					// omega
-					htolememcpy((void*)new_angv.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
-					if (new_angv.isExactlyZero())
-					{
-						// reset rotation time
-						resetRot();
-					}
-					setAngularVelocity(new_angv);
+                length = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_ObjectData);
+                mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_ObjectData, data, length, block_num, MAX_OBJECT_BINARY_DATA_SIZE);
+                count = 0;
+                LLVector4 collision_plane;
+
+                switch(length)
+                {
+                case(60 + 16):
+                    // pull out collision normal for avatar
+                    htolememcpy(collision_plane.mV, &data[count], MVT_LLVector4, sizeof(LLVector4));
+                    ((LLVOAvatar*)this)->setFootPlane(collision_plane);
+                    count += sizeof(LLVector4);
+                    // fall through
+                case 60:
+                    // this is a terse 32 update
+                    // pos
+                    this_update_precision = 32;
+                    htolememcpy(new_pos_parent.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                    count += sizeof(LLVector3);
+                    // vel
+                    htolememcpy((void*)getVelocity().mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                    count += sizeof(LLVector3);
+                    // acc
+                    htolememcpy((void*)getAcceleration().mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                    count += sizeof(LLVector3);
+                    // theta
+                    {
+                        LLVector3 vec;
+                        htolememcpy(vec.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                        new_rot.unpackFromVector3(vec);
+                    }
+                    count += sizeof(LLVector3);
+                    // omega
+                    htolememcpy((void*)new_angv.mV, &data[count], MVT_LLVector3, sizeof(LLVector3));
+                    if (new_angv.isExactlyZero())
+                    {
+                        // reset rotation time
+                        resetRot();
+                    }
+                    setAngularVelocity(new_angv);
 #if LL_DARWIN
-					if (length == 76)
-					{
-						setAngularVelocity(LLVector3::zero);
-					}
+                    if (length == 76)
+                    {
+                        setAngularVelocity(LLVector3::zero);
+                    }
 #endif
-					break;
-				case(32 + 16):
-					// pull out collision normal for avatar
-					htolememcpy(collision_plane.mV, &data[count], MVT_LLVector4, sizeof(LLVector4));
-					((LLVOAvatar*)this)->setFootPlane(collision_plane);
-					count += sizeof(LLVector4);
-					// fall through
-				case 32:
-					// this is a terse 16 update
-					this_update_precision = 16;
-					test_pos_parent.quantize16(-0.5f*size, 1.5f*size, MIN_HEIGHT, MAX_HEIGHT);
+                    break;
+                case(32 + 16):
+                    // pull out collision normal for avatar
+                    htolememcpy(collision_plane.mV, &data[count], MVT_LLVector4, sizeof(LLVector4));
+                    ((LLVOAvatar*)this)->setFootPlane(collision_plane);
+                    count += sizeof(LLVector4);
+                    // fall through
+                case 32:
+                    // this is a terse 16 update
+                    this_update_precision = 16;
+                    test_pos_parent.quantize16(-0.5f*size, 1.5f*size, MIN_HEIGHT, MAX_HEIGHT);
+
+#ifdef LL_BIG_ENDIAN
+                    htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
+                    val = valswizzle;
+#else
+                    val = (U16 *) &data[count];
+#endif
+                    count += sizeof(U16)*3;
+                    new_pos_parent.mV[VX] = U16_to_F32(val[VX], -0.5f*size, 1.5f*size);
+                    new_pos_parent.mV[VY] = U16_to_F32(val[VY], -0.5f*size, 1.5f*size);
+                    new_pos_parent.mV[VZ] = U16_to_F32(val[VZ], MIN_HEIGHT, MAX_HEIGHT);
+
+#ifdef LL_BIG_ENDIAN
+                    htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
+                    val = valswizzle;
+#else
+                    val = (U16 *) &data[count];
+#endif
+                    count += sizeof(U16)*3;
+                    setVelocity(U16_to_F32(val[VX], -size, size),
+                                U16_to_F32(val[VY], -size, size),
+                                U16_to_F32(val[VZ], -size, size));
+
+#ifdef LL_BIG_ENDIAN
+                    htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
+                    val = valswizzle;
+#else
+                    val = (U16 *) &data[count];
+#endif
+                    count += sizeof(U16)*3;
+                    setAcceleration(U16_to_F32(val[VX], -size, size),
+                                    U16_to_F32(val[VY], -size, size),
+                                    U16_to_F32(val[VZ], -size, size));
+
+#ifdef LL_BIG_ENDIAN
+                    htolememcpy(valswizzle, &data[count], MVT_U16Quat, 8);
+                    val = valswizzle;
+#else
+                    val = (U16 *) &data[count];
+#endif
+                    count += sizeof(U16)*4;
+                    new_rot.mQ[VX] = U16_to_F32(val[VX], -1.f, 1.f);
+                    new_rot.mQ[VY] = U16_to_F32(val[VY], -1.f, 1.f);
+                    new_rot.mQ[VZ] = U16_to_F32(val[VZ], -1.f, 1.f);
+                    new_rot.mQ[VW] = U16_to_F32(val[VW], -1.f, 1.f);
+
+#ifdef LL_BIG_ENDIAN
+                    htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6);
+                    val = valswizzle;
+#else
+                    val = (U16 *) &data[count];
+#endif
+                    new_angv.set(U16_to_F32(val[VX], -size, size),
+                                        U16_to_F32(val[VY], -size, size),
+                                        U16_to_F32(val[VZ], -size, size));
+                    setAngularVelocity(new_angv);
+                    break;
+
+                case 16:
+                    // this is a terse 8 update
+                    this_update_precision = 8;
+                    test_pos_parent.quantize8(-0.5f*size, 1.5f*size, MIN_HEIGHT, MAX_HEIGHT);
+                    new_pos_parent.mV[VX] = U8_to_F32(data[0], -0.5f*size, 1.5f*size);
+                    new_pos_parent.mV[VY] = U8_to_F32(data[1], -0.5f*size, 1.5f*size);
+                    new_pos_parent.mV[VZ] = U8_to_F32(data[2], MIN_HEIGHT, MAX_HEIGHT);
+
+                    setVelocity(U8_to_F32(data[3], -size, size),
+                                U8_to_F32(data[4], -size, size),
+                                U8_to_F32(data[5], -size, size) );
+
+                    setAcceleration(U8_to_F32(data[6], -size, size),
+                                    U8_to_F32(data[7], -size, size),
+                                    U8_to_F32(data[8], -size, size) );
+
+                    new_rot.mQ[VX] = U8_to_F32(data[9], -1.f, 1.f);
+                    new_rot.mQ[VY] = U8_to_F32(data[10], -1.f, 1.f);
+                    new_rot.mQ[VZ] = U8_to_F32(data[11], -1.f, 1.f);
+                    new_rot.mQ[VW] = U8_to_F32(data[12], -1.f, 1.f);
+
+                    new_angv.set(U8_to_F32(data[13], -size, size),
+                                        U8_to_F32(data[14], -size, size),
+                                        U8_to_F32(data[15], -size, size) );
+                    setAngularVelocity(new_angv);
+                    break;
+                }
+
+                U8 state;
+                mesgsys->getU8Fast(_PREHASH_ObjectData, _PREHASH_State, state, block_num );
+                mAttachmentState = state;
+                break;
+            }
+
+        default:
+            break;
+
+        }
+    }
+    else
+    {
+        // handle the compressed case
+        LLUUID sound_uuid;
+        LLUUID  owner_id;
+        F32    gain = 0;
+        U8     sound_flags = 0;
+        F32     cutoff = 0;
+
+        U16 val[4];
+
+        U8      state;
+
+        dp->unpackU8(state, "State");
+        mAttachmentState = state;
+
+        switch(update_type)
+        {
+            case OUT_TERSE_IMPROVED:
+            {
+#ifdef DEBUG_UPDATE_TYPE
+                LL_INFOS() << "CompTI:" << getID() << LL_ENDL;
+#endif
+                U8      value;
+                dp->unpackU8(value, "agent");
+                if (value)
+                {
+                    LLVector4 collision_plane;
+                    dp->unpackVector4(collision_plane, "Plane");
+                    ((LLVOAvatar*)this)->setFootPlane(collision_plane);
+                }
+                test_pos_parent = getPosition();
+                dp->unpackVector3(new_pos_parent, "Pos");
+                dp->unpackU16(val[VX], "VelX");
+                dp->unpackU16(val[VY], "VelY");
+                dp->unpackU16(val[VZ], "VelZ");
+                setVelocity(U16_to_F32(val[VX], -128.f, 128.f),
+                            U16_to_F32(val[VY], -128.f, 128.f),
+                            U16_to_F32(val[VZ], -128.f, 128.f));
+                dp->unpackU16(val[VX], "AccX");
+                dp->unpackU16(val[VY], "AccY");
+                dp->unpackU16(val[VZ], "AccZ");
+                setAcceleration(U16_to_F32(val[VX], -64.f, 64.f),
+                                U16_to_F32(val[VY], -64.f, 64.f),
+                                U16_to_F32(val[VZ], -64.f, 64.f));
+
+                dp->unpackU16(val[VX], "ThetaX");
+                dp->unpackU16(val[VY], "ThetaY");
+                dp->unpackU16(val[VZ], "ThetaZ");
+                dp->unpackU16(val[VS], "ThetaS");
+                new_rot.mQ[VX] = U16_to_F32(val[VX], -1.f, 1.f);
+                new_rot.mQ[VY] = U16_to_F32(val[VY], -1.f, 1.f);
+                new_rot.mQ[VZ] = U16_to_F32(val[VZ], -1.f, 1.f);
+                new_rot.mQ[VS] = U16_to_F32(val[VS], -1.f, 1.f);
+                dp->unpackU16(val[VX], "AccX");
+                dp->unpackU16(val[VY], "AccY");
+                dp->unpackU16(val[VZ], "AccZ");
+                new_angv.set(U16_to_F32(val[VX], -64.f, 64.f),
+                                    U16_to_F32(val[VY], -64.f, 64.f),
+                                    U16_to_F32(val[VZ], -64.f, 64.f));
+                setAngularVelocity(new_angv);
+            }
+            break;
+            case OUT_FULL_COMPRESSED:
+            case OUT_FULL_CACHED:
+            {
+#ifdef DEBUG_UPDATE_TYPE
+                LL_INFOS() << "CompFull:" << getID() << LL_ENDL;
+#endif
+                setObjectCostStale();
+
+                if (isSelected())
+                {
+                    gFloaterTools->dirty();
+                }
+
+                dp->unpackU32(crc, "CRC");
+                mTotalCRC = crc;
+                dp->unpackU8(material, "Material");
+                U8 old_material = getMaterial();
+                if (old_material != material)
+                {
+                    setMaterial(material);
+                    if (mDrawable.notNull())
+                    {
+                        gPipeline.markMoved(mDrawable, FALSE); // undamped
+                    }
+                }
+                dp->unpackU8(click_action, "ClickAction");
+                setClickAction(click_action);
+                dp->unpackVector3(new_scale, "Scale");
+                dp->unpackVector3(new_pos_parent, "Pos");
+                LLVector3 vec;
+                dp->unpackVector3(vec, "Rot");
+                new_rot.unpackFromVector3(vec);
+                setAcceleration(LLVector3::zero);
+
+                U32 value;
+                dp->unpackU32(value, "SpecialCode");
+                dp->setPassFlags(value);
+                dp->unpackUUID(owner_id, "Owner");
+
+                mOwnerID = owner_id;
+
+                if (value & 0x80)
+                {
+                    dp->unpackVector3(new_angv, "Omega");
+                    setAngularVelocity(new_angv);
+                }
+
+                if (value & 0x20)
+                {
+                    dp->unpackU32(parent_id, "ParentID");
+                }
+                else
+                {
+                    parent_id = 0;
+                }
+
+                S32 sp_size;
+                U32 size;
+                if (value & 0x2)
+                {
+                    sp_size = 1;
+                    delete [] mData;
+                    mData = new U8[1];
+                    dp->unpackU8(((U8*)mData)[0], "TreeData");
+                }
+                else if (value & 0x1)
+                {
+                    dp->unpackU32(size, "ScratchPadSize");
+                    delete [] mData;
+                    mData = new U8[size];
+                    dp->unpackBinaryData((U8 *)mData, sp_size, "PartData");
+                }
+                else
+                {
+                    mData = NULL;
+                }
+
+                // Setup object text
+                if (!mText && (value & 0x4))
+                {
+                    initHudText();
+                }
+
+                if (value & 0x4)
+                {
+                    std::string temp_string;
+                    dp->unpackString(temp_string, "Text");
+
+                    LLColor4U coloru;
+                    dp->unpackBinaryDataFixed(coloru.mV, 4, "Color");
+                    coloru.mV[3] = 255 - coloru.mV[3];
+                    mText->setColor(LLColor4(coloru));
+                    mText->setString(temp_string);
+// [RLVa:KB] - Checked: 2010-03-27 (RLVa-1.4.0a) | Added: RLVa-1.0.0f
+                    if (RlvActions::isRlvEnabled())
+                    {
+                        mText->setObjectText(temp_string);
+                    }
+// [/RLVa:KB]
+
+                    mHudText = temp_string;
+                    mHudTextColor = LLColor4(coloru);
+
+                    setChanged(TEXTURE);
+                }
+                else
+                {
+                    if (mText.notNull())
+                    {
+                        mText->markDead();
+                        mText = NULL;
+                    }
+                    mHudText.clear();
+                }
+
+                std::string media_url;
+                if (value & 0x200)
+                {
+                    dp->unpackString(media_url, "MediaURL");
+                }
+                retval |= checkMediaURL(media_url);
+
+                //
+                // Unpack particle system data (legacy)
+                //
+                if (value & 0x8)
+                {
+                    unpackParticleSource(*dp, owner_id, true);
+                }
+                else if (!(value & 0x400))
+                {
+                    deleteParticleSource();
+                }
+
+                // Mark all extra parameters not used
+                for (auto& entry : mExtraParameterList)
+                {
+                    if (entry.in_use) *entry.in_use = false;
+                }
+
+                // Unpack extra params
+                U8 num_parameters;
+                dp->unpackU8(num_parameters, "num_params");
+                U8 param_block[MAX_OBJECT_PARAMS_SIZE];
+                for (U8 param=0; param<num_parameters; ++param)
+                {
+                    U16 param_type;
+                    S32 param_size;
+                    dp->unpackU16(param_type, "param_type");
+                    dp->unpackBinaryData(param_block, param_size, "param_data");
+                    //LL_INFOS() << "Param type: " << param_type << ", Size: " << param_size << LL_ENDL;
+                    LLDataPackerBinaryBuffer dp2(param_block, param_size);
+                    unpackParameterEntry(param_type, &dp2);
+                }
+
+                for (size_t i = 0; i < mExtraParameterList.size(); ++i)
+                {
+                    auto& entry = mExtraParameterList[i];
+                    if (entry.in_use && !*entry.in_use)
+                    {
+                        // Send an update message in case it was formerly in use
+                        parameterChanged((i + 1) << 4, entry.data, FALSE, false);
+                    }
+                }
+
+                if (value & 0x10)
+                {
+                    dp->unpackUUID(sound_uuid, "SoundUUID");
+                    dp->unpackF32(gain, "SoundGain");
+                    dp->unpackU8(sound_flags, "SoundFlags");
+                    dp->unpackF32(cutoff, "SoundRadius");
+                }
+
+                if (value & 0x100)
+                {
+                    std::string name_value_list;
+                    dp->unpackString(name_value_list, "NV");
+
+                    setNameValueList(name_value_list);
+                }
+
+                mTotalCRC = crc;
+                mSoundCutOffRadius = cutoff;
+
+                setAttachedSound(sound_uuid, owner_id, gain, sound_flags);
+
+                // only get these flags on updates from sim, not cached ones
+                // Preload these five flags for every object.
+                // Finer shades require the object to be selected, and the selection manager
+                // stores the extended permission info.
+                if(mesgsys != NULL)
+                {
+                U32 flags;
+                mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_UpdateFlags, flags, block_num);
+                loadFlags(flags);
+                }
+            }
+            break;
+
+        default:
+            break;
+        }
+    }
+
+    //
+    // Fix object parenting.
+    //
+    BOOL b_changed_status = FALSE;
+
+    if (OUT_TERSE_IMPROVED != update_type)
+    {
+        // We only need to update parenting on full updates, terse updates
+        // don't send parenting information.
+        if (!cur_parentp)
+        {
+            if (parent_id == 0)
+            {
+                // No parent now, no parent in message -> do nothing
+            }
+            else
+            {
+                // No parent now, new parent in message -> attach to that parent if possible
+                LLUUID parent_uuid;
+
+                if(mesgsys != NULL)
+                {
+                    gObjectList.getUUIDFromLocal(parent_uuid,
+                                                        parent_id,
+                                                        mesgsys->getSenderIP(),
+                                                        mesgsys->getSenderPort());
+                }
+                else
+                {
+                    gObjectList.getUUIDFromLocal(parent_uuid,
+                                                        parent_id,
+                                                        mRegionp->getHost().getAddress(),
+                                                        mRegionp->getHost().getPort());
+                }
+
+                LLViewerObject *sent_parentp = gObjectList.findObject(parent_uuid);
+
+                //
+                // Check to see if we have the corresponding viewer object for the parent.
+                //
+                if (sent_parentp && sent_parentp->getParent() == this)
+                {
+                    // Try to recover if we attempt to attach a parent to its child
+                    LL_WARNS() << "Attempt to attach a parent to it's child: " << this->getID() << " to " << sent_parentp->getID() << LL_ENDL;
+                    this->removeChild(sent_parentp);
+                    sent_parentp->setDrawableParent(NULL);
+                }
+
+                if (sent_parentp && (sent_parentp != this) && !sent_parentp->isDead())
+                {
+                    if (((LLViewerObject*)sent_parentp)->isAvatar())
+                    {
+                        //LL_DEBUGS("Avatar") << "ATT got object update for attachment " << LL_ENDL;
+                    }
+
+                    //
+                    // We have a viewer object for the parent, and it's not dead.
+                    // Do the actual reparenting here.
+                    //
+
+                    // new parent is valid
+                    b_changed_status = TRUE;
+                    // ...no current parent, so don't try to remove child
+                    if (mDrawable.notNull())
+                    {
+                        if (mDrawable->isDead() || !mDrawable->getVObj())
+                        {
+                            LL_WARNS() << "Drawable is dead or no VObj!" << LL_ENDL;
+                            sent_parentp->addChild(this);
+                        }
+                        else
+                        {
+                            if (!setDrawableParent(sent_parentp->mDrawable)) // LLViewerObject::processUpdateMessage 1
+                            {
+                                // Bad, we got a cycle somehow.
+                                // Kill both the parent and the child, and
+                                // set cache misses for both of them.
+                                LL_WARNS() << "Attempting to recover from parenting cycle!" << LL_ENDL;
+                                LL_WARNS() << "Killing " << sent_parentp->getID() << " and " << getID() << LL_ENDL;
+                                LL_WARNS() << "Adding to cache miss list" << LL_ENDL;
+                                setParent(NULL);
+                                sent_parentp->setParent(NULL);
+                                getRegion()->addCacheMissFull(getLocalID());
+                                getRegion()->addCacheMissFull(sent_parentp->getLocalID());
+                                gObjectList.killObject(sent_parentp);
+                                gObjectList.killObject(this);
+                                return retval;
+                            }
+// [RLVa:KB] - Checked: 2010-03-16 (RLVa-1.1.0k) | Added: RLVa-1.1.0k
+                            if ( (RlvActions::isRlvEnabled()) && (sent_parentp->isAvatar()) && (sent_parentp->getID() == gAgent.getID()) )
+                            {
+                                // Rezzed object that's being worn as an attachment (we're assuming this will be due to llAttachToAvatar())
+                                S32 idxAttachPt = ATTACHMENT_ID_FROM_STATE(getAttachmentState());
+                                if (gRlvAttachmentLocks.isLockedAttachmentPoint(idxAttachPt, RLV_LOCK_ADD))
+                                {
+                                    // If this will end up on an "add locked" attachment point then treat the attach as a user action
+                                    LLNameValue* nvItem = getNVPair("AttachItemID");
+                                    if (nvItem)
+                                    {
+                                        LLUUID idItem(nvItem->getString());
+                                        // URGENT-RLVa: [RLVa-1.2.0] At the moment llAttachToAvatar always seems to *add*
+                                        if (idItem.notNull())
+                                            RlvAttachmentLockWatchdog::instance().onWearAttachment(idItem, RLV_WEAR_ADD);
+                                    }
+                                }
+                            }
+// [/RLVa:KB]
+                            sent_parentp->addChild(this);
+                            // make sure this object gets a non-damped update
+                            if (sent_parentp->mDrawable.notNull())
+                            {
+                                gPipeline.markMoved(sent_parentp->mDrawable, FALSE); // undamped
+                            }
+                        }
+                    }
+                    else
+                    {
+                        sent_parentp->addChild(this);
+                    }
+
+                    // Show particles, icon and HUD
+                    hideExtraDisplayItems( FALSE );
+
+                    setChanged(MOVED | SILHOUETTE);
+                }
+                else
+                {
+                    //
+                    // No corresponding viewer object for the parent, put the various
+                    // pieces on the orphan list.
+                    //
+
+                    //parent_id
+                    U32 ip, port;
+
+                    if(mesgsys != NULL)
+                    {
+                        ip = mesgsys->getSenderIP();
+                        port = mesgsys->getSenderPort();
+                    }
+                    else
+                    {
+                        ip = mRegionp->getHost().getAddress();
+                        port = mRegionp->getHost().getPort();
+                    }
+                    gObjectList.orphanize(this, parent_id, ip, port);
+
+                    // Hide particles, icon and HUD
+                    hideExtraDisplayItems( TRUE );
+                }
+            }
+        }
+        else
+        {
+            // BUG: this is a bad assumption once border crossing is alowed
+            if (  (parent_id == cur_parentp->mLocalID)
+                &&(update_type == OUT_TERSE_IMPROVED))
+            {
+                // Parent now, same parent in message -> do nothing
+
+                // Debugging for suspected problems with local ids.
+                //LLUUID parent_uuid;
+                //LLViewerObjectList::getUUIDFromLocal(parent_uuid, parent_id, mesgsys->getSenderIP(), mesgsys->getSenderPort() );
+                //if (parent_uuid != cur_parentp->getID() )
+                //{
+                //  LL_ERRS() << "Local ID match but UUID mismatch of viewer object" << LL_ENDL;
+                //}
+            }
+            else
+            {
+                // Parented now, different parent in message
+                LLViewerObject *sent_parentp;
+                if (parent_id == 0)
+                {
+                    //
+                    // This object is no longer parented, we sent in a zero parent ID.
+                    //
+                    sent_parentp = NULL;
+                }
+                else
+                {
+                    LLUUID parent_uuid;
+
+                    if(mesgsys != NULL)
+                    {
+                        gObjectList.getUUIDFromLocal(parent_uuid,
+                                                        parent_id,
+                                                        gMessageSystem->getSenderIP(),
+                                                        gMessageSystem->getSenderPort());
+                    }
+                    else
+                    {
+                        gObjectList.getUUIDFromLocal(parent_uuid,
+                                                        parent_id,
+                                                        mRegionp->getHost().getAddress(),
+                                                        mRegionp->getHost().getPort());
+                    }
+                    sent_parentp = gObjectList.findObject(parent_uuid);
+
+                    if (isAvatar())
+                    {
+                        // This logic is meant to handle the case where a sitting avatar has reached a new sim
+                        // ahead of the object she was sitting on (which is common as objects are transfered through
+                        // a slower route than agents)...
+                        // In this case, the local id for the object will not be valid, since the viewer has not received
+                        // a full update for the object from that sim yet, so we assume that the agent is still sitting
+                        // where she was originally. --RN
+                        if (!sent_parentp)
+                        {
+                            sent_parentp = cur_parentp;
+                        }
+                    }
+                    else if (!sent_parentp)
+                    {
+                        //
+                        // Switching parents, but we don't know the new parent.
+                        //
+                        U32 ip, port;
+
+                        if(mesgsys != NULL)
+                        {
+                            ip = mesgsys->getSenderIP();
+                            port = mesgsys->getSenderPort();
+                        }
+                        else
+                        {
+                            ip = mRegionp->getHost().getAddress();
+                            port = mRegionp->getHost().getPort();
+                        }
+
+                        // We're an orphan, flag things appropriately.
+                        gObjectList.orphanize(this, parent_id, ip, port);
+                    }
+                }
+
+                // Reattach if possible.
+                if (sent_parentp && sent_parentp != cur_parentp && sent_parentp != this)
+                {
+                    // New parent is valid, detach and reattach
+                    b_changed_status = TRUE;
+                    if (mDrawable.notNull())
+                    {
+                        if (!setDrawableParent(sent_parentp->mDrawable)) // LLViewerObject::processUpdateMessage 2
+                        {
+                            // Bad, we got a cycle somehow.
+                            // Kill both the parent and the child, and
+                            // set cache misses for both of them.
+                            LL_WARNS() << "Attempting to recover from parenting cycle!" << LL_ENDL;
+                            LL_WARNS() << "Killing " << sent_parentp->getID() << " and " << getID() << LL_ENDL;
+                            LL_WARNS() << "Adding to cache miss list" << LL_ENDL;
+                            setParent(NULL);
+                            sent_parentp->setParent(NULL);
+                            getRegion()->addCacheMissFull(getLocalID());
+                            getRegion()->addCacheMissFull(sent_parentp->getLocalID());
+                            gObjectList.killObject(sent_parentp);
+                            gObjectList.killObject(this);
+                            return retval;
+                        }
+                        // make sure this object gets a non-damped update
+                    }
+                    cur_parentp->removeChild(this);
+                    sent_parentp->addChild(this);
+                    setChanged(MOVED | SILHOUETTE);
+                    sent_parentp->setChanged(MOVED | SILHOUETTE);
+                    if (sent_parentp->mDrawable.notNull())
+                    {
+                        gPipeline.markMoved(sent_parentp->mDrawable, FALSE); // undamped
+                    }
+                }
+                else if (!sent_parentp)
+                {
+                    bool remove_parent = true;
+                    // No new parent, or the parent that we sent doesn't exist on the viewer.
+                    LLViewerObject *parentp = (LLViewerObject *)getParent();
+                    if (parentp)
+                    {
+                        if (parentp->getRegion() != getRegion())
+                        {
+                            // This is probably an object flying across a region boundary, the
+                            // object probably ISN'T being reparented, but just got an object
+                            // update out of order (child update before parent).
+                            //LL_INFOS() << "Don't reparent object handoffs!" << LL_ENDL;
+                            remove_parent = false;
+                        }
+                    }
+
+                    if (remove_parent)
+                    {
+                        b_changed_status = TRUE;
+                        if (mDrawable.notNull())
+                        {
+                            // clear parent to removeChild can put the drawable on the damped list
+                            setDrawableParent(NULL); // LLViewerObject::processUpdateMessage 3
+                        }
+
+                        cur_parentp->removeChild(this);
+
+                        setChanged(MOVED | SILHOUETTE);
+
+                        if (mDrawable.notNull())
+                        {
+                            // make sure this object gets a non-damped update
+                            gPipeline.markMoved(mDrawable, FALSE); // undamped
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    new_rot.normQuat();
+
+    if (sPingInterpolate && mesgsys != NULL)
+    {
+        LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mesgsys->getSender());
+        if (cdp)
+        {
+            // Note: delay is U32 and usually less then second,
+            // converting it into seconds with valueInUnits will result in 0
+            F32 ping_delay = 0.5f * time_dilation * ( ((F32)cdp->getPingDelay().value()) * 0.001f + gFrameDTClamped);
+            LLVector3 diff = getVelocity() * ping_delay;
+            new_pos_parent += diff;
+        }
+        else
+        {
+            LL_WARNS() << "findCircuit() returned NULL; skipping interpolation" << LL_ENDL;
+        }
+    }
+
+    //////////////////////////
+    //
+    // Set the generic change flags...
+    //
+    //
+
+    // If we're going to skip this message, why are we
+    // doing all the parenting, etc above?
+    if(mesgsys != NULL)
+    {
+    U32 packet_id = mesgsys->getCurrentRecvPacketID();
+    if (packet_id < mLatestRecvPacketID &&
+        mLatestRecvPacketID - packet_id < 65536)
+    {
+        //skip application of this message, it's old
+        return retval;
+    }
+    mLatestRecvPacketID = packet_id;
+    }
+
+    // Set the change flags for scale
+    if (new_scale != getScale())
+    {
+        setChanged(SCALED | SILHOUETTE);
+        setScale(new_scale);  // Must follow setting permYouOwner()
+    }
+
+    // first, let's see if the new position is actually a change
+
+    //static S32 counter = 0;
+
+    F32 vel_mag_sq = getVelocity().magVecSquared();
+    F32 accel_mag_sq = getAcceleration().magVecSquared();
+
+    if (  ((b_changed_status)||(test_pos_parent != new_pos_parent))
+        ||(  (!isSelected())
+           &&(  (vel_mag_sq != 0.f)
+              ||(accel_mag_sq != 0.f)
+              ||(this_update_precision > mBestUpdatePrecision))))
+    {
+        mBestUpdatePrecision = this_update_precision;
+
+        LLVector3 diff = new_pos_parent - test_pos_parent ;
+        F32 mag_sqr = diff.magVecSquared() ;
+        if(llfinite(mag_sqr))
+        {
+            setPositionParent(new_pos_parent);
+        }
+        else
+        {
+            LL_WARNS() << "Can not move the object/avatar to an infinite location!" << LL_ENDL ;
+
+            retval |= INVALID_UPDATE ;
+        }
 
-#ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6); 
-					val = valswizzle;
-#else
-					val = (U16 *) &data[count];
-#endif
-					count += sizeof(U16)*3;
-					new_pos_parent.mV[VX] = U16_to_F32(val[VX], -0.5f*size, 1.5f*size);
-					new_pos_parent.mV[VY] = U16_to_F32(val[VY], -0.5f*size, 1.5f*size);
-					new_pos_parent.mV[VZ] = U16_to_F32(val[VZ], MIN_HEIGHT, MAX_HEIGHT);
+        if (mParent && ((LLViewerObject*)mParent)->isAvatar())
+        {
+            // we have changed the position of an attachment, so we need to clamp it
+            LLVOAvatar *avatar = (LLVOAvatar*)mParent;
 
-#ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6); 
-					val = valswizzle;
-#else
-					val = (U16 *) &data[count];
-#endif
-					count += sizeof(U16)*3;
-					setVelocity(U16_to_F32(val[VX], -size, size),
-								U16_to_F32(val[VY], -size, size),
-								U16_to_F32(val[VZ], -size, size));
+            avatar->clampAttachmentPositions();
+        }
 
-#ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6); 
-					val = valswizzle;
-#else
-					val = (U16 *) &data[count];
-#endif
-					count += sizeof(U16)*3;
-					setAcceleration(U16_to_F32(val[VX], -size, size),
-									U16_to_F32(val[VY], -size, size),
-									U16_to_F32(val[VZ], -size, size));
+        // If we're snapping the position by more than 0.5m, update LLViewerStats::mAgentPositionSnaps
+        if ( asAvatar() && asAvatar()->isSelf() && (mag_sqr > 0.25f) )
+        {
+            record(LLStatViewer::AGENT_POSITION_SNAP, LLUnit<F64, LLUnits::Meters>(diff.length()));
+        }
+    }
 
-#ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Quat, 8); 
-					val = valswizzle;
-#else
-					val = (U16 *) &data[count];
-#endif
-					count += sizeof(U16)*4;
-					new_rot.mQ[VX] = U16_to_F32(val[VX], -1.f, 1.f);
-					new_rot.mQ[VY] = U16_to_F32(val[VY], -1.f, 1.f);
-					new_rot.mQ[VZ] = U16_to_F32(val[VZ], -1.f, 1.f);
-					new_rot.mQ[VW] = U16_to_F32(val[VW], -1.f, 1.f);
+    if ((new_rot.isNotEqualEps(getRotation(), F_ALMOST_ZERO))
+        || (new_angv != old_angv))
+    {
+        if (new_rot != mPreviousRotation)
+        {
+            resetRot();
+        }
+        else if (new_angv != old_angv)
+        {
+            if (flagUsePhysics())
+            {
+                resetRot();
+            }
+            else
+            {
+                resetRotTime();
+            }
+        }
 
-#ifdef LL_BIG_ENDIAN
-					htolememcpy(valswizzle, &data[count], MVT_U16Vec3, 6); 
-					val = valswizzle;
-#else
-					val = (U16 *) &data[count];
-#endif
-					new_angv.set(U16_to_F32(val[VX], -size, size),
-										U16_to_F32(val[VY], -size, size),
-										U16_to_F32(val[VZ], -size, size));
-					setAngularVelocity(new_angv);
-					break;
-
-				case 16:
-					// this is a terse 8 update
-					this_update_precision = 8;
-					test_pos_parent.quantize8(-0.5f*size, 1.5f*size, MIN_HEIGHT, MAX_HEIGHT);
-					new_pos_parent.mV[VX] = U8_to_F32(data[0], -0.5f*size, 1.5f*size);
-					new_pos_parent.mV[VY] = U8_to_F32(data[1], -0.5f*size, 1.5f*size);
-					new_pos_parent.mV[VZ] = U8_to_F32(data[2], MIN_HEIGHT, MAX_HEIGHT);
-
-					setVelocity(U8_to_F32(data[3], -size, size),
-								U8_to_F32(data[4], -size, size),
-								U8_to_F32(data[5], -size, size) );
-
-					setAcceleration(U8_to_F32(data[6], -size, size),
-									U8_to_F32(data[7], -size, size),
-									U8_to_F32(data[8], -size, size) );
-
-					new_rot.mQ[VX] = U8_to_F32(data[9], -1.f, 1.f);
-					new_rot.mQ[VY] = U8_to_F32(data[10], -1.f, 1.f);
-					new_rot.mQ[VZ] = U8_to_F32(data[11], -1.f, 1.f);
-					new_rot.mQ[VW] = U8_to_F32(data[12], -1.f, 1.f);
-
-					new_angv.set(U8_to_F32(data[13], -size, size),
-										U8_to_F32(data[14], -size, size),
-										U8_to_F32(data[15], -size, size) );
-					setAngularVelocity(new_angv);
-					break;
-				}
-
-				U8 state;
-				mesgsys->getU8Fast(_PREHASH_ObjectData, _PREHASH_State, state, block_num );
-				mAttachmentState = state;
-				break;
-			}
-
-		default:
-			break;
-
-		}
-	}
-	else
-	{
-		// handle the compressed case
-		LLUUID sound_uuid;
-		LLUUID	owner_id;
-		F32    gain = 0;
-		U8     sound_flags = 0;
-		F32		cutoff = 0;
-
-		U16 val[4];
-
-		U8		state;
-
-		dp->unpackU8(state, "State");
-		mAttachmentState = state;
-
-		switch(update_type)
-		{
-			case OUT_TERSE_IMPROVED:
-			{
-#ifdef DEBUG_UPDATE_TYPE
-				LL_INFOS() << "CompTI:" << getID() << LL_ENDL;
-#endif
-				U8		value;
-				dp->unpackU8(value, "agent");
-				if (value)
-				{
-					LLVector4 collision_plane;
-					dp->unpackVector4(collision_plane, "Plane");
-					((LLVOAvatar*)this)->setFootPlane(collision_plane);
-				}
-				test_pos_parent = getPosition();
-				dp->unpackVector3(new_pos_parent, "Pos");
-				dp->unpackU16(val[VX], "VelX");
-				dp->unpackU16(val[VY], "VelY");
-				dp->unpackU16(val[VZ], "VelZ");
-				setVelocity(U16_to_F32(val[VX], -128.f, 128.f),
-							U16_to_F32(val[VY], -128.f, 128.f),
-							U16_to_F32(val[VZ], -128.f, 128.f));
-				dp->unpackU16(val[VX], "AccX");
-				dp->unpackU16(val[VY], "AccY");
-				dp->unpackU16(val[VZ], "AccZ");
-				setAcceleration(U16_to_F32(val[VX], -64.f, 64.f),
-								U16_to_F32(val[VY], -64.f, 64.f),
-								U16_to_F32(val[VZ], -64.f, 64.f));
-
-				dp->unpackU16(val[VX], "ThetaX");
-				dp->unpackU16(val[VY], "ThetaY");
-				dp->unpackU16(val[VZ], "ThetaZ");
-				dp->unpackU16(val[VS], "ThetaS");
-				new_rot.mQ[VX] = U16_to_F32(val[VX], -1.f, 1.f);
-				new_rot.mQ[VY] = U16_to_F32(val[VY], -1.f, 1.f);
-				new_rot.mQ[VZ] = U16_to_F32(val[VZ], -1.f, 1.f);
-				new_rot.mQ[VS] = U16_to_F32(val[VS], -1.f, 1.f);
-				dp->unpackU16(val[VX], "AccX");
-				dp->unpackU16(val[VY], "AccY");
-				dp->unpackU16(val[VZ], "AccZ");
-				new_angv.set(U16_to_F32(val[VX], -64.f, 64.f),
-									U16_to_F32(val[VY], -64.f, 64.f),
-									U16_to_F32(val[VZ], -64.f, 64.f));
-				setAngularVelocity(new_angv);
-			}
-			break;
-			case OUT_FULL_COMPRESSED:
-			case OUT_FULL_CACHED:
-			{
-#ifdef DEBUG_UPDATE_TYPE
-				LL_INFOS() << "CompFull:" << getID() << LL_ENDL;
-#endif
-				setObjectCostStale();
-
-				if (isSelected())
-				{
-					gFloaterTools->dirty();
-				}
-	
-				dp->unpackU32(crc, "CRC");
-				mTotalCRC = crc;
-				dp->unpackU8(material, "Material");
-				U8 old_material = getMaterial();
-				if (old_material != material)
-				{
-					setMaterial(material);
-					if (mDrawable.notNull())
-					{
-						gPipeline.markMoved(mDrawable, FALSE); // undamped
-					}
-				}
-				dp->unpackU8(click_action, "ClickAction");
-				setClickAction(click_action);
-				dp->unpackVector3(new_scale, "Scale");
-				dp->unpackVector3(new_pos_parent, "Pos");
-				LLVector3 vec;
-				dp->unpackVector3(vec, "Rot");
-				new_rot.unpackFromVector3(vec);
-				setAcceleration(LLVector3::zero);
-
-				U32 value;
-				dp->unpackU32(value, "SpecialCode");
-				dp->setPassFlags(value);
-				dp->unpackUUID(owner_id, "Owner");
-
-				mOwnerID = owner_id;
-
-				if (value & 0x80)
-				{
-					dp->unpackVector3(new_angv, "Omega");
-					setAngularVelocity(new_angv);
-				}
-
-				if (value & 0x20)
-				{
-					dp->unpackU32(parent_id, "ParentID");
-				}
-				else
-				{
-					parent_id = 0;
-				}
-
-				S32 sp_size;
-				U32 size;
-				if (value & 0x2)
-				{
-					sp_size = 1;
-					delete [] mData;
-					mData = new U8[1];
-					dp->unpackU8(((U8*)mData)[0], "TreeData");
-				}
-				else if (value & 0x1)
-				{
-					dp->unpackU32(size, "ScratchPadSize");
-					delete [] mData;
-					mData = new U8[size];
-					dp->unpackBinaryData((U8 *)mData, sp_size, "PartData");
-				}
-				else
-				{
-					mData = NULL;
-				}
-
-				// Setup object text
-				if (!mText && (value & 0x4))
-				{
-				    initHudText();
-				}
-
-				if (value & 0x4)
-				{
-					std::string temp_string;
-					dp->unpackString(temp_string, "Text");
-                    
-					LLColor4U coloru;
-					dp->unpackBinaryDataFixed(coloru.mV, 4, "Color");
-					coloru.mV[3] = 255 - coloru.mV[3];
-					mText->setColor(LLColor4(coloru));
-					mText->setString(temp_string);
-// [RLVa:KB] - Checked: 2010-03-27 (RLVa-1.4.0a) | Added: RLVa-1.0.0f
-					if (RlvActions::isRlvEnabled())
-					{
-						mText->setObjectText(temp_string);
-					}
-// [/RLVa:KB]
+        // Remember the last rotation value
+        mPreviousRotation = new_rot;
 
-                    mHudText = temp_string;
-                    mHudTextColor = LLColor4(coloru);
+        // Set the rotation of the object followed by adjusting for the accumulated angular velocity (llSetTargetOmega)
+        setRotation(new_rot * mAngularVelocityRot);
+        setChanged(ROTATED | SILHOUETTE);
+    }
 
-					setChanged(TEXTURE);
-				}
-				else
-				{
-					if (mText.notNull())
-					{
-						mText->markDead();
-						mText = NULL;
-					}
-					mHudText.clear();
-				}
+    if ( gShowObjectUpdates )
+    {
+        LLColor4 color;
+        if (update_type == OUT_TERSE_IMPROVED)
+        {
+            color.setVec(0.f, 0.f, 1.f, 1.f);
+        }
+        else
+        {
+            color.setVec(1.f, 0.f, 0.f, 1.f);
+        }
+        gPipeline.addDebugBlip(getPositionAgent(), color);
+        LL_DEBUGS("MessageBlip") << "Update type " << (S32)update_type << " blip for local " << mLocalID << " at " << getPositionAgent() << LL_ENDL;
+    }
 
-                std::string media_url;
-				if (value & 0x200)
-				{
-					dp->unpackString(media_url, "MediaURL");
-				}
-                retval |= checkMediaURL(media_url);
+    const F32 MAG_CUTOFF = F_APPROXIMATELY_ZERO;
 
-				//
-				// Unpack particle system data (legacy)
-				//
-				if (value & 0x8)
-				{
-					unpackParticleSource(*dp, owner_id, true);
-				}
-				else if (!(value & 0x400))
-				{
-					deleteParticleSource();
-				}
-				
-				// Mark all extra parameters not used
-				for (auto& entry : mExtraParameterList)
-				{
-					if (entry.in_use) *entry.in_use = false;
-				}
-
-				// Unpack extra params
-				U8 num_parameters;
-				dp->unpackU8(num_parameters, "num_params");
-				U8 param_block[MAX_OBJECT_PARAMS_SIZE];
-				for (U8 param=0; param<num_parameters; ++param)
-				{
-					U16 param_type;
-					S32 param_size;
-					dp->unpackU16(param_type, "param_type");
-					dp->unpackBinaryData(param_block, param_size, "param_data");
-					//LL_INFOS() << "Param type: " << param_type << ", Size: " << param_size << LL_ENDL;
-					LLDataPackerBinaryBuffer dp2(param_block, param_size);
-					unpackParameterEntry(param_type, &dp2);
-				}
-
-				for (size_t i = 0; i < mExtraParameterList.size(); ++i)
-				{
-					auto& entry = mExtraParameterList[i];
-					if (entry.in_use && !*entry.in_use)
-					{
-						// Send an update message in case it was formerly in use
-						parameterChanged((i + 1) << 4, entry.data, FALSE, false);
-					}
-				}
-
-				if (value & 0x10)
-				{
-					dp->unpackUUID(sound_uuid, "SoundUUID");
-					dp->unpackF32(gain, "SoundGain");
-					dp->unpackU8(sound_flags, "SoundFlags");
-					dp->unpackF32(cutoff, "SoundRadius");
-				}
-
-				if (value & 0x100)
-				{
-					std::string name_value_list;
-					dp->unpackString(name_value_list, "NV");
-
-					setNameValueList(name_value_list);
-				}
-
-				mTotalCRC = crc;
-				mSoundCutOffRadius = cutoff;
-
-				setAttachedSound(sound_uuid, owner_id, gain, sound_flags);
-
-				// only get these flags on updates from sim, not cached ones
-				// Preload these five flags for every object.
-				// Finer shades require the object to be selected, and the selection manager
-				// stores the extended permission info.
-				if(mesgsys != NULL)
-				{
-				U32 flags;
-				mesgsys->getU32Fast(_PREHASH_ObjectData, _PREHASH_UpdateFlags, flags, block_num);
-				loadFlags(flags);					
-				}
-			}
-			break;
-
-		default:
-			break;
-		}
-	}
-
-	//
-	// Fix object parenting.
-	//
-	BOOL b_changed_status = FALSE;
-
-	if (OUT_TERSE_IMPROVED != update_type)
-	{
-		// We only need to update parenting on full updates, terse updates
-		// don't send parenting information.
-		if (!cur_parentp)
-		{
-			if (parent_id == 0)
-			{
-				// No parent now, no parent in message -> do nothing
-			}
-			else
-			{
-				// No parent now, new parent in message -> attach to that parent if possible
-				LLUUID parent_uuid;
-
-				if(mesgsys != NULL)
-				{
-					gObjectList.getUUIDFromLocal(parent_uuid,
-														parent_id,
-														mesgsys->getSenderIP(),
-														mesgsys->getSenderPort());
-				}
-				else
-				{
-					gObjectList.getUUIDFromLocal(parent_uuid,
-														parent_id,
-														mRegionp->getHost().getAddress(),
-														mRegionp->getHost().getPort());
-				}
-
-				LLViewerObject *sent_parentp = gObjectList.findObject(parent_uuid);
-
-				//
-				// Check to see if we have the corresponding viewer object for the parent.
-				//
-				if (sent_parentp && sent_parentp->getParent() == this)
-				{
-					// Try to recover if we attempt to attach a parent to its child
-					LL_WARNS() << "Attempt to attach a parent to it's child: " << this->getID() << " to " << sent_parentp->getID() << LL_ENDL;
-					this->removeChild(sent_parentp);
-					sent_parentp->setDrawableParent(NULL);
-				}
-				
-				if (sent_parentp && (sent_parentp != this) && !sent_parentp->isDead())
-				{
-                    if (((LLViewerObject*)sent_parentp)->isAvatar())
-                    {
-                        //LL_DEBUGS("Avatar") << "ATT got object update for attachment " << LL_ENDL; 
-                    }
-                    
-					//
-					// We have a viewer object for the parent, and it's not dead.
-					// Do the actual reparenting here.
-					//
-
-					// new parent is valid
-					b_changed_status = TRUE;
-					// ...no current parent, so don't try to remove child
-					if (mDrawable.notNull())
-					{
-						if (mDrawable->isDead() || !mDrawable->getVObj())
-						{
-							LL_WARNS() << "Drawable is dead or no VObj!" << LL_ENDL;
-							sent_parentp->addChild(this);
-						}
-						else
-						{
-							if (!setDrawableParent(sent_parentp->mDrawable)) // LLViewerObject::processUpdateMessage 1
-							{
-								// Bad, we got a cycle somehow.
-								// Kill both the parent and the child, and
-								// set cache misses for both of them.
-								LL_WARNS() << "Attempting to recover from parenting cycle!" << LL_ENDL;
-								LL_WARNS() << "Killing " << sent_parentp->getID() << " and " << getID() << LL_ENDL;
-								LL_WARNS() << "Adding to cache miss list" << LL_ENDL;
-								setParent(NULL);
-								sent_parentp->setParent(NULL);
-								getRegion()->addCacheMissFull(getLocalID());
-								getRegion()->addCacheMissFull(sent_parentp->getLocalID());
-								gObjectList.killObject(sent_parentp);
-								gObjectList.killObject(this);
-								return retval;
-							}
-// [RLVa:KB] - Checked: 2010-03-16 (RLVa-1.1.0k) | Added: RLVa-1.1.0k
-							if ( (RlvActions::isRlvEnabled()) && (sent_parentp->isAvatar()) && (sent_parentp->getID() == gAgent.getID()) )
-							{
-								// Rezzed object that's being worn as an attachment (we're assuming this will be due to llAttachToAvatar())
-								S32 idxAttachPt = ATTACHMENT_ID_FROM_STATE(getAttachmentState());
-								if (gRlvAttachmentLocks.isLockedAttachmentPoint(idxAttachPt, RLV_LOCK_ADD))
-								{
-									// If this will end up on an "add locked" attachment point then treat the attach as a user action
-									LLNameValue* nvItem = getNVPair("AttachItemID");
-									if (nvItem)
-									{
-										LLUUID idItem(nvItem->getString());
-										// URGENT-RLVa: [RLVa-1.2.0] At the moment llAttachToAvatar always seems to *add*
-										if (idItem.notNull())
-											RlvAttachmentLockWatchdog::instance().onWearAttachment(idItem, RLV_WEAR_ADD);
-									}
-								}
-							}
-// [/RLVa:KB]
-							sent_parentp->addChild(this);
-							// make sure this object gets a non-damped update
-							if (sent_parentp->mDrawable.notNull())
-							{
-								gPipeline.markMoved(sent_parentp->mDrawable, FALSE); // undamped
-							}
-						}
-					}
-					else
-					{
-						sent_parentp->addChild(this);
-					}
-					
-					// Show particles, icon and HUD
-					hideExtraDisplayItems( FALSE );
-
-					setChanged(MOVED | SILHOUETTE);
-				}
-				else
-				{
-					//
-					// No corresponding viewer object for the parent, put the various
-					// pieces on the orphan list.
-					//
-					
-					//parent_id
-					U32 ip, port; 
-					
-					if(mesgsys != NULL)
-					{
-						ip = mesgsys->getSenderIP();
-						port = mesgsys->getSenderPort();
-					}
-					else
-					{
-						ip = mRegionp->getHost().getAddress();
-						port = mRegionp->getHost().getPort();
-					}
-					gObjectList.orphanize(this, parent_id, ip, port);
-
-					// Hide particles, icon and HUD
-					hideExtraDisplayItems( TRUE );
-				}
-			}
-		}
-		else
-		{
-			// BUG: this is a bad assumption once border crossing is alowed
-			if (  (parent_id == cur_parentp->mLocalID)
-				&&(update_type == OUT_TERSE_IMPROVED))
-			{
-				// Parent now, same parent in message -> do nothing
-
-				// Debugging for suspected problems with local ids.
-				//LLUUID parent_uuid;
-				//LLViewerObjectList::getUUIDFromLocal(parent_uuid, parent_id, mesgsys->getSenderIP(), mesgsys->getSenderPort() );
-				//if (parent_uuid != cur_parentp->getID() )
-				//{
-				//	LL_ERRS() << "Local ID match but UUID mismatch of viewer object" << LL_ENDL;
-				//}
-			}
-			else
-			{
-				// Parented now, different parent in message
-				LLViewerObject *sent_parentp;
-				if (parent_id == 0)
-				{
-					//
-					// This object is no longer parented, we sent in a zero parent ID.
-					//
-					sent_parentp = NULL;
-				}
-				else
-				{
-					LLUUID parent_uuid;
-
-					if(mesgsys != NULL)
-					{
-						gObjectList.getUUIDFromLocal(parent_uuid,
-														parent_id,
-														gMessageSystem->getSenderIP(),
-														gMessageSystem->getSenderPort());
-					}
-					else
-					{
-						gObjectList.getUUIDFromLocal(parent_uuid,
-														parent_id,
-														mRegionp->getHost().getAddress(),
-														mRegionp->getHost().getPort());
-					}
-					sent_parentp = gObjectList.findObject(parent_uuid);
-					
-					if (isAvatar())
-					{
-						// This logic is meant to handle the case where a sitting avatar has reached a new sim
-						// ahead of the object she was sitting on (which is common as objects are transfered through
-						// a slower route than agents)...
-						// In this case, the local id for the object will not be valid, since the viewer has not received
-						// a full update for the object from that sim yet, so we assume that the agent is still sitting
-						// where she was originally. --RN
-						if (!sent_parentp)
-						{
-							sent_parentp = cur_parentp;
-						}
-					}
-					else if (!sent_parentp)
-					{
-						//
-						// Switching parents, but we don't know the new parent.
-						//
-						U32 ip, port; 
-					
-						if(mesgsys != NULL)
-						{
-							ip = mesgsys->getSenderIP();
-							port = mesgsys->getSenderPort();
-						}
-						else
-						{
-							ip = mRegionp->getHost().getAddress();
-							port = mRegionp->getHost().getPort();
-						}
-
-						// We're an orphan, flag things appropriately.
-						gObjectList.orphanize(this, parent_id, ip, port);
-					}
-				}
-
-				// Reattach if possible.
-				if (sent_parentp && sent_parentp != cur_parentp && sent_parentp != this)
-				{
-					// New parent is valid, detach and reattach
-					b_changed_status = TRUE;
-					if (mDrawable.notNull())
-					{
-						if (!setDrawableParent(sent_parentp->mDrawable)) // LLViewerObject::processUpdateMessage 2
-						{
-							// Bad, we got a cycle somehow.
-							// Kill both the parent and the child, and
-							// set cache misses for both of them.
-							LL_WARNS() << "Attempting to recover from parenting cycle!" << LL_ENDL;
-							LL_WARNS() << "Killing " << sent_parentp->getID() << " and " << getID() << LL_ENDL;
-							LL_WARNS() << "Adding to cache miss list" << LL_ENDL;
-							setParent(NULL);
-							sent_parentp->setParent(NULL);
-							getRegion()->addCacheMissFull(getLocalID());
-							getRegion()->addCacheMissFull(sent_parentp->getLocalID());
-							gObjectList.killObject(sent_parentp);
-							gObjectList.killObject(this);
-							return retval;
-						}
-						// make sure this object gets a non-damped update
-					}
-					cur_parentp->removeChild(this);
-					sent_parentp->addChild(this);
-					setChanged(MOVED | SILHOUETTE);
-					sent_parentp->setChanged(MOVED | SILHOUETTE);
-					if (sent_parentp->mDrawable.notNull())
-					{
-						gPipeline.markMoved(sent_parentp->mDrawable, FALSE); // undamped
-					}
-				}
-				else if (!sent_parentp)
-				{
-					bool remove_parent = true;
-					// No new parent, or the parent that we sent doesn't exist on the viewer.
-					LLViewerObject *parentp = (LLViewerObject *)getParent();
-					if (parentp)
-					{
-						if (parentp->getRegion() != getRegion())
-						{
-							// This is probably an object flying across a region boundary, the
-							// object probably ISN'T being reparented, but just got an object
-							// update out of order (child update before parent).
-							//LL_INFOS() << "Don't reparent object handoffs!" << LL_ENDL;
-							remove_parent = false;
-						}
-					}
-
-					if (remove_parent)
-					{
-						b_changed_status = TRUE;
-						if (mDrawable.notNull())
-						{
-							// clear parent to removeChild can put the drawable on the damped list
-							setDrawableParent(NULL); // LLViewerObject::processUpdateMessage 3
-						}
-
-						cur_parentp->removeChild(this);
-
-						setChanged(MOVED | SILHOUETTE);
-
-						if (mDrawable.notNull())
-						{
-							// make sure this object gets a non-damped update
-							gPipeline.markMoved(mDrawable, FALSE); // undamped
-						}
-					}
-				}
-			}
-		}
-	}
-
-	new_rot.normQuat();
-
-	if (sPingInterpolate && mesgsys != NULL)
-	{ 
-		LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mesgsys->getSender());
-		if (cdp)
-		{
-			// Note: delay is U32 and usually less then second,
-			// converting it into seconds with valueInUnits will result in 0
-			F32 ping_delay = 0.5f * time_dilation * ( ((F32)cdp->getPingDelay().value()) * 0.001f + gFrameDTClamped);
-			LLVector3 diff = getVelocity() * ping_delay; 
-			new_pos_parent += diff;
-		}
-		else
-		{
-			LL_WARNS() << "findCircuit() returned NULL; skipping interpolation" << LL_ENDL;
-		}
-	}
-
-	//////////////////////////
-	//
-	// Set the generic change flags...
-	//
-	//
-
-	// If we're going to skip this message, why are we 
-	// doing all the parenting, etc above?
-	if(mesgsys != NULL)
-	{
-	U32 packet_id = mesgsys->getCurrentRecvPacketID(); 
-	if (packet_id < mLatestRecvPacketID && 
-		mLatestRecvPacketID - packet_id < 65536)
-	{
-		//skip application of this message, it's old
-		return retval;
-	}
-	mLatestRecvPacketID = packet_id;
-	}
-
-	// Set the change flags for scale
-	if (new_scale != getScale())
-	{
-		setChanged(SCALED | SILHOUETTE);
-		setScale(new_scale);  // Must follow setting permYouOwner()
-	}
-
-	// first, let's see if the new position is actually a change
-
-	//static S32 counter = 0;
-
-	F32 vel_mag_sq = getVelocity().magVecSquared();
-	F32 accel_mag_sq = getAcceleration().magVecSquared();
-
-	if (  ((b_changed_status)||(test_pos_parent != new_pos_parent))
-		||(  (!isSelected())
-		   &&(  (vel_mag_sq != 0.f)
-			  ||(accel_mag_sq != 0.f)
-			  ||(this_update_precision > mBestUpdatePrecision))))
-	{
-		mBestUpdatePrecision = this_update_precision;
-		
-		LLVector3 diff = new_pos_parent - test_pos_parent ;
-		F32 mag_sqr = diff.magVecSquared() ;
-		if(llfinite(mag_sqr)) 
-		{
-			setPositionParent(new_pos_parent);
-		}
-		else
-		{
-			LL_WARNS() << "Can not move the object/avatar to an infinite location!" << LL_ENDL ;	
-
-			retval |= INVALID_UPDATE ;
-		}
-
-		if (mParent && ((LLViewerObject*)mParent)->isAvatar())
-		{
-			// we have changed the position of an attachment, so we need to clamp it
-			LLVOAvatar *avatar = (LLVOAvatar*)mParent;
-
-			avatar->clampAttachmentPositions();
-		}
-		
-		// If we're snapping the position by more than 0.5m, update LLViewerStats::mAgentPositionSnaps
-		if ( asAvatar() && asAvatar()->isSelf() && (mag_sqr > 0.25f) )
-		{
-			record(LLStatViewer::AGENT_POSITION_SNAP, LLUnit<F64, LLUnits::Meters>(diff.length()));
-		}
-	}
-
-	if ((new_rot.isNotEqualEps(getRotation(), F_ALMOST_ZERO))
-		|| (new_angv != old_angv))
-	{
-		if (new_rot != mPreviousRotation)
-		{
-			resetRot();
-		}
-		else if (new_angv != old_angv)
-		{
-			if (flagUsePhysics())
-			{
-				resetRot();
-			}
-			else
-			{
-				resetRotTime();
-			}
-		}
-
-		// Remember the last rotation value
-		mPreviousRotation = new_rot;
-
-		// Set the rotation of the object followed by adjusting for the accumulated angular velocity (llSetTargetOmega)
-		setRotation(new_rot * mAngularVelocityRot);
-		setChanged(ROTATED | SILHOUETTE);
-	}
-
-	if ( gShowObjectUpdates )
-	{
-		LLColor4 color;
-		if (update_type == OUT_TERSE_IMPROVED)
-		{
-			color.setVec(0.f, 0.f, 1.f, 1.f);
-		}
-		else
-		{
-			color.setVec(1.f, 0.f, 0.f, 1.f);
-		}
-		gPipeline.addDebugBlip(getPositionAgent(), color);
-		LL_DEBUGS("MessageBlip") << "Update type " << (S32)update_type << " blip for local " << mLocalID << " at " << getPositionAgent() << LL_ENDL;
-	}
-
-	const F32 MAG_CUTOFF = F_APPROXIMATELY_ZERO;
-
-	llassert(vel_mag_sq >= 0.f);
-	llassert(accel_mag_sq >= 0.f);
-	llassert(getAngularVelocity().magVecSquared() >= 0.f);
-
-	if ((MAG_CUTOFF >= vel_mag_sq) && 
-		(MAG_CUTOFF >= accel_mag_sq) &&
-		(MAG_CUTOFF >= getAngularVelocity().magVecSquared()))
-	{
-		mStatic = TRUE; // This object doesn't move!
-	}
-	else
-	{
-		mStatic = FALSE;
-	}
+    llassert(vel_mag_sq >= 0.f);
+    llassert(accel_mag_sq >= 0.f);
+    llassert(getAngularVelocity().magVecSquared() >= 0.f);
+
+    if ((MAG_CUTOFF >= vel_mag_sq) &&
+        (MAG_CUTOFF >= accel_mag_sq) &&
+        (MAG_CUTOFF >= getAngularVelocity().magVecSquared()))
+    {
+        mStatic = TRUE; // This object doesn't move!
+    }
+    else
+    {
+        mStatic = FALSE;
+    }
 
 // BUG: This code leads to problems during group rotate and any scale operation.
-// Small discepencies between the simulator and viewer representations cause the 
+// Small discepencies between the simulator and viewer representations cause the
 // selection center to creep, leading to objects moving around the wrong center.
-// 
+//
 // Removing this, however, means that if someone else drags an object you have
 // selected, your selection center and dialog boxes will be wrong.  It also means
 // that higher precision information on selected objects will be ignored.
 //
 // I believe the group rotation problem is fixed.  JNC 1.21.2002
 //
-	// Additionally, if any child is selected, need to update the dialogs and selection
-	// center.
-	BOOL needs_refresh = mUserSelected;
-	for (const LLViewerObject* child : mChildList)
-	{
-		needs_refresh = needs_refresh || child->mUserSelected;
-	}
+    // Additionally, if any child is selected, need to update the dialogs and selection
+    // center.
+    BOOL needs_refresh = mUserSelected;
+    for (const LLViewerObject* child : mChildList)
+    {
+        needs_refresh = needs_refresh || child->mUserSelected;
+    }
 
     static LLCachedControl<bool> allow_select_avatar(gSavedSettings, "AllowSelectAvatar", FALSE);
-	if (needs_refresh)
-	{
-		LLSelectMgr::getInstance()->updateSelectionCenter();
-		dialog_refresh_all();
-	}
+    if (needs_refresh)
+    {
+        LLSelectMgr::getInstance()->updateSelectionCenter();
+        dialog_refresh_all();
+    }
     else if (allow_select_avatar && asAvatar())
     {
         // Override any avatar position updates received
@@ -2545,287 +2545,287 @@ U32 LLViewerObject::processUpdateMessage(LLMessageSystem *mesgsys,
     }
 
 
-	// Mark update time as approx. now, with the ping delay.
-	// Ping delay is off because it's not set for velocity interpolation, causing
-	// much jumping and hopping around...
+    // Mark update time as approx. now, with the ping delay.
+    // Ping delay is off because it's not set for velocity interpolation, causing
+    // much jumping and hopping around...
 
-//	U32 ping_delay = mesgsys->mCircuitInfo.getPingDelay();
-	mLastInterpUpdateSecs = LLFrameTimer::getElapsedSeconds();
-	mLastMessageUpdateSecs = mLastInterpUpdateSecs;
-	if (mDrawable.notNull())
-	{
-		// Don't clear invisibility flag on update if still orphaned!
-		if (mDrawable->isState(LLDrawable::FORCE_INVISIBLE) && !mOrphaned)
-		{
-// 			LL_DEBUGS() << "Clearing force invisible: " << mID << ":" << getPCodeString() << ":" << getPositionAgent() << LL_ENDL;
-			mDrawable->clearState(LLDrawable::FORCE_INVISIBLE);
-			gPipeline.markRebuild( mDrawable, LLDrawable::REBUILD_ALL);
-		}
-	}
+//  U32 ping_delay = mesgsys->mCircuitInfo.getPingDelay();
+    mLastInterpUpdateSecs = LLFrameTimer::getElapsedSeconds();
+    mLastMessageUpdateSecs = mLastInterpUpdateSecs;
+    if (mDrawable.notNull())
+    {
+        // Don't clear invisibility flag on update if still orphaned!
+        if (mDrawable->isState(LLDrawable::FORCE_INVISIBLE) && !mOrphaned)
+        {
+//          LL_DEBUGS() << "Clearing force invisible: " << mID << ":" << getPCodeString() << ":" << getPositionAgent() << LL_ENDL;
+            mDrawable->clearState(LLDrawable::FORCE_INVISIBLE);
+            gPipeline.markRebuild( mDrawable, LLDrawable::REBUILD_ALL);
+        }
+    }
 
-	// Update special hover cursor status
-	bool special_hover_cursor = specialHoverCursor();
-	if (old_special_hover_cursor != special_hover_cursor
-		&& mDrawable.notNull())
-	{
-		mDrawable->updateSpecialHoverCursor(special_hover_cursor);
-	}
+    // Update special hover cursor status
+    bool special_hover_cursor = specialHoverCursor();
+    if (old_special_hover_cursor != special_hover_cursor
+        && mDrawable.notNull())
+    {
+        mDrawable->updateSpecialHoverCursor(special_hover_cursor);
+    }
 
-	return retval;
+    return retval;
 }
 
 BOOL LLViewerObject::isActive() const
 {
-	return TRUE;
+    return TRUE;
 }
 
 //load flags from cache or from message
 void LLViewerObject::loadFlags(U32 flags)
 {
-	if(flags == (U32)(-1))
-	{
-		return; //invalid
-	}
+    if(flags == (U32)(-1))
+    {
+        return; //invalid
+    }
 
-	// keep local flags and overwrite remote-controlled flags
-	mFlags = (mFlags & FLAGS_LOCAL) | flags;
+    // keep local flags and overwrite remote-controlled flags
+    mFlags = (mFlags & FLAGS_LOCAL) | flags;
 
-	// ...new objects that should come in selected need to be added to the selected list
-	mCreateSelected = ((flags & FLAGS_CREATE_SELECTED) != 0);
-	return;
+    // ...new objects that should come in selected need to be added to the selected list
+    mCreateSelected = ((flags & FLAGS_CREATE_SELECTED) != 0);
+    return;
 }
 
 void LLViewerObject::idleUpdate(LLAgent &agent, const F64 &frame_time)
 {
-	if (!mDead)
-	{
-		if (!mStatic && sVelocityInterpolate && !isSelected())
-		{
-			// calculate dt from last update
-			F32 time_dilation = mRegionp ? mRegionp->getTimeDilation() : 1.0f;
-			F32 dt_raw = ((F64Seconds)frame_time - mLastInterpUpdateSecs).value();
-			F32 dt = time_dilation * dt_raw;
+    if (!mDead)
+    {
+        if (!mStatic && sVelocityInterpolate && !isSelected())
+        {
+            // calculate dt from last update
+            F32 time_dilation = mRegionp ? mRegionp->getTimeDilation() : 1.0f;
+            F32 dt_raw = ((F64Seconds)frame_time - mLastInterpUpdateSecs).value();
+            F32 dt = time_dilation * dt_raw;
 
-			applyAngularVelocity(dt);
+            applyAngularVelocity(dt);
 
-			if (isAttachment())
-			{
-				mLastInterpUpdateSecs = (F64Seconds)frame_time;
-				return;
-			}
-			else
-			{	// Move object based on it's velocity and rotation
-				interpolateLinearMotion(frame_time, dt);
-			}
-		}
+            if (isAttachment())
+            {
+                mLastInterpUpdateSecs = (F64Seconds)frame_time;
+                return;
+            }
+            else
+            {   // Move object based on it's velocity and rotation
+                interpolateLinearMotion(frame_time, dt);
+            }
+        }
 
-		updateDrawable(FALSE);
-	}
+        updateDrawable(FALSE);
+    }
 }
 
 
 // Move an object due to idle-time viewer side updates by interpolating motion
 void LLViewerObject::interpolateLinearMotion(const F64SecondsImplicit& frame_time, const F32SecondsImplicit& dt_seconds)
 {
-	// linear motion
-	// PHYSICS_TIMESTEP is used below to correct for the fact that the velocity in object
-	// updates represents the average velocity of the last timestep, rather than the final velocity.
-	// the time dilation above should guarantee that dt is never less than PHYSICS_TIMESTEP, theoretically
-	// 
-	// *TODO: should also wrap linear accel/velocity in check
-	// to see if object is selected, instead of explicitly
-	// zeroing it out	
-
-	F32 dt = dt_seconds;
-	F64Seconds time_since_last_update = frame_time - mLastMessageUpdateSecs;
-	if (time_since_last_update <= (F64Seconds)0.0 || dt <= 0.f)
-	{
-		return;
-	}
-
-	LLVector3 accel = getAcceleration();
-	LLVector3 vel 	= getVelocity();
-	
-	if (sMaxUpdateInterpolationTime <= (F64Seconds)0.0)
-	{	// Old code path ... unbounded, simple interpolation
-		if (!(accel.isExactlyZero() && vel.isExactlyZero()))
-		{
-			LLVector3 pos   = (vel + (0.5f * (dt-PHYSICS_TIMESTEP)) * accel) * dt;  
-		
-			// region local  
-			setPositionRegion(pos + getPositionRegion());
-			setVelocity(vel + accel*dt);	
-			
-			// for objects that are spinning but not translating, make sure to flag them as having moved
-			setChanged(MOVED | SILHOUETTE);
-		}
-	}
-	else if (!accel.isExactlyZero() || !vel.isExactlyZero())		// object is moving
-	{	// Object is moving, and hasn't been too long since we got an update from the server
-		
-		// Calculate predicted position and velocity
-		LLVector3 new_pos = (vel + (0.5f * (dt-PHYSICS_TIMESTEP)) * accel) * dt;	
-		LLVector3 new_v = accel * dt;
-
-		if (time_since_last_update > sPhaseOutUpdateInterpolationTime &&
-			sPhaseOutUpdateInterpolationTime > (F64Seconds)0.0)
-		{	// Haven't seen a viewer update in a while, check to see if the circuit is still active
-			if (mRegionp)
-			{	// The simulator will NOT send updates if the object continues normally on the path
-				// predicted by the velocity and the acceleration (often gravity) sent to the viewer
-				// So check to see if the circuit is blocked, which means the sim is likely in a long lag
-				LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit( mRegionp->getHost() );
-				if (cdp)
-				{
-					// Find out how many seconds since last packet arrived on the circuit
-					F64Seconds time_since_last_packet = LLMessageSystem::getMessageTimeSeconds() - cdp->getLastPacketInTime();
-
-					if (!cdp->isAlive() ||		// Circuit is dead or blocked
-						 cdp->isBlocked() ||	// or doesn't seem to be getting any packets
-						 (time_since_last_packet > sPhaseOutUpdateInterpolationTime))
-					{
-						// Start to reduce motion interpolation since we haven't seen a server update in a while
-						F64Seconds time_since_last_interpolation = frame_time - mLastInterpUpdateSecs;
-						F64 phase_out = 1.0;
-						if (time_since_last_update > sMaxUpdateInterpolationTime)
-						{	// Past the time limit, so stop the object
-							phase_out = 0.0;
-							//LL_INFOS() << "Motion phase out to zero" << LL_ENDL;
-
-							// Kill angular motion as well.  Note - not adding this due to paranoia
-							// about stopping rotation for llTargetOmega objects and not having it restart
-							// setAngularVelocity(LLVector3::zero);
-						}
-						else if (mLastInterpUpdateSecs - mLastMessageUpdateSecs > sPhaseOutUpdateInterpolationTime)
-						{	// Last update was already phased out a bit
-							phase_out = (sMaxUpdateInterpolationTime - time_since_last_update) / 
-										(sMaxUpdateInterpolationTime - time_since_last_interpolation);
-							//LL_INFOS() << "Continuing motion phase out of " << (F32) phase_out << LL_ENDL;
-						}
-						else
-						{	// Phase out from full value
-							phase_out = (sMaxUpdateInterpolationTime - time_since_last_update) / 
-										(sMaxUpdateInterpolationTime - sPhaseOutUpdateInterpolationTime);
-							//LL_INFOS() << "Starting motion phase out of " << (F32) phase_out << LL_ENDL;
-						}
-						phase_out = llclamp(phase_out, 0.0, 1.0);
-
-						new_pos = new_pos * ((F32) phase_out);
-						new_v = new_v * ((F32) phase_out);
-					}
-				}
-			}
-		}
-
-		new_pos = new_pos + getPositionRegion();
-		new_v = new_v + vel;
-
-		auto& worldInst = LLWorld::instance();
-
-		// Clamp interpolated position to minimum underground and maximum region height
-		LLVector3d new_pos_global = mRegionp->getPosGlobalFromRegion(new_pos);
-		F32 min_height;
-		if (isAvatar())
-		{	// Make a better guess about AVs not going underground
-			min_height = worldInst.resolveLandHeightGlobal(new_pos_global);
-			min_height += (0.5f * getScale().mV[VZ]);
-		}
-		else
-		{	// This will put the object underground, but we can't tell if it will stop 
-			// at ground level or not
-			min_height = worldInst.getMinAllowedZ(this, new_pos_global);
-			// Cap maximum height
-			new_pos.mV[VZ] = llmin(worldInst.getRegionMaxHeight(), new_pos.mV[VZ]);
-		}
-
-		new_pos.mV[VZ] = llmax(min_height, new_pos.mV[VZ]);
-
-		// Check to see if it's going off the region
-		LLVector3 temp(new_pos.mV[VX], new_pos.mV[VY], 0.f);
-		if (temp.clamp(0.f, mRegionp->getWidth()))
-		{	// Going off this region, so see if we might end up on another region
-			LLVector3d old_pos_global = mRegionp->getPosGlobalFromRegion(getPositionRegion());
-			new_pos_global = mRegionp->getPosGlobalFromRegion(new_pos);		// Re-fetch in case it got clipped above
-
-			// Clip the positions to known regions
-			LLVector3d clip_pos_global = worldInst.clipToVisibleRegions(old_pos_global, new_pos_global);
-			if (clip_pos_global != new_pos_global)
-			{
-				// Was clipped, so this means we hit a edge where there is no region to enter
-				LLVector3 clip_pos = mRegionp->getPosRegionFromGlobal(clip_pos_global);
+    // linear motion
+    // PHYSICS_TIMESTEP is used below to correct for the fact that the velocity in object
+    // updates represents the average velocity of the last timestep, rather than the final velocity.
+    // the time dilation above should guarantee that dt is never less than PHYSICS_TIMESTEP, theoretically
+    //
+    // *TODO: should also wrap linear accel/velocity in check
+    // to see if object is selected, instead of explicitly
+    // zeroing it out
+
+    F32 dt = dt_seconds;
+    F64Seconds time_since_last_update = frame_time - mLastMessageUpdateSecs;
+    if (time_since_last_update <= (F64Seconds)0.0 || dt <= 0.f)
+    {
+        return;
+    }
+
+    LLVector3 accel = getAcceleration();
+    LLVector3 vel   = getVelocity();
+
+    if (sMaxUpdateInterpolationTime <= (F64Seconds)0.0)
+    {   // Old code path ... unbounded, simple interpolation
+        if (!(accel.isExactlyZero() && vel.isExactlyZero()))
+        {
+            LLVector3 pos   = (vel + (0.5f * (dt-PHYSICS_TIMESTEP)) * accel) * dt;
+
+            // region local
+            setPositionRegion(pos + getPositionRegion());
+            setVelocity(vel + accel*dt);
+
+            // for objects that are spinning but not translating, make sure to flag them as having moved
+            setChanged(MOVED | SILHOUETTE);
+        }
+    }
+    else if (!accel.isExactlyZero() || !vel.isExactlyZero())        // object is moving
+    {   // Object is moving, and hasn't been too long since we got an update from the server
+
+        // Calculate predicted position and velocity
+        LLVector3 new_pos = (vel + (0.5f * (dt-PHYSICS_TIMESTEP)) * accel) * dt;
+        LLVector3 new_v = accel * dt;
+
+        if (time_since_last_update > sPhaseOutUpdateInterpolationTime &&
+            sPhaseOutUpdateInterpolationTime > (F64Seconds)0.0)
+        {   // Haven't seen a viewer update in a while, check to see if the circuit is still active
+            if (mRegionp)
+            {   // The simulator will NOT send updates if the object continues normally on the path
+                // predicted by the velocity and the acceleration (often gravity) sent to the viewer
+                // So check to see if the circuit is blocked, which means the sim is likely in a long lag
+                LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit( mRegionp->getHost() );
+                if (cdp)
+                {
+                    // Find out how many seconds since last packet arrived on the circuit
+                    F64Seconds time_since_last_packet = LLMessageSystem::getMessageTimeSeconds() - cdp->getLastPacketInTime();
+
+                    if (!cdp->isAlive() ||      // Circuit is dead or blocked
+                         cdp->isBlocked() ||    // or doesn't seem to be getting any packets
+                         (time_since_last_packet > sPhaseOutUpdateInterpolationTime))
+                    {
+                        // Start to reduce motion interpolation since we haven't seen a server update in a while
+                        F64Seconds time_since_last_interpolation = frame_time - mLastInterpUpdateSecs;
+                        F64 phase_out = 1.0;
+                        if (time_since_last_update > sMaxUpdateInterpolationTime)
+                        {   // Past the time limit, so stop the object
+                            phase_out = 0.0;
+                            //LL_INFOS() << "Motion phase out to zero" << LL_ENDL;
+
+                            // Kill angular motion as well.  Note - not adding this due to paranoia
+                            // about stopping rotation for llTargetOmega objects and not having it restart
+                            // setAngularVelocity(LLVector3::zero);
+                        }
+                        else if (mLastInterpUpdateSecs - mLastMessageUpdateSecs > sPhaseOutUpdateInterpolationTime)
+                        {   // Last update was already phased out a bit
+                            phase_out = (sMaxUpdateInterpolationTime - time_since_last_update) /
+                                        (sMaxUpdateInterpolationTime - time_since_last_interpolation);
+                            //LL_INFOS() << "Continuing motion phase out of " << (F32) phase_out << LL_ENDL;
+                        }
+                        else
+                        {   // Phase out from full value
+                            phase_out = (sMaxUpdateInterpolationTime - time_since_last_update) /
+                                        (sMaxUpdateInterpolationTime - sPhaseOutUpdateInterpolationTime);
+                            //LL_INFOS() << "Starting motion phase out of " << (F32) phase_out << LL_ENDL;
+                        }
+                        phase_out = llclamp(phase_out, 0.0, 1.0);
+
+                        new_pos = new_pos * ((F32) phase_out);
+                        new_v = new_v * ((F32) phase_out);
+                    }
+                }
+            }
+        }
+
+        new_pos = new_pos + getPositionRegion();
+        new_v = new_v + vel;
+
+        auto& worldInst = LLWorld::instance();
+
+        // Clamp interpolated position to minimum underground and maximum region height
+        LLVector3d new_pos_global = mRegionp->getPosGlobalFromRegion(new_pos);
+        F32 min_height;
+        if (isAvatar())
+        {   // Make a better guess about AVs not going underground
+            min_height = worldInst.resolveLandHeightGlobal(new_pos_global);
+            min_height += (0.5f * getScale().mV[VZ]);
+        }
+        else
+        {   // This will put the object underground, but we can't tell if it will stop
+            // at ground level or not
+            min_height = worldInst.getMinAllowedZ(this, new_pos_global);
+            // Cap maximum height
+            new_pos.mV[VZ] = llmin(worldInst.getRegionMaxHeight(), new_pos.mV[VZ]);
+        }
+
+        new_pos.mV[VZ] = llmax(min_height, new_pos.mV[VZ]);
+
+        // Check to see if it's going off the region
+        LLVector3 temp(new_pos.mV[VX], new_pos.mV[VY], 0.f);
+        if (temp.clamp(0.f, mRegionp->getWidth()))
+        {   // Going off this region, so see if we might end up on another region
+            LLVector3d old_pos_global = mRegionp->getPosGlobalFromRegion(getPositionRegion());
+            new_pos_global = mRegionp->getPosGlobalFromRegion(new_pos);     // Re-fetch in case it got clipped above
+
+            // Clip the positions to known regions
+            LLVector3d clip_pos_global = worldInst.clipToVisibleRegions(old_pos_global, new_pos_global);
+            if (clip_pos_global != new_pos_global)
+            {
+                // Was clipped, so this means we hit a edge where there is no region to enter
+                LLVector3 clip_pos = mRegionp->getPosRegionFromGlobal(clip_pos_global);
 #ifdef SHOW_DEBUG
-				LL_DEBUGS("Interpolate") << "Hit empty region edge, clipped predicted position to "
-										 << clip_pos
-										 << " from " << new_pos << LL_ENDL;
+                LL_DEBUGS("Interpolate") << "Hit empty region edge, clipped predicted position to "
+                                         << clip_pos
+                                         << " from " << new_pos << LL_ENDL;
 #endif
-				new_pos = clip_pos;
-				
-				// Stop motion and get server update for bouncing on the edge
-				new_v.clear();
-				setAcceleration(LLVector3::zero);
-			}
-			else
-			{
-				// Check for how long we are crossing.
-				// Note: theoretically we can find time from velocity, acceleration and
-				// distance from border to new position, but it is not going to work
-				// if 'phase_out' activates
-				if (mRegionCrossExpire == 0)
-				{
-					// Workaround: we can't accurately figure out time when we cross border
-					// so just write down time 'after the fact', it is far from optimal in
-					// case of lags, but for lags sMaxUpdateInterpolationTime will kick in first
+                new_pos = clip_pos;
+
+                // Stop motion and get server update for bouncing on the edge
+                new_v.clear();
+                setAcceleration(LLVector3::zero);
+            }
+            else
+            {
+                // Check for how long we are crossing.
+                // Note: theoretically we can find time from velocity, acceleration and
+                // distance from border to new position, but it is not going to work
+                // if 'phase_out' activates
+                if (mRegionCrossExpire == 0)
+                {
+                    // Workaround: we can't accurately figure out time when we cross border
+                    // so just write down time 'after the fact', it is far from optimal in
+                    // case of lags, but for lags sMaxUpdateInterpolationTime will kick in first
 #ifdef SHOW_DEBUG
-					LL_DEBUGS("Interpolate") << "Predicted region crossing, new position " << new_pos << LL_ENDL;
+                    LL_DEBUGS("Interpolate") << "Predicted region crossing, new position " << new_pos << LL_ENDL;
 #endif
-					mRegionCrossExpire = frame_time + sMaxRegionCrossingInterpolationTime;
-				}
-				else if (frame_time > mRegionCrossExpire)
-				{
-					// Predicting crossing over 1s, stop motion
-					// Stop motion
+                    mRegionCrossExpire = frame_time + sMaxRegionCrossingInterpolationTime;
+                }
+                else if (frame_time > mRegionCrossExpire)
+                {
+                    // Predicting crossing over 1s, stop motion
+                    // Stop motion
 #ifdef SHOW_DEBUG
-					LL_DEBUGS("Interpolate") << "Predicting region crossing for too long, stopping at " << new_pos << LL_ENDL;
+                    LL_DEBUGS("Interpolate") << "Predicting region crossing for too long, stopping at " << new_pos << LL_ENDL;
 #endif
-					new_v.clear();
-					setAcceleration(LLVector3::zero);
-					mRegionCrossExpire = 0;
-				}
-			}
-		}
-		else
-		{
-			mRegionCrossExpire = 0;
-		}
+                    new_v.clear();
+                    setAcceleration(LLVector3::zero);
+                    mRegionCrossExpire = 0;
+                }
+            }
+        }
+        else
+        {
+            mRegionCrossExpire = 0;
+        }
+
+        // Set new position and velocity
+        setPositionRegion(new_pos);
+        setVelocity(new_v);
 
-		// Set new position and velocity
-		setPositionRegion(new_pos);
-		setVelocity(new_v);	
-		
-		// for objects that are spinning but not translating, make sure to flag them as having moved
-		setChanged(MOVED | SILHOUETTE);
-	}		
+        // for objects that are spinning but not translating, make sure to flag them as having moved
+        setChanged(MOVED | SILHOUETTE);
+    }
 
-	// Update the last time we did anything
-	mLastInterpUpdateSecs = frame_time;
+    // Update the last time we did anything
+    mLastInterpUpdateSecs = frame_time;
 }
 
 
 
 BOOL LLViewerObject::setData(const U8 *datap, const U32 data_size)
 {
-	delete [] mData;
+    delete [] mData;
 
-	if (datap)
-	{
-		mData = new U8[data_size];
-		if (!mData)
-		{
-			return FALSE;
-		}
-		memcpy(mData, datap, data_size);		/* Flawfinder: ignore */
-	}
-	return TRUE;
+    if (datap)
+    {
+        mData = new U8[data_size];
+        if (!mData)
+        {
+            return FALSE;
+        }
+        memcpy(mData, datap, data_size);        /* Flawfinder: ignore */
+    }
+    return TRUE;
 }
 
 // delete an item in the inventory, but don't tell the server. This is
@@ -2833,213 +2833,213 @@ BOOL LLViewerObject::setData(const U8 *datap, const U32 data_size)
 // This will only delete the first item with an item_id in the list
 void LLViewerObject::deleteInventoryItem(const LLUUID& item_id)
 {
-	if(mInventory)
-	{
-		LLInventoryObject::object_list_t::iterator it = mInventory->begin();
-		LLInventoryObject::object_list_t::iterator end = mInventory->end();
-		for( ; it != end; ++it )
-		{
-			if((*it)->getUUID() == item_id)
-			{
-				// This is safe only because we return immediatly.
-				mInventory->erase(it); // will deref and delete it
-				return;
-			}
-		}
-		doInventoryCallback();
-	}
+    if(mInventory)
+    {
+        LLInventoryObject::object_list_t::iterator it = mInventory->begin();
+        LLInventoryObject::object_list_t::iterator end = mInventory->end();
+        for( ; it != end; ++it )
+        {
+            if((*it)->getUUID() == item_id)
+            {
+                // This is safe only because we return immediatly.
+                mInventory->erase(it); // will deref and delete it
+                return;
+            }
+        }
+        doInventoryCallback();
+    }
 }
 
 void LLViewerObject::doUpdateInventory(
-	LLPointer<LLViewerInventoryItem>& item,
-	U8 key,
-	bool is_new)
-{
-	LLViewerInventoryItem* old_item = NULL;
-	if(TASK_INVENTORY_ITEM_KEY == key)
-	{
-		old_item = (LLViewerInventoryItem*)getInventoryObject(item->getUUID());
-	}
-	else if(TASK_INVENTORY_ASSET_KEY == key)
-	{
-		old_item = getInventoryItemByAsset(item->getAssetUUID());
-	}
-	LLUUID item_id;
-	LLUUID new_owner;
-	LLUUID new_group;
-	BOOL group_owned = FALSE;
-	if(old_item)
-	{
-		item_id = old_item->getUUID();
-		new_owner = old_item->getPermissions().getOwner();
-		new_group = old_item->getPermissions().getGroup();
-		group_owned = old_item->getPermissions().isGroupOwned();
-		old_item = NULL;
-	}
-	else
-	{
-		item_id = item->getUUID();
-	}
-	if(!is_new && mInventory)
-	{
-		// Attempt to update the local inventory. If we can get the
-		// object perm, we have perfect visibility, so we want the
-		// serial number to match. Otherwise, take our best guess and
-		// make sure that the serial number does not match.
-		deleteInventoryItem(item_id);
-		LLPermissions perm(item->getPermissions());
-		LLPermissions* obj_perm = LLSelectMgr::getInstance()->findObjectPermissions(this);
-		bool is_atomic = ((S32)LLAssetType::AT_OBJECT == item->getType()) ? false : true;
-		if(obj_perm)
-		{
-			perm.setOwnerAndGroup(LLUUID::null, obj_perm->getOwner(), obj_perm->getGroup(), is_atomic);
-		}
-		else
-		{
-			if(group_owned)
-			{
-				perm.setOwnerAndGroup(LLUUID::null, new_owner, new_group, is_atomic);
-			}
-			else if(!new_owner.isNull())
-			{
-				// The object used to be in inventory, so we can
-				// assume the owner and group will match what they are
-				// there.
-				perm.setOwnerAndGroup(LLUUID::null, new_owner, new_group, is_atomic);
-			}
-			// *FIX: can make an even better guess by using the mPermGroup flags
-			else if(permYouOwner())
-			{
-				// best guess.
-				perm.setOwnerAndGroup(LLUUID::null, gAgent.getID(), item->getPermissions().getGroup(), is_atomic);
-				--mExpectedInventorySerialNum;
-			}
-			else
-			{
-				// dummy it up.
-				perm.setOwnerAndGroup(LLUUID::null, LLUUID::null, LLUUID::null, is_atomic);
-				--mExpectedInventorySerialNum;
-			}
-		}
-		LLViewerInventoryItem* oldItem = item;
-		LLViewerInventoryItem* new_item = new LLViewerInventoryItem(oldItem);
-		new_item->setPermissions(perm);
-		mInventory->push_front(new_item);
-		doInventoryCallback();
-		++mExpectedInventorySerialNum;
-	}
-	else if (is_new)
-	{
-		++mExpectedInventorySerialNum;
-	}
+    LLPointer<LLViewerInventoryItem>& item,
+    U8 key,
+    bool is_new)
+{
+    LLViewerInventoryItem* old_item = NULL;
+    if(TASK_INVENTORY_ITEM_KEY == key)
+    {
+        old_item = (LLViewerInventoryItem*)getInventoryObject(item->getUUID());
+    }
+    else if(TASK_INVENTORY_ASSET_KEY == key)
+    {
+        old_item = getInventoryItemByAsset(item->getAssetUUID());
+    }
+    LLUUID item_id;
+    LLUUID new_owner;
+    LLUUID new_group;
+    BOOL group_owned = FALSE;
+    if(old_item)
+    {
+        item_id = old_item->getUUID();
+        new_owner = old_item->getPermissions().getOwner();
+        new_group = old_item->getPermissions().getGroup();
+        group_owned = old_item->getPermissions().isGroupOwned();
+        old_item = NULL;
+    }
+    else
+    {
+        item_id = item->getUUID();
+    }
+    if(!is_new && mInventory)
+    {
+        // Attempt to update the local inventory. If we can get the
+        // object perm, we have perfect visibility, so we want the
+        // serial number to match. Otherwise, take our best guess and
+        // make sure that the serial number does not match.
+        deleteInventoryItem(item_id);
+        LLPermissions perm(item->getPermissions());
+        LLPermissions* obj_perm = LLSelectMgr::getInstance()->findObjectPermissions(this);
+        bool is_atomic = ((S32)LLAssetType::AT_OBJECT == item->getType()) ? false : true;
+        if(obj_perm)
+        {
+            perm.setOwnerAndGroup(LLUUID::null, obj_perm->getOwner(), obj_perm->getGroup(), is_atomic);
+        }
+        else
+        {
+            if(group_owned)
+            {
+                perm.setOwnerAndGroup(LLUUID::null, new_owner, new_group, is_atomic);
+            }
+            else if(!new_owner.isNull())
+            {
+                // The object used to be in inventory, so we can
+                // assume the owner and group will match what they are
+                // there.
+                perm.setOwnerAndGroup(LLUUID::null, new_owner, new_group, is_atomic);
+            }
+            // *FIX: can make an even better guess by using the mPermGroup flags
+            else if(permYouOwner())
+            {
+                // best guess.
+                perm.setOwnerAndGroup(LLUUID::null, gAgent.getID(), item->getPermissions().getGroup(), is_atomic);
+                --mExpectedInventorySerialNum;
+            }
+            else
+            {
+                // dummy it up.
+                perm.setOwnerAndGroup(LLUUID::null, LLUUID::null, LLUUID::null, is_atomic);
+                --mExpectedInventorySerialNum;
+            }
+        }
+        LLViewerInventoryItem* oldItem = item;
+        LLViewerInventoryItem* new_item = new LLViewerInventoryItem(oldItem);
+        new_item->setPermissions(perm);
+        mInventory->push_front(new_item);
+        doInventoryCallback();
+        ++mExpectedInventorySerialNum;
+    }
+    else if (is_new)
+    {
+        ++mExpectedInventorySerialNum;
+    }
 }
 
 // save a script, which involves removing the old one, and rezzing
 // in the new one. This method should be called with the asset id
 // of the new and old script AFTER the bytecode has been saved.
 void LLViewerObject::saveScript(
-	const LLViewerInventoryItem* item,
-	BOOL active,
-	bool is_new)
-{
-	/*
-	 * XXXPAM Investigate not making this copy.  Seems unecessary, but I'm unsure about the
-	 * interaction with doUpdateInventory() called below.
-	 */
-	LL_DEBUGS() << "LLViewerObject::saveScript() " << item->getUUID() << " " << item->getAssetUUID() << LL_ENDL;
-
-	LLPointer<LLViewerInventoryItem> task_item =
-		new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
-								  item->getAssetUUID(), item->getType(),
-								  item->getInventoryType(),
-								  item->getName(), item->getDescription(),
-								  item->getSaleInfo(), item->getFlags(),
-								  item->getCreationDate());
-	task_item->setTransactionID(item->getTransactionID());
-
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_RezScript);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
-	msg->nextBlockFast(_PREHASH_UpdateBlock);
-	msg->addU32Fast(_PREHASH_ObjectLocalID, (mLocalID));
-	U8 enabled = active;
-	msg->addBOOLFast(_PREHASH_Enabled, enabled);
-	msg->nextBlockFast(_PREHASH_InventoryBlock);
-	task_item->packMessage(msg);
-	msg->sendReliable(mRegionp->getHost());
-
-	// do the internal logic
-	doUpdateInventory(task_item, TASK_INVENTORY_ITEM_KEY, is_new);
+    const LLViewerInventoryItem* item,
+    BOOL active,
+    bool is_new)
+{
+    /*
+     * XXXPAM Investigate not making this copy.  Seems unecessary, but I'm unsure about the
+     * interaction with doUpdateInventory() called below.
+     */
+    LL_DEBUGS() << "LLViewerObject::saveScript() " << item->getUUID() << " " << item->getAssetUUID() << LL_ENDL;
+
+    LLPointer<LLViewerInventoryItem> task_item =
+        new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
+                                  item->getAssetUUID(), item->getType(),
+                                  item->getInventoryType(),
+                                  item->getName(), item->getDescription(),
+                                  item->getSaleInfo(), item->getFlags(),
+                                  item->getCreationDate());
+    task_item->setTransactionID(item->getTransactionID());
+
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_RezScript);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addUUIDFast(_PREHASH_GroupID, gAgent.getGroupID());
+    msg->nextBlockFast(_PREHASH_UpdateBlock);
+    msg->addU32Fast(_PREHASH_ObjectLocalID, (mLocalID));
+    U8 enabled = active;
+    msg->addBOOLFast(_PREHASH_Enabled, enabled);
+    msg->nextBlockFast(_PREHASH_InventoryBlock);
+    task_item->packMessage(msg);
+    msg->sendReliable(mRegionp->getHost());
+
+    // do the internal logic
+    doUpdateInventory(task_item, TASK_INVENTORY_ITEM_KEY, is_new);
 }
 
 void LLViewerObject::moveInventory(const LLUUID& folder_id,
-								   const LLUUID& item_id)
-{
-	LL_DEBUGS() << "LLViewerObject::moveInventory " << item_id << LL_ENDL;
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_MoveTaskInventory);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addUUIDFast(_PREHASH_FolderID, folder_id);
-	msg->nextBlockFast(_PREHASH_InventoryData);
-	msg->addU32Fast(_PREHASH_LocalID, mLocalID);
-	msg->addUUIDFast(_PREHASH_ItemID, item_id);
-	msg->sendReliable(mRegionp->getHost());
-
-	LLInventoryObject* inv_obj = getInventoryObject(item_id);
-	if(inv_obj)
-	{
-		LLViewerInventoryItem* item = (LLViewerInventoryItem*)inv_obj;
-		if(!item->getPermissions().allowCopyBy(gAgent.getID()))
-		{
-			deleteInventoryItem(item_id);
-			++mExpectedInventorySerialNum;
-		}
-	}
+                                   const LLUUID& item_id)
+{
+    LL_DEBUGS() << "LLViewerObject::moveInventory " << item_id << LL_ENDL;
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_MoveTaskInventory);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addUUIDFast(_PREHASH_FolderID, folder_id);
+    msg->nextBlockFast(_PREHASH_InventoryData);
+    msg->addU32Fast(_PREHASH_LocalID, mLocalID);
+    msg->addUUIDFast(_PREHASH_ItemID, item_id);
+    msg->sendReliable(mRegionp->getHost());
+
+    LLInventoryObject* inv_obj = getInventoryObject(item_id);
+    if(inv_obj)
+    {
+        LLViewerInventoryItem* item = (LLViewerInventoryItem*)inv_obj;
+        if(!item->getPermissions().allowCopyBy(gAgent.getID()))
+        {
+            deleteInventoryItem(item_id);
+            ++mExpectedInventorySerialNum;
+        }
+    }
 }
 
 void LLViewerObject::dirtyInventory()
 {
-	// If there aren't any LLVOInventoryListeners, we won't be
-	// able to update our mInventory when it comes back from the
-	// simulator, so we should not clear the inventory either.
-	if(mInventory && !mInventoryCallbacks.empty())
-	{
-		mInventory->clear(); // will deref and delete entries
-		delete mInventory;
-		mInventory = NULL;
-	}
-	mInventoryDirty = TRUE;
+    // If there aren't any LLVOInventoryListeners, we won't be
+    // able to update our mInventory when it comes back from the
+    // simulator, so we should not clear the inventory either.
+    if(mInventory && !mInventoryCallbacks.empty())
+    {
+        mInventory->clear(); // will deref and delete entries
+        delete mInventory;
+        mInventory = NULL;
+    }
+    mInventoryDirty = TRUE;
 }
 
 void LLViewerObject::registerInventoryListener(LLVOInventoryListener* listener, void* user_data)
 {
-	LLInventoryCallbackInfo* info = new LLInventoryCallbackInfo;
-	info->mListener = listener;
-	info->mInventoryData = user_data;
-	mInventoryCallbacks.push_front(info);
+    LLInventoryCallbackInfo* info = new LLInventoryCallbackInfo;
+    info->mListener = listener;
+    info->mInventoryData = user_data;
+    mInventoryCallbacks.push_front(info);
 }
 
 void LLViewerObject::removeInventoryListener(LLVOInventoryListener* listener)
 {
-	if (listener == NULL)
-		return;
-	for (callback_list_t::iterator iter = mInventoryCallbacks.begin();
-		 iter != mInventoryCallbacks.end(); )
-	{
-		callback_list_t::iterator curiter = iter++;
-		LLInventoryCallbackInfo* info = *curiter;
-		if (info->mListener == listener)
-		{
-			delete info;
-			mInventoryCallbacks.erase(curiter);
-			break;
-		}
-	}
+    if (listener == NULL)
+        return;
+    for (callback_list_t::iterator iter = mInventoryCallbacks.begin();
+         iter != mInventoryCallbacks.end(); )
+    {
+        callback_list_t::iterator curiter = iter++;
+        LLInventoryCallbackInfo* info = *curiter;
+        if (info->mListener == listener)
+        {
+            delete info;
+            mInventoryCallbacks.erase(curiter);
+            break;
+        }
+    }
 }
 
 BOOL LLViewerObject::isInventoryPending()
@@ -3049,60 +3049,60 @@ BOOL LLViewerObject::isInventoryPending()
 
 void LLViewerObject::clearInventoryListeners()
 {
-	for_each(mInventoryCallbacks.begin(), mInventoryCallbacks.end(), DeletePointer());
-	mInventoryCallbacks.clear();
+    for_each(mInventoryCallbacks.begin(), mInventoryCallbacks.end(), DeletePointer());
+    mInventoryCallbacks.clear();
 }
 
 bool LLViewerObject::hasInventoryListeners()
 {
-	return !mInventoryCallbacks.empty();
+    return !mInventoryCallbacks.empty();
 }
 
 void LLViewerObject::requestInventory()
 {
-	if(mInventoryDirty && mInventory && !mInventoryCallbacks.empty())
-	{
-		mInventory->clear(); // will deref and delete entries
-		delete mInventory;
-		mInventory = NULL;
-	}
-
-	if(mInventory)
-	{
-		// inventory is either up to date or doesn't has a listener
-		// if it is dirty, leave it this way in case we gain a listener
-		doInventoryCallback();
-	}
-	else
-	{
-		// since we are going to request it now
-		mInventoryDirty = FALSE;
-
-		// Note: throws away duplicate requests
-		fetchInventoryFromServer();
-	}
+    if(mInventoryDirty && mInventory && !mInventoryCallbacks.empty())
+    {
+        mInventory->clear(); // will deref and delete entries
+        delete mInventory;
+        mInventory = NULL;
+    }
+
+    if(mInventory)
+    {
+        // inventory is either up to date or doesn't has a listener
+        // if it is dirty, leave it this way in case we gain a listener
+        doInventoryCallback();
+    }
+    else
+    {
+        // since we are going to request it now
+        mInventoryDirty = FALSE;
+
+        // Note: throws away duplicate requests
+        fetchInventoryFromServer();
+    }
 }
 
 void LLViewerObject::fetchInventoryFromServer()
 {
-	if (!isInventoryPending())
-	{
-		delete mInventory;
-		mInventory = NULL;
-
-		// Results in processTaskInv
-		LLMessageSystem* msg = gMessageSystem;
-		msg->newMessageFast(_PREHASH_RequestTaskInventory);
-		msg->nextBlockFast(_PREHASH_AgentData);
-		msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-		msg->nextBlockFast(_PREHASH_InventoryData);
-		msg->addU32Fast(_PREHASH_LocalID, mLocalID);
-		msg->sendReliable(mRegionp->getHost());
-
-		// This will get reset by doInventoryCallback or processTaskInv
-		mInvRequestState = INVENTORY_REQUEST_PENDING;
-	}
+    if (!isInventoryPending())
+    {
+        delete mInventory;
+        mInventory = NULL;
+
+        // Results in processTaskInv
+        LLMessageSystem* msg = gMessageSystem;
+        msg->newMessageFast(_PREHASH_RequestTaskInventory);
+        msg->nextBlockFast(_PREHASH_AgentData);
+        msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+        msg->nextBlockFast(_PREHASH_InventoryData);
+        msg->addU32Fast(_PREHASH_LocalID, mLocalID);
+        msg->sendReliable(mRegionp->getHost());
+
+        // This will get reset by doInventoryCallback or processTaskInv
+        mInvRequestState = INVENTORY_REQUEST_PENDING;
+    }
 }
 
 void LLViewerObject::fetchInventoryDelayed(const F64 &time_seconds)
@@ -3175,32 +3175,32 @@ void LLViewerObject::updateControlAvatar()
     if (is_animated_object)
     {
         bool any_rigged_mesh = root->isRiggedMesh();
-		if (!any_rigged_mesh)
-		{
-			LLViewerObject::const_child_list_t& child_list = root->getChildren();
-			for (const LLViewerObject* child : child_list)
-			{
-				any_rigged_mesh = child->isRiggedMesh();
-				if (any_rigged_mesh)
-					break;
-			}
-		}
+        if (!any_rigged_mesh)
+        {
+            LLViewerObject::const_child_list_t& child_list = root->getChildren();
+            for (const LLViewerObject* child : child_list)
+            {
+                any_rigged_mesh = child->isRiggedMesh();
+                if (any_rigged_mesh)
+                    break;
+            }
+        }
         should_have_control_avatar = is_animated_object && any_rigged_mesh;
     }
 
     if (should_have_control_avatar && !has_control_avatar)
     {
 #ifdef SHOW_DEBUG
-		std::string vobj_name = llformat("Vol%p", root);
-		LL_DEBUGS("AnimatedObjects") << vobj_name << " calling linkControlAvatar()" << LL_ENDL;
+        std::string vobj_name = llformat("Vol%p", root);
+        LL_DEBUGS("AnimatedObjects") << vobj_name << " calling linkControlAvatar()" << LL_ENDL;
 #endif
         root->linkControlAvatar();
     }
     if (!should_have_control_avatar && has_control_avatar)
     {
 #ifdef SHOW_DEBUG
-		std::string vobj_name = llformat("Vol%p", root);
-		LL_DEBUGS("AnimatedObjects") << vobj_name << " calling unlinkControlAvatar()" << LL_ENDL;
+        std::string vobj_name = llformat("Vol%p", root);
+        LL_DEBUGS("AnimatedObjects") << vobj_name << " calling unlinkControlAvatar()" << LL_ENDL;
 #endif
         root->unlinkControlAvatar();
     }
@@ -3226,8 +3226,8 @@ void LLViewerObject::linkControlAvatar()
         }
         mControlAvatar = LLControlAvatar::createControlAvatar(volp);
 #ifdef SHOW_DEBUG
-        LL_DEBUGS("AnimatedObjects") << volp->getID() 
-                                     << " created control av for " 
+        LL_DEBUGS("AnimatedObjects") << volp->getID()
+                                     << " created control av for "
                                      << (S32) (1+volp->numChildren()) << " prims" << LL_ENDL;
 #endif
     }
@@ -3278,26 +3278,26 @@ bool LLViewerObject::isAnimatedObject() const
 
 struct LLFilenameAndTask
 {
-	LLUUID mTaskID;
-	std::string mFilename;
+    LLUUID mTaskID;
+    std::string mFilename;
 
-	// for sequencing in case of multiple updates
-	S16 mSerial;
+    // for sequencing in case of multiple updates
+    S16 mSerial;
 #ifdef _DEBUG
-	static S32 sCount;
-	LLFilenameAndTask()
-	{
-		++sCount;
-		LL_DEBUGS() << "Constructing LLFilenameAndTask: " << sCount << LL_ENDL;
-	}
-	~LLFilenameAndTask()
-	{
-		--sCount;
-		LL_DEBUGS() << "Destroying LLFilenameAndTask: " << sCount << LL_ENDL;
-	}
+    static S32 sCount;
+    LLFilenameAndTask()
+    {
+        ++sCount;
+        LL_DEBUGS() << "Constructing LLFilenameAndTask: " << sCount << LL_ENDL;
+    }
+    ~LLFilenameAndTask()
+    {
+        --sCount;
+        LL_DEBUGS() << "Destroying LLFilenameAndTask: " << sCount << LL_ENDL;
+    }
 private:
-	LLFilenameAndTask(const LLFilenameAndTask& rhs);
-	const LLFilenameAndTask& operator=(const LLFilenameAndTask& rhs) const;
+    LLFilenameAndTask(const LLFilenameAndTask& rhs);
+    const LLFilenameAndTask& operator=(const LLFilenameAndTask& rhs) const;
 #endif
 };
 
@@ -3350,7 +3350,7 @@ void LLViewerObject::processTaskInv(LLMessageSystem* msg, void** user_data)
         LLFilenameAndTask* ft = new LLFilenameAndTask;
         ft->mTaskID = task_id;
         ft->mSerial = serial;
-        
+
         // We received version we expected or newer. Load it.
         object->mInventorySerialNum = ft->mSerial;
         object->mExpectedInventorySerialNum = ft->mSerial;
@@ -3406,154 +3406,154 @@ void LLViewerObject::processTaskInv(LLMessageSystem* msg, void** user_data)
 
 void LLViewerObject::processTaskInvFile(void** user_data, S32 error_code, LLExtStat ext_status)
 {
-	LLFilenameAndTask* ft = (LLFilenameAndTask*)user_data;
-	LLViewerObject* object = NULL;
-
-	if (ft
-		&& (0 == error_code)
-		&& (object = gObjectList.findObject(ft->mTaskID))
-		&& ft->mSerial >= object->mInventorySerialNum)
-	{
-		object->mInventorySerialNum = ft->mSerial;
-		LL_DEBUGS() << "Receiving inventory task file for serial " << object->mInventorySerialNum << " taskid: " << ft->mTaskID << LL_ENDL;
-		if (ft->mSerial < object->mExpectedInventorySerialNum)
-		{
-			// User managed to change something while inventory was loading
-			LL_DEBUGS() << "Processing file that is potentially out of date for task: " << ft->mTaskID << LL_ENDL;
-		}
-
-		if (object->loadTaskInvFile(ft->mFilename))
-		{
-
-			LLInventoryObject::object_list_t::iterator it = object->mInventory->begin();
-			LLInventoryObject::object_list_t::iterator end = object->mInventory->end();
-			auto& pending_lst = object->mPendingInventoryItemsIDs;
-
-			for (; it != end && pending_lst.size(); ++it)
-			{
-				LLViewerInventoryItem* item = dynamic_cast<LLViewerInventoryItem*>(it->get());
-				if(item && item->getType() != LLAssetType::AT_CATEGORY)
-				{
-					auto id_it = pending_lst.find(item->getAssetUUID());
-					if (id_it != pending_lst.end())
-					{
-						pending_lst.erase(id_it);
-					}
-				}
-			}
-		}
-		else
-		{
-			// MAINT-2597 - crash when trying to edit a no-mod object
-			// Somehow get an contents inventory response, but with an invalid stream (possibly 0 size?)
-			// Stated repro was specific to no-mod objects so failing without user interaction should be safe.
-			LL_WARNS() << "Trying to load invalid task inventory file. Ignoring file contents." << LL_ENDL;
-		}
-	}
-	else
-	{
-		// This Occurs When two requests were made, and the first one
-		// has already handled it.
-		LL_DEBUGS() << "Problem loading task inventory. Return code: "
-				 << error_code << LL_ENDL;
-	}
-	delete ft;
+    LLFilenameAndTask* ft = (LLFilenameAndTask*)user_data;
+    LLViewerObject* object = NULL;
+
+    if (ft
+        && (0 == error_code)
+        && (object = gObjectList.findObject(ft->mTaskID))
+        && ft->mSerial >= object->mInventorySerialNum)
+    {
+        object->mInventorySerialNum = ft->mSerial;
+        LL_DEBUGS() << "Receiving inventory task file for serial " << object->mInventorySerialNum << " taskid: " << ft->mTaskID << LL_ENDL;
+        if (ft->mSerial < object->mExpectedInventorySerialNum)
+        {
+            // User managed to change something while inventory was loading
+            LL_DEBUGS() << "Processing file that is potentially out of date for task: " << ft->mTaskID << LL_ENDL;
+        }
+
+        if (object->loadTaskInvFile(ft->mFilename))
+        {
+
+            LLInventoryObject::object_list_t::iterator it = object->mInventory->begin();
+            LLInventoryObject::object_list_t::iterator end = object->mInventory->end();
+            auto& pending_lst = object->mPendingInventoryItemsIDs;
+
+            for (; it != end && pending_lst.size(); ++it)
+            {
+                LLViewerInventoryItem* item = dynamic_cast<LLViewerInventoryItem*>(it->get());
+                if(item && item->getType() != LLAssetType::AT_CATEGORY)
+                {
+                    auto id_it = pending_lst.find(item->getAssetUUID());
+                    if (id_it != pending_lst.end())
+                    {
+                        pending_lst.erase(id_it);
+                    }
+                }
+            }
+        }
+        else
+        {
+            // MAINT-2597 - crash when trying to edit a no-mod object
+            // Somehow get an contents inventory response, but with an invalid stream (possibly 0 size?)
+            // Stated repro was specific to no-mod objects so failing without user interaction should be safe.
+            LL_WARNS() << "Trying to load invalid task inventory file. Ignoring file contents." << LL_ENDL;
+        }
+    }
+    else
+    {
+        // This Occurs When two requests were made, and the first one
+        // has already handled it.
+        LL_DEBUGS() << "Problem loading task inventory. Return code: "
+                 << error_code << LL_ENDL;
+    }
+    delete ft;
 }
 
 BOOL LLViewerObject::loadTaskInvFile(const std::string& filename)
 {
-	std::string filename_and_local_path = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, filename);
-	llifstream ifs(filename_and_local_path.c_str());
-	if(ifs.good())
-	{
-		U32 fail_count = 0;
-		char buffer[MAX_STRING];	/* Flawfinder: ignore */
-		// *NOTE: This buffer size is hard coded into scanf() below.
-		char keyword[MAX_STRING];	/* Flawfinder: ignore */
-		if(mInventory)
-		{
-			mInventory->clear(); // will deref and delete it
-		}
-		else
-		{
-			mInventory = new LLInventoryObject::object_list_t;
-		}
-		while(ifs.good())
-		{
-			ifs.getline(buffer, MAX_STRING);
-			if (sscanf(buffer, " %254s", keyword) == EOF) /* Flawfinder: ignore */
-			{
-				// Blank file?
-				LL_WARNS() << "Issue reading from file '"
-						<< filename << "'" << LL_ENDL;
-				break;
-			}
-			else if(0 == strcmp("inv_item", keyword))
-			{
-				LLPointer<LLInventoryObject> inv = new LLViewerInventoryItem;
-				inv->importLegacyStream(ifs);
-				mInventory->push_front(inv);
-			}
-			else if(0 == strcmp("inv_object", keyword))
-			{
-				LLPointer<LLInventoryObject> inv = new LLInventoryObject;
-				inv->importLegacyStream(ifs);
-				inv->rename("Contents");
-				mInventory->push_front(inv);
-			}
-			else if (fail_count >= MAX_INV_FILE_READ_FAILS)
-			{
-				LL_WARNS() << "Encountered too many unknowns while reading from file: '"
-						<< filename << "'" << LL_ENDL;
-				break;
-			}
-			else
-			{
-				// Is there really a point to continue processing? We already failing to display full inventory
-				fail_count++;
-				LL_WARNS_ONCE() << "Unknown token while reading from inventory file. Token: '"
-						<< keyword << "'" << LL_ENDL;
-			}
-		}
-		ifs.close();
-		LLFile::remove(filename_and_local_path);
-	}
-	else
-	{
-		LL_WARNS() << "unable to load task inventory: " << filename_and_local_path
-				<< LL_ENDL;
-		return FALSE;
-	}
-	doInventoryCallback();
-
-	return TRUE;
+    std::string filename_and_local_path = gDirUtilp->getExpandedFilename(LL_PATH_CACHE, filename);
+    llifstream ifs(filename_and_local_path.c_str());
+    if(ifs.good())
+    {
+        U32 fail_count = 0;
+        char buffer[MAX_STRING];    /* Flawfinder: ignore */
+        // *NOTE: This buffer size is hard coded into scanf() below.
+        char keyword[MAX_STRING];   /* Flawfinder: ignore */
+        if(mInventory)
+        {
+            mInventory->clear(); // will deref and delete it
+        }
+        else
+        {
+            mInventory = new LLInventoryObject::object_list_t;
+        }
+        while(ifs.good())
+        {
+            ifs.getline(buffer, MAX_STRING);
+            if (sscanf(buffer, " %254s", keyword) == EOF) /* Flawfinder: ignore */
+            {
+                // Blank file?
+                LL_WARNS() << "Issue reading from file '"
+                        << filename << "'" << LL_ENDL;
+                break;
+            }
+            else if(0 == strcmp("inv_item", keyword))
+            {
+                LLPointer<LLInventoryObject> inv = new LLViewerInventoryItem;
+                inv->importLegacyStream(ifs);
+                mInventory->push_front(inv);
+            }
+            else if(0 == strcmp("inv_object", keyword))
+            {
+                LLPointer<LLInventoryObject> inv = new LLInventoryObject;
+                inv->importLegacyStream(ifs);
+                inv->rename("Contents");
+                mInventory->push_front(inv);
+            }
+            else if (fail_count >= MAX_INV_FILE_READ_FAILS)
+            {
+                LL_WARNS() << "Encountered too many unknowns while reading from file: '"
+                        << filename << "'" << LL_ENDL;
+                break;
+            }
+            else
+            {
+                // Is there really a point to continue processing? We already failing to display full inventory
+                fail_count++;
+                LL_WARNS_ONCE() << "Unknown token while reading from inventory file. Token: '"
+                        << keyword << "'" << LL_ENDL;
+            }
+        }
+        ifs.close();
+        LLFile::remove(filename_and_local_path);
+    }
+    else
+    {
+        LL_WARNS() << "unable to load task inventory: " << filename_and_local_path
+                << LL_ENDL;
+        return FALSE;
+    }
+    doInventoryCallback();
+
+    return TRUE;
 }
 
-void LLViewerObject::doInventoryCallback()
-{
-	for (callback_list_t::iterator iter = mInventoryCallbacks.begin();
-		 iter != mInventoryCallbacks.end(); )
-	{
-		callback_list_t::iterator curiter = iter++;
-		LLInventoryCallbackInfo* info = *curiter;
-		if (info->mListener != NULL)
-		{
-			info->mListener->inventoryChanged(this,
-								 mInventory,
-								 mInventorySerialNum,
-								 info->mInventoryData);
-		}
-		else
-		{
-			LL_INFOS() << "LLViewerObject::doInventoryCallback() deleting bad listener entry." << LL_ENDL;
-			delete info;
-			mInventoryCallbacks.erase(curiter);
-		}
-	}
-
-	// release inventory loading state
-	mInvRequestXFerId = 0;
-	mInvRequestState = INVENTORY_REQUEST_STOPPED;
+void LLViewerObject::doInventoryCallback()
+{
+    for (callback_list_t::iterator iter = mInventoryCallbacks.begin();
+         iter != mInventoryCallbacks.end(); )
+    {
+        callback_list_t::iterator curiter = iter++;
+        LLInventoryCallbackInfo* info = *curiter;
+        if (info->mListener != NULL)
+        {
+            info->mListener->inventoryChanged(this,
+                                 mInventory,
+                                 mInventorySerialNum,
+                                 info->mInventoryData);
+        }
+        else
+        {
+            LL_INFOS() << "LLViewerObject::doInventoryCallback() deleting bad listener entry." << LL_ENDL;
+            delete info;
+            mInventoryCallbacks.erase(curiter);
+        }
+    }
+
+    // release inventory loading state
+    mInvRequestXFerId = 0;
+    mInvRequestState = INVENTORY_REQUEST_STOPPED;
 }
 
 void LLViewerObject::removeInventory(const LLUUID& item_id)
@@ -3564,17 +3564,17 @@ void LLViewerObject::removeInventory(const LLUUID& item_id)
     params["object"] = mID;
     LLFloaterReg::hideInstance("item_properties", params);
 
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_RemoveTaskInventory);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_InventoryData);
-	msg->addU32Fast(_PREHASH_LocalID, mLocalID);
-	msg->addUUIDFast(_PREHASH_ItemID, item_id);
-	msg->sendReliable(mRegionp->getHost());
-	deleteInventoryItem(item_id);
-	++mExpectedInventorySerialNum;
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_RemoveTaskInventory);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_InventoryData);
+    msg->addU32Fast(_PREHASH_LocalID, mLocalID);
+    msg->addUUIDFast(_PREHASH_ItemID, item_id);
+    msg->sendReliable(mRegionp->getHost());
+    deleteInventoryItem(item_id);
+    ++mExpectedInventorySerialNum;
 }
 
 bool LLViewerObject::isAssetInInventory(LLViewerInventoryItem* item, LLAssetType::EType type)
@@ -3587,7 +3587,7 @@ bool LLViewerObject::isAssetInInventory(LLViewerInventoryItem* item, LLAssetType
         // but if it gets to store more types, it will need to verify type as well
         // since null can be a shared default id and it is fine to need a null
         // script and a null material simultaneously.
-		bool is_fetching = mPendingInventoryItemsIDs.contains(item->getAssetUUID());
+        bool is_fetching = mPendingInventoryItemsIDs.contains(item->getAssetUUID());
 
         // null is the default asset for materials and default for scripts
         // so need to check type as well
@@ -3623,136 +3623,136 @@ void LLViewerObject::updateMaterialInventory(LLViewerInventoryItem* item, U8 key
 }
 
 void LLViewerObject::updateInventory(
-	LLViewerInventoryItem* item,
-	U8 key,
-	bool is_new)
-{
-	// This slices the object into what we're concerned about on the
-	// viewer. The simulator will take the permissions and transfer
-	// ownership.
-	LLPointer<LLViewerInventoryItem> task_item =
-		new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
-								  item->getAssetUUID(), item->getType(),
-								  item->getInventoryType(),
-								  item->getName(), item->getDescription(),
-								  item->getSaleInfo(),
-								  item->getFlags(),
-								  item->getCreationDate());
-	task_item->setTransactionID(item->getTransactionID());
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_UpdateTaskInventory);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_UpdateData);
-	msg->addU32Fast(_PREHASH_LocalID, mLocalID);
-	msg->addU8Fast(_PREHASH_Key, key);
-	msg->nextBlockFast(_PREHASH_InventoryData);
-	task_item->packMessage(msg);
-	msg->sendReliable(mRegionp->getHost());
-
-	// do the internal logic
-	doUpdateInventory(task_item, key, is_new);
+    LLViewerInventoryItem* item,
+    U8 key,
+    bool is_new)
+{
+    // This slices the object into what we're concerned about on the
+    // viewer. The simulator will take the permissions and transfer
+    // ownership.
+    LLPointer<LLViewerInventoryItem> task_item =
+        new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
+                                  item->getAssetUUID(), item->getType(),
+                                  item->getInventoryType(),
+                                  item->getName(), item->getDescription(),
+                                  item->getSaleInfo(),
+                                  item->getFlags(),
+                                  item->getCreationDate());
+    task_item->setTransactionID(item->getTransactionID());
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_UpdateTaskInventory);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_UpdateData);
+    msg->addU32Fast(_PREHASH_LocalID, mLocalID);
+    msg->addU8Fast(_PREHASH_Key, key);
+    msg->nextBlockFast(_PREHASH_InventoryData);
+    task_item->packMessage(msg);
+    msg->sendReliable(mRegionp->getHost());
+
+    // do the internal logic
+    doUpdateInventory(task_item, key, is_new);
 }
 
 void LLViewerObject::updateInventoryLocal(LLInventoryItem* item, U8 key)
 {
-	LLPointer<LLViewerInventoryItem> task_item =
-		new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
-								  item->getAssetUUID(), item->getType(),
-								  item->getInventoryType(),
-								  item->getName(), item->getDescription(),
-								  item->getSaleInfo(), item->getFlags(),
-								  item->getCreationDate());
+    LLPointer<LLViewerInventoryItem> task_item =
+        new LLViewerInventoryItem(item->getUUID(), mID, item->getPermissions(),
+                                  item->getAssetUUID(), item->getType(),
+                                  item->getInventoryType(),
+                                  item->getName(), item->getDescription(),
+                                  item->getSaleInfo(), item->getFlags(),
+                                  item->getCreationDate());
 
-	// do the internal logic
-	const bool is_new = false;
-	doUpdateInventory(task_item, key, is_new);
+    // do the internal logic
+    const bool is_new = false;
+    doUpdateInventory(task_item, key, is_new);
 }
 
 LLInventoryObject* LLViewerObject::getInventoryObject(const LLUUID& item_id)
 {
-	LLInventoryObject* rv = NULL;
-	if(mInventory)
-	{
-		LLInventoryObject::object_list_t::iterator it = mInventory->begin();
-		LLInventoryObject::object_list_t::iterator end = mInventory->end();
-		for ( ; it != end; ++it)
-		{
-			if((*it)->getUUID() == item_id)
-			{
-				rv = *it;
-				break;
-			}
-		}		
-	}
-	return rv;
+    LLInventoryObject* rv = NULL;
+    if(mInventory)
+    {
+        LLInventoryObject::object_list_t::iterator it = mInventory->begin();
+        LLInventoryObject::object_list_t::iterator end = mInventory->end();
+        for ( ; it != end; ++it)
+        {
+            if((*it)->getUUID() == item_id)
+            {
+                rv = *it;
+                break;
+            }
+        }
+    }
+    return rv;
 }
 
 LLInventoryItem* LLViewerObject::getInventoryItem(const LLUUID& item_id)
 {
-	LLInventoryObject* iobj = getInventoryObject(item_id);
-	if (!iobj || iobj->getType() == LLAssetType::AT_CATEGORY)
-	{
-		return NULL;
-	}
-	LLInventoryItem* item = dynamic_cast<LLInventoryItem*>(iobj);
-	return item;
+    LLInventoryObject* iobj = getInventoryObject(item_id);
+    if (!iobj || iobj->getType() == LLAssetType::AT_CATEGORY)
+    {
+        return NULL;
+    }
+    LLInventoryItem* item = dynamic_cast<LLInventoryItem*>(iobj);
+    return item;
 }
 
 void LLViewerObject::getInventoryContents(LLInventoryObject::object_list_t& objects)
 {
-	if(mInventory)
-	{
-		LLInventoryObject::object_list_t::iterator it = mInventory->begin();
-		LLInventoryObject::object_list_t::iterator end = mInventory->end();
-		for( ; it != end; ++it)
-		{
-			if ((*it)->getType() != LLAssetType::AT_CATEGORY)
-			{
-				objects.push_back(*it);
-			}
-		}
-	}
+    if(mInventory)
+    {
+        LLInventoryObject::object_list_t::iterator it = mInventory->begin();
+        LLInventoryObject::object_list_t::iterator end = mInventory->end();
+        for( ; it != end; ++it)
+        {
+            if ((*it)->getType() != LLAssetType::AT_CATEGORY)
+            {
+                objects.push_back(*it);
+            }
+        }
+    }
 }
 
 LLInventoryObject* LLViewerObject::getInventoryRoot()
 {
-	if (!mInventory || !mInventory->size())
-	{
-		return NULL;
-	}
-	return mInventory->back();
+    if (!mInventory || !mInventory->size())
+    {
+        return NULL;
+    }
+    return mInventory->back();
 }
 
 LLViewerInventoryItem* LLViewerObject::getInventoryItemByAsset(const LLUUID& asset_id)
 {
-	if (mInventoryDirty)
-		LL_WARNS() << "Peforming inventory lookup for object " << mID << " that has dirty inventory!" << LL_ENDL;
-
-	LLViewerInventoryItem* rv = NULL;
-	if(mInventory)
-	{
-		LLViewerInventoryItem* item = NULL;
-
-		LLInventoryObject::object_list_t::iterator it = mInventory->begin();
-		LLInventoryObject::object_list_t::iterator end = mInventory->end();
-		for( ; it != end; ++it)
-		{
-			LLInventoryObject* obj = *it;
-			if(obj->getType() != LLAssetType::AT_CATEGORY)
-			{
-				// *FIX: gank-ass down cast!
-				item = (LLViewerInventoryItem*)obj;
-				if(item->getAssetUUID() == asset_id)
-				{
-					rv = item;
-					break;
-				}
-			}
-		}		
-	}
-	return rv;
+    if (mInventoryDirty)
+        LL_WARNS() << "Peforming inventory lookup for object " << mID << " that has dirty inventory!" << LL_ENDL;
+
+    LLViewerInventoryItem* rv = NULL;
+    if(mInventory)
+    {
+        LLViewerInventoryItem* item = NULL;
+
+        LLInventoryObject::object_list_t::iterator it = mInventory->begin();
+        LLInventoryObject::object_list_t::iterator end = mInventory->end();
+        for( ; it != end; ++it)
+        {
+            LLInventoryObject* obj = *it;
+            if(obj->getType() != LLAssetType::AT_CATEGORY)
+            {
+                // *FIX: gank-ass down cast!
+                item = (LLViewerInventoryItem*)obj;
+                if(item->getAssetUUID() == asset_id)
+                {
+                    rv = item;
+                    break;
+                }
+            }
+        }
+    }
+    return rv;
 }
 
 LLViewerInventoryItem* LLViewerObject::getInventoryItemByAsset(const LLUUID& asset_id, LLAssetType::EType type)
@@ -3794,70 +3794,70 @@ LLViewerInventoryItem* LLViewerObject::getInventoryItemByAsset(const LLUUID& ass
 }
 
 void LLViewerObject::updateViewerInventoryAsset(
-					const LLViewerInventoryItem* item,
-					const LLUUID& new_asset)
+                    const LLViewerInventoryItem* item,
+                    const LLUUID& new_asset)
 {
-	LLPointer<LLViewerInventoryItem> task_item =
-		new LLViewerInventoryItem(item);
-	task_item->setAssetUUID(new_asset);
+    LLPointer<LLViewerInventoryItem> task_item =
+        new LLViewerInventoryItem(item);
+    task_item->setAssetUUID(new_asset);
 
-	// do the internal logic
-	doUpdateInventory(task_item, TASK_INVENTORY_ITEM_KEY, false);
+    // do the internal logic
+    doUpdateInventory(task_item, TASK_INVENTORY_ITEM_KEY, false);
 }
 
 void LLViewerObject::setPixelAreaAndAngle(LLAgent &agent)
 {
-	if (getVolume())
-	{	//volumes calculate pixel area and angle per face
-		return;
-	}
-	
-	LLVector3 viewer_pos_agent = gAgentCamera.getCameraPositionAgent();
-	LLVector3 pos_agent = getRenderPosition();
-
-	F32 dx = viewer_pos_agent.mV[VX] - pos_agent.mV[VX];
-	F32 dy = viewer_pos_agent.mV[VY] - pos_agent.mV[VY];
-	F32 dz = viewer_pos_agent.mV[VZ] - pos_agent.mV[VZ];
-
-	F32 max_scale = getMaxScale();
-	F32 mid_scale = getMidScale();
-	F32 min_scale = getMinScale();
-
-	// IW: estimate - when close to large objects, computing range based on distance from center is no good
-	// to try to get a min distance from face, subtract min_scale/2 from the range.
-	// This means we'll load too much detail sometimes, but that's better than not enough
-	// I don't think there's a better way to do this without calculating distance per-poly
-	F32 range = sqrt(dx*dx + dy*dy + dz*dz) - min_scale/2;
-
-	LLViewerCamera* camera = LLViewerCamera::getInstance();
-	if (range < 0.001f || isHUDAttachment())		// range == zero
-	{
-		mAppAngle = 180.f;
-		mPixelArea = (F32)camera->getScreenPixelArea();
-	}
-	else
-	{
-		mAppAngle = (F32) atan2( max_scale, range) * RAD_TO_DEG;
-
-		F32 pixels_per_meter = camera->getPixelMeterRatio() / range;
-
-		mPixelArea = (pixels_per_meter * max_scale) * (pixels_per_meter * mid_scale);
-		if (mPixelArea > camera->getScreenPixelArea())
-		{
-			mAppAngle = 180.f;
-			mPixelArea = (F32)camera->getScreenPixelArea();
-		}
-	}
+    if (getVolume())
+    {   //volumes calculate pixel area and angle per face
+        return;
+    }
+
+    LLVector3 viewer_pos_agent = gAgentCamera.getCameraPositionAgent();
+    LLVector3 pos_agent = getRenderPosition();
+
+    F32 dx = viewer_pos_agent.mV[VX] - pos_agent.mV[VX];
+    F32 dy = viewer_pos_agent.mV[VY] - pos_agent.mV[VY];
+    F32 dz = viewer_pos_agent.mV[VZ] - pos_agent.mV[VZ];
+
+    F32 max_scale = getMaxScale();
+    F32 mid_scale = getMidScale();
+    F32 min_scale = getMinScale();
+
+    // IW: estimate - when close to large objects, computing range based on distance from center is no good
+    // to try to get a min distance from face, subtract min_scale/2 from the range.
+    // This means we'll load too much detail sometimes, but that's better than not enough
+    // I don't think there's a better way to do this without calculating distance per-poly
+    F32 range = sqrt(dx*dx + dy*dy + dz*dz) - min_scale/2;
+
+    LLViewerCamera* camera = LLViewerCamera::getInstance();
+    if (range < 0.001f || isHUDAttachment())        // range == zero
+    {
+        mAppAngle = 180.f;
+        mPixelArea = (F32)camera->getScreenPixelArea();
+    }
+    else
+    {
+        mAppAngle = (F32) atan2( max_scale, range) * RAD_TO_DEG;
+
+        F32 pixels_per_meter = camera->getPixelMeterRatio() / range;
+
+        mPixelArea = (pixels_per_meter * max_scale) * (pixels_per_meter * mid_scale);
+        if (mPixelArea > camera->getScreenPixelArea())
+        {
+            mAppAngle = 180.f;
+            mPixelArea = (F32)camera->getScreenPixelArea();
+        }
+    }
 }
 
 BOOL LLViewerObject::updateLOD()
 {
-	return FALSE;
+    return FALSE;
 }
 
 BOOL LLViewerObject::updateGeometry(LLDrawable *drawable)
 {
-	return TRUE;
+    return TRUE;
 }
 
 void LLViewerObject::updateGL()
@@ -3867,51 +3867,51 @@ void LLViewerObject::updateGL()
 
 void LLViewerObject::updateFaceSize(S32 idx)
 {
-	
+
 }
 
 LLDrawable* LLViewerObject::createDrawable(LLPipeline *pipeline)
 {
-	return NULL;
+    return NULL;
 }
 
 void LLViewerObject::setScale(const LLVector3 &scale, BOOL damped)
 {
-	LLPrimitive::setScale(scale);
-	if (mDrawable.notNull())
-	{
-		//encompass completely sheared objects by taking 
-		//the most extreme point possible (<1,1,0.5>)
-		mDrawable->setRadius(LLVector3(1,1,0.5f).scaleVec(scale).magVec());
-		updateDrawable(damped);
-	}
-
-	if( (LL_PCODE_VOLUME == getPCode()) && !isDead() )
-	{
-		if (permYouOwner() || (scale.magVecSquared() > (7.5f * 7.5f)) )
-		{
-			if (!mOnMap)
-			{
-				llassert_always(LLWorld::getInstance()->getRegionFromHandle(getRegion()->getHandle()));
-
-				gObjectList.addToMap(this);
-				mOnMap = TRUE;
-			}
-		}
-		else
-		{
-			if (mOnMap)
-			{
-				gObjectList.removeFromMap(this);
-				mOnMap = FALSE;
-			}
-		}
-	}
+    LLPrimitive::setScale(scale);
+    if (mDrawable.notNull())
+    {
+        //encompass completely sheared objects by taking
+        //the most extreme point possible (<1,1,0.5>)
+        mDrawable->setRadius(LLVector3(1,1,0.5f).scaleVec(scale).magVec());
+        updateDrawable(damped);
+    }
+
+    if( (LL_PCODE_VOLUME == getPCode()) && !isDead() )
+    {
+        if (permYouOwner() || (scale.magVecSquared() > (7.5f * 7.5f)) )
+        {
+            if (!mOnMap)
+            {
+                llassert_always(LLWorld::getInstance()->getRegionFromHandle(getRegion()->getHandle()));
+
+                gObjectList.addToMap(this);
+                mOnMap = TRUE;
+            }
+        }
+        else
+        {
+            if (mOnMap)
+            {
+                gObjectList.removeFromMap(this);
+                mOnMap = FALSE;
+            }
+        }
+    }
 }
 
 void LLViewerObject::setObjectCostStale()
 {
-	mCostStale = true;
+    mCostStale = true;
     // *NOTE: This is harmlessly redundant for Blinn-Phong material updates, as
     // the root prim currently gets set stale anyway due to other property
     // updates. But it is needed for GLTF material ID updates.
@@ -3921,103 +3921,103 @@ void LLViewerObject::setObjectCostStale()
 
 void LLViewerObject::setObjectCost(F32 cost)
 {
-	mObjectCost = cost;
-	mCostStale = false;
+    mObjectCost = cost;
+    mCostStale = false;
 
-	if (isSelected())
-	{
-		gFloaterTools->dirty();
-	}
+    if (isSelected())
+    {
+        gFloaterTools->dirty();
+    }
 }
 
 void LLViewerObject::setLinksetCost(F32 cost)
 {
-	mLinksetCost = cost;
-	mCostStale = false;
+    mLinksetCost = cost;
+    mCostStale = false;
 
-	BOOL needs_refresh = isSelected();
-	child_list_t::iterator iter = mChildList.begin();
-	while(iter != mChildList.end() && !needs_refresh)
-	{
-		LLViewerObject* child = *iter;
-		needs_refresh = child->isSelected();
-		iter++;
-	}
+    BOOL needs_refresh = isSelected();
+    child_list_t::iterator iter = mChildList.begin();
+    while(iter != mChildList.end() && !needs_refresh)
+    {
+        LLViewerObject* child = *iter;
+        needs_refresh = child->isSelected();
+        iter++;
+    }
 
-	if (needs_refresh)
-	{
-		gFloaterTools->dirty();
-	}
+    if (needs_refresh)
+    {
+        gFloaterTools->dirty();
+    }
 }
 
 void LLViewerObject::setPhysicsCost(F32 cost)
 {
-	mPhysicsCost = cost;
-	mCostStale = false;
+    mPhysicsCost = cost;
+    mCostStale = false;
 
-	if (isSelected())
-	{
-		gFloaterTools->dirty();
-	}
+    if (isSelected())
+    {
+        gFloaterTools->dirty();
+    }
 }
 
 void LLViewerObject::setLinksetPhysicsCost(F32 cost)
 {
-	mLinksetPhysicsCost = cost;
-	mCostStale = false;
-	
-	if (isSelected())
-	{
-		gFloaterTools->dirty();
-	}
+    mLinksetPhysicsCost = cost;
+    mCostStale = false;
+
+    if (isSelected())
+    {
+        gFloaterTools->dirty();
+    }
 }
 
 
 F32 LLViewerObject::getObjectCost()
 {
-	if (mCostStale)
-	{
-		gObjectList.updateObjectCost(this);
-	}
-	
-	return mObjectCost;
+    if (mCostStale)
+    {
+        gObjectList.updateObjectCost(this);
+    }
+
+    return mObjectCost;
 }
 
 F32 LLViewerObject::getLinksetCost()
 {
-	if (mCostStale)
-	{
-		gObjectList.updateObjectCost(this);
-	}
+    if (mCostStale)
+    {
+        gObjectList.updateObjectCost(this);
+    }
 
-	return mLinksetCost;
+    return mLinksetCost;
 }
 
 F32 LLViewerObject::getPhysicsCost()
 {
-	if (mCostStale)
-	{
-		gObjectList.updateObjectCost(this);
-	}
-	
-	return mPhysicsCost;
+    if (mCostStale)
+    {
+        gObjectList.updateObjectCost(this);
+    }
+
+    return mPhysicsCost;
 }
 
 F32 LLViewerObject::getLinksetPhysicsCost()
 {
-	if (mCostStale)
-	{
-		gObjectList.updateObjectCost(this);
-	}
+    if (mCostStale)
+    {
+        gObjectList.updateObjectCost(this);
+    }
 
-	return mLinksetPhysicsCost;
+    return mLinksetPhysicsCost;
 }
 
 F32 LLViewerObject::recursiveGetEstTrianglesMax() const
 {
     F32 est_tris = getEstTrianglesMax();
-	for (const LLViewerObject* child : mChildList)
-	{
+    for (const LLViewerObject* child : mChildList)
+    {
         if (!child->isAvatar())
         {
             est_tris += child->recursiveGetEstTrianglesMax();
@@ -4054,7 +4054,7 @@ F32 LLViewerObject::getEstTrianglesStreamingCost() const
 // virtual
 F32 LLViewerObject::getStreamingCost() const
 {
-	return 0.f;
+    return 0.f;
 }
 
 // virtual
@@ -4066,12 +4066,12 @@ bool LLViewerObject::getCostData(LLMeshCostData& costs) const
 
 U32 LLViewerObject::getTriangleCount(S32* vcount) const
 {
-	return 0;
+    return 0;
 }
 
 U32 LLViewerObject::getHighLODTriangleCount()
 {
-	return 0;
+    return 0;
 }
 
 U32 LLViewerObject::recursiveGetTriangleCount(S32* vcount) const
@@ -4106,13 +4106,13 @@ F32 LLViewerObject::recursiveGetScaledSurfaceArea() const
         {
             if (volume->getVolume())
             {
-				const LLVector3& scale = volume->getScale();
+                const LLVector3& scale = volume->getScale();
                 area += volume->getVolume()->getSurfaceArea() * llmax(llmax(scale.mV[0], scale.mV[1]), scale.mV[2]);
             }
             const LLViewerObject::const_child_list_t& children = volume->getChildren();
             for (LLViewerObject* child_obj : children)
             {
-				if(!child_obj) continue;
+                if(!child_obj) continue;
 
                 LLVOVolume *child = child_obj->asVolume();
                 if (child && child->getVolume())
@@ -4128,68 +4128,68 @@ F32 LLViewerObject::recursiveGetScaledSurfaceArea() const
 
 void LLViewerObject::updateSpatialExtents(LLVector4a& newMin, LLVector4a &newMax)
 {
-	LLVector4a center;
-	center.load3(getRenderPosition().mV);
-	LLVector4a size;
-	size.load3(getScale().mV);
-	newMin.setSub(center, size);
-	newMax.setAdd(center, size);
-	
-	mDrawable->setPositionGroup(center);
+    LLVector4a center;
+    center.load3(getRenderPosition().mV);
+    LLVector4a size;
+    size.load3(getScale().mV);
+    newMin.setSub(center, size);
+    newMax.setAdd(center, size);
+
+    mDrawable->setPositionGroup(center);
 }
 
 F32 LLViewerObject::getBinRadius()
 {
-	if (mDrawable.notNull())
-	{
-		const LLVector4a* ext = mDrawable->getSpatialExtents();
-		LLVector4a diff;
-		diff.setSub(ext[1], ext[0]);
-		return diff.getLength3().getF32();
-	}
-	
-	return getScale().magVec();
+    if (mDrawable.notNull())
+    {
+        const LLVector4a* ext = mDrawable->getSpatialExtents();
+        LLVector4a diff;
+        diff.setSub(ext[1], ext[0]);
+        return diff.getLength3().getF32();
+    }
+
+    return getScale().magVec();
 }
 
 F32 LLViewerObject::getMaxScale() const
 {
-	return llmax(getScale().mV[VX],getScale().mV[VY], getScale().mV[VZ]);
+    return llmax(getScale().mV[VX],getScale().mV[VY], getScale().mV[VZ]);
 }
 
 F32 LLViewerObject::getMinScale() const
 {
-	return llmin(getScale().mV[0],getScale().mV[1],getScale().mV[2]);
+    return llmin(getScale().mV[0],getScale().mV[1],getScale().mV[2]);
 }
 
 F32 LLViewerObject::getMidScale() const
 {
-	if (getScale().mV[VX] < getScale().mV[VY])
-	{
-		if (getScale().mV[VY] < getScale().mV[VZ])
-		{
-			return getScale().mV[VY];
-		}
-		else if (getScale().mV[VX] < getScale().mV[VZ])
-		{
-			return getScale().mV[VZ];
-		}
-		else
-		{
-			return getScale().mV[VX];
-		}
-	}
-	else if (getScale().mV[VX] < getScale().mV[VZ])
-	{
-		return getScale().mV[VX];
-	}
-	else if (getScale().mV[VY] < getScale().mV[VZ])
-	{
-		return getScale().mV[VZ];
-	}
-	else
-	{
-		return getScale().mV[VY];
-	}
+    if (getScale().mV[VX] < getScale().mV[VY])
+    {
+        if (getScale().mV[VY] < getScale().mV[VZ])
+        {
+            return getScale().mV[VY];
+        }
+        else if (getScale().mV[VX] < getScale().mV[VZ])
+        {
+            return getScale().mV[VZ];
+        }
+        else
+        {
+            return getScale().mV[VX];
+        }
+    }
+    else if (getScale().mV[VX] < getScale().mV[VZ])
+    {
+        return getScale().mV[VX];
+    }
+    else if (getScale().mV[VY] < getScale().mV[VZ])
+    {
+        return getScale().mV[VZ];
+    }
+    else
+    {
+        return getScale().mV[VY];
+    }
 }
 
 
@@ -4199,66 +4199,66 @@ void LLViewerObject::updateTextures()
 
 void LLViewerObject::boostTexturePriority(BOOL boost_children /* = TRUE */)
 {
-	if (isDead() || !getVolume())
-	{
-		return;
-	}
-
-	S32 i;
-	S32 tex_count = getNumTEs();
-	for (i = 0; i < tex_count; i++)
-	{
- 		getTEImage(i)->setBoostLevel(LLGLTexture::BOOST_SELECTED);
-	}
-
-	if (isSculpted() && !isMesh())
-	{
-		const LLSculptParams *sculpt_params = getSculptParams();
-		LLUUID sculpt_id = sculpt_params->getSculptTexture();
-		LLViewerTextureManager::getFetchedTexture(sculpt_id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE)->setBoostLevel(LLGLTexture::BOOST_SELECTED);
-	}
-	
-	if (boost_children)
-	{
-		for (LLViewerObject* child : mChildList)
-		{
-			child->boostTexturePriority();
-		}
-	}
+    if (isDead() || !getVolume())
+    {
+        return;
+    }
+
+    S32 i;
+    S32 tex_count = getNumTEs();
+    for (i = 0; i < tex_count; i++)
+    {
+        getTEImage(i)->setBoostLevel(LLGLTexture::BOOST_SELECTED);
+    }
+
+    if (isSculpted() && !isMesh())
+    {
+        const LLSculptParams *sculpt_params = getSculptParams();
+        LLUUID sculpt_id = sculpt_params->getSculptTexture();
+        LLViewerTextureManager::getFetchedTexture(sculpt_id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE)->setBoostLevel(LLGLTexture::BOOST_SELECTED);
+    }
+
+    if (boost_children)
+    {
+        for (LLViewerObject* child : mChildList)
+        {
+            child->boostTexturePriority();
+        }
+    }
 }
 
 void LLViewerObject::setLineWidthForWindowSize(S32 window_width)
 {
-	if (window_width < 700)
-	{
-		LLUI::setLineWidth(2.0f);
-	}
-	else if (window_width < 1100)
-	{
-		LLUI::setLineWidth(3.0f);
-	}
-	else if (window_width < 2000)
-	{
-		LLUI::setLineWidth(4.0f);
-	}
-	else
-	{
-		// _damn_, what a nice monitor!
-		LLUI::setLineWidth(5.0f);
-	}
+    if (window_width < 700)
+    {
+        LLUI::setLineWidth(2.0f);
+    }
+    else if (window_width < 1100)
+    {
+        LLUI::setLineWidth(3.0f);
+    }
+    else if (window_width < 2000)
+    {
+        LLUI::setLineWidth(4.0f);
+    }
+    else
+    {
+        // _damn_, what a nice monitor!
+        LLUI::setLineWidth(5.0f);
+    }
 }
 
 void LLViewerObject::increaseArrowLength()
 {
 /* ???
-	if (mAxisArrowLength == 50)
-	{
-		mAxisArrowLength = 100;
-	}
-	else
-	{
-		mAxisArrowLength = 150;
-	}
+    if (mAxisArrowLength == 50)
+    {
+        mAxisArrowLength = 100;
+    }
+    else
+    {
+        mAxisArrowLength = 150;
+    }
 */
 }
 
@@ -4266,163 +4266,163 @@ void LLViewerObject::increaseArrowLength()
 void LLViewerObject::decreaseArrowLength()
 {
 /* ???
-	if (mAxisArrowLength == 150)
-	{
-		mAxisArrowLength = 100;
-	}
-	else
-	{
-		mAxisArrowLength = 50;
-	}
+    if (mAxisArrowLength == 150)
+    {
+        mAxisArrowLength = 100;
+    }
+    else
+    {
+        mAxisArrowLength = 50;
+    }
 */
 }
 
 // Culled from newsim LLTask::addNVPair
 void LLViewerObject::addNVPair(const std::string& data)
 {
-	// cout << "LLViewerObject::addNVPair() with ---" << data << "---" << endl;
-	LLNameValue *nv = new LLNameValue(data.c_str());
-
-//	char splat[MAX_STRING];
-//	temp->printNameValue(splat);
-//	LL_INFOS() << "addNVPair " << splat << LL_ENDL;
-
-	name_value_map_t::iterator iter = mNameValuePairs.find(nv->mName);
-	if (iter != mNameValuePairs.end())
-	{
-		LLNameValue* foundnv = iter->second;
-		if (foundnv->mClass != NVC_READ_ONLY)
-		{
-			delete foundnv;
-			mNameValuePairs.erase(iter);
-		}
-		else
-		{
-			delete nv;
-//			LL_INFOS() << "Trying to write to Read Only NVPair " << temp->mName << " in addNVPair()" << LL_ENDL;
-			return;
-		}
-	}
-	mNameValuePairs[nv->mName] = nv;
+    // cout << "LLViewerObject::addNVPair() with ---" << data << "---" << endl;
+    LLNameValue *nv = new LLNameValue(data.c_str());
+
+//  char splat[MAX_STRING];
+//  temp->printNameValue(splat);
+//  LL_INFOS() << "addNVPair " << splat << LL_ENDL;
+
+    name_value_map_t::iterator iter = mNameValuePairs.find(nv->mName);
+    if (iter != mNameValuePairs.end())
+    {
+        LLNameValue* foundnv = iter->second;
+        if (foundnv->mClass != NVC_READ_ONLY)
+        {
+            delete foundnv;
+            mNameValuePairs.erase(iter);
+        }
+        else
+        {
+            delete nv;
+//          LL_INFOS() << "Trying to write to Read Only NVPair " << temp->mName << " in addNVPair()" << LL_ENDL;
+            return;
+        }
+    }
+    mNameValuePairs[nv->mName] = nv;
 }
 
 BOOL LLViewerObject::removeNVPair(const std::string& name)
 {
-	char* canonical_name = gNVNameTable.addString(name);
+    char* canonical_name = gNVNameTable.addString(name);
 
-	LL_DEBUGS() << "LLViewerObject::removeNVPair(): " << name << LL_ENDL;
+    LL_DEBUGS() << "LLViewerObject::removeNVPair(): " << name << LL_ENDL;
 
-	name_value_map_t::iterator iter = mNameValuePairs.find(canonical_name);
-	if (iter != mNameValuePairs.end())
-	{
-		if( mRegionp )
-		{
-			LLNameValue* nv = iter->second;
+    name_value_map_t::iterator iter = mNameValuePairs.find(canonical_name);
+    if (iter != mNameValuePairs.end())
+    {
+        if( mRegionp )
+        {
+            LLNameValue* nv = iter->second;
 /*
-			std::string buffer = nv->printNameValue();
-			gMessageSystem->newMessageFast(_PREHASH_RemoveNameValuePair);
-			gMessageSystem->nextBlockFast(_PREHASH_TaskData);
-			gMessageSystem->addUUIDFast(_PREHASH_ID, mID);
-			
-			gMessageSystem->nextBlockFast(_PREHASH_NameValueData);
-			gMessageSystem->addStringFast(_PREHASH_NVPair, buffer);
-
-			gMessageSystem->sendReliable( mRegionp->getHost() );
+            std::string buffer = nv->printNameValue();
+            gMessageSystem->newMessageFast(_PREHASH_RemoveNameValuePair);
+            gMessageSystem->nextBlockFast(_PREHASH_TaskData);
+            gMessageSystem->addUUIDFast(_PREHASH_ID, mID);
+
+            gMessageSystem->nextBlockFast(_PREHASH_NameValueData);
+            gMessageSystem->addStringFast(_PREHASH_NVPair, buffer);
+
+            gMessageSystem->sendReliable( mRegionp->getHost() );
 */
-			// Remove the NV pair from the local list.
-			delete nv;
-			mNameValuePairs.erase(iter);
-			return TRUE;
-		}
-		else
-		{
-			LL_DEBUGS() << "removeNVPair - No region for object" << LL_ENDL;
-		}
-	}
-	return FALSE;
+            // Remove the NV pair from the local list.
+            delete nv;
+            mNameValuePairs.erase(iter);
+            return TRUE;
+        }
+        else
+        {
+            LL_DEBUGS() << "removeNVPair - No region for object" << LL_ENDL;
+        }
+    }
+    return FALSE;
 }
 
 
 LLNameValue *LLViewerObject::getNVPair(const std::string& name) const
 {
-	char		*canonical_name;
+    char        *canonical_name;
 
-	canonical_name = gNVNameTable.addString(name);
-	// It's possible for addString to return NULL.
-	if (canonical_name == NULL)
-	{
-		return NULL;
-	}
+    canonical_name = gNVNameTable.addString(name);
+    // It's possible for addString to return NULL.
+    if (canonical_name == NULL)
+    {
+        return NULL;
+    }
 
-	// If you access a map with a name that isn't in it, it will add the name and a null pointer.
-	// So first check if the data is in the map.
-	name_value_map_t::const_iterator iter = mNameValuePairs.find(canonical_name);
-	if (iter != mNameValuePairs.end())
-	{
-		return iter->second;
-	}
-	else
-	{
-		return NULL;
-	}
+    // If you access a map with a name that isn't in it, it will add the name and a null pointer.
+    // So first check if the data is in the map.
+    name_value_map_t::const_iterator iter = mNameValuePairs.find(canonical_name);
+    if (iter != mNameValuePairs.end())
+    {
+        return iter->second;
+    }
+    else
+    {
+        return NULL;
+    }
 }
 
 void LLViewerObject::updatePositionCaches() const
 {
-	// If region is removed from the list it is also deleted.
-	if(mRegionp && LLWorld::instance().isRegionListed(mRegionp))
-	{
-		if (!isRoot())
-		{
-			mPositionRegion = ((LLViewerObject *)getParent())->getPositionRegion() + getPosition() * getParent()->getRotation();
-			mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
-		}
-		else
-		{
-			mPositionRegion = getPosition();
-			mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
-		}
-	}
+    // If region is removed from the list it is also deleted.
+    if(mRegionp && LLWorld::instance().isRegionListed(mRegionp))
+    {
+        if (!isRoot())
+        {
+            mPositionRegion = ((LLViewerObject *)getParent())->getPositionRegion() + getPosition() * getParent()->getRotation();
+            mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
+        }
+        else
+        {
+            mPositionRegion = getPosition();
+            mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
+        }
+    }
 }
 
 const LLVector3d LLViewerObject::getPositionGlobal() const
-{	
-	// If region is removed from the list it is also deleted.
-	if(mRegionp && LLWorld::instance().isRegionListed(mRegionp))
-	{
-		LLVector3d position_global = mRegionp->getPosGlobalFromRegion(getPositionRegion());
-
-		if (isAttachment())
-		{
-			position_global = gAgent.getPosGlobalFromAgent(getRenderPosition());
-		}		
-		return position_global;
-	}
-	else
-	{
-		LLVector3d position_global(getPosition());
-		return position_global;
-	}	
+{
+    // If region is removed from the list it is also deleted.
+    if(mRegionp && LLWorld::instance().isRegionListed(mRegionp))
+    {
+        LLVector3d position_global = mRegionp->getPosGlobalFromRegion(getPositionRegion());
+
+        if (isAttachment())
+        {
+            position_global = gAgent.getPosGlobalFromAgent(getRenderPosition());
+        }
+        return position_global;
+    }
+    else
+    {
+        LLVector3d position_global(getPosition());
+        return position_global;
+    }
 }
 
 const LLVector3 &LLViewerObject::getPositionAgent() const
 {
-	// If region is removed from the list it is also deleted.
-	if(mRegionp && LLWorld::instance().isRegionListed(mRegionp))
-	{
-		if (mDrawable.notNull() && (!mDrawable->isRoot() && getParent()))
-		{
-			// Don't return cached position if you have a parent, recalc (until all dirtying is done correctly.
-			LLVector3 position_region;
-			position_region = ((LLViewerObject *)getParent())->getPositionRegion() + getPosition() * getParent()->getRotation();
-			mPositionAgent = mRegionp->getPosAgentFromRegion(position_region);
-		}
-		else
-		{
-			mPositionAgent = mRegionp->getPosAgentFromRegion(getPosition());
-		}
-	}
-	return mPositionAgent;
+    // If region is removed from the list it is also deleted.
+    if(mRegionp && LLWorld::instance().isRegionListed(mRegionp))
+    {
+        if (mDrawable.notNull() && (!mDrawable->isRoot() && getParent()))
+        {
+            // Don't return cached position if you have a parent, recalc (until all dirtying is done correctly.
+            LLVector3 position_region;
+            position_region = ((LLViewerObject *)getParent())->getPositionRegion() + getPosition() * getParent()->getRotation();
+            mPositionAgent = mRegionp->getPosAgentFromRegion(position_region);
+        }
+        else
+        {
+            mPositionAgent = mRegionp->getPosAgentFromRegion(getPosition());
+        }
+    }
+    return mPositionAgent;
 }
 
 LLMatrix4a LLViewerObject::getGLTFAssetToAgentTransform() const
@@ -4568,7 +4568,7 @@ void LLViewerObject::moveGLTFNode(S32 node_index, const LLVector3& offset)
         LLVector4a origin = LLVector4a::getZero();
         LLVector4a offset_v;
         offset_v.load3(offset.mV);
-        
+
 
         agent_to_node.affineTransform(offset_v, offset_v);
         agent_to_node.affineTransform(origin, origin);
@@ -4589,37 +4589,37 @@ void LLViewerObject::moveGLTFNode(S32 node_index, const LLVector3& offset)
 
 const LLVector3 &LLViewerObject::getPositionRegion() const
 {
-	if (!isRoot())
-	{
-		LLViewerObject *parent = (LLViewerObject *)getParent();
-		mPositionRegion = parent->getPositionRegion() + (getPosition() * parent->getRotation());
-	}
-	else
-	{
-		mPositionRegion = getPosition();
-	}
+    if (!isRoot())
+    {
+        LLViewerObject *parent = (LLViewerObject *)getParent();
+        mPositionRegion = parent->getPositionRegion() + (getPosition() * parent->getRotation());
+    }
+    else
+    {
+        mPositionRegion = getPosition();
+    }
 
-	return mPositionRegion;
+    return mPositionRegion;
 }
 
 const LLVector3 LLViewerObject::getPositionEdit() const
 {
-	if (isRootEdit())
-	{
-		return getPosition();
-	}
-	else
-	{
-		LLViewerObject *parent = (LLViewerObject *)getParent();
-		LLVector3 position_edit = parent->getPositionEdit() + getPosition() * parent->getRotationEdit();
-		return position_edit;
-	}
+    if (isRootEdit())
+    {
+        return getPosition();
+    }
+    else
+    {
+        LLViewerObject *parent = (LLViewerObject *)getParent();
+        LLVector3 position_edit = parent->getPositionEdit() + getPosition() * parent->getRotationEdit();
+        return position_edit;
+    }
 }
 
 const LLVector3 LLViewerObject::getRenderPosition() const
 {
-	if (mDrawable.notNull() && mDrawable->isState(LLDrawable::RIGGED))
-	{
+    if (mDrawable.notNull() && mDrawable->isState(LLDrawable::RIGGED))
+    {
         LLControlAvatar *cav = getControlAvatar();
         if (isRoot() && cav)
         {
@@ -4632,448 +4632,448 @@ const LLVector3 LLViewerObject::getRenderPosition() const
                 return pos;
             }
         }
-		LLVOAvatar* avatar = getAvatar();
-		if ((avatar) && !cav)
-		{
-			return avatar->getPositionAgent();
-		}
-	}
+        LLVOAvatar* avatar = getAvatar();
+        if ((avatar) && !cav)
+        {
+            return avatar->getPositionAgent();
+        }
+    }
 
-	if (mDrawable.isNull() || mDrawable->getGeneration() < 0)
-	{
-		return getPositionAgent();
-	}
-	else
-	{
-		return mDrawable->getPositionAgent();
-	}
+    if (mDrawable.isNull() || mDrawable->getGeneration() < 0)
+    {
+        return getPositionAgent();
+    }
+    else
+    {
+        return mDrawable->getPositionAgent();
+    }
 }
 
 const LLVector3 LLViewerObject::getPivotPositionAgent() const
 {
-	return getRenderPosition();
+    return getRenderPosition();
 }
 
 const LLQuaternion LLViewerObject::getRenderRotation() const
 {
-	LLQuaternion ret;
-	if (mDrawable.notNull() && mDrawable->isState(LLDrawable::RIGGED) && !isAnimatedObject())
-	{
-		return ret;
-	}
-	
-	if (mDrawable.isNull() || mDrawable->isStatic())
-	{
-		ret = getRotationEdit();
-	}
-	else
-	{
-		if (!mDrawable->isRoot())
-		{
-			ret = getRotation() * LLQuaternion(LLMatrix4(mDrawable->getParent()->getWorldMatrix().getF32ptr()));
-		}
-		else
-		{
-			ret = LLQuaternion(LLMatrix4(mDrawable->getWorldMatrix().getF32ptr()));
-		}
-	}
-	
-	return ret;
+    LLQuaternion ret;
+    if (mDrawable.notNull() && mDrawable->isState(LLDrawable::RIGGED) && !isAnimatedObject())
+    {
+        return ret;
+    }
+
+    if (mDrawable.isNull() || mDrawable->isStatic())
+    {
+        ret = getRotationEdit();
+    }
+    else
+    {
+        if (!mDrawable->isRoot())
+        {
+            ret = getRotation() * LLQuaternion(LLMatrix4(mDrawable->getParent()->getWorldMatrix().getF32ptr()));
+        }
+        else
+        {
+            ret = LLQuaternion(LLMatrix4(mDrawable->getWorldMatrix().getF32ptr()));
+        }
+    }
+
+    return ret;
 }
 
 const LLMatrix4a& LLViewerObject::getRenderMatrix() const
 {
-	return mDrawable->getWorldMatrix();
+    return mDrawable->getWorldMatrix();
 }
 
 const LLQuaternion LLViewerObject::getRotationRegion() const
 {
-	LLQuaternion global_rotation = getRotation();
-	if (!((LLXform *)this)->isRoot())
-	{
-		global_rotation = global_rotation * getParent()->getRotation();
-	}
-	return global_rotation;
+    LLQuaternion global_rotation = getRotation();
+    if (!((LLXform *)this)->isRoot())
+    {
+        global_rotation = global_rotation * getParent()->getRotation();
+    }
+    return global_rotation;
 }
 
 const LLQuaternion LLViewerObject::getRotationEdit() const
 {
-	LLQuaternion global_rotation = getRotation();
-	if (!((LLXform *)this)->isRootEdit())
-	{
-		global_rotation = global_rotation * getParent()->getRotation();
-	}
-	return global_rotation;
+    LLQuaternion global_rotation = getRotation();
+    if (!((LLXform *)this)->isRootEdit())
+    {
+        global_rotation = global_rotation * getParent()->getRotation();
+    }
+    return global_rotation;
 }
 
 void LLViewerObject::setPositionAbsoluteGlobal( const LLVector3d &pos_global, BOOL damped )
 {
-	if (isAttachment())
-	{
-		LLVector3 new_pos = mRegionp->getPosRegionFromGlobal(pos_global);
-		if (isRootEdit())
-		{
-			new_pos -= mDrawable->mXform.getParent()->getWorldPosition();
-			LLQuaternion world_rotation = mDrawable->mXform.getParent()->getWorldRotation();
-			new_pos = new_pos * ~world_rotation;
-		}
-		else
-		{
-			LLViewerObject* parentp = (LLViewerObject*)getParent();
-			new_pos -= parentp->getPositionAgent();
-			new_pos = new_pos * ~parentp->getRotationRegion();
-		}
-		LLViewerObject::setPosition(new_pos);
-		
-		if (mParent && ((LLViewerObject*)mParent)->isAvatar())
-		{
-			// we have changed the position of an attachment, so we need to clamp it
-			LLVOAvatar *avatar = (LLVOAvatar*)mParent;
-
-			avatar->clampAttachmentPositions();
-		}
-	}
-	else
-	{
-		if( isRoot() )
-		{
-			setPositionRegion(mRegionp->getPosRegionFromGlobal(pos_global));
-		}
-		else
-		{
-			// the relative position with the parent is not constant
-			LLViewerObject* parent = (LLViewerObject *)getParent();
-			//RN: this assumes we are only calling this function from the edit tools
-			gPipeline.updateMoveNormalAsync(parent->mDrawable);
-
-			LLVector3 pos_local = mRegionp->getPosRegionFromGlobal(pos_global) - parent->getPositionRegion();
-			pos_local = pos_local * ~parent->getRotationRegion();
-			LLViewerObject::setPosition( pos_local );
-		}
-	}
-	//RN: assumes we always want to snap the object when calling this function
-	gPipeline.updateMoveNormalAsync(mDrawable);
+    if (isAttachment())
+    {
+        LLVector3 new_pos = mRegionp->getPosRegionFromGlobal(pos_global);
+        if (isRootEdit())
+        {
+            new_pos -= mDrawable->mXform.getParent()->getWorldPosition();
+            LLQuaternion world_rotation = mDrawable->mXform.getParent()->getWorldRotation();
+            new_pos = new_pos * ~world_rotation;
+        }
+        else
+        {
+            LLViewerObject* parentp = (LLViewerObject*)getParent();
+            new_pos -= parentp->getPositionAgent();
+            new_pos = new_pos * ~parentp->getRotationRegion();
+        }
+        LLViewerObject::setPosition(new_pos);
+
+        if (mParent && ((LLViewerObject*)mParent)->isAvatar())
+        {
+            // we have changed the position of an attachment, so we need to clamp it
+            LLVOAvatar *avatar = (LLVOAvatar*)mParent;
+
+            avatar->clampAttachmentPositions();
+        }
+    }
+    else
+    {
+        if( isRoot() )
+        {
+            setPositionRegion(mRegionp->getPosRegionFromGlobal(pos_global));
+        }
+        else
+        {
+            // the relative position with the parent is not constant
+            LLViewerObject* parent = (LLViewerObject *)getParent();
+            //RN: this assumes we are only calling this function from the edit tools
+            gPipeline.updateMoveNormalAsync(parent->mDrawable);
+
+            LLVector3 pos_local = mRegionp->getPosRegionFromGlobal(pos_global) - parent->getPositionRegion();
+            pos_local = pos_local * ~parent->getRotationRegion();
+            LLViewerObject::setPosition( pos_local );
+        }
+    }
+    //RN: assumes we always want to snap the object when calling this function
+    gPipeline.updateMoveNormalAsync(mDrawable);
 }
 
 void LLViewerObject::setPosition(const LLVector3 &pos, BOOL damped)
 {
-	if (getPosition() != pos)
-	{
-		setChanged(TRANSLATED | SILHOUETTE);
-	}
-		
-	LLXform::setPosition(pos);
-	updateDrawable(damped);
-	if (isRoot())
-	{
-		// position caches need to be up to date on root objects
-		updatePositionCaches();
-	}
+    if (getPosition() != pos)
+    {
+        setChanged(TRANSLATED | SILHOUETTE);
+    }
+
+    LLXform::setPosition(pos);
+    updateDrawable(damped);
+    if (isRoot())
+    {
+        // position caches need to be up to date on root objects
+        updatePositionCaches();
+    }
 }
 
 void LLViewerObject::setPositionGlobal(const LLVector3d &pos_global, BOOL damped)
 {
-	if (isAttachment())
-	{
-		if (isRootEdit())
-		{
-			LLVector3 newPos = mRegionp->getPosRegionFromGlobal(pos_global);
-			newPos = newPos - mDrawable->mXform.getParent()->getWorldPosition();
-
-			LLQuaternion invWorldRotation = mDrawable->mXform.getParent()->getWorldRotation();
-			invWorldRotation.transQuat();
-
-			newPos = newPos * invWorldRotation;
-			LLViewerObject::setPosition(newPos);
-		}
-		else
-		{
-			// assumes parent is root editable (root of attachment)
-			LLVector3 newPos = mRegionp->getPosRegionFromGlobal(pos_global);
-			newPos = newPos - mDrawable->mXform.getParent()->getWorldPosition();
-			LLVector3 delta_pos = newPos - getPosition();
-
-			LLQuaternion invRotation = mDrawable->getRotation();
-			invRotation.transQuat();
-			
-			delta_pos = delta_pos * invRotation;
-
-			// *FIX: is this right?  Shouldn't we be calling the
-			// LLViewerObject version of setPosition?
-			LLVector3 old_pos = mDrawable->mXform.getParent()->getPosition();
-			mDrawable->mXform.getParent()->setPosition(old_pos + delta_pos);
-			setChanged(TRANSLATED | SILHOUETTE);
-		}
-		if (mParent && ((LLViewerObject*)mParent)->isAvatar())
-		{
-			// we have changed the position of an attachment, so we need to clamp it
-			LLVOAvatar *avatar = (LLVOAvatar*)mParent;
-
-			avatar->clampAttachmentPositions();
-		}
-	}
-	else
-	{
-		if (isRoot())
-		{
-			setPositionRegion(mRegionp->getPosRegionFromGlobal(pos_global));
-		}
-		else
-		{
-			// the relative position with the parent is constant, but the parent's position needs to be changed
-			LLVector3d position_offset;
-			position_offset.setVec(getPosition()*getParent()->getRotation());
-			LLVector3d new_pos_global = pos_global - position_offset;
-			((LLViewerObject *)getParent())->setPositionGlobal(new_pos_global);
-		}
-	}
-	updateDrawable(damped);
+    if (isAttachment())
+    {
+        if (isRootEdit())
+        {
+            LLVector3 newPos = mRegionp->getPosRegionFromGlobal(pos_global);
+            newPos = newPos - mDrawable->mXform.getParent()->getWorldPosition();
+
+            LLQuaternion invWorldRotation = mDrawable->mXform.getParent()->getWorldRotation();
+            invWorldRotation.transQuat();
+
+            newPos = newPos * invWorldRotation;
+            LLViewerObject::setPosition(newPos);
+        }
+        else
+        {
+            // assumes parent is root editable (root of attachment)
+            LLVector3 newPos = mRegionp->getPosRegionFromGlobal(pos_global);
+            newPos = newPos - mDrawable->mXform.getParent()->getWorldPosition();
+            LLVector3 delta_pos = newPos - getPosition();
+
+            LLQuaternion invRotation = mDrawable->getRotation();
+            invRotation.transQuat();
+
+            delta_pos = delta_pos * invRotation;
+
+            // *FIX: is this right?  Shouldn't we be calling the
+            // LLViewerObject version of setPosition?
+            LLVector3 old_pos = mDrawable->mXform.getParent()->getPosition();
+            mDrawable->mXform.getParent()->setPosition(old_pos + delta_pos);
+            setChanged(TRANSLATED | SILHOUETTE);
+        }
+        if (mParent && ((LLViewerObject*)mParent)->isAvatar())
+        {
+            // we have changed the position of an attachment, so we need to clamp it
+            LLVOAvatar *avatar = (LLVOAvatar*)mParent;
+
+            avatar->clampAttachmentPositions();
+        }
+    }
+    else
+    {
+        if (isRoot())
+        {
+            setPositionRegion(mRegionp->getPosRegionFromGlobal(pos_global));
+        }
+        else
+        {
+            // the relative position with the parent is constant, but the parent's position needs to be changed
+            LLVector3d position_offset;
+            position_offset.setVec(getPosition()*getParent()->getRotation());
+            LLVector3d new_pos_global = pos_global - position_offset;
+            ((LLViewerObject *)getParent())->setPositionGlobal(new_pos_global);
+        }
+    }
+    updateDrawable(damped);
 }
 
 
 void LLViewerObject::setPositionParent(const LLVector3 &pos_parent, BOOL damped)
 {
-	// Set position relative to parent, if no parent, relative to region
-	if (!isRoot())
-	{
-		LLViewerObject::setPosition(pos_parent, damped);
-		//updateDrawable(damped);
-	}
-	else
-	{
-		setPositionRegion(pos_parent, damped);
-	}
+    // Set position relative to parent, if no parent, relative to region
+    if (!isRoot())
+    {
+        LLViewerObject::setPosition(pos_parent, damped);
+        //updateDrawable(damped);
+    }
+    else
+    {
+        setPositionRegion(pos_parent, damped);
+    }
 }
 
 void LLViewerObject::setPositionRegion(const LLVector3 &pos_region, BOOL damped)
 {
-	if (!isRootEdit())
-	{
-		LLViewerObject* parent = (LLViewerObject*) getParent();
-		LLViewerObject::setPosition((pos_region-parent->getPositionRegion())*~parent->getRotationRegion());
-	}
-	else
-	{
-		LLViewerObject::setPosition(pos_region);
-		mPositionRegion = pos_region;
-		mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
-	}
+    if (!isRootEdit())
+    {
+        LLViewerObject* parent = (LLViewerObject*) getParent();
+        LLViewerObject::setPosition((pos_region-parent->getPositionRegion())*~parent->getRotationRegion());
+    }
+    else
+    {
+        LLViewerObject::setPosition(pos_region);
+        mPositionRegion = pos_region;
+        mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
+    }
 }
 
 void LLViewerObject::setPositionAgent(const LLVector3 &pos_agent, BOOL damped)
 {
-	LLVector3 pos_region = getRegion()->getPosRegionFromAgent(pos_agent);
-	setPositionRegion(pos_region, damped);
+    LLVector3 pos_region = getRegion()->getPosRegionFromAgent(pos_agent);
+    setPositionRegion(pos_region, damped);
 }
 
-// identical to setPositionRegion() except it checks for child-joints 
+// identical to setPositionRegion() except it checks for child-joints
 // and doesn't also move the joint-parent
 // TODO -- implement similar intelligence for joint-parents toward
 // their joint-children
 void LLViewerObject::setPositionEdit(const LLVector3 &pos_edit, BOOL damped)
 {
-	if (!isRootEdit())
-	{
-		// the relative position with the parent is constant, but the parent's position needs to be changed
-		LLVector3 position_offset = getPosition() * getParent()->getRotation();
+    if (!isRootEdit())
+    {
+        // the relative position with the parent is constant, but the parent's position needs to be changed
+        LLVector3 position_offset = getPosition() * getParent()->getRotation();
 
-		((LLViewerObject *)getParent())->setPositionEdit(pos_edit - position_offset);
-		updateDrawable(damped);
-	}
-	else
-	{
-		LLViewerObject::setPosition(pos_edit, damped);
-		mPositionRegion = pos_edit;
-		mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
-	}	
+        ((LLViewerObject *)getParent())->setPositionEdit(pos_edit - position_offset);
+        updateDrawable(damped);
+    }
+    else
+    {
+        LLViewerObject::setPosition(pos_edit, damped);
+        mPositionRegion = pos_edit;
+        mPositionAgent = mRegionp->getPosAgentFromRegion(mPositionRegion);
+    }
 }
 
 
 LLViewerObject* LLViewerObject::getRootEdit() const
 {
-	const LLViewerObject* root = this;
-	while (root->mParent 
-		   && !((LLViewerObject*)root->mParent)->isAvatar()) 
-	{
-		root = (LLViewerObject*)root->mParent;
-	}
-	return (LLViewerObject*)root;
+    const LLViewerObject* root = this;
+    while (root->mParent
+           && !((LLViewerObject*)root->mParent)->isAvatar())
+    {
+        root = (LLViewerObject*)root->mParent;
+    }
+    return (LLViewerObject*)root;
 }
 
 
 BOOL LLViewerObject::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
-										  S32 face,
-										  BOOL pick_transparent,
-										  BOOL pick_rigged,
+                                          S32 face,
+                                          BOOL pick_transparent,
+                                          BOOL pick_rigged,
                                           BOOL pick_unselectable,
-										  S32* face_hit,
-										  LLVector4a* intersection,
-										  LLVector2* tex_coord,
-										  LLVector4a* normal,
-										  LLVector4a* tangent)
+                                          S32* face_hit,
+                                          LLVector4a* intersection,
+                                          LLVector2* tex_coord,
+                                          LLVector4a* normal,
+                                          LLVector4a* tangent)
 {
-	return false;
+    return false;
 }
 
 BOOL LLViewerObject::lineSegmentBoundingBox(const LLVector4a& start, const LLVector4a& end)
 {
-	if (mDrawable.isNull() || mDrawable->isDead())
-	{
-		return FALSE;
-	}
+    if (mDrawable.isNull() || mDrawable->isDead())
+    {
+        return FALSE;
+    }
 
-	const LLVector4a* ext = mDrawable->getSpatialExtents();
+    const LLVector4a* ext = mDrawable->getSpatialExtents();
 
-	//VECTORIZE THIS
-	LLVector4a center;
-	center.setAdd(ext[1], ext[0]);
-	center.mul(0.5f);
-	LLVector4a size;
-	size.setSub(ext[1], ext[0]);
-	size.mul(0.5f);
+    //VECTORIZE THIS
+    LLVector4a center;
+    center.setAdd(ext[1], ext[0]);
+    center.mul(0.5f);
+    LLVector4a size;
+    size.setSub(ext[1], ext[0]);
+    size.mul(0.5f);
 
-	return LLLineSegmentBoxIntersect(start, end, center, size);
+    return LLLineSegmentBoxIntersect(start, end, center, size);
 }
 
 U8 LLViewerObject::getMediaType() const
 {
-	if (mMedia)
-	{
-		return mMedia->mMediaType;
-	}
-	else
-	{
-		return LLViewerObject::MEDIA_NONE;
-	}
+    if (mMedia)
+    {
+        return mMedia->mMediaType;
+    }
+    else
+    {
+        return LLViewerObject::MEDIA_NONE;
+    }
 }
 
 void LLViewerObject::setMediaType(U8 media_type)
 {
-	if (!mMedia)
-	{
-		// TODO what if we don't have a media pointer?
-	}
-	else if (mMedia->mMediaType != media_type)
-	{
-		mMedia->mMediaType = media_type;
+    if (!mMedia)
+    {
+        // TODO what if we don't have a media pointer?
+    }
+    else if (mMedia->mMediaType != media_type)
+    {
+        mMedia->mMediaType = media_type;
 
-		// TODO: update materials with new image
-	}
+        // TODO: update materials with new image
+    }
 }
 
 std::string LLViewerObject::getMediaURL() const
 {
-	if (mMedia)
-	{
-		return mMedia->mMediaURL;
-	}
-	else
-	{
-		return std::string();
-	}
+    if (mMedia)
+    {
+        return mMedia->mMediaURL;
+    }
+    else
+    {
+        return std::string();
+    }
 }
 
 void LLViewerObject::setMediaURL(const std::string& media_url)
 {
-	if (!mMedia)
-	{
-		mMedia = new LLViewerObjectMedia;
-		mMedia->mMediaURL = media_url;
-		mMedia->mPassedWhitelist = FALSE;
+    if (!mMedia)
+    {
+        mMedia = new LLViewerObjectMedia;
+        mMedia->mMediaURL = media_url;
+        mMedia->mPassedWhitelist = FALSE;
 
-		// TODO: update materials with new image
-	}
-	else if (mMedia->mMediaURL != media_url)
-	{
-		mMedia->mMediaURL = media_url;
-		mMedia->mPassedWhitelist = FALSE;
+        // TODO: update materials with new image
+    }
+    else if (mMedia->mMediaURL != media_url)
+    {
+        mMedia->mMediaURL = media_url;
+        mMedia->mPassedWhitelist = FALSE;
 
-		// TODO: update materials with new image
-	}
+        // TODO: update materials with new image
+    }
 }
 
 BOOL LLViewerObject::getMediaPassedWhitelist() const
 {
-	if (mMedia)
-	{
-		return mMedia->mPassedWhitelist;
-	}
-	else
-	{
-		return FALSE;
-	}
+    if (mMedia)
+    {
+        return mMedia->mPassedWhitelist;
+    }
+    else
+    {
+        return FALSE;
+    }
 }
 
 void LLViewerObject::setMediaPassedWhitelist(BOOL passed)
 {
-	if (mMedia)
-	{
-		mMedia->mPassedWhitelist = passed;
-	}
+    if (mMedia)
+    {
+        mMedia->mPassedWhitelist = passed;
+    }
 }
 
 BOOL LLViewerObject::setMaterial(const U8 material)
 {
-	BOOL res = LLPrimitive::setMaterial(material);
-	if (res)
-	{
-		setChanged(TEXTURE);
-	}
-	return res;
+    BOOL res = LLPrimitive::setMaterial(material);
+    if (res)
+    {
+        setChanged(TEXTURE);
+    }
+    return res;
 }
 
 void LLViewerObject::setNumTEs(const U8 num_tes)
 {
-	U32 i;
-	if (num_tes != getNumTEs())
-	{
-		if (num_tes)
-		{
-			LLPointer<LLViewerTexture> *new_images;
-			new_images = new LLPointer<LLViewerTexture>[num_tes];
-			
-			LLPointer<LLViewerTexture> *new_normmaps;
-			new_normmaps = new LLPointer<LLViewerTexture>[num_tes];
-			
-			LLPointer<LLViewerTexture> *new_specmaps;
-			new_specmaps = new LLPointer<LLViewerTexture>[num_tes];
-			for (i = 0; i < num_tes; i++)
-			{
-				if (i < getNumTEs())
-				{
-					new_images[i] = mTEImages[i];
-					new_normmaps[i] = mTENormalMaps[i];
-					new_specmaps[i] = mTESpecularMaps[i];
-				}
-				else if (getNumTEs())
-				{
-					new_images[i] = mTEImages[getNumTEs()-1];
-					new_normmaps[i] = mTENormalMaps[getNumTEs()-1];
-					new_specmaps[i] = mTESpecularMaps[getNumTEs()-1];
-				}
-				else
-				{
-					new_images[i] = NULL;
-					new_normmaps[i] = NULL;
-					new_specmaps[i] = NULL;
-				}
-			}
-
-			deleteTEImages();
-			
-			mTEImages = new_images;
-			mTENormalMaps = new_normmaps;
-			mTESpecularMaps = new_specmaps;
-		}
-		else
-		{
-			deleteTEImages();
-		}
+    U32 i;
+    if (num_tes != getNumTEs())
+    {
+        if (num_tes)
+        {
+            LLPointer<LLViewerTexture> *new_images;
+            new_images = new LLPointer<LLViewerTexture>[num_tes];
+
+            LLPointer<LLViewerTexture> *new_normmaps;
+            new_normmaps = new LLPointer<LLViewerTexture>[num_tes];
+
+            LLPointer<LLViewerTexture> *new_specmaps;
+            new_specmaps = new LLPointer<LLViewerTexture>[num_tes];
+            for (i = 0; i < num_tes; i++)
+            {
+                if (i < getNumTEs())
+                {
+                    new_images[i] = mTEImages[i];
+                    new_normmaps[i] = mTENormalMaps[i];
+                    new_specmaps[i] = mTESpecularMaps[i];
+                }
+                else if (getNumTEs())
+                {
+                    new_images[i] = mTEImages[getNumTEs()-1];
+                    new_normmaps[i] = mTENormalMaps[getNumTEs()-1];
+                    new_specmaps[i] = mTESpecularMaps[getNumTEs()-1];
+                }
+                else
+                {
+                    new_images[i] = NULL;
+                    new_normmaps[i] = NULL;
+                    new_specmaps[i] = NULL;
+                }
+            }
+
+            deleteTEImages();
+
+            mTEImages = new_images;
+            mTENormalMaps = new_normmaps;
+            mTESpecularMaps = new_specmaps;
+        }
+        else
+        {
+            deleteTEImages();
+        }
 
         S32 original_tes = getNumTEs();
 
-		LLPrimitive::setNumTEs(num_tes);
-		setChanged(TEXTURE);
+        LLPrimitive::setNumTEs(num_tes);
+        setChanged(TEXTURE);
 
         // touch up GLTF materials
         if (original_tes > 0)
@@ -5101,128 +5101,128 @@ void LLViewerObject::setNumTEs(const U8 num_tes)
             }
         }
 
-		if (mDrawable.notNull())
-		{
-			gPipeline.markTextured(mDrawable);
-		}
-	}
+        if (mDrawable.notNull())
+        {
+            gPipeline.markTextured(mDrawable);
+        }
+    }
 }
 
 void LLViewerObject::sendMaterialUpdate() const
 {
-	LLViewerRegion* regionp = getRegion();
-	if(!regionp) return;
-	gMessageSystem->newMessageFast(_PREHASH_ObjectMaterial);
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID,	mLocalID );
-	gMessageSystem->addU8Fast(_PREHASH_Material, getMaterial() );
-	gMessageSystem->sendReliable( regionp->getHost() );
+    LLViewerRegion* regionp = getRegion();
+    if(!regionp) return;
+    gMessageSystem->newMessageFast(_PREHASH_ObjectMaterial);
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID,  mLocalID );
+    gMessageSystem->addU8Fast(_PREHASH_Material, getMaterial() );
+    gMessageSystem->sendReliable( regionp->getHost() );
 
 }
 
 //formerly send_object_shape(LLViewerObject *object)
 void LLViewerObject::sendShapeUpdate()
 {
-	LLViewerRegion* regionp = getRegion();
-	if(!regionp) return;
+    LLViewerRegion* regionp = getRegion();
+    if(!regionp) return;
 
-	gMessageSystem->newMessageFast(_PREHASH_ObjectShape);
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
+    gMessageSystem->newMessageFast(_PREHASH_ObjectShape);
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
 
-	LLVolumeMessage::packVolumeParams(&getVolume()->getParams(), gMessageSystem);
+    LLVolumeMessage::packVolumeParams(&getVolume()->getParams(), gMessageSystem);
 
-	gMessageSystem->sendReliable( regionp->getHost() );
+    gMessageSystem->sendReliable( regionp->getHost() );
 }
 
 
 void LLViewerObject::sendTEUpdate() const
 {
-	LLViewerRegion* regionp = getRegion();
-	if(!regionp) return;
+    LLViewerRegion* regionp = getRegion();
+    if(!regionp) return;
 
-	LLMessageSystem* msg = gMessageSystem;
-	msg->newMessageFast(_PREHASH_ObjectImage);
+    LLMessageSystem* msg = gMessageSystem;
+    msg->newMessageFast(_PREHASH_ObjectImage);
 
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
 
-	msg->nextBlockFast(_PREHASH_ObjectData);
-	msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
-	if (mMedia)
-	{
-		msg->addStringFast(_PREHASH_MediaURL, mMedia->mMediaURL);
-	}
-	else
-	{
-		msg->addStringFast(_PREHASH_MediaURL, NULL);
-	}
+    msg->nextBlockFast(_PREHASH_ObjectData);
+    msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
+    if (mMedia)
+    {
+        msg->addStringFast(_PREHASH_MediaURL, mMedia->mMediaURL);
+    }
+    else
+    {
+        msg->addStringFast(_PREHASH_MediaURL, NULL);
+    }
 
-	// TODO send media type
+    // TODO send media type
 
-	packTEMessage(msg);
+    packTEMessage(msg);
 
-	msg->sendReliable( regionp->getHost() );
+    msg->sendReliable( regionp->getHost() );
 }
 
 LLViewerTexture* LLViewerObject::getBakedTextureForMagicId(const LLUUID& id)
 {
-	if (!LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(id))
-	{
-		return NULL;
-	}
-
-	LLViewerObject *root = getRootEdit();
-	if (root && root->isAnimatedObject())
-	{
-		return LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
-	}
-
-	LLVOAvatar* avatar = getAvatar();
-	if (avatar && !isHUDAttachment())
-	{
-		LLAvatarAppearanceDefines::EBakedTextureIndex texIndex = LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::assetIdToBakedTextureIndex(id);
-		LLViewerTexture* bakedTexture = avatar->getBakedTexture(texIndex);
-		if (bakedTexture == NULL || bakedTexture->isMissingAsset())
-		{
-			return LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
-		}
-		else
-		{
-			return bakedTexture;
-		}
-	}
-	else
-	{
-		return LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
-	}
+    if (!LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(id))
+    {
+        return NULL;
+    }
+
+    LLViewerObject *root = getRootEdit();
+    if (root && root->isAnimatedObject())
+    {
+        return LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+    }
+
+    LLVOAvatar* avatar = getAvatar();
+    if (avatar && !isHUDAttachment())
+    {
+        LLAvatarAppearanceDefines::EBakedTextureIndex texIndex = LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::assetIdToBakedTextureIndex(id);
+        LLViewerTexture* bakedTexture = avatar->getBakedTexture(texIndex);
+        if (bakedTexture == NULL || bakedTexture->isMissingAsset())
+        {
+            return LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+        }
+        else
+        {
+            return bakedTexture;
+        }
+    }
+    else
+    {
+        return LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+    }
 
 }
 
 void LLViewerObject::updateAvatarMeshVisibility(const LLUUID& id, const LLUUID& old_id)
 {
-	if (id == old_id)
-	{
-		return;
-	}
+    if (id == old_id)
+    {
+        return;
+    }
 
-	if (!LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(old_id) && !LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(id))
-	{
-		return;
-	}
+    if (!LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(old_id) && !LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(id))
+    {
+        return;
+    }
 
-	LLVOAvatar* avatar = getAvatar();
-	if (avatar)
-	{
-		avatar->updateMeshVisibility();
-	}
+    LLVOAvatar* avatar = getAvatar();
+    if (avatar)
+    {
+        avatar->updateMeshVisibility();
+    }
 }
 
 
@@ -5247,14 +5247,14 @@ void LLViewerObject::setTE(const U8 te, const LLTextureEntry& texture_entry)
 
 void LLViewerObject::updateTEMaterialTextures(U8 te)
 {
-	if (getTE(te)->getMaterialParams().notNull())
-	{
-		const LLUUID& norm_id = getTE(te)->getMaterialParams()->getNormalID();
-		mTENormalMaps[te] = LLViewerTextureManager::getFetchedTexture(norm_id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
-		
-		const LLUUID& spec_id = getTE(te)->getMaterialParams()->getSpecularID();
-		mTESpecularMaps[te] = LLViewerTextureManager::getFetchedTexture(spec_id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
-	}
+    if (getTE(te)->getMaterialParams().notNull())
+    {
+        const LLUUID& norm_id = getTE(te)->getMaterialParams()->getNormalID();
+        mTENormalMaps[te] = LLViewerTextureManager::getFetchedTexture(norm_id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+
+        const LLUUID& spec_id = getTE(te)->getMaterialParams()->getSpecularID();
+        mTESpecularMaps[te] = LLViewerTextureManager::getFetchedTexture(spec_id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+    }
 
     LLFetchedGLTFMaterial* mat = (LLFetchedGLTFMaterial*) getTE(te)->getGLTFRenderMaterial();
     llassert(mat == nullptr || dynamic_cast<LLFetchedGLTFMaterial*>(getTE(te)->getGLTFRenderMaterial()) != nullptr);
@@ -5314,358 +5314,358 @@ void LLViewerObject::updateTEMaterialTextures(U8 te)
 
 void LLViewerObject::refreshBakeTexture()
 {
-	for (int face_index = 0; face_index < getNumTEs(); face_index++)
-	{
-		LLTextureEntry* tex_entry = getTE(face_index);
-		if (tex_entry && LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(tex_entry->getID()))
-		{
-			const LLUUID& image_id = tex_entry->getID();
-			LLViewerTexture* bakedTexture = getBakedTextureForMagicId(image_id);
-			changeTEImage(face_index, bakedTexture);
-		}
-	}
+    for (int face_index = 0; face_index < getNumTEs(); face_index++)
+    {
+        LLTextureEntry* tex_entry = getTE(face_index);
+        if (tex_entry && LLAvatarAppearanceDefines::LLAvatarAppearanceDictionary::isBakedImageId(tex_entry->getID()))
+        {
+            const LLUUID& image_id = tex_entry->getID();
+            LLViewerTexture* bakedTexture = getBakedTextureForMagicId(image_id);
+            changeTEImage(face_index, bakedTexture);
+        }
+    }
 }
 
 void LLViewerObject::setTEImage(const U8 te, LLViewerTexture *imagep)
 {
-	if (mTEImages[te] != imagep)
-	{
-		LLUUID old_image_id = getTE(te) ? getTE(te)->getID() : LLUUID::null;
-		
-		LLPrimitive::setTETexture(te, imagep->getID());
+    if (mTEImages[te] != imagep)
+    {
+        LLUUID old_image_id = getTE(te) ? getTE(te)->getID() : LLUUID::null;
+
+        LLPrimitive::setTETexture(te, imagep->getID());
 
-		LLViewerTexture* baked_texture = getBakedTextureForMagicId(imagep->getID());
-		mTEImages[te] = baked_texture ? baked_texture : imagep;
-		updateAvatarMeshVisibility(imagep->getID(), old_image_id);
-		setChanged(TEXTURE);
-		if (mDrawable.notNull())
-		{
-			gPipeline.markTextured(mDrawable);
-		}
-	}
+        LLViewerTexture* baked_texture = getBakedTextureForMagicId(imagep->getID());
+        mTEImages[te] = baked_texture ? baked_texture : imagep;
+        updateAvatarMeshVisibility(imagep->getID(), old_image_id);
+        setChanged(TEXTURE);
+        if (mDrawable.notNull())
+        {
+            gPipeline.markTextured(mDrawable);
+        }
+    }
 }
 
 S32 LLViewerObject::setTETextureCore(const U8 te, LLViewerTexture *image)
 {
-	LLUUID old_image_id = getTE(te)->getID();
-	const LLUUID& uuid = image ? image->getID() : LLUUID::null;
-	S32 retval = 0;
-	if (uuid != getTE(te)->getID() ||
-		uuid == LLUUID::null)
-	{
-		retval = LLPrimitive::setTETexture(te, uuid);
-		LLViewerTexture* baked_texture = getBakedTextureForMagicId(uuid);
-		mTEImages[te] = baked_texture ? baked_texture : image;
-		updateAvatarMeshVisibility(uuid, old_image_id);
-		setChanged(TEXTURE);
-		if (mDrawable.notNull())
-		{
-			gPipeline.markTextured(mDrawable);
-		}
-	}
-	return retval;
+    LLUUID old_image_id = getTE(te)->getID();
+    const LLUUID& uuid = image ? image->getID() : LLUUID::null;
+    S32 retval = 0;
+    if (uuid != getTE(te)->getID() ||
+        uuid == LLUUID::null)
+    {
+        retval = LLPrimitive::setTETexture(te, uuid);
+        LLViewerTexture* baked_texture = getBakedTextureForMagicId(uuid);
+        mTEImages[te] = baked_texture ? baked_texture : image;
+        updateAvatarMeshVisibility(uuid, old_image_id);
+        setChanged(TEXTURE);
+        if (mDrawable.notNull())
+        {
+            gPipeline.markTextured(mDrawable);
+        }
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTENormalMapCore(const U8 te, LLViewerTexture *image)
 {
-	S32 retval = TEM_CHANGE_TEXTURE;
-	const LLUUID& uuid = image ? image->getID() : LLUUID::null;
-	if (uuid != getTE(te)->getID() ||
-		uuid == LLUUID::null)
-	{
-		LLTextureEntry* tep = getTE(te);
-		LLMaterial* mat = NULL;
-		if (tep)
-		{
-		   mat = tep->getMaterialParams();
-		}
-
-		if (mat)
-		{
-			mat->setNormalID(uuid);
-		}
-	}
-	changeTENormalMap(te,image);	
-	return retval;
+    S32 retval = TEM_CHANGE_TEXTURE;
+    const LLUUID& uuid = image ? image->getID() : LLUUID::null;
+    if (uuid != getTE(te)->getID() ||
+        uuid == LLUUID::null)
+    {
+        LLTextureEntry* tep = getTE(te);
+        LLMaterial* mat = NULL;
+        if (tep)
+        {
+           mat = tep->getMaterialParams();
+        }
+
+        if (mat)
+        {
+            mat->setNormalID(uuid);
+        }
+    }
+    changeTENormalMap(te,image);
+    return retval;
 }
 
 S32 LLViewerObject::setTESpecularMapCore(const U8 te, LLViewerTexture *image)
 {
-	S32 retval = TEM_CHANGE_TEXTURE;
-	const LLUUID& uuid = image ? image->getID() : LLUUID::null;
-	if (uuid != getTE(te)->getID() ||
-		uuid == LLUUID::null)
-	{
-		LLTextureEntry* tep = getTE(te);
-		LLMaterial* mat = NULL;
-		if (tep)
-		{
-			mat = tep->getMaterialParams();
-		}
-
-		if (mat)
-		{
-			mat->setSpecularID(uuid);
-		}		
-	}
-	changeTESpecularMap(te, image);
-	return retval;
+    S32 retval = TEM_CHANGE_TEXTURE;
+    const LLUUID& uuid = image ? image->getID() : LLUUID::null;
+    if (uuid != getTE(te)->getID() ||
+        uuid == LLUUID::null)
+    {
+        LLTextureEntry* tep = getTE(te);
+        LLMaterial* mat = NULL;
+        if (tep)
+        {
+            mat = tep->getMaterialParams();
+        }
+
+        if (mat)
+        {
+            mat->setSpecularID(uuid);
+        }
+    }
+    changeTESpecularMap(te, image);
+    return retval;
 }
 
 //virtual
-void LLViewerObject::changeTEImage(S32 index, LLViewerTexture* new_image) 
+void LLViewerObject::changeTEImage(S32 index, LLViewerTexture* new_image)
 {
-	if(index < 0 || index >= getNumTEs())
-	{
-		return ;
-	}
-	mTEImages[index] = new_image ;
+    if(index < 0 || index >= getNumTEs())
+    {
+        return ;
+    }
+    mTEImages[index] = new_image ;
 }
 
 void LLViewerObject::changeTENormalMap(S32 index, LLViewerTexture* new_image)
 {
-	if(index < 0 || index >= getNumTEs())
-	{
-		return ;
-	}
-	mTENormalMaps[index] = new_image ;
-	refreshMaterials();
+    if(index < 0 || index >= getNumTEs())
+    {
+        return ;
+    }
+    mTENormalMaps[index] = new_image ;
+    refreshMaterials();
 }
 
 void LLViewerObject::changeTESpecularMap(S32 index, LLViewerTexture* new_image)
 {
-	if(index < 0 || index >= getNumTEs())
-	{
-		return ;
-	}
-	mTESpecularMaps[index] = new_image ;
-	refreshMaterials();
+    if(index < 0 || index >= getNumTEs())
+    {
+        return ;
+    }
+    mTESpecularMaps[index] = new_image ;
+    refreshMaterials();
 }
 
 S32 LLViewerObject::setTETexture(const U8 te, const LLUUID& uuid)
 {
-	// Invalid host == get from the agent's sim
-	LLViewerFetchedTexture *image = LLViewerTextureManager::getFetchedTexture(
-		uuid, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, LLHost());
-		return setTETextureCore(te, image);
+    // Invalid host == get from the agent's sim
+    LLViewerFetchedTexture *image = LLViewerTextureManager::getFetchedTexture(
+        uuid, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, LLHost());
+        return setTETextureCore(te, image);
 }
 
 S32 LLViewerObject::setTENormalMap(const U8 te, const LLUUID& uuid)
 {
-	LLViewerFetchedTexture *image = (uuid.isNull()) ? NULL : LLViewerTextureManager::getFetchedTexture(
-		uuid, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, LLHost());
-	return setTENormalMapCore(te, image);
+    LLViewerFetchedTexture *image = (uuid.isNull()) ? NULL : LLViewerTextureManager::getFetchedTexture(
+        uuid, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, LLHost());
+    return setTENormalMapCore(te, image);
 }
 
 S32 LLViewerObject::setTESpecularMap(const U8 te, const LLUUID& uuid)
 {
-	LLViewerFetchedTexture *image = (uuid.isNull()) ? NULL : LLViewerTextureManager::getFetchedTexture(
-		uuid, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, LLHost());
-	return setTESpecularMapCore(te, image);
+    LLViewerFetchedTexture *image = (uuid.isNull()) ? NULL : LLViewerTextureManager::getFetchedTexture(
+        uuid, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, LLHost());
+    return setTESpecularMapCore(te, image);
 }
 
 S32 LLViewerObject::setTEColor(const U8 te, const LLColor3& color)
 {
-	return setTEColor(te, LLColor4(color));
+    return setTEColor(te, LLColor4(color));
 }
 
 S32 LLViewerObject::setTEColor(const U8 te, const LLColor4& color)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-	}
-	else if (color != tep->getColor())
-	{
-		retval = LLPrimitive::setTEColor(te, color);
-		if (mDrawable.notNull() && retval)
-		{
-			// These should only happen on updates which are not the initial update.
-			dirtyMesh();
-		}
-	}
-	return retval;
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+    }
+    else if (color != tep->getColor())
+    {
+        retval = LLPrimitive::setTEColor(te, color);
+        if (mDrawable.notNull() && retval)
+        {
+            // These should only happen on updates which are not the initial update.
+            dirtyMesh();
+        }
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEBumpmap(const U8 te, const U8 bump)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-	}
-	else if (bump != tep->getBumpmap())
-	{
-		retval = LLPrimitive::setTEBumpmap(te, bump);
-		setChanged(TEXTURE);
-		if (mDrawable.notNull() && retval)
-		{
-			gPipeline.markTextured(mDrawable);
-			gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
-		}
-	}
-	return retval;
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+    }
+    else if (bump != tep->getBumpmap())
+    {
+        retval = LLPrimitive::setTEBumpmap(te, bump);
+        setChanged(TEXTURE);
+        if (mDrawable.notNull() && retval)
+        {
+            gPipeline.markTextured(mDrawable);
+            gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
+        }
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTETexGen(const U8 te, const U8 texgen)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-	}
-	else if (texgen != tep->getTexGen())
-	{
-		retval = LLPrimitive::setTETexGen(te, texgen);
-		setChanged(TEXTURE);
-	}
-	return retval;
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+    }
+    else if (texgen != tep->getTexGen())
+    {
+        retval = LLPrimitive::setTETexGen(te, texgen);
+        setChanged(TEXTURE);
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEMediaTexGen(const U8 te, const U8 media)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-	}
-	else if (media != tep->getMediaTexGen())
-	{
-		retval = LLPrimitive::setTEMediaTexGen(te, media);
-		setChanged(TEXTURE);
-	}
-	return retval;
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+    }
+    else if (media != tep->getMediaTexGen())
+    {
+        retval = LLPrimitive::setTEMediaTexGen(te, media);
+        setChanged(TEXTURE);
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEShiny(const U8 te, const U8 shiny)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-	}
-	else if (shiny != tep->getShiny())
-	{
-		retval = LLPrimitive::setTEShiny(te, shiny);
-		setChanged(TEXTURE);
-	}
-	return retval;
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+    }
+    else if (shiny != tep->getShiny())
+    {
+        retval = LLPrimitive::setTEShiny(te, shiny);
+        setChanged(TEXTURE);
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEFullbright(const U8 te, const U8 fullbright)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-	}
-	else if (fullbright != tep->getFullbright())
-	{
-		retval = LLPrimitive::setTEFullbright(te, fullbright);
-		setChanged(TEXTURE);
-		if (mDrawable.notNull() && retval)
-		{
-			gPipeline.markTextured(mDrawable);
-		}
-	}
-	return retval;
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+    }
+    else if (fullbright != tep->getFullbright())
+    {
+        retval = LLPrimitive::setTEFullbright(te, fullbright);
+        setChanged(TEXTURE);
+        if (mDrawable.notNull() && retval)
+        {
+            gPipeline.markTextured(mDrawable);
+        }
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEMediaFlags(const U8 te, const U8 media_flags)
 {
-	// this might need work for media type
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-	}
-	else if (media_flags != tep->getMediaFlags())
-	{
-		retval = LLPrimitive::setTEMediaFlags(te, media_flags);
-		setChanged(TEXTURE);
-		if (mDrawable.notNull() && retval)
-		{
-			gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
-			gPipeline.markTextured(mDrawable);
-		}
-	}
-	return retval;
+    // this might need work for media type
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+    }
+    else if (media_flags != tep->getMediaFlags())
+    {
+        retval = LLPrimitive::setTEMediaFlags(te, media_flags);
+        setChanged(TEXTURE);
+        if (mDrawable.notNull() && retval)
+        {
+            gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
+            gPipeline.markTextured(mDrawable);
+        }
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEGlow(const U8 te, const F32 glow)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-	}
-	else if (glow != tep->getGlow())
-	{
-		retval = LLPrimitive::setTEGlow(te, glow);
-		setChanged(TEXTURE);
-		if (mDrawable.notNull() && retval)
-		{
-			gPipeline.markTextured(mDrawable);
-		}
-	}
-	return retval;
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+    }
+    else if (glow != tep->getGlow())
+    {
+        retval = LLPrimitive::setTEGlow(te, glow);
+        setChanged(TEXTURE);
+        if (mDrawable.notNull() && retval)
+        {
+            gPipeline.markTextured(mDrawable);
+        }
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS("Material") << "No texture entry for te " << (S32)te
-							 << ", object " << mID
-							 << ", material " << pMaterialID
-							 << LL_ENDL;
-	}
-	//else if (pMaterialID != tep->getMaterialID())
-	{
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS("Material") << "No texture entry for te " << (S32)te
+                             << ", object " << mID
+                             << ", material " << pMaterialID
+                             << LL_ENDL;
+    }
+    //else if (pMaterialID != tep->getMaterialID())
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("Material") << "Changing texture entry for te " << (S32)te
-							 << ", object " << mID
-							 << ", material " << pMaterialID
-							 << LL_ENDL;
+        LL_DEBUGS("Material") << "Changing texture entry for te " << (S32)te
+                             << ", object " << mID
+                             << ", material " << pMaterialID
+                             << LL_ENDL;
 #endif
-		retval = LLPrimitive::setTEMaterialID(te, pMaterialID);
-		refreshMaterials();
-	}
-	return retval;
+        retval = LLPrimitive::setTEMaterialID(te, pMaterialID);
+        refreshMaterials();
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-		return 0;
-	}
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS() << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+        return 0;
+    }
 
-	retval = LLPrimitive::setTEMaterialParams(te, pMaterialParams);
+    retval = LLPrimitive::setTEMaterialParams(te, pMaterialParams);
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Material") << "Changing material params for te " << (S32)te
-							<< ", object " << mID
-			               << " (" << retval << ")"
-							<< LL_ENDL;
+    LL_DEBUGS("Material") << "Changing material params for te " << (S32)te
+                            << ", object " << mID
+                           << " (" << retval << ")"
+                            << LL_ENDL;
 #endif
-	setTENormalMap(te, (pMaterialParams) ? pMaterialParams->getNormalID() : LLUUID::null);
-	setTESpecularMap(te, (pMaterialParams) ? pMaterialParams->getSpecularID() : LLUUID::null);
+    setTENormalMap(te, (pMaterialParams) ? pMaterialParams->getNormalID() : LLUUID::null);
+    setTESpecularMap(te, (pMaterialParams) ? pMaterialParams->getSpecularID() : LLUUID::null);
 
-	return retval;
+    return retval;
 }
 
 S32 LLViewerObject::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* override_mat)
@@ -5725,287 +5725,287 @@ S32 LLViewerObject::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* override_ma
 
 void LLViewerObject::refreshMaterials()
 {
-	setChanged(TEXTURE);
-	if (mDrawable.notNull())
-	{
-		gPipeline.markTextured(mDrawable);
-	}
+    setChanged(TEXTURE);
+    if (mDrawable.notNull())
+    {
+        gPipeline.markTextured(mDrawable);
+    }
 }
 
 S32 LLViewerObject::setTEScale(const U8 te, const F32 s, const F32 t)
 {
-	S32 retval = 0;
-	retval = LLPrimitive::setTEScale(te, s, t);
-	setChanged(TEXTURE);
-	if (mDrawable.notNull() && retval)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
-	}
-	return retval;
+    S32 retval = 0;
+    retval = LLPrimitive::setTEScale(te, s, t);
+    setChanged(TEXTURE);
+    if (mDrawable.notNull() && retval)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEScaleS(const U8 te, const F32 s)
 {
-	S32 retval = LLPrimitive::setTEScaleS(te, s);
-	if (mDrawable.notNull() && retval)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
-	}
+    S32 retval = LLPrimitive::setTEScaleS(te, s);
+    if (mDrawable.notNull() && retval)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
+    }
 
-	return retval;
+    return retval;
 }
 
 S32 LLViewerObject::setTEScaleT(const U8 te, const F32 t)
 {
-	S32 retval = LLPrimitive::setTEScaleT(te, t);
-	if (mDrawable.notNull() && retval)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
-	}
+    S32 retval = LLPrimitive::setTEScaleT(te, t);
+    if (mDrawable.notNull() && retval)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
+    }
 
-	return retval;
+    return retval;
 }
 
 S32 LLViewerObject::setTEOffset(const U8 te, const F32 s, const F32 t)
 {
-	S32 retval = LLPrimitive::setTEOffset(te, s, t);
-	if (mDrawable.notNull() && retval)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
-	}
-	return retval;
+    S32 retval = LLPrimitive::setTEOffset(te, s, t);
+    if (mDrawable.notNull() && retval)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
+    }
+    return retval;
 }
 
 S32 LLViewerObject::setTEOffsetS(const U8 te, const F32 s)
 {
-	S32 retval = LLPrimitive::setTEOffsetS(te, s);
-	if (mDrawable.notNull() && retval)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
-	}
+    S32 retval = LLPrimitive::setTEOffsetS(te, s);
+    if (mDrawable.notNull() && retval)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
+    }
 
-	return retval;
+    return retval;
 }
 
 S32 LLViewerObject::setTEOffsetT(const U8 te, const F32 t)
 {
-	S32 retval = LLPrimitive::setTEOffsetT(te, t);
-	if (mDrawable.notNull() && retval)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
-	}
+    S32 retval = LLPrimitive::setTEOffsetT(te, t);
+    if (mDrawable.notNull() && retval)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
+    }
 
-	return retval;
+    return retval;
 }
 
 S32 LLViewerObject::setTERotation(const U8 te, const F32 r)
 {
-	S32 retval = LLPrimitive::setTERotation(te, r);
-	if (mDrawable.notNull() && retval)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
+    S32 retval = LLPrimitive::setTERotation(te, r);
+    if (mDrawable.notNull() && retval)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
         shrinkWrap();
-	}
-	return retval;
+    }
+    return retval;
 }
 
 
 LLViewerTexture *LLViewerObject::getTEImage(const U8 face) const
 {
-//	llassert(mTEImages);
+//  llassert(mTEImages);
 
-	if (face < getNumTEs())
-	{
-		LLViewerTexture* image = mTEImages[face];
-		if (image)
-		{
-			return image;
-		}
-		else
-		{
-			return (LLViewerTexture*)(LLViewerFetchedTexture::sDefaultImagep);
-		}
-	}
+    if (face < getNumTEs())
+    {
+        LLViewerTexture* image = mTEImages[face];
+        if (image)
+        {
+            return image;
+        }
+        else
+        {
+            return (LLViewerTexture*)(LLViewerFetchedTexture::sDefaultImagep);
+        }
+    }
 
-	LL_ERRS() << "Requested Image from invalid face: " << face <<"/" << getNumTEs() << LL_ENDL;
+    LL_ERRS() << "Requested Image from invalid face: " << face <<"/" << getNumTEs() << LL_ENDL;
 
-	return NULL;
+    return NULL;
 }
 
 
 bool LLViewerObject::isImageAlphaBlended(const U8 te) const
 {
-	LLViewerTexture* image = getTEImage(te);
-	LLGLenum format = image ? image->getPrimaryFormat() : GL_RGB;
-	switch (format)
-	{
-		case GL_RGBA:
-		case GL_ALPHA:
-		{
-			return true;
-		}
-		break;
+    LLViewerTexture* image = getTEImage(te);
+    LLGLenum format = image ? image->getPrimaryFormat() : GL_RGB;
+    switch (format)
+    {
+        case GL_RGBA:
+        case GL_ALPHA:
+        {
+            return true;
+        }
+        break;
 
-		case GL_RGB: break;
-		default:
-		{
-			LL_WARNS() << "Unexpected tex format in LLViewerObject::isImageAlphaBlended...returning no alpha." << LL_ENDL;
-		}
-		break;
-	}
+        case GL_RGB: break;
+        default:
+        {
+            LL_WARNS() << "Unexpected tex format in LLViewerObject::isImageAlphaBlended...returning no alpha." << LL_ENDL;
+        }
+        break;
+    }
 
-	return false;
+    return false;
 }
 
 LLViewerTexture *LLViewerObject::getTENormalMap(const U8 face) const
 {
-	//	llassert(mTEImages);
-	
-	if (face < getNumTEs())
-	{
-		LLViewerTexture* image = mTENormalMaps[face];
-		if (image)
-		{
-			return image;
-		}
-		else
-		{
-			return (LLViewerTexture*)(LLViewerFetchedTexture::sDefaultImagep);
-		}
-	}
-	
-	LL_ERRS() << llformat("Requested Image from invalid face: %d/%d",face,getNumTEs()) << LL_ENDL;
-	
-	return NULL;
+    //  llassert(mTEImages);
+
+    if (face < getNumTEs())
+    {
+        LLViewerTexture* image = mTENormalMaps[face];
+        if (image)
+        {
+            return image;
+        }
+        else
+        {
+            return (LLViewerTexture*)(LLViewerFetchedTexture::sDefaultImagep);
+        }
+    }
+
+    LL_ERRS() << llformat("Requested Image from invalid face: %d/%d",face,getNumTEs()) << LL_ENDL;
+
+    return NULL;
 }
 
 LLViewerTexture *LLViewerObject::getTESpecularMap(const U8 face) const
 {
-	//	llassert(mTEImages);
-	
-	if (face < getNumTEs())
-	{
-		LLViewerTexture* image = mTESpecularMaps[face];
-		if (image)
-		{
-			return image;
-		}
-		else
-		{
-			return (LLViewerTexture*)(LLViewerFetchedTexture::sDefaultImagep);
-		}
-	}
-	
-	LL_ERRS() << llformat("Requested Image from invalid face: %d/%d",face,getNumTEs()) << LL_ENDL;
-	
-	return NULL;
+    //  llassert(mTEImages);
+
+    if (face < getNumTEs())
+    {
+        LLViewerTexture* image = mTESpecularMaps[face];
+        if (image)
+        {
+            return image;
+        }
+        else
+        {
+            return (LLViewerTexture*)(LLViewerFetchedTexture::sDefaultImagep);
+        }
+    }
+
+    LL_ERRS() << llformat("Requested Image from invalid face: %d/%d",face,getNumTEs()) << LL_ENDL;
+
+    return NULL;
 }
 
 void LLViewerObject::fitFaceTexture(const U8 face)
 {
-	LL_INFOS() << "fitFaceTexture not implemented" << LL_ENDL;
+    LL_INFOS() << "fitFaceTexture not implemented" << LL_ENDL;
 }
 
 LLBBox LLViewerObject::getBoundingBoxAgent() const
 {
-	LLVector3 position_agent;
-	LLQuaternion rot;
-	LLViewerObject* avatar_parent = NULL;
-	LLViewerObject* root_edit = (LLViewerObject*)getRootEdit();
-	if (root_edit)
-	{
-		avatar_parent = (LLViewerObject*)root_edit->getParent();
-	}
-	
-	if (avatar_parent && avatar_parent->isAvatar() &&
-		root_edit && root_edit->mDrawable.notNull() && root_edit->mDrawable->getXform()->getParent())
-	{
-		LLXform* parent_xform = root_edit->mDrawable->getXform()->getParent();
-		position_agent = (getPositionEdit() * parent_xform->getWorldRotation()) + parent_xform->getWorldPosition();
-		rot = getRotationEdit() * parent_xform->getWorldRotation();
-	}
-	else
-	{
-		position_agent = getPositionAgent();
-		rot = getRotationRegion();
-	}
-	
-	return LLBBox( position_agent, rot, getScale() * -0.5f, getScale() * 0.5f );
+    LLVector3 position_agent;
+    LLQuaternion rot;
+    LLViewerObject* avatar_parent = NULL;
+    LLViewerObject* root_edit = (LLViewerObject*)getRootEdit();
+    if (root_edit)
+    {
+        avatar_parent = (LLViewerObject*)root_edit->getParent();
+    }
+
+    if (avatar_parent && avatar_parent->isAvatar() &&
+        root_edit && root_edit->mDrawable.notNull() && root_edit->mDrawable->getXform()->getParent())
+    {
+        LLXform* parent_xform = root_edit->mDrawable->getXform()->getParent();
+        position_agent = (getPositionEdit() * parent_xform->getWorldRotation()) + parent_xform->getWorldPosition();
+        rot = getRotationEdit() * parent_xform->getWorldRotation();
+    }
+    else
+    {
+        position_agent = getPositionAgent();
+        rot = getRotationRegion();
+    }
+
+    return LLBBox( position_agent, rot, getScale() * -0.5f, getScale() * 0.5f );
 }
 
 U32 LLViewerObject::getNumVertices() const
 {
-	U32 num_vertices = 0;
-	if (mDrawable.notNull())
-	{
-		S32 i, num_faces;
-		num_faces = mDrawable->getNumFaces();
-		for (i = 0; i < num_faces; i++)
-		{
-			LLFace * facep = mDrawable->getFace(i);
-			if (facep)
-			{
-				num_vertices += facep->getGeomCount();
-			}
-		}
-	}
-	return num_vertices;
+    U32 num_vertices = 0;
+    if (mDrawable.notNull())
+    {
+        S32 i, num_faces;
+        num_faces = mDrawable->getNumFaces();
+        for (i = 0; i < num_faces; i++)
+        {
+            LLFace * facep = mDrawable->getFace(i);
+            if (facep)
+            {
+                num_vertices += facep->getGeomCount();
+            }
+        }
+    }
+    return num_vertices;
 }
 
 U32 LLViewerObject::getNumIndices() const
 {
-	U32 num_indices = 0;
-	if (mDrawable.notNull())
-	{
-		S32 i, num_faces;
-		num_faces = mDrawable->getNumFaces();
-		for (i = 0; i < num_faces; i++)
-		{
-			LLFace * facep = mDrawable->getFace(i);
-			if (facep)
-			{
-				num_indices += facep->getIndicesCount();
-			}
-		}
-	}
-	return num_indices;
+    U32 num_indices = 0;
+    if (mDrawable.notNull())
+    {
+        S32 i, num_faces;
+        num_faces = mDrawable->getNumFaces();
+        for (i = 0; i < num_faces; i++)
+        {
+            LLFace * facep = mDrawable->getFace(i);
+            if (facep)
+            {
+                num_indices += facep->getIndicesCount();
+            }
+        }
+    }
+    return num_indices;
 }
 
 // Find the number of instances of this object's inventory that are of the given type
 S32 LLViewerObject::countInventoryContents(LLAssetType::EType type)
 {
-	S32 count = 0;
-	if( mInventory )
-	{
-		LLInventoryObject::object_list_t::const_iterator it = mInventory->begin();
-		LLInventoryObject::object_list_t::const_iterator end = mInventory->end();
-		for(  ; it != end ; ++it )
-		{
-			if( (*it)->getType() == type )
-			{
-				++count;
-			}
-		}
-	}
-	return count;
+    S32 count = 0;
+    if( mInventory )
+    {
+        LLInventoryObject::object_list_t::const_iterator it = mInventory->begin();
+        LLInventoryObject::object_list_t::const_iterator end = mInventory->end();
+        for(  ; it != end ; ++it )
+        {
+            if( (*it)->getType() == type )
+            {
+                ++count;
+            }
+        }
+    }
+    return count;
 }
 
 void LLViewerObject::setDebugText(const std::string &utf8text, const LLColor4& color)
 {
-	if (utf8text.empty() && !mText)
-	{
-		return;
-	}
+    if (utf8text.empty() && !mText)
+    {
+        return;
+    }
 
-	if (!mText)
-	{
-	    initHudText();
-	}
-	mText->setColor(color);
-	mText->setString(utf8text);
-	mText->setZCompare(FALSE);
-	mText->setDoFade(FALSE);
-	updateText();
+    if (!mText)
+    {
+        initHudText();
+    }
+    mText->setColor(color);
+    mText->setString(utf8text);
+    mText->setZCompare(FALSE);
+    mText->setDoFade(FALSE);
+    updateText();
 }
 
 void LLViewerObject::appendDebugText(const std::string &utf8text)
@@ -6064,105 +6064,105 @@ void LLViewerObject::restoreHudText()
 
 void LLViewerObject::setIcon(LLViewerTexture* icon_image)
 {
-	if (!mIcon)
-	{
-		mIcon = (LLHUDIcon *)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_ICON);
-		mIcon->setSourceObject(this);
-		mIcon->setImage(icon_image);
-		// *TODO: make this user configurable
-		mIcon->setScale(0.03f);
-	}
-	else
-	{
-		mIcon->restartLifeTimer();
-	}
+    if (!mIcon)
+    {
+        mIcon = (LLHUDIcon *)LLHUDObject::addHUDObject(LLHUDObject::LL_HUD_ICON);
+        mIcon->setSourceObject(this);
+        mIcon->setImage(icon_image);
+        // *TODO: make this user configurable
+        mIcon->setScale(0.03f);
+    }
+    else
+    {
+        mIcon->restartLifeTimer();
+    }
 }
 
 void LLViewerObject::clearIcon()
 {
-	if (mIcon)
-	{
-		mIcon = NULL;
-	}
+    if (mIcon)
+    {
+        mIcon = NULL;
+    }
 }
 
-LLViewerObject* LLViewerObject::getSubParent() 
-{ 
-	return (LLViewerObject*) getParent();
+LLViewerObject* LLViewerObject::getSubParent()
+{
+    return (LLViewerObject*) getParent();
 }
 
 const LLViewerObject* LLViewerObject::getSubParent() const
 {
-	return (const LLViewerObject*) getParent();
+    return (const LLViewerObject*) getParent();
 }
 
 BOOL LLViewerObject::isOnMap()
 {
-	return mOnMap;
+    return mOnMap;
 }
 
 
 void LLViewerObject::updateText()
 {
-	if (!isDead())
-	{
-		if (mText.notNull())
-		{		
-		    LLVOAvatar* avatar = getAvatar();
-		    if (avatar)
-		    {
-		        mText->setHidden(avatar->isInMuteList());
-		    }
-
-		    LLVector3 up_offset(0,0,0);
-			up_offset.mV[2] = getScale().mV[VZ]*0.6f;
-			
-			if (mDrawable.notNull())
-			{
-				mText->setPositionAgent(getRenderPosition() + up_offset);
-			}
-			else
-			{
-				mText->setPositionAgent(getPositionAgent() + up_offset);
-			}
-		}
-	}
+    if (!isDead())
+    {
+        if (mText.notNull())
+        {
+            LLVOAvatar* avatar = getAvatar();
+            if (avatar)
+            {
+                mText->setHidden(avatar->isInMuteList());
+            }
+
+            LLVector3 up_offset(0,0,0);
+            up_offset.mV[2] = getScale().mV[VZ]*0.6f;
+
+            if (mDrawable.notNull())
+            {
+                mText->setPositionAgent(getRenderPosition() + up_offset);
+            }
+            else
+            {
+                mText->setPositionAgent(getPositionAgent() + up_offset);
+            }
+        }
+    }
 }
 
 bool LLViewerObject::isOwnerInMuteList(LLUUID id)
 {
-	LLUUID owner_id = id.isNull() ? mOwnerID : id;
-	if (isAvatar() || owner_id.isNull())
-	{
-		return false;
-	}
-	bool muted = false;
-	F64 now = LLFrameTimer::getTotalSeconds();
-	if (now < mCachedMuteListUpdateTime)
-	{
-		muted = mCachedOwnerInMuteList;
-	}
-	else
-	{
-		muted = LLMuteList::getInstance()->isMuted(owner_id);
-
-		const F64 SECONDS_BETWEEN_MUTE_UPDATES = 1;
-		mCachedMuteListUpdateTime = now + SECONDS_BETWEEN_MUTE_UPDATES;
-		mCachedOwnerInMuteList = muted;
-	}
-	return muted;
-}
-
-// virtual 
+    LLUUID owner_id = id.isNull() ? mOwnerID : id;
+    if (isAvatar() || owner_id.isNull())
+    {
+        return false;
+    }
+    bool muted = false;
+    F64 now = LLFrameTimer::getTotalSeconds();
+    if (now < mCachedMuteListUpdateTime)
+    {
+        muted = mCachedOwnerInMuteList;
+    }
+    else
+    {
+        muted = LLMuteList::getInstance()->isMuted(owner_id);
+
+        const F64 SECONDS_BETWEEN_MUTE_UPDATES = 1;
+        mCachedMuteListUpdateTime = now + SECONDS_BETWEEN_MUTE_UPDATES;
+        mCachedOwnerInMuteList = muted;
+    }
+    return muted;
+}
+
+// virtual
 LLVOAvatar* LLViewerObject::asAvatar()
 {
-	return NULL;
+    return NULL;
 }
 
-// virtual 
+// virtual
 LLVOVolume* LLViewerObject::asVolume()
 {
-	return nullptr;
+    return nullptr;
 }
 
 // If this object is directly or indirectly parented by an avatar,
@@ -6174,418 +6174,418 @@ LLVOVolume* LLViewerObject::asVolume()
 // attached.
 LLVOAvatar* LLViewerObject::getAvatarAncestor()
 {
-	LLViewerObject *pobj = (LLViewerObject*) getParent();
-	while (pobj)
-	{
-		LLVOAvatar *av = pobj->asAvatar();
-		if (av)
-		{
-			return av;
-		}
-		pobj =  (LLViewerObject*) pobj->getParent();
-	}
-	return NULL;
+    LLViewerObject *pobj = (LLViewerObject*) getParent();
+    while (pobj)
+    {
+        LLVOAvatar *av = pobj->asAvatar();
+        if (av)
+        {
+            return av;
+        }
+        pobj =  (LLViewerObject*) pobj->getParent();
+    }
+    return NULL;
 }
 
 BOOL LLViewerObject::isParticleSource() const
 {
-	return !mPartSourcep.isNull() && !mPartSourcep->isDead();
+    return !mPartSourcep.isNull() && !mPartSourcep->isDead();
 }
 
 void LLViewerObject::setParticleSource(const LLPartSysData& particle_parameters, const LLUUID& owner_id)
 {
-	if (mPartSourcep)
-	{
-		deleteParticleSource();
-	}
-
-	LLPointer<LLViewerPartSourceScript> pss = LLViewerPartSourceScript::createPSS(this, particle_parameters);
-	mPartSourcep = pss;
-	
-	if (mPartSourcep)
-	{
-		mPartSourcep->setOwnerUUID(owner_id);
-
-		if (mPartSourcep->getImage()->getID() != mPartSourcep->mPartSysData.mPartImageID)
-		{
-			LLViewerTexture* image;
-			if (mPartSourcep->mPartSysData.mPartImageID.isNull())
-			{
-				image = LLViewerFetchedTexture::sPixieSmallImagep;
-			}
-			else
-			{
-				image = LLViewerTextureManager::getFetchedTexture(mPartSourcep->mPartSysData.mPartImageID);
-			}
-			mPartSourcep->setImage(image);
-		}
-	}
-	LLViewerPartSim::getInstance()->addPartSource(pss);
+    if (mPartSourcep)
+    {
+        deleteParticleSource();
+    }
+
+    LLPointer<LLViewerPartSourceScript> pss = LLViewerPartSourceScript::createPSS(this, particle_parameters);
+    mPartSourcep = pss;
+
+    if (mPartSourcep)
+    {
+        mPartSourcep->setOwnerUUID(owner_id);
+
+        if (mPartSourcep->getImage()->getID() != mPartSourcep->mPartSysData.mPartImageID)
+        {
+            LLViewerTexture* image;
+            if (mPartSourcep->mPartSysData.mPartImageID.isNull())
+            {
+                image = LLViewerFetchedTexture::sPixieSmallImagep;
+            }
+            else
+            {
+                image = LLViewerTextureManager::getFetchedTexture(mPartSourcep->mPartSysData.mPartImageID);
+            }
+            mPartSourcep->setImage(image);
+        }
+    }
+    LLViewerPartSim::getInstance()->addPartSource(pss);
 }
 
 void LLViewerObject::unpackParticleSource(const S32 block_num, const LLUUID& owner_id)
 {
-	if (!mPartSourcep.isNull() && mPartSourcep->isDead())
-	{
-		mPartSourcep = NULL;
-	}
-	if (mPartSourcep)
-	{
-		// If we've got one already, just update the existing source (or remove it)
-		if (!LLViewerPartSourceScript::unpackPSS(this, mPartSourcep, block_num))
-		{
-			mPartSourcep->setDead();
-			mPartSourcep = NULL;
-		}
-	}
-	else
-	{
-		LLPointer<LLViewerPartSourceScript> pss = LLViewerPartSourceScript::unpackPSS(this, NULL, block_num);
-		//If the owner is muted, don't create the system
-		if(LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagParticles)) return;
-
-		// We need to be able to deal with a particle source that hasn't changed, but still got an update!
-		if (pss)
-		{
-// 			LL_INFOS() << "Making particle system with owner " << owner_id << LL_ENDL;
-			pss->setOwnerUUID(owner_id);
-			mPartSourcep = pss;
-			LLViewerPartSim::getInstance()->addPartSource(pss);
-		}
-	}
-	if (mPartSourcep)
-	{
-		if (mPartSourcep->getImage()->getID() != mPartSourcep->mPartSysData.mPartImageID)
-		{
-			LLViewerTexture* image;
-			if (mPartSourcep->mPartSysData.mPartImageID.isNull())
-			{
-				image = LLViewerFetchedTexture::sPixieSmallImagep;
-			}
-			else
-			{
-				image = LLViewerTextureManager::getFetchedTexture(mPartSourcep->mPartSysData.mPartImageID);
-			}
-			mPartSourcep->setImage(image);
-		}
-	}
+    if (!mPartSourcep.isNull() && mPartSourcep->isDead())
+    {
+        mPartSourcep = NULL;
+    }
+    if (mPartSourcep)
+    {
+        // If we've got one already, just update the existing source (or remove it)
+        if (!LLViewerPartSourceScript::unpackPSS(this, mPartSourcep, block_num))
+        {
+            mPartSourcep->setDead();
+            mPartSourcep = NULL;
+        }
+    }
+    else
+    {
+        LLPointer<LLViewerPartSourceScript> pss = LLViewerPartSourceScript::unpackPSS(this, NULL, block_num);
+        //If the owner is muted, don't create the system
+        if(LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagParticles)) return;
+
+        // We need to be able to deal with a particle source that hasn't changed, but still got an update!
+        if (pss)
+        {
+//          LL_INFOS() << "Making particle system with owner " << owner_id << LL_ENDL;
+            pss->setOwnerUUID(owner_id);
+            mPartSourcep = pss;
+            LLViewerPartSim::getInstance()->addPartSource(pss);
+        }
+    }
+    if (mPartSourcep)
+    {
+        if (mPartSourcep->getImage()->getID() != mPartSourcep->mPartSysData.mPartImageID)
+        {
+            LLViewerTexture* image;
+            if (mPartSourcep->mPartSysData.mPartImageID.isNull())
+            {
+                image = LLViewerFetchedTexture::sPixieSmallImagep;
+            }
+            else
+            {
+                image = LLViewerTextureManager::getFetchedTexture(mPartSourcep->mPartSysData.mPartImageID);
+            }
+            mPartSourcep->setImage(image);
+        }
+    }
 }
 
 void LLViewerObject::unpackParticleSource(LLDataPacker &dp, const LLUUID& owner_id, bool legacy)
 {
-	if (!mPartSourcep.isNull() && mPartSourcep->isDead())
-	{
-		mPartSourcep = NULL;
-	}
-	if (mPartSourcep)
-	{
-		// If we've got one already, just update the existing source (or remove it)
-		if (!LLViewerPartSourceScript::unpackPSS(this, mPartSourcep, dp, legacy))
-		{
-			mPartSourcep->setDead();
-			mPartSourcep = NULL;
-		}
-	}
-	else
-	{
-		LLPointer<LLViewerPartSourceScript> pss = LLViewerPartSourceScript::unpackPSS(this, NULL, dp, legacy);
-		//If the owner is muted, don't create the system
-		if(LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagParticles)) return;
-		// We need to be able to deal with a particle source that hasn't changed, but still got an update!
-		if (pss)
-		{
-// 			LL_INFOS() << "Making particle system with owner " << owner_id << LL_ENDL;
-			pss->setOwnerUUID(owner_id);
-			mPartSourcep = pss;
-			LLViewerPartSim::getInstance()->addPartSource(pss);
-		}
-	}
-	if (mPartSourcep)
-	{
-		if (mPartSourcep->getImage()->getID() != mPartSourcep->mPartSysData.mPartImageID)
-		{
-			LLViewerTexture* image;
-			if (mPartSourcep->mPartSysData.mPartImageID.isNull())
-			{
-				image = LLViewerFetchedTexture::sPixieSmallImagep;
-			}
-			else
-			{
-				image = LLViewerTextureManager::getFetchedTexture(mPartSourcep->mPartSysData.mPartImageID);
-			}
-			mPartSourcep->setImage(image);
-		}
-	}
+    if (!mPartSourcep.isNull() && mPartSourcep->isDead())
+    {
+        mPartSourcep = NULL;
+    }
+    if (mPartSourcep)
+    {
+        // If we've got one already, just update the existing source (or remove it)
+        if (!LLViewerPartSourceScript::unpackPSS(this, mPartSourcep, dp, legacy))
+        {
+            mPartSourcep->setDead();
+            mPartSourcep = NULL;
+        }
+    }
+    else
+    {
+        LLPointer<LLViewerPartSourceScript> pss = LLViewerPartSourceScript::unpackPSS(this, NULL, dp, legacy);
+        //If the owner is muted, don't create the system
+        if(LLMuteList::getInstance()->isMuted(owner_id, LLMute::flagParticles)) return;
+        // We need to be able to deal with a particle source that hasn't changed, but still got an update!
+        if (pss)
+        {
+//          LL_INFOS() << "Making particle system with owner " << owner_id << LL_ENDL;
+            pss->setOwnerUUID(owner_id);
+            mPartSourcep = pss;
+            LLViewerPartSim::getInstance()->addPartSource(pss);
+        }
+    }
+    if (mPartSourcep)
+    {
+        if (mPartSourcep->getImage()->getID() != mPartSourcep->mPartSysData.mPartImageID)
+        {
+            LLViewerTexture* image;
+            if (mPartSourcep->mPartSysData.mPartImageID.isNull())
+            {
+                image = LLViewerFetchedTexture::sPixieSmallImagep;
+            }
+            else
+            {
+                image = LLViewerTextureManager::getFetchedTexture(mPartSourcep->mPartSysData.mPartImageID);
+            }
+            mPartSourcep->setImage(image);
+        }
+    }
 }
 
 void LLViewerObject::deleteParticleSource()
 {
-	if (mPartSourcep.notNull())
-	{
-		mPartSourcep->setDead();
-		mPartSourcep = NULL;
-	}
+    if (mPartSourcep.notNull())
+    {
+        mPartSourcep->setDead();
+        mPartSourcep = NULL;
+    }
 }
 
 // virtual
 void LLViewerObject::updateDrawable(BOOL force_damped)
 {
-	if (!isChanged(MOVED))
-	{ //most common case, having an empty if case here makes for better branch prediction
-	}
-	else if (mDrawable.notNull() && 
-		!mDrawable->isState(LLDrawable::ON_MOVE_LIST))
-	{
-		BOOL damped_motion = 
-			!isChanged(SHIFTED) &&										// not shifted between regions this frame and...
-			(	force_damped ||										// ...forced into damped motion by application logic or...
-				(	!isSelected() &&									// ...not selected and...
-					(	mDrawable->isRoot() ||								// ... is root or ...
-						(getParent() && !((LLViewerObject*)getParent())->isSelected())// ... parent is not selected and ...
-					) &&	
-					getPCode() == LL_PCODE_VOLUME &&					// ...is a volume object and...
-					getVelocity().isExactlyZero() &&					// ...is not moving physically and...
-					mDrawable->getGeneration() != -1                    // ...was not created this frame.
-				)					
-			);
-		gPipeline.markMoved(mDrawable, damped_motion);
-	}
-	clearChanged(SHIFTED);
+    if (!isChanged(MOVED))
+    { //most common case, having an empty if case here makes for better branch prediction
+    }
+    else if (mDrawable.notNull() &&
+        !mDrawable->isState(LLDrawable::ON_MOVE_LIST))
+    {
+        BOOL damped_motion =
+            !isChanged(SHIFTED) &&                                      // not shifted between regions this frame and...
+            (   force_damped ||                                     // ...forced into damped motion by application logic or...
+                (   !isSelected() &&                                    // ...not selected and...
+                    (   mDrawable->isRoot() ||                              // ... is root or ...
+                        (getParent() && !((LLViewerObject*)getParent())->isSelected())// ... parent is not selected and ...
+                    ) &&
+                    getPCode() == LL_PCODE_VOLUME &&                    // ...is a volume object and...
+                    getVelocity().isExactlyZero() &&                    // ...is not moving physically and...
+                    mDrawable->getGeneration() != -1                    // ...was not created this frame.
+                )
+            );
+        gPipeline.markMoved(mDrawable, damped_motion);
+    }
+    clearChanged(SHIFTED);
 }
 
 // virtual, overridden by LLVOVolume
 F32 LLViewerObject::getVObjRadius() const
 {
-	return mDrawable.notNull() ? mDrawable->getRadius() : 0.f;
+    return mDrawable.notNull() ? mDrawable->getRadius() : 0.f;
 }
 
 void LLViewerObject::setAttachedSound(const LLUUID &audio_uuid, const LLUUID& owner_id, const F32 gain, const U8 flags)
 {
-	if (!gAudiop)
-	{
-		return;
-	}
-	
-	if (audio_uuid.isNull())
-	{
-		if (!mAudioSourcep)
-		{
-			return;
-		}
-		if (mAudioSourcep->isLoop() && !mAudioSourcep->hasPendingPreloads())
-		{
-			// We don't clear the sound if it's a loop, it'll go away on its own.
-			// At least, this appears to be how the scripts work.
-			// The attached sound ID is set to NULL to avoid it playing back when the
-			// object rezzes in on non-looping sounds.
-			//LL_INFOS() << "Clearing attached sound " << mAudioSourcep->getCurrentData()->getID() << LL_ENDL;
-			gAudiop->cleanupAudioSource(mAudioSourcep);
-			mAudioSourcep = NULL;
-		}
-		else if (flags & LL_SOUND_FLAG_STOP)
-        {
-			// Just shut off the sound
-			mAudioSourcep->stop();
-		}
-		return;
-	}
-
-	if (gAudiop->isCorruptSound(audio_uuid) || ALAssetBlocklist::instance().isBlocked(audio_uuid))
-		return;
-
-	if (flags & LL_SOUND_FLAG_LOOP
-		&& mAudioSourcep && mAudioSourcep->isLoop() && mAudioSourcep->getCurrentData()
-		&& mAudioSourcep->getCurrentData()->getID() == audio_uuid)
-	{
-		//LL_INFOS() << "Already playing this sound on a loop, ignoring" << LL_ENDL;
-		return;
-	}
-
-	// don't clean up before previous sound is done. Solves: SL-33486
-	if ( mAudioSourcep && mAudioSourcep->isDone() ) 
-	{
-		gAudiop->cleanupAudioSource(mAudioSourcep);
-		mAudioSourcep = NULL;
-	}
-
-	if (mAudioSourcep && mAudioSourcep->isMuted() &&
-	    mAudioSourcep->getCurrentData() && mAudioSourcep->getCurrentData()->getID() == audio_uuid)
-	{
-		//LL_INFOS() << "Already having this sound as muted sound, ignoring" << LL_ENDL;
-		return;
-	}
-
-	getAudioSource(owner_id);
-
-	if (mAudioSourcep)
-	{
-		BOOL queue = flags & LL_SOUND_FLAG_QUEUE;
-		mAudioGain = gain;
-		mAudioSourcep->setGain(gain);
-		mAudioSourcep->setLoop(flags & LL_SOUND_FLAG_LOOP);
-		mAudioSourcep->setSyncMaster(flags & LL_SOUND_FLAG_SYNC_MASTER);
-		mAudioSourcep->setSyncSlave(flags & LL_SOUND_FLAG_SYNC_SLAVE);
-		mAudioSourcep->setQueueSounds(queue);
-		if(!queue) // stop any current sound first to avoid "farts of doom" (SL-1541) -MG
-		{
-			mAudioSourcep->stop();
-		}
-		
-		// Play this sound if region maturity permits
-		if( gAgent.canAccessMaturityAtGlobal(this->getPositionGlobal()) )
-		{
-			//LL_INFOS() << "Playing attached sound " << audio_uuid << LL_ENDL;
-			// recheck cutoff radius in case this update was an object-update with new value
-			mAudioSourcep->checkCutOffRadius();
-			mAudioSourcep->play(audio_uuid);
-		}
-	}
+    if (!gAudiop)
+    {
+        return;
+    }
+
+    if (audio_uuid.isNull())
+    {
+        if (!mAudioSourcep)
+        {
+            return;
+        }
+        if (mAudioSourcep->isLoop() && !mAudioSourcep->hasPendingPreloads())
+        {
+            // We don't clear the sound if it's a loop, it'll go away on its own.
+            // At least, this appears to be how the scripts work.
+            // The attached sound ID is set to NULL to avoid it playing back when the
+            // object rezzes in on non-looping sounds.
+            //LL_INFOS() << "Clearing attached sound " << mAudioSourcep->getCurrentData()->getID() << LL_ENDL;
+            gAudiop->cleanupAudioSource(mAudioSourcep);
+            mAudioSourcep = NULL;
+        }
+        else if (flags & LL_SOUND_FLAG_STOP)
+        {
+            // Just shut off the sound
+            mAudioSourcep->stop();
+        }
+        return;
+    }
+
+    if (gAudiop->isCorruptSound(audio_uuid) || ALAssetBlocklist::instance().isBlocked(audio_uuid))
+        return;
+
+    if (flags & LL_SOUND_FLAG_LOOP
+        && mAudioSourcep && mAudioSourcep->isLoop() && mAudioSourcep->getCurrentData()
+        && mAudioSourcep->getCurrentData()->getID() == audio_uuid)
+    {
+        //LL_INFOS() << "Already playing this sound on a loop, ignoring" << LL_ENDL;
+        return;
+    }
+
+    // don't clean up before previous sound is done. Solves: SL-33486
+    if ( mAudioSourcep && mAudioSourcep->isDone() )
+    {
+        gAudiop->cleanupAudioSource(mAudioSourcep);
+        mAudioSourcep = NULL;
+    }
+
+    if (mAudioSourcep && mAudioSourcep->isMuted() &&
+        mAudioSourcep->getCurrentData() && mAudioSourcep->getCurrentData()->getID() == audio_uuid)
+    {
+        //LL_INFOS() << "Already having this sound as muted sound, ignoring" << LL_ENDL;
+        return;
+    }
+
+    getAudioSource(owner_id);
+
+    if (mAudioSourcep)
+    {
+        BOOL queue = flags & LL_SOUND_FLAG_QUEUE;
+        mAudioGain = gain;
+        mAudioSourcep->setGain(gain);
+        mAudioSourcep->setLoop(flags & LL_SOUND_FLAG_LOOP);
+        mAudioSourcep->setSyncMaster(flags & LL_SOUND_FLAG_SYNC_MASTER);
+        mAudioSourcep->setSyncSlave(flags & LL_SOUND_FLAG_SYNC_SLAVE);
+        mAudioSourcep->setQueueSounds(queue);
+        if(!queue) // stop any current sound first to avoid "farts of doom" (SL-1541) -MG
+        {
+            mAudioSourcep->stop();
+        }
+
+        // Play this sound if region maturity permits
+        if( gAgent.canAccessMaturityAtGlobal(this->getPositionGlobal()) )
+        {
+            //LL_INFOS() << "Playing attached sound " << audio_uuid << LL_ENDL;
+            // recheck cutoff radius in case this update was an object-update with new value
+            mAudioSourcep->checkCutOffRadius();
+            mAudioSourcep->play(audio_uuid);
+        }
+    }
 }
 
 LLAudioSource *LLViewerObject::getAudioSource(const LLUUID& owner_id)
 {
-	if (!mAudioSourcep)
-	{
-		// Arbitrary low gain for a sound that's not playing.
-		// This is used for sound preloads, for example.
-		LLAudioSourceVO *asvop = new LLAudioSourceVO(mID, owner_id, 0.01f, this);
+    if (!mAudioSourcep)
+    {
+        // Arbitrary low gain for a sound that's not playing.
+        // This is used for sound preloads, for example.
+        LLAudioSourceVO *asvop = new LLAudioSourceVO(mID, owner_id, 0.01f, this);
 
-		mAudioSourcep = asvop;
-		if(gAudiop)
-		{
-			gAudiop->addAudioSource(asvop);
-		}
-	}
+        mAudioSourcep = asvop;
+        if(gAudiop)
+        {
+            gAudiop->addAudioSource(asvop);
+        }
+    }
 
-	return mAudioSourcep;
+    return mAudioSourcep;
 }
 
 void LLViewerObject::adjustAudioGain(const F32 gain)
 {
-	if (mAudioSourcep)
-	{
-		mAudioGain = gain;
-		mAudioSourcep->setGain(mAudioGain);
-	}
+    if (mAudioSourcep)
+    {
+        mAudioGain = gain;
+        mAudioSourcep->setGain(mAudioGain);
+    }
 }
 
 //----------------------------------------------------------------------------
 
 bool LLViewerObject::unpackParameterEntry(U16 param_type, LLDataPacker *dp)
 {
-	if (LLNetworkData::PARAMS_MESH == param_type)
-	{
-		param_type = LLNetworkData::PARAMS_SCULPT;
-	}
-	ExtraParameter* param = getExtraParameterEntryCreate(param_type);
-	if (param)
-	{
-		param->data->unpack(*dp);
-		*param->in_use = TRUE;
-		parameterChanged(param_type, param->data, TRUE, false);
-		return true;
-	}
-	else
-	{
-		return false;
-	}
+    if (LLNetworkData::PARAMS_MESH == param_type)
+    {
+        param_type = LLNetworkData::PARAMS_SCULPT;
+    }
+    ExtraParameter* param = getExtraParameterEntryCreate(param_type);
+    if (param)
+    {
+        param->data->unpack(*dp);
+        *param->in_use = TRUE;
+        parameterChanged(param_type, param->data, TRUE, false);
+        return true;
+    }
+    else
+    {
+        return false;
+    }
 }
 
 LLViewerObject::ExtraParameter* LLViewerObject::createNewParameterEntry(U16 param_type)
 {
-	LLNetworkData* new_block = nullptr;
-	bool* in_use = NULL;
-	switch (param_type)
-	{
-	  case LLNetworkData::PARAMS_FLEXIBLE:
-	  {
-		  mFlexibleObjectData = std::make_unique<LLFlexibleObjectData>();
-		  new_block = mFlexibleObjectData.get();
-		  in_use = &mFlexibleObjectDataInUse;
-		  break;
-	  }
-	  case LLNetworkData::PARAMS_LIGHT:
-	  {
-		  mLightParams = std::make_unique<LLLightParams>();
-		  new_block = mLightParams.get();
-		  in_use = &mLightParamsInUse;
-		  break;
-	  }
-	  case LLNetworkData::PARAMS_SCULPT:
-	  {
-		  mSculptParams = std::make_unique<LLSculptParams>();
-		  new_block = mSculptParams.get();
-		  in_use = &mSculptParamsInUse;
-		  break;
-	  }
-	  case LLNetworkData::PARAMS_LIGHT_IMAGE:
-	  {
-		  mLightImageParams = std::make_unique<LLLightImageParams>();
-		  new_block = mLightImageParams.get();
-		  in_use = &mLightImageParamsInUse;
-		  break;
-	  }
+    LLNetworkData* new_block = nullptr;
+    bool* in_use = NULL;
+    switch (param_type)
+    {
+      case LLNetworkData::PARAMS_FLEXIBLE:
+      {
+          mFlexibleObjectData = std::make_unique<LLFlexibleObjectData>();
+          new_block = mFlexibleObjectData.get();
+          in_use = &mFlexibleObjectDataInUse;
+          break;
+      }
+      case LLNetworkData::PARAMS_LIGHT:
+      {
+          mLightParams = std::make_unique<LLLightParams>();
+          new_block = mLightParams.get();
+          in_use = &mLightParamsInUse;
+          break;
+      }
+      case LLNetworkData::PARAMS_SCULPT:
+      {
+          mSculptParams = std::make_unique<LLSculptParams>();
+          new_block = mSculptParams.get();
+          in_use = &mSculptParamsInUse;
+          break;
+      }
+      case LLNetworkData::PARAMS_LIGHT_IMAGE:
+      {
+          mLightImageParams = std::make_unique<LLLightImageParams>();
+          new_block = mLightImageParams.get();
+          in_use = &mLightImageParamsInUse;
+          break;
+      }
       case LLNetworkData::PARAMS_EXTENDED_MESH:
       {
-		  mExtendedMeshParams = std::make_unique<LLExtendedMeshParams>();
-		  new_block = mExtendedMeshParams.get();
-		  in_use = &mExtendedMeshParamsInUse;
-		  break;
+          mExtendedMeshParams = std::make_unique<LLExtendedMeshParams>();
+          new_block = mExtendedMeshParams.get();
+          in_use = &mExtendedMeshParamsInUse;
+          break;
       }
       case LLNetworkData::PARAMS_RENDER_MATERIAL:
       {
-		  mRenderMaterialParams = std::make_unique<LLRenderMaterialParams>();
-		  new_block = mRenderMaterialParams.get();
-		  in_use = &mRenderMaterialParamsInUse;
+          mRenderMaterialParams = std::make_unique<LLRenderMaterialParams>();
+          new_block = mRenderMaterialParams.get();
+          in_use = &mRenderMaterialParamsInUse;
           break;
       }
       case LLNetworkData::PARAMS_REFLECTION_PROBE:
       {
-	      mReflectionProbeParams = std::make_unique<LLReflectionProbeParams>();
-		  new_block = mReflectionProbeParams.get();
-		  in_use = &mReflectionProbeParamsInUse;
+          mReflectionProbeParams = std::make_unique<LLReflectionProbeParams>();
+          new_block = mReflectionProbeParams.get();
+          in_use = &mReflectionProbeParamsInUse;
+          break;
+      }
+      default:
+      {
+          LL_INFOS_ONCE() << "Unknown param type. (" << llformat("0x%2x", param_type) << ")" << LL_ENDL;
           break;
       }
-	  default:
-	  {
-		  LL_INFOS_ONCE() << "Unknown param type. (" << llformat("0x%2x", param_type) << ")" << LL_ENDL;
-		  break;
-	  }
-	};
-
-	ExtraParameter& entry = mExtraParameterList[U32(param_type >> 4) - 1];
-	if (new_block)
-	{
-		entry.in_use = in_use;
-		*entry.in_use = false; // not in use yet
-		entry.data = new_block;
-		return &entry;
-	}
-	else
-	{
-		entry.is_invalid = true;
-	}
-	return nullptr;
+    };
+
+    ExtraParameter& entry = mExtraParameterList[U32(param_type >> 4) - 1];
+    if (new_block)
+    {
+        entry.in_use = in_use;
+        *entry.in_use = false; // not in use yet
+        entry.data = new_block;
+        return &entry;
+    }
+    else
+    {
+        entry.is_invalid = true;
+    }
+    return nullptr;
 }
 
 bool LLViewerObject::setParameterEntry(U16 param_type, const LLNetworkData& new_value, bool local_origin)
 {
-	ExtraParameter* param = getExtraParameterEntryCreate(param_type);
-	if (param)
-	{
-		if (*(param->in_use) && new_value == *(param->data))
-		{
-			return false;
-		}
-		*param->in_use = true;
-		param->data->copy(new_value);
-		parameterChanged(param_type, param->data, TRUE, local_origin);
-		return true;
-	}
-	else
-	{
-		return false;
-	}
+    ExtraParameter* param = getExtraParameterEntryCreate(param_type);
+    if (param)
+    {
+        if (*(param->in_use) && new_value == *(param->data))
+        {
+            return false;
+        }
+        *param->in_use = true;
+        param->data->copy(new_value);
+        parameterChanged(param_type, param->data, TRUE, local_origin);
+        return true;
+    }
+    else
+    {
+        return false;
+    }
 }
 
 // Assumed to be called locally
@@ -6593,71 +6593,71 @@ bool LLViewerObject::setParameterEntry(U16 param_type, const LLNetworkData& new_
 // Should always return true.
 bool LLViewerObject::setParameterEntryInUse(U16 param_type, BOOL in_use, bool local_origin)
 {
-	if (param_type <= LLNetworkData::PARAMS_MAX)
-	{
-		ExtraParameter* param = (in_use ? getExtraParameterEntryCreate(param_type) : &getExtraParameterEntry(param_type));
-		if (param && param->data && *param->in_use != (bool)in_use)
-		{
-			*param->in_use = in_use;
-			parameterChanged(param_type, param->data, in_use, local_origin);
-			return true;
-		}
-	}
-	return false;
+    if (param_type <= LLNetworkData::PARAMS_MAX)
+    {
+        ExtraParameter* param = (in_use ? getExtraParameterEntryCreate(param_type) : &getExtraParameterEntry(param_type));
+        if (param && param->data && *param->in_use != (bool)in_use)
+        {
+            *param->in_use = in_use;
+            parameterChanged(param_type, param->data, in_use, local_origin);
+            return true;
+        }
+    }
+    return false;
 }
 
 void LLViewerObject::parameterChanged(U16 param_type, bool local_origin)
 {
-	if (param_type <= LLNetworkData::PARAMS_MAX)
-	{
-		const ExtraParameter& param = getExtraParameterEntry(param_type);
-		if (param.data)
-		{
-			parameterChanged(param_type, param.data, *param.in_use, local_origin);
-		}
-	}
+    if (param_type <= LLNetworkData::PARAMS_MAX)
+    {
+        const ExtraParameter& param = getExtraParameterEntry(param_type);
+        if (param.data)
+        {
+            parameterChanged(param_type, param.data, *param.in_use, local_origin);
+        }
+    }
 }
 
 void LLViewerObject::parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_use, bool local_origin)
 {
-	if (local_origin)
-	{
+    if (local_origin)
+    {
         // *NOTE: Do not send the render material ID in this way as it will get
         // out-of-sync with other sent client data.
         // See LLViewerObject::setRenderMaterialID and LLGLTFMaterialList
         llassert(param_type != LLNetworkData::PARAMS_RENDER_MATERIAL);
 
-		LLViewerRegion* regionp = getRegion();
-		if(!regionp) return;
-
-		// Change happened on the viewer. Send the change up
-		U8 tmp[MAX_OBJECT_PARAMS_SIZE];
-		LLDataPackerBinaryBuffer dpb(tmp, MAX_OBJECT_PARAMS_SIZE);
-		if (data->pack(dpb))
-		{
-			U32 datasize = (U32)dpb.getCurrentSize();
-
-			LLMessageSystem* msg = gMessageSystem;
-			msg->newMessageFast(_PREHASH_ObjectExtraParams);
-			msg->nextBlockFast(_PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-			msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-			msg->nextBlockFast(_PREHASH_ObjectData);
-			msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
-
-			msg->addU16Fast(_PREHASH_ParamType, param_type);
-			msg->addBOOLFast(_PREHASH_ParamInUse, in_use);
-
-			msg->addU32Fast(_PREHASH_ParamSize, datasize);
-			msg->addBinaryDataFast(_PREHASH_ParamData, tmp, datasize);
-
-			msg->sendReliable( regionp->getHost() );
-		}
-		else
-		{
-			LL_WARNS() << "Failed to send object extra parameters: " << param_type << LL_ENDL;
-		}
-	}
+        LLViewerRegion* regionp = getRegion();
+        if(!regionp) return;
+
+        // Change happened on the viewer. Send the change up
+        U8 tmp[MAX_OBJECT_PARAMS_SIZE];
+        LLDataPackerBinaryBuffer dpb(tmp, MAX_OBJECT_PARAMS_SIZE);
+        if (data->pack(dpb))
+        {
+            U32 datasize = (U32)dpb.getCurrentSize();
+
+            LLMessageSystem* msg = gMessageSystem;
+            msg->newMessageFast(_PREHASH_ObjectExtraParams);
+            msg->nextBlockFast(_PREHASH_AgentData);
+            msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+            msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+            msg->nextBlockFast(_PREHASH_ObjectData);
+            msg->addU32Fast(_PREHASH_ObjectLocalID, mLocalID );
+
+            msg->addU16Fast(_PREHASH_ParamType, param_type);
+            msg->addBOOLFast(_PREHASH_ParamInUse, in_use);
+
+            msg->addU32Fast(_PREHASH_ParamSize, datasize);
+            msg->addBinaryDataFast(_PREHASH_ParamData, tmp, datasize);
+
+            msg->sendReliable( regionp->getHost() );
+        }
+        else
+        {
+            LL_WARNS() << "Failed to send object extra parameters: " << param_type << LL_ENDL;
+        }
+    }
     else
     {
         if (param_type == LLNetworkData::PARAMS_RENDER_MATERIAL)
@@ -6670,225 +6670,225 @@ void LLViewerObject::parameterChanged(U16 param_type, LLNetworkData* data, BOOL
 
 void LLViewerObject::setDrawableState(U32 state, BOOL recursive)
 {
-	if (mDrawable)
-	{
-		mDrawable->setState(state);
-	}
-	if (recursive)
-	{
-		for (LLViewerObject* child : mChildList)
-		{
-			child->setDrawableState(state, recursive);
-		}
-	}
+    if (mDrawable)
+    {
+        mDrawable->setState(state);
+    }
+    if (recursive)
+    {
+        for (LLViewerObject* child : mChildList)
+        {
+            child->setDrawableState(state, recursive);
+        }
+    }
 }
 
 void LLViewerObject::clearDrawableState(U32 state, BOOL recursive)
 {
-	if (mDrawable)
-	{
-		mDrawable->clearState(state);
-	}
-	if (recursive)
-	{
-		for (LLViewerObject* child : mChildList)
-		{
-			child->clearDrawableState(state, recursive);
-		}
-	}
+    if (mDrawable)
+    {
+        mDrawable->clearState(state);
+    }
+    if (recursive)
+    {
+        for (LLViewerObject* child : mChildList)
+        {
+            child->clearDrawableState(state, recursive);
+        }
+    }
 }
 
 BOOL LLViewerObject::isDrawableState(U32 state, BOOL recursive) const
 {
-	BOOL matches = FALSE;
-	if (mDrawable)
-	{
-		matches = mDrawable->isState(state);
-	}
-	if (recursive)
-	{
-		for (LLViewerObject* child : mChildList)
-		{
-			matches &= child->isDrawableState(state, recursive);
-		}
-	}
+    BOOL matches = FALSE;
+    if (mDrawable)
+    {
+        matches = mDrawable->isState(state);
+    }
+    if (recursive)
+    {
+        for (LLViewerObject* child : mChildList)
+        {
+            matches &= child->isDrawableState(state, recursive);
+        }
+    }
 
-	return matches;
+    return matches;
 }
 
 
 
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
-// RN: these functions assume a 2-level hierarchy 
+// RN: these functions assume a 2-level hierarchy
 //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
 
 // Owned by anyone?
 BOOL LLViewerObject::permAnyOwner() const
-{ 
-	if (isRootEdit())
-	{
-		return flagObjectAnyOwner(); 
-	}
-	else
-	{
-		return ((LLViewerObject*)getParent())->permAnyOwner();
-	}
-}	
+{
+    if (isRootEdit())
+    {
+        return flagObjectAnyOwner();
+    }
+    else
+    {
+        return ((LLViewerObject*)getParent())->permAnyOwner();
+    }
+}
 // Owned by this viewer?
 BOOL LLViewerObject::permYouOwner() const
-{ 
-	if (isRootEdit())
-	{
+{
+    if (isRootEdit())
+    {
 #ifdef HACKED_GODLIKE_VIEWER
-		return TRUE;
+        return TRUE;
 #else
 # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-		if (LLGridManager::getInstance()->isInSLBeta()
+        if (LLGridManager::getInstance()->isInSLBeta()
             && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
-		{
-			return TRUE;
-		}
+        {
+            return TRUE;
+        }
 # endif
-		return flagObjectYouOwner(); 
+        return flagObjectYouOwner();
 #endif
-	}
-	else
-	{
-		return ((LLViewerObject*)getParent())->permYouOwner();
-	}
+    }
+    else
+    {
+        return ((LLViewerObject*)getParent())->permYouOwner();
+    }
 }
 
 // Owned by a group?
-BOOL LLViewerObject::permGroupOwner() const		
-{ 
-	if (isRootEdit())
-	{
-		return flagObjectGroupOwned(); 
-	}
-	else
-	{
-		return ((LLViewerObject*)getParent())->permGroupOwner();
-	}
+BOOL LLViewerObject::permGroupOwner() const
+{
+    if (isRootEdit())
+    {
+        return flagObjectGroupOwned();
+    }
+    else
+    {
+        return ((LLViewerObject*)getParent())->permGroupOwner();
+    }
 }
 
 // Can the owner edit
 BOOL LLViewerObject::permOwnerModify() const
-{ 
-	if (isRootEdit())
-	{
+{
+    if (isRootEdit())
+    {
 #ifdef HACKED_GODLIKE_VIEWER
-		return TRUE;
+        return TRUE;
 #else
 # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-		if (LLGridManager::getInstance()->isInSLBeta()
+        if (LLGridManager::getInstance()->isInSLBeta()
             && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
-	{
-			return TRUE;
-	}
+    {
+            return TRUE;
+    }
 # endif
-		return flagObjectOwnerModify(); 
+        return flagObjectOwnerModify();
 #endif
-	}
-	else
-	{
-		return ((LLViewerObject*)getParent())->permOwnerModify();
-	}
+    }
+    else
+    {
+        return ((LLViewerObject*)getParent())->permOwnerModify();
+    }
 }
 
 // Can edit
 BOOL LLViewerObject::permModify() const
-{ 
-	if (isRootEdit())
-	{
+{
+    if (isRootEdit())
+    {
 #ifdef HACKED_GODLIKE_VIEWER
-		return TRUE;
+        return TRUE;
 #else
 # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-		if (LLGridManager::getInstance()->isInSLBeta()
+        if (LLGridManager::getInstance()->isInSLBeta()
             && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
-	{
-			return TRUE;
-	}
+    {
+            return TRUE;
+    }
 # endif
-		return flagObjectModify(); 
+        return flagObjectModify();
 #endif
-	}
-	else
-	{
-		return ((LLViewerObject*)getParent())->permModify();
-	}
+    }
+    else
+    {
+        return ((LLViewerObject*)getParent())->permModify();
+    }
 }
 
 // Can copy
 BOOL LLViewerObject::permCopy() const
-{ 
-	if (isRootEdit())
-	{
+{
+    if (isRootEdit())
+    {
 #ifdef HACKED_GODLIKE_VIEWER
-		return TRUE;
+        return TRUE;
 #else
 # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-		if (LLGridManager::getInstance()->isInSLBeta()
+        if (LLGridManager::getInstance()->isInSLBeta()
             && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
-		{
-			return TRUE;
-		}
+        {
+            return TRUE;
+        }
 # endif
-		return flagObjectCopy();
+        return flagObjectCopy();
 #endif
-	}
-	else
-	{
-		return ((LLViewerObject*)getParent())->permCopy();
-	}
+    }
+    else
+    {
+        return ((LLViewerObject*)getParent())->permCopy();
+    }
 }
 
 // Can move
 BOOL LLViewerObject::permMove() const
 {
-	if (isRootEdit())
-	{
+    if (isRootEdit())
+    {
 #ifdef HACKED_GODLIKE_VIEWER
-		return TRUE;
+        return TRUE;
 #else
 # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-		if (LLGridManager::getInstance()->isInSLBeta()
+        if (LLGridManager::getInstance()->isInSLBeta()
             && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
-		{
-			return TRUE;
-		}
+        {
+            return TRUE;
+        }
 # endif
-		return flagObjectMove(); 
+        return flagObjectMove();
 #endif
-	}
-	else
-	{
-		return ((LLViewerObject*)getParent())->permMove();
-	}
+    }
+    else
+    {
+        return ((LLViewerObject*)getParent())->permMove();
+    }
 }
 
 // Can be transferred
 BOOL LLViewerObject::permTransfer() const
-{ 
-	if (isRootEdit())
-	{
+{
+    if (isRootEdit())
+    {
 #ifdef HACKED_GODLIKE_VIEWER
-		return TRUE;
+        return TRUE;
 #else
 # ifdef TOGGLE_HACKED_GODLIKE_VIEWER
-		if (LLGridManager::getInstance()->isInSLBeta()
+        if (LLGridManager::getInstance()->isInSLBeta()
             && (gAgent.getGodLevel() >= GOD_MAINTENANCE))
-		{
-			return TRUE;
-		}
+        {
+            return TRUE;
+        }
 # endif
-		return flagObjectTransfer(); 
+        return flagObjectTransfer();
 #endif
-	}
-	else
-	{
-		return ((LLViewerObject*)getParent())->permTransfer();
-	}
+    }
+    else
+    {
+        return ((LLViewerObject*)getParent())->permTransfer();
+    }
 }
 
 // Can only open objects that you own, or that someone has
@@ -6896,33 +6896,33 @@ BOOL LLViewerObject::permTransfer() const
 BOOL LLViewerObject::allowOpen() const
 {
 // [RLVa:KB] - Checked: 2010-11-29 (RLVa-1.3.0c) | Modified: RLVa-1.3.0c
-	return !flagInventoryEmpty() && (permYouOwner() || permModify()) && ((!RlvActions::isRlvEnabled()) || (RlvActions::canEdit(this)));
+    return !flagInventoryEmpty() && (permYouOwner() || permModify()) && ((!RlvActions::isRlvEnabled()) || (RlvActions::canEdit(this)));
 // [/RLVa:KB]
-//	return !flagInventoryEmpty() && (permYouOwner() || permModify());
+//  return !flagInventoryEmpty() && (permYouOwner() || permModify());
 }
 
 LLViewerObject::LLInventoryCallbackInfo::~LLInventoryCallbackInfo()
 {
-	if (mListener)
-	{
-		mListener->clearVOInventoryListener();
-	}
+    if (mListener)
+    {
+        mListener->clearVOInventoryListener();
+    }
 }
 
 void LLViewerObject::updateVolume(const LLVolumeParams& volume_params)
 {
-	if (setVolume(volume_params, 1)) // *FIX: magic number, ack!
-	{
-		// Transmit the update to the simulator
-		sendShapeUpdate();
-		markForUpdate();
-	}
+    if (setVolume(volume_params, 1)) // *FIX: magic number, ack!
+    {
+        // Transmit the update to the simulator
+        sendShapeUpdate();
+        markForUpdate();
+    }
 }
 
 void LLViewerObject::recursiveMarkForUpdate()
 {
-	for (LLViewerObject* child : mChildList)
-	{
+    for (LLViewerObject* child : mChildList)
+    {
         child->markForUpdate();
     }
     markForUpdate();
@@ -6930,258 +6930,258 @@ void LLViewerObject::recursiveMarkForUpdate()
 
 void LLViewerObject::markForUpdate()
 {
-	if (mDrawable.notNull())
-	{
-		gPipeline.markTextured(mDrawable);
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
-	}
+    if (mDrawable.notNull())
+    {
+        gPipeline.markTextured(mDrawable);
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
+    }
 }
 
 bool LLViewerObject::isPermanentEnforced() const
 {
-	return flagObjectPermanent() && (mRegionp != gAgent.getRegion()) && !gAgent.isGodlike();
+    return flagObjectPermanent() && (mRegionp != gAgent.getRegion()) && !gAgent.isGodlike();
 }
 
 bool LLViewerObject::getIncludeInSearch() const
 {
-	return flagIncludeInSearch();
+    return flagIncludeInSearch();
 }
 
 void LLViewerObject::setIncludeInSearch(bool include_in_search)
 {
-	setFlags(FLAGS_INCLUDE_IN_SEARCH, include_in_search);
+    setFlags(FLAGS_INCLUDE_IN_SEARCH, include_in_search);
 }
 
 void LLViewerObject::setRegion(LLViewerRegion *regionp)
 {
-	if (!regionp)
-	{
-		LL_WARNS() << "viewer object set region to NULL" << LL_ENDL;
-	}
-	if(regionp != mRegionp)
-	{
-		if(mRegionp)
-		{
-			mRegionp->removeFromCreatedList(getLocalID()); 
-		}
-		if(regionp)
-		{
-			regionp->addToCreatedList(getLocalID()); 
-		}
-	}
-	
-	mLatestRecvPacketID = 0;
-	mRegionp = regionp;
-
-	for (LLViewerObject* child : mChildList)
-	{
-		child->setRegion(regionp);
-	}
+    if (!regionp)
+    {
+        LL_WARNS() << "viewer object set region to NULL" << LL_ENDL;
+    }
+    if(regionp != mRegionp)
+    {
+        if(mRegionp)
+        {
+            mRegionp->removeFromCreatedList(getLocalID());
+        }
+        if(regionp)
+        {
+            regionp->addToCreatedList(getLocalID());
+        }
+    }
+
+    mLatestRecvPacketID = 0;
+    mRegionp = regionp;
+
+    for (LLViewerObject* child : mChildList)
+    {
+        child->setRegion(regionp);
+    }
 
     if (mControlAvatar)
     {
         mControlAvatar->setRegion(regionp);
     }
 
-	setChanged(MOVED | SILHOUETTE);
-	updateDrawable(FALSE);
+    setChanged(MOVED | SILHOUETTE);
+    updateDrawable(FALSE);
 }
 
 // virtual
-void	LLViewerObject::updateRegion(LLViewerRegion *regionp)
+void    LLViewerObject::updateRegion(LLViewerRegion *regionp)
 {
-//	if (regionp)
-//	{
-//		F64 now = LLFrameTimer::getElapsedSeconds();
-//		LL_INFOS() << "Updating to region " << regionp->getName()
-//			<< ", ms since last update message: " << (F32)((now - mLastMessageUpdateSecs) * 1000.0)
-//			<< ", ms since last interpolation: " << (F32)((now - mLastInterpUpdateSecs) * 1000.0) 
-//			<< LL_ENDL;
-//	}
+//  if (regionp)
+//  {
+//      F64 now = LLFrameTimer::getElapsedSeconds();
+//      LL_INFOS() << "Updating to region " << regionp->getName()
+//          << ", ms since last update message: " << (F32)((now - mLastMessageUpdateSecs) * 1000.0)
+//          << ", ms since last interpolation: " << (F32)((now - mLastInterpUpdateSecs) * 1000.0)
+//          << LL_ENDL;
+//  }
 }
 
 
 bool LLViewerObject::specialHoverCursor() const
 {
-	return flagUsePhysics()
-			|| flagHandleTouch()
-			|| (mClickAction != 0);
+    return flagUsePhysics()
+            || flagHandleTouch()
+            || (mClickAction != 0);
 }
 
 void LLViewerObject::updateFlags(BOOL physics_changed)
 {
-	LLViewerRegion* regionp = getRegion();
-	if(!regionp) return;
-	gMessageSystem->newMessageFast(_PREHASH_ObjectFlagUpdate);
-	gMessageSystem->nextBlockFast(_PREHASH_AgentData);
-	gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
-	gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, getLocalID() );
-	gMessageSystem->addBOOLFast(_PREHASH_UsePhysics, flagUsePhysics() );
-	gMessageSystem->addBOOLFast(_PREHASH_IsTemporary, flagTemporaryOnRez() );
-	gMessageSystem->addBOOLFast(_PREHASH_IsPhantom, flagPhantom() );
-
-	// stinson 02/28/2012 : This CastsShadows BOOL is no longer used in either the viewer or the simulator
-	// The simulator code does not even unpack this value when the message is received.
-	// This could be potentially hijacked in the future for another use should the urgent need arise.
-	gMessageSystem->addBOOLFast(_PREHASH_CastsShadows, FALSE );
-
-	if (physics_changed)
-	{
-		gMessageSystem->nextBlockFast(_PREHASH_ExtraPhysics);
-		gMessageSystem->addU8Fast(_PREHASH_PhysicsShapeType, getPhysicsShapeType() );
-		gMessageSystem->addF32Fast(_PREHASH_Density, getPhysicsDensity() );
-		gMessageSystem->addF32Fast(_PREHASH_Friction, getPhysicsFriction() );
-		gMessageSystem->addF32Fast(_PREHASH_Restitution, getPhysicsRestitution() );
-		gMessageSystem->addF32Fast(_PREHASH_GravityMultiplier, getPhysicsGravity() );
-	}
-	gMessageSystem->sendReliable( regionp->getHost() );
+    LLViewerRegion* regionp = getRegion();
+    if(!regionp) return;
+    gMessageSystem->newMessageFast(_PREHASH_ObjectFlagUpdate);
+    gMessageSystem->nextBlockFast(_PREHASH_AgentData);
+    gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID() );
+    gMessageSystem->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    gMessageSystem->addU32Fast(_PREHASH_ObjectLocalID, getLocalID() );
+    gMessageSystem->addBOOLFast(_PREHASH_UsePhysics, flagUsePhysics() );
+    gMessageSystem->addBOOLFast(_PREHASH_IsTemporary, flagTemporaryOnRez() );
+    gMessageSystem->addBOOLFast(_PREHASH_IsPhantom, flagPhantom() );
+
+    // stinson 02/28/2012 : This CastsShadows BOOL is no longer used in either the viewer or the simulator
+    // The simulator code does not even unpack this value when the message is received.
+    // This could be potentially hijacked in the future for another use should the urgent need arise.
+    gMessageSystem->addBOOLFast(_PREHASH_CastsShadows, FALSE );
+
+    if (physics_changed)
+    {
+        gMessageSystem->nextBlockFast(_PREHASH_ExtraPhysics);
+        gMessageSystem->addU8Fast(_PREHASH_PhysicsShapeType, getPhysicsShapeType() );
+        gMessageSystem->addF32Fast(_PREHASH_Density, getPhysicsDensity() );
+        gMessageSystem->addF32Fast(_PREHASH_Friction, getPhysicsFriction() );
+        gMessageSystem->addF32Fast(_PREHASH_Restitution, getPhysicsRestitution() );
+        gMessageSystem->addF32Fast(_PREHASH_GravityMultiplier, getPhysicsGravity() );
+    }
+    gMessageSystem->sendReliable( regionp->getHost() );
 }
 
 BOOL LLViewerObject::setFlags(U32 flags, BOOL state)
 {
-	BOOL setit = setFlagsWithoutUpdate(flags, state);
+    BOOL setit = setFlagsWithoutUpdate(flags, state);
 
-	// BUG: Sometimes viewer physics and simulator physics get
-	// out of sync.  To fix this, always send update to simulator.
-// 	if (setit)
-	{
-		updateFlags();
-	}
-	return setit;
+    // BUG: Sometimes viewer physics and simulator physics get
+    // out of sync.  To fix this, always send update to simulator.
+//  if (setit)
+    {
+        updateFlags();
+    }
+    return setit;
 }
 
 BOOL LLViewerObject::setFlagsWithoutUpdate(U32 flags, BOOL state)
 {
-	BOOL setit = FALSE;
-	if (state)
-	{
-		if ((mFlags & flags) != flags)
-		{
-			mFlags |= flags;
-			setit = TRUE;
-		}
-	}
-	else
-	{
-		if ((mFlags & flags) != 0)
-		{
-			mFlags &= ~flags;
-			setit = TRUE;
-		}
-	}
-	return setit;
+    BOOL setit = FALSE;
+    if (state)
+    {
+        if ((mFlags & flags) != flags)
+        {
+            mFlags |= flags;
+            setit = TRUE;
+        }
+    }
+    else
+    {
+        if ((mFlags & flags) != 0)
+        {
+            mFlags &= ~flags;
+            setit = TRUE;
+        }
+    }
+    return setit;
 }
 
 void LLViewerObject::setPhysicsShapeType(U8 type)
 {
-	mPhysicsShapeUnknown = false;
-	if (type != mPhysicsShapeType)
-	{
-		mPhysicsShapeType = type;
-		setObjectCostStale();
-	}
+    mPhysicsShapeUnknown = false;
+    if (type != mPhysicsShapeType)
+    {
+        mPhysicsShapeType = type;
+        setObjectCostStale();
+    }
 }
 
 void LLViewerObject::setPhysicsGravity(F32 gravity)
 {
-	mPhysicsGravity = gravity;
+    mPhysicsGravity = gravity;
 }
 
 void LLViewerObject::setPhysicsFriction(F32 friction)
 {
-	mPhysicsFriction = friction;
+    mPhysicsFriction = friction;
 }
 
 void LLViewerObject::setPhysicsDensity(F32 density)
 {
-	mPhysicsDensity = density;
+    mPhysicsDensity = density;
 }
 
 void LLViewerObject::setPhysicsRestitution(F32 restitution)
 {
-	mPhysicsRestitution = restitution;
+    mPhysicsRestitution = restitution;
 }
 
 U8 LLViewerObject::getPhysicsShapeType() const
-{ 
-	if (mPhysicsShapeUnknown)
-	{
-		gObjectList.updatePhysicsFlags(this);
-	}
+{
+    if (mPhysicsShapeUnknown)
+    {
+        gObjectList.updatePhysicsFlags(this);
+    }
 
-	return mPhysicsShapeType; 
+    return mPhysicsShapeType;
 }
 
 void LLViewerObject::applyAngularVelocity(F32 dt)
 {
-	//do target omega here
-	mRotTime += dt;
-	LLVector3 ang_vel = getAngularVelocity();
-	F32 omega = ang_vel.magVecSquared();
-	F32 angle = 0.0f;
-	LLQuaternion dQ;
-	if (omega > 0.00001f)
-	{
-		omega = sqrt(omega);
-		angle = omega * dt;
-
-		ang_vel *= 1.f/omega;
-		
-		// calculate the delta increment based on the object's angular velocity
-		dQ.setQuat(angle, ang_vel);
-
-		// accumulate the angular velocity rotations to re-apply in the case of an object update
-		mAngularVelocityRot *= dQ;
-		
-		// Just apply the delta increment to the current rotation
-		setRotation(getRotation()*dQ);
-		setChanged(MOVED | SILHOUETTE);
-	}
+    //do target omega here
+    mRotTime += dt;
+    LLVector3 ang_vel = getAngularVelocity();
+    F32 omega = ang_vel.magVecSquared();
+    F32 angle = 0.0f;
+    LLQuaternion dQ;
+    if (omega > 0.00001f)
+    {
+        omega = sqrt(omega);
+        angle = omega * dt;
+
+        ang_vel *= 1.f/omega;
+
+        // calculate the delta increment based on the object's angular velocity
+        dQ.setQuat(angle, ang_vel);
+
+        // accumulate the angular velocity rotations to re-apply in the case of an object update
+        mAngularVelocityRot *= dQ;
+
+        // Just apply the delta increment to the current rotation
+        setRotation(getRotation()*dQ);
+        setChanged(MOVED | SILHOUETTE);
+    }
 }
 
 void LLViewerObject::resetRotTime()
 {
-	mRotTime = 0.0f;
+    mRotTime = 0.0f;
 }
 
 void LLViewerObject::resetRot()
 {
-	resetRotTime();
+    resetRotTime();
 
-	// Reset the accumulated angular velocity rotation
-	mAngularVelocityRot.loadIdentity(); 
+    // Reset the accumulated angular velocity rotation
+    mAngularVelocityRot.loadIdentity();
 }
 
 U32 LLViewerObject::getPartitionType() const
-{ 
-	return LLViewerRegion::PARTITION_NONE; 
+{
+    return LLViewerRegion::PARTITION_NONE;
 }
 
 void LLViewerObject::dirtySpatialGroup() const
 {
-	if (mDrawable)
-	{
-		LLSpatialGroup* group = mDrawable->getSpatialGroup();
-		if (group)
-		{
-			group->dirtyGeom();
-			gPipeline.markRebuild(group);
-		}
-	}
+    if (mDrawable)
+    {
+        LLSpatialGroup* group = mDrawable->getSpatialGroup();
+        if (group)
+        {
+            group->dirtyGeom();
+            gPipeline.markRebuild(group);
+        }
+    }
 }
 
 void LLViewerObject::dirtyMesh()
 {
-	if (mDrawable)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL);
-	}
+    if (mDrawable)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL);
+    }
 }
 
 F32 LLAlphaObject::getPartSize(S32 idx)
 {
-	return 0.f;
+    return 0.f;
 }
 
 void LLAlphaObject::getBlendFunc(S32 face, LLRender::eBlendFactor& src, LLRender::eBlendFactor& dst)
@@ -7192,227 +7192,227 @@ void LLAlphaObject::getBlendFunc(S32 face, LLRender::eBlendFactor& src, LLRender
 // virtual
 void LLStaticViewerObject::updateDrawable(BOOL force_damped)
 {
-	// Force an immediate rebuild on any update
-	if (mDrawable.notNull())
-	{
-		mDrawable->updateXform(TRUE);
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL);
-	}
-	clearChanged(SHIFTED);
+    // Force an immediate rebuild on any update
+    if (mDrawable.notNull())
+    {
+        mDrawable->updateXform(TRUE);
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL);
+    }
+    clearChanged(SHIFTED);
 }
 
 void LLViewerObject::saveUnselectedChildrenPosition(std::vector<LLVector3>& positions)
 {
-	if(mChildList.empty() || !positions.empty())
-	{
-		return ;
-	}
+    if(mChildList.empty() || !positions.empty())
+    {
+        return ;
+    }
 
-	for (const LLViewerObject* childp : mChildList)
-	{
-		if (!childp->isSelected() && childp->mDrawable.notNull())
-		{
-			positions.push_back(childp->getPositionEdit());		
-		}
-	}
+    for (const LLViewerObject* childp : mChildList)
+    {
+        if (!childp->isSelected() && childp->mDrawable.notNull())
+        {
+            positions.push_back(childp->getPositionEdit());
+        }
+    }
 
-	return ;
+    return ;
 }
 
 void LLViewerObject::saveUnselectedChildrenRotation(std::vector<LLQuaternion>& rotations)
 {
-	if(mChildList.empty())
-	{
-		return ;
-	}
+    if(mChildList.empty())
+    {
+        return ;
+    }
 
-	for (const LLViewerObject* childp : mChildList)
-	{
-		if (!childp->isSelected() && childp->mDrawable.notNull())
-		{
-			rotations.push_back(childp->getRotationEdit());				
-		}		
-	}
+    for (const LLViewerObject* childp : mChildList)
+    {
+        if (!childp->isSelected() && childp->mDrawable.notNull())
+        {
+            rotations.push_back(childp->getRotationEdit());
+        }
+    }
 
-	return ;
+    return ;
 }
 
 //counter-rotation
-void LLViewerObject::resetChildrenRotationAndPosition(const std::vector<LLQuaternion>& rotations, 
-											const std::vector<LLVector3>& positions)
-{
-	if(mChildList.empty())
-	{
-		return ;
-	}
-
-	S32 index = 0 ;
-	LLQuaternion inv_rotation = ~getRotationEdit() ;
-	LLVector3 offset = getPositionEdit() ;
-	for (LLViewerObject* childp : mChildList)
-	{
-		if (!childp->isSelected() && childp->mDrawable.notNull())
-		{
-			if (childp->getPCode() != LL_PCODE_LEGACY_AVATAR)
-			{
-				childp->setRotation(rotations[index] * inv_rotation);
-				childp->setPosition((positions[index] - offset) * inv_rotation);
-				LLManip::rebuild(childp);					
-			}
-			else //avatar
-			{
-				LLVector3 reset_pos = (positions[index] - offset) * inv_rotation ;
-				LLQuaternion reset_rot = rotations[index] * inv_rotation ;
-
-				((LLVOAvatar*)childp)->mDrawable->mXform.setPosition(reset_pos);				
-				((LLVOAvatar*)childp)->mDrawable->mXform.setRotation(reset_rot) ;
-				
-				((LLVOAvatar*)childp)->mDrawable->getVObj()->setPosition(reset_pos, TRUE);				
-				((LLVOAvatar*)childp)->mDrawable->getVObj()->setRotation(reset_rot, TRUE) ;
-
-				LLManip::rebuild(childp);				
-			}	
-			index++;
-		}				
-	}
-
-	return ;
+void LLViewerObject::resetChildrenRotationAndPosition(const std::vector<LLQuaternion>& rotations,
+                                            const std::vector<LLVector3>& positions)
+{
+    if(mChildList.empty())
+    {
+        return ;
+    }
+
+    S32 index = 0 ;
+    LLQuaternion inv_rotation = ~getRotationEdit() ;
+    LLVector3 offset = getPositionEdit() ;
+    for (LLViewerObject* childp : mChildList)
+    {
+        if (!childp->isSelected() && childp->mDrawable.notNull())
+        {
+            if (childp->getPCode() != LL_PCODE_LEGACY_AVATAR)
+            {
+                childp->setRotation(rotations[index] * inv_rotation);
+                childp->setPosition((positions[index] - offset) * inv_rotation);
+                LLManip::rebuild(childp);
+            }
+            else //avatar
+            {
+                LLVector3 reset_pos = (positions[index] - offset) * inv_rotation ;
+                LLQuaternion reset_rot = rotations[index] * inv_rotation ;
+
+                ((LLVOAvatar*)childp)->mDrawable->mXform.setPosition(reset_pos);
+                ((LLVOAvatar*)childp)->mDrawable->mXform.setRotation(reset_rot) ;
+
+                ((LLVOAvatar*)childp)->mDrawable->getVObj()->setPosition(reset_pos, TRUE);
+                ((LLVOAvatar*)childp)->mDrawable->getVObj()->setRotation(reset_rot, TRUE) ;
+
+                LLManip::rebuild(childp);
+            }
+            index++;
+        }
+    }
+
+    return ;
 }
 
 //counter-translation
 void LLViewerObject::resetChildrenPosition(const LLVector3& offset, BOOL simplified, BOOL skip_avatar_child)
 {
-	if(mChildList.empty())
-	{
-		return ;
-	}
-
-	LLVector3 child_offset;
-	if(simplified) //translation only, rotation matrix does not change
-	{
-		child_offset = offset * ~getRotation();
-	}
-	else //rotation matrix might change too.
-	{
-		if (isAttachment() && mDrawable.notNull())
-		{
-			LLXform* attachment_point_xform = mDrawable->getXform()->getParent();
-			LLQuaternion parent_rotation = getRotation() * attachment_point_xform->getWorldRotation();
-			child_offset = offset * ~parent_rotation;
-		}
-		else
-		{
-			child_offset = offset * ~getRenderRotation();
-		}
-	}
-
-	for (LLViewerObject* childp : mChildList)
-	{
-
-		if (!childp->isSelected() && childp->mDrawable.notNull())
-		{
-			if (childp->getPCode() != LL_PCODE_LEGACY_AVATAR)
-			{
-				childp->setPosition(childp->getPosition() + child_offset);
-				LLManip::rebuild(childp);
-			}
-			else //avatar
-			{
-				if(!skip_avatar_child)
-				{
-					LLVector3 reset_pos = ((LLVOAvatar*)childp)->mDrawable->mXform.getPosition() + child_offset ;
-
-					((LLVOAvatar*)childp)->mDrawable->mXform.setPosition(reset_pos);
-					((LLVOAvatar*)childp)->mDrawable->getVObj()->setPosition(reset_pos);
-					LLManip::rebuild(childp);
-				}
-			}
-		}
-	}
-
-	return ;
-}
-
-// virtual 
-BOOL	LLViewerObject::isTempAttachment() const
-{
-	return (mID.notNull() && (mID == mAttachmentItemID));
+    if(mChildList.empty())
+    {
+        return ;
+    }
+
+    LLVector3 child_offset;
+    if(simplified) //translation only, rotation matrix does not change
+    {
+        child_offset = offset * ~getRotation();
+    }
+    else //rotation matrix might change too.
+    {
+        if (isAttachment() && mDrawable.notNull())
+        {
+            LLXform* attachment_point_xform = mDrawable->getXform()->getParent();
+            LLQuaternion parent_rotation = getRotation() * attachment_point_xform->getWorldRotation();
+            child_offset = offset * ~parent_rotation;
+        }
+        else
+        {
+            child_offset = offset * ~getRenderRotation();
+        }
+    }
+
+    for (LLViewerObject* childp : mChildList)
+    {
+
+        if (!childp->isSelected() && childp->mDrawable.notNull())
+        {
+            if (childp->getPCode() != LL_PCODE_LEGACY_AVATAR)
+            {
+                childp->setPosition(childp->getPosition() + child_offset);
+                LLManip::rebuild(childp);
+            }
+            else //avatar
+            {
+                if(!skip_avatar_child)
+                {
+                    LLVector3 reset_pos = ((LLVOAvatar*)childp)->mDrawable->mXform.getPosition() + child_offset ;
+
+                    ((LLVOAvatar*)childp)->mDrawable->mXform.setPosition(reset_pos);
+                    ((LLVOAvatar*)childp)->mDrawable->getVObj()->setPosition(reset_pos);
+                    LLManip::rebuild(childp);
+                }
+            }
+        }
+    }
+
+    return ;
 }
 
-BOOL LLViewerObject::isHiglightedOrBeacon() const
+// virtual
+BOOL    LLViewerObject::isTempAttachment() const
 {
-	if (LLFloaterReg::instanceVisible("beacons") && (gPipeline.getRenderBeacons() || gPipeline.getRenderHighlights()))
-	{
-		BOOL has_media = (getMediaType() == LLViewerObject::MEDIA_SET);
-		BOOL is_scripted = !isAvatar() && !getParent() && flagScripted();
-		BOOL is_physical = !isAvatar() && flagUsePhysics();
+    return (mID.notNull() && (mID == mAttachmentItemID));
+}
 
-		return (isParticleSource() && gPipeline.getRenderParticleBeacons())
-				|| (isAudioSource() && gPipeline.getRenderSoundBeacons())
-				|| (has_media && gPipeline.getRenderMOAPBeacons())
-				|| (is_scripted && gPipeline.getRenderScriptedBeacons())
-				|| (is_scripted && flagHandleTouch() && gPipeline.getRenderScriptedTouchBeacons())
-				|| (is_physical && gPipeline.getRenderPhysicalBeacons());
-	}
-	return FALSE;
+BOOL LLViewerObject::isHiglightedOrBeacon() const
+{
+    if (LLFloaterReg::instanceVisible("beacons") && (gPipeline.getRenderBeacons() || gPipeline.getRenderHighlights()))
+    {
+        BOOL has_media = (getMediaType() == LLViewerObject::MEDIA_SET);
+        BOOL is_scripted = !isAvatar() && !getParent() && flagScripted();
+        BOOL is_physical = !isAvatar() && flagUsePhysics();
+
+        return (isParticleSource() && gPipeline.getRenderParticleBeacons())
+                || (isAudioSource() && gPipeline.getRenderSoundBeacons())
+                || (has_media && gPipeline.getRenderMOAPBeacons())
+                || (is_scripted && gPipeline.getRenderScriptedBeacons())
+                || (is_scripted && flagHandleTouch() && gPipeline.getRenderScriptedTouchBeacons())
+                || (is_physical && gPipeline.getRenderPhysicalBeacons());
+    }
+    return FALSE;
 }
 
 
 const LLUUID &LLViewerObject::getAttachmentItemID() const
 {
-	return mAttachmentItemID;
+    return mAttachmentItemID;
 }
 
 void LLViewerObject::setAttachmentItemID(const LLUUID &id)
 {
-	mAttachmentItemID = id;
+    mAttachmentItemID = id;
 }
 
 EObjectUpdateType LLViewerObject::getLastUpdateType() const
 {
-	return mLastUpdateType;
+    return mLastUpdateType;
 }
 
 void LLViewerObject::setLastUpdateType(EObjectUpdateType last_update_type)
 {
-	mLastUpdateType = last_update_type;
+    mLastUpdateType = last_update_type;
 }
 
 BOOL LLViewerObject::getLastUpdateCached() const
 {
-	return mLastUpdateCached;
+    return mLastUpdateCached;
 }
 
 void LLViewerObject::setLastUpdateCached(BOOL last_update_cached)
 {
-	mLastUpdateCached = last_update_cached;
+    mLastUpdateCached = last_update_cached;
 }
 
 const LLUUID &LLViewerObject::extractAttachmentItemID()
 {
-	LLUUID item_id = LLUUID::null;
-	LLNameValue* item_id_nv = getNVPair("AttachItemID");
-	if( item_id_nv )
-	{
-		const char* s = item_id_nv->getString();
-		if( s )
-		{
-			item_id.set(s);
-		}
-	}
-	setAttachmentItemID(item_id);
-	return getAttachmentItemID();
+    LLUUID item_id = LLUUID::null;
+    LLNameValue* item_id_nv = getNVPair("AttachItemID");
+    if( item_id_nv )
+    {
+        const char* s = item_id_nv->getString();
+        if( s )
+        {
+            item_id.set(s);
+        }
+    }
+    setAttachmentItemID(item_id);
+    return getAttachmentItemID();
 }
 
 const std::string& LLViewerObject::getAttachmentItemName() const
 {
-	static std::string empty;
-	LLInventoryItem *item = gInventory.getItem(getAttachmentItemID());
-	if (isAttachment() && item)
-	{
-		return item->getName();
-	}
-	return empty;
+    static std::string empty;
+    LLInventoryItem *item = gInventory.getItem(getAttachmentItemID());
+    if (isAttachment() && item)
+    {
+        return item->getName();
+    }
+    return empty;
 }
 
 //virtual
@@ -7422,19 +7422,19 @@ LLVOAvatar* LLViewerObject::getAvatar() const
     {
         return getControlAvatar();
     }
-	if (isAttachment())
-	{
-		LLViewerObject* vobj = (LLViewerObject*) getParent();
+    if (isAttachment())
+    {
+        LLViewerObject* vobj = (LLViewerObject*) getParent();
 
-		while (vobj && !vobj->asAvatar())
-		{
-			vobj = (LLViewerObject*) vobj->getParent();
-		}
+        while (vobj && !vobj->asAvatar())
+        {
+            vobj = (LLViewerObject*) vobj->getParent();
+        }
 
-		return (LLVOAvatar*) vobj;
-	}
+        return (LLVOAvatar*) vobj;
+    }
 
-	return NULL;
+    return NULL;
 }
 
 bool LLViewerObject::hasRenderMaterialParams() const
@@ -7514,12 +7514,12 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat
     {
         new_material = gGLTFMaterialList.getMaterial(id);
     }
-        
+
     // update local state
     for (S32 te = start_idx; te < end_idx; ++te)
     {
         LLTextureEntry* tep = getTE(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
@@ -7528,7 +7528,7 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat
         bool material_changed = !local_origin || !param_block || id != param_block->getMaterial(te);
 
         if (update_server)
-        { 
+        {
             // Clear most overrides so the render material better matches the material
             // ID (preserve transforms). If overrides become passthrough, set the overrides
             // to nullptr.
@@ -7539,7 +7539,7 @@ void LLViewerObject::setRenderMaterialID(S32 te_in, const LLUUID& id, bool updat
         }
 
         if (update_server || material_changed)
-        { 
+        {
             tep->setGLTFRenderMaterial(nullptr);
         }
 
@@ -7656,53 +7656,53 @@ void LLViewerObject::shrinkWrap()
 class ObjectPhysicsProperties : public LLHTTPNode
 {
 public:
-	virtual void post(
-		ResponsePtr responder,
-		const LLSD& context,
-		const LLSD& input) const
-	{
-		LLSD object_data = input["body"]["ObjectData"];
-		S32 num_entries = object_data.size();
-		
-		for ( S32 i = 0; i < num_entries; i++ )
-		{
-			LLSD& curr_object_data = object_data[i];
-			U32 local_id = curr_object_data["LocalID"].asInteger();
-
-			// Iterate through nodes at end, since it can be on both the regular AND hover list
-			struct f : public LLSelectedNodeFunctor
-			{
-				U32 mID;
-				f(const U32& id) : mID(id) {}
-				virtual bool apply(LLSelectNode* node)
-				{
-					return (node->getObject() && node->getObject()->mLocalID == mID );
-				}
-			} func(local_id);
-
-			LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstNode(&func);
-
-			if (node)
-			{
-				// The LLSD message builder doesn't know how to handle U8, so we need to send as S8 and cast
-				U8 type = (U8)curr_object_data["PhysicsShapeType"].asInteger();
-				F32 density = (F32)curr_object_data["Density"].asReal();
-				F32 friction = (F32)curr_object_data["Friction"].asReal();
-				F32 restitution = (F32)curr_object_data["Restitution"].asReal();
-				F32 gravity = (F32)curr_object_data["GravityMultiplier"].asReal();
-
-				node->getObject()->setPhysicsShapeType(type);
-				node->getObject()->setPhysicsGravity(gravity);
-				node->getObject()->setPhysicsFriction(friction);
-				node->getObject()->setPhysicsDensity(density);
-				node->getObject()->setPhysicsRestitution(restitution);
-			}	
-		}
-		
-		dialog_refresh_all();
-	};
+    virtual void post(
+        ResponsePtr responder,
+        const LLSD& context,
+        const LLSD& input) const
+    {
+        LLSD object_data = input["body"]["ObjectData"];
+        S32 num_entries = object_data.size();
+
+        for ( S32 i = 0; i < num_entries; i++ )
+        {
+            LLSD& curr_object_data = object_data[i];
+            U32 local_id = curr_object_data["LocalID"].asInteger();
+
+            // Iterate through nodes at end, since it can be on both the regular AND hover list
+            struct f : public LLSelectedNodeFunctor
+            {
+                U32 mID;
+                f(const U32& id) : mID(id) {}
+                virtual bool apply(LLSelectNode* node)
+                {
+                    return (node->getObject() && node->getObject()->mLocalID == mID );
+                }
+            } func(local_id);
+
+            LLSelectNode* node = LLSelectMgr::getInstance()->getSelection()->getFirstNode(&func);
+
+            if (node)
+            {
+                // The LLSD message builder doesn't know how to handle U8, so we need to send as S8 and cast
+                U8 type = (U8)curr_object_data["PhysicsShapeType"].asInteger();
+                F32 density = (F32)curr_object_data["Density"].asReal();
+                F32 friction = (F32)curr_object_data["Friction"].asReal();
+                F32 restitution = (F32)curr_object_data["Restitution"].asReal();
+                F32 gravity = (F32)curr_object_data["GravityMultiplier"].asReal();
+
+                node->getObject()->setPhysicsShapeType(type);
+                node->getObject()->setPhysicsGravity(gravity);
+                node->getObject()->setPhysicsFriction(friction);
+                node->getObject()->setPhysicsDensity(density);
+                node->getObject()->setPhysicsRestitution(restitution);
+            }
+        }
+
+        dialog_refresh_all();
+    };
 };
 
 LLHTTPRegistration<ObjectPhysicsProperties>
-	gHTTPRegistrationObjectPhysicsProperties("/message/ObjectPhysicsProperties");
+    gHTTPRegistrationObjectPhysicsProperties("/message/ObjectPhysicsProperties");
 
diff --git a/indra/newview/llviewerobject.h b/indra/newview/llviewerobject.h
index 8a639934d6bd5c890cd7e71f5023aabc1eac8222..c5176503eb964855db62f477709fa628616f8b2b 100644
--- a/indra/newview/llviewerobject.h
+++ b/indra/newview/llviewerobject.h
@@ -5,21 +5,21 @@
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -47,7 +47,7 @@
 #include "llreflectionmap.h"
 #include "gltf/asset.h"
 
-class LLAgent;			// TODO: Get rid of this.
+class LLAgent;          // TODO: Get rid of this.
 class LLAudioSource;
 class LLAudioSourceVO;
 class LLColor4;
@@ -77,129 +77,129 @@ class LLMeshCostData;
 
 typedef enum e_object_update_type
 {
-	OUT_FULL,
-	OUT_TERSE_IMPROVED,
-	OUT_FULL_COMPRESSED,
-	OUT_FULL_CACHED,
-	OUT_UNKNOWN,
+    OUT_FULL,
+    OUT_TERSE_IMPROVED,
+    OUT_FULL_COMPRESSED,
+    OUT_FULL_CACHED,
+    OUT_UNKNOWN,
 } EObjectUpdateType;
 
 
 // callback typedef for inventory
 typedef void (*inventory_callback)(LLViewerObject*,
-								   LLInventoryObject::object_list_t*,
-								   S32 serial_num,
-								   void*);
+                                   LLInventoryObject::object_list_t*,
+                                   S32 serial_num,
+                                   void*);
 
 // for exporting textured materials from SL
 struct LLMaterialExportInfo
 {
 public:
-	LLMaterialExportInfo(S32 mat_index, S32 texture_index, LLColor4 color) : 
-	  mMaterialIndex(mat_index), mTextureIndex(texture_index), mColor(color) {};
+    LLMaterialExportInfo(S32 mat_index, S32 texture_index, LLColor4 color) :
+      mMaterialIndex(mat_index), mTextureIndex(texture_index), mColor(color) {};
 
-	S32			mMaterialIndex;
-	S32			mTextureIndex;
-	LLColor4	mColor;
+    S32         mMaterialIndex;
+    S32         mTextureIndex;
+    LLColor4    mColor;
 };
 
 struct PotentialReturnableObject
 {
-	LLBBox			box;
-	LLViewerRegion* pRegion;
+    LLBBox          box;
+    LLViewerRegion* pRegion;
 };
 
 //============================================================================
 
-class LLViewerObject 
-:	public LLPrimitive, 
-	public LLRefCount, 
-	public LLGLUpdate
+class LLViewerObject
+:   public LLPrimitive,
+    public LLRefCount,
+    public LLGLUpdate
 {
 protected:
-	virtual ~LLViewerObject(); // use unref()
+    virtual ~LLViewerObject(); // use unref()
 
 private:
-	struct ExtraParameter
-	{
-		bool is_invalid = false;
-		bool* in_use = nullptr;
-		LLNetworkData* data = nullptr;
-	};
-	std::vector<ExtraParameter> mExtraParameterList;
-	bool mFlexibleObjectDataInUse = false;
-	bool mLightParamsInUse = false;
-	bool mSculptParamsInUse = false;
-	bool mLightImageParamsInUse = false;
-	bool mExtendedMeshParamsInUse = false;
-	bool mRenderMaterialParamsInUse = false;
-	bool mReflectionProbeParamsInUse = false;
-	std::unique_ptr<LLFlexibleObjectData> mFlexibleObjectData;
-	std::unique_ptr<LLLightParams> mLightParams;
-	std::unique_ptr<LLSculptParams> mSculptParams;
-	std::unique_ptr<LLLightImageParams> mLightImageParams;
-	std::unique_ptr<LLExtendedMeshParams> mExtendedMeshParams;
-	std::unique_ptr<LLRenderMaterialParams> mRenderMaterialParams;
-	std::unique_ptr<LLReflectionProbeParams> mReflectionProbeParams;
+    struct ExtraParameter
+    {
+        bool is_invalid = false;
+        bool* in_use = nullptr;
+        LLNetworkData* data = nullptr;
+    };
+    std::vector<ExtraParameter> mExtraParameterList;
+    bool mFlexibleObjectDataInUse = false;
+    bool mLightParamsInUse = false;
+    bool mSculptParamsInUse = false;
+    bool mLightImageParamsInUse = false;
+    bool mExtendedMeshParamsInUse = false;
+    bool mRenderMaterialParamsInUse = false;
+    bool mReflectionProbeParamsInUse = false;
+    std::unique_ptr<LLFlexibleObjectData> mFlexibleObjectData;
+    std::unique_ptr<LLLightParams> mLightParams;
+    std::unique_ptr<LLSculptParams> mSculptParams;
+    std::unique_ptr<LLLightImageParams> mLightImageParams;
+    std::unique_ptr<LLExtendedMeshParams> mExtendedMeshParams;
+    std::unique_ptr<LLRenderMaterialParams> mRenderMaterialParams;
+    std::unique_ptr<LLReflectionProbeParams> mReflectionProbeParams;
 
 public:
-	typedef std::list<LLPointer<LLViewerObject> > child_list_t;
-	typedef std::list<LLPointer<LLViewerObject> > vobj_list_t;
+    typedef std::list<LLPointer<LLViewerObject> > child_list_t;
+    typedef std::list<LLPointer<LLViewerObject> > vobj_list_t;
 
-	typedef const child_list_t const_child_list_t;
+    typedef const child_list_t const_child_list_t;
 
-	LLViewerObject(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp, BOOL is_global = FALSE);
+    LLViewerObject(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp, BOOL is_global = FALSE);
 
-	virtual void resetVertexBuffers() {}
-	virtual void markDead();				// Mark this object as dead, and clean up its references
-	BOOL isDead() const									{return mDead;}
-	BOOL isOrphaned() const								{ return mOrphaned; }
-	BOOL isParticleSource() const;
+    virtual void resetVertexBuffers() {}
+    virtual void markDead();                // Mark this object as dead, and clean up its references
+    BOOL isDead() const                                 {return mDead;}
+    BOOL isOrphaned() const                             { return mOrphaned; }
+    BOOL isParticleSource() const;
 
-	virtual LLVOAvatar* asAvatar();
-	virtual LLVOVolume* asVolume();
+    virtual LLVOAvatar* asAvatar();
+    virtual LLVOVolume* asVolume();
 
-	LLVOAvatar* getAvatarAncestor();
+    LLVOAvatar* getAvatarAncestor();
 
-	static void initVOClasses();
-	static void cleanupVOClasses();
+    static void initVOClasses();
+    static void cleanupVOClasses();
 
-	void			addNVPair(const std::string& data);
-	BOOL			removeNVPair(const std::string& name);
-	LLNameValue*	getNVPair(const std::string& name) const;			// null if no name value pair by that name
+    void            addNVPair(const std::string& data);
+    BOOL            removeNVPair(const std::string& name);
+    LLNameValue*    getNVPair(const std::string& name) const;           // null if no name value pair by that name
 
-	// Object create and update functions
-	virtual void	idleUpdate(LLAgent &agent, const F64 &time);
+    // Object create and update functions
+    virtual void    idleUpdate(LLAgent &agent, const F64 &time);
 
-	// Types of media we can associate
-	enum { MEDIA_NONE = 0, MEDIA_SET = 1 };
+    // Types of media we can associate
+    enum { MEDIA_NONE = 0, MEDIA_SET = 1 };
 
-	// Return codes for processUpdateMessage
-	enum { 
-        MEDIA_URL_REMOVED = 0x1, 
-        MEDIA_URL_ADDED = 0x2, 
-        MEDIA_URL_UPDATED = 0x4, 
+    // Return codes for processUpdateMessage
+    enum {
+        MEDIA_URL_REMOVED = 0x1,
+        MEDIA_URL_ADDED = 0x2,
+        MEDIA_URL_UPDATED = 0x4,
         MEDIA_FLAGS_CHANGED = 0x8,
         INVALID_UPDATE = 0x80000000
     };
 
-	static  U32     extractSpatialExtents(LLDataPackerBinaryBuffer *dp, LLVector3& pos, LLVector3& scale, LLQuaternion& rot);
-	virtual U32		processUpdateMessage(LLMessageSystem *mesgsys,
-										void **user_data,
-										U32 block_num,
-										const EObjectUpdateType update_type,
-										LLDataPacker *dp);
+    static  U32     extractSpatialExtents(LLDataPackerBinaryBuffer *dp, LLVector3& pos, LLVector3& scale, LLQuaternion& rot);
+    virtual U32     processUpdateMessage(LLMessageSystem *mesgsys,
+                                        void **user_data,
+                                        U32 block_num,
+                                        const EObjectUpdateType update_type,
+                                        LLDataPacker *dp);
+
 
+    virtual BOOL    isActive() const; // Whether this object needs to do an idleUpdate.
+    BOOL            onActiveList() const                {return mOnActiveList;}
+    void            setOnActiveList(BOOL on_active)     { mOnActiveList = on_active; }
 
-	virtual BOOL    isActive() const; // Whether this object needs to do an idleUpdate.
-	BOOL			onActiveList() const				{return mOnActiveList;}
-	void			setOnActiveList(BOOL on_active)		{ mOnActiveList = on_active; }
+    virtual BOOL    isAttachment() const { return FALSE; }
+    const std::string& getAttachmentItemName() const;
 
-	virtual BOOL	isAttachment() const { return FALSE; }
-	const std::string& getAttachmentItemName() const;
+    virtual LLVOAvatar* getAvatar() const;  //get the avatar this object is attached to, or NULL if object is not an attachment
 
-	virtual LLVOAvatar* getAvatar() const;  //get the avatar this object is attached to, or NULL if object is not an attachment
-    
     bool hasRenderMaterialParams() const;
     void setHasRenderMaterialParams(bool has_params);
 
@@ -212,445 +212,445 @@ class LLViewerObject
     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; }
-	virtual BOOL	isTempAttachment() const;
+    virtual BOOL    isHUDAttachment() const { return FALSE; }
+    virtual BOOL    isTempAttachment() const;
 
-	virtual BOOL isHiglightedOrBeacon() const;
+    virtual BOOL isHiglightedOrBeacon() const;
 
-	virtual void 	updateRadius() {};
-	virtual F32 	getVObjRadius() const; // default implemenation is mDrawable->getRadius()
-	
-	// for jointed and other parent-relative hacks
-	LLViewerObject* getSubParent();
-	const LLViewerObject* getSubParent() const;
-	
-	// Object visiblility and GPW functions
-	virtual void setPixelAreaAndAngle(LLAgent &agent); // Override to generate accurate apparent angle and area
+    virtual void    updateRadius() {};
+    virtual F32     getVObjRadius() const; // default implemenation is mDrawable->getRadius()
 
-	virtual U32 getNumVertices() const;
-	virtual U32 getNumIndices() const;
-	S32 getNumFaces() const { return mNumFaces; }
-	S32 getNumVisibleFaces() const;
+    // for jointed and other parent-relative hacks
+    LLViewerObject* getSubParent();
+    const LLViewerObject* getSubParent() const;
 
-	// Graphical stuff for objects - maybe broken out into render class later?
-	virtual void updateTextures();
+    // Object visiblility and GPW functions
+    virtual void setPixelAreaAndAngle(LLAgent &agent); // Override to generate accurate apparent angle and area
+
+    virtual U32 getNumVertices() const;
+    virtual U32 getNumIndices() const;
+    S32 getNumFaces() const { return mNumFaces; }
+    S32 getNumVisibleFaces() const;
+
+    // Graphical stuff for objects - maybe broken out into render class later?
+    virtual void updateTextures();
     virtual void faceMappingChanged() {}
-	virtual void boostTexturePriority(BOOL boost_children = TRUE);	// When you just want to boost priority of this object
-	
-	virtual LLDrawable* createDrawable(LLPipeline *pipeline);
-	virtual BOOL		updateGeometry(LLDrawable *drawable);
-	virtual void		updateGL();
-	virtual void		updateFaceSize(S32 idx);
-	virtual BOOL		updateLOD();
-	virtual BOOL		setDrawableParent(LLDrawable* parentp);
-	F32					getRotTime() { return mRotTime; }
+    virtual void boostTexturePriority(BOOL boost_children = TRUE);  // When you just want to boost priority of this object
+
+    virtual LLDrawable* createDrawable(LLPipeline *pipeline);
+    virtual BOOL        updateGeometry(LLDrawable *drawable);
+    virtual void        updateGL();
+    virtual void        updateFaceSize(S32 idx);
+    virtual BOOL        updateLOD();
+    virtual BOOL        setDrawableParent(LLDrawable* parentp);
+    F32                 getRotTime() { return mRotTime; }
 private:
-	void				resetRotTime();
-    void				setRenderMaterialIDs(const LLRenderMaterialParams* material_params, bool local_origin);
+    void                resetRotTime();
+    void                setRenderMaterialIDs(const LLRenderMaterialParams* material_params, bool local_origin);
     void                rebuildMaterial();
 public:
-	void				resetRot();
-	void				applyAngularVelocity(F32 dt);
+    void                resetRot();
+    void                applyAngularVelocity(F32 dt);
 
-	void setLineWidthForWindowSize(S32 window_width);
+    void setLineWidthForWindowSize(S32 window_width);
 
-	static void increaseArrowLength();				// makes axis arrows for selections longer
-	static void decreaseArrowLength();				// makes axis arrows for selections shorter
+    static void increaseArrowLength();              // makes axis arrows for selections longer
+    static void decreaseArrowLength();              // makes axis arrows for selections shorter
 
-	// Accessor functions
-	LLViewerRegion* getRegion() const				{ return mRegionp; }
+    // Accessor functions
+    LLViewerRegion* getRegion() const               { return mRegionp; }
 
-	BOOL isSelected() const							{ return mUserSelected; }
+    BOOL isSelected() const                         { return mUserSelected; }
     // Check whole linkset
     BOOL isAnySelected() const;
-	virtual void setSelected(BOOL sel);
-
-	const LLUUID &getID() const						{ return mID; }
-	U32 getLocalID() const							{ return mLocalID; }
-	U32 getCRC() const								{ return mTotalCRC; }
-	S32 getListIndex() const						{ return mListIndex; }
-	void setListIndex(S32 idx)						{ mListIndex = idx; }
-
-	virtual BOOL isFlexible() const					{ return FALSE; }
-	virtual BOOL isSculpted() const 				{ return FALSE; }
-	virtual BOOL isMesh() const						{ return FALSE; }
-	virtual BOOL isRiggedMesh() const				{ return FALSE; }
-	virtual BOOL hasLightTexture() const			{ return FALSE; }
+    virtual void setSelected(BOOL sel);
+
+    const LLUUID &getID() const                     { return mID; }
+    U32 getLocalID() const                          { return mLocalID; }
+    U32 getCRC() const                              { return mTotalCRC; }
+    S32 getListIndex() const                        { return mListIndex; }
+    void setListIndex(S32 idx)                      { mListIndex = idx; }
+
+    virtual BOOL isFlexible() const                 { return FALSE; }
+    virtual BOOL isSculpted() const                 { return FALSE; }
+    virtual BOOL isMesh() const                     { return FALSE; }
+    virtual BOOL isRiggedMesh() const               { return FALSE; }
+    virtual BOOL hasLightTexture() const            { return FALSE; }
     virtual BOOL isReflectionProbe() const          { return FALSE; }
 
-	// This method returns true if the object is over land owned by
-	// the agent, one of its groups, or it encroaches and 
-	// anti-encroachment is enabled
-	bool isReturnable();
+    // This method returns true if the object is over land owned by
+    // the agent, one of its groups, or it encroaches and
+    // anti-encroachment is enabled
+    bool isReturnable();
 
-	void buildReturnablesForChildrenVO( std::vector<PotentialReturnableObject>& returnables, LLViewerObject* pChild, LLViewerRegion* pTargetRegion );
-	void constructAndAddReturnable( std::vector<PotentialReturnableObject>& returnables, LLViewerObject* pChild, LLViewerRegion* pTargetRegion );
+    void buildReturnablesForChildrenVO( std::vector<PotentialReturnableObject>& returnables, LLViewerObject* pChild, LLViewerRegion* pTargetRegion );
+    void constructAndAddReturnable( std::vector<PotentialReturnableObject>& returnables, LLViewerObject* pChild, LLViewerRegion* pTargetRegion );
 
-	// This method returns true if the object crosses
-	// any parcel bounds in the region.
-	bool crossesParcelBounds();
+    // This method returns true if the object crosses
+    // any parcel bounds in the region.
+    bool crossesParcelBounds();
 
-	/*
-	// This method will scan through this object, and then query the
-	// selection manager to see if the local agent probably has the
-	// ability to modify the object. Since this calls into the
-	// selection manager, you should avoid calling this method from
-	// there.
-	BOOL isProbablyModifiable() const;
-	*/
+    /*
+    // This method will scan through this object, and then query the
+    // selection manager to see if the local agent probably has the
+    // ability to modify the object. Since this calls into the
+    // selection manager, you should avoid calling this method from
+    // there.
+    BOOL isProbablyModifiable() const;
+    */
 
-	virtual BOOL setParent(LLViewerObject* parent);
+    virtual BOOL setParent(LLViewerObject* parent);
     virtual void onReparent(LLViewerObject *old_parent, LLViewerObject *new_parent);
     virtual void afterReparent();
-	virtual void addChild(LLViewerObject *childp);
-	virtual void removeChild(LLViewerObject *childp);
-	const_child_list_t& getChildren() const { 	return mChildList; }
-	S32 numChildren() const { return mChildList.size(); }
-	void addThisAndAllChildren(std::vector<LLViewerObject*>& objects);
-	void addThisAndNonJointChildren(std::vector<LLViewerObject*>& objects);
-//	BOOL isChild(LLViewerObject *childp) const;
+    virtual void addChild(LLViewerObject *childp);
+    virtual void removeChild(LLViewerObject *childp);
+    const_child_list_t& getChildren() const {   return mChildList; }
+    S32 numChildren() const { return mChildList.size(); }
+    void addThisAndAllChildren(std::vector<LLViewerObject*>& objects);
+    void addThisAndNonJointChildren(std::vector<LLViewerObject*>& objects);
+//  BOOL isChild(LLViewerObject *childp) const;
 // [RLVa:KB] - Checked: 2011-05-28 (RLVa-1.4.0a) | Added: RLVa-1.4.0a
-	BOOL isChild(const LLViewerObject *childp) const;
+    BOOL isChild(const LLViewerObject *childp) const;
 // [/RLVa:KB]
-	BOOL isSeat() const;
-	
-
-	//detect if given line segment (in agent space) intersects with this viewer object.
-	//returns TRUE if intersection detected and returns information about intersection
-	virtual BOOL lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
-									  S32 face = -1,                          // which face to check, -1 = ALL_SIDES
-									  BOOL pick_transparent = FALSE,
-									  BOOL pick_rigged = FALSE,
+    BOOL isSeat() const;
+
+
+    //detect if given line segment (in agent space) intersects with this viewer object.
+    //returns TRUE if intersection detected and returns information about intersection
+    virtual BOOL lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
+                                      S32 face = -1,                          // which face to check, -1 = ALL_SIDES
+                                      BOOL pick_transparent = FALSE,
+                                      BOOL pick_rigged = FALSE,
                                       BOOL pick_unselectable = TRUE,
-									  S32* face_hit = NULL,                   // which face was hit
-									  LLVector4a* intersection = NULL,         // return the intersection point
-									  LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
-									  LLVector4a* normal = NULL,               // return the surface normal at the intersection point
-									  LLVector4a* tangent = NULL             // return the surface tangent at the intersection point
-		);
-	
-	virtual BOOL lineSegmentBoundingBox(const LLVector4a& start, const LLVector4a& end);
-
-	virtual const LLVector3d getPositionGlobal() const;
-	virtual const LLVector3 &getPositionRegion() const;
-	virtual const LLVector3 getPositionEdit() const;
-	virtual const LLVector3 &getPositionAgent() const;
-	virtual const LLVector3 getRenderPosition() const;
+                                      S32* face_hit = NULL,                   // which face was hit
+                                      LLVector4a* intersection = NULL,         // return the intersection point
+                                      LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
+                                      LLVector4a* normal = NULL,               // return the surface normal at the intersection point
+                                      LLVector4a* tangent = NULL             // return the surface tangent at the intersection point
+        );
+
+    virtual BOOL lineSegmentBoundingBox(const LLVector4a& start, const LLVector4a& end);
+
+    virtual const LLVector3d getPositionGlobal() const;
+    virtual const LLVector3 &getPositionRegion() const;
+    virtual const LLVector3 getPositionEdit() const;
+    virtual const LLVector3 &getPositionAgent() const;
+    virtual const LLVector3 getRenderPosition() const;
 
     LLMatrix4a getAgentToGLTFAssetTransform() const;
     LLMatrix4a getGLTFAssetToAgentTransform() const;
     LLVector3 getGLTFNodePositionAgent(S32 node_index) const;
     LLMatrix4a getGLTFNodeTransformAgent(S32 node_index) const;
     void getGLTFNodeTransformAgent(S32 node_index, LLVector3* position, LLQuaternion* rotation, LLVector3* scale) const;
-    
+
     // move the node at the given index by the given offset in agent space
     void moveGLTFNode(S32 node_index, const LLVector3& offset);
 
     // set the rotation in agent space of the given node
     void setGLTFNodeRotationAgent(S32 node_index, const LLQuaternion& rotation);
 
-	virtual const LLVector3 getPivotPositionAgent() const; // Usually = to getPositionAgent, unless like flex objects it's not
+    virtual const LLVector3 getPivotPositionAgent() const; // Usually = to getPositionAgent, unless like flex objects it's not
 
-	LLViewerObject* getRootEdit() const;
+    LLViewerObject* getRootEdit() const;
 
-	const LLQuaternion getRotationRegion() const;
-	const LLQuaternion getRotationEdit() const;
-	const LLQuaternion getRenderRotation() const;
-	virtual	const LLMatrix4a& getRenderMatrix() const;
+    const LLQuaternion getRotationRegion() const;
+    const LLQuaternion getRotationEdit() const;
+    const LLQuaternion getRenderRotation() const;
+    virtual const LLMatrix4a& getRenderMatrix() const;
 
-	void setPosition(const LLVector3 &pos, BOOL damped = FALSE);
-	void setPositionGlobal(const LLVector3d &position, BOOL damped = FALSE);
-	void setPositionRegion(const LLVector3 &position, BOOL damped = FALSE);
-	void setPositionEdit(const LLVector3 &position, BOOL damped = FALSE);
-	void setPositionAgent(const LLVector3 &pos_agent, BOOL damped = FALSE);
-	void setPositionParent(const LLVector3 &pos_parent, BOOL damped = FALSE);
-	void setPositionAbsoluteGlobal( const LLVector3d &pos_global, BOOL damped = FALSE );
+    void setPosition(const LLVector3 &pos, BOOL damped = FALSE);
+    void setPositionGlobal(const LLVector3d &position, BOOL damped = FALSE);
+    void setPositionRegion(const LLVector3 &position, BOOL damped = FALSE);
+    void setPositionEdit(const LLVector3 &position, BOOL damped = FALSE);
+    void setPositionAgent(const LLVector3 &pos_agent, BOOL damped = FALSE);
+    void setPositionParent(const LLVector3 &pos_parent, BOOL damped = FALSE);
+    void setPositionAbsoluteGlobal( const LLVector3d &pos_global, BOOL damped = FALSE );
 
-	virtual const LLMatrix4a& getWorldMatrix(LLXformMatrix* xform) const		{ return xform->getWorldMatrix(); }
+    virtual const LLMatrix4a& getWorldMatrix(LLXformMatrix* xform) const        { return xform->getWorldMatrix(); }
 
-	inline void setRotation(const F32 x, const F32 y, const F32 z, BOOL damped = FALSE);
-	inline void setRotation(const LLQuaternion& quat, BOOL damped = FALSE);
+    inline void setRotation(const F32 x, const F32 y, const F32 z, BOOL damped = FALSE);
+    inline void setRotation(const LLQuaternion& quat, BOOL damped = FALSE);
 
-	/*virtual*/	void	setNumTEs(const U8 num_tes);
-	/*virtual*/	void	setTE(const U8 te, const LLTextureEntry &texture_entry);
+    /*virtual*/ void    setNumTEs(const U8 num_tes);
+    /*virtual*/ void    setTE(const U8 te, const LLTextureEntry &texture_entry);
     void updateTEMaterialTextures(U8 te);
-	/*virtual*/ S32		setTETexture(const U8 te, const LLUUID &uuid);
-	/*virtual*/ S32		setTENormalMap(const U8 te, const LLUUID &uuid);
-	/*virtual*/ S32		setTESpecularMap(const U8 te, const LLUUID &uuid);
-	S32 				setTETextureCore(const U8 te, LLViewerTexture *image);
-	S32 setTENormalMapCore(const U8 te, LLViewerTexture *image);
-	S32 setTESpecularMapCore(const U8 te, LLViewerTexture *image);
-	/*virtual*/ S32		setTEColor(const U8 te, const LLColor3 &color);
-	/*virtual*/ S32		setTEColor(const U8 te, const LLColor4 &color);
-	/*virtual*/ S32		setTEScale(const U8 te, const F32 s, const F32 t);
-	/*virtual*/ S32		setTEScaleS(const U8 te, const F32 s);
-	/*virtual*/ S32		setTEScaleT(const U8 te, const F32 t);
-	/*virtual*/ S32		setTEOffset(const U8 te, const F32 s, const F32 t);
-	/*virtual*/ S32		setTEOffsetS(const U8 te, const F32 s);
-	/*virtual*/ S32		setTEOffsetT(const U8 te, const F32 t);
-	/*virtual*/ S32		setTERotation(const U8 te, const F32 r);
-	/*virtual*/	S32		setTEBumpmap(const U8 te, const U8 bump );
-	/*virtual*/	S32		setTETexGen(const U8 te, const U8 texgen );
-	/*virtual*/	S32		setTEMediaTexGen(const U8 te, const U8 media ); // *FIXME: this confusingly acts upon a superset of setTETexGen's flags without absorbing its semantics
-	/*virtual*/	S32		setTEShiny(const U8 te, const U8 shiny );
-	/*virtual*/	S32		setTEFullbright(const U8 te, const U8 fullbright );
-	/*virtual*/	S32		setTEMediaFlags(const U8 te, const U8 media_flags );
-	/*virtual*/ S32     setTEGlow(const U8 te, const F32 glow);
-	/*virtual*/ S32     setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID);
-	/*virtual*/ S32		setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams);
+    /*virtual*/ S32     setTETexture(const U8 te, const LLUUID &uuid);
+    /*virtual*/ S32     setTENormalMap(const U8 te, const LLUUID &uuid);
+    /*virtual*/ S32     setTESpecularMap(const U8 te, const LLUUID &uuid);
+    S32                 setTETextureCore(const U8 te, LLViewerTexture *image);
+    S32 setTENormalMapCore(const U8 te, LLViewerTexture *image);
+    S32 setTESpecularMapCore(const U8 te, LLViewerTexture *image);
+    /*virtual*/ S32     setTEColor(const U8 te, const LLColor3 &color);
+    /*virtual*/ S32     setTEColor(const U8 te, const LLColor4 &color);
+    /*virtual*/ S32     setTEScale(const U8 te, const F32 s, const F32 t);
+    /*virtual*/ S32     setTEScaleS(const U8 te, const F32 s);
+    /*virtual*/ S32     setTEScaleT(const U8 te, const F32 t);
+    /*virtual*/ S32     setTEOffset(const U8 te, const F32 s, const F32 t);
+    /*virtual*/ S32     setTEOffsetS(const U8 te, const F32 s);
+    /*virtual*/ S32     setTEOffsetT(const U8 te, const F32 t);
+    /*virtual*/ S32     setTERotation(const U8 te, const F32 r);
+    /*virtual*/ S32     setTEBumpmap(const U8 te, const U8 bump );
+    /*virtual*/ S32     setTETexGen(const U8 te, const U8 texgen );
+    /*virtual*/ S32     setTEMediaTexGen(const U8 te, const U8 media ); // *FIXME: this confusingly acts upon a superset of setTETexGen's flags without absorbing its semantics
+    /*virtual*/ S32     setTEShiny(const U8 te, const U8 shiny );
+    /*virtual*/ S32     setTEFullbright(const U8 te, const U8 fullbright );
+    /*virtual*/ S32     setTEMediaFlags(const U8 te, const U8 media_flags );
+    /*virtual*/ S32     setTEGlow(const U8 te, const F32 glow);
+    /*virtual*/ S32     setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID);
+    /*virtual*/ S32     setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams);
     virtual     S32     setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* mat);
 
-	// Used by Materials update functions to properly kick off rebuilds
-	// of VBs etc when materials updates require changes.
-	//
-	void refreshMaterials();
+    // Used by Materials update functions to properly kick off rebuilds
+    // of VBs etc when materials updates require changes.
+    //
+    void refreshMaterials();
+
+    /*virtual*/ BOOL    setMaterial(const U8 material);
+    virtual     void    setTEImage(const U8 te, LLViewerTexture *imagep); // Not derived from LLPrimitive
+    virtual     void    changeTEImage(S32 index, LLViewerTexture* new_image)  ;
+    virtual     void    changeTENormalMap(S32 index, LLViewerTexture* new_image)  ;
+    virtual     void    changeTESpecularMap(S32 index, LLViewerTexture* new_image)  ;
+    LLViewerTexture     *getTEImage(const U8 te) const;
+    LLViewerTexture     *getTENormalMap(const U8 te) const;
+    LLViewerTexture     *getTESpecularMap(const U8 te) const;
 
-	/*virtual*/	BOOL	setMaterial(const U8 material);
-	virtual		void	setTEImage(const U8 te, LLViewerTexture *imagep); // Not derived from LLPrimitive
-	virtual     void    changeTEImage(S32 index, LLViewerTexture* new_image)  ;
-	virtual     void    changeTENormalMap(S32 index, LLViewerTexture* new_image)  ;
-	virtual     void    changeTESpecularMap(S32 index, LLViewerTexture* new_image)  ;
-	LLViewerTexture		*getTEImage(const U8 te) const;
-	LLViewerTexture		*getTENormalMap(const U8 te) const;
-	LLViewerTexture		*getTESpecularMap(const U8 te) const;
+    bool                        isImageAlphaBlended(const U8 te) const;
 
-	bool 						isImageAlphaBlended(const U8 te) const;
+    void fitFaceTexture(const U8 face);
+    void sendTEUpdate() const;          // Sends packed representation of all texture entry information
 
-	void fitFaceTexture(const U8 face);
-	void sendTEUpdate() const;			// Sends packed representation of all texture entry information
-	
-	virtual void setScale(const LLVector3 &scale, BOOL damped = FALSE);
+    virtual void setScale(const LLVector3 &scale, BOOL damped = FALSE);
 
     S32 getAnimatedObjectMaxTris() const;
     F32 recursiveGetEstTrianglesMax() const;
     virtual F32 getEstTrianglesMax() const;
     virtual F32 getEstTrianglesStreamingCost() const;
-	virtual F32 getStreamingCost() const;
+    virtual F32 getStreamingCost() const;
     virtual bool getCostData(LLMeshCostData& costs) const;
-	virtual U32 getTriangleCount(S32* vcount = NULL) const;
-	virtual U32 getHighLODTriangleCount();
+    virtual U32 getTriangleCount(S32* vcount = NULL) const;
+    virtual U32 getHighLODTriangleCount();
     F32 recursiveGetScaledSurfaceArea() const;
 
     U32 recursiveGetTriangleCount(S32* vcount = NULL) const;
 
-	void setObjectCost(F32 cost);
-	F32 getObjectCost();
-	
-	void setLinksetCost(F32 cost);
-	F32 getLinksetCost();
-	
-	void setPhysicsCost(F32 cost);
-	F32 getPhysicsCost();
-	
-	void setLinksetPhysicsCost(F32 cost);
-	F32 getLinksetPhysicsCost();
+    void setObjectCost(F32 cost);
+    F32 getObjectCost();
+
+    void setLinksetCost(F32 cost);
+    F32 getLinksetCost();
+
+    void setPhysicsCost(F32 cost);
+    F32 getPhysicsCost();
 
-	void sendShapeUpdate();
+    void setLinksetPhysicsCost(F32 cost);
+    F32 getLinksetPhysicsCost();
+
+    void sendShapeUpdate();
 
 // [RLVa:KB] - Checked: 2010-02-27 (RLVa-1.2.0a) | Added: RLVa-1.2.0a
-	U8 getAttachmentState() const					{ return mAttachmentState; }
+    U8 getAttachmentState() const                   { return mAttachmentState; }
 // [/RLVa:KB]
-//	U8 getAttachmentState()							{ return mAttachmentState; }
+//  U8 getAttachmentState()                         { return mAttachmentState; }
 
-	F32 getAppAngle() const					{ return mAppAngle; }
-	F32 getPixelArea() const				{ return mPixelArea; }
-	void setPixelArea(F32 area)				{ mPixelArea = area; }
-	F32 getMaxScale() const;
-	F32 getMidScale() const;
-	F32 getMinScale() const;
+    F32 getAppAngle() const                 { return mAppAngle; }
+    F32 getPixelArea() const                { return mPixelArea; }
+    void setPixelArea(F32 area)             { mPixelArea = area; }
+    F32 getMaxScale() const;
+    F32 getMidScale() const;
+    F32 getMinScale() const;
 
-	// Owner id is this object's owner
-	void setAttachedSound(const LLUUID &audio_uuid, const LLUUID& owner_id, const F32 gain, const U8 flags);
-	void adjustAudioGain(const F32 gain);
-	F32  getSoundCutOffRadius() const { return mSoundCutOffRadius; }
-	void clearAttachedSound()								{ mAudioSourcep = NULL; }
+    // Owner id is this object's owner
+    void setAttachedSound(const LLUUID &audio_uuid, const LLUUID& owner_id, const F32 gain, const U8 flags);
+    void adjustAudioGain(const F32 gain);
+    F32  getSoundCutOffRadius() const { return mSoundCutOffRadius; }
+    void clearAttachedSound()                               { mAudioSourcep = NULL; }
 
-	 // Create if necessary
-	LLAudioSource *getAudioSource(const LLUUID& owner_id);
-	BOOL isAudioSource() const {return mAudioSourcep != NULL;}
+     // Create if necessary
+    LLAudioSource *getAudioSource(const LLUUID& owner_id);
+    BOOL isAudioSource() const {return mAudioSourcep != NULL;}
 
-	U8 getMediaType() const;
-	void setMediaType(U8 media_type);
+    U8 getMediaType() const;
+    void setMediaType(U8 media_type);
 
-	std::string getMediaURL() const;
-	void setMediaURL(const std::string& media_url);
+    std::string getMediaURL() const;
+    void setMediaURL(const std::string& media_url);
 
-	BOOL getMediaPassedWhitelist() const;
-	void setMediaPassedWhitelist(BOOL passed);
+    BOOL getMediaPassedWhitelist() const;
+    void setMediaPassedWhitelist(BOOL passed);
 
-	void sendMaterialUpdate() const;
+    void sendMaterialUpdate() const;
 
-	void setDebugText(const std::string &utf8text, const LLColor4& color = LLColor4::white);
-	void appendDebugText(const std::string &utf8text);
-	void initHudText();
-	void restoreHudText();
-	void setIcon(LLViewerTexture* icon_image);
-	void clearIcon();
+    void setDebugText(const std::string &utf8text, const LLColor4& color = LLColor4::white);
+    void appendDebugText(const std::string &utf8text);
+    void initHudText();
+    void restoreHudText();
+    void setIcon(LLViewerTexture* icon_image);
+    void clearIcon();
 
     void recursiveMarkForUpdate();
-	virtual void markForUpdate();
-	void updateVolume(const LLVolumeParams& volume_params);
-	virtual	void updateSpatialExtents(LLVector4a& min, LLVector4a& max);
-	virtual F32 getBinRadius();
-	
-	LLBBox				getBoundingBoxAgent() const;
-
-	void updatePositionCaches() const; // Update the global and region position caches from the object (and parent's) xform.
-	void updateText(); // update text label position
-	virtual void updateDrawable(BOOL force_damped); // force updates on static objects
-
-	bool isOwnerInMuteList(LLUUID item_id = LLUUID());
-
-	void setDrawableState(U32 state, BOOL recursive = TRUE);
-	void clearDrawableState(U32 state, BOOL recursive = TRUE);
-	BOOL isDrawableState(U32 state, BOOL recursive = TRUE) const;
-
-	// Called when the drawable shifts
-	virtual void onShift(const LLVector4a &shift_vector)	{ }
-		
-	//////////////////////////////////////
-	//
-	// Inventory methods
-	//
-
-	// This function is called when someone is interested in a viewer
-	// object's inventory. The callback is called as soon as the
-	// viewer object has the inventory stored locally.
-	void registerInventoryListener(LLVOInventoryListener* listener, void* user_data);
-	void removeInventoryListener(LLVOInventoryListener* listener);
-	BOOL isInventoryPending();
-	void clearInventoryListeners();
-	bool hasInventoryListeners();
-	void requestInventory();
-	static void processTaskInv(LLMessageSystem* msg, void** user_data);
-	void removeInventory(const LLUUID& item_id);
-
-	// The updateInventory() call potentially calls into the selection
-	// manager, so do no call updateInventory() from the selection
-	// manager until we have better iterators.
-	void updateInventory(LLViewerInventoryItem* item, U8 key, bool is_new);
-	void updateInventoryLocal(LLInventoryItem* item, U8 key); // Update without messaging.
-	void updateMaterialInventory(LLViewerInventoryItem* item, U8 key, bool is_new);
-	LLInventoryObject* getInventoryObject(const LLUUID& item_id);
-	LLInventoryItem* getInventoryItem(const LLUUID& item_id);
-
-	// Get content except for root category
-	void getInventoryContents(LLInventoryObject::object_list_t& objects);
-	LLInventoryObject* getInventoryRoot();
-	LLViewerInventoryItem* getInventoryItemByAsset(const LLUUID& asset_id);
+    virtual void markForUpdate();
+    void updateVolume(const LLVolumeParams& volume_params);
+    virtual void updateSpatialExtents(LLVector4a& min, LLVector4a& max);
+    virtual F32 getBinRadius();
+
+    LLBBox              getBoundingBoxAgent() const;
+
+    void updatePositionCaches() const; // Update the global and region position caches from the object (and parent's) xform.
+    void updateText(); // update text label position
+    virtual void updateDrawable(BOOL force_damped); // force updates on static objects
+
+    bool isOwnerInMuteList(LLUUID item_id = LLUUID());
+
+    void setDrawableState(U32 state, BOOL recursive = TRUE);
+    void clearDrawableState(U32 state, BOOL recursive = TRUE);
+    BOOL isDrawableState(U32 state, BOOL recursive = TRUE) const;
+
+    // Called when the drawable shifts
+    virtual void onShift(const LLVector4a &shift_vector)    { }
+
+    //////////////////////////////////////
+    //
+    // Inventory methods
+    //
+
+    // This function is called when someone is interested in a viewer
+    // object's inventory. The callback is called as soon as the
+    // viewer object has the inventory stored locally.
+    void registerInventoryListener(LLVOInventoryListener* listener, void* user_data);
+    void removeInventoryListener(LLVOInventoryListener* listener);
+    BOOL isInventoryPending();
+    void clearInventoryListeners();
+    bool hasInventoryListeners();
+    void requestInventory();
+    static void processTaskInv(LLMessageSystem* msg, void** user_data);
+    void removeInventory(const LLUUID& item_id);
+
+    // The updateInventory() call potentially calls into the selection
+    // manager, so do no call updateInventory() from the selection
+    // manager until we have better iterators.
+    void updateInventory(LLViewerInventoryItem* item, U8 key, bool is_new);
+    void updateInventoryLocal(LLInventoryItem* item, U8 key); // Update without messaging.
+    void updateMaterialInventory(LLViewerInventoryItem* item, U8 key, bool is_new);
+    LLInventoryObject* getInventoryObject(const LLUUID& item_id);
+    LLInventoryItem* getInventoryItem(const LLUUID& item_id);
+
+    // Get content except for root category
+    void getInventoryContents(LLInventoryObject::object_list_t& objects);
+    LLInventoryObject* getInventoryRoot();
+    LLViewerInventoryItem* getInventoryItemByAsset(const LLUUID& asset_id);
     LLViewerInventoryItem* getInventoryItemByAsset(const LLUUID& asset_id, LLAssetType::EType type);
-	S16 getInventorySerial() const { return mInventorySerialNum; }
-
-	// These functions does viewer-side only object inventory modifications
-	void updateViewerInventoryAsset(
-		const LLViewerInventoryItem* item,
-		const LLUUID& new_asset);
-
-	// This function will make sure that we refresh the inventory.
-	void dirtyInventory();
-	BOOL isInventoryDirty() { return mInventoryDirty; }
-
-	// save a script, which involves removing the old one, and rezzing
-	// in the new one. This method should be called with the asset id
-	// of the new and old script AFTER the bytecode has been saved.
-	void saveScript(const LLViewerInventoryItem* item, BOOL active, bool is_new);
-
-	// move an inventory item out of the task and into agent
-	// inventory. This operation is based on messaging. No permissions
-	// checks are made on the viewer - the server will double check.
-	void moveInventory(const LLUUID& agent_folder, const LLUUID& item_id);
-
-	// Find the number of instances of this object's inventory that are of the given type
-	S32 countInventoryContents( LLAssetType::EType type );
-
-	BOOL			permAnyOwner() const;	
-	BOOL			permYouOwner() const;
-	BOOL			permGroupOwner() const;
-	BOOL			permOwnerModify() const;
-	BOOL			permModify() const;	
-	BOOL			permCopy() const;	
-	BOOL			permMove() const;		
-	BOOL			permTransfer() const;
-	inline BOOL		flagUsePhysics() const			{ return ((mFlags & FLAGS_USE_PHYSICS) != 0); }
-	inline BOOL		flagObjectAnyOwner() const		{ return ((mFlags & FLAGS_OBJECT_ANY_OWNER) != 0); }
-	inline BOOL		flagObjectYouOwner() const		{ return ((mFlags & FLAGS_OBJECT_YOU_OWNER) != 0); }
-	inline BOOL		flagObjectGroupOwned() const	{ return ((mFlags & FLAGS_OBJECT_GROUP_OWNED) != 0); }
-	inline BOOL		flagObjectOwnerModify() const	{ return ((mFlags & FLAGS_OBJECT_OWNER_MODIFY) != 0); }
-	inline BOOL		flagObjectModify() const		{ return ((mFlags & FLAGS_OBJECT_MODIFY) != 0); }
-	inline BOOL		flagObjectCopy() const			{ return ((mFlags & FLAGS_OBJECT_COPY) != 0); }
-	inline BOOL		flagObjectMove() const			{ return ((mFlags & FLAGS_OBJECT_MOVE) != 0); }
-	inline BOOL		flagObjectTransfer() const		{ return ((mFlags & FLAGS_OBJECT_TRANSFER) != 0); }
-	inline BOOL		flagObjectPermanent() const		{ return ((mFlags & FLAGS_AFFECTS_NAVMESH) != 0); }
-	inline BOOL		flagCharacter() const			{ return ((mFlags & FLAGS_CHARACTER) != 0); }
-	inline BOOL		flagVolumeDetect() const		{ return ((mFlags & FLAGS_VOLUME_DETECT) != 0); }
-	inline BOOL		flagIncludeInSearch() const     { return ((mFlags & FLAGS_INCLUDE_IN_SEARCH) != 0); }
-	inline BOOL		flagScripted() const			{ return ((mFlags & FLAGS_SCRIPTED) != 0); }
-	inline BOOL		flagHandleTouch() const			{ return ((mFlags & FLAGS_HANDLE_TOUCH) != 0); }
-	inline BOOL		flagTakesMoney() const			{ return ((mFlags & FLAGS_TAKES_MONEY) != 0); }
-	inline BOOL		flagPhantom() const				{ return ((mFlags & FLAGS_PHANTOM) != 0); }
-	inline BOOL		flagInventoryEmpty() const		{ return ((mFlags & FLAGS_INVENTORY_EMPTY) != 0); }
-	inline BOOL		flagAllowInventoryAdd() const	{ return ((mFlags & FLAGS_ALLOW_INVENTORY_DROP) != 0); }
-	inline BOOL		flagTemporaryOnRez() const		{ return ((mFlags & FLAGS_TEMPORARY_ON_REZ) != 0); }
-	inline BOOL		flagAnimSource() const			{ return ((mFlags & FLAGS_ANIM_SOURCE) != 0); }
-	inline BOOL		flagCameraSource() const		{ return ((mFlags & FLAGS_CAMERA_SOURCE) != 0); }
-	inline BOOL		flagCameraDecoupled() const		{ return ((mFlags & FLAGS_CAMERA_DECOUPLED) != 0); }
-
-	U8       getPhysicsShapeType() const;
-	inline F32      getPhysicsGravity() const       { return mPhysicsGravity; }
-	inline F32      getPhysicsFriction() const      { return mPhysicsFriction; }
-	inline F32      getPhysicsDensity() const       { return mPhysicsDensity; }
-	inline F32      getPhysicsRestitution() const   { return mPhysicsRestitution; }
-
-	bool            isPermanentEnforced() const;
-	
-	bool getIncludeInSearch() const;
-	void setIncludeInSearch(bool include_in_search);
-
-	// Does "open" object menu item apply?
-	BOOL allowOpen() const;
-
-	void setClickAction(U8 action) { mClickAction = action; }
-	U8 getClickAction() const { return mClickAction; }
-	bool specialHoverCursor() const;	// does it have a special hover cursor?
-
-	void			setRegion(LLViewerRegion *regionp);
-	virtual void	updateRegion(LLViewerRegion *regionp);
-
-	void updateFlags(BOOL physics_changed = FALSE);
-	void loadFlags(U32 flags); //load flags from cache or from message
-	BOOL setFlags(U32 flag, BOOL state);
-	BOOL setFlagsWithoutUpdate(U32 flag, BOOL state);
-	void setPhysicsShapeType(U8 type);
-	void setPhysicsGravity(F32 gravity);
-	void setPhysicsFriction(F32 friction);
-	void setPhysicsDensity(F32 density);
-	void setPhysicsRestitution(F32 restitution);
-	
-	virtual void dump() const;
-	static U32		getNumZombieObjects()			{ return sNumZombieObjects; }
-
-	void printNameValuePairs() const;
-
-	virtual S32 getLOD() const { return 3; } 
-	virtual U32 getPartitionType() const;
-	void dirtySpatialGroup() const;
-	virtual void dirtyMesh();
-
-	const LLFlexibleObjectData* getFlexibleObjectData() const { return mFlexibleObjectDataInUse ? mFlexibleObjectData.get() : nullptr; }
-	const LLLightParams* getLightParams() const { return mLightParamsInUse ? mLightParams.get() : nullptr; }
-	const LLSculptParams* getSculptParams() const { return mSculptParamsInUse ? mSculptParams.get() : nullptr; }
-	const LLLightImageParams* getLightImageParams() const { return mLightImageParamsInUse ? mLightImageParams.get() : nullptr; }
-	const LLExtendedMeshParams* getExtendedMeshParams() const { return mExtendedMeshParamsInUse ? mExtendedMeshParams.get() : nullptr; }
-	 LLRenderMaterialParams* getRenderMaterialParams() const { return mRenderMaterialParamsInUse ? mRenderMaterialParams.get() : nullptr; }
-	LLReflectionProbeParams* getReflectionProbeParams() const { return mReflectionProbeParamsInUse ? mReflectionProbeParams.get() : nullptr; }
-
-	bool setParameterEntry(U16 param_type, const LLNetworkData& new_value, bool local_origin);
-	bool setParameterEntryInUse(U16 param_type, BOOL in_use, bool local_origin);
-
-	// Called when a parameter is changed
-	virtual void parameterChanged(U16 param_type, bool local_origin);
-	virtual void parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_use, bool local_origin);
-	
+    S16 getInventorySerial() const { return mInventorySerialNum; }
+
+    // These functions does viewer-side only object inventory modifications
+    void updateViewerInventoryAsset(
+        const LLViewerInventoryItem* item,
+        const LLUUID& new_asset);
+
+    // This function will make sure that we refresh the inventory.
+    void dirtyInventory();
+    BOOL isInventoryDirty() { return mInventoryDirty; }
+
+    // save a script, which involves removing the old one, and rezzing
+    // in the new one. This method should be called with the asset id
+    // of the new and old script AFTER the bytecode has been saved.
+    void saveScript(const LLViewerInventoryItem* item, BOOL active, bool is_new);
+
+    // move an inventory item out of the task and into agent
+    // inventory. This operation is based on messaging. No permissions
+    // checks are made on the viewer - the server will double check.
+    void moveInventory(const LLUUID& agent_folder, const LLUUID& item_id);
+
+    // Find the number of instances of this object's inventory that are of the given type
+    S32 countInventoryContents( LLAssetType::EType type );
+
+    BOOL            permAnyOwner() const;
+    BOOL            permYouOwner() const;
+    BOOL            permGroupOwner() const;
+    BOOL            permOwnerModify() const;
+    BOOL            permModify() const;
+    BOOL            permCopy() const;
+    BOOL            permMove() const;
+    BOOL            permTransfer() const;
+    inline BOOL     flagUsePhysics() const          { return ((mFlags & FLAGS_USE_PHYSICS) != 0); }
+    inline BOOL     flagObjectAnyOwner() const      { return ((mFlags & FLAGS_OBJECT_ANY_OWNER) != 0); }
+    inline BOOL     flagObjectYouOwner() const      { return ((mFlags & FLAGS_OBJECT_YOU_OWNER) != 0); }
+    inline BOOL     flagObjectGroupOwned() const    { return ((mFlags & FLAGS_OBJECT_GROUP_OWNED) != 0); }
+    inline BOOL     flagObjectOwnerModify() const   { return ((mFlags & FLAGS_OBJECT_OWNER_MODIFY) != 0); }
+    inline BOOL     flagObjectModify() const        { return ((mFlags & FLAGS_OBJECT_MODIFY) != 0); }
+    inline BOOL     flagObjectCopy() const          { return ((mFlags & FLAGS_OBJECT_COPY) != 0); }
+    inline BOOL     flagObjectMove() const          { return ((mFlags & FLAGS_OBJECT_MOVE) != 0); }
+    inline BOOL     flagObjectTransfer() const      { return ((mFlags & FLAGS_OBJECT_TRANSFER) != 0); }
+    inline BOOL     flagObjectPermanent() const     { return ((mFlags & FLAGS_AFFECTS_NAVMESH) != 0); }
+    inline BOOL     flagCharacter() const           { return ((mFlags & FLAGS_CHARACTER) != 0); }
+    inline BOOL     flagVolumeDetect() const        { return ((mFlags & FLAGS_VOLUME_DETECT) != 0); }
+    inline BOOL     flagIncludeInSearch() const     { return ((mFlags & FLAGS_INCLUDE_IN_SEARCH) != 0); }
+    inline BOOL     flagScripted() const            { return ((mFlags & FLAGS_SCRIPTED) != 0); }
+    inline BOOL     flagHandleTouch() const         { return ((mFlags & FLAGS_HANDLE_TOUCH) != 0); }
+    inline BOOL     flagTakesMoney() const          { return ((mFlags & FLAGS_TAKES_MONEY) != 0); }
+    inline BOOL     flagPhantom() const             { return ((mFlags & FLAGS_PHANTOM) != 0); }
+    inline BOOL     flagInventoryEmpty() const      { return ((mFlags & FLAGS_INVENTORY_EMPTY) != 0); }
+    inline BOOL     flagAllowInventoryAdd() const   { return ((mFlags & FLAGS_ALLOW_INVENTORY_DROP) != 0); }
+    inline BOOL     flagTemporaryOnRez() const      { return ((mFlags & FLAGS_TEMPORARY_ON_REZ) != 0); }
+    inline BOOL     flagAnimSource() const          { return ((mFlags & FLAGS_ANIM_SOURCE) != 0); }
+    inline BOOL     flagCameraSource() const        { return ((mFlags & FLAGS_CAMERA_SOURCE) != 0); }
+    inline BOOL     flagCameraDecoupled() const     { return ((mFlags & FLAGS_CAMERA_DECOUPLED) != 0); }
+
+    U8       getPhysicsShapeType() const;
+    inline F32      getPhysicsGravity() const       { return mPhysicsGravity; }
+    inline F32      getPhysicsFriction() const      { return mPhysicsFriction; }
+    inline F32      getPhysicsDensity() const       { return mPhysicsDensity; }
+    inline F32      getPhysicsRestitution() const   { return mPhysicsRestitution; }
+
+    bool            isPermanentEnforced() const;
+
+    bool getIncludeInSearch() const;
+    void setIncludeInSearch(bool include_in_search);
+
+    // Does "open" object menu item apply?
+    BOOL allowOpen() const;
+
+    void setClickAction(U8 action) { mClickAction = action; }
+    U8 getClickAction() const { return mClickAction; }
+    bool specialHoverCursor() const;    // does it have a special hover cursor?
+
+    void            setRegion(LLViewerRegion *regionp);
+    virtual void    updateRegion(LLViewerRegion *regionp);
+
+    void updateFlags(BOOL physics_changed = FALSE);
+    void loadFlags(U32 flags); //load flags from cache or from message
+    BOOL setFlags(U32 flag, BOOL state);
+    BOOL setFlagsWithoutUpdate(U32 flag, BOOL state);
+    void setPhysicsShapeType(U8 type);
+    void setPhysicsGravity(F32 gravity);
+    void setPhysicsFriction(F32 friction);
+    void setPhysicsDensity(F32 density);
+    void setPhysicsRestitution(F32 restitution);
+
+    virtual void dump() const;
+    static U32      getNumZombieObjects()           { return sNumZombieObjects; }
+
+    void printNameValuePairs() const;
+
+    virtual S32 getLOD() const { return 3; }
+    virtual U32 getPartitionType() const;
+    void dirtySpatialGroup() const;
+    virtual void dirtyMesh();
+
+    const LLFlexibleObjectData* getFlexibleObjectData() const { return mFlexibleObjectDataInUse ? mFlexibleObjectData.get() : nullptr; }
+    const LLLightParams* getLightParams() const { return mLightParamsInUse ? mLightParams.get() : nullptr; }
+    const LLSculptParams* getSculptParams() const { return mSculptParamsInUse ? mSculptParams.get() : nullptr; }
+    const LLLightImageParams* getLightImageParams() const { return mLightImageParamsInUse ? mLightImageParams.get() : nullptr; }
+    const LLExtendedMeshParams* getExtendedMeshParams() const { return mExtendedMeshParamsInUse ? mExtendedMeshParams.get() : nullptr; }
+     LLRenderMaterialParams* getRenderMaterialParams() const { return mRenderMaterialParamsInUse ? mRenderMaterialParams.get() : nullptr; }
+    LLReflectionProbeParams* getReflectionProbeParams() const { return mReflectionProbeParamsInUse ? mReflectionProbeParams.get() : nullptr; }
+
+    bool setParameterEntry(U16 param_type, const LLNetworkData& new_value, bool local_origin);
+    bool setParameterEntryInUse(U16 param_type, BOOL in_use, bool local_origin);
+
+    // Called when a parameter is changed
+    virtual void parameterChanged(U16 param_type, bool local_origin);
+    virtual void parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_use, bool local_origin);
+
     bool isShrinkWrapped() const { return mShouldShrinkWrap; }
 
     // Used to improve performance.  If an object is likely to rebuild its vertex buffer often
@@ -659,162 +659,162 @@ class LLViewerObject
     // so that nearby objects won't attempt to share a vertex buffer with this object.
     void shrinkWrap();
 
-	friend class LLViewerObjectList;
-	friend class LLViewerMediaList;
+    friend class LLViewerObjectList;
+    friend class LLViewerMediaList;
 
 public:
-	LLViewerTexture* getBakedTextureForMagicId(const LLUUID& id);
-	void updateAvatarMeshVisibility(const LLUUID& id, const LLUUID& old_id);
-	void refreshBakeTexture();
+    LLViewerTexture* getBakedTextureForMagicId(const LLUUID& id);
+    void updateAvatarMeshVisibility(const LLUUID& id, const LLUUID& old_id);
+    void refreshBakeTexture();
 public:
-	static void unpackVector3(LLDataPackerBinaryBuffer* dp, LLVector3& value, std::string name);
-	static void unpackUUID(LLDataPackerBinaryBuffer* dp, LLUUID& value, std::string name);
-	static void unpackU32(LLDataPackerBinaryBuffer* dp, U32& value, std::string name);
-	static void unpackU8(LLDataPackerBinaryBuffer* dp, U8& value, std::string name);
-	static U32 unpackParentID(LLDataPackerBinaryBuffer* dp, U32& parent_id);
+    static void unpackVector3(LLDataPackerBinaryBuffer* dp, LLVector3& value, std::string name);
+    static void unpackUUID(LLDataPackerBinaryBuffer* dp, LLUUID& value, std::string name);
+    static void unpackU32(LLDataPackerBinaryBuffer* dp, U32& value, std::string name);
+    static void unpackU8(LLDataPackerBinaryBuffer* dp, U8& value, std::string name);
+    static U32 unpackParentID(LLDataPackerBinaryBuffer* dp, U32& parent_id);
 
 public:
-	//counter-translation
-	void resetChildrenPosition(const LLVector3& offset, BOOL simplified = FALSE,  BOOL skip_avatar_child = FALSE) ;
-	//counter-rotation
-	void resetChildrenRotationAndPosition(const std::vector<LLQuaternion>& rotations, 
-											const std::vector<LLVector3>& positions) ;
-	void saveUnselectedChildrenRotation(std::vector<LLQuaternion>& rotations) ;
-	void saveUnselectedChildrenPosition(std::vector<LLVector3>& positions) ;
-	std::vector<LLVector3> mUnselectedChildrenPositions ;
+    //counter-translation
+    void resetChildrenPosition(const LLVector3& offset, BOOL simplified = FALSE,  BOOL skip_avatar_child = FALSE) ;
+    //counter-rotation
+    void resetChildrenRotationAndPosition(const std::vector<LLQuaternion>& rotations,
+                                            const std::vector<LLVector3>& positions) ;
+    void saveUnselectedChildrenRotation(std::vector<LLQuaternion>& rotations) ;
+    void saveUnselectedChildrenPosition(std::vector<LLVector3>& positions) ;
+    std::vector<LLVector3> mUnselectedChildrenPositions ;
 
 private:
     void setObjectCostStale();
     bool isAssetInInventory(LLViewerInventoryItem* item, LLAssetType::EType type);
 
-	ExtraParameter* createNewParameterEntry(U16 param_type);
-	const ExtraParameter& getExtraParameterEntry(U16 param_type) const
-	{
-		return mExtraParameterList[U32(param_type >> 4) - 1];
-	}
-	ExtraParameter& getExtraParameterEntry(U16 param_type)
-	{
-		return mExtraParameterList[U32(param_type >> 4) - 1];
-	}
-	ExtraParameter* getExtraParameterEntryCreate(U16 param_type)
-	{
-		if (param_type <= LLNetworkData::PARAMS_MAX)
-		{
-			ExtraParameter& param = getExtraParameterEntry(param_type);
-			if (!param.is_invalid)
-			{
-				if (!param.data)
-				{
-					ExtraParameter* new_entry = createNewParameterEntry(param_type);
-					return new_entry;
-				}
-				return &param;
-			}
-		}
-		return nullptr;
-	}
-	bool unpackParameterEntry(U16 param_type, LLDataPacker* dp);
+    ExtraParameter* createNewParameterEntry(U16 param_type);
+    const ExtraParameter& getExtraParameterEntry(U16 param_type) const
+    {
+        return mExtraParameterList[U32(param_type >> 4) - 1];
+    }
+    ExtraParameter& getExtraParameterEntry(U16 param_type)
+    {
+        return mExtraParameterList[U32(param_type >> 4) - 1];
+    }
+    ExtraParameter* getExtraParameterEntryCreate(U16 param_type)
+    {
+        if (param_type <= LLNetworkData::PARAMS_MAX)
+        {
+            ExtraParameter& param = getExtraParameterEntry(param_type);
+            if (!param.is_invalid)
+            {
+                if (!param.data)
+                {
+                    ExtraParameter* new_entry = createNewParameterEntry(param_type);
+                    return new_entry;
+                }
+                return &param;
+            }
+        }
+        return nullptr;
+    }
+    bool unpackParameterEntry(U16 param_type, LLDataPacker* dp);
 
     // This function checks to see if the given media URL has changed its version
     // and the update wasn't due to this agent's last action.
     U32 checkMediaURL(const std::string &media_url);
-	
-	// Motion prediction between updates
-	void interpolateLinearMotion(const F64SecondsImplicit & frame_time, const F32SecondsImplicit & dt);
 
-	static void initObjectDataMap();
+    // Motion prediction between updates
+    void interpolateLinearMotion(const F64SecondsImplicit & frame_time, const F32SecondsImplicit & dt);
+
+    static void initObjectDataMap();
 
-	// forms task inventory request if none are pending, marks request as pending
-	void fetchInventoryFromServer();
+    // forms task inventory request if none are pending, marks request as pending
+    void fetchInventoryFromServer();
 
-	// forms task inventory request after some time passed, marks request as pending
-	void fetchInventoryDelayed(const F64 &time_seconds);
-	static void fetchInventoryDelayedCoro(const LLUUID task_inv, const F64 time_seconds);
+    // forms task inventory request after some time passed, marks request as pending
+    void fetchInventoryDelayed(const F64 &time_seconds);
+    static void fetchInventoryDelayedCoro(const LLUUID task_inv, const F64 time_seconds);
 
 public:
-	//
-	// Viewer-side only types - use the LL_PCODE_APP mask.
-	//
-	typedef enum e_vo_types
-	{
-		LL_VO_CLOUDS =				LL_PCODE_APP | 0x20, // no longer used
-		LL_VO_SURFACE_PATCH =		LL_PCODE_APP | 0x30,
-		LL_VO_WL_SKY =				LL_PCODE_APP | 0x40,
-		LL_VO_SQUARE_TORUS =		LL_PCODE_APP | 0x50,
-		LL_VO_SKY =					LL_PCODE_APP | 0x60,
-		LL_VO_VOID_WATER =			LL_PCODE_APP | 0x70,
-		LL_VO_WATER =				LL_PCODE_APP | 0x80,
-		LL_VO_PART_GROUP =			LL_PCODE_APP | 0xa0,
-		LL_VO_TRIANGLE_TORUS =		LL_PCODE_APP | 0xb0,
-		LL_VO_HUD_PART_GROUP =		LL_PCODE_APP | 0xc0,
-	} EVOType;
-
-	typedef enum e_physics_shape_types
-	{
-		PHYSICS_SHAPE_PRIM = 0,
-		PHYSICS_SHAPE_NONE,
-		PHYSICS_SHAPE_CONVEX_HULL,
-	} EPhysicsShapeType;
-
-	LLUUID			mID;
-	LLUUID			mOwnerID; //null if unknown
-
-	// unique within region, not unique across regions
-	// Local ID = 0 is not used
-	U32				mLocalID;
-
-	// Last total CRC received from sim, used for caching
-	U32				mTotalCRC;
-
-	// index into LLViewerObjectList::mActiveObjects or -1 if not in list
-	S32				mListIndex;
-
-	LLPointer<LLViewerTexture> *mTEImages;
-	LLPointer<LLViewerTexture> *mTENormalMaps;
-	LLPointer<LLViewerTexture> *mTESpecularMaps;
-    
+    //
+    // Viewer-side only types - use the LL_PCODE_APP mask.
+    //
+    typedef enum e_vo_types
+    {
+        LL_VO_CLOUDS =              LL_PCODE_APP | 0x20, // no longer used
+        LL_VO_SURFACE_PATCH =       LL_PCODE_APP | 0x30,
+        LL_VO_WL_SKY =              LL_PCODE_APP | 0x40,
+        LL_VO_SQUARE_TORUS =        LL_PCODE_APP | 0x50,
+        LL_VO_SKY =                 LL_PCODE_APP | 0x60,
+        LL_VO_VOID_WATER =          LL_PCODE_APP | 0x70,
+        LL_VO_WATER =               LL_PCODE_APP | 0x80,
+        LL_VO_PART_GROUP =          LL_PCODE_APP | 0xa0,
+        LL_VO_TRIANGLE_TORUS =      LL_PCODE_APP | 0xb0,
+        LL_VO_HUD_PART_GROUP =      LL_PCODE_APP | 0xc0,
+    } EVOType;
+
+    typedef enum e_physics_shape_types
+    {
+        PHYSICS_SHAPE_PRIM = 0,
+        PHYSICS_SHAPE_NONE,
+        PHYSICS_SHAPE_CONVEX_HULL,
+    } EPhysicsShapeType;
+
+    LLUUID          mID;
+    LLUUID          mOwnerID; //null if unknown
+
+    // unique within region, not unique across regions
+    // Local ID = 0 is not used
+    U32             mLocalID;
+
+    // Last total CRC received from sim, used for caching
+    U32             mTotalCRC;
+
+    // index into LLViewerObjectList::mActiveObjects or -1 if not in list
+    S32             mListIndex;
+
+    LLPointer<LLViewerTexture> *mTEImages;
+    LLPointer<LLViewerTexture> *mTENormalMaps;
+    LLPointer<LLViewerTexture> *mTESpecularMaps;
+
     // true if user can select this object by clicking under any circumstances (even if pick_unselectable is true)
     // can likely be factored out
-    BOOL			mbCanSelect;
+    BOOL            mbCanSelect;
 
 private:
-	// Grabbed from UPDATE_FLAGS
-	U32				mFlags;
+    // Grabbed from UPDATE_FLAGS
+    U32             mFlags;
 
-	static boost::unordered_flat_map<std::string, U32> sObjectDataMap;
+    static boost::unordered_flat_map<std::string, U32> sObjectDataMap;
 public:
-	// Sent to sim in UPDATE_FLAGS, received in ObjectPhysicsProperties
-	U8              mPhysicsShapeType;
-	F32             mPhysicsGravity;
-	F32             mPhysicsFriction;
-	F32             mPhysicsDensity;
-	F32             mPhysicsRestitution;
-	
+    // Sent to sim in UPDATE_FLAGS, received in ObjectPhysicsProperties
+    U8              mPhysicsShapeType;
+    F32             mPhysicsGravity;
+    F32             mPhysicsFriction;
+    F32             mPhysicsDensity;
+    F32             mPhysicsRestitution;
+
     // Associated GLTF Asset
     LLPointer<LL::GLTF::Asset> mGLTFAsset;
 
-	// Pipeline classes
-	LLPointer<LLDrawable> mDrawable;
+    // Pipeline classes
+    LLPointer<LLDrawable> mDrawable;
 
-	// Band-aid to select object after all creation initialization is done
-	BOOL mCreateSelected;
+    // Band-aid to select object after all creation initialization is done
+    BOOL mCreateSelected;
 
-	// Replace textures with web pages on this object while drawing
-	BOOL mRenderMedia;
+    // Replace textures with web pages on this object while drawing
+    BOOL mRenderMedia;
 
     bool mRiggedAttachedWarned;
 
-	// In bits
-	S32				mBestUpdatePrecision;
+    // In bits
+    S32             mBestUpdatePrecision;
 
-	// TODO: Make all this stuff private.  JC
-	LLPointer<LLHUDText> mText;
-	LLPointer<class LLHUDIcon> mIcon;
+    // TODO: Make all this stuff private.  JC
+    LLPointer<LLHUDText> mText;
+    LLPointer<class LLHUDIcon> mIcon;
 
-	std::string mHudText;
-	LLColor4 mHudTextColor;
+    std::string mHudText;
+    LLColor4 mHudTextColor;
 
-	static			BOOL		sUseSharedDrawables;
+    static          BOOL        sUseSharedDrawables;
 
 public:
     // Returns mControlAvatar for the edit root prim of this linkset
@@ -838,177 +838,177 @@ class LLViewerObject
     LLPointer<LLControlAvatar> mControlAvatar;
 
 protected:
-	// delete an item in the inventory, but don't tell the
-	// server. This is used internally by remove, update, and
-	// savescript.
-	void deleteInventoryItem(const LLUUID& item_id);
-
-	// do the update/caching logic. called by saveScript and
-	// updateInventory.
-	void doUpdateInventory(LLPointer<LLViewerInventoryItem>& item, U8 key, bool is_new);
-
-	static LLViewerObject *createObject(const LLUUID &id, LLPCode pcode, LLViewerRegion *regionp, S32 flags = 0);
-
-	BOOL setData(const U8 *datap, const U32 data_size);
-
-	// Hide or show HUD, icon and particles
-	void	hideExtraDisplayItems( BOOL hidden );
-
-	//////////////////////////
-	//
-	// inventory functionality
-	//
-
-	static void processTaskInvFile(void** user_data, S32 error_code, LLExtStat ext_status);
-	BOOL loadTaskInvFile(const std::string& filename);
-	void doInventoryCallback();
-	
-	BOOL isOnMap();
-
-	void unpackParticleSource(const S32 block_num, const LLUUID& owner_id);
-	void unpackParticleSource(LLDataPacker &dp, const LLUUID& owner_id, bool legacy);
-	void deleteParticleSource();
-	void setParticleSource(const LLPartSysData& particle_parameters, const LLUUID& owner_id);
-	
+    // delete an item in the inventory, but don't tell the
+    // server. This is used internally by remove, update, and
+    // savescript.
+    void deleteInventoryItem(const LLUUID& item_id);
+
+    // do the update/caching logic. called by saveScript and
+    // updateInventory.
+    void doUpdateInventory(LLPointer<LLViewerInventoryItem>& item, U8 key, bool is_new);
+
+    static LLViewerObject *createObject(const LLUUID &id, LLPCode pcode, LLViewerRegion *regionp, S32 flags = 0);
+
+    BOOL setData(const U8 *datap, const U32 data_size);
+
+    // Hide or show HUD, icon and particles
+    void    hideExtraDisplayItems( BOOL hidden );
+
+    //////////////////////////
+    //
+    // inventory functionality
+    //
+
+    static void processTaskInvFile(void** user_data, S32 error_code, LLExtStat ext_status);
+    BOOL loadTaskInvFile(const std::string& filename);
+    void doInventoryCallback();
+
+    BOOL isOnMap();
+
+    void unpackParticleSource(const S32 block_num, const LLUUID& owner_id);
+    void unpackParticleSource(LLDataPacker &dp, const LLUUID& owner_id, bool legacy);
+    void deleteParticleSource();
+    void setParticleSource(const LLPartSysData& particle_parameters, const LLUUID& owner_id);
+
 private:
-	void setNameValueList(const std::string& list);		// clears nv pairs and then individually adds \n separated NV pairs from \0 terminated string
-	void deleteTEImages(); // correctly deletes list of images
-	
+    void setNameValueList(const std::string& list);     // clears nv pairs and then individually adds \n separated NV pairs from \0 terminated string
+    void deleteTEImages(); // correctly deletes list of images
+
 protected:
 
-	typedef std::map<char *, LLNameValue *> name_value_map_t;
-	name_value_map_t mNameValuePairs;	// Any name-value pairs stored by script
-
-	child_list_t	mChildList;
-	
-	F64Seconds		mLastInterpUpdateSecs;			// Last update for purposes of interpolation
-	F64Seconds		mLastMessageUpdateSecs;			// Last update from a message from the simulator
-	TPACKETID		mLatestRecvPacketID;			// Latest time stamp on message from simulator
-	F64SecondsImplicit mRegionCrossExpire;		// frame time we detected region crossing in + wait time
-
-	// extra data sent from the sim...currently only used for tree species info
-	U8* mData;
-
-	LLPointer<LLViewerPartSourceScript>		mPartSourcep;	// Particle source associated with this object.
-	LLAudioSourceVO* mAudioSourcep;
-	F32				mAudioGain;
-	F32				mSoundCutOffRadius;
-	
-	F32				mAppAngle;	// Apparent visual arc in degrees
-	F32				mPixelArea; // Apparent area in pixels
-
-	// IDs of of all items in the object's content which are added to the object's content,
-	// but not updated on the server yet. After item was updated, its ID will be removed from this list.
-	boost::unordered_set<LLUUID> mPendingInventoryItemsIDs;
-
-	// This is the object's inventory from the viewer's perspective.
-	LLInventoryObject::object_list_t* mInventory;
-	class LLInventoryCallbackInfo
-	{
-	public:
-		~LLInventoryCallbackInfo();
-		LLVOInventoryListener* mListener;
-		void* mInventoryData;
-	};
-	typedef std::list<LLInventoryCallbackInfo*> callback_list_t;
-	callback_list_t mInventoryCallbacks;
-	S16 mInventorySerialNum;
-	S16 mExpectedInventorySerialNum;
-
-	enum EInventoryRequestState
-	{
-		INVENTORY_REQUEST_STOPPED,
-		INVENTORY_REQUEST_WAIT,    // delay before requesting
-		INVENTORY_REQUEST_PENDING, // just did fetchInventoryFromServer()
-		INVENTORY_XFER             // processed response from 'fetch', now doing an xfer
-	};
-	EInventoryRequestState	mInvRequestState;
-	U64						mInvRequestXFerId;
-	BOOL					mInventoryDirty;
-
-	LLViewerRegion	*mRegionp;					// Region that this object belongs to.
-	BOOL			mDead;
-	BOOL			mOrphaned;					// This is an orphaned child
-	BOOL			mUserSelected;				// Cached user select information
-	BOOL			mOnActiveList;
-	BOOL			mOnMap;						// On the map.
-	BOOL			mStatic;					// Object doesn't move.
-	S32				mSeatCount;
-	S32				mNumFaces;
-
-	F32				mRotTime;					// Amount (in seconds) that object has rotated according to angular velocity (llSetTargetOmega)
-	LLQuaternion	mAngularVelocityRot;		// accumulated rotation from the angular velocity computations
-	LLQuaternion	mPreviousRotation;
-
-	U8				mAttachmentState;	// this encodes the attachment id in a somewhat complex way. 0 if not an attachment.
-	LLViewerObjectMedia* mMedia;	// NULL if no media associated
-	U8 mClickAction;
-	F32 mObjectCost; //resource cost of this object or -1 if unknown
-	F32 mLinksetCost;
-	F32 mPhysicsCost;
-	F32 mLinksetPhysicsCost;
-    
+    typedef std::map<char *, LLNameValue *> name_value_map_t;
+    name_value_map_t mNameValuePairs;   // Any name-value pairs stored by script
+
+    child_list_t    mChildList;
+
+    F64Seconds      mLastInterpUpdateSecs;          // Last update for purposes of interpolation
+    F64Seconds      mLastMessageUpdateSecs;         // Last update from a message from the simulator
+    TPACKETID       mLatestRecvPacketID;            // Latest time stamp on message from simulator
+    F64SecondsImplicit mRegionCrossExpire;      // frame time we detected region crossing in + wait time
+
+    // extra data sent from the sim...currently only used for tree species info
+    U8* mData;
+
+    LLPointer<LLViewerPartSourceScript>     mPartSourcep;   // Particle source associated with this object.
+    LLAudioSourceVO* mAudioSourcep;
+    F32             mAudioGain;
+    F32             mSoundCutOffRadius;
+
+    F32             mAppAngle;  // Apparent visual arc in degrees
+    F32             mPixelArea; // Apparent area in pixels
+
+    // IDs of of all items in the object's content which are added to the object's content,
+    // but not updated on the server yet. After item was updated, its ID will be removed from this list.
+    boost::unordered_set<LLUUID> mPendingInventoryItemsIDs;
+
+    // This is the object's inventory from the viewer's perspective.
+    LLInventoryObject::object_list_t* mInventory;
+    class LLInventoryCallbackInfo
+    {
+    public:
+        ~LLInventoryCallbackInfo();
+        LLVOInventoryListener* mListener;
+        void* mInventoryData;
+    };
+    typedef std::list<LLInventoryCallbackInfo*> callback_list_t;
+    callback_list_t mInventoryCallbacks;
+    S16 mInventorySerialNum;
+    S16 mExpectedInventorySerialNum;
+
+    enum EInventoryRequestState
+    {
+        INVENTORY_REQUEST_STOPPED,
+        INVENTORY_REQUEST_WAIT,    // delay before requesting
+        INVENTORY_REQUEST_PENDING, // just did fetchInventoryFromServer()
+        INVENTORY_XFER             // processed response from 'fetch', now doing an xfer
+    };
+    EInventoryRequestState  mInvRequestState;
+    U64                     mInvRequestXFerId;
+    BOOL                    mInventoryDirty;
+
+    LLViewerRegion  *mRegionp;                  // Region that this object belongs to.
+    BOOL            mDead;
+    BOOL            mOrphaned;                  // This is an orphaned child
+    BOOL            mUserSelected;              // Cached user select information
+    BOOL            mOnActiveList;
+    BOOL            mOnMap;                     // On the map.
+    BOOL            mStatic;                    // Object doesn't move.
+    S32             mSeatCount;
+    S32             mNumFaces;
+
+    F32             mRotTime;                   // Amount (in seconds) that object has rotated according to angular velocity (llSetTargetOmega)
+    LLQuaternion    mAngularVelocityRot;        // accumulated rotation from the angular velocity computations
+    LLQuaternion    mPreviousRotation;
+
+    U8              mAttachmentState;   // this encodes the attachment id in a somewhat complex way. 0 if not an attachment.
+    LLViewerObjectMedia* mMedia;    // NULL if no media associated
+    U8 mClickAction;
+    F32 mObjectCost; //resource cost of this object or -1 if unknown
+    F32 mLinksetCost;
+    F32 mPhysicsCost;
+    F32 mLinksetPhysicsCost;
+
     // If true, "shrink wrap" this volume in its spatial partition.  See "shrinkWrap"
     bool mShouldShrinkWrap = false;
 
-	bool mCostStale;
-	mutable bool mPhysicsShapeUnknown;
+    bool mCostStale;
+    mutable bool mPhysicsShapeUnknown;
 
-	static			U32			sNumZombieObjects;			// Objects which are dead, but not deleted
+    static          U32         sNumZombieObjects;          // Objects which are dead, but not deleted
 
-	static			BOOL		sMapDebug;					// Map render mode
-	static			LLColor4	sEditSelectColor;
-	static			LLColor4	sNoEditSelectColor;
-	static			F32			sCurrentPulse;
-	static			BOOL		sPulseEnabled;
+    static          BOOL        sMapDebug;                  // Map render mode
+    static          LLColor4    sEditSelectColor;
+    static          LLColor4    sNoEditSelectColor;
+    static          F32         sCurrentPulse;
+    static          BOOL        sPulseEnabled;
 
-	static			S32			sAxisArrowLength;
+    static          S32         sAxisArrowLength;
 
 
-	// These two caches are only correct for non-parented objects right now!
-	mutable LLVector3		mPositionRegion;
-	mutable LLVector3		mPositionAgent;
+    // These two caches are only correct for non-parented objects right now!
+    mutable LLVector3       mPositionRegion;
+    mutable LLVector3       mPositionAgent;
 
-	static void setPhaseOutUpdateInterpolationTime(F32 value)	{ sPhaseOutUpdateInterpolationTime = (F64Seconds) value;	}
-	static void setMaxUpdateInterpolationTime(F32 value)		{ sMaxUpdateInterpolationTime = (F64Seconds) value;	}
-	static void setMaxRegionCrossingInterpolationTime(F32 value)		{ sMaxRegionCrossingInterpolationTime = (F64Seconds) value; }
+    static void setPhaseOutUpdateInterpolationTime(F32 value)   { sPhaseOutUpdateInterpolationTime = (F64Seconds) value;    }
+    static void setMaxUpdateInterpolationTime(F32 value)        { sMaxUpdateInterpolationTime = (F64Seconds) value; }
+    static void setMaxRegionCrossingInterpolationTime(F32 value)        { sMaxRegionCrossingInterpolationTime = (F64Seconds) value; }
 
-	static void	setVelocityInterpolate(BOOL value)		{ sVelocityInterpolate = value;	}
-	static void	setPingInterpolate(BOOL value)			{ sPingInterpolate = value;	}
+    static void setVelocityInterpolate(BOOL value)      { sVelocityInterpolate = value; }
+    static void setPingInterpolate(BOOL value)          { sPingInterpolate = value; }
 
-private:	
-	static S32 sNumObjects;
+private:
+    static S32 sNumObjects;
 
-	static F64Seconds sPhaseOutUpdateInterpolationTime;	// For motion interpolation
-	static F64Seconds sMaxUpdateInterpolationTime;			// For motion interpolation
-	static F64Seconds sMaxRegionCrossingInterpolationTime;			// For motion interpolation
+    static F64Seconds sPhaseOutUpdateInterpolationTime; // For motion interpolation
+    static F64Seconds sMaxUpdateInterpolationTime;          // For motion interpolation
+    static F64Seconds sMaxRegionCrossingInterpolationTime;          // For motion interpolation
 
-	static BOOL sVelocityInterpolate;
-	static BOOL sPingInterpolate;
+    static BOOL sVelocityInterpolate;
+    static BOOL sPingInterpolate;
 
-	bool mCachedOwnerInMuteList;
-	F64 mCachedMuteListUpdateTime;
+    bool mCachedOwnerInMuteList;
+    F64 mCachedMuteListUpdateTime;
 
-	//--------------------------------------------------------------------
-	// For objects that are attachments
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // For objects that are attachments
+    //--------------------------------------------------------------------
 public:
-	const LLUUID &getAttachmentItemID() const;
-	void setAttachmentItemID(const LLUUID &id);
-	const LLUUID &extractAttachmentItemID(); // find&set the inventory item ID of the attached object
-	EObjectUpdateType getLastUpdateType() const;
-	void setLastUpdateType(EObjectUpdateType last_update_type);
-	BOOL getLastUpdateCached() const;
-	void setLastUpdateCached(BOOL last_update_cached);
+    const LLUUID &getAttachmentItemID() const;
+    void setAttachmentItemID(const LLUUID &id);
+    const LLUUID &extractAttachmentItemID(); // find&set the inventory item ID of the attached object
+    EObjectUpdateType getLastUpdateType() const;
+    void setLastUpdateType(EObjectUpdateType last_update_type);
+    BOOL getLastUpdateCached() const;
+    void setLastUpdateCached(BOOL last_update_cached);
 
     virtual void updateRiggingInfo() {}
 
     LLJointRiggingInfoTab mJointRiggingInfoTab;
 
 private:
-	LLUUID mAttachmentItemID; // ItemID of the associated object is in user inventory.
-	EObjectUpdateType	mLastUpdateType;
-	BOOL	mLastUpdateCached;
+    LLUUID mAttachmentItemID; // ItemID of the associated object is in user inventory.
+    EObjectUpdateType   mLastUpdateType;
+    BOOL    mLastUpdateCached;
 
 public:
     // reflection probe state
@@ -1029,58 +1029,58 @@ class LLViewerObject
 
 inline void LLViewerObject::setRotation(const LLQuaternion& quat, BOOL damped)
 {
-	LLPrimitive::setRotation(quat);
-	setChanged(ROTATED | SILHOUETTE);
-	updateDrawable(damped);
+    LLPrimitive::setRotation(quat);
+    setChanged(ROTATED | SILHOUETTE);
+    updateDrawable(damped);
 }
 
 inline void LLViewerObject::setRotation(const F32 x, const F32 y, const F32 z, BOOL damped)
 {
-	LLPrimitive::setRotation(x, y, z);
-	setChanged(ROTATED | SILHOUETTE);
-	updateDrawable(damped);
+    LLPrimitive::setRotation(x, y, z);
+    setChanged(ROTATED | SILHOUETTE);
+    updateDrawable(damped);
 }
 
 class LLViewerObjectMedia
 {
 public:
-	LLViewerObjectMedia() : mMediaURL(), mPassedWhitelist(FALSE), mMediaType(0) { }
+    LLViewerObjectMedia() : mMediaURL(), mPassedWhitelist(FALSE), mMediaType(0) { }
 
-	std::string mMediaURL;	// for web pages on surfaces, one per prim
-	BOOL mPassedWhitelist;	// user has OK'd display
-	U8 mMediaType;			// see LLTextureEntry::WEB_PAGE, etc.
+    std::string mMediaURL;  // for web pages on surfaces, one per prim
+    BOOL mPassedWhitelist;  // user has OK'd display
+    U8 mMediaType;          // see LLTextureEntry::WEB_PAGE, etc.
 };
 
 // subclass of viewer object that can be added to particle partitions
 class LLAlphaObject : public LLViewerObject
 {
 public:
-	LLAlphaObject(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
-	: LLViewerObject(id,pcode,regionp) 
-	{ mDepth = 0.f; }
-
-	virtual F32 getPartSize(S32 idx);
-	virtual void getGeometry(S32 idx,
-								LLStrider<LLVector4a>& verticesp,
-								LLStrider<LLVector3>& normalsp, 
-								LLStrider<LLVector2>& texcoordsp,
-								LLStrider<LLColor4U>& colorsp, 
-								LLStrider<LLColor4U>& emissivep,
-								LLStrider<U16>& indicesp) = 0;
-
-	virtual void getBlendFunc(S32 face, LLRender::eBlendFactor& src, LLRender::eBlendFactor& dst);
-
-	F32 mDepth;
+    LLAlphaObject(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
+    : LLViewerObject(id,pcode,regionp)
+    { mDepth = 0.f; }
+
+    virtual F32 getPartSize(S32 idx);
+    virtual void getGeometry(S32 idx,
+                                LLStrider<LLVector4a>& verticesp,
+                                LLStrider<LLVector3>& normalsp,
+                                LLStrider<LLVector2>& texcoordsp,
+                                LLStrider<LLColor4U>& colorsp,
+                                LLStrider<LLColor4U>& emissivep,
+                                LLStrider<U16>& indicesp) = 0;
+
+    virtual void getBlendFunc(S32 face, LLRender::eBlendFactor& src, LLRender::eBlendFactor& dst);
+
+    F32 mDepth;
 };
 
 class LLStaticViewerObject : public LLViewerObject
 {
 public:
-	LLStaticViewerObject(const LLUUID& id, const LLPCode pcode, LLViewerRegion* regionp, BOOL is_global = FALSE)
-		: LLViewerObject(id,pcode,regionp, is_global)
-	{ }
+    LLStaticViewerObject(const LLUUID& id, const LLPCode pcode, LLViewerRegion* regionp, BOOL is_global = FALSE)
+        : LLViewerObject(id,pcode,regionp, is_global)
+    { }
 
-	virtual void updateDrawable(BOOL force_damped);
+    virtual void updateDrawable(BOOL force_damped);
 };
 
 
diff --git a/indra/newview/llviewerregion.cpp b/indra/newview/llviewerregion.cpp
index 7dd335917c1829a52357de18db166cb350d9358c..54f0ea3d5d8c4cdc7a90de3ea52d67ff40659348 100755
--- a/indra/newview/llviewerregion.cpp
+++ b/indra/newview/llviewerregion.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewerregion.cpp
  * @brief Implementation of the LLViewerRegion class.
  *
  * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010-2013, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -31,7 +31,7 @@
 // linden libraries
 #include "indra_constants.h"
 #include "llaisapi.h"
-#include "llavatarnamecache.h"		// name lookup cap url
+#include "llavatarnamecache.h"      // name lookup cap url
 #include "llfloaterreg.h"
 #include "llmath.h"
 #include "llregex.h"
@@ -93,8 +93,8 @@
 #include <boost/regex.hpp>
 
 
-// When we receive a base grant of capabilities that has a different number of 
-// capabilities than the original base grant received for the region, print 
+// When we receive a base grant of capabilities that has a different number of
+// capabilities than the original base grant received for the region, print
 // out the two lists of capabilities for analysis.
 //#define DEBUG_CAPS_GRANTS
 
@@ -148,25 +148,25 @@ class LLRegionHandler : public LLCommandHandler
         {
             return false;
         }
-           
+
         // build a secondlife://{PLACE} SLurl from this SLapp
         std::string url = "secondlife://";
         if (!grid.empty())
         {
             url += grid + "/secondlife/";
         }
-		boost::regex name_rx("[A-Za-z0-9()_%]+");
-		boost::regex coord_rx("[0-9]+");
+        boost::regex name_rx("[A-Za-z0-9()_%]+");
+        boost::regex coord_rx("[0-9]+");
         for (int i = 0; i < num_params; i++)
         {
             if (i > 0)
             {
                 url += "/";
             }
-			if (!ll_regex_match(params[i].asString(), i > 0 ? coord_rx : name_rx))
-			{
-				return false;
-			}
+            if (!ll_regex_match(params[i].asString(), i > 0 ? coord_rx : name_rx))
+            {
+                return false;
+            }
 
             url += params[i].asString();
         }
@@ -175,15 +175,15 @@ class LLRegionHandler : public LLCommandHandler
         LLURLDispatcher::dispatch(url, LLCommandHandler::NAV_TYPE_CLICKED, web, true);
         return true;
     }
-       
+
 };
 LLRegionHandler gRegionHandler;
 
 
-class LLViewerRegionImpl 
+class LLViewerRegionImpl
 {
 public:
-	LLViewerRegionImpl(LLViewerRegion * region, LLHost const & host):   
+    LLViewerRegionImpl(LLViewerRegion * region, LLHost const & host):
         mHost(host),
         mCompositionp(NULL),
         mEventPoll(NULL),
@@ -194,62 +194,62 @@ class LLViewerRegionImpl
         mLastCameraOrigin(),
         mVOCachePartition(NULL),
         mLandp(NULL)
-	{}
+    {}
 
-	static void buildCapabilityNames(LLSD& capabilityNames);
+    static void buildCapabilityNames(LLSD& capabilityNames);
 
-	// The surfaces and other layers
-	LLSurface*	mLandp;
+    // The surfaces and other layers
+    LLSurface*  mLandp;
 
-	// Region geometry data
-	LLVector3d	mOriginGlobal;	// Location of southwest corner of region (meters)
-	LLVector3d	mCenterGlobal;	// Location of center in world space (meters)
-	LLHost		mHost;
+    // Region geometry data
+    LLVector3d  mOriginGlobal;  // Location of southwest corner of region (meters)
+    LLVector3d  mCenterGlobal;  // Location of center in world space (meters)
+    LLHost      mHost;
 
-	// The unique ID for this region.
-	LLUUID mRegionID;
+    // The unique ID for this region.
+    LLUUID mRegionID;
 
-	// region/estate owner - usually null.
-	LLUUID mOwnerID;
+    // region/estate owner - usually null.
+    LLUUID mOwnerID;
 
-	// Network statistics for the region's circuit...
-	LLTimer mLastNetUpdate;
+    // Network statistics for the region's circuit...
+    LLTimer mLastNetUpdate;
 
-	// Misc
-	LLVLComposition *mCompositionp;		// Composition layer for the surface
+    // Misc
+    LLVLComposition *mCompositionp;     // Composition layer for the surface
 
-	LLVOCacheEntry::vocache_entry_map_t	  mCacheMap; //all cached entries
-	LLVOCacheEntry::vocache_entry_set_t   mActiveSet; //all active entries;
-	LLVOCacheEntry::vocache_entry_set_t   mWaitingSet; //entries waiting for LLDrawable to be generated.	
-	std::set< LLPointer<LLViewerOctreeGroup> >      mVisibleGroups; //visible groupa
-	LLVOCachePartition*                   mVOCachePartition;
-	LLVOCacheEntry::vocache_entry_set_t   mVisibleEntries; //must-be-created visible entries wait for objects creation.	
-	LLVOCacheEntry::vocache_entry_priority_list_t mWaitingList; //transient list storing sorted visible entries waiting for object creation.
-	std::set<U32>                          mNonCacheableCreatedList; //list of local ids of all non-cacheable objects
+    LLVOCacheEntry::vocache_entry_map_t   mCacheMap; //all cached entries
+    LLVOCacheEntry::vocache_entry_set_t   mActiveSet; //all active entries;
+    LLVOCacheEntry::vocache_entry_set_t   mWaitingSet; //entries waiting for LLDrawable to be generated.
+    std::set< LLPointer<LLViewerOctreeGroup> >      mVisibleGroups; //visible groupa
+    LLVOCachePartition*                   mVOCachePartition;
+    LLVOCacheEntry::vocache_entry_set_t   mVisibleEntries; //must-be-created visible entries wait for objects creation.
+    LLVOCacheEntry::vocache_entry_priority_list_t mWaitingList; //transient list storing sorted visible entries waiting for object creation.
+    std::set<U32>                          mNonCacheableCreatedList; //list of local ids of all non-cacheable objects
     LLVOCacheEntry::vocache_gltf_overrides_map_t mGLTFOverridesLLSD; // for materials
 
-	// time?
-	// LRU info?
+    // time?
+    // LRU info?
 
-	// Cache ID is unique per-region, across renames, moving locations,
-	// etc.
-	LLUUID mCacheID;
+    // Cache ID is unique per-region, across renames, moving locations,
+    // etc.
+    LLUUID mCacheID;
 
-	CapabilityMap mCapabilities;
-	CapabilityMap mSecondCapabilitiesTracker; 
+    CapabilityMap mCapabilities;
+    CapabilityMap mSecondCapabilitiesTracker;
 
-	LLEventPoll* mEventPoll;
+    LLEventPoll* mEventPoll;
 
-	S32 mSeedCapMaxAttempts;
-	S32 mSeedCapAttempts;
+    S32 mSeedCapMaxAttempts;
+    S32 mSeedCapAttempts;
 
-	S32 mHttpResponderID;
+    S32 mHttpResponderID;
 
-	//spatial partitions for objects in this region
-	std::vector<LLViewerOctreePartition*> mObjectPartition;
+    //spatial partitions for objects in this region
+    std::vector<LLViewerOctreePartition*> mObjectPartition;
 
-	LLVector3   mLastCameraOrigin;
-	U32         mLastCameraUpdate;
+    LLVector3   mLastCameraOrigin;
+    U32         mLastCameraUpdate;
 
     static void        requestBaseCapabilitiesCoro(U64 regionHandle);
     static void        requestBaseCapabilitiesCompleteCoro(U64 regionHandle);
@@ -259,7 +259,7 @@ class LLViewerRegionImpl
 void LLViewerRegionImpl::requestBaseCapabilitiesCoro(U64 regionHandle)
 {
     LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID);
-    LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t 
+    LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t
         httpAdapter(std::make_shared<LLCoreHttpUtil::HttpCoroutineAdapter>("BaseCapabilitiesRequest", httpPolicy));
     LLCore::HttpRequest::ptr_t httpRequest(std::make_shared<LLCore::HttpRequest>());
 
@@ -288,7 +288,7 @@ void LLViewerRegionImpl::requestBaseCapabilitiesCoro(U64 regionHandle)
             return; // this error condition is not recoverable.
         }
         LLViewerRegionImpl* impl = regionp->getRegionImplNC();
-        LL_DEBUGS("AppInit", "Capabilities") << "requesting seed caps for handle " << regionHandle 
+        LL_DEBUGS("AppInit", "Capabilities") << "requesting seed caps for handle " << regionHandle
                                              << " name " << regionp->getName() << LL_ENDL;
 
         std::string url = regionp->getCapability("Seed");
@@ -314,12 +314,12 @@ void LLViewerRegionImpl::requestBaseCapabilitiesCoro(U64 regionHandle)
         LLSD capabilityNames = LLSD::emptyArray();
         impl->buildCapabilityNames(capabilityNames);
 
-        LL_INFOS("AppInit", "Capabilities") << "Requesting seed from " << url 
+        LL_INFOS("AppInit", "Capabilities") << "Requesting seed from " << url
                                             << " region name " << regionp->getName()
                                             << " region id " << regionp->getRegionID()
                                             << " handle " << regionp->getHandle()
                                             << " (attempt #" << impl->mSeedCapAttempts + 1 << ")" << LL_ENDL;
-		LL_DEBUGS("AppInit", "Capabilities") << "Capabilities requested: " << capabilityNames << LL_ENDL;
+        LL_DEBUGS("AppInit", "Capabilities") << "Capabilities requested: " << capabilityNames << LL_ENDL;
 
         regionp = NULL;
         impl = NULL;
@@ -379,7 +379,7 @@ void LLViewerRegionImpl::requestBaseCapabilitiesCoro(U64 regionHandle)
         {
             LL_WARNS("AppInit", "Capabilities") << "Received results for a stale capabilities request!" << LL_ENDL;
             // setup for retry.
-			++(impl->mSeedCapAttempts);
+            ++(impl->mSeedCapAttempts);
             continue;
         }
 
@@ -395,12 +395,12 @@ void LLViewerRegionImpl::requestBaseCapabilitiesCoro(U64 regionHandle)
         log_capabilities(mCapabilities);
 #endif
 
-        LL_DEBUGS("AppInit", "Capabilities", "Teleport") << "received caps for handle " << regionHandle 
-														 << " region name " << regionp->getName() << LL_ENDL;
+        LL_DEBUGS("AppInit", "Capabilities", "Teleport") << "received caps for handle " << regionHandle
+                                                         << " region name " << regionp->getName() << LL_ENDL;
         regionp->setCapabilitiesReceived(true);
 
         break;
-    } 
+    }
     while (true);
 
     if (regionp && regionp->isCapabilityAvailable("ServerReleaseNotes") &&
@@ -540,7 +540,7 @@ void LLViewerRegionImpl::requestBaseCapabilitiesCompleteCoro(U64 regionHandle)
             LL_DEBUGS("CrossingCaps") << "Sim sent multiple base cap grants with matching sizes." << LL_ENDL;
         }
         impl->mSecondCapabilitiesTracker.clear();
-    } 
+    }
     while (false);
 }
 
@@ -560,7 +560,7 @@ void LLViewerRegionImpl::requestSimulatorFeatureCoro(std::string url, U64 region
 
         if (attemptNumber > MAX_CAP_REQUEST_ATTEMPTS)
         {
-            LL_WARNS("AppInit", "SimulatorFeatures") << "Retries count exceeded attempting to get Simulator feature from " 
+            LL_WARNS("AppInit", "SimulatorFeatures") << "Retries count exceeded attempting to get Simulator feature from "
                 << url << LL_ENDL;
             break;
         }
@@ -588,7 +588,7 @@ void LLViewerRegionImpl::requestSimulatorFeatureCoro(std::string url, U64 region
         if (!status)
         {
             LL_WARNS("AppInit", "SimulatorFeatures") << "HttpStatus error retrying" << LL_ENDL;
-            continue;  
+            continue;
         }
 
         if (LLApp::isExiting() || gDisconnected)
@@ -622,237 +622,237 @@ void LLViewerRegionImpl::requestSimulatorFeatureCoro(std::string url, U64 region
 }
 
 LLViewerRegion::LLViewerRegion(const U64 &handle,
-							   const LLHost &host,
-							   const U32 grids_per_region_edge, 
-							   const U32 grids_per_patch_edge, 
-							   const F32 region_width_meters)
-:	mImpl(new LLViewerRegionImpl(this, host)),
-	mWidth(region_width_meters),
-	mHandle(handle),
-	mTimeDilation(1.0f),
-	mWidthScaleFactor(region_width_meters / REGION_WIDTH_METERS),
-	mName(""),
-	mZoning(""),
-	mIsEstateManager(FALSE),
-	mRegionFlags( REGION_FLAGS_DEFAULT ),
-	mRegionProtocols( 0 ),
-	mSimAccess( SIM_ACCESS_MIN ),
-	mBillableFactor(1.0),
-	mMaxTasks(DEFAULT_MAX_REGION_WIDE_PRIM_COUNT),
-	mCentralBakeVersion(1),
-	mClassID(0),
-	mCPURatio(0),
-	mColoName("unknown"),
-	mProductSKU("unknown"),
-	mProductName("unknown"),
-	mLegacyHttpUrl(""),
-	mViewerAssetUrl(""),
-	mCacheLoaded(FALSE),
-	mCacheDirty(FALSE),
-	mReleaseNotesRequested(FALSE),
-	mCapabilitiesState(CAPABILITIES_STATE_INIT),
-	mSimulatorFeaturesReceived(false),
-	mBitsReceived(0.f),
-	mPacketsReceived(0.f),
-	mDead(FALSE),
-	mLastVisitedEntry(NULL),
-	mInvisibilityCheckHistory(-1),
-	mPaused(FALSE),
-	mRegionCacheHitCount(0),
-	mRegionCacheMissCount(0),
+                               const LLHost &host,
+                               const U32 grids_per_region_edge,
+                               const U32 grids_per_patch_edge,
+                               const F32 region_width_meters)
+:   mImpl(new LLViewerRegionImpl(this, host)),
+    mWidth(region_width_meters),
+    mHandle(handle),
+    mTimeDilation(1.0f),
+    mWidthScaleFactor(region_width_meters / REGION_WIDTH_METERS),
+    mName(""),
+    mZoning(""),
+    mIsEstateManager(FALSE),
+    mRegionFlags( REGION_FLAGS_DEFAULT ),
+    mRegionProtocols( 0 ),
+    mSimAccess( SIM_ACCESS_MIN ),
+    mBillableFactor(1.0),
+    mMaxTasks(DEFAULT_MAX_REGION_WIDE_PRIM_COUNT),
+    mCentralBakeVersion(1),
+    mClassID(0),
+    mCPURatio(0),
+    mColoName("unknown"),
+    mProductSKU("unknown"),
+    mProductName("unknown"),
+    mLegacyHttpUrl(""),
+    mViewerAssetUrl(""),
+    mCacheLoaded(FALSE),
+    mCacheDirty(FALSE),
+    mReleaseNotesRequested(FALSE),
+    mCapabilitiesState(CAPABILITIES_STATE_INIT),
+    mSimulatorFeaturesReceived(false),
+    mBitsReceived(0.f),
+    mPacketsReceived(0.f),
+    mDead(FALSE),
+    mLastVisitedEntry(NULL),
+    mInvisibilityCheckHistory(-1),
+    mPaused(FALSE),
+    mRegionCacheHitCount(0),
+    mRegionCacheMissCount(0),
     mInterestListMode(IL_MODE_DEFAULT)
 {
-	mRenderMatrix.setIdentity();
+    mRenderMatrix.setIdentity();
 
-	mImpl->mOriginGlobal = from_region_handle(handle); 
-	updateRenderMatrix();
+    mImpl->mOriginGlobal = from_region_handle(handle);
+    updateRenderMatrix();
 
-	mImpl->mLandp = new LLSurface('l', NULL);
+    mImpl->mLandp = new LLSurface('l', NULL);
 
-	// Create the composition layer for the surface
-	mImpl->mCompositionp =
-		new LLVLComposition(mImpl->mLandp,
-							grids_per_region_edge,
-							mWidth / grids_per_region_edge);
-	mImpl->mCompositionp->setSurface(mImpl->mLandp);
+    // Create the composition layer for the surface
+    mImpl->mCompositionp =
+        new LLVLComposition(mImpl->mLandp,
+                            grids_per_region_edge,
+                            mWidth / grids_per_region_edge);
+    mImpl->mCompositionp->setSurface(mImpl->mLandp);
 
-	// Create the surfaces
-	mImpl->mLandp->setRegion(this);
-	mImpl->mLandp->create(grids_per_region_edge,
-					grids_per_patch_edge,
-					mImpl->mOriginGlobal,
-					mWidth);
+    // Create the surfaces
+    mImpl->mLandp->setRegion(this);
+    mImpl->mLandp->create(grids_per_region_edge,
+                    grids_per_patch_edge,
+                    mImpl->mOriginGlobal,
+                    mWidth);
 
-	mParcelOverlay = new LLViewerParcelOverlay(this, mWidth);
-	LLViewerParcelMgr::getInstance()->init(mWidth);
+    mParcelOverlay = new LLViewerParcelOverlay(this, mWidth);
+    LLViewerParcelMgr::getInstance()->init(mWidth);
 
-	setOriginGlobal(from_region_handle(handle));
-	calculateCenterGlobal();
+    setOriginGlobal(from_region_handle(handle));
+    calculateCenterGlobal();
 
-	// Create the object lists
-	initStats();
-	initPartitions();
+    // Create the object lists
+    initStats();
+    initPartitions();
 }
 
 void LLViewerRegion::initPartitions()
 {
 
-	//create object partitions
-	//MUST MATCH declaration of eObjectPartitions
-	mImpl->mObjectPartition.push_back(new LLHUDPartition(this));		//PARTITION_HUD
-	mImpl->mObjectPartition.push_back(new LLTerrainPartition(this));	//PARTITION_TERRAIN
-	mImpl->mObjectPartition.push_back(new LLVoidWaterPartition(this));	//PARTITION_VOIDWATER
-	mImpl->mObjectPartition.push_back(new LLWaterPartition(this));		//PARTITION_WATER
-	mImpl->mObjectPartition.push_back(new LLTreePartition(this));		//PARTITION_TREE
-	mImpl->mObjectPartition.push_back(new LLParticlePartition(this));	//PARTITION_PARTICLE
-	mImpl->mObjectPartition.push_back(new LLGrassPartition(this));		//PARTITION_GRASS
-	mImpl->mObjectPartition.push_back(new LLVolumePartition(this));	//PARTITION_VOLUME
-	mImpl->mObjectPartition.push_back(new LLBridgePartition(this));	//PARTITION_BRIDGE
-	mImpl->mObjectPartition.push_back(new LLAvatarPartition(this));	//PARTITION_AVATAR
-	mImpl->mObjectPartition.push_back(new LLControlAVPartition(this));	//PARTITION_CONTROL_AV
-	mImpl->mObjectPartition.push_back(new LLHUDParticlePartition(this));//PARTITION_HUD_PARTICLE
-	mImpl->mObjectPartition.push_back(new LLVOCachePartition(this)); //PARTITION_VO_CACHE
-	mImpl->mObjectPartition.push_back(NULL);					//PARTITION_NONE
-	mImpl->mVOCachePartition = getVOCachePartition();
+    //create object partitions
+    //MUST MATCH declaration of eObjectPartitions
+    mImpl->mObjectPartition.push_back(new LLHUDPartition(this));        //PARTITION_HUD
+    mImpl->mObjectPartition.push_back(new LLTerrainPartition(this));    //PARTITION_TERRAIN
+    mImpl->mObjectPartition.push_back(new LLVoidWaterPartition(this));  //PARTITION_VOIDWATER
+    mImpl->mObjectPartition.push_back(new LLWaterPartition(this));      //PARTITION_WATER
+    mImpl->mObjectPartition.push_back(new LLTreePartition(this));       //PARTITION_TREE
+    mImpl->mObjectPartition.push_back(new LLParticlePartition(this));   //PARTITION_PARTICLE
+    mImpl->mObjectPartition.push_back(new LLGrassPartition(this));      //PARTITION_GRASS
+    mImpl->mObjectPartition.push_back(new LLVolumePartition(this)); //PARTITION_VOLUME
+    mImpl->mObjectPartition.push_back(new LLBridgePartition(this)); //PARTITION_BRIDGE
+    mImpl->mObjectPartition.push_back(new LLAvatarPartition(this)); //PARTITION_AVATAR
+    mImpl->mObjectPartition.push_back(new LLControlAVPartition(this));  //PARTITION_CONTROL_AV
+    mImpl->mObjectPartition.push_back(new LLHUDParticlePartition(this));//PARTITION_HUD_PARTICLE
+    mImpl->mObjectPartition.push_back(new LLVOCachePartition(this)); //PARTITION_VO_CACHE
+    mImpl->mObjectPartition.push_back(NULL);                    //PARTITION_NONE
+    mImpl->mVOCachePartition = getVOCachePartition();
 
-	setCapabilitiesReceivedCallback(boost::bind(&LLAvatarRenderInfoAccountant::scanNewRegion, _1));
+    setCapabilitiesReceivedCallback(boost::bind(&LLAvatarRenderInfoAccountant::scanNewRegion, _1));
 }
 
 void LLViewerRegion::reInitPartitions()
 {
-	std::for_each(mImpl->mObjectPartition.begin(), mImpl->mObjectPartition.end(), DeletePointer());
-	mImpl->mObjectPartition.clear();
-	initPartitions();
+    std::for_each(mImpl->mObjectPartition.begin(), mImpl->mObjectPartition.end(), DeletePointer());
+    mImpl->mObjectPartition.clear();
+    initPartitions();
 }
 
 void LLViewerRegion::initStats()
 {
-	mImpl->mLastNetUpdate.reset();
-	mPacketsIn = 0;
-	mBitsIn = (U32Bits)0;
-	mLastBitsIn = (U32Bits)0;
-	mLastPacketsIn = 0;
-	mPacketsOut = 0;
-	mLastPacketsOut = 0;
-	mPacketsLost = 0;
-	mLastPacketsLost = 0;
-	mPingDelay = (U32Seconds)0;
-	mAlive = false;					// can become false if circuit disconnects
+    mImpl->mLastNetUpdate.reset();
+    mPacketsIn = 0;
+    mBitsIn = (U32Bits)0;
+    mLastBitsIn = (U32Bits)0;
+    mLastPacketsIn = 0;
+    mPacketsOut = 0;
+    mLastPacketsOut = 0;
+    mPacketsLost = 0;
+    mLastPacketsLost = 0;
+    mPingDelay = (U32Seconds)0;
+    mAlive = false;                 // can become false if circuit disconnects
 }
 
 static LLTrace::BlockTimerStatHandle FTM_CLEANUP_REGION_OBJECTS("Cleanup Region Objects");
 static LLTrace::BlockTimerStatHandle FTM_SAVE_REGION_CACHE("Save Region Cache");
 
-LLViewerRegion::~LLViewerRegion() 
+LLViewerRegion::~LLViewerRegion()
 {
     LL_PROFILE_ZONE_SCOPED;
-	mDead = TRUE;
-	mImpl->mActiveSet.clear();
-	mImpl->mVisibleEntries.clear();
-	mImpl->mVisibleGroups.clear();
-	mImpl->mWaitingSet.clear();
-
-	gVLManager.cleanupData(this);
-	// Can't do this on destruction, because the neighbor pointers might be invalid.
-	// This should be reference counted...
-	disconnectAllNeighbors();
-	LLViewerPartSim::getInstance()->cleanupRegion(this);
+    mDead = TRUE;
+    mImpl->mActiveSet.clear();
+    mImpl->mVisibleEntries.clear();
+    mImpl->mVisibleGroups.clear();
+    mImpl->mWaitingSet.clear();
+
+    gVLManager.cleanupData(this);
+    // Can't do this on destruction, because the neighbor pointers might be invalid.
+    // This should be reference counted...
+    disconnectAllNeighbors();
+    LLViewerPartSim::getInstance()->cleanupRegion(this);
 
     {
         LL_RECORD_BLOCK_TIME(FTM_CLEANUP_REGION_OBJECTS);
         gObjectList.killObjects(this);
     }
 
-	delete mImpl->mCompositionp;
-	delete mParcelOverlay;
-	delete mImpl->mLandp;
-	delete mImpl->mEventPoll;
+    delete mImpl->mCompositionp;
+    delete mParcelOverlay;
+    delete mImpl->mLandp;
+    delete mImpl->mEventPoll;
 #if 0
-	LLHTTPSender::clearSender(mImpl->mHost);
-#endif	
-	std::for_each(mImpl->mObjectPartition.begin(), mImpl->mObjectPartition.end(), DeletePointer());
+    LLHTTPSender::clearSender(mImpl->mHost);
+#endif
+    std::for_each(mImpl->mObjectPartition.begin(), mImpl->mObjectPartition.end(), DeletePointer());
 
     {
         LL_RECORD_BLOCK_TIME(FTM_SAVE_REGION_CACHE);
         saveObjectCache();
     }
 
-	delete mImpl;
-	mImpl = nullptr;
+    delete mImpl;
+    mImpl = nullptr;
 
-	for (LLPointer<LLViewerTexture> tile : mWorldMapTiles)
-		tile->setBoostLevel(LLViewerTexture::BOOST_NONE);
+    for (LLPointer<LLViewerTexture> tile : mWorldMapTiles)
+        tile->setBoostLevel(LLViewerTexture::BOOST_NONE);
 }
 
-/*virtual*/ 
-const LLHost&	LLViewerRegion::getHost() const				
-{ 
-	return mImpl->mHost; 
+/*virtual*/
+const LLHost&   LLViewerRegion::getHost() const
+{
+    return mImpl->mHost;
 }
 
 LLSurface & LLViewerRegion::getLand() const
 {
-	return *mImpl->mLandp;
+    return *mImpl->mLandp;
 }
 
 const LLUUID& LLViewerRegion::getRegionID() const
 {
-	return mImpl->mRegionID;
+    return mImpl->mRegionID;
 }
 
 void LLViewerRegion::setRegionID(const LLUUID& region_id)
 {
-	mImpl->mRegionID = region_id;
+    mImpl->mRegionID = region_id;
 }
 
 void LLViewerRegion::loadObjectCache()
 {
-	if (mCacheLoaded)
-	{
-		return;
-	}
+    if (mCacheLoaded)
+    {
+        return;
+    }
 
-	// Presume success.  If it fails, we don't want to try again.
-	mCacheLoaded = TRUE;
+    // Presume success.  If it fails, we don't want to try again.
+    mCacheLoaded = TRUE;
 
-	if(LLVOCache::instanceExists())
-	{
+    if(LLVOCache::instanceExists())
+    {
         LLVOCache & vocache = LLVOCache::instance();
-		// Without this a "corrupted" vocache persists until a cache clear or other rewrite. Mark as dirty hereif read fails to force a rewrite.
-		mCacheDirty = !vocache.readFromCache(mHandle, mImpl->mCacheID, mImpl->mCacheMap);
-		vocache.readGenericExtrasFromCache(mHandle, mImpl->mCacheID, mImpl->mGLTFOverridesLLSD, mImpl->mCacheMap);
+        // Without this a "corrupted" vocache persists until a cache clear or other rewrite. Mark as dirty hereif read fails to force a rewrite.
+        mCacheDirty = !vocache.readFromCache(mHandle, mImpl->mCacheID, mImpl->mCacheMap);
+        vocache.readGenericExtrasFromCache(mHandle, mImpl->mCacheID, mImpl->mGLTFOverridesLLSD, mImpl->mCacheMap);
 
-		if (mImpl->mCacheMap.empty())
-		{
-			mCacheDirty = TRUE;
-		}
-	}
+        if (mImpl->mCacheMap.empty())
+        {
+            mCacheDirty = TRUE;
+        }
+    }
 }
 
 
 void LLViewerRegion::saveObjectCache()
 {
-	if (!mCacheLoaded)
-	{
-		return;
-	}
+    if (!mCacheLoaded)
+    {
+        return;
+    }
 
-	if (mImpl->mCacheMap.empty())
-	{
-		return;
-	}
+    if (mImpl->mCacheMap.empty())
+    {
+        return;
+    }
 
-	if(LLVOCache::instanceExists())
-	{
-		const F32 start_time_threshold = 600.0f; //seconds
-		bool removal_enabled = sVOCacheCullingEnabled && (mRegionTimer.getElapsedTimeF32() > start_time_threshold); //allow to remove invalid objects from object cache file.
+    if(LLVOCache::instanceExists())
+    {
+        const F32 start_time_threshold = 600.0f; //seconds
+        bool removal_enabled = sVOCacheCullingEnabled && (mRegionTimer.getElapsedTimeF32() > start_time_threshold); //allow to remove invalid objects from object cache file.
 
         LLVOCache & instance = LLVOCache::instance();
 
         instance.writeToCache(mHandle, mImpl->mCacheID, mImpl->mCacheMap, mCacheDirty, removal_enabled);
         instance.writeGenericExtrasToCache(mHandle, mImpl->mCacheID, mImpl->mGLTFOverridesLLSD, mCacheDirty, removal_enabled);
-		mCacheDirty = FALSE;
-	}
+        mCacheDirty = FALSE;
+    }
 
     if (LLAppViewer::instance()->isQuitting())
     {
@@ -869,259 +869,259 @@ void LLViewerRegion::saveObjectCache()
 
 void LLViewerRegion::sendMessage()
 {
-	gMessageSystem->sendMessage(mImpl->mHost);
+    gMessageSystem->sendMessage(mImpl->mHost);
 }
 
 void LLViewerRegion::sendReliableMessage()
 {
-	gMessageSystem->sendReliable(mImpl->mHost);
+    gMessageSystem->sendReliable(mImpl->mHost);
 }
 
 void LLViewerRegion::setWaterHeight(F32 water_level)
 {
-	mImpl->mLandp->setWaterHeight(water_level);
+    mImpl->mLandp->setWaterHeight(water_level);
 }
 
 F32 LLViewerRegion::getWaterHeight() const
 {
-	return mImpl->mLandp->getWaterHeight();
+    return mImpl->mLandp->getWaterHeight();
 }
 
 BOOL LLViewerRegion::isVoiceEnabled() const
 {
-	return getRegionFlag(REGION_FLAGS_ALLOW_VOICE);
+    return getRegionFlag(REGION_FLAGS_ALLOW_VOICE);
 }
 
 void LLViewerRegion::setRegionFlags(U64 flags)
 {
-	mRegionFlags = flags;
+    mRegionFlags = flags;
 }
 
 
-void LLViewerRegion::setOriginGlobal(const LLVector3d &origin_global) 
-{ 
-	mImpl->mOriginGlobal = origin_global; 
-	updateRenderMatrix();
-	mImpl->mLandp->setOriginGlobal(origin_global);
-	mWind.setOriginGlobal(origin_global);
-	calculateCenterGlobal();
+void LLViewerRegion::setOriginGlobal(const LLVector3d &origin_global)
+{
+    mImpl->mOriginGlobal = origin_global;
+    updateRenderMatrix();
+    mImpl->mLandp->setOriginGlobal(origin_global);
+    mWind.setOriginGlobal(origin_global);
+    calculateCenterGlobal();
 }
 
 void LLViewerRegion::updateRenderMatrix()
 {
-	mRenderMatrix.setTranslate_affine(getOriginAgent());
+    mRenderMatrix.setTranslate_affine(getOriginAgent());
 }
 
 void LLViewerRegion::setTimeDilation(F32 time_dilation)
 {
-	mTimeDilation = time_dilation;
+    mTimeDilation = time_dilation;
 }
 
 const LLVector3d & LLViewerRegion::getOriginGlobal() const
 {
-	return mImpl->mOriginGlobal;
+    return mImpl->mOriginGlobal;
 }
 
 LLVector3 LLViewerRegion::getOriginAgent() const
 {
-	return gAgent.getPosAgentFromGlobal(mImpl->mOriginGlobal);
+    return gAgent.getPosAgentFromGlobal(mImpl->mOriginGlobal);
 }
 
 const LLVector3d & LLViewerRegion::getCenterGlobal() const
 {
-	return mImpl->mCenterGlobal;
+    return mImpl->mCenterGlobal;
 }
 
 LLVector3 LLViewerRegion::getCenterAgent() const
 {
-	return gAgent.getPosAgentFromGlobal(mImpl->mCenterGlobal);
+    return gAgent.getPosAgentFromGlobal(mImpl->mCenterGlobal);
 }
 
 void LLViewerRegion::setOwner(const LLUUID& owner_id)
 {
-	mImpl->mOwnerID = owner_id;
+    mImpl->mOwnerID = owner_id;
 }
 
 const LLUUID& LLViewerRegion::getOwner() const
 {
-	return mImpl->mOwnerID;
+    return mImpl->mOwnerID;
 }
 
-void LLViewerRegion::setRegionNameAndZone	(const std::string& name_zone)
+void LLViewerRegion::setRegionNameAndZone   (const std::string& name_zone)
 {
-	std::string::size_type pipe_pos = name_zone.find('|');
-	S32 length   = name_zone.size();
-	if (pipe_pos != std::string::npos)
-	{
-		mName   = name_zone.substr(0, pipe_pos);
-		mZoning = name_zone.substr(pipe_pos+1, length-(pipe_pos+1));
-	}
-	else
-	{
-		mName   = name_zone;
-		mZoning = "";
-	}
+    std::string::size_type pipe_pos = name_zone.find('|');
+    S32 length   = name_zone.size();
+    if (pipe_pos != std::string::npos)
+    {
+        mName   = name_zone.substr(0, pipe_pos);
+        mZoning = name_zone.substr(pipe_pos+1, length-(pipe_pos+1));
+    }
+    else
+    {
+        mName   = name_zone;
+        mZoning = "";
+    }
 
-	LLStringUtil::stripNonprintable(mName);
-	LLStringUtil::stripNonprintable(mZoning);
+    LLStringUtil::stripNonprintable(mName);
+    LLStringUtil::stripNonprintable(mZoning);
 }
 
 BOOL LLViewerRegion::canManageEstate() const
 {
-	return gAgent.isGodlike()
-		|| isEstateManager()
-		|| gAgent.getID() == getOwner();
+    return gAgent.isGodlike()
+        || isEstateManager()
+        || gAgent.getID() == getOwner();
 }
 
 const std::string LLViewerRegion::getSimAccessString() const
 {
-	return accessToString(mSimAccess);
+    return accessToString(mSimAccess);
 }
 
 std::string LLViewerRegion::getLocalizedSimProductName() const
 {
-	std::string localized_spn;
-	return LLTrans::findString(localized_spn, mProductName) ? localized_spn : mProductName;
+    std::string localized_spn;
+    return LLTrans::findString(localized_spn, mProductName) ? localized_spn : mProductName;
 }
 
 // static
 std::string LLViewerRegion::regionFlagsToString(U64 flags)
 {
-	std::string result;
+    std::string result;
 
-	if (flags & REGION_FLAGS_SANDBOX)
-	{
-		result += "Sandbox";
-	}
+    if (flags & REGION_FLAGS_SANDBOX)
+    {
+        result += "Sandbox";
+    }
 
-	if (flags & REGION_FLAGS_ALLOW_DAMAGE)
-	{
-		result += " Not Safe";
-	}
+    if (flags & REGION_FLAGS_ALLOW_DAMAGE)
+    {
+        result += " Not Safe";
+    }
 
-	return result;
+    return result;
 }
 
 // static
 const std::string& LLViewerRegion::accessToString(U8 sim_access)
 {
-	static std::vector<std::string> access_strings;
-	if (access_strings.empty())
-	{
-		access_strings.reserve(5);
-		access_strings.push_back(LLTrans::getString("SIM_ACCESS_PG"));
-		access_strings.push_back(LLTrans::getString("SIM_ACCESS_MATURE"));
-		access_strings.push_back(LLTrans::getString("SIM_ACCESS_ADULT"));
-		access_strings.push_back(LLTrans::getString("SIM_ACCESS_DOWN"));
-		access_strings.push_back(LLTrans::getString("SIM_ACCESS_MIN"));
-	}
-	switch(sim_access)
-	{
-	case SIM_ACCESS_PG:
-		return access_strings[0];
+    static std::vector<std::string> access_strings;
+    if (access_strings.empty())
+    {
+        access_strings.reserve(5);
+        access_strings.push_back(LLTrans::getString("SIM_ACCESS_PG"));
+        access_strings.push_back(LLTrans::getString("SIM_ACCESS_MATURE"));
+        access_strings.push_back(LLTrans::getString("SIM_ACCESS_ADULT"));
+        access_strings.push_back(LLTrans::getString("SIM_ACCESS_DOWN"));
+        access_strings.push_back(LLTrans::getString("SIM_ACCESS_MIN"));
+    }
+    switch(sim_access)
+    {
+    case SIM_ACCESS_PG:
+        return access_strings[0];
 
-	case SIM_ACCESS_MATURE:
-		return access_strings[1];
+    case SIM_ACCESS_MATURE:
+        return access_strings[1];
 
-	case SIM_ACCESS_ADULT:
-		return access_strings[2];
+    case SIM_ACCESS_ADULT:
+        return access_strings[2];
 
-	case SIM_ACCESS_DOWN:
-		return access_strings[3];
+    case SIM_ACCESS_DOWN:
+        return access_strings[3];
 
-	case SIM_ACCESS_MIN:
-	default:
-		return access_strings[4];
-	}
+    case SIM_ACCESS_MIN:
+    default:
+        return access_strings[4];
+    }
 }
 
 // static
 std::string LLViewerRegion::getAccessIcon(U8 sim_access)
 {
-	switch(sim_access)
-	{
-	case SIM_ACCESS_MATURE:
-		return "Parcel_M_Dark";
+    switch(sim_access)
+    {
+    case SIM_ACCESS_MATURE:
+        return "Parcel_M_Dark";
 
-	case SIM_ACCESS_ADULT:
-		return "Parcel_R_Light";
+    case SIM_ACCESS_ADULT:
+        return "Parcel_R_Light";
 
-	case SIM_ACCESS_PG:
-		return "Parcel_PG_Light";
+    case SIM_ACCESS_PG:
+        return "Parcel_PG_Light";
 
-	case SIM_ACCESS_MIN:
-	default:
-		return "";
-	}
+    case SIM_ACCESS_MIN:
+    default:
+        return "";
+    }
 }
 
 // static
 std::string LLViewerRegion::accessToShortString(U8 sim_access)
 {
-	switch(sim_access)		/* Flawfinder: ignore */
-	{
-	case SIM_ACCESS_PG:
-		return "PG";
+    switch(sim_access)      /* Flawfinder: ignore */
+    {
+    case SIM_ACCESS_PG:
+        return "PG";
 
-	case SIM_ACCESS_MATURE:
-		return "M";
+    case SIM_ACCESS_MATURE:
+        return "M";
 
-	case SIM_ACCESS_ADULT:
-		return "A";
+    case SIM_ACCESS_ADULT:
+        return "A";
 
-	case SIM_ACCESS_MIN:
-	default:
-		return "U";
-	}
+    case SIM_ACCESS_MIN:
+    default:
+        return "U";
+    }
 }
 
 // static
 U8 LLViewerRegion::shortStringToAccess(const std::string &sim_access)
 {
-	U8 accessValue;
+    U8 accessValue;
 
-	if (LLStringUtil::compareStrings(sim_access, "PG") == 0)
-	{
-		accessValue = SIM_ACCESS_PG;
-	}
-	else if (LLStringUtil::compareStrings(sim_access, "M") == 0)
-	{
-		accessValue = SIM_ACCESS_MATURE;
-	}
-	else if (LLStringUtil::compareStrings(sim_access, "A") == 0)
-	{
-		accessValue = SIM_ACCESS_ADULT;
-	}
-	else
-	{
-		accessValue = SIM_ACCESS_MIN;
-	}
+    if (LLStringUtil::compareStrings(sim_access, "PG") == 0)
+    {
+        accessValue = SIM_ACCESS_PG;
+    }
+    else if (LLStringUtil::compareStrings(sim_access, "M") == 0)
+    {
+        accessValue = SIM_ACCESS_MATURE;
+    }
+    else if (LLStringUtil::compareStrings(sim_access, "A") == 0)
+    {
+        accessValue = SIM_ACCESS_ADULT;
+    }
+    else
+    {
+        accessValue = SIM_ACCESS_MIN;
+    }
 
-	return accessValue;
+    return accessValue;
 }
 
 // static
 void LLViewerRegion::processRegionInfo(LLMessageSystem* msg, void**)
 {
-	// send it to 'observers'
-	// *TODO: switch the floaters to using LLRegionInfoModel
-	LL_INFOS() << "Processing region info" << LL_ENDL;
-	LLRegionInfoModel::instance().update(msg);
-	LLFloaterGodTools::processRegionInfo(msg);
-	LLFloaterRegionInfo::processRegionInfo(msg);
+    // send it to 'observers'
+    // *TODO: switch the floaters to using LLRegionInfoModel
+    LL_INFOS() << "Processing region info" << LL_ENDL;
+    LLRegionInfoModel::instance().update(msg);
+    LLFloaterGodTools::processRegionInfo(msg);
+    LLFloaterRegionInfo::processRegionInfo(msg);
 }
 
 void LLViewerRegion::setCacheID(const LLUUID& id)
 {
-	mImpl->mCacheID = id;
+    mImpl->mCacheID = id;
 }
 
 void LLViewerRegion::renderPropertyLines()
 {
-	if (mParcelOverlay)
-	{
+    if (mParcelOverlay)
+    {
         mParcelOverlay->renderPropertyLines();
-	}
+    }
 }
 
 void LLViewerRegion::renderPropertyLinesOnMinimap(F32 scale_pixels_per_meter, const F32 *parcel_outline_color)
@@ -1136,11 +1136,11 @@ void LLViewerRegion::renderPropertyLinesOnMinimap(F32 scale_pixels_per_meter, co
 // This gets called when the height field changes.
 void LLViewerRegion::dirtyHeights()
 {
-	// Property lines need to be reconstructed when the land changes.
-	if (mParcelOverlay)
-	{
-		mParcelOverlay->setDirty();
-	}
+    // Property lines need to be reconstructed when the land changes.
+    if (mParcelOverlay)
+    {
+        mParcelOverlay->setDirty();
+    }
 }
 
 void LLViewerRegion::dirtyAllPatches()
@@ -1150,159 +1150,159 @@ void LLViewerRegion::dirtyAllPatches()
 
 //physically delete the cache entry
 void LLViewerRegion::killCacheEntry(LLVOCacheEntry* entry, bool for_rendering)
-{	
-	if(!entry || !entry->isValid())
-	{
-		return;
-	}
-
-	if(for_rendering && !entry->isState(LLVOCacheEntry::ACTIVE))
-	{
-		addNewObject(entry); //force to add to rendering pipeline
-	}
-
-	//remove from active list and waiting list
-	if(entry->isState(LLVOCacheEntry::ACTIVE))
-	{
-		mImpl->mActiveSet.erase(entry);
-	}
-	else
-	{
-		if(entry->isState(LLVOCacheEntry::WAITING))
-		{
-			mImpl->mWaitingSet.erase(entry);
-		}
-		
-		//remove from mVOCachePartition
-		removeFromVOCacheTree(entry);
-	}
-
-	//remove from the forced visible list
-	mImpl->mVisibleEntries.erase(entry);
-
-	//disconnect from parent if it is a child
-	if(entry->getParentID() > 0)
-	{
-		LLVOCacheEntry* parent = getCacheEntry(entry->getParentID());
-		if(parent)
-		{
-			parent->removeChild(entry);
-		}
-	}
-	else if(entry->getNumOfChildren() > 0)//remove children from cache if has any
-	{
-		LLVOCacheEntry* child = entry->getChild();
-		while(child != NULL)
-		{
-			killCacheEntry(child, for_rendering);
-			child = entry->getChild();
-		}
-	}
-	// Kill the assocaited overrides
-	mImpl->mGLTFOverridesLLSD.erase(entry->getLocalID());
-	//will remove it from the object cache, real deletion
-	entry->setState(LLVOCacheEntry::INACTIVE);
-	entry->removeOctreeEntry();
-	entry->setValid(FALSE);
-
-}
-
-//physically delete the cache entry	
-void LLViewerRegion::killCacheEntry(U32 local_id) 
-{
-	killCacheEntry(getCacheEntry(local_id));
+{
+    if(!entry || !entry->isValid())
+    {
+        return;
+    }
+
+    if(for_rendering && !entry->isState(LLVOCacheEntry::ACTIVE))
+    {
+        addNewObject(entry); //force to add to rendering pipeline
+    }
+
+    //remove from active list and waiting list
+    if(entry->isState(LLVOCacheEntry::ACTIVE))
+    {
+        mImpl->mActiveSet.erase(entry);
+    }
+    else
+    {
+        if(entry->isState(LLVOCacheEntry::WAITING))
+        {
+            mImpl->mWaitingSet.erase(entry);
+        }
+
+        //remove from mVOCachePartition
+        removeFromVOCacheTree(entry);
+    }
+
+    //remove from the forced visible list
+    mImpl->mVisibleEntries.erase(entry);
+
+    //disconnect from parent if it is a child
+    if(entry->getParentID() > 0)
+    {
+        LLVOCacheEntry* parent = getCacheEntry(entry->getParentID());
+        if(parent)
+        {
+            parent->removeChild(entry);
+        }
+    }
+    else if(entry->getNumOfChildren() > 0)//remove children from cache if has any
+    {
+        LLVOCacheEntry* child = entry->getChild();
+        while(child != NULL)
+        {
+            killCacheEntry(child, for_rendering);
+            child = entry->getChild();
+        }
+    }
+    // Kill the assocaited overrides
+    mImpl->mGLTFOverridesLLSD.erase(entry->getLocalID());
+    //will remove it from the object cache, real deletion
+    entry->setState(LLVOCacheEntry::INACTIVE);
+    entry->removeOctreeEntry();
+    entry->setValid(FALSE);
+
+}
+
+//physically delete the cache entry
+void LLViewerRegion::killCacheEntry(U32 local_id)
+{
+    killCacheEntry(getCacheEntry(local_id));
 }
 
 U32 LLViewerRegion::getNumOfActiveCachedObjects() const
 {
-	return  mImpl->mActiveSet.size();
+    return  mImpl->mActiveSet.size();
 }
 
 void LLViewerRegion::addActiveCacheEntry(LLVOCacheEntry* entry)
 {
-	if(!entry || mDead)
-	{
-		return;
-	}
-	if(entry->isState(LLVOCacheEntry::ACTIVE))
-	{
-		return; //already inserted.
-	}
+    if(!entry || mDead)
+    {
+        return;
+    }
+    if(entry->isState(LLVOCacheEntry::ACTIVE))
+    {
+        return; //already inserted.
+    }
 
-	if(entry->isState(LLVOCacheEntry::WAITING))
-	{
-		mImpl->mWaitingSet.erase(entry);
-	}
+    if(entry->isState(LLVOCacheEntry::WAITING))
+    {
+        mImpl->mWaitingSet.erase(entry);
+    }
 
-	entry->setState(LLVOCacheEntry::ACTIVE);
-	entry->setVisible();
+    entry->setState(LLVOCacheEntry::ACTIVE);
+    entry->setVisible();
 
-	llassert(entry->getEntry()->hasDrawable());
-	mImpl->mActiveSet.insert(entry);
+    llassert(entry->getEntry()->hasDrawable());
+    mImpl->mActiveSet.insert(entry);
 }
 
 void LLViewerRegion::removeActiveCacheEntry(LLVOCacheEntry* entry, LLDrawable* drawablep)
 {
-	if(mDead || !entry || !entry->isValid())
-	{
-		return;
-	}
-	if(!entry->isState(LLVOCacheEntry::ACTIVE))
-	{
-		return; //not an active entry.
-	}
-
-	//shift to the local regional space from agent space
-	if(drawablep != NULL && drawablep->getVObj().notNull())
-	{
-		const LLVector3& pos = drawablep->getVObj()->getPositionRegion();
-		LLVector4a shift;
-		shift.load3(pos.mV);
-		shift.sub(entry->getPositionGroup());
-		entry->shift(shift);
-	}
-
-	if(entry->getParentID() > 0) //is a child
-	{
-		LLVOCacheEntry* parent = getCacheEntry(entry->getParentID());
-		if(parent)
-		{
-			parent->addChild(entry);
-		}
-		else //parent not in cache.
-		{
-			//this happens only when parent is not cacheable.
-			mOrphanMap[entry->getParentID()].push_back(entry->getLocalID());
-		}
-	}
-	else //insert to vo cache tree.
-	{		
-		entry->updateParentBoundingInfo();
-		entry->saveBoundingSphere();
-		addToVOCacheTree(entry);
-	}
-
-	mImpl->mVisibleEntries.erase(entry);
-	mImpl->mActiveSet.erase(entry);
-	mImpl->mWaitingSet.erase(entry);
-	entry->setState(LLVOCacheEntry::INACTIVE);
+    if(mDead || !entry || !entry->isValid())
+    {
+        return;
+    }
+    if(!entry->isState(LLVOCacheEntry::ACTIVE))
+    {
+        return; //not an active entry.
+    }
+
+    //shift to the local regional space from agent space
+    if(drawablep != NULL && drawablep->getVObj().notNull())
+    {
+        const LLVector3& pos = drawablep->getVObj()->getPositionRegion();
+        LLVector4a shift;
+        shift.load3(pos.mV);
+        shift.sub(entry->getPositionGroup());
+        entry->shift(shift);
+    }
+
+    if(entry->getParentID() > 0) //is a child
+    {
+        LLVOCacheEntry* parent = getCacheEntry(entry->getParentID());
+        if(parent)
+        {
+            parent->addChild(entry);
+        }
+        else //parent not in cache.
+        {
+            //this happens only when parent is not cacheable.
+            mOrphanMap[entry->getParentID()].push_back(entry->getLocalID());
+        }
+    }
+    else //insert to vo cache tree.
+    {
+        entry->updateParentBoundingInfo();
+        entry->saveBoundingSphere();
+        addToVOCacheTree(entry);
+    }
+
+    mImpl->mVisibleEntries.erase(entry);
+    mImpl->mActiveSet.erase(entry);
+    mImpl->mWaitingSet.erase(entry);
+    entry->setState(LLVOCacheEntry::INACTIVE);
 }
 
 bool LLViewerRegion::addVisibleGroup(LLViewerOctreeGroup* group)
 {
-	if(mDead || group->isEmpty())
-	{
-		return false;
-	}
-	
-	mImpl->mVisibleGroups.insert(group);
+    if(mDead || group->isEmpty())
+    {
+        return false;
+    }
 
-	return true;
+    mImpl->mVisibleGroups.insert(group);
+
+    return true;
 }
 
 U32 LLViewerRegion::getNumOfVisibleGroups() const
 {
-	return mImpl ? mImpl->mVisibleGroups.size() : 0;
+    return mImpl ? mImpl->mVisibleGroups.size() : 0;
 }
 
 void LLViewerRegion::updateReflectionProbes()
@@ -1347,306 +1347,306 @@ void LLViewerRegion::updateReflectionProbes()
 
 void LLViewerRegion::addToVOCacheTree(LLVOCacheEntry* entry)
 {
-	if(!sVOCacheCullingEnabled)
-	{
-		return;
-	}
+    if(!sVOCacheCullingEnabled)
+    {
+        return;
+    }
 
-	if(mDead || !entry || !entry->getEntry() || !entry->isValid())
-	{
-		return;
-	}
-	if(entry->getParentID() > 0)
-	{
-		return; //no child prim in cache octree.
-	}
+    if(mDead || !entry || !entry->getEntry() || !entry->isValid())
+    {
+        return;
+    }
+    if(entry->getParentID() > 0)
+    {
+        return; //no child prim in cache octree.
+    }
 
-	if(entry->hasState(LLVOCacheEntry::IN_VO_TREE))
-	{
-		return; //already in the tree.
-	}	
+    if(entry->hasState(LLVOCacheEntry::IN_VO_TREE))
+    {
+        return; //already in the tree.
+    }
 
-	llassert_always(!entry->getGroup()); //not in octree.
-	llassert(!entry->getEntry()->hasDrawable()); //not have drawables
+    llassert_always(!entry->getGroup()); //not in octree.
+    llassert(!entry->getEntry()->hasDrawable()); //not have drawables
 
-	if(mImpl->mVOCachePartition->addEntry(entry->getEntry()))
-	{
-		entry->setState(LLVOCacheEntry::IN_VO_TREE);
-	}
+    if(mImpl->mVOCachePartition->addEntry(entry->getEntry()))
+    {
+        entry->setState(LLVOCacheEntry::IN_VO_TREE);
+    }
 }
 
 void LLViewerRegion::removeFromVOCacheTree(LLVOCacheEntry* entry)
 {
-	if(mDead || !entry || !entry->getEntry())
-	{
-		return;
-	}
-	
-	if(!entry->hasState(LLVOCacheEntry::IN_VO_TREE))
-	{
-		return; //not in the tree.
-	}
-	entry->clearState(LLVOCacheEntry::IN_VO_TREE);
+    if(mDead || !entry || !entry->getEntry())
+    {
+        return;
+    }
+
+    if(!entry->hasState(LLVOCacheEntry::IN_VO_TREE))
+    {
+        return; //not in the tree.
+    }
+    entry->clearState(LLVOCacheEntry::IN_VO_TREE);
 
-	mImpl->mVOCachePartition->removeEntry(entry->getEntry());	
+    mImpl->mVOCachePartition->removeEntry(entry->getEntry());
 }
 
 //add child objects as visible entries
 void LLViewerRegion::addVisibleChildCacheEntry(LLVOCacheEntry* parent, LLVOCacheEntry* child)
 {
-	if(mDead)
-	{
-		return;
-	}
-
-	if(parent && (!parent->isValid() || !parent->isState(LLVOCacheEntry::ACTIVE)))
-	{
-		return; //parent must be valid and in rendering pipeline
-	}
-
-	if(child && (!child->getEntry() || !child->isValid() || !child->isState(LLVOCacheEntry::INACTIVE)))
-	{
-		return; //child must be valid and not in the rendering pipeline
-	}
-
-	if(child)
-	{
-		child->setState(LLVOCacheEntry::IN_QUEUE);
-		mImpl->mVisibleEntries.insert(child);
-	}	
-	else if(parent && parent->getNumOfChildren() > 0) //add all children
-	{
-		child = parent->getChild();
-		while(child != NULL)
-		{
-			addVisibleChildCacheEntry(NULL, child);
-			child = parent->getChild();
-		}
-	}
+    if(mDead)
+    {
+        return;
+    }
+
+    if(parent && (!parent->isValid() || !parent->isState(LLVOCacheEntry::ACTIVE)))
+    {
+        return; //parent must be valid and in rendering pipeline
+    }
+
+    if(child && (!child->getEntry() || !child->isValid() || !child->isState(LLVOCacheEntry::INACTIVE)))
+    {
+        return; //child must be valid and not in the rendering pipeline
+    }
+
+    if(child)
+    {
+        child->setState(LLVOCacheEntry::IN_QUEUE);
+        mImpl->mVisibleEntries.insert(child);
+    }
+    else if(parent && parent->getNumOfChildren() > 0) //add all children
+    {
+        child = parent->getChild();
+        while(child != NULL)
+        {
+            addVisibleChildCacheEntry(NULL, child);
+            child = parent->getChild();
+        }
+    }
 }
 
 void LLViewerRegion::updateVisibleEntries(F32 max_time)
 {
-	if(mDead)
-	{
-		return;
-	}
-
-	if(mImpl->mVisibleGroups.empty() && mImpl->mVisibleEntries.empty())
-	{
-		return;
-	}
-
-	if(!sNewObjectCreationThrottle)
-	{
-		return;
-	}
-
-	const F32 LARGE_SCENE_CONTRIBUTION = 1000.f; //a large number to force to load the object.
-	const LLVector3 camera_origin = LLViewerCamera::getInstance()->getOrigin();
-	const U32 cur_frame = LLViewerOctreeEntryData::getCurrentFrame();
-	bool needs_update = ((cur_frame - mImpl->mLastCameraUpdate) > 5) && ((camera_origin - mImpl->mLastCameraOrigin).lengthSquared() > 10.f);	
-	U32 last_update = mImpl->mLastCameraUpdate;
-	LLVector4a local_origin;
-	local_origin.load3((camera_origin - getOriginAgent()).mV);
-
-	//process visible entries
-	for(LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mVisibleEntries.begin(); iter != mImpl->mVisibleEntries.end();)
-	{
-		LLVOCacheEntry* vo_entry = *iter;
-		
-		if(vo_entry->isValid() && vo_entry->getState() < LLVOCacheEntry::WAITING)
-		{
-			//set a large number to force to load this object.
-			vo_entry->setSceneContribution(LARGE_SCENE_CONTRIBUTION);
-			
-			mImpl->mWaitingList.insert(vo_entry);
-			++iter;
-		}
-		else
-		{
-			LLVOCacheEntry::vocache_entry_set_t::iterator next_iter = iter;
-			++next_iter;
-			mImpl->mVisibleEntries.erase(iter);
-			iter = next_iter;
-		}
-	}
-
-	//
-	//process visible groups
-	//
-	//object projected area threshold
-	F32 projection_threshold = LLVOCacheEntry::getSquaredPixelThreshold(mImpl->mVOCachePartition->isFrontCull());
-	F32 dist_threshold = mImpl->mVOCachePartition->isFrontCull() ? gAgentCamera.mDrawDistance : LLVOCacheEntry::sRearFarRadius;
-	
-	std::set< LLPointer<LLViewerOctreeGroup> >::iterator group_iter = mImpl->mVisibleGroups.begin(), group_end = mImpl->mVisibleGroups.end();
-	for(; group_iter != group_end; ++group_iter)
-	{
-		LLPointer<LLViewerOctreeGroup> group = *group_iter;
-		if(group->getNumRefs() < 3 || //group to be deleted
-			!group->getOctreeNode() || group->isEmpty()) //group empty
+    if(mDead)
+    {
+        return;
+    }
+
+    if(mImpl->mVisibleGroups.empty() && mImpl->mVisibleEntries.empty())
+    {
+        return;
+    }
+
+    if(!sNewObjectCreationThrottle)
+    {
+        return;
+    }
+
+    const F32 LARGE_SCENE_CONTRIBUTION = 1000.f; //a large number to force to load the object.
+    const LLVector3 camera_origin = LLViewerCamera::getInstance()->getOrigin();
+    const U32 cur_frame = LLViewerOctreeEntryData::getCurrentFrame();
+    bool needs_update = ((cur_frame - mImpl->mLastCameraUpdate) > 5) && ((camera_origin - mImpl->mLastCameraOrigin).lengthSquared() > 10.f);
+    U32 last_update = mImpl->mLastCameraUpdate;
+    LLVector4a local_origin;
+    local_origin.load3((camera_origin - getOriginAgent()).mV);
+
+    //process visible entries
+    for(LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mVisibleEntries.begin(); iter != mImpl->mVisibleEntries.end();)
+    {
+        LLVOCacheEntry* vo_entry = *iter;
+
+        if(vo_entry->isValid() && vo_entry->getState() < LLVOCacheEntry::WAITING)
+        {
+            //set a large number to force to load this object.
+            vo_entry->setSceneContribution(LARGE_SCENE_CONTRIBUTION);
+
+            mImpl->mWaitingList.insert(vo_entry);
+            ++iter;
+        }
+        else
+        {
+            LLVOCacheEntry::vocache_entry_set_t::iterator next_iter = iter;
+            ++next_iter;
+            mImpl->mVisibleEntries.erase(iter);
+            iter = next_iter;
+        }
+    }
+
+    //
+    //process visible groups
+    //
+    //object projected area threshold
+    F32 projection_threshold = LLVOCacheEntry::getSquaredPixelThreshold(mImpl->mVOCachePartition->isFrontCull());
+    F32 dist_threshold = mImpl->mVOCachePartition->isFrontCull() ? gAgentCamera.mDrawDistance : LLVOCacheEntry::sRearFarRadius;
+
+    std::set< LLPointer<LLViewerOctreeGroup> >::iterator group_iter = mImpl->mVisibleGroups.begin(), group_end = mImpl->mVisibleGroups.end();
+    for(; group_iter != group_end; ++group_iter)
+    {
+        LLPointer<LLViewerOctreeGroup> group = *group_iter;
+        if(group->getNumRefs() < 3 || //group to be deleted
+            !group->getOctreeNode() || group->isEmpty()) //group empty
+        {
+            continue;
+        }
+
+        for (LLViewerOctreeGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
         {
-			continue;
-		}
-
-		for (LLViewerOctreeGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
-		{
-			if((*i)->hasVOCacheEntry())
-			{
-				LLVOCacheEntry* vo_entry = (LLVOCacheEntry*)(*i)->getVOCacheEntry();
-
-				if(vo_entry->getParentID() > 0) //is a child
-				{
-					//child visibility depends on its parent.
-					continue;
-				}
-				if(!vo_entry->isValid())
-				{
-					continue; //skip invalid entry.
-				}
-
-				vo_entry->calcSceneContribution(local_origin, needs_update, last_update, dist_threshold);
-				if(vo_entry->getSceneContribution() > projection_threshold)
-				{
-					mImpl->mWaitingList.insert(vo_entry);			
-				}
-			}
-		}
-	}
-
-	if(needs_update)
-	{
-		mImpl->mLastCameraOrigin = camera_origin;
-		mImpl->mLastCameraUpdate = cur_frame;
-	}
-
-	return;
+            if((*i)->hasVOCacheEntry())
+            {
+                LLVOCacheEntry* vo_entry = (LLVOCacheEntry*)(*i)->getVOCacheEntry();
+
+                if(vo_entry->getParentID() > 0) //is a child
+                {
+                    //child visibility depends on its parent.
+                    continue;
+                }
+                if(!vo_entry->isValid())
+                {
+                    continue; //skip invalid entry.
+                }
+
+                vo_entry->calcSceneContribution(local_origin, needs_update, last_update, dist_threshold);
+                if(vo_entry->getSceneContribution() > projection_threshold)
+                {
+                    mImpl->mWaitingList.insert(vo_entry);
+                }
+            }
+        }
+    }
+
+    if(needs_update)
+    {
+        mImpl->mLastCameraOrigin = camera_origin;
+        mImpl->mLastCameraUpdate = cur_frame;
+    }
+
+    return;
 }
 
 void LLViewerRegion::createVisibleObjects(F32 max_time)
 {
-	if(mDead)
-	{
-		return;
-	}
-	if(mImpl->mWaitingList.empty())
-	{
-		mImpl->mVOCachePartition->setCullHistory(FALSE);
-		return;
-	}	
-	
-	S32 throttle = sNewObjectCreationThrottle;
-	BOOL has_new_obj = FALSE;
-	LLTimer update_timer;	
-	for(LLVOCacheEntry::vocache_entry_priority_list_t::iterator iter = mImpl->mWaitingList.begin();
-		iter != mImpl->mWaitingList.end(); ++iter)
-	{
-		LLVOCacheEntry* vo_entry = *iter;		
-
-		if(vo_entry->getState() < LLVOCacheEntry::WAITING)
-		{
-			addNewObject(vo_entry);
-			has_new_obj = TRUE;
-			if(throttle > 0 && !(--throttle) && update_timer.getElapsedTimeF32() > max_time)
-			{
-				break;
-			}
-		}
-	}	
-
-	mImpl->mVOCachePartition->setCullHistory(has_new_obj);
-
-	return;
+    if(mDead)
+    {
+        return;
+    }
+    if(mImpl->mWaitingList.empty())
+    {
+        mImpl->mVOCachePartition->setCullHistory(FALSE);
+        return;
+    }
+
+    S32 throttle = sNewObjectCreationThrottle;
+    BOOL has_new_obj = FALSE;
+    LLTimer update_timer;
+    for(LLVOCacheEntry::vocache_entry_priority_list_t::iterator iter = mImpl->mWaitingList.begin();
+        iter != mImpl->mWaitingList.end(); ++iter)
+    {
+        LLVOCacheEntry* vo_entry = *iter;
+
+        if(vo_entry->getState() < LLVOCacheEntry::WAITING)
+        {
+            addNewObject(vo_entry);
+            has_new_obj = TRUE;
+            if(throttle > 0 && !(--throttle) && update_timer.getElapsedTimeF32() > max_time)
+            {
+                break;
+            }
+        }
+    }
+
+    mImpl->mVOCachePartition->setCullHistory(has_new_obj);
+
+    return;
 }
 
 void LLViewerRegion::clearCachedVisibleObjects()
 {
-	mImpl->mWaitingList.clear();
-	mImpl->mVisibleGroups.clear();
-
-	//reset all occluders
-	mImpl->mVOCachePartition->resetOccluders();
-	mPaused = TRUE;
-
-	//clean visible entries
-	for(LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mVisibleEntries.begin(); iter != mImpl->mVisibleEntries.end();)
-	{
-		LLVOCacheEntry* entry = *iter;
-		LLVOCacheEntry* parent = getCacheEntry(entry->getParentID());
-
-		if(!entry->getParentID() || parent) //no child or parent is cache-able
-		{
-			if(parent) //has a cache-able parent
-			{
-				parent->addChild(entry);
-			}
-
-			LLVOCacheEntry::vocache_entry_set_t::iterator next_iter = iter;
-			++next_iter;
-			mImpl->mVisibleEntries.erase(iter);
-			iter = next_iter;
-		}
-		else //parent is not cache-able, leave it.
-		{
-			++iter;
-		}
-	}
-
-	//remove all visible entries.
-	mLastVisitedEntry = NULL;
-	std::vector<LLDrawable*> delete_list;
-	for(LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mActiveSet.begin();
-		iter != mImpl->mActiveSet.end(); ++iter)
-	{
+    mImpl->mWaitingList.clear();
+    mImpl->mVisibleGroups.clear();
+
+    //reset all occluders
+    mImpl->mVOCachePartition->resetOccluders();
+    mPaused = TRUE;
+
+    //clean visible entries
+    for(LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mVisibleEntries.begin(); iter != mImpl->mVisibleEntries.end();)
+    {
+        LLVOCacheEntry* entry = *iter;
+        LLVOCacheEntry* parent = getCacheEntry(entry->getParentID());
+
+        if(!entry->getParentID() || parent) //no child or parent is cache-able
+        {
+            if(parent) //has a cache-able parent
+            {
+                parent->addChild(entry);
+            }
+
+            LLVOCacheEntry::vocache_entry_set_t::iterator next_iter = iter;
+            ++next_iter;
+            mImpl->mVisibleEntries.erase(iter);
+            iter = next_iter;
+        }
+        else //parent is not cache-able, leave it.
+        {
+            ++iter;
+        }
+    }
+
+    //remove all visible entries.
+    mLastVisitedEntry = NULL;
+    std::vector<LLDrawable*> delete_list;
+    for(LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mActiveSet.begin();
+        iter != mImpl->mActiveSet.end(); ++iter)
+    {
         LLVOCacheEntry* vo_entry = *iter;
         if (!vo_entry || !vo_entry->getEntry())
         {
             continue;
         }
         LLDrawable* drawablep = (LLDrawable*)vo_entry->getEntry()->getDrawable();
-	
-		if(drawablep && !drawablep->getParent())
-		{
-			delete_list.push_back(drawablep);
-		}
-	}
 
-	if(!delete_list.empty())
-	{
-		for(S32 i = 0; i < delete_list.size(); i++)
-		{
-			gObjectList.killObject(delete_list[i]->getVObj());
-		}
-		delete_list.clear();
-	}
+        if(drawablep && !drawablep->getParent())
+        {
+            delete_list.push_back(drawablep);
+        }
+    }
+
+    if(!delete_list.empty())
+    {
+        for(S32 i = 0; i < delete_list.size(); i++)
+        {
+            gObjectList.killObject(delete_list[i]->getVObj());
+        }
+        delete_list.clear();
+    }
 
-	return;
+    return;
 }
 
 //perform some necessary but very light updates.
 //to replace the function idleUpdate(...) in case there is no enough time.
 void LLViewerRegion::lightIdleUpdate()
 {
-	if(!sVOCacheCullingEnabled)
-	{
-		return;
-	}
-	if(mImpl->mCacheMap.empty())
-	{
-		return;
-	}
+    if(!sVOCacheCullingEnabled)
+    {
+        return;
+    }
+    if(mImpl->mCacheMap.empty())
+    {
+        return;
+    }
 
-	//reset all occluders
-	mImpl->mVOCachePartition->resetOccluders();	
+    //reset all occluders
+    mImpl->mVOCachePartition->resetOccluders();
 }
 
 void LLViewerRegion::idleUpdate(F32 max_update_time)
-{	
+{
     LL_PROFILE_ZONE_SCOPED;
-	LLTimer update_timer;
-	F32 max_time;
+    LLTimer update_timer;
+    F32 max_time;
 
-	mLastUpdate = LLViewerOctreeEntryData::getCurrentFrame();
+    mLastUpdate = LLViewerOctreeEntryData::getCurrentFrame();
 
     static LLCachedControl<bool> pbr_terrain_enabled(gSavedSettings, "RenderTerrainPBREnabled", false);
     static LLCachedControl<bool> pbr_terrain_experimental_normals(gSavedSettings, "RenderTerrainPBRNormalsEnabled", false);
@@ -1661,48 +1661,48 @@ void LLViewerRegion::idleUpdate(F32 max_update_time)
     {
         mImpl->mLandp->idleUpdate</*PBR=*/true>(max_update_time);
     }
-	
-	if (mParcelOverlay)
-	{
-		// Hopefully not a significant time sink...
-		mParcelOverlay->idleUpdate();
-	}
 
-	if(!sVOCacheCullingEnabled)
-	{
-		return;
-	}
-	if(mImpl->mCacheMap.empty())
-	{
-		return;
-	}	
-	if(mPaused)
-	{
-		mPaused = FALSE; //unpause.
-	}
+    if (mParcelOverlay)
+    {
+        // Hopefully not a significant time sink...
+        mParcelOverlay->idleUpdate();
+    }
+
+    if(!sVOCacheCullingEnabled)
+    {
+        return;
+    }
+    if(mImpl->mCacheMap.empty())
+    {
+        return;
+    }
+    if(mPaused)
+    {
+        mPaused = FALSE; //unpause.
+    }
 
-	LLViewerCamera::eCameraID old_camera_id = LLViewerCamera::sCurCameraID;
-	LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
+    LLViewerCamera::eCameraID old_camera_id = LLViewerCamera::sCurCameraID;
+    LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
 
-	//reset all occluders
-	mImpl->mVOCachePartition->resetOccluders();	
+    //reset all occluders
+    mImpl->mVOCachePartition->resetOccluders();
 
-	max_time = max_update_time - update_timer.getElapsedTimeF32();	
+    max_time = max_update_time - update_timer.getElapsedTimeF32();
 
-	//kill invisible objects
-	killInvisibleObjects(max_time * 0.4f);	
-	max_time = max_update_time - update_timer.getElapsedTimeF32();	
+    //kill invisible objects
+    killInvisibleObjects(max_time * 0.4f);
+    max_time = max_update_time - update_timer.getElapsedTimeF32();
 
-	updateVisibleEntries(max_time);
-	max_time = max_update_time - update_timer.getElapsedTimeF32();	
+    updateVisibleEntries(max_time);
+    max_time = max_update_time - update_timer.getElapsedTimeF32();
 
-	createVisibleObjects(max_time);
+    createVisibleObjects(max_time);
 
-	mImpl->mWaitingList.clear();
-	mImpl->mVisibleGroups.clear();
+    mImpl->mWaitingList.clear();
+    mImpl->mVisibleGroups.clear();
 
-	LLViewerCamera::sCurCameraID = old_camera_id;
-	return;
+    LLViewerCamera::sCurCameraID = old_camera_id;
+    return;
 }
 
 // static
@@ -1718,395 +1718,395 @@ void LLViewerRegion::idleCleanup(F32 max_update_time)
 //update the throttling number for new object creation
 void LLViewerRegion::calcNewObjectCreationThrottle()
 {
-	static LLCachedControl<S32> new_object_creation_throttle(gSavedSettings,"NewObjectCreationThrottle");
-	static LLCachedControl<F32> throttle_delay_time(gSavedSettings,"NewObjectCreationThrottleDelayTime");
-	static LLFrameTimer timer;
-
-	//
-	//sNewObjectCreationThrottle =
-	//-2: throttle is disabled because either the screen is showing progress view, or immediate after the screen is not black
-	//-1: throttle is disabled by the debug setting
-	//0:  no new object creation is allowed
-	//>0: valid throttling number
-	//
-
-	if(gViewerWindow->getProgressView()->getVisible() && throttle_delay_time > 0.f)
-	{
-		sNewObjectCreationThrottle = -2; //cancel the throttling
-		timer.reset();
-	}	
-	else if(sNewObjectCreationThrottle < -1) //just recoved from the login/teleport screen
-	{
-		if(timer.getElapsedTimeF32() > throttle_delay_time) //wait for throttle_delay_time to reset the throttle
-		{
-			sNewObjectCreationThrottle = new_object_creation_throttle; //reset
-			if(sNewObjectCreationThrottle < -1)
-			{
-				sNewObjectCreationThrottle = -1;
-			}
-		}
-	}
-
-	//update some LLVOCacheEntry debug setting factors.
-	LLVOCacheEntry::updateDebugSettings();
+    static LLCachedControl<S32> new_object_creation_throttle(gSavedSettings,"NewObjectCreationThrottle");
+    static LLCachedControl<F32> throttle_delay_time(gSavedSettings,"NewObjectCreationThrottleDelayTime");
+    static LLFrameTimer timer;
+
+    //
+    //sNewObjectCreationThrottle =
+    //-2: throttle is disabled because either the screen is showing progress view, or immediate after the screen is not black
+    //-1: throttle is disabled by the debug setting
+    //0:  no new object creation is allowed
+    //>0: valid throttling number
+    //
+
+    if(gViewerWindow->getProgressView()->getVisible() && throttle_delay_time > 0.f)
+    {
+        sNewObjectCreationThrottle = -2; //cancel the throttling
+        timer.reset();
+    }
+    else if(sNewObjectCreationThrottle < -1) //just recoved from the login/teleport screen
+    {
+        if(timer.getElapsedTimeF32() > throttle_delay_time) //wait for throttle_delay_time to reset the throttle
+        {
+            sNewObjectCreationThrottle = new_object_creation_throttle; //reset
+            if(sNewObjectCreationThrottle < -1)
+            {
+                sNewObjectCreationThrottle = -1;
+            }
+        }
+    }
+
+    //update some LLVOCacheEntry debug setting factors.
+    LLVOCacheEntry::updateDebugSettings();
 }
 
 BOOL LLViewerRegion::isViewerCameraStatic()
 {
-	return sLastCameraUpdated < LLViewerOctreeEntryData::getCurrentFrame();
+    return sLastCameraUpdated < LLViewerOctreeEntryData::getCurrentFrame();
 }
 
 void LLViewerRegion::killInvisibleObjects(F32 max_time)
 {
 #if 1 // TODO: kill this.  This is ill-conceived, objects that aren't in the camera frustum should not be deleted from memory.
         // because of this, every time you turn around the simulator sends a swarm of full object update messages from cache
-    // probe misses and objects have to be reloaded from scratch.  From some reason, disabling this causes holes to 
+    // probe misses and objects have to be reloaded from scratch.  From some reason, disabling this causes holes to
     // appear in the scene when flying back and forth between regions
-	if(!sVOCacheCullingEnabled)
-	{
-		return;
-	}
-	if(mImpl->mActiveSet.empty())
-	{
-		return;
-	}
-	if(sNewObjectCreationThrottle < 0)
-	{
-		return;
-	}
-
-	LLTimer update_timer;
-	LLVector4a camera_origin;
-	camera_origin.load3(LLViewerCamera::getInstance()->getOrigin().mV);
-	LLVector4a local_origin;
-	local_origin.load3((LLViewerCamera::getInstance()->getOrigin() - getOriginAgent()).mV);
-	F32 back_threshold = LLVOCacheEntry::sRearFarRadius;
-	
-	size_t max_update = 64; 
-	if(!mInvisibilityCheckHistory && isViewerCameraStatic())
-	{
-		//history is clean, reduce number of checking
-		max_update /= 2;
-	}
-	
-	std::vector<LLDrawable*> delete_list;
-	S32 update_counter = llmin(max_update, mImpl->mActiveSet.size());
-	LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mActiveSet.upper_bound(mLastVisitedEntry);		
-
-	for(; update_counter > 0; --update_counter, ++iter)
-	{	
-		if(iter == mImpl->mActiveSet.end())
-		{
-			iter = mImpl->mActiveSet.begin();
-		}
-		if((*iter)->getParentID() > 0)
-		{
-			continue; //skip child objects, they are removed with their parent.
-		}
-
-		LLVOCacheEntry* vo_entry = *iter;
-		if(!vo_entry->isAnyVisible(camera_origin, local_origin, back_threshold) && vo_entry->mLastCameraUpdated < sLastCameraUpdated)
-		{
-			killObject(vo_entry, delete_list);
-		}
-
-		if(max_time < update_timer.getElapsedTimeF32()) //time out
-		{
-			break;
-		}
-	}
-
-	if(iter == mImpl->mActiveSet.end())
-	{
-		mLastVisitedEntry = NULL;
-	}
-	else
-	{
-		mLastVisitedEntry = *iter;
-	}
-
-	mInvisibilityCheckHistory <<= 1;
-	if(!delete_list.empty())
-	{
-		mInvisibilityCheckHistory |= 1;
-		S32 count = delete_list.size();
-		for(S32 i = 0; i < count; i++)
-		{
-			gObjectList.killObject(delete_list[i]->getVObj());
-		}
-		delete_list.clear();
-	}
-
-	return;
-#endif
-}
+    if(!sVOCacheCullingEnabled)
+    {
+        return;
+    }
+    if(mImpl->mActiveSet.empty())
+    {
+        return;
+    }
+    if(sNewObjectCreationThrottle < 0)
+    {
+        return;
+    }
+
+    LLTimer update_timer;
+    LLVector4a camera_origin;
+    camera_origin.load3(LLViewerCamera::getInstance()->getOrigin().mV);
+    LLVector4a local_origin;
+    local_origin.load3((LLViewerCamera::getInstance()->getOrigin() - getOriginAgent()).mV);
+    F32 back_threshold = LLVOCacheEntry::sRearFarRadius;
+
+    size_t max_update = 64;
+    if(!mInvisibilityCheckHistory && isViewerCameraStatic())
+    {
+        //history is clean, reduce number of checking
+        max_update /= 2;
+    }
+
+    std::vector<LLDrawable*> delete_list;
+    S32 update_counter = llmin(max_update, mImpl->mActiveSet.size());
+    LLVOCacheEntry::vocache_entry_set_t::iterator iter = mImpl->mActiveSet.upper_bound(mLastVisitedEntry);
+
+    for(; update_counter > 0; --update_counter, ++iter)
+    {
+        if(iter == mImpl->mActiveSet.end())
+        {
+            iter = mImpl->mActiveSet.begin();
+        }
+        if((*iter)->getParentID() > 0)
+        {
+            continue; //skip child objects, they are removed with their parent.
+        }
+
+        LLVOCacheEntry* vo_entry = *iter;
+        if(!vo_entry->isAnyVisible(camera_origin, local_origin, back_threshold) && vo_entry->mLastCameraUpdated < sLastCameraUpdated)
+        {
+            killObject(vo_entry, delete_list);
+        }
+
+        if(max_time < update_timer.getElapsedTimeF32()) //time out
+        {
+            break;
+        }
+    }
+
+    if(iter == mImpl->mActiveSet.end())
+    {
+        mLastVisitedEntry = NULL;
+    }
+    else
+    {
+        mLastVisitedEntry = *iter;
+    }
+
+    mInvisibilityCheckHistory <<= 1;
+    if(!delete_list.empty())
+    {
+        mInvisibilityCheckHistory |= 1;
+        S32 count = delete_list.size();
+        for(S32 i = 0; i < count; i++)
+        {
+            gObjectList.killObject(delete_list[i]->getVObj());
+        }
+        delete_list.clear();
+    }
+
+    return;
+#endif
+}
 
 void LLViewerRegion::killObject(LLVOCacheEntry* entry, std::vector<LLDrawable*>& delete_list)
 {
-	//kill the object.
-	LLDrawable* drawablep = (LLDrawable*)entry->getEntry()->getDrawable();
-	llassert(drawablep);
-	llassert(drawablep->getRegion() == this);
-
-	if(drawablep && !drawablep->getParent())
-	{
-		LLViewerObject* v_obj = drawablep->getVObj();
-		if (v_obj->isSelected()
-			|| (v_obj->flagAnimSource() && isAgentAvatarValid() && gAgentAvatarp->hasMotionFromSource(v_obj->getID())))
-		{
-			// do not remove objects user is interacting with
-			((LLViewerOctreeEntryData*)drawablep)->setVisible();
-			return;
-		}
-		LLViewerObject::const_child_list_t& child_list = v_obj->getChildren();
-		for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
-			iter != child_list.end(); iter++)
-		{
-			LLViewerObject* child = *iter;
-			if(child->mDrawable)
-			{
-				if( !child->mDrawable->getEntry()
-					|| !child->mDrawable->getEntry()->hasVOCacheEntry()
-					|| child->isSelected()
-					|| (child->flagAnimSource() && isAgentAvatarValid() && gAgentAvatarp->hasMotionFromSource(child->getID())))
-				{
-					//do not remove parent if any of its children non-cacheable, animating or selected
-					//especially for the case that an avatar sits on a cache-able object
-					((LLViewerOctreeEntryData*)drawablep)->setVisible();
-					return;
-				}
-
-				LLOcclusionCullingGroup* group = (LLOcclusionCullingGroup*)child->mDrawable->getGroup();
-				if(group && group->isAnyRecentlyVisible())
-				{
-					//set the parent visible if any of its children visible.
-					((LLViewerOctreeEntryData*)drawablep)->setVisible();
-					return;
-				}
-			}
-		}
-		delete_list.push_back(drawablep);				
-	}				
+    //kill the object.
+    LLDrawable* drawablep = (LLDrawable*)entry->getEntry()->getDrawable();
+    llassert(drawablep);
+    llassert(drawablep->getRegion() == this);
+
+    if(drawablep && !drawablep->getParent())
+    {
+        LLViewerObject* v_obj = drawablep->getVObj();
+        if (v_obj->isSelected()
+            || (v_obj->flagAnimSource() && isAgentAvatarValid() && gAgentAvatarp->hasMotionFromSource(v_obj->getID())))
+        {
+            // do not remove objects user is interacting with
+            ((LLViewerOctreeEntryData*)drawablep)->setVisible();
+            return;
+        }
+        LLViewerObject::const_child_list_t& child_list = v_obj->getChildren();
+        for (LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
+            iter != child_list.end(); iter++)
+        {
+            LLViewerObject* child = *iter;
+            if(child->mDrawable)
+            {
+                if( !child->mDrawable->getEntry()
+                    || !child->mDrawable->getEntry()->hasVOCacheEntry()
+                    || child->isSelected()
+                    || (child->flagAnimSource() && isAgentAvatarValid() && gAgentAvatarp->hasMotionFromSource(child->getID())))
+                {
+                    //do not remove parent if any of its children non-cacheable, animating or selected
+                    //especially for the case that an avatar sits on a cache-able object
+                    ((LLViewerOctreeEntryData*)drawablep)->setVisible();
+                    return;
+                }
+
+                LLOcclusionCullingGroup* group = (LLOcclusionCullingGroup*)child->mDrawable->getGroup();
+                if(group && group->isAnyRecentlyVisible())
+                {
+                    //set the parent visible if any of its children visible.
+                    ((LLViewerOctreeEntryData*)drawablep)->setVisible();
+                    return;
+                }
+            }
+        }
+        delete_list.push_back(drawablep);
+    }
 }
 
 LLViewerObject* LLViewerRegion::addNewObject(LLVOCacheEntry* entry)
 {
-	if(!entry || !entry->getEntry())
-	{
-		if(entry)
-		{
-			mImpl->mVisibleEntries.erase(entry);
-			entry->setState(LLVOCacheEntry::INACTIVE);
-		}
-		return NULL;
-	}
-
-	LLViewerObject* obj = NULL;
-	if(!entry->getEntry()->hasDrawable()) //not added to the rendering pipeline yet
-	{ 
-		//add the object
-		obj = gObjectList.processObjectUpdateFromCache(entry, this);
-		if(obj)
-		{
-			if(!entry->isState(LLVOCacheEntry::ACTIVE))
-			{
-				mImpl->mWaitingSet.insert(entry);
-				entry->setState(LLVOCacheEntry::WAITING);
-			}
-		}
-	}
-	else
-	{
-		LLViewerRegion* old_regionp = ((LLDrawable*)entry->getEntry()->getDrawable())->getRegion();
-		if(old_regionp != this)
-		{
-			//this object exists in two regions at the same time;
-			//this case can be safely ignored here because
-			//server should soon send update message to remove one region for this object.
-
-			LL_WARNS() << "Entry: " << entry->getLocalID() << " exists in two regions at the same time." << LL_ENDL;
-			return NULL;
-		}
-		
-		LL_WARNS() << "Entry: " << entry->getLocalID() << " in rendering pipeline but not set to be active." << LL_ENDL;
-
-		//should not hit here any more, but does not hurt either, just put it back to active list
-		addActiveCacheEntry(entry);
-	}
-
-	return obj;
+    if(!entry || !entry->getEntry())
+    {
+        if(entry)
+        {
+            mImpl->mVisibleEntries.erase(entry);
+            entry->setState(LLVOCacheEntry::INACTIVE);
+        }
+        return NULL;
+    }
+
+    LLViewerObject* obj = NULL;
+    if(!entry->getEntry()->hasDrawable()) //not added to the rendering pipeline yet
+    {
+        //add the object
+        obj = gObjectList.processObjectUpdateFromCache(entry, this);
+        if(obj)
+        {
+            if(!entry->isState(LLVOCacheEntry::ACTIVE))
+            {
+                mImpl->mWaitingSet.insert(entry);
+                entry->setState(LLVOCacheEntry::WAITING);
+            }
+        }
+    }
+    else
+    {
+        LLViewerRegion* old_regionp = ((LLDrawable*)entry->getEntry()->getDrawable())->getRegion();
+        if(old_regionp != this)
+        {
+            //this object exists in two regions at the same time;
+            //this case can be safely ignored here because
+            //server should soon send update message to remove one region for this object.
+
+            LL_WARNS() << "Entry: " << entry->getLocalID() << " exists in two regions at the same time." << LL_ENDL;
+            return NULL;
+        }
+
+        LL_WARNS() << "Entry: " << entry->getLocalID() << " in rendering pipeline but not set to be active." << LL_ENDL;
+
+        //should not hit here any more, but does not hurt either, just put it back to active list
+        addActiveCacheEntry(entry);
+    }
+
+    return obj;
 }
 
 //update object cache if the object receives a full-update or terse update
 //update_type == EObjectUpdateType::OUT_TERSE_IMPROVED or EObjectUpdateType::OUT_FULL
 LLViewerObject* LLViewerRegion::updateCacheEntry(U32 local_id, LLViewerObject* objectp)
 {
-	LLVOCacheEntry* entry = getCacheEntry(local_id);
-	if (!entry)
-	{
-		return objectp; //not in the cache, do nothing.
-	}
-	if(!objectp) //object not created
-	{
-		//create a new object from cache.
-		objectp = addNewObject(entry);
-	}
+    LLVOCacheEntry* entry = getCacheEntry(local_id);
+    if (!entry)
+    {
+        return objectp; //not in the cache, do nothing.
+    }
+    if(!objectp) //object not created
+    {
+        //create a new object from cache.
+        objectp = addNewObject(entry);
+    }
 
     //remove from cache.
     killCacheEntry(entry, true);
 
-	return objectp;
+    return objectp;
 }
 
 // As above, but forcibly do the update.
 void LLViewerRegion::forceUpdate()
 {
-	constexpr F32 max_update_time = 0.f;
+    constexpr F32 max_update_time = 0.f;
 
     static LLCachedControl<bool> pbr_terrain_enabled(gSavedSettings, "RenderTerrainPBREnabled", false);
     static LLCachedControl<bool> pbr_terrain_experimental_normals(gSavedSettings, "RenderTerrainPBRNormalsEnabled", false);
-	bool pbr_material = mImpl->mCompositionp && (mImpl->mCompositionp->getMaterialType() == LLTerrainMaterials::Type::PBR);
-	bool pbr_land = pbr_material && pbr_terrain_enabled && pbr_terrain_experimental_normals;
+    bool pbr_material = mImpl->mCompositionp && (mImpl->mCompositionp->getMaterialType() == LLTerrainMaterials::Type::PBR);
+    bool pbr_land = pbr_material && pbr_terrain_enabled && pbr_terrain_experimental_normals;
 
-	if (!pbr_land)
-	{
-		mImpl->mLandp->idleUpdate</*PBR=*/false>(max_update_time);
-	}
-	else
-	{
-		mImpl->mLandp->idleUpdate</*PBR=*/true>(max_update_time);
-	}
+    if (!pbr_land)
+    {
+        mImpl->mLandp->idleUpdate</*PBR=*/false>(max_update_time);
+    }
+    else
+    {
+        mImpl->mLandp->idleUpdate</*PBR=*/true>(max_update_time);
+    }
 
-	if (mParcelOverlay)
-	{
-		mParcelOverlay->idleUpdate(true);
-	}
+    if (mParcelOverlay)
+    {
+        mParcelOverlay->idleUpdate(true);
+    }
 }
 
 void LLViewerRegion::connectNeighbor(LLViewerRegion *neighborp, U32 direction)
 {
-	mImpl->mLandp->connectNeighbor(neighborp->mImpl->mLandp, direction);
+    mImpl->mLandp->connectNeighbor(neighborp->mImpl->mLandp, direction);
 }
 
 
 void LLViewerRegion::disconnectAllNeighbors()
 {
-	mImpl->mLandp->disconnectAllNeighbors();
+    mImpl->mLandp->disconnectAllNeighbors();
 }
 
 LLVLComposition * LLViewerRegion::getComposition() const
 {
-	return mImpl->mCompositionp;
+    return mImpl->mCompositionp;
 }
 
 F32 LLViewerRegion::getCompositionXY(const S32 x, const S32 y) const
 {
-	if (x >= mWidth)
-	{
-		if (y >= mWidth)
-		{
-			LLVector3d center = getCenterGlobal() + LLVector3d(mWidth, mWidth, 0.f);
-			LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromPosGlobal(center);
-			if (regionp)
-			{
-				// OK, we need to do some hackery here - different simulators no longer use
-				// the same composition values, necessarily.
-				// If we're attempting to blend, then we want to make the fractional part of
-				// this region match the fractional of the adjacent.  For now, just minimize
-				// the delta.
-				F32 our_comp = getComposition()->getValueScaled(mWidth-1.f, mWidth-1.f);
-				F32 adj_comp = regionp->getComposition()->getValueScaled(x - regionp->getWidth(), y - regionp->getWidth());
-				while (llabs(our_comp - adj_comp) >= 1.f)
-				{
-					if (our_comp > adj_comp)
-					{
-						adj_comp += 1.f;
-					}
-					else
-					{
-						adj_comp -= 1.f;
-					}
-				}
-				return adj_comp;
-			}
-		}
-		else
-		{
-			LLVector3d center = getCenterGlobal() + LLVector3d(mWidth, 0.f, 0.f);
-			LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromPosGlobal(center);
-			if (regionp)
-			{
-				// OK, we need to do some hackery here - different simulators no longer use
-				// the same composition values, necessarily.
-				// If we're attempting to blend, then we want to make the fractional part of
-				// this region match the fractional of the adjacent.  For now, just minimize
-				// the delta.
-				F32 our_comp = getComposition()->getValueScaled(mWidth-1.f, (F32)y);
-				F32 adj_comp = regionp->getComposition()->getValueScaled(x - regionp->getWidth(), (F32)y);
-				while (llabs(our_comp - adj_comp) >= 1.f)
-				{
-					if (our_comp > adj_comp)
-					{
-						adj_comp += 1.f;
-					}
-					else
-					{
-						adj_comp -= 1.f;
-					}
-				}
-				return adj_comp;
-			}
-		}
-	}
-	else if (y >= mWidth)
-	{
-		LLVector3d center = getCenterGlobal() + LLVector3d(0.f, mWidth, 0.f);
-		LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromPosGlobal(center);
-		if (regionp)
-		{
-			// OK, we need to do some hackery here - different simulators no longer use
-			// the same composition values, necessarily.
-			// If we're attempting to blend, then we want to make the fractional part of
-			// this region match the fractional of the adjacent.  For now, just minimize
-			// the delta.
-			F32 our_comp = getComposition()->getValueScaled((F32)x, mWidth-1.f);
-			F32 adj_comp = regionp->getComposition()->getValueScaled((F32)x, y - regionp->getWidth());
-			while (llabs(our_comp - adj_comp) >= 1.f)
-			{
-				if (our_comp > adj_comp)
-				{
-					adj_comp += 1.f;
-				}
-				else
-				{
-					adj_comp -= 1.f;
-				}
-			}
-			return adj_comp;
-		}
-	}
-
-	return getComposition()->getValueScaled((F32)x, (F32)y);
-}
-
-void LLViewerRegion::calculateCenterGlobal() 
-{
-	mImpl->mCenterGlobal = mImpl->mOriginGlobal;
-	mImpl->mCenterGlobal.mdV[VX] += 0.5 * mWidth;
-	mImpl->mCenterGlobal.mdV[VY] += 0.5 * mWidth;
-	mImpl->mCenterGlobal.mdV[VZ] = 0.5 * mImpl->mLandp->getMinZ() + mImpl->mLandp->getMaxZ();
+    if (x >= mWidth)
+    {
+        if (y >= mWidth)
+        {
+            LLVector3d center = getCenterGlobal() + LLVector3d(mWidth, mWidth, 0.f);
+            LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromPosGlobal(center);
+            if (regionp)
+            {
+                // OK, we need to do some hackery here - different simulators no longer use
+                // the same composition values, necessarily.
+                // If we're attempting to blend, then we want to make the fractional part of
+                // this region match the fractional of the adjacent.  For now, just minimize
+                // the delta.
+                F32 our_comp = getComposition()->getValueScaled(mWidth-1.f, mWidth-1.f);
+                F32 adj_comp = regionp->getComposition()->getValueScaled(x - regionp->getWidth(), y - regionp->getWidth());
+                while (llabs(our_comp - adj_comp) >= 1.f)
+                {
+                    if (our_comp > adj_comp)
+                    {
+                        adj_comp += 1.f;
+                    }
+                    else
+                    {
+                        adj_comp -= 1.f;
+                    }
+                }
+                return adj_comp;
+            }
+        }
+        else
+        {
+            LLVector3d center = getCenterGlobal() + LLVector3d(mWidth, 0.f, 0.f);
+            LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromPosGlobal(center);
+            if (regionp)
+            {
+                // OK, we need to do some hackery here - different simulators no longer use
+                // the same composition values, necessarily.
+                // If we're attempting to blend, then we want to make the fractional part of
+                // this region match the fractional of the adjacent.  For now, just minimize
+                // the delta.
+                F32 our_comp = getComposition()->getValueScaled(mWidth-1.f, (F32)y);
+                F32 adj_comp = regionp->getComposition()->getValueScaled(x - regionp->getWidth(), (F32)y);
+                while (llabs(our_comp - adj_comp) >= 1.f)
+                {
+                    if (our_comp > adj_comp)
+                    {
+                        adj_comp += 1.f;
+                    }
+                    else
+                    {
+                        adj_comp -= 1.f;
+                    }
+                }
+                return adj_comp;
+            }
+        }
+    }
+    else if (y >= mWidth)
+    {
+        LLVector3d center = getCenterGlobal() + LLVector3d(0.f, mWidth, 0.f);
+        LLViewerRegion *regionp = LLWorld::getInstance()->getRegionFromPosGlobal(center);
+        if (regionp)
+        {
+            // OK, we need to do some hackery here - different simulators no longer use
+            // the same composition values, necessarily.
+            // If we're attempting to blend, then we want to make the fractional part of
+            // this region match the fractional of the adjacent.  For now, just minimize
+            // the delta.
+            F32 our_comp = getComposition()->getValueScaled((F32)x, mWidth-1.f);
+            F32 adj_comp = regionp->getComposition()->getValueScaled((F32)x, y - regionp->getWidth());
+            while (llabs(our_comp - adj_comp) >= 1.f)
+            {
+                if (our_comp > adj_comp)
+                {
+                    adj_comp += 1.f;
+                }
+                else
+                {
+                    adj_comp -= 1.f;
+                }
+            }
+            return adj_comp;
+        }
+    }
+
+    return getComposition()->getValueScaled((F32)x, (F32)y);
+}
+
+void LLViewerRegion::calculateCenterGlobal()
+{
+    mImpl->mCenterGlobal = mImpl->mOriginGlobal;
+    mImpl->mCenterGlobal.mdV[VX] += 0.5 * mWidth;
+    mImpl->mCenterGlobal.mdV[VY] += 0.5 * mWidth;
+    mImpl->mCenterGlobal.mdV[VZ] = 0.5 * mImpl->mLandp->getMinZ() + mImpl->mLandp->getMaxZ();
 }
 
 void LLViewerRegion::calculateCameraDistance()
 {
-	mCameraDistanceSquared = (F32)(gAgentCamera.getCameraPositionGlobal() - getCenterGlobal()).magVecSquared();
+    mCameraDistanceSquared = (F32)(gAgentCamera.getCameraPositionGlobal() - getCenterGlobal()).magVecSquared();
 }
 
 std::ostream& operator<<(std::ostream &s, const LLViewerRegion &region)
 {
-	s << "{ ";
-	s << region.mImpl->mHost;
-	s << " mOriginGlobal = " << region.getOriginGlobal()<< "\n";
+    s << "{ ";
+    s << region.mImpl->mHost;
+    s << " mOriginGlobal = " << region.getOriginGlobal()<< "\n";
     std::string name(region.getName()), zone(region.getZoning());
     if (! name.empty())
     {
@@ -2116,8 +2116,8 @@ std::ostream& operator<<(std::ostream &s, const LLViewerRegion &region)
     {
         s << " mZoning       = " << zone << '\n';
     }
-	s << "}";
-	return s;
+    s << "}";
+    return s;
 }
 
 
@@ -2125,143 +2125,143 @@ std::ostream& operator<<(std::ostream &s, const LLViewerRegion &region)
 
 void LLViewerRegion::updateNetStats()
 {
-	F32 dt = mImpl->mLastNetUpdate.getElapsedTimeAndResetF32();
+    F32 dt = mImpl->mLastNetUpdate.getElapsedTimeAndResetF32();
 
-	LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mImpl->mHost);
-	if (!cdp)
-	{
-		mAlive = false;
-		return;
-	}
+    LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mImpl->mHost);
+    if (!cdp)
+    {
+        mAlive = false;
+        return;
+    }
 
-	mAlive = true;
-	mDeltaTime = dt;
+    mAlive = true;
+    mDeltaTime = dt;
 
-	mLastPacketsIn =	mPacketsIn;
-	mLastBitsIn =		mBitsIn;
-	mLastPacketsOut =	mPacketsOut;
-	mLastPacketsLost =	mPacketsLost;
+    mLastPacketsIn =    mPacketsIn;
+    mLastBitsIn =       mBitsIn;
+    mLastPacketsOut =   mPacketsOut;
+    mLastPacketsLost =  mPacketsLost;
 
-	mPacketsIn =				cdp->getPacketsIn();
-	mBitsIn =					cdp->getBytesIn();
-	mPacketsOut =				cdp->getPacketsOut();
-	mPacketsLost =				cdp->getPacketsLost();
-	mPingDelay =				cdp->getPingDelay();
+    mPacketsIn =                cdp->getPacketsIn();
+    mBitsIn =                   cdp->getBytesIn();
+    mPacketsOut =               cdp->getPacketsOut();
+    mPacketsLost =              cdp->getPacketsLost();
+    mPingDelay =                cdp->getPingDelay();
 
-	mBitsReceived += mBitsIn - mLastBitsIn;
-	mPacketsReceived += mPacketsIn - mLastPacketsIn;
+    mBitsReceived += mBitsIn - mLastBitsIn;
+    mPacketsReceived += mPacketsIn - mLastPacketsIn;
 }
 
 
 U32 LLViewerRegion::getPacketsLost() const
 {
-	LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mImpl->mHost);
-	if (!cdp)
-	{
-		LL_INFOS() << "LLViewerRegion::getPacketsLost couldn't find circuit for " << mImpl->mHost << LL_ENDL;
-		return 0;
-	}
-	else
-	{
-		return cdp->getPacketsLost();
-	}
+    LLCircuitData *cdp = gMessageSystem->mCircuitInfo.findCircuit(mImpl->mHost);
+    if (!cdp)
+    {
+        LL_INFOS() << "LLViewerRegion::getPacketsLost couldn't find circuit for " << mImpl->mHost << LL_ENDL;
+        return 0;
+    }
+    else
+    {
+        return cdp->getPacketsLost();
+    }
 }
 
 S32 LLViewerRegion::getHttpResponderID() const
 {
-	return mImpl->mHttpResponderID;
+    return mImpl->mHttpResponderID;
 }
 
 BOOL LLViewerRegion::pointInRegionGlobal(const LLVector3d &point_global) const
 {
-	LLVector3 pos_region = getPosRegionFromGlobal(point_global);
-
-	if (pos_region.mV[VX] < 0)
-	{
-		return FALSE;
-	}
-	if (pos_region.mV[VX] >= mWidth)
-	{
-		return FALSE;
-	}
-	if (pos_region.mV[VY] < 0)
-	{
-		return FALSE;
-	}
-	if (pos_region.mV[VY] >= mWidth)
-	{
-		return FALSE;
-	}
-	return TRUE;
+    LLVector3 pos_region = getPosRegionFromGlobal(point_global);
+
+    if (pos_region.mV[VX] < 0)
+    {
+        return FALSE;
+    }
+    if (pos_region.mV[VX] >= mWidth)
+    {
+        return FALSE;
+    }
+    if (pos_region.mV[VY] < 0)
+    {
+        return FALSE;
+    }
+    if (pos_region.mV[VY] >= mWidth)
+    {
+        return FALSE;
+    }
+    return TRUE;
 }
 
 LLVector3 LLViewerRegion::getPosRegionFromGlobal(const LLVector3d &point_global) const
 {
-	LLVector3 pos_region;
-	pos_region.setVec(point_global - mImpl->mOriginGlobal);
-	return pos_region;
+    LLVector3 pos_region;
+    pos_region.setVec(point_global - mImpl->mOriginGlobal);
+    return pos_region;
 }
 
 LLVector3d LLViewerRegion::getPosGlobalFromRegion(const LLVector3 &pos_region) const
 {
-	LLVector3d pos_region_d;
-	pos_region_d.setVec(pos_region);
-	return pos_region_d + mImpl->mOriginGlobal;
+    LLVector3d pos_region_d;
+    pos_region_d.setVec(pos_region);
+    return pos_region_d + mImpl->mOriginGlobal;
 }
 
 LLVector3 LLViewerRegion::getPosAgentFromRegion(const LLVector3 &pos_region) const
 {
-	LLVector3d pos_global = getPosGlobalFromRegion(pos_region);
+    LLVector3d pos_global = getPosGlobalFromRegion(pos_region);
 
-	return gAgent.getPosAgentFromGlobal(pos_global);
+    return gAgent.getPosAgentFromGlobal(pos_global);
 }
 
 LLVector3 LLViewerRegion::getPosRegionFromAgent(const LLVector3 &pos_agent) const
 {
-	return pos_agent - getOriginAgent();
+    return pos_agent - getOriginAgent();
 }
 
 F32 LLViewerRegion::getLandHeightRegion(const LLVector3& region_pos)
 {
-	return mImpl->mLandp->resolveHeightRegion( region_pos );
+    return mImpl->mLandp->resolveHeightRegion( region_pos );
 }
 
 bool LLViewerRegion::isAlive()
 {
-	return mAlive;
+    return mAlive;
 }
 
 BOOL LLViewerRegion::isOwnedSelf(const LLVector3& pos) const
 {
-	if (mParcelOverlay)
-	{
-		return mParcelOverlay->isOwnedSelf(pos);
-	} else {
-		return FALSE;
-	}
+    if (mParcelOverlay)
+    {
+        return mParcelOverlay->isOwnedSelf(pos);
+    } else {
+        return FALSE;
+    }
 }
 
 // Owned by a group you belong to?  (officer or member)
 BOOL LLViewerRegion::isOwnedGroup(const LLVector3& pos) const
 {
-	if (mParcelOverlay)
-	{
-		return mParcelOverlay->isOwnedGroup(pos);
-	} else {
-		return FALSE;
-	}
+    if (mParcelOverlay)
+    {
+        return mParcelOverlay->isOwnedGroup(pos);
+    } else {
+        return FALSE;
+    }
 }
 
 // the new TCP coarse location handler node
 class CoarseLocationUpdate final : public LLHTTPNode
 {
 public:
-	void post(
-		ResponsePtr responder,
-		const LLSD& context,
-		const LLSD& input) const override
-	{
-		LLHost host(input["sender"].asString());
+    void post(
+        ResponsePtr responder,
+        const LLSD& context,
+        const LLSD& input) const override
+    {
+        LLHost host(input["sender"].asString());
 
         LLWorld *world_inst = LLWorld::getInstance(); // Not a singleton!
         if (!world_inst)
@@ -2269,106 +2269,106 @@ class CoarseLocationUpdate final : public LLHTTPNode
             return;
         }
 
-		LLViewerRegion* region = world_inst->getRegion(host);
-		if( !region )
-		{
-			return;
-		}
-
-		S32 target_index = input["body"]["Index"][0]["Prey"].asInteger();
-		S32 you_index    = input["body"]["Index"][0]["You" ].asInteger();
-
-		std::vector<U32>* avatar_locs = &region->mMapAvatars;
-		std::vector<LLUUID>* avatar_ids = &region->mMapAvatarIDs;
-		avatar_locs->clear();
-		avatar_ids->clear();
-
-		//LL_INFOS() << "coarse locations agent[0] " << input["body"]["AgentData"][0]["AgentID"].asUUID() << LL_ENDL;
-		//LL_INFOS() << "my agent id = " << gAgent.getID() << LL_ENDL;
-		//LL_INFOS() << ll_pretty_print_sd(input) << LL_ENDL;
-
-		LLSD 
-			locs   = input["body"]["Location"],
-			agents = input["body"]["AgentData"];
-		LLSD::array_iterator 
-			locs_it = locs.beginArray(), 
-			locs_end = locs.endArray(),
-			agents_it = agents.beginArray();
-		BOOL has_agent_data = input["body"].has("AgentData");
-
-		for (int i=0; locs_it != locs_end; i++, ++locs_it)
-		{
-			U8 
-				x = locs_it->get("X").asInteger(),
-				y = locs_it->get("Y").asInteger(),
-				z = locs_it->get("Z").asInteger();
-			// treat the target specially for the map, and don't add you or the target
-			if(i == target_index)
-			{
-				LLVector3d global_pos(region->getOriginGlobal());
-				global_pos.mdV[VX] += (F64)x * region->getWidthScaleFactor();
-				global_pos.mdV[VY] += (F64)y * region->getWidthScaleFactor();
-				global_pos.mdV[VZ] += (F64)z * 4.0;
-				LLAvatarTracker::instance().setTrackedCoarseLocation(global_pos);
-			}
-			else if( i != you_index)
-			{
-				U32 pos = 0x0;
-				pos |= x;
-				pos <<= 8;
-				pos |= y;
-				pos <<= 8;
-				pos |= z;
-				avatar_locs->push_back(pos);
-				//LL_INFOS() << "next pos: " << x << "," << y << "," << z << ": " << pos << LL_ENDL;
-				if(has_agent_data) // for backwards compatibility with old message format
-				{
-					LLUUID agent_id(agents_it->get("AgentID").asUUID());
-					//LL_INFOS() << "next agent: " << agent_id.asString() << LL_ENDL;
-					avatar_ids->push_back(agent_id);
-				}
-			}
-			if (has_agent_data)
-			{
-				++agents_it;
-			}
-		}
-	}
+        LLViewerRegion* region = world_inst->getRegion(host);
+        if( !region )
+        {
+            return;
+        }
+
+        S32 target_index = input["body"]["Index"][0]["Prey"].asInteger();
+        S32 you_index    = input["body"]["Index"][0]["You" ].asInteger();
+
+        std::vector<U32>* avatar_locs = &region->mMapAvatars;
+        std::vector<LLUUID>* avatar_ids = &region->mMapAvatarIDs;
+        avatar_locs->clear();
+        avatar_ids->clear();
+
+        //LL_INFOS() << "coarse locations agent[0] " << input["body"]["AgentData"][0]["AgentID"].asUUID() << LL_ENDL;
+        //LL_INFOS() << "my agent id = " << gAgent.getID() << LL_ENDL;
+        //LL_INFOS() << ll_pretty_print_sd(input) << LL_ENDL;
+
+        LLSD
+            locs   = input["body"]["Location"],
+            agents = input["body"]["AgentData"];
+        LLSD::array_iterator
+            locs_it = locs.beginArray(),
+            locs_end = locs.endArray(),
+            agents_it = agents.beginArray();
+        BOOL has_agent_data = input["body"].has("AgentData");
+
+        for (int i=0; locs_it != locs_end; i++, ++locs_it)
+        {
+            U8
+                x = locs_it->get("X").asInteger(),
+                y = locs_it->get("Y").asInteger(),
+                z = locs_it->get("Z").asInteger();
+            // treat the target specially for the map, and don't add you or the target
+            if(i == target_index)
+            {
+                LLVector3d global_pos(region->getOriginGlobal());
+                global_pos.mdV[VX] += (F64)x * region->getWidthScaleFactor();
+                global_pos.mdV[VY] += (F64)y * region->getWidthScaleFactor();
+                global_pos.mdV[VZ] += (F64)z * 4.0;
+                LLAvatarTracker::instance().setTrackedCoarseLocation(global_pos);
+            }
+            else if( i != you_index)
+            {
+                U32 pos = 0x0;
+                pos |= x;
+                pos <<= 8;
+                pos |= y;
+                pos <<= 8;
+                pos |= z;
+                avatar_locs->push_back(pos);
+                //LL_INFOS() << "next pos: " << x << "," << y << "," << z << ": " << pos << LL_ENDL;
+                if(has_agent_data) // for backwards compatibility with old message format
+                {
+                    LLUUID agent_id(agents_it->get("AgentID").asUUID());
+                    //LL_INFOS() << "next agent: " << agent_id.asString() << LL_ENDL;
+                    avatar_ids->push_back(agent_id);
+                }
+            }
+            if (has_agent_data)
+            {
+                ++agents_it;
+            }
+        }
+    }
 };
 
 // build the coarse location HTTP node under the "/message" URL
 LLHTTPRegistration<CoarseLocationUpdate>
    gHTTPRegistrationCoarseLocationUpdate(
-	   "/message/CoarseLocationUpdate");
+       "/message/CoarseLocationUpdate");
 
 
 void sendRadarAlert(const LLUUID& agent, const std::string& region_str, bool entering)
 {
-	// If we're teleporting, we don't want to see the radar's alerts about EVERY agent leaving.
-	if(gAgent.getTeleportState() != LLAgent::TELEPORT_NONE && !entering)
-	{
-		return;
-	}
-	LLSD args;
-	args["AGENT"] = LLSLURL("agent", agent, "inspect").getSLURLString();
-	args["REGION"] = region_str;
-
-	LLNotification::Params notify_params;
-	notify_params.substitutions = args;
-	if (entering)
-	{
-		notify_params.name = "RadarAlertEnter";
-		notify_params.payload = LLSD().with("respond_on_mousedown", TRUE);
-		notify_params.functor.function = boost::bind(&ALAvatarActions::zoomIn, agent);
-	}
-	else
-	{
-		notify_params.name = "RadarAlertLeave";
-	}
-
-	static LLCachedControl<bool> sLogRadarToChat(gSavedSettings, "AlchemyRadarAlertsToChat", false);
-	notify_params.force_to_chat = sLogRadarToChat;
-	LLNotifications::instance().add(notify_params);
+    // If we're teleporting, we don't want to see the radar's alerts about EVERY agent leaving.
+    if(gAgent.getTeleportState() != LLAgent::TELEPORT_NONE && !entering)
+    {
+        return;
+    }
+    LLSD args;
+    args["AGENT"] = LLSLURL("agent", agent, "inspect").getSLURLString();
+    args["REGION"] = region_str;
+
+    LLNotification::Params notify_params;
+    notify_params.substitutions = args;
+    if (entering)
+    {
+        notify_params.name = "RadarAlertEnter";
+        notify_params.payload = LLSD().with("respond_on_mousedown", TRUE);
+        notify_params.functor.function = boost::bind(&ALAvatarActions::zoomIn, agent);
+    }
+    else
+    {
+        notify_params.name = "RadarAlertLeave";
+    }
+
+    static LLCachedControl<bool> sLogRadarToChat(gSavedSettings, "AlchemyRadarAlertsToChat", false);
+    notify_params.force_to_chat = sLogRadarToChat;
+    LLNotifications::instance().add(notify_params);
 
 }
 
@@ -2377,103 +2377,103 @@ static uuid_vec_t mVecAgents;
 // the deprecated coarse location handler
 void LLViewerRegion::updateCoarseLocations(LLMessageSystem* msg)
 {
-	//LL_INFOS() << "CoarseLocationUpdate" << LL_ENDL;
-	mMapAvatars.clear();
-	mMapAvatarIDs.clear(); // only matters in a rare case but it's good to be safe.
-	
-	static LLCachedControl<bool> sRadarAlerts(gSavedSettings, "AlchemyRadarAlerts", false);
-	LLViewerRegion* cur_region = gAgent.getRegion();
-	uuid_vec_t region_agents;
-
-	U8 x_pos = 0;
-	U8 y_pos = 0;
-	U8 z_pos = 0;
-
-	U32 pos = 0x0;
-
-	S16 agent_index;
-	S16 target_index;
-	msg->getS16Fast(_PREHASH_Index, _PREHASH_You, agent_index);
-	msg->getS16Fast(_PREHASH_Index, _PREHASH_Prey, target_index);
-
-	BOOL has_agent_data = msg->hasFast(_PREHASH_AgentData);
-	S32 count = msg->getNumberOfBlocksFast(_PREHASH_Location);
-	for(S32 i = 0; i < count; i++)
-	{
-		msg->getU8Fast(_PREHASH_Location, _PREHASH_X, x_pos, i);
-		msg->getU8Fast(_PREHASH_Location, _PREHASH_Y, y_pos, i);
-		msg->getU8Fast(_PREHASH_Location, _PREHASH_Z, z_pos, i);
-		LLUUID agent_id = LLUUID::null;
-		if(has_agent_data)
-		{
-			msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id, i);
-		}
-
-		//LL_INFOS() << "  object X: " << (S32)x_pos << " Y: " << (S32)y_pos
-		//		<< " Z: " << (S32)(z_pos * 4)
-		//		<< LL_ENDL;
-
-		// treat the target specially for the map
-		if(i == target_index)
-		{
-			LLVector3d global_pos(mImpl->mOriginGlobal);
-			global_pos.mdV[VX] += (F64)(x_pos) * mWidthScaleFactor;
-			global_pos.mdV[VY] += (F64)(y_pos) * mWidthScaleFactor;
-			global_pos.mdV[VZ] += (F64)(z_pos) * 4.0;
-			LLAvatarTracker::instance().setTrackedCoarseLocation(global_pos);
-		}
-		
-		//don't add you
-		if( i != agent_index)
-		{
-			pos = 0x0;
-			pos |= x_pos;
-			pos <<= 8;
-			pos |= y_pos;
-			pos <<= 8;
-			pos |= z_pos;
-			mMapAvatars.push_back(pos);
-			if(has_agent_data)
-			{
-				mMapAvatarIDs.push_back(agent_id);
-				
-				if (this == cur_region)
-				{
-					region_agents.push_back(agent_id);
-					uuid_vec_t::iterator end = mVecAgents.end();
-					if (find(mVecAgents.begin(), end, agent_id) == end)
-					{
-						if (sRadarAlerts)
-							sendRadarAlert(agent_id, this->getName(), true);
-					}
-				}
-			}
-		}
-	}
-	if (this == cur_region)
-	{
-		for (const LLUUID& agent: mVecAgents)
-		{
-			uuid_vec_t::iterator end = region_agents.end();
-			if (find(region_agents.begin(), end, agent) == end)
-			{
-				if (sRadarAlerts)
-					sendRadarAlert(agent, this->getName(), false);
-			}
-		}
-		mVecAgents.clear();
-		mVecAgents = region_agents;
-	}
+    //LL_INFOS() << "CoarseLocationUpdate" << LL_ENDL;
+    mMapAvatars.clear();
+    mMapAvatarIDs.clear(); // only matters in a rare case but it's good to be safe.
+
+    static LLCachedControl<bool> sRadarAlerts(gSavedSettings, "AlchemyRadarAlerts", false);
+    LLViewerRegion* cur_region = gAgent.getRegion();
+    uuid_vec_t region_agents;
+
+    U8 x_pos = 0;
+    U8 y_pos = 0;
+    U8 z_pos = 0;
+
+    U32 pos = 0x0;
+
+    S16 agent_index;
+    S16 target_index;
+    msg->getS16Fast(_PREHASH_Index, _PREHASH_You, agent_index);
+    msg->getS16Fast(_PREHASH_Index, _PREHASH_Prey, target_index);
+
+    BOOL has_agent_data = msg->hasFast(_PREHASH_AgentData);
+    S32 count = msg->getNumberOfBlocksFast(_PREHASH_Location);
+    for(S32 i = 0; i < count; i++)
+    {
+        msg->getU8Fast(_PREHASH_Location, _PREHASH_X, x_pos, i);
+        msg->getU8Fast(_PREHASH_Location, _PREHASH_Y, y_pos, i);
+        msg->getU8Fast(_PREHASH_Location, _PREHASH_Z, z_pos, i);
+        LLUUID agent_id = LLUUID::null;
+        if(has_agent_data)
+        {
+            msg->getUUIDFast(_PREHASH_AgentData, _PREHASH_AgentID, agent_id, i);
+        }
+
+        //LL_INFOS() << "  object X: " << (S32)x_pos << " Y: " << (S32)y_pos
+        //      << " Z: " << (S32)(z_pos * 4)
+        //      << LL_ENDL;
+
+        // treat the target specially for the map
+        if(i == target_index)
+        {
+            LLVector3d global_pos(mImpl->mOriginGlobal);
+            global_pos.mdV[VX] += (F64)(x_pos) * mWidthScaleFactor;
+            global_pos.mdV[VY] += (F64)(y_pos) * mWidthScaleFactor;
+            global_pos.mdV[VZ] += (F64)(z_pos) * 4.0;
+            LLAvatarTracker::instance().setTrackedCoarseLocation(global_pos);
+        }
+
+        //don't add you
+        if( i != agent_index)
+        {
+            pos = 0x0;
+            pos |= x_pos;
+            pos <<= 8;
+            pos |= y_pos;
+            pos <<= 8;
+            pos |= z_pos;
+            mMapAvatars.push_back(pos);
+            if(has_agent_data)
+            {
+                mMapAvatarIDs.push_back(agent_id);
+
+                if (this == cur_region)
+                {
+                    region_agents.push_back(agent_id);
+                    uuid_vec_t::iterator end = mVecAgents.end();
+                    if (find(mVecAgents.begin(), end, agent_id) == end)
+                    {
+                        if (sRadarAlerts)
+                            sendRadarAlert(agent_id, this->getName(), true);
+                    }
+                }
+            }
+        }
+    }
+    if (this == cur_region)
+    {
+        for (const LLUUID& agent: mVecAgents)
+        {
+            uuid_vec_t::iterator end = region_agents.end();
+            if (find(region_agents.begin(), end, agent) == end)
+            {
+                if (sRadarAlerts)
+                    sendRadarAlert(agent, this->getName(), false);
+            }
+        }
+        mVecAgents.clear();
+        mVecAgents = region_agents;
+    }
 }
 
 void LLViewerRegion::getInfo(LLSD& info)
 {
-	info["Region"]["Host"] = getHost().getIPandPort();
-	info["Region"]["Name"] = getName();
-	U32 x, y;
-	from_region_handle(getHandle(), &x, &y);
-	info["Region"]["Handle"]["x"] = (LLSD::Integer)x;
-	info["Region"]["Handle"]["y"] = (LLSD::Integer)y;
+    info["Region"]["Host"] = getHost().getIPandPort();
+    info["Region"]["Name"] = getName();
+    U32 x, y;
+    from_region_handle(getHandle(), &x, &y);
+    info["Region"]["Handle"]["x"] = (LLSD::Integer)x;
+    info["Region"]["Handle"]["y"] = (LLSD::Integer)y;
 }
 
 void LLViewerRegion::requestSimulatorFeatures()
@@ -2492,7 +2492,7 @@ void LLViewerRegion::requestSimulatorFeatures()
         // launch() acts like a suspend()
         // Make sure we are still good to do
         LLCoros::checkStop();
-        
+
         LL_INFOS("AppInit", "SimulatorFeatures") << "Launching " << coroname << " requesting simulator features from " << url << " for region " << getRegionID() << LL_ENDL;
     }
     else
@@ -2503,141 +2503,141 @@ void LLViewerRegion::requestSimulatorFeatures()
 
 boost::signals2::connection LLViewerRegion::setSimulatorFeaturesReceivedCallback(const caps_received_signal_t::slot_type& cb)
 {
-	return mSimulatorFeaturesReceivedSignal.connect(cb);
+    return mSimulatorFeaturesReceivedSignal.connect(cb);
 }
 
 void LLViewerRegion::setSimulatorFeaturesReceived(bool received)
 {
-	mSimulatorFeaturesReceived = received;
-	if (received)
-	{
-		mSimulatorFeaturesReceivedSignal(getRegionID(), this);
-		mSimulatorFeaturesReceivedSignal.disconnect_all_slots();
-	}
+    mSimulatorFeaturesReceived = received;
+    if (received)
+    {
+        mSimulatorFeaturesReceivedSignal(getRegionID(), this);
+        mSimulatorFeaturesReceivedSignal.disconnect_all_slots();
+    }
 }
 
 bool LLViewerRegion::simulatorFeaturesReceived() const
 {
-	return mSimulatorFeaturesReceived;
+    return mSimulatorFeaturesReceived;
 }
 
 void LLViewerRegion::getSimulatorFeatures(LLSD& sim_features) const
 {
-	sim_features = mSimulatorFeatures;
+    sim_features = mSimulatorFeatures;
 
 }
 
 void LLViewerRegion::setSimulatorFeatures(const LLSD& sim_features)
 {
-	LL_INFOS() << "region " << getName() << " "  << ll_pretty_print_sd(sim_features) << LL_ENDL;
-	mSimulatorFeatures = sim_features;
+    LL_INFOS() << "region " << getName() << " "  << ll_pretty_print_sd(sim_features) << LL_ENDL;
+    mSimulatorFeatures = sim_features;
 #ifndef LL_HAVOK
-	if (LLGridManager::getInstance()->isInOpenSim())
-	{
-		setGodnames();
-		if (mSimulatorFeatures.has("OpenSimExtras"))
-		{
-			const LLSD& extras(mSimulatorFeatures["OpenSimExtras"]);
-
-			if (extras.has("GridURL"))
-			{
-				mHGGridURL = extras["GridURL"].asString();
-				if (LLGridManager::getInstance()->getGrid(LLURI(mHGGridURL).authority()).empty())
-					LLGridManager::getInstance()->addRemoteGrid(mHGGridURL, LLGridManager::ADD_HYPERGRID);
-			}
-
-			if (extras.has("GridName"))
-			{
-				mHGGridName = extras["GridName"].asString();
-			}
-
-			if (extras.has("GridNick"))
-			{
-				mHGGridNick = extras["GridNick"].asString();
-			}
-
-			if (extras.has("map-server-url"))
-			{
-				mHGMapServerURL = extras["map-server-url"].asString();
-			}
-
-			if (extras.has("whisper-range"))
-			{
-				mWhisperRange = extras["whisper-range"].asInteger();
-			}
-			if (extras.has("say-range"))
-			{
-				mSayRange = extras["say-range"].asInteger();
-			}
-			if (extras.has("shout-range"))
-			{
-				mShoutRange = extras["shout-range"].asInteger();
-			}
-
-			mMinSimHeight = extras.has("MinSimHeight") ? extras["MinSimHeight"].asReal() : OS_MIN_OBJECT_Z;
-			mMaxSimHeight = extras.has("MaxSimHeight") ? extras["MaxSimHeight"].asReal() : OS_MAX_OBJECT_Z;
-			mMinPrimScale = extras.has("MinPrimScale") ? extras["MinPrimScale"].asReal() : OS_MIN_PRIM_SCALE;
-			mMaxPrimScale = extras.has("MaxPrimScale") ? extras["MaxPrimScale"].asReal() : OS_DEFAULT_MAX_PRIM_SCALE;
-			mMaxPrimScaleNoMesh = extras.has("MaxPrimScale") ? extras["MaxPrimScale"].asReal() : OS_DEFAULT_MAX_PRIM_SCALE;
-			mMinPhysPrimScale = extras.has("MinPhysPrimScale") ? extras["MinPhysPrimScale"].asReal() : OS_MIN_PRIM_SCALE;
-			mMaxPhysPrimScale = extras.has("MaxPhysPrimScale") ? extras["MaxPhysPrimScale"].asReal() : OS_DEFAULT_MAX_PRIM_SCALE;
-		}
-		else
-		{
-			mWhisperRange = 10;
-			mSayRange = 20;
-			mShoutRange = 100;
-			mMinSimHeight = OS_MIN_OBJECT_Z;
-			mMaxSimHeight = OS_MAX_OBJECT_Z;
-			mMinPrimScale = OS_MIN_PRIM_SCALE;
-			mMaxPrimScale = OS_DEFAULT_MAX_PRIM_SCALE;
-			mMaxPrimScaleNoMesh = OS_DEFAULT_MAX_PRIM_SCALE;
-			mMinPhysPrimScale = OS_MIN_PRIM_SCALE;
-			mMaxPhysPrimScale = OS_DEFAULT_MAX_PRIM_SCALE;
-		}
-	}
-	else
+    if (LLGridManager::getInstance()->isInOpenSim())
+    {
+        setGodnames();
+        if (mSimulatorFeatures.has("OpenSimExtras"))
+        {
+            const LLSD& extras(mSimulatorFeatures["OpenSimExtras"]);
+
+            if (extras.has("GridURL"))
+            {
+                mHGGridURL = extras["GridURL"].asString();
+                if (LLGridManager::getInstance()->getGrid(LLURI(mHGGridURL).authority()).empty())
+                    LLGridManager::getInstance()->addRemoteGrid(mHGGridURL, LLGridManager::ADD_HYPERGRID);
+            }
+
+            if (extras.has("GridName"))
+            {
+                mHGGridName = extras["GridName"].asString();
+            }
+
+            if (extras.has("GridNick"))
+            {
+                mHGGridNick = extras["GridNick"].asString();
+            }
+
+            if (extras.has("map-server-url"))
+            {
+                mHGMapServerURL = extras["map-server-url"].asString();
+            }
+
+            if (extras.has("whisper-range"))
+            {
+                mWhisperRange = extras["whisper-range"].asInteger();
+            }
+            if (extras.has("say-range"))
+            {
+                mSayRange = extras["say-range"].asInteger();
+            }
+            if (extras.has("shout-range"))
+            {
+                mShoutRange = extras["shout-range"].asInteger();
+            }
+
+            mMinSimHeight = extras.has("MinSimHeight") ? extras["MinSimHeight"].asReal() : OS_MIN_OBJECT_Z;
+            mMaxSimHeight = extras.has("MaxSimHeight") ? extras["MaxSimHeight"].asReal() : OS_MAX_OBJECT_Z;
+            mMinPrimScale = extras.has("MinPrimScale") ? extras["MinPrimScale"].asReal() : OS_MIN_PRIM_SCALE;
+            mMaxPrimScale = extras.has("MaxPrimScale") ? extras["MaxPrimScale"].asReal() : OS_DEFAULT_MAX_PRIM_SCALE;
+            mMaxPrimScaleNoMesh = extras.has("MaxPrimScale") ? extras["MaxPrimScale"].asReal() : OS_DEFAULT_MAX_PRIM_SCALE;
+            mMinPhysPrimScale = extras.has("MinPhysPrimScale") ? extras["MinPhysPrimScale"].asReal() : OS_MIN_PRIM_SCALE;
+            mMaxPhysPrimScale = extras.has("MaxPhysPrimScale") ? extras["MaxPhysPrimScale"].asReal() : OS_DEFAULT_MAX_PRIM_SCALE;
+        }
+        else
+        {
+            mWhisperRange = 10;
+            mSayRange = 20;
+            mShoutRange = 100;
+            mMinSimHeight = OS_MIN_OBJECT_Z;
+            mMaxSimHeight = OS_MAX_OBJECT_Z;
+            mMinPrimScale = OS_MIN_PRIM_SCALE;
+            mMaxPrimScale = OS_DEFAULT_MAX_PRIM_SCALE;
+            mMaxPrimScaleNoMesh = OS_DEFAULT_MAX_PRIM_SCALE;
+            mMinPhysPrimScale = OS_MIN_PRIM_SCALE;
+            mMaxPhysPrimScale = OS_DEFAULT_MAX_PRIM_SCALE;
+        }
+    }
+    else
 #endif
-	{
-		mMinSimHeight = SL_MIN_OBJECT_Z;
-		mMaxSimHeight = SL_MAX_OBJECT_Z;
-		mMinPrimScale = SL_MIN_PRIM_SCALE;
-		mMaxPrimScale = SL_DEFAULT_MAX_PRIM_SCALE;
-		mMaxPrimScaleNoMesh = SL_DEFAULT_MAX_PRIM_SCALE_NO_MESH;
-		mMinPhysPrimScale = SL_MIN_PRIM_SCALE;
-		mMaxPhysPrimScale = SL_DEFAULT_MAX_PRIM_SCALE;
-		mWhisperRange = 10;
-		mSayRange = 20;
-		mShoutRange = 100;
-	}
-
-	if(mSimulatorFeatures.has("MaxMaterialsPerTransaction")
-		&& mSimulatorFeatures["MaxMaterialsPerTransaction"].isInteger())
-	{
-		mMaxMaterialsPerTrans = mSimulatorFeatures["MaxMaterialsPerTransaction"].asInteger();
-	}
-
-	mMeshUploadEnabled = (mSimulatorFeatures.has("MeshUploadEnabled") &&
-		mSimulatorFeatures["MeshUploadEnabled"].asBoolean());
-
-	mBakesOnMeshEnabled = (mSimulatorFeatures.has("BakesOnMeshEnabled") &&
-		mSimulatorFeatures["BakesOnMeshEnabled"].asBoolean());
-
-	mMeshRezEnabled = (mSimulatorFeatures.has("MeshRezEnabled") &&
-		mSimulatorFeatures["MeshRezEnabled"].asBoolean());
-
-	mDynamicPathfindingEnabled = (mSimulatorFeatures.has("DynamicPathfindingEnabled") &&
-		mSimulatorFeatures["DynamicPathfindingEnabled"].asBoolean());
-
-	mAvatarHoverHeightEnabled = (mSimulatorFeatures.has("AvatarHoverHeightEnabled") &&
-		mSimulatorFeatures["AvatarHoverHeightEnabled"].asBoolean());
-
-	setSimulatorFeaturesReceived(true);
-
-    // WARNING: this is called from a coroutine, and flipping saved settings has a LOT of side effects, shuttle 
+    {
+        mMinSimHeight = SL_MIN_OBJECT_Z;
+        mMaxSimHeight = SL_MAX_OBJECT_Z;
+        mMinPrimScale = SL_MIN_PRIM_SCALE;
+        mMaxPrimScale = SL_DEFAULT_MAX_PRIM_SCALE;
+        mMaxPrimScaleNoMesh = SL_DEFAULT_MAX_PRIM_SCALE_NO_MESH;
+        mMinPhysPrimScale = SL_MIN_PRIM_SCALE;
+        mMaxPhysPrimScale = SL_DEFAULT_MAX_PRIM_SCALE;
+        mWhisperRange = 10;
+        mSayRange = 20;
+        mShoutRange = 100;
+    }
+
+    if(mSimulatorFeatures.has("MaxMaterialsPerTransaction")
+        && mSimulatorFeatures["MaxMaterialsPerTransaction"].isInteger())
+    {
+        mMaxMaterialsPerTrans = mSimulatorFeatures["MaxMaterialsPerTransaction"].asInteger();
+    }
+
+    mMeshUploadEnabled = (mSimulatorFeatures.has("MeshUploadEnabled") &&
+        mSimulatorFeatures["MeshUploadEnabled"].asBoolean());
+
+    mBakesOnMeshEnabled = (mSimulatorFeatures.has("BakesOnMeshEnabled") &&
+        mSimulatorFeatures["BakesOnMeshEnabled"].asBoolean());
+
+    mMeshRezEnabled = (mSimulatorFeatures.has("MeshRezEnabled") &&
+        mSimulatorFeatures["MeshRezEnabled"].asBoolean());
+
+    mDynamicPathfindingEnabled = (mSimulatorFeatures.has("DynamicPathfindingEnabled") &&
+        mSimulatorFeatures["DynamicPathfindingEnabled"].asBoolean());
+
+    mAvatarHoverHeightEnabled = (mSimulatorFeatures.has("AvatarHoverHeightEnabled") &&
+        mSimulatorFeatures["AvatarHoverHeightEnabled"].asBoolean());
+
+    setSimulatorFeaturesReceived(true);
+
+    // WARNING: this is called from a coroutine, and flipping saved settings has a LOT of side effects, shuttle
     // the work below back to the main loop
-    // 
-    
+    //
+
     // copy features to lambda in case the region is deleted before the lambda is executed
     LLSD features = mSimulatorFeatures;
 
@@ -2688,267 +2688,267 @@ void LLViewerRegion::setSimulatorFeatures(const LLSD& sim_features)
 //move all orphan children out of cache and insert to rendering octree.
 void LLViewerRegion::findOrphans(U32 parent_id)
 {
-	orphan_list_t::iterator iter = mOrphanMap.find(parent_id);
-	if(iter != mOrphanMap.end())
-	{
-		std::vector<U32>* children = &mOrphanMap[parent_id];
-		for(S32 i = 0; i < children->size(); i++)
-		{
-			//parent is visible, so is the child.
-			addVisibleChildCacheEntry(NULL, getCacheEntry((*children)[i]));
-		}
-		children->clear();
-		mOrphanMap.erase(parent_id);
-	}
+    orphan_list_t::iterator iter = mOrphanMap.find(parent_id);
+    if(iter != mOrphanMap.end())
+    {
+        std::vector<U32>* children = &mOrphanMap[parent_id];
+        for(S32 i = 0; i < children->size(); i++)
+        {
+            //parent is visible, so is the child.
+            addVisibleChildCacheEntry(NULL, getCacheEntry((*children)[i]));
+        }
+        children->clear();
+        mOrphanMap.erase(parent_id);
+    }
 }
 
 void LLViewerRegion::decodeBoundingInfo(LLVOCacheEntry* entry)
 {
-	if(!sVOCacheCullingEnabled)
-	{
-		gObjectList.processObjectUpdateFromCache(entry, this);
-		return;
-	}
-	if(!entry || !entry->isValid())
-	{
-		return;
-	}
-
-	if(!entry->getEntry())
-	{
-		entry->setOctreeEntry(NULL);
-	}
-		
-	if(entry->getEntry()->hasDrawable()) //already in the rendering pipeline
-	{
-		LLViewerRegion* old_regionp = ((LLDrawable*)entry->getEntry()->getDrawable())->getRegion();
-		if(old_regionp != this && old_regionp)
+    if(!sVOCacheCullingEnabled)
+    {
+        gObjectList.processObjectUpdateFromCache(entry, this);
+        return;
+    }
+    if(!entry || !entry->isValid())
+    {
+        return;
+    }
+
+    if(!entry->getEntry())
+    {
+        entry->setOctreeEntry(NULL);
+    }
+
+    if(entry->getEntry()->hasDrawable()) //already in the rendering pipeline
+    {
+        LLViewerRegion* old_regionp = ((LLDrawable*)entry->getEntry()->getDrawable())->getRegion();
+        if(old_regionp != this && old_regionp)
         {
-			LLViewerObject* obj = ((LLDrawable*)entry->getEntry()->getDrawable())->getVObj();
-			if(obj)
-			{
-				//remove from old region
-				old_regionp->killCacheEntry(obj->getLocalID());
+            LLViewerObject* obj = ((LLDrawable*)entry->getEntry()->getDrawable())->getVObj();
+            if(obj)
+            {
+                //remove from old region
+                old_regionp->killCacheEntry(obj->getLocalID());
 
-				//change region
-				obj->setRegion(this);
-			}
-		}
+                //change region
+                obj->setRegion(this);
+            }
+        }
 
-		addActiveCacheEntry(entry);
+        addActiveCacheEntry(entry);
 
-		//set parent id
-		U32	parent_id = 0;
+        //set parent id
+        U32 parent_id = 0;
         if (entry->getDP()) // NULL if nothing cached
         {
             LLViewerObject::unpackParentID(entry->getDP(), parent_id);
         }
-		if(parent_id != entry->getParentID())
-		{				
-			entry->setParentID(parent_id);
-		}
-
-		//update the object
-		gObjectList.processObjectUpdateFromCache(entry, this);
-		return; //done
-	}
-	
-	//must not be active.
-	llassert_always(!entry->isState(LLVOCacheEntry::ACTIVE));
-	removeFromVOCacheTree(entry); //remove from cache octree if it is in.
-
-	LLVector3 pos;
-	LLVector3 scale;
-	LLQuaternion rot;
-
-	//decode spatial info and parent info
-	U32 parent_id = entry->getDP() ? LLViewerObject::extractSpatialExtents(entry->getDP(), pos, scale, rot) : entry->getParentID();
-	
-	U32 old_parent_id = entry->getParentID();
-	bool same_old_parent = false;
-	if(parent_id != old_parent_id) //parent changed.
-	{
-		if(old_parent_id > 0) //has an old parent, disconnect it
-		{
-			LLVOCacheEntry* old_parent = getCacheEntry(old_parent_id);
-			if(old_parent)
-			{
-				old_parent->removeChild(entry);
-				if(!old_parent->isState(LLVOCacheEntry::INACTIVE))
-				{
-					mImpl->mVisibleEntries.erase(entry);
-					entry->setState(LLVOCacheEntry::INACTIVE);
-				}
-			}
-		}
-		entry->setParentID(parent_id);
-	}
-	else
-	{
-		same_old_parent = true;
-	}
-
-	if(parent_id > 0) //has a new parent
-	{	
-		//1, find the parent in cache
-		LLVOCacheEntry* parent = getCacheEntry(parent_id);
-		
-		//2, parent is not in the cache, put into the orphan list.
-		if(!parent)
-		{
-			if(!same_old_parent)
-			{
-				//check if parent is non-cacheable and already created
-				if(isNonCacheableObjectCreated(parent_id))
-				{
-					//parent is visible, so is the child.
-					addVisibleChildCacheEntry(NULL, entry);
-				}
-				else
-				{
-					entry->setBoundingInfo(pos, scale);
-					mOrphanMap[parent_id].push_back(entry->getLocalID());
-				}
-			}
-			else
-			{
-				entry->setBoundingInfo(pos, scale);
-			}
-		}
-		else //parent in cache.
-		{
-			if(!parent->isState(LLVOCacheEntry::INACTIVE)) 
-			{
-				//parent is visible, so is the child.
-				addVisibleChildCacheEntry(parent, entry);
-			}
-			else
-			{
-				entry->setBoundingInfo(pos, scale);
-				parent->addChild(entry);
-
-				if(parent->getGroup()) //re-insert parent to vo-cache tree because its bounding info changed.
-				{
-					removeFromVOCacheTree(parent);
-					addToVOCacheTree(parent);
-				}
-			}
-		}
-
-		return;
-	}
-	
-	//
-	//no parent
-	//
-	entry->setBoundingInfo(pos, scale);	
-
-	if(!parent_id) //a potential parent
-	{
-		//find all children and update their bounding info
-		orphan_list_t::iterator iter = mOrphanMap.find(entry->getLocalID());
-		if(iter != mOrphanMap.end())
-		{			
-			std::vector<U32>* orphans = &mOrphanMap[entry->getLocalID()];
-			S32 size = orphans->size();
-			for(S32 i = 0; i < size; i++)
-			{
-				LLVOCacheEntry* child = getCacheEntry((*orphans)[i]);
-				if(child)
-				{
-					entry->addChild(child);
-				}
-			}
-			orphans->clear();
-			mOrphanMap.erase(entry->getLocalID());
-		}
-	}
-	
-	if(!entry->getGroup() && entry->isState(LLVOCacheEntry::INACTIVE))
-	{
-		addToVOCacheTree(entry);
-	}
-	return ;
+        if(parent_id != entry->getParentID())
+        {
+            entry->setParentID(parent_id);
+        }
+
+        //update the object
+        gObjectList.processObjectUpdateFromCache(entry, this);
+        return; //done
+    }
+
+    //must not be active.
+    llassert_always(!entry->isState(LLVOCacheEntry::ACTIVE));
+    removeFromVOCacheTree(entry); //remove from cache octree if it is in.
+
+    LLVector3 pos;
+    LLVector3 scale;
+    LLQuaternion rot;
+
+    //decode spatial info and parent info
+    U32 parent_id = entry->getDP() ? LLViewerObject::extractSpatialExtents(entry->getDP(), pos, scale, rot) : entry->getParentID();
+
+    U32 old_parent_id = entry->getParentID();
+    bool same_old_parent = false;
+    if(parent_id != old_parent_id) //parent changed.
+    {
+        if(old_parent_id > 0) //has an old parent, disconnect it
+        {
+            LLVOCacheEntry* old_parent = getCacheEntry(old_parent_id);
+            if(old_parent)
+            {
+                old_parent->removeChild(entry);
+                if(!old_parent->isState(LLVOCacheEntry::INACTIVE))
+                {
+                    mImpl->mVisibleEntries.erase(entry);
+                    entry->setState(LLVOCacheEntry::INACTIVE);
+                }
+            }
+        }
+        entry->setParentID(parent_id);
+    }
+    else
+    {
+        same_old_parent = true;
+    }
+
+    if(parent_id > 0) //has a new parent
+    {
+        //1, find the parent in cache
+        LLVOCacheEntry* parent = getCacheEntry(parent_id);
+
+        //2, parent is not in the cache, put into the orphan list.
+        if(!parent)
+        {
+            if(!same_old_parent)
+            {
+                //check if parent is non-cacheable and already created
+                if(isNonCacheableObjectCreated(parent_id))
+                {
+                    //parent is visible, so is the child.
+                    addVisibleChildCacheEntry(NULL, entry);
+                }
+                else
+                {
+                    entry->setBoundingInfo(pos, scale);
+                    mOrphanMap[parent_id].push_back(entry->getLocalID());
+                }
+            }
+            else
+            {
+                entry->setBoundingInfo(pos, scale);
+            }
+        }
+        else //parent in cache.
+        {
+            if(!parent->isState(LLVOCacheEntry::INACTIVE))
+            {
+                //parent is visible, so is the child.
+                addVisibleChildCacheEntry(parent, entry);
+            }
+            else
+            {
+                entry->setBoundingInfo(pos, scale);
+                parent->addChild(entry);
+
+                if(parent->getGroup()) //re-insert parent to vo-cache tree because its bounding info changed.
+                {
+                    removeFromVOCacheTree(parent);
+                    addToVOCacheTree(parent);
+                }
+            }
+        }
+
+        return;
+    }
+
+    //
+    //no parent
+    //
+    entry->setBoundingInfo(pos, scale);
+
+    if(!parent_id) //a potential parent
+    {
+        //find all children and update their bounding info
+        orphan_list_t::iterator iter = mOrphanMap.find(entry->getLocalID());
+        if(iter != mOrphanMap.end())
+        {
+            std::vector<U32>* orphans = &mOrphanMap[entry->getLocalID()];
+            S32 size = orphans->size();
+            for(S32 i = 0; i < size; i++)
+            {
+                LLVOCacheEntry* child = getCacheEntry((*orphans)[i]);
+                if(child)
+                {
+                    entry->addChild(child);
+                }
+            }
+            orphans->clear();
+            mOrphanMap.erase(entry->getLocalID());
+        }
+    }
+
+    if(!entry->getGroup() && entry->isState(LLVOCacheEntry::INACTIVE))
+    {
+        addToVOCacheTree(entry);
+    }
+    return ;
 }
 
 LLViewerRegion::eCacheUpdateResult LLViewerRegion::cacheFullUpdate(LLDataPackerBinaryBuffer &dp, U32 flags)
 {
-	eCacheUpdateResult result;
-	U32 crc;
-	U32 local_id;
+    eCacheUpdateResult result;
+    U32 crc;
+    U32 local_id;
 
-	LLViewerObject::unpackU32(&dp, local_id, "LocalID");
-	LLViewerObject::unpackU32(&dp, crc, "CRC");
+    LLViewerObject::unpackU32(&dp, local_id, "LocalID");
+    LLViewerObject::unpackU32(&dp, crc, "CRC");
 
-	LLVOCacheEntry* entry = getCacheEntry(local_id, false);
+    LLVOCacheEntry* entry = getCacheEntry(local_id, false);
 
-	if (entry)
-	{
+    if (entry)
+    {
 // [SL:KB] - Patch: World-Derender | Checked: 2014-08-10 (Catznip-3.7)
-		// If the entry isn't currently valid then we shouldn't just assume everything's in perfect working order
-		bool fUpdateObj = (!entry->isValid()) || (entry->getCRC() != crc);
+        // If the entry isn't currently valid then we shouldn't just assume everything's in perfect working order
+        bool fUpdateObj = (!entry->isValid()) || (entry->getCRC() != crc);
 // [/SL:KB]
-		entry->setValid();
+        entry->setValid();
 
-		// we've seen this object before
-		if (entry->getCRC() == crc)
-		{
+        // we've seen this object before
+        if (entry->getCRC() == crc)
+        {
 #ifdef SHOW_DEBUG
             LL_DEBUGS("AnimatedObjects") << " got dupe for local_id " << local_id << LL_ENDL;
             dumpStack("AnimatedObjectsStack");
 #endif
 
-			// Record a hit
-			entry->recordDupe();
-			result = CACHE_UPDATE_DUPE;
-		}
-		else //CRC changed
-		{
+            // Record a hit
+            entry->recordDupe();
+            result = CACHE_UPDATE_DUPE;
+        }
+        else //CRC changed
+        {
 #ifdef SHOW_DEBUG
             LL_DEBUGS("AnimatedObjects") << " got update for local_id " << local_id << LL_ENDL;
             dumpStack("AnimatedObjectsStack");
 #endif
 
-			// Update the cache entry 
-			entry->updateEntry(crc, dp);
+            // Update the cache entry
+            entry->updateEntry(crc, dp);
 
-//			decodeBoundingInfo(entry);
+//          decodeBoundingInfo(entry);
 
-			result = CACHE_UPDATE_CHANGED;
-		}		
+            result = CACHE_UPDATE_CHANGED;
+        }
 
 // [SL:KB] - Patch: World-Derender | Checked: 2014-08-10 (Catznip-3.7)
-		if (fUpdateObj)
-			decodeBoundingInfo(entry);
+        if (fUpdateObj)
+            decodeBoundingInfo(entry);
 // [/SL:KB]
-	}
-	else
-	{
+    }
+    else
+    {
 #ifdef SHOW_DEBUG
         LL_DEBUGS("AnimatedObjects") << " got first notification for local_id " << local_id << LL_ENDL;
         dumpStack("AnimatedObjectsStack");
 #endif
 
-		// we haven't seen this object before
-		// Create new entry and add to map
-		result = CACHE_UPDATE_ADDED;
-		entry = new LLVOCacheEntry(local_id, crc, dp);
-		record(LLStatViewer::OBJECT_CACHE_HIT_RATE, LLUnits::Ratio::fromValue(0)); 
-		
-		mImpl->mCacheMap[local_id] = entry;
-		
-		decodeBoundingInfo(entry);
-	}
-	entry->setUpdateFlags(flags);
-
-	return result;
-	}
+        // we haven't seen this object before
+        // Create new entry and add to map
+        result = CACHE_UPDATE_ADDED;
+        entry = new LLVOCacheEntry(local_id, crc, dp);
+        record(LLStatViewer::OBJECT_CACHE_HIT_RATE, LLUnits::Ratio::fromValue(0));
+
+        mImpl->mCacheMap[local_id] = entry;
+
+        decodeBoundingInfo(entry);
+    }
+    entry->setUpdateFlags(flags);
+
+    return result;
+    }
 
 LLViewerRegion::eCacheUpdateResult LLViewerRegion::cacheFullUpdate(LLViewerObject* objectp, LLDataPackerBinaryBuffer &dp, U32 flags)
 {
-	eCacheUpdateResult result = cacheFullUpdate(dp, flags);
+    eCacheUpdateResult result = cacheFullUpdate(dp, flags);
 
-	return result;
+    return result;
 }
 
 void LLViewerRegion::cacheFullUpdateGLTFOverride(const LLGLTFOverrideCacheEntry &override_data)
@@ -2966,218 +2966,218 @@ void LLViewerRegion::cacheFullUpdateGLTFOverride(const LLGLTFOverrideCacheEntry
 
 LLVOCacheEntry* LLViewerRegion::getCacheEntryForOctree(U32 local_id)
 {
-	if(!sVOCacheCullingEnabled)
-	{
-		return NULL;
-	}
+    if(!sVOCacheCullingEnabled)
+    {
+        return NULL;
+    }
+
+    LLVOCacheEntry* entry = getCacheEntry(local_id);
+    removeFromVOCacheTree(entry);
 
-	LLVOCacheEntry* entry = getCacheEntry(local_id);
-	removeFromVOCacheTree(entry);
-		
-	return entry;
+    return entry;
 }
 
 LLVOCacheEntry* LLViewerRegion::getCacheEntry(U32 local_id, bool valid)
 {
-	LLVOCacheEntry::vocache_entry_map_t::iterator iter = mImpl->mCacheMap.find(local_id);
-	if(iter != mImpl->mCacheMap.end())
-	{
-		if(!valid || iter->second->isValid())
-		{
-			return iter->second;
-		}
-	}
-	return NULL;
+    LLVOCacheEntry::vocache_entry_map_t::iterator iter = mImpl->mCacheMap.find(local_id);
+    if(iter != mImpl->mCacheMap.end())
+    {
+        if(!valid || iter->second->isValid())
+        {
+            return iter->second;
+        }
+    }
+    return NULL;
 }
 
 void LLViewerRegion::addCacheMiss(U32 id, LLViewerRegion::eCacheMissType cache_miss_type)
 {
-	mRegionCacheMissCount++;
+    mRegionCacheMissCount++;
     mCacheMissList.push_back(CacheMissItem(id, cache_miss_type));
 }
 
 //check if a non-cacheable object is already created.
 bool LLViewerRegion::isNonCacheableObjectCreated(U32 local_id)
 {
-	if(mImpl && local_id > 0 && mImpl->mNonCacheableCreatedList.find(local_id) != mImpl->mNonCacheableCreatedList.end())
-	{
-		return true;
-	}
-	return false;
+    if(mImpl && local_id > 0 && mImpl->mNonCacheableCreatedList.find(local_id) != mImpl->mNonCacheableCreatedList.end())
+    {
+        return true;
+    }
+    return false;
 }
-		
+
 void LLViewerRegion::removeFromCreatedList(U32 local_id)
-{	
-	if(mImpl && local_id > 0)
-	{
-		std::set<U32>::iterator iter = mImpl->mNonCacheableCreatedList.find(local_id);
-		if(iter != mImpl->mNonCacheableCreatedList.end())
-		{
-			mImpl->mNonCacheableCreatedList.erase(iter);
-		}
-	}
-	}
+{
+    if(mImpl && local_id > 0)
+    {
+        std::set<U32>::iterator iter = mImpl->mNonCacheableCreatedList.find(local_id);
+        if(iter != mImpl->mNonCacheableCreatedList.end())
+        {
+            mImpl->mNonCacheableCreatedList.erase(iter);
+        }
+    }
+    }
 
 void LLViewerRegion::addToCreatedList(U32 local_id)
 {
-	if(mImpl && local_id > 0)
-	{
-		mImpl->mNonCacheableCreatedList.insert(local_id);
-	}
+    if(mImpl && local_id > 0)
+    {
+        mImpl->mNonCacheableCreatedList.insert(local_id);
+    }
 }
 
 // Get data packer for this object, if we have cached data
 // AND the CRC matches. JC
 bool LLViewerRegion::probeCache(U32 local_id, U32 crc, U32 flags, U8 &cache_miss_type)
 {
-	//llassert(mCacheLoaded);  This assert failes often, changing to early-out -- davep, 2010/10/18
+    //llassert(mCacheLoaded);  This assert failes often, changing to early-out -- davep, 2010/10/18
 
-	LLVOCacheEntry* entry = getCacheEntry(local_id, false);
+    LLVOCacheEntry* entry = getCacheEntry(local_id, false);
 
-	if (entry)
-	{
-		// we've seen this object before
-		if (entry->getCRC() == crc)
-		{
-			// Record a hit
-			mRegionCacheHitCount++;
-			entry->recordHit();
+    if (entry)
+    {
+        // we've seen this object before
+        if (entry->getCRC() == crc)
+        {
+            // Record a hit
+            mRegionCacheHitCount++;
+            entry->recordHit();
             cache_miss_type = CACHE_MISS_TYPE_NONE;
-			entry->setUpdateFlags(flags);
-			
-			if(entry->isState(LLVOCacheEntry::ACTIVE))
-			{
-				((LLDrawable*)entry->getEntry()->getDrawable())->getVObj()->loadFlags(flags);
-				return true;
-			}
-
-			if(entry->isValid())
-			{
-				return true; //already probed
-			}
-
-			entry->setValid();
-			decodeBoundingInfo(entry);
+            entry->setUpdateFlags(flags);
+
+            if(entry->isState(LLVOCacheEntry::ACTIVE))
+            {
+                ((LLDrawable*)entry->getEntry()->getDrawable())->getVObj()->loadFlags(flags);
+                return true;
+            }
+
+            if(entry->isValid())
+            {
+                return true; //already probed
+            }
+
+            entry->setValid();
+            decodeBoundingInfo(entry);
 
             //loadCacheMiscExtras(local_id, entry, crc);
 
-			return true;
-		}
-		else
-		{
-			// LL_INFOS() << "CRC miss for " << local_id << LL_ENDL;
+            return true;
+        }
+        else
+        {
+            // LL_INFOS() << "CRC miss for " << local_id << LL_ENDL;
 
-			addCacheMiss(local_id, CACHE_MISS_TYPE_CRC);
+            addCacheMiss(local_id, CACHE_MISS_TYPE_CRC);
             cache_miss_type = CACHE_MISS_TYPE_CRC;
-		}
-	}
-	else
-	{	// Total miss, don't have the object in cache
-		// LL_INFOS() << "Cache miss for " << local_id << LL_ENDL;
+        }
+    }
+    else
+    {   // Total miss, don't have the object in cache
+        // LL_INFOS() << "Cache miss for " << local_id << LL_ENDL;
         addCacheMiss(local_id, CACHE_MISS_TYPE_TOTAL);
         cache_miss_type = CACHE_MISS_TYPE_TOTAL;
-	}
+    }
 
-	return false;
+    return false;
 }
 
 void LLViewerRegion::addCacheMissFull(const U32 local_id)
 {
-	addCacheMiss(local_id, CACHE_MISS_TYPE_TOTAL);
+    addCacheMiss(local_id, CACHE_MISS_TYPE_TOTAL);
 }
 
 void LLViewerRegion::requestCacheMisses()
 {
-	if (mCacheMissList.empty()) 
-	{
-		return;
-	}
-
-	LLMessageSystem* msg = gMessageSystem;
-	BOOL start_new_message = TRUE;
-	S32 blocks = 0;
-
-	//send requests for all cache-missed objects
-	for (CacheMissItem::cache_miss_list_t::iterator iter = mCacheMissList.begin(); iter != mCacheMissList.end(); ++iter)
-	{
-		if (start_new_message)
-		{
-			msg->newMessageFast(_PREHASH_RequestMultipleObjects);
-			msg->nextBlockFast(_PREHASH_AgentData);
-			msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-			msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-			start_new_message = FALSE;
-		}
-
-		msg->nextBlockFast(_PREHASH_ObjectData);
-		msg->addU8Fast(_PREHASH_CacheMissType, (*iter).mType);
-		msg->addU32Fast(_PREHASH_ID, (*iter).mID);
+    if (mCacheMissList.empty())
+    {
+        return;
+    }
+
+    LLMessageSystem* msg = gMessageSystem;
+    BOOL start_new_message = TRUE;
+    S32 blocks = 0;
+
+    //send requests for all cache-missed objects
+    for (CacheMissItem::cache_miss_list_t::iterator iter = mCacheMissList.begin(); iter != mCacheMissList.end(); ++iter)
+    {
+        if (start_new_message)
+        {
+            msg->newMessageFast(_PREHASH_RequestMultipleObjects);
+            msg->nextBlockFast(_PREHASH_AgentData);
+            msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+            msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+            start_new_message = FALSE;
+        }
+
+        msg->nextBlockFast(_PREHASH_ObjectData);
+        msg->addU8Fast(_PREHASH_CacheMissType, (*iter).mType);
+        msg->addU32Fast(_PREHASH_ID, (*iter).mID);
 
 #ifdef SHOW_DEBUG
         LL_DEBUGS("AnimatedObjects") << "Requesting cache missed object " << (*iter).mID << LL_ENDL;
 #endif
-        
-		blocks++;
 
-		if (blocks >= 255)
-		{
-			sendReliableMessage();
-			start_new_message = TRUE;
-			blocks = 0;
-		}
-	}
+        blocks++;
+
+        if (blocks >= 255)
+        {
+            sendReliableMessage();
+            start_new_message = TRUE;
+            blocks = 0;
+        }
+    }
 
-	// finish any pending message
-	if (!start_new_message)
-	{
-		sendReliableMessage();
-	}
+    // finish any pending message
+    if (!start_new_message)
+    {
+        sendReliableMessage();
+    }
 
-	mCacheDirty = TRUE ;
-	// LL_INFOS() << "KILLDEBUG Sent cache miss full " << full_count << " crc " << crc_count << LL_ENDL;
-	LLViewerStatsRecorder::instance().requestCacheMissesEvent(mCacheMissList.size());
+    mCacheDirty = TRUE ;
+    // LL_INFOS() << "KILLDEBUG Sent cache miss full " << full_count << " crc " << crc_count << LL_ENDL;
+    LLViewerStatsRecorder::instance().requestCacheMissesEvent(mCacheMissList.size());
 
-	mCacheMissList.clear();
+    mCacheMissList.clear();
 }
 
 void LLViewerRegion::dumpCache()
 {
-	const S32 BINS = 4;
-	S32 hit_bin[BINS];
-	S32 change_bin[BINS];
+    const S32 BINS = 4;
+    S32 hit_bin[BINS];
+    S32 change_bin[BINS];
 
-	S32 i;
-	for (i = 0; i < BINS; ++i)
-	{
-		hit_bin[i] = 0;
-		change_bin[i] = 0;
-	}
+    S32 i;
+    for (i = 0; i < BINS; ++i)
+    {
+        hit_bin[i] = 0;
+        change_bin[i] = 0;
+    }
 
-	LLVOCacheEntry *entry;
-	for(LLVOCacheEntry::vocache_entry_map_t::iterator iter = mImpl->mCacheMap.begin(); iter != mImpl->mCacheMap.end(); ++iter)
-	{
-		entry = iter->second ;
+    LLVOCacheEntry *entry;
+    for(LLVOCacheEntry::vocache_entry_map_t::iterator iter = mImpl->mCacheMap.begin(); iter != mImpl->mCacheMap.end(); ++iter)
+    {
+        entry = iter->second ;
 
-		S32 hits = entry->getHitCount();
-		S32 changes = entry->getCRCChangeCount();
+        S32 hits = entry->getHitCount();
+        S32 changes = entry->getCRCChangeCount();
 
-		hits = llclamp(hits, 0, BINS-1);
-		changes = llclamp(changes, 0, BINS-1);
+        hits = llclamp(hits, 0, BINS-1);
+        changes = llclamp(changes, 0, BINS-1);
 
-		hit_bin[hits]++;
-		change_bin[changes]++;
-	}
+        hit_bin[hits]++;
+        change_bin[changes]++;
+    }
 
-	LL_INFOS() << "Count " << mImpl->mCacheMap.size() << LL_ENDL;
-	for (i = 0; i < BINS; i++)
-	{
-		LL_INFOS() << "Hits " << i << " " << hit_bin[i] << LL_ENDL;
-	}
-	for (i = 0; i < BINS; i++)
-	{
-		LL_INFOS() << "Changes " << i << " " << change_bin[i] << LL_ENDL;
-	}
-	// TODO - add overrides cache too
+    LL_INFOS() << "Count " << mImpl->mCacheMap.size() << LL_ENDL;
+    for (i = 0; i < BINS; i++)
+    {
+        LL_INFOS() << "Hits " << i << " " << hit_bin[i] << LL_ENDL;
+    }
+    for (i = 0; i < BINS; i++)
+    {
+        LL_INFOS() << "Changes " << i << " " << change_bin[i] << LL_ENDL;
+    }
+    // TODO - add overrides cache too
 }
 
 void LLViewerRegion::clearVOCacheFromMemory()
@@ -3187,327 +3187,327 @@ void LLViewerRegion::clearVOCacheFromMemory()
 
 void LLViewerRegion::unpackRegionHandshake()
 {
-	LLMessageSystem *msg = gMessageSystem;
-
-	U64 region_flags = 0;
-	U64 region_protocols = 0;
-	U8 sim_access;
-	std::string sim_name;
-	LLUUID sim_owner;
-	BOOL is_estate_manager;
-	F32 water_height;
-	F32 billable_factor;
-	LLUUID cache_id;
-
-	msg->getU8Fast		(_PREHASH_RegionInfo, _PREHASH_SimAccess, sim_access);
-	msg->getStringFast	(_PREHASH_RegionInfo, _PREHASH_SimName, sim_name);
-	msg->getUUIDFast	(_PREHASH_RegionInfo, _PREHASH_SimOwner, sim_owner);
-	msg->getBOOLFast	(_PREHASH_RegionInfo, _PREHASH_IsEstateManager, is_estate_manager);
-	msg->getF32Fast		(_PREHASH_RegionInfo, _PREHASH_WaterHeight, water_height);
-	msg->getF32Fast		(_PREHASH_RegionInfo, _PREHASH_BillableFactor, billable_factor);
-	msg->getUUIDFast	(_PREHASH_RegionInfo, _PREHASH_CacheID, cache_id );
-
-	if (msg->hasFast(_PREHASH_RegionInfo4))
-	{
-		msg->getU64Fast(_PREHASH_RegionInfo4, _PREHASH_RegionFlagsExtended, region_flags);
-		msg->getU64Fast(_PREHASH_RegionInfo4, _PREHASH_RegionProtocols, region_protocols);
-	}
-	else
-	{
-		U32 flags = 0;
-		msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_RegionFlags, flags);
-		region_flags = flags;
-	}
-
-	setRegionFlags(region_flags);
-	setRegionProtocols(region_protocols);
-	setSimAccess(sim_access);
-	setRegionNameAndZone(sim_name);
-	setOwner(sim_owner);
-	setIsEstateManager(is_estate_manager);
-	setWaterHeight(water_height);
-	setBillableFactor(billable_factor);
-	setCacheID(cache_id);
-
-	LLUUID region_id;
-	msg->getUUIDFast(_PREHASH_RegionInfo2, _PREHASH_RegionID, region_id);
-	setRegionID(region_id);
-	
-	// Retrieve the CR-53 (Homestead/Land SKU) information
-	S32 classID = 0;
-	S32 cpuRatio = 0;
-	std::string coloName;
-	std::string productSKU;
-	std::string productName;
-
-	// the only reasonable way to decide if we actually have any data is to
-	// check to see if any of these fields have positive sizes
-	if (msg->getSizeFast(_PREHASH_RegionInfo3, _PREHASH_ColoName) > 0 ||
-	    msg->getSizeFast(_PREHASH_RegionInfo3, _PREHASH_ProductSKU) > 0 ||
-	    msg->getSizeFast(_PREHASH_RegionInfo3, _PREHASH_ProductName) > 0)
-	{
-		msg->getS32Fast     (_PREHASH_RegionInfo3, _PREHASH_CPUClassID,  classID);
-		msg->getS32Fast     (_PREHASH_RegionInfo3, _PREHASH_CPURatio,    cpuRatio);
-		msg->getStringFast  (_PREHASH_RegionInfo3, _PREHASH_ColoName,    coloName);
-		msg->getStringFast  (_PREHASH_RegionInfo3, _PREHASH_ProductSKU,  productSKU);
-		msg->getStringFast  (_PREHASH_RegionInfo3, _PREHASH_ProductName, productName);
-		
-		mClassID = classID;
-		mCPURatio = cpuRatio;
-		mColoName = coloName;
-		mProductSKU = productSKU;
-		mProductName = productName;
-	}
-
-	mCentralBakeVersion = region_protocols & 1; // was (S32)gSavedSettings.getBOOL("UseServerTextureBaking");
-	LLVLComposition *compp = getComposition();
-	if (compp)
-	{
-		LLUUID tmp_id;
-
-		bool changed = false;
-
-		// Get the 4 textures for land
-		msg->getUUIDFast(_PREHASH_RegionInfo, _PREHASH_TerrainDetail0, tmp_id);
-		changed |= (tmp_id != compp->getDetailAssetID(0));		
-		compp->setDetailAssetID(0, tmp_id);
-
-		msg->getUUIDFast(_PREHASH_RegionInfo, _PREHASH_TerrainDetail1, tmp_id);
-		changed |= (tmp_id != compp->getDetailAssetID(1));		
-		compp->setDetailAssetID(1, tmp_id);
-
-		msg->getUUIDFast(_PREHASH_RegionInfo, _PREHASH_TerrainDetail2, tmp_id);
-		changed |= (tmp_id != compp->getDetailAssetID(2));		
-		compp->setDetailAssetID(2, tmp_id);
-
-		msg->getUUIDFast(_PREHASH_RegionInfo, _PREHASH_TerrainDetail3, tmp_id);
-		changed |= (tmp_id != compp->getDetailAssetID(3));		
-		compp->setDetailAssetID(3, tmp_id);
-
-		// Get the start altitude and range values for land textures
-		F32 tmp_f32;
-		msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainStartHeight00, tmp_f32);
-		changed |= (tmp_f32 != compp->getStartHeight(0));
-		compp->setStartHeight(0, tmp_f32);
-
-		msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainStartHeight01, tmp_f32);
-		changed |= (tmp_f32 != compp->getStartHeight(1));
-		compp->setStartHeight(1, tmp_f32);
-
-		msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainStartHeight10, tmp_f32);
-		changed |= (tmp_f32 != compp->getStartHeight(2));
-		compp->setStartHeight(2, tmp_f32);
-
-		msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainStartHeight11, tmp_f32);
-		changed |= (tmp_f32 != compp->getStartHeight(3));
-		compp->setStartHeight(3, tmp_f32);
-
-
-		msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainHeightRange00, tmp_f32);
-		changed |= (tmp_f32 != compp->getHeightRange(0));
-		compp->setHeightRange(0, tmp_f32);
-
-		msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainHeightRange01, tmp_f32);
-		changed |= (tmp_f32 != compp->getHeightRange(1));
-		compp->setHeightRange(1, tmp_f32);
-
-		msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainHeightRange10, tmp_f32);
-		changed |= (tmp_f32 != compp->getHeightRange(2));
-		compp->setHeightRange(2, tmp_f32);
-
-		msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainHeightRange11, tmp_f32);
-		changed |= (tmp_f32 != compp->getHeightRange(3));
-		compp->setHeightRange(3, tmp_f32);
-
-		// If this is an UPDATE (params already ready, we need to regenerate
-		// all of our terrain stuff, by
-		if (compp->getParamsReady())
-		{
-			// Update if the land changed
-			if (changed)
-			{
-				getLand().dirtyAllPatches();
-			}
-		}
-		else
-		{
-			compp->setParamsReady();
-		}
-	}
-
-
-	// Now that we have the name, we can load the cache file
-	// off disk.
-	loadObjectCache();
-
-	// After loading cache, signal that simulator can start
-	// sending data.
-	// TODO: Send all upstream viewer->sim handshake info here.
-	LLHost host = msg->getSender();
-	msg->newMessageFast(_PREHASH_RegionHandshakeReply);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->nextBlockFast(_PREHASH_RegionInfo);
-
-	U32 flags = 0;
-	flags |= REGION_HANDSHAKE_SUPPORTS_SELF_APPEARANCE;
-
-	if(sVOCacheCullingEnabled)
-	{
-		flags |= 0x00000001; //set the bit 0 to be 1 to ask sim to send all cacheable objects.		
-	}
-	if(mImpl->mCacheMap.empty())
-	{
-		flags |= 0x00000002; //set the bit 1 to be 1 to tell sim the cache file is empty, no need to send cache probes.
-	}
-	msg->addU32Fast(_PREHASH_Flags, flags );
-	msg->sendReliable(host);
-
-	mRegionTimer.reset(); //reset region timer.
+    LLMessageSystem *msg = gMessageSystem;
+
+    U64 region_flags = 0;
+    U64 region_protocols = 0;
+    U8 sim_access;
+    std::string sim_name;
+    LLUUID sim_owner;
+    BOOL is_estate_manager;
+    F32 water_height;
+    F32 billable_factor;
+    LLUUID cache_id;
+
+    msg->getU8Fast      (_PREHASH_RegionInfo, _PREHASH_SimAccess, sim_access);
+    msg->getStringFast  (_PREHASH_RegionInfo, _PREHASH_SimName, sim_name);
+    msg->getUUIDFast    (_PREHASH_RegionInfo, _PREHASH_SimOwner, sim_owner);
+    msg->getBOOLFast    (_PREHASH_RegionInfo, _PREHASH_IsEstateManager, is_estate_manager);
+    msg->getF32Fast     (_PREHASH_RegionInfo, _PREHASH_WaterHeight, water_height);
+    msg->getF32Fast     (_PREHASH_RegionInfo, _PREHASH_BillableFactor, billable_factor);
+    msg->getUUIDFast    (_PREHASH_RegionInfo, _PREHASH_CacheID, cache_id );
+
+    if (msg->hasFast(_PREHASH_RegionInfo4))
+    {
+        msg->getU64Fast(_PREHASH_RegionInfo4, _PREHASH_RegionFlagsExtended, region_flags);
+        msg->getU64Fast(_PREHASH_RegionInfo4, _PREHASH_RegionProtocols, region_protocols);
+    }
+    else
+    {
+        U32 flags = 0;
+        msg->getU32Fast(_PREHASH_RegionInfo, _PREHASH_RegionFlags, flags);
+        region_flags = flags;
+    }
+
+    setRegionFlags(region_flags);
+    setRegionProtocols(region_protocols);
+    setSimAccess(sim_access);
+    setRegionNameAndZone(sim_name);
+    setOwner(sim_owner);
+    setIsEstateManager(is_estate_manager);
+    setWaterHeight(water_height);
+    setBillableFactor(billable_factor);
+    setCacheID(cache_id);
+
+    LLUUID region_id;
+    msg->getUUIDFast(_PREHASH_RegionInfo2, _PREHASH_RegionID, region_id);
+    setRegionID(region_id);
+
+    // Retrieve the CR-53 (Homestead/Land SKU) information
+    S32 classID = 0;
+    S32 cpuRatio = 0;
+    std::string coloName;
+    std::string productSKU;
+    std::string productName;
+
+    // the only reasonable way to decide if we actually have any data is to
+    // check to see if any of these fields have positive sizes
+    if (msg->getSizeFast(_PREHASH_RegionInfo3, _PREHASH_ColoName) > 0 ||
+        msg->getSizeFast(_PREHASH_RegionInfo3, _PREHASH_ProductSKU) > 0 ||
+        msg->getSizeFast(_PREHASH_RegionInfo3, _PREHASH_ProductName) > 0)
+    {
+        msg->getS32Fast     (_PREHASH_RegionInfo3, _PREHASH_CPUClassID,  classID);
+        msg->getS32Fast     (_PREHASH_RegionInfo3, _PREHASH_CPURatio,    cpuRatio);
+        msg->getStringFast  (_PREHASH_RegionInfo3, _PREHASH_ColoName,    coloName);
+        msg->getStringFast  (_PREHASH_RegionInfo3, _PREHASH_ProductSKU,  productSKU);
+        msg->getStringFast  (_PREHASH_RegionInfo3, _PREHASH_ProductName, productName);
+
+        mClassID = classID;
+        mCPURatio = cpuRatio;
+        mColoName = coloName;
+        mProductSKU = productSKU;
+        mProductName = productName;
+    }
+
+    mCentralBakeVersion = region_protocols & 1; // was (S32)gSavedSettings.getBOOL("UseServerTextureBaking");
+    LLVLComposition *compp = getComposition();
+    if (compp)
+    {
+        LLUUID tmp_id;
+
+        bool changed = false;
+
+        // Get the 4 textures for land
+        msg->getUUIDFast(_PREHASH_RegionInfo, _PREHASH_TerrainDetail0, tmp_id);
+        changed |= (tmp_id != compp->getDetailAssetID(0));
+        compp->setDetailAssetID(0, tmp_id);
+
+        msg->getUUIDFast(_PREHASH_RegionInfo, _PREHASH_TerrainDetail1, tmp_id);
+        changed |= (tmp_id != compp->getDetailAssetID(1));
+        compp->setDetailAssetID(1, tmp_id);
+
+        msg->getUUIDFast(_PREHASH_RegionInfo, _PREHASH_TerrainDetail2, tmp_id);
+        changed |= (tmp_id != compp->getDetailAssetID(2));
+        compp->setDetailAssetID(2, tmp_id);
+
+        msg->getUUIDFast(_PREHASH_RegionInfo, _PREHASH_TerrainDetail3, tmp_id);
+        changed |= (tmp_id != compp->getDetailAssetID(3));
+        compp->setDetailAssetID(3, tmp_id);
+
+        // Get the start altitude and range values for land textures
+        F32 tmp_f32;
+        msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainStartHeight00, tmp_f32);
+        changed |= (tmp_f32 != compp->getStartHeight(0));
+        compp->setStartHeight(0, tmp_f32);
+
+        msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainStartHeight01, tmp_f32);
+        changed |= (tmp_f32 != compp->getStartHeight(1));
+        compp->setStartHeight(1, tmp_f32);
+
+        msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainStartHeight10, tmp_f32);
+        changed |= (tmp_f32 != compp->getStartHeight(2));
+        compp->setStartHeight(2, tmp_f32);
+
+        msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainStartHeight11, tmp_f32);
+        changed |= (tmp_f32 != compp->getStartHeight(3));
+        compp->setStartHeight(3, tmp_f32);
+
+
+        msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainHeightRange00, tmp_f32);
+        changed |= (tmp_f32 != compp->getHeightRange(0));
+        compp->setHeightRange(0, tmp_f32);
+
+        msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainHeightRange01, tmp_f32);
+        changed |= (tmp_f32 != compp->getHeightRange(1));
+        compp->setHeightRange(1, tmp_f32);
+
+        msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainHeightRange10, tmp_f32);
+        changed |= (tmp_f32 != compp->getHeightRange(2));
+        compp->setHeightRange(2, tmp_f32);
+
+        msg->getF32Fast(_PREHASH_RegionInfo, _PREHASH_TerrainHeightRange11, tmp_f32);
+        changed |= (tmp_f32 != compp->getHeightRange(3));
+        compp->setHeightRange(3, tmp_f32);
+
+        // If this is an UPDATE (params already ready, we need to regenerate
+        // all of our terrain stuff, by
+        if (compp->getParamsReady())
+        {
+            // Update if the land changed
+            if (changed)
+            {
+                getLand().dirtyAllPatches();
+            }
+        }
+        else
+        {
+            compp->setParamsReady();
+        }
+    }
+
+
+    // Now that we have the name, we can load the cache file
+    // off disk.
+    loadObjectCache();
+
+    // After loading cache, signal that simulator can start
+    // sending data.
+    // TODO: Send all upstream viewer->sim handshake info here.
+    LLHost host = msg->getSender();
+    msg->newMessageFast(_PREHASH_RegionHandshakeReply);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->nextBlockFast(_PREHASH_RegionInfo);
+
+    U32 flags = 0;
+    flags |= REGION_HANDSHAKE_SUPPORTS_SELF_APPEARANCE;
+
+    if(sVOCacheCullingEnabled)
+    {
+        flags |= 0x00000001; //set the bit 0 to be 1 to ask sim to send all cacheable objects.
+    }
+    if(mImpl->mCacheMap.empty())
+    {
+        flags |= 0x00000002; //set the bit 1 to be 1 to tell sim the cache file is empty, no need to send cache probes.
+    }
+    msg->addU32Fast(_PREHASH_Flags, flags );
+    msg->sendReliable(host);
+
+    mRegionTimer.reset(); //reset region timer.
 }
 
 // static
 void LLViewerRegionImpl::buildCapabilityNames(LLSD& capabilityNames)
 {
-	capabilityNames.append("AbuseCategories");
-	capabilityNames.append("AcceptFriendship");
-	capabilityNames.append("AcceptGroupInvite"); // ReadOfflineMsgs recieved messages only!!!
-	capabilityNames.append("AgentPreferences");
+    capabilityNames.append("AbuseCategories");
+    capabilityNames.append("AcceptFriendship");
+    capabilityNames.append("AcceptGroupInvite"); // ReadOfflineMsgs recieved messages only!!!
+    capabilityNames.append("AgentPreferences");
     capabilityNames.append("AgentProfile");
-	capabilityNames.append("AgentState");
-	capabilityNames.append("AttachmentResources");
-	capabilityNames.append("AvatarPickerSearch");
-	capabilityNames.append("AvatarRenderInfo");
-	capabilityNames.append("CharacterProperties");
-	capabilityNames.append("ChatSessionRequest");
-	capabilityNames.append("CopyInventoryFromNotecard");
-	capabilityNames.append("CreateInventoryCategory");
-	capabilityNames.append("DeclineFriendship");
-	capabilityNames.append("DeclineGroupInvite"); // ReadOfflineMsgs recieved messages only!!!
-	capabilityNames.append("DispatchRegionInfo");
-	capabilityNames.append("DirectDelivery");
-	capabilityNames.append("EnvironmentSettings");
-	capabilityNames.append("EstateAccess");
-	capabilityNames.append("EstateChangeInfo");
-	capabilityNames.append("EventQueueGet");
+    capabilityNames.append("AgentState");
+    capabilityNames.append("AttachmentResources");
+    capabilityNames.append("AvatarPickerSearch");
+    capabilityNames.append("AvatarRenderInfo");
+    capabilityNames.append("CharacterProperties");
+    capabilityNames.append("ChatSessionRequest");
+    capabilityNames.append("CopyInventoryFromNotecard");
+    capabilityNames.append("CreateInventoryCategory");
+    capabilityNames.append("DeclineFriendship");
+    capabilityNames.append("DeclineGroupInvite"); // ReadOfflineMsgs recieved messages only!!!
+    capabilityNames.append("DispatchRegionInfo");
+    capabilityNames.append("DirectDelivery");
+    capabilityNames.append("EnvironmentSettings");
+    capabilityNames.append("EstateAccess");
+    capabilityNames.append("EstateChangeInfo");
+    capabilityNames.append("EventQueueGet");
     capabilityNames.append("ExtEnvironment");
 
-	if (LLGridManager::instance().isInSecondlife() || gSavedSettings.getBOOL("UseHTTPInventory"))
-	{
-		capabilityNames.append("FetchLib2");
-		capabilityNames.append("FetchLibDescendents2");
-		capabilityNames.append("FetchInventory2");
-		capabilityNames.append("FetchInventoryDescendents2");
-		capabilityNames.append("IncrementCOFVersion");
-		AISAPI::getCapNames(capabilityNames);
-	}
+    if (LLGridManager::instance().isInSecondlife() || gSavedSettings.getBOOL("UseHTTPInventory"))
+    {
+        capabilityNames.append("FetchLib2");
+        capabilityNames.append("FetchLibDescendents2");
+        capabilityNames.append("FetchInventory2");
+        capabilityNames.append("FetchInventoryDescendents2");
+        capabilityNames.append("IncrementCOFVersion");
+        AISAPI::getCapNames(capabilityNames);
+    }
 
-	capabilityNames.append("InterestList");
+    capabilityNames.append("InterestList");
 
     capabilityNames.append("InventoryThumbnailUpload");
-	capabilityNames.append("GetDisplayNames");
-	capabilityNames.append("GetExperiences");
-	capabilityNames.append("AgentExperiences");
-	capabilityNames.append("FindExperienceByName");
-	capabilityNames.append("GetExperienceInfo");
-	capabilityNames.append("GetAdminExperiences");
-	capabilityNames.append("GetCreatorExperiences");
-	capabilityNames.append("ExperiencePreferences");
-	capabilityNames.append("GroupExperiences");
-	capabilityNames.append("UpdateExperience");
-	capabilityNames.append("IsExperienceAdmin");
-	capabilityNames.append("IsExperienceContributor");
-	capabilityNames.append("RegionExperiences");
+    capabilityNames.append("GetDisplayNames");
+    capabilityNames.append("GetExperiences");
+    capabilityNames.append("AgentExperiences");
+    capabilityNames.append("FindExperienceByName");
+    capabilityNames.append("GetExperienceInfo");
+    capabilityNames.append("GetAdminExperiences");
+    capabilityNames.append("GetCreatorExperiences");
+    capabilityNames.append("ExperiencePreferences");
+    capabilityNames.append("GroupExperiences");
+    capabilityNames.append("UpdateExperience");
+    capabilityNames.append("IsExperienceAdmin");
+    capabilityNames.append("IsExperienceContributor");
+    capabilityNames.append("RegionExperiences");
     capabilityNames.append("ExperienceQuery");
-	if(!LLGridManager::instance().isInSecondlife())
-	{
-		capabilityNames.append("GetMesh");
-		capabilityNames.append("GetMesh2");
-	}
-	capabilityNames.append("GetMetadata");
-	capabilityNames.append("GetObjectCost");
-	capabilityNames.append("GetObjectPhysicsData");
-	if(!LLGridManager::instance().isInSecondlife())
-	{
-		capabilityNames.append("GetTexture");
-	}
-	capabilityNames.append("GroupAPIv1");
-	capabilityNames.append("GroupMemberData");
-	capabilityNames.append("GroupProposalBallot");
-	capabilityNames.append("HomeLocation");
-	capabilityNames.append("LandResources");
-	capabilityNames.append("LSLSyntax");
-	capabilityNames.append("MapLayer");
-	capabilityNames.append("MapLayerGod");
-	capabilityNames.append("MeshUploadFlag");	
-	capabilityNames.append("ModifyMaterialParams");
-	capabilityNames.append("NavMeshGenerationStatus");
-	capabilityNames.append("NewFileAgentInventory");
-	capabilityNames.append("ObjectAnimation");
-	capabilityNames.append("ObjectMedia");
-	capabilityNames.append("ObjectMediaNavigate");
-	capabilityNames.append("ObjectNavMeshProperties");
-	capabilityNames.append("ParcelPropertiesUpdate");
-	capabilityNames.append("ParcelVoiceInfoRequest");
-	capabilityNames.append("ProductInfoRequest");
-	capabilityNames.append("ProvisionVoiceAccountRequest");
-	capabilityNames.append("ReadOfflineMsgs"); // Requires to respond reliably: AcceptFriendship, AcceptGroupInvite, DeclineFriendship, DeclineGroupInvite
-	capabilityNames.append("RegionObjects");
-	capabilityNames.append("RemoteParcelRequest");
-	capabilityNames.append("RenderMaterials");
-	capabilityNames.append("RequestTextureDownload");
-	capabilityNames.append("ResourceCostSelected");
-	capabilityNames.append("RetrieveNavMeshSrc");
-	capabilityNames.append("SearchStatRequest");
-	capabilityNames.append("SearchStatTracking");
-	capabilityNames.append("SendPostcard");
-	capabilityNames.append("SendUserReport");
-	capabilityNames.append("SendUserReportWithScreenshot");
-	capabilityNames.append("ServerReleaseNotes");
-	capabilityNames.append("SetDisplayName");
-	capabilityNames.append("SimConsoleAsync");
-	capabilityNames.append("SimulatorFeatures");
-	capabilityNames.append("StartGroupProposal");
-	capabilityNames.append("TerrainNavMeshProperties");
-	capabilityNames.append("TextureStats");
-	capabilityNames.append("UntrustedSimulatorMessage");
-	capabilityNames.append("UpdateAgentInformation");
-	capabilityNames.append("UpdateAgentLanguage");
-	capabilityNames.append("UpdateAvatarAppearance");
-	capabilityNames.append("UpdateGestureAgentInventory");
-	capabilityNames.append("UpdateGestureTaskInventory");
-	capabilityNames.append("UpdateNotecardAgentInventory");
-	capabilityNames.append("UpdateNotecardTaskInventory");
-	capabilityNames.append("UpdateScriptAgent");
-	capabilityNames.append("UpdateScriptTask");
+    if(!LLGridManager::instance().isInSecondlife())
+    {
+        capabilityNames.append("GetMesh");
+        capabilityNames.append("GetMesh2");
+    }
+    capabilityNames.append("GetMetadata");
+    capabilityNames.append("GetObjectCost");
+    capabilityNames.append("GetObjectPhysicsData");
+    if(!LLGridManager::instance().isInSecondlife())
+    {
+        capabilityNames.append("GetTexture");
+    }
+    capabilityNames.append("GroupAPIv1");
+    capabilityNames.append("GroupMemberData");
+    capabilityNames.append("GroupProposalBallot");
+    capabilityNames.append("HomeLocation");
+    capabilityNames.append("LandResources");
+    capabilityNames.append("LSLSyntax");
+    capabilityNames.append("MapLayer");
+    capabilityNames.append("MapLayerGod");
+    capabilityNames.append("MeshUploadFlag");
+    capabilityNames.append("ModifyMaterialParams");
+    capabilityNames.append("NavMeshGenerationStatus");
+    capabilityNames.append("NewFileAgentInventory");
+    capabilityNames.append("ObjectAnimation");
+    capabilityNames.append("ObjectMedia");
+    capabilityNames.append("ObjectMediaNavigate");
+    capabilityNames.append("ObjectNavMeshProperties");
+    capabilityNames.append("ParcelPropertiesUpdate");
+    capabilityNames.append("ParcelVoiceInfoRequest");
+    capabilityNames.append("ProductInfoRequest");
+    capabilityNames.append("ProvisionVoiceAccountRequest");
+    capabilityNames.append("ReadOfflineMsgs"); // Requires to respond reliably: AcceptFriendship, AcceptGroupInvite, DeclineFriendship, DeclineGroupInvite
+    capabilityNames.append("RegionObjects");
+    capabilityNames.append("RemoteParcelRequest");
+    capabilityNames.append("RenderMaterials");
+    capabilityNames.append("RequestTextureDownload");
+    capabilityNames.append("ResourceCostSelected");
+    capabilityNames.append("RetrieveNavMeshSrc");
+    capabilityNames.append("SearchStatRequest");
+    capabilityNames.append("SearchStatTracking");
+    capabilityNames.append("SendPostcard");
+    capabilityNames.append("SendUserReport");
+    capabilityNames.append("SendUserReportWithScreenshot");
+    capabilityNames.append("ServerReleaseNotes");
+    capabilityNames.append("SetDisplayName");
+    capabilityNames.append("SimConsoleAsync");
+    capabilityNames.append("SimulatorFeatures");
+    capabilityNames.append("StartGroupProposal");
+    capabilityNames.append("TerrainNavMeshProperties");
+    capabilityNames.append("TextureStats");
+    capabilityNames.append("UntrustedSimulatorMessage");
+    capabilityNames.append("UpdateAgentInformation");
+    capabilityNames.append("UpdateAgentLanguage");
+    capabilityNames.append("UpdateAvatarAppearance");
+    capabilityNames.append("UpdateGestureAgentInventory");
+    capabilityNames.append("UpdateGestureTaskInventory");
+    capabilityNames.append("UpdateNotecardAgentInventory");
+    capabilityNames.append("UpdateNotecardTaskInventory");
+    capabilityNames.append("UpdateScriptAgent");
+    capabilityNames.append("UpdateScriptTask");
     capabilityNames.append("UpdateSettingsAgentInventory");
     capabilityNames.append("UpdateSettingsTaskInventory");
     capabilityNames.append("UploadAgentProfileImage");
     capabilityNames.append("UpdateMaterialAgentInventory");
     capabilityNames.append("UpdateMaterialTaskInventory");
-	capabilityNames.append("UploadBakedTexture");
+    capabilityNames.append("UploadBakedTexture");
     capabilityNames.append("UserInfo");
-	capabilityNames.append("ViewerAsset"); 
-	capabilityNames.append("ViewerBenefits");
-	capabilityNames.append("ViewerMetrics");
-	capabilityNames.append("ViewerStartAuction");
-	capabilityNames.append("ViewerStats");
+    capabilityNames.append("ViewerAsset");
+    capabilityNames.append("ViewerBenefits");
+    capabilityNames.append("ViewerMetrics");
+    capabilityNames.append("ViewerStartAuction");
+    capabilityNames.append("ViewerStats");
 
-	// Please add new capabilities alphabetically to reduce
-	// merge conflicts.
+    // Please add new capabilities alphabetically to reduce
+    // merge conflicts.
 }
 
 void LLViewerRegion::setSeedCapability(const std::string& url)
 {
-	if (getCapability("Seed") == url)
-    {	
-		setCapabilityDebug("Seed", url);
-		LL_WARNS("CrossingCaps") <<  "Received duplicate seed capability for " << getRegionID() << ", posting to seed " <<
-				url	<< LL_ENDL;
+    if (getCapability("Seed") == url)
+    {
+        setCapabilityDebug("Seed", url);
+        LL_WARNS("CrossingCaps") <<  "Received duplicate seed capability for " << getRegionID() << ", posting to seed " <<
+                url << LL_ENDL;
 
-		//Instead of just returning we build up a second set of seed caps and compare them 
-		//to the "original" seed cap received and determine why there is problem!
+        //Instead of just returning we build up a second set of seed caps and compare them
+        //to the "original" seed cap received and determine why there is problem!
         std::string coroname =
             LLCoros::instance().launch("LLEnvironmentRequest::requestBaseCapabilitiesCompleteCoro",
             boost::bind(&LLViewerRegionImpl::requestBaseCapabilitiesCompleteCoro, getHandle()));
@@ -3517,14 +3517,14 @@ void LLViewerRegion::setSeedCapability(const std::string& url)
         // Make sure we are still good to do
         LLCoros::checkStop();
 
-		return;
+        return;
     }
-	
-	delete mImpl->mEventPoll;
-	mImpl->mEventPoll = NULL;
-	
-	mImpl->mCapabilities.clear();
-	setCapability("Seed", url);
+
+    delete mImpl->mEventPoll;
+    mImpl->mEventPoll = NULL;
+
+    mImpl->mCapabilities.clear();
+    setCapability("Seed", url);
 
     std::string coroname =
         LLCoros::instance().launch("LLViewerRegionImpl::requestBaseCapabilitiesCoro",
@@ -3540,105 +3540,105 @@ void LLViewerRegion::setSeedCapability(const std::string& url)
 
 S32 LLViewerRegion::getNumSeedCapRetries()
 {
-	return mImpl->mSeedCapAttempts;
+    return mImpl->mSeedCapAttempts;
 }
 
 void LLViewerRegion::setCapability(const std::string& name, const std::string& url)
 {
-	bool add_to_mapping = true;
-
-	std::string base_url = get_base_cap_url(url);
-	//we need a multimap, since CERTAIN PEOPLE use non-unique URIs for each Cap.
-	//let's check if this cap name is already registered for this URI
-	//TODO: Better represented as map of sets
-	if(mCapURLMappings.count(base_url) > 0)
-	{
-		auto iter = mCapURLMappings.find(base_url);
-
-		while(iter != mCapURLMappings.cend())
-		{
-			if(iter->second == name)
-			{
-				add_to_mapping = false;
-				break;
-			}
-			++iter;
-		}
-	}
-
-	if(add_to_mapping)
-		mCapURLMappings.insert(std::pair<std::string, std::string>(base_url, name));
-
-	if(name == "EventQueueGet")
-	{
-		delete mImpl->mEventPoll;
-		mImpl->mEventPoll = NULL;
-		mImpl->mEventPoll = new LLEventPoll(url, getHost());
-	}
-	else if(name == "UntrustedSimulatorMessage")
-	{
+    bool add_to_mapping = true;
+
+    std::string base_url = get_base_cap_url(url);
+    //we need a multimap, since CERTAIN PEOPLE use non-unique URIs for each Cap.
+    //let's check if this cap name is already registered for this URI
+    //TODO: Better represented as map of sets
+    if(mCapURLMappings.count(base_url) > 0)
+    {
+        auto iter = mCapURLMappings.find(base_url);
+
+        while(iter != mCapURLMappings.cend())
+        {
+            if(iter->second == name)
+            {
+                add_to_mapping = false;
+                break;
+            }
+            ++iter;
+        }
+    }
+
+    if(add_to_mapping)
+        mCapURLMappings.insert(std::pair<std::string, std::string>(base_url, name));
+
+    if(name == "EventQueueGet")
+    {
+        delete mImpl->mEventPoll;
+        mImpl->mEventPoll = NULL;
+        mImpl->mEventPoll = new LLEventPoll(url, getHost());
+    }
+    else if(name == "UntrustedSimulatorMessage")
+    {
         mImpl->mHost.setUntrustedSimulatorCap(url);
-	}
-	else if (name == "SimulatorFeatures")
-	{
+    }
+    else if (name == "SimulatorFeatures")
+    {
         mImpl->mCapabilities["SimulatorFeatures"] = url;
         requestSimulatorFeatures();
-	}
-	else
-	{
-		mImpl->mCapabilities[name] = url;
-		if(name == "ViewerAsset")
-		{
-			/*==============================================================*/
-			// The following inserted lines are a hack for testing MAINT-7081,
-			// which is why the indentation and formatting are left ugly.
-			const char* VIEWERASSET = getenv("VIEWERASSET");
-			if (VIEWERASSET)
-			{
-				mImpl->mCapabilities[name] = VIEWERASSET;
-				mViewerAssetUrl = VIEWERASSET;
-			}
-			else
-			{
-				mViewerAssetUrl = url;
-			}
-			/*==============================================================*/
-		}
-		else if (name == "GetTexture")
-		{
-			mLegacyHttpUrl = url;
-		}
-	}
+    }
+    else
+    {
+        mImpl->mCapabilities[name] = url;
+        if(name == "ViewerAsset")
+        {
+            /*==============================================================*/
+            // The following inserted lines are a hack for testing MAINT-7081,
+            // which is why the indentation and formatting are left ugly.
+            const char* VIEWERASSET = getenv("VIEWERASSET");
+            if (VIEWERASSET)
+            {
+                mImpl->mCapabilities[name] = VIEWERASSET;
+                mViewerAssetUrl = VIEWERASSET;
+            }
+            else
+            {
+                mViewerAssetUrl = url;
+            }
+            /*==============================================================*/
+        }
+        else if (name == "GetTexture")
+        {
+            mLegacyHttpUrl = url;
+        }
+    }
 }
 
 void LLViewerRegion::setCapabilityDebug(const std::string& name, const std::string& url)
 {
-	// Continue to not add certain caps, as we do in setCapability. This is so they match up when we check them later.
-	if ( ! ( name == "EventQueueGet" || name == "UntrustedSimulatorMessage" || name == "SimulatorFeatures" ) )
-	{
-		mImpl->mSecondCapabilitiesTracker[name] = url;
-		if(name == "ViewerAsset")
-		{
-			/*==============================================================*/
-			// The following inserted lines are a hack for testing MAINT-7081,
-			// which is why the indentation and formatting are left ugly.
-			const char* VIEWERASSET = getenv("VIEWERASSET");
-			if (VIEWERASSET)
-			{
-				mImpl->mSecondCapabilitiesTracker[name] = VIEWERASSET;
-				mViewerAssetUrl = VIEWERASSET;
-			}
-			else
-			{
-				mViewerAssetUrl = url;
-			}
-			/*==============================================================*/
-		}
-		else if (name == "GetTexture")
-		{
-			mLegacyHttpUrl = url;
-		}
-	}
+    // Continue to not add certain caps, as we do in setCapability. This is so they match up when we check them later.
+    if ( ! ( name == "EventQueueGet" || name == "UntrustedSimulatorMessage" || name == "SimulatorFeatures" ) )
+    {
+        mImpl->mSecondCapabilitiesTracker[name] = url;
+        if(name == "ViewerAsset")
+        {
+            /*==============================================================*/
+            // The following inserted lines are a hack for testing MAINT-7081,
+            // which is why the indentation and formatting are left ugly.
+            const char* VIEWERASSET = getenv("VIEWERASSET");
+            if (VIEWERASSET)
+            {
+                mImpl->mSecondCapabilitiesTracker[name] = VIEWERASSET;
+                mViewerAssetUrl = VIEWERASSET;
+            }
+            else
+            {
+                mViewerAssetUrl = url;
+            }
+            /*==============================================================*/
+        }
+        else if (name == "GetTexture")
+        {
+            mLegacyHttpUrl = url;
+        }
+    }
 }
 
 const std::string& LLViewerRegion::getCapabilityDebug(std::string_view name) const
@@ -3655,77 +3655,77 @@ const std::string& LLViewerRegion::getCapabilityDebug(std::string_view name) con
 
 bool LLViewerRegion::isSpecialCapabilityName(std::string_view name)
 {
-	return name == "EventQueueGet" || name == "UntrustedSimulatorMessage";
+    return name == "EventQueueGet" || name == "UntrustedSimulatorMessage";
 }
 
 const std::string& LLViewerRegion::getCapability(std::string_view name) const
 {
-	using namespace std::string_view_literals;
-	if (!capabilitiesReceived() && (name != "Seed"sv) && (name != "ObjectMedia"sv))
-	{
-		LL_WARNS() << "getCapability called before caps received for " << name << LL_ENDL;
-	}
-	
-	CapabilityMap::const_iterator iter = mImpl->mCapabilities.find(name);
-	if(iter == mImpl->mCapabilities.end())
-	{
-		return LLStringUtil::null;
-	}
+    using namespace std::string_view_literals;
+    if (!capabilitiesReceived() && (name != "Seed"sv) && (name != "ObjectMedia"sv))
+    {
+        LL_WARNS() << "getCapability called before caps received for " << name << LL_ENDL;
+    }
+
+    CapabilityMap::const_iterator iter = mImpl->mCapabilities.find(name);
+    if(iter == mImpl->mCapabilities.end())
+    {
+        return LLStringUtil::null;
+    }
 
-	return iter->second;
+    return iter->second;
 }
 
 bool LLViewerRegion::isCapabilityAvailable(std::string_view name) const
 {
-	using namespace std::string_view_literals;
+    using namespace std::string_view_literals;
     if (!capabilitiesReceived() && (name != "Seed"sv) && (name != "ObjectMedia"sv))
-	{
-		LL_WARNS() << "isCapabilityAvailable called before caps received for " << name << LL_ENDL;
-	}
-	
-	CapabilityMap::const_iterator iter = mImpl->mCapabilities.find(name);
-	if(iter == mImpl->mCapabilities.end())
-	{
-		return false;
-	}
+    {
+        LL_WARNS() << "isCapabilityAvailable called before caps received for " << name << LL_ENDL;
+    }
+
+    CapabilityMap::const_iterator iter = mImpl->mCapabilities.find(name);
+    if(iter == mImpl->mCapabilities.end())
+    {
+        return false;
+    }
 
-	return true;
+    return true;
 }
 
 std::set<std::string> LLViewerRegion::getCapURLNames(const std::string &cap_url)
 {
-	std::set<std::string> url_capnames;
-	if(mCapURLMappings.count(cap_url) > 0)
-	{
-		auto range = mCapURLMappings.equal_range(cap_url);
+    std::set<std::string> url_capnames;
+    if(mCapURLMappings.count(cap_url) > 0)
+    {
+        auto range = mCapURLMappings.equal_range(cap_url);
 
-		for (url_mapping_t::iterator iter = range.first; iter != range.second; ++iter)
-		{
-			url_capnames.insert(iter->second);
-		}
-	}
-	return url_capnames;
+        for (url_mapping_t::iterator iter = range.first; iter != range.second; ++iter)
+        {
+            url_capnames.insert(iter->second);
+        }
+    }
+    return url_capnames;
 }
 
 
 bool LLViewerRegion::isCapURLMapped(const std::string &cap_url)
 {
-	return (mCapURLMappings.count(cap_url) > 0);
+    return (mCapURLMappings.count(cap_url) > 0);
 }
 
 std::set<std::string> LLViewerRegion::getAllCaps()
 {
-	std::set<std::string> url_capnames;
-	for (auto& capability : mImpl->mCapabilities)
+    std::set<std::string> url_capnames;
+    for (auto& capability : mImpl->mCapabilities)
     {
-		url_capnames.insert(capability.first);
-	}
-	return url_capnames;
+        url_capnames.insert(capability.first);
+    }
+    return url_capnames;
 }
 
 bool LLViewerRegion::capabilitiesReceived() const
 {
-	return mCapabilitiesState == CAPABILITIES_STATE_RECEIVED;
+    return mCapabilitiesState == CAPABILITIES_STATE_RECEIVED;
 }
 
 bool LLViewerRegion::capabilitiesError() const
@@ -3735,22 +3735,22 @@ bool LLViewerRegion::capabilitiesError() const
 
 void LLViewerRegion::setCapabilitiesReceived(bool received)
 {
-	mCapabilitiesState = received ? CAPABILITIES_STATE_RECEIVED : CAPABILITIES_STATE_INIT;
+    mCapabilitiesState = received ? CAPABILITIES_STATE_RECEIVED : CAPABILITIES_STATE_INIT;
 
-	// Tell interested parties that we've received capabilities,
-	// so that they can safely use getCapability().
-	if (received)
-	{
-		mCapabilitiesReceivedSignal(getRegionID(), this);
+    // Tell interested parties that we've received capabilities,
+    // so that they can safely use getCapability().
+    if (received)
+    {
+        mCapabilitiesReceivedSignal(getRegionID(), this);
 
-		LLFloaterPermsDefault::sendInitialPerms();
+        LLFloaterPermsDefault::sendInitialPerms();
 
-		// This is a single-shot signal. Forget callbacks to save resources.
-		mCapabilitiesReceivedSignal.disconnect_all_slots();
+        // This is a single-shot signal. Forget callbacks to save resources.
+        mCapabilitiesReceivedSignal.disconnect_all_slots();
 
-		// Set the region to the desired interest list mode
+        // Set the region to the desired interest list mode
         setInterestListMode(gAgent.getInterestListMode());
-	}
+    }
 }
 
 void LLViewerRegion::setCapabilitiesError()
@@ -3760,12 +3760,12 @@ void LLViewerRegion::setCapabilitiesError()
 
 boost::signals2::connection LLViewerRegion::setCapabilitiesReceivedCallback(const caps_received_signal_t::slot_type& cb)
 {
-	return mCapabilitiesReceivedSignal.connect(cb);
+    return mCapabilitiesReceivedSignal.connect(cb);
 }
 
 void LLViewerRegion::logActiveCapabilities() const
 {
-	log_capabilities(mImpl->mCapabilities);
+    log_capabilities(mImpl->mCapabilities);
 }
 
 
@@ -3776,7 +3776,7 @@ bool LLViewerRegion::requestPostCapability(const std::string &capName, LLSD &pos
     if (url.empty())
     {
         LL_WARNS("Region") << "Could not retrieve region " << getRegionID()
-			<< " POST capability \"" << capName << "\"" << LL_ENDL;
+            << " POST capability \"" << capName << "\"" << LL_ENDL;
         return false;
     }
 
@@ -3823,14 +3823,14 @@ void LLViewerRegion::setInterestListMode(const std::string &new_mode)
     {
         mInterestListMode = new_mode;
 
-		if (mInterestListMode != std::string(IL_MODE_DEFAULT) && mInterestListMode != std::string(IL_MODE_360))
-		{
-			LL_WARNS("360Capture") << "Region " << getRegionID() << " setInterestListMode() invalid interest list mode: " 
-				<< mInterestListMode << ", setting to default" << LL_ENDL;
+        if (mInterestListMode != std::string(IL_MODE_DEFAULT) && mInterestListMode != std::string(IL_MODE_360))
+        {
+            LL_WARNS("360Capture") << "Region " << getRegionID() << " setInterestListMode() invalid interest list mode: "
+                << mInterestListMode << ", setting to default" << LL_ENDL;
             mInterestListMode = IL_MODE_DEFAULT;
-		}
+        }
 
-		LLSD body;
+        LLSD body;
         body["mode"] = mInterestListMode;
         if (requestPostCapability("InterestList", body,
                                   [](const LLSD &response) {
@@ -3844,99 +3844,99 @@ void LLViewerRegion::setInterestListMode(const std::string &new_mode)
         }
         else
         {
-            LL_WARNS("360Capture") << "Region " << getRegionID() 
-								   << " Unable to post an InterestList capability request with payload: \n"
+            LL_WARNS("360Capture") << "Region " << getRegionID()
+                                   << " Unable to post an InterestList capability request with payload: \n"
                                    << ll_pretty_print_sd(body) << LL_ENDL;
         }
     }
     else
     {
         LL_DEBUGS("360Capture") << "Region " << getRegionID() << "No change, skipping Interest List mode POST to "
-								<< new_mode << " mode" << LL_ENDL;
+                                << new_mode << " mode" << LL_ENDL;
     }
 }
 
 
 void LLViewerRegion::resetInterestList()
 {
-	if (requestDelCapability("InterestList", [](const LLSD &response) {
-							LL_DEBUGS("360Capture") << "InterestList capability DEL responded: \n" << ll_pretty_print_sd(response) << LL_ENDL;
-						}))
-	{
-		LL_DEBUGS("360Capture") << "Region " << getRegionID() << " Successfully reset InterestList capability" << LL_ENDL;
-	}
-	else
-	{
-		LL_WARNS("360Capture") << "Region " << getRegionID() << " Unable to DEL InterestList capability request" << LL_ENDL;
-	}
+    if (requestDelCapability("InterestList", [](const LLSD &response) {
+                            LL_DEBUGS("360Capture") << "InterestList capability DEL responded: \n" << ll_pretty_print_sd(response) << LL_ENDL;
+                        }))
+    {
+        LL_DEBUGS("360Capture") << "Region " << getRegionID() << " Successfully reset InterestList capability" << LL_ENDL;
+    }
+    else
+    {
+        LL_WARNS("360Capture") << "Region " << getRegionID() << " Unable to DEL InterestList capability request" << LL_ENDL;
+    }
 }
 
 
 LLSpatialPartition *LLViewerRegion::getSpatialPartition(U32 type)
 {
-	if (type < mImpl->mObjectPartition.size() && type < PARTITION_VO_CACHE)
-	{
-		return (LLSpatialPartition*)mImpl->mObjectPartition[type];
-	}
-	return NULL;
+    if (type < mImpl->mObjectPartition.size() && type < PARTITION_VO_CACHE)
+    {
+        return (LLSpatialPartition*)mImpl->mObjectPartition[type];
+    }
+    return NULL;
 }
 
 LLVOCachePartition* LLViewerRegion::getVOCachePartition()
 {
-	if(PARTITION_VO_CACHE < mImpl->mObjectPartition.size())
-	{
-		return (LLVOCachePartition*)mImpl->mObjectPartition[PARTITION_VO_CACHE];
-	}
-	return NULL;
+    if(PARTITION_VO_CACHE < mImpl->mObjectPartition.size())
+    {
+        return (LLVOCachePartition*)mImpl->mObjectPartition[PARTITION_VO_CACHE];
+    }
+    return NULL;
 }
 
 // the viewer can not yet distinquish between normal- and estate-owned objects
 // so we collapse these two bits and enable the UI if either are set
 const U64 ALLOW_RETURN_ENCROACHING_OBJECT = REGION_FLAGS_ALLOW_RETURN_ENCROACHING_OBJECT
-											| REGION_FLAGS_ALLOW_RETURN_ENCROACHING_ESTATE_OBJECT;
+                                            | REGION_FLAGS_ALLOW_RETURN_ENCROACHING_ESTATE_OBJECT;
 
 bool LLViewerRegion::objectIsReturnable(const LLVector3& pos, const std::vector<LLBBox>& boxes) const
 {
-	return (mParcelOverlay != NULL)
-		&& (mParcelOverlay->isOwnedSelf(pos)
-			|| mParcelOverlay->isOwnedGroup(pos)
-			|| (getRegionFlag(ALLOW_RETURN_ENCROACHING_OBJECT)
-				&& mParcelOverlay->encroachesOwned(boxes)) );
+    return (mParcelOverlay != NULL)
+        && (mParcelOverlay->isOwnedSelf(pos)
+            || mParcelOverlay->isOwnedGroup(pos)
+            || (getRegionFlag(ALLOW_RETURN_ENCROACHING_OBJECT)
+                && mParcelOverlay->encroachesOwned(boxes)) );
 }
 
 bool LLViewerRegion::childrenObjectReturnable( const std::vector<LLBBox>& boxes ) const
 {
-	bool result = false;
-	result = ( mParcelOverlay && mParcelOverlay->encroachesOnUnowned( boxes ) ) ? 1 : 0;
-	return result;
+    bool result = false;
+    result = ( mParcelOverlay && mParcelOverlay->encroachesOnUnowned( boxes ) ) ? 1 : 0;
+    return result;
 }
 
 bool LLViewerRegion::objectsCrossParcel(const std::vector<LLBBox>& boxes) const
 {
-	return mParcelOverlay && mParcelOverlay->encroachesOnNearbyParcel(boxes);
+    return mParcelOverlay && mParcelOverlay->encroachesOnNearbyParcel(boxes);
 }
 
 void LLViewerRegion::getNeighboringRegions( std::vector<LLViewerRegion*>& uniqueRegions )
 {
-	mImpl->mLandp->getNeighboringRegions( uniqueRegions );
+    mImpl->mLandp->getNeighboringRegions( uniqueRegions );
 }
 void LLViewerRegion::getNeighboringRegionsStatus( std::vector<S32>& regions )
 {
-	mImpl->mLandp->getNeighboringRegionsStatus( regions );
+    mImpl->mLandp->getNeighboringRegionsStatus( regions );
 }
 void LLViewerRegion::showReleaseNotes()
 {
-	std::string url = this->getCapability("ServerReleaseNotes");
+    std::string url = this->getCapability("ServerReleaseNotes");
 
-	if (url.empty()) {
-		// HACK haven't received the capability yet, we'll wait until
-		// it arives.
-		mReleaseNotesRequested = TRUE;
-		return;
-	}
+    if (url.empty()) {
+        // HACK haven't received the capability yet, we'll wait until
+        // it arives.
+        mReleaseNotesRequested = TRUE;
+        return;
+    }
 
-	LLWeb::loadURL(url);
-	mReleaseNotesRequested = FALSE;
+    LLWeb::loadURL(url);
+    mReleaseNotesRequested = FALSE;
 }
 
 std::string LLViewerRegion::getDescription() const
@@ -3946,92 +3946,92 @@ std::string LLViewerRegion::getDescription() const
 
 bool LLViewerRegion::meshUploadEnabled() const
 {
-	return mMeshUploadEnabled;
+    return mMeshUploadEnabled;
 }
 
 bool LLViewerRegion::bakesOnMeshEnabled() const
 {
-	return mBakesOnMeshEnabled;
+    return mBakesOnMeshEnabled;
 }
 
 bool LLViewerRegion::meshRezEnabled() const
 {
-	return mMeshRezEnabled;
+    return mMeshRezEnabled;
 }
 
 bool LLViewerRegion::dynamicPathfindingEnabled() const
 {
-	return mDynamicPathfindingEnabled;
+    return mDynamicPathfindingEnabled;
 }
 
 bool LLViewerRegion::avatarHoverHeightEnabled() const
 {
-	return mAvatarHoverHeightEnabled;
+    return mAvatarHoverHeightEnabled;
 }
 /* Static Functions */
 
 void log_capabilities(const CapabilityMap &capmap)
 {
-	S32 count = 0;
-	CapabilityMap::const_iterator iter;
-	for (iter = capmap.begin(); iter != capmap.end(); ++iter, ++count)
-	{
-		if (!iter->second.empty())
-		{
-			LL_INFOS() << "log_capabilities: " << iter->first << " URL is " << iter->second << LL_ENDL;
-		}
-	}
-	LL_INFOS() << "log_capabilities: Dumped " << count << " entries." << LL_ENDL;
+    S32 count = 0;
+    CapabilityMap::const_iterator iter;
+    for (iter = capmap.begin(); iter != capmap.end(); ++iter, ++count)
+    {
+        if (!iter->second.empty())
+        {
+            LL_INFOS() << "log_capabilities: " << iter->first << " URL is " << iter->second << LL_ENDL;
+        }
+    }
+    LL_INFOS() << "log_capabilities: Dumped " << count << " entries." << LL_ENDL;
 }
 void LLViewerRegion::resetMaterialsCapThrottle()
 {
-	F32 requests_per_sec = 	1.0f; // original default;
-	if (   mSimulatorFeatures.has("RenderMaterialsCapability")
-		&& mSimulatorFeatures["RenderMaterialsCapability"].isReal() )
-	{
-		requests_per_sec = mSimulatorFeatures["RenderMaterialsCapability"].asReal();
-		if ( requests_per_sec == 0.0f )
-		{
-			requests_per_sec = 1.0f;
-			LL_WARNS("Materials")
-				<< "region '" << getName()
-				<< "' returned zero for RenderMaterialsCapability; using default "
-				<< requests_per_sec << " per second"
-				<< LL_ENDL;
-		}
-		LL_DEBUGS("Materials") << "region '" << getName()
-							   << "' RenderMaterialsCapability " << requests_per_sec
-							   << LL_ENDL;
-	}
-	else
-	{
-		LL_DEBUGS("Materials")
-			<< "region '" << getName()
-			<< "' did not return RenderMaterialsCapability, using default "
-			<< requests_per_sec << " per second"
-			<< LL_ENDL;
-	}
-	
-	mMaterialsCapThrottleTimer.resetWithExpiry( 1.0f / requests_per_sec );
+    F32 requests_per_sec =  1.0f; // original default;
+    if (   mSimulatorFeatures.has("RenderMaterialsCapability")
+        && mSimulatorFeatures["RenderMaterialsCapability"].isReal() )
+    {
+        requests_per_sec = mSimulatorFeatures["RenderMaterialsCapability"].asReal();
+        if ( requests_per_sec == 0.0f )
+        {
+            requests_per_sec = 1.0f;
+            LL_WARNS("Materials")
+                << "region '" << getName()
+                << "' returned zero for RenderMaterialsCapability; using default "
+                << requests_per_sec << " per second"
+                << LL_ENDL;
+        }
+        LL_DEBUGS("Materials") << "region '" << getName()
+                               << "' RenderMaterialsCapability " << requests_per_sec
+                               << LL_ENDL;
+    }
+    else
+    {
+        LL_DEBUGS("Materials")
+            << "region '" << getName()
+            << "' did not return RenderMaterialsCapability, using default "
+            << requests_per_sec << " per second"
+            << LL_ENDL;
+    }
+
+    mMaterialsCapThrottleTimer.resetWithExpiry( 1.0f / requests_per_sec );
 }
 
 U32 LLViewerRegion::getMaxMaterialsPerTransaction() const
 {
-	U32 max_entries = 50; // original hard coded default
-	if (mMaxMaterialsPerTrans != 0)
-	{
-		max_entries = mMaxMaterialsPerTrans;
-	}
-	return max_entries;
+    U32 max_entries = 50; // original hard coded default
+    if (mMaxMaterialsPerTrans != 0)
+    {
+        max_entries = mMaxMaterialsPerTrans;
+    }
+    return max_entries;
 }
 
 std::string LLViewerRegion::getSimHostName()
 {
-	if (mSimulatorFeaturesReceived)
-	{
-		return mSimulatorFeatures.has("HostName") ? mSimulatorFeatures["HostName"].asString() : getHost().getHostName();
-	}
-	return std::string("...");
+    if (mSimulatorFeaturesReceived)
+    {
+        return mSimulatorFeatures.has("HostName") ? mSimulatorFeatures["HostName"].asString() : getHost().getHostName();
+    }
+    return std::string("...");
 }
 
 void LLViewerRegion::applyCacheMiscExtras(LLViewerObject* obj)
@@ -4059,143 +4059,143 @@ void LLViewerRegion::applyCacheMiscExtras(LLViewerObject* obj)
 
 bool LLViewerRegion::getRegionAllowsExport() const
 {
-	if (mSimulatorFeatures.has("OpenSimExtras")
-		&& mSimulatorFeatures["OpenSimExtras"].has("ExportSupported"))
-	{
-		return mSimulatorFeatures["OpenSimExtras"]["ExportSupported"].asBoolean() || mSimulatorFeatures["OpenSimExtras"]["ExportSupported"].asString() == "true";
-	}
-	return false;
+    if (mSimulatorFeatures.has("OpenSimExtras")
+        && mSimulatorFeatures["OpenSimExtras"].has("ExportSupported"))
+    {
+        return mSimulatorFeatures["OpenSimExtras"]["ExportSupported"].asBoolean() || mSimulatorFeatures["OpenSimExtras"]["ExportSupported"].asString() == "true";
+    }
+    return false;
 }
 
 std::string LLViewerRegion::getAvatarPickerURL() const
 {
-	std::string url;
-	if (mSimulatorFeatures.has("OpenSimExtras")
-		&& mSimulatorFeatures["OpenSimExtras"].has("avatar-picker-url"))
-	{
-		url = mSimulatorFeatures["OpenSimExtras"]["avatar-picker-url"].asString();
-	}
-	else if (LLLoginInstance::getInstance()->hasResponse("avatar_picker_url"))
-	{
-		url = LLLoginInstance::getInstance()->getResponse("avatar_picker_url").asString();
-	}
-	else if (LLGridManager::getInstance()->isInSecondlife())
-	{
-		url = gSavedSettings.getString("AvatarPickerURL");
-	}
-	return url;
+    std::string url;
+    if (mSimulatorFeatures.has("OpenSimExtras")
+        && mSimulatorFeatures["OpenSimExtras"].has("avatar-picker-url"))
+    {
+        url = mSimulatorFeatures["OpenSimExtras"]["avatar-picker-url"].asString();
+    }
+    else if (LLLoginInstance::getInstance()->hasResponse("avatar_picker_url"))
+    {
+        url = LLLoginInstance::getInstance()->getResponse("avatar_picker_url").asString();
+    }
+    else if (LLGridManager::getInstance()->isInSecondlife())
+    {
+        url = gSavedSettings.getString("AvatarPickerURL");
+    }
+    return url;
 }
 
 std::string LLViewerRegion::getDestinationGuideURL() const
 {
-	std::string url;
-	if (mSimulatorFeatures.has("OpenSimExtras")
-		&& mSimulatorFeatures["OpenSimExtras"].has("destination-guide-url"))
-	{
-		url = mSimulatorFeatures["OpenSimExtras"]["destination-guide-url"].asString();
-	}
-	else if (LLLoginInstance::getInstance()->hasResponse("destination_guide_url"))
-	{
-		url = LLLoginInstance::getInstance()->getResponse("destination_guide_url").asString();
-	}
-	else if (LLGridManager::getInstance()->isInSecondlife())
-	{
-		url = gSavedSettings.getString("DestinationGuideURL");
-	}
-	return url;
+    std::string url;
+    if (mSimulatorFeatures.has("OpenSimExtras")
+        && mSimulatorFeatures["OpenSimExtras"].has("destination-guide-url"))
+    {
+        url = mSimulatorFeatures["OpenSimExtras"]["destination-guide-url"].asString();
+    }
+    else if (LLLoginInstance::getInstance()->hasResponse("destination_guide_url"))
+    {
+        url = LLLoginInstance::getInstance()->getResponse("destination_guide_url").asString();
+    }
+    else if (LLGridManager::getInstance()->isInSecondlife())
+    {
+        url = gSavedSettings.getString("DestinationGuideURL");
+    }
+    return url;
 }
 
 std::string LLViewerRegion::getMapServerURL() const
 {
-	if (!mHGMapServerURL.empty())
-	{
-		return mHGMapServerURL;
-	}
-	else
-	{
-		static const LLCachedControl<std::string> map_server_url(gSavedSettings, "CurrentMapServerURL");
-		return map_server_url();
-	}
+    if (!mHGMapServerURL.empty())
+    {
+        return mHGMapServerURL;
+    }
+    else
+    {
+        static const LLCachedControl<std::string> map_server_url(gSavedSettings, "CurrentMapServerURL");
+        return map_server_url();
+    }
 }
 
 std::string LLViewerRegion::getSearchServerURL() const
 {
-	std::string url;
-	// Check the region it trumps the grid
-	if (mSimulatorFeatures.has("OpenSimExtras")
-		&& mSimulatorFeatures["OpenSimExtras"].has("search-server-url"))
-	{
-		url = mSimulatorFeatures["OpenSimExtras"]["search-server-url"].asString();
-	}
-	// Check the login message
-	else if (LLLoginInstance::getInstance()->hasResponse("search"))
-	{
-		url = LLLoginInstance::getInstance()->getResponse("search").asString();
-	}
-	// If all else fails, fall back to defaults
-	else
-	{
-		url = gSavedSettings.getString(LLGridManager::getInstance()->isInOpenSim() ? "OpenSimSearchURL" : "SearchURL");
-	}
-	return url;
+    std::string url;
+    // Check the region it trumps the grid
+    if (mSimulatorFeatures.has("OpenSimExtras")
+        && mSimulatorFeatures["OpenSimExtras"].has("search-server-url"))
+    {
+        url = mSimulatorFeatures["OpenSimExtras"]["search-server-url"].asString();
+    }
+    // Check the login message
+    else if (LLLoginInstance::getInstance()->hasResponse("search"))
+    {
+        url = LLLoginInstance::getInstance()->getResponse("search").asString();
+    }
+    // If all else fails, fall back to defaults
+    else
+    {
+        url = gSavedSettings.getString(LLGridManager::getInstance()->isInOpenSim() ? "OpenSimSearchURL" : "SearchURL");
+    }
+    return url;
 }
 
 std::string LLViewerRegion::getBuyCurrencyServerURL() const
 {
-	std::string url = LLGridManager::getInstance()->getHelperURI() + "currency.php";
-	// If we have the feature, override grid default.
-	if (mSimulatorFeatures.has("OpenSimExtras")
-		&& mSimulatorFeatures["OpenSimExtras"].has("currency-base-uri"))
-	{
-		url = mSimulatorFeatures["OpenSimExtras"]["currency-base-uri"].asString();
-	}
-	return url;
+    std::string url = LLGridManager::getInstance()->getHelperURI() + "currency.php";
+    // If we have the feature, override grid default.
+    if (mSimulatorFeatures.has("OpenSimExtras")
+        && mSimulatorFeatures["OpenSimExtras"].has("currency-base-uri"))
+    {
+        url = mSimulatorFeatures["OpenSimExtras"]["currency-base-uri"].asString();
+    }
+    return url;
 }
 
 std::string LLViewerRegion::getHGGrid() const
 {
-	std::string authority;
-	if (!mHGGridURL.empty())
-	{
-		authority = LLURI(mHGGridURL).authority();
-	}
-	else
-	{
-		authority = LLGridManager::getInstance()->getGatekeeper(LLGridManager::getInstance()->getGrid());
-	}
-	return authority;
+    std::string authority;
+    if (!mHGGridURL.empty())
+    {
+        authority = LLURI(mHGGridURL).authority();
+    }
+    else
+    {
+        authority = LLGridManager::getInstance()->getGatekeeper(LLGridManager::getInstance()->getGrid());
+    }
+    return authority;
 }
 
 std::string LLViewerRegion::getHGGridName() const
 {
-	std::string name;
-	if (!mHGGridName.empty())
-	{
-		name = mHGGridName;
-	}
-	else if (!mHGGridURL.empty())
-	{
-		name = LLURI(mHGGridURL).authority();
-	}
-	else
-	{
-		name = LLGridManager::getInstance()->getGridLabel();
-	}
-	return name;
+    std::string name;
+    if (!mHGGridName.empty())
+    {
+        name = mHGGridName;
+    }
+    else if (!mHGGridURL.empty())
+    {
+        name = LLURI(mHGGridURL).authority();
+    }
+    else
+    {
+        name = LLGridManager::getInstance()->getGridLabel();
+    }
+    return name;
 }
 
 std::string LLViewerRegion::getHGGridNick() const
 {
-	std::string name;
-	if (!mHGGridNick.empty())
-	{
-		name = mHGGridNick;
-	}
-	else
-	{
-		name = LLGridManager::getInstance()->getGridId();
-	}
-	return name;
+    std::string name;
+    if (!mHGGridNick.empty())
+    {
+        name = mHGGridNick;
+    }
+    else
+    {
+        name = LLGridManager::getInstance()->getGridId();
+    }
+    return name;
 }
 
 U32 LLViewerRegion::getChatRange() const
@@ -4215,84 +4215,84 @@ U32 LLViewerRegion::getWhisperRange() const
 
 F32 LLViewerRegion::getMinPrimScale() const
 {
-	return mMinPrimScale;
+    return mMinPrimScale;
 }
 
 F32 LLViewerRegion::getMaxPrimScale() const
 {
-	return mMaxPrimScale;
+    return mMaxPrimScale;
 }
 
 F32 LLViewerRegion::getMinPhysPrimScale() const
 {
-	return mMinPhysPrimScale;
+    return mMinPhysPrimScale;
 }
 
 F32 LLViewerRegion::getMaxPhysPrimScale() const
 {
-	return mMaxPhysPrimScale;
+    return mMaxPhysPrimScale;
 }
 
 F32 LLViewerRegion::getMinRegionHeight() const
 {
-	return mMinSimHeight;
+    return mMinSimHeight;
 }
 
 F32 LLViewerRegion::getMaxRegionHeight() const
 {
-	return mMaxSimHeight;
+    return mMaxSimHeight;
 }
 
 void LLViewerRegion::setGodnames()
 {
-	mGodNames.clear();
-	if (mSimulatorFeatures.has("god_names"))
-	{
-		if (mSimulatorFeatures["god_names"].has("full_names"))
-		{
-			LLSD god_names = mSimulatorFeatures["god_names"]["full_names"];
-			for (LLSD::array_const_iterator itr = god_names.beginArray(),
-				ite = god_names.endArray();
-				 itr != ite;
-				 ++itr)
-			{
-				mGodNames.insert((*itr).asString());
-			}
-		}
-		if (mSimulatorFeatures["god_names"].has("last_names"))
-		{
-			LLSD god_names = mSimulatorFeatures["god_names"]["last_names"];
-			for (LLSD::array_const_iterator itr = god_names.beginArray(), ite = god_names.endArray();
-				 itr != ite;
-				 ++itr)
-			{
-				mGodNames.insert((*itr).asString());
-			}
-		}
-	}
+    mGodNames.clear();
+    if (mSimulatorFeatures.has("god_names"))
+    {
+        if (mSimulatorFeatures["god_names"].has("full_names"))
+        {
+            LLSD god_names = mSimulatorFeatures["god_names"]["full_names"];
+            for (LLSD::array_const_iterator itr = god_names.beginArray(),
+                ite = god_names.endArray();
+                 itr != ite;
+                 ++itr)
+            {
+                mGodNames.insert((*itr).asString());
+            }
+        }
+        if (mSimulatorFeatures["god_names"].has("last_names"))
+        {
+            LLSD god_names = mSimulatorFeatures["god_names"]["last_names"];
+            for (LLSD::array_const_iterator itr = god_names.beginArray(), ite = god_names.endArray();
+                 itr != ite;
+                 ++itr)
+            {
+                mGodNames.insert((*itr).asString());
+            }
+        }
+    }
 }
 
 const LLViewerRegion::tex_matrix_t& LLViewerRegion::getWorldMapTiles() const
 {
-	if (mWorldMapTiles.empty())
-	{
-		U32 gridX, gridY;
-		grid_from_region_handle(mHandle, &gridX, &gridY);
-		U32 totalX(getWidth() / REGION_WIDTH_U32);
-		if (!totalX) ++totalX; // If this region is too small, still get an image.
-		// *TODO: Non-square regions?
-		//U32 totalY(getLength()/REGION_WIDTH_U32);
-		//if (!totalY) ++totalY; // If this region is too small, still get an image.
-		const U32 totalY(totalX);
-		mWorldMapTiles.reserve(totalX * totalY);
-		for (U32 x = 0; x != totalX; ++x)
-			for (U32 y = 0; y != totalY; ++y)
-			{
-				const std::string map_url = getMapServerURL().append(llformat("map-1-%d-%d-objects.jpg", gridX + x, gridY + y));
-				LLPointer<LLViewerTexture> tex(LLViewerTextureManager::getFetchedTextureFromUrl(map_url, FTT_MAP_TILE, TRUE,
-											   LLViewerTexture::BOOST_MAP, LLViewerTexture::LOD_TEXTURE));
-				mWorldMapTiles.push_back(tex);
-			}
-	}
-	return mWorldMapTiles;
+    if (mWorldMapTiles.empty())
+    {
+        U32 gridX, gridY;
+        grid_from_region_handle(mHandle, &gridX, &gridY);
+        U32 totalX(getWidth() / REGION_WIDTH_U32);
+        if (!totalX) ++totalX; // If this region is too small, still get an image.
+        // *TODO: Non-square regions?
+        //U32 totalY(getLength()/REGION_WIDTH_U32);
+        //if (!totalY) ++totalY; // If this region is too small, still get an image.
+        const U32 totalY(totalX);
+        mWorldMapTiles.reserve(totalX * totalY);
+        for (U32 x = 0; x != totalX; ++x)
+            for (U32 y = 0; y != totalY; ++y)
+            {
+                const std::string map_url = getMapServerURL().append(llformat("map-1-%d-%d-objects.jpg", gridX + x, gridY + y));
+                LLPointer<LLViewerTexture> tex(LLViewerTextureManager::getFetchedTextureFromUrl(map_url, FTT_MAP_TILE, TRUE,
+                                               LLViewerTexture::BOOST_MAP, LLViewerTexture::LOD_TEXTURE));
+                mWorldMapTiles.push_back(tex);
+            }
+    }
+    return mWorldMapTiles;
 }
diff --git a/indra/newview/llviewerregion.h b/indra/newview/llviewerregion.h
index cfc98072cb8f4ec571f811b18252af15ace1d21e..37ed28dfda9cf2727aaa7ddfcdef339db0bb2e32 100644
--- a/indra/newview/llviewerregion.h
+++ b/indra/newview/llviewerregion.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewerregion.h
  * @brief Description of the LLViewerRegion class.
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -42,7 +42,7 @@
 #include "lluuid.h"
 #include "llweb.h"
 #include "llcapabilityprovider.h"
-#include "m4math.h"					// LLMatrix4
+#include "m4math.h"                 // LLMatrix4
 #include "llframetimer.h"
 #include "llreflectionmap.h"
 #include "lleasymessagesender.h"
@@ -50,7 +50,7 @@
 // Surface id's
 #define LAND  1
 #define WATER 2
-const U32	MAX_OBJECT_CACHE_ENTRIES = 50000;
+const U32   MAX_OBJECT_CACHE_ENTRIES = 50000;
 
 // Region handshake flags
 const U32 REGION_HANDSHAKE_SUPPORTS_SELF_APPEARANCE = 1U << 2;
@@ -81,219 +81,219 @@ class LLVOCachePartition;
 class LLViewerRegion final : public LLCapabilityProvider // implements this interface
 {
 public:
-	//MUST MATCH THE ORDER OF DECLARATION IN CONSTRUCTOR
-	typedef enum 
-	{
-		PARTITION_HUD=0,
-		PARTITION_TERRAIN,
-		PARTITION_VOIDWATER,
-		PARTITION_WATER,
-		PARTITION_TREE,
-		PARTITION_PARTICLE,
-		PARTITION_GRASS,
-		PARTITION_VOLUME,
-		PARTITION_BRIDGE,
-		PARTITION_AVATAR,
-		PARTITION_CONTROL_AV, // Animesh
-		PARTITION_HUD_PARTICLE,
-		PARTITION_VO_CACHE,
-		PARTITION_NONE,
-		NUM_PARTITIONS
-	} eObjectPartitions;
-
-	typedef boost::signals2::signal<void(const LLUUID& region_id, LLViewerRegion* regionp)> caps_received_signal_t;
-
-	LLViewerRegion(const U64 &handle,
-				   const LLHost &host,
-				   const U32 surface_grid_width,
-				   const U32 patch_grid_width,
-				   const F32 region_width_meters);
-	~LLViewerRegion();
-
-	// Call this after you have the region name and handle.
-	void loadObjectCache();
-	void saveObjectCache();
-
-	void sendMessage(); // Send the current message to this region's simulator
-	void sendReliableMessage(); // Send the current message to this region's simulator
-
-	void setOriginGlobal(const LLVector3d &origin);
-	//void setAgentOffset(const LLVector3d &offset);
-	void updateRenderMatrix();
-
-	void setAllowDamage(BOOL b) { setRegionFlag(REGION_FLAGS_ALLOW_DAMAGE, b); }
-	void setAllowLandmark(BOOL b) { setRegionFlag(REGION_FLAGS_ALLOW_LANDMARK, b); }
-	void setAllowSetHome(BOOL b) { setRegionFlag(REGION_FLAGS_ALLOW_SET_HOME, b); }
-	void setResetHomeOnTeleport(BOOL b) { setRegionFlag(REGION_FLAGS_RESET_HOME_ON_TELEPORT, b); }
-	void setSunFixed(BOOL b) { setRegionFlag(REGION_FLAGS_SUN_FIXED, b); }
-	//void setBlockFly(BOOL b) { setRegionFlag(REGION_FLAGS_BLOCK_FLY, b); }		Never used
-	void setAllowDirectTeleport(BOOL b) { setRegionFlag(REGION_FLAGS_ALLOW_DIRECT_TELEPORT, b); }
-
-
-	inline BOOL getAllowDamage()			const;
-	inline BOOL getAllowLandmark()			const;
-	inline BOOL getAllowSetHome()			const;
-	inline BOOL getResetHomeOnTeleport()	const;
-	inline BOOL getSunFixed()				const;
-	inline BOOL getBlockFly()				const;
-	inline BOOL getAllowDirectTeleport()	const;
-	inline BOOL isPrelude()					const;
-	inline BOOL getAllowTerraform() 		const;
-	inline BOOL getRestrictPushObject()		const;
+    //MUST MATCH THE ORDER OF DECLARATION IN CONSTRUCTOR
+    typedef enum
+    {
+        PARTITION_HUD=0,
+        PARTITION_TERRAIN,
+        PARTITION_VOIDWATER,
+        PARTITION_WATER,
+        PARTITION_TREE,
+        PARTITION_PARTICLE,
+        PARTITION_GRASS,
+        PARTITION_VOLUME,
+        PARTITION_BRIDGE,
+        PARTITION_AVATAR,
+        PARTITION_CONTROL_AV, // Animesh
+        PARTITION_HUD_PARTICLE,
+        PARTITION_VO_CACHE,
+        PARTITION_NONE,
+        NUM_PARTITIONS
+    } eObjectPartitions;
+
+    typedef boost::signals2::signal<void(const LLUUID& region_id, LLViewerRegion* regionp)> caps_received_signal_t;
+
+    LLViewerRegion(const U64 &handle,
+                   const LLHost &host,
+                   const U32 surface_grid_width,
+                   const U32 patch_grid_width,
+                   const F32 region_width_meters);
+    ~LLViewerRegion();
+
+    // Call this after you have the region name and handle.
+    void loadObjectCache();
+    void saveObjectCache();
+
+    void sendMessage(); // Send the current message to this region's simulator
+    void sendReliableMessage(); // Send the current message to this region's simulator
+
+    void setOriginGlobal(const LLVector3d &origin);
+    //void setAgentOffset(const LLVector3d &offset);
+    void updateRenderMatrix();
+
+    void setAllowDamage(BOOL b) { setRegionFlag(REGION_FLAGS_ALLOW_DAMAGE, b); }
+    void setAllowLandmark(BOOL b) { setRegionFlag(REGION_FLAGS_ALLOW_LANDMARK, b); }
+    void setAllowSetHome(BOOL b) { setRegionFlag(REGION_FLAGS_ALLOW_SET_HOME, b); }
+    void setResetHomeOnTeleport(BOOL b) { setRegionFlag(REGION_FLAGS_RESET_HOME_ON_TELEPORT, b); }
+    void setSunFixed(BOOL b) { setRegionFlag(REGION_FLAGS_SUN_FIXED, b); }
+    //void setBlockFly(BOOL b) { setRegionFlag(REGION_FLAGS_BLOCK_FLY, b); }        Never used
+    void setAllowDirectTeleport(BOOL b) { setRegionFlag(REGION_FLAGS_ALLOW_DIRECT_TELEPORT, b); }
+
+
+    inline BOOL getAllowDamage()            const;
+    inline BOOL getAllowLandmark()          const;
+    inline BOOL getAllowSetHome()           const;
+    inline BOOL getResetHomeOnTeleport()    const;
+    inline BOOL getSunFixed()               const;
+    inline BOOL getBlockFly()               const;
+    inline BOOL getAllowDirectTeleport()    const;
+    inline BOOL isPrelude()                 const;
+    inline BOOL getAllowTerraform()         const;
+    inline BOOL getRestrictPushObject()     const;
     inline BOOL getAllowEnvironmentOverride()   const;
-	inline BOOL getReleaseNotesRequested()		const;
+    inline BOOL getReleaseNotesRequested()      const;
 
-	bool isAlive(); // can become false if circuit disconnects
+    bool isAlive(); // can become false if circuit disconnects
 
-	void setWaterHeight(F32 water_level);
-	F32 getWaterHeight() const;
+    void setWaterHeight(F32 water_level);
+    F32 getWaterHeight() const;
 
-	BOOL isVoiceEnabled() const;
+    BOOL isVoiceEnabled() const;
 
-	void setBillableFactor(F32 billable_factor) { mBillableFactor = billable_factor; }
-	F32 getBillableFactor() 		const 	{ return mBillableFactor; }
+    void setBillableFactor(F32 billable_factor) { mBillableFactor = billable_factor; }
+    F32 getBillableFactor()         const   { return mBillableFactor; }
 
-	// Maximum number of primitives allowed, regardless of object
-	// bonus factor.
-	U32 getMaxTasks() const { return mMaxTasks; }
-	void setMaxTasks(U32 max_tasks) { mMaxTasks = max_tasks; }
+    // Maximum number of primitives allowed, regardless of object
+    // bonus factor.
+    U32 getMaxTasks() const { return mMaxTasks; }
+    void setMaxTasks(U32 max_tasks) { mMaxTasks = max_tasks; }
 
-	// Draw lines in the dirt showing ownership. Return number of 
-	// vertices drawn.
+    // Draw lines in the dirt showing ownership. Return number of
+    // vertices drawn.
     void renderPropertyLines();
     void renderPropertyLinesOnMinimap(F32 scale_pixels_per_meter, const F32* parcel_outline_color);
 
 
-	// Call this whenever you change the height data in the region.
-	// (Automatically called by LLSurfacePatch's update routine)
-	void dirtyHeights();
+    // Call this whenever you change the height data in the region.
+    // (Automatically called by LLSurfacePatch's update routine)
+    void dirtyHeights();
     // Call this whenever you want to force all terrain to rebuild.
     // (For example, if a global terrain config option has changed)
     void dirtyAllPatches();
 
-	LLViewerParcelOverlay *getParcelOverlay() const
-			{ return mParcelOverlay; }
-
-	inline void setRegionFlag(U64 flag, BOOL on);
-	inline BOOL getRegionFlag(U64 flag) const;
-	void setRegionFlags(U64 flags);
-	U64 getRegionFlags() const					{ return mRegionFlags; }
-
-	inline void setRegionProtocol(U64 protocol, BOOL on);
-	BOOL getRegionProtocol(U64 protocol) const;
-	void setRegionProtocols(U64 protocols)			{ mRegionProtocols = protocols; }
-	U64 getRegionProtocols() const					{ return mRegionProtocols; }
-
-	void setTimeDilation(F32 time_dilation);
-	F32  getTimeDilation() const				{ return mTimeDilation; }
-
-	// Origin height is at zero.
-	const LLVector3d &getOriginGlobal() const;
-	LLVector3 getOriginAgent() const;
-
-	// Center is at the height of the water table.
-	const LLVector3d &getCenterGlobal() const;
-	LLVector3 getCenterAgent() const;
-
-	void setRegionNameAndZone(const std::string& name_and_zone);
-	const std::string& getName() const				{ return mName; }
-	const std::string& getZoning() const			{ return mZoning; }
-
-	void setOwner(const LLUUID& owner_id);
-	const LLUUID& getOwner() const;
-
-	// Is the current agent on the estate manager list for this region?
-	void setIsEstateManager(BOOL b) { mIsEstateManager = b; }
-	BOOL isEstateManager() const { return mIsEstateManager; }
-	BOOL canManageEstate() const;
-
-	void setSimAccess(U8 sim_access)			{ mSimAccess = sim_access; }
-	U8 getSimAccess() const						{ return mSimAccess; }
-	const std::string getSimAccessString() const;
-	
-	// Homestead-related getters; there are no setters as nobody should be
-	// setting them other than the individual message handler which is a member
-	S32 getSimClassID()                    const { return mClassID; }
-	S32 getSimCPURatio()                   const { return mCPURatio; }
-	const std::string& getSimColoName()    const { return mColoName; }
-	const std::string& getSimProductSKU()  const { return mProductSKU; }
-	std::string getLocalizedSimProductName() const;
-
-	// Returns "Sandbox", "Expensive", etc.
-	static std::string regionFlagsToString(U64 flags);
-
-	// Returns translated version of "Mature", "PG", "Adult", etc.
-	static const std::string& accessToString(U8 sim_access);
-
-	// Returns "M", "PG", "A" etc.
-	static std::string accessToShortString(U8 sim_access);
-	static U8          shortStringToAccess(const std::string &sim_access);
-
-	// Return access icon name
-	static std::string getAccessIcon(U8 sim_access);
-	
-	// helper function which just makes sure all interested parties
-	// can process the message.
-	static void processRegionInfo(LLMessageSystem* msg, void**);
-
-	//check if the viewer camera is static
-	static BOOL isViewerCameraStatic();
-	static void calcNewObjectCreationThrottle();
-
-	void setCacheID(const LLUUID& id);
-
-	F32	getWidth() const						{ return mWidth; }
-
-	// regions are expensive to release, this function gradually releases cache from memory
-	static void idleCleanup(F32 max_update_time);
-	F32 getWidthScaleFactor() const				{ return mWidthScaleFactor; } // Scaling for OpenSim VarRegions
-
-	void idleUpdate(F32 max_update_time);
-	void lightIdleUpdate();
-	bool addVisibleGroup(LLViewerOctreeGroup* group);
-	void addVisibleChildCacheEntry(LLVOCacheEntry* parent, LLVOCacheEntry* child);
-	void addActiveCacheEntry(LLVOCacheEntry* entry);
-	void removeActiveCacheEntry(LLVOCacheEntry* entry, LLDrawable* drawablep);	
-	void killCacheEntry(U32 local_id); //physically delete the cache entry	
-
-	// Like idleUpdate, but forces everything to complete regardless of
-	// how long it takes.
-	void forceUpdate();
-
-	void connectNeighbor(LLViewerRegion *neighborp, U32 direction);
-
-	void updateNetStats();
-
-	U32	getPacketsLost() const;
-
-	S32 getHttpResponderID() const;
-
-	// Get/set named capability URLs for this region.
-	void setSeedCapability(const std::string& url);
-	S32 getNumSeedCapRetries();
-	void setCapability(const std::string& name, const std::string& url);
-	void setCapabilityDebug(const std::string& name, const std::string& url);
-	bool isCapabilityAvailable(std::string_view name) const;
-	// implements LLCapabilityProvider
+    LLViewerParcelOverlay *getParcelOverlay() const
+            { return mParcelOverlay; }
+
+    inline void setRegionFlag(U64 flag, BOOL on);
+    inline BOOL getRegionFlag(U64 flag) const;
+    void setRegionFlags(U64 flags);
+    U64 getRegionFlags() const                  { return mRegionFlags; }
+
+    inline void setRegionProtocol(U64 protocol, BOOL on);
+    BOOL getRegionProtocol(U64 protocol) const;
+    void setRegionProtocols(U64 protocols)          { mRegionProtocols = protocols; }
+    U64 getRegionProtocols() const                  { return mRegionProtocols; }
+
+    void setTimeDilation(F32 time_dilation);
+    F32  getTimeDilation() const                { return mTimeDilation; }
+
+    // Origin height is at zero.
+    const LLVector3d &getOriginGlobal() const;
+    LLVector3 getOriginAgent() const;
+
+    // Center is at the height of the water table.
+    const LLVector3d &getCenterGlobal() const;
+    LLVector3 getCenterAgent() const;
+
+    void setRegionNameAndZone(const std::string& name_and_zone);
+    const std::string& getName() const              { return mName; }
+    const std::string& getZoning() const            { return mZoning; }
+
+    void setOwner(const LLUUID& owner_id);
+    const LLUUID& getOwner() const;
+
+    // Is the current agent on the estate manager list for this region?
+    void setIsEstateManager(BOOL b) { mIsEstateManager = b; }
+    BOOL isEstateManager() const { return mIsEstateManager; }
+    BOOL canManageEstate() const;
+
+    void setSimAccess(U8 sim_access)            { mSimAccess = sim_access; }
+    U8 getSimAccess() const                     { return mSimAccess; }
+    const std::string getSimAccessString() const;
+
+    // Homestead-related getters; there are no setters as nobody should be
+    // setting them other than the individual message handler which is a member
+    S32 getSimClassID()                    const { return mClassID; }
+    S32 getSimCPURatio()                   const { return mCPURatio; }
+    const std::string& getSimColoName()    const { return mColoName; }
+    const std::string& getSimProductSKU()  const { return mProductSKU; }
+    std::string getLocalizedSimProductName() const;
+
+    // Returns "Sandbox", "Expensive", etc.
+    static std::string regionFlagsToString(U64 flags);
+
+    // Returns translated version of "Mature", "PG", "Adult", etc.
+    static const std::string& accessToString(U8 sim_access);
+
+    // Returns "M", "PG", "A" etc.
+    static std::string accessToShortString(U8 sim_access);
+    static U8          shortStringToAccess(const std::string &sim_access);
+
+    // Return access icon name
+    static std::string getAccessIcon(U8 sim_access);
+
+    // helper function which just makes sure all interested parties
+    // can process the message.
+    static void processRegionInfo(LLMessageSystem* msg, void**);
+
+    //check if the viewer camera is static
+    static BOOL isViewerCameraStatic();
+    static void calcNewObjectCreationThrottle();
+
+    void setCacheID(const LLUUID& id);
+
+    F32 getWidth() const                        { return mWidth; }
+
+    // regions are expensive to release, this function gradually releases cache from memory
+    static void idleCleanup(F32 max_update_time);
+    F32 getWidthScaleFactor() const             { return mWidthScaleFactor; } // Scaling for OpenSim VarRegions
+
+    void idleUpdate(F32 max_update_time);
+    void lightIdleUpdate();
+    bool addVisibleGroup(LLViewerOctreeGroup* group);
+    void addVisibleChildCacheEntry(LLVOCacheEntry* parent, LLVOCacheEntry* child);
+    void addActiveCacheEntry(LLVOCacheEntry* entry);
+    void removeActiveCacheEntry(LLVOCacheEntry* entry, LLDrawable* drawablep);
+    void killCacheEntry(U32 local_id); //physically delete the cache entry
+
+    // Like idleUpdate, but forces everything to complete regardless of
+    // how long it takes.
+    void forceUpdate();
+
+    void connectNeighbor(LLViewerRegion *neighborp, U32 direction);
+
+    void updateNetStats();
+
+    U32 getPacketsLost() const;
+
+    S32 getHttpResponderID() const;
+
+    // Get/set named capability URLs for this region.
+    void setSeedCapability(const std::string& url);
+    S32 getNumSeedCapRetries();
+    void setCapability(const std::string& name, const std::string& url);
+    void setCapabilityDebug(const std::string& name, const std::string& url);
+    bool isCapabilityAvailable(std::string_view name) const;
+    // implements LLCapabilityProvider
     const std::string& getCapability(std::string_view name) const override;
     const std::string& getCapabilityDebug(std::string_view name) const;
 
 
-	virtual std::set<std::string> getCapURLNames(const std::string& cap_url);
-	virtual bool isCapURLMapped(const std::string& cap_url);
-	virtual std::set<std::string> getAllCaps();
+    virtual std::set<std::string> getCapURLNames(const std::string& cap_url);
+    virtual bool isCapURLMapped(const std::string& cap_url);
+    virtual std::set<std::string> getAllCaps();
 
-	// has region received its final (not seed) capability list?
-	bool capabilitiesReceived() const;
+    // has region received its final (not seed) capability list?
+    bool capabilitiesReceived() const;
     bool capabilitiesError() const;
-	void setCapabilitiesReceived(bool received);
-	void setCapabilitiesError();
-	boost::signals2::connection setCapabilitiesReceivedCallback(const caps_received_signal_t::slot_type& cb);
+    void setCapabilitiesReceived(bool received);
+    void setCapabilitiesError();
+    boost::signals2::connection setCapabilitiesReceivedCallback(const caps_received_signal_t::slot_type& cb);
 
-	static bool isSpecialCapabilityName(std::string_view name);
-	void logActiveCapabilities() const;
+    static bool isSpecialCapabilityName(std::string_view name);
+    void logActiveCapabilities() const;
 
-	// Utilities to post and get via
+    // Utilities to post and get via
     // HTTP using the agent's policy settings and headers.
     typedef LLCoreHttpUtil::HttpCoroutineAdapter::completionCallback_t httpCallback_t;
     bool requestPostCapability(const std::string &capName,
@@ -304,331 +304,331 @@ class LLViewerRegion final : public LLCapabilityProvider // implements this inte
     bool requestDelCapability(const std::string &capName, httpCallback_t cbSuccess = NULL, httpCallback_t cbFailure = NULL);
 
     /// implements LLCapabilityProvider
-	/*virtual*/ const LLHost& getHost() const override;
-	const U64 		&getHandle() const 			{ return mHandle; }
+    /*virtual*/ const LLHost& getHost() const override;
+    const U64       &getHandle() const          { return mHandle; }
+
+    LLSurface       &getLand() const;
 
-	LLSurface		&getLand() const;
+    // set and get the region id
+    const LLUUID& getRegionID() const;
+    void setRegionID(const LLUUID& region_id);
 
-	// set and get the region id
-	const LLUUID& getRegionID() const;
-	void setRegionID(const LLUUID& region_id);
+    BOOL pointInRegionGlobal(const LLVector3d &point_global) const;
+    LLVector3   getPosRegionFromGlobal(const LLVector3d &point_global) const;
+    LLVector3   getPosRegionFromAgent(const LLVector3 &agent_pos) const;
+    LLVector3   getPosAgentFromRegion(const LLVector3 &region_pos) const;
+    LLVector3d  getPosGlobalFromRegion(const LLVector3 &offset) const;
 
-	BOOL pointInRegionGlobal(const LLVector3d &point_global) const;
-	LLVector3	getPosRegionFromGlobal(const LLVector3d &point_global) const;
-	LLVector3	getPosRegionFromAgent(const LLVector3 &agent_pos) const;
-	LLVector3	getPosAgentFromRegion(const LLVector3 &region_pos) const;
-	LLVector3d	getPosGlobalFromRegion(const LLVector3 &offset) const;
+    LLVLComposition *getComposition() const;
+    F32 getCompositionXY(const S32 x, const S32 y) const;
 
-	LLVLComposition *getComposition() const;
-	F32 getCompositionXY(const S32 x, const S32 y) const;
+    BOOL isOwnedSelf(const LLVector3& pos) const;
 
-	BOOL isOwnedSelf(const LLVector3& pos) const;
+    // Owned by a group you belong to?  (officer OR member)
+    BOOL isOwnedGroup(const LLVector3& pos) const;
 
-	// Owned by a group you belong to?  (officer OR member)
-	BOOL isOwnedGroup(const LLVector3& pos) const;
+    // deal with map object updates in the world.
+    void updateCoarseLocations(LLMessageSystem* msg);
 
-	// deal with map object updates in the world.
-	void updateCoarseLocations(LLMessageSystem* msg);
+    F32 getLandHeightRegion(const LLVector3& region_pos);
 
-	F32 getLandHeightRegion(const LLVector3& region_pos);
+    U8 getCentralBakeVersion() { return mCentralBakeVersion; }
 
-	U8 getCentralBakeVersion() { return mCentralBakeVersion; }
+    void getInfo(LLSD& info);
 
-	void getInfo(LLSD& info);
-	
-	bool meshRezEnabled() const;
-	bool meshUploadEnabled() const;
+    bool meshRezEnabled() const;
+    bool meshUploadEnabled() const;
 
-	bool bakesOnMeshEnabled() const;
+    bool bakesOnMeshEnabled() const;
 
-	// has region received its simulator features list? Requires an additional query after caps received.
+    // has region received its simulator features list? Requires an additional query after caps received.
     void requestSimulatorFeatures();
-	void setSimulatorFeaturesReceived(bool);
-	bool simulatorFeaturesReceived() const;
-	boost::signals2::connection setSimulatorFeaturesReceivedCallback(const caps_received_signal_t::slot_type& cb);
-	
-	void getSimulatorFeatures(LLSD& info) const;	
-	void setSimulatorFeatures(const LLSD& info);
-
-	
-	bool dynamicPathfindingEnabled() const;
-
-	bool avatarHoverHeightEnabled() const;
-
-	typedef enum
-	{
-		CACHE_MISS_TYPE_TOTAL = 0,	// total cache miss - object not in cache
-		CACHE_MISS_TYPE_CRC,		// object in cache, but CRC doesn't match
-		CACHE_MISS_TYPE_NONE		// not a miss:  cache hit
-	} eCacheMissType;
-
-	typedef enum
-	{
-		CACHE_UPDATE_DUPE = 0,
-		CACHE_UPDATE_CHANGED,
-		CACHE_UPDATE_ADDED,
-		CACHE_UPDATE_REPLACED
-	} eCacheUpdateResult;
-
-	// handle a full update message
-	eCacheUpdateResult cacheFullUpdate(LLDataPackerBinaryBuffer &dp, U32 flags);
-	eCacheUpdateResult cacheFullUpdate(LLViewerObject* objectp, LLDataPackerBinaryBuffer &dp, U32 flags);
+    void setSimulatorFeaturesReceived(bool);
+    bool simulatorFeaturesReceived() const;
+    boost::signals2::connection setSimulatorFeaturesReceivedCallback(const caps_received_signal_t::slot_type& cb);
+
+    void getSimulatorFeatures(LLSD& info) const;
+    void setSimulatorFeatures(const LLSD& info);
+
+
+    bool dynamicPathfindingEnabled() const;
+
+    bool avatarHoverHeightEnabled() const;
+
+    typedef enum
+    {
+        CACHE_MISS_TYPE_TOTAL = 0,  // total cache miss - object not in cache
+        CACHE_MISS_TYPE_CRC,        // object in cache, but CRC doesn't match
+        CACHE_MISS_TYPE_NONE        // not a miss:  cache hit
+    } eCacheMissType;
+
+    typedef enum
+    {
+        CACHE_UPDATE_DUPE = 0,
+        CACHE_UPDATE_CHANGED,
+        CACHE_UPDATE_ADDED,
+        CACHE_UPDATE_REPLACED
+    } eCacheUpdateResult;
+
+    // handle a full update message
+    eCacheUpdateResult cacheFullUpdate(LLDataPackerBinaryBuffer &dp, U32 flags);
+    eCacheUpdateResult cacheFullUpdate(LLViewerObject* objectp, LLDataPackerBinaryBuffer &dp, U32 flags);
 
     void cacheFullUpdateGLTFOverride(const LLGLTFOverrideCacheEntry &override_data);
 
-	LLVOCacheEntry* getCacheEntryForOctree(U32 local_id);
-	LLVOCacheEntry* getCacheEntry(U32 local_id, bool valid = true);
-	bool probeCache(U32 local_id, U32 crc, U32 flags, U8 &cache_miss_type);
-	U64 getRegionCacheHitCount() { return mRegionCacheHitCount; }
-	U64 getRegionCacheMissCount() { return mRegionCacheMissCount; }
-	void requestCacheMisses();
-	void addCacheMissFull(const U32 local_id);
-	//update object cache if the object receives a full-update or terse update
-	LLViewerObject* updateCacheEntry(U32 local_id, LLViewerObject* objectp);
-	void findOrphans(U32 parent_id);
-	void clearCachedVisibleObjects();
-	void dumpCache  ();
+    LLVOCacheEntry* getCacheEntryForOctree(U32 local_id);
+    LLVOCacheEntry* getCacheEntry(U32 local_id, bool valid = true);
+    bool probeCache(U32 local_id, U32 crc, U32 flags, U8 &cache_miss_type);
+    U64 getRegionCacheHitCount() { return mRegionCacheHitCount; }
+    U64 getRegionCacheMissCount() { return mRegionCacheMissCount; }
+    void requestCacheMisses();
+    void addCacheMissFull(const U32 local_id);
+    //update object cache if the object receives a full-update or terse update
+    LLViewerObject* updateCacheEntry(U32 local_id, LLViewerObject* objectp);
+    void findOrphans(U32 parent_id);
+    void clearCachedVisibleObjects();
+    void dumpCache  ();
     void clearVOCacheFromMemory();
 
-	void unpackRegionHandshake();
+    void unpackRegionHandshake();
 
-	void calculateCenterGlobal();
-	void calculateCameraDistance();
+    void calculateCenterGlobal();
+    void calculateCameraDistance();
 
-	friend std::ostream& operator<<(std::ostream &s, const LLViewerRegion &region);
+    friend std::ostream& operator<<(std::ostream &s, const LLViewerRegion &region);
     /// implements LLCapabilityProvider
     virtual std::string getDescription() const override;
     const std::string& getLegacyHttpUrl() const { return mLegacyHttpUrl; }
     const std::string& getViewerAssetUrl() const { return mViewerAssetUrl; }
 
-	U32 getNumOfVisibleGroups() const;
-	U32 getNumOfActiveCachedObjects() const;
-	LLSpatialPartition* getSpatialPartition(U32 type);
-	LLVOCachePartition* getVOCachePartition();
+    U32 getNumOfVisibleGroups() const;
+    U32 getNumOfActiveCachedObjects() const;
+    LLSpatialPartition* getSpatialPartition(U32 type);
+    LLVOCachePartition* getVOCachePartition();
 
-	bool objectIsReturnable(const LLVector3& pos, const std::vector<LLBBox>& boxes) const;
-	bool childrenObjectReturnable( const std::vector<LLBBox>& boxes ) const;
-	bool objectsCrossParcel(const std::vector<LLBBox>& boxes) const;
+    bool objectIsReturnable(const LLVector3& pos, const std::vector<LLBBox>& boxes) const;
+    bool childrenObjectReturnable( const std::vector<LLBBox>& boxes ) const;
+    bool objectsCrossParcel(const std::vector<LLBBox>& boxes) const;
 
-	void getNeighboringRegions( std::vector<LLViewerRegion*>& uniqueRegions );
-	void getNeighboringRegionsStatus( std::vector<S32>& regions );
-	const LLViewerRegionImpl * getRegionImpl() const { return mImpl; }
-	LLViewerRegionImpl * getRegionImplNC() { return mImpl; }
+    void getNeighboringRegions( std::vector<LLViewerRegion*>& uniqueRegions );
+    void getNeighboringRegionsStatus( std::vector<S32>& regions );
+    const LLViewerRegionImpl * getRegionImpl() const { return mImpl; }
+    LLViewerRegionImpl * getRegionImplNC() { return mImpl; }
 
-	// implements the materials capability throttle
-	bool materialsCapThrottled() const { return !mMaterialsCapThrottleTimer.hasExpired(); }
-	void resetMaterialsCapThrottle();
-	
-	U32 getMaxMaterialsPerTransaction() const;
+    // implements the materials capability throttle
+    bool materialsCapThrottled() const { return !mMaterialsCapThrottleTimer.hasExpired(); }
+    void resetMaterialsCapThrottle();
 
-	void removeFromCreatedList(U32 local_id);
-	void addToCreatedList(U32 local_id);	
+    U32 getMaxMaterialsPerTransaction() const;
 
-	BOOL isPaused() const {return mPaused;}
-	S32  getLastUpdate() const {return mLastUpdate;}
+    void removeFromCreatedList(U32 local_id);
+    void addToCreatedList(U32 local_id);
 
-	std::string getSimHostName();
+    BOOL isPaused() const {return mPaused;}
+    S32  getLastUpdate() const {return mLastUpdate;}
 
-	static BOOL isNewObjectCreationThrottleDisabled() {return sNewObjectCreationThrottle < 0;}
+    std::string getSimHostName();
+
+    static BOOL isNewObjectCreationThrottleDisabled() {return sNewObjectCreationThrottle < 0;}
 
     // rebuild reflection probe list
     void updateReflectionProbes();
 
-	/* ================================================================
-	 * @name OpenSimExtras Simulator Features capability
-	 * @{
-	 */
-	/// Get region allows export
-	bool getRegionAllowsExport() const;
-	/// Avatar picker url
-	std::string getAvatarPickerURL() const;
-	/// Destination guide url
-	std::string getDestinationGuideURL() const;
-	/// Hypergrid map server url
-	std::string getMapServerURL() const;
-	/// Hypergrid search server url
-	std::string getSearchServerURL() const;
-	/// Buy currency server url
-	std::string getBuyCurrencyServerURL() const;
-	/// Grid login/gateway authority (0.8.1)
-	std::string getHGGrid() const;
-	/// Grid name (0.8.1)
-	std::string getHGGridName() const;
-	/// Grid nick (0.8.1)
-	std::string getHGGridNick() const;
+    /* ================================================================
+     * @name OpenSimExtras Simulator Features capability
+     * @{
+     */
+    /// Get region allows export
+    bool getRegionAllowsExport() const;
+    /// Avatar picker url
+    std::string getAvatarPickerURL() const;
+    /// Destination guide url
+    std::string getDestinationGuideURL() const;
+    /// Hypergrid map server url
+    std::string getMapServerURL() const;
+    /// Hypergrid search server url
+    std::string getSearchServerURL() const;
+    /// Buy currency server url
+    std::string getBuyCurrencyServerURL() const;
+    /// Grid login/gateway authority (0.8.1)
+    std::string getHGGrid() const;
+    /// Grid name (0.8.1)
+    std::string getHGGridName() const;
+    /// Grid nick (0.8.1)
+    std::string getHGGridNick() const;
     /// Chat Range (0.8.1)
     U32 getChatRange() const;
     /// Shout Range (0.8.1)
     U32 getShoutRange() const;
     /// Whisper Range (0.8.1)
     U32 getWhisperRange() const;
-	/// Prim Scale
-	F32 getMinPrimScale() const;
-	F32 getMaxPrimScale() const;
-	F32 getMinPhysPrimScale() const;
-	F32 getMaxPhysPrimScale() const;
-	/// Sim Z
-	F32 getMinRegionHeight() const;
-	F32 getMaxRegionHeight() const;
-
-	/// "God names" surname and full account names map
-	const auto& getGods() const { return mGodNames; };
-	//@}
-
-	typedef std::vector<LLPointer<LLViewerTexture> > tex_matrix_t;
-	const tex_matrix_t& getWorldMapTiles() const;
+    /// Prim Scale
+    F32 getMinPrimScale() const;
+    F32 getMaxPrimScale() const;
+    F32 getMinPhysPrimScale() const;
+    F32 getMaxPhysPrimScale() const;
+    /// Sim Z
+    F32 getMinRegionHeight() const;
+    F32 getMaxRegionHeight() const;
+
+    /// "God names" surname and full account names map
+    const auto& getGods() const { return mGodNames; };
+    //@}
+
+    typedef std::vector<LLPointer<LLViewerTexture> > tex_matrix_t;
+    const tex_matrix_t& getWorldMapTiles() const;
 
 private:
-	void addToVOCacheTree(LLVOCacheEntry* entry);
-	LLViewerObject* addNewObject(LLVOCacheEntry* entry);
-	void killObject(LLVOCacheEntry* entry, std::vector<LLDrawable*>& delete_list); //adds entry into list if it is safe to move into cache
-	void removeFromVOCacheTree(LLVOCacheEntry* entry);
-	void killCacheEntry(LLVOCacheEntry* entry, bool for_rendering = false); //physically delete the cache entry	
-	void killInvisibleObjects(F32 max_time);
-	void createVisibleObjects(F32 max_time);
-	void updateVisibleEntries(F32 max_time); //update visible entries
-
-	void addCacheMiss(U32 id, LLViewerRegion::eCacheMissType miss_type);
-	void decodeBoundingInfo(LLVOCacheEntry* entry);
-	bool isNonCacheableObjectCreated(U32 local_id);	
-	void setGodnames();
+    void addToVOCacheTree(LLVOCacheEntry* entry);
+    LLViewerObject* addNewObject(LLVOCacheEntry* entry);
+    void killObject(LLVOCacheEntry* entry, std::vector<LLDrawable*>& delete_list); //adds entry into list if it is safe to move into cache
+    void removeFromVOCacheTree(LLVOCacheEntry* entry);
+    void killCacheEntry(LLVOCacheEntry* entry, bool for_rendering = false); //physically delete the cache entry
+    void killInvisibleObjects(F32 max_time);
+    void createVisibleObjects(F32 max_time);
+    void updateVisibleEntries(F32 max_time); //update visible entries
+
+    void addCacheMiss(U32 id, LLViewerRegion::eCacheMissType miss_type);
+    void decodeBoundingInfo(LLVOCacheEntry* entry);
+    bool isNonCacheableObjectCreated(U32 local_id);
+    void setGodnames();
 
 public:
     void applyCacheMiscExtras(LLViewerObject* obj);
 
-	struct CompareDistance
-	{
-		bool operator()(const LLViewerRegion* const& lhs, const LLViewerRegion* const& rhs)
-		{
-			return lhs->mCameraDistanceSquared < rhs->mCameraDistanceSquared; 
-		}
-	};
+    struct CompareDistance
+    {
+        bool operator()(const LLViewerRegion* const& lhs, const LLViewerRegion* const& rhs)
+        {
+            return lhs->mCameraDistanceSquared < rhs->mCameraDistanceSquared;
+        }
+    };
 
-	void showReleaseNotes();
-	void reInitPartitions();
+    void showReleaseNotes();
+    void reInitPartitions();
 
 protected:
-	void disconnectAllNeighbors();
-	void initStats();
-	void initPartitions();
+    void disconnectAllNeighbors();
+    void initStats();
+    void initPartitions();
 
 public:
-	LLWind  mWind;
-	LLViewerParcelOverlay	*mParcelOverlay;
-
-	F32Bits	mBitsReceived;
-	F32		mPacketsReceived;
-
-	LL_ALIGN_16(LLMatrix4a mRenderMatrix);
-
-	// These arrays are maintained in parallel. Ideally they'd be combined into a
-	// single array of an aggrigate data type but for compatibility with the old
-	// messaging system in which the previous message only sends and parses the 
-	// positions stored in the first array so they're maintained separately until 
-	// we stop supporting the old CoarseLocationUpdate message.
-	std::vector<U32> mMapAvatars;
-	std::vector<LLUUID> mMapAvatarIDs;
-
-	static BOOL sVOCacheCullingEnabled; //vo cache culling enabled or not.
-	static S32  sLastCameraUpdated;
-
-	LLFrameTimer &	getRenderInfoRequestTimer()	{ return mRenderInfoRequestTimer; };
-	LLFrameTimer &	getRenderInfoReportTimer()	{ return mRenderInfoReportTimer; };
-
-	struct CompareRegionByLastUpdate
-	{
-		bool operator()(const LLViewerRegion* const& lhs, const LLViewerRegion* const& rhs) const
-		{
-			S32 lpa = lhs->getLastUpdate();
-			S32 rpa = rhs->getLastUpdate();
-
-			//small mLastUpdate first
-			if(lpa < rpa)		
-			{
-				return true;
-			}
-			else if(lpa > rpa)
-			{
-				return false;
-			}
-			else
-			{
-				return lhs < rhs;
-			}			
-		}
-	};
-	typedef std::set<LLViewerRegion*, CompareRegionByLastUpdate> region_priority_list_t;
-
-	void setInterestListMode(const std::string & new_mode);
+    LLWind  mWind;
+    LLViewerParcelOverlay   *mParcelOverlay;
+
+    F32Bits mBitsReceived;
+    F32     mPacketsReceived;
+
+    LL_ALIGN_16(LLMatrix4a mRenderMatrix);
+
+    // These arrays are maintained in parallel. Ideally they'd be combined into a
+    // single array of an aggrigate data type but for compatibility with the old
+    // messaging system in which the previous message only sends and parses the
+    // positions stored in the first array so they're maintained separately until
+    // we stop supporting the old CoarseLocationUpdate message.
+    std::vector<U32> mMapAvatars;
+    std::vector<LLUUID> mMapAvatarIDs;
+
+    static BOOL sVOCacheCullingEnabled; //vo cache culling enabled or not.
+    static S32  sLastCameraUpdated;
+
+    LLFrameTimer &  getRenderInfoRequestTimer() { return mRenderInfoRequestTimer; };
+    LLFrameTimer &  getRenderInfoReportTimer()  { return mRenderInfoReportTimer; };
+
+    struct CompareRegionByLastUpdate
+    {
+        bool operator()(const LLViewerRegion* const& lhs, const LLViewerRegion* const& rhs) const
+        {
+            S32 lpa = lhs->getLastUpdate();
+            S32 rpa = rhs->getLastUpdate();
+
+            //small mLastUpdate first
+            if(lpa < rpa)
+            {
+                return true;
+            }
+            else if(lpa > rpa)
+            {
+                return false;
+            }
+            else
+            {
+                return lhs < rhs;
+            }
+        }
+    };
+    typedef std::set<LLViewerRegion*, CompareRegionByLastUpdate> region_priority_list_t;
+
+    void setInterestListMode(const std::string & new_mode);
     const std::string & getInterestListMode() const { return mInterestListMode; }
 
-	void resetInterestList();
+    void resetInterestList();
 
-	static const std::string IL_MODE_DEFAULT;
+    static const std::string IL_MODE_DEFAULT;
     static const std::string IL_MODE_360;
 
   private:
-	static S32  sNewObjectCreationThrottle;
-	LLViewerRegionImpl * mImpl;
-	LLFrameTimer         mRegionTimer;
-
-	F32			mWidth;			// Width of region on a side (meters)
-	U64			mHandle;
-	F32			mTimeDilation;	// time dilation of physics simulation on simulator
-	S32         mLastUpdate; //last time called idleUpdate()
-	F32			mWidthScaleFactor; // Scaling for OpenSim VarRegions
-	S32			mMaxBakes; // store max bakes on the region
-	S32			mMaxTEs; // store max TEs on the region
-
-	// simulator name
-	std::string mName;
-	std::string mZoning;
-
-	// Is this agent on the estate managers list for this region?
-	BOOL mIsEstateManager;
-
-	U32		mPacketsIn;
-	U32Bits	mBitsIn,
-			mLastBitsIn;
-	U32		mLastPacketsIn;
-	U32		mPacketsOut;
-	U32		mLastPacketsOut;
-	S32		mPacketsLost;
-	S32		mLastPacketsLost;
-	U32Milliseconds		mPingDelay;
-	F32		mDeltaTime;				// Time since last measurement of lastPackets, Bits, etc
-
-	U64		mRegionFlags;			// includes damage flags
-	U64		mRegionProtocols;		// protocols supported by this region
-	U8		mSimAccess;
-	F32 	mBillableFactor;
-	U32		mMaxTasks;				// max prim count
-	F32		mCameraDistanceSquared;	// updated once per frame
-	U8		mCentralBakeVersion;
-	
-	LLVOCacheEntry* mLastVisitedEntry;
-	U32				mInvisibilityCheckHistory;	
-
-	// Information for Homestead / CR-53
-	S32 mClassID;
-	S32 mCPURatio;
-
-	std::string mColoName;
-	std::string mProductSKU;
-	std::string mProductName;
-	std::string mLegacyHttpUrl;
-	std::string mViewerAssetUrl;
-	
-	// Maps local ids to cache entries.
-	// Regions can have order 10,000 objects, so assume
-	// a structure of size 2^14 = 16,000
-	BOOL									mCacheLoaded;
-	BOOL                                    mCacheDirty;
-	BOOL	mAlive;					// can become false if circuit disconnects
-	BOOL	mSimulatorFeaturesReceived;
-	BOOL    mReleaseNotesRequested;
-	BOOL    mDead;  //if true, this region is in the process of deleting.
-	BOOL    mPaused; //pause processing the objects in the region
+    static S32  sNewObjectCreationThrottle;
+    LLViewerRegionImpl * mImpl;
+    LLFrameTimer         mRegionTimer;
+
+    F32         mWidth;         // Width of region on a side (meters)
+    U64         mHandle;
+    F32         mTimeDilation;  // time dilation of physics simulation on simulator
+    S32         mLastUpdate; //last time called idleUpdate()
+    F32         mWidthScaleFactor; // Scaling for OpenSim VarRegions
+    S32         mMaxBakes; // store max bakes on the region
+    S32         mMaxTEs; // store max TEs on the region
+
+    // simulator name
+    std::string mName;
+    std::string mZoning;
+
+    // Is this agent on the estate managers list for this region?
+    BOOL mIsEstateManager;
+
+    U32     mPacketsIn;
+    U32Bits mBitsIn,
+            mLastBitsIn;
+    U32     mLastPacketsIn;
+    U32     mPacketsOut;
+    U32     mLastPacketsOut;
+    S32     mPacketsLost;
+    S32     mLastPacketsLost;
+    U32Milliseconds     mPingDelay;
+    F32     mDeltaTime;             // Time since last measurement of lastPackets, Bits, etc
+
+    U64     mRegionFlags;           // includes damage flags
+    U64     mRegionProtocols;       // protocols supported by this region
+    U8      mSimAccess;
+    F32     mBillableFactor;
+    U32     mMaxTasks;              // max prim count
+    F32     mCameraDistanceSquared; // updated once per frame
+    U8      mCentralBakeVersion;
+
+    LLVOCacheEntry* mLastVisitedEntry;
+    U32             mInvisibilityCheckHistory;
+
+    // Information for Homestead / CR-53
+    S32 mClassID;
+    S32 mCPURatio;
+
+    std::string mColoName;
+    std::string mProductSKU;
+    std::string mProductName;
+    std::string mLegacyHttpUrl;
+    std::string mViewerAssetUrl;
+
+    // Maps local ids to cache entries.
+    // Regions can have order 10,000 objects, so assume
+    // a structure of size 2^14 = 16,000
+    BOOL                                    mCacheLoaded;
+    BOOL                                    mCacheDirty;
+    BOOL    mAlive;                 // can become false if circuit disconnects
+    BOOL    mSimulatorFeaturesReceived;
+    BOOL    mReleaseNotesRequested;
+    BOOL    mDead;  //if true, this region is in the process of deleting.
+    BOOL    mPaused; //pause processing the objects in the region
 
     typedef enum
     {
@@ -637,154 +637,154 @@ class LLViewerRegion final : public LLCapabilityProvider // implements this inte
         CAPABILITIES_STATE_RECEIVED
     } eCababilitiesState;
 
-    eCababilitiesState	mCapabilitiesState;
+    eCababilitiesState  mCapabilitiesState;
 
-	typedef std::map<U32, std::vector<U32> > orphan_list_t;
-	orphan_list_t mOrphanMap;
+    typedef std::map<U32, std::vector<U32> > orphan_list_t;
+    orphan_list_t mOrphanMap;
 
-	class CacheMissItem
-	{
-	public:
+    class CacheMissItem
+    {
+    public:
         CacheMissItem(U32 id, LLViewerRegion::eCacheMissType miss_type) : mID(id), mType(miss_type) {}
 
-		U32                         mID;     //local object id
-        LLViewerRegion::eCacheMissType	mType;  // cache miss type
-
-		typedef std::list<CacheMissItem> cache_miss_list_t;
-	};
-	CacheMissItem::cache_miss_list_t   mCacheMissList;
-	U64 mRegionCacheHitCount;
-	U64 mRegionCacheMissCount;
-
-	caps_received_signal_t mCapabilitiesReceivedSignal;		
-	caps_received_signal_t mSimulatorFeaturesReceivedSignal;		
-
-	LLSD mSimulatorFeatures;
-	U32 mMaxMaterialsPerTrans = 0;
-	bool mMeshUploadEnabled = false;
-	bool mBakesOnMeshEnabled = false;
-	bool mMeshRezEnabled = false;
-	bool mDynamicPathfindingEnabled = false;
-	bool mAvatarHoverHeightEnabled = false;
-	F32  mMinSimHeight = SL_MIN_OBJECT_Z;
-	F32  mMaxSimHeight = SL_MAX_OBJECT_Z;
-	F32  mMinPrimScale = SL_MIN_PRIM_SCALE;
-	F32  mMaxPrimScale = SL_DEFAULT_MAX_PRIM_SCALE;
-	F32  mMaxPrimScaleNoMesh = SL_DEFAULT_MAX_PRIM_SCALE_NO_MESH;
-	F32  mMinPhysPrimScale = SL_MIN_PRIM_SCALE;
-	F32  mMaxPhysPrimScale = SL_DEFAULT_MAX_PRIM_SCALE;
-	U32  mWhisperRange = 10;
-	U32  mSayRange = 20;
-	U32  mShoutRange = 100;
-	std::string mHGMapServerURL;
-	std::string mHGGridName;
-	std::string mHGGridNick;
-	std::string mHGGridURL;
-
-    typedef std::map<U32, LLPointer<LLVOCacheEntry> >	   vocache_entry_map_t;
+        U32                         mID;     //local object id
+        LLViewerRegion::eCacheMissType  mType;  // cache miss type
+
+        typedef std::list<CacheMissItem> cache_miss_list_t;
+    };
+    CacheMissItem::cache_miss_list_t   mCacheMissList;
+    U64 mRegionCacheHitCount;
+    U64 mRegionCacheMissCount;
+
+    caps_received_signal_t mCapabilitiesReceivedSignal;
+    caps_received_signal_t mSimulatorFeaturesReceivedSignal;
+
+    LLSD mSimulatorFeatures;
+    U32 mMaxMaterialsPerTrans = 0;
+    bool mMeshUploadEnabled = false;
+    bool mBakesOnMeshEnabled = false;
+    bool mMeshRezEnabled = false;
+    bool mDynamicPathfindingEnabled = false;
+    bool mAvatarHoverHeightEnabled = false;
+    F32  mMinSimHeight = SL_MIN_OBJECT_Z;
+    F32  mMaxSimHeight = SL_MAX_OBJECT_Z;
+    F32  mMinPrimScale = SL_MIN_PRIM_SCALE;
+    F32  mMaxPrimScale = SL_DEFAULT_MAX_PRIM_SCALE;
+    F32  mMaxPrimScaleNoMesh = SL_DEFAULT_MAX_PRIM_SCALE_NO_MESH;
+    F32  mMinPhysPrimScale = SL_MIN_PRIM_SCALE;
+    F32  mMaxPhysPrimScale = SL_DEFAULT_MAX_PRIM_SCALE;
+    U32  mWhisperRange = 10;
+    U32  mSayRange = 20;
+    U32  mShoutRange = 100;
+    std::string mHGMapServerURL;
+    std::string mHGGridName;
+    std::string mHGGridNick;
+    std::string mHGGridURL;
+
+    typedef std::map<U32, LLPointer<LLVOCacheEntry> >      vocache_entry_map_t;
     static vocache_entry_map_t sRegionCacheCleanup;
 
-	// the materials capability throttle
-	LLFrameTimer mMaterialsCapThrottleTimer;
-	LLFrameTimer mRenderInfoRequestTimer;
-	LLFrameTimer mRenderInfoReportTimer;
+    // the materials capability throttle
+    LLFrameTimer mMaterialsCapThrottleTimer;
+    LLFrameTimer mRenderInfoRequestTimer;
+    LLFrameTimer mRenderInfoReportTimer;
 
-	// how the server interest list works
+    // how the server interest list works
     std::string mInterestListMode;
 
     // list of reflection maps being managed by this llviewer region
     std::vector<LLPointer<LLReflectionMap> > mReflectionMaps;
 
-	mutable tex_matrix_t mWorldMapTiles;
-	boost::unordered_flat_set<std::string, al::string_hash, std::equal_to<>> mGodNames;
+    mutable tex_matrix_t mWorldMapTiles;
+    boost::unordered_flat_set<std::string, al::string_hash, std::equal_to<>> mGodNames;
 
-	LLEasyMessageSender mMessageSender;
-	using url_mapping_t = boost::unordered_multimap<std::string, std::string>;
-	url_mapping_t mCapURLMappings;
+    LLEasyMessageSender mMessageSender;
+    using url_mapping_t = boost::unordered_multimap<std::string, std::string>;
+    url_mapping_t mCapURLMappings;
 };
 
 inline BOOL LLViewerRegion::getRegionProtocol(U64 protocol) const
 {
-	return ((mRegionProtocols & protocol) != 0);
+    return ((mRegionProtocols & protocol) != 0);
 }
 
 inline void LLViewerRegion::setRegionProtocol(U64 protocol, BOOL on)
 {
-	if (on)
-	{
-		mRegionProtocols |= protocol;
-	}
-	else
-	{
-		mRegionProtocols &= ~protocol;
-	}
+    if (on)
+    {
+        mRegionProtocols |= protocol;
+    }
+    else
+    {
+        mRegionProtocols &= ~protocol;
+    }
 }
 
 inline BOOL LLViewerRegion::getRegionFlag(U64 flag) const
 {
-	return ((mRegionFlags & flag) != 0);
+    return ((mRegionFlags & flag) != 0);
 }
 
 inline void LLViewerRegion::setRegionFlag(U64 flag, BOOL on)
 {
-	if (on)
-	{
-		mRegionFlags |= flag;
-	}
-	else
-	{
-		mRegionFlags &= ~flag;
-	}
+    if (on)
+    {
+        mRegionFlags |= flag;
+    }
+    else
+    {
+        mRegionFlags &= ~flag;
+    }
 }
 
 inline BOOL LLViewerRegion::getAllowDamage() const
 {
-	return ((mRegionFlags & REGION_FLAGS_ALLOW_DAMAGE) !=0);
+    return ((mRegionFlags & REGION_FLAGS_ALLOW_DAMAGE) !=0);
 }
 
 inline BOOL LLViewerRegion::getAllowLandmark() const
 {
-	return ((mRegionFlags & REGION_FLAGS_ALLOW_LANDMARK) !=0);
+    return ((mRegionFlags & REGION_FLAGS_ALLOW_LANDMARK) !=0);
 }
 
 inline BOOL LLViewerRegion::getAllowSetHome() const
 {
-	return ((mRegionFlags & REGION_FLAGS_ALLOW_SET_HOME) != 0);
+    return ((mRegionFlags & REGION_FLAGS_ALLOW_SET_HOME) != 0);
 }
 
 inline BOOL LLViewerRegion::getResetHomeOnTeleport() const
 {
-	return ((mRegionFlags & REGION_FLAGS_RESET_HOME_ON_TELEPORT) !=0);
+    return ((mRegionFlags & REGION_FLAGS_RESET_HOME_ON_TELEPORT) !=0);
 }
 
 inline BOOL LLViewerRegion::getSunFixed() const
 {
-	return ((mRegionFlags & REGION_FLAGS_SUN_FIXED) !=0);
+    return ((mRegionFlags & REGION_FLAGS_SUN_FIXED) !=0);
 }
 
 inline BOOL LLViewerRegion::getBlockFly() const
 {
-	return ((mRegionFlags & REGION_FLAGS_BLOCK_FLY) !=0);
+    return ((mRegionFlags & REGION_FLAGS_BLOCK_FLY) !=0);
 }
 
 inline BOOL LLViewerRegion::getAllowDirectTeleport() const
 {
-	return ((mRegionFlags & REGION_FLAGS_ALLOW_DIRECT_TELEPORT) !=0);
+    return ((mRegionFlags & REGION_FLAGS_ALLOW_DIRECT_TELEPORT) !=0);
 }
 
 inline BOOL LLViewerRegion::isPrelude() const
 {
-	return is_prelude( mRegionFlags );
+    return is_prelude( mRegionFlags );
 }
 
 inline BOOL LLViewerRegion::getAllowTerraform() const
 {
-	return ((mRegionFlags & REGION_FLAGS_BLOCK_TERRAFORM) == 0);
+    return ((mRegionFlags & REGION_FLAGS_BLOCK_TERRAFORM) == 0);
 }
 
 inline BOOL LLViewerRegion::getRestrictPushObject() const
 {
-	return ((mRegionFlags & REGION_FLAGS_RESTRICT_PUSHOBJECT) != 0);
+    return ((mRegionFlags & REGION_FLAGS_RESTRICT_PUSHOBJECT) != 0);
 }
 
 inline BOOL LLViewerRegion::getAllowEnvironmentOverride() const
@@ -794,7 +794,7 @@ inline BOOL LLViewerRegion::getAllowEnvironmentOverride() const
 
 inline BOOL LLViewerRegion::getReleaseNotesRequested() const
 {
-	return mReleaseNotesRequested;
+    return mReleaseNotesRequested;
 }
 
 #endif
diff --git a/indra/newview/llviewershadermgr.cpp b/indra/newview/llviewershadermgr.cpp
index b972c2ecaae0382aa0b60643518f56292ce3a0f0..470db5218512555b11d32e831c835d380f71190d 100644
--- a/indra/newview/llviewershadermgr.cpp
+++ b/indra/newview/llviewershadermgr.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewershadermgr.cpp
  * @brief Viewer shader manager implementation.
  *
  * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -62,10 +62,10 @@ using std::pair;
 using std::make_pair;
 using std::string;
 
-BOOL				LLViewerShaderMgr::sInitialized = FALSE;
-bool				LLViewerShaderMgr::sSkipReload = false;
+BOOL                LLViewerShaderMgr::sInitialized = FALSE;
+bool                LLViewerShaderMgr::sSkipReload = false;
 
-LLVector4			gShinyOrigin;
+LLVector4           gShinyOrigin;
 
 S32 clamp_terrain_mapping(S32 mapping)
 {
@@ -76,172 +76,172 @@ S32 clamp_terrain_mapping(S32 mapping)
 }
 
 //utility shaders
-LLGLSLShader	gOcclusionProgram;
+LLGLSLShader    gOcclusionProgram;
 LLGLSLShader    gSkinnedOcclusionProgram;
-LLGLSLShader	gOcclusionCubeProgram;
-LLGLSLShader	gGlowCombineProgram;
-LLGLSLShader	gReflectionMipProgram;
+LLGLSLShader    gOcclusionCubeProgram;
+LLGLSLShader    gGlowCombineProgram;
+LLGLSLShader    gReflectionMipProgram;
 LLGLSLShader    gGaussianProgram;
 LLGLSLShader    gRadianceGenProgram;
 LLGLSLShader    gHeroRadianceGenProgram;
-LLGLSLShader	gIrradianceGenProgram;
-LLGLSLShader	gGlowCombineFXAAProgram;
-LLGLSLShader	gTwoTextureCompareProgram;
-LLGLSLShader	gOneTextureFilterProgram;
-LLGLSLShader	gDebugProgram;
+LLGLSLShader    gIrradianceGenProgram;
+LLGLSLShader    gGlowCombineFXAAProgram;
+LLGLSLShader    gTwoTextureCompareProgram;
+LLGLSLShader    gOneTextureFilterProgram;
+LLGLSLShader    gDebugProgram;
 LLGLSLShader    gSkinnedDebugProgram;
-LLGLSLShader	gNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
-LLGLSLShader	gSkinnedNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
-LLGLSLShader	gClipProgram;
-LLGLSLShader	gAlphaMaskProgram;
-LLGLSLShader	gBenchmarkProgram;
+LLGLSLShader    gNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
+LLGLSLShader    gSkinnedNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
+LLGLSLShader    gClipProgram;
+LLGLSLShader    gAlphaMaskProgram;
+LLGLSLShader    gBenchmarkProgram;
 LLGLSLShader    gReflectionProbeDisplayProgram;
 LLGLSLShader    gCopyProgram;
 LLGLSLShader    gCopyDepthProgram;
 
 //object shaders
-LLGLSLShader		gObjectPreviewProgram;
+LLGLSLShader        gObjectPreviewProgram;
 LLGLSLShader        gSkinnedObjectPreviewProgram;
 LLGLSLShader        gPhysicsPreviewProgram;
-LLGLSLShader		gObjectFullbrightAlphaMaskProgram;
-LLGLSLShader		gObjectBumpProgram;
+LLGLSLShader        gObjectFullbrightAlphaMaskProgram;
+LLGLSLShader        gObjectBumpProgram;
 LLGLSLShader        gSkinnedObjectBumpProgram;
-LLGLSLShader		gObjectAlphaMaskNoColorProgram;
+LLGLSLShader        gObjectAlphaMaskNoColorProgram;
 
 //environment shaders
-LLGLSLShader		gWaterProgram;
+LLGLSLShader        gWaterProgram;
 LLGLSLShader        gWaterEdgeProgram;
-LLGLSLShader		gUnderWaterProgram;
+LLGLSLShader        gUnderWaterProgram;
 
 //interface shaders
-LLGLSLShader		gHighlightProgram;
+LLGLSLShader        gHighlightProgram;
 LLGLSLShader        gSkinnedHighlightProgram;
-LLGLSLShader		gHighlightNormalProgram;
-LLGLSLShader		gHighlightSpecularProgram;
+LLGLSLShader        gHighlightNormalProgram;
+LLGLSLShader        gHighlightSpecularProgram;
 
-LLGLSLShader		gDeferredHighlightProgram;
+LLGLSLShader        gDeferredHighlightProgram;
 
-LLGLSLShader		gPathfindingProgram;
-LLGLSLShader		gPathfindingNoNormalsProgram;
+LLGLSLShader        gPathfindingProgram;
+LLGLSLShader        gPathfindingNoNormalsProgram;
 
 //avatar shader handles
-LLGLSLShader		gAvatarProgram;
-LLGLSLShader		gAvatarEyeballProgram;
-LLGLSLShader		gImpostorProgram;
+LLGLSLShader        gAvatarProgram;
+LLGLSLShader        gAvatarEyeballProgram;
+LLGLSLShader        gImpostorProgram;
 
 // Effects Shaders
-LLGLSLShader			gGlowProgram;
-LLGLSLShader			gGlowExtractProgram;
-LLGLSLShader			gPostScreenSpaceReflectionProgram;
+LLGLSLShader            gGlowProgram;
+LLGLSLShader            gGlowExtractProgram;
+LLGLSLShader            gPostScreenSpaceReflectionProgram;
 LLGLSLShader            gPostSMAAEdgeDetect[4];
 LLGLSLShader            gPostSMAABlendWeights[4];
 LLGLSLShader            gPostSMAANeighborhoodBlend[4];
 
 
 // Deferred rendering shaders
-LLGLSLShader			gDeferredImpostorProgram;
-LLGLSLShader			gDeferredDiffuseProgram;
-LLGLSLShader			gDeferredDiffuseAlphaMaskProgram;
+LLGLSLShader            gDeferredImpostorProgram;
+LLGLSLShader            gDeferredDiffuseProgram;
+LLGLSLShader            gDeferredDiffuseAlphaMaskProgram;
 LLGLSLShader            gDeferredSkinnedDiffuseAlphaMaskProgram;
-LLGLSLShader			gDeferredNonIndexedDiffuseAlphaMaskProgram;
-LLGLSLShader			gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
-LLGLSLShader			gDeferredSkinnedDiffuseProgram;
-LLGLSLShader			gDeferredSkinnedBumpProgram;
-LLGLSLShader			gDeferredBumpProgram;
-LLGLSLShader			gDeferredTerrainProgram;
-LLGLSLShader			gDeferredTreeProgram;
-LLGLSLShader			gDeferredTreeShadowProgram;
+LLGLSLShader            gDeferredNonIndexedDiffuseAlphaMaskProgram;
+LLGLSLShader            gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
+LLGLSLShader            gDeferredSkinnedDiffuseProgram;
+LLGLSLShader            gDeferredSkinnedBumpProgram;
+LLGLSLShader            gDeferredBumpProgram;
+LLGLSLShader            gDeferredTerrainProgram;
+LLGLSLShader            gDeferredTreeProgram;
+LLGLSLShader            gDeferredTreeShadowProgram;
 LLGLSLShader            gDeferredSkinnedTreeShadowProgram;
-LLGLSLShader			gDeferredAvatarProgram;
-LLGLSLShader			gDeferredAvatarAlphaProgram;
-LLGLSLShader			gDeferredLightProgram;
-LLGLSLShader			gDeferredMultiLightProgram[16];
-LLGLSLShader			gDeferredSpotLightProgram;
-LLGLSLShader			gDeferredMultiSpotLightProgram;
-LLGLSLShader			gDeferredSunProgram;
+LLGLSLShader            gDeferredAvatarProgram;
+LLGLSLShader            gDeferredAvatarAlphaProgram;
+LLGLSLShader            gDeferredLightProgram;
+LLGLSLShader            gDeferredMultiLightProgram[16];
+LLGLSLShader            gDeferredSpotLightProgram;
+LLGLSLShader            gDeferredMultiSpotLightProgram;
+LLGLSLShader            gDeferredSunProgram;
 LLGLSLShader            gHazeProgram;
 LLGLSLShader            gHazeWaterProgram;
-LLGLSLShader			gDeferredBlurLightProgram;
-LLGLSLShader			gDeferredSoftenProgram;
-LLGLSLShader			gDeferredShadowProgram;
+LLGLSLShader            gDeferredBlurLightProgram;
+LLGLSLShader            gDeferredSoftenProgram;
+LLGLSLShader            gDeferredShadowProgram;
 LLGLSLShader            gDeferredSkinnedShadowProgram;
-LLGLSLShader			gDeferredShadowCubeProgram;
-LLGLSLShader			gDeferredShadowAlphaMaskProgram;
+LLGLSLShader            gDeferredShadowCubeProgram;
+LLGLSLShader            gDeferredShadowAlphaMaskProgram;
 LLGLSLShader            gDeferredSkinnedShadowAlphaMaskProgram;
-LLGLSLShader			gDeferredShadowGLTFAlphaMaskProgram;
-LLGLSLShader			gDeferredSkinnedShadowGLTFAlphaMaskProgram;
+LLGLSLShader            gDeferredShadowGLTFAlphaMaskProgram;
+LLGLSLShader            gDeferredSkinnedShadowGLTFAlphaMaskProgram;
 LLGLSLShader            gDeferredShadowGLTFAlphaBlendProgram;
 LLGLSLShader            gDeferredSkinnedShadowGLTFAlphaBlendProgram;
-LLGLSLShader			gDeferredShadowFullbrightAlphaMaskProgram;
+LLGLSLShader            gDeferredShadowFullbrightAlphaMaskProgram;
 LLGLSLShader            gDeferredSkinnedShadowFullbrightAlphaMaskProgram;
-LLGLSLShader			gDeferredAvatarShadowProgram;
-LLGLSLShader			gDeferredAvatarAlphaShadowProgram;
-LLGLSLShader			gDeferredAvatarAlphaMaskShadowProgram;
-LLGLSLShader			gDeferredAlphaProgram;
-LLGLSLShader			gHUDAlphaProgram;
+LLGLSLShader            gDeferredAvatarShadowProgram;
+LLGLSLShader            gDeferredAvatarAlphaShadowProgram;
+LLGLSLShader            gDeferredAvatarAlphaMaskShadowProgram;
+LLGLSLShader            gDeferredAlphaProgram;
+LLGLSLShader            gHUDAlphaProgram;
 LLGLSLShader            gDeferredSkinnedAlphaProgram;
-LLGLSLShader			gDeferredAlphaImpostorProgram;
+LLGLSLShader            gDeferredAlphaImpostorProgram;
 LLGLSLShader            gDeferredSkinnedAlphaImpostorProgram;
-LLGLSLShader			gDeferredAvatarEyesProgram;
-LLGLSLShader			gDeferredFullbrightProgram;
+LLGLSLShader            gDeferredAvatarEyesProgram;
+LLGLSLShader            gDeferredFullbrightProgram;
 LLGLSLShader            gHUDFullbrightProgram;
-LLGLSLShader			gDeferredFullbrightAlphaMaskProgram;
-LLGLSLShader			gHUDFullbrightAlphaMaskProgram;
-LLGLSLShader			gDeferredFullbrightAlphaMaskAlphaProgram;
-LLGLSLShader			gHUDFullbrightAlphaMaskAlphaProgram;
-LLGLSLShader			gDeferredEmissiveProgram;
+LLGLSLShader            gDeferredFullbrightAlphaMaskProgram;
+LLGLSLShader            gHUDFullbrightAlphaMaskProgram;
+LLGLSLShader            gDeferredFullbrightAlphaMaskAlphaProgram;
+LLGLSLShader            gHUDFullbrightAlphaMaskAlphaProgram;
+LLGLSLShader            gDeferredEmissiveProgram;
 LLGLSLShader            gDeferredSkinnedEmissiveProgram;
-LLGLSLShader			gDeferredPostProgram;
-LLGLSLShader			gDeferredPostProgramNoNear;
-LLGLSLShader			gDeferredCoFProgram;
-LLGLSLShader			gDeferredDoFCombineProgram;
-LLGLSLShader			gDeferredPostGammaCorrectProgram;
+LLGLSLShader            gDeferredPostProgram;
+LLGLSLShader            gDeferredPostProgramNoNear;
+LLGLSLShader            gDeferredCoFProgram;
+LLGLSLShader            gDeferredDoFCombineProgram;
+LLGLSLShader            gDeferredPostGammaCorrectProgram;
 LLGLSLShader            gNoPostGammaCorrectProgram;
 LLGLSLShader            gLegacyPostGammaCorrectProgram;
-LLGLSLShader			gExposureProgram;
-LLGLSLShader			gExposureProgramNoFade;
-LLGLSLShader			gLuminanceProgram;
-LLGLSLShader			gFXAAProgram[4];
-LLGLSLShader			gDeferredPostNoDoFProgram;
-LLGLSLShader			gDeferredWLSkyProgram;
+LLGLSLShader            gExposureProgram;
+LLGLSLShader            gExposureProgramNoFade;
+LLGLSLShader            gLuminanceProgram;
+LLGLSLShader            gFXAAProgram[4];
+LLGLSLShader            gDeferredPostNoDoFProgram;
+LLGLSLShader            gDeferredWLSkyProgram;
 LLGLSLShader            gEnvironmentMapProgram;
-LLGLSLShader			gDeferredWLCloudProgram;
-LLGLSLShader			gDeferredWLSunProgram;
-LLGLSLShader			gDeferredWLMoonProgram;
-LLGLSLShader			gDeferredStarProgram;
-LLGLSLShader			gDeferredFullbrightShinyProgram;
+LLGLSLShader            gDeferredWLCloudProgram;
+LLGLSLShader            gDeferredWLSunProgram;
+LLGLSLShader            gDeferredWLMoonProgram;
+LLGLSLShader            gDeferredStarProgram;
+LLGLSLShader            gDeferredFullbrightShinyProgram;
 LLGLSLShader            gHUDFullbrightShinyProgram;
 LLGLSLShader            gDeferredSkinnedFullbrightShinyProgram;
-LLGLSLShader			gDeferredSkinnedFullbrightProgram;
+LLGLSLShader            gDeferredSkinnedFullbrightProgram;
 LLGLSLShader            gDeferredSkinnedFullbrightAlphaMaskProgram;
 LLGLSLShader            gDeferredSkinnedFullbrightAlphaMaskAlphaProgram;
-LLGLSLShader			gNormalMapGenProgram;
+LLGLSLShader            gNormalMapGenProgram;
 LLGLSLShader            gDeferredGenBrdfLutProgram;
 LLGLSLShader            gDeferredBufferVisualProgram;
 LLGLSLShader            gDeferredPostCASProgram;
-LLGLSLShader			gDeferredPostDLSProgram;
-LLGLSLShader			gDeferredPostTonemapProgram;
-LLGLSLShader			gDeferredPostTonemapACESProgram;
-LLGLSLShader			gDeferredPostTonemapUchiProgram;
-LLGLSLShader			gDeferredPostTonemapLPMProgram;
-LLGLSLShader			gDeferredPostTonemapHableProgram;
-LLGLSLShader			gDeferredPostColorCorrectProgram[3];
-LLGLSLShader			gDeferredPostColorCorrectLUTProgram[3];
+LLGLSLShader            gDeferredPostDLSProgram;
+LLGLSLShader            gDeferredPostTonemapProgram;
+LLGLSLShader            gDeferredPostTonemapACESProgram;
+LLGLSLShader            gDeferredPostTonemapUchiProgram;
+LLGLSLShader            gDeferredPostTonemapLPMProgram;
+LLGLSLShader            gDeferredPostTonemapHableProgram;
+LLGLSLShader            gDeferredPostColorCorrectProgram[3];
+LLGLSLShader            gDeferredPostColorCorrectLUTProgram[3];
 // [RLVa:KB] - @setsphere
-LLGLSLShader			gRlvSphereProgram;
+LLGLSLShader            gRlvSphereProgram;
 // [/RLVa:KB]
 
 // Deferred materials shaders
-LLGLSLShader			gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2];
-LLGLSLShader			gHUDPBROpaqueProgram;
+LLGLSLShader            gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2];
+LLGLSLShader            gHUDPBROpaqueProgram;
 LLGLSLShader            gPBRGlowProgram;
 LLGLSLShader            gPBRGlowSkinnedProgram;
-LLGLSLShader			gDeferredPBROpaqueProgram;
+LLGLSLShader            gDeferredPBROpaqueProgram;
 LLGLSLShader            gDeferredSkinnedPBROpaqueProgram;
 LLGLSLShader            gHUDPBRAlphaProgram;
 LLGLSLShader            gDeferredPBRAlphaProgram;
 LLGLSLShader            gDeferredSkinnedPBRAlphaProgram;
-LLGLSLShader			gDeferredPBRTerrainProgram;
+LLGLSLShader            gDeferredPBRTerrainProgram;
 
 //helper for making a rigged variant of a given shader
 static bool make_rigged_variant(LLGLSLShader& shader, LLGLSLShader& riggedShader)
@@ -290,15 +290,15 @@ static bool no_redundant_shaders(const std::vector<LLGLSLShader*>& shaders)
 
 
 LLViewerShaderMgr::LLViewerShaderMgr() :
-	mShaderLevel(SHADER_COUNT, 0),
-	mMaxAvatarShaderLevel(0)
-{   
+    mShaderLevel(SHADER_COUNT, 0),
+    mMaxAvatarShaderLevel(0)
+{
 }
 
 LLViewerShaderMgr::~LLViewerShaderMgr()
 {
-	mShaderLevel.clear();
-	mShaderList.clear();
+    mShaderLevel.clear();
+    mShaderList.clear();
 }
 
 void LLViewerShaderMgr::finalizeShaderList()
@@ -353,46 +353,46 @@ void LLViewerShaderMgr::finalizeShaderList()
     mShaderList.push_back(&gDeferredPostColorCorrectProgram[1]);
     mShaderList.push_back(&gDeferredPostColorCorrectLUTProgram[1]);
 
-    // make sure there are no redundancies 
+    // make sure there are no redundancies
     llassert(no_redundant_shaders(mShaderList));
 }
 
 // static
 LLViewerShaderMgr * LLViewerShaderMgr::instance()
 {
-	if(NULL == sInstance)
-	{
-		sInstance = new LLViewerShaderMgr();
-	}
+    if(NULL == sInstance)
+    {
+        sInstance = new LLViewerShaderMgr();
+    }
 
-	return static_cast<LLViewerShaderMgr*>(sInstance);
+    return static_cast<LLViewerShaderMgr*>(sInstance);
 }
 
 // static
 void LLViewerShaderMgr::releaseInstance()
 {
-	if (sInstance != NULL)
-	{
-		delete sInstance;
-		sInstance = NULL;
-	}
+    if (sInstance != NULL)
+    {
+        delete sInstance;
+        sInstance = NULL;
+    }
 }
 
 void LLViewerShaderMgr::initAttribsAndUniforms(void)
 {
-	if (mReservedAttribs.empty())
-	{
-		LLShaderMgr::initAttribsAndUniforms();
-	}	
+    if (mReservedAttribs.empty())
+    {
+        LLShaderMgr::initAttribsAndUniforms();
+    }
 }
-	
+
 
 //============================================================================
 // Set Levels
 
 S32 LLViewerShaderMgr::getShaderLevel(S32 type)
 {
-	return mShaderLevel[type];
+    return mShaderLevel[type];
 }
 
 //============================================================================
@@ -403,7 +403,7 @@ void LLViewerShaderMgr::setShaders()
     LL_PROFILE_ZONE_SCOPED;
     //setShaders might be called redundantly by gSavedSettings, so return on reentrance
     static bool reentrance = false;
-    
+
     if (!gPipeline.mInitialized || !sInitialized || reentrance || sSkipReload)
     {
         return;
@@ -420,25 +420,25 @@ void LLViewerShaderMgr::setShaders()
         return;
     }
 
-	{
-		static LLCachedControl<bool> shader_cache_enabled(gSavedSettings, "RenderShaderCacheEnabled", true);
-		static LLUUID old_cache_version;
-		static LLUUID current_cache_version;
-		if (current_cache_version.isNull())
-		{
-			HBXXH128 hash_obj;
-			hash_obj.update(LLVersionInfo::instance().getVersion());
-			current_cache_version = hash_obj.digest();
+    {
+        static LLCachedControl<bool> shader_cache_enabled(gSavedSettings, "RenderShaderCacheEnabled", true);
+        static LLUUID old_cache_version;
+        static LLUUID current_cache_version;
+        if (current_cache_version.isNull())
+        {
+            HBXXH128 hash_obj;
+            hash_obj.update(LLVersionInfo::instance().getVersion());
+            current_cache_version = hash_obj.digest();
 
-			old_cache_version = LLUUID(gSavedSettings.getString("RenderShaderCacheVersion"));
-			gSavedSettings.setString("RenderShaderCacheVersion", current_cache_version.asString());
-		}
+            old_cache_version = LLUUID(gSavedSettings.getString("RenderShaderCacheVersion"));
+            gSavedSettings.setString("RenderShaderCacheVersion", current_cache_version.asString());
+        }
 
-		initShaderCache(shader_cache_enabled, old_cache_version, current_cache_version);
-	}
+        initShaderCache(shader_cache_enabled, old_cache_version, current_cache_version);
+    }
 
     static LLCachedControl<U32> max_texture_index(gSavedSettings, "RenderMaxTextureIndex", 16);
-    
+
     // when using indexed texture rendering, leave some texture units available for shadow and reflection maps
     static LLCachedControl<S32> reserved_texture_units(gSavedSettings, "RenderReservedTextureIndices", 14);
 
@@ -450,14 +450,14 @@ void LLViewerShaderMgr::setShaders()
     // Make sure the compiled shader map is cleared before we recompile shaders.
     mVertexShaderObjects.clear();
     mFragmentShaderObjects.clear();
-    
+
     initAttribsAndUniforms();
     gPipeline.releaseGLBuffers();
 
-	unloadShaders();
+    unloadShaders();
+
+    LLPipeline::sRenderGlow = gSavedSettings.getBOOL("RenderGlow");
 
-    LLPipeline::sRenderGlow = gSavedSettings.getBOOL("RenderGlow"); 
-    
     if (gViewerWindow)
     {
         gViewerWindow->setCursor(UI_CURSOR_WAIT);
@@ -477,7 +477,7 @@ void LLViewerShaderMgr::setShaders()
 
     llassert((gGLManager.mGLSLVersionMajor > 1 || gGLManager.mGLSLVersionMinor >= 10));
 
-    
+
     S32 light_class = 3;
     S32 interface_class = 2;
     S32 env_class = 2;
@@ -516,7 +516,7 @@ void LLViewerShaderMgr::setShaders()
         loadBasicShaders();
         LLError::setDefaultLevel(lvl);
         LL_ERRS() << "Unable to load basic shader " << shader_name << ", verify graphics driver installed and current." << LL_ENDL;
-        reentrance = false; // For hygiene only, re-try probably helps nothing 
+        reentrance = false; // For hygiene only, re-try probably helps nothing
         return;
     }
 
@@ -572,7 +572,7 @@ void LLViewerShaderMgr::setShaders()
         { //hardware skinning is enabled and rigged attachment shaders loaded correctly
             // cloth is a class3 shader
             S32 avatar_class = 1;
-                
+
             // Set the actual level
             mShaderLevel[SHADER_AVATAR] = avatar_class;
 
@@ -589,7 +589,7 @@ void LLViewerShaderMgr::setShaders()
     loaded = loaded && loadShadersDeferred();
     llassert(loaded);
 
-	persistShaderCacheMetadata();
+    persistShaderCacheMetadata();
 
     if (gViewerWindow)
     {
@@ -604,68 +604,68 @@ void LLViewerShaderMgr::setShaders()
 
 void LLViewerShaderMgr::unloadShaders()
 {
-	while (!LLGLSLShader::sInstances.empty())
-	{
-		LLGLSLShader* shader = *(LLGLSLShader::sInstances.begin());
-		shader->unload();
-	}
-
-	mShaderLevel[SHADER_LIGHTING] = 0;
-	mShaderLevel[SHADER_OBJECT] = 0;
-	mShaderLevel[SHADER_AVATAR] = 0;
-	mShaderLevel[SHADER_ENVIRONMENT] = 0;
-	mShaderLevel[SHADER_WATER] = 0;
-	mShaderLevel[SHADER_INTERFACE] = 0;
-	mShaderLevel[SHADER_EFFECT] = 0;
-	mShaderLevel[SHADER_WINDLIGHT] = 0;
-
-	gPipeline.mShadersLoaded = false;
+    while (!LLGLSLShader::sInstances.empty())
+    {
+        LLGLSLShader* shader = *(LLGLSLShader::sInstances.begin());
+        shader->unload();
+    }
+
+    mShaderLevel[SHADER_LIGHTING] = 0;
+    mShaderLevel[SHADER_OBJECT] = 0;
+    mShaderLevel[SHADER_AVATAR] = 0;
+    mShaderLevel[SHADER_ENVIRONMENT] = 0;
+    mShaderLevel[SHADER_WATER] = 0;
+    mShaderLevel[SHADER_INTERFACE] = 0;
+    mShaderLevel[SHADER_EFFECT] = 0;
+    mShaderLevel[SHADER_WINDLIGHT] = 0;
+
+    gPipeline.mShadersLoaded = false;
 }
 
 std::string LLViewerShaderMgr::loadBasicShaders()
 {
-	// Load basic dependency shaders first
-	// All of these have to load for any shaders to function
-	
-	S32 sum_lights_class = 3;
-
-	// Use the feature table to mask out the max light level to use.  Also make sure it's at least 1.
-	S32 max_light_class = gSavedSettings.getS32("RenderShaderLightingMaxLevel");
-	sum_lights_class = llclamp(sum_lights_class, 1, max_light_class);
-
-	// Load the Basic Vertex Shaders at the appropriate level. 
-	// (in order of shader function call depth for reference purposes, deepest level first)
-
-	vector< pair<string, S32> > shaders;
-	shaders.push_back( make_pair( "windlight/atmosphericsVarsV.glsl",       mShaderLevel[SHADER_WINDLIGHT] ) );
-	shaders.push_back( make_pair( "windlight/atmosphericsHelpersV.glsl",    mShaderLevel[SHADER_WINDLIGHT] ) );
-	shaders.push_back( make_pair( "lighting/lightFuncV.glsl",               mShaderLevel[SHADER_LIGHTING] ) );
-	shaders.push_back( make_pair( "lighting/sumLightsV.glsl",               sum_lights_class ) );
-	shaders.push_back( make_pair( "lighting/lightV.glsl",                   mShaderLevel[SHADER_LIGHTING] ) );
-	shaders.push_back( make_pair( "lighting/lightFuncSpecularV.glsl",       mShaderLevel[SHADER_LIGHTING] ) );
-	shaders.push_back( make_pair( "lighting/sumLightsSpecularV.glsl",       sum_lights_class ) );
-	shaders.push_back( make_pair( "lighting/lightSpecularV.glsl",           mShaderLevel[SHADER_LIGHTING] ) );
+    // Load basic dependency shaders first
+    // All of these have to load for any shaders to function
+
+    S32 sum_lights_class = 3;
+
+    // Use the feature table to mask out the max light level to use.  Also make sure it's at least 1.
+    S32 max_light_class = gSavedSettings.getS32("RenderShaderLightingMaxLevel");
+    sum_lights_class = llclamp(sum_lights_class, 1, max_light_class);
+
+    // Load the Basic Vertex Shaders at the appropriate level.
+    // (in order of shader function call depth for reference purposes, deepest level first)
+
+    vector< pair<string, S32> > shaders;
+    shaders.push_back( make_pair( "windlight/atmosphericsVarsV.glsl",       mShaderLevel[SHADER_WINDLIGHT] ) );
+    shaders.push_back( make_pair( "windlight/atmosphericsHelpersV.glsl",    mShaderLevel[SHADER_WINDLIGHT] ) );
+    shaders.push_back( make_pair( "lighting/lightFuncV.glsl",               mShaderLevel[SHADER_LIGHTING] ) );
+    shaders.push_back( make_pair( "lighting/sumLightsV.glsl",               sum_lights_class ) );
+    shaders.push_back( make_pair( "lighting/lightV.glsl",                   mShaderLevel[SHADER_LIGHTING] ) );
+    shaders.push_back( make_pair( "lighting/lightFuncSpecularV.glsl",       mShaderLevel[SHADER_LIGHTING] ) );
+    shaders.push_back( make_pair( "lighting/sumLightsSpecularV.glsl",       sum_lights_class ) );
+    shaders.push_back( make_pair( "lighting/lightSpecularV.glsl",           mShaderLevel[SHADER_LIGHTING] ) );
     shaders.push_back( make_pair( "windlight/atmosphericsFuncs.glsl",       mShaderLevel[SHADER_WINDLIGHT] ) );
-	shaders.push_back( make_pair( "windlight/atmosphericsV.glsl",           mShaderLevel[SHADER_WINDLIGHT] ) );
+    shaders.push_back( make_pair( "windlight/atmosphericsV.glsl",           mShaderLevel[SHADER_WINDLIGHT] ) );
     shaders.push_back( make_pair( "environment/srgbF.glsl",                 1 ) );
-	shaders.push_back( make_pair( "avatar/avatarSkinV.glsl",                1 ) );
-	shaders.push_back( make_pair( "avatar/objectSkinV.glsl",                1 ) );
+    shaders.push_back( make_pair( "avatar/avatarSkinV.glsl",                1 ) );
+    shaders.push_back( make_pair( "avatar/objectSkinV.glsl",                1 ) );
     shaders.push_back( make_pair( "deferred/textureUtilV.glsl",             1 ) );
-	if (gGLManager.mGLSLVersionMajor >= 2 || gGLManager.mGLSLVersionMinor >= 30)
-	{
-		shaders.push_back( make_pair( "objects/indexedTextureV.glsl",           1 ) );
-	}
-	shaders.push_back( make_pair( "objects/nonindexedTextureV.glsl",        1 ) );
+    if (gGLManager.mGLSLVersionMajor >= 2 || gGLManager.mGLSLVersionMinor >= 30)
+    {
+        shaders.push_back( make_pair( "objects/indexedTextureV.glsl",           1 ) );
+    }
+    shaders.push_back( make_pair( "objects/nonindexedTextureV.glsl",        1 ) );
 
-	std::map<std::string, std::string> attribs;
-	attribs["MAX_JOINTS_PER_MESH_OBJECT"] = 
-		std::to_string(LLSkinningUtil::getMaxJointCount());
+    std::map<std::string, std::string> attribs;
+    attribs["MAX_JOINTS_PER_MESH_OBJECT"] =
+        std::to_string(LLSkinningUtil::getMaxJointCount());
 
     BOOL ssr = gSavedSettings.getBOOL("RenderScreenSpaceReflections");
 
-	bool has_reflection_probes = gSavedSettings.getBOOL("RenderReflectionsEnabled") && gGLManager.mGLVersion > 3.99f;
+    bool has_reflection_probes = gSavedSettings.getBOOL("RenderReflectionsEnabled") && gGLManager.mGLVersion > 3.99f;
 
-	S32 probe_level = llclamp(gSavedSettings.getS32("RenderReflectionProbeLevel"), 0, 3);
+    S32 probe_level = llclamp(gSavedSettings.getS32("RenderReflectionProbeLevel"), 0, 3);
 
     S32 shadow_detail            = gSavedSettings.getS32("RenderShadowDetail");
 
@@ -684,11 +684,11 @@ std::string LLViewerShaderMgr::loadBasicShaders()
         attribs["SSR"] = "1";
     }
 
-	if (has_reflection_probes)
-	{
+    if (has_reflection_probes)
+    {
         attribs["REFMAP_LEVEL"] = std::to_string(probe_level);
-		attribs["REF_SAMPLE_COUNT"] = "32";
-	}
+        attribs["REF_SAMPLE_COUNT"] = "32";
+    }
 
     { // PBR terrain
         const S32 mapping = clamp_terrain_mapping(gSavedSettings.getS32("RenderTerrainPBRPlanarSampleCount"));
@@ -700,94 +700,94 @@ std::string LLViewerShaderMgr::loadBasicShaders()
         attribs["TERRAIN_PBR_DETAIL"] = llformat("%d", detail);
     }
 
-	LLGLSLShader::sGlobalDefines = attribs;
+    LLGLSLShader::sGlobalDefines = attribs;
 
-	// We no longer have to bind the shaders to global glhandles, they are automatically added to a map now.
-	for (U32 i = 0; i < shaders.size(); i++)
-	{
-		// Note usage of GL_VERTEX_SHADER
-		if (loadShaderFile(shaders[i].first, shaders[i].second, GL_VERTEX_SHADER, &attribs) == 0)
-		{
-			LL_WARNS("Shader") << "Failed to load vertex shader " << shaders[i].first << LL_ENDL;
-			return shaders[i].first;
-		}
-	}
+    // We no longer have to bind the shaders to global glhandles, they are automatically added to a map now.
+    for (U32 i = 0; i < shaders.size(); i++)
+    {
+        // Note usage of GL_VERTEX_SHADER
+        if (loadShaderFile(shaders[i].first, shaders[i].second, GL_VERTEX_SHADER, &attribs) == 0)
+        {
+            LL_WARNS("Shader") << "Failed to load vertex shader " << shaders[i].first << LL_ENDL;
+            return shaders[i].first;
+        }
+    }
 
-	// Load the Basic Fragment Shaders at the appropriate level. 
-	// (in order of shader function call depth for reference purposes, deepest level first)
+    // Load the Basic Fragment Shaders at the appropriate level.
+    // (in order of shader function call depth for reference purposes, deepest level first)
 
-	shaders.clear();
-	S32 ch = 1;
+    shaders.clear();
+    S32 ch = 1;
 
-	if (gGLManager.mGLSLVersionMajor > 1 || gGLManager.mGLSLVersionMinor >= 30)
-	{ //use indexed texture rendering for GLSL >= 1.30
-		ch = llmax(LLGLSLShader::sIndexedTextureChannels, 1);
-	}
+    if (gGLManager.mGLSLVersionMajor > 1 || gGLManager.mGLSLVersionMinor >= 30)
+    { //use indexed texture rendering for GLSL >= 1.30
+        ch = llmax(LLGLSLShader::sIndexedTextureChannels, 1);
+    }
 
 
-	std::vector<S32> index_channels;    
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "windlight/atmosphericsVarsF.glsl",      mShaderLevel[SHADER_WINDLIGHT] ) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "windlight/atmosphericsHelpersF.glsl",       mShaderLevel[SHADER_WINDLIGHT] ) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "windlight/gammaF.glsl",                 mShaderLevel[SHADER_WINDLIGHT]) );
+    std::vector<S32> index_channels;
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "windlight/atmosphericsVarsF.glsl",      mShaderLevel[SHADER_WINDLIGHT] ) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "windlight/atmosphericsHelpersF.glsl",       mShaderLevel[SHADER_WINDLIGHT] ) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "windlight/gammaF.glsl",                 mShaderLevel[SHADER_WINDLIGHT]) );
     index_channels.push_back(-1);    shaders.push_back( make_pair( "windlight/atmosphericsFuncs.glsl",       mShaderLevel[SHADER_WINDLIGHT] ) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "windlight/atmosphericsF.glsl",          mShaderLevel[SHADER_WINDLIGHT] ) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "environment/waterFogF.glsl",                mShaderLevel[SHADER_WATER] ) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "environment/srgbF.glsl",                    mShaderLevel[SHADER_ENVIRONMENT] ) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/deferredUtil.glsl",                    1) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "windlight/atmosphericsF.glsl",          mShaderLevel[SHADER_WINDLIGHT] ) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "environment/waterFogF.glsl",                mShaderLevel[SHADER_WATER] ) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "environment/srgbF.glsl",                    mShaderLevel[SHADER_ENVIRONMENT] ) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/deferredUtil.glsl",                    1) );
     index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/globalF.glsl",                          1));
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/shadowUtil.glsl",                      1) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/aoUtil.glsl",                          1) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/pbrterrainUtilF.glsl",                 1) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/shadowUtil.glsl",                      1) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/aoUtil.glsl",                          1) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/pbrterrainUtilF.glsl",                 1) );
     index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/reflectionProbeF.glsl",                has_reflection_probes ? 3 : 2) );
     index_channels.push_back(-1);    shaders.push_back( make_pair( "deferred/screenSpaceReflUtil.glsl",             ssr ? 3 : 1) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "lighting/lightNonIndexedF.glsl",                    mShaderLevel[SHADER_LIGHTING] ) );
-	index_channels.push_back(-1);    shaders.push_back( make_pair( "lighting/lightAlphaMaskNonIndexedF.glsl",                   mShaderLevel[SHADER_LIGHTING] ) );
-	index_channels.push_back(ch);    shaders.push_back( make_pair( "lighting/lightF.glsl",                  mShaderLevel[SHADER_LIGHTING] ) );
-	index_channels.push_back(ch);    shaders.push_back( make_pair( "lighting/lightAlphaMaskF.glsl",                 mShaderLevel[SHADER_LIGHTING] ) );
-	
-	for (U32 i = 0; i < shaders.size(); i++)
-	{
-		// Note usage of GL_FRAGMENT_SHADER
-		if (loadShaderFile(shaders[i].first, shaders[i].second, GL_FRAGMENT_SHADER, &attribs, index_channels[i]) == 0)
-		{
-			LL_WARNS("Shader") << "Failed to load fragment shader " << shaders[i].first << LL_ENDL;
-			return shaders[i].first;
-		}
-	}
-
-	return std::string();
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "lighting/lightNonIndexedF.glsl",                    mShaderLevel[SHADER_LIGHTING] ) );
+    index_channels.push_back(-1);    shaders.push_back( make_pair( "lighting/lightAlphaMaskNonIndexedF.glsl",                   mShaderLevel[SHADER_LIGHTING] ) );
+    index_channels.push_back(ch);    shaders.push_back( make_pair( "lighting/lightF.glsl",                  mShaderLevel[SHADER_LIGHTING] ) );
+    index_channels.push_back(ch);    shaders.push_back( make_pair( "lighting/lightAlphaMaskF.glsl",                 mShaderLevel[SHADER_LIGHTING] ) );
+
+    for (U32 i = 0; i < shaders.size(); i++)
+    {
+        // Note usage of GL_FRAGMENT_SHADER
+        if (loadShaderFile(shaders[i].first, shaders[i].second, GL_FRAGMENT_SHADER, &attribs, index_channels[i]) == 0)
+        {
+            LL_WARNS("Shader") << "Failed to load fragment shader " << shaders[i].first << LL_ENDL;
+            return shaders[i].first;
+        }
+    }
+
+    return std::string();
 }
 
 BOOL LLViewerShaderMgr::loadShadersWater()
 {
     LL_PROFILE_ZONE_SCOPED;
-	BOOL success = TRUE;
-	BOOL terrainWaterSuccess = TRUE;
-    
+    BOOL success = TRUE;
+    BOOL terrainWaterSuccess = TRUE;
+
     bool use_sun_shadow = mShaderLevel[SHADER_DEFERRED] > 1 &&
         gSavedSettings.getS32("RenderShadowDetail") > 0;
 
-	if (mShaderLevel[SHADER_WATER] == 0)
-	{
-		gWaterProgram.unload();
-		gWaterEdgeProgram.unload();
-		gUnderWaterProgram.unload();
-		return TRUE;
-	}
-
-	if (success)
-	{
-		// load water shader
-		gWaterProgram.mName = "Water Shader";
-		gWaterProgram.mFeatures.calculatesAtmospherics = true;
+    if (mShaderLevel[SHADER_WATER] == 0)
+    {
+        gWaterProgram.unload();
+        gWaterEdgeProgram.unload();
+        gUnderWaterProgram.unload();
+        return TRUE;
+    }
+
+    if (success)
+    {
+        // load water shader
+        gWaterProgram.mName = "Water Shader";
+        gWaterProgram.mFeatures.calculatesAtmospherics = true;
         gWaterProgram.mFeatures.hasAtmospherics = true;
-		gWaterProgram.mFeatures.hasGamma = true;
-		gWaterProgram.mFeatures.hasSrgb = true;
+        gWaterProgram.mFeatures.hasGamma = true;
+        gWaterProgram.mFeatures.hasSrgb = true;
         gWaterProgram.mFeatures.hasReflectionProbes = true;
         gWaterProgram.mFeatures.hasShadows = use_sun_shadow;
-		gWaterProgram.mShaderFiles.clear();
-		gWaterProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER));
-		gWaterProgram.mShaderFiles.push_back(make_pair("environment/waterF.glsl", GL_FRAGMENT_SHADER));
+        gWaterProgram.mShaderFiles.clear();
+        gWaterProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER));
+        gWaterProgram.mShaderFiles.push_back(make_pair("environment/waterF.glsl", GL_FRAGMENT_SHADER));
         gWaterProgram.clearPermutations();
         if (LLPipeline::sRenderTransparentWater)
         {
@@ -799,27 +799,27 @@ BOOL LLViewerShaderMgr::loadShadersWater()
             gWaterProgram.addPermutation("HAS_SUN_SHADOW", "1");
         }
 
-		gWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
-		gWaterProgram.mShaderLevel = mShaderLevel[SHADER_WATER];
-		success = gWaterProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-	// load water shader
-		gWaterEdgeProgram.mName = "Water Edge Shader";
-		gWaterEdgeProgram.mFeatures.calculatesAtmospherics = true;
+        gWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
+        gWaterProgram.mShaderLevel = mShaderLevel[SHADER_WATER];
+        success = gWaterProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+    // load water shader
+        gWaterEdgeProgram.mName = "Water Edge Shader";
+        gWaterEdgeProgram.mFeatures.calculatesAtmospherics = true;
         gWaterEdgeProgram.mFeatures.hasAtmospherics = true;
-		gWaterEdgeProgram.mFeatures.hasGamma = true;
-		gWaterEdgeProgram.mFeatures.hasSrgb = true;
+        gWaterEdgeProgram.mFeatures.hasGamma = true;
+        gWaterEdgeProgram.mFeatures.hasSrgb = true;
         gWaterEdgeProgram.mFeatures.hasReflectionProbes = true;
         gWaterEdgeProgram.mFeatures.hasShadows = use_sun_shadow;
-		gWaterEdgeProgram.mShaderFiles.clear();
-		gWaterEdgeProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER));
-		gWaterEdgeProgram.mShaderFiles.push_back(make_pair("environment/waterF.glsl", GL_FRAGMENT_SHADER));
+        gWaterEdgeProgram.mShaderFiles.clear();
+        gWaterEdgeProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER));
+        gWaterEdgeProgram.mShaderFiles.push_back(make_pair("environment/waterF.glsl", GL_FRAGMENT_SHADER));
         gWaterEdgeProgram.clearPermutations();
-		gWaterEdgeProgram.addPermutation("WATER_EDGE", "1");
+        gWaterEdgeProgram.addPermutation("WATER_EDGE", "1");
         if (LLPipeline::sRenderTransparentWater)
         {
             gWaterEdgeProgram.addPermutation("TRANSPARENT_WATER", "1");
@@ -829,54 +829,54 @@ BOOL LLViewerShaderMgr::loadShadersWater()
         {
             gWaterEdgeProgram.addPermutation("HAS_SUN_SHADOW", "1");
         }
-		gWaterEdgeProgram.mShaderGroup = LLGLSLShader::SG_WATER;
-		gWaterEdgeProgram.mShaderLevel = mShaderLevel[SHADER_WATER];
-		success = gWaterEdgeProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		//load under water vertex shader
-		gUnderWaterProgram.mName = "Underwater Shader";
-		gUnderWaterProgram.mFeatures.calculatesAtmospherics = true;
-		gUnderWaterProgram.mFeatures.hasAtmospherics = true;
-		gUnderWaterProgram.mShaderFiles.clear();
-		gUnderWaterProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER));
-		gUnderWaterProgram.mShaderFiles.push_back(make_pair("environment/underWaterF.glsl", GL_FRAGMENT_SHADER));
-		gUnderWaterProgram.mShaderLevel = mShaderLevel[SHADER_WATER];        
-		gUnderWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;       
+        gWaterEdgeProgram.mShaderGroup = LLGLSLShader::SG_WATER;
+        gWaterEdgeProgram.mShaderLevel = mShaderLevel[SHADER_WATER];
+        success = gWaterEdgeProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        //load under water vertex shader
+        gUnderWaterProgram.mName = "Underwater Shader";
+        gUnderWaterProgram.mFeatures.calculatesAtmospherics = true;
+        gUnderWaterProgram.mFeatures.hasAtmospherics = true;
+        gUnderWaterProgram.mShaderFiles.clear();
+        gUnderWaterProgram.mShaderFiles.push_back(make_pair("environment/waterV.glsl", GL_VERTEX_SHADER));
+        gUnderWaterProgram.mShaderFiles.push_back(make_pair("environment/underWaterF.glsl", GL_FRAGMENT_SHADER));
+        gUnderWaterProgram.mShaderLevel = mShaderLevel[SHADER_WATER];
+        gUnderWaterProgram.mShaderGroup = LLGLSLShader::SG_WATER;
         gUnderWaterProgram.clearPermutations();
         if (LLPipeline::sRenderTransparentWater)
         {
             gUnderWaterProgram.addPermutation("TRANSPARENT_WATER", "1");
         }
-		success = gUnderWaterProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	/// Keep track of water shader levels
-	if (gWaterProgram.mShaderLevel != mShaderLevel[SHADER_WATER]
-		|| gUnderWaterProgram.mShaderLevel != mShaderLevel[SHADER_WATER])
-	{
-		mShaderLevel[SHADER_WATER] = llmin(gWaterProgram.mShaderLevel, gUnderWaterProgram.mShaderLevel);
-	}
-
-	if (!success)
-	{
-		mShaderLevel[SHADER_WATER] = 0;
-		return FALSE;
-	}
-
-	// if we failed to load the terrain water shaders and we need them (using class2 water),
-	// then drop down to class1 water.
-	if (mShaderLevel[SHADER_WATER] > 1 && !terrainWaterSuccess)
-	{
-		mShaderLevel[SHADER_WATER]--;
-		return loadShadersWater();
-	}
-	
-	LLWorld::getInstance()->updateWaterObjects();
+        success = gUnderWaterProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    /// Keep track of water shader levels
+    if (gWaterProgram.mShaderLevel != mShaderLevel[SHADER_WATER]
+        || gUnderWaterProgram.mShaderLevel != mShaderLevel[SHADER_WATER])
+    {
+        mShaderLevel[SHADER_WATER] = llmin(gWaterProgram.mShaderLevel, gUnderWaterProgram.mShaderLevel);
+    }
+
+    if (!success)
+    {
+        mShaderLevel[SHADER_WATER] = 0;
+        return FALSE;
+    }
+
+    // if we failed to load the terrain water shaders and we need them (using class2 water),
+    // then drop down to class1 water.
+    if (mShaderLevel[SHADER_WATER] > 1 && !terrainWaterSuccess)
+    {
+        mShaderLevel[SHADER_WATER]--;
+        return loadShadersWater();
+    }
+
+    LLWorld::getInstance()->updateWaterObjects();
 
     return TRUE;
 }
@@ -884,167 +884,167 @@ BOOL LLViewerShaderMgr::loadShadersWater()
 BOOL LLViewerShaderMgr::loadShadersEffects()
 {
     LL_PROFILE_ZONE_SCOPED;
-	BOOL success = TRUE;
-
-	if (mShaderLevel[SHADER_EFFECT] == 0)
-	{
-		gGlowProgram.unload();
-		gGlowExtractProgram.unload();
-		return TRUE;
-	}
-
-	if (success)
-	{
-		gGlowProgram.mName = "Glow Shader (Post)";
-		gGlowProgram.mShaderFiles.clear();
-		gGlowProgram.mShaderFiles.push_back(make_pair("effects/glowV.glsl", GL_VERTEX_SHADER));
-		gGlowProgram.mShaderFiles.push_back(make_pair("effects/glowF.glsl", GL_FRAGMENT_SHADER));
-		gGlowProgram.mShaderLevel = mShaderLevel[SHADER_EFFECT];
-		success = gGlowProgram.createShader(NULL, NULL);
-		if (!success)
-		{
-			LLPipeline::sRenderGlow = FALSE;
-		}
-	}
-	
-	if (success)
-	{
+    BOOL success = TRUE;
+
+    if (mShaderLevel[SHADER_EFFECT] == 0)
+    {
+        gGlowProgram.unload();
+        gGlowExtractProgram.unload();
+        return TRUE;
+    }
+
+    if (success)
+    {
+        gGlowProgram.mName = "Glow Shader (Post)";
+        gGlowProgram.mShaderFiles.clear();
+        gGlowProgram.mShaderFiles.push_back(make_pair("effects/glowV.glsl", GL_VERTEX_SHADER));
+        gGlowProgram.mShaderFiles.push_back(make_pair("effects/glowF.glsl", GL_FRAGMENT_SHADER));
+        gGlowProgram.mShaderLevel = mShaderLevel[SHADER_EFFECT];
+        success = gGlowProgram.createShader(NULL, NULL);
+        if (!success)
+        {
+            LLPipeline::sRenderGlow = FALSE;
+        }
+    }
+
+    if (success)
+    {
         const bool use_glow_noise = gSavedSettings.getBOOL("RenderGlowNoise");
         const std::string glow_noise_label = use_glow_noise ? " (+Noise)" : "";
 
-		gGlowExtractProgram.mName = llformat("Glow Extract Shader (Post)%s", glow_noise_label.c_str());
-		gGlowExtractProgram.mShaderFiles.clear();
-		gGlowExtractProgram.mShaderFiles.push_back(make_pair("effects/glowExtractV.glsl", GL_VERTEX_SHADER));
-		gGlowExtractProgram.mShaderFiles.push_back(make_pair("effects/glowExtractF.glsl", GL_FRAGMENT_SHADER));
-		gGlowExtractProgram.mShaderLevel = mShaderLevel[SHADER_EFFECT];
+        gGlowExtractProgram.mName = llformat("Glow Extract Shader (Post)%s", glow_noise_label.c_str());
+        gGlowExtractProgram.mShaderFiles.clear();
+        gGlowExtractProgram.mShaderFiles.push_back(make_pair("effects/glowExtractV.glsl", GL_VERTEX_SHADER));
+        gGlowExtractProgram.mShaderFiles.push_back(make_pair("effects/glowExtractF.glsl", GL_FRAGMENT_SHADER));
+        gGlowExtractProgram.mShaderLevel = mShaderLevel[SHADER_EFFECT];
 
         if (use_glow_noise)
         {
             gGlowExtractProgram.addPermutation("HAS_NOISE", "1");
         }
 
-		success = gGlowExtractProgram.createShader(NULL, NULL);
-		if (!success)
-		{
-			LLPipeline::sRenderGlow = FALSE;
-		}
-	}
-	
-	return success;
+        success = gGlowExtractProgram.createShader(NULL, NULL);
+        if (!success)
+        {
+            LLPipeline::sRenderGlow = FALSE;
+        }
+    }
+
+    return success;
 
 }
 
 BOOL LLViewerShaderMgr::loadShadersDeferred()
 {
     LL_PROFILE_ZONE_SCOPED;
-    bool use_sun_shadow = mShaderLevel[SHADER_DEFERRED] > 1 && 
+    bool use_sun_shadow = mShaderLevel[SHADER_DEFERRED] > 1 &&
         gSavedSettings.getS32("RenderShadowDetail") > 0;
 
-	if (mShaderLevel[SHADER_DEFERRED] == 0)
-	{
-		gDeferredTreeProgram.unload();
-		gDeferredTreeShadowProgram.unload();
+    if (mShaderLevel[SHADER_DEFERRED] == 0)
+    {
+        gDeferredTreeProgram.unload();
+        gDeferredTreeShadowProgram.unload();
         gDeferredSkinnedTreeShadowProgram.unload();
-		gDeferredDiffuseProgram.unload();
+        gDeferredDiffuseProgram.unload();
         gDeferredSkinnedDiffuseProgram.unload();
-		gDeferredDiffuseAlphaMaskProgram.unload();
+        gDeferredDiffuseAlphaMaskProgram.unload();
         gDeferredSkinnedDiffuseAlphaMaskProgram.unload();
-		gDeferredNonIndexedDiffuseAlphaMaskProgram.unload();
-		gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.unload();
-		gDeferredBumpProgram.unload();
+        gDeferredNonIndexedDiffuseAlphaMaskProgram.unload();
+        gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.unload();
+        gDeferredBumpProgram.unload();
         gDeferredSkinnedBumpProgram.unload();
-		gDeferredImpostorProgram.unload();
-		gDeferredTerrainProgram.unload();
-		gDeferredLightProgram.unload();
-		for (U32 i = 0; i < LL_DEFERRED_MULTI_LIGHT_COUNT; ++i)
-		{
-			gDeferredMultiLightProgram[i].unload();
-		}
-		gDeferredSpotLightProgram.unload();
-		gDeferredMultiSpotLightProgram.unload();
-		gDeferredSunProgram.unload();
-		gDeferredBlurLightProgram.unload();
-		gDeferredSoftenProgram.unload();
-		gDeferredShadowProgram.unload();
+        gDeferredImpostorProgram.unload();
+        gDeferredTerrainProgram.unload();
+        gDeferredLightProgram.unload();
+        for (U32 i = 0; i < LL_DEFERRED_MULTI_LIGHT_COUNT; ++i)
+        {
+            gDeferredMultiLightProgram[i].unload();
+        }
+        gDeferredSpotLightProgram.unload();
+        gDeferredMultiSpotLightProgram.unload();
+        gDeferredSunProgram.unload();
+        gDeferredBlurLightProgram.unload();
+        gDeferredSoftenProgram.unload();
+        gDeferredShadowProgram.unload();
         gDeferredSkinnedShadowProgram.unload();
-		gDeferredShadowCubeProgram.unload();
+        gDeferredShadowCubeProgram.unload();
         gDeferredShadowAlphaMaskProgram.unload();
         gDeferredSkinnedShadowAlphaMaskProgram.unload();
         gDeferredShadowGLTFAlphaMaskProgram.unload();
         gDeferredSkinnedShadowGLTFAlphaMaskProgram.unload();
         gDeferredShadowFullbrightAlphaMaskProgram.unload();
         gDeferredSkinnedShadowFullbrightAlphaMaskProgram.unload();
-		gDeferredAvatarShadowProgram.unload();
+        gDeferredAvatarShadowProgram.unload();
         gDeferredAvatarAlphaShadowProgram.unload();
         gDeferredAvatarAlphaMaskShadowProgram.unload();
-		gDeferredAvatarProgram.unload();
-		gDeferredAvatarAlphaProgram.unload();
-		gDeferredAlphaProgram.unload();
+        gDeferredAvatarProgram.unload();
+        gDeferredAvatarAlphaProgram.unload();
+        gDeferredAlphaProgram.unload();
         gHUDAlphaProgram.unload();
         gDeferredSkinnedAlphaProgram.unload();
-		gDeferredFullbrightProgram.unload();
+        gDeferredFullbrightProgram.unload();
         gHUDFullbrightProgram.unload();
-		gDeferredFullbrightAlphaMaskProgram.unload();
+        gDeferredFullbrightAlphaMaskProgram.unload();
         gHUDFullbrightAlphaMaskProgram.unload();
         gDeferredFullbrightAlphaMaskAlphaProgram.unload();
         gHUDFullbrightAlphaMaskAlphaProgram.unload();
-		gDeferredEmissiveProgram.unload();
+        gDeferredEmissiveProgram.unload();
         gDeferredSkinnedEmissiveProgram.unload();
-		gDeferredAvatarEyesProgram.unload();
-		gDeferredPostProgram.unload();		
-		gDeferredCoFProgram.unload();		
-		gDeferredDoFCombineProgram.unload();
+        gDeferredAvatarEyesProgram.unload();
+        gDeferredPostProgram.unload();
+        gDeferredCoFProgram.unload();
+        gDeferredDoFCombineProgram.unload();
         gExposureProgram.unload();
         gExposureProgramNoFade.unload();
         gLuminanceProgram.unload();
-		gDeferredPostGammaCorrectProgram.unload();
+        gDeferredPostGammaCorrectProgram.unload();
         gNoPostGammaCorrectProgram.unload();
         gLegacyPostGammaCorrectProgram.unload();
         for (auto i = 0; i < 4; ++i)
         {
             gFXAAProgram[i].unload();
-			gPostSMAAEdgeDetect[i].unload();
+            gPostSMAAEdgeDetect[i].unload();
             gPostSMAABlendWeights[i].unload();
             gPostSMAANeighborhoodBlend[i].unload();
         }
         gEnvironmentMapProgram.unload();
-		gDeferredWLSkyProgram.unload();
-		gDeferredWLCloudProgram.unload();
+        gDeferredWLSkyProgram.unload();
+        gDeferredWLCloudProgram.unload();
         gDeferredWLSunProgram.unload();
         gDeferredWLMoonProgram.unload();
-		gDeferredStarProgram.unload();
-		gDeferredFullbrightShinyProgram.unload();
+        gDeferredStarProgram.unload();
+        gDeferredFullbrightShinyProgram.unload();
         gHUDFullbrightShinyProgram.unload();
         gDeferredSkinnedFullbrightShinyProgram.unload();
-		gDeferredSkinnedFullbrightProgram.unload();
+        gDeferredSkinnedFullbrightProgram.unload();
         gDeferredSkinnedFullbrightAlphaMaskProgram.unload();
         gDeferredSkinnedFullbrightAlphaMaskAlphaProgram.unload();
 
         gDeferredHighlightProgram.unload();
-        
-		gNormalMapGenProgram.unload();
+
+        gNormalMapGenProgram.unload();
         gDeferredGenBrdfLutProgram.unload();
-		gDeferredBufferVisualProgram.unload();
-
-		for (U32 i = 0; i < LLMaterial::SHADER_COUNT*2; ++i)
-		{
-			gDeferredMaterialProgram[i].unload();
-		}
-
-		gDeferredPostCASProgram.unload();
-		gDeferredPostDLSProgram.unload();
-		gDeferredPostTonemapProgram.unload();
-		gDeferredPostTonemapACESProgram.unload();
-		gDeferredPostTonemapUchiProgram.unload();
-		gDeferredPostTonemapLPMProgram.unload();
-		gDeferredPostTonemapHableProgram.unload();
-		for (U32 i = 0; i < 3; ++i)
-		{
-			gDeferredPostColorCorrectProgram[i].unload();
-			gDeferredPostColorCorrectLUTProgram[i].unload();
-		}
-
-		gRlvSphereProgram.unload();
+        gDeferredBufferVisualProgram.unload();
+
+        for (U32 i = 0; i < LLMaterial::SHADER_COUNT*2; ++i)
+        {
+            gDeferredMaterialProgram[i].unload();
+        }
+
+        gDeferredPostCASProgram.unload();
+        gDeferredPostDLSProgram.unload();
+        gDeferredPostTonemapProgram.unload();
+        gDeferredPostTonemapACESProgram.unload();
+        gDeferredPostTonemapUchiProgram.unload();
+        gDeferredPostTonemapLPMProgram.unload();
+        gDeferredPostTonemapHableProgram.unload();
+        for (U32 i = 0; i < 3; ++i)
+        {
+            gDeferredPostColorCorrectProgram[i].unload();
+            gDeferredPostColorCorrectLUTProgram[i].unload();
+        }
+
+        gRlvSphereProgram.unload();
 
         gHUDPBROpaqueProgram.unload();
         gPBRGlowProgram.unload();
@@ -1052,95 +1052,95 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         gDeferredSkinnedPBROpaqueProgram.unload();
         gDeferredPBRAlphaProgram.unload();
         gDeferredSkinnedPBRAlphaProgram.unload();
-		gDeferredPBRTerrainProgram.unload();
+        gDeferredPBRTerrainProgram.unload();
 
-		return TRUE;
-	}
+        return TRUE;
+    }
 
-	BOOL success = TRUE;
+    BOOL success = TRUE;
 
     if (success)
-	{
-		gDeferredHighlightProgram.mName = "Deferred Highlight Shader";
-		gDeferredHighlightProgram.mShaderFiles.clear();
-		gDeferredHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightV.glsl", GL_VERTEX_SHADER));
-		gDeferredHighlightProgram.mShaderFiles.push_back(make_pair("deferred/highlightF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredHighlightProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];		
-		success = gDeferredHighlightProgram.createShader(NULL, NULL);
-	}
+    {
+        gDeferredHighlightProgram.mName = "Deferred Highlight Shader";
+        gDeferredHighlightProgram.mShaderFiles.clear();
+        gDeferredHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightV.glsl", GL_VERTEX_SHADER));
+        gDeferredHighlightProgram.mShaderFiles.push_back(make_pair("deferred/highlightF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredHighlightProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gDeferredHighlightProgram.createShader(NULL, NULL);
+    }
 
-	if (success)
-	{
-		gDeferredDiffuseProgram.mName = "Deferred Diffuse Shader";
+    if (success)
+    {
+        gDeferredDiffuseProgram.mName = "Deferred Diffuse Shader";
         gDeferredDiffuseProgram.mFeatures.hasSrgb = true;
-		gDeferredDiffuseProgram.mShaderFiles.clear();
-		gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER));
-		gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseIndexedF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredDiffuseProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
-		gDeferredDiffuseProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredDiffuseProgram.mShaderFiles.clear();
+        gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER));
+        gDeferredDiffuseProgram.mShaderFiles.push_back(make_pair("deferred/diffuseIndexedF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredDiffuseProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
+        gDeferredDiffuseProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = make_rigged_variant(gDeferredDiffuseProgram, gDeferredSkinnedDiffuseProgram);
-		success = success && gDeferredDiffuseProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredDiffuseAlphaMaskProgram.mName = "Deferred Diffuse Alpha Mask Shader";
-		gDeferredDiffuseAlphaMaskProgram.mShaderFiles.clear();
-		gDeferredDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER));
-		gDeferredDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseAlphaMaskIndexedF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredDiffuseAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
-		gDeferredDiffuseAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = success && gDeferredDiffuseProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredDiffuseAlphaMaskProgram.mName = "Deferred Diffuse Alpha Mask Shader";
+        gDeferredDiffuseAlphaMaskProgram.mShaderFiles.clear();
+        gDeferredDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER));
+        gDeferredDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseAlphaMaskIndexedF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredDiffuseAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
+        gDeferredDiffuseAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = make_rigged_variant(gDeferredDiffuseAlphaMaskProgram, gDeferredSkinnedDiffuseAlphaMaskProgram);
-		success = success && gDeferredDiffuseAlphaMaskProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredNonIndexedDiffuseAlphaMaskProgram.mName = "Deferred Diffuse Non-Indexed Alpha Mask Shader";
-		gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderFiles.clear();
-		gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER));
-		gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseAlphaMaskF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredNonIndexedDiffuseAlphaMaskProgram.createShader(NULL, NULL);
+        success = success && gDeferredDiffuseAlphaMaskProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredNonIndexedDiffuseAlphaMaskProgram.mName = "Deferred Diffuse Non-Indexed Alpha Mask Shader";
+        gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderFiles.clear();
+        gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseV.glsl", GL_VERTEX_SHADER));
+        gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/diffuseAlphaMaskF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredNonIndexedDiffuseAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredNonIndexedDiffuseAlphaMaskProgram.createShader(NULL, NULL);
         llassert(success);
-	}
-    
-	if (success)
-	{
-		gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mName = "Deferred Diffuse Non-Indexed Alpha Mask No Color Shader";
-		gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderFiles.clear();
-		gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("deferred/diffuseNoColorV.glsl", GL_VERTEX_SHADER));
-		gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("deferred/diffuseAlphaMaskNoColorF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredBumpProgram.mName = "Deferred Bump Shader";
-		gDeferredBumpProgram.mShaderFiles.clear();
-		gDeferredBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpV.glsl", GL_VERTEX_SHADER));
-		gDeferredBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredBumpProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+    }
+
+    if (success)
+    {
+        gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mName = "Deferred Diffuse Non-Indexed Alpha Mask No Color Shader";
+        gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderFiles.clear();
+        gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("deferred/diffuseNoColorV.glsl", GL_VERTEX_SHADER));
+        gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("deferred/diffuseAlphaMaskNoColorF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredBumpProgram.mName = "Deferred Bump Shader";
+        gDeferredBumpProgram.mShaderFiles.clear();
+        gDeferredBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpV.glsl", GL_VERTEX_SHADER));
+        gDeferredBumpProgram.mShaderFiles.push_back(make_pair("deferred/bumpF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredBumpProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = make_rigged_variant(gDeferredBumpProgram, gDeferredSkinnedBumpProgram);
-		success = success && gDeferredBumpProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	gDeferredMaterialProgram[1].mFeatures.hasLighting = false;
-	gDeferredMaterialProgram[5].mFeatures.hasLighting = false;
-	gDeferredMaterialProgram[9].mFeatures.hasLighting = false;
-	gDeferredMaterialProgram[13].mFeatures.hasLighting = false;
-	gDeferredMaterialProgram[1+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false;
-	gDeferredMaterialProgram[5+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false;
-	gDeferredMaterialProgram[9+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false;
-	gDeferredMaterialProgram[13+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false;
-
-	for (U32 i = 0; i < LLMaterial::SHADER_COUNT*2; ++i)
-	{
-		if (success)
-		{
+        success = success && gDeferredBumpProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    gDeferredMaterialProgram[1].mFeatures.hasLighting = false;
+    gDeferredMaterialProgram[5].mFeatures.hasLighting = false;
+    gDeferredMaterialProgram[9].mFeatures.hasLighting = false;
+    gDeferredMaterialProgram[13].mFeatures.hasLighting = false;
+    gDeferredMaterialProgram[1+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false;
+    gDeferredMaterialProgram[5+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false;
+    gDeferredMaterialProgram[9+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false;
+    gDeferredMaterialProgram[13+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = false;
+
+    for (U32 i = 0; i < LLMaterial::SHADER_COUNT*2; ++i)
+    {
+        if (success)
+        {
             bool has_skin = i & 0x10;
 
             if (!has_skin)
@@ -1152,28 +1152,28 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
             {
                 gDeferredMaterialProgram[i].mName = llformat("Skinned Material Shader %d", i);
             }
-			
-			U32 alpha_mode = i & 0x3;
 
-			gDeferredMaterialProgram[i].mShaderFiles.clear();
-			gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER));
-			gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER));
-			gDeferredMaterialProgram[i].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+            U32 alpha_mode = i & 0x3;
+
+            gDeferredMaterialProgram[i].mShaderFiles.clear();
+            gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialV.glsl", GL_VERTEX_SHADER));
+            gDeferredMaterialProgram[i].mShaderFiles.push_back(make_pair("deferred/materialF.glsl", GL_FRAGMENT_SHADER));
+            gDeferredMaterialProgram[i].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
 
-			gDeferredMaterialProgram[i].clearPermutations();
+            gDeferredMaterialProgram[i].clearPermutations();
 
-			bool has_normal_map   = (i & 0x8) > 0;
-			bool has_specular_map = (i & 0x4) > 0;
+            bool has_normal_map   = (i & 0x8) > 0;
+            bool has_specular_map = (i & 0x4) > 0;
 
-			if (has_normal_map)
-			{
-				gDeferredMaterialProgram[i].addPermutation("HAS_NORMAL_MAP", "1");
-			}
+            if (has_normal_map)
+            {
+                gDeferredMaterialProgram[i].addPermutation("HAS_NORMAL_MAP", "1");
+            }
 
-			if (has_specular_map)
-			{
-				gDeferredMaterialProgram[i].addPermutation("HAS_SPECULAR_MAP", "1");
-			}
+            if (has_specular_map)
+            {
+                gDeferredMaterialProgram[i].addPermutation("HAS_SPECULAR_MAP", "1");
+            }
 
             gDeferredMaterialProgram[i].addPermutation("DIFFUSE_ALPHA_MODE", llformat("%d", alpha_mode));
 
@@ -1188,7 +1188,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
                 gDeferredMaterialProgram[i].addPermutation("HAS_SUN_SHADOW", "1");
             }
 
-            
+
             gDeferredMaterialProgram[i].mFeatures.hasSrgb = true;
             gDeferredMaterialProgram[i].mFeatures.calculatesAtmospherics = true;
             gDeferredMaterialProgram[i].mFeatures.hasAtmospherics = true;
@@ -1208,17 +1208,17 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
 
             success = gDeferredMaterialProgram[i].createShader(NULL, NULL);
             llassert(success);
-		}
-	}
+        }
+    }
 
-	gDeferredMaterialProgram[1].mFeatures.hasLighting = true;
-	gDeferredMaterialProgram[5].mFeatures.hasLighting = true;
-	gDeferredMaterialProgram[9].mFeatures.hasLighting = true;
-	gDeferredMaterialProgram[13].mFeatures.hasLighting = true;
-	gDeferredMaterialProgram[1+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
-	gDeferredMaterialProgram[5+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
-	gDeferredMaterialProgram[9+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
-	gDeferredMaterialProgram[13+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
+    gDeferredMaterialProgram[1].mFeatures.hasLighting = true;
+    gDeferredMaterialProgram[5].mFeatures.hasLighting = true;
+    gDeferredMaterialProgram[9].mFeatures.hasLighting = true;
+    gDeferredMaterialProgram[13].mFeatures.hasLighting = true;
+    gDeferredMaterialProgram[1+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
+    gDeferredMaterialProgram[5+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
+    gDeferredMaterialProgram[9+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
+    gDeferredMaterialProgram[13+LLMaterial::SHADER_COUNT].mFeatures.hasLighting = true;
 
     if (success)
     {
@@ -1230,7 +1230,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         gDeferredPBROpaqueProgram.mShaderFiles.push_back(make_pair("deferred/pbropaqueF.glsl", GL_FRAGMENT_SHADER));
         gDeferredPBROpaqueProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         gDeferredPBROpaqueProgram.clearPermutations();
-        
+
         success = make_rigged_variant(gDeferredPBROpaqueProgram, gDeferredSkinnedPBROpaqueProgram);
         if (success)
         {
@@ -1268,17 +1268,17 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         gHUDPBROpaqueProgram.addPermutation("IS_HUD", "1");
 
         success = gHUDPBROpaqueProgram.createShader(NULL, NULL);
- 
+
         llassert(success);
     }
 
-    
 
-	if (success)
-	{
+
+    if (success)
+    {
         LLGLSLShader* shader = &gDeferredPBRAlphaProgram;
         shader->mName = "Deferred PBR Alpha Shader";
-                          
+
         shader->mFeatures.calculatesLighting = false;
         shader->mFeatures.hasLighting = false;
         shader->mFeatures.isAlphaLighting = true;
@@ -1331,7 +1331,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         shader->mName = "HUD PBR Alpha Shader";
 
         shader->mFeatures.hasSrgb = true;
-        
+
         shader->mShaderFiles.clear();
         shader->mShaderFiles.push_back(make_pair("deferred/pbralphaV.glsl", GL_VERTEX_SHADER));
         shader->mShaderFiles.push_back(make_pair("deferred/pbralphaF.glsl", GL_FRAGMENT_SHADER));
@@ -1345,8 +1345,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
+    if (success)
+    {
         S32 detail = gSavedSettings.getS32("RenderTerrainPBRDetail");
         detail = llclamp(detail, TERRAIN_PBR_DETAIL_MIN, TERRAIN_PBR_DETAIL_MAX);
         const S32 mapping = clamp_terrain_mapping(gSavedSettings.getS32("RenderTerrainPBRPlanarSampleCount"));
@@ -1370,29 +1370,29 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         gDeferredPBRTerrainProgram.addPermutation("TERRAIN_PLANAR_TEXTURE_SAMPLE_COUNT", llformat("%d", mapping));
         success = gDeferredPBRTerrainProgram.createShader(NULL, NULL);
         llassert(success);
-	}
-	
-	if (success)
-	{
-		gDeferredTreeProgram.mName = "Deferred Tree Shader";
-		gDeferredTreeProgram.mShaderFiles.clear();
-		gDeferredTreeProgram.mShaderFiles.push_back(make_pair("deferred/treeV.glsl", GL_VERTEX_SHADER));
-		gDeferredTreeProgram.mShaderFiles.push_back(make_pair("deferred/treeF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredTreeProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredTreeProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredTreeShadowProgram.mName = "Deferred Tree Shadow Shader";
-		gDeferredTreeShadowProgram.mShaderFiles.clear();
-		gDeferredTreeShadowProgram.mShaderFiles.push_back(make_pair("deferred/treeShadowV.glsl", GL_VERTEX_SHADER));
-		gDeferredTreeShadowProgram.mShaderFiles.push_back(make_pair("deferred/treeShadowF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredTreeShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+    }
+
+    if (success)
+    {
+        gDeferredTreeProgram.mName = "Deferred Tree Shader";
+        gDeferredTreeProgram.mShaderFiles.clear();
+        gDeferredTreeProgram.mShaderFiles.push_back(make_pair("deferred/treeV.glsl", GL_VERTEX_SHADER));
+        gDeferredTreeProgram.mShaderFiles.push_back(make_pair("deferred/treeF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredTreeProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredTreeProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredTreeShadowProgram.mName = "Deferred Tree Shadow Shader";
+        gDeferredTreeShadowProgram.mShaderFiles.clear();
+        gDeferredTreeShadowProgram.mShaderFiles.push_back(make_pair("deferred/treeShadowV.glsl", GL_VERTEX_SHADER));
+        gDeferredTreeShadowProgram.mShaderFiles.push_back(make_pair("deferred/treeShadowF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredTreeShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         gDeferredTreeShadowProgram.mRiggedVariant = &gDeferredSkinnedTreeShadowProgram;
-		success = gDeferredTreeShadowProgram.createShader(NULL, NULL);
+        success = gDeferredTreeShadowProgram.createShader(NULL, NULL);
         llassert(success);
-	}
+    }
 
     if (success)
     {
@@ -1406,99 +1406,99 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
-		gDeferredImpostorProgram.mName = "Deferred Impostor Shader";
-		gDeferredImpostorProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredImpostorProgram.mFeatures.hasGamma = true;
-		gDeferredImpostorProgram.mFeatures.hasTransport = true;
-		gDeferredImpostorProgram.mFeatures.hasSrgb = true;
-		gDeferredImpostorProgram.mShaderFiles.clear();
-		gDeferredImpostorProgram.mShaderFiles.push_back(make_pair("deferred/impostorV.glsl", GL_VERTEX_SHADER));
+    if (success)
+    {
+        gDeferredImpostorProgram.mName = "Deferred Impostor Shader";
+        gDeferredImpostorProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredImpostorProgram.mFeatures.hasGamma = true;
+        gDeferredImpostorProgram.mFeatures.hasTransport = true;
+        gDeferredImpostorProgram.mFeatures.hasSrgb = true;
+        gDeferredImpostorProgram.mShaderFiles.clear();
+        gDeferredImpostorProgram.mShaderFiles.push_back(make_pair("deferred/impostorV.glsl", GL_VERTEX_SHADER));
         gDeferredImpostorProgram.mShaderFiles.push_back(make_pair("deferred/impostorF.glsl", GL_FRAGMENT_SHADER));
         gDeferredImpostorProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = gDeferredImpostorProgram.createShader(NULL, NULL);
         llassert(success);
-	}
+    }
 
-	if (success)
-	{       
-		gDeferredLightProgram.mName = "Deferred Light Shader";
-		gDeferredLightProgram.mFeatures.isDeferred = true;
-		gDeferredLightProgram.mFeatures.hasShadows = true;
+    if (success)
+    {
+        gDeferredLightProgram.mName = "Deferred Light Shader";
+        gDeferredLightProgram.mFeatures.isDeferred = true;
+        gDeferredLightProgram.mFeatures.hasShadows = true;
         gDeferredLightProgram.mFeatures.hasSrgb = true;
 
-		gDeferredLightProgram.mShaderFiles.clear();
-		gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER));
-		gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredLightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredLightProgram.mShaderFiles.clear();
+        gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER));
+        gDeferredLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredLightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
 
         gDeferredLightProgram.clearPermutations();
 
-		success = gDeferredLightProgram.createShader(NULL, NULL);
+        success = gDeferredLightProgram.createShader(NULL, NULL);
         llassert(success);
-	}
-
-	for (U32 i = 0; i < LL_DEFERRED_MULTI_LIGHT_COUNT; i++)
-	{
-		if (success)
-		{
-			gDeferredMultiLightProgram[i].mName = llformat("Deferred MultiLight Shader %d", i);
-			gDeferredMultiLightProgram[i].mFeatures.isDeferred = true;
-			gDeferredMultiLightProgram[i].mFeatures.hasShadows = true;
+    }
+
+    for (U32 i = 0; i < LL_DEFERRED_MULTI_LIGHT_COUNT; i++)
+    {
+        if (success)
+        {
+            gDeferredMultiLightProgram[i].mName = llformat("Deferred MultiLight Shader %d", i);
+            gDeferredMultiLightProgram[i].mFeatures.isDeferred = true;
+            gDeferredMultiLightProgram[i].mFeatures.hasShadows = true;
             gDeferredMultiLightProgram[i].mFeatures.hasSrgb = true;
 
             gDeferredMultiLightProgram[i].clearPermutations();
-			gDeferredMultiLightProgram[i].mShaderFiles.clear();
-			gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER));
-			gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER));
-			gDeferredMultiLightProgram[i].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-			gDeferredMultiLightProgram[i].addPermutation("LIGHT_COUNT", llformat("%d", i+1));
+            gDeferredMultiLightProgram[i].mShaderFiles.clear();
+            gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER));
+            gDeferredMultiLightProgram[i].mShaderFiles.push_back(make_pair("deferred/multiPointLightF.glsl", GL_FRAGMENT_SHADER));
+            gDeferredMultiLightProgram[i].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+            gDeferredMultiLightProgram[i].addPermutation("LIGHT_COUNT", llformat("%d", i+1));
 
-			success = gDeferredMultiLightProgram[i].createShader(NULL, NULL);
+            success = gDeferredMultiLightProgram[i].createShader(NULL, NULL);
             llassert(success);
-		}
-	}
+        }
+    }
 
-	if (success)
-	{
-		gDeferredSpotLightProgram.mName = "Deferred SpotLight Shader";
-		gDeferredSpotLightProgram.mShaderFiles.clear();
-		gDeferredSpotLightProgram.mFeatures.hasSrgb = true;
-		gDeferredSpotLightProgram.mFeatures.isDeferred = true;
-		gDeferredSpotLightProgram.mFeatures.hasShadows = true;
+    if (success)
+    {
+        gDeferredSpotLightProgram.mName = "Deferred SpotLight Shader";
+        gDeferredSpotLightProgram.mShaderFiles.clear();
+        gDeferredSpotLightProgram.mFeatures.hasSrgb = true;
+        gDeferredSpotLightProgram.mFeatures.isDeferred = true;
+        gDeferredSpotLightProgram.mFeatures.hasShadows = true;
 
         gDeferredSpotLightProgram.clearPermutations();
-		gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER));
-		gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredSpotLightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/pointLightV.glsl", GL_VERTEX_SHADER));
+        gDeferredSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredSpotLightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
 
-		success = gDeferredSpotLightProgram.createShader(NULL, NULL);
+        success = gDeferredSpotLightProgram.createShader(NULL, NULL);
         llassert(success);
-	}
+    }
 
-	if (success)
-	{
-		gDeferredMultiSpotLightProgram.mName = "Deferred MultiSpotLight Shader";
-		gDeferredMultiSpotLightProgram.mFeatures.hasSrgb = true;
-		gDeferredMultiSpotLightProgram.mFeatures.isDeferred = true;
-		gDeferredMultiSpotLightProgram.mFeatures.hasShadows = true;
+    if (success)
+    {
+        gDeferredMultiSpotLightProgram.mName = "Deferred MultiSpotLight Shader";
+        gDeferredMultiSpotLightProgram.mFeatures.hasSrgb = true;
+        gDeferredMultiSpotLightProgram.mFeatures.isDeferred = true;
+        gDeferredMultiSpotLightProgram.mFeatures.hasShadows = true;
 
         gDeferredMultiSpotLightProgram.clearPermutations();
         gDeferredMultiSpotLightProgram.addPermutation("MULTI_SPOTLIGHT", "1");
-		gDeferredMultiSpotLightProgram.mShaderFiles.clear();
-		gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER));
-		gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredMultiSpotLightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredMultiSpotLightProgram.mShaderFiles.clear();
+        gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/multiPointLightV.glsl", GL_VERTEX_SHADER));
+        gDeferredMultiSpotLightProgram.mShaderFiles.push_back(make_pair("deferred/spotLightF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredMultiSpotLightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
 
-		success = gDeferredMultiSpotLightProgram.createShader(NULL, NULL);
+        success = gDeferredMultiSpotLightProgram.createShader(NULL, NULL);
         llassert(success);
-	}
+    }
 
-	if (success)
-	{
-		std::string fragment;
-		std::string vertex = "deferred/sunLightV.glsl";
+    if (success)
+    {
+        std::string fragment;
+        std::string vertex = "deferred/sunLightV.glsl";
 
         bool use_ao = gSavedSettings.getBOOL("RenderDeferredSSAO");
 
@@ -1521,30 +1521,30 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         gDeferredSunProgram.mFeatures.hasAmbientOcclusion = use_ao;
 
         gDeferredSunProgram.mShaderFiles.clear();
-		gDeferredSunProgram.mShaderFiles.push_back(make_pair(vertex, GL_VERTEX_SHADER));
-		gDeferredSunProgram.mShaderFiles.push_back(make_pair(fragment, GL_FRAGMENT_SHADER));
-		gDeferredSunProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredSunProgram.mShaderFiles.push_back(make_pair(vertex, GL_VERTEX_SHADER));
+        gDeferredSunProgram.mShaderFiles.push_back(make_pair(fragment, GL_FRAGMENT_SHADER));
+        gDeferredSunProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
 
         success = gDeferredSunProgram.createShader(NULL, NULL);
         llassert(success);
-	}
+    }
 
-	if (success)
-	{
-		gDeferredBlurLightProgram.mName = "Deferred Blur Light Shader";
-		gDeferredBlurLightProgram.mFeatures.isDeferred = true;
+    if (success)
+    {
+        gDeferredBlurLightProgram.mName = "Deferred Blur Light Shader";
+        gDeferredBlurLightProgram.mFeatures.isDeferred = true;
 
-		gDeferredBlurLightProgram.mShaderFiles.clear();
-		gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightV.glsl", GL_VERTEX_SHADER));
-		gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredBlurLightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredBlurLightProgram.mShaderFiles.clear();
+        gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightV.glsl", GL_VERTEX_SHADER));
+        gDeferredBlurLightProgram.mShaderFiles.push_back(make_pair("deferred/blurLightF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredBlurLightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
 
-		success = gDeferredBlurLightProgram.createShader(NULL, NULL);
+        success = gDeferredBlurLightProgram.createShader(NULL, NULL);
         llassert(success);
-	}
+    }
 
-	if (success)
-	{
+    if (success)
+    {
         for (int i = 0; i < 3 && success; ++i)
         {
             LLGLSLShader* shader = nullptr;
@@ -1617,9 +1617,9 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
 
     if (success)
     {
-        LLGLSLShader* shaders[] = { 
-            &gDeferredAlphaImpostorProgram, 
-            &gDeferredSkinnedAlphaImpostorProgram 
+        LLGLSLShader* shaders[] = {
+            &gDeferredAlphaImpostorProgram,
+            &gDeferredSkinnedAlphaImpostorProgram
         };
 
         for (int i = 0; i < 2 && success; ++i)
@@ -1674,40 +1674,40 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         }
     }
 
-	if (success)
-	{
-		gDeferredAvatarEyesProgram.mName = "Deferred Avatar Eyes Shader";
-		gDeferredAvatarEyesProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredAvatarEyesProgram.mFeatures.hasGamma = true;
-		gDeferredAvatarEyesProgram.mFeatures.hasAtmospherics = true;
-		gDeferredAvatarEyesProgram.mFeatures.disableTextureIndex = true;
-		gDeferredAvatarEyesProgram.mFeatures.hasSrgb = true;
-		gDeferredAvatarEyesProgram.mFeatures.hasShadows = true;
-
-		gDeferredAvatarEyesProgram.mShaderFiles.clear();
-		gDeferredAvatarEyesProgram.mShaderFiles.push_back(make_pair("deferred/avatarEyesV.glsl", GL_VERTEX_SHADER));
-		gDeferredAvatarEyesProgram.mShaderFiles.push_back(make_pair("deferred/diffuseF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredAvatarEyesProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredAvatarEyesProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredFullbrightProgram.mName = "Deferred Fullbright Shader";
-		gDeferredFullbrightProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredFullbrightProgram.mFeatures.hasGamma = true;
-		gDeferredFullbrightProgram.mFeatures.hasAtmospherics = true;
-		gDeferredFullbrightProgram.mFeatures.hasSrgb = true;
-		gDeferredFullbrightProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
-		gDeferredFullbrightProgram.mShaderFiles.clear();
-		gDeferredFullbrightProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER));
-		gDeferredFullbrightProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredFullbrightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+    if (success)
+    {
+        gDeferredAvatarEyesProgram.mName = "Deferred Avatar Eyes Shader";
+        gDeferredAvatarEyesProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredAvatarEyesProgram.mFeatures.hasGamma = true;
+        gDeferredAvatarEyesProgram.mFeatures.hasAtmospherics = true;
+        gDeferredAvatarEyesProgram.mFeatures.disableTextureIndex = true;
+        gDeferredAvatarEyesProgram.mFeatures.hasSrgb = true;
+        gDeferredAvatarEyesProgram.mFeatures.hasShadows = true;
+
+        gDeferredAvatarEyesProgram.mShaderFiles.clear();
+        gDeferredAvatarEyesProgram.mShaderFiles.push_back(make_pair("deferred/avatarEyesV.glsl", GL_VERTEX_SHADER));
+        gDeferredAvatarEyesProgram.mShaderFiles.push_back(make_pair("deferred/diffuseF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredAvatarEyesProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredAvatarEyesProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredFullbrightProgram.mName = "Deferred Fullbright Shader";
+        gDeferredFullbrightProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredFullbrightProgram.mFeatures.hasGamma = true;
+        gDeferredFullbrightProgram.mFeatures.hasAtmospherics = true;
+        gDeferredFullbrightProgram.mFeatures.hasSrgb = true;
+        gDeferredFullbrightProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
+        gDeferredFullbrightProgram.mShaderFiles.clear();
+        gDeferredFullbrightProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER));
+        gDeferredFullbrightProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredFullbrightProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = make_rigged_variant(gDeferredFullbrightProgram, gDeferredSkinnedFullbrightProgram);
-		success = gDeferredFullbrightProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
+        success = gDeferredFullbrightProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
 
     if (success)
     {
@@ -1727,24 +1727,24 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
-		gDeferredFullbrightAlphaMaskProgram.mName = "Deferred Fullbright Alpha Masking Shader";
-		gDeferredFullbrightAlphaMaskProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredFullbrightAlphaMaskProgram.mFeatures.hasGamma = true;
-		gDeferredFullbrightAlphaMaskProgram.mFeatures.hasAtmospherics = true;
-		gDeferredFullbrightAlphaMaskProgram.mFeatures.hasSrgb = true;		
-		gDeferredFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
-		gDeferredFullbrightAlphaMaskProgram.mShaderFiles.clear();
-		gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER));
-		gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER));
+    if (success)
+    {
+        gDeferredFullbrightAlphaMaskProgram.mName = "Deferred Fullbright Alpha Masking Shader";
+        gDeferredFullbrightAlphaMaskProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredFullbrightAlphaMaskProgram.mFeatures.hasGamma = true;
+        gDeferredFullbrightAlphaMaskProgram.mFeatures.hasAtmospherics = true;
+        gDeferredFullbrightAlphaMaskProgram.mFeatures.hasSrgb = true;
+        gDeferredFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
+        gDeferredFullbrightAlphaMaskProgram.mShaderFiles.clear();
+        gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightV.glsl", GL_VERTEX_SHADER));
+        gDeferredFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightF.glsl", GL_FRAGMENT_SHADER));
         gDeferredFullbrightAlphaMaskProgram.clearPermutations();
-		gDeferredFullbrightAlphaMaskProgram.addPermutation("HAS_ALPHA_MASK","1");
-		gDeferredFullbrightAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredFullbrightAlphaMaskProgram.addPermutation("HAS_ALPHA_MASK","1");
+        gDeferredFullbrightAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = make_rigged_variant(gDeferredFullbrightAlphaMaskProgram, gDeferredSkinnedFullbrightAlphaMaskProgram);
-		success = success && gDeferredFullbrightAlphaMaskProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
+        success = success && gDeferredFullbrightAlphaMaskProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
 
     if (success)
     {
@@ -1807,23 +1807,23 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
-		gDeferredFullbrightShinyProgram.mName = "Deferred FullbrightShiny Shader";
-		gDeferredFullbrightShinyProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredFullbrightShinyProgram.mFeatures.hasAtmospherics = true;
-		gDeferredFullbrightShinyProgram.mFeatures.hasGamma = true;
-		gDeferredFullbrightShinyProgram.mFeatures.hasSrgb = true;
-		gDeferredFullbrightShinyProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
-		gDeferredFullbrightShinyProgram.mShaderFiles.clear();
-		gDeferredFullbrightShinyProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightShinyV.glsl", GL_VERTEX_SHADER));
-		gDeferredFullbrightShinyProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightShinyF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredFullbrightShinyProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+    if (success)
+    {
+        gDeferredFullbrightShinyProgram.mName = "Deferred FullbrightShiny Shader";
+        gDeferredFullbrightShinyProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredFullbrightShinyProgram.mFeatures.hasAtmospherics = true;
+        gDeferredFullbrightShinyProgram.mFeatures.hasGamma = true;
+        gDeferredFullbrightShinyProgram.mFeatures.hasSrgb = true;
+        gDeferredFullbrightShinyProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
+        gDeferredFullbrightShinyProgram.mShaderFiles.clear();
+        gDeferredFullbrightShinyProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightShinyV.glsl", GL_VERTEX_SHADER));
+        gDeferredFullbrightShinyProgram.mShaderFiles.push_back(make_pair("deferred/fullbrightShinyF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredFullbrightShinyProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         gDeferredFullbrightShinyProgram.mFeatures.hasReflectionProbes = true;
         success = make_rigged_variant(gDeferredFullbrightShinyProgram, gDeferredSkinnedFullbrightShinyProgram);
-		success = success && gDeferredFullbrightShinyProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
+        success = success && gDeferredFullbrightShinyProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
 
     if (success)
     {
@@ -1844,54 +1844,54 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
-		gDeferredEmissiveProgram.mName = "Deferred Emissive Shader";
-		gDeferredEmissiveProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredEmissiveProgram.mFeatures.hasGamma = true;
-		gDeferredEmissiveProgram.mFeatures.hasAtmospherics = true;
-		gDeferredEmissiveProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
-		gDeferredEmissiveProgram.mShaderFiles.clear();
-		gDeferredEmissiveProgram.mShaderFiles.push_back(make_pair("deferred/emissiveV.glsl", GL_VERTEX_SHADER));
-		gDeferredEmissiveProgram.mShaderFiles.push_back(make_pair("deferred/emissiveF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredEmissiveProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+    if (success)
+    {
+        gDeferredEmissiveProgram.mName = "Deferred Emissive Shader";
+        gDeferredEmissiveProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredEmissiveProgram.mFeatures.hasGamma = true;
+        gDeferredEmissiveProgram.mFeatures.hasAtmospherics = true;
+        gDeferredEmissiveProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
+        gDeferredEmissiveProgram.mShaderFiles.clear();
+        gDeferredEmissiveProgram.mShaderFiles.push_back(make_pair("deferred/emissiveV.glsl", GL_VERTEX_SHADER));
+        gDeferredEmissiveProgram.mShaderFiles.push_back(make_pair("deferred/emissiveF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredEmissiveProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = make_rigged_variant(gDeferredEmissiveProgram, gDeferredSkinnedEmissiveProgram);
-		success = success && gDeferredEmissiveProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredSoftenProgram.mName = "Deferred Soften Shader";
-		gDeferredSoftenProgram.mShaderFiles.clear();
-		gDeferredSoftenProgram.mFeatures.hasSrgb = true;
-		gDeferredSoftenProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredSoftenProgram.mFeatures.hasAtmospherics = true;
-		gDeferredSoftenProgram.mFeatures.hasGamma = true;
-		gDeferredSoftenProgram.mFeatures.isDeferred = true;
-		gDeferredSoftenProgram.mFeatures.hasShadows = use_sun_shadow;
+        success = success && gDeferredEmissiveProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredSoftenProgram.mName = "Deferred Soften Shader";
+        gDeferredSoftenProgram.mShaderFiles.clear();
+        gDeferredSoftenProgram.mFeatures.hasSrgb = true;
+        gDeferredSoftenProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredSoftenProgram.mFeatures.hasAtmospherics = true;
+        gDeferredSoftenProgram.mFeatures.hasGamma = true;
+        gDeferredSoftenProgram.mFeatures.isDeferred = true;
+        gDeferredSoftenProgram.mFeatures.hasShadows = use_sun_shadow;
         gDeferredSoftenProgram.mFeatures.hasReflectionProbes = mShaderLevel[SHADER_DEFERRED] > 2;
 
         gDeferredSoftenProgram.clearPermutations();
-		gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER));
-		gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightV.glsl", GL_VERTEX_SHADER));
+        gDeferredSoftenProgram.mShaderFiles.push_back(make_pair("deferred/softenLightF.glsl", GL_FRAGMENT_SHADER));
 
-		gDeferredSoftenProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredSoftenProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
 
         if (use_sun_shadow)
         {
             gDeferredSoftenProgram.addPermutation("HAS_SUN_SHADOW", "1");
         }
 
-		if (gSavedSettings.getBOOL("RenderDeferredSSAO"))
-		{ //if using SSAO, take screen space light map into account as if shadows are enabled
-			gDeferredSoftenProgram.mShaderLevel = llmax(gDeferredSoftenProgram.mShaderLevel, 2);
+        if (gSavedSettings.getBOOL("RenderDeferredSSAO"))
+        { //if using SSAO, take screen space light map into account as if shadows are enabled
+            gDeferredSoftenProgram.mShaderLevel = llmax(gDeferredSoftenProgram.mShaderLevel, 2);
             gDeferredSoftenProgram.addPermutation("HAS_SSAO", "1");
-		}
-				
-		success = gDeferredSoftenProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
+        }
+
+        success = gDeferredSoftenProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
 
     if (success)
     {
@@ -1940,17 +1940,17 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
     }
 
 
-	if (success)
-	{
-		gDeferredShadowProgram.mName = "Deferred Shadow Shader";
-		gDeferredShadowProgram.mShaderFiles.clear();
-		gDeferredShadowProgram.mShaderFiles.push_back(make_pair("deferred/shadowV.glsl", GL_VERTEX_SHADER));
-		gDeferredShadowProgram.mShaderFiles.push_back(make_pair("deferred/shadowF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredShadowProgram.mRiggedVariant = &gDeferredSkinnedShadowProgram;
-		success = gDeferredShadowProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
+    if (success)
+    {
+        gDeferredShadowProgram.mName = "Deferred Shadow Shader";
+        gDeferredShadowProgram.mShaderFiles.clear();
+        gDeferredShadowProgram.mShaderFiles.push_back(make_pair("deferred/shadowV.glsl", GL_VERTEX_SHADER));
+        gDeferredShadowProgram.mShaderFiles.push_back(make_pair("deferred/shadowF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredShadowProgram.mRiggedVariant = &gDeferredSkinnedShadowProgram;
+        success = gDeferredShadowProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
 
     if (success)
     {
@@ -1967,52 +1967,52 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
-		gDeferredShadowCubeProgram.mName = "Deferred Shadow Cube Shader";
-		gDeferredShadowCubeProgram.mFeatures.isDeferred = true;
-		gDeferredShadowCubeProgram.mFeatures.hasShadows = true;
-		gDeferredShadowCubeProgram.mShaderFiles.clear();
-		gDeferredShadowCubeProgram.mShaderFiles.push_back(make_pair("deferred/shadowCubeV.glsl", GL_VERTEX_SHADER));
-		gDeferredShadowCubeProgram.mShaderFiles.push_back(make_pair("deferred/shadowF.glsl", GL_FRAGMENT_SHADER));
-		// gDeferredShadowCubeProgram.addPermutation("DEPTH_CLAMP", "1");
-		gDeferredShadowCubeProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredShadowCubeProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredShadowFullbrightAlphaMaskProgram.mName = "Deferred Shadow Fullbright Alpha Mask Shader";
-		gDeferredShadowFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
-
-		gDeferredShadowFullbrightAlphaMaskProgram.mShaderFiles.clear();
-		gDeferredShadowFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/shadowAlphaMaskV.glsl", GL_VERTEX_SHADER));
-		gDeferredShadowFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/shadowAlphaMaskF.glsl", GL_FRAGMENT_SHADER));
+    if (success)
+    {
+        gDeferredShadowCubeProgram.mName = "Deferred Shadow Cube Shader";
+        gDeferredShadowCubeProgram.mFeatures.isDeferred = true;
+        gDeferredShadowCubeProgram.mFeatures.hasShadows = true;
+        gDeferredShadowCubeProgram.mShaderFiles.clear();
+        gDeferredShadowCubeProgram.mShaderFiles.push_back(make_pair("deferred/shadowCubeV.glsl", GL_VERTEX_SHADER));
+        gDeferredShadowCubeProgram.mShaderFiles.push_back(make_pair("deferred/shadowF.glsl", GL_FRAGMENT_SHADER));
+        // gDeferredShadowCubeProgram.addPermutation("DEPTH_CLAMP", "1");
+        gDeferredShadowCubeProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredShadowCubeProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredShadowFullbrightAlphaMaskProgram.mName = "Deferred Shadow Fullbright Alpha Mask Shader";
+        gDeferredShadowFullbrightAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
+
+        gDeferredShadowFullbrightAlphaMaskProgram.mShaderFiles.clear();
+        gDeferredShadowFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/shadowAlphaMaskV.glsl", GL_VERTEX_SHADER));
+        gDeferredShadowFullbrightAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/shadowAlphaMaskF.glsl", GL_FRAGMENT_SHADER));
 
         gDeferredShadowFullbrightAlphaMaskProgram.clearPermutations();
-		gDeferredShadowFullbrightAlphaMaskProgram.addPermutation("DEPTH_CLAMP", "1");
+        gDeferredShadowFullbrightAlphaMaskProgram.addPermutation("DEPTH_CLAMP", "1");
         gDeferredShadowFullbrightAlphaMaskProgram.addPermutation("IS_FULLBRIGHT", "1");
-		gDeferredShadowFullbrightAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredShadowFullbrightAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = make_rigged_variant(gDeferredShadowFullbrightAlphaMaskProgram, gDeferredSkinnedShadowFullbrightAlphaMaskProgram);
         success = success && gDeferredShadowFullbrightAlphaMaskProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-    
-    if (success)
-	{
-		gDeferredShadowAlphaMaskProgram.mName = "Deferred Shadow Alpha Mask Shader";
-		gDeferredShadowAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
-
-		gDeferredShadowAlphaMaskProgram.mShaderFiles.clear();
-		gDeferredShadowAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/shadowAlphaMaskV.glsl", GL_VERTEX_SHADER));
-		gDeferredShadowAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/shadowAlphaMaskF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredShadowAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredShadowAlphaMaskProgram.mName = "Deferred Shadow Alpha Mask Shader";
+        gDeferredShadowAlphaMaskProgram.mFeatures.mIndexedTextureChannels = LLGLSLShader::sIndexedTextureChannels;
+
+        gDeferredShadowAlphaMaskProgram.mShaderFiles.clear();
+        gDeferredShadowAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/shadowAlphaMaskV.glsl", GL_VERTEX_SHADER));
+        gDeferredShadowAlphaMaskProgram.mShaderFiles.push_back(make_pair("deferred/shadowAlphaMaskF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredShadowAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = make_rigged_variant(gDeferredShadowAlphaMaskProgram, gDeferredSkinnedShadowAlphaMaskProgram);
         success = success && gDeferredShadowAlphaMaskProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-    
+        llassert(success);
+    }
+
 
     if (success)
     {
@@ -2040,108 +2040,108 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
-		gDeferredAvatarShadowProgram.mName = "Deferred Avatar Shadow Shader";
-		gDeferredAvatarShadowProgram.mFeatures.hasSkinning = true;
-
-		gDeferredAvatarShadowProgram.mShaderFiles.clear();
-		gDeferredAvatarShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarShadowV.glsl", GL_VERTEX_SHADER));
-		gDeferredAvatarShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarShadowF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredAvatarShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredAvatarShadowProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredAvatarAlphaShadowProgram.mName = "Deferred Avatar Alpha Shadow Shader";
-		gDeferredAvatarAlphaShadowProgram.mFeatures.hasSkinning = true;
-		gDeferredAvatarAlphaShadowProgram.mShaderFiles.clear();
-		gDeferredAvatarAlphaShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaShadowV.glsl", GL_VERTEX_SHADER));
-		gDeferredAvatarAlphaShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaShadowF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredAvatarAlphaShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredAvatarAlphaShadowProgram.createShader(NULL, NULL);
+    if (success)
+    {
+        gDeferredAvatarShadowProgram.mName = "Deferred Avatar Shadow Shader";
+        gDeferredAvatarShadowProgram.mFeatures.hasSkinning = true;
+
+        gDeferredAvatarShadowProgram.mShaderFiles.clear();
+        gDeferredAvatarShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarShadowV.glsl", GL_VERTEX_SHADER));
+        gDeferredAvatarShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarShadowF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredAvatarShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredAvatarShadowProgram.createShader(NULL, NULL);
         llassert(success);
-	}
-    if (success)
-	{
-		gDeferredAvatarAlphaMaskShadowProgram.mName = "Deferred Avatar Alpha Mask Shadow Shader";
-		gDeferredAvatarAlphaMaskShadowProgram.mFeatures.hasSkinning  = true;
-		gDeferredAvatarAlphaMaskShadowProgram.mShaderFiles.clear();
-		gDeferredAvatarAlphaMaskShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaShadowV.glsl", GL_VERTEX_SHADER));
-		gDeferredAvatarAlphaMaskShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaMaskShadowF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredAvatarAlphaMaskShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredAvatarAlphaMaskShadowProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredAvatarAlphaShadowProgram.mName = "Deferred Avatar Alpha Shadow Shader";
+        gDeferredAvatarAlphaShadowProgram.mFeatures.hasSkinning = true;
+        gDeferredAvatarAlphaShadowProgram.mShaderFiles.clear();
+        gDeferredAvatarAlphaShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaShadowV.glsl", GL_VERTEX_SHADER));
+        gDeferredAvatarAlphaShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaShadowF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredAvatarAlphaShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredAvatarAlphaShadowProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+    if (success)
+    {
+        gDeferredAvatarAlphaMaskShadowProgram.mName = "Deferred Avatar Alpha Mask Shadow Shader";
+        gDeferredAvatarAlphaMaskShadowProgram.mFeatures.hasSkinning  = true;
+        gDeferredAvatarAlphaMaskShadowProgram.mShaderFiles.clear();
+        gDeferredAvatarAlphaMaskShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaShadowV.glsl", GL_VERTEX_SHADER));
+        gDeferredAvatarAlphaMaskShadowProgram.mShaderFiles.push_back(make_pair("deferred/avatarAlphaMaskShadowF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredAvatarAlphaMaskShadowProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredAvatarAlphaMaskShadowProgram.createShader(NULL, NULL);
         llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredTerrainProgram.mName = "Deferred Terrain Shader";
-		gDeferredTerrainProgram.mFeatures.hasSrgb = true;
-		gDeferredTerrainProgram.mFeatures.isAlphaLighting = true;
-		gDeferredTerrainProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels
-		gDeferredTerrainProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredTerrainProgram.mFeatures.hasAtmospherics = true;
-		gDeferredTerrainProgram.mFeatures.hasGamma = true;
-
-		gDeferredTerrainProgram.mShaderFiles.clear();
-		gDeferredTerrainProgram.mShaderFiles.push_back(make_pair("deferred/terrainV.glsl", GL_VERTEX_SHADER));
-		gDeferredTerrainProgram.mShaderFiles.push_back(make_pair("deferred/terrainF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredTerrainProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+    }
+
+    if (success)
+    {
+        gDeferredTerrainProgram.mName = "Deferred Terrain Shader";
+        gDeferredTerrainProgram.mFeatures.hasSrgb = true;
+        gDeferredTerrainProgram.mFeatures.isAlphaLighting = true;
+        gDeferredTerrainProgram.mFeatures.disableTextureIndex = true; //hack to disable auto-setup of texture channels
+        gDeferredTerrainProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredTerrainProgram.mFeatures.hasAtmospherics = true;
+        gDeferredTerrainProgram.mFeatures.hasGamma = true;
+
+        gDeferredTerrainProgram.mShaderFiles.clear();
+        gDeferredTerrainProgram.mShaderFiles.push_back(make_pair("deferred/terrainV.glsl", GL_VERTEX_SHADER));
+        gDeferredTerrainProgram.mShaderFiles.push_back(make_pair("deferred/terrainF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredTerrainProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         success = gDeferredTerrainProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredAvatarProgram.mName = "Deferred Avatar Shader";
-		gDeferredAvatarProgram.mFeatures.hasSkinning = true;
-		gDeferredAvatarProgram.mShaderFiles.clear();
-		gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarV.glsl", GL_VERTEX_SHADER));
-		gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredAvatarProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredAvatarProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredAvatarAlphaProgram.mName = "Deferred Avatar Alpha Shader";
-		gDeferredAvatarAlphaProgram.mFeatures.hasSkinning = true;
-		gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = false;
-		gDeferredAvatarAlphaProgram.mFeatures.hasLighting = false;
-		gDeferredAvatarAlphaProgram.mFeatures.isAlphaLighting = true;
-		gDeferredAvatarAlphaProgram.mFeatures.disableTextureIndex = true;
-		gDeferredAvatarAlphaProgram.mFeatures.hasSrgb = true;
-		gDeferredAvatarAlphaProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredAvatarAlphaProgram.mFeatures.hasAtmospherics = true;
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredAvatarProgram.mName = "Deferred Avatar Shader";
+        gDeferredAvatarProgram.mFeatures.hasSkinning = true;
+        gDeferredAvatarProgram.mShaderFiles.clear();
+        gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarV.glsl", GL_VERTEX_SHADER));
+        gDeferredAvatarProgram.mShaderFiles.push_back(make_pair("deferred/avatarF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredAvatarProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredAvatarProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredAvatarAlphaProgram.mName = "Deferred Avatar Alpha Shader";
+        gDeferredAvatarAlphaProgram.mFeatures.hasSkinning = true;
+        gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = false;
+        gDeferredAvatarAlphaProgram.mFeatures.hasLighting = false;
+        gDeferredAvatarAlphaProgram.mFeatures.isAlphaLighting = true;
+        gDeferredAvatarAlphaProgram.mFeatures.disableTextureIndex = true;
+        gDeferredAvatarAlphaProgram.mFeatures.hasSrgb = true;
+        gDeferredAvatarAlphaProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredAvatarAlphaProgram.mFeatures.hasAtmospherics = true;
         gDeferredAvatarAlphaProgram.mFeatures.hasGamma = true;
         gDeferredAvatarAlphaProgram.mFeatures.isDeferred = true;
-		gDeferredAvatarAlphaProgram.mFeatures.hasShadows = true;
+        gDeferredAvatarAlphaProgram.mFeatures.hasShadows = true;
         gDeferredAvatarAlphaProgram.mFeatures.hasReflectionProbes = true;
 
-		gDeferredAvatarAlphaProgram.mShaderFiles.clear();
+        gDeferredAvatarAlphaProgram.mShaderFiles.clear();
         gDeferredAvatarAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaV.glsl", GL_VERTEX_SHADER));
         gDeferredAvatarAlphaProgram.mShaderFiles.push_back(make_pair("deferred/alphaF.glsl", GL_FRAGMENT_SHADER));
 
-		gDeferredAvatarAlphaProgram.clearPermutations();
-		gDeferredAvatarAlphaProgram.addPermutation("USE_DIFFUSE_TEX", "1");
-		gDeferredAvatarAlphaProgram.addPermutation("IS_AVATAR_SKIN", "1");
-		if (use_sun_shadow)
-		{
-			gDeferredAvatarAlphaProgram.addPermutation("HAS_SUN_SHADOW", "1");
-		}
+        gDeferredAvatarAlphaProgram.clearPermutations();
+        gDeferredAvatarAlphaProgram.addPermutation("USE_DIFFUSE_TEX", "1");
+        gDeferredAvatarAlphaProgram.addPermutation("IS_AVATAR_SKIN", "1");
+        if (use_sun_shadow)
+        {
+            gDeferredAvatarAlphaProgram.addPermutation("HAS_SUN_SHADOW", "1");
+        }
 
-		gDeferredAvatarAlphaProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredAvatarAlphaProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
 
-		success = gDeferredAvatarAlphaProgram.createShader(NULL, NULL);
-		llassert(success);
+        success = gDeferredAvatarAlphaProgram.createShader(NULL, NULL);
+        llassert(success);
 
-		gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = true;
-		gDeferredAvatarAlphaProgram.mFeatures.hasLighting = true;
-	}
+        gDeferredAvatarAlphaProgram.mFeatures.calculatesLighting = true;
+        gDeferredAvatarAlphaProgram.mFeatures.hasLighting = true;
+    }
 
     if (success)
     {
@@ -2184,20 +2184,20 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
-		gDeferredPostGammaCorrectProgram.mName = "Deferred Gamma Correction Post Process";
-		gDeferredPostGammaCorrectProgram.mFeatures.hasSrgb = true;
-		gDeferredPostGammaCorrectProgram.mFeatures.isDeferred = true;
-		gDeferredPostGammaCorrectProgram.mShaderFiles.clear();
+    if (success)
+    {
+        gDeferredPostGammaCorrectProgram.mName = "Deferred Gamma Correction Post Process";
+        gDeferredPostGammaCorrectProgram.mFeatures.hasSrgb = true;
+        gDeferredPostGammaCorrectProgram.mFeatures.isDeferred = true;
+        gDeferredPostGammaCorrectProgram.mShaderFiles.clear();
         gDeferredPostGammaCorrectProgram.clearPermutations();
         gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredGammaCorrect.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostGammaCorrectProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredGammaCorrect.glsl", GL_FRAGMENT_SHADER));
         gDeferredPostGammaCorrectProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredPostGammaCorrectProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-    
+        success = gDeferredPostGammaCorrectProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
     if (success)
     {
         gNoPostGammaCorrectProgram.mName = "No Post Gamma Correction Post Process";
@@ -2228,8 +2228,8 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
+    if (success)
+    {
         std::vector<std::pair<std::string, std::string>> smaa_preset_pair = {{"12", "Low"},
                                                                              {"23", "Medium"},
                                                                              {"29", "High"},
@@ -2245,16 +2245,16 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
                 gFXAAProgram[i].mShaderFiles.push_back(make_pair("deferred/postDeferredV.glsl", GL_VERTEX_SHADER));
                 gFXAAProgram[i].mShaderFiles.push_back(make_pair("deferred/fxaaF.glsl", GL_FRAGMENT_SHADER));
                 gFXAAProgram[i].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-				gFXAAProgram[i].clearPermutations();
+                gFXAAProgram[i].clearPermutations();
                 gFXAAProgram[i].addPermutation("FXAA_QUALITY__PRESET", fxaa_pair.first);
-				if(gGLManager.mGLVersion > 3.9)
-				{
-					gFXAAProgram[i].addPermutation("FXAA_GLSL_400", "1");
-				}
-				else
-				{
-					gFXAAProgram[i].addPermutation("FXAA_GLSL_130", "1");
-				}
+                if(gGLManager.mGLVersion > 3.9)
+                {
+                    gFXAAProgram[i].addPermutation("FXAA_GLSL_400", "1");
+                }
+                else
+                {
+                    gFXAAProgram[i].addPermutation("FXAA_GLSL_130", "1");
+                }
                 success = gFXAAProgram[i].createShader(NULL, NULL);
                 llassert(success);
             }
@@ -2263,7 +2263,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
     }
 
 #if 0
-	if (success && gGLManager.mGLVersion > 3.9f)
+    if (success && gGLManager.mGLVersion > 3.9f)
     {
         std::vector<std::pair<std::string, std::string>> smaa_preset_pair = {{"SMAA_PRESET_LOW", "Low"},
                                                                              {"SMAA_PRESET_MEDIUM", "Medium"},
@@ -2275,12 +2275,12 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
             std::map<std::string, std::string> defines;
             if (gGLManager.mGLVersion >= 4.f)
                 defines.emplace("SMAA_GLSL_4", "1");
-			else if (gGLManager.mGLVersion >= 3.1f)
-				defines.emplace("SMAA_GLSL_3", "1");
+            else if (gGLManager.mGLVersion >= 3.1f)
+                defines.emplace("SMAA_GLSL_3", "1");
             else
                 defines.emplace("SMAA_GLSL_2", "1");
-			defines.emplace("SMAA_PREDICATION", "0");
-			defines.emplace("SMAA_REPROJECTION", "0");
+            defines.emplace("SMAA_PREDICATION", "0");
+            defines.emplace("SMAA_REPROJECTION", "0");
             defines.emplace(smaa_pair.first, "1");
 
             if (success)
@@ -2349,71 +2349,71 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
     }
 #endif
 
-	if (success)
-	{
-		gDeferredPostProgram.mName = "Deferred Post Shader";
+    if (success)
+    {
+        gDeferredPostProgram.mName = "Deferred Post Shader";
         gDeferredPostProgram.mFeatures.isDeferred = true;
-		gDeferredPostProgram.mShaderFiles.clear();
-		gDeferredPostProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostProgram.clearPermutations();
-		gDeferredPostProgram.addPermutation("FRONT_BLUR", "1");
-
-		success = gDeferredPostProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredPostProgramNoNear.mName = "Deferred Post Shader No Near Blur";
-		gDeferredPostProgramNoNear.mFeatures.isDeferred = true;
-		gDeferredPostProgramNoNear.mShaderFiles.clear();
-		gDeferredPostProgramNoNear.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostProgramNoNear.mShaderFiles.push_back(make_pair("deferred/postDeferredF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostProgramNoNear.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostProgramNoNear.clearPermutations();
-		gDeferredPostProgramNoNear.addPermutation("FRONT_BLUR", "0");
-
-		success = gDeferredPostProgramNoNear.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredCoFProgram.mName = "Deferred CoF Shader";
-		gDeferredCoFProgram.mShaderFiles.clear();
-		gDeferredCoFProgram.mFeatures.isDeferred = true;
-		gDeferredCoFProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredCoFProgram.mShaderFiles.push_back(make_pair("deferred/cofF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredCoFProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredCoFProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredDoFCombineProgram.mName = "Deferred DoFCombine Shader";
-		gDeferredDoFCombineProgram.mFeatures.isDeferred = true;
-		gDeferredDoFCombineProgram.mShaderFiles.clear();
-		gDeferredDoFCombineProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredDoFCombineProgram.mShaderFiles.push_back(make_pair("deferred/dofCombineF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredDoFCombineProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredDoFCombineProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredPostNoDoFProgram.mName = "Deferred Post NoDoF Shader";
-		gDeferredPostNoDoFProgram.mFeatures.isDeferred = true;
-		gDeferredPostNoDoFProgram.mShaderFiles.clear();
-		gDeferredPostNoDoFProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostNoDoFProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoDoFF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostNoDoFProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredPostNoDoFProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
+        gDeferredPostProgram.mShaderFiles.clear();
+        gDeferredPostProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostProgram.clearPermutations();
+        gDeferredPostProgram.addPermutation("FRONT_BLUR", "1");
+
+        success = gDeferredPostProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredPostProgramNoNear.mName = "Deferred Post Shader No Near Blur";
+        gDeferredPostProgramNoNear.mFeatures.isDeferred = true;
+        gDeferredPostProgramNoNear.mShaderFiles.clear();
+        gDeferredPostProgramNoNear.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostProgramNoNear.mShaderFiles.push_back(make_pair("deferred/postDeferredF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostProgramNoNear.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostProgramNoNear.clearPermutations();
+        gDeferredPostProgramNoNear.addPermutation("FRONT_BLUR", "0");
+
+        success = gDeferredPostProgramNoNear.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredCoFProgram.mName = "Deferred CoF Shader";
+        gDeferredCoFProgram.mShaderFiles.clear();
+        gDeferredCoFProgram.mFeatures.isDeferred = true;
+        gDeferredCoFProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredCoFProgram.mShaderFiles.push_back(make_pair("deferred/cofF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredCoFProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredCoFProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredDoFCombineProgram.mName = "Deferred DoFCombine Shader";
+        gDeferredDoFCombineProgram.mFeatures.isDeferred = true;
+        gDeferredDoFCombineProgram.mShaderFiles.clear();
+        gDeferredDoFCombineProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredDoFCombineProgram.mShaderFiles.push_back(make_pair("deferred/dofCombineF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredDoFCombineProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredDoFCombineProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredPostNoDoFProgram.mName = "Deferred Post NoDoF Shader";
+        gDeferredPostNoDoFProgram.mFeatures.isDeferred = true;
+        gDeferredPostNoDoFProgram.mShaderFiles.clear();
+        gDeferredPostNoDoFProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostNoDoFProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoDoFF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostNoDoFProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredPostNoDoFProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
 
     if (success)
     {
@@ -2435,45 +2435,45 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         llassert(success);
     }
 
-	if (success)
-	{
-		gDeferredWLSkyProgram.mName = "Deferred Windlight Sky Shader";
-		gDeferredWLSkyProgram.mShaderFiles.clear();
-		gDeferredWLSkyProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredWLSkyProgram.mFeatures.hasAtmospherics = true;
-		gDeferredWLSkyProgram.mFeatures.hasGamma = true;
-		gDeferredWLSkyProgram.mFeatures.hasSrgb = true;
-
-		gDeferredWLSkyProgram.mShaderFiles.push_back(make_pair("deferred/skyV.glsl", GL_VERTEX_SHADER));
-		gDeferredWLSkyProgram.mShaderFiles.push_back(make_pair("deferred/skyF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredWLSkyProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredWLSkyProgram.mShaderGroup = LLGLSLShader::SG_SKY;
-
-		success = gDeferredWLSkyProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
-
-	if (success)
-	{
-		gDeferredWLCloudProgram.mName = "Deferred Windlight Cloud Program";
-		gDeferredWLCloudProgram.mShaderFiles.clear();
-		gDeferredWLCloudProgram.mFeatures.calculatesAtmospherics = true;
-		gDeferredWLCloudProgram.mFeatures.hasAtmospherics = true;
+    if (success)
+    {
+        gDeferredWLSkyProgram.mName = "Deferred Windlight Sky Shader";
+        gDeferredWLSkyProgram.mShaderFiles.clear();
+        gDeferredWLSkyProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredWLSkyProgram.mFeatures.hasAtmospherics = true;
+        gDeferredWLSkyProgram.mFeatures.hasGamma = true;
+        gDeferredWLSkyProgram.mFeatures.hasSrgb = true;
+
+        gDeferredWLSkyProgram.mShaderFiles.push_back(make_pair("deferred/skyV.glsl", GL_VERTEX_SHADER));
+        gDeferredWLSkyProgram.mShaderFiles.push_back(make_pair("deferred/skyF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredWLSkyProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredWLSkyProgram.mShaderGroup = LLGLSLShader::SG_SKY;
+
+        success = gDeferredWLSkyProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
+
+    if (success)
+    {
+        gDeferredWLCloudProgram.mName = "Deferred Windlight Cloud Program";
+        gDeferredWLCloudProgram.mShaderFiles.clear();
+        gDeferredWLCloudProgram.mFeatures.calculatesAtmospherics = true;
+        gDeferredWLCloudProgram.mFeatures.hasAtmospherics = true;
         gDeferredWLCloudProgram.mFeatures.hasGamma = true;
         gDeferredWLCloudProgram.mFeatures.hasSrgb = true;
-        
-		gDeferredWLCloudProgram.mShaderFiles.push_back(make_pair("deferred/cloudsV.glsl", GL_VERTEX_SHADER));
-		gDeferredWLCloudProgram.mShaderFiles.push_back(make_pair("deferred/cloudsF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredWLCloudProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredWLCloudProgram.mShaderGroup = LLGLSLShader::SG_SKY;
+
+        gDeferredWLCloudProgram.mShaderFiles.push_back(make_pair("deferred/cloudsV.glsl", GL_VERTEX_SHADER));
+        gDeferredWLCloudProgram.mShaderFiles.push_back(make_pair("deferred/cloudsF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredWLCloudProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredWLCloudProgram.mShaderGroup = LLGLSLShader::SG_SKY;
         gDeferredWLCloudProgram.addConstant( LLGLSLShader::SHADER_CONST_CLOUD_MOON_DEPTH ); // SL-14113
-		success = gDeferredWLCloudProgram.createShader(NULL, NULL);
-		llassert(success);
-	}
+        success = gDeferredWLCloudProgram.createShader(NULL, NULL);
+        llassert(success);
+    }
 
-	if (success)
-	{
-	    gDeferredWLSunProgram.mName = "Deferred Windlight Sun Program";
+    if (success)
+    {
+        gDeferredWLSunProgram.mName = "Deferred Windlight Sun Program";
         gDeferredWLSunProgram.mFeatures.calculatesAtmospherics = true;
         gDeferredWLSunProgram.mFeatures.hasAtmospherics = true;
         gDeferredWLSunProgram.mFeatures.hasGamma = true;
@@ -2498,40 +2498,40 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         gDeferredWLMoonProgram.mFeatures.hasAtmospherics = true;
         gDeferredWLMoonProgram.mFeatures.hasSrgb = true;
         gDeferredWLMoonProgram.mFeatures.disableTextureIndex = true;
-        
+
         gDeferredWLMoonProgram.mShaderFiles.clear();
         gDeferredWLMoonProgram.mShaderFiles.push_back(make_pair("deferred/moonV.glsl", GL_VERTEX_SHADER));
         gDeferredWLMoonProgram.mShaderFiles.push_back(make_pair("deferred/moonF.glsl", GL_FRAGMENT_SHADER));
         gDeferredWLMoonProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
         gDeferredWLMoonProgram.mShaderGroup = LLGLSLShader::SG_SKY;
         gDeferredWLMoonProgram.addConstant( LLGLSLShader::SHADER_CONST_CLOUD_MOON_DEPTH ); // SL-14113
- 	 	success = gDeferredWLMoonProgram.createShader(NULL, NULL);
+        success = gDeferredWLMoonProgram.createShader(NULL, NULL);
         llassert(success);
- 	}
-
- 	if (success)
-	{
-		gDeferredStarProgram.mName = "Deferred Star Program";
-		gDeferredStarProgram.mShaderFiles.clear();
-		gDeferredStarProgram.mShaderFiles.push_back(make_pair("deferred/starsV.glsl", GL_VERTEX_SHADER));
-		gDeferredStarProgram.mShaderFiles.push_back(make_pair("deferred/starsF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredStarProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredStarProgram.mShaderGroup = LLGLSLShader::SG_SKY;
+    }
+
+    if (success)
+    {
+        gDeferredStarProgram.mName = "Deferred Star Program";
+        gDeferredStarProgram.mShaderFiles.clear();
+        gDeferredStarProgram.mShaderFiles.push_back(make_pair("deferred/starsV.glsl", GL_VERTEX_SHADER));
+        gDeferredStarProgram.mShaderFiles.push_back(make_pair("deferred/starsF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredStarProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredStarProgram.mShaderGroup = LLGLSLShader::SG_SKY;
         gDeferredStarProgram.addConstant( LLGLSLShader::SHADER_CONST_STAR_DEPTH ); // SL-14113
-		success = gDeferredStarProgram.createShader(NULL, NULL);
+        success = gDeferredStarProgram.createShader(NULL, NULL);
         llassert(success);
-	}
+    }
 
-	if (success)
-	{
-		gNormalMapGenProgram.mName = "Normal Map Generation Program";
-		gNormalMapGenProgram.mShaderFiles.clear();
-		gNormalMapGenProgram.mShaderFiles.push_back(make_pair("deferred/normgenV.glsl", GL_VERTEX_SHADER));
-		gNormalMapGenProgram.mShaderFiles.push_back(make_pair("deferred/normgenF.glsl", GL_FRAGMENT_SHADER));
-		gNormalMapGenProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gNormalMapGenProgram.mShaderGroup = LLGLSLShader::SG_SKY;
-		success = gNormalMapGenProgram.createShader(NULL, NULL);
-	}
+    if (success)
+    {
+        gNormalMapGenProgram.mName = "Normal Map Generation Program";
+        gNormalMapGenProgram.mShaderFiles.clear();
+        gNormalMapGenProgram.mShaderFiles.push_back(make_pair("deferred/normgenV.glsl", GL_VERTEX_SHADER));
+        gNormalMapGenProgram.mShaderFiles.push_back(make_pair("deferred/normgenF.glsl", GL_FRAGMENT_SHADER));
+        gNormalMapGenProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gNormalMapGenProgram.mShaderGroup = LLGLSLShader::SG_SKY;
+        success = gNormalMapGenProgram.createShader(NULL, NULL);
+    }
 
     if (success)
     {
@@ -2543,7 +2543,7 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         success = gDeferredGenBrdfLutProgram.createShader(NULL, NULL);
     }
 
-	if (success) {
+    if (success) {
         gPostScreenSpaceReflectionProgram.mName = "Screen Space Reflection Post";
         gPostScreenSpaceReflectionProgram.mShaderFiles.clear();
         gPostScreenSpaceReflectionProgram.mShaderFiles.push_back(make_pair("deferred/screenSpaceReflPostV.glsl", GL_VERTEX_SHADER));
@@ -2552,213 +2552,213 @@ BOOL LLViewerShaderMgr::loadShadersDeferred()
         gPostScreenSpaceReflectionProgram.mFeatures.isDeferred                = true;
         gPostScreenSpaceReflectionProgram.mShaderLevel = 3;
         success = gPostScreenSpaceReflectionProgram.createShader(NULL, NULL);
-	}
-
-	if (success) {
-		gDeferredBufferVisualProgram.mName = "Deferred Buffer Visualization Shader";
-		gDeferredBufferVisualProgram.mShaderFiles.clear();
-		gDeferredBufferVisualProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredBufferVisualProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredVisualizeBuffers.glsl", GL_FRAGMENT_SHADER));
-		gDeferredBufferVisualProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		success = gDeferredBufferVisualProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostTonemapProgram.mName = "Tonemapping Shader None";
-		gDeferredPostTonemapProgram.mFeatures.hasSrgb = true;
-		gDeferredPostTonemapProgram.mShaderFiles.clear();
-		gDeferredPostTonemapProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostTonemapProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostTonemapProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostTonemapProgram.clearPermutations();
-		gDeferredPostTonemapProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_NONE));
-		success = gDeferredPostTonemapProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostTonemapACESProgram.mName = "Tonemapping Shader ACES";
-		gDeferredPostTonemapACESProgram.mFeatures.hasSrgb = true;
-		gDeferredPostTonemapACESProgram.mShaderFiles.clear();
-		gDeferredPostTonemapACESProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostTonemapACESProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostTonemapACESProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostTonemapACESProgram.clearPermutations();
-		gDeferredPostTonemapACESProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_ACES_HILL));
-		success = gDeferredPostTonemapACESProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostTonemapUchiProgram.mName = "Tonemapping Shader Uchimura";
-		gDeferredPostTonemapUchiProgram.mFeatures.hasSrgb = true;
-		gDeferredPostTonemapUchiProgram.mShaderFiles.clear();
-		gDeferredPostTonemapUchiProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostTonemapUchiProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostTonemapUchiProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostTonemapUchiProgram.clearPermutations();
-		gDeferredPostTonemapUchiProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_UCHIMURA));
-		success = gDeferredPostTonemapUchiProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostTonemapHableProgram.mName = "Tonemapping Shader Uncharted";
-		gDeferredPostTonemapHableProgram.mFeatures.hasSrgb = true;
-		gDeferredPostTonemapHableProgram.mShaderFiles.clear();
-		gDeferredPostTonemapHableProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostTonemapHableProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostTonemapHableProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostTonemapHableProgram.clearPermutations();
-		gDeferredPostTonemapHableProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_UNCHARTED));
-		success = gDeferredPostTonemapHableProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostColorCorrectProgram[0].mName = "Color Grading Shader";
-		gDeferredPostColorCorrectProgram[0].mFeatures.hasSrgb = true;
-		gDeferredPostColorCorrectProgram[0].mShaderFiles.clear();
-		gDeferredPostColorCorrectProgram[0].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostColorCorrectProgram[0].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostColorCorrectProgram[0].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostColorCorrectProgram[0].clearPermutations();
-		gDeferredPostColorCorrectProgram[0].addPermutation("COLOR_GRADE_LUT", std::to_string(0));
-		success = gDeferredPostColorCorrectProgram[0].createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostColorCorrectProgram[1].mName = "Color Grading Shader Legacy";
-		gDeferredPostColorCorrectProgram[1].mFeatures.hasSrgb = true;
-		gDeferredPostColorCorrectProgram[1].mShaderFiles.clear();
-		gDeferredPostColorCorrectProgram[1].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostColorCorrectProgram[1].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostColorCorrectProgram[1].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostColorCorrectProgram[1].clearPermutations();
-		gDeferredPostColorCorrectProgram[1].addPermutation("COLOR_GRADE_LUT", std::to_string(0));
-		gDeferredPostColorCorrectProgram[1].addPermutation("LEGACY_GAMMA", "1");
-		success = gDeferredPostColorCorrectProgram[1].createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostColorCorrectProgram[2].mName = "Color Grading Shader NoPost";
-		gDeferredPostColorCorrectProgram[2].mFeatures.hasSrgb = true;
-		gDeferredPostColorCorrectProgram[2].mShaderFiles.clear();
-		gDeferredPostColorCorrectProgram[2].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostColorCorrectProgram[2].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostColorCorrectProgram[2].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostColorCorrectProgram[2].clearPermutations();
-		gDeferredPostColorCorrectProgram[2].addPermutation("COLOR_GRADE_LUT", std::to_string(0));
-		gDeferredPostColorCorrectProgram[2].addPermutation("NO_POST", "1");
-		success = gDeferredPostColorCorrectProgram[2].createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostColorCorrectLUTProgram[0].mName = "Color Grading LUT Shader";
-		gDeferredPostColorCorrectLUTProgram[0].mFeatures.hasSrgb = true;
-		gDeferredPostColorCorrectLUTProgram[0].mShaderFiles.clear();
-		gDeferredPostColorCorrectLUTProgram[0].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostColorCorrectLUTProgram[0].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostColorCorrectLUTProgram[0].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostColorCorrectLUTProgram[0].clearPermutations();
-		gDeferredPostColorCorrectLUTProgram[0].addPermutation("COLOR_GRADE_LUT", std::to_string(1));
-		success = gDeferredPostColorCorrectLUTProgram[0].createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostColorCorrectLUTProgram[1].mName = "Color Grading LUT Shader Legacy";
-		gDeferredPostColorCorrectLUTProgram[1].mFeatures.hasSrgb = true;
-		gDeferredPostColorCorrectLUTProgram[1].mShaderFiles.clear();
-		gDeferredPostColorCorrectLUTProgram[1].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostColorCorrectLUTProgram[1].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostColorCorrectLUTProgram[1].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostColorCorrectLUTProgram[1].clearPermutations();
-		gDeferredPostColorCorrectLUTProgram[1].addPermutation("COLOR_GRADE_LUT", std::to_string(1));
-		gDeferredPostColorCorrectLUTProgram[1].addPermutation("LEGACY_GAMMA", "1");
-		success = gDeferredPostColorCorrectLUTProgram[1].createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDeferredPostColorCorrectLUTProgram[2].mName = "Color Grading LUT Shader NoPost";
-		gDeferredPostColorCorrectLUTProgram[2].mFeatures.hasSrgb = true;
-		gDeferredPostColorCorrectLUTProgram[2].mShaderFiles.clear();
-		gDeferredPostColorCorrectLUTProgram[2].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-		gDeferredPostColorCorrectLUTProgram[2].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
-		gDeferredPostColorCorrectLUTProgram[2].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-		gDeferredPostColorCorrectLUTProgram[2].clearPermutations();
-		gDeferredPostColorCorrectLUTProgram[2].addPermutation("COLOR_GRADE_LUT", std::to_string(1));
-		gDeferredPostColorCorrectLUTProgram[2].addPermutation("NO_POST", "1");
-		success = gDeferredPostColorCorrectLUTProgram[2].createShader(NULL, NULL);
-	}
-
-	// These shaders are non-critical and do not fail shader load
-	if (success)
-	{
-		{
-			gDeferredPostDLSProgram.mName = "DLS Shader";
-			gDeferredPostDLSProgram.mFeatures.hasSrgb = true;
-			gDeferredPostDLSProgram.mShaderFiles.clear();
-			gDeferredPostDLSProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-			gDeferredPostDLSProgram.mShaderFiles.push_back(make_pair("alchemy/DLSF.glsl", GL_FRAGMENT_SHADER));
-			gDeferredPostDLSProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-			gDeferredPostDLSProgram.createShader(NULL, NULL);
-		}
-
-		// [RLVa:KB] - @setsphere
-		{
-			gRlvSphereProgram.mName = "RLVa Sphere Post Processing Shader";
-			gRlvSphereProgram.mFeatures.isDeferred = true;
-			gRlvSphereProgram.mShaderFiles.clear();
-			gRlvSphereProgram.mShaderFiles.push_back(make_pair("deferred/rlvV.glsl", GL_VERTEX_SHADER));
-			if (gGLManager.mGLVersion >= 4.5f)
-				gRlvSphereProgram.mShaderFiles.push_back(make_pair("deferred/rlvF.glsl", GL_FRAGMENT_SHADER));
-			else
-				gRlvSphereProgram.mShaderFiles.push_back(make_pair("deferred/rlvFLegacy.glsl", GL_FRAGMENT_SHADER));
-			gRlvSphereProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-			gRlvSphereProgram.createShader(NULL, NULL);
-		}
-		// [/RLV:KB]
+    }
+
+    if (success) {
+        gDeferredBufferVisualProgram.mName = "Deferred Buffer Visualization Shader";
+        gDeferredBufferVisualProgram.mShaderFiles.clear();
+        gDeferredBufferVisualProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredBufferVisualProgram.mShaderFiles.push_back(make_pair("deferred/postDeferredVisualizeBuffers.glsl", GL_FRAGMENT_SHADER));
+        gDeferredBufferVisualProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        success = gDeferredBufferVisualProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostTonemapProgram.mName = "Tonemapping Shader None";
+        gDeferredPostTonemapProgram.mFeatures.hasSrgb = true;
+        gDeferredPostTonemapProgram.mShaderFiles.clear();
+        gDeferredPostTonemapProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostTonemapProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostTonemapProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostTonemapProgram.clearPermutations();
+        gDeferredPostTonemapProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_NONE));
+        success = gDeferredPostTonemapProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostTonemapACESProgram.mName = "Tonemapping Shader ACES";
+        gDeferredPostTonemapACESProgram.mFeatures.hasSrgb = true;
+        gDeferredPostTonemapACESProgram.mShaderFiles.clear();
+        gDeferredPostTonemapACESProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostTonemapACESProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostTonemapACESProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostTonemapACESProgram.clearPermutations();
+        gDeferredPostTonemapACESProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_ACES_HILL));
+        success = gDeferredPostTonemapACESProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostTonemapUchiProgram.mName = "Tonemapping Shader Uchimura";
+        gDeferredPostTonemapUchiProgram.mFeatures.hasSrgb = true;
+        gDeferredPostTonemapUchiProgram.mShaderFiles.clear();
+        gDeferredPostTonemapUchiProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostTonemapUchiProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostTonemapUchiProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostTonemapUchiProgram.clearPermutations();
+        gDeferredPostTonemapUchiProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_UCHIMURA));
+        success = gDeferredPostTonemapUchiProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostTonemapHableProgram.mName = "Tonemapping Shader Uncharted";
+        gDeferredPostTonemapHableProgram.mFeatures.hasSrgb = true;
+        gDeferredPostTonemapHableProgram.mShaderFiles.clear();
+        gDeferredPostTonemapHableProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostTonemapHableProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostTonemapHableProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostTonemapHableProgram.clearPermutations();
+        gDeferredPostTonemapHableProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_UNCHARTED));
+        success = gDeferredPostTonemapHableProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostColorCorrectProgram[0].mName = "Color Grading Shader";
+        gDeferredPostColorCorrectProgram[0].mFeatures.hasSrgb = true;
+        gDeferredPostColorCorrectProgram[0].mShaderFiles.clear();
+        gDeferredPostColorCorrectProgram[0].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostColorCorrectProgram[0].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostColorCorrectProgram[0].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostColorCorrectProgram[0].clearPermutations();
+        gDeferredPostColorCorrectProgram[0].addPermutation("COLOR_GRADE_LUT", std::to_string(0));
+        success = gDeferredPostColorCorrectProgram[0].createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostColorCorrectProgram[1].mName = "Color Grading Shader Legacy";
+        gDeferredPostColorCorrectProgram[1].mFeatures.hasSrgb = true;
+        gDeferredPostColorCorrectProgram[1].mShaderFiles.clear();
+        gDeferredPostColorCorrectProgram[1].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostColorCorrectProgram[1].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostColorCorrectProgram[1].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostColorCorrectProgram[1].clearPermutations();
+        gDeferredPostColorCorrectProgram[1].addPermutation("COLOR_GRADE_LUT", std::to_string(0));
+        gDeferredPostColorCorrectProgram[1].addPermutation("LEGACY_GAMMA", "1");
+        success = gDeferredPostColorCorrectProgram[1].createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostColorCorrectProgram[2].mName = "Color Grading Shader NoPost";
+        gDeferredPostColorCorrectProgram[2].mFeatures.hasSrgb = true;
+        gDeferredPostColorCorrectProgram[2].mShaderFiles.clear();
+        gDeferredPostColorCorrectProgram[2].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostColorCorrectProgram[2].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostColorCorrectProgram[2].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostColorCorrectProgram[2].clearPermutations();
+        gDeferredPostColorCorrectProgram[2].addPermutation("COLOR_GRADE_LUT", std::to_string(0));
+        gDeferredPostColorCorrectProgram[2].addPermutation("NO_POST", "1");
+        success = gDeferredPostColorCorrectProgram[2].createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostColorCorrectLUTProgram[0].mName = "Color Grading LUT Shader";
+        gDeferredPostColorCorrectLUTProgram[0].mFeatures.hasSrgb = true;
+        gDeferredPostColorCorrectLUTProgram[0].mShaderFiles.clear();
+        gDeferredPostColorCorrectLUTProgram[0].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostColorCorrectLUTProgram[0].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostColorCorrectLUTProgram[0].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostColorCorrectLUTProgram[0].clearPermutations();
+        gDeferredPostColorCorrectLUTProgram[0].addPermutation("COLOR_GRADE_LUT", std::to_string(1));
+        success = gDeferredPostColorCorrectLUTProgram[0].createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostColorCorrectLUTProgram[1].mName = "Color Grading LUT Shader Legacy";
+        gDeferredPostColorCorrectLUTProgram[1].mFeatures.hasSrgb = true;
+        gDeferredPostColorCorrectLUTProgram[1].mShaderFiles.clear();
+        gDeferredPostColorCorrectLUTProgram[1].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostColorCorrectLUTProgram[1].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostColorCorrectLUTProgram[1].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostColorCorrectLUTProgram[1].clearPermutations();
+        gDeferredPostColorCorrectLUTProgram[1].addPermutation("COLOR_GRADE_LUT", std::to_string(1));
+        gDeferredPostColorCorrectLUTProgram[1].addPermutation("LEGACY_GAMMA", "1");
+        success = gDeferredPostColorCorrectLUTProgram[1].createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDeferredPostColorCorrectLUTProgram[2].mName = "Color Grading LUT Shader NoPost";
+        gDeferredPostColorCorrectLUTProgram[2].mFeatures.hasSrgb = true;
+        gDeferredPostColorCorrectLUTProgram[2].mShaderFiles.clear();
+        gDeferredPostColorCorrectLUTProgram[2].mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+        gDeferredPostColorCorrectLUTProgram[2].mShaderFiles.push_back(make_pair("alchemy/colorCorrectF.glsl", GL_FRAGMENT_SHADER));
+        gDeferredPostColorCorrectLUTProgram[2].mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+        gDeferredPostColorCorrectLUTProgram[2].clearPermutations();
+        gDeferredPostColorCorrectLUTProgram[2].addPermutation("COLOR_GRADE_LUT", std::to_string(1));
+        gDeferredPostColorCorrectLUTProgram[2].addPermutation("NO_POST", "1");
+        success = gDeferredPostColorCorrectLUTProgram[2].createShader(NULL, NULL);
+    }
+
+    // These shaders are non-critical and do not fail shader load
+    if (success)
+    {
+        {
+            gDeferredPostDLSProgram.mName = "DLS Shader";
+            gDeferredPostDLSProgram.mFeatures.hasSrgb = true;
+            gDeferredPostDLSProgram.mShaderFiles.clear();
+            gDeferredPostDLSProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+            gDeferredPostDLSProgram.mShaderFiles.push_back(make_pair("alchemy/DLSF.glsl", GL_FRAGMENT_SHADER));
+            gDeferredPostDLSProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+            gDeferredPostDLSProgram.createShader(NULL, NULL);
+        }
+
+        // [RLVa:KB] - @setsphere
+        {
+            gRlvSphereProgram.mName = "RLVa Sphere Post Processing Shader";
+            gRlvSphereProgram.mFeatures.isDeferred = true;
+            gRlvSphereProgram.mShaderFiles.clear();
+            gRlvSphereProgram.mShaderFiles.push_back(make_pair("deferred/rlvV.glsl", GL_VERTEX_SHADER));
+            if (gGLManager.mGLVersion >= 4.5f)
+                gRlvSphereProgram.mShaderFiles.push_back(make_pair("deferred/rlvF.glsl", GL_FRAGMENT_SHADER));
+            else
+                gRlvSphereProgram.mShaderFiles.push_back(make_pair("deferred/rlvFLegacy.glsl", GL_FRAGMENT_SHADER));
+            gRlvSphereProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+            gRlvSphereProgram.createShader(NULL, NULL);
+        }
+        // [/RLV:KB]
 #ifndef LL_DARWIN
-		if (gGLManager.mGLVersion >= 4.59f)
-		{
-			gDeferredPostCASProgram.mName = "Contrast Adaptive Sharpen Shader";
-			gDeferredPostCASProgram.mFeatures.hasSrgb = true;
-			gDeferredPostCASProgram.mShaderFiles.clear();
-			gDeferredPostCASProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-			gDeferredPostCASProgram.mShaderFiles.push_back(make_pair("alchemy/CASF.glsl", GL_FRAGMENT_SHADER));
-			gDeferredPostCASProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-			gDeferredPostCASProgram.createShader(NULL, NULL);
-		}
-
-		if (gGLManager.mGLVersion >= 4.59f)
-		{
-			gDeferredPostTonemapLPMProgram.mName = "Tonemapping Shader LPM";
-			gDeferredPostTonemapLPMProgram.mFeatures.hasSrgb = true;
-			gDeferredPostTonemapLPMProgram.mShaderFiles.clear();
-			gDeferredPostTonemapLPMProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
-			gDeferredPostTonemapLPMProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
-			gDeferredPostTonemapLPMProgram.mShaderFiles.push_back(make_pair("alchemy/LPMUtil.glsl", GL_FRAGMENT_SHADER));
-			gDeferredPostTonemapLPMProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
-			gDeferredPostTonemapLPMProgram.clearPermutations();
-			gDeferredPostTonemapLPMProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_AMD));
-			gDeferredPostTonemapLPMProgram.createShader(NULL, NULL); // Ignore return value for this shader
-		}
+        if (gGLManager.mGLVersion >= 4.59f)
+        {
+            gDeferredPostCASProgram.mName = "Contrast Adaptive Sharpen Shader";
+            gDeferredPostCASProgram.mFeatures.hasSrgb = true;
+            gDeferredPostCASProgram.mShaderFiles.clear();
+            gDeferredPostCASProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+            gDeferredPostCASProgram.mShaderFiles.push_back(make_pair("alchemy/CASF.glsl", GL_FRAGMENT_SHADER));
+            gDeferredPostCASProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+            gDeferredPostCASProgram.createShader(NULL, NULL);
+        }
+
+        if (gGLManager.mGLVersion >= 4.59f)
+        {
+            gDeferredPostTonemapLPMProgram.mName = "Tonemapping Shader LPM";
+            gDeferredPostTonemapLPMProgram.mFeatures.hasSrgb = true;
+            gDeferredPostTonemapLPMProgram.mShaderFiles.clear();
+            gDeferredPostTonemapLPMProgram.mShaderFiles.push_back(make_pair("alchemy/postNoTCV.glsl", GL_VERTEX_SHADER));
+            gDeferredPostTonemapLPMProgram.mShaderFiles.push_back(make_pair("alchemy/toneMapF.glsl", GL_FRAGMENT_SHADER));
+            gDeferredPostTonemapLPMProgram.mShaderFiles.push_back(make_pair("alchemy/LPMUtil.glsl", GL_FRAGMENT_SHADER));
+            gDeferredPostTonemapLPMProgram.mShaderLevel = mShaderLevel[SHADER_DEFERRED];
+            gDeferredPostTonemapLPMProgram.clearPermutations();
+            gDeferredPostTonemapLPMProgram.addPermutation("TONEMAP_METHOD", std::to_string(ALRenderUtil::TONEMAP_AMD));
+            gDeferredPostTonemapLPMProgram.createShader(NULL, NULL); // Ignore return value for this shader
+        }
 #endif
-	}
+    }
 
-	return success;
+    return success;
 }
 
 BOOL LLViewerShaderMgr::loadShadersObject()
 {
     LL_PROFILE_ZONE_SCOPED;
-	BOOL success = TRUE;
+    BOOL success = TRUE;
 
     if (success)
     {
@@ -2782,66 +2782,66 @@ BOOL LLViewerShaderMgr::loadShadersObject()
         }
     }
 
-	if (success)
-	{
-		gObjectAlphaMaskNoColorProgram.mName = "No color alpha mask Shader";
-		gObjectAlphaMaskNoColorProgram.mFeatures.calculatesLighting = true;
-		gObjectAlphaMaskNoColorProgram.mFeatures.calculatesAtmospherics = true;
-		gObjectAlphaMaskNoColorProgram.mFeatures.hasGamma = true;
-		gObjectAlphaMaskNoColorProgram.mFeatures.hasAtmospherics = true;
-		gObjectAlphaMaskNoColorProgram.mFeatures.hasLighting = true;
-		gObjectAlphaMaskNoColorProgram.mFeatures.disableTextureIndex = true;
-		gObjectAlphaMaskNoColorProgram.mFeatures.hasAlphaMask = true;
-		gObjectAlphaMaskNoColorProgram.mShaderFiles.clear();
-		gObjectAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("objects/simpleNoColorV.glsl", GL_VERTEX_SHADER));
-		gObjectAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("objects/simpleF.glsl", GL_FRAGMENT_SHADER));
-		gObjectAlphaMaskNoColorProgram.mShaderLevel = mShaderLevel[SHADER_OBJECT];
-		success = gObjectAlphaMaskNoColorProgram.createShader(NULL, NULL);
-	}
-	
-	if (success)
-	{
-		gImpostorProgram.mName = "Impostor Shader";
-		gImpostorProgram.mFeatures.disableTextureIndex = true;
-		gImpostorProgram.mFeatures.hasSrgb = true;
-		gImpostorProgram.mShaderFiles.clear();
-		gImpostorProgram.mShaderFiles.push_back(make_pair("objects/impostorV.glsl", GL_VERTEX_SHADER));
-		gImpostorProgram.mShaderFiles.push_back(make_pair("objects/impostorF.glsl", GL_FRAGMENT_SHADER));
-		gImpostorProgram.mShaderLevel = mShaderLevel[SHADER_OBJECT];
-		success = gImpostorProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gObjectPreviewProgram.mName = "Object Preview Shader";
-		gObjectPreviewProgram.mFeatures.disableTextureIndex = true;
-		gObjectPreviewProgram.mShaderFiles.clear();
-		gObjectPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewV.glsl", GL_VERTEX_SHADER));
-		gObjectPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewF.glsl", GL_FRAGMENT_SHADER));
-		gObjectPreviewProgram.mShaderLevel = mShaderLevel[SHADER_OBJECT];
+    if (success)
+    {
+        gObjectAlphaMaskNoColorProgram.mName = "No color alpha mask Shader";
+        gObjectAlphaMaskNoColorProgram.mFeatures.calculatesLighting = true;
+        gObjectAlphaMaskNoColorProgram.mFeatures.calculatesAtmospherics = true;
+        gObjectAlphaMaskNoColorProgram.mFeatures.hasGamma = true;
+        gObjectAlphaMaskNoColorProgram.mFeatures.hasAtmospherics = true;
+        gObjectAlphaMaskNoColorProgram.mFeatures.hasLighting = true;
+        gObjectAlphaMaskNoColorProgram.mFeatures.disableTextureIndex = true;
+        gObjectAlphaMaskNoColorProgram.mFeatures.hasAlphaMask = true;
+        gObjectAlphaMaskNoColorProgram.mShaderFiles.clear();
+        gObjectAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("objects/simpleNoColorV.glsl", GL_VERTEX_SHADER));
+        gObjectAlphaMaskNoColorProgram.mShaderFiles.push_back(make_pair("objects/simpleF.glsl", GL_FRAGMENT_SHADER));
+        gObjectAlphaMaskNoColorProgram.mShaderLevel = mShaderLevel[SHADER_OBJECT];
+        success = gObjectAlphaMaskNoColorProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gImpostorProgram.mName = "Impostor Shader";
+        gImpostorProgram.mFeatures.disableTextureIndex = true;
+        gImpostorProgram.mFeatures.hasSrgb = true;
+        gImpostorProgram.mShaderFiles.clear();
+        gImpostorProgram.mShaderFiles.push_back(make_pair("objects/impostorV.glsl", GL_VERTEX_SHADER));
+        gImpostorProgram.mShaderFiles.push_back(make_pair("objects/impostorF.glsl", GL_FRAGMENT_SHADER));
+        gImpostorProgram.mShaderLevel = mShaderLevel[SHADER_OBJECT];
+        success = gImpostorProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gObjectPreviewProgram.mName = "Object Preview Shader";
+        gObjectPreviewProgram.mFeatures.disableTextureIndex = true;
+        gObjectPreviewProgram.mShaderFiles.clear();
+        gObjectPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewV.glsl", GL_VERTEX_SHADER));
+        gObjectPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewF.glsl", GL_FRAGMENT_SHADER));
+        gObjectPreviewProgram.mShaderLevel = mShaderLevel[SHADER_OBJECT];
         success = make_rigged_variant(gObjectPreviewProgram, gSkinnedObjectPreviewProgram);
-		success = gObjectPreviewProgram.createShader(NULL, NULL);
-		gObjectPreviewProgram.mFeatures.hasLighting = true;
+        success = gObjectPreviewProgram.createShader(NULL, NULL);
+        gObjectPreviewProgram.mFeatures.hasLighting = true;
         gSkinnedObjectPreviewProgram.mFeatures.hasLighting = true;
-	}
-
-	if (success)
-	{
-		gPhysicsPreviewProgram.mName = "Preview Physics Shader";
-		gPhysicsPreviewProgram.mFeatures.calculatesLighting = false;
-		gPhysicsPreviewProgram.mFeatures.calculatesAtmospherics = false;
-		gPhysicsPreviewProgram.mFeatures.hasGamma = false;
-		gPhysicsPreviewProgram.mFeatures.hasAtmospherics = false;
-		gPhysicsPreviewProgram.mFeatures.hasLighting = false;
-		gPhysicsPreviewProgram.mFeatures.mIndexedTextureChannels = 0;
-		gPhysicsPreviewProgram.mFeatures.disableTextureIndex = true;
-		gPhysicsPreviewProgram.mShaderFiles.clear();
-		gPhysicsPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewPhysicsV.glsl", GL_VERTEX_SHADER));
-		gPhysicsPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewPhysicsF.glsl", GL_FRAGMENT_SHADER));
-		gPhysicsPreviewProgram.mShaderLevel = mShaderLevel[SHADER_OBJECT];
-		success = gPhysicsPreviewProgram.createShader(NULL, NULL);
-		gPhysicsPreviewProgram.mFeatures.hasLighting = false;
-	}
+    }
+
+    if (success)
+    {
+        gPhysicsPreviewProgram.mName = "Preview Physics Shader";
+        gPhysicsPreviewProgram.mFeatures.calculatesLighting = false;
+        gPhysicsPreviewProgram.mFeatures.calculatesAtmospherics = false;
+        gPhysicsPreviewProgram.mFeatures.hasGamma = false;
+        gPhysicsPreviewProgram.mFeatures.hasAtmospherics = false;
+        gPhysicsPreviewProgram.mFeatures.hasLighting = false;
+        gPhysicsPreviewProgram.mFeatures.mIndexedTextureChannels = 0;
+        gPhysicsPreviewProgram.mFeatures.disableTextureIndex = true;
+        gPhysicsPreviewProgram.mShaderFiles.clear();
+        gPhysicsPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewPhysicsV.glsl", GL_VERTEX_SHADER));
+        gPhysicsPreviewProgram.mShaderFiles.push_back(make_pair("objects/previewPhysicsF.glsl", GL_FRAGMENT_SHADER));
+        gPhysicsPreviewProgram.mShaderLevel = mShaderLevel[SHADER_OBJECT];
+        success = gPhysicsPreviewProgram.createShader(NULL, NULL);
+        gPhysicsPreviewProgram.mFeatures.hasLighting = false;
+    }
 
     if (!success)
     {
@@ -2849,234 +2849,234 @@ BOOL LLViewerShaderMgr::loadShadersObject()
         return FALSE;
     }
 
-	return TRUE;
+    return TRUE;
 }
 
 BOOL LLViewerShaderMgr::loadShadersAvatar()
 {
     LL_PROFILE_ZONE_SCOPED;
 #if 1 // DEPRECATED -- forward rendering is deprecated
-	BOOL success = TRUE;
-
-	if (mShaderLevel[SHADER_AVATAR] == 0)
-	{
-		gAvatarProgram.unload();
-		gAvatarEyeballProgram.unload();
-		return TRUE;
-	}
-
-	if (success)
-	{
-		gAvatarProgram.mName = "Avatar Shader";
-		gAvatarProgram.mFeatures.hasSkinning = true;
-		gAvatarProgram.mFeatures.calculatesAtmospherics = true;
-		gAvatarProgram.mFeatures.calculatesLighting = true;
-		gAvatarProgram.mFeatures.hasGamma = true;
-		gAvatarProgram.mFeatures.hasAtmospherics = true;
-		gAvatarProgram.mFeatures.hasLighting = true;
-		gAvatarProgram.mFeatures.hasAlphaMask = true;
-		gAvatarProgram.mFeatures.disableTextureIndex = true;
-		gAvatarProgram.mShaderFiles.clear();
-		gAvatarProgram.mShaderFiles.push_back(make_pair("avatar/avatarV.glsl", GL_VERTEX_SHADER));
-		gAvatarProgram.mShaderFiles.push_back(make_pair("avatar/avatarF.glsl", GL_FRAGMENT_SHADER));
-		gAvatarProgram.mShaderLevel = mShaderLevel[SHADER_AVATAR];
-		success = gAvatarProgram.createShader(NULL, NULL);
-			
-		/// Keep track of avatar levels
-		if (gAvatarProgram.mShaderLevel != mShaderLevel[SHADER_AVATAR])
-		{
-			mMaxAvatarShaderLevel = mShaderLevel[SHADER_AVATAR] = gAvatarProgram.mShaderLevel;
-		}
-	}
-
-	if (success)
-	{
-		gAvatarEyeballProgram.mName = "Avatar Eyeball Program";
-		gAvatarEyeballProgram.mFeatures.calculatesLighting = true;
-		gAvatarEyeballProgram.mFeatures.isSpecular = true;
-		gAvatarEyeballProgram.mFeatures.calculatesAtmospherics = true;
-		gAvatarEyeballProgram.mFeatures.hasGamma = true;
-		gAvatarEyeballProgram.mFeatures.hasAtmospherics = true;
-		gAvatarEyeballProgram.mFeatures.hasLighting = true;
-		gAvatarEyeballProgram.mFeatures.hasAlphaMask = true;
-		gAvatarEyeballProgram.mFeatures.disableTextureIndex = true;
-		gAvatarEyeballProgram.mShaderFiles.clear();
-		gAvatarEyeballProgram.mShaderFiles.push_back(make_pair("avatar/eyeballV.glsl", GL_VERTEX_SHADER));
-		gAvatarEyeballProgram.mShaderFiles.push_back(make_pair("avatar/eyeballF.glsl", GL_FRAGMENT_SHADER));
-		gAvatarEyeballProgram.mShaderLevel = mShaderLevel[SHADER_AVATAR];
-		success = gAvatarEyeballProgram.createShader(NULL, NULL);
-	}
-
-	if( !success )
-	{
-		mShaderLevel[SHADER_AVATAR] = 0;
-		mMaxAvatarShaderLevel = 0;
-		return FALSE;
-	}
+    BOOL success = TRUE;
+
+    if (mShaderLevel[SHADER_AVATAR] == 0)
+    {
+        gAvatarProgram.unload();
+        gAvatarEyeballProgram.unload();
+        return TRUE;
+    }
+
+    if (success)
+    {
+        gAvatarProgram.mName = "Avatar Shader";
+        gAvatarProgram.mFeatures.hasSkinning = true;
+        gAvatarProgram.mFeatures.calculatesAtmospherics = true;
+        gAvatarProgram.mFeatures.calculatesLighting = true;
+        gAvatarProgram.mFeatures.hasGamma = true;
+        gAvatarProgram.mFeatures.hasAtmospherics = true;
+        gAvatarProgram.mFeatures.hasLighting = true;
+        gAvatarProgram.mFeatures.hasAlphaMask = true;
+        gAvatarProgram.mFeatures.disableTextureIndex = true;
+        gAvatarProgram.mShaderFiles.clear();
+        gAvatarProgram.mShaderFiles.push_back(make_pair("avatar/avatarV.glsl", GL_VERTEX_SHADER));
+        gAvatarProgram.mShaderFiles.push_back(make_pair("avatar/avatarF.glsl", GL_FRAGMENT_SHADER));
+        gAvatarProgram.mShaderLevel = mShaderLevel[SHADER_AVATAR];
+        success = gAvatarProgram.createShader(NULL, NULL);
+
+        /// Keep track of avatar levels
+        if (gAvatarProgram.mShaderLevel != mShaderLevel[SHADER_AVATAR])
+        {
+            mMaxAvatarShaderLevel = mShaderLevel[SHADER_AVATAR] = gAvatarProgram.mShaderLevel;
+        }
+    }
+
+    if (success)
+    {
+        gAvatarEyeballProgram.mName = "Avatar Eyeball Program";
+        gAvatarEyeballProgram.mFeatures.calculatesLighting = true;
+        gAvatarEyeballProgram.mFeatures.isSpecular = true;
+        gAvatarEyeballProgram.mFeatures.calculatesAtmospherics = true;
+        gAvatarEyeballProgram.mFeatures.hasGamma = true;
+        gAvatarEyeballProgram.mFeatures.hasAtmospherics = true;
+        gAvatarEyeballProgram.mFeatures.hasLighting = true;
+        gAvatarEyeballProgram.mFeatures.hasAlphaMask = true;
+        gAvatarEyeballProgram.mFeatures.disableTextureIndex = true;
+        gAvatarEyeballProgram.mShaderFiles.clear();
+        gAvatarEyeballProgram.mShaderFiles.push_back(make_pair("avatar/eyeballV.glsl", GL_VERTEX_SHADER));
+        gAvatarEyeballProgram.mShaderFiles.push_back(make_pair("avatar/eyeballF.glsl", GL_FRAGMENT_SHADER));
+        gAvatarEyeballProgram.mShaderLevel = mShaderLevel[SHADER_AVATAR];
+        success = gAvatarEyeballProgram.createShader(NULL, NULL);
+    }
+
+    if( !success )
+    {
+        mShaderLevel[SHADER_AVATAR] = 0;
+        mMaxAvatarShaderLevel = 0;
+        return FALSE;
+    }
 #endif
-	return TRUE;
+    return TRUE;
 }
 
 BOOL LLViewerShaderMgr::loadShadersInterface()
 {
     LL_PROFILE_ZONE_SCOPED;
-	BOOL success = TRUE;
-
-	if (success)
-	{
-		gHighlightProgram.mName = "Highlight Shader";
-		gHighlightProgram.mShaderFiles.clear();
-		gHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightV.glsl", GL_VERTEX_SHADER));
-		gHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightF.glsl", GL_FRAGMENT_SHADER));
-		gHighlightProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+    BOOL success = TRUE;
+
+    if (success)
+    {
+        gHighlightProgram.mName = "Highlight Shader";
+        gHighlightProgram.mShaderFiles.clear();
+        gHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightV.glsl", GL_VERTEX_SHADER));
+        gHighlightProgram.mShaderFiles.push_back(make_pair("interface/highlightF.glsl", GL_FRAGMENT_SHADER));
+        gHighlightProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
         success = make_rigged_variant(gHighlightProgram, gSkinnedHighlightProgram);
-		success = success && gHighlightProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gHighlightNormalProgram.mName = "Highlight Normals Shader";
-		gHighlightNormalProgram.mShaderFiles.clear();
-		gHighlightNormalProgram.mShaderFiles.push_back(make_pair("interface/highlightNormV.glsl", GL_VERTEX_SHADER));
-		gHighlightNormalProgram.mShaderFiles.push_back(make_pair("interface/highlightF.glsl", GL_FRAGMENT_SHADER));
-		gHighlightNormalProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gHighlightNormalProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gHighlightSpecularProgram.mName = "Highlight Spec Shader";
-		gHighlightSpecularProgram.mShaderFiles.clear();
-		gHighlightSpecularProgram.mShaderFiles.push_back(make_pair("interface/highlightSpecV.glsl", GL_VERTEX_SHADER));
-		gHighlightSpecularProgram.mShaderFiles.push_back(make_pair("interface/highlightF.glsl", GL_FRAGMENT_SHADER));
-		gHighlightSpecularProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gHighlightSpecularProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gUIProgram.mName = "UI Shader";
-		gUIProgram.mShaderFiles.clear();
-		gUIProgram.mShaderFiles.push_back(make_pair("interface/uiV.glsl", GL_VERTEX_SHADER));
-		gUIProgram.mShaderFiles.push_back(make_pair("interface/uiF.glsl", GL_FRAGMENT_SHADER));
-		gUIProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gUIProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gPathfindingProgram.mName = "Pathfinding Shader";
-		gPathfindingProgram.mShaderFiles.clear();
-		gPathfindingProgram.mShaderFiles.push_back(make_pair("interface/pathfindingV.glsl", GL_VERTEX_SHADER));
-		gPathfindingProgram.mShaderFiles.push_back(make_pair("interface/pathfindingF.glsl", GL_FRAGMENT_SHADER));
-		gPathfindingProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gPathfindingProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gPathfindingNoNormalsProgram.mName = "PathfindingNoNormals Shader";
-		gPathfindingNoNormalsProgram.mShaderFiles.clear();
-		gPathfindingNoNormalsProgram.mShaderFiles.push_back(make_pair("interface/pathfindingNoNormalV.glsl", GL_VERTEX_SHADER));
-		gPathfindingNoNormalsProgram.mShaderFiles.push_back(make_pair("interface/pathfindingF.glsl", GL_FRAGMENT_SHADER));
-		gPathfindingNoNormalsProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gPathfindingNoNormalsProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gGlowCombineProgram.mName = "Glow Combine Shader";
-		gGlowCombineProgram.mShaderFiles.clear();
-		gGlowCombineProgram.mShaderFiles.push_back(make_pair("interface/glowcombineV.glsl", GL_VERTEX_SHADER));
-		gGlowCombineProgram.mShaderFiles.push_back(make_pair("interface/glowcombineF.glsl", GL_FRAGMENT_SHADER));
-		gGlowCombineProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gGlowCombineProgram.createShader(NULL, NULL);
-		if (success)
-		{
-			gGlowCombineProgram.bind();
-			gGlowCombineProgram.uniform1i(sGlowMap, 0);
-			gGlowCombineProgram.uniform1i(sScreenMap, 1);
-			gGlowCombineProgram.unbind();
-		}
-	}
-
-	if (success)
-	{
-		gGlowCombineFXAAProgram.mName = "Glow CombineFXAA Shader";
-		gGlowCombineFXAAProgram.mShaderFiles.clear();
-		gGlowCombineFXAAProgram.mShaderFiles.push_back(make_pair("interface/glowcombineFXAAV.glsl", GL_VERTEX_SHADER));
-		gGlowCombineFXAAProgram.mShaderFiles.push_back(make_pair("interface/glowcombineFXAAF.glsl", GL_FRAGMENT_SHADER));
-		gGlowCombineFXAAProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gGlowCombineFXAAProgram.createShader(NULL, NULL);
-		if (success)
-		{
-			gGlowCombineFXAAProgram.bind();
-			gGlowCombineFXAAProgram.uniform1i(sGlowMap, 0);
-			gGlowCombineFXAAProgram.uniform1i(sScreenMap, 1);
-			gGlowCombineFXAAProgram.unbind();
-		}
-	}
+        success = success && gHighlightProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gHighlightNormalProgram.mName = "Highlight Normals Shader";
+        gHighlightNormalProgram.mShaderFiles.clear();
+        gHighlightNormalProgram.mShaderFiles.push_back(make_pair("interface/highlightNormV.glsl", GL_VERTEX_SHADER));
+        gHighlightNormalProgram.mShaderFiles.push_back(make_pair("interface/highlightF.glsl", GL_FRAGMENT_SHADER));
+        gHighlightNormalProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gHighlightNormalProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gHighlightSpecularProgram.mName = "Highlight Spec Shader";
+        gHighlightSpecularProgram.mShaderFiles.clear();
+        gHighlightSpecularProgram.mShaderFiles.push_back(make_pair("interface/highlightSpecV.glsl", GL_VERTEX_SHADER));
+        gHighlightSpecularProgram.mShaderFiles.push_back(make_pair("interface/highlightF.glsl", GL_FRAGMENT_SHADER));
+        gHighlightSpecularProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gHighlightSpecularProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gUIProgram.mName = "UI Shader";
+        gUIProgram.mShaderFiles.clear();
+        gUIProgram.mShaderFiles.push_back(make_pair("interface/uiV.glsl", GL_VERTEX_SHADER));
+        gUIProgram.mShaderFiles.push_back(make_pair("interface/uiF.glsl", GL_FRAGMENT_SHADER));
+        gUIProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gUIProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gPathfindingProgram.mName = "Pathfinding Shader";
+        gPathfindingProgram.mShaderFiles.clear();
+        gPathfindingProgram.mShaderFiles.push_back(make_pair("interface/pathfindingV.glsl", GL_VERTEX_SHADER));
+        gPathfindingProgram.mShaderFiles.push_back(make_pair("interface/pathfindingF.glsl", GL_FRAGMENT_SHADER));
+        gPathfindingProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gPathfindingProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gPathfindingNoNormalsProgram.mName = "PathfindingNoNormals Shader";
+        gPathfindingNoNormalsProgram.mShaderFiles.clear();
+        gPathfindingNoNormalsProgram.mShaderFiles.push_back(make_pair("interface/pathfindingNoNormalV.glsl", GL_VERTEX_SHADER));
+        gPathfindingNoNormalsProgram.mShaderFiles.push_back(make_pair("interface/pathfindingF.glsl", GL_FRAGMENT_SHADER));
+        gPathfindingNoNormalsProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gPathfindingNoNormalsProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gGlowCombineProgram.mName = "Glow Combine Shader";
+        gGlowCombineProgram.mShaderFiles.clear();
+        gGlowCombineProgram.mShaderFiles.push_back(make_pair("interface/glowcombineV.glsl", GL_VERTEX_SHADER));
+        gGlowCombineProgram.mShaderFiles.push_back(make_pair("interface/glowcombineF.glsl", GL_FRAGMENT_SHADER));
+        gGlowCombineProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gGlowCombineProgram.createShader(NULL, NULL);
+        if (success)
+        {
+            gGlowCombineProgram.bind();
+            gGlowCombineProgram.uniform1i(sGlowMap, 0);
+            gGlowCombineProgram.uniform1i(sScreenMap, 1);
+            gGlowCombineProgram.unbind();
+        }
+    }
+
+    if (success)
+    {
+        gGlowCombineFXAAProgram.mName = "Glow CombineFXAA Shader";
+        gGlowCombineFXAAProgram.mShaderFiles.clear();
+        gGlowCombineFXAAProgram.mShaderFiles.push_back(make_pair("interface/glowcombineFXAAV.glsl", GL_VERTEX_SHADER));
+        gGlowCombineFXAAProgram.mShaderFiles.push_back(make_pair("interface/glowcombineFXAAF.glsl", GL_FRAGMENT_SHADER));
+        gGlowCombineFXAAProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gGlowCombineFXAAProgram.createShader(NULL, NULL);
+        if (success)
+        {
+            gGlowCombineFXAAProgram.bind();
+            gGlowCombineFXAAProgram.uniform1i(sGlowMap, 0);
+            gGlowCombineFXAAProgram.uniform1i(sScreenMap, 1);
+            gGlowCombineFXAAProgram.unbind();
+        }
+    }
 
 #ifdef LL_WINDOWS
-	if (success)
-	{
-		gTwoTextureCompareProgram.mName = "Two Texture Compare Shader";
-		gTwoTextureCompareProgram.mShaderFiles.clear();
-		gTwoTextureCompareProgram.mShaderFiles.push_back(make_pair("interface/twotexturecompareV.glsl", GL_VERTEX_SHADER));
-		gTwoTextureCompareProgram.mShaderFiles.push_back(make_pair("interface/twotexturecompareF.glsl", GL_FRAGMENT_SHADER));
-		gTwoTextureCompareProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gTwoTextureCompareProgram.createShader(NULL, NULL);
-		if (success)
-		{
-			gTwoTextureCompareProgram.bind();
-			gTwoTextureCompareProgram.uniform1i(sTex0, 0);
-			gTwoTextureCompareProgram.uniform1i(sTex1, 1);
-			gTwoTextureCompareProgram.uniform1i(sDitherTex, 2);
-		}
-	}
-
-	if (success)
-	{
-		gOneTextureFilterProgram.mName = "One Texture Filter Shader";
-		gOneTextureFilterProgram.mShaderFiles.clear();
-		gOneTextureFilterProgram.mShaderFiles.push_back(make_pair("interface/onetexturefilterV.glsl", GL_VERTEX_SHADER));
-		gOneTextureFilterProgram.mShaderFiles.push_back(make_pair("interface/onetexturefilterF.glsl", GL_FRAGMENT_SHADER));
-		gOneTextureFilterProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gOneTextureFilterProgram.createShader(NULL, NULL);
-		if (success)
-		{
-			gOneTextureFilterProgram.bind();
-			gOneTextureFilterProgram.uniform1i(sTex0, 0);
-		}
-	}
+    if (success)
+    {
+        gTwoTextureCompareProgram.mName = "Two Texture Compare Shader";
+        gTwoTextureCompareProgram.mShaderFiles.clear();
+        gTwoTextureCompareProgram.mShaderFiles.push_back(make_pair("interface/twotexturecompareV.glsl", GL_VERTEX_SHADER));
+        gTwoTextureCompareProgram.mShaderFiles.push_back(make_pair("interface/twotexturecompareF.glsl", GL_FRAGMENT_SHADER));
+        gTwoTextureCompareProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gTwoTextureCompareProgram.createShader(NULL, NULL);
+        if (success)
+        {
+            gTwoTextureCompareProgram.bind();
+            gTwoTextureCompareProgram.uniform1i(sTex0, 0);
+            gTwoTextureCompareProgram.uniform1i(sTex1, 1);
+            gTwoTextureCompareProgram.uniform1i(sDitherTex, 2);
+        }
+    }
+
+    if (success)
+    {
+        gOneTextureFilterProgram.mName = "One Texture Filter Shader";
+        gOneTextureFilterProgram.mShaderFiles.clear();
+        gOneTextureFilterProgram.mShaderFiles.push_back(make_pair("interface/onetexturefilterV.glsl", GL_VERTEX_SHADER));
+        gOneTextureFilterProgram.mShaderFiles.push_back(make_pair("interface/onetexturefilterF.glsl", GL_FRAGMENT_SHADER));
+        gOneTextureFilterProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gOneTextureFilterProgram.createShader(NULL, NULL);
+        if (success)
+        {
+            gOneTextureFilterProgram.bind();
+            gOneTextureFilterProgram.uniform1i(sTex0, 0);
+        }
+    }
 #endif
 
-	if (success)
-	{
-		gSolidColorProgram.mName = "Solid Color Shader";
-		gSolidColorProgram.mShaderFiles.clear();
-		gSolidColorProgram.mShaderFiles.push_back(make_pair("interface/solidcolorV.glsl", GL_VERTEX_SHADER));
-		gSolidColorProgram.mShaderFiles.push_back(make_pair("interface/solidcolorF.glsl", GL_FRAGMENT_SHADER));
-		gSolidColorProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gSolidColorProgram.createShader(NULL, NULL);
-		if (success)
-		{
-			gSolidColorProgram.bind();
-			gSolidColorProgram.uniform1i(sTex0, 0);
-			gSolidColorProgram.unbind();
-		}
-	}
-
-	if (success)
-	{
-		gOcclusionProgram.mName = "Occlusion Shader";
-		gOcclusionProgram.mShaderFiles.clear();
-		gOcclusionProgram.mShaderFiles.push_back(make_pair("interface/occlusionV.glsl", GL_VERTEX_SHADER));
-		gOcclusionProgram.mShaderFiles.push_back(make_pair("interface/occlusionF.glsl", GL_FRAGMENT_SHADER));
-		gOcclusionProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+    if (success)
+    {
+        gSolidColorProgram.mName = "Solid Color Shader";
+        gSolidColorProgram.mShaderFiles.clear();
+        gSolidColorProgram.mShaderFiles.push_back(make_pair("interface/solidcolorV.glsl", GL_VERTEX_SHADER));
+        gSolidColorProgram.mShaderFiles.push_back(make_pair("interface/solidcolorF.glsl", GL_FRAGMENT_SHADER));
+        gSolidColorProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gSolidColorProgram.createShader(NULL, NULL);
+        if (success)
+        {
+            gSolidColorProgram.bind();
+            gSolidColorProgram.uniform1i(sTex0, 0);
+            gSolidColorProgram.unbind();
+        }
+    }
+
+    if (success)
+    {
+        gOcclusionProgram.mName = "Occlusion Shader";
+        gOcclusionProgram.mShaderFiles.clear();
+        gOcclusionProgram.mShaderFiles.push_back(make_pair("interface/occlusionV.glsl", GL_VERTEX_SHADER));
+        gOcclusionProgram.mShaderFiles.push_back(make_pair("interface/occlusionF.glsl", GL_FRAGMENT_SHADER));
+        gOcclusionProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
         gOcclusionProgram.mRiggedVariant = &gSkinnedOcclusionProgram;
-		success = gOcclusionProgram.createShader(NULL, NULL);
-	}
+        success = gOcclusionProgram.createShader(NULL, NULL);
+    }
 
     if (success)
     {
@@ -3089,30 +3089,30 @@ BOOL LLViewerShaderMgr::loadShadersInterface()
         success = gSkinnedOcclusionProgram.createShader(NULL, NULL);
     }
 
-	if (success)
-	{
-		gOcclusionCubeProgram.mName = "Occlusion Cube Shader";
-		gOcclusionCubeProgram.mShaderFiles.clear();
-		gOcclusionCubeProgram.mShaderFiles.push_back(make_pair("interface/occlusionCubeV.glsl", GL_VERTEX_SHADER));
-		gOcclusionCubeProgram.mShaderFiles.push_back(make_pair("interface/occlusionF.glsl", GL_FRAGMENT_SHADER));
-		gOcclusionCubeProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gOcclusionCubeProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gDebugProgram.mName = "Debug Shader";
-		gDebugProgram.mShaderFiles.clear();
-		gDebugProgram.mShaderFiles.push_back(make_pair("interface/debugV.glsl", GL_VERTEX_SHADER));
-		gDebugProgram.mShaderFiles.push_back(make_pair("interface/debugF.glsl", GL_FRAGMENT_SHADER));
+    if (success)
+    {
+        gOcclusionCubeProgram.mName = "Occlusion Cube Shader";
+        gOcclusionCubeProgram.mShaderFiles.clear();
+        gOcclusionCubeProgram.mShaderFiles.push_back(make_pair("interface/occlusionCubeV.glsl", GL_VERTEX_SHADER));
+        gOcclusionCubeProgram.mShaderFiles.push_back(make_pair("interface/occlusionF.glsl", GL_FRAGMENT_SHADER));
+        gOcclusionCubeProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gOcclusionCubeProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gDebugProgram.mName = "Debug Shader";
+        gDebugProgram.mShaderFiles.clear();
+        gDebugProgram.mShaderFiles.push_back(make_pair("interface/debugV.glsl", GL_VERTEX_SHADER));
+        gDebugProgram.mShaderFiles.push_back(make_pair("interface/debugF.glsl", GL_FRAGMENT_SHADER));
         gDebugProgram.mRiggedVariant = &gSkinnedDebugProgram;
-		gDebugProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        gDebugProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
         success = make_rigged_variant(gDebugProgram, gSkinnedDebugProgram);
-		success = success && gDebugProgram.createShader(NULL, NULL);
-	}
+        success = success && gDebugProgram.createShader(NULL, NULL);
+    }
 
-	if (success)
-	{
+    if (success)
+    {
         for (S32 variant = 0; variant < NORMAL_DEBUG_SHADER_COUNT; ++variant)
         {
             LLGLSLShader& shader = gNormalDebugProgram[variant];
@@ -3136,27 +3136,27 @@ BOOL LLViewerShaderMgr::loadShadersInterface()
             success = make_rigged_variant(shader, skinned_shader);
             success = success && shader.createShader(NULL, NULL);
         }
-	}
-
-	if (success)
-	{
-		gClipProgram.mName = "Clip Shader";
-		gClipProgram.mShaderFiles.clear();
-		gClipProgram.mShaderFiles.push_back(make_pair("interface/clipV.glsl", GL_VERTEX_SHADER));
-		gClipProgram.mShaderFiles.push_back(make_pair("interface/clipF.glsl", GL_FRAGMENT_SHADER));
-		gClipProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gClipProgram.createShader(NULL, NULL);
-	}
-
-	if (success)
-	{
-		gBenchmarkProgram.mName = "Benchmark Shader";
-		gBenchmarkProgram.mShaderFiles.clear();
-		gBenchmarkProgram.mShaderFiles.push_back(make_pair("interface/benchmarkV.glsl", GL_VERTEX_SHADER));
-		gBenchmarkProgram.mShaderFiles.push_back(make_pair("interface/benchmarkF.glsl", GL_FRAGMENT_SHADER));
-		gBenchmarkProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gBenchmarkProgram.createShader(NULL, NULL);
-	}
+    }
+
+    if (success)
+    {
+        gClipProgram.mName = "Clip Shader";
+        gClipProgram.mShaderFiles.clear();
+        gClipProgram.mShaderFiles.push_back(make_pair("interface/clipV.glsl", GL_VERTEX_SHADER));
+        gClipProgram.mShaderFiles.push_back(make_pair("interface/clipF.glsl", GL_FRAGMENT_SHADER));
+        gClipProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gClipProgram.createShader(NULL, NULL);
+    }
+
+    if (success)
+    {
+        gBenchmarkProgram.mName = "Benchmark Shader";
+        gBenchmarkProgram.mShaderFiles.clear();
+        gBenchmarkProgram.mShaderFiles.push_back(make_pair("interface/benchmarkV.glsl", GL_VERTEX_SHADER));
+        gBenchmarkProgram.mShaderFiles.push_back(make_pair("interface/benchmarkF.glsl", GL_FRAGMENT_SHADER));
+        gBenchmarkProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gBenchmarkProgram.createShader(NULL, NULL);
+    }
 
     if (success)
     {
@@ -3195,16 +3195,16 @@ BOOL LLViewerShaderMgr::loadShadersInterface()
         gCopyDepthProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
         success = gCopyDepthProgram.createShader(NULL, NULL);
     }
-    
-	if (success)
-	{
-		gAlphaMaskProgram.mName = "Alpha Mask Shader";
-		gAlphaMaskProgram.mShaderFiles.clear();
-		gAlphaMaskProgram.mShaderFiles.push_back(make_pair("interface/alphamaskV.glsl", GL_VERTEX_SHADER));
-		gAlphaMaskProgram.mShaderFiles.push_back(make_pair("interface/alphamaskF.glsl", GL_FRAGMENT_SHADER));
-		gAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
-		success = gAlphaMaskProgram.createShader(NULL, NULL);
-	}
+
+    if (success)
+    {
+        gAlphaMaskProgram.mName = "Alpha Mask Shader";
+        gAlphaMaskProgram.mShaderFiles.clear();
+        gAlphaMaskProgram.mShaderFiles.push_back(make_pair("interface/alphamaskV.glsl", GL_VERTEX_SHADER));
+        gAlphaMaskProgram.mShaderFiles.push_back(make_pair("interface/alphamaskF.glsl", GL_FRAGMENT_SHADER));
+        gAlphaMaskProgram.mShaderLevel = mShaderLevel[SHADER_INTERFACE];
+        success = gAlphaMaskProgram.createShader(NULL, NULL);
+    }
 
     if (success)
     {
@@ -3244,7 +3244,7 @@ BOOL LLViewerShaderMgr::loadShadersInterface()
         gRadianceGenProgram.addPermutation("PROBE_FILTER_SAMPLES", "32");
         success = gRadianceGenProgram.createShader(NULL, NULL);
     }
-	
+
     if (success && gGLManager.mHasCubeMapArray)
     {
         gHeroRadianceGenProgram.mName = "Hero Radiance Gen Shader";
@@ -3266,18 +3266,18 @@ BOOL LLViewerShaderMgr::loadShadersInterface()
         success = gIrradianceGenProgram.createShader(NULL, NULL);
     }
 
-	if( !success )
-	{
-		mShaderLevel[SHADER_INTERFACE] = 0;
-		return FALSE;
-	}
-	
-	return TRUE;
+    if( !success )
+    {
+        mShaderLevel[SHADER_INTERFACE] = 0;
+        return FALSE;
+    }
+
+    return TRUE;
 }
 
 std::string LLViewerShaderMgr::getShaderDirPrefix(void)
 {
-	return gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "shaders/class");
+    return gDirUtilp->getExpandedFilename(LL_PATH_APP_SETTINGS, "shaders/class");
 }
 
 void LLViewerShaderMgr::updateShaderUniforms(LLGLSLShader * shader)
@@ -3287,11 +3287,11 @@ void LLViewerShaderMgr::updateShaderUniforms(LLGLSLShader * shader)
 
 LLViewerShaderMgr::shader_iter LLViewerShaderMgr::beginShaders() const
 {
-	return mShaderList.begin();
+    return mShaderList.begin();
 }
 
 LLViewerShaderMgr::shader_iter LLViewerShaderMgr::endShaders() const
 {
-	return mShaderList.end();
+    return mShaderList.end();
 }
 
diff --git a/indra/newview/llviewershadermgr.h b/indra/newview/llviewershadermgr.h
index c66cabc217e8ae69a0a22aeacae4910622e95cae..0c28a57d61c66d3cbf2d0e2b4730d5ba2d16085e 100644
--- a/indra/newview/llviewershadermgr.h
+++ b/indra/newview/llviewershadermgr.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewershadermgr.h
  * @brief Viewer Shader Manager
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -37,179 +37,179 @@
 class LLViewerShaderMgr: public LLShaderMgr
 {
 public:
-	static BOOL sInitialized;
-	static bool sSkipReload;
+    static BOOL sInitialized;
+    static bool sSkipReload;
 
-	LLViewerShaderMgr();
-	/* virtual */ ~LLViewerShaderMgr();
+    LLViewerShaderMgr();
+    /* virtual */ ~LLViewerShaderMgr();
 
     // Add shaders to mShaderList for later uniform propagation
     // Will assert on redundant shader entries in debug builds
     void finalizeShaderList();
 
-	// singleton pattern implementation
-	static LLViewerShaderMgr * instance();
-	static void releaseInstance();
+    // singleton pattern implementation
+    static LLViewerShaderMgr * instance();
+    static void releaseInstance();
 
-	void initAttribsAndUniforms(void);
-	void setShaders();
-	void unloadShaders();
+    void initAttribsAndUniforms(void);
+    void setShaders();
+    void unloadShaders();
     S32  getShaderLevel(S32 type);
 
     // loadBasicShaders in case of a failure returns
     // name of a file error happened at, otherwise
     // returns an empty string
     std::string loadBasicShaders();
-	BOOL loadShadersEffects();
-	BOOL loadShadersDeferred();
-	BOOL loadShadersObject();
-	BOOL loadShadersAvatar();
-	BOOL loadShadersWater();
-	BOOL loadShadersInterface();
-
-	std::vector<S32> mShaderLevel;
-	S32	mMaxAvatarShaderLevel;
-
-	enum EShaderClass
-	{
-		SHADER_LIGHTING,
-		SHADER_OBJECT,
-		SHADER_AVATAR,
-		SHADER_ENVIRONMENT,
-		SHADER_INTERFACE,
-		SHADER_EFFECT,
-		SHADER_WINDLIGHT,
-		SHADER_WATER,
-		SHADER_DEFERRED,
-		SHADER_COUNT
-	};
-
-	// simple model of forward iterator
-	// http://www.sgi.com/tech/stl/ForwardIterator.html
-	class shader_iter
-	{
-	private:
-		friend bool operator == (shader_iter const & a, shader_iter const & b);
-		friend bool operator != (shader_iter const & a, shader_iter const & b);
-
-		typedef std::vector<LLGLSLShader *>::const_iterator base_iter_t;
-	public:
-		shader_iter()
-		{
-		}
-
-		shader_iter(base_iter_t iter) : mIter(iter)
-		{
-		}
-
-		LLGLSLShader & operator * () const
-		{
-			return **mIter;
-		}
-
-		LLGLSLShader * operator -> () const
-		{
-			return *mIter;
-		}
-
-		shader_iter & operator++ ()
-		{
-			++mIter;
-			return *this;
-		}
-
-		shader_iter operator++ (int)
-		{
-			return mIter++;
-		}
-
-	private:
-		base_iter_t mIter;
-	};
-
-	shader_iter beginShaders() const;
-	shader_iter endShaders() const;
-
-	/* virtual */ std::string getShaderDirPrefix(void);
-
-	/* virtual */ void updateShaderUniforms(LLGLSLShader * shader);
+    BOOL loadShadersEffects();
+    BOOL loadShadersDeferred();
+    BOOL loadShadersObject();
+    BOOL loadShadersAvatar();
+    BOOL loadShadersWater();
+    BOOL loadShadersInterface();
+
+    std::vector<S32> mShaderLevel;
+    S32 mMaxAvatarShaderLevel;
+
+    enum EShaderClass
+    {
+        SHADER_LIGHTING,
+        SHADER_OBJECT,
+        SHADER_AVATAR,
+        SHADER_ENVIRONMENT,
+        SHADER_INTERFACE,
+        SHADER_EFFECT,
+        SHADER_WINDLIGHT,
+        SHADER_WATER,
+        SHADER_DEFERRED,
+        SHADER_COUNT
+    };
+
+    // simple model of forward iterator
+    // http://www.sgi.com/tech/stl/ForwardIterator.html
+    class shader_iter
+    {
+    private:
+        friend bool operator == (shader_iter const & a, shader_iter const & b);
+        friend bool operator != (shader_iter const & a, shader_iter const & b);
+
+        typedef std::vector<LLGLSLShader *>::const_iterator base_iter_t;
+    public:
+        shader_iter()
+        {
+        }
+
+        shader_iter(base_iter_t iter) : mIter(iter)
+        {
+        }
+
+        LLGLSLShader & operator * () const
+        {
+            return **mIter;
+        }
+
+        LLGLSLShader * operator -> () const
+        {
+            return *mIter;
+        }
+
+        shader_iter & operator++ ()
+        {
+            ++mIter;
+            return *this;
+        }
+
+        shader_iter operator++ (int)
+        {
+            return mIter++;
+        }
+
+    private:
+        base_iter_t mIter;
+    };
+
+    shader_iter beginShaders() const;
+    shader_iter endShaders() const;
+
+    /* virtual */ std::string getShaderDirPrefix(void);
+
+    /* virtual */ void updateShaderUniforms(LLGLSLShader * shader);
 
 private:
-	// the list of shaders we need to propagate parameters to.
-	std::vector<LLGLSLShader *> mShaderList;
+    // the list of shaders we need to propagate parameters to.
+    std::vector<LLGLSLShader *> mShaderList;
 
 }; //LLViewerShaderMgr
 
 inline bool operator == (LLViewerShaderMgr::shader_iter const & a, LLViewerShaderMgr::shader_iter const & b)
 {
-	return a.mIter == b.mIter;
+    return a.mIter == b.mIter;
 }
 
 inline bool operator != (LLViewerShaderMgr::shader_iter const & a, LLViewerShaderMgr::shader_iter const & b)
 {
-	return a.mIter != b.mIter;
+    return a.mIter != b.mIter;
 }
 
-extern LLVector4			gShinyOrigin;
+extern LLVector4            gShinyOrigin;
 //utility shaders
-extern LLGLSLShader			gOcclusionProgram;
-extern LLGLSLShader			gOcclusionCubeProgram;
-extern LLGLSLShader			gGlowCombineProgram;
-extern LLGLSLShader			gReflectionMipProgram;
+extern LLGLSLShader         gOcclusionProgram;
+extern LLGLSLShader         gOcclusionCubeProgram;
+extern LLGLSLShader         gGlowCombineProgram;
+extern LLGLSLShader         gReflectionMipProgram;
 extern LLGLSLShader         gGaussianProgram;
 extern LLGLSLShader         gRadianceGenProgram;
 extern LLGLSLShader         gHeroRadianceGenProgram;
 extern LLGLSLShader         gIrradianceGenProgram;
-extern LLGLSLShader			gGlowCombineFXAAProgram;
-extern LLGLSLShader			gDebugProgram;
+extern LLGLSLShader         gGlowCombineFXAAProgram;
+extern LLGLSLShader         gDebugProgram;
 enum NormalDebugShaderVariant : S32
 {
     NORMAL_DEBUG_SHADER_DEFAULT,
     NORMAL_DEBUG_SHADER_WITH_TANGENTS,
     NORMAL_DEBUG_SHADER_COUNT
 };
-extern LLGLSLShader			gNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
-extern LLGLSLShader			gSkinnedNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
-extern LLGLSLShader			gClipProgram;
-extern LLGLSLShader			gBenchmarkProgram;
+extern LLGLSLShader         gNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
+extern LLGLSLShader         gSkinnedNormalDebugProgram[NORMAL_DEBUG_SHADER_COUNT];
+extern LLGLSLShader         gClipProgram;
+extern LLGLSLShader         gBenchmarkProgram;
 extern LLGLSLShader         gReflectionProbeDisplayProgram;
 extern LLGLSLShader         gCopyProgram;
 extern LLGLSLShader         gCopyDepthProgram;
 
 //output tex0[tc0] - tex1[tc1]
-extern LLGLSLShader			gTwoTextureCompareProgram;
+extern LLGLSLShader         gTwoTextureCompareProgram;
 //discard some fragments based on user-set color tolerance
-extern LLGLSLShader			gOneTextureFilterProgram;
-						
+extern LLGLSLShader         gOneTextureFilterProgram;
+
 
 //object shaders
-extern LLGLSLShader		gObjectPreviewProgram;
+extern LLGLSLShader     gObjectPreviewProgram;
 extern LLGLSLShader        gPhysicsPreviewProgram;
-extern LLGLSLShader		gObjectBumpProgram;
+extern LLGLSLShader     gObjectBumpProgram;
 extern LLGLSLShader        gSkinnedObjectBumpProgram;
-extern LLGLSLShader		gObjectAlphaMaskNoColorProgram;
+extern LLGLSLShader     gObjectAlphaMaskNoColorProgram;
 
 //environment shaders
-extern LLGLSLShader			gWaterProgram;
-extern LLGLSLShader			gWaterEdgeProgram;
-extern LLGLSLShader			gUnderWaterProgram;
-extern LLGLSLShader			gGlowProgram;
-extern LLGLSLShader			gGlowExtractProgram;
+extern LLGLSLShader         gWaterProgram;
+extern LLGLSLShader         gWaterEdgeProgram;
+extern LLGLSLShader         gUnderWaterProgram;
+extern LLGLSLShader         gGlowProgram;
+extern LLGLSLShader         gGlowExtractProgram;
 
 //interface shaders
-extern LLGLSLShader			gHighlightProgram;
-extern LLGLSLShader			gHighlightNormalProgram;
-extern LLGLSLShader			gHighlightSpecularProgram;
+extern LLGLSLShader         gHighlightProgram;
+extern LLGLSLShader         gHighlightNormalProgram;
+extern LLGLSLShader         gHighlightSpecularProgram;
 
-extern LLGLSLShader			gDeferredHighlightProgram;
+extern LLGLSLShader         gDeferredHighlightProgram;
 
-extern LLGLSLShader			gPathfindingProgram;
-extern LLGLSLShader			gPathfindingNoNormalsProgram;
+extern LLGLSLShader         gPathfindingProgram;
+extern LLGLSLShader         gPathfindingNoNormalsProgram;
 
 // avatar shader handles
-extern LLGLSLShader			gAvatarProgram;
-extern LLGLSLShader			gAvatarEyeballProgram;
-extern LLGLSLShader			gImpostorProgram;
+extern LLGLSLShader         gAvatarProgram;
+extern LLGLSLShader         gAvatarEyeballProgram;
+extern LLGLSLShader         gImpostorProgram;
 
 // Post Process Shaders
 extern LLGLSLShader         gPostScreenSpaceReflectionProgram;
@@ -219,85 +219,85 @@ extern LLGLSLShader         gPostSMAABlendWeights[4];
 extern LLGLSLShader         gPostSMAANeighborhoodBlend[4];
 
 // Deferred rendering shaders
-extern LLGLSLShader			gDeferredImpostorProgram;
-extern LLGLSLShader			gDeferredDiffuseProgram;
-extern LLGLSLShader			gDeferredDiffuseAlphaMaskProgram;
-extern LLGLSLShader			gDeferredNonIndexedDiffuseAlphaMaskProgram;
-extern LLGLSLShader			gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
-extern LLGLSLShader			gDeferredNonIndexedDiffuseProgram;
-extern LLGLSLShader			gDeferredBumpProgram;
-extern LLGLSLShader			gDeferredTerrainProgram;
-extern LLGLSLShader			gDeferredTreeProgram;
-extern LLGLSLShader			gDeferredTreeShadowProgram;
-extern LLGLSLShader			gDeferredLightProgram;
-extern LLGLSLShader			gDeferredMultiLightProgram[LL_DEFERRED_MULTI_LIGHT_COUNT];
-extern LLGLSLShader			gDeferredSpotLightProgram;
-extern LLGLSLShader			gDeferredMultiSpotLightProgram;
-extern LLGLSLShader			gDeferredSunProgram;
+extern LLGLSLShader         gDeferredImpostorProgram;
+extern LLGLSLShader         gDeferredDiffuseProgram;
+extern LLGLSLShader         gDeferredDiffuseAlphaMaskProgram;
+extern LLGLSLShader         gDeferredNonIndexedDiffuseAlphaMaskProgram;
+extern LLGLSLShader         gDeferredNonIndexedDiffuseAlphaMaskNoColorProgram;
+extern LLGLSLShader         gDeferredNonIndexedDiffuseProgram;
+extern LLGLSLShader         gDeferredBumpProgram;
+extern LLGLSLShader         gDeferredTerrainProgram;
+extern LLGLSLShader         gDeferredTreeProgram;
+extern LLGLSLShader         gDeferredTreeShadowProgram;
+extern LLGLSLShader         gDeferredLightProgram;
+extern LLGLSLShader         gDeferredMultiLightProgram[LL_DEFERRED_MULTI_LIGHT_COUNT];
+extern LLGLSLShader         gDeferredSpotLightProgram;
+extern LLGLSLShader         gDeferredMultiSpotLightProgram;
+extern LLGLSLShader         gDeferredSunProgram;
 extern LLGLSLShader         gHazeProgram;
 extern LLGLSLShader         gHazeWaterProgram;
-extern LLGLSLShader			gDeferredBlurLightProgram;
-extern LLGLSLShader			gDeferredAvatarProgram;
-extern LLGLSLShader			gDeferredSoftenProgram;
-extern LLGLSLShader			gDeferredShadowProgram;
-extern LLGLSLShader			gDeferredShadowCubeProgram;
-extern LLGLSLShader			gDeferredShadowAlphaMaskProgram;
+extern LLGLSLShader         gDeferredBlurLightProgram;
+extern LLGLSLShader         gDeferredAvatarProgram;
+extern LLGLSLShader         gDeferredSoftenProgram;
+extern LLGLSLShader         gDeferredShadowProgram;
+extern LLGLSLShader         gDeferredShadowCubeProgram;
+extern LLGLSLShader         gDeferredShadowAlphaMaskProgram;
 extern LLGLSLShader         gDeferredShadowGLTFAlphaMaskProgram;
 extern LLGLSLShader         gDeferredShadowGLTFAlphaBlendProgram;
-extern LLGLSLShader			gDeferredShadowFullbrightAlphaMaskProgram;
-extern LLGLSLShader			gDeferredPostProgram;
-extern LLGLSLShader			gDeferredPostProgramNoNear;
-extern LLGLSLShader			gDeferredCoFProgram;
-extern LLGLSLShader			gDeferredDoFCombineProgram;
-extern LLGLSLShader			gFXAAProgram[4];
-extern LLGLSLShader			gDeferredPostNoDoFProgram;
-extern LLGLSLShader			gDeferredPostGammaCorrectProgram;
+extern LLGLSLShader         gDeferredShadowFullbrightAlphaMaskProgram;
+extern LLGLSLShader         gDeferredPostProgram;
+extern LLGLSLShader         gDeferredPostProgramNoNear;
+extern LLGLSLShader         gDeferredCoFProgram;
+extern LLGLSLShader         gDeferredDoFCombineProgram;
+extern LLGLSLShader         gFXAAProgram[4];
+extern LLGLSLShader         gDeferredPostNoDoFProgram;
+extern LLGLSLShader         gDeferredPostGammaCorrectProgram;
 extern LLGLSLShader         gNoPostGammaCorrectProgram;
 extern LLGLSLShader         gLegacyPostGammaCorrectProgram;
-extern LLGLSLShader			gExposureProgram;
-extern LLGLSLShader			gExposureProgramNoFade;
-extern LLGLSLShader			gLuminanceProgram;
-extern LLGLSLShader			gDeferredAvatarShadowProgram;
-extern LLGLSLShader			gDeferredAvatarAlphaShadowProgram;
-extern LLGLSLShader			gDeferredAvatarAlphaMaskShadowProgram;
-extern LLGLSLShader			gDeferredAlphaProgram;
-extern LLGLSLShader			gHUDAlphaProgram;
-extern LLGLSLShader			gDeferredAlphaImpostorProgram;
-extern LLGLSLShader			gDeferredFullbrightProgram;
-extern LLGLSLShader			gHUDFullbrightProgram;
-extern LLGLSLShader			gDeferredFullbrightAlphaMaskProgram;
-extern LLGLSLShader			gHUDFullbrightAlphaMaskProgram;
-extern LLGLSLShader			gDeferredFullbrightAlphaMaskAlphaProgram;
-extern LLGLSLShader			gHUDFullbrightAlphaMaskAlphaProgram;
-extern LLGLSLShader			gDeferredEmissiveProgram;
-extern LLGLSLShader			gDeferredAvatarEyesProgram;
-extern LLGLSLShader			gDeferredAvatarAlphaProgram;
+extern LLGLSLShader         gExposureProgram;
+extern LLGLSLShader         gExposureProgramNoFade;
+extern LLGLSLShader         gLuminanceProgram;
+extern LLGLSLShader         gDeferredAvatarShadowProgram;
+extern LLGLSLShader         gDeferredAvatarAlphaShadowProgram;
+extern LLGLSLShader         gDeferredAvatarAlphaMaskShadowProgram;
+extern LLGLSLShader         gDeferredAlphaProgram;
+extern LLGLSLShader         gHUDAlphaProgram;
+extern LLGLSLShader         gDeferredAlphaImpostorProgram;
+extern LLGLSLShader         gDeferredFullbrightProgram;
+extern LLGLSLShader         gHUDFullbrightProgram;
+extern LLGLSLShader         gDeferredFullbrightAlphaMaskProgram;
+extern LLGLSLShader         gHUDFullbrightAlphaMaskProgram;
+extern LLGLSLShader         gDeferredFullbrightAlphaMaskAlphaProgram;
+extern LLGLSLShader         gHUDFullbrightAlphaMaskAlphaProgram;
+extern LLGLSLShader         gDeferredEmissiveProgram;
+extern LLGLSLShader         gDeferredAvatarEyesProgram;
+extern LLGLSLShader         gDeferredAvatarAlphaProgram;
 extern LLGLSLShader         gEnvironmentMapProgram;
-extern LLGLSLShader			gDeferredWLSkyProgram;
-extern LLGLSLShader			gDeferredWLCloudProgram;
-extern LLGLSLShader			gDeferredWLSunProgram;
-extern LLGLSLShader			gDeferredWLMoonProgram;
-extern LLGLSLShader			gDeferredStarProgram;
-extern LLGLSLShader			gDeferredFullbrightShinyProgram;
+extern LLGLSLShader         gDeferredWLSkyProgram;
+extern LLGLSLShader         gDeferredWLCloudProgram;
+extern LLGLSLShader         gDeferredWLSunProgram;
+extern LLGLSLShader         gDeferredWLMoonProgram;
+extern LLGLSLShader         gDeferredStarProgram;
+extern LLGLSLShader         gDeferredFullbrightShinyProgram;
 extern LLGLSLShader         gHUDFullbrightShinyProgram;
-extern LLGLSLShader			gNormalMapGenProgram;
+extern LLGLSLShader         gNormalMapGenProgram;
 extern LLGLSLShader         gDeferredGenBrdfLutProgram;
-extern LLGLSLShader			gDeferredBufferVisualProgram;
+extern LLGLSLShader         gDeferredBufferVisualProgram;
 extern LLGLSLShader         gDeferredPostCASProgram;
-extern LLGLSLShader			gDeferredPostDLSProgram;
-extern LLGLSLShader			gDeferredPostTonemapProgram;
-extern LLGLSLShader			gDeferredPostTonemapACESProgram;
-extern LLGLSLShader			gDeferredPostTonemapUchiProgram;
-extern LLGLSLShader			gDeferredPostTonemapLPMProgram;
-extern LLGLSLShader			gDeferredPostTonemapHableProgram;
-extern LLGLSLShader			gDeferredPostColorCorrectProgram[3];
-extern LLGLSLShader			gDeferredPostColorCorrectLUTProgram[3];
+extern LLGLSLShader         gDeferredPostDLSProgram;
+extern LLGLSLShader         gDeferredPostTonemapProgram;
+extern LLGLSLShader         gDeferredPostTonemapACESProgram;
+extern LLGLSLShader         gDeferredPostTonemapUchiProgram;
+extern LLGLSLShader         gDeferredPostTonemapLPMProgram;
+extern LLGLSLShader         gDeferredPostTonemapHableProgram;
+extern LLGLSLShader         gDeferredPostColorCorrectProgram[3];
+extern LLGLSLShader         gDeferredPostColorCorrectLUTProgram[3];
 // [RLVa:KB] - @setsphere
-extern LLGLSLShader			gRlvSphereProgram;
+extern LLGLSLShader         gRlvSphereProgram;
 // [/RLVa:KB]
 
 // Deferred materials shaders
-extern LLGLSLShader			gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2];
+extern LLGLSLShader         gDeferredMaterialProgram[LLMaterial::SHADER_COUNT*2];
 
 extern LLGLSLShader         gHUDPBROpaqueProgram;
 extern LLGLSLShader         gPBRGlowProgram;
diff --git a/indra/newview/llviewertexture.cpp b/indra/newview/llviewertexture.cpp
index 40a724e3636950a4c9a285d3c377a83f81015bab..5cbab6d5d49ec60393cd32ddd368185944971e27 100644
--- a/indra/newview/llviewertexture.cpp
+++ b/indra/newview/llviewertexture.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewertexture.cpp
  * @brief Object which handles a received image (and associated texture(s))
  *
  * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -123,24 +123,24 @@ const U32 DESIRED_NORMAL_TEXTURE_SIZE = (U32)LLViewerFetchedTexture::MAX_IMAGE_S
 //----------------------------------------------------------------------------------------------
 
 LLLoadedCallbackEntry::LLLoadedCallbackEntry(loaded_callback_func cb,
-					  S32 discard_level,
-					  BOOL need_imageraw, // Needs image raw for the callback
-					  void* userdata,
-					  LLLoadedCallbackEntry::source_callback_list_t* src_callback_list,
-					  LLViewerFetchedTexture* target,
-					  BOOL pause) 
-	: mCallback(cb),
-	  mLastUsedDiscard(MAX_DISCARD_LEVEL+1),
-	  mDesiredDiscard(discard_level),
-	  mNeedsImageRaw(need_imageraw),
-	  mUserData(userdata),
-	  mSourceCallbackList(src_callback_list),
-	  mPaused(pause)
-{
-	if(mSourceCallbackList)
-	{
+                      S32 discard_level,
+                      BOOL need_imageraw, // Needs image raw for the callback
+                      void* userdata,
+                      LLLoadedCallbackEntry::source_callback_list_t* src_callback_list,
+                      LLViewerFetchedTexture* target,
+                      BOOL pause)
+    : mCallback(cb),
+      mLastUsedDiscard(MAX_DISCARD_LEVEL+1),
+      mDesiredDiscard(discard_level),
+      mNeedsImageRaw(need_imageraw),
+      mUserData(userdata),
+      mSourceCallbackList(src_callback_list),
+      mPaused(pause)
+{
+    if(mSourceCallbackList)
+    {
         mSourceCallbackList->insert(LLTextureKey(target->getID(), (ETexListType)target->getTextureListType()));
-	}
+    }
 }
 
 LLLoadedCallbackEntry::~LLLoadedCallbackEntry()
@@ -149,34 +149,34 @@ LLLoadedCallbackEntry::~LLLoadedCallbackEntry()
 
 void LLLoadedCallbackEntry::removeTexture(LLViewerFetchedTexture* tex)
 {
-	if(mSourceCallbackList)
-	{
-		mSourceCallbackList->erase(LLTextureKey(tex->getID(), (ETexListType)tex->getTextureListType()));
-	}
+    if(mSourceCallbackList)
+    {
+        mSourceCallbackList->erase(LLTextureKey(tex->getID(), (ETexListType)tex->getTextureListType()));
+    }
 }
 
-//static 
+//static
 void LLLoadedCallbackEntry::cleanUpCallbackList(LLLoadedCallbackEntry::source_callback_list_t* callback_list)
 {
-	//clear texture callbacks.
-	if(callback_list && !callback_list->empty())
-	{
-		for(LLLoadedCallbackEntry::source_callback_list_t::iterator iter = callback_list->begin();
-				iter != callback_list->end(); ++iter)
-		{
-			LLViewerFetchedTexture* tex = gTextureList.findImage(*iter);
-			if(tex)
-			{
-				tex->deleteCallbackEntry(callback_list);			
-			}
-		}
-		callback_list->clear();
-	}
+    //clear texture callbacks.
+    if(callback_list && !callback_list->empty())
+    {
+        for(LLLoadedCallbackEntry::source_callback_list_t::iterator iter = callback_list->begin();
+                iter != callback_list->end(); ++iter)
+        {
+            LLViewerFetchedTexture* tex = gTextureList.findImage(*iter);
+            if(tex)
+            {
+                tex->deleteCallbackEntry(callback_list);
+            }
+        }
+        callback_list->clear();
+    }
 }
 
 LLViewerMediaTexture* LLViewerTextureManager::createMediaTexture(const LLUUID &media_id, BOOL usemipmaps, LLImageGL* gl_image)
 {
-	return new LLViewerMediaTexture(media_id, usemipmaps, gl_image);		
+    return new LLViewerMediaTexture(media_id, usemipmaps, gl_image);
 }
 
 void LLViewerTextureManager::findFetchedTextures(const LLUUID& id, std::vector<LLViewerFetchedTexture*> &output)
@@ -217,78 +217,78 @@ LLViewerFetchedTexture* LLViewerTextureManager::findFetchedTexture(const LLUUID&
 
 LLViewerMediaTexture* LLViewerTextureManager::findMediaTexture(const LLUUID &media_id)
 {
-	return LLViewerMediaTexture::findMediaTexture(media_id);	
+    return LLViewerMediaTexture::findMediaTexture(media_id);
 }
 
-LLViewerMediaTexture*  LLViewerTextureManager::getMediaTexture(const LLUUID& id, BOOL usemipmaps, LLImageGL* gl_image) 
+LLViewerMediaTexture*  LLViewerTextureManager::getMediaTexture(const LLUUID& id, BOOL usemipmaps, LLImageGL* gl_image)
 {
-	LLViewerMediaTexture* tex = LLViewerMediaTexture::findMediaTexture(id);	
-	if(!tex)
-	{
-		tex = LLViewerTextureManager::createMediaTexture(id, usemipmaps, gl_image);
-	}
+    LLViewerMediaTexture* tex = LLViewerMediaTexture::findMediaTexture(id);
+    if(!tex)
+    {
+        tex = LLViewerTextureManager::createMediaTexture(id, usemipmaps, gl_image);
+    }
 
-	tex->initVirtualSize();
+    tex->initVirtualSize();
 
-	return tex;
+    return tex;
 }
 
 LLViewerFetchedTexture* LLViewerTextureManager::staticCastToFetchedTexture(LLTexture* tex, BOOL report_error)
 {
-	if(!tex)
-	{
-		return NULL;
-	}
+    if(!tex)
+    {
+        return NULL;
+    }
 
-	S8 type = tex->getType();
-	if(type == LLViewerTexture::FETCHED_TEXTURE || type == LLViewerTexture::LOD_TEXTURE)
-	{
-		return static_cast<LLViewerFetchedTexture*>(tex);
-	}
+    S8 type = tex->getType();
+    if(type == LLViewerTexture::FETCHED_TEXTURE || type == LLViewerTexture::LOD_TEXTURE)
+    {
+        return static_cast<LLViewerFetchedTexture*>(tex);
+    }
 
-	if(report_error)
-	{
-		LL_ERRS() << "not a fetched texture type: " << type << LL_ENDL;
-	}
+    if(report_error)
+    {
+        LL_ERRS() << "not a fetched texture type: " << type << LL_ENDL;
+    }
 
-	return NULL;
+    return NULL;
 }
 
 LLPointer<LLViewerTexture> LLViewerTextureManager::getLocalTexture(BOOL usemipmaps, BOOL generate_gl_tex)
 {
-	LLPointer<LLViewerTexture> tex = new LLViewerTexture(usemipmaps);
-	if(generate_gl_tex)
-	{
-		tex->generateGLTexture();
-		tex->setCategory(LLGLTexture::LOCAL);
-	}
-	return tex;
+    LLPointer<LLViewerTexture> tex = new LLViewerTexture(usemipmaps);
+    if(generate_gl_tex)
+    {
+        tex->generateGLTexture();
+        tex->setCategory(LLGLTexture::LOCAL);
+    }
+    return tex;
 }
-LLPointer<LLViewerTexture> LLViewerTextureManager::getLocalTexture(const LLUUID& id, BOOL usemipmaps, BOOL generate_gl_tex) 
+LLPointer<LLViewerTexture> LLViewerTextureManager::getLocalTexture(const LLUUID& id, BOOL usemipmaps, BOOL generate_gl_tex)
 {
-	LLPointer<LLViewerTexture> tex = new LLViewerTexture(id, usemipmaps);
-	if(generate_gl_tex)
-	{
-		tex->generateGLTexture();
-		tex->setCategory(LLGLTexture::LOCAL);
-	}
-	return tex;
+    LLPointer<LLViewerTexture> tex = new LLViewerTexture(id, usemipmaps);
+    if(generate_gl_tex)
+    {
+        tex->generateGLTexture();
+        tex->setCategory(LLGLTexture::LOCAL);
+    }
+    return tex;
 }
-LLPointer<LLViewerTexture> LLViewerTextureManager::getLocalTexture(const LLImageRaw* raw, BOOL usemipmaps) 
+LLPointer<LLViewerTexture> LLViewerTextureManager::getLocalTexture(const LLImageRaw* raw, BOOL usemipmaps)
 {
-	LLPointer<LLViewerTexture> tex = new LLViewerTexture(raw, usemipmaps);
-	tex->setCategory(LLGLTexture::LOCAL);
-	return tex;
+    LLPointer<LLViewerTexture> tex = new LLViewerTexture(raw, usemipmaps);
+    tex->setCategory(LLGLTexture::LOCAL);
+    return tex;
 }
-LLPointer<LLViewerTexture> LLViewerTextureManager::getLocalTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps, BOOL generate_gl_tex) 
+LLPointer<LLViewerTexture> LLViewerTextureManager::getLocalTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps, BOOL generate_gl_tex)
 {
-	LLPointer<LLViewerTexture> tex = new LLViewerTexture(width, height, components, usemipmaps);
-	if(generate_gl_tex)
-	{
-		tex->generateGLTexture();
-		tex->setCategory(LLGLTexture::LOCAL);
-	}
-	return tex;
+    LLPointer<LLViewerTexture> tex = new LLViewerTexture(width, height, components, usemipmaps);
+    if(generate_gl_tex)
+    {
+        tex->generateGLTexture();
+        tex->setCategory(LLGLTexture::LOCAL);
+    }
+    return tex;
 }
 
 LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTexture(const LLImageRaw* raw, FTType type, bool usemipmaps)
@@ -299,172 +299,172 @@ LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTexture(const LLImageR
 }
 
 LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTexture(
-	                                               const LLUUID &image_id,											       
-												   FTType f_type,
-												   BOOL usemipmaps,
-												   LLViewerTexture::EBoostLevel boost_priority,
-												   S8 texture_type,
-												   LLGLint internal_format,
-												   LLGLenum primary_format,
-												   LLHost request_from_host)
-{
-	return gTextureList.getImage(image_id, f_type, usemipmaps, boost_priority, texture_type, internal_format, primary_format, request_from_host);
-}
-	
+                                                   const LLUUID &image_id,
+                                                   FTType f_type,
+                                                   BOOL usemipmaps,
+                                                   LLViewerTexture::EBoostLevel boost_priority,
+                                                   S8 texture_type,
+                                                   LLGLint internal_format,
+                                                   LLGLenum primary_format,
+                                                   LLHost request_from_host)
+{
+    return gTextureList.getImage(image_id, f_type, usemipmaps, boost_priority, texture_type, internal_format, primary_format, request_from_host);
+}
+
 LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromFile(
-	                                               const std::string& filename,
-												   FTType f_type,
-												   BOOL usemipmaps,
-												   LLViewerTexture::EBoostLevel boost_priority,
-												   S8 texture_type,
-												   LLGLint internal_format,
-												   LLGLenum primary_format, 
-												   const LLUUID& force_id)
+                                                   const std::string& filename,
+                                                   FTType f_type,
+                                                   BOOL usemipmaps,
+                                                   LLViewerTexture::EBoostLevel boost_priority,
+                                                   S8 texture_type,
+                                                   LLGLint internal_format,
+                                                   LLGLenum primary_format,
+                                                   const LLUUID& force_id)
 {
-	return gTextureList.getImageFromFile(filename, f_type, usemipmaps, boost_priority, texture_type, internal_format, primary_format, force_id);
+    return gTextureList.getImageFromFile(filename, f_type, usemipmaps, boost_priority, texture_type, internal_format, primary_format, force_id);
 }
 
-//static 
+//static
 LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromUrl(const std::string& url,
-									 FTType f_type,
-									 BOOL usemipmaps,
-									 LLViewerTexture::EBoostLevel boost_priority,
-									 S8 texture_type,
-									 LLGLint internal_format,
-									 LLGLenum primary_format,
-									 const LLUUID& force_id
-									 )
+                                     FTType f_type,
+                                     BOOL usemipmaps,
+                                     LLViewerTexture::EBoostLevel boost_priority,
+                                     S8 texture_type,
+                                     LLGLint internal_format,
+                                     LLGLenum primary_format,
+                                     const LLUUID& force_id
+                                     )
 {
-	return gTextureList.getImageFromUrl(url, f_type, usemipmaps, boost_priority, texture_type, internal_format, primary_format, force_id);
+    return gTextureList.getImageFromUrl(url, f_type, usemipmaps, boost_priority, texture_type, internal_format, primary_format, force_id);
 }
 
-LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromHost(const LLUUID& image_id, FTType f_type, LLHost host) 
+LLViewerFetchedTexture* LLViewerTextureManager::getFetchedTextureFromHost(const LLUUID& image_id, FTType f_type, LLHost host)
 {
-	return gTextureList.getImageFromHost(image_id, f_type, host);
+    return gTextureList.getImageFromHost(image_id, f_type, host);
 }
 
 // Create a bridge to the viewer texture manager.
 class LLViewerTextureManagerBridge : public LLTextureManagerBridge
 {
-	/*virtual*/ LLPointer<LLGLTexture> getLocalTexture(BOOL usemipmaps = TRUE, BOOL generate_gl_tex = TRUE)
-	{
-		return LLViewerTextureManager::getLocalTexture(usemipmaps, generate_gl_tex);
-	}
+    /*virtual*/ LLPointer<LLGLTexture> getLocalTexture(BOOL usemipmaps = TRUE, BOOL generate_gl_tex = TRUE)
+    {
+        return LLViewerTextureManager::getLocalTexture(usemipmaps, generate_gl_tex);
+    }
 
-	/*virtual*/ LLPointer<LLGLTexture> getLocalTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps, BOOL generate_gl_tex = TRUE)
-	{
-		return LLViewerTextureManager::getLocalTexture(width, height, components, usemipmaps, generate_gl_tex);
-	}
+    /*virtual*/ LLPointer<LLGLTexture> getLocalTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps, BOOL generate_gl_tex = TRUE)
+    {
+        return LLViewerTextureManager::getLocalTexture(width, height, components, usemipmaps, generate_gl_tex);
+    }
 
-	/*virtual*/ LLGLTexture* getFetchedTexture(const LLUUID &image_id)
-	{
-		return LLViewerTextureManager::getFetchedTexture(image_id);
-	}
+    /*virtual*/ LLGLTexture* getFetchedTexture(const LLUUID &image_id)
+    {
+        return LLViewerTextureManager::getFetchedTexture(image_id);
+    }
 };
 
 
 void LLViewerTextureManager::init()
 {
-	{
-		LLPointer<LLImageRaw> raw = new LLImageRaw(1,1,3);
-		raw->clear(0x77, 0x77, 0x77, 0xFF);
-		LLViewerTexture::sNullImagep = LLViewerTextureManager::getLocalTexture(raw.get(), TRUE);
-	}
+    {
+        LLPointer<LLImageRaw> raw = new LLImageRaw(1,1,3);
+        raw->clear(0x77, 0x77, 0x77, 0xFF);
+        LLViewerTexture::sNullImagep = LLViewerTextureManager::getLocalTexture(raw.get(), TRUE);
+    }
+
+    const S32 dim = 128;
+    LLPointer<LLImageRaw> image_raw = new LLImageRaw(dim,dim,3);
+    U8* data = image_raw->getData();
 
-	const S32 dim = 128;
-	LLPointer<LLImageRaw> image_raw = new LLImageRaw(dim,dim,3);
-	U8* data = image_raw->getData();
-	
-	memset(data, 0, dim * dim * 3);
-	LLViewerTexture::sBlackImagep = LLViewerTextureManager::getLocalTexture(image_raw.get(), TRUE);
+    memset(data, 0, dim * dim * 3);
+    LLViewerTexture::sBlackImagep = LLViewerTextureManager::getLocalTexture(image_raw.get(), TRUE);
 
 #if 1
-	LLPointer<LLViewerFetchedTexture> imagep = LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT);
-	LLViewerFetchedTexture::sDefaultImagep = imagep;
-	
-	for (S32 i = 0; i<dim; i++)
-	{
-		for (S32 j = 0; j<dim; j++)
-		{
+    LLPointer<LLViewerFetchedTexture> imagep = LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT);
+    LLViewerFetchedTexture::sDefaultImagep = imagep;
+
+    for (S32 i = 0; i<dim; i++)
+    {
+        for (S32 j = 0; j<dim; j++)
+        {
 #if 0
-			const S32 border = 2;
-			if (i<border || j<border || i>=(dim-border) || j>=(dim-border))
-			{
-				*data++ = 0xff;
-				*data++ = 0xff;
-				*data++ = 0xff;
-			}
-			else
+            const S32 border = 2;
+            if (i<border || j<border || i>=(dim-border) || j>=(dim-border))
+            {
+                *data++ = 0xff;
+                *data++ = 0xff;
+                *data++ = 0xff;
+            }
+            else
 #endif
-			{
-				*data++ = 0x7f;
-				*data++ = 0x7f;
-				*data++ = 0x7f;
-			}
-		}
-	}
-	imagep->createGLTexture(0, image_raw);
-	//cache the raw image
-	imagep->setCachedRawImage(0, image_raw);
-	image_raw = NULL;
+            {
+                *data++ = 0x7f;
+                *data++ = 0x7f;
+                *data++ = 0x7f;
+            }
+        }
+    }
+    imagep->createGLTexture(0, image_raw);
+    //cache the raw image
+    imagep->setCachedRawImage(0, image_raw);
+    image_raw = NULL;
 #else
- 	LLViewerFetchedTexture::sDefaultImagep = LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, TRUE, LLGLTexture::BOOST_UI);
+    LLViewerFetchedTexture::sDefaultImagep = LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT, TRUE, LLGLTexture::BOOST_UI);
 #endif
-	LLViewerFetchedTexture::sDefaultImagep->dontDiscard();
-	LLViewerFetchedTexture::sDefaultImagep->setCategory(LLGLTexture::OTHER);
-
-	image_raw = new LLImageRaw(32,32,3);
-	data = image_raw->getData();
-
-	for (S32 i = 0; i < (32*32*3); i+=3)
-	{
-		S32 x = (i % (32*3)) / (3*16);
-		S32 y = i / (32*3*16);
-		U8 color = ((x + y) % 2) * 255;
-		data[i] = color;
-		data[i+1] = color;
-		data[i+2] = color;
-	}
-
-	LLViewerTexture::sCheckerBoardImagep = LLViewerTextureManager::getLocalTexture(image_raw.get(), TRUE);
-
-	LLViewerTexture::initClass();
-	
-	// Create a texture manager bridge.
-	gTextureManagerBridgep = new LLViewerTextureManagerBridge;
-
-	if (LLMetricPerformanceTesterBasic::isMetricLogRequested(sTesterName) && !LLMetricPerformanceTesterBasic::getTester(sTesterName))
-	{
-		sTesterp = new LLTexturePipelineTester();
-		if (!sTesterp->isValid())
-		{
-			delete sTesterp;
-			sTesterp = NULL;
-		}
-	}
+    LLViewerFetchedTexture::sDefaultImagep->dontDiscard();
+    LLViewerFetchedTexture::sDefaultImagep->setCategory(LLGLTexture::OTHER);
+
+    image_raw = new LLImageRaw(32,32,3);
+    data = image_raw->getData();
+
+    for (S32 i = 0; i < (32*32*3); i+=3)
+    {
+        S32 x = (i % (32*3)) / (3*16);
+        S32 y = i / (32*3*16);
+        U8 color = ((x + y) % 2) * 255;
+        data[i] = color;
+        data[i+1] = color;
+        data[i+2] = color;
+    }
+
+    LLViewerTexture::sCheckerBoardImagep = LLViewerTextureManager::getLocalTexture(image_raw.get(), TRUE);
+
+    LLViewerTexture::initClass();
+
+    // Create a texture manager bridge.
+    gTextureManagerBridgep = new LLViewerTextureManagerBridge;
+
+    if (LLMetricPerformanceTesterBasic::isMetricLogRequested(sTesterName) && !LLMetricPerformanceTesterBasic::getTester(sTesterName))
+    {
+        sTesterp = new LLTexturePipelineTester();
+        if (!sTesterp->isValid())
+        {
+            delete sTesterp;
+            sTesterp = NULL;
+        }
+    }
 }
 
 void LLViewerTextureManager::cleanup()
 {
-	stop_glerror();
+    stop_glerror();
 
-	delete gTextureManagerBridgep;
-	LLImageGL::sDefaultGLTexture = NULL;
-	LLViewerTexture::sNullImagep = NULL;
-	LLViewerTexture::sBlackImagep = NULL;
-	LLViewerTexture::sCheckerBoardImagep = NULL;
-	LLViewerFetchedTexture::sDefaultImagep = NULL;	
-	LLViewerFetchedTexture::sSmokeImagep = NULL;
-	LLViewerFetchedTexture::sMissingAssetImagep = NULL;
-	LLTexUnit::sWhiteTexture = 0;
-	LLViewerFetchedTexture::sWhiteImagep = NULL;
-	
-	LLViewerFetchedTexture::sFlatNormalImagep = NULL;
-	LLViewerFetchedTexture::sDefaultIrradiancePBRp = NULL;
-	LLViewerFetchedTexture::sPixieSmallImagep = NULL;
-	LLViewerFetchedTexture::sDefaultDiffuseImagep = NULL;
+    delete gTextureManagerBridgep;
+    LLImageGL::sDefaultGLTexture = NULL;
+    LLViewerTexture::sNullImagep = NULL;
+    LLViewerTexture::sBlackImagep = NULL;
+    LLViewerTexture::sCheckerBoardImagep = NULL;
+    LLViewerFetchedTexture::sDefaultImagep = NULL;
+    LLViewerFetchedTexture::sSmokeImagep = NULL;
+    LLViewerFetchedTexture::sMissingAssetImagep = NULL;
+    LLTexUnit::sWhiteTexture = 0;
+    LLViewerFetchedTexture::sWhiteImagep = NULL;
 
-	LLViewerMediaTexture::cleanUpClass();	
+    LLViewerFetchedTexture::sFlatNormalImagep = NULL;
+    LLViewerFetchedTexture::sDefaultIrradiancePBRp = NULL;
+    LLViewerFetchedTexture::sPixieSmallImagep = NULL;
+    LLViewerFetchedTexture::sDefaultDiffuseImagep = NULL;
+
+    LLViewerMediaTexture::cleanUpClass();
 }
 
 //----------------------------------------------------------------------------------------------
@@ -474,7 +474,7 @@ void LLViewerTextureManager::cleanup()
 // static
 void LLViewerTexture::initClass()
 {
-	LLImageGL::sDefaultGLTexture = LLViewerFetchedTexture::sDefaultImagep->getGLTexture();
+    LLImageGL::sDefaultGLTexture = LLViewerFetchedTexture::sDefaultImagep->getGLTexture();
 }
 
 // tuning params
@@ -483,7 +483,7 @@ const F32 GPU_MEMORY_CHECK_WAIT_TIME = 1.0f;
 F32 texmem_lower_bound_scale = 0.85f;
 F32 texmem_middle_bound_scale = 0.925f;
 
-//static 
+//static
 bool LLViewerTexture::isMemoryForTextureLow()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
@@ -509,7 +509,7 @@ void LLViewerTexture::getGPUMemoryForTextures(S32Megabytes &gpu, S32Megabytes &p
 
     static S32Megabytes gpu_res = S32Megabytes(S32_MAX);
     static S32Megabytes physical_res = S32Megabytes(S32_MAX);
-    
+
     if (timer.getElapsedTimeF32() < GPU_MEMORY_CHECK_WAIT_TIME) //call this once per second.
     {
         gpu = gpu_res;
@@ -520,7 +520,7 @@ void LLViewerTexture::getGPUMemoryForTextures(S32Megabytes &gpu, S32Megabytes &p
 
     {
         gpu_res = (S32Megabytes)gViewerWindow->getWindow()->getAvailableVRAMMegabytes();
-        
+
         //check main memory, only works for windows and macos.
         LLMemory::updateMemoryInfo();
         physical_res = LLMemory::getAvailableMemKB();
@@ -534,25 +534,25 @@ void LLViewerTexture::getGPUMemoryForTextures(S32Megabytes &gpu, S32Megabytes &p
 void LLViewerTexture::updateClass()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	sCurrentTime = gFrameTimeSeconds;
+    sCurrentTime = gFrameTimeSeconds;
 
-	LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
-	if (tester)
-	{
-		tester->update();
-	}
+    LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
+    if (tester)
+    {
+        tester->update();
+    }
 
-	LLViewerMediaTexture::updateClass();
+    LLViewerMediaTexture::updateClass();
 
     static LLCachedControl<U32> max_vram_budget(gSavedSettings, "RenderMaxVRAMBudget", 0);
 
-	F64 texture_bytes_alloc = LLImageGL::getTextureBytesAllocated() / 1024.0 / 512.0;
-	F64 vertex_bytes_alloc = LLVertexBuffer::getBytesAllocated() / 1024.0 / 512.0;
+    F64 texture_bytes_alloc = LLImageGL::getTextureBytesAllocated() / 1024.0 / 512.0;
+    F64 vertex_bytes_alloc = LLVertexBuffer::getBytesAllocated() / 1024.0 / 512.0;
 
-    // get an estimate of how much video memory we're using 
+    // get an estimate of how much video memory we're using
     // NOTE: our metrics miss about half the vram we use, so this biases high but turns out to typically be within 5% of the real number
-	F32 used = (F32)ll_round(texture_bytes_alloc + vertex_bytes_alloc);
-    
+    F32 used = (F32)ll_round(texture_bytes_alloc + vertex_bytes_alloc);
+
     F32 budget = max_vram_budget == 0 ? gGLManager.mVRAM : llmin(max_vram_budget, gGLManager.mVRAM);
 
     // try to leave half a GB for everyone else, but keep at least 768MB for ourselves
@@ -574,75 +574,75 @@ void LLViewerTexture::updateClass()
 const U32 LLViewerTexture::sCurrentFileVersion = 1;
 
 LLViewerTexture::LLViewerTexture(BOOL usemipmaps) :
-	LLGLTexture(usemipmaps)
+    LLGLTexture(usemipmaps)
 {
-	init(true);
+    init(true);
 
-	mID.generate();
-	sImageCount++;
+    mID.generate();
+    sImageCount++;
 }
 
 LLViewerTexture::LLViewerTexture(const LLUUID& id, BOOL usemipmaps) :
-	LLGLTexture(usemipmaps),
-	mID(id)
+    LLGLTexture(usemipmaps),
+    mID(id)
 {
-	init(true);
-	
-	sImageCount++;
+    init(true);
+
+    sImageCount++;
 }
 
 LLViewerTexture::LLViewerTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps)  :
-	LLGLTexture(width, height, components, usemipmaps)
+    LLGLTexture(width, height, components, usemipmaps)
 {
-	init(true);
+    init(true);
 
-	mID.generate();
-	sImageCount++;
+    mID.generate();
+    sImageCount++;
 }
 
 LLViewerTexture::LLViewerTexture(const LLImageRaw* raw, BOOL usemipmaps) :
-	LLGLTexture(raw, usemipmaps)
+    LLGLTexture(raw, usemipmaps)
 {
-	init(true);
-	
-	mID.generate();
-	sImageCount++;
+    init(true);
+
+    mID.generate();
+    sImageCount++;
 }
 
 LLViewerTexture::~LLViewerTexture()
 {
-	// LL_DEBUGS("Avatar") << mID << LL_ENDL;
-	cleanup();
-	sImageCount--;
+    // LL_DEBUGS("Avatar") << mID << LL_ENDL;
+    cleanup();
+    sImageCount--;
 }
 
 // virtual
 void LLViewerTexture::init(bool firstinit)
 {
-	mMaxVirtualSize = 0.f;
-	mMaxVirtualSizeResetInterval = 1;
-	mMaxVirtualSizeResetCounter = mMaxVirtualSizeResetInterval;
-	mParcelMedia = NULL;
-	
-	memset(&mNumVolumes, 0, sizeof(U32)* LLRender::NUM_VOLUME_TEXTURE_CHANNELS);
-	mFaceList[LLRender::DIFFUSE_MAP].clear();
-	mFaceList[LLRender::NORMAL_MAP].clear();
-	mFaceList[LLRender::SPECULAR_MAP].clear();
-	mNumFaces[LLRender::DIFFUSE_MAP] = 
-	mNumFaces[LLRender::NORMAL_MAP] = 
-	mNumFaces[LLRender::SPECULAR_MAP] = 0;
-	
-	mVolumeList[LLRender::LIGHT_TEX].clear();
-	mVolumeList[LLRender::SCULPT_TEX].clear();
-
-	mMainQueue	= LL::WorkQueue::getInstance("mainloop");
-	mImageQueue = LL::WorkQueue::getInstance("LLImageGL");
-}
-
-//virtual 
+    mMaxVirtualSize = 0.f;
+    mMaxVirtualSizeResetInterval = 1;
+    mMaxVirtualSizeResetCounter = mMaxVirtualSizeResetInterval;
+    mParcelMedia = NULL;
+
+    memset(&mNumVolumes, 0, sizeof(U32)* LLRender::NUM_VOLUME_TEXTURE_CHANNELS);
+    mFaceList[LLRender::DIFFUSE_MAP].clear();
+    mFaceList[LLRender::NORMAL_MAP].clear();
+    mFaceList[LLRender::SPECULAR_MAP].clear();
+    mNumFaces[LLRender::DIFFUSE_MAP] =
+    mNumFaces[LLRender::NORMAL_MAP] =
+    mNumFaces[LLRender::SPECULAR_MAP] = 0;
+
+    mVolumeList[LLRender::LIGHT_TEX].clear();
+    mVolumeList[LLRender::SCULPT_TEX].clear();
+
+    mMainQueue  = LL::WorkQueue::getInstance("mainloop");
+    mImageQueue = LL::WorkQueue::getInstance("LLImageGL");
+}
+
+//virtual
 S8 LLViewerTexture::getType() const
 {
-	return LLViewerTexture::LOCAL_TEXTURE;
+    return LLViewerTexture::LOCAL_TEXTURE;
 }
 
 void LLViewerTexture::cleanup()
@@ -652,37 +652,37 @@ void LLViewerTexture::cleanup()
         LLAppViewer::getTextureFetch()->updateRequestPriority(mID, 0.f);
     }
 
-	mFaceList[LLRender::DIFFUSE_MAP].clear();
-	mFaceList[LLRender::NORMAL_MAP].clear();
-	mFaceList[LLRender::SPECULAR_MAP].clear();
-	mVolumeList[LLRender::LIGHT_TEX].clear();
-	mVolumeList[LLRender::SCULPT_TEX].clear();
+    mFaceList[LLRender::DIFFUSE_MAP].clear();
+    mFaceList[LLRender::NORMAL_MAP].clear();
+    mFaceList[LLRender::SPECULAR_MAP].clear();
+    mVolumeList[LLRender::LIGHT_TEX].clear();
+    mVolumeList[LLRender::SCULPT_TEX].clear();
 }
 
 // virtual
 void LLViewerTexture::dump()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	LLGLTexture::dump();
+    LLGLTexture::dump();
 
-	LL_INFOS() << "LLViewerTexture"
-			<< " mID " << mID
-			<< LL_ENDL;
+    LL_INFOS() << "LLViewerTexture"
+            << " mID " << mID
+            << LL_ENDL;
 }
 
 void LLViewerTexture::setBoostLevel(S32 level)
 {
-	if(mBoostLevel != level)
-	{
-		mBoostLevel = level;
-		if(mBoostLevel != LLViewerTexture::BOOST_NONE && 
-			mBoostLevel != LLViewerTexture::BOOST_SELECTED && 
-			mBoostLevel != LLViewerTexture::BOOST_ICON &&
+    if(mBoostLevel != level)
+    {
+        mBoostLevel = level;
+        if(mBoostLevel != LLViewerTexture::BOOST_NONE &&
+            mBoostLevel != LLViewerTexture::BOOST_SELECTED &&
+            mBoostLevel != LLViewerTexture::BOOST_ICON &&
             mBoostLevel != LLViewerTexture::BOOST_THUMBNAIL)
-		{
-			setNoDelete();		
-		}
-	}
+        {
+            setNoDelete();
+        }
+    }
 
     // strongly encourage anything boosted to load at full res
     if (mBoostLevel >= LLViewerTexture::BOOST_HIGH)
@@ -693,159 +693,159 @@ void LLViewerTexture::setBoostLevel(S32 level)
 
 bool LLViewerTexture::isActiveFetching()
 {
-	return false;
+    return false;
 }
 
 bool LLViewerTexture::bindDebugImage(const S32 stage)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if (stage < 0) return false;
+    if (stage < 0) return false;
 
-	bool res = true;
-	if (LLViewerTexture::sCheckerBoardImagep.notNull() && (this != LLViewerTexture::sCheckerBoardImagep.get()))
-	{
-		res = gGL.getTexUnit(stage)->bind(LLViewerTexture::sCheckerBoardImagep);
-	}
+    bool res = true;
+    if (LLViewerTexture::sCheckerBoardImagep.notNull() && (this != LLViewerTexture::sCheckerBoardImagep.get()))
+    {
+        res = gGL.getTexUnit(stage)->bind(LLViewerTexture::sCheckerBoardImagep);
+    }
 
-	if(!res)
-	{
-		return bindDefaultImage(stage);
-	}
+    if(!res)
+    {
+        return bindDefaultImage(stage);
+    }
 
-	return res;
+    return res;
 }
 
-bool LLViewerTexture::bindDefaultImage(S32 stage) 
+bool LLViewerTexture::bindDefaultImage(S32 stage)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if (stage < 0) return false;
+    if (stage < 0) return false;
 
-	bool res = true;
-	if (LLViewerFetchedTexture::sDefaultImagep.notNull() && (this != LLViewerFetchedTexture::sDefaultImagep.get()))
-	{
-		// use default if we've got it
-		res = gGL.getTexUnit(stage)->bind(LLViewerFetchedTexture::sDefaultImagep);
-	}
-	if (!res && LLViewerTexture::sNullImagep.notNull() && (this != LLViewerTexture::sNullImagep.get()))
-	{
-		res = gGL.getTexUnit(stage)->bind(LLViewerTexture::sNullImagep);
-	}
-	if (!res)
-	{
-		LL_WARNS() << "LLViewerTexture::bindDefaultImage failed." << LL_ENDL;
-	}
-	stop_glerror();
+    bool res = true;
+    if (LLViewerFetchedTexture::sDefaultImagep.notNull() && (this != LLViewerFetchedTexture::sDefaultImagep.get()))
+    {
+        // use default if we've got it
+        res = gGL.getTexUnit(stage)->bind(LLViewerFetchedTexture::sDefaultImagep);
+    }
+    if (!res && LLViewerTexture::sNullImagep.notNull() && (this != LLViewerTexture::sNullImagep.get()))
+    {
+        res = gGL.getTexUnit(stage)->bind(LLViewerTexture::sNullImagep);
+    }
+    if (!res)
+    {
+        LL_WARNS() << "LLViewerTexture::bindDefaultImage failed." << LL_ENDL;
+    }
+    stop_glerror();
 
-	//check if there is cached raw image and switch to it if possible
-	switchToCachedImage();
+    //check if there is cached raw image and switch to it if possible
+    switchToCachedImage();
 
-	LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
-	if (tester)
-	{
-		tester->updateGrayTextureBinding();
-	}
-	return res;
+    LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
+    if (tester)
+    {
+        tester->updateGrayTextureBinding();
+    }
+    return res;
 }
 
-//virtual 
-BOOL LLViewerTexture::isMissingAsset()const		
-{ 
-	return FALSE; 
+//virtual
+BOOL LLViewerTexture::isMissingAsset()const
+{
+    return FALSE;
 }
 
-//virtual 
-void LLViewerTexture::forceImmediateUpdate() 
+//virtual
+void LLViewerTexture::forceImmediateUpdate()
 {
 }
 
-void LLViewerTexture::addTextureStats(F32 virtual_size, BOOL needs_gltexture) const 
+void LLViewerTexture::addTextureStats(F32 virtual_size, BOOL needs_gltexture) const
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if(needs_gltexture)
-	{
-		mNeedsGLTexture = TRUE;
-	}
+    if(needs_gltexture)
+    {
+        mNeedsGLTexture = TRUE;
+    }
 
     virtual_size = llmin(virtual_size, LLViewerFetchedTexture::sMaxVirtualSize);
 
-	if (virtual_size > mMaxVirtualSize)
-	{
-		mMaxVirtualSize = virtual_size;
-	}
+    if (virtual_size > mMaxVirtualSize)
+    {
+        mMaxVirtualSize = virtual_size;
+    }
 }
 
 void LLViewerTexture::resetTextureStats()
 {
-	mMaxVirtualSize = 0.0f;
-	mMaxVirtualSizeResetCounter = 0;
+    mMaxVirtualSize = 0.0f;
+    mMaxVirtualSizeResetCounter = 0;
 }
 
-//virtual 
+//virtual
 F32 LLViewerTexture::getMaxVirtualSize()
 {
-	return mMaxVirtualSize;
+    return mMaxVirtualSize;
 }
 
-//virtual 
+//virtual
 void LLViewerTexture::setKnownDrawSize(S32 width, S32 height)
 {
-	//nothing here.
+    //nothing here.
 }
 
 //virtual
-void LLViewerTexture::addFace(U32 ch, LLFace* facep) 
+void LLViewerTexture::addFace(U32 ch, LLFace* facep)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
+    llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
 
-	if(mNumFaces[ch] >= mFaceList[ch].size())
-	{
-		mFaceList[ch].resize(2 * mNumFaces[ch] + 1);		
-	}
-	mFaceList[ch][mNumFaces[ch]] = facep;
-	facep->setIndexInTex(ch, mNumFaces[ch]);
-	mNumFaces[ch]++;
-	mLastFaceListUpdateTimer.reset();
+    if(mNumFaces[ch] >= mFaceList[ch].size())
+    {
+        mFaceList[ch].resize(2 * mNumFaces[ch] + 1);
+    }
+    mFaceList[ch][mNumFaces[ch]] = facep;
+    facep->setIndexInTex(ch, mNumFaces[ch]);
+    mNumFaces[ch]++;
+    mLastFaceListUpdateTimer.reset();
 }
 
 //virtual
-void LLViewerTexture::removeFace(U32 ch, LLFace* facep) 
+void LLViewerTexture::removeFace(U32 ch, LLFace* facep)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
-
-	if(mNumFaces[ch] > 1)
-	{
-		S32 index = facep->getIndexInTex(ch); 
-		llassert(index < mFaceList[ch].size());
-		llassert(index < mNumFaces[ch]);
-		mFaceList[ch][index] = mFaceList[ch][--mNumFaces[ch]];
-		mFaceList[ch][index]->setIndexInTex(ch, index);
-	}
-	else 
-	{
-		mFaceList[ch].clear();
-		mNumFaces[ch] = 0;
-	}
-	mLastFaceListUpdateTimer.reset();
+    llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
+
+    if(mNumFaces[ch] > 1)
+    {
+        S32 index = facep->getIndexInTex(ch);
+        llassert(index < mFaceList[ch].size());
+        llassert(index < mNumFaces[ch]);
+        mFaceList[ch][index] = mFaceList[ch][--mNumFaces[ch]];
+        mFaceList[ch][index]->setIndexInTex(ch, index);
+    }
+    else
+    {
+        mFaceList[ch].clear();
+        mNumFaces[ch] = 0;
+    }
+    mLastFaceListUpdateTimer.reset();
 }
 
 S32 LLViewerTexture::getTotalNumFaces() const
 {
-	S32 ret = 0;
+    S32 ret = 0;
 
-	for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i)
-	{
-		ret += mNumFaces[i];
-	}
+    for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i)
+    {
+        ret += mNumFaces[i];
+    }
 
-	return ret;
+    return ret;
 }
 
 S32 LLViewerTexture::getNumFaces(U32 ch) const
 {
-	llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
-	return mNumFaces[ch];
+    llassert(ch < LLRender::NUM_TEXTURE_CHANNELS);
+    return mNumFaces[ch];
 }
 
 
@@ -853,117 +853,117 @@ S32 LLViewerTexture::getNumFaces(U32 ch) const
 void LLViewerTexture::addVolume(U32 ch, LLVOVolume* volumep)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if (mNumVolumes[ch] >= mVolumeList[ch].size())
-	{
-		mVolumeList[ch].resize(2 * mNumVolumes[ch] + 1);
-	}
-	mVolumeList[ch][mNumVolumes[ch]] = volumep;
-	volumep->setIndexInTex(ch, mNumVolumes[ch]);
-	mNumVolumes[ch]++;
-	mLastVolumeListUpdateTimer.reset();
+    if (mNumVolumes[ch] >= mVolumeList[ch].size())
+    {
+        mVolumeList[ch].resize(2 * mNumVolumes[ch] + 1);
+    }
+    mVolumeList[ch][mNumVolumes[ch]] = volumep;
+    volumep->setIndexInTex(ch, mNumVolumes[ch]);
+    mNumVolumes[ch]++;
+    mLastVolumeListUpdateTimer.reset();
 }
 
 //virtual
 void LLViewerTexture::removeVolume(U32 ch, LLVOVolume* volumep)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if (mNumVolumes[ch] > 1)
-	{
-		S32 index = volumep->getIndexInTex(ch); 
-		llassert(index < mVolumeList[ch].size());
-		llassert(index < mNumVolumes[ch]);
-		mVolumeList[ch][index] = mVolumeList[ch][--mNumVolumes[ch]];
-		mVolumeList[ch][index]->setIndexInTex(ch, index);
-	}
-	else 
-	{
-		mVolumeList[ch].clear();
-		mNumVolumes[ch] = 0;
-	}
-	mLastVolumeListUpdateTimer.reset();
+    if (mNumVolumes[ch] > 1)
+    {
+        S32 index = volumep->getIndexInTex(ch);
+        llassert(index < mVolumeList[ch].size());
+        llassert(index < mNumVolumes[ch]);
+        mVolumeList[ch][index] = mVolumeList[ch][--mNumVolumes[ch]];
+        mVolumeList[ch][index]->setIndexInTex(ch, index);
+    }
+    else
+    {
+        mVolumeList[ch].clear();
+        mNumVolumes[ch] = 0;
+    }
+    mLastVolumeListUpdateTimer.reset();
 }
 
 S32 LLViewerTexture::getNumVolumes(U32 ch) const
 {
-	return mNumVolumes[ch];
+    return mNumVolumes[ch];
 }
 
 void LLViewerTexture::reorganizeFaceList()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	static const F32 MAX_WAIT_TIME = 20.f; // seconds
-	static const U32 MAX_EXTRA_BUFFER_SIZE = 4;
+    static const F32 MAX_WAIT_TIME = 20.f; // seconds
+    static const U32 MAX_EXTRA_BUFFER_SIZE = 4;
+
+    if(mLastFaceListUpdateTimer.getElapsedTimeF32() < MAX_WAIT_TIME)
+    {
+        return;
+    }
 
-	if(mLastFaceListUpdateTimer.getElapsedTimeF32() < MAX_WAIT_TIME)
-	{
-		return;
-	}
+    for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i)
+    {
+        if(mNumFaces[i] + MAX_EXTRA_BUFFER_SIZE > mFaceList[i].size())
+    {
+        return;
+    }
 
-	for (U32 i = 0; i < LLRender::NUM_TEXTURE_CHANNELS; ++i)
-	{
-		if(mNumFaces[i] + MAX_EXTRA_BUFFER_SIZE > mFaceList[i].size())
-	{
-		return;
-	}
+        mFaceList[i].erase(mFaceList[i].begin() + mNumFaces[i], mFaceList[i].end());
+    }
 
-		mFaceList[i].erase(mFaceList[i].begin() + mNumFaces[i], mFaceList[i].end());
-	}
-	
-	mLastFaceListUpdateTimer.reset();
+    mLastFaceListUpdateTimer.reset();
 }
 
 void LLViewerTexture::reorganizeVolumeList()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	static const F32 MAX_WAIT_TIME = 20.f; // seconds
-	static const U32 MAX_EXTRA_BUFFER_SIZE = 4;
+    static const F32 MAX_WAIT_TIME = 20.f; // seconds
+    static const U32 MAX_EXTRA_BUFFER_SIZE = 4;
 
 
-	for (U32 i = 0; i < LLRender::NUM_VOLUME_TEXTURE_CHANNELS; ++i)
-	{
-		if (mNumVolumes[i] + MAX_EXTRA_BUFFER_SIZE > mVolumeList[i].size())
-		{
-			return;
-		}
-	}
+    for (U32 i = 0; i < LLRender::NUM_VOLUME_TEXTURE_CHANNELS; ++i)
+    {
+        if (mNumVolumes[i] + MAX_EXTRA_BUFFER_SIZE > mVolumeList[i].size())
+        {
+            return;
+        }
+    }
 
-	if(mLastVolumeListUpdateTimer.getElapsedTimeF32() < MAX_WAIT_TIME)
-	{
-		return;
-	}
+    if(mLastVolumeListUpdateTimer.getElapsedTimeF32() < MAX_WAIT_TIME)
+    {
+        return;
+    }
 
-	mLastVolumeListUpdateTimer.reset();
-	for (U32 i = 0; i < LLRender::NUM_VOLUME_TEXTURE_CHANNELS; ++i)
-	{
-		mVolumeList[i].erase(mVolumeList[i].begin() + mNumVolumes[i], mVolumeList[i].end());
-	}
+    mLastVolumeListUpdateTimer.reset();
+    for (U32 i = 0; i < LLRender::NUM_VOLUME_TEXTURE_CHANNELS; ++i)
+    {
+        mVolumeList[i].erase(mVolumeList[i].begin() + mNumVolumes[i], mVolumeList[i].end());
+    }
 }
 
 //virtual
 void LLViewerTexture::switchToCachedImage()
 {
-	//nothing here.
+    //nothing here.
 }
 
 //virtual
 void LLViewerTexture::setCachedRawImage(S32 discard_level, LLImageRaw* imageraw)
 {
-	//nothing here.
+    //nothing here.
 }
 
 BOOL LLViewerTexture::isLargeImage()
 {
-	return  (S32)mTexelsPerImage > LLViewerTexture::sMinLargeImageSize;
+    return  (S32)mTexelsPerImage > LLViewerTexture::sMinLargeImageSize;
 }
 
-//virtual 
+//virtual
 void LLViewerTexture::updateBindStatsForTester()
 {
-	LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
-	if (tester)
-	{
-		tester->updateTextureBindingStats(this);
-	}
+    LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
+    if (tester)
+    {
+        tester->updateTextureBindingStats(this);
+    }
 }
 
 //----------------------------------------------------------------------------------------------
@@ -972,30 +972,30 @@ void LLViewerTexture::updateBindStatsForTester()
 
 const std::string& fttype_to_string(const FTType& fttype)
 {
-	static const std::string ftt_unknown("FTT_UNKNOWN");
-	static const std::string ftt_default("FTT_DEFAULT");
-	static const std::string ftt_server_bake("FTT_SERVER_BAKE");
-	static const std::string ftt_host_bake("FTT_HOST_BAKE");
-	static const std::string ftt_map_tile("FTT_MAP_TILE");
-	static const std::string ftt_local_file("FTT_LOCAL_FILE");
-	static const std::string ftt_error("FTT_ERROR");
-	switch(fttype)
-	{
-		case FTT_UNKNOWN: return ftt_unknown; break;
-		case FTT_DEFAULT: return ftt_default; break;
-		case FTT_SERVER_BAKE: return ftt_server_bake; break;
-		case FTT_HOST_BAKE: return ftt_host_bake; break;
-		case FTT_MAP_TILE: return ftt_map_tile; break;
-		case FTT_LOCAL_FILE: return ftt_local_file; break;
-	}
-	return ftt_error;
+    static const std::string ftt_unknown("FTT_UNKNOWN");
+    static const std::string ftt_default("FTT_DEFAULT");
+    static const std::string ftt_server_bake("FTT_SERVER_BAKE");
+    static const std::string ftt_host_bake("FTT_HOST_BAKE");
+    static const std::string ftt_map_tile("FTT_MAP_TILE");
+    static const std::string ftt_local_file("FTT_LOCAL_FILE");
+    static const std::string ftt_error("FTT_ERROR");
+    switch(fttype)
+    {
+        case FTT_UNKNOWN: return ftt_unknown; break;
+        case FTT_DEFAULT: return ftt_default; break;
+        case FTT_SERVER_BAKE: return ftt_server_bake; break;
+        case FTT_HOST_BAKE: return ftt_host_bake; break;
+        case FTT_MAP_TILE: return ftt_map_tile; break;
+        case FTT_LOCAL_FILE: return ftt_local_file; break;
+    }
+    return ftt_error;
 }
 
 //----------------------------------------------------------------------------------------------
 //start of LLViewerFetchedTexture
 //----------------------------------------------------------------------------------------------
 
-//static 
+//static
 LLViewerFetchedTexture* LLViewerFetchedTexture::getSmokeImage()
 {
     if (sSmokeImagep.isNull())
@@ -1009,189 +1009,189 @@ LLViewerFetchedTexture* LLViewerFetchedTexture::getSmokeImage()
 }
 
 LLViewerFetchedTexture::LLViewerFetchedTexture(const LLUUID& id, FTType f_type, const LLHost& host, BOOL usemipmaps)
-	: LLViewerTexture(id, usemipmaps),
-	mTargetHost(host)
-{
-	init(TRUE);
-	mFTType = f_type;
-	if (mFTType == FTT_HOST_BAKE)
-	{
-		LL_WARNS() << "Unsupported fetch type " << mFTType << LL_ENDL;
-	}
-	generateGLTexture();
-	mGLTexturep->setNeedsAlphaAndPickMask(TRUE);
-}
-	
+    : LLViewerTexture(id, usemipmaps),
+    mTargetHost(host)
+{
+    init(TRUE);
+    mFTType = f_type;
+    if (mFTType == FTT_HOST_BAKE)
+    {
+        LL_WARNS() << "Unsupported fetch type " << mFTType << LL_ENDL;
+    }
+    generateGLTexture();
+    mGLTexturep->setNeedsAlphaAndPickMask(TRUE);
+}
+
 LLViewerFetchedTexture::LLViewerFetchedTexture(const LLImageRaw* raw, FTType f_type, BOOL usemipmaps)
-	: LLViewerTexture(raw, usemipmaps)
+    : LLViewerTexture(raw, usemipmaps)
 {
-	init(TRUE);
-	mFTType = f_type;
-	mGLTexturep->setNeedsAlphaAndPickMask(TRUE);
+    init(TRUE);
+    mFTType = f_type;
+    mGLTexturep->setNeedsAlphaAndPickMask(TRUE);
 }
-	
+
 LLViewerFetchedTexture::LLViewerFetchedTexture(const std::string& url, FTType f_type, const LLUUID& id, BOOL usemipmaps)
-	: LLViewerTexture(id, usemipmaps),
-	mUrl(url)
+    : LLViewerTexture(id, usemipmaps),
+    mUrl(url)
 {
-	init(TRUE);
-	mFTType = f_type;
-	generateGLTexture();
-	mGLTexturep->setNeedsAlphaAndPickMask(TRUE);
+    init(TRUE);
+    mFTType = f_type;
+    generateGLTexture();
+    mGLTexturep->setNeedsAlphaAndPickMask(TRUE);
 }
 
 void LLViewerFetchedTexture::init(bool firstinit)
 {
-	mOrigWidth = 0;
-	mOrigHeight = 0;
-	mHasAux = FALSE;
-	mNeedsAux = FALSE;
-	mRequestedDiscardLevel = -1;
-	mRequestedDownloadPriority = 0.f;
-	mFullyLoaded = FALSE;
-	mCanUseHTTP = true;
-	mDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1;
-	mMinDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1;
-	
-	mDecodingAux = FALSE;
-
-	mKnownDrawWidth = 0;
-	mKnownDrawHeight = 0;
-	mKnownDrawSizeChanged = FALSE;
-
-	if (firstinit)
-	{
-		mInImageList = 0;
-	}
-
-	// Only set mIsMissingAsset true when we know for certain that the database
-	// does not contain this image.
-	mIsMissingAsset = FALSE;
-
-	mLoadedCallbackDesiredDiscardLevel = S8_MAX;
-	mPauseLoadedCallBacks = FALSE;
-
-	mNeedsCreateTexture = false;
-	
-	mIsRawImageValid = FALSE;
-	mRawDiscardLevel = INVALID_DISCARD_LEVEL;
-	mMinDiscardLevel = 0;
-
-	mHasFetcher = FALSE;
-	mIsFetching = FALSE;
-	mFetchState = 0;
-	mFetchPriority = 0;
-	mDownloadProgress = 0.f;
-	mFetchDeltaTime = 999999.f;
-	mRequestDeltaTime = 0.f;
-	mForSculpt = FALSE;
-	mIsFetched = FALSE;
-	mInFastCacheList = FALSE;
-
-	mCachedRawImage = NULL;
-	mCachedRawDiscardLevel = -1;
-	mCachedRawImageReady = FALSE;
-
-	mSavedRawImage = NULL;
-	mForceToSaveRawImage  = FALSE;
-	mSaveRawImage = FALSE;
-	mSavedRawDiscardLevel = -1;
-	mDesiredSavedRawDiscardLevel = -1;
-	mLastReferencedSavedRawImageTime = 0.0f;
-	mKeptSavedRawImageTime = 0.f;
-	mLastCallBackActiveTime = 0.f;
-	mForceCallbackFetch = FALSE;
-	mInDebug = FALSE;
-	mUnremovable = FALSE;
-
-	mFTType = FTT_UNKNOWN;
+    mOrigWidth = 0;
+    mOrigHeight = 0;
+    mHasAux = FALSE;
+    mNeedsAux = FALSE;
+    mRequestedDiscardLevel = -1;
+    mRequestedDownloadPriority = 0.f;
+    mFullyLoaded = FALSE;
+    mCanUseHTTP = true;
+    mDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1;
+    mMinDesiredDiscardLevel = MAX_DISCARD_LEVEL + 1;
+
+    mDecodingAux = FALSE;
+
+    mKnownDrawWidth = 0;
+    mKnownDrawHeight = 0;
+    mKnownDrawSizeChanged = FALSE;
+
+    if (firstinit)
+    {
+        mInImageList = 0;
+    }
+
+    // Only set mIsMissingAsset true when we know for certain that the database
+    // does not contain this image.
+    mIsMissingAsset = FALSE;
+
+    mLoadedCallbackDesiredDiscardLevel = S8_MAX;
+    mPauseLoadedCallBacks = FALSE;
+
+    mNeedsCreateTexture = false;
+
+    mIsRawImageValid = FALSE;
+    mRawDiscardLevel = INVALID_DISCARD_LEVEL;
+    mMinDiscardLevel = 0;
+
+    mHasFetcher = FALSE;
+    mIsFetching = FALSE;
+    mFetchState = 0;
+    mFetchPriority = 0;
+    mDownloadProgress = 0.f;
+    mFetchDeltaTime = 999999.f;
+    mRequestDeltaTime = 0.f;
+    mForSculpt = FALSE;
+    mIsFetched = FALSE;
+    mInFastCacheList = FALSE;
+
+    mCachedRawImage = NULL;
+    mCachedRawDiscardLevel = -1;
+    mCachedRawImageReady = FALSE;
+
+    mSavedRawImage = NULL;
+    mForceToSaveRawImage  = FALSE;
+    mSaveRawImage = FALSE;
+    mSavedRawDiscardLevel = -1;
+    mDesiredSavedRawDiscardLevel = -1;
+    mLastReferencedSavedRawImageTime = 0.0f;
+    mKeptSavedRawImageTime = 0.f;
+    mLastCallBackActiveTime = 0.f;
+    mForceCallbackFetch = FALSE;
+    mInDebug = FALSE;
+    mUnremovable = FALSE;
+
+    mFTType = FTT_UNKNOWN;
 }
 
 LLViewerFetchedTexture::~LLViewerFetchedTexture()
 {
     assert_main_thread();
-	//*NOTE getTextureFetch can return NULL when Viewer is shutting down.
-	// This is due to LLWearableList is singleton and is destroyed after 
-	// LLAppViewer::cleanup() was called. (see ticket EXT-177)
-	if (mHasFetcher && LLAppViewer::getTextureFetch())
-	{
-		LLAppViewer::getTextureFetch()->deleteRequest(getID(), true);
-	}
-	cleanup();	
+    //*NOTE getTextureFetch can return NULL when Viewer is shutting down.
+    // This is due to LLWearableList is singleton and is destroyed after
+    // LLAppViewer::cleanup() was called. (see ticket EXT-177)
+    if (mHasFetcher && LLAppViewer::getTextureFetch())
+    {
+        LLAppViewer::getTextureFetch()->deleteRequest(getID(), true);
+    }
+    cleanup();
 }
 
-//virtual 
+//virtual
 S8 LLViewerFetchedTexture::getType() const
 {
-	return LLViewerTexture::FETCHED_TEXTURE;
+    return LLViewerTexture::FETCHED_TEXTURE;
 }
 
 FTType LLViewerFetchedTexture::getFTType() const
 {
-	return mFTType;
+    return mFTType;
 }
 
 void LLViewerFetchedTexture::cleanup()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
-		iter != mLoadedCallbackList.end(); )
-	{
-		LLLoadedCallbackEntry *entryp = *iter++;
-		// We never finished loading the image.  Indicate failure.
-		// Note: this allows mLoadedCallbackUserData to be cleaned up.
-		entryp->mCallback( FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData );
-		entryp->removeTexture(this);
-		delete entryp;
-	}
-	mLoadedCallbackList.clear();
-	mNeedsAux = FALSE;
-	
-	// Clean up image data
-	destroyRawImage();
-	mCachedRawImage = NULL;
-	mCachedRawDiscardLevel = -1;
-	mCachedRawImageReady = FALSE;
-	mSavedRawImage = NULL;
-	mSavedRawDiscardLevel = -1;
+    for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+        iter != mLoadedCallbackList.end(); )
+    {
+        LLLoadedCallbackEntry *entryp = *iter++;
+        // We never finished loading the image.  Indicate failure.
+        // Note: this allows mLoadedCallbackUserData to be cleaned up.
+        entryp->mCallback( FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData );
+        entryp->removeTexture(this);
+        delete entryp;
+    }
+    mLoadedCallbackList.clear();
+    mNeedsAux = FALSE;
+
+    // Clean up image data
+    destroyRawImage();
+    mCachedRawImage = NULL;
+    mCachedRawDiscardLevel = -1;
+    mCachedRawImageReady = FALSE;
+    mSavedRawImage = NULL;
+    mSavedRawDiscardLevel = -1;
 }
 
 //access the fast cache
 void LLViewerFetchedTexture::loadFromFastCache()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if(!mInFastCacheList)
-	{
-		return; //no need to access the fast cache.
-	}
-	mInFastCacheList = FALSE;
+    if(!mInFastCacheList)
+    {
+        return; //no need to access the fast cache.
+    }
+    mInFastCacheList = FALSE;
 
     add(LLTextureFetch::sCacheAttempt, 1.0);
 
     LLTimer fastCacheTimer;
-	mRawImage = LLAppViewer::getTextureCache()->readFromFastCache(getID(), mRawDiscardLevel);
-	if(mRawImage.notNull())
-	{
+    mRawImage = LLAppViewer::getTextureCache()->readFromFastCache(getID(), mRawDiscardLevel);
+    if(mRawImage.notNull())
+    {
         F32 cachReadTime = fastCacheTimer.getElapsedTimeF32();
 
         add(LLTextureFetch::sCacheHit, 1.0);
         record(LLTextureFetch::sCacheHitRate, LLUnits::Ratio::fromValue(1));
         sample(LLTextureFetch::sCacheReadLatency, cachReadTime);
 
-		mFullWidth = mRawImage->getWidth() << mRawDiscardLevel;
-		mFullHeight = mRawImage->getHeight() << mRawDiscardLevel;
-		setTexelsPerImage();
-
-		if(mFullWidth > MAX_IMAGE_SIZE || mFullHeight > MAX_IMAGE_SIZE)
-		{ 
-			//discard all oversized textures.
-			destroyRawImage();
-			LL_WARNS() << "oversized, setting as missing" << LL_ENDL;
-			setIsMissingAsset();
-			mRawDiscardLevel = INVALID_DISCARD_LEVEL;
-		}
-		else
-		{
+        mFullWidth = mRawImage->getWidth() << mRawDiscardLevel;
+        mFullHeight = mRawImage->getHeight() << mRawDiscardLevel;
+        setTexelsPerImage();
+
+        if(mFullWidth > MAX_IMAGE_SIZE || mFullHeight > MAX_IMAGE_SIZE)
+        {
+            //discard all oversized textures.
+            destroyRawImage();
+            LL_WARNS() << "oversized, setting as missing" << LL_ENDL;
+            setIsMissingAsset();
+            mRawDiscardLevel = INVALID_DISCARD_LEVEL;
+        }
+        else
+        {
             if (mBoostLevel == LLGLTexture::BOOST_ICON)
             {
                 // Shouldn't do anything usefull since texures in fast cache are 16x16,
@@ -1216,11 +1216,11 @@ void LLViewerFetchedTexture::loadFromFastCache()
                 }
             }
 
-			mRequestedDiscardLevel = mDesiredDiscardLevel + 1;
-			mIsRawImageValid = TRUE;			
-			addToCreateTexture();
-		}
-	}
+            mRequestedDiscardLevel = mDesiredDiscardLevel + 1;
+            mIsRawImageValid = TRUE;
+            addToCreateTexture();
+        }
+    }
     else
     {
         record(LLTextureFetch::sCacheHitRate, LLUnits::Ratio::fromValue(0));
@@ -1229,197 +1229,197 @@ void LLViewerFetchedTexture::loadFromFastCache()
 
 void LLViewerFetchedTexture::setForSculpt()
 {
-	static const S32 MAX_INTERVAL = 8; //frames
+    static const S32 MAX_INTERVAL = 8; //frames
 
-	mForSculpt = TRUE;
-	if(isForSculptOnly() && hasGLTexture() && !getBoundRecently())
-	{
-		destroyGLTexture(); //sculpt image does not need gl texture.
-		mTextureState = ACTIVE;
-	}
-	checkCachedRawSculptImage();
-	setMaxVirtualSizeResetInterval(MAX_INTERVAL);
+    mForSculpt = TRUE;
+    if(isForSculptOnly() && hasGLTexture() && !getBoundRecently())
+    {
+        destroyGLTexture(); //sculpt image does not need gl texture.
+        mTextureState = ACTIVE;
+    }
+    checkCachedRawSculptImage();
+    setMaxVirtualSizeResetInterval(MAX_INTERVAL);
 }
 
 BOOL LLViewerFetchedTexture::isForSculptOnly() const
 {
-	return mForSculpt && !mNeedsGLTexture;
+    return mForSculpt && !mNeedsGLTexture;
 }
 
-BOOL LLViewerFetchedTexture::isDeleted()  
-{ 
-	return mTextureState == DELETED; 
+BOOL LLViewerFetchedTexture::isDeleted()
+{
+    return mTextureState == DELETED;
 }
 
-BOOL LLViewerFetchedTexture::isInactive()  
-{ 
-	return mTextureState == INACTIVE; 
+BOOL LLViewerFetchedTexture::isInactive()
+{
+    return mTextureState == INACTIVE;
 }
 
-BOOL LLViewerFetchedTexture::isDeletionCandidate()  
-{ 
-	return mTextureState == DELETION_CANDIDATE; 
+BOOL LLViewerFetchedTexture::isDeletionCandidate()
+{
+    return mTextureState == DELETION_CANDIDATE;
 }
 
-void LLViewerFetchedTexture::setDeletionCandidate()  
-{ 
-	if(mGLTexturep.notNull() && mGLTexturep->getTexName() && (mTextureState == INACTIVE))
-	{
-		mTextureState = DELETION_CANDIDATE;		
-	}
+void LLViewerFetchedTexture::setDeletionCandidate()
+{
+    if(mGLTexturep.notNull() && mGLTexturep->getTexName() && (mTextureState == INACTIVE))
+    {
+        mTextureState = DELETION_CANDIDATE;
+    }
 }
 
 //set the texture inactive
 void LLViewerFetchedTexture::setInactive()
 {
-	if(mTextureState == ACTIVE && mGLTexturep.notNull() && mGLTexturep->getTexName() && !mGLTexturep->getBoundRecently())
-	{
-		mTextureState = INACTIVE; 
-	}
+    if(mTextureState == ACTIVE && mGLTexturep.notNull() && mGLTexturep->getTexName() && !mGLTexturep->getBoundRecently())
+    {
+        mTextureState = INACTIVE;
+    }
 }
 
 BOOL LLViewerFetchedTexture::isFullyLoaded() const
 {
-	// Unfortunately, the boolean "mFullyLoaded" is never updated correctly so we use that logic
-	// to check if the texture is there and completely downloaded
-	return (mFullWidth != 0) && (mFullHeight != 0) && !mIsFetching && !mHasFetcher;
+    // Unfortunately, the boolean "mFullyLoaded" is never updated correctly so we use that logic
+    // to check if the texture is there and completely downloaded
+    return (mFullWidth != 0) && (mFullHeight != 0) && !mIsFetching && !mHasFetcher;
 }
 
 
 // virtual
 void LLViewerFetchedTexture::dump()
 {
-	LLViewerTexture::dump();
-
-	LL_INFOS() << "Dump : " << mID 
-			<< ", mIsMissingAsset = " << (S32)mIsMissingAsset
-			<< ", mFullWidth = " << (S32)mFullWidth
-			<< ", mFullHeight = " << (S32)mFullHeight
-			<< ", mOrigWidth = " << (S32)mOrigWidth
-			<< ", mOrigHeight = " << (S32)mOrigHeight
-			<< LL_ENDL;
-	LL_INFOS() << "     : " 
-			<< " mFullyLoaded = " << (S32)mFullyLoaded
-			<< ", mFetchState = " << (S32)mFetchState
-			<< ", mFetchPriority = " << (S32)mFetchPriority
-			<< ", mDownloadProgress = " << (F32)mDownloadProgress
-			<< LL_ENDL;
-	LL_INFOS() << "     : " 
-			<< " mHasFetcher = " << (S32)mHasFetcher
-			<< ", mIsFetching = " << (S32)mIsFetching
-			<< ", mIsFetched = " << (S32)mIsFetched
-			<< ", mBoostLevel = " << (S32)mBoostLevel
-			<< LL_ENDL;
+    LLViewerTexture::dump();
+
+    LL_INFOS() << "Dump : " << mID
+            << ", mIsMissingAsset = " << (S32)mIsMissingAsset
+            << ", mFullWidth = " << (S32)mFullWidth
+            << ", mFullHeight = " << (S32)mFullHeight
+            << ", mOrigWidth = " << (S32)mOrigWidth
+            << ", mOrigHeight = " << (S32)mOrigHeight
+            << LL_ENDL;
+    LL_INFOS() << "     : "
+            << " mFullyLoaded = " << (S32)mFullyLoaded
+            << ", mFetchState = " << (S32)mFetchState
+            << ", mFetchPriority = " << (S32)mFetchPriority
+            << ", mDownloadProgress = " << (F32)mDownloadProgress
+            << LL_ENDL;
+    LL_INFOS() << "     : "
+            << " mHasFetcher = " << (S32)mHasFetcher
+            << ", mIsFetching = " << (S32)mIsFetching
+            << ", mIsFetched = " << (S32)mIsFetched
+            << ", mBoostLevel = " << (S32)mBoostLevel
+            << LL_ENDL;
 }
 
 ///////////////////////////////////////////////////////////////////////////////
 // ONLY called from LLViewerFetchedTextureList
-void LLViewerFetchedTexture::destroyTexture() 
+void LLViewerFetchedTexture::destroyTexture()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
 
-	if (mNeedsCreateTexture)//return if in the process of generating a new texture.
-	{
-		return;
-	}
+    if (mNeedsCreateTexture)//return if in the process of generating a new texture.
+    {
+        return;
+    }
 
-	//LL_DEBUGS("Avatar") << mID << LL_ENDL;
-	destroyGLTexture();
-	mFullyLoaded = FALSE;
+    //LL_DEBUGS("Avatar") << mID << LL_ENDL;
+    destroyGLTexture();
+    mFullyLoaded = FALSE;
 }
 
 void LLViewerFetchedTexture::addToCreateTexture()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	bool force_update = false;
-	if (getComponents() != mRawImage->getComponents())
-	{
-		// We've changed the number of components, so we need to move any
-		// objects using this pool to a different pool.
-		mComponents = mRawImage->getComponents();
-		mGLTexturep->setComponents(mComponents);
-		force_update = true;
-
-		for (U32 j = 0; j < LLRender::NUM_TEXTURE_CHANNELS; ++j)
-		{
-			llassert(mNumFaces[j] <= mFaceList[j].size());
-
-			for(U32 i = 0; i < mNumFaces[j]; i++)
-			{
-				mFaceList[j][i]->dirtyTexture();
-			}
-		}
-
-		//discard the cached raw image and the saved raw image
-		mCachedRawImageReady = FALSE;
-		mCachedRawDiscardLevel = -1;
-		mCachedRawImage = NULL;
-		mSavedRawDiscardLevel = -1;
-		mSavedRawImage = NULL;
-	}	
-
-	if(isForSculptOnly())
-	{
-		//just update some variables, not to create a real GL texture.
-		createGLTexture(mRawDiscardLevel, mRawImage, 0, FALSE);
-		mNeedsCreateTexture = false;
-		destroyRawImage();
-	}
-	else if(!force_update && getDiscardLevel() > -1 && getDiscardLevel() <= mRawDiscardLevel)
-	{
-		mNeedsCreateTexture = false;
-		destroyRawImage();
-	}
-	else
-	{	
+    bool force_update = false;
+    if (getComponents() != mRawImage->getComponents())
+    {
+        // We've changed the number of components, so we need to move any
+        // objects using this pool to a different pool.
+        mComponents = mRawImage->getComponents();
+        mGLTexturep->setComponents(mComponents);
+        force_update = true;
+
+        for (U32 j = 0; j < LLRender::NUM_TEXTURE_CHANNELS; ++j)
+        {
+            llassert(mNumFaces[j] <= mFaceList[j].size());
+
+            for(U32 i = 0; i < mNumFaces[j]; i++)
+            {
+                mFaceList[j][i]->dirtyTexture();
+            }
+        }
+
+        //discard the cached raw image and the saved raw image
+        mCachedRawImageReady = FALSE;
+        mCachedRawDiscardLevel = -1;
+        mCachedRawImage = NULL;
+        mSavedRawDiscardLevel = -1;
+        mSavedRawImage = NULL;
+    }
+
+    if(isForSculptOnly())
+    {
+        //just update some variables, not to create a real GL texture.
+        createGLTexture(mRawDiscardLevel, mRawImage, 0, FALSE);
+        mNeedsCreateTexture = false;
+        destroyRawImage();
+    }
+    else if(!force_update && getDiscardLevel() > -1 && getDiscardLevel() <= mRawDiscardLevel)
+    {
+        mNeedsCreateTexture = false;
+        destroyRawImage();
+    }
+    else
+    {
         LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
 #if 1
-		//
-		//if mRequestedDiscardLevel > mDesiredDiscardLevel, we assume the required image res keep going up,
-		//so do not scale down the over qualified image.
-		//Note: scaling down image is expensensive. Do it only when very necessary.
-		//
-		if(mRequestedDiscardLevel <= mDesiredDiscardLevel && !mForceToSaveRawImage)
-		{
-			S32 w = mFullWidth >> mRawDiscardLevel;
-			S32 h = mFullHeight >> mRawDiscardLevel;
-
-			//if big image, do not load extra data
-			//scale it down to size >= LLViewerTexture::sMinLargeImageSize
-			if(w * h > LLViewerTexture::sMinLargeImageSize)
-			{
-				S32 d_level = llmin(mRequestedDiscardLevel, (S32)mDesiredDiscardLevel) - mRawDiscardLevel;
-				
-				if(d_level > 0)
-				{
-					S32 i = 0;
-					while((d_level > 0) && ((w >> i) * (h >> i) > LLViewerTexture::sMinLargeImageSize))
-					{
-						i++;
-						d_level--;
-					}
-					if(i > 0)
-					{
-						mRawDiscardLevel += i;
-						if(mRawDiscardLevel >= getDiscardLevel() && getDiscardLevel() > 0)
-						{
-							mNeedsCreateTexture = false;
-							destroyRawImage();
-							return;
-						}
-
-						{
-							//make a duplicate in case somebody else is using this raw image
-							mRawImage = mRawImage->scaled(w >> i, h >> i);
-						}
-					}
-				}
-			}
-		}
+        //
+        //if mRequestedDiscardLevel > mDesiredDiscardLevel, we assume the required image res keep going up,
+        //so do not scale down the over qualified image.
+        //Note: scaling down image is expensensive. Do it only when very necessary.
+        //
+        if(mRequestedDiscardLevel <= mDesiredDiscardLevel && !mForceToSaveRawImage)
+        {
+            S32 w = mFullWidth >> mRawDiscardLevel;
+            S32 h = mFullHeight >> mRawDiscardLevel;
+
+            //if big image, do not load extra data
+            //scale it down to size >= LLViewerTexture::sMinLargeImageSize
+            if(w * h > LLViewerTexture::sMinLargeImageSize)
+            {
+                S32 d_level = llmin(mRequestedDiscardLevel, (S32)mDesiredDiscardLevel) - mRawDiscardLevel;
+
+                if(d_level > 0)
+                {
+                    S32 i = 0;
+                    while((d_level > 0) && ((w >> i) * (h >> i) > LLViewerTexture::sMinLargeImageSize))
+                    {
+                        i++;
+                        d_level--;
+                    }
+                    if(i > 0)
+                    {
+                        mRawDiscardLevel += i;
+                        if(mRawDiscardLevel >= getDiscardLevel() && getDiscardLevel() > 0)
+                        {
+                            mNeedsCreateTexture = false;
+                            destroyRawImage();
+                            return;
+                        }
+
+                        {
+                            //make a duplicate in case somebody else is using this raw image
+                            mRawImage = mRawImage->scaled(w >> i, h >> i);
+                        }
+                    }
+                }
+            }
+        }
 #endif
         scheduleCreateTexture();
-	}
-	return;
+    }
+    return;
 }
 
 // ONLY called from LLViewerTextureList
@@ -1447,10 +1447,10 @@ BOOL LLViewerFetchedTexture::preCreateTexture(S32 usename/*= 0*/)
         destroyRawImage();
         return FALSE;
     }
-    // 	LL_INFOS() << llformat("IMAGE Creating (%d) [%d x %d] Bytes: %d ",
-    // 						mRawDiscardLevel, 
-    // 						mRawImage->getWidth(), mRawImage->getHeight(),mRawImage->getDataSize())
-    // 			<< mID.getString() << LL_ENDL;
+    //  LL_INFOS() << llformat("IMAGE Creating (%d) [%d x %d] Bytes: %d ",
+    //                      mRawDiscardLevel,
+    //                      mRawImage->getWidth(), mRawImage->getHeight(),mRawImage->getDataSize())
+    //          << mID.getString() << LL_ENDL;
     BOOL res = TRUE;
 
     // store original size only for locally-sourced images
@@ -1479,39 +1479,39 @@ BOOL LLViewerFetchedTexture::preCreateTexture(S32 usename/*= 0*/)
         mOrigWidth = mFullWidth;
         mOrigHeight = mFullHeight;
     }
-	
-	if (!mRawImage->mComment.empty())
-	{
-		// a is for uploader
-		// z is for time
-		// K is the whole thing (just coz)
-		std::string comment = mRawImage->getComment();
-		mComment['K'] = comment;
-		size_t position = 0;
-		size_t length = comment.length();
-		while (position < length)
-		{
-			std::size_t equals_position = comment.find('=', position);
-			if (equals_position != std::string::npos)
-			{
-				S8 type = comment.at(equals_position - 1);
-				position = comment.find('&', position);
-				if (position != std::string::npos)
-				{
-					mComment[type] = comment.substr(equals_position + 1, position - (equals_position + 1));
-					position++;
-				}
-				else
-				{
-					mComment[type] = comment.substr(equals_position + 1, length - (equals_position + 1));
-				}
-			}
-			else
-			{
-				position = equals_position;
-			}
-		}
-	}
+
+    if (!mRawImage->mComment.empty())
+    {
+        // a is for uploader
+        // z is for time
+        // K is the whole thing (just coz)
+        std::string comment = mRawImage->getComment();
+        mComment['K'] = comment;
+        size_t position = 0;
+        size_t length = comment.length();
+        while (position < length)
+        {
+            std::size_t equals_position = comment.find('=', position);
+            if (equals_position != std::string::npos)
+            {
+                S8 type = comment.at(equals_position - 1);
+                position = comment.find('&', position);
+                if (position != std::string::npos)
+                {
+                    mComment[type] = comment.substr(equals_position + 1, position - (equals_position + 1));
+                    position++;
+                }
+                else
+                {
+                    mComment[type] = comment.substr(equals_position + 1, length - (equals_position + 1));
+                }
+            }
+            else
+            {
+                position = equals_position;
+            }
+        }
+    }
 
     bool size_okay = true;
 
@@ -1581,9 +1581,9 @@ BOOL LLViewerFetchedTexture::createTexture(S32 usename/*= 0*/)
         return FALSE;
     }
 
-	BOOL res = mGLTexturep->createGLTexture(mRawDiscardLevel, mRawImage, usename, TRUE, mBoostLevel);
-    
-	return res;
+    BOOL res = mGLTexturep->createGLTexture(mRawDiscardLevel, mRawImage, usename, TRUE, mBoostLevel);
+
+    return res;
 }
 
 void LLViewerFetchedTexture::postCreateTexture()
@@ -1689,15 +1689,15 @@ void LLViewerFetchedTexture::scheduleCreateTexture()
 void LLViewerFetchedTexture::setKnownDrawSize(S32 width, S32 height)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if(mKnownDrawWidth < width || mKnownDrawHeight < height)
-	{
-		mKnownDrawWidth = llmax(mKnownDrawWidth, width);
-		mKnownDrawHeight = llmax(mKnownDrawHeight, height);
+    if(mKnownDrawWidth < width || mKnownDrawHeight < height)
+    {
+        mKnownDrawWidth = llmax(mKnownDrawWidth, width);
+        mKnownDrawHeight = llmax(mKnownDrawHeight, height);
 
-		mKnownDrawSizeChanged = TRUE;
-		mFullyLoaded = FALSE;
-	}
-	addTextureStats((F32)(mKnownDrawWidth * mKnownDrawHeight));
+        mKnownDrawSizeChanged = TRUE;
+        mFullyLoaded = FALSE;
+    }
+    addTextureStats((F32)(mKnownDrawWidth * mKnownDrawHeight));
 }
 
 void LLViewerFetchedTexture::setDebugText(const std::string& text)
@@ -1725,126 +1725,126 @@ void LLViewerFetchedTexture::setDebugText(const std::string& text)
 void LLViewerFetchedTexture::processTextureStats()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if(mFullyLoaded)
-	{		
-		if(mDesiredDiscardLevel > mMinDesiredDiscardLevel)//need to load more
-		{
-			mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel);
-			mFullyLoaded = FALSE;
-		}
-        //setDebugText("fully loaded");
-	}
-	else
-	{
-		updateVirtualSize();
-		
-		static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes", false);
-		
-		if (textures_fullres)
-		{
-			mDesiredDiscardLevel = 0;
-		}
-        else if (mDontDiscard && (mBoostLevel == LLGLTexture::BOOST_ICON || mBoostLevel == LLGLTexture::BOOST_THUMBNAIL))
+    if(mFullyLoaded)
+    {
+        if(mDesiredDiscardLevel > mMinDesiredDiscardLevel)//need to load more
         {
-            if (mFullWidth > MAX_IMAGE_SIZE_DEFAULT || mFullHeight > MAX_IMAGE_SIZE_DEFAULT)
-            {
-                mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
+            mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel);
+            mFullyLoaded = FALSE;
+        }
+        //setDebugText("fully loaded");
+    }
+    else
+    {
+        updateVirtualSize();
+
+        static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes", false);
+
+        if (textures_fullres)
+        {
+            mDesiredDiscardLevel = 0;
+        }
+        else if (mDontDiscard && (mBoostLevel == LLGLTexture::BOOST_ICON || mBoostLevel == LLGLTexture::BOOST_THUMBNAIL))
+        {
+            if (mFullWidth > MAX_IMAGE_SIZE_DEFAULT || mFullHeight > MAX_IMAGE_SIZE_DEFAULT)
+            {
+                mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
             }
             else
             {
                 mDesiredDiscardLevel = 0;
             }
         }
-		else if(!mFullWidth || !mFullHeight)
-		{
-			mDesiredDiscardLevel = 	llmin(getMaxDiscardLevel(), (S32)mLoadedCallbackDesiredDiscardLevel);
-		}
-		else
-		{
-			U32 desired_size = MAX_IMAGE_SIZE_DEFAULT; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
-			if(!mKnownDrawWidth || !mKnownDrawHeight || mFullWidth <= mKnownDrawWidth || mFullHeight <= mKnownDrawHeight)
-			{
-				if (mFullWidth > desired_size || mFullHeight > desired_size)
-				{
-					mDesiredDiscardLevel = 1;
-				}
-				else
-				{
-					mDesiredDiscardLevel = 0;
-				}
-			}
-			else if(mKnownDrawSizeChanged)//known draw size is set
-			{			
-				mDesiredDiscardLevel = (S8)llmin(log((F32)mFullWidth / mKnownDrawWidth) / log_2, 
-													 log((F32)mFullHeight / mKnownDrawHeight) / log_2);
-				mDesiredDiscardLevel = 	llclamp(mDesiredDiscardLevel, (S8)0, (S8)getMaxDiscardLevel());
-				mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel);
-			}
-			mKnownDrawSizeChanged = FALSE;
-		
-			if(getDiscardLevel() >= 0 && (getDiscardLevel() <= mDesiredDiscardLevel))
-			{
-				mFullyLoaded = TRUE;
-			}
-		}
-	}
-
-	if(mForceToSaveRawImage && mDesiredSavedRawDiscardLevel >= 0) //force to refetch the texture.
-	{
-		mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S8)mDesiredSavedRawDiscardLevel);
-		if(getDiscardLevel() < 0 || getDiscardLevel() > mDesiredDiscardLevel)
-		{
-			mFullyLoaded = FALSE;
-		}
-	}
+        else if(!mFullWidth || !mFullHeight)
+        {
+            mDesiredDiscardLevel =  llmin(getMaxDiscardLevel(), (S32)mLoadedCallbackDesiredDiscardLevel);
+        }
+        else
+        {
+            U32 desired_size = MAX_IMAGE_SIZE_DEFAULT; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
+            if(!mKnownDrawWidth || !mKnownDrawHeight || mFullWidth <= mKnownDrawWidth || mFullHeight <= mKnownDrawHeight)
+            {
+                if (mFullWidth > desired_size || mFullHeight > desired_size)
+                {
+                    mDesiredDiscardLevel = 1;
+                }
+                else
+                {
+                    mDesiredDiscardLevel = 0;
+                }
+            }
+            else if(mKnownDrawSizeChanged)//known draw size is set
+            {
+                mDesiredDiscardLevel = (S8)llmin(log((F32)mFullWidth / mKnownDrawWidth) / log_2,
+                                                     log((F32)mFullHeight / mKnownDrawHeight) / log_2);
+                mDesiredDiscardLevel =  llclamp(mDesiredDiscardLevel, (S8)0, (S8)getMaxDiscardLevel());
+                mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, mMinDesiredDiscardLevel);
+            }
+            mKnownDrawSizeChanged = FALSE;
+
+            if(getDiscardLevel() >= 0 && (getDiscardLevel() <= mDesiredDiscardLevel))
+            {
+                mFullyLoaded = TRUE;
+            }
+        }
+    }
+
+    if(mForceToSaveRawImage && mDesiredSavedRawDiscardLevel >= 0) //force to refetch the texture.
+    {
+        mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S8)mDesiredSavedRawDiscardLevel);
+        if(getDiscardLevel() < 0 || getDiscardLevel() > mDesiredDiscardLevel)
+        {
+            mFullyLoaded = FALSE;
+        }
+    }
 }
 
 //============================================================================
 
-void LLViewerFetchedTexture::updateVirtualSize() 
-{	
+void LLViewerFetchedTexture::updateVirtualSize()
+{
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	reorganizeFaceList();
-	reorganizeVolumeList();
+    reorganizeFaceList();
+    reorganizeVolumeList();
 }
 
 S32 LLViewerFetchedTexture::getCurrentDiscardLevelForFetching()
 {
-	S32 current_discard = getDiscardLevel();
-	if(mForceToSaveRawImage)
-	{
-		if(mSavedRawDiscardLevel < 0 || current_discard < 0)
-		{
-			current_discard = -1;
-		}
-		else
-		{
-			current_discard = llmax(current_discard, mSavedRawDiscardLevel);
-		}		
-	}
+    S32 current_discard = getDiscardLevel();
+    if(mForceToSaveRawImage)
+    {
+        if(mSavedRawDiscardLevel < 0 || current_discard < 0)
+        {
+            current_discard = -1;
+        }
+        else
+        {
+            current_discard = llmax(current_discard, mSavedRawDiscardLevel);
+        }
+    }
 
-	return current_discard;
+    return current_discard;
 }
 
 bool LLViewerFetchedTexture::setDebugFetching(S32 debug_level)
 {
-	if(debug_level < 0)
-	{
-		mInDebug = FALSE;
-		return false;
-	}
-	mInDebug = TRUE;
+    if(debug_level < 0)
+    {
+        mInDebug = FALSE;
+        return false;
+    }
+    mInDebug = TRUE;
 
-	mDesiredDiscardLevel = debug_level;	
+    mDesiredDiscardLevel = debug_level;
 
-	return true;
+    return true;
 }
 
 bool LLViewerFetchedTexture::isActiveFetching()
 {
-	static LLCachedControl<bool> monitor_enabled(gSavedSettings,"DebugShowTextureInfo");
+    static LLCachedControl<bool> monitor_enabled(gSavedSettings,"DebugShowTextureInfo");
 
-	return mFetchState > 7 && mFetchState < 10 && monitor_enabled; //in state of WAIT_HTTP_REQ or DECODE_IMAGE.
+    return mFetchState > 7 && mFetchState < 10 && monitor_enabled; //in state of WAIT_HTTP_REQ or DECODE_IMAGE.
 }
 
 void LLViewerFetchedTexture::setBoostLevel(S32 level)
@@ -1860,121 +1860,121 @@ void LLViewerFetchedTexture::setBoostLevel(S32 level)
 bool LLViewerFetchedTexture::updateFetch()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	static LLCachedControl<bool> textures_decode_disabled(gSavedSettings,"TextureDecodeDisabled", false);
-	
-	if(textures_decode_disabled) // don't fetch the surface textures in wireframe mode
-	{
-		return false;
-	}
-
-	mFetchState = 0;
-	mFetchPriority = 0;
-	mFetchDeltaTime = 999999.f;
-	mRequestDeltaTime = 999999.f;
+    static LLCachedControl<bool> textures_decode_disabled(gSavedSettings,"TextureDecodeDisabled", false);
+
+    if(textures_decode_disabled) // don't fetch the surface textures in wireframe mode
+    {
+        return false;
+    }
+
+    mFetchState = 0;
+    mFetchPriority = 0;
+    mFetchDeltaTime = 999999.f;
+    mRequestDeltaTime = 999999.f;
 
 #ifndef LL_RELEASE_FOR_DOWNLOAD
-	if (mID == LLAppViewer::getTextureFetch()->mDebugID)
-	{
-		LLAppViewer::getTextureFetch()->mDebugCount++; // for setting breakpoints
-	}
+    if (mID == LLAppViewer::getTextureFetch()->mDebugID)
+    {
+        LLAppViewer::getTextureFetch()->mDebugCount++; // for setting breakpoints
+    }
 #endif
 
-	if (mNeedsCreateTexture)
-	{
+    if (mNeedsCreateTexture)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - needs create");
-		// We may be fetching still (e.g. waiting on write)
-		// but don't check until we've processed the raw data we have
-		return false;
-	}
-	if (mIsMissingAsset)
-	{
+        // We may be fetching still (e.g. waiting on write)
+        // but don't check until we've processed the raw data we have
+        return false;
+    }
+    if (mIsMissingAsset)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - missing asset");
-		llassert(!mHasFetcher);
-		return false; // skip
-	}
-	if (!mLoadedCallbackList.empty() && mRawImage.notNull())
-	{
+        llassert(!mHasFetcher);
+        return false; // skip
+    }
+    if (!mLoadedCallbackList.empty() && mRawImage.notNull())
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - callback pending");
-		return false; // process any raw image data in callbacks before replacing
-	}
-	if(mInFastCacheList)
-	{
+        return false; // process any raw image data in callbacks before replacing
+    }
+    if(mInFastCacheList)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - in fast cache");
-		return false;
-	}
+        return false;
+    }
     if (mGLTexturep.isNull())
     { // fix for crash inside getCurrentDiscardLevelForFetching (shouldn't happen but appears to be happening)
         llassert(false);
         return false;
     }
-	
-	S32 current_discard = getCurrentDiscardLevelForFetching();
-	S32 desired_discard = getDesiredDiscardLevel();
-	F32 decode_priority = mMaxVirtualSize;
 
-	if (mIsFetching)
-	{
+    S32 current_discard = getCurrentDiscardLevelForFetching();
+    S32 desired_discard = getDesiredDiscardLevel();
+    F32 decode_priority = mMaxVirtualSize;
+
+    if (mIsFetching)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - is fetching");
-		// Sets mRawDiscardLevel, mRawImage, mAuxRawImage
-		S32 fetch_discard = current_discard;
-		
-		if (mRawImage.notNull()) sRawCount--;
-		if (mAuxRawImage.notNull()) sAuxCount--;
-		// keep in mind that fetcher still might need raw image, don't modify original
-		bool finished = LLAppViewer::getTextureFetch()->getRequestFinished(getID(), fetch_discard, mRawImage, mAuxRawImage,
-																		   mLastHttpGetStatus);
-		if (mRawImage.notNull()) sRawCount++;
-		if (mAuxRawImage.notNull())
-		{
-			mHasAux = TRUE;
-			sAuxCount++;
-		}
-		if (finished)
-		{
-			mIsFetching = FALSE;
+        // Sets mRawDiscardLevel, mRawImage, mAuxRawImage
+        S32 fetch_discard = current_discard;
+
+        if (mRawImage.notNull()) sRawCount--;
+        if (mAuxRawImage.notNull()) sAuxCount--;
+        // keep in mind that fetcher still might need raw image, don't modify original
+        bool finished = LLAppViewer::getTextureFetch()->getRequestFinished(getID(), fetch_discard, mRawImage, mAuxRawImage,
+                                                                           mLastHttpGetStatus);
+        if (mRawImage.notNull()) sRawCount++;
+        if (mAuxRawImage.notNull())
+        {
+            mHasAux = TRUE;
+            sAuxCount++;
+        }
+        if (finished)
+        {
+            mIsFetching = FALSE;
             mLastFetchState = -1;
-			mLastPacketTimer.reset();
-		}
-		else
-		{
-			mFetchState = LLAppViewer::getTextureFetch()->getFetchState(mID, mDownloadProgress, mRequestedDownloadPriority,
-																		mFetchPriority, mFetchDeltaTime, mRequestDeltaTime, mCanUseHTTP);
-		}
-		
-		// We may have data ready regardless of whether or not we are finished (e.g. waiting on write)
-		if (mRawImage.notNull())
-		{
+            mLastPacketTimer.reset();
+        }
+        else
+        {
+            mFetchState = LLAppViewer::getTextureFetch()->getFetchState(mID, mDownloadProgress, mRequestedDownloadPriority,
+                                                                        mFetchPriority, mFetchDeltaTime, mRequestDeltaTime, mCanUseHTTP);
+        }
+
+        // We may have data ready regardless of whether or not we are finished (e.g. waiting on write)
+        if (mRawImage.notNull())
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - has raw image");
-			LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
-			if (tester)
-			{
-				mIsFetched = TRUE;
-				tester->updateTextureLoadingStats(this, mRawImage, LLAppViewer::getTextureFetch()->isFromLocalCache(mID));
-			}
-			mRawDiscardLevel = fetch_discard;
-			if ((mRawImage->getDataSize() > 0 && mRawDiscardLevel >= 0) &&
-				(current_discard < 0 || mRawDiscardLevel < current_discard))
-			{
+            LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
+            if (tester)
+            {
+                mIsFetched = TRUE;
+                tester->updateTextureLoadingStats(this, mRawImage, LLAppViewer::getTextureFetch()->isFromLocalCache(mID));
+            }
+            mRawDiscardLevel = fetch_discard;
+            if ((mRawImage->getDataSize() > 0 && mRawDiscardLevel >= 0) &&
+                (current_discard < 0 || mRawDiscardLevel < current_discard))
+            {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - data good");
-				mFullWidth = mRawImage->getWidth() << mRawDiscardLevel;
-				mFullHeight = mRawImage->getHeight() << mRawDiscardLevel;
-				setTexelsPerImage();
-
-				if(mFullWidth > MAX_IMAGE_SIZE || mFullHeight > MAX_IMAGE_SIZE)
-				{ 
-					//discard all oversized textures.
-					destroyRawImage();
-					LL_WARNS() << "oversize, setting as missing" << LL_ENDL;
-					setIsMissingAsset();
-					mRawDiscardLevel = INVALID_DISCARD_LEVEL;
-					mIsFetching = FALSE;
-					mLastPacketTimer.reset();
-				}
-				else
-				{
-					mIsRawImageValid = TRUE;
-					addToCreateTexture();
-				}
+                mFullWidth = mRawImage->getWidth() << mRawDiscardLevel;
+                mFullHeight = mRawImage->getHeight() << mRawDiscardLevel;
+                setTexelsPerImage();
+
+                if(mFullWidth > MAX_IMAGE_SIZE || mFullHeight > MAX_IMAGE_SIZE)
+                {
+                    //discard all oversized textures.
+                    destroyRawImage();
+                    LL_WARNS() << "oversize, setting as missing" << LL_ENDL;
+                    setIsMissingAsset();
+                    mRawDiscardLevel = INVALID_DISCARD_LEVEL;
+                    mIsFetching = FALSE;
+                    mLastPacketTimer.reset();
+                }
+                else
+                {
+                    mIsRawImageValid = TRUE;
+                    addToCreateTexture();
+                }
 
                 if (mBoostLevel == LLGLTexture::BOOST_ICON)
                 {
@@ -2000,304 +2000,304 @@ bool LLViewerFetchedTexture::updateFetch()
                     }
                 }
 
-				return TRUE;
-			}
-			else
-			{
+                return TRUE;
+            }
+            else
+            {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - data not needed");
-				// Data is ready but we don't need it
-				// (received it already while fetcher was writing to disk)
-				destroyRawImage();
-				return false; // done
-			}
-		}
-		
-		if (!mIsFetching)
-		{
-			if ((decode_priority > 0) && (mRawDiscardLevel < 0 || mRawDiscardLevel == INVALID_DISCARD_LEVEL))
-			{
-				// We finished but received no data
-				if (getDiscardLevel() < 0)
-				{
-					if (getFTType() != FTT_MAP_TILE)
-					{
-						LL_WARNS() << mID
-								<< " Fetch failure, setting as missing, decode_priority " << decode_priority
-								<< " mRawDiscardLevel " << mRawDiscardLevel
-								<< " current_discard " << current_discard
-								<< " stats " << mLastHttpGetStatus.toHex()
-								<< LL_ENDL;
-					}
-					setIsMissingAsset();
-					desired_discard = -1;
-				}
-				else
-				{
-					//LL_WARNS() << mID << ": Setting min discard to " << current_discard << LL_ENDL;
-					if(current_discard >= 0)
-					{
-						mMinDiscardLevel = current_discard;
-						//desired_discard = current_discard;
-					}
-					else
-					{
-						S32 dis_level = getDiscardLevel();
-						mMinDiscardLevel = dis_level;
-						//desired_discard = dis_level;
-					}
-				}
-				destroyRawImage();
-			}
-			else if (mRawImage.notNull())
-			{
-				// We have data, but our fetch failed to return raw data
-				// *TODO: FIgure out why this is happening and fix it
-				destroyRawImage();
-			}
-		}
-		else
-		{
-			static const F32 MAX_HOLD_TIME = 5.0f; //seconds to wait before canceling fecthing if decode_priority is 0.f.
-			if(decode_priority > 0.0f || mStopFetchingTimer.getElapsedTimeF32() > MAX_HOLD_TIME)
-			{
-				mStopFetchingTimer.reset();
-				LLAppViewer::getTextureFetch()->updateRequestPriority(mID, decode_priority);
-			}
-		}
-	}
+                // Data is ready but we don't need it
+                // (received it already while fetcher was writing to disk)
+                destroyRawImage();
+                return false; // done
+            }
+        }
+
+        if (!mIsFetching)
+        {
+            if ((decode_priority > 0) && (mRawDiscardLevel < 0 || mRawDiscardLevel == INVALID_DISCARD_LEVEL))
+            {
+                // We finished but received no data
+                if (getDiscardLevel() < 0)
+                {
+                    if (getFTType() != FTT_MAP_TILE)
+                    {
+                        LL_WARNS() << mID
+                                << " Fetch failure, setting as missing, decode_priority " << decode_priority
+                                << " mRawDiscardLevel " << mRawDiscardLevel
+                                << " current_discard " << current_discard
+                                << " stats " << mLastHttpGetStatus.toHex()
+                                << LL_ENDL;
+                    }
+                    setIsMissingAsset();
+                    desired_discard = -1;
+                }
+                else
+                {
+                    //LL_WARNS() << mID << ": Setting min discard to " << current_discard << LL_ENDL;
+                    if(current_discard >= 0)
+                    {
+                        mMinDiscardLevel = current_discard;
+                        //desired_discard = current_discard;
+                    }
+                    else
+                    {
+                        S32 dis_level = getDiscardLevel();
+                        mMinDiscardLevel = dis_level;
+                        //desired_discard = dis_level;
+                    }
+                }
+                destroyRawImage();
+            }
+            else if (mRawImage.notNull())
+            {
+                // We have data, but our fetch failed to return raw data
+                // *TODO: FIgure out why this is happening and fix it
+                destroyRawImage();
+            }
+        }
+        else
+        {
+            static const F32 MAX_HOLD_TIME = 5.0f; //seconds to wait before canceling fecthing if decode_priority is 0.f.
+            if(decode_priority > 0.0f || mStopFetchingTimer.getElapsedTimeF32() > MAX_HOLD_TIME)
+            {
+                mStopFetchingTimer.reset();
+                LLAppViewer::getTextureFetch()->updateRequestPriority(mID, decode_priority);
+            }
+        }
+    }
 
     desired_discard = llmin(desired_discard, getMaxDiscardLevel());
 
-	bool make_request = true;	
-	if (decode_priority <= 0)
-	{
+    bool make_request = true;
+    if (decode_priority <= 0)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - priority <= 0");
-		make_request = false;
-	}
-	else if(mDesiredDiscardLevel > getMaxDiscardLevel())
-	{
+        make_request = false;
+    }
+    else if(mDesiredDiscardLevel > getMaxDiscardLevel())
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - desired > max");
-		make_request = false;
-	}
-	else  if (mNeedsCreateTexture || mIsMissingAsset)
-	{
+        make_request = false;
+    }
+    else  if (mNeedsCreateTexture || mIsMissingAsset)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - create or missing");
-		make_request = false;
-	}
-	else if (current_discard >= 0 && current_discard <= mMinDiscardLevel)
-	{
+        make_request = false;
+    }
+    else if (current_discard >= 0 && current_discard <= mMinDiscardLevel)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - current < min");
-		make_request = false;
-	}
-	else if(mCachedRawImage.notNull() // can be empty
-			&& mCachedRawImageReady
-			&& (current_discard < 0 || current_discard > mCachedRawDiscardLevel))
-	{
-		make_request = false;
-		switchToCachedImage(); //use the cached raw data first
-	}
-	
-	if (make_request)
-	{
-		if (mIsFetching)
-		{
+        make_request = false;
+    }
+    else if(mCachedRawImage.notNull() // can be empty
+            && mCachedRawImageReady
+            && (current_discard < 0 || current_discard > mCachedRawDiscardLevel))
+    {
+        make_request = false;
+        switchToCachedImage(); //use the cached raw data first
+    }
+
+    if (make_request)
+    {
+        if (mIsFetching)
+        {
             // already requested a higher resolution mip
-			if (mRequestedDiscardLevel <= desired_discard)
-			{
+            if (mRequestedDiscardLevel <= desired_discard)
+            {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - requested < desired");
-				make_request = false;
-			}
-		}
-		else
-		{
+                make_request = false;
+            }
+        }
+        else
+        {
             // already at a higher resolution mip, don't discard
-			if (current_discard >= 0 && current_discard <= desired_discard)
-			{
+            if (current_discard >= 0 && current_discard <= desired_discard)
+            {
                 LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - current <= desired");
-				make_request = false;
-			}
-		}
-	}
-	
-	if (make_request)
-	{
+                make_request = false;
+            }
+        }
+    }
+
+    if (make_request)
+    {
         LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - make request");
-		S32 w=0, h=0, c=0;
-		if (getDiscardLevel() >= 0)
-		{
-			w = mGLTexturep->getWidth(0);
-			h = mGLTexturep->getHeight(0);
-			c = mComponents;
-		}
-
-		static const LLCachedControl<U32> override_tex_discard_level(gSavedSettings, "TextureDiscardLevel");
-		if (override_tex_discard_level != 0)
-		{
-			desired_discard = override_tex_discard_level;
-		}
-		
-		// bypass texturefetch directly by pulling from LLTextureCache
-		S32 fetch_request_discard = -1;
+        S32 w=0, h=0, c=0;
+        if (getDiscardLevel() >= 0)
+        {
+            w = mGLTexturep->getWidth(0);
+            h = mGLTexturep->getHeight(0);
+            c = mComponents;
+        }
+
+        static const LLCachedControl<U32> override_tex_discard_level(gSavedSettings, "TextureDiscardLevel");
+        if (override_tex_discard_level != 0)
+        {
+            desired_discard = override_tex_discard_level;
+        }
+
+        // bypass texturefetch directly by pulling from LLTextureCache
+        S32 fetch_request_discard = -1;
         fetch_request_discard = LLAppViewer::getTextureFetch()->createRequest(mFTType, mUrl, getID(), getTargetHost(), decode_priority,
-																			  w, h, c, desired_discard, needsAux(), mCanUseHTTP);
-		
-		if (fetch_request_discard >= 0)
-		{
+                                                                              w, h, c, desired_discard, needsAux(), mCanUseHTTP);
+
+        if (fetch_request_discard >= 0)
+        {
             LL_PROFILE_ZONE_NAMED_CATEGORY_TEXTURE("vftuf - request created");
-			mHasFetcher = TRUE;
-			mIsFetching = TRUE;
+            mHasFetcher = TRUE;
+            mIsFetching = TRUE;
             // in some cases createRequest can modify discard, as an example
             // bake textures are always at discard 0
             mRequestedDiscardLevel = llmin(desired_discard, fetch_request_discard);
-			mFetchState = LLAppViewer::getTextureFetch()->getFetchState(mID, mDownloadProgress, mRequestedDownloadPriority,
-													   mFetchPriority, mFetchDeltaTime, mRequestDeltaTime, mCanUseHTTP);
-		}
+            mFetchState = LLAppViewer::getTextureFetch()->getFetchState(mID, mDownloadProgress, mRequestedDownloadPriority,
+                                                       mFetchPriority, mFetchDeltaTime, mRequestDeltaTime, mCanUseHTTP);
+        }
 
         // If createRequest() failed, that means one of two things:
         // 1. We're finishing up a request for this UUID, so we
         //    should wait for it to complete
         // 2. We've failed a request for this UUID, so there is
         //    no need to create another request
-	}
-	else if (mHasFetcher && !mIsFetching)
-	{
-		// Only delete requests that haven't received any network data
-		// for a while.  Note - this is the normal mechanism for
-		// deleting requests, not just a place to handle timeouts.
-		const F32 FETCH_IDLE_TIME = 0.1f;
-		if (mLastPacketTimer.getElapsedTimeF32() > FETCH_IDLE_TIME)
-		{
+    }
+    else if (mHasFetcher && !mIsFetching)
+    {
+        // Only delete requests that haven't received any network data
+        // for a while.  Note - this is the normal mechanism for
+        // deleting requests, not just a place to handle timeouts.
+        const F32 FETCH_IDLE_TIME = 0.1f;
+        if (mLastPacketTimer.getElapsedTimeF32() > FETCH_IDLE_TIME)
+        {
 #ifdef SHOW_DEBUG
- 			LL_DEBUGS("Texture") << "exceeded idle time " << FETCH_IDLE_TIME << ", deleting request: " << getID() << LL_ENDL;
+            LL_DEBUGS("Texture") << "exceeded idle time " << FETCH_IDLE_TIME << ", deleting request: " << getID() << LL_ENDL;
 #endif
-			LLAppViewer::getTextureFetch()->deleteRequest(getID(), true);
-			mHasFetcher = FALSE;
-		}
-	}
-	
-	return mIsFetching ? true : false;
+            LLAppViewer::getTextureFetch()->deleteRequest(getID(), true);
+            mHasFetcher = FALSE;
+        }
+    }
+
+    return mIsFetching ? true : false;
 }
 
 void LLViewerFetchedTexture::clearFetchedResults()
 {
-	if(mNeedsCreateTexture || mIsFetching)
-	{
-		return;
-	}
-	
-	cleanup();
-	destroyGLTexture();
+    if(mNeedsCreateTexture || mIsFetching)
+    {
+        return;
+    }
+
+    cleanup();
+    destroyGLTexture();
 
-	if(getDiscardLevel() >= 0) //sculpty texture, force to invalidate
-	{
-		mGLTexturep->forceToInvalidateGLTexture();
-	}
+    if(getDiscardLevel() >= 0) //sculpty texture, force to invalidate
+    {
+        mGLTexturep->forceToInvalidateGLTexture();
+    }
 }
 
 void LLViewerFetchedTexture::forceToDeleteRequest()
 {
-	if (mHasFetcher)
-	{
-		mHasFetcher = FALSE;
-		mIsFetching = FALSE;
-	}
-		
-	resetTextureStats();
+    if (mHasFetcher)
+    {
+        mHasFetcher = FALSE;
+        mIsFetching = FALSE;
+    }
 
-	mDesiredDiscardLevel = getMaxDiscardLevel() + 1;
+    resetTextureStats();
+
+    mDesiredDiscardLevel = getMaxDiscardLevel() + 1;
 }
 
 void LLViewerFetchedTexture::setIsMissingAsset(BOOL is_missing)
 {
-	if (is_missing == mIsMissingAsset)
-	{
-		return;
-	}
-	if (is_missing)
-	{
-		if (mUrl.empty())
-		{
-			LL_WARNS() << mID << ": Marking image as missing" << LL_ENDL;
-		}
-		else
-		{
-			// This may or may not be an error - it is normal to have no
-			// map tile on an empty region, but bad if we're failing on a
-			// server bake texture.
-			if (getFTType() != FTT_MAP_TILE)
-			{
-				LL_WARNS() << mUrl << ": Marking image as missing" << LL_ENDL;
-			}
-		}
-		if (mHasFetcher)
-		{
-			LLAppViewer::getTextureFetch()->deleteRequest(getID(), true);
-			mHasFetcher = FALSE;
-			mIsFetching = FALSE;
-			mLastPacketTimer.reset();
-			mFetchState = 0;
-			mFetchPriority = 0;
-		}
-	}
-	else
-	{
-		LL_INFOS() << mID << ": un-flagging missing asset" << LL_ENDL;
-	}
-	mIsMissingAsset = is_missing;
+    if (is_missing == mIsMissingAsset)
+    {
+        return;
+    }
+    if (is_missing)
+    {
+        if (mUrl.empty())
+        {
+            LL_WARNS() << mID << ": Marking image as missing" << LL_ENDL;
+        }
+        else
+        {
+            // This may or may not be an error - it is normal to have no
+            // map tile on an empty region, but bad if we're failing on a
+            // server bake texture.
+            if (getFTType() != FTT_MAP_TILE)
+            {
+                LL_WARNS() << mUrl << ": Marking image as missing" << LL_ENDL;
+            }
+        }
+        if (mHasFetcher)
+        {
+            LLAppViewer::getTextureFetch()->deleteRequest(getID(), true);
+            mHasFetcher = FALSE;
+            mIsFetching = FALSE;
+            mLastPacketTimer.reset();
+            mFetchState = 0;
+            mFetchPriority = 0;
+        }
+    }
+    else
+    {
+        LL_INFOS() << mID << ": un-flagging missing asset" << LL_ENDL;
+    }
+    mIsMissingAsset = is_missing;
 }
 
 void LLViewerFetchedTexture::setLoadedCallback( loaded_callback_func loaded_callback,
-									   S32 discard_level, BOOL keep_imageraw, BOOL needs_aux, void* userdata, 
-									   LLLoadedCallbackEntry::source_callback_list_t* src_callback_list, BOOL pause)
-{
-	//
-	// Don't do ANYTHING here, just add it to the global callback list
-	//
-	if (mLoadedCallbackList.empty())
-	{
-		// Put in list to call this->doLoadedCallbacks() periodically
-		gTextureList.mCallbackList.insert(this);
-		mLoadedCallbackDesiredDiscardLevel = (S8)discard_level;
-	}
-	else
-	{
-		mLoadedCallbackDesiredDiscardLevel = llmin(mLoadedCallbackDesiredDiscardLevel, (S8)discard_level);
-	}
-
-	if(mPauseLoadedCallBacks)
-	{
-		if(!pause)
-		{
-			unpauseLoadedCallbacks(src_callback_list);
-		}
-	}
-	else if(pause)
-	{
-		pauseLoadedCallbacks(src_callback_list);
-	}
-
-	LLLoadedCallbackEntry* entryp = new LLLoadedCallbackEntry(loaded_callback, discard_level, keep_imageraw, userdata, src_callback_list, this, pause);
-	mLoadedCallbackList.push_back(entryp);	
-
-	mNeedsAux |= needs_aux;
-	if(keep_imageraw)
-	{
-		mSaveRawImage = TRUE;
-	}
-	if (mNeedsAux && mAuxRawImage.isNull() && getDiscardLevel() >= 0)
-	{
-		if(mHasAux)
-		{
-			//trigger a refetch
-			forceToRefetchTexture();
-		}
-		else
-		{
-			// We need aux data, but we've already loaded the image, and it didn't have any
-			LL_WARNS() << "No aux data available for callback for image:" << getID() << LL_ENDL;
-		}
-	}
-	mLastCallBackActiveTime = sCurrentTime ;
+                                       S32 discard_level, BOOL keep_imageraw, BOOL needs_aux, void* userdata,
+                                       LLLoadedCallbackEntry::source_callback_list_t* src_callback_list, BOOL pause)
+{
+    //
+    // Don't do ANYTHING here, just add it to the global callback list
+    //
+    if (mLoadedCallbackList.empty())
+    {
+        // Put in list to call this->doLoadedCallbacks() periodically
+        gTextureList.mCallbackList.insert(this);
+        mLoadedCallbackDesiredDiscardLevel = (S8)discard_level;
+    }
+    else
+    {
+        mLoadedCallbackDesiredDiscardLevel = llmin(mLoadedCallbackDesiredDiscardLevel, (S8)discard_level);
+    }
+
+    if(mPauseLoadedCallBacks)
+    {
+        if(!pause)
+        {
+            unpauseLoadedCallbacks(src_callback_list);
+        }
+    }
+    else if(pause)
+    {
+        pauseLoadedCallbacks(src_callback_list);
+    }
+
+    LLLoadedCallbackEntry* entryp = new LLLoadedCallbackEntry(loaded_callback, discard_level, keep_imageraw, userdata, src_callback_list, this, pause);
+    mLoadedCallbackList.push_back(entryp);
+
+    mNeedsAux |= needs_aux;
+    if(keep_imageraw)
+    {
+        mSaveRawImage = TRUE;
+    }
+    if (mNeedsAux && mAuxRawImage.isNull() && getDiscardLevel() >= 0)
+    {
+        if(mHasAux)
+        {
+            //trigger a refetch
+            forceToRefetchTexture();
+        }
+        else
+        {
+            // We need aux data, but we've already loaded the image, and it didn't have any
+            LL_WARNS() << "No aux data available for callback for image:" << getID() << LL_ENDL;
+        }
+    }
+    mLastCallBackActiveTime = sCurrentTime ;
         mLastReferencedSavedRawImageTime = sCurrentTime;
 }
 
@@ -2350,501 +2350,501 @@ void LLViewerFetchedTexture::setLoadedCallbackNoAux(loaded_callback_func loaded_
 
 void LLViewerFetchedTexture::clearCallbackEntryList()
 {
-	if(mLoadedCallbackList.empty())
-	{
-		return;
-	}
-
-	for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
-			iter != mLoadedCallbackList.end(); )
-	{
-		LLLoadedCallbackEntry *entryp = *iter;
-			
-		// We never finished loading the image.  Indicate failure.
-		// Note: this allows mLoadedCallbackUserData to be cleaned up.
-		entryp->mCallback(FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData);
-		iter = mLoadedCallbackList.erase(iter);
-		delete entryp;
-	}
-	gTextureList.mCallbackList.erase(this);
-		
-	mLoadedCallbackDesiredDiscardLevel = S8_MAX;
-	if(needsToSaveRawImage())
-	{
-		destroySavedRawImage();
-	}
-
-	return;
-}
-
-void LLViewerFetchedTexture::deleteCallbackEntry(const LLLoadedCallbackEntry::source_callback_list_t* callback_list)
-{
-	if(mLoadedCallbackList.empty() || !callback_list)
-	{
-		return;
-	}
-
-	S32 desired_discard = S8_MAX;
-	S32 desired_raw_discard = INVALID_DISCARD_LEVEL;
-	for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
-			iter != mLoadedCallbackList.end(); )
-	{
-		LLLoadedCallbackEntry *entryp = *iter;
-		if(entryp->mSourceCallbackList == callback_list)
-		{
-			// We never finished loading the image.  Indicate failure.
-			// Note: this allows mLoadedCallbackUserData to be cleaned up.
-			entryp->mCallback(FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData);
-			iter = mLoadedCallbackList.erase(iter);
-			delete entryp;
-		}
-		else
-		{
-			++iter;
-
-			desired_discard = llmin(desired_discard, entryp->mDesiredDiscard);
-			if(entryp->mNeedsImageRaw)
-			{
-				desired_raw_discard = llmin(desired_raw_discard, entryp->mDesiredDiscard);
-			}
-		}
-	}
-
-	mLoadedCallbackDesiredDiscardLevel = desired_discard;
-	if (mLoadedCallbackList.empty())
-	{
-		// If we have no callbacks, take us off of the image callback list.
-		gTextureList.mCallbackList.erase(this);
-		
-		if(needsToSaveRawImage())
-		{
-			destroySavedRawImage();
-		}
-	}
-	else if(needsToSaveRawImage() && mBoostLevel != LLGLTexture::BOOST_PREVIEW)
-	{
-		if(desired_raw_discard != INVALID_DISCARD_LEVEL)
-		{
-			mDesiredSavedRawDiscardLevel = desired_raw_discard;
-		}
-		else
-		{
-			destroySavedRawImage();
-		}
-	}
-}
-
-void LLViewerFetchedTexture::unpauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list)
-{
-	if(!callback_list)
-{
-		mPauseLoadedCallBacks = FALSE;
-		return;
-	}
-
-	BOOL need_raw = FALSE;
-	for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
-			iter != mLoadedCallbackList.end(); )
-	{
-		LLLoadedCallbackEntry *entryp = *iter++;
-		if(entryp->mSourceCallbackList == callback_list)
-		{
-			entryp->mPaused = FALSE;
-			if(entryp->mNeedsImageRaw)
-			{
-				need_raw = TRUE;
-			}
-		}
-	}
-	mPauseLoadedCallBacks = FALSE ;
-	mLastCallBackActiveTime = sCurrentTime ;
-	mForceCallbackFetch = TRUE;
-	if(need_raw)
-	{
-		mSaveRawImage = TRUE;
-	}
-}
-
-void LLViewerFetchedTexture::pauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list)
-{
-	if(!callback_list)
-{
-		return;
-	}
+    if(mLoadedCallbackList.empty())
+    {
+        return;
+    }
 
-	bool paused = true;
+    for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+            iter != mLoadedCallbackList.end(); )
+    {
+        LLLoadedCallbackEntry *entryp = *iter;
 
-	for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
-			iter != mLoadedCallbackList.end(); )
-	{
-		LLLoadedCallbackEntry *entryp = *iter++;
-		if(entryp->mSourceCallbackList == callback_list)
-		{
-			entryp->mPaused = TRUE;
-		}
-		else if(!entryp->mPaused)
-		{
-			paused = false;
-		}
-	}
+        // We never finished loading the image.  Indicate failure.
+        // Note: this allows mLoadedCallbackUserData to be cleaned up.
+        entryp->mCallback(FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData);
+        iter = mLoadedCallbackList.erase(iter);
+        delete entryp;
+    }
+    gTextureList.mCallbackList.erase(this);
 
-	if(paused)
-	{
-		mPauseLoadedCallBacks = TRUE;//when set, loaded callback is paused.
-		resetTextureStats();
-		mSaveRawImage = FALSE;
-	}
-}
+    mLoadedCallbackDesiredDiscardLevel = S8_MAX;
+    if(needsToSaveRawImage())
+    {
+        destroySavedRawImage();
+    }
 
-bool LLViewerFetchedTexture::doLoadedCallbacks()
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	static const F32 MAX_INACTIVE_TIME = 900.f ; //seconds
-	static const F32 MAX_IDLE_WAIT_TIME = 5.f ; //seconds
-
-	if (mNeedsCreateTexture)
-	{
-		return false;
-	}
-	if(mPauseLoadedCallBacks)
-	{
-		destroyRawImage();
-		return false; //paused
-	}	
-	if(sCurrentTime - mLastCallBackActiveTime > MAX_INACTIVE_TIME && !mIsFetching)
-	{
-		if (mFTType == FTT_SERVER_BAKE)
-		{
-			//output some debug info
-			LL_INFOS() << "baked texture: " << mID << "clears all call backs due to inactivity." << LL_ENDL;
-			LL_INFOS() << mUrl << LL_ENDL;
-			LL_INFOS() << "current discard: " << getDiscardLevel() << " current discard for fetch: " << getCurrentDiscardLevelForFetching() <<
-				" Desired discard: " << getDesiredDiscardLevel() << "decode Pri: " << mMaxVirtualSize << LL_ENDL;
-		}
-
-		clearCallbackEntryList() ; //remove all callbacks.
-		return false ;
-	}
-
-	bool res = false;
-	
-	if (isMissingAsset())
-	{
-		if (mFTType == FTT_SERVER_BAKE)
-		{
-			//output some debug info
-			LL_INFOS() << "baked texture: " << mID << "is missing." << LL_ENDL;
-			LL_INFOS() << mUrl << LL_ENDL;
-		}
-
-		for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
-			iter != mLoadedCallbackList.end(); )
-		{
-			LLLoadedCallbackEntry *entryp = *iter++;
-			// We never finished loading the image.  Indicate failure.
-			// Note: this allows mLoadedCallbackUserData to be cleaned up.
-			entryp->mCallback(FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData);
-			delete entryp;
-		}
-		mLoadedCallbackList.clear();
-
-		// Remove ourself from the global list of textures with callbacks
-		gTextureList.mCallbackList.erase(this);
-		return false;
-	}	
-
-	S32 gl_discard = getDiscardLevel();
-
-	// If we don't have a legit GL image, set it to be lower than the worst discard level
-	if (gl_discard == -1)
-	{
-		gl_discard = MAX_DISCARD_LEVEL + 1;
-	}
-
-	//
-	// Determine the quality levels of textures that we can provide to callbacks
-	// and whether we need to do decompression/readback to get it
-	//
-	S32 current_raw_discard = MAX_DISCARD_LEVEL + 1; // We can always do a readback to get a raw discard
-	S32 best_raw_discard = gl_discard;	// Current GL quality level
-	S32 current_aux_discard = MAX_DISCARD_LEVEL + 1;
-	S32 best_aux_discard = MAX_DISCARD_LEVEL + 1;
-
-	if (mIsRawImageValid)
-	{
-		// If we have an existing raw image, we have a baseline for the raw and auxiliary quality levels.
-		best_raw_discard = llmin(best_raw_discard, mRawDiscardLevel);
-		best_aux_discard = llmin(best_aux_discard, mRawDiscardLevel); // We always decode the aux when we decode the base raw
-		current_aux_discard = llmin(current_aux_discard, best_aux_discard);
-	}
-	else
-	{
-		// We have no data at all, we need to get it
-		// Do this by forcing the best aux discard to be 0.
-		best_aux_discard = 0;
-	}
-
-
-	//
-	// See if any of the callbacks would actually run using the data that we can provide,
-	// and also determine if we need to perform any readbacks or decodes.
-	//
-	bool run_gl_callbacks = false;
-	bool run_raw_callbacks = false;
-	bool need_readback = false;
-
-	for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
-		iter != mLoadedCallbackList.end(); )
-	{
-		LLLoadedCallbackEntry *entryp = *iter++;
-	
-		if (entryp->mNeedsImageRaw)
-		{
-			if (mNeedsAux)
-			{
-				//
-				// Need raw and auxiliary channels
-				//
-				if (entryp->mLastUsedDiscard > current_aux_discard)
-				{
-					// We have useful data, run the callbacks
-					run_raw_callbacks = true;
-				}
-			}
-			else
-			{
-				if (entryp->mLastUsedDiscard > current_raw_discard)
-				{
-					// We have useful data, just run the callbacks
-					run_raw_callbacks = true;
-				}
-				else if (entryp->mLastUsedDiscard > best_raw_discard)
-				{
-					// We can readback data, and then run the callbacks
-					need_readback = true;
-					run_raw_callbacks = true;
-				}
-			}
-		}
-		else
-		{
-			// Needs just GL
-			if (entryp->mLastUsedDiscard > gl_discard)
-			{
-				// We have enough data, run this callback requiring GL data
-				run_gl_callbacks = true;
-			}
-		}
-	}
-
-	//
-	// Do a readback if required, OR start off a texture decode
-	//
-	if (need_readback && (getMaxDiscardLevel() > gl_discard))
-	{
-		// Do a readback to get the GL data into the raw image
-		// We have GL data.
-
-		destroyRawImage();
-		reloadRawImage(mLoadedCallbackDesiredDiscardLevel);
-		llassert(mRawImage.notNull());
-		llassert(!mNeedsAux || mAuxRawImage.notNull());
-	}
-
-	//
-	// Run raw/auxiliary data callbacks
-	//
-	if (run_raw_callbacks && mIsRawImageValid && (mRawDiscardLevel <= getMaxDiscardLevel()))
-	{
-		// Do callbacks which require raw image data.
-		//LL_INFOS() << "doLoadedCallbacks raw for " << getID() << LL_ENDL;
-
-		// Call each party interested in the raw data.
-		for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
-			iter != mLoadedCallbackList.end(); )
-		{
-			callback_list_t::iterator curiter = iter++;
-			LLLoadedCallbackEntry *entryp = *curiter;
-			if (entryp->mNeedsImageRaw && (entryp->mLastUsedDiscard > mRawDiscardLevel))
-			{
-				// If we've loaded all the data there is to load or we've loaded enough
-				// to satisfy the interested party, then this is the last time that
-				// we're going to call them.
-
-				mLastCallBackActiveTime = sCurrentTime;
-				if(mNeedsAux && mAuxRawImage.isNull())
-				{
-					LL_WARNS() << "Raw Image with no Aux Data for callback" << LL_ENDL;
-				}
-				BOOL final = mRawDiscardLevel <= entryp->mDesiredDiscard ? TRUE : FALSE;
-				//LL_INFOS() << "Running callback for " << getID() << LL_ENDL;
-				//LL_INFOS() << mRawImage->getWidth() << "x" << mRawImage->getHeight() << LL_ENDL;
-				entryp->mLastUsedDiscard = mRawDiscardLevel;
-				entryp->mCallback(TRUE, this, mRawImage, mAuxRawImage, mRawDiscardLevel, final, entryp->mUserData);
-				if (final)
-				{
-					iter = mLoadedCallbackList.erase(curiter);
-					delete entryp;
-				}
-				res = true;
-			}
-		}
-	}
-
-	//
-	// Run GL callbacks
-	//
-	if (run_gl_callbacks && (gl_discard <= getMaxDiscardLevel()))
-	{
-		//LL_INFOS() << "doLoadedCallbacks GL for " << getID() << LL_ENDL;
-
-		// Call the callbacks interested in GL data.
-		for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
-			iter != mLoadedCallbackList.end(); )
-		{
-			callback_list_t::iterator curiter = iter++;
-			LLLoadedCallbackEntry *entryp = *curiter;
-			if (!entryp->mNeedsImageRaw && (entryp->mLastUsedDiscard > gl_discard))
-			{
-				mLastCallBackActiveTime = sCurrentTime;
-				BOOL final = gl_discard <= entryp->mDesiredDiscard ? TRUE : FALSE;
-				entryp->mLastUsedDiscard = gl_discard;
-				entryp->mCallback(TRUE, this, NULL, NULL, gl_discard, final, entryp->mUserData);
-				if (final)
-				{
-					iter = mLoadedCallbackList.erase(curiter);
-					delete entryp;
-				}
-				res = true;
-			}
-		}
-	}
-
-	// Done with any raw image data at this point (will be re-created if we still have callbacks)
-	destroyRawImage();
-
-	//
-	// If we have no callbacks, take us off of the image callback list.
-	//
-	if (mLoadedCallbackList.empty())
-	{
-		gTextureList.mCallbackList.erase(this);
-	}
-	else if(!res && mForceCallbackFetch && sCurrentTime - mLastCallBackActiveTime > MAX_IDLE_WAIT_TIME && !mIsFetching)
-	{
-		//wait for long enough but no fetching request issued, force one.
-		forceToRefetchTexture(mLoadedCallbackDesiredDiscardLevel, 5.f);
-		mForceCallbackFetch = FALSE; //fire once.
-	}
-
-	return res;
+    return;
 }
 
-//virtual
-void LLViewerFetchedTexture::forceImmediateUpdate()
+void LLViewerFetchedTexture::deleteCallbackEntry(const LLLoadedCallbackEntry::source_callback_list_t* callback_list)
 {
-	//only immediately update a deleted texture which is now being re-used.
-	if(!isDeleted())
-	{
-		return;
-	}
-	//if already called forceImmediateUpdate()
-	if(mInImageList && mMaxVirtualSize == LLViewerFetchedTexture::sMaxVirtualSize)
-	{
-		return;
-	}
+    if(mLoadedCallbackList.empty() || !callback_list)
+    {
+        return;
+    }
 
-	gTextureList.forceImmediateUpdate(this);
-	return;
-}
+    S32 desired_discard = S8_MAX;
+    S32 desired_raw_discard = INVALID_DISCARD_LEVEL;
+    for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+            iter != mLoadedCallbackList.end(); )
+    {
+        LLLoadedCallbackEntry *entryp = *iter;
+        if(entryp->mSourceCallbackList == callback_list)
+        {
+            // We never finished loading the image.  Indicate failure.
+            // Note: this allows mLoadedCallbackUserData to be cleaned up.
+            entryp->mCallback(FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData);
+            iter = mLoadedCallbackList.erase(iter);
+            delete entryp;
+        }
+        else
+        {
+            ++iter;
 
-LLImageRaw* LLViewerFetchedTexture::reloadRawImage(S8 discard_level)
-{
-	llassert(mGLTexturep.notNull());
-	llassert(discard_level >= 0);
-	llassert(mComponents > 0);
+            desired_discard = llmin(desired_discard, entryp->mDesiredDiscard);
+            if(entryp->mNeedsImageRaw)
+            {
+                desired_raw_discard = llmin(desired_raw_discard, entryp->mDesiredDiscard);
+            }
+        }
+    }
 
-	if (mRawImage.notNull())
-	{
-		//mRawImage is in use by somebody else, do not delete it.
-		return NULL;
-	}
+    mLoadedCallbackDesiredDiscardLevel = desired_discard;
+    if (mLoadedCallbackList.empty())
+    {
+        // If we have no callbacks, take us off of the image callback list.
+        gTextureList.mCallbackList.erase(this);
 
-	if(mSavedRawDiscardLevel >= 0 && mSavedRawDiscardLevel <= discard_level)
-	{
-		if (mSavedRawDiscardLevel != discard_level
+        if(needsToSaveRawImage())
+        {
+            destroySavedRawImage();
+        }
+    }
+    else if(needsToSaveRawImage() && mBoostLevel != LLGLTexture::BOOST_PREVIEW)
+    {
+        if(desired_raw_discard != INVALID_DISCARD_LEVEL)
+        {
+            mDesiredSavedRawDiscardLevel = desired_raw_discard;
+        }
+        else
+        {
+            destroySavedRawImage();
+        }
+    }
+}
+
+void LLViewerFetchedTexture::unpauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list)
+{
+    if(!callback_list)
+{
+        mPauseLoadedCallBacks = FALSE;
+        return;
+    }
+
+    BOOL need_raw = FALSE;
+    for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+            iter != mLoadedCallbackList.end(); )
+    {
+        LLLoadedCallbackEntry *entryp = *iter++;
+        if(entryp->mSourceCallbackList == callback_list)
+        {
+            entryp->mPaused = FALSE;
+            if(entryp->mNeedsImageRaw)
+            {
+                need_raw = TRUE;
+            }
+        }
+    }
+    mPauseLoadedCallBacks = FALSE ;
+    mLastCallBackActiveTime = sCurrentTime ;
+    mForceCallbackFetch = TRUE;
+    if(need_raw)
+    {
+        mSaveRawImage = TRUE;
+    }
+}
+
+void LLViewerFetchedTexture::pauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list)
+{
+    if(!callback_list)
+{
+        return;
+    }
+
+    bool paused = true;
+
+    for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+            iter != mLoadedCallbackList.end(); )
+    {
+        LLLoadedCallbackEntry *entryp = *iter++;
+        if(entryp->mSourceCallbackList == callback_list)
+        {
+            entryp->mPaused = TRUE;
+        }
+        else if(!entryp->mPaused)
+        {
+            paused = false;
+        }
+    }
+
+    if(paused)
+    {
+        mPauseLoadedCallBacks = TRUE;//when set, loaded callback is paused.
+        resetTextureStats();
+        mSaveRawImage = FALSE;
+    }
+}
+
+bool LLViewerFetchedTexture::doLoadedCallbacks()
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
+    static const F32 MAX_INACTIVE_TIME = 900.f ; //seconds
+    static const F32 MAX_IDLE_WAIT_TIME = 5.f ; //seconds
+
+    if (mNeedsCreateTexture)
+    {
+        return false;
+    }
+    if(mPauseLoadedCallBacks)
+    {
+        destroyRawImage();
+        return false; //paused
+    }
+    if(sCurrentTime - mLastCallBackActiveTime > MAX_INACTIVE_TIME && !mIsFetching)
+    {
+        if (mFTType == FTT_SERVER_BAKE)
+        {
+            //output some debug info
+            LL_INFOS() << "baked texture: " << mID << "clears all call backs due to inactivity." << LL_ENDL;
+            LL_INFOS() << mUrl << LL_ENDL;
+            LL_INFOS() << "current discard: " << getDiscardLevel() << " current discard for fetch: " << getCurrentDiscardLevelForFetching() <<
+                " Desired discard: " << getDesiredDiscardLevel() << "decode Pri: " << mMaxVirtualSize << LL_ENDL;
+        }
+
+        clearCallbackEntryList() ; //remove all callbacks.
+        return false ;
+    }
+
+    bool res = false;
+
+    if (isMissingAsset())
+    {
+        if (mFTType == FTT_SERVER_BAKE)
+        {
+            //output some debug info
+            LL_INFOS() << "baked texture: " << mID << "is missing." << LL_ENDL;
+            LL_INFOS() << mUrl << LL_ENDL;
+        }
+
+        for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+            iter != mLoadedCallbackList.end(); )
+        {
+            LLLoadedCallbackEntry *entryp = *iter++;
+            // We never finished loading the image.  Indicate failure.
+            // Note: this allows mLoadedCallbackUserData to be cleaned up.
+            entryp->mCallback(FALSE, this, NULL, NULL, 0, TRUE, entryp->mUserData);
+            delete entryp;
+        }
+        mLoadedCallbackList.clear();
+
+        // Remove ourself from the global list of textures with callbacks
+        gTextureList.mCallbackList.erase(this);
+        return false;
+    }
+
+    S32 gl_discard = getDiscardLevel();
+
+    // If we don't have a legit GL image, set it to be lower than the worst discard level
+    if (gl_discard == -1)
+    {
+        gl_discard = MAX_DISCARD_LEVEL + 1;
+    }
+
+    //
+    // Determine the quality levels of textures that we can provide to callbacks
+    // and whether we need to do decompression/readback to get it
+    //
+    S32 current_raw_discard = MAX_DISCARD_LEVEL + 1; // We can always do a readback to get a raw discard
+    S32 best_raw_discard = gl_discard;  // Current GL quality level
+    S32 current_aux_discard = MAX_DISCARD_LEVEL + 1;
+    S32 best_aux_discard = MAX_DISCARD_LEVEL + 1;
+
+    if (mIsRawImageValid)
+    {
+        // If we have an existing raw image, we have a baseline for the raw and auxiliary quality levels.
+        best_raw_discard = llmin(best_raw_discard, mRawDiscardLevel);
+        best_aux_discard = llmin(best_aux_discard, mRawDiscardLevel); // We always decode the aux when we decode the base raw
+        current_aux_discard = llmin(current_aux_discard, best_aux_discard);
+    }
+    else
+    {
+        // We have no data at all, we need to get it
+        // Do this by forcing the best aux discard to be 0.
+        best_aux_discard = 0;
+    }
+
+
+    //
+    // See if any of the callbacks would actually run using the data that we can provide,
+    // and also determine if we need to perform any readbacks or decodes.
+    //
+    bool run_gl_callbacks = false;
+    bool run_raw_callbacks = false;
+    bool need_readback = false;
+
+    for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+        iter != mLoadedCallbackList.end(); )
+    {
+        LLLoadedCallbackEntry *entryp = *iter++;
+
+        if (entryp->mNeedsImageRaw)
+        {
+            if (mNeedsAux)
+            {
+                //
+                // Need raw and auxiliary channels
+                //
+                if (entryp->mLastUsedDiscard > current_aux_discard)
+                {
+                    // We have useful data, run the callbacks
+                    run_raw_callbacks = true;
+                }
+            }
+            else
+            {
+                if (entryp->mLastUsedDiscard > current_raw_discard)
+                {
+                    // We have useful data, just run the callbacks
+                    run_raw_callbacks = true;
+                }
+                else if (entryp->mLastUsedDiscard > best_raw_discard)
+                {
+                    // We can readback data, and then run the callbacks
+                    need_readback = true;
+                    run_raw_callbacks = true;
+                }
+            }
+        }
+        else
+        {
+            // Needs just GL
+            if (entryp->mLastUsedDiscard > gl_discard)
+            {
+                // We have enough data, run this callback requiring GL data
+                run_gl_callbacks = true;
+            }
+        }
+    }
+
+    //
+    // Do a readback if required, OR start off a texture decode
+    //
+    if (need_readback && (getMaxDiscardLevel() > gl_discard))
+    {
+        // Do a readback to get the GL data into the raw image
+        // We have GL data.
+
+        destroyRawImage();
+        reloadRawImage(mLoadedCallbackDesiredDiscardLevel);
+        llassert(mRawImage.notNull());
+        llassert(!mNeedsAux || mAuxRawImage.notNull());
+    }
+
+    //
+    // Run raw/auxiliary data callbacks
+    //
+    if (run_raw_callbacks && mIsRawImageValid && (mRawDiscardLevel <= getMaxDiscardLevel()))
+    {
+        // Do callbacks which require raw image data.
+        //LL_INFOS() << "doLoadedCallbacks raw for " << getID() << LL_ENDL;
+
+        // Call each party interested in the raw data.
+        for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+            iter != mLoadedCallbackList.end(); )
+        {
+            callback_list_t::iterator curiter = iter++;
+            LLLoadedCallbackEntry *entryp = *curiter;
+            if (entryp->mNeedsImageRaw && (entryp->mLastUsedDiscard > mRawDiscardLevel))
+            {
+                // If we've loaded all the data there is to load or we've loaded enough
+                // to satisfy the interested party, then this is the last time that
+                // we're going to call them.
+
+                mLastCallBackActiveTime = sCurrentTime;
+                if(mNeedsAux && mAuxRawImage.isNull())
+                {
+                    LL_WARNS() << "Raw Image with no Aux Data for callback" << LL_ENDL;
+                }
+                BOOL final = mRawDiscardLevel <= entryp->mDesiredDiscard ? TRUE : FALSE;
+                //LL_INFOS() << "Running callback for " << getID() << LL_ENDL;
+                //LL_INFOS() << mRawImage->getWidth() << "x" << mRawImage->getHeight() << LL_ENDL;
+                entryp->mLastUsedDiscard = mRawDiscardLevel;
+                entryp->mCallback(TRUE, this, mRawImage, mAuxRawImage, mRawDiscardLevel, final, entryp->mUserData);
+                if (final)
+                {
+                    iter = mLoadedCallbackList.erase(curiter);
+                    delete entryp;
+                }
+                res = true;
+            }
+        }
+    }
+
+    //
+    // Run GL callbacks
+    //
+    if (run_gl_callbacks && (gl_discard <= getMaxDiscardLevel()))
+    {
+        //LL_INFOS() << "doLoadedCallbacks GL for " << getID() << LL_ENDL;
+
+        // Call the callbacks interested in GL data.
+        for(callback_list_t::iterator iter = mLoadedCallbackList.begin();
+            iter != mLoadedCallbackList.end(); )
+        {
+            callback_list_t::iterator curiter = iter++;
+            LLLoadedCallbackEntry *entryp = *curiter;
+            if (!entryp->mNeedsImageRaw && (entryp->mLastUsedDiscard > gl_discard))
+            {
+                mLastCallBackActiveTime = sCurrentTime;
+                BOOL final = gl_discard <= entryp->mDesiredDiscard ? TRUE : FALSE;
+                entryp->mLastUsedDiscard = gl_discard;
+                entryp->mCallback(TRUE, this, NULL, NULL, gl_discard, final, entryp->mUserData);
+                if (final)
+                {
+                    iter = mLoadedCallbackList.erase(curiter);
+                    delete entryp;
+                }
+                res = true;
+            }
+        }
+    }
+
+    // Done with any raw image data at this point (will be re-created if we still have callbacks)
+    destroyRawImage();
+
+    //
+    // If we have no callbacks, take us off of the image callback list.
+    //
+    if (mLoadedCallbackList.empty())
+    {
+        gTextureList.mCallbackList.erase(this);
+    }
+    else if(!res && mForceCallbackFetch && sCurrentTime - mLastCallBackActiveTime > MAX_IDLE_WAIT_TIME && !mIsFetching)
+    {
+        //wait for long enough but no fetching request issued, force one.
+        forceToRefetchTexture(mLoadedCallbackDesiredDiscardLevel, 5.f);
+        mForceCallbackFetch = FALSE; //fire once.
+    }
+
+    return res;
+}
+
+//virtual
+void LLViewerFetchedTexture::forceImmediateUpdate()
+{
+    //only immediately update a deleted texture which is now being re-used.
+    if(!isDeleted())
+    {
+        return;
+    }
+    //if already called forceImmediateUpdate()
+    if(mInImageList && mMaxVirtualSize == LLViewerFetchedTexture::sMaxVirtualSize)
+    {
+        return;
+    }
+
+    gTextureList.forceImmediateUpdate(this);
+    return;
+}
+
+LLImageRaw* LLViewerFetchedTexture::reloadRawImage(S8 discard_level)
+{
+    llassert(mGLTexturep.notNull());
+    llassert(discard_level >= 0);
+    llassert(mComponents > 0);
+
+    if (mRawImage.notNull())
+    {
+        //mRawImage is in use by somebody else, do not delete it.
+        return NULL;
+    }
+
+    if(mSavedRawDiscardLevel >= 0 && mSavedRawDiscardLevel <= discard_level)
+    {
+        if (mSavedRawDiscardLevel != discard_level
             && mBoostLevel != BOOST_ICON
             && mBoostLevel != BOOST_THUMBNAIL)
-		{
-			mRawImage = new LLImageRaw(getWidth(discard_level), getHeight(discard_level), getComponents());
-			mRawImage->copy(getSavedRawImage());
-		}
-		else
-		{
-			mRawImage = getSavedRawImage();
-		}
-		mRawDiscardLevel = discard_level;
-	}
-	else
-	{		
-		//force to fetch raw image again if cached raw image is not good enough.
-		if(mCachedRawDiscardLevel > discard_level)
-		{
-			mRawImage = mCachedRawImage;
-			mRawDiscardLevel = mCachedRawDiscardLevel;
-		}
-		else //cached raw image is good enough, copy it.
-		{
-			if(mCachedRawDiscardLevel != discard_level)
-			{
-				mRawImage = new LLImageRaw(getWidth(discard_level), getHeight(discard_level), getComponents());
-				mRawImage->copy(mCachedRawImage);
-			}
-			else
-			{
-				mRawImage = mCachedRawImage;
-			}
-			mRawDiscardLevel = discard_level;
-		}
-	}
-	mIsRawImageValid = TRUE;
-	sRawCount++;	
-	
-	return mRawImage;
+        {
+            mRawImage = new LLImageRaw(getWidth(discard_level), getHeight(discard_level), getComponents());
+            mRawImage->copy(getSavedRawImage());
+        }
+        else
+        {
+            mRawImage = getSavedRawImage();
+        }
+        mRawDiscardLevel = discard_level;
+    }
+    else
+    {
+        //force to fetch raw image again if cached raw image is not good enough.
+        if(mCachedRawDiscardLevel > discard_level)
+        {
+            mRawImage = mCachedRawImage;
+            mRawDiscardLevel = mCachedRawDiscardLevel;
+        }
+        else //cached raw image is good enough, copy it.
+        {
+            if(mCachedRawDiscardLevel != discard_level)
+            {
+                mRawImage = new LLImageRaw(getWidth(discard_level), getHeight(discard_level), getComponents());
+                mRawImage->copy(mCachedRawImage);
+            }
+            else
+            {
+                mRawImage = mCachedRawImage;
+            }
+            mRawDiscardLevel = discard_level;
+        }
+    }
+    mIsRawImageValid = TRUE;
+    sRawCount++;
+
+    return mRawImage;
 }
 
 bool LLViewerFetchedTexture::needsToSaveRawImage()
 {
-	return mForceToSaveRawImage || mSaveRawImage;
+    return mForceToSaveRawImage || mSaveRawImage;
 }
 
 void LLViewerFetchedTexture::destroyRawImage()
-{	
+{
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if (mAuxRawImage.notNull() && !needsToSaveRawImage())
-	{
-		sAuxCount--;
-		mAuxRawImage = NULL;
-	}
-
-	if (mRawImage.notNull()) 
-	{
-		sRawCount--;		
-
-		if(mIsRawImageValid)
-		{
-			if(needsToSaveRawImage())
-			{
-				saveRawImage();
-			}		
-			setCachedRawImage();
-		}
-		
-		mRawImage = NULL;
-	
-		mIsRawImageValid = FALSE;
-		mRawDiscardLevel = INVALID_DISCARD_LEVEL;
-	}
+    if (mAuxRawImage.notNull() && !needsToSaveRawImage())
+    {
+        sAuxCount--;
+        mAuxRawImage = NULL;
+    }
+
+    if (mRawImage.notNull())
+    {
+        sRawCount--;
+
+        if(mIsRawImageValid)
+        {
+            if(needsToSaveRawImage())
+            {
+                saveRawImage();
+            }
+            setCachedRawImage();
+        }
+
+        mRawImage = NULL;
+
+        mIsRawImageValid = FALSE;
+        mRawDiscardLevel = INVALID_DISCARD_LEVEL;
+    }
 }
 
 //use the mCachedRawImage to (re)generate the gl texture.
@@ -2852,32 +2852,32 @@ void LLViewerFetchedTexture::destroyRawImage()
 void LLViewerFetchedTexture::switchToCachedImage()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if(mCachedRawImage.notNull() && 
+    if(mCachedRawImage.notNull() &&
         !mNeedsCreateTexture) // <--- texture creation is pending, don't step on it
-	{
-		mRawImage = mCachedRawImage;
-						
-		if (getComponents() != mRawImage->getComponents())
-		{
-			// We've changed the number of components, so we need to move any
-			// objects using this pool to a different pool.
-			mComponents = mRawImage->getComponents();
-			mGLTexturep->setComponents(mComponents);
-			gTextureList.dirtyImage(this);
-		}
-
-		mIsRawImageValid = TRUE;
-		mRawDiscardLevel = mCachedRawDiscardLevel;
+    {
+        mRawImage = mCachedRawImage;
+
+        if (getComponents() != mRawImage->getComponents())
+        {
+            // We've changed the number of components, so we need to move any
+            // objects using this pool to a different pool.
+            mComponents = mRawImage->getComponents();
+            mGLTexturep->setComponents(mComponents);
+            gTextureList.dirtyImage(this);
+        }
+
+        mIsRawImageValid = TRUE;
+        mRawDiscardLevel = mCachedRawDiscardLevel;
 
         scheduleCreateTexture();
-	}
+    }
 }
 
 //cache the imageraw forcefully.
-//virtual 
-void LLViewerFetchedTexture::setCachedRawImage(S32 discard_level, LLImageRaw* imageraw) 
+//virtual
+void LLViewerFetchedTexture::setCachedRawImage(S32 discard_level, LLImageRaw* imageraw)
 {
-	if(imageraw != mRawImage.get())
+    if(imageraw != mRawImage.get())
     {
         if (mBoostLevel == LLGLTexture::BOOST_ICON)
         {
@@ -2911,122 +2911,122 @@ void LLViewerFetchedTexture::setCachedRawImage(S32 discard_level, LLImageRaw* im
         {
             mCachedRawImage = imageraw;
         }
-		mCachedRawDiscardLevel = discard_level;
-		mCachedRawImageReady = TRUE;
-	}
+        mCachedRawDiscardLevel = discard_level;
+        mCachedRawImageReady = TRUE;
+    }
 }
 
 void LLViewerFetchedTexture::setCachedRawImage()
-{	
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if(mRawImage == mCachedRawImage)
-	{
-		return;
-	}
-	if(!mIsRawImageValid)
-	{
-		return;
-	}
-
-	if(mCachedRawImageReady)
-	{
-		return;
-	}
-
-	if(mCachedRawDiscardLevel < 0 || mCachedRawDiscardLevel > mRawDiscardLevel)
-	{
-		S32 i = 0;
-		S32 w = mRawImage->getWidth();
-		S32 h = mRawImage->getHeight();
-
-		S32 max_size = MAX_CACHED_RAW_IMAGE_AREA;
-		if(LLGLTexture::BOOST_TERRAIN == mBoostLevel)
-		{
-			max_size = MAX_CACHED_RAW_TERRAIN_IMAGE_AREA;
-		}		
-		if(mForSculpt)
-		{
-			max_size = MAX_CACHED_RAW_SCULPT_IMAGE_AREA;
-			mCachedRawImageReady = !mRawDiscardLevel;
-		}
-		else
-		{
-			mCachedRawImageReady = (!mRawDiscardLevel || ((w * h) >= max_size));
-		}
-
-		while(((w >> i) * (h >> i)) > max_size)
-		{
-			++i;
-		}
-		
-		if(i)
-		{
-			if(!(w >> i) || !(h >> i))
-			{
-				--i;
-			}
-			
-			{
-				//make a duplicate in case somebody else is using this raw image
-				mRawImage = mRawImage->scaled(w >> i, h >> i);
-			}
-		}
-		mCachedRawImage = mRawImage;
-		mRawDiscardLevel += i;
-		mCachedRawDiscardLevel = mRawDiscardLevel;			
-	}
-}
-
-void LLViewerFetchedTexture::checkCachedRawSculptImage()
-{
-	if(mCachedRawImageReady && mCachedRawDiscardLevel > 0)
-	{
-		if(getDiscardLevel() != 0)
-		{
-			mCachedRawImageReady = FALSE;
-		}
-		else if(isForSculptOnly())
-		{
-			resetTextureStats(); //do not update this image any more.
-		}
-	}
-}
-
-void LLViewerFetchedTexture::saveRawImage() 
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	if(mRawImage.isNull() || mRawImage == mSavedRawImage || (mSavedRawDiscardLevel >= 0 && mSavedRawDiscardLevel <= mRawDiscardLevel))
-	{
-		return;
-	}
+    if(mRawImage == mCachedRawImage)
+    {
+        return;
+    }
+    if(!mIsRawImageValid)
+    {
+        return;
+    }
 
-	mSavedRawDiscardLevel = mRawDiscardLevel;
-    if (mBoostLevel == LLGLTexture::BOOST_ICON)
+    if(mCachedRawImageReady)
     {
-        S32 expected_width = mKnownDrawWidth > 0 ? mKnownDrawWidth : DEFAULT_ICON_DIMENSIONS;
-        S32 expected_height = mKnownDrawHeight > 0 ? mKnownDrawHeight : DEFAULT_ICON_DIMENSIONS;
-        if (mRawImage->getWidth() > expected_width || mRawImage->getHeight() > expected_height)
+        return;
+    }
+
+    if(mCachedRawDiscardLevel < 0 || mCachedRawDiscardLevel > mRawDiscardLevel)
+    {
+        S32 i = 0;
+        S32 w = mRawImage->getWidth();
+        S32 h = mRawImage->getHeight();
+
+        S32 max_size = MAX_CACHED_RAW_IMAGE_AREA;
+        if(LLGLTexture::BOOST_TERRAIN == mBoostLevel)
         {
-            mSavedRawImage = new LLImageRaw(expected_width, expected_height, mRawImage->getComponents());
-            mSavedRawImage->copyScaled(mRawImage);
+            max_size = MAX_CACHED_RAW_TERRAIN_IMAGE_AREA;
         }
-        else
+        if(mForSculpt)
         {
-            mSavedRawImage = new LLImageRaw(mRawImage->getData(), mRawImage->getWidth(), mRawImage->getHeight(), mRawImage->getComponents());
+            max_size = MAX_CACHED_RAW_SCULPT_IMAGE_AREA;
+            mCachedRawImageReady = !mRawDiscardLevel;
         }
-    }
-    else if (mBoostLevel == LLGLTexture::BOOST_THUMBNAIL)
-    {
-        S32 expected_width = mKnownDrawWidth > 0 ? mKnownDrawWidth : DEFAULT_THUMBNAIL_DIMENSIONS;
-        S32 expected_height = mKnownDrawHeight > 0 ? mKnownDrawHeight : DEFAULT_THUMBNAIL_DIMENSIONS;
-        if (mRawImage->getWidth() > expected_width || mRawImage->getHeight() > expected_height)
+        else
         {
-            mSavedRawImage = new LLImageRaw(expected_width, expected_height, mRawImage->getComponents());
-            mSavedRawImage->copyScaled(mRawImage);
+            mCachedRawImageReady = (!mRawDiscardLevel || ((w * h) >= max_size));
         }
-        else
+
+        while(((w >> i) * (h >> i)) > max_size)
         {
-            mSavedRawImage = new LLImageRaw(mRawImage->getData(), mRawImage->getWidth(), mRawImage->getHeight(), mRawImage->getComponents());
+            ++i;
+        }
+
+        if(i)
+        {
+            if(!(w >> i) || !(h >> i))
+            {
+                --i;
+            }
+
+            {
+                //make a duplicate in case somebody else is using this raw image
+                mRawImage = mRawImage->scaled(w >> i, h >> i);
+            }
+        }
+        mCachedRawImage = mRawImage;
+        mRawDiscardLevel += i;
+        mCachedRawDiscardLevel = mRawDiscardLevel;
+    }
+}
+
+void LLViewerFetchedTexture::checkCachedRawSculptImage()
+{
+    if(mCachedRawImageReady && mCachedRawDiscardLevel > 0)
+    {
+        if(getDiscardLevel() != 0)
+        {
+            mCachedRawImageReady = FALSE;
+        }
+        else if(isForSculptOnly())
+        {
+            resetTextureStats(); //do not update this image any more.
+        }
+    }
+}
+
+void LLViewerFetchedTexture::saveRawImage()
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
+    if(mRawImage.isNull() || mRawImage == mSavedRawImage || (mSavedRawDiscardLevel >= 0 && mSavedRawDiscardLevel <= mRawDiscardLevel))
+    {
+        return;
+    }
+
+    mSavedRawDiscardLevel = mRawDiscardLevel;
+    if (mBoostLevel == LLGLTexture::BOOST_ICON)
+    {
+        S32 expected_width = mKnownDrawWidth > 0 ? mKnownDrawWidth : DEFAULT_ICON_DIMENSIONS;
+        S32 expected_height = mKnownDrawHeight > 0 ? mKnownDrawHeight : DEFAULT_ICON_DIMENSIONS;
+        if (mRawImage->getWidth() > expected_width || mRawImage->getHeight() > expected_height)
+        {
+            mSavedRawImage = new LLImageRaw(expected_width, expected_height, mRawImage->getComponents());
+            mSavedRawImage->copyScaled(mRawImage);
+        }
+        else
+        {
+            mSavedRawImage = new LLImageRaw(mRawImage->getData(), mRawImage->getWidth(), mRawImage->getHeight(), mRawImage->getComponents());
+        }
+    }
+    else if (mBoostLevel == LLGLTexture::BOOST_THUMBNAIL)
+    {
+        S32 expected_width = mKnownDrawWidth > 0 ? mKnownDrawWidth : DEFAULT_THUMBNAIL_DIMENSIONS;
+        S32 expected_height = mKnownDrawHeight > 0 ? mKnownDrawHeight : DEFAULT_THUMBNAIL_DIMENSIONS;
+        if (mRawImage->getWidth() > expected_width || mRawImage->getHeight() > expected_height)
+        {
+            mSavedRawImage = new LLImageRaw(expected_width, expected_height, mRawImage->getComponents());
+            mSavedRawImage->copyScaled(mRawImage);
+        }
+        else
+        {
+            mSavedRawImage = new LLImageRaw(mRawImage->getData(), mRawImage->getWidth(), mRawImage->getHeight(), mRawImage->getComponents());
         }
     }
     else
@@ -3034,125 +3034,125 @@ void LLViewerFetchedTexture::saveRawImage()
         mSavedRawImage = new LLImageRaw(mRawImage->getData(), mRawImage->getWidth(), mRawImage->getHeight(), mRawImage->getComponents());
     }
 
-	if(mForceToSaveRawImage && mSavedRawDiscardLevel <= mDesiredSavedRawDiscardLevel)
-	{
-		mForceToSaveRawImage = FALSE;
-	}
+    if(mForceToSaveRawImage && mSavedRawDiscardLevel <= mDesiredSavedRawDiscardLevel)
+    {
+        mForceToSaveRawImage = FALSE;
+    }
 
-	mLastReferencedSavedRawImageTime = sCurrentTime;
+    mLastReferencedSavedRawImageTime = sCurrentTime;
 }
 
-//force to refetch the texture to the discard level 
+//force to refetch the texture to the discard level
 void LLViewerFetchedTexture::forceToRefetchTexture(S32 desired_discard, F32 kept_time)
 {
-	if(mForceToSaveRawImage)
-	{
-		desired_discard = llmin(desired_discard, mDesiredSavedRawDiscardLevel);
-		kept_time = llmax(kept_time, mKeptSavedRawImageTime);
-	}
-
-	//trigger a new fetch.
-	mForceToSaveRawImage = TRUE ;
-	mDesiredSavedRawDiscardLevel = desired_discard ;
-	mKeptSavedRawImageTime = kept_time ;
-	mLastReferencedSavedRawImageTime = sCurrentTime ;
-	mSavedRawImage = NULL ;
-	mSavedRawDiscardLevel = -1 ;
-}
-
-void LLViewerFetchedTexture::forceToSaveRawImage(S32 desired_discard, F32 kept_time) 
-{ 
-	mKeptSavedRawImageTime = kept_time;
-	mLastReferencedSavedRawImageTime = sCurrentTime;
-
-	if(mSavedRawDiscardLevel > -1 && mSavedRawDiscardLevel <= desired_discard)
-	{
-		return; //raw imge is ready.
-	}
-
-	if(!mForceToSaveRawImage || mDesiredSavedRawDiscardLevel < 0 || mDesiredSavedRawDiscardLevel > desired_discard)
-	{
-		mForceToSaveRawImage = TRUE;
-		mDesiredSavedRawDiscardLevel = desired_discard;
-	
-		//copy from the cached raw image if exists.
-		if(mCachedRawImage.notNull() && mRawImage.isNull() )
-		{
-			mRawImage = mCachedRawImage;
-			mRawDiscardLevel = mCachedRawDiscardLevel;
-
-			saveRawImage();
-
-			mRawImage = NULL;
-			mRawDiscardLevel = INVALID_DISCARD_LEVEL;
-		}		
-	}
+    if(mForceToSaveRawImage)
+    {
+        desired_discard = llmin(desired_discard, mDesiredSavedRawDiscardLevel);
+        kept_time = llmax(kept_time, mKeptSavedRawImageTime);
+    }
+
+    //trigger a new fetch.
+    mForceToSaveRawImage = TRUE ;
+    mDesiredSavedRawDiscardLevel = desired_discard ;
+    mKeptSavedRawImageTime = kept_time ;
+    mLastReferencedSavedRawImageTime = sCurrentTime ;
+    mSavedRawImage = NULL ;
+    mSavedRawDiscardLevel = -1 ;
+}
+
+void LLViewerFetchedTexture::forceToSaveRawImage(S32 desired_discard, F32 kept_time)
+{
+    mKeptSavedRawImageTime = kept_time;
+    mLastReferencedSavedRawImageTime = sCurrentTime;
+
+    if(mSavedRawDiscardLevel > -1 && mSavedRawDiscardLevel <= desired_discard)
+    {
+        return; //raw imge is ready.
+    }
+
+    if(!mForceToSaveRawImage || mDesiredSavedRawDiscardLevel < 0 || mDesiredSavedRawDiscardLevel > desired_discard)
+    {
+        mForceToSaveRawImage = TRUE;
+        mDesiredSavedRawDiscardLevel = desired_discard;
+
+        //copy from the cached raw image if exists.
+        if(mCachedRawImage.notNull() && mRawImage.isNull() )
+        {
+            mRawImage = mCachedRawImage;
+            mRawDiscardLevel = mCachedRawDiscardLevel;
+
+            saveRawImage();
+
+            mRawImage = NULL;
+            mRawDiscardLevel = INVALID_DISCARD_LEVEL;
+        }
+    }
 }
 void LLViewerFetchedTexture::destroySavedRawImage()
 {
-	if(mLastReferencedSavedRawImageTime < mKeptSavedRawImageTime)
-	{
-		return; //keep the saved raw image.
-	}
+    if(mLastReferencedSavedRawImageTime < mKeptSavedRawImageTime)
+    {
+        return; //keep the saved raw image.
+    }
+
+    mForceToSaveRawImage  = FALSE;
+    mSaveRawImage = FALSE;
+
+    clearCallbackEntryList();
 
-	mForceToSaveRawImage  = FALSE;
-	mSaveRawImage = FALSE;
+    mSavedRawImage = NULL ;
+    mForceToSaveRawImage  = FALSE ;
+    mSaveRawImage = FALSE ;
+    mSavedRawDiscardLevel = -1 ;
+    mDesiredSavedRawDiscardLevel = -1 ;
+    mLastReferencedSavedRawImageTime = 0.0f ;
+    mKeptSavedRawImageTime = 0.f ;
 
-	clearCallbackEntryList();
-	
-	mSavedRawImage = NULL ;
-	mForceToSaveRawImage  = FALSE ;
-	mSaveRawImage = FALSE ;
-	mSavedRawDiscardLevel = -1 ;
-	mDesiredSavedRawDiscardLevel = -1 ;
-	mLastReferencedSavedRawImageTime = 0.0f ;
-	mKeptSavedRawImageTime = 0.f ;
-	
-	if(mAuxRawImage.notNull())
-	{
-		sAuxCount--;
-		mAuxRawImage = NULL;
-	}
+    if(mAuxRawImage.notNull())
+    {
+        sAuxCount--;
+        mAuxRawImage = NULL;
+    }
 }
 
-LLImageRaw* LLViewerFetchedTexture::getSavedRawImage() 
+LLImageRaw* LLViewerFetchedTexture::getSavedRawImage()
 {
-	mLastReferencedSavedRawImageTime = sCurrentTime;
+    mLastReferencedSavedRawImageTime = sCurrentTime;
 
-	return mSavedRawImage;
+    return mSavedRawImage;
 }
-	
+
 BOOL LLViewerFetchedTexture::hasSavedRawImage() const
 {
-	return mSavedRawImage.notNull();
+    return mSavedRawImage.notNull();
 }
-	
+
 F32 LLViewerFetchedTexture::getElapsedLastReferencedSavedRawImageTime() const
-{ 
-	return sCurrentTime - mLastReferencedSavedRawImageTime;
+{
+    return sCurrentTime - mLastReferencedSavedRawImageTime;
 }
 
 LLUUID LLViewerFetchedTexture::getUploader()
 {
-	return (mComment.find('a') != mComment.end()) ? LLUUID(mComment['a']) : LLUUID::null;
+    return (mComment.find('a') != mComment.end()) ? LLUUID(mComment['a']) : LLUUID::null;
 }
 
 LLDate LLViewerFetchedTexture::getUploadTime()
 {
-	if (mComment.find('z') != mComment.end())
-	{
-		struct tm t = {};
-		sscanf(mComment['z'].c_str(), "%4d%2d%2d%2d%2d%2d",
-			   &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec);
-		std::string iso_date = llformat("%d-%d-%dT%d:%d:%dZ", t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
-		return LLDate(iso_date);
-	}
-	return LLDate();
+    if (mComment.find('z') != mComment.end())
+    {
+        struct tm t = {};
+        sscanf(mComment['z'].c_str(), "%4d%2d%2d%2d%2d%2d",
+               &t.tm_year, &t.tm_mon, &t.tm_mday, &t.tm_hour, &t.tm_min, &t.tm_sec);
+        std::string iso_date = llformat("%d-%d-%dT%d:%d:%dZ", t.tm_year, t.tm_mon, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec);
+        return LLDate(iso_date);
+    }
+    return LLDate();
 }
 
 std::string LLViewerFetchedTexture::getComment()
 {
-	return (mComment.find('K') != mComment.end()) ? mComment['K'] : LLStringUtil::null;
+    return (mComment.find('K') != mComment.end()) ? mComment['K'] : LLStringUtil::null;
 }
 
 //----------------------------------------------------------------------------------------------
@@ -3163,33 +3163,33 @@ std::string LLViewerFetchedTexture::getComment()
 //start of LLViewerLODTexture
 //----------------------------------------------------------------------------------------------
 LLViewerLODTexture::LLViewerLODTexture(const LLUUID& id, FTType f_type, const LLHost& host, BOOL usemipmaps)
-	: LLViewerFetchedTexture(id, f_type, host, usemipmaps)
+    : LLViewerFetchedTexture(id, f_type, host, usemipmaps)
 {
-	init(TRUE);
+    init(TRUE);
 }
 
 LLViewerLODTexture::LLViewerLODTexture(const std::string& url, FTType f_type, const LLUUID& id, BOOL usemipmaps)
-	: LLViewerFetchedTexture(url, f_type, id, usemipmaps)
+    : LLViewerFetchedTexture(url, f_type, id, usemipmaps)
 {
-	init(TRUE);
+    init(TRUE);
 }
 
 void LLViewerLODTexture::init(bool firstinit)
 {
-	mTexelsPerImage = 64.f*64.f;
-	mDiscardVirtualSize = 0.f;
-	mCalculatedDiscardLevel = -1.f;
+    mTexelsPerImage = 64.f*64.f;
+    mDiscardVirtualSize = 0.f;
+    mCalculatedDiscardLevel = -1.f;
 }
 
-//virtual 
+//virtual
 S8 LLViewerLODTexture::getType() const
 {
-	return LLViewerTexture::LOD_TEXTURE;
+    return LLViewerTexture::LOD_TEXTURE;
 }
 
 bool LLViewerLODTexture::isUpdateFrozen()
 {
-	return LLViewerTexture::sFreezeImageUpdates;
+    return LLViewerTexture::sFreezeImageUpdates;
 }
 
 // This is gauranteed to get called periodically for every texture
@@ -3197,9 +3197,9 @@ bool LLViewerLODTexture::isUpdateFrozen()
 void LLViewerLODTexture::processTextureStats()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	updateVirtualSize();
-	
-	static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes", false);
+    updateVirtualSize();
+
+    static LLCachedControl<bool> textures_fullres(gSavedSettings,"TextureLoadFullRes", false);
 
     { // restrict texture resolution to download based on RenderMaxTextureResolution
         static LLCachedControl<U32> max_texture_resolution(gSavedSettings, "RenderMaxTextureResolution", 2048);
@@ -3208,1100 +3208,1100 @@ void LLViewerLODTexture::processTextureStats()
         tex_res *= tex_res;
         mMaxVirtualSize = llmin(mMaxVirtualSize, tex_res);
     }
-
-	if (textures_fullres)
-	{
-		mDesiredDiscardLevel = 0;
-	}
-	// Generate the request priority and render priority
-	else if (mDontDiscard || !mUseMipMaps)
-	{
-		mDesiredDiscardLevel = 0;
-		if (mFullWidth > MAX_IMAGE_SIZE_DEFAULT || mFullHeight > MAX_IMAGE_SIZE_DEFAULT)
-			mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
-	}
-	else if (mBoostLevel < LLGLTexture::BOOST_HIGH && mMaxVirtualSize <= 10.f)
-	{
-		// If the image has not been significantly visible in a while, we don't want it
-		mDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel, (S8)(MAX_DISCARD_LEVEL + 1));
-	}
-	else if (!mFullWidth  || !mFullHeight)
-	{
-		mDesiredDiscardLevel = 	getMaxDiscardLevel();
-	}
-    else
+
+    if (textures_fullres)
+    {
+        mDesiredDiscardLevel = 0;
+    }
+    // Generate the request priority and render priority
+    else if (mDontDiscard || !mUseMipMaps)
+    {
+        mDesiredDiscardLevel = 0;
+        if (mFullWidth > MAX_IMAGE_SIZE_DEFAULT || mFullHeight > MAX_IMAGE_SIZE_DEFAULT)
+            mDesiredDiscardLevel = 1; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
+    }
+    else if (mBoostLevel < LLGLTexture::BOOST_HIGH && mMaxVirtualSize <= 10.f)
+    {
+        // If the image has not been significantly visible in a while, we don't want it
+        mDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel, (S8)(MAX_DISCARD_LEVEL + 1));
+    }
+    else if (!mFullWidth  || !mFullHeight)
+    {
+        mDesiredDiscardLevel =  getMaxDiscardLevel();
+    }
+    else
+    {
+        //static const F64 log_2 = log(2.0);
+        static const F64 log_4 = log(4.0);
+
+        F32 discard_level = 0.f;
+
+        // If we know the output width and height, we can force the discard
+        // level to the correct value, and thus not decode more texture
+        // data than we need to.
+        if (mKnownDrawWidth && mKnownDrawHeight)
+        {
+            S32 draw_texels = mKnownDrawWidth * mKnownDrawHeight;
+            draw_texels = llclamp(draw_texels, MIN_IMAGE_AREA, MAX_IMAGE_AREA);
+
+            // Use log_4 because we're in square-pixel space, so an image
+            // with twice the width and twice the height will have mTexelsPerImage
+            // 4 * draw_size
+            discard_level = (F32)(log(mTexelsPerImage / draw_texels) / log_4);
+        }
+        else
+        {
+            // Calculate the required scale factor of the image using pixels per texel
+            discard_level = (F32)(log(mTexelsPerImage / mMaxVirtualSize) / log_4);
+            mDiscardVirtualSize = mMaxVirtualSize;
+            mCalculatedDiscardLevel = discard_level;
+        }
+        if (mBoostLevel < LLGLTexture::BOOST_SCULPTED)
+        {
+            discard_level *= sDesiredDiscardScale; // scale (default 1.1f)
+        }
+        discard_level = floorf(discard_level);
+
+        F32 min_discard = 0.f;
+        U32 desired_size = MAX_IMAGE_SIZE_DEFAULT; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
+        if (mBoostLevel <= LLGLTexture::BOOST_SCULPTED)
+        {
+            desired_size = DESIRED_NORMAL_TEXTURE_SIZE;
+        }
+        if (mFullWidth > desired_size || mFullHeight > desired_size)
+            min_discard = 1.f;
+
+        discard_level = llclamp(discard_level, min_discard, (F32)MAX_DISCARD_LEVEL);
+
+        // Can't go higher than the max discard level
+        mDesiredDiscardLevel = llmin(getMaxDiscardLevel() + 1, (S32)discard_level);
+        // Clamp to min desired discard
+        mDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel, mDesiredDiscardLevel);
+
+        //
+        // At this point we've calculated the quality level that we want,
+        // if possible.  Now we check to see if we have it, and take the
+        // proper action if we don't.
+        //
+
+        S32 current_discard = getDiscardLevel();
+        if (mBoostLevel < LLGLTexture::BOOST_AVATAR_BAKED &&
+            current_discard >= 0)
+        {
+            if (current_discard < (mDesiredDiscardLevel-1) && !mForceToSaveRawImage)
+            { // should scale down
+                scaleDown();
+            }
+        }
+
+        if (isUpdateFrozen() // we are out of memory and nearing max allowed bias
+            && mBoostLevel < LLGLTexture::BOOST_SCULPTED
+            && mDesiredDiscardLevel < current_discard)
+        {
+            // stop requesting more
+            mDesiredDiscardLevel = current_discard;
+        }
+    }
+
+    if(mForceToSaveRawImage && mDesiredSavedRawDiscardLevel >= 0)
+    {
+        mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S8)mDesiredSavedRawDiscardLevel);
+    }
+
+    // decay max virtual size over time
+    mMaxVirtualSize *= 0.8f;
+
+    // selection manager will immediately reset BOOST_SELECTED but never unsets it
+    // unset it immediately after we consume it
+    if (getBoostLevel() == BOOST_SELECTED)
+    {
+        setBoostLevel(BOOST_NONE);
+    }
+}
+
+bool LLViewerLODTexture::scaleDown()
+{
+    if(hasGLTexture() && mCachedRawDiscardLevel > getDiscardLevel())
+    {
+        switchToCachedImage();
+
+        LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
+        if (tester)
+        {
+            tester->setStablizingTime();
+        }
+
+        return true;
+    }
+    return false;
+}
+//----------------------------------------------------------------------------------------------
+//end of LLViewerLODTexture
+//----------------------------------------------------------------------------------------------
+
+//----------------------------------------------------------------------------------------------
+//start of LLViewerMediaTexture
+//----------------------------------------------------------------------------------------------
+//static
+void LLViewerMediaTexture::updateClass()
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
+    static const F32 MAX_INACTIVE_TIME = 30.f;
+
+#if 0
+    //force to play media.
+    gSavedSettings.setBOOL("AudioStreamingMedia", true);
+#endif
+
+    for(media_map_t::iterator iter = sMediaMap.begin(); iter != sMediaMap.end(); )
+    {
+        LLViewerMediaTexture* mediap = iter->second;
+
+        if(mediap->getNumRefs() == 1) //one reference by sMediaMap
+        {
+            //
+            //Note: delay some time to delete the media textures to stop endlessly creating and immediately removing media texture.
+            //
+            if(mediap->getLastReferencedTimer()->getElapsedTimeF32() > MAX_INACTIVE_TIME)
+            {
+                media_map_t::iterator cur = iter++;
+                sMediaMap.erase(cur);
+                continue;
+            }
+        }
+        ++iter;
+    }
+}
+
+//static
+void LLViewerMediaTexture::removeMediaImplFromTexture(const LLUUID& media_id)
+{
+    LLViewerMediaTexture* media_tex = findMediaTexture(media_id);
+    if(media_tex)
+    {
+        media_tex->invalidateMediaImpl();
+    }
+}
+
+//static
+void LLViewerMediaTexture::cleanUpClass()
+{
+    sMediaMap.clear();
+}
+
+//static
+LLViewerMediaTexture* LLViewerMediaTexture::findMediaTexture(const LLUUID& media_id)
+{
+    media_map_t::iterator iter = sMediaMap.find(media_id);
+    if(iter == sMediaMap.end())
+    {
+        return NULL;
+    }
+
+    LLViewerMediaTexture* media_tex = iter->second;
+    media_tex->setMediaImpl();
+    media_tex->getLastReferencedTimer()->reset();
+
+    return media_tex;
+}
+
+LLViewerMediaTexture::LLViewerMediaTexture(const LLUUID& id, BOOL usemipmaps, LLImageGL* gl_image)
+    : LLViewerTexture(id, usemipmaps),
+    mMediaImplp(NULL),
+    mUpdateVirtualSizeTime(0)
+{
+    sMediaMap.insert(std::make_pair(id, this));
+
+    mGLTexturep = gl_image;
+
+    if(mGLTexturep.isNull())
+    {
+        generateGLTexture();
+    }
+
+    mGLTexturep->setAllowCompression(false);
+
+    mGLTexturep->setNeedsAlphaAndPickMask(FALSE);
+
+    mIsPlaying = FALSE;
+
+    setMediaImpl();
+
+    setCategory(LLGLTexture::MEDIA);
+
+    LLViewerTexture* tex = gTextureList.findImage(mID, TEX_LIST_STANDARD);
+    if(tex) //this media is a parcel media for tex.
+    {
+        tex->setParcelMedia(this);
+    }
+}
+
+//virtual
+LLViewerMediaTexture::~LLViewerMediaTexture()
+{
+    LLViewerTexture* tex = gTextureList.findImage(mID, TEX_LIST_STANDARD);
+    if(tex) //this media is a parcel media for tex.
+    {
+        tex->setParcelMedia(NULL);
+    }
+}
+
+void LLViewerMediaTexture::reinit(BOOL usemipmaps /* = TRUE */)
+{
+    llassert(mGLTexturep.notNull());
+
+    mUseMipMaps = usemipmaps;
+    getLastReferencedTimer()->reset();
+    mGLTexturep->setUseMipMaps(mUseMipMaps);
+    mGLTexturep->setNeedsAlphaAndPickMask(FALSE);
+}
+
+void LLViewerMediaTexture::setUseMipMaps(BOOL mipmap)
+{
+    mUseMipMaps = mipmap;
+
+    if(mGLTexturep.notNull())
+    {
+        mGLTexturep->setUseMipMaps(mipmap);
+    }
+}
+
+//virtual
+S8 LLViewerMediaTexture::getType() const
+{
+    return LLViewerTexture::MEDIA_TEXTURE;
+}
+
+void LLViewerMediaTexture::invalidateMediaImpl()
+{
+    mMediaImplp = NULL;
+}
+
+void LLViewerMediaTexture::setMediaImpl()
+{
+    if(!mMediaImplp)
+    {
+        mMediaImplp = LLViewerMedia::getInstance()->getMediaImplFromTextureID(mID);
+    }
+}
+
+//return true if all faces to reference to this media texture are found
+//Note: mMediaFaceList is valid only for the current instant
+//      because it does not check the face validity after the current frame.
+BOOL LLViewerMediaTexture::findFaces()
+{
+    mMediaFaceList.clear();
+
+    BOOL ret = TRUE;
+
+    LLViewerTexture* tex = gTextureList.findImage(mID, TEX_LIST_STANDARD);
+    if(tex) //this media is a parcel media for tex.
+    {
+        for (U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch)
+        {
+            const ll_face_list_t* face_list = tex->getFaceList(ch);
+            U32 end = tex->getNumFaces(ch);
+        for(U32 i = 0; i < end; i++)
+        {
+            if ((*face_list)[i]->isMediaAllowed())
+            {
+                mMediaFaceList.push_back((*face_list)[i]);
+            }
+        }
+    }
+    }
+
+    if(!mMediaImplp)
+    {
+        return TRUE;
+    }
+
+    //for media on a face.
+    const std::list< LLVOVolume* >* obj_list = mMediaImplp->getObjectList();
+    std::list< LLVOVolume* >::const_iterator iter = obj_list->begin();
+    for(; iter != obj_list->end(); ++iter)
+    {
+        LLVOVolume* obj = *iter;
+        if (obj->isDead())
+        {
+            // Isn't supposed to happen, objects are supposed to detach
+            // themselves on markDead()
+            // If this happens, viewer is likely to crash
+            llassert(0);
+            LL_WARNS() << "Dead object in mMediaImplp's object list" << LL_ENDL;
+            ret = FALSE;
+            continue;
+        }
+
+        if (obj->mDrawable.isNull() || obj->mDrawable->isDead())
+        {
+            ret = FALSE;
+            continue;
+        }
+
+        S32 face_id = -1;
+        S32 num_faces = obj->mDrawable->getNumFaces();
+        while((face_id = obj->getFaceIndexWithMediaImpl(mMediaImplp, face_id)) > -1 && face_id < num_faces)
+        {
+            LLFace* facep = obj->mDrawable->getFace(face_id);
+            if(facep)
+            {
+                mMediaFaceList.push_back(facep);
+            }
+            else
+            {
+                ret = FALSE;
+            }
+        }
+    }
+
+    return ret;
+}
+
+void LLViewerMediaTexture::initVirtualSize()
+{
+    if(mIsPlaying)
+    {
+        return;
+    }
+
+    findFaces();
+    for(std::list< LLFace* >::iterator iter = mMediaFaceList.begin(); iter!= mMediaFaceList.end(); ++iter)
+    {
+        addTextureStats((*iter)->getVirtualSize());
+    }
+}
+
+void LLViewerMediaTexture::addMediaToFace(LLFace* facep)
+{
+    if(facep)
+    {
+        facep->setHasMedia(true);
+    }
+    if(!mIsPlaying)
+    {
+        return; //no need to add the face because the media is not in playing.
+    }
+
+    switchTexture(LLRender::DIFFUSE_MAP, facep);
+}
+
+void LLViewerMediaTexture::removeMediaFromFace(LLFace* facep)
+{
+    if(!facep)
+    {
+        return;
+    }
+    facep->setHasMedia(false);
+
+    if(!mIsPlaying)
+    {
+        return; //no need to remove the face because the media is not in playing.
+    }
+
+    mIsPlaying = FALSE; //set to remove the media from the face.
+    switchTexture(LLRender::DIFFUSE_MAP, facep);
+    mIsPlaying = TRUE; //set the flag back.
+
+    if(getTotalNumFaces() < 1) //no face referencing to this media
+    {
+        stopPlaying();
+    }
+}
+
+//virtual
+void LLViewerMediaTexture::addFace(U32 ch, LLFace* facep)
+{
+    LLViewerTexture::addFace(ch, facep);
+
+    const LLTextureEntry* te = facep->getTextureEntry();
+    if(te && te->getID().notNull())
+    {
+        LLViewerTexture* tex = gTextureList.findImage(te->getID(), TEX_LIST_STANDARD);
+        if(tex)
+        {
+// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
+            // See LLViewerMediaTexture::removeFace()
+            if (facep->isDefaultTexture(ch))
+            {
+                return;
+            }
+// [/SL:KB]
+
+            mTextureList.push_back(tex);//increase the reference number by one for tex to avoid deleting it.
+            return;
+        }
+    }
+
+    //check if it is a parcel media
+    if(facep->getTexture() && facep->getTexture() != this && facep->getTexture()->getID() == mID)
+    {
+        mTextureList.push_back(facep->getTexture()); //a parcel media.
+        return;
+    }
+
+    if(te && te->getID().notNull()) //should have a texture
+    {
+        LL_WARNS_ONCE() << "The face's texture " << te->getID() << " is not valid. Face must have a valid texture before media texture." << LL_ENDL;
+        // This might break the object, but it likely isn't a 'recoverable' situation.
+        LLViewerFetchedTexture* tex = LLViewerTextureManager::getFetchedTexture(te->getID());
+        mTextureList.push_back(tex);
+    }
+}
+
+//virtual
+//void LLViewerMediaTexture::removeFace(U32 ch, LLFace* facep)
+// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
+void LLViewerMediaTexture::removeFace(U32 channel, LLFace* facep)
+// [/SL:KB]
+{
+// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
+    LLViewerTexture::removeFace(channel, facep);
+// [/SL:KB]
+//  LLViewerTexture::removeFace(ch, facep);
+
+    const LLTextureEntry* te = facep->getTextureEntry();
+    if(te && te->getID().notNull())
+    {
+        LLViewerTexture* tex = gTextureList.findImage(te->getID(), TEX_LIST_STANDARD);
+        if(tex)
+        {
+            for(std::list< LLPointer<LLViewerTexture> >::iterator iter = mTextureList.begin();
+                iter != mTextureList.end(); ++iter)
+            {
+                if(*iter == tex)
+                {
+// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
+                    // Switching to the default texture results in clearing the media textures on all prims;
+                    // a side-effect is that we loose out on the reference to the original (non-media)
+                    // texture potentially letting it dissapear from memory if this was the only reference to it
+                    // (which is harmless, it just means we'll need to grab it from the cache or refetch it but
+                    // the LL - debug - code at the bottom of addFace/removeFace disagrees so we'll hang on
+                    // to it (and then block readding it a seond time higher up)
+                    if (facep->isDefaultTexture(channel))
+                    {
+                        return;
+                    }
+// [/SL:KB]
+                    mTextureList.erase(iter); //decrease the reference number for tex by one.
+                    return;
+                }
+            }
+
+            std::vector<const LLTextureEntry*> te_list;
+
+            for (U32 ch = 0; ch < 3; ++ch)
+            {
+            //
+            //we have some trouble here: the texture of the face is changed.
+            //we need to find the former texture, and remove it from the list to avoid memory leaking.
+
+                llassert(mNumFaces[ch] <= mFaceList[ch].size());
+
+                for(U32 j = 0; j < mNumFaces[ch]; j++)
+                {
+                    te_list.push_back(mFaceList[ch][j]->getTextureEntry());//all textures are in use.
+                }
+            }
+
+            if (te_list.empty())
+            {
+                mTextureList.clear();
+                return;
+            }
+
+            S32 end = te_list.size();
+
+            for(std::list< LLPointer<LLViewerTexture> >::iterator iter = mTextureList.begin();
+                iter != mTextureList.end(); ++iter)
+            {
+                S32 i = 0;
+
+                for(i = 0; i < end; i++)
+                {
+                    if(te_list[i] && te_list[i]->getID() == (*iter)->getID())//the texture is in use.
+                    {
+                        te_list[i] = NULL;
+                        break;
+                    }
+                }
+                if(i == end) //no hit for this texture, remove it.
+                {
+// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
+                    // See above
+                    if (facep->isDefaultTexture(channel))
+                    {
+                        return;
+                    }
+// [/SL:KB]
+                    mTextureList.erase(iter); //decrease the reference number for tex by one.
+                    return;
+                }
+            }
+        }
+    }
+
+    //check if it is a parcel media
+    for(std::list< LLPointer<LLViewerTexture> >::iterator iter = mTextureList.begin();
+                iter != mTextureList.end(); ++iter)
+    {
+        if((*iter)->getID() == mID)
+        {
+            mTextureList.erase(iter); //decrease the reference number for tex by one.
+            return;
+        }
+    }
+
+    if(te && te->getID().notNull()) //should have a texture but none found
+    {
+        LL_ERRS() << "mTextureList texture reference number is corrupted. Texture id: " << te->getID() << " List size: " << (U32)mTextureList.size() << LL_ENDL;
+    }
+}
+
+void LLViewerMediaTexture::stopPlaying()
+{
+    // Don't stop the media impl playing here -- this breaks non-inworld media (login screen, search, and media browser).
+//  if(mMediaImplp)
+//  {
+//      mMediaImplp->stop();
+//  }
+    mIsPlaying = FALSE;
+}
+
+void LLViewerMediaTexture::switchTexture(U32 ch, LLFace* facep)
+{
+    if(facep)
+    {
+        //check if another media is playing on this face.
+        if(facep->getTexture() && facep->getTexture() != this
+            && facep->getTexture()->getType() == LLViewerTexture::MEDIA_TEXTURE)
+        {
+            if(mID == facep->getTexture()->getID()) //this is a parcel media
+            {
+                return; //let the prim media win.
+            }
+        }
+
+        if(mIsPlaying) //old textures switch to the media texture
+        {
+            facep->switchTexture(ch, this);
+        }
+        else //switch to old textures.
+        {
+            const LLTextureEntry* te = facep->getTextureEntry();
+            if(te)
+            {
+                LLViewerTexture* tex = te->getID().notNull() ? gTextureList.findImage(te->getID(), TEX_LIST_STANDARD) : NULL;
+                if(!tex && te->getID() != mID)//try parcel media.
+                {
+                    tex = gTextureList.findImage(mID, TEX_LIST_STANDARD);
+                }
+                if(!tex)
+                {
+                    tex = LLViewerFetchedTexture::sDefaultImagep;
+                }
+                facep->switchTexture(ch, tex);
+            }
+        }
+    }
+}
+
+void LLViewerMediaTexture::setPlaying(BOOL playing)
+{
+    if(!mMediaImplp)
+    {
+        return;
+    }
+    if(!playing && !mIsPlaying)
     {
-        //static const F64 log_2 = log(2.0);
-        static const F64 log_4 = log(4.0);
+        return; //media is already off
+    }
 
-        F32 discard_level = 0.f;
+    if(playing == mIsPlaying && !mMediaImplp->isUpdated())
+    {
+        return; //nothing has changed since last time.
+    }
 
-        // If we know the output width and height, we can force the discard
-        // level to the correct value, and thus not decode more texture
-        // data than we need to.
-        if (mKnownDrawWidth && mKnownDrawHeight)
+    mIsPlaying = playing;
+    if(mIsPlaying) //is about to play this media
+    {
+        if(findFaces())
         {
-            S32 draw_texels = mKnownDrawWidth * mKnownDrawHeight;
-            draw_texels = llclamp(draw_texels, MIN_IMAGE_AREA, MAX_IMAGE_AREA);
-
-            // Use log_4 because we're in square-pixel space, so an image
-            // with twice the width and twice the height will have mTexelsPerImage
-            // 4 * draw_size
-            discard_level = (F32)(log(mTexelsPerImage / draw_texels) / log_4);
+            //about to update all faces.
+            mMediaImplp->setUpdated(FALSE);
         }
-        else
+
+        if(mMediaFaceList.empty())//no face pointing to this media
         {
-            // Calculate the required scale factor of the image using pixels per texel
-            discard_level = (F32)(log(mTexelsPerImage / mMaxVirtualSize) / log_4);
-            mDiscardVirtualSize = mMaxVirtualSize;
-            mCalculatedDiscardLevel = discard_level;
+            stopPlaying();
+            return;
         }
-        if (mBoostLevel < LLGLTexture::BOOST_SCULPTED)
+
+        for(std::list< LLFace* >::iterator iter = mMediaFaceList.begin(); iter!= mMediaFaceList.end(); ++iter)
         {
-            discard_level *= sDesiredDiscardScale; // scale (default 1.1f)
+            switchTexture(LLRender::DIFFUSE_MAP, *iter);
         }
-        discard_level = floorf(discard_level);
+    }
+    else //stop playing this media
+    {
+        U32 ch = LLRender::DIFFUSE_MAP;
 
-        F32 min_discard = 0.f;
-        U32 desired_size = MAX_IMAGE_SIZE_DEFAULT; // MAX_IMAGE_SIZE_DEFAULT = 2048 and max size ever is 4096
-        if (mBoostLevel <= LLGLTexture::BOOST_SCULPTED)
+        llassert(mNumFaces[ch] <= mFaceList[ch].size());
+        for(U32 i = mNumFaces[ch]; i; i--)
         {
-            desired_size = DESIRED_NORMAL_TEXTURE_SIZE;
+            switchTexture(ch, mFaceList[ch][i - 1]); //current face could be removed in this function.
         }
-        if (mFullWidth > desired_size || mFullHeight > desired_size)
-            min_discard = 1.f;
-
-        discard_level = llclamp(discard_level, min_discard, (F32)MAX_DISCARD_LEVEL);
+    }
+    return;
+}
 
-        // Can't go higher than the max discard level
-        mDesiredDiscardLevel = llmin(getMaxDiscardLevel() + 1, (S32)discard_level);
-        // Clamp to min desired discard
-        mDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel, mDesiredDiscardLevel);
+//virtual
+F32 LLViewerMediaTexture::getMaxVirtualSize()
+{
+    if(LLFrameTimer::getFrameCount() == mUpdateVirtualSizeTime)
+    {
+        return mMaxVirtualSize;
+    }
+    mUpdateVirtualSizeTime = LLFrameTimer::getFrameCount();
 
-        //
-        // At this point we've calculated the quality level that we want,
-        // if possible.  Now we check to see if we have it, and take the
-        // proper action if we don't.
-        //
+    if(!mMaxVirtualSizeResetCounter)
+    {
+        addTextureStats(0.f, FALSE);//reset
+    }
 
-        S32 current_discard = getDiscardLevel();
-        if (mBoostLevel < LLGLTexture::BOOST_AVATAR_BAKED && 
-            current_discard >= 0)
+    if(mIsPlaying) //media is playing
+    {
+        for (U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch)
         {
-            if (current_discard < (mDesiredDiscardLevel-1) && !mForceToSaveRawImage)
-            { // should scale down
-                scaleDown();
+            llassert(mNumFaces[ch] <= mFaceList[ch].size());
+            for(U32 i = 0; i < mNumFaces[ch]; i++)
+            {
+                LLFace* facep = mFaceList[ch][i];
+            if(facep->getDrawable()->isRecentlyVisible())
+            {
+                addTextureStats(facep->getVirtualSize());
             }
         }
+    }
+    }
+    else //media is not in playing
+    {
+        findFaces();
 
-		if (isUpdateFrozen() // we are out of memory and nearing max allowed bias
-			&& mBoostLevel < LLGLTexture::BOOST_SCULPTED
-			&& mDesiredDiscardLevel < current_discard)
-		{
-			// stop requesting more
-			mDesiredDiscardLevel = current_discard;
-		}
-	}
-
-	if(mForceToSaveRawImage && mDesiredSavedRawDiscardLevel >= 0)
-	{
-		mDesiredDiscardLevel = llmin(mDesiredDiscardLevel, (S8)mDesiredSavedRawDiscardLevel);
-	}
-
-    // decay max virtual size over time
-    mMaxVirtualSize *= 0.8f;
+        if(!mMediaFaceList.empty())
+        {
+            for(std::list< LLFace* >::iterator iter = mMediaFaceList.begin(); iter!= mMediaFaceList.end(); ++iter)
+            {
+                LLFace* facep = *iter;
+                if(facep->getDrawable()->isRecentlyVisible())
+                {
+                    addTextureStats(facep->getVirtualSize());
+                }
+            }
+        }
+    }
 
-    // selection manager will immediately reset BOOST_SELECTED but never unsets it
-    // unset it immediately after we consume it
-    if (getBoostLevel() == BOOST_SELECTED)
+    if(mMaxVirtualSizeResetCounter > 0)
     {
-        setBoostLevel(BOOST_NONE);
+        mMaxVirtualSizeResetCounter--;
     }
-}
-
-bool LLViewerLODTexture::scaleDown()
-{
-	if(hasGLTexture() && mCachedRawDiscardLevel > getDiscardLevel())
-	{		
-		switchToCachedImage();	
+    reorganizeFaceList();
+    reorganizeVolumeList();
 
-		LLTexturePipelineTester* tester = (LLTexturePipelineTester*)LLMetricPerformanceTesterBasic::getTester(sTesterName);
-		if (tester)
-		{
-			tester->setStablizingTime();
-		}
-
-		return true;
-	}
-	return false;
+    return mMaxVirtualSize;
 }
 //----------------------------------------------------------------------------------------------
-//end of LLViewerLODTexture
+//end of LLViewerMediaTexture
 //----------------------------------------------------------------------------------------------
 
 //----------------------------------------------------------------------------------------------
-//start of LLViewerMediaTexture
+//start of LLTexturePipelineTester
 //----------------------------------------------------------------------------------------------
-//static
-void LLViewerMediaTexture::updateClass()
+LLTexturePipelineTester::LLTexturePipelineTester() : LLMetricPerformanceTesterWithSession(sTesterName)
 {
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-	static const F32 MAX_INACTIVE_TIME = 30.f;
+    addMetric("TotalBytesLoaded");
+    addMetric("TotalBytesLoadedFromCache");
+    addMetric("TotalBytesLoadedForLargeImage");
+    addMetric("TotalBytesLoadedForSculpties");
+    addMetric("StartFetchingTime");
+    addMetric("TotalGrayTime");
+    addMetric("TotalStablizingTime");
+    addMetric("StartTimeLoadingSculpties");
+    addMetric("EndTimeLoadingSculpties");
 
-#if 0
-	//force to play media.
-	gSavedSettings.setBOOL("AudioStreamingMedia", true);
-#endif
+    addMetric("Time");
+    addMetric("TotalBytesBound");
+    addMetric("TotalBytesBoundForLargeImage");
+    addMetric("PercentageBytesBound");
 
-	for(media_map_t::iterator iter = sMediaMap.begin(); iter != sMediaMap.end(); )
-	{
-		LLViewerMediaTexture* mediap = iter->second;	
-		
-		if(mediap->getNumRefs() == 1) //one reference by sMediaMap
-		{
-			//
-			//Note: delay some time to delete the media textures to stop endlessly creating and immediately removing media texture.
-			//
-			if(mediap->getLastReferencedTimer()->getElapsedTimeF32() > MAX_INACTIVE_TIME)
-			{
-				media_map_t::iterator cur = iter++;
-				sMediaMap.erase(cur);
-				continue;
-			}
-		}
-		++iter;
-	}
-}
-
-//static 
-void LLViewerMediaTexture::removeMediaImplFromTexture(const LLUUID& media_id) 
-{
-	LLViewerMediaTexture* media_tex = findMediaTexture(media_id);
-	if(media_tex)
-	{
-		media_tex->invalidateMediaImpl();
-	}
+    mTotalBytesLoaded = (S32Bytes)0;
+    mTotalBytesLoadedFromCache = (S32Bytes)0;
+    mTotalBytesLoadedForLargeImage = (S32Bytes)0;
+    mTotalBytesLoadedForSculpties = (S32Bytes)0;
+
+    reset();
 }
 
-//static
-void LLViewerMediaTexture::cleanUpClass()
+LLTexturePipelineTester::~LLTexturePipelineTester()
 {
-	sMediaMap.clear();
+    LLViewerTextureManager::sTesterp = NULL;
 }
 
-//static
-LLViewerMediaTexture* LLViewerMediaTexture::findMediaTexture(const LLUUID& media_id)
+void LLTexturePipelineTester::update()
 {
-	media_map_t::iterator iter = sMediaMap.find(media_id);
-	if(iter == sMediaMap.end())
-	{
-		return NULL;
-	}
+    mLastTotalBytesUsed = mTotalBytesUsed;
+    mLastTotalBytesUsedForLargeImage = mTotalBytesUsedForLargeImage;
+    mTotalBytesUsed = (S32Bytes)0;
+    mTotalBytesUsedForLargeImage = (S32Bytes)0;
+
+    if(LLAppViewer::getTextureFetch()->getNumRequests() > 0) //fetching list is not empty
+    {
+        if(mPause)
+        {
+            //start a new fetching session
+            reset();
+            mStartFetchingTime = LLImageGL::sLastFrameTime;
+            mPause = FALSE;
+        }
+
+        //update total gray time
+        if(mUsingDefaultTexture)
+        {
+            mUsingDefaultTexture = FALSE;
+            mTotalGrayTime = LLImageGL::sLastFrameTime - mStartFetchingTime;
+        }
 
-	LLViewerMediaTexture* media_tex = iter->second;
-	media_tex->setMediaImpl();
-	media_tex->getLastReferencedTimer()->reset();
+        //update the stablizing timer.
+        updateStablizingTime();
 
-	return media_tex;
+        outputTestResults();
+    }
+    else if(!mPause)
+    {
+        //stop the current fetching session
+        mPause = TRUE;
+        outputTestResults();
+        reset();
+    }
 }
 
-LLViewerMediaTexture::LLViewerMediaTexture(const LLUUID& id, BOOL usemipmaps, LLImageGL* gl_image) 
-	: LLViewerTexture(id, usemipmaps),
-	mMediaImplp(NULL),
-	mUpdateVirtualSizeTime(0)
+void LLTexturePipelineTester::reset()
 {
-	sMediaMap.insert(std::make_pair(id, this));
+    mPause = TRUE;
+
+    mUsingDefaultTexture = FALSE;
+    mStartStablizingTime = 0.0f;
+    mEndStablizingTime = 0.0f;
 
-	mGLTexturep = gl_image;
+    mTotalBytesUsed = (S32Bytes)0;
+    mTotalBytesUsedForLargeImage = (S32Bytes)0;
+    mLastTotalBytesUsed = (S32Bytes)0;
+    mLastTotalBytesUsedForLargeImage = (S32Bytes)0;
 
-	if(mGLTexturep.isNull())
-	{
-		generateGLTexture();
-	}
+    mStartFetchingTime = 0.0f;
 
-	mGLTexturep->setAllowCompression(false);
+    mTotalGrayTime = 0.0f;
+    mTotalStablizingTime = 0.0f;
 
-	mGLTexturep->setNeedsAlphaAndPickMask(FALSE);
+    mStartTimeLoadingSculpties = 1.0f;
+    mEndTimeLoadingSculpties = 0.0f;
+}
 
-	mIsPlaying = FALSE;
+//virtual
+void LLTexturePipelineTester::outputTestRecord(LLSD *sd)
+{
+    std::string currentLabel = getCurrentLabelName();
+    (*sd)[currentLabel]["TotalBytesLoaded"]              = (LLSD::Integer)mTotalBytesLoaded.value();
+    (*sd)[currentLabel]["TotalBytesLoadedFromCache"]     = (LLSD::Integer)mTotalBytesLoadedFromCache.value();
+    (*sd)[currentLabel]["TotalBytesLoadedForLargeImage"] = (LLSD::Integer)mTotalBytesLoadedForLargeImage.value();
+    (*sd)[currentLabel]["TotalBytesLoadedForSculpties"]  = (LLSD::Integer)mTotalBytesLoadedForSculpties.value();
 
-	setMediaImpl();
+    (*sd)[currentLabel]["StartFetchingTime"]             = (LLSD::Real)mStartFetchingTime;
+    (*sd)[currentLabel]["TotalGrayTime"]                 = (LLSD::Real)mTotalGrayTime;
+    (*sd)[currentLabel]["TotalStablizingTime"]           = (LLSD::Real)mTotalStablizingTime;
 
-	setCategory(LLGLTexture::MEDIA);
-	
-	LLViewerTexture* tex = gTextureList.findImage(mID, TEX_LIST_STANDARD);
-	if(tex) //this media is a parcel media for tex.
-	{
-		tex->setParcelMedia(this);
-	}
-}
+    (*sd)[currentLabel]["StartTimeLoadingSculpties"]     = (LLSD::Real)mStartTimeLoadingSculpties;
+    (*sd)[currentLabel]["EndTimeLoadingSculpties"]       = (LLSD::Real)mEndTimeLoadingSculpties;
 
-//virtual 
-LLViewerMediaTexture::~LLViewerMediaTexture() 
-{	
-	LLViewerTexture* tex = gTextureList.findImage(mID, TEX_LIST_STANDARD);
-	if(tex) //this media is a parcel media for tex.
-	{
-		tex->setParcelMedia(NULL);
-	}
+    (*sd)[currentLabel]["Time"]                          = LLImageGL::sLastFrameTime;
+    (*sd)[currentLabel]["TotalBytesBound"]               = (LLSD::Integer)mLastTotalBytesUsed.value();
+    (*sd)[currentLabel]["TotalBytesBoundForLargeImage"]  = (LLSD::Integer)mLastTotalBytesUsedForLargeImage.value();
+    (*sd)[currentLabel]["PercentageBytesBound"]          = (LLSD::Real)(100.f * mLastTotalBytesUsed / mTotalBytesLoaded);
 }
 
-void LLViewerMediaTexture::reinit(BOOL usemipmaps /* = TRUE */)
+void LLTexturePipelineTester::updateTextureBindingStats(const LLViewerTexture* imagep)
 {
-	llassert(mGLTexturep.notNull());
+    U32Bytes mem_size = imagep->getTextureMemory();
+    mTotalBytesUsed += mem_size;
 
-	mUseMipMaps = usemipmaps;
-	getLastReferencedTimer()->reset();
-	mGLTexturep->setUseMipMaps(mUseMipMaps);
-	mGLTexturep->setNeedsAlphaAndPickMask(FALSE);
+    if(MIN_LARGE_IMAGE_AREA <= (U32)(mem_size.value() / (U32)imagep->getComponents()))
+    {
+        mTotalBytesUsedForLargeImage += mem_size;
+    }
 }
 
-void LLViewerMediaTexture::setUseMipMaps(BOOL mipmap) 
+void LLTexturePipelineTester::updateTextureLoadingStats(const LLViewerFetchedTexture* imagep, const LLImageRaw* raw_imagep, BOOL from_cache)
 {
-	mUseMipMaps = mipmap;
+    U32Bytes data_size = (U32Bytes)raw_imagep->getDataSize();
+    mTotalBytesLoaded += data_size;
+
+    if(from_cache)
+    {
+        mTotalBytesLoadedFromCache += data_size;
+    }
 
-	if(mGLTexturep.notNull())
-	{
-		mGLTexturep->setUseMipMaps(mipmap);
-	}
+    if(MIN_LARGE_IMAGE_AREA <= (U32)(data_size.value() / (U32)raw_imagep->getComponents()))
+    {
+        mTotalBytesLoadedForLargeImage += data_size;
+    }
+
+    if(imagep->forSculpt())
+    {
+        mTotalBytesLoadedForSculpties += data_size;
+
+        if(mStartTimeLoadingSculpties > mEndTimeLoadingSculpties)
+        {
+            mStartTimeLoadingSculpties = LLImageGL::sLastFrameTime;
+        }
+        mEndTimeLoadingSculpties = LLImageGL::sLastFrameTime;
+    }
 }
 
-//virtual 
-S8 LLViewerMediaTexture::getType() const
+void LLTexturePipelineTester::updateGrayTextureBinding()
 {
-	return LLViewerTexture::MEDIA_TEXTURE;
+    mUsingDefaultTexture = TRUE;
 }
 
-void LLViewerMediaTexture::invalidateMediaImpl() 
+void LLTexturePipelineTester::setStablizingTime()
 {
-	mMediaImplp = NULL;
+    if(mStartStablizingTime <= mStartFetchingTime)
+    {
+        mStartStablizingTime = LLImageGL::sLastFrameTime;
+    }
+    mEndStablizingTime = LLImageGL::sLastFrameTime;
 }
 
-void LLViewerMediaTexture::setMediaImpl()
+void LLTexturePipelineTester::updateStablizingTime()
 {
-	if(!mMediaImplp)
-	{
-		mMediaImplp = LLViewerMedia::getInstance()->getMediaImplFromTextureID(mID);
-	}
-}
+    if(mStartStablizingTime > mStartFetchingTime)
+    {
+        F32 t = mEndStablizingTime - mStartStablizingTime;
 
-//return true if all faces to reference to this media texture are found
-//Note: mMediaFaceList is valid only for the current instant 
-//      because it does not check the face validity after the current frame.
-BOOL LLViewerMediaTexture::findFaces()
-{	
-	mMediaFaceList.clear();
-
-	BOOL ret = TRUE;
-	
-	LLViewerTexture* tex = gTextureList.findImage(mID, TEX_LIST_STANDARD);
-	if(tex) //this media is a parcel media for tex.
-	{
-		for (U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch)
-		{
-			const ll_face_list_t* face_list = tex->getFaceList(ch);
-			U32 end = tex->getNumFaces(ch);
-		for(U32 i = 0; i < end; i++)
-		{
-			if ((*face_list)[i]->isMediaAllowed())
-			{
-				mMediaFaceList.push_back((*face_list)[i]);
-			}
-		}
-	}
-	}
-	
-	if(!mMediaImplp)
-	{
-		return TRUE; 
-	}
-
-	//for media on a face.
-	const std::list< LLVOVolume* >* obj_list = mMediaImplp->getObjectList();
-	std::list< LLVOVolume* >::const_iterator iter = obj_list->begin();
-	for(; iter != obj_list->end(); ++iter)
-	{
-		LLVOVolume* obj = *iter;
-        if (obj->isDead())
+        if(t > F_ALMOST_ZERO && (t - mTotalStablizingTime) < F_ALMOST_ZERO)
         {
-            // Isn't supposed to happen, objects are supposed to detach
-            // themselves on markDead()
-            // If this happens, viewer is likely to crash
-            llassert(0);
-            LL_WARNS() << "Dead object in mMediaImplp's object list" << LL_ENDL;
-            ret = FALSE;
-            continue;
-        }
+            //already stablized
+            mTotalStablizingTime = LLImageGL::sLastFrameTime - mStartStablizingTime;
 
-        if (obj->mDrawable.isNull() || obj->mDrawable->isDead())
+            //cancel the timer
+            mStartStablizingTime = 0.f;
+            mEndStablizingTime = 0.f;
+        }
+        else
         {
-            ret = FALSE;
-            continue;
+            mTotalStablizingTime = t;
         }
-
-		S32 face_id = -1;
-		S32 num_faces = obj->mDrawable->getNumFaces();
-		while((face_id = obj->getFaceIndexWithMediaImpl(mMediaImplp, face_id)) > -1 && face_id < num_faces)
-		{
-			LLFace* facep = obj->mDrawable->getFace(face_id);
-			if(facep)
-			{
-				mMediaFaceList.push_back(facep);
-			}
-			else
-			{
-				ret = FALSE;
-			}
-		}
-	}
-
-	return ret;
+    }
+    mTotalStablizingTime = 0.f;
 }
 
-void LLViewerMediaTexture::initVirtualSize()
+//virtual
+void LLTexturePipelineTester::compareTestSessions(llofstream* os)
 {
-	if(mIsPlaying)
-	{
-		return;
-	}
+    LLTexturePipelineTester::LLTextureTestSession* base_sessionp = dynamic_cast<LLTexturePipelineTester::LLTextureTestSession*>(mBaseSessionp);
+    LLTexturePipelineTester::LLTextureTestSession* current_sessionp = dynamic_cast<LLTexturePipelineTester::LLTextureTestSession*>(mCurrentSessionp);
+    if(!base_sessionp || !current_sessionp)
+    {
+        LL_ERRS() << "type of test session does not match!" << LL_ENDL;
+    }
 
-	findFaces();
-	for(std::list< LLFace* >::iterator iter = mMediaFaceList.begin(); iter!= mMediaFaceList.end(); ++iter)
-	{
-		addTextureStats((*iter)->getVirtualSize());
-	}
-}
+    //compare and output the comparison
+    *os << llformat("%s\n", getTesterName().c_str());
+    *os << llformat("AggregateResults\n");
 
-void LLViewerMediaTexture::addMediaToFace(LLFace* facep) 
-{
-	if(facep)
-	{
-		facep->setHasMedia(true);
-	}
-	if(!mIsPlaying)
-	{
-		return; //no need to add the face because the media is not in playing.
-	}
+    compareTestResults(os, "TotalGrayTime", base_sessionp->mTotalGrayTime, current_sessionp->mTotalGrayTime);
+    compareTestResults(os, "TotalStablizingTime", base_sessionp->mTotalStablizingTime, current_sessionp->mTotalStablizingTime);
+    compareTestResults(os, "StartTimeLoadingSculpties", base_sessionp->mStartTimeLoadingSculpties, current_sessionp->mStartTimeLoadingSculpties);
+    compareTestResults(os, "TotalTimeLoadingSculpties", base_sessionp->mTotalTimeLoadingSculpties, current_sessionp->mTotalTimeLoadingSculpties);
 
-	switchTexture(LLRender::DIFFUSE_MAP, facep);
-}
-	
-void LLViewerMediaTexture::removeMediaFromFace(LLFace* facep) 
-{
-	if(!facep)
-	{
-		return;
-	}
-	facep->setHasMedia(false);
+    compareTestResults(os, "TotalBytesLoaded", base_sessionp->mTotalBytesLoaded, current_sessionp->mTotalBytesLoaded);
+    compareTestResults(os, "TotalBytesLoadedFromCache", base_sessionp->mTotalBytesLoadedFromCache, current_sessionp->mTotalBytesLoadedFromCache);
+    compareTestResults(os, "TotalBytesLoadedForLargeImage", base_sessionp->mTotalBytesLoadedForLargeImage, current_sessionp->mTotalBytesLoadedForLargeImage);
+    compareTestResults(os, "TotalBytesLoadedForSculpties", base_sessionp->mTotalBytesLoadedForSculpties, current_sessionp->mTotalBytesLoadedForSculpties);
 
-	if(!mIsPlaying)
-	{
-		return; //no need to remove the face because the media is not in playing.
-	}	
+    *os << llformat("InstantResults\n");
+    S32 size = llmin(base_sessionp->mInstantPerformanceListCounter, current_sessionp->mInstantPerformanceListCounter);
+    for(S32 i = 0; i < size; i++)
+    {
+        *os << llformat("Time(B-T)-%.4f-%.4f\n", base_sessionp->mInstantPerformanceList[i].mTime, current_sessionp->mInstantPerformanceList[i].mTime);
 
-	mIsPlaying = FALSE; //set to remove the media from the face.
-	switchTexture(LLRender::DIFFUSE_MAP, facep);
-	mIsPlaying = TRUE; //set the flag back.
+        compareTestResults(os, "AverageBytesUsedPerSecond", base_sessionp->mInstantPerformanceList[i].mAverageBytesUsedPerSecond,
+            current_sessionp->mInstantPerformanceList[i].mAverageBytesUsedPerSecond);
 
-	if(getTotalNumFaces() < 1) //no face referencing to this media
-	{
-		stopPlaying();
-	}
-}
+        compareTestResults(os, "AverageBytesUsedForLargeImagePerSecond", base_sessionp->mInstantPerformanceList[i].mAverageBytesUsedForLargeImagePerSecond,
+            current_sessionp->mInstantPerformanceList[i].mAverageBytesUsedForLargeImagePerSecond);
 
-//virtual 
-void LLViewerMediaTexture::addFace(U32 ch, LLFace* facep) 
-{
-	LLViewerTexture::addFace(ch, facep);
+        compareTestResults(os, "AveragePercentageBytesUsedPerSecond", base_sessionp->mInstantPerformanceList[i].mAveragePercentageBytesUsedPerSecond,
+            current_sessionp->mInstantPerformanceList[i].mAveragePercentageBytesUsedPerSecond);
+    }
 
-	const LLTextureEntry* te = facep->getTextureEntry();
-	if(te && te->getID().notNull())
-	{
-		LLViewerTexture* tex = gTextureList.findImage(te->getID(), TEX_LIST_STANDARD);
-		if(tex)
-		{
-// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
-			// See LLViewerMediaTexture::removeFace()
-			if (facep->isDefaultTexture(ch))
-			{
-				return;
-			}
-// [/SL:KB]
+    if(size < base_sessionp->mInstantPerformanceListCounter)
+    {
+        for(S32 i = size; i < base_sessionp->mInstantPerformanceListCounter; i++)
+        {
+            *os << llformat("Time(B-T)-%.4f- \n", base_sessionp->mInstantPerformanceList[i].mTime);
 
-			mTextureList.push_back(tex);//increase the reference number by one for tex to avoid deleting it.
-			return;
-		}
-	}
-
-	//check if it is a parcel media
-	if(facep->getTexture() && facep->getTexture() != this && facep->getTexture()->getID() == mID)
-	{
-		mTextureList.push_back(facep->getTexture()); //a parcel media.
-		return;
-	}
-	
-	if(te && te->getID().notNull()) //should have a texture
-	{
-        LL_WARNS_ONCE() << "The face's texture " << te->getID() << " is not valid. Face must have a valid texture before media texture." << LL_ENDL;
-        // This might break the object, but it likely isn't a 'recoverable' situation.
-        LLViewerFetchedTexture* tex = LLViewerTextureManager::getFetchedTexture(te->getID());
-        mTextureList.push_back(tex);
-	}
-}
+            *os << llformat(", AverageBytesUsedPerSecond, %d, N/A \n", base_sessionp->mInstantPerformanceList[i].mAverageBytesUsedPerSecond);
+            *os << llformat(", AverageBytesUsedForLargeImagePerSecond, %d, N/A \n", base_sessionp->mInstantPerformanceList[i].mAverageBytesUsedForLargeImagePerSecond);
+            *os << llformat(", AveragePercentageBytesUsedPerSecond, %.4f, N/A \n", base_sessionp->mInstantPerformanceList[i].mAveragePercentageBytesUsedPerSecond);
+        }
+    }
+    else if(size < current_sessionp->mInstantPerformanceListCounter)
+    {
+        for(S32 i = size; i < current_sessionp->mInstantPerformanceListCounter; i++)
+        {
+            *os << llformat("Time(B-T)- -%.4f\n", current_sessionp->mInstantPerformanceList[i].mTime);
 
-//virtual 
-//void LLViewerMediaTexture::removeFace(U32 ch, LLFace* facep) 
-// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
-void LLViewerMediaTexture::removeFace(U32 channel, LLFace* facep) 
-// [/SL:KB]
-{
-// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
-	LLViewerTexture::removeFace(channel, facep);
-// [/SL:KB]
-//	LLViewerTexture::removeFace(ch, facep);
-
-	const LLTextureEntry* te = facep->getTextureEntry();
-	if(te && te->getID().notNull())
-	{
-		LLViewerTexture* tex = gTextureList.findImage(te->getID(), TEX_LIST_STANDARD);
-		if(tex)
-		{
-			for(std::list< LLPointer<LLViewerTexture> >::iterator iter = mTextureList.begin();
-				iter != mTextureList.end(); ++iter)
-			{
-				if(*iter == tex)
-				{
-// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
-					// Switching to the default texture results in clearing the media textures on all prims;
-					// a side-effect is that we loose out on the reference to the original (non-media)
-					// texture potentially letting it dissapear from memory if this was the only reference to it
-					// (which is harmless, it just means we'll need to grab it from the cache or refetch it but
-					// the LL - debug - code at the bottom of addFace/removeFace disagrees so we'll hang on
-					// to it (and then block readding it a seond time higher up)
-					if (facep->isDefaultTexture(channel))
-					{
-						return;
-					}
-// [/SL:KB]
-					mTextureList.erase(iter); //decrease the reference number for tex by one.
-					return;
-				}
-			}
-
-			std::vector<const LLTextureEntry*> te_list;
-			
-			for (U32 ch = 0; ch < 3; ++ch)
-			{
-			//
-			//we have some trouble here: the texture of the face is changed.
-			//we need to find the former texture, and remove it from the list to avoid memory leaking.
-				
-				llassert(mNumFaces[ch] <= mFaceList[ch].size());
-
-				for(U32 j = 0; j < mNumFaces[ch]; j++)
-				{
-					te_list.push_back(mFaceList[ch][j]->getTextureEntry());//all textures are in use.
-				}
-			}
-
-			if (te_list.empty())
-			{
-				mTextureList.clear();
-				return;
-			}
-
-			S32 end = te_list.size();
-
-			for(std::list< LLPointer<LLViewerTexture> >::iterator iter = mTextureList.begin();
-				iter != mTextureList.end(); ++iter)
-			{
-				S32 i = 0;
-
-				for(i = 0; i < end; i++)
-				{
-					if(te_list[i] && te_list[i]->getID() == (*iter)->getID())//the texture is in use.
-					{
-						te_list[i] = NULL;
-						break;
-					}
-				}
-				if(i == end) //no hit for this texture, remove it.
-				{
-// [SL:KB] - Patch: Render-TextureToggle (Catznip-5.2)
-					// See above
-					if (facep->isDefaultTexture(channel))
-					{
-						return;
-					}
-// [/SL:KB]
-					mTextureList.erase(iter); //decrease the reference number for tex by one.
-					return;
-				}
-			}
-		}
-	}
-
-	//check if it is a parcel media
-	for(std::list< LLPointer<LLViewerTexture> >::iterator iter = mTextureList.begin();
-				iter != mTextureList.end(); ++iter)
-	{
-		if((*iter)->getID() == mID)
-		{
-			mTextureList.erase(iter); //decrease the reference number for tex by one.
-			return;
-		}
-	}
-
-	if(te && te->getID().notNull()) //should have a texture but none found
-	{
-		LL_ERRS() << "mTextureList texture reference number is corrupted. Texture id: " << te->getID() << " List size: " << (U32)mTextureList.size() << LL_ENDL;
-	}
+            *os << llformat(", AverageBytesUsedPerSecond, N/A, %d\n", current_sessionp->mInstantPerformanceList[i].mAverageBytesUsedPerSecond);
+            *os << llformat(", AverageBytesUsedForLargeImagePerSecond, N/A, %d\n", current_sessionp->mInstantPerformanceList[i].mAverageBytesUsedForLargeImagePerSecond);
+            *os << llformat(", AveragePercentageBytesUsedPerSecond, N/A, %.4f\n", current_sessionp->mInstantPerformanceList[i].mAveragePercentageBytesUsedPerSecond);
+        }
+    }
 }
 
-void LLViewerMediaTexture::stopPlaying()
+//virtual
+LLMetricPerformanceTesterWithSession::LLTestSession* LLTexturePipelineTester::loadTestSession(LLSD* log)
 {
-	// Don't stop the media impl playing here -- this breaks non-inworld media (login screen, search, and media browser).
-//	if(mMediaImplp)
-//	{
-//		mMediaImplp->stop();
-//	}
-	mIsPlaying = FALSE;			
-}
+    LLTexturePipelineTester::LLTextureTestSession* sessionp = new LLTexturePipelineTester::LLTextureTestSession();
+    if(!sessionp)
+    {
+        return NULL;
+    }
 
-void LLViewerMediaTexture::switchTexture(U32 ch, LLFace* facep)
-{
-	if(facep)
-	{
-		//check if another media is playing on this face.
-		if(facep->getTexture() && facep->getTexture() != this 
-			&& facep->getTexture()->getType() == LLViewerTexture::MEDIA_TEXTURE)
-		{
-			if(mID == facep->getTexture()->getID()) //this is a parcel media
-			{
-				return; //let the prim media win.
-			}
-		}
-
-		if(mIsPlaying) //old textures switch to the media texture
-		{
-			facep->switchTexture(ch, this);
-		}
-		else //switch to old textures.
-		{
-			const LLTextureEntry* te = facep->getTextureEntry();
-			if(te)
-			{
-				LLViewerTexture* tex = te->getID().notNull() ? gTextureList.findImage(te->getID(), TEX_LIST_STANDARD) : NULL;
-				if(!tex && te->getID() != mID)//try parcel media.
-				{
-					tex = gTextureList.findImage(mID, TEX_LIST_STANDARD);
-				}
-				if(!tex)
-				{
-					tex = LLViewerFetchedTexture::sDefaultImagep;
-				}
-				facep->switchTexture(ch, tex);
-			}
-		}
-	}
-}
-
-void LLViewerMediaTexture::setPlaying(BOOL playing) 
-{
-	if(!mMediaImplp)
-	{
-		return; 
-	}
-	if(!playing && !mIsPlaying)
-	{
-		return; //media is already off
-	}
-
-	if(playing == mIsPlaying && !mMediaImplp->isUpdated())
-	{
-		return; //nothing has changed since last time.
-	}	
-
-	mIsPlaying = playing;
-	if(mIsPlaying) //is about to play this media
-	{
-		if(findFaces())
-		{
-			//about to update all faces.
-			mMediaImplp->setUpdated(FALSE);
-		}
-
-		if(mMediaFaceList.empty())//no face pointing to this media
-		{
-			stopPlaying();
-			return;
-		}
-
-		for(std::list< LLFace* >::iterator iter = mMediaFaceList.begin(); iter!= mMediaFaceList.end(); ++iter)
-		{
-			switchTexture(LLRender::DIFFUSE_MAP, *iter);
-		}
-	}
-	else //stop playing this media
-	{
-		U32 ch = LLRender::DIFFUSE_MAP;
-		
-		llassert(mNumFaces[ch] <= mFaceList[ch].size());
-		for(U32 i = mNumFaces[ch]; i; i--)
-		{
-			switchTexture(ch, mFaceList[ch][i - 1]); //current face could be removed in this function.
-		}
-	}
-	return;
-}
-
-//virtual 
-F32 LLViewerMediaTexture::getMaxVirtualSize() 
-{	
-	if(LLFrameTimer::getFrameCount() == mUpdateVirtualSizeTime)
-	{
-		return mMaxVirtualSize;
-	}
-	mUpdateVirtualSizeTime = LLFrameTimer::getFrameCount();
-
-	if(!mMaxVirtualSizeResetCounter)
-	{
-		addTextureStats(0.f, FALSE);//reset
-	}
-
-	if(mIsPlaying) //media is playing
-	{
-		for (U32 ch = 0; ch < LLRender::NUM_TEXTURE_CHANNELS; ++ch)
-		{
-			llassert(mNumFaces[ch] <= mFaceList[ch].size());
-			for(U32 i = 0; i < mNumFaces[ch]; i++)
-			{
-				LLFace* facep = mFaceList[ch][i];
-			if(facep->getDrawable()->isRecentlyVisible())
-			{
-				addTextureStats(facep->getVirtualSize());
-			}
-		}		
-	}
-	}
-	else //media is not in playing
-	{
-		findFaces();
-	
-		if(!mMediaFaceList.empty())
-		{
-			for(std::list< LLFace* >::iterator iter = mMediaFaceList.begin(); iter!= mMediaFaceList.end(); ++iter)
-			{
-				LLFace* facep = *iter;
-				if(facep->getDrawable()->isRecentlyVisible())
-				{
-					addTextureStats(facep->getVirtualSize());
-				}
-			}
-		}
-	}
-
-	if(mMaxVirtualSizeResetCounter > 0)
-	{
-		mMaxVirtualSizeResetCounter--;
-	}
-	reorganizeFaceList();
-	reorganizeVolumeList();
-
-	return mMaxVirtualSize;
-}
-//----------------------------------------------------------------------------------------------
-//end of LLViewerMediaTexture
-//----------------------------------------------------------------------------------------------
+    F32 total_gray_time = 0.f;
+    F32 total_stablizing_time = 0.f;
+    F32 total_loading_sculpties_time = 0.f;
 
-//----------------------------------------------------------------------------------------------
-//start of LLTexturePipelineTester
-//----------------------------------------------------------------------------------------------
-LLTexturePipelineTester::LLTexturePipelineTester() : LLMetricPerformanceTesterWithSession(sTesterName) 
-{
-	addMetric("TotalBytesLoaded");
-	addMetric("TotalBytesLoadedFromCache");
-	addMetric("TotalBytesLoadedForLargeImage");
-	addMetric("TotalBytesLoadedForSculpties");
-	addMetric("StartFetchingTime");
-	addMetric("TotalGrayTime");
-	addMetric("TotalStablizingTime");
-	addMetric("StartTimeLoadingSculpties");
-	addMetric("EndTimeLoadingSculpties");
-
-	addMetric("Time");
-	addMetric("TotalBytesBound");
-	addMetric("TotalBytesBoundForLargeImage");
-	addMetric("PercentageBytesBound");
-	
-	mTotalBytesLoaded = (S32Bytes)0;
-	mTotalBytesLoadedFromCache = (S32Bytes)0;	
-	mTotalBytesLoadedForLargeImage = (S32Bytes)0;
-	mTotalBytesLoadedForSculpties = (S32Bytes)0;
-
-	reset();
-}
+    F32 start_fetching_time = -1.f;
+    F32 start_fetching_sculpties_time = 0.f;
 
-LLTexturePipelineTester::~LLTexturePipelineTester()
-{
-	LLViewerTextureManager::sTesterp = NULL;
-}
+    F32 last_time = 0.0f;
+    S32 frame_count = 0;
 
-void LLTexturePipelineTester::update()
-{
-	mLastTotalBytesUsed = mTotalBytesUsed;
-	mLastTotalBytesUsedForLargeImage = mTotalBytesUsedForLargeImage;
-	mTotalBytesUsed = (S32Bytes)0;
-	mTotalBytesUsedForLargeImage = (S32Bytes)0;
-	
-	if(LLAppViewer::getTextureFetch()->getNumRequests() > 0) //fetching list is not empty
-	{
-		if(mPause)
-		{
-			//start a new fetching session
-			reset();
-			mStartFetchingTime = LLImageGL::sLastFrameTime;
-			mPause = FALSE;
-		}
-
-		//update total gray time		
-		if(mUsingDefaultTexture)
-		{
-			mUsingDefaultTexture = FALSE;
-			mTotalGrayTime = LLImageGL::sLastFrameTime - mStartFetchingTime;		
-		}
-
-		//update the stablizing timer.
-		updateStablizingTime();
-
-		outputTestResults();
-	}
-	else if(!mPause)
-	{
-		//stop the current fetching session
-		mPause = TRUE;
-		outputTestResults();
-		reset();
-	}		
-}
-	
-void LLTexturePipelineTester::reset() 
-{
-	mPause = TRUE;
-
-	mUsingDefaultTexture = FALSE;
-	mStartStablizingTime = 0.0f;
-	mEndStablizingTime = 0.0f;
-
-	mTotalBytesUsed = (S32Bytes)0;
-	mTotalBytesUsedForLargeImage = (S32Bytes)0;
-	mLastTotalBytesUsed = (S32Bytes)0;
-	mLastTotalBytesUsedForLargeImage = (S32Bytes)0;
-	
-	mStartFetchingTime = 0.0f;
-	
-	mTotalGrayTime = 0.0f;
-	mTotalStablizingTime = 0.0f;
-
-	mStartTimeLoadingSculpties = 1.0f;
-	mEndTimeLoadingSculpties = 0.0f;
-}
-
-//virtual 
-void LLTexturePipelineTester::outputTestRecord(LLSD *sd) 
-{	
-	std::string currentLabel = getCurrentLabelName();
-	(*sd)[currentLabel]["TotalBytesLoaded"]              = (LLSD::Integer)mTotalBytesLoaded.value();
-	(*sd)[currentLabel]["TotalBytesLoadedFromCache"]     = (LLSD::Integer)mTotalBytesLoadedFromCache.value();
-	(*sd)[currentLabel]["TotalBytesLoadedForLargeImage"] = (LLSD::Integer)mTotalBytesLoadedForLargeImage.value();
-	(*sd)[currentLabel]["TotalBytesLoadedForSculpties"]  = (LLSD::Integer)mTotalBytesLoadedForSculpties.value();
-
-	(*sd)[currentLabel]["StartFetchingTime"]             = (LLSD::Real)mStartFetchingTime;
-	(*sd)[currentLabel]["TotalGrayTime"]                 = (LLSD::Real)mTotalGrayTime;
-	(*sd)[currentLabel]["TotalStablizingTime"]           = (LLSD::Real)mTotalStablizingTime;
-
-	(*sd)[currentLabel]["StartTimeLoadingSculpties"]     = (LLSD::Real)mStartTimeLoadingSculpties;
-	(*sd)[currentLabel]["EndTimeLoadingSculpties"]       = (LLSD::Real)mEndTimeLoadingSculpties;
-
-	(*sd)[currentLabel]["Time"]                          = LLImageGL::sLastFrameTime;
-	(*sd)[currentLabel]["TotalBytesBound"]               = (LLSD::Integer)mLastTotalBytesUsed.value();
-	(*sd)[currentLabel]["TotalBytesBoundForLargeImage"]  = (LLSD::Integer)mLastTotalBytesUsedForLargeImage.value();
-	(*sd)[currentLabel]["PercentageBytesBound"]          = (LLSD::Real)(100.f * mLastTotalBytesUsed / mTotalBytesLoaded);
-}
-
-void LLTexturePipelineTester::updateTextureBindingStats(const LLViewerTexture* imagep) 
-{
-	U32Bytes mem_size = imagep->getTextureMemory();
-	mTotalBytesUsed += mem_size; 
-
-	if(MIN_LARGE_IMAGE_AREA <= (U32)(mem_size.value() / (U32)imagep->getComponents()))
-	{
-		mTotalBytesUsedForLargeImage += mem_size;
-	}
-}
-	
-void LLTexturePipelineTester::updateTextureLoadingStats(const LLViewerFetchedTexture* imagep, const LLImageRaw* raw_imagep, BOOL from_cache) 
-{
-	U32Bytes data_size = (U32Bytes)raw_imagep->getDataSize();
-	mTotalBytesLoaded += data_size;
-
-	if(from_cache)
-	{
-		mTotalBytesLoadedFromCache += data_size;
-	}
-
-	if(MIN_LARGE_IMAGE_AREA <= (U32)(data_size.value() / (U32)raw_imagep->getComponents()))
-	{
-		mTotalBytesLoadedForLargeImage += data_size;
-	}
-
-	if(imagep->forSculpt())
-	{
-		mTotalBytesLoadedForSculpties += data_size;
-
-		if(mStartTimeLoadingSculpties > mEndTimeLoadingSculpties)
-		{
-			mStartTimeLoadingSculpties = LLImageGL::sLastFrameTime;
-		}
-		mEndTimeLoadingSculpties = LLImageGL::sLastFrameTime;
-	}
-}
+    sessionp->mInstantPerformanceListCounter = 0;
+    sessionp->mInstantPerformanceList.resize(128);
+    sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedPerSecond = 0;
+    sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedForLargeImagePerSecond = 0;
+    sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAveragePercentageBytesUsedPerSecond = 0.f;
+    sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mTime = 0.f;
 
-void LLTexturePipelineTester::updateGrayTextureBinding()
-{
-	mUsingDefaultTexture = TRUE;
+    //load a session
+    std::string currentLabel = getCurrentLabelName();
+    BOOL in_log = (*log).has(currentLabel);
+    while (in_log)
+    {
+        LLSD::String label = currentLabel;
+
+        if(sessionp->mInstantPerformanceListCounter >= (S32)sessionp->mInstantPerformanceList.size())
+        {
+            sessionp->mInstantPerformanceList.resize(sessionp->mInstantPerformanceListCounter + 128);
+        }
+
+        //time
+        F32 start_time = (*log)[label]["StartFetchingTime"].asReal();
+        F32 cur_time   = (*log)[label]["Time"].asReal();
+        if(start_time - start_fetching_time > F_ALMOST_ZERO) //fetching has paused for a while
+        {
+            sessionp->mTotalGrayTime += total_gray_time;
+            sessionp->mTotalStablizingTime += total_stablizing_time;
+
+            sessionp->mStartTimeLoadingSculpties = start_fetching_sculpties_time;
+            sessionp->mTotalTimeLoadingSculpties += total_loading_sculpties_time;
+
+            start_fetching_time = start_time;
+            total_gray_time = 0.f;
+            total_stablizing_time = 0.f;
+            total_loading_sculpties_time = 0.f;
+        }
+        else
+        {
+            total_gray_time = (*log)[label]["TotalGrayTime"].asReal();
+            total_stablizing_time = (*log)[label]["TotalStablizingTime"].asReal();
+
+            total_loading_sculpties_time = (*log)[label]["EndTimeLoadingSculpties"].asReal() - (*log)[label]["StartTimeLoadingSculpties"].asReal();
+            if(start_fetching_sculpties_time < 0.f && total_loading_sculpties_time > 0.f)
+            {
+                start_fetching_sculpties_time = (*log)[label]["StartTimeLoadingSculpties"].asReal();
+            }
+        }
+
+        //total loaded bytes
+        sessionp->mTotalBytesLoaded = (*log)[label]["TotalBytesLoaded"].asInteger();
+        sessionp->mTotalBytesLoadedFromCache = (*log)[label]["TotalBytesLoadedFromCache"].asInteger();
+        sessionp->mTotalBytesLoadedForLargeImage = (*log)[label]["TotalBytesLoadedForLargeImage"].asInteger();
+        sessionp->mTotalBytesLoadedForSculpties = (*log)[label]["TotalBytesLoadedForSculpties"].asInteger();
+
+        //instant metrics
+        sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedPerSecond +=
+            (*log)[label]["TotalBytesBound"].asInteger();
+        sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedForLargeImagePerSecond +=
+            (*log)[label]["TotalBytesBoundForLargeImage"].asInteger();
+        sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAveragePercentageBytesUsedPerSecond +=
+            (*log)[label]["PercentageBytesBound"].asReal();
+        frame_count++;
+        if(cur_time - last_time >= 1.0f)
+        {
+            sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedPerSecond /= frame_count;
+            sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedForLargeImagePerSecond /= frame_count;
+            sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAveragePercentageBytesUsedPerSecond /= frame_count;
+            sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mTime = last_time;
+
+            frame_count = 0;
+            last_time = cur_time;
+            sessionp->mInstantPerformanceListCounter++;
+            sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedPerSecond = 0;
+            sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedForLargeImagePerSecond = 0;
+            sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAveragePercentageBytesUsedPerSecond = 0.f;
+            sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mTime = 0.f;
+        }
+        // Next label
+        incrementCurrentCount();
+        currentLabel = getCurrentLabelName();
+        in_log = (*log).has(currentLabel);
+    }
+
+    sessionp->mTotalGrayTime += total_gray_time;
+    sessionp->mTotalStablizingTime += total_stablizing_time;
+
+    if(sessionp->mStartTimeLoadingSculpties < 0.f)
+    {
+        sessionp->mStartTimeLoadingSculpties = start_fetching_sculpties_time;
+    }
+    sessionp->mTotalTimeLoadingSculpties += total_loading_sculpties_time;
+
+    return sessionp;
 }
 
-void LLTexturePipelineTester::setStablizingTime()
+LLTexturePipelineTester::LLTextureTestSession::LLTextureTestSession()
 {
-	if(mStartStablizingTime <= mStartFetchingTime)
-	{
-		mStartStablizingTime = LLImageGL::sLastFrameTime;
-	}
-	mEndStablizingTime = LLImageGL::sLastFrameTime;
+    reset();
 }
-
-void LLTexturePipelineTester::updateStablizingTime()
+LLTexturePipelineTester::LLTextureTestSession::~LLTextureTestSession()
 {
-	if(mStartStablizingTime > mStartFetchingTime)
-	{
-		F32 t = mEndStablizingTime - mStartStablizingTime;
-
-		if(t > F_ALMOST_ZERO && (t - mTotalStablizingTime) < F_ALMOST_ZERO)
-		{
-			//already stablized
-			mTotalStablizingTime = LLImageGL::sLastFrameTime - mStartStablizingTime;
-
-			//cancel the timer
-			mStartStablizingTime = 0.f;
-			mEndStablizingTime = 0.f;
-		}
-		else
-		{
-			mTotalStablizingTime = t;
-		}
-	}
-	mTotalStablizingTime = 0.f;
-}
-
-//virtual 
-void LLTexturePipelineTester::compareTestSessions(llofstream* os) 
-{	
-	LLTexturePipelineTester::LLTextureTestSession* base_sessionp = dynamic_cast<LLTexturePipelineTester::LLTextureTestSession*>(mBaseSessionp);
-	LLTexturePipelineTester::LLTextureTestSession* current_sessionp = dynamic_cast<LLTexturePipelineTester::LLTextureTestSession*>(mCurrentSessionp);
-	if(!base_sessionp || !current_sessionp)
-	{
-		LL_ERRS() << "type of test session does not match!" << LL_ENDL;
-	}
-
-	//compare and output the comparison
-	*os << llformat("%s\n", getTesterName().c_str());
-	*os << llformat("AggregateResults\n");
-
-	compareTestResults(os, "TotalGrayTime", base_sessionp->mTotalGrayTime, current_sessionp->mTotalGrayTime);
-	compareTestResults(os, "TotalStablizingTime", base_sessionp->mTotalStablizingTime, current_sessionp->mTotalStablizingTime);
-	compareTestResults(os, "StartTimeLoadingSculpties", base_sessionp->mStartTimeLoadingSculpties, current_sessionp->mStartTimeLoadingSculpties);		
-	compareTestResults(os, "TotalTimeLoadingSculpties", base_sessionp->mTotalTimeLoadingSculpties, current_sessionp->mTotalTimeLoadingSculpties);
-	
-	compareTestResults(os, "TotalBytesLoaded", base_sessionp->mTotalBytesLoaded, current_sessionp->mTotalBytesLoaded);
-	compareTestResults(os, "TotalBytesLoadedFromCache", base_sessionp->mTotalBytesLoadedFromCache, current_sessionp->mTotalBytesLoadedFromCache);
-	compareTestResults(os, "TotalBytesLoadedForLargeImage", base_sessionp->mTotalBytesLoadedForLargeImage, current_sessionp->mTotalBytesLoadedForLargeImage);
-	compareTestResults(os, "TotalBytesLoadedForSculpties", base_sessionp->mTotalBytesLoadedForSculpties, current_sessionp->mTotalBytesLoadedForSculpties);
-		
-	*os << llformat("InstantResults\n");
-	S32 size = llmin(base_sessionp->mInstantPerformanceListCounter, current_sessionp->mInstantPerformanceListCounter);
-	for(S32 i = 0; i < size; i++)
-	{
-		*os << llformat("Time(B-T)-%.4f-%.4f\n", base_sessionp->mInstantPerformanceList[i].mTime, current_sessionp->mInstantPerformanceList[i].mTime);
-
-		compareTestResults(os, "AverageBytesUsedPerSecond", base_sessionp->mInstantPerformanceList[i].mAverageBytesUsedPerSecond,
-			current_sessionp->mInstantPerformanceList[i].mAverageBytesUsedPerSecond);
-			
-		compareTestResults(os, "AverageBytesUsedForLargeImagePerSecond", base_sessionp->mInstantPerformanceList[i].mAverageBytesUsedForLargeImagePerSecond,
-			current_sessionp->mInstantPerformanceList[i].mAverageBytesUsedForLargeImagePerSecond);
-			
-		compareTestResults(os, "AveragePercentageBytesUsedPerSecond", base_sessionp->mInstantPerformanceList[i].mAveragePercentageBytesUsedPerSecond,
-			current_sessionp->mInstantPerformanceList[i].mAveragePercentageBytesUsedPerSecond);
-	}
-	
-	if(size < base_sessionp->mInstantPerformanceListCounter)
-	{
-		for(S32 i = size; i < base_sessionp->mInstantPerformanceListCounter; i++)
-		{
-			*os << llformat("Time(B-T)-%.4f- \n", base_sessionp->mInstantPerformanceList[i].mTime);
-
-			*os << llformat(", AverageBytesUsedPerSecond, %d, N/A \n", base_sessionp->mInstantPerformanceList[i].mAverageBytesUsedPerSecond);
-			*os << llformat(", AverageBytesUsedForLargeImagePerSecond, %d, N/A \n", base_sessionp->mInstantPerformanceList[i].mAverageBytesUsedForLargeImagePerSecond);				
-			*os << llformat(", AveragePercentageBytesUsedPerSecond, %.4f, N/A \n", base_sessionp->mInstantPerformanceList[i].mAveragePercentageBytesUsedPerSecond);			
-		}
-	}
-	else if(size < current_sessionp->mInstantPerformanceListCounter)
-	{
-		for(S32 i = size; i < current_sessionp->mInstantPerformanceListCounter; i++)
-		{
-			*os << llformat("Time(B-T)- -%.4f\n", current_sessionp->mInstantPerformanceList[i].mTime);
-
-			*os << llformat(", AverageBytesUsedPerSecond, N/A, %d\n", current_sessionp->mInstantPerformanceList[i].mAverageBytesUsedPerSecond);
-			*os << llformat(", AverageBytesUsedForLargeImagePerSecond, N/A, %d\n", current_sessionp->mInstantPerformanceList[i].mAverageBytesUsedForLargeImagePerSecond);				
-			*os << llformat(", AveragePercentageBytesUsedPerSecond, N/A, %.4f\n", current_sessionp->mInstantPerformanceList[i].mAveragePercentageBytesUsedPerSecond);			
-		}
-	}
-}
-
-//virtual 
-LLMetricPerformanceTesterWithSession::LLTestSession* LLTexturePipelineTester::loadTestSession(LLSD* log)
+}
+void LLTexturePipelineTester::LLTextureTestSession::reset()
 {
-	LLTexturePipelineTester::LLTextureTestSession* sessionp = new LLTexturePipelineTester::LLTextureTestSession();
-	if(!sessionp)
-	{
-		return NULL;
-	}
-	
-	F32 total_gray_time = 0.f;
-	F32 total_stablizing_time = 0.f;
-	F32 total_loading_sculpties_time = 0.f;
-
-	F32 start_fetching_time = -1.f;
-	F32 start_fetching_sculpties_time = 0.f;
-
-	F32 last_time = 0.0f;
-	S32 frame_count = 0;
-
-	sessionp->mInstantPerformanceListCounter = 0;
-	sessionp->mInstantPerformanceList.resize(128);
-	sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedPerSecond = 0;
-	sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedForLargeImagePerSecond = 0;
-	sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAveragePercentageBytesUsedPerSecond = 0.f;
-	sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mTime = 0.f;
-	
-	//load a session
-	std::string currentLabel = getCurrentLabelName();
-	BOOL in_log = (*log).has(currentLabel);
-	while (in_log)
-	{
-		LLSD::String label = currentLabel;		
-
-		if(sessionp->mInstantPerformanceListCounter >= (S32)sessionp->mInstantPerformanceList.size())
-		{
-			sessionp->mInstantPerformanceList.resize(sessionp->mInstantPerformanceListCounter + 128);
-		}
-		
-		//time
-		F32 start_time = (*log)[label]["StartFetchingTime"].asReal();
-		F32 cur_time   = (*log)[label]["Time"].asReal();
-		if(start_time - start_fetching_time > F_ALMOST_ZERO) //fetching has paused for a while
-		{
-			sessionp->mTotalGrayTime += total_gray_time;
-			sessionp->mTotalStablizingTime += total_stablizing_time;
-
-			sessionp->mStartTimeLoadingSculpties = start_fetching_sculpties_time; 
-			sessionp->mTotalTimeLoadingSculpties += total_loading_sculpties_time;
-
-			start_fetching_time = start_time;
-			total_gray_time = 0.f;
-			total_stablizing_time = 0.f;
-			total_loading_sculpties_time = 0.f;
-		}
-		else
-		{
-			total_gray_time = (*log)[label]["TotalGrayTime"].asReal();
-			total_stablizing_time = (*log)[label]["TotalStablizingTime"].asReal();
-
-			total_loading_sculpties_time = (*log)[label]["EndTimeLoadingSculpties"].asReal() - (*log)[label]["StartTimeLoadingSculpties"].asReal();
-			if(start_fetching_sculpties_time < 0.f && total_loading_sculpties_time > 0.f)
-			{
-				start_fetching_sculpties_time = (*log)[label]["StartTimeLoadingSculpties"].asReal();
-			}			
-		}
-		
-		//total loaded bytes
-		sessionp->mTotalBytesLoaded = (*log)[label]["TotalBytesLoaded"].asInteger(); 
-		sessionp->mTotalBytesLoadedFromCache = (*log)[label]["TotalBytesLoadedFromCache"].asInteger();
-		sessionp->mTotalBytesLoadedForLargeImage = (*log)[label]["TotalBytesLoadedForLargeImage"].asInteger();
-		sessionp->mTotalBytesLoadedForSculpties = (*log)[label]["TotalBytesLoadedForSculpties"].asInteger(); 
-
-		//instant metrics			
-		sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedPerSecond +=
-			(*log)[label]["TotalBytesBound"].asInteger();
-		sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedForLargeImagePerSecond +=
-			(*log)[label]["TotalBytesBoundForLargeImage"].asInteger();
-		sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAveragePercentageBytesUsedPerSecond +=
-			(*log)[label]["PercentageBytesBound"].asReal();
-		frame_count++;
-		if(cur_time - last_time >= 1.0f)
-		{
-			sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedPerSecond /= frame_count;
-			sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedForLargeImagePerSecond /= frame_count;
-			sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAveragePercentageBytesUsedPerSecond /= frame_count;
-			sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mTime = last_time;
-
-			frame_count = 0;
-			last_time = cur_time;
-			sessionp->mInstantPerformanceListCounter++;
-			sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedPerSecond = 0;
-			sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAverageBytesUsedForLargeImagePerSecond = 0;
-			sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mAveragePercentageBytesUsedPerSecond = 0.f;
-			sessionp->mInstantPerformanceList[sessionp->mInstantPerformanceListCounter].mTime = 0.f;
-		}
-		// Next label
-		incrementCurrentCount();
-		currentLabel = getCurrentLabelName();
-		in_log = (*log).has(currentLabel);
-	}
-
-	sessionp->mTotalGrayTime += total_gray_time;
-	sessionp->mTotalStablizingTime += total_stablizing_time;
-
-	if(sessionp->mStartTimeLoadingSculpties < 0.f)
-	{
-		sessionp->mStartTimeLoadingSculpties = start_fetching_sculpties_time; 
-	}
-	sessionp->mTotalTimeLoadingSculpties += total_loading_sculpties_time;
-
-	return sessionp;
-}
-
-LLTexturePipelineTester::LLTextureTestSession::LLTextureTestSession() 
-{
-	reset();
-}
-LLTexturePipelineTester::LLTextureTestSession::~LLTextureTestSession() 
-{
-}
-void LLTexturePipelineTester::LLTextureTestSession::reset() 
-{
-	mTotalGrayTime = 0.0f;
-	mTotalStablizingTime = 0.0f;
-
-	mStartTimeLoadingSculpties = 0.0f; 
-	mTotalTimeLoadingSculpties = 0.0f;
-
-	mTotalBytesLoaded = 0; 
-	mTotalBytesLoadedFromCache = 0;
-	mTotalBytesLoadedForLargeImage = 0;
-	mTotalBytesLoadedForSculpties = 0; 
-
-	mInstantPerformanceListCounter = 0;
+    mTotalGrayTime = 0.0f;
+    mTotalStablizingTime = 0.0f;
+
+    mStartTimeLoadingSculpties = 0.0f;
+    mTotalTimeLoadingSculpties = 0.0f;
+
+    mTotalBytesLoaded = 0;
+    mTotalBytesLoadedFromCache = 0;
+    mTotalBytesLoadedForLargeImage = 0;
+    mTotalBytesLoadedForSculpties = 0;
+
+    mInstantPerformanceListCounter = 0;
 }
 //----------------------------------------------------------------------------------------------
 //end of LLTexturePipelineTester
diff --git a/indra/newview/llviewertexture.h b/indra/newview/llviewertexture.h
index 4819131a70872d2d6a277816cb80d76b89c3b4ba..c726fea86c6a3bd997a7dea34826a0edcb9e2923 100644
--- a/indra/newview/llviewertexture.h
+++ b/indra/newview/llviewertexture.h
@@ -1,30 +1,30 @@
-/** 
+/**
  * @file llviewertexture.h
  * @brief Object for managing images and their textures
  *
  * $LicenseInfo:firstyear=2000&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
 
-#ifndef LL_LLVIEWERTEXTURE_H					
+#ifndef LL_LLVIEWERTEXTURE_H
 #define LL_LLVIEWERTEXTURE_H
 
 #include "llatomic.h"
@@ -54,7 +54,7 @@ class LLViewerMediaTexture ;
 class LLTexturePipelineTester ;
 
 
-typedef	void	(*loaded_callback_func)( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata );
+typedef void    (*loaded_callback_func)( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* src_aux, S32 discard_level, BOOL final, void* userdata );
 
 class LLMessageSystem;
 class LLViewerMediaImpl ;
@@ -67,26 +67,26 @@ class LLLoadedCallbackEntry
     typedef std::set< LLTextureKey > source_callback_list_t;
 
 public:
-	LLLoadedCallbackEntry(loaded_callback_func cb,
-						  S32 discard_level,
-						  BOOL need_imageraw, // Needs image raw for the callback
-						  void* userdata,
-						  source_callback_list_t* src_callback_list,
-						  LLViewerFetchedTexture* target,
-						  BOOL pause);
-	~LLLoadedCallbackEntry();
-	void removeTexture(LLViewerFetchedTexture* tex) ;
-
-	loaded_callback_func	mCallback;
-	S32						mLastUsedDiscard;
-	S32						mDesiredDiscard;
-	BOOL					mNeedsImageRaw;
-	BOOL                    mPaused;
-	void*					mUserData;
-	source_callback_list_t* mSourceCallbackList;
-	
+    LLLoadedCallbackEntry(loaded_callback_func cb,
+                          S32 discard_level,
+                          BOOL need_imageraw, // Needs image raw for the callback
+                          void* userdata,
+                          source_callback_list_t* src_callback_list,
+                          LLViewerFetchedTexture* target,
+                          BOOL pause);
+    ~LLLoadedCallbackEntry();
+    void removeTexture(LLViewerFetchedTexture* tex) ;
+
+    loaded_callback_func    mCallback;
+    S32                     mLastUsedDiscard;
+    S32                     mDesiredDiscard;
+    BOOL                    mNeedsImageRaw;
+    BOOL                    mPaused;
+    void*                   mUserData;
+    source_callback_list_t* mSourceCallbackList;
+
 public:
-	static void cleanUpCallbackList(LLLoadedCallbackEntry::source_callback_list_t* callback_list) ;
+    static void cleanUpCallbackList(LLLoadedCallbackEntry::source_callback_list_t* callback_list) ;
 };
 
 class LLTextureBar;
@@ -94,163 +94,163 @@ class LLTextureBar;
 class LLViewerTexture : public LLGLTexture
 {
 public:
-	enum
-	{
-		LOCAL_TEXTURE,		
-		MEDIA_TEXTURE,
-		DYNAMIC_TEXTURE,
-		FETCHED_TEXTURE,
-		LOD_TEXTURE,
-		ATLAS_TEXTURE,
-		INVALID_TEXTURE_TYPE
-	};
+    enum
+    {
+        LOCAL_TEXTURE,
+        MEDIA_TEXTURE,
+        DYNAMIC_TEXTURE,
+        FETCHED_TEXTURE,
+        LOD_TEXTURE,
+        ATLAS_TEXTURE,
+        INVALID_TEXTURE_TYPE
+    };
 
-	typedef std::vector<class LLFace*> ll_face_list_t;
-	typedef std::vector<LLVOVolume*> ll_volume_list_t;
+    typedef std::vector<class LLFace*> ll_face_list_t;
+    typedef std::vector<LLVOVolume*> ll_volume_list_t;
 
 
 protected:
-	virtual ~LLViewerTexture();
-	LOG_CLASS(LLViewerTexture);
-
-public:	
-	static void initClass();
-	static void updateClass();
-	
-	LLViewerTexture(BOOL usemipmaps = TRUE);
-	LLViewerTexture(const LLUUID& id, BOOL usemipmaps) ;
-	LLViewerTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
-	LLViewerTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) ;
-
-	virtual S8 getType() const;
-	virtual BOOL isMissingAsset() const ;
-	virtual void dump();	// debug info to LL_INFOS()
-	
+    virtual ~LLViewerTexture();
+    LOG_CLASS(LLViewerTexture);
+
+public:
+    static void initClass();
+    static void updateClass();
+
+    LLViewerTexture(BOOL usemipmaps = TRUE);
+    LLViewerTexture(const LLUUID& id, BOOL usemipmaps) ;
+    LLViewerTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
+    LLViewerTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps) ;
+
+    virtual S8 getType() const;
+    virtual BOOL isMissingAsset() const ;
+    virtual void dump();    // debug info to LL_INFOS()
+
     virtual bool isViewerMediaTexture() const { return false; }
 
-	/*virtual*/ bool bindDefaultImage(const S32 stage = 0) ;
-	/*virtual*/ bool bindDebugImage(const S32 stage = 0) ;
-	/*virtual*/ void forceImmediateUpdate() ;
-	/*virtual*/ bool isActiveFetching();
-	
-	/*virtual*/ const LLUUID& getID() const { return mID; }
-	virtual void setBoostLevel(S32 level);
-	S32  getBoostLevel() { return mBoostLevel; }
-	void setTextureListType(S32 tex_type) { mTextureListType = tex_type; }
-	S32 getTextureListType() { return mTextureListType; }
-
-	void addTextureStats(F32 virtual_size, BOOL needs_gltexture = TRUE) const;
-	void resetTextureStats();	
-	void setMaxVirtualSizeResetInterval(S32 interval)const {mMaxVirtualSizeResetInterval = interval;}
-	void resetMaxVirtualSizeResetCounter()const {mMaxVirtualSizeResetCounter = mMaxVirtualSizeResetInterval;}
-	S32 getMaxVirtualSizeResetCounter() const { return mMaxVirtualSizeResetCounter; }
-
-	virtual F32  getMaxVirtualSize() ;
-
-	LLFrameTimer* getLastReferencedTimer() {return &mLastReferencedTimer ;}
-	
-	S32 getFullWidth() const { return mFullWidth; }
-	S32 getFullHeight() const { return mFullHeight; }	
-	/*virtual*/ void setKnownDrawSize(S32 width, S32 height);
-
-	virtual void addFace(U32 channel, LLFace* facep) ;
-	virtual void removeFace(U32 channel, LLFace* facep) ; 
-	S32 getTotalNumFaces() const;
-	S32 getNumFaces(U32 ch) const;
-	const ll_face_list_t* getFaceList(U32 channel) const {llassert(channel < LLRender::NUM_TEXTURE_CHANNELS); return &mFaceList[channel];}
-
-	virtual void addVolume(U32 channel, LLVOVolume* volumep);
-	virtual void removeVolume(U32 channel, LLVOVolume* volumep);
-	S32 getNumVolumes(U32 channel) const;
-	const ll_volume_list_t* getVolumeList(U32 channel) const { return &mVolumeList[channel]; }
-
-	
-	virtual void setCachedRawImage(S32 discard_level, LLImageRaw* imageraw) ;
-	BOOL isLargeImage() ;	
-	
-	void setParcelMedia(LLViewerMediaTexture* media) {mParcelMedia = media;}
-	BOOL hasParcelMedia() const { return mParcelMedia != NULL;}
-	LLViewerMediaTexture* getParcelMedia() const { return mParcelMedia;}
-
-	/*virtual*/ void updateBindStatsForTester() ;
+    /*virtual*/ bool bindDefaultImage(const S32 stage = 0) ;
+    /*virtual*/ bool bindDebugImage(const S32 stage = 0) ;
+    /*virtual*/ void forceImmediateUpdate() ;
+    /*virtual*/ bool isActiveFetching();
+
+    /*virtual*/ const LLUUID& getID() const { return mID; }
+    virtual void setBoostLevel(S32 level);
+    S32  getBoostLevel() { return mBoostLevel; }
+    void setTextureListType(S32 tex_type) { mTextureListType = tex_type; }
+    S32 getTextureListType() { return mTextureListType; }
+
+    void addTextureStats(F32 virtual_size, BOOL needs_gltexture = TRUE) const;
+    void resetTextureStats();
+    void setMaxVirtualSizeResetInterval(S32 interval)const {mMaxVirtualSizeResetInterval = interval;}
+    void resetMaxVirtualSizeResetCounter()const {mMaxVirtualSizeResetCounter = mMaxVirtualSizeResetInterval;}
+    S32 getMaxVirtualSizeResetCounter() const { return mMaxVirtualSizeResetCounter; }
+
+    virtual F32  getMaxVirtualSize() ;
+
+    LLFrameTimer* getLastReferencedTimer() {return &mLastReferencedTimer ;}
+
+    S32 getFullWidth() const { return mFullWidth; }
+    S32 getFullHeight() const { return mFullHeight; }
+    /*virtual*/ void setKnownDrawSize(S32 width, S32 height);
+
+    virtual void addFace(U32 channel, LLFace* facep) ;
+    virtual void removeFace(U32 channel, LLFace* facep) ;
+    S32 getTotalNumFaces() const;
+    S32 getNumFaces(U32 ch) const;
+    const ll_face_list_t* getFaceList(U32 channel) const {llassert(channel < LLRender::NUM_TEXTURE_CHANNELS); return &mFaceList[channel];}
+
+    virtual void addVolume(U32 channel, LLVOVolume* volumep);
+    virtual void removeVolume(U32 channel, LLVOVolume* volumep);
+    S32 getNumVolumes(U32 channel) const;
+    const ll_volume_list_t* getVolumeList(U32 channel) const { return &mVolumeList[channel]; }
+
+
+    virtual void setCachedRawImage(S32 discard_level, LLImageRaw* imageraw) ;
+    BOOL isLargeImage() ;
+
+    void setParcelMedia(LLViewerMediaTexture* media) {mParcelMedia = media;}
+    BOOL hasParcelMedia() const { return mParcelMedia != NULL;}
+    LLViewerMediaTexture* getParcelMedia() const { return mParcelMedia;}
+
+    /*virtual*/ void updateBindStatsForTester() ;
 protected:
-	void cleanup() ;
-	void init(bool firstinit) ;
-	void reorganizeFaceList() ;
-	void reorganizeVolumeList();
+    void cleanup() ;
+    void init(bool firstinit) ;
+    void reorganizeFaceList() ;
+    void reorganizeVolumeList();
 
 private:
-	friend class LLBumpImageList;
-	friend class LLUIImageList;
+    friend class LLBumpImageList;
+    friend class LLUIImageList;
 
-	virtual void switchToCachedImage();
-	
-	static void getGPUMemoryForTextures(S32Megabytes &gpu, S32Megabytes &physical);
+    virtual void switchToCachedImage();
+
+    static void getGPUMemoryForTextures(S32Megabytes &gpu, S32Megabytes &physical);
 
 public:
     static bool isMemoryForTextureLow();
 protected:
     friend class LLViewerTextureList;
-	LLUUID mID;
-	S32 mTextureListType; // along with mID identifies where to search for this texture in TextureList
+    LLUUID mID;
+    S32 mTextureListType; // along with mID identifies where to search for this texture in TextureList
 
-	mutable F32 mMaxVirtualSize = 0.f;	// The largest virtual size of the image, in pixels - how much data to we need?	
-	mutable S32  mMaxVirtualSizeResetCounter;
-	mutable S32  mMaxVirtualSizeResetInterval;
-	LLFrameTimer mLastReferencedTimer;	
+    mutable F32 mMaxVirtualSize = 0.f;  // The largest virtual size of the image, in pixels - how much data to we need?
+    mutable S32  mMaxVirtualSizeResetCounter;
+    mutable S32  mMaxVirtualSizeResetInterval;
+    LLFrameTimer mLastReferencedTimer;
 
-	ll_face_list_t    mFaceList[LLRender::NUM_TEXTURE_CHANNELS]; //reverse pointer pointing to the faces using this image as texture
-	U32               mNumFaces[LLRender::NUM_TEXTURE_CHANNELS];
-	LLFrameTimer      mLastFaceListUpdateTimer ;
+    ll_face_list_t    mFaceList[LLRender::NUM_TEXTURE_CHANNELS]; //reverse pointer pointing to the faces using this image as texture
+    U32               mNumFaces[LLRender::NUM_TEXTURE_CHANNELS];
+    LLFrameTimer      mLastFaceListUpdateTimer ;
 
-	ll_volume_list_t  mVolumeList[LLRender::NUM_VOLUME_TEXTURE_CHANNELS];
-	U32					mNumVolumes[LLRender::NUM_VOLUME_TEXTURE_CHANNELS];
-	LLFrameTimer	  mLastVolumeListUpdateTimer;
+    ll_volume_list_t  mVolumeList[LLRender::NUM_VOLUME_TEXTURE_CHANNELS];
+    U32                 mNumVolumes[LLRender::NUM_VOLUME_TEXTURE_CHANNELS];
+    LLFrameTimer      mLastVolumeListUpdateTimer;
 
-	//do not use LLPointer here.
-	LLViewerMediaTexture* mParcelMedia ;
+    //do not use LLPointer here.
+    LLViewerMediaTexture* mParcelMedia ;
 
-	LL::WorkQueue::weak_t mMainQueue;
-	LL::WorkQueue::weak_t mImageQueue;
+    LL::WorkQueue::weak_t mMainQueue;
+    LL::WorkQueue::weak_t mImageQueue;
 
 public:
-	static const U32 sCurrentFileVersion;	
-	static S32 sImageCount;
-	static S32 sRawCount;
-	static S32 sAuxCount;
-	static LLFrameTimer sEvaluationTimer;
-	static F32 sDesiredDiscardBias;
-	static F32 sDesiredDiscardScale;
-	static S32 sMaxSculptRez ;
-	static U32 sMinLargeImageSize ;
-	static U32 sMaxSmallImageSize ;
-	static bool sFreezeImageUpdates;
-	static F32  sCurrentTime ;
-
-	enum EDebugTexels
-	{
-		DEBUG_TEXELS_OFF,
-		DEBUG_TEXELS_CURRENT,
-		DEBUG_TEXELS_DESIRED,
-		DEBUG_TEXELS_FULL
-	};
-
-	static EDebugTexels sDebugTexelsMode;
-
-	static LLPointer<LLViewerTexture> sNullImagep; // Null texture for non-textured objects.
-	static LLPointer<LLViewerTexture> sBlackImagep;	// Texture to show NOTHING (pure black)
-	static LLPointer<LLViewerTexture> sCheckerBoardImagep;	// Texture to show NOTHING (pure black)
+    static const U32 sCurrentFileVersion;
+    static S32 sImageCount;
+    static S32 sRawCount;
+    static S32 sAuxCount;
+    static LLFrameTimer sEvaluationTimer;
+    static F32 sDesiredDiscardBias;
+    static F32 sDesiredDiscardScale;
+    static S32 sMaxSculptRez ;
+    static U32 sMinLargeImageSize ;
+    static U32 sMaxSmallImageSize ;
+    static bool sFreezeImageUpdates;
+    static F32  sCurrentTime ;
+
+    enum EDebugTexels
+    {
+        DEBUG_TEXELS_OFF,
+        DEBUG_TEXELS_CURRENT,
+        DEBUG_TEXELS_DESIRED,
+        DEBUG_TEXELS_FULL
+    };
+
+    static EDebugTexels sDebugTexelsMode;
+
+    static LLPointer<LLViewerTexture> sNullImagep; // Null texture for non-textured objects.
+    static LLPointer<LLViewerTexture> sBlackImagep; // Texture to show NOTHING (pure black)
+    static LLPointer<LLViewerTexture> sCheckerBoardImagep;  // Texture to show NOTHING (pure black)
 };
 
 
 enum FTType
 {
-	FTT_UNKNOWN = -1,
-	FTT_DEFAULT = 0, // standard texture fetched by id.
-	FTT_SERVER_BAKE, // texture produced by appearance service and fetched from there.
-	FTT_HOST_BAKE, // old-style baked texture uploaded by viewer and fetched from avatar's host.
-	FTT_MAP_TILE, // tiles are fetched from map server directly.
-	FTT_LOCAL_FILE // fetch directly from a local file.
+    FTT_UNKNOWN = -1,
+    FTT_DEFAULT = 0, // standard texture fetched by id.
+    FTT_SERVER_BAKE, // texture produced by appearance service and fetched from there.
+    FTT_HOST_BAKE, // old-style baked texture uploaded by viewer and fetched from avatar's host.
+    FTT_MAP_TILE, // tiles are fetched from map server directly.
+    FTT_LOCAL_FILE // fetch directly from a local file.
 };
 
 const std::string& fttype_to_string(const FTType& fttype);
@@ -262,284 +262,284 @@ const std::string& fttype_to_string(const FTType& fttype);
 //
 class LLViewerFetchedTexture : public LLViewerTexture
 {
-	friend class LLTextureBar; // debug info only
-	friend class LLTextureView; // debug info only
+    friend class LLTextureBar; // debug info only
+    friend class LLTextureView; // debug info only
 
 protected:
-	/*virtual*/ ~LLViewerFetchedTexture();
+    /*virtual*/ ~LLViewerFetchedTexture();
 public:
-	LLViewerFetchedTexture(const LLUUID& id, FTType f_type, const LLHost& host = LLHost(), BOOL usemipmaps = TRUE);
-	LLViewerFetchedTexture(const LLImageRaw* raw, FTType f_type, BOOL usemipmaps);
-	LLViewerFetchedTexture(const std::string& url, FTType f_type, const LLUUID& id, BOOL usemipmaps = TRUE);
+    LLViewerFetchedTexture(const LLUUID& id, FTType f_type, const LLHost& host = LLHost(), BOOL usemipmaps = TRUE);
+    LLViewerFetchedTexture(const LLImageRaw* raw, FTType f_type, BOOL usemipmaps);
+    LLViewerFetchedTexture(const std::string& url, FTType f_type, const LLUUID& id, BOOL usemipmaps = TRUE);
 
 public:
-	
-	struct Compare
-	{
-		// lhs < rhs
-		bool operator()(const LLPointer<LLViewerFetchedTexture> &lhs, const LLPointer<LLViewerFetchedTexture> &rhs) const
-		{
-			const LLViewerFetchedTexture* lhsp = (const LLViewerFetchedTexture*)lhs;
-			const LLViewerFetchedTexture* rhsp = (const LLViewerFetchedTexture*)rhs;
-            
-			// greater priority is "less"
-			const F32 lpriority = lhsp->mMaxVirtualSize;
-			const F32 rpriority = rhsp->mMaxVirtualSize;
-			if (lpriority > rpriority) // higher priority
-				return true;
-			if (lpriority < rpriority)
-				return false;
-			return lhsp < rhsp;
-		}
-	};
+
+    struct Compare
+    {
+        // lhs < rhs
+        bool operator()(const LLPointer<LLViewerFetchedTexture> &lhs, const LLPointer<LLViewerFetchedTexture> &rhs) const
+        {
+            const LLViewerFetchedTexture* lhsp = (const LLViewerFetchedTexture*)lhs;
+            const LLViewerFetchedTexture* rhsp = (const LLViewerFetchedTexture*)rhs;
+
+            // greater priority is "less"
+            const F32 lpriority = lhsp->mMaxVirtualSize;
+            const F32 rpriority = rhsp->mMaxVirtualSize;
+            if (lpriority > rpriority) // higher priority
+                return true;
+            if (lpriority < rpriority)
+                return false;
+            return lhsp < rhsp;
+        }
+    };
 
 public:
-	/*virtual*/ S8 getType() const override;
-	FTType getFTType() const;
-	/*virtual*/ void forceImmediateUpdate() override;
-	/*virtual*/ void dump() override;
-
-	// Set callbacks to get called when the image gets updated with higher 
-	// resolution versions.
-	void setLoadedCallback(loaded_callback_func cb,
-						   S32 discard_level, BOOL keep_imageraw, BOOL needs_aux,
-						   void* userdata, LLLoadedCallbackEntry::source_callback_list_t* src_callback_list, BOOL pause = FALSE);
+    /*virtual*/ S8 getType() const override;
+    FTType getFTType() const;
+    /*virtual*/ void forceImmediateUpdate() override;
+    /*virtual*/ void dump() override;
+
+    // Set callbacks to get called when the image gets updated with higher
+    // resolution versions.
+    void setLoadedCallback(loaded_callback_func cb,
+                           S32 discard_level, BOOL keep_imageraw, BOOL needs_aux,
+                           void* userdata, LLLoadedCallbackEntry::source_callback_list_t* src_callback_list, BOOL pause = FALSE);
     void setLoadedCallbackNoAux(loaded_callback_func cb, S32 discard_level, BOOL keep_imageraw, BOOL needs_aux, void* userdata,
                            LLLoadedCallbackEntry::source_callback_list_t* src_callback_list, BOOL pause = FALSE);
-	bool hasCallbacks() { return mLoadedCallbackList.empty() ? false : true; }	
-	void pauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
-	void unpauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
-	bool doLoadedCallbacks();
-	void deleteCallbackEntry(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
-	void clearCallbackEntryList() ;
+    bool hasCallbacks() { return mLoadedCallbackList.empty() ? false : true; }
+    void pauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
+    void unpauseLoadedCallbacks(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
+    bool doLoadedCallbacks();
+    void deleteCallbackEntry(const LLLoadedCallbackEntry::source_callback_list_t* callback_list);
+    void clearCallbackEntryList() ;
 
-	void addToCreateTexture();
+    void addToCreateTexture();
 
     //call to determine if createTexture is necessary
     BOOL preCreateTexture(S32 usename = 0);
-	 // ONLY call from LLViewerTextureList or ImageGL background thread
-	BOOL createTexture(S32 usename = 0);
+     // ONLY call from LLViewerTextureList or ImageGL background thread
+    BOOL createTexture(S32 usename = 0);
     void postCreateTexture();
     void scheduleCreateTexture();
 
-	void destroyTexture() ;
+    void destroyTexture() ;
 
-	virtual void processTextureStats() ;
+    virtual void processTextureStats() ;
 
-	BOOL needsAux() const { return mNeedsAux; }
+    BOOL needsAux() const { return mNeedsAux; }
 
-	// Host we think might have this image, used for baked av textures.
-	void setTargetHost(LLHost host)			{ mTargetHost = host; }
-	LLHost getTargetHost() const			{ return mTargetHost; }
-	
-	void updateVirtualSize() ;
+    // Host we think might have this image, used for baked av textures.
+    void setTargetHost(LLHost host)         { mTargetHost = host; }
+    LLHost getTargetHost() const            { return mTargetHost; }
 
-	S32  getDesiredDiscardLevel()			 { return mDesiredDiscardLevel; }
-	void setMinDiscardLevel(S32 discard) 	{ mMinDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel,(S8)discard); }
+    void updateVirtualSize() ;
+
+    S32  getDesiredDiscardLevel()            { return mDesiredDiscardLevel; }
+    void setMinDiscardLevel(S32 discard)    { mMinDesiredDiscardLevel = llmin(mMinDesiredDiscardLevel,(S8)discard); }
 
     void setBoostLevel(S32 level) override;
-	bool updateFetch();
-	bool setDebugFetching(S32 debug_level);
-	bool isInDebug() const { return mInDebug; }
+    bool updateFetch();
+    bool setDebugFetching(S32 debug_level);
+    bool isInDebug() const { return mInDebug; }
+
+    void setUnremovable(BOOL value) { mUnremovable = value; }
+    bool isUnremovable() const { return mUnremovable; }
 
-	void setUnremovable(BOOL value) { mUnremovable = value; }
-	bool isUnremovable() const { return mUnremovable; }
-	
-	void clearFetchedResults(); //clear all fetched results, for debug use.
+    void clearFetchedResults(); //clear all fetched results, for debug use.
 
-	// Override the computation of discard levels if we know the exact output
-	// size of the image.  Used for UI textures to not decode, even if we have
-	// more data.
-	/*virtual*/ void setKnownDrawSize(S32 width, S32 height) override;
+    // Override the computation of discard levels if we know the exact output
+    // size of the image.  Used for UI textures to not decode, even if we have
+    // more data.
+    /*virtual*/ void setKnownDrawSize(S32 width, S32 height) override;
 
     // Set the debug text of all Viewer Objects associated with this texture
     // to the specified text
     void setDebugText(const std::string& text);
 
-	void setIsMissingAsset(BOOL is_missing = true);
-	/*virtual*/ BOOL isMissingAsset() const override { return mIsMissingAsset; }
-
-	// returns dimensions of original image for local files (before power of two scaling)
-	// and returns 0 for all asset system images
-	S32 getOriginalWidth() { return mOrigWidth; }
-	S32 getOriginalHeight() { return mOrigHeight; }
-
-	BOOL isInImageList() const {return mInImageList ;}
-	void setInImageList(BOOL flag) {mInImageList = flag ;}
-
-	LLFrameTimer* getLastPacketTimer() {return &mLastPacketTimer;}
-
-	U32 getFetchPriority() const { return mFetchPriority ;}
-	F32 getDownloadProgress() const {return mDownloadProgress ;}
-
-	LLImageRaw* reloadRawImage(S8 discard_level) ;
-	void destroyRawImage();
-	bool needsToSaveRawImage();
-
-	const std::string& getUrl() const {return mUrl;}
-	//---------------
-	BOOL isDeleted() ;
-	BOOL isInactive() ;
-	BOOL isDeletionCandidate();
-	void setDeletionCandidate() ;
-	void setInactive() ;
-	BOOL getUseDiscard() const { return mUseMipMaps && !mDontDiscard; }	
-	//---------------
-
-	void setForSculpt();
-	BOOL forSculpt() const {return mForSculpt;}
-	BOOL isForSculptOnly() const;
-
-	//raw image management	
-	void        checkCachedRawSculptImage() ;
-	LLImageRaw* getRawImage()const { return mRawImage ;}
-	S32         getRawImageLevel() const {return mRawDiscardLevel;}
-	LLImageRaw* getCachedRawImage() const { return mCachedRawImage ;}
-	S32         getCachedRawImageLevel() const {return mCachedRawDiscardLevel;}
-	BOOL        isCachedRawImageReady() const {return mCachedRawImageReady ;}
-	BOOL        isRawImageValid()const { return mIsRawImageValid ; }	
-	void        forceToSaveRawImage(S32 desired_discard = 0, F32 kept_time = 0.f) ;
-	/*virtual*/ void setCachedRawImage(S32 discard_level, LLImageRaw* imageraw) override;
-	void        destroySavedRawImage() ;
-	LLImageRaw* getSavedRawImage() ;
-	BOOL        hasSavedRawImage() const ;
-	F32         getElapsedLastReferencedSavedRawImageTime() const ;
-	BOOL		isFullyLoaded() const;
-
-	BOOL        hasFetcher() const { return mHasFetcher;}
-	bool        isFetching() const { return mIsFetching;}
-	void        setCanUseHTTP(bool can_use_http) {mCanUseHTTP = can_use_http;}
-
-	void        forceToDeleteRequest();
-	void        loadFromFastCache();
-	void        setInFastCacheList(bool in_list) { mInFastCacheList = in_list; }
-	bool        isInFastCacheList() { return mInFastCacheList; }
-
-	/*virtual*/bool  isActiveFetching() override; //is actively in fetching by the fetching pipeline.
-
-	LLUUID		getUploader();
-	LLDate		getUploadTime();
-	std::string getComment();
+    void setIsMissingAsset(BOOL is_missing = true);
+    /*virtual*/ BOOL isMissingAsset() const override { return mIsMissingAsset; }
+
+    // returns dimensions of original image for local files (before power of two scaling)
+    // and returns 0 for all asset system images
+    S32 getOriginalWidth() { return mOrigWidth; }
+    S32 getOriginalHeight() { return mOrigHeight; }
+
+    BOOL isInImageList() const {return mInImageList ;}
+    void setInImageList(BOOL flag) {mInImageList = flag ;}
+
+    LLFrameTimer* getLastPacketTimer() {return &mLastPacketTimer;}
+
+    U32 getFetchPriority() const { return mFetchPriority ;}
+    F32 getDownloadProgress() const {return mDownloadProgress ;}
+
+    LLImageRaw* reloadRawImage(S8 discard_level) ;
+    void destroyRawImage();
+    bool needsToSaveRawImage();
+
+    const std::string& getUrl() const {return mUrl;}
+    //---------------
+    BOOL isDeleted() ;
+    BOOL isInactive() ;
+    BOOL isDeletionCandidate();
+    void setDeletionCandidate() ;
+    void setInactive() ;
+    BOOL getUseDiscard() const { return mUseMipMaps && !mDontDiscard; }
+    //---------------
+
+    void setForSculpt();
+    BOOL forSculpt() const {return mForSculpt;}
+    BOOL isForSculptOnly() const;
+
+    //raw image management
+    void        checkCachedRawSculptImage() ;
+    LLImageRaw* getRawImage()const { return mRawImage ;}
+    S32         getRawImageLevel() const {return mRawDiscardLevel;}
+    LLImageRaw* getCachedRawImage() const { return mCachedRawImage ;}
+    S32         getCachedRawImageLevel() const {return mCachedRawDiscardLevel;}
+    BOOL        isCachedRawImageReady() const {return mCachedRawImageReady ;}
+    BOOL        isRawImageValid()const { return mIsRawImageValid ; }
+    void        forceToSaveRawImage(S32 desired_discard = 0, F32 kept_time = 0.f) ;
+    /*virtual*/ void setCachedRawImage(S32 discard_level, LLImageRaw* imageraw) override;
+    void        destroySavedRawImage() ;
+    LLImageRaw* getSavedRawImage() ;
+    BOOL        hasSavedRawImage() const ;
+    F32         getElapsedLastReferencedSavedRawImageTime() const ;
+    BOOL        isFullyLoaded() const;
+
+    BOOL        hasFetcher() const { return mHasFetcher;}
+    bool        isFetching() const { return mIsFetching;}
+    void        setCanUseHTTP(bool can_use_http) {mCanUseHTTP = can_use_http;}
+
+    void        forceToDeleteRequest();
+    void        loadFromFastCache();
+    void        setInFastCacheList(bool in_list) { mInFastCacheList = in_list; }
+    bool        isInFastCacheList() { return mInFastCacheList; }
+
+    /*virtual*/bool  isActiveFetching() override; //is actively in fetching by the fetching pipeline.
+
+    LLUUID      getUploader();
+    LLDate      getUploadTime();
+    std::string getComment();
 
 protected:
-	/*virtual*/ void switchToCachedImage() override;
-	S32 getCurrentDiscardLevelForFetching() ;
-	void forceToRefetchTexture(S32 desired_discard = 0, F32 kept_time = 60.f);
+    /*virtual*/ void switchToCachedImage() override;
+    S32 getCurrentDiscardLevelForFetching() ;
+    void forceToRefetchTexture(S32 desired_discard = 0, F32 kept_time = 60.f);
 
 private:
-	void init(bool firstinit) ;	
-	void cleanup() ;
+    void init(bool firstinit) ;
+    void cleanup() ;
 
-	void saveRawImage() ;
-	void setCachedRawImage() ;
+    void saveRawImage() ;
+    void setCachedRawImage() ;
 
-	//for atlas
-	void resetFaceAtlas() ;
-	void invalidateAtlas(BOOL rebuild_geom) ;
-	BOOL insertToAtlas() ;
+    //for atlas
+    void resetFaceAtlas() ;
+    void invalidateAtlas(BOOL rebuild_geom) ;
+    BOOL insertToAtlas() ;
 
 private:
-	BOOL  mFullyLoaded;
-	BOOL  mInDebug;
-	BOOL  mUnremovable;
-	BOOL  mInFastCacheList;
-	BOOL  mForceCallbackFetch;
-
-protected:		
-	std::string mLocalFileName;
-
-	S32 mOrigWidth;
-	S32 mOrigHeight;
-
-	// Override the computation of discard levels if we know the exact output size of the image.
-	// Used for UI textures to not decode, even if we have more data.
-	S32 mKnownDrawWidth;
-	S32	mKnownDrawHeight;
-	BOOL mKnownDrawSizeChanged ;
-	std::string mUrl;
-	
-	S32 mRequestedDiscardLevel;
-	F32 mRequestedDownloadPriority;
-	S32 mFetchState;
+    BOOL  mFullyLoaded;
+    BOOL  mInDebug;
+    BOOL  mUnremovable;
+    BOOL  mInFastCacheList;
+    BOOL  mForceCallbackFetch;
+
+protected:
+    std::string mLocalFileName;
+
+    S32 mOrigWidth;
+    S32 mOrigHeight;
+
+    // Override the computation of discard levels if we know the exact output size of the image.
+    // Used for UI textures to not decode, even if we have more data.
+    S32 mKnownDrawWidth;
+    S32 mKnownDrawHeight;
+    BOOL mKnownDrawSizeChanged ;
+    std::string mUrl;
+
+    S32 mRequestedDiscardLevel;
+    F32 mRequestedDownloadPriority;
+    S32 mFetchState;
     S32 mLastFetchState = -1; // DEBUG
-	U32 mFetchPriority;
-	F32 mDownloadProgress;
-	F32 mFetchDeltaTime;
-	F32 mRequestDeltaTime;
-	S32	mMinDiscardLevel;
-	S8  mDesiredDiscardLevel;			// The discard level we'd LIKE to have - if we have it and there's space	
-	S8  mMinDesiredDiscardLevel;	// The minimum discard level we'd like to have
-
-	S8  mNeedsAux;					// We need to decode the auxiliary channels
-	S8  mHasAux;                    // We have aux channels
-	S8  mDecodingAux;				// Are we decoding high components
-	S8  mIsRawImageValid;
-	S8  mHasFetcher;				// We've made a fecth request
-	S8  mIsFetching;				// Fetch request is active
-	bool mCanUseHTTP;              //This texture can be fetched through http if true.
-	LLCore::HttpStatus mLastHttpGetStatus; // Result of the most recently completed http request for this texture.
-
-	FTType mFTType; // What category of image is this - map tile, server bake, etc?
-	mutable S8 mIsMissingAsset;		// True if we know that there is no image asset with this image id in the database.		
-
-	typedef std::list<LLLoadedCallbackEntry*> callback_list_t;
-	S8              mLoadedCallbackDesiredDiscardLevel;
-	BOOL            mPauseLoadedCallBacks;
-	callback_list_t mLoadedCallbackList;
-	F32             mLastCallBackActiveTime;
-
-	LLPointer<LLImageRaw> mRawImage;
-	S32 mRawDiscardLevel = -1;
-
-	// Used ONLY for cloth meshes right now.  Make SURE you know what you're 
-	// doing if you use it for anything else! - djs
-	LLPointer<LLImageRaw> mAuxRawImage;
-
-	//keep a copy of mRawImage for some special purposes
-	//when mForceToSaveRawImage is set.
-	BOOL mForceToSaveRawImage ;
-	BOOL mSaveRawImage;
-	LLPointer<LLImageRaw> mSavedRawImage;
-	S32 mSavedRawDiscardLevel;
-	S32 mDesiredSavedRawDiscardLevel;
-	F32 mLastReferencedSavedRawImageTime ;
-	F32 mKeptSavedRawImageTime ;
-
-	//a small version of the copy of the raw image (<= 64 * 64)
-	LLPointer<LLImageRaw> mCachedRawImage;
-	S32 mCachedRawDiscardLevel;
-	BOOL mCachedRawImageReady; //the rez of the mCachedRawImage reaches the upper limit.	
-
-	LLHost mTargetHost;	// if invalid, just request from agent's simulator
-
-	// Timers
-	LLFrameTimer mLastPacketTimer;		// Time since last packet.
-	LLFrameTimer mStopFetchingTimer;	// Time since mDecodePriority == 0.f.
-
-	BOOL  mInImageList;				// TRUE if image is in list (in which case don't reset priority!)
-	// This needs to be atomic, since it is written both in the main thread
-	// and in the GL image worker thread... HB
-	LLAtomicBool mNeedsCreateTexture;	
-
-	BOOL   mForSculpt ; //a flag if the texture is used as sculpt data.
-	BOOL   mIsFetched ; //is loaded from remote or from cache, not generated locally.
-	
-	std::map<S8, std::string> mComment;
+    U32 mFetchPriority;
+    F32 mDownloadProgress;
+    F32 mFetchDeltaTime;
+    F32 mRequestDeltaTime;
+    S32 mMinDiscardLevel;
+    S8  mDesiredDiscardLevel;           // The discard level we'd LIKE to have - if we have it and there's space
+    S8  mMinDesiredDiscardLevel;    // The minimum discard level we'd like to have
+
+    S8  mNeedsAux;                  // We need to decode the auxiliary channels
+    S8  mHasAux;                    // We have aux channels
+    S8  mDecodingAux;               // Are we decoding high components
+    S8  mIsRawImageValid;
+    S8  mHasFetcher;                // We've made a fecth request
+    S8  mIsFetching;                // Fetch request is active
+    bool mCanUseHTTP;              //This texture can be fetched through http if true.
+    LLCore::HttpStatus mLastHttpGetStatus; // Result of the most recently completed http request for this texture.
+
+    FTType mFTType; // What category of image is this - map tile, server bake, etc?
+    mutable S8 mIsMissingAsset;     // True if we know that there is no image asset with this image id in the database.
+
+    typedef std::list<LLLoadedCallbackEntry*> callback_list_t;
+    S8              mLoadedCallbackDesiredDiscardLevel;
+    BOOL            mPauseLoadedCallBacks;
+    callback_list_t mLoadedCallbackList;
+    F32             mLastCallBackActiveTime;
+
+    LLPointer<LLImageRaw> mRawImage;
+    S32 mRawDiscardLevel = -1;
+
+    // Used ONLY for cloth meshes right now.  Make SURE you know what you're
+    // doing if you use it for anything else! - djs
+    LLPointer<LLImageRaw> mAuxRawImage;
+
+    //keep a copy of mRawImage for some special purposes
+    //when mForceToSaveRawImage is set.
+    BOOL mForceToSaveRawImage ;
+    BOOL mSaveRawImage;
+    LLPointer<LLImageRaw> mSavedRawImage;
+    S32 mSavedRawDiscardLevel;
+    S32 mDesiredSavedRawDiscardLevel;
+    F32 mLastReferencedSavedRawImageTime ;
+    F32 mKeptSavedRawImageTime ;
+
+    //a small version of the copy of the raw image (<= 64 * 64)
+    LLPointer<LLImageRaw> mCachedRawImage;
+    S32 mCachedRawDiscardLevel;
+    BOOL mCachedRawImageReady; //the rez of the mCachedRawImage reaches the upper limit.
+
+    LLHost mTargetHost; // if invalid, just request from agent's simulator
+
+    // Timers
+    LLFrameTimer mLastPacketTimer;      // Time since last packet.
+    LLFrameTimer mStopFetchingTimer;    // Time since mDecodePriority == 0.f.
+
+    BOOL  mInImageList;             // TRUE if image is in list (in which case don't reset priority!)
+    // This needs to be atomic, since it is written both in the main thread
+    // and in the GL image worker thread... HB
+    LLAtomicBool mNeedsCreateTexture;
+
+    BOOL   mForSculpt ; //a flag if the texture is used as sculpt data.
+    BOOL   mIsFetched ; //is loaded from remote or from cache, not generated locally.
+
+    std::map<S8, std::string> mComment;
 
 public:
     static F32 sMaxVirtualSize; //maximum possible value of mMaxVirtualSize
-	static LLPointer<LLViewerFetchedTexture> sMissingAssetImagep;	// Texture to show for an image asset that is not in the database
-	static LLPointer<LLViewerFetchedTexture> sWhiteImagep;	// Texture to show NOTHING (whiteness)
-	static LLPointer<LLViewerFetchedTexture> sDefaultImagep; // "Default" texture for error cases, the only case of fetched texture which is generated in local.
-	static LLPointer<LLViewerFetchedTexture> sFlatNormalImagep; // Flat normal map denoting no bumpiness on a surface
-	static LLPointer<LLViewerFetchedTexture> sDefaultIrradiancePBRp; // PBR: irradiance
+    static LLPointer<LLViewerFetchedTexture> sMissingAssetImagep;   // Texture to show for an image asset that is not in the database
+    static LLPointer<LLViewerFetchedTexture> sWhiteImagep;  // Texture to show NOTHING (whiteness)
+    static LLPointer<LLViewerFetchedTexture> sDefaultImagep; // "Default" texture for error cases, the only case of fetched texture which is generated in local.
+    static LLPointer<LLViewerFetchedTexture> sFlatNormalImagep; // Flat normal map denoting no bumpiness on a surface
+    static LLPointer<LLViewerFetchedTexture> sDefaultIrradiancePBRp; // PBR: irradiance
 
     // not sure why, but something is iffy about the loading of this particular texture, use the accessor instead of accessing directly
     static LLPointer<LLViewerFetchedTexture> sSmokeImagep; // Old "Default" translucent texture
     static LLViewerFetchedTexture* getSmokeImage();
-	static LLPointer<LLViewerFetchedTexture> sPixieSmallImagep; // Small pixmap for default particle tex
+    static LLPointer<LLViewerFetchedTexture> sPixieSmallImagep; // Small pixmap for default particle tex
 // [SL:KB] - Patch: Render-TextureToggle (Catznip-4.0)
-	static LLPointer<LLViewerFetchedTexture> sDefaultDiffuseImagep;
+    static LLPointer<LLViewerFetchedTexture> sDefaultDiffuseImagep;
 // [/SL:KB]
 };
 
@@ -550,24 +550,24 @@ class LLViewerFetchedTexture : public LLViewerTexture
 class LLViewerLODTexture : public LLViewerFetchedTexture
 {
 protected:
-	/*virtual*/ ~LLViewerLODTexture(){}
+    /*virtual*/ ~LLViewerLODTexture(){}
 
 public:
-	LLViewerLODTexture(const LLUUID& id, FTType f_type, const LLHost& host = LLHost(), BOOL usemipmaps = TRUE);
-	LLViewerLODTexture(const std::string& url, FTType f_type, const LLUUID& id, BOOL usemipmaps = TRUE);
+    LLViewerLODTexture(const LLUUID& id, FTType f_type, const LLHost& host = LLHost(), BOOL usemipmaps = TRUE);
+    LLViewerLODTexture(const std::string& url, FTType f_type, const LLUUID& id, BOOL usemipmaps = TRUE);
 
-	/*virtual*/ S8 getType() const;
-	// Process image stats to determine priority/quality requirements.
-	/*virtual*/ void processTextureStats();
-	bool isUpdateFrozen() ;
+    /*virtual*/ S8 getType() const;
+    // Process image stats to determine priority/quality requirements.
+    /*virtual*/ void processTextureStats();
+    bool isUpdateFrozen() ;
 
 private:
-	void init(bool firstinit) ;
-	bool scaleDown() ;		
+    void init(bool firstinit) ;
+    bool scaleDown() ;
 
 private:
-	F32 mDiscardVirtualSize;		// Virtual size used to calculate desired discard	
-	F32 mCalculatedDiscardLevel;    // Last calculated discard level
+    F32 mDiscardVirtualSize;        // Virtual size used to calculate desired discard
+    F32 mCalculatedDiscardLevel;    // Last calculated discard level
 };
 
 //
@@ -577,135 +577,135 @@ class LLViewerLODTexture : public LLViewerFetchedTexture
 class LLViewerMediaTexture : public LLViewerTexture
 {
 protected:
-	/*virtual*/ ~LLViewerMediaTexture() ;
+    /*virtual*/ ~LLViewerMediaTexture() ;
 
 public:
-	LLViewerMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
+    LLViewerMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
 
-	/*virtual*/ S8 getType() const;
-	void reinit(BOOL usemipmaps = TRUE);	
+    /*virtual*/ S8 getType() const;
+    void reinit(BOOL usemipmaps = TRUE);
 
-	BOOL  getUseMipMaps() {return mUseMipMaps ; }
-	void  setUseMipMaps(BOOL mipmap) ;	
-	
-	void setPlaying(BOOL playing) ;
-	BOOL isPlaying() const {return mIsPlaying;}
-	void setMediaImpl() ;
+    BOOL  getUseMipMaps() {return mUseMipMaps ; }
+    void  setUseMipMaps(BOOL mipmap) ;
+
+    void setPlaying(BOOL playing) ;
+    BOOL isPlaying() const {return mIsPlaying;}
+    void setMediaImpl() ;
 
     virtual bool isViewerMediaTexture() const { return true; }
 
-	void initVirtualSize() ;	
-	void invalidateMediaImpl() ;
+    void initVirtualSize() ;
+    void invalidateMediaImpl() ;
 
-	void addMediaToFace(LLFace* facep) ;
-	void removeMediaFromFace(LLFace* facep) ;
+    void addMediaToFace(LLFace* facep) ;
+    void removeMediaFromFace(LLFace* facep) ;
 
-	/*virtual*/ void addFace(U32 ch, LLFace* facep) ;
-	/*virtual*/ void removeFace(U32 ch, LLFace* facep) ; 
+    /*virtual*/ void addFace(U32 ch, LLFace* facep) ;
+    /*virtual*/ void removeFace(U32 ch, LLFace* facep) ;
 
-	/*virtual*/ F32  getMaxVirtualSize() ;
+    /*virtual*/ F32  getMaxVirtualSize() ;
 private:
-	void switchTexture(U32 ch, LLFace* facep) ;
-	BOOL findFaces() ;
-	void stopPlaying() ;
+    void switchTexture(U32 ch, LLFace* facep) ;
+    BOOL findFaces() ;
+    void stopPlaying() ;
 
 private:
-	//
-	//an instant list, recording all faces referencing or can reference to this media texture.
-	//NOTE: it is NOT thread safe. 
-	//
-	std::list< LLFace* > mMediaFaceList ; 
+    //
+    //an instant list, recording all faces referencing or can reference to this media texture.
+    //NOTE: it is NOT thread safe.
+    //
+    std::list< LLFace* > mMediaFaceList ;
 
-	//an instant list keeping all textures which are replaced by the current media texture,
-	//is only used to avoid the removal of those textures from memory.
-	std::list< LLPointer<LLViewerTexture> > mTextureList ;
+    //an instant list keeping all textures which are replaced by the current media texture,
+    //is only used to avoid the removal of those textures from memory.
+    std::list< LLPointer<LLViewerTexture> > mTextureList ;
 
-	LLViewerMediaImpl* mMediaImplp ;	
-	BOOL mIsPlaying ;
-	U32  mUpdateVirtualSizeTime ;
+    LLViewerMediaImpl* mMediaImplp ;
+    BOOL mIsPlaying ;
+    U32  mUpdateVirtualSizeTime ;
 
 public:
-	static void updateClass() ;
-	static void cleanUpClass() ;	
+    static void updateClass() ;
+    static void cleanUpClass() ;
 
-	static LLViewerMediaTexture* findMediaTexture(const LLUUID& media_id) ;
-	static void removeMediaImplFromTexture(const LLUUID& media_id) ;
+    static LLViewerMediaTexture* findMediaTexture(const LLUUID& media_id) ;
+    static void removeMediaImplFromTexture(const LLUUID& media_id) ;
 
 private:
-	typedef std::map< LLUUID, LLPointer<LLViewerMediaTexture> > media_map_t ;
-	static media_map_t sMediaMap ;	
+    typedef std::map< LLUUID, LLPointer<LLViewerMediaTexture> > media_map_t ;
+    static media_map_t sMediaMap ;
 };
 
 //just an interface class, do not create instance from this class.
 class LLViewerTextureManager
 {
 private:
-	//make the constructor private to preclude creating instances from this class.
-	LLViewerTextureManager(){}
+    //make the constructor private to preclude creating instances from this class.
+    LLViewerTextureManager(){}
 
 public:
     //texture pipeline tester
-	static LLTexturePipelineTester* sTesterp ;
-
-	//returns NULL if tex is not a LLViewerFetchedTexture nor derived from LLViewerFetchedTexture.
-	static LLViewerFetchedTexture*    staticCastToFetchedTexture(LLTexture* tex, BOOL report_error = FALSE) ;
-
-	//
-	//"find-texture" just check if the texture exists, if yes, return it, otherwise return null.
-	//
-	static void                       findFetchedTextures(const LLUUID& id, std::vector<LLViewerFetchedTexture*> &output);
-	static void                       findTextures(const LLUUID& id, std::vector<LLViewerTexture*> &output);
-	static LLViewerFetchedTexture*    findFetchedTexture(const LLUUID& id, S32 tex_type);
-	static LLViewerMediaTexture*      findMediaTexture(const LLUUID& id) ;
-	
-	static LLViewerMediaTexture*      createMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
-
-	//
-	//"get-texture" will create a new texture if the texture does not exist.
-	//
-	static LLViewerMediaTexture*      getMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
-	
-	static LLPointer<LLViewerTexture> getLocalTexture(BOOL usemipmaps = TRUE, BOOL generate_gl_tex = TRUE);
-	static LLPointer<LLViewerTexture> getLocalTexture(const LLUUID& id, BOOL usemipmaps, BOOL generate_gl_tex = TRUE) ;
-	static LLPointer<LLViewerTexture> getLocalTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
-	static LLPointer<LLViewerTexture> getLocalTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps, BOOL generate_gl_tex = TRUE) ;
+    static LLTexturePipelineTester* sTesterp ;
+
+    //returns NULL if tex is not a LLViewerFetchedTexture nor derived from LLViewerFetchedTexture.
+    static LLViewerFetchedTexture*    staticCastToFetchedTexture(LLTexture* tex, BOOL report_error = FALSE) ;
+
+    //
+    //"find-texture" just check if the texture exists, if yes, return it, otherwise return null.
+    //
+    static void                       findFetchedTextures(const LLUUID& id, std::vector<LLViewerFetchedTexture*> &output);
+    static void                       findTextures(const LLUUID& id, std::vector<LLViewerTexture*> &output);
+    static LLViewerFetchedTexture*    findFetchedTexture(const LLUUID& id, S32 tex_type);
+    static LLViewerMediaTexture*      findMediaTexture(const LLUUID& id) ;
+
+    static LLViewerMediaTexture*      createMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
+
+    //
+    //"get-texture" will create a new texture if the texture does not exist.
+    //
+    static LLViewerMediaTexture*      getMediaTexture(const LLUUID& id, BOOL usemipmaps = TRUE, LLImageGL* gl_image = NULL) ;
+
+    static LLPointer<LLViewerTexture> getLocalTexture(BOOL usemipmaps = TRUE, BOOL generate_gl_tex = TRUE);
+    static LLPointer<LLViewerTexture> getLocalTexture(const LLUUID& id, BOOL usemipmaps, BOOL generate_gl_tex = TRUE) ;
+    static LLPointer<LLViewerTexture> getLocalTexture(const LLImageRaw* raw, BOOL usemipmaps) ;
+    static LLPointer<LLViewerTexture> getLocalTexture(const U32 width, const U32 height, const U8 components, BOOL usemipmaps, BOOL generate_gl_tex = TRUE) ;
 
     static LLViewerFetchedTexture* getFetchedTexture(const LLImageRaw* raw, FTType type, bool usemipmaps);
 
-	static LLViewerFetchedTexture* getFetchedTexture(const LLUUID &image_id,									 
-									 FTType f_type = FTT_DEFAULT,
-									 BOOL usemipmap = TRUE,
-									 LLViewerTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,		// Get the requested level immediately upon creation.
-									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
-									 LLGLint internal_format = 0,
-									 LLGLenum primary_format = 0,
-									 LLHost request_from_host = LLHost()
-									 );
-	
-	static LLViewerFetchedTexture* getFetchedTextureFromFile(const std::string& filename,									 
-									 FTType f_type = FTT_LOCAL_FILE,
-									 BOOL usemipmap = TRUE,
-									 LLViewerTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
-									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
-									 LLGLint internal_format = 0,
-									 LLGLenum primary_format = 0,
-									 const LLUUID& force_id = LLUUID::null
-									 );
-
-	static LLViewerFetchedTexture* getFetchedTextureFromUrl(const std::string& url,									 
-									 FTType f_type,
-									 BOOL usemipmap = TRUE,
-									 LLViewerTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
-									 S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
-									 LLGLint internal_format = 0,
-									 LLGLenum primary_format = 0,
-									 const LLUUID& force_id = LLUUID::null
-									 );
-
-	static LLViewerFetchedTexture* getFetchedTextureFromHost(const LLUUID& image_id, FTType f_type, LLHost host) ;
-
-	static void init() ;
-	static void cleanup() ;
+    static LLViewerFetchedTexture* getFetchedTexture(const LLUUID &image_id,
+                                     FTType f_type = FTT_DEFAULT,
+                                     BOOL usemipmap = TRUE,
+                                     LLViewerTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,     // Get the requested level immediately upon creation.
+                                     S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
+                                     LLGLint internal_format = 0,
+                                     LLGLenum primary_format = 0,
+                                     LLHost request_from_host = LLHost()
+                                     );
+
+    static LLViewerFetchedTexture* getFetchedTextureFromFile(const std::string& filename,
+                                     FTType f_type = FTT_LOCAL_FILE,
+                                     BOOL usemipmap = TRUE,
+                                     LLViewerTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
+                                     S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
+                                     LLGLint internal_format = 0,
+                                     LLGLenum primary_format = 0,
+                                     const LLUUID& force_id = LLUUID::null
+                                     );
+
+    static LLViewerFetchedTexture* getFetchedTextureFromUrl(const std::string& url,
+                                     FTType f_type,
+                                     BOOL usemipmap = TRUE,
+                                     LLViewerTexture::EBoostLevel boost_priority = LLGLTexture::BOOST_NONE,
+                                     S8 texture_type = LLViewerTexture::FETCHED_TEXTURE,
+                                     LLGLint internal_format = 0,
+                                     LLGLenum primary_format = 0,
+                                     const LLUUID& force_id = LLUUID::null
+                                     );
+
+    static LLViewerFetchedTexture* getFetchedTextureFromHost(const LLUUID& image_id, FTType f_type, LLHost host) ;
+
+    static void init() ;
+    static void cleanup() ;
 };
 //
 //this class is used for test/debug only
@@ -714,91 +714,91 @@ class LLViewerTextureManager
 //
 class LLTexturePipelineTester : public LLMetricPerformanceTesterWithSession
 {
-	enum
-	{
-		MIN_LARGE_IMAGE_AREA = 262144  //512 * 512
-	};
+    enum
+    {
+        MIN_LARGE_IMAGE_AREA = 262144  //512 * 512
+    };
 public:
-	LLTexturePipelineTester() ;
-	~LLTexturePipelineTester() ;
+    LLTexturePipelineTester() ;
+    ~LLTexturePipelineTester() ;
 
-	void update();		
-	void updateTextureBindingStats(const LLViewerTexture* imagep) ;
-	void updateTextureLoadingStats(const LLViewerFetchedTexture* imagep, const LLImageRaw* raw_imagep, BOOL from_cache) ;
-	void updateGrayTextureBinding() ;
-	void setStablizingTime() ;
+    void update();
+    void updateTextureBindingStats(const LLViewerTexture* imagep) ;
+    void updateTextureLoadingStats(const LLViewerFetchedTexture* imagep, const LLImageRaw* raw_imagep, BOOL from_cache) ;
+    void updateGrayTextureBinding() ;
+    void setStablizingTime() ;
 
 private:
-	void reset() ;
-	void updateStablizingTime() ;
+    void reset() ;
+    void updateStablizingTime() ;
 
-	/*virtual*/ void outputTestRecord(LLSD* sd) ;
+    /*virtual*/ void outputTestRecord(LLSD* sd) ;
 
 private:
-	BOOL mPause ;
+    BOOL mPause ;
 private:
-	BOOL mUsingDefaultTexture;            //if set, some textures are still gray.
-
-	U32Bytes mTotalBytesUsed ;                     //total bytes of textures bound/used for the current frame.
-	U32Bytes mTotalBytesUsedForLargeImage ;        //total bytes of textures bound/used for the current frame for images larger than 256 * 256.
-	U32Bytes mLastTotalBytesUsed ;                 //total bytes of textures bound/used for the previous frame.
-	U32Bytes mLastTotalBytesUsedForLargeImage ;    //total bytes of textures bound/used for the previous frame for images larger than 256 * 256.
-		
-	//
-	//data size
-	//
-	U32Bytes mTotalBytesLoaded ;               //total bytes fetched by texture pipeline
-	U32Bytes mTotalBytesLoadedFromCache ;      //total bytes fetched by texture pipeline from local cache	
-	U32Bytes mTotalBytesLoadedForLargeImage ;  //total bytes fetched by texture pipeline for images larger than 256 * 256. 
-	U32Bytes mTotalBytesLoadedForSculpties ;   //total bytes fetched by texture pipeline for sculpties
-
-	//
-	//time
-	//NOTE: the error tolerances of the following timers is one frame time.
-	//
-	F32 mStartFetchingTime ;
-	F32 mTotalGrayTime ;                  //total loading time when no gray textures.
-	F32 mTotalStablizingTime ;            //total stablizing time when texture memory overflows
-	F32 mStartTimeLoadingSculpties ;      //the start moment of loading sculpty images.
-	F32 mEndTimeLoadingSculpties ;        //the end moment of loading sculpty images.
-	F32 mStartStablizingTime ;
-	F32 mEndStablizingTime ;
+    BOOL mUsingDefaultTexture;            //if set, some textures are still gray.
+
+    U32Bytes mTotalBytesUsed ;                     //total bytes of textures bound/used for the current frame.
+    U32Bytes mTotalBytesUsedForLargeImage ;        //total bytes of textures bound/used for the current frame for images larger than 256 * 256.
+    U32Bytes mLastTotalBytesUsed ;                 //total bytes of textures bound/used for the previous frame.
+    U32Bytes mLastTotalBytesUsedForLargeImage ;    //total bytes of textures bound/used for the previous frame for images larger than 256 * 256.
+
+    //
+    //data size
+    //
+    U32Bytes mTotalBytesLoaded ;               //total bytes fetched by texture pipeline
+    U32Bytes mTotalBytesLoadedFromCache ;      //total bytes fetched by texture pipeline from local cache
+    U32Bytes mTotalBytesLoadedForLargeImage ;  //total bytes fetched by texture pipeline for images larger than 256 * 256.
+    U32Bytes mTotalBytesLoadedForSculpties ;   //total bytes fetched by texture pipeline for sculpties
+
+    //
+    //time
+    //NOTE: the error tolerances of the following timers is one frame time.
+    //
+    F32 mStartFetchingTime ;
+    F32 mTotalGrayTime ;                  //total loading time when no gray textures.
+    F32 mTotalStablizingTime ;            //total stablizing time when texture memory overflows
+    F32 mStartTimeLoadingSculpties ;      //the start moment of loading sculpty images.
+    F32 mEndTimeLoadingSculpties ;        //the end moment of loading sculpty images.
+    F32 mStartStablizingTime ;
+    F32 mEndStablizingTime ;
 
 private:
-	//
-	//The following members are used for performance analyzing
-	//
-	class LLTextureTestSession : public LLTestSession
-	{
-	public:
-		LLTextureTestSession() ;
-		/*virtual*/ ~LLTextureTestSession() ;
-
-		void reset() ;
-
-		F32 mTotalGrayTime ;
-		F32 mTotalStablizingTime ;
-		F32 mStartTimeLoadingSculpties ; 
-		F32 mTotalTimeLoadingSculpties ;
-
-		S32 mTotalBytesLoaded ; 
-		S32 mTotalBytesLoadedFromCache ;
-		S32 mTotalBytesLoadedForLargeImage ;
-		S32 mTotalBytesLoadedForSculpties ; 
-
-		typedef struct _texture_instant_preformance_t
-		{
-			S32 mAverageBytesUsedPerSecond ;         
-			S32 mAverageBytesUsedForLargeImagePerSecond ;
-			F32 mAveragePercentageBytesUsedPerSecond ;
-			F32 mTime ;
-		}texture_instant_preformance_t ;
-		std::vector<texture_instant_preformance_t> mInstantPerformanceList ;
-		S32 mInstantPerformanceListCounter ;
-	};
-
-	/*virtual*/ LLMetricPerformanceTesterWithSession::LLTestSession* loadTestSession(LLSD* log) ;
-	/*virtual*/ void compareTestSessions(llofstream* os) ;
+    //
+    //The following members are used for performance analyzing
+    //
+    class LLTextureTestSession : public LLTestSession
+    {
+    public:
+        LLTextureTestSession() ;
+        /*virtual*/ ~LLTextureTestSession() ;
+
+        void reset() ;
+
+        F32 mTotalGrayTime ;
+        F32 mTotalStablizingTime ;
+        F32 mStartTimeLoadingSculpties ;
+        F32 mTotalTimeLoadingSculpties ;
+
+        S32 mTotalBytesLoaded ;
+        S32 mTotalBytesLoadedFromCache ;
+        S32 mTotalBytesLoadedForLargeImage ;
+        S32 mTotalBytesLoadedForSculpties ;
+
+        typedef struct _texture_instant_preformance_t
+        {
+            S32 mAverageBytesUsedPerSecond ;
+            S32 mAverageBytesUsedForLargeImagePerSecond ;
+            F32 mAveragePercentageBytesUsedPerSecond ;
+            F32 mTime ;
+        }texture_instant_preformance_t ;
+        std::vector<texture_instant_preformance_t> mInstantPerformanceList ;
+        S32 mInstantPerformanceListCounter ;
+    };
+
+    /*virtual*/ LLMetricPerformanceTesterWithSession::LLTestSession* loadTestSession(LLSD* log) ;
+    /*virtual*/ void compareTestSessions(llofstream* os) ;
 };
 
 #endif
diff --git a/indra/newview/llviewerwindow.cpp b/indra/newview/llviewerwindow.cpp
index 36c52eae307296d1f7b6b11f6b633fecbebd30a3..793db69bbf175afc8b5b2b43de611a63426d5843 100644
--- a/indra/newview/llviewerwindow.cpp
+++ b/indra/newview/llviewerwindow.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewerwindow.cpp
  * @brief Implementation of the LLViewerWindow class.
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -62,7 +62,7 @@
 //
 
 // linden library includes
-#include "llaudioengine.h"		// mute on minimize
+#include "llaudioengine.h"      // mute on minimize
 #include "llchatentry.h"
 #include "indra_constants.h"
 #include "llassetstorage.h"
@@ -173,7 +173,7 @@
 #include "lltoolselectland.h"
 #include "lltrans.h"
 #include "lluictrlfactory.h"
-#include "llurldispatcher.h"		// SLURL from other app instance
+#include "llurldispatcher.h"        // SLURL from other app instance
 #include "llversioninfo.h"
 #include "llvieweraudio.h"
 #include "llviewercamera.h"
@@ -249,31 +249,31 @@ extern BOOL gResizeScreenTexture;
 extern BOOL gCubeSnapshot;
 extern BOOL gSnapshotNoPost;
 
-LLViewerWindow	*gViewerWindow = NULL;
+LLViewerWindow  *gViewerWindow = NULL;
 
-LLFrameTimer	gAwayTimer;
-LLFrameTimer	gAwayTriggerTimer;
+LLFrameTimer    gAwayTimer;
+LLFrameTimer    gAwayTriggerTimer;
 
-BOOL			gShowOverlayTitle = FALSE;
+BOOL            gShowOverlayTitle = FALSE;
 
 LLViewerObject*  gDebugRaycastObject = NULL;
 LLVOPartGroup* gDebugRaycastParticle = NULL;
 LLVector4a       gDebugRaycastIntersection;
-LLVector4a		gDebugRaycastParticleIntersection;
+LLVector4a      gDebugRaycastParticleIntersection;
 LLVector2        gDebugRaycastTexCoord;
 LLVector4a       gDebugRaycastNormal;
 LLVector4a       gDebugRaycastTangent;
-S32				gDebugRaycastFaceHit;
+S32             gDebugRaycastFaceHit;
 S32             gDebugRaycastGLTFNodeHit;
 S32             gDebugRaycastGLTFPrimitiveHit;
-LLVector4a		 gDebugRaycastStart;
-LLVector4a		 gDebugRaycastEnd;
+LLVector4a       gDebugRaycastStart;
+LLVector4a       gDebugRaycastEnd;
 
 // HUD display lines in lower right
-BOOL				gDisplayWindInfo = FALSE;
-BOOL				gDisplayCameraPos = FALSE;
-BOOL				gDisplayFOV = FALSE;
-BOOL				gDisplayBadge = FALSE;
+BOOL                gDisplayWindInfo = FALSE;
+BOOL                gDisplayCameraPos = FALSE;
+BOOL                gDisplayFOV = FALSE;
+BOOL                gDisplayBadge = FALSE;
 
 static const U8 NO_FACE = 255;
 BOOL gQuietSnapshot = FALSE;
@@ -294,40 +294,40 @@ LLTrace::SampleStatHandle<> LLViewerWindow::sMouseVelocityStat("Mouse Velocity")
 class RecordToChatConsoleRecorder : public LLError::Recorder
 {
 public:
-	virtual void recordMessage(LLError::ELevel level,
-								const std::string& message)
-	{
-		//FIXME: this is NOT thread safe, and will do bad things when a warning is issued from a non-UI thread
-
-		// only log warnings to chat console
-		//if (level == LLError::LEVEL_WARN)
-		//{
-			//LLFloaterChat* chat_floater = LLFloaterReg::findTypedInstance<LLFloaterChat>("chat");
-			//if (chat_floater && gSavedSettings.getBOOL("WarningsAsChat"))
-			//{
-			//	LLChat chat;
-			//	chat.mText = message;
-			//	chat.mSourceType = CHAT_SOURCE_SYSTEM;
-
-			//	chat_floater->addChat(chat, FALSE, FALSE);
-			//}
-		//}
-	}
+    virtual void recordMessage(LLError::ELevel level,
+                                const std::string& message)
+    {
+        //FIXME: this is NOT thread safe, and will do bad things when a warning is issued from a non-UI thread
+
+        // only log warnings to chat console
+        //if (level == LLError::LEVEL_WARN)
+        //{
+            //LLFloaterChat* chat_floater = LLFloaterReg::findTypedInstance<LLFloaterChat>("chat");
+            //if (chat_floater && gSavedSettings.getBOOL("WarningsAsChat"))
+            //{
+            //  LLChat chat;
+            //  chat.mText = message;
+            //  chat.mSourceType = CHAT_SOURCE_SYSTEM;
+
+            //  chat_floater->addChat(chat, FALSE, FALSE);
+            //}
+        //}
+    }
 };
 
 class RecordToChatConsole final : public LLSingleton<RecordToChatConsole>
 {
-	LLSINGLETON(RecordToChatConsole);
+    LLSINGLETON(RecordToChatConsole);
 public:
-	void startRecorder() { LLError::addRecorder(mRecorder); }
-	void stopRecorder() { LLError::removeRecorder(mRecorder); }
+    void startRecorder() { LLError::addRecorder(mRecorder); }
+    void stopRecorder() { LLError::removeRecorder(mRecorder); }
 
 private:
-	LLError::RecorderPtr mRecorder;
+    LLError::RecorderPtr mRecorder;
 };
 
 RecordToChatConsole::RecordToChatConsole():
-	mRecorder(new RecordToChatConsoleRecorder())
+    mRecorder(new RecordToChatConsoleRecorder())
 {
     mRecorder->showTags(false);
     mRecorder->showLocation(false);
@@ -439,269 +439,269 @@ static LLTrace::BlockTimerStatHandle FTM_DISPLAY_DEBUG_TEXT("Display Debug Text"
 class LLDebugText
 {
 private:
-	struct Line
-	{
-		Line(const std::string& in_text, S32 in_x, S32 in_y) : text(in_text), x(in_x), y(in_y) {}
-		std::string text;
-		S32 x,y;
-	};
-
-	LLViewerWindow *mWindow;
-	
-	typedef std::vector<Line> line_list_t;
-	line_list_t mLineList;
-	LLColor4 mTextColor;
-
-	LLColor4 mBackColor;
-	LLRect mBackRectCamera1;
-	LLRect mBackRectCamera2;
-
-	void addText(S32 x, S32 y, const std::string &text) 
-	{
-		mLineList.push_back(Line(text, x, y));
-	}
-	
-	void clearText() { mLineList.clear(); }
-	
+    struct Line
+    {
+        Line(const std::string& in_text, S32 in_x, S32 in_y) : text(in_text), x(in_x), y(in_y) {}
+        std::string text;
+        S32 x,y;
+    };
+
+    LLViewerWindow *mWindow;
+
+    typedef std::vector<Line> line_list_t;
+    line_list_t mLineList;
+    LLColor4 mTextColor;
+
+    LLColor4 mBackColor;
+    LLRect mBackRectCamera1;
+    LLRect mBackRectCamera2;
+
+    void addText(S32 x, S32 y, const std::string &text)
+    {
+        mLineList.push_back(Line(text, x, y));
+    }
+
+    void clearText() { mLineList.clear(); }
+
 public:
-	LLDebugText(LLViewerWindow* window) : mWindow(window) {}
-
-	void update()
-	{
-		if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
-		{
-			clearText();
-			return;
-		}
-
-		static LLCachedControl<bool> log_texture_traffic(gSavedSettings,"LogTextureNetworkTraffic", false) ;
-
-		std::string wind_vel_text;
-		std::string wind_vector_text;
-		std::string rwind_vel_text;
-		std::string rwind_vector_text;
-		std::string audio_text;
-
-		static const std::string beacon_particle = LLTrans::getString("BeaconParticle");
-		static const std::string beacon_physical = LLTrans::getString("BeaconPhysical");
-		static const std::string beacon_scripted = LLTrans::getString("BeaconScripted");
-		static const std::string beacon_scripted_touch = LLTrans::getString("BeaconScriptedTouch");
-		static const std::string beacon_sound = LLTrans::getString("BeaconSound");
-		static const std::string beacon_media = LLTrans::getString("BeaconMedia");
-		static const std::string beacon_sun = LLTrans::getString("BeaconSun");
-		static const std::string beacon_moon = LLTrans::getString("BeaconMoon");
-		static const std::string particle_hiding = LLTrans::getString("ParticleHiding");
-
-		// Draw the statistics in a light gray
-		// and in a thin font
-		mTextColor = LLColor4( 0.86f, 0.86f, 0.86f, 1.f );
-
-		// Draw stuff growing up from right lower corner of screen
-		S32 x_right = mWindow->getWorldViewWidthScaled();
-		S32 xpos = x_right - 400;
-		xpos = llmax(xpos, 0);
-		S32 ypos = 64;
-		const S32 y_inc = 20;
-
-		// Camera matrix text is hard to see again a white background
-		// Add a dark background underneath the matrices for readability (contrast)
-		mBackRectCamera1.mLeft   = xpos;
-		mBackRectCamera1.mRight  = x_right;
-		mBackRectCamera1.mTop    = -1;
-		mBackRectCamera1.mBottom = -1;
-		mBackRectCamera2 = mBackRectCamera1;
-
-		static LLUIColor debug_background_color = LLUIColorTable::instance().getColor("MenuDefaultBgColor");
-
-		mBackColor = debug_background_color;
-
-		clearText();
-		
-		static LLCachedControl<bool> debugShowTime(gSavedSettings, "DebugShowTime");
-		if (debugShowTime)
-		{
-			F32 time = gFrameTimeSeconds;
-			S32 hours = (S32)(time / (60*60));
-			S32 mins = (S32)((time - hours*(60*60)) / 60);
-			S32 secs = (S32)((time - hours*(60*60) - mins*60));
-			addText(xpos, ypos, llformat("Time: %d:%02d:%02d", hours,mins,secs)); ypos += y_inc;
-		}
-
-		static LLCachedControl<bool> analyze_target_texture(gSavedSettings, "AnalyzeTargetTexture", false);
-		if (analyze_target_texture)
-		{
-			LLSelectNode* nodep = LLSelectMgr::instance().getPrimaryHoverNode();
-			LLObjectSelectionHandle handle = LLSelectMgr::instance().getHoverObjects();
-			if (nodep || handle.notNull())
-			{
-
-				LLViewerObject* obj1 = nodep ? nodep->getObject() : NULL;
-				LLViewerObject* obj2 = handle ? handle->getPrimaryObject() : NULL;
-				LLViewerObject* obj = obj1 ? obj1 : obj2;
-				//LL_INFOS() << std::hex << obj1 << " " << obj2 << std::dec << LL_ENDL;
-				if (obj)
-				{
-					S32 te = nodep ? nodep->getLastSelectedTE() : -1;
-					if (te >= 0)
-					{
-						LLViewerTexture* imagep = obj->getTEImage(te);
-						if (imagep && imagep != (LLViewerTexture*) LLViewerFetchedTexture::sDefaultImagep.get())
-						{
-							//LLGLuint tex = imagep->getTexName();
-							//std::map<LLGLuint, std::list<std::pair<std::string, std::string> > >::iterator it = sTextureMaskMap.find(tex);
-							//if (it != sTextureMaskMap.end())
-							//{
-							//	std::list<std::pair<std::string, std::string> >::reverse_iterator it2 = it->second.rbegin();
-							//	for (; it2 != it->second.rend(); ++it2)
-							//	{
-							//		addText(xpos, ypos, llformat(" %s: %s", it2->first.c_str(), it2->second.c_str())); ypos += y_inc;
-							//	}
-							//}
-							static const LLCachedControl<bool> use_rmse_auto_mask(gSavedSettings, "RenderAutoMaskAlphaUseRMSE", false);
-							static const LLCachedControl<F32> auto_mask_max_rmse(gSavedSettings, "RenderAutoMaskAlphaMaxRMSE", .09f);
-							static const LLCachedControl<F32> auto_mask_max_mid(gSavedSettings, "RenderAutoMaskAlphaMaxMid", .25f);
-							addText(xpos, ypos, llformat("Mask: %s", imagep->getIsAlphaMask(use_rmse_auto_mask ? auto_mask_max_rmse : -1.f, auto_mask_max_mid) ? "TRUE" : "FALSE")); ypos += y_inc;
-							//addText(xpos, ypos, llformat("ID: %s", imagep->getID().asString().c_str())); ypos += y_inc;
-						}
-					}
-				}
-			}
-		}
-		
-		static LLCachedControl<bool> debugShowMemory(gSavedSettings, "DebugShowMemory");
-		if (debugShowMemory)
-		{
-			addText(xpos, ypos,
-					STRINGIZE("Memory: " << (LLMemory::getCurrentRSS() / 1024) << " (KB)"));
-			ypos += y_inc;
-		}
-
-		if (gDisplayCameraPos)
-		{
-			std::string camera_view_text;
-			std::string camera_center_text;
-			std::string agent_view_text;
-			std::string agent_left_text;
-			std::string agent_center_text;
-			std::string agent_root_center_text;
-
-			LLVector3d tvector; // Temporary vector to hold data for printing.
-
-			// Update camera center, camera view, wind info every other frame
-			tvector = gAgent.getPositionGlobal();
-			agent_center_text = llformat("AgentCenter  %f %f %f",
-										 (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
-
-			if (isAgentAvatarValid())
-			{
-				tvector = gAgent.getPosGlobalFromAgent(gAgentAvatarp->mRoot->getWorldPosition());
-				agent_root_center_text = llformat("AgentRootCenter %f %f %f",
-												  (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
-			}
-			else
-			{
-				agent_root_center_text = "---";
-			}
-
-
-			tvector = LLVector4(gAgent.getFrameAgent().getAtAxis());
-			agent_view_text = llformat("AgentAtAxis  %f %f %f",
-									   (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
-
-			tvector = LLVector4(gAgent.getFrameAgent().getLeftAxis());
-			agent_left_text = llformat("AgentLeftAxis  %f %f %f",
-									   (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
-
-			tvector = gAgentCamera.getCameraPositionGlobal();
-			camera_center_text = llformat("CameraCenter %f %f %f",
-										  (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
-
-			tvector = LLVector4(LLViewerCamera::getInstance()->getAtAxis());
-			camera_view_text = llformat("CameraAtAxis    %f %f %f",
-										(F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
-		
+    LLDebugText(LLViewerWindow* window) : mWindow(window) {}
+
+    void update()
+    {
+        if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
+        {
+            clearText();
+            return;
+        }
+
+        static LLCachedControl<bool> log_texture_traffic(gSavedSettings,"LogTextureNetworkTraffic", false) ;
+
+        std::string wind_vel_text;
+        std::string wind_vector_text;
+        std::string rwind_vel_text;
+        std::string rwind_vector_text;
+        std::string audio_text;
+
+        static const std::string beacon_particle = LLTrans::getString("BeaconParticle");
+        static const std::string beacon_physical = LLTrans::getString("BeaconPhysical");
+        static const std::string beacon_scripted = LLTrans::getString("BeaconScripted");
+        static const std::string beacon_scripted_touch = LLTrans::getString("BeaconScriptedTouch");
+        static const std::string beacon_sound = LLTrans::getString("BeaconSound");
+        static const std::string beacon_media = LLTrans::getString("BeaconMedia");
+        static const std::string beacon_sun = LLTrans::getString("BeaconSun");
+        static const std::string beacon_moon = LLTrans::getString("BeaconMoon");
+        static const std::string particle_hiding = LLTrans::getString("ParticleHiding");
+
+        // Draw the statistics in a light gray
+        // and in a thin font
+        mTextColor = LLColor4( 0.86f, 0.86f, 0.86f, 1.f );
+
+        // Draw stuff growing up from right lower corner of screen
+        S32 x_right = mWindow->getWorldViewWidthScaled();
+        S32 xpos = x_right - 400;
+        xpos = llmax(xpos, 0);
+        S32 ypos = 64;
+        const S32 y_inc = 20;
+
+        // Camera matrix text is hard to see again a white background
+        // Add a dark background underneath the matrices for readability (contrast)
+        mBackRectCamera1.mLeft   = xpos;
+        mBackRectCamera1.mRight  = x_right;
+        mBackRectCamera1.mTop    = -1;
+        mBackRectCamera1.mBottom = -1;
+        mBackRectCamera2 = mBackRectCamera1;
+
+        static LLUIColor debug_background_color = LLUIColorTable::instance().getColor("MenuDefaultBgColor");
+
+        mBackColor = debug_background_color;
+
+        clearText();
+
+        static LLCachedControl<bool> debugShowTime(gSavedSettings, "DebugShowTime");
+        if (debugShowTime)
+        {
+            F32 time = gFrameTimeSeconds;
+            S32 hours = (S32)(time / (60*60));
+            S32 mins = (S32)((time - hours*(60*60)) / 60);
+            S32 secs = (S32)((time - hours*(60*60) - mins*60));
+            addText(xpos, ypos, llformat("Time: %d:%02d:%02d", hours,mins,secs)); ypos += y_inc;
+        }
+
+        static LLCachedControl<bool> analyze_target_texture(gSavedSettings, "AnalyzeTargetTexture", false);
+        if (analyze_target_texture)
+        {
+            LLSelectNode* nodep = LLSelectMgr::instance().getPrimaryHoverNode();
+            LLObjectSelectionHandle handle = LLSelectMgr::instance().getHoverObjects();
+            if (nodep || handle.notNull())
+            {
+
+                LLViewerObject* obj1 = nodep ? nodep->getObject() : NULL;
+                LLViewerObject* obj2 = handle ? handle->getPrimaryObject() : NULL;
+                LLViewerObject* obj = obj1 ? obj1 : obj2;
+                //LL_INFOS() << std::hex << obj1 << " " << obj2 << std::dec << LL_ENDL;
+                if (obj)
+                {
+                    S32 te = nodep ? nodep->getLastSelectedTE() : -1;
+                    if (te >= 0)
+                    {
+                        LLViewerTexture* imagep = obj->getTEImage(te);
+                        if (imagep && imagep != (LLViewerTexture*) LLViewerFetchedTexture::sDefaultImagep.get())
+                        {
+                            //LLGLuint tex = imagep->getTexName();
+                            //std::map<LLGLuint, std::list<std::pair<std::string, std::string> > >::iterator it = sTextureMaskMap.find(tex);
+                            //if (it != sTextureMaskMap.end())
+                            //{
+                            //  std::list<std::pair<std::string, std::string> >::reverse_iterator it2 = it->second.rbegin();
+                            //  for (; it2 != it->second.rend(); ++it2)
+                            //  {
+                            //      addText(xpos, ypos, llformat(" %s: %s", it2->first.c_str(), it2->second.c_str())); ypos += y_inc;
+                            //  }
+                            //}
+                            static const LLCachedControl<bool> use_rmse_auto_mask(gSavedSettings, "RenderAutoMaskAlphaUseRMSE", false);
+                            static const LLCachedControl<F32> auto_mask_max_rmse(gSavedSettings, "RenderAutoMaskAlphaMaxRMSE", .09f);
+                            static const LLCachedControl<F32> auto_mask_max_mid(gSavedSettings, "RenderAutoMaskAlphaMaxMid", .25f);
+                            addText(xpos, ypos, llformat("Mask: %s", imagep->getIsAlphaMask(use_rmse_auto_mask ? auto_mask_max_rmse : -1.f, auto_mask_max_mid) ? "TRUE" : "FALSE")); ypos += y_inc;
+                            //addText(xpos, ypos, llformat("ID: %s", imagep->getID().asString().c_str())); ypos += y_inc;
+                        }
+                    }
+                }
+            }
+        }
+
+        static LLCachedControl<bool> debugShowMemory(gSavedSettings, "DebugShowMemory");
+        if (debugShowMemory)
+        {
+            addText(xpos, ypos,
+                    STRINGIZE("Memory: " << (LLMemory::getCurrentRSS() / 1024) << " (KB)"));
+            ypos += y_inc;
+        }
+
+        if (gDisplayCameraPos)
+        {
+            std::string camera_view_text;
+            std::string camera_center_text;
+            std::string agent_view_text;
+            std::string agent_left_text;
+            std::string agent_center_text;
+            std::string agent_root_center_text;
+
+            LLVector3d tvector; // Temporary vector to hold data for printing.
+
+            // Update camera center, camera view, wind info every other frame
+            tvector = gAgent.getPositionGlobal();
+            agent_center_text = llformat("AgentCenter  %f %f %f",
+                                         (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
+
+            if (isAgentAvatarValid())
+            {
+                tvector = gAgent.getPosGlobalFromAgent(gAgentAvatarp->mRoot->getWorldPosition());
+                agent_root_center_text = llformat("AgentRootCenter %f %f %f",
+                                                  (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
+            }
+            else
+            {
+                agent_root_center_text = "---";
+            }
+
+
+            tvector = LLVector4(gAgent.getFrameAgent().getAtAxis());
+            agent_view_text = llformat("AgentAtAxis  %f %f %f",
+                                       (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
+
+            tvector = LLVector4(gAgent.getFrameAgent().getLeftAxis());
+            agent_left_text = llformat("AgentLeftAxis  %f %f %f",
+                                       (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
+
+            tvector = gAgentCamera.getCameraPositionGlobal();
+            camera_center_text = llformat("CameraCenter %f %f %f",
+                                          (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
+
+            tvector = LLVector4(LLViewerCamera::getInstance()->getAtAxis());
+            camera_view_text = llformat("CameraAtAxis    %f %f %f",
+                                        (F32)(tvector.mdV[VX]), (F32)(tvector.mdV[VY]), (F32)(tvector.mdV[VZ]));
+
 // [RLVa:KB] - @showloc
-			if (!RlvActions::canShowLocation())
-			{
-				agent_center_text = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
-				agent_root_center_text = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
-				camera_center_text = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
-			}
+            if (!RlvActions::canShowLocation())
+            {
+                agent_center_text = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
+                agent_root_center_text = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
+                camera_center_text = RlvStrings::getString(RlvStringKeys::Hidden::Generic);
+            }
 // [/RLVa:KB]
 
-			addText(xpos, ypos, agent_center_text);  ypos += y_inc;
-			addText(xpos, ypos, agent_root_center_text);  ypos += y_inc;
-			addText(xpos, ypos, agent_view_text);  ypos += y_inc;
-			addText(xpos, ypos, agent_left_text);  ypos += y_inc;
-			addText(xpos, ypos, camera_center_text);  ypos += y_inc;
-			addText(xpos, ypos, camera_view_text);  ypos += y_inc;
-		}
-
-		if (gDisplayWindInfo)
-		{
-			wind_vel_text = llformat("Wind velocity %.2f m/s", gWindVec.magVec());
-			wind_vector_text = llformat("Wind vector   %.2f %.2f %.2f", gWindVec.mV[0], gWindVec.mV[1], gWindVec.mV[2]);
-			rwind_vel_text = llformat("RWind vel %.2f m/s", gRelativeWindVec.magVec());
-			rwind_vector_text = llformat("RWind vec   %.2f %.2f %.2f", gRelativeWindVec.mV[0], gRelativeWindVec.mV[1], gRelativeWindVec.mV[2]);
-
-			addText(xpos, ypos, wind_vel_text);  ypos += y_inc;
-			addText(xpos, ypos, wind_vector_text);  ypos += y_inc;
-			addText(xpos, ypos, rwind_vel_text);  ypos += y_inc;
-			addText(xpos, ypos, rwind_vector_text);  ypos += y_inc;
-		}
-		if (gDisplayWindInfo)
-		{
-			audio_text = llformat("Audio for wind: %d", gAudiop ? gAudiop->isWindEnabled() : -1);
-			addText(xpos, ypos, audio_text);  ypos += y_inc;
-		}
-		if (gDisplayFOV)
-		{
-			addText(xpos, ypos, llformat("FOV: %2.1f deg", RAD_TO_DEG * LLViewerCamera::getInstance()->getView()));
-			ypos += y_inc;
-		}
-		if (gDisplayBadge)
-		{
-			addText(xpos, ypos+(y_inc/2), llformat("Hippos!", RAD_TO_DEG * LLViewerCamera::getInstance()->getView()));
-			ypos += y_inc * 2;
-		}
-		
-		/*if (LLViewerJoystick::getInstance()->getOverrideCamera())
-		{
-			addText(xpos + 200, ypos, llformat("Flycam"));
-			ypos += y_inc;
-		}*/
-		
-		static LLCachedControl<bool> debugShowRenderInfo(gSavedSettings, "DebugShowRenderInfo");
-		if (debugShowRenderInfo)
-		{
-			LLTrace::Recording& last_frame_recording = LLTrace::get_frame_recording().getLastRecording();
-
-			//show streaming cost/triangle count of known prims in current region OR selection
-			{
-				F32 cost = 0.f;
-				S32 count = 0;
-				S32 vcount = 0;
-				S32 object_count = 0;
-				S32 total_bytes = 0;
-				S32 visible_bytes = 0;
-
-				const char* label = "Region";
-				if (LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 0)
-				{ //region
-					LLViewerRegion* region = gAgent.getRegion();
-					if (region)
-					{
-						for (U32 i = 0; i < gObjectList.getNumObjects(); ++i)
-						{
-							LLViewerObject* object = gObjectList.getObject(i);
-							if (object && 
-								object->getRegion() == region &&
-								object->getVolume())
-							{
-								object_count++;
-								S32 bytes = 0;	
-								S32 visible = 0;
-								cost += object->getStreamingCost();
+            addText(xpos, ypos, agent_center_text);  ypos += y_inc;
+            addText(xpos, ypos, agent_root_center_text);  ypos += y_inc;
+            addText(xpos, ypos, agent_view_text);  ypos += y_inc;
+            addText(xpos, ypos, agent_left_text);  ypos += y_inc;
+            addText(xpos, ypos, camera_center_text);  ypos += y_inc;
+            addText(xpos, ypos, camera_view_text);  ypos += y_inc;
+        }
+
+        if (gDisplayWindInfo)
+        {
+            wind_vel_text = llformat("Wind velocity %.2f m/s", gWindVec.magVec());
+            wind_vector_text = llformat("Wind vector   %.2f %.2f %.2f", gWindVec.mV[0], gWindVec.mV[1], gWindVec.mV[2]);
+            rwind_vel_text = llformat("RWind vel %.2f m/s", gRelativeWindVec.magVec());
+            rwind_vector_text = llformat("RWind vec   %.2f %.2f %.2f", gRelativeWindVec.mV[0], gRelativeWindVec.mV[1], gRelativeWindVec.mV[2]);
+
+            addText(xpos, ypos, wind_vel_text);  ypos += y_inc;
+            addText(xpos, ypos, wind_vector_text);  ypos += y_inc;
+            addText(xpos, ypos, rwind_vel_text);  ypos += y_inc;
+            addText(xpos, ypos, rwind_vector_text);  ypos += y_inc;
+        }
+        if (gDisplayWindInfo)
+        {
+            audio_text = llformat("Audio for wind: %d", gAudiop ? gAudiop->isWindEnabled() : -1);
+            addText(xpos, ypos, audio_text);  ypos += y_inc;
+        }
+        if (gDisplayFOV)
+        {
+            addText(xpos, ypos, llformat("FOV: %2.1f deg", RAD_TO_DEG * LLViewerCamera::getInstance()->getView()));
+            ypos += y_inc;
+        }
+        if (gDisplayBadge)
+        {
+            addText(xpos, ypos+(y_inc/2), llformat("Hippos!", RAD_TO_DEG * LLViewerCamera::getInstance()->getView()));
+            ypos += y_inc * 2;
+        }
+
+        /*if (LLViewerJoystick::getInstance()->getOverrideCamera())
+        {
+            addText(xpos + 200, ypos, llformat("Flycam"));
+            ypos += y_inc;
+        }*/
+
+        static LLCachedControl<bool> debugShowRenderInfo(gSavedSettings, "DebugShowRenderInfo");
+        if (debugShowRenderInfo)
+        {
+            LLTrace::Recording& last_frame_recording = LLTrace::get_frame_recording().getLastRecording();
+
+            //show streaming cost/triangle count of known prims in current region OR selection
+            {
+                F32 cost = 0.f;
+                S32 count = 0;
+                S32 vcount = 0;
+                S32 object_count = 0;
+                S32 total_bytes = 0;
+                S32 visible_bytes = 0;
+
+                const char* label = "Region";
+                if (LLSelectMgr::getInstance()->getSelection()->getObjectCount() == 0)
+                { //region
+                    LLViewerRegion* region = gAgent.getRegion();
+                    if (region)
+                    {
+                        for (U32 i = 0; i < gObjectList.getNumObjects(); ++i)
+                        {
+                            LLViewerObject* object = gObjectList.getObject(i);
+                            if (object &&
+                                object->getRegion() == region &&
+                                object->getVolume())
+                            {
+                                object_count++;
+                                S32 bytes = 0;
+                                S32 visible = 0;
+                                cost += object->getStreamingCost();
                                 LLMeshCostData costs;
                                 if (object->getCostData(costs))
                                 {
@@ -709,96 +709,96 @@ class LLDebugText
                                     visible = costs.getSizeByLOD(object->getLOD());
                                 }
 
-								S32 vt = 0;
-								count += object->getTriangleCount(&vt);
-								vcount += vt;
-								total_bytes += bytes;
-								visible_bytes += visible;
-							}
-						}
-					}
-				}
-				else
-				{
-					label = "Selection";
-					cost = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectStreamingCost(&total_bytes, &visible_bytes);
-					count = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectTriangleCount(&vcount);
-					object_count = LLSelectMgr::getInstance()->getSelection()->getObjectCount();
-				}
-					
-				addText(xpos,ypos, llformat("%s streaming cost: %.1f", label, cost));
-				ypos += y_inc;
-
-				addText(xpos, ypos, llformat("    %.3f KTris, %.3f KVerts, %.1f/%.1f KB, %d objects",
-										count/1000.f, vcount/1000.f, visible_bytes/1024.f, total_bytes/1024.f, object_count));
-				ypos += y_inc;
-			
-			}
-
-			addText(xpos, ypos, llformat("%d Texture Binds", LLImageGL::sBindCount));
-			ypos += y_inc;
-
-			addText(xpos, ypos, llformat("%d Unique Textures", LLImageGL::sUniqueCount));
-			ypos += y_inc;
-
-			addText(xpos, ypos, llformat("%d Render Calls", (U32)last_frame_recording.getSampleCount(LLPipeline::sStatBatchSize)));
+                                S32 vt = 0;
+                                count += object->getTriangleCount(&vt);
+                                vcount += vt;
+                                total_bytes += bytes;
+                                visible_bytes += visible;
+                            }
+                        }
+                    }
+                }
+                else
+                {
+                    label = "Selection";
+                    cost = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectStreamingCost(&total_bytes, &visible_bytes);
+                    count = LLSelectMgr::getInstance()->getSelection()->getSelectedObjectTriangleCount(&vcount);
+                    object_count = LLSelectMgr::getInstance()->getSelection()->getObjectCount();
+                }
+
+                addText(xpos,ypos, llformat("%s streaming cost: %.1f", label, cost));
+                ypos += y_inc;
+
+                addText(xpos, ypos, llformat("    %.3f KTris, %.3f KVerts, %.1f/%.1f KB, %d objects",
+                                        count/1000.f, vcount/1000.f, visible_bytes/1024.f, total_bytes/1024.f, object_count));
+                ypos += y_inc;
+
+            }
+
+            addText(xpos, ypos, llformat("%d Texture Binds", LLImageGL::sBindCount));
+            ypos += y_inc;
+
+            addText(xpos, ypos, llformat("%d Unique Textures", LLImageGL::sUniqueCount));
+            ypos += y_inc;
+
+            addText(xpos, ypos, llformat("%d Render Calls", (U32)last_frame_recording.getSampleCount(LLPipeline::sStatBatchSize)));
             ypos += y_inc;
 
-			addText(xpos, ypos, llformat("%d/%d Objects Active", gObjectList.getNumActiveObjects(), gObjectList.getNumObjects()));
-			ypos += y_inc;
+            addText(xpos, ypos, llformat("%d/%d Objects Active", gObjectList.getNumActiveObjects(), gObjectList.getNumObjects()));
+            ypos += y_inc;
 
-			addText(xpos, ypos, llformat("%d Matrix Ops", gPipeline.mMatrixOpCount));
-			ypos += y_inc;
+            addText(xpos, ypos, llformat("%d Matrix Ops", gPipeline.mMatrixOpCount));
+            ypos += y_inc;
 
-			addText(xpos, ypos, llformat("%d Texture Matrix Ops", gPipeline.mTextureMatrixOps));
-			ypos += y_inc;
+            addText(xpos, ypos, llformat("%d Texture Matrix Ops", gPipeline.mTextureMatrixOps));
+            ypos += y_inc;
 
-			gPipeline.mTextureMatrixOps = 0;
-			gPipeline.mMatrixOpCount = 0;
+            gPipeline.mTextureMatrixOps = 0;
+            gPipeline.mMatrixOpCount = 0;
 
- 			if (last_frame_recording.getSampleCount(LLPipeline::sStatBatchSize) > 0)
-			{
+            if (last_frame_recording.getSampleCount(LLPipeline::sStatBatchSize) > 0)
+            {
                 addText(xpos, ypos, llformat("Batch min/max/mean: %d/%d/%d", (U32)last_frame_recording.getMin(LLPipeline::sStatBatchSize), (U32)last_frame_recording.getMax(LLPipeline::sStatBatchSize), (U32)last_frame_recording.getMean(LLPipeline::sStatBatchSize)));
-			}
+            }
             ypos += y_inc;
 
-			addText(xpos, ypos, llformat("UI Verts/Calls: %d/%d", LLRender::sUIVerts, LLRender::sUICalls));
-			LLRender::sUICalls = LLRender::sUIVerts = 0;
-			ypos += y_inc;
+            addText(xpos, ypos, llformat("UI Verts/Calls: %d/%d", LLRender::sUIVerts, LLRender::sUICalls));
+            LLRender::sUICalls = LLRender::sUIVerts = 0;
+            ypos += y_inc;
+
+            addText(xpos,ypos, llformat("%d/%d Nodes visible", gPipeline.mNumVisibleNodes, LLSpatialGroup::sNodeCount));
+
+            ypos += y_inc;
+
+            if (!LLOcclusionCullingGroup::sPendingQueries.empty())
+            {
+                addText(xpos,ypos, llformat("%d Queries pending", LLOcclusionCullingGroup::sPendingQueries.size()));
+                ypos += y_inc;
+            }
 
-			addText(xpos,ypos, llformat("%d/%d Nodes visible", gPipeline.mNumVisibleNodes, LLSpatialGroup::sNodeCount));
-			
-			ypos += y_inc;
 
-			if (!LLOcclusionCullingGroup::sPendingQueries.empty())
-			{
-				addText(xpos,ypos, llformat("%d Queries pending", LLOcclusionCullingGroup::sPendingQueries.size()));
-				ypos += y_inc;
-			}
+            addText(xpos,ypos, llformat("%d Avatars visible", LLVOAvatar::sNumVisibleAvatars));
 
+            ypos += y_inc;
+
+            addText(xpos,ypos, llformat("%d Lights visible", LLPipeline::sVisibleLightCount));
+
+            ypos += y_inc;
 
-			addText(xpos,ypos, llformat("%d Avatars visible", LLVOAvatar::sNumVisibleAvatars));
-			
-			ypos += y_inc;
+            if (gMeshRepo.meshRezEnabled())
+            {
+                addText(xpos, ypos, llformat("%.3f MB Mesh Data Received", LLMeshRepository::sBytesReceived/(1024.f*1024.f)));
 
-			addText(xpos,ypos, llformat("%d Lights visible", LLPipeline::sVisibleLightCount));
-			
-			ypos += y_inc;
+                ypos += y_inc;
 
-			if (gMeshRepo.meshRezEnabled())
-			{
-				addText(xpos, ypos, llformat("%.3f MB Mesh Data Received", LLMeshRepository::sBytesReceived/(1024.f*1024.f)));
-				
-				ypos += y_inc;
-				
-				addText(xpos, ypos, llformat("%d/%d Mesh HTTP Requests/Retries", LLMeshRepository::sHTTPRequestCount,
-					LLMeshRepository::sHTTPRetryCount));
-				ypos += y_inc;
+                addText(xpos, ypos, llformat("%d/%d Mesh HTTP Requests/Retries", LLMeshRepository::sHTTPRequestCount,
+                    LLMeshRepository::sHTTPRetryCount));
+                ypos += y_inc;
 
-				addText(xpos, ypos, llformat("%d/%d Mesh LOD Pending/Processing", LLMeshRepository::sLODPending, LLMeshRepository::sLODProcessing));
-				ypos += y_inc;
+                addText(xpos, ypos, llformat("%d/%d Mesh LOD Pending/Processing", LLMeshRepository::sLODPending, LLMeshRepository::sLODProcessing));
+                ypos += y_inc;
 
-				addText(xpos, ypos, llformat("%.3f/%.3f MB Mesh Cache Read/Write ", LLMeshRepository::sCacheBytesRead/(1024.f*1024.f), LLMeshRepository::sCacheBytesWritten/(1024.f*1024.f)));
+                addText(xpos, ypos, llformat("%.3f/%.3f MB Mesh Cache Read/Write ", LLMeshRepository::sCacheBytesRead/(1024.f*1024.f), LLMeshRepository::sCacheBytesWritten/(1024.f*1024.f)));
                 ypos += y_inc;
 
                 addText(xpos, ypos, llformat("%.3f/%.3f MB Mesh Skins/Decompositions Memory", LLMeshRepository::sCacheBytesSkins / (1024.f*1024.f), LLMeshRepository::sCacheBytesDecomps / (1024.f*1024.f)));
@@ -806,76 +806,76 @@ class LLDebugText
 
                 addText(xpos, ypos, llformat("%.3f MB Mesh Headers Memory", LLMeshRepository::sCacheBytesHeaders / (1024.f*1024.f)));
 
-				ypos += y_inc;
-			}
+                ypos += y_inc;
+            }
 
             gPipeline.mNumVisibleNodes = LLPipeline::sVisibleLightCount = 0;
-		}
-		static LLCachedControl<bool> debugShowAvatarRenderInfo(gSavedSettings, "DebugShowAvatarRenderInfo");
-		if (debugShowAvatarRenderInfo)
-		{
-			std::map<std::string, LLVOAvatar*> sorted_avs;
-			
-			std::vector<LLCharacter*>::iterator sort_iter = LLCharacter::sInstances.begin();
-			while (sort_iter != LLCharacter::sInstances.end())
-			{
-				LLVOAvatar* avatar = static_cast<LLVOAvatar*>(*sort_iter);
-				if (avatar &&
-					!avatar->isDead())						// Not dead yet
-				{
-					// Stuff into a sorted map so the display is ordered
-					sorted_avs[avatar->getFullname()] = avatar;
-				}
-				sort_iter++;
-			}
-
-			std::string trunc_name;
-			std::map<std::string, LLVOAvatar*>::reverse_iterator av_iter = sorted_avs.rbegin();		// Put "A" at the top
-			while (av_iter != sorted_avs.rend())
-			{
-				LLVOAvatar* avatar = av_iter->second;
-
-				avatar->calculateUpdateRenderComplexity(); // Make sure the numbers are up-to-date
-
-				trunc_name = utf8str_truncate(avatar->getFullname(), 16);
-				addText(xpos, ypos, llformat("%s : %s, complexity %d, area %.2f",
-					trunc_name.c_str(),
+        }
+        static LLCachedControl<bool> debugShowAvatarRenderInfo(gSavedSettings, "DebugShowAvatarRenderInfo");
+        if (debugShowAvatarRenderInfo)
+        {
+            std::map<std::string, LLVOAvatar*> sorted_avs;
+
+            std::vector<LLCharacter*>::iterator sort_iter = LLCharacter::sInstances.begin();
+            while (sort_iter != LLCharacter::sInstances.end())
+            {
+                LLVOAvatar* avatar = static_cast<LLVOAvatar*>(*sort_iter);
+                if (avatar &&
+                    !avatar->isDead())                      // Not dead yet
+                {
+                    // Stuff into a sorted map so the display is ordered
+                    sorted_avs[avatar->getFullname()] = avatar;
+                }
+                sort_iter++;
+            }
+
+            std::string trunc_name;
+            std::map<std::string, LLVOAvatar*>::reverse_iterator av_iter = sorted_avs.rbegin();     // Put "A" at the top
+            while (av_iter != sorted_avs.rend())
+            {
+                LLVOAvatar* avatar = av_iter->second;
+
+                avatar->calculateUpdateRenderComplexity(); // Make sure the numbers are up-to-date
+
+                trunc_name = utf8str_truncate(avatar->getFullname(), 16);
+                addText(xpos, ypos, llformat("%s : %s, complexity %d, area %.2f",
+                    trunc_name.c_str(),
                     LLVOAvatar::rezStatusToString(avatar->getRezzedStatus()).c_str(),
-					avatar->getVisualComplexity(),
-					avatar->getAttachmentSurfaceArea()));
-				ypos += y_inc;
-				av_iter++;
-			}
-		}
-
-		static LLCachedControl<bool> debugShowRenderMatrices(gSavedSettings, "DebugShowRenderMatrices");
-		if (debugShowRenderMatrices)
-		{
-			char camera_lines[8][32];
-			memset(camera_lines, ' ', sizeof(camera_lines));
-
-			// Projection last column is always <0,0,-1.0001,0>
-			// Projection last row is always <0,0,-0.2>
-			mBackRectCamera1.mBottom = ypos - y_inc + 2;
-			MATRIX_ROW_N32_TO_STR(gGLProjection.getF32ptr(), 12, camera_lines[7]); addText(xpos, ypos, std::string(camera_lines[7])); ypos += y_inc;
-			MATRIX_ROW_N32_TO_STR(gGLProjection.getF32ptr(),  8,camera_lines[6]); addText(xpos, ypos, std::string(camera_lines[6])); ypos += y_inc;
-			MATRIX_ROW_N32_TO_STR(gGLProjection.getF32ptr(),  4,camera_lines[5]); addText(xpos, ypos, std::string(camera_lines[5])); ypos += y_inc; mBackRectCamera1.mTop    = ypos + 2;
-			MATRIX_ROW_N32_TO_STR(gGLProjection.getF32ptr(),  0,camera_lines[4]); addText(xpos, ypos, std::string(camera_lines[4])); ypos += y_inc; mBackRectCamera2.mBottom = ypos + 2;
-
-			addText(xpos, ypos, "Projection Matrix");
-			ypos += y_inc;
-
-			// View last column is always <0,0,0,1>
-			MATRIX_ROW_F32_TO_STR(gGLModelView.getF32ptr(), 12,camera_lines[3]); addText(xpos, ypos, std::string(camera_lines[3])); ypos += y_inc;
-			MATRIX_ROW_N32_TO_STR(gGLModelView.getF32ptr(),  8,camera_lines[2]); addText(xpos, ypos, std::string(camera_lines[2])); ypos += y_inc;
-			MATRIX_ROW_N32_TO_STR(gGLModelView.getF32ptr(),  4,camera_lines[1]); addText(xpos, ypos, std::string(camera_lines[1])); ypos += y_inc; mBackRectCamera2.mTop = ypos + 2;
-			MATRIX_ROW_N32_TO_STR(gGLModelView.getF32ptr(),  0,camera_lines[0]); addText(xpos, ypos, std::string(camera_lines[0])); ypos += y_inc;
-
-			addText(xpos, ypos, "View Matrix");
-			ypos += y_inc;
-		}
-		static LLCachedControl<bool> debugShowColor(gSavedSettings, "DebugShowColor");
-		if (debugShowColor && !LLRender::sNsightDebugSupport)
+                    avatar->getVisualComplexity(),
+                    avatar->getAttachmentSurfaceArea()));
+                ypos += y_inc;
+                av_iter++;
+            }
+        }
+
+        static LLCachedControl<bool> debugShowRenderMatrices(gSavedSettings, "DebugShowRenderMatrices");
+        if (debugShowRenderMatrices)
+        {
+            char camera_lines[8][32];
+            memset(camera_lines, ' ', sizeof(camera_lines));
+
+            // Projection last column is always <0,0,-1.0001,0>
+            // Projection last row is always <0,0,-0.2>
+            mBackRectCamera1.mBottom = ypos - y_inc + 2;
+            MATRIX_ROW_N32_TO_STR(gGLProjection.getF32ptr(), 12, camera_lines[7]); addText(xpos, ypos, std::string(camera_lines[7])); ypos += y_inc;
+            MATRIX_ROW_N32_TO_STR(gGLProjection.getF32ptr(),  8,camera_lines[6]); addText(xpos, ypos, std::string(camera_lines[6])); ypos += y_inc;
+            MATRIX_ROW_N32_TO_STR(gGLProjection.getF32ptr(),  4,camera_lines[5]); addText(xpos, ypos, std::string(camera_lines[5])); ypos += y_inc; mBackRectCamera1.mTop    = ypos + 2;
+            MATRIX_ROW_N32_TO_STR(gGLProjection.getF32ptr(),  0,camera_lines[4]); addText(xpos, ypos, std::string(camera_lines[4])); ypos += y_inc; mBackRectCamera2.mBottom = ypos + 2;
+
+            addText(xpos, ypos, "Projection Matrix");
+            ypos += y_inc;
+
+            // View last column is always <0,0,0,1>
+            MATRIX_ROW_F32_TO_STR(gGLModelView.getF32ptr(), 12,camera_lines[3]); addText(xpos, ypos, std::string(camera_lines[3])); ypos += y_inc;
+            MATRIX_ROW_N32_TO_STR(gGLModelView.getF32ptr(),  8,camera_lines[2]); addText(xpos, ypos, std::string(camera_lines[2])); ypos += y_inc;
+            MATRIX_ROW_N32_TO_STR(gGLModelView.getF32ptr(),  4,camera_lines[1]); addText(xpos, ypos, std::string(camera_lines[1])); ypos += y_inc; mBackRectCamera2.mTop = ypos + 2;
+            MATRIX_ROW_N32_TO_STR(gGLModelView.getF32ptr(),  0,camera_lines[0]); addText(xpos, ypos, std::string(camera_lines[0])); ypos += y_inc;
+
+            addText(xpos, ypos, "View Matrix");
+            ypos += y_inc;
+        }
+        static LLCachedControl<bool> debugShowColor(gSavedSettings, "DebugShowColor");
+        if (debugShowColor && !LLRender::sNsightDebugSupport)
         {
             U8 color[4];
             LLCoordGL coord = gViewerWindow->getCurrentMouse();
@@ -883,166 +883,166 @@ class LLDebugText
             // Convert x,y to raw pixel coords
             S32 x_raw = ll_round(coord.mX * gViewerWindow->getWindowWidthRaw() / (F32) gViewerWindow->getWindowWidthScaled());
             S32 y_raw = ll_round(coord.mY * gViewerWindow->getWindowHeightRaw() / (F32) gViewerWindow->getWindowHeightScaled());
-            
+
             glReadPixels(x_raw, y_raw, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, color);
             addText(xpos, ypos, llformat("Pixel <%1d, %1d> R:%1d G:%1d B:%1d A:%1d", x_raw, y_raw, color[0], color[1], color[2], color[3]));
             ypos += y_inc;
         }
 
         // only display these messages if we are actually rendering beacons at this moment
-		if (LLPipeline::getRenderBeacons() && LLFloaterReg::instanceVisible("beacons"))
-		{
-			if (LLPipeline::getRenderMOAPBeacons())
-			{
-				addText(xpos, ypos, "Viewing media beacons (white)");
-				ypos += y_inc;
-			}
-
-			if (LLPipeline::toggleRenderTypeControlNegated(LLPipeline::RENDER_TYPE_PARTICLES))
-			{
-				addText(xpos, ypos, particle_hiding);
-				ypos += y_inc;
-			}
-
-			if (LLPipeline::getRenderParticleBeacons())
-			{
-				addText(xpos, ypos, "Viewing particle beacons (blue)");
-				ypos += y_inc;
-			}
-
-			if (LLPipeline::getRenderSoundBeacons())
-			{
-				addText(xpos, ypos, "Viewing sound beacons (yellow)");
-				ypos += y_inc;
-			}
-
-			if (LLPipeline::getRenderScriptedBeacons())
-			{
-				addText(xpos, ypos, beacon_scripted);
-				ypos += y_inc;
-			}
-			else
-				if (LLPipeline::getRenderScriptedTouchBeacons())
-				{
-					addText(xpos, ypos, beacon_scripted_touch);
-					ypos += y_inc;
-				}
-
-			if (LLPipeline::getRenderPhysicalBeacons())
-			{
-				addText(xpos, ypos, "Viewing physical object beacons (green)");
-				ypos += y_inc;
-			}
-		}
-
-		static LLUICachedControl<bool> show_sun_beacon("sunbeacon", false);
-		static LLUICachedControl<bool> show_moon_beacon("moonbeacon", false);
-
-		if (show_sun_beacon)
-		{
-			addText(xpos, ypos, beacon_sun);
-			ypos += y_inc;
-		}
-		if (show_moon_beacon)
-		{
-			addText(xpos, ypos, beacon_moon);
-			ypos += y_inc;
-		}
-
-		if(log_texture_traffic)
-		{	
-			U32 old_y = ypos ;
-			for(S32 i = LLViewerTexture::BOOST_NONE; i < LLViewerTexture::MAX_GL_IMAGE_CATEGORY; i++)
-			{
-				if(gTotalTextureBytesPerBoostLevel[i] > U64Bytes(0))
-				{
-					addText(xpos, ypos, llformat("Boost_Level %d:  %.3f MB", i, F32Megabytes(gTotalTextureBytesPerBoostLevel[i]).value()));
-					ypos += y_inc;
-				}
-			}
-			if(ypos != old_y)
-			{
-				addText(xpos, ypos, "Network traffic for textures:");
-				ypos += y_inc;
-			}
-		}				
-
-		static LLCachedControl<bool> debugShowTextureInfo(gSavedSettings, "DebugShowTextureInfo");
-		if (debugShowTextureInfo)
-		{
-			LLViewerObject* objectp = NULL ;
-			
-			LLSelectNode* nodep = LLSelectMgr::instance().getHoverNode();
-			if (nodep)
-			{
-				objectp = nodep->getObject();
-			}
-
-			if (objectp && !objectp->isDead())
-			{
-				S32 num_faces = objectp->mDrawable->getNumFaces() ;
-				std::set<LLViewerFetchedTexture*> tex_list;
-
-				for(S32 i = 0 ; i < num_faces; i++)
-				{
-					LLFace* facep = objectp->mDrawable->getFace(i) ;
-					if(facep)
-					{						
-						LLViewerFetchedTexture* tex = dynamic_cast<LLViewerFetchedTexture*>(facep->getTexture()) ;
-						if(tex)
-						{
-							if(tex_list.find(tex) != tex_list.end())
-							{
-								continue ; //already displayed.
-							}
-							tex_list.insert(tex);
-
-							std::string uuid_str;
-							tex->getID().toString(uuid_str);
-							uuid_str = uuid_str.substr(0,7);
-
-							addText(xpos, ypos, llformat("ID: %s v_size: %.3f", uuid_str.c_str(), tex->getMaxVirtualSize()));
-							ypos += y_inc;
-
-							addText(xpos, ypos, llformat("discard level: %d desired level: %d Missing: %s", tex->getDiscardLevel(), 
-								tex->getDesiredDiscardLevel(), tex->isMissingAsset() ? "Y" : "N"));
-							ypos += y_inc;
-						}
-					}
-				}
-			}
-		}
-	}
-
-	void draw()
-	{
-		LL_RECORD_BLOCK_TIME(FTM_DISPLAY_DEBUG_TEXT);
-
-		// Camera matrix text is hard to see again a white background
-		// Add a dark background underneath the matrices for readability (contrast)
-		if (mBackRectCamera1.mTop >= 0)
-		{
-			mBackColor.setAlpha( 0.75f );
-			gl_rect_2d(mBackRectCamera1, mBackColor, true);
-
-			mBackColor.setAlpha( 0.66f );
-			gl_rect_2d(mBackRectCamera2, mBackColor, true);
-		}
-
-		for (line_list_t::iterator iter = mLineList.begin();
-			 iter != mLineList.end(); ++iter)
-		{
-			const Line& line = *iter;
-			LLFontGL::getFontMonospace()->renderUTF8(line.text, 0, (F32)line.x, (F32)line.y, mTextColor,
-					LLFontGL::LEFT, LLFontGL::TOP, LLFontGL::NORMAL, LLFontGL::NO_SHADOW);
-		}
-	}
+        if (LLPipeline::getRenderBeacons() && LLFloaterReg::instanceVisible("beacons"))
+        {
+            if (LLPipeline::getRenderMOAPBeacons())
+            {
+                addText(xpos, ypos, "Viewing media beacons (white)");
+                ypos += y_inc;
+            }
+
+            if (LLPipeline::toggleRenderTypeControlNegated(LLPipeline::RENDER_TYPE_PARTICLES))
+            {
+                addText(xpos, ypos, particle_hiding);
+                ypos += y_inc;
+            }
+
+            if (LLPipeline::getRenderParticleBeacons())
+            {
+                addText(xpos, ypos, "Viewing particle beacons (blue)");
+                ypos += y_inc;
+            }
+
+            if (LLPipeline::getRenderSoundBeacons())
+            {
+                addText(xpos, ypos, "Viewing sound beacons (yellow)");
+                ypos += y_inc;
+            }
+
+            if (LLPipeline::getRenderScriptedBeacons())
+            {
+                addText(xpos, ypos, beacon_scripted);
+                ypos += y_inc;
+            }
+            else
+                if (LLPipeline::getRenderScriptedTouchBeacons())
+                {
+                    addText(xpos, ypos, beacon_scripted_touch);
+                    ypos += y_inc;
+                }
+
+            if (LLPipeline::getRenderPhysicalBeacons())
+            {
+                addText(xpos, ypos, "Viewing physical object beacons (green)");
+                ypos += y_inc;
+            }
+        }
+
+        static LLUICachedControl<bool> show_sun_beacon("sunbeacon", false);
+        static LLUICachedControl<bool> show_moon_beacon("moonbeacon", false);
+
+        if (show_sun_beacon)
+        {
+            addText(xpos, ypos, beacon_sun);
+            ypos += y_inc;
+        }
+        if (show_moon_beacon)
+        {
+            addText(xpos, ypos, beacon_moon);
+            ypos += y_inc;
+        }
+
+        if(log_texture_traffic)
+        {
+            U32 old_y = ypos ;
+            for(S32 i = LLViewerTexture::BOOST_NONE; i < LLViewerTexture::MAX_GL_IMAGE_CATEGORY; i++)
+            {
+                if(gTotalTextureBytesPerBoostLevel[i] > U64Bytes(0))
+                {
+                    addText(xpos, ypos, llformat("Boost_Level %d:  %.3f MB", i, F32Megabytes(gTotalTextureBytesPerBoostLevel[i]).value()));
+                    ypos += y_inc;
+                }
+            }
+            if(ypos != old_y)
+            {
+                addText(xpos, ypos, "Network traffic for textures:");
+                ypos += y_inc;
+            }
+        }
+
+        static LLCachedControl<bool> debugShowTextureInfo(gSavedSettings, "DebugShowTextureInfo");
+        if (debugShowTextureInfo)
+        {
+            LLViewerObject* objectp = NULL ;
+
+            LLSelectNode* nodep = LLSelectMgr::instance().getHoverNode();
+            if (nodep)
+            {
+                objectp = nodep->getObject();
+            }
+
+            if (objectp && !objectp->isDead())
+            {
+                S32 num_faces = objectp->mDrawable->getNumFaces() ;
+                std::set<LLViewerFetchedTexture*> tex_list;
+
+                for(S32 i = 0 ; i < num_faces; i++)
+                {
+                    LLFace* facep = objectp->mDrawable->getFace(i) ;
+                    if(facep)
+                    {
+                        LLViewerFetchedTexture* tex = dynamic_cast<LLViewerFetchedTexture*>(facep->getTexture()) ;
+                        if(tex)
+                        {
+                            if(tex_list.find(tex) != tex_list.end())
+                            {
+                                continue ; //already displayed.
+                            }
+                            tex_list.insert(tex);
+
+                            std::string uuid_str;
+                            tex->getID().toString(uuid_str);
+                            uuid_str = uuid_str.substr(0,7);
+
+                            addText(xpos, ypos, llformat("ID: %s v_size: %.3f", uuid_str.c_str(), tex->getMaxVirtualSize()));
+                            ypos += y_inc;
+
+                            addText(xpos, ypos, llformat("discard level: %d desired level: %d Missing: %s", tex->getDiscardLevel(),
+                                tex->getDesiredDiscardLevel(), tex->isMissingAsset() ? "Y" : "N"));
+                            ypos += y_inc;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    void draw()
+    {
+        LL_RECORD_BLOCK_TIME(FTM_DISPLAY_DEBUG_TEXT);
+
+        // Camera matrix text is hard to see again a white background
+        // Add a dark background underneath the matrices for readability (contrast)
+        if (mBackRectCamera1.mTop >= 0)
+        {
+            mBackColor.setAlpha( 0.75f );
+            gl_rect_2d(mBackRectCamera1, mBackColor, true);
+
+            mBackColor.setAlpha( 0.66f );
+            gl_rect_2d(mBackRectCamera2, mBackColor, true);
+        }
+
+        for (line_list_t::iterator iter = mLineList.begin();
+             iter != mLineList.end(); ++iter)
+        {
+            const Line& line = *iter;
+            LLFontGL::getFontMonospace()->renderUTF8(line.text, 0, (F32)line.x, (F32)line.y, mTextColor,
+                    LLFontGL::LEFT, LLFontGL::TOP, LLFontGL::NORMAL, LLFontGL::NO_SHADOW);
+        }
+    }
 
 };
 
 void LLViewerWindow::updateDebugText()
 {
-	mDebugText->update();
+    mDebugText->update();
 }
 
 ////////////////////////////////////////////////////////////////////////////
@@ -1051,16 +1051,16 @@ void LLViewerWindow::updateDebugText()
 //
 
 LLViewerWindow::Params::Params()
-:	title("title"),
-	name("name"),
-	x("x"),
-	y("y"),
-	width("width"),
-	height("height"),
-	min_width("min_width"),
-	min_height("min_height"),
-	fullscreen("fullscreen", false),
-	ignore_pixel_depth("ignore_pixel_depth", false)
+:   title("title"),
+    name("name"),
+    x("x"),
+    y("y"),
+    width("width"),
+    height("height"),
+    min_width("min_width"),
+    min_height("min_height"),
+    fullscreen("fullscreen", false),
+    ignore_pixel_depth("ignore_pixel_depth", false)
 {}
 
 
@@ -1077,243 +1077,243 @@ void LLViewerWindow::handlePieMenu(S32 x, S32 y, MASK mask)
 
 BOOL LLViewerWindow::handleAnyMouseClick(LLWindow *window, LLCoordGL pos, MASK mask, EMouseClickType clicktype, BOOL down, bool& is_toolmgr_action)
 {
-	const char* buttonname = "";
-	const char* buttonstatestr = "";
-	S32 x = pos.mX;
-	S32 y = pos.mY;
-	x = ll_round((F32)x / mDisplayScale.mV[VX]);
-	y = ll_round((F32)y / mDisplayScale.mV[VY]);
+    const char* buttonname = "";
+    const char* buttonstatestr = "";
+    S32 x = pos.mX;
+    S32 y = pos.mY;
+    x = ll_round((F32)x / mDisplayScale.mV[VX]);
+    y = ll_round((F32)y / mDisplayScale.mV[VY]);
 
-    // Handle non-consuming global keybindings, like voice 
+    // Handle non-consuming global keybindings, like voice
     gViewerInput.handleGlobalBindsMouse(clicktype, mask, down);
 
-	// only send mouse clicks to UI if UI is visible
-	if(gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
-	{	
-
-		if (down)
-		{
-			buttonstatestr = "down" ;
-		}
-		else
-		{
-			buttonstatestr = "up" ;
-		}
-		
-		switch (clicktype)
-		{
-		case CLICK_LEFT:
-			mLeftMouseDown = down;
-			buttonname = "Left";
-			break;
-		case CLICK_RIGHT:
-			mRightMouseDown = down;
-			buttonname = "Right";
-			break;
-		case CLICK_MIDDLE:
-			mMiddleMouseDown = down;
-			buttonname = "Middle";
-			break;
-		case CLICK_DOUBLELEFT:
-			mLeftMouseDown = down;
-			buttonname = "Left Double Click";
-			break;
-		case CLICK_BUTTON4:
-			buttonname = "Button 4";
-			break;
-		case CLICK_BUTTON5:
-			buttonname = "Button 5";
-			break;
-		default:
-			break; // COUNT and NONE
-		}
-		
-		LLView::sMouseHandlerMessage.clear();
-
-		if (gMenuBarView)
-		{
-			// stop ALT-key access to menu
-			gMenuBarView->resetMenuTrigger();
-		}
-
-		if (gDebugClicks)
-		{	
-			LL_INFOS() << "ViewerWindow " << buttonname << " mouse " << buttonstatestr << " at " << x << "," << y << LL_ENDL;
-		}
-
-		// Make sure we get a corresponding mouseup event, even if the mouse leaves the window
-		if (down)
-			mWindow->captureMouse();
-		else
-			mWindow->releaseMouse();
-
-		// Indicate mouse was active
-		LLUI::resetMouseIdleTimer();
-
-		// Don't let the user move the mouse out of the window until mouse up.
-		if( LLToolMgr::getInstance()->getCurrentTool()->clipMouseWhenDown() )
-		{
-			mWindow->setMouseClipping(down);
-		}
-
-		LLMouseHandler* mouse_captor = gFocusMgr.getMouseCapture();
-		if( mouse_captor )
-		{
-			S32 local_x;
-			S32 local_y;
-			mouse_captor->screenPointToLocal( x, y, &local_x, &local_y );
-			if (LLView::sDebugMouseHandling)
-			{
-				LL_INFOS() << buttonname << " Mouse " << buttonstatestr << " handled by captor " << mouse_captor->getName() << LL_ENDL;
-			}
-
-			BOOL r = mouse_captor->handleAnyMouseClick(local_x, local_y, mask, clicktype, down); 
-			if (r) {
-
-				LL_DEBUGS() << "LLViewerWindow::handleAnyMouseClick viewer with mousecaptor calling updatemouseeventinfo - local_x|global x  "<< local_x << " " << x  << "local/global y " << local_y << " " << y << LL_ENDL;
-#if AL_VIEWER_EVENT_RECORDER
-				if (LLViewerEventRecorder::getLoggingStatus())
-				{
-					LLViewerEventRecorder::instance().setMouseGlobalCoords(x,y);
-					LLViewerEventRecorder::instance().logMouseEvent(std::string(buttonstatestr),std::string(buttonname)); 
-				}
-#endif
-			}
-			else if (down && clicktype == CLICK_RIGHT)
-			{
-				handlePieMenu(x, y, mask);
-				r = TRUE;
-			}
-			return r;
-		}
-
-		// Mark the click as handled and return if we aren't within the root view to avoid spurious bugs
-		if( !mRootView->pointInView(x, y) )
-		{
-			return TRUE;
-		}
-		// Give the UI views a chance to process the click
-
-		BOOL r= mRootView->handleAnyMouseClick(x, y, mask, clicktype, down) ;
-		if (r) 
-		{
-
-			LL_DEBUGS() << "LLViewerWindow::handleAnyMouseClick calling updatemouseeventinfo - global x  "<< " " << x	<< "global y " << y	 << "buttonstate: " << buttonstatestr << " buttonname " << buttonname << LL_ENDL;
+    // only send mouse clicks to UI if UI is visible
+    if(gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
+    {
 
-#if AL_VIEWER_EVENT_RECORDER
-			if (LLViewerEventRecorder::getLoggingStatus())
-			{
-				LLViewerEventRecorder::instance().setMouseGlobalCoords(x,y);
-
-				// Clear local coords - this was a click on root window so these are not needed
-				// By not including them, this allows the test skeleton generation tool to be smarter when generating code
-				// the code generator can be smarter because when local coords are present it can try the xui path with local coords
-				// and fallback to global coordinates only if needed. 
-				// The drawback to this approach is sometimes a valid xui path will appear to work fine, but NOT interact with the UI element
-				// (VITA support not implemented yet or not visible to VITA due to widget further up xui path not being visible to VITA)
-				// For this reason it's best to provide hints where possible here by leaving out local coordinates
-				LLViewerEventRecorder::instance().setMouseLocalCoords(-1,-1);
-				LLViewerEventRecorder::instance().logMouseEvent(buttonstatestr,buttonname); 
-			}
-
-			if (LLView::sDebugMouseHandling)
-			{
-				LL_INFOS() << buttonname << " Mouse " << buttonstatestr << " " << LLViewerEventRecorder::instance().get_xui()	<< LL_ENDL;
-			} 
-#endif
-			return TRUE;
-		} else if (LLView::sDebugMouseHandling)
-			{
-				LL_INFOS() << buttonname << " Mouse " << buttonstatestr << " not handled by view" << LL_ENDL;
-			}
-	}
-
-	// Do not allow tool manager to handle mouseclicks if we have disconnected	
-	if(!gDisconnected && LLToolMgr::getInstance()->getCurrentTool()->handleAnyMouseClick( x, y, mask, clicktype, down ) )
-	{
-#if AL_VIEWER_EVENT_RECORDER
-		if (LLViewerEventRecorder::getLoggingStatus())
-		{
-			LLViewerEventRecorder::instance().clear_xui(); 
-		}
-#endif
-        is_toolmgr_action = true;
-		return TRUE;
-	}
+        if (down)
+        {
+            buttonstatestr = "down" ;
+        }
+        else
+        {
+            buttonstatestr = "up" ;
+        }
 
-	if (down && clicktype == CLICK_RIGHT)
-	{
-		handlePieMenu(x, y, mask);
-		return TRUE;
-	}
+        switch (clicktype)
+        {
+        case CLICK_LEFT:
+            mLeftMouseDown = down;
+            buttonname = "Left";
+            break;
+        case CLICK_RIGHT:
+            mRightMouseDown = down;
+            buttonname = "Right";
+            break;
+        case CLICK_MIDDLE:
+            mMiddleMouseDown = down;
+            buttonname = "Middle";
+            break;
+        case CLICK_DOUBLELEFT:
+            mLeftMouseDown = down;
+            buttonname = "Left Double Click";
+            break;
+        case CLICK_BUTTON4:
+            buttonname = "Button 4";
+            break;
+        case CLICK_BUTTON5:
+            buttonname = "Button 5";
+            break;
+        default:
+            break; // COUNT and NONE
+        }
 
-	// If we got this far on a down-click, it wasn't handled.
-	// Up-clicks, though, are always handled as far as the OS is concerned.
-	BOOL default_rtn = !down;
-	return default_rtn;
-}
+        LLView::sMouseHandlerMessage.clear();
 
-BOOL LLViewerWindow::handleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask)
-{
-    BOOL down = TRUE;
-    //handleMouse() loops back to LLViewerWindow::handleAnyMouseClick
-    return gViewerInput.handleMouse(window, pos, mask, CLICK_LEFT, down);
-}
+        if (gMenuBarView)
+        {
+            // stop ALT-key access to menu
+            gMenuBarView->resetMenuTrigger();
+        }
 
-BOOL LLViewerWindow::handleDoubleClick(LLWindow *window,  LLCoordGL pos, MASK mask)
-{
-	// try handling as a double-click first, then a single-click if that
-	// wasn't handled.
-	BOOL down = TRUE;
-	if (gViewerInput.handleMouse(window, pos, mask, CLICK_DOUBLELEFT, down))
-	{
-		return TRUE;
-	}
-	return handleMouseDown(window, pos, mask);
-}
+        if (gDebugClicks)
+        {
+            LL_INFOS() << "ViewerWindow " << buttonname << " mouse " << buttonstatestr << " at " << x << "," << y << LL_ENDL;
+        }
 
-BOOL LLViewerWindow::handleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask)
-{
-    BOOL down = FALSE;
-    return gViewerInput.handleMouse(window, pos, mask, CLICK_LEFT, down);
-}
-BOOL LLViewerWindow::handleRightMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask)
-{
-	BOOL down = TRUE;
-	return gViewerInput.handleMouse(window, pos, mask, CLICK_RIGHT, down);
-}
+        // Make sure we get a corresponding mouseup event, even if the mouse leaves the window
+        if (down)
+            mWindow->captureMouse();
+        else
+            mWindow->releaseMouse();
 
-BOOL LLViewerWindow::handleRightMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask)
-{
-	BOOL down = FALSE;
- 	return gViewerInput.handleMouse(window, pos, mask, CLICK_RIGHT, down);
-}
+        // Indicate mouse was active
+        LLUI::resetMouseIdleTimer();
 
-BOOL LLViewerWindow::handleMiddleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask)
-{
-	BOOL down = TRUE;
- 	gViewerInput.handleMouse(window, pos, mask, CLICK_MIDDLE, down);
-  
-  	// Always handled as far as the OS is concerned.
-	return TRUE;
+        // Don't let the user move the mouse out of the window until mouse up.
+        if( LLToolMgr::getInstance()->getCurrentTool()->clipMouseWhenDown() )
+        {
+            mWindow->setMouseClipping(down);
+        }
+
+        LLMouseHandler* mouse_captor = gFocusMgr.getMouseCapture();
+        if( mouse_captor )
+        {
+            S32 local_x;
+            S32 local_y;
+            mouse_captor->screenPointToLocal( x, y, &local_x, &local_y );
+            if (LLView::sDebugMouseHandling)
+            {
+                LL_INFOS() << buttonname << " Mouse " << buttonstatestr << " handled by captor " << mouse_captor->getName() << LL_ENDL;
+            }
+
+            BOOL r = mouse_captor->handleAnyMouseClick(local_x, local_y, mask, clicktype, down);
+            if (r) {
+
+                LL_DEBUGS() << "LLViewerWindow::handleAnyMouseClick viewer with mousecaptor calling updatemouseeventinfo - local_x|global x  "<< local_x << " " << x  << "local/global y " << local_y << " " << y << LL_ENDL;
+#if AL_VIEWER_EVENT_RECORDER
+                if (LLViewerEventRecorder::getLoggingStatus())
+                {
+                    LLViewerEventRecorder::instance().setMouseGlobalCoords(x,y);
+                    LLViewerEventRecorder::instance().logMouseEvent(std::string(buttonstatestr),std::string(buttonname));
+                }
+#endif
+            }
+            else if (down && clicktype == CLICK_RIGHT)
+            {
+                handlePieMenu(x, y, mask);
+                r = TRUE;
+            }
+            return r;
+        }
+
+        // Mark the click as handled and return if we aren't within the root view to avoid spurious bugs
+        if( !mRootView->pointInView(x, y) )
+        {
+            return TRUE;
+        }
+        // Give the UI views a chance to process the click
+
+        BOOL r= mRootView->handleAnyMouseClick(x, y, mask, clicktype, down) ;
+        if (r)
+        {
+
+            LL_DEBUGS() << "LLViewerWindow::handleAnyMouseClick calling updatemouseeventinfo - global x  "<< " " << x   << "global y " << y  << "buttonstate: " << buttonstatestr << " buttonname " << buttonname << LL_ENDL;
+
+#if AL_VIEWER_EVENT_RECORDER
+            if (LLViewerEventRecorder::getLoggingStatus())
+            {
+                LLViewerEventRecorder::instance().setMouseGlobalCoords(x,y);
+
+                // Clear local coords - this was a click on root window so these are not needed
+                // By not including them, this allows the test skeleton generation tool to be smarter when generating code
+                // the code generator can be smarter because when local coords are present it can try the xui path with local coords
+                // and fallback to global coordinates only if needed.
+                // The drawback to this approach is sometimes a valid xui path will appear to work fine, but NOT interact with the UI element
+                // (VITA support not implemented yet or not visible to VITA due to widget further up xui path not being visible to VITA)
+                // For this reason it's best to provide hints where possible here by leaving out local coordinates
+                LLViewerEventRecorder::instance().setMouseLocalCoords(-1,-1);
+                LLViewerEventRecorder::instance().logMouseEvent(buttonstatestr,buttonname);
+            }
+
+            if (LLView::sDebugMouseHandling)
+            {
+                LL_INFOS() << buttonname << " Mouse " << buttonstatestr << " " << LLViewerEventRecorder::instance().get_xui()   << LL_ENDL;
+            }
+#endif
+            return TRUE;
+        } else if (LLView::sDebugMouseHandling)
+            {
+                LL_INFOS() << buttonname << " Mouse " << buttonstatestr << " not handled by view" << LL_ENDL;
+            }
+    }
+
+    // Do not allow tool manager to handle mouseclicks if we have disconnected
+    if(!gDisconnected && LLToolMgr::getInstance()->getCurrentTool()->handleAnyMouseClick( x, y, mask, clicktype, down ) )
+    {
+#if AL_VIEWER_EVENT_RECORDER
+        if (LLViewerEventRecorder::getLoggingStatus())
+        {
+            LLViewerEventRecorder::instance().clear_xui();
+        }
+#endif
+        is_toolmgr_action = true;
+        return TRUE;
+    }
+
+    if (down && clicktype == CLICK_RIGHT)
+    {
+        handlePieMenu(x, y, mask);
+        return TRUE;
+    }
+
+    // If we got this far on a down-click, it wasn't handled.
+    // Up-clicks, though, are always handled as far as the OS is concerned.
+    BOOL default_rtn = !down;
+    return default_rtn;
+}
+
+BOOL LLViewerWindow::handleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask)
+{
+    BOOL down = TRUE;
+    //handleMouse() loops back to LLViewerWindow::handleAnyMouseClick
+    return gViewerInput.handleMouse(window, pos, mask, CLICK_LEFT, down);
+}
+
+BOOL LLViewerWindow::handleDoubleClick(LLWindow *window,  LLCoordGL pos, MASK mask)
+{
+    // try handling as a double-click first, then a single-click if that
+    // wasn't handled.
+    BOOL down = TRUE;
+    if (gViewerInput.handleMouse(window, pos, mask, CLICK_DOUBLELEFT, down))
+    {
+        return TRUE;
+    }
+    return handleMouseDown(window, pos, mask);
+}
+
+BOOL LLViewerWindow::handleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask)
+{
+    BOOL down = FALSE;
+    return gViewerInput.handleMouse(window, pos, mask, CLICK_LEFT, down);
+}
+BOOL LLViewerWindow::handleRightMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask)
+{
+    BOOL down = TRUE;
+    return gViewerInput.handleMouse(window, pos, mask, CLICK_RIGHT, down);
+}
+
+BOOL LLViewerWindow::handleRightMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask)
+{
+    BOOL down = FALSE;
+    return gViewerInput.handleMouse(window, pos, mask, CLICK_RIGHT, down);
+}
+
+BOOL LLViewerWindow::handleMiddleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask)
+{
+    BOOL down = TRUE;
+    gViewerInput.handleMouse(window, pos, mask, CLICK_MIDDLE, down);
+
+    // Always handled as far as the OS is concerned.
+    return TRUE;
 }
 
 // [SL:KB] - Patch: Build-DragNDrop | Checked: 2013-07-22 (Catznip-3.6)
-LLWindowCallbacks::DragNDropResult LLViewerWindow::handleDragNDrop(LLWindow *window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action, 
+LLWindowCallbacks::DragNDropResult LLViewerWindow::handleDragNDrop(LLWindow *window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action,
                                                                    LLWindowCallbacks::DragNDropType type, const std::vector<std::string>& data)
 {
-	LLWindowCallbacks::DragNDropResult result = LLWindowCallbacks::DND_NONE;
-	switch (type)
-	{
-		case LLWindowCallbacks::DNDT_FILE:
-			result = handleDragNDropFile(window, pos, mask, action, type, data);
-			break;
-		case LLWindowCallbacks::DNDT_DEFAULT:
-		default:
-			result = handleDragNDropDefault(window, pos, mask, action, (!data.empty()) ? data.front() : LLStringUtil::null);
-			break;
-	}
-	return result;
+    LLWindowCallbacks::DragNDropResult result = LLWindowCallbacks::DND_NONE;
+    switch (type)
+    {
+        case LLWindowCallbacks::DNDT_FILE:
+            result = handleDragNDropFile(window, pos, mask, action, type, data);
+            break;
+        case LLWindowCallbacks::DNDT_DEFAULT:
+        default:
+            result = handleDragNDropDefault(window, pos, mask, action, (!data.empty()) ? data.front() : LLStringUtil::null);
+            break;
+    }
+    return result;
 }
 // [/SL:KB]
 
@@ -1322,349 +1322,349 @@ LLWindowCallbacks::DragNDropResult LLViewerWindow::handleDragNDrop(LLWindow *win
 LLWindowCallbacks::DragNDropResult LLViewerWindow::handleDragNDropDefault(LLWindow* window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action, std::string data)
 // [/SL:KB]
 {
-	LLWindowCallbacks::DragNDropResult result = LLWindowCallbacks::DND_NONE;
-
-	const bool prim_media_dnd_enabled = gSavedSettings.getBOOL("PrimMediaDragNDrop");
-	const bool slurl_dnd_enabled = gSavedSettings.getBOOL("SLURLDragNDrop");
-	
-	if ( prim_media_dnd_enabled || slurl_dnd_enabled )
-	{
-		switch(action)
-		{
-			// Much of the handling for these two cases is the same.
-			case LLWindowCallbacks::DNDA_TRACK:
-			case LLWindowCallbacks::DNDA_DROPPED:
-			case LLWindowCallbacks::DNDA_START_TRACKING:
-			{
-				bool drop = (LLWindowCallbacks::DNDA_DROPPED == action);
-					
-				if (slurl_dnd_enabled)
-				{
-					LLSLURL dropped_slurl(data);
-					if(dropped_slurl.isSpatial())
-					{
-						if (drop)
-						{
-							LLURLDispatcher::dispatch( dropped_slurl.getSLURLString(), LLCommandHandler::NAV_TYPE_CLICKED, NULL, true );
-							return LLWindowCallbacks::DND_MOVE;
-						}
-						return LLWindowCallbacks::DND_COPY;
-					}
-				}
-
-				if (prim_media_dnd_enabled)
-				{
-					LLPickInfo pick_info = pickImmediate( pos.mX, pos.mY,
-                                                          TRUE /* pick_transparent */, 
+    LLWindowCallbacks::DragNDropResult result = LLWindowCallbacks::DND_NONE;
+
+    const bool prim_media_dnd_enabled = gSavedSettings.getBOOL("PrimMediaDragNDrop");
+    const bool slurl_dnd_enabled = gSavedSettings.getBOOL("SLURLDragNDrop");
+
+    if ( prim_media_dnd_enabled || slurl_dnd_enabled )
+    {
+        switch(action)
+        {
+            // Much of the handling for these two cases is the same.
+            case LLWindowCallbacks::DNDA_TRACK:
+            case LLWindowCallbacks::DNDA_DROPPED:
+            case LLWindowCallbacks::DNDA_START_TRACKING:
+            {
+                bool drop = (LLWindowCallbacks::DNDA_DROPPED == action);
+
+                if (slurl_dnd_enabled)
+                {
+                    LLSLURL dropped_slurl(data);
+                    if(dropped_slurl.isSpatial())
+                    {
+                        if (drop)
+                        {
+                            LLURLDispatcher::dispatch( dropped_slurl.getSLURLString(), LLCommandHandler::NAV_TYPE_CLICKED, NULL, true );
+                            return LLWindowCallbacks::DND_MOVE;
+                        }
+                        return LLWindowCallbacks::DND_COPY;
+                    }
+                }
+
+                if (prim_media_dnd_enabled)
+                {
+                    LLPickInfo pick_info = pickImmediate( pos.mX, pos.mY,
+                                                          TRUE /* pick_transparent */,
                                                           FALSE /* pick_rigged */);
 
-					S32 object_face = pick_info.mObjectFace;
-					std::string url = data;
-
-					LL_DEBUGS() << "Object: picked at " << pos.mX << ", " << pos.mY << " - face = " << object_face << " - URL = " << url << LL_ENDL;
-
-					LLViewerObject* vobjp = static_cast<LLViewerObject*>(pick_info.getObject());
-					LLVOVolume *obj = vobjp ? vobjp->asVolume() : nullptr;
-				
-					if (obj && !obj->getRegion()->getCapability("ObjectMedia").empty())
-					{
-						LLTextureEntry *te = obj->getTE(object_face);
-
-						// can modify URL if we can modify the object or we have navigate permissions
-						bool allow_modify_url = obj->permModify() || (te && obj->hasMediaPermission( te->getMediaData(), LLVOVolume::MEDIA_PERM_INTERACT ));
-
-						if (te && allow_modify_url )
-						{
-							if (drop)
-							{
-								// object does NOT have media already
-								if ( ! te->hasMedia() )
-								{
-									// we are allowed to modify the object
-									if ( obj->permModify() )
-									{
-										// Create new media entry
-										LLSD media_data;
-										// XXX Should we really do Home URL too?
-										media_data[LLMediaEntry::HOME_URL_KEY] = url;
-										media_data[LLMediaEntry::CURRENT_URL_KEY] = url;
-										media_data[LLMediaEntry::AUTO_PLAY_KEY] = true;
-										obj->syncMediaData(object_face, media_data, true, true);
-										// XXX This shouldn't be necessary, should it ?!?
-										if (obj->getMediaImpl(object_face))
-											obj->getMediaImpl(object_face)->navigateReload();
-										obj->sendMediaDataUpdate();
-
-										result = LLWindowCallbacks::DND_COPY;
-									}
-								}
-								else 
-								// object HAS media already
-								{
-									// URL passes the whitelist
-									if (te->getMediaData()->checkCandidateUrl( url ) )
-									{
-										// just navigate to the URL
-										if (obj->getMediaImpl(object_face))
-										{
-											obj->getMediaImpl(object_face)->navigateTo(url);
-										}
-										else 
-										{
-											// This is very strange.  Navigation should
-											// happen via the Impl, but we don't have one.
-											// This sends it to the server, which /should/
-											// trigger us getting it.  Hopefully.
-											LLSD media_data;
-											media_data[LLMediaEntry::CURRENT_URL_KEY] = url;
-											obj->syncMediaData(object_face, media_data, true, true);
-											obj->sendMediaDataUpdate();
-										}
-										result = LLWindowCallbacks::DND_LINK;
-										
-									}
-								}
-								LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
-								mDragHoveredObject = NULL;
-							
-							}
-							else 
-							{
-								// Check the whitelist, if there's media (otherwise just show it)
-								if (te->getMediaData() == NULL || te->getMediaData()->checkCandidateUrl(url))
-								{
-									if ( obj != mDragHoveredObject.get())
-									{
-										// Highlight the dragged object
-										LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
-										mDragHoveredObject = obj;
-										LLSelectMgr::getInstance()->highlightObjectOnly(mDragHoveredObject);
-									}
-									result = (! te->hasMedia()) ? LLWindowCallbacks::DND_COPY : LLWindowCallbacks::DND_LINK;
-
-								}
-							}
-						}
-					}
-				}
-			}
-			break;
-			
-			case LLWindowCallbacks::DNDA_STOP_TRACKING:
-				// The cleanup case below will make sure things are unhilighted if necessary.
-			break;
-		}
-
-		if (prim_media_dnd_enabled &&
-			result == LLWindowCallbacks::DND_NONE && !mDragHoveredObject.isNull())
-		{
-			LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
-			mDragHoveredObject = NULL;
-		}
-	}
-	
-	return result;
+                    S32 object_face = pick_info.mObjectFace;
+                    std::string url = data;
+
+                    LL_DEBUGS() << "Object: picked at " << pos.mX << ", " << pos.mY << " - face = " << object_face << " - URL = " << url << LL_ENDL;
+
+                    LLViewerObject* vobjp = static_cast<LLViewerObject*>(pick_info.getObject());
+                    LLVOVolume *obj = vobjp ? vobjp->asVolume() : nullptr;
+
+                    if (obj && !obj->getRegion()->getCapability("ObjectMedia").empty())
+                    {
+                        LLTextureEntry *te = obj->getTE(object_face);
+
+                        // can modify URL if we can modify the object or we have navigate permissions
+                        bool allow_modify_url = obj->permModify() || (te && obj->hasMediaPermission( te->getMediaData(), LLVOVolume::MEDIA_PERM_INTERACT ));
+
+                        if (te && allow_modify_url )
+                        {
+                            if (drop)
+                            {
+                                // object does NOT have media already
+                                if ( ! te->hasMedia() )
+                                {
+                                    // we are allowed to modify the object
+                                    if ( obj->permModify() )
+                                    {
+                                        // Create new media entry
+                                        LLSD media_data;
+                                        // XXX Should we really do Home URL too?
+                                        media_data[LLMediaEntry::HOME_URL_KEY] = url;
+                                        media_data[LLMediaEntry::CURRENT_URL_KEY] = url;
+                                        media_data[LLMediaEntry::AUTO_PLAY_KEY] = true;
+                                        obj->syncMediaData(object_face, media_data, true, true);
+                                        // XXX This shouldn't be necessary, should it ?!?
+                                        if (obj->getMediaImpl(object_face))
+                                            obj->getMediaImpl(object_face)->navigateReload();
+                                        obj->sendMediaDataUpdate();
+
+                                        result = LLWindowCallbacks::DND_COPY;
+                                    }
+                                }
+                                else
+                                // object HAS media already
+                                {
+                                    // URL passes the whitelist
+                                    if (te->getMediaData()->checkCandidateUrl( url ) )
+                                    {
+                                        // just navigate to the URL
+                                        if (obj->getMediaImpl(object_face))
+                                        {
+                                            obj->getMediaImpl(object_face)->navigateTo(url);
+                                        }
+                                        else
+                                        {
+                                            // This is very strange.  Navigation should
+                                            // happen via the Impl, but we don't have one.
+                                            // This sends it to the server, which /should/
+                                            // trigger us getting it.  Hopefully.
+                                            LLSD media_data;
+                                            media_data[LLMediaEntry::CURRENT_URL_KEY] = url;
+                                            obj->syncMediaData(object_face, media_data, true, true);
+                                            obj->sendMediaDataUpdate();
+                                        }
+                                        result = LLWindowCallbacks::DND_LINK;
+
+                                    }
+                                }
+                                LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
+                                mDragHoveredObject = NULL;
+
+                            }
+                            else
+                            {
+                                // Check the whitelist, if there's media (otherwise just show it)
+                                if (te->getMediaData() == NULL || te->getMediaData()->checkCandidateUrl(url))
+                                {
+                                    if ( obj != mDragHoveredObject.get())
+                                    {
+                                        // Highlight the dragged object
+                                        LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
+                                        mDragHoveredObject = obj;
+                                        LLSelectMgr::getInstance()->highlightObjectOnly(mDragHoveredObject);
+                                    }
+                                    result = (! te->hasMedia()) ? LLWindowCallbacks::DND_COPY : LLWindowCallbacks::DND_LINK;
+
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            break;
+
+            case LLWindowCallbacks::DNDA_STOP_TRACKING:
+                // The cleanup case below will make sure things are unhilighted if necessary.
+            break;
+        }
+
+        if (prim_media_dnd_enabled &&
+            result == LLWindowCallbacks::DND_NONE && !mDragHoveredObject.isNull())
+        {
+            LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
+            mDragHoveredObject = NULL;
+        }
+    }
+
+    return result;
 }
 
 // [SL:KB] - Patch: Build-DragNDrop | Checked: 2013-07-22 (Catznip-3.6)
 // This really should be standardized somewhere instead of having extensions duplicated all over the code
 typedef std::tuple<const char*, LLAssetType::EType, LLFilePicker::ELoadFilter> dragdrop_type_lookup_t;
 static dragdrop_type_lookup_t s_DragDropTypesLookup[] = {
-	std::make_tuple("bmp", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
-	std::make_tuple("jpg", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
-	std::make_tuple("jpeg", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
-	std::make_tuple("png", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
-	std::make_tuple("tga", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
-	std::make_tuple("webp", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
-	std::make_tuple("bvh", LLAssetType::AT_ANIMATION, LLFilePicker::FFLOAD_ANIM),
-	std::make_tuple("anim", LLAssetType::AT_ANIMATION, LLFilePicker::FFLOAD_ANIM),
-	std::make_tuple("wav", LLAssetType::AT_SOUND_WAV, LLFilePicker::FFLOAD_WAV),
-	std::make_tuple("dae", LLAssetType::AT_MESH, LLFilePicker::FFLOAD_MODEL),
-	std::make_tuple("gltf", LLAssetType::AT_MATERIAL, LLFilePicker::FFLOAD_GLTF),
-	std::make_tuple("glb", LLAssetType::AT_MATERIAL, LLFilePicker::FFLOAD_GLTF),
+    std::make_tuple("bmp", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
+    std::make_tuple("jpg", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
+    std::make_tuple("jpeg", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
+    std::make_tuple("png", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
+    std::make_tuple("tga", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
+    std::make_tuple("webp", LLAssetType::AT_TEXTURE, LLFilePicker::FFLOAD_IMAGE),
+    std::make_tuple("bvh", LLAssetType::AT_ANIMATION, LLFilePicker::FFLOAD_ANIM),
+    std::make_tuple("anim", LLAssetType::AT_ANIMATION, LLFilePicker::FFLOAD_ANIM),
+    std::make_tuple("wav", LLAssetType::AT_SOUND_WAV, LLFilePicker::FFLOAD_WAV),
+    std::make_tuple("dae", LLAssetType::AT_MESH, LLFilePicker::FFLOAD_MODEL),
+    std::make_tuple("gltf", LLAssetType::AT_MATERIAL, LLFilePicker::FFLOAD_GLTF),
+    std::make_tuple("glb", LLAssetType::AT_MATERIAL, LLFilePicker::FFLOAD_GLTF),
 };
 
 static LLAssetType::EType getAssetTypeFromFilename(const std::string strFilename)
 {
-	const std::string& strExt = gDirUtilp->getExtension(strFilename);
-	for (int idxLookup = 0, cntLookup = sizeof(s_DragDropTypesLookup) / sizeof(dragdrop_type_lookup_t); idxLookup < cntLookup; idxLookup++)
-	{
-		if (strExt == std::get<0>(s_DragDropTypesLookup[idxLookup]))
-			return std::get<1>(s_DragDropTypesLookup[idxLookup]);
-	}
-	return LLAssetType::AT_NONE;
+    const std::string& strExt = gDirUtilp->getExtension(strFilename);
+    for (int idxLookup = 0, cntLookup = sizeof(s_DragDropTypesLookup) / sizeof(dragdrop_type_lookup_t); idxLookup < cntLookup; idxLookup++)
+    {
+        if (strExt == std::get<0>(s_DragDropTypesLookup[idxLookup]))
+            return std::get<1>(s_DragDropTypesLookup[idxLookup]);
+    }
+    return LLAssetType::AT_NONE;
 }
 
 static LLFilePicker::ELoadFilter getLoadFilterFromFilename(const std::string strFilename)
 {
-	const std::string& strExt = gDirUtilp->getExtension(strFilename);
-	for (int idxLookup = 0, cntLookup = sizeof(s_DragDropTypesLookup) / sizeof(dragdrop_type_lookup_t); idxLookup < cntLookup; idxLookup++)
-	{
-		if (strExt == std::get<0>(s_DragDropTypesLookup[idxLookup]))
-			return std::get<2>(s_DragDropTypesLookup[idxLookup]);
-	}
-	return LLFilePicker::FFLOAD_ALL;
+    const std::string& strExt = gDirUtilp->getExtension(strFilename);
+    for (int idxLookup = 0, cntLookup = sizeof(s_DragDropTypesLookup) / sizeof(dragdrop_type_lookup_t); idxLookup < cntLookup; idxLookup++)
+    {
+        if (strExt == std::get<0>(s_DragDropTypesLookup[idxLookup]))
+            return std::get<2>(s_DragDropTypesLookup[idxLookup]);
+    }
+    return LLFilePicker::FFLOAD_ALL;
 }
 
 LLWindowCallbacks::DragNDropResult LLViewerWindow::handleDragNDropFile(LLWindow *window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action,
                                                                        LLWindowCallbacks::DragNDropType type, const std::vector<std::string>& data)
 {
-	LL_INFOS() << "BARK" << LL_ENDL;
-	bool fDrop = (LLWindowCallbacks::DNDA_DROPPED == action);
-
-	LLWindowCallbacks::DragNDropResult result = LLWindowCallbacks::DND_NONE;
-	switch (action)
-	{
-		case LLWindowCallbacks::DNDA_START_TRACKING:
-			{
-				mDragItems.clear();
-				if (gLoggedInTime.getStarted())
-				{
-					for (std::vector<std::string>::const_iterator itFile = data.begin(); itFile != data.end(); ++itFile)
-					{
-						const std::string& strFile = *itFile;
-
-						LLAssetType::EType eAssetType = getAssetTypeFromFilename(strFile);
-						if (LLAssetType::AT_NONE != eAssetType)
-						{
-							LLPointer<LLViewerInventoryItem> pItem = new LLViewerInventoryItem(LLUUID::generateNewID(), LLUUID::null, gDirUtilp->getBaseFileName(strFile), LLInventoryType::defaultForAssetType(eAssetType));
-							pItem->setType(eAssetType);
-							mDragItems.push_back(drag_item_t(pItem, strFile));
-						}
-					}
-				}
-
-				if (!mDragItems.empty())
-				{
-					result = LLWindowCallbacks::DND_LINK;
-				}
-			}
-			// Fall through to tracking and dropping for now
-		case LLWindowCallbacks::DNDA_TRACK:
-		case LLWindowCallbacks::DNDA_DROPPED:
-			{
-				if (!LLToolMgr::getInstance()->inBuildMode())
-				{
-					if (!mDragItems.empty())
-					{
-						if (fDrop)
-						{
-							bool fCanBulkUpload = (mDragItems.size() > 1) && (std::all_of(mDragItems.begin(), mDragItems.end(), [](const drag_item_t& dragItem)
-																																{
-																																	auto asset_type = getAssetTypeFromFilename(dragItem.second);
-																																	return (asset_type == LLAssetType::AT_TEXTURE) 
-																																		|| (asset_type == LLAssetType::AT_ANIMATION) 
-																																		|| (asset_type == LLAssetType::AT_SOUND_WAV) 
-																																		|| (asset_type == LLAssetType::AT_MATERIAL);
-																																}));
-							if (!fCanBulkUpload)
-							{
- 								if (gAgentCamera.cameraMouselook())
-								{
-									gAgentCamera.changeCameraToDefault();
-								}
-
-								for (const drag_item_t& dragItem : mDragItems)
-								{
-									std::vector<std::string> tmpvec;
-									tmpvec.push_back(dragItem.second);
-									upload_single_file(tmpvec, getLoadFilterFromFilename(dragItem.second));
-								}
-							}
-							else
-							{
-								std::vector<std::string> files;
-								for (const drag_item_t& dragItem : mDragItems)
-									files.push_back(dragItem.second);
-
-								upload_bulk(files, LLFilePicker::FFLOAD_ALL);
-							}
-						}
-						result = DND_COPY;
-					}
-				}
-				else
-				{
-					if ( (1 == mDragItems.size()) && (LLAssetType::AT_TEXTURE == mDragItems.front().first->getType() || LLAssetType::AT_MATERIAL == mDragItems.front().first->getType()) )
-					{
-						LLPickInfo pick = pickImmediate(pos.mX, pos.mY, TRUE);
-
-						LLViewerObject* pObj = pick.getObject();
-						if ( (pObj) && (pObj->permModify()) )
-						{
-							result = LLWindowCallbacks::DND_LINK;
-							if (!fDrop)
-							{
-								if (pObj != mDragHoveredObject.get())
-								{
-									LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
-									mDragHoveredObject = pObj;
-									LLSelectMgr::getInstance()->highlightObjectOnly(mDragHoveredObject);
-								}
-							}
-							else
-							{
-								LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
-								mDragHoveredObject = NULL;
-
-								const std::string& strFilename = mDragItems.front().second;
-
-								if (LLAssetType::AT_TEXTURE == mDragItems.front().first->getType())
-								{
-									LLUUID idLocalBitmap = LLLocalBitmapMgr::instance().getUnitID(strFilename);
-									if (idLocalBitmap.isNull())
-									{
-										idLocalBitmap = LLLocalBitmapMgr::instance().addUnit(strFilename);
-									}
-
-									if (idLocalBitmap.notNull())
-									{
-										pObj->setTETexture(pick.mObjectFace, LLLocalBitmapMgr::instance().getWorldID(idLocalBitmap));
-										pObj->sendTEUpdate();
-									}
-								}
-								else if (LLAssetType::AT_MATERIAL == mDragItems.front().first->getType())
-								{
-									LLUUID isLocalMat = LLLocalGLTFMaterialMgr::instance().getUnitID(strFilename, 0);
-									if (isLocalMat.isNull())
-									{
-										LLLocalGLTFMaterialMgr::instance().addUnit(strFilename, isLocalMat);
-									}
-
-									if (isLocalMat.notNull())
-									{
-										pObj->setRenderMaterialID(pick.mObjectFace, LLLocalGLTFMaterialMgr::instance().getWorldID(isLocalMat));
-									}
-								}
-							}
-						}
-					}
-				}
-			}
-			break;
-		case LLWindowCallbacks::DNDA_STOP_TRACKING:
-			{
-				mDragItems.clear();
-			}
-			break;
-	}
-
-	if ( (LLWindowCallbacks::DND_NONE == result) && (mDragHoveredObject.notNull()) )
-	{
-		LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
-		mDragHoveredObject = NULL;
-	}
-	return result;
+    LL_INFOS() << "BARK" << LL_ENDL;
+    bool fDrop = (LLWindowCallbacks::DNDA_DROPPED == action);
+
+    LLWindowCallbacks::DragNDropResult result = LLWindowCallbacks::DND_NONE;
+    switch (action)
+    {
+        case LLWindowCallbacks::DNDA_START_TRACKING:
+            {
+                mDragItems.clear();
+                if (gLoggedInTime.getStarted())
+                {
+                    for (std::vector<std::string>::const_iterator itFile = data.begin(); itFile != data.end(); ++itFile)
+                    {
+                        const std::string& strFile = *itFile;
+
+                        LLAssetType::EType eAssetType = getAssetTypeFromFilename(strFile);
+                        if (LLAssetType::AT_NONE != eAssetType)
+                        {
+                            LLPointer<LLViewerInventoryItem> pItem = new LLViewerInventoryItem(LLUUID::generateNewID(), LLUUID::null, gDirUtilp->getBaseFileName(strFile), LLInventoryType::defaultForAssetType(eAssetType));
+                            pItem->setType(eAssetType);
+                            mDragItems.push_back(drag_item_t(pItem, strFile));
+                        }
+                    }
+                }
+
+                if (!mDragItems.empty())
+                {
+                    result = LLWindowCallbacks::DND_LINK;
+                }
+            }
+            // Fall through to tracking and dropping for now
+        case LLWindowCallbacks::DNDA_TRACK:
+        case LLWindowCallbacks::DNDA_DROPPED:
+            {
+                if (!LLToolMgr::getInstance()->inBuildMode())
+                {
+                    if (!mDragItems.empty())
+                    {
+                        if (fDrop)
+                        {
+                            bool fCanBulkUpload = (mDragItems.size() > 1) && (std::all_of(mDragItems.begin(), mDragItems.end(), [](const drag_item_t& dragItem)
+                                                                                                                                {
+                                                                                                                                    auto asset_type = getAssetTypeFromFilename(dragItem.second);
+                                                                                                                                    return (asset_type == LLAssetType::AT_TEXTURE)
+                                                                                                                                        || (asset_type == LLAssetType::AT_ANIMATION)
+                                                                                                                                        || (asset_type == LLAssetType::AT_SOUND_WAV)
+                                                                                                                                        || (asset_type == LLAssetType::AT_MATERIAL);
+                                                                                                                                }));
+                            if (!fCanBulkUpload)
+                            {
+                                if (gAgentCamera.cameraMouselook())
+                                {
+                                    gAgentCamera.changeCameraToDefault();
+                                }
+
+                                for (const drag_item_t& dragItem : mDragItems)
+                                {
+                                    std::vector<std::string> tmpvec;
+                                    tmpvec.push_back(dragItem.second);
+                                    upload_single_file(tmpvec, getLoadFilterFromFilename(dragItem.second));
+                                }
+                            }
+                            else
+                            {
+                                std::vector<std::string> files;
+                                for (const drag_item_t& dragItem : mDragItems)
+                                    files.push_back(dragItem.second);
+
+                                upload_bulk(files, LLFilePicker::FFLOAD_ALL);
+                            }
+                        }
+                        result = DND_COPY;
+                    }
+                }
+                else
+                {
+                    if ( (1 == mDragItems.size()) && (LLAssetType::AT_TEXTURE == mDragItems.front().first->getType() || LLAssetType::AT_MATERIAL == mDragItems.front().first->getType()) )
+                    {
+                        LLPickInfo pick = pickImmediate(pos.mX, pos.mY, TRUE);
+
+                        LLViewerObject* pObj = pick.getObject();
+                        if ( (pObj) && (pObj->permModify()) )
+                        {
+                            result = LLWindowCallbacks::DND_LINK;
+                            if (!fDrop)
+                            {
+                                if (pObj != mDragHoveredObject.get())
+                                {
+                                    LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
+                                    mDragHoveredObject = pObj;
+                                    LLSelectMgr::getInstance()->highlightObjectOnly(mDragHoveredObject);
+                                }
+                            }
+                            else
+                            {
+                                LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
+                                mDragHoveredObject = NULL;
+
+                                const std::string& strFilename = mDragItems.front().second;
+
+                                if (LLAssetType::AT_TEXTURE == mDragItems.front().first->getType())
+                                {
+                                    LLUUID idLocalBitmap = LLLocalBitmapMgr::instance().getUnitID(strFilename);
+                                    if (idLocalBitmap.isNull())
+                                    {
+                                        idLocalBitmap = LLLocalBitmapMgr::instance().addUnit(strFilename);
+                                    }
+
+                                    if (idLocalBitmap.notNull())
+                                    {
+                                        pObj->setTETexture(pick.mObjectFace, LLLocalBitmapMgr::instance().getWorldID(idLocalBitmap));
+                                        pObj->sendTEUpdate();
+                                    }
+                                }
+                                else if (LLAssetType::AT_MATERIAL == mDragItems.front().first->getType())
+                                {
+                                    LLUUID isLocalMat = LLLocalGLTFMaterialMgr::instance().getUnitID(strFilename, 0);
+                                    if (isLocalMat.isNull())
+                                    {
+                                        LLLocalGLTFMaterialMgr::instance().addUnit(strFilename, isLocalMat);
+                                    }
+
+                                    if (isLocalMat.notNull())
+                                    {
+                                        pObj->setRenderMaterialID(pick.mObjectFace, LLLocalGLTFMaterialMgr::instance().getWorldID(isLocalMat));
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            break;
+        case LLWindowCallbacks::DNDA_STOP_TRACKING:
+            {
+                mDragItems.clear();
+            }
+            break;
+    }
+
+    if ( (LLWindowCallbacks::DND_NONE == result) && (mDragHoveredObject.notNull()) )
+    {
+        LLSelectMgr::getInstance()->unhighlightObjectOnly(mDragHoveredObject);
+        mDragHoveredObject = NULL;
+    }
+    return result;
 }
 // [/SL:KB]
 
 BOOL LLViewerWindow::handleMiddleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask)
 {
-	BOOL down = FALSE;
- 	gViewerInput.handleMouse(window, pos, mask, CLICK_MIDDLE, down);
-  
-  	// Always handled as far as the OS is concerned.
-	return TRUE;
+    BOOL down = FALSE;
+    gViewerInput.handleMouse(window, pos, mask, CLICK_MIDDLE, down);
+
+    // Always handled as far as the OS is concerned.
+    return TRUE;
 }
 
 BOOL LLViewerWindow::handleOtherMouse(LLWindow *window, LLCoordGL pos, MASK mask, S32 button, bool down)
@@ -1698,144 +1698,144 @@ BOOL LLViewerWindow::handleOtherMouseUp(LLWindow *window, LLCoordGL pos, MASK ma
 // WARNING: this is potentially called multiple times per frame
 void LLViewerWindow::handleMouseMove(LLWindow *window,  LLCoordGL pos, MASK mask)
 {
-	S32 x = pos.mX;
-	S32 y = pos.mY;
+    S32 x = pos.mX;
+    S32 y = pos.mY;
 
-	x = ll_round((F32)x / mDisplayScale.mV[VX]);
-	y = ll_round((F32)y / mDisplayScale.mV[VY]);
+    x = ll_round((F32)x / mDisplayScale.mV[VX]);
+    y = ll_round((F32)y / mDisplayScale.mV[VY]);
 
-	mMouseInWindow = TRUE;
+    mMouseInWindow = TRUE;
 
-	// Save mouse point for access during idle() and display()
+    // Save mouse point for access during idle() and display()
 
-	LLCoordGL mouse_point(x, y);
+    LLCoordGL mouse_point(x, y);
 
-	if (mouse_point != mCurrentMousePoint)
-	{
-		LLUI::resetMouseIdleTimer();
-	}
+    if (mouse_point != mCurrentMousePoint)
+    {
+        LLUI::resetMouseIdleTimer();
+    }
 
-	saveLastMouse(mouse_point);
+    saveLastMouse(mouse_point);
 
-	mWindow->showCursorFromMouseMove();
+    mWindow->showCursorFromMouseMove();
 
-	if (gAwayTimer.getElapsedTimeF32() > LLAgent::MIN_AFK_TIME
-		&& !gDisconnected)
-	{
-		gAgent.clearAFK();
-	}
+    if (gAwayTimer.getElapsedTimeF32() > LLAgent::MIN_AFK_TIME
+        && !gDisconnected)
+    {
+        gAgent.clearAFK();
+    }
 }
 
 void LLViewerWindow::handleMouseLeave(LLWindow *window)
 {
-	// Note: we won't get this if we have captured the mouse.
-	llassert( gFocusMgr.getMouseCapture() == NULL );
-	mMouseInWindow = FALSE;
-	LLToolTipMgr::instance().blockToolTips();
+    // Note: we won't get this if we have captured the mouse.
+    llassert( gFocusMgr.getMouseCapture() == NULL );
+    mMouseInWindow = FALSE;
+    LLToolTipMgr::instance().blockToolTips();
 }
 
 BOOL LLViewerWindow::handleCloseRequest(LLWindow *window)
 {
-	// User has indicated they want to close, but we may need to ask
-	// about modified documents.
-	LLAppViewer::instance()->userQuit();
-	// Don't quit immediately
-	return FALSE;
+    // User has indicated they want to close, but we may need to ask
+    // about modified documents.
+    LLAppViewer::instance()->userQuit();
+    // Don't quit immediately
+    return FALSE;
 }
 
 void LLViewerWindow::handleQuit(LLWindow *window)
 {
-	if (gNonInteractive)
-	{
-		LLAppViewer::instance()->requestQuit();
-	}
-	else
-	{
-		LL_INFOS() << "Window forced quit" << LL_ENDL;
-		LLAppViewer::instance()->forceQuit();
-	}
+    if (gNonInteractive)
+    {
+        LLAppViewer::instance()->requestQuit();
+    }
+    else
+    {
+        LL_INFOS() << "Window forced quit" << LL_ENDL;
+        LLAppViewer::instance()->forceQuit();
+    }
 }
 
 void LLViewerWindow::handleResize(LLWindow *window,  S32 width,  S32 height)
 {
-	reshape(width, height);
-	mResDirty = true;
+    reshape(width, height);
+    mResDirty = true;
 }
 
 // The top-level window has gained focus (e.g. via ALT-TAB)
 void LLViewerWindow::handleFocus(LLWindow *window)
 {
-	gFocusMgr.setAppHasFocus(TRUE);
-	LLModalDialog::onAppFocusGained();
+    gFocusMgr.setAppHasFocus(TRUE);
+    LLModalDialog::onAppFocusGained();
 
-	gAgent.onAppFocusGained();
-	LLToolMgr::getInstance()->onAppFocusGained();
+    gAgent.onAppFocusGained();
+    LLToolMgr::getInstance()->onAppFocusGained();
 
-	// See if we're coming in with modifier keys held down
-	if (gKeyboard)
-	{
-		gKeyboard->resetMaskKeys();
-	}
+    // See if we're coming in with modifier keys held down
+    if (gKeyboard)
+    {
+        gKeyboard->resetMaskKeys();
+    }
 
-	// resume foreground running timer
-	// since we artifically limit framerate when not frontmost
-	gForegroundTime.unpause();
+    // resume foreground running timer
+    // since we artifically limit framerate when not frontmost
+    gForegroundTime.unpause();
 }
 
 // The top-level window has lost focus (e.g. via ALT-TAB)
 void LLViewerWindow::handleFocusLost(LLWindow *window)
 {
-	gFocusMgr.setAppHasFocus(FALSE);
-	//LLModalDialog::onAppFocusLost();
-	LLToolMgr::getInstance()->onAppFocusLost();
-	gFocusMgr.setMouseCapture( NULL );
+    gFocusMgr.setAppHasFocus(FALSE);
+    //LLModalDialog::onAppFocusLost();
+    LLToolMgr::getInstance()->onAppFocusLost();
+    gFocusMgr.setMouseCapture( NULL );
 
-	if (gMenuBarView)
-	{
-		// stop ALT-key access to menu
-		gMenuBarView->resetMenuTrigger();
-	}
+    if (gMenuBarView)
+    {
+        // stop ALT-key access to menu
+        gMenuBarView->resetMenuTrigger();
+    }
 
-	// restore mouse cursor
-	showCursor();
-	getWindow()->setMouseClipping(FALSE);
+    // restore mouse cursor
+    showCursor();
+    getWindow()->setMouseClipping(FALSE);
 
-	// If losing focus while keys are down, handle them as
+    // If losing focus while keys are down, handle them as
     // an 'up' to correctly release states, then reset states
-	if (gKeyboard)
-	{
+    if (gKeyboard)
+    {
         gKeyboard->resetKeyDownAndHandle();
-		gKeyboard->resetKeys();
-	}
+        gKeyboard->resetKeys();
+    }
 
-	// pause timer that tracks total foreground running time
-	gForegroundTime.pause();
+    // pause timer that tracks total foreground running time
+    gForegroundTime.pause();
 }
 
 
 BOOL LLViewerWindow::handleTranslatedKeyDown(KEY key,  MASK mask, BOOL repeated)
 {
-    // Handle non-consuming global keybindings, like voice 
+    // Handle non-consuming global keybindings, like voice
     // Never affects event processing.
     gViewerInput.handleGlobalBindsKeyDown(key, mask);
 
-	if (gAwayTimer.getElapsedTimeF32() > LLAgent::MIN_AFK_TIME)
-	{
-		gAgent.clearAFK();
-	}
-
-	// *NOTE: We want to interpret KEY_RETURN later when it arrives as
-	// a Unicode char, not as a keydown.  Otherwise when client frame
-	// rate is really low, hitting return sends your chat text before
-	// it's all entered/processed.
-	if (key == KEY_RETURN && mask == MASK_NONE)
-	{
+    if (gAwayTimer.getElapsedTimeF32() > LLAgent::MIN_AFK_TIME)
+    {
+        gAgent.clearAFK();
+    }
+
+    // *NOTE: We want to interpret KEY_RETURN later when it arrives as
+    // a Unicode char, not as a keydown.  Otherwise when client frame
+    // rate is really low, hitting return sends your chat text before
+    // it's all entered/processed.
+    if (key == KEY_RETURN && mask == MASK_NONE)
+    {
         // RIDER: although, at times some of the controlls (in particular the CEF viewer
         // would like to know about the KEYDOWN for an enter key... so ask and pass it along.
         LLFocusableElement* keyboard_focus = gFocusMgr.getKeyboardFocus();
         if (keyboard_focus && !keyboard_focus->wantsReturnKey())
-    		return FALSE;
-	}
+            return FALSE;
+    }
 
     // remaps, handles ignored cases and returns back to viewer window.
     return gViewerInput.handleKey(key, mask, repeated);
@@ -1843,25 +1843,25 @@ BOOL LLViewerWindow::handleTranslatedKeyDown(KEY key,  MASK mask, BOOL repeated)
 
 BOOL LLViewerWindow::handleTranslatedKeyUp(KEY key,  MASK mask)
 {
-    // Handle non-consuming global keybindings, like voice 
+    // Handle non-consuming global keybindings, like voice
     // Never affects event processing.
     gViewerInput.handleGlobalBindsKeyUp(key, mask);
 
-	// Let the inspect tool code check for ALT key to set LLToolSelectRect active instead LLToolCamera
-	LLToolCompInspect * tool_inspectp = LLToolCompInspect::getInstance();
-	if (LLToolMgr::getInstance()->getCurrentTool() == tool_inspectp)
-	{
-		tool_inspectp->keyUp(key, mask);
-	}
+    // Let the inspect tool code check for ALT key to set LLToolSelectRect active instead LLToolCamera
+    LLToolCompInspect * tool_inspectp = LLToolCompInspect::getInstance();
+    if (LLToolMgr::getInstance()->getCurrentTool() == tool_inspectp)
+    {
+        tool_inspectp->keyUp(key, mask);
+    }
 
-	return gViewerInput.handleKeyUp(key, mask);
+    return gViewerInput.handleKeyUp(key, mask);
 }
 
 void LLViewerWindow::handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level)
 {
-	LLViewerJoystick::getInstance()->setCameraNeedsUpdate(true);
-	gViewerInput.scanKey(key, key_down, key_up, key_level);
-	return; // Be clear this function returns nothing
+    LLViewerJoystick::getInstance()->setCameraNeedsUpdate(true);
+    gViewerInput.scanKey(key, key_down, key_up, key_level);
+    return; // Be clear this function returns nothing
 }
 
 
@@ -1869,45 +1869,45 @@ void LLViewerWindow::handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key
 
 BOOL LLViewerWindow::handleActivate(LLWindow *window, BOOL activated)
 {
-	if (activated)
-	{
-		mActive = true;
-		send_agent_resume();
-		gAgent.clearAFK();
-		
-		// Unmute audio
-		audio_update_volume();
-	}
-	else
-	{
-		mActive = false;
-				
-		// if the user has chosen to go Away automatically after some time, then go Away when minimizing
-		if (gSavedSettings.getS32("AFKTimeout"))
-		{
-			gAgent.setAFK();
-		}
-		
-		// SL-53351: Make sure we're not in mouselook when minimised, to prevent control issues
-		if (gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK)
-		{
-			gAgentCamera.changeCameraToDefault();
-		}
-		
-		send_agent_pause();
-	
-		// Mute audio
-		audio_update_volume();
-	}
-	return TRUE;
+    if (activated)
+    {
+        mActive = true;
+        send_agent_resume();
+        gAgent.clearAFK();
+
+        // Unmute audio
+        audio_update_volume();
+    }
+    else
+    {
+        mActive = false;
+
+        // if the user has chosen to go Away automatically after some time, then go Away when minimizing
+        if (gSavedSettings.getS32("AFKTimeout"))
+        {
+            gAgent.setAFK();
+        }
+
+        // SL-53351: Make sure we're not in mouselook when minimised, to prevent control issues
+        if (gAgentCamera.getCameraMode() == CAMERA_MODE_MOUSELOOK)
+        {
+            gAgentCamera.changeCameraToDefault();
+        }
+
+        send_agent_pause();
+
+        // Mute audio
+        audio_update_volume();
+    }
+    return TRUE;
 }
 
 BOOL LLViewerWindow::handleActivateApp(LLWindow *window, BOOL activating)
 {
-	//if (!activating) gAgentCamera.changeCameraToDefault();
+    //if (!activating) gAgentCamera.changeCameraToDefault();
 
-	LLViewerJoystick::getInstance()->setNeedsReset(true);
-	return FALSE;
+    LLViewerJoystick::getInstance()->setNeedsReset(true);
+    return FALSE;
 }
 
 
@@ -1918,108 +1918,108 @@ void LLViewerWindow::handleMenuSelect(LLWindow *window,  S32 menu_item)
 
 BOOL LLViewerWindow::handlePaint(LLWindow *window,  S32 x,  S32 y, S32 width,  S32 height)
 {
-	// *TODO: Enable similar information output for other platforms?  DK 2011-02-18
+    // *TODO: Enable similar information output for other platforms?  DK 2011-02-18
 #if LL_WINDOWS
-	if (gHeadlessClient)
-	{
-		HWND window_handle = (HWND)window->getPlatformWindow();
-		PAINTSTRUCT ps; 
-		HDC hdc; 
- 
-		RECT wnd_rect;
-		wnd_rect.left = 0;
-		wnd_rect.top = 0;
-		wnd_rect.bottom = 200;
-		wnd_rect.right = 500;
-
-		hdc = BeginPaint(window_handle, &ps); 
-		//SetBKColor(hdc, RGB(255, 255, 255));
-		FillRect(hdc, &wnd_rect, CreateSolidBrush(RGB(255, 255, 255)));
-
-		std::string temp_str;
-		LLTrace::Recording& recording = LLViewerStats::instance().getRecording();
-		temp_str = llformat( "FPS %3.1f Phy FPS %2.1f Time Dil %1.3f",		/* Flawfinder: ignore */
-				recording.getPerSec(LLStatViewer::FPS), //mFPSStat.getMeanPerSec(),
-				recording.getLastValue(LLStatViewer::SIM_PHYSICS_FPS), 
-				recording.getLastValue(LLStatViewer::SIM_TIME_DILATION));
-		S32 len = temp_str.length();
-		TextOutA(hdc, 0, 0, temp_str.c_str(), len); 
-
-
-		LLVector3d pos_global = gAgent.getPositionGlobal();
-		temp_str = llformat( "Avatar pos %6.1lf %6.1lf %6.1lf", pos_global.mdV[0], pos_global.mdV[1], pos_global.mdV[2]);
-		len = temp_str.length();
-		TextOutA(hdc, 0, 25, temp_str.c_str(), len); 
-
-		TextOutA(hdc, 0, 50, "Set \"HeadlessClient FALSE\" in settings.ini file to reenable", 61);
-		EndPaint(window_handle, &ps); 
-		return TRUE;
-	}
+    if (gHeadlessClient)
+    {
+        HWND window_handle = (HWND)window->getPlatformWindow();
+        PAINTSTRUCT ps;
+        HDC hdc;
+
+        RECT wnd_rect;
+        wnd_rect.left = 0;
+        wnd_rect.top = 0;
+        wnd_rect.bottom = 200;
+        wnd_rect.right = 500;
+
+        hdc = BeginPaint(window_handle, &ps);
+        //SetBKColor(hdc, RGB(255, 255, 255));
+        FillRect(hdc, &wnd_rect, CreateSolidBrush(RGB(255, 255, 255)));
+
+        std::string temp_str;
+        LLTrace::Recording& recording = LLViewerStats::instance().getRecording();
+        temp_str = llformat( "FPS %3.1f Phy FPS %2.1f Time Dil %1.3f",      /* Flawfinder: ignore */
+                recording.getPerSec(LLStatViewer::FPS), //mFPSStat.getMeanPerSec(),
+                recording.getLastValue(LLStatViewer::SIM_PHYSICS_FPS),
+                recording.getLastValue(LLStatViewer::SIM_TIME_DILATION));
+        S32 len = temp_str.length();
+        TextOutA(hdc, 0, 0, temp_str.c_str(), len);
+
+
+        LLVector3d pos_global = gAgent.getPositionGlobal();
+        temp_str = llformat( "Avatar pos %6.1lf %6.1lf %6.1lf", pos_global.mdV[0], pos_global.mdV[1], pos_global.mdV[2]);
+        len = temp_str.length();
+        TextOutA(hdc, 0, 25, temp_str.c_str(), len);
+
+        TextOutA(hdc, 0, 50, "Set \"HeadlessClient FALSE\" in settings.ini file to reenable", 61);
+        EndPaint(window_handle, &ps);
+        return TRUE;
+    }
 #endif
-	return FALSE;
+    return FALSE;
 }
 
 
 void LLViewerWindow::handleScrollWheel(LLWindow *window,  S32 clicks)
 {
-	handleScrollWheel( clicks );
+    handleScrollWheel( clicks );
 }
 
 void LLViewerWindow::handleScrollHWheel(LLWindow *window,  S32 clicks)
 {
-	handleScrollHWheel(clicks);
+    handleScrollHWheel(clicks);
 }
 
 void LLViewerWindow::handleWindowBlock(LLWindow *window)
 {
-	send_agent_pause();
+    send_agent_pause();
 }
 
 void LLViewerWindow::handleWindowUnblock(LLWindow *window)
 {
-	send_agent_resume();
+    send_agent_resume();
 }
 
 void LLViewerWindow::handleDataCopy(LLWindow *window, S32 data_type, void *data)
 {
-	const S32 SLURL_MESSAGE_TYPE = 0;
-	switch (data_type)
-	{
-	case SLURL_MESSAGE_TYPE:
-		// received URL
-		std::string url = (const char*)data;
-		LLMediaCtrl* web = NULL;
-		const bool trusted_browser = false;
-		// don't treat slapps coming from external browsers as "clicks" as this would bypass throttling
-		if (LLURLDispatcher::dispatch(url, LLCommandHandler::NAV_TYPE_EXTERNAL, web, trusted_browser))
-		{
-			// bring window to foreground, as it has just been "launched" from a URL
-			mWindow->bringToFront();
-		}
-		break;
-	}
+    const S32 SLURL_MESSAGE_TYPE = 0;
+    switch (data_type)
+    {
+    case SLURL_MESSAGE_TYPE:
+        // received URL
+        std::string url = (const char*)data;
+        LLMediaCtrl* web = NULL;
+        const bool trusted_browser = false;
+        // don't treat slapps coming from external browsers as "clicks" as this would bypass throttling
+        if (LLURLDispatcher::dispatch(url, LLCommandHandler::NAV_TYPE_EXTERNAL, web, trusted_browser))
+        {
+            // bring window to foreground, as it has just been "launched" from a URL
+            mWindow->bringToFront();
+        }
+        break;
+    }
 }
 
 BOOL LLViewerWindow::handleTimerEvent(LLWindow *window)
 {
     //TODO: just call this every frame from gatherInput instead of using a convoluted 30fps timer callback
-	if (LLViewerJoystick::getInstance()->getOverrideCamera())
-	{
-		LLViewerJoystick::getInstance()->updateStatus();
-		return TRUE;
-	}
-	return FALSE;
+    if (LLViewerJoystick::getInstance()->getOverrideCamera())
+    {
+        LLViewerJoystick::getInstance()->updateStatus();
+        return TRUE;
+    }
+    return FALSE;
 }
 
 BOOL LLViewerWindow::handleDeviceChange(LLWindow *window)
 {
-	// give a chance to use a joystick after startup (hot-plugging)
-	if (!LLViewerJoystick::getInstance()->isJoystickInitialized() )
-	{
-		LLViewerJoystick::getInstance()->init(true);
-		return TRUE;
-	}
-	return FALSE;
+    // give a chance to use a joystick after startup (hot-plugging)
+    if (!LLViewerJoystick::getInstance()->isJoystickInitialized() )
+    {
+        LLViewerJoystick::getInstance()->init(true);
+        return TRUE;
+    }
+    return FALSE;
 }
 
 BOOL LLViewerWindow::handleDPIChanged(LLWindow *window, F32 ui_scale_factor, S32 window_width, S32 window_height)
@@ -2040,147 +2040,147 @@ BOOL LLViewerWindow::handleDPIChanged(LLWindow *window, F32 ui_scale_factor, S32
 
 void LLViewerWindow::handlePingWatchdog(LLWindow *window, const char * msg)
 {
-	LLAppViewer::instance()->pingMainloopTimeout(msg);
+    LLAppViewer::instance()->pingMainloopTimeout(msg);
 }
 
 
 void LLViewerWindow::handleResumeWatchdog(LLWindow *window)
 {
-	LLAppViewer::instance()->resumeMainloopTimeout();
+    LLAppViewer::instance()->resumeMainloopTimeout();
 }
 
 void LLViewerWindow::handlePauseWatchdog(LLWindow *window)
 {
-	LLAppViewer::instance()->pauseMainloopTimeout();
+    LLAppViewer::instance()->pauseMainloopTimeout();
 }
 
 //virtual
 std::string LLViewerWindow::translateString(const char* tag)
 {
-	return LLTrans::getString( std::string(tag) );
+    return LLTrans::getString( std::string(tag) );
 }
 
 //virtual
 std::string LLViewerWindow::translateString(const char* tag,
-		const std::map<std::string, std::string>& args)
-{
-	// LLTrans uses a special subclass of std::string for format maps,
-	// but we must use std::map<> in these callbacks, otherwise we create
-	// a dependency between LLWindow and LLFormatMapString.  So copy the data.
-	LLStringUtil::format_map_t args_copy;
-	std::map<std::string,std::string>::const_iterator it = args.begin();
-	for ( ; it != args.end(); ++it)
-	{
-		args_copy[it->first] = it->second;
-	}
-	return LLTrans::getString( std::string(tag), args_copy);
+        const std::map<std::string, std::string>& args)
+{
+    // LLTrans uses a special subclass of std::string for format maps,
+    // but we must use std::map<> in these callbacks, otherwise we create
+    // a dependency between LLWindow and LLFormatMapString.  So copy the data.
+    LLStringUtil::format_map_t args_copy;
+    std::map<std::string,std::string>::const_iterator it = args.begin();
+    for ( ; it != args.end(); ++it)
+    {
+        args_copy[it->first] = it->second;
+    }
+    return LLTrans::getString( std::string(tag), args_copy);
 }
 
 //
 // Classes
 //
 LLViewerWindow::LLViewerWindow(const Params& p)
-:	mWindow(NULL),
-	mActive(true),
-	mUIVisible(true),
-	mWindowRectRaw(0, p.height, p.width, 0),
-	mWindowRectScaled(0, p.height, p.width, 0),
-	mWorldViewRectRaw(0, p.height, p.width, 0),
-	mLeftMouseDown(FALSE),
-	mMiddleMouseDown(FALSE),
-	mRightMouseDown(FALSE),
-	mMouseInWindow( FALSE ),
-	mLastMask( MASK_NONE ),
-	mToolStored( NULL ),
-	mHideCursorPermanent( FALSE ),
-	mCursorHidden(FALSE),
-	mIgnoreActivate( FALSE ),
-	mResDirty(false),
-	mStatesDirty(false),
-	mCurrResolutionIndex(0),
-	mProgressView(NULL)
-{
-	// gKeyboard is still NULL, so it doesn't do LLWindowListener any good to
-	// pass its value right now. Instead, pass it a nullary function that
-	// will, when we later need it, return the value of gKeyboard.
-	// boost::lambda::var() constructs such a functor on the fly.
-	mWindowListener.reset(new LLWindowListener(this, boost::lambda::var(gKeyboard)));
-	mViewerWindowListener.reset(new LLViewerWindowListener(this));
-
-	mSystemChannel.reset(new LLNotificationChannel("System", "Visible", LLNotificationFilters::includeEverything));
-	mCommunicationChannel.reset(new LLCommunicationChannel("Communication", "Visible"));
-	mAlertsChannel.reset(new LLNotificationsUI::LLViewerAlertHandler("VW_alerts", "alert"));
-	mModalAlertsChannel.reset(new LLNotificationsUI::LLViewerAlertHandler("VW_alertmodal", "alertmodal"));
-
-	bool ignore = gSavedSettings.getBOOL("IgnoreAllNotifications");
-	LLNotifications::instance().setIgnoreAllNotifications(ignore);
-	if (ignore)
-	{
-	LL_INFOS() << "NOTE: ALL NOTIFICATIONS THAT OCCUR WILL GET ADDED TO IGNORE LIST FOR LATER RUNS." << LL_ENDL;
-	}
-
-
-	/*
-	LLWindowCallbacks* callbacks,
-	const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, U32 flags,
-	BOOL fullscreen, 
-	BOOL clearBg,
-	BOOL disable_vsync,
-	BOOL ignore_pixel_depth,
-	U32 fsaa_samples)
-	*/
-	// create window
+:   mWindow(NULL),
+    mActive(true),
+    mUIVisible(true),
+    mWindowRectRaw(0, p.height, p.width, 0),
+    mWindowRectScaled(0, p.height, p.width, 0),
+    mWorldViewRectRaw(0, p.height, p.width, 0),
+    mLeftMouseDown(FALSE),
+    mMiddleMouseDown(FALSE),
+    mRightMouseDown(FALSE),
+    mMouseInWindow( FALSE ),
+    mLastMask( MASK_NONE ),
+    mToolStored( NULL ),
+    mHideCursorPermanent( FALSE ),
+    mCursorHidden(FALSE),
+    mIgnoreActivate( FALSE ),
+    mResDirty(false),
+    mStatesDirty(false),
+    mCurrResolutionIndex(0),
+    mProgressView(NULL)
+{
+    // gKeyboard is still NULL, so it doesn't do LLWindowListener any good to
+    // pass its value right now. Instead, pass it a nullary function that
+    // will, when we later need it, return the value of gKeyboard.
+    // boost::lambda::var() constructs such a functor on the fly.
+    mWindowListener.reset(new LLWindowListener(this, boost::lambda::var(gKeyboard)));
+    mViewerWindowListener.reset(new LLViewerWindowListener(this));
+
+    mSystemChannel.reset(new LLNotificationChannel("System", "Visible", LLNotificationFilters::includeEverything));
+    mCommunicationChannel.reset(new LLCommunicationChannel("Communication", "Visible"));
+    mAlertsChannel.reset(new LLNotificationsUI::LLViewerAlertHandler("VW_alerts", "alert"));
+    mModalAlertsChannel.reset(new LLNotificationsUI::LLViewerAlertHandler("VW_alertmodal", "alertmodal"));
+
+    bool ignore = gSavedSettings.getBOOL("IgnoreAllNotifications");
+    LLNotifications::instance().setIgnoreAllNotifications(ignore);
+    if (ignore)
+    {
+    LL_INFOS() << "NOTE: ALL NOTIFICATIONS THAT OCCUR WILL GET ADDED TO IGNORE LIST FOR LATER RUNS." << LL_ENDL;
+    }
+
+
+    /*
+    LLWindowCallbacks* callbacks,
+    const std::string& title, const std::string& name, S32 x, S32 y, S32 width, S32 height, U32 flags,
+    BOOL fullscreen,
+    BOOL clearBg,
+    BOOL disable_vsync,
+    BOOL ignore_pixel_depth,
+    U32 fsaa_samples)
+    */
+    // create window
 
     U32 max_core_count = gSavedSettings.getU32("EmulateCoreCount");
     U32 max_vram = gSavedSettings.getU32("RenderMaxVRAMBudget");
     F32 max_gl_version = gSavedSettings.getF32("RenderMaxOpenGLVersion");
-    
-	mWindow = LLWindowManager::createWindow(this,
-		p.title, p.name, p.x, p.y, p.width, p.height, 0,
-		p.fullscreen, 
-		gHeadlessClient,
-		gSavedSettings.getBOOL("RenderVSyncEnable"),
-		!gHeadlessClient,
-		p.ignore_pixel_depth,
-		0,
+
+    mWindow = LLWindowManager::createWindow(this,
+        p.title, p.name, p.x, p.y, p.width, p.height, 0,
+        p.fullscreen,
+        gHeadlessClient,
+        gSavedSettings.getBOOL("RenderVSyncEnable"),
+        !gHeadlessClient,
+        p.ignore_pixel_depth,
+        0,
         max_core_count,
         max_vram,
         max_gl_version); //don't use window level anti-aliasing
 
-	if (NULL == mWindow)
-	{
-		LLSplashScreen::update(LLTrans::getString("StartupRequireDriverUpdate"));
-	
-		LL_WARNS("Window") << "Failed to create window, to be shutting Down, be sure your graphics driver is updated." << LL_ENDL ;
+    if (NULL == mWindow)
+    {
+        LLSplashScreen::update(LLTrans::getString("StartupRequireDriverUpdate"));
+
+        LL_WARNS("Window") << "Failed to create window, to be shutting Down, be sure your graphics driver is updated." << LL_ENDL ;
 
-		ms_sleep(5000) ; //wait for 5 seconds.
+        ms_sleep(5000) ; //wait for 5 seconds.
 
-		LLSplashScreen::update(LLTrans::getString("ShuttingDown"));
+        LLSplashScreen::update(LLTrans::getString("ShuttingDown"));
 #if LL_LINUX
-		LL_WARNS() << "Unable to create window, be sure screen is set at 32-bit color and your graphics driver is configured correctly.  See README-linux.txt for further information."
-				<< LL_ENDL;
+        LL_WARNS() << "Unable to create window, be sure screen is set at 32-bit color and your graphics driver is configured correctly.  See README-linux.txt for further information."
+                << LL_ENDL;
 #else
-		LL_WARNS("Window") << "Unable to create window, be sure screen is set at 32-bit color in Control Panels->Display->Settings"
-				<< LL_ENDL;
+        LL_WARNS("Window") << "Unable to create window, be sure screen is set at 32-bit color in Control Panels->Display->Settings"
+                << LL_ENDL;
 #endif
         LLAppViewer::instance()->fastQuit(1);
-	}
+    }
     else if (!LLViewerShaderMgr::sInitialized)
     {
         //immediately initialize shaders
         LLViewerShaderMgr::sInitialized = TRUE;
         LLViewerShaderMgr::instance()->setShaders();
     }
-	
-	if (!LLAppViewer::instance()->restoreErrorTrap())
-	{
+
+    if (!LLAppViewer::instance()->restoreErrorTrap())
+    {
         // this always happens, so downgrading it to INFO
-		LL_INFOS("Window") << " Someone took over my signal/exception handler (post createWindow; normal)" << LL_ENDL;
-	}
+        LL_INFOS("Window") << " Someone took over my signal/exception handler (post createWindow; normal)" << LL_ENDL;
+    }
 
-	const bool do_not_enforce = false;
-	mWindow->setMinSize(p.min_width, p.min_height, do_not_enforce);  // root view not set 
-	LLCoordScreen scr;
+    const bool do_not_enforce = false;
+    mWindow->setMinSize(p.min_width, p.min_height, do_not_enforce);  // root view not set
+    LLCoordScreen scr;
     mWindow->getSize(&scr);
 
     // Reset UI scale factor on first run if OS's display scaling is not 100%
@@ -2193,109 +2193,109 @@ LLViewerWindow::LLViewerWindow(const Params& p)
         gSavedSettings.setBOOL("ResetUIScaleOnFirstRun", FALSE);
     }
 
-	// Get the real window rect the window was created with (since there are various OS-dependent reasons why
-	// the size of a window or fullscreen context may have been adjusted slightly...)
-	F32 ui_scale_factor = llclamp(gSavedSettings.getF32("UIScaleFactor") * mWindow->getSystemUISize(), MIN_UI_SCALE, MAX_UI_SCALE);
-	
-	mDisplayScale.setVec(llmax(1.f / mWindow->getPixelAspectRatio(), 1.f), llmax(mWindow->getPixelAspectRatio(), 1.f));
-	mDisplayScale *= ui_scale_factor;
-	LLUI::setScaleFactor(mDisplayScale);
-
-	{
-		LLCoordWindow size;
-		mWindow->getSize(&size);
-		mWindowRectRaw.set(0, size.mY, size.mX, 0);
-		mWindowRectScaled.set(0, ll_round((F32)size.mY / mDisplayScale.mV[VY]), ll_round((F32)size.mX / mDisplayScale.mV[VX]), 0);
-	}
-	
-	LLFontManager::initClass();
-	// Init font system, load default fonts and generate basic glyphs
-	// currently it takes aprox. 0.5 sec and we would load these fonts anyway
-	// before login screen.
-	std::vector<std::string> font_files(1, "fonts.xml");
-	std::string strFontOverride = gSavedSettings.getString("FontOverrideMain");
-	if (!strFontOverride.empty())
-		font_files.push_back(strFontOverride);
-	strFontOverride = gSavedSettings.getString("FontOverrideMonospace");
-	if (!strFontOverride.empty())
-		font_files.push_back(strFontOverride);
-	LLFontGL::initClass(font_files, gSavedSettings.getF32("FontScreenDPI"),
-		mDisplayScale.mV[VX],
-		mDisplayScale.mV[VY],
-		gDirUtilp->getAppRODataDir());
-
-	//
-	// We want to set this stuff up BEFORE we initialize the pipeline, so we can turn off
-	// stuff like AGP if we think that it'll crash the viewer.
-	//
-	LL_DEBUGS("Window") << "Loading feature tables." << LL_ENDL;
-
-	// Initialize OpenGL Renderer
-	LLVertexBuffer::initClass(mWindow);
-	LL_INFOS("RenderInit") << "LLVertexBuffer initialization done." << LL_ENDL ;
-	if (!gGL.init(true))
+    // Get the real window rect the window was created with (since there are various OS-dependent reasons why
+    // the size of a window or fullscreen context may have been adjusted slightly...)
+    F32 ui_scale_factor = llclamp(gSavedSettings.getF32("UIScaleFactor") * mWindow->getSystemUISize(), MIN_UI_SCALE, MAX_UI_SCALE);
+
+    mDisplayScale.setVec(llmax(1.f / mWindow->getPixelAspectRatio(), 1.f), llmax(mWindow->getPixelAspectRatio(), 1.f));
+    mDisplayScale *= ui_scale_factor;
+    LLUI::setScaleFactor(mDisplayScale);
+
+    {
+        LLCoordWindow size;
+        mWindow->getSize(&size);
+        mWindowRectRaw.set(0, size.mY, size.mX, 0);
+        mWindowRectScaled.set(0, ll_round((F32)size.mY / mDisplayScale.mV[VY]), ll_round((F32)size.mX / mDisplayScale.mV[VX]), 0);
+    }
+
+    LLFontManager::initClass();
+    // Init font system, load default fonts and generate basic glyphs
+    // currently it takes aprox. 0.5 sec and we would load these fonts anyway
+    // before login screen.
+    std::vector<std::string> font_files(1, "fonts.xml");
+    std::string strFontOverride = gSavedSettings.getString("FontOverrideMain");
+    if (!strFontOverride.empty())
+        font_files.push_back(strFontOverride);
+    strFontOverride = gSavedSettings.getString("FontOverrideMonospace");
+    if (!strFontOverride.empty())
+        font_files.push_back(strFontOverride);
+    LLFontGL::initClass(font_files, gSavedSettings.getF32("FontScreenDPI"),
+        mDisplayScale.mV[VX],
+        mDisplayScale.mV[VY],
+        gDirUtilp->getAppRODataDir());
+
+    //
+    // We want to set this stuff up BEFORE we initialize the pipeline, so we can turn off
+    // stuff like AGP if we think that it'll crash the viewer.
+    //
+    LL_DEBUGS("Window") << "Loading feature tables." << LL_ENDL;
+
+    // Initialize OpenGL Renderer
+    LLVertexBuffer::initClass(mWindow);
+    LL_INFOS("RenderInit") << "LLVertexBuffer initialization done." << LL_ENDL ;
+    if (!gGL.init(true))
     {
         LLError::LLUserWarningMsg::show(LLTrans::getString("MBVideoDrvErr"));
         LL_ERRS() << "gGL not initialized" << LL_ENDL;
     }
 
-	if (LLFeatureManager::getInstance()->isSafe()
-		|| (gSavedSettings.getS32("LastFeatureVersion") != LLFeatureManager::getInstance()->getVersion())
-		|| (gSavedSettings.getString("LastGPUString") != LLFeatureManager::getInstance()->getGPUString())
-		|| (gSavedSettings.getBOOL("ProbeHardwareOnStartup")))
-	{
-		LLFeatureManager::getInstance()->applyRecommendedSettings();
-		gSavedSettings.setBOOL("ProbeHardwareOnStartup", FALSE);
-	}
-
-	// If we crashed while initializng GL stuff last time, disable certain features
-	if (gSavedSettings.getBOOL("RenderInitError"))
-	{
-		mInitAlert = "DisplaySettingsNoShaders";
-		LLFeatureManager::getInstance()->setGraphicsLevel(0, false);
-		gSavedSettings.setU32("RenderQualityPerformance", 0);		
-	}
-		
-	// Init the image list.  Must happen after GL is initialized and before the images that
-	// LLViewerWindow needs are requested, as well as before LLViewerMedia starts updating images.
+    if (LLFeatureManager::getInstance()->isSafe()
+        || (gSavedSettings.getS32("LastFeatureVersion") != LLFeatureManager::getInstance()->getVersion())
+        || (gSavedSettings.getString("LastGPUString") != LLFeatureManager::getInstance()->getGPUString())
+        || (gSavedSettings.getBOOL("ProbeHardwareOnStartup")))
+    {
+        LLFeatureManager::getInstance()->applyRecommendedSettings();
+        gSavedSettings.setBOOL("ProbeHardwareOnStartup", FALSE);
+    }
+
+    // If we crashed while initializng GL stuff last time, disable certain features
+    if (gSavedSettings.getBOOL("RenderInitError"))
+    {
+        mInitAlert = "DisplaySettingsNoShaders";
+        LLFeatureManager::getInstance()->setGraphicsLevel(0, false);
+        gSavedSettings.setU32("RenderQualityPerformance", 0);
+    }
+
+    // Init the image list.  Must happen after GL is initialized and before the images that
+    // LLViewerWindow needs are requested, as well as before LLViewerMedia starts updating images.
     LLImageGL::initClass(mWindow, LLViewerTexture::MAX_GL_IMAGE_CATEGORY, false, gSavedSettings.getBOOL("RenderGLMultiThreadedTextures"), gSavedSettings.getBOOL("RenderGLMultiThreadedMedia"));
-	gTextureList.init();
-	LLViewerTextureManager::init() ;
-	gBumpImageList.init();
-	
+    gTextureList.init();
+    LLViewerTextureManager::init() ;
+    gBumpImageList.init();
+
     // Create container for all sub-views
-	LLView::Params rvp;
-	rvp.name("root");
-	rvp.rect(mWindowRectScaled);
-	rvp.mouse_opaque(false);
-	rvp.follows.flags(FOLLOWS_NONE);
-	mRootView = LLUICtrlFactory::create<LLRootView>(rvp);
-	LLUI::setRootView(mRootView);
+    LLView::Params rvp;
+    rvp.name("root");
+    rvp.rect(mWindowRectScaled);
+    rvp.mouse_opaque(false);
+    rvp.follows.flags(FOLLOWS_NONE);
+    mRootView = LLUICtrlFactory::create<LLRootView>(rvp);
+    LLUI::setRootView(mRootView);
 
-	// Make avatar head look forward at start
-	mCurrentMousePoint.mX = getWindowWidthScaled() / 2;
-	mCurrentMousePoint.mY = getWindowHeightScaled() / 2;
+    // Make avatar head look forward at start
+    mCurrentMousePoint.mX = getWindowWidthScaled() / 2;
+    mCurrentMousePoint.mY = getWindowHeightScaled() / 2;
 
-	gShowOverlayTitle = gSavedSettings.getBOOL("ShowOverlayTitle");
-	mOverlayTitle = gSavedSettings.getString("OverlayTitle");
-	// Can't have spaces in settings.ini strings, so use underscores instead and convert them.
-	LLStringUtil::replaceChar(mOverlayTitle, '_', ' ');
+    gShowOverlayTitle = gSavedSettings.getBOOL("ShowOverlayTitle");
+    mOverlayTitle = gSavedSettings.getString("OverlayTitle");
+    // Can't have spaces in settings.ini strings, so use underscores instead and convert them.
+    LLStringUtil::replaceChar(mOverlayTitle, '_', ' ');
 
-	mDebugText = new LLDebugText(this);
+    mDebugText = new LLDebugText(this);
 
-	mWorldViewRectScaled = calcScaledRect(mWorldViewRectRaw, mDisplayScale);
+    mWorldViewRectScaled = calcScaledRect(mWorldViewRectRaw, mDisplayScale);
 }
 
 std::string LLViewerWindow::getLastSnapshotDir()
 {
-    static LLCachedControl<std::string>	sSnapshotDir(gSavedPerAccountSettings, "SnapshotBaseDir", "");
+    static LLCachedControl<std::string> sSnapshotDir(gSavedPerAccountSettings, "SnapshotBaseDir", "");
     return sSnapshotDir;
 }
 
 void LLViewerWindow::initGLDefaults()
 {
-	// RN: Need this for translation and stretch manip.
-	gBox.prerender();
+    // RN: Need this for translation and stretch manip.
+    gBox.prerender();
 }
 
 struct MainPanel final : public LLPanel
@@ -2304,549 +2304,549 @@ struct MainPanel final : public LLPanel
 
 void LLViewerWindow::initBase()
 {
-	S32 height = getWindowHeightScaled();
-	S32 width = getWindowWidthScaled();
+    S32 height = getWindowHeightScaled();
+    S32 width = getWindowWidthScaled();
 
-	LLRect full_window(0, height, width, 0);
+    LLRect full_window(0, height, width, 0);
 
-	////////////////////
-	//
-	// Set the gamma
-	//
+    ////////////////////
+    //
+    // Set the gamma
+    //
 
-	F32 gamma = gSavedSettings.getF32("RenderGamma");
-	if (gamma != 0.0f)
-	{
-		getWindow()->setGamma(gamma);
-	}
+    F32 gamma = gSavedSettings.getF32("RenderGamma");
+    if (gamma != 0.0f)
+    {
+        getWindow()->setGamma(gamma);
+    }
 
-	// Create global views
+    // Create global views
 
-	// Login screen and main_view.xml need edit menus for preferences and browser
-	LL_DEBUGS("AppInit") << "initializing edit menu" << LL_ENDL;
-	initialize_edit_menu();
+    // Login screen and main_view.xml need edit menus for preferences and browser
+    LL_DEBUGS("AppInit") << "initializing edit menu" << LL_ENDL;
+    initialize_edit_menu();
 
     LLFontGL::loadCommonFonts();
 
-	// Create the floater view at the start so that other views can add children to it. 
-	// (But wait to add it as a child of the root view so that it will be in front of the 
-	// other views.)
-	MainPanel* main_view = new MainPanel();
-	if (!main_view->buildFromFile("main_view.xml"))
-	{
-		LL_ERRS() << "Failed to initialize viewer: Viewer couldn't process file main_view.xml, "
-				<< "if this problem happens again, please validate your installation." << LL_ENDL;
-	}
-	main_view->setShape(full_window);
-	getRootView()->addChild(main_view);
-
-	// placeholder widget that controls where "world" is rendered
-	mWorldViewPlaceholder = main_view->getChildView("world_view_rect")->getHandle();
-	mPopupView = main_view->getChild<LLPopupView>("popup_holder");
-	mHintHolder = main_view->getChild<LLView>("hint_holder")->getHandle();
-	mLoginPanelHolder = main_view->getChild<LLView>("login_panel_holder")->getHandle();
-
-	// Create the toolbar view
-	// Get a pointer to the toolbar view holder
-	LLPanel* panel_holder = main_view->getChild<LLPanel>("toolbar_view_holder");
-	// Load the toolbar view from file 
-	gToolBarView = LLUICtrlFactory::getInstance()->createFromFile<LLToolBarView>("panel_toolbar_view.xml", panel_holder, LLDefaultChildRegistry::instance());
-	if (!gToolBarView)
-	{
-		LL_ERRS() << "Failed to initialize viewer: Viewer couldn't process file panel_toolbar_view.xml, "
-				<< "if this problem happens again, please validate your installation." << LL_ENDL;
-	}
-	gToolBarView->setShape(panel_holder->getLocalRect());
-	// Hide the toolbars for the moment: we'll make them visible after logging in world (see LLViewerWindow::initWorldUI())
-	gToolBarView->setVisible(FALSE);
-
-	// Constrain floaters to inside the menu and status bar regions.
-	gFloaterView = main_view->getChild<LLFloaterView>("Floater View");
-	for (S32 i = 0; i < LLToolBarEnums::TOOLBAR_COUNT; ++i)
-	{
-		LLToolBar * toolbarp = gToolBarView->getToolbar((LLToolBarEnums::EToolBarLocation)i);
-		if (toolbarp)
-		{
-			toolbarp->getCenterLayoutPanel()->setReshapeCallback(boost::bind(&LLFloaterView::setToolbarRect, gFloaterView, _1, _2));
-		}
-	}
-	mChicletContainer = getRootView()->getChild<LLPanel>("chiclet_container");
-	mFloaterSnapRegion = main_view->getChild<LLView>("floater_snap_region");
-	gFloaterView->setFloaterSnapView(mFloaterSnapRegion->getHandle());
-	gSnapshotFloaterView = main_view->getChild<LLSnapshotFloaterView>("Snapshot Floater View");
+    // Create the floater view at the start so that other views can add children to it.
+    // (But wait to add it as a child of the root view so that it will be in front of the
+    // other views.)
+    MainPanel* main_view = new MainPanel();
+    if (!main_view->buildFromFile("main_view.xml"))
+    {
+        LL_ERRS() << "Failed to initialize viewer: Viewer couldn't process file main_view.xml, "
+                << "if this problem happens again, please validate your installation." << LL_ENDL;
+    }
+    main_view->setShape(full_window);
+    getRootView()->addChild(main_view);
+
+    // placeholder widget that controls where "world" is rendered
+    mWorldViewPlaceholder = main_view->getChildView("world_view_rect")->getHandle();
+    mPopupView = main_view->getChild<LLPopupView>("popup_holder");
+    mHintHolder = main_view->getChild<LLView>("hint_holder")->getHandle();
+    mLoginPanelHolder = main_view->getChild<LLView>("login_panel_holder")->getHandle();
+
+    // Create the toolbar view
+    // Get a pointer to the toolbar view holder
+    LLPanel* panel_holder = main_view->getChild<LLPanel>("toolbar_view_holder");
+    // Load the toolbar view from file
+    gToolBarView = LLUICtrlFactory::getInstance()->createFromFile<LLToolBarView>("panel_toolbar_view.xml", panel_holder, LLDefaultChildRegistry::instance());
+    if (!gToolBarView)
+    {
+        LL_ERRS() << "Failed to initialize viewer: Viewer couldn't process file panel_toolbar_view.xml, "
+                << "if this problem happens again, please validate your installation." << LL_ENDL;
+    }
+    gToolBarView->setShape(panel_holder->getLocalRect());
+    // Hide the toolbars for the moment: we'll make them visible after logging in world (see LLViewerWindow::initWorldUI())
+    gToolBarView->setVisible(FALSE);
+
+    // Constrain floaters to inside the menu and status bar regions.
+    gFloaterView = main_view->getChild<LLFloaterView>("Floater View");
+    for (S32 i = 0; i < LLToolBarEnums::TOOLBAR_COUNT; ++i)
+    {
+        LLToolBar * toolbarp = gToolBarView->getToolbar((LLToolBarEnums::EToolBarLocation)i);
+        if (toolbarp)
+        {
+            toolbarp->getCenterLayoutPanel()->setReshapeCallback(boost::bind(&LLFloaterView::setToolbarRect, gFloaterView, _1, _2));
+        }
+    }
+    mChicletContainer = getRootView()->getChild<LLPanel>("chiclet_container");
+    mFloaterSnapRegion = main_view->getChild<LLView>("floater_snap_region");
+    gFloaterView->setFloaterSnapView(mFloaterSnapRegion->getHandle());
+    gSnapshotFloaterView = main_view->getChild<LLSnapshotFloaterView>("Snapshot Floater View");
 
     const F32 CHAT_PERSIST_TIME = 20.f;
 
-	// Console
-	llassert( !gConsole );
-	LLConsole::Params cp;
-	cp.name("console");
-	cp.max_lines(gSavedSettings.getS32("ConsoleBufferSize"));
-	cp.rect(getChatConsoleRect());
+    // Console
+    llassert( !gConsole );
+    LLConsole::Params cp;
+    cp.name("console");
+    cp.max_lines(gSavedSettings.getS32("ConsoleBufferSize"));
+    cp.rect(getChatConsoleRect());
     cp.persist_time(CHAT_PERSIST_TIME);
-	cp.font_size_index(gSavedSettings.getS32("ChatFontSize"));
-	cp.follows.flags(FOLLOWS_LEFT | FOLLOWS_RIGHT | FOLLOWS_BOTTOM);
-	gConsole = LLUICtrlFactory::create<LLConsole>(cp);
-	getRootView()->addChild(gConsole);
+    cp.font_size_index(gSavedSettings.getS32("ChatFontSize"));
+    cp.follows.flags(FOLLOWS_LEFT | FOLLOWS_RIGHT | FOLLOWS_BOTTOM);
+    gConsole = LLUICtrlFactory::create<LLConsole>(cp);
+    getRootView()->addChild(gConsole);
 
-	// optionally forward warnings to chat console/chat floater
-	// for qa runs and dev builds
+    // optionally forward warnings to chat console/chat floater
+    // for qa runs and dev builds
 #if  !LL_RELEASE_FOR_DOWNLOAD
-	RecordToChatConsole::getInstance()->startRecorder();
+    RecordToChatConsole::getInstance()->startRecorder();
 #else
-	if(gSavedSettings.getBOOL("QAMode"))
-	{
-		RecordToChatConsole::getInstance()->startRecorder();
-	}
+    if(gSavedSettings.getBOOL("QAMode"))
+    {
+        RecordToChatConsole::getInstance()->startRecorder();
+    }
 #endif
 
-	gDebugView = getRootView()->getChild<LLDebugView>("DebugView");
-	gDebugView->init();
-	gToolTipView = getRootView()->getChild<LLToolTipView>("tooltip view");
+    gDebugView = getRootView()->getChild<LLDebugView>("DebugView");
+    gDebugView->init();
+    gToolTipView = getRootView()->getChild<LLToolTipView>("tooltip view");
 
-	// Initialize do not disturb response message when logged in
-	LLAppViewer::instance()->setOnLoginCompletedCallback(boost::bind(&LLFloaterPreference::initDoNotDisturbResponse));
+    // Initialize do not disturb response message when logged in
+    LLAppViewer::instance()->setOnLoginCompletedCallback(boost::bind(&LLFloaterPreference::initDoNotDisturbResponse));
 
-	// Add the progress bar view (startup view), which overrides everything
-	mProgressView = getRootView()->findChild<LLProgressView>("progress_view");
-	setShowProgress(FALSE);
-	setProgressCancelButtonVisible(FALSE);
+    // Add the progress bar view (startup view), which overrides everything
+    mProgressView = getRootView()->findChild<LLProgressView>("progress_view");
+    setShowProgress(FALSE);
+    setProgressCancelButtonVisible(FALSE);
 
-	gMenuHolder = getRootView()->getChild<LLViewerMenuHolderGL>("Menu Holder");
-	LLMenuGL::sMenuContainer = gMenuHolder;
+    gMenuHolder = getRootView()->getChild<LLViewerMenuHolderGL>("Menu Holder");
+    LLMenuGL::sMenuContainer = gMenuHolder;
 }
 
 void LLViewerWindow::initWorldUI()
 {
-	if (gNonInteractive)
-	{
-		gIMMgr = LLIMMgr::getInstance();
-		LLNavigationBar::getInstance();
-		gFloaterView->pushVisibleAll(FALSE);
-		return;
-	}
-	
-	S32 height = mRootView->getRect().getHeight();
-	S32 width = mRootView->getRect().getWidth();
-	LLRect full_window(0, height, width, 0);
-
-
-	gIMMgr = LLIMMgr::getInstance();
-
-	//getRootView()->sendChildToFront(gFloaterView);
-	//getRootView()->sendChildToFront(gSnapshotFloaterView);
-
-	if (!gNonInteractive)
-	{
-		LLChicletBar* chiclet_bar = LLChicletBar::getInstance();
-		chiclet_bar->setShape(mChicletContainer->getLocalRect());
-		chiclet_bar->setFollowsAll();
-		mChicletContainer->addChild(chiclet_bar);
-		mChicletContainer->setVisible(TRUE);
-	}
-
-	LLRect morph_view_rect = full_window;
-	morph_view_rect.stretch( -STATUS_BAR_HEIGHT );
-	morph_view_rect.mTop = full_window.mTop - 32;
-	LLMorphView::Params mvp;
-	mvp.name("MorphView");
-	mvp.rect(morph_view_rect);
-	mvp.visible(false);
-	gMorphView = LLUICtrlFactory::create<LLMorphView>(mvp);
-	getRootView()->addChild(gMorphView);
-
-	LLWorldMapView::initClass();
-	
-	// Force gFloaterWorldMap to initialize
-	LLFloaterReg::getInstance("world_map");
-
-	// Force gFloaterTools to initialize
-	LLFloaterReg::getInstance("build");
-
-	// Status bar
-	mStatusBarContainer = getRootView()->getChild<LLPanel>("status_bar_container");
-	gStatusBar = new LLStatusBar(mStatusBarContainer->getLocalRect());
-	gStatusBar->setFollows(FOLLOWS_LEFT | FOLLOWS_TOP | FOLLOWS_RIGHT);
-	gStatusBar->setShape(mStatusBarContainer->getLocalRect());
-	// sync bg color with menu bar
-	gStatusBar->setBackgroundColor( gMenuBarView->getBackgroundColor().get() );
+    if (gNonInteractive)
+    {
+        gIMMgr = LLIMMgr::getInstance();
+        LLNavigationBar::getInstance();
+        gFloaterView->pushVisibleAll(FALSE);
+        return;
+    }
+
+    S32 height = mRootView->getRect().getHeight();
+    S32 width = mRootView->getRect().getWidth();
+    LLRect full_window(0, height, width, 0);
+
+
+    gIMMgr = LLIMMgr::getInstance();
+
+    //getRootView()->sendChildToFront(gFloaterView);
+    //getRootView()->sendChildToFront(gSnapshotFloaterView);
+
+    if (!gNonInteractive)
+    {
+        LLChicletBar* chiclet_bar = LLChicletBar::getInstance();
+        chiclet_bar->setShape(mChicletContainer->getLocalRect());
+        chiclet_bar->setFollowsAll();
+        mChicletContainer->addChild(chiclet_bar);
+        mChicletContainer->setVisible(TRUE);
+    }
+
+    LLRect morph_view_rect = full_window;
+    morph_view_rect.stretch( -STATUS_BAR_HEIGHT );
+    morph_view_rect.mTop = full_window.mTop - 32;
+    LLMorphView::Params mvp;
+    mvp.name("MorphView");
+    mvp.rect(morph_view_rect);
+    mvp.visible(false);
+    gMorphView = LLUICtrlFactory::create<LLMorphView>(mvp);
+    getRootView()->addChild(gMorphView);
+
+    LLWorldMapView::initClass();
+
+    // Force gFloaterWorldMap to initialize
+    LLFloaterReg::getInstance("world_map");
+
+    // Force gFloaterTools to initialize
+    LLFloaterReg::getInstance("build");
+
+    // Status bar
+    mStatusBarContainer = getRootView()->getChild<LLPanel>("status_bar_container");
+    gStatusBar = new LLStatusBar(mStatusBarContainer->getLocalRect());
+    gStatusBar->setFollows(FOLLOWS_LEFT | FOLLOWS_TOP | FOLLOWS_RIGHT);
+    gStatusBar->setShape(mStatusBarContainer->getLocalRect());
+    // sync bg color with menu bar
+    gStatusBar->setBackgroundColor( gMenuBarView->getBackgroundColor().get() );
     // add InBack so that gStatusBar won't be drawn over menu
     mStatusBarContainer->addChildInBack(gStatusBar, 2/*tab order, after menu*/);
     mStatusBarContainer->setVisible(TRUE);
 
-	// Navigation bar
-	mNavBarBarContainer = getRootView()->getChild<LLView>("nav_bar_container");
+    // Navigation bar
+    mNavBarBarContainer = getRootView()->getChild<LLView>("nav_bar_container");
 
-	LLNavigationBar* navbar = LLNavigationBar::getInstance();
-	navbar->setShape(mNavBarBarContainer->getLocalRect());
-	navbar->setBackgroundColor(gMenuBarView->getBackgroundColor().get());
-	mNavBarBarContainer->addChild(navbar);
-	mNavBarBarContainer->setVisible(TRUE);
+    LLNavigationBar* navbar = LLNavigationBar::getInstance();
+    navbar->setShape(mNavBarBarContainer->getLocalRect());
+    navbar->setBackgroundColor(gMenuBarView->getBackgroundColor().get());
+    mNavBarBarContainer->addChild(navbar);
+    mNavBarBarContainer->setVisible(TRUE);
 
 
-	if (!gSavedSettings.getBOOL("ShowNavbarNavigationPanel"))
-	{
-		navbar->setVisible(FALSE);
-	}
+    if (!gSavedSettings.getBOOL("ShowNavbarNavigationPanel"))
+    {
+        navbar->setVisible(FALSE);
+    }
     else
     {
         reshapeStatusBarContainer();
     }
 
 
-	// Top Info bar
-	LLPanel* topinfo_bar_container = getRootView()->getChild<LLPanel>("topinfo_bar_container");
-	LLPanelTopInfoBar* topinfo_bar = LLPanelTopInfoBar::getInstance();
+    // Top Info bar
+    LLPanel* topinfo_bar_container = getRootView()->getChild<LLPanel>("topinfo_bar_container");
+    LLPanelTopInfoBar* topinfo_bar = LLPanelTopInfoBar::getInstance();
 
-	topinfo_bar->setShape(topinfo_bar_container->getLocalRect());
+    topinfo_bar->setShape(topinfo_bar_container->getLocalRect());
 
-	topinfo_bar_container->addChild(topinfo_bar);
-	topinfo_bar_container->setVisible(TRUE);
+    topinfo_bar_container->addChild(topinfo_bar);
+    topinfo_bar_container->setVisible(TRUE);
 
-	if (!gSavedSettings.getBOOL("ShowMiniLocationPanel"))
-	{
-		topinfo_bar->setVisible(FALSE);
-	}
+    if (!gSavedSettings.getBOOL("ShowMiniLocationPanel"))
+    {
+        topinfo_bar->setVisible(FALSE);
+    }
 
-	if ( gHUDView == NULL )
-	{
-		LLRect hud_rect = full_window;
-		hud_rect.mBottom += 50;
-		if (gMenuBarView && gMenuBarView->isInVisibleChain())
-		{
-			hud_rect.mTop -= gMenuBarView->getRect().getHeight();
-		}
-		gHUDView = new LLHUDView(hud_rect);
-		getRootView()->addChild(gHUDView);
-		getRootView()->sendChildToBack(gHUDView);
-	}
+    if ( gHUDView == NULL )
+    {
+        LLRect hud_rect = full_window;
+        hud_rect.mBottom += 50;
+        if (gMenuBarView && gMenuBarView->isInVisibleChain())
+        {
+            hud_rect.mTop -= gMenuBarView->getRect().getHeight();
+        }
+        gHUDView = new LLHUDView(hud_rect);
+        getRootView()->addChild(gHUDView);
+        getRootView()->sendChildToBack(gHUDView);
+    }
 
-	LLPanel* panel_ssf_container = getRootView()->getChild<LLPanel>("state_management_buttons_container");
+    LLPanel* panel_ssf_container = getRootView()->getChild<LLPanel>("state_management_buttons_container");
 
-	LLPanelStandStopFlying* panel_stand_stop_flying	= LLPanelStandStopFlying::getInstance();
-	panel_ssf_container->addChild(panel_stand_stop_flying);
+    LLPanelStandStopFlying* panel_stand_stop_flying = LLPanelStandStopFlying::getInstance();
+    panel_ssf_container->addChild(panel_stand_stop_flying);
 
-	LLPanelHideBeacon* panel_hide_beacon = LLPanelHideBeacon::getInstance();
-	panel_ssf_container->addChild(panel_hide_beacon);
+    LLPanelHideBeacon* panel_hide_beacon = LLPanelHideBeacon::getInstance();
+    panel_ssf_container->addChild(panel_hide_beacon);
 
-	panel_ssf_container->setVisible(TRUE);
+    panel_ssf_container->setVisible(TRUE);
 
-	LLMenuOptionPathfindingRebakeNavmesh::getInstance()->initialize();
+    LLMenuOptionPathfindingRebakeNavmesh::getInstance()->initialize();
 
-	// Load and make the toolbars visible
-	// Note: we need to load the toolbars only *after* the user is logged in and IW
-	if (gToolBarView)
-	{
-		gToolBarView->loadToolbars();
-		gToolBarView->setVisible(TRUE);
-	}
+    // Load and make the toolbars visible
+    // Note: we need to load the toolbars only *after* the user is logged in and IW
+    if (gToolBarView)
+    {
+        gToolBarView->loadToolbars();
+        gToolBarView->setVisible(TRUE);
+    }
 }
 
 // Destroy the UI
 void LLViewerWindow::shutdownViews()
 {
-	// clean up warning logger
-	RecordToChatConsole::getInstance()->stopRecorder();
-	LL_INFOS() << "Warning logger is cleaned." << LL_ENDL ;
-
-	gFocusMgr.unlockFocus();
-	gFocusMgr.setMouseCapture(NULL);
-	gFocusMgr.setKeyboardFocus(NULL);
-	gFocusMgr.setTopCtrl(NULL);
-	if (mWindow)
-	{
-		mWindow->allowLanguageTextInput(NULL, FALSE);
-	}
-
-	delete mDebugText;
-	mDebugText = NULL;
-	
-	LL_INFOS() << "DebugText deleted." << LL_ENDL ;
-
-	// Cleanup global views
-	if (gMorphView)
-	{
-		gMorphView->setVisible(FALSE);
-	}
-	LL_INFOS() << "Global views cleaned." << LL_ENDL ;
-	
-	LLNotificationsUI::LLToast::cleanupToasts();
-	LL_INFOS() << "Leftover toast cleaned up." << LL_ENDL;
-
-	// DEV-40930: Clear sModalStack. Otherwise, any LLModalDialog left open
-	// will crump with LL_ERRS.
-	LLModalDialog::shutdownModals();
-	LL_INFOS() << "LLModalDialog shut down." << LL_ENDL; 
-
-	// destroy the nav bar, not currently part of gViewerWindow
-	// *TODO: Make LLNavigationBar part of gViewerWindow
-	LLNavigationBar::deleteSingleton();
-	LL_INFOS() << "LLNavigationBar destroyed." << LL_ENDL ;
-	
-	// destroy menus after instantiating navbar above, as it needs
-	// access to gMenuHolder
-	cleanup_menus();
-	LL_INFOS() << "menus destroyed." << LL_ENDL ;
-
-	view_listener_t::cleanup();
-	LL_INFOS() << "view listeners destroyed." << LL_ENDL ;
-
-	// Clean up pointers that are going to be invalid. (todo: check sMenuContainer)
-	mProgressView = NULL;
-	mPopupView = NULL;
-
-	// Delete all child views.
-	delete mRootView;
-	mRootView = NULL;
-	LL_INFOS() << "RootView deleted." << LL_ENDL ;
-	
-	LLMenuOptionPathfindingRebakeNavmesh::getInstance()->quit();
-
-	// Automatically deleted as children of mRootView.  Fix the globals.
-	gStatusBar = NULL;
-	gIMMgr = NULL;
-	gToolTipView = NULL;
-
-	gToolBarView = NULL;
-	gFloaterView = NULL;
-	gMorphView = NULL;
-
-	gHUDView = NULL;
+    // clean up warning logger
+    RecordToChatConsole::getInstance()->stopRecorder();
+    LL_INFOS() << "Warning logger is cleaned." << LL_ENDL ;
+
+    gFocusMgr.unlockFocus();
+    gFocusMgr.setMouseCapture(NULL);
+    gFocusMgr.setKeyboardFocus(NULL);
+    gFocusMgr.setTopCtrl(NULL);
+    if (mWindow)
+    {
+        mWindow->allowLanguageTextInput(NULL, FALSE);
+    }
+
+    delete mDebugText;
+    mDebugText = NULL;
+
+    LL_INFOS() << "DebugText deleted." << LL_ENDL ;
+
+    // Cleanup global views
+    if (gMorphView)
+    {
+        gMorphView->setVisible(FALSE);
+    }
+    LL_INFOS() << "Global views cleaned." << LL_ENDL ;
+
+    LLNotificationsUI::LLToast::cleanupToasts();
+    LL_INFOS() << "Leftover toast cleaned up." << LL_ENDL;
+
+    // DEV-40930: Clear sModalStack. Otherwise, any LLModalDialog left open
+    // will crump with LL_ERRS.
+    LLModalDialog::shutdownModals();
+    LL_INFOS() << "LLModalDialog shut down." << LL_ENDL;
+
+    // destroy the nav bar, not currently part of gViewerWindow
+    // *TODO: Make LLNavigationBar part of gViewerWindow
+    LLNavigationBar::deleteSingleton();
+    LL_INFOS() << "LLNavigationBar destroyed." << LL_ENDL ;
+
+    // destroy menus after instantiating navbar above, as it needs
+    // access to gMenuHolder
+    cleanup_menus();
+    LL_INFOS() << "menus destroyed." << LL_ENDL ;
+
+    view_listener_t::cleanup();
+    LL_INFOS() << "view listeners destroyed." << LL_ENDL ;
+
+    // Clean up pointers that are going to be invalid. (todo: check sMenuContainer)
+    mProgressView = NULL;
+    mPopupView = NULL;
+
+    // Delete all child views.
+    delete mRootView;
+    mRootView = NULL;
+    LL_INFOS() << "RootView deleted." << LL_ENDL ;
+
+    LLMenuOptionPathfindingRebakeNavmesh::getInstance()->quit();
+
+    // Automatically deleted as children of mRootView.  Fix the globals.
+    gStatusBar = NULL;
+    gIMMgr = NULL;
+    gToolTipView = NULL;
+
+    gToolBarView = NULL;
+    gFloaterView = NULL;
+    gMorphView = NULL;
+
+    gHUDView = NULL;
 }
 
 void LLViewerWindow::shutdownGL()
 {
-	//--------------------------------------------------------
-	// Shutdown GL cleanly.  Order is very important here.
-	//--------------------------------------------------------
-	LLFontGL::destroyDefaultFonts();
-	SUBSYSTEM_CLEANUP(LLFontManager);
-	stop_glerror();
+    //--------------------------------------------------------
+    // Shutdown GL cleanly.  Order is very important here.
+    //--------------------------------------------------------
+    LLFontGL::destroyDefaultFonts();
+    SUBSYSTEM_CLEANUP(LLFontManager);
+    stop_glerror();
 
-	gSky.cleanup();
-	stop_glerror();
+    gSky.cleanup();
+    stop_glerror();
+
+    LL_INFOS() << "Cleaning up pipeline" << LL_ENDL;
+    gPipeline.cleanup();
+    stop_glerror();
 
-	LL_INFOS() << "Cleaning up pipeline" << LL_ENDL;
-	gPipeline.cleanup();
-	stop_glerror();
+    //MUST clean up pipeline before cleaning up wearables
+    LL_INFOS() << "Cleaning up wearables" << LL_ENDL;
+    LLWearableList::instance().cleanup() ;
 
-	//MUST clean up pipeline before cleaning up wearables
-	LL_INFOS() << "Cleaning up wearables" << LL_ENDL;
-	LLWearableList::instance().cleanup() ;
+    gTextureList.shutdown();
+    stop_glerror();
 
-	gTextureList.shutdown();
-	stop_glerror();
+    gBumpImageList.shutdown();
+    stop_glerror();
 
-	gBumpImageList.shutdown();
-	stop_glerror();
+    LLWorldMapView::cleanupTextures();
 
-	LLWorldMapView::cleanupTextures();
+    LLViewerTextureManager::cleanup() ;
+    SUBSYSTEM_CLEANUP(LLImageGL) ;
 
-	LLViewerTextureManager::cleanup() ;
-	SUBSYSTEM_CLEANUP(LLImageGL) ;
-    
-	LL_INFOS() << "All textures and llimagegl images are destroyed!" << LL_ENDL ;
+    LL_INFOS() << "All textures and llimagegl images are destroyed!" << LL_ENDL ;
 
-	LL_INFOS() << "Cleaning up select manager" << LL_ENDL;
-	LLSelectMgr::getInstance()->cleanup();	
+    LL_INFOS() << "Cleaning up select manager" << LL_ENDL;
+    LLSelectMgr::getInstance()->cleanup();
 
-	LL_INFOS() << "Stopping GL during shutdown" << LL_ENDL;
-	stopGL(FALSE);
-	stop_glerror();
+    LL_INFOS() << "Stopping GL during shutdown" << LL_ENDL;
+    stopGL(FALSE);
+    stop_glerror();
 
-	gGL.shutdown();
+    gGL.shutdown();
 
-	SUBSYSTEM_CLEANUP(LLVertexBuffer);
+    SUBSYSTEM_CLEANUP(LLVertexBuffer);
 
-	LL_INFOS() << "LLVertexBuffer cleaned." << LL_ENDL ;
+    LL_INFOS() << "LLVertexBuffer cleaned." << LL_ENDL ;
 }
 
 // shutdownViews() and shutdownGL() need to be called first
 LLViewerWindow::~LLViewerWindow()
 {
-	LL_INFOS() << "Destroying Window" << LL_ENDL;
-	destroyWindow();
+    LL_INFOS() << "Destroying Window" << LL_ENDL;
+    destroyWindow();
 
-	delete mDebugText;
-	mDebugText = NULL;
+    delete mDebugText;
+    mDebugText = NULL;
 
-	if (LLViewerShaderMgr::sInitialized)
-	{
-		LLViewerShaderMgr::releaseInstance();
-		LLViewerShaderMgr::sInitialized = FALSE;
-	}
+    if (LLViewerShaderMgr::sInitialized)
+    {
+        LLViewerShaderMgr::releaseInstance();
+        LLViewerShaderMgr::sInitialized = FALSE;
+    }
 }
 
 
 void LLViewerWindow::setCursor( ECursorType c )
 {
-	mWindow->setCursor( c );
+    mWindow->setCursor( c );
 }
 
 void LLViewerWindow::showCursor()
 {
-	mWindow->showCursor();
-	
-	mCursorHidden = FALSE;
+    mWindow->showCursor();
+
+    mCursorHidden = FALSE;
 }
 
 void LLViewerWindow::hideCursor()
 {
-	// And hide the cursor
-	mWindow->hideCursor();
+    // And hide the cursor
+    mWindow->hideCursor();
 
-	mCursorHidden = TRUE;
+    mCursorHidden = TRUE;
 }
 
 void LLViewerWindow::sendShapeToSim()
 {
-	LLMessageSystem* msg = gMessageSystem;
-	if(!msg) return;
-	msg->newMessageFast(_PREHASH_AgentHeightWidth);
-	msg->nextBlockFast(_PREHASH_AgentData);
-	msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-	msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
-	msg->addU32Fast(_PREHASH_CircuitCode, gMessageSystem->mOurCircuitCode);
-	msg->nextBlockFast(_PREHASH_HeightWidthBlock);
-	msg->addU32Fast(_PREHASH_GenCounter, 0);
-	U16 height16 = (U16) mWorldViewRectRaw.getHeight();
-	U16 width16 = (U16) mWorldViewRectRaw.getWidth();
-	msg->addU16Fast(_PREHASH_Height, height16);
-	msg->addU16Fast(_PREHASH_Width, width16);
-	gAgent.sendReliableMessage();
+    LLMessageSystem* msg = gMessageSystem;
+    if(!msg) return;
+    msg->newMessageFast(_PREHASH_AgentHeightWidth);
+    msg->nextBlockFast(_PREHASH_AgentData);
+    msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+    msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
+    msg->addU32Fast(_PREHASH_CircuitCode, gMessageSystem->mOurCircuitCode);
+    msg->nextBlockFast(_PREHASH_HeightWidthBlock);
+    msg->addU32Fast(_PREHASH_GenCounter, 0);
+    U16 height16 = (U16) mWorldViewRectRaw.getHeight();
+    U16 width16 = (U16) mWorldViewRectRaw.getWidth();
+    msg->addU16Fast(_PREHASH_Height, height16);
+    msg->addU16Fast(_PREHASH_Width, width16);
+    gAgent.sendReliableMessage();
 }
 
 // Must be called after window is created to set up agent
 // camera variables and UI variables.
 void LLViewerWindow::reshape(S32 width, S32 height)
 {
-	// Destroying the window at quit time generates spurious
-	// reshape messages.  We don't care about these, and we
-	// don't want to send messages because the message system
-	// may have been destructed.
-	if (!LLApp::isExiting())
-	{
-		gWindowResized = TRUE;
+    // Destroying the window at quit time generates spurious
+    // reshape messages.  We don't care about these, and we
+    // don't want to send messages because the message system
+    // may have been destructed.
+    if (!LLApp::isExiting())
+    {
+        gWindowResized = TRUE;
 
-		// update our window rectangle
-		mWindowRectRaw.mRight = mWindowRectRaw.mLeft + width;
-		mWindowRectRaw.mTop = mWindowRectRaw.mBottom + height;
+        // update our window rectangle
+        mWindowRectRaw.mRight = mWindowRectRaw.mLeft + width;
+        mWindowRectRaw.mTop = mWindowRectRaw.mBottom + height;
 
-		//glViewport(0, 0, width, height );
+        //glViewport(0, 0, width, height );
 
         LLViewerCamera * camera = LLViewerCamera::getInstance(); // simpleton, might not exist
-		if (height > 0 && camera)
-		{ 
+        if (height > 0 && camera)
+        {
             camera->setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
             camera->setAspect( getWorldViewAspectRatio() );
-		}
+        }
 
-		calcDisplayScale();
-	
-		BOOL display_scale_changed = mDisplayScale != LLUI::getScaleFactor();
-		LLUI::setScaleFactor(mDisplayScale);
+        calcDisplayScale();
 
-		// update our window rectangle
-		mWindowRectScaled.mRight = mWindowRectScaled.mLeft + ll_round((F32)width / mDisplayScale.mV[VX]);
-		mWindowRectScaled.mTop = mWindowRectScaled.mBottom + ll_round((F32)height / mDisplayScale.mV[VY]);
+        BOOL display_scale_changed = mDisplayScale != LLUI::getScaleFactor();
+        LLUI::setScaleFactor(mDisplayScale);
 
-		setup2DViewport();
+        // update our window rectangle
+        mWindowRectScaled.mRight = mWindowRectScaled.mLeft + ll_round((F32)width / mDisplayScale.mV[VX]);
+        mWindowRectScaled.mTop = mWindowRectScaled.mBottom + ll_round((F32)height / mDisplayScale.mV[VY]);
 
-		// Inform lower views of the change
-		// round up when converting coordinates to make sure there are no gaps at edge of window
-		LLView::sForceReshape = display_scale_changed;
-		mRootView->reshape(llceil((F32)width / mDisplayScale.mV[VX]), llceil((F32)height / mDisplayScale.mV[VY]));
+        setup2DViewport();
+
+        // Inform lower views of the change
+        // round up when converting coordinates to make sure there are no gaps at edge of window
+        LLView::sForceReshape = display_scale_changed;
+        mRootView->reshape(llceil((F32)width / mDisplayScale.mV[VX]), llceil((F32)height / mDisplayScale.mV[VY]));
         if (display_scale_changed)
         {
             // Needs only a 'scale change' update, everything else gets handled by LLLayoutStack::updateClass()
             LLPanelLogin::reshapePanel();
         }
-		LLView::sForceReshape = FALSE;
+        LLView::sForceReshape = FALSE;
 
-		// clear font width caches
-		if (display_scale_changed)
-		{
-			LLHUDObject::reshapeAll();
-		}
+        // clear font width caches
+        if (display_scale_changed)
+        {
+            LLHUDObject::reshapeAll();
+        }
 
-		sendShapeToSim();
+        sendShapeToSim();
 
-		// store new settings for the mode we are in, regardless
-		BOOL maximized = mWindow->getMaximized();
-		gSavedSettings.setBOOL("WindowMaximized", maximized);
+        // store new settings for the mode we are in, regardless
+        BOOL maximized = mWindow->getMaximized();
+        gSavedSettings.setBOOL("WindowMaximized", maximized);
 
-		if (!maximized)
-		{
-			U32 min_window_width=gSavedSettings.getU32("MinWindowWidth");
-			U32 min_window_height=gSavedSettings.getU32("MinWindowHeight");
-			// tell the OS specific window code about min window size
-			mWindow->setMinSize(min_window_width, min_window_height);
+        if (!maximized)
+        {
+            U32 min_window_width=gSavedSettings.getU32("MinWindowWidth");
+            U32 min_window_height=gSavedSettings.getU32("MinWindowHeight");
+            // tell the OS specific window code about min window size
+            mWindow->setMinSize(min_window_width, min_window_height);
 
-			LLCoordScreen window_rect;
-			if (!gNonInteractive && mWindow->getSize(&window_rect))
-			{
-			// Only save size if not maximized
-				gSavedSettings.setU32("WindowWidth", window_rect.mX);
-				gSavedSettings.setU32("WindowHeight", window_rect.mY);
-			}
-		}
+            LLCoordScreen window_rect;
+            if (!gNonInteractive && mWindow->getSize(&window_rect))
+            {
+            // Only save size if not maximized
+                gSavedSettings.setU32("WindowWidth", window_rect.mX);
+                gSavedSettings.setU32("WindowHeight", window_rect.mY);
+            }
+        }
 
-		sample(LLStatViewer::WINDOW_WIDTH, width);
-		sample(LLStatViewer::WINDOW_HEIGHT, height);
+        sample(LLStatViewer::WINDOW_WIDTH, width);
+        sample(LLStatViewer::WINDOW_HEIGHT, height);
 
-		LLLayoutStack::updateClass();
-	}
+        LLLayoutStack::updateClass();
+    }
 }
 
 
 // Hide normal UI when a logon fails
 void LLViewerWindow::setNormalControlsVisible( BOOL visible )
 {
-	if(LLChicletBar::instanceExists())
-	{
-		LLChicletBar::getInstance()->setVisible(visible);
-		LLChicletBar::getInstance()->setEnabled(visible);
-	}
-
-	if ( gMenuBarView )
-	{
-		gMenuBarView->setVisible( visible );
-		gMenuBarView->setEnabled( visible );
-
-		// ...and set the menu color appropriately.
-		setMenuBackgroundColor(gAgent.getGodLevel() > GOD_NOT, 
-			LLGridManager::getInstance()->isInSLBeta());
-	}
-        
-	if ( gStatusBar )
-	{
-		gStatusBar->setVisible( visible );	
-		gStatusBar->setEnabled( visible );	
-	}
-	
-	LLNavigationBar* navbarp = LLUI::getRootView()->findChild<LLNavigationBar>("navigation_bar");
-	if (navbarp)
-	{
-		// when it's time to show navigation bar we need to ensure that the user wants to see it
-		// i.e. ShowNavbarNavigationPanel option is true
-		navbarp->setVisible( visible && gSavedSettings.getBOOL("ShowNavbarNavigationPanel") );
-	}
+    if(LLChicletBar::instanceExists())
+    {
+        LLChicletBar::getInstance()->setVisible(visible);
+        LLChicletBar::getInstance()->setEnabled(visible);
+    }
+
+    if ( gMenuBarView )
+    {
+        gMenuBarView->setVisible( visible );
+        gMenuBarView->setEnabled( visible );
+
+        // ...and set the menu color appropriately.
+        setMenuBackgroundColor(gAgent.getGodLevel() > GOD_NOT,
+            LLGridManager::getInstance()->isInSLBeta());
+    }
+
+    if ( gStatusBar )
+    {
+        gStatusBar->setVisible( visible );
+        gStatusBar->setEnabled( visible );
+    }
+
+    LLNavigationBar* navbarp = LLUI::getRootView()->findChild<LLNavigationBar>("navigation_bar");
+    if (navbarp)
+    {
+        // when it's time to show navigation bar we need to ensure that the user wants to see it
+        // i.e. ShowNavbarNavigationPanel option is true
+        navbarp->setVisible( visible && gSavedSettings.getBOOL("ShowNavbarNavigationPanel") );
+    }
 }
 
 void LLViewerWindow::setMenuBackgroundColor(bool god_mode, bool dev_grid)
 {
     LLColor4 new_bg_color;
 
-	// god more important than project, proj more important than grid
-    if ( god_mode ) 
+    // god more important than project, proj more important than grid
+    if ( god_mode )
     {
-		new_bg_color = LLUIColorTable::instance().getColor("MenuBarGodBgColor");
+        new_bg_color = LLUIColorTable::instance().getColor("MenuBarGodBgColor");
     }
     else
     {
         new_bg_color = LLUIColorTable::instance().getColor("MenuBarBgColor");
     }
-    
+
     if(gMenuBarView)
     {
         gMenuBarView->setBackgroundColor( new_bg_color );
@@ -2861,145 +2861,145 @@ void LLViewerWindow::setMenuBackgroundColor(bool god_mode, bool dev_grid)
 void LLViewerWindow::drawDebugText()
 {
     gUIProgram.bind();
-	gGL.color4f(1,1,1,1);
-	gGL.pushMatrix();
-	gGL.pushUIMatrix();
-	{
-		// scale view by UI global scale factor and aspect ratio correction factor
-		gGL.scaleUI(mDisplayScale.mV[VX], mDisplayScale.mV[VY], 1.f);
-		mDebugText->draw();
-	}
-	gGL.popUIMatrix();
-	gGL.popMatrix();
+    gGL.color4f(1,1,1,1);
+    gGL.pushMatrix();
+    gGL.pushUIMatrix();
+    {
+        // scale view by UI global scale factor and aspect ratio correction factor
+        gGL.scaleUI(mDisplayScale.mV[VX], mDisplayScale.mV[VY], 1.f);
+        mDebugText->draw();
+    }
+    gGL.popUIMatrix();
+    gGL.popMatrix();
 
-	gGL.flush();
-	gUIProgram.unbind();
+    gGL.flush();
+    gUIProgram.unbind();
 }
 
 void LLViewerWindow::draw()
 {
-	
+
 //#if LL_DEBUG
-	LLView::sIsDrawing = TRUE;
+    LLView::sIsDrawing = TRUE;
 //#endif
-	stop_glerror();
-	
-	LLUI::setLineWidth(1.f);
-
-	LLUI::setLineWidth(1.f);
-	// Reset any left-over transforms
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	
-	gGL.loadIdentity();
-
-	//S32 screen_x, screen_y;
-
-	if (!LLPipeline::RenderUIBuffer)
-	{
-		LLView::sDirtyRect = getWindowRectScaled();
-	}
-
-	// HACK for timecode debugging
-	static const LLCachedControl<bool> display_timecode(gSavedSettings, "DisplayTimecode");
-	if (display_timecode)
-	{
-		// draw timecode block
-		std::string text;
-
-		gGL.loadIdentity();
-
-		microsecondsToTimecodeString(gFrameTime,text);
-		const LLFontGL* font = LLFontGL::getFontSansSerif();
-		font->renderUTF8(text, 0,
-						ll_round((getWindowWidthScaled()/2)-100.f),
-						ll_round((getWindowHeightScaled()-60.f)),
-			LLColor4( 1.f, 1.f, 1.f, 1.f ),
-			LLFontGL::LEFT, LLFontGL::TOP);
-	}
-
-	// Draw all nested UI views.
-	// No translation needed, this view is glued to 0,0
-
-	gUIProgram.bind();
+    stop_glerror();
+
+    LLUI::setLineWidth(1.f);
+
+    LLUI::setLineWidth(1.f);
+    // Reset any left-over transforms
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+
+    gGL.loadIdentity();
+
+    //S32 screen_x, screen_y;
+
+    if (!LLPipeline::RenderUIBuffer)
+    {
+        LLView::sDirtyRect = getWindowRectScaled();
+    }
+
+    // HACK for timecode debugging
+    static const LLCachedControl<bool> display_timecode(gSavedSettings, "DisplayTimecode");
+    if (display_timecode)
+    {
+        // draw timecode block
+        std::string text;
+
+        gGL.loadIdentity();
+
+        microsecondsToTimecodeString(gFrameTime,text);
+        const LLFontGL* font = LLFontGL::getFontSansSerif();
+        font->renderUTF8(text, 0,
+                        ll_round((getWindowWidthScaled()/2)-100.f),
+                        ll_round((getWindowHeightScaled()-60.f)),
+            LLColor4( 1.f, 1.f, 1.f, 1.f ),
+            LLFontGL::LEFT, LLFontGL::TOP);
+    }
+
+    // Draw all nested UI views.
+    // No translation needed, this view is glued to 0,0
+
+    gUIProgram.bind();
     gGL.color4f(1, 1, 1, 1);
 
-	gGL.pushMatrix();
-	LLUI::pushMatrix();
-	{
-		
-		// scale view by UI global scale factor and aspect ratio correction factor
-		gGL.scaleUI(mDisplayScale.mV[VX], mDisplayScale.mV[VY], 1.f);
-
-		LLVector2 old_scale_factor = LLUI::getScaleFactor();
-		// apply camera zoom transform (for high res screenshots)
-		F32 zoom_factor = LLViewerCamera::getInstance()->getZoomFactor();
-		S16 sub_region = LLViewerCamera::getInstance()->getZoomSubRegion();
-		if (zoom_factor > 1.f)
-		{
-			//decompose subregion number to x and y values
-			int pos_y = sub_region / llceil(zoom_factor);
-			int pos_x = sub_region - (pos_y*llceil(zoom_factor));
-			// offset for this tile
-			gGL.translatef((F32)getWindowWidthScaled() * -(F32)pos_x, 
-						(F32)getWindowHeightScaled() * -(F32)pos_y, 
-						0.f);
-			gGL.scalef(zoom_factor, zoom_factor, 1.f);
-			LLUI::getScaleFactor() *= zoom_factor;
-		}
-
-		// Draw tool specific overlay on world
-		LLToolMgr::getInstance()->getCurrentTool()->draw();
-
-		if( gAgentCamera.cameraMouselook() )
-		{
-			drawMouselookInstructions();
-			stop_glerror();
-		}
-
-		// Draw all nested UI views.
-		// No translation needed, this view is glued to 0,0
-		mRootView->draw();
-
-		if (LLView::sDebugRects)
-		{
-			gToolTipView->drawStickyRect();
-		}
-
-		// Draw optional on-top-of-everyone view
-		LLUICtrl* top_ctrl = gFocusMgr.getTopCtrl();
-		if (top_ctrl && top_ctrl->getVisible())
-		{
-			S32 screen_x, screen_y;
-			top_ctrl->localPointToScreen(0, 0, &screen_x, &screen_y);
-
-			gGL.matrixMode(LLRender::MM_MODELVIEW);
-			LLUI::pushMatrix();
-			LLUI::translate( (F32) screen_x, (F32) screen_y);
-			top_ctrl->draw();	
-			LLUI::popMatrix();
-		}
-
-
-		if( gShowOverlayTitle && !mOverlayTitle.empty() )
-		{
-			// Used for special titles such as "Second Life - Special E3 2003 Beta"
-			const S32 DIST_FROM_TOP = 20;
-			LLFontGL::getFontSansSerifBig()->renderUTF8(
-				mOverlayTitle, 0,
-				ll_round( getWindowWidthScaled() * 0.5f),
-				getWindowHeightScaled() - DIST_FROM_TOP,
-				LLColor4(1, 1, 1, 0.4f),
-				LLFontGL::HCENTER, LLFontGL::TOP);
-		}
-
-		LLUI::setScaleFactor(old_scale_factor);
-	}
-	LLUI::popMatrix();
-	gGL.popMatrix();
-
-	gUIProgram.unbind();
-
-	LLView::sIsDrawing = FALSE;
+    gGL.pushMatrix();
+    LLUI::pushMatrix();
+    {
+
+        // scale view by UI global scale factor and aspect ratio correction factor
+        gGL.scaleUI(mDisplayScale.mV[VX], mDisplayScale.mV[VY], 1.f);
+
+        LLVector2 old_scale_factor = LLUI::getScaleFactor();
+        // apply camera zoom transform (for high res screenshots)
+        F32 zoom_factor = LLViewerCamera::getInstance()->getZoomFactor();
+        S16 sub_region = LLViewerCamera::getInstance()->getZoomSubRegion();
+        if (zoom_factor > 1.f)
+        {
+            //decompose subregion number to x and y values
+            int pos_y = sub_region / llceil(zoom_factor);
+            int pos_x = sub_region - (pos_y*llceil(zoom_factor));
+            // offset for this tile
+            gGL.translatef((F32)getWindowWidthScaled() * -(F32)pos_x,
+                        (F32)getWindowHeightScaled() * -(F32)pos_y,
+                        0.f);
+            gGL.scalef(zoom_factor, zoom_factor, 1.f);
+            LLUI::getScaleFactor() *= zoom_factor;
+        }
+
+        // Draw tool specific overlay on world
+        LLToolMgr::getInstance()->getCurrentTool()->draw();
+
+        if( gAgentCamera.cameraMouselook() )
+        {
+            drawMouselookInstructions();
+            stop_glerror();
+        }
+
+        // Draw all nested UI views.
+        // No translation needed, this view is glued to 0,0
+        mRootView->draw();
+
+        if (LLView::sDebugRects)
+        {
+            gToolTipView->drawStickyRect();
+        }
+
+        // Draw optional on-top-of-everyone view
+        LLUICtrl* top_ctrl = gFocusMgr.getTopCtrl();
+        if (top_ctrl && top_ctrl->getVisible())
+        {
+            S32 screen_x, screen_y;
+            top_ctrl->localPointToScreen(0, 0, &screen_x, &screen_y);
+
+            gGL.matrixMode(LLRender::MM_MODELVIEW);
+            LLUI::pushMatrix();
+            LLUI::translate( (F32) screen_x, (F32) screen_y);
+            top_ctrl->draw();
+            LLUI::popMatrix();
+        }
+
+
+        if( gShowOverlayTitle && !mOverlayTitle.empty() )
+        {
+            // Used for special titles such as "Second Life - Special E3 2003 Beta"
+            const S32 DIST_FROM_TOP = 20;
+            LLFontGL::getFontSansSerifBig()->renderUTF8(
+                mOverlayTitle, 0,
+                ll_round( getWindowWidthScaled() * 0.5f),
+                getWindowHeightScaled() - DIST_FROM_TOP,
+                LLColor4(1, 1, 1, 0.4f),
+                LLFontGL::HCENTER, LLFontGL::TOP);
+        }
+
+        LLUI::setScaleFactor(old_scale_factor);
+    }
+    LLUI::popMatrix();
+    gGL.popMatrix();
+
+    gUIProgram.unbind();
+
+    LLView::sIsDrawing = FALSE;
 }
 
 // Takes a single keyup event, usually when UI is visible
@@ -3017,35 +3017,35 @@ BOOL LLViewerWindow::handleKeyUp(KEY key, MASK mask)
     LLFocusableElement* keyboard_focus = gFocusMgr.getKeyboardFocus();
 
     if (keyboard_focus
-		&& !(mask & (MASK_CONTROL | MASK_ALT))
-		&& !gFocusMgr.getKeystrokesOnly())
-	{
-		// We have keyboard focus, and it's not an accelerator
+        && !(mask & (MASK_CONTROL | MASK_ALT))
+        && !gFocusMgr.getKeystrokesOnly())
+    {
+        // We have keyboard focus, and it's not an accelerator
         if (keyboard_focus && keyboard_focus->wantsKeyUpKeyDown())
         {
             return keyboard_focus->handleKeyUp(key, mask, FALSE);
         }
         else if (key < 0x80)
-		{
-			// Not a special key, so likely (we hope) to generate a character.  Let it fall through to character handler first.
-			return (gFocusMgr.getKeyboardFocus() != NULL);
-		}
-	}
-
-	if (keyboard_focus)
-	{
-		if (keyboard_focus->handleKeyUp(key, mask, FALSE))
-		{
-			LL_DEBUGS() << "LLviewerWindow::handleKeyUp - in 'traverse up' - no loops seen... just called keyboard_focus->handleKeyUp an it returned true" << LL_ENDL;
+        {
+            // Not a special key, so likely (we hope) to generate a character.  Let it fall through to character handler first.
+            return (gFocusMgr.getKeyboardFocus() != NULL);
+        }
+    }
+
+    if (keyboard_focus)
+    {
+        if (keyboard_focus->handleKeyUp(key, mask, FALSE))
+        {
+            LL_DEBUGS() << "LLviewerWindow::handleKeyUp - in 'traverse up' - no loops seen... just called keyboard_focus->handleKeyUp an it returned true" << LL_ENDL;
 #if AL_VIEWER_EVENT_RECORDER
-			LLViewerEventRecorder::instance().logKeyEvent(key, mask);
+            LLViewerEventRecorder::instance().logKeyEvent(key, mask);
 #endif
-			return TRUE;
-		}
-		else {
-			LL_DEBUGS() << "LLviewerWindow::handleKeyUp - in 'traverse up' - no loops seen... just called keyboard_focus->handleKeyUp an it returned FALSE" << LL_ENDL;
-		}
-	}
+            return TRUE;
+        }
+        else {
+            LL_DEBUGS() << "LLviewerWindow::handleKeyUp - in 'traverse up' - no loops seen... just called keyboard_focus->handleKeyUp an it returned FALSE" << LL_ENDL;
+        }
+    }
 
     // Try for a new-format gesture
     if (LLGestureMgr::instance().triggerGestureRelease(key, mask))
@@ -3056,17 +3056,17 @@ BOOL LLViewerWindow::handleKeyUp(KEY key, MASK mask)
     }
     //Old format gestures do not support this, so no need to implement it.
 
-	// don't pass keys on to world when something in ui has focus
-	return gFocusMgr.childHasKeyboardFocus(mRootView)
-		|| LLMenuGL::getKeyboardMode()
-		|| (gMenuBarView && gMenuBarView->getHighlightedItem() && gMenuBarView->getHighlightedItem()->isActive());
+    // don't pass keys on to world when something in ui has focus
+    return gFocusMgr.childHasKeyboardFocus(mRootView)
+        || LLMenuGL::getKeyboardMode()
+        || (gMenuBarView && gMenuBarView->getHighlightedItem() && gMenuBarView->getHighlightedItem()->isActive());
 }
 
 // Takes a single keydown event, usually when UI is visible
 BOOL LLViewerWindow::handleKey(KEY key, MASK mask)
 {
-	// hide tooltips on keypress
-	LLToolTipMgr::instance().blockToolTips();
+    // hide tooltips on keypress
+    LLToolTipMgr::instance().blockToolTips();
 
     // Menus get handled on key down instead of key up
     // so keybindings have to be recorded before that
@@ -3080,7 +3080,7 @@ BOOL LLViewerWindow::handleKey(KEY key, MASK mask)
     }
 
     LLFocusableElement* keyboard_focus = gFocusMgr.getKeyboardFocus();
-    
+
     if (keyboard_focus
         && !gFocusMgr.getKeystrokesOnly())
     {
@@ -3155,336 +3155,281 @@ BOOL LLViewerWindow::handleKey(KEY key, MASK mask)
         }
     }
 
-	// let menus handle navigation keys for navigation
-	if ((gMenuBarView && gMenuBarView->handleKey(key, mask, TRUE))
-		||(gLoginMenuBarView && gLoginMenuBarView->handleKey(key, mask, TRUE))
-		||(gMenuHolder && gMenuHolder->handleKey(key, mask, TRUE)))
-	{
-		LL_DEBUGS() << "LLviewerWindow::handleKey handle nav keys for nav" << LL_ENDL;
+    // let menus handle navigation keys for navigation
+    if ((gMenuBarView && gMenuBarView->handleKey(key, mask, TRUE))
+        ||(gLoginMenuBarView && gLoginMenuBarView->handleKey(key, mask, TRUE))
+        ||(gMenuHolder && gMenuHolder->handleKey(key, mask, TRUE)))
+    {
+        LL_DEBUGS() << "LLviewerWindow::handleKey handle nav keys for nav" << LL_ENDL;
 #if AL_VIEWER_EVENT_RECORDER
-		LLViewerEventRecorder::instance().logKeyEvent(key,mask);
+        LLViewerEventRecorder::instance().logKeyEvent(key,mask);
 #endif
-		return TRUE;
-	}
-
-
-	// give menus a chance to handle modified (Ctrl, Alt) shortcut keys before current focus 
-	// as long as focus isn't locked
-	if (mask & (MASK_CONTROL | MASK_ALT) && !gFocusMgr.focusLocked())
-	{
-		// Check the current floater's menu first, if it has one.
-		if (gFocusMgr.keyboardFocusHasAccelerators()
-			&& keyboard_focus 
-			&& keyboard_focus->handleKey(key,mask,FALSE))
-		{
+        return TRUE;
+    }
+
+
+    // give menus a chance to handle modified (Ctrl, Alt) shortcut keys before current focus
+    // as long as focus isn't locked
+    if (mask & (MASK_CONTROL | MASK_ALT) && !gFocusMgr.focusLocked())
+    {
+        // Check the current floater's menu first, if it has one.
+        if (gFocusMgr.keyboardFocusHasAccelerators()
+            && keyboard_focus
+            && keyboard_focus->handleKey(key,mask,FALSE))
+        {
 #if AL_VIEWER_EVENT_RECORDER
-			LLViewerEventRecorder::instance().logKeyEvent(key,mask);
+            LLViewerEventRecorder::instance().logKeyEvent(key,mask);
 #endif
-			return TRUE;
-		}
-
-		if (gAgent.isInitialized()
-			&& (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE || gAgent.getTeleportState() == LLAgent::TELEPORT_LOCAL)
-			&& gMenuBarView
-			&& gMenuBarView->handleAcceleratorKey(key, mask))
-		{
+            return TRUE;
+        }
+
+        if (gAgent.isInitialized()
+            && (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE || gAgent.getTeleportState() == LLAgent::TELEPORT_LOCAL)
+            && gMenuBarView
+            && gMenuBarView->handleAcceleratorKey(key, mask))
+        {
 #if AL_VIEWER_EVENT_RECORDER
-			LLViewerEventRecorder::instance().logKeyEvent(key, mask);
+            LLViewerEventRecorder::instance().logKeyEvent(key, mask);
 #endif
-			return TRUE;
-		}
+            return TRUE;
+        }
 
-		if (gLoginMenuBarView && gLoginMenuBarView->handleAcceleratorKey(key, mask))
-		{
+        if (gLoginMenuBarView && gLoginMenuBarView->handleAcceleratorKey(key, mask))
+        {
 #if AL_VIEWER_EVENT_RECORDER
-			LLViewerEventRecorder::instance().logKeyEvent(key,mask);
+            LLViewerEventRecorder::instance().logKeyEvent(key,mask);
 #endif
-			return TRUE;
-		}
-	}
+            return TRUE;
+        }
+    }
 
-	// give floaters first chance to handle TAB key
-	// so frontmost floater gets focus
-	// if nothing has focus, go to first or last UI element as appropriate
+    // give floaters first chance to handle TAB key
+    // so frontmost floater gets focus
+    // if nothing has focus, go to first or last UI element as appropriate
     if (key == KEY_TAB && (mask & MASK_CONTROL || keyboard_focus == NULL))
-	{
-		LL_WARNS() << "LLviewerWindow::handleKey give floaters first chance at tab key " << LL_ENDL;
-		if (gMenuHolder) gMenuHolder->hideMenus();
-
-		// if CTRL-tabbing (and not just TAB with no focus), go into window cycle mode
-		gFloaterView->setCycleMode((mask & MASK_CONTROL) != 0);
-
-		// do CTRL-TAB and CTRL-SHIFT-TAB logic
-		if (mask & MASK_SHIFT)
-		{
-			mRootView->focusPrevRoot();
-		}
-		else
-		{
-			mRootView->focusNextRoot();
-		}
+    {
+        LL_WARNS() << "LLviewerWindow::handleKey give floaters first chance at tab key " << LL_ENDL;
+        if (gMenuHolder) gMenuHolder->hideMenus();
+
+        // if CTRL-tabbing (and not just TAB with no focus), go into window cycle mode
+        gFloaterView->setCycleMode((mask & MASK_CONTROL) != 0);
+
+        // do CTRL-TAB and CTRL-SHIFT-TAB logic
+        if (mask & MASK_SHIFT)
+        {
+            mRootView->focusPrevRoot();
+        }
+        else
+        {
+            mRootView->focusNextRoot();
+        }
 #if AL_VIEWER_EVENT_RECORDER
-		LLViewerEventRecorder::instance().logKeyEvent(key,mask);
+        LLViewerEventRecorder::instance().logKeyEvent(key,mask);
 #endif
-		return TRUE;
-	}
-	// hidden edit menu for cut/copy/paste
-	if (gEditMenu && gEditMenu->handleAcceleratorKey(key, mask))
-	{
+        return TRUE;
+    }
+    // hidden edit menu for cut/copy/paste
+    if (gEditMenu && gEditMenu->handleAcceleratorKey(key, mask))
+    {
 #if AL_VIEWER_EVENT_RECORDER
-		LLViewerEventRecorder::instance().logKeyEvent(key,mask);
+        LLViewerEventRecorder::instance().logKeyEvent(key,mask);
 #endif
-		return TRUE;
-	}
-
-	LLFloater* focused_floaterp = gFloaterView->getFocusedFloater();
-	const std::string& focusedFloaterName = (focused_floaterp ? focused_floaterp->getInstanceName() : LLStringUtil::null);
-
-	if( keyboard_focus )
-	{
-		if ((focusedFloaterName == "chatbar") || (focusedFloaterName == "nearby_chat") || (focusedFloaterName == "im_container") || (focusedFloaterName == "impanel"))
-		{
-			if (gSavedSettings.getBOOL("ArrowKeysAlwaysMove"))
-			{
-				// let Control-Up and Control-Down through for chat line history,
-				if (!(key == KEY_UP && mask == MASK_CONTROL)
-					&& !(key == KEY_DOWN && mask == MASK_CONTROL)
-					&& !(key == KEY_UP && mask == MASK_ALT)
-					&& !(key == KEY_DOWN && mask == MASK_ALT))
-				{
-					switch(key)
-					{
-					case KEY_LEFT:
-					case KEY_RIGHT:
-					case KEY_UP:
-					case KEY_DOWN:
-					case KEY_PAGE_UP:
-					case KEY_PAGE_DOWN:
-					case KEY_HOME:
-					case KEY_END:
-						// when chatbar is empty or ArrowKeysAlwaysMove set,
-						// pass arrow keys on to avatar...
-						return FALSE;
-					default:
-						break;
-					}
-				}
-		}
-		}
-
-		if (keyboard_focus->handleKey(key, mask, FALSE))
-		{
-
-			LL_DEBUGS() << "LLviewerWindow::handleKey - in 'traverse up' - no loops seen... just called keyboard_focus->handleKey an it returned true" << LL_ENDL;
+        return TRUE;
+    }
+
+    LLFloater* focused_floaterp = gFloaterView->getFocusedFloater();
+    const std::string& focusedFloaterName = (focused_floaterp ? focused_floaterp->getInstanceName() : LLStringUtil::null);
+
+    if( keyboard_focus )
+    {
+        if ((focusedFloaterName == "chatbar") || (focusedFloaterName == "nearby_chat") || (focusedFloaterName == "im_container") || (focusedFloaterName == "impanel"))
+        {
+            if (gSavedSettings.getBOOL("ArrowKeysAlwaysMove"))
+            {
+                // let Control-Up and Control-Down through for chat line history,
+                if (!(key == KEY_UP && mask == MASK_CONTROL)
+                    && !(key == KEY_DOWN && mask == MASK_CONTROL)
+                    && !(key == KEY_UP && mask == MASK_ALT)
+                    && !(key == KEY_DOWN && mask == MASK_ALT))
+                {
+                    switch(key)
+                    {
+                    case KEY_LEFT:
+                    case KEY_RIGHT:
+                    case KEY_UP:
+                    case KEY_DOWN:
+                    case KEY_PAGE_UP:
+                    case KEY_PAGE_DOWN:
+                    case KEY_HOME:
+                    case KEY_END:
+                        // when chatbar is empty or ArrowKeysAlwaysMove set,
+                        // pass arrow keys on to avatar...
+                        return FALSE;
+                    default:
+                        break;
+                    }
+                }
+        }
+        }
+
+        if (keyboard_focus->handleKey(key, mask, FALSE))
+        {
+
+            LL_DEBUGS() << "LLviewerWindow::handleKey - in 'traverse up' - no loops seen... just called keyboard_focus->handleKey an it returned true" << LL_ENDL;
 #if AL_VIEWER_EVENT_RECORDER
-			LLViewerEventRecorder::instance().logKeyEvent(key,mask); 
+            LLViewerEventRecorder::instance().logKeyEvent(key,mask);
 #endif
-			return TRUE;
-		} else {
-			LL_DEBUGS() << "LLviewerWindow::handleKey - in 'traverse up' - no loops seen... just called keyboard_focus->handleKey an it returned FALSE" << LL_ENDL;
-		}
-	}
-
-	if( LLToolMgr::getInstance()->getCurrentTool()->handleKey(key, mask) )
-	{
-		LL_DEBUGS() << "LLviewerWindow::handleKey toolbar handling?" << LL_ENDL;
+            return TRUE;
+        } else {
+            LL_DEBUGS() << "LLviewerWindow::handleKey - in 'traverse up' - no loops seen... just called keyboard_focus->handleKey an it returned FALSE" << LL_ENDL;
+        }
+    }
+
+    if( LLToolMgr::getInstance()->getCurrentTool()->handleKey(key, mask) )
+    {
+        LL_DEBUGS() << "LLviewerWindow::handleKey toolbar handling?" << LL_ENDL;
 #if AL_VIEWER_EVENT_RECORDER
-		LLViewerEventRecorder::instance().logKeyEvent(key,mask);
+        LLViewerEventRecorder::instance().logKeyEvent(key,mask);
 #endif
-		return TRUE;
-	}
+        return TRUE;
+    }
 
-	// Try for a new-format gesture
-	if (LLGestureMgr::instance().triggerGesture(key, mask))
-	{
-		LL_DEBUGS() << "LLviewerWindow::handleKey new gesture feature" << LL_ENDL;
+    // Try for a new-format gesture
+    if (LLGestureMgr::instance().triggerGesture(key, mask))
+    {
+        LL_DEBUGS() << "LLviewerWindow::handleKey new gesture feature" << LL_ENDL;
 #if AL_VIEWER_EVENT_RECORDER
-		LLViewerEventRecorder::instance().logKeyEvent(key,mask);
+        LLViewerEventRecorder::instance().logKeyEvent(key,mask);
 #endif
-		return TRUE;
-	}
-
-	// See if this is a gesture trigger.  If so, eat the key and
-	// don't pass it down to the menus.
-	if (gGestureList.trigger(key, mask))
-	{
-		LL_DEBUGS() << "LLviewerWindow::handleKey check gesture trigger" << LL_ENDL;
+        return TRUE;
+    }
+
+    // See if this is a gesture trigger.  If so, eat the key and
+    // don't pass it down to the menus.
+    if (gGestureList.trigger(key, mask))
+    {
+        LL_DEBUGS() << "LLviewerWindow::handleKey check gesture trigger" << LL_ENDL;
 #if AL_VIEWER_EVENT_RECORDER
-		LLViewerEventRecorder::instance().logKeyEvent(key,mask);
+        LLViewerEventRecorder::instance().logKeyEvent(key,mask);
 #endif
-		return TRUE;
-	}
-
-	// If "Pressing letter keys starts local chat" option is selected, we are not in mouselook, 
-	// no view has keyboard focus, this is a printable character key (and no modifier key is 
-	// pressed except shift), then give focus to nearby chat (STORM-560)
-	static const LLCachedControl<bool> letter_keys_Focus_chat_bar(gSavedSettings, "LetterKeysFocusChatBar");
-	if ( LLStartUp::getStartupState() >= STATE_STARTED && 
-		letter_keys_Focus_chat_bar && !gAgentCamera.cameraMouselook() &&
-		!keyboard_focus && key < 0x80 && (mask == MASK_NONE || mask == MASK_SHIFT) )
-	{
+        return TRUE;
+    }
+
+    // If "Pressing letter keys starts local chat" option is selected, we are not in mouselook,
+    // no view has keyboard focus, this is a printable character key (and no modifier key is
+    // pressed except shift), then give focus to nearby chat (STORM-560)
+    static const LLCachedControl<bool> letter_keys_Focus_chat_bar(gSavedSettings, "LetterKeysFocusChatBar");
+    if ( LLStartUp::getStartupState() >= STATE_STARTED &&
+        letter_keys_Focus_chat_bar && !gAgentCamera.cameraMouselook() &&
+        !keyboard_focus && key < 0x80 && (mask == MASK_NONE || mask == MASK_SHIFT) )
+    {
         static LLCachedControl<bool> sChatInWindow(gSavedSettings, "AlchemyNearbyChatInput", true);
-		if (!sChatInWindow)
-		{
-			// Initialize nearby chat if it's missing
-			LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::findTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
-			if (!nearby_chat)
-			{
-				LLSD name("im_container");
-				LLFloaterReg::toggleInstanceOrBringToFront(name);
-			}
-			
-			LLChatEntry* chat_editor = nearby_chat ? nearby_chat->getChatBox() : nullptr; 
-			if (chat_editor)
-			{
-				// passing NULL here, character will be added later when it is handled by character handler.
-				nearby_chat->startChat(nullptr);
-				return TRUE;
-			}
-		}
-		else
-		{
-			LLChatBar* chat_bar = LLFloaterReg::findTypedInstance<LLChatBar>("chatbar");
-			if (!chat_bar)
-				LLFloaterReg::toggleInstanceOrBringToFront("chatbar");
-			
-			LLChatBar::startChat(nullptr);
-			return TRUE;
-		}
-	}
-
-	// give menus a chance to handle unmodified accelerator keys
-	if (gAgent.isInitialized()
-		&& (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE || gAgent.getTeleportState() == LLAgent::TELEPORT_LOCAL)
-		&& gMenuBarView
-		&& gMenuBarView->handleAcceleratorKey(key, mask))
-	{
+        if (!sChatInWindow)
+        {
+            // Initialize nearby chat if it's missing
+            LLFloaterIMNearbyChat* nearby_chat = LLFloaterReg::findTypedInstance<LLFloaterIMNearbyChat>("nearby_chat");
+            if (!nearby_chat)
+            {
+                LLSD name("im_container");
+                LLFloaterReg::toggleInstanceOrBringToFront(name);
+            }
+
+            LLChatEntry* chat_editor = nearby_chat ? nearby_chat->getChatBox() : nullptr;
+            if (chat_editor)
+            {
+                // passing NULL here, character will be added later when it is handled by character handler.
+                nearby_chat->startChat(nullptr);
+                return TRUE;
+            }
+        }
+        else
+        {
+            LLChatBar* chat_bar = LLFloaterReg::findTypedInstance<LLChatBar>("chatbar");
+            if (!chat_bar)
+                LLFloaterReg::toggleInstanceOrBringToFront("chatbar");
+
+            LLChatBar::startChat(nullptr);
+            return TRUE;
+        }
+    }
+
+    // give menus a chance to handle unmodified accelerator keys
+    if (gAgent.isInitialized()
+        && (gAgent.getTeleportState() == LLAgent::TELEPORT_NONE || gAgent.getTeleportState() == LLAgent::TELEPORT_LOCAL)
+        && gMenuBarView
+        && gMenuBarView->handleAcceleratorKey(key, mask))
+    {
 #if AL_VIEWER_EVENT_RECORDER
-		LLViewerEventRecorder::instance().logKeyEvent(key, mask);
+        LLViewerEventRecorder::instance().logKeyEvent(key, mask);
 #endif
-		return TRUE;
-	}
+        return TRUE;
+    }
 
-	if (gLoginMenuBarView && gLoginMenuBarView->handleAcceleratorKey(key, mask))
-	{
-		return TRUE;
-	}
+    if (gLoginMenuBarView && gLoginMenuBarView->handleAcceleratorKey(key, mask))
+    {
+        return TRUE;
+    }
 
-	// don't pass keys on to world when something in ui has focus
-	return gFocusMgr.childHasKeyboardFocus(mRootView) 
-		|| LLMenuGL::getKeyboardMode() 
-		|| (gMenuBarView && gMenuBarView->getHighlightedItem() && gMenuBarView->getHighlightedItem()->isActive());
+    // don't pass keys on to world when something in ui has focus
+    return gFocusMgr.childHasKeyboardFocus(mRootView)
+        || LLMenuGL::getKeyboardMode()
+        || (gMenuBarView && gMenuBarView->getHighlightedItem() && gMenuBarView->getHighlightedItem()->isActive());
 }
 
 
 BOOL LLViewerWindow::handleUnicodeChar(llwchar uni_char, MASK mask)
 {
-	// HACK:  We delay processing of return keys until they arrive as a Unicode char,
-	// so that if you're typing chat text at low frame rate, we don't send the chat
-	// until all keystrokes have been entered. JC
-	// HACK: Numeric keypad <enter> on Mac is Unicode 3
-	// HACK: Control-M on Windows is Unicode 13
-	if ((uni_char == 13 && mask != MASK_CONTROL && mask != MASK_SHIFT)
-	    || (uni_char == 3 && mask == MASK_NONE) )
-	{
-		if (mask != MASK_ALT)
-		{
-			// remaps, handles ignored cases and returns back to viewer window.
-			return gViewerInput.handleKey(KEY_RETURN, mask, gKeyboard->getKeyRepeated(KEY_RETURN));
-		}
-	}
-
-	// let menus handle navigation (jump) keys
-	if (gMenuBarView && gMenuBarView->handleUnicodeChar(uni_char, TRUE))
-	{
-		return TRUE;
-	}
-
-	// Traverses up the hierarchy
-	LLFocusableElement* keyboard_focus = gFocusMgr.getKeyboardFocus();
-	if( keyboard_focus )
-	{
-		if (keyboard_focus->handleUnicodeChar(uni_char, FALSE))
-		{
-			return TRUE;
-		}
+    // HACK:  We delay processing of return keys until they arrive as a Unicode char,
+    // so that if you're typing chat text at low frame rate, we don't send the chat
+    // until all keystrokes have been entered. JC
+    // HACK: Numeric keypad <enter> on Mac is Unicode 3
+    // HACK: Control-M on Windows is Unicode 13
+    if ((uni_char == 13 && mask != MASK_CONTROL && mask != MASK_SHIFT)
+        || (uni_char == 3 && mask == MASK_NONE) )
+    {
+        if (mask != MASK_ALT)
+        {
+            // remaps, handles ignored cases and returns back to viewer window.
+            return gViewerInput.handleKey(KEY_RETURN, mask, gKeyboard->getKeyRepeated(KEY_RETURN));
+        }
+    }
 
+    // let menus handle navigation (jump) keys
+    if (gMenuBarView && gMenuBarView->handleUnicodeChar(uni_char, TRUE))
+    {
         return TRUE;
-	}
+    }
 
-	return FALSE;
-}
+    // Traverses up the hierarchy
+    LLFocusableElement* keyboard_focus = gFocusMgr.getKeyboardFocus();
+    if( keyboard_focus )
+    {
+        if (keyboard_focus->handleUnicodeChar(uni_char, FALSE))
+        {
+            return TRUE;
+        }
 
+        return TRUE;
+    }
 
-void LLViewerWindow::handleScrollWheel(S32 clicks)
-{
-	LLUI::resetMouseIdleTimer();
-	
-	LLMouseHandler* mouse_captor = gFocusMgr.getMouseCapture();
-	if( mouse_captor )
-	{
-		S32 local_x;
-		S32 local_y;
-		mouse_captor->screenPointToLocal( mCurrentMousePoint.mX, mCurrentMousePoint.mY, &local_x, &local_y );
-		mouse_captor->handleScrollWheel(local_x, local_y, clicks);
-		if (LLView::sDebugMouseHandling)
-		{
-			LL_INFOS() << "Scroll Wheel handled by captor " << mouse_captor->getName() << LL_ENDL;
-		}
-		return;
-	}
-
-	LLUICtrl* top_ctrl = gFocusMgr.getTopCtrl();
-	if (top_ctrl)
-	{
-		S32 local_x;
-		S32 local_y;
-		top_ctrl->screenPointToLocal( mCurrentMousePoint.mX, mCurrentMousePoint.mY, &local_x, &local_y );
-		if (top_ctrl->handleScrollWheel(local_x, local_y, clicks)) return;
-	}
-
-	if (mRootView->handleScrollWheel(mCurrentMousePoint.mX, mCurrentMousePoint.mY, clicks) )
-	{
-		if (LLView::sDebugMouseHandling)
-		{
-			LL_INFOS() << "Scroll Wheel" << LLView::sMouseHandlerMessage << LL_ENDL;
-		}
-		return;
-	}
-	else if (LLView::sDebugMouseHandling)
-	{
-		LL_INFOS() << "Scroll Wheel not handled by view" << LL_ENDL;
-	}
-
-	// Zoom the camera in and out behavior
-
-	if(top_ctrl == 0 
-		&& getWorldViewRectScaled().pointInRect(mCurrentMousePoint.mX, mCurrentMousePoint.mY) 
-		&& gAgentCamera.isInitialized())
-		gAgentCamera.handleScrollWheel(clicks);
-
-	return;
+    return FALSE;
 }
 
-void LLViewerWindow::handleScrollHWheel(S32 clicks)
+
+void LLViewerWindow::handleScrollWheel(S32 clicks)
 {
-    if (LLAppViewer::instance()->quitRequested())
-    {
-        return;
-    }
-    
     LLUI::resetMouseIdleTimer();
 
     LLMouseHandler* mouse_captor = gFocusMgr.getMouseCapture();
-    if (mouse_captor)
+    if( mouse_captor )
     {
         S32 local_x;
         S32 local_y;
-        mouse_captor->screenPointToLocal(mCurrentMousePoint.mX, mCurrentMousePoint.mY, &local_x, &local_y);
-        mouse_captor->handleScrollHWheel(local_x, local_y, clicks);
+        mouse_captor->screenPointToLocal( mCurrentMousePoint.mX, mCurrentMousePoint.mY, &local_x, &local_y );
+        mouse_captor->handleScrollWheel(local_x, local_y, clicks);
         if (LLView::sDebugMouseHandling)
         {
-            LL_INFOS() << "Scroll Horizontal Wheel handled by captor " << mouse_captor->getName() << LL_ENDL;
+            LL_INFOS() << "Scroll Wheel handled by captor " << mouse_captor->getName() << LL_ENDL;
         }
         return;
     }
@@ -3494,65 +3439,120 @@ void LLViewerWindow::handleScrollHWheel(S32 clicks)
     {
         S32 local_x;
         S32 local_y;
-        top_ctrl->screenPointToLocal(mCurrentMousePoint.mX, mCurrentMousePoint.mY, &local_x, &local_y);
-        if (top_ctrl->handleScrollHWheel(local_x, local_y, clicks)) return;
+        top_ctrl->screenPointToLocal( mCurrentMousePoint.mX, mCurrentMousePoint.mY, &local_x, &local_y );
+        if (top_ctrl->handleScrollWheel(local_x, local_y, clicks)) return;
     }
 
-    if (mRootView->handleScrollHWheel(mCurrentMousePoint.mX, mCurrentMousePoint.mY, clicks))
+    if (mRootView->handleScrollWheel(mCurrentMousePoint.mX, mCurrentMousePoint.mY, clicks) )
     {
         if (LLView::sDebugMouseHandling)
         {
-            LL_INFOS() << "Scroll Horizontal Wheel" << LLView::sMouseHandlerMessage << LL_ENDL;
+            LL_INFOS() << "Scroll Wheel" << LLView::sMouseHandlerMessage << LL_ENDL;
         }
         return;
     }
     else if (LLView::sDebugMouseHandling)
     {
-        LL_INFOS() << "Scroll Horizontal Wheel not handled by view" << LL_ENDL;
+        LL_INFOS() << "Scroll Wheel not handled by view" << LL_ENDL;
     }
 
+    // Zoom the camera in and out behavior
+
+    if(top_ctrl == 0
+        && getWorldViewRectScaled().pointInRect(mCurrentMousePoint.mX, mCurrentMousePoint.mY)
+        && gAgentCamera.isInitialized())
+        gAgentCamera.handleScrollWheel(clicks);
+
     return;
 }
 
-void LLViewerWindow::addPopup(LLView* popup)
+void LLViewerWindow::handleScrollHWheel(S32 clicks)
+{
+    if (LLAppViewer::instance()->quitRequested())
+    {
+        return;
+    }
+
+    LLUI::resetMouseIdleTimer();
+
+    LLMouseHandler* mouse_captor = gFocusMgr.getMouseCapture();
+    if (mouse_captor)
+    {
+        S32 local_x;
+        S32 local_y;
+        mouse_captor->screenPointToLocal(mCurrentMousePoint.mX, mCurrentMousePoint.mY, &local_x, &local_y);
+        mouse_captor->handleScrollHWheel(local_x, local_y, clicks);
+        if (LLView::sDebugMouseHandling)
+        {
+            LL_INFOS() << "Scroll Horizontal Wheel handled by captor " << mouse_captor->getName() << LL_ENDL;
+        }
+        return;
+    }
+
+    LLUICtrl* top_ctrl = gFocusMgr.getTopCtrl();
+    if (top_ctrl)
+    {
+        S32 local_x;
+        S32 local_y;
+        top_ctrl->screenPointToLocal(mCurrentMousePoint.mX, mCurrentMousePoint.mY, &local_x, &local_y);
+        if (top_ctrl->handleScrollHWheel(local_x, local_y, clicks)) return;
+    }
+
+    if (mRootView->handleScrollHWheel(mCurrentMousePoint.mX, mCurrentMousePoint.mY, clicks))
+    {
+        if (LLView::sDebugMouseHandling)
+        {
+            LL_INFOS() << "Scroll Horizontal Wheel" << LLView::sMouseHandlerMessage << LL_ENDL;
+        }
+        return;
+    }
+    else if (LLView::sDebugMouseHandling)
+    {
+        LL_INFOS() << "Scroll Horizontal Wheel not handled by view" << LL_ENDL;
+    }
+
+    return;
+}
+
+void LLViewerWindow::addPopup(LLView* popup)
 {
-	if (mPopupView)
-	{
-		mPopupView->addPopup(popup);
-	}
+    if (mPopupView)
+    {
+        mPopupView->addPopup(popup);
+    }
 }
 
 void LLViewerWindow::removePopup(LLView* popup)
 {
-	if (mPopupView)
-	{
-		mPopupView->removePopup(popup);
-	}
+    if (mPopupView)
+    {
+        mPopupView->removePopup(popup);
+    }
 }
 
 void LLViewerWindow::clearPopups()
 {
-	if (mPopupView)
-	{
-		mPopupView->clearPopups();
-	}
+    if (mPopupView)
+    {
+        mPopupView->clearPopups();
+    }
 }
 
 void LLViewerWindow::moveCursorToCenter()
 {
-	static LLCachedControl<bool> disable_mouse_warp(gSavedSettings, "DisableMouseWarp");
-	if (!disable_mouse_warp)
-	{
-		S32 x = getWorldViewWidthScaled() / 2;
-		S32 y = getWorldViewHeightScaled() / 2;
-	
-		LLUI::setMousePositionScreen(x, y);
-		
-		//on a forced move, all deltas get zeroed out to prevent jumping
-		mCurrentMousePoint.set(x,y);
-		mLastMousePoint.set(x,y);
-		mCurrentMouseDelta.set(0,0);	
-	}
+    static LLCachedControl<bool> disable_mouse_warp(gSavedSettings, "DisableMouseWarp");
+    if (!disable_mouse_warp)
+    {
+        S32 x = getWorldViewWidthScaled() / 2;
+        S32 y = getWorldViewHeightScaled() / 2;
+
+        LLUI::setMousePositionScreen(x, y);
+
+        //on a forced move, all deltas get zeroed out to prevent jumping
+        mCurrentMousePoint.set(x,y);
+        mLastMousePoint.set(x,y);
+        mCurrentMouseDelta.set(0,0);
+    }
 }
 
 
@@ -3563,32 +3563,32 @@ void LLViewerWindow::moveCursorToCenter()
 
 void append_xui_tooltip(LLView* viewp, LLToolTip::Params& params)
 {
-	if (viewp) 
-	{
-		if (!params.styled_message.empty())
-		{
-			params.styled_message.add().text("\n---------\n"); 
-		}
-		LLView::root_to_view_iterator_t end_tooltip_it = viewp->endRootToView();
-		// NOTE: we skip "root" since it is assumed
-		for (LLView::root_to_view_iterator_t tooltip_it = ++viewp->beginRootToView();
-			tooltip_it != end_tooltip_it;
-			++tooltip_it)
-		{
-			LLView* viewp = *tooltip_it;
-		
-			params.styled_message.add().text(viewp->getName());
-
-			LLPanel* panelp = dynamic_cast<LLPanel*>(viewp);
-			if (panelp && !panelp->getXMLFilename().empty())
-			{
-				params.styled_message.add()
-					.text("(" + panelp->getXMLFilename() + ")")
-					.style.color(LLColor4(0.7f, 0.7f, 1.f, 1.f));
-			}
-			params.styled_message.add().text("/");
-		}
-	}
+    if (viewp)
+    {
+        if (!params.styled_message.empty())
+        {
+            params.styled_message.add().text("\n---------\n");
+        }
+        LLView::root_to_view_iterator_t end_tooltip_it = viewp->endRootToView();
+        // NOTE: we skip "root" since it is assumed
+        for (LLView::root_to_view_iterator_t tooltip_it = ++viewp->beginRootToView();
+            tooltip_it != end_tooltip_it;
+            ++tooltip_it)
+        {
+            LLView* viewp = *tooltip_it;
+
+            params.styled_message.add().text(viewp->getName());
+
+            LLPanel* panelp = dynamic_cast<LLPanel*>(viewp);
+            if (panelp && !panelp->getXMLFilename().empty())
+            {
+                params.styled_message.add()
+                    .text("(" + panelp->getXMLFilename() + ")")
+                    .style.color(LLColor4(0.7f, 0.7f, 1.f, 1.f));
+            }
+            params.styled_message.add().text("/");
+        }
+    }
 }
 
 static LLTrace::BlockTimerStatHandle FTM_UPDATE_UI("Update UI");
@@ -3597,980 +3597,980 @@ static LLTrace::BlockTimerStatHandle FTM_UPDATE_UI("Update UI");
 // event processing.
 void LLViewerWindow::updateUI()
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_UI; //LL_RECORD_BLOCK_TIME(ftm);
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_UI; //LL_RECORD_BLOCK_TIME(ftm);
 
-	static std::string last_handle_msg;
+    static std::string last_handle_msg;
 
-	if (gLoggedInTime.getStarted())
-	{
+    if (gLoggedInTime.getStarted())
+    {
         const F32 DESTINATION_GUIDE_HINT_TIMEOUT = 1200.f;
         const F32 SIDE_PANEL_HINT_TIMEOUT = 300.f;
         if (gLoggedInTime.getElapsedTimeF32() > DESTINATION_GUIDE_HINT_TIMEOUT)
-		{
-			LLFirstUse::notUsingDestinationGuide();
-		}
+        {
+            LLFirstUse::notUsingDestinationGuide();
+        }
         if (gLoggedInTime.getElapsedTimeF32() > SIDE_PANEL_HINT_TIMEOUT)
-		{
-			LLFirstUse::notUsingSidePanel();
-		}
-	}
+        {
+            LLFirstUse::notUsingSidePanel();
+        }
+    }
 
-	LLConsole::updateClass();
+    LLConsole::updateClass();
 
-	// animate layout stacks so we have up to date rect for world view
-	LLLayoutStack::updateClass();
+    // animate layout stacks so we have up to date rect for world view
+    LLLayoutStack::updateClass();
 
-	// use full window for world view when not rendering UI
-	bool world_view_uses_full_window = gAgentCamera.cameraMouselook() || !gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI);
-	updateWorldViewRect(world_view_uses_full_window);
+    // use full window for world view when not rendering UI
+    bool world_view_uses_full_window = gAgentCamera.cameraMouselook() || !gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI);
+    updateWorldViewRect(world_view_uses_full_window);
 
-	LLView::sMouseHandlerMessage.clear();
+    LLView::sMouseHandlerMessage.clear();
 
-	S32 x = mCurrentMousePoint.mX;
-	S32 y = mCurrentMousePoint.mY;
+    S32 x = mCurrentMousePoint.mX;
+    S32 y = mCurrentMousePoint.mY;
 
-	MASK	mask = gKeyboard->currentMask(TRUE);
+    MASK    mask = gKeyboard->currentMask(TRUE);
 
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST))
-	{
-		gDebugRaycastFaceHit = gDebugRaycastGLTFNodeHit = gDebugRaycastGLTFPrimitiveHit = -1;
-		gDebugRaycastObject = cursorIntersect(-1, -1, 512.f, NULL, -1, FALSE, FALSE, TRUE, FALSE,
-											  &gDebugRaycastFaceHit,
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST))
+    {
+        gDebugRaycastFaceHit = gDebugRaycastGLTFNodeHit = gDebugRaycastGLTFPrimitiveHit = -1;
+        gDebugRaycastObject = cursorIntersect(-1, -1, 512.f, NULL, -1, FALSE, FALSE, TRUE, FALSE,
+                                              &gDebugRaycastFaceHit,
                                               &gDebugRaycastGLTFNodeHit,
                                               &gDebugRaycastGLTFPrimitiveHit,
-											  &gDebugRaycastIntersection,
-											  &gDebugRaycastTexCoord,
-											  &gDebugRaycastNormal,
-											  &gDebugRaycastTangent,
-											  &gDebugRaycastStart,
-											  &gDebugRaycastEnd);
-
-		gDebugRaycastParticle = gPipeline.lineSegmentIntersectParticle(gDebugRaycastStart, gDebugRaycastEnd, &gDebugRaycastParticleIntersection, NULL);
-	}
-
-	updateMouseDelta();
-	updateKeyboardFocus();
-
-	BOOL handled = FALSE;
-
-	LLUICtrl* top_ctrl = gFocusMgr.getTopCtrl();
-	LLMouseHandler* mouse_captor = gFocusMgr.getMouseCapture();
-	LLView* captor_view = dynamic_cast<LLView*>(mouse_captor);
-
-	//FIXME: only include captor and captor's ancestors if mouse is truly over them --RN
-
-	//build set of views containing mouse cursor by traversing UI hierarchy and testing 
-	//screen rect against mouse cursor
-	view_handle_set_t mouse_hover_set;
-
-	// constraint mouse enter events to children of mouse captor
-	LLView* root_view = captor_view;
-
-	// if mouse captor doesn't exist or isn't a LLView
-	// then allow mouse enter events on entire UI hierarchy
-	if (!root_view)
-	{
-		root_view = mRootView;
-	}
-
-	static LLCachedControl<bool> dump_floater_view_child (gSavedSettings, "AlchemyDumpFloaterViewSize", false);
-	if (dump_floater_view_child)
-	{
-		static bool fv_init = false;
-		static LLFrameTimer fv_child_count_timer;
-		static std::vector <std::string> fv_child_vec;
-		if (!fv_init)
-		{
-			fv_child_count_timer.resetWithExpiry(5.f);
-			fv_init = true;
-		}
-		if (fv_child_count_timer.hasExpired())
-		{
-			LL_INFOS() << "gFloaterView child count: " << gFloaterView->getChildCount() << LL_ENDL;
-			std::vector<std::string> local_child_vec;
-			LLView::child_list_t child_list = *gFloaterView->getChildList();
-			for (auto child : child_list)
-			{
-				local_child_vec.emplace_back(child->getName());
-			}
-			if (!local_child_vec.empty() && local_child_vec != fv_child_vec)
-			{
-				std::vector<std::string> out_vec;
-				std::sort(local_child_vec.begin(), local_child_vec.end());
-				std::sort(fv_child_vec.begin(), fv_child_vec.end());
-				std::set_difference(fv_child_vec.begin(), fv_child_vec.end(), local_child_vec.begin(), local_child_vec.end(), std::inserter(out_vec, out_vec.begin()));
-				if (!out_vec.empty())
-				{
-					LL_INFOS() << "gFloaterView removal diff size: '" << out_vec.size() << "' begin_child_diff";
-					for (const auto& str : out_vec)
-					{
-						LL_CONT << " : " << str;
-					}
-					LL_CONT << " : end_child_diff" << LL_ENDL;
-				}
-
-				out_vec.clear();
-				std::set_difference(local_child_vec.begin(), local_child_vec.end(), fv_child_vec.begin(), fv_child_vec.end(), std::inserter(out_vec, out_vec.begin()));
-				if (!out_vec.empty())
-				{
-					LL_INFOS() << "gFloaterView addition diff size: '" << out_vec.size() << "' begin_child_diff";
-					for (const auto& str : out_vec)
-					{
-						LL_CONT << " : " << str;
-					}
-					LL_CONT << " : end_child_diff" << LL_ENDL;
-				}
-				fv_child_vec.swap(local_child_vec);
-			}
-			fv_child_count_timer.resetWithExpiry(5.f);
-		}
-	}
-
-	static LLCachedControl<bool> dump_menu_holder(gSavedSettings, "DumpMenuHolderSize", false);
-	if (dump_menu_holder)
-	{
-		static bool init = false;
-		static LLFrameTimer child_count_timer;
-		static std::vector <std::string> child_vec;
-		if (!init)
-		{
-			child_count_timer.resetWithExpiry(5.f);
-			init = true;
-		}
-		if (child_count_timer.hasExpired())
-		{
-			LL_INFOS() << "gMenuHolder child count: " << gMenuHolder->getChildCount() << LL_ENDL;
-			std::vector<std::string> local_child_vec;
-			LLView::child_list_t child_list = *gMenuHolder->getChildList();
-			for (auto child : child_list)
-			{
-				local_child_vec.emplace_back(child->getName());
-			}
-			if (!local_child_vec.empty() && local_child_vec != child_vec)
-			{
-				std::vector<std::string> out_vec;
-				std::sort(local_child_vec.begin(), local_child_vec.end());
-				std::sort(child_vec.begin(), child_vec.end());
-				std::set_difference(child_vec.begin(), child_vec.end(), local_child_vec.begin(), local_child_vec.end(), std::inserter(out_vec, out_vec.begin()));
-				if (!out_vec.empty())
-				{
-					LL_INFOS() << "gMenuHolder removal diff size: '"<<out_vec.size() <<"' begin_child_diff";
-					for (const auto& str : out_vec)
-					{
-						LL_CONT << " : " << str;
-					}
-					LL_CONT << " : end_child_diff" << LL_ENDL;
-				}
-
-				out_vec.clear();
-				std::set_difference(local_child_vec.begin(), local_child_vec.end(), child_vec.begin(), child_vec.end(), std::inserter(out_vec, out_vec.begin()));
-				if (!out_vec.empty())
-				{
-					LL_INFOS() << "gMenuHolder addition diff size: '" << out_vec.size() << "' begin_child_diff";
-					for (const auto& str : out_vec)
-					{
-						LL_CONT << " : " << str;
-					}
-					LL_CONT << " : end_child_diff" << LL_ENDL;
-				}
-				child_vec.swap(local_child_vec);
-			}
-			child_count_timer.resetWithExpiry(5.f);
-		}
-	}
-
-	// only update mouse hover set when UI is visible (since we shouldn't send hover events to invisible UI
-	if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
-	{
-		// include all ancestors of captor_view as automatically having mouse
-		if (captor_view)
-		{
-			LLView* captor_parent_view = captor_view->getParent();
-			while(captor_parent_view)
-			{
-				mouse_hover_set.insert(captor_parent_view->getHandle());
-				captor_parent_view = captor_parent_view->getParent();
-			}
-		}
-
-		// aggregate visible views that contain mouse cursor in display order
-		LLPopupView::popup_list_t popups = mPopupView->getCurrentPopups();
-
-		for(LLPopupView::popup_list_t::iterator popup_it = popups.begin(); popup_it != popups.end(); ++popup_it)
-		{
-			LLView* popup = popup_it->get();
-			if (popup && popup->calcScreenBoundingRect().pointInRect(x, y))
-			{
-				// iterator over contents of top_ctrl, and throw into mouse_hover_set
-				for (LLView::tree_iterator_t it = popup->beginTreeDFS();
-					it != popup->endTreeDFS();
-					++it)
-				{
-					LLView* viewp = *it;
-					if (viewp->getVisible()
-						&& viewp->calcScreenBoundingRect().pointInRect(x, y))
-					{
-						// we have a view that contains the mouse, add it to the set
-						mouse_hover_set.insert(viewp->getHandle());
-					}
-					else
-					{
-						// skip this view and all of its children
-						it.skipDescendants();
-					}
-				}
-			}
-		}
-
-		// while the top_ctrl contains the mouse cursor, only it and its descendants will receive onMouseEnter events
-		if (top_ctrl && top_ctrl->calcScreenBoundingRect().pointInRect(x, y))
-		{
-			// iterator over contents of top_ctrl, and throw into mouse_hover_set
-			for (LLView::tree_iterator_t it = top_ctrl->beginTreeDFS();
-				it != top_ctrl->endTreeDFS();
-				++it)
-			{
-				LLView* viewp = *it;
-				if (viewp->getVisible()
-					&& viewp->calcScreenBoundingRect().pointInRect(x, y))
-				{
-					// we have a view that contains the mouse, add it to the set
-					mouse_hover_set.insert(viewp->getHandle());
-				}
-				else
-				{
-					// skip this view and all of its children
-					it.skipDescendants();
-				}
-			}
-		}
-		else
-		{
-			// walk UI tree in depth-first order
-			for (LLView::tree_iterator_t it = root_view->beginTreeDFS();
-				it != root_view->endTreeDFS();
-				++it)
-			{
-				LLView* viewp = *it;
-				// calculating the screen rect involves traversing the parent, so this is less than optimal
-				if (viewp->getVisible()
-					&& viewp->calcScreenBoundingRect().pointInRect(x, y))
-				{
-
-					// if this view is mouse opaque, nothing behind it should be in mouse_hover_set
-					if (viewp->getMouseOpaque())
-					{
-						// constrain further iteration to children of this widget
-						it = viewp->beginTreeDFS();
-					}
-		
-					// we have a view that contains the mouse, add it to the set
-					mouse_hover_set.insert(viewp->getHandle());
-				}
-				else
-				{
-					// skip this view and all of its children
-					it.skipDescendants();
-				}
-			}
-		}
-	}
-
-	typedef std::vector<LLHandle<LLView> > view_handle_list_t;
-
-	// call onMouseEnter() on all views which contain the mouse cursor but did not before
-	view_handle_list_t mouse_enter_views;
-	std::set_difference(mouse_hover_set.begin(), mouse_hover_set.end(),
-						mMouseHoverViews.begin(), mMouseHoverViews.end(),
-						std::back_inserter(mouse_enter_views));
-	for (view_handle_list_t::iterator it = mouse_enter_views.begin();
-		it != mouse_enter_views.end();
-		++it)
-	{
-		LLView* viewp = it->get();
-		if (viewp)
-		{
-			LLRect view_screen_rect = viewp->calcScreenRect();
-			viewp->onMouseEnter(x - view_screen_rect.mLeft, y - view_screen_rect.mBottom, mask);
-		}
-	}
-
-	// call onMouseLeave() on all views which no longer contain the mouse cursor
-	view_handle_list_t mouse_leave_views;
-	std::set_difference(mMouseHoverViews.begin(), mMouseHoverViews.end(),
-						mouse_hover_set.begin(), mouse_hover_set.end(),
-						std::back_inserter(mouse_leave_views));
-	for (view_handle_list_t::iterator it = mouse_leave_views.begin();
-		it != mouse_leave_views.end();
-		++it)
-	{
-		LLView* viewp = it->get();
-		if (viewp)
-		{
-			LLRect view_screen_rect = viewp->calcScreenRect();
-			viewp->onMouseLeave(x - view_screen_rect.mLeft, y - view_screen_rect.mBottom, mask);
-		}
-	}
-
-	// store resulting hover set for next frame
-	swap(mMouseHoverViews, mouse_hover_set);
-
-	// only handle hover events when UI is enabled
-	if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
-	{	
-
-		if( mouse_captor )
-		{
-			// Pass hover events to object capturing mouse events.
-			S32 local_x;
-			S32 local_y; 
-			mouse_captor->screenPointToLocal( x, y, &local_x, &local_y );
-			handled = mouse_captor->handleHover(local_x, local_y, mask);
-			if (LLView::sDebugMouseHandling)
-			{
-				LL_INFOS() << "Hover handled by captor " << mouse_captor->getName() << LL_ENDL;
-			}
-
-			if( !handled )
-			{
-				LL_DEBUGS("UserInput") << "hover not handled by mouse captor" << LL_ENDL;
-			}
-		}
-		else
-		{
-			if (top_ctrl)
-			{
-				S32 local_x, local_y;
-				top_ctrl->screenPointToLocal( x, y, &local_x, &local_y );
-				handled = top_ctrl->pointInView(local_x, local_y) && top_ctrl->handleHover(local_x, local_y, mask);
-			}
-
-			if ( !handled )
-			{
-				// x and y are from last time mouse was in window
-				// mMouseInWindow tracks *actual* mouse location
-				if (mMouseInWindow && mRootView->handleHover(x, y, mask) )
-				{
-					if (LLView::sDebugMouseHandling && LLView::sMouseHandlerMessage != last_handle_msg)
-					{
-						last_handle_msg = LLView::sMouseHandlerMessage;
-						LL_INFOS() << "Hover" << LLView::sMouseHandlerMessage << LL_ENDL;
-					}
-					handled = TRUE;
-				}
-				else if (LLView::sDebugMouseHandling)
-				{
-					if (last_handle_msg != LLStringUtil::null)
-					{
-						last_handle_msg.clear();
-						LL_INFOS() << "Hover not handled by view" << LL_ENDL;
-					}
-				}
-			}
-		
-			if (!handled)
-			{
-				LLTool *tool = LLToolMgr::getInstance()->getCurrentTool();
-
-				if(mMouseInWindow && tool)
-				{
-					handled = tool->handleHover(x, y, mask);
-				}
-			}
-		}
-
-		// Show a new tool tip (or update one that is already shown)
-		BOOL tool_tip_handled = FALSE;
-		if( handled 
-			&& !mWindow->isCursorHidden())
-		{
-			LLRect screen_sticky_rect = mRootView->getLocalRect();
-			S32 local_x, local_y;
-
-			static LLCachedControl<bool> debug_show_xui_names(gSavedSettings, "DebugShowXUINames", 0);
-			if (debug_show_xui_names)
-			{
-				LLToolTip::Params params;
-
-				LLView* tooltip_view = mRootView;
-				LLView::tree_iterator_t end_it = mRootView->endTreeDFS();
-				for (LLView::tree_iterator_t it = mRootView->beginTreeDFS(); it != end_it; ++it)
-				{
-					LLView* viewp = *it;
-					LLRect screen_rect;
-					viewp->localRectToScreen(viewp->getLocalRect(), &screen_rect);
-					if (!(viewp->getVisible()
-						 && screen_rect.pointInRect(x, y)))
-					{
-						it.skipDescendants();
-					}
-					// only report xui names for LLUICtrls, 
-					// and blacklist the various containers we don't care about
-					else if (dynamic_cast<LLUICtrl*>(viewp) 
-							&& viewp != gMenuHolder
-							&& viewp != gFloaterView
-							&& viewp != gConsole) 
-					{
-						if (dynamic_cast<LLFloater*>(viewp))
-						{
-							// constrain search to descendants of this (frontmost) floater
-							// by resetting iterator
-							it = viewp->beginTreeDFS();
-						}
-
-						// if we are in a new part of the tree (not a descendent of current tooltip_view)
-						// then push the results for tooltip_view and start with a new potential view
-						// NOTE: this emulates visiting only the leaf nodes that meet our criteria
-						if (!viewp->hasAncestor(tooltip_view))
-						{
-							append_xui_tooltip(tooltip_view, params);
-							screen_sticky_rect.intersectWith(tooltip_view->calcScreenRect());
-						}
-						tooltip_view = viewp;
-					}
-				}
-
-				append_xui_tooltip(tooltip_view, params);
-				params.styled_message.add().text("\n");
-
-				screen_sticky_rect.intersectWith(tooltip_view->calcScreenRect());
-				
-				params.sticky_rect = screen_sticky_rect;
-				params.max_width = 400;
-
-				LLToolTipMgr::instance().show(params);
-			}
-			// if there is a mouse captor, nothing else gets a tooltip
-			else if (mouse_captor)
-			{
-				mouse_captor->screenPointToLocal(x, y, &local_x, &local_y);
-				tool_tip_handled = mouse_captor->handleToolTip(local_x, local_y, mask);
-			}
-			else 
-			{
-				// next is top_ctrl
-				if (!tool_tip_handled && top_ctrl)
-				{
-					top_ctrl->screenPointToLocal(x, y, &local_x, &local_y);
-					tool_tip_handled = top_ctrl->handleToolTip(local_x, local_y, mask );
-				}
-				
-				if (!tool_tip_handled)
-				{
-					local_x = x; local_y = y;
-					tool_tip_handled = mRootView->handleToolTip(local_x, local_y, mask );
-				}
-
-				LLTool* current_tool = LLToolMgr::getInstance()->getCurrentTool();
-				if (!tool_tip_handled && current_tool)
-				{
-					current_tool->screenPointToLocal(x, y, &local_x, &local_y);
-					tool_tip_handled = current_tool->handleToolTip(local_x, local_y, mask );
-				}
-			}
-		}		
-	}
-	else
-	{	// just have tools handle hover when UI is turned off
-		LLTool *tool = LLToolMgr::getInstance()->getCurrentTool();
-
-		if(mMouseInWindow && tool)
-		{
-			handled = tool->handleHover(x, y, mask);
-		}
-	}
-
-	updateLayout();
-
-	mLastMousePoint = mCurrentMousePoint;
-
-	// cleanup unused selections when no modal dialogs are open
-	if (LLModalDialog::activeCount() == 0)
-	{
-		LLViewerParcelMgr::getInstance()->deselectUnused();
-	}
-
-	if (LLModalDialog::activeCount() == 0)
-	{
-		LLSelectMgr::getInstance()->deselectUnused();
-	}
+                                              &gDebugRaycastIntersection,
+                                              &gDebugRaycastTexCoord,
+                                              &gDebugRaycastNormal,
+                                              &gDebugRaycastTangent,
+                                              &gDebugRaycastStart,
+                                              &gDebugRaycastEnd);
+
+        gDebugRaycastParticle = gPipeline.lineSegmentIntersectParticle(gDebugRaycastStart, gDebugRaycastEnd, &gDebugRaycastParticleIntersection, NULL);
+    }
+
+    updateMouseDelta();
+    updateKeyboardFocus();
+
+    BOOL handled = FALSE;
+
+    LLUICtrl* top_ctrl = gFocusMgr.getTopCtrl();
+    LLMouseHandler* mouse_captor = gFocusMgr.getMouseCapture();
+    LLView* captor_view = dynamic_cast<LLView*>(mouse_captor);
+
+    //FIXME: only include captor and captor's ancestors if mouse is truly over them --RN
+
+    //build set of views containing mouse cursor by traversing UI hierarchy and testing
+    //screen rect against mouse cursor
+    view_handle_set_t mouse_hover_set;
+
+    // constraint mouse enter events to children of mouse captor
+    LLView* root_view = captor_view;
+
+    // if mouse captor doesn't exist or isn't a LLView
+    // then allow mouse enter events on entire UI hierarchy
+    if (!root_view)
+    {
+        root_view = mRootView;
+    }
+
+    static LLCachedControl<bool> dump_floater_view_child (gSavedSettings, "AlchemyDumpFloaterViewSize", false);
+    if (dump_floater_view_child)
+    {
+        static bool fv_init = false;
+        static LLFrameTimer fv_child_count_timer;
+        static std::vector <std::string> fv_child_vec;
+        if (!fv_init)
+        {
+            fv_child_count_timer.resetWithExpiry(5.f);
+            fv_init = true;
+        }
+        if (fv_child_count_timer.hasExpired())
+        {
+            LL_INFOS() << "gFloaterView child count: " << gFloaterView->getChildCount() << LL_ENDL;
+            std::vector<std::string> local_child_vec;
+            LLView::child_list_t child_list = *gFloaterView->getChildList();
+            for (auto child : child_list)
+            {
+                local_child_vec.emplace_back(child->getName());
+            }
+            if (!local_child_vec.empty() && local_child_vec != fv_child_vec)
+            {
+                std::vector<std::string> out_vec;
+                std::sort(local_child_vec.begin(), local_child_vec.end());
+                std::sort(fv_child_vec.begin(), fv_child_vec.end());
+                std::set_difference(fv_child_vec.begin(), fv_child_vec.end(), local_child_vec.begin(), local_child_vec.end(), std::inserter(out_vec, out_vec.begin()));
+                if (!out_vec.empty())
+                {
+                    LL_INFOS() << "gFloaterView removal diff size: '" << out_vec.size() << "' begin_child_diff";
+                    for (const auto& str : out_vec)
+                    {
+                        LL_CONT << " : " << str;
+                    }
+                    LL_CONT << " : end_child_diff" << LL_ENDL;
+                }
+
+                out_vec.clear();
+                std::set_difference(local_child_vec.begin(), local_child_vec.end(), fv_child_vec.begin(), fv_child_vec.end(), std::inserter(out_vec, out_vec.begin()));
+                if (!out_vec.empty())
+                {
+                    LL_INFOS() << "gFloaterView addition diff size: '" << out_vec.size() << "' begin_child_diff";
+                    for (const auto& str : out_vec)
+                    {
+                        LL_CONT << " : " << str;
+                    }
+                    LL_CONT << " : end_child_diff" << LL_ENDL;
+                }
+                fv_child_vec.swap(local_child_vec);
+            }
+            fv_child_count_timer.resetWithExpiry(5.f);
+        }
+    }
+
+    static LLCachedControl<bool> dump_menu_holder(gSavedSettings, "DumpMenuHolderSize", false);
+    if (dump_menu_holder)
+    {
+        static bool init = false;
+        static LLFrameTimer child_count_timer;
+        static std::vector <std::string> child_vec;
+        if (!init)
+        {
+            child_count_timer.resetWithExpiry(5.f);
+            init = true;
+        }
+        if (child_count_timer.hasExpired())
+        {
+            LL_INFOS() << "gMenuHolder child count: " << gMenuHolder->getChildCount() << LL_ENDL;
+            std::vector<std::string> local_child_vec;
+            LLView::child_list_t child_list = *gMenuHolder->getChildList();
+            for (auto child : child_list)
+            {
+                local_child_vec.emplace_back(child->getName());
+            }
+            if (!local_child_vec.empty() && local_child_vec != child_vec)
+            {
+                std::vector<std::string> out_vec;
+                std::sort(local_child_vec.begin(), local_child_vec.end());
+                std::sort(child_vec.begin(), child_vec.end());
+                std::set_difference(child_vec.begin(), child_vec.end(), local_child_vec.begin(), local_child_vec.end(), std::inserter(out_vec, out_vec.begin()));
+                if (!out_vec.empty())
+                {
+                    LL_INFOS() << "gMenuHolder removal diff size: '"<<out_vec.size() <<"' begin_child_diff";
+                    for (const auto& str : out_vec)
+                    {
+                        LL_CONT << " : " << str;
+                    }
+                    LL_CONT << " : end_child_diff" << LL_ENDL;
+                }
+
+                out_vec.clear();
+                std::set_difference(local_child_vec.begin(), local_child_vec.end(), child_vec.begin(), child_vec.end(), std::inserter(out_vec, out_vec.begin()));
+                if (!out_vec.empty())
+                {
+                    LL_INFOS() << "gMenuHolder addition diff size: '" << out_vec.size() << "' begin_child_diff";
+                    for (const auto& str : out_vec)
+                    {
+                        LL_CONT << " : " << str;
+                    }
+                    LL_CONT << " : end_child_diff" << LL_ENDL;
+                }
+                child_vec.swap(local_child_vec);
+            }
+            child_count_timer.resetWithExpiry(5.f);
+        }
+    }
+
+    // only update mouse hover set when UI is visible (since we shouldn't send hover events to invisible UI
+    if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
+    {
+        // include all ancestors of captor_view as automatically having mouse
+        if (captor_view)
+        {
+            LLView* captor_parent_view = captor_view->getParent();
+            while(captor_parent_view)
+            {
+                mouse_hover_set.insert(captor_parent_view->getHandle());
+                captor_parent_view = captor_parent_view->getParent();
+            }
+        }
+
+        // aggregate visible views that contain mouse cursor in display order
+        LLPopupView::popup_list_t popups = mPopupView->getCurrentPopups();
+
+        for(LLPopupView::popup_list_t::iterator popup_it = popups.begin(); popup_it != popups.end(); ++popup_it)
+        {
+            LLView* popup = popup_it->get();
+            if (popup && popup->calcScreenBoundingRect().pointInRect(x, y))
+            {
+                // iterator over contents of top_ctrl, and throw into mouse_hover_set
+                for (LLView::tree_iterator_t it = popup->beginTreeDFS();
+                    it != popup->endTreeDFS();
+                    ++it)
+                {
+                    LLView* viewp = *it;
+                    if (viewp->getVisible()
+                        && viewp->calcScreenBoundingRect().pointInRect(x, y))
+                    {
+                        // we have a view that contains the mouse, add it to the set
+                        mouse_hover_set.insert(viewp->getHandle());
+                    }
+                    else
+                    {
+                        // skip this view and all of its children
+                        it.skipDescendants();
+                    }
+                }
+            }
+        }
+
+        // while the top_ctrl contains the mouse cursor, only it and its descendants will receive onMouseEnter events
+        if (top_ctrl && top_ctrl->calcScreenBoundingRect().pointInRect(x, y))
+        {
+            // iterator over contents of top_ctrl, and throw into mouse_hover_set
+            for (LLView::tree_iterator_t it = top_ctrl->beginTreeDFS();
+                it != top_ctrl->endTreeDFS();
+                ++it)
+            {
+                LLView* viewp = *it;
+                if (viewp->getVisible()
+                    && viewp->calcScreenBoundingRect().pointInRect(x, y))
+                {
+                    // we have a view that contains the mouse, add it to the set
+                    mouse_hover_set.insert(viewp->getHandle());
+                }
+                else
+                {
+                    // skip this view and all of its children
+                    it.skipDescendants();
+                }
+            }
+        }
+        else
+        {
+            // walk UI tree in depth-first order
+            for (LLView::tree_iterator_t it = root_view->beginTreeDFS();
+                it != root_view->endTreeDFS();
+                ++it)
+            {
+                LLView* viewp = *it;
+                // calculating the screen rect involves traversing the parent, so this is less than optimal
+                if (viewp->getVisible()
+                    && viewp->calcScreenBoundingRect().pointInRect(x, y))
+                {
+
+                    // if this view is mouse opaque, nothing behind it should be in mouse_hover_set
+                    if (viewp->getMouseOpaque())
+                    {
+                        // constrain further iteration to children of this widget
+                        it = viewp->beginTreeDFS();
+                    }
+
+                    // we have a view that contains the mouse, add it to the set
+                    mouse_hover_set.insert(viewp->getHandle());
+                }
+                else
+                {
+                    // skip this view and all of its children
+                    it.skipDescendants();
+                }
+            }
+        }
+    }
+
+    typedef std::vector<LLHandle<LLView> > view_handle_list_t;
+
+    // call onMouseEnter() on all views which contain the mouse cursor but did not before
+    view_handle_list_t mouse_enter_views;
+    std::set_difference(mouse_hover_set.begin(), mouse_hover_set.end(),
+                        mMouseHoverViews.begin(), mMouseHoverViews.end(),
+                        std::back_inserter(mouse_enter_views));
+    for (view_handle_list_t::iterator it = mouse_enter_views.begin();
+        it != mouse_enter_views.end();
+        ++it)
+    {
+        LLView* viewp = it->get();
+        if (viewp)
+        {
+            LLRect view_screen_rect = viewp->calcScreenRect();
+            viewp->onMouseEnter(x - view_screen_rect.mLeft, y - view_screen_rect.mBottom, mask);
+        }
+    }
+
+    // call onMouseLeave() on all views which no longer contain the mouse cursor
+    view_handle_list_t mouse_leave_views;
+    std::set_difference(mMouseHoverViews.begin(), mMouseHoverViews.end(),
+                        mouse_hover_set.begin(), mouse_hover_set.end(),
+                        std::back_inserter(mouse_leave_views));
+    for (view_handle_list_t::iterator it = mouse_leave_views.begin();
+        it != mouse_leave_views.end();
+        ++it)
+    {
+        LLView* viewp = it->get();
+        if (viewp)
+        {
+            LLRect view_screen_rect = viewp->calcScreenRect();
+            viewp->onMouseLeave(x - view_screen_rect.mLeft, y - view_screen_rect.mBottom, mask);
+        }
+    }
+
+    // store resulting hover set for next frame
+    swap(mMouseHoverViews, mouse_hover_set);
+
+    // only handle hover events when UI is enabled
+    if (gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
+    {
+
+        if( mouse_captor )
+        {
+            // Pass hover events to object capturing mouse events.
+            S32 local_x;
+            S32 local_y;
+            mouse_captor->screenPointToLocal( x, y, &local_x, &local_y );
+            handled = mouse_captor->handleHover(local_x, local_y, mask);
+            if (LLView::sDebugMouseHandling)
+            {
+                LL_INFOS() << "Hover handled by captor " << mouse_captor->getName() << LL_ENDL;
+            }
+
+            if( !handled )
+            {
+                LL_DEBUGS("UserInput") << "hover not handled by mouse captor" << LL_ENDL;
+            }
+        }
+        else
+        {
+            if (top_ctrl)
+            {
+                S32 local_x, local_y;
+                top_ctrl->screenPointToLocal( x, y, &local_x, &local_y );
+                handled = top_ctrl->pointInView(local_x, local_y) && top_ctrl->handleHover(local_x, local_y, mask);
+            }
+
+            if ( !handled )
+            {
+                // x and y are from last time mouse was in window
+                // mMouseInWindow tracks *actual* mouse location
+                if (mMouseInWindow && mRootView->handleHover(x, y, mask) )
+                {
+                    if (LLView::sDebugMouseHandling && LLView::sMouseHandlerMessage != last_handle_msg)
+                    {
+                        last_handle_msg = LLView::sMouseHandlerMessage;
+                        LL_INFOS() << "Hover" << LLView::sMouseHandlerMessage << LL_ENDL;
+                    }
+                    handled = TRUE;
+                }
+                else if (LLView::sDebugMouseHandling)
+                {
+                    if (last_handle_msg != LLStringUtil::null)
+                    {
+                        last_handle_msg.clear();
+                        LL_INFOS() << "Hover not handled by view" << LL_ENDL;
+                    }
+                }
+            }
+
+            if (!handled)
+            {
+                LLTool *tool = LLToolMgr::getInstance()->getCurrentTool();
+
+                if(mMouseInWindow && tool)
+                {
+                    handled = tool->handleHover(x, y, mask);
+                }
+            }
+        }
+
+        // Show a new tool tip (or update one that is already shown)
+        BOOL tool_tip_handled = FALSE;
+        if( handled
+            && !mWindow->isCursorHidden())
+        {
+            LLRect screen_sticky_rect = mRootView->getLocalRect();
+            S32 local_x, local_y;
+
+            static LLCachedControl<bool> debug_show_xui_names(gSavedSettings, "DebugShowXUINames", 0);
+            if (debug_show_xui_names)
+            {
+                LLToolTip::Params params;
+
+                LLView* tooltip_view = mRootView;
+                LLView::tree_iterator_t end_it = mRootView->endTreeDFS();
+                for (LLView::tree_iterator_t it = mRootView->beginTreeDFS(); it != end_it; ++it)
+                {
+                    LLView* viewp = *it;
+                    LLRect screen_rect;
+                    viewp->localRectToScreen(viewp->getLocalRect(), &screen_rect);
+                    if (!(viewp->getVisible()
+                         && screen_rect.pointInRect(x, y)))
+                    {
+                        it.skipDescendants();
+                    }
+                    // only report xui names for LLUICtrls,
+                    // and blacklist the various containers we don't care about
+                    else if (dynamic_cast<LLUICtrl*>(viewp)
+                            && viewp != gMenuHolder
+                            && viewp != gFloaterView
+                            && viewp != gConsole)
+                    {
+                        if (dynamic_cast<LLFloater*>(viewp))
+                        {
+                            // constrain search to descendants of this (frontmost) floater
+                            // by resetting iterator
+                            it = viewp->beginTreeDFS();
+                        }
+
+                        // if we are in a new part of the tree (not a descendent of current tooltip_view)
+                        // then push the results for tooltip_view and start with a new potential view
+                        // NOTE: this emulates visiting only the leaf nodes that meet our criteria
+                        if (!viewp->hasAncestor(tooltip_view))
+                        {
+                            append_xui_tooltip(tooltip_view, params);
+                            screen_sticky_rect.intersectWith(tooltip_view->calcScreenRect());
+                        }
+                        tooltip_view = viewp;
+                    }
+                }
+
+                append_xui_tooltip(tooltip_view, params);
+                params.styled_message.add().text("\n");
+
+                screen_sticky_rect.intersectWith(tooltip_view->calcScreenRect());
+
+                params.sticky_rect = screen_sticky_rect;
+                params.max_width = 400;
+
+                LLToolTipMgr::instance().show(params);
+            }
+            // if there is a mouse captor, nothing else gets a tooltip
+            else if (mouse_captor)
+            {
+                mouse_captor->screenPointToLocal(x, y, &local_x, &local_y);
+                tool_tip_handled = mouse_captor->handleToolTip(local_x, local_y, mask);
+            }
+            else
+            {
+                // next is top_ctrl
+                if (!tool_tip_handled && top_ctrl)
+                {
+                    top_ctrl->screenPointToLocal(x, y, &local_x, &local_y);
+                    tool_tip_handled = top_ctrl->handleToolTip(local_x, local_y, mask );
+                }
+
+                if (!tool_tip_handled)
+                {
+                    local_x = x; local_y = y;
+                    tool_tip_handled = mRootView->handleToolTip(local_x, local_y, mask );
+                }
+
+                LLTool* current_tool = LLToolMgr::getInstance()->getCurrentTool();
+                if (!tool_tip_handled && current_tool)
+                {
+                    current_tool->screenPointToLocal(x, y, &local_x, &local_y);
+                    tool_tip_handled = current_tool->handleToolTip(local_x, local_y, mask );
+                }
+            }
+        }
+    }
+    else
+    {   // just have tools handle hover when UI is turned off
+        LLTool *tool = LLToolMgr::getInstance()->getCurrentTool();
+
+        if(mMouseInWindow && tool)
+        {
+            handled = tool->handleHover(x, y, mask);
+        }
+    }
+
+    updateLayout();
+
+    mLastMousePoint = mCurrentMousePoint;
+
+    // cleanup unused selections when no modal dialogs are open
+    if (LLModalDialog::activeCount() == 0)
+    {
+        LLViewerParcelMgr::getInstance()->deselectUnused();
+    }
+
+    if (LLModalDialog::activeCount() == 0)
+    {
+        LLSelectMgr::getInstance()->deselectUnused();
+    }
 }
 
 
 void LLViewerWindow::updateLayout()
 {
-	LLTool* tool = LLToolMgr::getInstance()->getCurrentTool();
-	if (gFloaterTools != NULL
-		&& tool != NULL
-		&& tool != gToolNull  
-		&& tool != LLToolCompInspect::getInstance()
-		&& tool != LLToolDragAndDrop::getInstance()
-		&& !LLPipeline::FreezeTime)
-	{ 
-		// Suppress the toolbox view if our source tool was the pie tool,
-		// and we've overridden to something else.
-		bool suppress_toolbox = 
-			(LLToolMgr::getInstance()->getBaseTool() == LLToolPie::getInstance()) &&
-			(LLToolMgr::getInstance()->getCurrentTool() != LLToolPie::getInstance());
-
-		LLMouseHandler *captor = gFocusMgr.getMouseCapture();
-		// With the null, inspect, or drag and drop tool, don't muck
-		// with visibility.
-
-		if (gFloaterTools->isMinimized()
-			||	(tool != LLToolPie::getInstance()						// not default tool
-				&& tool != LLToolCompGun::getInstance()					// not coming out of mouselook
-				&& !suppress_toolbox									// not override in third person
-				&& LLToolMgr::getInstance()->getCurrentToolset()->isShowFloaterTools()
-				&& (!captor || dynamic_cast<LLView*>(captor) != NULL)))						// not dragging
-		{
-			// Force floater tools to be visible (unless minimized)
-			if (!gFloaterTools->getVisible())
-			{
-				gFloaterTools->openFloater();
-			}
-			// Update the location of the blue box tool popup
-			LLCoordGL select_center_screen;
-			MASK	mask = gKeyboard->currentMask(TRUE);
-			gFloaterTools->updatePopup( select_center_screen, mask );
-		}
-		else
-		{
-			if (gFloaterTools->getVisible())
-			{
-				gFloaterTools->setVisible(FALSE);
-			}
-		}
-		//gMenuBarView->setItemVisible("BuildTools", gFloaterTools->getVisible());
-	}
-
-	// Always update console
-	if(gConsole)
-	{
-		LLRect console_rect = getChatConsoleRect();
-		gConsole->reshape(console_rect.getWidth(), console_rect.getHeight());
-		gConsole->setRect(console_rect);
-	}
+    LLTool* tool = LLToolMgr::getInstance()->getCurrentTool();
+    if (gFloaterTools != NULL
+        && tool != NULL
+        && tool != gToolNull
+        && tool != LLToolCompInspect::getInstance()
+        && tool != LLToolDragAndDrop::getInstance()
+        && !LLPipeline::FreezeTime)
+    {
+        // Suppress the toolbox view if our source tool was the pie tool,
+        // and we've overridden to something else.
+        bool suppress_toolbox =
+            (LLToolMgr::getInstance()->getBaseTool() == LLToolPie::getInstance()) &&
+            (LLToolMgr::getInstance()->getCurrentTool() != LLToolPie::getInstance());
+
+        LLMouseHandler *captor = gFocusMgr.getMouseCapture();
+        // With the null, inspect, or drag and drop tool, don't muck
+        // with visibility.
+
+        if (gFloaterTools->isMinimized()
+            ||  (tool != LLToolPie::getInstance()                       // not default tool
+                && tool != LLToolCompGun::getInstance()                 // not coming out of mouselook
+                && !suppress_toolbox                                    // not override in third person
+                && LLToolMgr::getInstance()->getCurrentToolset()->isShowFloaterTools()
+                && (!captor || dynamic_cast<LLView*>(captor) != NULL)))                     // not dragging
+        {
+            // Force floater tools to be visible (unless minimized)
+            if (!gFloaterTools->getVisible())
+            {
+                gFloaterTools->openFloater();
+            }
+            // Update the location of the blue box tool popup
+            LLCoordGL select_center_screen;
+            MASK    mask = gKeyboard->currentMask(TRUE);
+            gFloaterTools->updatePopup( select_center_screen, mask );
+        }
+        else
+        {
+            if (gFloaterTools->getVisible())
+            {
+                gFloaterTools->setVisible(FALSE);
+            }
+        }
+        //gMenuBarView->setItemVisible("BuildTools", gFloaterTools->getVisible());
+    }
+
+    // Always update console
+    if(gConsole)
+    {
+        LLRect console_rect = getChatConsoleRect();
+        gConsole->reshape(console_rect.getWidth(), console_rect.getHeight());
+        gConsole->setRect(console_rect);
+    }
 }
 
 void LLViewerWindow::updateMouseDelta()
 {
 #if LL_WINDOWS
-    LLCoordCommon delta; 
+    LLCoordCommon delta;
     mWindow->getCursorDelta(&delta);
     S32 dx = delta.mX;
     S32 dy = delta.mY;
 #else
-	S32 dx = lltrunc((F32) (mCurrentMousePoint.mX - mLastMousePoint.mX) * LLUI::getScaleFactor().mV[VX]);
-	S32 dy = lltrunc((F32) (mCurrentMousePoint.mY - mLastMousePoint.mY) * LLUI::getScaleFactor().mV[VY]);
+    S32 dx = lltrunc((F32) (mCurrentMousePoint.mX - mLastMousePoint.mX) * LLUI::getScaleFactor().mV[VX]);
+    S32 dy = lltrunc((F32) (mCurrentMousePoint.mY - mLastMousePoint.mY) * LLUI::getScaleFactor().mV[VY]);
 #endif
 
-	//RN: fix for asynchronous notification of mouse leaving window not working
-	LLCoordWindow mouse_pos;
-	mWindow->getCursorPosition(&mouse_pos);
-	if (mouse_pos.mX < 0 || 
-		mouse_pos.mY < 0 ||
-		mouse_pos.mX > mWindowRectRaw.getWidth() ||
-		mouse_pos.mY > mWindowRectRaw.getHeight())
-	{
-		mMouseInWindow = FALSE;
-	}
-	else
-	{
-		mMouseInWindow = TRUE;
-	}
-
-	LLVector2 mouse_vel; 
-
-	static const LLCachedControl<bool> mouseSmooth(gSavedSettings, "MouseSmooth");
-	if (mouseSmooth)
-	{
-		static F32 fdx = 0.f;
-		static F32 fdy = 0.f;
-
-		F32 amount = 16.f;
-		fdx = fdx + ((F32) dx - fdx) * llmin(gFrameIntervalSeconds.value()*amount,1.f);
-		fdy = fdy + ((F32) dy - fdy) * llmin(gFrameIntervalSeconds.value()*amount,1.f);
-
-		mCurrentMouseDelta.set(ll_round(fdx), ll_round(fdy));
-		mouse_vel.setVec(fdx,fdy);
-	}
-	else
-	{
-		mCurrentMouseDelta.set(dx, dy);
-		mouse_vel.setVec((F32) dx, (F32) dy);
-	}
-    
-	sample(sMouseVelocityStat, mouse_vel.magVec());
+    //RN: fix for asynchronous notification of mouse leaving window not working
+    LLCoordWindow mouse_pos;
+    mWindow->getCursorPosition(&mouse_pos);
+    if (mouse_pos.mX < 0 ||
+        mouse_pos.mY < 0 ||
+        mouse_pos.mX > mWindowRectRaw.getWidth() ||
+        mouse_pos.mY > mWindowRectRaw.getHeight())
+    {
+        mMouseInWindow = FALSE;
+    }
+    else
+    {
+        mMouseInWindow = TRUE;
+    }
+
+    LLVector2 mouse_vel;
+
+    static const LLCachedControl<bool> mouseSmooth(gSavedSettings, "MouseSmooth");
+    if (mouseSmooth)
+    {
+        static F32 fdx = 0.f;
+        static F32 fdy = 0.f;
+
+        F32 amount = 16.f;
+        fdx = fdx + ((F32) dx - fdx) * llmin(gFrameIntervalSeconds.value()*amount,1.f);
+        fdy = fdy + ((F32) dy - fdy) * llmin(gFrameIntervalSeconds.value()*amount,1.f);
+
+        mCurrentMouseDelta.set(ll_round(fdx), ll_round(fdy));
+        mouse_vel.setVec(fdx,fdy);
+    }
+    else
+    {
+        mCurrentMouseDelta.set(dx, dy);
+        mouse_vel.setVec((F32) dx, (F32) dy);
+    }
+
+    sample(sMouseVelocityStat, mouse_vel.magVec());
 }
 
 void LLViewerWindow::updateKeyboardFocus()
 {
-	if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
-	{
-		gFocusMgr.setKeyboardFocus(NULL);
-	}
-
-	// clean up current focus
-	LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
-	if (cur_focus)
-	{
-		if (!cur_focus->isInVisibleChain() || !cur_focus->isInEnabledChain())
-		{
+    if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
+    {
+        gFocusMgr.setKeyboardFocus(NULL);
+    }
+
+    // clean up current focus
+    LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
+    if (cur_focus)
+    {
+        if (!cur_focus->isInVisibleChain() || !cur_focus->isInEnabledChain())
+        {
             // don't release focus, just reassign so that if being given
             // to a sibling won't call onFocusLost on all the ancestors
-			// gFocusMgr.releaseFocusIfNeeded(cur_focus);
-
-			LLUICtrl* parent = cur_focus->getParentUICtrl();
-			const LLUICtrl* focus_root = cur_focus->findRootMostFocusRoot();
-			bool new_focus_found = false;
-			while(parent)
-			{
-				if (parent->isCtrl() 
-					&& (parent->hasTabStop() || parent == focus_root) 
-					&& !parent->getIsChrome() 
-					&& parent->isInVisibleChain() 
-					&& parent->isInEnabledChain())
-				{
-					if (!parent->focusFirstItem())
-					{
-						parent->setFocus(TRUE);
-					}
-					new_focus_found = true;
-					break;
-				}
-				parent = parent->getParentUICtrl();
-			}
-
-			// if we didn't find a better place to put focus, just release it
-			// hasFocus() will return true if and only if we didn't touch focus since we
-			// are only moving focus higher in the hierarchy
-			if (!new_focus_found)
-			{
-				cur_focus->setFocus(FALSE);
-			}
-		}
-		else if (cur_focus->isFocusRoot())
-		{
-			// focus roots keep trying to delegate focus to their first valid descendant
-			// this assumes that focus roots are not valid focus holders on their own
-			cur_focus->focusFirstItem();
-		}
-	}
-
-	// last ditch force of edit menu to selection manager
-	if (LLEditMenuHandler::gEditMenuHandler == NULL && LLSelectMgr::getInstance()->getSelection()->getObjectCount())
-	{
-		LLEditMenuHandler::gEditMenuHandler = LLSelectMgr::getInstance();
-	}
-
-	if (gFloaterView->getCycleMode())
-	{
-		// sync all floaters with their focus state
-		gFloaterView->highlightFocusedFloater();
-		gSnapshotFloaterView->highlightFocusedFloater();
-		MASK	mask = gKeyboard->currentMask(TRUE);
-		if ((mask & MASK_CONTROL) == 0)
-		{
-			// control key no longer held down, finish cycle mode
-			gFloaterView->setCycleMode(FALSE);
-
-			gFloaterView->syncFloaterTabOrder();
-		}
-		else
-		{
-			// user holding down CTRL, don't update tab order of floaters
-		}
-	}
-	else
-	{
-		// update focused floater
-		gFloaterView->highlightFocusedFloater();
-		gSnapshotFloaterView->highlightFocusedFloater();
-		// make sure floater visible order is in sync with tab order
-		gFloaterView->syncFloaterTabOrder();
-	}
+            // gFocusMgr.releaseFocusIfNeeded(cur_focus);
+
+            LLUICtrl* parent = cur_focus->getParentUICtrl();
+            const LLUICtrl* focus_root = cur_focus->findRootMostFocusRoot();
+            bool new_focus_found = false;
+            while(parent)
+            {
+                if (parent->isCtrl()
+                    && (parent->hasTabStop() || parent == focus_root)
+                    && !parent->getIsChrome()
+                    && parent->isInVisibleChain()
+                    && parent->isInEnabledChain())
+                {
+                    if (!parent->focusFirstItem())
+                    {
+                        parent->setFocus(TRUE);
+                    }
+                    new_focus_found = true;
+                    break;
+                }
+                parent = parent->getParentUICtrl();
+            }
+
+            // if we didn't find a better place to put focus, just release it
+            // hasFocus() will return true if and only if we didn't touch focus since we
+            // are only moving focus higher in the hierarchy
+            if (!new_focus_found)
+            {
+                cur_focus->setFocus(FALSE);
+            }
+        }
+        else if (cur_focus->isFocusRoot())
+        {
+            // focus roots keep trying to delegate focus to their first valid descendant
+            // this assumes that focus roots are not valid focus holders on their own
+            cur_focus->focusFirstItem();
+        }
+    }
+
+    // last ditch force of edit menu to selection manager
+    if (LLEditMenuHandler::gEditMenuHandler == NULL && LLSelectMgr::getInstance()->getSelection()->getObjectCount())
+    {
+        LLEditMenuHandler::gEditMenuHandler = LLSelectMgr::getInstance();
+    }
+
+    if (gFloaterView->getCycleMode())
+    {
+        // sync all floaters with their focus state
+        gFloaterView->highlightFocusedFloater();
+        gSnapshotFloaterView->highlightFocusedFloater();
+        MASK    mask = gKeyboard->currentMask(TRUE);
+        if ((mask & MASK_CONTROL) == 0)
+        {
+            // control key no longer held down, finish cycle mode
+            gFloaterView->setCycleMode(FALSE);
+
+            gFloaterView->syncFloaterTabOrder();
+        }
+        else
+        {
+            // user holding down CTRL, don't update tab order of floaters
+        }
+    }
+    else
+    {
+        // update focused floater
+        gFloaterView->highlightFocusedFloater();
+        gSnapshotFloaterView->highlightFocusedFloater();
+        // make sure floater visible order is in sync with tab order
+        gFloaterView->syncFloaterTabOrder();
+    }
 }
 
 static LLTrace::BlockTimerStatHandle FTM_UPDATE_WORLD_VIEW("Update World View");
 void LLViewerWindow::updateWorldViewRect(bool use_full_window)
 {
-	LL_RECORD_BLOCK_TIME(FTM_UPDATE_WORLD_VIEW);
-
-	// start off using whole window to render world
-	LLRect new_world_rect = mWindowRectRaw;
+    LL_RECORD_BLOCK_TIME(FTM_UPDATE_WORLD_VIEW);
 
-	if (use_full_window == false && mWorldViewPlaceholder.get())
-	{
-		new_world_rect = mWorldViewPlaceholder.get()->calcScreenRect();
-		// clamp to at least a 1x1 rect so we don't try to allocate zero width gl buffers
-		new_world_rect.mTop = llmax(new_world_rect.mTop, new_world_rect.mBottom + 1);
-		new_world_rect.mRight = llmax(new_world_rect.mRight, new_world_rect.mLeft + 1);
+    // start off using whole window to render world
+    LLRect new_world_rect = mWindowRectRaw;
 
-		new_world_rect.mLeft = ll_round((F32)new_world_rect.mLeft * mDisplayScale.mV[VX]);
-		new_world_rect.mRight = ll_round((F32)new_world_rect.mRight * mDisplayScale.mV[VX]);
-		new_world_rect.mBottom = ll_round((F32)new_world_rect.mBottom * mDisplayScale.mV[VY]);
-		new_world_rect.mTop = ll_round((F32)new_world_rect.mTop * mDisplayScale.mV[VY]);
-	}
+    if (use_full_window == false && mWorldViewPlaceholder.get())
+    {
+        new_world_rect = mWorldViewPlaceholder.get()->calcScreenRect();
+        // clamp to at least a 1x1 rect so we don't try to allocate zero width gl buffers
+        new_world_rect.mTop = llmax(new_world_rect.mTop, new_world_rect.mBottom + 1);
+        new_world_rect.mRight = llmax(new_world_rect.mRight, new_world_rect.mLeft + 1);
+
+        new_world_rect.mLeft = ll_round((F32)new_world_rect.mLeft * mDisplayScale.mV[VX]);
+        new_world_rect.mRight = ll_round((F32)new_world_rect.mRight * mDisplayScale.mV[VX]);
+        new_world_rect.mBottom = ll_round((F32)new_world_rect.mBottom * mDisplayScale.mV[VY]);
+        new_world_rect.mTop = ll_round((F32)new_world_rect.mTop * mDisplayScale.mV[VY]);
+    }
 
-	if (mWorldViewRectRaw != new_world_rect)
-	{
-		mWorldViewRectRaw = new_world_rect;
-		gResizeScreenTexture = TRUE;
-		LLViewerCamera::getInstance()->setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
-		LLViewerCamera::getInstance()->setAspect( getWorldViewAspectRatio() );
+    if (mWorldViewRectRaw != new_world_rect)
+    {
+        mWorldViewRectRaw = new_world_rect;
+        gResizeScreenTexture = TRUE;
+        LLViewerCamera::getInstance()->setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
+        LLViewerCamera::getInstance()->setAspect( getWorldViewAspectRatio() );
 
-		LLRect old_world_rect_scaled = mWorldViewRectScaled;
-		mWorldViewRectScaled = calcScaledRect(mWorldViewRectRaw, mDisplayScale);
+        LLRect old_world_rect_scaled = mWorldViewRectScaled;
+        mWorldViewRectScaled = calcScaledRect(mWorldViewRectRaw, mDisplayScale);
 
-		// sending a signal with a new WorldView rect
-		mOnWorldViewRectUpdated(old_world_rect_scaled, mWorldViewRectScaled);
-	}
+        // sending a signal with a new WorldView rect
+        mOnWorldViewRectUpdated(old_world_rect_scaled, mWorldViewRectScaled);
+    }
 }
 
 void LLViewerWindow::saveLastMouse(const LLCoordGL &point)
 {
-	// Store last mouse location.
-	// If mouse leaves window, pretend last point was on edge of window
-
-	if (point.mX < 0)
-	{
-		mCurrentMousePoint.mX = 0;
-	}
-	else if (point.mX > getWindowWidthScaled())
-	{
-		mCurrentMousePoint.mX = getWindowWidthScaled();
-	}
-	else
-	{
-		mCurrentMousePoint.mX = point.mX;
-	}
-
-	if (point.mY < 0)
-	{
-		mCurrentMousePoint.mY = 0;
-	}
-	else if (point.mY > getWindowHeightScaled() )
-	{
-		mCurrentMousePoint.mY = getWindowHeightScaled();
-	}
-	else
-	{
-		mCurrentMousePoint.mY = point.mY;
-	}
+    // Store last mouse location.
+    // If mouse leaves window, pretend last point was on edge of window
+
+    if (point.mX < 0)
+    {
+        mCurrentMousePoint.mX = 0;
+    }
+    else if (point.mX > getWindowWidthScaled())
+    {
+        mCurrentMousePoint.mX = getWindowWidthScaled();
+    }
+    else
+    {
+        mCurrentMousePoint.mX = point.mX;
+    }
+
+    if (point.mY < 0)
+    {
+        mCurrentMousePoint.mY = 0;
+    }
+    else if (point.mY > getWindowHeightScaled() )
+    {
+        mCurrentMousePoint.mY = getWindowHeightScaled();
+    }
+    else
+    {
+        mCurrentMousePoint.mY = point.mY;
+    }
 }
 
 
 // Draws the selection outlines for the currently selected objects
 // Must be called after displayObjects is called, which sets the mGLName parameter
 // NOTE: This function gets called 3 times:
-//  render_ui_3d: 			FALSE, FALSE, TRUE
-//  render_hud_elements:	FALSE, FALSE, FALSE
+//  render_ui_3d:           FALSE, FALSE, TRUE
+//  render_hud_elements:    FALSE, FALSE, FALSE
 void LLViewerWindow::renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls, BOOL for_hud )
 {
-	LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-
-	if (!for_hud && !for_gl_pick)
-	{
-		// Call this once and only once
-		LLSelectMgr::getInstance()->updateSilhouettes();
-	}
-	
-	// Draw fence around land selections
-	if (for_gl_pick)
-	{
-		if (pick_parcel_walls)
-		{
-			LLViewerParcelMgr::getInstance()->renderParcelCollision();
-		}
-	}
-	else if (( for_hud && selection->getSelectType() == SELECT_TYPE_HUD) ||
-			 (!for_hud && selection->getSelectType() != SELECT_TYPE_HUD))
-	{		
-		LLSelectMgr::getInstance()->renderSilhouettes(for_hud);
-		
-		stop_glerror();
-
-		// setup HUD render
-		if (selection->getSelectType() == SELECT_TYPE_HUD && LLSelectMgr::getInstance()->getSelection()->getObjectCount())
-		{
-			LLBBox hud_bbox = gAgentAvatarp->getHUDBBox();
-
-			// set up transform to encompass bounding box of HUD
-			gGL.matrixMode(LLRender::MM_PROJECTION);
-			gGL.pushMatrix();
-			gGL.loadIdentity();
-			F32 depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
-			gGL.ortho(-0.5f * LLViewerCamera::getInstance()->getAspect(), 0.5f * LLViewerCamera::getInstance()->getAspect(), -0.5f, 0.5f, 0.f, depth);
-			
-			gGL.matrixMode(LLRender::MM_MODELVIEW);
-			gGL.pushMatrix();
-			gGL.loadIdentity();
-			gGL.loadMatrix(OGL_TO_CFR_ROTATION_4A);		// Load Cory's favorite reference frame
-			gGL.translatef(-hud_bbox.getCenterLocal().mV[VX] + (depth *0.5f), 0.f, 0.f);
-		}
-
-		// Render light for editing
-		if (LLSelectMgr::sRenderLightRadius && LLToolMgr::getInstance()->inEdit())
-		{
-			gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-			LLGLEnable gls_blend(GL_BLEND);
-			LLGLEnable gls_cull(GL_CULL_FACE);
-			LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
-			gGL.matrixMode(LLRender::MM_MODELVIEW);
-			gGL.pushMatrix();
-			if (selection->getSelectType() == SELECT_TYPE_HUD)
-			{
-				F32 zoom = gAgentCamera.mHUDCurZoom;
-				gGL.scalef(zoom, zoom, zoom);
-			}
-
-			struct f : public LLSelectedObjectFunctor
-			{
-				virtual bool apply(LLViewerObject* object)
-				{
-					LLDrawable* drawable = object->mDrawable;
-					if (drawable && drawable->isLight())
-					{
-						LLVOVolume* vovolume = drawable->getVOVolume();
-						gGL.pushMatrix();
-
-						LLVector3 center = drawable->getPositionAgent();
-						gGL.translatef(center[0], center[1], center[2]);
-						F32 scale = vovolume->getLightRadius();
-						gGL.scalef(scale, scale, scale);
-
-						LLColor4 color(vovolume->getLightSRGBColor(), .5f);
-						gGL.color4fv(color.mV);
-					
-						//F32 pixel_area = 100000.f;
-						// Render Outside
-						gSphere.render();
-
-						// Render Inside
-						glCullFace(GL_FRONT);
-						gSphere.render();
-						glCullFace(GL_BACK);
-					
-						gGL.popMatrix();
-					}
-					return true;
-				}
-			} func;
-			LLSelectMgr::getInstance()->getSelection()->applyToObjects(&func);
-			
-			gGL.popMatrix();
-		}				
-		
-		// NOTE: The average position for the axis arrows of the selected objects should
-		// not be recalculated at this time.  If they are, then group rotations will break.
-
-		// Draw arrows at average center of all selected objects
-		LLTool* tool = LLToolMgr::getInstance()->getCurrentTool();
-		if (tool)
-		{
-			if(tool->isAlwaysRendered())
-			{
-				tool->render();
-			}
-			else
-			{
-				if( !LLSelectMgr::getInstance()->getSelection()->isEmpty() )
-				{
-					bool all_selected_objects_move;
-					bool all_selected_objects_modify;
-					// Note: This might be costly to do on each frame and when a lot of objects are selected
-					// we might be better off with some kind of memory for selection and/or states, consider
-					// optimizing, perhaps even some kind of selection generation at level of LLSelectMgr to
-					// make whole viewer benefit.
-					LLSelectMgr::getInstance()->selectGetEditMoveLinksetPermissions(all_selected_objects_move, all_selected_objects_modify);
-
-					BOOL draw_handles = TRUE;
-
-					if (tool == LLToolCompTranslate::getInstance() && !all_selected_objects_move && !LLSelectMgr::getInstance()->isMovableAvatarSelected())
-					{
-						draw_handles = FALSE;
-					}
-
-					if (tool == LLToolCompRotate::getInstance() && !all_selected_objects_move && !LLSelectMgr::getInstance()->isMovableAvatarSelected())
-					{
-						draw_handles = FALSE;
-					}
-
-					if ( !all_selected_objects_modify && tool == LLToolCompScale::getInstance() )
-					{
-						draw_handles = FALSE;
-					}
-				
-					if( draw_handles )
-					{
-						tool->render();
-					}
-				}
-			}
-			if (selection->getSelectType() == SELECT_TYPE_HUD && selection->getObjectCount())
-			{
-				gGL.matrixMode(LLRender::MM_PROJECTION);
-				gGL.popMatrix();
-
-				gGL.matrixMode(LLRender::MM_MODELVIEW);
-				gGL.popMatrix();
-				stop_glerror();
-			}
-		}
-	}
+    LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+
+    if (!for_hud && !for_gl_pick)
+    {
+        // Call this once and only once
+        LLSelectMgr::getInstance()->updateSilhouettes();
+    }
+
+    // Draw fence around land selections
+    if (for_gl_pick)
+    {
+        if (pick_parcel_walls)
+        {
+            LLViewerParcelMgr::getInstance()->renderParcelCollision();
+        }
+    }
+    else if (( for_hud && selection->getSelectType() == SELECT_TYPE_HUD) ||
+             (!for_hud && selection->getSelectType() != SELECT_TYPE_HUD))
+    {
+        LLSelectMgr::getInstance()->renderSilhouettes(for_hud);
+
+        stop_glerror();
+
+        // setup HUD render
+        if (selection->getSelectType() == SELECT_TYPE_HUD && LLSelectMgr::getInstance()->getSelection()->getObjectCount())
+        {
+            LLBBox hud_bbox = gAgentAvatarp->getHUDBBox();
+
+            // set up transform to encompass bounding box of HUD
+            gGL.matrixMode(LLRender::MM_PROJECTION);
+            gGL.pushMatrix();
+            gGL.loadIdentity();
+            F32 depth = llmax(1.f, hud_bbox.getExtentLocal().mV[VX] * 1.1f);
+            gGL.ortho(-0.5f * LLViewerCamera::getInstance()->getAspect(), 0.5f * LLViewerCamera::getInstance()->getAspect(), -0.5f, 0.5f, 0.f, depth);
+
+            gGL.matrixMode(LLRender::MM_MODELVIEW);
+            gGL.pushMatrix();
+            gGL.loadIdentity();
+            gGL.loadMatrix(OGL_TO_CFR_ROTATION_4A);     // Load Cory's favorite reference frame
+            gGL.translatef(-hud_bbox.getCenterLocal().mV[VX] + (depth *0.5f), 0.f, 0.f);
+        }
+
+        // Render light for editing
+        if (LLSelectMgr::sRenderLightRadius && LLToolMgr::getInstance()->inEdit())
+        {
+            gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+            LLGLEnable gls_blend(GL_BLEND);
+            LLGLEnable gls_cull(GL_CULL_FACE);
+            LLGLDepthTest gls_depth(GL_TRUE, GL_FALSE);
+            gGL.matrixMode(LLRender::MM_MODELVIEW);
+            gGL.pushMatrix();
+            if (selection->getSelectType() == SELECT_TYPE_HUD)
+            {
+                F32 zoom = gAgentCamera.mHUDCurZoom;
+                gGL.scalef(zoom, zoom, zoom);
+            }
+
+            struct f : public LLSelectedObjectFunctor
+            {
+                virtual bool apply(LLViewerObject* object)
+                {
+                    LLDrawable* drawable = object->mDrawable;
+                    if (drawable && drawable->isLight())
+                    {
+                        LLVOVolume* vovolume = drawable->getVOVolume();
+                        gGL.pushMatrix();
+
+                        LLVector3 center = drawable->getPositionAgent();
+                        gGL.translatef(center[0], center[1], center[2]);
+                        F32 scale = vovolume->getLightRadius();
+                        gGL.scalef(scale, scale, scale);
+
+                        LLColor4 color(vovolume->getLightSRGBColor(), .5f);
+                        gGL.color4fv(color.mV);
+
+                        //F32 pixel_area = 100000.f;
+                        // Render Outside
+                        gSphere.render();
+
+                        // Render Inside
+                        glCullFace(GL_FRONT);
+                        gSphere.render();
+                        glCullFace(GL_BACK);
+
+                        gGL.popMatrix();
+                    }
+                    return true;
+                }
+            } func;
+            LLSelectMgr::getInstance()->getSelection()->applyToObjects(&func);
+
+            gGL.popMatrix();
+        }
+
+        // NOTE: The average position for the axis arrows of the selected objects should
+        // not be recalculated at this time.  If they are, then group rotations will break.
+
+        // Draw arrows at average center of all selected objects
+        LLTool* tool = LLToolMgr::getInstance()->getCurrentTool();
+        if (tool)
+        {
+            if(tool->isAlwaysRendered())
+            {
+                tool->render();
+            }
+            else
+            {
+                if( !LLSelectMgr::getInstance()->getSelection()->isEmpty() )
+                {
+                    bool all_selected_objects_move;
+                    bool all_selected_objects_modify;
+                    // Note: This might be costly to do on each frame and when a lot of objects are selected
+                    // we might be better off with some kind of memory for selection and/or states, consider
+                    // optimizing, perhaps even some kind of selection generation at level of LLSelectMgr to
+                    // make whole viewer benefit.
+                    LLSelectMgr::getInstance()->selectGetEditMoveLinksetPermissions(all_selected_objects_move, all_selected_objects_modify);
+
+                    BOOL draw_handles = TRUE;
+
+                    if (tool == LLToolCompTranslate::getInstance() && !all_selected_objects_move && !LLSelectMgr::getInstance()->isMovableAvatarSelected())
+                    {
+                        draw_handles = FALSE;
+                    }
+
+                    if (tool == LLToolCompRotate::getInstance() && !all_selected_objects_move && !LLSelectMgr::getInstance()->isMovableAvatarSelected())
+                    {
+                        draw_handles = FALSE;
+                    }
+
+                    if ( !all_selected_objects_modify && tool == LLToolCompScale::getInstance() )
+                    {
+                        draw_handles = FALSE;
+                    }
+
+                    if( draw_handles )
+                    {
+                        tool->render();
+                    }
+                }
+            }
+            if (selection->getSelectType() == SELECT_TYPE_HUD && selection->getObjectCount())
+            {
+                gGL.matrixMode(LLRender::MM_PROJECTION);
+                gGL.popMatrix();
+
+                gGL.matrixMode(LLRender::MM_MODELVIEW);
+                gGL.popMatrix();
+                stop_glerror();
+            }
+        }
+    }
 }
 
 // Return a point near the clicked object representative of the place the object was clicked.
 LLVector3d LLViewerWindow::clickPointInWorldGlobal(S32 x, S32 y_from_bot, LLViewerObject* clicked_object) const
 {
-	// create a normalized vector pointing from the camera center into the 
-	// world at the location of the mouse click
-	LLVector3 mouse_direction_global = mouseDirectionGlobal( x, y_from_bot );
+    // create a normalized vector pointing from the camera center into the
+    // world at the location of the mouse click
+    LLVector3 mouse_direction_global = mouseDirectionGlobal( x, y_from_bot );
 
-	LLVector3d relative_object = clicked_object->getPositionGlobal() - gAgentCamera.getCameraPositionGlobal();
+    LLVector3d relative_object = clicked_object->getPositionGlobal() - gAgentCamera.getCameraPositionGlobal();
 
-	// make mouse vector as long as object vector, so it touchs a point near
-	// where the user clicked on the object
-	mouse_direction_global *= (F32) relative_object.magVec();
+    // make mouse vector as long as object vector, so it touchs a point near
+    // where the user clicked on the object
+    mouse_direction_global *= (F32) relative_object.magVec();
 
-	LLVector3d new_pos;
-	new_pos.setVec(mouse_direction_global);
-	// transform mouse vector back to world coords
-	new_pos += gAgentCamera.getCameraPositionGlobal();
+    LLVector3d new_pos;
+    new_pos.setVec(mouse_direction_global);
+    // transform mouse vector back to world coords
+    new_pos += gAgentCamera.getCameraPositionGlobal();
 
-	return new_pos;
+    return new_pos;
 }
 
 
 BOOL LLViewerWindow::clickPointOnSurfaceGlobal(const S32 x, const S32 y, LLViewerObject *objectp, LLVector3d &point_global) const
 {
-	BOOL intersect = FALSE;
+    BOOL intersect = FALSE;
 
-//	U8 shape = objectp->mPrimitiveCode & LL_PCODE_BASE_MASK;
-	if (!intersect)
-	{
-		point_global = clickPointInWorldGlobal(x, y, objectp);
-		LL_INFOS() << "approx intersection at " <<  (objectp->getPositionGlobal() - point_global) << LL_ENDL;
-	}
-	else
-	{
-		LL_INFOS() << "good intersection at " <<  (objectp->getPositionGlobal() - point_global) << LL_ENDL;
-	}
+//  U8 shape = objectp->mPrimitiveCode & LL_PCODE_BASE_MASK;
+    if (!intersect)
+    {
+        point_global = clickPointInWorldGlobal(x, y, objectp);
+        LL_INFOS() << "approx intersection at " <<  (objectp->getPositionGlobal() - point_global) << LL_ENDL;
+    }
+    else
+    {
+        LL_INFOS() << "good intersection at " <<  (objectp->getPositionGlobal() - point_global) << LL_ENDL;
+    }
 
-	return intersect;
+    return intersect;
 }
 
 void LLViewerWindow::pickAsync( S32 x,
-								S32 y_from_bot,
-								MASK mask,
-								void (*callback)(const LLPickInfo& info),
-								BOOL pick_transparent,
-								BOOL pick_rigged,
-								BOOL pick_unselectable,
+                                S32 y_from_bot,
+                                MASK mask,
+                                void (*callback)(const LLPickInfo& info),
+                                BOOL pick_transparent,
+                                BOOL pick_rigged,
+                                BOOL pick_unselectable,
                                 BOOL pick_reflection_probes)
 {
-	// "Show Debug Alpha" means no object actually transparent
+    // "Show Debug Alpha" means no object actually transparent
     BOOL in_build_mode = LLFloaterReg::instanceVisible("build");
     if (LLDrawPoolAlpha::sShowDebugAlpha
         || (in_build_mode && gSavedSettings.getBOOL("SelectInvisibleObjects")))
@@ -4578,633 +4578,633 @@ void LLViewerWindow::pickAsync( S32 x,
         pick_transparent = TRUE;
     }
 
-	LLPickInfo pick_info(LLCoordGL(x, y_from_bot), mask, pick_transparent, pick_rigged, FALSE, pick_reflection_probes, pick_unselectable, TRUE, callback);
-	schedulePick(pick_info);
+    LLPickInfo pick_info(LLCoordGL(x, y_from_bot), mask, pick_transparent, pick_rigged, FALSE, pick_reflection_probes, pick_unselectable, TRUE, callback);
+    schedulePick(pick_info);
 }
 
 void LLViewerWindow::schedulePick(LLPickInfo& pick_info)
 {
-	if (mPicks.size() >= 1024 || mWindow->getMinimized())
-	{ //something went wrong, picks are being scheduled but not processed
-		
-		if (pick_info.mPickCallback)
-		{
-			pick_info.mPickCallback(pick_info);
-		}
-	
-		return;
-	}
-	mPicks.push_back(pick_info);
-	
-	// delay further event processing until we receive results of pick
-	// only do this for async picks so that handleMouseUp won't be called
-	// until the pick triggered in handleMouseDown has been processed, for example
-	mWindow->delayInputProcessing();
+    if (mPicks.size() >= 1024 || mWindow->getMinimized())
+    { //something went wrong, picks are being scheduled but not processed
+
+        if (pick_info.mPickCallback)
+        {
+            pick_info.mPickCallback(pick_info);
+        }
+
+        return;
+    }
+    mPicks.push_back(pick_info);
+
+    // delay further event processing until we receive results of pick
+    // only do this for async picks so that handleMouseUp won't be called
+    // until the pick triggered in handleMouseDown has been processed, for example
+    mWindow->delayInputProcessing();
 }
 
 
 void LLViewerWindow::performPick()
 {
-	if (!mPicks.empty())
-	{
-		std::vector<LLPickInfo>::iterator pick_it;
-		for (pick_it = mPicks.begin(); pick_it != mPicks.end(); ++pick_it)
-		{
-			pick_it->fetchResults();
-		}
+    if (!mPicks.empty())
+    {
+        std::vector<LLPickInfo>::iterator pick_it;
+        for (pick_it = mPicks.begin(); pick_it != mPicks.end(); ++pick_it)
+        {
+            pick_it->fetchResults();
+        }
 
-		mLastPick = mPicks.back();
-		mPicks.clear();
-	}
+        mLastPick = mPicks.back();
+        mPicks.clear();
+    }
 }
 
 void LLViewerWindow::returnEmptyPicks()
 {
-	std::vector<LLPickInfo>::iterator pick_it;
-	for (pick_it = mPicks.begin(); pick_it != mPicks.end(); ++pick_it)
-	{
-		mLastPick = *pick_it;
-		// just trigger callback with empty results
-		if (pick_it->mPickCallback)
-		{
-			pick_it->mPickCallback(*pick_it);
-		}
-	}
-	mPicks.clear();
+    std::vector<LLPickInfo>::iterator pick_it;
+    for (pick_it = mPicks.begin(); pick_it != mPicks.end(); ++pick_it)
+    {
+        mLastPick = *pick_it;
+        // just trigger callback with empty results
+        if (pick_it->mPickCallback)
+        {
+            pick_it->mPickCallback(*pick_it);
+        }
+    }
+    mPicks.clear();
 }
 
 // Performs the GL object/land pick.
 LLPickInfo LLViewerWindow::pickImmediate(S32 x, S32 y_from_bot, BOOL pick_transparent, BOOL pick_rigged, BOOL pick_particle, BOOL pick_unselectable, BOOL pick_reflection_probe)
 {
-	BOOL in_build_mode = LLFloaterReg::instanceVisible("build");
-	if ((in_build_mode && gSavedSettings.getBOOL("SelectInvisibleObjects")) || LLDrawPoolAlpha::sShowDebugAlpha)
-	{
-		// build mode allows interaction with all transparent objects
-		// "Show Debug Alpha" means no object actually transparent
-		pick_transparent = TRUE;
-	}
-	
-	// shortcut queueing in mPicks and just update mLastPick in place
-	MASK	key_mask = gKeyboard->currentMask(TRUE);
-	mLastPick = LLPickInfo(LLCoordGL(x, y_from_bot), key_mask, pick_transparent, pick_rigged, pick_particle, pick_reflection_probe, TRUE, FALSE, NULL);
-	mLastPick.fetchResults();
+    BOOL in_build_mode = LLFloaterReg::instanceVisible("build");
+    if ((in_build_mode && gSavedSettings.getBOOL("SelectInvisibleObjects")) || LLDrawPoolAlpha::sShowDebugAlpha)
+    {
+        // build mode allows interaction with all transparent objects
+        // "Show Debug Alpha" means no object actually transparent
+        pick_transparent = TRUE;
+    }
 
-	return mLastPick;
+    // shortcut queueing in mPicks and just update mLastPick in place
+    MASK    key_mask = gKeyboard->currentMask(TRUE);
+    mLastPick = LLPickInfo(LLCoordGL(x, y_from_bot), key_mask, pick_transparent, pick_rigged, pick_particle, pick_reflection_probe, TRUE, FALSE, NULL);
+    mLastPick.fetchResults();
+
+    return mLastPick;
 }
 
 LLHUDIcon* LLViewerWindow::cursorIntersectIcon(S32 mouse_x, S32 mouse_y, F32 depth,
-										   LLVector4a* intersection)
+                                           LLVector4a* intersection)
 {
-	S32 x = mouse_x;
-	S32 y = mouse_y;
+    S32 x = mouse_x;
+    S32 y = mouse_y;
+
+    if ((mouse_x == -1) && (mouse_y == -1)) // use current mouse position
+    {
+        x = getCurrentMouseX();
+        y = getCurrentMouseY();
+    }
 
-	if ((mouse_x == -1) && (mouse_y == -1)) // use current mouse position
-	{
-		x = getCurrentMouseX();
-		y = getCurrentMouseY();
-	}
+    // world coordinates of mouse
+    // VECTORIZE THIS
+    LLVector3 mouse_direction_global = mouseDirectionGlobal(x,y);
+    LLVector3 mouse_point_global = LLViewerCamera::getInstance()->getOrigin();
+    LLVector3 mouse_world_start = mouse_point_global;
+    LLVector3 mouse_world_end   = mouse_point_global + mouse_direction_global * depth;
 
-	// world coordinates of mouse
-	// VECTORIZE THIS
-	LLVector3 mouse_direction_global = mouseDirectionGlobal(x,y);
-	LLVector3 mouse_point_global = LLViewerCamera::getInstance()->getOrigin();
-	LLVector3 mouse_world_start = mouse_point_global;
-	LLVector3 mouse_world_end   = mouse_point_global + mouse_direction_global * depth;
+    LLVector4a start, end;
+    start.load3(mouse_world_start.mV);
+    end.load3(mouse_world_end.mV);
 
-	LLVector4a start, end;
-	start.load3(mouse_world_start.mV);
-	end.load3(mouse_world_end.mV);
-	
-	return LLHUDIcon::lineSegmentIntersectAll(start, end, intersection);
+    return LLHUDIcon::lineSegmentIntersectAll(start, end, intersection);
 }
 
 LLViewerObject* LLViewerWindow::cursorIntersect(S32 mouse_x, S32 mouse_y, F32 depth,
-												LLViewerObject *this_object,
-												S32 this_face,
-												BOOL pick_transparent,
-												BOOL pick_rigged,
+                                                LLViewerObject *this_object,
+                                                S32 this_face,
+                                                BOOL pick_transparent,
+                                                BOOL pick_rigged,
                                                 BOOL pick_unselectable,
                                                 BOOL pick_reflection_probe,
-												S32* face_hit,
+                                                S32* face_hit,
                                                 S32* gltf_node_hit,
                                                 S32* gltf_primitive_hit,
-												LLVector4a *intersection,
-												LLVector2 *uv,
-												LLVector4a *normal,
-												LLVector4a *tangent,
-												LLVector4a* start,
-												LLVector4a* end)
-{
-	S32 x = mouse_x;
-	S32 y = mouse_y;
-
-	if ((mouse_x == -1) && (mouse_y == -1)) // use current mouse position
-	{
-		x = getCurrentMouseX();
-		y = getCurrentMouseY();
-	}
-
-	// HUD coordinates of mouse
-	LLVector3 mouse_point_hud = mousePointHUD(x, y);
-	LLVector3 mouse_hud_start = mouse_point_hud - LLVector3(depth, 0, 0);
-	LLVector3 mouse_hud_end   = mouse_point_hud + LLVector3(depth, 0, 0);
-	
-	// world coordinates of mouse
-	LLVector3 mouse_direction_global = mouseDirectionGlobal(x,y);
-	LLVector3 mouse_point_global = LLViewerCamera::getInstance()->getOrigin();
-	
-	//get near clip plane
-	LLVector3 n = LLViewerCamera::getInstance()->getAtAxis();
-	LLVector3 p = mouse_point_global + n * LLViewerCamera::getInstance()->getNear();
-
-	//project mouse point onto plane
-	LLVector3 pos;
-	line_plane(mouse_point_global, mouse_direction_global, p, n, pos);
-	mouse_point_global = pos;
-
-	LLVector3 mouse_world_start = mouse_point_global;
-	LLVector3 mouse_world_end   = mouse_point_global + mouse_direction_global * depth;
-
-	if (!LLViewerJoystick::getInstance()->getOverrideCamera() && !gPipeline.RenderFocusPointFollowsPointer)
-	{ //always set raycast intersection to mouse_world_end unless
-		//flycam is on (for DoF effect)
-		gDebugRaycastIntersection.load3(mouse_world_end.mV);
-	}
-
-	LLVector4a mw_start;
-	mw_start.load3(mouse_world_start.mV);
-	LLVector4a mw_end;
-	mw_end.load3(mouse_world_end.mV);
-
-	LLVector4a mh_start;
-	mh_start.load3(mouse_hud_start.mV);
-	LLVector4a mh_end;
-	mh_end.load3(mouse_hud_end.mV);
-
-	if (start)
-	{
-		*start = mw_start;
-	}
-
-	if (end)
-	{
-		*end = mw_end;
-	}
-
-	LLViewerObject* found = NULL;
-
-	if (this_object)  // check only this object
-	{
-		if (this_object->isHUDAttachment()) // is a HUD object?
-		{
-			if (this_object->lineSegmentIntersect(mh_start, mh_end, this_face, pick_transparent, pick_rigged, pick_unselectable,
-												  face_hit, intersection, uv, normal, tangent))
-			{
-				found = this_object;
-			}
-		}
-		else // is a world object
-		{
+                                                LLVector4a *intersection,
+                                                LLVector2 *uv,
+                                                LLVector4a *normal,
+                                                LLVector4a *tangent,
+                                                LLVector4a* start,
+                                                LLVector4a* end)
+{
+    S32 x = mouse_x;
+    S32 y = mouse_y;
+
+    if ((mouse_x == -1) && (mouse_y == -1)) // use current mouse position
+    {
+        x = getCurrentMouseX();
+        y = getCurrentMouseY();
+    }
+
+    // HUD coordinates of mouse
+    LLVector3 mouse_point_hud = mousePointHUD(x, y);
+    LLVector3 mouse_hud_start = mouse_point_hud - LLVector3(depth, 0, 0);
+    LLVector3 mouse_hud_end   = mouse_point_hud + LLVector3(depth, 0, 0);
+
+    // world coordinates of mouse
+    LLVector3 mouse_direction_global = mouseDirectionGlobal(x,y);
+    LLVector3 mouse_point_global = LLViewerCamera::getInstance()->getOrigin();
+
+    //get near clip plane
+    LLVector3 n = LLViewerCamera::getInstance()->getAtAxis();
+    LLVector3 p = mouse_point_global + n * LLViewerCamera::getInstance()->getNear();
+
+    //project mouse point onto plane
+    LLVector3 pos;
+    line_plane(mouse_point_global, mouse_direction_global, p, n, pos);
+    mouse_point_global = pos;
+
+    LLVector3 mouse_world_start = mouse_point_global;
+    LLVector3 mouse_world_end   = mouse_point_global + mouse_direction_global * depth;
+
+    if (!LLViewerJoystick::getInstance()->getOverrideCamera() && !gPipeline.RenderFocusPointFollowsPointer)
+    { //always set raycast intersection to mouse_world_end unless
+        //flycam is on (for DoF effect)
+        gDebugRaycastIntersection.load3(mouse_world_end.mV);
+    }
+
+    LLVector4a mw_start;
+    mw_start.load3(mouse_world_start.mV);
+    LLVector4a mw_end;
+    mw_end.load3(mouse_world_end.mV);
+
+    LLVector4a mh_start;
+    mh_start.load3(mouse_hud_start.mV);
+    LLVector4a mh_end;
+    mh_end.load3(mouse_hud_end.mV);
+
+    if (start)
+    {
+        *start = mw_start;
+    }
+
+    if (end)
+    {
+        *end = mw_end;
+    }
+
+    LLViewerObject* found = NULL;
+
+    if (this_object)  // check only this object
+    {
+        if (this_object->isHUDAttachment()) // is a HUD object?
+        {
+            if (this_object->lineSegmentIntersect(mh_start, mh_end, this_face, pick_transparent, pick_rigged, pick_unselectable,
+                                                  face_hit, intersection, uv, normal, tangent))
+            {
+                found = this_object;
+            }
+        }
+        else // is a world object
+        {
             if ((pick_reflection_probe || !this_object->isReflectionProbe())
                 && this_object->lineSegmentIntersect(mw_start, mw_end, this_face, pick_transparent, pick_rigged, pick_unselectable,
-												  face_hit, intersection, uv, normal, tangent))
-			{
-				found = this_object;
-			}
-		}
-	}
-	else // check ALL objects
-	{
-		found = gPipeline.lineSegmentIntersectInHUD(mh_start, mh_end, pick_transparent,
-													face_hit, intersection, uv, normal, tangent);
+                                                  face_hit, intersection, uv, normal, tangent))
+            {
+                found = this_object;
+            }
+        }
+    }
+    else // check ALL objects
+    {
+        found = gPipeline.lineSegmentIntersectInHUD(mh_start, mh_end, pick_transparent,
+                                                    face_hit, intersection, uv, normal, tangent);
 
 // [RLVa:KB] - Checked: 2010-03-31 (RLVa-1.2.0c) | Modified: RLVa-1.2.0c
-		if ( (rlv_handler_t::isEnabled()) && (found) &&
-			 (LLToolCamera::getInstance()->hasMouseCapture()) && (gKeyboard->currentMask(TRUE) & MASK_ALT) )
-		{
-			found = NULL;
-		}
+        if ( (rlv_handler_t::isEnabled()) && (found) &&
+             (LLToolCamera::getInstance()->hasMouseCapture()) && (gKeyboard->currentMask(TRUE) & MASK_ALT) )
+        {
+            found = NULL;
+        }
 // [/RLVa:KB]
-		if (!found) // if not found in HUD, look in world:
-		{
-			found = gPipeline.lineSegmentIntersectInWorld(mw_start, mw_end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe,
-														  face_hit, gltf_node_hit, gltf_primitive_hit, intersection, uv, normal, tangent);
-			if (found && !pick_transparent)
-			{
-				gDebugRaycastIntersection = *intersection;
-			}
-		}
+        if (!found) // if not found in HUD, look in world:
+        {
+            found = gPipeline.lineSegmentIntersectInWorld(mw_start, mw_end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe,
+                                                          face_hit, gltf_node_hit, gltf_primitive_hit, intersection, uv, normal, tangent);
+            if (found && !pick_transparent)
+            {
+                gDebugRaycastIntersection = *intersection;
+            }
+        }
 
 // [RLVa:KB] - Checked: RLVa-1.2.0
-		if ( (found) && ((gTeleportDisplay) || ((rlv_handler_t::isEnabled()) && (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT)))) )
-		{
-			// Allow picking if:
-			//   - the drag-and-drop tool is active (allows inventory offers)
-			//   - the camera tool is active
-			//   - the pie tool is active *and* we picked our own avie (allows "mouse steering" and the self pie menu)
-			LLTool* pCurTool = LLToolMgr::getInstance()->getCurrentTool();
-			if ( (LLToolDragAndDrop::getInstance() != pCurTool) &&
-			     (!LLToolCamera::getInstance()->hasMouseCapture()) &&
-			     ((LLToolPie::getInstance() != pCurTool) || (gAgent.getID() != found->getID())) )
-			{
-				found = NULL;
-			}
-		}
+        if ( (found) && ((gTeleportDisplay) || ((rlv_handler_t::isEnabled()) && (gRlvHandler.hasBehaviour(RLV_BHVR_INTERACT)))) )
+        {
+            // Allow picking if:
+            //   - the drag-and-drop tool is active (allows inventory offers)
+            //   - the camera tool is active
+            //   - the pie tool is active *and* we picked our own avie (allows "mouse steering" and the self pie menu)
+            LLTool* pCurTool = LLToolMgr::getInstance()->getCurrentTool();
+            if ( (LLToolDragAndDrop::getInstance() != pCurTool) &&
+                 (!LLToolCamera::getInstance()->hasMouseCapture()) &&
+                 ((LLToolPie::getInstance() != pCurTool) || (gAgent.getID() != found->getID())) )
+            {
+                found = NULL;
+            }
+        }
 // [/RLVa:KB]
-	}
+    }
 
-	return found;
+    return found;
 }
 
 // Returns unit vector relative to camera
 // indicating direction of point on screen x,y
 LLVector3 LLViewerWindow::mouseDirectionGlobal(const S32 x, const S32 y) const
 {
-	auto& viewerCamera = LLViewerCamera::instance();
+    auto& viewerCamera = LLViewerCamera::instance();
 
-	// find vertical field of view
-	F32			fov = viewerCamera.getView();
+    // find vertical field of view
+    F32         fov = viewerCamera.getView();
 
-	// find world view center in scaled ui coordinates
-	F32			center_x = getWorldViewRectScaled().getCenterX();
-	F32			center_y = getWorldViewRectScaled().getCenterY();
+    // find world view center in scaled ui coordinates
+    F32         center_x = getWorldViewRectScaled().getCenterX();
+    F32         center_y = getWorldViewRectScaled().getCenterY();
 
-	// calculate pixel distance to screen
-	F32			distance = ((F32)getWorldViewHeightScaled() * 0.5f) / (tan(fov / 2.f));
+    // calculate pixel distance to screen
+    F32         distance = ((F32)getWorldViewHeightScaled() * 0.5f) / (tan(fov / 2.f));
 
-	// calculate click point relative to middle of screen
-	F32			click_x = x - center_x;
-	F32			click_y = y - center_y;
+    // calculate click point relative to middle of screen
+    F32         click_x = x - center_x;
+    F32         click_y = y - center_y;
 
-	// compute mouse vector
-	LLVector3	mouse_vector =	distance * viewerCamera.getAtAxis()
-								- click_x * viewerCamera.getLeftAxis()
-								+ click_y * viewerCamera.getUpAxis();
+    // compute mouse vector
+    LLVector3   mouse_vector =  distance * viewerCamera.getAtAxis()
+                                - click_x * viewerCamera.getLeftAxis()
+                                + click_y * viewerCamera.getUpAxis();
 
-	mouse_vector.normVec();
+    mouse_vector.normVec();
 
-	return mouse_vector;
+    return mouse_vector;
 }
 
 LLVector3 LLViewerWindow::mousePointHUD(const S32 x, const S32 y) const
 {
-	// find screen resolution
-	S32			height = getWorldViewHeightScaled();
+    // find screen resolution
+    S32         height = getWorldViewHeightScaled();
 
-	// find world view center
-	F32			center_x = getWorldViewRectScaled().getCenterX();
-	F32			center_y = getWorldViewRectScaled().getCenterY();
+    // find world view center
+    F32         center_x = getWorldViewRectScaled().getCenterX();
+    F32         center_y = getWorldViewRectScaled().getCenterY();
 
-	// remap with uniform scale (1/height) so that top is -0.5, bottom is +0.5
-	F32 hud_x = -((F32)x - center_x)  / height;
-	F32 hud_y = ((F32)y - center_y) / height;
+    // remap with uniform scale (1/height) so that top is -0.5, bottom is +0.5
+    F32 hud_x = -((F32)x - center_x)  / height;
+    F32 hud_y = ((F32)y - center_y) / height;
 
-	return LLVector3(0.f, hud_x/gAgentCamera.mHUDCurZoom, hud_y/gAgentCamera.mHUDCurZoom);
+    return LLVector3(0.f, hud_x/gAgentCamera.mHUDCurZoom, hud_y/gAgentCamera.mHUDCurZoom);
 }
 
 // Returns unit vector relative to camera in camera space
 // indicating direction of point on screen x,y
 LLVector3 LLViewerWindow::mouseDirectionCamera(const S32 x, const S32 y) const
 {
-	auto& viewerCamera = LLViewerCamera::instance();
+    auto& viewerCamera = LLViewerCamera::instance();
 
-	// find vertical field of view
-	F32			fov_height = viewerCamera.getView();
-	F32			fov_width = fov_height * viewerCamera.getAspect();
+    // find vertical field of view
+    F32         fov_height = viewerCamera.getView();
+    F32         fov_width = fov_height * viewerCamera.getAspect();
 
-	// find screen resolution
-	S32			height = getWorldViewHeightScaled();
-	S32			width = getWorldViewWidthScaled();
+    // find screen resolution
+    S32         height = getWorldViewHeightScaled();
+    S32         width = getWorldViewWidthScaled();
 
-	// find world view center
-	F32			center_x = getWorldViewRectScaled().getCenterX();
-	F32			center_y = getWorldViewRectScaled().getCenterY();
+    // find world view center
+    F32         center_x = getWorldViewRectScaled().getCenterX();
+    F32         center_y = getWorldViewRectScaled().getCenterY();
 
-	// calculate click point relative to middle of screen
-	F32			click_x = (((F32)x - center_x) / (F32)width) * fov_width * -1.f;
-	F32			click_y = (((F32)y - center_y) / (F32)height) * fov_height;
+    // calculate click point relative to middle of screen
+    F32         click_x = (((F32)x - center_x) / (F32)width) * fov_width * -1.f;
+    F32         click_y = (((F32)y - center_y) / (F32)height) * fov_height;
 
-	// compute mouse vector
-	LLVector3	mouse_vector =	LLVector3(0.f, 0.f, -1.f);
-	LLQuaternion mouse_rotate;
-	mouse_rotate.setQuat(click_y, click_x, 0.f);
+    // compute mouse vector
+    LLVector3   mouse_vector =  LLVector3(0.f, 0.f, -1.f);
+    LLQuaternion mouse_rotate;
+    mouse_rotate.setQuat(click_y, click_x, 0.f);
 
-	mouse_vector = mouse_vector * mouse_rotate;
-	// project to z = -1 plane;
-	mouse_vector = mouse_vector * (-1.f / mouse_vector.mV[VZ]);
+    mouse_vector = mouse_vector * mouse_rotate;
+    // project to z = -1 plane;
+    mouse_vector = mouse_vector * (-1.f / mouse_vector.mV[VZ]);
 
-	return mouse_vector;
+    return mouse_vector;
 }
 
 
 
-BOOL LLViewerWindow::mousePointOnPlaneGlobal(LLVector3d& point, const S32 x, const S32 y, 
-										const LLVector3d &plane_point_global, 
-										const LLVector3 &plane_normal_global)
+BOOL LLViewerWindow::mousePointOnPlaneGlobal(LLVector3d& point, const S32 x, const S32 y,
+                                        const LLVector3d &plane_point_global,
+                                        const LLVector3 &plane_normal_global)
 {
-	LLVector3d	mouse_direction_global_d;
+    LLVector3d  mouse_direction_global_d;
+
+    mouse_direction_global_d.setVec(mouseDirectionGlobal(x,y));
+    LLVector3d  plane_normal_global_d;
+    plane_normal_global_d.setVec(plane_normal_global);
+    F64 plane_mouse_dot = (plane_normal_global_d * mouse_direction_global_d);
+    LLVector3d plane_origin_camera_rel = plane_point_global - gAgentCamera.getCameraPositionGlobal();
+    F64 mouse_look_at_scale = (plane_normal_global_d * plane_origin_camera_rel)
+                                / plane_mouse_dot;
+    if (llabs(plane_mouse_dot) < 0.00001)
+    {
+        // if mouse is parallel to plane, return closest point on line through plane origin
+        // that is parallel to camera plane by scaling mouse direction vector
+        // by distance to plane origin, modulated by deviation of mouse direction from plane origin
+        LLVector3d plane_origin_dir = plane_origin_camera_rel;
+        plane_origin_dir.normVec();
 
-	mouse_direction_global_d.setVec(mouseDirectionGlobal(x,y));
-	LLVector3d	plane_normal_global_d;
-	plane_normal_global_d.setVec(plane_normal_global);
-	F64 plane_mouse_dot = (plane_normal_global_d * mouse_direction_global_d);
-	LLVector3d plane_origin_camera_rel = plane_point_global - gAgentCamera.getCameraPositionGlobal();
-	F64	mouse_look_at_scale = (plane_normal_global_d * plane_origin_camera_rel)
-								/ plane_mouse_dot;
-	if (llabs(plane_mouse_dot) < 0.00001)
-	{
-		// if mouse is parallel to plane, return closest point on line through plane origin
-		// that is parallel to camera plane by scaling mouse direction vector
-		// by distance to plane origin, modulated by deviation of mouse direction from plane origin
-		LLVector3d plane_origin_dir = plane_origin_camera_rel;
-		plane_origin_dir.normVec();
-		
-		mouse_look_at_scale = plane_origin_camera_rel.magVec() / (plane_origin_dir * mouse_direction_global_d);
-	}
+        mouse_look_at_scale = plane_origin_camera_rel.magVec() / (plane_origin_dir * mouse_direction_global_d);
+    }
 
-	point = gAgentCamera.getCameraPositionGlobal() + mouse_look_at_scale * mouse_direction_global_d;
+    point = gAgentCamera.getCameraPositionGlobal() + mouse_look_at_scale * mouse_direction_global_d;
 
-	return mouse_look_at_scale > 0.0;
+    return mouse_look_at_scale > 0.0;
 }
 
 
 // Returns global position
 BOOL LLViewerWindow::mousePointOnLandGlobal(const S32 x, const S32 y, LLVector3d *land_position_global, BOOL ignore_distance)
 {
-	LLVector3		mouse_direction_global = mouseDirectionGlobal(x,y);
-	F32				mouse_dir_scale;
-	BOOL			hit_land = FALSE;
-	LLViewerRegion	*regionp;
-	F32			land_z;
-	const F32	FIRST_PASS_STEP = 1.0f;		// meters
-	const F32	SECOND_PASS_STEP = 0.1f;	// meters
-	const F32	draw_distance = ignore_distance ? MAX_FAR_CLIP : gAgentCamera.mDrawDistance;
-	LLVector3d	camera_pos_global;
-
-	camera_pos_global = gAgentCamera.getCameraPositionGlobal();
-	LLVector3d		probe_point_global;
-	LLVector3		probe_point_region;
-
-	// walk forwards to find the point
-	for (mouse_dir_scale = FIRST_PASS_STEP; mouse_dir_scale < draw_distance; mouse_dir_scale += FIRST_PASS_STEP)
-	{
-		LLVector3d mouse_direction_global_d;
-		mouse_direction_global_d.setVec(mouse_direction_global * mouse_dir_scale);
-		probe_point_global = camera_pos_global + mouse_direction_global_d;
-
-		regionp = LLWorld::getInstance()->resolveRegionGlobal(probe_point_region, probe_point_global);
-
-		if (!regionp)
-		{
-			// ...we're outside the world somehow
-			continue;
-		}
-
-		S32 i = (S32) (probe_point_region.mV[VX]/regionp->getLand().getMetersPerGrid());
-		S32 j = (S32) (probe_point_region.mV[VY]/regionp->getLand().getMetersPerGrid());
-		S32 grids_per_edge = (S32) regionp->getLand().mGridsPerEdge;
-		if ((i >= grids_per_edge) || (j >= grids_per_edge))
-		{
-			//LL_INFOS() << "LLViewerWindow::mousePointOnLand probe_point is out of region" << LL_ENDL;
-			continue;
-		}
-
-		land_z = regionp->getLand().resolveHeightRegion(probe_point_region);
-
-		//LL_INFOS() << "mousePointOnLand initial z " << land_z << LL_ENDL;
-
-		if (probe_point_region.mV[VZ] < land_z)
-		{
-			// ...just went under land
-
-			// cout << "under land at " << probe_point << " scale " << mouse_vec_scale << endl;
-
-			hit_land = TRUE;
-			break;
-		}
-	}
-
-
-	if (hit_land)
-	{
-		// Don't go more than one step beyond where we stopped above.
-		// This can't just be "mouse_vec_scale" because floating point error
-		// will stop the loop before the last increment.... X - 1.0 + 0.1 + 0.1 + ... + 0.1 != X
-		F32 stop_mouse_dir_scale = mouse_dir_scale + FIRST_PASS_STEP;
-
-		// take a step backwards, then walk forwards again to refine position
-		for ( mouse_dir_scale -= FIRST_PASS_STEP; mouse_dir_scale <= stop_mouse_dir_scale; mouse_dir_scale += SECOND_PASS_STEP)
-		{
-			LLVector3d mouse_direction_global_d;
-			mouse_direction_global_d.setVec(mouse_direction_global * mouse_dir_scale);
-			probe_point_global = camera_pos_global + mouse_direction_global_d;
-
-			regionp = LLWorld::getInstance()->resolveRegionGlobal(probe_point_region, probe_point_global);
-
-			if (!regionp)
-			{
-				// ...we're outside the world somehow
-				continue;
-			}
-
-			/*
-			i = (S32) (local_probe_point.mV[VX]/regionp->getLand().getMetersPerGrid());
-			j = (S32) (local_probe_point.mV[VY]/regionp->getLand().getMetersPerGrid());
-			if ((i >= regionp->getLand().mGridsPerEdge) || (j >= regionp->getLand().mGridsPerEdge))
-			{
-				// LL_INFOS() << "LLViewerWindow::mousePointOnLand probe_point is out of region" << LL_ENDL;
-				continue;
-			}
-			land_z = regionp->getLand().mSurfaceZ[ i + j * (regionp->getLand().mGridsPerEdge) ];
-			*/
-
-			land_z = regionp->getLand().resolveHeightRegion(probe_point_region);
-
-			//LL_INFOS() << "mousePointOnLand refine z " << land_z << LL_ENDL;
-
-			if (probe_point_region.mV[VZ] < land_z)
-			{
-				// ...just went under land again
-
-				*land_position_global = probe_point_global;
-				return TRUE;
-			}
-		}
-	}
-
-	return FALSE;
+    LLVector3       mouse_direction_global = mouseDirectionGlobal(x,y);
+    F32             mouse_dir_scale;
+    BOOL            hit_land = FALSE;
+    LLViewerRegion  *regionp;
+    F32         land_z;
+    const F32   FIRST_PASS_STEP = 1.0f;     // meters
+    const F32   SECOND_PASS_STEP = 0.1f;    // meters
+    const F32   draw_distance = ignore_distance ? MAX_FAR_CLIP : gAgentCamera.mDrawDistance;
+    LLVector3d  camera_pos_global;
+
+    camera_pos_global = gAgentCamera.getCameraPositionGlobal();
+    LLVector3d      probe_point_global;
+    LLVector3       probe_point_region;
+
+    // walk forwards to find the point
+    for (mouse_dir_scale = FIRST_PASS_STEP; mouse_dir_scale < draw_distance; mouse_dir_scale += FIRST_PASS_STEP)
+    {
+        LLVector3d mouse_direction_global_d;
+        mouse_direction_global_d.setVec(mouse_direction_global * mouse_dir_scale);
+        probe_point_global = camera_pos_global + mouse_direction_global_d;
+
+        regionp = LLWorld::getInstance()->resolveRegionGlobal(probe_point_region, probe_point_global);
+
+        if (!regionp)
+        {
+            // ...we're outside the world somehow
+            continue;
+        }
+
+        S32 i = (S32) (probe_point_region.mV[VX]/regionp->getLand().getMetersPerGrid());
+        S32 j = (S32) (probe_point_region.mV[VY]/regionp->getLand().getMetersPerGrid());
+        S32 grids_per_edge = (S32) regionp->getLand().mGridsPerEdge;
+        if ((i >= grids_per_edge) || (j >= grids_per_edge))
+        {
+            //LL_INFOS() << "LLViewerWindow::mousePointOnLand probe_point is out of region" << LL_ENDL;
+            continue;
+        }
+
+        land_z = regionp->getLand().resolveHeightRegion(probe_point_region);
+
+        //LL_INFOS() << "mousePointOnLand initial z " << land_z << LL_ENDL;
+
+        if (probe_point_region.mV[VZ] < land_z)
+        {
+            // ...just went under land
+
+            // cout << "under land at " << probe_point << " scale " << mouse_vec_scale << endl;
+
+            hit_land = TRUE;
+            break;
+        }
+    }
+
+
+    if (hit_land)
+    {
+        // Don't go more than one step beyond where we stopped above.
+        // This can't just be "mouse_vec_scale" because floating point error
+        // will stop the loop before the last increment.... X - 1.0 + 0.1 + 0.1 + ... + 0.1 != X
+        F32 stop_mouse_dir_scale = mouse_dir_scale + FIRST_PASS_STEP;
+
+        // take a step backwards, then walk forwards again to refine position
+        for ( mouse_dir_scale -= FIRST_PASS_STEP; mouse_dir_scale <= stop_mouse_dir_scale; mouse_dir_scale += SECOND_PASS_STEP)
+        {
+            LLVector3d mouse_direction_global_d;
+            mouse_direction_global_d.setVec(mouse_direction_global * mouse_dir_scale);
+            probe_point_global = camera_pos_global + mouse_direction_global_d;
+
+            regionp = LLWorld::getInstance()->resolveRegionGlobal(probe_point_region, probe_point_global);
+
+            if (!regionp)
+            {
+                // ...we're outside the world somehow
+                continue;
+            }
+
+            /*
+            i = (S32) (local_probe_point.mV[VX]/regionp->getLand().getMetersPerGrid());
+            j = (S32) (local_probe_point.mV[VY]/regionp->getLand().getMetersPerGrid());
+            if ((i >= regionp->getLand().mGridsPerEdge) || (j >= regionp->getLand().mGridsPerEdge))
+            {
+                // LL_INFOS() << "LLViewerWindow::mousePointOnLand probe_point is out of region" << LL_ENDL;
+                continue;
+            }
+            land_z = regionp->getLand().mSurfaceZ[ i + j * (regionp->getLand().mGridsPerEdge) ];
+            */
+
+            land_z = regionp->getLand().resolveHeightRegion(probe_point_region);
+
+            //LL_INFOS() << "mousePointOnLand refine z " << land_z << LL_ENDL;
+
+            if (probe_point_region.mV[VZ] < land_z)
+            {
+                // ...just went under land again
+
+                *land_position_global = probe_point_global;
+                return TRUE;
+            }
+        }
+    }
+
+    return FALSE;
 }
 
 // Saves an image to the harddrive as "SnapshotX" where X >= 1.
 void LLViewerWindow::saveImageNumbered(LLImageFormatted *image, BOOL force_picker, const snapshot_saved_signal_t::slot_type& success_cb, const snapshot_saved_signal_t::slot_type& failure_cb)
 {
-	if (!image)
-	{
-		LL_WARNS() << "No image to save" << LL_ENDL;
-		return;
-	}
-	std::string extension("." + image->getExtension());
-	LLImageFormatted* formatted_image = image;
-	// Get a base file location if needed.
-	if (force_picker || !isSnapshotLocSet())
-	{
-        static LLCachedControl<std::string>	sSnapshotBaseName(LLCachedControl<std::string>(gSavedPerAccountSettings, "SnapshotBaseName", "Snapshot"));
-		std::string proposed_name(sSnapshotBaseName);
-
-		// getSaveFile will append an appropriate extension to the proposed name, based on the ESaveFilter constant passed in.
-		LLFilePicker::ESaveFilter pick_type;
-
-		if (extension == ".j2c")
-			pick_type = LLFilePicker::FFSAVE_J2C;
-		else if (extension == ".bmp")
-			pick_type = LLFilePicker::FFSAVE_BMP;
-		else if (extension == ".jpg")
-			pick_type = LLFilePicker::FFSAVE_JPEG;
-		else if (extension == ".png")
-			pick_type = LLFilePicker::FFSAVE_PNG;
-		else if (extension == ".tga")
-			pick_type = LLFilePicker::FFSAVE_TGA;
-		else if (extension == ".webp")
-			pick_type = LLFilePicker::FFSAVE_WEBP;
-		else
-			pick_type = LLFilePicker::FFSAVE_ALL;
-
-		LLFilePickerReplyThread::startPicker(boost::bind(&LLViewerWindow::onDirectorySelected, this, _1, formatted_image, success_cb, failure_cb), pick_type, proposed_name,
-										boost::bind(&LLViewerWindow::onSelectionFailure, this, failure_cb));
-	}
-	else
-	{
-		saveImageLocal(formatted_image, success_cb, failure_cb);
-	}	
+    if (!image)
+    {
+        LL_WARNS() << "No image to save" << LL_ENDL;
+        return;
+    }
+    std::string extension("." + image->getExtension());
+    LLImageFormatted* formatted_image = image;
+    // Get a base file location if needed.
+    if (force_picker || !isSnapshotLocSet())
+    {
+        static LLCachedControl<std::string> sSnapshotBaseName(LLCachedControl<std::string>(gSavedPerAccountSettings, "SnapshotBaseName", "Snapshot"));
+        std::string proposed_name(sSnapshotBaseName);
+
+        // getSaveFile will append an appropriate extension to the proposed name, based on the ESaveFilter constant passed in.
+        LLFilePicker::ESaveFilter pick_type;
+
+        if (extension == ".j2c")
+            pick_type = LLFilePicker::FFSAVE_J2C;
+        else if (extension == ".bmp")
+            pick_type = LLFilePicker::FFSAVE_BMP;
+        else if (extension == ".jpg")
+            pick_type = LLFilePicker::FFSAVE_JPEG;
+        else if (extension == ".png")
+            pick_type = LLFilePicker::FFSAVE_PNG;
+        else if (extension == ".tga")
+            pick_type = LLFilePicker::FFSAVE_TGA;
+        else if (extension == ".webp")
+            pick_type = LLFilePicker::FFSAVE_WEBP;
+        else
+            pick_type = LLFilePicker::FFSAVE_ALL;
+
+        LLFilePickerReplyThread::startPicker(boost::bind(&LLViewerWindow::onDirectorySelected, this, _1, formatted_image, success_cb, failure_cb), pick_type, proposed_name,
+                                        boost::bind(&LLViewerWindow::onSelectionFailure, this, failure_cb));
+    }
+    else
+    {
+        saveImageLocal(formatted_image, success_cb, failure_cb);
+    }
 }
 
 void LLViewerWindow::onDirectorySelected(const std::vector<std::string>& filenames, LLImageFormatted *image, const snapshot_saved_signal_t::slot_type& success_cb, const snapshot_saved_signal_t::slot_type& failure_cb)
 {
-	// Copy the directory + file name
-	std::string filepath = filenames[0];
+    // Copy the directory + file name
+    std::string filepath = filenames[0];
 
-	gSavedPerAccountSettings.setString("SnapshotBaseName", gDirUtilp->getBaseFileName(filepath, true));
-	gSavedPerAccountSettings.setString("SnapshotBaseDir", gDirUtilp->getDirName(filepath));
-	saveImageLocal(image, success_cb, failure_cb);
+    gSavedPerAccountSettings.setString("SnapshotBaseName", gDirUtilp->getBaseFileName(filepath, true));
+    gSavedPerAccountSettings.setString("SnapshotBaseDir", gDirUtilp->getDirName(filepath));
+    saveImageLocal(image, success_cb, failure_cb);
 }
 
 void LLViewerWindow::onSelectionFailure(const snapshot_saved_signal_t::slot_type& failure_cb)
 {
-	failure_cb();
+    failure_cb();
 }
 
 
 void LLViewerWindow::saveImageLocal(LLImageFormatted *image, const snapshot_saved_signal_t::slot_type& success_cb, const snapshot_saved_signal_t::slot_type& failure_cb)
 {
-	std::string lastSnapshotDir = LLViewerWindow::getLastSnapshotDir();
-	if (lastSnapshotDir.empty())
-	{
-		failure_cb();
-		return;
-	}
+    std::string lastSnapshotDir = LLViewerWindow::getLastSnapshotDir();
+    if (lastSnapshotDir.empty())
+    {
+        failure_cb();
+        return;
+    }
 
-	// Check if there is enough free space to save snapshot
-	boost::system::error_code ec;
+    // Check if there is enough free space to save snapshot
+    boost::system::error_code ec;
 #ifdef LL_WINDOWS
-	boost::filesystem::path b_path(ll_convert_string_to_wide(lastSnapshotDir));
+    boost::filesystem::path b_path(ll_convert_string_to_wide(lastSnapshotDir));
 #else
-	boost::filesystem::path b_path(lastSnapshotDir);
+    boost::filesystem::path b_path(lastSnapshotDir);
 #endif
-	bool is_dir = boost::filesystem::is_directory(b_path, ec);
-	if (!is_dir || ec.failed())
-	{
-		LLSD args;
-		args["PATH"] = lastSnapshotDir;
-		LLNotificationsUtil::add("SnapshotToLocalDirNotExist", args);
-		resetSnapshotLoc();
-		failure_cb();
-		return;
-	}
-	boost::filesystem::space_info b_space = boost::filesystem::space(b_path, ec);
-	if (ec.failed())
-	{
-		LL_WARNS() << "Failed to read disk space for filesystem path " << lastSnapshotDir << " : " << ec.message() << LL_ENDL;
-		LLSD args;
-		args["PATH"] = lastSnapshotDir;
-		LLNotificationsUtil::add("SnapshotToLocalDirNotExist", args);
-		resetSnapshotLoc();
-		failure_cb();
-		return;
-	}
-	if (b_space.free < image->getDataSize())
-	{
-		LLSD args;
-		args["PATH"] = lastSnapshotDir;
-
-		std::string needM_bytes_string;
-		LLResMgr::getIntegerString(needM_bytes_string, (image->getDataSize()) >> 10);
-		args["NEED_MEMORY"] = needM_bytes_string;
-
-		std::string freeM_bytes_string;
-		LLResMgr::getIntegerString(freeM_bytes_string, (b_space.free) >> 10);
-		args["FREE_MEMORY"] = freeM_bytes_string;
-
-		LLNotificationsUtil::add("SnapshotToComputerFailed", args);
-
-		failure_cb();
-		return;
-	}
-	
-	// Look for an unused file name
-	BOOL is_snapshot_name_loc_set = isSnapshotLocSet();
-	std::string filepath;
-	S32 i = 1;
-	S32 err = 0;
-	std::string extension("." + image->getExtension());
-    static LLCachedControl<std::string>	sSnapshotBaseName(gSavedPerAccountSettings, "SnapshotBaseName", "Snapshot");
-    static LLCachedControl<std::string>	sSnapshotDir(gSavedPerAccountSettings, "SnapshotBaseDir", "");
-	do
-	{
-		filepath = sSnapshotDir;
-		filepath += gDirUtilp->getDirDelimiter();
-		filepath += sSnapshotBaseName;
-
-		if (is_snapshot_name_loc_set)
-		{
-			filepath += llformat("_%.3d",i);
-		}		
-
-		filepath += extension;
-
-		llstat stat_info;
-		err = LLFile::stat( filepath, &stat_info );
-		i++;
-	}
-	while( -1 != err  // Search until the file is not found (i.e., stat() gives an error).
-			&& is_snapshot_name_loc_set); // Or stop if we are rewriting.
-
-	LL_INFOS() << "Saving snapshot to " << filepath << LL_ENDL;
-	if (image->save(filepath))
-	{
-		playSnapshotAnimAndSound();
-		success_cb();
-	}
-	else
-	{
-		failure_cb();
-	}
+    bool is_dir = boost::filesystem::is_directory(b_path, ec);
+    if (!is_dir || ec.failed())
+    {
+        LLSD args;
+        args["PATH"] = lastSnapshotDir;
+        LLNotificationsUtil::add("SnapshotToLocalDirNotExist", args);
+        resetSnapshotLoc();
+        failure_cb();
+        return;
+    }
+    boost::filesystem::space_info b_space = boost::filesystem::space(b_path, ec);
+    if (ec.failed())
+    {
+        LL_WARNS() << "Failed to read disk space for filesystem path " << lastSnapshotDir << " : " << ec.message() << LL_ENDL;
+        LLSD args;
+        args["PATH"] = lastSnapshotDir;
+        LLNotificationsUtil::add("SnapshotToLocalDirNotExist", args);
+        resetSnapshotLoc();
+        failure_cb();
+        return;
+    }
+    if (b_space.free < image->getDataSize())
+    {
+        LLSD args;
+        args["PATH"] = lastSnapshotDir;
+
+        std::string needM_bytes_string;
+        LLResMgr::getIntegerString(needM_bytes_string, (image->getDataSize()) >> 10);
+        args["NEED_MEMORY"] = needM_bytes_string;
+
+        std::string freeM_bytes_string;
+        LLResMgr::getIntegerString(freeM_bytes_string, (b_space.free) >> 10);
+        args["FREE_MEMORY"] = freeM_bytes_string;
+
+        LLNotificationsUtil::add("SnapshotToComputerFailed", args);
+
+        failure_cb();
+        return;
+    }
+
+    // Look for an unused file name
+    BOOL is_snapshot_name_loc_set = isSnapshotLocSet();
+    std::string filepath;
+    S32 i = 1;
+    S32 err = 0;
+    std::string extension("." + image->getExtension());
+    static LLCachedControl<std::string> sSnapshotBaseName(gSavedPerAccountSettings, "SnapshotBaseName", "Snapshot");
+    static LLCachedControl<std::string> sSnapshotDir(gSavedPerAccountSettings, "SnapshotBaseDir", "");
+    do
+    {
+        filepath = sSnapshotDir;
+        filepath += gDirUtilp->getDirDelimiter();
+        filepath += sSnapshotBaseName;
+
+        if (is_snapshot_name_loc_set)
+        {
+            filepath += llformat("_%.3d",i);
+        }
+
+        filepath += extension;
+
+        llstat stat_info;
+        err = LLFile::stat( filepath, &stat_info );
+        i++;
+    }
+    while( -1 != err  // Search until the file is not found (i.e., stat() gives an error).
+            && is_snapshot_name_loc_set); // Or stop if we are rewriting.
+
+    LL_INFOS() << "Saving snapshot to " << filepath << LL_ENDL;
+    if (image->save(filepath))
+    {
+        playSnapshotAnimAndSound();
+        success_cb();
+    }
+    else
+    {
+        failure_cb();
+    }
 }
 
 void LLViewerWindow::resetSnapshotLoc()
 {
-	gSavedPerAccountSettings.setString("SnapshotBaseDir", std::string());
+    gSavedPerAccountSettings.setString("SnapshotBaseDir", std::string());
 }
 
 // static
 void LLViewerWindow::movieSize(S32 new_width, S32 new_height)
 {
-	LLCoordWindow size;
-	LLCoordWindow new_size(new_width, new_height);
-	gViewerWindow->getWindow()->getSize(&size);
-	if ( size != new_size )
-	{
-		gViewerWindow->getWindow()->setSize(new_size);
-	}
+    LLCoordWindow size;
+    LLCoordWindow new_size(new_width, new_height);
+    gViewerWindow->getWindow()->getSize(&size);
+    if ( size != new_size )
+    {
+        gViewerWindow->getWindow()->setSize(new_size);
+    }
 }
 
 BOOL LLViewerWindow::saveSnapshot(const std::string& filepath, S32 image_width, S32 image_height, BOOL show_ui, BOOL show_hud, BOOL do_rebuild, LLSnapshotModel::ESnapshotLayerType type, LLSnapshotModel::ESnapshotFormat format)
@@ -5225,9 +5225,9 @@ BOOL LLViewerWindow::saveSnapshot(const std::string& filepath, S32 image_width,
         case LLSnapshotModel::SNAPSHOT_FORMAT_JPEG:
             image_codec = IMG_CODEC_JPEG;
             break;
-		case LLSnapshotModel::SNAPSHOT_FORMAT_WEBP:
-			image_codec = IMG_CODEC_WEBP;
-			break;
+        case LLSnapshotModel::SNAPSHOT_FORMAT_WEBP:
+            image_codec = IMG_CODEC_WEBP;
+            break;
         default:
             image_codec = IMG_CODEC_BMP;
             break;
@@ -5255,379 +5255,379 @@ BOOL LLViewerWindow::saveSnapshot(const std::string& filepath, S32 image_width,
 
 void LLViewerWindow::playSnapshotAnimAndSound()
 {
-	if (gSavedSettings.getBOOL("QuietSnapshotsToDisk"))
-	{
-		return;
-	}
-	gAgent.sendAnimationRequest(ANIM_AGENT_SNAPSHOT, ANIM_REQUEST_START);
-	send_sound_trigger(LLUUID(gSavedSettings.getString("UISndSnapshot")), 1.0f);
+    if (gSavedSettings.getBOOL("QuietSnapshotsToDisk"))
+    {
+        return;
+    }
+    gAgent.sendAnimationRequest(ANIM_AGENT_SNAPSHOT, ANIM_REQUEST_START);
+    send_sound_trigger(LLUUID(gSavedSettings.getString("UISndSnapshot")), 1.0f);
 }
 
 BOOL LLViewerWindow::isSnapshotLocSet() const
 {
-    static LLCachedControl<std::string>	sSnapshotDir(gSavedPerAccountSettings, "SnapshotBaseDir", "");
-	return !sSnapshotDir().empty();
+    static LLCachedControl<std::string> sSnapshotDir(gSavedPerAccountSettings, "SnapshotBaseDir", "");
+    return !sSnapshotDir().empty();
 }
 
 void LLViewerWindow::resetSnapshotLoc() const
 {
-	gSavedPerAccountSettings.setString("SnapshotBaseDir", std::string());
+    gSavedPerAccountSettings.setString("SnapshotBaseDir", std::string());
 }
 
 BOOL LLViewerWindow::thumbnailSnapshot(LLImageRaw *raw, S32 preview_width, S32 preview_height, BOOL show_ui, BOOL show_hud, BOOL do_rebuild, BOOL no_post, LLSnapshotModel::ESnapshotLayerType type)
 {
-	return rawSnapshot(raw, preview_width, preview_height, FALSE, FALSE, show_ui, show_hud, do_rebuild, no_post, type);
+    return rawSnapshot(raw, preview_width, preview_height, FALSE, FALSE, show_ui, show_hud, do_rebuild, no_post, type);
 }
 
 // Saves the image from the screen to a raw image
 // Since the required size might be bigger than the available screen, this method rerenders the scene in parts (called subimages) and copy
 // the results over to the final raw image.
-BOOL LLViewerWindow::rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_height, 
+BOOL LLViewerWindow::rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_height,
     BOOL keep_window_aspect, BOOL is_texture, BOOL show_ui, BOOL show_hud, BOOL do_rebuild, BOOL no_post, LLSnapshotModel::ESnapshotLayerType type, S32 max_size)
 {
-	if (!raw)
-	{
-		return FALSE;
-	}
-	//check if there is enough memory for the snapshot image
-	if(image_width * image_height > (1 << 22)) //if snapshot image is larger than 2K by 2K
-	{
-		if(!LLMemory::tryToAlloc(NULL, image_width * image_height * 3))
-		{
-			LL_WARNS() << "No enough memory to take the snapshot with size (w : h): " << image_width << " : " << image_height << LL_ENDL ;
-			return FALSE ; //there is no enough memory for taking this snapshot.
-		}
-	}
-
-	// PRE SNAPSHOT
-	gSnapshotNoPost = no_post;
-	gDisplaySwapBuffers = FALSE;
-	
+    if (!raw)
+    {
+        return FALSE;
+    }
+    //check if there is enough memory for the snapshot image
+    if(image_width * image_height > (1 << 22)) //if snapshot image is larger than 2K by 2K
+    {
+        if(!LLMemory::tryToAlloc(NULL, image_width * image_height * 3))
+        {
+            LL_WARNS() << "No enough memory to take the snapshot with size (w : h): " << image_width << " : " << image_height << LL_ENDL ;
+            return FALSE ; //there is no enough memory for taking this snapshot.
+        }
+    }
+
+    // PRE SNAPSHOT
+    gSnapshotNoPost = no_post;
+    gDisplaySwapBuffers = FALSE;
+
     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // stencil buffer is deprecated | GL_STENCIL_BUFFER_BIT);
-	setCursor(UI_CURSOR_WAIT);
+    setCursor(UI_CURSOR_WAIT);
+
+    // Hide all the UI widgets first and draw a frame
+    BOOL prev_draw_ui = gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI) ? TRUE : FALSE;
+
+    if ( prev_draw_ui != show_ui)
+    {
+        LLPipeline::toggleRenderDebugFeature(LLPipeline::RENDER_DEBUG_FEATURE_UI);
+    }
+
+    BOOL hide_hud = !show_hud && LLPipeline::sShowHUDAttachments;
+    if (hide_hud)
+    {
+        LLPipeline::sShowHUDAttachments = FALSE;
+    }
+
+    // if not showing ui, use full window to render world view
+    updateWorldViewRect(!show_ui);
+
+    // Copy screen to a buffer
+    // crop sides or top and bottom, if taking a snapshot of different aspect ratio
+    // from window
+    LLRect window_rect = show_ui ? getWindowRectRaw() : getWorldViewRectRaw();
+
+    S32 snapshot_width  = window_rect.getWidth();
+    S32 snapshot_height = window_rect.getHeight();
+    // SNAPSHOT
+    S32 window_width  = snapshot_width;
+    S32 window_height = snapshot_height;
+
+    // Note: Scaling of the UI is currently *not* supported so we limit the output size if UI is requested
+    if (show_ui)
+    {
+        // If the user wants the UI, limit the output size to the available screen size
+        image_width  = llmin(image_width, window_width);
+        image_height = llmin(image_height, window_height);
+    }
+
+    S32 original_width = 0;
+    S32 original_height = 0;
+    bool reset_deferred = false;
+
+    LLRenderTarget scratch_space;
+
+    auto& viewerCamera = LLViewerCamera::instance();
+
+    F32 scale_factor = 1.0f ;
+    if (!keep_window_aspect || (image_width > window_width) || (image_height > window_height))
+    {
+        if ((image_width <= gGLManager.mGLMaxTextureSize && image_height <= gGLManager.mGLMaxTextureSize) &&
+            (image_width > window_width || image_height > window_height) && LLPipeline::sRenderDeferred && !show_ui)
+        {
+            U32 color_fmt = (type == LLSnapshotModel::SNAPSHOT_TYPE_DEPTH || type == LLSnapshotModel::SNAPSHOT_TYPE_DEPTH24) ? GL_DEPTH_COMPONENT : GL_RGBA;
+            if (scratch_space.allocate(image_width, image_height, color_fmt, true))
+            {
+                original_width = gPipeline.mRT->deferredScreen.getWidth();
+                original_height = gPipeline.mRT->deferredScreen.getHeight();
+
+                if (gPipeline.allocateScreenBuffer(image_width, image_height))
+                {
+                    window_width = image_width;
+                    window_height = image_height;
+                    snapshot_width = image_width;
+                    snapshot_height = image_height;
+                    reset_deferred = true;
+                    mWorldViewRectRaw.set(0, image_height, image_width, 0);
+                    viewerCamera.setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
+                    viewerCamera.setAspect( getWorldViewAspectRatio() );
+                    scratch_space.bindTarget();
+                }
+                else
+                {
+                    scratch_space.release();
+                    gPipeline.allocateScreenBuffer(original_width, original_height);
+                }
+            }
+        }
+
+        if (!reset_deferred)
+        {
+            // if image cropping or need to enlarge the scene, compute a scale_factor
+            F32 ratio = llmin( (F32)window_width / image_width , (F32)window_height / image_height) ;
+            snapshot_width  = (S32)(ratio * image_width) ;
+            snapshot_height = (S32)(ratio * image_height) ;
+            scale_factor = llmax(1.0f, 1.0f / ratio) ;
+        }
+    }
+
+    if (show_ui && scale_factor > 1.f)
+    {
+        // Note: we should never get there...
+        LL_WARNS() << "over scaling UI not supported." << LL_ENDL;
+    }
+
+    S32 buffer_x_offset = llfloor(((window_width  - snapshot_width)  * scale_factor) / 2.f);
+    S32 buffer_y_offset = llfloor(((window_height - snapshot_height) * scale_factor) / 2.f);
+
+    S32 image_buffer_x = llfloor(snapshot_width  * scale_factor) ;
+    S32 image_buffer_y = llfloor(snapshot_height * scale_factor) ;
+
+    if ((image_buffer_x > max_size) || (image_buffer_y > max_size)) // boundary check to avoid memory overflow
+    {
+        scale_factor *= llmin((F32)max_size / image_buffer_x, (F32)max_size / image_buffer_y) ;
+        image_buffer_x = llfloor(snapshot_width  * scale_factor) ;
+        image_buffer_y = llfloor(snapshot_height * scale_factor) ;
+    }
+    if ((image_buffer_x > 0) && (image_buffer_y > 0))
+    {
+        raw->resize(image_buffer_x, image_buffer_y, 3);
+    }
+    else
+    {
+        return FALSE ;
+    }
+    if (raw->isBufferInvalid())
+    {
+        return FALSE ;
+    }
+
+    BOOL high_res = scale_factor >= 2.f; // Font scaling is slow, only do so if rez is much higher
+    if (high_res && show_ui)
+    {
+        // Note: we should never get there...
+        LL_WARNS() << "High res UI snapshot not supported. " << LL_ENDL;
+        /*send_agent_pause();
+        //rescale fonts
+        initFonts(scale_factor);
+        LLHUDObject::reshapeAll();*/
+    }
+
+    S32 output_buffer_offset_y = 0;
+
+    F32 depth_conversion_factor_1 = (viewerCamera.getFar() + viewerCamera.getNear()) / (2.f * viewerCamera.getFar() * viewerCamera.getNear());
+    F32 depth_conversion_factor_2 = (viewerCamera.getFar() - viewerCamera.getNear()) / (2.f * viewerCamera.getFar() * viewerCamera.getNear());
+
+    // Subimages are in fact partial rendering of the final view. This happens when the final view is bigger than the screen.
+    // In most common cases, scale_factor is 1 and there's no more than 1 iteration on x and y
+    for (int subimage_y = 0; subimage_y < scale_factor; ++subimage_y)
+    {
+        S32 subimage_y_offset = llclamp(buffer_y_offset - (subimage_y * window_height), 0, window_height);;
+        // handle fractional columns
+        U32 read_height = llmax(0, (window_height - subimage_y_offset) -
+            llmax(0, (window_height * (subimage_y + 1)) - (buffer_y_offset + raw->getHeight())));
+
+        S32 output_buffer_offset_x = 0;
+        for (int subimage_x = 0; subimage_x < scale_factor; ++subimage_x)
+        {
+            gDisplaySwapBuffers = FALSE;
+            gDepthDirty = TRUE;
+
+            S32 subimage_x_offset = llclamp(buffer_x_offset - (subimage_x * window_width), 0, window_width);
+            // handle fractional rows
+            U32 read_width = llmax(0, (window_width - subimage_x_offset) -
+                                    llmax(0, (window_width * (subimage_x + 1)) - (buffer_x_offset + raw->getWidth())));
+
+            // Skip rendering and sampling altogether if either width or height is degenerated to 0 (common in cropping cases)
+            if (read_width && read_height)
+            {
+                const U32 subfield = subimage_x+(subimage_y*llceil(scale_factor));
+                display(do_rebuild, scale_factor, subfield, TRUE);
+
+                if (!LLPipeline::sRenderDeferred)
+                {
+                    // Required for showing the GUI in snapshots and performing bloom composite overlay
+                    // Call even if show_ui is FALSE
+                    render_ui(scale_factor, subfield);
+                    swap();
+                }
+
+                for (U32 out_y = 0; out_y < read_height ; out_y++)
+                {
+                    S32 output_buffer_offset = (
+                                                (out_y * (raw->getWidth())) // ...plus iterated y...
+                                                + (window_width * subimage_x) // ...plus subimage start in x...
+                                                + (raw->getWidth() * window_height * subimage_y) // ...plus subimage start in y...
+                                                - output_buffer_offset_x // ...minus buffer padding x...
+                                                - (output_buffer_offset_y * (raw->getWidth()))  // ...minus buffer padding y...
+                                                ) * raw->getComponents();
+
+                    // Ping the watchdog thread every 100 lines to keep us alive (arbitrary number, feel free to change)
+                    if (out_y % 100 == 0)
+                    {
+                        LLAppViewer::instance()->pingMainloopTimeout("LLViewerWindow::rawSnapshot");
+                    }
+                    // disable use of glReadPixels when doing nVidia nSight graphics debugging
+                    if (!LLRender::sNsightDebugSupport)
+                    {
+                        if (type == LLSnapshotModel::SNAPSHOT_TYPE_COLOR)
+                        {
+                            glReadPixels(
+                                     subimage_x_offset, out_y + subimage_y_offset,
+                                     read_width, 1,
+                                     GL_RGB, GL_UNSIGNED_BYTE,
+                                     raw->getData() + output_buffer_offset
+                                     );
+                        }
+                        else if (type == LLSnapshotModel::SNAPSHOT_TYPE_DEPTH24)
+                        {
+                            LLPointer<LLImageRaw> depth_line_buffer = new LLImageRaw(read_width, 1, sizeof(GLfloat)); // need to store floating point values
+                            glReadPixels(
+                                         subimage_x_offset, out_y + subimage_y_offset,
+                                         read_width, 1,
+                                         GL_DEPTH_COMPONENT, GL_FLOAT,
+                                         depth_line_buffer->getData()// current output pixel is beginning of buffer...
+                                         );
+
+                            for (S32 i = 0; i < (S32)read_width; i++)
+                            {
+                                F32 depth_float = *(F32*)(depth_line_buffer->getData() + (i * sizeof(F32)));
+
+                                F32 linear_depth_float = 1.f / (depth_conversion_factor_1 - (depth_float * depth_conversion_factor_2));
+                                U32 RGB24 = F32_to_U32(linear_depth_float, viewerCamera.getNear(), viewerCamera.getFar());
+                                //A max value of 16777215 for RGB24 evaluates to black when it shold be white.  The clamp assures that the divisions do not somehow become >=256.
+                                U8 depth_byteR = (U8)(llclamp(llfloor(RGB24 / 65536.f), 0, 255));
+                                U8 depth_byteG = (U8)(llclamp(llfloor((RGB24 - depth_byteR * 65536) / 256.f), 0, 255));
+                                U8 depth_byteB = (U8)(llclamp((RGB24 - depth_byteR * 65536 - depth_byteG * 256), 0u, 255u));
+                                // write converted scanline out to result image
+                                *(raw->getData() + output_buffer_offset + (i * raw->getComponents())) = depth_byteR;
+                                *(raw->getData() + output_buffer_offset + (i * raw->getComponents()) + 1) = depth_byteG;
+                                *(raw->getData() + output_buffer_offset + (i * raw->getComponents()) + 2) = depth_byteB;
+                                for (S32 j = 3; j < raw->getComponents(); j++)
+                                {
+                                    *(raw->getData() + output_buffer_offset + (i * raw->getComponents()) + j) = depth_byteR;
+                                }
+                            }
+                        }
+                        else // LLSnapshotModel::SNAPSHOT_TYPE_DEPTH
+                        {
+                            LLPointer<LLImageRaw> depth_line_buffer = new LLImageRaw(read_width, 1, sizeof(GLfloat)); // need to store floating point values
+                            glReadPixels(
+                                         subimage_x_offset, out_y + subimage_y_offset,
+                                         read_width, 1,
+                                         GL_DEPTH_COMPONENT, GL_FLOAT,
+                                         depth_line_buffer->getData()// current output pixel is beginning of buffer...
+                                         );
+
+                            for (S32 i = 0; i < (S32)read_width; i++)
+                            {
+                                F32 depth_float = *(F32*)(depth_line_buffer->getData() + (i * sizeof(F32)));
+
+                                F32 linear_depth_float = 1.f / (depth_conversion_factor_1 - (depth_float * depth_conversion_factor_2));
+                                U8 depth_byte = F32_to_U8(linear_depth_float, viewerCamera.getNear(), viewerCamera.getFar());
+                                // write converted scanline out to result image
+                                for (S32 j = 0; j < raw->getComponents(); j++)
+                                {
+                                    *(raw->getData() + output_buffer_offset + (i * raw->getComponents()) + j) = depth_byte;
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            output_buffer_offset_x += subimage_x_offset;
+            stop_glerror();
+        }
+        output_buffer_offset_y += subimage_y_offset;
+    }
+
+    gDisplaySwapBuffers = FALSE;
+    gSnapshotNoPost = FALSE;
+    gDepthDirty = TRUE;
+
+    // POST SNAPSHOT
+    if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
+    {
+        LLPipeline::toggleRenderDebugFeature(LLPipeline::RENDER_DEBUG_FEATURE_UI);
+    }
+
+    if (hide_hud)
+    {
+        LLPipeline::sShowHUDAttachments = TRUE;
+    }
+
+    /*if (high_res)
+    {
+        initFonts(1.f);
+        LLHUDObject::reshapeAll();
+    }*/
+
+    // Pre-pad image to number of pixels such that the line length is a multiple of 4 bytes (for BMP encoding)
+    // Note: this formula depends on the number of components being 3.  Not obvious, but it's correct.
+    image_width += (image_width * 3) % 4;
+
+    BOOL ret = TRUE ;
+    // Resize image
+    if(llabs(image_width - image_buffer_x) > 4 || llabs(image_height - image_buffer_y) > 4)
+    {
+        ret = raw->scale( image_width, image_height );
+    }
+    else if(image_width != image_buffer_x || image_height != image_buffer_y)
+    {
+        ret = raw->scale( image_width, image_height, FALSE );
+    }
+
+
+    setCursor(UI_CURSOR_ARROW);
 
-	// Hide all the UI widgets first and draw a frame
-	BOOL prev_draw_ui = gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI) ? TRUE : FALSE;
+    if (do_rebuild)
+    {
+        // If we had to do a rebuild, that means that the lists of drawables to be rendered
+        // was empty before we started.
+        // Need to reset these, otherwise we call state sort on it again when render gets called the next time
+        // and we stand a good chance of crashing on rebuild because the render drawable arrays have multiple copies of
+        // objects on them.
+        gPipeline.resetDrawOrders();
+    }
 
-	if ( prev_draw_ui != show_ui)
-	{
-		LLPipeline::toggleRenderDebugFeature(LLPipeline::RENDER_DEBUG_FEATURE_UI);
-	}
+    if (reset_deferred)
+    {
+        mWorldViewRectRaw = window_rect;
+        viewerCamera.setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
+        viewerCamera.setAspect( getWorldViewAspectRatio() );
+        scratch_space.flush();
+        scratch_space.release();
+        gPipeline.allocateScreenBuffer(original_width, original_height);
 
-    BOOL hide_hud = !show_hud && LLPipeline::sShowHUDAttachments;
-	if (hide_hud)
-	{
-		LLPipeline::sShowHUDAttachments = FALSE;
-	}
-
-	// if not showing ui, use full window to render world view
-	updateWorldViewRect(!show_ui);
-
-	// Copy screen to a buffer
-	// crop sides or top and bottom, if taking a snapshot of different aspect ratio
-	// from window
-	LLRect window_rect = show_ui ? getWindowRectRaw() : getWorldViewRectRaw(); 
-
-	S32 snapshot_width  = window_rect.getWidth();
-	S32 snapshot_height = window_rect.getHeight();
-	// SNAPSHOT
-	S32 window_width  = snapshot_width;
-	S32 window_height = snapshot_height;
-	
-	// Note: Scaling of the UI is currently *not* supported so we limit the output size if UI is requested
-	if (show_ui)
-	{
-		// If the user wants the UI, limit the output size to the available screen size
-		image_width  = llmin(image_width, window_width);
-		image_height = llmin(image_height, window_height);
-	}
-
-	S32 original_width = 0;
-	S32 original_height = 0;
-	bool reset_deferred = false;
-
-	LLRenderTarget scratch_space;
-
-	auto& viewerCamera = LLViewerCamera::instance();
-
-	F32 scale_factor = 1.0f ;
-	if (!keep_window_aspect || (image_width > window_width) || (image_height > window_height))
-	{	
-		if ((image_width <= gGLManager.mGLMaxTextureSize && image_height <= gGLManager.mGLMaxTextureSize) && 
-			(image_width > window_width || image_height > window_height) && LLPipeline::sRenderDeferred && !show_ui)
-		{
-			U32 color_fmt = (type == LLSnapshotModel::SNAPSHOT_TYPE_DEPTH || type == LLSnapshotModel::SNAPSHOT_TYPE_DEPTH24) ? GL_DEPTH_COMPONENT : GL_RGBA;
-			if (scratch_space.allocate(image_width, image_height, color_fmt, true))
-			{
-				original_width = gPipeline.mRT->deferredScreen.getWidth();
-				original_height = gPipeline.mRT->deferredScreen.getHeight();
-
-				if (gPipeline.allocateScreenBuffer(image_width, image_height))
-				{
-					window_width = image_width;
-					window_height = image_height;
-					snapshot_width = image_width;
-					snapshot_height = image_height;
-					reset_deferred = true;
-					mWorldViewRectRaw.set(0, image_height, image_width, 0);
-					viewerCamera.setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
-					viewerCamera.setAspect( getWorldViewAspectRatio() );
-					scratch_space.bindTarget();
-				}
-				else
-				{
-					scratch_space.release();
-					gPipeline.allocateScreenBuffer(original_width, original_height);
-				}
-			}
-		}
-
-		if (!reset_deferred)
-		{
-			// if image cropping or need to enlarge the scene, compute a scale_factor
-			F32 ratio = llmin( (F32)window_width / image_width , (F32)window_height / image_height) ;
-			snapshot_width  = (S32)(ratio * image_width) ;
-			snapshot_height = (S32)(ratio * image_height) ;
-			scale_factor = llmax(1.0f, 1.0f / ratio) ;
-		}
-	}
-	
-	if (show_ui && scale_factor > 1.f)
-	{
-		// Note: we should never get there...
-		LL_WARNS() << "over scaling UI not supported." << LL_ENDL;
-	}
-
-	S32 buffer_x_offset = llfloor(((window_width  - snapshot_width)  * scale_factor) / 2.f);
-	S32 buffer_y_offset = llfloor(((window_height - snapshot_height) * scale_factor) / 2.f);
-
-	S32 image_buffer_x = llfloor(snapshot_width  * scale_factor) ;
-	S32 image_buffer_y = llfloor(snapshot_height * scale_factor) ;
-
-	if ((image_buffer_x > max_size) || (image_buffer_y > max_size)) // boundary check to avoid memory overflow
-	{
-		scale_factor *= llmin((F32)max_size / image_buffer_x, (F32)max_size / image_buffer_y) ;
-		image_buffer_x = llfloor(snapshot_width  * scale_factor) ;
-		image_buffer_y = llfloor(snapshot_height * scale_factor) ;
-	}
-	if ((image_buffer_x > 0) && (image_buffer_y > 0))
-	{
-		raw->resize(image_buffer_x, image_buffer_y, 3);
-	}
-	else
-	{
-		return FALSE ;
-	}
-	if (raw->isBufferInvalid())
-	{
-		return FALSE ;
-	}
-
-	BOOL high_res = scale_factor >= 2.f; // Font scaling is slow, only do so if rez is much higher
-	if (high_res && show_ui)
-	{
-		// Note: we should never get there...
-		LL_WARNS() << "High res UI snapshot not supported. " << LL_ENDL;
-		/*send_agent_pause();
-		//rescale fonts
-		initFonts(scale_factor);
-		LLHUDObject::reshapeAll();*/
-	}
-
-	S32 output_buffer_offset_y = 0;
-
-	F32 depth_conversion_factor_1 = (viewerCamera.getFar() + viewerCamera.getNear()) / (2.f * viewerCamera.getFar() * viewerCamera.getNear());
-	F32 depth_conversion_factor_2 = (viewerCamera.getFar() - viewerCamera.getNear()) / (2.f * viewerCamera.getFar() * viewerCamera.getNear());
-
-	// Subimages are in fact partial rendering of the final view. This happens when the final view is bigger than the screen.
-	// In most common cases, scale_factor is 1 and there's no more than 1 iteration on x and y
-	for (int subimage_y = 0; subimage_y < scale_factor; ++subimage_y)
-	{
-		S32 subimage_y_offset = llclamp(buffer_y_offset - (subimage_y * window_height), 0, window_height);;
-		// handle fractional columns
-		U32 read_height = llmax(0, (window_height - subimage_y_offset) -
-			llmax(0, (window_height * (subimage_y + 1)) - (buffer_y_offset + raw->getHeight())));
-
-		S32 output_buffer_offset_x = 0;
-		for (int subimage_x = 0; subimage_x < scale_factor; ++subimage_x)
-		{
-			gDisplaySwapBuffers = FALSE;
-			gDepthDirty = TRUE;
-
-			S32 subimage_x_offset = llclamp(buffer_x_offset - (subimage_x * window_width), 0, window_width);
-			// handle fractional rows
-			U32 read_width = llmax(0, (window_width - subimage_x_offset) -
-									llmax(0, (window_width * (subimage_x + 1)) - (buffer_x_offset + raw->getWidth())));
-			
-			// Skip rendering and sampling altogether if either width or height is degenerated to 0 (common in cropping cases)
-			if (read_width && read_height)
-			{
-				const U32 subfield = subimage_x+(subimage_y*llceil(scale_factor));
-				display(do_rebuild, scale_factor, subfield, TRUE);
-				
-				if (!LLPipeline::sRenderDeferred)
-				{
-					// Required for showing the GUI in snapshots and performing bloom composite overlay
-					// Call even if show_ui is FALSE
-					render_ui(scale_factor, subfield);
-					swap();
-				}
-				
-				for (U32 out_y = 0; out_y < read_height ; out_y++)
-				{
-					S32 output_buffer_offset = ( 
-												(out_y * (raw->getWidth())) // ...plus iterated y...
-												+ (window_width * subimage_x) // ...plus subimage start in x...
-												+ (raw->getWidth() * window_height * subimage_y) // ...plus subimage start in y...
-												- output_buffer_offset_x // ...minus buffer padding x...
-												- (output_buffer_offset_y * (raw->getWidth()))  // ...minus buffer padding y...
-												) * raw->getComponents();
-				
-					// Ping the watchdog thread every 100 lines to keep us alive (arbitrary number, feel free to change)
-					if (out_y % 100 == 0)
-					{
-						LLAppViewer::instance()->pingMainloopTimeout("LLViewerWindow::rawSnapshot");
-					}
-					// disable use of glReadPixels when doing nVidia nSight graphics debugging
-					if (!LLRender::sNsightDebugSupport)
-					{
-						if (type == LLSnapshotModel::SNAPSHOT_TYPE_COLOR)
-						{
-							glReadPixels(
-									 subimage_x_offset, out_y + subimage_y_offset,
-									 read_width, 1,
-									 GL_RGB, GL_UNSIGNED_BYTE,
-									 raw->getData() + output_buffer_offset
-									 );
-						}
-						else if (type == LLSnapshotModel::SNAPSHOT_TYPE_DEPTH24)
-						{
-							LLPointer<LLImageRaw> depth_line_buffer = new LLImageRaw(read_width, 1, sizeof(GLfloat)); // need to store floating point values
-							glReadPixels(
-										 subimage_x_offset, out_y + subimage_y_offset,
-										 read_width, 1,
-										 GL_DEPTH_COMPONENT, GL_FLOAT,
-										 depth_line_buffer->getData()// current output pixel is beginning of buffer...
-										 );
-
-							for (S32 i = 0; i < (S32)read_width; i++)
-							{
-								F32 depth_float = *(F32*)(depth_line_buffer->getData() + (i * sizeof(F32)));
-					
-								F32 linear_depth_float = 1.f / (depth_conversion_factor_1 - (depth_float * depth_conversion_factor_2));
-								U32 RGB24 = F32_to_U32(linear_depth_float, viewerCamera.getNear(), viewerCamera.getFar());
-								//A max value of 16777215 for RGB24 evaluates to black when it shold be white.  The clamp assures that the divisions do not somehow become >=256.
-								U8 depth_byteR = (U8)(llclamp(llfloor(RGB24 / 65536.f), 0, 255));
-								U8 depth_byteG = (U8)(llclamp(llfloor((RGB24 - depth_byteR * 65536) / 256.f), 0, 255));
-								U8 depth_byteB = (U8)(llclamp((RGB24 - depth_byteR * 65536 - depth_byteG * 256), 0u, 255u));
-								// write converted scanline out to result image
-								*(raw->getData() + output_buffer_offset + (i * raw->getComponents())) = depth_byteR;
-								*(raw->getData() + output_buffer_offset + (i * raw->getComponents()) + 1) = depth_byteG;
-								*(raw->getData() + output_buffer_offset + (i * raw->getComponents()) + 2) = depth_byteB;
-								for (S32 j = 3; j < raw->getComponents(); j++)
-								{
-									*(raw->getData() + output_buffer_offset + (i * raw->getComponents()) + j) = depth_byteR;
-								}
-							}
-						}
-						else // LLSnapshotModel::SNAPSHOT_TYPE_DEPTH
-						{
-							LLPointer<LLImageRaw> depth_line_buffer = new LLImageRaw(read_width, 1, sizeof(GLfloat)); // need to store floating point values
-							glReadPixels(
-										 subimage_x_offset, out_y + subimage_y_offset,
-										 read_width, 1,
-										 GL_DEPTH_COMPONENT, GL_FLOAT,
-										 depth_line_buffer->getData()// current output pixel is beginning of buffer...
-										 );
-
-							for (S32 i = 0; i < (S32)read_width; i++)
-							{
-								F32 depth_float = *(F32*)(depth_line_buffer->getData() + (i * sizeof(F32)));
-					
-								F32 linear_depth_float = 1.f / (depth_conversion_factor_1 - (depth_float * depth_conversion_factor_2));
-								U8 depth_byte = F32_to_U8(linear_depth_float, viewerCamera.getNear(), viewerCamera.getFar());
-								// write converted scanline out to result image
-								for (S32 j = 0; j < raw->getComponents(); j++)
-								{
-									*(raw->getData() + output_buffer_offset + (i * raw->getComponents()) + j) = depth_byte;
-								}
-							}
-						}
-					}
-				}
-			}
-			output_buffer_offset_x += subimage_x_offset;
-			stop_glerror();
-		}
-		output_buffer_offset_y += subimage_y_offset;
-	}
-
-	gDisplaySwapBuffers = FALSE;
-	gSnapshotNoPost = FALSE;
-	gDepthDirty = TRUE;
-
-	// POST SNAPSHOT
-	if (!gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
-	{
-		LLPipeline::toggleRenderDebugFeature(LLPipeline::RENDER_DEBUG_FEATURE_UI);
-	}
-
-	if (hide_hud)
-	{
-		LLPipeline::sShowHUDAttachments = TRUE;
-	}
-
-	/*if (high_res)
-	{
-		initFonts(1.f);
-		LLHUDObject::reshapeAll();
-	}*/
-
-	// Pre-pad image to number of pixels such that the line length is a multiple of 4 bytes (for BMP encoding)
-	// Note: this formula depends on the number of components being 3.  Not obvious, but it's correct.	
-	image_width += (image_width * 3) % 4;
-
-	BOOL ret = TRUE ;
-	// Resize image
-	if(llabs(image_width - image_buffer_x) > 4 || llabs(image_height - image_buffer_y) > 4)
-	{
-		ret = raw->scale( image_width, image_height );  
-	}
-	else if(image_width != image_buffer_x || image_height != image_buffer_y)
-	{
-		ret = raw->scale( image_width, image_height, FALSE );  
-	}
-	
-
-	setCursor(UI_CURSOR_ARROW);
-
-	if (do_rebuild)
-	{
-		// If we had to do a rebuild, that means that the lists of drawables to be rendered
-		// was empty before we started.
-		// Need to reset these, otherwise we call state sort on it again when render gets called the next time
-		// and we stand a good chance of crashing on rebuild because the render drawable arrays have multiple copies of
-		// objects on them.
-		gPipeline.resetDrawOrders();
-	}
-
-	if (reset_deferred)
-	{
-		mWorldViewRectRaw = window_rect;
-		viewerCamera.setViewHeightInPixels( mWorldViewRectRaw.getHeight() );
-		viewerCamera.setAspect( getWorldViewAspectRatio() );
-		scratch_space.flush();
-		scratch_space.release();
-		gPipeline.allocateScreenBuffer(original_width, original_height);
-		
-	}
-
-	if (high_res)
-	{
-		send_agent_resume();
-	}
-	
-	return ret;
+    }
+
+    if (high_res)
+    {
+        send_agent_resume();
+    }
+
+    return ret;
 }
 
 BOOL LLViewerWindow::simpleSnapshot(LLImageRaw* raw, S32 image_width, S32 image_height, const int num_render_passes)
@@ -5645,10 +5645,10 @@ BOOL LLViewerWindow::simpleSnapshot(LLImageRaw* raw, S32 image_width, S32 image_
     }
 
     BOOL hide_hud = LLPipeline::sShowHUDAttachments;
-	if (hide_hud)
-	{
-		LLPipeline::sShowHUDAttachments = FALSE;
-	}
+    if (hide_hud)
+    {
+        LLPipeline::sShowHUDAttachments = FALSE;
+    }
 
     LLRect window_rect = getWorldViewRectRaw();
 
@@ -5673,8 +5673,8 @@ BOOL LLViewerWindow::simpleSnapshot(LLImageRaw* raw, S32 image_width, S32 image_
     }
 
     // we render the scene more than once since this helps
-    // greatly with the objects not being drawn in the 
-    // snapshot when they are drawn in the scene. This is 
+    // greatly with the objects not being drawn in the
+    // snapshot when they are drawn in the scene. This is
     // evident when you set this value via the debug setting
     // called 360CaptureNumRenderPasses to 1. The theory is
     // that the missing objects are caused by the sUseOcclusion
@@ -5719,10 +5719,10 @@ BOOL LLViewerWindow::simpleSnapshot(LLImageRaw* raw, S32 image_width, S32 image_
         }
     }
 
-	if (hide_hud)
-	{
-		LLPipeline::sShowHUDAttachments = TRUE;
-	}
+    if (hide_hud)
+    {
+        LLPipeline::sShowHUDAttachments = TRUE;
+    }
 
     setCursor(UI_CURSOR_ARROW);
 
@@ -5744,7 +5744,7 @@ BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
     LL_PROFILE_GPU_ZONE("cubeSnapshot");
     llassert(LLPipeline::sRenderDeferred);
     llassert(!gCubeSnapshot); //assert a snapshot isn't already in progress
-    
+
     U32 res = gPipeline.mRT->deferredScreen.getWidth();
 
     //llassert(res <= gPipeline.mRT->deferredScreen.getWidth());
@@ -5756,7 +5756,7 @@ BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
     // set new parameters specific to the 360 requirements
     LLPipeline::sUseOcclusion = 0;
     LLViewerCamera* camera = LLViewerCamera::getInstance();
-    
+
     LLViewerCamera saved_camera = LLViewerCamera::instance();
     LLMatrix4a saved_proj = get_current_projection();
     LLMatrix4a saved_mod = get_current_modelview();
@@ -5768,16 +5768,16 @@ BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
     camera->setOrigin(origin);
     camera->setNear(near_clip);
 
-	LLPlane previousClipPlane;
+    LLPlane previousClipPlane;
 
-	if (useCustomClipPlane)
-	{
+    if (useCustomClipPlane)
+    {
         previousClipPlane = camera->getUserClipPlane();
         camera->setUserClipPlane(clipPlane);
-	}
+    }
 
     glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // stencil buffer is deprecated | GL_STENCIL_BUFFER_BIT);
-    
+
     U32 dynamic_render_types[] = {
         LLPipeline::RENDER_TYPE_AVATAR,
         LLPipeline::RENDER_TYPE_CONTROL_AV,
@@ -5786,7 +5786,7 @@ BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
     constexpr U32 dynamic_render_type_count = sizeof(dynamic_render_types) / sizeof(U32);
     bool prev_dynamic_render_type[dynamic_render_type_count];
 
-    
+
     if (!dynamic_render)
     {
         for (int i = 0; i < dynamic_render_type_count; ++i)
@@ -5804,12 +5804,12 @@ BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
     {
         LLPipeline::toggleRenderDebugFeature(LLPipeline::RENDER_DEBUG_FEATURE_UI);
     }
-    
+
     BOOL hide_hud = LLPipeline::sShowHUDAttachments;
-	if (hide_hud)
-	{
-		LLPipeline::sShowHUDAttachments = FALSE;
-	}
+    if (hide_hud)
+    {
+        LLPipeline::sShowHUDAttachments = FALSE;
+    }
     LLRect window_rect = getWorldViewRectRaw();
 
     mWorldViewRectRaw.set(0, res, res, 0);
@@ -5875,19 +5875,19 @@ BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
         }
     }
 
-	if (hide_hud)
-	{
-		LLPipeline::sShowHUDAttachments = TRUE;
-	}
+    if (hide_hud)
+    {
+        LLPipeline::sShowHUDAttachments = TRUE;
+    }
 
     gPipeline.resetDrawOrders();
     mWorldViewRectRaw = window_rect;
 
-	if (useCustomClipPlane)
-	{
+    if (useCustomClipPlane)
+    {
         camera->setUserClipPlane(previousClipPlane);
-	}
-    
+    }
+
     // restore original view/camera/avatar settings settings
     *camera = saved_camera;
     set_current_modelview(saved_mod);
@@ -5901,195 +5901,195 @@ BOOL LLViewerWindow::cubeSnapshot(const LLVector3& origin, LLCubeMapArray* cubea
 
 void LLViewerWindow::destroyWindow()
 {
-	if (mWindow)
-	{
-		LLWindowManager::destroyWindow(mWindow);
-	}
-	mWindow = NULL;
+    if (mWindow)
+    {
+        LLWindowManager::destroyWindow(mWindow);
+    }
+    mWindow = NULL;
 }
 
 
 void LLViewerWindow::drawMouselookInstructions()
 {
-	static LLCachedControl<bool> draw_mouselook_instructions(gSavedSettings, "AlchemyMouselookInstructions", true);
-	static LLCachedControl<bool> draw_mouselook_position(gSavedSettings, "AlchemyMouselookPosition", true);
-	if (draw_mouselook_position || draw_mouselook_instructions)
-	{
-		// Draw information for mouselook (pos, health)
-		const LLFontGL* font = LLFontGL::getFontSansSerifBig();
-
-		if (draw_mouselook_position)
-		{
-			//to be at top of viewer 
-			const S32 INSTRUCTIONS_TOP_PAD = getWorldViewRectScaled().mTop - 15;
-			const S32 text_pos_start = getWorldViewRectScaled().getCenterX() - 150;
-			const LLVector3& vec = gAgent.getPositionAgent();
-
-			font->renderUTF8(
-				llformat("X: %.2f", vec.mV[VX]), 0,
-				text_pos_start,
-				INSTRUCTIONS_TOP_PAD,
-				LLColor4(1.0f, 0.5f, 0.5f, 0.5f),
-				LLFontGL::HCENTER, LLFontGL::TOP,
-				LLFontGL::BOLD, LLFontGL::DROP_SHADOW_SOFT);
-			font->renderUTF8(
-				llformat("Y: %.2f", vec.mV[VY]), 0,
-				text_pos_start + 100,
-				INSTRUCTIONS_TOP_PAD,
-				LLColor4(0.5f, 1.0f, 0.5f, 0.5f),
-				LLFontGL::HCENTER, LLFontGL::TOP,
-				LLFontGL::BOLD, LLFontGL::DROP_SHADOW_SOFT);
-			font->renderUTF8(
-				llformat("Z: %.2f", vec.mV[VZ]), 0,
-				text_pos_start + 200,
-				INSTRUCTIONS_TOP_PAD,
-				LLColor4(0.5f, 0.5f, 1.0f, 0.5f),
-				LLFontGL::HCENTER, LLFontGL::TOP,
-				LLFontGL::BOLD, LLFontGL::DROP_SHADOW_SOFT);
-			LLViewerParcelMgr* vpm = LLViewerParcelMgr::getInstance();
-			const bool allow_damage = vpm->allowAgentDamage(gAgent.getRegion(), vpm->getAgentParcel());
-			if (allow_damage)
-			{
-				S32 health = -1;
-				if (gStatusBar)
-				{
-					health = gStatusBar->getHealth();
-				}
-				font->renderUTF8(
-					llformat("HP: %d%%", health), 0,
-					text_pos_start + 300,
-					INSTRUCTIONS_TOP_PAD,
-					LLColor4(1.0f, 1.0f, 1.0f, 0.5f),
-					LLFontGL::HCENTER, LLFontGL::TOP,
-					LLFontGL::BOLD, LLFontGL::DROP_SHADOW_SOFT);
-			}
-		}
-
-		if (draw_mouselook_instructions)
-		{
-			// Draw instructions for mouselook ("Press ESC to return to World View" partially transparent at the bottom of the screen.)
-			static const std::string instructions = LLTrans::getString("LeaveMouselook");
-
-			//to be on top of Bottom bar when it is opened
-			const S32 INSTRUCTIONS_BOTTOM_PAD = 50;
-
-			font->renderUTF8(
-				instructions, 0,
-				getWorldViewRectScaled().getCenterX(),
-				getWorldViewRectScaled().mBottom + INSTRUCTIONS_BOTTOM_PAD,
-				LLColor4(1.0f, 1.0f, 1.0f, 0.5f),
-				LLFontGL::HCENTER, LLFontGL::TOP,
-				LLFontGL::BOLD, LLFontGL::DROP_SHADOW);
-		}
-	}
+    static LLCachedControl<bool> draw_mouselook_instructions(gSavedSettings, "AlchemyMouselookInstructions", true);
+    static LLCachedControl<bool> draw_mouselook_position(gSavedSettings, "AlchemyMouselookPosition", true);
+    if (draw_mouselook_position || draw_mouselook_instructions)
+    {
+        // Draw information for mouselook (pos, health)
+        const LLFontGL* font = LLFontGL::getFontSansSerifBig();
+
+        if (draw_mouselook_position)
+        {
+            //to be at top of viewer
+            const S32 INSTRUCTIONS_TOP_PAD = getWorldViewRectScaled().mTop - 15;
+            const S32 text_pos_start = getWorldViewRectScaled().getCenterX() - 150;
+            const LLVector3& vec = gAgent.getPositionAgent();
+
+            font->renderUTF8(
+                llformat("X: %.2f", vec.mV[VX]), 0,
+                text_pos_start,
+                INSTRUCTIONS_TOP_PAD,
+                LLColor4(1.0f, 0.5f, 0.5f, 0.5f),
+                LLFontGL::HCENTER, LLFontGL::TOP,
+                LLFontGL::BOLD, LLFontGL::DROP_SHADOW_SOFT);
+            font->renderUTF8(
+                llformat("Y: %.2f", vec.mV[VY]), 0,
+                text_pos_start + 100,
+                INSTRUCTIONS_TOP_PAD,
+                LLColor4(0.5f, 1.0f, 0.5f, 0.5f),
+                LLFontGL::HCENTER, LLFontGL::TOP,
+                LLFontGL::BOLD, LLFontGL::DROP_SHADOW_SOFT);
+            font->renderUTF8(
+                llformat("Z: %.2f", vec.mV[VZ]), 0,
+                text_pos_start + 200,
+                INSTRUCTIONS_TOP_PAD,
+                LLColor4(0.5f, 0.5f, 1.0f, 0.5f),
+                LLFontGL::HCENTER, LLFontGL::TOP,
+                LLFontGL::BOLD, LLFontGL::DROP_SHADOW_SOFT);
+            LLViewerParcelMgr* vpm = LLViewerParcelMgr::getInstance();
+            const bool allow_damage = vpm->allowAgentDamage(gAgent.getRegion(), vpm->getAgentParcel());
+            if (allow_damage)
+            {
+                S32 health = -1;
+                if (gStatusBar)
+                {
+                    health = gStatusBar->getHealth();
+                }
+                font->renderUTF8(
+                    llformat("HP: %d%%", health), 0,
+                    text_pos_start + 300,
+                    INSTRUCTIONS_TOP_PAD,
+                    LLColor4(1.0f, 1.0f, 1.0f, 0.5f),
+                    LLFontGL::HCENTER, LLFontGL::TOP,
+                    LLFontGL::BOLD, LLFontGL::DROP_SHADOW_SOFT);
+            }
+        }
+
+        if (draw_mouselook_instructions)
+        {
+            // Draw instructions for mouselook ("Press ESC to return to World View" partially transparent at the bottom of the screen.)
+            static const std::string instructions = LLTrans::getString("LeaveMouselook");
+
+            //to be on top of Bottom bar when it is opened
+            const S32 INSTRUCTIONS_BOTTOM_PAD = 50;
+
+            font->renderUTF8(
+                instructions, 0,
+                getWorldViewRectScaled().getCenterX(),
+                getWorldViewRectScaled().mBottom + INSTRUCTIONS_BOTTOM_PAD,
+                LLColor4(1.0f, 1.0f, 1.0f, 0.5f),
+                LLFontGL::HCENTER, LLFontGL::TOP,
+                LLFontGL::BOLD, LLFontGL::DROP_SHADOW);
+        }
+    }
 }
 
 void* LLViewerWindow::getPlatformWindow() const
 {
-	return mWindow->getPlatformWindow();
+    return mWindow->getPlatformWindow();
 }
 
-void* LLViewerWindow::getMediaWindow() 	const
+void* LLViewerWindow::getMediaWindow()  const
 {
-	return mWindow->getMediaWindow();
+    return mWindow->getMediaWindow();
 }
 
-void LLViewerWindow::focusClient()		const
+void LLViewerWindow::focusClient()      const
 {
-	return mWindow->focusClient();
+    return mWindow->focusClient();
 }
 
-LLRootView*	LLViewerWindow::getRootView() const
+LLRootView* LLViewerWindow::getRootView() const
 {
-	return mRootView;
+    return mRootView;
 }
 
 LLRect LLViewerWindow::getWorldViewRectScaled() const
 {
-	return mWorldViewRectScaled;
+    return mWorldViewRectScaled;
 }
 
 S32 LLViewerWindow::getWorldViewHeightScaled() const
 {
-	return mWorldViewRectScaled.getHeight();
+    return mWorldViewRectScaled.getHeight();
 }
 
 S32 LLViewerWindow::getWorldViewWidthScaled() const
 {
-	return mWorldViewRectScaled.getWidth();
+    return mWorldViewRectScaled.getWidth();
 }
 
 
 S32 LLViewerWindow::getWorldViewHeightRaw() const
 {
-	return mWorldViewRectRaw.getHeight(); 
+    return mWorldViewRectRaw.getHeight();
 }
 
 S32 LLViewerWindow::getWorldViewWidthRaw() const
 {
-	return mWorldViewRectRaw.getWidth(); 
+    return mWorldViewRectRaw.getWidth();
 }
 
-S32	LLViewerWindow::getWindowHeightScaled()	const 	
-{ 
-	return mWindowRectScaled.getHeight(); 
+S32 LLViewerWindow::getWindowHeightScaled() const
+{
+    return mWindowRectScaled.getHeight();
 }
 
-S32	LLViewerWindow::getWindowWidthScaled() const 	
-{ 
-	return mWindowRectScaled.getWidth(); 
+S32 LLViewerWindow::getWindowWidthScaled() const
+{
+    return mWindowRectScaled.getWidth();
 }
 
-S32	LLViewerWindow::getWindowHeightRaw()	const 	
-{ 
-	return mWindowRectRaw.getHeight(); 
+S32 LLViewerWindow::getWindowHeightRaw()    const
+{
+    return mWindowRectRaw.getHeight();
 }
 
-S32	LLViewerWindow::getWindowWidthRaw() const 	
-{ 
-	return mWindowRectRaw.getWidth(); 
+S32 LLViewerWindow::getWindowWidthRaw() const
+{
+    return mWindowRectRaw.getWidth();
 }
 
 void LLViewerWindow::setup2DRender()
 {
-	// setup ortho camera
-	gl_state_for_2d(mWindowRectRaw.getWidth(), mWindowRectRaw.getHeight());
-	setup2DViewport();
+    // setup ortho camera
+    gl_state_for_2d(mWindowRectRaw.getWidth(), mWindowRectRaw.getHeight());
+    setup2DViewport();
 }
 
 void LLViewerWindow::setup2DViewport(S32 x_offset, S32 y_offset)
 {
-	gGLViewport[0] = mWindowRectRaw.mLeft + x_offset;
-	gGLViewport[1] = mWindowRectRaw.mBottom + y_offset;
-	gGLViewport[2] = mWindowRectRaw.getWidth();
-	gGLViewport[3] = mWindowRectRaw.getHeight();
-	glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]);
+    gGLViewport[0] = mWindowRectRaw.mLeft + x_offset;
+    gGLViewport[1] = mWindowRectRaw.mBottom + y_offset;
+    gGLViewport[2] = mWindowRectRaw.getWidth();
+    gGLViewport[3] = mWindowRectRaw.getHeight();
+    glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]);
 }
 
 
 void LLViewerWindow::setup3DRender()
 {
-	// setup perspective camera
-	LLViewerCamera::getInstance()->setPerspective(NOT_FOR_SELECTION, mWorldViewRectRaw.mLeft, mWorldViewRectRaw.mBottom,  mWorldViewRectRaw.getWidth(), mWorldViewRectRaw.getHeight(), FALSE, LLViewerCamera::getInstance()->getNear(), MAX_FAR_CLIP*2.f);
-	setup3DViewport();
+    // setup perspective camera
+    LLViewerCamera::getInstance()->setPerspective(NOT_FOR_SELECTION, mWorldViewRectRaw.mLeft, mWorldViewRectRaw.mBottom,  mWorldViewRectRaw.getWidth(), mWorldViewRectRaw.getHeight(), FALSE, LLViewerCamera::getInstance()->getNear(), MAX_FAR_CLIP*2.f);
+    setup3DViewport();
 }
 
 void LLViewerWindow::setup3DViewport(S32 x_offset, S32 y_offset)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_UI
-	gGLViewport[0] = mWorldViewRectRaw.mLeft + x_offset;
-	gGLViewport[1] = mWorldViewRectRaw.mBottom + y_offset;
-	gGLViewport[2] = mWorldViewRectRaw.getWidth();
-	gGLViewport[3] = mWorldViewRectRaw.getHeight();
-	glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]);
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_UI
+    gGLViewport[0] = mWorldViewRectRaw.mLeft + x_offset;
+    gGLViewport[1] = mWorldViewRectRaw.mBottom + y_offset;
+    gGLViewport[2] = mWorldViewRectRaw.getWidth();
+    gGLViewport[3] = mWorldViewRectRaw.getHeight();
+    glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]);
 }
 
 void LLViewerWindow::revealIntroPanel()
 {
-	if (mProgressView)
-	{
-		mProgressView->revealIntroPanel();
-	}
+    if (mProgressView)
+    {
+        mProgressView->revealIntroPanel();
+    }
 }
 
 void LLViewerWindow::initTextures(S32 location_id)
@@ -6102,435 +6102,435 @@ void LLViewerWindow::initTextures(S32 location_id)
 
 void LLViewerWindow::setShowProgress(const BOOL show)
 {
-	if (mProgressView)
-	{
-		mProgressView->setVisible(show);
-	}
+    if (mProgressView)
+    {
+        mProgressView->setVisible(show);
+    }
 }
 
 void LLViewerWindow::setStartupComplete()
 {
-	if (mProgressView)
-	{
-		mProgressView->setStartupComplete();
-	}
+    if (mProgressView)
+    {
+        mProgressView->setStartupComplete();
+    }
 }
 
 BOOL LLViewerWindow::getShowProgress() const
 {
-	return (mProgressView && mProgressView->getVisible());
+    return (mProgressView && mProgressView->getVisible());
 }
 
 void LLViewerWindow::setProgressString(const std::string& string)
 {
-	if (mProgressView)
-	{
-		mProgressView->setText(string);
-	}
+    if (mProgressView)
+    {
+        mProgressView->setText(string);
+    }
 }
 
 void LLViewerWindow::setProgressMessage(const std::string& msg)
 {
-	if(mProgressView)
-	{
-		mProgressView->setMessage(msg);
-	}
+    if(mProgressView)
+    {
+        mProgressView->setMessage(msg);
+    }
 }
 
 void LLViewerWindow::setProgressPercent(const F32 percent)
 {
-	if (mProgressView)
-	{
-		mProgressView->setPercent(percent);
-	}
+    if (mProgressView)
+    {
+        mProgressView->setPercent(percent);
+    }
 }
 
 void LLViewerWindow::setProgressCancelButtonVisible( BOOL b, const std::string& label )
 {
-	LLFloaterProgressView* pProgFloater = LLFloaterReg::findTypedInstance<LLFloaterProgressView>("progress_view");
-	if(pProgFloater)
-	{
-		pProgFloater->setProgressCancelButtonVisible(b, label);
-	}
-	if (mProgressView)
-	{
-		mProgressView->setCancelButtonVisible( b, label );
-	}
+    LLFloaterProgressView* pProgFloater = LLFloaterReg::findTypedInstance<LLFloaterProgressView>("progress_view");
+    if(pProgFloater)
+    {
+        pProgFloater->setProgressCancelButtonVisible(b, label);
+    }
+    if (mProgressView)
+    {
+        mProgressView->setCancelButtonVisible( b, label );
+    }
 }
 
 LLProgressView *LLViewerWindow::getProgressView() const
 {
-	return mProgressView;
+    return mProgressView;
 }
 
 void LLViewerWindow::dumpState()
 {
-	LL_INFOS() << "LLViewerWindow Active " << S32(mActive) << LL_ENDL;
-	LL_INFOS() << "mWindow visible " << S32(mWindow->getVisible())
-		<< " minimized " << S32(mWindow->getMinimized())
-		<< LL_ENDL;
+    LL_INFOS() << "LLViewerWindow Active " << S32(mActive) << LL_ENDL;
+    LL_INFOS() << "mWindow visible " << S32(mWindow->getVisible())
+        << " minimized " << S32(mWindow->getMinimized())
+        << LL_ENDL;
 }
 
 void LLViewerWindow::stopGL(BOOL save_state)
 {
-	//Note: --bao
-	//if not necessary, do not change the order of the function calls in this function.
-	//if change something, make sure it will not break anything.
-	//especially be careful to put anything behind gTextureList.destroyGL(save_state);
-	if (!gGLManager.mIsDisabled)
-	{
-		LL_INFOS() << "Shutting down GL..." << LL_ENDL;
-
-		// Pause texture decode threads (will get unpaused during main loop)
-		LLAppViewer::getTextureCache()->pause();
-		LLAppViewer::getTextureFetch()->pause();
-				
-		gSky.destroyGL();
-		stop_glerror();		
-
-		LLManipTranslate::destroyGL() ;
-		stop_glerror();		
-
-		gBumpImageList.destroyGL();
-		stop_glerror();
-
-		LLFontGL::destroyAllGL();
-		stop_glerror();
-
-		LLVOAvatar::destroyGL();
-		stop_glerror();
-
-		LLVOPartGroup::destroyGL();
-		stop_glerror();
-
-		LLViewerDynamicTexture::destroyGL();
-		stop_glerror();
-
-		if (gPipeline.isInit())
-		{
-			gPipeline.destroyGL();
-		}
-		stop_glerror();
-		
-		gBox.cleanupGL();
-		stop_glerror();
-		
-		gTextureList.destroyGL(save_state);
-		stop_glerror();
-		
-		gGLManager.mIsDisabled = TRUE;
-		stop_glerror();
-
-		//unload shader's
-		while (!LLGLSLShader::sInstances.empty())
-		{
-			LLGLSLShader* shader = *(LLGLSLShader::sInstances.begin());
-			shader->unload();
-		}
-	}
+    //Note: --bao
+    //if not necessary, do not change the order of the function calls in this function.
+    //if change something, make sure it will not break anything.
+    //especially be careful to put anything behind gTextureList.destroyGL(save_state);
+    if (!gGLManager.mIsDisabled)
+    {
+        LL_INFOS() << "Shutting down GL..." << LL_ENDL;
+
+        // Pause texture decode threads (will get unpaused during main loop)
+        LLAppViewer::getTextureCache()->pause();
+        LLAppViewer::getTextureFetch()->pause();
+
+        gSky.destroyGL();
+        stop_glerror();
+
+        LLManipTranslate::destroyGL() ;
+        stop_glerror();
+
+        gBumpImageList.destroyGL();
+        stop_glerror();
+
+        LLFontGL::destroyAllGL();
+        stop_glerror();
+
+        LLVOAvatar::destroyGL();
+        stop_glerror();
+
+        LLVOPartGroup::destroyGL();
+        stop_glerror();
+
+        LLViewerDynamicTexture::destroyGL();
+        stop_glerror();
+
+        if (gPipeline.isInit())
+        {
+            gPipeline.destroyGL();
+        }
+        stop_glerror();
+
+        gBox.cleanupGL();
+        stop_glerror();
+
+        gTextureList.destroyGL(save_state);
+        stop_glerror();
+
+        gGLManager.mIsDisabled = TRUE;
+        stop_glerror();
+
+        //unload shader's
+        while (!LLGLSLShader::sInstances.empty())
+        {
+            LLGLSLShader* shader = *(LLGLSLShader::sInstances.begin());
+            shader->unload();
+        }
+    }
 }
 
 void LLViewerWindow::restoreGL(const std::string& progress_message)
 {
-	//Note: --bao
-	//if not necessary, do not change the order of the function calls in this function.
-	//if change something, make sure it will not break anything. 
-	//especially, be careful to put something before gTextureList.restoreGL();
-	if (gGLManager.mIsDisabled)
-	{
-		LL_INFOS() << "Restoring GL..." << LL_ENDL;
-		gGLManager.mIsDisabled = FALSE;
-		
-		gGL.init(true);
-		initGLDefaults();
-		gGL.refreshState();
-		LLGLState::restoreGL();
-		
-		gTextureList.restoreGL();
-		
-		// for future support of non-square pixels, and fonts that are properly stretched
-		//LLFontGL::destroyDefaultFonts();
-		initFonts();
-				
-		gSky.restoreGL();
-		gPipeline.restoreGL();
-		LLManipTranslate::restoreGL();
-		
-		gBumpImageList.restoreGL();
-		LLViewerDynamicTexture::restoreGL();
-		LLVOAvatar::restoreGL();
-		LLVOPartGroup::restoreGL();
-		
-		gResizeScreenTexture = TRUE;
-		gWindowResized = TRUE;
-
-		if (isAgentAvatarValid() && gAgentAvatarp->isEditingAppearance())
-		{
-			LLVisualParamHint::requestHintUpdates();
-		}
-
-		if (!progress_message.empty())
-		{
-			gRestoreGLTimer.reset();
-			gRestoreGL = TRUE;
-			setShowProgress(TRUE);
-			setProgressString(progress_message);
-		}
-		LL_INFOS() << "...Restoring GL done" << LL_ENDL;
-		if(!LLAppViewer::instance()->restoreErrorTrap())
-		{
-			LL_WARNS() << " Someone took over my signal/exception handler (post restoreGL)!" << LL_ENDL;
-		}
-
-	}
+    //Note: --bao
+    //if not necessary, do not change the order of the function calls in this function.
+    //if change something, make sure it will not break anything.
+    //especially, be careful to put something before gTextureList.restoreGL();
+    if (gGLManager.mIsDisabled)
+    {
+        LL_INFOS() << "Restoring GL..." << LL_ENDL;
+        gGLManager.mIsDisabled = FALSE;
+
+        gGL.init(true);
+        initGLDefaults();
+        gGL.refreshState();
+        LLGLState::restoreGL();
+
+        gTextureList.restoreGL();
+
+        // for future support of non-square pixels, and fonts that are properly stretched
+        //LLFontGL::destroyDefaultFonts();
+        initFonts();
+
+        gSky.restoreGL();
+        gPipeline.restoreGL();
+        LLManipTranslate::restoreGL();
+
+        gBumpImageList.restoreGL();
+        LLViewerDynamicTexture::restoreGL();
+        LLVOAvatar::restoreGL();
+        LLVOPartGroup::restoreGL();
+
+        gResizeScreenTexture = TRUE;
+        gWindowResized = TRUE;
+
+        if (isAgentAvatarValid() && gAgentAvatarp->isEditingAppearance())
+        {
+            LLVisualParamHint::requestHintUpdates();
+        }
+
+        if (!progress_message.empty())
+        {
+            gRestoreGLTimer.reset();
+            gRestoreGL = TRUE;
+            setShowProgress(TRUE);
+            setProgressString(progress_message);
+        }
+        LL_INFOS() << "...Restoring GL done" << LL_ENDL;
+        if(!LLAppViewer::instance()->restoreErrorTrap())
+        {
+            LL_WARNS() << " Someone took over my signal/exception handler (post restoreGL)!" << LL_ENDL;
+        }
+
+    }
 }
 
 void LLViewerWindow::initFonts(F32 zoom_factor)
 {
-	LLFontGL::destroyAllGL();
-	// Initialize with possibly different zoom factor
+    LLFontGL::destroyAllGL();
+    // Initialize with possibly different zoom factor
 
-	LLFontManager::initClass();
+    LLFontManager::initClass();
 
-	std::string font_dir;
+    std::string font_dir;
 #if LL_WINDOWS
-	font_dir = gDirUtilp->getExecutableDir();
+    font_dir = gDirUtilp->getExecutableDir();
 #else
-	font_dir = gDirUtilp->getAppRODataDir();
+    font_dir = gDirUtilp->getAppRODataDir();
 #endif
-	std::vector<std::string> font_files(1, "fonts.xml");
-	std::string strFontOverride = gSavedSettings.getString("FontOverrideMain");
-	if (!strFontOverride.empty())
-		font_files.push_back(strFontOverride);
-	strFontOverride = gSavedSettings.getString("FontOverrideMonospace");
-	if (!strFontOverride.empty())
-		font_files.push_back(strFontOverride);
-	LLFontGL::initClass(font_files, gSavedSettings.getF32("FontScreenDPI"),
-								mDisplayScale.mV[VX] * zoom_factor,
-								mDisplayScale.mV[VY] * zoom_factor,
-								font_dir);
+    std::vector<std::string> font_files(1, "fonts.xml");
+    std::string strFontOverride = gSavedSettings.getString("FontOverrideMain");
+    if (!strFontOverride.empty())
+        font_files.push_back(strFontOverride);
+    strFontOverride = gSavedSettings.getString("FontOverrideMonospace");
+    if (!strFontOverride.empty())
+        font_files.push_back(strFontOverride);
+    LLFontGL::initClass(font_files, gSavedSettings.getF32("FontScreenDPI"),
+                                mDisplayScale.mV[VX] * zoom_factor,
+                                mDisplayScale.mV[VY] * zoom_factor,
+                                font_dir);
 }
 
 void LLViewerWindow::requestResolutionUpdate()
 {
-	mResDirty = true;
+    mResDirty = true;
 }
 
 static LLTrace::BlockTimerStatHandle FTM_WINDOW_CHECK_SETTINGS("Window Settings");
 
 void LLViewerWindow::checkSettings()
 {
-	LL_RECORD_BLOCK_TIME(FTM_WINDOW_CHECK_SETTINGS);
-	if (mStatesDirty)
-	{
-		gGL.refreshState();
-		LLViewerShaderMgr::instance()->setShaders();
-		mStatesDirty = false;
-	}
-	
-	// We want to update the resolution AFTER the states getting refreshed not before.
-	if (mResDirty)
-	{
-		reshape(getWindowWidthRaw(), getWindowHeightRaw());
-		mResDirty = false;
-	}	
+    LL_RECORD_BLOCK_TIME(FTM_WINDOW_CHECK_SETTINGS);
+    if (mStatesDirty)
+    {
+        gGL.refreshState();
+        LLViewerShaderMgr::instance()->setShaders();
+        mStatesDirty = false;
+    }
+
+    // We want to update the resolution AFTER the states getting refreshed not before.
+    if (mResDirty)
+    {
+        reshape(getWindowWidthRaw(), getWindowHeightRaw());
+        mResDirty = false;
+    }
 }
 
 void LLViewerWindow::restartDisplay(BOOL show_progress_bar)
 {
-	LL_INFOS() << "Restaring GL" << LL_ENDL;
-	stopGL();
-	if (show_progress_bar)
-	{
-		restoreGL(LLTrans::getString("ProgressChangingResolution"));
-	}
-	else
-	{
-		restoreGL();
-	}
+    LL_INFOS() << "Restaring GL" << LL_ENDL;
+    stopGL();
+    if (show_progress_bar)
+    {
+        restoreGL(LLTrans::getString("ProgressChangingResolution"));
+    }
+    else
+    {
+        restoreGL();
+    }
 }
 
 BOOL LLViewerWindow::changeDisplaySettings(LLCoordScreen size, BOOL enable_vsync, BOOL show_progress_bar)
 {
-	//BOOL was_maximized = gSavedSettings.getBOOL("WindowMaximized");
+    //BOOL was_maximized = gSavedSettings.getBOOL("WindowMaximized");
 
-	//gResizeScreenTexture = TRUE;
+    //gResizeScreenTexture = TRUE;
 
 
-	//U32 fsaa = gSavedSettings.getU32("RenderFSAASamples");
-	//U32 old_fsaa = mWindow->getFSAASamples();
+    //U32 fsaa = gSavedSettings.getU32("RenderFSAASamples");
+    //U32 old_fsaa = mWindow->getFSAASamples();
 
-	// if not maximized, use the request size
-	if (!mWindow->getMaximized())
-	{
-		mWindow->setSize(size);
-	}
+    // if not maximized, use the request size
+    if (!mWindow->getMaximized())
+    {
+        mWindow->setSize(size);
+    }
 
-	//if (fsaa == old_fsaa)
-	{
-		return TRUE;
-	}
+    //if (fsaa == old_fsaa)
+    {
+        return TRUE;
+    }
 
 /*
 
-	// Close floaters that don't handle settings change
-	LLFloaterReg::hideInstance("snapshot");
-	
-	BOOL result_first_try = FALSE;
-	BOOL result_second_try = FALSE;
-
-	LLFocusableElement* keyboard_focus = gFocusMgr.getKeyboardFocus();
-	send_agent_pause();
-	LL_INFOS() << "Stopping GL during changeDisplaySettings" << LL_ENDL;
-	stopGL();
-	mIgnoreActivate = TRUE;
-	LLCoordScreen old_size;
-	LLCoordScreen old_pos;
-	mWindow->getSize(&old_size);
-
-	//mWindow->setFSAASamples(fsaa);
-
-	result_first_try = mWindow->switchContext(false, size, disable_vsync);
-	if (!result_first_try)
-	{
-		// try to switch back
-		//mWindow->setFSAASamples(old_fsaa);
-		result_second_try = mWindow->switchContext(false, old_size, disable_vsync);
-
-		if (!result_second_try)
-		{
-			// we are stuck...try once again with a minimal resolution?
-			send_agent_resume();
-			mIgnoreActivate = FALSE;
-			return FALSE;
-		}
-	}
-	send_agent_resume();
-
-	LL_INFOS() << "Restoring GL during resolution change" << LL_ENDL;
-	if (show_progress_bar)
-	{
-		restoreGL(LLTrans::getString("ProgressChangingResolution"));
-	}
-	else
-	{
-		restoreGL();
-	}
-
-	if (!result_first_try)
-	{
-		LLSD args;
-		args["RESX"] = llformat("%d",size.mX);
-		args["RESY"] = llformat("%d",size.mY);
-		LLNotificationsUtil::add("ResolutionSwitchFail", args);
-		size = old_size; // for reshape below
-	}
-
-	BOOL success = result_first_try || result_second_try;
-
-	if (success)
-	{
-		// maximize window if was maximized, else reposition
-		if (was_maximized)
-		{
-			mWindow->maximize();
-		}
-		else
-		{
-			S32 windowX = gSavedSettings.getS32("WindowX");
-			S32 windowY = gSavedSettings.getS32("WindowY");
-
-			mWindow->setPosition(LLCoordScreen ( windowX, windowY ) );
-		}
-	}
-
-	mIgnoreActivate = FALSE;
-	gFocusMgr.setKeyboardFocus(keyboard_focus);
-	
-	return success;
-
-	*/
-}
-
-F32	LLViewerWindow::getWorldViewAspectRatio() const
-{
-	F32 world_aspect = (F32)mWorldViewRectRaw.getWidth() / (F32)mWorldViewRectRaw.getHeight();
-	return world_aspect;
+    // Close floaters that don't handle settings change
+    LLFloaterReg::hideInstance("snapshot");
+
+    BOOL result_first_try = FALSE;
+    BOOL result_second_try = FALSE;
+
+    LLFocusableElement* keyboard_focus = gFocusMgr.getKeyboardFocus();
+    send_agent_pause();
+    LL_INFOS() << "Stopping GL during changeDisplaySettings" << LL_ENDL;
+    stopGL();
+    mIgnoreActivate = TRUE;
+    LLCoordScreen old_size;
+    LLCoordScreen old_pos;
+    mWindow->getSize(&old_size);
+
+    //mWindow->setFSAASamples(fsaa);
+
+    result_first_try = mWindow->switchContext(false, size, disable_vsync);
+    if (!result_first_try)
+    {
+        // try to switch back
+        //mWindow->setFSAASamples(old_fsaa);
+        result_second_try = mWindow->switchContext(false, old_size, disable_vsync);
+
+        if (!result_second_try)
+        {
+            // we are stuck...try once again with a minimal resolution?
+            send_agent_resume();
+            mIgnoreActivate = FALSE;
+            return FALSE;
+        }
+    }
+    send_agent_resume();
+
+    LL_INFOS() << "Restoring GL during resolution change" << LL_ENDL;
+    if (show_progress_bar)
+    {
+        restoreGL(LLTrans::getString("ProgressChangingResolution"));
+    }
+    else
+    {
+        restoreGL();
+    }
+
+    if (!result_first_try)
+    {
+        LLSD args;
+        args["RESX"] = llformat("%d",size.mX);
+        args["RESY"] = llformat("%d",size.mY);
+        LLNotificationsUtil::add("ResolutionSwitchFail", args);
+        size = old_size; // for reshape below
+    }
+
+    BOOL success = result_first_try || result_second_try;
+
+    if (success)
+    {
+        // maximize window if was maximized, else reposition
+        if (was_maximized)
+        {
+            mWindow->maximize();
+        }
+        else
+        {
+            S32 windowX = gSavedSettings.getS32("WindowX");
+            S32 windowY = gSavedSettings.getS32("WindowY");
+
+            mWindow->setPosition(LLCoordScreen ( windowX, windowY ) );
+        }
+    }
+
+    mIgnoreActivate = FALSE;
+    gFocusMgr.setKeyboardFocus(keyboard_focus);
+
+    return success;
+
+    */
+}
+
+F32 LLViewerWindow::getWorldViewAspectRatio() const
+{
+    F32 world_aspect = (F32)mWorldViewRectRaw.getWidth() / (F32)mWorldViewRectRaw.getHeight();
+    return world_aspect;
 }
 
 void LLViewerWindow::calcDisplayScale()
 {
-	F32 ui_scale_factor = llclamp(gSavedSettings.getF32("UIScaleFactor") * mWindow->getSystemUISize(), MIN_UI_SCALE, MAX_UI_SCALE);
-	LLVector2 display_scale;
-	display_scale.setVec(llmax(1.f / mWindow->getPixelAspectRatio(), 1.f), llmax(mWindow->getPixelAspectRatio(), 1.f));
-	display_scale *= ui_scale_factor;
+    F32 ui_scale_factor = llclamp(gSavedSettings.getF32("UIScaleFactor") * mWindow->getSystemUISize(), MIN_UI_SCALE, MAX_UI_SCALE);
+    LLVector2 display_scale;
+    display_scale.setVec(llmax(1.f / mWindow->getPixelAspectRatio(), 1.f), llmax(mWindow->getPixelAspectRatio(), 1.f));
+    display_scale *= ui_scale_factor;
+
+    // limit minimum display scale
+    if (display_scale.mV[VX] < MIN_DISPLAY_SCALE || display_scale.mV[VY] < MIN_DISPLAY_SCALE)
+    {
+        display_scale *= MIN_DISPLAY_SCALE / llmin(display_scale.mV[VX], display_scale.mV[VY]);
+    }
 
-	// limit minimum display scale
-	if (display_scale.mV[VX] < MIN_DISPLAY_SCALE || display_scale.mV[VY] < MIN_DISPLAY_SCALE)
-	{
-		display_scale *= MIN_DISPLAY_SCALE / llmin(display_scale.mV[VX], display_scale.mV[VY]);
-	}
-	
-	if (display_scale != mDisplayScale)
-	{
-		LL_INFOS() << "Setting display scale to " << display_scale << " for ui scale: " << ui_scale_factor << LL_ENDL;
+    if (display_scale != mDisplayScale)
+    {
+        LL_INFOS() << "Setting display scale to " << display_scale << " for ui scale: " << ui_scale_factor << LL_ENDL;
 
-		mDisplayScale = display_scale;
-		// Init default fonts
-		initFonts();
-	}
+        mDisplayScale = display_scale;
+        // Init default fonts
+        initFonts();
+    }
 }
 
 //static
-LLRect 	LLViewerWindow::calcScaledRect(const LLRect & rect, const LLVector2& display_scale)
+LLRect  LLViewerWindow::calcScaledRect(const LLRect & rect, const LLVector2& display_scale)
 {
-	LLRect res = rect;
-	res.mLeft = ll_round((F32)res.mLeft / display_scale.mV[VX]);
-	res.mRight = ll_round((F32)res.mRight / display_scale.mV[VX]);
-	res.mBottom = ll_round((F32)res.mBottom / display_scale.mV[VY]);
-	res.mTop = ll_round((F32)res.mTop / display_scale.mV[VY]);
+    LLRect res = rect;
+    res.mLeft = ll_round((F32)res.mLeft / display_scale.mV[VX]);
+    res.mRight = ll_round((F32)res.mRight / display_scale.mV[VX]);
+    res.mBottom = ll_round((F32)res.mBottom / display_scale.mV[VY]);
+    res.mTop = ll_round((F32)res.mTop / display_scale.mV[VY]);
 
-	return res;
+    return res;
 }
 
 S32 LLViewerWindow::getChatConsoleBottomPad()
 {
-	S32 offset = 0;
+    S32 offset = 0;
 
-	if(gToolBarView)
-		offset += gToolBarView->getBottomToolbar()->getRect().getHeight();
+    if(gToolBarView)
+        offset += gToolBarView->getBottomToolbar()->getRect().getHeight();
 
-	return offset;
+    return offset;
 }
 
 LLRect LLViewerWindow::getChatConsoleRect()
 {
-	LLRect full_window(0, getWindowHeightScaled(), getWindowWidthScaled(), 0);
-	LLRect console_rect = full_window;
+    LLRect full_window(0, getWindowHeightScaled(), getWindowWidthScaled(), 0);
+    LLRect console_rect = full_window;
 
-	const S32 CONSOLE_PADDING_TOP = 24;
-	const S32 CONSOLE_PADDING_LEFT = 24;
-	const S32 CONSOLE_PADDING_RIGHT = 10;
+    const S32 CONSOLE_PADDING_TOP = 24;
+    const S32 CONSOLE_PADDING_LEFT = 24;
+    const S32 CONSOLE_PADDING_RIGHT = 10;
 
-	console_rect.mTop    -= CONSOLE_PADDING_TOP;
-	console_rect.mBottom += getChatConsoleBottomPad();
+    console_rect.mTop    -= CONSOLE_PADDING_TOP;
+    console_rect.mBottom += getChatConsoleBottomPad();
 
-	console_rect.mLeft   += CONSOLE_PADDING_LEFT; 
+    console_rect.mLeft   += CONSOLE_PADDING_LEFT;
 
-	static const BOOL CHAT_FULL_WIDTH = gSavedSettings.getBOOL("ChatFullWidth");
+    static const BOOL CHAT_FULL_WIDTH = gSavedSettings.getBOOL("ChatFullWidth");
 
-	if (CHAT_FULL_WIDTH)
-	{
-		console_rect.mRight -= CONSOLE_PADDING_RIGHT;
-	}
-	else
-	{
-		// Make console rect somewhat narrow so having inventory open is
-		// less of a problem.
-		console_rect.mRight  = console_rect.mLeft + 2 * getWindowWidthScaled() / 3;
-	}
+    if (CHAT_FULL_WIDTH)
+    {
+        console_rect.mRight -= CONSOLE_PADDING_RIGHT;
+    }
+    else
+    {
+        // Make console rect somewhat narrow so having inventory open is
+        // less of a problem.
+        console_rect.mRight  = console_rect.mLeft + 2 * getWindowWidthScaled() / 3;
+    }
 
-	return console_rect;
+    return console_rect;
 }
 
 void LLViewerWindow::reshapeStatusBarContainer()
@@ -6538,7 +6538,7 @@ void LLViewerWindow::reshapeStatusBarContainer()
     S32 new_height = mStatusBarContainer->getRect().getHeight();
     S32 new_width = mStatusBarContainer->getRect().getWidth();
 
-	static LLCachedControl<bool> show_navbar_nav_panel(gSavedSettings, "ShowNavbarNavigationPanel");
+    static LLCachedControl<bool> show_navbar_nav_panel(gSavedSettings, "ShowNavbarNavigationPanel");
     if (show_navbar_nav_panel)
     {
         // Navigation bar is outside visible area, expand status_bar_container to show it
@@ -6550,40 +6550,40 @@ void LLViewerWindow::reshapeStatusBarContainer()
         new_height -= mNavBarBarContainer->getRect().getHeight();
     }
     mStatusBarContainer
-		->reshape(new_width, new_height, TRUE);
+        ->reshape(new_width, new_height, TRUE);
 }
 //----------------------------------------------------------------------------
 
 
 void LLViewerWindow::setUIVisibility(bool visible)
 {
-	mUIVisible = visible;
+    mUIVisible = visible;
 
-	if (!visible)
-	{
-		gAgentCamera.changeCameraToThirdPerson(FALSE);
-		gFloaterView->hideAllFloaters();
-	}
-	else
-	{
-		gFloaterView->showHiddenFloaters();
-	}
+    if (!visible)
+    {
+        gAgentCamera.changeCameraToThirdPerson(FALSE);
+        gFloaterView->hideAllFloaters();
+    }
+    else
+    {
+        gFloaterView->showHiddenFloaters();
+    }
 
-	if (gToolBarView)
-	{
-		gToolBarView->setToolBarsVisible(visible);
-	}
+    if (gToolBarView)
+    {
+        gToolBarView->setToolBarsVisible(visible);
+    }
 
-	static LLCachedControl<bool> show_navbar_nav_panel(gSavedSettings, "ShowNavbarNavigationPanel");
-	static LLCachedControl<bool> show_miniloc_panel(gSavedSettings, "ShowMiniLocationPanel");
-	LLNavigationBar::getInstance()->setVisible(visible ? show_navbar_nav_panel : FALSE);
-	LLPanelTopInfoBar::getInstance()->setVisible(visible? show_miniloc_panel : FALSE);
-	mStatusBarContainer->setVisible(visible);
+    static LLCachedControl<bool> show_navbar_nav_panel(gSavedSettings, "ShowNavbarNavigationPanel");
+    static LLCachedControl<bool> show_miniloc_panel(gSavedSettings, "ShowMiniLocationPanel");
+    LLNavigationBar::getInstance()->setVisible(visible ? show_navbar_nav_panel : FALSE);
+    LLPanelTopInfoBar::getInstance()->setVisible(visible? show_miniloc_panel : FALSE);
+    mStatusBarContainer->setVisible(visible);
 }
 
 bool LLViewerWindow::getUIVisibility()
 {
-	return mUIVisible;
+    return mUIVisible;
 }
 
 ////////////////////////////////////////////////////////////////////////////
@@ -6591,22 +6591,22 @@ bool LLViewerWindow::getUIVisibility()
 // LLPickInfo
 //
 LLPickInfo::LLPickInfo()
-	: mKeyMask(MASK_NONE),
-	  mPickCallback(NULL),
-	  mPickType(PICK_INVALID),
-	  mWantSurfaceInfo(FALSE),
-	  mObjectFace(-1),
-	  mUVCoords(-1.f, -1.f),
-	  mSTCoords(-1.f, -1.f),
-	  mXYCoords(-1, -1),
-	  mIntersection(),
-	  mNormal(),
-	  mTangent(),
-	  mBinormal(),
-	  mHUDIcon(NULL),
-	  mPickTransparent(FALSE),
-	  mPickRigged(FALSE),
-	  mPickParticle(FALSE)
+    : mKeyMask(MASK_NONE),
+      mPickCallback(NULL),
+      mPickType(PICK_INVALID),
+      mWantSurfaceInfo(FALSE),
+      mObjectFace(-1),
+      mUVCoords(-1.f, -1.f),
+      mSTCoords(-1.f, -1.f),
+      mXYCoords(-1, -1),
+      mIntersection(),
+      mNormal(),
+      mTangent(),
+      mBinormal(),
+      mHUDIcon(NULL),
+      mPickTransparent(FALSE),
+      mPickRigged(FALSE),
+      mPickParticle(FALSE)
 {
 }
 
@@ -6636,252 +6636,252 @@ LLPickInfo::LLPickInfo(const LLCoordGL& mouse_pos,
     mPickRigged(pick_rigged),
     mPickParticle(pick_particle),
     mPickReflectionProbe(pick_reflection_probe),
-	  mPickUnselectable(pick_unselectable)
+      mPickUnselectable(pick_unselectable)
 {
 }
 
 void LLPickInfo::fetchResults()
 {
-	S32 face_hit = -1;
+    S32 face_hit = -1;
 
-	LLVector4a intersection, normal;
-	LLVector4a tangent;
+    LLVector4a intersection, normal;
+    LLVector4a tangent;
 
-	LLVector2 uv;
+    LLVector2 uv;
 
-	LLHUDIcon* hit_icon = gViewerWindow->cursorIntersectIcon(mMousePt.mX, mMousePt.mY, 512.f, &intersection);
-	
-	LLVector4a origin;
-	origin.load3(LLViewerCamera::getInstance()->getOrigin().mV);
-	F32 icon_dist = 0.f;
-	LLVector4a start;
-	LLVector4a end;
-	LLVector4a particle_end;
+    LLHUDIcon* hit_icon = gViewerWindow->cursorIntersectIcon(mMousePt.mX, mMousePt.mY, 512.f, &intersection);
 
-	if (hit_icon)
-	{
-		LLVector4a delta;
-		delta.setSub(intersection, origin);
-		icon_dist = delta.getLength3().getF32();
-	}
+    LLVector4a origin;
+    origin.load3(LLViewerCamera::getInstance()->getOrigin().mV);
+    F32 icon_dist = 0.f;
+    LLVector4a start;
+    LLVector4a end;
+    LLVector4a particle_end;
 
-	LLViewerObject* hit_object = gViewerWindow->cursorIntersect(mMousePt.mX, mMousePt.mY, 512.f,
-									nullptr, -1, mPickTransparent, mPickRigged, mPickUnselectable, mPickReflectionProbe, &face_hit, &mGLTFNodeIndex, &mGLTFPrimitiveIndex,
+    if (hit_icon)
+    {
+        LLVector4a delta;
+        delta.setSub(intersection, origin);
+        icon_dist = delta.getLength3().getF32();
+    }
+
+    LLViewerObject* hit_object = gViewerWindow->cursorIntersect(mMousePt.mX, mMousePt.mY, 512.f,
+                                    nullptr, -1, mPickTransparent, mPickRigged, mPickUnselectable, mPickReflectionProbe, &face_hit, &mGLTFNodeIndex, &mGLTFPrimitiveIndex,
                                 &intersection, &uv, &normal, &tangent, &start, &end);
-	
-	mPickPt = mMousePt;
+
+    mPickPt = mMousePt;
 
 // [RLVa:KB] - Checked: RLVa-2.2 (@setoverlay)
-	if ( (RlvActions::hasBehaviour(RLV_BHVR_SETOVERLAY)) && (hit_object) && (!hit_object->isHUDAttachment()) )
-	{
-		std::list<RlvOverlayEffect*> effects;
-		LLVfxManager::instance().getEffects<RlvOverlayEffect>(effects);
-		for (const RlvOverlayEffect* pEffect : effects)
-		{
-			if (pEffect->getEnabled() && pEffect->hitTest(mMousePt))
-			{
-				hit_object = nullptr;
-				break;
-			}
-		}
-	}
+    if ( (RlvActions::hasBehaviour(RLV_BHVR_SETOVERLAY)) && (hit_object) && (!hit_object->isHUDAttachment()) )
+    {
+        std::list<RlvOverlayEffect*> effects;
+        LLVfxManager::instance().getEffects<RlvOverlayEffect>(effects);
+        for (const RlvOverlayEffect* pEffect : effects)
+        {
+            if (pEffect->getEnabled() && pEffect->hitTest(mMousePt))
+            {
+                hit_object = nullptr;
+                break;
+            }
+        }
+    }
 // [/RLVa:KB]
 
-	U32 te_offset = face_hit > -1 ? face_hit : 0;
-
-	if (mPickParticle)
-	{ //get the end point of line segement to use for particle raycast
-		if (hit_object)
-		{
-			particle_end = intersection;
-		}
-		else
-		{
-			particle_end = end;
-		}
-	}
-
-	LLViewerObject* objectp = hit_object;
-
-
-	LLVector4a delta;
-	delta.setSub(origin, intersection);
-
-	if (hit_icon && 
-		(!objectp || 
-		icon_dist < delta.getLength3().getF32()))
-	{
-		// was this name referring to a hud icon?
-		mHUDIcon = hit_icon;
-		mPickType = PICK_ICON;
-		mPosGlobal = mHUDIcon->getPositionGlobal();
-
-	}
-	else if (objectp)
-	{
-		if( objectp->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH )
-		{
-			// Hit land
-			mPickType = PICK_LAND;
-			mObjectID.setNull(); // land has no id
-
-			// put global position into land_pos
-			LLVector3d land_pos;
-			if (!gViewerWindow->mousePointOnLandGlobal(mPickPt.mX, mPickPt.mY, &land_pos, mPickUnselectable))
-			{
-				// The selected point is beyond the draw distance or is otherwise 
-				// not selectable. Return before calling mPickCallback().
-				return;
-			}
-
-			// Fudge the land focus a little bit above ground.
-			mPosGlobal = land_pos + LLVector3d::z_axis * 0.1f;
-		}
-		else
-		{
-			if(isFlora(objectp))
-			{
-				mPickType = PICK_FLORA;
-			}
-			else
-			{
-				mPickType = PICK_OBJECT;
-			}
-
-			LLVector3 v_intersection(intersection.getF32ptr());
-
-			mObjectOffset = gAgentCamera.calcFocusOffset(objectp, v_intersection, mPickPt.mX, mPickPt.mY);
-			mObjectID = objectp->mID;
-			mObjectFace = (te_offset == NO_FACE) ? -1 : (S32)te_offset;
-
-			
-
-			mPosGlobal = gAgent.getPosGlobalFromAgent(v_intersection);
-			
-			if (mWantSurfaceInfo)
-			{
-				getSurfaceInfo();
-			}
-		}
-	}
-	
-	if (mPickParticle)
-	{ //search for closest particle to click origin out to intersection point
-		S32 part_face = -1;
-
-		LLVOPartGroup* group = gPipeline.lineSegmentIntersectParticle(start, particle_end, NULL, &part_face);
-		if (group)
-		{
-			mParticleOwnerID = group->getPartOwner(part_face);
-			mParticleSourceID = group->getPartSource(part_face);
-		}
-	}
-
-	if (mPickCallback)
-	{
-		mPickCallback(*this);
-	}
+    U32 te_offset = face_hit > -1 ? face_hit : 0;
+
+    if (mPickParticle)
+    { //get the end point of line segement to use for particle raycast
+        if (hit_object)
+        {
+            particle_end = intersection;
+        }
+        else
+        {
+            particle_end = end;
+        }
+    }
+
+    LLViewerObject* objectp = hit_object;
+
+
+    LLVector4a delta;
+    delta.setSub(origin, intersection);
+
+    if (hit_icon &&
+        (!objectp ||
+        icon_dist < delta.getLength3().getF32()))
+    {
+        // was this name referring to a hud icon?
+        mHUDIcon = hit_icon;
+        mPickType = PICK_ICON;
+        mPosGlobal = mHUDIcon->getPositionGlobal();
+
+    }
+    else if (objectp)
+    {
+        if( objectp->getPCode() == LLViewerObject::LL_VO_SURFACE_PATCH )
+        {
+            // Hit land
+            mPickType = PICK_LAND;
+            mObjectID.setNull(); // land has no id
+
+            // put global position into land_pos
+            LLVector3d land_pos;
+            if (!gViewerWindow->mousePointOnLandGlobal(mPickPt.mX, mPickPt.mY, &land_pos, mPickUnselectable))
+            {
+                // The selected point is beyond the draw distance or is otherwise
+                // not selectable. Return before calling mPickCallback().
+                return;
+            }
+
+            // Fudge the land focus a little bit above ground.
+            mPosGlobal = land_pos + LLVector3d::z_axis * 0.1f;
+        }
+        else
+        {
+            if(isFlora(objectp))
+            {
+                mPickType = PICK_FLORA;
+            }
+            else
+            {
+                mPickType = PICK_OBJECT;
+            }
+
+            LLVector3 v_intersection(intersection.getF32ptr());
+
+            mObjectOffset = gAgentCamera.calcFocusOffset(objectp, v_intersection, mPickPt.mX, mPickPt.mY);
+            mObjectID = objectp->mID;
+            mObjectFace = (te_offset == NO_FACE) ? -1 : (S32)te_offset;
+
+
+
+            mPosGlobal = gAgent.getPosGlobalFromAgent(v_intersection);
+
+            if (mWantSurfaceInfo)
+            {
+                getSurfaceInfo();
+            }
+        }
+    }
+
+    if (mPickParticle)
+    { //search for closest particle to click origin out to intersection point
+        S32 part_face = -1;
+
+        LLVOPartGroup* group = gPipeline.lineSegmentIntersectParticle(start, particle_end, NULL, &part_face);
+        if (group)
+        {
+            mParticleOwnerID = group->getPartOwner(part_face);
+            mParticleSourceID = group->getPartSource(part_face);
+        }
+    }
+
+    if (mPickCallback)
+    {
+        mPickCallback(*this);
+    }
 }
 
 LLPointer<LLViewerObject> LLPickInfo::getObject() const
 {
-	return gObjectList.findObject( mObjectID );
+    return gObjectList.findObject( mObjectID );
 }
 
 void LLPickInfo::updateXYCoords()
 {
-	if (mObjectFace > -1)
-	{
-		const LLTextureEntry* tep = getObject()->getTE(mObjectFace);
-		LLPointer<LLViewerTexture> imagep = LLViewerTextureManager::getFetchedTexture(tep->getID());
-		if(mUVCoords.mV[VX] >= 0.f && mUVCoords.mV[VY] >= 0.f && imagep.notNull())
-		{
-			mXYCoords.mX = ll_round(mUVCoords.mV[VX] * (F32)imagep->getWidth());
-			mXYCoords.mY = ll_round((1.f - mUVCoords.mV[VY]) * (F32)imagep->getHeight());
-		}
-	}
+    if (mObjectFace > -1)
+    {
+        const LLTextureEntry* tep = getObject()->getTE(mObjectFace);
+        LLPointer<LLViewerTexture> imagep = LLViewerTextureManager::getFetchedTexture(tep->getID());
+        if(mUVCoords.mV[VX] >= 0.f && mUVCoords.mV[VY] >= 0.f && imagep.notNull())
+        {
+            mXYCoords.mX = ll_round(mUVCoords.mV[VX] * (F32)imagep->getWidth());
+            mXYCoords.mY = ll_round((1.f - mUVCoords.mV[VY]) * (F32)imagep->getHeight());
+        }
+    }
 }
 
 void LLPickInfo::getSurfaceInfo()
 {
-	// set values to uninitialized - this is what we return if no intersection is found
-	mObjectFace   = -1;
-	mUVCoords     = LLVector2(-1, -1);
-	mSTCoords     = LLVector2(-1, -1);
-	mXYCoords	  = LLCoordScreen(-1, -1);
-	mIntersection = LLVector3(0,0,0);
-	mNormal       = LLVector3(0,0,0);
-	mBinormal     = LLVector3(0,0,0);
-	mTangent	  = LLVector4(0,0,0,0);
-	
-	LLVector4a tangent;
-	LLVector4a intersection;
-	LLVector4a normal;
-
-	tangent.clear();
-	normal.clear();
-	intersection.clear();
-	
-	LLViewerObject* objectp = getObject();
-
-	if (objectp)
-	{
-		if (gViewerWindow->cursorIntersect(ll_round((F32)mMousePt.mX), ll_round((F32)mMousePt.mY), 1024.f,
-										   objectp, -1, mPickTransparent, mPickRigged, mPickUnselectable, mPickReflectionProbe,
-										   &mObjectFace,
+    // set values to uninitialized - this is what we return if no intersection is found
+    mObjectFace   = -1;
+    mUVCoords     = LLVector2(-1, -1);
+    mSTCoords     = LLVector2(-1, -1);
+    mXYCoords     = LLCoordScreen(-1, -1);
+    mIntersection = LLVector3(0,0,0);
+    mNormal       = LLVector3(0,0,0);
+    mBinormal     = LLVector3(0,0,0);
+    mTangent      = LLVector4(0,0,0,0);
+
+    LLVector4a tangent;
+    LLVector4a intersection;
+    LLVector4a normal;
+
+    tangent.clear();
+    normal.clear();
+    intersection.clear();
+
+    LLViewerObject* objectp = getObject();
+
+    if (objectp)
+    {
+        if (gViewerWindow->cursorIntersect(ll_round((F32)mMousePt.mX), ll_round((F32)mMousePt.mY), 1024.f,
+                                           objectp, -1, mPickTransparent, mPickRigged, mPickUnselectable, mPickReflectionProbe,
+                                           &mObjectFace,
                                            &mGLTFNodeIndex,
                                            &mGLTFPrimitiveIndex,
-										   &intersection,
-										   &mSTCoords,
-										   &normal,
-										   &tangent))
-		{
-			// if we succeeded with the intersect above, compute the texture coordinates:
-
-			if (objectp->mDrawable.notNull() && mObjectFace > -1)
-			{
-				LLFace* facep = objectp->mDrawable->getFace(mObjectFace);
-				if (facep)
-				{
-					mUVCoords = facep->surfaceToTexture(mSTCoords, intersection, normal);
-			}
-			}
-
-			mIntersection.set(intersection.getF32ptr());
-			mNormal.set(normal.getF32ptr());
-			mTangent.set(tangent.getF32ptr());
-
-			//extrapoloate binormal from normal and tangent
-			
-			LLVector4a binormal;
-			binormal.setCross3(normal, tangent);
-			binormal.mul(tangent.getF32ptr()[3]);
-
-			mBinormal.set(binormal.getF32ptr());
-
-			mBinormal.normalize();
-			mNormal.normalize();
-			mTangent.normalize();
-
-			// and XY coords:
-			updateXYCoords();
-			
-		}
-	}
-}
-
-//static 
+                                           &intersection,
+                                           &mSTCoords,
+                                           &normal,
+                                           &tangent))
+        {
+            // if we succeeded with the intersect above, compute the texture coordinates:
+
+            if (objectp->mDrawable.notNull() && mObjectFace > -1)
+            {
+                LLFace* facep = objectp->mDrawable->getFace(mObjectFace);
+                if (facep)
+                {
+                    mUVCoords = facep->surfaceToTexture(mSTCoords, intersection, normal);
+            }
+            }
+
+            mIntersection.set(intersection.getF32ptr());
+            mNormal.set(normal.getF32ptr());
+            mTangent.set(tangent.getF32ptr());
+
+            //extrapoloate binormal from normal and tangent
+
+            LLVector4a binormal;
+            binormal.setCross3(normal, tangent);
+            binormal.mul(tangent.getF32ptr()[3]);
+
+            mBinormal.set(binormal.getF32ptr());
+
+            mBinormal.normalize();
+            mNormal.normalize();
+            mTangent.normalize();
+
+            // and XY coords:
+            updateXYCoords();
+
+        }
+    }
+}
+
+//static
 bool LLPickInfo::isFlora(LLViewerObject* object)
 {
-	if (!object) return false;
+    if (!object) return false;
 
-	LLPCode pcode = object->getPCode();
+    LLPCode pcode = object->getPCode();
 
-	if( (LL_PCODE_LEGACY_GRASS == pcode) 
-		|| (LL_PCODE_LEGACY_TREE == pcode) 
-		|| (LL_PCODE_TREE_NEW == pcode))
-	{
-		return true;
-	}
-	return false;
+    if( (LL_PCODE_LEGACY_GRASS == pcode)
+        || (LL_PCODE_LEGACY_TREE == pcode)
+        || (LL_PCODE_TREE_NEW == pcode))
+    {
+        return true;
+    }
+    return false;
 }
diff --git a/indra/newview/llviewerwindow.h b/indra/newview/llviewerwindow.h
index de0674657857cad0ce0f1e843f3e8026bc2a0e07..e218d453f0a9743da5aa4402b157bb45ae8b3258 100644
--- a/indra/newview/llviewerwindow.h
+++ b/indra/newview/llviewerwindow.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llviewerwindow.h
  * @brief Description of the LLViewerWindow class.
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -79,69 +79,69 @@ class LLCubeMapArray;
 class LLPickInfo
 {
 public:
-	typedef enum
-	{
-		PICK_OBJECT,
-		PICK_FLORA,
-		PICK_LAND,
-		PICK_ICON,
-		PICK_PARCEL_WALL,
-		PICK_INVALID
-	} EPickType;
+    typedef enum
+    {
+        PICK_OBJECT,
+        PICK_FLORA,
+        PICK_LAND,
+        PICK_ICON,
+        PICK_PARCEL_WALL,
+        PICK_INVALID
+    } EPickType;
 
 public:
-	LLPickInfo();
-	LLPickInfo(const LLCoordGL& mouse_pos, 
-		MASK keyboard_mask, 
-		BOOL pick_transparent,
-		BOOL pick_rigged,
-		BOOL pick_particle,
+    LLPickInfo();
+    LLPickInfo(const LLCoordGL& mouse_pos,
+        MASK keyboard_mask,
+        BOOL pick_transparent,
+        BOOL pick_rigged,
+        BOOL pick_particle,
         BOOL pick_reflection_probe,
-		BOOL pick_surface_info,
-		BOOL pick_unselectable,
-		void (*pick_callback)(const LLPickInfo& pick_info));
+        BOOL pick_surface_info,
+        BOOL pick_unselectable,
+        void (*pick_callback)(const LLPickInfo& pick_info));
 
-	void fetchResults();
-	LLPointer<LLViewerObject> getObject() const;
-	LLUUID getObjectID() const { return mObjectID; }
-	bool isValid() const { return mPickType != PICK_INVALID; }
+    void fetchResults();
+    LLPointer<LLViewerObject> getObject() const;
+    LLUUID getObjectID() const { return mObjectID; }
+    bool isValid() const { return mPickType != PICK_INVALID; }
 
-	static bool isFlora(LLViewerObject* object);
+    static bool isFlora(LLViewerObject* object);
 
 public:
-	LLCoordGL		mMousePt;
-	MASK			mKeyMask;
-	void			(*mPickCallback)(const LLPickInfo& pick_info);
-
-	EPickType		mPickType;
-	LLCoordGL		mPickPt;
-	LLVector3d		mPosGlobal;
-	LLVector3		mObjectOffset;
-	LLUUID			mObjectID;
-	LLUUID			mParticleOwnerID;
-	LLUUID			mParticleSourceID;
-	S32				mObjectFace;
+    LLCoordGL       mMousePt;
+    MASK            mKeyMask;
+    void            (*mPickCallback)(const LLPickInfo& pick_info);
+
+    EPickType       mPickType;
+    LLCoordGL       mPickPt;
+    LLVector3d      mPosGlobal;
+    LLVector3       mObjectOffset;
+    LLUUID          mObjectID;
+    LLUUID          mParticleOwnerID;
+    LLUUID          mParticleSourceID;
+    S32             mObjectFace;
     S32             mGLTFNodeIndex = -1;
     S32             mGLTFPrimitiveIndex = -1;
-	LLHUDIcon*		mHUDIcon;
-	LLVector3       mIntersection;
-	LLVector2		mUVCoords;
-	LLVector2       mSTCoords;
-	LLCoordScreen	mXYCoords;
-	LLVector3		mNormal;
-	LLVector4		mTangent;
-	LLVector3		mBinormal;
-	BOOL			mPickTransparent;
-	BOOL			mPickRigged;
-	BOOL			mPickParticle;
-	BOOL			mPickUnselectable = FALSE;
+    LLHUDIcon*      mHUDIcon;
+    LLVector3       mIntersection;
+    LLVector2       mUVCoords;
+    LLVector2       mSTCoords;
+    LLCoordScreen   mXYCoords;
+    LLVector3       mNormal;
+    LLVector4       mTangent;
+    LLVector3       mBinormal;
+    BOOL            mPickTransparent;
+    BOOL            mPickRigged;
+    BOOL            mPickParticle;
+    BOOL            mPickUnselectable = FALSE;
     BOOL            mPickReflectionProbe = FALSE;
-	void		    getSurfaceInfo();
+    void            getSurfaceInfo();
 
 private:
-	void			updateXYCoords();
+    void            updateXYCoords();
 
-	BOOL			mWantSurfaceInfo;   // do we populate mUVCoord, mNormal, mBinormal?
+    BOOL            mWantSurfaceInfo;   // do we populate mUVCoord, mNormal, mBinormal?
 
 };
 
@@ -150,233 +150,233 @@ static const U32 MAX_SNAPSHOT_IMAGE_SIZE = 10240; // max snapshot image size
 class LLViewerWindow final : public LLWindowCallbacks
 {
 public:
-	//
-	// CREATORS
-	//
-	struct Params : public LLInitParam::Block<Params>
-	{
-		Mandatory<std::string>		title,
-									name;
-		Mandatory<S32>				x,
-									y,
-									width,
-									height,
-									min_width,
-									min_height;
-		Optional<bool>				fullscreen,
-									ignore_pixel_depth,
-									first_run;
-
-		Params();
-	};
-
-	LLViewerWindow(const Params& p);
-	virtual ~LLViewerWindow();
-
-	void			shutdownViews();
-	void			shutdownGL();
-	
-	void			initGLDefaults();
-	void			initBase();
-	void			adjustRectanglesForFirstUse(const LLRect& window);
-	void            adjustControlRectanglesForFirstUse(const LLRect& window);
-	void			initWorldUI();
-	void			setUIVisibility(bool);
-	bool			getUIVisibility();
-	void			handlePieMenu(S32 x, S32 y, MASK mask);
+    //
+    // CREATORS
+    //
+    struct Params : public LLInitParam::Block<Params>
+    {
+        Mandatory<std::string>      title,
+                                    name;
+        Mandatory<S32>              x,
+                                    y,
+                                    width,
+                                    height,
+                                    min_width,
+                                    min_height;
+        Optional<bool>              fullscreen,
+                                    ignore_pixel_depth,
+                                    first_run;
+
+        Params();
+    };
+
+    LLViewerWindow(const Params& p);
+    virtual ~LLViewerWindow();
+
+    void            shutdownViews();
+    void            shutdownGL();
+
+    void            initGLDefaults();
+    void            initBase();
+    void            adjustRectanglesForFirstUse(const LLRect& window);
+    void            adjustControlRectanglesForFirstUse(const LLRect& window);
+    void            initWorldUI();
+    void            setUIVisibility(bool);
+    bool            getUIVisibility();
+    void            handlePieMenu(S32 x, S32 y, MASK mask);
 
     void            reshapeStatusBarContainer();
 
-	BOOL handleAnyMouseClick(LLWindow *window, LLCoordGL pos, MASK mask, EMouseClickType clicktype, BOOL down, bool &is_toolmgr_action);
-
-	//
-	// LLWindowCallback interface implementation
-	//
-	/*virtual*/ BOOL handleTranslatedKeyDown(KEY key,  MASK mask, BOOL repeated);
-	/*virtual*/ BOOL handleTranslatedKeyUp(KEY key,  MASK mask);
-	/*virtual*/ void handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level);
-	/*virtual*/ BOOL handleUnicodeChar(llwchar uni_char, MASK mask);	// NOT going to handle extended 
-	/*virtual*/ BOOL handleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
-	/*virtual*/ BOOL handleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
-	/*virtual*/ BOOL handleCloseRequest(LLWindow *window);
-	/*virtual*/ void handleQuit(LLWindow *window);
-	/*virtual*/ BOOL handleRightMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
-	/*virtual*/ BOOL handleRightMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
-	/*virtual*/ BOOL handleMiddleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
-	/*virtual*/ BOOL handleMiddleMouseUp(LLWindow *window, LLCoordGL pos, MASK mask);
-	/*virtual*/ BOOL handleOtherMouseDown(LLWindow *window, LLCoordGL pos, MASK mask, S32 button);
-	/*virtual*/ BOOL handleOtherMouseUp(LLWindow *window, LLCoordGL pos, MASK mask, S32 button);
-	BOOL handleOtherMouse(LLWindow *window, LLCoordGL pos, MASK mask, S32 button, bool down);
+    BOOL handleAnyMouseClick(LLWindow *window, LLCoordGL pos, MASK mask, EMouseClickType clicktype, BOOL down, bool &is_toolmgr_action);
+
+    //
+    // LLWindowCallback interface implementation
+    //
+    /*virtual*/ BOOL handleTranslatedKeyDown(KEY key,  MASK mask, BOOL repeated);
+    /*virtual*/ BOOL handleTranslatedKeyUp(KEY key,  MASK mask);
+    /*virtual*/ void handleScanKey(KEY key, BOOL key_down, BOOL key_up, BOOL key_level);
+    /*virtual*/ BOOL handleUnicodeChar(llwchar uni_char, MASK mask);    // NOT going to handle extended
+    /*virtual*/ BOOL handleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
+    /*virtual*/ BOOL handleMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
+    /*virtual*/ BOOL handleCloseRequest(LLWindow *window);
+    /*virtual*/ void handleQuit(LLWindow *window);
+    /*virtual*/ BOOL handleRightMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
+    /*virtual*/ BOOL handleRightMouseUp(LLWindow *window,  LLCoordGL pos, MASK mask);
+    /*virtual*/ BOOL handleMiddleMouseDown(LLWindow *window,  LLCoordGL pos, MASK mask);
+    /*virtual*/ BOOL handleMiddleMouseUp(LLWindow *window, LLCoordGL pos, MASK mask);
+    /*virtual*/ BOOL handleOtherMouseDown(LLWindow *window, LLCoordGL pos, MASK mask, S32 button);
+    /*virtual*/ BOOL handleOtherMouseUp(LLWindow *window, LLCoordGL pos, MASK mask, S32 button);
+    BOOL handleOtherMouse(LLWindow *window, LLCoordGL pos, MASK mask, S32 button, bool down);
 // [SL:KB] - Patch: Build-DragNDrop | Checked: 2013-07-22 (Catznip-3.6)
-	/*virtual*/ LLWindowCallbacks::DragNDropResult handleDragNDrop(LLWindow* window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action, 
+    /*virtual*/ LLWindowCallbacks::DragNDropResult handleDragNDrop(LLWindow* window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action,
                                                                    LLWindowCallbacks::DragNDropType type, const std::vector<std::string>& data);
-	            LLWindowCallbacks::DragNDropResult handleDragNDropDefault(LLWindow* window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action, std::string data);
-	            LLWindowCallbacks::DragNDropResult handleDragNDropFile(LLWindow* window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action, 
+                LLWindowCallbacks::DragNDropResult handleDragNDropDefault(LLWindow* window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action, std::string data);
+                LLWindowCallbacks::DragNDropResult handleDragNDropFile(LLWindow* window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action,
                                                                        LLWindowCallbacks::DragNDropType type, const std::vector<std::string>& data);
 // [/SL:KB]
-//	/*virtual*/ LLWindowCallbacks::DragNDropResult handleDragNDrop(LLWindow *window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action, std::string data);
-				void handleMouseMove(LLWindow *window,  LLCoordGL pos, MASK mask);
-	/*virtual*/ void handleMouseLeave(LLWindow *window);
-	/*virtual*/ void handleResize(LLWindow *window,  S32 x,  S32 y);
-	/*virtual*/ void handleFocus(LLWindow *window);
-	/*virtual*/ void handleFocusLost(LLWindow *window);
-	/*virtual*/ BOOL handleActivate(LLWindow *window, BOOL activated);
-	/*virtual*/ BOOL handleActivateApp(LLWindow *window, BOOL activating);
-	/*virtual*/ void handleMenuSelect(LLWindow *window,  S32 menu_item);
-	/*virtual*/ BOOL handlePaint(LLWindow *window,  S32 x,  S32 y,  S32 width,  S32 height);
-	/*virtual*/ void handleScrollWheel(LLWindow *window,  S32 clicks);
-	/*virtual*/ void handleScrollHWheel(LLWindow *window,  S32 clicks);
-	/*virtual*/ BOOL handleDoubleClick(LLWindow *window,  LLCoordGL pos, MASK mask);
-	/*virtual*/ void handleWindowBlock(LLWindow *window);
-	/*virtual*/ void handleWindowUnblock(LLWindow *window);
-	/*virtual*/ void handleDataCopy(LLWindow *window, S32 data_type, void *data);
-	/*virtual*/ BOOL handleTimerEvent(LLWindow *window);
-	/*virtual*/ BOOL handleDeviceChange(LLWindow *window);
-	/*virtual*/ BOOL handleDPIChanged(LLWindow *window, F32 ui_scale_factor, S32 window_width, S32 window_height);
-
-	/*virtual*/ void handlePingWatchdog(LLWindow *window, const char * msg);
-	/*virtual*/ void handlePauseWatchdog(LLWindow *window);
-	/*virtual*/ void handleResumeWatchdog(LLWindow *window);
-	/*virtual*/ std::string translateString(const char* tag);
-	/*virtual*/ std::string translateString(const char* tag,
-					const std::map<std::string, std::string>& args);
-	
-	// signal on update of WorldView rect
-	typedef boost::function<void (LLRect old_world_rect, LLRect new_world_rect)> world_rect_callback_t;
-	typedef boost::signals2::signal<void (LLRect old_world_rect, LLRect new_world_rect)> world_rect_signal_t;
-	world_rect_signal_t mOnWorldViewRectUpdated;
-	boost::signals2::connection setOnWorldViewRectUpdated(world_rect_callback_t cb) { return mOnWorldViewRectUpdated.connect(cb); }
-
-	//
-	// ACCESSORS
-	//
-	LLRootView*			getRootView()		const;
-
-	// 3D world area in scaled pixels (via UI scale), use for most UI computations
-	LLRect			getWorldViewRectScaled() const;
-	S32				getWorldViewHeightScaled() const;
-	S32				getWorldViewWidthScaled() const;
-
-	// 3D world area, in raw unscaled pixels
-	const LLRect&   getWorldViewRectRaw() const		{ return mWorldViewRectRaw; }
-	S32 			getWorldViewHeightRaw() const;
-	S32 			getWorldViewWidthRaw() const;
-
-	// Window in scaled pixels (via UI scale), use for most UI computations
-	const LLRect&   getWindowRectScaled() const		{ return mWindowRectScaled; }
-	S32				getWindowHeightScaled() const;
-	S32				getWindowWidthScaled() const;
-
-	// Window in raw pixels as seen on screen.
-	const LLRect&   getWindowRectRaw() const		{ return mWindowRectRaw; }
-	S32				getWindowHeightRaw() const;
-	S32				getWindowWidthRaw() const;
-
-	LLWindow*		getWindow()			const	{ return mWindow; }
-	void*			getPlatformWindow() const;
-	void*			getMediaWindow() 	const;
-	void			focusClient()		const;
-
-	LLCoordGL		getLastMouse()		const	{ return mLastMousePoint; }
-	S32				getLastMouseX()		const	{ return mLastMousePoint.mX; }
-	S32				getLastMouseY()		const	{ return mLastMousePoint.mY; }
-	LLCoordGL		getCurrentMouse()		const	{ return mCurrentMousePoint; }
-	S32				getCurrentMouseX()		const	{ return mCurrentMousePoint.mX; }
-	S32				getCurrentMouseY()		const	{ return mCurrentMousePoint.mY; }
-	S32				getCurrentMouseDX()		const	{ return mCurrentMouseDelta.mX; }
-	S32				getCurrentMouseDY()		const	{ return mCurrentMouseDelta.mY; }
-	LLCoordGL		getCurrentMouseDelta()	const	{ return mCurrentMouseDelta; }
-	static LLTrace::SampleStatHandle<>*	getMouseVelocityStat()		{ return &sMouseVelocityStat; }
-	BOOL			getLeftMouseDown()	const	{ return mLeftMouseDown; }
-	BOOL			getMiddleMouseDown()	const	{ return mMiddleMouseDown; }
-	BOOL			getRightMouseDown()	const	{ return mRightMouseDown; }
-
-	const LLPickInfo&	getLastPick() const { return mLastPick; }
-
-	void			setup2DViewport(S32 x_offset = 0, S32 y_offset = 0);
-	void			setup3DViewport(S32 x_offset = 0, S32 y_offset = 0);
-	void			setup3DRender();
-	void			setup2DRender();
-
-	LLVector3		mouseDirectionGlobal(const S32 x, const S32 y) const;
-	LLVector3		mouseDirectionCamera(const S32 x, const S32 y) const;
-	LLVector3       mousePointHUD(const S32 x, const S32 y) const;
-		
-
-	// Is window of our application frontmost?
-	BOOL			getActive() const			{ return mActive; }
-
-	const std::string&	getInitAlert() { return mInitAlert; }
-	
-	//
-	// MANIPULATORS
-	//
-	void			saveLastMouse(const LLCoordGL &point);
-
-	void			setCursor( ECursorType c );
-	void			showCursor();
-	void			hideCursor();
-	BOOL            getCursorHidden() { return mCursorHidden; }
-	void			moveCursorToCenter();								// move to center of window
-													
-	void			initTextures(S32 location_id);
-	void			setShowProgress(const BOOL show);
-	BOOL			getShowProgress() const;
-	void			setProgressString(const std::string& string);
-	void			setProgressPercent(const F32 percent);
-	void			setProgressMessage(const std::string& msg);
-	void			setProgressCancelButtonVisible( BOOL b, const std::string& label = LLStringUtil::null );
-	LLProgressView *getProgressView() const;
-	void			revealIntroPanel();
-	void			setStartupComplete();
-
-	void			updateObjectUnderCursor();
-
-	void			updateUI();		// Once per frame, update UI based on mouse position, calls following update* functions
-	void				updateLayout();						
-	void				updateMouseDelta();		
-	void				updateKeyboardFocus();		
-
-	void			updateWorldViewRect(bool use_full_window=false);
-	LLView*			getToolBarHolder() { return mToolBarHolder.get(); }
-	LLView*			getHintHolder() { return mHintHolder.get(); }
-	LLView*			getLoginPanelHolder() { return mLoginPanelHolder.get(); }
-	BOOL			handleKey(KEY key, MASK mask);
-	BOOL			handleKeyUp(KEY key, MASK mask);
-	void			handleScrollWheel	(S32 clicks);
-	void			handleScrollHWheel	(S32 clicks);
-
-	// add and remove views from "popup" layer
-	void			addPopup(LLView* popup);
-	void			removePopup(LLView* popup);
-	void			clearPopups();
-
-	// Hide normal UI when a logon fails, re-show everything when logon is attempted again
-	void			setNormalControlsVisible( BOOL visible );
-	void			setMenuBackgroundColor(bool god_mode = false, bool dev_grid = false);
-
-	void			reshape(S32 width, S32 height);
-	void			sendShapeToSim();
-
-	void			draw();
-	void			updateDebugText();
-	void			drawDebugText();
-
-	static void		loadUserImage(void **cb_data, const LLUUID &uuid);
-
-	static void		movieSize(S32 new_width, S32 new_height);
-
-	// snapshot functionality.
-	// perhaps some of this should move to llfloatershapshot?  -MG
-
-	BOOL			saveSnapshot(const std::string&  filename, S32 image_width, S32 image_height, BOOL show_ui = TRUE, BOOL show_hud = TRUE, BOOL do_rebuild = FALSE, LLSnapshotModel::ESnapshotLayerType type = LLSnapshotModel::SNAPSHOT_TYPE_COLOR, LLSnapshotModel::ESnapshotFormat format = LLSnapshotModel::SNAPSHOT_FORMAT_BMP);
-	BOOL			rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_height, BOOL keep_window_aspect = TRUE, BOOL is_texture = FALSE,
-		BOOL show_ui = TRUE, BOOL show_hud = TRUE, BOOL do_rebuild = FALSE, BOOL no_post = FALSE, LLSnapshotModel::ESnapshotLayerType type = LLSnapshotModel::SNAPSHOT_TYPE_COLOR, S32 max_size = MAX_SNAPSHOT_IMAGE_SIZE);
-
-    BOOL			simpleSnapshot(LLImageRaw *raw, S32 image_width, S32 image_height, const int num_render_passes);
-
-    
-    
+//  /*virtual*/ LLWindowCallbacks::DragNDropResult handleDragNDrop(LLWindow *window, LLCoordGL pos, MASK mask, LLWindowCallbacks::DragNDropAction action, std::string data);
+                void handleMouseMove(LLWindow *window,  LLCoordGL pos, MASK mask);
+    /*virtual*/ void handleMouseLeave(LLWindow *window);
+    /*virtual*/ void handleResize(LLWindow *window,  S32 x,  S32 y);
+    /*virtual*/ void handleFocus(LLWindow *window);
+    /*virtual*/ void handleFocusLost(LLWindow *window);
+    /*virtual*/ BOOL handleActivate(LLWindow *window, BOOL activated);
+    /*virtual*/ BOOL handleActivateApp(LLWindow *window, BOOL activating);
+    /*virtual*/ void handleMenuSelect(LLWindow *window,  S32 menu_item);
+    /*virtual*/ BOOL handlePaint(LLWindow *window,  S32 x,  S32 y,  S32 width,  S32 height);
+    /*virtual*/ void handleScrollWheel(LLWindow *window,  S32 clicks);
+    /*virtual*/ void handleScrollHWheel(LLWindow *window,  S32 clicks);
+    /*virtual*/ BOOL handleDoubleClick(LLWindow *window,  LLCoordGL pos, MASK mask);
+    /*virtual*/ void handleWindowBlock(LLWindow *window);
+    /*virtual*/ void handleWindowUnblock(LLWindow *window);
+    /*virtual*/ void handleDataCopy(LLWindow *window, S32 data_type, void *data);
+    /*virtual*/ BOOL handleTimerEvent(LLWindow *window);
+    /*virtual*/ BOOL handleDeviceChange(LLWindow *window);
+    /*virtual*/ BOOL handleDPIChanged(LLWindow *window, F32 ui_scale_factor, S32 window_width, S32 window_height);
+
+    /*virtual*/ void handlePingWatchdog(LLWindow *window, const char * msg);
+    /*virtual*/ void handlePauseWatchdog(LLWindow *window);
+    /*virtual*/ void handleResumeWatchdog(LLWindow *window);
+    /*virtual*/ std::string translateString(const char* tag);
+    /*virtual*/ std::string translateString(const char* tag,
+                    const std::map<std::string, std::string>& args);
+
+    // signal on update of WorldView rect
+    typedef boost::function<void (LLRect old_world_rect, LLRect new_world_rect)> world_rect_callback_t;
+    typedef boost::signals2::signal<void (LLRect old_world_rect, LLRect new_world_rect)> world_rect_signal_t;
+    world_rect_signal_t mOnWorldViewRectUpdated;
+    boost::signals2::connection setOnWorldViewRectUpdated(world_rect_callback_t cb) { return mOnWorldViewRectUpdated.connect(cb); }
+
+    //
+    // ACCESSORS
+    //
+    LLRootView*         getRootView()       const;
+
+    // 3D world area in scaled pixels (via UI scale), use for most UI computations
+    LLRect          getWorldViewRectScaled() const;
+    S32             getWorldViewHeightScaled() const;
+    S32             getWorldViewWidthScaled() const;
+
+    // 3D world area, in raw unscaled pixels
+    const LLRect&   getWorldViewRectRaw() const     { return mWorldViewRectRaw; }
+    S32             getWorldViewHeightRaw() const;
+    S32             getWorldViewWidthRaw() const;
+
+    // Window in scaled pixels (via UI scale), use for most UI computations
+    const LLRect&   getWindowRectScaled() const     { return mWindowRectScaled; }
+    S32             getWindowHeightScaled() const;
+    S32             getWindowWidthScaled() const;
+
+    // Window in raw pixels as seen on screen.
+    const LLRect&   getWindowRectRaw() const        { return mWindowRectRaw; }
+    S32             getWindowHeightRaw() const;
+    S32             getWindowWidthRaw() const;
+
+    LLWindow*       getWindow()         const   { return mWindow; }
+    void*           getPlatformWindow() const;
+    void*           getMediaWindow()    const;
+    void            focusClient()       const;
+
+    LLCoordGL       getLastMouse()      const   { return mLastMousePoint; }
+    S32             getLastMouseX()     const   { return mLastMousePoint.mX; }
+    S32             getLastMouseY()     const   { return mLastMousePoint.mY; }
+    LLCoordGL       getCurrentMouse()       const   { return mCurrentMousePoint; }
+    S32             getCurrentMouseX()      const   { return mCurrentMousePoint.mX; }
+    S32             getCurrentMouseY()      const   { return mCurrentMousePoint.mY; }
+    S32             getCurrentMouseDX()     const   { return mCurrentMouseDelta.mX; }
+    S32             getCurrentMouseDY()     const   { return mCurrentMouseDelta.mY; }
+    LLCoordGL       getCurrentMouseDelta()  const   { return mCurrentMouseDelta; }
+    static LLTrace::SampleStatHandle<>* getMouseVelocityStat()      { return &sMouseVelocityStat; }
+    BOOL            getLeftMouseDown()  const   { return mLeftMouseDown; }
+    BOOL            getMiddleMouseDown()    const   { return mMiddleMouseDown; }
+    BOOL            getRightMouseDown() const   { return mRightMouseDown; }
+
+    const LLPickInfo&   getLastPick() const { return mLastPick; }
+
+    void            setup2DViewport(S32 x_offset = 0, S32 y_offset = 0);
+    void            setup3DViewport(S32 x_offset = 0, S32 y_offset = 0);
+    void            setup3DRender();
+    void            setup2DRender();
+
+    LLVector3       mouseDirectionGlobal(const S32 x, const S32 y) const;
+    LLVector3       mouseDirectionCamera(const S32 x, const S32 y) const;
+    LLVector3       mousePointHUD(const S32 x, const S32 y) const;
+
+
+    // Is window of our application frontmost?
+    BOOL            getActive() const           { return mActive; }
+
+    const std::string&  getInitAlert() { return mInitAlert; }
+
+    //
+    // MANIPULATORS
+    //
+    void            saveLastMouse(const LLCoordGL &point);
+
+    void            setCursor( ECursorType c );
+    void            showCursor();
+    void            hideCursor();
+    BOOL            getCursorHidden() { return mCursorHidden; }
+    void            moveCursorToCenter();                               // move to center of window
+
+    void            initTextures(S32 location_id);
+    void            setShowProgress(const BOOL show);
+    BOOL            getShowProgress() const;
+    void            setProgressString(const std::string& string);
+    void            setProgressPercent(const F32 percent);
+    void            setProgressMessage(const std::string& msg);
+    void            setProgressCancelButtonVisible( BOOL b, const std::string& label = LLStringUtil::null );
+    LLProgressView *getProgressView() const;
+    void            revealIntroPanel();
+    void            setStartupComplete();
+
+    void            updateObjectUnderCursor();
+
+    void            updateUI();     // Once per frame, update UI based on mouse position, calls following update* functions
+    void                updateLayout();
+    void                updateMouseDelta();
+    void                updateKeyboardFocus();
+
+    void            updateWorldViewRect(bool use_full_window=false);
+    LLView*         getToolBarHolder() { return mToolBarHolder.get(); }
+    LLView*         getHintHolder() { return mHintHolder.get(); }
+    LLView*         getLoginPanelHolder() { return mLoginPanelHolder.get(); }
+    BOOL            handleKey(KEY key, MASK mask);
+    BOOL            handleKeyUp(KEY key, MASK mask);
+    void            handleScrollWheel   (S32 clicks);
+    void            handleScrollHWheel  (S32 clicks);
+
+    // add and remove views from "popup" layer
+    void            addPopup(LLView* popup);
+    void            removePopup(LLView* popup);
+    void            clearPopups();
+
+    // Hide normal UI when a logon fails, re-show everything when logon is attempted again
+    void            setNormalControlsVisible( BOOL visible );
+    void            setMenuBackgroundColor(bool god_mode = false, bool dev_grid = false);
+
+    void            reshape(S32 width, S32 height);
+    void            sendShapeToSim();
+
+    void            draw();
+    void            updateDebugText();
+    void            drawDebugText();
+
+    static void     loadUserImage(void **cb_data, const LLUUID &uuid);
+
+    static void     movieSize(S32 new_width, S32 new_height);
+
+    // snapshot functionality.
+    // perhaps some of this should move to llfloatershapshot?  -MG
+
+    BOOL            saveSnapshot(const std::string&  filename, S32 image_width, S32 image_height, BOOL show_ui = TRUE, BOOL show_hud = TRUE, BOOL do_rebuild = FALSE, LLSnapshotModel::ESnapshotLayerType type = LLSnapshotModel::SNAPSHOT_TYPE_COLOR, LLSnapshotModel::ESnapshotFormat format = LLSnapshotModel::SNAPSHOT_FORMAT_BMP);
+    BOOL            rawSnapshot(LLImageRaw *raw, S32 image_width, S32 image_height, BOOL keep_window_aspect = TRUE, BOOL is_texture = FALSE,
+        BOOL show_ui = TRUE, BOOL show_hud = TRUE, BOOL do_rebuild = FALSE, BOOL no_post = FALSE, LLSnapshotModel::ESnapshotLayerType type = LLSnapshotModel::SNAPSHOT_TYPE_COLOR, S32 max_size = MAX_SNAPSHOT_IMAGE_SIZE);
+
+    BOOL            simpleSnapshot(LLImageRaw *raw, S32 image_width, S32 image_height, const int num_render_passes);
+
+
+
     // take a cubemap snapshot
     // origin - vantage point to take the snapshot from
     // cubearray - cubemap array for storing the results
@@ -386,212 +386,212 @@ class LLViewerWindow final : public LLWindowCallbacks
     BOOL cubeSnapshot(const LLVector3 &origin, LLCubeMapArray *cubearray, S32 index, S32 face, F32 near_clip, bool render_avatars,
                       bool customCullingPlane = false, LLPlane cullingPlane = LLPlane(LLVector3(0, 0, 0), LLVector3(0, 0, 1)));
 
-    
+
     // special implementation of simpleSnapshot for reflection maps
-    BOOL			reflectionSnapshot(LLImageRaw* raw, S32 image_width, S32 image_height, const int num_render_passes);
-
-    BOOL			thumbnailSnapshot(LLImageRaw *raw, S32 preview_width, S32 preview_height, BOOL show_ui, BOOL show_hud, BOOL do_rebuild, BOOL no_post, LLSnapshotModel::ESnapshotLayerType type);
-	BOOL			isSnapshotLocSet() const;
-	void			resetSnapshotLoc() const;
-
-	typedef boost::signals2::signal<void(void)> snapshot_saved_signal_t;
-
-	void			saveImageNumbered(LLImageFormatted *image, BOOL force_picker, const snapshot_saved_signal_t::slot_type& success_cb, const snapshot_saved_signal_t::slot_type& failure_cb);
-	void			onDirectorySelected(const std::vector<std::string>& filenames, LLImageFormatted *image, const snapshot_saved_signal_t::slot_type& success_cb, const snapshot_saved_signal_t::slot_type& failure_cb);
-	void			saveImageLocal(LLImageFormatted *image, const snapshot_saved_signal_t::slot_type& success_cb, const snapshot_saved_signal_t::slot_type& failure_cb);
-	void			onSelectionFailure(const snapshot_saved_signal_t::slot_type& failure_cb);
-
-	// Reset the directory where snapshots are saved.
-	// Client will open directory picker on next snapshot save.
-	void resetSnapshotLoc();
-
-	void			playSnapshotAnimAndSound();
-	
-	// draws selection boxes around selected objects, must call displayObjects first
-	void			renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls, BOOL for_hud );
-	void			performPick();
-	void			returnEmptyPicks();
-
-	void			pickAsync(	S32 x,
-								S32 y_from_bot,
-								MASK mask,
-								void (*callback)(const LLPickInfo& pick_info),
-								BOOL pick_transparent = FALSE,
-								BOOL pick_rigged = FALSE,
-								BOOL pick_unselectable = FALSE,
+    BOOL            reflectionSnapshot(LLImageRaw* raw, S32 image_width, S32 image_height, const int num_render_passes);
+
+    BOOL            thumbnailSnapshot(LLImageRaw *raw, S32 preview_width, S32 preview_height, BOOL show_ui, BOOL show_hud, BOOL do_rebuild, BOOL no_post, LLSnapshotModel::ESnapshotLayerType type);
+    BOOL            isSnapshotLocSet() const;
+    void            resetSnapshotLoc() const;
+
+    typedef boost::signals2::signal<void(void)> snapshot_saved_signal_t;
+
+    void            saveImageNumbered(LLImageFormatted *image, BOOL force_picker, const snapshot_saved_signal_t::slot_type& success_cb, const snapshot_saved_signal_t::slot_type& failure_cb);
+    void            onDirectorySelected(const std::vector<std::string>& filenames, LLImageFormatted *image, const snapshot_saved_signal_t::slot_type& success_cb, const snapshot_saved_signal_t::slot_type& failure_cb);
+    void            saveImageLocal(LLImageFormatted *image, const snapshot_saved_signal_t::slot_type& success_cb, const snapshot_saved_signal_t::slot_type& failure_cb);
+    void            onSelectionFailure(const snapshot_saved_signal_t::slot_type& failure_cb);
+
+    // Reset the directory where snapshots are saved.
+    // Client will open directory picker on next snapshot save.
+    void resetSnapshotLoc();
+
+    void            playSnapshotAnimAndSound();
+
+    // draws selection boxes around selected objects, must call displayObjects first
+    void            renderSelections( BOOL for_gl_pick, BOOL pick_parcel_walls, BOOL for_hud );
+    void            performPick();
+    void            returnEmptyPicks();
+
+    void            pickAsync(  S32 x,
+                                S32 y_from_bot,
+                                MASK mask,
+                                void (*callback)(const LLPickInfo& pick_info),
+                                BOOL pick_transparent = FALSE,
+                                BOOL pick_rigged = FALSE,
+                                BOOL pick_unselectable = FALSE,
                                 BOOL pick_reflection_probes = FALSE);
-	LLPickInfo		pickImmediate(S32 x, S32 y, BOOL pick_transparent, BOOL pick_rigged = FALSE, BOOL pick_particle = FALSE, BOOL pick_unselectable = TRUE, BOOL pick_reflection_probe = FALSE);
-	LLHUDIcon* cursorIntersectIcon(S32 mouse_x, S32 mouse_y, F32 depth,
-										   LLVector4a* intersection);
-
-	LLViewerObject* cursorIntersect(S32 mouse_x = -1, S32 mouse_y = -1, F32 depth = 512.f,
-									LLViewerObject *this_object = NULL,
-									S32 this_face = -1,
-									BOOL pick_transparent = FALSE,
-									BOOL pick_rigged = FALSE,
+    LLPickInfo      pickImmediate(S32 x, S32 y, BOOL pick_transparent, BOOL pick_rigged = FALSE, BOOL pick_particle = FALSE, BOOL pick_unselectable = TRUE, BOOL pick_reflection_probe = FALSE);
+    LLHUDIcon* cursorIntersectIcon(S32 mouse_x, S32 mouse_y, F32 depth,
+                                           LLVector4a* intersection);
+
+    LLViewerObject* cursorIntersect(S32 mouse_x = -1, S32 mouse_y = -1, F32 depth = 512.f,
+                                    LLViewerObject *this_object = NULL,
+                                    S32 this_face = -1,
+                                    BOOL pick_transparent = FALSE,
+                                    BOOL pick_rigged = FALSE,
                                     BOOL pick_unselectable = TRUE,
                                     BOOL pick_reflection_probe = TRUE,
-									S32* face_hit = NULL,
+                                    S32* face_hit = NULL,
                                     S32* gltf_node_hit = nullptr,
                                     S32* gltf_primitive_hit = nullptr,
-									LLVector4a *intersection = NULL,
-									LLVector2 *uv = NULL,
-									LLVector4a *normal = NULL,
-									LLVector4a *tangent = NULL,
-									LLVector4a* start = NULL,
-									LLVector4a* end = NULL);
-	
-	
-	// Returns a pointer to the last object hit
-	//LLViewerObject	*getObject();
-	//LLViewerObject  *lastNonFloraObjectHit();
-
-	//const LLVector3d& getObjectOffset();
-	//const LLVector3d& lastNonFloraObjectHitOffset();
-
-	// mousePointOnLand() returns true if found point
-	BOOL			mousePointOnLandGlobal(const S32 x, const S32 y, LLVector3d *land_pos_global, BOOL ignore_distance = FALSE);
-	BOOL			mousePointOnPlaneGlobal(LLVector3d& point, const S32 x, const S32 y, const LLVector3d &plane_point, const LLVector3 &plane_normal);
-	LLVector3d		clickPointInWorldGlobal(const S32 x, const S32 y_from_bot, LLViewerObject* clicked_object) const;
-	BOOL			clickPointOnSurfaceGlobal(const S32 x, const S32 y, LLViewerObject *objectp, LLVector3d &point_global) const;
-
-	// Prints window implementation details
-	void			dumpState();
-
-	// handle shutting down GL and bringing it back up
-	void			requestResolutionUpdate();
-	void			checkSettings();
-	void			restartDisplay(BOOL show_progress_bar);
-	BOOL			changeDisplaySettings(LLCoordScreen size, BOOL enable_vsync, BOOL show_progress_bar);
-	BOOL			getIgnoreDestroyWindow() { return mIgnoreActivate; }
-	F32				getWorldViewAspectRatio() const;
-	const LLVector2& getDisplayScale() const { return mDisplayScale; }
-	void			calcDisplayScale();
-	static LLRect 	calcScaledRect(const LLRect & rect, const LLVector2& display_scale);
-
-	static std::string getLastSnapshotDir();
-
-	LLPanel* getChicletContainer() { return mChicletContainer; }
-	LLView* getFloaterSnapRegion() { return mFloaterSnapRegion; }
+                                    LLVector4a *intersection = NULL,
+                                    LLVector2 *uv = NULL,
+                                    LLVector4a *normal = NULL,
+                                    LLVector4a *tangent = NULL,
+                                    LLVector4a* start = NULL,
+                                    LLVector4a* end = NULL);
+
+
+    // Returns a pointer to the last object hit
+    //LLViewerObject    *getObject();
+    //LLViewerObject  *lastNonFloraObjectHit();
+
+    //const LLVector3d& getObjectOffset();
+    //const LLVector3d& lastNonFloraObjectHitOffset();
+
+    // mousePointOnLand() returns true if found point
+    BOOL            mousePointOnLandGlobal(const S32 x, const S32 y, LLVector3d *land_pos_global, BOOL ignore_distance = FALSE);
+    BOOL            mousePointOnPlaneGlobal(LLVector3d& point, const S32 x, const S32 y, const LLVector3d &plane_point, const LLVector3 &plane_normal);
+    LLVector3d      clickPointInWorldGlobal(const S32 x, const S32 y_from_bot, LLViewerObject* clicked_object) const;
+    BOOL            clickPointOnSurfaceGlobal(const S32 x, const S32 y, LLViewerObject *objectp, LLVector3d &point_global) const;
+
+    // Prints window implementation details
+    void            dumpState();
+
+    // handle shutting down GL and bringing it back up
+    void            requestResolutionUpdate();
+    void            checkSettings();
+    void            restartDisplay(BOOL show_progress_bar);
+    BOOL            changeDisplaySettings(LLCoordScreen size, BOOL enable_vsync, BOOL show_progress_bar);
+    BOOL            getIgnoreDestroyWindow() { return mIgnoreActivate; }
+    F32             getWorldViewAspectRatio() const;
+    const LLVector2& getDisplayScale() const { return mDisplayScale; }
+    void            calcDisplayScale();
+    static LLRect   calcScaledRect(const LLRect & rect, const LLVector2& display_scale);
+
+    static std::string getLastSnapshotDir();
+
+    LLPanel* getChicletContainer() { return mChicletContainer; }
+    LLView* getFloaterSnapRegion() { return mFloaterSnapRegion; }
 
 private:
-	bool                    shouldShowToolTipFor(LLMouseHandler *mh);
-
-	void			switchToolByMask(MASK mask);
-	void			destroyWindow();
-	void			drawMouselookInstructions();
-	void			stopGL(BOOL save_state = TRUE);
-	void			restoreGL(const std::string& progress_message = LLStringUtil::null);
-	void			initFonts(F32 zoom_factor = 1.f);
-	void			schedulePick(LLPickInfo& pick_info);
-	S32				getChatConsoleBottomPad(); // Vertical padding for child console rect, varied by bottom clutter
-	LLRect			getChatConsoleRect(); // Get optimal cosole rect.
+    bool                    shouldShowToolTipFor(LLMouseHandler *mh);
+
+    void            switchToolByMask(MASK mask);
+    void            destroyWindow();
+    void            drawMouselookInstructions();
+    void            stopGL(BOOL save_state = TRUE);
+    void            restoreGL(const std::string& progress_message = LLStringUtil::null);
+    void            initFonts(F32 zoom_factor = 1.f);
+    void            schedulePick(LLPickInfo& pick_info);
+    S32             getChatConsoleBottomPad(); // Vertical padding for child console rect, varied by bottom clutter
+    LLRect          getChatConsoleRect(); // Get optimal cosole rect.
 
 private:
-	LLWindow*		mWindow;						// graphical window object
-	bool			mActive;
-	bool			mUIVisible;
-
-	LLNotificationChannelPtr mSystemChannel;
-	LLNotificationChannelPtr mCommunicationChannel;
-	LLNotificationChannelPtr mAlertsChannel;
-	LLNotificationChannelPtr mModalAlertsChannel;
-
-	LLRect			mWindowRectRaw;				// whole window, including UI
-	LLRect			mWindowRectScaled;			// whole window, scaled by UI size
-	LLRect			mWorldViewRectRaw;			// area of screen for 3D world
-	LLRect			mWorldViewRectScaled;		// area of screen for 3D world scaled by UI size
-	LLRootView*		mRootView;					// a view of size mWindowRectRaw, containing all child views
-	LLVector2		mDisplayScale;
-
-	LLCoordGL		mCurrentMousePoint;			// last mouse position in GL coords
-	LLCoordGL		mLastMousePoint;		// Mouse point at last frame.
-	LLCoordGL		mCurrentMouseDelta;		//amount mouse moved this frame
-	BOOL			mLeftMouseDown;
-	BOOL			mMiddleMouseDown;
-	BOOL			mRightMouseDown;
-
-	LLProgressView	*mProgressView;
-
-	LLFrameTimer	mToolTipFadeTimer;
-	LLPanel*		mToolTip;
-	std::string		mLastToolTipMessage;
-	LLRect			mToolTipStickyRect;			// Once a tool tip is shown, it will stay visible until the mouse leaves this rect.
-
-	BOOL			mMouseInWindow;				// True if the mouse is over our window or if we have captured the mouse.
-	BOOL			mFocusCycleMode;
-	typedef std::set<LLHandle<LLView> > view_handle_set_t;
-	view_handle_set_t mMouseHoverViews;
-
-	// Variables used for tool override switching based on modifier keys.  JC
-	MASK			mLastMask;			// used to detect changes in modifier mask
-	LLTool*			mToolStored;		// the tool we're overriding
-	BOOL			mHideCursorPermanent;	// true during drags, mouselook
-	BOOL            mCursorHidden;
-	LLPickInfo		mLastPick;
-	std::vector<LLPickInfo> mPicks;
-	LLRect			mPickScreenRegion; // area of frame buffer for rendering pick frames (generally follows mouse to avoid going offscreen)
-	LLTimer         mPickTimer;        // timer for scheduling n picks per second
-
-	std::string		mOverlayTitle;		// Used for special titles such as "Second Life - Special E3 2003 Beta"
-
-	BOOL			mIgnoreActivate;
-
-	std::string		mInitAlert;			// Window / GL initialization requires an alert
-
-	LLHandle<LLView> mWorldViewPlaceholder;	// widget that spans the portion of screen dedicated to rendering the 3d world
-	LLHandle<LLView> mToolBarHolder;		// container for toolbars
-	LLHandle<LLView> mHintHolder;			// container for hints
-	LLHandle<LLView> mLoginPanelHolder;		// container for login panel
-	LLPopupView*	mPopupView;			// container for transient popups
-
-	LLView*		mFloaterSnapRegion = nullptr;
-	LLPanel*		mChicletContainer = nullptr;
-	LLPanel*		mStatusBarContainer = nullptr;
-	LLView*		mNavBarBarContainer = nullptr;
-	
-	class LLDebugText* mDebugText; // Internal class for debug text
-	
-	bool			mResDirty;
-	bool			mStatesDirty;
-	U32			mCurrResolutionIndex;
-
-	std::unique_ptr<LLWindowListener> mWindowListener;
-	std::unique_ptr<LLViewerWindowListener> mViewerWindowListener;
-
-	// Object temporarily hovered over while dragging
-	LLPointer<LLViewerObject>	mDragHoveredObject;
+    LLWindow*       mWindow;                        // graphical window object
+    bool            mActive;
+    bool            mUIVisible;
+
+    LLNotificationChannelPtr mSystemChannel;
+    LLNotificationChannelPtr mCommunicationChannel;
+    LLNotificationChannelPtr mAlertsChannel;
+    LLNotificationChannelPtr mModalAlertsChannel;
+
+    LLRect          mWindowRectRaw;             // whole window, including UI
+    LLRect          mWindowRectScaled;          // whole window, scaled by UI size
+    LLRect          mWorldViewRectRaw;          // area of screen for 3D world
+    LLRect          mWorldViewRectScaled;       // area of screen for 3D world scaled by UI size
+    LLRootView*     mRootView;                  // a view of size mWindowRectRaw, containing all child views
+    LLVector2       mDisplayScale;
+
+    LLCoordGL       mCurrentMousePoint;         // last mouse position in GL coords
+    LLCoordGL       mLastMousePoint;        // Mouse point at last frame.
+    LLCoordGL       mCurrentMouseDelta;     //amount mouse moved this frame
+    BOOL            mLeftMouseDown;
+    BOOL            mMiddleMouseDown;
+    BOOL            mRightMouseDown;
+
+    LLProgressView  *mProgressView;
+
+    LLFrameTimer    mToolTipFadeTimer;
+    LLPanel*        mToolTip;
+    std::string     mLastToolTipMessage;
+    LLRect          mToolTipStickyRect;         // Once a tool tip is shown, it will stay visible until the mouse leaves this rect.
+
+    BOOL            mMouseInWindow;             // True if the mouse is over our window or if we have captured the mouse.
+    BOOL            mFocusCycleMode;
+    typedef std::set<LLHandle<LLView> > view_handle_set_t;
+    view_handle_set_t mMouseHoverViews;
+
+    // Variables used for tool override switching based on modifier keys.  JC
+    MASK            mLastMask;          // used to detect changes in modifier mask
+    LLTool*         mToolStored;        // the tool we're overriding
+    BOOL            mHideCursorPermanent;   // true during drags, mouselook
+    BOOL            mCursorHidden;
+    LLPickInfo      mLastPick;
+    std::vector<LLPickInfo> mPicks;
+    LLRect          mPickScreenRegion; // area of frame buffer for rendering pick frames (generally follows mouse to avoid going offscreen)
+    LLTimer         mPickTimer;        // timer for scheduling n picks per second
+
+    std::string     mOverlayTitle;      // Used for special titles such as "Second Life - Special E3 2003 Beta"
+
+    BOOL            mIgnoreActivate;
+
+    std::string     mInitAlert;         // Window / GL initialization requires an alert
+
+    LLHandle<LLView> mWorldViewPlaceholder; // widget that spans the portion of screen dedicated to rendering the 3d world
+    LLHandle<LLView> mToolBarHolder;        // container for toolbars
+    LLHandle<LLView> mHintHolder;           // container for hints
+    LLHandle<LLView> mLoginPanelHolder;     // container for login panel
+    LLPopupView*    mPopupView;         // container for transient popups
+
+    LLView*     mFloaterSnapRegion = nullptr;
+    LLPanel*        mChicletContainer = nullptr;
+    LLPanel*        mStatusBarContainer = nullptr;
+    LLView*     mNavBarBarContainer = nullptr;
+
+    class LLDebugText* mDebugText; // Internal class for debug text
+
+    bool            mResDirty;
+    bool            mStatesDirty;
+    U32         mCurrResolutionIndex;
+
+    std::unique_ptr<LLWindowListener> mWindowListener;
+    std::unique_ptr<LLViewerWindowListener> mViewerWindowListener;
+
+    // Object temporarily hovered over while dragging
+    LLPointer<LLViewerObject>   mDragHoveredObject;
 // [SL:KB] - Patch: Build-DragNDrop | Checked: 2013-07-27 (Catznip-3.6)
-	typedef std::pair<LLPointer<LLViewerInventoryItem>, std::string> drag_item_t;
-	std::vector<drag_item_t> mDragItems;
+    typedef std::pair<LLPointer<LLViewerInventoryItem>, std::string> drag_item_t;
+    std::vector<drag_item_t> mDragItems;
 // [/SL:KB]
 
-	static LLTrace::SampleStatHandle<>	sMouseVelocityStat;
+    static LLTrace::SampleStatHandle<>  sMouseVelocityStat;
 };
 
 //
 // Globals
 //
 
-extern LLViewerWindow*	gViewerWindow;
+extern LLViewerWindow*  gViewerWindow;
 
-extern LLFrameTimer		gAwayTimer;				// tracks time before setting the avatar away state to true
-extern LLFrameTimer		gAwayTriggerTimer;		// how long the avatar has been away
+extern LLFrameTimer     gAwayTimer;             // tracks time before setting the avatar away state to true
+extern LLFrameTimer     gAwayTriggerTimer;      // how long the avatar has been away
 
 extern LLViewerObject*  gDebugRaycastObject;
 extern LLVector4a       gDebugRaycastIntersection;
-extern LLVOPartGroup*	gDebugRaycastParticle;
-extern LLVector4a		gDebugRaycastParticleIntersection;
+extern LLVOPartGroup*   gDebugRaycastParticle;
+extern LLVector4a       gDebugRaycastParticleIntersection;
 extern LLVector2        gDebugRaycastTexCoord;
 extern LLVector4a       gDebugRaycastNormal;
 extern LLVector4a       gDebugRaycastTangent;
-extern S32				gDebugRaycastFaceHit;
-extern LLVector4a		gDebugRaycastStart;
-extern LLVector4a		gDebugRaycastEnd;
-
-extern BOOL			gDisplayCameraPos;
-extern BOOL			gDisplayWindInfo;
-extern BOOL			gDisplayFOV;
-extern BOOL			gDisplayBadge;
+extern S32              gDebugRaycastFaceHit;
+extern LLVector4a       gDebugRaycastStart;
+extern LLVector4a       gDebugRaycastEnd;
+
+extern BOOL         gDisplayCameraPos;
+extern BOOL         gDisplayWindInfo;
+extern BOOL         gDisplayFOV;
+extern BOOL         gDisplayBadge;
 
 #endif
diff --git a/indra/newview/llvlcomposition.cpp b/indra/newview/llvlcomposition.cpp
index 656e819af08660283d1cee9bff9e2d4cf393bfab..40e5aed8ffc11aa6c17e840887efb196d0d02c40 100644
--- a/indra/newview/llvlcomposition.cpp
+++ b/indra/newview/llvlcomposition.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvlcomposition.cpp
  * @brief Viewer-side representation of a composition layer...
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -161,7 +161,7 @@ LLUUID LLTerrainMaterials::getDetailAssetID(S32 asset)
     // Assume both the the material and texture were fetched in the same way
     // using the same UUID. However, we may not know at this point which one
     // will load.
-	return mDetailTextures[asset] ? mDetailTextures[asset]->getID() : LLUUID::null;
+    return mDetailTextures[asset] ? mDetailTextures[asset]->getID() : LLUUID::null;
 }
 
 LLPointer<LLViewerFetchedTexture> fetch_terrain_texture(const LLUUID& id)
@@ -183,9 +183,9 @@ void LLTerrainMaterials::setDetailAssetID(S32 asset, const LLUUID& id)
     unboost_minimap_texture(mDetailTextures[asset]);
     unboost_minimap_material(mDetailMaterials[asset]);
 
-	// This is terrain texture, but we are not setting it as BOOST_TERRAIN
-	// since we will be manipulating it later as needed.
-	mDetailTextures[asset] = fetch_terrain_texture(id);
+    // This is terrain texture, but we are not setting it as BOOST_TERRAIN
+    // since we will be manipulating it later as needed.
+    mDetailTextures[asset] = fetch_terrain_texture(id);
     LLPointer<LLFetchedGLTFMaterial>& mat = mDetailMaterials[asset];
     mat = id.isNull() ? nullptr : gGLTFMaterialList.getMaterial(id);
     mMaterialTexturesSet[asset] = false;
@@ -193,7 +193,7 @@ void LLTerrainMaterials::setDetailAssetID(S32 asset, const LLUUID& id)
 
 LLTerrainMaterials::Type LLTerrainMaterials::getMaterialType()
 {
-	LL_PROFILE_ZONE_SCOPED;
+    LL_PROFILE_ZONE_SCOPED;
 
     const BOOL use_textures = texturesReady(false, false) || !materialsReady(false, false);
     return use_textures ? Type::TEXTURE : Type::PBR;
@@ -372,23 +372,23 @@ const LLUUID (&LLVLComposition::getDefaultTextures())[ASSET_COUNT]
 
 LLVLComposition::LLVLComposition(LLSurface *surfacep, const U32 width, const F32 scale) :
     LLTerrainMaterials(),
-	LLViewerLayer(width, scale)
+    LLViewerLayer(width, scale)
 {
-	// Load Terrain Textures - Original ones
+    // Load Terrain Textures - Original ones
     const LLUUID (&default_textures)[LLVLComposition::ASSET_COUNT] = LLVLComposition::getDefaultTextures();
     for (S32 i = 0; i < ASSET_COUNT; ++i)
     {
         setDetailAssetID(i, default_textures[i]);
     }
 
-	mSurfacep = surfacep;
+    mSurfacep = surfacep;
 
-	// Initialize the texture matrix to defaults.
-	for (S32 i = 0; i < CORNER_COUNT; ++i)
-	{
-		mStartHeight[i] = gSavedSettings.getF32("TerrainColorStartHeight");
-		mHeightRange[i] = gSavedSettings.getF32("TerrainColorHeightRange");
-	}
+    // Initialize the texture matrix to defaults.
+    for (S32 i = 0; i < CORNER_COUNT; ++i)
+    {
+        mStartHeight[i] = gSavedSettings.getF32("TerrainColorStartHeight");
+        mHeightRange[i] = gSavedSettings.getF32("TerrainColorHeightRange");
+    }
 }
 
 
@@ -400,117 +400,117 @@ LLVLComposition::~LLVLComposition()
 
 void LLVLComposition::setSurface(LLSurface *surfacep)
 {
-	mSurfacep = surfacep;
+    mSurfacep = surfacep;
 }
 
 BOOL LLVLComposition::generateHeights(const F32 x, const F32 y,
-									  const F32 width, const F32 height)
+                                      const F32 width, const F32 height)
 {
-	if (!mParamsReady)
-	{
-		// All the parameters haven't been set yet (we haven't gotten the message from the sim)
-		return FALSE;
-	}
-
-	llassert(mSurfacep);
-
-	if (!mSurfacep || !mSurfacep->getRegion()) 
-	{
-		// We don't always have the region yet here....
-		return FALSE;
-	}
-
-	S32 x_begin, y_begin, x_end, y_end;
-
-	x_begin = ll_round( x * mScaleInv );
-	y_begin = ll_round( y * mScaleInv );
-	x_end = ll_round( (x + width) * mScaleInv );
-	y_end = ll_round( (y + width) * mScaleInv );
-
-	if (x_end > mWidth)
-	{
-		x_end = mWidth;
-	}
-	if (y_end > mWidth)
-	{
-		y_end = mWidth;
-	}
-
-	LLVector3d origin_global = from_region_handle(mSurfacep->getRegion()->getHandle());
-
-	// For perlin noise generation...
-	const F32 slope_squared = 1.5f*1.5f;
-	const F32 xyScale = 4.9215f; //0.93284f;
-	const F32 zScale = 4; //0.92165f;
-	const F32 z_offset = 0.f;
-	const F32 noise_magnitude = 2.f;		//  Degree to which noise modulates composition layer (versus
-											//  simple height)
-
-	const F32 xyScaleInv = (1.f / xyScale);
-	const F32 zScaleInv = (1.f / zScale);
-
-	const F32 inv_width = 1.f/(F32)mWidth;
-
-	// OK, for now, just have the composition value equal the height at the point.
-	for (S32 j = y_begin; j < y_end; j++)
-	{
-		for (S32 i = x_begin; i < x_end; i++)
-		{
-
-			F32 vec[3];
-			F32 vec1[3];
-			F32 twiddle;
-
-			// Bilinearly interpolate the start height and height range of the textures
-			F32 start_height = bilinear(mStartHeight[SOUTHWEST],
-										mStartHeight[SOUTHEAST],
-										mStartHeight[NORTHWEST],
-										mStartHeight[NORTHEAST],
-										i*inv_width, j*inv_width); // These will be bilinearly interpolated
-			F32 height_range = bilinear(mHeightRange[SOUTHWEST],
-										mHeightRange[SOUTHEAST],
-										mHeightRange[NORTHWEST],
-										mHeightRange[NORTHEAST],
-										i*inv_width, j*inv_width); // These will be bilinearly interpolated
-
-			LLVector3 location(i*mScale, j*mScale, 0.f);
-
-			F32 height = mSurfacep->resolveHeightRegion(location) + z_offset;
-
-			// Step 0: Measure the exact height at this texel
-			vec[0] = (F32)(origin_global.mdV[VX]+location.mV[VX])*xyScaleInv;	//  Adjust to non-integer lattice
-			vec[1] = (F32)(origin_global.mdV[VY]+location.mV[VY])*xyScaleInv;
-			vec[2] = height*zScaleInv;
-			//
-			//  Choose material value by adding to the exact height a random value 
-			//
-			vec1[0] = vec[0]*(0.2222222222f);
-			vec1[1] = vec[1]*(0.2222222222f);
-			vec1[2] = vec[2]*(0.2222222222f);
-			twiddle = noise2(vec1)*6.5f;					//  Low freq component for large divisions
-
-			twiddle += turbulence2(vec, 2)*slope_squared;	//  High frequency component
-			twiddle *= noise_magnitude;
-
-			F32 scaled_noisy_height = (height + twiddle - start_height) * F32(ASSET_COUNT) / height_range;
-
-			scaled_noisy_height = llmax(0.f, scaled_noisy_height);
-			scaled_noisy_height = llmin(3.f, scaled_noisy_height);
-			*(mDatap + i + j*mWidth) = scaled_noisy_height;
-		}
-	}
-	return TRUE;
+    if (!mParamsReady)
+    {
+        // All the parameters haven't been set yet (we haven't gotten the message from the sim)
+        return FALSE;
+    }
+
+    llassert(mSurfacep);
+
+    if (!mSurfacep || !mSurfacep->getRegion())
+    {
+        // We don't always have the region yet here....
+        return FALSE;
+    }
+
+    S32 x_begin, y_begin, x_end, y_end;
+
+    x_begin = ll_round( x * mScaleInv );
+    y_begin = ll_round( y * mScaleInv );
+    x_end = ll_round( (x + width) * mScaleInv );
+    y_end = ll_round( (y + width) * mScaleInv );
+
+    if (x_end > mWidth)
+    {
+        x_end = mWidth;
+    }
+    if (y_end > mWidth)
+    {
+        y_end = mWidth;
+    }
+
+    LLVector3d origin_global = from_region_handle(mSurfacep->getRegion()->getHandle());
+
+    // For perlin noise generation...
+    const F32 slope_squared = 1.5f*1.5f;
+    const F32 xyScale = 4.9215f; //0.93284f;
+    const F32 zScale = 4; //0.92165f;
+    const F32 z_offset = 0.f;
+    const F32 noise_magnitude = 2.f;        //  Degree to which noise modulates composition layer (versus
+                                            //  simple height)
+
+    const F32 xyScaleInv = (1.f / xyScale);
+    const F32 zScaleInv = (1.f / zScale);
+
+    const F32 inv_width = 1.f/(F32)mWidth;
+
+    // OK, for now, just have the composition value equal the height at the point.
+    for (S32 j = y_begin; j < y_end; j++)
+    {
+        for (S32 i = x_begin; i < x_end; i++)
+        {
+
+            F32 vec[3];
+            F32 vec1[3];
+            F32 twiddle;
+
+            // Bilinearly interpolate the start height and height range of the textures
+            F32 start_height = bilinear(mStartHeight[SOUTHWEST],
+                                        mStartHeight[SOUTHEAST],
+                                        mStartHeight[NORTHWEST],
+                                        mStartHeight[NORTHEAST],
+                                        i*inv_width, j*inv_width); // These will be bilinearly interpolated
+            F32 height_range = bilinear(mHeightRange[SOUTHWEST],
+                                        mHeightRange[SOUTHEAST],
+                                        mHeightRange[NORTHWEST],
+                                        mHeightRange[NORTHEAST],
+                                        i*inv_width, j*inv_width); // These will be bilinearly interpolated
+
+            LLVector3 location(i*mScale, j*mScale, 0.f);
+
+            F32 height = mSurfacep->resolveHeightRegion(location) + z_offset;
+
+            // Step 0: Measure the exact height at this texel
+            vec[0] = (F32)(origin_global.mdV[VX]+location.mV[VX])*xyScaleInv;   //  Adjust to non-integer lattice
+            vec[1] = (F32)(origin_global.mdV[VY]+location.mV[VY])*xyScaleInv;
+            vec[2] = height*zScaleInv;
+            //
+            //  Choose material value by adding to the exact height a random value
+            //
+            vec1[0] = vec[0]*(0.2222222222f);
+            vec1[1] = vec[1]*(0.2222222222f);
+            vec1[2] = vec[2]*(0.2222222222f);
+            twiddle = noise2(vec1)*6.5f;                    //  Low freq component for large divisions
+
+            twiddle += turbulence2(vec, 2)*slope_squared;   //  High frequency component
+            twiddle *= noise_magnitude;
+
+            F32 scaled_noisy_height = (height + twiddle - start_height) * F32(ASSET_COUNT) / height_range;
+
+            scaled_noisy_height = llmax(0.f, scaled_noisy_height);
+            scaled_noisy_height = llmin(3.f, scaled_noisy_height);
+            *(mDatap + i + j*mWidth) = scaled_noisy_height;
+        }
+    }
+    return TRUE;
 }
 
 LLTerrainMaterials gLocalTerrainMaterials;
 
 BOOL LLVLComposition::generateComposition()
 {
-	if (!mParamsReady)
-	{
-		// All the parameters haven't been set yet (we haven't gotten the message from the sim)
-		return FALSE;
-	}
+    if (!mParamsReady)
+    {
+        // All the parameters haven't been set yet (we haven't gotten the message from the sim)
+        return FALSE;
+    }
 
     return LLTerrainMaterials::generateMaterials();
 }
@@ -618,22 +618,22 @@ namespace
 };
 
 BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
-									  const F32 width, const F32 height)
+                                      const F32 width, const F32 height)
 {
-	LL_PROFILE_ZONE_SCOPED
-	llassert(mSurfacep);
-	llassert(x >= 0.f);
-	llassert(y >= 0.f);
+    LL_PROFILE_ZONE_SCOPED
+    llassert(mSurfacep);
+    llassert(x >= 0.f);
+    llassert(y >= 0.f);
 
-	///////////////////////////
-	//
-	// Generate raw data arrays for surface textures
-	//
-	//
+    ///////////////////////////
+    //
+    // Generate raw data arrays for surface textures
+    //
+    //
 
-	// These have already been validated by generateComposition.
-	U8* st_data[ASSET_COUNT];
-	S32 st_data_size[ASSET_COUNT]; // for debugging
+    // These have already been validated by generateComposition.
+    U8* st_data[ASSET_COUNT];
+    S32 st_data_size[ASSET_COUNT]; // for debugging
 
     const bool use_textures = getMaterialType() != LLTerrainMaterials::Type::PBR;
     if (use_textures)
@@ -645,11 +645,11 @@ BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
         if (!materialsReady(true, true)) { return FALSE; }
     }
 
-	for (S32 i = 0; i < ASSET_COUNT; i++)
-	{
-		if (mRawImages[i].isNull())
-		{
-			// Read back a raw image for this discard level, if it exists
+    for (S32 i = 0; i < ASSET_COUNT; i++)
+    {
+        if (mRawImages[i].isNull())
+        {
+            // Read back a raw image for this discard level, if it exists
             LLViewerFetchedTexture* tex;
             LLViewerFetchedTexture* tex_emissive; // Can be null
             bool has_base_color_factor;
@@ -721,14 +721,14 @@ BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
                     raw_emissive = newraw_emissive;
                 }
             }
-			if (has_base_color_factor ||
+            if (has_base_color_factor ||
                 raw_emissive ||
                 has_alpha ||
                 tex->getWidth(tex->getRawImageLevel()) != BASE_SIZE ||
-				tex->getHeight(tex->getRawImageLevel()) != BASE_SIZE ||
-				tex->getComponents() != 3)
-			{
-				LLPointer<LLImageRaw> newraw = new LLImageRaw(BASE_SIZE, BASE_SIZE, 3);
+                tex->getHeight(tex->getRawImageLevel()) != BASE_SIZE ||
+                tex->getComponents() != 3)
+            {
+                LLPointer<LLImageRaw> newraw = new LLImageRaw(BASE_SIZE, BASE_SIZE, 3);
                 if (has_alpha)
                 {
                     // Approximate the water underneath terrain alpha with solid water color
@@ -738,7 +738,7 @@ BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
                         MAX_WATER_COLOR.mV[VZ],
                         255);
                 }
-				newraw->composite(mRawImagesBaseColor[i]);
+                newraw->composite(mRawImagesBaseColor[i]);
                 if (has_base_color_factor)
                 {
                     newraw->tint(base_color_factor);
@@ -749,8 +749,8 @@ BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
                     newraw->addEmissive(raw_emissive);
                 }
 
-				mRawImages[i] = newraw; // deletes old
-			}
+                mRawImages[i] = newraw; // deletes old
+            }
 
             if (delete_raw_post)
             {
@@ -764,150 +764,150 @@ BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
             // Remove intermediary image references
             mRawImagesBaseColor[i] = nullptr;
             mRawImagesEmissive[i] = nullptr;
-		}
-		st_data[i] = mRawImages[i]->getData();
-		st_data_size[i] = mRawImages[i]->getDataSize();
-	}
-
-	///////////////////////////////////////
-	//
-	// Generate and clamp x/y bounding box.
-	//
-	//
-
-	S32 x_begin, y_begin, x_end, y_end;
-	x_begin = (S32)(x * mScaleInv);
-	y_begin = (S32)(y * mScaleInv);
-	x_end = ll_round( (x + width) * mScaleInv );
-	y_end = ll_round( (y + width) * mScaleInv );
-
-	if (x_end > mWidth)
-	{
+        }
+        st_data[i] = mRawImages[i]->getData();
+        st_data_size[i] = mRawImages[i]->getDataSize();
+    }
+
+    ///////////////////////////////////////
+    //
+    // Generate and clamp x/y bounding box.
+    //
+    //
+
+    S32 x_begin, y_begin, x_end, y_end;
+    x_begin = (S32)(x * mScaleInv);
+    y_begin = (S32)(y * mScaleInv);
+    x_end = ll_round( (x + width) * mScaleInv );
+    y_end = ll_round( (y + width) * mScaleInv );
+
+    if (x_end > mWidth)
+    {
         llassert(false);
-		x_end = mWidth;
-	}
-	if (y_end > mWidth)
-	{
+        x_end = mWidth;
+    }
+    if (y_end > mWidth)
+    {
         llassert(false);
-		y_end = mWidth;
-	}
-
-
-	///////////////////////////////////////////
-	//
-	// Generate target texture information, stride ratios.
-	//
-	//
-
-	LLViewerTexture *texturep;
-	U32 tex_width, tex_height, tex_comps;
-	U32 tex_stride;
-	F32 tex_x_scalef, tex_y_scalef;
-	S32 tex_x_begin, tex_y_begin, tex_x_end, tex_y_end;
-	F32 tex_x_ratiof, tex_y_ratiof;
-
-	texturep = mSurfacep->getSTexture();
-	tex_width = texturep->getWidth();
-	tex_height = texturep->getHeight();
-	tex_comps = texturep->getComponents();
-	tex_stride = tex_width * tex_comps;
-
-	U32 st_comps = 3;
-	U32 st_width = BASE_SIZE;
-	U32 st_height = BASE_SIZE;
-	
-	if (tex_comps != st_comps)
-	{
+        y_end = mWidth;
+    }
+
+
+    ///////////////////////////////////////////
+    //
+    // Generate target texture information, stride ratios.
+    //
+    //
+
+    LLViewerTexture *texturep;
+    U32 tex_width, tex_height, tex_comps;
+    U32 tex_stride;
+    F32 tex_x_scalef, tex_y_scalef;
+    S32 tex_x_begin, tex_y_begin, tex_x_end, tex_y_end;
+    F32 tex_x_ratiof, tex_y_ratiof;
+
+    texturep = mSurfacep->getSTexture();
+    tex_width = texturep->getWidth();
+    tex_height = texturep->getHeight();
+    tex_comps = texturep->getComponents();
+    tex_stride = tex_width * tex_comps;
+
+    U32 st_comps = 3;
+    U32 st_width = BASE_SIZE;
+    U32 st_height = BASE_SIZE;
+
+    if (tex_comps != st_comps)
+    {
         llassert(false);
-		return FALSE;
-	}
-
-	tex_x_scalef = (F32)tex_width / (F32)mWidth;
-	tex_y_scalef = (F32)tex_height / (F32)mWidth;
-	tex_x_begin = (S32)((F32)x_begin * tex_x_scalef);
-	tex_y_begin = (S32)((F32)y_begin * tex_y_scalef);
-	tex_x_end = (S32)((F32)x_end * tex_x_scalef);
-	tex_y_end = (S32)((F32)y_end * tex_y_scalef);
-
-	tex_x_ratiof = (F32)mWidth*mScale / (F32)tex_width;
-	tex_y_ratiof = (F32)mWidth*mScale / (F32)tex_height;
-
-	LLPointer<LLImageRaw> raw = new LLImageRaw(tex_width, tex_height, tex_comps);
-	U8 *rawp = raw->getData();
-
-	F32 st_x_stride, st_y_stride;
-	st_x_stride = ((F32)st_width / (F32)mTexScaleX)*((F32)mWidth / (F32)tex_width);
-	st_y_stride = ((F32)st_height / (F32)mTexScaleY)*((F32)mWidth / (F32)tex_height);
-
-	llassert(st_x_stride > 0.f);
-	llassert(st_y_stride > 0.f);
-	////////////////////////////////
-	//
-	// Iterate through the target texture, striding through the
-	// subtextures and interpolating appropriately.
-	//
-	//
-
-	F32 sti, stj;
-	S32 st_offset;
-	sti = (tex_x_begin * st_x_stride) - st_width*(llfloor((tex_x_begin * st_x_stride)/st_width));
-	stj = (tex_y_begin * st_y_stride) - st_height*(llfloor((tex_y_begin * st_y_stride)/st_height));
-
-	st_offset = (llfloor(stj * st_width) + llfloor(sti)) * st_comps;
-	for (S32 j = tex_y_begin; j < tex_y_end; j++)
-	{
-		U32 offset = j * tex_stride + tex_x_begin * tex_comps;
-		sti = (tex_x_begin * st_x_stride) - st_width*((U32)(tex_x_begin * st_x_stride)/st_width);
-		for (S32 i = tex_x_begin; i < tex_x_end; i++)
-		{
-			S32 tex0, tex1;
-			F32 composition = getValueScaled(i*tex_x_ratiof, j*tex_y_ratiof);
-
-			tex0 = llfloor( composition );
-			tex0 = llclamp(tex0, 0, 3);
-			composition -= tex0;
-			tex1 = tex0 + 1;
-			tex1 = llclamp(tex1, 0, 3);
-
-			st_offset = (lltrunc(sti) + lltrunc(stj)*st_width) * st_comps;
-			for (U32 k = 0; k < tex_comps; k++)
-			{
-				// Linearly interpolate based on composition.
-				if (st_offset >= st_data_size[tex0] || st_offset >= st_data_size[tex1])
-				{
-					// SJB: This shouldn't be happening, but does... Rounding error?
-					//LL_WARNS() << "offset 0 [" << tex0 << "] =" << st_offset << " >= size=" << st_data_size[tex0] << LL_ENDL;
-					//LL_WARNS() << "offset 1 [" << tex1 << "] =" << st_offset << " >= size=" << st_data_size[tex1] << LL_ENDL;
-				}
-				else
-				{
-					F32 a = *(st_data[tex0] + st_offset);
-					F32 b = *(st_data[tex1] + st_offset);
-					rawp[ offset ] = (U8)lltrunc( a + composition * (b - a) );
-				}
-				offset++;
-				st_offset++;
-			}
-
-			sti += st_x_stride;
-			if (sti >= st_width)
-			{
-				sti -= st_width;
-			}
-		}
-
-		stj += st_y_stride;
-		if (stj >= st_height)
-		{
-			stj -= st_height;
-		}
-	}
-
-	if (!texturep->hasGLTexture())
-	{
-		texturep->createGLTexture(0, raw);
-	}
-	texturep->setSubImage(raw, tex_x_begin, tex_y_begin, tex_x_end - tex_x_begin, tex_y_end - tex_y_begin);
+        return FALSE;
+    }
+
+    tex_x_scalef = (F32)tex_width / (F32)mWidth;
+    tex_y_scalef = (F32)tex_height / (F32)mWidth;
+    tex_x_begin = (S32)((F32)x_begin * tex_x_scalef);
+    tex_y_begin = (S32)((F32)y_begin * tex_y_scalef);
+    tex_x_end = (S32)((F32)x_end * tex_x_scalef);
+    tex_y_end = (S32)((F32)y_end * tex_y_scalef);
+
+    tex_x_ratiof = (F32)mWidth*mScale / (F32)tex_width;
+    tex_y_ratiof = (F32)mWidth*mScale / (F32)tex_height;
+
+    LLPointer<LLImageRaw> raw = new LLImageRaw(tex_width, tex_height, tex_comps);
+    U8 *rawp = raw->getData();
+
+    F32 st_x_stride, st_y_stride;
+    st_x_stride = ((F32)st_width / (F32)mTexScaleX)*((F32)mWidth / (F32)tex_width);
+    st_y_stride = ((F32)st_height / (F32)mTexScaleY)*((F32)mWidth / (F32)tex_height);
+
+    llassert(st_x_stride > 0.f);
+    llassert(st_y_stride > 0.f);
+    ////////////////////////////////
+    //
+    // Iterate through the target texture, striding through the
+    // subtextures and interpolating appropriately.
+    //
+    //
+
+    F32 sti, stj;
+    S32 st_offset;
+    sti = (tex_x_begin * st_x_stride) - st_width*(llfloor((tex_x_begin * st_x_stride)/st_width));
+    stj = (tex_y_begin * st_y_stride) - st_height*(llfloor((tex_y_begin * st_y_stride)/st_height));
+
+    st_offset = (llfloor(stj * st_width) + llfloor(sti)) * st_comps;
+    for (S32 j = tex_y_begin; j < tex_y_end; j++)
+    {
+        U32 offset = j * tex_stride + tex_x_begin * tex_comps;
+        sti = (tex_x_begin * st_x_stride) - st_width*((U32)(tex_x_begin * st_x_stride)/st_width);
+        for (S32 i = tex_x_begin; i < tex_x_end; i++)
+        {
+            S32 tex0, tex1;
+            F32 composition = getValueScaled(i*tex_x_ratiof, j*tex_y_ratiof);
+
+            tex0 = llfloor( composition );
+            tex0 = llclamp(tex0, 0, 3);
+            composition -= tex0;
+            tex1 = tex0 + 1;
+            tex1 = llclamp(tex1, 0, 3);
+
+            st_offset = (lltrunc(sti) + lltrunc(stj)*st_width) * st_comps;
+            for (U32 k = 0; k < tex_comps; k++)
+            {
+                // Linearly interpolate based on composition.
+                if (st_offset >= st_data_size[tex0] || st_offset >= st_data_size[tex1])
+                {
+                    // SJB: This shouldn't be happening, but does... Rounding error?
+                    //LL_WARNS() << "offset 0 [" << tex0 << "] =" << st_offset << " >= size=" << st_data_size[tex0] << LL_ENDL;
+                    //LL_WARNS() << "offset 1 [" << tex1 << "] =" << st_offset << " >= size=" << st_data_size[tex1] << LL_ENDL;
+                }
+                else
+                {
+                    F32 a = *(st_data[tex0] + st_offset);
+                    F32 b = *(st_data[tex1] + st_offset);
+                    rawp[ offset ] = (U8)lltrunc( a + composition * (b - a) );
+                }
+                offset++;
+                st_offset++;
+            }
+
+            sti += st_x_stride;
+            if (sti >= st_width)
+            {
+                sti -= st_width;
+            }
+        }
+
+        stj += st_y_stride;
+        if (stj >= st_height)
+        {
+            stj -= st_height;
+        }
+    }
+
+    if (!texturep->hasGLTexture())
+    {
+        texturep->createGLTexture(0, raw);
+    }
+    texturep->setSubImage(raw, tex_x_begin, tex_y_begin, tex_x_end - tex_x_begin, tex_y_end - tex_y_begin);
 
     // Un-boost detail textures (will get re-boosted if rendering in high detail)
     for (S32 i = 0; i < ASSET_COUNT; i++)
@@ -920,38 +920,38 @@ BOOL LLVLComposition::generateMinimapTileLand(const F32 x, const F32 y,
     {
         unboost_minimap_material(mDetailMaterials[i]);
     }
-	
-	return TRUE;
+
+    return TRUE;
 }
 
 F32 LLVLComposition::getStartHeight(S32 corner)
 {
-	return mStartHeight[corner];
+    return mStartHeight[corner];
 }
 
 void LLVLComposition::setDetailAssetID(S32 asset, const LLUUID& id)
 {
-	if (id.isNull())
-	{
+    if (id.isNull())
+    {
         return;
     }
     LLTerrainMaterials::setDetailAssetID(asset, id);
-	mRawImages[asset] = NULL;
-	mRawImagesBaseColor[asset] = NULL;
-	mRawImagesEmissive[asset] = NULL;
+    mRawImages[asset] = NULL;
+    mRawImagesBaseColor[asset] = NULL;
+    mRawImagesEmissive[asset] = NULL;
 }
 
 void LLVLComposition::setStartHeight(S32 corner, const F32 start_height)
 {
-	mStartHeight[corner] = start_height;
+    mStartHeight[corner] = start_height;
 }
 
 F32 LLVLComposition::getHeightRange(S32 corner)
 {
-	return mHeightRange[corner];
+    return mHeightRange[corner];
 }
 
 void LLVLComposition::setHeightRange(S32 corner, const F32 range)
 {
-	mHeightRange[corner] = range;
+    mHeightRange[corner] = range;
 }
diff --git a/indra/newview/llvlcomposition.h b/indra/newview/llvlcomposition.h
index 5db832e034c56db9f8eab26fdebaacb18ded59af..e0b08a3aca6bf1e2d1161bce6bda81705ae419c4 100644
--- a/indra/newview/llvlcomposition.h
+++ b/indra/newview/llvlcomposition.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvlcomposition.h
  * @brief Viewer-side representation of a composition layer...
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -40,13 +40,13 @@ class LLFetchedGLTFMaterial;
 class LLTerrainMaterials
 {
 public:
-	friend class LLDrawPoolTerrain;
+    friend class LLDrawPoolTerrain;
 
     LLTerrainMaterials();
     virtual ~LLTerrainMaterials();
 
-	// Heights map into textures (or materials) as 0-1 = first, 1-2 = second, etc.
-	// So we need to compress heights into this range.
+    // Heights map into textures (or materials) as 0-1 = first, 1-2 = second, etc.
+    // So we need to compress heights into this range.
     static const S32 ASSET_COUNT = 4;
 
     enum class Type
@@ -60,8 +60,8 @@ class LLTerrainMaterials
 
     void boost();
 
-	virtual LLUUID getDetailAssetID(S32 asset);
-	virtual void setDetailAssetID(S32 asset, const LLUUID& id);
+    virtual LLUUID getDetailAssetID(S32 asset);
+    virtual void setDetailAssetID(S32 asset, const LLUUID& id);
     Type getMaterialType();
     bool texturesReady(bool boost, bool strict);
     // strict = true -> all materials must be sufficiently loaded
@@ -74,8 +74,8 @@ class LLTerrainMaterials
     // strict = true -> all materials must be sufficiently loaded
     // strict = false -> at least one material must be loaded
     static bool materialReady(LLPointer<LLFetchedGLTFMaterial>& mat, bool& textures_set, bool boost, bool strict);
-	LLPointer<LLViewerFetchedTexture> mDetailTextures[ASSET_COUNT];
-	LLPointer<LLFetchedGLTFMaterial> mDetailMaterials[ASSET_COUNT];
+    LLPointer<LLViewerFetchedTexture> mDetailTextures[ASSET_COUNT];
+    LLPointer<LLFetchedGLTFMaterial> mDetailMaterials[ASSET_COUNT];
     bool mMaterialTexturesSet[ASSET_COUNT];
 };
 
@@ -85,63 +85,63 @@ extern LLTerrainMaterials gLocalTerrainMaterials;
 class LLVLComposition : public LLTerrainMaterials, public LLViewerLayer
 {
 public:
-	// Heights map into textures (or materials) as 0-1 = first, 1-2 = second, etc.
-	// So we need to compress heights into this range.
+    // Heights map into textures (or materials) as 0-1 = first, 1-2 = second, etc.
+    // So we need to compress heights into this range.
     static const S32 ASSET_COUNT = 4;
-	static const LLUUID (&getDefaultTextures())[ASSET_COUNT];
+    static const LLUUID (&getDefaultTextures())[ASSET_COUNT];
 
-	LLVLComposition(LLSurface *surfacep, const U32 width, const F32 scale);
-	/*virtual*/ ~LLVLComposition();
+    LLVLComposition(LLSurface *surfacep, const U32 width, const F32 scale);
+    /*virtual*/ ~LLVLComposition();
 
-	void setSurface(LLSurface *surfacep);
+    void setSurface(LLSurface *surfacep);
 
-	// Viewer side hack to generate composition values
-	BOOL generateHeights(const F32 x, const F32 y, const F32 width, const F32 height);
-	BOOL generateComposition();
-	// Generate texture from composition values.
-	BOOL generateMinimapTileLand(const F32 x, const F32 y, const F32 width, const F32 height);		
+    // Viewer side hack to generate composition values
+    BOOL generateHeights(const F32 x, const F32 y, const F32 width, const F32 height);
+    BOOL generateComposition();
+    // Generate texture from composition values.
+    BOOL generateMinimapTileLand(const F32 x, const F32 y, const F32 width, const F32 height);
 
-	// Use these as indeces ito the get/setters below that use 'corner'
-	enum ECorner
-	{
-		SOUTHWEST = 0,
-		SOUTHEAST = 1,
-		NORTHWEST = 2,
-		NORTHEAST = 3,
-		CORNER_COUNT = 4
-	};
+    // Use these as indeces ito the get/setters below that use 'corner'
+    enum ECorner
+    {
+        SOUTHWEST = 0,
+        SOUTHEAST = 1,
+        NORTHWEST = 2,
+        NORTHEAST = 3,
+        CORNER_COUNT = 4
+    };
 
-	void setDetailAssetID(S32 asset, const LLUUID& id) override;
-	F32 getStartHeight(S32 corner);
-	F32 getHeightRange(S32 corner);
+    void setDetailAssetID(S32 asset, const LLUUID& id) override;
+    F32 getStartHeight(S32 corner);
+    F32 getHeightRange(S32 corner);
 
-	void setStartHeight(S32 corner, F32 start_height);
-	void setHeightRange(S32 corner, F32 range);
+    void setStartHeight(S32 corner, F32 start_height);
+    void setHeightRange(S32 corner, F32 range);
 
-	friend class LLVOSurfacePatch;
-	friend class LLDrawPoolTerrain;
-	void setParamsReady()		{ mParamsReady = TRUE; }
-	BOOL getParamsReady() const	{ return mParamsReady; }
+    friend class LLVOSurfacePatch;
+    friend class LLDrawPoolTerrain;
+    void setParamsReady()       { mParamsReady = TRUE; }
+    BOOL getParamsReady() const { return mParamsReady; }
 
 protected:
     static bool textureReady(LLPointer<LLViewerFetchedTexture>& tex, bool boost = false);
     static bool materialReady(LLPointer<LLFetchedGLTFMaterial>& mat, bool& textures_set, bool boost = false);
 
-	BOOL mParamsReady = FALSE;
-	LLSurface *mSurfacep;
+    BOOL mParamsReady = FALSE;
+    LLSurface *mSurfacep;
 
     // Final minimap raw images
-	LLPointer<LLImageRaw> mRawImages[LLTerrainMaterials::ASSET_COUNT];
+    LLPointer<LLImageRaw> mRawImages[LLTerrainMaterials::ASSET_COUNT];
 
     // Only non-null during minimap tile generation
-	LLPointer<LLImageRaw> mRawImagesBaseColor[LLTerrainMaterials::ASSET_COUNT];
-	LLPointer<LLImageRaw> mRawImagesEmissive[LLTerrainMaterials::ASSET_COUNT];
+    LLPointer<LLImageRaw> mRawImagesBaseColor[LLTerrainMaterials::ASSET_COUNT];
+    LLPointer<LLImageRaw> mRawImagesEmissive[LLTerrainMaterials::ASSET_COUNT];
 
-	F32 mStartHeight[CORNER_COUNT];
-	F32 mHeightRange[CORNER_COUNT];
+    F32 mStartHeight[CORNER_COUNT];
+    F32 mHeightRange[CORNER_COUNT];
 
-	F32 mTexScaleX = 16.f;
-	F32 mTexScaleY = 16.f;
+    F32 mTexScaleX = 16.f;
+    F32 mTexScaleY = 16.f;
 };
 
 #endif //LL_LLVLCOMPOSITION_H
diff --git a/indra/newview/llvoavatar.cpp b/indra/newview/llvoavatar.cpp
index 3f6b84822d2a717f670f6da16acd1107faeab34f..3b98a07ed6cc6bc3d1d91d770a43d3159ea69770 100644
--- a/indra/newview/llvoavatar.cpp
+++ b/indra/newview/llvoavatar.cpp
@@ -5,21 +5,21 @@
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -51,7 +51,7 @@
 #include "llexperiencecache.h"
 #include "llphysicsmotion.h"
 #include "llviewercontrol.h"
-#include "llcallingcard.h"		// IDEVO for LLAvatarTracker
+#include "llcallingcard.h"      // IDEVO for LLAvatarTracker
 #include "lldrawpoolavatar.h"
 #include "lldriverparam.h"
 #include "llpolyskeletaldistortion.h"
@@ -63,7 +63,7 @@
 #include "llhudeffecttrail.h"
 #include "llhudmanager.h"
 #include "llhudnametag.h"
-#include "llhudtext.h"				// for mText/mDebugText
+#include "llhudtext.h"              // for mText/mDebugText
 #include "llimview.h"
 #include "llinitparam.h"
 #include "llkeyframefallmotion.h"
@@ -157,30 +157,30 @@ using namespace LLAvatarAppearanceDefines;
 // Global constants
 //-----------------------------------------------------------------------------
 const LLUUID ANIM_AGENT_BODY_NOISE = LLUUID("9aa8b0a6-0c6f-9518-c7c3-4f41f2c001ad"); //"body_noise"
-const LLUUID ANIM_AGENT_BREATHE_ROT	= LLUUID("4c5a103e-b830-2f1c-16bc-224aa0ad5bc8");  //"breathe_rot"
-const LLUUID ANIM_AGENT_EDITING	= LLUUID("2a8eba1d-a7f8-5596-d44a-b4977bf8c8bb");  //"editing"
-const LLUUID ANIM_AGENT_EYE	= LLUUID("5c780ea8-1cd1-c463-a128-48c023f6fbea");  //"eye"
+const LLUUID ANIM_AGENT_BREATHE_ROT = LLUUID("4c5a103e-b830-2f1c-16bc-224aa0ad5bc8");  //"breathe_rot"
+const LLUUID ANIM_AGENT_EDITING = LLUUID("2a8eba1d-a7f8-5596-d44a-b4977bf8c8bb");  //"editing"
+const LLUUID ANIM_AGENT_EYE = LLUUID("5c780ea8-1cd1-c463-a128-48c023f6fbea");  //"eye"
 const LLUUID ANIM_AGENT_FLY_ADJUST = LLUUID("db95561f-f1b0-9f9a-7224-b12f71af126e");  //"fly_adjust"
-const LLUUID ANIM_AGENT_HAND_MOTION	= LLUUID("ce986325-0ba7-6e6e-cc24-b17c4b795578");  //"hand_motion"
+const LLUUID ANIM_AGENT_HAND_MOTION = LLUUID("ce986325-0ba7-6e6e-cc24-b17c4b795578");  //"hand_motion"
 const LLUUID ANIM_AGENT_HEAD_ROT = LLUUID("e6e8d1dd-e643-fff7-b238-c6b4b056a68d");  //"head_rot"
 const LLUUID ANIM_AGENT_PELVIS_FIX = LLUUID("0c5dd2a2-514d-8893-d44d-05beffad208b");  //"pelvis_fix"
 const LLUUID ANIM_AGENT_TARGET = LLUUID("0e4896cb-fba4-926c-f355-8720189d5b55");  //"target"
-const LLUUID ANIM_AGENT_WALK_ADJUST	= LLUUID("829bc85b-02fc-ec41-be2e-74cc6dd7215d");  //"walk_adjust"
+const LLUUID ANIM_AGENT_WALK_ADJUST = LLUUID("829bc85b-02fc-ec41-be2e-74cc6dd7215d");  //"walk_adjust"
 const LLUUID ANIM_AGENT_PHYSICS_MOTION = LLUUID("7360e029-3cb8-ebc4-863e-212df440d987");  //"physics_motion"
 const LLUUID ANIM_BD_POSING_MOTION = LLUUID("fd29b117-9429-09c4-10cb-933d0b2ab653");  //"custom_motion"
 
 //-----------------------------------------------------------------------------
 // Constants
 //-----------------------------------------------------------------------------
-const F32 DELTA_TIME_MIN = 0.01f;	// we clamp measured delta_time to this
-const F32 DELTA_TIME_MAX = 0.2f;	// range to insure stability of computations.
+const F32 DELTA_TIME_MIN = 0.01f;   // we clamp measured delta_time to this
+const F32 DELTA_TIME_MAX = 0.2f;    // range to insure stability of computations.
 
-const F32 PELVIS_LAG_FLYING		= 0.22f;// pelvis follow half life while flying
-const F32 PELVIS_LAG_WALKING	= 0.4f;	// ...while walking
+const F32 PELVIS_LAG_FLYING     = 0.22f;// pelvis follow half life while flying
+const F32 PELVIS_LAG_WALKING    = 0.4f; // ...while walking
 const F32 PELVIS_LAG_MOUSELOOK = 0.15f;
 const F32 MOUSELOOK_PELVIS_FOLLOW_FACTOR = 0.5f;
-const F32 TORSO_NOISE_AMOUNT = 1.0f;	// Amount of deviation from up-axis, in degrees
-const F32 TORSO_NOISE_SPEED = 0.2f;	// Time scale factor on torso noise.
+const F32 TORSO_NOISE_AMOUNT = 1.0f;    // Amount of deviation from up-axis, in degrees
+const F32 TORSO_NOISE_SPEED = 0.2f; // Time scale factor on torso noise.
 
 const F32 BREATHE_ROT_MOTION_STRENGTH = 0.05f;
 
@@ -227,9 +227,9 @@ const S32 MIN_NONTUNED_AVS = 5;
 
 enum ERenderName
 {
-	RENDER_NAME_NEVER,
-	RENDER_NAME_ALWAYS,	
-	RENDER_NAME_FADE
+    RENDER_NAME_NEVER,
+    RENDER_NAME_ALWAYS,
+    RENDER_NAME_FADE
 };
 
 #define JELLYDOLLS_SHOULD_IMPOSTOR
@@ -240,12 +240,12 @@ enum ERenderName
 
 struct LLTextureMaskData
 {
-	LLTextureMaskData( const LLUUID& id ) :
-		mAvatarID(id), 
-		mLastDiscardLevel(S32_MAX) 
-	{}
-	LLUUID				mAvatarID;
-	S32					mLastDiscardLevel;
+    LLTextureMaskData( const LLUUID& id ) :
+        mAvatarID(id),
+        mLastDiscardLevel(S32_MAX)
+    {}
+    LLUUID              mAvatarID;
+    S32                 mLastDiscardLevel;
 };
 
 /*********************************************************************************
@@ -257,22 +257,22 @@ struct LLTextureMaskData
 
 struct LLAppearanceMessageContents: public LLRefCount
 {
-	LLAppearanceMessageContents():
-		mAppearanceVersion(-1),
-		mParamAppearanceVersion(-1),
-		mCOFVersion(LLViewerInventoryCategory::VERSION_UNKNOWN)
-	{
-	}
-	LLTEContents mTEContents;
-	S32 mAppearanceVersion;
-	S32 mParamAppearanceVersion;
-	S32 mCOFVersion;
-	// For future use:
-	//U32 appearance_flags = 0;
-	std::vector<F32> mParamWeights;
-	std::vector<LLVisualParam*> mParams;
-	LLVector3 mHoverOffset;
-	bool mHoverOffsetWasSet;
+    LLAppearanceMessageContents():
+        mAppearanceVersion(-1),
+        mParamAppearanceVersion(-1),
+        mCOFVersion(LLViewerInventoryCategory::VERSION_UNKNOWN)
+    {
+    }
+    LLTEContents mTEContents;
+    S32 mAppearanceVersion;
+    S32 mParamAppearanceVersion;
+    S32 mCOFVersion;
+    // For future use:
+    //U32 appearance_flags = 0;
+    std::vector<F32> mParamWeights;
+    std::vector<LLVisualParam*> mParams;
+    LLVector3 mHoverOffset;
+    bool mHoverOffsetWasSet;
 };
 
 
@@ -280,317 +280,317 @@ struct LLAppearanceMessageContents: public LLRefCount
 // class LLBodyNoiseMotion
 //-----------------------------------------------------------------------------
 class LLBodyNoiseMotion final :
-	public LLMotion
+    public LLMotion
 {
 public:
-	// Constructor
-	LLBodyNoiseMotion(const LLUUID &id)
-		: LLMotion(id)
-	{
-		mName = "body_noise";
-		mTorsoState = new LLJointState;
-	}
+    // Constructor
+    LLBodyNoiseMotion(const LLUUID &id)
+        : LLMotion(id)
+    {
+        mName = "body_noise";
+        mTorsoState = new LLJointState;
+    }
 
-	// Destructor
-	virtual ~LLBodyNoiseMotion() = default;
+    // Destructor
+    virtual ~LLBodyNoiseMotion() = default;
 
 public:
-	//-------------------------------------------------------------------------
-	// functions to support MotionController and MotionRegistry
-	//-------------------------------------------------------------------------
-	// static constructor
-	// all subclasses must implement such a function and register it
-	static LLMotion *create(const LLUUID &id) { return new LLBodyNoiseMotion(id); }
+    //-------------------------------------------------------------------------
+    // functions to support MotionController and MotionRegistry
+    //-------------------------------------------------------------------------
+    // static constructor
+    // all subclasses must implement such a function and register it
+    static LLMotion *create(const LLUUID &id) { return new LLBodyNoiseMotion(id); }
 
 public:
-	//-------------------------------------------------------------------------
-	// animation callbacks to be implemented by subclasses
-	//-------------------------------------------------------------------------
+    //-------------------------------------------------------------------------
+    // animation callbacks to be implemented by subclasses
+    //-------------------------------------------------------------------------
 
-	// motions must specify whether or not they loop
-	virtual BOOL getLoop() { return TRUE; }
+    // motions must specify whether or not they loop
+    virtual BOOL getLoop() { return TRUE; }
 
-	// motions must report their total duration
-	virtual F32 getDuration() { return 0.0; }
+    // motions must report their total duration
+    virtual F32 getDuration() { return 0.0; }
 
-	// motions must report their "ease in" duration
-	virtual F32 getEaseInDuration() { return 0.0; }
+    // motions must report their "ease in" duration
+    virtual F32 getEaseInDuration() { return 0.0; }
 
-	// motions must report their "ease out" duration.
-	virtual F32 getEaseOutDuration() { return 0.0; }
+    // motions must report their "ease out" duration.
+    virtual F32 getEaseOutDuration() { return 0.0; }
 
-	// motions must report their priority
-	virtual LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; }
+    // motions must report their priority
+    virtual LLJoint::JointPriority getPriority() { return LLJoint::HIGH_PRIORITY; }
 
-	virtual LLMotionBlendType getBlendType() { return ADDITIVE_BLEND; }
+    virtual LLMotionBlendType getBlendType() { return ADDITIVE_BLEND; }
 
-	// called to determine when a motion should be activated/deactivated based on avatar pixel coverage
-	virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_BODY_NOISE; }
+    // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
+    virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_BODY_NOISE; }
 
-	// run-time (post constructor) initialization,
-	// called after parameters have been set
-	// must return true to indicate success and be available for activation
-	virtual LLMotionInitStatus onInitialize(LLCharacter *character)
-	{
-		if( !mTorsoState->setJoint( character->getJoint("mTorso") ))
-		{
-			return STATUS_FAILURE;
-		}
+    // run-time (post constructor) initialization,
+    // called after parameters have been set
+    // must return true to indicate success and be available for activation
+    virtual LLMotionInitStatus onInitialize(LLCharacter *character)
+    {
+        if( !mTorsoState->setJoint( character->getJoint("mTorso") ))
+        {
+            return STATUS_FAILURE;
+        }
 
-		mTorsoState->setUsage(LLJointState::ROT);
+        mTorsoState->setUsage(LLJointState::ROT);
 
-		addJointState( mTorsoState );
-		return STATUS_SUCCESS;
-	}
+        addJointState( mTorsoState );
+        return STATUS_SUCCESS;
+    }
 
-	// called when a motion is activated
-	// must return TRUE to indicate success, or else
-	// it will be deactivated
-	virtual BOOL onActivate() { return TRUE; }
+    // called when a motion is activated
+    // must return TRUE to indicate success, or else
+    // it will be deactivated
+    virtual BOOL onActivate() { return TRUE; }
 
-	// called per time step
-	// must return TRUE while it is active, and
-	// must return FALSE when the motion is completed.
-	virtual BOOL onUpdate(F32 time, U8* joint_mask)
-	{
+    // called per time step
+    // must return TRUE while it is active, and
+    // must return FALSE when the motion is completed.
+    virtual BOOL onUpdate(F32 time, U8* joint_mask)
+    {
         LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
-		F32 nx[2];
-		nx[0]=time*TORSO_NOISE_SPEED;
-		nx[1]=0.0f;
-		F32 ny[2];
-		ny[0]=0.0f;
-		ny[1]=time*TORSO_NOISE_SPEED;
-		F32 noiseX = noise2(nx);
-		F32 noiseY = noise2(ny);
-
-		F32 rx = TORSO_NOISE_AMOUNT * DEG_TO_RAD * noiseX / 0.42f;
-		F32 ry = TORSO_NOISE_AMOUNT * DEG_TO_RAD * noiseY / 0.42f;
-		LLQuaternion tQn;
-		tQn.setQuat( rx, ry, 0.0f );
-		mTorsoState->setRotation( tQn );
-
-		return TRUE;
-	}
-
-	// called when a motion is deactivated
-	virtual void onDeactivate() {}
+        F32 nx[2];
+        nx[0]=time*TORSO_NOISE_SPEED;
+        nx[1]=0.0f;
+        F32 ny[2];
+        ny[0]=0.0f;
+        ny[1]=time*TORSO_NOISE_SPEED;
+        F32 noiseX = noise2(nx);
+        F32 noiseY = noise2(ny);
+
+        F32 rx = TORSO_NOISE_AMOUNT * DEG_TO_RAD * noiseX / 0.42f;
+        F32 ry = TORSO_NOISE_AMOUNT * DEG_TO_RAD * noiseY / 0.42f;
+        LLQuaternion tQn;
+        tQn.setQuat( rx, ry, 0.0f );
+        mTorsoState->setRotation( tQn );
+
+        return TRUE;
+    }
+
+    // called when a motion is deactivated
+    virtual void onDeactivate() {}
 
 private:
-	//-------------------------------------------------------------------------
-	// joint states to be animated
-	//-------------------------------------------------------------------------
-	LLPointer<LLJointState> mTorsoState;
+    //-------------------------------------------------------------------------
+    // joint states to be animated
+    //-------------------------------------------------------------------------
+    LLPointer<LLJointState> mTorsoState;
 };
 
 //-----------------------------------------------------------------------------
 // class LLBreatheMotionRot
 //-----------------------------------------------------------------------------
 class LLBreatheMotionRot final :
-	public LLMotion
+    public LLMotion
 {
 public:
-	// Constructor
-	LLBreatheMotionRot(const LLUUID &id) :
-		LLMotion(id),
-		mBreatheRate(1.f),
-		mCharacter(NULL)
-	{
-		mName = "breathe_rot";
-		mChestState = new LLJointState;
-	}
-
-	// Destructor
-	virtual ~LLBreatheMotionRot() {}
+    // Constructor
+    LLBreatheMotionRot(const LLUUID &id) :
+        LLMotion(id),
+        mBreatheRate(1.f),
+        mCharacter(NULL)
+    {
+        mName = "breathe_rot";
+        mChestState = new LLJointState;
+    }
+
+    // Destructor
+    virtual ~LLBreatheMotionRot() {}
 
 public:
-	//-------------------------------------------------------------------------
-	// functions to support MotionController and MotionRegistry
-	//-------------------------------------------------------------------------
-	// static constructor
-	// all subclasses must implement such a function and register it
-	static LLMotion *create(const LLUUID &id) { return new LLBreatheMotionRot(id); }
+    //-------------------------------------------------------------------------
+    // functions to support MotionController and MotionRegistry
+    //-------------------------------------------------------------------------
+    // static constructor
+    // all subclasses must implement such a function and register it
+    static LLMotion *create(const LLUUID &id) { return new LLBreatheMotionRot(id); }
 
 public:
-	//-------------------------------------------------------------------------
-	// animation callbacks to be implemented by subclasses
-	//-------------------------------------------------------------------------
-
-	// motions must specify whether or not they loop
-	virtual BOOL getLoop() { return TRUE; }
-
-	// motions must report their total duration
-	virtual F32 getDuration() { return 0.0; }
-
-	// motions must report their "ease in" duration
-	virtual F32 getEaseInDuration() { return 0.0; }
-
-	// motions must report their "ease out" duration.
-	virtual F32 getEaseOutDuration() { return 0.0; }
-
-	// motions must report their priority
-	virtual LLJoint::JointPriority getPriority() { return LLJoint::MEDIUM_PRIORITY; }
-
-	virtual LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
-
-	// called to determine when a motion should be activated/deactivated based on avatar pixel coverage
-	virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_BREATHE; }
-
-	// run-time (post constructor) initialization,
-	// called after parameters have been set
-	// must return true to indicate success and be available for activation
-	virtual LLMotionInitStatus onInitialize(LLCharacter *character)
-	{		
-		mCharacter = character;
-		BOOL success = true;
-
-		if ( !mChestState->setJoint( character->getJoint( "mChest" ) ) )
-		{
-			success = false;
-		}
-
-		if ( success )
-		{
-			mChestState->setUsage(LLJointState::ROT);
-			addJointState( mChestState );
-		}
-
-		if ( success )
-		{
-			return STATUS_SUCCESS;
-		}
-		else
-		{
-			return STATUS_FAILURE;
-		}
-	}
-
-	// called when a motion is activated
-	// must return TRUE to indicate success, or else
-	// it will be deactivated
-	virtual BOOL onActivate() { return TRUE; }
-
-	// called per time step
-	// must return TRUE while it is active, and
-	// must return FALSE when the motion is completed.
-	virtual BOOL onUpdate(F32 time, U8* joint_mask)
-	{
+    //-------------------------------------------------------------------------
+    // animation callbacks to be implemented by subclasses
+    //-------------------------------------------------------------------------
+
+    // motions must specify whether or not they loop
+    virtual BOOL getLoop() { return TRUE; }
+
+    // motions must report their total duration
+    virtual F32 getDuration() { return 0.0; }
+
+    // motions must report their "ease in" duration
+    virtual F32 getEaseInDuration() { return 0.0; }
+
+    // motions must report their "ease out" duration.
+    virtual F32 getEaseOutDuration() { return 0.0; }
+
+    // motions must report their priority
+    virtual LLJoint::JointPriority getPriority() { return LLJoint::MEDIUM_PRIORITY; }
+
+    virtual LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
+
+    // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
+    virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_BREATHE; }
+
+    // run-time (post constructor) initialization,
+    // called after parameters have been set
+    // must return true to indicate success and be available for activation
+    virtual LLMotionInitStatus onInitialize(LLCharacter *character)
+    {
+        mCharacter = character;
+        BOOL success = true;
+
+        if ( !mChestState->setJoint( character->getJoint( "mChest" ) ) )
+        {
+            success = false;
+        }
+
+        if ( success )
+        {
+            mChestState->setUsage(LLJointState::ROT);
+            addJointState( mChestState );
+        }
+
+        if ( success )
+        {
+            return STATUS_SUCCESS;
+        }
+        else
+        {
+            return STATUS_FAILURE;
+        }
+    }
+
+    // called when a motion is activated
+    // must return TRUE to indicate success, or else
+    // it will be deactivated
+    virtual BOOL onActivate() { return TRUE; }
+
+    // called per time step
+    // must return TRUE while it is active, and
+    // must return FALSE when the motion is completed.
+    virtual BOOL onUpdate(F32 time, U8* joint_mask)
+    {
         LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
-		mBreatheRate = 1.f;
+        mBreatheRate = 1.f;
 
-		F32 breathe_amt = (sinf(mBreatheRate * time) * BREATHE_ROT_MOTION_STRENGTH);
+        F32 breathe_amt = (sinf(mBreatheRate * time) * BREATHE_ROT_MOTION_STRENGTH);
 
-		mChestState->setRotation(LLQuaternion(breathe_amt, LLVector3(0.f, 1.f, 0.f)));
+        mChestState->setRotation(LLQuaternion(breathe_amt, LLVector3(0.f, 1.f, 0.f)));
 
-		return TRUE;
-	}
+        return TRUE;
+    }
 
-	// called when a motion is deactivated
-	virtual void onDeactivate() {}
+    // called when a motion is deactivated
+    virtual void onDeactivate() {}
 
 private:
-	//-------------------------------------------------------------------------
-	// joint states to be animated
-	//-------------------------------------------------------------------------
-	LLPointer<LLJointState> mChestState;
-	F32					mBreatheRate;
-	LLCharacter*		mCharacter;
+    //-------------------------------------------------------------------------
+    // joint states to be animated
+    //-------------------------------------------------------------------------
+    LLPointer<LLJointState> mChestState;
+    F32                 mBreatheRate;
+    LLCharacter*        mCharacter;
 };
 
 //-----------------------------------------------------------------------------
 // class LLPelvisFixMotion
 //-----------------------------------------------------------------------------
 class LLPelvisFixMotion final :
-	public LLMotion
+    public LLMotion
 {
 public:
-	// Constructor
-	LLPelvisFixMotion(const LLUUID &id)
-		: LLMotion(id), mCharacter(NULL)
-	{
-		mName = "pelvis_fix";
+    // Constructor
+    LLPelvisFixMotion(const LLUUID &id)
+        : LLMotion(id), mCharacter(NULL)
+    {
+        mName = "pelvis_fix";
 
-		mPelvisState = new LLJointState;
-	}
+        mPelvisState = new LLJointState;
+    }
 
-	// Destructor
-	virtual ~LLPelvisFixMotion() = default;
+    // Destructor
+    virtual ~LLPelvisFixMotion() = default;
 
 public:
-	//-------------------------------------------------------------------------
-	// functions to support MotionController and MotionRegistry
-	//-------------------------------------------------------------------------
-	// static constructor
-	// all subclasses must implement such a function and register it
-	static LLMotion *create(const LLUUID& id) { return new LLPelvisFixMotion(id); }
+    //-------------------------------------------------------------------------
+    // functions to support MotionController and MotionRegistry
+    //-------------------------------------------------------------------------
+    // static constructor
+    // all subclasses must implement such a function and register it
+    static LLMotion *create(const LLUUID& id) { return new LLPelvisFixMotion(id); }
 
 public:
-	//-------------------------------------------------------------------------
-	// animation callbacks to be implemented by subclasses
-	//-------------------------------------------------------------------------
+    //-------------------------------------------------------------------------
+    // animation callbacks to be implemented by subclasses
+    //-------------------------------------------------------------------------
 
-	// motions must specify whether or not they loop
-	virtual BOOL getLoop() { return TRUE; }
+    // motions must specify whether or not they loop
+    virtual BOOL getLoop() { return TRUE; }
 
-	// motions must report their total duration
-	virtual F32 getDuration() { return 0.0; }
+    // motions must report their total duration
+    virtual F32 getDuration() { return 0.0; }
 
-	// motions must report their "ease in" duration
-	virtual F32 getEaseInDuration() { return 0.5f; }
+    // motions must report their "ease in" duration
+    virtual F32 getEaseInDuration() { return 0.5f; }
 
-	// motions must report their "ease out" duration.
-	virtual F32 getEaseOutDuration() { return 0.5f; }
+    // motions must report their "ease out" duration.
+    virtual F32 getEaseOutDuration() { return 0.5f; }
 
-	// motions must report their priority
-	virtual LLJoint::JointPriority getPriority() { return LLJoint::LOW_PRIORITY; }
+    // motions must report their priority
+    virtual LLJoint::JointPriority getPriority() { return LLJoint::LOW_PRIORITY; }
 
-	virtual LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
+    virtual LLMotionBlendType getBlendType() { return NORMAL_BLEND; }
 
-	// called to determine when a motion should be activated/deactivated based on avatar pixel coverage
-	virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_PELVIS_FIX; }
+    // called to determine when a motion should be activated/deactivated based on avatar pixel coverage
+    virtual F32 getMinPixelArea() { return MIN_REQUIRED_PIXEL_AREA_PELVIS_FIX; }
 
-	// run-time (post constructor) initialization,
-	// called after parameters have been set
-	// must return true to indicate success and be available for activation
-	virtual LLMotionInitStatus onInitialize(LLCharacter *character)
-	{
-		mCharacter = character;
+    // run-time (post constructor) initialization,
+    // called after parameters have been set
+    // must return true to indicate success and be available for activation
+    virtual LLMotionInitStatus onInitialize(LLCharacter *character)
+    {
+        mCharacter = character;
 
-		if (!mPelvisState->setJoint( character->getJoint("mPelvis")))
-		{
-			return STATUS_FAILURE;
-		}
+        if (!mPelvisState->setJoint( character->getJoint("mPelvis")))
+        {
+            return STATUS_FAILURE;
+        }
 
-		mPelvisState->setUsage(LLJointState::POS);
+        mPelvisState->setUsage(LLJointState::POS);
 
-		addJointState( mPelvisState );
-		return STATUS_SUCCESS;
-	}
+        addJointState( mPelvisState );
+        return STATUS_SUCCESS;
+    }
 
-	// called when a motion is activated
-	// must return TRUE to indicate success, or else
-	// it will be deactivated
-	virtual BOOL onActivate() { return TRUE; }
+    // called when a motion is activated
+    // must return TRUE to indicate success, or else
+    // it will be deactivated
+    virtual BOOL onActivate() { return TRUE; }
 
-	// called per time step
-	// must return TRUE while it is active, and
-	// must return FALSE when the motion is completed.
-	virtual BOOL onUpdate(F32 time, U8* joint_mask)
-	{
+    // called per time step
+    // must return TRUE while it is active, and
+    // must return FALSE when the motion is completed.
+    virtual BOOL onUpdate(F32 time, U8* joint_mask)
+    {
         LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
-		mPelvisState->setPosition(LLVector3::zero);
+        mPelvisState->setPosition(LLVector3::zero);
 
-		return TRUE;
-	}
+        return TRUE;
+    }
 
-	// called when a motion is deactivated
-	virtual void onDeactivate() {}
+    // called when a motion is deactivated
+    virtual void onDeactivate() {}
 
 private:
-	//-------------------------------------------------------------------------
-	// joint states to be animated
-	//-------------------------------------------------------------------------
-	LLPointer<LLJointState> mPelvisState;
-	LLCharacter*		mCharacter;
+    //-------------------------------------------------------------------------
+    // joint states to be animated
+    //-------------------------------------------------------------------------
+    LLPointer<LLJointState> mPelvisState;
+    LLCharacter*        mCharacter;
 };
 
 /**
@@ -606,19 +606,19 @@ class LLPelvisFixMotion final :
 U32 LLVOAvatar::sMaxNonImpostors = 12; // Set from RenderAvatarMaxNonImpostors
 bool LLVOAvatar::sLimitNonImpostors = false; // True unless RenderAvatarMaxNonImpostors is 0 (unlimited)
 F32 LLVOAvatar::sRenderDistance = 256.f;
-S32	LLVOAvatar::sNumVisibleAvatars = 0;
-S32	LLVOAvatar::sNumLODChangesThisFrame = 0;
+S32 LLVOAvatar::sNumVisibleAvatars = 0;
+S32 LLVOAvatar::sNumLODChangesThisFrame = 0;
 
 const LLUUID LLVOAvatar::sStepSoundOnLand("e8af4a28-aa83-4310-a7c4-c047e15ea0df");
 const LLUUID LLVOAvatar::sStepSounds[LL_MCODE_END] =
 {
-	SND_STONE_RUBBER,
-	SND_METAL_RUBBER,
-	SND_GLASS_RUBBER,
-	SND_WOOD_RUBBER,
-	SND_FLESH_RUBBER,
-	SND_RUBBER_PLASTIC,
-	SND_RUBBER_RUBBER
+    SND_STONE_RUBBER,
+    SND_METAL_RUBBER,
+    SND_GLASS_RUBBER,
+    SND_WOOD_RUBBER,
+    SND_FLESH_RUBBER,
+    SND_RUBBER_PLASTIC,
+    SND_RUBBER_RUBBER
 };
 
 S32 LLVOAvatar::sRenderName = RENDER_NAME_ALWAYS;
@@ -646,152 +646,152 @@ static F32 calc_bouncy_animation(F32 x);
 
 void revoke_permissions_on_object(const LLUUID &object_id)
 {
-	U32 permissions = SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_TRIGGER_ANIMATION].permbit | SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS].permbit;
-	gAgent.sendRevokePermissions(object_id, permissions);
+    U32 permissions = SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_TRIGGER_ANIMATION].permbit | SCRIPT_PERMISSIONS[SCRIPT_PERMISSION_OVERRIDE_ANIMATIONS].permbit;
+    gAgent.sendRevokePermissions(object_id, permissions);
 }
 
 //-----------------------------------------------------------------------------
 // LLVOAvatar()
 //-----------------------------------------------------------------------------
 LLVOAvatar::LLVOAvatar(const LLUUID& id,
-					   const LLPCode pcode,
-					   LLViewerRegion* regionp) :
-	LLAvatarAppearance(&gAgentWearables),
-	LLViewerObject(id, pcode, regionp),
-	mSpecialRenderMode(0),
-	mAttachmentSurfaceArea(0.f),
-	mAttachmentVisibleTriangleCount(0),
-	mAttachmentEstTriangleCount(0.f),
-	mReportedVisualComplexity(VISUAL_COMPLEXITY_UNKNOWN),
-	mTurning(FALSE),
-	mLastSkeletonSerialNum( 0 ),
-	mIsSitting(FALSE),
-	mTimeVisible(),
-	mTyping(FALSE),
-	mTypingLast(false),
-	mMeshValid(FALSE),
-	mVisible(FALSE),
-	mLastImpostorUpdateFrameTime(0.f),
-	mLastImpostorUpdateReason(0),
-	mWindFreq(0.f),
-	mRipplePhase( 0.f ),
-	mBelowWater(FALSE),
-	mLastAppearanceBlendTime(0.f),
-	mAppearanceAnimating(FALSE),
+                       const LLPCode pcode,
+                       LLViewerRegion* regionp) :
+    LLAvatarAppearance(&gAgentWearables),
+    LLViewerObject(id, pcode, regionp),
+    mSpecialRenderMode(0),
+    mAttachmentSurfaceArea(0.f),
+    mAttachmentVisibleTriangleCount(0),
+    mAttachmentEstTriangleCount(0.f),
+    mReportedVisualComplexity(VISUAL_COMPLEXITY_UNKNOWN),
+    mTurning(FALSE),
+    mLastSkeletonSerialNum( 0 ),
+    mIsSitting(FALSE),
+    mTimeVisible(),
+    mTyping(FALSE),
+    mTypingLast(false),
+    mMeshValid(FALSE),
+    mVisible(FALSE),
+    mLastImpostorUpdateFrameTime(0.f),
+    mLastImpostorUpdateReason(0),
+    mWindFreq(0.f),
+    mRipplePhase( 0.f ),
+    mBelowWater(FALSE),
+    mLastAppearanceBlendTime(0.f),
+    mAppearanceAnimating(FALSE),
     mNameIsSet(false),
-	mTitle(),
-	mNameAway(false),
-	mNameDoNotDisturb(false),
-	mNameMute(false),
-	mNameAppearance(false),
-	mNameFriend(false),
-	mNameAlpha(0.f),
-	mRenderGroupTitles(sRenderGroupTitles),
-	mNameCloud(false),
-	mFirstTEMessageReceived( FALSE ),
-	mFirstAppearanceMessageReceived( FALSE ),
-	mCulled( FALSE ),
-	mVisibilityRank(0),
-	mNeedsSkin(FALSE),
-	mLastSkinTime(0.f),
-	mUpdatePeriod(1),
-	mOverallAppearance(AOA_INVISIBLE),
-	mVisualComplexityStale(true),
-	mVisuallyMuteSetting(AV_RENDER_NORMALLY),
-	mMutedAVColor(LLColor4::white /* used for "uninitialize" */),
-	mFirstFullyVisible(TRUE),
-	mFirstUseDelaySeconds(FIRST_APPEARANCE_CLOUD_MIN_DELAY),
-	mFullyLoaded(FALSE),
-	mPreviousFullyLoaded(FALSE),
-	mFullyLoadedInitialized(FALSE),
-	mVisualComplexity(VISUAL_COMPLEXITY_UNKNOWN),
-	mLoadedCallbacksPaused(FALSE),
-	mLoadedCallbackTextures(0),
-	mLastRezzedStatus(-1),
-	mIsEditingAppearance(FALSE),
-	mUseLocalAppearance(FALSE),
-	mLastUpdateRequestCOFVersion(-1),
-	mLastUpdateReceivedCOFVersion(-1),
-	mCachedMuteListUpdateTime(0),
-	mCachedInMuteList(false),
-	mCachedBuddyListUpdateTime(0),
-	mCachedInBuddyList(false),
+    mTitle(),
+    mNameAway(false),
+    mNameDoNotDisturb(false),
+    mNameMute(false),
+    mNameAppearance(false),
+    mNameFriend(false),
+    mNameAlpha(0.f),
+    mRenderGroupTitles(sRenderGroupTitles),
+    mNameCloud(false),
+    mFirstTEMessageReceived( FALSE ),
+    mFirstAppearanceMessageReceived( FALSE ),
+    mCulled( FALSE ),
+    mVisibilityRank(0),
+    mNeedsSkin(FALSE),
+    mLastSkinTime(0.f),
+    mUpdatePeriod(1),
+    mOverallAppearance(AOA_INVISIBLE),
+    mVisualComplexityStale(true),
+    mVisuallyMuteSetting(AV_RENDER_NORMALLY),
+    mMutedAVColor(LLColor4::white /* used for "uninitialize" */),
+    mFirstFullyVisible(TRUE),
+    mFirstUseDelaySeconds(FIRST_APPEARANCE_CLOUD_MIN_DELAY),
+    mFullyLoaded(FALSE),
+    mPreviousFullyLoaded(FALSE),
+    mFullyLoadedInitialized(FALSE),
+    mVisualComplexity(VISUAL_COMPLEXITY_UNKNOWN),
+    mLoadedCallbacksPaused(FALSE),
+    mLoadedCallbackTextures(0),
+    mLastRezzedStatus(-1),
+    mIsEditingAppearance(FALSE),
+    mUseLocalAppearance(FALSE),
+    mLastUpdateRequestCOFVersion(-1),
+    mLastUpdateReceivedCOFVersion(-1),
+    mCachedMuteListUpdateTime(0),
+    mCachedInMuteList(false),
+    mCachedBuddyListUpdateTime(0),
+    mCachedInBuddyList(false),
     mIsControlAvatar(false),
     mIsUIAvatar(false),
     mEnableDefaultMotions(true),
     //BD - Custom Posing
-	mIsPosing(false),
-	mExpiryTime(0.0f),
-	mCurrentAction(0)
+    mIsPosing(false),
+    mExpiryTime(0.0f),
+    mCurrentAction(0)
 {
-	LL_DEBUGS("AvatarRender") << "LLVOAvatar Constructor (0x" << this << ") id:" << mID << LL_ENDL;
+    LL_DEBUGS("AvatarRender") << "LLVOAvatar Constructor (0x" << this << ") id:" << mID << LL_ENDL;
 
-	//VTResume();  // VTune
-	setHoverOffset(LLVector3(0.0, 0.0, 0.0));
+    //VTResume();  // VTune
+    setHoverOffset(LLVector3(0.0, 0.0, 0.0));
 
-	// mVoiceVisualizer is created by the hud effects manager and uses the HUD Effects pipeline
-	const BOOL needsSendToSim = false; // currently, this HUD effect doesn't need to pack and unpack data to do its job
-	mVoiceVisualizer = ( LLVoiceVisualizer *)LLHUDManager::getInstance()->createViewerEffect( LLHUDObject::LL_HUD_EFFECT_VOICE_VISUALIZER, needsSendToSim );
+    // mVoiceVisualizer is created by the hud effects manager and uses the HUD Effects pipeline
+    const BOOL needsSendToSim = false; // currently, this HUD effect doesn't need to pack and unpack data to do its job
+    mVoiceVisualizer = ( LLVoiceVisualizer *)LLHUDManager::getInstance()->createViewerEffect( LLHUDObject::LL_HUD_EFFECT_VOICE_VISUALIZER, needsSendToSim );
 
-	LL_DEBUGS("Avatar","Message") << "LLVOAvatar Constructor (0x" << this << ") id:" << mID << LL_ENDL;
-	mPelvisp = NULL;
+    LL_DEBUGS("Avatar","Message") << "LLVOAvatar Constructor (0x" << this << ") id:" << mID << LL_ENDL;
+    mPelvisp = NULL;
 
-	mDirtyMesh = 2;	// Dirty geometry, need to regenerate.
-	mMeshTexturesDirty = FALSE;
-	mHeadp = NULL;
+    mDirtyMesh = 2; // Dirty geometry, need to regenerate.
+    mMeshTexturesDirty = FALSE;
+    mHeadp = NULL;
 
 
-	// set up animation variables
-	mSpeed = 0.f;
-	setAnimationData("Speed", &mSpeed);
+    // set up animation variables
+    mSpeed = 0.f;
+    setAnimationData("Speed", &mSpeed);
 
-	mNeedsImpostorUpdate = TRUE;
-	mLastImpostorUpdateReason = 0;
-	mNeedsAnimUpdate = TRUE;
+    mNeedsImpostorUpdate = TRUE;
+    mLastImpostorUpdateReason = 0;
+    mNeedsAnimUpdate = TRUE;
 
-	mNeedsExtentUpdate = true;
+    mNeedsExtentUpdate = true;
 
-	mImpostorDistance = 0;
-	mImpostorPixelArea = 0;
+    mImpostorDistance = 0;
+    mImpostorPixelArea = 0;
 
-	setNumTEs(TEX_NUM_INDICES);
+    setNumTEs(TEX_NUM_INDICES);
 
-	mbCanSelect = TRUE;
+    mbCanSelect = TRUE;
 
-	mSignaledAnimations.clear();
-	mPlayingAnimations.clear();
+    mSignaledAnimations.clear();
+    mPlayingAnimations.clear();
 
-	mWasOnGroundLeft = FALSE;
-	mWasOnGroundRight = FALSE;
+    mWasOnGroundLeft = FALSE;
+    mWasOnGroundRight = FALSE;
 
-	mTimeLast = 0.0f;
-	mSpeedAccum = 0.0f;
+    mTimeLast = 0.0f;
+    mSpeedAccum = 0.0f;
 
-	mRippleTimeLast = 0.f;
+    mRippleTimeLast = 0.f;
 
-	mInAir = FALSE;
+    mInAir = FALSE;
 
-	mStepOnLand = TRUE;
-	mStepMaterial = 0;
+    mStepOnLand = TRUE;
+    mStepMaterial = 0;
 
-	mLipSyncActive = false;
-	mOohMorph      = NULL;
-	mAahMorph      = NULL;
+    mLipSyncActive = false;
+    mOohMorph      = NULL;
+    mAahMorph      = NULL;
 
-	mCurrentGesticulationLevel = 0;
+    mCurrentGesticulationLevel = 0;
 
     mFirstAppearanceMessageTimer.reset();
-	mRuthTimer.reset();
-	mRuthDebugTimer.reset();
-	mDebugExistenceTimer.reset();
-	mLastAppearanceMessageTimer.reset();
+    mRuthTimer.reset();
+    mRuthDebugTimer.reset();
+    mDebugExistenceTimer.reset();
+    mLastAppearanceMessageTimer.reset();
 
-	if(LLSceneMonitor::getInstance()->isEnabled())
-	{
-	    LLSceneMonitor::getInstance()->freezeAvatar((LLCharacter*)this);
-	}
+    if(LLSceneMonitor::getInstance()->isEnabled())
+    {
+        LLSceneMonitor::getInstance()->freezeAvatar((LLCharacter*)this);
+    }
 
-	mVisuallyMuteSetting = LLVOAvatar::VisualMuteSettings(LLRenderMuteList::getInstance()->getSavedVisualMuteSetting(getID()));
+    mVisuallyMuteSetting = LLVOAvatar::VisualMuteSettings(LLRenderMuteList::getInstance()->getSavedVisualMuteSetting(getID()));
 }
 
 std::string LLVOAvatar::avString() const
@@ -802,8 +802,8 @@ std::string LLVOAvatar::avString() const
     }
     else
     {
-		std::string viz_string = LLVOAvatar::rezStatusToString(getRezzedStatus());
-		return " Avatar '" + getFullname() + "' " + viz_string + " ";
+        std::string viz_string = LLVOAvatar::rezStatusToString(getRezzedStatus());
+        return " Avatar '" + getFullname() + "' " + viz_string + " ";
     }
 }
 
@@ -816,22 +816,22 @@ void LLVOAvatar::debugAvatarRezTime(std::string notification_name, std::string c
         return;
     }
 
-	LL_INFOS("Avatar") << "REZTIME: [ " << (U32)mDebugExistenceTimer.getElapsedTimeF32()
-					   << "sec ]"
-					   << avString() 
-					   << "RuthTimer " << (U32)mRuthDebugTimer.getElapsedTimeF32()
-					   << " Notification " << notification_name
-					   << " : " << comment
-					   << LL_ENDL;
+    LL_INFOS("Avatar") << "REZTIME: [ " << (U32)mDebugExistenceTimer.getElapsedTimeF32()
+                       << "sec ]"
+                       << avString()
+                       << "RuthTimer " << (U32)mRuthDebugTimer.getElapsedTimeF32()
+                       << " Notification " << notification_name
+                       << " : " << comment
+                       << LL_ENDL;
 
-	if (ALControlCache::DebugAvatarRezTime)
-	{
-		LLSD args;
-		args["EXISTENCE"] = llformat("%d",(U32)mDebugExistenceTimer.getElapsedTimeF32());
-		args["TIME"] = llformat("%d",(U32)mRuthDebugTimer.getElapsedTimeF32());
-		args["NAME"] = getFullname();
-		LLNotificationsUtil::add(notification_name,args);
-	}
+    if (ALControlCache::DebugAvatarRezTime)
+    {
+        LLSD args;
+        args["EXISTENCE"] = llformat("%d",(U32)mDebugExistenceTimer.getElapsedTimeF32());
+        args["TIME"] = llformat("%d",(U32)mRuthDebugTimer.getElapsedTimeF32());
+        args["NAME"] = getFullname();
+        LLNotificationsUtil::add(notification_name,args);
+    }
 }
 
 //------------------------------------------------------------------------
@@ -839,14 +839,14 @@ void LLVOAvatar::debugAvatarRezTime(std::string notification_name, std::string c
 //------------------------------------------------------------------------
 LLVOAvatar::~LLVOAvatar()
 {
-	if (!mFullyLoaded)
-	{
-		debugAvatarRezTime("AvatarRezLeftCloudNotification","left after ruth seconds as cloud");
-	}
-	else
-	{
-		debugAvatarRezTime("AvatarRezLeftNotification","left sometime after declouding");
-	}
+    if (!mFullyLoaded)
+    {
+        debugAvatarRezTime("AvatarRezLeftCloudNotification","left after ruth seconds as cloud");
+    }
+    else
+    {
+        debugAvatarRezTime("AvatarRezLeftNotification","left sometime after declouding");
+    }
 
     if(mTuned)
     {
@@ -856,299 +856,299 @@ LLVOAvatar::~LLVOAvatar()
     sAVsIgnoringARTLimit.erase(std::remove(sAVsIgnoringARTLimit.begin(), sAVsIgnoringARTLimit.end(), mID), sAVsIgnoringARTLimit.end());
 
 
-	logPendingPhases();
-	
-	LL_DEBUGS("Avatar") << "LLVOAvatar Destructor (0x" << this << ") id:" << mID << LL_ENDL;
+    logPendingPhases();
+
+    LL_DEBUGS("Avatar") << "LLVOAvatar Destructor (0x" << this << ") id:" << mID << LL_ENDL;
+
+    std::for_each(mAttachmentPoints.begin(), mAttachmentPoints.end(), DeletePairedPointer());
+    mAttachmentPoints.clear();
 
-	std::for_each(mAttachmentPoints.begin(), mAttachmentPoints.end(), DeletePairedPointer());
-	mAttachmentPoints.clear();
+    mDead = TRUE;
 
-	mDead = TRUE;
-	
-	mAnimationSources.clear();
-	LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList) ;
+    mAnimationSources.clear();
+    LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList) ;
 
-	getPhases().clearPhases();
-	
-	LL_DEBUGS() << "LLVOAvatar Destructor end" << LL_ENDL;
+    getPhases().clearPhases();
+
+    LL_DEBUGS() << "LLVOAvatar Destructor end" << LL_ENDL;
 }
 
 void LLVOAvatar::markDead()
 {
-	if (mNameText)
-	{
-		mNameText->markDead();
-		mNameText = NULL;
-		sNumVisibleChatBubbles--;
-	}
-	mVoiceVisualizer->markDead();
-	LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList) ;
-	LLViewerObject::markDead();
+    if (mNameText)
+    {
+        mNameText->markDead();
+        mNameText = NULL;
+        sNumVisibleChatBubbles--;
+    }
+    mVoiceVisualizer->markDead();
+    LLLoadedCallbackEntry::cleanUpCallbackList(&mCallbackTextureList) ;
+    LLViewerObject::markDead();
 }
 
 
 BOOL LLVOAvatar::isFullyBaked()
 {
-	if (mIsDummy) return TRUE;
-	if (getNumTEs() == 0) return FALSE;
+    if (mIsDummy) return TRUE;
+    if (getNumTEs() == 0) return FALSE;
 
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		if (!isTextureDefined(mBakedTextureDatas[i].mTextureIndex)
-			&& ((i != BAKED_SKIRT) || isWearingWearableType(LLWearableType::WT_SKIRT))
-			&& (i != BAKED_LEFT_ARM) && (i != BAKED_LEFT_LEG) && (i != BAKED_AUX1) && (i != BAKED_AUX2) && (i != BAKED_AUX3))
-		{
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        if (!isTextureDefined(mBakedTextureDatas[i].mTextureIndex)
+            && ((i != BAKED_SKIRT) || isWearingWearableType(LLWearableType::WT_SKIRT))
+            && (i != BAKED_LEFT_ARM) && (i != BAKED_LEFT_LEG) && (i != BAKED_AUX1) && (i != BAKED_AUX2) && (i != BAKED_AUX3))
+        {
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 BOOL LLVOAvatar::isFullyTextured() const
 {
-	for (S32 i = 0; i < mMeshLOD.size(); i++)
-	{
-		LLAvatarJoint* joint = mMeshLOD[i];
-		if (i==MESH_ID_SKIRT && !isWearingWearableType(LLWearableType::WT_SKIRT))
-		{
-			continue; // don't care about skirt textures if we're not wearing one.
-		}
-		if (!joint)
-		{
-			continue; // nonexistent LOD OK.
-		}
-		avatar_joint_mesh_list_t::iterator meshIter = joint->mMeshParts.begin();
-		if (meshIter != joint->mMeshParts.end())
-		{
-			LLAvatarJointMesh *mesh = (*meshIter);
-			if (!mesh)
-			{
-				continue; // nonexistent mesh OK
-			}
-			if (mesh->hasGLTexture())
-			{
-				continue; // Mesh exists and has a baked texture.
-			}
-			if (mesh->hasComposite())
-			{
-				continue; // Mesh exists and has a composite texture.
-			}
-			// Fail
-			return FALSE;
-		}
-	}
-	return TRUE;
+    for (S32 i = 0; i < mMeshLOD.size(); i++)
+    {
+        LLAvatarJoint* joint = mMeshLOD[i];
+        if (i==MESH_ID_SKIRT && !isWearingWearableType(LLWearableType::WT_SKIRT))
+        {
+            continue; // don't care about skirt textures if we're not wearing one.
+        }
+        if (!joint)
+        {
+            continue; // nonexistent LOD OK.
+        }
+        avatar_joint_mesh_list_t::iterator meshIter = joint->mMeshParts.begin();
+        if (meshIter != joint->mMeshParts.end())
+        {
+            LLAvatarJointMesh *mesh = (*meshIter);
+            if (!mesh)
+            {
+                continue; // nonexistent mesh OK
+            }
+            if (mesh->hasGLTexture())
+            {
+                continue; // Mesh exists and has a baked texture.
+            }
+            if (mesh->hasComposite())
+            {
+                continue; // Mesh exists and has a composite texture.
+            }
+            // Fail
+            return FALSE;
+        }
+    }
+    return TRUE;
 }
 
 BOOL LLVOAvatar::hasGray() const
 {
-	return !getIsCloud() && !isFullyTextured();
+    return !getIsCloud() && !isFullyTextured();
 }
 
 S32 LLVOAvatar::getRezzedStatus() const
 {
-	if (getIsCloud()) return 0;
-	bool textured = isFullyTextured();
-	if (textured && allBakedTexturesCompletelyDownloaded()) return 3;
-	if (textured) return 2;
-	llassert(hasGray());
-	return 1; // gray
+    if (getIsCloud()) return 0;
+    bool textured = isFullyTextured();
+    if (textured && allBakedTexturesCompletelyDownloaded()) return 3;
+    if (textured) return 2;
+    llassert(hasGray());
+    return 1; // gray
 }
 
 void LLVOAvatar::deleteLayerSetCaches(bool clearAll)
 {
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		if (mBakedTextureDatas[i].mTexLayerSet)
-		{
-			// ! BACKWARDS COMPATIBILITY !
-			// Can be removed after hair baking is mandatory on the grid
-			if ((i != BAKED_HAIR || isSelf()) && !clearAll)
-			{
-				mBakedTextureDatas[i].mTexLayerSet->deleteCaches();
-			}
-		}
-		if (mBakedTextureDatas[i].mMaskTexName)
-		{
-			LLImageGL::deleteTextures(1, (GLuint*)&(mBakedTextureDatas[i].mMaskTexName));
-			mBakedTextureDatas[i].mMaskTexName = 0 ;
-		}
-	}
-}
-
-// static 
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        if (mBakedTextureDatas[i].mTexLayerSet)
+        {
+            // ! BACKWARDS COMPATIBILITY !
+            // Can be removed after hair baking is mandatory on the grid
+            if ((i != BAKED_HAIR || isSelf()) && !clearAll)
+            {
+                mBakedTextureDatas[i].mTexLayerSet->deleteCaches();
+            }
+        }
+        if (mBakedTextureDatas[i].mMaskTexName)
+        {
+            LLImageGL::deleteTextures(1, (GLuint*)&(mBakedTextureDatas[i].mMaskTexName));
+            mBakedTextureDatas[i].mMaskTexName = 0 ;
+        }
+    }
+}
+
+// static
 BOOL LLVOAvatar::areAllNearbyInstancesBaked(S32& grey_avatars)
 {
-	BOOL res = TRUE;
-	grey_avatars = 0;
-	for (LLCharacter* character : LLCharacter::sInstances)
-	{
-		LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
-		if( inst->isDead() )
-		{
-			continue;
-		}
-		else if( !inst->isFullyBaked() )
-		{
-			res = FALSE;
-			if (inst->mHasGrey)
-			{
-				++grey_avatars;
-			}
-		}
-	}
-	return res;
+    BOOL res = TRUE;
+    grey_avatars = 0;
+    for (LLCharacter* character : LLCharacter::sInstances)
+    {
+        LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
+        if( inst->isDead() )
+        {
+            continue;
+        }
+        else if( !inst->isFullyBaked() )
+        {
+            res = FALSE;
+            if (inst->mHasGrey)
+            {
+                ++grey_avatars;
+            }
+        }
+    }
+    return res;
 }
 
 // static
 void LLVOAvatar::getNearbyRezzedStats(std::vector<S32>& counts)
 {
-	counts.clear();
-	counts.resize(4);
-	for (LLCharacter* character : LLCharacter::sInstances)
-	{
-		LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
-		if (inst)
-		{
-			S32 rez_status = inst->getRezzedStatus();
-			counts[rez_status]++;
-		}
-	}
+    counts.clear();
+    counts.resize(4);
+    for (LLCharacter* character : LLCharacter::sInstances)
+    {
+        LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
+        if (inst)
+        {
+            S32 rez_status = inst->getRezzedStatus();
+            counts[rez_status]++;
+        }
+    }
 }
 
 // static
 std::string LLVOAvatar::rezStatusToString(S32 rez_status)
 {
-	if (rez_status==0) return "cloud";
-	if (rez_status==1) return "gray";
-	if (rez_status==2) return "downloading";
-	if (rez_status==3) return "full";
-	return "unknown";
+    if (rez_status==0) return "cloud";
+    if (rez_status==1) return "gray";
+    if (rez_status==2) return "downloading";
+    if (rez_status==3) return "full";
+    return "unknown";
 }
 
 // static
 void LLVOAvatar::dumpBakedStatus()
 {
-	LLVector3d camera_pos_global = gAgentCamera.getCameraPositionGlobal();
-
-	for (LLCharacter* character : LLCharacter::sInstances)
-	{
-		LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
-		LL_INFOS() << "Avatar ";
-
-		LLNameValue* firstname = inst->getNVPair("FirstName");
-		LLNameValue* lastname = inst->getNVPair("LastName");
-
-		if( firstname )
-		{
-			LL_CONT << firstname->getString();
-		}
-		if( lastname )
-		{
-			LL_CONT << " " << lastname->getString();
-		}
-
-		LL_CONT << " " << inst->mID;
-
-		if( inst->isDead() )
-		{
-			LL_CONT << " DEAD ("<< inst->getNumRefs() << " refs)";
-		}
-
-		if( inst->isSelf() )
-		{
-			LL_CONT << " (self)";
-		}
-
-
-		F64 dist_to_camera = (inst->getPositionGlobal() - camera_pos_global).length();
-		LL_CONT << " " << dist_to_camera << "m ";
-
-		LL_CONT << " " << inst->mPixelArea << " pixels";
-
-		if( inst->isVisible() )
-		{
-			LL_CONT << " (visible)";
-		}
-		else
-		{
-			LL_CONT << " (not visible)";
-		}
-
-		if( inst->isFullyBaked() )
-		{
-			LL_CONT << " Baked";
-		}
-		else
-		{
-			LL_CONT << " Unbaked (";
-			
-			for (const auto& baked_pair : LLAvatarAppearance::getDictionary()->getBakedTextures())
-			{
-				const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
-				const ETextureIndex index = baked_dict->mTextureIndex;
-				if (!inst->isTextureDefined(index))
-				{
-					LL_CONT << " " << (LLAvatarAppearance::getDictionary()->getTexture(index) ? LLAvatarAppearance::getDictionary()->getTexture(index)->mName : "");
-				}
-			}
-			LL_CONT << " ) " << inst->getUnbakedPixelAreaRank();
-			if( inst->isCulled() )
-			{
-				LL_CONT << " culled";
-			}
-		}
-		LL_CONT << LL_ENDL;
-	}
+    LLVector3d camera_pos_global = gAgentCamera.getCameraPositionGlobal();
+
+    for (LLCharacter* character : LLCharacter::sInstances)
+    {
+        LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
+        LL_INFOS() << "Avatar ";
+
+        LLNameValue* firstname = inst->getNVPair("FirstName");
+        LLNameValue* lastname = inst->getNVPair("LastName");
+
+        if( firstname )
+        {
+            LL_CONT << firstname->getString();
+        }
+        if( lastname )
+        {
+            LL_CONT << " " << lastname->getString();
+        }
+
+        LL_CONT << " " << inst->mID;
+
+        if( inst->isDead() )
+        {
+            LL_CONT << " DEAD ("<< inst->getNumRefs() << " refs)";
+        }
+
+        if( inst->isSelf() )
+        {
+            LL_CONT << " (self)";
+        }
+
+
+        F64 dist_to_camera = (inst->getPositionGlobal() - camera_pos_global).length();
+        LL_CONT << " " << dist_to_camera << "m ";
+
+        LL_CONT << " " << inst->mPixelArea << " pixels";
+
+        if( inst->isVisible() )
+        {
+            LL_CONT << " (visible)";
+        }
+        else
+        {
+            LL_CONT << " (not visible)";
+        }
+
+        if( inst->isFullyBaked() )
+        {
+            LL_CONT << " Baked";
+        }
+        else
+        {
+            LL_CONT << " Unbaked (";
+
+            for (const auto& baked_pair : LLAvatarAppearance::getDictionary()->getBakedTextures())
+            {
+                const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
+                const ETextureIndex index = baked_dict->mTextureIndex;
+                if (!inst->isTextureDefined(index))
+                {
+                    LL_CONT << " " << (LLAvatarAppearance::getDictionary()->getTexture(index) ? LLAvatarAppearance::getDictionary()->getTexture(index)->mName : "");
+                }
+            }
+            LL_CONT << " ) " << inst->getUnbakedPixelAreaRank();
+            if( inst->isCulled() )
+            {
+                LL_CONT << " culled";
+            }
+        }
+        LL_CONT << LL_ENDL;
+    }
 }
 
 //static
 void LLVOAvatar::restoreGL()
 {
-	if (!isAgentAvatarValid()) return;
+    if (!isAgentAvatarValid()) return;
 
-	gAgentAvatarp->setCompositeUpdatesEnabled(TRUE);
-	for (U32 i = 0; i < gAgentAvatarp->mBakedTextureDatas.size(); i++)
-	{
-		gAgentAvatarp->invalidateComposite(gAgentAvatarp->getTexLayerSet(i));
-	}
-	gAgentAvatarp->updateMeshTextures();
+    gAgentAvatarp->setCompositeUpdatesEnabled(TRUE);
+    for (U32 i = 0; i < gAgentAvatarp->mBakedTextureDatas.size(); i++)
+    {
+        gAgentAvatarp->invalidateComposite(gAgentAvatarp->getTexLayerSet(i));
+    }
+    gAgentAvatarp->updateMeshTextures();
 }
 
 //static
 void LLVOAvatar::destroyGL()
 {
-	deleteCachedImages();
+    deleteCachedImages();
 
-	resetImpostors();
+    resetImpostors();
 }
 
 //static
 void LLVOAvatar::resetImpostors()
 {
-	for (LLCharacter* character : LLCharacter::sInstances)
-	{
-		LLVOAvatar* avatar = static_cast<LLVOAvatar*>(character);
-		avatar->mImpostor.release();
-		avatar->mNeedsImpostorUpdate = TRUE;
-		avatar->mLastImpostorUpdateReason = 1;
-	}
+    for (LLCharacter* character : LLCharacter::sInstances)
+    {
+        LLVOAvatar* avatar = static_cast<LLVOAvatar*>(character);
+        avatar->mImpostor.release();
+        avatar->mNeedsImpostorUpdate = TRUE;
+        avatar->mLastImpostorUpdateReason = 1;
+    }
 }
 
 // static
 void LLVOAvatar::deleteCachedImages(bool clearAll)
-{	
-	if (LLViewerTexLayerSet::sHasCaches)
-	{
-		for (LLCharacter* character : LLCharacter::sInstances)
-		{
-			LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
-			inst->deleteLayerSetCaches(clearAll);
-		}
-		LLViewerTexLayerSet::sHasCaches = FALSE;
-	}
-	LLVOAvatarSelf::deleteScratchTextures();
-	LLTexLayerStaticImageList::getInstance()->deleteCachedImages();
+{
+    if (LLViewerTexLayerSet::sHasCaches)
+    {
+        for (LLCharacter* character : LLCharacter::sInstances)
+        {
+            LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
+            inst->deleteLayerSetCaches(clearAll);
+        }
+        LLViewerTexLayerSet::sHasCaches = FALSE;
+    }
+    LLVOAvatarSelf::deleteScratchTextures();
+    LLTexLayerStaticImageList::getInstance()->deleteCachedImages();
 }
 
 
@@ -1157,26 +1157,26 @@ void LLVOAvatar::deleteCachedImages(bool clearAll)
 // LLVOAvatar::initClass()
 //------------------------------------------------------------------------
 void LLVOAvatar::initClass()
-{ 
-	gAnimLibrary.animStateSetString(ANIM_AGENT_BODY_NOISE,"body_noise");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_BREATHE_ROT,"breathe_rot");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_PHYSICS_MOTION,"physics_motion");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_EDITING,"editing");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_EYE,"eye");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_FLY_ADJUST,"fly_adjust");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_HAND_MOTION,"hand_motion");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_HEAD_ROT,"head_rot");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_PELVIS_FIX,"pelvis_fix");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_TARGET,"target");
-	gAnimLibrary.animStateSetString(ANIM_AGENT_WALK_ADJUST,"walk_adjust");
-
-	//BD
-	gAnimLibrary.animStateSetString(ANIM_BD_POSING_MOTION, "custom_pose");
+{
+    gAnimLibrary.animStateSetString(ANIM_AGENT_BODY_NOISE,"body_noise");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_BREATHE_ROT,"breathe_rot");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_PHYSICS_MOTION,"physics_motion");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_EDITING,"editing");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_EYE,"eye");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_FLY_ADJUST,"fly_adjust");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_HAND_MOTION,"hand_motion");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_HEAD_ROT,"head_rot");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_PELVIS_FIX,"pelvis_fix");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_TARGET,"target");
+    gAnimLibrary.animStateSetString(ANIM_AGENT_WALK_ADJUST,"walk_adjust");
+
+    //BD
+    gAnimLibrary.animStateSetString(ANIM_BD_POSING_MOTION, "custom_pose");
 
     // Where should this be set initially?
     LLJoint::setDebugJointNames(gSavedSettings.getString("DebugAvatarJoints"));
 
-	LLControlAvatar::sRegionChangedSlot = gAgent.addRegionChangedCallback(&LLControlAvatar::onRegionChanged);
+    LLControlAvatar::sRegionChangedSlot = gAgent.addRegionChangedCallback(&LLControlAvatar::onRegionChanged);
 
     sCloudTexture = LLViewerTextureManager::getFetchedTextureFromFile("SoftDotNoBack.png");
 }
@@ -1189,77 +1189,77 @@ void LLVOAvatar::cleanupClass()
 // virtual
 void LLVOAvatar::initInstance()
 {
-	//-------------------------------------------------------------------------
-	// register motions
-	//-------------------------------------------------------------------------
-	if (LLCharacter::sInstances.size() == 1)
-	{
-		registerMotion( ANIM_AGENT_DO_NOT_DISTURB,					LLNullMotion::create );
-		registerMotion( ANIM_AGENT_CROUCH,					LLKeyframeStandMotion::create );
-		registerMotion( ANIM_AGENT_CROUCHWALK,				LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_EXPRESS_AFRAID,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_ANGER,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_BORED,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_CRY,				LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_DISDAIN,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_EMBARRASSED,		LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_FROWN,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_KISS,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_LAUGH,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_OPEN_MOUTH,		LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_REPULSED,		LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_SAD,				LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_SHRUG,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_SMILE,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_SURPRISE,		LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_TONGUE_OUT,		LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_TOOTHSMILE,		LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_WINK,			LLEmote::create );
-		registerMotion( ANIM_AGENT_EXPRESS_WORRY,			LLEmote::create );
-		registerMotion( ANIM_AGENT_FEMALE_RUN_NEW,			LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_FEMALE_WALK,				LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_FEMALE_WALK_NEW,			LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_RUN,						LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_RUN_NEW,					LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_STAND,					LLKeyframeStandMotion::create );
-		registerMotion( ANIM_AGENT_STAND_1,					LLKeyframeStandMotion::create );
-		registerMotion( ANIM_AGENT_STAND_2,					LLKeyframeStandMotion::create );
-		registerMotion( ANIM_AGENT_STAND_3,					LLKeyframeStandMotion::create );
-		registerMotion( ANIM_AGENT_STAND_4,					LLKeyframeStandMotion::create );
-		registerMotion( ANIM_AGENT_STANDUP,					LLKeyframeFallMotion::create );
-		registerMotion( ANIM_AGENT_TURNLEFT,				LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_TURNRIGHT,				LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_WALK,					LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_WALK_NEW,				LLKeyframeWalkMotion::create );
-		
-		// motions without a start/stop bit
-		registerMotion( ANIM_AGENT_BODY_NOISE,				LLBodyNoiseMotion::create );
-		registerMotion( ANIM_AGENT_BREATHE_ROT,				LLBreatheMotionRot::create );
-		registerMotion( ANIM_AGENT_PHYSICS_MOTION,			LLPhysicsMotionController::create );
-		registerMotion( ANIM_AGENT_EDITING,					LLEditingMotion::create	);
-		registerMotion( ANIM_AGENT_EYE,						LLEyeMotion::create	);
-		registerMotion( ANIM_AGENT_FEMALE_WALK,				LLKeyframeWalkMotion::create );
-		registerMotion( ANIM_AGENT_FLY_ADJUST,				LLFlyAdjustMotion::create );
-		registerMotion( ANIM_AGENT_HAND_MOTION,				LLHandMotion::create );
-		registerMotion( ANIM_AGENT_HEAD_ROT,				LLHeadRotMotion::create );
-		registerMotion( ANIM_AGENT_PELVIS_FIX,				LLPelvisFixMotion::create );
-		registerMotion( ANIM_AGENT_SIT_FEMALE,				LLKeyframeMotion::create );
-		registerMotion( ANIM_AGENT_TARGET,					LLTargetingMotion::create );
-		registerMotion( ANIM_AGENT_WALK_ADJUST,				LLWalkAdjustMotion::create );
-
-		//BD - Jackpot.
-		registerMotion(	ANIM_BD_POSING_MOTION,				BDPosingMotion::create);
-	}
-	
-	LLAvatarAppearance::initInstance();
-	
-	// preload specific motions here
-	createMotion( ANIM_AGENT_CUSTOMIZE);
-	createMotion( ANIM_AGENT_CUSTOMIZE_DONE);
-	
-	//VTPause();  // VTune
-	
-	mVoiceVisualizer->setVoiceEnabled( LLVoiceClient::getInstance()->getVoiceEnabled( mID ) );
+    //-------------------------------------------------------------------------
+    // register motions
+    //-------------------------------------------------------------------------
+    if (LLCharacter::sInstances.size() == 1)
+    {
+        registerMotion( ANIM_AGENT_DO_NOT_DISTURB,                  LLNullMotion::create );
+        registerMotion( ANIM_AGENT_CROUCH,                  LLKeyframeStandMotion::create );
+        registerMotion( ANIM_AGENT_CROUCHWALK,              LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_EXPRESS_AFRAID,          LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_ANGER,           LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_BORED,           LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_CRY,             LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_DISDAIN,         LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_EMBARRASSED,     LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_FROWN,           LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_KISS,            LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_LAUGH,           LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_OPEN_MOUTH,      LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_REPULSED,        LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_SAD,             LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_SHRUG,           LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_SMILE,           LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_SURPRISE,        LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_TONGUE_OUT,      LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_TOOTHSMILE,      LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_WINK,            LLEmote::create );
+        registerMotion( ANIM_AGENT_EXPRESS_WORRY,           LLEmote::create );
+        registerMotion( ANIM_AGENT_FEMALE_RUN_NEW,          LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_FEMALE_WALK,             LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_FEMALE_WALK_NEW,         LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_RUN,                     LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_RUN_NEW,                 LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_STAND,                   LLKeyframeStandMotion::create );
+        registerMotion( ANIM_AGENT_STAND_1,                 LLKeyframeStandMotion::create );
+        registerMotion( ANIM_AGENT_STAND_2,                 LLKeyframeStandMotion::create );
+        registerMotion( ANIM_AGENT_STAND_3,                 LLKeyframeStandMotion::create );
+        registerMotion( ANIM_AGENT_STAND_4,                 LLKeyframeStandMotion::create );
+        registerMotion( ANIM_AGENT_STANDUP,                 LLKeyframeFallMotion::create );
+        registerMotion( ANIM_AGENT_TURNLEFT,                LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_TURNRIGHT,               LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_WALK,                    LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_WALK_NEW,                LLKeyframeWalkMotion::create );
+
+        // motions without a start/stop bit
+        registerMotion( ANIM_AGENT_BODY_NOISE,              LLBodyNoiseMotion::create );
+        registerMotion( ANIM_AGENT_BREATHE_ROT,             LLBreatheMotionRot::create );
+        registerMotion( ANIM_AGENT_PHYSICS_MOTION,          LLPhysicsMotionController::create );
+        registerMotion( ANIM_AGENT_EDITING,                 LLEditingMotion::create );
+        registerMotion( ANIM_AGENT_EYE,                     LLEyeMotion::create );
+        registerMotion( ANIM_AGENT_FEMALE_WALK,             LLKeyframeWalkMotion::create );
+        registerMotion( ANIM_AGENT_FLY_ADJUST,              LLFlyAdjustMotion::create );
+        registerMotion( ANIM_AGENT_HAND_MOTION,             LLHandMotion::create );
+        registerMotion( ANIM_AGENT_HEAD_ROT,                LLHeadRotMotion::create );
+        registerMotion( ANIM_AGENT_PELVIS_FIX,              LLPelvisFixMotion::create );
+        registerMotion( ANIM_AGENT_SIT_FEMALE,              LLKeyframeMotion::create );
+        registerMotion( ANIM_AGENT_TARGET,                  LLTargetingMotion::create );
+        registerMotion( ANIM_AGENT_WALK_ADJUST,             LLWalkAdjustMotion::create );
+
+        //BD - Jackpot.
+        registerMotion( ANIM_BD_POSING_MOTION,              BDPosingMotion::create);
+    }
+
+    LLAvatarAppearance::initInstance();
+
+    // preload specific motions here
+    createMotion( ANIM_AGENT_CUSTOMIZE);
+    createMotion( ANIM_AGENT_CUSTOMIZE_DONE);
+
+    //VTPause();  // VTune
+
+    mVoiceVisualizer->setVoiceEnabled( LLVoiceClient::getInstance()->getVoiceEnabled( mID ) );
 
     mInitFlags |= 1<<1;
 }
@@ -1267,68 +1267,68 @@ void LLVOAvatar::initInstance()
 // virtual
 LLAvatarJoint* LLVOAvatar::createAvatarJoint()
 {
-	return new LLViewerJoint();
+    return new LLViewerJoint();
 }
 
 // virtual
 LLAvatarJoint* LLVOAvatar::createAvatarJoint(S32 joint_num)
 {
-	return new LLViewerJoint(joint_num);
+    return new LLViewerJoint(joint_num);
 }
 
 // virtual
 LLAvatarJointMesh* LLVOAvatar::createAvatarJointMesh()
 {
-	return new LLViewerJointMesh();
+    return new LLViewerJointMesh();
 }
 
 // virtual
 LLTexLayerSet* LLVOAvatar::createTexLayerSet()
 {
-	return new LLViewerTexLayerSet(this);
+    return new LLViewerTexLayerSet(this);
 }
 
 const LLVector3 LLVOAvatar::getRenderPosition() const
 {
 
-	if (mDrawable.isNull() || mDrawable->getGeneration() < 0)
-	{
-		return getPositionAgent();
-	}
-	else if (isRoot())
-	{
-		F32 fixup;
-		if ( hasPelvisFixup( fixup) )
-		{
-			//Apply a pelvis fixup (as defined by the avs skin)
-			LLVector3 pos = mDrawable->getPositionAgent();
-			pos[VZ] += fixup;
-			return pos;
-		}
-		else
-		{
-			return mDrawable->getPositionAgent();
-		}
-	}
-	else
-	{
-		LLVector4a pos;
-		pos.load3(getPosition().mV);
-		mDrawable->getParent()->getRenderMatrix().affineTransform(pos,pos);
-		return LLVector3(pos.getF32ptr());
-	}
+    if (mDrawable.isNull() || mDrawable->getGeneration() < 0)
+    {
+        return getPositionAgent();
+    }
+    else if (isRoot())
+    {
+        F32 fixup;
+        if ( hasPelvisFixup( fixup) )
+        {
+            //Apply a pelvis fixup (as defined by the avs skin)
+            LLVector3 pos = mDrawable->getPositionAgent();
+            pos[VZ] += fixup;
+            return pos;
+        }
+        else
+        {
+            return mDrawable->getPositionAgent();
+        }
+    }
+    else
+    {
+        LLVector4a pos;
+        pos.load3(getPosition().mV);
+        mDrawable->getParent()->getRenderMatrix().affineTransform(pos,pos);
+        return LLVector3(pos.getF32ptr());
+    }
 }
 
 void LLVOAvatar::updateDrawable(BOOL force_damped)
 {
-	clearChanged(SHIFTED);
+    clearChanged(SHIFTED);
 }
 
 void LLVOAvatar::onShift(const LLVector4a& shift_vector)
 {
-	const LLVector3& shift = reinterpret_cast<const LLVector3&>(shift_vector);
-	mLastAnimExtents[0] += shift;
-	mLastAnimExtents[1] += shift;
+    const LLVector3& shift = reinterpret_cast<const LLVector3&>(shift_vector);
+    mLastAnimExtents[0] += shift;
+    mLastAnimExtents[1] += shift;
 }
 
 void LLVOAvatar::updateSpatialExtents(LLVector4a& newMin, LLVector4a &newMax)
@@ -1343,37 +1343,37 @@ void LLVOAvatar::updateSpatialExtents(LLVector4a& newMin, LLVector4a &newMax)
         calculateSpatialExtents(newMin,newMax);
         mLastAnimExtents[0].set(newMin.getF32ptr());
         mLastAnimExtents[1].set(newMax.getF32ptr());
-		mLastAnimBasePos = mPelvisp->getWorldPosition();
+        mLastAnimBasePos = mPelvisp->getWorldPosition();
         mNeedsExtentUpdate = false;
     }
-	else
-	{
-		LLVector3 new_base_pos = mPelvisp->getWorldPosition();
-		LLVector3 shift = new_base_pos-mLastAnimBasePos;
-		mLastAnimExtents[0] += shift;
-		mLastAnimExtents[1] += shift;
-		mLastAnimBasePos = new_base_pos;
-
-	}
-          
-	if (isImpostor() && !needsImpostorUpdate())
-	{
-		LLVector3 delta = getRenderPosition() -
-			((LLVector3(mDrawable->getPositionGroup().getF32ptr())-mImpostorOffset));
-		
-		newMin.load3( (mLastAnimExtents[0] + delta).mV);
-		newMax.load3( (mLastAnimExtents[1] + delta).mV);
-	}
-	else
-	{
+    else
+    {
+        LLVector3 new_base_pos = mPelvisp->getWorldPosition();
+        LLVector3 shift = new_base_pos-mLastAnimBasePos;
+        mLastAnimExtents[0] += shift;
+        mLastAnimExtents[1] += shift;
+        mLastAnimBasePos = new_base_pos;
+
+    }
+
+    if (isImpostor() && !needsImpostorUpdate())
+    {
+        LLVector3 delta = getRenderPosition() -
+            ((LLVector3(mDrawable->getPositionGroup().getF32ptr())-mImpostorOffset));
+
+        newMin.load3( (mLastAnimExtents[0] + delta).mV);
+        newMax.load3( (mLastAnimExtents[1] + delta).mV);
+    }
+    else
+    {
         newMin.load3(mLastAnimExtents[0].mV);
         newMax.load3(mLastAnimExtents[1].mV);
-		LLVector4a pos_group;
-		pos_group.setAdd(newMin,newMax);
-		pos_group.mul(0.5f);
-		mImpostorOffset = LLVector3(pos_group.getF32ptr())-getRenderPosition();
-		mDrawable->setPositionGroup(pos_group);
-	}
+        LLVector4a pos_group;
+        pos_group.setAdd(newMin,newMax);
+        pos_group.mul(0.5f);
+        mImpostorOffset = LLVector3(pos_group.getF32ptr())-getRenderPosition();
+        mDrawable->setPositionGroup(pos_group);
+    }
 }
 
 
@@ -1486,10 +1486,10 @@ void LLVOAvatar::calculateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
                                 LLVector4a max_span(max_attachment_span);
 
                                 S32 lt = distance.lessThan(max_span).getGatheredBits() & 0x7;
-                        
+
                                 // Only add the prim to spatial extents calculations if it isn't a megaprim.
-                                // max_attachment_span calculated at the start of the function 
-                                // (currently 5 times our max prim size) 
+                                // max_attachment_span calculated at the start of the function
+                                // (currently 5 times our max prim size)
                                 if (lt == 0x7)
                                 {
                                     update_min_max(newMin,newMax,ext[0]);
@@ -1526,8 +1526,8 @@ void LLVOAvatar::calculateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
                 }
 
                 LLVector4a new_extents[2];
-				const LLMatrix4a& mat = joint->getWorldMatrix();
-				mat.mulBoundBox(rig_info->getRiggedExtents(), new_extents);
+                const LLMatrix4a& mat = joint->getWorldMatrix();
+                mat.mulBoundBox(rig_info->getRiggedExtents(), new_extents);
                 update_min_max(newMin, newMax, new_extents[0]);
                 update_min_max(newMin, newMax, new_extents[1]);
                 //if (isSelf())
@@ -1543,10 +1543,10 @@ void LLVOAvatar::calculateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
     LLVector4a center, size;
     center.setAdd(newMin, newMax);
     center.mul(0.5f);
-    
+
     size.setSub(newMax,newMin);
     size.mul(0.5f);
-    
+
     mPixelArea = LLPipeline::calcPixelArea(center, size, LLViewerCamera::instance());
 }
 
@@ -1559,24 +1559,24 @@ void render_sphere_and_line(const LLVector3& begin_pos, const LLVector3& end_pos
     gGL.diffuseColor3f(visible_color[0], visible_color[1], visible_color[2]);
 
     gGL.begin(LLRender::LINES);
-    gGL.vertex3fv(begin_pos.mV); 
+    gGL.vertex3fv(begin_pos.mV);
     gGL.vertex3fv(end_pos.mV);
     gGL.end();
-        
+
 
     // Draw sphere representing joint pos
     gGL.pushMatrix();
     gGL.scalef(sphere_scale, sphere_scale, sphere_scale);
     gSphere.renderGGL();
     gGL.popMatrix();
-        
+
     LLGLDepthTest depth_under(GL_TRUE, GL_FALSE, GL_GREATER);
 
     // Occluded bone portions
     gGL.diffuseColor3f(occ_color[0], occ_color[1], occ_color[2]);
 
     gGL.begin(LLRender::LINES);
-    gGL.vertex3fv(begin_pos.mV); 
+    gGL.vertex3fv(begin_pos.mV);
     gGL.vertex3fv(end_pos.mV);
     gGL.end();
 
@@ -1592,18 +1592,18 @@ void render_sphere_and_line(const LLVector3& begin_pos, const LLVector3& end_pos
 //-----------------------------------------------------------------------------
 void LLVOAvatar::renderCollisionVolumes()
 {
-	std::ostringstream ostr;
+    std::ostringstream ostr;
 
-	for (S32 i = 0; i < mNumCollisionVolumes; i++)
-	{
-		ostr << mCollisionVolumes[i].getName() << ", ";
+    for (S32 i = 0; i < mNumCollisionVolumes; i++)
+    {
+        ostr << mCollisionVolumes[i].getName() << ", ";
 
         LLAvatarJointCollisionVolume& collision_volume = mCollisionVolumes[i];
 
-		collision_volume.updateWorldMatrix();
+        collision_volume.updateWorldMatrix();
 
-		gGL.pushMatrix();
-		gGL.multMatrix(collision_volume.getXform()->getWorldMatrix());
+        gGL.pushMatrix();
+        gGL.multMatrix(collision_volume.getXform()->getWorldMatrix());
 
         LLVector3 begin_pos(0,0,0);
         LLVector3 end_pos(collision_volume.getEnd());
@@ -1615,7 +1615,7 @@ void LLVOAvatar::renderCollisionVolumes()
         static LLVector3 RED(1.0f, 0.0f, 0.0f);
         static LLVector3 PASTEL_RED(1.0f, 0.5f, 0.5f);
         static LLVector3 WHITE(1.0f, 1.0f, 1.0f);
-        
+
 
         LLVector3 cv_color_occluded;
         LLVector3 cv_color_visible;
@@ -1637,13 +1637,13 @@ void LLVOAvatar::renderCollisionVolumes()
         gGL.popMatrix();
     }
 
-    
-	if (mNameText.notNull())
-	{
-		LLVector4a unused;
-	
-		mNameText->lineSegmentIntersect(unused, unused, unused, TRUE);
-	}
+
+    if (mNameText.notNull())
+    {
+        LLVector4a unused;
+
+        mNameText->lineSegmentIntersect(unused, unused, unused, TRUE);
+    }
 }
 
 void LLVOAvatar::renderBones(const std::string &selected_joint)
@@ -1662,17 +1662,17 @@ void LLVOAvatar::renderBones(const std::string &selected_joint)
     // For bones not otherwise colored
     static LLVector3 OTHER_COLOR_OCCLUDED(0.0f, 1.0f, 0.0f);
     static LLVector3 OTHER_COLOR_VISIBLE(0.5f, 0.5f, 0.5f);
-    
+
     static F32 SPHERE_SCALEF = 0.001f;
 
-	for (LLJoint* jointp : mSkeleton)
-	{
-		if (!jointp)
-		{
-			continue;
-		}
+    for (LLJoint* jointp : mSkeleton)
+    {
+        if (!jointp)
+        {
+            continue;
+        }
 
-		jointp->updateWorldMatrix();
+        jointp->updateWorldMatrix();
 
         LLVector3 occ_color, visible_color;
 
@@ -1710,331 +1710,331 @@ void LLVOAvatar::renderBones(const std::string &selected_joint)
         LLVector3 begin_pos(0,0,0);
         LLVector3 end_pos(jointp->getEnd());
 
-        
-		gGL.pushMatrix();
-		gGL.multMatrix(jointp->getXform()->getWorldMatrix());
+
+        gGL.pushMatrix();
+        gGL.multMatrix(jointp->getXform()->getWorldMatrix());
 
         render_sphere_and_line(begin_pos, end_pos, sphere_scale, occ_color, visible_color);
-        
-		gGL.popMatrix();
-	}
+
+        gGL.popMatrix();
+    }
 }
 
 
 void LLVOAvatar::renderJoints()
 {
-	std::ostringstream ostr;
-	std::ostringstream nullstr;
+    std::ostringstream ostr;
+    std::ostringstream nullstr;
+
+    for (const auto& joint_pair : mJointMap)
+    {
+        LLJoint* jointp = joint_pair.second;
+        if (!jointp)
+        {
+            nullstr << joint_pair.first << " is NULL" << std::endl;
+            continue;
+        }
+
+        ostr << jointp->getName() << ", ";
 
-	for (const auto& joint_pair : mJointMap)
-	{
-		LLJoint* jointp = joint_pair.second;
-		if (!jointp)
-		{
-			nullstr << joint_pair.first << " is NULL" << std::endl;
-			continue;
-		}
+        jointp->updateWorldMatrix();
 
-		ostr << jointp->getName() << ", ";
+        gGL.pushMatrix();
+        gGL.multMatrix(jointp->getXform()->getWorldMatrix());
 
-		jointp->updateWorldMatrix();
-	
-		gGL.pushMatrix();
-		gGL.multMatrix(jointp->getXform()->getWorldMatrix());
+        gGL.diffuseColor3f( 1.f, 0.f, 1.f );
 
-		gGL.diffuseColor3f( 1.f, 0.f, 1.f );
-	
-		gGL.begin(LLRender::LINES);
-	
-		LLVector3 v[] = 
-		{
-			LLVector3(1,0,0),
-			LLVector3(-1,0,0),
-			LLVector3(0,1,0),
-			LLVector3(0,-1,0),
+        gGL.begin(LLRender::LINES);
 
-			LLVector3(0,0,-1),
-			LLVector3(0,0,1),
-		};
+        LLVector3 v[] =
+        {
+            LLVector3(1,0,0),
+            LLVector3(-1,0,0),
+            LLVector3(0,1,0),
+            LLVector3(0,-1,0),
+
+            LLVector3(0,0,-1),
+            LLVector3(0,0,1),
+        };
 
-		//sides
-		gGL.vertex3fv(v[0].mV); 
-		gGL.vertex3fv(v[2].mV);
+        //sides
+        gGL.vertex3fv(v[0].mV);
+        gGL.vertex3fv(v[2].mV);
 
-		gGL.vertex3fv(v[0].mV); 
-		gGL.vertex3fv(v[3].mV);
+        gGL.vertex3fv(v[0].mV);
+        gGL.vertex3fv(v[3].mV);
 
-		gGL.vertex3fv(v[1].mV); 
-		gGL.vertex3fv(v[2].mV);
+        gGL.vertex3fv(v[1].mV);
+        gGL.vertex3fv(v[2].mV);
 
-		gGL.vertex3fv(v[1].mV); 
-		gGL.vertex3fv(v[3].mV);
+        gGL.vertex3fv(v[1].mV);
+        gGL.vertex3fv(v[3].mV);
 
 
-		//top
-		gGL.vertex3fv(v[0].mV); 
-		gGL.vertex3fv(v[4].mV);
+        //top
+        gGL.vertex3fv(v[0].mV);
+        gGL.vertex3fv(v[4].mV);
 
-		gGL.vertex3fv(v[1].mV); 
-		gGL.vertex3fv(v[4].mV);
+        gGL.vertex3fv(v[1].mV);
+        gGL.vertex3fv(v[4].mV);
 
-		gGL.vertex3fv(v[2].mV); 
-		gGL.vertex3fv(v[4].mV);
+        gGL.vertex3fv(v[2].mV);
+        gGL.vertex3fv(v[4].mV);
 
-		gGL.vertex3fv(v[3].mV); 
-		gGL.vertex3fv(v[4].mV);
+        gGL.vertex3fv(v[3].mV);
+        gGL.vertex3fv(v[4].mV);
 
 
-		//bottom
-		gGL.vertex3fv(v[0].mV); 
-		gGL.vertex3fv(v[5].mV);
+        //bottom
+        gGL.vertex3fv(v[0].mV);
+        gGL.vertex3fv(v[5].mV);
 
-		gGL.vertex3fv(v[1].mV); 
-		gGL.vertex3fv(v[5].mV);
+        gGL.vertex3fv(v[1].mV);
+        gGL.vertex3fv(v[5].mV);
 
-		gGL.vertex3fv(v[2].mV); 
-		gGL.vertex3fv(v[5].mV);
+        gGL.vertex3fv(v[2].mV);
+        gGL.vertex3fv(v[5].mV);
 
-		gGL.vertex3fv(v[3].mV); 
-		gGL.vertex3fv(v[5].mV);
+        gGL.vertex3fv(v[3].mV);
+        gGL.vertex3fv(v[5].mV);
 
-		gGL.end();
+        gGL.end();
 
-		gGL.popMatrix();
-	}
+        gGL.popMatrix();
+    }
 
-	mDebugText.clear();
-	addDebugText(ostr.str());
-	addDebugText(nullstr.str());
+    mDebugText.clear();
+    addDebugText(ostr.str());
+    addDebugText(nullstr.str());
 }
 
 BOOL LLVOAvatar::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
-									  S32 face,
-									  BOOL pick_transparent,
-									  BOOL pick_rigged,
+                                      S32 face,
+                                      BOOL pick_transparent,
+                                      BOOL pick_rigged,
                                       BOOL pick_unselectable,
-									  S32* face_hit,
-									  LLVector4a* intersection,
-									  LLVector2* tex_coord,
-									  LLVector4a* normal,
-									  LLVector4a* tangent)
+                                      S32* face_hit,
+                                      LLVector4a* intersection,
+                                      LLVector2* tex_coord,
+                                      LLVector4a* normal,
+                                      LLVector4a* tangent)
 {
-	if ((isSelf() && !gAgent.needsRenderAvatar()) || !LLPipeline::sPickAvatar)
-	{
-		return FALSE;
-	}
+    if ((isSelf() && !gAgent.needsRenderAvatar()) || !LLPipeline::sPickAvatar)
+    {
+        return FALSE;
+    }
 
     if (isControlAvatar())
     {
         return FALSE;
     }
-    
-	if (lineSegmentBoundingBox(start, end))
-	{
-		for (S32 i = 0; i < mNumCollisionVolumes; ++i)
-		{
-			mCollisionVolumes[i].updateWorldMatrix();
-            
-			LLMatrix4a mat = mCollisionVolumes[i].getXform()->getWorldMatrix();
-			LLMatrix4a inverse = mat;
-			inverse.invert();
-			LLMatrix4a norm_mat = inverse;
-			norm_mat.transpose();
-
-			LLVector4a p1, p2;
-			inverse.affineTransform(start,p1);	//Might need to use perspectiveTransform here.
-			inverse.affineTransform(end,p2);
-
-			LLVector3 position;
-			LLVector3 norm;
-
-			if (linesegment_sphere(LLVector3(p1.getF32ptr()), LLVector3(p2.getF32ptr()), LLVector3(0,0,0), 1.f, position, norm))
-			{
-				if (intersection)
-				{
-					LLVector4a res_pos;
-					res_pos.load3(position.mV);
-					mat.affineTransform(res_pos,res_pos);
-					*intersection = res_pos;
-				}
-
-				if (normal)
-				{
-					LLVector4a res_norm;
-					res_norm.load3(norm.mV);
-					res_norm.normalize3fast();
-					norm_mat.perspectiveTransform(res_norm,res_norm);
-					*normal = res_norm;
-				}
-
-				return TRUE;
-			}
-		}
-
-		if (isSelf())
-		{
-			for (const auto& attach_pair : mAttachmentPoints)
-			{
-				LLViewerJointAttachment* attachment = attach_pair.second;
-				if (!attachment) continue;
-				for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-				{
-					if (attached_object && !attached_object->isDead() && attachment->getValid())
-					{
-						LLDrawable* drawable = attached_object->mDrawable;
-						if (drawable->isState(LLDrawable::RIGGED))
-						{ //regenerate octree for rigged attachment
-							gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_RIGGED);
-						}
-					}
-				}
-			}
-		}
-	}
-
-	LLVector4a position;
-	if (mNameText.notNull() && mNameText->lineSegmentIntersect(start, end, position))
-	{
-		if (intersection)
-		{
-			*intersection = position;
-		}
-
-		return TRUE;
-	}
-
-	return FALSE;
-}
-
-// virtual
-LLViewerObject* LLVOAvatar::lineSegmentIntersectRiggedAttachments(const LLVector4a& start, const LLVector4a& end,
-									  S32 face,
-									  BOOL pick_transparent,
-									  BOOL pick_rigged,
-                                      BOOL pick_unselectable,
-									  S32* face_hit,
-									  LLVector4a* intersection,
-									  LLVector2* tex_coord,
-									  LLVector4a* normal,
-									  LLVector4a* tangent)
-{
-	if (isSelf() && !gAgent.needsRenderAvatar())
-	{
-		return NULL;
-	}
-
-	LLViewerObject* hit = NULL;
-
-	if (lineSegmentBoundingBox(start, end))
-	{
-		LLVector4a local_end = end;
-		LLVector4a local_intersection;
-        local_intersection.clear();
-
-		for (const auto& attach_pair : mAttachmentPoints)
-		{
-			LLViewerJointAttachment* attachment = attach_pair.second;
-			if (!attachment) continue;
-
-			for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-			{
-				if (attached_object->lineSegmentIntersect(start, local_end, face, pick_transparent, pick_rigged, pick_unselectable, face_hit, &local_intersection, tex_coord, normal, tangent))
-				{
-					local_end = local_intersection;
-					if (intersection)
-					{
-						*intersection = local_intersection;
-					}
-					
-					hit = attached_object;
-				}
-			}
-		}
-	}
-		
-	return hit;
-}
-
-
-LLVOAvatar* LLVOAvatar::asAvatar()
-{
-	return this;
-}
 
-//-----------------------------------------------------------------------------
-// LLVOAvatar::startDefaultMotions()
-//-----------------------------------------------------------------------------
-void LLVOAvatar::startDefaultMotions()
-{
-	//-------------------------------------------------------------------------
-	// start default motions
-	//-------------------------------------------------------------------------
-	startMotion( ANIM_AGENT_HEAD_ROT );
-	startMotion( ANIM_AGENT_EYE );
-	startMotion( ANIM_AGENT_BODY_NOISE );
-	startMotion( ANIM_AGENT_BREATHE_ROT );
-	startMotion( ANIM_AGENT_PHYSICS_MOTION );
-	startMotion( ANIM_AGENT_HAND_MOTION );
-	startMotion( ANIM_AGENT_PELVIS_FIX );
-
-	//-------------------------------------------------------------------------
-	// restart any currently active motions
-	//-------------------------------------------------------------------------
-	processAnimationStateChanges();
-}
+    if (lineSegmentBoundingBox(start, end))
+    {
+        for (S32 i = 0; i < mNumCollisionVolumes; ++i)
+        {
+            mCollisionVolumes[i].updateWorldMatrix();
 
-//-----------------------------------------------------------------------------
-// LLVOAvatar::buildCharacter()
-// Deferred initialization and rebuild of the avatar.
-//-----------------------------------------------------------------------------
-// virtual
-void LLVOAvatar::buildCharacter()
-{
-	LLAvatarAppearance::buildCharacter();
+            LLMatrix4a mat = mCollisionVolumes[i].getXform()->getWorldMatrix();
+            LLMatrix4a inverse = mat;
+            inverse.invert();
+            LLMatrix4a norm_mat = inverse;
+            norm_mat.transpose();
 
-	// Not done building yet; more to do.
-	mIsBuilt = FALSE;
+            LLVector4a p1, p2;
+            inverse.affineTransform(start,p1);  //Might need to use perspectiveTransform here.
+            inverse.affineTransform(end,p2);
 
-	//-------------------------------------------------------------------------
-	// set head offset from pelvis
-	//-------------------------------------------------------------------------
-	updateHeadOffset();
+            LLVector3 position;
+            LLVector3 norm;
 
-	//-------------------------------------------------------------------------
-	// initialize lip sync morph pointers
-	//-------------------------------------------------------------------------
-	mOohMorph     = getVisualParam( "Lipsync_Ooh" );
-	mAahMorph     = getVisualParam( "Lipsync_Aah" );
+            if (linesegment_sphere(LLVector3(p1.getF32ptr()), LLVector3(p2.getF32ptr()), LLVector3(0,0,0), 1.f, position, norm))
+            {
+                if (intersection)
+                {
+                    LLVector4a res_pos;
+                    res_pos.load3(position.mV);
+                    mat.affineTransform(res_pos,res_pos);
+                    *intersection = res_pos;
+                }
 
-	// If we don't have the Ooh morph, use the Kiss morph
-	if (!mOohMorph)
-	{
-		LL_WARNS() << "Missing 'Ooh' morph for lipsync, using fallback." << LL_ENDL;
-		mOohMorph = getVisualParam( "Express_Kiss" );
-	}
+                if (normal)
+                {
+                    LLVector4a res_norm;
+                    res_norm.load3(norm.mV);
+                    res_norm.normalize3fast();
+                    norm_mat.perspectiveTransform(res_norm,res_norm);
+                    *normal = res_norm;
+                }
 
-	// If we don't have the Aah morph, use the Open Mouth morph
-	if (!mAahMorph)
-	{
-		LL_WARNS() << "Missing 'Aah' morph for lipsync, using fallback." << LL_ENDL;
-		mAahMorph = getVisualParam( "Express_Open_Mouth" );
-	}
+                return TRUE;
+            }
+        }
 
-    // Currently disabled for control avatars (animated objects), enabled for all others.
+        if (isSelf())
+        {
+            for (const auto& attach_pair : mAttachmentPoints)
+            {
+                LLViewerJointAttachment* attachment = attach_pair.second;
+                if (!attachment) continue;
+                for (LLViewerObject* attached_object : attachment->mAttachedObjects)
+                {
+                    if (attached_object && !attached_object->isDead() && attachment->getValid())
+                    {
+                        LLDrawable* drawable = attached_object->mDrawable;
+                        if (drawable->isState(LLDrawable::RIGGED))
+                        { //regenerate octree for rigged attachment
+                            gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_RIGGED);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    LLVector4a position;
+    if (mNameText.notNull() && mNameText->lineSegmentIntersect(start, end, position))
+    {
+        if (intersection)
+        {
+            *intersection = position;
+        }
+
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
+// virtual
+LLViewerObject* LLVOAvatar::lineSegmentIntersectRiggedAttachments(const LLVector4a& start, const LLVector4a& end,
+                                      S32 face,
+                                      BOOL pick_transparent,
+                                      BOOL pick_rigged,
+                                      BOOL pick_unselectable,
+                                      S32* face_hit,
+                                      LLVector4a* intersection,
+                                      LLVector2* tex_coord,
+                                      LLVector4a* normal,
+                                      LLVector4a* tangent)
+{
+    if (isSelf() && !gAgent.needsRenderAvatar())
+    {
+        return NULL;
+    }
+
+    LLViewerObject* hit = NULL;
+
+    if (lineSegmentBoundingBox(start, end))
+    {
+        LLVector4a local_end = end;
+        LLVector4a local_intersection;
+        local_intersection.clear();
+
+        for (const auto& attach_pair : mAttachmentPoints)
+        {
+            LLViewerJointAttachment* attachment = attach_pair.second;
+            if (!attachment) continue;
+
+            for (LLViewerObject* attached_object : attachment->mAttachedObjects)
+            {
+                if (attached_object->lineSegmentIntersect(start, local_end, face, pick_transparent, pick_rigged, pick_unselectable, face_hit, &local_intersection, tex_coord, normal, tangent))
+                {
+                    local_end = local_intersection;
+                    if (intersection)
+                    {
+                        *intersection = local_intersection;
+                    }
+
+                    hit = attached_object;
+                }
+            }
+        }
+    }
+
+    return hit;
+}
+
+
+LLVOAvatar* LLVOAvatar::asAvatar()
+{
+    return this;
+}
+
+//-----------------------------------------------------------------------------
+// LLVOAvatar::startDefaultMotions()
+//-----------------------------------------------------------------------------
+void LLVOAvatar::startDefaultMotions()
+{
+    //-------------------------------------------------------------------------
+    // start default motions
+    //-------------------------------------------------------------------------
+    startMotion( ANIM_AGENT_HEAD_ROT );
+    startMotion( ANIM_AGENT_EYE );
+    startMotion( ANIM_AGENT_BODY_NOISE );
+    startMotion( ANIM_AGENT_BREATHE_ROT );
+    startMotion( ANIM_AGENT_PHYSICS_MOTION );
+    startMotion( ANIM_AGENT_HAND_MOTION );
+    startMotion( ANIM_AGENT_PELVIS_FIX );
+
+    //-------------------------------------------------------------------------
+    // restart any currently active motions
+    //-------------------------------------------------------------------------
+    processAnimationStateChanges();
+}
+
+//-----------------------------------------------------------------------------
+// LLVOAvatar::buildCharacter()
+// Deferred initialization and rebuild of the avatar.
+//-----------------------------------------------------------------------------
+// virtual
+void LLVOAvatar::buildCharacter()
+{
+    LLAvatarAppearance::buildCharacter();
+
+    // Not done building yet; more to do.
+    mIsBuilt = FALSE;
+
+    //-------------------------------------------------------------------------
+    // set head offset from pelvis
+    //-------------------------------------------------------------------------
+    updateHeadOffset();
+
+    //-------------------------------------------------------------------------
+    // initialize lip sync morph pointers
+    //-------------------------------------------------------------------------
+    mOohMorph     = getVisualParam( "Lipsync_Ooh" );
+    mAahMorph     = getVisualParam( "Lipsync_Aah" );
+
+    // If we don't have the Ooh morph, use the Kiss morph
+    if (!mOohMorph)
+    {
+        LL_WARNS() << "Missing 'Ooh' morph for lipsync, using fallback." << LL_ENDL;
+        mOohMorph = getVisualParam( "Express_Kiss" );
+    }
+
+    // If we don't have the Aah morph, use the Open Mouth morph
+    if (!mAahMorph)
+    {
+        LL_WARNS() << "Missing 'Aah' morph for lipsync, using fallback." << LL_ENDL;
+        mAahMorph = getVisualParam( "Express_Open_Mouth" );
+    }
+
+    // Currently disabled for control avatars (animated objects), enabled for all others.
     if (mEnableDefaultMotions)
     {
-	startDefaultMotions();
+    startDefaultMotions();
     }
 
-	//-------------------------------------------------------------------------
-	// restart any currently active motions
-	//-------------------------------------------------------------------------
-	processAnimationStateChanges();
+    //-------------------------------------------------------------------------
+    // restart any currently active motions
+    //-------------------------------------------------------------------------
+    processAnimationStateChanges();
 
-	mIsBuilt = TRUE;
-	stop_glerror();
+    mIsBuilt = TRUE;
+    stop_glerror();
 
-	mMeshValid = TRUE;
+    mMeshValid = TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -2042,24 +2042,24 @@ void LLVOAvatar::buildCharacter()
 //-----------------------------------------------------------------------------
 void LLVOAvatar::resetVisualParams()
 {
-	// Skeletal params
-	{
-		for (LLViewerVisualParamInfo* vparam : sAvatarXmlInfo->mSkeletalDistortionInfoList)
-		{
-			LLPolySkeletalDistortionInfo *info = static_cast<LLPolySkeletalDistortionInfo*>(vparam);
-			LLPolySkeletalDistortion *param = static_cast<LLPolySkeletalDistortion*>(getVisualParam(info->getID()));
+    // Skeletal params
+    {
+        for (LLViewerVisualParamInfo* vparam : sAvatarXmlInfo->mSkeletalDistortionInfoList)
+        {
+            LLPolySkeletalDistortionInfo *info = static_cast<LLPolySkeletalDistortionInfo*>(vparam);
+            LLPolySkeletalDistortion *param = static_cast<LLPolySkeletalDistortion*>(getVisualParam(info->getID()));
             *param = LLPolySkeletalDistortion(this);
             llassert(param);
-			if (!param->setInfo(info))
-			{
-				llassert(false);
-			}			
-		}
-	}
-
-	// Driver parameters
-	for (LLDriverParamInfo* info : sAvatarXmlInfo->mDriverInfoList)
-	{
+            if (!param->setInfo(info))
+            {
+                llassert(false);
+            }
+        }
+    }
+
+    // Driver parameters
+    for (LLDriverParamInfo* info : sAvatarXmlInfo->mDriverInfoList)
+    {
         LLDriverParam *param = static_cast<LLDriverParam*>(getVisualParam(info->getID()));
         LLDriverParam::entry_list_t driven_list = param->getDrivenList();
         *param = LLDriverParam(this);
@@ -2067,41 +2067,41 @@ void LLVOAvatar::resetVisualParams()
         if (!param->setInfo(info))
         {
             llassert(false);
-        }			
+        }
         param->setDrivenList(std::move(driven_list));
-	}
+    }
 }
 
 void LLVOAvatar::applyDefaultParams()
 {
-	// These are params from avs with newly created copies of shape,
-	// skin, hair, eyes, plus gender set as noted. Run arche_tool.py
-	// to get params from some other xml appearance dump.
-	std::map<S32, U8> male_params = {
-		{1,33}, {2,61}, {4,85}, {5,23}, {6,58}, {7,127}, {8,63}, {10,85}, {11,63}, {12,42}, {13,0}, {14,85}, {15,63}, {16,36}, {17,85}, {18,95}, {19,153}, {20,63}, {21,34}, {22,0}, {23,63}, {24,109}, {25,88}, {27,132}, {31,63}, {33,136}, {34,81}, {35,85}, {36,103}, {37,136}, {38,127}, {80,255}, {93,203}, {98,0}, {99,0}, {105,127}, {108,0}, {110,0}, {111,127}, {112,0}, {113,0}, {114,127}, {115,0}, {116,0}, {117,0}, {119,127}, {130,114}, {131,127}, {132,99}, {133,63}, {134,127}, {135,140}, {136,127}, {137,127}, {140,0}, {141,0}, {142,0}, {143,191}, {150,0}, {155,104}, {157,0}, {162,0}, {163,0}, {165,0}, {166,0}, {167,0}, {168,0}, {169,0}, {177,0}, {181,145}, {182,216}, {183,133}, {184,0}, {185,127}, {192,0}, {193,127}, {196,170}, {198,0}, {503,0}, {505,127}, {506,127}, {507,109}, {508,85}, {513,127}, {514,127}, {515,63}, {517,85}, {518,42}, {603,100}, {604,216}, {605,214}, {606,204}, {607,204}, {608,204}, {609,51}, {616,25}, {617,89}, {619,76}, {624,204}, {625,0}, {629,127}, {637,0}, {638,0}, {646,144}, {647,85}, {649,127}, {650,132}, {652,127}, {653,85}, {654,0}, {656,127}, {659,127}, {662,127}, {663,127}, {664,127}, {665,127}, {674,59}, {675,127}, {676,85}, {678,127}, {682,127}, {683,106}, {684,47}, {685,79}, {690,127}, {692,127}, {693,204}, {700,63}, {701,0}, {702,0}, {703,0}, {704,0}, {705,127}, {706,127}, {707,0}, {708,0}, {709,0}, {710,0}, {711,127}, {712,0}, {713,159}, {714,0}, {715,0}, {750,178}, {752,127}, {753,36}, {754,85}, {755,131}, {756,127}, {757,127}, {758,127}, {759,153}, {760,95}, {762,0}, {763,140}, {764,74}, {765,27}, {769,127}, {773,127}, {775,0}, {779,214}, {780,204}, {781,198}, {785,0}, {789,0}, {795,63}, {796,30}, {799,127}, {800,226}, {801,255}, {802,198}, {803,255}, {804,255}, {805,255}, {806,255}, {807,255}, {808,255}, {812,255}, {813,255}, {814,255}, {815,204}, {816,0}, {817,255}, {818,255}, {819,255}, {820,255}, {821,255}, {822,255}, {823,255}, {824,255}, {825,255}, {826,255}, {827,255}, {828,0}, {829,255}, {830,255}, {834,255}, {835,255}, {836,255}, {840,0}, {841,127}, {842,127}, {844,255}, {848,25}, {858,100}, {859,255}, {860,255}, {861,255}, {862,255}, {863,84}, {868,0}, {869,0}, {877,0}, {879,51}, {880,132}, {921,255}, {922,255}, {923,255}, {10000,0}, {10001,0}, {10002,25}, {10003,0}, {10004,25}, {10005,23}, {10006,51}, {10007,0}, {10008,25}, {10009,23}, {10010,51}, {10011,0}, {10012,0}, {10013,25}, {10014,0}, {10015,25}, {10016,23}, {10017,51}, {10018,0}, {10019,0}, {10020,25}, {10021,0}, {10022,25}, {10023,23}, {10024,51}, {10025,0}, {10026,25}, {10027,23}, {10028,51}, {10029,0}, {10030,25}, {10031,23}, {10032,51}, {11000,1}, {11001,127}
-	};
-	std::map<S32, U8> female_params = {
-		{1,33}, {2,61}, {4,85}, {5,23}, {6,58}, {7,127}, {8,63}, {10,85}, {11,63}, {12,42}, {13,0}, {14,85}, {15,63}, {16,36}, {17,85}, {18,95}, {19,153}, {20,63}, {21,34}, {22,0}, {23,63}, {24,109}, {25,88}, {27,132}, {31,63}, {33,136}, {34,81}, {35,85}, {36,103}, {37,136}, {38,127}, {80,0}, {93,203}, {98,0}, {99,0}, {105,127}, {108,0}, {110,0}, {111,127}, {112,0}, {113,0}, {114,127}, {115,0}, {116,0}, {117,0}, {119,127}, {130,114}, {131,127}, {132,99}, {133,63}, {134,127}, {135,140}, {136,127}, {137,127}, {140,0}, {141,0}, {142,0}, {143,191}, {150,0}, {155,104}, {157,0}, {162,0}, {163,0}, {165,0}, {166,0}, {167,0}, {168,0}, {169,0}, {177,0}, {181,145}, {182,216}, {183,133}, {184,0}, {185,127}, {192,0}, {193,127}, {196,170}, {198,0}, {503,0}, {505,127}, {506,127}, {507,109}, {508,85}, {513,127}, {514,127}, {515,63}, {517,85}, {518,42}, {603,100}, {604,216}, {605,214}, {606,204}, {607,204}, {608,204}, {609,51}, {616,25}, {617,89}, {619,76}, {624,204}, {625,0}, {629,127}, {637,0}, {638,0}, {646,144}, {647,85}, {649,127}, {650,132}, {652,127}, {653,85}, {654,0}, {656,127}, {659,127}, {662,127}, {663,127}, {664,127}, {665,127}, {674,59}, {675,127}, {676,85}, {678,127}, {682,127}, {683,106}, {684,47}, {685,79}, {690,127}, {692,127}, {693,204}, {700,63}, {701,0}, {702,0}, {703,0}, {704,0}, {705,127}, {706,127}, {707,0}, {708,0}, {709,0}, {710,0}, {711,127}, {712,0}, {713,159}, {714,0}, {715,0}, {750,178}, {752,127}, {753,36}, {754,85}, {755,131}, {756,127}, {757,127}, {758,127}, {759,153}, {760,95}, {762,0}, {763,140}, {764,74}, {765,27}, {769,127}, {773,127}, {775,0}, {779,214}, {780,204}, {781,198}, {785,0}, {789,0}, {795,63}, {796,30}, {799,127}, {800,226}, {801,255}, {802,198}, {803,255}, {804,255}, {805,255}, {806,255}, {807,255}, {808,255}, {812,255}, {813,255}, {814,255}, {815,204}, {816,0}, {817,255}, {818,255}, {819,255}, {820,255}, {821,255}, {822,255}, {823,255}, {824,255}, {825,255}, {826,255}, {827,255}, {828,0}, {829,255}, {830,255}, {834,255}, {835,255}, {836,255}, {840,0}, {841,127}, {842,127}, {844,255}, {848,25}, {858,100}, {859,255}, {860,255}, {861,255}, {862,255}, {863,84}, {868,0}, {869,0}, {877,0}, {879,51}, {880,132}, {921,255}, {922,255}, {923,255}, {10000,0}, {10001,0}, {10002,25}, {10003,0}, {10004,25}, {10005,23}, {10006,51}, {10007,0}, {10008,25}, {10009,23}, {10010,51}, {10011,0}, {10012,0}, {10013,25}, {10014,0}, {10015,25}, {10016,23}, {10017,51}, {10018,0}, {10019,0}, {10020,25}, {10021,0}, {10022,25}, {10023,23}, {10024,51}, {10025,0}, {10026,25}, {10027,23}, {10028,51}, {10029,0}, {10030,25}, {10031,23}, {10032,51}, {11000,1}, {11001,127}
-	};
-	std::map<S32, U8> *params = NULL;
-	if (getSex() == SEX_MALE)
-		params = &male_params;
-	else
-		params = &female_params;
-			
-	for( auto it = params->begin(); it != params->end(); ++it)
-	{
-		LLVisualParam* param = getVisualParam(it->first);
-		if( !param )
-		{
-			// invalid id
-			break;
-		}
-
-		U8 value = it->second;
-		F32 newWeight = U8_to_F32(value, param->getMinWeight(), param->getMaxWeight());
-		param->setWeight(newWeight);
-	}
+    // These are params from avs with newly created copies of shape,
+    // skin, hair, eyes, plus gender set as noted. Run arche_tool.py
+    // to get params from some other xml appearance dump.
+    std::map<S32, U8> male_params = {
+        {1,33}, {2,61}, {4,85}, {5,23}, {6,58}, {7,127}, {8,63}, {10,85}, {11,63}, {12,42}, {13,0}, {14,85}, {15,63}, {16,36}, {17,85}, {18,95}, {19,153}, {20,63}, {21,34}, {22,0}, {23,63}, {24,109}, {25,88}, {27,132}, {31,63}, {33,136}, {34,81}, {35,85}, {36,103}, {37,136}, {38,127}, {80,255}, {93,203}, {98,0}, {99,0}, {105,127}, {108,0}, {110,0}, {111,127}, {112,0}, {113,0}, {114,127}, {115,0}, {116,0}, {117,0}, {119,127}, {130,114}, {131,127}, {132,99}, {133,63}, {134,127}, {135,140}, {136,127}, {137,127}, {140,0}, {141,0}, {142,0}, {143,191}, {150,0}, {155,104}, {157,0}, {162,0}, {163,0}, {165,0}, {166,0}, {167,0}, {168,0}, {169,0}, {177,0}, {181,145}, {182,216}, {183,133}, {184,0}, {185,127}, {192,0}, {193,127}, {196,170}, {198,0}, {503,0}, {505,127}, {506,127}, {507,109}, {508,85}, {513,127}, {514,127}, {515,63}, {517,85}, {518,42}, {603,100}, {604,216}, {605,214}, {606,204}, {607,204}, {608,204}, {609,51}, {616,25}, {617,89}, {619,76}, {624,204}, {625,0}, {629,127}, {637,0}, {638,0}, {646,144}, {647,85}, {649,127}, {650,132}, {652,127}, {653,85}, {654,0}, {656,127}, {659,127}, {662,127}, {663,127}, {664,127}, {665,127}, {674,59}, {675,127}, {676,85}, {678,127}, {682,127}, {683,106}, {684,47}, {685,79}, {690,127}, {692,127}, {693,204}, {700,63}, {701,0}, {702,0}, {703,0}, {704,0}, {705,127}, {706,127}, {707,0}, {708,0}, {709,0}, {710,0}, {711,127}, {712,0}, {713,159}, {714,0}, {715,0}, {750,178}, {752,127}, {753,36}, {754,85}, {755,131}, {756,127}, {757,127}, {758,127}, {759,153}, {760,95}, {762,0}, {763,140}, {764,74}, {765,27}, {769,127}, {773,127}, {775,0}, {779,214}, {780,204}, {781,198}, {785,0}, {789,0}, {795,63}, {796,30}, {799,127}, {800,226}, {801,255}, {802,198}, {803,255}, {804,255}, {805,255}, {806,255}, {807,255}, {808,255}, {812,255}, {813,255}, {814,255}, {815,204}, {816,0}, {817,255}, {818,255}, {819,255}, {820,255}, {821,255}, {822,255}, {823,255}, {824,255}, {825,255}, {826,255}, {827,255}, {828,0}, {829,255}, {830,255}, {834,255}, {835,255}, {836,255}, {840,0}, {841,127}, {842,127}, {844,255}, {848,25}, {858,100}, {859,255}, {860,255}, {861,255}, {862,255}, {863,84}, {868,0}, {869,0}, {877,0}, {879,51}, {880,132}, {921,255}, {922,255}, {923,255}, {10000,0}, {10001,0}, {10002,25}, {10003,0}, {10004,25}, {10005,23}, {10006,51}, {10007,0}, {10008,25}, {10009,23}, {10010,51}, {10011,0}, {10012,0}, {10013,25}, {10014,0}, {10015,25}, {10016,23}, {10017,51}, {10018,0}, {10019,0}, {10020,25}, {10021,0}, {10022,25}, {10023,23}, {10024,51}, {10025,0}, {10026,25}, {10027,23}, {10028,51}, {10029,0}, {10030,25}, {10031,23}, {10032,51}, {11000,1}, {11001,127}
+    };
+    std::map<S32, U8> female_params = {
+        {1,33}, {2,61}, {4,85}, {5,23}, {6,58}, {7,127}, {8,63}, {10,85}, {11,63}, {12,42}, {13,0}, {14,85}, {15,63}, {16,36}, {17,85}, {18,95}, {19,153}, {20,63}, {21,34}, {22,0}, {23,63}, {24,109}, {25,88}, {27,132}, {31,63}, {33,136}, {34,81}, {35,85}, {36,103}, {37,136}, {38,127}, {80,0}, {93,203}, {98,0}, {99,0}, {105,127}, {108,0}, {110,0}, {111,127}, {112,0}, {113,0}, {114,127}, {115,0}, {116,0}, {117,0}, {119,127}, {130,114}, {131,127}, {132,99}, {133,63}, {134,127}, {135,140}, {136,127}, {137,127}, {140,0}, {141,0}, {142,0}, {143,191}, {150,0}, {155,104}, {157,0}, {162,0}, {163,0}, {165,0}, {166,0}, {167,0}, {168,0}, {169,0}, {177,0}, {181,145}, {182,216}, {183,133}, {184,0}, {185,127}, {192,0}, {193,127}, {196,170}, {198,0}, {503,0}, {505,127}, {506,127}, {507,109}, {508,85}, {513,127}, {514,127}, {515,63}, {517,85}, {518,42}, {603,100}, {604,216}, {605,214}, {606,204}, {607,204}, {608,204}, {609,51}, {616,25}, {617,89}, {619,76}, {624,204}, {625,0}, {629,127}, {637,0}, {638,0}, {646,144}, {647,85}, {649,127}, {650,132}, {652,127}, {653,85}, {654,0}, {656,127}, {659,127}, {662,127}, {663,127}, {664,127}, {665,127}, {674,59}, {675,127}, {676,85}, {678,127}, {682,127}, {683,106}, {684,47}, {685,79}, {690,127}, {692,127}, {693,204}, {700,63}, {701,0}, {702,0}, {703,0}, {704,0}, {705,127}, {706,127}, {707,0}, {708,0}, {709,0}, {710,0}, {711,127}, {712,0}, {713,159}, {714,0}, {715,0}, {750,178}, {752,127}, {753,36}, {754,85}, {755,131}, {756,127}, {757,127}, {758,127}, {759,153}, {760,95}, {762,0}, {763,140}, {764,74}, {765,27}, {769,127}, {773,127}, {775,0}, {779,214}, {780,204}, {781,198}, {785,0}, {789,0}, {795,63}, {796,30}, {799,127}, {800,226}, {801,255}, {802,198}, {803,255}, {804,255}, {805,255}, {806,255}, {807,255}, {808,255}, {812,255}, {813,255}, {814,255}, {815,204}, {816,0}, {817,255}, {818,255}, {819,255}, {820,255}, {821,255}, {822,255}, {823,255}, {824,255}, {825,255}, {826,255}, {827,255}, {828,0}, {829,255}, {830,255}, {834,255}, {835,255}, {836,255}, {840,0}, {841,127}, {842,127}, {844,255}, {848,25}, {858,100}, {859,255}, {860,255}, {861,255}, {862,255}, {863,84}, {868,0}, {869,0}, {877,0}, {879,51}, {880,132}, {921,255}, {922,255}, {923,255}, {10000,0}, {10001,0}, {10002,25}, {10003,0}, {10004,25}, {10005,23}, {10006,51}, {10007,0}, {10008,25}, {10009,23}, {10010,51}, {10011,0}, {10012,0}, {10013,25}, {10014,0}, {10015,25}, {10016,23}, {10017,51}, {10018,0}, {10019,0}, {10020,25}, {10021,0}, {10022,25}, {10023,23}, {10024,51}, {10025,0}, {10026,25}, {10027,23}, {10028,51}, {10029,0}, {10030,25}, {10031,23}, {10032,51}, {11000,1}, {11001,127}
+    };
+    std::map<S32, U8> *params = NULL;
+    if (getSex() == SEX_MALE)
+        params = &male_params;
+    else
+        params = &female_params;
+
+    for( auto it = params->begin(); it != params->end(); ++it)
+    {
+        LLVisualParam* param = getVisualParam(it->first);
+        if( !param )
+        {
+            // invalid id
+            break;
+        }
+
+        U8 value = it->second;
+        F32 newWeight = U8_to_F32(value, param->getMinWeight(), param->getMaxWeight());
+        param->setWeight(newWeight);
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -2116,13 +2116,13 @@ void LLVOAvatar::resetSkeleton(bool reset_animations)
         return;
     }
 
-	//BD - We need to clear posing here otherwise we'll crash.
-	LLMotion* pose_motion = findMotion(ANIM_BD_POSING_MOTION);
-	if (pose_motion)
-	{
-		gAgent.clearPosing();
-		removeMotion(ANIM_BD_POSING_MOTION);
-	}
+    //BD - We need to clear posing here otherwise we'll crash.
+    LLMotion* pose_motion = findMotion(ANIM_BD_POSING_MOTION);
+    if (pose_motion)
+    {
+        gAgent.clearPosing();
+        removeMotion(ANIM_BD_POSING_MOTION);
+    }
 
     // Save mPelvis state
     //LLVector3 pelvis_pos = getJoint("mPelvis")->getPosition();
@@ -2135,10 +2135,10 @@ void LLVOAvatar::resetSkeleton(bool reset_animations)
     // just to get the right scale for the collision volumes, because
     // this will be used in setting the mJointScales for the
     // LLPolySkeletalDistortions of which the CVs are children.
-	if( !buildSkeleton(sAvatarSkeletonInfo) )
+    if( !buildSkeleton(sAvatarSkeletonInfo) )
     {
         LL_ERRS() << "Error resetting skeleton" << LL_ENDL;
-	}
+    }
 
     // Reset some params to default state, without propagating changes downstream.
     resetVisualParams();
@@ -2146,10 +2146,10 @@ void LLVOAvatar::resetSkeleton(bool reset_animations)
     // Now we have to reset the skeleton again, because its state
     // got clobbered by the resetVisualParams() calls
     // above.
-	if( !buildSkeleton(sAvatarSkeletonInfo) )
+    if( !buildSkeleton(sAvatarSkeletonInfo) )
     {
         LL_ERRS() << "Error resetting skeleton" << LL_ENDL;
-	}
+    }
 
     // Reset attachment points
     // BuildSkeleton only does bones and CVs but we still need to reinit huds
@@ -2158,7 +2158,7 @@ void LLVOAvatar::resetSkeleton(bool reset_animations)
     initAttachmentPoints(ignore_hud_joints);
 
     // Fix up collision volumes
-    for (LLVisualParam *param = getFirstVisualParam(); 
+    for (LLVisualParam *param = getFirstVisualParam();
          param;
          param = getNextVisualParam())
     {
@@ -2174,30 +2174,30 @@ void LLVOAvatar::resetSkeleton(bool reset_animations)
     }
 
     // Reset tweakable params to preserved state
-	if (getOverallAppearance() == AOA_NORMAL)
-	{
-		if (mLastProcessedAppearance)
-		{
-			bool slam_params = true;
-			applyParsedAppearanceMessage(*mLastProcessedAppearance, slam_params);
-		}
-	}
-	else
-	{
-		// Stripped down approximation of
-		// applyParsedAppearanceMessage, but with alternative default
-		// (jellydoll) params
-		setCompositeUpdatesEnabled( FALSE );
-		gPipeline.markGLRebuild(this);
-		applyDefaultParams();
-		setCompositeUpdatesEnabled( TRUE );
-		updateMeshTextures();
-		updateMeshVisibility();
-	}
+    if (getOverallAppearance() == AOA_NORMAL)
+    {
+        if (mLastProcessedAppearance)
+        {
+            bool slam_params = true;
+            applyParsedAppearanceMessage(*mLastProcessedAppearance, slam_params);
+        }
+    }
+    else
+    {
+        // Stripped down approximation of
+        // applyParsedAppearanceMessage, but with alternative default
+        // (jellydoll) params
+        setCompositeUpdatesEnabled( FALSE );
+        gPipeline.markGLRebuild(this);
+        applyDefaultParams();
+        setCompositeUpdatesEnabled( TRUE );
+        updateMeshTextures();
+        updateMeshVisibility();
+    }
     updateVisualParams();
 
     // Restore attachment pos overrides
-	updateAttachmentOverrides();
+    updateAttachmentOverrides();
 
     // Animations
     if (reset_animations)
@@ -2215,7 +2215,7 @@ void LLVOAvatar::resetSkeleton(bool reset_animations)
             resetAnimations();
         }
     }
-    
+
     LL_DEBUGS("Avatar") << avString() << " reset ends" << LL_ENDL;
 }
 
@@ -2224,44 +2224,44 @@ void LLVOAvatar::resetSkeleton(bool reset_animations)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::releaseMeshData()
 {
-	if (sInstances.size() < AVATAR_RELEASE_THRESHOLD || isUIAvatar())
-	{
-		return;
-	}
-
-	// cleanup mesh data
-	for (LLAvatarJoint* joint : mMeshLOD)
-	{
-		joint->setValid(FALSE, TRUE);
-	}
-
-	//cleanup data
-	if (mDrawable.notNull())
-	{
-		LLFace* facep = mDrawable->getFace(0);
-		if (facep)
-		{
-		facep->setSize(0, 0);
-		for(S32 i = mNumInitFaces ; i < mDrawable->getNumFaces(); i++)
-		{
-			facep = mDrawable->getFace(i);
-				if (facep)
-				{
-			facep->setSize(0, 0);
-		}
-	}
-		}
-	}
-	
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		if (attachment && !attachment->getIsHUDAttachment())
-		{
-			attachment->setAttachmentVisibility(FALSE);
-		}
-	}
-	mMeshValid = FALSE;
+    if (sInstances.size() < AVATAR_RELEASE_THRESHOLD || isUIAvatar())
+    {
+        return;
+    }
+
+    // cleanup mesh data
+    for (LLAvatarJoint* joint : mMeshLOD)
+    {
+        joint->setValid(FALSE, TRUE);
+    }
+
+    //cleanup data
+    if (mDrawable.notNull())
+    {
+        LLFace* facep = mDrawable->getFace(0);
+        if (facep)
+        {
+        facep->setSize(0, 0);
+        for(S32 i = mNumInitFaces ; i < mDrawable->getNumFaces(); i++)
+        {
+            facep = mDrawable->getFace(i);
+                if (facep)
+                {
+            facep->setSize(0, 0);
+        }
+    }
+        }
+    }
+
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        if (attachment && !attachment->getIsHUDAttachment())
+        {
+            attachment->setAttachmentVisibility(FALSE);
+        }
+    }
+    mMeshValid = FALSE;
 }
 
 //-----------------------------------------------------------------------------
@@ -2270,27 +2270,27 @@ void LLVOAvatar::releaseMeshData()
 // virtual
 void LLVOAvatar::restoreMeshData()
 {
-	llassert(!isSelf());
+    llassert(!isSelf());
     if (mDrawable.isNull())
     {
         return;
     }
-	
-	//LL_INFOS() << "Restoring" << LL_ENDL;
-	mMeshValid = TRUE;
-	updateJointLODs();
 
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		if (!attachment->getIsHUDAttachment())
-		{
-			attachment->setAttachmentVisibility(TRUE);
-		}
-	}
+    //LL_INFOS() << "Restoring" << LL_ENDL;
+    mMeshValid = TRUE;
+    updateJointLODs();
+
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        if (!attachment->getIsHUDAttachment())
+        {
+            attachment->setAttachmentVisibility(TRUE);
+        }
+    }
 
-	// force mesh update as LOD might not have changed to trigger this
-	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
+    // force mesh update as LOD might not have changed to trigger this
+    gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
 }
 
 //-----------------------------------------------------------------------------
@@ -2298,149 +2298,149 @@ void LLVOAvatar::restoreMeshData()
 //-----------------------------------------------------------------------------
 void LLVOAvatar::updateMeshData()
 {
-	if (mDrawable.notNull())
-	{
-		stop_glerror();
-
-		S32 f_num = 0 ;
-		const U32 VERTEX_NUMBER_THRESHOLD = 128 ;//small number of this means each part of an avatar has its own vertex buffer.
-		const S32 num_parts = mMeshLOD.size();
-
-		// this order is determined by number of LODS
-		// if a mesh earlier in this list changed LODs while a later mesh doesn't,
-		// the later mesh's index offset will be inaccurate
-		for(S32 part_index = 0 ; part_index < num_parts ;)
-		{
-			S32 j = part_index ;
-			U32 last_v_num = 0, num_vertices = 0 ;
-			U32 last_i_num = 0, num_indices = 0 ;
-
-			while(part_index < num_parts && num_vertices < VERTEX_NUMBER_THRESHOLD)
-			{
-				last_v_num = num_vertices ;
-				last_i_num = num_indices ;
-
-				LLViewerJoint* part_mesh = getViewerJoint(part_index++);
-				if (part_mesh)
-				{
-					part_mesh->updateFaceSizes(num_vertices, num_indices, mAdjustedPixelArea);
-				}
-			}
-			if(num_vertices < 1)//skip empty meshes
-			{
-				continue ;
-			}
-			if(last_v_num > 0)//put the last inserted part into next vertex buffer.
-			{
-				num_vertices = last_v_num ;
-				num_indices = last_i_num ;	
-				part_index-- ;
-			}
-		
-			LLFace* facep = NULL;
-			if(f_num < mDrawable->getNumFaces()) 
-			{
-				facep = mDrawable->getFace(f_num);
-			}
-			else
-			{
-				facep = mDrawable->getFace(0);
-				if (facep)
-				{
-					facep = mDrawable->addFace(facep->getPool(), facep->getTexture()) ;
-				}
-			}
-			if (!facep) continue;
-			
-			// resize immediately
-			facep->setSize(num_vertices, num_indices);
-
-			bool terse_update = false;
-
-			facep->setGeomIndex(0);
-			facep->setIndicesIndex(0);
-		
-			LLVertexBuffer* buff = facep->getVertexBuffer();
-			if(!facep->getVertexBuffer())
-			{
+    if (mDrawable.notNull())
+    {
+        stop_glerror();
+
+        S32 f_num = 0 ;
+        const U32 VERTEX_NUMBER_THRESHOLD = 128 ;//small number of this means each part of an avatar has its own vertex buffer.
+        const S32 num_parts = mMeshLOD.size();
+
+        // this order is determined by number of LODS
+        // if a mesh earlier in this list changed LODs while a later mesh doesn't,
+        // the later mesh's index offset will be inaccurate
+        for(S32 part_index = 0 ; part_index < num_parts ;)
+        {
+            S32 j = part_index ;
+            U32 last_v_num = 0, num_vertices = 0 ;
+            U32 last_i_num = 0, num_indices = 0 ;
+
+            while(part_index < num_parts && num_vertices < VERTEX_NUMBER_THRESHOLD)
+            {
+                last_v_num = num_vertices ;
+                last_i_num = num_indices ;
+
+                LLViewerJoint* part_mesh = getViewerJoint(part_index++);
+                if (part_mesh)
+                {
+                    part_mesh->updateFaceSizes(num_vertices, num_indices, mAdjustedPixelArea);
+                }
+            }
+            if(num_vertices < 1)//skip empty meshes
+            {
+                continue ;
+            }
+            if(last_v_num > 0)//put the last inserted part into next vertex buffer.
+            {
+                num_vertices = last_v_num ;
+                num_indices = last_i_num ;
+                part_index-- ;
+            }
+
+            LLFace* facep = NULL;
+            if(f_num < mDrawable->getNumFaces())
+            {
+                facep = mDrawable->getFace(f_num);
+            }
+            else
+            {
+                facep = mDrawable->getFace(0);
+                if (facep)
+                {
+                    facep = mDrawable->addFace(facep->getPool(), facep->getTexture()) ;
+                }
+            }
+            if (!facep) continue;
+
+            // resize immediately
+            facep->setSize(num_vertices, num_indices);
+
+            bool terse_update = false;
+
+            facep->setGeomIndex(0);
+            facep->setIndicesIndex(0);
+
+            LLVertexBuffer* buff = facep->getVertexBuffer();
+            if(!facep->getVertexBuffer())
+            {
                 buff = new LLVertexBuffer(LLDrawPoolAvatar::VERTEX_DATA_MASK);
-				if (!buff->allocateBuffer(num_vertices, num_indices))
-				{
-					LL_WARNS() << "Failed to allocate Vertex Buffer for Mesh to "
-						<< num_vertices << " vertices and "
-						<< num_indices << " indices" << LL_ENDL;
-					// Attempt to create a dummy triangle (one vertex, 3 indices, all 0)
-					facep->setSize(1, 3);
-					buff->allocateBuffer(1, 3);
-					memset((U8*) buff->getMappedData(), 0, buff->getSize());
-					memset((U8*) buff->getMappedIndices(), 0, buff->getIndicesSize());
-				}
-				facep->setVertexBuffer(buff);
-			}
-			else
-			{
-				if (buff->getNumIndices() == num_indices &&
-					buff->getNumVerts() == num_vertices)
-				{
-					terse_update = true;
-				}
-				else
-				{
+                if (!buff->allocateBuffer(num_vertices, num_indices))
+                {
+                    LL_WARNS() << "Failed to allocate Vertex Buffer for Mesh to "
+                        << num_vertices << " vertices and "
+                        << num_indices << " indices" << LL_ENDL;
+                    // Attempt to create a dummy triangle (one vertex, 3 indices, all 0)
+                    facep->setSize(1, 3);
+                    buff->allocateBuffer(1, 3);
+                    memset((U8*) buff->getMappedData(), 0, buff->getSize());
+                    memset((U8*) buff->getMappedIndices(), 0, buff->getIndicesSize());
+                }
+                facep->setVertexBuffer(buff);
+            }
+            else
+            {
+                if (buff->getNumIndices() == num_indices &&
+                    buff->getNumVerts() == num_vertices)
+                {
+                    terse_update = true;
+                }
+                else
+                {
                     buff = new LLVertexBuffer(buff->getTypeMask());
                     if (!buff->allocateBuffer(num_vertices, num_indices))
                     {
-						LL_WARNS() << "Failed to allocate vertex buffer for Mesh, Substituting" << LL_ENDL;
-						// Attempt to create a dummy triangle (one vertex, 3 indices, all 0)
-						facep->setSize(1, 3);
-						buff->allocateBuffer(1, 3);
-						memset((U8*) buff->getMappedData(), 0, buff->getSize());
-						memset((U8*) buff->getMappedIndices(), 0, buff->getIndicesSize());
-					}
-				}
-			}
-			
-		
-			// This is a hack! Avatars have their own pool, so we are detecting
-			//   the case of more than one avatar in the pool (thus > 0 instead of >= 0)
-			if (facep->getGeomIndex() > 0)
-			{
-				LL_ERRS() << "non-zero geom index: " << facep->getGeomIndex() << " in LLVOAvatar::restoreMeshData" << LL_ENDL;
-			}
-
-			if (num_vertices == buff->getNumVerts() && num_indices == buff->getNumIndices())
-			{
-				for(S32 k = j ; k < part_index ; k++)
-				{
-					bool rigid = false;
-					if (k == MESH_ID_EYEBALL_LEFT ||
-						k == MESH_ID_EYEBALL_RIGHT)
-					{
-						//eyeballs can't have terse updates since they're never rendered with
-						//the hardware skinning shader
-						rigid = true;
-					}
-				
-					LLViewerJoint* mesh = getViewerJoint(k);
-					if (mesh)
-					{
-						mesh->updateFaceData(facep, mAdjustedPixelArea, k == MESH_ID_HAIR, terse_update && !rigid);
-					}
-				}
-			}
-
-			stop_glerror();
-			buff->unmapBuffer();
-
-			if(!f_num)
-			{
-				f_num += mNumInitFaces ;
-			}
-			else
-			{
-				f_num++ ;
-			}
-		}
-	}
+                        LL_WARNS() << "Failed to allocate vertex buffer for Mesh, Substituting" << LL_ENDL;
+                        // Attempt to create a dummy triangle (one vertex, 3 indices, all 0)
+                        facep->setSize(1, 3);
+                        buff->allocateBuffer(1, 3);
+                        memset((U8*) buff->getMappedData(), 0, buff->getSize());
+                        memset((U8*) buff->getMappedIndices(), 0, buff->getIndicesSize());
+                    }
+                }
+            }
+
+
+            // This is a hack! Avatars have their own pool, so we are detecting
+            //   the case of more than one avatar in the pool (thus > 0 instead of >= 0)
+            if (facep->getGeomIndex() > 0)
+            {
+                LL_ERRS() << "non-zero geom index: " << facep->getGeomIndex() << " in LLVOAvatar::restoreMeshData" << LL_ENDL;
+            }
+
+            if (num_vertices == buff->getNumVerts() && num_indices == buff->getNumIndices())
+            {
+                for(S32 k = j ; k < part_index ; k++)
+                {
+                    bool rigid = false;
+                    if (k == MESH_ID_EYEBALL_LEFT ||
+                        k == MESH_ID_EYEBALL_RIGHT)
+                    {
+                        //eyeballs can't have terse updates since they're never rendered with
+                        //the hardware skinning shader
+                        rigid = true;
+                    }
+
+                    LLViewerJoint* mesh = getViewerJoint(k);
+                    if (mesh)
+                    {
+                        mesh->updateFaceData(facep, mAdjustedPixelArea, k == MESH_ID_HAIR, terse_update && !rigid);
+                    }
+                }
+            }
+
+            stop_glerror();
+            buff->unmapBuffer();
+
+            if(!f_num)
+            {
+                f_num += mNumInitFaces ;
+            }
+            else
+            {
+                f_num++ ;
+            }
+        }
+    }
 }
 
 //------------------------------------------------------------------------
@@ -2449,78 +2449,78 @@ void LLVOAvatar::updateMeshData()
 // LLVOAvatar::processUpdateMessage()
 //------------------------------------------------------------------------
 U32 LLVOAvatar::processUpdateMessage(LLMessageSystem *mesgsys,
-									 void **user_data,
-									 U32 block_num, const EObjectUpdateType update_type,
-									 LLDataPacker *dp)
+                                     void **user_data,
+                                     U32 block_num, const EObjectUpdateType update_type,
+                                     LLDataPacker *dp)
 {
-	const BOOL has_name = !getNVPair("FirstName");
+    const BOOL has_name = !getNVPair("FirstName");
 
-	// Do base class updates...
-	U32 retval = LLViewerObject::processUpdateMessage(mesgsys, user_data, block_num, update_type, dp);
+    // Do base class updates...
+    U32 retval = LLViewerObject::processUpdateMessage(mesgsys, user_data, block_num, update_type, dp);
 
-	// Print out arrival information once we have name of avatar.
+    // Print out arrival information once we have name of avatar.
     if (has_name && getNVPair("FirstName"))
     {
         mDebugExistenceTimer.reset();
         debugAvatarRezTime("AvatarRezArrivedNotification","avatar arrived");
     }
 
-	if(retval & LLViewerObject::INVALID_UPDATE)
-	{
-		if (isSelf())
-		{
-			//tell sim to cancel this update
-			gAgent.teleportViaLocation(gAgent.getPositionGlobal());
-		}
-	}
+    if(retval & LLViewerObject::INVALID_UPDATE)
+    {
+        if (isSelf())
+        {
+            //tell sim to cancel this update
+            gAgent.teleportViaLocation(gAgent.getPositionGlobal());
+        }
+    }
 
-	return retval;
+    return retval;
 }
 
 LLViewerFetchedTexture *LLVOAvatar::getBakedTextureImage(const U8 te, const LLUUID& uuid)
 {
-	LLViewerFetchedTexture *result = NULL;
-
-	if (uuid == IMG_DEFAULT_AVATAR ||
-		uuid == IMG_DEFAULT ||
-		uuid == IMG_INVISIBLE)
-	{
-		// Should already exist, don't need to find it on sim or baked-texture host.
-		result = gTextureList.findImage(uuid, TEX_LIST_STANDARD);
-	}
-	if (!result)
-	{
-		const std::string url = getImageURL(te,uuid);
-
-		if (url.empty())
-		{
-			LL_WARNS() << "unable to determine URL for te " << te << " uuid " << uuid << LL_ENDL;
-			return NULL;
-		}
-		LL_DEBUGS("Avatar") << avString() << "get server-bake image from URL " << url << LL_ENDL;
-		result = LLViewerTextureManager::getFetchedTextureFromUrl(
-			url, FTT_SERVER_BAKE, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, uuid);
-		if (result->isMissingAsset())
-		{
-			result->setIsMissingAsset(false);
-		}
-		
-	}
-	return result;
+    LLViewerFetchedTexture *result = NULL;
+
+    if (uuid == IMG_DEFAULT_AVATAR ||
+        uuid == IMG_DEFAULT ||
+        uuid == IMG_INVISIBLE)
+    {
+        // Should already exist, don't need to find it on sim or baked-texture host.
+        result = gTextureList.findImage(uuid, TEX_LIST_STANDARD);
+    }
+    if (!result)
+    {
+        const std::string url = getImageURL(te,uuid);
+
+        if (url.empty())
+        {
+            LL_WARNS() << "unable to determine URL for te " << te << " uuid " << uuid << LL_ENDL;
+            return NULL;
+        }
+        LL_DEBUGS("Avatar") << avString() << "get server-bake image from URL " << url << LL_ENDL;
+        result = LLViewerTextureManager::getFetchedTextureFromUrl(
+            url, FTT_SERVER_BAKE, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE, 0, 0, uuid);
+        if (result->isMissingAsset())
+        {
+            result->setIsMissingAsset(false);
+        }
+
+    }
+    return result;
 }
 
 // virtual
 S32 LLVOAvatar::setTETexture(const U8 te, const LLUUID& uuid)
 {
-	if (!isIndexBakedTexture((ETextureIndex)te))
-	{
-		// Sim still sends some uuids for non-baked slots sometimes - ignore.
-		return LLViewerObject::setTETexture(te, LLUUID::null);
-	}
+    if (!isIndexBakedTexture((ETextureIndex)te))
+    {
+        // Sim still sends some uuids for non-baked slots sometimes - ignore.
+        return LLViewerObject::setTETexture(te, LLUUID::null);
+    }
 
-	LLViewerFetchedTexture *image = getBakedTextureImage(te,uuid);
-	llassert(image);
-	return setTETextureCore(te, image);
+    LLViewerFetchedTexture *image = getBakedTextureImage(te,uuid);
+    llassert(image);
+    return setTETextureCore(te, image);
 }
 
 //------------------------------------------------------------------------
@@ -2528,26 +2528,26 @@ S32 LLVOAvatar::setTETexture(const U8 te, const LLUUID& uuid)
 //------------------------------------------------------------------------
 void LLVOAvatar::dumpAnimationState()
 {
-	LL_INFOS() << "==============================================" << LL_ENDL;
-	for (const auto& sig_anim_pair : mSignaledAnimations)
-	{
-		const LLUUID& id = sig_anim_pair.first;
-		std::string playtag;
-		if (mPlayingAnimations.find(id) != mPlayingAnimations.end())
-		{
-			playtag = "*";
-		}
-		LL_INFOS() << gAnimLibrary.animationName(id) << playtag << LL_ENDL;
-	}
-	for (const auto& playing_anim_pair : mPlayingAnimations)
-	{
-		const LLUUID& id = playing_anim_pair.first;
-		bool is_signaled = mSignaledAnimations.find(id) != mSignaledAnimations.end();
-		if (!is_signaled)
-		{
-			LL_INFOS() << gAnimLibrary.animationName(id) << "!S" << LL_ENDL;
-		}
-	}
+    LL_INFOS() << "==============================================" << LL_ENDL;
+    for (const auto& sig_anim_pair : mSignaledAnimations)
+    {
+        const LLUUID& id = sig_anim_pair.first;
+        std::string playtag;
+        if (mPlayingAnimations.find(id) != mPlayingAnimations.end())
+        {
+            playtag = "*";
+        }
+        LL_INFOS() << gAnimLibrary.animationName(id) << playtag << LL_ENDL;
+    }
+    for (const auto& playing_anim_pair : mPlayingAnimations)
+    {
+        const LLUUID& id = playing_anim_pair.first;
+        bool is_signaled = mSignaledAnimations.find(id) != mSignaledAnimations.end();
+        if (!is_signaled)
+        {
+            LL_INFOS() << gAnimLibrary.animationName(id) << "!S" << LL_ENDL;
+        }
+    }
 }
 
 //------------------------------------------------------------------------
@@ -2557,156 +2557,156 @@ void LLVOAvatar::idleUpdate(LLAgent &agent, const F64 &time)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
 
-	if (isDead())
-	{
-		LL_INFOS() << "Warning!  Idle on dead avatar" << LL_ENDL;
-		return;
-	}
+    if (isDead())
+    {
+        LL_INFOS() << "Warning!  Idle on dead avatar" << LL_ENDL;
+        return;
+    }
     // record time and refresh "tooSlow" status
     updateTooSlow();
 
-	static LLCachedControl<bool> disable_all_render_types(gSavedSettings, "DisableAllRenderTypes");
-	if (!(gPipeline.hasRenderType(mIsControlAvatar ? LLPipeline::RENDER_TYPE_CONTROL_AV : LLPipeline::RENDER_TYPE_AVATAR))
-		&& !disable_all_render_types && !isSelf())
-	{
+    static LLCachedControl<bool> disable_all_render_types(gSavedSettings, "DisableAllRenderTypes");
+    if (!(gPipeline.hasRenderType(mIsControlAvatar ? LLPipeline::RENDER_TYPE_CONTROL_AV : LLPipeline::RENDER_TYPE_AVATAR))
+        && !disable_all_render_types && !isSelf())
+    {
         if (!mIsControlAvatar)
         {
             idleUpdateNameTag(idleCalcNameTagPosition(mLastRootPos));
         }
-		return;
-	}
+        return;
+    }
 
     // Update should be happening max once per frame.
-	// <FS:Beq> enable dynamic spreading of the BB calculations
-	static LLCachedControl<S32> refreshPeriod(gSavedSettings, "AvatarExtentRefreshPeriodBatch");
-	static LLCachedControl<S32> refreshMaxPerPeriod(gSavedSettings, "AvatarExtentRefreshMaxPerBatch");
-	static S32 upd_freq = refreshPeriod; // initialise to a reasonable default of 1 batch
-	static S32 lastRecalibrationFrame{ 0 };
-
-	const S32 thisFrame = LLDrawable::getCurrentFrame(); 
-	if (thisFrame - lastRecalibrationFrame >= upd_freq)
-	{
-		// Only update at the start of a cycle. .
-		upd_freq = (((gObjectList.getAvatarCount() - 1) / refreshMaxPerPeriod) + 1)*refreshPeriod;
-		lastRecalibrationFrame = thisFrame;
-	}
-	//</FS:Beq>
-	if ((mLastAnimExtents[0]==LLVector3())||
-		(mLastAnimExtents[1])==LLVector3())
-	{
-		mNeedsExtentUpdate = true;
-	}
-	else
-	{
-		//<FS:Beq> enable dynamic spreading of the BB calculations
-		//const S32 upd_freq = 4; // force update every upd_freq frames.
-		//mNeedsExtentUpdate = ((LLDrawable::getCurrentFrame()+mID.mData[0]) % upd_freq == 0);
-		mNeedsExtentUpdate = ((thisFrame + mID.mData[0]) % upd_freq == 0);
-		//</FS:Beq>
-	}
-    
+    // <FS:Beq> enable dynamic spreading of the BB calculations
+    static LLCachedControl<S32> refreshPeriod(gSavedSettings, "AvatarExtentRefreshPeriodBatch");
+    static LLCachedControl<S32> refreshMaxPerPeriod(gSavedSettings, "AvatarExtentRefreshMaxPerBatch");
+    static S32 upd_freq = refreshPeriod; // initialise to a reasonable default of 1 batch
+    static S32 lastRecalibrationFrame{ 0 };
+
+    const S32 thisFrame = LLDrawable::getCurrentFrame();
+    if (thisFrame - lastRecalibrationFrame >= upd_freq)
+    {
+        // Only update at the start of a cycle. .
+        upd_freq = (((gObjectList.getAvatarCount() - 1) / refreshMaxPerPeriod) + 1)*refreshPeriod;
+        lastRecalibrationFrame = thisFrame;
+    }
+    //</FS:Beq>
+    if ((mLastAnimExtents[0]==LLVector3())||
+        (mLastAnimExtents[1])==LLVector3())
+    {
+        mNeedsExtentUpdate = true;
+    }
+    else
+    {
+        //<FS:Beq> enable dynamic spreading of the BB calculations
+        //const S32 upd_freq = 4; // force update every upd_freq frames.
+        //mNeedsExtentUpdate = ((LLDrawable::getCurrentFrame()+mID.mData[0]) % upd_freq == 0);
+        mNeedsExtentUpdate = ((thisFrame + mID.mData[0]) % upd_freq == 0);
+        //</FS:Beq>
+    }
+
 #ifdef SHOW_DEBUG
     LLScopedContextString str("avatar_idle_update " + getFullname());
 #endif
-    
-	checkTextureLoading() ;
-	
-	// force immediate pixel area update on avatars using last frames data (before drawable or camera updates)
-	setPixelAreaAndAngle(gAgent);
-
-	// force asynchronous drawable update
-	if(mDrawable.notNull())
-	{	
-		if (isSitting() && getParent())
-		{
-			LLViewerObject *root_object = (LLViewerObject*)getRoot();
-			LLDrawable* drawablep = root_object->mDrawable;
-			// if this object hasn't already been updated by another avatar...
-			if (drawablep) // && !drawablep->isState(LLDrawable::EARLY_MOVE))
-			{
-				if (root_object->isSelected())
-				{
-					gPipeline.updateMoveNormalAsync(drawablep);
-				}
-				else
-				{
-					gPipeline.updateMoveDampedAsync(drawablep);
-				}
-			}
-		}
-		else 
-		{
-			gPipeline.updateMoveDampedAsync(mDrawable);
-		}
-	}
-
-	//--------------------------------------------------------------------
-	// set alpha flag depending on state
-	//--------------------------------------------------------------------
-
-	if (isSelf())
-	{
-		LLViewerObject::idleUpdate(agent, time);
-		
-		// trigger fidget anims
-		if (isAnyAnimationSignaled(AGENT_STAND_ANIMS, NUM_AGENT_STAND_ANIMS))
-		{
-			agent.fidget();
-		}
-	}
-	else
-	{
-		// Should override the idleUpdate stuff and leave out the angular update part.
-		LLQuaternion rotation = getRotation();
-		LLViewerObject::idleUpdate(agent, time);
-		setRotation(rotation);
-	}
-
-	// attach objects that were waiting for a drawable
-	lazyAttach();
-	
-	// animate the character
-	// store off last frame's root position to be consistent with camera position
-	mLastRootPos = mRoot->getWorldPosition();
-	BOOL detailed_update = updateCharacter(agent);
-
-	static LLUICachedControl<bool> visualizers_in_calls("ShowVoiceVisualizersInCalls", false);
-	bool voice_enabled = (visualizers_in_calls || LLVoiceClient::getInstance()->inProximalChannel()) &&
-						 LLVoiceClient::getInstance()->getVoiceEnabled(mID);
 
-    LLVector3 hud_name_pos = idleCalcNameTagPosition(mLastRootPos);
+    checkTextureLoading() ;
 
-	idleUpdateVoiceVisualizer(voice_enabled, hud_name_pos);
-	idleUpdateMisc( detailed_update );
-	idleUpdateAppearanceAnimation();
-	if (detailed_update)
-	{
-		idleUpdateLipSync( voice_enabled );
-		idleUpdateLoadingEffect();
-		idleUpdateBelowWater();	// wind effect uses this
-		idleUpdateWindEffect();
-	}
-		
-	idleUpdateNameTag(hud_name_pos);
+    // force immediate pixel area update on avatars using last frames data (before drawable or camera updates)
+    setPixelAreaAndAngle(gAgent);
 
-    // Complexity has stale mechanics, but updates still can be very rapid
-    // so spread avatar complexity calculations over frames to lesen load from
-    // rapid updates and to make sure all avatars are not calculated at once.
-    S32 compl_upd_freq = 20;
-    if (isControlAvatar())
-    {
-        // animeshes do not (or won't) have impostors nor change outfis,
-        // no need for high frequency
-        compl_upd_freq = 100;
-    }
-    else if (mLastRezzedStatus <= 0) //cloud or  init
-    {
-        compl_upd_freq = 60;
-    }
-    else if (isSelf())
+    // force asynchronous drawable update
+    if(mDrawable.notNull())
     {
-        compl_upd_freq = 5;
-    }
+        if (isSitting() && getParent())
+        {
+            LLViewerObject *root_object = (LLViewerObject*)getRoot();
+            LLDrawable* drawablep = root_object->mDrawable;
+            // if this object hasn't already been updated by another avatar...
+            if (drawablep) // && !drawablep->isState(LLDrawable::EARLY_MOVE))
+            {
+                if (root_object->isSelected())
+                {
+                    gPipeline.updateMoveNormalAsync(drawablep);
+                }
+                else
+                {
+                    gPipeline.updateMoveDampedAsync(drawablep);
+                }
+            }
+        }
+        else
+        {
+            gPipeline.updateMoveDampedAsync(mDrawable);
+        }
+    }
+
+    //--------------------------------------------------------------------
+    // set alpha flag depending on state
+    //--------------------------------------------------------------------
+
+    if (isSelf())
+    {
+        LLViewerObject::idleUpdate(agent, time);
+
+        // trigger fidget anims
+        if (isAnyAnimationSignaled(AGENT_STAND_ANIMS, NUM_AGENT_STAND_ANIMS))
+        {
+            agent.fidget();
+        }
+    }
+    else
+    {
+        // Should override the idleUpdate stuff and leave out the angular update part.
+        LLQuaternion rotation = getRotation();
+        LLViewerObject::idleUpdate(agent, time);
+        setRotation(rotation);
+    }
+
+    // attach objects that were waiting for a drawable
+    lazyAttach();
+
+    // animate the character
+    // store off last frame's root position to be consistent with camera position
+    mLastRootPos = mRoot->getWorldPosition();
+    BOOL detailed_update = updateCharacter(agent);
+
+    static LLUICachedControl<bool> visualizers_in_calls("ShowVoiceVisualizersInCalls", false);
+    bool voice_enabled = (visualizers_in_calls || LLVoiceClient::getInstance()->inProximalChannel()) &&
+                         LLVoiceClient::getInstance()->getVoiceEnabled(mID);
+
+    LLVector3 hud_name_pos = idleCalcNameTagPosition(mLastRootPos);
+
+    idleUpdateVoiceVisualizer(voice_enabled, hud_name_pos);
+    idleUpdateMisc( detailed_update );
+    idleUpdateAppearanceAnimation();
+    if (detailed_update)
+    {
+        idleUpdateLipSync( voice_enabled );
+        idleUpdateLoadingEffect();
+        idleUpdateBelowWater(); // wind effect uses this
+        idleUpdateWindEffect();
+    }
+
+    idleUpdateNameTag(hud_name_pos);
+
+    // Complexity has stale mechanics, but updates still can be very rapid
+    // so spread avatar complexity calculations over frames to lesen load from
+    // rapid updates and to make sure all avatars are not calculated at once.
+    S32 compl_upd_freq = 20;
+    if (isControlAvatar())
+    {
+        // animeshes do not (or won't) have impostors nor change outfis,
+        // no need for high frequency
+        compl_upd_freq = 100;
+    }
+    else if (mLastRezzedStatus <= 0) //cloud or  init
+    {
+        compl_upd_freq = 60;
+    }
+    else if (isSelf())
+    {
+        compl_upd_freq = 5;
+    }
     else if (mLastRezzedStatus == 1) //'grey', not fully loaded
     {
         compl_upd_freq = 40;
@@ -2718,7 +2718,7 @@ void LLVOAvatar::idleUpdate(LLAgent &agent, const F64 &time)
 
     if ((LLFrameTimer::getFrameCount() + mID.mData[0]) % compl_upd_freq == 0)
     {
-        // DEPRECATED 
+        // DEPRECATED
         // replace with LLPipeline::profileAvatar?
         // Avatar profile takes ~ 0.5ms while idleUpdateRenderComplexity takes ~5ms
         // (both are unacceptably costly)
@@ -2729,96 +2729,96 @@ void LLVOAvatar::idleUpdate(LLAgent &agent, const F64 &time)
 
 void LLVOAvatar::idleUpdateVoiceVisualizer(bool voice_enabled, const LLVector3 &position)
 {
-	bool render_visualizer = voice_enabled;
-	
-	// Don't render the user's own voice visualizer when in mouselook, or when opening the mic is disabled.
-	if(isSelf())
-	{
+    bool render_visualizer = voice_enabled;
+
+    // Don't render the user's own voice visualizer when in mouselook, or when opening the mic is disabled.
+    if(isSelf())
+    {
         static LLCachedControl<bool> voice_disable_mic(gSavedSettings, "VoiceDisableMic");
-		if(gAgentCamera.cameraMouselook() || voice_disable_mic)
-		{
-			render_visualizer = false;
-		}
-	}
-	
-	mVoiceVisualizer->setVoiceEnabled(render_visualizer);
-	
-	if ( voice_enabled )
-	{		
-		//----------------------------------------------------------------
-		// Only do gesture triggering for your own avatar, and only when you're in a proximal channel.
-		//----------------------------------------------------------------
-		if( isSelf() )
-		{
-			//----------------------------------------------------------------------------------------
-			// The following takes the voice signal and uses that to trigger gesticulations. 
-			//----------------------------------------------------------------------------------------
-			int lastGesticulationLevel = mCurrentGesticulationLevel;
-			mCurrentGesticulationLevel = mVoiceVisualizer->getCurrentGesticulationLevel();
-			
-			//---------------------------------------------------------------------------------------------------
-			// If "current gesticulation level" changes, we catch this, and trigger the new gesture
-			//---------------------------------------------------------------------------------------------------
-			if ( lastGesticulationLevel != mCurrentGesticulationLevel )
-			{
-				if ( mCurrentGesticulationLevel != VOICE_GESTICULATION_LEVEL_OFF )
-				{
-					std::string gestureString = "unInitialized";
-					if ( mCurrentGesticulationLevel == 0 )	{ gestureString = "/voicelevel1";	}
-					else	if ( mCurrentGesticulationLevel == 1 )	{ gestureString = "/voicelevel2";	}
-					else	if ( mCurrentGesticulationLevel == 2 )	{ gestureString = "/voicelevel3";	}
-					else	{ LL_INFOS() << "oops - CurrentGesticulationLevel can be only 0, 1, or 2"  << LL_ENDL; }
-					
-					// this is the call that Karl S. created for triggering gestures from within the code.
-					LLGestureMgr::instance().triggerAndReviseString( gestureString );
-				}
-			}
-			
-		} //if( isSelf() )
-		
-		//-----------------------------------------------------------------------------------------------------------------
-		// If the avatar is speaking, then the voice amplitude signal is passed to the voice visualizer.
-		// Also, here we trigger voice visualizer start and stop speaking, so it can animate the voice symbol.
-		//
-		// Notice the calls to "gAwayTimer.reset()". This resets the timer that determines how long the avatar has been
-		// "away", so that the avatar doesn't lapse into away-mode (and slump over) while the user is still talking. 
-		//-----------------------------------------------------------------------------------------------------------------
-		if (LLVoiceClient::getInstance()->getIsSpeaking( mID ))
-		{		
-			if (!mVoiceVisualizer->getCurrentlySpeaking())
-			{
-				mVoiceVisualizer->setStartSpeaking();
-				
-				//printf( "gAwayTimer.reset();\n" );
-			}
-			
-			mVoiceVisualizer->setSpeakingAmplitude( LLVoiceClient::getInstance()->getCurrentPower( mID ) );
-			
-			if( isSelf() )
-			{
-				gAgent.clearAFK();
-			}
-		}
-		else
-		{
-			if ( mVoiceVisualizer->getCurrentlySpeaking() )
-			{
-				mVoiceVisualizer->setStopSpeaking();
-				
-				if ( mLipSyncActive )
-				{
-					if( mOohMorph ) mOohMorph->setWeight(mOohMorph->getMinWeight());
-					if( mAahMorph ) mAahMorph->setWeight(mAahMorph->getMinWeight());
-					
-					mLipSyncActive = false;
-					LLCharacter::updateVisualParams();
-					dirtyMesh();
-				}
-			}
-		}
+        if(gAgentCamera.cameraMouselook() || voice_disable_mic)
+        {
+            render_visualizer = false;
+        }
+    }
+
+    mVoiceVisualizer->setVoiceEnabled(render_visualizer);
+
+    if ( voice_enabled )
+    {
+        //----------------------------------------------------------------
+        // Only do gesture triggering for your own avatar, and only when you're in a proximal channel.
+        //----------------------------------------------------------------
+        if( isSelf() )
+        {
+            //----------------------------------------------------------------------------------------
+            // The following takes the voice signal and uses that to trigger gesticulations.
+            //----------------------------------------------------------------------------------------
+            int lastGesticulationLevel = mCurrentGesticulationLevel;
+            mCurrentGesticulationLevel = mVoiceVisualizer->getCurrentGesticulationLevel();
+
+            //---------------------------------------------------------------------------------------------------
+            // If "current gesticulation level" changes, we catch this, and trigger the new gesture
+            //---------------------------------------------------------------------------------------------------
+            if ( lastGesticulationLevel != mCurrentGesticulationLevel )
+            {
+                if ( mCurrentGesticulationLevel != VOICE_GESTICULATION_LEVEL_OFF )
+                {
+                    std::string gestureString = "unInitialized";
+                    if ( mCurrentGesticulationLevel == 0 )  { gestureString = "/voicelevel1";   }
+                    else    if ( mCurrentGesticulationLevel == 1 )  { gestureString = "/voicelevel2";   }
+                    else    if ( mCurrentGesticulationLevel == 2 )  { gestureString = "/voicelevel3";   }
+                    else    { LL_INFOS() << "oops - CurrentGesticulationLevel can be only 0, 1, or 2"  << LL_ENDL; }
+
+                    // this is the call that Karl S. created for triggering gestures from within the code.
+                    LLGestureMgr::instance().triggerAndReviseString( gestureString );
+                }
+            }
+
+        } //if( isSelf() )
+
+        //-----------------------------------------------------------------------------------------------------------------
+        // If the avatar is speaking, then the voice amplitude signal is passed to the voice visualizer.
+        // Also, here we trigger voice visualizer start and stop speaking, so it can animate the voice symbol.
+        //
+        // Notice the calls to "gAwayTimer.reset()". This resets the timer that determines how long the avatar has been
+        // "away", so that the avatar doesn't lapse into away-mode (and slump over) while the user is still talking.
+        //-----------------------------------------------------------------------------------------------------------------
+        if (LLVoiceClient::getInstance()->getIsSpeaking( mID ))
+        {
+            if (!mVoiceVisualizer->getCurrentlySpeaking())
+            {
+                mVoiceVisualizer->setStartSpeaking();
+
+                //printf( "gAwayTimer.reset();\n" );
+            }
+
+            mVoiceVisualizer->setSpeakingAmplitude( LLVoiceClient::getInstance()->getCurrentPower( mID ) );
+
+            if( isSelf() )
+            {
+                gAgent.clearAFK();
+            }
+        }
+        else
+        {
+            if ( mVoiceVisualizer->getCurrentlySpeaking() )
+            {
+                mVoiceVisualizer->setStopSpeaking();
+
+                if ( mLipSyncActive )
+                {
+                    if( mOohMorph ) mOohMorph->setWeight(mOohMorph->getMinWeight());
+                    if( mAahMorph ) mAahMorph->setWeight(mAahMorph->getMinWeight());
+
+                    mLipSyncActive = false;
+                    LLCharacter::updateVisualParams();
+                    dirtyMesh();
+                }
+            }
+        }
         mVoiceVisualizer->setPositionAgent(position);
-	}//if ( voiceEnabled )
-}		
+    }//if ( voiceEnabled )
+}
 
 static void override_bbox(LLDrawable* drawable, LLVector4a* extents)
 {
@@ -2831,29 +2831,29 @@ static void override_bbox(LLDrawable* drawable, LLVector4a* extents)
 void LLVOAvatar::idleUpdateMisc(bool detailed_update)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
-	if (LLVOAvatar::sJointDebug)
-	{
-		LL_INFOS() << getFullname() << ": joint touches: " << LLJoint::sNumTouches << " updates: " << LLJoint::sNumUpdates << LL_ENDL;
-	}
+    if (LLVOAvatar::sJointDebug)
+    {
+        LL_INFOS() << getFullname() << ": joint touches: " << LLJoint::sNumTouches << " updates: " << LLJoint::sNumUpdates << LL_ENDL;
+    }
 
-	LLJoint::sNumUpdates = 0;
-	LLJoint::sNumTouches = 0;
+    LLJoint::sNumUpdates = 0;
+    LLJoint::sNumTouches = 0;
 
-	BOOL visible = isVisible() || mNeedsAnimUpdate;
+    BOOL visible = isVisible() || mNeedsAnimUpdate;
 
-	// update attachments positions
-	if (detailed_update)
-	{
+    // update attachments positions
+    if (detailed_update)
+    {
         U32 draw_order = 0;
-		auto& selectMgr = LLSelectMgr::instance();
+        auto& selectMgr = LLSelectMgr::instance();
         S32 attachment_selected = selectMgr.getSelection()->getObjectCount() && selectMgr.getSelection()->isAttachment();
-		for (const auto& attach_point_pair : mAttachmentPoints)
-		{
-			LLViewerJointAttachment* attachment = attach_point_pair.second;
-			if (!attachment) continue;
+        for (const auto& attach_point_pair : mAttachmentPoints)
+        {
+            LLViewerJointAttachment* attachment = attach_point_pair.second;
+            if (!attachment) continue;
 
-			for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-			{
+            for (LLViewerObject* attached_object : attachment->mAttachedObjects)
+            {
                 if (!attached_object
                     || attached_object->isDead()
                     || !attachment->getValid()
@@ -2863,9 +2863,9 @@ void LLVOAvatar::idleUpdateMisc(bool detailed_update)
                 }
 
                 LLSpatialBridge* bridge = attached_object->mDrawable->getSpatialBridge();
-				
-				if (visible || !(bridge && bridge->getRadius() < 2.0f))
-				{
+
+                if (visible || !(bridge && bridge->getRadius() < 2.0f))
+                {
                     //override rigged attachments' octree spatial extents with this avatar's bounding box
                     bool rigged = false;
                     if (bridge)
@@ -2919,988 +2919,988 @@ void LLVOAvatar::idleUpdateMisc(bool detailed_update)
                         }
                     }
 
-					attached_object->updateText();	
-				}
-			}
-		}
-	}
-
-	mNeedsAnimUpdate = FALSE;
-
-	if (isImpostor() && !mNeedsImpostorUpdate)
-	{
-		LL_ALIGN_16(LLVector4a ext[2]);
-		F32 distance;
-		LLVector3 angle;
-
-		getImpostorValues(ext, angle, distance);
-
-		for (U32 i = 0; i < 3 && !mNeedsImpostorUpdate; i++)
-		{
-			F32 cur_angle = angle.mV[i];
-			F32 old_angle = mImpostorAngle.mV[i];
-			F32 angle_diff = fabsf(cur_angle-old_angle);
-		
-			if (angle_diff > F_PI/512.f*distance*mUpdatePeriod)
-			{
-				mNeedsImpostorUpdate = TRUE;
-				mLastImpostorUpdateReason = 2;
-			}
-		}
-
-		if (detailed_update && !mNeedsImpostorUpdate)
-		{	//update impostor if view angle, distance, or bounding box change
-			//significantly
-			
-			F32 dist_diff = fabsf(distance-mImpostorDistance);
-			if (dist_diff/mImpostorDistance > 0.1f)
-			{
-				mNeedsImpostorUpdate = TRUE;
-				mLastImpostorUpdateReason = 3;
-			}
-			else
-			{
-				ext[0].load3(mLastAnimExtents[0].mV);
+                    attached_object->updateText();
+                }
+            }
+        }
+    }
+
+    mNeedsAnimUpdate = FALSE;
+
+    if (isImpostor() && !mNeedsImpostorUpdate)
+    {
+        LL_ALIGN_16(LLVector4a ext[2]);
+        F32 distance;
+        LLVector3 angle;
+
+        getImpostorValues(ext, angle, distance);
+
+        for (U32 i = 0; i < 3 && !mNeedsImpostorUpdate; i++)
+        {
+            F32 cur_angle = angle.mV[i];
+            F32 old_angle = mImpostorAngle.mV[i];
+            F32 angle_diff = fabsf(cur_angle-old_angle);
+
+            if (angle_diff > F_PI/512.f*distance*mUpdatePeriod)
+            {
+                mNeedsImpostorUpdate = TRUE;
+                mLastImpostorUpdateReason = 2;
+            }
+        }
+
+        if (detailed_update && !mNeedsImpostorUpdate)
+        {   //update impostor if view angle, distance, or bounding box change
+            //significantly
+
+            F32 dist_diff = fabsf(distance-mImpostorDistance);
+            if (dist_diff/mImpostorDistance > 0.1f)
+            {
+                mNeedsImpostorUpdate = TRUE;
+                mLastImpostorUpdateReason = 3;
+            }
+            else
+            {
+                ext[0].load3(mLastAnimExtents[0].mV);
                 ext[1].load3(mLastAnimExtents[1].mV);
                 // Expensive. Just call this once per frame, in updateSpatialExtents();
                 //calculateSpatialExtents(ext[0], ext[1]);
-				LLVector4a diff;
-				diff.setSub(ext[1], mImpostorExtents[1]);
-				if (diff.getLength3().getF32() > 0.05f)
-				{
-					mNeedsImpostorUpdate = TRUE;
-					mLastImpostorUpdateReason = 4;
-				}
-				else
-				{
-					diff.setSub(ext[0], mImpostorExtents[0]);
-					if (diff.getLength3().getF32() > 0.05f)
-					{
-						mNeedsImpostorUpdate = TRUE;
-						mLastImpostorUpdateReason = 5;
-					}
-				}
-			}
-		}
-	}
+                LLVector4a diff;
+                diff.setSub(ext[1], mImpostorExtents[1]);
+                if (diff.getLength3().getF32() > 0.05f)
+                {
+                    mNeedsImpostorUpdate = TRUE;
+                    mLastImpostorUpdateReason = 4;
+                }
+                else
+                {
+                    diff.setSub(ext[0], mImpostorExtents[0]);
+                    if (diff.getLength3().getF32() > 0.05f)
+                    {
+                        mNeedsImpostorUpdate = TRUE;
+                        mLastImpostorUpdateReason = 5;
+                    }
+                }
+            }
+        }
+    }
 
     if (mDrawable.notNull())
     {
-		mDrawable->movePartition();
-	
-		//force a move if sitting on an active object
-		if (getParent() && ((LLViewerObject*) getParent())->mDrawable->isActive())
-		{
-			gPipeline.markMoved(mDrawable, TRUE);
-		}
+        mDrawable->movePartition();
+
+        //force a move if sitting on an active object
+        if (getParent() && ((LLViewerObject*) getParent())->mDrawable->isActive())
+        {
+            gPipeline.markMoved(mDrawable, TRUE);
+        }
     }
 }
 
 void LLVOAvatar::idleUpdateAppearanceAnimation()
 {
-	// update morphing params
-	if (mAppearanceAnimating)
-	{
-		ESex avatar_sex = getSex();
-		F32 appearance_anim_time = mAppearanceMorphTimer.getElapsedTimeF32();
-		if (appearance_anim_time >= APPEARANCE_MORPH_TIME)
-		{
-			mAppearanceAnimating = FALSE;
-			for (LLVisualParam *param = getFirstVisualParam(); 
-				 param;
-				 param = getNextVisualParam())
-			{
-				if (param->isTweakable())
-				{
-					param->stopAnimating();
-				}
-			}
-			updateVisualParams();
-		}
-		else
-		{
-			F32 morph_amt = calcMorphAmount();
-			LLVisualParam *param;
-
-			if (!isSelf())
-			{
-				// animate only top level params for non-self avatars
-				for (param = getFirstVisualParam();
-					 param;
-					 param = getNextVisualParam())
-				{
-					if (param->isTweakable())
-					{
-						param->animate(morph_amt);
-					}
-				}
-			}
-
-			// apply all params
-			for (param = getFirstVisualParam();
-				 param;
-				 param = getNextVisualParam())
-			{
-				param->apply(avatar_sex);
-			}
-
-			mLastAppearanceBlendTime = appearance_anim_time;
-		}
-		dirtyMesh();
-	}
+    // update morphing params
+    if (mAppearanceAnimating)
+    {
+        ESex avatar_sex = getSex();
+        F32 appearance_anim_time = mAppearanceMorphTimer.getElapsedTimeF32();
+        if (appearance_anim_time >= APPEARANCE_MORPH_TIME)
+        {
+            mAppearanceAnimating = FALSE;
+            for (LLVisualParam *param = getFirstVisualParam();
+                 param;
+                 param = getNextVisualParam())
+            {
+                if (param->isTweakable())
+                {
+                    param->stopAnimating();
+                }
+            }
+            updateVisualParams();
+        }
+        else
+        {
+            F32 morph_amt = calcMorphAmount();
+            LLVisualParam *param;
+
+            if (!isSelf())
+            {
+                // animate only top level params for non-self avatars
+                for (param = getFirstVisualParam();
+                     param;
+                     param = getNextVisualParam())
+                {
+                    if (param->isTweakable())
+                    {
+                        param->animate(morph_amt);
+                    }
+                }
+            }
+
+            // apply all params
+            for (param = getFirstVisualParam();
+                 param;
+                 param = getNextVisualParam())
+            {
+                param->apply(avatar_sex);
+            }
+
+            mLastAppearanceBlendTime = appearance_anim_time;
+        }
+        dirtyMesh();
+    }
 }
 
 F32 LLVOAvatar::calcMorphAmount()
 {
-	F32 appearance_anim_time = mAppearanceMorphTimer.getElapsedTimeF32();
-	F32 blend_frac = calc_bouncy_animation(appearance_anim_time / APPEARANCE_MORPH_TIME);
-	F32 last_blend_frac = calc_bouncy_animation(mLastAppearanceBlendTime / APPEARANCE_MORPH_TIME);
+    F32 appearance_anim_time = mAppearanceMorphTimer.getElapsedTimeF32();
+    F32 blend_frac = calc_bouncy_animation(appearance_anim_time / APPEARANCE_MORPH_TIME);
+    F32 last_blend_frac = calc_bouncy_animation(mLastAppearanceBlendTime / APPEARANCE_MORPH_TIME);
 
-	F32 morph_amt;
-	if (last_blend_frac == 1.f)
-	{
-		morph_amt = 1.f;
-	}
-	else
-	{
-		morph_amt = (blend_frac - last_blend_frac) / (1.f - last_blend_frac);
-	}
+    F32 morph_amt;
+    if (last_blend_frac == 1.f)
+    {
+        morph_amt = 1.f;
+    }
+    else
+    {
+        morph_amt = (blend_frac - last_blend_frac) / (1.f - last_blend_frac);
+    }
 
-	return morph_amt;
+    return morph_amt;
 }
 
 void LLVOAvatar::idleUpdateLipSync(bool voice_enabled)
 {
-	// Use the Lipsync_Ooh and Lipsync_Aah morphs for lip sync
-	auto& voiceClient = LLVoiceClient::instance();
+    // Use the Lipsync_Ooh and Lipsync_Aah morphs for lip sync
+    auto& voiceClient = LLVoiceClient::instance();
     if ( voice_enabled
         && mLastRezzedStatus > 0 // no point updating lip-sync for clouds
         && (voiceClient.lipSyncEnabled())
         && voiceClient.getIsSpeaking( mID ) )
-	{
-		F32 ooh_morph_amount = 0.0f;
-		F32 aah_morph_amount = 0.0f;
+    {
+        F32 ooh_morph_amount = 0.0f;
+        F32 aah_morph_amount = 0.0f;
 
-		mVoiceVisualizer->lipSyncOohAah( ooh_morph_amount, aah_morph_amount );
+        mVoiceVisualizer->lipSyncOohAah( ooh_morph_amount, aah_morph_amount );
 
-		if( mOohMorph )
-		{
-			F32 ooh_weight = mOohMorph->getMinWeight()
-				+ ooh_morph_amount * (mOohMorph->getMaxWeight() - mOohMorph->getMinWeight());
+        if( mOohMorph )
+        {
+            F32 ooh_weight = mOohMorph->getMinWeight()
+                + ooh_morph_amount * (mOohMorph->getMaxWeight() - mOohMorph->getMinWeight());
 
-			mOohMorph->setWeight( ooh_weight);
-		}
+            mOohMorph->setWeight( ooh_weight);
+        }
 
-		if( mAahMorph )
-		{
-			F32 aah_weight = mAahMorph->getMinWeight()
-				+ aah_morph_amount * (mAahMorph->getMaxWeight() - mAahMorph->getMinWeight());
+        if( mAahMorph )
+        {
+            F32 aah_weight = mAahMorph->getMinWeight()
+                + aah_morph_amount * (mAahMorph->getMaxWeight() - mAahMorph->getMinWeight());
 
-			mAahMorph->setWeight( aah_weight);
-		}
+            mAahMorph->setWeight( aah_weight);
+        }
 
-		mLipSyncActive = true;
-		LLCharacter::updateVisualParams();
-		dirtyMesh();
-	}
+        mLipSyncActive = true;
+        LLCharacter::updateVisualParams();
+        dirtyMesh();
+    }
 }
 
 void LLVOAvatar::idleUpdateLoadingEffect()
 {
-	// update visibility when avatar is partially loaded
-	if (updateIsFullyLoaded()) // changed?
-	{
-		if (isFullyLoaded())
-		{
-			if (mFirstFullyVisible)
-			{
-				mFirstFullyVisible = FALSE;
-				if (isSelf())
-				{
-					LL_INFOS("Avatar") << avString() << "self isFullyLoaded, mFirstFullyVisible" << LL_ENDL;
-					LLAppearanceMgr::instance().onFirstFullyVisible();
-
-					AOEngine::instance().onLoginComplete();
-				}
-				else
-				{
-					LL_INFOS("Avatar") << avString() << "other isFullyLoaded, mFirstFullyVisible" << LL_ENDL;
-				}
-			}
-
-			deleteParticleSource();
-			updateLOD();
-		}
-		else
-		{
-			LLPartSysData particle_parameters;
-
-			// fancy particle cloud designed by Brent
-			particle_parameters.mPartData.mMaxAge            = 5.f;
-			particle_parameters.mPartData.mStartScale		 = LLVector2(0.100250f, 0.100250f);
-			particle_parameters.mPartData.mEndScale			 = LLVector2(1.000250f, 1.000250f);
-		    particle_parameters.mPartData.mStartGlow		 = 0;
-		    particle_parameters.mPartData.mEndGlow			 = 0;
-			particle_parameters.mPartData.mStartColor        = LLColor4(0.501773f, 0.743102f, 1.000000f, 1.f);
-			particle_parameters.mPartData.mEndColor          = LLColor4(0.000000f, 0.000000f, 0.000000f, 1.f);
-			particle_parameters.mPartData.mBlendFuncSource	 = LLPartData::LL_PART_BF_SOURCE_COLOR;
-			particle_parameters.mPartData.mBlendFuncDest	 = LLPartData::LL_PART_BF_SOURCE_ALPHA;
-
-			particle_parameters.mPartImageID                 = sCloudTexture->getID();
-			particle_parameters.mMaxAge                      = 0.f;
-			particle_parameters.mPattern                     = LLPartSysData::LL_PART_SRC_PATTERN_EXPLODE;
-			particle_parameters.mInnerAngle                  = 0.f;
-			particle_parameters.mOuterAngle                  = 0.f;
-			particle_parameters.mBurstRate                   = 0.02f;
-			particle_parameters.mBurstRadius                 = 0.0f;
-			particle_parameters.mBurstPartCount              = 1;
-			particle_parameters.mBurstSpeedMin               = 0.01f;
-			particle_parameters.mBurstSpeedMax               = 0.6f;
-			particle_parameters.mPartData.mFlags             = ( LLPartData::LL_PART_INTERP_COLOR_MASK | LLPartData::LL_PART_INTERP_SCALE_MASK |
-																 LLPartData::LL_PART_EMISSIVE_MASK | LLPartData::LL_PART_FOLLOW_SRC_MASK |
-																 LLPartData::LL_PART_TARGET_POS_MASK );
-			
-			// do not generate particles for dummy or overly-complex avatars
-			if (!mIsDummy && !isTooComplex() && !isTooSlow())
-			{
-				setParticleSource(particle_parameters, getID());
-			}
-		}
-	}
-}	
+    // update visibility when avatar is partially loaded
+    if (updateIsFullyLoaded()) // changed?
+    {
+        if (isFullyLoaded())
+        {
+            if (mFirstFullyVisible)
+            {
+                mFirstFullyVisible = FALSE;
+                if (isSelf())
+                {
+                    LL_INFOS("Avatar") << avString() << "self isFullyLoaded, mFirstFullyVisible" << LL_ENDL;
+                    LLAppearanceMgr::instance().onFirstFullyVisible();
+
+                    AOEngine::instance().onLoginComplete();
+                }
+                else
+                {
+                    LL_INFOS("Avatar") << avString() << "other isFullyLoaded, mFirstFullyVisible" << LL_ENDL;
+                }
+            }
+
+            deleteParticleSource();
+            updateLOD();
+        }
+        else
+        {
+            LLPartSysData particle_parameters;
+
+            // fancy particle cloud designed by Brent
+            particle_parameters.mPartData.mMaxAge            = 5.f;
+            particle_parameters.mPartData.mStartScale        = LLVector2(0.100250f, 0.100250f);
+            particle_parameters.mPartData.mEndScale          = LLVector2(1.000250f, 1.000250f);
+            particle_parameters.mPartData.mStartGlow         = 0;
+            particle_parameters.mPartData.mEndGlow           = 0;
+            particle_parameters.mPartData.mStartColor        = LLColor4(0.501773f, 0.743102f, 1.000000f, 1.f);
+            particle_parameters.mPartData.mEndColor          = LLColor4(0.000000f, 0.000000f, 0.000000f, 1.f);
+            particle_parameters.mPartData.mBlendFuncSource   = LLPartData::LL_PART_BF_SOURCE_COLOR;
+            particle_parameters.mPartData.mBlendFuncDest     = LLPartData::LL_PART_BF_SOURCE_ALPHA;
+
+            particle_parameters.mPartImageID                 = sCloudTexture->getID();
+            particle_parameters.mMaxAge                      = 0.f;
+            particle_parameters.mPattern                     = LLPartSysData::LL_PART_SRC_PATTERN_EXPLODE;
+            particle_parameters.mInnerAngle                  = 0.f;
+            particle_parameters.mOuterAngle                  = 0.f;
+            particle_parameters.mBurstRate                   = 0.02f;
+            particle_parameters.mBurstRadius                 = 0.0f;
+            particle_parameters.mBurstPartCount              = 1;
+            particle_parameters.mBurstSpeedMin               = 0.01f;
+            particle_parameters.mBurstSpeedMax               = 0.6f;
+            particle_parameters.mPartData.mFlags             = ( LLPartData::LL_PART_INTERP_COLOR_MASK | LLPartData::LL_PART_INTERP_SCALE_MASK |
+                                                                 LLPartData::LL_PART_EMISSIVE_MASK | LLPartData::LL_PART_FOLLOW_SRC_MASK |
+                                                                 LLPartData::LL_PART_TARGET_POS_MASK );
+
+            // do not generate particles for dummy or overly-complex avatars
+            if (!mIsDummy && !isTooComplex() && !isTooSlow())
+            {
+                setParticleSource(particle_parameters, getID());
+            }
+        }
+    }
+}
 
 void LLVOAvatar::idleUpdateWindEffect()
 {
-	// update wind effect
-	if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_AVATAR) >= LLDrawPoolAvatar::SHADER_LEVEL_CLOTH))
-	{
-		F32 hover_strength = 0.f;
-		F32 time_delta = mRippleTimer.getElapsedTimeF32() - mRippleTimeLast;
-		mRippleTimeLast = mRippleTimer.getElapsedTimeF32();
-		LLVector3 velocity = getVelocity();
-		F32 speed = velocity.length();
-		//RN: velocity varies too much frame to frame for this to work
-		mRippleAccel.clearVec();//lerp(mRippleAccel, (velocity - mLastVel) * time_delta, LLSmoothInterpolation::getInterpolant(0.02f));
-		mLastVel = velocity;
-		LLVector4 wind;
-		wind.setVec(getRegion()->mWind.getVelocityNoisy(getPositionAgent(), 4.f) - velocity);
-
-		if (mInAir)
-		{
-			hover_strength = HOVER_EFFECT_STRENGTH * llmax(0.f, HOVER_EFFECT_MAX_SPEED - speed);
-		}
-
-		if (mBelowWater)
-		{
-			// TODO: make cloth flow more gracefully when underwater
-			hover_strength += UNDERWATER_EFFECT_STRENGTH;
-		}
-
-		wind.mV[VZ] += hover_strength;
-		wind.normalize();
-
-		wind.mV[VW] = llmin(0.025f + (speed * 0.015f) + hover_strength, 0.5f);
-		F32 interp;
-		if (wind.mV[VW] > mWindVec.mV[VW])
-		{
-			interp = LLSmoothInterpolation::getInterpolant(0.2f);
-		}
-		else
-		{
-			interp = LLSmoothInterpolation::getInterpolant(0.4f);
-		}
-		mWindVec = lerp(mWindVec, wind, interp);
-	
-		F32 wind_freq = hover_strength + llclamp(8.f + (speed * 0.7f) + (noise1(mRipplePhase) * 4.f), 8.f, 25.f);
-		mWindFreq = ll_lerp(mWindFreq, wind_freq, interp);
-
-		if (mBelowWater)
-		{
-			mWindFreq *= UNDERWATER_FREQUENCY_DAMP;
-		}
-
-		mRipplePhase += (time_delta * mWindFreq);
-		if (mRipplePhase > F_TWO_PI)
-		{
-			mRipplePhase = fmodf(mRipplePhase, F_TWO_PI);
-		}
-	}
+    // update wind effect
+    if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_AVATAR) >= LLDrawPoolAvatar::SHADER_LEVEL_CLOTH))
+    {
+        F32 hover_strength = 0.f;
+        F32 time_delta = mRippleTimer.getElapsedTimeF32() - mRippleTimeLast;
+        mRippleTimeLast = mRippleTimer.getElapsedTimeF32();
+        LLVector3 velocity = getVelocity();
+        F32 speed = velocity.length();
+        //RN: velocity varies too much frame to frame for this to work
+        mRippleAccel.clearVec();//lerp(mRippleAccel, (velocity - mLastVel) * time_delta, LLSmoothInterpolation::getInterpolant(0.02f));
+        mLastVel = velocity;
+        LLVector4 wind;
+        wind.setVec(getRegion()->mWind.getVelocityNoisy(getPositionAgent(), 4.f) - velocity);
+
+        if (mInAir)
+        {
+            hover_strength = HOVER_EFFECT_STRENGTH * llmax(0.f, HOVER_EFFECT_MAX_SPEED - speed);
+        }
+
+        if (mBelowWater)
+        {
+            // TODO: make cloth flow more gracefully when underwater
+            hover_strength += UNDERWATER_EFFECT_STRENGTH;
+        }
+
+        wind.mV[VZ] += hover_strength;
+        wind.normalize();
+
+        wind.mV[VW] = llmin(0.025f + (speed * 0.015f) + hover_strength, 0.5f);
+        F32 interp;
+        if (wind.mV[VW] > mWindVec.mV[VW])
+        {
+            interp = LLSmoothInterpolation::getInterpolant(0.2f);
+        }
+        else
+        {
+            interp = LLSmoothInterpolation::getInterpolant(0.4f);
+        }
+        mWindVec = lerp(mWindVec, wind, interp);
+
+        F32 wind_freq = hover_strength + llclamp(8.f + (speed * 0.7f) + (noise1(mRipplePhase) * 4.f), 8.f, 25.f);
+        mWindFreq = ll_lerp(mWindFreq, wind_freq, interp);
+
+        if (mBelowWater)
+        {
+            mWindFreq *= UNDERWATER_FREQUENCY_DAMP;
+        }
+
+        mRipplePhase += (time_delta * mWindFreq);
+        if (mRipplePhase > F_TWO_PI)
+        {
+            mRipplePhase = fmodf(mRipplePhase, F_TWO_PI);
+        }
+    }
 }
 
 void LLVOAvatar::idleUpdateNameTag(const LLVector3& root_pos_last)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
 
-	// update chat bubble
-	//--------------------------------------------------------------------
-	// draw text label over character's head
-	//--------------------------------------------------------------------
-	if (mChatTimer.getElapsedTimeF32() > BUBBLE_CHAT_TIME)
-	{
-		mChats.clear();
-	}
-	
-	const F32 time_visible = mTimeVisible.getElapsedTimeF32();
-	static const LLCachedControl<F32> NAME_SHOW_TIME(gSavedSettings, "RenderNameShowTime");	// seconds
-	static const LLCachedControl<F32> FADE_DURATION(gSavedSettings, "RenderNameFadeDuration"); // seconds
+    // update chat bubble
+    //--------------------------------------------------------------------
+    // draw text label over character's head
+    //--------------------------------------------------------------------
+    if (mChatTimer.getElapsedTimeF32() > BUBBLE_CHAT_TIME)
+    {
+        mChats.clear();
+    }
+
+    const F32 time_visible = mTimeVisible.getElapsedTimeF32();
+    static const LLCachedControl<F32> NAME_SHOW_TIME(gSavedSettings, "RenderNameShowTime"); // seconds
+    static const LLCachedControl<F32> FADE_DURATION(gSavedSettings, "RenderNameFadeDuration"); // seconds
     static LLCachedControl<bool> use_chat_bubbles(gSavedSettings, "UseChatBubbles");
 // [RLVa:KB] - Checked: RLVa-2.0.1
-	bool fRlvShowAvTag = true, fRlvShowAvName = true;
-	if (RlvActions::isRlvEnabled())
-	{
-		fRlvShowAvTag = RlvActions::canShowNameTag(this);
-		fRlvShowAvName = (fRlvShowAvTag) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, getID()));
-	}
+    bool fRlvShowAvTag = true, fRlvShowAvName = true;
+    if (RlvActions::isRlvEnabled())
+    {
+        fRlvShowAvTag = RlvActions::canShowNameTag(this);
+        fRlvShowAvName = (fRlvShowAvTag) && (RlvActions::canShowName(RlvActions::SNC_DEFAULT, getID()));
+    }
 // [/RLVa:KB]
-	bool visible_chat = use_chat_bubbles && (mChats.size() || mTyping);
-	bool render_name =	visible_chat ||
+    bool visible_chat = use_chat_bubbles && (mChats.size() || mTyping);
+    bool render_name =  visible_chat ||
 // [RLVa:KB] - Checked: RLVa-2.0.1
-		((fRlvShowAvTag) &&
-		 ((sRenderName == RENDER_NAME_ALWAYS) ||
-		  (sRenderName == RENDER_NAME_FADE && time_visible < NAME_SHOW_TIME)));
+        ((fRlvShowAvTag) &&
+         ((sRenderName == RENDER_NAME_ALWAYS) ||
+          (sRenderName == RENDER_NAME_FADE && time_visible < NAME_SHOW_TIME)));
 // [/RLVa:KB]
-//		(((sRenderName == RENDER_NAME_ALWAYS) ||
-//		  (sRenderName == RENDER_NAME_FADE && time_visible < NAME_SHOW_TIME)));
-	// If it's your own avatar, don't draw in mouselook, and don't
-	// draw if we're specifically hiding our own name.
-	if (isSelf())
-	{
-		static const LLCachedControl<bool> render_name_show_self(gSavedSettings, "RenderNameShowSelf");
-		render_name = render_name
-			&& !gAgentCamera.cameraMouselook()
-			&& (visible_chat || (render_name_show_self && sRenderName));
-	}
-
-	if ( !render_name )
-	{
-		if (mNameText)
-		{
-			// ...clean up old name tag
-			mNameText->markDead();
-			mNameText = NULL;
-			sNumVisibleChatBubbles--;
-		}
-		return;
-	}
-
-	bool new_name = FALSE;
-	if (visible_chat != mVisibleChat)
-	{
-		mVisibleChat = visible_chat;
-		new_name = TRUE;
-	}
+//      (((sRenderName == RENDER_NAME_ALWAYS) ||
+//        (sRenderName == RENDER_NAME_FADE && time_visible < NAME_SHOW_TIME)));
+    // If it's your own avatar, don't draw in mouselook, and don't
+    // draw if we're specifically hiding our own name.
+    if (isSelf())
+    {
+        static const LLCachedControl<bool> render_name_show_self(gSavedSettings, "RenderNameShowSelf");
+        render_name = render_name
+            && !gAgentCamera.cameraMouselook()
+            && (visible_chat || (render_name_show_self && sRenderName));
+    }
+
+    if ( !render_name )
+    {
+        if (mNameText)
+        {
+            // ...clean up old name tag
+            mNameText->markDead();
+            mNameText = NULL;
+            sNumVisibleChatBubbles--;
+        }
+        return;
+    }
+
+    bool new_name = FALSE;
+    if (visible_chat != mVisibleChat)
+    {
+        mVisibleChat = visible_chat;
+        new_name = TRUE;
+    }
 
 // [RLVa:KB] - Checked: RLVa-0.2.0
-	if (!fRlvShowAvName)
-	{
-		if (mRenderGroupTitles)
-		{
-			mRenderGroupTitles = FALSE;
-			new_name = TRUE;
-		}
-	}
-	else if (sRenderGroupTitles != mRenderGroupTitles)
+    if (!fRlvShowAvName)
+    {
+        if (mRenderGroupTitles)
+        {
+            mRenderGroupTitles = FALSE;
+            new_name = TRUE;
+        }
+    }
+    else if (sRenderGroupTitles != mRenderGroupTitles)
 // [/RLVa]
-//	if (sRenderGroupTitles != mRenderGroupTitles)
-	{
-		mRenderGroupTitles = sRenderGroupTitles;
-		new_name = TRUE;
-	}
-
-	// First Calculate Alpha
-	// If alpha > 0, create mNameText if necessary, otherwise delete it
-	F32 alpha = 0.f;
-	if (mAppAngle > 5.f)
-	{
-		const F32 START_FADE_TIME = NAME_SHOW_TIME - FADE_DURATION;
-		if (!visible_chat && sRenderName == RENDER_NAME_FADE && time_visible > START_FADE_TIME)
-		{
-			alpha = 1.f - (time_visible - START_FADE_TIME) / FADE_DURATION;
-		}
-		else
-		{
-			// ...not fading, full alpha
-			alpha = 1.f;
-		}
-	}
-	else if (mAppAngle > 2.f)
-	{
-		// far away is faded out also
-		alpha = (mAppAngle-2.f)/3.f;
-	}
-
-	if (alpha <= 0.f)
-	{
-		if (mNameText)
-		{
-			mNameText->markDead();
-			mNameText = NULL;
-			sNumVisibleChatBubbles--;
-		}
-		return;
-	}
-
-	if (!mNameText)
-	{
-		mNameText = static_cast<LLHUDNameTag*>( LLHUDObject::addHUDObject(
-			LLHUDObject::LL_HUD_NAME_TAG) );
-		//mNameText->setMass(10.f);
-		mNameText->setSourceObject(this);
-		mNameText->setVertAlignment(LLHUDNameTag::ALIGN_VERT_TOP);
-		mNameText->setVisibleOffScreen(TRUE);
-		mNameText->setMaxLines(11);
-		mNameText->setFadeDistance(CHAT_NORMAL_RADIUS, 5.f);
-		sNumVisibleChatBubbles++;
-		new_name = TRUE;
-    }
-				
+//  if (sRenderGroupTitles != mRenderGroupTitles)
+    {
+        mRenderGroupTitles = sRenderGroupTitles;
+        new_name = TRUE;
+    }
+
+    // First Calculate Alpha
+    // If alpha > 0, create mNameText if necessary, otherwise delete it
+    F32 alpha = 0.f;
+    if (mAppAngle > 5.f)
+    {
+        const F32 START_FADE_TIME = NAME_SHOW_TIME - FADE_DURATION;
+        if (!visible_chat && sRenderName == RENDER_NAME_FADE && time_visible > START_FADE_TIME)
+        {
+            alpha = 1.f - (time_visible - START_FADE_TIME) / FADE_DURATION;
+        }
+        else
+        {
+            // ...not fading, full alpha
+            alpha = 1.f;
+        }
+    }
+    else if (mAppAngle > 2.f)
+    {
+        // far away is faded out also
+        alpha = (mAppAngle-2.f)/3.f;
+    }
+
+    if (alpha <= 0.f)
+    {
+        if (mNameText)
+        {
+            mNameText->markDead();
+            mNameText = NULL;
+            sNumVisibleChatBubbles--;
+        }
+        return;
+    }
+
+    if (!mNameText)
+    {
+        mNameText = static_cast<LLHUDNameTag*>( LLHUDObject::addHUDObject(
+            LLHUDObject::LL_HUD_NAME_TAG) );
+        //mNameText->setMass(10.f);
+        mNameText->setSourceObject(this);
+        mNameText->setVertAlignment(LLHUDNameTag::ALIGN_VERT_TOP);
+        mNameText->setVisibleOffScreen(TRUE);
+        mNameText->setMaxLines(11);
+        mNameText->setFadeDistance(CHAT_NORMAL_RADIUS, 5.f);
+        sNumVisibleChatBubbles++;
+        new_name = TRUE;
+    }
+
     mNameText->setPositionAgent(root_pos_last);
 
-	idleUpdateNameTagText(new_name);			
-	idleUpdateNameTagAlpha(new_name, alpha);
+    idleUpdateNameTagText(new_name);
+    idleUpdateNameTagAlpha(new_name, alpha);
 }
 
 void LLVOAvatar::idleUpdateNameTagText(bool new_name)
 {
-	LLNameValue *title = getNVPair("Title");
-	LLNameValue* firstname = getNVPair("FirstName");
-	LLNameValue* lastname = getNVPair("LastName");
+    LLNameValue *title = getNVPair("Title");
+    LLNameValue* firstname = getNVPair("FirstName");
+    LLNameValue* lastname = getNVPair("LastName");
 
-	// Avatars must have a first and last name
-	if (!firstname || !lastname) return;
+    // Avatars must have a first and last name
+    if (!firstname || !lastname) return;
 
-	static const F32 chat_range_whisper_squared = 10 * 10;
-	static const F32 chat_range_say_squared = 20 * 20;
-	static const F32 chat_range_shout_squared = 100 * 100;
+    static const F32 chat_range_whisper_squared = 10 * 10;
+    static const F32 chat_range_say_squared = 20 * 20;
+    static const F32 chat_range_shout_squared = 100 * 100;
 
 // [RLVa:KB] - Checked: RLVa-2.0.1
-	bool fRlvShowAvName = RlvActions::canShowName(RlvActions::SNC_DEFAULT, getID());
+    bool fRlvShowAvName = RlvActions::canShowName(RlvActions::SNC_DEFAULT, getID());
+// [/RLVa:KB]
+    bool is_away = mSignaledAnimations.find(ANIM_AGENT_AWAY)  != mSignaledAnimations.end();
+    bool is_do_not_disturb = mSignaledAnimations.find(ANIM_AGENT_DO_NOT_DISTURB) != mSignaledAnimations.end();
+    bool is_appearance = mSignaledAnimations.find(ANIM_AGENT_CUSTOMIZE) != mSignaledAnimations.end();
+    bool is_muted;
+    if (isSelf())
+    {
+        is_muted = false;
+    }
+    else
+    {
+        is_muted = isInMuteList();
+    }
+//  bool is_friend = LLAvatarTracker::instance().isBuddy(getID());
+// [RLVa:KB] - Checked: RLVa-1.2.2
+    bool is_friend = (fRlvShowAvName) && isInBuddyList();
+// [/RLVa:KB]
+    bool is_cloud = getIsCloud();
+    static LLCachedControl<bool> sShowTyping(gSavedSettings, "AlchemyNearbyTypingIndicators", true);
+    static LLCachedControl<bool> use_chat_bubble(gSavedSettings, "UseChatBubbles");
+    bool is_typing = !isSelf() && sShowTyping && mTyping;
+    if (is_appearance != mNameAppearance)
+    {
+        if (is_appearance)
+        {
+            debugAvatarRezTime("AvatarRezEnteredAppearanceNotification","entered appearance mode");
+        }
+        else
+        {
+            debugAvatarRezTime("AvatarRezLeftAppearanceNotification","left appearance mode");
+        }
+    }
+
+    LLColor4 name_tag_color = getNameTagColor(is_friend);
+    LLColor4 distance_color = name_tag_color;
+    std::string distance_string;
+
+    static LLCachedControl<bool> show_distance_color_tag(gSavedSettings, "NameTagShowDistanceColors", false);
+    static LLCachedControl<bool> show_distance_in_tag(gSavedSettings, "NameTagShowDistance", true);
+    static LLUIColor tag_whisper_color = LLUIColorTable::instance().getColor("NameTagWhisperDistanceColor", LLColor4::green);
+    static LLUIColor tag_chat_color = LLUIColorTable::instance().getColor("NameTagChatDistanceColor", LLColor4::green);
+    static LLUIColor tag_shout_color = LLUIColorTable::instance().getColor("NameTagShoutDistanceColor", LLColor4::yellow);
+    static LLUIColor tag_beyond_shout_color = LLUIColorTable::instance().getColor("NameTagBeyondShoutDistanceColor", LLColor4::red);
+
+    if (!isSelf() && (show_distance_color_tag || show_distance_in_tag))
+    {
+        F64 distance_squared = dist_vec_squared(getPositionGlobal(), gAgent.getPositionGlobal());
+        if (distance_squared <= chat_range_whisper_squared)
+        {
+            distance_color = tag_whisper_color;
+        }
+        else if (distance_squared <= chat_range_say_squared)
+        {
+            distance_color = tag_chat_color;
+        }
+        else if (distance_squared <= chat_range_shout_squared)
+        {
+            distance_color = tag_shout_color;
+        }
+        else
+        {
+            distance_color = tag_beyond_shout_color;
+        }
+
+        if (show_distance_in_tag)
+        {
+            distance_string = llformat("%.02f m", sqrt(distance_squared));
+        }
+
+        // Override nametag color only if friend color is disabled
+        // or avatar is not a friend nor has a contact set color
+        static LLCachedControl<bool> show_friends(gSavedSettings, "NameTagShowFriends");
+        bool special_color_override = show_friends && is_friend;
+        if (show_distance_color_tag && !special_color_override)
+        {
+            name_tag_color = distance_color;
+        }
+    }
+
+    // Rebuild name tag if state change detected
+    if (!mNameIsSet
+        || new_name
+        || (!title && !mTitle.empty())
+        || (title && mTitle != title->getString())
+        || is_away != mNameAway
+        || is_do_not_disturb != mNameDoNotDisturb
+        || is_muted != mNameMute
+        || is_appearance != mNameAppearance
+        || is_friend != mNameFriend
+        || is_cloud != mNameCloud
+        || is_typing != mTypingLast
+        || distance_string != mDistanceString
+        || name_tag_color != mNameTagColor)
+    {
+        clearNameTag();
+
+        if (is_away || is_muted || is_do_not_disturb || is_appearance || (is_typing && !use_chat_bubble))
+        {
+            static const std::string avatar_away_str = LLTrans::getString("AvatarAway");
+            static const std::string avatar_dnd_str = LLTrans::getString("AvatarDoNotDisturb");
+            static const std::string avatar_muted_str = LLTrans::getString("AvatarMuted");
+            static const std::string avatar_edit_appr_str = LLTrans::getString("AvatarEditingAppearance");
+            static const std::string avatar_loading_data_str = LLTrans::getString("LoadingData");
+            static const std::string avatar_typing_str = LLTrans::getString("AvatarTyping");
+
+            std::string line;
+            if (is_away)
+            {
+                line += avatar_away_str;
+                line += ", ";
+            }
+            if (is_do_not_disturb)
+            {
+                line += avatar_dnd_str;
+                line += ", ";
+            }
+            if (is_muted)
+            {
+                line += avatar_muted_str;
+                line += ", ";
+            }
+            if (is_appearance)
+            {
+                line += avatar_edit_appr_str;
+                line += ", ";
+            }
+            if (is_cloud)
+            {
+                line += avatar_loading_data_str;
+                line += ", ";
+            }
+            if (is_typing)
+            {
+                line += avatar_typing_str;
+                line += ", ";
+            }
+            // trim last ", "
+            line.resize( line.length() - 2 );
+            addNameTagLine(line, name_tag_color, LLFontGL::NORMAL,
+                LLFontGL::getFontSansSerifSmall());
+        }
+
+//      if (sRenderGroupTitles
+// [RLVa:KB] - Checked: RLVa-1.2.2
+        if (sRenderGroupTitles && fRlvShowAvName
 // [/RLVa:KB]
-	bool is_away = mSignaledAnimations.find(ANIM_AGENT_AWAY)  != mSignaledAnimations.end();
-	bool is_do_not_disturb = mSignaledAnimations.find(ANIM_AGENT_DO_NOT_DISTURB) != mSignaledAnimations.end();
-	bool is_appearance = mSignaledAnimations.find(ANIM_AGENT_CUSTOMIZE) != mSignaledAnimations.end();
-	bool is_muted;
-	if (isSelf())
-	{
-		is_muted = false;
-	}
-	else
-	{
-		is_muted = isInMuteList();
-	}
-//	bool is_friend = LLAvatarTracker::instance().isBuddy(getID());
+            && title && title->getString() && title->getString()[0] != '\0')
+        {
+            std::string title_str = title->getString();
+            LLStringFn::replace_ascii_controlchars(title_str,LL_UNKNOWN_CHAR);
+            addNameTagLine(title_str, name_tag_color, LLFontGL::NORMAL,
+                LLFontGL::getFontSansSerifSmall(), true);
+        }
+
+        static LLUICachedControl<bool> show_display_names("NameTagShowDisplayNames", true);
+        static LLUICachedControl<bool> show_usernames("NameTagShowUsernames", true);
+
+        if (LLAvatarName::useDisplayNames())
+        {
+            LLAvatarName av_name;
+            if (!LLAvatarNameCache::get(getID(), &av_name))
+            {
+                // Force a rebuild at next idle
+                // Note: do not connect a callback on idle().
+                clearNameTag();
+            }
+
 // [RLVa:KB] - Checked: RLVa-1.2.2
-	bool is_friend = (fRlvShowAvName) && isInBuddyList();
+            if ( (fRlvShowAvName) || (isSelf()) )
+            {
+// [/RLVa:KB]
+                // Might be blank if name not available yet, that's OK
+                if (show_display_names)
+                {
+                    addNameTagLine(av_name.getDisplayName(), name_tag_color, LLFontGL::NORMAL,
+                        LLFontGL::getFontSansSerif(), true);
+                }
+                // Suppress SLID display if display name matches exactly (ugh)
+                if (show_usernames && !av_name.isDisplayNameDefault())
+                {
+                    // *HACK: Desaturate the color
+                    LLColor4 username_color = name_tag_color * 0.83f;
+                    addNameTagLine(av_name.getUserName(), username_color, LLFontGL::NORMAL,
+                    LLFontGL::getFontSansSerifSmall(), true);
+                }
+// [RLVa:KB] - Checked: RLVa-1.2.2
+            }
+            else
+            {
+                addNameTagLine(RlvStrings::getAnonym(av_name), name_tag_color, LLFontGL::NORMAL, LLFontGL::getFontSansSerif(), true);
+            }
 // [/RLVa:KB]
-	bool is_cloud = getIsCloud();
-	static LLCachedControl<bool> sShowTyping(gSavedSettings, "AlchemyNearbyTypingIndicators", true);
-	static LLCachedControl<bool> use_chat_bubble(gSavedSettings, "UseChatBubbles");
-	bool is_typing = !isSelf() && sShowTyping && mTyping;
-	if (is_appearance != mNameAppearance)
-	{
-		if (is_appearance)
-		{
-			debugAvatarRezTime("AvatarRezEnteredAppearanceNotification","entered appearance mode");
-		}
-		else
-		{
-			debugAvatarRezTime("AvatarRezLeftAppearanceNotification","left appearance mode");
-		}
-	}
-
-	LLColor4 name_tag_color = getNameTagColor(is_friend);
-	LLColor4 distance_color = name_tag_color;
-	std::string distance_string;
-
-	static LLCachedControl<bool> show_distance_color_tag(gSavedSettings, "NameTagShowDistanceColors", false);
-	static LLCachedControl<bool> show_distance_in_tag(gSavedSettings, "NameTagShowDistance", true);
-	static LLUIColor tag_whisper_color = LLUIColorTable::instance().getColor("NameTagWhisperDistanceColor", LLColor4::green);
-	static LLUIColor tag_chat_color = LLUIColorTable::instance().getColor("NameTagChatDistanceColor", LLColor4::green);
-	static LLUIColor tag_shout_color = LLUIColorTable::instance().getColor("NameTagShoutDistanceColor", LLColor4::yellow);
-	static LLUIColor tag_beyond_shout_color = LLUIColorTable::instance().getColor("NameTagBeyondShoutDistanceColor", LLColor4::red);
-
-	if (!isSelf() && (show_distance_color_tag || show_distance_in_tag))
-	{
-		F64 distance_squared = dist_vec_squared(getPositionGlobal(), gAgent.getPositionGlobal());
-		if (distance_squared <= chat_range_whisper_squared)
-		{
-			distance_color = tag_whisper_color;
-		}
-		else if (distance_squared <= chat_range_say_squared)
-		{
-			distance_color = tag_chat_color;
-		}
-		else if (distance_squared <= chat_range_shout_squared)
-		{
-			distance_color = tag_shout_color;
-		}
-		else
-		{
-			distance_color = tag_beyond_shout_color;
-		}
-
-		if (show_distance_in_tag)
-		{
-			distance_string = llformat("%.02f m", sqrt(distance_squared));
-		}
-
-		// Override nametag color only if friend color is disabled
-		// or avatar is not a friend nor has a contact set color
-		static LLCachedControl<bool> show_friends(gSavedSettings, "NameTagShowFriends");
-		bool special_color_override = show_friends && is_friend;
-		if (show_distance_color_tag && !special_color_override)
-		{
-			name_tag_color = distance_color;
-		}
-	}
-
-	// Rebuild name tag if state change detected
-	if (!mNameIsSet
-		|| new_name
-		|| (!title && !mTitle.empty())
-		|| (title && mTitle != title->getString())
-		|| is_away != mNameAway 
-		|| is_do_not_disturb != mNameDoNotDisturb 
-		|| is_muted != mNameMute
-		|| is_appearance != mNameAppearance 
-		|| is_friend != mNameFriend
-		|| is_cloud != mNameCloud
-		|| is_typing != mTypingLast
-		|| distance_string != mDistanceString
-		|| name_tag_color != mNameTagColor)
-	{
-		clearNameTag();
-
-		if (is_away || is_muted || is_do_not_disturb || is_appearance || (is_typing && !use_chat_bubble))
-		{
-			static const std::string avatar_away_str = LLTrans::getString("AvatarAway");
-			static const std::string avatar_dnd_str = LLTrans::getString("AvatarDoNotDisturb");
-			static const std::string avatar_muted_str = LLTrans::getString("AvatarMuted");
-			static const std::string avatar_edit_appr_str = LLTrans::getString("AvatarEditingAppearance");
-			static const std::string avatar_loading_data_str = LLTrans::getString("LoadingData");
-			static const std::string avatar_typing_str = LLTrans::getString("AvatarTyping");
-
-			std::string line;
-			if (is_away)
-			{
-				line += avatar_away_str;
-				line += ", ";
-			}
-			if (is_do_not_disturb)
-			{
-				line += avatar_dnd_str;
-				line += ", ";
-			}
-			if (is_muted)
-			{
-				line += avatar_muted_str;
-				line += ", ";
-			}
-			if (is_appearance)
-			{
-				line += avatar_edit_appr_str;
-				line += ", ";
-			}
-			if (is_cloud)
-			{
-				line += avatar_loading_data_str;
-				line += ", ";
-			}
-			if (is_typing)
-			{
-				line += avatar_typing_str;
-				line += ", ";
-			}
-			// trim last ", "
-			line.resize( line.length() - 2 );
-			addNameTagLine(line, name_tag_color, LLFontGL::NORMAL,
-				LLFontGL::getFontSansSerifSmall());
-		}
-
-//		if (sRenderGroupTitles
+        }
+        else
+        {
+            const LLFontGL* font = LLFontGL::getFontSansSerif();
+            std::string full_name = LLCacheName::buildFullName( firstname->getString(), lastname->getString() );
 // [RLVa:KB] - Checked: RLVa-1.2.2
-		if (sRenderGroupTitles && fRlvShowAvName
+            if ( (!fRlvShowAvName) && (!isSelf()) )
+            {
+                full_name = RlvStrings::getAnonym(full_name);
+            }
 // [/RLVa:KB]
-			&& title && title->getString() && title->getString()[0] != '\0')
-		{
-			std::string title_str = title->getString();
-			LLStringFn::replace_ascii_controlchars(title_str,LL_UNKNOWN_CHAR);
-			addNameTagLine(title_str, name_tag_color, LLFontGL::NORMAL,
-				LLFontGL::getFontSansSerifSmall(), true);
-		}
-
-		static LLUICachedControl<bool> show_display_names("NameTagShowDisplayNames", true);
-		static LLUICachedControl<bool> show_usernames("NameTagShowUsernames", true);
-
-		if (LLAvatarName::useDisplayNames())
-		{
-			LLAvatarName av_name;
-			if (!LLAvatarNameCache::get(getID(), &av_name))
-			{
-				// Force a rebuild at next idle
-				// Note: do not connect a callback on idle().
-				clearNameTag();
-			}
+            addNameTagLine(full_name, name_tag_color, LLFontGL::NORMAL, font, true);
+        }
+
+        if (show_distance_in_tag)
+        {
+            addNameTagLine(distance_string, distance_color, LLFontGL::NORMAL, LLFontGL::getFontSansSerifSmall());
+        }
+
+        mNameAway = is_away;
+        mNameDoNotDisturb = is_do_not_disturb;
+        mNameMute = is_muted;
+        mNameAppearance = is_appearance;
+        mNameFriend = is_friend;
+        mNameCloud = is_cloud;
+        mTypingLast = is_typing;
+        mDistanceString = distance_string;
+        mTitle = title ? title->getString() : "";
+        mNameTagColor = name_tag_color;
+        LLStringFn::replace_ascii_controlchars(mTitle,LL_UNKNOWN_CHAR);
+        new_name = TRUE;
+    }
+
+    if (mVisibleChat)
+    {
+        mNameText->setFont(LLFontGL::getFontSansSerif());
+        mNameText->setTextAlignment(LLHUDNameTag::ALIGN_TEXT_LEFT);
+        mNameText->setFadeDistance(CHAT_NORMAL_RADIUS * 2.f, 5.f);
+
+        std::deque<LLChat>::iterator chat_iter = mChats.begin(), chat_iter_end = mChats.end();
+        mNameText->clearString();
+
+        static LLUIColor agent_chat_color = LLUIColorTable::instance().getColor(isSelf() ? "UserChatColor" : "AgentChatColor");
+
+        LLColor4 new_chat = ALAvatarGroups::instance().getAvatarColor(getID(), agent_chat_color, ALAvatarGroups::COLOR_CHAT);
+        LLColor4 normal_chat = lerp(new_chat, LLColor4(0.8f, 0.8f, 0.8f, 1.f), 0.7f);
+        LLColor4 old_chat = lerp(normal_chat, LLColor4(0.6f, 0.6f, 0.6f, 1.f), 0.7f);
+        if (mTyping && mChats.size() >= MAX_BUBBLE_CHAT_UTTERANCES)
+        {
+            ++chat_iter;
+        }
+
+        for(; chat_iter != chat_iter_end; ++chat_iter)
+        {
+            F32 chat_fade_amt = llclamp((F32)((LLFrameTimer::getElapsedSeconds() - chat_iter->mTime) / CHAT_FADE_TIME), 0.f, 4.f);
+            LLFontGL::StyleFlags style;
+            switch(chat_iter->mChatType)
+            {
+            case CHAT_TYPE_WHISPER:
+                style = LLFontGL::ITALIC;
+                break;
+            case CHAT_TYPE_SHOUT:
+                style = LLFontGL::BOLD;
+                break;
+            default:
+                style = LLFontGL::NORMAL;
+                break;
+            }
+            if (chat_fade_amt < 1.f)
+            {
+                F32 u = clamp_rescale(chat_fade_amt, 0.9f, 1.f, 0.f, 1.f);
+                mNameText->addLine(chat_iter->mText, lerp(new_chat, normal_chat, u), style);
+            }
+            else if (chat_fade_amt < 2.f)
+            {
+                F32 u = clamp_rescale(chat_fade_amt, 1.9f, 2.f, 0.f, 1.f);
+                mNameText->addLine(chat_iter->mText, lerp(normal_chat, old_chat, u), style);
+            }
+            else if (chat_fade_amt < 3.f)
+            {
+                // *NOTE: only remove lines down to minimum number
+                mNameText->addLine(chat_iter->mText, old_chat, style);
+            }
+        }
+        mNameText->setVisibleOffScreen(TRUE);
 
-// [RLVa:KB] - Checked: RLVa-1.2.2
-			if ( (fRlvShowAvName) || (isSelf()) )
-			{
-// [/RLVa:KB]
-				// Might be blank if name not available yet, that's OK
-				if (show_display_names)
-				{
-					addNameTagLine(av_name.getDisplayName(), name_tag_color, LLFontGL::NORMAL,
-						LLFontGL::getFontSansSerif(), true);
-				}
-				// Suppress SLID display if display name matches exactly (ugh)
-				if (show_usernames && !av_name.isDisplayNameDefault())
-				{
-					// *HACK: Desaturate the color
-					LLColor4 username_color = name_tag_color * 0.83f;
-					addNameTagLine(av_name.getUserName(), username_color, LLFontGL::NORMAL,
-					LLFontGL::getFontSansSerifSmall(), true);
-				}
-// [RLVa:KB] - Checked: RLVa-1.2.2
-			}
-			else
-			{
-				addNameTagLine(RlvStrings::getAnonym(av_name), name_tag_color, LLFontGL::NORMAL, LLFontGL::getFontSansSerif(), true);
-			}
-// [/RLVa:KB]
-		}
-		else
-		{
-			const LLFontGL* font = LLFontGL::getFontSansSerif();
-			std::string full_name = LLCacheName::buildFullName( firstname->getString(), lastname->getString() );
-// [RLVa:KB] - Checked: RLVa-1.2.2
-			if ( (!fRlvShowAvName) && (!isSelf()) )
-			{
-				full_name = RlvStrings::getAnonym(full_name);
-			}
-// [/RLVa:KB]
-			addNameTagLine(full_name, name_tag_color, LLFontGL::NORMAL, font, true);
-		}
-
-		if (show_distance_in_tag)
-		{
-			addNameTagLine(distance_string, distance_color, LLFontGL::NORMAL, LLFontGL::getFontSansSerifSmall());
-		}
-
-		mNameAway = is_away;
-		mNameDoNotDisturb = is_do_not_disturb;
-		mNameMute = is_muted;
-		mNameAppearance = is_appearance;
-		mNameFriend = is_friend;
-		mNameCloud = is_cloud;
-		mTypingLast = is_typing;
-		mDistanceString = distance_string;
-		mTitle = title ? title->getString() : "";
-		mNameTagColor = name_tag_color;
-		LLStringFn::replace_ascii_controlchars(mTitle,LL_UNKNOWN_CHAR);
-		new_name = TRUE;
-	}
-
-	if (mVisibleChat)
-	{
-		mNameText->setFont(LLFontGL::getFontSansSerif());
-		mNameText->setTextAlignment(LLHUDNameTag::ALIGN_TEXT_LEFT);
-		mNameText->setFadeDistance(CHAT_NORMAL_RADIUS * 2.f, 5.f);
-
-		std::deque<LLChat>::iterator chat_iter = mChats.begin(), chat_iter_end = mChats.end();
-		mNameText->clearString();
-
-		static LLUIColor agent_chat_color = LLUIColorTable::instance().getColor(isSelf() ? "UserChatColor" : "AgentChatColor");
-		
-		LLColor4 new_chat = ALAvatarGroups::instance().getAvatarColor(getID(), agent_chat_color, ALAvatarGroups::COLOR_CHAT);
-		LLColor4 normal_chat = lerp(new_chat, LLColor4(0.8f, 0.8f, 0.8f, 1.f), 0.7f);
-		LLColor4 old_chat = lerp(normal_chat, LLColor4(0.6f, 0.6f, 0.6f, 1.f), 0.7f);
-		if (mTyping && mChats.size() >= MAX_BUBBLE_CHAT_UTTERANCES) 
-		{
-			++chat_iter;
-		}
-
-		for(; chat_iter != chat_iter_end; ++chat_iter)
-		{
-			F32 chat_fade_amt = llclamp((F32)((LLFrameTimer::getElapsedSeconds() - chat_iter->mTime) / CHAT_FADE_TIME), 0.f, 4.f);
-			LLFontGL::StyleFlags style;
-			switch(chat_iter->mChatType)
-			{
-			case CHAT_TYPE_WHISPER:
-				style = LLFontGL::ITALIC;
-				break;
-			case CHAT_TYPE_SHOUT:
-				style = LLFontGL::BOLD;
-				break;
-			default:
-				style = LLFontGL::NORMAL;
-				break;
-			}
-			if (chat_fade_amt < 1.f)
-			{
-				F32 u = clamp_rescale(chat_fade_amt, 0.9f, 1.f, 0.f, 1.f);
-				mNameText->addLine(chat_iter->mText, lerp(new_chat, normal_chat, u), style);
-			}
-			else if (chat_fade_amt < 2.f)
-			{
-				F32 u = clamp_rescale(chat_fade_amt, 1.9f, 2.f, 0.f, 1.f);
-				mNameText->addLine(chat_iter->mText, lerp(normal_chat, old_chat, u), style);
-			}
-			else if (chat_fade_amt < 3.f)
-			{
-				// *NOTE: only remove lines down to minimum number
-				mNameText->addLine(chat_iter->mText, old_chat, style);
-			}
-		}
-		mNameText->setVisibleOffScreen(TRUE);
-
-		if (is_typing)
-		{
-			S32 dot_count = (llfloor(mTypingTimer.getElapsedTimeF32() * 3.f) + 2) % 3 + 1;
-			switch(dot_count)
-			{
-			case 1:
-				mNameText->addLine(".", new_chat);
-				break;
-			case 2:
-				mNameText->addLine("..", new_chat);
-				break;
-			case 3:
-				mNameText->addLine("...", new_chat);
-				break;
-			}
-
-		}
-	}
-	else
-	{
-		// ...not using chat bubbles, just names
-		mNameText->setTextAlignment(LLHUDNameTag::ALIGN_TEXT_CENTER);
-		mNameText->setFadeDistance(CHAT_NORMAL_RADIUS, 5.f);
-		mNameText->setVisibleOffScreen(FALSE);
-	}
+        if (is_typing)
+        {
+            S32 dot_count = (llfloor(mTypingTimer.getElapsedTimeF32() * 3.f) + 2) % 3 + 1;
+            switch(dot_count)
+            {
+            case 1:
+                mNameText->addLine(".", new_chat);
+                break;
+            case 2:
+                mNameText->addLine("..", new_chat);
+                break;
+            case 3:
+                mNameText->addLine("...", new_chat);
+                break;
+            }
+
+        }
+    }
+    else
+    {
+        // ...not using chat bubbles, just names
+        mNameText->setTextAlignment(LLHUDNameTag::ALIGN_TEXT_CENTER);
+        mNameText->setFadeDistance(CHAT_NORMAL_RADIUS, 5.f);
+        mNameText->setVisibleOffScreen(FALSE);
+    }
 }
 
 void LLVOAvatar::addNameTagLine(const std::string& line, const LLColor4& color, S32 style, const LLFontGL* font, const bool use_ellipses)
 {
     // extra width (NAMETAG_MAX_WIDTH) is for names only, not for chat
-	llassert(mNameText);
-	if (mVisibleChat)
-	{
-		mNameText->addLabel(line, LLHUDNameTag::NAMETAG_MAX_WIDTH);
-	}
-	else
-	{
-		mNameText->addLine(line, color, (LLFontGL::StyleFlags)style, font, use_ellipses, LLHUDNameTag::NAMETAG_MAX_WIDTH);
-	}
+    llassert(mNameText);
+    if (mVisibleChat)
+    {
+        mNameText->addLabel(line, LLHUDNameTag::NAMETAG_MAX_WIDTH);
+    }
+    else
+    {
+        mNameText->addLine(line, color, (LLFontGL::StyleFlags)style, font, use_ellipses, LLHUDNameTag::NAMETAG_MAX_WIDTH);
+    }
     mNameIsSet |= !line.empty();
 }
 
 void LLVOAvatar::clearNameTag()
 {
     mNameIsSet = false;
-	if (mNameText)
-	{
-		mNameText->setLabel("");
-		mNameText->setString("");
-	}
-	mTimeVisible.reset();
+    if (mNameText)
+    {
+        mNameText->setLabel("");
+        mNameText->setString("");
+    }
+    mTimeVisible.reset();
 }
 
 //static
 void LLVOAvatar::invalidateNameTag(const LLUUID& agent_id)
 {
-	LLViewerObject* obj = gObjectList.findObject(agent_id);
-	if (!obj) return;
+    LLViewerObject* obj = gObjectList.findObject(agent_id);
+    if (!obj) return;
 
-	LLVOAvatar* avatar = obj->asAvatar();
-	if (!avatar) return;
+    LLVOAvatar* avatar = obj->asAvatar();
+    if (!avatar) return;
 
-	avatar->clearNameTag();
+    avatar->clearNameTag();
 }
 
 //static
 void LLVOAvatar::invalidateNameTags()
 {
-	for (LLCharacter* character : LLCharacter::sInstances)
-	{
-		LLVOAvatar* avatar = static_cast<LLVOAvatar*>(character);
-		if (!avatar) continue;
-		if (avatar->isDead()) continue;
+    for (LLCharacter* character : LLCharacter::sInstances)
+    {
+        LLVOAvatar* avatar = static_cast<LLVOAvatar*>(character);
+        if (!avatar) continue;
+        if (avatar->isDead()) continue;
 
-		avatar->clearNameTag();
-	}
+        avatar->clearNameTag();
+    }
 }
 
 // Compute name tag position during idle update
 LLVector3 LLVOAvatar::idleCalcNameTagPosition(const LLVector3 &root_pos_last)
 {
-	auto& viewerCamera = LLViewerCamera::instance();
-	LLQuaternion root_rot = mRoot->getWorldRotation();
-	LLQuaternion inv_root_rot = ~root_rot;
-	LLVector3 pixel_right_vec;
-	LLVector3 pixel_up_vec;
-	viewerCamera.getPixelVectors(root_pos_last, pixel_up_vec, pixel_right_vec);
-	LLVector3 camera_to_av = root_pos_last - viewerCamera.getOrigin();
-	camera_to_av.normalize();
-	LLVector3 local_camera_at = camera_to_av * inv_root_rot;
-	LLVector3 local_camera_up = camera_to_av % viewerCamera.getLeftAxis();
-	local_camera_up.normalize();
-	local_camera_up = local_camera_up * inv_root_rot;
-
-	// position is based on head position, does not require mAvatarOffset here. - Nyx
-	LLVector3 avatar_ellipsoid(mBodySize.mV[VX] * 0.4f,
-								mBodySize.mV[VY] * 0.4f,
-								mBodySize.mV[VZ] * NAMETAG_VERT_OFFSET_WEIGHT);
-
-	local_camera_up.scaleVec(avatar_ellipsoid);
-	local_camera_at.scaleVec(avatar_ellipsoid);
-
-	LLVector3 head_offset = (mHeadp->getLastWorldPosition() - mRoot->getLastWorldPosition()) * inv_root_rot;
-
-	if (dist_vec(head_offset, mTargetRootToHeadOffset) > NAMETAG_UPDATE_THRESHOLD)
-	{
-		mTargetRootToHeadOffset = head_offset;
-	}
-	
-	mCurRootToHeadOffset = lerp(mCurRootToHeadOffset, mTargetRootToHeadOffset, LLSmoothInterpolation::getInterpolant(0.2f));
-
-	LLVector3 name_position = mRoot->getLastWorldPosition() + (mCurRootToHeadOffset * root_rot);
-	name_position += (local_camera_up * root_rot) - (projected_vec(local_camera_at * root_rot, camera_to_av));	
-	name_position += pixel_up_vec * NAMETAG_VERTICAL_SCREEN_OFFSET;
-
-	const F32 water_height = getRegion()->getWaterHeight();
-	static const F32 WATER_HEIGHT_DELTA = 0.25f;
-	if (name_position[VZ] < water_height + WATER_HEIGHT_DELTA)
-	{
-		if (LLViewerCamera::getInstance()->getOrigin()[VZ] >= water_height)
-		{
-			name_position[VZ] = water_height;
-		}
-		else if (mNameText) // both camera and HUD are below watermark
-		{
-			F32 name_world_height = mNameText->getWorldHeight();
-			F32 max_z_position = water_height - name_world_height;
-			if (name_position[VZ] > max_z_position)
-			{
-				name_position[VZ] = max_z_position;
-			}
-		}
-	}
-
-	return name_position;
+    auto& viewerCamera = LLViewerCamera::instance();
+    LLQuaternion root_rot = mRoot->getWorldRotation();
+    LLQuaternion inv_root_rot = ~root_rot;
+    LLVector3 pixel_right_vec;
+    LLVector3 pixel_up_vec;
+    viewerCamera.getPixelVectors(root_pos_last, pixel_up_vec, pixel_right_vec);
+    LLVector3 camera_to_av = root_pos_last - viewerCamera.getOrigin();
+    camera_to_av.normalize();
+    LLVector3 local_camera_at = camera_to_av * inv_root_rot;
+    LLVector3 local_camera_up = camera_to_av % viewerCamera.getLeftAxis();
+    local_camera_up.normalize();
+    local_camera_up = local_camera_up * inv_root_rot;
+
+    // position is based on head position, does not require mAvatarOffset here. - Nyx
+    LLVector3 avatar_ellipsoid(mBodySize.mV[VX] * 0.4f,
+                                mBodySize.mV[VY] * 0.4f,
+                                mBodySize.mV[VZ] * NAMETAG_VERT_OFFSET_WEIGHT);
+
+    local_camera_up.scaleVec(avatar_ellipsoid);
+    local_camera_at.scaleVec(avatar_ellipsoid);
+
+    LLVector3 head_offset = (mHeadp->getLastWorldPosition() - mRoot->getLastWorldPosition()) * inv_root_rot;
+
+    if (dist_vec(head_offset, mTargetRootToHeadOffset) > NAMETAG_UPDATE_THRESHOLD)
+    {
+        mTargetRootToHeadOffset = head_offset;
+    }
+
+    mCurRootToHeadOffset = lerp(mCurRootToHeadOffset, mTargetRootToHeadOffset, LLSmoothInterpolation::getInterpolant(0.2f));
+
+    LLVector3 name_position = mRoot->getLastWorldPosition() + (mCurRootToHeadOffset * root_rot);
+    name_position += (local_camera_up * root_rot) - (projected_vec(local_camera_at * root_rot, camera_to_av));
+    name_position += pixel_up_vec * NAMETAG_VERTICAL_SCREEN_OFFSET;
+
+    const F32 water_height = getRegion()->getWaterHeight();
+    static const F32 WATER_HEIGHT_DELTA = 0.25f;
+    if (name_position[VZ] < water_height + WATER_HEIGHT_DELTA)
+    {
+        if (LLViewerCamera::getInstance()->getOrigin()[VZ] >= water_height)
+        {
+            name_position[VZ] = water_height;
+        }
+        else if (mNameText) // both camera and HUD are below watermark
+        {
+            F32 name_world_height = mNameText->getWorldHeight();
+            F32 max_z_position = water_height - name_world_height;
+            if (name_position[VZ] > max_z_position)
+            {
+                name_position[VZ] = max_z_position;
+            }
+        }
+    }
+
+    return name_position;
 }
 
 void LLVOAvatar::idleUpdateNameTagAlpha(bool new_name, F32 alpha)
 {
-	llassert(mNameText);
+    llassert(mNameText);
 
-	if (new_name
-		|| alpha != mNameAlpha)
-	{
-		mNameText->setAlpha(alpha);
-		mNameAlpha = alpha;
-	}
+    if (new_name
+        || alpha != mNameAlpha)
+    {
+        mNameText->setAlpha(alpha);
+        mNameAlpha = alpha;
+    }
 }
 
 LLColor4 LLVOAvatar::getNameTagColor(bool is_friend)
 {
-	//enum ENameColor { NameTagFriend = 0, NameTagMatch, NameTagMismatch, NameTagLegacy, Size};
-	//static std::vector<LLUIColor> sNameTagColors;
-	//if (sNameTagColors.empty())
-	//{
-	//	sNameTagColors.resize(ENameColor::Size);
-
-	//	auto& inst = LLUIColorTable::instance();
-	//	sNameTagColors[NameTagFriend] = inst.getColor("NameTagFriend");
-	//	sNameTagColors[NameTagMatch] = inst.getColor("NameTagMatch");
-	//	sNameTagColors[NameTagMismatch] = inst.getColor("NameTagMismatch");
-	//	sNameTagColors[NameTagLegacy] = inst.getColor("NameTagLegacy");
-	//}
-
-	//LLColor4 color_name;
-	//if (LLAvatarName::useDisplayNames())
-	//{
-	//	// ...color based on whether username "matches" a computed display name
-	//	LLAvatarName av_name;
-	//	if (LLAvatarNameCache::get(getID(), &av_name) && av_name.isDisplayNameDefault())
-	//	{
-	//		color_name = sNameTagColors[ENameColor::NameTagMatch];
-	//	}
-	//	else
-	//	{
-	//		color_name = sNameTagColors[ENameColor::NameTagMismatch];
-	//	}
-	//}
-	//else
-	//{
-	//	// ...not using display names
-	//	color_name = sNameTagColors[ENameColor::NameTagLegacy];
-	//}
-
-	static LLUIColor name_tag_match = LLUIColorTable::instance().getColor("NameTagMatch");
-	LLColor4 color_name = name_tag_match;
-	color_name = ALAvatarGroups::instance().getAvatarColor(getID(), color_name, ALAvatarGroups::COLOR_NAMETAG);
-
-	return color_name;
+    //enum ENameColor { NameTagFriend = 0, NameTagMatch, NameTagMismatch, NameTagLegacy, Size};
+    //static std::vector<LLUIColor> sNameTagColors;
+    //if (sNameTagColors.empty())
+    //{
+    //  sNameTagColors.resize(ENameColor::Size);
+
+    //  auto& inst = LLUIColorTable::instance();
+    //  sNameTagColors[NameTagFriend] = inst.getColor("NameTagFriend");
+    //  sNameTagColors[NameTagMatch] = inst.getColor("NameTagMatch");
+    //  sNameTagColors[NameTagMismatch] = inst.getColor("NameTagMismatch");
+    //  sNameTagColors[NameTagLegacy] = inst.getColor("NameTagLegacy");
+    //}
+
+    //LLColor4 color_name;
+    //if (LLAvatarName::useDisplayNames())
+    //{
+    //  // ...color based on whether username "matches" a computed display name
+    //  LLAvatarName av_name;
+    //  if (LLAvatarNameCache::get(getID(), &av_name) && av_name.isDisplayNameDefault())
+    //  {
+    //      color_name = sNameTagColors[ENameColor::NameTagMatch];
+    //  }
+    //  else
+    //  {
+    //      color_name = sNameTagColors[ENameColor::NameTagMismatch];
+    //  }
+    //}
+    //else
+    //{
+    //  // ...not using display names
+    //  color_name = sNameTagColors[ENameColor::NameTagLegacy];
+    //}
+
+    static LLUIColor name_tag_match = LLUIColorTable::instance().getColor("NameTagMatch");
+    LLColor4 color_name = name_tag_match;
+    color_name = ALAvatarGroups::instance().getAvatarColor(getID(), color_name, ALAvatarGroups::COLOR_NAMETAG);
+
+    return color_name;
 }
 
 void LLVOAvatar::idleUpdateBelowWater()
 {
-	F32 avatar_height = (F32)(getPositionGlobal().mdV[VZ]);
-	F32 water_height = getRegion()->getWaterHeight();
+    F32 avatar_height = (F32)(getPositionGlobal().mdV[VZ]);
+    F32 water_height = getRegion()->getWaterHeight();
 
-	BOOL wasBelowWater = mBelowWater;
-	mBelowWater =  avatar_height < water_height;
-	if (isSelf() && wasBelowWater != mBelowWater)
-	{
-		AOEngine::instance().checkBelowWater(mBelowWater);
-	}
+    BOOL wasBelowWater = mBelowWater;
+    mBelowWater =  avatar_height < water_height;
+    if (isSelf() && wasBelowWater != mBelowWater)
+    {
+        AOEngine::instance().checkBelowWater(mBelowWater);
+    }
 }
 
 void LLVOAvatar::slamPosition()
 {
-	gAgent.setPositionAgent(getPositionAgent());
-	// SL-315
-	mRoot->setWorldPosition(getPositionAgent()); // teleport
-	setChanged(TRANSLATED);
-	if (mDrawable.notNull())
-	{
-		gPipeline.updateMoveNormalAsync(mDrawable);
-	}
-	mRoot->updateWorldMatrixChildren();
+    gAgent.setPositionAgent(getPositionAgent());
+    // SL-315
+    mRoot->setWorldPosition(getPositionAgent()); // teleport
+    setChanged(TRANSLATED);
+    if (mDrawable.notNull())
+    {
+        gPipeline.updateMoveNormalAsync(mDrawable);
+    }
+    mRoot->updateWorldMatrixChildren();
 }
 
 bool LLVOAvatar::isVisuallyMuted()
 {
-	bool muted = false;
+    bool muted = false;
 
-	// Priority order (highest priority first)
-	// * own avatar is never visually muted
-	// * if on the "always draw normally" list, draw them normally
-	// * if on the "always visually mute" list, mute them
-	// * check against the render cost and attachment limits
-	if (!isSelf())
-	{
+    // Priority order (highest priority first)
+    // * own avatar is never visually muted
+    // * if on the "always draw normally" list, draw them normally
+    // * if on the "always visually mute" list, mute them
+    // * check against the render cost and attachment limits
+    if (!isSelf())
+    {
 // [RLVa:KB] - Checked: RLVa-2.2 (@setcam_avdist)
-		if (isRlvSilhouette())
-		{
-			muted = true;
-		}
-		else if (mVisuallyMuteSetting == AV_ALWAYS_RENDER)
+        if (isRlvSilhouette())
+        {
+            muted = true;
+        }
+        else if (mVisuallyMuteSetting == AV_ALWAYS_RENDER)
 // [/RLVa:KB]
-//		if (mVisuallyMuteSetting == AV_ALWAYS_RENDER)
-		{
-			muted = false;
-		}
-		else if (mVisuallyMuteSetting == AV_DO_NOT_RENDER)
-		{
+//      if (mVisuallyMuteSetting == AV_ALWAYS_RENDER)
+        {
+            muted = false;
+        }
+        else if (mVisuallyMuteSetting == AV_DO_NOT_RENDER)
+        {
 #ifdef JELLYDOLLS_SHOULD_IMPOSTOR
-			muted = true;
-			// Always want to see this AV as an impostor
+            muted = true;
+            // Always want to see this AV as an impostor
 #else
-			muted = false;
+            muted = false;
 #endif
-		}
+        }
         else if (isInMuteList())
         {
             muted = true;
@@ -3909,132 +3909,132 @@ bool LLVOAvatar::isVisuallyMuted()
         {
             muted = isTooSlow();
         }
-		else 
-		{
-			muted = isTooComplex() || isTooSlow();
-		}
-	}
+        else
+        {
+            muted = isTooComplex() || isTooSlow();
+        }
+    }
 
-	return muted;
+    return muted;
 }
 
 bool LLVOAvatar::isInMuteList() const
 {
-	bool muted = false;
-	F64 now = LLFrameTimer::getTotalSeconds();
-	if (now < mCachedMuteListUpdateTime)
-	{
-		muted = mCachedInMuteList;
-	}
-	else
-	{
-		muted = LLMuteList::getInstance()->isMuted(getID(), getFullname());
+    bool muted = false;
+    F64 now = LLFrameTimer::getTotalSeconds();
+    if (now < mCachedMuteListUpdateTime)
+    {
+        muted = mCachedInMuteList;
+    }
+    else
+    {
+        muted = LLMuteList::getInstance()->isMuted(getID(), getFullname());
 
-		const F64 SECONDS_BETWEEN_MUTE_UPDATES = 1;
-		mCachedMuteListUpdateTime = now + SECONDS_BETWEEN_MUTE_UPDATES;
-		mCachedInMuteList = muted;
-	}
-	return muted;
+        const F64 SECONDS_BETWEEN_MUTE_UPDATES = 1;
+        mCachedMuteListUpdateTime = now + SECONDS_BETWEEN_MUTE_UPDATES;
+        mCachedInMuteList = muted;
+    }
+    return muted;
 }
 
 bool LLVOAvatar::isInBuddyList() const
 {
-	bool is_friend = false;
-	F64 now = LLFrameTimer::getTotalSeconds();
-	if (now < mCachedBuddyListUpdateTime)
-	{
-		is_friend = mCachedInBuddyList;
-	}
-	else
-	{
-		is_friend = LLAvatarTracker::instance().isBuddy(getID());
+    bool is_friend = false;
+    F64 now = LLFrameTimer::getTotalSeconds();
+    if (now < mCachedBuddyListUpdateTime)
+    {
+        is_friend = mCachedInBuddyList;
+    }
+    else
+    {
+        is_friend = LLAvatarTracker::instance().isBuddy(getID());
 
-		const F64 SECONDS_BETWEEN_MUTE_UPDATES = 1;
-		mCachedBuddyListUpdateTime = now + SECONDS_BETWEEN_MUTE_UPDATES;
-		mCachedInBuddyList = is_friend;
-	}
-	return is_friend;
+        const F64 SECONDS_BETWEEN_MUTE_UPDATES = 1;
+        mCachedBuddyListUpdateTime = now + SECONDS_BETWEEN_MUTE_UPDATES;
+        mCachedInBuddyList = is_friend;
+    }
+    return is_friend;
 }
 
 // [RLVa:KB] - Checked: RLVa-2.2 (@setcam_avdist)
 bool LLVOAvatar::isRlvSilhouette() const
 {
-	if (!RlvActions::hasBehaviour(RLV_BHVR_SETCAM_AVDIST))
-		return false;
-
-	static RlvCachedBehaviourModifier<float> s_nSetCamAvDist(RLV_MODIFIER_SETCAM_AVDIST);
-
-	const F64 now = LLFrameTimer::getTotalSeconds();
-	if (now >= mCachedRlvSilhouetteUpdateTime)
-	{
-		const F64 SECONDS_BETWEEN_SILHOUETTE_UPDATES = .5f;
-		bool fIsRlvSilhouette = dist_vec_squared(gAgent.getPositionGlobal(), getPositionGlobal()) > s_nSetCamAvDist() * s_nSetCamAvDist();
-		if (fIsRlvSilhouette != mCachedIsRlvSilhouette)
-		{
-			mCachedIsRlvSilhouette = fIsRlvSilhouette;
-			mNeedsImpostorUpdate = TRUE;
-		}
-		mCachedRlvSilhouetteUpdateTime = now + SECONDS_BETWEEN_SILHOUETTE_UPDATES;
-	}
-	return mCachedIsRlvSilhouette;
+    if (!RlvActions::hasBehaviour(RLV_BHVR_SETCAM_AVDIST))
+        return false;
+
+    static RlvCachedBehaviourModifier<float> s_nSetCamAvDist(RLV_MODIFIER_SETCAM_AVDIST);
+
+    const F64 now = LLFrameTimer::getTotalSeconds();
+    if (now >= mCachedRlvSilhouetteUpdateTime)
+    {
+        const F64 SECONDS_BETWEEN_SILHOUETTE_UPDATES = .5f;
+        bool fIsRlvSilhouette = dist_vec_squared(gAgent.getPositionGlobal(), getPositionGlobal()) > s_nSetCamAvDist() * s_nSetCamAvDist();
+        if (fIsRlvSilhouette != mCachedIsRlvSilhouette)
+        {
+            mCachedIsRlvSilhouette = fIsRlvSilhouette;
+            mNeedsImpostorUpdate = TRUE;
+        }
+        mCachedRlvSilhouetteUpdateTime = now + SECONDS_BETWEEN_SILHOUETTE_UPDATES;
+    }
+    return mCachedIsRlvSilhouette;
 }
 // [/RLVa:KB]
 
 void LLVOAvatar::updateAppearanceMessageDebugText()
 {
-		S32 central_bake_version = -1;
-		if (getRegion())
-		{
-			central_bake_version = getRegion()->getCentralBakeVersion();
-		}
-		bool all_baked_downloaded = allBakedTexturesCompletelyDownloaded();
-		bool all_local_downloaded = allLocalTexturesCompletelyDownloaded();
-		std::string debug_line = llformat("%s%s - mLocal: %d, mEdit: %d, mUSB: %d, CBV: %d",
-										  isSelf() ? (all_local_downloaded ? "L" : "l") : "-",
-										  all_baked_downloaded ? "B" : "b",
-										  mUseLocalAppearance, mIsEditingAppearance,
-										  1, central_bake_version);
-		std::string origin_string = bakedTextureOriginInfo();
-		debug_line += " [" + origin_string + "]";
-		S32 curr_cof_version = LLAppearanceMgr::instance().getCOFVersion();
-		S32 last_request_cof_version = mLastUpdateRequestCOFVersion;
-		S32 last_received_cof_version = mLastUpdateReceivedCOFVersion;
-		if (isSelf())
-		{
-			debug_line += llformat(" - cof: %d req: %d rcv:%d",
-								   curr_cof_version, last_request_cof_version, last_received_cof_version);
-			static LLCachedControl<bool> debug_force_failure(gSavedSettings, "DebugForceAppearanceRequestFailure");
-			if (debug_force_failure)
-			{
-				debug_line += " FORCING ERRS";
-			}
-		}
-		else
-		{
-			debug_line += llformat(" - cof rcv:%d", last_received_cof_version);
-		}
-		debug_line += llformat(" bsz-z: %.3f", mBodySize[2]);
+        S32 central_bake_version = -1;
+        if (getRegion())
+        {
+            central_bake_version = getRegion()->getCentralBakeVersion();
+        }
+        bool all_baked_downloaded = allBakedTexturesCompletelyDownloaded();
+        bool all_local_downloaded = allLocalTexturesCompletelyDownloaded();
+        std::string debug_line = llformat("%s%s - mLocal: %d, mEdit: %d, mUSB: %d, CBV: %d",
+                                          isSelf() ? (all_local_downloaded ? "L" : "l") : "-",
+                                          all_baked_downloaded ? "B" : "b",
+                                          mUseLocalAppearance, mIsEditingAppearance,
+                                          1, central_bake_version);
+        std::string origin_string = bakedTextureOriginInfo();
+        debug_line += " [" + origin_string + "]";
+        S32 curr_cof_version = LLAppearanceMgr::instance().getCOFVersion();
+        S32 last_request_cof_version = mLastUpdateRequestCOFVersion;
+        S32 last_received_cof_version = mLastUpdateReceivedCOFVersion;
+        if (isSelf())
+        {
+            debug_line += llformat(" - cof: %d req: %d rcv:%d",
+                                   curr_cof_version, last_request_cof_version, last_received_cof_version);
+            static LLCachedControl<bool> debug_force_failure(gSavedSettings, "DebugForceAppearanceRequestFailure");
+            if (debug_force_failure)
+            {
+                debug_line += " FORCING ERRS";
+            }
+        }
+        else
+        {
+            debug_line += llformat(" - cof rcv:%d", last_received_cof_version);
+        }
+        debug_line += llformat(" bsz-z: %.3f", mBodySize[2]);
         if (mAvatarOffset[2] != 0.0f)
         {
             debug_line += llformat("avofs-z: %.3f", mAvatarOffset[2]);
         }
-		bool hover_enabled = getRegion() && getRegion()->avatarHoverHeightEnabled();
-		debug_line += hover_enabled ? " H" : " h";
-		const LLVector3& hover_offset = getHoverOffset();
-		if (hover_offset[2] != 0.0)
-		{
-			debug_line += llformat(" hov_z: %.3f", hover_offset[2]);
-			debug_line += llformat(" %s", (isSitting() ? "S" : "T"));
-			debug_line += llformat("%s", (isMotionActive(ANIM_AGENT_SIT_GROUND_CONSTRAINED) ? "G" : "-"));
-		}
-		if (mInAir)
-		{
-			debug_line += " A";
-			
-		}
+        bool hover_enabled = getRegion() && getRegion()->avatarHoverHeightEnabled();
+        debug_line += hover_enabled ? " H" : " h";
+        const LLVector3& hover_offset = getHoverOffset();
+        if (hover_offset[2] != 0.0)
+        {
+            debug_line += llformat(" hov_z: %.3f", hover_offset[2]);
+            debug_line += llformat(" %s", (isSitting() ? "S" : "T"));
+            debug_line += llformat("%s", (isMotionActive(ANIM_AGENT_SIT_GROUND_CONSTRAINED) ? "G" : "-"));
+        }
+        if (mInAir)
+        {
+            debug_line += " A";
+
+        }
 
         LLVector3 ankle_right_pos_agent = mFootRightp->getWorldPosition();
-		LLVector3 normal;
+        LLVector3 normal;
         LLVector3 ankle_right_ground_agent = ankle_right_pos_agent;
         resolveHeightAgent(ankle_right_pos_agent, ankle_right_ground_agent, normal);
         F32 rightElev = llmax(-0.2f, ankle_right_pos_agent.mV[VZ] - ankle_right_ground_agent.mV[VZ]);
@@ -4044,40 +4044,40 @@ void LLVOAvatar::updateAppearanceMessageDebugText()
         LLVector3 pelvis_pos = mPelvisp->getPosition();
         debug_line += llformat(" rp %.3f pp %.3f", root_pos[2], pelvis_pos[2]);
 
-		const LLVector3& scale = getScale();
-		debug_line += llformat(" scale-z %.3f", scale[2]);
-		S32 is_visible = (S32) isVisible();
-		S32 is_m_visible = (S32) mVisible;
-		debug_line += llformat(" v %d/%d", is_visible, is_m_visible);
-
-		AvatarOverallAppearance aoa = getOverallAppearance();
-		if (aoa == AOA_NORMAL)
-		{
-			debug_line += " N";
-		}
-		else if (aoa == AOA_JELLYDOLL)
-		{
-			debug_line += " J";
-		}
-		else
-		{
-			debug_line += " I";
-		}
-
-		if (mMeshValid)
-		{
-			debug_line += "m";
-		}
-		else
-		{
-			debug_line += "-";
-		}
-		if (isImpostor())
-		{
-			debug_line += " Imp" + llformat("%d[%d]:%.1f", mUpdatePeriod, mLastImpostorUpdateReason, ((F32)(gFrameTimeSeconds-mLastImpostorUpdateFrameTime)));
-		}
-
-		addDebugText(debug_line);
+        const LLVector3& scale = getScale();
+        debug_line += llformat(" scale-z %.3f", scale[2]);
+        S32 is_visible = (S32) isVisible();
+        S32 is_m_visible = (S32) mVisible;
+        debug_line += llformat(" v %d/%d", is_visible, is_m_visible);
+
+        AvatarOverallAppearance aoa = getOverallAppearance();
+        if (aoa == AOA_NORMAL)
+        {
+            debug_line += " N";
+        }
+        else if (aoa == AOA_JELLYDOLL)
+        {
+            debug_line += " J";
+        }
+        else
+        {
+            debug_line += " I";
+        }
+
+        if (mMeshValid)
+        {
+            debug_line += "m";
+        }
+        else
+        {
+            debug_line += "-";
+        }
+        if (isImpostor())
+        {
+            debug_line += " Imp" + llformat("%d[%d]:%.1f", mUpdatePeriod, mLastImpostorUpdateReason, ((F32)(gFrameTimeSeconds-mLastImpostorUpdateFrameTime)));
+        }
+
+        addDebugText(debug_line);
 }
 
 LLViewerInventoryItem* getObjectInventoryItem(LLViewerObject *vobj, LLUUID asset_id)
@@ -4088,8 +4088,8 @@ LLViewerInventoryItem* getObjectInventoryItem(LLViewerObject *vobj, LLUUID asset
     {
         if (vobj->getInventorySerial()<=0)
         {
-            vobj->requestInventory(); 
-	}
+            vobj->requestInventory();
+    }
         item = vobj->getInventoryItemByAsset(asset_id);
     }
     return item;
@@ -4105,21 +4105,21 @@ LLViewerInventoryItem* recursiveGetObjectInventoryItem(LLViewerObject *vobj, LLU
         {
             item = getObjectInventoryItem(childp, asset_id);
             if (item)
-	{
+    {
                 break;
             }
         }
-	}
+    }
     return item;
 }
 
 void LLVOAvatar::updateAnimationDebugText()
 {
-	for (LLMotion* motionp : mMotionController.getActiveMotions())
-	{
-		if (motionp->getMinPixelArea() < getPixelArea())
-		{
-			std::string output;
+    for (LLMotion* motionp : mMotionController.getActiveMotions())
+    {
+        if (motionp->getMinPixelArea() < getPixelArea())
+        {
+            std::string output;
             std::string motion_name = motionp->getName();
             if (motion_name.empty())
             {
@@ -4136,109 +4136,109 @@ void LLVOAvatar::updateAnimationDebugText()
                 }
             }
             if (motion_name.empty())
-			{
-				std::string name;
-				if (gAgent.isGodlikeWithoutAdminMenuFakery() || isSelf())
-				{
-					name = motionp->getID().asString();
-					LLVOAvatar::AnimSourceIterator anim_it = mAnimationSources.begin();
-					for (; anim_it != mAnimationSources.end(); ++anim_it)
-					{
-						if (anim_it->second == motionp->getID())
-						{
-							LLViewerObject* object = gObjectList.findObject(anim_it->first);
-							if (!object)
-							{
-								break;
-							}
-							if (object->isAvatar())
-							{
-								if (mMotionController.mIsSelf)
-								{
-									// Searching inventory by asset id is really long
-									// so just mark as inventory
-									// Also item is likely to be named by LLPreviewAnim
-									name += "(inventory)";
-								}
-							}
-							else
-							{
-								LLViewerInventoryItem* item = NULL;
-								if (!object->isInventoryDirty())
-								{
-									item = object->getInventoryItemByAsset(motionp->getID());
-								}
-								if (item)
-								{
-									name = item->getName();
-								}
-								else if (object->isAttachment())
-								{
-									name += "(att:" + getAttachmentItemName() + ")";
-								}
-								else
-								{
-									// in-world object, name or content unknown
-									name += "(in-world)";
-								}
-							}
-							break;
-						}
-					}
-				}
-				else
-				{
-					name = LLUUID::null.asString();
-				}
-				motion_name = name;
-			}
-			std::string motion_tag = "";
-			if (mPlayingAnimations.find(motionp->getID()) != mPlayingAnimations.end())
-			{
-				motion_tag = "*";
-			}
-			output = llformat("%s%s - %d",
-							  motion_name.c_str(),
-							  motion_tag.c_str(),
-							  (U32)motionp->getPriority());
-			addDebugText(output);
-		}
-	}
+            {
+                std::string name;
+                if (gAgent.isGodlikeWithoutAdminMenuFakery() || isSelf())
+                {
+                    name = motionp->getID().asString();
+                    LLVOAvatar::AnimSourceIterator anim_it = mAnimationSources.begin();
+                    for (; anim_it != mAnimationSources.end(); ++anim_it)
+                    {
+                        if (anim_it->second == motionp->getID())
+                        {
+                            LLViewerObject* object = gObjectList.findObject(anim_it->first);
+                            if (!object)
+                            {
+                                break;
+                            }
+                            if (object->isAvatar())
+                            {
+                                if (mMotionController.mIsSelf)
+                                {
+                                    // Searching inventory by asset id is really long
+                                    // so just mark as inventory
+                                    // Also item is likely to be named by LLPreviewAnim
+                                    name += "(inventory)";
+                                }
+                            }
+                            else
+                            {
+                                LLViewerInventoryItem* item = NULL;
+                                if (!object->isInventoryDirty())
+                                {
+                                    item = object->getInventoryItemByAsset(motionp->getID());
+                                }
+                                if (item)
+                                {
+                                    name = item->getName();
+                                }
+                                else if (object->isAttachment())
+                                {
+                                    name += "(att:" + getAttachmentItemName() + ")";
+                                }
+                                else
+                                {
+                                    // in-world object, name or content unknown
+                                    name += "(in-world)";
+                                }
+                            }
+                            break;
+                        }
+                    }
+                }
+                else
+                {
+                    name = LLUUID::null.asString();
+                }
+                motion_name = name;
+            }
+            std::string motion_tag = "";
+            if (mPlayingAnimations.find(motionp->getID()) != mPlayingAnimations.end())
+            {
+                motion_tag = "*";
+            }
+            output = llformat("%s%s - %d",
+                              motion_name.c_str(),
+                              motion_tag.c_str(),
+                              (U32)motionp->getPriority());
+            addDebugText(output);
+        }
+    }
 }
 
 void LLVOAvatar::updateDebugText()
 {
     // Leave mDebugText uncleared here, in case a derived class has added some state first
 
-	static const LLCachedControl<bool> debug_av_appr_msg(gSavedSettings, "DebugAvatarAppearanceMessage");
-	if (debug_av_appr_msg)
-	{
+    static const LLCachedControl<bool> debug_av_appr_msg(gSavedSettings, "DebugAvatarAppearanceMessage");
+    if (debug_av_appr_msg)
+    {
         updateAppearanceMessageDebugText();
-	}
+    }
 
-	static const LLCachedControl<bool> debug_av_comp_bk(gSavedSettings, "DebugAvatarCompositeBaked");
-	if (debug_av_comp_bk)
-	{
-		if (!mBakedTextureDebugText.empty())
-			addDebugText(mBakedTextureDebugText);
-	}
+    static const LLCachedControl<bool> debug_av_comp_bk(gSavedSettings, "DebugAvatarCompositeBaked");
+    if (debug_av_comp_bk)
+    {
+        if (!mBakedTextureDebugText.empty())
+            addDebugText(mBakedTextureDebugText);
+    }
 
     // Develop -> Avatar -> Animation Info
-	if (LLVOAvatar::sShowAnimationDebug)
-	{
+    if (LLVOAvatar::sShowAnimationDebug)
+    {
         updateAnimationDebugText();
-	}
+    }
 
-	if (!mDebugText.size() && mText.notNull())
-	{
-		mText->markDead();
-		mText = NULL;
-	}
-	else if (mDebugText.size())
-	{
-		setDebugText(mDebugText);
-	}
-	mDebugText.clear();
+    if (!mDebugText.size() && mText.notNull())
+    {
+        mText->markDead();
+        mText = NULL;
+    }
+    else if (mDebugText.size())
+    {
+        setDebugText(mDebugText);
+    }
+    mDebugText.clear();
 }
 
 //------------------------------------------------------------------------
@@ -4252,82 +4252,82 @@ void LLVOAvatar::updateFootstepSounds()
     {
         return;
     }
-	
-	//-------------------------------------------------------------------------
-	// Find the ground under each foot, these are used for a variety
-	// of things that follow
-	//-------------------------------------------------------------------------
-	LLVector3 ankle_left_pos_agent = mFootLeftp->getWorldPosition();
-	LLVector3 ankle_right_pos_agent = mFootRightp->getWorldPosition();
 
-	LLVector3 ankle_left_ground_agent = ankle_left_pos_agent;
-	LLVector3 ankle_right_ground_agent = ankle_right_pos_agent;
+    //-------------------------------------------------------------------------
+    // Find the ground under each foot, these are used for a variety
+    // of things that follow
+    //-------------------------------------------------------------------------
+    LLVector3 ankle_left_pos_agent = mFootLeftp->getWorldPosition();
+    LLVector3 ankle_right_pos_agent = mFootRightp->getWorldPosition();
+
+    LLVector3 ankle_left_ground_agent = ankle_left_pos_agent;
+    LLVector3 ankle_right_ground_agent = ankle_right_pos_agent;
     LLVector3 normal;
-	resolveHeightAgent(ankle_left_pos_agent, ankle_left_ground_agent, normal);
-	resolveHeightAgent(ankle_right_pos_agent, ankle_right_ground_agent, normal);
-
-	F32 leftElev = llmax(-0.2f, ankle_left_pos_agent.mV[VZ] - ankle_left_ground_agent.mV[VZ]);
-	F32 rightElev = llmax(-0.2f, ankle_right_pos_agent.mV[VZ] - ankle_right_ground_agent.mV[VZ]);
-
-	if (!isSitting())
-	{
-		//-------------------------------------------------------------------------
-		// Figure out which foot is on ground
-		//-------------------------------------------------------------------------
-		if (!mInAir)
-		{
-			if ((leftElev < 0.0f) || (rightElev < 0.0f))
-	{
-				ankle_left_pos_agent = mFootLeftp->getWorldPosition();
-				ankle_right_pos_agent = mFootRightp->getWorldPosition();
-				leftElev = ankle_left_pos_agent.mV[VZ] - ankle_left_ground_agent.mV[VZ];
-				rightElev = ankle_right_pos_agent.mV[VZ] - ankle_right_ground_agent.mV[VZ];
-			}
-		}
-	}
-	
-	const LLUUID AGENT_FOOTSTEP_ANIMS[] = {ANIM_AGENT_WALK, ANIM_AGENT_RUN, ANIM_AGENT_LAND};
-	const S32 NUM_AGENT_FOOTSTEP_ANIMS = LL_ARRAY_SIZE(AGENT_FOOTSTEP_ANIMS);
-
-	if ( gAudiop && isAnyAnimationSignaled(AGENT_FOOTSTEP_ANIMS, NUM_AGENT_FOOTSTEP_ANIMS) )
-	{
-		BOOL playSound = FALSE;
-		LLVector3 foot_pos_agent;
-
-		BOOL onGroundLeft = (leftElev <= 0.05f);
-		BOOL onGroundRight = (rightElev <= 0.05f);
-
-		// did left foot hit the ground?
-		if ( onGroundLeft && !mWasOnGroundLeft )
-		{
-			foot_pos_agent = ankle_left_pos_agent;
-			playSound = TRUE;
-		}
-
-		// did right foot hit the ground?
-		if ( onGroundRight && !mWasOnGroundRight )
-	{
-			foot_pos_agent = ankle_right_pos_agent;
-			playSound = TRUE;
-	}
-
-		mWasOnGroundLeft = onGroundLeft;
-		mWasOnGroundRight = onGroundRight;
-
-		if ( playSound )
-		{
-			const F32 STEP_VOLUME = 0.1f;
-			const LLUUID& step_sound_id = getStepSound();
-
-			LLVector3d foot_pos_global = gAgent.getPosGlobalFromAgent(foot_pos_agent);
-
-			if (LLViewerParcelMgr::getInstance()->canHearSound(foot_pos_global)
-				&& !LLMuteList::getInstance()->isMuted(getID(), LLMute::flagObjectSounds))
-			{
-				gAudiop->triggerSound(step_sound_id, getID(), STEP_VOLUME, LLAudioEngine::AUDIO_TYPE_AMBIENT, foot_pos_global);
-			}
-		}
-	}
+    resolveHeightAgent(ankle_left_pos_agent, ankle_left_ground_agent, normal);
+    resolveHeightAgent(ankle_right_pos_agent, ankle_right_ground_agent, normal);
+
+    F32 leftElev = llmax(-0.2f, ankle_left_pos_agent.mV[VZ] - ankle_left_ground_agent.mV[VZ]);
+    F32 rightElev = llmax(-0.2f, ankle_right_pos_agent.mV[VZ] - ankle_right_ground_agent.mV[VZ]);
+
+    if (!isSitting())
+    {
+        //-------------------------------------------------------------------------
+        // Figure out which foot is on ground
+        //-------------------------------------------------------------------------
+        if (!mInAir)
+        {
+            if ((leftElev < 0.0f) || (rightElev < 0.0f))
+    {
+                ankle_left_pos_agent = mFootLeftp->getWorldPosition();
+                ankle_right_pos_agent = mFootRightp->getWorldPosition();
+                leftElev = ankle_left_pos_agent.mV[VZ] - ankle_left_ground_agent.mV[VZ];
+                rightElev = ankle_right_pos_agent.mV[VZ] - ankle_right_ground_agent.mV[VZ];
+            }
+        }
+    }
+
+    const LLUUID AGENT_FOOTSTEP_ANIMS[] = {ANIM_AGENT_WALK, ANIM_AGENT_RUN, ANIM_AGENT_LAND};
+    const S32 NUM_AGENT_FOOTSTEP_ANIMS = LL_ARRAY_SIZE(AGENT_FOOTSTEP_ANIMS);
+
+    if ( gAudiop && isAnyAnimationSignaled(AGENT_FOOTSTEP_ANIMS, NUM_AGENT_FOOTSTEP_ANIMS) )
+    {
+        BOOL playSound = FALSE;
+        LLVector3 foot_pos_agent;
+
+        BOOL onGroundLeft = (leftElev <= 0.05f);
+        BOOL onGroundRight = (rightElev <= 0.05f);
+
+        // did left foot hit the ground?
+        if ( onGroundLeft && !mWasOnGroundLeft )
+        {
+            foot_pos_agent = ankle_left_pos_agent;
+            playSound = TRUE;
+        }
+
+        // did right foot hit the ground?
+        if ( onGroundRight && !mWasOnGroundRight )
+    {
+            foot_pos_agent = ankle_right_pos_agent;
+            playSound = TRUE;
+    }
+
+        mWasOnGroundLeft = onGroundLeft;
+        mWasOnGroundRight = onGroundRight;
+
+        if ( playSound )
+        {
+            const F32 STEP_VOLUME = 0.1f;
+            const LLUUID& step_sound_id = getStepSound();
+
+            LLVector3d foot_pos_global = gAgent.getPosGlobalFromAgent(foot_pos_agent);
+
+            if (LLViewerParcelMgr::getInstance()->canHearSound(foot_pos_global)
+                && !LLMuteList::getInstance()->isMuted(getID(), LLMute::flagObjectSounds))
+            {
+                gAudiop->triggerSound(step_sound_id, getID(), STEP_VOLUME, LLAudioEngine::AUDIO_TYPE_AMBIENT, foot_pos_global);
+            }
+        }
+    }
 }
 
 //------------------------------------------------------------------------
@@ -4344,57 +4344,57 @@ void LLVOAvatar::updateFootstepSounds()
 // ------------------------------------------------------------------------
 void LLVOAvatar::computeUpdatePeriod()
 {
-	bool visually_muted = isVisuallyMuted();
-	if (mDrawable.notNull()
-        && isVisible() 
+    bool visually_muted = isVisuallyMuted();
+    if (mDrawable.notNull()
+        && isVisible()
         && (!isSelf() || visually_muted)
         && !isUIAvatar()
         && (sLimitNonImpostors || visually_muted)
         && !mNeedsAnimUpdate)
-	{
-		const LLVector4a* ext = mDrawable->getSpatialExtents();
-		LLVector4a size;
-		size.setSub(ext[1],ext[0]);
-		F32 mag = size.getLength3().getF32()*0.5f;
-
-		const S32 UPDATE_RATE_SLOW = 64;
-		const S32 UPDATE_RATE_MED = 48;
-		const S32 UPDATE_RATE_FAST = 32;
-		
-		if (visually_muted)
-		{   // visually muted avatars update at lowest rate
-			mUpdatePeriod = UPDATE_RATE_SLOW;
-		}
-		else if (! shouldImpostor()
-				 || mDrawable->mDistanceWRTCamera < 1.f + mag)
-		{   // first 25% of max visible avatars are not impostored
-			// also, don't impostor avatars whose bounding box may be penetrating the 
-			// impostor camera near clip plane
-			mUpdatePeriod = 1;
-		}
-		else if ( shouldImpostor(4.0) )
-		{ //background avatars are REALLY slow updating impostors
-			mUpdatePeriod = UPDATE_RATE_SLOW;
-		}
-		else if (mLastRezzedStatus <= 0)
-		{
-			// Don't update cloud avatars too often
-			mUpdatePeriod = UPDATE_RATE_SLOW;
-		}
-		else if ( shouldImpostor(3.0) )
-		{ //back 25% of max visible avatars are slow updating impostors
-			mUpdatePeriod = UPDATE_RATE_MED;
-		}
-		else 
-		{
-			//nearby avatars, update the impostors more frequently.
-			mUpdatePeriod = UPDATE_RATE_FAST;
-		}
-	}
-	else
-	{
-		mUpdatePeriod = 1;
-	}
+    {
+        const LLVector4a* ext = mDrawable->getSpatialExtents();
+        LLVector4a size;
+        size.setSub(ext[1],ext[0]);
+        F32 mag = size.getLength3().getF32()*0.5f;
+
+        const S32 UPDATE_RATE_SLOW = 64;
+        const S32 UPDATE_RATE_MED = 48;
+        const S32 UPDATE_RATE_FAST = 32;
+
+        if (visually_muted)
+        {   // visually muted avatars update at lowest rate
+            mUpdatePeriod = UPDATE_RATE_SLOW;
+        }
+        else if (! shouldImpostor()
+                 || mDrawable->mDistanceWRTCamera < 1.f + mag)
+        {   // first 25% of max visible avatars are not impostored
+            // also, don't impostor avatars whose bounding box may be penetrating the
+            // impostor camera near clip plane
+            mUpdatePeriod = 1;
+        }
+        else if ( shouldImpostor(4.0) )
+        { //background avatars are REALLY slow updating impostors
+            mUpdatePeriod = UPDATE_RATE_SLOW;
+        }
+        else if (mLastRezzedStatus <= 0)
+        {
+            // Don't update cloud avatars too often
+            mUpdatePeriod = UPDATE_RATE_SLOW;
+        }
+        else if ( shouldImpostor(3.0) )
+        { //back 25% of max visible avatars are slow updating impostors
+            mUpdatePeriod = UPDATE_RATE_MED;
+        }
+        else
+        {
+            //nearby avatars, update the impostors more frequently.
+            mUpdatePeriod = UPDATE_RATE_FAST;
+        }
+    }
+    else
+    {
+        mUpdatePeriod = 1;
+    }
 }
 
 //------------------------------------------------------------------------
@@ -4407,98 +4407,98 @@ void LLVOAvatar::computeUpdatePeriod()
 //------------------------------------------------------------------------
 void LLVOAvatar::updateOrientation(LLAgent& agent, F32 speed, F32 delta_time)
 {
-			LLQuaternion iQ;
-			LLVector3 upDir( 0.0f, 0.0f, 1.0f );
-			
-			// Compute a forward direction vector derived from the primitive rotation
-			// and the velocity vector.  When walking or jumping, don't let body deviate
-			// more than 90 from the view, if necessary, flip the velocity vector.
-
-			LLVector3 primDir;
-			if (isSelf())
-			{
-				primDir = agent.getAtAxis() - projected_vec(agent.getAtAxis(), agent.getReferenceUpVector());
-				primDir.normalize();
-			}
-			else
-			{
-				primDir = getRotation().getMatrix3().getFwdRow();
-			}
-			LLVector3 velDir = getVelocity();
-			velDir.normalize();
-			static LLCachedControl<bool> moon_walk(gSavedSettings, "AlchemyMoonWalk", false);
-			if (moon_walk && mSignaledAnimations.find(ANIM_AGENT_WALK) != mSignaledAnimations.end())
-			{
-				F32 vpD = velDir * primDir;
-				if (vpD < -0.5f)
-				{
-					velDir *= -1.0f;
-				}
-			}
-			LLVector3 fwdDir = lerp(primDir, velDir, clamp_rescale(speed, 0.5f, 2.0f, 0.0f, 1.0f));
-			if (isSelf() && gAgentCamera.cameraMouselook())
-			{
-				// make sure fwdDir stays in same general direction as primdir
-				if (gAgent.getFlying())
-				{
-					fwdDir = LLViewerCamera::getInstance()->getAtAxis();
-				}
-				else
-				{
-					LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis();
-					LLVector3 up_vector = gAgent.getReferenceUpVector();
-					at_axis -= up_vector * (at_axis * up_vector);
-					at_axis.normalize();
-					
-					F32 dot = fwdDir * at_axis;
-					if (dot < 0.f)
-					{
-						fwdDir -= 2.f * at_axis * dot;
-						fwdDir.normalize();
-					}
-				}
-			}
-
-			LLQuaternion root_rotation = LLMatrix4(mRoot->getWorldMatrix().getF32ptr()).quaternion();
-			F32 root_roll, root_pitch, root_yaw;
-			root_rotation.getEulerAngles(&root_roll, &root_pitch, &root_yaw);
-
-			// When moving very slow, the pelvis is allowed to deviate from the
+            LLQuaternion iQ;
+            LLVector3 upDir( 0.0f, 0.0f, 1.0f );
+
+            // Compute a forward direction vector derived from the primitive rotation
+            // and the velocity vector.  When walking or jumping, don't let body deviate
+            // more than 90 from the view, if necessary, flip the velocity vector.
+
+            LLVector3 primDir;
+            if (isSelf())
+            {
+                primDir = agent.getAtAxis() - projected_vec(agent.getAtAxis(), agent.getReferenceUpVector());
+                primDir.normalize();
+            }
+            else
+            {
+                primDir = getRotation().getMatrix3().getFwdRow();
+            }
+            LLVector3 velDir = getVelocity();
+            velDir.normalize();
+            static LLCachedControl<bool> moon_walk(gSavedSettings, "AlchemyMoonWalk", false);
+            if (moon_walk && mSignaledAnimations.find(ANIM_AGENT_WALK) != mSignaledAnimations.end())
+            {
+                F32 vpD = velDir * primDir;
+                if (vpD < -0.5f)
+                {
+                    velDir *= -1.0f;
+                }
+            }
+            LLVector3 fwdDir = lerp(primDir, velDir, clamp_rescale(speed, 0.5f, 2.0f, 0.0f, 1.0f));
+            if (isSelf() && gAgentCamera.cameraMouselook())
+            {
+                // make sure fwdDir stays in same general direction as primdir
+                if (gAgent.getFlying())
+                {
+                    fwdDir = LLViewerCamera::getInstance()->getAtAxis();
+                }
+                else
+                {
+                    LLVector3 at_axis = LLViewerCamera::getInstance()->getAtAxis();
+                    LLVector3 up_vector = gAgent.getReferenceUpVector();
+                    at_axis -= up_vector * (at_axis * up_vector);
+                    at_axis.normalize();
+
+                    F32 dot = fwdDir * at_axis;
+                    if (dot < 0.f)
+                    {
+                        fwdDir -= 2.f * at_axis * dot;
+                        fwdDir.normalize();
+                    }
+                }
+            }
+
+            LLQuaternion root_rotation = LLMatrix4(mRoot->getWorldMatrix().getF32ptr()).quaternion();
+            F32 root_roll, root_pitch, root_yaw;
+            root_rotation.getEulerAngles(&root_roll, &root_pitch, &root_yaw);
+
+            // When moving very slow, the pelvis is allowed to deviate from the
     // forward direction to allow it to hold its position while the torso
-			// and head turn.  Once in motion, it must conform however.
-			BOOL self_in_mouselook = isSelf() && gAgentCamera.cameraMouselook();
+            // and head turn.  Once in motion, it must conform however.
+            BOOL self_in_mouselook = isSelf() && gAgentCamera.cameraMouselook();
 
-			LLVector3 pelvisDir( mRoot->getWorldMatrix().getRow<LLMatrix4a::ROW_FWD>().getF32ptr() );
+            LLVector3 pelvisDir( mRoot->getWorldMatrix().getRow<LLMatrix4a::ROW_FWD>().getF32ptr() );
 
             const F32 AVATAR_PELVIS_ROTATE_THRESHOLD_SLOW = 60.0f;
             const F32 AVATAR_PELVIS_ROTATE_THRESHOLD_FAST = 2.0f;
 
             F32 pelvis_rot_threshold = clamp_rescale(speed, 0.1f, 1.0f, AVATAR_PELVIS_ROTATE_THRESHOLD_SLOW, AVATAR_PELVIS_ROTATE_THRESHOLD_FAST);
-						
-			if (self_in_mouselook)
-			{
-				pelvis_rot_threshold *= MOUSELOOK_PELVIS_FOLLOW_FACTOR;
-			}
-			pelvis_rot_threshold *= DEG_TO_RAD;
-
-			F32 angle = angle_between( pelvisDir, fwdDir );
-
-			// The avatar's root is allowed to have a yaw that deviates widely
-			// from the forward direction, but if roll or pitch are off even
-			// a little bit we need to correct the rotation.
-			if(root_roll < 1.f * DEG_TO_RAD
-			   && root_pitch < 5.f * DEG_TO_RAD)
-			{
-				// smaller correction vector means pelvis follows prim direction more closely
-				if (!mTurning && angle > pelvis_rot_threshold*0.75f)
-				{
-					mTurning = TRUE;
-				}
-
-				// use tighter threshold when turning
-				if (mTurning)
-				{
-					pelvis_rot_threshold *= 0.4f;
+
+            if (self_in_mouselook)
+            {
+                pelvis_rot_threshold *= MOUSELOOK_PELVIS_FOLLOW_FACTOR;
+            }
+            pelvis_rot_threshold *= DEG_TO_RAD;
+
+            F32 angle = angle_between( pelvisDir, fwdDir );
+
+            // The avatar's root is allowed to have a yaw that deviates widely
+            // from the forward direction, but if roll or pitch are off even
+            // a little bit we need to correct the rotation.
+            if(root_roll < 1.f * DEG_TO_RAD
+               && root_pitch < 5.f * DEG_TO_RAD)
+            {
+                // smaller correction vector means pelvis follows prim direction more closely
+                if (!mTurning && angle > pelvis_rot_threshold*0.75f)
+                {
+                    mTurning = TRUE;
+                }
+
+                // use tighter threshold when turning
+                if (mTurning)
+                {
+                    pelvis_rot_threshold *= 0.4f;
                     // account for fps, assume that above value is for ~60fps
                     constexpr F32 default_frame_sec = 0.016f;
                     F32 prev_frame_sec = LLFrameTimer::getFrameDeltaTimeF32();
@@ -4508,62 +4508,62 @@ void LLVOAvatar::updateOrientation(LLAgent& agent, F32 speed, F32 delta_time)
                         // shorter frame means shorter turn.
                         pelvis_rot_threshold *= prev_frame_sec/default_frame_sec;
                     }
-				}
-
-				// am I done turning?
-				if (angle < pelvis_rot_threshold)
-				{
-					mTurning = FALSE;
-				}
-
-				LLVector3 correction_vector = (pelvisDir - fwdDir) * clamp_rescale(angle, pelvis_rot_threshold*0.75f, pelvis_rot_threshold, 1.0f, 0.0f);
-				fwdDir += correction_vector;
-			}
-			else
-			{
-				mTurning = FALSE;
-			}
-
-			// Now compute the full world space rotation for the whole body (wQv)
-			LLVector3 leftDir = upDir % fwdDir;
-			leftDir.normalize();
-			fwdDir = leftDir % upDir;
-			LLQuaternion wQv( fwdDir, leftDir, upDir );
-
-			if (isSelf() && mTurning)
-			{
-				if ((fwdDir % pelvisDir) * upDir > 0.f)
-				{
-					gAgent.setControlFlags(AGENT_CONTROL_TURN_RIGHT);
-				}
-				else
-				{
-					gAgent.setControlFlags(AGENT_CONTROL_TURN_LEFT);
-				}
-			}
-
-			// Set the root rotation, but do so incrementally so that it
-			// lags in time by some fixed amount.
-			//F32 u = LLSmoothInterpolation::getInterpolant(PELVIS_LAG);
-			F32 pelvis_lag_time = 0.f;
-			if (self_in_mouselook)
-			{
-				pelvis_lag_time = PELVIS_LAG_MOUSELOOK;
-			}
-			else if (mInAir)
-			{
-				pelvis_lag_time = PELVIS_LAG_FLYING;
-				// increase pelvis lag time when moving slowly
-				pelvis_lag_time *= clamp_rescale(mSpeedAccum, 0.f, 15.f, 3.f, 1.f);
-			}
-			else
-			{
-				pelvis_lag_time = PELVIS_LAG_WALKING;
-			}
-
-    F32 u = llclamp((delta_time / pelvis_lag_time), 0.0f, 1.0f);	
-
-			mRoot->setWorldRotation( slerp(u, mRoot->getWorldRotation(), wQv) );
+                }
+
+                // am I done turning?
+                if (angle < pelvis_rot_threshold)
+                {
+                    mTurning = FALSE;
+                }
+
+                LLVector3 correction_vector = (pelvisDir - fwdDir) * clamp_rescale(angle, pelvis_rot_threshold*0.75f, pelvis_rot_threshold, 1.0f, 0.0f);
+                fwdDir += correction_vector;
+            }
+            else
+            {
+                mTurning = FALSE;
+            }
+
+            // Now compute the full world space rotation for the whole body (wQv)
+            LLVector3 leftDir = upDir % fwdDir;
+            leftDir.normalize();
+            fwdDir = leftDir % upDir;
+            LLQuaternion wQv( fwdDir, leftDir, upDir );
+
+            if (isSelf() && mTurning)
+            {
+                if ((fwdDir % pelvisDir) * upDir > 0.f)
+                {
+                    gAgent.setControlFlags(AGENT_CONTROL_TURN_RIGHT);
+                }
+                else
+                {
+                    gAgent.setControlFlags(AGENT_CONTROL_TURN_LEFT);
+                }
+            }
+
+            // Set the root rotation, but do so incrementally so that it
+            // lags in time by some fixed amount.
+            //F32 u = LLSmoothInterpolation::getInterpolant(PELVIS_LAG);
+            F32 pelvis_lag_time = 0.f;
+            if (self_in_mouselook)
+            {
+                pelvis_lag_time = PELVIS_LAG_MOUSELOOK;
+            }
+            else if (mInAir)
+            {
+                pelvis_lag_time = PELVIS_LAG_FLYING;
+                // increase pelvis lag time when moving slowly
+                pelvis_lag_time *= clamp_rescale(mSpeedAccum, 0.f, 15.f, 3.f, 1.f);
+            }
+            else
+            {
+                pelvis_lag_time = PELVIS_LAG_WALKING;
+            }
+
+    F32 u = llclamp((delta_time / pelvis_lag_time), 0.0f, 1.0f);
+
+            mRoot->setWorldRotation( slerp(u, mRoot->getWorldRotation(), wQv) );
 }
 
 //------------------------------------------------------------------------
@@ -4576,91 +4576,91 @@ void LLVOAvatar::updateOrientation(LLAgent& agent, F32 speed, F32 delta_time)
 // ------------------------------------------------------------------------
 void LLVOAvatar::updateTimeStep()
 {
-	if (!isSelf() && !isUIAvatar()) // ie, non-self avatars, and animated objects will be affected.
-	{
+    if (!isSelf() && !isUIAvatar()) // ie, non-self avatars, and animated objects will be affected.
+    {
         // Note that sInstances counts animated objects and
         // standard avatars in the same bucket. Is this desirable?
-		F32 time_quantum = clamp_rescale((F32)sInstances.size(), 10.f, 35.f, 0.f, 0.25f);
-		F32 pixel_area_scale = clamp_rescale(mPixelArea, 100, 5000, 1.f, 0.f);
-		F32 time_step = time_quantum * pixel_area_scale;
+        F32 time_quantum = clamp_rescale((F32)sInstances.size(), 10.f, 35.f, 0.f, 0.25f);
+        F32 pixel_area_scale = clamp_rescale(mPixelArea, 100, 5000, 1.f, 0.f);
+        F32 time_step = time_quantum * pixel_area_scale;
         // Extrema:
         //   If number of avs is 10 or less, time_step is unmodified (flagged with 0.0).
         //   If area of av is 5000 or greater, time_step is unmodified (flagged with 0.0).
         //   If number of avs is 35 or greater, and area of av is 100 or less,
         //   time_step takes the maximum possible value of 0.25.
         //   Other situations will give values within the (0, 0.25) range.
-		if (time_step != 0.f)
-		{
-			// disable walk motion servo controller as it doesn't work with motion timesteps
-			stopMotion(ANIM_AGENT_WALK_ADJUST);
-			removeAnimationData("Walk Speed");
-		}
+        if (time_step != 0.f)
+        {
+            // disable walk motion servo controller as it doesn't work with motion timesteps
+            stopMotion(ANIM_AGENT_WALK_ADJUST);
+            removeAnimationData("Walk Speed");
+        }
         // See SL-763 - playback with altered time step does not
         // appear to work correctly, odd behavior for distant avatars.
         // As of 11-2017, LLMotionController::updateMotions() will
         // ignore the value here. Need to re-enable if it's every
         // fixed.
-		mMotionController.setTimeStep(time_step);
-	}
-}
-
-void LLVOAvatar::updateRootPositionAndRotation(LLAgent& agent, F32 speed, bool was_sit_ground_constrained) 
-{
-	if (!(isSitting() && getParent()))
-	{
-		// This case includes all configurations except sitting on an
-		// object, so does include ground sit.
-
-		//--------------------------------------------------------------------
-		// get timing info
-		// handle initial condition case
-		//--------------------------------------------------------------------
-		F32 animation_time = mAnimTimer.getElapsedTimeF32();
-		if (mTimeLast == 0.0f)
-		{
-			mTimeLast = animation_time;
-
-			// Initially put the pelvis at slaved position/mRotation
-			// SL-315
-			mRoot->setWorldPosition( getPositionAgent() ); // first frame
-			mRoot->setWorldRotation( getRotation() );
-		}
-			
-		//--------------------------------------------------------------------
-		// dont' let dT get larger than 1/5th of a second
-		//--------------------------------------------------------------------
-		F32 delta_time = animation_time - mTimeLast;
-
-		delta_time = llclamp( delta_time, DELTA_TIME_MIN, DELTA_TIME_MAX );
-		mTimeLast = animation_time;
-
-		mSpeedAccum = (mSpeedAccum * 0.95f) + (speed * 0.05f);
-
-		//--------------------------------------------------------------------
-		// compute the position of the avatar's root
-		//--------------------------------------------------------------------
-		LLVector3d root_pos;
-		LLVector3d ground_under_pelvis;
-
-		if (isSelf())
-		{
-			gAgent.setPositionAgent(getRenderPosition());
-		}
-
-		root_pos = gAgent.getPosGlobalFromAgent(getRenderPosition());
-		root_pos.mdV[VZ] += getVisualParamWeight(AVATAR_HOVER);
+        mMotionController.setTimeStep(time_step);
+    }
+}
+
+void LLVOAvatar::updateRootPositionAndRotation(LLAgent& agent, F32 speed, bool was_sit_ground_constrained)
+{
+    if (!(isSitting() && getParent()))
+    {
+        // This case includes all configurations except sitting on an
+        // object, so does include ground sit.
+
+        //--------------------------------------------------------------------
+        // get timing info
+        // handle initial condition case
+        //--------------------------------------------------------------------
+        F32 animation_time = mAnimTimer.getElapsedTimeF32();
+        if (mTimeLast == 0.0f)
+        {
+            mTimeLast = animation_time;
+
+            // Initially put the pelvis at slaved position/mRotation
+            // SL-315
+            mRoot->setWorldPosition( getPositionAgent() ); // first frame
+            mRoot->setWorldRotation( getRotation() );
+        }
+
+        //--------------------------------------------------------------------
+        // dont' let dT get larger than 1/5th of a second
+        //--------------------------------------------------------------------
+        F32 delta_time = animation_time - mTimeLast;
+
+        delta_time = llclamp( delta_time, DELTA_TIME_MIN, DELTA_TIME_MAX );
+        mTimeLast = animation_time;
+
+        mSpeedAccum = (mSpeedAccum * 0.95f) + (speed * 0.05f);
+
+        //--------------------------------------------------------------------
+        // compute the position of the avatar's root
+        //--------------------------------------------------------------------
+        LLVector3d root_pos;
+        LLVector3d ground_under_pelvis;
+
+        if (isSelf())
+        {
+            gAgent.setPositionAgent(getRenderPosition());
+        }
+
+        root_pos = gAgent.getPosGlobalFromAgent(getRenderPosition());
+        root_pos.mdV[VZ] += getVisualParamWeight(AVATAR_HOVER);
 
         LLVector3 normal;
-		resolveHeightGlobal(root_pos, ground_under_pelvis, normal);
-		F32 foot_to_ground = (F32) (root_pos.mdV[VZ] - mPelvisToFoot - ground_under_pelvis.mdV[VZ]);				
-		BOOL in_air = ((!LLWorld::getInstance()->getRegionFromPosGlobal(ground_under_pelvis)) || 
-						foot_to_ground > FOOT_GROUND_COLLISION_TOLERANCE);
+        resolveHeightGlobal(root_pos, ground_under_pelvis, normal);
+        F32 foot_to_ground = (F32) (root_pos.mdV[VZ] - mPelvisToFoot - ground_under_pelvis.mdV[VZ]);
+        BOOL in_air = ((!LLWorld::getInstance()->getRegionFromPosGlobal(ground_under_pelvis)) ||
+                        foot_to_ground > FOOT_GROUND_COLLISION_TOLERANCE);
 
-		if (in_air && !mInAir)
-		{
-			mTimeInAir.reset();
-		}
-		mInAir = in_air;
+        if (in_air && !mInAir)
+        {
+            mTimeInAir.reset();
+        }
+        mInAir = in_air;
 
         // SL-402: with the ability to animate the position of joints
         // that affect the body size calculation, computed body size
@@ -4668,40 +4668,40 @@ void LLVOAvatar::updateRootPositionAndRotation(LLAgent& agent, F32 speed, bool w
         // it frequently.
         // SL-427: this appears to be too frequent, moving to only do on animation state change.
         //computeBodySize();
-    
-		// correct for the fact that the pelvis is not necessarily the center 
-		// of the agent's physical representation
-		root_pos.mdV[VZ] -= (0.5f * mBodySize.mV[VZ]) - mPelvisToFoot;
-		if (!isSitting() && !was_sit_ground_constrained)
-		{
-			root_pos += LLVector3d(getHoverOffset());
-			if (getOverallAppearance() == AOA_JELLYDOLL)
-			{
-				F32 offz = -0.5 * (getScale()[VZ] - mBodySize.mV[VZ]);
-				root_pos[2] += offz;
-				// if (!isSelf() && !isControlAvatar())
-				// {
-				// 	LL_DEBUGS("Avatar") << "av " << getFullname() 
-				// 						<< " frame " << LLFrameTimer::getFrameCount()
-				// 						<< " root adjust offz " << offz
-				// 						<< " scalez " << getScale()[VZ]
-				// 						<< " bsz " << mBodySize.mV[VZ]
-				// 						<< LL_ENDL;
-				// }
-			}
-		}
-		// if (!isSelf() && !isControlAvatar())
-		// {
-		// 	LL_DEBUGS("Avatar") << "av " << getFullname() << " aoa " << (S32) getOverallAppearance()
-		// 						<< " frame " << LLFrameTimer::getFrameCount()
-		// 						<< " scalez " << getScale()[VZ]
-		// 						<< " bsz " << mBodySize.mV[VZ]
-		// 						<< " root pos " << root_pos[2]
-		// 						<< " curr rootz " << mRoot->getPosition()[2] 
-		// 						<< " pp-z " << mPelvisp->getPosition()[2]
-		// 						<< " renderpos " << getRenderPosition()
-		// 						<< LL_ENDL;
-		// }
+
+        // correct for the fact that the pelvis is not necessarily the center
+        // of the agent's physical representation
+        root_pos.mdV[VZ] -= (0.5f * mBodySize.mV[VZ]) - mPelvisToFoot;
+        if (!isSitting() && !was_sit_ground_constrained)
+        {
+            root_pos += LLVector3d(getHoverOffset());
+            if (getOverallAppearance() == AOA_JELLYDOLL)
+            {
+                F32 offz = -0.5 * (getScale()[VZ] - mBodySize.mV[VZ]);
+                root_pos[2] += offz;
+                // if (!isSelf() && !isControlAvatar())
+                // {
+                //  LL_DEBUGS("Avatar") << "av " << getFullname()
+                //                      << " frame " << LLFrameTimer::getFrameCount()
+                //                      << " root adjust offz " << offz
+                //                      << " scalez " << getScale()[VZ]
+                //                      << " bsz " << mBodySize.mV[VZ]
+                //                      << LL_ENDL;
+                // }
+            }
+        }
+        // if (!isSelf() && !isControlAvatar())
+        // {
+        //  LL_DEBUGS("Avatar") << "av " << getFullname() << " aoa " << (S32) getOverallAppearance()
+        //                      << " frame " << LLFrameTimer::getFrameCount()
+        //                      << " scalez " << getScale()[VZ]
+        //                      << " bsz " << mBodySize.mV[VZ]
+        //                      << " root pos " << root_pos[2]
+        //                      << " curr rootz " << mRoot->getPosition()[2]
+        //                      << " pp-z " << mPelvisp->getPosition()[2]
+        //                      << " renderpos " << getRenderPosition()
+        //                      << LL_ENDL;
+        // }
 
         if (isControlAvatar())
         {
@@ -4711,73 +4711,73 @@ void LLVOAvatar::updateRootPositionAndRotation(LLAgent& agent, F32 speed, bool w
         else
         {
             LLVector3 newPosition = gAgent.getPosAgentFromGlobal(root_pos);
-			// if (!isSelf() && !isControlAvatar())
-			// {
-			// 	LL_DEBUGS("Avatar") << "av " << getFullname() 
-			// 						<< " frame " << LLFrameTimer::getFrameCount()
-			// 						<< " newPosition " << newPosition
-			// 						<< " renderpos " << getRenderPosition()
-			// 						<< LL_ENDL;
-			// }
+            // if (!isSelf() && !isControlAvatar())
+            // {
+            //  LL_DEBUGS("Avatar") << "av " << getFullname()
+            //                      << " frame " << LLFrameTimer::getFrameCount()
+            //                      << " newPosition " << newPosition
+            //                      << " renderpos " << getRenderPosition()
+            //                      << LL_ENDL;
+            // }
             if (newPosition != mRoot->getXform()->getWorldPosition())
-            {		
+            {
                 mRoot->touch();
                 // SL-315
-                mRoot->setWorldPosition( newPosition ); // regular update				
+                mRoot->setWorldPosition( newPosition ); // regular update
             }
         }
 
-		//--------------------------------------------------------------------
-		// Propagate viewer object rotation to root of avatar
-		//--------------------------------------------------------------------
-		if (!isControlAvatar() && !isAnyAnimationSignaled(AGENT_NO_ROTATE_ANIMS, NUM_AGENT_NO_ROTATE_ANIMS))
-		{
+        //--------------------------------------------------------------------
+        // Propagate viewer object rotation to root of avatar
+        //--------------------------------------------------------------------
+        if (!isControlAvatar() && !isAnyAnimationSignaled(AGENT_NO_ROTATE_ANIMS, NUM_AGENT_NO_ROTATE_ANIMS))
+        {
             // Rotation fixups for avatars in motion.
             // Skip for animated objects.
             updateOrientation(agent, speed, delta_time);
-		}
-	}
-	else if (mDrawable.notNull())
-	{
+        }
+    }
+    else if (mDrawable.notNull())
+    {
         // Sitting on an object - mRoot is slaved to mDrawable orientation.
-		LLVector3 pos = mDrawable->getPosition();
-		pos += getHoverOffset() * mDrawable->getRotation();
-		// SL-315
-		mRoot->setPosition(pos);
-		mRoot->setRotation(mDrawable->getRotation());
-	}
+        LLVector3 pos = mDrawable->getPosition();
+        pos += getHoverOffset() * mDrawable->getRotation();
+        // SL-315
+        mRoot->setPosition(pos);
+        mRoot->setRotation(mDrawable->getRotation());
+    }
 }
 
 //------------------------------------------------------------------------
 // LLVOAvatar::computeNeedsUpdate()
-// 
+//
 // Most of the logic here is to figure out when to periodically update impostors.
 // Non-impostors have mUpdatePeriod == 1 and will need update every frame.
 //------------------------------------------------------------------------
 bool LLVOAvatar::computeNeedsUpdate()
 {
-	const F32 MAX_IMPOSTOR_INTERVAL = 4.0f;
-	computeUpdatePeriod();
+    const F32 MAX_IMPOSTOR_INTERVAL = 4.0f;
+    computeUpdatePeriod();
 
-	bool needs_update_by_frame_count = ((LLDrawable::getCurrentFrame()+mID.mData[0])%mUpdatePeriod == 0);
+    bool needs_update_by_frame_count = ((LLDrawable::getCurrentFrame()+mID.mData[0])%mUpdatePeriod == 0);
 
     bool needs_update_by_max_time = ((gFrameTimeSeconds-mLastImpostorUpdateFrameTime)> MAX_IMPOSTOR_INTERVAL);
-	bool needs_update = needs_update_by_frame_count || needs_update_by_max_time;
-
-	if (needs_update && !isSelf())
-	{
-		if (needs_update_by_max_time)
-		{
-			mNeedsImpostorUpdate = TRUE;
-			mLastImpostorUpdateReason = 11;
-		}
-		else
-		{
-			//mNeedsImpostorUpdate = TRUE;
-			//mLastImpostorUpdateReason = 10;
-		}
-	}
-	return needs_update;
+    bool needs_update = needs_update_by_frame_count || needs_update_by_max_time;
+
+    if (needs_update && !isSelf())
+    {
+        if (needs_update_by_max_time)
+        {
+            mNeedsImpostorUpdate = TRUE;
+            mLastImpostorUpdateReason = 11;
+        }
+        else
+        {
+            //mNeedsImpostorUpdate = TRUE;
+            //mLastImpostorUpdateReason = 10;
+        }
+    }
+    return needs_update;
 }
 
 // updateCharacter()
@@ -4803,155 +4803,155 @@ bool LLVOAvatar::computeNeedsUpdate()
 //
 //------------------------------------------------------------------------
 bool LLVOAvatar::updateCharacter(LLAgent &agent)
-{	
-	updateDebugText();
-	
-	if (!mIsBuilt)
-	{
-		return FALSE;
-	}
-
-	BOOL visible = isVisible();
+{
+    updateDebugText();
+
+    if (!mIsBuilt)
+    {
+        return FALSE;
+    }
+
+    BOOL visible = isVisible();
 #ifdef SHOW_DEBUG
     bool is_control_avatar = isControlAvatar(); // capture state to simplify tracing
-	bool is_attachment = false;
+    bool is_attachment = false;
 
-	if (is_control_avatar)
-	{
+    if (is_control_avatar)
+    {
         LLControlAvatar *cav = static_cast<LLControlAvatar*>(this);
         is_attachment = cav->mRootVolp && cav->mRootVolp->isAttachment(); // For attached animated objects
-	}
+    }
 
     LLScopedContextString str("updateCharacter " + getFullname() + " is_control_avatar "
-                              + fmt::to_string(is_control_avatar) 
+                              + fmt::to_string(is_control_avatar)
                               + " is_attachment " + fmt::to_string(is_attachment));
 #endif
 
-	// For fading out the names above heads, only let the timer
-	// run if we're visible.
-	if (mDrawable.notNull() && !visible)
-	{
-		mTimeVisible.reset();
-	}
+    // For fading out the names above heads, only let the timer
+    // run if we're visible.
+    if (mDrawable.notNull() && !visible)
+    {
+        mTimeVisible.reset();
+    }
 
-	//--------------------------------------------------------------------
-	// The rest should only be done occasionally for far away avatars.
+    //--------------------------------------------------------------------
+    // The rest should only be done occasionally for far away avatars.
     // Set mUpdatePeriod and visible based on distance and other criteria,
-	// and flag for impostor update if needed.
-	//--------------------------------------------------------------------
-	bool needs_update = computeNeedsUpdate();
-	
-	//--------------------------------------------------------------------
-	// Early out if does not need update and not self
-	// don't early out for your own avatar, as we rely on your animations playing reliably
-	// for example, the "turn around" animation when entering customize avatar needs to trigger
-	// even when your avatar is offscreen
-	//--------------------------------------------------------------------
-	if (!needs_update && !isSelf())
-	{
-		updateMotions(LLCharacter::HIDDEN_UPDATE);
-		return FALSE;
-	}
-
-	//--------------------------------------------------------------------
-	// Handle transitions between regular rendering, jellydoll, or invisible.
-	// Can trigger skeleton reset or animation changes
-	//--------------------------------------------------------------------
-	updateOverallAppearance();
-	
-	//--------------------------------------------------------------------
-	// change animation time quanta based on avatar render load
-	//--------------------------------------------------------------------
+    // and flag for impostor update if needed.
+    //--------------------------------------------------------------------
+    bool needs_update = computeNeedsUpdate();
+
+    //--------------------------------------------------------------------
+    // Early out if does not need update and not self
+    // don't early out for your own avatar, as we rely on your animations playing reliably
+    // for example, the "turn around" animation when entering customize avatar needs to trigger
+    // even when your avatar is offscreen
+    //--------------------------------------------------------------------
+    if (!needs_update && !isSelf())
+    {
+        updateMotions(LLCharacter::HIDDEN_UPDATE);
+        return FALSE;
+    }
+
+    //--------------------------------------------------------------------
+    // Handle transitions between regular rendering, jellydoll, or invisible.
+    // Can trigger skeleton reset or animation changes
+    //--------------------------------------------------------------------
+    updateOverallAppearance();
+
+    //--------------------------------------------------------------------
+    // change animation time quanta based on avatar render load
+    //--------------------------------------------------------------------
     // SL-763 the time step quantization does not currently work.
     //updateTimeStep();
-    
-	//--------------------------------------------------------------------
+
+    //--------------------------------------------------------------------
     // Update sitting state based on parent and active animation info.
-	//--------------------------------------------------------------------
-	if (getParent() && !isSitting())
-	{
-		sitOnObject((LLViewerObject*)getParent());
-	}
-	else if (!getParent() && isSitting() && !isMotionActive(ANIM_AGENT_SIT_GROUND_CONSTRAINED))
-	{
+    //--------------------------------------------------------------------
+    if (getParent() && !isSitting())
+    {
+        sitOnObject((LLViewerObject*)getParent());
+    }
+    else if (!getParent() && isSitting() && !isMotionActive(ANIM_AGENT_SIT_GROUND_CONSTRAINED))
+    {
         // If we are starting up, motion might be loading
         LLMotion *motionp = mMotionController.findMotion(ANIM_AGENT_SIT_GROUND_CONSTRAINED);
         if (!motionp || !mMotionController.isMotionLoading(motionp))
         {
             getOffObject();
         }
-	}
-
-	//--------------------------------------------------------------------
-	// create local variables in world coords for region position values
-	//--------------------------------------------------------------------
-	LLVector3 xyVel = getVelocity();
-	xyVel.mV[VZ] = 0.0f;
-	F32 speed = xyVel.length();
-	// remembering the value here prevents a display glitch if the
-	// animation gets toggled during this update.
-	bool was_sit_ground_constrained = isMotionActive(ANIM_AGENT_SIT_GROUND_CONSTRAINED);
+    }
 
-	//--------------------------------------------------------------------
+    //--------------------------------------------------------------------
+    // create local variables in world coords for region position values
+    //--------------------------------------------------------------------
+    LLVector3 xyVel = getVelocity();
+    xyVel.mV[VZ] = 0.0f;
+    F32 speed = xyVel.length();
+    // remembering the value here prevents a display glitch if the
+    // animation gets toggled during this update.
+    bool was_sit_ground_constrained = isMotionActive(ANIM_AGENT_SIT_GROUND_CONSTRAINED);
+
+    //--------------------------------------------------------------------
     // This does a bunch of state updating, including figuring out
     // whether av is in the air, setting mRoot position and rotation
     // In some cases, calls updateOrientation() for a lot of the
     // work
     // --------------------------------------------------------------------
     updateRootPositionAndRotation(agent, speed, was_sit_ground_constrained);
-	
-	//-------------------------------------------------------------------------
-	// Update character motions
-	//-------------------------------------------------------------------------
-	// store data relevant to motions
-	mSpeed = speed;
-
-	// update animations
-	if (!visible && !isSelf()) // NOTE: never do a "hidden update" for self avatar as it interrupts controller processing
-	{
-		updateMotions(LLCharacter::HIDDEN_UPDATE);
-	}
-	else if (mSpecialRenderMode == 1) // Animation Preview
-	{
-		updateMotions(LLCharacter::FORCE_UPDATE);
-	}
-	else
-	{
-		// Might be better to do HIDDEN_UPDATE if cloud
-		updateMotions(LLCharacter::NORMAL_UPDATE);
-	}
-
-	// Special handling for sitting on ground.
-	if (!getParent() && (isSitting() || was_sit_ground_constrained))
-	{
-		
-		F32 off_z = LLVector3d(getHoverOffset()).mdV[VZ];
-		if (off_z != 0.0)
-		{
-			LLVector3 pos = mRoot->getWorldPosition();
-			pos.mV[VZ] += off_z;
-			mRoot->touch();
-			// SL-315
-			mRoot->setWorldPosition(pos);
-		}
-	}
-
-	// update head position
-	updateHeadOffset();
-
-	// Generate footstep sounds when feet hit the ground
+
+    //-------------------------------------------------------------------------
+    // Update character motions
+    //-------------------------------------------------------------------------
+    // store data relevant to motions
+    mSpeed = speed;
+
+    // update animations
+    if (!visible && !isSelf()) // NOTE: never do a "hidden update" for self avatar as it interrupts controller processing
+    {
+        updateMotions(LLCharacter::HIDDEN_UPDATE);
+    }
+    else if (mSpecialRenderMode == 1) // Animation Preview
+    {
+        updateMotions(LLCharacter::FORCE_UPDATE);
+    }
+    else
+    {
+        // Might be better to do HIDDEN_UPDATE if cloud
+        updateMotions(LLCharacter::NORMAL_UPDATE);
+    }
+
+    // Special handling for sitting on ground.
+    if (!getParent() && (isSitting() || was_sit_ground_constrained))
+    {
+
+        F32 off_z = LLVector3d(getHoverOffset()).mdV[VZ];
+        if (off_z != 0.0)
+        {
+            LLVector3 pos = mRoot->getWorldPosition();
+            pos.mV[VZ] += off_z;
+            mRoot->touch();
+            // SL-315
+            mRoot->setWorldPosition(pos);
+        }
+    }
+
+    // update head position
+    updateHeadOffset();
+
+    // Generate footstep sounds when feet hit the ground
     updateFootstepSounds();
 
-	// Update child joints as needed.
-	mRoot->updateWorldMatrixChildren();
+    // Update child joints as needed.
+    mRoot->updateWorldMatrixChildren();
 
     if (visible)
     {
-		// System avatar mesh vertices need to be reskinned.
-		mNeedsSkin = TRUE;
+        // System avatar mesh vertices need to be reskinned.
+        mNeedsSkin = TRUE;
     }
 
-	return visible;
+    return visible;
 }
 
 //-----------------------------------------------------------------------------
@@ -4959,226 +4959,226 @@ bool LLVOAvatar::updateCharacter(LLAgent &agent)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::updateHeadOffset()
 {
-	// since we only care about Z, just grab one of the eyes
-	LLVector3 midEyePt = mEyeLeftp->getWorldPosition();
-	midEyePt -= mDrawable.notNull() ? mDrawable->getWorldPosition() : mRoot->getWorldPosition();
-	midEyePt.mV[VZ] = llmax(-mPelvisToFoot + LLViewerCamera::getInstance()->getNear(), midEyePt.mV[VZ]);
-
-	if (mDrawable.notNull())
-	{
-		midEyePt = midEyePt * ~mDrawable->getWorldRotation();
-	}
-	if (isSitting())
-	{
-		mHeadOffset = midEyePt;	
-	}
-	else
-	{
-		F32 u = llmax(0.f, HEAD_MOVEMENT_AVG_TIME - (1.f / gFPSClamped));
-		mHeadOffset = lerp(midEyePt, mHeadOffset,  u);
-	}
+    // since we only care about Z, just grab one of the eyes
+    LLVector3 midEyePt = mEyeLeftp->getWorldPosition();
+    midEyePt -= mDrawable.notNull() ? mDrawable->getWorldPosition() : mRoot->getWorldPosition();
+    midEyePt.mV[VZ] = llmax(-mPelvisToFoot + LLViewerCamera::getInstance()->getNear(), midEyePt.mV[VZ]);
+
+    if (mDrawable.notNull())
+    {
+        midEyePt = midEyePt * ~mDrawable->getWorldRotation();
+    }
+    if (isSitting())
+    {
+        mHeadOffset = midEyePt;
+    }
+    else
+    {
+        F32 u = llmax(0.f, HEAD_MOVEMENT_AVG_TIME - (1.f / gFPSClamped));
+        mHeadOffset = lerp(midEyePt, mHeadOffset,  u);
+    }
 }
 
 void LLVOAvatar::debugBodySize() const
 {
-	LLVector3 pelvis_scale = mPelvisp->getScale();
+    LLVector3 pelvis_scale = mPelvisp->getScale();
 
-	// some of the joints have not been cached
-	LLVector3 skull = mSkullp->getPosition();
+    // some of the joints have not been cached
+    LLVector3 skull = mSkullp->getPosition();
     LL_DEBUGS("Avatar") << "skull pos " << skull << LL_ENDL;
-	//LLVector3 skull_scale = mSkullp->getScale();
+    //LLVector3 skull_scale = mSkullp->getScale();
 
-	LLVector3 neck = mNeckp->getPosition();
-	LLVector3 neck_scale = mNeckp->getScale();
+    LLVector3 neck = mNeckp->getPosition();
+    LLVector3 neck_scale = mNeckp->getScale();
     LL_DEBUGS("Avatar") << "neck pos " << neck << " neck_scale " << neck_scale << LL_ENDL;
 
-	LLVector3 chest = mChestp->getPosition();
-	LLVector3 chest_scale = mChestp->getScale();
+    LLVector3 chest = mChestp->getPosition();
+    LLVector3 chest_scale = mChestp->getScale();
     LL_DEBUGS("Avatar") << "chest pos " << chest << " chest_scale " << chest_scale << LL_ENDL;
 
-	// the rest of the joints have been cached
-	LLVector3 head = mHeadp->getPosition();
-	LLVector3 head_scale = mHeadp->getScale();
+    // the rest of the joints have been cached
+    LLVector3 head = mHeadp->getPosition();
+    LLVector3 head_scale = mHeadp->getScale();
     LL_DEBUGS("Avatar") << "head pos " << head << " head_scale " << head_scale << LL_ENDL;
 
-	LLVector3 torso = mTorsop->getPosition();
-	LLVector3 torso_scale = mTorsop->getScale();
+    LLVector3 torso = mTorsop->getPosition();
+    LLVector3 torso_scale = mTorsop->getScale();
     LL_DEBUGS("Avatar") << "torso pos " << torso << " torso_scale " << torso_scale << LL_ENDL;
 
-	LLVector3 hip = mHipLeftp->getPosition();
-	LLVector3 hip_scale = mHipLeftp->getScale();
+    LLVector3 hip = mHipLeftp->getPosition();
+    LLVector3 hip_scale = mHipLeftp->getScale();
     LL_DEBUGS("Avatar") << "hip pos " << hip << " hip_scale " << hip_scale << LL_ENDL;
 
-	LLVector3 knee = mKneeLeftp->getPosition();
-	LLVector3 knee_scale = mKneeLeftp->getScale();
+    LLVector3 knee = mKneeLeftp->getPosition();
+    LLVector3 knee_scale = mKneeLeftp->getScale();
     LL_DEBUGS("Avatar") << "knee pos " << knee << " knee_scale " << knee_scale << LL_ENDL;
 
-	LLVector3 ankle = mAnkleLeftp->getPosition();
-	LLVector3 ankle_scale = mAnkleLeftp->getScale();
+    LLVector3 ankle = mAnkleLeftp->getPosition();
+    LLVector3 ankle_scale = mAnkleLeftp->getScale();
     LL_DEBUGS("Avatar") << "ankle pos " << ankle << " ankle_scale " << ankle_scale << LL_ENDL;
 
-	LLVector3 foot  = mFootLeftp->getPosition();
+    LLVector3 foot  = mFootLeftp->getPosition();
     LL_DEBUGS("Avatar") << "foot pos " << foot << LL_ENDL;
 
-	F32 new_offset = (const_cast<LLVOAvatar*>(this))->getVisualParamWeight(AVATAR_HOVER);
+    F32 new_offset = (const_cast<LLVOAvatar*>(this))->getVisualParamWeight(AVATAR_HOVER);
     LL_DEBUGS("Avatar") << "new_offset " << new_offset << LL_ENDL;
 
-	F32 new_pelvis_to_foot = hip.mV[VZ] * pelvis_scale.mV[VZ] -
+    F32 new_pelvis_to_foot = hip.mV[VZ] * pelvis_scale.mV[VZ] -
         knee.mV[VZ] * hip_scale.mV[VZ] -
         ankle.mV[VZ] * knee_scale.mV[VZ] -
         foot.mV[VZ] * ankle_scale.mV[VZ];
     LL_DEBUGS("Avatar") << "new_pelvis_to_foot " << new_pelvis_to_foot << LL_ENDL;
 
-	LLVector3 new_body_size;
-	new_body_size.mV[VZ] = new_pelvis_to_foot +
-					   // the sqrt(2) correction below is an approximate
-					   // correction to get to the top of the head
-					   F_SQRT2 * (skull.mV[VZ] * head_scale.mV[VZ]) + 
-					   head.mV[VZ] * neck_scale.mV[VZ] + 
-					   neck.mV[VZ] * chest_scale.mV[VZ] + 
-					   chest.mV[VZ] * torso_scale.mV[VZ] + 
-					   torso.mV[VZ] * pelvis_scale.mV[VZ]; 
+    LLVector3 new_body_size;
+    new_body_size.mV[VZ] = new_pelvis_to_foot +
+                       // the sqrt(2) correction below is an approximate
+                       // correction to get to the top of the head
+                       F_SQRT2 * (skull.mV[VZ] * head_scale.mV[VZ]) +
+                       head.mV[VZ] * neck_scale.mV[VZ] +
+                       neck.mV[VZ] * chest_scale.mV[VZ] +
+                       chest.mV[VZ] * torso_scale.mV[VZ] +
+                       torso.mV[VZ] * pelvis_scale.mV[VZ];
 
-	// TODO -- measure the real depth and width
-	new_body_size.mV[VX] = DEFAULT_AGENT_DEPTH;
-	new_body_size.mV[VY] = DEFAULT_AGENT_WIDTH;
+    // TODO -- measure the real depth and width
+    new_body_size.mV[VX] = DEFAULT_AGENT_DEPTH;
+    new_body_size.mV[VY] = DEFAULT_AGENT_WIDTH;
 
     LL_DEBUGS("Avatar") << "new_body_size " << new_body_size << LL_ENDL;
 }
-   
+
 //------------------------------------------------------------------------
 // postPelvisSetRecalc
 //------------------------------------------------------------------------
 void LLVOAvatar::postPelvisSetRecalc()
-{		
-	mRoot->updateWorldMatrixChildren();			
-	computeBodySize();
-	dirtyMesh(2);
+{
+    mRoot->updateWorldMatrixChildren();
+    computeBodySize();
+    dirtyMesh(2);
 }
 //------------------------------------------------------------------------
 // updateVisibility()
 //------------------------------------------------------------------------
 void LLVOAvatar::updateVisibility()
 {
-	BOOL visible = FALSE;
-
-	if (mIsDummy)
-	{
-		visible = FALSE;
-	}
-	else if (mDrawable.isNull())
-	{
-		visible = FALSE;
-	}
-	else
-	{
-		if (!mDrawable->getSpatialGroup() || mDrawable->getSpatialGroup()->isVisible())
-		{
-			visible = TRUE;
-		}
-		else
-		{
-			visible = FALSE;
-		}
-
-		if(isSelf())
-		{
-			if (!gAgentWearables.areWearablesLoaded())
-			{
-				visible = FALSE;
-			}
-		}
-		else if( !mFirstAppearanceMessageReceived )
-		{
-			visible = FALSE;
-		}
-
-		if (sDebugInvisible)
-		{
-			LLNameValue* firstname = getNVPair("FirstName");
-			if (firstname)
-			{
-				LL_DEBUGS("Avatar") << avString() << " updating visibility" << LL_ENDL;
-			}
-			else
-			{
-				LL_INFOS() << "Avatar " << this << " updating visiblity" << LL_ENDL;
-			}
-
-			if (visible)
-			{
-				LL_INFOS() << "Visible" << LL_ENDL;
-			}
-			else
-			{
-				LL_INFOS() << "Not visible" << LL_ENDL;
-			}
-
-			/*if (avatar_in_frustum)
-			{
-				LL_INFOS() << "Avatar in frustum" << LL_ENDL;
-			}
-			else
-			{
-				LL_INFOS() << "Avatar not in frustum" << LL_ENDL;
-			}*/
-
-			/*if (LLViewerCamera::getInstance()->sphereInFrustum(sel_pos_agent, 2.0f))
-			{
-				LL_INFOS() << "Sel pos visible" << LL_ENDL;
-			}
-			if (LLViewerCamera::getInstance()->sphereInFrustum(wrist_right_pos_agent, 0.2f))
-			{
-				LL_INFOS() << "Wrist pos visible" << LL_ENDL;
-			}
-			if (LLViewerCamera::getInstance()->sphereInFrustum(getPositionAgent(), getMaxScale()*2.f))
-			{
-				LL_INFOS() << "Agent visible" << LL_ENDL;
-			}*/
-			LL_INFOS() << "PA: " << getPositionAgent() << LL_ENDL;
-			/*LL_INFOS() << "SPA: " << sel_pos_agent << LL_ENDL;
-			LL_INFOS() << "WPA: " << wrist_right_pos_agent << LL_ENDL;*/
-			for (const auto& attach_pair : mAttachmentPoints)
-			{
-				LLViewerJointAttachment* attachment = attach_pair.second;
-				if (!attachment) continue;
-				for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-				{
-					{
-						if(attached_object && attached_object->mDrawable->isVisible())
-						{
-							LL_INFOS() << attachment->getName() << " visible" << LL_ENDL;
-						}
-						else
-						{
-							LL_INFOS() << attachment->getName() << " not visible at " << mDrawable->getWorldPosition() << " and radius " << mDrawable->getRadius() << LL_ENDL;
-						}
-					}
-				}
-			}
-		}
-	}
-
-	if (!visible && mVisible)
-	{
-		mMeshInvisibleTime.reset();
-	}
-
-	if (visible)
-	{
-		if (!mMeshValid)
-		{
-			restoreMeshData();
-		}
-	}
-	else
-	{
-		if (mMeshValid &&
+    BOOL visible = FALSE;
+
+    if (mIsDummy)
+    {
+        visible = FALSE;
+    }
+    else if (mDrawable.isNull())
+    {
+        visible = FALSE;
+    }
+    else
+    {
+        if (!mDrawable->getSpatialGroup() || mDrawable->getSpatialGroup()->isVisible())
+        {
+            visible = TRUE;
+        }
+        else
+        {
+            visible = FALSE;
+        }
+
+        if(isSelf())
+        {
+            if (!gAgentWearables.areWearablesLoaded())
+            {
+                visible = FALSE;
+            }
+        }
+        else if( !mFirstAppearanceMessageReceived )
+        {
+            visible = FALSE;
+        }
+
+        if (sDebugInvisible)
+        {
+            LLNameValue* firstname = getNVPair("FirstName");
+            if (firstname)
+            {
+                LL_DEBUGS("Avatar") << avString() << " updating visibility" << LL_ENDL;
+            }
+            else
+            {
+                LL_INFOS() << "Avatar " << this << " updating visiblity" << LL_ENDL;
+            }
+
+            if (visible)
+            {
+                LL_INFOS() << "Visible" << LL_ENDL;
+            }
+            else
+            {
+                LL_INFOS() << "Not visible" << LL_ENDL;
+            }
+
+            /*if (avatar_in_frustum)
+            {
+                LL_INFOS() << "Avatar in frustum" << LL_ENDL;
+            }
+            else
+            {
+                LL_INFOS() << "Avatar not in frustum" << LL_ENDL;
+            }*/
+
+            /*if (LLViewerCamera::getInstance()->sphereInFrustum(sel_pos_agent, 2.0f))
+            {
+                LL_INFOS() << "Sel pos visible" << LL_ENDL;
+            }
+            if (LLViewerCamera::getInstance()->sphereInFrustum(wrist_right_pos_agent, 0.2f))
+            {
+                LL_INFOS() << "Wrist pos visible" << LL_ENDL;
+            }
+            if (LLViewerCamera::getInstance()->sphereInFrustum(getPositionAgent(), getMaxScale()*2.f))
+            {
+                LL_INFOS() << "Agent visible" << LL_ENDL;
+            }*/
+            LL_INFOS() << "PA: " << getPositionAgent() << LL_ENDL;
+            /*LL_INFOS() << "SPA: " << sel_pos_agent << LL_ENDL;
+            LL_INFOS() << "WPA: " << wrist_right_pos_agent << LL_ENDL;*/
+            for (const auto& attach_pair : mAttachmentPoints)
+            {
+                LLViewerJointAttachment* attachment = attach_pair.second;
+                if (!attachment) continue;
+                for (LLViewerObject* attached_object : attachment->mAttachedObjects)
+                {
+                    {
+                        if(attached_object && attached_object->mDrawable->isVisible())
+                        {
+                            LL_INFOS() << attachment->getName() << " visible" << LL_ENDL;
+                        }
+                        else
+                        {
+                            LL_INFOS() << attachment->getName() << " not visible at " << mDrawable->getWorldPosition() << " and radius " << mDrawable->getRadius() << LL_ENDL;
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    if (!visible && mVisible)
+    {
+        mMeshInvisibleTime.reset();
+    }
+
+    if (visible)
+    {
+        if (!mMeshValid)
+        {
+            restoreMeshData();
+        }
+    }
+    else
+    {
+        if (mMeshValid &&
             (isControlAvatar() || mMeshInvisibleTime.getElapsedTimeF32() > TIME_BEFORE_MESH_CLEANUP))
-		{
-			releaseMeshData();
-		}
-	}
+        {
+            releaseMeshData();
+        }
+    }
 
 #ifdef SHOW_DEBUG
     if ( visible != mVisible )
@@ -5186,16 +5186,16 @@ void LLVOAvatar::updateVisibility()
         LL_DEBUGS("AvatarRender") << "visible was " << mVisible << " now " << visible << LL_ENDL;
     }
 #endif
-	mVisible = visible;
+    mVisible = visible;
 }
 
 // private
 bool LLVOAvatar::shouldAlphaMask()
 {
-	const bool should_alpha_mask = !LLDrawPoolAlpha::sShowDebugAlpha // Don't alpha mask if "Highlight Transparent" checked
-							&& !LLDrawPoolAvatar::sSkipTransparent;
+    const bool should_alpha_mask = !LLDrawPoolAlpha::sShowDebugAlpha // Don't alpha mask if "Highlight Transparent" checked
+                            && !LLDrawPoolAvatar::sSkipTransparent;
 
-	return should_alpha_mask;
+    return should_alpha_mask;
 
 }
 
@@ -5206,237 +5206,237 @@ U32 LLVOAvatar::renderSkinned()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
 
-	U32 num_indices = 0;
+    U32 num_indices = 0;
+
+    if (!mIsBuilt)
+    {
+        return num_indices;
+    }
+
+    if (mDrawable.isNull())
+    {
+        return num_indices;
+    }
+
+    LLFace* face = mDrawable->getFace(0);
+
+    bool needs_rebuild = !face || !face->getVertexBuffer() || mDrawable->isState(LLDrawable::REBUILD_GEOMETRY);
+
+    if (needs_rebuild || mDirtyMesh)
+    {   //LOD changed or new mesh created, allocate new vertex buffer if needed
+        if (needs_rebuild || mDirtyMesh >= 2 || mVisibilityRank <= 4)
+        {
+            updateMeshData();
+            mDirtyMesh = 0;
+            mNeedsSkin = TRUE;
+            mDrawable->clearState(LLDrawable::REBUILD_GEOMETRY);
+        }
+    }
+
+    if (LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_AVATAR) <= 0)
+    {
+        if (mNeedsSkin)
+        {
+            //generate animated mesh
+            LLViewerJoint* lower_mesh = getViewerJoint(MESH_ID_LOWER_BODY);
+            LLViewerJoint* upper_mesh = getViewerJoint(MESH_ID_UPPER_BODY);
+            LLViewerJoint* skirt_mesh = getViewerJoint(MESH_ID_SKIRT);
+            LLViewerJoint* eyelash_mesh = getViewerJoint(MESH_ID_EYELASH);
+            LLViewerJoint* head_mesh = getViewerJoint(MESH_ID_HEAD);
+            LLViewerJoint* hair_mesh = getViewerJoint(MESH_ID_HAIR);
+
+            if(upper_mesh)
+            {
+                upper_mesh->updateJointGeometry();
+            }
+            if (lower_mesh)
+            {
+                lower_mesh->updateJointGeometry();
+            }
+
+            if( isWearingWearableType( LLWearableType::WT_SKIRT ) )
+            {
+                if(skirt_mesh)
+                {
+                    skirt_mesh->updateJointGeometry();
+                }
+            }
+
+            if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
+            {
+                if(eyelash_mesh)
+                {
+                    eyelash_mesh->updateJointGeometry();
+                }
+                if(head_mesh)
+                {
+                    head_mesh->updateJointGeometry();
+                }
+                if(hair_mesh)
+                {
+                    hair_mesh->updateJointGeometry();
+                }
+            }
+            mNeedsSkin = FALSE;
+            mLastSkinTime = gFrameTimeSeconds;
+
+            LLFace * face = mDrawable->getFace(0);
+            if (face)
+            {
+                LLVertexBuffer* vb = face->getVertexBuffer();
+                if (vb)
+                {
+                    vb->unmapBuffer();
+                }
+            }
+        }
+    }
+    else
+    {
+        mNeedsSkin = FALSE;
+    }
+
+    if (sDebugInvisible)
+    {
+        LLNameValue* firstname = getNVPair("FirstName");
+        if (firstname)
+        {
+            LL_DEBUGS("Avatar") << avString() << " in render" << LL_ENDL;
+        }
+        else
+        {
+            LL_INFOS() << "Avatar " << this << " in render" << LL_ENDL;
+        }
+        if (!mIsBuilt)
+        {
+            LL_INFOS() << "Not built!" << LL_ENDL;
+        }
+        else if (!gAgent.needsRenderAvatar())
+        {
+            LL_INFOS() << "Doesn't need avatar render!" << LL_ENDL;
+        }
+        else
+        {
+            LL_INFOS() << "Rendering!" << LL_ENDL;
+        }
+    }
+
+    if (!mIsBuilt)
+    {
+        return num_indices;
+    }
+
+    if (isSelf() && !gAgent.needsRenderAvatar())
+    {
+        return num_indices;
+    }
+
+    //--------------------------------------------------------------------
+    // render all geometry attached to the skeleton
+    //--------------------------------------------------------------------
+
+        BOOL first_pass = TRUE;
+        if (!LLDrawPoolAvatar::sSkipOpaque)
+        {
+            if (isUIAvatar() && mIsDummy)
+            {
+                LLViewerJoint* hair_mesh = getViewerJoint(MESH_ID_HAIR);
+                if (hair_mesh)
+                {
+                    num_indices += hair_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
+                }
+                first_pass = FALSE;
+            }
+            if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
+            {
+
+                if (isTextureVisible(TEX_HEAD_BAKED) || (getOverallAppearance() == AOA_JELLYDOLL && !isControlAvatar()) || isUIAvatar())
+                {
+                    LLViewerJoint* head_mesh = getViewerJoint(MESH_ID_HEAD);
+                    if (head_mesh)
+                    {
+                        num_indices += head_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
+                    }
+                    first_pass = FALSE;
+                }
+            }
+            if (isTextureVisible(TEX_UPPER_BAKED) || (getOverallAppearance() == AOA_JELLYDOLL && !isControlAvatar()) || isUIAvatar())
+            {
+                LLViewerJoint* upper_mesh = getViewerJoint(MESH_ID_UPPER_BODY);
+                if (upper_mesh)
+                {
+                    num_indices += upper_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
+                }
+                first_pass = FALSE;
+            }
+
+            if (isTextureVisible(TEX_LOWER_BAKED) || (getOverallAppearance() == AOA_JELLYDOLL && !isControlAvatar()) || isUIAvatar())
+            {
+                LLViewerJoint* lower_mesh = getViewerJoint(MESH_ID_LOWER_BODY);
+                if (lower_mesh)
+                {
+                    num_indices += lower_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
+                }
+                first_pass = FALSE;
+            }
+        }
 
-	if (!mIsBuilt)
-	{
-		return num_indices;
-	}
+        if (!LLDrawPoolAvatar::sSkipTransparent || LLPipeline::sImpostorRender)
+        {
+            LLGLState blend(GL_BLEND, !mIsDummy);
+            num_indices += renderTransparent(first_pass);
+        }
 
-    if (mDrawable.isNull())
-    {
-		return num_indices;
-    }
-
-	LLFace* face = mDrawable->getFace(0);
-
-	bool needs_rebuild = !face || !face->getVertexBuffer() || mDrawable->isState(LLDrawable::REBUILD_GEOMETRY);
-
-	if (needs_rebuild || mDirtyMesh)
-	{	//LOD changed or new mesh created, allocate new vertex buffer if needed
-		if (needs_rebuild || mDirtyMesh >= 2 || mVisibilityRank <= 4)
-		{
-			updateMeshData();
-			mDirtyMesh = 0;
-			mNeedsSkin = TRUE;
-			mDrawable->clearState(LLDrawable::REBUILD_GEOMETRY);
-		}
-	}
-
-	if (LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_AVATAR) <= 0)
-	{
-		if (mNeedsSkin)
-		{
-			//generate animated mesh
-			LLViewerJoint* lower_mesh = getViewerJoint(MESH_ID_LOWER_BODY);
-			LLViewerJoint* upper_mesh = getViewerJoint(MESH_ID_UPPER_BODY);
-			LLViewerJoint* skirt_mesh = getViewerJoint(MESH_ID_SKIRT);
-			LLViewerJoint* eyelash_mesh = getViewerJoint(MESH_ID_EYELASH);
-			LLViewerJoint* head_mesh = getViewerJoint(MESH_ID_HEAD);
-			LLViewerJoint* hair_mesh = getViewerJoint(MESH_ID_HAIR);
-
-			if(upper_mesh)
-			{
-				upper_mesh->updateJointGeometry();
-			}
-			if (lower_mesh)
-			{
-				lower_mesh->updateJointGeometry();
-			}
-
-			if( isWearingWearableType( LLWearableType::WT_SKIRT ) )
-			{
-				if(skirt_mesh)
-				{
-					skirt_mesh->updateJointGeometry();
-				}
-			}
-
-			if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
-			{
-				if(eyelash_mesh)
-				{
-					eyelash_mesh->updateJointGeometry();
-				}
-				if(head_mesh)
-				{
-					head_mesh->updateJointGeometry();
-				}
-				if(hair_mesh)
-				{
-					hair_mesh->updateJointGeometry();
-				}
-			}
-			mNeedsSkin = FALSE;
-			mLastSkinTime = gFrameTimeSeconds;
-
-			LLFace * face = mDrawable->getFace(0);
-			if (face)
-			{
-				LLVertexBuffer* vb = face->getVertexBuffer();
-				if (vb)
-				{
-					vb->unmapBuffer();
-				}
-			}
-		}
-	}
-	else
-	{
-		mNeedsSkin = FALSE;
-	}
-
-	if (sDebugInvisible)
-	{
-		LLNameValue* firstname = getNVPair("FirstName");
-		if (firstname)
-		{
-			LL_DEBUGS("Avatar") << avString() << " in render" << LL_ENDL;
-		}
-		else
-		{
-			LL_INFOS() << "Avatar " << this << " in render" << LL_ENDL;
-		}
-		if (!mIsBuilt)
-		{
-			LL_INFOS() << "Not built!" << LL_ENDL;
-		}
-		else if (!gAgent.needsRenderAvatar())
-		{
-			LL_INFOS() << "Doesn't need avatar render!" << LL_ENDL;
-		}
-		else
-		{
-			LL_INFOS() << "Rendering!" << LL_ENDL;
-		}
-	}
-
-	if (!mIsBuilt)
-	{
-		return num_indices;
-	}
-
-	if (isSelf() && !gAgent.needsRenderAvatar())
-	{
-		return num_indices;
-	}
-
-	//--------------------------------------------------------------------
-	// render all geometry attached to the skeleton
-	//--------------------------------------------------------------------
-
-		BOOL first_pass = TRUE;
-		if (!LLDrawPoolAvatar::sSkipOpaque)
-		{
-			if (isUIAvatar() && mIsDummy)
-			{
-				LLViewerJoint* hair_mesh = getViewerJoint(MESH_ID_HAIR);
-				if (hair_mesh)
-				{
-					num_indices += hair_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
-				}
-				first_pass = FALSE;
-			}
-			if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
-			{
-	
-				if (isTextureVisible(TEX_HEAD_BAKED) || (getOverallAppearance() == AOA_JELLYDOLL && !isControlAvatar()) || isUIAvatar())
-				{
-					LLViewerJoint* head_mesh = getViewerJoint(MESH_ID_HEAD);
-					if (head_mesh)
-					{
-						num_indices += head_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
-					}
-					first_pass = FALSE;
-				}
-			}
-			if (isTextureVisible(TEX_UPPER_BAKED) || (getOverallAppearance() == AOA_JELLYDOLL && !isControlAvatar()) || isUIAvatar())
-			{
-				LLViewerJoint* upper_mesh = getViewerJoint(MESH_ID_UPPER_BODY);
-				if (upper_mesh)
-				{
-					num_indices += upper_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
-				}
-				first_pass = FALSE;
-			}
-			
-			if (isTextureVisible(TEX_LOWER_BAKED) || (getOverallAppearance() == AOA_JELLYDOLL && !isControlAvatar()) || isUIAvatar())
-			{
-				LLViewerJoint* lower_mesh = getViewerJoint(MESH_ID_LOWER_BODY);
-				if (lower_mesh)
-				{
-					num_indices += lower_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
-				}
-				first_pass = FALSE;
-			}
-		}
-
-		if (!LLDrawPoolAvatar::sSkipTransparent || LLPipeline::sImpostorRender)
-		{
-			LLGLState blend(GL_BLEND, !mIsDummy);
-			num_indices += renderTransparent(first_pass);
-		}
-
-	return num_indices;
+    return num_indices;
 }
 
 U32 LLVOAvatar::renderTransparent(BOOL first_pass)
 {
-	U32 num_indices = 0;
-	if( isWearingWearableType( LLWearableType::WT_SKIRT ) && (isUIAvatar() || isTextureVisible(TEX_SKIRT_BAKED)) )
-	{
+    U32 num_indices = 0;
+    if( isWearingWearableType( LLWearableType::WT_SKIRT ) && (isUIAvatar() || isTextureVisible(TEX_SKIRT_BAKED)) )
+    {
         gGL.flush();
-		LLViewerJoint* skirt_mesh = getViewerJoint(MESH_ID_SKIRT);
-		if (skirt_mesh)
-		{
-			num_indices += skirt_mesh->render(mAdjustedPixelArea, FALSE);
-		}
-		first_pass = FALSE;
+        LLViewerJoint* skirt_mesh = getViewerJoint(MESH_ID_SKIRT);
+        if (skirt_mesh)
+        {
+            num_indices += skirt_mesh->render(mAdjustedPixelArea, FALSE);
+        }
+        first_pass = FALSE;
         gGL.flush();
-	}
+    }
 
-	if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
-	{
-		if (LLPipeline::sImpostorRender)
-		{
+    if (!isSelf() || gAgent.needsRenderHead() || LLPipeline::sShadowRender)
+    {
+        if (LLPipeline::sImpostorRender)
+        {
             gGL.flush();
-		}
-		
-		if (isTextureVisible(TEX_HEAD_BAKED))
-		{
-			LLViewerJoint* eyelash_mesh = getViewerJoint(MESH_ID_EYELASH);
-			if (eyelash_mesh)
-			{
-				num_indices += eyelash_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
-			}
-			first_pass = FALSE;
-		}
-		if (isTextureVisible(TEX_HAIR_BAKED) && (getOverallAppearance() != AOA_JELLYDOLL))
-		{
-			LLViewerJoint* hair_mesh = getViewerJoint(MESH_ID_HAIR);
-			if (hair_mesh)
-			{
-				num_indices += hair_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
-			}
-			first_pass = FALSE;
-		}
-		if (LLPipeline::sImpostorRender)
-		{
+        }
+
+        if (isTextureVisible(TEX_HEAD_BAKED))
+        {
+            LLViewerJoint* eyelash_mesh = getViewerJoint(MESH_ID_EYELASH);
+            if (eyelash_mesh)
+            {
+                num_indices += eyelash_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
+            }
+            first_pass = FALSE;
+        }
+        if (isTextureVisible(TEX_HAIR_BAKED) && (getOverallAppearance() != AOA_JELLYDOLL))
+        {
+            LLViewerJoint* hair_mesh = getViewerJoint(MESH_ID_HAIR);
+            if (hair_mesh)
+            {
+                num_indices += hair_mesh->render(mAdjustedPixelArea, first_pass, mIsDummy);
+            }
+            first_pass = FALSE;
+        }
+        if (LLPipeline::sImpostorRender)
+        {
             gGL.flush();
-		}
-	}
-	
-	return num_indices;
+        }
+    }
+
+    return num_indices;
 }
 
 //-----------------------------------------------------------------------------
@@ -5444,401 +5444,401 @@ U32 LLVOAvatar::renderTransparent(BOOL first_pass)
 //-----------------------------------------------------------------------------
 U32 LLVOAvatar::renderRigid()
 {
-	U32 num_indices = 0;
+    U32 num_indices = 0;
 
-	if (!mIsBuilt)
-	{
-		return 0;
-	}
+    if (!mIsBuilt)
+    {
+        return 0;
+    }
 
-	if (isSelf() && (!gAgent.needsRenderAvatar() || !gAgent.needsRenderHead()))
-	{
-		return 0;
-	}
+    if (isSelf() && (!gAgent.needsRenderAvatar() || !gAgent.needsRenderHead()))
+    {
+        return 0;
+    }
 
-	if (isTextureVisible(TEX_EYES_BAKED) || (getOverallAppearance() == AOA_JELLYDOLL && !isControlAvatar()) || isUIAvatar())
-	{
-		LLViewerJoint* eyeball_left = getViewerJoint(MESH_ID_EYEBALL_LEFT);
-		LLViewerJoint* eyeball_right = getViewerJoint(MESH_ID_EYEBALL_RIGHT);
-		if (eyeball_left)
-		{
-			num_indices += eyeball_left->render(mAdjustedPixelArea, TRUE, mIsDummy);
-		}
-		if(eyeball_right)
-		{
-			num_indices += eyeball_right->render(mAdjustedPixelArea, TRUE, mIsDummy);
-		}
-	}
+    if (isTextureVisible(TEX_EYES_BAKED) || (getOverallAppearance() == AOA_JELLYDOLL && !isControlAvatar()) || isUIAvatar())
+    {
+        LLViewerJoint* eyeball_left = getViewerJoint(MESH_ID_EYEBALL_LEFT);
+        LLViewerJoint* eyeball_right = getViewerJoint(MESH_ID_EYEBALL_RIGHT);
+        if (eyeball_left)
+        {
+            num_indices += eyeball_left->render(mAdjustedPixelArea, TRUE, mIsDummy);
+        }
+        if(eyeball_right)
+        {
+            num_indices += eyeball_right->render(mAdjustedPixelArea, TRUE, mIsDummy);
+        }
+    }
 
-	return num_indices;
+    return num_indices;
 }
 
 U32 LLVOAvatar::renderImpostor(LLColor4U color, S32 diffuse_channel)
 {
-	if (!mImpostor.isComplete())
-	{
-		return 0;
-	}
-
-	auto& camera = LLViewerCamera::instance();
-
-	LLVector3 pos(getRenderPosition()+mImpostorOffset);
-	LLVector3 at = (pos - camera.getOrigin());
-	at.normalize();
-	LLVector3 left = camera.getUpAxis() % at;
-	LLVector3 up = at%left;
-
-	left *= mImpostorDim.mV[0];
-	up *= mImpostorDim.mV[1];
-
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_IMPOSTORS))
-	{
-		LLGLEnable blend(GL_BLEND);
-		gGL.setSceneBlendType(LLRender::BT_ADD);
-		gGL.getTexUnit(diffuse_channel)->unbind(LLTexUnit::TT_TEXTURE);
-
-		// gGL.begin(LLRender::QUADS);
-		// gGL.vertex3fv((pos+left-up).mV);
-		// gGL.vertex3fv((pos-left-up).mV);
-		// gGL.vertex3fv((pos-left+up).mV);
-		// gGL.vertex3fv((pos+left+up).mV);
-		// gGL.end();
-
-
-		gGL.begin(LLRender::LINES); 
-		gGL.color4f(1.f,1.f,1.f,1.f);
-		F32 thickness = llmax(F32(5.0f - 5.0f * (gFrameTimeSeconds - mLastImpostorUpdateFrameTime)), 1.0f);
-		gGL.setLineWidth(thickness);
-		gGL.vertex3fv((pos+left-up).mV);
-		gGL.vertex3fv((pos-left-up).mV);
-		gGL.vertex3fv((pos-left-up).mV);
-		gGL.vertex3fv((pos-left+up).mV);
-		gGL.vertex3fv((pos-left+up).mV);
-		gGL.vertex3fv((pos+left+up).mV);
-		gGL.vertex3fv((pos+left+up).mV);
-		gGL.vertex3fv((pos+left-up).mV);
-		gGL.end();
-		gGL.flush();
-	}
-	{
-	gGL.flush();
-
-	gGL.color4ubv(color.mV);
-	gGL.getTexUnit(diffuse_channel)->bind(&mImpostor);
-	gGL.begin(LLRender::TRIANGLE_STRIP);
-	gGL.texCoord2f(0,0);
-	gGL.vertex3fv((pos+left-up).mV);
-	gGL.texCoord2f(1,0);
-	gGL.vertex3fv((pos-left-up).mV);
-	gGL.texCoord2f(0, 1);
-	gGL.vertex3fv((pos + left + up).mV);
-	gGL.texCoord2f(1,1);
-	gGL.vertex3fv((pos-left+up).mV);
-	gGL.end();
-	gGL.flush();
-	}
-
-	return 6;
+    if (!mImpostor.isComplete())
+    {
+        return 0;
+    }
+
+    auto& camera = LLViewerCamera::instance();
+
+    LLVector3 pos(getRenderPosition()+mImpostorOffset);
+    LLVector3 at = (pos - camera.getOrigin());
+    at.normalize();
+    LLVector3 left = camera.getUpAxis() % at;
+    LLVector3 up = at%left;
+
+    left *= mImpostorDim.mV[0];
+    up *= mImpostorDim.mV[1];
+
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_IMPOSTORS))
+    {
+        LLGLEnable blend(GL_BLEND);
+        gGL.setSceneBlendType(LLRender::BT_ADD);
+        gGL.getTexUnit(diffuse_channel)->unbind(LLTexUnit::TT_TEXTURE);
+
+        // gGL.begin(LLRender::QUADS);
+        // gGL.vertex3fv((pos+left-up).mV);
+        // gGL.vertex3fv((pos-left-up).mV);
+        // gGL.vertex3fv((pos-left+up).mV);
+        // gGL.vertex3fv((pos+left+up).mV);
+        // gGL.end();
+
+
+        gGL.begin(LLRender::LINES);
+        gGL.color4f(1.f,1.f,1.f,1.f);
+        F32 thickness = llmax(F32(5.0f - 5.0f * (gFrameTimeSeconds - mLastImpostorUpdateFrameTime)), 1.0f);
+        gGL.setLineWidth(thickness);
+        gGL.vertex3fv((pos+left-up).mV);
+        gGL.vertex3fv((pos-left-up).mV);
+        gGL.vertex3fv((pos-left-up).mV);
+        gGL.vertex3fv((pos-left+up).mV);
+        gGL.vertex3fv((pos-left+up).mV);
+        gGL.vertex3fv((pos+left+up).mV);
+        gGL.vertex3fv((pos+left+up).mV);
+        gGL.vertex3fv((pos+left-up).mV);
+        gGL.end();
+        gGL.flush();
+    }
+    {
+    gGL.flush();
+
+    gGL.color4ubv(color.mV);
+    gGL.getTexUnit(diffuse_channel)->bind(&mImpostor);
+    gGL.begin(LLRender::TRIANGLE_STRIP);
+    gGL.texCoord2f(0,0);
+    gGL.vertex3fv((pos+left-up).mV);
+    gGL.texCoord2f(1,0);
+    gGL.vertex3fv((pos-left-up).mV);
+    gGL.texCoord2f(0, 1);
+    gGL.vertex3fv((pos + left + up).mV);
+    gGL.texCoord2f(1,1);
+    gGL.vertex3fv((pos-left+up).mV);
+    gGL.end();
+    gGL.flush();
+    }
+
+    return 6;
 }
 
 bool LLVOAvatar::allTexturesCompletelyDownloaded(std::set<LLUUID>& ids) const
 {
-	for (const LLUUID& id : ids)
-	{
-		LLViewerFetchedTexture *imagep = gTextureList.findImage(id, TEX_LIST_STANDARD);
-		if (imagep && imagep->getDiscardLevel()!=0)
-		{
-			return false;
-		}
-	}
-	return true;
+    for (const LLUUID& id : ids)
+    {
+        LLViewerFetchedTexture *imagep = gTextureList.findImage(id, TEX_LIST_STANDARD);
+        if (imagep && imagep->getDiscardLevel()!=0)
+        {
+            return false;
+        }
+    }
+    return true;
 }
 
 bool LLVOAvatar::allLocalTexturesCompletelyDownloaded() const
 {
-	std::set<LLUUID> local_ids;
-	collectLocalTextureUUIDs(local_ids);
-	return allTexturesCompletelyDownloaded(local_ids);
+    std::set<LLUUID> local_ids;
+    collectLocalTextureUUIDs(local_ids);
+    return allTexturesCompletelyDownloaded(local_ids);
 }
 
 bool LLVOAvatar::allBakedTexturesCompletelyDownloaded() const
 {
-	std::set<LLUUID> baked_ids;
-	collectBakedTextureUUIDs(baked_ids);
-	return allTexturesCompletelyDownloaded(baked_ids);
+    std::set<LLUUID> baked_ids;
+    collectBakedTextureUUIDs(baked_ids);
+    return allTexturesCompletelyDownloaded(baked_ids);
 }
 
 std::string LLVOAvatar::bakedTextureOriginInfo()
 {
-	std::string result;
-	
-	std::set<LLUUID> baked_ids;
-	collectBakedTextureUUIDs(baked_ids);
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		ETextureIndex texture_index = mBakedTextureDatas[i].mTextureIndex;
-		LLViewerFetchedTexture *imagep =
-			LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index,0), TRUE);
-		if (!imagep ||
-			imagep->getID() == IMG_DEFAULT ||
-			imagep->getID() == IMG_DEFAULT_AVATAR)
-			
-		{
-			result += "-";
-		}
-		else
-		{
-			bool has_url = false, has_host = false;
-			if (!imagep->getUrl().empty())
-			{
-				has_url = true;
-			}
-			if (imagep->getTargetHost().isOk())
-			{
-				has_host = true;
-			}
-			S32 discard = imagep->getDiscardLevel();
-			if (has_url && !has_host) result += discard ? "u" : "U"; // server-bake texture with url 
-			else if (has_host && !has_url) result += discard ? "h" : "H"; // old-style texture on sim
-			else if (has_host && has_url) result += discard ? "x" : "X"; // both origins?
-			else if (!has_host && !has_url) result += discard ? "n" : "N"; // no origin?
-			if (discard != 0)
-			{
-				result += llformat("(%d/%d)",discard,imagep->getDesiredDiscardLevel());
-			}
-		}
-
-	}
-	return result;
+    std::string result;
+
+    std::set<LLUUID> baked_ids;
+    collectBakedTextureUUIDs(baked_ids);
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        ETextureIndex texture_index = mBakedTextureDatas[i].mTextureIndex;
+        LLViewerFetchedTexture *imagep =
+            LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index,0), TRUE);
+        if (!imagep ||
+            imagep->getID() == IMG_DEFAULT ||
+            imagep->getID() == IMG_DEFAULT_AVATAR)
+
+        {
+            result += "-";
+        }
+        else
+        {
+            bool has_url = false, has_host = false;
+            if (!imagep->getUrl().empty())
+            {
+                has_url = true;
+            }
+            if (imagep->getTargetHost().isOk())
+            {
+                has_host = true;
+            }
+            S32 discard = imagep->getDiscardLevel();
+            if (has_url && !has_host) result += discard ? "u" : "U"; // server-bake texture with url
+            else if (has_host && !has_url) result += discard ? "h" : "H"; // old-style texture on sim
+            else if (has_host && has_url) result += discard ? "x" : "X"; // both origins?
+            else if (!has_host && !has_url) result += discard ? "n" : "N"; // no origin?
+            if (discard != 0)
+            {
+                result += llformat("(%d/%d)",discard,imagep->getDesiredDiscardLevel());
+            }
+        }
+
+    }
+    return result;
 }
 
 S32Bytes LLVOAvatar::totalTextureMemForUUIDS(std::set<LLUUID>& ids)
 {
-	S32Bytes result(0);
-	for (const LLUUID& id : ids)
-	{
-		LLViewerFetchedTexture *imagep = gTextureList.findImage(id, TEX_LIST_STANDARD);
-		if (imagep)
-		{
-			result += imagep->getTextureMemory();
-		}
-	}
-	return result;
-}
-	
+    S32Bytes result(0);
+    for (const LLUUID& id : ids)
+    {
+        LLViewerFetchedTexture *imagep = gTextureList.findImage(id, TEX_LIST_STANDARD);
+        if (imagep)
+        {
+            result += imagep->getTextureMemory();
+        }
+    }
+    return result;
+}
+
 void LLVOAvatar::collectLocalTextureUUIDs(std::set<LLUUID>& ids) const
 {
-	for (U32 texture_index = 0; texture_index < getNumTEs(); texture_index++)
-	{
-		LLWearableType::EType wearable_type = LLAvatarAppearance::getDictionary()->getTEWearableType((ETextureIndex)texture_index);
-		U32 num_wearables = gAgentWearables.getWearableCount(wearable_type);
-
-		LLViewerFetchedTexture *imagep = NULL;
-		for (U32 wearable_index = 0; wearable_index < num_wearables; wearable_index++)
-		{
-			imagep = LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index, wearable_index), TRUE);
-			if (imagep)
-			{
-				const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = LLAvatarAppearance::getDictionary()->getTexture((ETextureIndex)texture_index);
-				if (texture_dict && texture_dict->mIsLocalTexture)
-				{
-					ids.insert(imagep->getID());
-				}
-			}
-		}
-	}
-	ids.erase(IMG_DEFAULT);
-	ids.erase(IMG_DEFAULT_AVATAR);
-	ids.erase(IMG_INVISIBLE);
+    for (U32 texture_index = 0; texture_index < getNumTEs(); texture_index++)
+    {
+        LLWearableType::EType wearable_type = LLAvatarAppearance::getDictionary()->getTEWearableType((ETextureIndex)texture_index);
+        U32 num_wearables = gAgentWearables.getWearableCount(wearable_type);
+
+        LLViewerFetchedTexture *imagep = NULL;
+        for (U32 wearable_index = 0; wearable_index < num_wearables; wearable_index++)
+        {
+            imagep = LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index, wearable_index), TRUE);
+            if (imagep)
+            {
+                const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = LLAvatarAppearance::getDictionary()->getTexture((ETextureIndex)texture_index);
+                if (texture_dict && texture_dict->mIsLocalTexture)
+                {
+                    ids.insert(imagep->getID());
+                }
+            }
+        }
+    }
+    ids.erase(IMG_DEFAULT);
+    ids.erase(IMG_DEFAULT_AVATAR);
+    ids.erase(IMG_INVISIBLE);
 }
 
 void LLVOAvatar::collectBakedTextureUUIDs(std::set<LLUUID>& ids) const
 {
-	for (U32 texture_index = 0; texture_index < getNumTEs(); texture_index++)
-	{
-		LLViewerFetchedTexture *imagep = NULL;
-		if (isIndexBakedTexture((ETextureIndex) texture_index))
-		{
-			imagep = LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index,0), TRUE);
-			if (imagep)
-			{
-				ids.insert(imagep->getID());
-			}
-		}
-	}
-	ids.erase(IMG_DEFAULT);
-	ids.erase(IMG_DEFAULT_AVATAR);
-	ids.erase(IMG_INVISIBLE);
+    for (U32 texture_index = 0; texture_index < getNumTEs(); texture_index++)
+    {
+        LLViewerFetchedTexture *imagep = NULL;
+        if (isIndexBakedTexture((ETextureIndex) texture_index))
+        {
+            imagep = LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index,0), TRUE);
+            if (imagep)
+            {
+                ids.insert(imagep->getID());
+            }
+        }
+    }
+    ids.erase(IMG_DEFAULT);
+    ids.erase(IMG_DEFAULT_AVATAR);
+    ids.erase(IMG_INVISIBLE);
 }
 
 void LLVOAvatar::collectTextureUUIDs(std::set<LLUUID>& ids)
 {
-	collectLocalTextureUUIDs(ids);
-	collectBakedTextureUUIDs(ids);
+    collectLocalTextureUUIDs(ids);
+    collectBakedTextureUUIDs(ids);
 }
 
 void LLVOAvatar::releaseOldTextures()
 {
-	S32Bytes current_texture_mem;
-	
-	// Any textures that we used to be using but are no longer using should no longer be flagged as "NO_DELETE"
-	std::set<LLUUID> baked_texture_ids;
-	collectBakedTextureUUIDs(baked_texture_ids);
-	S32Bytes new_baked_mem = totalTextureMemForUUIDS(baked_texture_ids);
-
-	std::set<LLUUID> local_texture_ids;
-	collectLocalTextureUUIDs(local_texture_ids);
-	//S32 new_local_mem = totalTextureMemForUUIDS(local_texture_ids);
-
-	std::set<LLUUID> new_texture_ids;
-	new_texture_ids.insert(baked_texture_ids.begin(),baked_texture_ids.end());
-	new_texture_ids.insert(local_texture_ids.begin(),local_texture_ids.end());
-	S32Bytes new_total_mem = totalTextureMemForUUIDS(new_texture_ids);
-
-	//S32 old_total_mem = totalTextureMemForUUIDS(mTextureIDs);
-	//LL_DEBUGS("Avatar") << getFullname() << " old_total_mem: " << old_total_mem << " new_total_mem (L/B): " << new_total_mem << " (" << new_local_mem <<", " << new_baked_mem << ")" << LL_ENDL;  
-	if (!isSelf() && new_total_mem > new_baked_mem)
-	{
-			LL_WARNS() << "extra local textures stored for non-self av" << LL_ENDL;
-	}
-	for (const LLUUID& id : mTextureIDs)
-	{
-		if (new_texture_ids.find(id) == new_texture_ids.end())
-		{
-			LLViewerFetchedTexture *imagep = gTextureList.findImage(id, TEX_LIST_STANDARD);
-			if (imagep)
-			{
-				current_texture_mem += imagep->getTextureMemory();
-				if (imagep->getTextureState() == LLGLTexture::NO_DELETE)
-				{
-					// This will allow the texture to be deleted if not in use.
-					imagep->forceActive();
-
-					// This resets the clock to texture being flagged
-					// as unused, preventing the texture from being
-					// deleted immediately. If other avatars or
-					// objects are using it, it can still be flagged
-					// no-delete by them.
-					imagep->forceUpdateBindStats();
-				}
-			}
-		}
-	}
-	mTextureIDs = new_texture_ids;
+    S32Bytes current_texture_mem;
+
+    // Any textures that we used to be using but are no longer using should no longer be flagged as "NO_DELETE"
+    std::set<LLUUID> baked_texture_ids;
+    collectBakedTextureUUIDs(baked_texture_ids);
+    S32Bytes new_baked_mem = totalTextureMemForUUIDS(baked_texture_ids);
+
+    std::set<LLUUID> local_texture_ids;
+    collectLocalTextureUUIDs(local_texture_ids);
+    //S32 new_local_mem = totalTextureMemForUUIDS(local_texture_ids);
+
+    std::set<LLUUID> new_texture_ids;
+    new_texture_ids.insert(baked_texture_ids.begin(),baked_texture_ids.end());
+    new_texture_ids.insert(local_texture_ids.begin(),local_texture_ids.end());
+    S32Bytes new_total_mem = totalTextureMemForUUIDS(new_texture_ids);
+
+    //S32 old_total_mem = totalTextureMemForUUIDS(mTextureIDs);
+    //LL_DEBUGS("Avatar") << getFullname() << " old_total_mem: " << old_total_mem << " new_total_mem (L/B): " << new_total_mem << " (" << new_local_mem <<", " << new_baked_mem << ")" << LL_ENDL;
+    if (!isSelf() && new_total_mem > new_baked_mem)
+    {
+            LL_WARNS() << "extra local textures stored for non-self av" << LL_ENDL;
+    }
+    for (const LLUUID& id : mTextureIDs)
+    {
+        if (new_texture_ids.find(id) == new_texture_ids.end())
+        {
+            LLViewerFetchedTexture *imagep = gTextureList.findImage(id, TEX_LIST_STANDARD);
+            if (imagep)
+            {
+                current_texture_mem += imagep->getTextureMemory();
+                if (imagep->getTextureState() == LLGLTexture::NO_DELETE)
+                {
+                    // This will allow the texture to be deleted if not in use.
+                    imagep->forceActive();
+
+                    // This resets the clock to texture being flagged
+                    // as unused, preventing the texture from being
+                    // deleted immediately. If other avatars or
+                    // objects are using it, it can still be flagged
+                    // no-delete by them.
+                    imagep->forceUpdateBindStats();
+                }
+            }
+        }
+    }
+    mTextureIDs = new_texture_ids;
 }
 
 void LLVOAvatar::updateTextures()
 {
-	releaseOldTextures();
-	
-	BOOL render_avatar = TRUE;
-
-	if (mIsDummy)
-	{
-		return;
-	}
-
-	if( isSelf() )
-	{
-		render_avatar = TRUE;
-	}
-	else
-	{
-		if(!isVisible())
-		{
-			return ;//do not update for invisible avatar.
-		}
-
-		render_avatar = !mCulled; //visible and not culled.
-	}
-
-	std::vector<BOOL> layer_baked;
-	// GL NOT ACTIVE HERE - *TODO
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		layer_baked.push_back(isTextureDefined(mBakedTextureDatas[i].mTextureIndex));
-		// bind the texture so that they'll be decoded slightly 
-		// inefficient, we can short-circuit this if we have to
-		if (render_avatar && !gGLManager.mIsDisabled)
-		{
-			if (layer_baked[i] && !mBakedTextureDatas[i].mIsLoaded)
-			{
-				gGL.getTexUnit(0)->bind(getImage( mBakedTextureDatas[i].mTextureIndex, 0 ));
-			}
-		}
-	}
-
-	mMaxPixelArea = 0.f;
-	mMinPixelArea = 99999999.f;
-	mHasGrey = FALSE; // debug
-	for (U32 texture_index = 0; texture_index < getNumTEs(); texture_index++)
-	{
-		LLWearableType::EType wearable_type = LLAvatarAppearance::getDictionary()->getTEWearableType((ETextureIndex)texture_index);
-		U32 num_wearables = gAgentWearables.getWearableCount(wearable_type);
-		const LLTextureEntry *te = getTE(texture_index);
-
-		// getTE can return 0.
-		// Not sure yet why it does, but of course it crashes when te->mScale? gets used.
-		// Put safeguard in place so this corner case get better handling and does not result in a crash.
-		F32 texel_area_ratio = 1.0f;
-		if( te )
-		{
-			texel_area_ratio = fabs(te->mScaleS * te->mScaleT);
-		}
-		else
-		{
-			LL_WARNS() << "getTE( " << texture_index << " ) returned 0" <<LL_ENDL;
-		}
-
-		LLViewerFetchedTexture *imagep = NULL;
-		for (U32 wearable_index = 0; wearable_index < num_wearables; wearable_index++)
-		{
-			imagep = LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index, wearable_index), TRUE);
-			if (imagep)
-			{
-				const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = LLAvatarAppearance::getDictionary()->getTexture((ETextureIndex)texture_index);
-				const EBakedTextureIndex baked_index = texture_dict ? texture_dict->mBakedTextureIndex : EBakedTextureIndex::BAKED_NUM_INDICES;
-				if (texture_dict && texture_dict->mIsLocalTexture)
-				{
-					addLocalTextureStats((ETextureIndex)texture_index, imagep, texel_area_ratio, render_avatar, mBakedTextureDatas[baked_index].mIsUsed);
-				}
-			}
-		}
-		if (isIndexBakedTexture((ETextureIndex) texture_index) && render_avatar)
-		{
-			const S32 boost_level = getAvatarBakedBoostLevel();
-			imagep = LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index,0), TRUE);
-			addBakedTextureStats( imagep, mPixelArea, texel_area_ratio, boost_level );			
-		}
-	}
-
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_AREA))
-	{
-		setDebugText(llformat("%4.0f:%4.0f", (F32) sqrt(mMinPixelArea),(F32) sqrt(mMaxPixelArea)));
-	}	
+    releaseOldTextures();
+
+    BOOL render_avatar = TRUE;
+
+    if (mIsDummy)
+    {
+        return;
+    }
+
+    if( isSelf() )
+    {
+        render_avatar = TRUE;
+    }
+    else
+    {
+        if(!isVisible())
+        {
+            return ;//do not update for invisible avatar.
+        }
+
+        render_avatar = !mCulled; //visible and not culled.
+    }
+
+    std::vector<BOOL> layer_baked;
+    // GL NOT ACTIVE HERE - *TODO
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        layer_baked.push_back(isTextureDefined(mBakedTextureDatas[i].mTextureIndex));
+        // bind the texture so that they'll be decoded slightly
+        // inefficient, we can short-circuit this if we have to
+        if (render_avatar && !gGLManager.mIsDisabled)
+        {
+            if (layer_baked[i] && !mBakedTextureDatas[i].mIsLoaded)
+            {
+                gGL.getTexUnit(0)->bind(getImage( mBakedTextureDatas[i].mTextureIndex, 0 ));
+            }
+        }
+    }
+
+    mMaxPixelArea = 0.f;
+    mMinPixelArea = 99999999.f;
+    mHasGrey = FALSE; // debug
+    for (U32 texture_index = 0; texture_index < getNumTEs(); texture_index++)
+    {
+        LLWearableType::EType wearable_type = LLAvatarAppearance::getDictionary()->getTEWearableType((ETextureIndex)texture_index);
+        U32 num_wearables = gAgentWearables.getWearableCount(wearable_type);
+        const LLTextureEntry *te = getTE(texture_index);
+
+        // getTE can return 0.
+        // Not sure yet why it does, but of course it crashes when te->mScale? gets used.
+        // Put safeguard in place so this corner case get better handling and does not result in a crash.
+        F32 texel_area_ratio = 1.0f;
+        if( te )
+        {
+            texel_area_ratio = fabs(te->mScaleS * te->mScaleT);
+        }
+        else
+        {
+            LL_WARNS() << "getTE( " << texture_index << " ) returned 0" <<LL_ENDL;
+        }
+
+        LLViewerFetchedTexture *imagep = NULL;
+        for (U32 wearable_index = 0; wearable_index < num_wearables; wearable_index++)
+        {
+            imagep = LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index, wearable_index), TRUE);
+            if (imagep)
+            {
+                const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = LLAvatarAppearance::getDictionary()->getTexture((ETextureIndex)texture_index);
+                const EBakedTextureIndex baked_index = texture_dict ? texture_dict->mBakedTextureIndex : EBakedTextureIndex::BAKED_NUM_INDICES;
+                if (texture_dict && texture_dict->mIsLocalTexture)
+                {
+                    addLocalTextureStats((ETextureIndex)texture_index, imagep, texel_area_ratio, render_avatar, mBakedTextureDatas[baked_index].mIsUsed);
+                }
+            }
+        }
+        if (isIndexBakedTexture((ETextureIndex) texture_index) && render_avatar)
+        {
+            const S32 boost_level = getAvatarBakedBoostLevel();
+            imagep = LLViewerTextureManager::staticCastToFetchedTexture(getImage(texture_index,0), TRUE);
+            addBakedTextureStats( imagep, mPixelArea, texel_area_ratio, boost_level );
+        }
+    }
+
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_AREA))
+    {
+        setDebugText(llformat("%4.0f:%4.0f", (F32) sqrt(mMinPixelArea),(F32) sqrt(mMaxPixelArea)));
+    }
 }
 
 
 void LLVOAvatar::addLocalTextureStats( ETextureIndex idx, LLViewerFetchedTexture* imagep,
-									   F32 texel_area_ratio, BOOL render_avatar, BOOL covered_by_baked)
+                                       F32 texel_area_ratio, BOOL render_avatar, BOOL covered_by_baked)
 {
-	// No local texture stats for non-self avatars
-	return;
+    // No local texture stats for non-self avatars
+    return;
 }
 
-const S32 MAX_TEXTURE_UPDATE_INTERVAL = 64 ; //need to call updateTextures() at least every 32 frames.	
+const S32 MAX_TEXTURE_UPDATE_INTERVAL = 64 ; //need to call updateTextures() at least every 32 frames.
 const S32 MAX_TEXTURE_VIRTUAL_SIZE_RESET_INTERVAL = S32_MAX ; //frames
 void LLVOAvatar::checkTextureLoading()
 {
-	static const F32 MAX_INVISIBLE_WAITING_TIME = 15.f ; //seconds
+    static const F32 MAX_INVISIBLE_WAITING_TIME = 15.f ; //seconds
 
-	BOOL pause = !isVisible() ;
-	if(!pause)
-	{
-		mInvisibleTimer.reset() ;
-	}
-	if(mLoadedCallbacksPaused == pause)
-	{
+    BOOL pause = !isVisible() ;
+    if(!pause)
+    {
+        mInvisibleTimer.reset() ;
+    }
+    if(mLoadedCallbacksPaused == pause)
+    {
         if (!pause && mFirstFullyVisible && mLoadedCallbackTextures < mCallbackTextureList.size())
         {
             // We still need to update 'loaded' textures count to decide on 'cloud' visibility
@@ -5853,119 +5853,119 @@ void LLVOAvatar::checkTextureLoading()
                 }
             }
         }
-		return ; 
-	}
-	
-	if(mCallbackTextureList.empty()) //when is self or no callbacks. Note: this list for self is always empty.
-	{
-		mLoadedCallbacksPaused = pause ;
-		mLoadedCallbackTextures = 0;
-		return ; //nothing to check.
-	}
-	
-	if(pause && mInvisibleTimer.getElapsedTimeF32() < MAX_INVISIBLE_WAITING_TIME)
-	{
-		return ; //have not been invisible for enough time.
-	}
-
-	mLoadedCallbackTextures = pause ? mCallbackTextureList.size() : 0;
-
-	for(const LLTextureKey& texkey : mCallbackTextureList)
-	{
-		LLViewerFetchedTexture* tex = gTextureList.findImage(texkey) ;
-		if(tex)
-		{
-			if(pause)//pause texture fetching.
-			{
-				tex->pauseLoadedCallbacks(&mCallbackTextureList) ;
-
-				//set to terminate texture fetching after MAX_TEXTURE_UPDATE_INTERVAL frames.
-				tex->setMaxVirtualSizeResetInterval(MAX_TEXTURE_UPDATE_INTERVAL);
-				tex->resetMaxVirtualSizeResetCounter() ;
-			}
-			else//unpause
-			{
-				static const F32 START_AREA = 100.f ;
-
-				tex->unpauseLoadedCallbacks(&mCallbackTextureList) ;
-				tex->addTextureStats(START_AREA); //jump start the fetching again
-
-				// technically shouldn't need to account for missing, but callback might not have happened yet
-				if (tex->getDiscardLevel() >= 0 || tex->isMissingAsset())
-				{
-					mLoadedCallbackTextures++; // consider it loaded (we have at least some data)
-				}
-			}
-		}
-	}
-	
-	if(!pause)
-	{
-		updateTextures() ; //refresh texture stats.
-	}
-	mLoadedCallbacksPaused = pause ;
-	return ;
+        return ;
+    }
+
+    if(mCallbackTextureList.empty()) //when is self or no callbacks. Note: this list for self is always empty.
+    {
+        mLoadedCallbacksPaused = pause ;
+        mLoadedCallbackTextures = 0;
+        return ; //nothing to check.
+    }
+
+    if(pause && mInvisibleTimer.getElapsedTimeF32() < MAX_INVISIBLE_WAITING_TIME)
+    {
+        return ; //have not been invisible for enough time.
+    }
+
+    mLoadedCallbackTextures = pause ? mCallbackTextureList.size() : 0;
+
+    for(const LLTextureKey& texkey : mCallbackTextureList)
+    {
+        LLViewerFetchedTexture* tex = gTextureList.findImage(texkey) ;
+        if(tex)
+        {
+            if(pause)//pause texture fetching.
+            {
+                tex->pauseLoadedCallbacks(&mCallbackTextureList) ;
+
+                //set to terminate texture fetching after MAX_TEXTURE_UPDATE_INTERVAL frames.
+                tex->setMaxVirtualSizeResetInterval(MAX_TEXTURE_UPDATE_INTERVAL);
+                tex->resetMaxVirtualSizeResetCounter() ;
+            }
+            else//unpause
+            {
+                static const F32 START_AREA = 100.f ;
+
+                tex->unpauseLoadedCallbacks(&mCallbackTextureList) ;
+                tex->addTextureStats(START_AREA); //jump start the fetching again
+
+                // technically shouldn't need to account for missing, but callback might not have happened yet
+                if (tex->getDiscardLevel() >= 0 || tex->isMissingAsset())
+                {
+                    mLoadedCallbackTextures++; // consider it loaded (we have at least some data)
+                }
+            }
+        }
+    }
+
+    if(!pause)
+    {
+        updateTextures() ; //refresh texture stats.
+    }
+    mLoadedCallbacksPaused = pause ;
+    return ;
 }
 
 const F32  SELF_ADDITIONAL_PRI = 0.75f ;
 void LLVOAvatar::addBakedTextureStats( LLViewerFetchedTexture* imagep, F32 pixel_area, F32 texel_area_ratio, S32 boost_level)
 {
-	//Note:
-	//if this function is not called for the last MAX_TEXTURE_VIRTUAL_SIZE_RESET_INTERVAL frames, 
-	//the texture pipeline will stop fetching this texture.
+    //Note:
+    //if this function is not called for the last MAX_TEXTURE_VIRTUAL_SIZE_RESET_INTERVAL frames,
+    //the texture pipeline will stop fetching this texture.
 
-	imagep->resetTextureStats();
-	imagep->setMaxVirtualSizeResetInterval(MAX_TEXTURE_VIRTUAL_SIZE_RESET_INTERVAL);
-	imagep->resetMaxVirtualSizeResetCounter() ;
+    imagep->resetTextureStats();
+    imagep->setMaxVirtualSizeResetInterval(MAX_TEXTURE_VIRTUAL_SIZE_RESET_INTERVAL);
+    imagep->resetMaxVirtualSizeResetCounter() ;
 
-	mMaxPixelArea = llmax(pixel_area, mMaxPixelArea);
-	mMinPixelArea = llmin(pixel_area, mMinPixelArea);	
-	imagep->addTextureStats(pixel_area / texel_area_ratio);
-	imagep->setBoostLevel(boost_level);
+    mMaxPixelArea = llmax(pixel_area, mMaxPixelArea);
+    mMinPixelArea = llmin(pixel_area, mMinPixelArea);
+    imagep->addTextureStats(pixel_area / texel_area_ratio);
+    imagep->setBoostLevel(boost_level);
 }
 
-//virtual	
+//virtual
 void LLVOAvatar::setImage(const U8 te, LLViewerTexture *imagep, const U32 index)
 {
-	setTEImage(te, imagep);
+    setTEImage(te, imagep);
 }
 
-//virtual 
+//virtual
 LLViewerTexture* LLVOAvatar::getImage(const U8 te, const U32 index) const
 {
-	return getTEImage(te);
+    return getTEImage(te);
 }
-//virtual 
+//virtual
 const LLTextureEntry* LLVOAvatar::getTexEntry(const U8 te_num) const
 {
-	return getTE(te_num);
+    return getTE(te_num);
 }
 
-//virtual 
+//virtual
 void LLVOAvatar::setTexEntry(const U8 index, const LLTextureEntry &te)
 {
-	setTE(index, te);
+    setTE(index, te);
 }
 
 const std::string LLVOAvatar::getImageURL(const U8 te, const LLUUID &uuid)
 {
-	llassert(isIndexBakedTexture(ETextureIndex(te)));
-	std::string url = "";
-	const std::string& appearance_service_url = LLAppearanceMgr::instance().getAppearanceServiceURL();
-	if (appearance_service_url.empty())
-	{
-		// Probably a server-side issue if we get here:
-		LL_WARNS() << "AgentAppearanceServiceURL not set - Baked texture requests will fail" << LL_ENDL;
-		return url;
-	}
-	
-	const LLAvatarAppearanceDictionary::TextureEntry* texture_entry = LLAvatarAppearance::getDictionary()->getTexture((ETextureIndex)te);
-	if (texture_entry != NULL)
-	{
-		url = appearance_service_url + "texture/" + getID().asString() + "/" + texture_entry->mDefaultImageName + "/" + uuid.asString();
-		//LL_INFOS() << "baked texture url: " << url << LL_ENDL;
-	}
-	return url;
+    llassert(isIndexBakedTexture(ETextureIndex(te)));
+    std::string url = "";
+    const std::string& appearance_service_url = LLAppearanceMgr::instance().getAppearanceServiceURL();
+    if (appearance_service_url.empty())
+    {
+        // Probably a server-side issue if we get here:
+        LL_WARNS() << "AgentAppearanceServiceURL not set - Baked texture requests will fail" << LL_ENDL;
+        return url;
+    }
+
+    const LLAvatarAppearanceDictionary::TextureEntry* texture_entry = LLAvatarAppearance::getDictionary()->getTexture((ETextureIndex)te);
+    if (texture_entry != NULL)
+    {
+        url = appearance_service_url + "texture/" + getID().asString() + "/" + texture_entry->mDefaultImageName + "/" + uuid.asString();
+        //LL_INFOS() << "baked texture url: " << url << LL_ENDL;
+    }
+    return url;
 }
 
 //-----------------------------------------------------------------------------
@@ -5974,47 +5974,47 @@ const std::string LLVOAvatar::getImageURL(const U8 te, const LLUUID &uuid)
 
 void LLVOAvatar::resolveHeightAgent(const LLVector3 &in_pos_agent, LLVector3 &out_pos_agent, LLVector3 &out_norm)
 {
-	LLVector3d in_pos_global, out_pos_global;
+    LLVector3d in_pos_global, out_pos_global;
 
-	in_pos_global = gAgent.getPosGlobalFromAgent(in_pos_agent);
-	resolveHeightGlobal(in_pos_global, out_pos_global, out_norm);
-	out_pos_agent = gAgent.getPosAgentFromGlobal(out_pos_global);
+    in_pos_global = gAgent.getPosGlobalFromAgent(in_pos_agent);
+    resolveHeightGlobal(in_pos_global, out_pos_global, out_norm);
+    out_pos_agent = gAgent.getPosAgentFromGlobal(out_pos_global);
 }
 
 
 void LLVOAvatar::resolveRayCollisionAgent(const LLVector3d start_pt, const LLVector3d end_pt, LLVector3d &out_pos, LLVector3 &out_norm)
 {
-	LLViewerObject *obj;
-	LLWorld::getInstance()->resolveStepHeightGlobal(this, start_pt, end_pt, out_pos, out_norm, &obj);
+    LLViewerObject *obj;
+    LLWorld::getInstance()->resolveStepHeightGlobal(this, start_pt, end_pt, out_pos, out_norm, &obj);
 }
 
 void LLVOAvatar::resolveHeightGlobal(const LLVector3d &inPos, LLVector3d &outPos, LLVector3 &outNorm)
 {
-	LLVector3d zVec(0.0f, 0.0f, 0.5f);
-	LLVector3d p0 = inPos + zVec;
-	LLVector3d p1 = inPos - zVec;
-	LLViewerObject *obj;
-	LLWorld::getInstance()->resolveStepHeightGlobal(this, p0, p1, outPos, outNorm, &obj);
-	if (!obj)
-	{
-		mStepOnLand = TRUE;
-		mStepMaterial = 0;
-		mStepObjectVelocity.setVec(0.0f, 0.0f, 0.0f);
-	}
-	else
-	{
-		mStepOnLand = FALSE;
-		mStepMaterial = obj->getMaterial();
+    LLVector3d zVec(0.0f, 0.0f, 0.5f);
+    LLVector3d p0 = inPos + zVec;
+    LLVector3d p1 = inPos - zVec;
+    LLViewerObject *obj;
+    LLWorld::getInstance()->resolveStepHeightGlobal(this, p0, p1, outPos, outNorm, &obj);
+    if (!obj)
+    {
+        mStepOnLand = TRUE;
+        mStepMaterial = 0;
+        mStepObjectVelocity.setVec(0.0f, 0.0f, 0.0f);
+    }
+    else
+    {
+        mStepOnLand = FALSE;
+        mStepMaterial = obj->getMaterial();
 
-		// We want the primitive velocity, not our velocity... (which actually subtracts the
-		// step object velocity)
-		LLVector3 angularVelocity = obj->getAngularVelocity();
-		LLVector3 relativePos = gAgent.getPosAgentFromGlobal(outPos) - obj->getPositionAgent();
+        // We want the primitive velocity, not our velocity... (which actually subtracts the
+        // step object velocity)
+        LLVector3 angularVelocity = obj->getAngularVelocity();
+        LLVector3 relativePos = gAgent.getPosAgentFromGlobal(outPos) - obj->getPositionAgent();
 
-		LLVector3 linearComponent = angularVelocity % relativePos;
-//		LL_INFOS() << "Linear Component of Rotation Velocity " << linearComponent << LL_ENDL;
-		mStepObjectVelocity = obj->getVelocity() + linearComponent;
-	}
+        LLVector3 linearComponent = angularVelocity % relativePos;
+//      LL_INFOS() << "Linear Component of Rotation Velocity " << linearComponent << LL_ENDL;
+        mStepObjectVelocity = obj->getVelocity() + linearComponent;
+    }
 }
 
 
@@ -6023,12 +6023,12 @@ void LLVOAvatar::resolveHeightGlobal(const LLVector3d &inPos, LLVector3d &outPos
 //-----------------------------------------------------------------------------
 const LLUUID& LLVOAvatar::getStepSound() const
 {
-	if ( mStepOnLand )
-	{
-		return sStepSoundOnLand;
-	}
+    if ( mStepOnLand )
+    {
+        return sStepSoundOnLand;
+    }
 
-	return sStepSounds[mStepMaterial];
+    return sStepSounds[mStepMaterial];
 }
 
 
@@ -6037,104 +6037,104 @@ const LLUUID& LLVOAvatar::getStepSound() const
 //-----------------------------------------------------------------------------
 void LLVOAvatar::processAnimationStateChanges()
 {
-	if ( isAnyAnimationSignaled(AGENT_WALK_ANIMS, NUM_AGENT_WALK_ANIMS) )
-	{
-		startMotion(ANIM_AGENT_WALK_ADJUST);
-		stopMotion(ANIM_AGENT_FLY_ADJUST);
-	}
-	else if (mInAir && !isSitting())
-	{
-		stopMotion(ANIM_AGENT_WALK_ADJUST);
+    if ( isAnyAnimationSignaled(AGENT_WALK_ANIMS, NUM_AGENT_WALK_ANIMS) )
+    {
+        startMotion(ANIM_AGENT_WALK_ADJUST);
+        stopMotion(ANIM_AGENT_FLY_ADJUST);
+    }
+    else if (mInAir && !isSitting())
+    {
+        stopMotion(ANIM_AGENT_WALK_ADJUST);
         if (mEnableDefaultMotions)
         {
-		startMotion(ANIM_AGENT_FLY_ADJUST);
-	}
-	}
-	else
-	{
-		stopMotion(ANIM_AGENT_WALK_ADJUST);
-		stopMotion(ANIM_AGENT_FLY_ADJUST);
-	}
-
-	if ( isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) )
-	{
+        startMotion(ANIM_AGENT_FLY_ADJUST);
+    }
+    }
+    else
+    {
+        stopMotion(ANIM_AGENT_WALK_ADJUST);
+        stopMotion(ANIM_AGENT_FLY_ADJUST);
+    }
+
+    if ( isAnyAnimationSignaled(AGENT_GUN_AIM_ANIMS, NUM_AGENT_GUN_AIM_ANIMS) )
+    {
         if (mEnableDefaultMotions)
         {
-		startMotion(ANIM_AGENT_TARGET);
+        startMotion(ANIM_AGENT_TARGET);
         }
-		stopMotion(ANIM_AGENT_BODY_NOISE);
-	}
-	else
-	{
-		stopMotion(ANIM_AGENT_TARGET);
+        stopMotion(ANIM_AGENT_BODY_NOISE);
+    }
+    else
+    {
+        stopMotion(ANIM_AGENT_TARGET);
         if (mEnableDefaultMotions)
         {
-			startMotion(ANIM_AGENT_BODY_NOISE);
-		}
-	}
-	
-	// clear all current animations
-	for (auto anim_it = mPlayingAnimations.begin(); anim_it != mPlayingAnimations.end();)
-	{
-		AnimIterator found_anim = mSignaledAnimations.find(anim_it->first);
-
-		// playing, but not signaled, so stop
-		if (found_anim == mSignaledAnimations.end())
-		{
-			processSingleAnimationStateChange(anim_it->first, FALSE);
-			anim_it = mPlayingAnimations.erase(anim_it);
-		}
-		else
-		{
-			++anim_it;
-		}
-	}
-
-	// if jellydolled, shelve all playing animations
-	if (getOverallAppearance() != AOA_NORMAL)
-	{
-		mPlayingAnimations.clear();
-	}
-	
-	// start up all new anims
-	if (getOverallAppearance() == AOA_NORMAL)
-	{
-		for (auto anim_it = mSignaledAnimations.begin(); anim_it != mSignaledAnimations.end();)
-		{
-			AnimIterator found_anim = mPlayingAnimations.find(anim_it->first);
-
-			// signaled but not playing, or different sequence id, start motion
-			if (found_anim == mPlayingAnimations.end() || found_anim->second != anim_it->second)
-			{
-				if (processSingleAnimationStateChange(anim_it->first, TRUE))
-				{
-					mPlayingAnimations[anim_it->first] = anim_it->second;
-					++anim_it;
-					continue;
-				}
-			}
-
-			++anim_it;
-		}
-	}
-
-	// clear source information for animations which have been stopped
-	if (isSelf())
-	{
-		for (auto source_it = mAnimationSources.begin(); source_it != mAnimationSources.end();)
-		{
-			if (mSignaledAnimations.find(source_it->second) == mSignaledAnimations.end())
-			{
-				source_it = mAnimationSources.erase(source_it);
-			}
-			else
-			{
-				++source_it;
-			}
-		}
-	}
-
-	stop_glerror();
+            startMotion(ANIM_AGENT_BODY_NOISE);
+        }
+    }
+
+    // clear all current animations
+    for (auto anim_it = mPlayingAnimations.begin(); anim_it != mPlayingAnimations.end();)
+    {
+        AnimIterator found_anim = mSignaledAnimations.find(anim_it->first);
+
+        // playing, but not signaled, so stop
+        if (found_anim == mSignaledAnimations.end())
+        {
+            processSingleAnimationStateChange(anim_it->first, FALSE);
+            anim_it = mPlayingAnimations.erase(anim_it);
+        }
+        else
+        {
+            ++anim_it;
+        }
+    }
+
+    // if jellydolled, shelve all playing animations
+    if (getOverallAppearance() != AOA_NORMAL)
+    {
+        mPlayingAnimations.clear();
+    }
+
+    // start up all new anims
+    if (getOverallAppearance() == AOA_NORMAL)
+    {
+        for (auto anim_it = mSignaledAnimations.begin(); anim_it != mSignaledAnimations.end();)
+        {
+            AnimIterator found_anim = mPlayingAnimations.find(anim_it->first);
+
+            // signaled but not playing, or different sequence id, start motion
+            if (found_anim == mPlayingAnimations.end() || found_anim->second != anim_it->second)
+            {
+                if (processSingleAnimationStateChange(anim_it->first, TRUE))
+                {
+                    mPlayingAnimations[anim_it->first] = anim_it->second;
+                    ++anim_it;
+                    continue;
+                }
+            }
+
+            ++anim_it;
+        }
+    }
+
+    // clear source information for animations which have been stopped
+    if (isSelf())
+    {
+        for (auto source_it = mAnimationSources.begin(); source_it != mAnimationSources.end();)
+        {
+            if (mSignaledAnimations.find(source_it->second) == mSignaledAnimations.end())
+            {
+                source_it = mAnimationSources.erase(source_it);
+            }
+            else
+            {
+                ++source_it;
+            }
+        }
+    }
+
+    stop_glerror();
 }
 
 
@@ -6147,45 +6147,45 @@ BOOL LLVOAvatar::processSingleAnimationStateChange( const LLUUID& anim_id, BOOL
     // keep appearances in sync, but not so often that animations
     // cause constant jiggling of the body or camera. Possible
     // compromise is to do it on animation changes:
-	//BD - Poser
-	//     Don't refresh our root position while we pose otherwise moving any joint that moves
-	//     mFootLeft will trigger mRoot repositioning.
-	if (!isSelf() || !gAgent.getPosing())
-	{
+    //BD - Poser
+    //     Don't refresh our root position while we pose otherwise moving any joint that moves
+    //     mFootLeft will trigger mRoot repositioning.
+    if (!isSelf() || !gAgent.getPosing())
+    {
     computeBodySize();
-	}
-    
-	BOOL result = FALSE;
-
-	if ( start ) // start animation
-	{
-		if (anim_id == ANIM_AGENT_TYPE)
-		{
-			static LLCachedControl<bool> play_typing_sound(gSavedSettings, "PlayTypingSound", true);
-			if (gAudiop && play_typing_sound)
-			{
-				LLVector3d char_pos_global = gAgent.getPosGlobalFromAgent(getCharacterPosition());
-				if (LLViewerParcelMgr::getInstance()->canHearSound(char_pos_global)
-				    && !LLMuteList::getInstance()->isMuted(getID(), LLMute::flagObjectSounds))
-				{
-					// RN: uncomment this to play on typing sound at fixed volume once sound engine is fixed
-					// to support both spatialized and non-spatialized instances of the same sound
-					//if (isSelf())
-					//{
-					//	gAudiop->triggerSound(LLUUID(gSavedSettings.getString("UISndTyping")), 1.0f, LLAudioEngine::AUDIO_TYPE_UI);
-					//}
-					//else
-					{
+    }
+
+    BOOL result = FALSE;
+
+    if ( start ) // start animation
+    {
+        if (anim_id == ANIM_AGENT_TYPE)
+        {
+            static LLCachedControl<bool> play_typing_sound(gSavedSettings, "PlayTypingSound", true);
+            if (gAudiop && play_typing_sound)
+            {
+                LLVector3d char_pos_global = gAgent.getPosGlobalFromAgent(getCharacterPosition());
+                if (LLViewerParcelMgr::getInstance()->canHearSound(char_pos_global)
+                    && !LLMuteList::getInstance()->isMuted(getID(), LLMute::flagObjectSounds))
+                {
+                    // RN: uncomment this to play on typing sound at fixed volume once sound engine is fixed
+                    // to support both spatialized and non-spatialized instances of the same sound
+                    //if (isSelf())
+                    //{
+                    //  gAudiop->triggerSound(LLUUID(gSavedSettings.getString("UISndTyping")), 1.0f, LLAudioEngine::AUDIO_TYPE_UI);
+                    //}
+                    //else
+                    {
                         static LLCachedControl<std::string> ui_snd_string(gSavedSettings, "UISndTyping");
-						gAudiop->triggerSound(LLUUID(ui_snd_string()), getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_SFX, char_pos_global);
-					}
-				}
-			}
-		}
-		else if (anim_id == ANIM_AGENT_SIT_GROUND_CONSTRAINED)
-		{
-			sitDown(TRUE);
-		}
+                        gAudiop->triggerSound(LLUUID(ui_snd_string()), getID(), 1.0f, LLAudioEngine::AUDIO_TYPE_SFX, char_pos_global);
+                    }
+                }
+            }
+        }
+        else if (anim_id == ANIM_AGENT_SIT_GROUND_CONSTRAINED)
+        {
+            sitDown(TRUE);
+        }
         else if (anim_id == ANIM_AGENT_SNAPSHOT)
         {
             static LLCachedControl<bool> announce_snapshot(gSavedSettings, "SnapshotDetection");
@@ -6195,32 +6195,32 @@ BOOL LLVOAvatar::processSingleAnimationStateChange( const LLUUID& anim_id, BOOL
             }
         }
 
-		if (startMotion(anim_id))
-		{
-			result = TRUE;
-		}
-		else
-		{
-			LL_WARNS("Motion") << "Failed to start motion!" << LL_ENDL;
-		}
-	}
-	else //stop animation
-	{
-		if (anim_id == ANIM_AGENT_SIT_GROUND_CONSTRAINED)
-		{
-			sitDown(FALSE);
-		}
-		if ((anim_id == ANIM_AGENT_DO_NOT_DISTURB) && gAgent.isDoNotDisturb())
-		{
-			// re-assert DND tag animation
-			gAgent.sendAnimationRequest(ANIM_AGENT_DO_NOT_DISTURB, ANIM_REQUEST_START);
-			return result;
-		}
-		stopMotion(anim_id);
-		result = TRUE;
-	}
-
-	return result;
+        if (startMotion(anim_id))
+        {
+            result = TRUE;
+        }
+        else
+        {
+            LL_WARNS("Motion") << "Failed to start motion!" << LL_ENDL;
+        }
+    }
+    else //stop animation
+    {
+        if (anim_id == ANIM_AGENT_SIT_GROUND_CONSTRAINED)
+        {
+            sitDown(FALSE);
+        }
+        if ((anim_id == ANIM_AGENT_DO_NOT_DISTURB) && gAgent.isDoNotDisturb())
+        {
+            // re-assert DND tag animation
+            gAgent.sendAnimationRequest(ANIM_AGENT_DO_NOT_DISTURB, ANIM_REQUEST_START);
+            return result;
+        }
+        stopMotion(anim_id);
+        result = TRUE;
+    }
+
+    return result;
 }
 
 //-----------------------------------------------------------------------------
@@ -6228,14 +6228,14 @@ BOOL LLVOAvatar::processSingleAnimationStateChange( const LLUUID& anim_id, BOOL
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatar::isAnyAnimationSignaled(const LLUUID *anim_array, const S32 num_anims) const
 {
-	for (S32 i = 0; i < num_anims; i++)
-	{
-		if(mSignaledAnimations.find(anim_array[i]) != mSignaledAnimations.end())
-		{
-			return TRUE;
-		}
-	}
-	return FALSE;
+    for (S32 i = 0; i < num_anims; i++)
+    {
+        if(mSignaledAnimations.find(anim_array[i]) != mSignaledAnimations.end())
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 //-----------------------------------------------------------------------------
@@ -6243,8 +6243,8 @@ BOOL LLVOAvatar::isAnyAnimationSignaled(const LLUUID *anim_array, const S32 num_
 //-----------------------------------------------------------------------------
 void LLVOAvatar::resetAnimations()
 {
-	LLKeyframeMotion::flushKeyframeCache();
-	flushAllMotions();
+    LLKeyframeMotion::flushKeyframeCache();
+    flushAllMotions();
 }
 
 // Override selectively based on avatar sex and whether we're using new
@@ -6252,52 +6252,52 @@ void LLVOAvatar::resetAnimations()
 LLUUID LLVOAvatar::remapMotionID(const LLUUID& id)
 {
     static LLCachedControl<bool> use_new_walk_run(gSavedSettings, "UseNewWalkRun");
-	LLUUID result = id;
-
-	// start special case female walk for female avatars
-	if (getSex() == SEX_FEMALE)
-	{
-		if (id == ANIM_AGENT_WALK)
-		{
-			if (use_new_walk_run)
-				result = ANIM_AGENT_FEMALE_WALK_NEW;
-			else
-				result = ANIM_AGENT_FEMALE_WALK;
-		}
-		else if (id == ANIM_AGENT_RUN)
-		{
-			// There is no old female run animation, so only override
-			// in one case.
-			if (use_new_walk_run)
-				result = ANIM_AGENT_FEMALE_RUN_NEW;
-		}
-		else if (id == ANIM_AGENT_SIT)
-		{
-			result = ANIM_AGENT_SIT_FEMALE;
-		}
-	}
-	else
-	{
-		// Male avatar.
-		if (id == ANIM_AGENT_WALK)
-		{
-			if (use_new_walk_run)
-				result = ANIM_AGENT_WALK_NEW;
-		}
-		else if (id == ANIM_AGENT_RUN)
-		{
-			if (use_new_walk_run)
-				result = ANIM_AGENT_RUN_NEW;
-		}
-		// keeps in sync with setSex() related code (viewer controls sit's sex)
-		else if (id == ANIM_AGENT_SIT_FEMALE)
-		{
-			result = ANIM_AGENT_SIT;
-		}
-	
-	}
-
-	return result;
+    LLUUID result = id;
+
+    // start special case female walk for female avatars
+    if (getSex() == SEX_FEMALE)
+    {
+        if (id == ANIM_AGENT_WALK)
+        {
+            if (use_new_walk_run)
+                result = ANIM_AGENT_FEMALE_WALK_NEW;
+            else
+                result = ANIM_AGENT_FEMALE_WALK;
+        }
+        else if (id == ANIM_AGENT_RUN)
+        {
+            // There is no old female run animation, so only override
+            // in one case.
+            if (use_new_walk_run)
+                result = ANIM_AGENT_FEMALE_RUN_NEW;
+        }
+        else if (id == ANIM_AGENT_SIT)
+        {
+            result = ANIM_AGENT_SIT_FEMALE;
+        }
+    }
+    else
+    {
+        // Male avatar.
+        if (id == ANIM_AGENT_WALK)
+        {
+            if (use_new_walk_run)
+                result = ANIM_AGENT_WALK_NEW;
+        }
+        else if (id == ANIM_AGENT_RUN)
+        {
+            if (use_new_walk_run)
+                result = ANIM_AGENT_RUN_NEW;
+        }
+        // keeps in sync with setSex() related code (viewer controls sit's sex)
+        else if (id == ANIM_AGENT_SIT_FEMALE)
+        {
+            result = ANIM_AGENT_SIT;
+        }
+
+    }
+
+    return result;
 
 }
 
@@ -6309,47 +6309,47 @@ LLUUID LLVOAvatar::remapMotionID(const LLUUID& id)
 BOOL LLVOAvatar::startMotion(const LLUUID& id, F32 time_offset)
 {
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Motion") << "motion requested " << id.asString() << " " << gAnimLibrary.animationName(id) << LL_ENDL;
+    LL_DEBUGS("Motion") << "motion requested " << id.asString() << " " << gAnimLibrary.animationName(id) << LL_ENDL;
 #endif
 #if 1
-	LLUUID remap_id;
-	if (isSelf())
-	{
-		remap_id = AOEngine::getInstance()->override(id, true);
-		if (remap_id.isNull())
-		{
-			remap_id = remapMotionID(id);
-		}
-		else
-		{
-			gAgent.sendAnimationRequest(remap_id, ANIM_REQUEST_START);
-
-			// since we did an override, there is no need to do anything else,
-			// specifically not the startMotion() part at the bottom of this function
-			// See FIRE-29020
-			return true;
-		}
-	}
-	else
-	{
-		remap_id = remapMotionID(id);
-	}
+    LLUUID remap_id;
+    if (isSelf())
+    {
+        remap_id = AOEngine::getInstance()->override(id, true);
+        if (remap_id.isNull())
+        {
+            remap_id = remapMotionID(id);
+        }
+        else
+        {
+            gAgent.sendAnimationRequest(remap_id, ANIM_REQUEST_START);
+
+            // since we did an override, there is no need to do anything else,
+            // specifically not the startMotion() part at the bottom of this function
+            // See FIRE-29020
+            return true;
+        }
+    }
+    else
+    {
+        remap_id = remapMotionID(id);
+    }
 #else
 LLUUID remap_id = remapMotionID(id);
 #endif
 #ifdef SHOW_DEBUG
-	if (remap_id != id)
-	{
-		LL_DEBUGS("Motion") << "motion resultant " << remap_id.asString() << " " << gAnimLibrary.animationName(remap_id) << LL_ENDL;
-	}
+    if (remap_id != id)
+    {
+        LL_DEBUGS("Motion") << "motion resultant " << remap_id.asString() << " " << gAnimLibrary.animationName(remap_id) << LL_ENDL;
+    }
 #endif
 
-	if (isSelf() && remap_id == ANIM_AGENT_AWAY)
-	{
-		gAgent.setAFK();
-	}
+    if (isSelf() && remap_id == ANIM_AGENT_AWAY)
+    {
+        gAgent.setAFK();
+    }
 
-	return LLCharacter::startMotion(remap_id, time_offset);
+    return LLCharacter::startMotion(remap_id, time_offset);
 }
 
 //-----------------------------------------------------------------------------
@@ -6358,48 +6358,48 @@ LLUUID remap_id = remapMotionID(id);
 BOOL LLVOAvatar::stopMotion(const LLUUID& id, BOOL stop_immediate)
 {
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Motion") << "Motion requested " << id.asString() << " " << gAnimLibrary.animationName(id) << LL_ENDL;
+    LL_DEBUGS("Motion") << "Motion requested " << id.asString() << " " << gAnimLibrary.animationName(id) << LL_ENDL;
 #endif
 
 #if 1
-	LLUUID remap_id;
-	if (isSelf())
-	{
-		remap_id = AOEngine::getInstance()->override(id, false);
-		if (remap_id.isNull())
-		{
-			remap_id = remapMotionID(id);
-		}
-		else
-		{
-			gAgent.sendAnimationRequest(remap_id, ANIM_REQUEST_STOP);
-
-			// since we did an override, there is no need to do anything else,
-			// specifically not the stopMotion() part at the bottom of this function
-			// See FIRE-29020
-			return true;
-		}
-	}
-	else
-	{
-		remap_id = remapMotionID(id);
-	}
+    LLUUID remap_id;
+    if (isSelf())
+    {
+        remap_id = AOEngine::getInstance()->override(id, false);
+        if (remap_id.isNull())
+        {
+            remap_id = remapMotionID(id);
+        }
+        else
+        {
+            gAgent.sendAnimationRequest(remap_id, ANIM_REQUEST_STOP);
+
+            // since we did an override, there is no need to do anything else,
+            // specifically not the stopMotion() part at the bottom of this function
+            // See FIRE-29020
+            return true;
+        }
+    }
+    else
+    {
+        remap_id = remapMotionID(id);
+    }
 #else
 LLUUID remap_id = remapMotionID(id);
 #endif
 #ifdef SHOW_DEBUG
-	if (remap_id != id)
-	{
-		LL_DEBUGS("Motion") << "motion resultant " << remap_id.asString() << " " << gAnimLibrary.animationName(remap_id) << LL_ENDL;
-	}
+    if (remap_id != id)
+    {
+        LL_DEBUGS("Motion") << "motion resultant " << remap_id.asString() << " " << gAnimLibrary.animationName(remap_id) << LL_ENDL;
+    }
 #endif
 
-	if (isSelf())
-	{
-		gAgent.onAnimStop(remap_id);
-	}
+    if (isSelf())
+    {
+        gAgent.onAnimStop(remap_id);
+    }
 
-	return LLCharacter::stopMotion(remap_id, stop_immediate);
+    return LLCharacter::stopMotion(remap_id, stop_immediate);
 }
 
 //-----------------------------------------------------------------------------
@@ -6408,7 +6408,7 @@ LLUUID remap_id = remapMotionID(id);
 // virtual
 bool LLVOAvatar::hasMotionFromSource(const LLUUID& source_id)
 {
-	return false;
+    return false;
 }
 
 //-----------------------------------------------------------------------------
@@ -6424,8 +6424,8 @@ void LLVOAvatar::stopMotionFromSource(const LLUUID& source_id)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::addDebugText(const std::string& text)
 {
-	mDebugText.append(1, '\n');
-	mDebugText.append(text);
+    mDebugText.append(1, '\n');
+    mDebugText.append(text);
 }
 
 //-----------------------------------------------------------------------------
@@ -6433,7 +6433,7 @@ void LLVOAvatar::addDebugText(const std::string& text)
 //-----------------------------------------------------------------------------
 const LLUUID& LLVOAvatar::getID() const
 {
-	return mID;
+    return mID;
 }
 
 //-----------------------------------------------------------------------------
@@ -6442,33 +6442,33 @@ const LLUUID& LLVOAvatar::getID() const
 // RN: avatar joints are multi-rooted to include screen-based attachments
 LLJoint *LLVOAvatar::getJoint( const std::string &name )
 {
-	joint_map_t::iterator iter = mJointMap.find(name);
-
-	LLJoint* jointp = NULL;
-
-	if (iter == mJointMap.end() || iter->second == NULL)
-	{   //search for joint and cache found joint in lookup table
-		if (mJointAliasMap.empty())
-		{
-			getJointAliases();
-		}
-		joint_alias_map_t::const_iterator alias_iter = mJointAliasMap.find(name);
-		std::string canonical_name;
-		if (alias_iter != mJointAliasMap.end())
-		{
-			canonical_name = alias_iter->second;
-		}
-		else
-		{
-			canonical_name = name;
-		}
-		jointp = mRoot->findJoint(canonical_name);
-		mJointMap[name] = jointp;
-	}
-	else
-	{   //return cached pointer
-		jointp = iter->second;
-	}
+    joint_map_t::iterator iter = mJointMap.find(name);
+
+    LLJoint* jointp = NULL;
+
+    if (iter == mJointMap.end() || iter->second == NULL)
+    {   //search for joint and cache found joint in lookup table
+        if (mJointAliasMap.empty())
+        {
+            getJointAliases();
+        }
+        joint_alias_map_t::const_iterator alias_iter = mJointAliasMap.find(name);
+        std::string canonical_name;
+        if (alias_iter != mJointAliasMap.end())
+        {
+            canonical_name = alias_iter->second;
+        }
+        else
+        {
+            canonical_name = name;
+        }
+        jointp = mRoot->findJoint(canonical_name);
+        mJointMap[name] = jointp;
+    }
+    else
+    {   //return cached pointer
+        jointp = iter->second;
+    }
 
 #ifdef SHOW_ASSERT
     if (jointp && jointp->getName()!="mScreen" && jointp->getName()!="mRoot")
@@ -6476,7 +6476,7 @@ LLJoint *LLVOAvatar::getJoint( const std::string &name )
         llassert(getJoint(jointp->getJointNum())==jointp);
     }
 #endif
-	return jointp;
+    return jointp;
 }
 
 LLJoint *LLVOAvatar::getJoint( S32 joint_num )
@@ -6504,8 +6504,8 @@ LLJoint *LLVOAvatar::getJoint( S32 joint_num )
             }
         }
     }
-    
-	llassert(!pJoint || pJoint->getJointNum() == joint_num);
+
+    llassert(!pJoint || pJoint->getJointNum() == joint_num);
     return pJoint;
 }
 
@@ -6518,31 +6518,31 @@ LLJoint *LLVOAvatar::getJoint( S32 joint_num )
 // static
 bool LLVOAvatar::getRiggedMeshID(LLViewerObject* pVO, LLUUID& mesh_id)
 {
-	mesh_id.setNull();
-	
-	//If a VO has a skin that we'll reset the joint positions to their default
-	if ( pVO && pVO->mDrawable )
-	{
-		LLVOVolume* pVObj = pVO->mDrawable->getVOVolume();
-		if ( pVObj )
-		{
-			const LLMeshSkinInfo* pSkinData = pVObj->getSkinInfo();
-			if (pSkinData 
-				&& pSkinData->mJointNames.size() > JOINT_COUNT_REQUIRED_FOR_FULLRIG	// full rig
-				&& pSkinData->mAlternateBindMatrix.size() > 0 )
-					{				
-						mesh_id = pSkinData->mMeshID;
-						return true;
-					}
-		}
-	}
-	return false;
+    mesh_id.setNull();
+
+    //If a VO has a skin that we'll reset the joint positions to their default
+    if ( pVO && pVO->mDrawable )
+    {
+        LLVOVolume* pVObj = pVO->mDrawable->getVOVolume();
+        if ( pVObj )
+        {
+            const LLMeshSkinInfo* pSkinData = pVObj->getSkinInfo();
+            if (pSkinData
+                && pSkinData->mJointNames.size() > JOINT_COUNT_REQUIRED_FOR_FULLRIG // full rig
+                && pSkinData->mAlternateBindMatrix.size() > 0 )
+                    {
+                        mesh_id = pSkinData->mMeshID;
+                        return true;
+                    }
+        }
+    }
+    return false;
 }
 
 bool LLVOAvatar::jointIsRiggedTo(const LLJoint *joint) const
 {
     if (joint)
-	{
+    {
         const LLJointRiggingInfoTab& tab = mJointRiggingInfoTab;
         S32 joint_num = joint->getJointNum();
         if (joint_num < tab.size() && tab[joint_num].isRiggedTo())
@@ -6560,25 +6560,25 @@ void LLVOAvatar::clearAttachmentOverrides()
 #endif
 
     for (S32 i=0; i<LL_CHARACTER_MAX_ANIMATED_JOINTS; i++)
-	{
+    {
         LLJoint *pJoint = getJoint(i);
         if (pJoint)
         {
-			pJoint->clearAttachmentPosOverrides();
-			pJoint->clearAttachmentScaleOverrides();
+            pJoint->clearAttachmentPosOverrides();
+            pJoint->clearAttachmentScaleOverrides();
         }
-	}
+    }
 
     if (mPelvisFixups.count()>0)
     {
         mPelvisFixups.clear();
         LLJoint* pJointPelvis = getJoint("mPelvis");
         if (pJointPelvis)
-	{
-			pJointPelvis->setPosition( LLVector3( 0.0f, 0.0f, 0.0f) );
+    {
+            pJointPelvis->setPosition( LLVector3( 0.0f, 0.0f, 0.0f) );
         }
-        postPelvisSetRecalc();	
-	}
+        postPelvisSetRecalc();
+    }
 
     mActiveOverrideMeshes.clear();
     onActiveOverrideMeshesChanged();
@@ -6595,17 +6595,17 @@ void LLVOAvatar::rebuildAttachmentOverrides()
     LL_DEBUGS("AnimatedObjects") << "rebuilding" << LL_ENDL;
     dumpStack("AnimatedObjectsStack");
 #endif
-    
+
     clearAttachmentOverrides();
 
     // Handle the case that we're resetting the skeleton of an animated object.
     if (isControlAvatar())
-	{
+    {
         LLVOVolume *volp = static_cast<LLControlAvatar*>(this)->mRootVolp;
         if (volp)
         {
 #ifdef SHOW_DEBUG
-            LL_DEBUGS("Avatar") << volp->getID() << " adding attachment overrides for root vol, prim count " 
+            LL_DEBUGS("Avatar") << volp->getID() << " adding attachment overrides for root vol, prim count "
                                 << (S32) (1+volp->numChildren()) << LL_ENDL;
 #endif
             addAttachmentOverridesForObject(volp);
@@ -6613,9 +6613,9 @@ void LLVOAvatar::rebuildAttachmentOverrides()
     }
 
     // Attached objects
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment *attachment_pt = attach_pair.second;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment *attachment_pt = attach_pair.second;
         if (attachment_pt)
         {
             for (LLViewerObject* vo : attachment_pt->mAttachedObjects)
@@ -6647,16 +6647,16 @@ void LLVOAvatar::updateAttachmentOverrides()
 #endif
 
     std::set<LLUUID> meshes_seen;
-    
+
     // Handle the case that we're updating the skeleton of an animated object.
     if (isControlAvatar())
     {
-		LLControlAvatar* control_av = static_cast<LLControlAvatar*>(this);
-		LLVOVolume *volp = control_av->mRootVolp;
+        LLControlAvatar* control_av = static_cast<LLControlAvatar*>(this);
+        LLVOVolume *volp = control_av->mRootVolp;
         if (volp)
         {
 #ifdef SHOW_DEBUG
-            LL_DEBUGS("Avatar") << volp->getID() << " adding attachment overrides for root vol, prim count " 
+            LL_DEBUGS("Avatar") << volp->getID() << " adding attachment overrides for root vol, prim count "
                                 << (S32) (1+volp->numChildren()) << LL_ENDL;
 #endif
             addAttachmentOverridesForObject(volp, &meshes_seen);
@@ -6664,9 +6664,9 @@ void LLVOAvatar::updateAttachmentOverrides()
     }
 
     // Attached objects
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		const LLViewerJointAttachment* attachment_pt = attach_pair.second;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        const LLViewerJointAttachment* attachment_pt = attach_pair.second;
         if (attachment_pt)
         {
             for (LLViewerObject* vo : attachment_pt->mAttachedObjects)
@@ -6682,8 +6682,8 @@ void LLVOAvatar::updateAttachmentOverrides()
     }
     // Remove meshes that are no longer present on the skeleton
 
-	// have to work with a copy because removeAttachmentOverrides() will change mActiveOverrideMeshes.
-    std::set<LLUUID> active_override_meshes = mActiveOverrideMeshes; 
+    // have to work with a copy because removeAttachmentOverrides() will change mActiveOverrideMeshes.
+    std::set<LLUUID> active_override_meshes = mActiveOverrideMeshes;
     for (const auto& meshid : active_override_meshes)
     {
         if (meshes_seen.find(meshid) == meshes_seen.end())
@@ -6766,66 +6766,66 @@ void LLVOAvatar::notifyAttachmentMeshLoaded()
 void LLVOAvatar::addAttachmentOverridesForObject(LLViewerObject *vo, std::set<LLUUID>* meshes_seen, bool recursive)
 {
     if (vo->getAvatar() != this && vo->getAvatarAncestor() != this)
-	{
-		LL_WARNS("Avatar") << "called with invalid avatar" << LL_ENDL;
+    {
+        LL_WARNS("Avatar") << "called with invalid avatar" << LL_ENDL;
         return;
-	}
+    }
 
-	if (getOverallAppearance() != AOA_NORMAL)
-	{
-		return;
-	}
+    if (getOverallAppearance() != AOA_NORMAL)
+    {
+        return;
+    }
 
 #ifdef SHOW_DEBUG
     LLScopedContextString str("addAttachmentOverridesForObject " + getFullname());
-    
+
     LL_DEBUGS("AnimatedObjects") << "adding" << LL_ENDL;
     dumpStack("AnimatedObjectsStack");
 #endif
-    
-	// Process all children
+
+    // Process all children
     if (recursive)
     {
-	LLViewerObject::const_child_list_t& children = vo->getChildren();
-	for (LLViewerObject* childp : children)
-	{
+    LLViewerObject::const_child_list_t& children = vo->getChildren();
+    for (LLViewerObject* childp : children)
+    {
             addAttachmentOverridesForObject(childp, meshes_seen, true);
         }
-	}
+    }
 
-	LLVOVolume *vobj = vo->asVolume();
-	bool pelvisGotSet = false;
+    LLVOVolume *vobj = vo->asVolume();
+    bool pelvisGotSet = false;
 
-	if (!vobj)
-	{
-		return;
-	}
+    if (!vobj)
+    {
+        return;
+    }
 
 #ifdef SHOW_DEBUG
-	LLViewerObject* root_object = (LLViewerObject*)vobj->getRoot();
-	LL_DEBUGS("AnimatedObjects") << "trying to add attachment overrides for root object " << root_object->getID() << " prim is " << vobj << LL_ENDL;
+    LLViewerObject* root_object = (LLViewerObject*)vobj->getRoot();
+    LL_DEBUGS("AnimatedObjects") << "trying to add attachment overrides for root object " << root_object->getID() << " prim is " << vobj << LL_ENDL;
 #endif
-	if (!vobj->isMesh() ||
-		(((vobj->getVolume() && !vobj->getVolume()->isMeshAssetLoaded()) || !gMeshRepo.meshRezEnabled())))
-	{
+    if (!vobj->isMesh() ||
+        (((vobj->getVolume() && !vobj->getVolume()->isMeshAssetLoaded()) || !gMeshRepo.meshRezEnabled())))
+    {
 #ifdef SHOW_DEBUG
         LL_DEBUGS("AnimatedObjects") << "failed to add attachment overrides for root object " << root_object->getID() << " mesh asset not loaded" << LL_ENDL;
 #endif
-		return;
-	}
-	const LLMeshSkinInfo*  pSkinData = nullptr;
-	if ((pSkinData = vobj->getSkinInfo()))
-	{
-		const int bindCnt = pSkinData->mAlternateBindMatrix.size();								
+        return;
+    }
+    const LLMeshSkinInfo*  pSkinData = nullptr;
+    if ((pSkinData = vobj->getSkinInfo()))
+    {
+        const int bindCnt = pSkinData->mAlternateBindMatrix.size();
         const int jointCnt = pSkinData->mJointNames.size();
         if ((bindCnt > 0) && (bindCnt != jointCnt))
         {
             LL_WARNS_ONCE() << "invalid mesh, bindCnt " << bindCnt << "!= jointCnt " << jointCnt << ", joint overrides will be ignored." << LL_ENDL;
         }
-		if ((bindCnt > 0) && (bindCnt == jointCnt))
-		{					
-			const F32 pelvisZOffset = pSkinData->mPelvisOffset;
-			const LLUUID& mesh_id = pSkinData->mMeshID;
+        if ((bindCnt > 0) && (bindCnt == jointCnt))
+        {
+            const F32 pelvisZOffset = pSkinData->mPelvisOffset;
+            const LLUUID& mesh_id = pSkinData->mMeshID;
 
             if (meshes_seen)
             {
@@ -6835,39 +6835,39 @@ void LLVOAvatar::addAttachmentOverridesForObject(LLViewerObject *vo, std::set<LL
 #ifdef SHOW_DEBUG
             if (mesh_overrides_loaded)
             {
-                LL_DEBUGS("AnimatedObjects") << "skipping add attachment overrides for " << mesh_id 
+                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 
+                LL_DEBUGS("AnimatedObjects") << "adding attachment overrides for " << mesh_id
                                              << " to root object " << root_object->getID() << LL_ENDL;
             }
 #endif
-			bool fullRig = (jointCnt>=JOINT_COUNT_REQUIRED_FOR_FULLRIG) ? true : false;								
-			if ( fullRig && !mesh_overrides_loaded )
-			{								
-				for ( int i=0; i<jointCnt; ++i )
-				{
-					std::string lookingForJoint = pSkinData->mJointNames[i].c_str();
-					LLJoint* pJoint = getJoint( lookingForJoint );
-					if (pJoint)
-					{   									
-						const LLVector3& jointPos = LLVector3(pSkinData->mAlternateBindMatrix[i].getTranslation());
+            bool fullRig = (jointCnt>=JOINT_COUNT_REQUIRED_FOR_FULLRIG) ? true : false;
+            if ( fullRig && !mesh_overrides_loaded )
+            {
+                for ( int i=0; i<jointCnt; ++i )
+                {
+                    std::string lookingForJoint = pSkinData->mJointNames[i].c_str();
+                    LLJoint* pJoint = getJoint( lookingForJoint );
+                    if (pJoint)
+                    {
+                        const LLVector3& jointPos = LLVector3(pSkinData->mAlternateBindMatrix[i].getTranslation());
                         if (pJoint->aboveJointPosThreshold(jointPos))
                         {
                             bool override_changed;
                             pJoint->addAttachmentPosOverride( jointPos, mesh_id, avString(), override_changed );
-                            
+
                             if (override_changed)
                             {
                                 //If joint is a pelvis then handle old/new pelvis to foot values
                                 if ( lookingForJoint == "mPelvis" )
-                                {	
-                                    pelvisGotSet = true;											
-                                }										
+                                {
+                                    pelvisGotSet = true;
+                                }
                             }
                             if (pSkinData->mLockScaleIfJointPosition)
                             {
@@ -6876,38 +6876,38 @@ void LLVOAvatar::addAttachmentOverridesForObject(LLViewerObject *vo, std::set<LL
                                 pJoint->addAttachmentScaleOverride(pJoint->getDefaultScale(), mesh_id, avString());
                             }
                         }
-					}										
-				}																
-				if (pelvisZOffset != 0.0F)
-				{
+                    }
+                }
+                if (pelvisZOffset != 0.0F)
+                {
                     F32 pelvis_fixup_before;
                     bool has_fixup_before =  hasPelvisFixup(pelvis_fixup_before);
-					addPelvisFixup( pelvisZOffset, mesh_id );
-					F32 pelvis_fixup_after;
+                    addPelvisFixup( pelvisZOffset, mesh_id );
+                    F32 pelvis_fixup_after;
                     hasPelvisFixup(pelvis_fixup_after); // Don't have to check bool here because we just added it...
                     if (!has_fixup_before || (pelvis_fixup_before != pelvis_fixup_after))
                     {
-                        pelvisGotSet = true;											
+                        pelvisGotSet = true;
                     }
-                    
-				}
+
+                }
                 mActiveOverrideMeshes.insert(mesh_id);
                 onActiveOverrideMeshesChanged();
-			}							
-		}
-	}
+            }
+        }
+    }
 #ifdef SHOW_DEBUG
     else
     {
         LL_DEBUGS("AnimatedObjects") << "failed to add attachment overrides for root object " << root_object->getID() << " not mesh or no pSkinData" << LL_ENDL;
     }
 #endif
-					
-	//Rebuild body data if we altered joints/pelvis
-	if ( pelvisGotSet ) 
-	{
-		postPelvisSetRecalc();
-	}		
+
+    //Rebuild body data if we altered joints/pelvis
+    if ( pelvisGotSet )
+    {
+        postPelvisSetRecalc();
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -6920,22 +6920,22 @@ void LLVOAvatar::getAttachmentOverrideNames(std::set<std::string>& pos_names, st
     LLUUID mesh_id;
 
     // Bones
-	for (const LLJoint* pJoint : mSkeleton)
-	{
-		if (pJoint && pJoint->hasAttachmentPosOverride(pos,mesh_id))
-		{
+    for (const LLJoint* pJoint : mSkeleton)
+    {
+        if (pJoint && pJoint->hasAttachmentPosOverride(pos,mesh_id))
+        {
             pos_names.insert(pJoint->getName());
-		}
-		if (pJoint && pJoint->hasAttachmentScaleOverride(scale,mesh_id))
-		{
+        }
+        if (pJoint && pJoint->hasAttachmentScaleOverride(scale,mesh_id))
+        {
             scale_names.insert(pJoint->getName());
-		}
-	}
+        }
+    }
 
     // Attachment points
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		const LLViewerJointAttachment* attachment_pt = attach_pair.second;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        const LLViewerJointAttachment* attachment_pt = attach_pair.second;
         if (attachment_pt && attachment_pt->hasAttachmentPosOverride(pos,mesh_id))
         {
             pos_names.insert(attachment_pt->getName());
@@ -6983,26 +6983,26 @@ void LLVOAvatar::showAttachmentOverrides(bool verbose) const
     S32 count = 0;
 
     // Bones
-	for (avatar_joint_list_t::const_iterator iter = mSkeleton.begin();
+    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))
-		{
-			pJoint->showAttachmentPosOverrides(getFullname());
+    {
+        const LLJoint* pJoint = (*iter);
+        if (pJoint && pJoint->hasAttachmentPosOverride(pos,mesh_id))
+        {
+            pJoint->showAttachmentPosOverrides(getFullname());
             count++;
-		}
-		if (pJoint && pJoint->hasAttachmentScaleOverride(scale,mesh_id))
-		{
-			pJoint->showAttachmentScaleOverrides(getFullname());
+        }
+        if (pJoint && pJoint->hasAttachmentScaleOverride(scale,mesh_id))
+        {
+            pJoint->showAttachmentScaleOverrides(getFullname());
             count++;
         }
-	}
+    }
 
     // Attachment points
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		const LLViewerJointAttachment* attachment_pt = attach_pair.second;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        const LLViewerJointAttachment* attachment_pt = attach_pair.second;
         if (attachment_pt && attachment_pt->hasAttachmentPosOverride(pos,mesh_id))
         {
             attachment_pt->showAttachmentPosOverrides(getFullname());
@@ -7023,51 +7023,51 @@ void LLVOAvatar::showAttachmentOverrides(bool verbose) const
 void LLVOAvatar::removeAttachmentOverridesForObject(LLViewerObject *vo)
 {
     if (vo->getAvatar() != this && vo->getAvatarAncestor() != this)
-	{
-		LL_WARNS("Avatar") << "called with invalid avatar" << LL_ENDL;
+    {
+        LL_WARNS("Avatar") << "called with invalid avatar" << LL_ENDL;
         return;
-	}
-		
-	// Process all children
-	LLViewerObject::const_child_list_t& children = vo->getChildren();
-	for (LLViewerObject* childp : children)
-	{
-		removeAttachmentOverridesForObject(childp);
-	}
+    }
+
+    // Process all children
+    LLViewerObject::const_child_list_t& children = vo->getChildren();
+    for (LLViewerObject* childp : children)
+    {
+        removeAttachmentOverridesForObject(childp);
+    }
 
-	// Process self.
-	LLUUID mesh_id;
-	if (getRiggedMeshID(vo,mesh_id))
-	{
-		removeAttachmentOverridesForObject(mesh_id);
-	}
+    // Process self.
+    LLUUID mesh_id;
+    if (getRiggedMeshID(vo,mesh_id))
+    {
+        removeAttachmentOverridesForObject(mesh_id);
+    }
 }
 
 //-----------------------------------------------------------------------------
 // removeAttachmentOverridesForObject
 //-----------------------------------------------------------------------------
 void LLVOAvatar::removeAttachmentOverridesForObject(const LLUUID& mesh_id)
-{	
-	LLJoint* pJointPelvis = getJoint("mPelvis");
+{
+    LLJoint* pJointPelvis = getJoint("mPelvis");
     const std::string av_string = avString();
     for (S32 joint_num = 0; joint_num < LL_CHARACTER_MAX_ANIMATED_JOINTS; joint_num++)
-	{
+    {
         LLJoint *pJoint = getJoint(joint_num);
-		if ( pJoint )
-		{			
+        if ( pJoint )
+        {
             bool dummy; // unused
-			pJoint->removeAttachmentPosOverride(mesh_id, av_string, dummy);
-			pJoint->removeAttachmentScaleOverride(mesh_id, av_string);
-		}		
-		if ( pJoint && pJoint == pJointPelvis)
-		{
-			removePelvisFixup( mesh_id );
-			// SL-315
-			pJoint->setPosition( LLVector3( 0.0f, 0.0f, 0.0f) );
-		}		
-	}	
-		
-	postPelvisSetRecalc();	
+            pJoint->removeAttachmentPosOverride(mesh_id, av_string, dummy);
+            pJoint->removeAttachmentScaleOverride(mesh_id, av_string);
+        }
+        if ( pJoint && pJoint == pJointPelvis)
+        {
+            removePelvisFixup( mesh_id );
+            // SL-315
+            pJoint->setPosition( LLVector3( 0.0f, 0.0f, 0.0f) );
+        }
+    }
+
+    postPelvisSetRecalc();
 
     mActiveOverrideMeshes.erase(mesh_id);
     onActiveOverrideMeshesChanged();
@@ -7077,14 +7077,14 @@ void LLVOAvatar::removeAttachmentOverridesForObject(const LLUUID& mesh_id)
 //-----------------------------------------------------------------------------
 LLVector3 LLVOAvatar::getCharacterPosition()
 {
-	if (mDrawable.notNull())
-	{
-		return mDrawable->getPositionAgent();
-	}
-	else
-	{
-		return getPositionAgent();
-	}
+    if (mDrawable.notNull())
+    {
+        return mDrawable->getPositionAgent();
+    }
+    else
+    {
+        return getPositionAgent();
+    }
 }
 
 
@@ -7093,7 +7093,7 @@ LLVector3 LLVOAvatar::getCharacterPosition()
 //-----------------------------------------------------------------------------
 LLQuaternion LLVOAvatar::getCharacterRotation()
 {
-	return getRotation();
+    return getRotation();
 }
 
 
@@ -7102,7 +7102,7 @@ LLQuaternion LLVOAvatar::getCharacterRotation()
 //-----------------------------------------------------------------------------
 LLVector3 LLVOAvatar::getCharacterVelocity()
 {
-	return getVelocity() - mStepObjectVelocity;
+    return getVelocity() - mStepObjectVelocity;
 }
 
 
@@ -7111,7 +7111,7 @@ LLVector3 LLVOAvatar::getCharacterVelocity()
 //-----------------------------------------------------------------------------
 LLVector3 LLVOAvatar::getCharacterAngularVelocity()
 {
-	return getAngularVelocity();
+    return getAngularVelocity();
 }
 
 //-----------------------------------------------------------------------------
@@ -7119,22 +7119,22 @@ LLVector3 LLVOAvatar::getCharacterAngularVelocity()
 //-----------------------------------------------------------------------------
 void LLVOAvatar::getGround(const LLVector3 &in_pos_agent, LLVector3 &out_pos_agent, LLVector3 &outNorm)
 {
-	LLVector3d z_vec(0.0f, 0.0f, 1.0f);
-	LLVector3d p0_global, p1_global;
+    LLVector3d z_vec(0.0f, 0.0f, 1.0f);
+    LLVector3d p0_global, p1_global;
+
+    if (isUIAvatar())
+    {
+        outNorm.setVec(z_vec);
+        out_pos_agent = in_pos_agent;
+        return;
+    }
 
-	if (isUIAvatar())
-	{
-		outNorm.setVec(z_vec);
-		out_pos_agent = in_pos_agent;
-		return;
-	}
-	
-	p0_global = gAgent.getPosGlobalFromAgent(in_pos_agent) + z_vec;
-	p1_global = gAgent.getPosGlobalFromAgent(in_pos_agent) - z_vec;
-	LLViewerObject *obj;
-	LLVector3d out_pos_global;
-	LLWorld::getInstance()->resolveStepHeightGlobal(this, p0_global, p1_global, out_pos_global, outNorm, &obj);
-	out_pos_agent = gAgent.getPosAgentFromGlobal(out_pos_global);
+    p0_global = gAgent.getPosGlobalFromAgent(in_pos_agent) + z_vec;
+    p1_global = gAgent.getPosGlobalFromAgent(in_pos_agent) - z_vec;
+    LLViewerObject *obj;
+    LLVector3d out_pos_global;
+    LLWorld::getInstance()->resolveStepHeightGlobal(this, p0_global, p1_global, out_pos_global, outNorm, &obj);
+    out_pos_agent = gAgent.getPosAgentFromGlobal(out_pos_global);
 }
 
 //-----------------------------------------------------------------------------
@@ -7142,7 +7142,7 @@ void LLVOAvatar::getGround(const LLVector3 &in_pos_agent, LLVector3 &out_pos_age
 //-----------------------------------------------------------------------------
 F32 LLVOAvatar::getTimeDilation()
 {
-	return mRegionp ? mRegionp->getTimeDilation() : 1.f;
+    return mRegionp ? mRegionp->getTimeDilation() : 1.f;
 }
 
 
@@ -7151,11 +7151,11 @@ F32 LLVOAvatar::getTimeDilation()
 //-----------------------------------------------------------------------------
 F32 LLVOAvatar::getPixelArea() const
 {
-	if (isUIAvatar())
-	{
-		return 100000.f;
-	}
-	return mPixelArea;
+    if (isUIAvatar())
+    {
+        return 100000.f;
+    }
+    return mPixelArea;
 }
 
 
@@ -7163,17 +7163,17 @@ F32 LLVOAvatar::getPixelArea() const
 //-----------------------------------------------------------------------------
 // LLVOAvatar::getPosGlobalFromAgent()
 //-----------------------------------------------------------------------------
-LLVector3d	LLVOAvatar::getPosGlobalFromAgent(const LLVector3 &position)
+LLVector3d  LLVOAvatar::getPosGlobalFromAgent(const LLVector3 &position)
 {
-	return gAgent.getPosGlobalFromAgent(position);
+    return gAgent.getPosGlobalFromAgent(position);
 }
 
 //-----------------------------------------------------------------------------
 // getPosAgentFromGlobal()
 //-----------------------------------------------------------------------------
-LLVector3	LLVOAvatar::getPosAgentFromGlobal(const LLVector3d &position)
+LLVector3   LLVOAvatar::getPosAgentFromGlobal(const LLVector3d &position)
 {
-	return gAgent.getPosAgentFromGlobal(position);
+    return gAgent.getPosAgentFromGlobal(position);
 }
 
 
@@ -7183,7 +7183,7 @@ LLVector3	LLVOAvatar::getPosAgentFromGlobal(const LLVector3d &position)
 // virtual
 void LLVOAvatar::requestStopMotion( LLMotion* motion )
 {
-	// Only agent avatars should handle the stop motion notifications.
+    // Only agent avatars should handle the stop motion notifications.
 }
 
 //-----------------------------------------------------------------------------
@@ -7192,19 +7192,19 @@ void LLVOAvatar::requestStopMotion( LLMotion* motion )
 //virtual
 BOOL LLVOAvatar::loadSkeletonNode ()
 {
-	if (!LLAvatarAppearance::loadSkeletonNode())
-	{
-		return FALSE;
-	}
-	
+    if (!LLAvatarAppearance::loadSkeletonNode())
+    {
+        return FALSE;
+    }
+
     bool ignore_hud_joints = false;
     initAttachmentPoints(ignore_hud_joints);
 
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
-// initAttachmentPoints(): creates attachment points if needed, sets state based on avatar_lad.xml. 
+// initAttachmentPoints(): creates attachment points if needed, sets state based on avatar_lad.xml.
 //-----------------------------------------------------------------------------
 void LLVOAvatar::initAttachmentPoints(bool ignore_hud_joints)
 {
@@ -7212,7 +7212,7 @@ void LLVOAvatar::initAttachmentPoints(bool ignore_hud_joints)
     {
         if (info->mIsHUDAttachment && (!isSelf() || ignore_hud_joints))
         {
-		    //don't process hud joint for other avatars.
+            //don't process hud joint for other avatars.
             continue;
         }
 
@@ -7249,7 +7249,7 @@ void LLVOAvatar::initAttachmentPoints(bool ignore_hud_joints)
             attachment->setOriginalPosition(info->mPosition);
             attachment->setDefaultPosition(info->mPosition);
         }
-			
+
         if (info->mHasRotation)
         {
             LLQuaternion rotation;
@@ -7281,7 +7281,7 @@ void LLVOAvatar::initAttachmentPoints(bool ignore_hud_joints)
         if (newly_created)
         {
             mAttachmentPoints[attachmentID] = attachment;
-            
+
             // now add attachment joint
             parent_joint->addChild(attachment);
         }
@@ -7293,51 +7293,51 @@ void LLVOAvatar::initAttachmentPoints(bool ignore_hud_joints)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::updateVisualParams()
 {
-	ESex avatar_sex = (getVisualParamWeight("male") > 0.5f) ? SEX_MALE : SEX_FEMALE;
-	if (getSex() != avatar_sex)
-	{
-		if (mIsSitting && findMotion(avatar_sex == SEX_MALE ? ANIM_AGENT_SIT_FEMALE : ANIM_AGENT_SIT) != NULL)
-		{
-			// In some cases of gender change server changes sit motion with motion message,
-			// but in case of some avatars (legacy?) there is no update from server side,
-			// likely because server doesn't know about difference between motions
-			// (female and male sit ids are same server side, so it is likely unaware that it
-			// need to send update)
-			// Make sure motion is up to date
-			stopMotion(ANIM_AGENT_SIT);
-			setSex(avatar_sex);
-			startMotion(ANIM_AGENT_SIT);
-		}
-		else
-		{
-			setSex(avatar_sex);
-		}
-	}
-
-	LLCharacter::updateVisualParams();
-
-	if (mLastSkeletonSerialNum != mSkeletonSerialNum)
-	{
-		//BD - Poser
-		//     Don't refresh our root position while we pose otherwise moving any joint that moves
-		//     mFootLeft will trigger mRoot repositioning.
-		if (!isSelf() || !gAgent.getPosing())
-		{
-			computeBodySize();
-		}
-		mLastSkeletonSerialNum = mSkeletonSerialNum;
-		mRoot->updateWorldMatrixChildren();
-	}
-
-	dirtyMesh();
-	updateHeadOffset();
+    ESex avatar_sex = (getVisualParamWeight("male") > 0.5f) ? SEX_MALE : SEX_FEMALE;
+    if (getSex() != avatar_sex)
+    {
+        if (mIsSitting && findMotion(avatar_sex == SEX_MALE ? ANIM_AGENT_SIT_FEMALE : ANIM_AGENT_SIT) != NULL)
+        {
+            // In some cases of gender change server changes sit motion with motion message,
+            // but in case of some avatars (legacy?) there is no update from server side,
+            // likely because server doesn't know about difference between motions
+            // (female and male sit ids are same server side, so it is likely unaware that it
+            // need to send update)
+            // Make sure motion is up to date
+            stopMotion(ANIM_AGENT_SIT);
+            setSex(avatar_sex);
+            startMotion(ANIM_AGENT_SIT);
+        }
+        else
+        {
+            setSex(avatar_sex);
+        }
+    }
+
+    LLCharacter::updateVisualParams();
+
+    if (mLastSkeletonSerialNum != mSkeletonSerialNum)
+    {
+        //BD - Poser
+        //     Don't refresh our root position while we pose otherwise moving any joint that moves
+        //     mFootLeft will trigger mRoot repositioning.
+        if (!isSelf() || !gAgent.getPosing())
+        {
+            computeBodySize();
+        }
+        mLastSkeletonSerialNum = mSkeletonSerialNum;
+        mRoot->updateWorldMatrixChildren();
+    }
+
+    dirtyMesh();
+    updateHeadOffset();
 }
 //-----------------------------------------------------------------------------
 // isActive()
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatar::isActive() const
 {
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -7345,39 +7345,39 @@ BOOL LLVOAvatar::isActive() const
 //-----------------------------------------------------------------------------
 void LLVOAvatar::setPixelAreaAndAngle(LLAgent &agent)
 {
-	if (mDrawable.isNull())
-	{
-		return;
-	}
+    if (mDrawable.isNull())
+    {
+        return;
+    }
 
-	const LLVector4a* ext = mDrawable->getSpatialExtents();
-	LLVector4a center;
-	center.setAdd(ext[1], ext[0]);
-	center.mul(0.5f);
-	LLVector4a size;
-	size.setSub(ext[1], ext[0]);
-	size.mul(0.5f);
+    const LLVector4a* ext = mDrawable->getSpatialExtents();
+    LLVector4a center;
+    center.setAdd(ext[1], ext[0]);
+    center.mul(0.5f);
+    LLVector4a size;
+    size.setSub(ext[1], ext[0]);
+    size.mul(0.5f);
 
-	mImpostorPixelArea = LLPipeline::calcPixelArea(center, size, *LLViewerCamera::getInstance());
+    mImpostorPixelArea = LLPipeline::calcPixelArea(center, size, *LLViewerCamera::getInstance());
     mPixelArea = mImpostorPixelArea;
 
-	F32 range = mDrawable->mDistanceWRTCamera;
+    F32 range = mDrawable->mDistanceWRTCamera;
 
-	if (range < 0.001f)		// range == zero
-	{
-		mAppAngle = 180.f;
-	}
-	else
-	{
-		F32 radius = size.getLength3().getF32();
-		mAppAngle = (F32) atan2( radius, range) * RAD_TO_DEG;
-	}
+    if (range < 0.001f)     // range == zero
+    {
+        mAppAngle = 180.f;
+    }
+    else
+    {
+        F32 radius = size.getLength3().getF32();
+        mAppAngle = (F32) atan2( radius, range) * RAD_TO_DEG;
+    }
 
-	// We always want to look good to ourselves
-	if( isSelf() )
-	{
-		mPixelArea = llmax( mPixelArea, F32(getTexImageSize() / 16) );
-	}
+    // We always want to look good to ourselves
+    if( isSelf() )
+    {
+        mPixelArea = llmax( mPixelArea, F32(getTexImageSize() / 16) );
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -7385,48 +7385,48 @@ void LLVOAvatar::setPixelAreaAndAngle(LLAgent &agent)
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatar::updateJointLODs()
 {
-	const F32 MAX_PIXEL_AREA = 100000000.f;
-	F32 lod_factor = (sLODFactor * AVATAR_LOD_TWEAK_RANGE + (1.f - AVATAR_LOD_TWEAK_RANGE));
-	F32 avatar_num_min_factor = clamp_rescale(sLODFactor, 0.f, 1.f, 0.25f, 0.6f);
-	F32 avatar_num_factor = clamp_rescale((F32)sNumVisibleAvatars, 8, 25, 1.f, avatar_num_min_factor);
-	F32 area_scale = 0.16f;
-
-		if (isSelf())
-		{
-			if(gAgentCamera.cameraCustomizeAvatar() || gAgentCamera.cameraMouselook())
-			{
-				mAdjustedPixelArea = MAX_PIXEL_AREA;
-			}
-			else
-			{
-				mAdjustedPixelArea = mPixelArea*area_scale;
-			}
-		}
-		else if (mIsDummy)
-		{
-			mAdjustedPixelArea = MAX_PIXEL_AREA;
-		}
-		else
-		{
-			// reported avatar pixel area is dependent on avatar render load, based on number of visible avatars
-			mAdjustedPixelArea = (F32)mPixelArea * area_scale * lod_factor * lod_factor * avatar_num_factor * avatar_num_factor;
-		}
-
-		// now select meshes to render based on adjusted pixel area
-		LLViewerJoint* root = dynamic_cast<LLViewerJoint*>(mRoot);
-		BOOL res = FALSE;
-		if (root)
-		{
-			res = root->updateLOD(mAdjustedPixelArea, TRUE);
-		}
- 		if (res)
-		{
-			sNumLODChangesThisFrame++;
-			dirtyMesh(2);
-			return TRUE;
-		}
-
-	return FALSE;
+    const F32 MAX_PIXEL_AREA = 100000000.f;
+    F32 lod_factor = (sLODFactor * AVATAR_LOD_TWEAK_RANGE + (1.f - AVATAR_LOD_TWEAK_RANGE));
+    F32 avatar_num_min_factor = clamp_rescale(sLODFactor, 0.f, 1.f, 0.25f, 0.6f);
+    F32 avatar_num_factor = clamp_rescale((F32)sNumVisibleAvatars, 8, 25, 1.f, avatar_num_min_factor);
+    F32 area_scale = 0.16f;
+
+        if (isSelf())
+        {
+            if(gAgentCamera.cameraCustomizeAvatar() || gAgentCamera.cameraMouselook())
+            {
+                mAdjustedPixelArea = MAX_PIXEL_AREA;
+            }
+            else
+            {
+                mAdjustedPixelArea = mPixelArea*area_scale;
+            }
+        }
+        else if (mIsDummy)
+        {
+            mAdjustedPixelArea = MAX_PIXEL_AREA;
+        }
+        else
+        {
+            // reported avatar pixel area is dependent on avatar render load, based on number of visible avatars
+            mAdjustedPixelArea = (F32)mPixelArea * area_scale * lod_factor * lod_factor * avatar_num_factor * avatar_num_factor;
+        }
+
+        // now select meshes to render based on adjusted pixel area
+        LLViewerJoint* root = dynamic_cast<LLViewerJoint*>(mRoot);
+        BOOL res = FALSE;
+        if (root)
+        {
+            res = root->updateLOD(mAdjustedPixelArea, TRUE);
+        }
+        if (res)
+        {
+            sNumLODChangesThisFrame++;
+            dirtyMesh(2);
+            return TRUE;
+        }
+
+    return FALSE;
 }
 
 //-----------------------------------------------------------------------------
@@ -7434,32 +7434,32 @@ BOOL LLVOAvatar::updateJointLODs()
 //-----------------------------------------------------------------------------
 LLDrawable *LLVOAvatar::createDrawable(LLPipeline *pipeline)
 {
-	pipeline->allocDrawable(this);
-	mDrawable->setLit(FALSE);
+    pipeline->allocDrawable(this);
+    mDrawable->setLit(FALSE);
 
-	LLDrawPoolAvatar *poolp = (LLDrawPoolAvatar*)gPipeline.getPool(mIsControlAvatar ? LLDrawPool::POOL_CONTROL_AV : LLDrawPool::POOL_AVATAR);
+    LLDrawPoolAvatar *poolp = (LLDrawPoolAvatar*)gPipeline.getPool(mIsControlAvatar ? LLDrawPool::POOL_CONTROL_AV : LLDrawPool::POOL_AVATAR);
 
-	// Only a single face (one per avatar)
-	//this face will be splitted into several if its vertex buffer is too long.
-	mDrawable->setState(LLDrawable::ACTIVE);
-	mDrawable->addFace(poolp, NULL);
-	mDrawable->setRenderType(mIsControlAvatar ? LLPipeline::RENDER_TYPE_CONTROL_AV : LLPipeline::RENDER_TYPE_AVATAR);
-	
-	mNumInitFaces = mDrawable->getNumFaces() ;
+    // Only a single face (one per avatar)
+    //this face will be splitted into several if its vertex buffer is too long.
+    mDrawable->setState(LLDrawable::ACTIVE);
+    mDrawable->addFace(poolp, NULL);
+    mDrawable->setRenderType(mIsControlAvatar ? LLPipeline::RENDER_TYPE_CONTROL_AV : LLPipeline::RENDER_TYPE_AVATAR);
 
-	dirtyMesh(2);
-	return mDrawable;
+    mNumInitFaces = mDrawable->getNumFaces() ;
+
+    dirtyMesh(2);
+    return mDrawable;
 }
 
 
 void LLVOAvatar::updateGL()
 {
-	if (mMeshTexturesDirty)
-	{
-		LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
-		updateMeshTextures();
-		mMeshTexturesDirty = FALSE;
-	}
+    if (mMeshTexturesDirty)
+    {
+        LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
+        updateMeshTextures();
+        mMeshTexturesDirty = FALSE;
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -7468,22 +7468,22 @@ void LLVOAvatar::updateGL()
 BOOL LLVOAvatar::updateGeometry(LLDrawable *drawable)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
-	if (!(gPipeline.hasRenderType(mIsControlAvatar ? LLPipeline::RENDER_TYPE_CONTROL_AV : LLPipeline::RENDER_TYPE_AVATAR)))
-	{
-		return TRUE;
-	}
-	
-	if (!mMeshValid)
-	{
-		return TRUE;
-	}
+    if (!(gPipeline.hasRenderType(mIsControlAvatar ? LLPipeline::RENDER_TYPE_CONTROL_AV : LLPipeline::RENDER_TYPE_AVATAR)))
+    {
+        return TRUE;
+    }
+
+    if (!mMeshValid)
+    {
+        return TRUE;
+    }
 
-	if (!drawable)
-	{
-		LL_ERRS() << "LLVOAvatar::updateGeometry() called with NULL drawable" << LL_ENDL;
-	}
+    if (!drawable)
+    {
+        LL_ERRS() << "LLVOAvatar::updateGeometry() called with NULL drawable" << LL_ENDL;
+    }
 
-	return TRUE;
+    return TRUE;
 }
 
 //-----------------------------------------------------------------------------
@@ -7491,9 +7491,9 @@ BOOL LLVOAvatar::updateGeometry(LLDrawable *drawable)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::updateSexDependentLayerSets()
 {
-	invalidateComposite( mBakedTextureDatas[BAKED_HEAD].mTexLayerSet);
-	invalidateComposite( mBakedTextureDatas[BAKED_UPPER].mTexLayerSet);
-	invalidateComposite( mBakedTextureDatas[BAKED_LOWER].mTexLayerSet);
+    invalidateComposite( mBakedTextureDatas[BAKED_HEAD].mTexLayerSet);
+    invalidateComposite( mBakedTextureDatas[BAKED_UPPER].mTexLayerSet);
+    invalidateComposite( mBakedTextureDatas[BAKED_LOWER].mTexLayerSet);
 }
 
 //-----------------------------------------------------------------------------
@@ -7501,19 +7501,19 @@ void LLVOAvatar::updateSexDependentLayerSets()
 //-----------------------------------------------------------------------------
 void LLVOAvatar::dirtyMesh()
 {
-	dirtyMesh(1);
+    dirtyMesh(1);
 }
 void LLVOAvatar::dirtyMesh(S32 priority)
 {
-	mDirtyMesh = llmax(mDirtyMesh, priority);
+    mDirtyMesh = llmax(mDirtyMesh, priority);
 }
 
 //-----------------------------------------------------------------------------
 // getViewerJoint()
 //-----------------------------------------------------------------------------
-LLViewerJoint*	LLVOAvatar::getViewerJoint(S32 idx)
+LLViewerJoint*  LLVOAvatar::getViewerJoint(S32 idx)
 {
-	return dynamic_cast<LLViewerJoint*>(mMeshLOD[idx]);
+    return dynamic_cast<LLViewerJoint*>(mMeshLOD[idx]);
 }
 
 //-----------------------------------------------------------------------------
@@ -7529,111 +7529,111 @@ void LLVOAvatar::hideHair()
 //-----------------------------------------------------------------------------
 void LLVOAvatar::hideSkirt()
 {
-	mMeshLOD[MESH_ID_SKIRT]->setVisible(FALSE, TRUE);
+    mMeshLOD[MESH_ID_SKIRT]->setVisible(FALSE, TRUE);
 }
 
 BOOL LLVOAvatar::setParent(LLViewerObject* parent)
 {
-	BOOL ret ;
-	if (parent == NULL)
-	{
-		getOffObject();
-		ret = LLViewerObject::setParent(parent);
-		if (isSelf())
-		{
-			gAgentCamera.resetCamera();
-		}
-	}
-	else
-	{
-		ret = LLViewerObject::setParent(parent);
-		if(ret)
-		{
-			sitOnObject(parent);
-		}
-	}
-	return ret ;
+    BOOL ret ;
+    if (parent == NULL)
+    {
+        getOffObject();
+        ret = LLViewerObject::setParent(parent);
+        if (isSelf())
+        {
+            gAgentCamera.resetCamera();
+        }
+    }
+    else
+    {
+        ret = LLViewerObject::setParent(parent);
+        if(ret)
+        {
+            sitOnObject(parent);
+        }
+    }
+    return ret ;
 }
 
 void LLVOAvatar::addChild(LLViewerObject *childp)
 {
-	childp->extractAttachmentItemID(); // find the inventory item this object is associated with.
-	if (isSelf())
-	{
-	    const LLUUID& item_id = childp->getAttachmentItemID();
-		LLViewerInventoryItem *item = gInventory.getItem(item_id);
-		LL_DEBUGS("Avatar") << "ATT attachment child added " << (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
-
-	}
-
-	LLViewerObject::addChild(childp);
-	if (childp->mDrawable)
-	{
-		if (!attachObject(childp))
-		{
-			LL_WARNS() << "ATT addChild() failed for " 
-					<< childp->getID()
-					<< " item " << childp->getAttachmentItemID()
-					<< LL_ENDL;
-			// MAINT-3312 backout
-			// mPendingAttachment.push_back(childp);
-		}
-	}
-	else
-	{
-		mPendingAttachment.push_back(childp);
-	}
+    childp->extractAttachmentItemID(); // find the inventory item this object is associated with.
+    if (isSelf())
+    {
+        const LLUUID& item_id = childp->getAttachmentItemID();
+        LLViewerInventoryItem *item = gInventory.getItem(item_id);
+        LL_DEBUGS("Avatar") << "ATT attachment child added " << (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
+
+    }
+
+    LLViewerObject::addChild(childp);
+    if (childp->mDrawable)
+    {
+        if (!attachObject(childp))
+        {
+            LL_WARNS() << "ATT addChild() failed for "
+                    << childp->getID()
+                    << " item " << childp->getAttachmentItemID()
+                    << LL_ENDL;
+            // MAINT-3312 backout
+            // mPendingAttachment.push_back(childp);
+        }
+    }
+    else
+    {
+        mPendingAttachment.push_back(childp);
+    }
 }
 
 void LLVOAvatar::removeChild(LLViewerObject *childp)
 {
-	LLViewerObject::removeChild(childp);
-	if (!detachObject(childp))
-	{
-		LL_WARNS() << "Calling detach on non-attached object " << LL_ENDL;
-	}
+    LLViewerObject::removeChild(childp);
+    if (!detachObject(childp))
+    {
+        LL_WARNS() << "Calling detach on non-attached object " << LL_ENDL;
+    }
 }
 
 LLViewerJointAttachment* LLVOAvatar::getTargetAttachmentPoint(LLViewerObject* viewer_object)
 {
-	S32 attachmentID = ATTACHMENT_ID_FROM_STATE(viewer_object->getAttachmentState());
-
-	// This should never happen unless the server didn't process the attachment point
-	// correctly, but putting this check in here to be safe.
-	if (attachmentID & ATTACHMENT_ADD)
-	{
-		LL_WARNS() << "Got an attachment with ATTACHMENT_ADD mask, removing ( attach pt:" << attachmentID << " )" << LL_ENDL;
-		attachmentID &= ~ATTACHMENT_ADD;
-	}
-	
-	LLViewerJointAttachment* attachment = get_if_there(mAttachmentPoints, attachmentID, (LLViewerJointAttachment*)NULL);
-
-	if (!attachment)
-	{
-		LL_WARNS() << "Object attachment point invalid: " << attachmentID 
-			<< " trying to use 1 (chest)"
-			<< LL_ENDL;
-
-		attachment = get_if_there(mAttachmentPoints, 1, (LLViewerJointAttachment*)NULL); // Arbitrary using 1 (chest)
-		if (attachment)
-		{
-			LL_WARNS() << "Object attachment point invalid: " << attachmentID 
-				<< " on object " << viewer_object->getID()
-				<< " attachment item " << viewer_object->getAttachmentItemID()
-				<< " falling back to 1 (chest)"
-				<< LL_ENDL;
-		}
-		else
-		{
-			LL_WARNS() << "Object attachment point invalid: " << attachmentID 
-				<< " on object " << viewer_object->getID()
-				<< " attachment item " << viewer_object->getAttachmentItemID()
-				<< "Unable to use fallback attachment point 1 (chest)"
-				<< LL_ENDL;
-		}
-	}
-
-	return attachment;
+    S32 attachmentID = ATTACHMENT_ID_FROM_STATE(viewer_object->getAttachmentState());
+
+    // This should never happen unless the server didn't process the attachment point
+    // correctly, but putting this check in here to be safe.
+    if (attachmentID & ATTACHMENT_ADD)
+    {
+        LL_WARNS() << "Got an attachment with ATTACHMENT_ADD mask, removing ( attach pt:" << attachmentID << " )" << LL_ENDL;
+        attachmentID &= ~ATTACHMENT_ADD;
+    }
+
+    LLViewerJointAttachment* attachment = get_if_there(mAttachmentPoints, attachmentID, (LLViewerJointAttachment*)NULL);
+
+    if (!attachment)
+    {
+        LL_WARNS() << "Object attachment point invalid: " << attachmentID
+            << " trying to use 1 (chest)"
+            << LL_ENDL;
+
+        attachment = get_if_there(mAttachmentPoints, 1, (LLViewerJointAttachment*)NULL); // Arbitrary using 1 (chest)
+        if (attachment)
+        {
+            LL_WARNS() << "Object attachment point invalid: " << attachmentID
+                << " on object " << viewer_object->getID()
+                << " attachment item " << viewer_object->getAttachmentItemID()
+                << " falling back to 1 (chest)"
+                << LL_ENDL;
+        }
+        else
+        {
+            LL_WARNS() << "Object attachment point invalid: " << attachmentID
+                << " on object " << viewer_object->getID()
+                << " attachment item " << viewer_object->getAttachmentItemID()
+                << "Unable to use fallback attachment point 1 (chest)"
+                << LL_ENDL;
+        }
+    }
+
+    return attachment;
 }
 
 //-----------------------------------------------------------------------------
@@ -7641,52 +7641,52 @@ LLViewerJointAttachment* LLVOAvatar::getTargetAttachmentPoint(LLViewerObject* vi
 //-----------------------------------------------------------------------------
 const LLViewerJointAttachment *LLVOAvatar::attachObject(LLViewerObject *viewer_object)
 {
-	if (isSelf())
-	{
-		const LLUUID& item_id = viewer_object->getAttachmentItemID();
-		LLViewerInventoryItem *item = gInventory.getItem(item_id);
-		LL_DEBUGS("Avatar") << "ATT attaching object "
-							<< (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;	
-	}
-	LLViewerJointAttachment* attachment = getTargetAttachmentPoint(viewer_object);
-
-	if (!attachment || !attachment->addObject(viewer_object))
-	{
-		const LLUUID& item_id = viewer_object->getAttachmentItemID();
-		LLViewerInventoryItem *item = gInventory.getItem(item_id);
-		LL_WARNS("Avatar") << "ATT attach failed "
-						   << (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;	
-		return 0;
-	}
-	
+    if (isSelf())
+    {
+        const LLUUID& item_id = viewer_object->getAttachmentItemID();
+        LLViewerInventoryItem *item = gInventory.getItem(item_id);
+        LL_DEBUGS("Avatar") << "ATT attaching object "
+                            << (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
+    }
+    LLViewerJointAttachment* attachment = getTargetAttachmentPoint(viewer_object);
+
+    if (!attachment || !attachment->addObject(viewer_object))
+    {
+        const LLUUID& item_id = viewer_object->getAttachmentItemID();
+        LLViewerInventoryItem *item = gInventory.getItem(item_id);
+        LL_WARNS("Avatar") << "ATT attach failed "
+                           << (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
+        return 0;
+    }
+
     if (!viewer_object->isAnimatedObject())
     {
         updateAttachmentOverrides();
     }
 
-	updateVisualComplexity();
+    updateVisualComplexity();
 
-	if (viewer_object->isSelected())
-	{
-		LLSelectMgr::getInstance()->updateSelectionCenter();
-		LLSelectMgr::getInstance()->updatePointAt();
-	}
+    if (viewer_object->isSelected())
+    {
+        LLSelectMgr::getInstance()->updateSelectionCenter();
+        LLSelectMgr::getInstance()->updatePointAt();
+    }
 
-	viewer_object->refreshBakeTexture();
+    viewer_object->refreshBakeTexture();
 
 
-	LLViewerObject::const_child_list_t& child_list = viewer_object->getChildren();
-	for (LLViewerObject* objectp : child_list)
-	{
-		if (objectp)
-		{
-			objectp->refreshBakeTexture();
-		}
-	}
+    LLViewerObject::const_child_list_t& child_list = viewer_object->getChildren();
+    for (LLViewerObject* objectp : child_list)
+    {
+        if (objectp)
+        {
+            objectp->refreshBakeTexture();
+        }
+    }
 
-	updateMeshVisibility();
+    updateMeshVisibility();
 
-	return attachment;
+    return attachment;
 }
 
 //-----------------------------------------------------------------------------
@@ -7694,14 +7694,14 @@ const LLViewerJointAttachment *LLVOAvatar::attachObject(LLViewerObject *viewer_o
 //-----------------------------------------------------------------------------
 U32 LLVOAvatar::getNumAttachments() const
 {
-	U32 num_attachments = 0;
+    U32 num_attachments = 0;
 
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		const LLViewerJointAttachment* attachment_pt = attach_pair.second;
-		num_attachments += attachment_pt->getNumObjects();
-	}
-	return num_attachments;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        const LLViewerJointAttachment* attachment_pt = attach_pair.second;
+        num_attachments += attachment_pt->getNumObjects();
+    }
+    return num_attachments;
 }
 
 //-----------------------------------------------------------------------------
@@ -7709,7 +7709,7 @@ U32 LLVOAvatar::getNumAttachments() const
 //-----------------------------------------------------------------------------
 S32 LLVOAvatar::getMaxAttachments() const
 {
-	return LLAgentBenefitsMgr::current().getAttachmentLimit();
+    return LLAgentBenefitsMgr::current().getAttachmentLimit();
 }
 
 //-----------------------------------------------------------------------------
@@ -7718,7 +7718,7 @@ S32 LLVOAvatar::getMaxAttachments() const
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatar::canAttachMoreObjects(U32 n) const
 {
-	return (getNumAttachments() + n) <= getMaxAttachments();
+    return (getNumAttachments() + n) <= getMaxAttachments();
 }
 
 //-----------------------------------------------------------------------------
@@ -7726,14 +7726,14 @@ BOOL LLVOAvatar::canAttachMoreObjects(U32 n) const
 //-----------------------------------------------------------------------------
 U32 LLVOAvatar::getNumAnimatedObjectAttachments() const
 {
-	U32 num_attachments = 0;
+    U32 num_attachments = 0;
 
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		const LLViewerJointAttachment *attachment_pt = attach_pair.second;
-		num_attachments += attachment_pt->getNumAnimatedObjects();
-	}
-	return num_attachments;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        const LLViewerJointAttachment *attachment_pt = attach_pair.second;
+        num_attachments += attachment_pt->getNumAnimatedObjects();
+    }
+    return num_attachments;
 }
 
 //-----------------------------------------------------------------------------
@@ -7742,7 +7742,7 @@ U32 LLVOAvatar::getNumAnimatedObjectAttachments() const
 //-----------------------------------------------------------------------------
 S32 LLVOAvatar::getMaxAnimatedObjectAttachments() const
 {
-	return LLAgentBenefitsMgr::current().getAnimatedObjectLimit();
+    return LLAgentBenefitsMgr::current().getAnimatedObjectLimit();
 }
 
 //-----------------------------------------------------------------------------
@@ -7751,7 +7751,7 @@ S32 LLVOAvatar::getMaxAnimatedObjectAttachments() const
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatar::canAttachMoreAnimatedObjects(U32 n) const
 {
-	return (getNumAnimatedObjectAttachments() + n) <= getMaxAnimatedObjectAttachments();
+    return (getNumAnimatedObjectAttachments() + n) <= getMaxAnimatedObjectAttachments();
 }
 
 //-----------------------------------------------------------------------------
@@ -7759,92 +7759,92 @@ BOOL LLVOAvatar::canAttachMoreAnimatedObjects(U32 n) const
 //-----------------------------------------------------------------------------
 void LLVOAvatar::lazyAttach()
 {
-	std::vector<LLPointer<LLViewerObject> > still_pending;
-	
-	for (LLPointer<LLViewerObject> cur_attachment : mPendingAttachment)
-	{
-		// Object might have died while we were waiting for drawable
-		if (cur_attachment.notNull() && !cur_attachment->isDead())
-		{
-			if (cur_attachment->mDrawable)
-			{
-				if (isSelf())
-				{
-					const LLUUID& item_id = cur_attachment->getAttachmentItemID();
-					LLViewerInventoryItem *item = gInventory.getItem(item_id);
-					LL_DEBUGS("Avatar") << "ATT attaching object "
-						<< (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
-				}
-				if (!attachObject(cur_attachment))
-				{	// Drop it
-					LL_WARNS() << "attachObject() failed for "
-						<< cur_attachment->getID()
-						<< " item " << cur_attachment->getAttachmentItemID()
-						<< LL_ENDL;
-					// MAINT-3312 backout
-					//still_pending.push_back(cur_attachment);
-				}
-			}
-			else
-			{
-				still_pending.push_back(cur_attachment);
-			}
-		}
-	}
-
-	mPendingAttachment = still_pending;
+    std::vector<LLPointer<LLViewerObject> > still_pending;
+
+    for (LLPointer<LLViewerObject> cur_attachment : mPendingAttachment)
+    {
+        // Object might have died while we were waiting for drawable
+        if (cur_attachment.notNull() && !cur_attachment->isDead())
+        {
+            if (cur_attachment->mDrawable)
+            {
+                if (isSelf())
+                {
+                    const LLUUID& item_id = cur_attachment->getAttachmentItemID();
+                    LLViewerInventoryItem *item = gInventory.getItem(item_id);
+                    LL_DEBUGS("Avatar") << "ATT attaching object "
+                        << (item ? item->getName() : "UNKNOWN") << " id " << item_id << LL_ENDL;
+                }
+                if (!attachObject(cur_attachment))
+                {   // Drop it
+                    LL_WARNS() << "attachObject() failed for "
+                        << cur_attachment->getID()
+                        << " item " << cur_attachment->getAttachmentItemID()
+                        << LL_ENDL;
+                    // MAINT-3312 backout
+                    //still_pending.push_back(cur_attachment);
+                }
+            }
+            else
+            {
+                still_pending.push_back(cur_attachment);
+            }
+        }
+    }
+
+    mPendingAttachment = still_pending;
 }
 
 void LLVOAvatar::resetHUDAttachments()
 {
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		if (attachment && attachment->getIsHUDAttachment())
-		{
-			for (const LLViewerObject* attached_object : attachment->mAttachedObjects)
-			{
-				if (attached_object && attached_object->mDrawable.notNull())
-				{
-					gPipeline.markMoved(attached_object->mDrawable);
-				}
-			}
-		}
-	}
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        if (attachment && attachment->getIsHUDAttachment())
+        {
+            for (const LLViewerObject* attached_object : attachment->mAttachedObjects)
+            {
+                if (attached_object && attached_object->mDrawable.notNull())
+                {
+                    gPipeline.markMoved(attached_object->mDrawable);
+                }
+            }
+        }
+    }
 }
 
 void LLVOAvatar::rebuildRiggedAttachments( void )
 {
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* pAttachment = attach_pair.second;
-		if (!pAttachment) continue;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* pAttachment = attach_pair.second;
+        if (!pAttachment) continue;
 
-		for (const LLViewerObject* pAttachedObject : pAttachment->mAttachedObjects)
-		{
-			if (pAttachedObject && pAttachedObject->mDrawable.notNull() )
-			{
-				gPipeline.markRebuild(pAttachedObject->mDrawable);
-			}
-		}
-	}
+        for (const LLViewerObject* pAttachedObject : pAttachment->mAttachedObjects)
+        {
+            if (pAttachedObject && pAttachedObject->mDrawable.notNull() )
+            {
+                gPipeline.markRebuild(pAttachedObject->mDrawable);
+            }
+        }
+    }
 }
 //-----------------------------------------------------------------------------
 // cleanupAttachedMesh()
 //-----------------------------------------------------------------------------
 void LLVOAvatar::cleanupAttachedMesh( LLViewerObject* pVO )
 {
-	LLUUID mesh_id;
-	if (getRiggedMeshID(pVO, mesh_id))
-	{
+    LLUUID mesh_id;
+    if (getRiggedMeshID(pVO, mesh_id))
+    {
         // FIXME this seems like an odd place for this code.
-		if ( gAgentCamera.cameraCustomizeAvatar() )
-		{
-			gAgent.unpauseAnimation();
-			//Still want to refocus on head bone
-			gAgentCamera.changeCameraToCustomizeAvatar();
-		}
-	}
+        if ( gAgentCamera.cameraCustomizeAvatar() )
+        {
+            gAgent.unpauseAnimation();
+            //Still want to refocus on head bone
+            gAgentCamera.changeCameraToCustomizeAvatar();
+        }
+    }
 }
 
 bool LLVOAvatar::hasPendingAttachedMeshes()
@@ -7931,47 +7931,47 @@ bool LLVOAvatar::hasPendingAttachedMeshes()
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatar::detachObject(LLViewerObject *viewer_object)
 {
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		
-		if (attachment->isObjectAttached(viewer_object))
-		{
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+
+        if (attachment->isObjectAttached(viewer_object))
+        {
             updateVisualComplexity();
             bool is_animated_object = viewer_object->isAnimatedObject();
-			cleanupAttachedMesh(viewer_object);
+            cleanupAttachedMesh(viewer_object);
 
-			attachment->removeObject(viewer_object);
+            attachment->removeObject(viewer_object);
             if (!is_animated_object)
             {
                 updateAttachmentOverrides();
             }
-			viewer_object->refreshBakeTexture();
-		
-			LLViewerObject::const_child_list_t& child_list = viewer_object->getChildren();
-			for (LLViewerObject* objectp : child_list)
-			{
-				if (objectp)
-				{
-					objectp->refreshBakeTexture();
-				}
+            viewer_object->refreshBakeTexture();
+
+            LLViewerObject::const_child_list_t& child_list = viewer_object->getChildren();
+            for (LLViewerObject* objectp : child_list)
+            {
+                if (objectp)
+                {
+                    objectp->refreshBakeTexture();
+                }
             }
 
-			updateMeshVisibility();
+            updateMeshVisibility();
+
+            LL_DEBUGS() << "Detaching object " << viewer_object->mID << " from " << attachment->getName() << LL_ENDL;
+            return TRUE;
+        }
+    }
 
-			LL_DEBUGS() << "Detaching object " << viewer_object->mID << " from " << attachment->getName() << LL_ENDL;
-			return TRUE;
-		}
-	}
+    std::vector<LLPointer<LLViewerObject> >::iterator iter = std::find(mPendingAttachment.begin(), mPendingAttachment.end(), viewer_object);
+    if (iter != mPendingAttachment.end())
+    {
+        mPendingAttachment.erase(iter);
+        return TRUE;
+    }
 
-	std::vector<LLPointer<LLViewerObject> >::iterator iter = std::find(mPendingAttachment.begin(), mPendingAttachment.end(), viewer_object);
-	if (iter != mPendingAttachment.end())
-	{
-		mPendingAttachment.erase(iter);
-		return TRUE;
-	}
-	
-	return FALSE;
+    return FALSE;
 }
 
 //-----------------------------------------------------------------------------
@@ -7979,19 +7979,19 @@ BOOL LLVOAvatar::detachObject(LLViewerObject *viewer_object)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::sitDown(BOOL bSitting)
 {
-	mIsSitting = bSitting;
-	if (isSelf())
-	{
-		// Update Movement Controls according to own Sitting mode
-		LLFloaterMove::setSittingMode(bSitting);
+    mIsSitting = bSitting;
+    if (isSelf())
+    {
+        // Update Movement Controls according to own Sitting mode
+        LLFloaterMove::setSittingMode(bSitting);
 
 // [RLVa:KB] - Checked: 2010-08-29 (RLVa-1.2.1c) | Modified: RLVa-1.2.1c
-		if (rlv_handler_t::isEnabled())
-		{
-			gRlvHandler.onSitOrStand(bSitting);
-		}
+        if (rlv_handler_t::isEnabled())
+        {
+            gRlvHandler.onSitOrStand(bSitting);
+        }
 // [/RLVa:KB]
-	}
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -7999,22 +7999,22 @@ void LLVOAvatar::sitDown(BOOL bSitting)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::sitOnObject(LLViewerObject *sit_object)
 {
-	if (isSelf())
-	{
-		// Might be first sit
-		//LLFirstUse::useSit();
-
-		gAgent.setFlying(FALSE);
-		gAgentCamera.setThirdPersonHeadOffset(LLVector3::zero);
-		//interpolate to new camera position
-		gAgentCamera.startCameraAnimation();
-		// make sure we are not trying to autopilot
-		gAgent.stopAutoPilot();
-		gAgentCamera.setupSitCamera();
-		if (gAgentCamera.getForceMouselook())
-		{
-			gAgentCamera.changeCameraToMouselook();
-		}
+    if (isSelf())
+    {
+        // Might be first sit
+        //LLFirstUse::useSit();
+
+        gAgent.setFlying(FALSE);
+        gAgentCamera.setThirdPersonHeadOffset(LLVector3::zero);
+        //interpolate to new camera position
+        gAgentCamera.startCameraAnimation();
+        // make sure we are not trying to autopilot
+        gAgent.stopAutoPilot();
+        gAgentCamera.setupSitCamera();
+        if (gAgentCamera.getForceMouselook())
+        {
+            gAgentCamera.changeCameraToMouselook();
+        }
 
         if (gAgentCamera.getFocusOnAvatar() && LLToolMgr::getInstance()->inEdit())
         {
@@ -8029,38 +8029,38 @@ void LLVOAvatar::sitOnObject(LLViewerObject *sit_object)
             }
         }
 
-		static LLCachedControl<U32> revoke_perms(gSavedSettings, "AlchemyRevokeObjectPerms");
-		if ((revoke_perms == 1 || revoke_perms == 3) && !sit_object->permYouOwner())
-		{
-			revoke_permissions_on_object(sit_object->getID());
-		}
-	}
+        static LLCachedControl<U32> revoke_perms(gSavedSettings, "AlchemyRevokeObjectPerms");
+        if ((revoke_perms == 1 || revoke_perms == 3) && !sit_object->permYouOwner())
+        {
+            revoke_permissions_on_object(sit_object->getID());
+        }
+    }
+
+    if (mDrawable.isNull())
+    {
+        return;
+    }
+    LLQuaternion inv_obj_rot = ~sit_object->getRenderRotation();
+    LLVector3 obj_pos = sit_object->getRenderPosition();
 
-	if (mDrawable.isNull())
-	{
-		return;
-	}
-	LLQuaternion inv_obj_rot = ~sit_object->getRenderRotation();
-	LLVector3 obj_pos = sit_object->getRenderPosition();
+    LLVector3 rel_pos = getRenderPosition() - obj_pos;
+    rel_pos.rotVec(inv_obj_rot);
 
-	LLVector3 rel_pos = getRenderPosition() - obj_pos;
-	rel_pos.rotVec(inv_obj_rot);
+    mDrawable->mXform.setPosition(rel_pos);
+    mDrawable->mXform.setRotation(mDrawable->getWorldRotation() * inv_obj_rot);
 
-	mDrawable->mXform.setPosition(rel_pos);
-	mDrawable->mXform.setRotation(mDrawable->getWorldRotation() * inv_obj_rot);
+    gPipeline.markMoved(mDrawable, TRUE);
+    // Notice that removing sitDown() from here causes avatars sitting on
+    // objects to be not rendered for new arrivals. See EXT-6835 and EXT-1655.
+    sitDown(TRUE);
+    mRoot->getXform()->setParent(&sit_object->mDrawable->mXform); // LLVOAvatar::sitOnObject
+    // SL-315
+    mRoot->setPosition(getPosition());
+    mRoot->updateWorldMatrixChildren();
 
-	gPipeline.markMoved(mDrawable, TRUE);
-	// Notice that removing sitDown() from here causes avatars sitting on
-	// objects to be not rendered for new arrivals. See EXT-6835 and EXT-1655.
-	sitDown(TRUE);
-	mRoot->getXform()->setParent(&sit_object->mDrawable->mXform); // LLVOAvatar::sitOnObject
-	// SL-315
-	mRoot->setPosition(getPosition());
-	mRoot->updateWorldMatrixChildren();
+    stopMotion(ANIM_AGENT_BODY_NOISE);
 
-	stopMotion(ANIM_AGENT_BODY_NOISE);
-	
-	gAgentCamera.setInitSitRot(gAgent.getFrameAgent().getQuaternion());
+    gAgentCamera.setInitSitRot(gAgent.getFrameAgent().getQuaternion());
 }
 
 //-----------------------------------------------------------------------------
@@ -8068,188 +8068,188 @@ void LLVOAvatar::sitOnObject(LLViewerObject *sit_object)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::getOffObject()
 {
-	if (mDrawable.isNull())
-	{
-		return;
-	}
-
-	LLViewerObject* sit_object = (LLViewerObject*)getParent();
-
-	if (sit_object)
-	{
-		stopMotionFromSource(sit_object->getID());
-
-		auto& followcam_mgr = LLFollowCamMgr::instance();
-		followcam_mgr.setCameraActive(sit_object->getID(), FALSE);
-
-		LLViewerObject::const_child_list_t& child_list = sit_object->getChildren();
-		for (LLViewerObject* child_objectp : child_list)
-		{
-			stopMotionFromSource(child_objectp->getID());
-			followcam_mgr.setCameraActive(child_objectp->getID(), FALSE);
-		}
-	}
-
-	// assumes that transform will not be updated with drawable still having a parent
-	// or that drawable had no parent from the start
-	LLVector3 cur_position_world = mDrawable->getWorldPosition();
-	LLQuaternion cur_rotation_world = mDrawable->getWorldRotation();
-
-	if (mLastRootPos.length() >= MAX_STANDOFF_FROM_ORIGIN
-		&& (cur_position_world.length() < MAX_STANDOFF_FROM_ORIGIN
-			|| dist_vec(cur_position_world, mLastRootPos) > MAX_STANDOFF_DISTANCE_CHANGE))
-	{
-		// Most likely drawable got updated too early or some updates were missed - we got relative position to non-existing parent
-		// restore coordinates from cache
-		cur_position_world = mLastRootPos;
-	}
-
-	// set *local* position based on last *world* position, since we're unparenting the avatar
-	mDrawable->mXform.setPosition(cur_position_world);
-	mDrawable->mXform.setRotation(cur_rotation_world);	
-	
-	gPipeline.markMoved(mDrawable, TRUE);
-
-	sitDown(FALSE);
-
-	mRoot->getXform()->setParent(NULL); // LLVOAvatar::getOffObject
-	// SL-315
-	mRoot->setPosition(cur_position_world);
-	mRoot->setRotation(cur_rotation_world);
-	mRoot->getXform()->update();
+    if (mDrawable.isNull())
+    {
+        return;
+    }
 
-    if (mEnableDefaultMotions)
+    LLViewerObject* sit_object = (LLViewerObject*)getParent();
+
+    if (sit_object)
+    {
+        stopMotionFromSource(sit_object->getID());
+
+        auto& followcam_mgr = LLFollowCamMgr::instance();
+        followcam_mgr.setCameraActive(sit_object->getID(), FALSE);
+
+        LLViewerObject::const_child_list_t& child_list = sit_object->getChildren();
+        for (LLViewerObject* child_objectp : child_list)
+        {
+            stopMotionFromSource(child_objectp->getID());
+            followcam_mgr.setCameraActive(child_objectp->getID(), FALSE);
+        }
+    }
+
+    // assumes that transform will not be updated with drawable still having a parent
+    // or that drawable had no parent from the start
+    LLVector3 cur_position_world = mDrawable->getWorldPosition();
+    LLQuaternion cur_rotation_world = mDrawable->getWorldRotation();
+
+    if (mLastRootPos.length() >= MAX_STANDOFF_FROM_ORIGIN
+        && (cur_position_world.length() < MAX_STANDOFF_FROM_ORIGIN
+            || dist_vec(cur_position_world, mLastRootPos) > MAX_STANDOFF_DISTANCE_CHANGE))
     {
-	startMotion(ANIM_AGENT_BODY_NOISE);
+        // Most likely drawable got updated too early or some updates were missed - we got relative position to non-existing parent
+        // restore coordinates from cache
+        cur_position_world = mLastRootPos;
     }
 
-	if (isSelf())
-	{
-		LLQuaternion av_rot = gAgent.getFrameAgent().getQuaternion();
-		LLQuaternion obj_rot = sit_object ? sit_object->getRenderRotation() : LLQuaternion::DEFAULT;
-		av_rot = av_rot * obj_rot;
-		LLVector3 at_axis = LLVector3::x_axis;
-		at_axis = at_axis * av_rot;
-		at_axis.mV[VZ] = 0.f;
-		at_axis.normalize();
-		gAgent.resetAxes(at_axis);
-		gAgentCamera.setThirdPersonHeadOffset(LLVector3(0.f, 0.f, 1.f));
-		gAgentCamera.setSitCamera(LLUUID::null);
+    // set *local* position based on last *world* position, since we're unparenting the avatar
+    mDrawable->mXform.setPosition(cur_position_world);
+    mDrawable->mXform.setRotation(cur_rotation_world);
+
+    gPipeline.markMoved(mDrawable, TRUE);
+
+    sitDown(FALSE);
+
+    mRoot->getXform()->setParent(NULL); // LLVOAvatar::getOffObject
+    // SL-315
+    mRoot->setPosition(cur_position_world);
+    mRoot->setRotation(cur_rotation_world);
+    mRoot->getXform()->update();
+
+    if (mEnableDefaultMotions)
+    {
+    startMotion(ANIM_AGENT_BODY_NOISE);
+    }
 
-		static LLCachedControl<U32> revoke_perms(gSavedSettings, "AlchemyRevokeObjectPerms");
-		if ((revoke_perms == 2 || revoke_perms == 3) && sit_object && !sit_object->permYouOwner())
-		{
-			revoke_permissions_on_object(sit_object->getID());
-		}
-	}
+    if (isSelf())
+    {
+        LLQuaternion av_rot = gAgent.getFrameAgent().getQuaternion();
+        LLQuaternion obj_rot = sit_object ? sit_object->getRenderRotation() : LLQuaternion::DEFAULT;
+        av_rot = av_rot * obj_rot;
+        LLVector3 at_axis = LLVector3::x_axis;
+        at_axis = at_axis * av_rot;
+        at_axis.mV[VZ] = 0.f;
+        at_axis.normalize();
+        gAgent.resetAxes(at_axis);
+        gAgentCamera.setThirdPersonHeadOffset(LLVector3(0.f, 0.f, 1.f));
+        gAgentCamera.setSitCamera(LLUUID::null);
+
+        static LLCachedControl<U32> revoke_perms(gSavedSettings, "AlchemyRevokeObjectPerms");
+        if ((revoke_perms == 2 || revoke_perms == 3) && sit_object && !sit_object->permYouOwner())
+        {
+            revoke_permissions_on_object(sit_object->getID());
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
 // findAvatarFromAttachment()
 //-----------------------------------------------------------------------------
-// static 
+// static
 LLVOAvatar* LLVOAvatar::findAvatarFromAttachment( LLViewerObject* obj )
 {
-	if( obj->isAttachment() )
-	{
-		do
-		{
-			obj = (LLViewerObject*) obj->getParent();
-		}
-		while( obj && !obj->isAvatar() );
+    if( obj->isAttachment() )
+    {
+        do
+        {
+            obj = (LLViewerObject*) obj->getParent();
+        }
+        while( obj && !obj->isAvatar() );
 
-		if( obj && !obj->isDead() )
-		{
-			return (LLVOAvatar*)obj;
-		}
-	}
-	return NULL;
+        if( obj && !obj->isDead() )
+        {
+            return (LLVOAvatar*)obj;
+        }
+    }
+    return NULL;
 }
 
 S32 LLVOAvatar::getAttachmentCount()
 {
-	S32 count = mAttachmentPoints.size();
-	return count;
+    S32 count = mAttachmentPoints.size();
+    return count;
 }
 
 BOOL LLVOAvatar::isWearingWearableType(LLWearableType::EType type) const
 {
-	if (mIsDummy) return TRUE;
-
-	if (isSelf())
-	{
-		return LLAvatarAppearance::isWearingWearableType(type);
-	}
-
-	switch(type)
-	{
-		case LLWearableType::WT_SHAPE:
-		case LLWearableType::WT_SKIN:
-		case LLWearableType::WT_HAIR:
-		case LLWearableType::WT_EYES:
-			return TRUE;  // everyone has all bodyparts
-		default:
-			break; // Do nothing
-	}
-
-	for (const auto& tex_pair : LLAvatarAppearance::getDictionary()->getTextures())
-	{
-		const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
-		if (texture_dict->mWearableType == type)
-		{
-			// Thus, you must check to see if the corresponding baked texture is defined.
-			// NOTE: this is a poor substitute if you actually want to know about individual pieces of clothing
-			// this works for detecting a skirt (most important), but is ineffective at any piece of clothing that
-			// gets baked into a texture that always exists (upper or lower).
-			if (texture_dict->mIsUsedByBakedTexture)
-			{
-				const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex;
-				return isTextureDefined(LLAvatarAppearance::getDictionary()->getBakedTexture(baked_index)->mTextureIndex);
-			}
-			return FALSE;
-		}
-	}
-	return FALSE;
-}
-
-LLViewerObject *	LLVOAvatar::findAttachmentByID( const LLUUID & target_id ) const
-{
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-		{
-			if (attached_object &&
-				attached_object->getID() == target_id)
-			{
-				return attached_object;
-			}
-		}
-	}
-
-	return NULL;
+    if (mIsDummy) return TRUE;
+
+    if (isSelf())
+    {
+        return LLAvatarAppearance::isWearingWearableType(type);
+    }
+
+    switch(type)
+    {
+        case LLWearableType::WT_SHAPE:
+        case LLWearableType::WT_SKIN:
+        case LLWearableType::WT_HAIR:
+        case LLWearableType::WT_EYES:
+            return TRUE;  // everyone has all bodyparts
+        default:
+            break; // Do nothing
+    }
+
+    for (const auto& tex_pair : LLAvatarAppearance::getDictionary()->getTextures())
+    {
+        const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
+        if (texture_dict->mWearableType == type)
+        {
+            // Thus, you must check to see if the corresponding baked texture is defined.
+            // NOTE: this is a poor substitute if you actually want to know about individual pieces of clothing
+            // this works for detecting a skirt (most important), but is ineffective at any piece of clothing that
+            // gets baked into a texture that always exists (upper or lower).
+            if (texture_dict->mIsUsedByBakedTexture)
+            {
+                const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex;
+                return isTextureDefined(LLAvatarAppearance::getDictionary()->getBakedTexture(baked_index)->mTextureIndex);
+            }
+            return FALSE;
+        }
+    }
+    return FALSE;
+}
+
+LLViewerObject *    LLVOAvatar::findAttachmentByID( const LLUUID & target_id ) const
+{
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        for (LLViewerObject* attached_object : attachment->mAttachedObjects)
+        {
+            if (attached_object &&
+                attached_object->getID() == target_id)
+            {
+                return attached_object;
+            }
+        }
+    }
+
+    return NULL;
 }
 
 // [SL:KB] - Patch: Appearance-RefreshAttachments | Checked: Catznip-5.3
 void LLVOAvatar::rebuildAttachments()
 {
-	for (const auto& kvpAttachPt : mAttachmentPoints)
-	{
-		for (LLViewerObject* pAttachObj : kvpAttachPt.second->mAttachedObjects)
-		{
-			if (!pAttachObj) continue;
-
-			if (LLVOVolume* pAttachVol = (pAttachObj->isMesh()) ? pAttachObj->asVolume() : nullptr)
-			{
-				pAttachVol->forceLOD(3);
-				for (LLViewerObject* pChildObj : pAttachObj->getChildren())
-				{
-					if (LLVOVolume* pChildVol = (pChildObj->isMesh()) ? pChildObj->asVolume() : nullptr)
-						pChildVol->forceLOD(3);
-				}
-			}
-		}
-	}
+    for (const auto& kvpAttachPt : mAttachmentPoints)
+    {
+        for (LLViewerObject* pAttachObj : kvpAttachPt.second->mAttachedObjects)
+        {
+            if (!pAttachObj) continue;
+
+            if (LLVOVolume* pAttachVol = (pAttachObj->isMesh()) ? pAttachObj->asVolume() : nullptr)
+            {
+                pAttachVol->forceLOD(3);
+                for (LLViewerObject* pChildObj : pAttachObj->getChildren())
+                {
+                    if (LLVOVolume* pChildVol = (pChildObj->isMesh()) ? pChildObj->asVolume() : nullptr)
+                        pChildVol->forceLOD(3);
+                }
+            }
+        }
+    }
 }
 // [/SL:KB]
 
@@ -8265,38 +8265,38 @@ void LLVOAvatar::invalidateAll()
 // virtual
 void LLVOAvatar::onGlobalColorChanged(const LLTexGlobalColor* global_color)
 {
-	if (global_color == mTexSkinColor)
-	{
-		invalidateComposite( mBakedTextureDatas[BAKED_HEAD].mTexLayerSet);
-		invalidateComposite( mBakedTextureDatas[BAKED_UPPER].mTexLayerSet);
-		invalidateComposite( mBakedTextureDatas[BAKED_LOWER].mTexLayerSet);
-	}
-	else if (global_color == mTexHairColor)
-	{
-		invalidateComposite( mBakedTextureDatas[BAKED_HEAD].mTexLayerSet);
-		invalidateComposite( mBakedTextureDatas[BAKED_HAIR].mTexLayerSet);
-		
-		// ! BACKWARDS COMPATIBILITY !
-		// Fix for dealing with avatars from viewers that don't bake hair.
-		if (!isTextureDefined(mBakedTextureDatas[BAKED_HAIR].mTextureIndex))
-		{
-			LLColor4 color = mTexHairColor->getColor();
-
-			for (LLAvatarJointMesh* mesh : mBakedTextureDatas[BAKED_HAIR].mJointMeshes)
-			{
-				if (mesh)
-			{
-					mesh->setColor( color );
-				}
-			}
-		}
-	} 
-	else if (global_color == mTexEyeColor)
-	{
-		// LL_INFOS() << "invalidateComposite cause: onGlobalColorChanged( eyecolor )" << LL_ENDL; 
-		invalidateComposite( mBakedTextureDatas[BAKED_EYES].mTexLayerSet);
-	}
-	updateMeshTextures();
+    if (global_color == mTexSkinColor)
+    {
+        invalidateComposite( mBakedTextureDatas[BAKED_HEAD].mTexLayerSet);
+        invalidateComposite( mBakedTextureDatas[BAKED_UPPER].mTexLayerSet);
+        invalidateComposite( mBakedTextureDatas[BAKED_LOWER].mTexLayerSet);
+    }
+    else if (global_color == mTexHairColor)
+    {
+        invalidateComposite( mBakedTextureDatas[BAKED_HEAD].mTexLayerSet);
+        invalidateComposite( mBakedTextureDatas[BAKED_HAIR].mTexLayerSet);
+
+        // ! BACKWARDS COMPATIBILITY !
+        // Fix for dealing with avatars from viewers that don't bake hair.
+        if (!isTextureDefined(mBakedTextureDatas[BAKED_HAIR].mTextureIndex))
+        {
+            LLColor4 color = mTexHairColor->getColor();
+
+            for (LLAvatarJointMesh* mesh : mBakedTextureDatas[BAKED_HAIR].mJointMeshes)
+            {
+                if (mesh)
+            {
+                    mesh->setColor( color );
+                }
+            }
+        }
+    }
+    else if (global_color == mTexEyeColor)
+    {
+        // LL_INFOS() << "invalidateComposite cause: onGlobalColorChanged( eyecolor )" << LL_ENDL;
+        invalidateComposite( mBakedTextureDatas[BAKED_EYES].mTexLayerSet);
+    }
+    updateMeshTextures();
 }
 
 // virtual
@@ -8305,12 +8305,12 @@ bool LLVOAvatar::shouldRenderRigged() const
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
 
-	if (getOverallAppearance() == AOA_NORMAL)
-	{
-		return true;
-	}
-	// TBD - render for AOA_JELLYDOLL?
-	return false;
+    if (getOverallAppearance() == AOA_NORMAL)
+    {
+        return true;
+    }
+    // TBD - render for AOA_JELLYDOLL?
+    return false;
 }
 
 // FIXME: We have an mVisible member, set in updateVisibility(), but this
@@ -8321,214 +8321,214 @@ bool LLVOAvatar::shouldRenderRigged() const
 // Maybe better naming could make this clearer?
 BOOL LLVOAvatar::isVisible() const
 {
-	return mDrawable.notNull()
-		&& (!mOrphaned || isSelf())
-		&& (mDrawable->isVisible() || mIsDummy);
+    return mDrawable.notNull()
+        && (!mOrphaned || isSelf())
+        && (mDrawable->isVisible() || mIsDummy);
 }
 
 // Determine if we have enough avatar data to render
 bool LLVOAvatar::getIsCloud() const
 {
-	if (mIsDummy)
-	{
-		return false;
-	}
+    if (mIsDummy)
+    {
+        return false;
+    }
 
-	return (   ((const_cast<LLVOAvatar*>(this))->visualParamWeightsAreDefault())// Do we have a shape?
-			|| (   !isTextureDefined(TEX_LOWER_BAKED)
-				|| !isTextureDefined(TEX_UPPER_BAKED)
-				|| !isTextureDefined(TEX_HEAD_BAKED)
-				)
-			);
+    return (   ((const_cast<LLVOAvatar*>(this))->visualParamWeightsAreDefault())// Do we have a shape?
+            || (   !isTextureDefined(TEX_LOWER_BAKED)
+                || !isTextureDefined(TEX_UPPER_BAKED)
+                || !isTextureDefined(TEX_HEAD_BAKED)
+                )
+            );
 }
 
 void LLVOAvatar::updateRezzedStatusTimers(S32 rez_status)
 {
-	// State machine for rezzed status. Statuses are -1 on startup, 0
-	// = cloud, 1 = gray, 2 = downloading, 3 = full.
-	// Purpose is to collect time data for each it takes avatar to reach
-	// various loading landmarks: gray, textured (partial), textured fully.
-
-	if (rez_status != mLastRezzedStatus)
-	{
-		LL_DEBUGS("Avatar") << avString() << "rez state change: " << mLastRezzedStatus << " -> " << rez_status << LL_ENDL;
-
-		if (mLastRezzedStatus == -1 && rez_status != -1)
-		{
-			// First time initialization, start all timers.
-			for (S32 i = 1; i < 4; i++)
-			{
-				startPhase("load_" + LLVOAvatar::rezStatusToString(i));
-				startPhase("first_load_" + LLVOAvatar::rezStatusToString(i));
-			}
-		}
-		if (rez_status < mLastRezzedStatus)
-		{
-			// load level has decreased. start phase timers for higher load levels.
-			for (S32 i = rez_status+1; i <= mLastRezzedStatus; i++)
-			{
-				startPhase("load_" + LLVOAvatar::rezStatusToString(i));
-			}
-		}
-		else if (rez_status > mLastRezzedStatus)
-		{
-			// load level has increased. stop phase timers for lower and equal load levels.
-			for (S32 i = llmax(mLastRezzedStatus+1,1); i <= rez_status; i++)
-			{
-				stopPhase("load_" + LLVOAvatar::rezStatusToString(i));
-				stopPhase("first_load_" + LLVOAvatar::rezStatusToString(i), false);
-			}
-			if (rez_status == 3)
-			{
-				// "fully loaded", mark any pending appearance change complete.
-				selfStopPhase("update_appearance_from_cof");
-				selfStopPhase("wear_inventory_category", false);
-				selfStopPhase("process_initial_wearables_update", false);
+    // State machine for rezzed status. Statuses are -1 on startup, 0
+    // = cloud, 1 = gray, 2 = downloading, 3 = full.
+    // Purpose is to collect time data for each it takes avatar to reach
+    // various loading landmarks: gray, textured (partial), textured fully.
+
+    if (rez_status != mLastRezzedStatus)
+    {
+        LL_DEBUGS("Avatar") << avString() << "rez state change: " << mLastRezzedStatus << " -> " << rez_status << LL_ENDL;
+
+        if (mLastRezzedStatus == -1 && rez_status != -1)
+        {
+            // First time initialization, start all timers.
+            for (S32 i = 1; i < 4; i++)
+            {
+                startPhase("load_" + LLVOAvatar::rezStatusToString(i));
+                startPhase("first_load_" + LLVOAvatar::rezStatusToString(i));
+            }
+        }
+        if (rez_status < mLastRezzedStatus)
+        {
+            // load level has decreased. start phase timers for higher load levels.
+            for (S32 i = rez_status+1; i <= mLastRezzedStatus; i++)
+            {
+                startPhase("load_" + LLVOAvatar::rezStatusToString(i));
+            }
+        }
+        else if (rez_status > mLastRezzedStatus)
+        {
+            // load level has increased. stop phase timers for lower and equal load levels.
+            for (S32 i = llmax(mLastRezzedStatus+1,1); i <= rez_status; i++)
+            {
+                stopPhase("load_" + LLVOAvatar::rezStatusToString(i));
+                stopPhase("first_load_" + LLVOAvatar::rezStatusToString(i), false);
+            }
+            if (rez_status == 3)
+            {
+                // "fully loaded", mark any pending appearance change complete.
+                selfStopPhase("update_appearance_from_cof");
+                selfStopPhase("wear_inventory_category", false);
+                selfStopPhase("process_initial_wearables_update", false);
 
                 updateVisualComplexity();
-			}
-		}
-		mLastRezzedStatus = rez_status;
-	}
+            }
+        }
+        mLastRezzedStatus = rez_status;
+    }
 }
 
 void LLVOAvatar::clearPhases()
 {
-	getPhases().clearPhases();
+    getPhases().clearPhases();
 }
 
 void LLVOAvatar::startPhase(const std::string& phase_name)
 {
-	F32 elapsed = 0.0;
-	bool completed = false;
-	bool found = getPhases().getPhaseValues(phase_name, elapsed, completed);
-	//LL_DEBUGS("Avatar") << avString() << " phase state " << phase_name
-	//					<< " found " << found << " elapsed " << elapsed << " completed " << completed << LL_ENDL;
-	if (found)
-	{
-		if (!completed)
-		{
+    F32 elapsed = 0.0;
+    bool completed = false;
+    bool found = getPhases().getPhaseValues(phase_name, elapsed, completed);
+    //LL_DEBUGS("Avatar") << avString() << " phase state " << phase_name
+    //                  << " found " << found << " elapsed " << elapsed << " completed " << completed << LL_ENDL;
+    if (found)
+    {
+        if (!completed)
+        {
 #ifdef SHOW_DEBUG
-			LL_DEBUGS("Avatar") << avString() << "no-op, start when started already for " << phase_name << LL_ENDL;
+            LL_DEBUGS("Avatar") << avString() << "no-op, start when started already for " << phase_name << LL_ENDL;
 #endif
-			return;
-		}
-	}
+            return;
+        }
+    }
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Avatar") << "started phase " << phase_name << LL_ENDL;
+    LL_DEBUGS("Avatar") << "started phase " << phase_name << LL_ENDL;
 #endif
-	getPhases().startPhase(phase_name);
+    getPhases().startPhase(phase_name);
 }
 
 void LLVOAvatar::stopPhase(const std::string& phase_name, bool err_check)
 {
-	F32 elapsed = 0.0;
-	bool completed = false;
-	if (getPhases().getPhaseValues(phase_name, elapsed, completed))
-	{
-		if (!completed)
-		{
-			getPhases().stopPhase(phase_name);
-			completed = true;
-			logMetricsTimerRecord(phase_name, elapsed, completed);
+    F32 elapsed = 0.0;
+    bool completed = false;
+    if (getPhases().getPhaseValues(phase_name, elapsed, completed))
+    {
+        if (!completed)
+        {
+            getPhases().stopPhase(phase_name);
+            completed = true;
+            logMetricsTimerRecord(phase_name, elapsed, completed);
 #ifdef SHOW_DEBUG
-			LL_DEBUGS("Avatar") << avString() << "stopped phase " << phase_name << " elapsed " << elapsed << LL_ENDL;
+            LL_DEBUGS("Avatar") << avString() << "stopped phase " << phase_name << " elapsed " << elapsed << LL_ENDL;
 #endif
-		}
+        }
 #ifdef SHOW_DEBUG
-		else
-		{
-			if (err_check)
-			{
-				LL_DEBUGS("Avatar") << "no-op, stop when stopped already for " << phase_name << LL_ENDL;
-			}
-		}
+        else
+        {
+            if (err_check)
+            {
+                LL_DEBUGS("Avatar") << "no-op, stop when stopped already for " << phase_name << LL_ENDL;
+            }
+        }
 #endif
-	}
+    }
 #ifdef SHOW_DEBUG
-	else
-	{
-		if (err_check)
-		{
-			LL_DEBUGS("Avatar") << "no-op, stop when not started for " << phase_name << LL_ENDL;
-		}
-	}
+    else
+    {
+        if (err_check)
+        {
+            LL_DEBUGS("Avatar") << "no-op, stop when not started for " << phase_name << LL_ENDL;
+        }
+    }
 #endif
 }
 
 void LLVOAvatar::logPendingPhases()
 {
-	if (!isAgentAvatarValid())
-	{
-		return;
-	}
-	
-	for (const auto& phase_pair : getPhases())
-	{
-		const std::string& phase_name = phase_pair.first;
-		F32 elapsed;
-		bool completed;
-		if (getPhases().getPhaseValues(phase_name, elapsed, completed))
-		{
-			if (!completed)
-			{
-				logMetricsTimerRecord(phase_name, elapsed, completed);
-			}
-		}
-	}
+    if (!isAgentAvatarValid())
+    {
+        return;
+    }
+
+    for (const auto& phase_pair : getPhases())
+    {
+        const std::string& phase_name = phase_pair.first;
+        F32 elapsed;
+        bool completed;
+        if (getPhases().getPhaseValues(phase_name, elapsed, completed))
+        {
+            if (!completed)
+            {
+                logMetricsTimerRecord(phase_name, elapsed, completed);
+            }
+        }
+    }
 }
 
 //static
 void LLVOAvatar::logPendingPhasesAllAvatars()
 {
-	for (LLCharacter* character : LLCharacter::sInstances)
-	{
-		LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
-		if( inst->isDead() )
-		{
-			continue;
-		}
-		inst->logPendingPhases();
-	}
+    for (LLCharacter* character : LLCharacter::sInstances)
+    {
+        LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
+        if( inst->isDead() )
+        {
+            continue;
+        }
+        inst->logPendingPhases();
+    }
 }
 
 void LLVOAvatar::logMetricsTimerRecord(const std::string& phase_name, F32 elapsed, bool completed)
 {
-	if (!isAgentAvatarValid())
-	{
-		return;
-	}
-	
-	LLSD record;
-	record["timer_name"] = phase_name;
-	record["avatar_id"] = getID();
-	record["elapsed"] = elapsed;
-	record["completed"] = completed;
-	U32 grid_x(0), grid_y(0);
-	if (!isDead() && getRegion() && LLWorld::instance().isRegionListed(getRegion()))
-	{
-		record["central_bake_version"] = LLSD::Integer(getRegion()->getCentralBakeVersion());
-		grid_from_region_handle(getRegion()->getHandle(), &grid_x, &grid_y);
-	}
-	record["grid_x"] = LLSD::Integer(grid_x);
-	record["grid_y"] = LLSD::Integer(grid_y);
-	record["is_using_server_bakes"] = true;
-	record["is_self"] = isSelf();
-		
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->addMetricsTimerRecord(record);
-	}
+    if (!isAgentAvatarValid())
+    {
+        return;
+    }
+
+    LLSD record;
+    record["timer_name"] = phase_name;
+    record["avatar_id"] = getID();
+    record["elapsed"] = elapsed;
+    record["completed"] = completed;
+    U32 grid_x(0), grid_y(0);
+    if (!isDead() && getRegion() && LLWorld::instance().isRegionListed(getRegion()))
+    {
+        record["central_bake_version"] = LLSD::Integer(getRegion()->getCentralBakeVersion());
+        grid_from_region_handle(getRegion()->getHandle(), &grid_x, &grid_y);
+    }
+    record["grid_x"] = LLSD::Integer(grid_x);
+    record["grid_y"] = LLSD::Integer(grid_y);
+    record["is_using_server_bakes"] = true;
+    record["is_self"] = isSelf();
+
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->addMetricsTimerRecord(record);
+    }
 }
 
 // call periodically to keep isFullyLoaded up to date.
 // returns true if the value has changed.
 BOOL LLVOAvatar::updateIsFullyLoaded()
 {
-	S32 rez_status = getRezzedStatus();
-	bool loading = getIsCloud();
-	if (mFirstFullyVisible && !mIsControlAvatar)
-	{
+    S32 rez_status = getRezzedStatus();
+    bool loading = getIsCloud();
+    if (mFirstFullyVisible && !mIsControlAvatar)
+    {
         loading = ((rez_status < 2)
                    // Wait at least 60s for unfinished textures to finish on first load,
                    // don't wait forever, it might fail. Even if it will eventually load by
@@ -8539,56 +8539,56 @@ BOOL LLVOAvatar::updateIsFullyLoaded()
                    || (rez_status < 3 && !isFullyBaked())
                    //|| hasPendingAttachedMeshes()
                   );
-	}
-	updateRezzedStatusTimers(rez_status);
-	updateRuthTimer(loading);
-	return processFullyLoadedChange(loading);
+    }
+    updateRezzedStatusTimers(rez_status);
+    updateRuthTimer(loading);
+    return processFullyLoadedChange(loading);
 }
 
 void LLVOAvatar::updateRuthTimer(bool loading)
 {
-	if (isSelf() || !loading) 
-	{
-		return;
-	}
-
-	if (mPreviousFullyLoaded)
-	{
-		mRuthTimer.reset();
-		debugAvatarRezTime("AvatarRezCloudNotification","became cloud");
-	}
-	
-	const F32 LOADING_TIMEOUT__SECONDS = 120.f;
-	if (mRuthTimer.getElapsedTimeF32() > LOADING_TIMEOUT__SECONDS)
-	{
-		LL_DEBUGS("Avatar") << avString()
-				<< "Ruth Timer timeout: Missing texture data for '" << getFullname() << "' "
-				<< "( Params loaded : " << !visualParamWeightsAreDefault() << " ) "
-				<< "( Lower : " << isTextureDefined(TEX_LOWER_BAKED) << " ) "
-				<< "( Upper : " << isTextureDefined(TEX_UPPER_BAKED) << " ) "
-				<< "( Head : " << isTextureDefined(TEX_HEAD_BAKED) << " )."
-				<< LL_ENDL;
-		
-		LLAvatarPropertiesProcessor::getInstance()->sendAvatarTexturesRequest(getID());
-		mRuthTimer.reset();
-	}
+    if (isSelf() || !loading)
+    {
+        return;
+    }
+
+    if (mPreviousFullyLoaded)
+    {
+        mRuthTimer.reset();
+        debugAvatarRezTime("AvatarRezCloudNotification","became cloud");
+    }
+
+    const F32 LOADING_TIMEOUT__SECONDS = 120.f;
+    if (mRuthTimer.getElapsedTimeF32() > LOADING_TIMEOUT__SECONDS)
+    {
+        LL_DEBUGS("Avatar") << avString()
+                << "Ruth Timer timeout: Missing texture data for '" << getFullname() << "' "
+                << "( Params loaded : " << !visualParamWeightsAreDefault() << " ) "
+                << "( Lower : " << isTextureDefined(TEX_LOWER_BAKED) << " ) "
+                << "( Upper : " << isTextureDefined(TEX_UPPER_BAKED) << " ) "
+                << "( Head : " << isTextureDefined(TEX_HEAD_BAKED) << " )."
+                << LL_ENDL;
+
+        LLAvatarPropertiesProcessor::getInstance()->sendAvatarTexturesRequest(getID());
+        mRuthTimer.reset();
+    }
 }
 
 BOOL LLVOAvatar::processFullyLoadedChange(bool loading)
 {
-	// We wait a little bit before giving the 'all clear', to let things to
-	// settle down (models to snap into place, textures to get first packets).
+    // We wait a little bit before giving the 'all clear', to let things to
+    // settle down (models to snap into place, textures to get first packets).
     // And if viewer isn't aware of some parts yet, this gives them a chance
     // to arrive.
-	const F32 LOADED_DELAY = 1.f;
+    const F32 LOADED_DELAY = 1.f;
 
     if (loading)
     {
         mFullyLoadedTimer.reset();
     }
 
-	if (mFirstFullyVisible)
-	{
+    if (mFirstFullyVisible)
+    {
         if (!isSelf() && loading)
         {
                 // Note that textures can causes 60s delay on thier own
@@ -8605,31 +8605,31 @@ BOOL LLVOAvatar::processFullyLoadedChange(bool loading)
                     mFirstUseDelaySeconds *= 1.25;
                 }
         }
-		mFullyLoaded = (mFullyLoadedTimer.getElapsedTimeF32() > mFirstUseDelaySeconds);
-	}
-	else
-	{
-		mFullyLoaded = (mFullyLoadedTimer.getElapsedTimeF32() > LOADED_DELAY);
-	}
-
-	if (!mPreviousFullyLoaded && !loading && mFullyLoaded)
-	{
-		debugAvatarRezTime("AvatarRezNotification","fully loaded");
-	}
-
-	// did our loading state "change" from last call?
-	// FIXME runway - why are we updating every 30 calls even if nothing has changed?
-	// This causes updateLOD() to run every 30 frames, among other things.
-	const S32 UPDATE_RATE = 30;
-	BOOL changed =
-		((mFullyLoaded != mPreviousFullyLoaded) ||         // if the value is different from the previous call
-		 (!mFullyLoadedInitialized) ||                     // if we've never been called before
-		 (mFullyLoadedFrameCounter % UPDATE_RATE == 0));   // every now and then issue a change
-	BOOL fully_loaded_changed = (mFullyLoaded != mPreviousFullyLoaded);
-
-	mPreviousFullyLoaded = mFullyLoaded;
-	mFullyLoadedInitialized = TRUE;
-	mFullyLoadedFrameCounter++;
+        mFullyLoaded = (mFullyLoadedTimer.getElapsedTimeF32() > mFirstUseDelaySeconds);
+    }
+    else
+    {
+        mFullyLoaded = (mFullyLoadedTimer.getElapsedTimeF32() > LOADED_DELAY);
+    }
+
+    if (!mPreviousFullyLoaded && !loading && mFullyLoaded)
+    {
+        debugAvatarRezTime("AvatarRezNotification","fully loaded");
+    }
+
+    // did our loading state "change" from last call?
+    // FIXME runway - why are we updating every 30 calls even if nothing has changed?
+    // This causes updateLOD() to run every 30 frames, among other things.
+    const S32 UPDATE_RATE = 30;
+    BOOL changed =
+        ((mFullyLoaded != mPreviousFullyLoaded) ||         // if the value is different from the previous call
+         (!mFullyLoadedInitialized) ||                     // if we've never been called before
+         (mFullyLoadedFrameCounter % UPDATE_RATE == 0));   // every now and then issue a change
+    BOOL fully_loaded_changed = (mFullyLoaded != mPreviousFullyLoaded);
+
+    mPreviousFullyLoaded = mFullyLoaded;
+    mFullyLoadedInitialized = TRUE;
+    mFullyLoadedFrameCounter++;
 
     if (changed && isSelf())
     {
@@ -8637,44 +8637,44 @@ BOOL LLVOAvatar::processFullyLoadedChange(bool loading)
         LLAvatarRenderNotifier::getInstance()->updateNotificationState();
     }
 
-	if (fully_loaded_changed && !isSelf() && mFullyLoaded && isImpostor())
-	{
-		// Fix for jellydoll initially invisible
-		mNeedsImpostorUpdate = TRUE;
-		mLastImpostorUpdateReason = 6;
-	}	
-	return changed;
+    if (fully_loaded_changed && !isSelf() && mFullyLoaded && isImpostor())
+    {
+        // Fix for jellydoll initially invisible
+        mNeedsImpostorUpdate = TRUE;
+        mLastImpostorUpdateReason = 6;
+    }
+    return changed;
 }
 
 BOOL LLVOAvatar::isFullyLoaded() const
 {
-	static LLCachedControl<bool> render_unloaded_avatar(gSavedSettings, "RenderUnloadedAvatar", false);
-	return (render_unloaded_avatar || mFullyLoaded);
+    static LLCachedControl<bool> render_unloaded_avatar(gSavedSettings, "RenderUnloadedAvatar", false);
+    return (render_unloaded_avatar || mFullyLoaded);
 }
 
 bool LLVOAvatar::isTooComplex() const
 {
-	static const LLCachedControl<bool> always_render_friends(gSavedSettings, "AlwaysRenderFriends", false);
-	bool too_complex;
-	if (isSelf() || mVisuallyMuteSetting == AV_ALWAYS_RENDER || (always_render_friends && isInBuddyList()))
-	{
-		too_complex = false;
-	}
-	else
-	{
-		// Determine if visually muted or not
-		static LLCachedControl<U32> max_render_cost(gSavedSettings, "RenderAvatarMaxComplexity", 0U);
-		static LLCachedControl<F32> max_attachment_area(gSavedSettings, "RenderAutoMuteSurfaceAreaLimit", 1000.0f);
-		// If the user has chosen unlimited max complexity, we also disregard max attachment area
+    static const LLCachedControl<bool> always_render_friends(gSavedSettings, "AlwaysRenderFriends", false);
+    bool too_complex;
+    if (isSelf() || mVisuallyMuteSetting == AV_ALWAYS_RENDER || (always_render_friends && isInBuddyList()))
+    {
+        too_complex = false;
+    }
+    else
+    {
+        // Determine if visually muted or not
+        static LLCachedControl<U32> max_render_cost(gSavedSettings, "RenderAvatarMaxComplexity", 0U);
+        static LLCachedControl<F32> max_attachment_area(gSavedSettings, "RenderAutoMuteSurfaceAreaLimit", 1000.0f);
+        // If the user has chosen unlimited max complexity, we also disregard max attachment area
         // so that unlimited will completely disable the overly complex impostor rendering
         // yes, this leaves them vulnerable to griefing objects... their choice
         too_complex = (   max_render_cost > 0
                           && (mVisualComplexity > max_render_cost
                            || (max_attachment_area > 0.0f && mAttachmentSurfaceArea > max_attachment_area)
                            ));
-	}
+    }
 
-	return too_complex;
+    return too_complex;
 }
 
 bool LLVOAvatar::isTooSlow() const
@@ -8699,13 +8699,13 @@ void LLVOAvatar::updateTooSlow()
 
     // mTooSlow - Is the avatar flagged as being slow (includes shadow time)
     // mTooSlowWithoutShadows - Is the avatar flagged as being slow even with shadows removed.
-    
+
     // get max render time in ms
     F32 max_art_ms = (F32) (LLPerfStats::renderAvatarMaxART_ns / 1000000.0);
 
-	bool autotune = LLPerfStats::tunables.userAutoTuneEnabled && !mIsControlAvatar && !isSelf();
+    bool autotune = LLPerfStats::tunables.userAutoTuneEnabled && !mIsControlAvatar && !isSelf();
 
-	bool ignore_tune = false;
+    bool ignore_tune = false;
     if (autotune && sAVsIgnoringARTLimit.size() > 0)
     {
         auto it = std::find(sAVsIgnoringARTLimit.begin(), sAVsIgnoringARTLimit.end(), mID);
@@ -8716,18 +8716,18 @@ void LLVOAvatar::updateTooSlow()
         }
     }
 
-	bool exceeds_max_ART =
-        ((LLPerfStats::renderAvatarMaxART_ns > 0) && 
+    bool exceeds_max_ART =
+        ((LLPerfStats::renderAvatarMaxART_ns > 0) &&
             (mGPURenderTime >= max_art_ms)); // NOTE: don't use getGPURenderTime accessor here to avoid "isTooSlow" feedback loop
 
     if (exceeds_max_ART && !ignore_tune)
     {
         mTooSlow = true;
-        
+
         if(!mTooSlowWithoutShadows) // if we were not previously above the full impostor cap
         {
-            bool render_friend_or_exception =  	( alwaysRenderFriends && LLAvatarTracker::instance().isBuddy( id ) ) ||
-                ( getVisualMuteSettings() == LLVOAvatar::AV_ALWAYS_RENDER ); 
+            bool render_friend_or_exception =   ( alwaysRenderFriends && LLAvatarTracker::instance().isBuddy( id ) ) ||
+                ( getVisualMuteSettings() == LLVOAvatar::AV_ALWAYS_RENDER );
             if( (!isSelf() || allowSelfImpostor) && !render_friend_or_exception  )
             {
                 // Note: slow rendering Friends still get their shadows zapped.
@@ -8740,10 +8740,10 @@ void LLVOAvatar::updateTooSlow()
         mTooSlow = false;
         mTooSlowWithoutShadows = false;
 
-		if (ignore_tune)
-		{
+        if (ignore_tune)
+        {
             return;
-		}
+        }
     }
     if(mTooSlow && !mTuned)
     {
@@ -8762,24 +8762,24 @@ void LLVOAvatar::updateTooSlow()
 //-----------------------------------------------------------------------------
 LLMotion* LLVOAvatar::findMotion(const LLUUID& id) const
 {
-	return mMotionController.findMotion(id);
+    return mMotionController.findMotion(id);
 }
 
 // This is a semi-deprecated debugging tool - meshes will not show as
 // colorized if using deferred rendering.
 void LLVOAvatar::debugColorizeSubMeshes(U32 i, const LLColor4& color)
 {
-	static const LLCachedControl<bool> debug_av_comp_bk(gSavedSettings, "DebugAvatarCompositeBaked");
-	if (debug_av_comp_bk)
-	{
-		for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
-		{
-			if (mesh)
-			{
-				mesh->setColor(color);
-			}
-		}
-	}
+    static const LLCachedControl<bool> debug_av_comp_bk(gSavedSettings, "DebugAvatarCompositeBaked");
+    if (debug_av_comp_bk)
+    {
+        for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
+        {
+            if (mesh)
+            {
+                mesh->setColor(color);
+            }
+        }
+    }
 }
 
 
@@ -8789,109 +8789,109 @@ void LLVOAvatar::debugColorizeSubMeshes(U32 i, const LLColor4& color)
 //-----------------------------------------------------------------------------
 void LLVOAvatar::updateMeshVisibility()
 {
-	bool bake_flag[BAKED_NUM_INDICES];
-	memset(bake_flag, 0, BAKED_NUM_INDICES*sizeof(bool));
-
-	if (getOverallAppearance() == AOA_NORMAL)
-	{
-		for (const auto& attach_pair : mAttachmentPoints)
-		{
-			LLViewerJointAttachment* attachment = attach_pair.second;
-			if (attachment)
-			{
-				for (LLViewerObject* objectp : attachment->mAttachedObjects)
-				{
-					if (objectp)
-					{
-						for (int face_index = 0; face_index < objectp->getNumTEs(); face_index++)
-						{
-							LLTextureEntry* tex_entry = objectp->getTE(face_index);
-							if (tex_entry)
-							{
-								bake_flag[BAKED_HEAD] |= (tex_entry->getID() == IMG_USE_BAKED_HEAD);
-								bake_flag[BAKED_EYES] |= (tex_entry->getID() == IMG_USE_BAKED_EYES);
-								bake_flag[BAKED_HAIR] |= (tex_entry->getID() == IMG_USE_BAKED_HAIR);
-								bake_flag[BAKED_LOWER] |= (tex_entry->getID() == IMG_USE_BAKED_LOWER);
-								bake_flag[BAKED_UPPER] |= (tex_entry->getID() == IMG_USE_BAKED_UPPER);
-								bake_flag[BAKED_SKIRT] |= (tex_entry->getID() == IMG_USE_BAKED_SKIRT);
-								bake_flag[BAKED_LEFT_ARM] |= (tex_entry->getID() == IMG_USE_BAKED_LEFTARM);
-								bake_flag[BAKED_LEFT_LEG] |= (tex_entry->getID() == IMG_USE_BAKED_LEFTLEG);
-								bake_flag[BAKED_AUX1] |= (tex_entry->getID() == IMG_USE_BAKED_AUX1);
-								bake_flag[BAKED_AUX2] |= (tex_entry->getID() == IMG_USE_BAKED_AUX2);
-								bake_flag[BAKED_AUX3] |= (tex_entry->getID() == IMG_USE_BAKED_AUX3);
-							}
-						}
-
-
-						LLViewerObject::const_child_list_t& child_list = objectp->getChildren();
-						for (LLViewerObject* objectchild : child_list)
-						{
-							if (objectchild)
-							{
-								for (int face_index = 0; face_index < objectchild->getNumTEs(); face_index++)
-								{
-									LLTextureEntry* tex_entry = objectchild->getTE(face_index);
-									if (tex_entry)
-									{
-										bake_flag[BAKED_HEAD] |= (tex_entry->getID() == IMG_USE_BAKED_HEAD);
-										bake_flag[BAKED_EYES] |= (tex_entry->getID() == IMG_USE_BAKED_EYES);
-										bake_flag[BAKED_HAIR] |= (tex_entry->getID() == IMG_USE_BAKED_HAIR);
-										bake_flag[BAKED_LOWER] |= (tex_entry->getID() == IMG_USE_BAKED_LOWER);
-										bake_flag[BAKED_UPPER] |= (tex_entry->getID() == IMG_USE_BAKED_UPPER);
-										bake_flag[BAKED_SKIRT] |= (tex_entry->getID() == IMG_USE_BAKED_SKIRT);
-										bake_flag[BAKED_LEFT_ARM] |= (tex_entry->getID() == IMG_USE_BAKED_LEFTARM);
-										bake_flag[BAKED_LEFT_LEG] |= (tex_entry->getID() == IMG_USE_BAKED_LEFTLEG);
-										bake_flag[BAKED_AUX1] |= (tex_entry->getID() == IMG_USE_BAKED_AUX1);
-										bake_flag[BAKED_AUX2] |= (tex_entry->getID() == IMG_USE_BAKED_AUX2);
-										bake_flag[BAKED_AUX3] |= (tex_entry->getID() == IMG_USE_BAKED_AUX3);
-									}
-								}
-							}
-						}
-					}
-				}
-			}
-		}
-	}
-
-	//LL_INFOS() << "head " << bake_flag[BAKED_HEAD] << "eyes " << bake_flag[BAKED_EYES] << "hair " << bake_flag[BAKED_HAIR] << "lower " << bake_flag[BAKED_LOWER] << "upper " << bake_flag[BAKED_UPPER] << "skirt " << bake_flag[BAKED_SKIRT] << LL_ENDL;
-
-	for (S32 i = 0; i < mMeshLOD.size(); i++)
-	{
-		LLAvatarJoint* joint = mMeshLOD[i];
-		if (i == MESH_ID_HAIR)
-		{
-			joint->setVisible(!bake_flag[BAKED_HAIR], TRUE);
-		}
-		else if (i == MESH_ID_HEAD)
-		{
-			joint->setVisible(!bake_flag[BAKED_HEAD], TRUE);
-		}
-		else if (i == MESH_ID_SKIRT)
-		{
-			joint->setVisible(!bake_flag[BAKED_SKIRT], TRUE);
-		}
-		else if (i == MESH_ID_UPPER_BODY)
-		{
-			joint->setVisible(!bake_flag[BAKED_UPPER], TRUE);
-		}
-		else if (i == MESH_ID_LOWER_BODY)
-		{
-			joint->setVisible(!bake_flag[BAKED_LOWER], TRUE);
-		}
-		else if (i == MESH_ID_EYEBALL_LEFT)
-		{
-			joint->setVisible(!bake_flag[BAKED_EYES], TRUE);
-		}
-		else if (i == MESH_ID_EYEBALL_RIGHT)
-		{
-			joint->setVisible(!bake_flag[BAKED_EYES], TRUE);
-		}
-		else if (i == MESH_ID_EYELASH)
-		{
-			joint->setVisible(!bake_flag[BAKED_HEAD], TRUE);
-		}
-	}
+    bool bake_flag[BAKED_NUM_INDICES];
+    memset(bake_flag, 0, BAKED_NUM_INDICES*sizeof(bool));
+
+    if (getOverallAppearance() == AOA_NORMAL)
+    {
+        for (const auto& attach_pair : mAttachmentPoints)
+        {
+            LLViewerJointAttachment* attachment = attach_pair.second;
+            if (attachment)
+            {
+                for (LLViewerObject* objectp : attachment->mAttachedObjects)
+                {
+                    if (objectp)
+                    {
+                        for (int face_index = 0; face_index < objectp->getNumTEs(); face_index++)
+                        {
+                            LLTextureEntry* tex_entry = objectp->getTE(face_index);
+                            if (tex_entry)
+                            {
+                                bake_flag[BAKED_HEAD] |= (tex_entry->getID() == IMG_USE_BAKED_HEAD);
+                                bake_flag[BAKED_EYES] |= (tex_entry->getID() == IMG_USE_BAKED_EYES);
+                                bake_flag[BAKED_HAIR] |= (tex_entry->getID() == IMG_USE_BAKED_HAIR);
+                                bake_flag[BAKED_LOWER] |= (tex_entry->getID() == IMG_USE_BAKED_LOWER);
+                                bake_flag[BAKED_UPPER] |= (tex_entry->getID() == IMG_USE_BAKED_UPPER);
+                                bake_flag[BAKED_SKIRT] |= (tex_entry->getID() == IMG_USE_BAKED_SKIRT);
+                                bake_flag[BAKED_LEFT_ARM] |= (tex_entry->getID() == IMG_USE_BAKED_LEFTARM);
+                                bake_flag[BAKED_LEFT_LEG] |= (tex_entry->getID() == IMG_USE_BAKED_LEFTLEG);
+                                bake_flag[BAKED_AUX1] |= (tex_entry->getID() == IMG_USE_BAKED_AUX1);
+                                bake_flag[BAKED_AUX2] |= (tex_entry->getID() == IMG_USE_BAKED_AUX2);
+                                bake_flag[BAKED_AUX3] |= (tex_entry->getID() == IMG_USE_BAKED_AUX3);
+                            }
+                        }
+
+
+                        LLViewerObject::const_child_list_t& child_list = objectp->getChildren();
+                        for (LLViewerObject* objectchild : child_list)
+                        {
+                            if (objectchild)
+                            {
+                                for (int face_index = 0; face_index < objectchild->getNumTEs(); face_index++)
+                                {
+                                    LLTextureEntry* tex_entry = objectchild->getTE(face_index);
+                                    if (tex_entry)
+                                    {
+                                        bake_flag[BAKED_HEAD] |= (tex_entry->getID() == IMG_USE_BAKED_HEAD);
+                                        bake_flag[BAKED_EYES] |= (tex_entry->getID() == IMG_USE_BAKED_EYES);
+                                        bake_flag[BAKED_HAIR] |= (tex_entry->getID() == IMG_USE_BAKED_HAIR);
+                                        bake_flag[BAKED_LOWER] |= (tex_entry->getID() == IMG_USE_BAKED_LOWER);
+                                        bake_flag[BAKED_UPPER] |= (tex_entry->getID() == IMG_USE_BAKED_UPPER);
+                                        bake_flag[BAKED_SKIRT] |= (tex_entry->getID() == IMG_USE_BAKED_SKIRT);
+                                        bake_flag[BAKED_LEFT_ARM] |= (tex_entry->getID() == IMG_USE_BAKED_LEFTARM);
+                                        bake_flag[BAKED_LEFT_LEG] |= (tex_entry->getID() == IMG_USE_BAKED_LEFTLEG);
+                                        bake_flag[BAKED_AUX1] |= (tex_entry->getID() == IMG_USE_BAKED_AUX1);
+                                        bake_flag[BAKED_AUX2] |= (tex_entry->getID() == IMG_USE_BAKED_AUX2);
+                                        bake_flag[BAKED_AUX3] |= (tex_entry->getID() == IMG_USE_BAKED_AUX3);
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+        }
+    }
+
+    //LL_INFOS() << "head " << bake_flag[BAKED_HEAD] << "eyes " << bake_flag[BAKED_EYES] << "hair " << bake_flag[BAKED_HAIR] << "lower " << bake_flag[BAKED_LOWER] << "upper " << bake_flag[BAKED_UPPER] << "skirt " << bake_flag[BAKED_SKIRT] << LL_ENDL;
+
+    for (S32 i = 0; i < mMeshLOD.size(); i++)
+    {
+        LLAvatarJoint* joint = mMeshLOD[i];
+        if (i == MESH_ID_HAIR)
+        {
+            joint->setVisible(!bake_flag[BAKED_HAIR], TRUE);
+        }
+        else if (i == MESH_ID_HEAD)
+        {
+            joint->setVisible(!bake_flag[BAKED_HEAD], TRUE);
+        }
+        else if (i == MESH_ID_SKIRT)
+        {
+            joint->setVisible(!bake_flag[BAKED_SKIRT], TRUE);
+        }
+        else if (i == MESH_ID_UPPER_BODY)
+        {
+            joint->setVisible(!bake_flag[BAKED_UPPER], TRUE);
+        }
+        else if (i == MESH_ID_LOWER_BODY)
+        {
+            joint->setVisible(!bake_flag[BAKED_LOWER], TRUE);
+        }
+        else if (i == MESH_ID_EYEBALL_LEFT)
+        {
+            joint->setVisible(!bake_flag[BAKED_EYES], TRUE);
+        }
+        else if (i == MESH_ID_EYEBALL_RIGHT)
+        {
+            joint->setVisible(!bake_flag[BAKED_EYES], TRUE);
+        }
+        else if (i == MESH_ID_EYELASH)
+        {
+            joint->setVisible(!bake_flag[BAKED_HEAD], TRUE);
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -8901,234 +8901,234 @@ void LLVOAvatar::updateMeshVisibility()
 // virtual
 void LLVOAvatar::updateMeshTextures()
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
-	static S32 update_counter = 0;
-	mBakedTextureDebugText.clear();
-	
-	// if user has never specified a texture, assign the default
-	for (U32 i=0; i < getNumTEs(); i++)
-	{
-		const LLViewerTexture* te_image = getImage(i, 0);
-		if(!te_image || te_image->getID().isNull() || (te_image->getID() == IMG_DEFAULT))
-		{
-			// IMG_DEFAULT_AVATAR = a special texture that's never rendered.
-			const LLUUID& image_id = (i == TEX_HAIR ? IMG_DEFAULT : IMG_DEFAULT_AVATAR);
-			setImage(i, LLViewerTextureManager::getFetchedTexture(image_id), 0); 
-		}
-	}
-
-	const BOOL other_culled = !isSelf() && mCulled;
-	LLLoadedCallbackEntry::source_callback_list_t* src_callback_list = NULL ;
-	BOOL paused = FALSE;
-	if(!isSelf())
-	{
-		src_callback_list = &mCallbackTextureList ;
-		paused = !isVisible();
-	}
-
-	std::vector<BOOL> is_layer_baked;
-	is_layer_baked.resize(mBakedTextureDatas.size(), false);
-
-	std::vector<BOOL> use_lkg_baked_layer; // lkg = "last known good"
-	use_lkg_baked_layer.resize(mBakedTextureDatas.size(), false);
-
-	mBakedTextureDebugText += llformat("%06d\n",update_counter++);
-	mBakedTextureDebugText += "indx layerset linvld ltda ilb ulkg ltid\n";
-	for (U32 i=0; i < mBakedTextureDatas.size(); i++)
-	{
-		is_layer_baked[i] = isTextureDefined(mBakedTextureDatas[i].mTextureIndex);
-		LLViewerTexLayerSet* layerset = NULL;
-		bool layerset_invalid = false;
-		if (!other_culled)
-		{
-			// When an avatar is changing clothes and not in Appearance mode,
-			// use the last-known good baked texture until it finishes the first
-			// render of the new layerset.
-			layerset = getTexLayerSet(i);
-			layerset_invalid = layerset && ( !layerset->getViewerComposite()->isInitialized()
-											 || !layerset->isLocalTextureDataAvailable() );
-			use_lkg_baked_layer[i] = (!is_layer_baked[i] 
-									  && (mBakedTextureDatas[i].mLastTextureID != IMG_DEFAULT_AVATAR) 
-									  && layerset_invalid);
-			if (use_lkg_baked_layer[i])
-			{
-				layerset->setUpdatesEnabled(TRUE);
-			}
-		}
-		else
-		{
-			use_lkg_baked_layer[i] = (!is_layer_baked[i] 
-									  && mBakedTextureDatas[i].mLastTextureID != IMG_DEFAULT_AVATAR);
-		}
-
-		std::string last_id_string;
-		if (mBakedTextureDatas[i].mLastTextureID == IMG_DEFAULT_AVATAR)
-			last_id_string = "A";
-		else if (mBakedTextureDatas[i].mLastTextureID == IMG_DEFAULT)
-			last_id_string = "D";
-		else if (mBakedTextureDatas[i].mLastTextureID == IMG_INVISIBLE)
-			last_id_string = "I";
-		else
-			last_id_string = "*";
-		bool is_ltda = layerset
-			&& layerset->getViewerComposite()->isInitialized()
-			&& layerset->isLocalTextureDataAvailable();
-		mBakedTextureDebugText += llformat("%4d   %4s     %4d %4d %4d %4d %4s\n",
-										   i,
-										   (layerset?"*":"0"),
-										   layerset_invalid,
-										   is_ltda,
-										   is_layer_baked[i],
-										   use_lkg_baked_layer[i],
-										   last_id_string.c_str());
-	}
-
-	for (U32 i=0; i < mBakedTextureDatas.size(); i++)
-	{
-		debugColorizeSubMeshes(i, LLColor4::white);
-
-		LLViewerTexLayerSet* layerset = getTexLayerSet(i);
-		if (use_lkg_baked_layer[i] && !isUsingLocalAppearance() )
-		{
-			// use last known good layer (no new one)
-			LLViewerFetchedTexture* baked_img = LLViewerTextureManager::getFetchedTexture(mBakedTextureDatas[i].mLastTextureID);
-			mBakedTextureDatas[i].mIsUsed = TRUE;
-
-			debugColorizeSubMeshes(i,LLColor4::red);
-	
-			for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
-			{
-				if (mesh)
-				{
-					mesh->setTexture( baked_img );
-				}
-			}
-		}
-		else if (!isUsingLocalAppearance() && is_layer_baked[i])
-		{
-			// use new layer
-			LLViewerFetchedTexture* baked_img =
-				LLViewerTextureManager::staticCastToFetchedTexture(
-					getImage( mBakedTextureDatas[i].mTextureIndex, 0 ), TRUE) ;
-			if( baked_img->getID() == mBakedTextureDatas[i].mLastTextureID )
-			{
-				// Even though the file may not be finished loading,
-				// we'll consider it loaded and use it (rather than
-				// doing compositing).
-				useBakedTexture( baked_img->getID() );
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR
+    static S32 update_counter = 0;
+    mBakedTextureDebugText.clear();
+
+    // if user has never specified a texture, assign the default
+    for (U32 i=0; i < getNumTEs(); i++)
+    {
+        const LLViewerTexture* te_image = getImage(i, 0);
+        if(!te_image || te_image->getID().isNull() || (te_image->getID() == IMG_DEFAULT))
+        {
+            // IMG_DEFAULT_AVATAR = a special texture that's never rendered.
+            const LLUUID& image_id = (i == TEX_HAIR ? IMG_DEFAULT : IMG_DEFAULT_AVATAR);
+            setImage(i, LLViewerTextureManager::getFetchedTexture(image_id), 0);
+        }
+    }
+
+    const BOOL other_culled = !isSelf() && mCulled;
+    LLLoadedCallbackEntry::source_callback_list_t* src_callback_list = NULL ;
+    BOOL paused = FALSE;
+    if(!isSelf())
+    {
+        src_callback_list = &mCallbackTextureList ;
+        paused = !isVisible();
+    }
+
+    std::vector<BOOL> is_layer_baked;
+    is_layer_baked.resize(mBakedTextureDatas.size(), false);
+
+    std::vector<BOOL> use_lkg_baked_layer; // lkg = "last known good"
+    use_lkg_baked_layer.resize(mBakedTextureDatas.size(), false);
+
+    mBakedTextureDebugText += llformat("%06d\n",update_counter++);
+    mBakedTextureDebugText += "indx layerset linvld ltda ilb ulkg ltid\n";
+    for (U32 i=0; i < mBakedTextureDatas.size(); i++)
+    {
+        is_layer_baked[i] = isTextureDefined(mBakedTextureDatas[i].mTextureIndex);
+        LLViewerTexLayerSet* layerset = NULL;
+        bool layerset_invalid = false;
+        if (!other_culled)
+        {
+            // When an avatar is changing clothes and not in Appearance mode,
+            // use the last-known good baked texture until it finishes the first
+            // render of the new layerset.
+            layerset = getTexLayerSet(i);
+            layerset_invalid = layerset && ( !layerset->getViewerComposite()->isInitialized()
+                                             || !layerset->isLocalTextureDataAvailable() );
+            use_lkg_baked_layer[i] = (!is_layer_baked[i]
+                                      && (mBakedTextureDatas[i].mLastTextureID != IMG_DEFAULT_AVATAR)
+                                      && layerset_invalid);
+            if (use_lkg_baked_layer[i])
+            {
+                layerset->setUpdatesEnabled(TRUE);
+            }
+        }
+        else
+        {
+            use_lkg_baked_layer[i] = (!is_layer_baked[i]
+                                      && mBakedTextureDatas[i].mLastTextureID != IMG_DEFAULT_AVATAR);
+        }
+
+        std::string last_id_string;
+        if (mBakedTextureDatas[i].mLastTextureID == IMG_DEFAULT_AVATAR)
+            last_id_string = "A";
+        else if (mBakedTextureDatas[i].mLastTextureID == IMG_DEFAULT)
+            last_id_string = "D";
+        else if (mBakedTextureDatas[i].mLastTextureID == IMG_INVISIBLE)
+            last_id_string = "I";
+        else
+            last_id_string = "*";
+        bool is_ltda = layerset
+            && layerset->getViewerComposite()->isInitialized()
+            && layerset->isLocalTextureDataAvailable();
+        mBakedTextureDebugText += llformat("%4d   %4s     %4d %4d %4d %4d %4s\n",
+                                           i,
+                                           (layerset?"*":"0"),
+                                           layerset_invalid,
+                                           is_ltda,
+                                           is_layer_baked[i],
+                                           use_lkg_baked_layer[i],
+                                           last_id_string.c_str());
+    }
+
+    for (U32 i=0; i < mBakedTextureDatas.size(); i++)
+    {
+        debugColorizeSubMeshes(i, LLColor4::white);
+
+        LLViewerTexLayerSet* layerset = getTexLayerSet(i);
+        if (use_lkg_baked_layer[i] && !isUsingLocalAppearance() )
+        {
+            // use last known good layer (no new one)
+            LLViewerFetchedTexture* baked_img = LLViewerTextureManager::getFetchedTexture(mBakedTextureDatas[i].mLastTextureID);
+            mBakedTextureDatas[i].mIsUsed = TRUE;
+
+            debugColorizeSubMeshes(i,LLColor4::red);
+
+            for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
+            {
+                if (mesh)
+                {
+                    mesh->setTexture( baked_img );
+                }
+            }
+        }
+        else if (!isUsingLocalAppearance() && is_layer_baked[i])
+        {
+            // use new layer
+            LLViewerFetchedTexture* baked_img =
+                LLViewerTextureManager::staticCastToFetchedTexture(
+                    getImage( mBakedTextureDatas[i].mTextureIndex, 0 ), TRUE) ;
+            if( baked_img->getID() == mBakedTextureDatas[i].mLastTextureID )
+            {
+                // Even though the file may not be finished loading,
+                // we'll consider it loaded and use it (rather than
+                // doing compositing).
+                useBakedTexture( baked_img->getID() );
                                 mLoadedCallbacksPaused |= !isVisible();
                                 checkTextureLoading();
-			}
-			else
-			{
-				mBakedTextureDatas[i].mIsLoaded = FALSE;
-				if ( (baked_img->getID() != IMG_INVISIBLE) &&
-					 ((i == BAKED_HEAD) || (i == BAKED_UPPER) || (i == BAKED_LOWER)) )
-				{			
-					baked_img->setLoadedCallback(onBakedTextureMasksLoaded, MORPH_MASK_REQUESTED_DISCARD, TRUE, TRUE, new LLTextureMaskData( mID ), 
-						src_callback_list, paused);
-				}
-				baked_img->setLoadedCallback(onBakedTextureLoaded, SWITCH_TO_BAKED_DISCARD, FALSE, FALSE, new LLUUID( mID ), 
-					src_callback_list, paused );
-				if (baked_img->getDiscardLevel() < 0 && !paused)
-				{
-					// mLoadedCallbackTextures will be updated by checkTextureLoading() below
-					mLastTexCallbackAddedTime.reset();
-				}
-
-				// this could add paused texture callbacks
-				mLoadedCallbacksPaused |= paused; 
-				checkTextureLoading();
-			}
-		}
-		else if (layerset && isUsingLocalAppearance())
-		{
-			debugColorizeSubMeshes(i,LLColor4::yellow );
-
-			layerset->createComposite();
-			layerset->setUpdatesEnabled( TRUE );
-			mBakedTextureDatas[i].mIsUsed = FALSE;
-
-			for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
-			{
-				if (mesh)
-				{
-					mesh->setLayerSet( layerset );
-				}
-			}
-		}
-		else
-		{
-			debugColorizeSubMeshes(i,LLColor4::blue);
-		}
-	}
-
-	// set texture and color of hair manually if we are not using a baked image.
-	// This can happen while loading hair for yourself, or for clients that did not
-	// bake a hair texture. Still needed for yourself after 1.22 is depricated.
-	if (!is_layer_baked[BAKED_HAIR])
-	{
-		const LLColor4 color = mTexHairColor ? mTexHairColor->getColor() : LLColor4(1,1,1,1);
-		LLViewerTexture* hair_img = getImage( TEX_HAIR, 0 );
-		for (LLAvatarJointMesh* mesh : mBakedTextureDatas[BAKED_HAIR].mJointMeshes)
-		{
-			if (mesh)
-			{
-				mesh->setColor( color );
-				mesh->setTexture( hair_img );
-			}
-		}
-	} 
-	
-	
-	for (const auto& baked_pair : LLAvatarAppearance::getDictionary()->getBakedTextures())
-	{
-		const EBakedTextureIndex baked_index = baked_pair.first;
-		const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
-		
-		for (const ETextureIndex texture_index : baked_dict->mLocalTextures)
-		{
-			const BOOL is_baked_ready = (is_layer_baked[baked_index] && mBakedTextureDatas[baked_index].mIsLoaded) || other_culled;
-			if (isSelf())
-			{
-				setBakedReady(texture_index, is_baked_ready);
-			}
-		}
-	}
-
-	// removeMissingBakedTextures() will call back into this rountine if something is removed, and can blow up the stack
-	static bool call_remove_missing = true;	
-	if (call_remove_missing)
-	{
-		call_remove_missing = false;
-		removeMissingBakedTextures();	// May call back into this function if anything is removed
-		call_remove_missing = true;
-	}
-
-	//refresh bakes on any attached objects
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-
-		for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-		{
-			if (attached_object && !attached_object->isDead())
-			{
-				attached_object->refreshBakeTexture();
-
-				LLViewerObject::const_child_list_t& child_list = attached_object->getChildren();
-				for (LLViewerObject* objectp : child_list)
-				{
-					if (objectp && !objectp->isDead())
-					{
-						objectp->refreshBakeTexture();
-					}
-				}
-			}
-		}
-	}
-
-	
+            }
+            else
+            {
+                mBakedTextureDatas[i].mIsLoaded = FALSE;
+                if ( (baked_img->getID() != IMG_INVISIBLE) &&
+                     ((i == BAKED_HEAD) || (i == BAKED_UPPER) || (i == BAKED_LOWER)) )
+                {
+                    baked_img->setLoadedCallback(onBakedTextureMasksLoaded, MORPH_MASK_REQUESTED_DISCARD, TRUE, TRUE, new LLTextureMaskData( mID ),
+                        src_callback_list, paused);
+                }
+                baked_img->setLoadedCallback(onBakedTextureLoaded, SWITCH_TO_BAKED_DISCARD, FALSE, FALSE, new LLUUID( mID ),
+                    src_callback_list, paused );
+                if (baked_img->getDiscardLevel() < 0 && !paused)
+                {
+                    // mLoadedCallbackTextures will be updated by checkTextureLoading() below
+                    mLastTexCallbackAddedTime.reset();
+                }
+
+                // this could add paused texture callbacks
+                mLoadedCallbacksPaused |= paused;
+                checkTextureLoading();
+            }
+        }
+        else if (layerset && isUsingLocalAppearance())
+        {
+            debugColorizeSubMeshes(i,LLColor4::yellow );
+
+            layerset->createComposite();
+            layerset->setUpdatesEnabled( TRUE );
+            mBakedTextureDatas[i].mIsUsed = FALSE;
+
+            for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
+            {
+                if (mesh)
+                {
+                    mesh->setLayerSet( layerset );
+                }
+            }
+        }
+        else
+        {
+            debugColorizeSubMeshes(i,LLColor4::blue);
+        }
+    }
+
+    // set texture and color of hair manually if we are not using a baked image.
+    // This can happen while loading hair for yourself, or for clients that did not
+    // bake a hair texture. Still needed for yourself after 1.22 is depricated.
+    if (!is_layer_baked[BAKED_HAIR])
+    {
+        const LLColor4 color = mTexHairColor ? mTexHairColor->getColor() : LLColor4(1,1,1,1);
+        LLViewerTexture* hair_img = getImage( TEX_HAIR, 0 );
+        for (LLAvatarJointMesh* mesh : mBakedTextureDatas[BAKED_HAIR].mJointMeshes)
+        {
+            if (mesh)
+            {
+                mesh->setColor( color );
+                mesh->setTexture( hair_img );
+            }
+        }
+    }
+
+
+    for (const auto& baked_pair : LLAvatarAppearance::getDictionary()->getBakedTextures())
+    {
+        const EBakedTextureIndex baked_index = baked_pair.first;
+        const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
+
+        for (const ETextureIndex texture_index : baked_dict->mLocalTextures)
+        {
+            const BOOL is_baked_ready = (is_layer_baked[baked_index] && mBakedTextureDatas[baked_index].mIsLoaded) || other_culled;
+            if (isSelf())
+            {
+                setBakedReady(texture_index, is_baked_ready);
+            }
+        }
+    }
+
+    // removeMissingBakedTextures() will call back into this rountine if something is removed, and can blow up the stack
+    static bool call_remove_missing = true;
+    if (call_remove_missing)
+    {
+        call_remove_missing = false;
+        removeMissingBakedTextures();   // May call back into this function if anything is removed
+        call_remove_missing = true;
+    }
+
+    //refresh bakes on any attached objects
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+
+        for (LLViewerObject* attached_object : attachment->mAttachedObjects)
+        {
+            if (attached_object && !attached_object->isDead())
+            {
+                attached_object->refreshBakeTexture();
+
+                LLViewerObject::const_child_list_t& child_list = attached_object->getChildren();
+                for (LLViewerObject* objectp : child_list)
+                {
+                    if (objectp && !objectp->isDead())
+                    {
+                        objectp->refreshBakeTexture();
+                    }
+                }
+            }
+        }
+    }
+
+
 
 }
 
@@ -9138,88 +9138,88 @@ void LLVOAvatar::updateMeshTextures()
 //-----------------------------------------------------------------------------
 void LLVOAvatar::setLocalTexture( ETextureIndex type, LLViewerTexture* in_tex, BOOL baked_version_ready, U32 index )
 {
-	// invalid for anyone but self
-	llassert(0);
+    // invalid for anyone but self
+    llassert(0);
 }
 
-//virtual 
+//virtual
 void LLVOAvatar::setBakedReady(LLAvatarAppearanceDefines::ETextureIndex type, BOOL baked_version_exists, U32 index)
 {
-	// invalid for anyone but self
-	llassert(0);
+    // invalid for anyone but self
+    llassert(0);
 }
 
 void LLVOAvatar::addChat(const LLChat& chat)
 {
-	mChats.push_back(chat);
+    mChats.push_back(chat);
 
-	S32 chat_length = 0;
-	for(const LLChat& chats : mChats)
-	{
-		chat_length += chats.mText.size();
-	}
+    S32 chat_length = 0;
+    for(const LLChat& chats : mChats)
+    {
+        chat_length += chats.mText.size();
+    }
 
-	// remove any excess chat
-	auto chat_iter = mChats.begin();
-	while ((chat_length > MAX_BUBBLE_CHAT_LENGTH || mChats.size() > MAX_BUBBLE_CHAT_UTTERANCES) && chat_iter != mChats.end())
-	{
-		chat_length -= chat_iter->mText.size();
-		mChats.pop_front();
-		chat_iter = mChats.begin();
-	}
+    // remove any excess chat
+    auto chat_iter = mChats.begin();
+    while ((chat_length > MAX_BUBBLE_CHAT_LENGTH || mChats.size() > MAX_BUBBLE_CHAT_UTTERANCES) && chat_iter != mChats.end())
+    {
+        chat_length -= chat_iter->mText.size();
+        mChats.pop_front();
+        chat_iter = mChats.begin();
+    }
 
-	mChatTimer.reset();
+    mChatTimer.reset();
 }
 
 void LLVOAvatar::clearChat()
 {
-	mChats.clear();
+    mChats.clear();
 }
 
 
 void LLVOAvatar::applyMorphMask(U8* tex_data, S32 width, S32 height, S32 num_components, LLAvatarAppearanceDefines::EBakedTextureIndex index)
 {
-	if (index >= BAKED_NUM_INDICES)
-	{
-		LL_WARNS() << "invalid baked texture index passed to applyMorphMask" << LL_ENDL;
-		return;
-	}
+    if (index >= BAKED_NUM_INDICES)
+    {
+        LL_WARNS() << "invalid baked texture index passed to applyMorphMask" << LL_ENDL;
+        return;
+    }
 
-	for (const LLMaskedMorph* maskedMorph : mBakedTextureDatas[index].mMaskedMorphs)
-	{
-		LLPolyMorphTarget* morph_target = dynamic_cast<LLPolyMorphTarget*>(maskedMorph->mMorphTarget);
-		if (morph_target)
-		{
-			morph_target->applyMask(tex_data, width, height, num_components, maskedMorph->mInvert);
-		}
-	}
+    for (const LLMaskedMorph* maskedMorph : mBakedTextureDatas[index].mMaskedMorphs)
+    {
+        LLPolyMorphTarget* morph_target = dynamic_cast<LLPolyMorphTarget*>(maskedMorph->mMorphTarget);
+        if (morph_target)
+        {
+            morph_target->applyMask(tex_data, width, height, num_components, maskedMorph->mInvert);
+        }
+    }
 }
 
 // returns TRUE if morph masks are present and not valid for a given baked texture, FALSE otherwise
 BOOL LLVOAvatar::morphMaskNeedsUpdate(LLAvatarAppearanceDefines::EBakedTextureIndex index)
 {
-	if (index >= BAKED_NUM_INDICES)
-	{
-		return FALSE;
-	}
+    if (index >= BAKED_NUM_INDICES)
+    {
+        return FALSE;
+    }
 
-	if (!mBakedTextureDatas[index].mMaskedMorphs.empty())
-	{
-		if (isSelf())
-		{
-			LLViewerTexLayerSet *layer_set = getTexLayerSet(index);
-			if (layer_set)
-			{
-				return !layer_set->isMorphValid();
-			}
-		}
-		else
-		{
-			return FALSE;
-		}
-	}
+    if (!mBakedTextureDatas[index].mMaskedMorphs.empty())
+    {
+        if (isSelf())
+        {
+            LLViewerTexLayerSet *layer_set = getTexLayerSet(index);
+            if (layer_set)
+            {
+                return !layer_set->isMorphValid();
+            }
+        }
+        else
+        {
+            return FALSE;
+        }
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 //-----------------------------------------------------------------------------
@@ -9231,64 +9231,64 @@ BOOL LLVOAvatar::morphMaskNeedsUpdate(LLAvatarAppearanceDefines::EBakedTextureIn
 //-----------------------------------------------------------------------------
 void LLVOAvatar::releaseComponentTextures()
 {
-	// ! BACKWARDS COMPATIBILITY !
-	// Detect if the baked hair texture actually wasn't sent, and if so set to default
-	if (isTextureDefined(TEX_HAIR_BAKED) && getImage(TEX_HAIR_BAKED,0)->getID() == getImage(TEX_SKIRT_BAKED,0)->getID())
-	{
-		if (getImage(TEX_HAIR_BAKED,0)->getID() != IMG_INVISIBLE)
-		{
-			// Regression case of messaging system. Expected 21 textures, received 20. last texture is not valid so set to default
-			setTETexture(TEX_HAIR_BAKED, IMG_DEFAULT_AVATAR);
-		}
-	}
-
-	for (U8 baked_index = 0; baked_index < BAKED_NUM_INDICES; baked_index++)
-	{
-		const LLAvatarAppearanceDictionary::BakedEntry * bakedDicEntry = LLAvatarAppearance::getDictionary()->getBakedTexture((EBakedTextureIndex)baked_index);
-		// skip if this is a skirt and av is not wearing one, or if we don't have a baked texture UUID
-		if (!isTextureDefined(bakedDicEntry->mTextureIndex)
-			&& ( (baked_index != BAKED_SKIRT) || isWearingWearableType(LLWearableType::WT_SKIRT) ))
-		{
-			continue;
-		}
-
-		for (U8 texture = 0; texture < bakedDicEntry->mLocalTextures.size(); texture++)
-		{
-			const U8 te = (ETextureIndex)bakedDicEntry->mLocalTextures[texture];
-			setTETexture(te, IMG_DEFAULT_AVATAR);
-		}
-	}
+    // ! BACKWARDS COMPATIBILITY !
+    // Detect if the baked hair texture actually wasn't sent, and if so set to default
+    if (isTextureDefined(TEX_HAIR_BAKED) && getImage(TEX_HAIR_BAKED,0)->getID() == getImage(TEX_SKIRT_BAKED,0)->getID())
+    {
+        if (getImage(TEX_HAIR_BAKED,0)->getID() != IMG_INVISIBLE)
+        {
+            // Regression case of messaging system. Expected 21 textures, received 20. last texture is not valid so set to default
+            setTETexture(TEX_HAIR_BAKED, IMG_DEFAULT_AVATAR);
+        }
+    }
+
+    for (U8 baked_index = 0; baked_index < BAKED_NUM_INDICES; baked_index++)
+    {
+        const LLAvatarAppearanceDictionary::BakedEntry * bakedDicEntry = LLAvatarAppearance::getDictionary()->getBakedTexture((EBakedTextureIndex)baked_index);
+        // skip if this is a skirt and av is not wearing one, or if we don't have a baked texture UUID
+        if (!isTextureDefined(bakedDicEntry->mTextureIndex)
+            && ( (baked_index != BAKED_SKIRT) || isWearingWearableType(LLWearableType::WT_SKIRT) ))
+        {
+            continue;
+        }
+
+        for (U8 texture = 0; texture < bakedDicEntry->mLocalTextures.size(); texture++)
+        {
+            const U8 te = (ETextureIndex)bakedDicEntry->mLocalTextures[texture];
+            setTETexture(te, IMG_DEFAULT_AVATAR);
+        }
+    }
 }
 
 void LLVOAvatar::dumpAvatarTEs( const std::string& context ) const
-{	
-	LL_DEBUGS("Avatar") << avString() << (isSelf() ? "Self: " : "Other: ") << context << LL_ENDL;
-	for (const auto& tex_pair : LLAvatarAppearance::getDictionary()->getTextures())
-	{
-		const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
-		// TODO: MULTI-WEARABLE: handle multiple textures for self
-		const LLViewerTexture* te_image = getImage(tex_pair.first,0);
-		if( !te_image )
-		{
-			LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": null ptr" << LL_ENDL;
-		}
-		else if( te_image->getID().isNull() )
-		{
-			LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": null UUID" << LL_ENDL;
-		}
-		else if( te_image->getID() == IMG_DEFAULT )
-		{
-			LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": IMG_DEFAULT" << LL_ENDL;
-		}
-		else if( te_image->getID() == IMG_DEFAULT_AVATAR )
-		{
-			LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": IMG_DEFAULT_AVATAR" << LL_ENDL;
-		}
-		else
-		{
-			LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": " << te_image->getID() << LL_ENDL;
-		}
-	}
+{
+    LL_DEBUGS("Avatar") << avString() << (isSelf() ? "Self: " : "Other: ") << context << LL_ENDL;
+    for (const auto& tex_pair : LLAvatarAppearance::getDictionary()->getTextures())
+    {
+        const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
+        // TODO: MULTI-WEARABLE: handle multiple textures for self
+        const LLViewerTexture* te_image = getImage(tex_pair.first,0);
+        if( !te_image )
+        {
+            LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": null ptr" << LL_ENDL;
+        }
+        else if( te_image->getID().isNull() )
+        {
+            LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": null UUID" << LL_ENDL;
+        }
+        else if( te_image->getID() == IMG_DEFAULT )
+        {
+            LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": IMG_DEFAULT" << LL_ENDL;
+        }
+        else if( te_image->getID() == IMG_DEFAULT_AVATAR )
+        {
+            LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": IMG_DEFAULT_AVATAR" << LL_ENDL;
+        }
+        else
+        {
+            LL_DEBUGS("Avatar") << avString() << "       " << texture_dict->mName << ": " << te_image->getID() << LL_ENDL;
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -9296,63 +9296,63 @@ void LLVOAvatar::dumpAvatarTEs( const std::string& context ) const
 //-----------------------------------------------------------------------------
 void LLVOAvatar::clampAttachmentPositions()
 {
-	if (isDead())
-	{
-		return;
-	}
+    if (isDead())
+    {
+        return;
+    }
 
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		if (attachment)
-		{
-			attachment->clampObjectPosition();
-		}
-	}
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        if (attachment)
+        {
+            attachment->clampObjectPosition();
+        }
+    }
 }
 
 BOOL LLVOAvatar::hasHUDAttachment() const
 {
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		if (attachment && attachment->getIsHUDAttachment() && attachment->getNumObjects() > 0)
-		{
-			return TRUE;
-		}
-	}
-	return FALSE;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        if (attachment && attachment->getIsHUDAttachment() && attachment->getNumObjects() > 0)
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 LLBBox LLVOAvatar::getHUDBBox() const
 {
-	LLBBox bbox;
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		if (attachment && attachment->getIsHUDAttachment())
-		{
-			for (const LLViewerObject* attached_object : attachment->mAttachedObjects)
-			{
-				if (attached_object == NULL)
-				{
-					LL_WARNS() << "HUD attached object is NULL!" << LL_ENDL;
-					continue;
-				}
-				// initialize bounding box to contain identity orientation and center point for attached object
-				bbox.addPointLocal(attached_object->getPosition());
-				// add rotated bounding box for attached object
-				bbox.addBBoxAgent(attached_object->getBoundingBoxAgent());
-				LLViewerObject::const_child_list_t& child_list = attached_object->getChildren();
-				for (const LLViewerObject* child_objectp : child_list)
-				{
-					bbox.addBBoxAgent(child_objectp->getBoundingBoxAgent());
-				}
-			}
-		}
-	}
-
-	return bbox;
+    LLBBox bbox;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        if (attachment && attachment->getIsHUDAttachment())
+        {
+            for (const LLViewerObject* attached_object : attachment->mAttachedObjects)
+            {
+                if (attached_object == NULL)
+                {
+                    LL_WARNS() << "HUD attached object is NULL!" << LL_ENDL;
+                    continue;
+                }
+                // initialize bounding box to contain identity orientation and center point for attached object
+                bbox.addPointLocal(attached_object->getPosition());
+                // add rotated bounding box for attached object
+                bbox.addBBoxAgent(attached_object->getBoundingBoxAgent());
+                LLViewerObject::const_child_list_t& child_list = attached_object->getChildren();
+                for (const LLViewerObject* child_objectp : child_list)
+                {
+                    bbox.addBBoxAgent(child_objectp->getBoundingBoxAgent());
+                }
+            }
+        }
+    }
+
+    return bbox;
 }
 
 //-----------------------------------------------------------------------------
@@ -9360,53 +9360,53 @@ LLBBox LLVOAvatar::getHUDBBox() const
 //-----------------------------------------------------------------------------
 void LLVOAvatar::onFirstTEMessageReceived()
 {
-	LL_DEBUGS("Avatar") << avString() << LL_ENDL;
-	if( !mFirstTEMessageReceived )
-	{
-		mFirstTEMessageReceived = TRUE;
-
-		LLLoadedCallbackEntry::source_callback_list_t* src_callback_list = NULL ;
-		BOOL paused = FALSE ;
-		if(!isSelf())
-		{
-			src_callback_list = &mCallbackTextureList ;
-			paused = !isVisible();
-		}
-
-		for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-		{
-			const BOOL layer_baked = isTextureDefined(mBakedTextureDatas[i].mTextureIndex);
-
-			// Use any baked textures that we have even if they haven't downloaded yet.
-			// (That is, don't do a transition from unbaked to baked.)
-			if (layer_baked)
-			{
-				LLViewerFetchedTexture* image = LLViewerTextureManager::staticCastToFetchedTexture(getImage( mBakedTextureDatas[i].mTextureIndex, 0 ), TRUE) ;
-				mBakedTextureDatas[i].mLastTextureID = image->getID();
-				// If we have more than one texture for the other baked layers, we'll want to call this for them too.
-				if ( (image->getID() != IMG_INVISIBLE) && ((i == BAKED_HEAD) || (i == BAKED_UPPER) || (i == BAKED_LOWER)) )
-				{
-					image->setLoadedCallback( onBakedTextureMasksLoaded, MORPH_MASK_REQUESTED_DISCARD, TRUE, TRUE, new LLTextureMaskData( mID ), 
-						src_callback_list, paused);
-				}
-				LL_DEBUGS("Avatar") << avString() << "layer_baked, setting onInitialBakedTextureLoaded as callback" << LL_ENDL;
-				image->setLoadedCallback( onInitialBakedTextureLoaded, MAX_DISCARD_LEVEL, FALSE, FALSE, new LLUUID( mID ), 
-					src_callback_list, paused );
-				if (image->getDiscardLevel() < 0 && !paused)
-				{
-					mLastTexCallbackAddedTime.reset();
-				}
+    LL_DEBUGS("Avatar") << avString() << LL_ENDL;
+    if( !mFirstTEMessageReceived )
+    {
+        mFirstTEMessageReceived = TRUE;
+
+        LLLoadedCallbackEntry::source_callback_list_t* src_callback_list = NULL ;
+        BOOL paused = FALSE ;
+        if(!isSelf())
+        {
+            src_callback_list = &mCallbackTextureList ;
+            paused = !isVisible();
+        }
+
+        for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+        {
+            const BOOL layer_baked = isTextureDefined(mBakedTextureDatas[i].mTextureIndex);
+
+            // Use any baked textures that we have even if they haven't downloaded yet.
+            // (That is, don't do a transition from unbaked to baked.)
+            if (layer_baked)
+            {
+                LLViewerFetchedTexture* image = LLViewerTextureManager::staticCastToFetchedTexture(getImage( mBakedTextureDatas[i].mTextureIndex, 0 ), TRUE) ;
+                mBakedTextureDatas[i].mLastTextureID = image->getID();
+                // If we have more than one texture for the other baked layers, we'll want to call this for them too.
+                if ( (image->getID() != IMG_INVISIBLE) && ((i == BAKED_HEAD) || (i == BAKED_UPPER) || (i == BAKED_LOWER)) )
+                {
+                    image->setLoadedCallback( onBakedTextureMasksLoaded, MORPH_MASK_REQUESTED_DISCARD, TRUE, TRUE, new LLTextureMaskData( mID ),
+                        src_callback_list, paused);
+                }
+                LL_DEBUGS("Avatar") << avString() << "layer_baked, setting onInitialBakedTextureLoaded as callback" << LL_ENDL;
+                image->setLoadedCallback( onInitialBakedTextureLoaded, MAX_DISCARD_LEVEL, FALSE, FALSE, new LLUUID( mID ),
+                    src_callback_list, paused );
+                if (image->getDiscardLevel() < 0 && !paused)
+                {
+                    mLastTexCallbackAddedTime.reset();
+                }
                                // this could add paused texture callbacks
-                               mLoadedCallbacksPaused |= paused; 
-			}
-		}
+                               mLoadedCallbacksPaused |= paused;
+            }
+        }
 
         mMeshTexturesDirty = TRUE;
-		gPipeline.markGLRebuild(this);
+        gPipeline.markGLRebuild(this);
 
         mFirstAppearanceMessageTimer.reset();
         mFullyLoadedTimer.reset();
-	}
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -9414,231 +9414,231 @@ void LLVOAvatar::onFirstTEMessageReceived()
 //-----------------------------------------------------------------------------
 bool LLVOAvatar::visualParamWeightsAreDefault()
 {
-	bool rtn = true;
-
-	bool is_wearing_skirt = isWearingWearableType(LLWearableType::WT_SKIRT);
-	for (LLVisualParam *param = getFirstVisualParam(); 
-	     param;
-	     param = getNextVisualParam())
-	{
-		if (param->isTweakable())
-		{
-			LLViewerVisualParam* vparam = dynamic_cast<LLViewerVisualParam*>(param);
-			llassert(vparam);
-			bool is_skirt_param = vparam &&
-				LLWearableType::WT_SKIRT == vparam->getWearableType();
-			if (param->getWeight() != param->getDefaultWeight() &&
-			    // we have to not care whether skirt weights are default, if we're not actually wearing a skirt
-			    (is_wearing_skirt || !is_skirt_param))
-			{
-				//LL_INFOS() << "param '" << param->getName() << "'=" << param->getWeight() << " which differs from default=" << param->getDefaultWeight() << LL_ENDL;
-				rtn = false;
-				break;
-			}
-		}
-	}
-
-	//LL_INFOS() << "params are default ? " << int(rtn) << LL_ENDL;
-
-	return rtn;
+    bool rtn = true;
+
+    bool is_wearing_skirt = isWearingWearableType(LLWearableType::WT_SKIRT);
+    for (LLVisualParam *param = getFirstVisualParam();
+         param;
+         param = getNextVisualParam())
+    {
+        if (param->isTweakable())
+        {
+            LLViewerVisualParam* vparam = dynamic_cast<LLViewerVisualParam*>(param);
+            llassert(vparam);
+            bool is_skirt_param = vparam &&
+                LLWearableType::WT_SKIRT == vparam->getWearableType();
+            if (param->getWeight() != param->getDefaultWeight() &&
+                // we have to not care whether skirt weights are default, if we're not actually wearing a skirt
+                (is_wearing_skirt || !is_skirt_param))
+            {
+                //LL_INFOS() << "param '" << param->getName() << "'=" << param->getWeight() << " which differs from default=" << param->getDefaultWeight() << LL_ENDL;
+                rtn = false;
+                break;
+            }
+        }
+    }
+
+    //LL_INFOS() << "params are default ? " << int(rtn) << LL_ENDL;
+
+    return rtn;
 }
 
 void dump_visual_param(apr_file_t* file, LLVisualParam* viewer_param, F32 value)
 {
-	std::string type_string = "unknown";
-	if (dynamic_cast<LLTexLayerParamAlpha*>(viewer_param))
-		type_string = "param_alpha";
-	if (dynamic_cast<LLTexLayerParamColor*>(viewer_param))
-		type_string = "param_color";
-	if (dynamic_cast<LLDriverParam*>(viewer_param))
-		type_string = "param_driver";
-	if (dynamic_cast<LLPolyMorphTarget*>(viewer_param))
-		type_string = "param_morph";
-	if (dynamic_cast<LLPolySkeletalDistortion*>(viewer_param))
-		type_string = "param_skeleton";
-	S32 wtype = -1;
-	LLViewerVisualParam *vparam = dynamic_cast<LLViewerVisualParam*>(viewer_param);
-	if (vparam)
-	{
-		wtype = vparam->getWearableType();
-	}
-	S32 u8_value = F32_to_U8(value,viewer_param->getMinWeight(),viewer_param->getMaxWeight());
-	apr_file_printf(file, "\t\t<param id=\"%d\" name=\"%s\" display=\"%s\" value=\"%.3f\" u8=\"%d\" type=\"%s\" wearable=\"%s\" group=\"%d\"/>\n",
-					viewer_param->getID(), viewer_param->getName().c_str(), viewer_param->getDisplayName().c_str(), value, u8_value, type_string.c_str(),
-					LLWearableType::getInstance()->getTypeName(LLWearableType::EType(wtype)).c_str(),
-					viewer_param->getGroup());
-	}
-	
+    std::string type_string = "unknown";
+    if (dynamic_cast<LLTexLayerParamAlpha*>(viewer_param))
+        type_string = "param_alpha";
+    if (dynamic_cast<LLTexLayerParamColor*>(viewer_param))
+        type_string = "param_color";
+    if (dynamic_cast<LLDriverParam*>(viewer_param))
+        type_string = "param_driver";
+    if (dynamic_cast<LLPolyMorphTarget*>(viewer_param))
+        type_string = "param_morph";
+    if (dynamic_cast<LLPolySkeletalDistortion*>(viewer_param))
+        type_string = "param_skeleton";
+    S32 wtype = -1;
+    LLViewerVisualParam *vparam = dynamic_cast<LLViewerVisualParam*>(viewer_param);
+    if (vparam)
+    {
+        wtype = vparam->getWearableType();
+    }
+    S32 u8_value = F32_to_U8(value,viewer_param->getMinWeight(),viewer_param->getMaxWeight());
+    apr_file_printf(file, "\t\t<param id=\"%d\" name=\"%s\" display=\"%s\" value=\"%.3f\" u8=\"%d\" type=\"%s\" wearable=\"%s\" group=\"%d\"/>\n",
+                    viewer_param->getID(), viewer_param->getName().c_str(), viewer_param->getDisplayName().c_str(), value, u8_value, type_string.c_str(),
+                    LLWearableType::getInstance()->getTypeName(LLWearableType::EType(wtype)).c_str(),
+                    viewer_param->getGroup());
+    }
+
 
 void LLVOAvatar::dumpAppearanceMsgParams( const std::string& dump_prefix,
-	const LLAppearanceMessageContents& contents)
-{
-	std::string outfilename = get_sequential_numbered_file_name(dump_prefix,".xml");
-	const std::vector<F32>& params_for_dump = contents.mParamWeights;
-	const LLTEContents& tec = contents.mTEContents;
-
-	LLAPRFile outfile;
-	std::string fullpath = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,outfilename);
-	outfile.open(fullpath, LL_APR_WB );
-	apr_file_t* file = outfile.getFileHandle();
-	if (!file)
-	{
-		return;
-	}
-	else
-	{
-		LL_DEBUGS("Avatar") << "dumping appearance message to " << fullpath << LL_ENDL;
-	}
-
-	apr_file_printf(file, "<header>\n");
-	apr_file_printf(file, "\t\t<cof_version %i />\n", contents.mCOFVersion);
-	apr_file_printf(file, "\t\t<appearance_version %i />\n", contents.mAppearanceVersion);
-	apr_file_printf(file, "</header>\n");
-
-	apr_file_printf(file, "\n<params>\n");
-	LLVisualParam* param = getFirstVisualParam();
-	for (S32 i = 0; i < params_for_dump.size(); i++)
-	{
-		while( param && ((param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE) && 
-						 (param->getGroup() != VISUAL_PARAM_GROUP_TRANSMIT_NOT_TWEAKABLE)) ) // should not be any of group VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
-		{
-			param = getNextVisualParam();
-		}
-		LLViewerVisualParam* viewer_param = (LLViewerVisualParam*)param;
-		F32 value = params_for_dump[i];
-		dump_visual_param(file, viewer_param, value);
-		param = getNextVisualParam();
-	}
-	apr_file_printf(file, "</params>\n");
-
-	apr_file_printf(file, "\n<textures>\n");
-	for (U32 i = 0; i < tec.face_count; i++)
-	{
-		std::string uuid_str;
-		((LLUUID*)tec.image_data)[i].toString(uuid_str);
-		apr_file_printf( file, "\t\t<texture te=\"%i\" uuid=\"%s\"/>\n", i, uuid_str.c_str());
-	}
-	apr_file_printf(file, "</textures>\n");
+    const LLAppearanceMessageContents& contents)
+{
+    std::string outfilename = get_sequential_numbered_file_name(dump_prefix,".xml");
+    const std::vector<F32>& params_for_dump = contents.mParamWeights;
+    const LLTEContents& tec = contents.mTEContents;
+
+    LLAPRFile outfile;
+    std::string fullpath = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,outfilename);
+    outfile.open(fullpath, LL_APR_WB );
+    apr_file_t* file = outfile.getFileHandle();
+    if (!file)
+    {
+        return;
+    }
+    else
+    {
+        LL_DEBUGS("Avatar") << "dumping appearance message to " << fullpath << LL_ENDL;
+    }
+
+    apr_file_printf(file, "<header>\n");
+    apr_file_printf(file, "\t\t<cof_version %i />\n", contents.mCOFVersion);
+    apr_file_printf(file, "\t\t<appearance_version %i />\n", contents.mAppearanceVersion);
+    apr_file_printf(file, "</header>\n");
+
+    apr_file_printf(file, "\n<params>\n");
+    LLVisualParam* param = getFirstVisualParam();
+    for (S32 i = 0; i < params_for_dump.size(); i++)
+    {
+        while( param && ((param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE) &&
+                         (param->getGroup() != VISUAL_PARAM_GROUP_TRANSMIT_NOT_TWEAKABLE)) ) // should not be any of group VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
+        {
+            param = getNextVisualParam();
+        }
+        LLViewerVisualParam* viewer_param = (LLViewerVisualParam*)param;
+        F32 value = params_for_dump[i];
+        dump_visual_param(file, viewer_param, value);
+        param = getNextVisualParam();
+    }
+    apr_file_printf(file, "</params>\n");
+
+    apr_file_printf(file, "\n<textures>\n");
+    for (U32 i = 0; i < tec.face_count; i++)
+    {
+        std::string uuid_str;
+        ((LLUUID*)tec.image_data)[i].toString(uuid_str);
+        apr_file_printf( file, "\t\t<texture te=\"%i\" uuid=\"%s\"/>\n", i, uuid_str.c_str());
+    }
+    apr_file_printf(file, "</textures>\n");
 }
 
 void LLVOAvatar::parseAppearanceMessage(LLMessageSystem* mesgsys, LLAppearanceMessageContents& contents)
 {
-	parseTEMessage(mesgsys, _PREHASH_ObjectData, -1, contents.mTEContents);
-
-	// Parse the AppearanceData field, if any.
-	if (mesgsys->has(_PREHASH_AppearanceData))
-	{
-		U8 av_u8;
-		mesgsys->getU8Fast(_PREHASH_AppearanceData, _PREHASH_AppearanceVersion, av_u8, 0);
-		contents.mAppearanceVersion = av_u8;
-		//LL_DEBUGS("Avatar") << "appversion set by AppearanceData field: " << contents.mAppearanceVersion << LL_ENDL;
-		mesgsys->getS32Fast(_PREHASH_AppearanceData, _PREHASH_CofVersion, contents.mCOFVersion, 0);
-		// For future use:
-		//mesgsys->getU32Fast(_PREHASH_AppearanceData, _PREHASH_Flags, appearance_flags, 0);
-	}
-
-	// Parse the AppearanceData field, if any.
-	contents.mHoverOffsetWasSet = false;
-	if (mesgsys->has(_PREHASH_AppearanceHover))
-	{
-		LLVector3 hover;
-		mesgsys->getVector3Fast(_PREHASH_AppearanceHover, _PREHASH_HoverHeight, hover);
-		//LL_DEBUGS("Avatar") << avString() << " hover received " << hover.mV[ VX ] << "," << hover.mV[ VY ] << "," << hover.mV[ VZ ] << LL_ENDL;
-		contents.mHoverOffset = hover;
-		contents.mHoverOffsetWasSet = true;
-	}
-	
-	// Parse visual params, if any.
-	S32 num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_VisualParam);
+    parseTEMessage(mesgsys, _PREHASH_ObjectData, -1, contents.mTEContents);
+
+    // Parse the AppearanceData field, if any.
+    if (mesgsys->has(_PREHASH_AppearanceData))
+    {
+        U8 av_u8;
+        mesgsys->getU8Fast(_PREHASH_AppearanceData, _PREHASH_AppearanceVersion, av_u8, 0);
+        contents.mAppearanceVersion = av_u8;
+        //LL_DEBUGS("Avatar") << "appversion set by AppearanceData field: " << contents.mAppearanceVersion << LL_ENDL;
+        mesgsys->getS32Fast(_PREHASH_AppearanceData, _PREHASH_CofVersion, contents.mCOFVersion, 0);
+        // For future use:
+        //mesgsys->getU32Fast(_PREHASH_AppearanceData, _PREHASH_Flags, appearance_flags, 0);
+    }
+
+    // Parse the AppearanceData field, if any.
+    contents.mHoverOffsetWasSet = false;
+    if (mesgsys->has(_PREHASH_AppearanceHover))
+    {
+        LLVector3 hover;
+        mesgsys->getVector3Fast(_PREHASH_AppearanceHover, _PREHASH_HoverHeight, hover);
+        //LL_DEBUGS("Avatar") << avString() << " hover received " << hover.mV[ VX ] << "," << hover.mV[ VY ] << "," << hover.mV[ VZ ] << LL_ENDL;
+        contents.mHoverOffset = hover;
+        contents.mHoverOffsetWasSet = true;
+    }
+
+    // Parse visual params, if any.
+    S32 num_blocks = mesgsys->getNumberOfBlocksFast(_PREHASH_VisualParam);
     if( num_blocks > 1)
-	{
-		//LL_DEBUGS("Avatar") << avString() << " handle visual params, num_blocks " << num_blocks << LL_ENDL;
-		
-		LLVisualParam* param = getFirstVisualParam();
-		llassert(param); // if this ever fires, we should do the same as when num_blocks<=1
-		if (!param)
-		{
-			LL_WARNS() << "No visual params!" << LL_ENDL;
-		}
-		else
-		{
-			for( S32 i = 0; i < num_blocks; i++ )
-			{
-				while( param && ((param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE) && 
-								 (param->getGroup() != VISUAL_PARAM_GROUP_TRANSMIT_NOT_TWEAKABLE)) ) // should not be any of group VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
-				{
-					param = getNextVisualParam();
-				}
-						
-				if( !param )
-				{
-					// more visual params supplied than expected - just process what we know about
-					break;
-				}
-
-				U8 value;
-				mesgsys->getU8Fast(_PREHASH_VisualParam, _PREHASH_ParamValue, value, i);
-				F32 newWeight = U8_to_F32(value, param->getMinWeight(), param->getMaxWeight());
-				contents.mParamWeights.push_back(newWeight);
-				contents.mParams.push_back(param);
-
-				param = getNextVisualParam();
-			}
-		}
-
-		const S32 expected_tweakable_count = getVisualParamCountInGroup(VISUAL_PARAM_GROUP_TWEAKABLE) +
-											 getVisualParamCountInGroup(VISUAL_PARAM_GROUP_TRANSMIT_NOT_TWEAKABLE); // don't worry about VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
-		if (num_blocks != expected_tweakable_count)
-		{
-			LL_DEBUGS("Avatar") << "Number of params in AvatarAppearance msg (" << num_blocks << ") does not match number of tweakable params in avatar xml file (" << expected_tweakable_count << ").  Processing what we can.  object: " << getID() << LL_ENDL;
-		}
-	}
-	else
-	{
-			LL_DEBUGS("Avatar") << "AvatarAppearance msg received without any parameters, object: " << getID() << LL_ENDL;
-		}
-
-	LLVisualParam* appearance_version_param = getVisualParam(11000);
-	if (appearance_version_param)
-	{
-		std::vector<LLVisualParam*>::iterator it = std::find(contents.mParams.begin(), contents.mParams.end(),appearance_version_param);
-		if (it != contents.mParams.end())
-		{
-			S32 index = it - contents.mParams.begin();
-			contents.mParamAppearanceVersion = ll_round(contents.mParamWeights[index]);
-			//LL_DEBUGS("Avatar") << "appversion req by appearance_version param: " << contents.mParamAppearanceVersion << LL_ENDL;
-		}
-	}
+    {
+        //LL_DEBUGS("Avatar") << avString() << " handle visual params, num_blocks " << num_blocks << LL_ENDL;
+
+        LLVisualParam* param = getFirstVisualParam();
+        llassert(param); // if this ever fires, we should do the same as when num_blocks<=1
+        if (!param)
+        {
+            LL_WARNS() << "No visual params!" << LL_ENDL;
+        }
+        else
+        {
+            for( S32 i = 0; i < num_blocks; i++ )
+            {
+                while( param && ((param->getGroup() != VISUAL_PARAM_GROUP_TWEAKABLE) &&
+                                 (param->getGroup() != VISUAL_PARAM_GROUP_TRANSMIT_NOT_TWEAKABLE)) ) // should not be any of group VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
+                {
+                    param = getNextVisualParam();
+                }
+
+                if( !param )
+                {
+                    // more visual params supplied than expected - just process what we know about
+                    break;
+                }
+
+                U8 value;
+                mesgsys->getU8Fast(_PREHASH_VisualParam, _PREHASH_ParamValue, value, i);
+                F32 newWeight = U8_to_F32(value, param->getMinWeight(), param->getMaxWeight());
+                contents.mParamWeights.push_back(newWeight);
+                contents.mParams.push_back(param);
+
+                param = getNextVisualParam();
+            }
+        }
+
+        const S32 expected_tweakable_count = getVisualParamCountInGroup(VISUAL_PARAM_GROUP_TWEAKABLE) +
+                                             getVisualParamCountInGroup(VISUAL_PARAM_GROUP_TRANSMIT_NOT_TWEAKABLE); // don't worry about VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
+        if (num_blocks != expected_tweakable_count)
+        {
+            LL_DEBUGS("Avatar") << "Number of params in AvatarAppearance msg (" << num_blocks << ") does not match number of tweakable params in avatar xml file (" << expected_tweakable_count << ").  Processing what we can.  object: " << getID() << LL_ENDL;
+        }
+    }
+    else
+    {
+            LL_DEBUGS("Avatar") << "AvatarAppearance msg received without any parameters, object: " << getID() << LL_ENDL;
+        }
+
+    LLVisualParam* appearance_version_param = getVisualParam(11000);
+    if (appearance_version_param)
+    {
+        std::vector<LLVisualParam*>::iterator it = std::find(contents.mParams.begin(), contents.mParams.end(),appearance_version_param);
+        if (it != contents.mParams.end())
+        {
+            S32 index = it - contents.mParams.begin();
+            contents.mParamAppearanceVersion = ll_round(contents.mParamWeights[index]);
+            //LL_DEBUGS("Avatar") << "appversion req by appearance_version param: " << contents.mParamAppearanceVersion << LL_ENDL;
+        }
+    }
 }
 
 bool resolve_appearance_version(const LLAppearanceMessageContents& contents, S32& appearance_version)
 {
-	appearance_version = -1;
-	
-	if ((contents.mAppearanceVersion) >= 0 &&
-		(contents.mParamAppearanceVersion >= 0) &&
-		(contents.mAppearanceVersion != contents.mParamAppearanceVersion))
-	{
-		LL_WARNS() << "inconsistent appearance_version settings - field: " <<
-			contents.mAppearanceVersion << ", param: " <<  contents.mParamAppearanceVersion << LL_ENDL;
-		return false;
-	}
-	if (contents.mParamAppearanceVersion >= 0) // use visual param if available.
-	{
-		appearance_version = contents.mParamAppearanceVersion;
-	}
-	else if (contents.mAppearanceVersion > 0)
-	{
-		appearance_version = contents.mAppearanceVersion;
-	}
-	else // still not set, go with 1.
-	{
-		appearance_version = 1;
-	}
-	//LL_DEBUGS("Avatar") << "appearance version info - field " << contents.mAppearanceVersion
-	//					<< " param: " << contents.mParamAppearanceVersion
-	//					<< " final: " << appearance_version << LL_ENDL;
-	return true;
+    appearance_version = -1;
+
+    if ((contents.mAppearanceVersion) >= 0 &&
+        (contents.mParamAppearanceVersion >= 0) &&
+        (contents.mAppearanceVersion != contents.mParamAppearanceVersion))
+    {
+        LL_WARNS() << "inconsistent appearance_version settings - field: " <<
+            contents.mAppearanceVersion << ", param: " <<  contents.mParamAppearanceVersion << LL_ENDL;
+        return false;
+    }
+    if (contents.mParamAppearanceVersion >= 0) // use visual param if available.
+    {
+        appearance_version = contents.mParamAppearanceVersion;
+    }
+    else if (contents.mAppearanceVersion > 0)
+    {
+        appearance_version = contents.mAppearanceVersion;
+    }
+    else // still not set, go with 1.
+    {
+        appearance_version = 1;
+    }
+    //LL_DEBUGS("Avatar") << "appearance version info - field " << contents.mAppearanceVersion
+    //                  << " param: " << contents.mParamAppearanceVersion
+    //                  << " final: " << appearance_version << LL_ENDL;
+    return true;
 }
 
 //-----------------------------------------------------------------------------
@@ -9646,46 +9646,46 @@ bool resolve_appearance_version(const LLAppearanceMessageContents& contents, S32
 //-----------------------------------------------------------------------------
 void LLVOAvatar::processAvatarAppearance( LLMessageSystem* mesgsys )
 {
-	LL_DEBUGS("Avatar") << "starts" << LL_ENDL;
+    LL_DEBUGS("Avatar") << "starts" << LL_ENDL;
 
     static LLCachedControl<bool> enable_verbose_dumps(gSavedSettings, "DebugAvatarAppearanceMessage");
     static LLCachedControl<bool> block_avatar_appearance_messages(gSavedSettings, "BlockAvatarAppearanceMessages");
 
-	std::string dump_prefix = getFullname() + "_" + (isSelf()?"s":"o") + "_";
-	if (block_avatar_appearance_messages)
-	{
-		LL_WARNS() << "Blocking AvatarAppearance message" << LL_ENDL;
-		return;
-	}
-
-	mLastAppearanceMessageTimer.reset();
-
-	LLPointer<LLAppearanceMessageContents> contents(new LLAppearanceMessageContents);
-	parseAppearanceMessage(mesgsys, *contents);
-	if (enable_verbose_dumps)
-	{
-		dumpAppearanceMsgParams(dump_prefix + "appearance_msg", *contents);
-	}
-
-	S32 appearance_version;
-	if (!resolve_appearance_version(*contents, appearance_version))
-	{
-		LL_WARNS() << "bad appearance version info, discarding" << LL_ENDL;
-		return;
-	}
-	llassert(appearance_version > 0);
-	if (appearance_version > 1)
-	{
-		LL_WARNS() << "unsupported appearance version " << appearance_version << ", discarding appearance message" << LL_ENDL;
-		return;
-	}
+    std::string dump_prefix = getFullname() + "_" + (isSelf()?"s":"o") + "_";
+    if (block_avatar_appearance_messages)
+    {
+        LL_WARNS() << "Blocking AvatarAppearance message" << LL_ENDL;
+        return;
+    }
+
+    mLastAppearanceMessageTimer.reset();
+
+    LLPointer<LLAppearanceMessageContents> contents(new LLAppearanceMessageContents);
+    parseAppearanceMessage(mesgsys, *contents);
+    if (enable_verbose_dumps)
+    {
+        dumpAppearanceMsgParams(dump_prefix + "appearance_msg", *contents);
+    }
+
+    S32 appearance_version;
+    if (!resolve_appearance_version(*contents, appearance_version))
+    {
+        LL_WARNS() << "bad appearance version info, discarding" << LL_ENDL;
+        return;
+    }
+    llassert(appearance_version > 0);
+    if (appearance_version > 1)
+    {
+        LL_WARNS() << "unsupported appearance version " << appearance_version << ", discarding appearance message" << LL_ENDL;
+        return;
+    }
 
     S32 thisAppearanceVersion(contents->mCOFVersion);
     if (isSelf())
-    {   // In the past this was considered to be the canonical COF version, 
-        // that is no longer the case.  The canonical version is maintained 
+    {   // In the past this was considered to be the canonical COF version,
+        // that is no longer the case.  The canonical version is maintained
         // by the AIS code and should match the COF version there. Even so,
-        // we must prevent rolling this one backwards backwards or processing 
+        // we must prevent rolling this one backwards backwards or processing
         // stale versions.
 
         LL_DEBUGS("Avatar") << "handling self appearance message #" << thisAppearanceVersion <<
@@ -9707,30 +9707,30 @@ void LLVOAvatar::processAvatarAppearance( LLMessageSystem* mesgsys )
 
     }
 
-	// SUNSHINE CLEANUP - is this case OK now?
-	S32 num_params = contents->mParamWeights.size();
-	if (num_params <= 1)
-	{
-		// In this case, we have no reliable basis for knowing
-		// appearance version, which may cause us to look for baked
-		// textures in the wrong place and flag them as missing
-		// assets.
-		if(isSelf() && mLastUpdateReceivedCOFVersion != -1)
-		{
-			LL_INFOS("Avatar") << "Empty appearance for self. Forcing a refresh" << LL_ENDL;
-			LLNotificationsUtil::add("AvatarRezSelfBakeForceUpdateNotification");
-			LLAppearanceMgr::instance().syncCofVersionAndRefresh();
-		}
-		else
-			LL_DEBUGS("Avatar") << "ignoring appearance message due to lack of params" << LL_ENDL;
-		return;
-	}
-
-	// No backsies zone - if we get here, the message should be valid and usable, will be processed.
-	// Note:
-	// RequestAgentUpdateAppearanceResponder::onRequestRequested()
-	// assumes that cof version is only updated with server-bake
-	// appearance messages.
+    // SUNSHINE CLEANUP - is this case OK now?
+    S32 num_params = contents->mParamWeights.size();
+    if (num_params <= 1)
+    {
+        // In this case, we have no reliable basis for knowing
+        // appearance version, which may cause us to look for baked
+        // textures in the wrong place and flag them as missing
+        // assets.
+        if(isSelf() && mLastUpdateReceivedCOFVersion != -1)
+        {
+            LL_INFOS("Avatar") << "Empty appearance for self. Forcing a refresh" << LL_ENDL;
+            LLNotificationsUtil::add("AvatarRezSelfBakeForceUpdateNotification");
+            LLAppearanceMgr::instance().syncCofVersionAndRefresh();
+        }
+        else
+            LL_DEBUGS("Avatar") << "ignoring appearance message due to lack of params" << LL_ENDL;
+        return;
+    }
+
+    // No backsies zone - if we get here, the message should be valid and usable, will be processed.
+    // Note:
+    // RequestAgentUpdateAppearanceResponder::onRequestRequested()
+    // assumes that cof version is only updated with server-bake
+    // appearance messages.
     if (isSelf())
     {
         LL_INFOS("Avatar") << "Processing appearance message version " << thisAppearanceVersion << LL_ENDL;
@@ -9742,210 +9742,210 @@ void LLVOAvatar::processAvatarAppearance( LLMessageSystem* mesgsys )
 
     // Note:
     // locally the COF is maintained via LLInventoryModel::accountForUpdate
-    // which is called from various places.  This should match the simhost's 
+    // which is called from various places.  This should match the simhost's
     // idea of what the COF version is.  AIS however maintains its own version
-    // of the COF that should be considered canonical. 
+    // of the COF that should be considered canonical.
     mLastUpdateReceivedCOFVersion = thisAppearanceVersion;
 
     mLastProcessedAppearance = contents;
 
     bool slam_params = false;
-	applyParsedAppearanceMessage(*contents, slam_params);
-	if (getOverallAppearance() != AOA_NORMAL && !getPosing())
-	{
-		resetSkeleton(false);
-	}
+    applyParsedAppearanceMessage(*contents, slam_params);
+    if (getOverallAppearance() != AOA_NORMAL && !getPosing())
+    {
+        resetSkeleton(false);
+    }
 }
 
 void LLVOAvatar::applyParsedAppearanceMessage(LLAppearanceMessageContents& contents, bool slam_params)
 {
-	S32 num_params = contents.mParamWeights.size();
-	ESex old_sex = getSex();
+    S32 num_params = contents.mParamWeights.size();
+    ESex old_sex = getSex();
 
     if (applyParsedTEMessage(contents.mTEContents) > 0 && isChanged(TEXTURE))
     {
         updateVisualComplexity();
     }
 
-	// prevent the overwriting of valid baked textures with invalid baked textures
-	for (U8 baked_index = 0; baked_index < mBakedTextureDatas.size(); baked_index++)
-	{
-		if (!isTextureDefined(mBakedTextureDatas[baked_index].mTextureIndex) 
-			&& mBakedTextureDatas[baked_index].mLastTextureID != IMG_DEFAULT
-			&& baked_index != BAKED_SKIRT && baked_index != BAKED_LEFT_ARM && baked_index != BAKED_LEFT_LEG && baked_index != BAKED_AUX1 && baked_index != BAKED_AUX2 && baked_index != BAKED_AUX3)
-		{
-			LL_DEBUGS("Avatar") << avString() << " baked_index " << (S32) baked_index << " using mLastTextureID " << mBakedTextureDatas[baked_index].mLastTextureID << LL_ENDL;
-			setTEImage(mBakedTextureDatas[baked_index].mTextureIndex, 
-				LLViewerTextureManager::getFetchedTexture(mBakedTextureDatas[baked_index].mLastTextureID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE));
-		}
+    // prevent the overwriting of valid baked textures with invalid baked textures
+    for (U8 baked_index = 0; baked_index < mBakedTextureDatas.size(); baked_index++)
+    {
+        if (!isTextureDefined(mBakedTextureDatas[baked_index].mTextureIndex)
+            && mBakedTextureDatas[baked_index].mLastTextureID != IMG_DEFAULT
+            && baked_index != BAKED_SKIRT && baked_index != BAKED_LEFT_ARM && baked_index != BAKED_LEFT_LEG && baked_index != BAKED_AUX1 && baked_index != BAKED_AUX2 && baked_index != BAKED_AUX3)
+        {
+            LL_DEBUGS("Avatar") << avString() << " baked_index " << (S32) baked_index << " using mLastTextureID " << mBakedTextureDatas[baked_index].mLastTextureID << LL_ENDL;
+            setTEImage(mBakedTextureDatas[baked_index].mTextureIndex,
+                LLViewerTextureManager::getFetchedTexture(mBakedTextureDatas[baked_index].mLastTextureID, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE));
+        }
 #ifdef SHOW_DEBUG
-		else
-		{
-			LL_DEBUGS("Avatar") << avString() << " baked_index " << (S32) baked_index << " using texture id "
-								<< getTE(mBakedTextureDatas[baked_index].mTextureIndex)->getID() << LL_ENDL;
-		}
+        else
+        {
+            LL_DEBUGS("Avatar") << avString() << " baked_index " << (S32) baked_index << " using texture id "
+                                << getTE(mBakedTextureDatas[baked_index].mTextureIndex)->getID() << LL_ENDL;
+        }
 #endif
-	}
+    }
 
-	// runway - was
-	// if (!is_first_appearance_message )
-	// which means it would be called on second appearance message - probably wrong.
-	BOOL is_first_appearance_message = !mFirstAppearanceMessageReceived;
-	mFirstAppearanceMessageReceived = TRUE;
+    // runway - was
+    // if (!is_first_appearance_message )
+    // which means it would be called on second appearance message - probably wrong.
+    BOOL is_first_appearance_message = !mFirstAppearanceMessageReceived;
+    mFirstAppearanceMessageReceived = TRUE;
 
-	//LL_DEBUGS("Avatar") << avString() << "processAvatarAppearance start " << mID
+    //LL_DEBUGS("Avatar") << avString() << "processAvatarAppearance start " << mID
     //                    << " first? " << is_first_appearance_message << " self? " << isSelf() << LL_ENDL;
 
-	if (is_first_appearance_message )
-	{
-		onFirstTEMessageReceived();
-	}
-
-	setCompositeUpdatesEnabled( FALSE );
-	gPipeline.markGLRebuild(this);
-
-	// Apply visual params
-	if( num_params > 1)
-	{
-		//LL_DEBUGS("Avatar") << avString() << " handle visual params, num_params " << num_params << LL_ENDL;
-		BOOL params_changed = FALSE;
-		BOOL interp_params = FALSE;
-		S32 params_changed_count = 0;
-		
-		for( S32 i = 0; i < num_params; i++ )
-		{
-			LLVisualParam* param = contents.mParams[i];
-			F32 newWeight = contents.mParamWeights[i];
-
-			if (slam_params || is_first_appearance_message || (param->getWeight() != newWeight))
-			{
-				params_changed = TRUE;
-				params_changed_count++;
-
-				if(is_first_appearance_message || slam_params)
-				{
-					//LL_DEBUGS("Avatar") << "param slam " << i << " " << newWeight << LL_ENDL;
-					param->setWeight(newWeight);
-				}
-				else
-				{
-					interp_params = TRUE;
-					param->setAnimationTarget(newWeight);
-				}
-			}
-		}
+    if (is_first_appearance_message )
+    {
+        onFirstTEMessageReceived();
+    }
+
+    setCompositeUpdatesEnabled( FALSE );
+    gPipeline.markGLRebuild(this);
+
+    // Apply visual params
+    if( num_params > 1)
+    {
+        //LL_DEBUGS("Avatar") << avString() << " handle visual params, num_params " << num_params << LL_ENDL;
+        BOOL params_changed = FALSE;
+        BOOL interp_params = FALSE;
+        S32 params_changed_count = 0;
+
+        for( S32 i = 0; i < num_params; i++ )
+        {
+            LLVisualParam* param = contents.mParams[i];
+            F32 newWeight = contents.mParamWeights[i];
+
+            if (slam_params || is_first_appearance_message || (param->getWeight() != newWeight))
+            {
+                params_changed = TRUE;
+                params_changed_count++;
+
+                if(is_first_appearance_message || slam_params)
+                {
+                    //LL_DEBUGS("Avatar") << "param slam " << i << " " << newWeight << LL_ENDL;
+                    param->setWeight(newWeight);
+                }
+                else
+                {
+                    interp_params = TRUE;
+                    param->setAnimationTarget(newWeight);
+                }
+            }
+        }
 #ifdef SHOW_DEBUG
-		const S32 expected_tweakable_count = getVisualParamCountInGroup(VISUAL_PARAM_GROUP_TWEAKABLE) +
-											 getVisualParamCountInGroup(VISUAL_PARAM_GROUP_TRANSMIT_NOT_TWEAKABLE); // don't worry about VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
-		if (num_params != expected_tweakable_count)
-		{
-			LL_DEBUGS("Avatar") << "Number of params in AvatarAppearance msg (" << num_params << ") does not match number of tweakable params in avatar xml file (" << expected_tweakable_count << ").  Processing what we can.  object: " << getID() << LL_ENDL;
-		}
-
-		LL_DEBUGS("Avatar") << "Changed " << params_changed_count << " params" << LL_ENDL;
+        const S32 expected_tweakable_count = getVisualParamCountInGroup(VISUAL_PARAM_GROUP_TWEAKABLE) +
+                                             getVisualParamCountInGroup(VISUAL_PARAM_GROUP_TRANSMIT_NOT_TWEAKABLE); // don't worry about VISUAL_PARAM_GROUP_TWEAKABLE_NO_TRANSMIT
+        if (num_params != expected_tweakable_count)
+        {
+            LL_DEBUGS("Avatar") << "Number of params in AvatarAppearance msg (" << num_params << ") does not match number of tweakable params in avatar xml file (" << expected_tweakable_count << ").  Processing what we can.  object: " << getID() << LL_ENDL;
+        }
+
+        LL_DEBUGS("Avatar") << "Changed " << params_changed_count << " params" << LL_ENDL;
 #endif
-		if (params_changed)
-		{
-			if (interp_params)
-			{
-				startAppearanceAnimation();
-			}
-			updateVisualParams();
-
-			ESex new_sex = getSex();
-			if( old_sex != new_sex )
-			{
-				updateSexDependentLayerSets();
-			}	
-		}
-
-		llassert( getSex() == ((getVisualParamWeight( "male" ) > 0.5f) ? SEX_MALE : SEX_FEMALE) );
-	}
-	else
-	{
-		// AvatarAppearance message arrived without visual params
+        if (params_changed)
+        {
+            if (interp_params)
+            {
+                startAppearanceAnimation();
+            }
+            updateVisualParams();
+
+            ESex new_sex = getSex();
+            if( old_sex != new_sex )
+            {
+                updateSexDependentLayerSets();
+            }
+        }
+
+        llassert( getSex() == ((getVisualParamWeight( "male" ) > 0.5f) ? SEX_MALE : SEX_FEMALE) );
+    }
+    else
+    {
+        // AvatarAppearance message arrived without visual params
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("Avatar") << avString() << "no visual params" << LL_ENDL;
+        LL_DEBUGS("Avatar") << avString() << "no visual params" << LL_ENDL;
 #endif
 
-		const F32 LOADING_TIMEOUT_SECONDS = 60.f;
-		// this isn't really a problem if we already have a non-default shape
-		if (visualParamWeightsAreDefault() && mRuthTimer.getElapsedTimeF32() > LOADING_TIMEOUT_SECONDS)
-		{
-			// re-request appearance, hoping that it comes back with a shape next time
-			LL_INFOS() << "Re-requesting AvatarAppearance for object: "  << getID() << LL_ENDL;
-			LLAvatarPropertiesProcessor::getInstance()->sendAvatarTexturesRequest(getID());
-			mRuthTimer.reset();
-		}
-		else
-		{
-			LL_INFOS() << "That's okay, we already have a non-default shape for object: "  << getID() << LL_ENDL;
-			// we don't really care.
-		}
-	}
-
-	if (contents.mHoverOffsetWasSet && !isSelf())
-	{
-		// Got an update for some other avatar
-		// Ignore updates for self, because we have a more authoritative value in the preferences.
-		setHoverOffset(contents.mHoverOffset);
+        const F32 LOADING_TIMEOUT_SECONDS = 60.f;
+        // this isn't really a problem if we already have a non-default shape
+        if (visualParamWeightsAreDefault() && mRuthTimer.getElapsedTimeF32() > LOADING_TIMEOUT_SECONDS)
+        {
+            // re-request appearance, hoping that it comes back with a shape next time
+            LL_INFOS() << "Re-requesting AvatarAppearance for object: "  << getID() << LL_ENDL;
+            LLAvatarPropertiesProcessor::getInstance()->sendAvatarTexturesRequest(getID());
+            mRuthTimer.reset();
+        }
+        else
+        {
+            LL_INFOS() << "That's okay, we already have a non-default shape for object: "  << getID() << LL_ENDL;
+            // we don't really care.
+        }
+    }
+
+    if (contents.mHoverOffsetWasSet && !isSelf())
+    {
+        // Got an update for some other avatar
+        // Ignore updates for self, because we have a more authoritative value in the preferences.
+        setHoverOffset(contents.mHoverOffset);
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("Avatar") << avString() << "setting hover to " << contents.mHoverOffset[2] << LL_ENDL;
+        LL_DEBUGS("Avatar") << avString() << "setting hover to " << contents.mHoverOffset[2] << LL_ENDL;
 #endif
-	}
+    }
 
-	if (!contents.mHoverOffsetWasSet && !isSelf())
-	{
-		// If we don't get a value at all, we are presumably in a
-		// region that does not support hover height.
-		LL_WARNS() << avString() << "zeroing hover because not defined in appearance message" << LL_ENDL;
-		setHoverOffset(LLVector3(0.0, 0.0, 0.0));
-	}
+    if (!contents.mHoverOffsetWasSet && !isSelf())
+    {
+        // If we don't get a value at all, we are presumably in a
+        // region that does not support hover height.
+        LL_WARNS() << avString() << "zeroing hover because not defined in appearance message" << LL_ENDL;
+        setHoverOffset(LLVector3(0.0, 0.0, 0.0));
+    }
 
-	setCompositeUpdatesEnabled( TRUE );
+    setCompositeUpdatesEnabled( TRUE );
 
-	// If all of the avatars are completely baked, release the global image caches to conserve memory.
-	LLVOAvatar::cullAvatarsByPixelArea();
+    // If all of the avatars are completely baked, release the global image caches to conserve memory.
+    LLVOAvatar::cullAvatarsByPixelArea();
 
-	if (isSelf())
-	{
-		mUseLocalAppearance = false;
-	}
+    if (isSelf())
+    {
+        mUseLocalAppearance = false;
+    }
 
-	updateMeshTextures();
-	updateMeshVisibility();
+    updateMeshTextures();
+    updateMeshVisibility();
 
 }
 
 LLViewerTexture* LLVOAvatar::getBakedTexture(const U8 te)
 {
-	if (te < 0 || te >= BAKED_NUM_INDICES)
-	{
-		return NULL;
-	}
+    if (te < 0 || te >= BAKED_NUM_INDICES)
+    {
+        return NULL;
+    }
+
+    BOOL is_layer_baked = isTextureDefined(mBakedTextureDatas[te].mTextureIndex);
 
-	BOOL is_layer_baked = isTextureDefined(mBakedTextureDatas[te].mTextureIndex);
-	
-	LLViewerTexLayerSet* layerset = NULL;
-	layerset = getTexLayerSet(te);
-	
+    LLViewerTexLayerSet* layerset = NULL;
+    layerset = getTexLayerSet(te);
 
-	if (!isEditingAppearance() && is_layer_baked)
-	{
-		LLViewerFetchedTexture* baked_img = LLViewerTextureManager::staticCastToFetchedTexture(getImage(mBakedTextureDatas[te].mTextureIndex, 0), TRUE);
-		return baked_img;
-	}
-	else if (layerset && isEditingAppearance())
-	{
-		layerset->createComposite();
-		layerset->setUpdatesEnabled(TRUE);
 
-		return layerset->getViewerComposite();
-	}
+    if (!isEditingAppearance() && is_layer_baked)
+    {
+        LLViewerFetchedTexture* baked_img = LLViewerTextureManager::staticCastToFetchedTexture(getImage(mBakedTextureDatas[te].mTextureIndex, 0), TRUE);
+        return baked_img;
+    }
+    else if (layerset && isEditingAppearance())
+    {
+        layerset->createComposite();
+        layerset->setUpdatesEnabled(TRUE);
+
+        return layerset->getViewerComposite();
+    }
+
+    return NULL;
 
-	return NULL;
 
-	
 }
 
 const LLVOAvatar::MatrixPaletteCache& LLVOAvatar::updateSkinInfoMatrixPalette(const LLMeshSkinInfo* skin)
@@ -9999,252 +9999,252 @@ const LLVOAvatar::MatrixPaletteCache& LLVOAvatar::updateSkinInfoMatrixPalette(co
 // static
 void LLVOAvatar::getAnimLabels( std::vector<std::string>* labels )
 {
-	S32 i;
-	labels->reserve(gUserAnimStatesCount);
-	for( i = 0; i < gUserAnimStatesCount; i++ )
-	{
-		labels->push_back( LLAnimStateLabels::getStateLabel( gUserAnimStates[i].mName ) );
-	}
+    S32 i;
+    labels->reserve(gUserAnimStatesCount);
+    for( i = 0; i < gUserAnimStatesCount; i++ )
+    {
+        labels->push_back( LLAnimStateLabels::getStateLabel( gUserAnimStates[i].mName ) );
+    }
 
-	// Special case to trigger away (AFK) state
-	labels->push_back( "Away From Keyboard" );
+    // Special case to trigger away (AFK) state
+    labels->push_back( "Away From Keyboard" );
 }
 
-// static 
+// static
 void LLVOAvatar::getAnimNames( std::vector<std::string>* names )
 {
-	S32 i;
+    S32 i;
 
-	names->reserve(gUserAnimStatesCount);
-	for( i = 0; i < gUserAnimStatesCount; i++ )
-	{
-		names->push_back( std::string(gUserAnimStates[i].mName) );
-	}
+    names->reserve(gUserAnimStatesCount);
+    for( i = 0; i < gUserAnimStatesCount; i++ )
+    {
+        names->push_back( std::string(gUserAnimStates[i].mName) );
+    }
 
-	// Special case to trigger away (AFK) state
-	names->push_back( "enter_away_from_keyboard_state" );
+    // Special case to trigger away (AFK) state
+    names->push_back( "enter_away_from_keyboard_state" );
 }
 
 // static
 void LLVOAvatar::onBakedTextureMasksLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata )
 {
-	if (!userdata) return;
-
-	//LL_INFOS() << "onBakedTextureMasksLoaded: " << src_vi->getID() << LL_ENDL;
-	const LLUUID id = src_vi->getID();
- 
-	LLTextureMaskData* maskData = (LLTextureMaskData*) userdata;
-	LLVOAvatar* self = (LLVOAvatar*) gObjectList.findObject( maskData->mAvatarID );
-
-	// if discard level is 2 less than last discard level we processed, or we hit 0,
-	// then generate morph masks
-	if(self && success && (discard_level < maskData->mLastDiscardLevel - 2 || discard_level == 0))
-	{
-		if(aux_src && aux_src->getComponents() == 1)
-		{
-			if (!aux_src->getData())
-			{
-				LL_WARNS() << "No auxiliary source (morph mask) data for image id " << id << LL_ENDL;
-				return;
-			}
-
-			U32 gl_name;
-			LLImageGL::generateTextures(1, &gl_name );
-			stop_glerror();
-
-			gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, gl_name);
-			stop_glerror();
-
-			LLImageGL::setManualImage(
-				GL_TEXTURE_2D, 0, GL_ALPHA8, 
-				aux_src->getWidth(), aux_src->getHeight(),
-				GL_ALPHA, GL_UNSIGNED_BYTE, aux_src->getData());
-			stop_glerror();
-
-			gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
-
-			/* if( id == head_baked->getID() )
-			     if (self->mBakedTextureDatas[BAKED_HEAD].mTexLayerSet)
-				     //LL_INFOS() << "onBakedTextureMasksLoaded for head " << id << " discard = " << discard_level << LL_ENDL;
-					 self->mBakedTextureDatas[BAKED_HEAD].mTexLayerSet->applyMorphMask(aux_src->getData(), aux_src->getWidth(), aux_src->getHeight(), 1);
-					 maskData->mLastDiscardLevel = discard_level; */
-			BOOL found_texture_id = false;
-			for (const auto& tex_pair : LLAvatarAppearance::getDictionary()->getTextures())
-			{
-				const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
-				if (texture_dict->mIsUsedByBakedTexture)
-				{
-					const ETextureIndex texture_index = tex_pair.first;
-					const LLViewerTexture *baked_img = self->getImage(texture_index, 0);
-					if (baked_img && id == baked_img->getID())
-					{
-						const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex;
-						self->applyMorphMask(aux_src->getData(), aux_src->getWidth(), aux_src->getHeight(), 1, baked_index);
-						maskData->mLastDiscardLevel = discard_level;
-						if (self->mBakedTextureDatas[baked_index].mMaskTexName)
-						{
-							LLImageGL::deleteTextures(1, &(self->mBakedTextureDatas[baked_index].mMaskTexName));
-						}
-						self->mBakedTextureDatas[baked_index].mMaskTexName = gl_name;
-						found_texture_id = true;
-						break;
-					}
-				}
-			}
-			if (!found_texture_id)
-			{
-				LL_INFOS() << "unexpected image id: " << id << LL_ENDL;
-			}
-			self->dirtyMesh();
-		}
-		else
-		{
-            // this can happen when someone uses an old baked texture possibly provided by 
+    if (!userdata) return;
+
+    //LL_INFOS() << "onBakedTextureMasksLoaded: " << src_vi->getID() << LL_ENDL;
+    const LLUUID id = src_vi->getID();
+
+    LLTextureMaskData* maskData = (LLTextureMaskData*) userdata;
+    LLVOAvatar* self = (LLVOAvatar*) gObjectList.findObject( maskData->mAvatarID );
+
+    // if discard level is 2 less than last discard level we processed, or we hit 0,
+    // then generate morph masks
+    if(self && success && (discard_level < maskData->mLastDiscardLevel - 2 || discard_level == 0))
+    {
+        if(aux_src && aux_src->getComponents() == 1)
+        {
+            if (!aux_src->getData())
+            {
+                LL_WARNS() << "No auxiliary source (morph mask) data for image id " << id << LL_ENDL;
+                return;
+            }
+
+            U32 gl_name;
+            LLImageGL::generateTextures(1, &gl_name );
+            stop_glerror();
+
+            gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, gl_name);
+            stop_glerror();
+
+            LLImageGL::setManualImage(
+                GL_TEXTURE_2D, 0, GL_ALPHA8,
+                aux_src->getWidth(), aux_src->getHeight(),
+                GL_ALPHA, GL_UNSIGNED_BYTE, aux_src->getData());
+            stop_glerror();
+
+            gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
+
+            /* if( id == head_baked->getID() )
+                 if (self->mBakedTextureDatas[BAKED_HEAD].mTexLayerSet)
+                     //LL_INFOS() << "onBakedTextureMasksLoaded for head " << id << " discard = " << discard_level << LL_ENDL;
+                     self->mBakedTextureDatas[BAKED_HEAD].mTexLayerSet->applyMorphMask(aux_src->getData(), aux_src->getWidth(), aux_src->getHeight(), 1);
+                     maskData->mLastDiscardLevel = discard_level; */
+            BOOL found_texture_id = false;
+            for (const auto& tex_pair : LLAvatarAppearance::getDictionary()->getTextures())
+            {
+                const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
+                if (texture_dict->mIsUsedByBakedTexture)
+                {
+                    const ETextureIndex texture_index = tex_pair.first;
+                    const LLViewerTexture *baked_img = self->getImage(texture_index, 0);
+                    if (baked_img && id == baked_img->getID())
+                    {
+                        const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex;
+                        self->applyMorphMask(aux_src->getData(), aux_src->getWidth(), aux_src->getHeight(), 1, baked_index);
+                        maskData->mLastDiscardLevel = discard_level;
+                        if (self->mBakedTextureDatas[baked_index].mMaskTexName)
+                        {
+                            LLImageGL::deleteTextures(1, &(self->mBakedTextureDatas[baked_index].mMaskTexName));
+                        }
+                        self->mBakedTextureDatas[baked_index].mMaskTexName = gl_name;
+                        found_texture_id = true;
+                        break;
+                    }
+                }
+            }
+            if (!found_texture_id)
+            {
+                LL_INFOS() << "unexpected image id: " << id << LL_ENDL;
+            }
+            self->dirtyMesh();
+        }
+        else
+        {
+            // this can happen when someone uses an old baked texture possibly provided by
             // viewer-side baked texture caching
-			LL_WARNS() << "Masks loaded callback but NO aux source, id " << id << LL_ENDL;
-		}
-	}
+            LL_WARNS() << "Masks loaded callback but NO aux source, id " << id << LL_ENDL;
+        }
+    }
 
-	if (final || !success)
-	{
-		delete maskData;
-	}
+    if (final || !success)
+    {
+        delete maskData;
+    }
 }
 
 // static
 void LLVOAvatar::onInitialBakedTextureLoaded( BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata )
 {
-	LLUUID *avatar_idp = (LLUUID *)userdata;
-	LLVOAvatar *selfp = (LLVOAvatar *)gObjectList.findObject(*avatar_idp);
+    LLUUID *avatar_idp = (LLUUID *)userdata;
+    LLVOAvatar *selfp = (LLVOAvatar *)gObjectList.findObject(*avatar_idp);
 
-	if (selfp)
-	{
-		//LL_DEBUGS("Avatar") << selfp->avString() << "discard_level " << discard_level << " success " << success << " final " << final << LL_ENDL;
-	}
+    if (selfp)
+    {
+        //LL_DEBUGS("Avatar") << selfp->avString() << "discard_level " << discard_level << " success " << success << " final " << final << LL_ENDL;
+    }
 
-	if (!success && selfp)
-	{
-		selfp->removeMissingBakedTextures();
-	}
-	if (final || !success )
-	{
-		delete avatar_idp;
-	}
+    if (!success && selfp)
+    {
+        selfp->removeMissingBakedTextures();
+    }
+    if (final || !success )
+    {
+        delete avatar_idp;
+    }
 }
 
 // Static
 void LLVOAvatar::onBakedTextureLoaded(BOOL success,
-									  LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src,
-									  S32 discard_level, BOOL final, void* userdata)
+                                      LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src,
+                                      S32 discard_level, BOOL final, void* userdata)
 {
-	//LL_DEBUGS("Avatar") << "onBakedTextureLoaded: " << src_vi->getID() << LL_ENDL;
+    //LL_DEBUGS("Avatar") << "onBakedTextureLoaded: " << src_vi->getID() << LL_ENDL;
 
-	LLUUID id = src_vi->getID();
-	LLUUID *avatar_idp = (LLUUID *)userdata;
-	LLVOAvatar *selfp = (LLVOAvatar *)gObjectList.findObject(*avatar_idp);
-	if (selfp)
-	{	
-		//LL_DEBUGS("Avatar") << selfp->avString() << "discard_level " << discard_level << " success " << success << " final " << final << " id " << src_vi->getID() << LL_ENDL;
-	}
+    LLUUID id = src_vi->getID();
+    LLUUID *avatar_idp = (LLUUID *)userdata;
+    LLVOAvatar *selfp = (LLVOAvatar *)gObjectList.findObject(*avatar_idp);
+    if (selfp)
+    {
+        //LL_DEBUGS("Avatar") << selfp->avString() << "discard_level " << discard_level << " success " << success << " final " << final << " id " << src_vi->getID() << LL_ENDL;
+    }
 
-	if (selfp && !success)
-	{
-		selfp->removeMissingBakedTextures();
-	}
+    if (selfp && !success)
+    {
+        selfp->removeMissingBakedTextures();
+    }
 
-	if( final || !success )
-	{
-		delete avatar_idp;
-	}
+    if( final || !success )
+    {
+        delete avatar_idp;
+    }
 
-	if( selfp && success && final )
-	{
-		selfp->useBakedTexture( id );
-	}
+    if( selfp && success && final )
+    {
+        selfp->useBakedTexture( id );
+    }
 }
 
 
 // Called when baked texture is loaded and also when we start up with a baked texture
 void LLVOAvatar::useBakedTexture( const LLUUID& id )
 {
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		LLViewerTexture* image_baked = getImage( mBakedTextureDatas[i].mTextureIndex, 0 );
-		if (id == image_baked->getID())
-		{
-			//LL_DEBUGS("Avatar") << avString() << " i " << i << " id " << id << LL_ENDL;
-			mBakedTextureDatas[i].mIsLoaded = true;
-			mBakedTextureDatas[i].mLastTextureID = id;
-			mBakedTextureDatas[i].mIsUsed = true;
-
-			if (isUsingLocalAppearance())
-			{
-				LL_INFOS() << "not changing to baked texture while isUsingLocalAppearance" << LL_ENDL;
-			}
-			else
-			{
-				debugColorizeSubMeshes(i,LLColor4::green);
-
-				for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
-				{
-					if (mesh)
-					{
-						mesh->setTexture( image_baked );
-					}
-				}
-			}
-			
-			const LLAvatarAppearanceDictionary::BakedEntry *baked_dict =
-				LLAvatarAppearance::getDictionary()->getBakedTexture((EBakedTextureIndex)i);
-			for (const auto& tex_index : baked_dict->mLocalTextures)
-			{
-				if (isSelf()) setBakedReady(tex_index, TRUE);
-			}
-
-			// ! BACKWARDS COMPATIBILITY !
-			// Workaround for viewing avatars from old viewers that haven't baked hair textures.
-			// This is paired with similar code in updateMeshTextures that sets hair mesh color.
-			if (i == BAKED_HAIR)
-			{
-				for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
-				{
-					if (mesh)
-					{
-						mesh->setColor( LLColor4::white );
-					}
-				}
-			}
-		}
-	}
-
-	dirtyMesh();
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        LLViewerTexture* image_baked = getImage( mBakedTextureDatas[i].mTextureIndex, 0 );
+        if (id == image_baked->getID())
+        {
+            //LL_DEBUGS("Avatar") << avString() << " i " << i << " id " << id << LL_ENDL;
+            mBakedTextureDatas[i].mIsLoaded = true;
+            mBakedTextureDatas[i].mLastTextureID = id;
+            mBakedTextureDatas[i].mIsUsed = true;
+
+            if (isUsingLocalAppearance())
+            {
+                LL_INFOS() << "not changing to baked texture while isUsingLocalAppearance" << LL_ENDL;
+            }
+            else
+            {
+                debugColorizeSubMeshes(i,LLColor4::green);
+
+                for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
+                {
+                    if (mesh)
+                    {
+                        mesh->setTexture( image_baked );
+                    }
+                }
+            }
+
+            const LLAvatarAppearanceDictionary::BakedEntry *baked_dict =
+                LLAvatarAppearance::getDictionary()->getBakedTexture((EBakedTextureIndex)i);
+            for (const auto& tex_index : baked_dict->mLocalTextures)
+            {
+                if (isSelf()) setBakedReady(tex_index, TRUE);
+            }
+
+            // ! BACKWARDS COMPATIBILITY !
+            // Workaround for viewing avatars from old viewers that haven't baked hair textures.
+            // This is paired with similar code in updateMeshTextures that sets hair mesh color.
+            if (i == BAKED_HAIR)
+            {
+                for (LLAvatarJointMesh* mesh : mBakedTextureDatas[i].mJointMeshes)
+                {
+                    if (mesh)
+                    {
+                        mesh->setColor( LLColor4::white );
+                    }
+                }
+            }
+        }
+    }
+
+    dirtyMesh();
 }
 
 std::string get_sequential_numbered_file_name(const std::string& prefix,
-											  const std::string& suffix)
-{
-	typedef std::map<std::string,S32> file_num_type;
-	static  file_num_type file_nums;
-	file_num_type::iterator it = file_nums.find(prefix);
-	S32 num = 0;
-	if (it != file_nums.end())
-	{
-		num = it->second;
-	}
-	file_nums[prefix] = num+1;
-	std::string outfilename = prefix + " " + llformat("%04d",num) + ".xml";
-	std::replace(outfilename.begin(),outfilename.end(),' ','_');
-	return outfilename;
+                                              const std::string& suffix)
+{
+    typedef std::map<std::string,S32> file_num_type;
+    static  file_num_type file_nums;
+    file_num_type::iterator it = file_nums.find(prefix);
+    S32 num = 0;
+    if (it != file_nums.end())
+    {
+        num = it->second;
+    }
+    file_nums[prefix] = num+1;
+    std::string outfilename = prefix + " " + llformat("%04d",num) + ".xml";
+    std::replace(outfilename.begin(),outfilename.end(),' ','_');
+    return outfilename;
 }
 
 void dump_sequential_xml(const std::string outprefix, const LLSD& content)
 {
-	std::string outfilename = get_sequential_numbered_file_name(outprefix,".xml");
-	std::string fullpath = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,outfilename);
-	llofstream ofs(fullpath.c_str(), std::ios_base::out);
-	ofs << LLSDOStreamer<LLSDXMLFormatter>(content, LLSDFormatter::OPTIONS_PRETTY);
+    std::string outfilename = get_sequential_numbered_file_name(outprefix,".xml");
+    std::string fullpath = gDirUtilp->getExpandedFilename(LL_PATH_LOGS,outfilename);
+    llofstream ofs(fullpath.c_str(), std::ios_base::out);
+    ofs << LLSDOStreamer<LLSDXMLFormatter>(content, LLSDFormatter::OPTIONS_PRETTY);
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Avatar") << "results saved to: " << fullpath << LL_ENDL;
+    LL_DEBUGS("Avatar") << "results saved to: " << fullpath << LL_ENDL;
 #endif
 }
 
@@ -10255,9 +10255,9 @@ void LLVOAvatar::getSortedJointNames(S32 joint_type, std::vector<std::string>& r
     {
         avatar_joint_list_t::const_iterator iter = mSkeleton.begin();
         avatar_joint_list_t::const_iterator end  = mSkeleton.end();
-		for (; iter != end; ++iter)
-		{
-			LLJoint* pJoint = (*iter);
+        for (; iter != end; ++iter)
+        {
+            LLJoint* pJoint = (*iter);
             result.push_back(pJoint->getName());
         }
     }
@@ -10271,10 +10271,10 @@ void LLVOAvatar::getSortedJointNames(S32 joint_type, std::vector<std::string>& r
     }
     else if (joint_type==2)
     {
-		for (const auto& attach_pair : mAttachmentPoints)
-		{
-			LLViewerJointAttachment* pJoint = attach_pair.second;
-			if (!pJoint) continue;
+        for (const auto& attach_pair : mAttachmentPoints)
+        {
+            LLViewerJointAttachment* pJoint = attach_pair.second;
+            if (!pJoint) continue;
             result.push_back(pJoint->getName());
         }
     }
@@ -10283,100 +10283,100 @@ void LLVOAvatar::getSortedJointNames(S32 joint_type, std::vector<std::string>& r
 
 void LLVOAvatar::dumpArchetypeXML(const std::string& prefix, bool group_by_wearables)
 {
-	std::string outprefix(prefix);
-	if (outprefix.empty())
-	{
-		outprefix = getFullname() + (isSelf() ? "_s" : "_o");
-	}
-	if (outprefix.empty())
-	{
-		outprefix = std::string("new_archetype");
-	}
-	std::string outfilename = get_sequential_numbered_file_name(outprefix, ".xml");
-	LLFilePickerReplyThread::startPicker(boost::bind(&LLVOAvatar::dumpArchetypeXMLCallback, this, _1, group_by_wearables), LLFilePicker::FFSAVE_XML, outfilename);
+    std::string outprefix(prefix);
+    if (outprefix.empty())
+    {
+        outprefix = getFullname() + (isSelf() ? "_s" : "_o");
+    }
+    if (outprefix.empty())
+    {
+        outprefix = std::string("new_archetype");
+    }
+    std::string outfilename = get_sequential_numbered_file_name(outprefix, ".xml");
+    LLFilePickerReplyThread::startPicker(boost::bind(&LLVOAvatar::dumpArchetypeXMLCallback, this, _1, group_by_wearables), LLFilePicker::FFSAVE_XML, outfilename);
 }
 
 void LLVOAvatar::dumpArchetypeXMLCallback(const std::vector<std::string>& filenames, bool group_by_wearables)
 {
-	LLAPRFile outfile;
+    LLAPRFile outfile;
     LLWearableType *wr_inst = LLWearableType::getInstance();
-	std::string fullpath = filenames[0];
-	if (APR_SUCCESS == outfile.open(fullpath, LL_APR_WB ))
-	{
-		apr_file_t* file = outfile.getFileHandle();
-		LL_INFOS() << "xmlfile write handle obtained : " << fullpath << LL_ENDL;
-
-		apr_file_printf( file, "<?xml version=\"1.0\" encoding=\"US-ASCII\" standalone=\"yes\"?>\n" );
-		apr_file_printf( file, "<linden_genepool version=\"1.0\">\n" );
-		apr_file_printf( file, "\n\t<archetype name=\"???\">\n" );
-
-		bool agent_is_godlike = gAgent.isGodlikeWithoutAdminMenuFakery();
-
-		if (group_by_wearables)
-		{
-			for (S32 type = LLWearableType::WT_SHAPE; type < LLWearableType::WT_COUNT; type++)
-			{
-				const std::string& wearable_name = wr_inst->getTypeName((LLWearableType::EType)type);
-				apr_file_printf( file, "\n\t\t<!-- wearable: %s -->\n", wearable_name.c_str() );
-
-				for (LLVisualParam* param = getFirstVisualParam(); param; param = getNextVisualParam())
-				{
-					LLViewerVisualParam* viewer_param = (LLViewerVisualParam*)param;
-					if( (viewer_param->getWearableType() == type) && 
-					   (viewer_param->isTweakable() ) )
-					{
-						dump_visual_param(file, viewer_param, viewer_param->getWeight());
-					}
-				}
-
-				for (U8 te = 0; te < TEX_NUM_INDICES; te++)
-				{
-					if (LLAvatarAppearance::getDictionary()->getTEWearableType((ETextureIndex)te) == type)
-					{
-						// MULTIPLE_WEARABLES: extend to multiple wearables?
-						LLViewerTexture* te_image = getImage((ETextureIndex)te, 0);
-						if( te_image )
-						{
-							std::string uuid_str = LLUUID().asString();
-							if (agent_is_godlike)
-							{
-								te_image->getID().toString(uuid_str);
-							}
-							apr_file_printf( file, "\t\t<texture te=\"%i\" uuid=\"%s\"/>\n", te, uuid_str.c_str());
-						}
-					}
-				}
-			}
-		}
-		else 
-		{
-			// Just dump all params sequentially.
-			for (LLVisualParam* param = getFirstVisualParam(); param; param = getNextVisualParam())
-			{
-				LLViewerVisualParam* viewer_param = (LLViewerVisualParam*)param;
-				dump_visual_param(file, viewer_param, viewer_param->getWeight());
-			}
-
-			for (U8 te = 0; te < TEX_NUM_INDICES; te++)
-			{
-				// MULTIPLE_WEARABLES: extend to multiple wearables?
-				LLViewerTexture* te_image = getImage((ETextureIndex)te, 0);
-				if( te_image )
-				{
-					std::string uuid_str = LLUUID().asString();
-					if (agent_is_godlike)
-					{
-						te_image->getID().toString(uuid_str);
-					}
-					apr_file_printf( file, "\t\t<texture te=\"%i\" uuid=\"%s\"/>\n", te, uuid_str.c_str());
-				}
-			}
-		}
+    std::string fullpath = filenames[0];
+    if (APR_SUCCESS == outfile.open(fullpath, LL_APR_WB ))
+    {
+        apr_file_t* file = outfile.getFileHandle();
+        LL_INFOS() << "xmlfile write handle obtained : " << fullpath << LL_ENDL;
+
+        apr_file_printf( file, "<?xml version=\"1.0\" encoding=\"US-ASCII\" standalone=\"yes\"?>\n" );
+        apr_file_printf( file, "<linden_genepool version=\"1.0\">\n" );
+        apr_file_printf( file, "\n\t<archetype name=\"???\">\n" );
+
+        bool agent_is_godlike = gAgent.isGodlikeWithoutAdminMenuFakery();
+
+        if (group_by_wearables)
+        {
+            for (S32 type = LLWearableType::WT_SHAPE; type < LLWearableType::WT_COUNT; type++)
+            {
+                const std::string& wearable_name = wr_inst->getTypeName((LLWearableType::EType)type);
+                apr_file_printf( file, "\n\t\t<!-- wearable: %s -->\n", wearable_name.c_str() );
+
+                for (LLVisualParam* param = getFirstVisualParam(); param; param = getNextVisualParam())
+                {
+                    LLViewerVisualParam* viewer_param = (LLViewerVisualParam*)param;
+                    if( (viewer_param->getWearableType() == type) &&
+                       (viewer_param->isTweakable() ) )
+                    {
+                        dump_visual_param(file, viewer_param, viewer_param->getWeight());
+                    }
+                }
+
+                for (U8 te = 0; te < TEX_NUM_INDICES; te++)
+                {
+                    if (LLAvatarAppearance::getDictionary()->getTEWearableType((ETextureIndex)te) == type)
+                    {
+                        // MULTIPLE_WEARABLES: extend to multiple wearables?
+                        LLViewerTexture* te_image = getImage((ETextureIndex)te, 0);
+                        if( te_image )
+                        {
+                            std::string uuid_str = LLUUID().asString();
+                            if (agent_is_godlike)
+                            {
+                                te_image->getID().toString(uuid_str);
+                            }
+                            apr_file_printf( file, "\t\t<texture te=\"%i\" uuid=\"%s\"/>\n", te, uuid_str.c_str());
+                        }
+                    }
+                }
+            }
+        }
+        else
+        {
+            // Just dump all params sequentially.
+            for (LLVisualParam* param = getFirstVisualParam(); param; param = getNextVisualParam())
+            {
+                LLViewerVisualParam* viewer_param = (LLViewerVisualParam*)param;
+                dump_visual_param(file, viewer_param, viewer_param->getWeight());
+            }
+
+            for (U8 te = 0; te < TEX_NUM_INDICES; te++)
+            {
+                // MULTIPLE_WEARABLES: extend to multiple wearables?
+                LLViewerTexture* te_image = getImage((ETextureIndex)te, 0);
+                if( te_image )
+                {
+                    std::string uuid_str = LLUUID().asString();
+                    if (agent_is_godlike)
+                    {
+                        te_image->getID().toString(uuid_str);
+                    }
+                    apr_file_printf( file, "\t\t<texture te=\"%i\" uuid=\"%s\"/>\n", te, uuid_str.c_str());
+                }
+            }
+        }
 
         // Root joint
         const LLVector3& pos = mRoot->getPosition();
         const LLVector3& scale = mRoot->getScale();
-        apr_file_printf( file, "\t\t<root name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n", 
+        apr_file_printf( file, "\t\t<root name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n",
                          mRoot->getName().c_str(), pos[0], pos[1], pos[2], scale[0], scale[1], scale[2]);
 
         // Bones
@@ -10392,10 +10392,10 @@ void LLVOAvatar::dumpArchetypeXMLCallback(const std::vector<std::string>& filena
              name_iter != bone_names.end(); ++name_iter)
         {
             LLJoint *pJoint = getJoint(*name_iter);
-			const LLVector3& pos = pJoint->getPosition();
-			const LLVector3& scale = pJoint->getScale();
-			apr_file_printf( file, "\t\t<bone name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n", 
-							 pJoint->getName().c_str(), pos[0], pos[1], pos[2], scale[0], scale[1], scale[2]);
+            const LLVector3& pos = pJoint->getPosition();
+            const LLVector3& scale = pJoint->getScale();
+            apr_file_printf( file, "\t\t<bone name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n",
+                             pJoint->getName().c_str(), pos[0], pos[1], pos[2], scale[0], scale[1], scale[2]);
         }
 
         // Collision volumes
@@ -10403,10 +10403,10 @@ void LLVOAvatar::dumpArchetypeXMLCallback(const std::vector<std::string>& filena
              name_iter != cv_names.end(); ++name_iter)
         {
             LLJoint *pJoint = getJoint(*name_iter);
-			const LLVector3& pos = pJoint->getPosition();
-			const LLVector3& scale = pJoint->getScale();
-			apr_file_printf( file, "\t\t<collision_volume name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n", 
-							 pJoint->getName().c_str(), pos[0], pos[1], pos[2], scale[0], scale[1], scale[2]);
+            const LLVector3& pos = pJoint->getPosition();
+            const LLVector3& scale = pJoint->getScale();
+            apr_file_printf( file, "\t\t<collision_volume name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n",
+                             pJoint->getName().c_str(), pos[0], pos[1], pos[2], scale[0], scale[1], scale[2]);
         }
 
         // Attachment joints
@@ -10414,63 +10414,63 @@ void LLVOAvatar::dumpArchetypeXMLCallback(const std::vector<std::string>& filena
              name_iter != attach_names.end(); ++name_iter)
         {
             LLJoint *pJoint = getJoint(*name_iter);
-			if (!pJoint) continue;
-			const LLVector3& pos = pJoint->getPosition();
-			const LLVector3& scale = pJoint->getScale();
-			apr_file_printf( file, "\t\t<attachment_point name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n", 
-							 pJoint->getName().c_str(), pos[0], pos[1], pos[2], scale[0], scale[1], scale[2]);
+            if (!pJoint) continue;
+            const LLVector3& pos = pJoint->getPosition();
+            const LLVector3& scale = pJoint->getScale();
+            apr_file_printf( file, "\t\t<attachment_point name=\"%s\" position=\"%f %f %f\" scale=\"%f %f %f\"/>\n",
+                             pJoint->getName().c_str(), pos[0], pos[1], pos[2], scale[0], scale[1], scale[2]);
         }
-        
+
         // Joint pos overrides
         for (std::vector<std::string>::iterator name_iter = all_names.begin();
              name_iter != all_names.end(); ++name_iter)
         {
             LLJoint *pJoint = getJoint(*name_iter);
-		
-			LLVector3 pos;
-			LLUUID mesh_id;
 
-			if (pJoint && pJoint->hasAttachmentPosOverride(pos,mesh_id))
-			{
+            LLVector3 pos;
+            LLUUID mesh_id;
+
+            if (pJoint && pJoint->hasAttachmentPosOverride(pos,mesh_id))
+            {
                 S32 num_pos_overrides;
                 std::set<LLVector3> distinct_pos_overrides;
                 pJoint->getAllAttachmentPosOverrides(num_pos_overrides, distinct_pos_overrides);
-				apr_file_printf( file, "\t\t<joint_offset name=\"%s\" position=\"%f %f %f\" mesh_id=\"%s\" count=\"%d\" distinct=\"%d\"/>\n", 
-								 pJoint->getName().c_str(), pos[0], pos[1], pos[2], mesh_id.asString().c_str(),
+                apr_file_printf( file, "\t\t<joint_offset name=\"%s\" position=\"%f %f %f\" mesh_id=\"%s\" count=\"%d\" distinct=\"%d\"/>\n",
+                                 pJoint->getName().c_str(), pos[0], pos[1], pos[2], mesh_id.asString().c_str(),
                                  num_pos_overrides, (S32) distinct_pos_overrides.size());
-			}
-		}
+            }
+        }
         // Joint scale overrides
         for (std::vector<std::string>::iterator name_iter = all_names.begin();
              name_iter != all_names.end(); ++name_iter)
         {
             LLJoint *pJoint = getJoint(*name_iter);
-		
-			LLVector3 scale;
-			LLUUID mesh_id;
 
-			if (pJoint && pJoint->hasAttachmentScaleOverride(scale,mesh_id))
-			{
+            LLVector3 scale;
+            LLUUID mesh_id;
+
+            if (pJoint && pJoint->hasAttachmentScaleOverride(scale,mesh_id))
+            {
                 S32 num_scale_overrides;
                 std::set<LLVector3> distinct_scale_overrides;
                 pJoint->getAllAttachmentPosOverrides(num_scale_overrides, distinct_scale_overrides);
-				apr_file_printf( file, "\t\t<joint_scale name=\"%s\" scale=\"%f %f %f\" mesh_id=\"%s\" count=\"%d\" distinct=\"%d\"/>\n",
-								 pJoint->getName().c_str(), scale[0], scale[1], scale[2], mesh_id.asString().c_str(),
+                apr_file_printf( file, "\t\t<joint_scale name=\"%s\" scale=\"%f %f %f\" mesh_id=\"%s\" count=\"%d\" distinct=\"%d\"/>\n",
+                                 pJoint->getName().c_str(), scale[0], scale[1], scale[2], mesh_id.asString().c_str(),
                                  num_scale_overrides, (S32) distinct_scale_overrides.size());
-			}
-		}
-		F32 pelvis_fixup;
-		LLUUID mesh_id;
-		if (hasPelvisFixup(pelvis_fixup, mesh_id))
-		{
-			apr_file_printf( file, "\t\t<pelvis_fixup z=\"%f\" mesh_id=\"%s\"/>\n", 
-							 pelvis_fixup, mesh_id.asString().c_str());
-		}
+            }
+        }
+        F32 pelvis_fixup;
+        LLUUID mesh_id;
+        if (hasPelvisFixup(pelvis_fixup, mesh_id))
+        {
+            apr_file_printf( file, "\t\t<pelvis_fixup z=\"%f\" mesh_id=\"%s\"/>\n",
+                             pelvis_fixup, mesh_id.asString().c_str());
+        }
 
         LLVector3 rp = getRootJoint()->getWorldPosition();
         LLVector4a rpv;
         rpv.load3(rp.mV);
-        
+
         for (S32 joint_num = 0; joint_num < LL_CHARACTER_MAX_ANIMATED_JOINTS; joint_num++)
         {
             LLJoint *joint = getJoint(joint_num);
@@ -10480,12 +10480,12 @@ void LLVOAvatar::dumpArchetypeXMLCallback(const std::vector<std::string>& filena
                 if (rig_info.isRiggedTo())
                 {
                     LLVector4a new_extents[2];
-					const LLMatrix4a& mat = joint->getWorldMatrix();
+                    const LLMatrix4a& mat = joint->getWorldMatrix();
                     mat.mulBoundBox(rig_info.getRiggedExtents(), new_extents);
                     LLVector4a rrp[2];
                     rrp[0].setSub(new_extents[0],rpv);
                     rrp[1].setSub(new_extents[1],rpv);
-                    apr_file_printf( file, "\t\t<joint_rig_info num=\"%d\" name=\"%s\" min=\"%f %f %f\" max=\"%f %f %f\" tmin=\"%f %f %f\" tmax=\"%f %f %f\"/>\n", 
+                    apr_file_printf( file, "\t\t<joint_rig_info num=\"%d\" name=\"%s\" min=\"%f %f %f\" max=\"%f %f %f\" tmin=\"%f %f %f\" tmax=\"%f %f %f\"/>\n",
                                      joint_num,
                                      joint->getName().c_str(),
                                      rig_info.getRiggedExtents()[0][0],
@@ -10504,136 +10504,136 @@ void LLVOAvatar::dumpArchetypeXMLCallback(const std::vector<std::string>& filena
             }
         }
 
-		bool ultra_verbose = false;
-		if (isSelf() && ultra_verbose)
-		{
-			// show the cloned params inside the wearables as well.
-			gAgentAvatarp->dumpWearableInfo(outfile);
-		}
+        bool ultra_verbose = false;
+        if (isSelf() && ultra_verbose)
+        {
+            // show the cloned params inside the wearables as well.
+            gAgentAvatarp->dumpWearableInfo(outfile);
+        }
 
-		apr_file_printf( file, "\t</archetype>\n" );
-		apr_file_printf( file, "\n</linden_genepool>\n" );
+        apr_file_printf( file, "\t</archetype>\n" );
+        apr_file_printf( file, "\n</linden_genepool>\n" );
 
-		LLSD args;
-		args["PATH"] = fullpath;
-		LLNotificationsUtil::add("AppearanceToXMLSaved", args);
-	}
-	else
-	{
-		LLNotificationsUtil::add("AppearanceToXMLFailed");
-	}
-	// File will close when handle goes out of scope
-	LL_INFOS("DumpArchetypeXML") << "Archetype xml written successfully!" << LL_ENDL;
-	LLNotificationsUtil::add("DumpArchetypeSuccess", LLSD().with("FILE_PATH", fullpath));
+        LLSD args;
+        args["PATH"] = fullpath;
+        LLNotificationsUtil::add("AppearanceToXMLSaved", args);
+    }
+    else
+    {
+        LLNotificationsUtil::add("AppearanceToXMLFailed");
+    }
+    // File will close when handle goes out of scope
+    LL_INFOS("DumpArchetypeXML") << "Archetype xml written successfully!" << LL_ENDL;
+    LLNotificationsUtil::add("DumpArchetypeSuccess", LLSD().with("FILE_PATH", fullpath));
 }
 
 
 void LLVOAvatar::setVisibilityRank(U32 rank)
 {
-	if (mDrawable.isNull() || mDrawable->isDead())
-	{
-		// do nothing
-		return;
-	}
-	mVisibilityRank = rank;
+    if (mDrawable.isNull() || mDrawable->isDead())
+    {
+        // do nothing
+        return;
+    }
+    mVisibilityRank = rank;
 }
 
 // Assumes LLVOAvatar::sInstances has already been sorted.
 S32 LLVOAvatar::getUnbakedPixelAreaRank()
 {
-	S32 rank = 1;
-	for (LLCharacter* character : LLCharacter::sInstances)
-	{
-		LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
-		if (inst == this)
-		{
-			return rank;
-		}
-		else if (!inst->isDead() && !inst->isFullyBaked())
-		{
-			rank++;
-		}
-	}
+    S32 rank = 1;
+    for (LLCharacter* character : LLCharacter::sInstances)
+    {
+        LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
+        if (inst == this)
+        {
+            return rank;
+        }
+        else if (!inst->isDead() && !inst->isFullyBaked())
+        {
+            rank++;
+        }
+    }
 
-	llassert(0);
-	return 0;
+    llassert(0);
+    return 0;
 }
 
 struct CompareScreenAreaGreater
 {
-	BOOL operator()(const LLCharacter* const& lhs, const LLCharacter* const& rhs)
-	{
-		return lhs->getPixelArea() > rhs->getPixelArea();
-	}
+    BOOL operator()(const LLCharacter* const& lhs, const LLCharacter* const& rhs)
+    {
+        return lhs->getPixelArea() > rhs->getPixelArea();
+    }
 };
 
 // static
 void LLVOAvatar::cullAvatarsByPixelArea()
 {
-	std::sort(LLCharacter::sInstances.begin(), LLCharacter::sInstances.end(), CompareScreenAreaGreater());
-	
-	// Update the avatars that have changed status
-	U32 rank = 2; //1 is reserved for self. 
-	for (LLCharacter* character : LLCharacter::sInstances)
-	{
-		LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
-		BOOL culled;
-		if (inst->isSelf() || inst->isFullyBaked())
-		{
-			culled = FALSE;
-		}
-		else 
-		{
-			culled = TRUE;
-		}
-
-		if (inst->mCulled != culled)
-		{
-			inst->mCulled = culled;
+    std::sort(LLCharacter::sInstances.begin(), LLCharacter::sInstances.end(), CompareScreenAreaGreater());
+
+    // Update the avatars that have changed status
+    U32 rank = 2; //1 is reserved for self.
+    for (LLCharacter* character : LLCharacter::sInstances)
+    {
+        LLVOAvatar* inst = static_cast<LLVOAvatar*>(character);
+        BOOL culled;
+        if (inst->isSelf() || inst->isFullyBaked())
+        {
+            culled = FALSE;
+        }
+        else
+        {
+            culled = TRUE;
+        }
+
+        if (inst->mCulled != culled)
+        {
+            inst->mCulled = culled;
 #ifdef SHOW_DEBUG
-			LL_DEBUGS() << "avatar " << inst->getID() << (culled ? " start culled" : " start not culled" ) << LL_ENDL;
+            LL_DEBUGS() << "avatar " << inst->getID() << (culled ? " start culled" : " start not culled" ) << LL_ENDL;
 #endif
-			inst->updateMeshTextures();
-		}
-
-		if (inst->isSelf())
-		{
-			inst->setVisibilityRank(1);
-		}
-		else if (inst->mDrawable.notNull() && inst->mDrawable->isVisible())
-		{
-			inst->setVisibilityRank(rank++);
-		}
-	}
-
-	// runway - this doesn't really detect gray/grey state.
-	S32 grey_avatars = 0;
-	if (!LLVOAvatar::areAllNearbyInstancesBaked(grey_avatars))
-	{
-		if (gFrameTimeSeconds != sUnbakedUpdateTime) // only update once per frame
-		{
-			sUnbakedUpdateTime = gFrameTimeSeconds;
-			sUnbakedTime += gFrameIntervalSeconds.value();
-		}
-		if (grey_avatars > 0)
-		{
-			if (gFrameTimeSeconds != sGreyUpdateTime) // only update once per frame
-			{
-				sGreyUpdateTime = gFrameTimeSeconds;
-				sGreyTime += gFrameIntervalSeconds.value();
-			}
-		}
-	}
+            inst->updateMeshTextures();
+        }
+
+        if (inst->isSelf())
+        {
+            inst->setVisibilityRank(1);
+        }
+        else if (inst->mDrawable.notNull() && inst->mDrawable->isVisible())
+        {
+            inst->setVisibilityRank(rank++);
+        }
+    }
+
+    // runway - this doesn't really detect gray/grey state.
+    S32 grey_avatars = 0;
+    if (!LLVOAvatar::areAllNearbyInstancesBaked(grey_avatars))
+    {
+        if (gFrameTimeSeconds != sUnbakedUpdateTime) // only update once per frame
+        {
+            sUnbakedUpdateTime = gFrameTimeSeconds;
+            sUnbakedTime += gFrameIntervalSeconds.value();
+        }
+        if (grey_avatars > 0)
+        {
+            if (gFrameTimeSeconds != sGreyUpdateTime) // only update once per frame
+            {
+                sGreyUpdateTime = gFrameTimeSeconds;
+                sGreyTime += gFrameIntervalSeconds.value();
+            }
+        }
+    }
 }
 
 void LLVOAvatar::startAppearanceAnimation()
 {
-	if(!mAppearanceAnimating)
-	{
-		mAppearanceAnimating = TRUE;
-		mAppearanceMorphTimer.reset();
-		mLastAppearanceBlendTime = 0.f;
-	}
+    if(!mAppearanceAnimating)
+    {
+        mAppearanceAnimating = TRUE;
+        mAppearanceMorphTimer.reset();
+        mLastAppearanceBlendTime = 0.f;
+    }
 }
 
 // virtual
@@ -10644,35 +10644,35 @@ void LLVOAvatar::removeMissingBakedTextures()
 //virtual
 void LLVOAvatar::updateRegion(LLViewerRegion *regionp)
 {
-	LLViewerObject::updateRegion(regionp);
+    LLViewerObject::updateRegion(regionp);
 }
 
 // virtual
 std::string LLVOAvatar::getFullname() const
 {
-	std::string name;
+    std::string name;
 
-	LLNameValue* first = getNVPair("FirstName"); 
-	LLNameValue* last  = getNVPair("LastName"); 
-	if (first && last)
-	{
-		name = LLCacheName::buildFullName( first->getString(), last->getString() );
-	}
+    LLNameValue* first = getNVPair("FirstName");
+    LLNameValue* last  = getNVPair("LastName");
+    if (first && last)
+    {
+        name = LLCacheName::buildFullName( first->getString(), last->getString() );
+    }
 
-	return name;
+    return name;
 }
 
 LLHost LLVOAvatar::getObjectHost() const
 {
-	LLViewerRegion* region = getRegion();
-	if (region && !isDead())
-	{
-		return region->getHost();
-	}
-	else
-	{
-		return LLHost();
-	}
+    LLViewerRegion* region = getRegion();
+    if (region && !isDead())
+    {
+        return region->getHost();
+    }
+    else
+    {
+        return LLHost();
+    }
 }
 
 BOOL LLVOAvatar::updateLOD()
@@ -10681,36 +10681,36 @@ BOOL LLVOAvatar::updateLOD()
     {
         return FALSE;
     }
-    
-	if (!LLPipeline::sImpostorRender && isImpostor() && 0 != mDrawable->getNumFaces() && mDrawable->getFace(0)->hasGeometry())
-	{
-		return TRUE;
-	}
 
-	BOOL res = updateJointLODs();
+    if (!LLPipeline::sImpostorRender && isImpostor() && 0 != mDrawable->getNumFaces() && mDrawable->getFace(0)->hasGeometry())
+    {
+        return TRUE;
+    }
 
-	LLFace* facep = mDrawable->getFace(0);
-	if (!facep || !facep->getVertexBuffer())
-	{
-		dirtyMesh(2);
-	}
+    BOOL res = updateJointLODs();
+
+    LLFace* facep = mDrawable->getFace(0);
+    if (!facep || !facep->getVertexBuffer())
+    {
+        dirtyMesh(2);
+    }
 
-	if (mDirtyMesh >= 2 || mDrawable->isState(LLDrawable::REBUILD_GEOMETRY))
-	{	//LOD changed or new mesh created, allocate new vertex buffer if needed
-		updateMeshData();
-		mDirtyMesh = 0;
-		mNeedsSkin = TRUE;
-		mDrawable->clearState(LLDrawable::REBUILD_GEOMETRY);
-	}
-	updateVisibility();
+    if (mDirtyMesh >= 2 || mDrawable->isState(LLDrawable::REBUILD_GEOMETRY))
+    {   //LOD changed or new mesh created, allocate new vertex buffer if needed
+        updateMeshData();
+        mDirtyMesh = 0;
+        mNeedsSkin = TRUE;
+        mDrawable->clearState(LLDrawable::REBUILD_GEOMETRY);
+    }
+    updateVisibility();
 
-	return res;
+    return res;
 }
 
 void LLVOAvatar::updateLODRiggedAttachments()
 {
-	updateLOD();
-	rebuildRiggedAttachments();
+    updateLOD();
+    rebuildRiggedAttachments();
 }
 
 void showRigInfoTabExtents(LLVOAvatar *avatar, LLJointRiggingInfoTab& tab, S32& count_rigged, S32& count_box)
@@ -10724,7 +10724,7 @@ void showRigInfoTabExtents(LLVOAvatar *avatar, LLJointRiggingInfoTab& tab, S32&
         {
             count_rigged++;
             LLJoint *joint = avatar->getJoint(i);
-            LL_DEBUGS("RigSpam") << "joint " << i << " name " << joint->getName() << " box " 
+            LL_DEBUGS("RigSpam") << "joint " << i << " name " << joint->getName() << " box "
                                  << tab[i].getRiggedExtents()[0] << ", " << tab[i].getRiggedExtents()[1] << LL_ENDL;
             if ((!tab[i].getRiggedExtents()[0].equals3(zero_vec)) ||
                 (!tab[i].getRiggedExtents()[1].equals3(zero_vec)))
@@ -10739,13 +10739,13 @@ void LLVOAvatar::getAssociatedVolumes(std::vector<LLVOVolume*>& volumes)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
 
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-		{
-			if (!attached_object)
-				continue;
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        for (LLViewerObject* attached_object : attachment->mAttachedObjects)
+        {
+            if (!attached_object)
+                continue;
 
             LLVOVolume *volume = attached_object->asVolume();
             if (volume)
@@ -10762,8 +10762,8 @@ void LLVOAvatar::getAssociatedVolumes(std::vector<LLVOVolume*>& volumes)
 
             for (LLViewerObject* childp : attached_object->getChildren())
             {
-				if (!childp) 
-					continue;
+                if (!childp)
+                    continue;
 
                 LLVOVolume *volume = childp->asVolume();
                 if (volume)
@@ -10776,8 +10776,8 @@ void LLVOAvatar::getAssociatedVolumes(std::vector<LLVOVolume*>& volumes)
 
     if (isControlAvatar())
     {
-		LLControlAvatar* control_av = static_cast<LLControlAvatar*>(this);
-		LLVOVolume *volp = control_av->mRootVolp;
+        LLControlAvatar* control_av = static_cast<LLControlAvatar*>(this);
+        LLVOVolume *volp = control_av->mRootVolp;
         if (volp)
         {
             volumes.push_back(volp);
@@ -10804,18 +10804,18 @@ void LLVOAvatar::updateRiggingInfo()
 #endif
 
     static std::vector<LLVOVolume*> volumes;
-	volumes.clear();
-	if (volumes.capacity() < mLastAssocVolSize)
-	{
-		volumes.reserve(mLastAssocVolSize);
-	}
-	getAssociatedVolumes(volumes);
+    volumes.clear();
+    if (volumes.capacity() < mLastAssocVolSize)
+    {
+        volumes.reserve(mLastAssocVolSize);
+    }
+    getAssociatedVolumes(volumes);
     mLastAssocVolSize = volumes.size();
 
     size_t rig_hash;
     size_t rig_count;
     {
-        
+
         // Get current rigging info key
         rigging_info_hash_vec_t curr_rigging_info_key;
         curr_rigging_info_key.reserve(mLastRiggingInfoMeshCount);
@@ -10837,8 +10837,8 @@ void LLVOAvatar::updateRiggingInfo()
         }
     }
 
-	// Something changed. Update.
-	mLastRiggingInfoKeyHash = rig_hash;
+    // Something changed. Update.
+    mLastRiggingInfoKeyHash = rig_hash;
     mLastRiggingInfoMeshCount = rig_count;
     mJointRiggingInfoTab.clear();
     for (LLVOVolume* vol : volumes)
@@ -10851,7 +10851,7 @@ void LLVOAvatar::updateRiggingInfo()
 #if DEBUG_SKINNING
     LL_DEBUGS("RigSpammish") << getFullname() << " after update rig tab:" << LL_ENDL;
 
-	LL_DEBUGS("RigSpammish") << "uses ";
+    LL_DEBUGS("RigSpammish") << "uses ";
     S32 joint_count, box_count;
     showRigInfoTabExtents(this, mJointRiggingInfoTab, joint_count, box_count);
     LL_CONT << joint_count << " joints " << " nonzero boxes: " << box_count << LL_ENDL;
@@ -10864,115 +10864,115 @@ void LLVOAvatar::onActiveOverrideMeshesChanged()
 }
 
 U32 LLVOAvatar::getPartitionType() const
-{ 
-	// Avatars merely exist as drawables in the bridge partition
-	return mIsControlAvatar ? LLViewerRegion::PARTITION_CONTROL_AV : LLViewerRegion::PARTITION_AVATAR;
+{
+    // Avatars merely exist as drawables in the bridge partition
+    return mIsControlAvatar ? LLViewerRegion::PARTITION_CONTROL_AV : LLViewerRegion::PARTITION_AVATAR;
 }
 
 //static
 void LLVOAvatar::updateImpostors()
 {
-	LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
+    LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
 
     std::vector<LLCharacter*> instances_copy = LLCharacter::sInstances;
-	for (LLCharacter* character : instances_copy)
-	{
-		LLVOAvatar* avatar = static_cast<LLVOAvatar*>(character);
-		if (!avatar->isDead()
-			&& avatar->isVisible()
-			&& avatar->isImpostor()
-			&& avatar->needsImpostorUpdate())
-		{
+    for (LLCharacter* character : instances_copy)
+    {
+        LLVOAvatar* avatar = static_cast<LLVOAvatar*>(character);
+        if (!avatar->isDead()
+            && avatar->isVisible()
+            && avatar->isImpostor()
+            && avatar->needsImpostorUpdate())
+        {
             avatar->calcMutedAVColor();
-			gPipeline.generateImpostor(avatar);
-		}
-	}
+            gPipeline.generateImpostor(avatar);
+        }
+    }
 
-	LLCharacter::sAllowInstancesChange = TRUE;
+    LLCharacter::sAllowInstancesChange = TRUE;
 }
 
 // virtual
 BOOL LLVOAvatar::isImpostor()
 {
-	return isVisuallyMuted() || (sLimitNonImpostors && (mUpdatePeriod > 1));
+    return isVisuallyMuted() || (sLimitNonImpostors && (mUpdatePeriod > 1));
 }
 
 BOOL LLVOAvatar::shouldImpostor(const F32 rank_factor)
 {
-	if (isSelf())
-	{
-		return false;
-	}
-	if (isVisuallyMuted())
-	{
-		return true;
-	}
-	return sLimitNonImpostors && (mVisibilityRank > sMaxNonImpostors * rank_factor);
+    if (isSelf())
+    {
+        return false;
+    }
+    if (isVisuallyMuted())
+    {
+        return true;
+    }
+    return sLimitNonImpostors && (mVisibilityRank > sMaxNonImpostors * rank_factor);
 }
 
 BOOL LLVOAvatar::needsImpostorUpdate() const
 {
-	return mNeedsImpostorUpdate;
+    return mNeedsImpostorUpdate;
 }
 
 const LLVector3& LLVOAvatar::getImpostorOffset() const
 {
-	return mImpostorOffset;
+    return mImpostorOffset;
 }
 
 const LLVector2& LLVOAvatar::getImpostorDim() const
 {
-	return mImpostorDim;
+    return mImpostorDim;
 }
 
 void LLVOAvatar::setImpostorDim(const LLVector2& dim)
 {
-	mImpostorDim = dim;
+    mImpostorDim = dim;
 }
 
 void LLVOAvatar::cacheImpostorValues()
 {
-	getImpostorValues(mImpostorExtents, mImpostorAngle, mImpostorDistance);
+    getImpostorValues(mImpostorExtents, mImpostorAngle, mImpostorDistance);
 }
 
 void LLVOAvatar::getImpostorValues(LLVector4a* extents, LLVector3& angle, F32& distance) const
 {
-	const LLVector4a* ext = mDrawable->getSpatialExtents();
-	extents[0] = ext[0];
-	extents[1] = ext[1];
+    const LLVector4a* ext = mDrawable->getSpatialExtents();
+    extents[0] = ext[0];
+    extents[1] = ext[1];
 
-	auto& vwrCamera = LLViewerCamera::instance();
+    auto& vwrCamera = LLViewerCamera::instance();
 
-	LLVector3 at = vwrCamera.getOrigin()-(getRenderPosition()+mImpostorOffset);
-	distance = at.normalize();
-	F32 da = 1.f - (at* vwrCamera.getAtAxis());
-	angle.mV[0] = vwrCamera.getYaw()*da;
-	angle.mV[1] = vwrCamera.getPitch()*da;
-	angle.mV[2] = da;
+    LLVector3 at = vwrCamera.getOrigin()-(getRenderPosition()+mImpostorOffset);
+    distance = at.normalize();
+    F32 da = 1.f - (at* vwrCamera.getAtAxis());
+    angle.mV[0] = vwrCamera.getYaw()*da;
+    angle.mV[1] = vwrCamera.getPitch()*da;
+    angle.mV[2] = da;
 }
 
 // static
 const U32 LLVOAvatar::NON_IMPOSTORS_MAX_SLIDER = 66; /* Must equal the maximum allowed the RenderAvatarMaxNonImpostors
-										   * slider in panel_preferences_graphics1.xml */
+                                           * slider in panel_preferences_graphics1.xml */
 
 // static
 void LLVOAvatar::updateImpostorRendering(U32 newMaxNonImpostorsValue)
 {
 #ifdef SHOW_DEBUG
-	U32  oldmax = sMaxNonImpostors;
-	bool oldflg = sLimitNonImpostors;
+    U32  oldmax = sMaxNonImpostors;
+    bool oldflg = sLimitNonImpostors;
 #endif
 
-	if (NON_IMPOSTORS_MAX_SLIDER <= newMaxNonImpostorsValue)
-	{
-		sMaxNonImpostors = 0;
-	}
-	else
-	{
-		sMaxNonImpostors = newMaxNonImpostorsValue;
-	}
-	// the sLimitNonImpostors flag depends on whether or not sMaxNonImpostors is set to the no-limit value (0)
-	sLimitNonImpostors = (0 != sMaxNonImpostors);
+    if (NON_IMPOSTORS_MAX_SLIDER <= newMaxNonImpostorsValue)
+    {
+        sMaxNonImpostors = 0;
+    }
+    else
+    {
+        sMaxNonImpostors = newMaxNonImpostorsValue;
+    }
+    // the sLimitNonImpostors flag depends on whether or not sMaxNonImpostors is set to the no-limit value (0)
+    sLimitNonImpostors = (0 != sMaxNonImpostors);
 #ifdef SHOW_DEBUG
     if ( oldflg != sLimitNonImpostors )
     {
@@ -11000,9 +11000,9 @@ void LLVOAvatar::idleUpdateRenderComplexity()
     }
 
     // Render Complexity
-    calculateUpdateRenderComplexity(); // Update mVisualComplexity if needed	
+    calculateUpdateRenderComplexity(); // Update mVisualComplexity if needed
 
-	bool autotune = LLPerfStats::tunables.userAutoTuneEnabled && !mIsControlAvatar && !isSelf();
+    bool autotune = LLPerfStats::tunables.userAutoTuneEnabled && !mIsControlAvatar && !isSelf();
     if (autotune && !isDead())
     {
         static LLCachedControl<F32> render_far_clip(gSavedSettings, "RenderFarClip", 64);
@@ -11035,7 +11035,7 @@ void LLVOAvatar::updateNearbyAvatarCount()
 {
     static LLFrameTimer agent_update_timer;
 
-	if (agent_update_timer.getElapsedTimeF32() > 1.0f)
+    if (agent_update_timer.getElapsedTimeF32() > 1.0f)
     {
         S32 avs_nearby = 0;
         static LLCachedControl<F32> render_far_clip(gSavedSettings, "RenderFarClip", 64);
@@ -11063,92 +11063,92 @@ void LLVOAvatar::updateNearbyAvatarCount()
 
 void LLVOAvatar::idleUpdateDebugInfo()
 {
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_AVATAR_DRAW_INFO))
-	{
-		std::string info_line;
-		F32 red_level;
-		F32 green_level;
-		LLColor4 info_color;
-		LLFontGL::StyleFlags info_style;
-		
-		if ( !mText )
-		{
-			initHudText();
-			mText->setFadeDistance(20.0, 5.0); // limit clutter in large crowds
-		}
-		else
-		{
-			mText->clearString(); // clear debug text
-		}
-
-		/*
-		 * NOTE: the logic for whether or not each of the values below
-		 * controls muting MUST match that in the isVisuallyMuted and isTooComplex methods.
-		 */
-
-		static LLCachedControl<U32> max_render_cost(gSavedSettings, "RenderAvatarMaxComplexity", 0);
-		info_line = llformat("%d Complexity", mVisualComplexity);
-
-		if (max_render_cost != 0) // zero means don't care, so don't bother coloring based on this
-		{
-			green_level = 1.f-llclamp(((F32) mVisualComplexity-(F32)max_render_cost)/(F32)max_render_cost, 0.f, 1.f);
-			red_level   = llmin((F32) mVisualComplexity/(F32)max_render_cost, 1.f);
-			info_color.set(red_level, green_level, 0.0, 1.0);
-			info_style = (  mVisualComplexity > max_render_cost
-						  ? LLFontGL::BOLD : LLFontGL::NORMAL );
-		}
-		else
-		{
-			info_color.set(LLColor4::grey);
-			info_style = LLFontGL::NORMAL;
-		}
-		mText->addLine(info_line, info_color, info_style);
-
-		// Visual rank
-		info_line = llformat("%d rank", mVisibilityRank);
-		// Use grey for imposters, white for normal rendering or no impostors
-		info_color.set(isImpostor() ? LLColor4::grey : (isControlAvatar() ? LLColor4::yellow : LLColor4::white));
-		info_style = LLFontGL::NORMAL;
-		mText->addLine(info_line, info_color, info_style);
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_AVATAR_DRAW_INFO))
+    {
+        std::string info_line;
+        F32 red_level;
+        F32 green_level;
+        LLColor4 info_color;
+        LLFontGL::StyleFlags info_style;
+
+        if ( !mText )
+        {
+            initHudText();
+            mText->setFadeDistance(20.0, 5.0); // limit clutter in large crowds
+        }
+        else
+        {
+            mText->clearString(); // clear debug text
+        }
+
+        /*
+         * NOTE: the logic for whether or not each of the values below
+         * controls muting MUST match that in the isVisuallyMuted and isTooComplex methods.
+         */
+
+        static LLCachedControl<U32> max_render_cost(gSavedSettings, "RenderAvatarMaxComplexity", 0);
+        info_line = llformat("%d Complexity", mVisualComplexity);
+
+        if (max_render_cost != 0) // zero means don't care, so don't bother coloring based on this
+        {
+            green_level = 1.f-llclamp(((F32) mVisualComplexity-(F32)max_render_cost)/(F32)max_render_cost, 0.f, 1.f);
+            red_level   = llmin((F32) mVisualComplexity/(F32)max_render_cost, 1.f);
+            info_color.set(red_level, green_level, 0.0, 1.0);
+            info_style = (  mVisualComplexity > max_render_cost
+                          ? LLFontGL::BOLD : LLFontGL::NORMAL );
+        }
+        else
+        {
+            info_color.set(LLColor4::grey);
+            info_style = LLFontGL::NORMAL;
+        }
+        mText->addLine(info_line, info_color, info_style);
+
+        // Visual rank
+        info_line = llformat("%d rank", mVisibilityRank);
+        // Use grey for imposters, white for normal rendering or no impostors
+        info_color.set(isImpostor() ? LLColor4::grey : (isControlAvatar() ? LLColor4::yellow : LLColor4::white));
+        info_style = LLFontGL::NORMAL;
+        mText->addLine(info_line, info_color, info_style);
 
         // Triangle count
-        mText->addLine(std::string("VisTris ") + LLStringOps::getReadableNumber(mAttachmentVisibleTriangleCount), 
+        mText->addLine(std::string("VisTris ") + LLStringOps::getReadableNumber(mAttachmentVisibleTriangleCount),
                        info_color, info_style);
-        mText->addLine(std::string("EstMaxTris ") + LLStringOps::getReadableNumber(mAttachmentEstTriangleCount), 
+        mText->addLine(std::string("EstMaxTris ") + LLStringOps::getReadableNumber(mAttachmentEstTriangleCount),
                        info_color, info_style);
 
-		// Attachment Surface Area
-		static LLCachedControl<F32> max_attachment_area(gSavedSettings, "RenderAutoMuteSurfaceAreaLimit", 1000.0f);
-		info_line = llformat("%.0f m^2", mAttachmentSurfaceArea);
+        // Attachment Surface Area
+        static LLCachedControl<F32> max_attachment_area(gSavedSettings, "RenderAutoMuteSurfaceAreaLimit", 1000.0f);
+        info_line = llformat("%.0f m^2", mAttachmentSurfaceArea);
 
-		if (max_render_cost != 0 && max_attachment_area != 0) // zero means don't care, so don't bother coloring based on this
-		{
-			green_level = 1.f-llclamp((mAttachmentSurfaceArea-max_attachment_area)/max_attachment_area, 0.f, 1.f);
-			red_level   = llmin(mAttachmentSurfaceArea/max_attachment_area, 1.f);
-			info_color.set(red_level, green_level, 0.0, 1.0);
-			info_style = (  mAttachmentSurfaceArea > max_attachment_area
-						  ? LLFontGL::BOLD : LLFontGL::NORMAL );
+        if (max_render_cost != 0 && max_attachment_area != 0) // zero means don't care, so don't bother coloring based on this
+        {
+            green_level = 1.f-llclamp((mAttachmentSurfaceArea-max_attachment_area)/max_attachment_area, 0.f, 1.f);
+            red_level   = llmin(mAttachmentSurfaceArea/max_attachment_area, 1.f);
+            info_color.set(red_level, green_level, 0.0, 1.0);
+            info_style = (  mAttachmentSurfaceArea > max_attachment_area
+                          ? LLFontGL::BOLD : LLFontGL::NORMAL );
 
-		}
-		else
-		{
-			info_color.set(LLColor4::grey);
-			info_style = LLFontGL::NORMAL;
-		}
+        }
+        else
+        {
+            info_color.set(LLColor4::grey);
+            info_style = LLFontGL::NORMAL;
+        }
 
-		mText->addLine(info_line, info_color, info_style);
+        mText->addLine(info_line, info_color, info_style);
 
-		updateText(); // corrects position
-	}
+        updateText(); // corrects position
+    }
 }
 
 void LLVOAvatar::updateVisualComplexity()
 {
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("AvatarRender") << "avatar " << getID() << " appearance changed" << LL_ENDL;
+    LL_DEBUGS("AvatarRender") << "avatar " << getID() << " appearance changed" << LL_ENDL;
 #endif
-	// Set the cache time to in the past so it's updated ASAP
-	mVisualComplexityStale = true;
+    // Set the cache time to in the past so it's updated ASAP
+    mVisualComplexityStale = true;
 }
 
 
@@ -11161,7 +11161,7 @@ void LLVOAvatar::accountRenderComplexityForObject(
     LLVOVolume::texture_cost_t& textures,
     U32& cost,
     hud_complexity_list_t& hud_complexity_list,
-	object_complexity_list_t& object_complexity_list,
+    object_complexity_list_t& object_complexity_list,
     std::map<LLUUID, U32>& item_complexity,
     std::map<LLUUID, U32>& temp_item_complexity)
 {
@@ -11191,10 +11191,10 @@ void LLVOAvatar::accountRenderComplexityForObject(
                 }
                 attachment_volume_cost += volume->getRenderCost(textures);
 
-				const_child_list_t& children = volume->getChildren();
-				for (LLViewerObject* child_obj : children)
-				{
-					LLVOVolume *child = child_obj ? child_obj->asVolume() : nullptr;
+                const_child_list_t& children = volume->getChildren();
+                for (LLViewerObject* child_obj : children)
+                {
+                    LLVOVolume *child = child_obj ? child_obj->asVolume() : nullptr;
 
                     if (child)
                     {
@@ -11230,14 +11230,14 @@ void LLVOAvatar::accountRenderComplexityForObject(
                     object_complexity.objectId = attached_object->getAttachmentItemID();
                     object_complexity.objectCost = attachment_total_cost;
                     object_complexity_list.push_back(object_complexity);
-					if (!attached_object->isTempAttachment())
-					{
-						item_complexity.insert(std::make_pair(attached_object->getAttachmentItemID(), (U32)attachment_total_cost));
-					}
-					else
-					{
-						temp_item_complexity.insert(std::make_pair(attached_object->getID(), (U32)attachment_total_cost));
-					}
+                    if (!attached_object->isTempAttachment())
+                    {
+                        item_complexity.insert(std::make_pair(attached_object->getAttachmentItemID(), (U32)attachment_total_cost));
+                    }
+                    else
+                    {
+                        temp_item_complexity.insert(std::make_pair(attached_object->getID(), (U32)attachment_total_cost));
+                    }
                 }
             }
         }
@@ -11268,7 +11268,7 @@ void LLVOAvatar::accountRenderComplexityForObject(
             LLViewerObject::const_child_list_t& child_list = attached_object->getChildren();
             for (LLViewerObject* childp : child_list)
             {
-				const LLVOVolume* chld_volume = childp ? childp->asVolume() : nullptr;
+                const LLVOVolume* chld_volume = childp ? childp->asVolume() : nullptr;
                 if (chld_volume)
                 {
                     is_rigged_mesh = is_rigged_mesh || chld_volume->isRiggedMeshFast();
@@ -11323,34 +11323,34 @@ void LLVOAvatar::calculateUpdateRenderComplexity()
      * the official viewer for consideration.
      *****************************************************************/
     if (mVisualComplexityStale)
-	{
-		const F64 now = LLFrameTimer::getTotalSeconds();
-		if (now < mVisualComplexityUpdateTime)
-		{
-			return;
-		}
-
-		static const U32 COMPLEXITY_BODY_PART_COST = 200;
-		static LLCachedControl<F32> max_complexity_setting(gSavedSettings, "MaxAttachmentComplexity");
-		F32 max_attachment_complexity = max_complexity_setting;
-		max_attachment_complexity = llmax(max_attachment_complexity, DEFAULT_MAX_ATTACHMENT_COMPLEXITY);
-
-		std::map<LLUUID, U32> item_complexity;
-		std::map<LLUUID, U32> temp_item_complexity;
-		U32 body_parts_complexity;
-
-		U32 cost = VISUAL_COMPLEXITY_UNKNOWN;
-		LLVOVolume::texture_cost_t textures;
-		hud_complexity_list_t hud_complexity_list;
+    {
+        const F64 now = LLFrameTimer::getTotalSeconds();
+        if (now < mVisualComplexityUpdateTime)
+        {
+            return;
+        }
+
+        static const U32 COMPLEXITY_BODY_PART_COST = 200;
+        static LLCachedControl<F32> max_complexity_setting(gSavedSettings, "MaxAttachmentComplexity");
+        F32 max_attachment_complexity = max_complexity_setting;
+        max_attachment_complexity = llmax(max_attachment_complexity, DEFAULT_MAX_ATTACHMENT_COMPLEXITY);
+
+        std::map<LLUUID, U32> item_complexity;
+        std::map<LLUUID, U32> temp_item_complexity;
+        U32 body_parts_complexity;
+
+        U32 cost = VISUAL_COMPLEXITY_UNKNOWN;
+        LLVOVolume::texture_cost_t textures;
+        hud_complexity_list_t hud_complexity_list;
         object_complexity_list_t object_complexity_list;
 
-		for (U8 baked_index = 0; baked_index < BAKED_NUM_INDICES; baked_index++)
-		{
-		    const LLAvatarAppearanceDictionary::BakedEntry *baked_dict
-				= LLAvatarAppearance::getDictionary()->getBakedTexture((EBakedTextureIndex)baked_index);
-			ETextureIndex tex_index = baked_dict->mTextureIndex;
-			if ((tex_index != TEX_SKIRT_BAKED) || (isWearingWearableType(LLWearableType::WT_SKIRT)))
-			{
+        for (U8 baked_index = 0; baked_index < BAKED_NUM_INDICES; baked_index++)
+        {
+            const LLAvatarAppearanceDictionary::BakedEntry *baked_dict
+                = LLAvatarAppearance::getDictionary()->getBakedTexture((EBakedTextureIndex)baked_index);
+            ETextureIndex tex_index = baked_dict->mTextureIndex;
+            if ((tex_index != TEX_SKIRT_BAKED) || (isWearingWearableType(LLWearableType::WT_SKIRT)))
+            {
                 // Same as isTextureVisible(), but doesn't account for isSelf to ensure identical numbers for all avatars
                 if (isIndexLocalTexture(tex_index))
                 {
@@ -11368,25 +11368,25 @@ void LLVOAvatar::calculateUpdateRenderComplexity()
                         cost += COMPLEXITY_BODY_PART_COST;
                     }
                 }
-			}
-		}
+            }
+        }
 #ifdef SHOW_DEBUG
         LL_DEBUGS("ARCdetail") << "Avatar body parts complexity: " << cost << LL_ENDL;
 #endif
 
-		body_parts_complexity = cost;
+        body_parts_complexity = cost;
 
         mAttachmentVisibleTriangleCount = 0;
         mAttachmentEstTriangleCount = 0.f;
         mAttachmentSurfaceArea = 0.f;
-        
+
         // A standalone animated object needs to be accounted for
         // using its associated volume. Attached animated objects
         // will be covered by the subsequent loop over attachments.
         if (isControlAvatar())
         {
-			LLControlAvatar* control_av = static_cast<LLControlAvatar*>(this);
-			LLVOVolume *volp = control_av->mRootVolp;
+            LLControlAvatar* control_av = static_cast<LLControlAvatar*>(this);
+            LLVOVolume *volp = control_av->mRootVolp;
             if (volp && !volp->isAttachment())
             {
                 accountRenderComplexityForObject(volp, max_attachment_complexity,
@@ -11395,15 +11395,15 @@ void LLVOAvatar::calculateUpdateRenderComplexity()
         }
 
         // Account for complexity of all attachments.
-		for (const auto& attach_pair : mAttachmentPoints)
-		{
-			LLViewerJointAttachment* attachment = attach_pair.second;
-			for (LLViewerObject* attached_object : attachment->mAttachedObjects)
-			{
+        for (const auto& attach_pair : mAttachmentPoints)
+        {
+            LLViewerJointAttachment* attachment = attach_pair.second;
+            for (LLViewerObject* attached_object : attachment->mAttachedObjects)
+            {
                 accountRenderComplexityForObject(attached_object, max_attachment_complexity,
                                                  textures, cost, hud_complexity_list, object_complexity_list, item_complexity, temp_item_complexity);
-			}
-		}
+            }
+        }
 #ifdef SHOW_DEBUG
         if ( cost != mVisualComplexity )
         {
@@ -11421,10 +11421,10 @@ void LLVOAvatar::calculateUpdateRenderComplexity()
         }
 #endif
 
-		mVisualComplexity = cost;
-		mVisualComplexityStale = false;
-		static const F64 SECONDS_BETWEEN_COMPLEXITY_RECALC = 1.f;
-		mVisualComplexityUpdateTime = now + SECONDS_BETWEEN_COMPLEXITY_RECALC;
+        mVisualComplexity = cost;
+        mVisualComplexityStale = false;
+        static const F64 SECONDS_BETWEEN_COMPLEXITY_RECALC = 1.f;
+        mVisualComplexityUpdateTime = now + SECONDS_BETWEEN_COMPLEXITY_RECALC;
 
         static LLCachedControl<U32> show_my_complexity_changes(gSavedSettings, "ShowMyComplexityChanges", 20);
 
@@ -11443,7 +11443,7 @@ void LLVOAvatar::calculateUpdateRenderComplexity()
         }
 
         //schedule an update to ART next frame if needed
-        if (LLPerfStats::tunables.userAutoTuneEnabled && 
+        if (LLPerfStats::tunables.userAutoTuneEnabled &&
             LLPerfStats::tunables.userFPSTuningStrategy != LLPerfStats::TUNE_SCENE_ONLY &&
             !isVisuallyMuted())
         {
@@ -11463,7 +11463,7 @@ void LLVOAvatar::setVisualMuteSettings(VisualMuteSettings set)
 {
     mVisuallyMuteSetting = set;
     mNeedsImpostorUpdate = TRUE;
-	mLastImpostorUpdateReason = 7;
+    mLastImpostorUpdateReason = 7;
 
     LLRenderMuteList::getInstance()->saveVisualMuteSetting(getID(), S32(set));
 }
@@ -11471,51 +11471,51 @@ void LLVOAvatar::setVisualMuteSettings(VisualMuteSettings set)
 
 void LLVOAvatar::setOverallAppearanceNormal()
 {
-	if (isControlAvatar())
-		return;
+    if (isControlAvatar())
+        return;
 
     LLVector3 pelvis_pos = getJoint("mPelvis")->getPosition();
-	if (!getPosing()) resetSkeleton(false);
+    if (!getPosing()) resetSkeleton(false);
     getJoint("mPelvis")->setPosition(pelvis_pos);
 
-	for (auto it = mJellyAnims.begin(); it !=  mJellyAnims.end(); ++it)
-	{
-		bool is_playing = (mPlayingAnimations.find(*it) != mPlayingAnimations.end());
-		LL_DEBUGS("Avatar") << "jelly anim " << *it << " " << is_playing << LL_ENDL;
-		if (!is_playing)
-		{
-			// Anim was not requested for this av by sim, but may be playing locally
-			stopMotion(*it);
-		}
-	}
-	mJellyAnims.clear();
+    for (auto it = mJellyAnims.begin(); it !=  mJellyAnims.end(); ++it)
+    {
+        bool is_playing = (mPlayingAnimations.find(*it) != mPlayingAnimations.end());
+        LL_DEBUGS("Avatar") << "jelly anim " << *it << " " << is_playing << LL_ENDL;
+        if (!is_playing)
+        {
+            // Anim was not requested for this av by sim, but may be playing locally
+            stopMotion(*it);
+        }
+    }
+    mJellyAnims.clear();
 
-	processAnimationStateChanges();
+    processAnimationStateChanges();
 }
 
 void LLVOAvatar::setOverallAppearanceJellyDoll()
 {
-	if (isControlAvatar())
-		return;
-
-	// stop current animations
-	{
-		for ( LLVOAvatar::AnimIterator anim_it= mPlayingAnimations.begin();
-			  anim_it != mPlayingAnimations.end();
-			  ++anim_it)
-		{
-			{
-				stopMotion(anim_it->first, TRUE);
-			}
-		}
-	}
-	processAnimationStateChanges();
-
-	// Start any needed anims for jellydoll
-	updateOverallAppearanceAnimations();
-	
+    if (isControlAvatar())
+        return;
+
+    // stop current animations
+    {
+        for ( LLVOAvatar::AnimIterator anim_it= mPlayingAnimations.begin();
+              anim_it != mPlayingAnimations.end();
+              ++anim_it)
+        {
+            {
+                stopMotion(anim_it->first, TRUE);
+            }
+        }
+    }
+    processAnimationStateChanges();
+
+    // Start any needed anims for jellydoll
+    updateOverallAppearanceAnimations();
+
     LLVector3 pelvis_pos = getJoint("mPelvis")->getPosition();
-	if (!getPosing()) resetSkeleton(false);
+    if (!getPosing()) resetSkeleton(false);
     getJoint("mPelvis")->setPosition(pelvis_pos);
 
 }
@@ -11526,114 +11526,114 @@ void LLVOAvatar::setOverallAppearanceInvisible()
 
 void LLVOAvatar::updateOverallAppearance()
 {
-	AvatarOverallAppearance new_overall = getOverallAppearance();
-	if (new_overall != mOverallAppearance)
-	{
-		switch (new_overall)
-		{
-			case AOA_NORMAL:
-				setOverallAppearanceNormal();
-				break;
-			case AOA_JELLYDOLL:
-				setOverallAppearanceJellyDoll();
-				break;
-			case AOA_INVISIBLE:
-				setOverallAppearanceInvisible();
-				break;
-		}
-		mOverallAppearance = new_overall;
-		if (!isSelf())
-		{
-			mNeedsImpostorUpdate = TRUE;
-			mLastImpostorUpdateReason = 8;
-		}
-		updateMeshVisibility();
-	}
-
-	// This needs to be done even if overall appearance has not
-	// changed, since sit/stand status can be different.
-	updateOverallAppearanceAnimations();
+    AvatarOverallAppearance new_overall = getOverallAppearance();
+    if (new_overall != mOverallAppearance)
+    {
+        switch (new_overall)
+        {
+            case AOA_NORMAL:
+                setOverallAppearanceNormal();
+                break;
+            case AOA_JELLYDOLL:
+                setOverallAppearanceJellyDoll();
+                break;
+            case AOA_INVISIBLE:
+                setOverallAppearanceInvisible();
+                break;
+        }
+        mOverallAppearance = new_overall;
+        if (!isSelf())
+        {
+            mNeedsImpostorUpdate = TRUE;
+            mLastImpostorUpdateReason = 8;
+        }
+        updateMeshVisibility();
+    }
+
+    // This needs to be done even if overall appearance has not
+    // changed, since sit/stand status can be different.
+    updateOverallAppearanceAnimations();
 }
 
 void LLVOAvatar::updateOverallAppearanceAnimations()
 {
-	if (isControlAvatar())
-		return;
-
-	if (getOverallAppearance() == AOA_JELLYDOLL)
-	{
-		LLUUID motion_id;
-		if (isSitting() && getParent()) // sitting on object
-		{
-			motion_id = ANIM_AGENT_SIT_FEMALE; 
-		}
-		else if (isSitting()) // sitting on ground
-		{
-			motion_id = ANIM_AGENT_SIT_GROUND_CONSTRAINED;
-		}
-		else // standing
-		{
-			motion_id = ANIM_AGENT_STAND;
-		}
-		if (mJellyAnims.find(motion_id) == mJellyAnims.end())
-		{
-			for (auto it = mJellyAnims.begin(); it !=  mJellyAnims.end(); ++it)
-			{
-				bool is_playing = (mPlayingAnimations.find(*it) != mPlayingAnimations.end());
-				LL_DEBUGS("Avatar") << "jelly anim " << *it << " " << is_playing << LL_ENDL;
-				if (!is_playing)
-				{
-					// Anim was not requested for this av by sim, but may be playing locally
-					stopMotion(*it, TRUE);
-				}
-			}
-			mJellyAnims.clear();
-
-			startMotion(motion_id);
-			mJellyAnims.insert(motion_id);
-
-			processAnimationStateChanges();
-		}
-	}
+    if (isControlAvatar())
+        return;
+
+    if (getOverallAppearance() == AOA_JELLYDOLL)
+    {
+        LLUUID motion_id;
+        if (isSitting() && getParent()) // sitting on object
+        {
+            motion_id = ANIM_AGENT_SIT_FEMALE;
+        }
+        else if (isSitting()) // sitting on ground
+        {
+            motion_id = ANIM_AGENT_SIT_GROUND_CONSTRAINED;
+        }
+        else // standing
+        {
+            motion_id = ANIM_AGENT_STAND;
+        }
+        if (mJellyAnims.find(motion_id) == mJellyAnims.end())
+        {
+            for (auto it = mJellyAnims.begin(); it !=  mJellyAnims.end(); ++it)
+            {
+                bool is_playing = (mPlayingAnimations.find(*it) != mPlayingAnimations.end());
+                LL_DEBUGS("Avatar") << "jelly anim " << *it << " " << is_playing << LL_ENDL;
+                if (!is_playing)
+                {
+                    // Anim was not requested for this av by sim, but may be playing locally
+                    stopMotion(*it, TRUE);
+                }
+            }
+            mJellyAnims.clear();
+
+            startMotion(motion_id);
+            mJellyAnims.insert(motion_id);
+
+            processAnimationStateChanges();
+        }
+    }
 }
 
 // Based on isVisuallyMuted(), but has 3 possible results.
 LLVOAvatar::AvatarOverallAppearance LLVOAvatar::getOverallAppearance() const
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
-	AvatarOverallAppearance result = AOA_NORMAL;
-
-	// Priority order (highest priority first)
-	// * own avatar is always drawn normally
-	// * if on the "always draw normally" list, draw them normally
-	// * if on the "always visually mute" list, show as jellydoll
-	// * if explicitly muted (blocked), show as invisible
-	// * check against the render cost and attachment limits - if too complex, show as jellydoll
-	if (isSelf())
-	{
-		result = AOA_NORMAL;
-	}
-	else // !isSelf()
-	{
-		if (isInMuteList())
-		{
-			result = AOA_INVISIBLE;
-		}
-		else if (mVisuallyMuteSetting == AV_ALWAYS_RENDER)
-		{
-			result = AOA_NORMAL;
-		}
-		else if (mVisuallyMuteSetting == AV_DO_NOT_RENDER)
-		{	// Always want to see this AV as an impostor
-			result = AOA_JELLYDOLL;
-		}
-		else if (isTooComplex() || isTooSlow())
-		{
-			result = AOA_JELLYDOLL;
-		}
-	}
-
-	return result;
+    AvatarOverallAppearance result = AOA_NORMAL;
+
+    // Priority order (highest priority first)
+    // * own avatar is always drawn normally
+    // * if on the "always draw normally" list, draw them normally
+    // * if on the "always visually mute" list, show as jellydoll
+    // * if explicitly muted (blocked), show as invisible
+    // * check against the render cost and attachment limits - if too complex, show as jellydoll
+    if (isSelf())
+    {
+        result = AOA_NORMAL;
+    }
+    else // !isSelf()
+    {
+        if (isInMuteList())
+        {
+            result = AOA_INVISIBLE;
+        }
+        else if (mVisuallyMuteSetting == AV_ALWAYS_RENDER)
+        {
+            result = AOA_NORMAL;
+        }
+        else if (mVisuallyMuteSetting == AV_DO_NOT_RENDER)
+        {   // Always want to see this AV as an impostor
+            result = AOA_JELLYDOLL;
+        }
+        else if (isTooComplex() || isTooSlow())
+        {
+            result = AOA_JELLYDOLL;
+        }
+    }
+
+    return result;
 }
 
 void LLVOAvatar::calcMutedAVColor()
@@ -11645,11 +11645,11 @@ void LLVOAvatar::calcMutedAVColor()
 #endif
 
 // [RLVa:KB] - Checked: RLVa-2.2 (@setcam_avdist)
-	if (isRlvSilhouette())
-	{
-		new_color = LLColor4::silhouette;
-		change_msg = " not rendered: color is silhouette";
-	}
+    if (isRlvSilhouette())
+    {
+        new_color = LLColor4::silhouette;
+        change_msg = " not rendered: color is silhouette";
+    }
     else if (getVisualMuteSettings() == AV_DO_NOT_RENDER)
 // [/RLVa:KB]
 //    if (getVisualMuteSettings() == AV_DO_NOT_RENDER)
@@ -11672,12 +11672,12 @@ void LLVOAvatar::calcMutedAVColor()
 #ifdef COLORIZE_JELLYDOLLS
 //    else if ( mMutedAVColor == LLColor4::white || mMutedAVColor == LLColor4::grey3 || mMutedAVColor == LLColor4::grey4 )
 // [RLVa:KB] - Checked: RLVa-2.2 (@setcam_avdist)
-	else if ( mMutedAVColor == LLColor4::white || mMutedAVColor == LLColor4::grey3 || mMutedAVColor == LLColor4::grey4 || mMutedAVColor == LLColor4::silhouette)
+    else if ( mMutedAVColor == LLColor4::white || mMutedAVColor == LLColor4::grey3 || mMutedAVColor == LLColor4::grey4 || mMutedAVColor == LLColor4::silhouette)
 // [/RLVa:KB]
-	{
+    {
         // select a color based on the first byte of the agents uuid so any muted agent is always the same color
         F32 color_value = (F32) (av_id.mData[0]);
-        F32 spectrum = (color_value / 256.f);		// spectrum is between 0 and 1.f
+        F32 spectrum = (color_value / 256.f);       // spectrum is between 0 and 1.f
 
         // Array of colors.  These are arranged so only one RGB color changes between each step,
         // and it loops back to red so there is an even distribution.  It is not a heat map
@@ -11690,17 +11690,17 @@ void LLVOAvatar::calcMutedAVColor()
         F32 fractBetween = spectrum - (F32)(spectrum_index_1);  // distance between the two indexes (0-1)
 
         new_color = lerp(*spectrum_color[spectrum_index_1], *spectrum_color[spectrum_index_2], fractBetween);
-		new_color.normalize();
+        new_color.normalize();
         new_color *= 0.28f;            // Tone it down
-	}
+    }
 #endif
     else
     {
-		new_color = LLColor4::grey4;
+        new_color = LLColor4::grey4;
         change_msg = " over limit color ";
     }
 
-    if (mMutedAVColor != new_color) 
+    if (mMutedAVColor != new_color)
     {
 #ifdef SHOW_DEBUG
         LL_DEBUGS("AvatarRender") << "avatar "<< av_id << change_msg << std::setprecision(3) << new_color << LL_ENDL;
@@ -11712,38 +11712,38 @@ void LLVOAvatar::calcMutedAVColor()
 // static
 BOOL LLVOAvatar::isIndexLocalTexture(ETextureIndex index)
 {
-	return (index < 0 || index >= TEX_NUM_INDICES)
-		? false
-		: LLAvatarAppearance::getDictionary()->getTexture(index)->mIsLocalTexture;
+    return (index < 0 || index >= TEX_NUM_INDICES)
+        ? false
+        : LLAvatarAppearance::getDictionary()->getTexture(index)->mIsLocalTexture;
 }
 
 // static
 BOOL LLVOAvatar::isIndexBakedTexture(ETextureIndex index)
 {
-	return (index < 0 || index >= TEX_NUM_INDICES)
-		? false
-		: LLAvatarAppearance::getDictionary()->getTexture(index)->mIsBakedTexture;
+    return (index < 0 || index >= TEX_NUM_INDICES)
+        ? false
+        : LLAvatarAppearance::getDictionary()->getTexture(index)->mIsBakedTexture;
 }
 
 const std::string LLVOAvatar::getBakedStatusForPrintout() const
 {
-	std::string line;
+    std::string line;
 
-	for (const auto& tex_pair : LLAvatarAppearance::getDictionary()->getTextures())
-	{
-		const ETextureIndex index = tex_pair.first;
-		const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
-		if (texture_dict->mIsBakedTexture)
-		{
-			line += texture_dict->mName;
-			if (isTextureDefined(index))
-			{
-				line += "_baked";
-			}
-			line += " ";
-		}
-	}
-	return line;
+    for (const auto& tex_pair : LLAvatarAppearance::getDictionary()->getTextures())
+    {
+        const ETextureIndex index = tex_pair.first;
+        const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
+        if (texture_dict->mIsBakedTexture)
+        {
+            line += texture_dict->mName;
+            if (isTextureDefined(index))
+            {
+                line += "_baked";
+            }
+            line += " ";
+        }
+    }
+    return line;
 }
 
 
@@ -11751,7 +11751,7 @@ const std::string LLVOAvatar::getBakedStatusForPrintout() const
 //virtual
 S32 LLVOAvatar::getTexImageSize() const
 {
-	return TEX_IMAGE_SIZE_OTHER;
+    return TEX_IMAGE_SIZE_OTHER;
 }
 
 //-----------------------------------------------------------------------------
@@ -11760,50 +11760,50 @@ S32 LLVOAvatar::getTexImageSize() const
 
 F32 calc_bouncy_animation(F32 x)
 {
-	return -(cosf(x * F_PI * 2.5f - F_PI_BY_TWO))*(0.4f + x * -0.1f) + x * 1.3f;
+    return -(cosf(x * F_PI * 2.5f - F_PI_BY_TWO))*(0.4f + x * -0.1f) + x * 1.3f;
 }
 
 //virtual
 BOOL LLVOAvatar::isTextureDefined(LLAvatarAppearanceDefines::ETextureIndex te, U32 index ) const
 {
-	if (isIndexLocalTexture(te)) 
-	{
-		return FALSE;
-	}
-	
-	LLViewerTexture* imagep = getImage(te, index);
+    if (isIndexLocalTexture(te))
+    {
+        return FALSE;
+    }
+
+    LLViewerTexture* imagep = getImage(te, index);
 
-	if(!imagep)
-	{
-		LL_WARNS() << "getImage( " << te << ", " << index << " ) returned 0" << LL_ENDL;
-		return FALSE;
-	}
+    if(!imagep)
+    {
+        LL_WARNS() << "getImage( " << te << ", " << index << " ) returned 0" << LL_ENDL;
+        return FALSE;
+    }
 
-	const auto& id = imagep->getID();
-	return (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
+    const auto& id = imagep->getID();
+    return (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
 }
 
 //virtual
 BOOL LLVOAvatar::isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type, U32 index) const
 {
-	if (isIndexLocalTexture(type))
-	{
-		return isTextureDefined(type, index);
-	}
-	else
-	{
-		// baked textures can use TE images directly
-		return ((isTextureDefined(type) || isSelf())
-				&& (getTEImage(type)->getID() != IMG_INVISIBLE 
-				|| LLDrawPoolAlpha::sShowDebugAlpha));
-	}
+    if (isIndexLocalTexture(type))
+    {
+        return isTextureDefined(type, index);
+    }
+    else
+    {
+        // baked textures can use TE images directly
+        return ((isTextureDefined(type) || isSelf())
+                && (getTEImage(type)->getID() != IMG_INVISIBLE
+                || LLDrawPoolAlpha::sShowDebugAlpha));
+    }
 }
 
 //virtual
 BOOL LLVOAvatar::isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type, LLViewerWearable *wearable) const
 {
-	// non-self avatars don't have wearables
-	return FALSE;
+    // non-self avatars don't have wearables
+    return FALSE;
 }
 
 void LLVOAvatar::placeProfileQuery()
diff --git a/indra/newview/llvoavatarself.cpp b/indra/newview/llvoavatarself.cpp
index 10200269b562fee9bca6629c75a5307c5cf44be9..36d59538a7027aab6cb75272035a3d337be7c38f 100644
--- a/indra/newview/llvoavatarself.cpp
+++ b/indra/newview/llvoavatarself.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvoavatar.cpp
  * @brief Implementation of LLVOAvatar class which is a derivation fo LLViewerObject
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -41,7 +41,7 @@
 #include "lllocaltextureobject.h"
 #include "llnotificationsutil.h"
 #include "llselectmgr.h"
-#include "lltoolgrab.h"	// for needsRenderBeam
+#include "lltoolgrab.h" // for needsRenderBeam
 #include "lltoolmgr.h" // for needsRenderBeam
 #include "lltoolmorph.h"
 #include "lltrans.h"
@@ -72,31 +72,31 @@ LLPointer<LLVOAvatarSelf> gAgentAvatarp = NULL;
 
 BOOL isAgentAvatarValid()
 {
-	return (gAgentAvatarp.notNull() && gAgentAvatarp->isValid());
+    return (gAgentAvatarp.notNull() && gAgentAvatarp->isValid());
 }
 
 void selfStartPhase(const std::string& phase_name)
 {
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->startPhase(phase_name);
-	}
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->startPhase(phase_name);
+    }
 }
 
 void selfStopPhase(const std::string& phase_name, bool err_check)
 {
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->stopPhase(phase_name, err_check);
-	}
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->stopPhase(phase_name, err_check);
+    }
 }
 
 void selfClearPhases()
 {
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->clearPhases();
-	}
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->clearPhases();
+    }
 }
 
 using namespace LLAvatarAppearanceDefines;
@@ -112,18 +112,18 @@ LLSD summarize_by_buckets(std::vector<LLSD> in_records, std::vector<std::string>
 
 struct LocalTextureData
 {
-	LocalTextureData() : 
-		mIsBakedReady(false), 
-		mDiscard(MAX_DISCARD_LEVEL+1), 
-		mImage(NULL), 
-		mWearableID(IMG_DEFAULT_AVATAR),
-		mTexEntry(NULL)
-	{}
-	LLPointer<LLViewerFetchedTexture> mImage;
-	bool mIsBakedReady;
-	S32 mDiscard;
-	LLUUID mWearableID;	// UUID of the wearable that this texture belongs to, not of the image itself
-	LLTextureEntry *mTexEntry;
+    LocalTextureData() :
+        mIsBakedReady(false),
+        mDiscard(MAX_DISCARD_LEVEL+1),
+        mImage(NULL),
+        mWearableID(IMG_DEFAULT_AVATAR),
+        mTexEntry(NULL)
+    {}
+    LLPointer<LLViewerFetchedTexture> mImage;
+    bool mIsBakedReady;
+    S32 mDiscard;
+    LLUUID mWearableID; // UUID of the wearable that this texture belongs to, not of the image itself
+    LLTextureEntry *mTexEntry;
 };
 
 //-----------------------------------------------------------------------------
@@ -152,523 +152,523 @@ std::map< LLGLenum, LLGLuint*> LLVOAvatarSelf::sScratchTexNames;
  **/
 
 LLVOAvatarSelf::LLVOAvatarSelf(const LLUUID& id,
-							   const LLPCode pcode,
-							   LLViewerRegion* regionp) :
-	LLVOAvatar(id, pcode, regionp),
+                               const LLPCode pcode,
+                               LLViewerRegion* regionp) :
+    LLVOAvatar(id, pcode, regionp),
 // [RLVa:KB] - Checked: 2012-07-28 (RLVa-1.4.7)
-	mAttachmentSignal(NULL),
+    mAttachmentSignal(NULL),
 // [/RLVa:KB]
-	mScreenp(NULL),
-	mLastRegionHandle(0),
-	mRegionCrossingCount(0),
-	// Value outside legal range, so will always be a mismatch the
-	// first time through.
-	mLastHoverOffsetSent(LLVector3(0.0f, 0.0f, -999.0f)),
+    mScreenp(NULL),
+    mLastRegionHandle(0),
+    mRegionCrossingCount(0),
+    // Value outside legal range, so will always be a mismatch the
+    // first time through.
+    mLastHoverOffsetSent(LLVector3(0.0f, 0.0f, -999.0f)),
     mInitialMetric(true),
     mMetricSequence(0)
 {
-	mMotionController.mIsSelf = TRUE;
+    mMotionController.mIsSelf = TRUE;
 
-	LL_DEBUGS() << "Marking avatar as self " << id << LL_ENDL;
+    LL_DEBUGS() << "Marking avatar as self " << id << LL_ENDL;
 }
 
 // Called periodically for diagnostics, return true when done.
 bool output_self_av_texture_diagnostics()
 {
-	if (!isAgentAvatarValid())
-		return true; // done checking
+    if (!isAgentAvatarValid())
+        return true; // done checking
 
-	gAgentAvatarp->outputRezDiagnostics();
+    gAgentAvatarp->outputRezDiagnostics();
 
-	return false;
+    return false;
 }
 
 bool update_avatar_rez_metrics()
 {
-	if (!isAgentAvatarValid())
-		return true;
-	
-	gAgentAvatarp->updateAvatarRezMetrics(false);
+    if (!isAgentAvatarValid())
+        return true;
 
-	return false;
+    gAgentAvatarp->updateAvatarRezMetrics(false);
+
+    return false;
 }
 
 void LLVOAvatarSelf::initInstance()
 {
-	BOOL status = TRUE;
-	// creates hud joint(mScreen) among other things
-	status &= loadAvatarSelf();
-
-	// adds attachment points to mScreen among other things
-	LLVOAvatar::initInstance();
-
-	LL_INFOS() << "Self avatar object created. Starting timer." << LL_ENDL;
-	mDebugSelfLoadTimer.reset();
-	// clear all times to -1 for debugging
-	for (U32 i =0; i < LLAvatarAppearanceDefines::TEX_NUM_INDICES; ++i)
-	{
-		for (U32 j = 0; j <= MAX_DISCARD_LEVEL; ++j)
-		{
-			mDebugTextureLoadTimes[i][j] = -1.0f;
-		}
-	}
-
-	for (U32 i =0; i < LLAvatarAppearanceDefines::BAKED_NUM_INDICES; ++i)
-	{
-		mDebugBakedTextureTimes[i][0] = -1.0f;
-		mDebugBakedTextureTimes[i][1] = -1.0f;
-	}
+    BOOL status = TRUE;
+    // creates hud joint(mScreen) among other things
+    status &= loadAvatarSelf();
+
+    // adds attachment points to mScreen among other things
+    LLVOAvatar::initInstance();
+
+    LL_INFOS() << "Self avatar object created. Starting timer." << LL_ENDL;
+    mDebugSelfLoadTimer.reset();
+    // clear all times to -1 for debugging
+    for (U32 i =0; i < LLAvatarAppearanceDefines::TEX_NUM_INDICES; ++i)
+    {
+        for (U32 j = 0; j <= MAX_DISCARD_LEVEL; ++j)
+        {
+            mDebugTextureLoadTimes[i][j] = -1.0f;
+        }
+    }
+
+    for (U32 i =0; i < LLAvatarAppearanceDefines::BAKED_NUM_INDICES; ++i)
+    {
+        mDebugBakedTextureTimes[i][0] = -1.0f;
+        mDebugBakedTextureTimes[i][1] = -1.0f;
+    }
 
 // [RLVa:KB] - Checked: 2010-12-12 (RLVa-1.2.2c) | Added: RLVa-1.2.2c
-	RlvAttachPtLookup::initLookupTable();
+    RlvAttachPtLookup::initLookupTable();
 // [/RLVa:KB]
 
-	status &= buildMenus();
-	if (!status)
-	{
-		LL_ERRS() << "Unable to load user's avatar" << LL_ENDL;
-		return;
-	}
+    status &= buildMenus();
+    if (!status)
+    {
+        LL_ERRS() << "Unable to load user's avatar" << LL_ENDL;
+        return;
+    }
 
-	setHoverIfRegionEnabled();
+    setHoverIfRegionEnabled();
 
-	//doPeriodically(output_self_av_texture_diagnostics, 30.0);
-	doPeriodically(update_avatar_rez_metrics, 5.0);
-	doPeriodically(boost::bind(&LLVOAvatarSelf::checkStuckAppearance, this), 30.0);
+    //doPeriodically(output_self_av_texture_diagnostics, 30.0);
+    doPeriodically(update_avatar_rez_metrics, 5.0);
+    doPeriodically(boost::bind(&LLVOAvatarSelf::checkStuckAppearance, this), 30.0);
 
     mInitFlags |= 1<<2;
 }
 
 void LLVOAvatarSelf::setHoverIfRegionEnabled()
 {
-	if (getRegion() && getRegion()->simulatorFeaturesReceived())
-	{
-		if (getRegion()->avatarHoverHeightEnabled())
-		{
-			F32 hover_z = gSavedPerAccountSettings.getF32("AvatarHoverOffsetZ");
-			setHoverOffset(LLVector3(0.0, 0.0, llclamp(hover_z,MIN_HOVER_Z,MAX_HOVER_Z)));
-			LL_INFOS("Avatar") << avString() << " set hover height from debug setting " << hover_z << LL_ENDL;
-		}
-		else 
-		{
-			setHoverOffset(LLVector3(0.0, 0.0, 0.0));
-			LL_INFOS("Avatar") << avString() << " zeroing hover height, region does not support" << LL_ENDL;
-		}
-	}
-	else
-	{
-		LL_INFOS("Avatar") << avString() << " region or simulator features not known, no change on hover" << LL_ENDL;
-		if (getRegion())
-		{
-			getRegion()->setSimulatorFeaturesReceivedCallback(boost::bind(&LLVOAvatarSelf::onSimulatorFeaturesReceived,this,_1));
-		}
-
-	}
+    if (getRegion() && getRegion()->simulatorFeaturesReceived())
+    {
+        if (getRegion()->avatarHoverHeightEnabled())
+        {
+            F32 hover_z = gSavedPerAccountSettings.getF32("AvatarHoverOffsetZ");
+            setHoverOffset(LLVector3(0.0, 0.0, llclamp(hover_z,MIN_HOVER_Z,MAX_HOVER_Z)));
+            LL_INFOS("Avatar") << avString() << " set hover height from debug setting " << hover_z << LL_ENDL;
+        }
+        else
+        {
+            setHoverOffset(LLVector3(0.0, 0.0, 0.0));
+            LL_INFOS("Avatar") << avString() << " zeroing hover height, region does not support" << LL_ENDL;
+        }
+    }
+    else
+    {
+        LL_INFOS("Avatar") << avString() << " region or simulator features not known, no change on hover" << LL_ENDL;
+        if (getRegion())
+        {
+            getRegion()->setSimulatorFeaturesReceivedCallback(boost::bind(&LLVOAvatarSelf::onSimulatorFeaturesReceived,this,_1));
+        }
+
+    }
 }
 
 bool LLVOAvatarSelf::checkStuckAppearance()
 {
-	const F32 CONDITIONAL_UNSTICK_INTERVAL = 300.0;
-	const F32 UNCONDITIONAL_UNSTICK_INTERVAL = 600.0;
-	
-	if (gAgentWearables.isCOFChangeInProgress())
-	{
+    const F32 CONDITIONAL_UNSTICK_INTERVAL = 300.0;
+    const F32 UNCONDITIONAL_UNSTICK_INTERVAL = 600.0;
+
+    if (gAgentWearables.isCOFChangeInProgress())
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("Avatar") << "checking for stuck appearance" << LL_ENDL;
+        LL_DEBUGS("Avatar") << "checking for stuck appearance" << LL_ENDL;
 #endif
-		F32 change_time = gAgentWearables.getCOFChangeTime();
+        F32 change_time = gAgentWearables.getCOFChangeTime();
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("Avatar") << "change in progress for " << change_time << " seconds" << LL_ENDL;
+        LL_DEBUGS("Avatar") << "change in progress for " << change_time << " seconds" << LL_ENDL;
 
-		S32 active_hp = LLAppearanceMgr::instance().countActiveHoldingPatterns();
-		LL_DEBUGS("Avatar") << "active holding patterns " << active_hp << " seconds" << LL_ENDL;
+        S32 active_hp = LLAppearanceMgr::instance().countActiveHoldingPatterns();
+        LL_DEBUGS("Avatar") << "active holding patterns " << active_hp << " seconds" << LL_ENDL;
 #endif
-		S32 active_copies = LLAppearanceMgr::instance().getActiveCopyOperations();
+        S32 active_copies = LLAppearanceMgr::instance().getActiveCopyOperations();
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("Avatar") << "active copy operations " << active_copies << LL_ENDL;
+        LL_DEBUGS("Avatar") << "active copy operations " << active_copies << LL_ENDL;
 #endif
 
-		if ((change_time > CONDITIONAL_UNSTICK_INTERVAL && active_copies == 0) ||
-			(change_time > UNCONDITIONAL_UNSTICK_INTERVAL))
-		{
-			gAgentWearables.notifyLoadingFinished();
-		}
-	}
+        if ((change_time > CONDITIONAL_UNSTICK_INTERVAL && active_copies == 0) ||
+            (change_time > UNCONDITIONAL_UNSTICK_INTERVAL))
+        {
+            gAgentWearables.notifyLoadingFinished();
+        }
+    }
 
-	// Return false to continue running check periodically.
-	return LLApp::isExiting();
+    // Return false to continue running check periodically.
+    return LLApp::isExiting();
 }
 
 // virtual
 void LLVOAvatarSelf::markDead()
 {
-	mBeam = NULL;
-	LLVOAvatar::markDead();
+    mBeam = NULL;
+    LLVOAvatar::markDead();
 }
 
 /*virtual*/ BOOL LLVOAvatarSelf::loadAvatar()
 {
-	BOOL success = LLVOAvatar::loadAvatar();
+    BOOL success = LLVOAvatar::loadAvatar();
 
-	// set all parameters stored directly in the avatar to have
-	// the isSelfParam to be TRUE - this is used to prevent
-	// them from being animated or trigger accidental rebakes
-	// when we copy params from the wearable to the base avatar.
-	for (LLViewerVisualParam* param = (LLViewerVisualParam*) getFirstVisualParam(); 
-		 param;
-		 param = (LLViewerVisualParam*) getNextVisualParam())
-	{
-		if (param->getWearableType() != LLWearableType::WT_INVALID)
-		{
-			param->setIsDummy(TRUE);
-		}
-	}
+    // set all parameters stored directly in the avatar to have
+    // the isSelfParam to be TRUE - this is used to prevent
+    // them from being animated or trigger accidental rebakes
+    // when we copy params from the wearable to the base avatar.
+    for (LLViewerVisualParam* param = (LLViewerVisualParam*) getFirstVisualParam();
+         param;
+         param = (LLViewerVisualParam*) getNextVisualParam())
+    {
+        if (param->getWearableType() != LLWearableType::WT_INVALID)
+        {
+            param->setIsDummy(TRUE);
+        }
+    }
 
-	return success;
+    return success;
 }
 
 
 BOOL LLVOAvatarSelf::loadAvatarSelf()
 {
-	BOOL success = TRUE;
-	// avatar_skeleton.xml
-	if (!buildSkeletonSelf(sAvatarSkeletonInfo))
-	{
-		LL_WARNS() << "avatar file: buildSkeleton() failed" << LL_ENDL;
-		return FALSE;
-	}
+    BOOL success = TRUE;
+    // avatar_skeleton.xml
+    if (!buildSkeletonSelf(sAvatarSkeletonInfo))
+    {
+        LL_WARNS() << "avatar file: buildSkeleton() failed" << LL_ENDL;
+        return FALSE;
+    }
 
-	return success;
+    return success;
 }
 
 BOOL LLVOAvatarSelf::buildSkeletonSelf(const LLAvatarSkeletonInfo *info)
 {
-	// add special-purpose "screen" joint
-	mScreenp = new LLViewerJoint("mScreen", NULL);
-	// for now, put screen at origin, as it is only used during special
-	// HUD rendering mode
-	F32 aspect = LLViewerCamera::getInstance()->getAspect();
-	LLVector3 scale(1.f, aspect, 1.f);
-	mScreenp->setScale(scale);
-	// SL-315
-	mScreenp->setWorldPosition(LLVector3::zero);
-	// need to update screen agressively when sidebar opens/closes, for example
-	mScreenp->mUpdateXform = TRUE;
-	return TRUE;
+    // add special-purpose "screen" joint
+    mScreenp = new LLViewerJoint("mScreen", NULL);
+    // for now, put screen at origin, as it is only used during special
+    // HUD rendering mode
+    F32 aspect = LLViewerCamera::getInstance()->getAspect();
+    LLVector3 scale(1.f, aspect, 1.f);
+    mScreenp->setScale(scale);
+    // SL-315
+    mScreenp->setWorldPosition(LLVector3::zero);
+    // need to update screen agressively when sidebar opens/closes, for example
+    mScreenp->mUpdateXform = TRUE;
+    return TRUE;
 }
 
 BOOL LLVOAvatarSelf::buildMenus()
 {
-	//-------------------------------------------------------------------------
-	// build the attach and detach menus
-	//-------------------------------------------------------------------------
-	gAttachBodyPartPieMenus[0] = NULL;
-
-	LLContextMenu::Params params;
-	params.label(LLTrans::getString("BodyPartsRightArm"));
-	params.name(params.label);
-	params.visible(false);
-	gAttachBodyPartPieMenus[1] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsHead"));
-	params.name(params.label);
-	gAttachBodyPartPieMenus[2] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsLeftArm"));
-	params.name(params.label);
-	gAttachBodyPartPieMenus[3] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	gAttachBodyPartPieMenus[4] = NULL;
-
-	params.label(LLTrans::getString("BodyPartsLeftLeg"));
-	params.name(params.label);
-	gAttachBodyPartPieMenus[5] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsTorso"));
-	params.name(params.label);
-	gAttachBodyPartPieMenus[6] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsRightLeg"));
-	params.name(params.label);
-	gAttachBodyPartPieMenus[7] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsEnhancedSkeleton"));
-	params.name(params.label);
-	gAttachBodyPartPieMenus[8] = LLUICtrlFactory::create<LLContextMenu>(params);
-
-	gDetachBodyPartPieMenus[0] = NULL;
-
-	params.label(LLTrans::getString("BodyPartsRightArm"));
-	params.name(params.label);
-	gDetachBodyPartPieMenus[1] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsHead"));
-	params.name(params.label);
-	gDetachBodyPartPieMenus[2] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsLeftArm"));
-	params.name(params.label);
-	gDetachBodyPartPieMenus[3] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	gDetachBodyPartPieMenus[4] = NULL;
-
-	params.label(LLTrans::getString("BodyPartsLeftLeg"));
-	params.name(params.label);
-	gDetachBodyPartPieMenus[5] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsTorso"));
-	params.name(params.label);
-	gDetachBodyPartPieMenus[6] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsRightLeg"));
-	params.name(params.label);
-	gDetachBodyPartPieMenus[7] = LLUICtrlFactory::create<LLContextMenu> (params);
-
-	params.label(LLTrans::getString("BodyPartsEnhancedSkeleton"));
-	params.name(params.label);
-	gDetachBodyPartPieMenus[8] = LLUICtrlFactory::create<LLContextMenu>(params);
-
-	for (S32 i = 0; i < 9; i++)
-	{
-		if (gAttachBodyPartPieMenus[i])
-		{
-			gAttachPieMenu->appendContextSubMenu( gAttachBodyPartPieMenus[i] );
-		}
-		else
-		{
-			for (const auto& attach_pair : mAttachmentPoints)
-			{
-				const LLViewerJointAttachment* attachment = attach_pair.second;
-				if (attachment && attachment->getGroup() == i)
-				{
-					LLMenuItemCallGL::Params item_params;
-						
-					std::string sub_piemenu_name = attachment->getName();
-					if (LLTrans::getString(sub_piemenu_name) != "")
-					{
-						item_params.label = LLTrans::getString(sub_piemenu_name);
-					}
-					else
-					{
-						item_params.label = sub_piemenu_name;
-					}
-					item_params.name =(item_params.label );
-					item_params.on_click.function_name = "Object.AttachToAvatar";
-					item_params.on_click.parameter = attach_pair.first;
-					// [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
-					item_params.on_enable.function_name = "Object.EnableWear";
-					item_params.on_enable.parameter = attach_pair.first;
-					LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
-
-					gAttachPieMenu->addChild(item);
-
-					break;
-
-				}
-			}
-		}
-
-		if (gDetachBodyPartPieMenus[i])
-		{
-			gDetachPieMenu->appendContextSubMenu( gDetachBodyPartPieMenus[i] );
-			gDetachAttSelfMenu->appendContextSubMenu(gDetachBodyPartPieMenus[i]);
-			gDetachAvatarMenu->appendContextSubMenu(gDetachBodyPartPieMenus[i]);
-		}
-		else
-		{
-			for (const auto& attach_pair : mAttachmentPoints)
-			{
-				const LLViewerJointAttachment* attachment = attach_pair.second;
-				if (attachment && attachment->getGroup() == i)
-				{
-					LLMenuItemCallGL::Params item_params;
-					std::string sub_piemenu_name = attachment->getName();
-					if (LLTrans::getString(sub_piemenu_name) != "")
-					{
-						item_params.label = LLTrans::getString(sub_piemenu_name);
-					}
-					else
-					{
-						item_params.label = sub_piemenu_name;
-					}
-					item_params.name =(item_params.label );
-					item_params.on_click.function_name = "Attachment.DetachFromPoint";
-					item_params.on_click.parameter = attach_pair.first;
-					item_params.on_enable.function_name = "Attachment.PointFilled";
-					item_params.on_enable.parameter = attach_pair.first;
-					LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
-
-					gDetachPieMenu->addChild(item);
-					gDetachAttSelfMenu->addChild(LLUICtrlFactory::create<LLMenuItemCallGL>(item_params));
-					gDetachAvatarMenu->addChild(LLUICtrlFactory::create<LLMenuItemCallGL>(item_params));
-					break;
-				}
-			}
-		}
-	}
-	
-
-	// add screen attachments
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		const LLViewerJointAttachment* attachment = attach_pair.second;
-		if (attachment->getGroup() == 9)
-		{
-			LLMenuItemCallGL::Params item_params;
-			std::string sub_piemenu_name = attachment->getName();
-			if (LLTrans::getString(sub_piemenu_name) != "")
-			{
-				item_params.label = LLTrans::getString(sub_piemenu_name);
-			}
-			else
-			{
-				item_params.label = sub_piemenu_name;
-			}
-			item_params.name =(item_params.label );
-			item_params.on_click.function_name = "Object.AttachToAvatar";
-			item_params.on_click.parameter = attach_pair.first;
-			// [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
-			item_params.on_enable.function_name = "Object.EnableWear";
-			item_params.on_enable.parameter = attach_pair.first;
-			LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
-			gAttachScreenPieMenu->addChild(item);
-
-			item_params.on_click.function_name = "Attachment.DetachFromPoint";
-			item_params.on_click.parameter = attach_pair.first;
-			item_params.on_enable.function_name = "Attachment.PointFilled";
-			item_params.on_enable.parameter = attach_pair.first;
-			item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
-			gDetachScreenPieMenu->addChild(item);
-			gDetachHUDAttSelfMenu->addChild(LLUICtrlFactory::create<LLMenuItemCallGL>(item_params));
-			gDetachHUDAvatarMenu->addChild(LLUICtrlFactory::create<LLMenuItemCallGL>(item_params));
-		}
-	}
-
-	for (S32 pass = 0; pass < 2; pass++)
-	{
-		// *TODO: Skinning - gAttachSubMenu is an awful, awful hack
-		if (!gAttachSubMenu)
-		{
-			break;
-		}
-		for (const auto& attach_pair : mAttachmentPoints)
-		{
-			const LLViewerJointAttachment* attachment = attach_pair.second;
-			if (attachment->getIsHUDAttachment() != (pass == 1))
-			{
-				continue;
-			}
-			LLMenuItemCallGL::Params item_params;
-			std::string sub_piemenu_name = attachment->getName();
-			if (LLTrans::getString(sub_piemenu_name) != "")
-			{
-				item_params.label = LLTrans::getString(sub_piemenu_name);
-			}
-			else
-			{
-				item_params.label = sub_piemenu_name;
-			}
-			item_params.name =(item_params.label );
-			item_params.on_click.function_name = "Object.AttachToAvatar";
-			item_params.on_click.parameter = attach_pair.first;
-			// [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
-			item_params.on_enable.function_name = "Object.EnableWear";
-			item_params.on_enable.parameter = attach_pair.first;
-			//* TODO: Skinning:
-			//LLSD params;
-			//params["index"] = iter->first;
-			//params["label"] = attachment->getName();
-			//item->addEventHandler("on_enable", LLMenuItemCallGL::MenuCallback().function_name("Attachment.Label").parameter(params));
-				
-			LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
-			gAttachSubMenu->addChild(item);
-
-			item_params.on_click.function_name = "Attachment.DetachFromPoint";
-			item_params.on_click.parameter = attach_pair.first;
-			item_params.on_enable.function_name = "Attachment.PointFilled";
-			item_params.on_enable.parameter = attach_pair.first;
-			//* TODO: Skinning: item->addEventHandler("on_enable", LLMenuItemCallGL::MenuCallback().function_name("Attachment.Label").parameter(params));
-
-			item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
-			gDetachSubMenu->addChild(item);
-		}
-		if (pass == 0)
-		{
-			// put separator between non-hud and hud attachments
-			gAttachSubMenu->addSeparator();
-			gDetachSubMenu->addSeparator();
-		}
-	}
-
-	for (S32 group = 0; group < 9; group++)
-	{
-		// skip over groups that don't have sub menus
-		if (!gAttachBodyPartPieMenus[group] || !gDetachBodyPartPieMenus[group])
-		{
-			continue;
-		}
-
-		std::multimap<S32, S32> attachment_pie_menu_map;
-
-		// gather up all attachment points assigned to this group, and throw into map sorted by pie slice number
-		for (const auto& attach_pair : mAttachmentPoints)
-		{
-			LLViewerJointAttachment* attachment = attach_pair.second;
-			if(attachment && attachment->getGroup() == group)
-			{
-				// use multimap to provide a partial order off of the pie slice key
-				S32 pie_index = attachment->getPieSlice();
-				attachment_pie_menu_map.insert(std::make_pair(pie_index, attach_pair.first));
-			}
-		}
-
-		// add in requested order to pie menu, inserting separators as necessary
-		for (std::multimap<S32, S32>::iterator attach_it = attachment_pie_menu_map.begin();
-			 attach_it != attachment_pie_menu_map.end(); ++attach_it)
-		{
-			S32 attach_index = attach_it->second;
-
-			LLViewerJointAttachment* attachment = get_if_there(mAttachmentPoints, attach_index, (LLViewerJointAttachment*)NULL);
-			if (attachment)
-			{
-				LLMenuItemCallGL::Params item_params;
-				item_params.name = attachment->getName();
-				item_params.label = LLTrans::getString(attachment->getName());
-				item_params.on_click.function_name = "Object.AttachToAvatar";
-				item_params.on_click.parameter = attach_index;
-				// [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
-				item_params.on_enable.function_name = "Object.EnableWear";
-				item_params.on_enable.parameter = attach_index;
-
-				LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
-				gAttachBodyPartPieMenus[group]->addChild(item);
-					
-				item_params.on_click.function_name = "Attachment.DetachFromPoint";
-				item_params.on_click.parameter = attach_index;
-				item_params.on_enable.function_name = "Attachment.PointFilled";
-				item_params.on_enable.parameter = attach_index;
-				item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
-				gDetachBodyPartPieMenus[group]->addChild(item);
-			}
-		}
-	}
-	return TRUE;
+    //-------------------------------------------------------------------------
+    // build the attach and detach menus
+    //-------------------------------------------------------------------------
+    gAttachBodyPartPieMenus[0] = NULL;
+
+    LLContextMenu::Params params;
+    params.label(LLTrans::getString("BodyPartsRightArm"));
+    params.name(params.label);
+    params.visible(false);
+    gAttachBodyPartPieMenus[1] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsHead"));
+    params.name(params.label);
+    gAttachBodyPartPieMenus[2] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsLeftArm"));
+    params.name(params.label);
+    gAttachBodyPartPieMenus[3] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    gAttachBodyPartPieMenus[4] = NULL;
+
+    params.label(LLTrans::getString("BodyPartsLeftLeg"));
+    params.name(params.label);
+    gAttachBodyPartPieMenus[5] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsTorso"));
+    params.name(params.label);
+    gAttachBodyPartPieMenus[6] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsRightLeg"));
+    params.name(params.label);
+    gAttachBodyPartPieMenus[7] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsEnhancedSkeleton"));
+    params.name(params.label);
+    gAttachBodyPartPieMenus[8] = LLUICtrlFactory::create<LLContextMenu>(params);
+
+    gDetachBodyPartPieMenus[0] = NULL;
+
+    params.label(LLTrans::getString("BodyPartsRightArm"));
+    params.name(params.label);
+    gDetachBodyPartPieMenus[1] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsHead"));
+    params.name(params.label);
+    gDetachBodyPartPieMenus[2] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsLeftArm"));
+    params.name(params.label);
+    gDetachBodyPartPieMenus[3] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    gDetachBodyPartPieMenus[4] = NULL;
+
+    params.label(LLTrans::getString("BodyPartsLeftLeg"));
+    params.name(params.label);
+    gDetachBodyPartPieMenus[5] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsTorso"));
+    params.name(params.label);
+    gDetachBodyPartPieMenus[6] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsRightLeg"));
+    params.name(params.label);
+    gDetachBodyPartPieMenus[7] = LLUICtrlFactory::create<LLContextMenu> (params);
+
+    params.label(LLTrans::getString("BodyPartsEnhancedSkeleton"));
+    params.name(params.label);
+    gDetachBodyPartPieMenus[8] = LLUICtrlFactory::create<LLContextMenu>(params);
+
+    for (S32 i = 0; i < 9; i++)
+    {
+        if (gAttachBodyPartPieMenus[i])
+        {
+            gAttachPieMenu->appendContextSubMenu( gAttachBodyPartPieMenus[i] );
+        }
+        else
+        {
+            for (const auto& attach_pair : mAttachmentPoints)
+            {
+                const LLViewerJointAttachment* attachment = attach_pair.second;
+                if (attachment && attachment->getGroup() == i)
+                {
+                    LLMenuItemCallGL::Params item_params;
+
+                    std::string sub_piemenu_name = attachment->getName();
+                    if (LLTrans::getString(sub_piemenu_name) != "")
+                    {
+                        item_params.label = LLTrans::getString(sub_piemenu_name);
+                    }
+                    else
+                    {
+                        item_params.label = sub_piemenu_name;
+                    }
+                    item_params.name =(item_params.label );
+                    item_params.on_click.function_name = "Object.AttachToAvatar";
+                    item_params.on_click.parameter = attach_pair.first;
+                    // [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
+                    item_params.on_enable.function_name = "Object.EnableWear";
+                    item_params.on_enable.parameter = attach_pair.first;
+                    LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
+
+                    gAttachPieMenu->addChild(item);
+
+                    break;
+
+                }
+            }
+        }
+
+        if (gDetachBodyPartPieMenus[i])
+        {
+            gDetachPieMenu->appendContextSubMenu( gDetachBodyPartPieMenus[i] );
+            gDetachAttSelfMenu->appendContextSubMenu(gDetachBodyPartPieMenus[i]);
+            gDetachAvatarMenu->appendContextSubMenu(gDetachBodyPartPieMenus[i]);
+        }
+        else
+        {
+            for (const auto& attach_pair : mAttachmentPoints)
+            {
+                const LLViewerJointAttachment* attachment = attach_pair.second;
+                if (attachment && attachment->getGroup() == i)
+                {
+                    LLMenuItemCallGL::Params item_params;
+                    std::string sub_piemenu_name = attachment->getName();
+                    if (LLTrans::getString(sub_piemenu_name) != "")
+                    {
+                        item_params.label = LLTrans::getString(sub_piemenu_name);
+                    }
+                    else
+                    {
+                        item_params.label = sub_piemenu_name;
+                    }
+                    item_params.name =(item_params.label );
+                    item_params.on_click.function_name = "Attachment.DetachFromPoint";
+                    item_params.on_click.parameter = attach_pair.first;
+                    item_params.on_enable.function_name = "Attachment.PointFilled";
+                    item_params.on_enable.parameter = attach_pair.first;
+                    LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
+
+                    gDetachPieMenu->addChild(item);
+                    gDetachAttSelfMenu->addChild(LLUICtrlFactory::create<LLMenuItemCallGL>(item_params));
+                    gDetachAvatarMenu->addChild(LLUICtrlFactory::create<LLMenuItemCallGL>(item_params));
+                    break;
+                }
+            }
+        }
+    }
+
+
+    // add screen attachments
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        const LLViewerJointAttachment* attachment = attach_pair.second;
+        if (attachment->getGroup() == 9)
+        {
+            LLMenuItemCallGL::Params item_params;
+            std::string sub_piemenu_name = attachment->getName();
+            if (LLTrans::getString(sub_piemenu_name) != "")
+            {
+                item_params.label = LLTrans::getString(sub_piemenu_name);
+            }
+            else
+            {
+                item_params.label = sub_piemenu_name;
+            }
+            item_params.name =(item_params.label );
+            item_params.on_click.function_name = "Object.AttachToAvatar";
+            item_params.on_click.parameter = attach_pair.first;
+            // [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
+            item_params.on_enable.function_name = "Object.EnableWear";
+            item_params.on_enable.parameter = attach_pair.first;
+            LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
+            gAttachScreenPieMenu->addChild(item);
+
+            item_params.on_click.function_name = "Attachment.DetachFromPoint";
+            item_params.on_click.parameter = attach_pair.first;
+            item_params.on_enable.function_name = "Attachment.PointFilled";
+            item_params.on_enable.parameter = attach_pair.first;
+            item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
+            gDetachScreenPieMenu->addChild(item);
+            gDetachHUDAttSelfMenu->addChild(LLUICtrlFactory::create<LLMenuItemCallGL>(item_params));
+            gDetachHUDAvatarMenu->addChild(LLUICtrlFactory::create<LLMenuItemCallGL>(item_params));
+        }
+    }
+
+    for (S32 pass = 0; pass < 2; pass++)
+    {
+        // *TODO: Skinning - gAttachSubMenu is an awful, awful hack
+        if (!gAttachSubMenu)
+        {
+            break;
+        }
+        for (const auto& attach_pair : mAttachmentPoints)
+        {
+            const LLViewerJointAttachment* attachment = attach_pair.second;
+            if (attachment->getIsHUDAttachment() != (pass == 1))
+            {
+                continue;
+            }
+            LLMenuItemCallGL::Params item_params;
+            std::string sub_piemenu_name = attachment->getName();
+            if (LLTrans::getString(sub_piemenu_name) != "")
+            {
+                item_params.label = LLTrans::getString(sub_piemenu_name);
+            }
+            else
+            {
+                item_params.label = sub_piemenu_name;
+            }
+            item_params.name =(item_params.label );
+            item_params.on_click.function_name = "Object.AttachToAvatar";
+            item_params.on_click.parameter = attach_pair.first;
+            // [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
+            item_params.on_enable.function_name = "Object.EnableWear";
+            item_params.on_enable.parameter = attach_pair.first;
+            //* TODO: Skinning:
+            //LLSD params;
+            //params["index"] = iter->first;
+            //params["label"] = attachment->getName();
+            //item->addEventHandler("on_enable", LLMenuItemCallGL::MenuCallback().function_name("Attachment.Label").parameter(params));
+
+            LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
+            gAttachSubMenu->addChild(item);
+
+            item_params.on_click.function_name = "Attachment.DetachFromPoint";
+            item_params.on_click.parameter = attach_pair.first;
+            item_params.on_enable.function_name = "Attachment.PointFilled";
+            item_params.on_enable.parameter = attach_pair.first;
+            //* TODO: Skinning: item->addEventHandler("on_enable", LLMenuItemCallGL::MenuCallback().function_name("Attachment.Label").parameter(params));
+
+            item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
+            gDetachSubMenu->addChild(item);
+        }
+        if (pass == 0)
+        {
+            // put separator between non-hud and hud attachments
+            gAttachSubMenu->addSeparator();
+            gDetachSubMenu->addSeparator();
+        }
+    }
+
+    for (S32 group = 0; group < 9; group++)
+    {
+        // skip over groups that don't have sub menus
+        if (!gAttachBodyPartPieMenus[group] || !gDetachBodyPartPieMenus[group])
+        {
+            continue;
+        }
+
+        std::multimap<S32, S32> attachment_pie_menu_map;
+
+        // gather up all attachment points assigned to this group, and throw into map sorted by pie slice number
+        for (const auto& attach_pair : mAttachmentPoints)
+        {
+            LLViewerJointAttachment* attachment = attach_pair.second;
+            if(attachment && attachment->getGroup() == group)
+            {
+                // use multimap to provide a partial order off of the pie slice key
+                S32 pie_index = attachment->getPieSlice();
+                attachment_pie_menu_map.insert(std::make_pair(pie_index, attach_pair.first));
+            }
+        }
+
+        // add in requested order to pie menu, inserting separators as necessary
+        for (std::multimap<S32, S32>::iterator attach_it = attachment_pie_menu_map.begin();
+             attach_it != attachment_pie_menu_map.end(); ++attach_it)
+        {
+            S32 attach_index = attach_it->second;
+
+            LLViewerJointAttachment* attachment = get_if_there(mAttachmentPoints, attach_index, (LLViewerJointAttachment*)NULL);
+            if (attachment)
+            {
+                LLMenuItemCallGL::Params item_params;
+                item_params.name = attachment->getName();
+                item_params.label = LLTrans::getString(attachment->getName());
+                item_params.on_click.function_name = "Object.AttachToAvatar";
+                item_params.on_click.parameter = attach_index;
+                // [RLVa:KB] - No changes, but we do need the parameter to always be idxAttachPt for object_selected_and_point_valid()
+                item_params.on_enable.function_name = "Object.EnableWear";
+                item_params.on_enable.parameter = attach_index;
+
+                LLMenuItemCallGL* item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
+                gAttachBodyPartPieMenus[group]->addChild(item);
+
+                item_params.on_click.function_name = "Attachment.DetachFromPoint";
+                item_params.on_click.parameter = attach_index;
+                item_params.on_enable.function_name = "Attachment.PointFilled";
+                item_params.on_enable.parameter = attach_index;
+                item = LLUICtrlFactory::create<LLMenuItemCallGL>(item_params);
+                gDetachBodyPartPieMenus[group]->addChild(item);
+            }
+        }
+    }
+    return TRUE;
 }
 
 void LLVOAvatarSelf::cleanup()
 {
-	markDead();
- 	delete mScreenp;
- 	mScreenp = NULL;
-	mRegionp = NULL;
+    markDead();
+    delete mScreenp;
+    mScreenp = NULL;
+    mRegionp = NULL;
 }
 
 LLVOAvatarSelf::~LLVOAvatarSelf()
 {
-	cleanup();
+    cleanup();
 
 // [RLVa:KB] - Checked: 2012-07-28 (RLVa-1.4.7)
-	delete mAttachmentSignal;
+    delete mAttachmentSignal;
 // [/RLVa:KB]
 }
 
@@ -681,33 +681,33 @@ LLVOAvatarSelf::~LLVOAvatarSelf()
 // virtual
 bool LLVOAvatarSelf::updateCharacter(LLAgent &agent)
 {
-	// update screen joint size
-	if (mScreenp)
-	{
-		F32 aspect = LLViewerCamera::getInstance()->getAspect();
-		LLVector3 scale(1.f, aspect, 1.f);
-		mScreenp->setScale(scale);
-		mScreenp->updateWorldMatrixChildren();
-		resetHUDAttachments();
-	}
-	
-	return LLVOAvatar::updateCharacter(agent);
+    // update screen joint size
+    if (mScreenp)
+    {
+        F32 aspect = LLViewerCamera::getInstance()->getAspect();
+        LLVector3 scale(1.f, aspect, 1.f);
+        mScreenp->setScale(scale);
+        mScreenp->updateWorldMatrixChildren();
+        resetHUDAttachments();
+    }
+
+    return LLVOAvatar::updateCharacter(agent);
 }
 
 // virtual
 BOOL LLVOAvatarSelf::isValid() const
 {
-	return ((getRegion() != NULL) && !isDead());
+    return ((getRegion() != NULL) && !isDead());
 }
 
 // virtual
 void LLVOAvatarSelf::idleUpdate(LLAgent &agent, const F64 &time)
 {
-	if (isValid())
-	{
-		LLVOAvatar::idleUpdate(agent, time);
-		idleUpdateTractorBeam();
-	}
+    if (isValid())
+    {
+        LLVOAvatar::idleUpdate(agent, time);
+        idleUpdateTractorBeam();
+    }
 }
 
 // virtual
@@ -715,14 +715,14 @@ LLJoint *LLVOAvatarSelf::getJoint(const std::string &name)
 {
     LLJoint *jointp = NULL;
     jointp = LLVOAvatar::getJoint(name);
-	if (!jointp && mScreenp)
-	{
-		jointp = mScreenp->findJoint(name);
+    if (!jointp && mScreenp)
+    {
+        jointp = mScreenp->findJoint(name);
         if (jointp)
         {
             mJointMap[name] = jointp;
         }
-	}
+    }
     if (jointp && jointp != mScreenp && jointp != mRoot)
     {
         llassert(LLVOAvatar::getJoint((S32)jointp->getJointNum())==jointp);
@@ -733,238 +733,238 @@ LLJoint *LLVOAvatarSelf::getJoint(const std::string &name)
 // virtual
 BOOL LLVOAvatarSelf::setVisualParamWeight(const LLVisualParam *which_param, F32 weight)
 {
-	if (!which_param)
-	{
-		return FALSE;
-	}
-	LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(which_param->getID());
-	return setParamWeight(param,weight);
+    if (!which_param)
+    {
+        return FALSE;
+    }
+    LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(which_param->getID());
+    return setParamWeight(param,weight);
 }
 
 // virtual
 BOOL LLVOAvatarSelf::setVisualParamWeight(const char* param_name, F32 weight)
 {
-	if (!param_name)
-	{
-		return FALSE;
-	}
-	LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(param_name);
-	return setParamWeight(param,weight);
+    if (!param_name)
+    {
+        return FALSE;
+    }
+    LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(param_name);
+    return setParamWeight(param,weight);
 }
 
 // virtual
 BOOL LLVOAvatarSelf::setVisualParamWeight(S32 index, F32 weight)
 {
-	LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(index);
-	return setParamWeight(param,weight);
+    LLViewerVisualParam *param = (LLViewerVisualParam*) LLCharacter::getVisualParam(index);
+    return setParamWeight(param,weight);
 }
 
 BOOL LLVOAvatarSelf::setParamWeight(const LLViewerVisualParam *param, F32 weight)
 {
-	if (!param)
-	{
-		return FALSE;
-	}
-
-	if (param->getCrossWearable())
-	{
-		LLWearableType::EType type = (LLWearableType::EType)param->getWearableType();
-		U32 size = gAgentWearables.getWearableCount(type);
-		for (U32 count = 0; count < size; ++count)
-		{
-			LLViewerWearable *wearable = gAgentWearables.getViewerWearable(type,count);
-			if (wearable)
-			{
-				wearable->setVisualParamWeight(param->getID(), weight);
-			}
-		}
-	}
-
-	return LLCharacter::setVisualParamWeight(param,weight);
-}
-
-/*virtual*/ 
+    if (!param)
+    {
+        return FALSE;
+    }
+
+    if (param->getCrossWearable())
+    {
+        LLWearableType::EType type = (LLWearableType::EType)param->getWearableType();
+        U32 size = gAgentWearables.getWearableCount(type);
+        for (U32 count = 0; count < size; ++count)
+        {
+            LLViewerWearable *wearable = gAgentWearables.getViewerWearable(type,count);
+            if (wearable)
+            {
+                wearable->setVisualParamWeight(param->getID(), weight);
+            }
+        }
+    }
+
+    return LLCharacter::setVisualParamWeight(param,weight);
+}
+
+/*virtual*/
 void LLVOAvatarSelf::updateVisualParams()
 {
-	LLVOAvatar::updateVisualParams();
+    LLVOAvatar::updateVisualParams();
 }
 
 void LLVOAvatarSelf::writeWearablesToAvatar()
 {
-	for (U32 type = 0; type < LLWearableType::WT_COUNT; type++)
-	{
-		LLWearable *wearable = gAgentWearables.getTopWearable((LLWearableType::EType)type);
-		if (wearable)
-		{
-			wearable->writeToAvatar(this);
-		}
-	}
+    for (U32 type = 0; type < LLWearableType::WT_COUNT; type++)
+    {
+        LLWearable *wearable = gAgentWearables.getTopWearable((LLWearableType::EType)type);
+        if (wearable)
+        {
+            wearable->writeToAvatar(this);
+        }
+    }
 
 }
 
 /*virtual*/
 void LLVOAvatarSelf::idleUpdateAppearanceAnimation()
 {
-	// Animate all top-level wearable visual parameters
-	gAgentWearables.animateAllWearableParams(calcMorphAmount());
+    // Animate all top-level wearable visual parameters
+    gAgentWearables.animateAllWearableParams(calcMorphAmount());
 
-	// Apply wearable visual params to avatar
-	writeWearablesToAvatar();
+    // Apply wearable visual params to avatar
+    writeWearablesToAvatar();
 
-	//allow avatar to process updates
-	LLVOAvatar::idleUpdateAppearanceAnimation();
+    //allow avatar to process updates
+    LLVOAvatar::idleUpdateAppearanceAnimation();
 
 }
 
 // virtual
 void LLVOAvatarSelf::requestStopMotion(LLMotion* motion)
 {
-	// Only agent avatars should handle the stop motion notifications.
+    // Only agent avatars should handle the stop motion notifications.
 
-	// Notify agent that motion has stopped
-	gAgent.requestStopMotion(motion);
+    // Notify agent that motion has stopped
+    gAgent.requestStopMotion(motion);
 }
 
 // virtual
 bool LLVOAvatarSelf::hasMotionFromSource(const LLUUID& source_id)
 {
-	AnimSourceIterator motion_it = mAnimationSources.find(source_id);
-	return motion_it != mAnimationSources.end();
+    AnimSourceIterator motion_it = mAnimationSources.find(source_id);
+    return motion_it != mAnimationSources.end();
 }
 
 // virtual
 void LLVOAvatarSelf::stopMotionFromSource(const LLUUID& source_id)
 {
-	for (AnimSourceIterator motion_it = mAnimationSources.find(source_id); motion_it != mAnimationSources.end(); )
-	{
-		gAgent.sendAnimationRequest(motion_it->second, ANIM_REQUEST_STOP);
-		mAnimationSources.erase(motion_it);
-		// Must find() after each erase() to deal with potential iterator invalidation
-		// This also ensures that we don't go past the end of this source's animations
-		// into those of another source.
-		motion_it = mAnimationSources.find(source_id);
-	}
+    for (AnimSourceIterator motion_it = mAnimationSources.find(source_id); motion_it != mAnimationSources.end(); )
+    {
+        gAgent.sendAnimationRequest(motion_it->second, ANIM_REQUEST_STOP);
+        mAnimationSources.erase(motion_it);
+        // Must find() after each erase() to deal with potential iterator invalidation
+        // This also ensures that we don't go past the end of this source's animations
+        // into those of another source.
+        motion_it = mAnimationSources.find(source_id);
+    }
 
 
-	LLViewerObject* object = gObjectList.findObject(source_id);
-	if (object)
-	{
-		object->setFlagsWithoutUpdate(FLAGS_ANIM_SOURCE, FALSE);
-	}
+    LLViewerObject* object = gObjectList.findObject(source_id);
+    if (object)
+    {
+        object->setFlagsWithoutUpdate(FLAGS_ANIM_SOURCE, FALSE);
+    }
 }
 
 void LLVOAvatarSelf::setLocalTextureTE(U8 te, LLViewerTexture* image, U32 index)
 {
-	if (te >= TEX_NUM_INDICES)
-	{
-		llassert(0);
-		return;
-	}
+    if (te >= TEX_NUM_INDICES)
+    {
+        llassert(0);
+        return;
+    }
 
-	if (getTEImage(te)->getID() == image->getID())
-	{
-		return;
-	}
+    if (getTEImage(te)->getID() == image->getID())
+    {
+        return;
+    }
 
-	if (isIndexBakedTexture((ETextureIndex)te))
-	{
-		llassert(0);
-		return;
-	}
+    if (isIndexBakedTexture((ETextureIndex)te))
+    {
+        llassert(0);
+        return;
+    }
 
-	setTEImage(te, image);
+    setTEImage(te, image);
 }
 
 //virtual
 void LLVOAvatarSelf::removeMissingBakedTextures()
-{	
-	BOOL removed = FALSE;
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		const S32 te = mBakedTextureDatas[i].mTextureIndex;
-		const LLViewerTexture* tex = getTEImage(te);
-
-		// Replace with default if we can't find the asset, assuming the
-		// default is actually valid (which it should be unless something
-		// is seriously wrong).
-		if (!tex || tex->isMissingAsset())
-		{
-			LLViewerTexture *imagep = LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR);
-			if (imagep && imagep != tex)
-			{
-				setTEImage(te, imagep);
-				removed = TRUE;
-			}
-		}
-	}
-
-	if (removed)
-	{
-		for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-		{
-			LLViewerTexLayerSet *layerset = getTexLayerSet(i);
-			layerset->setUpdatesEnabled(TRUE);
-			invalidateComposite(layerset);
-		}
-		updateMeshTextures();
-	}
+{
+    BOOL removed = FALSE;
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        const S32 te = mBakedTextureDatas[i].mTextureIndex;
+        const LLViewerTexture* tex = getTEImage(te);
+
+        // Replace with default if we can't find the asset, assuming the
+        // default is actually valid (which it should be unless something
+        // is seriously wrong).
+        if (!tex || tex->isMissingAsset())
+        {
+            LLViewerTexture *imagep = LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR);
+            if (imagep && imagep != tex)
+            {
+                setTEImage(te, imagep);
+                removed = TRUE;
+            }
+        }
+    }
+
+    if (removed)
+    {
+        for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+        {
+            LLViewerTexLayerSet *layerset = getTexLayerSet(i);
+            layerset->setUpdatesEnabled(TRUE);
+            invalidateComposite(layerset);
+        }
+        updateMeshTextures();
+    }
 }
 
 void LLVOAvatarSelf::onSimulatorFeaturesReceived(const LLUUID& region_id)
 {
-	LL_INFOS("Avatar") << "simulator features received, setting hover based on region props" << LL_ENDL;
-	setHoverIfRegionEnabled();
+    LL_INFOS("Avatar") << "simulator features received, setting hover based on region props" << LL_ENDL;
+    setHoverIfRegionEnabled();
 }
 
 //virtual
 void LLVOAvatarSelf::updateRegion(LLViewerRegion *regionp)
 {
-	// Save the global position
-	LLVector3d global_pos_from_old_region = getPositionGlobal();
-
-	// Change the region
-	setRegion(regionp);
-
-	if (regionp)
-	{	// Set correct region-relative position from global coordinates
-		setPositionGlobal(global_pos_from_old_region);
-
-		// Diagnostic info
-		//LLVector3d pos_from_new_region = getPositionGlobal();
-		//LL_INFOS() << "pos_from_old_region is " << global_pos_from_old_region
-		//	<< " while pos_from_new_region is " << pos_from_new_region
-		//	<< LL_ENDL;
-
-		// Update hover height, or schedule callback, based on whether
-		// it's supported in this region.
-		if (regionp->simulatorFeaturesReceived())
-		{
-			setHoverIfRegionEnabled();
-		}
-		else
-		{
-			regionp->setSimulatorFeaturesReceivedCallback(boost::bind(&LLVOAvatarSelf::onSimulatorFeaturesReceived,this,_1));
-		}
-	}
-
-	if (!regionp || (regionp->getHandle() != mLastRegionHandle))
-	{
-		if (mLastRegionHandle != 0)
-		{
-			++mRegionCrossingCount;
-			F64Seconds delta(mRegionCrossingTimer.getElapsedTimeF32());
-			record(LLStatViewer::REGION_CROSSING_TIME, delta);
-
-			// Diagnostics
-			LL_INFOS() << "Region crossing took " << (F32)(delta * 1000.0).value() << " ms " << LL_ENDL;
-		}
-		if (regionp)
-		{
-			mLastRegionHandle = regionp->getHandle();
-		}
-	}
-	mRegionCrossingTimer.reset();
-	LLViewerObject::updateRegion(regionp);
+    // Save the global position
+    LLVector3d global_pos_from_old_region = getPositionGlobal();
+
+    // Change the region
+    setRegion(regionp);
+
+    if (regionp)
+    {   // Set correct region-relative position from global coordinates
+        setPositionGlobal(global_pos_from_old_region);
+
+        // Diagnostic info
+        //LLVector3d pos_from_new_region = getPositionGlobal();
+        //LL_INFOS() << "pos_from_old_region is " << global_pos_from_old_region
+        //  << " while pos_from_new_region is " << pos_from_new_region
+        //  << LL_ENDL;
+
+        // Update hover height, or schedule callback, based on whether
+        // it's supported in this region.
+        if (regionp->simulatorFeaturesReceived())
+        {
+            setHoverIfRegionEnabled();
+        }
+        else
+        {
+            regionp->setSimulatorFeaturesReceivedCallback(boost::bind(&LLVOAvatarSelf::onSimulatorFeaturesReceived,this,_1));
+        }
+    }
+
+    if (!regionp || (regionp->getHandle() != mLastRegionHandle))
+    {
+        if (mLastRegionHandle != 0)
+        {
+            ++mRegionCrossingCount;
+            F64Seconds delta(mRegionCrossingTimer.getElapsedTimeF32());
+            record(LLStatViewer::REGION_CROSSING_TIME, delta);
+
+            // Diagnostics
+            LL_INFOS() << "Region crossing took " << (F32)(delta * 1000.0).value() << " ms " << LL_ENDL;
+        }
+        if (regionp)
+        {
+            mLastRegionHandle = regionp->getHandle();
+        }
+    }
+    mRegionCrossingTimer.reset();
+    LLViewerObject::updateRegion(regionp);
 }
 
 //--------------------------------------------------------------------
@@ -973,66 +973,66 @@ void LLVOAvatarSelf::updateRegion(LLViewerRegion *regionp)
 //virtual
 void LLVOAvatarSelf::idleUpdateTractorBeam()
 {
-	static LLCachedControl<bool> pointAtDisable(gSavedSettings, "AlchemyPointAtPrivate");
-	// This is only done for yourself (maybe it should be in the agent?)
-	if (pointAtDisable || !needsRenderBeam() || !isBuilt())
-	{
-		mBeam = NULL;
-	}
-	else if (!mBeam || mBeam->isDead())
-	{
-		// VEFFECT: Tractor Beam
-		mBeam = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM);
-		mBeam->setColor(LLColor4U(gAgent.getEffectColor()));
-		mBeam->setSourceObject(this);
-		mBeamTimer.reset();
-	}
-
-	if (!mBeam.isNull())
-	{
-		LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
-
-		if (gAgentCamera.mPointAt.notNull())
-		{
-			// get point from pointat effect
-			mBeam->setPositionGlobal(gAgentCamera.mPointAt->getPointAtPosGlobal());
-			mBeam->triggerLocal();
-		}
-		else if (selection->getFirstRootObject() && 
-				selection->getSelectType() != SELECT_TYPE_HUD)
-		{
-			LLViewerObject* objectp = selection->getFirstRootObject();
-			mBeam->setTargetObject(objectp);
-		}
-		else
-		{
-			mBeam->setTargetObject(NULL);
-			LLTool *tool = LLToolMgr::getInstance()->getCurrentTool();
-			if (tool->isEditing())
-			{
-				if (tool->getEditingObject())
-				{
-					mBeam->setTargetObject(tool->getEditingObject());
-				}
-				else
-				{
-					mBeam->setPositionGlobal(tool->getEditingPointGlobal());
-				}
-			}
-			else
-			{
-				const LLPickInfo& pick = gViewerWindow->getLastPick();
-				mBeam->setPositionGlobal(pick.mPosGlobal);
-			}
-
-		}
-		if (mBeamTimer.getElapsedTimeF32() > 0.25f)
-		{
-			mBeam->setColor(LLColor4U(gAgent.getEffectColor()));
-			mBeam->setNeedsSendToSim(TRUE);
-			mBeamTimer.reset();
-		}
-	}
+    static LLCachedControl<bool> pointAtDisable(gSavedSettings, "AlchemyPointAtPrivate");
+    // This is only done for yourself (maybe it should be in the agent?)
+    if (pointAtDisable || !needsRenderBeam() || !isBuilt())
+    {
+        mBeam = NULL;
+    }
+    else if (!mBeam || mBeam->isDead())
+    {
+        // VEFFECT: Tractor Beam
+        mBeam = (LLHUDEffectSpiral *)LLHUDManager::getInstance()->createViewerEffect(LLHUDObject::LL_HUD_EFFECT_BEAM);
+        mBeam->setColor(LLColor4U(gAgent.getEffectColor()));
+        mBeam->setSourceObject(this);
+        mBeamTimer.reset();
+    }
+
+    if (!mBeam.isNull())
+    {
+        LLObjectSelectionHandle selection = LLSelectMgr::getInstance()->getSelection();
+
+        if (gAgentCamera.mPointAt.notNull())
+        {
+            // get point from pointat effect
+            mBeam->setPositionGlobal(gAgentCamera.mPointAt->getPointAtPosGlobal());
+            mBeam->triggerLocal();
+        }
+        else if (selection->getFirstRootObject() &&
+                selection->getSelectType() != SELECT_TYPE_HUD)
+        {
+            LLViewerObject* objectp = selection->getFirstRootObject();
+            mBeam->setTargetObject(objectp);
+        }
+        else
+        {
+            mBeam->setTargetObject(NULL);
+            LLTool *tool = LLToolMgr::getInstance()->getCurrentTool();
+            if (tool->isEditing())
+            {
+                if (tool->getEditingObject())
+                {
+                    mBeam->setTargetObject(tool->getEditingObject());
+                }
+                else
+                {
+                    mBeam->setPositionGlobal(tool->getEditingPointGlobal());
+                }
+            }
+            else
+            {
+                const LLPickInfo& pick = gViewerWindow->getLastPick();
+                mBeam->setPositionGlobal(pick.mPosGlobal);
+            }
+
+        }
+        if (mBeamTimer.getElapsedTimeF32() > 0.25f)
+        {
+            mBeam->setColor(LLColor4U(gAgent.getEffectColor()));
+            mBeam->setNeedsSendToSim(TRUE);
+            mBeamTimer.reset();
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1041,13 +1041,13 @@ void LLVOAvatarSelf::idleUpdateTractorBeam()
 // virtual
 void LLVOAvatarSelf::restoreMeshData()
 {
-	//LL_INFOS() << "Restoring" << LL_ENDL;
-	mMeshValid = TRUE;
-	updateJointLODs();
-	updateAttachmentVisibility(gAgentCamera.getCameraMode());
+    //LL_INFOS() << "Restoring" << LL_ENDL;
+    mMeshValid = TRUE;
+    updateJointLODs();
+    updateAttachmentVisibility(gAgentCamera.getCameraMode());
 
-	// force mesh update as LOD might not have changed to trigger this
-	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
+    // force mesh update as LOD might not have changed to trigger this
+    gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
 }
 
 
@@ -1057,49 +1057,49 @@ void LLVOAvatarSelf::restoreMeshData()
 //-----------------------------------------------------------------------------
 void LLVOAvatarSelf::updateAttachmentVisibility(U32 camera_mode)
 {
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
-		if (attachment->getIsHUDAttachment())
-		{
-			attachment->setAttachmentVisibility(TRUE);
-		}
-		else
-		{
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        if (attachment->getIsHUDAttachment())
+        {
+            attachment->setAttachmentVisibility(TRUE);
+        }
+        else
+        {
 // [RLVa:KB] - Checked: RLVa-2.0.2
-			bool fRlvCanShowAttachment = true;
-			if (rlv_handler_t::isEnabled())
-			{
-				fRlvCanShowAttachment =
-					(!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWSELF)) &&
-					( (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWSELFHEAD)) || (RLV_ATTACHGROUP_HEAD != rlvAttachGroupFromIndex(attachment->getGroup())) );
-			}
+            bool fRlvCanShowAttachment = true;
+            if (rlv_handler_t::isEnabled())
+            {
+                fRlvCanShowAttachment =
+                    (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWSELF)) &&
+                    ( (!gRlvHandler.hasBehaviour(RLV_BHVR_SHOWSELFHEAD)) || (RLV_ATTACHGROUP_HEAD != rlvAttachGroupFromIndex(attachment->getGroup())) );
+            }
 // [/RLVa:KB]
 
-			switch (camera_mode)
-			{
-				case CAMERA_MODE_MOUSELOOK:
-					if ((LLVOAvatar::sVisibleInFirstPerson && attachment->getVisibleInFirstPerson()) || gPipeline.mHeroProbeManager.isMirrorPass())
-					{
+            switch (camera_mode)
+            {
+                case CAMERA_MODE_MOUSELOOK:
+                    if ((LLVOAvatar::sVisibleInFirstPerson && attachment->getVisibleInFirstPerson()) || gPipeline.mHeroProbeManager.isMirrorPass())
+                    {
 // [RLVa:KB] - Checked: RLVa-2.0.2
-						attachment->setAttachmentVisibility(fRlvCanShowAttachment);
+                        attachment->setAttachmentVisibility(fRlvCanShowAttachment);
 // [/RLVa:KB]
-//						attachment->setAttachmentVisibility(TRUE);
-					}
-					else
-					{
-						attachment->setAttachmentVisibility(FALSE);
-					}
-					break;
-				default:
+//                      attachment->setAttachmentVisibility(TRUE);
+                    }
+                    else
+                    {
+                        attachment->setAttachmentVisibility(FALSE);
+                    }
+                    break;
+                default:
 // [RLVa:KB] - Checked: RLVa-2.0.2
-					attachment->setAttachmentVisibility(fRlvCanShowAttachment);
+                    attachment->setAttachmentVisibility(fRlvCanShowAttachment);
 // [/RLVa:KB]
-//					attachment->setAttachmentVisibility(TRUE);
-					break;
-			}
-		}
-	}
+//                  attachment->setAttachmentVisibility(TRUE);
+                    break;
+            }
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1109,28 +1109,28 @@ void LLVOAvatarSelf::updateAttachmentVisibility(U32 camera_mode)
 //-----------------------------------------------------------------------------
 void LLVOAvatarSelf::wearableUpdated(LLWearableType::EType type)
 {
-	for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
-	{
-		const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
-		const LLAvatarAppearanceDefines::EBakedTextureIndex index = baked_pair.first;
-
-		if (baked_dict)
-		{
-			for (const LLWearableType::EType comp_type : baked_dict->mWearables)
-			{
-				if (comp_type == type)
-				{
-					LLViewerTexLayerSet *layerset = getLayerSet(index);
-					if (layerset)
-					{
-						layerset->setUpdatesEnabled(true);
-						invalidateComposite(layerset);
-					}
-					break;
-				}
-			}
-		}
-	}
+    for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
+    {
+        const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
+        const LLAvatarAppearanceDefines::EBakedTextureIndex index = baked_pair.first;
+
+        if (baked_dict)
+        {
+            for (const LLWearableType::EType comp_type : baked_dict->mWearables)
+            {
+                if (comp_type == type)
+                {
+                    LLViewerTexLayerSet *layerset = getLayerSet(index);
+                    if (layerset)
+                    {
+                        layerset->setUpdatesEnabled(true);
+                        invalidateComposite(layerset);
+                    }
+                    break;
+                }
+            }
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
@@ -1138,16 +1138,16 @@ void LLVOAvatarSelf::wearableUpdated(LLWearableType::EType type)
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatarSelf::isWearingAttachment(const LLUUID& inv_item_id) const
 {
-	const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		const LLViewerJointAttachment* attachment = attach_pair.second;
-		if (attachment->getAttachedObject(base_inv_item_id))
-		{
-			return TRUE;
-		}
-	}
-	return FALSE;
+    const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        const LLViewerJointAttachment* attachment = attach_pair.second;
+        if (attachment->getAttachedObject(base_inv_item_id))
+        {
+            return TRUE;
+        }
+    }
+    return FALSE;
 }
 
 //-----------------------------------------------------------------------------
@@ -1155,170 +1155,170 @@ BOOL LLVOAvatarSelf::isWearingAttachment(const LLUUID& inv_item_id) const
 //-----------------------------------------------------------------------------
 LLViewerObject* LLVOAvatarSelf::getWornAttachment(const LLUUID& inv_item_id)
 {
-	const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* attachment = attach_pair.second;
- 		if (LLViewerObject *attached_object = attachment->getAttachedObject(base_inv_item_id))
-		{
-			return attached_object;
-		}
-	}
-	return NULL;
+    const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* attachment = attach_pair.second;
+        if (LLViewerObject *attached_object = attachment->getAttachedObject(base_inv_item_id))
+        {
+            return attached_object;
+        }
+    }
+    return NULL;
 }
 
 // [RLVa:KB] - Checked: 2012-07-28 (RLVa-1.4.7)
 boost::signals2::connection LLVOAvatarSelf::setAttachmentCallback(const attachment_signal_t::slot_type& cb)
 {
-	if (!mAttachmentSignal)
-		mAttachmentSignal = new attachment_signal_t();
-	return mAttachmentSignal->connect(cb);
+    if (!mAttachmentSignal)
+        mAttachmentSignal = new attachment_signal_t();
+    return mAttachmentSignal->connect(cb);
 }
 // [/RLVa:KB]
 // [RLVa:KB] - Checked: 2010-03-14 (RLVa-1.2.0a) | Modified: RLVa-1.2.0a
 LLViewerJointAttachment* LLVOAvatarSelf::getWornAttachmentPoint(const LLUUID& idItem) const
 {
-	const LLUUID& idItemBase = gInventory.getLinkedItemID(idItem);
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		LLViewerJointAttachment* pAttachPt = attach_pair.second;
- 		if (pAttachPt->getAttachedObject(idItemBase))
-			return pAttachPt;
-	}
-	return NULL;
+    const LLUUID& idItemBase = gInventory.getLinkedItemID(idItem);
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        LLViewerJointAttachment* pAttachPt = attach_pair.second;
+        if (pAttachPt->getAttachedObject(idItemBase))
+            return pAttachPt;
+    }
+    return NULL;
 }
 // [/RLVa:KB]
 
 bool LLVOAvatarSelf::getAttachedPointName(const LLUUID& inv_item_id, std::string& name) const
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_AVATAR;
-	if (!gInventory.getItem(inv_item_id))
-	{
-		name = "ATTACHMENT_MISSING_ITEM";
-		return false;
-	}
-	const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
-	if (!gInventory.getItem(base_inv_item_id))
-	{
-		name = "ATTACHMENT_MISSING_BASE_ITEM";
-		return false;
-	}
-	for (const auto& attach_pair : mAttachmentPoints)
-	{
-		const LLViewerJointAttachment* attachment = attach_pair.second;
-		if (attachment->getAttachedObject(base_inv_item_id))
-		{
-			name = attachment->getName();
-			return true;
-		}
-	}
-
-	name = "ATTACHMENT_NOT_ATTACHED";
-	return false;
+    if (!gInventory.getItem(inv_item_id))
+    {
+        name = "ATTACHMENT_MISSING_ITEM";
+        return false;
+    }
+    const LLUUID& base_inv_item_id = gInventory.getLinkedItemID(inv_item_id);
+    if (!gInventory.getItem(base_inv_item_id))
+    {
+        name = "ATTACHMENT_MISSING_BASE_ITEM";
+        return false;
+    }
+    for (const auto& attach_pair : mAttachmentPoints)
+    {
+        const LLViewerJointAttachment* attachment = attach_pair.second;
+        if (attachment->getAttachedObject(base_inv_item_id))
+        {
+            name = attachment->getName();
+            return true;
+        }
+    }
+
+    name = "ATTACHMENT_NOT_ATTACHED";
+    return false;
 }
 
 //virtual
 const LLViewerJointAttachment *LLVOAvatarSelf::attachObject(LLViewerObject *viewer_object)
 {
-	const LLViewerJointAttachment *attachment = LLVOAvatar::attachObject(viewer_object);
-	if (!attachment)
-	{
-		return 0;
-	}
+    const LLViewerJointAttachment *attachment = LLVOAvatar::attachObject(viewer_object);
+    if (!attachment)
+    {
+        return 0;
+    }
 
-	updateAttachmentVisibility(gAgentCamera.getCameraMode());
-	
-	// Then make sure the inventory is in sync with the avatar.
+    updateAttachmentVisibility(gAgentCamera.getCameraMode());
 
-	// Should just be the last object added
-	if (attachment->isObjectAttached(viewer_object))
-	{
-		const LLUUID& attachment_id = viewer_object->getAttachmentItemID();
-		LLAppearanceMgr::instance().registerAttachment(attachment_id);
-		updateLODRiggedAttachments();		
+    // Then make sure the inventory is in sync with the avatar.
+
+    // Should just be the last object added
+    if (attachment->isObjectAttached(viewer_object))
+    {
+        const LLUUID& attachment_id = viewer_object->getAttachmentItemID();
+        LLAppearanceMgr::instance().registerAttachment(attachment_id);
+        updateLODRiggedAttachments();
 
 // [RLVa:KB] - Checked: 2010-08-22 (RLVa-1.2.1a) | Modified: RLVa-1.2.1a
-		// NOTE: RLVa event handlers should be invoked *after* LLVOAvatar::attachObject() calls LLViewerJointAttachment::addObject()
-		if (mAttachmentSignal)
-		{
-			(*mAttachmentSignal)(viewer_object, attachment, ACTION_ATTACH);
-		}
-		if (rlv_handler_t::isEnabled())
-		{
-			RlvAttachmentLockWatchdog::instance().onAttach(viewer_object, attachment);
-			gRlvHandler.onAttach(viewer_object, attachment);
-
-			if ( (attachment->getIsHUDAttachment()) && (!gRlvAttachmentLocks.hasLockedHUD()) )
-				gRlvAttachmentLocks.updateLockedHUD();
-		}
+        // NOTE: RLVa event handlers should be invoked *after* LLVOAvatar::attachObject() calls LLViewerJointAttachment::addObject()
+        if (mAttachmentSignal)
+        {
+            (*mAttachmentSignal)(viewer_object, attachment, ACTION_ATTACH);
+        }
+        if (rlv_handler_t::isEnabled())
+        {
+            RlvAttachmentLockWatchdog::instance().onAttach(viewer_object, attachment);
+            gRlvHandler.onAttach(viewer_object, attachment);
+
+            if ( (attachment->getIsHUDAttachment()) && (!gRlvAttachmentLocks.hasLockedHUD()) )
+                gRlvAttachmentLocks.updateLockedHUD();
+        }
 // [/RLVa:KB]
-	}
+    }
 
-	return attachment;
+    return attachment;
 }
 
 //virtual
 BOOL LLVOAvatarSelf::detachObject(LLViewerObject *viewer_object)
 {
-	const LLUUID attachment_id = viewer_object->getAttachmentItemID();
+    const LLUUID attachment_id = viewer_object->getAttachmentItemID();
 
 // [RLVa:KB] - Checked: 2010-03-05 (RLVa-1.2.0a) | Added: RLVa-1.2.0a
-	// NOTE: RLVa event handlers should be invoked *before* LLVOAvatar::detachObject() calls LLViewerJointAttachment::removeObject()
-	if (rlv_handler_t::isEnabled())
-	{
-		for (const auto& attach_pair : mAttachmentPoints)
-		{
-			const LLViewerJointAttachment* pAttachPt = attach_pair.second;
-			if (pAttachPt->isObjectAttached(viewer_object))
-			{
-				RlvAttachmentLockWatchdog::instance().onDetach(viewer_object, pAttachPt);
-				gRlvHandler.onDetach(viewer_object, pAttachPt);
-			}
-			if (mAttachmentSignal)
-			{
-				(*mAttachmentSignal)(viewer_object, pAttachPt, ACTION_DETACH);
-			}
-		}
-	}
+    // NOTE: RLVa event handlers should be invoked *before* LLVOAvatar::detachObject() calls LLViewerJointAttachment::removeObject()
+    if (rlv_handler_t::isEnabled())
+    {
+        for (const auto& attach_pair : mAttachmentPoints)
+        {
+            const LLViewerJointAttachment* pAttachPt = attach_pair.second;
+            if (pAttachPt->isObjectAttached(viewer_object))
+            {
+                RlvAttachmentLockWatchdog::instance().onDetach(viewer_object, pAttachPt);
+                gRlvHandler.onDetach(viewer_object, pAttachPt);
+            }
+            if (mAttachmentSignal)
+            {
+                (*mAttachmentSignal)(viewer_object, pAttachPt, ACTION_DETACH);
+            }
+        }
+    }
 // [/RLVa:KB]
 
-	if ( LLVOAvatar::detachObject(viewer_object) )
-	{
-		// the simulator should automatically handle permission revocation
-		
-		stopMotionFromSource(attachment_id);
-		LLFollowCamMgr::getInstance()->setCameraActive(viewer_object->getID(), FALSE);
-		
-		LLViewerObject::const_child_list_t& child_list = viewer_object->getChildren();
-		for (LLViewerObject* child_objectp : child_list)
-		{
-			// the simulator should automatically handle
-			// permissions revocation
-			
-			stopMotionFromSource(child_objectp->getID());
-			LLFollowCamMgr::getInstance()->setCameraActive(child_objectp->getID(), FALSE);
-		}
-		
-		// Make sure the inventory is in sync with the avatar.
-
-		// Update COF contents, don't trigger appearance update.
-		if (!isValid())
-		{
-			LL_INFOS() << "removeItemLinks skipped, avatar is under destruction" << LL_ENDL;
-		}
-		else
-		{
-			LLAppearanceMgr::instance().unregisterAttachment(attachment_id);
-		}
-		
+    if ( LLVOAvatar::detachObject(viewer_object) )
+    {
+        // the simulator should automatically handle permission revocation
+
+        stopMotionFromSource(attachment_id);
+        LLFollowCamMgr::getInstance()->setCameraActive(viewer_object->getID(), FALSE);
+
+        LLViewerObject::const_child_list_t& child_list = viewer_object->getChildren();
+        for (LLViewerObject* child_objectp : child_list)
+        {
+            // the simulator should automatically handle
+            // permissions revocation
+
+            stopMotionFromSource(child_objectp->getID());
+            LLFollowCamMgr::getInstance()->setCameraActive(child_objectp->getID(), FALSE);
+        }
+
+        // Make sure the inventory is in sync with the avatar.
+
+        // Update COF contents, don't trigger appearance update.
+        if (!isValid())
+        {
+            LL_INFOS() << "removeItemLinks skipped, avatar is under destruction" << LL_ENDL;
+        }
+        else
+        {
+            LLAppearanceMgr::instance().unregisterAttachment(attachment_id);
+        }
+
 // [RLVa:KB] - Checked: 2010-08-22 (RLVa-1.2.1a) | Added: RLVa-1.2.1a
-		if ( (rlv_handler_t::isEnabled()) && (viewer_object->isHUDAttachment()) && (gRlvAttachmentLocks.hasLockedHUD()) )
-			gRlvAttachmentLocks.updateLockedHUD();
+        if ( (rlv_handler_t::isEnabled()) && (viewer_object->isHUDAttachment()) && (gRlvAttachmentLocks.hasLockedHUD()) )
+            gRlvAttachmentLocks.updateLockedHUD();
 // [/RLVa:KB]
 
-		return TRUE;
-	}
-	return FALSE;
+        return TRUE;
+    }
+    return FALSE;
 }
 
 bool LLVOAvatarSelf::hasAttachmentsInTrash()
@@ -1345,143 +1345,143 @@ bool LLVOAvatarSelf::hasAttachmentsInTrash()
 // static
 BOOL LLVOAvatarSelf::detachAttachmentIntoInventory(const LLUUID &item_id)
 {
-	LLInventoryItem* item = gInventory.getItem(item_id);
-//	if (item)
+    LLInventoryItem* item = gInventory.getItem(item_id);
+//  if (item)
 // [RLVa:KB] - Checked: 2010-09-04 (RLVa-1.2.1c) | Added: RLVa-1.2.1c
-	if ( (item) && ((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(item))) )
+    if ( (item) && ((!rlv_handler_t::isEnabled()) || (gRlvAttachmentLocks.canDetach(item))) )
 // [/RLVa:KB]
-	{
-		gMessageSystem->newMessageFast(_PREHASH_DetachAttachmentIntoInv);
-		gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
-		gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
-		gMessageSystem->addUUIDFast(_PREHASH_ItemID, item_id);
-		gMessageSystem->sendReliable(gAgent.getRegionHost());
-		
-		// This object might have been selected, so let the selection manager know it's gone now
-		LLViewerObject *found_obj = gObjectList.findObject(item_id);
-		if (found_obj)
-		{
-			LLSelectMgr::getInstance()->remove(found_obj);
-		}
-
-		// Error checking in case this object was attached to an invalid point
-		// In that case, just remove the item from COF preemptively since detach 
-		// will fail.
-		if (isAgentAvatarValid())
-		{
-			const LLViewerObject *attached_obj = gAgentAvatarp->getWornAttachment(item_id);
-			if (!attached_obj)
-			{
-				LLAppearanceMgr::instance().removeCOFItemLinks(item_id);
-			}
-		}
-		return TRUE;
-	}
-	return FALSE;
+    {
+        gMessageSystem->newMessageFast(_PREHASH_DetachAttachmentIntoInv);
+        gMessageSystem->nextBlockFast(_PREHASH_ObjectData);
+        gMessageSystem->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
+        gMessageSystem->addUUIDFast(_PREHASH_ItemID, item_id);
+        gMessageSystem->sendReliable(gAgent.getRegionHost());
+
+        // This object might have been selected, so let the selection manager know it's gone now
+        LLViewerObject *found_obj = gObjectList.findObject(item_id);
+        if (found_obj)
+        {
+            LLSelectMgr::getInstance()->remove(found_obj);
+        }
+
+        // Error checking in case this object was attached to an invalid point
+        // In that case, just remove the item from COF preemptively since detach
+        // will fail.
+        if (isAgentAvatarValid())
+        {
+            const LLViewerObject *attached_obj = gAgentAvatarp->getWornAttachment(item_id);
+            if (!attached_obj)
+            {
+                LLAppearanceMgr::instance().removeCOFItemLinks(item_id);
+            }
+        }
+        return TRUE;
+    }
+    return FALSE;
 }
 
 U32 LLVOAvatarSelf::getNumWearables(LLAvatarAppearanceDefines::ETextureIndex i) const
 {
-	LLWearableType::EType type = sAvatarDictionary->getTEWearableType(i);
-	return gAgentWearables.getWearableCount(type);
+    LLWearableType::EType type = sAvatarDictionary->getTEWearableType(i);
+    return gAgentWearables.getWearableCount(type);
 }
 
 // virtual
 void LLVOAvatarSelf::localTextureLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src_raw, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
-{	
-
-	const LLUUID& src_id = src_vi->getID();
-	LLAvatarTexData *data = (LLAvatarTexData *)userdata;
-	ETextureIndex index = data->mIndex;
-	if (!isIndexLocalTexture(index)) return;
-
-	LLLocalTextureObject *local_tex_obj = getLocalTextureObject(index, 0);
-
-	// fix for EXT-268. Preventing using of NULL pointer
-	if(NULL == local_tex_obj)
-	{
-		LL_WARNS("TAG") << "There is no Local Texture Object with index: " << index 
-			<< ", final: " << final
-			<< LL_ENDL;
-		return;
-	}
-	if (success)
-	{
-		if (!local_tex_obj->getBakedReady() &&
-			local_tex_obj->getImage() != NULL &&
-			(local_tex_obj->getID() == src_id) &&
-			discard_level < local_tex_obj->getDiscard())
-		{
-			local_tex_obj->setDiscard(discard_level);
-			requestLayerSetUpdate(index);
-			if (isEditingAppearance())
-			{
-				LLVisualParamHint::requestHintUpdates();
-			}
-			updateMeshTextures();
-		}
-	}
-	else if (final)
-	{
-		// Failed: asset is missing
-		if (!local_tex_obj->getBakedReady() &&
-			local_tex_obj->getImage() != NULL &&
-			local_tex_obj->getImage()->getID() == src_id)
-		{
-			local_tex_obj->setDiscard(0);
-			requestLayerSetUpdate(index);
-			updateMeshTextures();
-		}
-	}
+{
+
+    const LLUUID& src_id = src_vi->getID();
+    LLAvatarTexData *data = (LLAvatarTexData *)userdata;
+    ETextureIndex index = data->mIndex;
+    if (!isIndexLocalTexture(index)) return;
+
+    LLLocalTextureObject *local_tex_obj = getLocalTextureObject(index, 0);
+
+    // fix for EXT-268. Preventing using of NULL pointer
+    if(NULL == local_tex_obj)
+    {
+        LL_WARNS("TAG") << "There is no Local Texture Object with index: " << index
+            << ", final: " << final
+            << LL_ENDL;
+        return;
+    }
+    if (success)
+    {
+        if (!local_tex_obj->getBakedReady() &&
+            local_tex_obj->getImage() != NULL &&
+            (local_tex_obj->getID() == src_id) &&
+            discard_level < local_tex_obj->getDiscard())
+        {
+            local_tex_obj->setDiscard(discard_level);
+            requestLayerSetUpdate(index);
+            if (isEditingAppearance())
+            {
+                LLVisualParamHint::requestHintUpdates();
+            }
+            updateMeshTextures();
+        }
+    }
+    else if (final)
+    {
+        // Failed: asset is missing
+        if (!local_tex_obj->getBakedReady() &&
+            local_tex_obj->getImage() != NULL &&
+            local_tex_obj->getImage()->getID() == src_id)
+        {
+            local_tex_obj->setDiscard(0);
+            requestLayerSetUpdate(index);
+            updateMeshTextures();
+        }
+    }
 }
 
 // virtual
 BOOL LLVOAvatarSelf::getLocalTextureGL(ETextureIndex type, LLViewerTexture** tex_pp, U32 index) const
 {
-	*tex_pp = NULL;
+    *tex_pp = NULL;
 
-	if (!isIndexLocalTexture(type)) return FALSE;
-	if (getLocalTextureID(type, index) == IMG_DEFAULT_AVATAR) return TRUE;
+    if (!isIndexLocalTexture(type)) return FALSE;
+    if (getLocalTextureID(type, index) == IMG_DEFAULT_AVATAR) return TRUE;
 
-	const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, index);
-	if (!local_tex_obj)
-	{
-		return FALSE;
-	}
-	*tex_pp = dynamic_cast<LLViewerTexture*> (local_tex_obj->getImage());
-	return TRUE;
+    const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, index);
+    if (!local_tex_obj)
+    {
+        return FALSE;
+    }
+    *tex_pp = dynamic_cast<LLViewerTexture*> (local_tex_obj->getImage());
+    return TRUE;
 }
 
 LLViewerFetchedTexture* LLVOAvatarSelf::getLocalTextureGL(LLAvatarAppearanceDefines::ETextureIndex type, U32 index) const
 {
-	if (!isIndexLocalTexture(type))
-	{
-		return NULL;
-	}
+    if (!isIndexLocalTexture(type))
+    {
+        return NULL;
+    }
 
-	const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, index);
-	if (!local_tex_obj)
-	{
-		return NULL;
-	}
-	if (local_tex_obj->getID() == IMG_DEFAULT_AVATAR)
-	{
-		return LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR);
-	}
-	return dynamic_cast<LLViewerFetchedTexture*> (local_tex_obj->getImage());
+    const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, index);
+    if (!local_tex_obj)
+    {
+        return NULL;
+    }
+    if (local_tex_obj->getID() == IMG_DEFAULT_AVATAR)
+    {
+        return LLViewerTextureManager::getFetchedTexture(IMG_DEFAULT_AVATAR);
+    }
+    return dynamic_cast<LLViewerFetchedTexture*> (local_tex_obj->getImage());
 }
 
 const LLUUID& LLVOAvatarSelf::getLocalTextureID(ETextureIndex type, U32 index) const
 {
-	if (!isIndexLocalTexture(type)) return IMG_DEFAULT_AVATAR;
+    if (!isIndexLocalTexture(type)) return IMG_DEFAULT_AVATAR;
 
-	const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, index);
-	if (local_tex_obj && local_tex_obj->getImage() != NULL)
-	{
-		return local_tex_obj->getImage()->getID();
-	}
-	return IMG_DEFAULT_AVATAR;
-} 
+    const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, index);
+    if (local_tex_obj && local_tex_obj->getImage() != NULL)
+    {
+        return local_tex_obj->getImage()->getID();
+    }
+    return IMG_DEFAULT_AVATAR;
+}
 
 
 //-----------------------------------------------------------------------------
@@ -1491,30 +1491,30 @@ const LLUUID& LLVOAvatarSelf::getLocalTextureID(ETextureIndex type, U32 index) c
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatarSelf::isLocalTextureDataAvailable(const LLViewerTexLayerSet* layerset) const
 {
-	/* if (layerset == mBakedTextureDatas[BAKED_HEAD].mTexLayerSet)
-	   return getLocalDiscardLevel(TEX_HEAD_BODYPAINT) >= 0; */
-	for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
-	{
-		const EBakedTextureIndex baked_index = baked_pair.first;
-		if (layerset == mBakedTextureDatas[baked_index].mTexLayerSet)
-		{
-			BOOL ret = true;
-			const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
-			for (const ETextureIndex tex_index : baked_dict->mLocalTextures)
-			{
-				const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
-				const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
-				for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
-				{
-					BOOL tex_avail = (getLocalDiscardLevel(tex_index, wearable_index) >= 0);
-					ret &= tex_avail;
-				}
-			}
-			return ret;
-		}
-	}
-	llassert(0);
-	return FALSE;
+    /* if (layerset == mBakedTextureDatas[BAKED_HEAD].mTexLayerSet)
+       return getLocalDiscardLevel(TEX_HEAD_BODYPAINT) >= 0; */
+    for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
+    {
+        const EBakedTextureIndex baked_index = baked_pair.first;
+        if (layerset == mBakedTextureDatas[baked_index].mTexLayerSet)
+        {
+            BOOL ret = true;
+            const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
+            for (const ETextureIndex tex_index : baked_dict->mLocalTextures)
+            {
+                const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
+                const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
+                for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
+                {
+                    BOOL tex_avail = (getLocalDiscardLevel(tex_index, wearable_index) >= 0);
+                    ret &= tex_avail;
+                }
+            }
+            return ret;
+        }
+    }
+    llassert(0);
+    return FALSE;
 }
 
 //-----------------------------------------------------------------------------
@@ -1525,153 +1525,153 @@ BOOL LLVOAvatarSelf::isLocalTextureDataAvailable(const LLViewerTexLayerSet* laye
 //-----------------------------------------------------------------------------
 BOOL LLVOAvatarSelf::isLocalTextureDataFinal(const LLViewerTexLayerSet* layerset) const
 {
-	static const LLCachedControl<U32> desired_tex_discard_level(gSavedSettings, "TextureDiscardLevel");
-	// const U32 desired_tex_discard_level = 0; // hack to not bake textures on lower discard levels.
-
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		if (layerset == mBakedTextureDatas[i].mTexLayerSet)
-		{
-			const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = sAvatarDictionary->getBakedTexture((EBakedTextureIndex)i);
-			for (const ETextureIndex tex_index : baked_dict->mLocalTextures)
-			{
-				const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
-				const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
-				for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
-				{
-					S32 local_discard_level = getLocalDiscardLevel(tex_index, wearable_index);
-					if ((local_discard_level > (S32)(desired_tex_discard_level)) ||
-						(local_discard_level < 0 ))
-					{
-						return FALSE;
-					}
-				}
-			}
-			return TRUE;
-		}
-	}
-	llassert(0);
-	return FALSE;
+    static const LLCachedControl<U32> desired_tex_discard_level(gSavedSettings, "TextureDiscardLevel");
+    // const U32 desired_tex_discard_level = 0; // hack to not bake textures on lower discard levels.
+
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        if (layerset == mBakedTextureDatas[i].mTexLayerSet)
+        {
+            const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = sAvatarDictionary->getBakedTexture((EBakedTextureIndex)i);
+            for (const ETextureIndex tex_index : baked_dict->mLocalTextures)
+            {
+                const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
+                const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
+                for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
+                {
+                    S32 local_discard_level = getLocalDiscardLevel(tex_index, wearable_index);
+                    if ((local_discard_level > (S32)(desired_tex_discard_level)) ||
+                        (local_discard_level < 0 ))
+                    {
+                        return FALSE;
+                    }
+                }
+            }
+            return TRUE;
+        }
+    }
+    llassert(0);
+    return FALSE;
 }
 
 
 BOOL LLVOAvatarSelf::isAllLocalTextureDataFinal() const
 {
-	static const LLCachedControl<U32> desired_tex_discard_level(gSavedSettings, "TextureDiscardLevel");
-	// const U32 desired_tex_discard_level = 0; // hack to not bake textures on lower discard levels
-
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = sAvatarDictionary->getBakedTexture((EBakedTextureIndex)i);
-		for (const ETextureIndex tex_index : baked_dict->mLocalTextures)
-		{
-			const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
-			const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
-			for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
-			{
-				S32 local_discard_level = getLocalDiscardLevel(tex_index, wearable_index);
-				if ((local_discard_level > (S32)(desired_tex_discard_level)) ||
-					(local_discard_level < 0 ))
-				{
-					return FALSE;
-				}
-			}
-		}
-	}
-	return TRUE;
+    static const LLCachedControl<U32> desired_tex_discard_level(gSavedSettings, "TextureDiscardLevel");
+    // const U32 desired_tex_discard_level = 0; // hack to not bake textures on lower discard levels
+
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = sAvatarDictionary->getBakedTexture((EBakedTextureIndex)i);
+        for (const ETextureIndex tex_index : baked_dict->mLocalTextures)
+        {
+            const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
+            const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
+            for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
+            {
+                S32 local_discard_level = getLocalDiscardLevel(tex_index, wearable_index);
+                if ((local_discard_level > (S32)(desired_tex_discard_level)) ||
+                    (local_discard_level < 0 ))
+                {
+                    return FALSE;
+                }
+            }
+        }
+    }
+    return TRUE;
 }
 
 BOOL LLVOAvatarSelf::isTextureDefined(LLAvatarAppearanceDefines::ETextureIndex type, U32 index) const
 {
-	LLUUID id;
-	BOOL isDefined = TRUE;
-	if (isIndexLocalTexture(type))
-	{
-		const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(type);
-		const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
-		if (index >= wearable_count)
-		{
-			// invalid index passed in. check all textures of a given type
-			for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
-			{
-				id = getLocalTextureID(type, wearable_index);
-				isDefined &= (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
-			}
-		}
-		else
-		{
-			id = getLocalTextureID(type, index);
-			isDefined &= (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
-		}
-	}
-	else
-	{
-		id = getTEImage(type)->getID();
-		isDefined &= (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
-	}
-	
-	return isDefined;
+    LLUUID id;
+    BOOL isDefined = TRUE;
+    if (isIndexLocalTexture(type))
+    {
+        const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(type);
+        const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
+        if (index >= wearable_count)
+        {
+            // invalid index passed in. check all textures of a given type
+            for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
+            {
+                id = getLocalTextureID(type, wearable_index);
+                isDefined &= (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
+            }
+        }
+        else
+        {
+            id = getLocalTextureID(type, index);
+            isDefined &= (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
+        }
+    }
+    else
+    {
+        id = getTEImage(type)->getID();
+        isDefined &= (id != IMG_DEFAULT_AVATAR && id != IMG_DEFAULT);
+    }
+
+    return isDefined;
 }
 
 //virtual
 BOOL LLVOAvatarSelf::isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type, U32 index) const
 {
-	if (isIndexBakedTexture(type))
-	{
-		return LLVOAvatar::isTextureVisible(type, (U32)0);
-	}
+    if (isIndexBakedTexture(type))
+    {
+        return LLVOAvatar::isTextureVisible(type, (U32)0);
+    }
 
-	LLUUID tex_id = getLocalTextureID(type,index);
-	return (tex_id != IMG_INVISIBLE) 
-			|| (LLDrawPoolAlpha::sShowDebugAlpha);
+    LLUUID tex_id = getLocalTextureID(type,index);
+    return (tex_id != IMG_INVISIBLE)
+            || (LLDrawPoolAlpha::sShowDebugAlpha);
 }
 
 //virtual
 BOOL LLVOAvatarSelf::isTextureVisible(LLAvatarAppearanceDefines::ETextureIndex type, LLViewerWearable *wearable) const
 {
-	if (isIndexBakedTexture(type))
-	{
-		return LLVOAvatar::isTextureVisible(type);
-	}
+    if (isIndexBakedTexture(type))
+    {
+        return LLVOAvatar::isTextureVisible(type);
+    }
 
-	U32 index;
-	if (gAgentWearables.getWearableIndex(wearable,index))
-	{
-		return isTextureVisible(type,index);
-	}
-	else
-	{
-		LL_WARNS() << "Wearable not found" << LL_ENDL;
-		return FALSE;
-	}
+    U32 index;
+    if (gAgentWearables.getWearableIndex(wearable,index))
+    {
+        return isTextureVisible(type,index);
+    }
+    else
+    {
+        LL_WARNS() << "Wearable not found" << LL_ENDL;
+        return FALSE;
+    }
 }
 
 bool LLVOAvatarSelf::areTexturesCurrent() const
 {
-	return gAgentWearables.areWearablesLoaded();
+    return gAgentWearables.areWearablesLoaded();
 }
 
 void LLVOAvatarSelf::invalidateComposite( LLTexLayerSet* layerset)
 {
-	LLViewerTexLayerSet *layer_set = dynamic_cast<LLViewerTexLayerSet*>(layerset);
-	if( !layer_set || !layer_set->getUpdatesEnabled() )
-	{
-		return;
-	}
-	// LL_INFOS() << "LLVOAvatar::invalidComposite() " << layerset->getBodyRegionName() << LL_ENDL;
+    LLViewerTexLayerSet *layer_set = dynamic_cast<LLViewerTexLayerSet*>(layerset);
+    if( !layer_set || !layer_set->getUpdatesEnabled() )
+    {
+        return;
+    }
+    // LL_INFOS() << "LLVOAvatar::invalidComposite() " << layerset->getBodyRegionName() << LL_ENDL;
 
-	layer_set->requestUpdate();
-	layer_set->invalidateMorphMasks();
+    layer_set->requestUpdate();
+    layer_set->invalidateMorphMasks();
 }
 
 void LLVOAvatarSelf::invalidateAll()
 {
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		LLViewerTexLayerSet *layerset = getTexLayerSet(i);
-		invalidateComposite(layerset);
-	}
-	//mDebugSelfLoadTimer.reset();
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        LLViewerTexLayerSet *layerset = getTexLayerSet(i);
+        invalidateComposite(layerset);
+    }
+    //mDebugSelfLoadTimer.reset();
 }
 
 //-----------------------------------------------------------------------------
@@ -1679,585 +1679,585 @@ void LLVOAvatarSelf::invalidateAll()
 //-----------------------------------------------------------------------------
 void LLVOAvatarSelf::setCompositeUpdatesEnabled( bool b )
 {
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		setCompositeUpdatesEnabled(i, b);
-	}
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        setCompositeUpdatesEnabled(i, b);
+    }
 }
 
 void LLVOAvatarSelf::setCompositeUpdatesEnabled(U32 index, bool b)
 {
-	LLViewerTexLayerSet *layerset = getTexLayerSet(index);
-	if (layerset )
-	{
-		layerset->setUpdatesEnabled( b );
-	}
+    LLViewerTexLayerSet *layerset = getTexLayerSet(index);
+    if (layerset )
+    {
+        layerset->setUpdatesEnabled( b );
+    }
 }
 
 bool LLVOAvatarSelf::isCompositeUpdateEnabled(U32 index)
 {
-	LLViewerTexLayerSet *layerset = getTexLayerSet(index);
-	if (layerset)
-	{
-		return layerset->getUpdatesEnabled();
-	}
-	return false;
+    LLViewerTexLayerSet *layerset = getTexLayerSet(index);
+    if (layerset)
+    {
+        return layerset->getUpdatesEnabled();
+    }
+    return false;
 }
 
 void LLVOAvatarSelf::setupComposites()
 {
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		ETextureIndex tex_index = mBakedTextureDatas[i].mTextureIndex;
-		BOOL layer_baked = isTextureDefined(tex_index, gAgentWearables.getWearableCount(tex_index));
-		LLViewerTexLayerSet *layerset = getTexLayerSet(i);
-		if (layerset)
-		{
-			layerset->setUpdatesEnabled(!layer_baked);
-		}
-	}
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        ETextureIndex tex_index = mBakedTextureDatas[i].mTextureIndex;
+        BOOL layer_baked = isTextureDefined(tex_index, gAgentWearables.getWearableCount(tex_index));
+        LLViewerTexLayerSet *layerset = getTexLayerSet(i);
+        if (layerset)
+        {
+            layerset->setUpdatesEnabled(!layer_baked);
+        }
+    }
 }
 
 void LLVOAvatarSelf::updateComposites()
 {
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		LLViewerTexLayerSet *layerset = getTexLayerSet(i);
-		if (layerset 
-			&& ((i != BAKED_SKIRT) || isWearingWearableType(LLWearableType::WT_SKIRT)))
-		{
-			layerset->updateComposite();
-		}
-	}
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        LLViewerTexLayerSet *layerset = getTexLayerSet(i);
+        if (layerset
+            && ((i != BAKED_SKIRT) || isWearingWearableType(LLWearableType::WT_SKIRT)))
+        {
+            layerset->updateComposite();
+        }
+    }
 }
 
 // virtual
 S32 LLVOAvatarSelf::getLocalDiscardLevel(ETextureIndex type, U32 wearable_index) const
 {
-	if (!isIndexLocalTexture(type)) return FALSE;
-
-	const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, wearable_index);
-	if (local_tex_obj)
-	{
-		const LLViewerFetchedTexture* image = dynamic_cast<LLViewerFetchedTexture*>( local_tex_obj->getImage() );
-		if (type >= 0
-			&& local_tex_obj->getID() != IMG_DEFAULT_AVATAR
-			&& !image->isMissingAsset())
-		{
-			return image->getDiscardLevel();
-		}
-		else
-		{
-			// We don't care about this (no image associated with the layer) treat as fully loaded.
-			return 0;
-		}
-	}
-	return 0;
+    if (!isIndexLocalTexture(type)) return FALSE;
+
+    const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type, wearable_index);
+    if (local_tex_obj)
+    {
+        const LLViewerFetchedTexture* image = dynamic_cast<LLViewerFetchedTexture*>( local_tex_obj->getImage() );
+        if (type >= 0
+            && local_tex_obj->getID() != IMG_DEFAULT_AVATAR
+            && !image->isMissingAsset())
+        {
+            return image->getDiscardLevel();
+        }
+        else
+        {
+            // We don't care about this (no image associated with the layer) treat as fully loaded.
+            return 0;
+        }
+    }
+    return 0;
 }
 
 // virtual
 // Counts the memory footprint of local textures.
 void LLVOAvatarSelf::getLocalTextureByteCount(S32* gl_bytes) const
 {
-	*gl_bytes = 0;
-	for (S32 type = 0; type < TEX_NUM_INDICES; type++)
-	{
-		if (!isIndexLocalTexture((ETextureIndex)type)) continue;
-		U32 max_tex = getNumWearables((ETextureIndex) type);
-		for (U32 num = 0; num < max_tex; num++)
-		{
-			const LLLocalTextureObject *local_tex_obj = getLocalTextureObject((ETextureIndex) type, num);
-			if (local_tex_obj)
-			{
-				const LLViewerFetchedTexture* image_gl = dynamic_cast<LLViewerFetchedTexture*>( local_tex_obj->getImage() );
-				if (image_gl)
-				{
-					S32 bytes = (S32)image_gl->getWidth() * image_gl->getHeight() * image_gl->getComponents();
-					
-					if (image_gl->hasGLTexture())
-					{
-						*gl_bytes += bytes;
-					}
-				}
-			}
-		}
-	}
-}
-
-// virtual 
+    *gl_bytes = 0;
+    for (S32 type = 0; type < TEX_NUM_INDICES; type++)
+    {
+        if (!isIndexLocalTexture((ETextureIndex)type)) continue;
+        U32 max_tex = getNumWearables((ETextureIndex) type);
+        for (U32 num = 0; num < max_tex; num++)
+        {
+            const LLLocalTextureObject *local_tex_obj = getLocalTextureObject((ETextureIndex) type, num);
+            if (local_tex_obj)
+            {
+                const LLViewerFetchedTexture* image_gl = dynamic_cast<LLViewerFetchedTexture*>( local_tex_obj->getImage() );
+                if (image_gl)
+                {
+                    S32 bytes = (S32)image_gl->getWidth() * image_gl->getHeight() * image_gl->getComponents();
+
+                    if (image_gl->hasGLTexture())
+                    {
+                        *gl_bytes += bytes;
+                    }
+                }
+            }
+        }
+    }
+}
+
+// virtual
 void LLVOAvatarSelf::setLocalTexture(ETextureIndex type, LLViewerTexture* src_tex, BOOL baked_version_ready, U32 index)
 {
-	if (!isIndexLocalTexture(type)) return;
-
-	LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(src_tex, TRUE) ;
-	if(!tex)
-	{
-		return ;
-	}
-
-	S32 desired_discard = isSelf() ? 0 : 2;
-	LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type,index);
-	if (!local_tex_obj)
-	{
-		if (type >= TEX_NUM_INDICES)
-		{
-			LL_ERRS() << "Tried to set local texture with invalid type: (" << (U32) type << ", " << index << ")" << LL_ENDL;
-			return;
-		}
-		LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(type);
-		if (!gAgentWearables.getViewerWearable(wearable_type,index))
-		{
-			// no wearable is loaded, cannot set the texture.
-			return;
-		}
-		gAgentWearables.addLocalTextureObject(wearable_type,type,index);
-		local_tex_obj = getLocalTextureObject(type,index);
-		if (!local_tex_obj)
-		{
-			LL_ERRS() << "Unable to create LocalTextureObject for wearable type & index: (" << (U32) wearable_type << ", " << index << ")" << LL_ENDL;
-			return;
-		}
-		
-		LLViewerTexLayerSet *layer_set = getLayerSet(type);
-		if (layer_set)
-		{
-			layer_set->cloneTemplates(local_tex_obj, type, gAgentWearables.getViewerWearable(wearable_type,index));
-		}
-
-	}
-	if (!baked_version_ready)
-	{
-		if (tex != local_tex_obj->getImage() || local_tex_obj->getBakedReady())
-		{
-			local_tex_obj->setDiscard(MAX_DISCARD_LEVEL+1);
-		}
-		if (tex->getID() != IMG_DEFAULT_AVATAR)
-		{
-			if (local_tex_obj->getDiscard() > desired_discard)
-			{
-				S32 tex_discard = tex->getDiscardLevel();
-				if (tex_discard >= 0 && tex_discard <= desired_discard)
-				{
-					local_tex_obj->setDiscard(tex_discard);
-					if (isSelf())
-					{
-						requestLayerSetUpdate(type);
-						if (isEditingAppearance())
-						{
-							LLVisualParamHint::requestHintUpdates();
-						}
-					}
-				}
-				else
-				{					
-					tex->setLoadedCallback(onLocalTextureLoaded, desired_discard, TRUE, FALSE, new LLAvatarTexData(getID(), type), NULL);
-				}
-			}
-			tex->setMinDiscardLevel(desired_discard);
-		}
-	}
-	local_tex_obj->setImage(tex);
-	local_tex_obj->setID(tex->getID());
-	setBakedReady(type,baked_version_ready,index);
+    if (!isIndexLocalTexture(type)) return;
+
+    LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(src_tex, TRUE) ;
+    if(!tex)
+    {
+        return ;
+    }
+
+    S32 desired_discard = isSelf() ? 0 : 2;
+    LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type,index);
+    if (!local_tex_obj)
+    {
+        if (type >= TEX_NUM_INDICES)
+        {
+            LL_ERRS() << "Tried to set local texture with invalid type: (" << (U32) type << ", " << index << ")" << LL_ENDL;
+            return;
+        }
+        LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(type);
+        if (!gAgentWearables.getViewerWearable(wearable_type,index))
+        {
+            // no wearable is loaded, cannot set the texture.
+            return;
+        }
+        gAgentWearables.addLocalTextureObject(wearable_type,type,index);
+        local_tex_obj = getLocalTextureObject(type,index);
+        if (!local_tex_obj)
+        {
+            LL_ERRS() << "Unable to create LocalTextureObject for wearable type & index: (" << (U32) wearable_type << ", " << index << ")" << LL_ENDL;
+            return;
+        }
+
+        LLViewerTexLayerSet *layer_set = getLayerSet(type);
+        if (layer_set)
+        {
+            layer_set->cloneTemplates(local_tex_obj, type, gAgentWearables.getViewerWearable(wearable_type,index));
+        }
+
+    }
+    if (!baked_version_ready)
+    {
+        if (tex != local_tex_obj->getImage() || local_tex_obj->getBakedReady())
+        {
+            local_tex_obj->setDiscard(MAX_DISCARD_LEVEL+1);
+        }
+        if (tex->getID() != IMG_DEFAULT_AVATAR)
+        {
+            if (local_tex_obj->getDiscard() > desired_discard)
+            {
+                S32 tex_discard = tex->getDiscardLevel();
+                if (tex_discard >= 0 && tex_discard <= desired_discard)
+                {
+                    local_tex_obj->setDiscard(tex_discard);
+                    if (isSelf())
+                    {
+                        requestLayerSetUpdate(type);
+                        if (isEditingAppearance())
+                        {
+                            LLVisualParamHint::requestHintUpdates();
+                        }
+                    }
+                }
+                else
+                {
+                    tex->setLoadedCallback(onLocalTextureLoaded, desired_discard, TRUE, FALSE, new LLAvatarTexData(getID(), type), NULL);
+                }
+            }
+            tex->setMinDiscardLevel(desired_discard);
+        }
+    }
+    local_tex_obj->setImage(tex);
+    local_tex_obj->setID(tex->getID());
+    setBakedReady(type,baked_version_ready,index);
 }
 
 //virtual
 void LLVOAvatarSelf::setBakedReady(LLAvatarAppearanceDefines::ETextureIndex type, BOOL baked_version_exists, U32 index)
 {
-	if (!isIndexLocalTexture(type)) return;
-	LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type,index);
-	if (local_tex_obj)
-	{
-		local_tex_obj->setBakedReady( baked_version_exists );
-	}
+    if (!isIndexLocalTexture(type)) return;
+    LLLocalTextureObject *local_tex_obj = getLocalTextureObject(type,index);
+    if (local_tex_obj)
+    {
+        local_tex_obj->setBakedReady( baked_version_exists );
+    }
 }
 
 
 // virtual
 void LLVOAvatarSelf::dumpLocalTextures() const
 {
-	LL_INFOS() << "Local Textures:" << LL_ENDL;
+    LL_INFOS() << "Local Textures:" << LL_ENDL;
 
-	/* ETextureIndex baked_equiv[] = {
-	   TEX_UPPER_BAKED,
-	   if (isTextureDefined(baked_equiv[i])) */
+    /* ETextureIndex baked_equiv[] = {
+       TEX_UPPER_BAKED,
+       if (isTextureDefined(baked_equiv[i])) */
 
-	for (const auto& tex_pair : sAvatarDictionary->getTextures())
-	{
-		const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
-		if (!texture_dict->mIsLocalTexture || !texture_dict->mIsUsedByBakedTexture)
-			continue;
+    for (const auto& tex_pair : sAvatarDictionary->getTextures())
+    {
+        const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
+        if (!texture_dict->mIsLocalTexture || !texture_dict->mIsUsedByBakedTexture)
+            continue;
 
-		const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex;
-		const ETextureIndex baked_equiv = sAvatarDictionary->getBakedTexture(baked_index)->mTextureIndex;
+        const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex;
+        const ETextureIndex baked_equiv = sAvatarDictionary->getBakedTexture(baked_index)->mTextureIndex;
 
-		const std::string &name = texture_dict->mName;
-		const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(tex_pair.first, 0);
-		// index is baked texture - index is not relevant. putting in 0 as placeholder
-		if (isTextureDefined(baked_equiv, 0))
-		{
+        const std::string &name = texture_dict->mName;
+        const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(tex_pair.first, 0);
+        // index is baked texture - index is not relevant. putting in 0 as placeholder
+        if (isTextureDefined(baked_equiv, 0))
+        {
 #if LL_RELEASE_FOR_DOWNLOAD
-			// End users don't get to trivially see avatar texture IDs, makes textures
-			// easier to steal. JC
-			LL_INFOS() << "LocTex " << name << ": Baked " << LL_ENDL;
+            // End users don't get to trivially see avatar texture IDs, makes textures
+            // easier to steal. JC
+            LL_INFOS() << "LocTex " << name << ": Baked " << LL_ENDL;
 #else
-			LL_INFOS() << "LocTex " << name << ": Baked " << getTEImage(baked_equiv)->getID() << LL_ENDL;
+            LL_INFOS() << "LocTex " << name << ": Baked " << getTEImage(baked_equiv)->getID() << LL_ENDL;
 #endif
-		}
-		else if (local_tex_obj && local_tex_obj->getImage() != NULL)
-		{
-			if (local_tex_obj->getImage()->getID() == IMG_DEFAULT_AVATAR)
-			{
-				LL_INFOS() << "LocTex " << name << ": None" << LL_ENDL;
-			}
-			else
-			{
-				LLViewerFetchedTexture* image = dynamic_cast<LLViewerFetchedTexture*>( local_tex_obj->getImage() );
-
-				LL_INFOS() << "LocTex " << name << ": "
-						<< "Discard " << image->getDiscardLevel() << ", "
-						<< "(" << image->getWidth() << ", " << image->getHeight() << ") " 
+        }
+        else if (local_tex_obj && local_tex_obj->getImage() != NULL)
+        {
+            if (local_tex_obj->getImage()->getID() == IMG_DEFAULT_AVATAR)
+            {
+                LL_INFOS() << "LocTex " << name << ": None" << LL_ENDL;
+            }
+            else
+            {
+                LLViewerFetchedTexture* image = dynamic_cast<LLViewerFetchedTexture*>( local_tex_obj->getImage() );
+
+                LL_INFOS() << "LocTex " << name << ": "
+                        << "Discard " << image->getDiscardLevel() << ", "
+                        << "(" << image->getWidth() << ", " << image->getHeight() << ") "
 #if !LL_RELEASE_FOR_DOWNLOAD
-					// End users don't get to trivially see avatar texture IDs,
-					// makes textures easier to steal
-						<< image->getID() << " "
+                    // End users don't get to trivially see avatar texture IDs,
+                    // makes textures easier to steal
+                        << image->getID() << " "
 #endif
-						<< "Priority: " << image->getMaxVirtualSize()
-						<< LL_ENDL;
-			}
-		}
-		else
-		{
-			LL_INFOS() << "LocTex " << name << ": No LLViewerTexture" << LL_ENDL;
-		}
-	}
+                        << "Priority: " << image->getMaxVirtualSize()
+                        << LL_ENDL;
+            }
+        }
+        else
+        {
+            LL_INFOS() << "LocTex " << name << ": No LLViewerTexture" << LL_ENDL;
+        }
+    }
 }
 
 //-----------------------------------------------------------------------------
-// static 
+// static
 // onLocalTextureLoaded()
 //-----------------------------------------------------------------------------
 
 void LLVOAvatarSelf::onLocalTextureLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src_raw, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
 {
-	LLAvatarTexData *data = (LLAvatarTexData *)userdata;
-	LLVOAvatarSelf *self = (LLVOAvatarSelf *)gObjectList.findObject(data->mAvatarID);
-	if (self)
-	{
-		// We should only be handling local textures for ourself
-		self->localTextureLoaded(success, src_vi, src_raw, aux_src, discard_level, final, userdata);
-	}
-	// ensure data is cleaned up
-	if (final || !success)
-	{
-		delete data;
-	}
+    LLAvatarTexData *data = (LLAvatarTexData *)userdata;
+    LLVOAvatarSelf *self = (LLVOAvatarSelf *)gObjectList.findObject(data->mAvatarID);
+    if (self)
+    {
+        // We should only be handling local textures for ourself
+        self->localTextureLoaded(success, src_vi, src_raw, aux_src, discard_level, final, userdata);
+    }
+    // ensure data is cleaned up
+    if (final || !success)
+    {
+        delete data;
+    }
 }
 
-/*virtual*/	void LLVOAvatarSelf::setImage(const U8 te, LLViewerTexture *imagep, const U32 index)
+/*virtual*/ void LLVOAvatarSelf::setImage(const U8 te, LLViewerTexture *imagep, const U32 index)
 {
-	if (isIndexLocalTexture((ETextureIndex)te))
-	{
-		setLocalTexture((ETextureIndex)te, imagep, FALSE ,index);
-	}
-	else 
-	{
-		setTEImage(te,imagep);
-	}
+    if (isIndexLocalTexture((ETextureIndex)te))
+    {
+        setLocalTexture((ETextureIndex)te, imagep, FALSE ,index);
+    }
+    else
+    {
+        setTEImage(te,imagep);
+    }
 }
 
 /*virtual*/ LLViewerTexture* LLVOAvatarSelf::getImage(const U8 te, const U32 index) const
 {
-	if (isIndexLocalTexture((ETextureIndex)te))
-	{
-		return getLocalTextureGL((ETextureIndex)te,index);
-	}
-	else 
-	{
-		return getTEImage(te);
-	}
+    if (isIndexLocalTexture((ETextureIndex)te))
+    {
+        return getLocalTextureGL((ETextureIndex)te,index);
+    }
+    else
+    {
+        return getTEImage(te);
+    }
 }
 
 
 // static
 void LLVOAvatarSelf::dumpTotalLocalTextureByteCount()
 {
-	S32 gl_bytes = 0;
-	gAgentAvatarp->getLocalTextureByteCount(&gl_bytes);
-	LL_INFOS() << "Total Avatar LocTex GL:" << (gl_bytes/1024) << "KB" << LL_ENDL;
+    S32 gl_bytes = 0;
+    gAgentAvatarp->getLocalTextureByteCount(&gl_bytes);
+    LL_INFOS() << "Total Avatar LocTex GL:" << (gl_bytes/1024) << "KB" << LL_ENDL;
 }
 
 bool LLVOAvatarSelf::getIsCloud() const
 {
-	// Let people know why they're clouded without spamming them into oblivion.
-	bool do_warn = false;
-	static LLTimer time_since_notice;
-	F32 update_freq = 30.0;
-	if (time_since_notice.getElapsedTimeF32() > update_freq)
-	{
-		time_since_notice.reset();
-		do_warn = true;
-	}
-	
-	// do we have our body parts?
-	S32 shape_count = gAgentWearables.getWearableCount(LLWearableType::WT_SHAPE);
-	S32 hair_count = gAgentWearables.getWearableCount(LLWearableType::WT_HAIR);
-	S32 eye_count = gAgentWearables.getWearableCount(LLWearableType::WT_EYES);
-	S32 skin_count = gAgentWearables.getWearableCount(LLWearableType::WT_SKIN);
-	if (!shape_count || !hair_count || !eye_count || !skin_count)
-	{
-		if (do_warn)
-		{
-			LL_INFOS() << "Self is clouded due to missing one or more required body parts: "
-					<< (shape_count ? "" : "SHAPE ")
-					<< (hair_count ? "" : "HAIR ")
-					<< (eye_count ? "" : "EYES ")
-					<< (skin_count ? "" : "SKIN ")
-					<< LL_ENDL;
-		}
-		return true;
-	}
-
-	if (!isTextureDefined(TEX_HAIR, 0))
-	{
-		if (do_warn)
-		{
-			LL_INFOS() << "Self is clouded because of no hair texture" << LL_ENDL;
-		}
-		return true;
-	}
-
-	if (!mPreviousFullyLoaded)
-	{
-		if (!isLocalTextureDataAvailable(getLayerSet(BAKED_LOWER)) &&
-			(!isTextureDefined(TEX_LOWER_BAKED, 0)))
-		{
-			if (do_warn)
-			{
-				LL_INFOS() << "Self is clouded because lower textures not baked" << LL_ENDL;
-			}
-			return true;
-		}
-
-		if (!isLocalTextureDataAvailable(getLayerSet(BAKED_UPPER)) &&
-			(!isTextureDefined(TEX_UPPER_BAKED, 0)))
-		{
-			if (do_warn)
-			{
-				LL_INFOS() << "Self is clouded because upper textures not baked" << LL_ENDL;
-			}
-			return true;
-		}
-
-		for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-		{
-			if (i == BAKED_SKIRT && !isWearingWearableType(LLWearableType::WT_SKIRT))
-				continue;
-
-			const BakedTextureData& texture_data = mBakedTextureDatas[i];
-			if (!isTextureDefined(texture_data.mTextureIndex, 0))
-				continue;
-
-			// Check for the case that texture is defined but not sufficiently loaded to display anything.
-			const LLViewerTexture* baked_img = getImage( texture_data.mTextureIndex, 0 );
-			if (!baked_img || !baked_img->hasGLTexture())
-			{
-				if (do_warn)
-				{
-					LL_INFOS() << "Self is clouded because texture at index " << i
-							<< " (texture index is " << texture_data.mTextureIndex << ") is not loaded" << LL_ENDL;
-				}
-				return true;
-			}
-		}
+    // Let people know why they're clouded without spamming them into oblivion.
+    bool do_warn = false;
+    static LLTimer time_since_notice;
+    F32 update_freq = 30.0;
+    if (time_since_notice.getElapsedTimeF32() > update_freq)
+    {
+        time_since_notice.reset();
+        do_warn = true;
+    }
+
+    // do we have our body parts?
+    S32 shape_count = gAgentWearables.getWearableCount(LLWearableType::WT_SHAPE);
+    S32 hair_count = gAgentWearables.getWearableCount(LLWearableType::WT_HAIR);
+    S32 eye_count = gAgentWearables.getWearableCount(LLWearableType::WT_EYES);
+    S32 skin_count = gAgentWearables.getWearableCount(LLWearableType::WT_SKIN);
+    if (!shape_count || !hair_count || !eye_count || !skin_count)
+    {
+        if (do_warn)
+        {
+            LL_INFOS() << "Self is clouded due to missing one or more required body parts: "
+                    << (shape_count ? "" : "SHAPE ")
+                    << (hair_count ? "" : "HAIR ")
+                    << (eye_count ? "" : "EYES ")
+                    << (skin_count ? "" : "SKIN ")
+                    << LL_ENDL;
+        }
+        return true;
+    }
+
+    if (!isTextureDefined(TEX_HAIR, 0))
+    {
+        if (do_warn)
+        {
+            LL_INFOS() << "Self is clouded because of no hair texture" << LL_ENDL;
+        }
+        return true;
+    }
+
+    if (!mPreviousFullyLoaded)
+    {
+        if (!isLocalTextureDataAvailable(getLayerSet(BAKED_LOWER)) &&
+            (!isTextureDefined(TEX_LOWER_BAKED, 0)))
+        {
+            if (do_warn)
+            {
+                LL_INFOS() << "Self is clouded because lower textures not baked" << LL_ENDL;
+            }
+            return true;
+        }
+
+        if (!isLocalTextureDataAvailable(getLayerSet(BAKED_UPPER)) &&
+            (!isTextureDefined(TEX_UPPER_BAKED, 0)))
+        {
+            if (do_warn)
+            {
+                LL_INFOS() << "Self is clouded because upper textures not baked" << LL_ENDL;
+            }
+            return true;
+        }
+
+        for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+        {
+            if (i == BAKED_SKIRT && !isWearingWearableType(LLWearableType::WT_SKIRT))
+                continue;
+
+            const BakedTextureData& texture_data = mBakedTextureDatas[i];
+            if (!isTextureDefined(texture_data.mTextureIndex, 0))
+                continue;
+
+            // Check for the case that texture is defined but not sufficiently loaded to display anything.
+            const LLViewerTexture* baked_img = getImage( texture_data.mTextureIndex, 0 );
+            if (!baked_img || !baked_img->hasGLTexture())
+            {
+                if (do_warn)
+                {
+                    LL_INFOS() << "Self is clouded because texture at index " << i
+                            << " (texture index is " << texture_data.mTextureIndex << ") is not loaded" << LL_ENDL;
+                }
+                return true;
+            }
+        }
 #ifdef SHOW_DEBUG
-		LL_DEBUGS() << "Avatar de-clouded" << LL_ENDL;
+        LL_DEBUGS() << "Avatar de-clouded" << LL_ENDL;
 #endif
-	}
-	return false;
+    }
+    return false;
 }
 
 /*static*/
 void LLVOAvatarSelf::debugOnTimingLocalTexLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
 {
-	if (gAgentAvatarp.notNull())
-	{
-		gAgentAvatarp->debugTimingLocalTexLoaded(success, src_vi, src, aux_src, discard_level, final, userdata);
-	}
+    if (gAgentAvatarp.notNull())
+    {
+        gAgentAvatarp->debugTimingLocalTexLoaded(success, src_vi, src, aux_src, discard_level, final, userdata);
+    }
 }
 
 void LLVOAvatarSelf::debugTimingLocalTexLoaded(BOOL success, LLViewerFetchedTexture *src_vi, LLImageRaw* src, LLImageRaw* aux_src, S32 discard_level, BOOL final, void* userdata)
 {
-	LLAvatarTexData *data = (LLAvatarTexData *)userdata;
-	if (!data)
-	{
-		return;
-	}
-
-	ETextureIndex index = data->mIndex;
-	
-	if (index < 0 || index >= TEX_NUM_INDICES)
-	{
-		return;
-	}
-
-	if (discard_level >=0 && discard_level <= MAX_DISCARD_LEVEL) // ignore discard level -1, as it means we have no data.
-	{
-		mDebugTextureLoadTimes[(U32)index][(U32)discard_level] = mDebugSelfLoadTimer.getElapsedTimeF32();
-	}
-	if (final)
-	{
-		delete data;
-	}
+    LLAvatarTexData *data = (LLAvatarTexData *)userdata;
+    if (!data)
+    {
+        return;
+    }
+
+    ETextureIndex index = data->mIndex;
+
+    if (index < 0 || index >= TEX_NUM_INDICES)
+    {
+        return;
+    }
+
+    if (discard_level >=0 && discard_level <= MAX_DISCARD_LEVEL) // ignore discard level -1, as it means we have no data.
+    {
+        mDebugTextureLoadTimes[(U32)index][(U32)discard_level] = mDebugSelfLoadTimer.getElapsedTimeF32();
+    }
+    if (final)
+    {
+        delete data;
+    }
 }
 
 void LLVOAvatarSelf::debugBakedTextureUpload(EBakedTextureIndex index, BOOL finished)
 {
-	U32 done = 0;
-	if (finished)
-	{
-		done = 1;
-	}
-	mDebugBakedTextureTimes[index][done] = mDebugSelfLoadTimer.getElapsedTimeF32();
+    U32 done = 0;
+    if (finished)
+    {
+        done = 1;
+    }
+    mDebugBakedTextureTimes[index][done] = mDebugSelfLoadTimer.getElapsedTimeF32();
 }
 
 const std::string LLVOAvatarSelf::verboseDebugDumpLocalTextureDataInfo(const LLViewerTexLayerSet* layerset) const
 {
-	std::ostringstream outbuf;
+    std::ostringstream outbuf;
     LLWearableType *wr_inst = LLWearableType::getInstance();
-	for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
-	{
-		const EBakedTextureIndex baked_index = baked_pair.first;
-		if (layerset == mBakedTextureDatas[baked_index].mTexLayerSet)
-		{
-			outbuf << "baked_index: " << baked_index << "\n";
-			const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
-			for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
-				 local_tex_iter != baked_dict->mLocalTextures.end();
-				 ++local_tex_iter)
-			{
-				const ETextureIndex tex_index = *local_tex_iter;
-				const std::string tex_name = sAvatarDictionary->getTexture(tex_index)->mName;
-				outbuf << "  tex_index " << (S32) tex_index << " name " << tex_name << "\n";
-				const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
-				const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
-				if (wearable_count > 0)
-				{
-					for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
-					{
-						outbuf << "    " << wr_inst->getTypeName(wearable_type) << " " << wearable_index << ":";
-						const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(tex_index, wearable_index);
-						if (local_tex_obj)
-						{
-							LLViewerFetchedTexture* image = dynamic_cast<LLViewerFetchedTexture*>( local_tex_obj->getImage() );
-							if (tex_index >= 0
-								&& local_tex_obj->getID() != IMG_DEFAULT_AVATAR
-								&& !image->isMissingAsset())
-							{
-								outbuf << " id: " << image->getID()
-									   << " refs: " << image->getNumRefs()
-									   << " glocdisc: " << getLocalDiscardLevel(tex_index, wearable_index)
-									   << " discard: " << image->getDiscardLevel()
-									   << " desired: " << image->getDesiredDiscardLevel()
-									   << " vsize: " << image->getMaxVirtualSize()
-									   << " ts: " << image->getTextureState()
-									   << " bl: " << image->getBoostLevel()
-									   << " fl: " << image->isFullyLoaded() // this is not an accessor for mFullyLoaded - see comment there.
-									   << " cl: " << (image->isFullyLoaded() && image->getDiscardLevel()==0) // "completely loaded"
-									   << " mvs: " << image->getMaxVirtualSize()
-									   << " mvsc: " << image->getMaxVirtualSizeResetCounter()
-									   << " mem: " << image->getTextureMemory();
-							}
-						}
-						outbuf << "\n";
-					}
-				}
-			}
-			break;
-		}
-	}
-	return outbuf.str();
+    for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
+    {
+        const EBakedTextureIndex baked_index = baked_pair.first;
+        if (layerset == mBakedTextureDatas[baked_index].mTexLayerSet)
+        {
+            outbuf << "baked_index: " << baked_index << "\n";
+            const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
+            for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
+                 local_tex_iter != baked_dict->mLocalTextures.end();
+                 ++local_tex_iter)
+            {
+                const ETextureIndex tex_index = *local_tex_iter;
+                const std::string tex_name = sAvatarDictionary->getTexture(tex_index)->mName;
+                outbuf << "  tex_index " << (S32) tex_index << " name " << tex_name << "\n";
+                const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
+                const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
+                if (wearable_count > 0)
+                {
+                    for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
+                    {
+                        outbuf << "    " << wr_inst->getTypeName(wearable_type) << " " << wearable_index << ":";
+                        const LLLocalTextureObject *local_tex_obj = getLocalTextureObject(tex_index, wearable_index);
+                        if (local_tex_obj)
+                        {
+                            LLViewerFetchedTexture* image = dynamic_cast<LLViewerFetchedTexture*>( local_tex_obj->getImage() );
+                            if (tex_index >= 0
+                                && local_tex_obj->getID() != IMG_DEFAULT_AVATAR
+                                && !image->isMissingAsset())
+                            {
+                                outbuf << " id: " << image->getID()
+                                       << " refs: " << image->getNumRefs()
+                                       << " glocdisc: " << getLocalDiscardLevel(tex_index, wearable_index)
+                                       << " discard: " << image->getDiscardLevel()
+                                       << " desired: " << image->getDesiredDiscardLevel()
+                                       << " vsize: " << image->getMaxVirtualSize()
+                                       << " ts: " << image->getTextureState()
+                                       << " bl: " << image->getBoostLevel()
+                                       << " fl: " << image->isFullyLoaded() // this is not an accessor for mFullyLoaded - see comment there.
+                                       << " cl: " << (image->isFullyLoaded() && image->getDiscardLevel()==0) // "completely loaded"
+                                       << " mvs: " << image->getMaxVirtualSize()
+                                       << " mvsc: " << image->getMaxVirtualSizeResetCounter()
+                                       << " mem: " << image->getTextureMemory();
+                            }
+                        }
+                        outbuf << "\n";
+                    }
+                }
+            }
+            break;
+        }
+    }
+    return outbuf.str();
 }
 
 void LLVOAvatarSelf::dumpAllTextures() const
 {
-	std::string vd_text = "Local textures per baked index and wearable:\n";
-	for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
-	{
-		const LLAvatarAppearanceDefines::EBakedTextureIndex baked_index = baked_pair.first;
-		const LLViewerTexLayerSet *layerset = debugGetLayerSet(baked_index);
-		if (!layerset) continue;
-		const LLViewerTexLayerSetBuffer *layerset_buffer = layerset->getViewerComposite();
-		if (!layerset_buffer) continue;
-		vd_text += verboseDebugDumpLocalTextureDataInfo(layerset);
-	}
-	LL_DEBUGS("Avatar") << vd_text << LL_ENDL;
+    std::string vd_text = "Local textures per baked index and wearable:\n";
+    for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
+    {
+        const LLAvatarAppearanceDefines::EBakedTextureIndex baked_index = baked_pair.first;
+        const LLViewerTexLayerSet *layerset = debugGetLayerSet(baked_index);
+        if (!layerset) continue;
+        const LLViewerTexLayerSetBuffer *layerset_buffer = layerset->getViewerComposite();
+        if (!layerset_buffer) continue;
+        vd_text += verboseDebugDumpLocalTextureDataInfo(layerset);
+    }
+    LL_DEBUGS("Avatar") << vd_text << LL_ENDL;
 }
 
 const std::string LLVOAvatarSelf::debugDumpLocalTextureDataInfo(const LLViewerTexLayerSet* layerset) const
 {
-	std::string text="";
+    std::string text="";
     LLWearableType *wr_inst = LLWearableType::getInstance();
 
-	text = llformat("[Final:%d Avail:%d] ",isLocalTextureDataFinal(layerset), isLocalTextureDataAvailable(layerset));
-
-	/* if (layerset == mBakedTextureDatas[BAKED_HEAD].mTexLayerSet)
-	   return getLocalDiscardLevel(TEX_HEAD_BODYPAINT) >= 0; */
-	for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
-	{
-		const EBakedTextureIndex baked_index = baked_pair.first;
-		if (layerset == mBakedTextureDatas[baked_index].mTexLayerSet)
-		{
-			const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
-			text += llformat("%d-%s ( ",baked_index, baked_dict->mName.c_str());
-			for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
-				 local_tex_iter != baked_dict->mLocalTextures.end();
-				 ++local_tex_iter)
-			{
-				const ETextureIndex tex_index = *local_tex_iter;
-				const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
-				const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
-				if (wearable_count > 0)
-				{
-					text += wr_inst->getTypeName(wearable_type) + ":";
-					for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
-					{
-						const U32 discard_level = getLocalDiscardLevel(tex_index, wearable_index);
-						text += llformat("%d ",discard_level);
-					}
-				}
-			}
-			text += ")";
-			break;
-		}
-	}
-	return text;
+    text = llformat("[Final:%d Avail:%d] ",isLocalTextureDataFinal(layerset), isLocalTextureDataAvailable(layerset));
+
+    /* if (layerset == mBakedTextureDatas[BAKED_HEAD].mTexLayerSet)
+       return getLocalDiscardLevel(TEX_HEAD_BODYPAINT) >= 0; */
+    for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
+    {
+        const EBakedTextureIndex baked_index = baked_pair.first;
+        if (layerset == mBakedTextureDatas[baked_index].mTexLayerSet)
+        {
+            const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = baked_pair.second;
+            text += llformat("%d-%s ( ",baked_index, baked_dict->mName.c_str());
+            for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
+                 local_tex_iter != baked_dict->mLocalTextures.end();
+                 ++local_tex_iter)
+            {
+                const ETextureIndex tex_index = *local_tex_iter;
+                const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
+                const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
+                if (wearable_count > 0)
+                {
+                    text += wr_inst->getTypeName(wearable_type) + ":";
+                    for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
+                    {
+                        const U32 discard_level = getLocalDiscardLevel(tex_index, wearable_index);
+                        text += llformat("%d ",discard_level);
+                    }
+                }
+            }
+            text += ")";
+            break;
+        }
+    }
+    return text;
 }
 
 const std::string LLVOAvatarSelf::debugDumpAllLocalTextureDataInfo() const
 {
-	std::string text;
-	static const LLCachedControl<U32> override_tex_discard_level(gSavedSettings, "TextureDiscardLevel");
-
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = sAvatarDictionary->getBakedTexture((EBakedTextureIndex)i);
-		BOOL is_texture_final = TRUE;
-		for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
-			 local_tex_iter != baked_dict->mLocalTextures.end();
-			 ++local_tex_iter)
-		{
-			const ETextureIndex tex_index = *local_tex_iter;
-			const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
-			const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
-			for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
-			{
-				is_texture_final &= (getLocalDiscardLevel(*local_tex_iter, wearable_index) <= (S32)(override_tex_discard_level));
-			}
-		}
-		text += llformat("%s:%d ",baked_dict->mName.c_str(),is_texture_final);
-	}
-	return text;
+    std::string text;
+    static const LLCachedControl<U32> override_tex_discard_level(gSavedSettings, "TextureDiscardLevel");
+
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = sAvatarDictionary->getBakedTexture((EBakedTextureIndex)i);
+        BOOL is_texture_final = TRUE;
+        for (texture_vec_t::const_iterator local_tex_iter = baked_dict->mLocalTextures.begin();
+             local_tex_iter != baked_dict->mLocalTextures.end();
+             ++local_tex_iter)
+        {
+            const ETextureIndex tex_index = *local_tex_iter;
+            const LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(tex_index);
+            const U32 wearable_count = gAgentWearables.getWearableCount(wearable_type);
+            for (U32 wearable_index = 0; wearable_index < wearable_count; wearable_index++)
+            {
+                is_texture_final &= (getLocalDiscardLevel(*local_tex_iter, wearable_index) <= (S32)(override_tex_discard_level));
+            }
+        }
+        text += llformat("%s:%d ",baked_dict->mName.c_str(),is_texture_final);
+    }
+    return text;
 }
 
 void LLVOAvatarSelf::appearanceChangeMetricsCoro(std::string url)
@@ -2294,7 +2294,7 @@ void LLVOAvatarSelf::appearanceChangeMetricsCoro(std::string url)
         msg["nearby"][rez_status_name] = rez_counts[rez_stat];
     }
 
-    //	std::vector<std::string> bucket_fields("timer_name","is_self","grid_x","grid_y","is_using_server_bake");
+    //  std::vector<std::string> bucket_fields("timer_name","is_self","grid_x","grid_y","is_using_server_bake");
     std::vector<std::string> by_fields;
     by_fields.push_back("timer_name");
     by_fields.push_back("completed");
@@ -2335,233 +2335,233 @@ void LLVOAvatarSelf::appearanceChangeMetricsCoro(std::string url)
 
 bool LLVOAvatarSelf::updateAvatarRezMetrics(bool force_send)
 {
-	const F32 AV_METRICS_INTERVAL_QA = 30.0;
-	F32 send_period = 300.0;
+    const F32 AV_METRICS_INTERVAL_QA = 30.0;
+    F32 send_period = 300.0;
 
-	static LLCachedControl<bool> qa_mode_metrics(gSavedSettings,"QAModeMetrics");
-	if (qa_mode_metrics)
-	{
-		send_period = AV_METRICS_INTERVAL_QA;
-	}
+    static LLCachedControl<bool> qa_mode_metrics(gSavedSettings,"QAModeMetrics");
+    if (qa_mode_metrics)
+    {
+        send_period = AV_METRICS_INTERVAL_QA;
+    }
+
+    if (force_send || mTimeSinceLastRezMessage.getElapsedTimeF32() > send_period)
+    {
+        // Stats for completed phases have been getting logged as they
+        // complete.  This will give us stats for any timers that
+        // haven't finished as of the metric's being sent.
 
-	if (force_send || mTimeSinceLastRezMessage.getElapsedTimeF32() > send_period)
-	{
-		// Stats for completed phases have been getting logged as they
-		// complete.  This will give us stats for any timers that
-		// haven't finished as of the metric's being sent.
-		
-		if (force_send)
-		{
-			LLVOAvatar::logPendingPhasesAllAvatars();
-		}
-		sendViewerAppearanceChangeMetrics();
-	}
+        if (force_send)
+        {
+            LLVOAvatar::logPendingPhasesAllAvatars();
+        }
+        sendViewerAppearanceChangeMetrics();
+    }
 
-	return false;
+    return false;
 }
 
 void LLVOAvatarSelf::addMetricsTimerRecord(const LLSD& record)
 {
-	mPendingTimerRecords.push_back(record);
+    mPendingTimerRecords.push_back(record);
 }
 
 bool operator<(const LLSD& a, const LLSD& b)
 {
-	std::ostringstream aout, bout;
-	aout << LLSDNotationStreamer(a);
-	bout << LLSDNotationStreamer(b);
-	std::string astring = aout.str();
-	std::string bstring = bout.str();
+    std::ostringstream aout, bout;
+    aout << LLSDNotationStreamer(a);
+    bout << LLSDNotationStreamer(b);
+    std::string astring = aout.str();
+    std::string bstring = bout.str();
 
-	return astring < bstring;
+    return astring < bstring;
 
 }
 
 // Given a vector of LLSD records, return an LLSD array of bucketed stats for val_field.
 LLSD summarize_by_buckets(std::vector<LLSD> in_records,
-						  std::vector<std::string> by_fields,
-						  std::string val_field)
-{
-	LLSD result = LLSD::emptyArray();
-	std::map<LLSD,LLViewerStats::StatsAccumulator> accum;
-	for (std::vector<LLSD>::iterator in_record_iter = in_records.begin();
-		 in_record_iter != in_records.end(); ++in_record_iter)
-	{
-		LLSD& record = *in_record_iter;
-		LLSD key;
-		for (std::vector<std::string>::iterator field_iter = by_fields.begin();
-			 field_iter != by_fields.end(); ++field_iter)
-		{
-			const std::string& field = *field_iter;
-			key[field] = record[field];
-		}
-		LLViewerStats::StatsAccumulator& stats = accum[key];
-		F32 value = record[val_field].asReal();
-		stats.push(value);
-	}
-	for (std::map<LLSD,LLViewerStats::StatsAccumulator>::iterator accum_it = accum.begin();
-		 accum_it != accum.end(); ++accum_it)
-	{
-		LLSD out_record = accum_it->first;
-		out_record["stats"] = accum_it->second.asLLSD();
-		result.append(out_record);
-	}
-	return result;
+                          std::vector<std::string> by_fields,
+                          std::string val_field)
+{
+    LLSD result = LLSD::emptyArray();
+    std::map<LLSD,LLViewerStats::StatsAccumulator> accum;
+    for (std::vector<LLSD>::iterator in_record_iter = in_records.begin();
+         in_record_iter != in_records.end(); ++in_record_iter)
+    {
+        LLSD& record = *in_record_iter;
+        LLSD key;
+        for (std::vector<std::string>::iterator field_iter = by_fields.begin();
+             field_iter != by_fields.end(); ++field_iter)
+        {
+            const std::string& field = *field_iter;
+            key[field] = record[field];
+        }
+        LLViewerStats::StatsAccumulator& stats = accum[key];
+        F32 value = record[val_field].asReal();
+        stats.push(value);
+    }
+    for (std::map<LLSD,LLViewerStats::StatsAccumulator>::iterator accum_it = accum.begin();
+         accum_it != accum.end(); ++accum_it)
+    {
+        LLSD out_record = accum_it->first;
+        out_record["stats"] = accum_it->second.asLLSD();
+        result.append(out_record);
+    }
+    return result;
 }
 
 void LLVOAvatarSelf::sendViewerAppearanceChangeMetrics()
 {
-    std::string	caps_url;
-	if (getRegion())
-	{
-		// runway - change here to activate.
-		caps_url = getRegion()->getCapability("ViewerMetrics");
-	}
-	if (!caps_url.empty())
-	{
+    std::string caps_url;
+    if (getRegion())
+    {
+        // runway - change here to activate.
+        caps_url = getRegion()->getCapability("ViewerMetrics");
+    }
+    if (!caps_url.empty())
+    {
 
         LLCoros::instance().launch("LLVOAvatarSelf::appearanceChangeMetricsCoro",
             boost::bind(&LLVOAvatarSelf::appearanceChangeMetricsCoro, this, caps_url));
-		mTimeSinceLastRezMessage.reset();
-	}
+        mTimeSinceLastRezMessage.reset();
+    }
 }
 
 const LLUUID& LLVOAvatarSelf::grabBakedTexture(EBakedTextureIndex baked_index) const
 {
-	if (canGrabBakedTexture(baked_index))
-	{
-		ETextureIndex tex_index = sAvatarDictionary->bakedToLocalTextureIndex(baked_index);
-		if (tex_index == TEX_NUM_INDICES)
-		{
-			return LLUUID::null;
-		}
-		return getTEImage( tex_index )->getID();
-	}
-	return LLUUID::null;
+    if (canGrabBakedTexture(baked_index))
+    {
+        ETextureIndex tex_index = sAvatarDictionary->bakedToLocalTextureIndex(baked_index);
+        if (tex_index == TEX_NUM_INDICES)
+        {
+            return LLUUID::null;
+        }
+        return getTEImage( tex_index )->getID();
+    }
+    return LLUUID::null;
 }
 
 BOOL LLVOAvatarSelf::canGrabBakedTexture(EBakedTextureIndex baked_index) const
 {
-	ETextureIndex tex_index = sAvatarDictionary->bakedToLocalTextureIndex(baked_index);
-	if (tex_index == TEX_NUM_INDICES)
-	{
-		return FALSE;
-	}
-	// Check if the texture hasn't been baked yet.
-	if (!isTextureDefined(tex_index, 0))
-	{
-		LL_DEBUGS() << "getTEImage( " << (U32) tex_index << " )->getID() == IMG_DEFAULT_AVATAR" << LL_ENDL;
-		return FALSE;
-	}
-
-	if (gAgent.isGodlikeWithoutAdminMenuFakery())
-		return TRUE;
-
-	// Check permissions of textures that show up in the
-	// baked texture.  We don't want people copying people's
-	// work via baked textures.
-
-	const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = sAvatarDictionary->getBakedTexture(baked_index);
-	for (texture_vec_t::const_iterator iter = baked_dict->mLocalTextures.begin();
-		 iter != baked_dict->mLocalTextures.end();
-		 ++iter)
-	{
-		const ETextureIndex t_index = (*iter);
-		LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(t_index);
-		U32 count = gAgentWearables.getWearableCount(wearable_type);
-		LL_DEBUGS() << "Checking index " << (U32) t_index << " count: " << count << LL_ENDL;
-		
-		for (U32 wearable_index = 0; wearable_index < count; ++wearable_index)
-		{
-			LLViewerWearable *wearable = gAgentWearables.getViewerWearable(wearable_type, wearable_index);
-			if (wearable)
-			{
-				const LLLocalTextureObject *texture = wearable->getLocalTextureObject((S32)t_index);
-				const LLUUID& texture_id = texture->getID();
-				if (texture_id != IMG_DEFAULT_AVATAR)
-				{
-					// Search inventory for this texture.
-					LLViewerInventoryCategory::cat_array_t cats;
-					LLViewerInventoryItem::item_array_t items;
-					LLAssetIDMatches asset_id_matches(texture_id);
-					gInventory.collectDescendentsIf(LLUUID::null,
-													cats,
-													items,
-													LLInventoryModel::INCLUDE_TRASH,
-													asset_id_matches);
-
-					BOOL can_grab = FALSE;
-					LL_DEBUGS() << "item count for asset " << texture_id << ": " << items.size() << LL_ENDL;
-					if (items.size())
-					{
-						// search for full permissions version
-						for (S32 i = 0; i < items.size(); i++)
-						{
-							LLViewerInventoryItem* itemp = items[i];
-												if (itemp->getIsFullPerm())
-							{
-								can_grab = TRUE;
-								break;
-							}
-						}
-					}
-					if (!can_grab) return FALSE;
-				}
-			}
-		}
-	}
-
-	return TRUE;
+    ETextureIndex tex_index = sAvatarDictionary->bakedToLocalTextureIndex(baked_index);
+    if (tex_index == TEX_NUM_INDICES)
+    {
+        return FALSE;
+    }
+    // Check if the texture hasn't been baked yet.
+    if (!isTextureDefined(tex_index, 0))
+    {
+        LL_DEBUGS() << "getTEImage( " << (U32) tex_index << " )->getID() == IMG_DEFAULT_AVATAR" << LL_ENDL;
+        return FALSE;
+    }
+
+    if (gAgent.isGodlikeWithoutAdminMenuFakery())
+        return TRUE;
+
+    // Check permissions of textures that show up in the
+    // baked texture.  We don't want people copying people's
+    // work via baked textures.
+
+    const LLAvatarAppearanceDictionary::BakedEntry *baked_dict = sAvatarDictionary->getBakedTexture(baked_index);
+    for (texture_vec_t::const_iterator iter = baked_dict->mLocalTextures.begin();
+         iter != baked_dict->mLocalTextures.end();
+         ++iter)
+    {
+        const ETextureIndex t_index = (*iter);
+        LLWearableType::EType wearable_type = sAvatarDictionary->getTEWearableType(t_index);
+        U32 count = gAgentWearables.getWearableCount(wearable_type);
+        LL_DEBUGS() << "Checking index " << (U32) t_index << " count: " << count << LL_ENDL;
+
+        for (U32 wearable_index = 0; wearable_index < count; ++wearable_index)
+        {
+            LLViewerWearable *wearable = gAgentWearables.getViewerWearable(wearable_type, wearable_index);
+            if (wearable)
+            {
+                const LLLocalTextureObject *texture = wearable->getLocalTextureObject((S32)t_index);
+                const LLUUID& texture_id = texture->getID();
+                if (texture_id != IMG_DEFAULT_AVATAR)
+                {
+                    // Search inventory for this texture.
+                    LLViewerInventoryCategory::cat_array_t cats;
+                    LLViewerInventoryItem::item_array_t items;
+                    LLAssetIDMatches asset_id_matches(texture_id);
+                    gInventory.collectDescendentsIf(LLUUID::null,
+                                                    cats,
+                                                    items,
+                                                    LLInventoryModel::INCLUDE_TRASH,
+                                                    asset_id_matches);
+
+                    BOOL can_grab = FALSE;
+                    LL_DEBUGS() << "item count for asset " << texture_id << ": " << items.size() << LL_ENDL;
+                    if (items.size())
+                    {
+                        // search for full permissions version
+                        for (S32 i = 0; i < items.size(); i++)
+                        {
+                            LLViewerInventoryItem* itemp = items[i];
+                                                if (itemp->getIsFullPerm())
+                            {
+                                can_grab = TRUE;
+                                break;
+                            }
+                        }
+                    }
+                    if (!can_grab) return FALSE;
+                }
+            }
+        }
+    }
+
+    return TRUE;
 }
 
 void LLVOAvatarSelf::addLocalTextureStats( ETextureIndex type, LLViewerFetchedTexture* imagep,
-										   F32 texel_area_ratio, BOOL render_avatar, BOOL covered_by_baked)
-{
-	if (!isIndexLocalTexture(type)) return;
-
-	// Sunshine - ignoring covered_by_baked will force local textures
-	// to always load.  Fix for SH-4001 and many related issues.  Do
-	// not restore this without some more targetted fix for the local
-	// textures failing to load issue.
-	//if (!covered_by_baked)
-	{
-		if (imagep->getID() != IMG_DEFAULT_AVATAR)
-		{
-			imagep->setNoDelete();
-			if (imagep->getDiscardLevel() != 0)
-			{
-				F32 desired_pixels;
-				desired_pixels = llmin(mPixelArea, (F32)getTexImageArea());
-				
-				imagep->setBoostLevel(getAvatarBoostLevel());
-				imagep->resetTextureStats();
-				imagep->setMaxVirtualSizeResetInterval(MAX_TEXTURE_VIRTUAL_SIZE_RESET_INTERVAL);
-				imagep->addTextureStats( desired_pixels / texel_area_ratio );
-				imagep->forceUpdateBindStats() ;
-				if (imagep->getDiscardLevel() < 0)
-				{
-					mHasGrey = TRUE; // for statistics gathering
-				}
-			}
-		}
-		else
-		{
-			// texture asset is missing
-			mHasGrey = TRUE; // for statistics gathering
-		}
-	}
+                                           F32 texel_area_ratio, BOOL render_avatar, BOOL covered_by_baked)
+{
+    if (!isIndexLocalTexture(type)) return;
+
+    // Sunshine - ignoring covered_by_baked will force local textures
+    // to always load.  Fix for SH-4001 and many related issues.  Do
+    // not restore this without some more targetted fix for the local
+    // textures failing to load issue.
+    //if (!covered_by_baked)
+    {
+        if (imagep->getID() != IMG_DEFAULT_AVATAR)
+        {
+            imagep->setNoDelete();
+            if (imagep->getDiscardLevel() != 0)
+            {
+                F32 desired_pixels;
+                desired_pixels = llmin(mPixelArea, (F32)getTexImageArea());
+
+                imagep->setBoostLevel(getAvatarBoostLevel());
+                imagep->resetTextureStats();
+                imagep->setMaxVirtualSizeResetInterval(MAX_TEXTURE_VIRTUAL_SIZE_RESET_INTERVAL);
+                imagep->addTextureStats( desired_pixels / texel_area_ratio );
+                imagep->forceUpdateBindStats() ;
+                if (imagep->getDiscardLevel() < 0)
+                {
+                    mHasGrey = TRUE; // for statistics gathering
+                }
+            }
+        }
+        else
+        {
+            // texture asset is missing
+            mHasGrey = TRUE; // for statistics gathering
+        }
+    }
 }
 
 LLLocalTextureObject* LLVOAvatarSelf::getLocalTextureObject(LLAvatarAppearanceDefines::ETextureIndex i, U32 wearable_index) const
 {
-	LLWearableType::EType type = sAvatarDictionary->getTEWearableType(i);
-	LLViewerWearable* wearable = gAgentWearables.getViewerWearable(type, wearable_index);
-	if (wearable)
-	{
-		return wearable->getLocalTextureObject(i);
-	}
+    LLWearableType::EType type = sAvatarDictionary->getTEWearableType(i);
+    LLViewerWearable* wearable = gAgentWearables.getViewerWearable(type, wearable_index);
+    if (wearable)
+    {
+        return wearable->getLocalTextureObject(i);
+    }
 
-	return NULL;
+    return NULL;
 }
 
 //-----------------------------------------------------------------------------
@@ -2570,119 +2570,119 @@ LLLocalTextureObject* LLVOAvatarSelf::getLocalTextureObject(LLAvatarAppearanceDe
 //-----------------------------------------------------------------------------
 ETextureIndex LLVOAvatarSelf::getBakedTE( const LLViewerTexLayerSet* layerset ) const
 {
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		if (layerset == mBakedTextureDatas[i].mTexLayerSet )
-		{
-			return mBakedTextureDatas[i].mTextureIndex;
-		}
-	}
-	llassert(0);
-	return TEX_HEAD_BAKED;
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        if (layerset == mBakedTextureDatas[i].mTexLayerSet )
+        {
+            return mBakedTextureDatas[i].mTextureIndex;
+        }
+    }
+    llassert(0);
+    return TEX_HEAD_BAKED;
 }
 
 // FIXME: This is not called consistently. Something may be broken.
 void LLVOAvatarSelf::outputRezDiagnostics() const
 {
-	if(!gSavedSettings.getBOOL("DebugAvatarLocalTexLoadedTime"))
-	{
-		return ;
-	}
-
-	const F32 final_time = mDebugSelfLoadTimer.getElapsedTimeF32();
-	LL_DEBUGS("Avatar") << "REZTIME: Myself rez stats:" << LL_ENDL;
-	LL_DEBUGS("Avatar") << "\t Time from avatar creation to load wearables: " << (S32)mDebugTimeWearablesLoaded << LL_ENDL;
-	LL_DEBUGS("Avatar") << "\t Time from avatar creation to de-cloud: " << (S32)mDebugTimeAvatarVisible << LL_ENDL;
-	LL_DEBUGS("Avatar") << "\t Time from avatar creation to de-cloud for others: " << (S32)final_time << LL_ENDL;
-	LL_DEBUGS("Avatar") << "\t Load time for each texture: " << LL_ENDL;
-	for (U32 i = 0; i < LLAvatarAppearanceDefines::TEX_NUM_INDICES; ++i)
-	{
-		std::stringstream out;
-		out << "\t\t (" << i << ") ";
-		U32 j=0;
-		for (j=0; j <= MAX_DISCARD_LEVEL; j++)
-		{
-			out << "\t";
-			S32 load_time = (S32)mDebugTextureLoadTimes[i][j];
-			if (load_time == -1)
-			{
-				out << "*";
-				if (j == 0)
-					break;
-			}
-			else
-			{
-				out << load_time;
-			}
-		}
-
-		// Don't print out non-existent textures.
-		if (j != 0)
-		{
-			LL_DEBUGS("Avatar") << out.str() << LL_ENDL;
-		}
-	}
-	LL_DEBUGS("Avatar") << "\t Time points for each upload (start / finish)" << LL_ENDL;
-	for (U32 i = 0; i < LLAvatarAppearanceDefines::BAKED_NUM_INDICES; ++i)
-	{
-		LL_DEBUGS("Avatar") << "\t\t (" << i << ") \t" << (S32)mDebugBakedTextureTimes[i][0] << " / " << (S32)mDebugBakedTextureTimes[i][1] << LL_ENDL;
-	}
-
-	for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
-	{
-		const LLAvatarAppearanceDefines::EBakedTextureIndex baked_index = baked_pair.first;
-		const LLViewerTexLayerSet *layerset = debugGetLayerSet(baked_index);
-		if (!layerset) continue;
-		const LLViewerTexLayerSetBuffer *layerset_buffer = layerset->getViewerComposite();
-		if (!layerset_buffer) continue;
-		LL_DEBUGS("Avatar") << layerset_buffer->dumpTextureInfo() << LL_ENDL;
-	}
-
-	dumpAllTextures();
+    if(!gSavedSettings.getBOOL("DebugAvatarLocalTexLoadedTime"))
+    {
+        return ;
+    }
+
+    const F32 final_time = mDebugSelfLoadTimer.getElapsedTimeF32();
+    LL_DEBUGS("Avatar") << "REZTIME: Myself rez stats:" << LL_ENDL;
+    LL_DEBUGS("Avatar") << "\t Time from avatar creation to load wearables: " << (S32)mDebugTimeWearablesLoaded << LL_ENDL;
+    LL_DEBUGS("Avatar") << "\t Time from avatar creation to de-cloud: " << (S32)mDebugTimeAvatarVisible << LL_ENDL;
+    LL_DEBUGS("Avatar") << "\t Time from avatar creation to de-cloud for others: " << (S32)final_time << LL_ENDL;
+    LL_DEBUGS("Avatar") << "\t Load time for each texture: " << LL_ENDL;
+    for (U32 i = 0; i < LLAvatarAppearanceDefines::TEX_NUM_INDICES; ++i)
+    {
+        std::stringstream out;
+        out << "\t\t (" << i << ") ";
+        U32 j=0;
+        for (j=0; j <= MAX_DISCARD_LEVEL; j++)
+        {
+            out << "\t";
+            S32 load_time = (S32)mDebugTextureLoadTimes[i][j];
+            if (load_time == -1)
+            {
+                out << "*";
+                if (j == 0)
+                    break;
+            }
+            else
+            {
+                out << load_time;
+            }
+        }
+
+        // Don't print out non-existent textures.
+        if (j != 0)
+        {
+            LL_DEBUGS("Avatar") << out.str() << LL_ENDL;
+        }
+    }
+    LL_DEBUGS("Avatar") << "\t Time points for each upload (start / finish)" << LL_ENDL;
+    for (U32 i = 0; i < LLAvatarAppearanceDefines::BAKED_NUM_INDICES; ++i)
+    {
+        LL_DEBUGS("Avatar") << "\t\t (" << i << ") \t" << (S32)mDebugBakedTextureTimes[i][0] << " / " << (S32)mDebugBakedTextureTimes[i][1] << LL_ENDL;
+    }
+
+    for (const auto& baked_pair : sAvatarDictionary->getBakedTextures())
+    {
+        const LLAvatarAppearanceDefines::EBakedTextureIndex baked_index = baked_pair.first;
+        const LLViewerTexLayerSet *layerset = debugGetLayerSet(baked_index);
+        if (!layerset) continue;
+        const LLViewerTexLayerSetBuffer *layerset_buffer = layerset->getViewerComposite();
+        if (!layerset_buffer) continue;
+        LL_DEBUGS("Avatar") << layerset_buffer->dumpTextureInfo() << LL_ENDL;
+    }
+
+    dumpAllTextures();
 }
 
 void LLVOAvatarSelf::outputRezTiming(const std::string& msg) const
 {
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("Avatar")
-		<< avString()
-		<< llformat("%s. Time from avatar creation: %.2f", msg.c_str(), mDebugSelfLoadTimer.getElapsedTimeF32())
-		<< LL_ENDL;
+    LL_DEBUGS("Avatar")
+        << avString()
+        << llformat("%s. Time from avatar creation: %.2f", msg.c_str(), mDebugSelfLoadTimer.getElapsedTimeF32())
+        << LL_ENDL;
 #endif
 }
 
 void LLVOAvatarSelf::reportAvatarRezTime() const
 {
-	// TODO: report mDebugSelfLoadTimer.getElapsedTimeF32() somehow.
+    // TODO: report mDebugSelfLoadTimer.getElapsedTimeF32() somehow.
 }
 
 // SUNSHINE CLEANUP - not clear we need any of this, may be sufficient to request server appearance in llviewermenu.cpp:handle_rebake_textures()
 void LLVOAvatarSelf::forceBakeAllTextures(bool slam_for_debug)
 {
-	LL_INFOS() << "TAT: forced full rebake. " << LL_ENDL;
+    LL_INFOS() << "TAT: forced full rebake. " << LL_ENDL;
 
-	for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
-	{
-		ETextureIndex baked_index = mBakedTextureDatas[i].mTextureIndex;
-		LLViewerTexLayerSet* layer_set = getLayerSet(baked_index);
-		if (layer_set)
-		{
-			if (slam_for_debug)
-			{
-				layer_set->setUpdatesEnabled(TRUE);
-			}
+    for (U32 i = 0; i < mBakedTextureDatas.size(); i++)
+    {
+        ETextureIndex baked_index = mBakedTextureDatas[i].mTextureIndex;
+        LLViewerTexLayerSet* layer_set = getLayerSet(baked_index);
+        if (layer_set)
+        {
+            if (slam_for_debug)
+            {
+                layer_set->setUpdatesEnabled(TRUE);
+            }
 
-			invalidateComposite(layer_set);
-			add(LLStatViewer::TEX_REBAKES, 1);
-		}
-		else
-		{
-			LL_WARNS() << "TAT: NO LAYER SET FOR " << (S32)baked_index << LL_ENDL;
-		}
-	}
+            invalidateComposite(layer_set);
+            add(LLStatViewer::TEX_REBAKES, 1);
+        }
+        else
+        {
+            LL_WARNS() << "TAT: NO LAYER SET FOR " << (S32)baked_index << LL_ENDL;
+        }
+    }
 
-	// Don't know if this is needed
-	updateMeshTextures();
+    // Don't know if this is needed
+    updateMeshTextures();
 }
 
 //-----------------------------------------------------------------------------
@@ -2690,21 +2690,21 @@ void LLVOAvatarSelf::forceBakeAllTextures(bool slam_for_debug)
 //-----------------------------------------------------------------------------
 void LLVOAvatarSelf::requestLayerSetUpdate(ETextureIndex index )
 {
-	/* switch(index)
-		case LOCTEX_UPPER_BODYPAINT:  
-		case LOCTEX_UPPER_SHIRT:
-			if( mUpperBodyLayerSet )
-				mUpperBodyLayerSet->requestUpdate(); */
-	const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = sAvatarDictionary->getTexture(index);
-	if (!texture_dict)
-		return;
-	if (!texture_dict->mIsLocalTexture || !texture_dict->mIsUsedByBakedTexture)
-		return;
-	const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex;
-	if (mBakedTextureDatas[baked_index].mTexLayerSet)
-	{
-		mBakedTextureDatas[baked_index].mTexLayerSet->requestUpdate();
-	}
+    /* switch(index)
+        case LOCTEX_UPPER_BODYPAINT:
+        case LOCTEX_UPPER_SHIRT:
+            if( mUpperBodyLayerSet )
+                mUpperBodyLayerSet->requestUpdate(); */
+    const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = sAvatarDictionary->getTexture(index);
+    if (!texture_dict)
+        return;
+    if (!texture_dict->mIsLocalTexture || !texture_dict->mIsUsedByBakedTexture)
+        return;
+    const EBakedTextureIndex baked_index = texture_dict->mBakedTextureIndex;
+    if (mBakedTextureDatas[baked_index].mTexLayerSet)
+    {
+        mBakedTextureDatas[baked_index].mTexLayerSet->requestUpdate();
+    }
 }
 
 LLViewerTexLayerSet* LLVOAvatarSelf::getLayerSet(ETextureIndex index) const
@@ -2730,7 +2730,7 @@ LLViewerTexLayerSet* LLVOAvatarSelf::getLayerSet(EBakedTextureIndex baked_index)
                        return mHeadLayerSet; */
        if (baked_index >= 0 && baked_index < BAKED_NUM_INDICES)
        {
-		   return  getTexLayerSet(baked_index);
+           return  getTexLayerSet(baked_index);
        }
        return NULL;
 }
@@ -2741,53 +2741,53 @@ LLViewerTexLayerSet* LLVOAvatarSelf::getLayerSet(EBakedTextureIndex baked_index)
 // static
 void LLVOAvatarSelf::onCustomizeStart(bool disable_camera_switch)
 {
-	if (isAgentAvatarValid())
-	{
-		if (!gAgentAvatarp->mEndCustomizeCallback.get())
-		{
-			gAgentAvatarp->mEndCustomizeCallback = new LLUpdateAppearanceOnDestroy;
-		}
-		
-		gAgentAvatarp->mIsEditingAppearance = true;
-		gAgentAvatarp->mUseLocalAppearance = true;
-
-		if (gSavedSettings.getBOOL("AppearanceCameraMovement") && !disable_camera_switch)
-		{
-			gAgentCamera.changeCameraToCustomizeAvatar();
-		}
-		
-		gAgentAvatarp->invalidateAll(); // mark all bakes as dirty, request updates
-		gAgentAvatarp->updateMeshTextures(); // make sure correct textures are applied to the avatar mesh.
-		gAgentAvatarp->updateTextures(); // call updateTextureStats
-	}
+    if (isAgentAvatarValid())
+    {
+        if (!gAgentAvatarp->mEndCustomizeCallback.get())
+        {
+            gAgentAvatarp->mEndCustomizeCallback = new LLUpdateAppearanceOnDestroy;
+        }
+
+        gAgentAvatarp->mIsEditingAppearance = true;
+        gAgentAvatarp->mUseLocalAppearance = true;
+
+        if (gSavedSettings.getBOOL("AppearanceCameraMovement") && !disable_camera_switch)
+        {
+            gAgentCamera.changeCameraToCustomizeAvatar();
+        }
+
+        gAgentAvatarp->invalidateAll(); // mark all bakes as dirty, request updates
+        gAgentAvatarp->updateMeshTextures(); // make sure correct textures are applied to the avatar mesh.
+        gAgentAvatarp->updateTextures(); // call updateTextureStats
+    }
 }
 
 // static
 void LLVOAvatarSelf::onCustomizeEnd(bool disable_camera_switch)
 {
 
-	if (isAgentAvatarValid())
-	{
-		gAgentAvatarp->mIsEditingAppearance = false;
-		gAgentAvatarp->invalidateAll();
+    if (isAgentAvatarValid())
+    {
+        gAgentAvatarp->mIsEditingAppearance = false;
+        gAgentAvatarp->invalidateAll();
 
-		if (gSavedSettings.getBOOL("AppearanceCameraMovement") && !disable_camera_switch)
-		{
-			gAgentCamera.changeCameraToDefault();
-			gAgentCamera.resetView();
-		}
+        if (gSavedSettings.getBOOL("AppearanceCameraMovement") && !disable_camera_switch)
+        {
+            gAgentCamera.changeCameraToDefault();
+            gAgentCamera.resetView();
+        }
 
-		// Dereferencing the previous callback will cause
-		// updateAppearanceFromCOF to be called, whenever all refs
-		// have resolved.
-		gAgentAvatarp->mEndCustomizeCallback = NULL;
-	}
+        // Dereferencing the previous callback will cause
+        // updateAppearanceFromCOF to be called, whenever all refs
+        // have resolved.
+        gAgentAvatarp->mEndCustomizeCallback = NULL;
+    }
 }
 
 // virtual
 bool LLVOAvatarSelf::shouldRenderRigged() const
 {
-    return gAgent.needsRenderAvatar(); 
+    return gAgent.needsRenderAvatar();
 }
 
 // HACK: this will null out the avatar's local texture IDs before the TE message is sent
@@ -2797,35 +2797,35 @@ bool LLVOAvatarSelf::shouldRenderRigged() const
 //       This will involve further refactoring that is too risky for the initial release of 2.0.
 bool LLVOAvatarSelf::sendAppearanceMessage(LLMessageSystem *mesgsys) const
 {
-	LLUUID texture_id[TEX_NUM_INDICES];
-	// pack away current TEs to make sure we don't send them out
-	for (const auto& tex_pair : sAvatarDictionary->getTextures())
-	{
-		const ETextureIndex index = tex_pair.first;
-		const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
-		if (!texture_dict->mIsBakedTexture)
-		{
-			LLTextureEntry* entry = getTE((U8) index);
-			texture_id[index] = entry->getID();
-			entry->setID(IMG_DEFAULT_AVATAR);
-		}
-	}
-
-	bool success = packTEMessage(mesgsys);
-
-	// unpack TEs to make sure we don't re-trigger a bake
-	for (const auto& tex_pair : sAvatarDictionary->getTextures())
-	{
-		const ETextureIndex index = tex_pair.first;
-		const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
-		if (!texture_dict->mIsBakedTexture)
-		{
-			LLTextureEntry* entry = getTE((U8) index);
-			entry->setID(texture_id[index]);
-		}
-	}
-
-	return success;
+    LLUUID texture_id[TEX_NUM_INDICES];
+    // pack away current TEs to make sure we don't send them out
+    for (const auto& tex_pair : sAvatarDictionary->getTextures())
+    {
+        const ETextureIndex index = tex_pair.first;
+        const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
+        if (!texture_dict->mIsBakedTexture)
+        {
+            LLTextureEntry* entry = getTE((U8) index);
+            texture_id[index] = entry->getID();
+            entry->setID(IMG_DEFAULT_AVATAR);
+        }
+    }
+
+    bool success = packTEMessage(mesgsys);
+
+    // unpack TEs to make sure we don't re-trigger a bake
+    for (const auto& tex_pair : sAvatarDictionary->getTextures())
+    {
+        const ETextureIndex index = tex_pair.first;
+        const LLAvatarAppearanceDictionary::TextureEntry *texture_dict = tex_pair.second;
+        if (!texture_dict->mIsBakedTexture)
+        {
+            LLTextureEntry* entry = getTE((U8) index);
+            entry->setID(texture_id[index]);
+        }
+    }
+
+    return success;
 }
 
 //------------------------------------------------------------------------
@@ -2833,39 +2833,39 @@ bool LLVOAvatarSelf::sendAppearanceMessage(LLMessageSystem *mesgsys) const
 //------------------------------------------------------------------------
 void LLVOAvatarSelf::sendHoverHeight() const
 {
-	std::string url = gAgent.getRegionCapability("AgentPreferences");
+    std::string url = gAgent.getRegionCapability("AgentPreferences");
 
-	if (!url.empty())
-	{
-		LLSD update = LLSD::emptyMap();
-		const LLVector3& hover_offset = getHoverOffset();
-		update["hover_height"] = hover_offset[2];
+    if (!url.empty())
+    {
+        LLSD update = LLSD::emptyMap();
+        const LLVector3& hover_offset = getHoverOffset();
+        update["hover_height"] = hover_offset[2];
 
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("Avatar") << avString() << "sending hover height value " << hover_offset[2] << LL_ENDL;
+        LL_DEBUGS("Avatar") << avString() << "sending hover height value " << hover_offset[2] << LL_ENDL;
 #endif
 
         // *TODO: - this class doesn't really do anything, could just use a base
-        // class responder if nothing else gets added. 
+        // class responder if nothing else gets added.
         // (comment from removed Responder)
-        LLCoreHttpUtil::HttpCoroutineAdapter::messageHttpPost(url, update, 
+        LLCoreHttpUtil::HttpCoroutineAdapter::messageHttpPost(url, update,
             "Hover height sent to sim", "Hover height not sent to sim");
-		mLastHoverOffsetSent = hover_offset;
-	}
+        mLastHoverOffsetSent = hover_offset;
+    }
 }
 
 void LLVOAvatarSelf::setHoverOffset(const LLVector3& hover_offset, bool send_update)
 {
-	if (getHoverOffset() != hover_offset)
-	{
-		LL_INFOS("Avatar") << avString() << " setting hover due to change " << hover_offset[2] << LL_ENDL;
-		LLVOAvatar::setHoverOffset(hover_offset, send_update);
-	}
-	if (send_update && (hover_offset != mLastHoverOffsetSent))
-	{
-		LL_INFOS("Avatar") << avString() << " sending hover due to change " << hover_offset[2] << LL_ENDL;
-		sendHoverHeight();
-	}
+    if (getHoverOffset() != hover_offset)
+    {
+        LL_INFOS("Avatar") << avString() << " setting hover due to change " << hover_offset[2] << LL_ENDL;
+        LLVOAvatar::setHoverOffset(hover_offset, send_update);
+    }
+    if (send_update && (hover_offset != mLastHoverOffsetSent))
+    {
+        LL_INFOS("Avatar") << avString() << " sending hover due to change " << hover_offset[2] << LL_ENDL;
+        sendHoverHeight();
+    }
 }
 
 //------------------------------------------------------------------------
@@ -2873,9 +2873,9 @@ void LLVOAvatarSelf::setHoverOffset(const LLVector3& hover_offset, bool send_upd
 //------------------------------------------------------------------------
 BOOL LLVOAvatarSelf::needsRenderBeam()
 {
-	LLTool *tool = LLToolMgr::getInstance()->getCurrentTool();
+    LLTool *tool = LLToolMgr::getInstance()->getCurrentTool();
 
-	BOOL is_touching_or_grabbing = (tool == LLToolGrab::getInstance() && LLToolGrab::getInstance()->isEditing());
+    BOOL is_touching_or_grabbing = (tool == LLToolGrab::getInstance() && LLToolGrab::getInstance()->isEditing());
     LLViewerObject* objp = LLToolGrab::getInstance()->getEditingObject();
     if (objp // might need to be "!objp ||" instead of "objp &&".
         && (objp->isAttachment() || objp->isAvatar()))
@@ -2884,65 +2884,65 @@ BOOL LLVOAvatarSelf::needsRenderBeam()
         // attachments or avatars
         is_touching_or_grabbing = FALSE;
     }
-	return is_touching_or_grabbing || (getAttachmentState() & AGENT_STATE_EDITING && LLSelectMgr::getInstance()->shouldShowSelection());
+    return is_touching_or_grabbing || (getAttachmentState() & AGENT_STATE_EDITING && LLSelectMgr::getInstance()->shouldShowSelection());
 }
 
 // static
 void LLVOAvatarSelf::deleteScratchTextures()
 {
-	for(std::map< LLGLenum, LLGLuint*>::iterator it = sScratchTexNames.begin(), end_it = sScratchTexNames.end();
-		it != end_it;
-		++it)
-	{
-		LLImageGL::deleteTextures(1, (U32 *)it->second );
-		stop_glerror();
-	}
+    for(std::map< LLGLenum, LLGLuint*>::iterator it = sScratchTexNames.begin(), end_it = sScratchTexNames.end();
+        it != end_it;
+        ++it)
+    {
+        LLImageGL::deleteTextures(1, (U32 *)it->second );
+        stop_glerror();
+    }
 
-	if( sScratchTexBytes.value() )
-	{
+    if( sScratchTexBytes.value() )
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS() << "Clearing Scratch Textures " << (S32Kilobytes)sScratchTexBytes << LL_ENDL;
+        LL_DEBUGS() << "Clearing Scratch Textures " << (S32Kilobytes)sScratchTexBytes << LL_ENDL;
 #endif
 
-		delete_and_clear(sScratchTexNames);
-		sScratchTexBytes = S32Bytes(0);
-	}
+        delete_and_clear(sScratchTexNames);
+        sScratchTexBytes = S32Bytes(0);
+    }
 }
 
-// static 
+// static
 void LLVOAvatarSelf::dumpScratchTextureByteCount()
 {
-	LL_INFOS() << "Scratch Texture GL: " << (sScratchTexBytes/1024) << "KB" << LL_ENDL;
+    LL_INFOS() << "Scratch Texture GL: " << (sScratchTexBytes/1024) << "KB" << LL_ENDL;
 }
 
 void LLVOAvatarSelf::dumpWearableInfo(LLAPRFile& outfile)
 {
-	apr_file_t* file = outfile.getFileHandle();
-	if (!file)
-	{
-		return;
-	}
+    apr_file_t* file = outfile.getFileHandle();
+    if (!file)
+    {
+        return;
+    }
+
 
-	
-	apr_file_printf( file, "\n<wearable_info>\n" );
+    apr_file_printf( file, "\n<wearable_info>\n" );
 
-	LLWearableData *wd = getWearableData();
+    LLWearableData *wd = getWearableData();
     LLWearableType *wr_inst = LLWearableType::getInstance();
-	for (S32 type = 0; type < LLWearableType::WT_COUNT; type++)
-	{
-		const std::string& type_name = wr_inst->getTypeName((LLWearableType::EType)type);
-		for (U32 j=0; j< wd->getWearableCount((LLWearableType::EType)type); j++)
-		{
-			LLViewerWearable *wearable = gAgentWearables.getViewerWearable((LLWearableType::EType)type,j);
-			apr_file_printf( file, "\n\t    <wearable type=\"%s\" name=\"%s\"/>\n",
-							 type_name.c_str(), wearable->getName().c_str() );
-			LLWearable::visual_param_vec_t v_params;
-			wearable->getVisualParams(v_params);
-			for (LLVisualParam *param : v_params)
-			{
-				dump_visual_param(file, param, param->getWeight());
-			}
-		}
-	}
-	apr_file_printf( file, "\n</wearable_info>\n" );
+    for (S32 type = 0; type < LLWearableType::WT_COUNT; type++)
+    {
+        const std::string& type_name = wr_inst->getTypeName((LLWearableType::EType)type);
+        for (U32 j=0; j< wd->getWearableCount((LLWearableType::EType)type); j++)
+        {
+            LLViewerWearable *wearable = gAgentWearables.getViewerWearable((LLWearableType::EType)type,j);
+            apr_file_printf( file, "\n\t    <wearable type=\"%s\" name=\"%s\"/>\n",
+                             type_name.c_str(), wearable->getName().c_str() );
+            LLWearable::visual_param_vec_t v_params;
+            wearable->getVisualParams(v_params);
+            for (LLVisualParam *param : v_params)
+            {
+                dump_visual_param(file, param, param->getWeight());
+            }
+        }
+    }
+    apr_file_printf( file, "\n</wearable_info>\n" );
 }
diff --git a/indra/newview/llvosurfacepatch.cpp b/indra/newview/llvosurfacepatch.cpp
index f085273f921512c34b06325e8ee119351cadb4cc..02455811d864a96589ca455cc0002e193e8ef072 100644
--- a/indra/newview/llvosurfacepatch.cpp
+++ b/indra/newview/llvosurfacepatch.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvosurfacepatch.cpp
  * @brief Viewer-object derived "surface patch", which is a piece of terrain
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -47,51 +47,51 @@
 F32 LLVOSurfacePatch::sLODFactor = 1.f;
 
 LLVOSurfacePatch::LLVOSurfacePatch(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
-	:	LLStaticViewerObject(id, pcode, regionp),
-		mDirtiedPatch(FALSE),
-		mPool(NULL),
-		mBaseComp(0),
-		mPatchp(NULL),
-		mDirtyTexture(FALSE),
-		mDirtyTerrain(FALSE),
-		mLastNorthStride(0),
-		mLastEastStride(0),
-		mLastStride(0),
-		mLastLength(0)
+    :   LLStaticViewerObject(id, pcode, regionp),
+        mDirtiedPatch(FALSE),
+        mPool(NULL),
+        mBaseComp(0),
+        mPatchp(NULL),
+        mDirtyTexture(FALSE),
+        mDirtyTerrain(FALSE),
+        mLastNorthStride(0),
+        mLastEastStride(0),
+        mLastStride(0),
+        mLastLength(0)
 {
-	// Terrain must draw during selection passes so it can block objects behind it.
-	mbCanSelect = TRUE;
-	setScale(LLVector3(16.f, 16.f, 16.f)); // Hack for setting scale for bounding boxes/visibility.
+    // Terrain must draw during selection passes so it can block objects behind it.
+    mbCanSelect = TRUE;
+    setScale(LLVector3(16.f, 16.f, 16.f)); // Hack for setting scale for bounding boxes/visibility.
 }
 
 
 LLVOSurfacePatch::~LLVOSurfacePatch()
 {
-	mPatchp = NULL;
+    mPatchp = NULL;
 }
 
 
 void LLVOSurfacePatch::markDead()
 {
-	if (mPatchp)
-	{
-		mPatchp->clearVObj();
-		mPatchp = NULL;
-	}
-	LLViewerObject::markDead();
+    if (mPatchp)
+    {
+        mPatchp->clearVObj();
+        mPatchp = NULL;
+    }
+    LLViewerObject::markDead();
 }
 
 
 BOOL LLVOSurfacePatch::isActive() const
 {
-	return FALSE;
+    return FALSE;
 }
 
 
 void LLVOSurfacePatch::setPixelAreaAndAngle(LLAgent &agent)
 {
-	mAppAngle = 50;
-	mPixelArea = 500*500;
+    mAppAngle = 50;
+    mPixelArea = 500*500;
 }
 
 
@@ -102,145 +102,145 @@ void LLVOSurfacePatch::updateTextures()
 
 LLFacePool *LLVOSurfacePatch::getPool()
 {
-	mPool = (LLDrawPoolTerrain*) gPipeline.getPool(LLDrawPool::POOL_TERRAIN, mPatchp->getSurface()->getSTexture());
+    mPool = (LLDrawPoolTerrain*) gPipeline.getPool(LLDrawPool::POOL_TERRAIN, mPatchp->getSurface()->getSTexture());
 
-	return mPool;
+    return mPool;
 }
 
 
 LLDrawable *LLVOSurfacePatch::createDrawable(LLPipeline *pipeline)
 {
-	pipeline->allocDrawable(this);
-
-	mDrawable->setRenderType(LLPipeline::RENDER_TYPE_TERRAIN);
-	
-	mBaseComp = llfloor(mPatchp->getMinComposition());
-	S32 min_comp, max_comp, range;
-	min_comp = llfloor(mPatchp->getMinComposition());
-	max_comp = llceil(mPatchp->getMaxComposition());
-	range = (max_comp - min_comp);
-	range++;
-	if (range > 3)
-	{
-		if ((mPatchp->getMinComposition() - min_comp) > (max_comp - mPatchp->getMaxComposition()))
-		{
-			// The top side runs over more
-			mBaseComp++;
-		}
-		range = 3;
-	}
-
-	LLFacePool *poolp = getPool();
-
-	mDrawable->addFace(poolp, NULL);
-
-	return mDrawable;
+    pipeline->allocDrawable(this);
+
+    mDrawable->setRenderType(LLPipeline::RENDER_TYPE_TERRAIN);
+
+    mBaseComp = llfloor(mPatchp->getMinComposition());
+    S32 min_comp, max_comp, range;
+    min_comp = llfloor(mPatchp->getMinComposition());
+    max_comp = llceil(mPatchp->getMaxComposition());
+    range = (max_comp - min_comp);
+    range++;
+    if (range > 3)
+    {
+        if ((mPatchp->getMinComposition() - min_comp) > (max_comp - mPatchp->getMaxComposition()))
+        {
+            // The top side runs over more
+            mBaseComp++;
+        }
+        range = 3;
+    }
+
+    LLFacePool *poolp = getPool();
+
+    mDrawable->addFace(poolp, NULL);
+
+    return mDrawable;
 }
 
 
 void LLVOSurfacePatch::updateGL()
 {
-	if (mPatchp)
-	{
-		LL_PROFILE_ZONE_SCOPED
-		mPatchp->updateGL();
-	}
+    if (mPatchp)
+    {
+        LL_PROFILE_ZONE_SCOPED
+        mPatchp->updateGL();
+    }
 }
 
 BOOL LLVOSurfacePatch::updateGeometry(LLDrawable *drawable)
 {
     LL_PROFILE_ZONE_SCOPED;
 
-	dirtySpatialGroup();
-	
-	S32 min_comp, max_comp, range;
-	min_comp = lltrunc(mPatchp->getMinComposition());
-	max_comp = lltrunc(ceil(mPatchp->getMaxComposition()));
-	range = (max_comp - min_comp);
-	range++;
-	S32 new_base_comp = lltrunc(mPatchp->getMinComposition());
-	if (range > 3)
-	{
-		if ((mPatchp->getMinComposition() - min_comp) > (max_comp - mPatchp->getMaxComposition()))
-		{
-			// The top side runs over more
-			new_base_comp++;
-		}
-		range = 3;
-	}
-
-	// Pick the two closest detail textures for this patch...
-	// Then create the draw pool for it.
-	// Actually, should get the average composition instead of the center.
-	mBaseComp = new_base_comp;
-
-	//////////////////////////
-	//
-	// Figure out the strides
-	//
-	//
-
-	U32 patch_width, render_stride, north_stride, east_stride, length;
-	render_stride = mPatchp->getRenderStride();
-	patch_width = mPatchp->getSurface()->getGridsPerPatchEdge();
-
-	length = patch_width / render_stride;
-
-	if (mPatchp->getNeighborPatch(NORTH))
-	{
-		north_stride = mPatchp->getNeighborPatch(NORTH)->getRenderStride();
-	}
-	else
-	{
-		north_stride = render_stride;
-	}
-
-	if (mPatchp->getNeighborPatch(EAST))
-	{
-		east_stride = mPatchp->getNeighborPatch(EAST)->getRenderStride();
-	}
-	else
-	{
-		east_stride = render_stride;
-	}
-
-	mLastLength = length;
-	mLastStride = render_stride;
-	mLastNorthStride = north_stride;
-	mLastEastStride = east_stride;
-
-	return TRUE;
+    dirtySpatialGroup();
+
+    S32 min_comp, max_comp, range;
+    min_comp = lltrunc(mPatchp->getMinComposition());
+    max_comp = lltrunc(ceil(mPatchp->getMaxComposition()));
+    range = (max_comp - min_comp);
+    range++;
+    S32 new_base_comp = lltrunc(mPatchp->getMinComposition());
+    if (range > 3)
+    {
+        if ((mPatchp->getMinComposition() - min_comp) > (max_comp - mPatchp->getMaxComposition()))
+        {
+            // The top side runs over more
+            new_base_comp++;
+        }
+        range = 3;
+    }
+
+    // Pick the two closest detail textures for this patch...
+    // Then create the draw pool for it.
+    // Actually, should get the average composition instead of the center.
+    mBaseComp = new_base_comp;
+
+    //////////////////////////
+    //
+    // Figure out the strides
+    //
+    //
+
+    U32 patch_width, render_stride, north_stride, east_stride, length;
+    render_stride = mPatchp->getRenderStride();
+    patch_width = mPatchp->getSurface()->getGridsPerPatchEdge();
+
+    length = patch_width / render_stride;
+
+    if (mPatchp->getNeighborPatch(NORTH))
+    {
+        north_stride = mPatchp->getNeighborPatch(NORTH)->getRenderStride();
+    }
+    else
+    {
+        north_stride = render_stride;
+    }
+
+    if (mPatchp->getNeighborPatch(EAST))
+    {
+        east_stride = mPatchp->getNeighborPatch(EAST)->getRenderStride();
+    }
+    else
+    {
+        east_stride = render_stride;
+    }
+
+    mLastLength = length;
+    mLastStride = render_stride;
+    mLastNorthStride = north_stride;
+    mLastEastStride = east_stride;
+
+    return TRUE;
 }
 
 void LLVOSurfacePatch::updateFaceSize(S32 idx)
 {
     LL_PROFILE_ZONE_SCOPED;
-	if (idx != 0)
-	{
-		LL_WARNS() << "Terrain partition requested invalid face!!!" << LL_ENDL;
-		return;
-	}
-
-	LLFace* facep = mDrawable->getFace(idx);
-	if (facep)
-	{
-		S32 num_vertices = 0;
-		S32 num_indices = 0;
-	
-		if (mLastStride)
-		{
-			getGeomSizesMain(mLastStride, num_vertices, num_indices);
-			getGeomSizesNorth(mLastStride, mLastNorthStride, num_vertices, num_indices);
-			getGeomSizesEast(mLastStride, mLastEastStride, num_vertices, num_indices);
-		}
-
-		facep->setSize(num_vertices, num_indices);	
-	}
+    if (idx != 0)
+    {
+        LL_WARNS() << "Terrain partition requested invalid face!!!" << LL_ENDL;
+        return;
+    }
+
+    LLFace* facep = mDrawable->getFace(idx);
+    if (facep)
+    {
+        S32 num_vertices = 0;
+        S32 num_indices = 0;
+
+        if (mLastStride)
+        {
+            getGeomSizesMain(mLastStride, num_vertices, num_indices);
+            getGeomSizesNorth(mLastStride, mLastNorthStride, num_vertices, num_indices);
+            getGeomSizesEast(mLastStride, mLastEastStride, num_vertices, num_indices);
+        }
+
+        facep->setSize(num_vertices, num_indices);
+    }
 }
 
 BOOL LLVOSurfacePatch::updateLOD()
 {
-	return TRUE;
+    return TRUE;
 }
 
 void LLVOSurfacePatch::getTerrainGeometry(LLStrider<LLVector3> &verticesp,
@@ -249,7 +249,7 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider<LLVector3> &verticesp,
                                               LLStrider<LLVector2> &texCoords1p,
                                               LLStrider<U16> &indicesp)
 {
-	LLFace* facep = mDrawable->getFace(0);
+    LLFace* facep = mDrawable->getFace(0);
     if (!facep)
     {
         return;
@@ -257,21 +257,21 @@ void LLVOSurfacePatch::getTerrainGeometry(LLStrider<LLVector3> &verticesp,
 
     U32 index_offset = facep->getGeomIndex();
 
-    updateMainGeometry(facep, 
+    updateMainGeometry(facep,
                     verticesp,
                     normalsp,
                     texCoords0p,
                     texCoords1p,
                     indicesp,
                     index_offset);
-    updateNorthGeometry(facep, 
+    updateNorthGeometry(facep,
                         verticesp,
                         normalsp,
                         texCoords0p,
                         texCoords1p,
                         indicesp,
                         index_offset);
-    updateEastGeometry(facep, 
+    updateEastGeometry(facep,
                         verticesp,
                         normalsp,
                         texCoords0p,
@@ -288,99 +288,99 @@ void LLVOSurfacePatch::updateMainGeometry(LLFace *facep,
                                         LLStrider<U16> &indicesp,
                                         U32 &index_offset)
 {
-	S32 i, j, x, y;
-
-	U32 patch_size, render_stride;
-	S32 num_vertices, num_indices;
-	U32 index;
-
-	llassert(mLastStride > 0);
-
-	render_stride = mLastStride;
-	patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
-	S32 vert_size = patch_size / render_stride;
-
-	///////////////////////////
-	//
-	// Render the main patch
-	//
-	//
-
-	num_vertices = 0;
-	num_indices = 0;
-	// First, figure out how many vertices we need...
-	getGeomSizesMain(render_stride, num_vertices, num_indices);
-
-	if (num_vertices > 0)
-	{
-		facep->mCenterAgent = mPatchp->getPointAgent(8, 8);
-
-		// Generate patch points first
-		for (j = 0; j < vert_size; j++)
-		{
-			for (i = 0; i < vert_size; i++)
-			{
-				x = i * render_stride;
-				y = j * render_stride;
-				mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-				verticesp++;
-				normalsp++;
-				texCoords0p++;
-				texCoords1p++;
-			}
-		}
-
-		for (j = 0; j < (vert_size - 1); j++)
-		{
-			if (j % 2)
-			{
-				for (i = (vert_size - 1); i > 0; i--)
-				{
-					index = (i - 1)+ j*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = i + (j+1)*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = (i - 1) + (j+1)*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = (i - 1) + j*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = i + j*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = i + (j+1)*vert_size;
-					*(indicesp++) = index_offset + index;
-				}
-			}
-			else
-			{
-				for (i = 0; i < (vert_size - 1); i++)
-				{
-					index = i + j*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = (i + 1) + (j+1)*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = i + (j+1)*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = i + j*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = (i + 1) + j*vert_size;
-					*(indicesp++) = index_offset + index;
-
-					index = (i + 1) + (j + 1)*vert_size;
-					*(indicesp++) = index_offset + index;
-				}
-			}
-		}
-	}
-	index_offset += num_vertices;
+    S32 i, j, x, y;
+
+    U32 patch_size, render_stride;
+    S32 num_vertices, num_indices;
+    U32 index;
+
+    llassert(mLastStride > 0);
+
+    render_stride = mLastStride;
+    patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
+    S32 vert_size = patch_size / render_stride;
+
+    ///////////////////////////
+    //
+    // Render the main patch
+    //
+    //
+
+    num_vertices = 0;
+    num_indices = 0;
+    // First, figure out how many vertices we need...
+    getGeomSizesMain(render_stride, num_vertices, num_indices);
+
+    if (num_vertices > 0)
+    {
+        facep->mCenterAgent = mPatchp->getPointAgent(8, 8);
+
+        // Generate patch points first
+        for (j = 0; j < vert_size; j++)
+        {
+            for (i = 0; i < vert_size; i++)
+            {
+                x = i * render_stride;
+                y = j * render_stride;
+                mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+                verticesp++;
+                normalsp++;
+                texCoords0p++;
+                texCoords1p++;
+            }
+        }
+
+        for (j = 0; j < (vert_size - 1); j++)
+        {
+            if (j % 2)
+            {
+                for (i = (vert_size - 1); i > 0; i--)
+                {
+                    index = (i - 1)+ j*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = i + (j+1)*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = (i - 1) + (j+1)*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = (i - 1) + j*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = i + j*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = i + (j+1)*vert_size;
+                    *(indicesp++) = index_offset + index;
+                }
+            }
+            else
+            {
+                for (i = 0; i < (vert_size - 1); i++)
+                {
+                    index = i + j*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = (i + 1) + (j+1)*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = i + (j+1)*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = i + j*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = (i + 1) + j*vert_size;
+                    *(indicesp++) = index_offset + index;
+
+                    index = (i + 1) + (j + 1)*vert_size;
+                    *(indicesp++) = index_offset + index;
+                }
+            }
+        }
+    }
+    index_offset += num_vertices;
 }
 
 
@@ -392,186 +392,186 @@ void LLVOSurfacePatch::updateNorthGeometry(LLFace *facep,
                                         LLStrider<U16> &indicesp,
                                         U32 &index_offset)
 {
-	S32 i, x, y;
-
-	S32 num_vertices;
-
-	U32 render_stride = mLastStride;
-	S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
-	S32 length = patch_size / render_stride;
-	S32 half_length = length / 2;
-	U32 north_stride = mLastNorthStride;
-	
-	///////////////////////////
-	//
-	// Render the north strip
-	//
-	//
-
-	// Stride lengths are the same
-	if (north_stride == render_stride)
-	{
-		num_vertices = 2 * length + 1;
-
-		facep->mCenterAgent = (mPatchp->getPointAgent(8, 15) + mPatchp->getPointAgent(8, 16))*0.5f;
-
-		// Main patch
-		for (i = 0; i < length; i++)
-		{
-			x = i * render_stride;
-			y = 16 - render_stride;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-		// North patch
-		for (i = 0; i <= length; i++)
-		{
-			x = i * render_stride;
-			y = 16;
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-
-		for (i = 0; i < length; i++)
-		{
-			// Generate indices
-			*(indicesp++) = index_offset + i;
-			*(indicesp++) = index_offset + length + i + 1;
-			*(indicesp++) = index_offset + length + i;
-
-			if (i != length - 1)
-			{
-				*(indicesp++) = index_offset + i;
-				*(indicesp++) = index_offset + i + 1;
-				*(indicesp++) = index_offset + length + i + 1;
-			}
-		}
-	}
-	else if (north_stride > render_stride)
-	{
-		// North stride is longer (has less vertices)
-		num_vertices = length + length/2 + 1;
-
-		facep->mCenterAgent = (mPatchp->getPointAgent(7, 15) + mPatchp->getPointAgent(8, 16))*0.5f;
-
-		// Iterate through this patch's points
-		for (i = 0; i < length; i++)
-		{
-			x = i * render_stride;
-			y = 16 - render_stride;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-		// Iterate through the north patch's points
-		for (i = 0; i <= length; i+=2)
-		{
-			x = i * render_stride;
-			y = 16;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-
-		for (i = 0; i < length; i++)
-		{
-			if (!(i % 2))
-			{
-				*(indicesp++) = index_offset + i;
-				*(indicesp++) = index_offset + i + 1;
-				*(indicesp++) = index_offset + length + (i/2);
-
-				*(indicesp++) = index_offset + i + 1;
-				*(indicesp++) = index_offset + length + (i/2) + 1;
-				*(indicesp++) = index_offset + length + (i/2);
-			}
-			else if (i < (length - 1))
-			{
-				*(indicesp++) = index_offset + i;
-				*(indicesp++) = index_offset + i + 1;
-				*(indicesp++) = index_offset + length + (i/2) + 1;
-			}
-		}
-	}
-	else
-	{
-		// North stride is shorter (more vertices)
-		length = patch_size / north_stride;
-		half_length = length / 2;
-		num_vertices = length + half_length + 1;
-
-		facep->mCenterAgent = (mPatchp->getPointAgent(15, 7) + mPatchp->getPointAgent(16, 8))*0.5f;
-
-		// Iterate through this patch's points
-		for (i = 0; i < length; i+=2)
-		{
-			x = i * north_stride;
-			y = 16 - render_stride;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-		// Iterate through the north patch's points
-		for (i = 0; i <= length; i++)
-		{
-			x = i * north_stride;
-			y = 16;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-		for (i = 0; i < length; i++)
-		{
-			if (!(i%2))
-			{
-				*(indicesp++) = index_offset + half_length + i;
-				*(indicesp++) = index_offset + i/2;
-				*(indicesp++) = index_offset + half_length + i + 1;
-			}
-			else if (i < (length - 2))
-			{
-				*(indicesp++) = index_offset + half_length + i;
-				*(indicesp++) = index_offset + i/2;
-				*(indicesp++) = index_offset + i/2 + 1;
-
-				*(indicesp++) = index_offset + half_length + i;
-				*(indicesp++) = index_offset + i/2 + 1;
-				*(indicesp++) = index_offset + half_length + i + 1;
-			}
-			else
-			{
-				*(indicesp++) = index_offset + half_length + i;
-				*(indicesp++) = index_offset + i/2;
-				*(indicesp++) = index_offset + half_length + i + 1;
-			}
-		}
-	}
-	index_offset += num_vertices;
+    S32 i, x, y;
+
+    S32 num_vertices;
+
+    U32 render_stride = mLastStride;
+    S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
+    S32 length = patch_size / render_stride;
+    S32 half_length = length / 2;
+    U32 north_stride = mLastNorthStride;
+
+    ///////////////////////////
+    //
+    // Render the north strip
+    //
+    //
+
+    // Stride lengths are the same
+    if (north_stride == render_stride)
+    {
+        num_vertices = 2 * length + 1;
+
+        facep->mCenterAgent = (mPatchp->getPointAgent(8, 15) + mPatchp->getPointAgent(8, 16))*0.5f;
+
+        // Main patch
+        for (i = 0; i < length; i++)
+        {
+            x = i * render_stride;
+            y = 16 - render_stride;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+        // North patch
+        for (i = 0; i <= length; i++)
+        {
+            x = i * render_stride;
+            y = 16;
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+
+        for (i = 0; i < length; i++)
+        {
+            // Generate indices
+            *(indicesp++) = index_offset + i;
+            *(indicesp++) = index_offset + length + i + 1;
+            *(indicesp++) = index_offset + length + i;
+
+            if (i != length - 1)
+            {
+                *(indicesp++) = index_offset + i;
+                *(indicesp++) = index_offset + i + 1;
+                *(indicesp++) = index_offset + length + i + 1;
+            }
+        }
+    }
+    else if (north_stride > render_stride)
+    {
+        // North stride is longer (has less vertices)
+        num_vertices = length + length/2 + 1;
+
+        facep->mCenterAgent = (mPatchp->getPointAgent(7, 15) + mPatchp->getPointAgent(8, 16))*0.5f;
+
+        // Iterate through this patch's points
+        for (i = 0; i < length; i++)
+        {
+            x = i * render_stride;
+            y = 16 - render_stride;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+        // Iterate through the north patch's points
+        for (i = 0; i <= length; i+=2)
+        {
+            x = i * render_stride;
+            y = 16;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+
+        for (i = 0; i < length; i++)
+        {
+            if (!(i % 2))
+            {
+                *(indicesp++) = index_offset + i;
+                *(indicesp++) = index_offset + i + 1;
+                *(indicesp++) = index_offset + length + (i/2);
+
+                *(indicesp++) = index_offset + i + 1;
+                *(indicesp++) = index_offset + length + (i/2) + 1;
+                *(indicesp++) = index_offset + length + (i/2);
+            }
+            else if (i < (length - 1))
+            {
+                *(indicesp++) = index_offset + i;
+                *(indicesp++) = index_offset + i + 1;
+                *(indicesp++) = index_offset + length + (i/2) + 1;
+            }
+        }
+    }
+    else
+    {
+        // North stride is shorter (more vertices)
+        length = patch_size / north_stride;
+        half_length = length / 2;
+        num_vertices = length + half_length + 1;
+
+        facep->mCenterAgent = (mPatchp->getPointAgent(15, 7) + mPatchp->getPointAgent(16, 8))*0.5f;
+
+        // Iterate through this patch's points
+        for (i = 0; i < length; i+=2)
+        {
+            x = i * north_stride;
+            y = 16 - render_stride;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+        // Iterate through the north patch's points
+        for (i = 0; i <= length; i++)
+        {
+            x = i * north_stride;
+            y = 16;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+        for (i = 0; i < length; i++)
+        {
+            if (!(i%2))
+            {
+                *(indicesp++) = index_offset + half_length + i;
+                *(indicesp++) = index_offset + i/2;
+                *(indicesp++) = index_offset + half_length + i + 1;
+            }
+            else if (i < (length - 2))
+            {
+                *(indicesp++) = index_offset + half_length + i;
+                *(indicesp++) = index_offset + i/2;
+                *(indicesp++) = index_offset + i/2 + 1;
+
+                *(indicesp++) = index_offset + half_length + i;
+                *(indicesp++) = index_offset + i/2 + 1;
+                *(indicesp++) = index_offset + half_length + i + 1;
+            }
+            else
+            {
+                *(indicesp++) = index_offset + half_length + i;
+                *(indicesp++) = index_offset + i/2;
+                *(indicesp++) = index_offset + half_length + i + 1;
+            }
+        }
+    }
+    index_offset += num_vertices;
 }
 
 void LLVOSurfacePatch::updateEastGeometry(LLFace *facep,
@@ -582,408 +582,408 @@ void LLVOSurfacePatch::updateEastGeometry(LLFace *facep,
                                           LLStrider<U16> &indicesp,
                                           U32 &index_offset)
 {
-	S32 i, x, y;
-
-	S32 num_vertices;
-
-	U32 render_stride = mLastStride;
-	S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
-	S32 length = patch_size / render_stride;
-	S32 half_length = length / 2;
-
-	U32 east_stride = mLastEastStride;
-
-	// Stride lengths are the same
-	if (east_stride == render_stride)
-	{
-		num_vertices = 2 * length + 1;
-
-		facep->mCenterAgent = (mPatchp->getPointAgent(8, 15) + mPatchp->getPointAgent(8, 16))*0.5f;
-
-		// Main patch
-		for (i = 0; i < length; i++)
-		{
-			x = 16 - render_stride;
-			y = i * render_stride;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-		// East patch
-		for (i = 0; i <= length; i++)
-		{
-			x = 16;
-			y = i * render_stride;
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-
-		for (i = 0; i < length; i++)
-		{
-			// Generate indices
-			*(indicesp++) = index_offset + i;
-			*(indicesp++) = index_offset + length + i;
-			*(indicesp++) = index_offset + length + i + 1;
-
-			if (i != length - 1)
-			{
-				*(indicesp++) = index_offset + i;
-				*(indicesp++) = index_offset + length + i + 1;
-				*(indicesp++) = index_offset + i + 1;
-			}
-		}
-	}
-	else if (east_stride > render_stride)
-	{
-		// East stride is longer (has less vertices)
-		num_vertices = length + half_length + 1;
-
-		facep->mCenterAgent = (mPatchp->getPointAgent(7, 15) + mPatchp->getPointAgent(8, 16))*0.5f;
-
-		// Iterate through this patch's points
-		for (i = 0; i < length; i++)
-		{
-			x = 16 - render_stride;
-			y = i * render_stride;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-		// Iterate through the east patch's points
-		for (i = 0; i <= length; i+=2)
-		{
-			x = 16;
-			y = i * render_stride;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-		for (i = 0; i < length; i++)
-		{
-			if (!(i % 2))
-			{
-				*(indicesp++) = index_offset + i;
-				*(indicesp++) = index_offset + length + (i/2);
-				*(indicesp++) = index_offset + i + 1;
-
-				*(indicesp++) = index_offset + i + 1;
-				*(indicesp++) = index_offset + length + (i/2);
-				*(indicesp++) = index_offset + length + (i/2) + 1;
-			}
-			else if (i < (length - 1))
-			{
-				*(indicesp++) = index_offset + i;
-				*(indicesp++) = index_offset + length + (i/2) + 1;
-				*(indicesp++) = index_offset + i + 1;
-			}
-		}
-	}
-	else
-	{
-		// East stride is shorter (more vertices)
-		length = patch_size / east_stride;
-		half_length = length / 2;
-		num_vertices = length + length/2 + 1;
-
-		facep->mCenterAgent = (mPatchp->getPointAgent(15, 7) + mPatchp->getPointAgent(16, 8))*0.5f;
-
-		// Iterate through this patch's points
-		for (i = 0; i < length; i+=2)
-		{
-			x = 16 - render_stride;
-			y = i * east_stride;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-		// Iterate through the east patch's points
-		for (i = 0; i <= length; i++)
-		{
-			x = 16;
-			y = i * east_stride;
-
-			mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
-			verticesp++;
-			normalsp++;
-			texCoords0p++;
-			texCoords1p++;
-		}
-
-		for (i = 0; i < length; i++)
-		{
-			if (!(i%2))
-			{
-				*(indicesp++) = index_offset + half_length + i;
-				*(indicesp++) = index_offset + half_length + i + 1;
-				*(indicesp++) = index_offset + i/2;
-			}
-			else if (i < (length - 2))
-			{
-				*(indicesp++) = index_offset + half_length + i;
-				*(indicesp++) = index_offset + i/2 + 1;
-				*(indicesp++) = index_offset + i/2;
-
-				*(indicesp++) = index_offset + half_length + i;
-				*(indicesp++) = index_offset + half_length + i + 1;
-				*(indicesp++) = index_offset + i/2 + 1;
-			}
-			else
-			{
-				*(indicesp++) = index_offset + half_length + i;
-				*(indicesp++) = index_offset + half_length + i + 1;
-				*(indicesp++) = index_offset + i/2;
-			}
-		}
-	}
-	index_offset += num_vertices;
+    S32 i, x, y;
+
+    S32 num_vertices;
+
+    U32 render_stride = mLastStride;
+    S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
+    S32 length = patch_size / render_stride;
+    S32 half_length = length / 2;
+
+    U32 east_stride = mLastEastStride;
+
+    // Stride lengths are the same
+    if (east_stride == render_stride)
+    {
+        num_vertices = 2 * length + 1;
+
+        facep->mCenterAgent = (mPatchp->getPointAgent(8, 15) + mPatchp->getPointAgent(8, 16))*0.5f;
+
+        // Main patch
+        for (i = 0; i < length; i++)
+        {
+            x = 16 - render_stride;
+            y = i * render_stride;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+        // East patch
+        for (i = 0; i <= length; i++)
+        {
+            x = 16;
+            y = i * render_stride;
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+
+        for (i = 0; i < length; i++)
+        {
+            // Generate indices
+            *(indicesp++) = index_offset + i;
+            *(indicesp++) = index_offset + length + i;
+            *(indicesp++) = index_offset + length + i + 1;
+
+            if (i != length - 1)
+            {
+                *(indicesp++) = index_offset + i;
+                *(indicesp++) = index_offset + length + i + 1;
+                *(indicesp++) = index_offset + i + 1;
+            }
+        }
+    }
+    else if (east_stride > render_stride)
+    {
+        // East stride is longer (has less vertices)
+        num_vertices = length + half_length + 1;
+
+        facep->mCenterAgent = (mPatchp->getPointAgent(7, 15) + mPatchp->getPointAgent(8, 16))*0.5f;
+
+        // Iterate through this patch's points
+        for (i = 0; i < length; i++)
+        {
+            x = 16 - render_stride;
+            y = i * render_stride;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+        // Iterate through the east patch's points
+        for (i = 0; i <= length; i+=2)
+        {
+            x = 16;
+            y = i * render_stride;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+        for (i = 0; i < length; i++)
+        {
+            if (!(i % 2))
+            {
+                *(indicesp++) = index_offset + i;
+                *(indicesp++) = index_offset + length + (i/2);
+                *(indicesp++) = index_offset + i + 1;
+
+                *(indicesp++) = index_offset + i + 1;
+                *(indicesp++) = index_offset + length + (i/2);
+                *(indicesp++) = index_offset + length + (i/2) + 1;
+            }
+            else if (i < (length - 1))
+            {
+                *(indicesp++) = index_offset + i;
+                *(indicesp++) = index_offset + length + (i/2) + 1;
+                *(indicesp++) = index_offset + i + 1;
+            }
+        }
+    }
+    else
+    {
+        // East stride is shorter (more vertices)
+        length = patch_size / east_stride;
+        half_length = length / 2;
+        num_vertices = length + length/2 + 1;
+
+        facep->mCenterAgent = (mPatchp->getPointAgent(15, 7) + mPatchp->getPointAgent(16, 8))*0.5f;
+
+        // Iterate through this patch's points
+        for (i = 0; i < length; i+=2)
+        {
+            x = 16 - render_stride;
+            y = i * east_stride;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+        // Iterate through the east patch's points
+        for (i = 0; i <= length; i++)
+        {
+            x = 16;
+            y = i * east_stride;
+
+            mPatchp->eval(x, y, render_stride, verticesp.get(), normalsp.get(), texCoords0p.get(), texCoords1p.get());
+            verticesp++;
+            normalsp++;
+            texCoords0p++;
+            texCoords1p++;
+        }
+
+        for (i = 0; i < length; i++)
+        {
+            if (!(i%2))
+            {
+                *(indicesp++) = index_offset + half_length + i;
+                *(indicesp++) = index_offset + half_length + i + 1;
+                *(indicesp++) = index_offset + i/2;
+            }
+            else if (i < (length - 2))
+            {
+                *(indicesp++) = index_offset + half_length + i;
+                *(indicesp++) = index_offset + i/2 + 1;
+                *(indicesp++) = index_offset + i/2;
+
+                *(indicesp++) = index_offset + half_length + i;
+                *(indicesp++) = index_offset + half_length + i + 1;
+                *(indicesp++) = index_offset + i/2 + 1;
+            }
+            else
+            {
+                *(indicesp++) = index_offset + half_length + i;
+                *(indicesp++) = index_offset + half_length + i + 1;
+                *(indicesp++) = index_offset + i/2;
+            }
+        }
+    }
+    index_offset += num_vertices;
 }
 
 void LLVOSurfacePatch::setPatch(LLSurfacePatch *patchp)
 {
-	mPatchp = patchp;
+    mPatchp = patchp;
 
-	dirtyPatch();
+    dirtyPatch();
 };
 
 
 void LLVOSurfacePatch::dirtyPatch()
 {
-	mDirtiedPatch = TRUE;
-	dirtyGeom();
-	mDirtyTerrain = TRUE;
-	LLVector3 center = mPatchp->getCenterRegion();
-	LLSurface *surfacep = mPatchp->getSurface();
+    mDirtiedPatch = TRUE;
+    dirtyGeom();
+    mDirtyTerrain = TRUE;
+    LLVector3 center = mPatchp->getCenterRegion();
+    LLSurface *surfacep = mPatchp->getSurface();
 
-	setPositionRegion(center);
+    setPositionRegion(center);
 
-	F32 scale_factor = surfacep->getGridsPerPatchEdge() * surfacep->getMetersPerGrid();
-	setScale(LLVector3(scale_factor, scale_factor, mPatchp->getMaxZ() - mPatchp->getMinZ()));
+    F32 scale_factor = surfacep->getGridsPerPatchEdge() * surfacep->getMetersPerGrid();
+    setScale(LLVector3(scale_factor, scale_factor, mPatchp->getMaxZ() - mPatchp->getMinZ()));
 }
 
 void LLVOSurfacePatch::dirtyGeom()
 {
-	if (mDrawable)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL);
-		LLFace* facep = mDrawable->getFace(0);
-		if (facep)
-		{
-			facep->setVertexBuffer(NULL);
-		}
-		mDrawable->movePartition();
-	}
+    if (mDrawable)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_ALL);
+        LLFace* facep = mDrawable->getFace(0);
+        if (facep)
+        {
+            facep->setVertexBuffer(NULL);
+        }
+        mDrawable->movePartition();
+    }
 }
 
 void LLVOSurfacePatch::getGeomSizesMain(const S32 stride, S32 &num_vertices, S32 &num_indices)
 {
-	S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
-
-	// First, figure out how many vertices we need...
-	S32 vert_size = patch_size / stride;
-	if (vert_size >= 2)
-	{
-		num_vertices += vert_size * vert_size;
-		num_indices += 6 * (vert_size - 1)*(vert_size - 1);
-	}
+    S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
+
+    // First, figure out how many vertices we need...
+    S32 vert_size = patch_size / stride;
+    if (vert_size >= 2)
+    {
+        num_vertices += vert_size * vert_size;
+        num_indices += 6 * (vert_size - 1)*(vert_size - 1);
+    }
 }
 
 void LLVOSurfacePatch::getGeomSizesNorth(const S32 stride, const S32 north_stride,
-										 S32 &num_vertices, S32 &num_indices)
+                                         S32 &num_vertices, S32 &num_indices)
 {
-	S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
-	S32 length = patch_size / stride;
-	// Stride lengths are the same
-	if (north_stride == stride)
-	{
-		num_vertices += 2 * length + 1;
-		num_indices += length * 6 - 3;
-	}
-	else if (north_stride > stride)
-	{
-		// North stride is longer (has less vertices)
-		num_vertices += length + (length/2) + 1;
-		num_indices += (length/2)*9 - 3;
-	}
-	else
-	{
-		// North stride is shorter (more vertices)
-		length = patch_size / north_stride;
-		num_vertices += length + (length/2) + 1;
-		num_indices += 9*(length/2) - 3;
-	}
+    S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
+    S32 length = patch_size / stride;
+    // Stride lengths are the same
+    if (north_stride == stride)
+    {
+        num_vertices += 2 * length + 1;
+        num_indices += length * 6 - 3;
+    }
+    else if (north_stride > stride)
+    {
+        // North stride is longer (has less vertices)
+        num_vertices += length + (length/2) + 1;
+        num_indices += (length/2)*9 - 3;
+    }
+    else
+    {
+        // North stride is shorter (more vertices)
+        length = patch_size / north_stride;
+        num_vertices += length + (length/2) + 1;
+        num_indices += 9*(length/2) - 3;
+    }
 }
 
 void LLVOSurfacePatch::getGeomSizesEast(const S32 stride, const S32 east_stride,
-										S32 &num_vertices, S32 &num_indices)
+                                        S32 &num_vertices, S32 &num_indices)
 {
-	S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
-	S32 length = patch_size / stride;
-	// Stride lengths are the same
-	if (east_stride == stride)
-	{
-		num_vertices += 2 * length + 1;
-		num_indices += length * 6 - 3;
-	}
-	else if (east_stride > stride)
-	{
-		// East stride is longer (has less vertices)
-		num_vertices += length + (length/2) + 1;
-		num_indices += (length/2)*9 - 3;
-	}
-	else
-	{
-		// East stride is shorter (more vertices)
-		length = patch_size / east_stride;
-		num_vertices += length + (length/2) + 1;
-		num_indices += 9*(length/2) - 3;
-	}
+    S32 patch_size = mPatchp->getSurface()->getGridsPerPatchEdge();
+    S32 length = patch_size / stride;
+    // Stride lengths are the same
+    if (east_stride == stride)
+    {
+        num_vertices += 2 * length + 1;
+        num_indices += length * 6 - 3;
+    }
+    else if (east_stride > stride)
+    {
+        // East stride is longer (has less vertices)
+        num_vertices += length + (length/2) + 1;
+        num_indices += (length/2)*9 - 3;
+    }
+    else
+    {
+        // East stride is shorter (more vertices)
+        length = patch_size / east_stride;
+        num_vertices += length + (length/2) + 1;
+        num_indices += 9*(length/2) - 3;
+    }
 }
 
 BOOL LLVOSurfacePatch::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end, S32 face, BOOL pick_transparent, BOOL pick_rigged, BOOL pick_unselectable, S32 *face_hitp,
-									  LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent)
-	
+                                      LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent)
+
 {
 
-	if (!lineSegmentBoundingBox(start, end))
-	{
-		return FALSE;
-	}
-
-	LLVector4a da;
-	da.setSub(end, start);
-	LLVector3 delta(da.getF32ptr());
-		
-	LLVector3 pdelta = delta;
-	pdelta.mV[2] = 0;
-
-	F32 plength = pdelta.length();
-	
-	F32 tdelta = 1.f/plength;
-
-	LLVector3 v_start(start.getF32ptr());
-
-	LLVector3 origin = v_start - mRegionp->getOriginAgent();
-
-	if (mRegionp->getLandHeightRegion(origin) > origin.mV[2])
-	{
-		//origin is under ground, treat as no intersection
-		return FALSE;
-	}
-
-	//step one meter at a time until intersection point found
-
-	//VECTORIZE THIS
-	const LLVector4a* exta = mDrawable->getSpatialExtents();
-
-	LLVector3 ext[2];
-	ext[0].set(exta[0].getF32ptr());
-	ext[1].set(exta[1].getF32ptr());
-
-	F32 rad = (delta*tdelta).magVecSquared();
-
-	F32 t = 0.f;
-	while ( t <= 1.f)
-	{
-		LLVector3 sample = origin + delta*t;
-		
-		if (AABBSphereIntersectR2(ext[0], ext[1], sample+mRegionp->getOriginAgent(), rad))
-		{
-			F32 height = mRegionp->getLandHeightRegion(sample);
-			if (height > sample.mV[2])
-			{ //ray went below ground, positive intersection
-				//quick and dirty binary search to get impact point
-				tdelta = -tdelta*0.5f;
-				F32 err_dist = 0.001f;
-				F32 dist = fabsf(sample.mV[2] - height);
-
-				while (dist > err_dist && tdelta*tdelta > 0.0f)
-				{
-					t += tdelta;
-					sample = origin+delta*t;
-					height = mRegionp->getLandHeightRegion(sample);
-					if ((tdelta < 0 && height < sample.mV[2]) ||
-						(height > sample.mV[2] && tdelta > 0))
-					{ //jumped over intersection point, go back
-						tdelta = -tdelta;
-					}
-					tdelta *= 0.5f;
-					dist = fabsf(sample.mV[2] - height);
-				}
-
-				if (intersection)
-				{
-					F32 height = mRegionp->getLandHeightRegion(sample);
-					if (fabsf(sample.mV[2]-height) < delta.length()*tdelta)
-					{
-						sample.mV[2] = mRegionp->getLandHeightRegion(sample);
-					}
-					intersection->load3((sample + mRegionp->getOriginAgent()).mV);
-				}
-
-				if (normal)
-				{
-					normal->load3((mRegionp->getLand().resolveNormalGlobal(mRegionp->getPosGlobalFromRegion(sample))).mV);
-				}
-
-				return TRUE;
-			}
-		}
-
-		t += tdelta;
-		if (t > 1 && t < 1.f+tdelta*0.99f)
-		{ //make sure end point is checked (saves vertical lines coming up negative)
-			t = 1.f;
-		}
-	}
-
-
-	return FALSE;
+    if (!lineSegmentBoundingBox(start, end))
+    {
+        return FALSE;
+    }
+
+    LLVector4a da;
+    da.setSub(end, start);
+    LLVector3 delta(da.getF32ptr());
+
+    LLVector3 pdelta = delta;
+    pdelta.mV[2] = 0;
+
+    F32 plength = pdelta.length();
+
+    F32 tdelta = 1.f/plength;
+
+    LLVector3 v_start(start.getF32ptr());
+
+    LLVector3 origin = v_start - mRegionp->getOriginAgent();
+
+    if (mRegionp->getLandHeightRegion(origin) > origin.mV[2])
+    {
+        //origin is under ground, treat as no intersection
+        return FALSE;
+    }
+
+    //step one meter at a time until intersection point found
+
+    //VECTORIZE THIS
+    const LLVector4a* exta = mDrawable->getSpatialExtents();
+
+    LLVector3 ext[2];
+    ext[0].set(exta[0].getF32ptr());
+    ext[1].set(exta[1].getF32ptr());
+
+    F32 rad = (delta*tdelta).magVecSquared();
+
+    F32 t = 0.f;
+    while ( t <= 1.f)
+    {
+        LLVector3 sample = origin + delta*t;
+
+        if (AABBSphereIntersectR2(ext[0], ext[1], sample+mRegionp->getOriginAgent(), rad))
+        {
+            F32 height = mRegionp->getLandHeightRegion(sample);
+            if (height > sample.mV[2])
+            { //ray went below ground, positive intersection
+                //quick and dirty binary search to get impact point
+                tdelta = -tdelta*0.5f;
+                F32 err_dist = 0.001f;
+                F32 dist = fabsf(sample.mV[2] - height);
+
+                while (dist > err_dist && tdelta*tdelta > 0.0f)
+                {
+                    t += tdelta;
+                    sample = origin+delta*t;
+                    height = mRegionp->getLandHeightRegion(sample);
+                    if ((tdelta < 0 && height < sample.mV[2]) ||
+                        (height > sample.mV[2] && tdelta > 0))
+                    { //jumped over intersection point, go back
+                        tdelta = -tdelta;
+                    }
+                    tdelta *= 0.5f;
+                    dist = fabsf(sample.mV[2] - height);
+                }
+
+                if (intersection)
+                {
+                    F32 height = mRegionp->getLandHeightRegion(sample);
+                    if (fabsf(sample.mV[2]-height) < delta.length()*tdelta)
+                    {
+                        sample.mV[2] = mRegionp->getLandHeightRegion(sample);
+                    }
+                    intersection->load3((sample + mRegionp->getOriginAgent()).mV);
+                }
+
+                if (normal)
+                {
+                    normal->load3((mRegionp->getLand().resolveNormalGlobal(mRegionp->getPosGlobalFromRegion(sample))).mV);
+                }
+
+                return TRUE;
+            }
+        }
+
+        t += tdelta;
+        if (t > 1 && t < 1.f+tdelta*0.99f)
+        { //make sure end point is checked (saves vertical lines coming up negative)
+            t = 1.f;
+        }
+    }
+
+
+    return FALSE;
 }
 
 void LLVOSurfacePatch::updateSpatialExtents(LLVector4a& newMin, LLVector4a &newMax)
 {
-	LLVector3 posAgent = getPositionAgent();
-	LLVector3 scale = getScale();
-	//make z-axis scale at least 1 to avoid shadow artifacts on totally flat land
-	scale.mV[VZ] = llmax(scale.mV[VZ], 1.f);
-	newMin.load3( (posAgent-scale*0.5f).mV); // Changing to 2.f makes the culling a -little- better, but still wrong
-	newMax.load3( (posAgent+scale*0.5f).mV);
-	LLVector4a pos;
-	pos.setAdd(newMin,newMax);
-	pos.mul(0.5f);
-	mDrawable->setPositionGroup(pos);
+    LLVector3 posAgent = getPositionAgent();
+    LLVector3 scale = getScale();
+    //make z-axis scale at least 1 to avoid shadow artifacts on totally flat land
+    scale.mV[VZ] = llmax(scale.mV[VZ], 1.f);
+    newMin.load3( (posAgent-scale*0.5f).mV); // Changing to 2.f makes the culling a -little- better, but still wrong
+    newMax.load3( (posAgent+scale*0.5f).mV);
+    LLVector4a pos;
+    pos.setAdd(newMin,newMax);
+    pos.mul(0.5f);
+    mDrawable->setPositionGroup(pos);
 }
 
 U32 LLVOSurfacePatch::getPartitionType() const
-{ 
-	return LLViewerRegion::PARTITION_TERRAIN; 
+{
+    return LLViewerRegion::PARTITION_TERRAIN;
 }
 
 LLTerrainPartition::LLTerrainPartition(LLViewerRegion* regionp)
 : LLSpatialPartition(LLDrawPoolTerrain::VERTEX_DATA_MASK, FALSE, regionp)
 {
-	mOcclusionEnabled = FALSE;
-	mInfiniteFarClip = TRUE;
-	mDrawableType = LLPipeline::RENDER_TYPE_TERRAIN;
-	mPartitionType = LLViewerRegion::PARTITION_TERRAIN;
+    mOcclusionEnabled = FALSE;
+    mInfiniteFarClip = TRUE;
+    mDrawableType = LLPipeline::RENDER_TYPE_TERRAIN;
+    mPartitionType = LLViewerRegion::PARTITION_TERRAIN;
 }
 
 // Do not add vertices; honor strict vertex count specified by strider_vertex_count
@@ -1033,22 +1033,22 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group)
 {
     LL_PROFILE_ZONE_SCOPED;
 
-	LLVertexBuffer* buffer = group->mVertexBuffer;
+    LLVertexBuffer* buffer = group->mVertexBuffer;
 
-	//get vertex buffer striders
-	LLStrider<LLVector3> vertices_start;
-	LLStrider<LLVector3> normals_start;
-	LLStrider<LLVector4a> tangents_start;
-	LLStrider<LLVector2> texcoords_start;
-	LLStrider<LLVector2> texcoords2_start;
-	LLStrider<U16> indices_start;
+    //get vertex buffer striders
+    LLStrider<LLVector3> vertices_start;
+    LLStrider<LLVector3> normals_start;
+    LLStrider<LLVector4a> tangents_start;
+    LLStrider<LLVector2> texcoords_start;
+    LLStrider<LLVector2> texcoords2_start;
+    LLStrider<U16> indices_start;
 
-	llassert_always(buffer->getVertexStrider(vertices_start));
-	llassert_always(buffer->getNormalStrider(normals_start));
-	llassert_always(buffer->getTangentStrider(tangents_start));
-	llassert_always(buffer->getTexCoord0Strider(texcoords_start));
-	llassert_always(buffer->getTexCoord1Strider(texcoords2_start));
-	llassert_always(buffer->getIndexStrider(indices_start));
+    llassert_always(buffer->getVertexStrider(vertices_start));
+    llassert_always(buffer->getNormalStrider(normals_start));
+    llassert_always(buffer->getTangentStrider(tangents_start));
+    llassert_always(buffer->getTexCoord0Strider(texcoords_start));
+    llassert_always(buffer->getTexCoord1Strider(texcoords2_start));
+    llassert_always(buffer->getIndexStrider(indices_start));
 
     U32 indices_index = 0;
     U32 index_offset = 0;
@@ -1086,7 +1086,7 @@ void LLTerrainPartition::getGeometry(LLSpatialGroup* group)
         gen_terrain_tangents(index_offset, indices_index, vertices, normals, tangents, texcoords, indices);
     }
 
-	buffer->unmapBuffer();
-	mFaceList.clear();
+    buffer->unmapBuffer();
+    mFaceList.clear();
 }
 
diff --git a/indra/newview/llvosurfacepatch.h b/indra/newview/llvosurfacepatch.h
index cde508627c4e91a0af58400190c8d9afe11fad90..e18fe966ca23190ea38d1c95ec27d5bcc9cf1e7f 100644
--- a/indra/newview/llvosurfacepatch.h
+++ b/indra/newview/llvosurfacepatch.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvosurfacepatch.h
  * @brief Description of LLVOSurfacePatch class
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -39,100 +39,100 @@ class LLFace;
 class LLVOSurfacePatch final : public LLStaticViewerObject
 {
 public:
-	static F32 sLODFactor;
+    static F32 sLODFactor;
 
-	enum
-	{
-		VERTEX_DATA_MASK =	(1 << LLVertexBuffer::TYPE_VERTEX) |
-							(1 << LLVertexBuffer::TYPE_NORMAL) |
-							(1 << LLVertexBuffer::TYPE_TEXCOORD0) |
-							(1 << LLVertexBuffer::TYPE_TEXCOORD1)
-	};
+    enum
+    {
+        VERTEX_DATA_MASK =  (1 << LLVertexBuffer::TYPE_VERTEX) |
+                            (1 << LLVertexBuffer::TYPE_NORMAL) |
+                            (1 << LLVertexBuffer::TYPE_TEXCOORD0) |
+                            (1 << LLVertexBuffer::TYPE_TEXCOORD1)
+    };
 
-	LLVOSurfacePatch(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
+    LLVOSurfacePatch(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
 
-	/*virtual*/ void markDead() override;
+    /*virtual*/ void markDead() override;
 
-	virtual U32 getPartitionType() const override;
+    virtual U32 getPartitionType() const override;
 
-	/*virtual*/ LLDrawable* createDrawable(LLPipeline *pipeline) override;
-	/*virtual*/ void		updateGL() override;
-	/*virtual*/ BOOL        updateGeometry(LLDrawable *drawable) override;
-	/*virtual*/ BOOL		updateLOD() override;
-	/*virtual*/ void		updateFaceSize(S32 idx) override;
+    /*virtual*/ LLDrawable* createDrawable(LLPipeline *pipeline) override;
+    /*virtual*/ void        updateGL() override;
+    /*virtual*/ BOOL        updateGeometry(LLDrawable *drawable) override;
+    /*virtual*/ BOOL        updateLOD() override;
+    /*virtual*/ void        updateFaceSize(S32 idx) override;
     void getTerrainGeometry(LLStrider<LLVector3> &verticesp,
                                 LLStrider<LLVector3> &normalsp,
                                 LLStrider<LLVector2> &texCoords0p,
                                 LLStrider<LLVector2> &texCoords1p,
                                 LLStrider<U16> &indicesp);
 
-	/*virtual*/ void updateTextures() override;
-	/*virtual*/ void setPixelAreaAndAngle(LLAgent &agent) override; // generate accurate apparent angle and area
+    /*virtual*/ void updateTextures() override;
+    /*virtual*/ void setPixelAreaAndAngle(LLAgent &agent) override; // generate accurate apparent angle and area
 
-	/*virtual*/ void updateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax) override;
-	/*virtual*/ BOOL isActive() const override; // Whether this object needs to do an idleUpdate.
+    /*virtual*/ void updateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax) override;
+    /*virtual*/ BOOL isActive() const override; // Whether this object needs to do an idleUpdate.
 
-	void setPatch(LLSurfacePatch *patchp);
-	LLSurfacePatch	*getPatch() const		{ return mPatchp; }
+    void setPatch(LLSurfacePatch *patchp);
+    LLSurfacePatch  *getPatch() const       { return mPatchp; }
 
-	void dirtyPatch();
-	void dirtyGeom();
+    void dirtyPatch();
+    void dirtyGeom();
 
-	/*virtual*/ BOOL lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end, 
-										  S32 face = -1,                        // which face to check, -1 = ALL_SIDES
-										  BOOL pick_transparent = FALSE,
-										  BOOL pick_rigged = FALSE,
+    /*virtual*/ BOOL lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
+                                          S32 face = -1,                        // which face to check, -1 = ALL_SIDES
+                                          BOOL pick_transparent = FALSE,
+                                          BOOL pick_rigged = FALSE,
                                           BOOL pick_unselectable = TRUE,
-										  S32* face_hit = NULL,                 // which face was hit
-										  LLVector4a* intersection = NULL,       // return the intersection point
-										  LLVector2* tex_coord = NULL,          // return the texture coordinates of the intersection point
-										  LLVector4a* normal = NULL,             // return the surface normal at the intersection point
-										  LLVector4a* tangent = NULL           // return the surface tangent at the intersection point
-		) override;
-
-	BOOL			mDirtiedPatch;
+                                          S32* face_hit = NULL,                 // which face was hit
+                                          LLVector4a* intersection = NULL,       // return the intersection point
+                                          LLVector2* tex_coord = NULL,          // return the texture coordinates of the intersection point
+                                          LLVector4a* normal = NULL,             // return the surface normal at the intersection point
+                                          LLVector4a* tangent = NULL           // return the surface tangent at the intersection point
+        ) override;
+
+    BOOL            mDirtiedPatch;
 protected:
-	~LLVOSurfacePatch();
-
-	LLFacePool		*mPool;
-	LLFacePool		*getPool();
-	S32				mBaseComp;
-	LLSurfacePatch	*mPatchp;
-	BOOL			mDirtyTexture;
-	BOOL			mDirtyTerrain;
-
-	S32				mLastNorthStride;
-	S32				mLastEastStride;
-	S32				mLastStride;
-	S32				mLastLength;
-
-	void getGeomSizesMain(const S32 stride, S32 &num_vertices, S32 &num_indices);
-	void getGeomSizesNorth(const S32 stride, const S32 north_stride,
-								  S32 &num_vertices, S32 &num_indices);
-	void getGeomSizesEast(const S32 stride, const S32 east_stride,
-								 S32 &num_vertices, S32 &num_indices);
-
-	void updateMainGeometry(LLFace *facep,
-					   LLStrider<LLVector3> &verticesp,
-					   LLStrider<LLVector3> &normalsp,
-					   LLStrider<LLVector2> &texCoords0p,
-					   LLStrider<LLVector2> &texCoords1p,
-					   LLStrider<U16> &indicesp,
-					   U32 &index_offset);
-	void updateNorthGeometry(LLFace *facep,
-					   LLStrider<LLVector3> &verticesp,
-					   LLStrider<LLVector3> &normalsp,
-					   LLStrider<LLVector2> &texCoords0p,
-					   LLStrider<LLVector2> &texCoords1p,
-					   LLStrider<U16> &indicesp,
-					   U32 &index_offset);
-	void updateEastGeometry(LLFace *facep,
-					   LLStrider<LLVector3> &verticesp,
-					   LLStrider<LLVector3> &normalsp,
-					   LLStrider<LLVector2> &texCoords0p,
-					   LLStrider<LLVector2> &texCoords1p,
-					   LLStrider<U16> &indicesp,
-					   U32 &index_offset);
+    ~LLVOSurfacePatch();
+
+    LLFacePool      *mPool;
+    LLFacePool      *getPool();
+    S32             mBaseComp;
+    LLSurfacePatch  *mPatchp;
+    BOOL            mDirtyTexture;
+    BOOL            mDirtyTerrain;
+
+    S32             mLastNorthStride;
+    S32             mLastEastStride;
+    S32             mLastStride;
+    S32             mLastLength;
+
+    void getGeomSizesMain(const S32 stride, S32 &num_vertices, S32 &num_indices);
+    void getGeomSizesNorth(const S32 stride, const S32 north_stride,
+                                  S32 &num_vertices, S32 &num_indices);
+    void getGeomSizesEast(const S32 stride, const S32 east_stride,
+                                 S32 &num_vertices, S32 &num_indices);
+
+    void updateMainGeometry(LLFace *facep,
+                       LLStrider<LLVector3> &verticesp,
+                       LLStrider<LLVector3> &normalsp,
+                       LLStrider<LLVector2> &texCoords0p,
+                       LLStrider<LLVector2> &texCoords1p,
+                       LLStrider<U16> &indicesp,
+                       U32 &index_offset);
+    void updateNorthGeometry(LLFace *facep,
+                       LLStrider<LLVector3> &verticesp,
+                       LLStrider<LLVector3> &normalsp,
+                       LLStrider<LLVector2> &texCoords0p,
+                       LLStrider<LLVector2> &texCoords1p,
+                       LLStrider<U16> &indicesp,
+                       U32 &index_offset);
+    void updateEastGeometry(LLFace *facep,
+                       LLStrider<LLVector3> &verticesp,
+                       LLStrider<LLVector3> &normalsp,
+                       LLStrider<LLVector2> &texCoords0p,
+                       LLStrider<LLVector2> &texCoords1p,
+                       LLStrider<U16> &indicesp,
+                       U32 &index_offset);
 };
 
 #endif // LL_VOSURFACEPATCH_H
diff --git a/indra/newview/llvovolume.cpp b/indra/newview/llvovolume.cpp
index 5f1caf6e192b47092abca4018adc2a0fba83238e..b674e897e36e665ad1b84acacc23596277be8169 100644
--- a/indra/newview/llvovolume.cpp
+++ b/indra/newview/llvovolume.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvovolume.cpp
  * @brief LLVOVolume class implementation
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -103,7 +103,7 @@ U32 JOINT_COUNT_REQUIRED_FOR_FULLRIG = 1;
 BOOL gAnimateTextures = TRUE;
 
 F32 LLVOVolume::sLODFactor = 1.f;
-F32	LLVOVolume::sLODSlopDistanceFactor = 0.5f; //Changing this to zero, effectively disables the LOD transition slop 
+F32 LLVOVolume::sLODSlopDistanceFactor = 0.5f; //Changing this to zero, effectively disables the LOD transition slop
 F32 LLVOVolume::sDistanceFactor = 1.0f;
 S32 LLVOVolume::sNumLODChanges = 0;
 S32 LLVOVolume::mRenderComplexity_last = 0;
@@ -117,233 +117,233 @@ extern BOOL gCubeSnapshot;
 class LLMediaDataClientObjectImpl final : public LLMediaDataClientObject
 {
 public:
-	LLMediaDataClientObjectImpl(LLVOVolume *obj, bool isNew) : mObject(obj), mNew(isNew) 
-	{
-		mObject->addMDCImpl();
-	}
-	~LLMediaDataClientObjectImpl()
-	{
-		mObject->removeMDCImpl();
-	}
-	
-	virtual U8 getMediaDataCount() const 
-		{ return mObject->getNumTEs(); }
-
-	virtual LLSD getMediaDataLLSD(U8 index) const 
-		{
-			LLSD result;
-			LLTextureEntry *te = mObject->getTE(index); 
-			if (NULL != te)
-			{
-				llassert((te->getMediaData() != NULL) == te->hasMedia());
-				if (te->getMediaData() != NULL)
-				{
-					result = te->getMediaData()->asLLSD();
-					// XXX HACK: workaround bug in asLLSD() where whitelist is not set properly
-					// See DEV-41949
-					if (!result.has(LLMediaEntry::WHITELIST_KEY))
-					{
-						result[LLMediaEntry::WHITELIST_KEY] = LLSD::emptyArray();
-					}
-				}
-			}
-			return result;
-		}
-	virtual bool isCurrentMediaUrl(U8 index, const std::string &url) const
-		{
-			LLTextureEntry *te = mObject->getTE(index); 
-			if (te)
-			{
-				if (te->getMediaData())
-				{
-					return (te->getMediaData()->getCurrentURL() == url);
-				}
-			}
-			return url.empty();
-		}
-
-	virtual LLUUID getID() const
-		{ return mObject->getID(); }
-
-	virtual void mediaNavigateBounceBack(U8 index)
-		{ mObject->mediaNavigateBounceBack(index); }
-	
-	virtual bool hasMedia() const
-		{ return mObject->hasMedia(); }
-	
-	virtual void updateObjectMediaData(LLSD const &data, const std::string &version_string) 
-		{ mObject->updateObjectMediaData(data, version_string); }
-	
-	virtual F64 getMediaInterest() const 
-		{ 
-			F64 interest = mObject->getTotalMediaInterest();
-			if (interest < (F64)0.0)
-			{
-				// media interest not valid yet, try pixel area
-				interest = mObject->getPixelArea();
-				// HACK: force recalculation of pixel area if interest is the "magic default" of 1024.
-				if (interest == 1024.f)
-				{
-					const_cast<LLVOVolume*>(static_cast<LLVOVolume*>(mObject))->setPixelAreaAndAngle(gAgent);
-					interest = mObject->getPixelArea();
-				}
-			}
-			return interest; 
-		}
-	
-	virtual bool isInterestingEnough() const
-		{
-			return LLViewerMedia::getInstance()->isInterestingEnough(mObject, getMediaInterest());
-		}
-
-	virtual std::string getCapabilityUrl(const std::string &name) const
-		{ return mObject->getRegion()->getCapability(name); }
-	
-	virtual bool isDead() const
-		{ return mObject->isDead(); }
-	
-	virtual U32 getMediaVersion() const
-		{ return LLTextureEntry::getVersionFromMediaVersionString(mObject->getMediaURL()); }
-	
-	virtual bool isNew() const
-		{ return mNew; }
+    LLMediaDataClientObjectImpl(LLVOVolume *obj, bool isNew) : mObject(obj), mNew(isNew)
+    {
+        mObject->addMDCImpl();
+    }
+    ~LLMediaDataClientObjectImpl()
+    {
+        mObject->removeMDCImpl();
+    }
+
+    virtual U8 getMediaDataCount() const
+        { return mObject->getNumTEs(); }
+
+    virtual LLSD getMediaDataLLSD(U8 index) const
+        {
+            LLSD result;
+            LLTextureEntry *te = mObject->getTE(index);
+            if (NULL != te)
+            {
+                llassert((te->getMediaData() != NULL) == te->hasMedia());
+                if (te->getMediaData() != NULL)
+                {
+                    result = te->getMediaData()->asLLSD();
+                    // XXX HACK: workaround bug in asLLSD() where whitelist is not set properly
+                    // See DEV-41949
+                    if (!result.has(LLMediaEntry::WHITELIST_KEY))
+                    {
+                        result[LLMediaEntry::WHITELIST_KEY] = LLSD::emptyArray();
+                    }
+                }
+            }
+            return result;
+        }
+    virtual bool isCurrentMediaUrl(U8 index, const std::string &url) const
+        {
+            LLTextureEntry *te = mObject->getTE(index);
+            if (te)
+            {
+                if (te->getMediaData())
+                {
+                    return (te->getMediaData()->getCurrentURL() == url);
+                }
+            }
+            return url.empty();
+        }
+
+    virtual LLUUID getID() const
+        { return mObject->getID(); }
+
+    virtual void mediaNavigateBounceBack(U8 index)
+        { mObject->mediaNavigateBounceBack(index); }
+
+    virtual bool hasMedia() const
+        { return mObject->hasMedia(); }
+
+    virtual void updateObjectMediaData(LLSD const &data, const std::string &version_string)
+        { mObject->updateObjectMediaData(data, version_string); }
+
+    virtual F64 getMediaInterest() const
+        {
+            F64 interest = mObject->getTotalMediaInterest();
+            if (interest < (F64)0.0)
+            {
+                // media interest not valid yet, try pixel area
+                interest = mObject->getPixelArea();
+                // HACK: force recalculation of pixel area if interest is the "magic default" of 1024.
+                if (interest == 1024.f)
+                {
+                    const_cast<LLVOVolume*>(static_cast<LLVOVolume*>(mObject))->setPixelAreaAndAngle(gAgent);
+                    interest = mObject->getPixelArea();
+                }
+            }
+            return interest;
+        }
+
+    virtual bool isInterestingEnough() const
+        {
+            return LLViewerMedia::getInstance()->isInterestingEnough(mObject, getMediaInterest());
+        }
+
+    virtual std::string getCapabilityUrl(const std::string &name) const
+        { return mObject->getRegion()->getCapability(name); }
+
+    virtual bool isDead() const
+        { return mObject->isDead(); }
+
+    virtual U32 getMediaVersion() const
+        { return LLTextureEntry::getVersionFromMediaVersionString(mObject->getMediaURL()); }
+
+    virtual bool isNew() const
+        { return mNew; }
 
 private:
-	LLPointer<LLVOVolume> mObject;
-	bool mNew;
+    LLPointer<LLVOVolume> mObject;
+    bool mNew;
 };
 
 
 LLVOVolume::LLVOVolume(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp)
-	: LLViewerObject(id, pcode, regionp),
-	  mVolumeImpl(NULL)
+    : LLViewerObject(id, pcode, regionp),
+      mVolumeImpl(NULL)
 {
-	mTexAnimMode = 0;
-	mRelativeXform.setIdentity();
-	mRelativeXformInvTrans.setIdentity();
+    mTexAnimMode = 0;
+    mRelativeXform.setIdentity();
+    mRelativeXformInvTrans.setIdentity();
 
-	mFaceMappingChanged = FALSE;
-	mLOD = MIN_LOD;
+    mFaceMappingChanged = FALSE;
+    mLOD = MIN_LOD;
     mLODDistance = 0.0f;
     mLODAdjustedDistance = 0.0f;
     mLODRadius = 0.0f;
-	mTextureAnimp = NULL;
-	mVolumeChanged = FALSE;
-	mVObjRadius = LLVector3(1,1,0.5f).length();
-	mNumFaces = 0;
-	mLODChanged = FALSE;
-	mSculptChanged = FALSE;
+    mTextureAnimp = NULL;
+    mVolumeChanged = FALSE;
+    mVObjRadius = LLVector3(1,1,0.5f).length();
+    mNumFaces = 0;
+    mLODChanged = FALSE;
+    mSculptChanged = FALSE;
     mColorChanged = FALSE;
-	mSpotLightPriority = 0.f;
+    mSpotLightPriority = 0.f;
 
     mSkinInfoUnavaliable = false;
-	mSkinInfo = NULL;
+    mSkinInfo = NULL;
 
-	mMediaImplList.resize(getNumTEs());
-	mLastFetchedMediaVersion = -1;
+    mMediaImplList.resize(getNumTEs());
+    mLastFetchedMediaVersion = -1;
     mServerDrawableUpdateCount = 0;
-	memset(&mIndexInTex, 0, sizeof(S32) * LLRender::NUM_VOLUME_TEXTURE_CHANNELS);
-	mMDCImplCount = 0;
-	mLastRiggingInfoLOD = -1;
-	mResetDebugText = false;
+    memset(&mIndexInTex, 0, sizeof(S32) * LLRender::NUM_VOLUME_TEXTURE_CHANNELS);
+    mMDCImplCount = 0;
+    mLastRiggingInfoLOD = -1;
+    mResetDebugText = false;
 }
 
 LLVOVolume::~LLVOVolume()
 {
     LL_PROFILE_ZONE_SCOPED;
-	delete mTextureAnimp;
-	mTextureAnimp = NULL;
-	delete mVolumeImpl;
-	mVolumeImpl = NULL;
-
-	mSkinInfo = nullptr;
-
-	if (mFetchingMesh > 0)
-	{
-		gMeshRepo.unregisterMesh(this, getVolume()->getParams().getSculptID());
-	}
-
-	if(mFetchingSkinInfo > 0)
-	{
-		gMeshRepo.unregisterSkin(this, getVolume()->getParams().getSculptID());
-	}
-
-	if(!mMediaImplList.empty())
-	{
-		for(U32 i = 0 ; i < mMediaImplList.size() ; i++)
-		{
-			if(mMediaImplList[i].notNull())
-			{
-				mMediaImplList[i]->removeObject(this) ;
-			}
-		}
-	}
+    delete mTextureAnimp;
+    mTextureAnimp = NULL;
+    delete mVolumeImpl;
+    mVolumeImpl = NULL;
+
+    mSkinInfo = nullptr;
+
+    if (mFetchingMesh > 0)
+    {
+        gMeshRepo.unregisterMesh(this, getVolume()->getParams().getSculptID());
+    }
+
+    if(mFetchingSkinInfo > 0)
+    {
+        gMeshRepo.unregisterSkin(this, getVolume()->getParams().getSculptID());
+    }
+
+    if(!mMediaImplList.empty())
+    {
+        for(U32 i = 0 ; i < mMediaImplList.size() ; i++)
+        {
+            if(mMediaImplList[i].notNull())
+            {
+                mMediaImplList[i]->removeObject(this) ;
+            }
+        }
+    }
 }
 
 LLVOVolume* LLVOVolume::asVolume()
 {
-	return this;
+    return this;
 }
 
 void LLVOVolume::markDead()
 {
-	if (!mDead)
-	{
+    if (!mDead)
+    {
         LL_PROFILE_ZONE_SCOPED;
         if (getVolume())
         {
             LLSculptIDSize::instance().rem(getVolume()->getParams().getSculptID());
         }
 
-		if(getMDCImplCount() > 0)
-		{
-			LLMediaDataClientObject::ptr_t obj = new LLMediaDataClientObjectImpl(const_cast<LLVOVolume*>(this), false);
-			if (sObjectMediaClient) sObjectMediaClient->removeFromQueue(obj);
-			if (sObjectMediaNavigateClient) sObjectMediaNavigateClient->removeFromQueue(obj);
-		}
-		
-		// Detach all media impls from this object
-		for(U32 i = 0 ; i < mMediaImplList.size() ; i++)
-		{
-			removeMediaImpl(i);
-		}
-
-		if (mSculptTexture.notNull())
-		{
-			mSculptTexture->removeVolume(LLRender::SCULPT_TEX, this);
-		}
-
-		if (mLightTexture.notNull())
-		{
-			mLightTexture->removeVolume(LLRender::LIGHT_TEX, this);
-		}
-        
+        if(getMDCImplCount() > 0)
+        {
+            LLMediaDataClientObject::ptr_t obj = new LLMediaDataClientObjectImpl(const_cast<LLVOVolume*>(this), false);
+            if (sObjectMediaClient) sObjectMediaClient->removeFromQueue(obj);
+            if (sObjectMediaNavigateClient) sObjectMediaNavigateClient->removeFromQueue(obj);
+        }
+
+        // Detach all media impls from this object
+        for(U32 i = 0 ; i < mMediaImplList.size() ; i++)
+        {
+            removeMediaImpl(i);
+        }
+
+        if (mSculptTexture.notNull())
+        {
+            mSculptTexture->removeVolume(LLRender::SCULPT_TEX, this);
+        }
+
+        if (mLightTexture.notNull())
+        {
+            mLightTexture->removeVolume(LLRender::LIGHT_TEX, this);
+        }
+
         if (mIsHeroProbe)
         {
             gPipeline.mHeroProbeManager.unregisterViewerObject(this);
         }
-	}
-	
-	LLViewerObject::markDead();
+    }
+
+    LLViewerObject::markDead();
 }
 
 
 // static
 void LLVOVolume::initClass()
 {
-	// gSavedSettings better be around
-	if (gSavedSettings.getBOOL("PrimMediaMasterEnabled"))
-	{
-		const F32 queue_timer_delay = gSavedSettings.getF32("PrimMediaRequestQueueDelay");
-		const F32 retry_timer_delay = gSavedSettings.getF32("PrimMediaRetryTimerDelay");
-		const U32 max_retries = gSavedSettings.getU32("PrimMediaMaxRetries");
-		const U32 max_sorted_queue_size = gSavedSettings.getU32("PrimMediaMaxSortedQueueSize");
-		const U32 max_round_robin_queue_size = gSavedSettings.getU32("PrimMediaMaxRoundRobinQueueSize");
-		sObjectMediaClient = new LLObjectMediaDataClient(queue_timer_delay, retry_timer_delay, max_retries, 
-														 max_sorted_queue_size, max_round_robin_queue_size);
-		sObjectMediaNavigateClient = new LLObjectMediaNavigateClient(queue_timer_delay, retry_timer_delay, 
-																	 max_retries, max_sorted_queue_size, max_round_robin_queue_size);
-	}
+    // gSavedSettings better be around
+    if (gSavedSettings.getBOOL("PrimMediaMasterEnabled"))
+    {
+        const F32 queue_timer_delay = gSavedSettings.getF32("PrimMediaRequestQueueDelay");
+        const F32 retry_timer_delay = gSavedSettings.getF32("PrimMediaRetryTimerDelay");
+        const U32 max_retries = gSavedSettings.getU32("PrimMediaMaxRetries");
+        const U32 max_sorted_queue_size = gSavedSettings.getU32("PrimMediaMaxSortedQueueSize");
+        const U32 max_round_robin_queue_size = gSavedSettings.getU32("PrimMediaMaxRoundRobinQueueSize");
+        sObjectMediaClient = new LLObjectMediaDataClient(queue_timer_delay, retry_timer_delay, max_retries,
+                                                         max_sorted_queue_size, max_round_robin_queue_size);
+        sObjectMediaNavigateClient = new LLObjectMediaNavigateClient(queue_timer_delay, retry_timer_delay,
+                                                                     max_retries, max_sorted_queue_size, max_round_robin_queue_size);
+    }
 }
 
 // static
@@ -354,67 +354,67 @@ void LLVOVolume::cleanupClass()
 }
 
 U32 LLVOVolume::processUpdateMessage(LLMessageSystem *mesgsys,
-										  void **user_data,
-										  U32 block_num, EObjectUpdateType update_type,
-										  LLDataPacker *dp)
+                                          void **user_data,
+                                          U32 block_num, EObjectUpdateType update_type,
+                                          LLDataPacker *dp)
 {
-	 	
-	LLColor4U color;
-	const S32 teDirtyBits = (TEM_CHANGE_TEXTURE|TEM_CHANGE_COLOR|TEM_CHANGE_MEDIA);
+
+    LLColor4U color;
+    const S32 teDirtyBits = (TEM_CHANGE_TEXTURE|TEM_CHANGE_COLOR|TEM_CHANGE_MEDIA);
     const bool previously_volume_changed = mVolumeChanged;
     const bool previously_face_mapping_changed = mFaceMappingChanged;
     const bool previously_color_changed = mColorChanged;
 
-	// Do base class updates...
-	U32 retval = LLViewerObject::processUpdateMessage(mesgsys, user_data, block_num, update_type, dp);
+    // Do base class updates...
+    U32 retval = LLViewerObject::processUpdateMessage(mesgsys, user_data, block_num, update_type, dp);
 
-	LLUUID sculpt_id;
-	U8 sculpt_type = 0;
-	if (isSculpted())
-	{
-		LLSculptParams *sculpt_params = (LLSculptParams *)getSculptParams();
-		sculpt_id = sculpt_params->getSculptTexture();
-		sculpt_type = sculpt_params->getSculptType();
+    LLUUID sculpt_id;
+    U8 sculpt_type = 0;
+    if (isSculpted())
+    {
+        LLSculptParams *sculpt_params = (LLSculptParams *)getSculptParams();
+        sculpt_id = sculpt_params->getSculptTexture();
+        sculpt_type = sculpt_params->getSculptType();
 
 #ifdef SHOW_DEBUG
         LL_DEBUGS("ObjectUpdate") << "uuid " << mID << " set sculpt_id " << sculpt_id << LL_ENDL;
         dumpStack("ObjectUpdateStack");
 #endif
-	}
-
-	if (!dp)
-	{
-		if (update_type == OUT_FULL)
-		{
-			////////////////////////////////
-			//
-			// Unpack texture animation data
-			//
-			//
-
-			if (mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_TextureAnim))
-			{
-				if (!mTextureAnimp)
-				{
-					mTextureAnimp = new LLViewerTextureAnim(this);
-				}
-				else
-				{
-					if (!(mTextureAnimp->mMode & LLTextureAnim::SMOOTH))
-					{
-						mTextureAnimp->reset();
-					}
-				}
-				mTexAnimMode = 0;
-				
-				mTextureAnimp->unpackTAMessage(mesgsys, block_num);
-			}
-			else
-			{
-				if (mTextureAnimp)
-				{
-					delete mTextureAnimp;
-					mTextureAnimp = NULL;
+    }
+
+    if (!dp)
+    {
+        if (update_type == OUT_FULL)
+        {
+            ////////////////////////////////
+            //
+            // Unpack texture animation data
+            //
+            //
+
+            if (mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_TextureAnim))
+            {
+                if (!mTextureAnimp)
+                {
+                    mTextureAnimp = new LLViewerTextureAnim(this);
+                }
+                else
+                {
+                    if (!(mTextureAnimp->mMode & LLTextureAnim::SMOOTH))
+                    {
+                        mTextureAnimp->reset();
+                    }
+                }
+                mTexAnimMode = 0;
+
+                mTextureAnimp->unpackTAMessage(mesgsys, block_num);
+            }
+            else
+            {
+                if (mTextureAnimp)
+                {
+                    delete mTextureAnimp;
+                    mTextureAnimp = NULL;
 
                     for (S32 i = 0; i < getNumTEs(); i++)
                     {
@@ -427,97 +427,97 @@ U32 LLVOVolume::processUpdateMessage(LLMessageSystem *mesgsys,
                         }
                     }
 
-					gPipeline.markTextured(mDrawable);
-					mFaceMappingChanged = TRUE;
-					mTexAnimMode = 0;
-				}
-			}
-
-			// Unpack volume data
-			LLVolumeParams volume_params;
-			LLVolumeMessage::unpackVolumeParams(&volume_params, mesgsys, _PREHASH_ObjectData, block_num);
-			volume_params.setSculptID(sculpt_id, sculpt_type);
-
-			if (setVolume(volume_params, 0))
-			{
-				markForUpdate();
-			}
-		}
-
-		// Sigh, this needs to be done AFTER the volume is set as well, otherwise bad stuff happens...
-		////////////////////////////
-		//
-		// Unpack texture entry data
-		//
-
-		S32 result = unpackTEMessage(mesgsys, _PREHASH_ObjectData, (S32) block_num);
-		
-		if (result & TEM_CHANGE_MEDIA)
-		{
-			retval |= MEDIA_FLAGS_CHANGED;
-		}
-	}
-	else
-	{
-		if (update_type != OUT_TERSE_IMPROVED)
-		{
-			LLVolumeParams volume_params;
-			BOOL res = LLVolumeMessage::unpackVolumeParams(&volume_params, *dp);
-			if (!res)
-			{
-				LL_WARNS() << "Bogus volume parameters in object " << getID() << LL_ENDL;
-				LL_WARNS() << getRegion()->getOriginGlobal() << LL_ENDL;
-			}
-
-			volume_params.setSculptID(sculpt_id, sculpt_type);
-
-			if (setVolume(volume_params, 0))
-			{
-				markForUpdate();
-			}
-			S32 res2 = unpackTEMessage(*dp);
-			if (TEM_INVALID == res2)
-			{
-				// There's something bogus in the data that we're unpacking.
-				LL_WARNS() << "Flushing cache files" << LL_ENDL;
-
-				if(LLVOCache::instanceExists() && getRegion())
-				{
-					LLVOCache::getInstance()->removeEntry(getRegion()->getHandle()) ;
-				}
-				
-				LL_WARNS() << "Bogus TE data in " << getID() << LL_ENDL;
-			}
-			else 
-			{
-				if (res2 & TEM_CHANGE_MEDIA)
-				{
-					retval |= MEDIA_FLAGS_CHANGED;
-				}
-			}
-
-			U32 value = dp->getPassFlags();
-
-			if (value & 0x40)
-			{
-				if (!mTextureAnimp)
-				{
-					mTextureAnimp = new LLViewerTextureAnim(this);
-				}
-				else
-				{
-					if (!(mTextureAnimp->mMode & LLTextureAnim::SMOOTH))
-					{
-						mTextureAnimp->reset();
-					}
-				}
-				mTexAnimMode = 0;
-				mTextureAnimp->unpackTAMessage(*dp);
-			}
-			else if (mTextureAnimp)
-			{
-				delete mTextureAnimp;
-				mTextureAnimp = NULL;
+                    gPipeline.markTextured(mDrawable);
+                    mFaceMappingChanged = TRUE;
+                    mTexAnimMode = 0;
+                }
+            }
+
+            // Unpack volume data
+            LLVolumeParams volume_params;
+            LLVolumeMessage::unpackVolumeParams(&volume_params, mesgsys, _PREHASH_ObjectData, block_num);
+            volume_params.setSculptID(sculpt_id, sculpt_type);
+
+            if (setVolume(volume_params, 0))
+            {
+                markForUpdate();
+            }
+        }
+
+        // Sigh, this needs to be done AFTER the volume is set as well, otherwise bad stuff happens...
+        ////////////////////////////
+        //
+        // Unpack texture entry data
+        //
+
+        S32 result = unpackTEMessage(mesgsys, _PREHASH_ObjectData, (S32) block_num);
+
+        if (result & TEM_CHANGE_MEDIA)
+        {
+            retval |= MEDIA_FLAGS_CHANGED;
+        }
+    }
+    else
+    {
+        if (update_type != OUT_TERSE_IMPROVED)
+        {
+            LLVolumeParams volume_params;
+            BOOL res = LLVolumeMessage::unpackVolumeParams(&volume_params, *dp);
+            if (!res)
+            {
+                LL_WARNS() << "Bogus volume parameters in object " << getID() << LL_ENDL;
+                LL_WARNS() << getRegion()->getOriginGlobal() << LL_ENDL;
+            }
+
+            volume_params.setSculptID(sculpt_id, sculpt_type);
+
+            if (setVolume(volume_params, 0))
+            {
+                markForUpdate();
+            }
+            S32 res2 = unpackTEMessage(*dp);
+            if (TEM_INVALID == res2)
+            {
+                // There's something bogus in the data that we're unpacking.
+                LL_WARNS() << "Flushing cache files" << LL_ENDL;
+
+                if(LLVOCache::instanceExists() && getRegion())
+                {
+                    LLVOCache::getInstance()->removeEntry(getRegion()->getHandle()) ;
+                }
+
+                LL_WARNS() << "Bogus TE data in " << getID() << LL_ENDL;
+            }
+            else
+            {
+                if (res2 & TEM_CHANGE_MEDIA)
+                {
+                    retval |= MEDIA_FLAGS_CHANGED;
+                }
+            }
+
+            U32 value = dp->getPassFlags();
+
+            if (value & 0x40)
+            {
+                if (!mTextureAnimp)
+                {
+                    mTextureAnimp = new LLViewerTextureAnim(this);
+                }
+                else
+                {
+                    if (!(mTextureAnimp->mMode & LLTextureAnim::SMOOTH))
+                    {
+                        mTextureAnimp->reset();
+                    }
+                }
+                mTexAnimMode = 0;
+                mTextureAnimp->unpackTAMessage(*dp);
+            }
+            else if (mTextureAnimp)
+            {
+                delete mTextureAnimp;
+                mTextureAnimp = NULL;
 
                 for (S32 i = 0; i < getNumTEs(); i++)
                 {
@@ -530,63 +530,63 @@ U32 LLVOVolume::processUpdateMessage(LLMessageSystem *mesgsys,
                     }
                 }
 
-				gPipeline.markTextured(mDrawable);
-				mFaceMappingChanged = TRUE;
-				mTexAnimMode = 0;
-			}
-
-			if (value & 0x400)
-			{ //particle system (new)
-				unpackParticleSource(*dp, mOwnerID, false);
-			}
-		}
-		else
-		{
-			S32 texture_length = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_TextureEntry);
-			if (texture_length)
-			{
-				U8							tdpbuffer[1024];
-				LLDataPackerBinaryBuffer	tdp(tdpbuffer, 1024);
-				mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextureEntry, tdpbuffer, 0, block_num, 1024);
-				S32 result = unpackTEMessage(tdp);
-				if (result & teDirtyBits)
-				{
-					if (mDrawable)
+                gPipeline.markTextured(mDrawable);
+                mFaceMappingChanged = TRUE;
+                mTexAnimMode = 0;
+            }
+
+            if (value & 0x400)
+            { //particle system (new)
+                unpackParticleSource(*dp, mOwnerID, false);
+            }
+        }
+        else
+        {
+            S32 texture_length = mesgsys->getSizeFast(_PREHASH_ObjectData, block_num, _PREHASH_TextureEntry);
+            if (texture_length)
+            {
+                U8                          tdpbuffer[1024];
+                LLDataPackerBinaryBuffer    tdp(tdpbuffer, 1024);
+                mesgsys->getBinaryDataFast(_PREHASH_ObjectData, _PREHASH_TextureEntry, tdpbuffer, 0, block_num, 1024);
+                S32 result = unpackTEMessage(tdp);
+                if (result & teDirtyBits)
+                {
+                    if (mDrawable)
                     { //on the fly TE updates break batches, isolate in octree
                         shrinkWrap();
                     }
-				}
-				if (result & TEM_CHANGE_MEDIA)
-				{
-					retval |= MEDIA_FLAGS_CHANGED;
-				}
-			}
-		}
-	}
-
-	// OS returns a zero. Don't request MediaData where MOAP isn't supported
-	if (retval != 0 && retval & (MEDIA_URL_REMOVED | MEDIA_URL_ADDED | MEDIA_URL_UPDATED | MEDIA_FLAGS_CHANGED)) 
-	{
-		// If only the media URL changed, and it isn't a media version URL,
-		// ignore it
-		if ( ! ( retval & (MEDIA_URL_ADDED | MEDIA_URL_UPDATED) &&
-				 mMedia && ! mMedia->mMediaURL.empty() &&
-				 ! LLTextureEntry::isMediaVersionString(mMedia->mMediaURL) ) )
-		{
-			// If the media changed at all, request new media data
+                }
+                if (result & TEM_CHANGE_MEDIA)
+                {
+                    retval |= MEDIA_FLAGS_CHANGED;
+                }
+            }
+        }
+    }
+
+    // OS returns a zero. Don't request MediaData where MOAP isn't supported
+    if (retval != 0 && retval & (MEDIA_URL_REMOVED | MEDIA_URL_ADDED | MEDIA_URL_UPDATED | MEDIA_FLAGS_CHANGED))
+    {
+        // If only the media URL changed, and it isn't a media version URL,
+        // ignore it
+        if ( ! ( retval & (MEDIA_URL_ADDED | MEDIA_URL_UPDATED) &&
+                 mMedia && ! mMedia->mMediaURL.empty() &&
+                 ! LLTextureEntry::isMediaVersionString(mMedia->mMediaURL) ) )
+        {
+            // If the media changed at all, request new media data
 #ifdef SHOW_DEBUG
-			LL_DEBUGS("MediaOnAPrim") << "Media update: " << getID() << ": retval=" << retval << " Media URL: " <<
+            LL_DEBUGS("MediaOnAPrim") << "Media update: " << getID() << ": retval=" << retval << " Media URL: " <<
                 ((mMedia) ?  mMedia->mMediaURL : std::string("")) << LL_ENDL;
 #endif
-			requestMediaDataUpdate(retval & MEDIA_FLAGS_CHANGED);
-		}
+            requestMediaDataUpdate(retval & MEDIA_FLAGS_CHANGED);
+        }
         else {
             LL_INFOS("MediaOnAPrim") << "Ignoring media update for: " << getID() << " Media URL: " <<
                 ((mMedia) ?  mMedia->mMediaURL : std::string("")) << LL_ENDL;
         }
-	}
-	// ...and clean up any media impls
-	cleanUpMediaImpls();
+    }
+    // ...and clean up any media impls
+    cleanUpMediaImpls();
 
     if ((
             (mVolumeChanged && !previously_volume_changed) ||
@@ -597,7 +597,7 @@ U32 LLVOVolume::processUpdateMessage(LLMessageSystem *mesgsys,
         onDrawableUpdateFromServer();
     }
 
-	return retval;
+    return retval;
 }
 
 // Called when a volume, material, etc is updated by the server, possibly by a
@@ -617,521 +617,521 @@ void LLVOVolume::onDrawableUpdateFromServer()
 // ALCHMERGE
 void LLVOVolume::animateTextures()
 {
-	if (!mDead)
-	{
+    if (!mDead)
+    {
         shrinkWrap();
-		F32 off_s = 0.f, off_t = 0.f, scale_s = 1.f, scale_t = 1.f, rot = 0.f;
-		S32 result = mTextureAnimp->animateTextures(off_s, off_t, scale_s, scale_t, rot);
-	
-		if (result)
-		{
-			if (!mTexAnimMode)
-			{
-				mFaceMappingChanged = TRUE;
-				gPipeline.markTextured(mDrawable);
-			}
-			mTexAnimMode = result | mTextureAnimp->mMode;
-				
-			S32 start=0, end=mDrawable->getNumFaces()-1;
-			if (mTextureAnimp->mFace >= 0 && mTextureAnimp->mFace <= end)
-			{
-				start = end = mTextureAnimp->mFace;
-			}
-		
-			for (S32 i = start; i <= end; i++)
-			{
-				LLFace* facep = mDrawable->getFace(i);
-				if (!facep) continue;
-				if(facep->getVirtualSize() <= MIN_TEX_ANIM_SIZE && facep->mTextureMatrix) continue;
-
-				const LLTextureEntry* te = facep->getTextureEntry();
-			
-				if (!te)
-				{
-					continue;
-				}
-		
-				if (!(result & LLViewerTextureAnim::ROTATE))
-				{
-					te->getRotation(&rot);
-				}
-				if (!(result & LLViewerTextureAnim::TRANSLATE))
-				{
-					te->getOffset(&off_s,&off_t);
-				}			
-				if (!(result & LLViewerTextureAnim::SCALE))
-				{
-					te->getScale(&scale_s, &scale_t);
-				}
-
-				if (!facep->mTextureMatrix)
-				{
-					facep->mTextureMatrix = new LLMatrix4a();
-				}
-
-				LLMatrix4a& tex_mat = *facep->mTextureMatrix;
-				tex_mat.setIdentity();
-				LLVector3 trans ;
-				{
-					trans.set(LLVector3(off_s + 0.5f, off_t + 0.5f, 0.f));
-					tex_mat.setTranslate_affine(LLVector3(-0.5f, -0.5f, 0.f));
-				}
-
-				LLVector3 scale(scale_s, scale_t, 1.f);
-
-				tex_mat.setMul(ALGLMath::genRot(rot * RAD_TO_DEG, 0.f, 0.f, -1.f), tex_mat);	//left mul
-
-				LLMatrix4a scale_mat;
-				scale_mat.setIdentity();
-				scale_mat.applyScale_affine(scale);
-				tex_mat.setMul(scale_mat, tex_mat);	//left mul
-
-				tex_mat.translate_affine(trans);
-
-			}
-		}
-		else
-		{
-			if (mTexAnimMode && mTextureAnimp->mRate == 0)
-			{
-				U8 start, count;
-
-				if (mTextureAnimp->mFace == -1)
-				{
-					start = 0;
-					count = getNumTEs();
-				}
-				else
-				{
-					start = (U8) mTextureAnimp->mFace;
-					count = 1;
-				}
-
-				for (S32 i = start; i < start + count; i++)
-				{
-					if (mTexAnimMode & LLViewerTextureAnim::TRANSLATE)
-					{
-						setTEOffset(i, mTextureAnimp->mOffS, mTextureAnimp->mOffT);				
-					}
-					if (mTexAnimMode & LLViewerTextureAnim::SCALE)
-					{
-						setTEScale(i, mTextureAnimp->mScaleS, mTextureAnimp->mScaleT);	
-					}
-					if (mTexAnimMode & LLViewerTextureAnim::ROTATE)
-					{
-						setTERotation(i, mTextureAnimp->mRot);
-					}
-				}
-
-				gPipeline.markTextured(mDrawable);
-				mFaceMappingChanged = TRUE;
-				mTexAnimMode = 0;
-			}
-		}
-	}
-}
-
-void LLVOVolume::updateTextures()
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
-    updateTextureVirtualSize();
-}
-
-BOOL LLVOVolume::isVisible() const 
-{
-	if(mDrawable.notNull() && mDrawable->isVisible())
-	{
-		return TRUE ;
-	}
+        F32 off_s = 0.f, off_t = 0.f, scale_s = 1.f, scale_t = 1.f, rot = 0.f;
+        S32 result = mTextureAnimp->animateTextures(off_s, off_t, scale_s, scale_t, rot);
 
-	if(isAttachment())
-	{
-		LLViewerObject* objp = (LLViewerObject*)getParent() ;
-		while(objp && !objp->isAvatar())
-		{
-			objp = (LLViewerObject*)objp->getParent() ;
-		}
+        if (result)
+        {
+            if (!mTexAnimMode)
+            {
+                mFaceMappingChanged = TRUE;
+                gPipeline.markTextured(mDrawable);
+            }
+            mTexAnimMode = result | mTextureAnimp->mMode;
 
-		return objp && objp->mDrawable.notNull() && objp->mDrawable->isVisible() ;
-	}
+            S32 start=0, end=mDrawable->getNumFaces()-1;
+            if (mTextureAnimp->mFace >= 0 && mTextureAnimp->mFace <= end)
+            {
+                start = end = mTextureAnimp->mFace;
+            }
 
-	return FALSE ;
-}
+            for (S32 i = start; i <= end; i++)
+            {
+                LLFace* facep = mDrawable->getFace(i);
+                if (!facep) continue;
+                if(facep->getVirtualSize() <= MIN_TEX_ANIM_SIZE && facep->mTextureMatrix) continue;
 
-void LLVOVolume::updateTextureVirtualSize(bool forced)
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	// Update the pixel area of all faces
+                const LLTextureEntry* te = facep->getTextureEntry();
 
-    if (mDrawable.isNull() || gCubeSnapshot)
-    {
-        return;
-    }
+                if (!te)
+                {
+                    continue;
+                }
 
-	if(!forced)
-	{
-		if(!isVisible())
-		{ //don't load textures for non-visible faces
-			const S32 num_faces = mDrawable->getNumFaces();
-			for (S32 i = 0; i < num_faces; i++)
-			{
-				LLFace* face = mDrawable->getFace(i);
-				if (face)
-				{
-					face->setPixelArea(0.f); 
-					face->setVirtualSize(0.f);
-				}
-			}
-
-			return ;
-		}
-
-		if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SIMPLE))
-		{
-			return;
-		}
-	}
-
-	static LLCachedControl<bool> dont_load_textures(gSavedSettings,"TextureDisable", false);
-		
-	if (dont_load_textures || LLAppViewer::getTextureFetch()->mDebugPause) // || !mDrawable->isVisible())
-	{
-		return;
-	}
-
-	mTextureUpdateTimer.reset();
-	
-	F32 old_area = mPixelArea;
-	mPixelArea = 0.f;
-
-	const S32 num_faces = mDrawable->getNumFaces();
-	F32 min_vsize=999999999.f, max_vsize=0.f;
-	LLViewerCamera* camera = LLViewerCamera::getInstance();
-    std::stringstream debug_text;
-	for (S32 i = 0; i < num_faces; i++)
-	{
-		LLFace* face = mDrawable->getFace(i);
-		if (!face) continue;
-		const LLTextureEntry *te = face->getTextureEntry();
-		LLViewerTexture *imagep = face->getTexture();
-		if (!imagep || !te ||			
-			face->mExtents[0].equals3(face->mExtents[1]))
-		{
-			continue;
-		}
-
-		F32 vsize;
-		F32 old_size = face->getVirtualSize();
-
-		if (isHUDAttachment())
-		{
-			F32 area = (F32) camera->getScreenPixelArea();
-			vsize = area;
-			imagep->setBoostLevel(LLGLTexture::BOOST_HUD);
- 			face->setPixelArea(area); // treat as full screen
-			face->setVirtualSize(vsize);
-		}
-		else
-		{
-			vsize = face->getTextureVirtualSize();
-		}
-
-		mPixelArea = llmax(mPixelArea, face->getPixelArea());
+                if (!(result & LLViewerTextureAnim::ROTATE))
+                {
+                    te->getRotation(&rot);
+                }
+                if (!(result & LLViewerTextureAnim::TRANSLATE))
+                {
+                    te->getOffset(&off_s,&off_t);
+                }
+                if (!(result & LLViewerTextureAnim::SCALE))
+                {
+                    te->getScale(&scale_s, &scale_t);
+                }
 
-        // if the face has gotten small enough to turn off texture animation and texture
-        // animation is running, rebuild the render batch for this face to turn off
-        // texture animation
-		if (face->mTextureMatrix != NULL)
-		{
-			if ((vsize < MIN_TEX_ANIM_SIZE && old_size > MIN_TEX_ANIM_SIZE) ||
-				(vsize > MIN_TEX_ANIM_SIZE && old_size < MIN_TEX_ANIM_SIZE))
-			{
-				gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
-			}
-		}
-				
-		if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY))
-		{
-			LLViewerFetchedTexture* img = LLViewerTextureManager::staticCastToFetchedTexture(imagep) ;
-			if(img)
-			{
-                debug_text << img->getDiscardLevel() << ":" << img->getDesiredDiscardLevel() << ":" << img->getWidth() << ":" << (S32) sqrtf(vsize) << ":" << (S32) sqrtf(img->getMaxVirtualSize()) << "\n";
-				/*F32 pri = img->getDecodePriority();
-				pri = llmax(pri, 0.0f);
-				if (pri < min_vsize) min_vsize = pri;
-				if (pri > max_vsize) max_vsize = pri;*/
-			}
-		}
-		else if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_FACE_AREA))
-		{
-			F32 pri = mPixelArea;
-			if (pri < min_vsize) min_vsize = pri;
-			if (pri > max_vsize) max_vsize = pri;
-		}	
-	}
-	
-	if (isSculpted())
-	{
-        updateSculptTexture();
+                if (!facep->mTextureMatrix)
+                {
+                    facep->mTextureMatrix = new LLMatrix4a();
+                }
 
-		if (mSculptTexture.notNull())
-		{
-			mSculptTexture->setBoostLevel(llmax((S32)mSculptTexture->getBoostLevel(),
-												(S32)LLGLTexture::BOOST_SCULPTED));
-			mSculptTexture->setForSculpt() ;
-			
-			if(!mSculptTexture->isCachedRawImageReady())
-			{
-				S32 lod = llmin(mLOD, 3);
-				F32 lodf = ((F32)(lod + 1.0f)/4.f);
-				F32 tex_size = lodf * LLViewerTexture::sMaxSculptRez ;
-				mSculptTexture->addTextureStats(2.f * tex_size * tex_size, FALSE);
-			}
-	
-			S32 texture_discard = mSculptTexture->getCachedRawImageLevel(); //try to match the texture
-			S32 current_discard = getVolume() ? getVolume()->getSculptLevel() : -2 ;
-
-			if (texture_discard >= 0 && //texture has some data available
-				(texture_discard < current_discard || //texture has more data than last rebuild
-				current_discard < 0)) //no previous rebuild
-			{
-				gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
-				mSculptChanged = TRUE;
-			}
-
-			if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SCULPTED))
-			{
-				setDebugText(llformat("T%d C%d V%d\n%dx%d",
-										  texture_discard, current_discard, getVolume()->getSculptLevel(),
-										  mSculptTexture->getHeight(), mSculptTexture->getWidth()));
-			}
-		}
-
-	}
-
-	if (getLightTextureID().notNull())
-	{
-		LLLightImageParams* params = (LLLightImageParams*) getLightImageParams();
-		LLUUID id = params->getLightTexture();
-		mLightTexture = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE);
-		if (mLightTexture.notNull())
-		{
-			F32 rad = getLightRadius();
-			mLightTexture->addTextureStats(gPipeline.calcPixelArea(getPositionAgent(), 
-																	LLVector3(rad,rad,rad),
-																	*camera));
-		}	
-	}
-	
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_AREA))
-	{
-		setDebugText(llformat("%.0f:%.0f", (F32) sqrt(min_vsize),(F32) sqrt(max_vsize)));
-	}
- 	else if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY))
- 	{
- 		//setDebugText(llformat("%.0f:%.0f", (F32) sqrt(min_vsize),(F32) sqrt(max_vsize)));
-        setDebugText(debug_text.str());
- 	}
-	else if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_FACE_AREA))
-	{
-		setDebugText(llformat("%.0f:%.0f", (F32) sqrt(min_vsize),(F32) sqrt(max_vsize)));
-	}
+                LLMatrix4a& tex_mat = *facep->mTextureMatrix;
+                tex_mat.setIdentity();
+                LLVector3 trans ;
+                {
+                    trans.set(LLVector3(off_s + 0.5f, off_t + 0.5f, 0.f));
+                    tex_mat.setTranslate_affine(LLVector3(-0.5f, -0.5f, 0.f));
+                }
 
-	if (mPixelArea == 0)
-	{ //flexi phasing issues make this happen
-		mPixelArea = old_area;
-	}
-}
+                LLVector3 scale(scale_s, scale_t, 1.f);
 
-BOOL LLVOVolume::isActive() const
-{
-	return !mStatic;
-}
+                tex_mat.setMul(ALGLMath::genRot(rot * RAD_TO_DEG, 0.f, 0.f, -1.f), tex_mat);    //left mul
 
-BOOL LLVOVolume::setMaterial(const U8 material)
-{
-	BOOL res = LLViewerObject::setMaterial(material);
-	
-	return res;
-}
+                LLMatrix4a scale_mat;
+                scale_mat.setIdentity();
+                scale_mat.applyScale_affine(scale);
+                tex_mat.setMul(scale_mat, tex_mat); //left mul
 
-void LLVOVolume::setTexture(const S32 face)
-{
-	llassert(face < getNumTEs());
-	gGL.getTexUnit(0)->bind(getTEImage(face));
-}
+                tex_mat.translate_affine(trans);
 
-void LLVOVolume::setScale(const LLVector3 &scale, BOOL damped)
-{
-	if (scale != getScale())
-	{
-		// store local radius
-		LLViewerObject::setScale(scale);
+            }
+        }
+        else
+        {
+            if (mTexAnimMode && mTextureAnimp->mRate == 0)
+            {
+                U8 start, count;
 
-		if (mVolumeImpl)
-		{
-			mVolumeImpl->onSetScale(scale, damped);
-		}
-		
-		updateRadius();
+                if (mTextureAnimp->mFace == -1)
+                {
+                    start = 0;
+                    count = getNumTEs();
+                }
+                else
+                {
+                    start = (U8) mTextureAnimp->mFace;
+                    count = 1;
+                }
 
-		//since drawable transforms do not include scale, changing volume scale
-		//requires an immediate rebuild of volume verts.
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_POSITION);
+                for (S32 i = start; i < start + count; i++)
+                {
+                    if (mTexAnimMode & LLViewerTextureAnim::TRANSLATE)
+                    {
+                        setTEOffset(i, mTextureAnimp->mOffS, mTextureAnimp->mOffT);
+                    }
+                    if (mTexAnimMode & LLViewerTextureAnim::SCALE)
+                    {
+                        setTEScale(i, mTextureAnimp->mScaleS, mTextureAnimp->mScaleT);
+                    }
+                    if (mTexAnimMode & LLViewerTextureAnim::ROTATE)
+                    {
+                        setTERotation(i, mTextureAnimp->mRot);
+                    }
+                }
 
-        if (mDrawable)
-        {
-            shrinkWrap();
+                gPipeline.markTextured(mDrawable);
+                mFaceMappingChanged = TRUE;
+                mTexAnimMode = 0;
+            }
         }
-	}
+    }
 }
 
-LLFace* LLVOVolume::addFace(S32 f)
+void LLVOVolume::updateTextures()
 {
-	const LLTextureEntry* te = getTE(f);
-	LLViewerTexture* imagep = getTEImage(f);
-	if (te && te->getMaterialParams().notNull())
-	{
-		LLViewerTexture* normalp = getTENormalMap(f);
-		LLViewerTexture* specularp = getTESpecularMap(f);
-		return mDrawable->addFace(te, imagep, normalp, specularp);
-	}
-	return mDrawable->addFace(te, imagep);
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_TEXTURE;
+    updateTextureVirtualSize();
 }
 
-LLDrawable *LLVOVolume::createDrawable(LLPipeline *pipeline)
+BOOL LLVOVolume::isVisible() const
 {
-	pipeline->allocDrawable(this);
-		
-	mDrawable->setRenderType(LLPipeline::RENDER_TYPE_VOLUME);
-
-	S32 max_tes_to_set = getNumTEs();
-	for (S32 i = 0; i < max_tes_to_set; i++)
-	{
-		addFace(i);
-	}
-	mNumFaces = max_tes_to_set;
-
-	if (isAttachment())
-	{
-		mDrawable->makeActive();
-	}
-
-	if (getIsLight())
-	{
-		// Add it to the pipeline mLightSet
-		gPipeline.setLight(mDrawable, TRUE);
-	}
+    if(mDrawable.notNull() && mDrawable->isVisible())
+    {
+        return TRUE ;
+    }
 
-    if (isReflectionProbe())
+    if(isAttachment())
     {
-        updateReflectionProbePtr();
+        LLViewerObject* objp = (LLViewerObject*)getParent() ;
+        while(objp && !objp->isAvatar())
+        {
+            objp = (LLViewerObject*)objp->getParent() ;
+        }
+
+        return objp && objp->mDrawable.notNull() && objp->mDrawable->isVisible() ;
     }
-    
-	updateRadius();
-	bool force_update = true; // avoid non-alpha mDistance update being optimized away
-	mDrawable->updateDistance(LLViewerCamera::instance(), force_update);
 
-	return mDrawable;
+    return FALSE ;
 }
 
-BOOL LLVOVolume::setVolume(const LLVolumeParams &params_in, const S32 detail, bool unique_volume)
+void LLVOVolume::updateTextureVirtualSize(bool forced)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	LLVolumeParams volume_params = params_in;
-
-	S32 last_lod = mVolumep.notNull() ? LLVolumeLODGroup::getVolumeDetailFromScale(mVolumep->getDetail()) : -1;
-	S32 lod = mLOD;
-
-	BOOL is404 = FALSE;
-	
-	if (isSculpted())
-	{
-		// if it's a mesh
-		if ((volume_params.getSculptType() & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
-		{ //meshes might not have all LODs, get the force detail to best existing LOD
-			if (NO_LOD != lod)
-			{
-				lod = gMeshRepo.getActualMeshLOD(volume_params, lod);
-				if (lod == -1)
-				{
-					is404 = TRUE;
-					lod = 0;
-				}
-			}
-		}
-	}
-
-	// Check if we need to change implementations
-	bool is_flexible = (volume_params.getPathParams().getCurveType() == LL_PCODE_PATH_FLEXIBLE);
-	if (is_flexible)
-	{
-		setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, TRUE, false);
-		if (!mVolumeImpl)
-		{
-			LLFlexibleObjectData* data = (LLFlexibleObjectData*)getFlexibleObjectData();
-			mVolumeImpl = new LLVolumeImplFlexible(this, data);
-		}
-	}
-	else
-	{
-		// Mark the parameter not in use
-		setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, FALSE, false);
-		if (mVolumeImpl)
-		{
-			delete mVolumeImpl;
-			mVolumeImpl = NULL;
-			if (mDrawable.notNull())
-			{
-				// Undo the damage we did to this matrix
-				mDrawable->updateXform(FALSE);
-			}
-		}
-	}
-	
-	if (is404)
-	{
-		setIcon(LLViewerTextureManager::getFetchedTextureFromFile("icons/Inv_Mesh.png", FTT_LOCAL_FILE, TRUE, LLGLTexture::BOOST_UI));
-		//render prim proxy when mesh loading attempts give up
-		volume_params.setSculptID(LLUUID::null, LL_SCULPT_TYPE_NONE);
-
-	}
-
-	if ((LLPrimitive::setVolume(volume_params, lod, (mVolumeImpl && mVolumeImpl->isVolumeUnique()))) || mSculptChanged)
-	{
-		mFaceMappingChanged = TRUE;
-		
-		if (mVolumeImpl)
-		{
-			mVolumeImpl->onSetVolume(volume_params, mLOD);
-		}
-	
-		updateSculptTexture();
-
-		if (isSculpted())
-		{
-			// if it's a mesh
-			if ((volume_params.getSculptType() & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
-			{
-				if (mSkinInfo && mSkinInfo->mMeshID != volume_params.getSculptID())
-				{
-					mSkinInfo = NULL;
-					mSkinInfoUnavaliable = false;
-				}
-
-				if (!getVolume()->isMeshAssetLoaded())
-				{ 
-					//load request not yet issued, request pipeline load this mesh
-					S32 available_lod = gMeshRepo.loadMesh(this, volume_params, lod, last_lod);
-					if (available_lod != lod)
-					{
-						LLPrimitive::setVolume(volume_params, available_lod);
-					}
-				}
-				
-				if (!mSkinInfo && !mSkinInfoUnavaliable)
-				{
-                    LLUUID mesh_id = volume_params.getSculptID();
+    // Update the pixel area of all faces
+
+    if (mDrawable.isNull() || gCubeSnapshot)
+    {
+        return;
+    }
+
+    if(!forced)
+    {
+        if(!isVisible())
+        { //don't load textures for non-visible faces
+            const S32 num_faces = mDrawable->getNumFaces();
+            for (S32 i = 0; i < num_faces; i++)
+            {
+                LLFace* face = mDrawable->getFace(i);
+                if (face)
+                {
+                    face->setPixelArea(0.f);
+                    face->setVirtualSize(0.f);
+                }
+            }
+
+            return ;
+        }
+
+        if (!gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_SIMPLE))
+        {
+            return;
+        }
+    }
+
+    static LLCachedControl<bool> dont_load_textures(gSavedSettings,"TextureDisable", false);
+
+    if (dont_load_textures || LLAppViewer::getTextureFetch()->mDebugPause) // || !mDrawable->isVisible())
+    {
+        return;
+    }
+
+    mTextureUpdateTimer.reset();
+
+    F32 old_area = mPixelArea;
+    mPixelArea = 0.f;
+
+    const S32 num_faces = mDrawable->getNumFaces();
+    F32 min_vsize=999999999.f, max_vsize=0.f;
+    LLViewerCamera* camera = LLViewerCamera::getInstance();
+    std::stringstream debug_text;
+    for (S32 i = 0; i < num_faces; i++)
+    {
+        LLFace* face = mDrawable->getFace(i);
+        if (!face) continue;
+        const LLTextureEntry *te = face->getTextureEntry();
+        LLViewerTexture *imagep = face->getTexture();
+        if (!imagep || !te ||
+            face->mExtents[0].equals3(face->mExtents[1]))
+        {
+            continue;
+        }
+
+        F32 vsize;
+        F32 old_size = face->getVirtualSize();
+
+        if (isHUDAttachment())
+        {
+            F32 area = (F32) camera->getScreenPixelArea();
+            vsize = area;
+            imagep->setBoostLevel(LLGLTexture::BOOST_HUD);
+            face->setPixelArea(area); // treat as full screen
+            face->setVirtualSize(vsize);
+        }
+        else
+        {
+            vsize = face->getTextureVirtualSize();
+        }
+
+        mPixelArea = llmax(mPixelArea, face->getPixelArea());
+
+        // if the face has gotten small enough to turn off texture animation and texture
+        // animation is running, rebuild the render batch for this face to turn off
+        // texture animation
+        if (face->mTextureMatrix != NULL)
+        {
+            if ((vsize < MIN_TEX_ANIM_SIZE && old_size > MIN_TEX_ANIM_SIZE) ||
+                (vsize > MIN_TEX_ANIM_SIZE && old_size < MIN_TEX_ANIM_SIZE))
+            {
+                gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_TCOORD);
+            }
+        }
+
+        if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY))
+        {
+            LLViewerFetchedTexture* img = LLViewerTextureManager::staticCastToFetchedTexture(imagep) ;
+            if(img)
+            {
+                debug_text << img->getDiscardLevel() << ":" << img->getDesiredDiscardLevel() << ":" << img->getWidth() << ":" << (S32) sqrtf(vsize) << ":" << (S32) sqrtf(img->getMaxVirtualSize()) << "\n";
+                /*F32 pri = img->getDecodePriority();
+                pri = llmax(pri, 0.0f);
+                if (pri < min_vsize) min_vsize = pri;
+                if (pri > max_vsize) max_vsize = pri;*/
+            }
+        }
+        else if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_FACE_AREA))
+        {
+            F32 pri = mPixelArea;
+            if (pri < min_vsize) min_vsize = pri;
+            if (pri > max_vsize) max_vsize = pri;
+        }
+    }
+
+    if (isSculpted())
+    {
+        updateSculptTexture();
+
+        if (mSculptTexture.notNull())
+        {
+            mSculptTexture->setBoostLevel(llmax((S32)mSculptTexture->getBoostLevel(),
+                                                (S32)LLGLTexture::BOOST_SCULPTED));
+            mSculptTexture->setForSculpt() ;
+
+            if(!mSculptTexture->isCachedRawImageReady())
+            {
+                S32 lod = llmin(mLOD, 3);
+                F32 lodf = ((F32)(lod + 1.0f)/4.f);
+                F32 tex_size = lodf * LLViewerTexture::sMaxSculptRez ;
+                mSculptTexture->addTextureStats(2.f * tex_size * tex_size, FALSE);
+            }
+
+            S32 texture_discard = mSculptTexture->getCachedRawImageLevel(); //try to match the texture
+            S32 current_discard = getVolume() ? getVolume()->getSculptLevel() : -2 ;
+
+            if (texture_discard >= 0 && //texture has some data available
+                (texture_discard < current_discard || //texture has more data than last rebuild
+                current_discard < 0)) //no previous rebuild
+            {
+                gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
+                mSculptChanged = TRUE;
+            }
+
+            if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SCULPTED))
+            {
+                setDebugText(llformat("T%d C%d V%d\n%dx%d",
+                                          texture_discard, current_discard, getVolume()->getSculptLevel(),
+                                          mSculptTexture->getHeight(), mSculptTexture->getWidth()));
+            }
+        }
+
+    }
+
+    if (getLightTextureID().notNull())
+    {
+        LLLightImageParams* params = (LLLightImageParams*) getLightImageParams();
+        LLUUID id = params->getLightTexture();
+        mLightTexture = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE);
+        if (mLightTexture.notNull())
+        {
+            F32 rad = getLightRadius();
+            mLightTexture->addTextureStats(gPipeline.calcPixelArea(getPositionAgent(),
+                                                                    LLVector3(rad,rad,rad),
+                                                                    *camera));
+        }
+    }
+
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_AREA))
+    {
+        setDebugText(llformat("%.0f:%.0f", (F32) sqrt(min_vsize),(F32) sqrt(max_vsize)));
+    }
+    else if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_TEXTURE_PRIORITY))
+    {
+        //setDebugText(llformat("%.0f:%.0f", (F32) sqrt(min_vsize),(F32) sqrt(max_vsize)));
+        setDebugText(debug_text.str());
+    }
+    else if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_FACE_AREA))
+    {
+        setDebugText(llformat("%.0f:%.0f", (F32) sqrt(min_vsize),(F32) sqrt(max_vsize)));
+    }
+
+    if (mPixelArea == 0)
+    { //flexi phasing issues make this happen
+        mPixelArea = old_area;
+    }
+}
+
+BOOL LLVOVolume::isActive() const
+{
+    return !mStatic;
+}
+
+BOOL LLVOVolume::setMaterial(const U8 material)
+{
+    BOOL res = LLViewerObject::setMaterial(material);
+
+    return res;
+}
+
+void LLVOVolume::setTexture(const S32 face)
+{
+    llassert(face < getNumTEs());
+    gGL.getTexUnit(0)->bind(getTEImage(face));
+}
+
+void LLVOVolume::setScale(const LLVector3 &scale, BOOL damped)
+{
+    if (scale != getScale())
+    {
+        // store local radius
+        LLViewerObject::setScale(scale);
+
+        if (mVolumeImpl)
+        {
+            mVolumeImpl->onSetScale(scale, damped);
+        }
+
+        updateRadius();
+
+        //since drawable transforms do not include scale, changing volume scale
+        //requires an immediate rebuild of volume verts.
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_POSITION);
+
+        if (mDrawable)
+        {
+            shrinkWrap();
+        }
+    }
+}
+
+LLFace* LLVOVolume::addFace(S32 f)
+{
+    const LLTextureEntry* te = getTE(f);
+    LLViewerTexture* imagep = getTEImage(f);
+    if (te && te->getMaterialParams().notNull())
+    {
+        LLViewerTexture* normalp = getTENormalMap(f);
+        LLViewerTexture* specularp = getTESpecularMap(f);
+        return mDrawable->addFace(te, imagep, normalp, specularp);
+    }
+    return mDrawable->addFace(te, imagep);
+}
+
+LLDrawable *LLVOVolume::createDrawable(LLPipeline *pipeline)
+{
+    pipeline->allocDrawable(this);
+
+    mDrawable->setRenderType(LLPipeline::RENDER_TYPE_VOLUME);
+
+    S32 max_tes_to_set = getNumTEs();
+    for (S32 i = 0; i < max_tes_to_set; i++)
+    {
+        addFace(i);
+    }
+    mNumFaces = max_tes_to_set;
+
+    if (isAttachment())
+    {
+        mDrawable->makeActive();
+    }
+
+    if (getIsLight())
+    {
+        // Add it to the pipeline mLightSet
+        gPipeline.setLight(mDrawable, TRUE);
+    }
+
+    if (isReflectionProbe())
+    {
+        updateReflectionProbePtr();
+    }
+
+    updateRadius();
+    bool force_update = true; // avoid non-alpha mDistance update being optimized away
+    mDrawable->updateDistance(LLViewerCamera::instance(), force_update);
+
+    return mDrawable;
+}
+
+BOOL LLVOVolume::setVolume(const LLVolumeParams &params_in, const S32 detail, bool unique_volume)
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
+    LLVolumeParams volume_params = params_in;
+
+    S32 last_lod = mVolumep.notNull() ? LLVolumeLODGroup::getVolumeDetailFromScale(mVolumep->getDetail()) : -1;
+    S32 lod = mLOD;
+
+    BOOL is404 = FALSE;
+
+    if (isSculpted())
+    {
+        // if it's a mesh
+        if ((volume_params.getSculptType() & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
+        { //meshes might not have all LODs, get the force detail to best existing LOD
+            if (NO_LOD != lod)
+            {
+                lod = gMeshRepo.getActualMeshLOD(volume_params, lod);
+                if (lod == -1)
+                {
+                    is404 = TRUE;
+                    lod = 0;
+                }
+            }
+        }
+    }
+
+    // Check if we need to change implementations
+    bool is_flexible = (volume_params.getPathParams().getCurveType() == LL_PCODE_PATH_FLEXIBLE);
+    if (is_flexible)
+    {
+        setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, TRUE, false);
+        if (!mVolumeImpl)
+        {
+            LLFlexibleObjectData* data = (LLFlexibleObjectData*)getFlexibleObjectData();
+            mVolumeImpl = new LLVolumeImplFlexible(this, data);
+        }
+    }
+    else
+    {
+        // Mark the parameter not in use
+        setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, FALSE, false);
+        if (mVolumeImpl)
+        {
+            delete mVolumeImpl;
+            mVolumeImpl = NULL;
+            if (mDrawable.notNull())
+            {
+                // Undo the damage we did to this matrix
+                mDrawable->updateXform(FALSE);
+            }
+        }
+    }
+
+    if (is404)
+    {
+        setIcon(LLViewerTextureManager::getFetchedTextureFromFile("icons/Inv_Mesh.png", FTT_LOCAL_FILE, TRUE, LLGLTexture::BOOST_UI));
+        //render prim proxy when mesh loading attempts give up
+        volume_params.setSculptID(LLUUID::null, LL_SCULPT_TYPE_NONE);
+
+    }
+
+    if ((LLPrimitive::setVolume(volume_params, lod, (mVolumeImpl && mVolumeImpl->isVolumeUnique()))) || mSculptChanged)
+    {
+        mFaceMappingChanged = TRUE;
+
+        if (mVolumeImpl)
+        {
+            mVolumeImpl->onSetVolume(volume_params, mLOD);
+        }
+
+        updateSculptTexture();
+
+        if (isSculpted())
+        {
+            // if it's a mesh
+            if ((volume_params.getSculptType() & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
+            {
+                if (mSkinInfo && mSkinInfo->mMeshID != volume_params.getSculptID())
+                {
+                    mSkinInfo = NULL;
+                    mSkinInfoUnavaliable = false;
+                }
+
+                if (!getVolume()->isMeshAssetLoaded())
+                {
+                    //load request not yet issued, request pipeline load this mesh
+                    S32 available_lod = gMeshRepo.loadMesh(this, volume_params, lod, last_lod);
+                    if (available_lod != lod)
+                    {
+                        LLPrimitive::setVolume(volume_params, available_lod);
+                    }
+                }
+
+                if (!mSkinInfo && !mSkinInfoUnavaliable)
+                {
+                    LLUUID mesh_id = volume_params.getSculptID();
                     if (gMeshRepo.hasHeader(mesh_id) && !gMeshRepo.hasSkinInfo(mesh_id))
                     {
                         // If header is present but has no data about skin,
@@ -1147,60 +1147,60 @@ BOOL LLVOVolume::setVolume(const LLVolumeParams &params_in, const S32 detail, bo
                             notifySkinInfoLoaded(skin_info);
                         }
                     }
-				}
-			}
-			else // otherwise is sculptie
-			{
-				if (mSculptTexture.notNull())
-				{
-					sculpt();
-				}
-			}
-		}
-
-		return TRUE;
-	}
-	else if (NO_LOD == lod) 
-	{
-		LLSculptIDSize::instance().resetSizeSum(volume_params.getSculptID());
-	}
-
-	return FALSE;
+                }
+            }
+            else // otherwise is sculptie
+            {
+                if (mSculptTexture.notNull())
+                {
+                    sculpt();
+                }
+            }
+        }
+
+        return TRUE;
+    }
+    else if (NO_LOD == lod)
+    {
+        LLSculptIDSize::instance().resetSizeSum(volume_params.getSculptID());
+    }
+
+    return FALSE;
 }
 
 void LLVOVolume::updateSculptTexture()
 {
-	LLPointer<LLViewerFetchedTexture> old_sculpt = mSculptTexture;
+    LLPointer<LLViewerFetchedTexture> old_sculpt = mSculptTexture;
 
-	if (isSculpted() && !isMesh())
-	{
-		LLSculptParams *sculpt_params = (LLSculptParams *)getSculptParams();
-		LLUUID id =  sculpt_params->getSculptTexture();
-		if (id.notNull())
-		{
-			mSculptTexture = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
-		}
+    if (isSculpted() && !isMesh())
+    {
+        LLSculptParams *sculpt_params = (LLSculptParams *)getSculptParams();
+        LLUUID id =  sculpt_params->getSculptTexture();
+        if (id.notNull())
+        {
+            mSculptTexture = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE, LLViewerTexture::LOD_TEXTURE);
+        }
 
         mSkinInfoUnavaliable = false;
-		mSkinInfo = NULL;
-	}
-	else
-	{
-		mSculptTexture = NULL;
-	}
-
-	if (mSculptTexture != old_sculpt)
-	{
-		if (old_sculpt.notNull())
-		{
-			old_sculpt->removeVolume(LLRender::SCULPT_TEX, this);
-		}
-		if (mSculptTexture.notNull())
-		{
-			mSculptTexture->addVolume(LLRender::SCULPT_TEX, this);
-		}
-	}
-	
+        mSkinInfo = NULL;
+    }
+    else
+    {
+        mSculptTexture = NULL;
+    }
+
+    if (mSculptTexture != old_sculpt)
+    {
+        if (old_sculpt.notNull())
+        {
+            old_sculpt->removeVolume(LLRender::SCULPT_TEX, this);
+        }
+        if (mSculptTexture.notNull())
+        {
+            mSculptTexture->addVolume(LLRender::SCULPT_TEX, this);
+        }
+    }
+
 }
 
 void LLVOVolume::updateVisualComplexity()
@@ -1218,9 +1218,9 @@ void LLVOVolume::updateVisualComplexity()
 }
 
 void LLVOVolume::notifyMeshLoaded()
-{ 
-	mSculptChanged = TRUE;
-	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
+{
+    mSculptChanged = TRUE;
+    gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
 
     if (!mSkinInfo && !mSkinInfoUnavaliable)
     {
@@ -1248,152 +1248,152 @@ void LLVOVolume::notifyMeshLoaded()
 void LLVOVolume::notifySkinInfoLoaded(const LLMeshSkinInfo* skin)
 {
     mSkinInfoUnavaliable = false;
-	mSkinInfo = skin;
-
-	mSculptChanged = TRUE;
-	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
-
-	LLVOAvatar* av = getAvatar();
-	if (av && !isAnimatedObject())
-	{
-		av->addAttachmentOverridesForObject(this);
-		av->notifyAttachmentMeshLoaded();
-	}
-	LLControlAvatar* cav = getControlAvatar();
-	if (cav && isAnimatedObject())
-	{
-		cav->addAttachmentOverridesForObject(this);
-		cav->notifyAttachmentMeshLoaded();
-	}
-	updateVisualComplexity();
+    mSkinInfo = skin;
+
+    mSculptChanged = TRUE;
+    gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_GEOMETRY);
+
+    LLVOAvatar* av = getAvatar();
+    if (av && !isAnimatedObject())
+    {
+        av->addAttachmentOverridesForObject(this);
+        av->notifyAttachmentMeshLoaded();
+    }
+    LLControlAvatar* cav = getControlAvatar();
+    if (cav && isAnimatedObject())
+    {
+        cav->addAttachmentOverridesForObject(this);
+        cav->notifyAttachmentMeshLoaded();
+    }
+    updateVisualComplexity();
 }
 
 void LLVOVolume::notifySkinInfoUnavailable()
 {
-	mSkinInfoUnavaliable = true;
-	mSkinInfo = nullptr;
+    mSkinInfoUnavaliable = true;
+    mSkinInfo = nullptr;
 }
 
 // sculpt replaces generate() for sculpted surfaces
 void LLVOVolume::sculpt()
-{	
-	if (mSculptTexture.notNull())
-	{				
-		U16 sculpt_height = 0;
-		U16 sculpt_width = 0;
-		S8 sculpt_components = 0;
-		const U8* sculpt_data = NULL;
-	
-		S32 discard_level = mSculptTexture->getCachedRawImageLevel() ;
-		LLImageRaw* raw_image = mSculptTexture->getCachedRawImage() ;
-		
-		S32 max_discard = mSculptTexture->getMaxDiscardLevel();
-		if (discard_level > max_discard)
-		{
-			discard_level = max_discard;    // clamp to the best we can do			
-		}
-		if(discard_level > MAX_DISCARD_LEVEL)
-		{
-			return; //we think data is not ready yet.
-		}
-
-		S32 current_discard = getVolume()->getSculptLevel() ;
-		if(current_discard < -2)
-		{
-			static S32 low_sculpty_discard_warning_count = 1;
-			S32 exponent = llmax(1, llfloor( log10((F64) low_sculpty_discard_warning_count) ));
-			S32 interval = pow(10.0, exponent);
-			if ( low_sculpty_discard_warning_count < 10 ||
-				(low_sculpty_discard_warning_count % interval) == 0)
-			{	// Log first 10 time, then decreasing intervals afterwards otherwise this can flood the logs
-				LL_WARNS() << "WARNING!!: Current discard for sculpty " << mSculptTexture->getID() 
-					<< " at " << current_discard 
-					<< " is less than -2." 
-					<< " Hit this " << low_sculpty_discard_warning_count << " times"
-					<< LL_ENDL;
-			}
-			low_sculpty_discard_warning_count++;
-			
-			// corrupted volume... don't update the sculpty
-			return;
-		}
-		else if (current_discard > MAX_DISCARD_LEVEL)
-		{
-			static S32 high_sculpty_discard_warning_count = 1;
-			S32 exponent = llmax(1, llfloor( log10((F64) high_sculpty_discard_warning_count) ));
-			S32 interval = pow(10.0, exponent);
-			if ( high_sculpty_discard_warning_count < 10 ||
-				(high_sculpty_discard_warning_count % interval) == 0)
-			{	// Log first 10 time, then decreasing intervals afterwards otherwise this can flood the logs
-				LL_WARNS() << "WARNING!!: Current discard for sculpty " << mSculptTexture->getID() 
-					<< " at " << current_discard 
-					<< " is more than than allowed max of " << MAX_DISCARD_LEVEL
-					<< ".  Hit this " << high_sculpty_discard_warning_count << " times"
-					<< LL_ENDL;
-			}
-			high_sculpty_discard_warning_count++;
-
-			// corrupted volume... don't update the sculpty			
-			return;
-		}
-
-		if (current_discard == discard_level)  // no work to do here
-			return;
-		
-		if(!raw_image)
-		{
-			llassert(discard_level < 0) ;
-
-			sculpt_width = 0;
-			sculpt_height = 0;
-			sculpt_data = NULL ;
-
-			if(LLViewerTextureManager::sTesterp)
-			{
-				LLViewerTextureManager::sTesterp->updateGrayTextureBinding();
-			}
-		}
-		else
-		{					
-			sculpt_height = raw_image->getHeight();
-			sculpt_width = raw_image->getWidth();
-			sculpt_components = raw_image->getComponents();		
-					   
-			sculpt_data = raw_image->getData();
-
-			if(LLViewerTextureManager::sTesterp)
-			{
-				mSculptTexture->updateBindStatsForTester() ;
-			}
-		}
-		getVolume()->sculpt(sculpt_width, sculpt_height, sculpt_components, sculpt_data, discard_level, mSculptTexture->isMissingAsset());
-
-		//notify rebuild any other VOVolumes that reference this sculpty volume
-		for (S32 i = 0; i < mSculptTexture->getNumVolumes(LLRender::SCULPT_TEX); ++i)
-		{
-			LLVOVolume* volume = (*(mSculptTexture->getVolumeList(LLRender::SCULPT_TEX)))[i];
-			if (volume != this && volume->getVolume() == getVolume())
-			{
-				gPipeline.markRebuild(volume->mDrawable, LLDrawable::REBUILD_GEOMETRY);
-			}
-		}
-	}
-}
-
-S32	LLVOVolume::computeLODDetail(F32 distance, F32 radius, F32 lod_factor)
-{
-	S32	cur_detail;
-	if (LLPipeline::sDynamicLOD)
-	{
-		// We've got LOD in the profile, and in the twist.  Use radius.
-		F32 tan_angle = (lod_factor*radius)/distance;
-		cur_detail = LLVolumeLODGroup::getDetailFromTan(ll_round(tan_angle, 0.01f));
-	}
-	else
-	{
-		cur_detail = llclamp((S32) (sqrtf(radius)*lod_factor*4.f), 0, 3);
-	}
-	return cur_detail;
+{
+    if (mSculptTexture.notNull())
+    {
+        U16 sculpt_height = 0;
+        U16 sculpt_width = 0;
+        S8 sculpt_components = 0;
+        const U8* sculpt_data = NULL;
+
+        S32 discard_level = mSculptTexture->getCachedRawImageLevel() ;
+        LLImageRaw* raw_image = mSculptTexture->getCachedRawImage() ;
+
+        S32 max_discard = mSculptTexture->getMaxDiscardLevel();
+        if (discard_level > max_discard)
+        {
+            discard_level = max_discard;    // clamp to the best we can do
+        }
+        if(discard_level > MAX_DISCARD_LEVEL)
+        {
+            return; //we think data is not ready yet.
+        }
+
+        S32 current_discard = getVolume()->getSculptLevel() ;
+        if(current_discard < -2)
+        {
+            static S32 low_sculpty_discard_warning_count = 1;
+            S32 exponent = llmax(1, llfloor( log10((F64) low_sculpty_discard_warning_count) ));
+            S32 interval = pow(10.0, exponent);
+            if ( low_sculpty_discard_warning_count < 10 ||
+                (low_sculpty_discard_warning_count % interval) == 0)
+            {   // Log first 10 time, then decreasing intervals afterwards otherwise this can flood the logs
+                LL_WARNS() << "WARNING!!: Current discard for sculpty " << mSculptTexture->getID()
+                    << " at " << current_discard
+                    << " is less than -2."
+                    << " Hit this " << low_sculpty_discard_warning_count << " times"
+                    << LL_ENDL;
+            }
+            low_sculpty_discard_warning_count++;
+
+            // corrupted volume... don't update the sculpty
+            return;
+        }
+        else if (current_discard > MAX_DISCARD_LEVEL)
+        {
+            static S32 high_sculpty_discard_warning_count = 1;
+            S32 exponent = llmax(1, llfloor( log10((F64) high_sculpty_discard_warning_count) ));
+            S32 interval = pow(10.0, exponent);
+            if ( high_sculpty_discard_warning_count < 10 ||
+                (high_sculpty_discard_warning_count % interval) == 0)
+            {   // Log first 10 time, then decreasing intervals afterwards otherwise this can flood the logs
+                LL_WARNS() << "WARNING!!: Current discard for sculpty " << mSculptTexture->getID()
+                    << " at " << current_discard
+                    << " is more than than allowed max of " << MAX_DISCARD_LEVEL
+                    << ".  Hit this " << high_sculpty_discard_warning_count << " times"
+                    << LL_ENDL;
+            }
+            high_sculpty_discard_warning_count++;
+
+            // corrupted volume... don't update the sculpty
+            return;
+        }
+
+        if (current_discard == discard_level)  // no work to do here
+            return;
+
+        if(!raw_image)
+        {
+            llassert(discard_level < 0) ;
+
+            sculpt_width = 0;
+            sculpt_height = 0;
+            sculpt_data = NULL ;
+
+            if(LLViewerTextureManager::sTesterp)
+            {
+                LLViewerTextureManager::sTesterp->updateGrayTextureBinding();
+            }
+        }
+        else
+        {
+            sculpt_height = raw_image->getHeight();
+            sculpt_width = raw_image->getWidth();
+            sculpt_components = raw_image->getComponents();
+
+            sculpt_data = raw_image->getData();
+
+            if(LLViewerTextureManager::sTesterp)
+            {
+                mSculptTexture->updateBindStatsForTester() ;
+            }
+        }
+        getVolume()->sculpt(sculpt_width, sculpt_height, sculpt_components, sculpt_data, discard_level, mSculptTexture->isMissingAsset());
+
+        //notify rebuild any other VOVolumes that reference this sculpty volume
+        for (S32 i = 0; i < mSculptTexture->getNumVolumes(LLRender::SCULPT_TEX); ++i)
+        {
+            LLVOVolume* volume = (*(mSculptTexture->getVolumeList(LLRender::SCULPT_TEX)))[i];
+            if (volume != this && volume->getVolume() == getVolume())
+            {
+                gPipeline.markRebuild(volume->mDrawable, LLDrawable::REBUILD_GEOMETRY);
+            }
+        }
+    }
+}
+
+S32 LLVOVolume::computeLODDetail(F32 distance, F32 radius, F32 lod_factor)
+{
+    S32 cur_detail;
+    if (LLPipeline::sDynamicLOD)
+    {
+        // We've got LOD in the profile, and in the twist.  Use radius.
+        F32 tan_angle = (lod_factor*radius)/distance;
+        cur_detail = LLVolumeLODGroup::getDetailFromTan(ll_round(tan_angle, 0.01f));
+    }
+    else
+    {
+        cur_detail = llclamp((S32) (sqrtf(radius)*lod_factor*4.f), 0, 3);
+    }
+    return cur_detail;
 }
 
 std::string get_debug_object_lod_text(LLVOVolume *rootp)
@@ -1438,28 +1438,28 @@ std::string get_debug_object_lod_text(LLVOVolume *rootp)
 
 BOOL LLVOVolume::calcLOD()
 {
-	if (mDrawable.isNull())
-	{
-		return FALSE;
-	}
+    if (mDrawable.isNull())
+    {
+        return FALSE;
+    }
 
-	S32 cur_detail = 0;
-	
-	F32 radius;
-	F32 distance;
-	F32 lod_factor = LLVOVolume::sLODFactor;
+    S32 cur_detail = 0;
 
-	if (mDrawable->isState(LLDrawable::RIGGED))
-	{
-		LLVOAvatar* avatar = getAvatar(); 
-		
-		// Not sure how this can really happen, but alas it does. Better exit here than crashing.
-		if( !avatar || !avatar->mDrawable )
-		{
-			return FALSE;
-		}
+    F32 radius;
+    F32 distance;
+    F32 lod_factor = LLVOVolume::sLODFactor;
 
-		distance = avatar->mDrawable->mDistanceWRTCamera;
+    if (mDrawable->isState(LLDrawable::RIGGED))
+    {
+        LLVOAvatar* avatar = getAvatar();
+
+        // Not sure how this can really happen, but alas it does. Better exit here than crashing.
+        if( !avatar || !avatar->mDrawable )
+        {
+            return FALSE;
+        }
+
+        distance = avatar->mDrawable->mDistanceWRTCamera;
 
 
         if (avatar->isControlAvatar())
@@ -1492,11 +1492,11 @@ BOOL LLVOVolume::calcLOD()
 #endif
             return FALSE;
         }
-	}
-	else
-	{
-		distance = mDrawable->mDistanceWRTCamera;
-		radius = getVolume() ? getVolume()->mLODScaleBias.scaledVec(getScale()).length() : getScale().length();
+    }
+    else
+    {
+        distance = mDrawable->mDistanceWRTCamera;
+        radius = getVolume() ? getVolume()->mLODScaleBias.scaledVec(getScale()).length() : getScale().length();
         if (distance <= 0.f || radius <= 0.f)
         {
 #ifdef SHOW_DEBUG
@@ -1504,10 +1504,10 @@ BOOL LLVOVolume::calcLOD()
 #endif
             return FALSE;
         }
-	}
-	
-	//hold onto unmodified distance for debugging
-	//F32 debug_distance = distance;
+    }
+
+    //hold onto unmodified distance for debugging
+    //F32 debug_distance = distance;
 
     mLODDistance = distance;
     mLODRadius = radius;
@@ -1533,24 +1533,24 @@ BOOL LLVOVolume::calcLOD()
 
     distance *= sDistanceFactor;
 
-	F32 rampDist = LLVOVolume::sLODFactor * 2;
-	
-	if (distance < rampDist)
-	{
-		// Boost LOD when you're REALLY close
-		distance *= 1.0f/rampDist;
-		distance *= distance;
-		distance *= rampDist;
-	}
-	
-
-	distance *= F_PI/3.f;
-
-	static LLCachedControl<bool> ignore_fov_zoom(gSavedSettings,"IgnoreFOVZoomForLODs");
-	if(!ignore_fov_zoom)
-	{
-		lod_factor *= DEFAULT_FIELD_OF_VIEW / LLViewerCamera::getInstance()->getDefaultFOV();
-	}
+    F32 rampDist = LLVOVolume::sLODFactor * 2;
+
+    if (distance < rampDist)
+    {
+        // Boost LOD when you're REALLY close
+        distance *= 1.0f/rampDist;
+        distance *= distance;
+        distance *= rampDist;
+    }
+
+
+    distance *= F_PI/3.f;
+
+    static LLCachedControl<bool> ignore_fov_zoom(gSavedSettings,"IgnoreFOVZoomForLODs");
+    if(!ignore_fov_zoom)
+    {
+        lod_factor *= DEFAULT_FIELD_OF_VIEW / LLViewerCamera::getInstance()->getDefaultFOV();
+    }
 
     mLODAdjustedDistance = distance;
 
@@ -1573,195 +1573,195 @@ BOOL LLVOVolume::calcLOD()
             setDebugText(llformat("TRIS SHOWN %d EST %d", total_tris, est_max_tris));
         }
     }
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_LOD_INFO) &&
-		mDrawable->getFace(0))
-	{
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_LOD_INFO) &&
+        mDrawable->getFace(0))
+    {
         // This is a debug display for LODs. Please don't put the texture index here.
         setDebugText(llformat("%d", cur_detail));
-	}
+    }
 
-	if (cur_detail != mLOD)
-	{
+    if (cur_detail != mLOD)
+    {
 #ifdef SHOW_DEBUG
-        LL_DEBUGS("DynamicBox","CalcLOD") << "new LOD " << cur_detail << " change from " << mLOD 
+        LL_DEBUGS("DynamicBox","CalcLOD") << "new LOD " << cur_detail << " change from " << mLOD
                              << " distance " << distance << " radius " << radius << " rampDist " << rampDist
                              << " drawable rigged? " << (mDrawable ? (S32) mDrawable->isState(LLDrawable::RIGGED) : (S32) -1)
-							 << " mRiggedVolume " << (void*)getRiggedVolume()
+                             << " mRiggedVolume " << (void*)getRiggedVolume()
                              << " distanceWRTCamera " << (mDrawable ? mDrawable->mDistanceWRTCamera : -1.f)
                              << LL_ENDL;
 #endif
-        
-		mAppAngle = ll_round((F32) atan2( mDrawable->getRadius(), mDrawable->mDistanceWRTCamera) * RAD_TO_DEG, 0.01f);
-		mLOD = cur_detail;		
+
+        mAppAngle = ll_round((F32) atan2( mDrawable->getRadius(), mDrawable->mDistanceWRTCamera) * RAD_TO_DEG, 0.01f);
+        mLOD = cur_detail;
 
         return TRUE;
-	}
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 BOOL LLVOVolume::updateLOD()
 {
-	if (mDrawable.isNull())
-	{
-		return FALSE;
-	}
+    if (mDrawable.isNull())
+    {
+        return FALSE;
+    }
 
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
 
-	BOOL lod_changed = FALSE;
-
-	if (!LLSculptIDSize::instance().isUnloaded(getVolume()->getParams().getSculptID())) 
-	{
-		lod_changed = calcLOD();
-	}
-	else
-	{
-		return FALSE;
-	}
-
-	if (lod_changed)
-	{
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
-		mLODChanged = TRUE;
-	}
-	else
-	{
-		F32 new_radius = getBinRadius();
-		F32 old_radius = mDrawable->getBinRadius();
-		if (new_radius < old_radius * 0.9f || new_radius > old_radius*1.1f)
-		{
-			gPipeline.markPartitionMove(mDrawable);
-		}
-	}
-
-	lod_changed = lod_changed || LLViewerObject::updateLOD();
-	
-	return lod_changed;
+    BOOL lod_changed = FALSE;
+
+    if (!LLSculptIDSize::instance().isUnloaded(getVolume()->getParams().getSculptID()))
+    {
+        lod_changed = calcLOD();
+    }
+    else
+    {
+        return FALSE;
+    }
+
+    if (lod_changed)
+    {
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
+        mLODChanged = TRUE;
+    }
+    else
+    {
+        F32 new_radius = getBinRadius();
+        F32 old_radius = mDrawable->getBinRadius();
+        if (new_radius < old_radius * 0.9f || new_radius > old_radius*1.1f)
+        {
+            gPipeline.markPartitionMove(mDrawable);
+        }
+    }
+
+    lod_changed = lod_changed || LLViewerObject::updateLOD();
+
+    return lod_changed;
 }
 
 BOOL LLVOVolume::setDrawableParent(LLDrawable* parentp)
 {
-	if (!LLViewerObject::setDrawableParent(parentp))
-	{
-		// no change in drawable parent
-		return FALSE;
-	}
-
-	if (!mDrawable->isRoot())
-	{
-		// rebuild vertices in parent relative space
-		gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
-
-		if (mDrawable->isActive() && !parentp->isActive())
-		{
-			parentp->makeActive();
-		}
-		else if (mDrawable->isStatic() && parentp->isActive())
-		{
-			mDrawable->makeActive();
-		}
-	}
-	
-	return TRUE;
+    if (!LLViewerObject::setDrawableParent(parentp))
+    {
+        // no change in drawable parent
+        return FALSE;
+    }
+
+    if (!mDrawable->isRoot())
+    {
+        // rebuild vertices in parent relative space
+        gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
+
+        if (mDrawable->isActive() && !parentp->isActive())
+        {
+            parentp->makeActive();
+        }
+        else if (mDrawable->isStatic() && parentp->isActive())
+        {
+            mDrawable->makeActive();
+        }
+    }
+
+    return TRUE;
 }
 
 void LLVOVolume::updateFaceFlags()
 {
-	// There's no guarantee that getVolume()->getNumFaces() == mDrawable->getNumFaces()
-	for (S32 i = 0, num_vol_face = getVolume()->getNumFaces(), num_face = mDrawable->getNumFaces(), num_te = getNumTEs();
-		i < num_vol_face&& i < num_face; ++i)
-	{
-		if (num_face <= i || num_te <= i)
-			return;
-
-		LLFace *face = mDrawable->getFace(i);
-		if (face)
-		{
-			BOOL fullbright = getTE(i)->getFullbright();
-			face->clearState(LLFace::FULLBRIGHT | LLFace::HUD_RENDER | LLFace::LIGHT);
-
-			if (fullbright || (mMaterial == LL_MCODE_LIGHT))
-			{
-				face->setState(LLFace::FULLBRIGHT);
-			}
-			if (mDrawable->isLight())
-			{
-				face->setState(LLFace::LIGHT);
-			}
-			if (isHUDAttachment())
-			{
-				face->setState(LLFace::HUD_RENDER);
-			}
-		}
-	}
+    // There's no guarantee that getVolume()->getNumFaces() == mDrawable->getNumFaces()
+    for (S32 i = 0, num_vol_face = getVolume()->getNumFaces(), num_face = mDrawable->getNumFaces(), num_te = getNumTEs();
+        i < num_vol_face&& i < num_face; ++i)
+    {
+        if (num_face <= i || num_te <= i)
+            return;
+
+        LLFace *face = mDrawable->getFace(i);
+        if (face)
+        {
+            BOOL fullbright = getTE(i)->getFullbright();
+            face->clearState(LLFace::FULLBRIGHT | LLFace::HUD_RENDER | LLFace::LIGHT);
+
+            if (fullbright || (mMaterial == LL_MCODE_LIGHT))
+            {
+                face->setState(LLFace::FULLBRIGHT);
+            }
+            if (mDrawable->isLight())
+            {
+                face->setState(LLFace::LIGHT);
+            }
+            if (isHUDAttachment())
+            {
+                face->setState(LLFace::HUD_RENDER);
+            }
+        }
+    }
 }
 
 BOOL LLVOVolume::setParent(LLViewerObject* parent)
 {
-	BOOL ret = FALSE ;
+    BOOL ret = FALSE ;
     LLViewerObject *old_parent = (LLViewerObject*) getParent();
-	if (parent != old_parent)
-	{
-		ret = LLViewerObject::setParent(parent);
-		if (ret && mDrawable)
-		{
-			gPipeline.markMoved(mDrawable);
-			gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
-		}
+    if (parent != old_parent)
+    {
+        ret = LLViewerObject::setParent(parent);
+        if (ret && mDrawable)
+        {
+            gPipeline.markMoved(mDrawable);
+            gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
+        }
         onReparent(old_parent, parent);
-	}
+    }
 
-	return ret ;
+    return ret ;
 }
 
 // NOTE: regenFaces() MUST be followed by genTriangles()!
 void LLVOVolume::regenFaces()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	// remove existing faces
-	BOOL count_changed = mNumFaces != getNumTEs();
-	
-	if (count_changed)
-	{
-		deleteFaces();		
-		// add new faces
-		mNumFaces = getNumTEs();
-	}
-		
-	for (S32 i = 0; i < mNumFaces; i++)
-	{
-		LLFace* facep = count_changed ? addFace(i) : mDrawable->getFace(i);
-		if (!facep) continue;
-
-		facep->setTEOffset(i);
-		facep->setTexture(getTEImage(i));
-		if (facep->getTextureEntry()->getMaterialParams().notNull())
-		{
-			facep->setNormalMap(getTENormalMap(i));
-			facep->setSpecularMap(getTESpecularMap(i));
-		}
-		facep->setViewerObject(this);
-		
-		// If the face had media on it, this will have broken the link between the LLViewerMediaTexture and the face.
-		// Re-establish the link.
-		if((int)mMediaImplList.size() > i)
-		{
-			if(mMediaImplList[i])
-			{
-				LLViewerMediaTexture* media_tex = LLViewerTextureManager::findMediaTexture(mMediaImplList[i]->getMediaTextureID()) ;
-				if(media_tex)
-				{
-					media_tex->addMediaToFace(facep) ;
-				}
-			}
-		}
-	}
-	
-	if (!count_changed)
-	{
-		updateFaceFlags();
-	}
+    // remove existing faces
+    BOOL count_changed = mNumFaces != getNumTEs();
+
+    if (count_changed)
+    {
+        deleteFaces();
+        // add new faces
+        mNumFaces = getNumTEs();
+    }
+
+    for (S32 i = 0; i < mNumFaces; i++)
+    {
+        LLFace* facep = count_changed ? addFace(i) : mDrawable->getFace(i);
+        if (!facep) continue;
+
+        facep->setTEOffset(i);
+        facep->setTexture(getTEImage(i));
+        if (facep->getTextureEntry()->getMaterialParams().notNull())
+        {
+            facep->setNormalMap(getTENormalMap(i));
+            facep->setSpecularMap(getTESpecularMap(i));
+        }
+        facep->setViewerObject(this);
+
+        // If the face had media on it, this will have broken the link between the LLViewerMediaTexture and the face.
+        // Re-establish the link.
+        if((int)mMediaImplList.size() > i)
+        {
+            if(mMediaImplList[i])
+            {
+                LLViewerMediaTexture* media_tex = LLViewerTextureManager::findMediaTexture(mMediaImplList[i]->getMediaTextureID()) ;
+                if(media_tex)
+                {
+                    media_tex->addMediaToFace(facep) ;
+                }
+            }
+        }
+    }
+
+    if (!count_changed)
+    {
+        updateFaceFlags();
+    }
 }
 
 BOOL LLVOVolume::genBBoxes(BOOL force_global, BOOL should_update_octree_bounds)
@@ -1801,9 +1801,9 @@ BOOL LLVOVolume::genBBoxes(BOOL force_global, BOOL should_update_octree_bounds)
     }
 #endif
     // There's no guarantee that getVolume()->getNumFaces() == mDrawable->getNumFaces()
-	for (S32 i = 0, num_vol_face = getVolume()->getNumVolumeFaces(), num_face = mDrawable->getNumFaces(), num_te = getNumTEs();
-		 i < num_vol_face && i < num_face&& i < num_te;
-		 ++i)
+    for (S32 i = 0, num_vol_face = getVolume()->getNumVolumeFaces(), num_face = mDrawable->getNumFaces(), num_te = getNumTEs();
+         i < num_vol_face && i < num_face&& i < num_te;
+         ++i)
     {
         LLFace* face = mDrawable->getFace(i);
         if (!face)
@@ -1882,557 +1882,557 @@ BOOL LLVOVolume::genBBoxes(BOOL force_global, BOOL should_update_octree_bounds)
                 mDrawable->setPositionGroup(min);
             }
         }
-        
-        updateRadius();
-        mDrawable->movePartition();
+
+        updateRadius();
+        mDrawable->movePartition();
+    }
+#ifdef SHOW_DEBUG
+    else
+    {
+        LL_DEBUGS("RiggedBox") << "genBBoxes failed to find any valid face boxes" << LL_ENDL;
+    }
+#endif
+
+    return res;
+}
+
+void LLVOVolume::preRebuild()
+{
+    if (mVolumeImpl != NULL)
+    {
+        mVolumeImpl->preRebuild();
+    }
+}
+
+void LLVOVolume::updateRelativeXform(bool force_identity)
+{
+    if (mVolumeImpl)
+    {
+        mVolumeImpl->updateRelativeXform(force_identity);
+        return;
+    }
+
+    LLDrawable* drawable = mDrawable;
+
+    if (drawable->isState(LLDrawable::RIGGED) && mRiggedVolume.notNull())
+    { //rigged volume (which is in agent space) is used for generating bounding boxes etc
+      //inverse of render matrix should go to partition space
+        mRelativeXform = getRenderMatrix();
+        mRelativeXformInvTrans = mRelativeXform;
+        mRelativeXform.invert();
+        mRelativeXformInvTrans.transpose();
+    }
+    else if (drawable->isActive() || force_identity)
+    {
+        // setup relative transforms
+
+        bool use_identity = force_identity || drawable->isSpatialRoot();
+
+        if(use_identity)
+        {
+            mRelativeXform.setIdentity();
+            mRelativeXform.applyScale_affine(mDrawable->getScale());
+        }
+        else
+        {
+            mRelativeXform = LLMatrix4a(LLQuaternion2(mDrawable->getRotation()));
+            mRelativeXform.applyScale_affine(mDrawable->getScale());
+            mRelativeXform.setTranslate_affine(mDrawable->getPosition());
+        }
+
+        mRelativeXformInvTrans = mRelativeXform;
+        mRelativeXformInvTrans.invert();
+        mRelativeXformInvTrans.transpose();
     }
-#ifdef SHOW_DEBUG
     else
     {
-        LL_DEBUGS("RiggedBox") << "genBBoxes failed to find any valid face boxes" << LL_ENDL;
-    }
-#endif
-
-    return res;
-}
+        LLVector4a pos;
+        pos.load3(getPosition().mV);
+        LLQuaternion2 rot(getRotation());
+        if (mParent)
+        {
+            LLMatrix4a lrot = LLMatrix4a(LLQuaternion2(mParent->getRotation()));
+            lrot.rotate(pos,pos);
+            LLVector4a lpos;
+            lpos.load3(mParent->getPosition().mV);
+            pos.add(lpos);
+            rot.mul(LLQuaternion2(mParent->getRotation()));
+        }
 
-void LLVOVolume::preRebuild()
-{
-	if (mVolumeImpl != NULL)
-	{
-		mVolumeImpl->preRebuild();
-	}
-}
+        mRelativeXform = LLMatrix4a(rot);
+        mRelativeXform.applyScale_affine(getScale());
+        mRelativeXform.setTranslate_affine(LLVector3(pos.getF32ptr()));
 
-void LLVOVolume::updateRelativeXform(bool force_identity)
-{
-	if (mVolumeImpl)
-	{
-		mVolumeImpl->updateRelativeXform(force_identity);
-		return;
-	}
-	
-	LLDrawable* drawable = mDrawable;
-	
-	if (drawable->isState(LLDrawable::RIGGED) && mRiggedVolume.notNull())
-	{ //rigged volume (which is in agent space) is used for generating bounding boxes etc
-	  //inverse of render matrix should go to partition space
-		mRelativeXform = getRenderMatrix();
-		mRelativeXformInvTrans = mRelativeXform;
-		mRelativeXform.invert();
-		mRelativeXformInvTrans.transpose();
-	}
-	else if (drawable->isActive() || force_identity)
-	{				
-		// setup relative transforms
-
-		bool use_identity = force_identity || drawable->isSpatialRoot();
-
-		if(use_identity)
-		{
-			mRelativeXform.setIdentity();
-			mRelativeXform.applyScale_affine(mDrawable->getScale());
-		}
-		else
-		{
-			mRelativeXform = LLMatrix4a(LLQuaternion2(mDrawable->getRotation()));
-			mRelativeXform.applyScale_affine(mDrawable->getScale());
-			mRelativeXform.setTranslate_affine(mDrawable->getPosition());
-		}
-
-		mRelativeXformInvTrans = mRelativeXform;
-		mRelativeXformInvTrans.invert();
-		mRelativeXformInvTrans.transpose();
-	}
-	else
-	{
-		LLVector4a pos;
-		pos.load3(getPosition().mV);
-		LLQuaternion2 rot(getRotation());
-		if (mParent)
-		{
-			LLMatrix4a lrot = LLMatrix4a(LLQuaternion2(mParent->getRotation()));
-			lrot.rotate(pos,pos);
-			LLVector4a lpos;
-			lpos.load3(mParent->getPosition().mV);
-			pos.add(lpos);
-			rot.mul(LLQuaternion2(mParent->getRotation()));
-		}
-
-		mRelativeXform = LLMatrix4a(rot);
-		mRelativeXform.applyScale_affine(getScale());
-		mRelativeXform.setTranslate_affine(LLVector3(pos.getF32ptr()));
-
-		mRelativeXformInvTrans = mRelativeXform;
-		mRelativeXformInvTrans.invert();
-		mRelativeXformInvTrans.transpose();
-	}
+        mRelativeXformInvTrans = mRelativeXform;
+        mRelativeXformInvTrans.invert();
+        mRelativeXformInvTrans.transpose();
+    }
 }
 
 bool LLVOVolume::lodOrSculptChanged(LLDrawable *drawable, BOOL &compiled, BOOL &should_update_octree_bounds)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	bool regen_faces = false;
+    bool regen_faces = false;
 
-	LLVolume *old_volumep, *new_volumep;
-	F32 old_lod, new_lod;
-	S32 old_num_faces, new_num_faces;
+    LLVolume *old_volumep, *new_volumep;
+    F32 old_lod, new_lod;
+    S32 old_num_faces, new_num_faces;
 
-	old_volumep = getVolume();
-	old_lod = old_volumep->getDetail();
-	old_num_faces = old_volumep->getNumFaces();
-	old_volumep = NULL;
+    old_volumep = getVolume();
+    old_lod = old_volumep->getDetail();
+    old_num_faces = old_volumep->getNumFaces();
+    old_volumep = NULL;
 
-	{
-		const LLVolumeParams &volume_params = getVolume()->getParams();
-		setVolume(volume_params, 0);
-	}
+    {
+        const LLVolumeParams &volume_params = getVolume()->getParams();
+        setVolume(volume_params, 0);
+    }
 
-	new_volumep = getVolume();
-	new_lod = new_volumep->getDetail();
-	new_num_faces = new_volumep->getNumFaces();
-	new_volumep = NULL;
+    new_volumep = getVolume();
+    new_lod = new_volumep->getDetail();
+    new_num_faces = new_volumep->getNumFaces();
+    new_volumep = NULL;
 
-	if ((new_lod != old_lod) || mSculptChanged)
-	{
+    if ((new_lod != old_lod) || mSculptChanged)
+    {
         if (mDrawable->isState(LLDrawable::RIGGED))
         {
             updateVisualComplexity();
         }
 
-		compiled = TRUE;
+        compiled = TRUE;
         // new_lod > old_lod breaks a feedback loop between LOD updates and
         // bounding box updates.
         should_update_octree_bounds = should_update_octree_bounds || mSculptChanged || new_lod > old_lod;
-		sNumLODChanges += new_num_faces;
-
-		if ((S32)getNumTEs() != getVolume()->getNumFaces())
-		{
-			setNumTEs(getVolume()->getNumFaces()); //mesh loading may change number of faces.
-		}
-
-		drawable->setState(LLDrawable::REBUILD_VOLUME); // for face->genVolumeTriangles()
-
-		{
-			regen_faces = new_num_faces != old_num_faces || mNumFaces != (S32)getNumTEs();
-			if (regen_faces)
-			{
-				regenFaces();
-			}
-
-			if (mSculptChanged)
-			{ //changes in sculpt maps can thrash an object bounding box without 
-				//triggering a spatial group bounding box update -- force spatial group
-				//to update bounding boxes
-				LLSpatialGroup* group = mDrawable->getSpatialGroup();
-				if (group)
-				{
-					group->unbound();
-				}
-			}
-		}
-	}
-
-	return regen_faces;
+        sNumLODChanges += new_num_faces;
+
+        if ((S32)getNumTEs() != getVolume()->getNumFaces())
+        {
+            setNumTEs(getVolume()->getNumFaces()); //mesh loading may change number of faces.
+        }
+
+        drawable->setState(LLDrawable::REBUILD_VOLUME); // for face->genVolumeTriangles()
+
+        {
+            regen_faces = new_num_faces != old_num_faces || mNumFaces != (S32)getNumTEs();
+            if (regen_faces)
+            {
+                regenFaces();
+            }
+
+            if (mSculptChanged)
+            { //changes in sculpt maps can thrash an object bounding box without
+                //triggering a spatial group bounding box update -- force spatial group
+                //to update bounding boxes
+                LLSpatialGroup* group = mDrawable->getSpatialGroup();
+                if (group)
+                {
+                    group->unbound();
+                }
+            }
+        }
+    }
+
+    return regen_faces;
 }
 
 BOOL LLVOVolume::updateGeometry(LLDrawable *drawable)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	
-	if (mDrawable->isState(LLDrawable::REBUILD_RIGGED))
-	{
+
+    if (mDrawable->isState(LLDrawable::REBUILD_RIGGED))
+    {
         updateRiggedVolume(false);
-		genBBoxes(FALSE);
-		mDrawable->clearState(LLDrawable::REBUILD_RIGGED);
-	}
-
-	if (mVolumeImpl != NULL)
-	{
-		BOOL res;
-		{
-			res = mVolumeImpl->doUpdateGeometry(drawable);
-		}
-		updateFaceFlags();
-		return res;
-	}
-	
-	LLSpatialGroup* group = drawable->getSpatialGroup();
-	if (group)
-	{
+        genBBoxes(FALSE);
+        mDrawable->clearState(LLDrawable::REBUILD_RIGGED);
+    }
+
+    if (mVolumeImpl != NULL)
+    {
+        BOOL res;
+        {
+            res = mVolumeImpl->doUpdateGeometry(drawable);
+        }
+        updateFaceFlags();
+        return res;
+    }
+
+    LLSpatialGroup* group = drawable->getSpatialGroup();
+    if (group)
+    {
         group->dirtyMesh();
-	}
+    }
 
-	updateRelativeXform();
-	
-	if (mDrawable.isNull()) // Not sure why this is happening, but it is...
-	{
-		return TRUE; // No update to complete
-	}
+    updateRelativeXform();
 
-	BOOL compiled = FALSE;
+    if (mDrawable.isNull()) // Not sure why this is happening, but it is...
+    {
+        return TRUE; // No update to complete
+    }
+
+    BOOL compiled = FALSE;
     // This should be true in most cases, unless we're sure no octree update is
     // needed.
     BOOL should_update_octree_bounds = bool(getRiggedVolume()) || mDrawable->isState(LLDrawable::REBUILD_POSITION) || !mDrawable->getSpatialExtents()->isFinite3();
 
-	if (mVolumeChanged || mFaceMappingChanged)
-	{
-		dirtySpatialGroup();
+    if (mVolumeChanged || mFaceMappingChanged)
+    {
+        dirtySpatialGroup();
 
-		bool was_regen_faces = false;
+        bool was_regen_faces = false;
         should_update_octree_bounds = true;
 
-		if (mVolumeChanged)
-		{
+        if (mVolumeChanged)
+        {
             was_regen_faces = lodOrSculptChanged(drawable, compiled, should_update_octree_bounds);
-			drawable->setState(LLDrawable::REBUILD_VOLUME);
-		}
-		else if (mSculptChanged || mLODChanged || mColorChanged)
-		{
-			compiled = TRUE;
+            drawable->setState(LLDrawable::REBUILD_VOLUME);
+        }
+        else if (mSculptChanged || mLODChanged || mColorChanged)
+        {
+            compiled = TRUE;
             was_regen_faces = lodOrSculptChanged(drawable, compiled, should_update_octree_bounds);
-		}
-
-		if (!was_regen_faces) {
-			regenFaces();
-		}
-	}
-	else if (mLODChanged || mSculptChanged || mColorChanged)
-	{
-		dirtySpatialGroup();
-		compiled = TRUE;
+        }
+
+        if (!was_regen_faces) {
+            regenFaces();
+        }
+    }
+    else if (mLODChanged || mSculptChanged || mColorChanged)
+    {
+        dirtySpatialGroup();
+        compiled = TRUE;
         lodOrSculptChanged(drawable, compiled, should_update_octree_bounds);
-		
-		if(drawable->isState(LLDrawable::REBUILD_RIGGED | LLDrawable::RIGGED)) 
-		{
-			updateRiggedVolume(false);
-		}
-	}
-	// it has its own drawable (it's moved) or it has changed UVs or it has changed xforms from global<->local
-	else
-	{
-		compiled = TRUE;
-		// All it did was move or we changed the texture coordinate offset
-	}
+
+        if(drawable->isState(LLDrawable::REBUILD_RIGGED | LLDrawable::RIGGED))
+        {
+            updateRiggedVolume(false);
+        }
+    }
+    // it has its own drawable (it's moved) or it has changed UVs or it has changed xforms from global<->local
+    else
+    {
+        compiled = TRUE;
+        // All it did was move or we changed the texture coordinate offset
+    }
 
     // Generate bounding boxes if needed, and update the object's size in the
     // octree
     genBBoxes(FALSE, should_update_octree_bounds);
 
-	// Update face flags
-	updateFaceFlags();
-	
-	mVolumeChanged = FALSE;
-	mLODChanged = FALSE;
-	mSculptChanged = FALSE;
-	mFaceMappingChanged = FALSE;
+    // Update face flags
+    updateFaceFlags();
+
+    mVolumeChanged = FALSE;
+    mLODChanged = FALSE;
+    mSculptChanged = FALSE;
+    mFaceMappingChanged = FALSE;
     mColorChanged = FALSE;
-	
-	return LLViewerObject::updateGeometry(drawable);
+
+    return LLViewerObject::updateGeometry(drawable);
 }
 
 void LLVOVolume::updateFaceSize(S32 idx)
 {
-	if( mDrawable->getNumFaces() <= idx )
-	{
-		return;
-	}
-
-	LLFace* facep = mDrawable->getFace(idx);
-	if (facep)
-	{
-		if (idx >= getVolume()->getNumVolumeFaces())
-		{
-			facep->setSize(0,0, true);
-		}
-		else
-		{
-			const LLVolumeFace& vol_face = getVolume()->getVolumeFace(idx);
-			facep->setSize(vol_face.mNumVertices, vol_face.mNumIndices, 
-							true); // <--- volume faces should be padded for 16-byte alignment
-		
-		}
-	}
+    if( mDrawable->getNumFaces() <= idx )
+    {
+        return;
+    }
+
+    LLFace* facep = mDrawable->getFace(idx);
+    if (facep)
+    {
+        if (idx >= getVolume()->getNumVolumeFaces())
+        {
+            facep->setSize(0,0, true);
+        }
+        else
+        {
+            const LLVolumeFace& vol_face = getVolume()->getVolumeFace(idx);
+            facep->setSize(vol_face.mNumVertices, vol_face.mNumIndices,
+                            true); // <--- volume faces should be padded for 16-byte alignment
+
+        }
+    }
 }
 
 BOOL LLVOVolume::isRootEdit() const
 {
-	if (mParent && !((LLViewerObject*)mParent)->isAvatar())
-	{
-		return FALSE;
-	}
-	return TRUE;
+    if (mParent && !((LLViewerObject*)mParent)->isAvatar())
+    {
+        return FALSE;
+    }
+    return TRUE;
 }
 
 //virtual
 void LLVOVolume::setNumTEs(const U8 num_tes)
 {
-	const U8 old_num_tes = getNumTEs() ;
-	
-	if(old_num_tes && old_num_tes < num_tes) //new faces added
-	{
-		LLViewerObject::setNumTEs(num_tes) ;
-
-		if(mMediaImplList.size() >= old_num_tes && mMediaImplList[old_num_tes -1].notNull())//duplicate the last media textures if exists.
-		{
-			mMediaImplList.resize(num_tes) ;
-			const LLTextureEntry* te = getTE(old_num_tes - 1) ;
-			for(U8 i = old_num_tes; i < num_tes ; i++)
-			{
-				setTE(i, *te) ;
-				mMediaImplList[i] = mMediaImplList[old_num_tes -1] ;
-			}
-			mMediaImplList[old_num_tes -1]->setUpdated(TRUE) ;
-		}
-	}
-	else if(old_num_tes > num_tes && mMediaImplList.size() > num_tes) //old faces removed
-	{
-		U8 end = (U8)(mMediaImplList.size()) ;
-		for(U8 i = num_tes; i < end ; i++)
-		{
-			removeMediaImpl(i) ;				
-		}
-		mMediaImplList.resize(num_tes) ;
-
-		LLViewerObject::setNumTEs(num_tes) ;
-	}
-	else
-	{
-		LLViewerObject::setNumTEs(num_tes) ;
-	}
-
-	return ;
+    const U8 old_num_tes = getNumTEs() ;
+
+    if(old_num_tes && old_num_tes < num_tes) //new faces added
+    {
+        LLViewerObject::setNumTEs(num_tes) ;
+
+        if(mMediaImplList.size() >= old_num_tes && mMediaImplList[old_num_tes -1].notNull())//duplicate the last media textures if exists.
+        {
+            mMediaImplList.resize(num_tes) ;
+            const LLTextureEntry* te = getTE(old_num_tes - 1) ;
+            for(U8 i = old_num_tes; i < num_tes ; i++)
+            {
+                setTE(i, *te) ;
+                mMediaImplList[i] = mMediaImplList[old_num_tes -1] ;
+            }
+            mMediaImplList[old_num_tes -1]->setUpdated(TRUE) ;
+        }
+    }
+    else if(old_num_tes > num_tes && mMediaImplList.size() > num_tes) //old faces removed
+    {
+        U8 end = (U8)(mMediaImplList.size()) ;
+        for(U8 i = num_tes; i < end ; i++)
+        {
+            removeMediaImpl(i) ;
+        }
+        mMediaImplList.resize(num_tes) ;
+
+        LLViewerObject::setNumTEs(num_tes) ;
+    }
+    else
+    {
+        LLViewerObject::setNumTEs(num_tes) ;
+    }
+
+    return ;
 }
 
 
 //virtual
 void LLVOVolume::changeTEImage(S32 index, LLViewerTexture* imagep)
 {
-	BOOL changed = (mTEImages[index] != imagep);
-	LLViewerObject::changeTEImage(index, imagep);
-	if (changed)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
+    BOOL changed = (mTEImages[index] != imagep);
+    LLViewerObject::changeTEImage(index, imagep);
+    if (changed)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
 }
 
 void LLVOVolume::setTEImage(const U8 te, LLViewerTexture *imagep)
 {
-	BOOL changed = (mTEImages[te] != imagep);
-	LLViewerObject::setTEImage(te, imagep);
-	if (changed)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
+    BOOL changed = (mTEImages[te] != imagep);
+    LLViewerObject::setTEImage(te, imagep);
+    if (changed)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
 }
 
 S32 LLVOVolume::setTETexture(const U8 te, const LLUUID &uuid)
 {
-	S32 res = LLViewerObject::setTETexture(te, uuid);
-	if (res)
-	{
+    S32 res = LLViewerObject::setTETexture(te, uuid);
+    if (res)
+    {
         if (mDrawable)
         {
             // dynamic texture changes break batches, isolate in octree
             shrinkWrap();
             gPipeline.markTextured(mDrawable);
         }
-		mFaceMappingChanged = TRUE;
-	}
-	return res;
+        mFaceMappingChanged = TRUE;
+    }
+    return res;
 }
 
 S32 LLVOVolume::setTEColor(const U8 te, const LLColor3& color)
 {
-	return setTEColor(te, LLColor4(color));
+    return setTEColor(te, LLColor4(color));
 }
 
 S32 LLVOVolume::setTEColor(const U8 te, const LLColor4& color)
 {
-	S32 retval = 0;
-	const LLTextureEntry *tep = getTE(te);
-	if (!tep)
-	{
-		LL_WARNS("MaterialTEs") << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
-	}
-	else if (color != tep->getColor())
-	{
-		F32 old_alpha = tep->getColor().mV[3];
-		if (color.mV[3] != old_alpha)
-		{
-			gPipeline.markTextured(mDrawable);
-			//treat this alpha change as an LoD update since render batches may need to get rebuilt
-			mLODChanged = TRUE;
-			gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
-		}
-		retval = LLPrimitive::setTEColor(te, color);
-		if (mDrawable.notNull() && retval)
-		{
-			// These should only happen on updates which are not the initial update.
+    S32 retval = 0;
+    const LLTextureEntry *tep = getTE(te);
+    if (!tep)
+    {
+        LL_WARNS("MaterialTEs") << "No texture entry for te " << (S32)te << ", object " << mID << LL_ENDL;
+    }
+    else if (color != tep->getColor())
+    {
+        F32 old_alpha = tep->getColor().mV[3];
+        if (color.mV[3] != old_alpha)
+        {
+            gPipeline.markTextured(mDrawable);
+            //treat this alpha change as an LoD update since render batches may need to get rebuilt
+            mLODChanged = TRUE;
+            gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
+        }
+        retval = LLPrimitive::setTEColor(te, color);
+        if (mDrawable.notNull() && retval)
+        {
+            // These should only happen on updates which are not the initial update.
             mColorChanged = TRUE;
-			mDrawable->setState(LLDrawable::REBUILD_COLOR);
+            mDrawable->setState(LLDrawable::REBUILD_COLOR);
             shrinkWrap();
-			dirtyMesh();
-		}
-	}
+            dirtyMesh();
+        }
+    }
 
-	return  retval;
+    return  retval;
 }
 
 S32 LLVOVolume::setTEBumpmap(const U8 te, const U8 bumpmap)
 {
-	S32 res = LLViewerObject::setTEBumpmap(te, bumpmap);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return  res;
+    S32 res = LLViewerObject::setTEBumpmap(te, bumpmap);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return  res;
 }
 
 S32 LLVOVolume::setTETexGen(const U8 te, const U8 texgen)
 {
-	S32 res = LLViewerObject::setTETexGen(te, texgen);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return  res;
+    S32 res = LLViewerObject::setTETexGen(te, texgen);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return  res;
 }
 
 S32 LLVOVolume::setTEMediaTexGen(const U8 te, const U8 media)
 {
-	S32 res = LLViewerObject::setTEMediaTexGen(te, media);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return  res;
+    S32 res = LLViewerObject::setTEMediaTexGen(te, media);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return  res;
 }
 
 S32 LLVOVolume::setTEShiny(const U8 te, const U8 shiny)
 {
-	S32 res = LLViewerObject::setTEShiny(te, shiny);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return  res;
+    S32 res = LLViewerObject::setTEShiny(te, shiny);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return  res;
 }
 
 S32 LLVOVolume::setTEFullbright(const U8 te, const U8 fullbright)
 {
-	S32 res = LLViewerObject::setTEFullbright(te, fullbright);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return  res;
+    S32 res = LLViewerObject::setTEFullbright(te, fullbright);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return  res;
 }
 
 S32 LLVOVolume::setTEBumpShinyFullbright(const U8 te, const U8 bump)
 {
-	S32 res = LLViewerObject::setTEBumpShinyFullbright(te, bump);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return res;
+    S32 res = LLViewerObject::setTEBumpShinyFullbright(te, bump);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return res;
 }
 
 S32 LLVOVolume::setTEMediaFlags(const U8 te, const U8 media_flags)
 {
-	S32 res = LLViewerObject::setTEMediaFlags(te, media_flags);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return  res;
+    S32 res = LLViewerObject::setTEMediaFlags(te, media_flags);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return  res;
 }
 
 S32 LLVOVolume::setTEGlow(const U8 te, const F32 glow)
 {
-	S32 res = LLViewerObject::setTEGlow(te, glow);
-	if (res)
-	{
+    S32 res = LLViewerObject::setTEGlow(te, glow);
+    if (res)
+    {
         if (mDrawable)
         {
             gPipeline.markTextured(mDrawable);
             shrinkWrap();
         }
-		mFaceMappingChanged = TRUE;
-	}
-	return  res;
+        mFaceMappingChanged = TRUE;
+    }
+    return  res;
 }
 
 void LLVOVolume::setTEMaterialParamsCallbackTE(const LLUUID& objectID, const LLMaterialID &pMaterialID, const LLMaterialPtr pMaterialParams, U32 te)
 {
-	LLVOVolume* pVol = (LLVOVolume*)gObjectList.findObject(objectID);
-	if (pVol)
-	{
+    LLVOVolume* pVol = (LLVOVolume*)gObjectList.findObject(objectID);
+    if (pVol)
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("MaterialTEs") << "materialid " << pMaterialID.asString() << " to TE " << te << LL_ENDL;
+        LL_DEBUGS("MaterialTEs") << "materialid " << pMaterialID.asString() << " to TE " << te << LL_ENDL;
 #endif
-		if (te >= pVol->getNumTEs())
-			return;
+        if (te >= pVol->getNumTEs())
+            return;
 
-		LLTextureEntry* texture_entry = pVol->getTE(te);
-		if (texture_entry && (texture_entry->getMaterialID() == pMaterialID))
-		{
-			pVol->setTEMaterialParams(te, pMaterialParams);
-		}
-	}
+        LLTextureEntry* texture_entry = pVol->getTE(te);
+        if (texture_entry && (texture_entry->getMaterialID() == pMaterialID))
+        {
+            pVol->setTEMaterialParams(te, pMaterialParams);
+        }
+    }
 }
 
 S32 LLVOVolume::setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID)
 {
-	S32 res = LLViewerObject::setTEMaterialID(te, pMaterialID);
+    S32 res = LLViewerObject::setTEMaterialID(te, pMaterialID);
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("MaterialTEs") << "te "<< (S32)te << " materialid " << pMaterialID.asString() << " res " << res
-								<< ( LLSelectMgr::getInstance()->getSelection()->contains(const_cast<LLVOVolume*>(this), te) ? " selected" : " not selected" )
-								<< LL_ENDL;
-		
-	LL_DEBUGS("MaterialTEs") << " " << pMaterialID.asString() << LL_ENDL;
+    LL_DEBUGS("MaterialTEs") << "te "<< (S32)te << " materialid " << pMaterialID.asString() << " res " << res
+                                << ( LLSelectMgr::getInstance()->getSelection()->contains(const_cast<LLVOVolume*>(this), te) ? " selected" : " not selected" )
+                                << LL_ENDL;
+
+    LL_DEBUGS("MaterialTEs") << " " << pMaterialID.asString() << LL_ENDL;
 #endif
-	if (res)
-	{
-		LLMaterialMgr::instance().getTE(getRegion()->getRegionID(), pMaterialID, te, boost::bind(&LLVOVolume::setTEMaterialParamsCallbackTE, getID(), _1, _2, _3));
+    if (res)
+    {
+        LLMaterialMgr::instance().getTE(getRegion()->getRegionID(), pMaterialID, te, boost::bind(&LLVOVolume::setTEMaterialParamsCallbackTE, getID(), _1, _2, _3));
 
-		setChanged(ALL_CHANGED);
-		if (!mDrawable.isNull())
-		{
-			gPipeline.markTextured(mDrawable);
-			gPipeline.markRebuild(mDrawable,LLDrawable::REBUILD_ALL);
-		}
-		mFaceMappingChanged = TRUE;
-	}
-	return res;
+        setChanged(ALL_CHANGED);
+        if (!mDrawable.isNull())
+        {
+            gPipeline.markTextured(mDrawable);
+            gPipeline.markRebuild(mDrawable,LLDrawable::REBUILD_ALL);
+        }
+        mFaceMappingChanged = TRUE;
+    }
+    return res;
 }
 
 S32 LLVOVolume::setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams)
 {
-	S32 res = LLViewerObject::setTEMaterialParams(te, pMaterialParams);
+    S32 res = LLViewerObject::setTEMaterialParams(te, pMaterialParams);
 
-	LL_DEBUGS("MaterialTEs") << "te " << (S32)te << " material " << ((pMaterialParams) ? pMaterialParams->asLLSD() : LLSD("null")) << " res " << res
-							 << ( LLSelectMgr::getInstance()->getSelection()->contains(const_cast<LLVOVolume*>(this), te) ? " selected" : " not selected" )
-							 << LL_ENDL;
+    LL_DEBUGS("MaterialTEs") << "te " << (S32)te << " material " << ((pMaterialParams) ? pMaterialParams->asLLSD() : LLSD("null")) << " res " << res
+                             << ( LLSelectMgr::getInstance()->getSelection()->contains(const_cast<LLVOVolume*>(this), te) ? " selected" : " not selected" )
+                             << LL_ENDL;
 
-	setChanged(ALL_CHANGED);
-	if (!mDrawable.isNull())
-	{
-		gPipeline.markTextured(mDrawable);
-		gPipeline.markRebuild(mDrawable,LLDrawable::REBUILD_ALL);
-	}
-	mFaceMappingChanged = TRUE;
-	return TEM_CHANGE_TEXTURE;
+    setChanged(ALL_CHANGED);
+    if (!mDrawable.isNull())
+    {
+        gPipeline.markTextured(mDrawable);
+        gPipeline.markRebuild(mDrawable,LLDrawable::REBUILD_ALL);
+    }
+    mFaceMappingChanged = TRUE;
+    return TEM_CHANGE_TEXTURE;
 }
 
 S32 LLVOVolume::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* mat)
@@ -2455,234 +2455,234 @@ S32 LLVOVolume::setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* mat)
 
 S32 LLVOVolume::setTEScale(const U8 te, const F32 s, const F32 t)
 {
-	S32 res = LLViewerObject::setTEScale(te, s, t);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return res;
+    S32 res = LLViewerObject::setTEScale(te, s, t);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return res;
 }
 
 S32 LLVOVolume::setTEScaleS(const U8 te, const F32 s)
 {
-	S32 res = LLViewerObject::setTEScaleS(te, s);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return res;
+    S32 res = LLViewerObject::setTEScaleS(te, s);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return res;
 }
 
 S32 LLVOVolume::setTEScaleT(const U8 te, const F32 t)
 {
-	S32 res = LLViewerObject::setTEScaleT(te, t);
-	if (res)
-	{
-		gPipeline.markTextured(mDrawable);
-		mFaceMappingChanged = TRUE;
-	}
-	return res;
+    S32 res = LLViewerObject::setTEScaleT(te, t);
+    if (res)
+    {
+        gPipeline.markTextured(mDrawable);
+        mFaceMappingChanged = TRUE;
+    }
+    return res;
 }
 
 bool LLVOVolume::hasMedia() const
 {
-	bool result = false;
-	const U8 numTEs = getNumTEs();
-	for (U8 i = 0; i < numTEs; i++)
-	{
-		const LLTextureEntry* te = getTE(i);
-		if(te && te->hasMedia())
-		{
-			result = true;
-			break;
-		}
-	}
-	return result;
+    bool result = false;
+    const U8 numTEs = getNumTEs();
+    for (U8 i = 0; i < numTEs; i++)
+    {
+        const LLTextureEntry* te = getTE(i);
+        if(te && te->hasMedia())
+        {
+            result = true;
+            break;
+        }
+    }
+    return result;
 }
 
 LLVector3 LLVOVolume::getApproximateFaceNormal(U8 face_id)
 {
-	LLVolume* volume = getVolume();
-	LLVector4a result;
-	result.clear();
+    LLVolume* volume = getVolume();
+    LLVector4a result;
+    result.clear();
 
-	LLVector3 ret;
+    LLVector3 ret;
+
+    if (volume && face_id < volume->getNumVolumeFaces())
+    {
+        const LLVolumeFace& face = volume->getVolumeFace(face_id);
+        for (S32 i = 0; i < (S32)face.mNumVertices; ++i)
+        {
+            result.add(face.mNormals[i]);
+        }
 
-	if (volume && face_id < volume->getNumVolumeFaces())
-	{
-		const LLVolumeFace& face = volume->getVolumeFace(face_id);
-		for (S32 i = 0; i < (S32)face.mNumVertices; ++i)
-		{
-			result.add(face.mNormals[i]);
-		}
+        ret = LLVector3(result.getF32ptr());
+        ret = volumeDirectionToAgent(ret);
+        ret.normVec();
+    }
 
-		ret = LLVector3(result.getF32ptr());
-		ret = volumeDirectionToAgent(ret);
-		ret.normVec();
-	}
-	
-	return ret;
+    return ret;
 }
 
 void LLVOVolume::requestMediaDataUpdate(bool isNew)
 {
     if (sObjectMediaClient)
-		sObjectMediaClient->fetchMedia(new LLMediaDataClientObjectImpl(this, isNew));
+        sObjectMediaClient->fetchMedia(new LLMediaDataClientObjectImpl(this, isNew));
 }
 
 bool LLVOVolume::isMediaDataBeingFetched() const
 {
-	// I know what I'm doing by const_casting this away: this is just 
-	// a wrapper class that is only going to do a lookup.
-	return (sObjectMediaClient) ? sObjectMediaClient->isInQueue(new LLMediaDataClientObjectImpl(const_cast<LLVOVolume*>(this), false)) : false;
+    // I know what I'm doing by const_casting this away: this is just
+    // a wrapper class that is only going to do a lookup.
+    return (sObjectMediaClient) ? sObjectMediaClient->isInQueue(new LLMediaDataClientObjectImpl(const_cast<LLVOVolume*>(this), false)) : false;
 }
 
 void LLVOVolume::cleanUpMediaImpls()
 {
-	// Iterate through our TEs and remove any Impls that are no longer used
-	const U8 numTEs = getNumTEs();
-	for (U8 i = 0; i < numTEs; i++)
-	{
-		const LLTextureEntry* te = getTE(i);
-		if(te && !te->hasMedia())
-		{
-			// Delete the media IMPL!
-			removeMediaImpl(i) ;
-		}
-	}
+    // Iterate through our TEs and remove any Impls that are no longer used
+    const U8 numTEs = getNumTEs();
+    for (U8 i = 0; i < numTEs; i++)
+    {
+        const LLTextureEntry* te = getTE(i);
+        if(te && !te->hasMedia())
+        {
+            // Delete the media IMPL!
+            removeMediaImpl(i) ;
+        }
+    }
 }
 
 void LLVOVolume::updateObjectMediaData(const LLSD &media_data_array, const std::string &media_version)
 {
-	// media_data_array is an array of media entry maps
-	// media_version is the version string in the response.
-	U32 fetched_version = LLTextureEntry::getVersionFromMediaVersionString(media_version);
-
-	// Only update it if it is newer!
-	if ( (S32)fetched_version > mLastFetchedMediaVersion)
-	{
-		mLastFetchedMediaVersion = fetched_version;
-		//LL_INFOS() << "updating:" << this->getID() << " " << ll_pretty_print_sd(media_data_array) << LL_ENDL;
-		
-		LLSD::array_const_iterator iter = media_data_array.beginArray();
-		LLSD::array_const_iterator end = media_data_array.endArray();
-		U8 texture_index = 0;
-		for (; iter != end; ++iter, ++texture_index)
-		{
-			syncMediaData(texture_index, *iter, false/*merge*/, false/*ignore_agent*/);
-		}
-	}
+    // media_data_array is an array of media entry maps
+    // media_version is the version string in the response.
+    U32 fetched_version = LLTextureEntry::getVersionFromMediaVersionString(media_version);
+
+    // Only update it if it is newer!
+    if ( (S32)fetched_version > mLastFetchedMediaVersion)
+    {
+        mLastFetchedMediaVersion = fetched_version;
+        //LL_INFOS() << "updating:" << this->getID() << " " << ll_pretty_print_sd(media_data_array) << LL_ENDL;
+
+        LLSD::array_const_iterator iter = media_data_array.beginArray();
+        LLSD::array_const_iterator end = media_data_array.endArray();
+        U8 texture_index = 0;
+        for (; iter != end; ++iter, ++texture_index)
+        {
+            syncMediaData(texture_index, *iter, false/*merge*/, false/*ignore_agent*/);
+        }
+    }
 }
 
 void LLVOVolume::syncMediaData(S32 texture_index, const LLSD &media_data, bool merge, bool ignore_agent)
 {
-	if(mDead)
-	{
-		// If the object has been marked dead, don't process media updates.
-		return;
-	}
-	
-	LLTextureEntry *te = getTE(texture_index);
-	if(!te)
-	{
-		return ;
-	}
+    if(mDead)
+    {
+        // If the object has been marked dead, don't process media updates.
+        return;
+    }
+
+    LLTextureEntry *te = getTE(texture_index);
+    if(!te)
+    {
+        return ;
+    }
 
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("MediaOnAPrim") << "BEFORE: texture_index = " << texture_index
-		<< " hasMedia = " << te->hasMedia() << " : " 
-		<< ((NULL == te->getMediaData()) ? "NULL MEDIA DATA" : ll_pretty_print_sd(te->getMediaData()->asLLSD())) << LL_ENDL;
+    LL_DEBUGS("MediaOnAPrim") << "BEFORE: texture_index = " << texture_index
+        << " hasMedia = " << te->hasMedia() << " : "
+        << ((NULL == te->getMediaData()) ? "NULL MEDIA DATA" : ll_pretty_print_sd(te->getMediaData()->asLLSD())) << LL_ENDL;
 #endif
 
-	std::string previous_url;
-	LLMediaEntry* mep = te->getMediaData();
-	if(mep)
-	{
-		// Save the "current url" from before the update so we can tell if
-		// it changes. 
-		previous_url = mep->getCurrentURL();
-	}
-
-	if (merge)
-	{
-		te->mergeIntoMediaData(media_data);
-	}
-	else {
-		// XXX Question: what if the media data is undefined LLSD, but the
-		// update we got above said that we have media flags??	Here we clobber
-		// that, assuming the data from the service is more up-to-date. 
-		te->updateMediaData(media_data);
-	}
-
-	mep = te->getMediaData();
-	if(mep)
-	{
-		bool update_from_self = false;
-		if (!ignore_agent) 
-		{
-			LLUUID updating_agent = LLTextureEntry::getAgentIDFromMediaVersionString(getMediaURL());
-			update_from_self = (updating_agent == gAgent.getID());
-		}
-		viewer_media_t media_impl = LLViewerMedia::getInstance()->updateMediaImpl(mep, previous_url, update_from_self, isHUDAttachment());
-			
-		addMediaImpl(media_impl, texture_index) ;
-	}
-	else
-	{
-		removeMediaImpl(texture_index);
-	}
+    std::string previous_url;
+    LLMediaEntry* mep = te->getMediaData();
+    if(mep)
+    {
+        // Save the "current url" from before the update so we can tell if
+        // it changes.
+        previous_url = mep->getCurrentURL();
+    }
+
+    if (merge)
+    {
+        te->mergeIntoMediaData(media_data);
+    }
+    else {
+        // XXX Question: what if the media data is undefined LLSD, but the
+        // update we got above said that we have media flags??  Here we clobber
+        // that, assuming the data from the service is more up-to-date.
+        te->updateMediaData(media_data);
+    }
+
+    mep = te->getMediaData();
+    if(mep)
+    {
+        bool update_from_self = false;
+        if (!ignore_agent)
+        {
+            LLUUID updating_agent = LLTextureEntry::getAgentIDFromMediaVersionString(getMediaURL());
+            update_from_self = (updating_agent == gAgent.getID());
+        }
+        viewer_media_t media_impl = LLViewerMedia::getInstance()->updateMediaImpl(mep, previous_url, update_from_self, isHUDAttachment());
+
+        addMediaImpl(media_impl, texture_index) ;
+    }
+    else
+    {
+        removeMediaImpl(texture_index);
+    }
 
 #ifdef SHOW_DEBUG
-	LL_DEBUGS("MediaOnAPrim") << "AFTER: texture_index = " << texture_index
-		<< " hasMedia = " << te->hasMedia() << " : " 
-		<< ((NULL == te->getMediaData()) ? "NULL MEDIA DATA" : ll_pretty_print_sd(te->getMediaData()->asLLSD())) << LL_ENDL;
+    LL_DEBUGS("MediaOnAPrim") << "AFTER: texture_index = " << texture_index
+        << " hasMedia = " << te->hasMedia() << " : "
+        << ((NULL == te->getMediaData()) ? "NULL MEDIA DATA" : ll_pretty_print_sd(te->getMediaData()->asLLSD())) << LL_ENDL;
 #endif
 }
 
 void LLVOVolume::mediaNavigateBounceBack(U8 texture_index)
 {
-	// Find the media entry for this navigate
-	const LLMediaEntry* mep = NULL;
-	viewer_media_t impl = getMediaImpl(texture_index);
-	LLTextureEntry *te = getTE(texture_index);
-	if(te)
-	{
-		mep = te->getMediaData();
-	}
-	
-	if (mep && impl)
-	{
+    // Find the media entry for this navigate
+    const LLMediaEntry* mep = NULL;
+    viewer_media_t impl = getMediaImpl(texture_index);
+    LLTextureEntry *te = getTE(texture_index);
+    if(te)
+    {
+        mep = te->getMediaData();
+    }
+
+    if (mep && impl)
+    {
         std::string url = mep->getCurrentURL();
-		// Look for a ":", if not there, assume "http://"
-		if (!url.empty() && std::string::npos == url.find(':')) 
-		{
-			url = "http://" + url;
-		}
-		// If the url we're trying to "bounce back" to is either empty or not
-		// allowed by the whitelist, try the home url.  If *that* doesn't work,
-		// set the media as failed and unload it
+        // Look for a ":", if not there, assume "http://"
+        if (!url.empty() && std::string::npos == url.find(':'))
+        {
+            url = "http://" + url;
+        }
+        // If the url we're trying to "bounce back" to is either empty or not
+        // allowed by the whitelist, try the home url.  If *that* doesn't work,
+        // set the media as failed and unload it
         if (url.empty() || !mep->checkCandidateUrl(url))
         {
             url = mep->getHomeURL();
-			// Look for a ":", if not there, assume "http://"
-			if (!url.empty() && std::string::npos == url.find(':')) 
-			{
-				url = "http://" + url;
-			}
+            // Look for a ":", if not there, assume "http://"
+            if (!url.empty() && std::string::npos == url.find(':'))
+            {
+                url = "http://" + url;
+            }
         }
         if (url.empty() || !mep->checkCandidateUrl(url))
-		{
-			// The url to navigate back to is not good, and we have nowhere else
-			// to go.
-			LL_WARNS("MediaOnAPrim") << "FAILED to bounce back URL \"" << url << "\" -- unloading impl" << LL_ENDL;
-			impl->setMediaFailed(true);
-		}
-		// Make sure we are not bouncing to url we came from
-		else if (impl->getCurrentMediaURL() != url) 
-		{
-			// Okay, navigate now
+        {
+            // The url to navigate back to is not good, and we have nowhere else
+            // to go.
+            LL_WARNS("MediaOnAPrim") << "FAILED to bounce back URL \"" << url << "\" -- unloading impl" << LL_ENDL;
+            impl->setMediaFailed(true);
+        }
+        // Make sure we are not bouncing to url we came from
+        else if (impl->getCurrentMediaURL() != url)
+        {
+            // Okay, navigate now
             LL_INFOS("MediaOnAPrim") << "bouncing back to URL: " << url << LL_ENDL;
             impl->navigateTo(url, "", false, true);
         }
@@ -2693,156 +2693,156 @@ bool LLVOVolume::hasMediaPermission(const LLMediaEntry* media_entry, MediaPermTy
 {
     // NOTE: This logic ALMOST duplicates the logic in the server (in particular, in llmediaservice.cpp).
     if (NULL == media_entry ) return false; // XXX should we assert here?
-    
+
     // The agent has permissions if:
     // - world permissions are on, or
     // - group permissions are on, and agent_id is in the group, or
     // - agent permissions are on, and agent_id is the owner
-    
-	// *NOTE: We *used* to check for modify permissions here (i.e. permissions were
-	// granted if permModify() was true).  However, this doesn't make sense in the
-	// viewer: we don't want to show controls or allow interaction if the author
-	// has deemed it so.  See DEV-42115.
-	
+
+    // *NOTE: We *used* to check for modify permissions here (i.e. permissions were
+    // granted if permModify() was true).  However, this doesn't make sense in the
+    // viewer: we don't want to show controls or allow interaction if the author
+    // has deemed it so.  See DEV-42115.
+
     U8 media_perms = (perm_type == MEDIA_PERM_INTERACT) ? media_entry->getPermsInteract() : media_entry->getPermsControl();
-    
+
     // World permissions
-    if (0 != (media_perms & LLMediaEntry::PERM_ANYONE)) 
+    if (0 != (media_perms & LLMediaEntry::PERM_ANYONE))
     {
         return true;
     }
-    
+
     // Group permissions
     else if (0 != (media_perms & LLMediaEntry::PERM_GROUP))
     {
-		LLPermissions* obj_perm = LLSelectMgr::getInstance()->findObjectPermissions(this);
-		if (obj_perm && gAgent.isInGroup(obj_perm->getGroup()))
-		{
-			return true;
-		}
+        LLPermissions* obj_perm = LLSelectMgr::getInstance()->findObjectPermissions(this);
+        if (obj_perm && gAgent.isInGroup(obj_perm->getGroup()))
+        {
+            return true;
+        }
     }
-    
+
     // Owner permissions
-    else if (0 != (media_perms & LLMediaEntry::PERM_OWNER) && permYouOwner()) 
+    else if (0 != (media_perms & LLMediaEntry::PERM_OWNER) && permYouOwner())
+    {
+        return true;
+    }
+
+    return false;
+
+}
+
+void LLVOVolume::mediaNavigated(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin, std::string new_location)
+{
+    bool block_navigation = false;
+    // FIXME: if/when we allow the same media impl to be used by multiple faces, the logic here will need to be fixed
+    // to deal with multiple face indices.
+    int face_index = getFaceIndexWithMediaImpl(impl, -1);
+
+    // Find the media entry for this navigate
+    LLMediaEntry* mep = NULL;
+    LLTextureEntry *te = getTE(face_index);
+    if(te)
+    {
+        mep = te->getMediaData();
+    }
+
+    if(mep)
+    {
+        if(!mep->checkCandidateUrl(new_location))
+        {
+            block_navigation = true;
+        }
+        if (!block_navigation && !hasMediaPermission(mep, MEDIA_PERM_INTERACT))
+        {
+            block_navigation = true;
+        }
+    }
+    else
     {
-        return true;
+        LL_WARNS("MediaOnAPrim") << "Couldn't find media entry!" << LL_ENDL;
     }
-    
-    return false;
-    
-}
 
-void LLVOVolume::mediaNavigated(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin, std::string new_location)
-{
-	bool block_navigation = false;
-	// FIXME: if/when we allow the same media impl to be used by multiple faces, the logic here will need to be fixed
-	// to deal with multiple face indices.
-	int face_index = getFaceIndexWithMediaImpl(impl, -1);
-	
-	// Find the media entry for this navigate
-	LLMediaEntry* mep = NULL;
-	LLTextureEntry *te = getTE(face_index);
-	if(te)
-	{
-		mep = te->getMediaData();
-	}
-	
-	if(mep)
-	{
-		if(!mep->checkCandidateUrl(new_location))
-		{
-			block_navigation = true;
-		}
-		if (!block_navigation && !hasMediaPermission(mep, MEDIA_PERM_INTERACT))
-		{
-			block_navigation = true;
-		}
-	}
-	else
-	{
-		LL_WARNS("MediaOnAPrim") << "Couldn't find media entry!" << LL_ENDL;
-	}
-						
-	if(block_navigation)
-	{
-		LL_INFOS("MediaOnAPrim") << "blocking navigate to URI " << new_location << LL_ENDL;
-
-		// "bounce back" to the current URL from the media entry
-		mediaNavigateBounceBack(face_index);
-	}
-	else if (sObjectMediaNavigateClient)
-	{
+    if(block_navigation)
+    {
+        LL_INFOS("MediaOnAPrim") << "blocking navigate to URI " << new_location << LL_ENDL;
+
+        // "bounce back" to the current URL from the media entry
+        mediaNavigateBounceBack(face_index);
+    }
+    else if (sObjectMediaNavigateClient)
+    {
 #ifdef SHOW_DEBUG
-		LL_DEBUGS("MediaOnAPrim") << "broadcasting navigate with URI " << new_location << LL_ENDL;
+        LL_DEBUGS("MediaOnAPrim") << "broadcasting navigate with URI " << new_location << LL_ENDL;
 #endif
 
-		sObjectMediaNavigateClient->navigate(new LLMediaDataClientObjectImpl(this, false), face_index, new_location);
-	}
+        sObjectMediaNavigateClient->navigate(new LLMediaDataClientObjectImpl(this, false), face_index, new_location);
+    }
 }
 
 void LLVOVolume::mediaEvent(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin, LLViewerMediaObserver::EMediaEvent event)
 {
-	switch(event)
-	{
-		
-		case LLViewerMediaObserver::MEDIA_EVENT_LOCATION_CHANGED:
-		{			
-			switch(impl->getNavState())
-			{
-				case LLViewerMediaImpl::MEDIANAVSTATE_FIRST_LOCATION_CHANGED:
-				{
-					// This is the first location changed event after the start of a non-server-directed nav.  It may need to be broadcast or bounced back.
-					mediaNavigated(impl, plugin, plugin->getLocation());
-				}
-				break;
-				
-				case LLViewerMediaImpl::MEDIANAVSTATE_FIRST_LOCATION_CHANGED_SPURIOUS:
-					// This navigate didn't change the current URL.  
-					LL_DEBUGS("MediaOnAPrim") << "	NOT broadcasting navigate (spurious)" << LL_ENDL;
-				break;
-				
-				case LLViewerMediaImpl::MEDIANAVSTATE_SERVER_FIRST_LOCATION_CHANGED:
-					// This is the first location changed event after the start of a server-directed nav.  Don't broadcast it.
-					LL_INFOS("MediaOnAPrim") << "	NOT broadcasting navigate (server-directed)" << LL_ENDL;
-				break;
-				
-				default:
-					// This is a subsequent location-changed due to a redirect.	 Don't broadcast.
-					LL_INFOS("MediaOnAPrim") << "	NOT broadcasting navigate (redirect)" << LL_ENDL;
-				break;
-			}
-		}
-		break;
-		
-		case LLViewerMediaObserver::MEDIA_EVENT_NAVIGATE_COMPLETE:
-		{
-			switch(impl->getNavState())
-			{
-				case LLViewerMediaImpl::MEDIANAVSTATE_COMPLETE_BEFORE_LOCATION_CHANGED:
-				{
-					// This is the first location changed event after the start of a non-server-directed nav.  It may need to be broadcast or bounced back.
-					mediaNavigated(impl, plugin, plugin->getNavigateURI());
-				}
-				break;
-				
-				case LLViewerMediaImpl::MEDIANAVSTATE_COMPLETE_BEFORE_LOCATION_CHANGED_SPURIOUS:
-					// This navigate didn't change the current URL.  
+    switch(event)
+    {
+
+        case LLViewerMediaObserver::MEDIA_EVENT_LOCATION_CHANGED:
+        {
+            switch(impl->getNavState())
+            {
+                case LLViewerMediaImpl::MEDIANAVSTATE_FIRST_LOCATION_CHANGED:
+                {
+                    // This is the first location changed event after the start of a non-server-directed nav.  It may need to be broadcast or bounced back.
+                    mediaNavigated(impl, plugin, plugin->getLocation());
+                }
+                break;
+
+                case LLViewerMediaImpl::MEDIANAVSTATE_FIRST_LOCATION_CHANGED_SPURIOUS:
+                    // This navigate didn't change the current URL.
+                    LL_DEBUGS("MediaOnAPrim") << "  NOT broadcasting navigate (spurious)" << LL_ENDL;
+                break;
+
+                case LLViewerMediaImpl::MEDIANAVSTATE_SERVER_FIRST_LOCATION_CHANGED:
+                    // This is the first location changed event after the start of a server-directed nav.  Don't broadcast it.
+                    LL_INFOS("MediaOnAPrim") << "   NOT broadcasting navigate (server-directed)" << LL_ENDL;
+                break;
+
+                default:
+                    // This is a subsequent location-changed due to a redirect.  Don't broadcast.
+                    LL_INFOS("MediaOnAPrim") << "   NOT broadcasting navigate (redirect)" << LL_ENDL;
+                break;
+            }
+        }
+        break;
+
+        case LLViewerMediaObserver::MEDIA_EVENT_NAVIGATE_COMPLETE:
+        {
+            switch(impl->getNavState())
+            {
+                case LLViewerMediaImpl::MEDIANAVSTATE_COMPLETE_BEFORE_LOCATION_CHANGED:
+                {
+                    // This is the first location changed event after the start of a non-server-directed nav.  It may need to be broadcast or bounced back.
+                    mediaNavigated(impl, plugin, plugin->getNavigateURI());
+                }
+                break;
+
+                case LLViewerMediaImpl::MEDIANAVSTATE_COMPLETE_BEFORE_LOCATION_CHANGED_SPURIOUS:
+                    // This navigate didn't change the current URL.
 #ifdef SHOW_DEBUG
-					LL_DEBUGS("MediaOnAPrim") << "	NOT broadcasting navigate (spurious)" << LL_ENDL;
+                    LL_DEBUGS("MediaOnAPrim") << "  NOT broadcasting navigate (spurious)" << LL_ENDL;
 #endif
-				break;
-
-				case LLViewerMediaImpl::MEDIANAVSTATE_SERVER_COMPLETE_BEFORE_LOCATION_CHANGED:
-					// This is the the navigate complete event from a server-directed nav.  Don't broadcast it.
-					LL_INFOS("MediaOnAPrim") << "	NOT broadcasting navigate (server-directed)" << LL_ENDL;
-				break;
-				
-				default:
-					// For all other states, the navigate should have been handled by LOCATION_CHANGED events already.
-				break;
-			}
-		}
-		break;
+                break;
+
+                case LLViewerMediaImpl::MEDIANAVSTATE_SERVER_COMPLETE_BEFORE_LOCATION_CHANGED:
+                    // This is the the navigate complete event from a server-directed nav.  Don't broadcast it.
+                    LL_INFOS("MediaOnAPrim") << "   NOT broadcasting navigate (server-directed)" << LL_ENDL;
+                break;
+
+                default:
+                    // For all other states, the navigate should have been handled by LOCATION_CHANGED events already.
+                break;
+            }
+        }
+        break;
 
         case LLViewerMediaObserver::MEDIA_EVENT_FILE_DOWNLOAD:
         {
@@ -2854,233 +2854,233 @@ void LLVOVolume::mediaEvent(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin,
             LLNotificationsUtil::add("MediaFileDownloadUnsupported");
         }
         break;
-		
-		default:
-		break;
-	}
+
+        default:
+        break;
+    }
 
 }
 
 void LLVOVolume::sendMediaDataUpdate()
 {
     if (sObjectMediaClient)
-		sObjectMediaClient->updateMedia(new LLMediaDataClientObjectImpl(this, false));
+        sObjectMediaClient->updateMedia(new LLMediaDataClientObjectImpl(this, false));
 }
 
 void LLVOVolume::removeMediaImpl(S32 texture_index)
 {
-	if(mMediaImplList.size() <= (U32)texture_index || mMediaImplList[texture_index].isNull())
-	{
-		return ;
-	}
-
-	//make the face referencing to mMediaImplList[texture_index] to point back to the old texture.
-	if(mDrawable && texture_index < mDrawable->getNumFaces())
-	{
-		LLFace* facep = mDrawable->getFace(texture_index) ;
-		if(facep)
-		{
-			LLViewerMediaTexture* media_tex = LLViewerTextureManager::findMediaTexture(mMediaImplList[texture_index]->getMediaTextureID()) ;
-			if(media_tex)
-			{
-				media_tex->removeMediaFromFace(facep) ;
-			}
-		}
-	}		
-	
-	//check if some other face(s) of this object reference(s)to this media impl.
-	S32 i ;
-	S32 end = (S32)mMediaImplList.size() ;
-	for(i = 0; i < end ; i++)
-	{
-		if( i != texture_index && mMediaImplList[i] == mMediaImplList[texture_index])
-		{
-			break ;
-		}
-	}
-
-	if(i == end) //this object does not need this media impl.
-	{
-		mMediaImplList[texture_index]->removeObject(this) ;
-	}
-
-	mMediaImplList[texture_index] = NULL ;
-	return ;
+    if(mMediaImplList.size() <= (U32)texture_index || mMediaImplList[texture_index].isNull())
+    {
+        return ;
+    }
+
+    //make the face referencing to mMediaImplList[texture_index] to point back to the old texture.
+    if(mDrawable && texture_index < mDrawable->getNumFaces())
+    {
+        LLFace* facep = mDrawable->getFace(texture_index) ;
+        if(facep)
+        {
+            LLViewerMediaTexture* media_tex = LLViewerTextureManager::findMediaTexture(mMediaImplList[texture_index]->getMediaTextureID()) ;
+            if(media_tex)
+            {
+                media_tex->removeMediaFromFace(facep) ;
+            }
+        }
+    }
+
+    //check if some other face(s) of this object reference(s)to this media impl.
+    S32 i ;
+    S32 end = (S32)mMediaImplList.size() ;
+    for(i = 0; i < end ; i++)
+    {
+        if( i != texture_index && mMediaImplList[i] == mMediaImplList[texture_index])
+        {
+            break ;
+        }
+    }
+
+    if(i == end) //this object does not need this media impl.
+    {
+        mMediaImplList[texture_index]->removeObject(this) ;
+    }
+
+    mMediaImplList[texture_index] = NULL ;
+    return ;
 }
 
 void LLVOVolume::addMediaImpl(LLViewerMediaImpl* media_impl, S32 texture_index)
 {
-	if((S32)mMediaImplList.size() < texture_index + 1)
-	{
-		mMediaImplList.resize(texture_index + 1) ;
-	}
-	
-	if(mMediaImplList[texture_index].notNull())
-	{
-		if(mMediaImplList[texture_index] == media_impl)
-		{
-			return ;
-		}
-
-		removeMediaImpl(texture_index) ;
-	}
-
-	mMediaImplList[texture_index] = media_impl;
-	media_impl->addObject(this) ;	
-
-	//add the face to show the media if it is in playing
-	if(mDrawable)
-	{
-		LLFace* facep(NULL);
-		if( texture_index < mDrawable->getNumFaces() )
-		{
-			facep = mDrawable->getFace(texture_index) ;
-		}
-
-		if(facep)
-		{
-			LLViewerMediaTexture* media_tex = LLViewerTextureManager::findMediaTexture(mMediaImplList[texture_index]->getMediaTextureID()) ;
-			if(media_tex)
-			{
-				media_tex->addMediaToFace(facep) ;
-			}
-		}
-		else //the face is not available now, start media on this face later.
-		{
-			media_impl->setUpdated(TRUE) ;
-		}
-	}
-	return ;
+    if((S32)mMediaImplList.size() < texture_index + 1)
+    {
+        mMediaImplList.resize(texture_index + 1) ;
+    }
+
+    if(mMediaImplList[texture_index].notNull())
+    {
+        if(mMediaImplList[texture_index] == media_impl)
+        {
+            return ;
+        }
+
+        removeMediaImpl(texture_index) ;
+    }
+
+    mMediaImplList[texture_index] = media_impl;
+    media_impl->addObject(this) ;
+
+    //add the face to show the media if it is in playing
+    if(mDrawable)
+    {
+        LLFace* facep(NULL);
+        if( texture_index < mDrawable->getNumFaces() )
+        {
+            facep = mDrawable->getFace(texture_index) ;
+        }
+
+        if(facep)
+        {
+            LLViewerMediaTexture* media_tex = LLViewerTextureManager::findMediaTexture(mMediaImplList[texture_index]->getMediaTextureID()) ;
+            if(media_tex)
+            {
+                media_tex->addMediaToFace(facep) ;
+            }
+        }
+        else //the face is not available now, start media on this face later.
+        {
+            media_impl->setUpdated(TRUE) ;
+        }
+    }
+    return ;
 }
 
 viewer_media_t LLVOVolume::getMediaImpl(U8 face_id) const
 {
-	if(mMediaImplList.size() > face_id)
-	{
-		return mMediaImplList[face_id];
-	}
-	return NULL;
+    if(mMediaImplList.size() > face_id)
+    {
+        return mMediaImplList[face_id];
+    }
+    return NULL;
 }
 
 F64 LLVOVolume::getTotalMediaInterest() const
 {
-	// If this object is currently focused, this object has "high" interest
-	if (LLViewerMediaFocus::getInstance()->getFocusedObjectID() == getID())
-		return F64_MAX;
-	
-	F64 interest = (F64)-1.0;  // means not interested;
-    
-	// If this object is selected, this object has "high" interest, but since 
-	// there can be more than one, we still add in calculated impl interest
-	// XXX Sadly, 'contains()' doesn't take a const :(
-	if (LLSelectMgr::getInstance()->getSelection()->contains(const_cast<LLVOVolume*>(this)))
-		interest = F64_MAX / 2.0;
-	
-	int i = 0;
-	const int end = getNumTEs();
-	for ( ; i < end; ++i)
-	{
-		const viewer_media_t &impl = getMediaImpl(i);
-		if (!impl.isNull())
-		{
-			if (interest == (F64)-1.0) interest = (F64)0.0;
-			interest += impl->getInterest();
-		}
-	}
-	return interest;
+    // If this object is currently focused, this object has "high" interest
+    if (LLViewerMediaFocus::getInstance()->getFocusedObjectID() == getID())
+        return F64_MAX;
+
+    F64 interest = (F64)-1.0;  // means not interested;
+
+    // If this object is selected, this object has "high" interest, but since
+    // there can be more than one, we still add in calculated impl interest
+    // XXX Sadly, 'contains()' doesn't take a const :(
+    if (LLSelectMgr::getInstance()->getSelection()->contains(const_cast<LLVOVolume*>(this)))
+        interest = F64_MAX / 2.0;
+
+    int i = 0;
+    const int end = getNumTEs();
+    for ( ; i < end; ++i)
+    {
+        const viewer_media_t &impl = getMediaImpl(i);
+        if (!impl.isNull())
+        {
+            if (interest == (F64)-1.0) interest = (F64)0.0;
+            interest += impl->getInterest();
+        }
+    }
+    return interest;
 }
 
 S32 LLVOVolume::getFaceIndexWithMediaImpl(const LLViewerMediaImpl* media_impl, S32 start_face_id)
 {
-	S32 end = (S32)mMediaImplList.size() ;
-	for(S32 face_id = start_face_id + 1; face_id < end; face_id++)
-	{
-		if(mMediaImplList[face_id] == media_impl)
-		{
-			return face_id ;
-		}
-	}
-	return -1 ;
+    S32 end = (S32)mMediaImplList.size() ;
+    for(S32 face_id = start_face_id + 1; face_id < end; face_id++)
+    {
+        if(mMediaImplList[face_id] == media_impl)
+        {
+            return face_id ;
+        }
+    }
+    return -1 ;
 }
 
 //----------------------------------------------------------------------------
 
 void LLVOVolume::setLightTextureID(LLUUID id)
 {
-	LLViewerTexture* old_texturep = getLightTexture(); // same as mLightTexture, but inits if nessesary
-	if (id.notNull())
-	{
-		if (!hasLightTexture())
-		{
-			setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, TRUE, true);
-		}
-		else if (old_texturep)
-		{	
-			old_texturep->removeVolume(LLRender::LIGHT_TEX, this);
-		}
-		LLLightImageParams* param_block = (LLLightImageParams*)getLightImageParams();
-		if (param_block && param_block->getLightTexture() != id)
-		{
-			param_block->setLightTexture(id);
-			parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
-		}
-		LLViewerTexture* tex = getLightTexture();
-		if (tex)
-		{
-			tex->addVolume(LLRender::LIGHT_TEX, this); // new texture
-		}
-		else
-		{
-			LL_WARNS() << "Can't get light texture for ID " << id.asString() << LL_ENDL;
-		}
-	}
-	else if (hasLightTexture())
-	{
-		if (old_texturep)
-		{
-			old_texturep->removeVolume(LLRender::LIGHT_TEX, this);
-		}
-		setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, FALSE, true);
-		parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
-		mLightTexture = NULL;
-	}		
+    LLViewerTexture* old_texturep = getLightTexture(); // same as mLightTexture, but inits if nessesary
+    if (id.notNull())
+    {
+        if (!hasLightTexture())
+        {
+            setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, TRUE, true);
+        }
+        else if (old_texturep)
+        {
+            old_texturep->removeVolume(LLRender::LIGHT_TEX, this);
+        }
+        LLLightImageParams* param_block = (LLLightImageParams*)getLightImageParams();
+        if (param_block && param_block->getLightTexture() != id)
+        {
+            param_block->setLightTexture(id);
+            parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
+        }
+        LLViewerTexture* tex = getLightTexture();
+        if (tex)
+        {
+            tex->addVolume(LLRender::LIGHT_TEX, this); // new texture
+        }
+        else
+        {
+            LL_WARNS() << "Can't get light texture for ID " << id.asString() << LL_ENDL;
+        }
+    }
+    else if (hasLightTexture())
+    {
+        if (old_texturep)
+        {
+            old_texturep->removeVolume(LLRender::LIGHT_TEX, this);
+        }
+        setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT_IMAGE, FALSE, true);
+        parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
+        mLightTexture = NULL;
+    }
 }
 
 void LLVOVolume::setSpotLightParams(LLVector3 params)
 {
-	LLLightImageParams* param_block = (LLLightImageParams*)getLightImageParams();
-	if (param_block && param_block->getParams() != params)
-	{
-		param_block->setParams(params);
-		parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
-	}
+    LLLightImageParams* param_block = (LLLightImageParams*)getLightImageParams();
+    if (param_block && param_block->getParams() != params)
+    {
+        param_block->setParams(params);
+        parameterChanged(LLNetworkData::PARAMS_LIGHT_IMAGE, true);
+    }
 }
-		
+
 void LLVOVolume::setIsLight(BOOL is_light)
 {
-	BOOL was_light = getIsLight();
-	if (is_light != was_light)
-	{
-		if (is_light)
-		{
-			setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT, TRUE, true);
-		}
-		else
-		{
-			setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT, FALSE, true);
-		}
-
-		if (is_light)
-		{
-			// Add it to the pipeline mLightSet
-			gPipeline.setLight(mDrawable, TRUE);
-		}
-		else
-		{
-			// Not a light.  Remove it from the pipeline's light set.
-			gPipeline.setLight(mDrawable, FALSE);
-		}
-	}
+    BOOL was_light = getIsLight();
+    if (is_light != was_light)
+    {
+        if (is_light)
+        {
+            setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT, TRUE, true);
+        }
+        else
+        {
+            setParameterEntryInUse(LLNetworkData::PARAMS_LIGHT, FALSE, true);
+        }
+
+        if (is_light)
+        {
+            // Add it to the pipeline mLightSet
+            gPipeline.setLight(mDrawable, TRUE);
+        }
+        else
+        {
+            // Not a light.  Remove it from the pipeline's light set.
+            gPipeline.setLight(mDrawable, FALSE);
+        }
+    }
 }
 
 void LLVOVolume::setLightSRGBColor(const LLColor3& color)
@@ -3090,69 +3090,69 @@ void LLVOVolume::setLightSRGBColor(const LLColor3& color)
 
 void LLVOVolume::setLightLinearColor(const LLColor3& color)
 {
-	LLLightParams *param_block = (LLLightParams *)getLightParams();
-	if (param_block)
-	{
-		if (param_block->getLinearColor() != color)
-		{
-			param_block->setLinearColor(LLColor4(color, param_block->getLinearColor().mV[3]));
-			parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
-			gPipeline.markTextured(mDrawable);
-			mFaceMappingChanged = TRUE;
-		}
-	}
+    LLLightParams *param_block = (LLLightParams *)getLightParams();
+    if (param_block)
+    {
+        if (param_block->getLinearColor() != color)
+        {
+            param_block->setLinearColor(LLColor4(color, param_block->getLinearColor().mV[3]));
+            parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
+            gPipeline.markTextured(mDrawable);
+            mFaceMappingChanged = TRUE;
+        }
+    }
 }
 
 void LLVOVolume::setLightIntensity(F32 intensity)
 {
-	LLLightParams *param_block = (LLLightParams *)getLightParams();
-	if (param_block)
-	{
-		if (param_block->getLinearColor().mV[3] != intensity)
-		{
-			param_block->setLinearColor(LLColor4(LLColor3(param_block->getLinearColor()), intensity));
-			parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
-		}
-	}
+    LLLightParams *param_block = (LLLightParams *)getLightParams();
+    if (param_block)
+    {
+        if (param_block->getLinearColor().mV[3] != intensity)
+        {
+            param_block->setLinearColor(LLColor4(LLColor3(param_block->getLinearColor()), intensity));
+            parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
+        }
+    }
 }
 
 void LLVOVolume::setLightRadius(F32 radius)
 {
-	LLLightParams *param_block = (LLLightParams *)getLightParams();
-	if (param_block)
-	{
-		if (param_block->getRadius() != radius)
-		{
-			param_block->setRadius(radius);
-			parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
-		}
-	}
+    LLLightParams *param_block = (LLLightParams *)getLightParams();
+    if (param_block)
+    {
+        if (param_block->getRadius() != radius)
+        {
+            param_block->setRadius(radius);
+            parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
+        }
+    }
 }
 
 void LLVOVolume::setLightFalloff(F32 falloff)
 {
-	LLLightParams *param_block = (LLLightParams *)getLightParams();
-	if (param_block)
-	{
-		if (param_block->getFalloff() != falloff)
-		{
-			param_block->setFalloff(falloff);
-			parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
-		}
-	}
+    LLLightParams *param_block = (LLLightParams *)getLightParams();
+    if (param_block)
+    {
+        if (param_block->getFalloff() != falloff)
+        {
+            param_block->setFalloff(falloff);
+            parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
+        }
+    }
 }
 
 void LLVOVolume::setLightCutoff(F32 cutoff)
 {
-	LLLightParams *param_block = (LLLightParams *)getLightParams();
-	if (param_block)
-	{
-		if (param_block->getCutoff() != cutoff)
-		{
-			param_block->setCutoff(cutoff);
-			parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
-		}
-	}
+    LLLightParams *param_block = (LLLightParams *)getLightParams();
+    if (param_block)
+    {
+        if (param_block->getCutoff() != cutoff)
+        {
+            param_block->setCutoff(cutoff);
+            parameterChanged(LLNetworkData::PARAMS_LIGHT, true);
+        }
+    }
 }
 
 //----------------------------------------------------------------------------
@@ -3175,15 +3175,15 @@ LLColor3 LLVOVolume::getLightSRGBBaseColor() const
 
 LLColor3 LLVOVolume::getLightLinearBaseColor() const
 {
-	const LLLightParams *param_block = getLightParams();
-	if (param_block)
-	{
-		return LLColor3(param_block->getLinearColor());
-	}
-	else
-	{
-		return LLColor3(1,1,1);
-	}
+    const LLLightParams *param_block = getLightParams();
+    if (param_block)
+    {
+        return LLColor3(param_block->getLinearColor());
+    }
+    else
+    {
+        return LLColor3(1,1,1);
+    }
 }
 
 LLColor3 LLVOVolume::getLightLinearColor() const
@@ -3208,30 +3208,30 @@ LLColor3 LLVOVolume::getLightSRGBColor() const
 
 LLUUID LLVOVolume::getLightTextureID() const
 {
-	const LLLightImageParams *param_block = getLightImageParams();
-	if (param_block)
-	{
-		return param_block->getLightTexture();
-	}
+    const LLLightImageParams *param_block = getLightImageParams();
+    if (param_block)
+    {
+        return param_block->getLightTexture();
+    }
 
-	return LLUUID::null;
+    return LLUUID::null;
 }
 
 
 LLVector3 LLVOVolume::getSpotLightParams() const
 {
-	const LLLightImageParams *param_block = getLightImageParams();
-	if (param_block)
-	{
-		return param_block->getParams();
-	}
+    const LLLightImageParams *param_block = getLightImageParams();
+    if (param_block)
+    {
+        return param_block->getParams();
+    }
 
-	return LLVector3();
+    return LLVector3();
 }
 
 F32 LLVOVolume::getSpotLightPriority() const
 {
-	return mSpotLightPriority;
+    return mSpotLightPriority;
 }
 
 void LLVOVolume::updateSpotLightPriority()
@@ -3240,107 +3240,107 @@ void LLVOVolume::updateSpotLightPriority()
     {
         return;
     }
-	auto& viewerCamera = LLViewerCamera::instance();
+    auto& viewerCamera = LLViewerCamera::instance();
 
     F32 r = getLightRadius();
-	LLVector3 pos = mDrawable->getPositionAgent();
+    LLVector3 pos = mDrawable->getPositionAgent();
 
-	LLVector3 at(0,0,-1);
-	at *= getRenderRotation();
-	pos += at * r;
+    LLVector3 at(0,0,-1);
+    at *= getRenderRotation();
+    pos += at * r;
 
-	at = viewerCamera.getAtAxis();
-	pos -= at * r;
+    at = viewerCamera.getAtAxis();
+    pos -= at * r;
 
-	mSpotLightPriority = gPipeline.calcPixelArea(pos, LLVector3(r,r,r), viewerCamera);
+    mSpotLightPriority = gPipeline.calcPixelArea(pos, LLVector3(r,r,r), viewerCamera);
 
-	if (mLightTexture.notNull())
-	{
-		mLightTexture->addTextureStats(mSpotLightPriority);
-	}
+    if (mLightTexture.notNull())
+    {
+        mLightTexture->addTextureStats(mSpotLightPriority);
+    }
 }
 
 
 bool LLVOVolume::isLightSpotlight() const
 {
-	const LLLightImageParams* params = getLightImageParams();
-	if (params)
-	{
-		return params->isLightSpotlight();
-	}
-	return false;
+    const LLLightImageParams* params = getLightImageParams();
+    if (params)
+    {
+        return params->isLightSpotlight();
+    }
+    return false;
 }
 
 
 LLViewerTexture* LLVOVolume::getLightTexture()
 {
-	LLUUID id = getLightTextureID();
+    LLUUID id = getLightTextureID();
 
-	if (id.notNull())
-	{
-		if (mLightTexture.isNull() || id != mLightTexture->getID())
-		{
-			mLightTexture = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE);
-		}
-	}
-	else
-	{
-		mLightTexture = NULL;
-	}
+    if (id.notNull())
+    {
+        if (mLightTexture.isNull() || id != mLightTexture->getID())
+        {
+            mLightTexture = LLViewerTextureManager::getFetchedTexture(id, FTT_DEFAULT, TRUE, LLGLTexture::BOOST_NONE);
+        }
+    }
+    else
+    {
+        mLightTexture = NULL;
+    }
 
-	return mLightTexture;
+    return mLightTexture;
 }
 
 F32 LLVOVolume::getLightIntensity() const
 {
-	const LLLightParams *param_block = getLightParams();
-	if (param_block)
-	{
-		return param_block->getLinearColor().mV[3];
-	}
-	else
-	{
-		return 1.f;
-	}
+    const LLLightParams *param_block = getLightParams();
+    if (param_block)
+    {
+        return param_block->getLinearColor().mV[3];
+    }
+    else
+    {
+        return 1.f;
+    }
 }
 
 F32 LLVOVolume::getLightRadius() const
 {
-	const LLLightParams *param_block = getLightParams();
-	if (param_block)
-	{
-		return param_block->getRadius();
-	}
-	else
-	{
-		return 0.f;
-	}
+    const LLLightParams *param_block = getLightParams();
+    if (param_block)
+    {
+        return param_block->getRadius();
+    }
+    else
+    {
+        return 0.f;
+    }
 }
 
 F32 LLVOVolume::getLightFalloff(const F32 fudge_factor) const
 {
-	const LLLightParams *param_block = getLightParams();
-	if (param_block)
-	{
-		return param_block->getFalloff() * fudge_factor;
-	}
-	else
-	{
-		return 0.f;
-	}
+    const LLLightParams *param_block = getLightParams();
+    if (param_block)
+    {
+        return param_block->getFalloff() * fudge_factor;
+    }
+    else
+    {
+        return 0.f;
+    }
 }
 
 F32 LLVOVolume::getLightCutoff() const
 {
-	const LLLightParams *param_block = getLightParams();
-	if (param_block)
-	{
-		return param_block->getCutoff();
-	}
-	else
-	{
-		return 0.f;
-	}
+    const LLLightParams *param_block = getLightParams();
+    if (param_block)
+    {
+        return param_block->getCutoff();
+    }
+    else
+    {
+        return 0.f;
+    }
 }
 
 BOOL LLVOVolume::isReflectionProbe() const
@@ -3434,7 +3434,7 @@ bool LLVOVolume::setReflectionProbeIsDynamic(bool is_dynamic)
 
 bool LLVOVolume::setReflectionProbeIsMirror(bool is_mirror)
 {
-	LLReflectionProbeParams* param_block = getReflectionProbeParams();
+    LLReflectionProbeParams* param_block = getReflectionProbeParams();
     if (param_block)
     {
         if (param_block->getIsMirror() != is_mirror)
@@ -3443,10 +3443,10 @@ bool LLVOVolume::setReflectionProbeIsMirror(bool is_mirror)
             param_block->setIsMirror(is_mirror);
             parameterChanged(LLNetworkData::PARAMS_REFLECTION_PROBE, true);
 
-			if (!is_mirror)
-				gPipeline.mHeroProbeManager.unregisterViewerObject(this);
-			else
-				gPipeline.mHeroProbeManager.registerViewerObject(this);
+            if (!is_mirror)
+                gPipeline.mHeroProbeManager.unregisterViewerObject(this);
+            else
+                gPipeline.mHeroProbeManager.registerViewerObject(this);
 
             return true;
         }
@@ -3488,7 +3488,7 @@ bool LLVOVolume::getReflectionProbeIsBox() const
     {
         return param_block->getIsBox();
     }
-    
+
     return false;
 }
 
@@ -3505,7 +3505,7 @@ bool LLVOVolume::getReflectionProbeIsDynamic() const
 
 bool LLVOVolume::getReflectionProbeIsMirror() const
 {
-	const LLReflectionProbeParams* param_block = getReflectionProbeParams();
+    const LLReflectionProbeParams* param_block = getReflectionProbeParams();
     if (param_block)
     {
         return param_block->getIsMirror();
@@ -3516,68 +3516,68 @@ bool LLVOVolume::getReflectionProbeIsMirror() const
 
 U32 LLVOVolume::getVolumeInterfaceID() const
 {
-	if (mVolumeImpl)
-	{
-		return mVolumeImpl->getID();
-	}
+    if (mVolumeImpl)
+    {
+        return mVolumeImpl->getID();
+    }
 
-	return 0;
+    return 0;
 }
 
 BOOL LLVOVolume::isFlexible() const
 {
-	if (getFlexibleObjectData())
-	{
-		LLVolume* volume = getVolume();
-		if (volume && volume->getParams().getPathParams().getCurveType() != LL_PCODE_PATH_FLEXIBLE)
-		{
-			LLVolumeParams volume_params = getVolume()->getParams();
-			U8 profile_and_hole = volume_params.getProfileParams().getCurveType();
-			volume_params.setType(profile_and_hole, LL_PCODE_PATH_FLEXIBLE);
-		}
-		return TRUE;
-	}
-	else
-	{
-		return FALSE;
-	}
+    if (getFlexibleObjectData())
+    {
+        LLVolume* volume = getVolume();
+        if (volume && volume->getParams().getPathParams().getCurveType() != LL_PCODE_PATH_FLEXIBLE)
+        {
+            LLVolumeParams volume_params = getVolume()->getParams();
+            U8 profile_and_hole = volume_params.getProfileParams().getCurveType();
+            volume_params.setType(profile_and_hole, LL_PCODE_PATH_FLEXIBLE);
+        }
+        return TRUE;
+    }
+    else
+    {
+        return FALSE;
+    }
 }
 
 BOOL LLVOVolume::isSculpted() const
 {
-	if (getSculptParams())
-	{
-		return TRUE;
-	}
-	
-	return FALSE;
+    if (getSculptParams())
+    {
+        return TRUE;
+    }
+
+    return FALSE;
 }
 
 BOOL LLVOVolume::isMesh() const
 {
-	if (isSculpted())
-	{
-		const LLSculptParams *sculpt_params = getSculptParams();
-		U8 sculpt_type = sculpt_params->getSculptType();
+    if (isSculpted())
+    {
+        const LLSculptParams *sculpt_params = getSculptParams();
+        U8 sculpt_type = sculpt_params->getSculptType();
 
-		if ((sculpt_type & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
-			// mesh is a mesh
-		{
-			return TRUE;	
-		}
-	}
+        if ((sculpt_type & LL_SCULPT_TYPE_MASK) == LL_SCULPT_TYPE_MESH)
+            // mesh is a mesh
+        {
+            return TRUE;
+        }
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 BOOL LLVOVolume::hasLightTexture() const
 {
-	if (getLightImageParams())
-	{
-		return TRUE;
-	}
+    if (getLightImageParams())
+    {
+        return TRUE;
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 bool LLVOVolume::isFlexibleFast() const
@@ -3607,73 +3607,73 @@ bool LLVOVolume::isAnimatedObjectFast() const
 
 BOOL LLVOVolume::isVolumeGlobal() const
 {
-	if (mVolumeImpl)
-	{
-		return mVolumeImpl->isVolumeGlobal() ? TRUE : FALSE;
-	}
-	else if (mRiggedVolume.notNull())
-	{
-		return TRUE;
-	}
+    if (mVolumeImpl)
+    {
+        return mVolumeImpl->isVolumeGlobal() ? TRUE : FALSE;
+    }
+    else if (mRiggedVolume.notNull())
+    {
+        return TRUE;
+    }
 
-	return FALSE;
+    return FALSE;
 }
 
 BOOL LLVOVolume::canBeFlexible() const
 {
-	U8 path = getVolume()->getParams().getPathParams().getCurveType();
-	return (path == LL_PCODE_PATH_FLEXIBLE || path == LL_PCODE_PATH_LINE);
+    U8 path = getVolume()->getParams().getPathParams().getCurveType();
+    return (path == LL_PCODE_PATH_FLEXIBLE || path == LL_PCODE_PATH_LINE);
 }
 
 BOOL LLVOVolume::setIsFlexible(BOOL is_flexible)
 {
-	BOOL res = FALSE;
-	BOOL was_flexible = isFlexible();
-	LLVolumeParams volume_params;
-	if (is_flexible)
-	{
-		if (!was_flexible)
-		{
-			volume_params = getVolume()->getParams();
-			U8 profile_and_hole = volume_params.getProfileParams().getCurveType();
-			volume_params.setType(profile_and_hole, LL_PCODE_PATH_FLEXIBLE);
-			res = TRUE;
-			setFlags(FLAGS_USE_PHYSICS, FALSE);
-			setFlags(FLAGS_PHANTOM, TRUE);
-			setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, TRUE, true);
-			if (mDrawable)
-			{
-				mDrawable->makeActive();
-			}
-		}
-	}
-	else
-	{
-		if (was_flexible)
-		{
-			volume_params = getVolume()->getParams();
-			U8 profile_and_hole = volume_params.getProfileParams().getCurveType();
-			volume_params.setType(profile_and_hole, LL_PCODE_PATH_LINE);
-			res = TRUE;
-			setFlags(FLAGS_PHANTOM, FALSE);
-			setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, FALSE, true);
-		}
-	}
-	if (res)
-	{
-		res = setVolume(volume_params, 1);
-		if (res)
-		{
-			markForUpdate();
-		}
-	}
-	return res;
+    BOOL res = FALSE;
+    BOOL was_flexible = isFlexible();
+    LLVolumeParams volume_params;
+    if (is_flexible)
+    {
+        if (!was_flexible)
+        {
+            volume_params = getVolume()->getParams();
+            U8 profile_and_hole = volume_params.getProfileParams().getCurveType();
+            volume_params.setType(profile_and_hole, LL_PCODE_PATH_FLEXIBLE);
+            res = TRUE;
+            setFlags(FLAGS_USE_PHYSICS, FALSE);
+            setFlags(FLAGS_PHANTOM, TRUE);
+            setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, TRUE, true);
+            if (mDrawable)
+            {
+                mDrawable->makeActive();
+            }
+        }
+    }
+    else
+    {
+        if (was_flexible)
+        {
+            volume_params = getVolume()->getParams();
+            U8 profile_and_hole = volume_params.getProfileParams().getCurveType();
+            volume_params.setType(profile_and_hole, LL_PCODE_PATH_LINE);
+            res = TRUE;
+            setFlags(FLAGS_PHANTOM, FALSE);
+            setParameterEntryInUse(LLNetworkData::PARAMS_FLEXIBLE, FALSE, true);
+        }
+    }
+    if (res)
+    {
+        res = setVolume(volume_params, 1);
+        if (res)
+        {
+            markForUpdate();
+        }
+    }
+    return res;
 }
 
 const LLMeshSkinInfo* LLVOVolume::getSkinInfo() const
 {
-	// TODO(nopjmp): extra protection against state screw-ups
-	if (getVolume())
+    // TODO(nopjmp): extra protection against state screw-ups
+    if (getVolume())
     {
          return mSkinInfo;
     }
@@ -3690,15 +3690,15 @@ BOOL LLVOVolume::isRiggedMesh() const
 //----------------------------------------------------------------------------
 U32 LLVOVolume::getExtendedMeshFlags() const
 {
-	const LLExtendedMeshParams *param_block = getExtendedMeshParams();
-	if (param_block)
-	{
-		return param_block->getFlags();
-	}
-	else
-	{
-		return 0;
-	}
+    const LLExtendedMeshParams *param_block = getExtendedMeshParams();
+    if (param_block)
+    {
+        return param_block->getFlags();
+    }
+    else
+    {
+        return 0;
+    }
 }
 
 void LLVOVolume::onSetExtendedMeshFlags(U32 flags)
@@ -3707,7 +3707,7 @@ void LLVOVolume::onSetExtendedMeshFlags(U32 flags)
     // The isAnySelected() check was needed at one point to prevent
     // graphics problems. These are now believed to be fixed so the
     // check has been disabled.
-	if (/*!getRootEdit()->isAnySelected() &&*/ mDrawable.notNull())
+    if (/*!getRootEdit()->isAnySelected() &&*/ mDrawable.notNull())
     {
         // Need to trigger rebuildGeom(), which is where control avatars get created/removed
         getRootEdit()->recursiveMarkForUpdate();
@@ -3735,7 +3735,7 @@ void LLVOVolume::setExtendedMeshFlags(U32 flags)
     {
         bool in_use = true;
         setParameterEntryInUse(LLNetworkData::PARAMS_EXTENDED_MESH, in_use, true);
-		LLExtendedMeshParams *param_block = (LLExtendedMeshParams *)getExtendedMeshParams();
+        LLExtendedMeshParams *param_block = (LLExtendedMeshParams *)getExtendedMeshParams();
         if (param_block)
         {
             param_block->setFlags(flags);
@@ -3775,7 +3775,7 @@ bool LLVOVolume::isAnimatedObject() const
 // virtual
 void LLVOVolume::onReparent(LLViewerObject *old_parent, LLViewerObject *new_parent)
 {
-	LLVOVolume *old_volp = old_parent ? old_parent->asVolume() : nullptr;
+    LLVOVolume *old_volp = old_parent ? old_parent->asVolume() : nullptr;
 
     if (new_parent && !new_parent->isAvatar())
     {
@@ -3788,7 +3788,7 @@ void LLVOVolume::onReparent(LLViewerObject *old_parent, LLViewerObject *new_pare
             av->markForDeath();
         }
     }
-	if (old_volp && old_volp->isAnimatedObject())
+    if (old_volp && old_volp->isAnimatedObject())
     {
         if (old_volp->getControlAvatar())
         {
@@ -3807,15 +3807,15 @@ void LLVOVolume::afterReparent()
 {
 #ifdef SHOW_DEBUG
     {
-        LL_DEBUGS("AnimatedObjects") << "new child added for parent " 
+        LL_DEBUGS("AnimatedObjects") << "new child added for parent "
             << ((LLViewerObject*)getParent())->getID() << LL_ENDL;
     }
-#endif                                
+#endif
 
     if (isAnimatedObject() && getControlAvatar())
     {
 #ifdef SHOW_DEBUG
-        LL_DEBUGS("AnimatedObjects") << "adding attachment overrides, parent is animated object " 
+        LL_DEBUGS("AnimatedObjects") << "adding attachment overrides, parent is animated object "
             << ((LLViewerObject*)getParent())->getID() << LL_ENDL;
 #endif
 
@@ -3824,7 +3824,7 @@ void LLVOVolume::afterReparent()
         // addAttachmentOverrides should be sufficient, but in
         // practice doing a full rebuild helps compensate for
         // notifyMeshLoaded() not being called reliably enough.
-        
+
         // was: getControlAvatar()->addAttachmentOverridesForObject(this);
         //getControlAvatar()->rebuildAttachmentOverrides();
         getControlAvatar()->updateAnimations();
@@ -3832,8 +3832,8 @@ void LLVOVolume::afterReparent()
 #ifdef SHOW_DEBUG
     else
     {
-        LL_DEBUGS("AnimatedObjects") << "not adding overrides, parent: " 
-                                     << ((LLViewerObject*)getParent())->getID() 
+        LL_DEBUGS("AnimatedObjects") << "not adding overrides, parent: "
+                                     << ((LLViewerObject*)getParent())->getID()
                                      << " isAnimated: "  << isAnimatedObject() << " cav "
                                      << getControlAvatar() << LL_ENDL;
     }
@@ -3870,8 +3870,8 @@ void LLVOVolume::updateRiggingInfo()
                 // Keep the highest LOD info available.
                 mLastRiggingInfoLOD = getLOD();
 #if DEBUG_SKINNING
-                LL_DEBUGS("RigSpammish") << "updated rigging info for LLVOVolume " 
-                                         << this << " lod " << mLastRiggingInfoLOD 
+                LL_DEBUGS("RigSpammish") << "updated rigging info for LLVOVolume "
+                                         << this << " lod " << mLastRiggingInfoLOD
                                          << LL_ENDL;
 #endif
             }
@@ -3883,86 +3883,86 @@ void LLVOVolume::updateRiggingInfo()
 
 void LLVOVolume::generateSilhouette(LLSelectNode* nodep, const LLVector3& view_point)
 {
-	LLVolume *volume = getVolume();
-
-	if (volume)
-	{
-		LLVector3 view_vector;
-		view_vector = view_point; 
-
-		//transform view vector into volume space
-		view_vector -= getRenderPosition();
-		//mDrawable->mDistanceWRTCamera = view_vector.length();
-		LLQuaternion worldRot = getRenderRotation();
-		view_vector = view_vector * ~worldRot;
-		if (!isVolumeGlobal())
-		{
-			LLVector3 objScale = getScale();
-			LLVector3 invObjScale(1.f / objScale.mV[VX], 1.f / objScale.mV[VY], 1.f / objScale.mV[VZ]);
-			view_vector.scaleVec(invObjScale);
-		}
-		
-		updateRelativeXform();
-		LLMatrix4a trans_mat = mRelativeXform;
-		if (mDrawable->isStatic())
-		{
-			trans_mat.translate_affine(getRegion()->getOriginAgent());
-		}
-
-		volume->generateSilhouetteVertices(nodep->mSilhouetteVertices, nodep->mSilhouetteNormals, view_vector, trans_mat, mRelativeXformInvTrans, nodep->getTESelectMask());
-
-		nodep->mSilhouetteExists = TRUE;
-	}
+    LLVolume *volume = getVolume();
+
+    if (volume)
+    {
+        LLVector3 view_vector;
+        view_vector = view_point;
+
+        //transform view vector into volume space
+        view_vector -= getRenderPosition();
+        //mDrawable->mDistanceWRTCamera = view_vector.length();
+        LLQuaternion worldRot = getRenderRotation();
+        view_vector = view_vector * ~worldRot;
+        if (!isVolumeGlobal())
+        {
+            LLVector3 objScale = getScale();
+            LLVector3 invObjScale(1.f / objScale.mV[VX], 1.f / objScale.mV[VY], 1.f / objScale.mV[VZ]);
+            view_vector.scaleVec(invObjScale);
+        }
+
+        updateRelativeXform();
+        LLMatrix4a trans_mat = mRelativeXform;
+        if (mDrawable->isStatic())
+        {
+            trans_mat.translate_affine(getRegion()->getOriginAgent());
+        }
+
+        volume->generateSilhouetteVertices(nodep->mSilhouetteVertices, nodep->mSilhouetteNormals, view_vector, trans_mat, mRelativeXformInvTrans, nodep->getTESelectMask());
+
+        nodep->mSilhouetteExists = TRUE;
+    }
 }
 
 void LLVOVolume::deleteFaces()
 {
-	S32 face_count = mNumFaces;
-	if (mDrawable.notNull())
-	{
-		mDrawable->deleteFaces(0, face_count);
-	}
+    S32 face_count = mNumFaces;
+    if (mDrawable.notNull())
+    {
+        mDrawable->deleteFaces(0, face_count);
+    }
 
-	mNumFaces = 0;
+    mNumFaces = 0;
 }
 
 void LLVOVolume::updateRadius()
 {
-	if (mDrawable.isNull())
-	{
-		return;
-	}
-	
-	mVObjRadius = getScale().length();
-	mDrawable->setRadius(mVObjRadius);
+    if (mDrawable.isNull())
+    {
+        return;
+    }
+
+    mVObjRadius = getScale().length();
+    mDrawable->setRadius(mVObjRadius);
 }
 
 
 BOOL LLVOVolume::isAttachment() const
 {
-	return mAttachmentState != 0 ;
+    return mAttachmentState != 0 ;
 }
 
 BOOL LLVOVolume::isHUDAttachment() const
 {
-	// *NOTE: we assume hud attachment points are in defined range
-	// since this range is constant for backwards compatibility
-	// reasons this is probably a reasonable assumption to make
-	S32 attachment_id = ATTACHMENT_ID_FROM_STATE(mAttachmentState);
-	return ( attachment_id >= 31 && attachment_id <= 38 );
+    // *NOTE: we assume hud attachment points are in defined range
+    // since this range is constant for backwards compatibility
+    // reasons this is probably a reasonable assumption to make
+    S32 attachment_id = ATTACHMENT_ID_FROM_STATE(mAttachmentState);
+    return ( attachment_id >= 31 && attachment_id <= 38 );
 }
 
 
 const LLMatrix4a& LLVOVolume::getRenderMatrix() const
 {
-	if (mDrawable->isActive() && !mDrawable->isRoot())
-	{
-		return mDrawable->getParent()->getWorldMatrix();
-	}
-	return mDrawable->getWorldMatrix();
+    if (mDrawable->isActive() && !mDrawable->isRoot())
+    {
+        return mDrawable->getParent()->getWorldMatrix();
+    }
+    return mDrawable->getWorldMatrix();
 }
 
-//static 
+//static
 S32 LLVOVolume::getTextureCost(const LLViewerTexture* img)
 {
     static const U32 ARC_TEXTURE_COST = 16; // multiplier for texture resolution - performance tested
@@ -4004,57 +4004,57 @@ U32 LLVOVolume::getRenderCost(texture_cost_t &textures) const
      * the official viewer for consideration.
      *****************************************************************/
 
-	// Get access to params we'll need at various points.  
-	// Skip if this is object doesn't have a volume (e.g. is an avatar).
+    // Get access to params we'll need at various points.
+    // Skip if this is object doesn't have a volume (e.g. is an avatar).
     if (getVolume() == NULL)
     {
         return 0;
     }
 
-	U32 num_triangles = 0;
+    U32 num_triangles = 0;
 
-	// per-prim costs
-	static const U32 ARC_PARTICLE_COST = 1; // determined experimentally
-	static const U32 ARC_PARTICLE_MAX = 2048; // default values
-	static const U32 ARC_LIGHT_COST = 500; // static cost for light-producing prims 
-	static const U32 ARC_MEDIA_FACE_COST = 1500; // static cost per media-enabled face 
+    // per-prim costs
+    static const U32 ARC_PARTICLE_COST = 1; // determined experimentally
+    static const U32 ARC_PARTICLE_MAX = 2048; // default values
+    static const U32 ARC_LIGHT_COST = 500; // static cost for light-producing prims
+    static const U32 ARC_MEDIA_FACE_COST = 1500; // static cost per media-enabled face
 
 
-	// per-prim multipliers
-	static const F32 ARC_GLOW_MULT = 1.5f; // tested based on performance
-	static const F32 ARC_BUMP_MULT = 1.25f; // tested based on performance
-	static const F32 ARC_FLEXI_MULT = 5; // tested based on performance
-	static const F32 ARC_SHINY_MULT = 1.6f; // tested based on performance
-	static const F32 ARC_INVISI_COST = 1.2f; // tested based on performance
-	static const F32 ARC_WEIGHTED_MESH = 1.2f; // tested based on performance
+    // per-prim multipliers
+    static const F32 ARC_GLOW_MULT = 1.5f; // tested based on performance
+    static const F32 ARC_BUMP_MULT = 1.25f; // tested based on performance
+    static const F32 ARC_FLEXI_MULT = 5; // tested based on performance
+    static const F32 ARC_SHINY_MULT = 1.6f; // tested based on performance
+    static const F32 ARC_INVISI_COST = 1.2f; // tested based on performance
+    static const F32 ARC_WEIGHTED_MESH = 1.2f; // tested based on performance
 
-	static const F32 ARC_PLANAR_COST = 1.0f; // tested based on performance to have negligible impact
-	static const F32 ARC_ANIM_TEX_COST = 4.f; // tested based on performance
-	static const F32 ARC_ALPHA_COST = 4.f; // 4x max - based on performance
+    static const F32 ARC_PLANAR_COST = 1.0f; // tested based on performance to have negligible impact
+    static const F32 ARC_ANIM_TEX_COST = 4.f; // tested based on performance
+    static const F32 ARC_ALPHA_COST = 4.f; // 4x max - based on performance
 
-	F32 shame = 0;
+    F32 shame = 0;
 
-	U32 invisi = 0;
-	U32 shiny = 0;
-	U32 glow = 0;
-	U32 alpha = 0;
-	U32 flexi = 0;
-	U32 animtex = 0;
-	U32 particles = 0;
-	U32 bump = 0;
-	U32 planar = 0;
-	U32 weighted_mesh = 0;
-	U32 produces_light = 0;
-	U32 media_faces = 0;
+    U32 invisi = 0;
+    U32 shiny = 0;
+    U32 glow = 0;
+    U32 alpha = 0;
+    U32 flexi = 0;
+    U32 animtex = 0;
+    U32 particles = 0;
+    U32 bump = 0;
+    U32 planar = 0;
+    U32 weighted_mesh = 0;
+    U32 produces_light = 0;
+    U32 media_faces = 0;
 
-	const LLDrawable* drawablep = mDrawable;
-	U32 num_faces = drawablep->getNumFaces();
+    const LLDrawable* drawablep = mDrawable;
+    U32 num_faces = drawablep->getNumFaces();
 
-	const LLVolumeParams& volume_params = getVolume()->getParams();
+    const LLVolumeParams& volume_params = getVolume()->getParams();
 
     LLMeshCostData costs;
-	if (getCostData(costs))
-	{
+    if (getCostData(costs))
+    {
         if (isAnimatedObjectFast() && isRiggedMeshFast())
         {
             // Scaling here is to make animated object vs
@@ -4067,58 +4067,58 @@ U32 LLVOVolume::getRenderCost(texture_cost_t &textures) const
             F32 radius = getScale().length()*0.5f;
             num_triangles = costs.getRadiusWeightedTris(radius);
         }
-	}
-	
-
-	if (num_triangles <= 0)
-	{
-		num_triangles = 4;
-	}
-
-	if (isSculptedFast())
-	{
-		if (isMeshFast())
-		{
-			// base cost is dependent on mesh complexity
-			// note that 3 is the highest LOD as of the time of this coding.
-			S32 size = gMeshRepo.getMeshSize(volume_params.getSculptID(), getLOD());
-			if ( size > 0)
-			{
-				if (isRiggedMeshFast())
-				{
-					// weighted attachment - 1 point for every 3 bytes
-					weighted_mesh = 1;
-				}
-			}
-			else
-			{
-				// something went wrong - user should know their content isn't render-free
-				return 0;
-			}
-		}
-		else
-		{
+    }
+
+
+    if (num_triangles <= 0)
+    {
+        num_triangles = 4;
+    }
+
+    if (isSculptedFast())
+    {
+        if (isMeshFast())
+        {
+            // base cost is dependent on mesh complexity
+            // note that 3 is the highest LOD as of the time of this coding.
+            S32 size = gMeshRepo.getMeshSize(volume_params.getSculptID(), getLOD());
+            if ( size > 0)
+            {
+                if (isRiggedMeshFast())
+                {
+                    // weighted attachment - 1 point for every 3 bytes
+                    weighted_mesh = 1;
+                }
+            }
+            else
+            {
+                // something went wrong - user should know their content isn't render-free
+                return 0;
+            }
+        }
+        else
+        {
             LLViewerFetchedTexture* texture = mSculptTexture;
-			if (texture && textures.find(texture) == textures.end())
-			{
+            if (texture && textures.find(texture) == textures.end())
+            {
                 textures.insert(texture);
-			}
-		}
-	}
+            }
+        }
+    }
 
-	if (isFlexibleFast())
-	{
-		flexi = 1;
-	}
-	if (isParticleSource())
-	{
-		particles = 1;
-	}
+    if (isFlexibleFast())
+    {
+        flexi = 1;
+    }
+    if (isParticleSource())
+    {
+        particles = 1;
+    }
 
-	if (getIsLightFast())
-	{
-		produces_light = 1;
-	}
+    if (getIsLightFast())
+    {
+        produces_light = 1;
+    }
 
     {
         LL_PROFILE_ZONE_NAMED_CATEGORY_VOLUME("ARC - face list");
@@ -4176,79 +4176,79 @@ U32 LLVOVolume::getRenderCost(texture_cost_t &textures) const
         }
     }
 
-	// shame currently has the "base" cost of 1 point per 15 triangles, min 2.
-	shame = num_triangles  * 5.f;
-	shame = shame < 2.f ? 2.f : shame;
-
-	// multiply by per-face modifiers
-	if (planar)
-	{
-		shame *= planar * ARC_PLANAR_COST;
-	}
-
-	if (animtex)
-	{
-		shame *= animtex * ARC_ANIM_TEX_COST;
-	}
-
-	if (alpha)
-	{
-		shame *= alpha * ARC_ALPHA_COST;
-	}
-
-	if(invisi)
-	{
-		shame *= invisi * ARC_INVISI_COST;
-	}
-
-	if (glow)
-	{
-		shame *= glow * ARC_GLOW_MULT;
-	}
-
-	if (bump)
-	{
-		shame *= bump * ARC_BUMP_MULT;
-	}
-
-	if (shiny)
-	{
-		shame *= shiny * ARC_SHINY_MULT;
-	}
-
-
-	// multiply shame by multipliers
-	if (weighted_mesh)
-	{
-		shame *= weighted_mesh * ARC_WEIGHTED_MESH;
-	}
-
-	if (flexi)
-	{
-		shame *= flexi * ARC_FLEXI_MULT;
-	}
-
-
-	// add additional costs
-	if (particles)
-	{
-		const LLPartSysData *part_sys_data = &(mPartSourcep->mPartSysData);
-		const LLPartData *part_data = &(part_sys_data->mPartData);
-		U32 num_particles = (U32)(part_sys_data->mBurstPartCount * llceil( part_data->mMaxAge / part_sys_data->mBurstRate));
-		num_particles = num_particles > ARC_PARTICLE_MAX ? ARC_PARTICLE_MAX : num_particles;
-		F32 part_size = (llmax(part_data->mStartScale[0], part_data->mEndScale[0]) + llmax(part_data->mStartScale[1], part_data->mEndScale[1])) / 2.f;
-		shame += num_particles * part_size * ARC_PARTICLE_COST;
-	}
-
-	if (produces_light)
-	{
-		shame += ARC_LIGHT_COST;
-	}
-
-	if (media_faces)
-	{
-		shame += media_faces * ARC_MEDIA_FACE_COST;
-	}
+    // shame currently has the "base" cost of 1 point per 15 triangles, min 2.
+    shame = num_triangles  * 5.f;
+    shame = shame < 2.f ? 2.f : shame;
+
+    // multiply by per-face modifiers
+    if (planar)
+    {
+        shame *= planar * ARC_PLANAR_COST;
+    }
+
+    if (animtex)
+    {
+        shame *= animtex * ARC_ANIM_TEX_COST;
+    }
+
+    if (alpha)
+    {
+        shame *= alpha * ARC_ALPHA_COST;
+    }
+
+    if(invisi)
+    {
+        shame *= invisi * ARC_INVISI_COST;
+    }
+
+    if (glow)
+    {
+        shame *= glow * ARC_GLOW_MULT;
+    }
+
+    if (bump)
+    {
+        shame *= bump * ARC_BUMP_MULT;
+    }
+
+    if (shiny)
+    {
+        shame *= shiny * ARC_SHINY_MULT;
+    }
+
+
+    // multiply shame by multipliers
+    if (weighted_mesh)
+    {
+        shame *= weighted_mesh * ARC_WEIGHTED_MESH;
+    }
+
+    if (flexi)
+    {
+        shame *= flexi * ARC_FLEXI_MULT;
+    }
+
+
+    // add additional costs
+    if (particles)
+    {
+        const LLPartSysData *part_sys_data = &(mPartSourcep->mPartSysData);
+        const LLPartData *part_data = &(part_sys_data->mPartData);
+        U32 num_particles = (U32)(part_sys_data->mBurstPartCount * llceil( part_data->mMaxAge / part_sys_data->mBurstRate));
+        num_particles = num_particles > ARC_PARTICLE_MAX ? ARC_PARTICLE_MAX : num_particles;
+        F32 part_size = (llmax(part_data->mStartScale[0], part_data->mEndScale[0]) + llmax(part_data->mStartScale[1], part_data->mEndScale[1])) / 2.f;
+        shame += num_particles * part_size * ARC_PARTICLE_COST;
+    }
+
+    if (produces_light)
+    {
+        shame += ARC_LIGHT_COST;
+    }
+
+    if (media_faces)
+    {
+        shame += media_faces * ARC_MEDIA_FACE_COST;
+    }
 
     // Streaming cost for animated objects includes a fixed cost
     // per linkset. Add a corresponding charge here translated into
@@ -4258,35 +4258,35 @@ U32 LLVOVolume::getRenderCost(texture_cost_t &textures) const
         shame += (ANIMATED_OBJECT_BASE_COST/0.06) * 5.0f;
     }
 
-	if (shame > mRenderComplexity_current)
-	{
-		mRenderComplexity_current = (S32)shame;
-	}
+    if (shame > mRenderComplexity_current)
+    {
+        mRenderComplexity_current = (S32)shame;
+    }
 
-	return (U32)shame;
+    return (U32)shame;
 }
 
 F32 LLVOVolume::getEstTrianglesMax() const
 {
-	if (isMeshFast() && getVolume())
-	{
-		return gMeshRepo.getEstTrianglesMax(getVolume()->getParams().getSculptID());
-	}
+    if (isMeshFast() && getVolume())
+    {
+        return gMeshRepo.getEstTrianglesMax(getVolume()->getParams().getSculptID());
+    }
     return 0.f;
 }
 
 F32 LLVOVolume::getEstTrianglesStreamingCost() const
 {
-	if (isMeshFast() && getVolume())
-	{
-		return gMeshRepo.getEstTrianglesStreamingCost(getVolume()->getParams().getSculptID());
-	}
+    if (isMeshFast() && getVolume())
+    {
+        return gMeshRepo.getEstTrianglesStreamingCost(getVolume()->getParams().getSculptID());
+    }
     return 0.f;
 }
 
 F32 LLVOVolume::getStreamingCost() const
 {
-	F32 radius = getScale().length()*0.5f;
+    F32 radius = getScale().length()*0.5f;
     F32 linkset_base_cost = 0.f;
 
     LLMeshCostData costs;
@@ -4330,101 +4330,101 @@ bool LLVOVolume::getCostData(LLMeshCostData& costs) const
     }
     else
     {
-		LLVolume* volume = getVolume();
-		S32 counts[4];
-		volume->getLoDTriangleCounts(counts);
+        LLVolume* volume = getVolume();
+        S32 counts[4];
+        volume->getLoDTriangleCounts(counts);
 
         LLMeshHeader header;
-		header.mLodSize[0] = counts[0] * 10;
-		header.mLodSize[1] = counts[1] * 10;
-		header.mLodSize[2] = counts[2] * 10;
-		header.mLodSize[3] = counts[3] * 10;
+        header.mLodSize[0] = counts[0] * 10;
+        header.mLodSize[1] = counts[1] * 10;
+        header.mLodSize[2] = counts[2] * 10;
+        header.mLodSize[3] = counts[3] * 10;
 
-		return gMeshRepo.getCostData(header, costs);
+        return gMeshRepo.getCostData(header, costs);
     }
 }
 
-//static 
+//static
 void LLVOVolume::updateRenderComplexity()
 {
-	mRenderComplexity_last = mRenderComplexity_current;
-	mRenderComplexity_current = 0;
+    mRenderComplexity_last = mRenderComplexity_current;
+    mRenderComplexity_current = 0;
 }
 
 U32 LLVOVolume::getTriangleCount(S32* vcount) const
 {
-	U32 count = 0;
-	LLVolume* volume = getVolume();
-	if (volume)
-	{
-		count = volume->getNumTriangles(vcount);
-	}
+    U32 count = 0;
+    LLVolume* volume = getVolume();
+    if (volume)
+    {
+        count = volume->getNumTriangles(vcount);
+    }
 
-	return count;
+    return count;
 }
 
 U32 LLVOVolume::getHighLODTriangleCount()
 {
-	U32 ret = 0;
-
-	LLVolume* volume = getVolume();
-
-	if (!isSculpted())
-	{
-		LLVolume* ref = LLPrimitive::getVolumeManager()->refVolume(volume->getParams(), 3);
-		ret = ref->getNumTriangles();
-		LLPrimitive::getVolumeManager()->unrefVolume(ref);
-	}
-	else if (isMesh())
-	{
-		LLVolume* ref = LLPrimitive::getVolumeManager()->refVolume(volume->getParams(), 3);
-		if (!ref->isMeshAssetLoaded() || ref->getNumVolumeFaces() == 0)
-		{
-			gMeshRepo.loadMesh(this, volume->getParams(), LLModel::LOD_HIGH);
-		}
-		ret = ref->getNumTriangles();
-		LLPrimitive::getVolumeManager()->unrefVolume(ref);
-	}
-	else
-	{ //default sculpts have a constant number of triangles
-		ret = 31*2*31;  //31 rows of 31 columns of quads for a 32x32 vertex patch
-	}
-
-	return ret;
+    U32 ret = 0;
+
+    LLVolume* volume = getVolume();
+
+    if (!isSculpted())
+    {
+        LLVolume* ref = LLPrimitive::getVolumeManager()->refVolume(volume->getParams(), 3);
+        ret = ref->getNumTriangles();
+        LLPrimitive::getVolumeManager()->unrefVolume(ref);
+    }
+    else if (isMesh())
+    {
+        LLVolume* ref = LLPrimitive::getVolumeManager()->refVolume(volume->getParams(), 3);
+        if (!ref->isMeshAssetLoaded() || ref->getNumVolumeFaces() == 0)
+        {
+            gMeshRepo.loadMesh(this, volume->getParams(), LLModel::LOD_HIGH);
+        }
+        ret = ref->getNumTriangles();
+        LLPrimitive::getVolumeManager()->unrefVolume(ref);
+    }
+    else
+    { //default sculpts have a constant number of triangles
+        ret = 31*2*31;  //31 rows of 31 columns of quads for a 32x32 vertex patch
+    }
+
+    return ret;
 }
 
 // [FS:Beq] - Patch: Appearance-RebuildAttachments | Checked: Catznip-5.3
 void LLVOVolume::forceLOD(S32 lod)
 {
 // [SL:KB] - Patch: Appearance-RebuildAttachments | Checked: Catznip-5.3
-	if (mDrawable.isNull())
-		return;
+    if (mDrawable.isNull())
+        return;
 // [/SL:KB]
 
-	mLOD = lod;
-	gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
-	mLODChanged = true;
+    mLOD = lod;
+    gPipeline.markRebuild(mDrawable, LLDrawable::REBUILD_VOLUME);
+    mLODChanged = true;
 }
 // [/FS]
 
 //static
 void LLVOVolume::preUpdateGeom()
 {
-	sNumLODChanges = 0;
+    sNumLODChanges = 0;
 }
 
 void LLVOVolume::parameterChanged(U16 param_type, bool local_origin)
 {
-	LLViewerObject::parameterChanged(param_type, local_origin);
+    LLViewerObject::parameterChanged(param_type, local_origin);
 }
 
 void LLVOVolume::parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_use, bool local_origin)
 {
-	LLViewerObject::parameterChanged(param_type, data, in_use, local_origin);
-	if (mVolumeImpl)
-	{
-		mVolumeImpl->onParameterChanged(param_type, data, in_use, local_origin);
-	}
+    LLViewerObject::parameterChanged(param_type, data, in_use, local_origin);
+    if (mVolumeImpl)
+    {
+        mVolumeImpl->onParameterChanged(param_type, data, in_use, local_origin);
+    }
     if (!local_origin && param_type == LLNetworkData::PARAMS_EXTENDED_MESH)
     {
         U32 extended_mesh_flags = getExtendedMeshFlags();
@@ -4443,15 +4443,15 @@ void LLVOVolume::parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_u
             onSetExtendedMeshFlags(extended_mesh_flags);
         }
     }
-	if (mDrawable.notNull())
-	{
-		BOOL is_light = getIsLight();
-		if (is_light != mDrawable->isState(LLDrawable::LIGHT))
-		{
-			gPipeline.setLight(mDrawable, is_light);
-		}
-	}
-   
+    if (mDrawable.notNull())
+    {
+        BOOL is_light = getIsLight();
+        if (is_light != mDrawable->isState(LLDrawable::LIGHT))
+        {
+            gPipeline.setLight(mDrawable, is_light);
+        }
+    }
+
     updateReflectionProbePtr();
 }
 
@@ -4464,13 +4464,13 @@ void LLVOVolume::updateReflectionProbePtr()
             mReflectionProbe = gPipeline.mReflectionMapManager.registerViewerObject(this);
         }
         else if (mReflectionProbe.isNull() && getReflectionProbeIsMirror())
-		{
-			// Geenz: This is a special case - what we want here is a hero probe.
-			// What we want to do here is instantiate a hero probe from the hero probe manager.
-            
+        {
+            // Geenz: This is a special case - what we want here is a hero probe.
+            // What we want to do here is instantiate a hero probe from the hero probe manager.
+
             if (!mIsHeroProbe)
                 mIsHeroProbe = gPipeline.mHeroProbeManager.registerViewerObject(this);
-		}
+        }
     }
     else if (mReflectionProbe.notNull() || getReflectionProbeIsMirror())
     {
@@ -4479,7 +4479,7 @@ void LLVOVolume::updateReflectionProbePtr()
             mReflectionProbe = nullptr;
         }
 
-		if (getReflectionProbeIsMirror())
+        if (getReflectionProbeIsMirror())
         {
             gPipeline.mHeroProbeManager.unregisterViewerObject(this);
         }
@@ -4488,7 +4488,7 @@ void LLVOVolume::updateReflectionProbePtr()
 
 void LLVOVolume::setSelected(BOOL sel)
 {
-	LLViewerObject::setSelected(sel);
+    LLViewerObject::setSelected(sel);
     if (isAnimatedObject())
     {
         getRootEdit()->recursiveMarkForUpdate();
@@ -4503,7 +4503,7 @@ void LLVOVolume::setSelected(BOOL sel)
 }
 
 void LLVOVolume::updateSpatialExtents(LLVector4a& newMin, LLVector4a& newMax)
-{		
+{
 }
 
 F32 LLVOVolume::getBinRadius()
@@ -4568,104 +4568,104 @@ F32 LLVOVolume::getBinRadius()
 
 const LLVector3 LLVOVolume::getPivotPositionAgent() const
 {
-	if (mVolumeImpl)
-	{
-		return mVolumeImpl->getPivotPosition();
-	}
-	return LLViewerObject::getPivotPositionAgent();
+    if (mVolumeImpl)
+    {
+        return mVolumeImpl->getPivotPosition();
+    }
+    return LLViewerObject::getPivotPositionAgent();
 }
 
 void LLVOVolume::onShift(const LLVector4a &shift_vector)
 {
-	if (mVolumeImpl)
-	{
-		mVolumeImpl->onShift(shift_vector);
-	}
+    if (mVolumeImpl)
+    {
+        mVolumeImpl->onShift(shift_vector);
+    }
 
-	updateRelativeXform();
+    updateRelativeXform();
 }
 
 const LLMatrix4a& LLVOVolume::getWorldMatrix(LLXformMatrix* xform) const
 {
-	if (mVolumeImpl)
-	{
-		return mVolumeImpl->getWorldMatrix(xform);
-	}
-	return xform->getWorldMatrix();
+    if (mVolumeImpl)
+    {
+        return mVolumeImpl->getWorldMatrix(xform);
+    }
+    return xform->getWorldMatrix();
 }
 
 void LLVOVolume::markForUpdate()
-{ 
+{
     if (mDrawable)
     {
         shrinkWrap();
     }
 
-    LLViewerObject::markForUpdate(); 
-    mVolumeChanged = TRUE; 
+    LLViewerObject::markForUpdate();
+    mVolumeChanged = TRUE;
 }
 
 LLVector3 LLVOVolume::agentPositionToVolume(const LLVector3& pos) const
 {
-	LLVector3 ret = pos - getRenderPosition();
-	ret = ret * ~getRenderRotation();
-	if (!isVolumeGlobal())
-	{
-		LLVector3 objScale = getScale();
-		LLVector3 invObjScale(1.f / objScale.mV[VX], 1.f / objScale.mV[VY], 1.f / objScale.mV[VZ]);
-		ret.scaleVec(invObjScale);
-	}
-	
-	return ret;
+    LLVector3 ret = pos - getRenderPosition();
+    ret = ret * ~getRenderRotation();
+    if (!isVolumeGlobal())
+    {
+        LLVector3 objScale = getScale();
+        LLVector3 invObjScale(1.f / objScale.mV[VX], 1.f / objScale.mV[VY], 1.f / objScale.mV[VZ]);
+        ret.scaleVec(invObjScale);
+    }
+
+    return ret;
 }
 
 LLVector3 LLVOVolume::agentDirectionToVolume(const LLVector3& dir) const
 {
-	LLVector3 ret = dir * ~getRenderRotation();
-	
-	LLVector3 objScale = isVolumeGlobal() ? LLVector3(1,1,1) : getScale();
-	ret.scaleVec(objScale);
+    LLVector3 ret = dir * ~getRenderRotation();
+
+    LLVector3 objScale = isVolumeGlobal() ? LLVector3(1,1,1) : getScale();
+    ret.scaleVec(objScale);
 
-	return ret;
+    return ret;
 }
 
 LLVector3 LLVOVolume::volumePositionToAgent(const LLVector3& dir) const
 {
-	LLVector3 ret = dir;
-	if (!isVolumeGlobal())
-	{
-		LLVector3 objScale = getScale();
-		ret.scaleVec(objScale);
-	}
+    LLVector3 ret = dir;
+    if (!isVolumeGlobal())
+    {
+        LLVector3 objScale = getScale();
+        ret.scaleVec(objScale);
+    }
+
+    ret = ret * getRenderRotation();
+    ret += getRenderPosition();
 
-	ret = ret * getRenderRotation();
-	ret += getRenderPosition();
-	
-	return ret;
+    return ret;
 }
 
 LLVector3 LLVOVolume::volumeDirectionToAgent(const LLVector3& dir) const
 {
-	LLVector3 ret = dir;
-	LLVector3 objScale = isVolumeGlobal() ? LLVector3(1,1,1) : getScale();
-	LLVector3 invObjScale(1.f / objScale.mV[VX], 1.f / objScale.mV[VY], 1.f / objScale.mV[VZ]);
-	ret.scaleVec(invObjScale);
-	ret = ret * getRenderRotation();
+    LLVector3 ret = dir;
+    LLVector3 objScale = isVolumeGlobal() ? LLVector3(1,1,1) : getScale();
+    LLVector3 invObjScale(1.f / objScale.mV[VX], 1.f / objScale.mV[VY], 1.f / objScale.mV[VZ]);
+    ret.scaleVec(invObjScale);
+    ret = ret * getRenderRotation();
 
-	return ret;
+    return ret;
 }
 
 
 BOOL LLVOVolume::lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end, S32 face, BOOL pick_transparent, BOOL pick_rigged, BOOL pick_unselectable, S32 *face_hitp,
-									      LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent)
-	
+                                          LLVector4a* intersection,LLVector2* tex_coord, LLVector4a* normal, LLVector4a* tangent)
+
 {
-	if (!mbCanSelect 
-		|| mDrawable->isDead() 
-		|| !gPipeline.hasRenderType(mDrawable->getRenderType()))
-	{
-		return FALSE;
-	}
+    if (!mbCanSelect
+        || mDrawable->isDead()
+        || !gPipeline.hasRenderType(mDrawable->getRenderType()))
+    {
+        return FALSE;
+    }
 
     if (!pick_unselectable)
     {
@@ -4680,203 +4680,203 @@ BOOL LLVOVolume::lineSegmentIntersect(const LLVector4a& start, const LLVector4a&
         return FALSE;
     }
 
-	BOOL ret = FALSE;
+    BOOL ret = FALSE;
 
-	LLVolume* volume = getVolume();
+    LLVolume* volume = getVolume();
 
-	bool transform = true;
+    bool transform = true;
 
-	if (mDrawable->isState(LLDrawable::RIGGED))
-	{
-		if (pick_rigged || LLToolMgr::getInstance()->inBuildMode())
-		{
+    if (mDrawable->isState(LLDrawable::RIGGED))
+    {
+        if (pick_rigged || LLToolMgr::getInstance()->inBuildMode())
+        {
             updateRiggedVolume(true, LLRiggedVolume::DO_NOT_UPDATE_FACES);
-			volume = mRiggedVolume;
-			transform = false;
-		}
-		else
-		{ //cannot pick rigged attachments when not in build mode
-			return FALSE;
-		}
-	}
-	
-	if (volume)
-	{	
-		LLVector4a local_start = start;
-		LLVector4a local_end = end;
-	
-		if (transform)
-		{
-			LLVector3 v_start(start.getF32ptr());
-			LLVector3 v_end(end.getF32ptr());
-		
-			v_start = agentPositionToVolume(v_start);
-			v_end = agentPositionToVolume(v_end);
-
-			local_start.load3(v_start.mV);
-			local_end.load3(v_end.mV);
-		}
-		
-		LLVector4a p;
-		LLVector4a n;
-		LLVector2 tc;
-		LLVector4a tn;
-
-		if (intersection != NULL)
-		{
-			p = *intersection;
-		}
-
-		if (tex_coord != NULL)
-		{
-			tc = *tex_coord;
-		}
-
-		if (normal != NULL)
-		{
-			n = *normal;
-		}
-
-		if (tangent != NULL)
-		{
-			tn = *tangent;
-		}
-
-		S32 face_hit = -1;
-
-		S32 start_face, end_face;
-		if (face == -1)
-		{
-			start_face = 0;
-			end_face = volume->getNumVolumeFaces();
-		}
-		else
-		{
-			start_face = face;
-			end_face = face+1;
-		}
-		pick_transparent |= isHiglightedOrBeacon();
+            volume = mRiggedVolume;
+            transform = false;
+        }
+        else
+        { //cannot pick rigged attachments when not in build mode
+            return FALSE;
+        }
+    }
+
+    if (volume)
+    {
+        LLVector4a local_start = start;
+        LLVector4a local_end = end;
+
+        if (transform)
+        {
+            LLVector3 v_start(start.getF32ptr());
+            LLVector3 v_end(end.getF32ptr());
+
+            v_start = agentPositionToVolume(v_start);
+            v_end = agentPositionToVolume(v_end);
+
+            local_start.load3(v_start.mV);
+            local_end.load3(v_end.mV);
+        }
+
+        LLVector4a p;
+        LLVector4a n;
+        LLVector2 tc;
+        LLVector4a tn;
+
+        if (intersection != NULL)
+        {
+            p = *intersection;
+        }
+
+        if (tex_coord != NULL)
+        {
+            tc = *tex_coord;
+        }
+
+        if (normal != NULL)
+        {
+            n = *normal;
+        }
+
+        if (tangent != NULL)
+        {
+            tn = *tangent;
+        }
+
+        S32 face_hit = -1;
+
+        S32 start_face, end_face;
+        if (face == -1)
+        {
+            start_face = 0;
+            end_face = volume->getNumVolumeFaces();
+        }
+        else
+        {
+            start_face = face;
+            end_face = face+1;
+        }
+        pick_transparent |= isHiglightedOrBeacon();
 
         // we *probably* shouldn't care about special cursor at all, but we *definitely*
         // don't care about special cursor for reflection probes -- makes alt-zoom
         // go through reflection probes on vehicles
-		bool special_cursor = mReflectionProbe.isNull() && specialHoverCursor();
+        bool special_cursor = mReflectionProbe.isNull() && specialHoverCursor();
 
-		for (S32 i = start_face; i < end_face; ++i)
-		{
-			if (!special_cursor && !pick_transparent && getTE(i) && getTE(i)->getColor().mV[3] == 0.f)
-			{ //don't attempt to pick completely transparent faces unless
-				//pick_transparent is true
-				continue;
-			}
+        for (S32 i = start_face; i < end_face; ++i)
+        {
+            if (!special_cursor && !pick_transparent && getTE(i) && getTE(i)->getColor().mV[3] == 0.f)
+            { //don't attempt to pick completely transparent faces unless
+                //pick_transparent is true
+                continue;
+            }
 
             // This calculates the bounding box of the skinned mesh from scratch. It's actually quite expensive, but not nearly as expensive as building a full octree.
             // rebuild_face_octrees = false because an octree for this face will be built later only if needed for narrow phase picking.
             updateRiggedVolume(true, i, false);
-			face_hit = volume->lineSegmentIntersect(local_start, local_end, i,
-													&p, &tc, &n, &tn);
-			
-			if (face_hit >= 0 && mDrawable->getNumFaces() > face_hit)
-			{
-				LLFace* face = mDrawable->getFace(face_hit);				
-
-				bool ignore_alpha = false;
-
-				const LLTextureEntry* te = face->getTextureEntry();
-				if (te)
-				{
-					LLMaterial* mat = te->getMaterialParams();
-					if (mat)
-					{
-						U8 mode = mat->getDiffuseAlphaMode();
-
-						if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_EMISSIVE
-							|| mode == LLMaterial::DIFFUSE_ALPHA_MODE_NONE
-							|| (mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK && mat->getAlphaMaskCutoff() == 0))
-						{
-							ignore_alpha = true;
-						}
-					}
-				}
+            face_hit = volume->lineSegmentIntersect(local_start, local_end, i,
+                                                    &p, &tc, &n, &tn);
+
+            if (face_hit >= 0 && mDrawable->getNumFaces() > face_hit)
+            {
+                LLFace* face = mDrawable->getFace(face_hit);
+
+                bool ignore_alpha = false;
+
+                const LLTextureEntry* te = face->getTextureEntry();
+                if (te)
+                {
+                    LLMaterial* mat = te->getMaterialParams();
+                    if (mat)
+                    {
+                        U8 mode = mat->getDiffuseAlphaMode();
+
+                        if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_EMISSIVE
+                            || mode == LLMaterial::DIFFUSE_ALPHA_MODE_NONE
+                            || (mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK && mat->getAlphaMaskCutoff() == 0))
+                        {
+                            ignore_alpha = true;
+                        }
+                    }
+                }
 
                 BOOL no_texture = !face->getTexture() || !face->getTexture()->hasGLTexture();
                 BOOL mask       = no_texture ? FALSE : face->getTexture()->getMask(face->surfaceToTexture(tc, p, n));
-				if (face &&
-					(ignore_alpha || pick_transparent || no_texture || mask))
-				{
-					local_end = p;
-					if (face_hitp != NULL)
-					{
-						*face_hitp = face_hit;
-					}
-					
-					if (intersection != NULL)
-					{
-						if (transform)
-						{
-							LLVector3 v_p(p.getF32ptr());
-
-							intersection->load3(volumePositionToAgent(v_p).mV);  // must map back to agent space
-						}
-						else
-						{
-							*intersection = p;
-						}
-					}
-
-					if (normal != NULL)
-					{
-						if (transform)
-						{
-							LLVector3 v_n(n.getF32ptr());
-							normal->load3(volumeDirectionToAgent(v_n).mV);
-						}
-						else
-						{
-							*normal = n;
-						}
-						(*normal).normalize3fast();
-					}
-
-					if (tangent != NULL)
-					{
-						if (transform)
-						{
-							LLVector3 v_tn(tn.getF32ptr());
-
-							LLVector4a trans_tangent;
-							trans_tangent.load3(volumeDirectionToAgent(v_tn).mV);
-
-							LLVector4Logical mask;
-							mask.clear();
-							mask.setElement<3>();
-
-							tangent->setSelectWithMask(mask, tn, trans_tangent);
-						}
-						else
-						{
-							*tangent = tn;
-						}
-						(*tangent).normalize3fast();
-					}
-
-					if (tex_coord != NULL)
-					{
-						*tex_coord = tc;
-					}
-					
-					ret = TRUE;
-				}
-			}
-		}
-	}
-
-	return ret;
+                if (face &&
+                    (ignore_alpha || pick_transparent || no_texture || mask))
+                {
+                    local_end = p;
+                    if (face_hitp != NULL)
+                    {
+                        *face_hitp = face_hit;
+                    }
+
+                    if (intersection != NULL)
+                    {
+                        if (transform)
+                        {
+                            LLVector3 v_p(p.getF32ptr());
+
+                            intersection->load3(volumePositionToAgent(v_p).mV);  // must map back to agent space
+                        }
+                        else
+                        {
+                            *intersection = p;
+                        }
+                    }
+
+                    if (normal != NULL)
+                    {
+                        if (transform)
+                        {
+                            LLVector3 v_n(n.getF32ptr());
+                            normal->load3(volumeDirectionToAgent(v_n).mV);
+                        }
+                        else
+                        {
+                            *normal = n;
+                        }
+                        (*normal).normalize3fast();
+                    }
+
+                    if (tangent != NULL)
+                    {
+                        if (transform)
+                        {
+                            LLVector3 v_tn(tn.getF32ptr());
+
+                            LLVector4a trans_tangent;
+                            trans_tangent.load3(volumeDirectionToAgent(v_tn).mV);
+
+                            LLVector4Logical mask;
+                            mask.clear();
+                            mask.setElement<3>();
+
+                            tangent->setSelectWithMask(mask, tn, trans_tangent);
+                        }
+                        else
+                        {
+                            *tangent = tn;
+                        }
+                        (*tangent).normalize3fast();
+                    }
+
+                    if (tex_coord != NULL)
+                    {
+                        *tex_coord = tc;
+                    }
+
+                    ret = TRUE;
+                }
+            }
+        }
+    }
+
+    return ret;
 }
 
 bool LLVOVolume::treatAsRigged()
 {
-	return isSelected() &&
+    return isSelected() &&
         (isAttachment() || isAnimatedObject()) &&
         mDrawable.notNull() &&
         mDrawable->isState(LLDrawable::RIGGED);
@@ -4884,57 +4884,57 @@ bool LLVOVolume::treatAsRigged()
 
 LLRiggedVolume* LLVOVolume::getRiggedVolume()
 {
-	return mRiggedVolume;
+    return mRiggedVolume;
 }
 
 void LLVOVolume::clearRiggedVolume()
 {
-	if (mRiggedVolume.notNull())
-	{
-		mRiggedVolume = NULL;
-		updateRelativeXform();
-	}
+    if (mRiggedVolume.notNull())
+    {
+        mRiggedVolume = NULL;
+        updateRelativeXform();
+    }
 }
 
 void LLVOVolume::updateRiggedVolume(bool force_treat_as_rigged, LLRiggedVolume::FaceIndex face_index, bool rebuild_face_octrees)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	//Update mRiggedVolume to match current animation frame of avatar. 
-	//Also update position/size in octree.  
+    //Update mRiggedVolume to match current animation frame of avatar.
+    //Also update position/size in octree.
+
+    if ((!force_treat_as_rigged) && (!treatAsRigged()))
+    {
+        clearRiggedVolume();
+
+        return;
+    }
+
+    LLVolume* volume = getVolume();
+    if (!volume)
+    {
+        clearRiggedVolume();
+        return;
+    }
+
+    if (!mSkinInfo)
+    {
+        clearRiggedVolume();
+        return;
+    }
 
-    if ((!force_treat_as_rigged) && (!treatAsRigged()))
-	{
-		clearRiggedVolume();
-		
-		return;
-	}
-
-	LLVolume* volume = getVolume();
-	if (!volume)
-	{
-		clearRiggedVolume();
-		return;
-	}
-
-	if (!mSkinInfo)
-	{
-		clearRiggedVolume();
-		return;
-	}
-
-	LLVOAvatar* avatar = getAvatar();
-	if (!avatar)
-	{
-		clearRiggedVolume();
-		return;
-	}
-
-	if (!mRiggedVolume)
-	{
-		LLVolumeParams p;
-		mRiggedVolume = new LLRiggedVolume(p);
-		updateRelativeXform();
-	}
+    LLVOAvatar* avatar = getAvatar();
+    if (!avatar)
+    {
+        clearRiggedVolume();
+        return;
+    }
+
+    if (!mRiggedVolume)
+    {
+        LLVolumeParams p;
+        mRiggedVolume = new LLRiggedVolume(p);
+        updateRelativeXform();
+    }
 
     mRiggedVolume->update(mSkinInfo, avatar, volume, face_index, rebuild_face_octrees);
 }
@@ -4947,48 +4947,48 @@ void LLRiggedVolume::update(
     bool rebuild_face_octrees)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	bool copy = false;
-	S32 vol_num_faces = volume->getNumVolumeFaces();
-	if (vol_num_faces != getNumVolumeFaces())
-	{ 
-		copy = true;
-	}
-
-	for (S32 i = 0; i < vol_num_faces && !copy; ++i)
-	{
-		const LLVolumeFace& src_face = volume->getVolumeFace(i);
-		const LLVolumeFace& dst_face = getVolumeFace(i);
-
-		if (src_face.mNumIndices != dst_face.mNumIndices ||
-			src_face.mNumVertices != dst_face.mNumVertices)
-		{
-			copy = true;
-		}
-	}
-
-	if (copy)
-	{
-		copyVolumeFaces(volume);
-	}
+    bool copy = false;
+    S32 vol_num_faces = volume->getNumVolumeFaces();
+    if (vol_num_faces != getNumVolumeFaces())
+    {
+        copy = true;
+    }
+
+    for (S32 i = 0; i < vol_num_faces && !copy; ++i)
+    {
+        const LLVolumeFace& src_face = volume->getVolumeFace(i);
+        const LLVolumeFace& dst_face = getVolumeFace(i);
+
+        if (src_face.mNumIndices != dst_face.mNumIndices ||
+            src_face.mNumVertices != dst_face.mNumVertices)
+        {
+            copy = true;
+        }
+    }
+
+    if (copy)
+    {
+        copyVolumeFaces(volume);
+    }
     else
     {
         bool is_paused = avatar && avatar->areAnimationsPaused();
-		if (is_paused)
-		{
+        if (is_paused)
+        {
             S32 frames_paused = LLFrameTimer::getFrameCount() - avatar->getMotionController().getPausedFrame();
             if (frames_paused > 1)
             {
                 return;
             }
-		}
+        }
     }
 
 
-	//build matrix palette
-	static const size_t kMaxJoints = LL_MAX_JOINTS_PER_MESH_OBJECT;
+    //build matrix palette
+    static const size_t kMaxJoints = LL_MAX_JOINTS_PER_MESH_OBJECT;
 
-	LLMatrix4a mat[kMaxJoints];
-	U32 maxJoints = LLSkinningUtil::getMeshJointCount(skin);
+    LLMatrix4a mat[kMaxJoints];
+    U32 maxJoints = LLSkinningUtil::getMeshJointCount(skin);
     LLSkinningUtil::initSkinningMatrixPalette(mat, maxJoints, skin, avatar);
     const LLMatrix4a bind_shape_matrix = skin->mBindShapeMatrix;
 
@@ -5013,73 +5013,73 @@ void LLRiggedVolume::update(
         face_end = face_begin + 1;
     }
     for (S32 i = face_begin; i < face_end; ++i)
-	{
-		const LLVolumeFace& vol_face = volume->getVolumeFace(i);
-		
-		LLVolumeFace& dst_face = mVolumeFaces[i];
-		
-		LLVector4a* weight = vol_face.mWeights;
-
-		if ( weight )
-		{
+    {
+        const LLVolumeFace& vol_face = volume->getVolumeFace(i);
+
+        LLVolumeFace& dst_face = mVolumeFaces[i];
+
+        LLVector4a* weight = vol_face.mWeights;
+
+        if ( weight )
+        {
             LLSkinningUtil::checkSkinWeights(weight, dst_face.mNumVertices, skin);
 
-			LLVector4a* pos = dst_face.mPositions;
+            LLVector4a* pos = dst_face.mPositions;
 
-			if (pos && dst_face.mExtents)
-			{
+            if (pos && dst_face.mExtents)
+            {
                 rigged_vert_count += dst_face.mNumVertices;
                 rigged_face_count++;
 
                 {
-				    for (U32 j = 0; j < dst_face.mNumVertices; ++j)
-				    {
-					    LLMatrix4a final_mat;
+                    for (U32 j = 0; j < dst_face.mNumVertices; ++j)
+                    {
+                        LLMatrix4a final_mat;
                         LLSkinningUtil::getPerVertexSkinMatrixUnchecked(weight[j], mat, final_mat);
-				
-					    LLVector4a& v = vol_face.mPositions[j];
-					    LLVector4a t;
-					    LLVector4a dst;
-					    bind_shape_matrix.affineTransform(v, t);
-					    final_mat.affineTransform(t, dst);
-					    pos[j] = dst;
-				    }
+
+                        LLVector4a& v = vol_face.mPositions[j];
+                        LLVector4a t;
+                        LLVector4a dst;
+                        bind_shape_matrix.affineTransform(v, t);
+                        final_mat.affineTransform(t, dst);
+                        pos[j] = dst;
+                    }
                 }
 
-				//update bounding box
-				// VFExtents change
-				LLVector4a& min = dst_face.mExtents[0];
-				LLVector4a& max = dst_face.mExtents[1];
+                //update bounding box
+                // VFExtents change
+                LLVector4a& min = dst_face.mExtents[0];
+                LLVector4a& max = dst_face.mExtents[1];
 
-				min = pos[0];
-				max = pos[1];
+                min = pos[0];
+                max = pos[1];
                 if (i==0)
                 {
                     box_min = min;
                     box_max = max;
                 }
 
-				for (U32 j = 1; j < dst_face.mNumVertices; ++j)
-				{
-					min.setMin(min, pos[j]);
-					max.setMax(max, pos[j]);
-				}
+                for (U32 j = 1; j < dst_face.mNumVertices; ++j)
+                {
+                    min.setMin(min, pos[j]);
+                    max.setMax(max, pos[j]);
+                }
 
                 box_min.setMin(min,box_min);
                 box_max.setMax(max,box_max);
 
-				dst_face.mCenter->setAdd(dst_face.mExtents[0], dst_face.mExtents[1]);
-				dst_face.mCenter->mul(0.5f);
+                dst_face.mCenter->setAdd(dst_face.mExtents[0], dst_face.mExtents[1]);
+                dst_face.mCenter->mul(0.5f);
 
-			}
+            }
 
             if (rebuild_face_octrees)
-			{
+            {
                 dst_face.destroyOctree();
                 dst_face.createOctree();
-			}
-		}
-	}
+            }
+        }
+    }
     mExtraDebugText = llformat("rigged %d/%d - box (%f %f %f) (%f %f %f)",
                                rigged_face_count, rigged_vert_count,
                                box_min[0], box_min[1], box_min[2],
@@ -5088,111 +5088,111 @@ void LLRiggedVolume::update(
 
 U32 LLVOVolume::getPartitionType() const
 {
-	if (isHUDAttachment())
-	{
-		return LLViewerRegion::PARTITION_HUD;
-	}
-	if (isAnimatedObject() && getControlAvatar())
-	{
-		return LLViewerRegion::PARTITION_CONTROL_AV;
-	}
-	if (isAttachment())
-	{
-		return LLViewerRegion::PARTITION_AVATAR;
-	}
+    if (isHUDAttachment())
+    {
+        return LLViewerRegion::PARTITION_HUD;
+    }
+    if (isAnimatedObject() && getControlAvatar())
+    {
+        return LLViewerRegion::PARTITION_CONTROL_AV;
+    }
+    if (isAttachment())
+    {
+        return LLViewerRegion::PARTITION_AVATAR;
+    }
 
-	return LLViewerRegion::PARTITION_VOLUME;
+    return LLViewerRegion::PARTITION_VOLUME;
 }
 
 LLVolumePartition::LLVolumePartition(LLViewerRegion* regionp)
 : LLSpatialPartition(LLVOVolume::VERTEX_DATA_MASK, TRUE, regionp),
 LLVolumeGeometryManager()
 {
-	mLODPeriod = 32;
-	mDepthMask = FALSE;
-	mDrawableType = LLPipeline::RENDER_TYPE_VOLUME;
-	mPartitionType = LLViewerRegion::PARTITION_VOLUME;
-	mSlopRatio = 0.25f;
+    mLODPeriod = 32;
+    mDepthMask = FALSE;
+    mDrawableType = LLPipeline::RENDER_TYPE_VOLUME;
+    mPartitionType = LLViewerRegion::PARTITION_VOLUME;
+    mSlopRatio = 0.25f;
 }
 
 LLVolumeBridge::LLVolumeBridge(LLDrawable* drawablep, LLViewerRegion* regionp)
 : LLSpatialBridge(drawablep, TRUE, LLVOVolume::VERTEX_DATA_MASK, regionp),
 LLVolumeGeometryManager()
 {
-	mDepthMask = FALSE;
-	mLODPeriod = 32;
-	mDrawableType = LLPipeline::RENDER_TYPE_VOLUME;
-	mPartitionType = LLViewerRegion::PARTITION_BRIDGE;
-	
-	mSlopRatio = 0.25f;
+    mDepthMask = FALSE;
+    mLODPeriod = 32;
+    mDrawableType = LLPipeline::RENDER_TYPE_VOLUME;
+    mPartitionType = LLViewerRegion::PARTITION_BRIDGE;
+
+    mSlopRatio = 0.25f;
 }
 
 LLAvatarBridge::LLAvatarBridge(LLDrawable* drawablep, LLViewerRegion* regionp)
-	: LLVolumeBridge(drawablep, regionp)
+    : LLVolumeBridge(drawablep, regionp)
 {
-	mDrawableType = LLPipeline::RENDER_TYPE_AVATAR;
-	mPartitionType = LLViewerRegion::PARTITION_AVATAR;
+    mDrawableType = LLPipeline::RENDER_TYPE_AVATAR;
+    mPartitionType = LLViewerRegion::PARTITION_AVATAR;
 }
 
 LLControlAVBridge::LLControlAVBridge(LLDrawable* drawablep, LLViewerRegion* regionp)
-	: LLVolumeBridge(drawablep, regionp)
+    : LLVolumeBridge(drawablep, regionp)
 {
-	mDrawableType = LLPipeline::RENDER_TYPE_CONTROL_AV;
-	mPartitionType = LLViewerRegion::PARTITION_CONTROL_AV;
+    mDrawableType = LLPipeline::RENDER_TYPE_CONTROL_AV;
+    mPartitionType = LLViewerRegion::PARTITION_CONTROL_AV;
 }
 
 void LLControlAVBridge::updateSpatialExtents()
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWABLE
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWABLE
 
-	LLSpatialGroup* root = (LLSpatialGroup*)mOctree->getListener(0);
+    LLSpatialGroup* root = (LLSpatialGroup*)mOctree->getListener(0);
 
-	bool rootWasDirty = root->isDirty();
+    bool rootWasDirty = root->isDirty();
 
-	super::updateSpatialExtents(); // root becomes non-dirty here
+    super::updateSpatialExtents(); // root becomes non-dirty here
 
-	// SL-18251 "On-screen animesh characters using pelvis offset animations
-	// disappear when root goes off-screen"
-	//
-	// Expand extents to include Control Avatar placed outside of the bounds
+    // SL-18251 "On-screen animesh characters using pelvis offset animations
+    // disappear when root goes off-screen"
+    //
+    // Expand extents to include Control Avatar placed outside of the bounds
     LLControlAvatar* controlAvatar = getVObj() ? getVObj()->getControlAvatar() : NULL;
     if (controlAvatar
         && controlAvatar->mDrawable
         && controlAvatar->mDrawable->getEntry()
         && (rootWasDirty || controlAvatar->mPlaying))
-	{
-		root->expandExtents(controlAvatar->mDrawable->getSpatialExtents(), *mDrawable->getXform());
-	}
+    {
+        root->expandExtents(controlAvatar->mDrawable->getSpatialExtents(), *mDrawable->getXform());
+    }
 }
 
 bool can_batch_texture(LLFace* facep)
 {
-	if (facep->getTextureEntry()->getBumpmap())
-	{ //bump maps aren't worked into texture batching yet
-		return false;
-	}
-
-	if (facep->getTextureEntry()->getMaterialParams().notNull())
-	{ //materials don't work with texture batching yet
-		return false;
-	}
-
-	if (facep->getTexture() && facep->getTexture()->getPrimaryFormat() == GL_ALPHA)
-	{ //can't batch invisiprims
-		return false;
-	}
-
-	if (facep->isState(LLFace::TEXTURE_ANIM) && facep->getVirtualSize() > MIN_TEX_ANIM_SIZE)
-	{ //texture animation breaks batches
-		return false;
-	}
-	
+    if (facep->getTextureEntry()->getBumpmap())
+    { //bump maps aren't worked into texture batching yet
+        return false;
+    }
+
+    if (facep->getTextureEntry()->getMaterialParams().notNull())
+    { //materials don't work with texture batching yet
+        return false;
+    }
+
+    if (facep->getTexture() && facep->getTexture()->getPrimaryFormat() == GL_ALPHA)
+    { //can't batch invisiprims
+        return false;
+    }
+
+    if (facep->isState(LLFace::TEXTURE_ANIM) && facep->getVirtualSize() > MIN_TEX_ANIM_SIZE)
+    { //texture animation breaks batches
+        return false;
+    }
+
     if (facep->getTextureEntry()->getGLTFRenderMaterial() != nullptr)
     { // PBR materials break indexed texture batching
         return false;
     }
 
-	return true;
+    return true;
 }
 
 const static U32 MAX_FACE_COUNT = 4096U;
@@ -5207,27 +5207,27 @@ LLFace** LLVolumeGeometryManager::sPbrFaces[2] = { NULL };
 LLFace** LLVolumeGeometryManager::sAlphaFaces[2] = { NULL };
 
 LLVolumeGeometryManager::LLVolumeGeometryManager()
-	: LLGeometryManager()
+    : LLGeometryManager()
 {
-	llassert(sInstanceCount >= 0);
-	if (sInstanceCount == 0)
-	{
-		allocateFaces(MAX_FACE_COUNT);
-	}
+    llassert(sInstanceCount >= 0);
+    if (sInstanceCount == 0)
+    {
+        allocateFaces(MAX_FACE_COUNT);
+    }
 
-	++sInstanceCount;
+    ++sInstanceCount;
 }
 
 LLVolumeGeometryManager::~LLVolumeGeometryManager()
 {
-	llassert(sInstanceCount > 0);
-	--sInstanceCount;
+    llassert(sInstanceCount > 0);
+    --sInstanceCount;
 
-	if (sInstanceCount <= 0)
-	{
-		freeFaces();
-		sInstanceCount = 0;
-	}
+    if (sInstanceCount <= 0)
+    {
+        freeFaces();
+        sInstanceCount = 0;
+    }
 }
 
 void LLVolumeGeometryManager::allocateFaces(U32 pMaxFaceCount)
@@ -5272,29 +5272,29 @@ void LLVolumeGeometryManager::freeFaces()
 void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep, U32 type)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	//if (   type == LLRenderPass::PASS_ALPHA 
-	//	&& facep->getTextureEntry()->getMaterialParams().notNull() 
-	//	&& !facep->getVertexBuffer()->hasDataType(LLVertexBuffer::TYPE_TANGENT)
-	//	&& LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 1)
-	//{
-	//	LL_WARNS_ONCE("RenderMaterials") << "Oh no! No binormals for this alpha blended face!" << LL_ENDL;
-	//}
-
-//	bool selected = facep->getViewerObject()->isSelected();
+    //if (   type == LLRenderPass::PASS_ALPHA
+    //  && facep->getTextureEntry()->getMaterialParams().notNull()
+    //  && !facep->getVertexBuffer()->hasDataType(LLVertexBuffer::TYPE_TANGENT)
+    //  && LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 1)
+    //{
+    //  LL_WARNS_ONCE("RenderMaterials") << "Oh no! No binormals for this alpha blended face!" << LL_ENDL;
+    //}
+
+//  bool selected = facep->getViewerObject()->isSelected();
 //
-//	if (selected && LLSelectMgr::getInstance()->mHideSelectedObjects)
+//  if (selected && LLSelectMgr::getInstance()->mHideSelectedObjects)
 // [RLVa:KB] - Checked: 2010-11-29 (RLVa-1.3.0c) | Modified: RLVa-1.3.0c
-	const LLViewerObject* pObj = facep->getViewerObject();
-	if ( (pObj->isSelected() && LLSelectMgr::getInstance()->mHideSelectedObjects) &&
-		 ( (!RlvActions::isRlvEnabled()) ||
-		   ( ((!pObj->isHUDAttachment()) || (!gRlvAttachmentLocks.isLockedAttachment(pObj->getRootEdit()))) &&
-		     (RlvActions::canEdit(pObj)) ) ) )
+    const LLViewerObject* pObj = facep->getViewerObject();
+    if ( (pObj->isSelected() && LLSelectMgr::getInstance()->mHideSelectedObjects) &&
+         ( (!RlvActions::isRlvEnabled()) ||
+           ( ((!pObj->isHUDAttachment()) || (!gRlvAttachmentLocks.isLockedAttachment(pObj->getRootEdit()))) &&
+             (RlvActions::canEdit(pObj)) ) ) )
 // [/RVLa:KB]
-	{
-		return;
-	}
+    {
+        return;
+    }
 
-	LL_LABEL_VERTEX_BUFFER(facep->getVertexBuffer(), LLRenderPass::lookupPassName(type));
+    LL_LABEL_VERTEX_BUFFER(facep->getVertexBuffer(), LLRenderPass::lookupPassName(type));
 
     U32 passType = type;
 
@@ -5306,66 +5306,66 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep,
         // See LLRenderPass PASS_foo enum
         passType += 1;
     }
-	//add face to drawmap
-	LLSpatialGroup::drawmap_elem_t& draw_vec = group->mDrawMap[passType];
+    //add face to drawmap
+    LLSpatialGroup::drawmap_elem_t& draw_vec = group->mDrawMap[passType];
+
+    S32 idx = draw_vec.size()-1;
 
-	S32 idx = draw_vec.size()-1;
+    bool fullbright = (type == LLRenderPass::PASS_FULLBRIGHT) ||
+        (type == LLRenderPass::PASS_INVISIBLE) ||
+        (type == LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK) ||
+        (type == LLRenderPass::PASS_ALPHA && facep->isState(LLFace::FULLBRIGHT)) ||
+        (facep->getTextureEntry()->getFullbright());
 
-	bool fullbright = (type == LLRenderPass::PASS_FULLBRIGHT) ||
-		(type == LLRenderPass::PASS_INVISIBLE) ||
-		(type == LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK) ||
-		(type == LLRenderPass::PASS_ALPHA && facep->isState(LLFace::FULLBRIGHT)) ||
-		(facep->getTextureEntry()->getFullbright());
-	
-	if (!fullbright && 
-        type != LLRenderPass::PASS_GLOW && 
+    if (!fullbright &&
+        type != LLRenderPass::PASS_GLOW &&
         !facep->getVertexBuffer()->hasDataType(LLVertexBuffer::TYPE_NORMAL))
-	{
+    {
         llassert(false);
-		LL_WARNS() << "Non fullbright face has no normals!" << LL_ENDL;
-		return;
-	}
+        LL_WARNS() << "Non fullbright face has no normals!" << LL_ENDL;
+        return;
+    }
+
+    const LLMatrix4a* tex_mat = NULL;
+    if (facep->isState(LLFace::TEXTURE_ANIM) && facep->getVirtualSize() > MIN_TEX_ANIM_SIZE)
+    {
+        tex_mat = facep->mTextureMatrix;
+    }
 
-	const LLMatrix4a* tex_mat = NULL;
-	if (facep->isState(LLFace::TEXTURE_ANIM) && facep->getVirtualSize() > MIN_TEX_ANIM_SIZE)
-	{
-		tex_mat = facep->mTextureMatrix;	
-	}
+    const LLMatrix4a* model_mat = NULL;
 
-	const LLMatrix4a* model_mat = NULL;
+    LLDrawable* drawable = facep->getDrawable();
 
-	LLDrawable* drawable = facep->getDrawable();
-	
     if (rigged)
     {
         // rigged meshes ignore their model matrix
         model_mat = nullptr;
     }
-	else if (drawable->isState(LLDrawable::ANIMATED_CHILD))
-	{
-		model_mat = &drawable->getWorldMatrix();
-	}
-	else if (drawable->isActive())
-	{
-		model_mat = &drawable->getRenderMatrix();
-	}
-	else
-	{
-		model_mat = &(drawable->getRegion()->mRenderMatrix);
-	}
-
-	//drawable->getVObj()->setDebugText(llformat("%d", drawable->isState(LLDrawable::ANIMATED_CHILD)));
+    else if (drawable->isState(LLDrawable::ANIMATED_CHILD))
+    {
+        model_mat = &drawable->getWorldMatrix();
+    }
+    else if (drawable->isActive())
+    {
+        model_mat = &drawable->getRenderMatrix();
+    }
+    else
+    {
+        model_mat = &(drawable->getRegion()->mRenderMatrix);
+    }
+
+    //drawable->getVObj()->setDebugText(llformat("%d", drawable->isState(LLDrawable::ANIMATED_CHILD)));
 
     const LLTextureEntry* te = facep->getTextureEntry();
-	U8 bump = (type == LLRenderPass::PASS_BUMP || type == LLRenderPass::PASS_POST_BUMP) ? te->getBumpmap() : 0;
-	U8 shiny = te->getShiny();
-	
-	LLViewerTexture* tex = facep->getTexture();
+    U8 bump = (type == LLRenderPass::PASS_BUMP || type == LLRenderPass::PASS_POST_BUMP) ? te->getBumpmap() : 0;
+    U8 shiny = te->getShiny();
 
-	U8 index = facep->getTextureIndex();
+    LLViewerTexture* tex = facep->getTexture();
+
+    U8 index = facep->getTextureIndex();
 
     LLMaterial* mat = nullptr;
-    
+
     LLUUID mat_id;
 
     auto* gltf_mat = (LLFetchedGLTFMaterial*)te->getGLTFRenderMaterial();
@@ -5387,110 +5387,110 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep,
         }
     }
 
-	bool batchable = false;
-
-	U32 shader_mask = 0xFFFFFFFF; //no shader
-
-	if (mat)
-	{
-		BOOL is_alpha = (facep->getPoolType() == LLDrawPool::POOL_ALPHA) || (te->getColor().mV[3] < 0.999f) ? TRUE : FALSE;
-		if (type == LLRenderPass::PASS_ALPHA)
-		{
-			shader_mask = mat->getShaderMask(LLMaterial::DIFFUSE_ALPHA_MODE_BLEND, is_alpha);
-		}
-		else
-		{
-			shader_mask = mat->getShaderMask(LLMaterial::DIFFUSE_ALPHA_MODE_DEFAULT, is_alpha);
-		}
-	}
-
-	if (index < FACE_DO_NOT_BATCH_TEXTURES && idx >= 0)
-	{
-		if (mat || gltf_mat || draw_vec[idx]->mMaterial)
-		{ //can't batch textures when materials are present (yet)
-			batchable = false;
-		}
-		else if (index < draw_vec[idx]->mTextureList.size())
-		{
-			if (draw_vec[idx]->mTextureList[index].isNull())
-			{
-				batchable = true;
-				draw_vec[idx]->mTextureList[index] = tex;
-			}
-			else if (draw_vec[idx]->mTextureList[index] == tex)
-			{ //this face's texture index can be used with this batch
-				batchable = true;
-			}
-		}
-		else
-		{ //texture list can be expanded to fit this texture index
-			batchable = true;
-		}
-	}
+    bool batchable = false;
+
+    U32 shader_mask = 0xFFFFFFFF; //no shader
+
+    if (mat)
+    {
+        BOOL is_alpha = (facep->getPoolType() == LLDrawPool::POOL_ALPHA) || (te->getColor().mV[3] < 0.999f) ? TRUE : FALSE;
+        if (type == LLRenderPass::PASS_ALPHA)
+        {
+            shader_mask = mat->getShaderMask(LLMaterial::DIFFUSE_ALPHA_MODE_BLEND, is_alpha);
+        }
+        else
+        {
+            shader_mask = mat->getShaderMask(LLMaterial::DIFFUSE_ALPHA_MODE_DEFAULT, is_alpha);
+        }
+    }
+
+    if (index < FACE_DO_NOT_BATCH_TEXTURES && idx >= 0)
+    {
+        if (mat || gltf_mat || draw_vec[idx]->mMaterial)
+        { //can't batch textures when materials are present (yet)
+            batchable = false;
+        }
+        else if (index < draw_vec[idx]->mTextureList.size())
+        {
+            if (draw_vec[idx]->mTextureList[index].isNull())
+            {
+                batchable = true;
+                draw_vec[idx]->mTextureList[index] = tex;
+            }
+            else if (draw_vec[idx]->mTextureList[index] == tex)
+            { //this face's texture index can be used with this batch
+                batchable = true;
+            }
+        }
+        else
+        { //texture list can be expanded to fit this texture index
+            batchable = true;
+        }
+    }
 
     LLDrawInfo* info = idx >= 0 ? draw_vec[idx] : nullptr;
 
-	if (info && 
-		info->mVertexBuffer == facep->getVertexBuffer() &&
-		info->mEnd == facep->getGeomIndex()-1 &&
-		(LLPipeline::sTextureBindTest || draw_vec[idx]->mTexture == tex || batchable) &&
+    if (info &&
+        info->mVertexBuffer == facep->getVertexBuffer() &&
+        info->mEnd == facep->getGeomIndex()-1 &&
+        (LLPipeline::sTextureBindTest || draw_vec[idx]->mTexture == tex || batchable) &&
 #if LL_DARWIN
-		info->mEnd - draw_vec[idx]->mStart + facep->getGeomCount() <= (U32) gGLManager.mGLMaxVertexRange &&
-		info->mCount + facep->getIndicesCount() <= (U32) gGLManager.mGLMaxIndexRange &&
+        info->mEnd - draw_vec[idx]->mStart + facep->getGeomCount() <= (U32) gGLManager.mGLMaxVertexRange &&
+        info->mCount + facep->getIndicesCount() <= (U32) gGLManager.mGLMaxIndexRange &&
 #endif
-		info->mMaterialID == mat_id &&
-		info->mFullbright == fullbright &&
-		info->mBump == bump &&
-		(!mat || (info->mShiny == shiny)) && // need to break batches when a material is shared, but legacy settings are different
-		info->mTextureMatrix == tex_mat &&
-		info->mModelMatrix == model_mat &&
-		info->mShaderMask == shader_mask &&
+        info->mMaterialID == mat_id &&
+        info->mFullbright == fullbright &&
+        info->mBump == bump &&
+        (!mat || (info->mShiny == shiny)) && // need to break batches when a material is shared, but legacy settings are different
+        info->mTextureMatrix == tex_mat &&
+        info->mModelMatrix == model_mat &&
+        info->mShaderMask == shader_mask &&
         info->mAvatar == facep->mAvatar &&
         info->getSkinHash() == facep->getSkinHash())
-	{
-		info->mCount += facep->getIndicesCount();
-		info->mEnd += facep->getGeomCount();
-
-		if (index < FACE_DO_NOT_BATCH_TEXTURES && index >= info->mTextureList.size())
-		{
-			info->mTextureList.resize(index+1);
-			info->mTextureList[index] = tex;
-		}
-		info->validate();
-	}
-	else
-	{
-		U32 start = facep->getGeomIndex();
-		U32 end = start + facep->getGeomCount()-1;
-		U32 offset = facep->getIndicesStart();
-		U32 count = facep->getIndicesCount();
-		LLPointer<LLDrawInfo> draw_info = new LLDrawInfo(start,end,count,offset, tex,
-			facep->getVertexBuffer(), fullbright, bump);
+    {
+        info->mCount += facep->getIndicesCount();
+        info->mEnd += facep->getGeomCount();
+
+        if (index < FACE_DO_NOT_BATCH_TEXTURES && index >= info->mTextureList.size())
+        {
+            info->mTextureList.resize(index+1);
+            info->mTextureList[index] = tex;
+        }
+        info->validate();
+    }
+    else
+    {
+        U32 start = facep->getGeomIndex();
+        U32 end = start + facep->getGeomCount()-1;
+        U32 offset = facep->getIndicesStart();
+        U32 count = facep->getIndicesCount();
+        LLPointer<LLDrawInfo> draw_info = new LLDrawInfo(start,end,count,offset, tex,
+            facep->getVertexBuffer(), fullbright, bump);
 
         info = draw_info;
 
-		draw_vec.push_back(draw_info);
-		draw_info->mTextureMatrix = tex_mat;
-		draw_info->mModelMatrix = model_mat;
-		
-		draw_info->mBump  = bump;
-		draw_info->mShiny = shiny;
-
-		static const float alpha[4] =
-		{
-			0.00f,
-			0.25f,
-			0.5f,
-			0.75f
-		};
-		float spec = alpha[shiny & TEM_SHINY_MASK];
-		LLVector4 specColor(spec, spec, spec, spec);
-		draw_info->mSpecColor = specColor;
-		draw_info->mEnvIntensity = spec;
-		draw_info->mSpecularMap = NULL;
-		draw_info->mMaterial = mat;
+        draw_vec.push_back(draw_info);
+        draw_info->mTextureMatrix = tex_mat;
+        draw_info->mModelMatrix = model_mat;
+
+        draw_info->mBump  = bump;
+        draw_info->mShiny = shiny;
+
+        static const float alpha[4] =
+        {
+            0.00f,
+            0.25f,
+            0.5f,
+            0.75f
+        };
+        float spec = alpha[shiny & TEM_SHINY_MASK];
+        LLVector4 specColor(spec, spec, spec, spec);
+        draw_info->mSpecColor = specColor;
+        draw_info->mEnvIntensity = spec;
+        draw_info->mSpecularMap = NULL;
+        draw_info->mMaterial = mat;
         draw_info->mGLTFMaterial = gltf_mat;
-		draw_info->mShaderMask = shader_mask;
+        draw_info->mShaderMask = shader_mask;
         draw_info->mAvatar = facep->mAvatar;
         draw_info->mSkinInfo = facep->mSkinInfo;
 
@@ -5500,58 +5500,58 @@ void LLVolumeGeometryManager::registerFace(LLSpatialGroup* group, LLFace* facep,
             draw_info->mMaterialID = mat_id;
         }
         else if (mat)
-		{
-			draw_info->mMaterialID = mat_id;
-
-			// We have a material.  Update our draw info accordingly.
-				
-			if (!mat->getSpecularID().isNull())
-			{
-				LLVector4 specColor;
-				specColor.mV[0] = mat->getSpecularLightColor().mV[0] * (1.f / 255.f);
-				specColor.mV[1] = mat->getSpecularLightColor().mV[1] * (1.f / 255.f);
-				specColor.mV[2] = mat->getSpecularLightColor().mV[2] * (1.f / 255.f);
-				specColor.mV[3] = mat->getSpecularLightExponent() * (1.f / 255.f);
-				draw_info->mSpecColor = specColor;
-				draw_info->mEnvIntensity = mat->getEnvironmentIntensity() * (1.f / 255.f);
-				draw_info->mSpecularMap = facep->getViewerObject()->getTESpecularMap(facep->getTEOffset());
-			}
-
-			draw_info->mAlphaMaskCutoff = mat->getAlphaMaskCutoff() * (1.f / 255.f);
-			draw_info->mDiffuseAlphaMode = mat->getDiffuseAlphaMode();
-			draw_info->mNormalMap = facep->getViewerObject()->getTENormalMap(facep->getTEOffset());
-		}
-		else 
-		{
-			if (type == LLRenderPass::PASS_GRASS)
-			{
-				draw_info->mAlphaMaskCutoff = 0.5f;
-			}
-			else
-			{
-				draw_info->mAlphaMaskCutoff = 0.33f;
-			}
-		}
-		
-		// if (type == LLRenderPass::PASS_ALPHA) // always populate the draw_info ptr
-		{ //for alpha sorting
-			facep->setDrawInfo(draw_info);
-		}
-
-		if (index < FACE_DO_NOT_BATCH_TEXTURES)
-		{ //initialize texture list for texture batching
-			draw_info->mTextureList.resize(index+1);
-			draw_info->mTextureList[index] = tex;
-		}
-		draw_info->validate();
-	}
+        {
+            draw_info->mMaterialID = mat_id;
+
+            // We have a material.  Update our draw info accordingly.
+
+            if (!mat->getSpecularID().isNull())
+            {
+                LLVector4 specColor;
+                specColor.mV[0] = mat->getSpecularLightColor().mV[0] * (1.f / 255.f);
+                specColor.mV[1] = mat->getSpecularLightColor().mV[1] * (1.f / 255.f);
+                specColor.mV[2] = mat->getSpecularLightColor().mV[2] * (1.f / 255.f);
+                specColor.mV[3] = mat->getSpecularLightExponent() * (1.f / 255.f);
+                draw_info->mSpecColor = specColor;
+                draw_info->mEnvIntensity = mat->getEnvironmentIntensity() * (1.f / 255.f);
+                draw_info->mSpecularMap = facep->getViewerObject()->getTESpecularMap(facep->getTEOffset());
+            }
+
+            draw_info->mAlphaMaskCutoff = mat->getAlphaMaskCutoff() * (1.f / 255.f);
+            draw_info->mDiffuseAlphaMode = mat->getDiffuseAlphaMode();
+            draw_info->mNormalMap = facep->getViewerObject()->getTENormalMap(facep->getTEOffset());
+        }
+        else
+        {
+            if (type == LLRenderPass::PASS_GRASS)
+            {
+                draw_info->mAlphaMaskCutoff = 0.5f;
+            }
+            else
+            {
+                draw_info->mAlphaMaskCutoff = 0.33f;
+            }
+        }
+
+        // if (type == LLRenderPass::PASS_ALPHA) // always populate the draw_info ptr
+        { //for alpha sorting
+            facep->setDrawInfo(draw_info);
+        }
+
+        if (index < FACE_DO_NOT_BATCH_TEXTURES)
+        { //initialize texture list for texture batching
+            draw_info->mTextureList.resize(index+1);
+            draw_info->mTextureList[index] = tex;
+        }
+        draw_info->validate();
+    }
 
     llassert(info->mGLTFMaterial == nullptr || (info->mVertexBuffer->getTypeMask() & LLVertexBuffer::MAP_TANGENT) != 0);
     llassert(type != LLPipeline::RENDER_TYPE_PASS_GLTF_PBR || info->mGLTFMaterial != nullptr);
     llassert(type != LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_RIGGED || info->mGLTFMaterial != nullptr);
     llassert(type != LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_ALPHA_MASK || info->mGLTFMaterial != nullptr);
     llassert(type != LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_ALPHA_MASK_RIGGED || info->mGLTFMaterial != nullptr);
-    
+
     llassert(type != LLRenderPass::PASS_BUMP || (info->mVertexBuffer->getTypeMask() & LLVertexBuffer::MAP_TANGENT) != 0);
     llassert(type != LLRenderPass::PASS_NORMSPEC || info->mNormalMap.notNull());
     llassert(type != LLRenderPass::PASS_SPECMAP || (info->mVertexBuffer->getTypeMask() & LLVertexBuffer::MAP_TEXCOORD2) != 0);
@@ -5594,79 +5594,79 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
         return;
     }
 
-	if (group->changeLOD())
-	{
-		group->mLastUpdateDistance = group->mDistance;
-	}
+    if (group->changeLOD())
+    {
+        group->mLastUpdateDistance = group->mDistance;
+    }
+
+    group->mLastUpdateViewAngle = group->mViewAngle;
+
+    if (!group->hasState(LLSpatialGroup::GEOM_DIRTY | LLSpatialGroup::ALPHA_DIRTY))
+    {
+        if (group->hasState(LLSpatialGroup::MESH_DIRTY))
+        {
+            rebuildMesh(group);
+        }
+        return;
+    }
 
-	group->mLastUpdateViewAngle = group->mViewAngle;
+    group->mBuilt = 1.f;
 
-	if (!group->hasState(LLSpatialGroup::GEOM_DIRTY | LLSpatialGroup::ALPHA_DIRTY))
-	{
-		if (group->hasState(LLSpatialGroup::MESH_DIRTY))
-		{
-			rebuildMesh(group);
-		}
-		return;
-	}
+    group->mGeometryBytes = 0;
+    group->mSurfaceArea = 0;
 
-	group->mBuilt = 1.f;
-	
-	group->mGeometryBytes = 0;
-	group->mSurfaceArea = 0;
-	
-	//cache object box size since it might be used for determining visibility
-	const LLVector4a* bounds = group->getObjectBounds();
-	group->mObjectBoxSize = bounds[1].getLength3().getF32();
+    //cache object box size since it might be used for determining visibility
+    const LLVector4a* bounds = group->getObjectBounds();
+    group->mObjectBoxSize = bounds[1].getLength3().getF32();
 
-	group->clearDrawMap();
+    group->clearDrawMap();
 
     U32 fullbright_count[2] = { 0 };
-	U32 bump_count[2] = { 0 };
-	U32 simple_count[2] = { 0 };
-	U32 alpha_count[2] = { 0 };
-	U32 norm_count[2] = { 0 };
-	U32 spec_count[2] = { 0 };
-	U32 normspec_count[2] = { 0 };
-	U32 pbr_count[2] = { 0 };
-
-	static LLCachedControl<S32> max_vbo_size(gSavedSettings, "RenderMaxVBOSize", 512);
-	static LLCachedControl<S32> max_node_size(gSavedSettings, "RenderMaxNodeSize", 65536);
-	U32 max_vertices = (max_vbo_size * 1024)/LLVertexBuffer::calcVertexSize(group->getSpatialPartition()->mVertexDataMask);
-	U32 max_total = (max_node_size * 1024) / LLVertexBuffer::calcVertexSize(group->getSpatialPartition()->mVertexDataMask);
-	max_vertices = llmin(max_vertices, (U32) 65535);
-
-	U32 cur_total = 0;
-
-	bool emissive = false;
-
-	//Determine if we've received skininfo that contains an
-	//alternate bind matrix - if it does then apply the translational component
-	//to the joints of the avatar.
+    U32 bump_count[2] = { 0 };
+    U32 simple_count[2] = { 0 };
+    U32 alpha_count[2] = { 0 };
+    U32 norm_count[2] = { 0 };
+    U32 spec_count[2] = { 0 };
+    U32 normspec_count[2] = { 0 };
+    U32 pbr_count[2] = { 0 };
+
+    static LLCachedControl<S32> max_vbo_size(gSavedSettings, "RenderMaxVBOSize", 512);
+    static LLCachedControl<S32> max_node_size(gSavedSettings, "RenderMaxNodeSize", 65536);
+    U32 max_vertices = (max_vbo_size * 1024)/LLVertexBuffer::calcVertexSize(group->getSpatialPartition()->mVertexDataMask);
+    U32 max_total = (max_node_size * 1024) / LLVertexBuffer::calcVertexSize(group->getSpatialPartition()->mVertexDataMask);
+    max_vertices = llmin(max_vertices, (U32) 65535);
+
+    U32 cur_total = 0;
+
+    bool emissive = false;
+
+    //Determine if we've received skininfo that contains an
+    //alternate bind matrix - if it does then apply the translational component
+    //to the joints of the avatar.
 #if 0
-	bool pelvisGotSet = false;
+    bool pelvisGotSet = false;
 #endif
 
-	{
+    {
         LL_PROFILE_ZONE_NAMED("rebuildGeom - face list");
 
-		//get all the faces into a list
-		for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(); 
+        //get all the faces into a list
+        for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin();
              drawable_iter != group->getDataEnd(); ++drawable_iter)
-		{
-			LLDrawable* drawablep = (LLDrawable*)(*drawable_iter)->getDrawable();
-		
-			if (!drawablep || drawablep->isDead() || drawablep->isState(LLDrawable::FORCE_INVISIBLE) )
-			{
-				continue;
-			}
-	
-			LLVOVolume* vobj = drawablep->getVOVolume();
-            
-			if (!vobj || vobj->isDead())
-			{
-				continue;
-			}
+        {
+            LLDrawable* drawablep = (LLDrawable*)(*drawable_iter)->getDrawable();
+
+            if (!drawablep || drawablep->isDead() || drawablep->isState(LLDrawable::FORCE_INVISIBLE) )
+            {
+                continue;
+            }
+
+            LLVOVolume* vobj = drawablep->getVOVolume();
+
+            if (!vobj || vobj->isDead())
+            {
+                continue;
+            }
 
             // HACK -- brute force this check every time a drawable gets rebuilt
             for (S32 i = 0; i < drawablep->getNumFaces(); ++i)
@@ -5694,25 +5694,25 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
                 }
             }
 
-			LLVolume* volume = vobj->getVolume();
-			if (volume)
-			{
-				const LLVector3& scale = vobj->getScale();
-				group->mSurfaceArea += volume->getSurfaceArea() * llmax(llmax(scale.mV[0], scale.mV[1]), scale.mV[2]);
-			}
+            LLVolume* volume = vobj->getVolume();
+            if (volume)
+            {
+                const LLVector3& scale = vobj->getScale();
+                group->mSurfaceArea += volume->getSurfaceArea() * llmax(llmax(scale.mV[0], scale.mV[1]), scale.mV[2]);
+            }
 
             vobj->updateControlAvatar();
-            
+
 #ifdef SHOW_DEBUG
-			std::string vobj_name = llformat("Vol%p", vobj);
+            std::string vobj_name = llformat("Vol%p", vobj);
 
-			F32 est_tris = vobj->getEstTrianglesMax();
-			LL_DEBUGS("AnimatedObjectsLinkset") << vobj_name << " rebuilding, isAttachment: " << (U32) vobj->isAttachment()
+            F32 est_tris = vobj->getEstTrianglesMax();
+            LL_DEBUGS("AnimatedObjectsLinkset") << vobj_name << " rebuilding, isAttachment: " << (U32) vobj->isAttachment()
                                                 << " is_mesh " << is_mesh
                                                 << " est_tris " << est_tris
                                                 << " is_animated " << vobj->isAnimatedObject()
-                                                << " can_animate " << vobj->canBeAnimatedObject() 
-                                                << " cav " << vobj->getControlAvatar() 
+                                                << " can_animate " << vobj->canBeAnimatedObject()
+                                                << " cav " << vobj->getControlAvatar()
                                                 << " lod " << vobj->getLOD()
                                                 << " drawable rigged " << (drawablep->isState(LLDrawable::RIGGED))
                                                 << " drawable state " << drawablep->getState()
@@ -5720,13 +5720,13 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
                                                 << " frame " << LLFrameTimer::getFrameCount()
                                                 << LL_ENDL;
 
-			llassert_always(vobj);
+            llassert_always(vobj);
 #endif
 
-			vobj->updateTextureVirtualSize(true);
-			vobj->preRebuild();
+            vobj->updateTextureVirtualSize(true);
+            vobj->preRebuild();
 
-			drawablep->clearState(LLDrawable::HAS_ALPHA);
+            drawablep->clearState(LLDrawable::HAS_ALPHA);
 
             LLVOAvatar* avatar = nullptr;
             const LLMeshSkinInfo* skinInfo = nullptr;
@@ -5752,23 +5752,23 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
                 avatar->addAttachmentOverridesForObject(vobj, NULL, false);
             }
 
-            // Standard rigged mesh attachments: 
-			bool rigged = !vobj->isAnimatedObject() && skinInfo && vobj->isAttachment();
+            // Standard rigged mesh attachments:
+            bool rigged = !vobj->isAnimatedObject() && skinInfo && vobj->isAttachment();
             // Animated objects. Have to check for isRiggedMesh() to
             // exclude static objects in animated object linksets.
-			rigged = rigged || (vobj->isAnimatedObject() && vobj->isRiggedMesh() &&
+            rigged = rigged || (vobj->isAnimatedObject() && vobj->isRiggedMesh() &&
                 vobj->getControlAvatar() && vobj->getControlAvatar()->mPlaying);
 
-			bool any_rigged_face = false;
+            bool any_rigged_face = false;
 
-			//for each face
-			for (S32 i = 0, i_end = drawablep->getNumFaces(); i < i_end; ++i)
-			{
-				LLFace* facep = drawablep->getFace(i);
-				if (!facep)
-				{
-					continue;
-				}
+            //for each face
+            for (S32 i = 0, i_end = drawablep->getNumFaces(); i < i_end; ++i)
+            {
+                LLFace* facep = drawablep->getFace(i);
+                if (!facep)
+                {
+                    continue;
+                }
 #if 0
 #if LL_RELEASE_WITH_DEBUG_INFO
                 const LLUUID pbr_id( "49c88210-7238-2a6b-70ac-92d4f35963cf" );
@@ -5782,12 +5782,12 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
                 bool is_pbr = gltf_mat != nullptr;
 #endif
 
-				//ALWAYS null out vertex buffer on rebuild -- if the face lands in a render
-				// batch, it will recover its vertex buffer reference from the spatial group
-				facep->setVertexBuffer(NULL);
-			
-				//sum up face verts and indices
-				drawablep->updateFaceSize(i);
+                //ALWAYS null out vertex buffer on rebuild -- if the face lands in a render
+                // batch, it will recover its vertex buffer reference from the spatial group
+                facep->setVertexBuffer(NULL);
+
+                //sum up face verts and indices
+                drawablep->updateFaceSize(i);
 
                 if (rigged)
                 {
@@ -5804,7 +5804,7 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
                 else
                 {
                     if (facep->isState(LLFace::RIGGED))
-                    { 
+                    {
                         //face is not rigged but used to be, remove from rigged face pool
                         LLDrawPoolAvatar* pool = (LLDrawPoolAvatar*)facep->getPool();
                         if (pool)
@@ -5817,84 +5817,84 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
                     }
                 }
 
-				if (cur_total > max_total || facep->getIndicesCount() <= 0 || facep->getGeomCount() <= 0)
-				{
-					facep->clearVertexBuffer();
-					continue;
-				}
+                if (cur_total > max_total || facep->getIndicesCount() <= 0 || facep->getGeomCount() <= 0)
+                {
+                    facep->clearVertexBuffer();
+                    continue;
+                }
 
-				if (facep->hasGeometry() &&
+                if (facep->hasGeometry() &&
                     (rigged ||  // <-- HACK FIXME -- getPixelArea might be incorrect for rigged objects
                         facep->getPixelArea() > FORCE_CULL_AREA)) // <-- don't render tiny faces
-				{
+                {
                     cur_total += facep->getGeomCount();
 
-					const LLTextureEntry* te = facep->getTextureEntry();
-					LLViewerTexture* tex = facep->getTexture();
+                    const LLTextureEntry* te = facep->getTextureEntry();
+                    LLViewerTexture* tex = facep->getTexture();
 
-					if (te->getGlow() > 0.f)
-					{
-						emissive = true;
-					}
+                    if (te->getGlow() > 0.f)
+                    {
+                        emissive = true;
+                    }
 
-					if (facep->isState(LLFace::TEXTURE_ANIM))
-					{
-						if (!vobj->mTexAnimMode)
-						{
-							facep->clearState(LLFace::TEXTURE_ANIM);
-						}
-					}
+                    if (facep->isState(LLFace::TEXTURE_ANIM))
+                    {
+                        if (!vobj->mTexAnimMode)
+                        {
+                            facep->clearState(LLFace::TEXTURE_ANIM);
+                        }
+                    }
 
-					BOOL force_simple = (facep->getPixelArea() < FORCE_SIMPLE_RENDER_AREA);
-					U32 type = gPipeline.getPoolTypeFromTE(te, tex);
+                    BOOL force_simple = (facep->getPixelArea() < FORCE_SIMPLE_RENDER_AREA);
+                    U32 type = gPipeline.getPoolTypeFromTE(te, tex);
                     if (is_pbr && gltf_mat && gltf_mat->mAlphaMode != LLGLTFMaterial::ALPHA_MODE_BLEND)
                     {
                         type = LLDrawPool::POOL_GLTF_PBR;
                     }
                     else if (type != LLDrawPool::POOL_ALPHA && force_simple)
-					{
-						type = LLDrawPool::POOL_SIMPLE;
-					}
-					facep->setPoolType(type);
-
-					if (vobj->isHUDAttachment() && !is_pbr)
-					{
-						facep->setState(LLFace::FULLBRIGHT);
-					}
-
-					if (vobj->mTextureAnimp && vobj->mTexAnimMode)
-					{
-						if (vobj->mTextureAnimp->mFace <= -1)
-						{
-							S32 face;
-							for (face = 0; face < vobj->getNumTEs(); face++)
-							{
-								LLFace * facep = drawablep->getFace(face);
-								if (facep)
-								{
-									facep->setState(LLFace::TEXTURE_ANIM);
-								}
-							}
-						}
-						else if (vobj->mTextureAnimp->mFace < vobj->getNumTEs())
-						{
-							LLFace * facep = drawablep->getFace(vobj->mTextureAnimp->mFace);
-							if (facep)
-							{
-								facep->setState(LLFace::TEXTURE_ANIM);
-							}
-						}
-					}
-
-					if (type == LLDrawPool::POOL_ALPHA)
-					{
-						if (facep->canRenderAsMask())
-						{ //can be treated as alpha mask
+                    {
+                        type = LLDrawPool::POOL_SIMPLE;
+                    }
+                    facep->setPoolType(type);
+
+                    if (vobj->isHUDAttachment() && !is_pbr)
+                    {
+                        facep->setState(LLFace::FULLBRIGHT);
+                    }
+
+                    if (vobj->mTextureAnimp && vobj->mTexAnimMode)
+                    {
+                        if (vobj->mTextureAnimp->mFace <= -1)
+                        {
+                            S32 face;
+                            for (face = 0; face < vobj->getNumTEs(); face++)
+                            {
+                                LLFace * facep = drawablep->getFace(face);
+                                if (facep)
+                                {
+                                    facep->setState(LLFace::TEXTURE_ANIM);
+                                }
+                            }
+                        }
+                        else if (vobj->mTextureAnimp->mFace < vobj->getNumTEs())
+                        {
+                            LLFace * facep = drawablep->getFace(vobj->mTextureAnimp->mFace);
+                            if (facep)
+                            {
+                                facep->setState(LLFace::TEXTURE_ANIM);
+                            }
+                        }
+                    }
+
+                    if (type == LLDrawPool::POOL_ALPHA)
+                    {
+                        if (facep->canRenderAsMask())
+                        { //can be treated as alpha mask
                             add_face(sSimpleFaces, simple_count, facep);
-						}
-						else
-						{
-							static LLCachedControl<bool> render_reflection_object(gSavedSettings, "RenderReflectionProbeShowTransparent", false);
+                        }
+                        else
+                        {
+                            static LLCachedControl<bool> render_reflection_object(gSavedSettings, "RenderReflectionProbeShowTransparent", false);
                             F32 alpha;
                             if (is_pbr)
                             {
@@ -5905,33 +5905,33 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
                                 alpha = te->getColor().mV[3];
                             }
                             if (alpha > 0.f || te->getGlow() > 0.f)
-							{ //only treat as alpha in the pipeline if < 100% transparent
-								drawablep->setState(LLDrawable::HAS_ALPHA);
-								add_face(sAlphaFaces, alpha_count, facep);
-							}
-							else if ((LLDrawPoolAlpha::sShowDebugAlpha && (render_reflection_object || !vobj->isReflectionProbe())) ||
-								(gPipeline.sRenderHighlight && !drawablep->getParent() &&
-								//only root objects are highlighted with red color in this case
-								drawablep->getVObj() && drawablep->getVObj()->flagScripted() &&
-								(LLPipeline::getRenderScriptedBeacons() ||
-								(LLPipeline::getRenderScriptedTouchBeacons() && drawablep->getVObj()->flagHandleTouch()))))
-							{ //draw the transparent face for debugging purposes using a custom texture
-								add_face(sAlphaFaces, alpha_count, facep);
-							}
-						}
-					}
-					else
-					{
-						if (drawablep->isState(LLDrawable::REBUILD_VOLUME))
-						{
-							facep->mLastUpdateTime = gFrameTimeSeconds;
-						}
-
-						{
+                            { //only treat as alpha in the pipeline if < 100% transparent
+                                drawablep->setState(LLDrawable::HAS_ALPHA);
+                                add_face(sAlphaFaces, alpha_count, facep);
+                            }
+                            else if ((LLDrawPoolAlpha::sShowDebugAlpha && (render_reflection_object || !vobj->isReflectionProbe())) ||
+                                (gPipeline.sRenderHighlight && !drawablep->getParent() &&
+                                //only root objects are highlighted with red color in this case
+                                drawablep->getVObj() && drawablep->getVObj()->flagScripted() &&
+                                (LLPipeline::getRenderScriptedBeacons() ||
+                                (LLPipeline::getRenderScriptedTouchBeacons() && drawablep->getVObj()->flagHandleTouch()))))
+                            { //draw the transparent face for debugging purposes using a custom texture
+                                add_face(sAlphaFaces, alpha_count, facep);
+                            }
+                        }
+                    }
+                    else
+                    {
+                        if (drawablep->isState(LLDrawable::REBUILD_VOLUME))
+                        {
+                            facep->mLastUpdateTime = gFrameTimeSeconds;
+                        }
+
+                        {
                             LLGLTFMaterial* gltf_mat = te->getGLTFRenderMaterial();
 
-							if (gltf_mat != nullptr || (te->getMaterialParams().notNull()))
-							{
+                            if (gltf_mat != nullptr || (te->getMaterialParams().notNull()))
+                            {
                                 if (gltf_mat != nullptr)
                                 {
                                     add_face(sPbrFaces, pbr_count, facep);
@@ -5960,91 +5960,91 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
                                         add_face(sSimpleFaces, simple_count, facep);
                                     }
                                 }
-							}
-							else if (te->getBumpmap())
-							{ //needs normal + tangent
+                            }
+                            else if (te->getBumpmap())
+                            { //needs normal + tangent
                                 add_face(sBumpFaces, bump_count, facep);
-							}
-							else if (te->getShiny() || !te->getFullbright())
-							{ //needs normal
+                            }
+                            else if (te->getShiny() || !te->getFullbright())
+                            { //needs normal
                                 add_face(sSimpleFaces, simple_count, facep);
-							}
-							else 
-							{ //doesn't need normal
-								facep->setState(LLFace::FULLBRIGHT);
+                            }
+                            else
+                            { //doesn't need normal
+                                facep->setState(LLFace::FULLBRIGHT);
                                 add_face(sFullbrightFaces, fullbright_count, facep);
-							}
-						}
-					}
-				}
-				else
-				{	//face has no renderable geometry
-					facep->clearVertexBuffer();
-				}		
-			}
-			
-			if (any_rigged_face)
-			{
-				if (!drawablep->isState(LLDrawable::RIGGED))
-				{
-					drawablep->setState(LLDrawable::RIGGED);
+                            }
+                        }
+                    }
+                }
+                else
+                {   //face has no renderable geometry
+                    facep->clearVertexBuffer();
+                }
+            }
+
+            if (any_rigged_face)
+            {
+                if (!drawablep->isState(LLDrawable::RIGGED))
+                {
+                    drawablep->setState(LLDrawable::RIGGED);
                     LLDrawable* root = drawablep->getRoot();
                     if (root != drawablep)
                     {
                         root->setState(LLDrawable::RIGGED_CHILD);
                     }
 
-					//first time this is drawable is being marked as rigged,
-					// do another LoD update to use avatar bounding box
-					vobj->updateLOD();
-				}
-			}
-			else
-			{
-				drawablep->clearState(LLDrawable::RIGGED);
+                    //first time this is drawable is being marked as rigged,
+                    // do another LoD update to use avatar bounding box
+                    vobj->updateLOD();
+                }
+            }
+            else
+            {
+                drawablep->clearState(LLDrawable::RIGGED);
                 vobj->updateRiggedVolume(false);
-			}
-		}
-	}
-
-	//PROCESS NON-ALPHA FACES
-	U32 simple_mask = LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR;
-	U32 alpha_mask = simple_mask | 0x80000000; //hack to give alpha verts their own VBO
-	U32 bump_mask = LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR;
-	U32 fullbright_mask = LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR;
-
-	U32 norm_mask = simple_mask | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TANGENT;
-	U32 normspec_mask = norm_mask | LLVertexBuffer::MAP_TEXCOORD2;
-	U32 spec_mask = simple_mask | LLVertexBuffer::MAP_TEXCOORD2;
-
-	U32 pbr_mask = LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TANGENT;
-
-	if (emissive)
-	{ //emissive faces are present, include emissive byte to preserve batching
-		simple_mask = simple_mask | LLVertexBuffer::MAP_EMISSIVE;
-		alpha_mask = alpha_mask | LLVertexBuffer::MAP_EMISSIVE;
-		bump_mask = bump_mask | LLVertexBuffer::MAP_EMISSIVE;
-		fullbright_mask = fullbright_mask | LLVertexBuffer::MAP_EMISSIVE;
-		norm_mask = norm_mask | LLVertexBuffer::MAP_EMISSIVE;
-		normspec_mask = normspec_mask | LLVertexBuffer::MAP_EMISSIVE;
-		spec_mask = spec_mask | LLVertexBuffer::MAP_EMISSIVE;
+            }
+        }
+    }
+
+    //PROCESS NON-ALPHA FACES
+    U32 simple_mask = LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR;
+    U32 alpha_mask = simple_mask | 0x80000000; //hack to give alpha verts their own VBO
+    U32 bump_mask = LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR;
+    U32 fullbright_mask = LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR;
+
+    U32 norm_mask = simple_mask | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TANGENT;
+    U32 normspec_mask = norm_mask | LLVertexBuffer::MAP_TEXCOORD2;
+    U32 spec_mask = simple_mask | LLVertexBuffer::MAP_TEXCOORD2;
+
+    U32 pbr_mask = LLVertexBuffer::MAP_TEXCOORD0 | LLVertexBuffer::MAP_NORMAL | LLVertexBuffer::MAP_VERTEX | LLVertexBuffer::MAP_COLOR | LLVertexBuffer::MAP_TANGENT;
+
+    if (emissive)
+    { //emissive faces are present, include emissive byte to preserve batching
+        simple_mask = simple_mask | LLVertexBuffer::MAP_EMISSIVE;
+        alpha_mask = alpha_mask | LLVertexBuffer::MAP_EMISSIVE;
+        bump_mask = bump_mask | LLVertexBuffer::MAP_EMISSIVE;
+        fullbright_mask = fullbright_mask | LLVertexBuffer::MAP_EMISSIVE;
+        norm_mask = norm_mask | LLVertexBuffer::MAP_EMISSIVE;
+        normspec_mask = normspec_mask | LLVertexBuffer::MAP_EMISSIVE;
+        spec_mask = spec_mask | LLVertexBuffer::MAP_EMISSIVE;
         pbr_mask = pbr_mask | LLVertexBuffer::MAP_EMISSIVE;
-	}
+    }
 
-	BOOL batch_textures = LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 1;
+    BOOL batch_textures = LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_OBJECT) > 1;
 
     // add extra vertex data for deferred rendering (not necessarily for batching textures)
-	if (batch_textures)
-	{
-		bump_mask = bump_mask | LLVertexBuffer::MAP_TANGENT;
-		simple_mask = simple_mask | LLVertexBuffer::MAP_TEXTURE_INDEX;
-		alpha_mask = alpha_mask | LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2;
-		fullbright_mask = fullbright_mask | LLVertexBuffer::MAP_TEXTURE_INDEX;
-	}
+    if (batch_textures)
+    {
+        bump_mask = bump_mask | LLVertexBuffer::MAP_TANGENT;
+        simple_mask = simple_mask | LLVertexBuffer::MAP_TEXTURE_INDEX;
+        alpha_mask = alpha_mask | LLVertexBuffer::MAP_TEXTURE_INDEX | LLVertexBuffer::MAP_TANGENT | LLVertexBuffer::MAP_TEXCOORD1 | LLVertexBuffer::MAP_TEXCOORD2;
+        fullbright_mask = fullbright_mask | LLVertexBuffer::MAP_TEXTURE_INDEX;
+    }
 
-	group->mGeometryBytes = 0;
+    group->mGeometryBytes = 0;
 
-	U32 geometryBytes = 0;
+    U32 geometryBytes = 0;
 
     // generate render batches for static geometry
     U32 extra_mask = LLVertexBuffer::MAP_TEXTURE_INDEX;
@@ -6066,70 +6066,70 @@ void LLVolumeGeometryManager::rebuildGeom(LLSpatialGroup* group)
         rigged = TRUE;
     }
 
-	group->mGeometryBytes = geometryBytes;
+    group->mGeometryBytes = geometryBytes;
 
-	{
-		//drawables have been rebuilt, clear rebuild status
-		for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(), drawable_end = group->getDataEnd(); drawable_iter != drawable_end; ++drawable_iter)
-		{
-			LLDrawable* drawablep = (LLDrawable*)(*drawable_iter)->getDrawable();
-			if(drawablep)
-			{
+    {
+        //drawables have been rebuilt, clear rebuild status
+        for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(), drawable_end = group->getDataEnd(); drawable_iter != drawable_end; ++drawable_iter)
+        {
+            LLDrawable* drawablep = (LLDrawable*)(*drawable_iter)->getDrawable();
+            if(drawablep)
+            {
                 drawablep->clearState(LLDrawable::REBUILD_ALL);
             }
         }
-	}
+    }
 
-	group->mLastUpdateTime = gFrameTimeSeconds;
-	group->mBuilt = 1.f;
-	group->clearState(LLSpatialGroup::GEOM_DIRTY | LLSpatialGroup::ALPHA_DIRTY);
+    group->mLastUpdateTime = gFrameTimeSeconds;
+    group->mBuilt = 1.f;
+    group->clearState(LLSpatialGroup::GEOM_DIRTY | LLSpatialGroup::ALPHA_DIRTY);
 }
 
 void LLVolumeGeometryManager::rebuildMesh(LLSpatialGroup* group)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
-	llassert(group);
-	if (group && group->hasState(LLSpatialGroup::MESH_DIRTY) && !group->hasState(LLSpatialGroup::GEOM_DIRTY))
-	{
-		{
+    llassert(group);
+    if (group && group->hasState(LLSpatialGroup::MESH_DIRTY) && !group->hasState(LLSpatialGroup::GEOM_DIRTY))
+    {
+        {
             LL_PROFILE_ZONE_NAMED("rebuildMesh - gen draw info");
 
             group->mBuilt = 1.f;
-		
-			const U32 MAX_BUFFER_COUNT = 4096;
-			LLVertexBuffer* locked_buffer[MAX_BUFFER_COUNT];
 
-			U32 buffer_count = 0;
+            const U32 MAX_BUFFER_COUNT = 4096;
+            LLVertexBuffer* locked_buffer[MAX_BUFFER_COUNT];
+
+            U32 buffer_count = 0;
 
             for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(); drawable_iter != group->getDataEnd(); ++drawable_iter)
-			{
-				LLDrawable* drawablep = (LLDrawable*)(*drawable_iter)->getDrawable();
-
-				if (drawablep && !drawablep->isDead() && drawablep->isState(LLDrawable::REBUILD_ALL))
-				{
-					LLVOVolume* vobj = drawablep->getVOVolume();
-					
-					if (!vobj) continue;
-
-					if (vobj->isNoLOD()) continue;
-
-					vobj->preRebuild();
-
-					if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
-					{
-						vobj->updateRelativeXform(true);
-					}
-
-					LLVolume* volume = vobj->getVolume();
-					if (!volume) continue;
-					for (S32 i = 0, i_end = drawablep->getNumFaces(); i < i_end; ++i)
-					{
-						LLFace* face = drawablep->getFace(i);
-						if (face)
-						{
-							LLVertexBuffer* buff = face->getVertexBuffer();
-							if (buff)
-							{
+            {
+                LLDrawable* drawablep = (LLDrawable*)(*drawable_iter)->getDrawable();
+
+                if (drawablep && !drawablep->isDead() && drawablep->isState(LLDrawable::REBUILD_ALL))
+                {
+                    LLVOVolume* vobj = drawablep->getVOVolume();
+
+                    if (!vobj) continue;
+
+                    if (vobj->isNoLOD()) continue;
+
+                    vobj->preRebuild();
+
+                    if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
+                    {
+                        vobj->updateRelativeXform(true);
+                    }
+
+                    LLVolume* volume = vobj->getVolume();
+                    if (!volume) continue;
+                    for (S32 i = 0, i_end = drawablep->getNumFaces(); i < i_end; ++i)
+                    {
+                        LLFace* face = drawablep->getFace(i);
+                        if (face)
+                        {
+                            LLVertexBuffer* buff = face->getVertexBuffer();
+                            if (buff)
+                            {
                                 if (!face->getGeometryVolume(*volume, // volume
                                     face->getTEOffset(),              // face_index
                                     vobj->getRelativeXform(),         // mat_vert_in
@@ -6144,72 +6144,72 @@ void LLVolumeGeometryManager::rebuildMesh(LLSpatialGroup* group)
                                 }
 
                                 buff->unmapBuffer();
-							}
-						}
-					}
+                            }
+                        }
+                    }
 
-					if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
-					{
-						vobj->updateRelativeXform();
-					}
+                    if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
+                    {
+                        vobj->updateRelativeXform();
+                    }
 
-					drawablep->clearState(LLDrawable::REBUILD_ALL);
-				}
-			}
+                    drawablep->clearState(LLDrawable::REBUILD_ALL);
+                }
+            }
 
-			{
+            {
                 LL_PROFILE_ZONE_NAMED("rebuildMesh - flush");
-				for (LLVertexBuffer** iter = locked_buffer, ** end_iter = locked_buffer+buffer_count; iter != end_iter; ++iter)
-				{
-					(*iter)->unmapBuffer();
-				}
-
-				// don't forget alpha
-				if(group != NULL &&
-				   !group->mVertexBuffer.isNull())
-				{
-					group->mVertexBuffer->unmapBuffer();
-				}
-			}
-			
-			group->clearState(LLSpatialGroup::MESH_DIRTY | LLSpatialGroup::NEW_DRAWINFO);
-		}
-	} 
+                for (LLVertexBuffer** iter = locked_buffer, ** end_iter = locked_buffer+buffer_count; iter != end_iter; ++iter)
+                {
+                    (*iter)->unmapBuffer();
+                }
+
+                // don't forget alpha
+                if(group != NULL &&
+                   !group->mVertexBuffer.isNull())
+                {
+                    group->mVertexBuffer->unmapBuffer();
+                }
+            }
+
+            group->clearState(LLSpatialGroup::MESH_DIRTY | LLSpatialGroup::NEW_DRAWINFO);
+        }
+    }
 }
 
 struct CompareBatchBreaker
 {
-	bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
-	{
-		const LLTextureEntry* lte = lhs->getTextureEntry();
-		const LLTextureEntry* rte = rhs->getTextureEntry();
+    bool operator()(const LLFace* const& lhs, const LLFace* const& rhs)
+    {
+        const LLTextureEntry* lte = lhs->getTextureEntry();
+        const LLTextureEntry* rte = rhs->getTextureEntry();
 
         if (lte->getBumpmap() != rte->getBumpmap())
-		{
-			return lte->getBumpmap() < rte->getBumpmap();
-		}
-		else if (lte->getFullbright() != rte->getFullbright())
-		{
-			return lte->getFullbright() < rte->getFullbright();
-		}
+        {
+            return lte->getBumpmap() < rte->getBumpmap();
+        }
+        else if (lte->getFullbright() != rte->getFullbright())
+        {
+            return lte->getFullbright() < rte->getFullbright();
+        }
         else if (lte->getMaterialID() != rte->getMaterialID())
         {
             return lte->getMaterialID() < rte->getMaterialID();
         }
-		else if (lte->getShiny() != rte->getShiny())
-		{
-			return lte->getShiny() < rte->getShiny();
-		}
+        else if (lte->getShiny() != rte->getShiny())
+        {
+            return lte->getShiny() < rte->getShiny();
+        }
         else if (lhs->getTexture() != rhs->getTexture())
-		{
-			return lhs->getTexture() < rhs->getTexture();
-		}
-        else 
+        {
+            return lhs->getTexture() < rhs->getTexture();
+        }
+        else
         {
             // all else being equal, maintain consistent draw order
             return lhs->getDrawOrderIndex() < rhs->getDrawOrderIndex();
         }
-	}
+    }
 };
 
 struct CompareBatchBreakerRigged
@@ -6237,16 +6237,16 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
 
-	U32 geometryBytes = 0;
-	
-	//calculate maximum number of vertices to store in a single buffer
-	static LLCachedControl<S32> max_vbo_size(gSavedSettings, "RenderMaxVBOSize", 512);
-	U32 max_vertices = (max_vbo_size * 1024)/LLVertexBuffer::calcVertexSize(group->getSpatialPartition()->mVertexDataMask);
-	max_vertices = llmin(max_vertices, (U32) 65535);
+    U32 geometryBytes = 0;
 
-	{
+    //calculate maximum number of vertices to store in a single buffer
+    static LLCachedControl<S32> max_vbo_size(gSavedSettings, "RenderMaxVBOSize", 512);
+    U32 max_vertices = (max_vbo_size * 1024)/LLVertexBuffer::calcVertexSize(group->getSpatialPartition()->mVertexDataMask);
+    max_vertices = llmin(max_vertices, (U32) 65535);
+
+    {
         LL_PROFILE_ZONE_NAMED("genDrawInfo - sort");
-        
+
         if (rigged)
         {
             if (!distance_sort) // <--- alpha "sort" rigged faces by maintaining original draw order
@@ -6260,277 +6260,277 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace
             //sort faces by things that break batches, not including avatar and mesh id
             std::sort(faces, faces + face_count, CompareBatchBreaker());
         }
-		else
-		{
-			//sort faces by distance
-			std::sort(faces, faces+face_count, LLFace::CompareDistanceGreater());
-		}
-	}
-				
-	bool hud_group = group->isHUDGroup() ;
-	LLFace** face_iter = faces;
-	LLFace** end_faces = faces+face_count;
-	
-	LLSpatialGroup::buffer_map_t buffer_map;
-
-	LLViewerTexture* last_tex = NULL;
-
-	S32 texture_index_channels = LLGLSLShader::sIndexedTextureChannels;
-
-	bool flexi = false;
-
-	while (face_iter != end_faces)
-	{
-		//pull off next face
-		LLFace* facep = *face_iter;
-		LLViewerTexture* tex = facep->getTexture();
+        else
+        {
+            //sort faces by distance
+            std::sort(faces, faces+face_count, LLFace::CompareDistanceGreater());
+        }
+    }
+
+    bool hud_group = group->isHUDGroup() ;
+    LLFace** face_iter = faces;
+    LLFace** end_faces = faces+face_count;
+
+    LLSpatialGroup::buffer_map_t buffer_map;
+
+    LLViewerTexture* last_tex = NULL;
+
+    S32 texture_index_channels = LLGLSLShader::sIndexedTextureChannels;
+
+    bool flexi = false;
+
+    while (face_iter != end_faces)
+    {
+        //pull off next face
+        LLFace* facep = *face_iter;
+        LLViewerTexture* tex = facep->getTexture();
         const LLTextureEntry* te = facep->getTextureEntry();
-		LLMaterialPtr mat = te->getMaterialParams();
+        LLMaterialPtr mat = te->getMaterialParams();
         LLMaterialID matId = te->getMaterialID();
 
-		if (distance_sort)
-		{
-			tex = NULL;
-		}
+        if (distance_sort)
+        {
+            tex = NULL;
+        }
+
+        if (last_tex != tex)
+        {
+            last_tex = tex;
+        }
+
+        bool bake_sunlight = LLPipeline::sBakeSunlight && facep->getDrawable()->isStatic();
 
-		if (last_tex != tex)
-		{
-			last_tex = tex;
-		}
+        U32 index_count = facep->getIndicesCount();
+        U32 geom_count = facep->getGeomCount();
 
-		bool bake_sunlight = LLPipeline::sBakeSunlight && facep->getDrawable()->isStatic(); 
+        flexi = flexi || facep->getViewerObject()->getVolume()->isUnique();
 
-		U32 index_count = facep->getIndicesCount();
-		U32 geom_count = facep->getGeomCount();
+        //sum up vertices needed for this render batch
+        LLFace** i = face_iter;
+        ++i;
 
-		flexi = flexi || facep->getViewerObject()->getVolume()->isUnique();
+        const U32 MAX_TEXTURE_COUNT = 32;
+        LLViewerTexture* texture_list[MAX_TEXTURE_COUNT];
 
-		//sum up vertices needed for this render batch
-		LLFace** i = face_iter;
-		++i;
-		
-		const U32 MAX_TEXTURE_COUNT = 32;
-		LLViewerTexture* texture_list[MAX_TEXTURE_COUNT];
-		
-		U32 texture_count = 0;
+        U32 texture_count = 0;
 
-		{
+        {
             LL_PROFILE_ZONE_NAMED("genDrawInfo - face size");
-			if (batch_textures)
-			{
-				U8 cur_tex = 0;
-				facep->setTextureIndex(cur_tex);
-				if (texture_count < MAX_TEXTURE_COUNT)
-				{
-					texture_list[texture_count++] = tex;
-				}
-
-				if (can_batch_texture(facep))
-				{ //populate texture_list with any textures that can be batched
-				  //move i to the next unbatchable face
-					while (i != end_faces)
-					{
-						facep = *i;
-						
-						if (!can_batch_texture(facep))
-						{ //face is bump mapped or has an animated texture matrix -- can't 
-							//batch more than 1 texture at a time
-							facep->setTextureIndex(0);
-							break;
-						}
-
-						if (facep->getTexture() != tex)
-						{
-							if (distance_sort)
-							{ //textures might be out of order, see if texture exists in current batch
-								bool found = false;
-								for (U32 tex_idx = 0; tex_idx < texture_count; ++tex_idx)
-								{
-									if (facep->getTexture() == texture_list[tex_idx])
-									{
-										cur_tex = tex_idx;
-										found = true;
-										break;
-									}
-								}
-
-								if (!found)
-								{
-									cur_tex = texture_count;
-								}
-							}
-							else
-							{
-								cur_tex++;
-							}
-
-							if (cur_tex >= texture_index_channels)
-							{ //cut batches when index channels are depleted
-								break;
-							}
-
-							tex = facep->getTexture();
-
-							if (texture_count < MAX_TEXTURE_COUNT)
-							{
-								texture_list[texture_count++] = tex;
-							}
-						}
-
-						if (geom_count + facep->getGeomCount() > max_vertices)
-						{ //cut batches on geom count too big
-							break;
-						}
-
-						++i;
-
-						flexi = flexi || facep->getViewerObject()->getVolume()->isUnique();
-
-						index_count += facep->getIndicesCount();
-						geom_count += facep->getGeomCount();
-
-						facep->setTextureIndex(cur_tex);
-					}
-				}
-				else
-				{
-					facep->setTextureIndex(0);
-				}
-
-				tex = texture_list[0];
-			}
-			else
-			{
-				while (i != end_faces && 
-					(LLPipeline::sTextureBindTest || 
-						(distance_sort || 
-							((*i)->getTexture() == tex))))
-				{
-					facep = *i;
+            if (batch_textures)
+            {
+                U8 cur_tex = 0;
+                facep->setTextureIndex(cur_tex);
+                if (texture_count < MAX_TEXTURE_COUNT)
+                {
+                    texture_list[texture_count++] = tex;
+                }
+
+                if (can_batch_texture(facep))
+                { //populate texture_list with any textures that can be batched
+                  //move i to the next unbatchable face
+                    while (i != end_faces)
+                    {
+                        facep = *i;
+
+                        if (!can_batch_texture(facep))
+                        { //face is bump mapped or has an animated texture matrix -- can't
+                            //batch more than 1 texture at a time
+                            facep->setTextureIndex(0);
+                            break;
+                        }
+
+                        if (facep->getTexture() != tex)
+                        {
+                            if (distance_sort)
+                            { //textures might be out of order, see if texture exists in current batch
+                                bool found = false;
+                                for (U32 tex_idx = 0; tex_idx < texture_count; ++tex_idx)
+                                {
+                                    if (facep->getTexture() == texture_list[tex_idx])
+                                    {
+                                        cur_tex = tex_idx;
+                                        found = true;
+                                        break;
+                                    }
+                                }
+
+                                if (!found)
+                                {
+                                    cur_tex = texture_count;
+                                }
+                            }
+                            else
+                            {
+                                cur_tex++;
+                            }
+
+                            if (cur_tex >= texture_index_channels)
+                            { //cut batches when index channels are depleted
+                                break;
+                            }
+
+                            tex = facep->getTexture();
+
+                            if (texture_count < MAX_TEXTURE_COUNT)
+                            {
+                                texture_list[texture_count++] = tex;
+                            }
+                        }
+
+                        if (geom_count + facep->getGeomCount() > max_vertices)
+                        { //cut batches on geom count too big
+                            break;
+                        }
+
+                        ++i;
+
+                        flexi = flexi || facep->getViewerObject()->getVolume()->isUnique();
+
+                        index_count += facep->getIndicesCount();
+                        geom_count += facep->getGeomCount();
+
+                        facep->setTextureIndex(cur_tex);
+                    }
+                }
+                else
+                {
+                    facep->setTextureIndex(0);
+                }
+
+                tex = texture_list[0];
+            }
+            else
+            {
+                while (i != end_faces &&
+                    (LLPipeline::sTextureBindTest ||
+                        (distance_sort ||
+                            ((*i)->getTexture() == tex))))
+                {
+                    facep = *i;
                     const LLTextureEntry* nextTe = facep->getTextureEntry();
                     if (nextTe->getMaterialID() != matId)
                     {
                         break;
                     }
 
-					//face has no texture index
-					facep->mDrawInfo = NULL;
-					facep->setTextureIndex(FACE_DO_NOT_BATCH_TEXTURES);
+                    //face has no texture index
+                    facep->mDrawInfo = NULL;
+                    facep->setTextureIndex(FACE_DO_NOT_BATCH_TEXTURES);
 
-					if (geom_count + facep->getGeomCount() > max_vertices)
-					{ //cut batches on geom count too big
-						break;
-					}
+                    if (geom_count + facep->getGeomCount() > max_vertices)
+                    { //cut batches on geom count too big
+                        break;
+                    }
 
-					++i;
-					index_count += facep->getIndicesCount();
-					geom_count += facep->getGeomCount();
+                    ++i;
+                    index_count += facep->getIndicesCount();
+                    geom_count += facep->getGeomCount();
 
-					flexi = flexi || facep->getViewerObject()->getVolume()->isUnique();
-				}
-			}
-		}
+                    flexi = flexi || facep->getViewerObject()->getVolume()->isUnique();
+                }
+            }
+        }
 
-		//create vertex buffer
-		LLPointer<LLVertexBuffer> buffer;
+        //create vertex buffer
+        LLPointer<LLVertexBuffer> buffer;
 
-		{
+        {
             LL_PROFILE_ZONE_NAMED("genDrawInfo - allocate");
-			buffer = new LLVertexBuffer(mask);
-			if(!buffer->allocateBuffer(geom_count, index_count))
-			{
-				LL_WARNS() << "Failed to allocate group Vertex Buffer to "
-					<< geom_count << " vertices and "
-					<< index_count << " indices" << LL_ENDL;
-				buffer = NULL;
-			}
-		}
-
-		if (buffer)
-		{
-			geometryBytes += buffer->getSize() + buffer->getIndicesSize();
-			buffer_map[mask][*face_iter].push_back(buffer);
-		}
-
-		//add face geometry
-
-		U32 indices_index = 0;
-		U16 index_offset = 0;
+            buffer = new LLVertexBuffer(mask);
+            if(!buffer->allocateBuffer(geom_count, index_count))
+            {
+                LL_WARNS() << "Failed to allocate group Vertex Buffer to "
+                    << geom_count << " vertices and "
+                    << index_count << " indices" << LL_ENDL;
+                buffer = NULL;
+            }
+        }
+
+        if (buffer)
+        {
+            geometryBytes += buffer->getSize() + buffer->getIndicesSize();
+            buffer_map[mask][*face_iter].push_back(buffer);
+        }
+
+        //add face geometry
+
+        U32 indices_index = 0;
+        U16 index_offset = 0;
 
         while (face_iter < i)
-		{
-			//update face indices for new buffer
-			facep = *face_iter;
-
-			if (buffer.isNull())
-			{
-				// Bulk allocation failed
-				facep->setVertexBuffer(buffer);
-				facep->setSize(0, 0); // mark as no geometry
-				++face_iter;
-				continue;
-			}
-			facep->setIndicesIndex(indices_index);
-			facep->setGeomIndex(index_offset);
-			facep->setVertexBuffer(buffer);	
-			
-			if (batch_textures && facep->getTextureIndex() == FACE_DO_NOT_BATCH_TEXTURES)
-			{
-				LL_ERRS() << "Invalid texture index." << LL_ENDL;
-			}
-			
-			{
-				//for debugging, set last time face was updated vs moved
-				facep->updateRebuildFlags();
-
-				{ //copy face geometry into vertex buffer
-					LLDrawable* drawablep = facep->getDrawable();
-					LLVOVolume* vobj = drawablep->getVOVolume();
-					LLVolume* volume = vobj->getVolume();
-
-					if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
-					{
-						vobj->updateRelativeXform(true);
-					}
-
-					U32 te_idx = facep->getTEOffset();
-
-					if (!facep->getGeometryVolume(*volume, te_idx, 
-						vobj->getRelativeXform(), vobj->getRelativeXformInvTrans(), index_offset,true))
-					{
-						LL_WARNS() << "Failed to get geometry for face!" << LL_ENDL;
-					}
-
-					if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
-					{
-						vobj->updateRelativeXform(false);
-					}
-				}
-			}
-
-			index_offset += facep->getGeomCount();
-			indices_index += facep->getIndicesCount();
-
-			//append face to appropriate render batch
-
-			BOOL force_simple = facep->getPixelArea() < FORCE_SIMPLE_RENDER_AREA;
-			BOOL fullbright = facep->isState(LLFace::FULLBRIGHT);
-			if ((mask & LLVertexBuffer::MAP_NORMAL) == 0)
-			{ //paranoia check to make sure GL doesn't try to read non-existant normals
-				fullbright = TRUE;
-			}
+        {
+            //update face indices for new buffer
+            facep = *face_iter;
+
+            if (buffer.isNull())
+            {
+                // Bulk allocation failed
+                facep->setVertexBuffer(buffer);
+                facep->setSize(0, 0); // mark as no geometry
+                ++face_iter;
+                continue;
+            }
+            facep->setIndicesIndex(indices_index);
+            facep->setGeomIndex(index_offset);
+            facep->setVertexBuffer(buffer);
+
+            if (batch_textures && facep->getTextureIndex() == FACE_DO_NOT_BATCH_TEXTURES)
+            {
+                LL_ERRS() << "Invalid texture index." << LL_ENDL;
+            }
+
+            {
+                //for debugging, set last time face was updated vs moved
+                facep->updateRebuildFlags();
+
+                { //copy face geometry into vertex buffer
+                    LLDrawable* drawablep = facep->getDrawable();
+                    LLVOVolume* vobj = drawablep->getVOVolume();
+                    LLVolume* volume = vobj->getVolume();
+
+                    if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
+                    {
+                        vobj->updateRelativeXform(true);
+                    }
+
+                    U32 te_idx = facep->getTEOffset();
+
+                    if (!facep->getGeometryVolume(*volume, te_idx,
+                        vobj->getRelativeXform(), vobj->getRelativeXformInvTrans(), index_offset,true))
+                    {
+                        LL_WARNS() << "Failed to get geometry for face!" << LL_ENDL;
+                    }
+
+                    if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
+                    {
+                        vobj->updateRelativeXform(false);
+                    }
+                }
+            }
+
+            index_offset += facep->getGeomCount();
+            indices_index += facep->getIndicesCount();
+
+            //append face to appropriate render batch
+
+            BOOL force_simple = facep->getPixelArea() < FORCE_SIMPLE_RENDER_AREA;
+            BOOL fullbright = facep->isState(LLFace::FULLBRIGHT);
+            if ((mask & LLVertexBuffer::MAP_NORMAL) == 0)
+            { //paranoia check to make sure GL doesn't try to read non-existant normals
+                fullbright = TRUE;
+            }
 
             const LLTextureEntry* te = facep->getTextureEntry();
             LLGLTFMaterial* gltf_mat = te->getGLTFRenderMaterial();
 
-			if (hud_group && gltf_mat == nullptr)
-			{ //all hud attachments are fullbright
-				fullbright = TRUE;
-			}
-			
-			tex = facep->getTexture();
+            if (hud_group && gltf_mat == nullptr)
+            { //all hud attachments are fullbright
+                fullbright = TRUE;
+            }
+
+            tex = facep->getTexture();
 
-			BOOL is_alpha = (facep->getPoolType() == LLDrawPool::POOL_ALPHA) ? TRUE : FALSE;
+            BOOL is_alpha = (facep->getPoolType() == LLDrawPool::POOL_ALPHA) ? TRUE : FALSE;
 
             LLMaterial* mat = nullptr;
             bool can_be_shiny = false;
@@ -6550,8 +6550,8 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace
             }
 
             F32 blinn_phong_alpha = te->getColor().mV[3];
-			bool use_legacy_bump = te->getBumpmap() && (te->getBumpmap() < 18) && (!mat || mat->getNormalID().isNull());
-			bool blinn_phong_opaque = blinn_phong_alpha >= 0.999f;
+            bool use_legacy_bump = te->getBumpmap() && (te->getBumpmap() < 18) && (!mat || mat->getNormalID().isNull());
+            bool blinn_phong_opaque = blinn_phong_alpha >= 0.999f;
             bool blinn_phong_transparent = blinn_phong_alpha < 0.999f;
 
             if (!gltf_mat)
@@ -6559,9 +6559,9 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace
                 is_alpha = (is_alpha || blinn_phong_transparent) ? TRUE : FALSE;
             }
 
-			if (gltf_mat || (mat && !hud_group))
-			{
-				bool material_pass = false;
+            if (gltf_mat || (mat && !hud_group))
+            {
+                bool material_pass = false;
 
                 if (gltf_mat)
                 { // all other parameters ignored if gltf material is present
@@ -6579,82 +6579,82 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace
                     }
                 }
                 else
-				// do NOT use 'fullbright' for this logic or you risk sending
-				// things without normals down the materials pipeline and will
-				// render poorly if not crash NORSPEC-240,314
-				//
-				if (te->getFullbright())
-				{
-					if (mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
-					{
-						if (blinn_phong_opaque)
-						{
-							registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
-						}
-						else
-						{
-							registerFace(group, facep, LLRenderPass::PASS_ALPHA);
-						}
-					}
-					else if (is_alpha)
-					{
-						registerFace(group, facep, LLRenderPass::PASS_ALPHA);
-					}
-					else
-					{
-						if (mat->getEnvironmentIntensity() > 0 || te->getShiny() > 0)
-						{
-							material_pass = true;
-						}
-						else
-						{
+                // do NOT use 'fullbright' for this logic or you risk sending
+                // things without normals down the materials pipeline and will
+                // render poorly if not crash NORSPEC-240,314
+                //
+                if (te->getFullbright())
+                {
+                    if (mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
+                    {
+                        if (blinn_phong_opaque)
+                        {
+                            registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
+                        }
+                        else
+                        {
+                            registerFace(group, facep, LLRenderPass::PASS_ALPHA);
+                        }
+                    }
+                    else if (is_alpha)
+                    {
+                        registerFace(group, facep, LLRenderPass::PASS_ALPHA);
+                    }
+                    else
+                    {
+                        if (mat->getEnvironmentIntensity() > 0 || te->getShiny() > 0)
+                        {
+                            material_pass = true;
+                        }
+                        else
+                        {
                             if (blinn_phong_opaque)
-						    {
-							    registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT);
+                            {
+                                registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT);
                             }
                             else
                             {
                                 registerFace(group, facep, LLRenderPass::PASS_ALPHA);
                             }
-						}
-					}
-				}
-				else if (blinn_phong_transparent)
-				{
-					registerFace(group, facep, LLRenderPass::PASS_ALPHA);
-				}
-				else if (use_legacy_bump)
-				{
+                        }
+                    }
+                }
+                else if (blinn_phong_transparent)
+                {
+                    registerFace(group, facep, LLRenderPass::PASS_ALPHA);
+                }
+                else if (use_legacy_bump)
+                {
                     llassert(mask & LLVertexBuffer::MAP_TANGENT);
-					// we have a material AND legacy bump settings, but no normal map
-					registerFace(group, facep, LLRenderPass::PASS_BUMP);
-				}
-				else
-				{
-					material_pass = true;
-				}
-
-				if (material_pass)
-				{
-					static const U32 pass[] = 
-					{
-						LLRenderPass::PASS_MATERIAL,
-						LLRenderPass::PASS_ALPHA, //LLRenderPass::PASS_MATERIAL_ALPHA,
-						LLRenderPass::PASS_MATERIAL_ALPHA_MASK,
-						LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE,
-						LLRenderPass::PASS_SPECMAP,
-						LLRenderPass::PASS_ALPHA, //LLRenderPass::PASS_SPECMAP_BLEND,
-						LLRenderPass::PASS_SPECMAP_MASK,
-						LLRenderPass::PASS_SPECMAP_EMISSIVE,
-						LLRenderPass::PASS_NORMMAP,
-						LLRenderPass::PASS_ALPHA, //LLRenderPass::PASS_NORMMAP_BLEND,
-						LLRenderPass::PASS_NORMMAP_MASK,
-						LLRenderPass::PASS_NORMMAP_EMISSIVE,
-						LLRenderPass::PASS_NORMSPEC,
-						LLRenderPass::PASS_ALPHA, //LLRenderPass::PASS_NORMSPEC_BLEND,
-						LLRenderPass::PASS_NORMSPEC_MASK,
-						LLRenderPass::PASS_NORMSPEC_EMISSIVE,
-					};
+                    // we have a material AND legacy bump settings, but no normal map
+                    registerFace(group, facep, LLRenderPass::PASS_BUMP);
+                }
+                else
+                {
+                    material_pass = true;
+                }
+
+                if (material_pass)
+                {
+                    static const U32 pass[] =
+                    {
+                        LLRenderPass::PASS_MATERIAL,
+                        LLRenderPass::PASS_ALPHA, //LLRenderPass::PASS_MATERIAL_ALPHA,
+                        LLRenderPass::PASS_MATERIAL_ALPHA_MASK,
+                        LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE,
+                        LLRenderPass::PASS_SPECMAP,
+                        LLRenderPass::PASS_ALPHA, //LLRenderPass::PASS_SPECMAP_BLEND,
+                        LLRenderPass::PASS_SPECMAP_MASK,
+                        LLRenderPass::PASS_SPECMAP_EMISSIVE,
+                        LLRenderPass::PASS_NORMMAP,
+                        LLRenderPass::PASS_ALPHA, //LLRenderPass::PASS_NORMMAP_BLEND,
+                        LLRenderPass::PASS_NORMMAP_MASK,
+                        LLRenderPass::PASS_NORMMAP_EMISSIVE,
+                        LLRenderPass::PASS_NORMSPEC,
+                        LLRenderPass::PASS_ALPHA, //LLRenderPass::PASS_NORMSPEC_BLEND,
+                        LLRenderPass::PASS_NORMSPEC_MASK,
+                        LLRenderPass::PASS_NORMSPEC_EMISSIVE,
+                    };
 
                     U32 alpha_mode = mat->getDiffuseAlphaMode();
                     if (!distance_sort && alpha_mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND)
@@ -6665,180 +6665,180 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace
 
                     U32 vb_mask = facep->getVertexBuffer()->getTypeMask();
 
-                    // HACK - this should also never happen, but sometimes we get here and the material thinks it has a specmap now 
+                    // HACK - this should also never happen, but sometimes we get here and the material thinks it has a specmap now
                     // even though it didn't appear to have a specmap when the face was added to the list of faces
                     if ((mask & 0x4) && !(vb_mask & LLVertexBuffer::MAP_TEXCOORD2))
                     {
                         mask &= ~0x4;
                     }
 
-					llassert(mask < sizeof(pass)/sizeof(U32));
+                    llassert(mask < sizeof(pass)/sizeof(U32));
 
-					mask = llmin(mask, (U32)(sizeof(pass)/sizeof(U32)-1));
+                    mask = llmin(mask, (U32)(sizeof(pass)/sizeof(U32)-1));
 
                     // if this is going into alpha pool, distance sort MUST be true
                     llassert(pass[mask] == LLRenderPass::PASS_ALPHA ? distance_sort : true);
-					registerFace(group, facep, pass[mask]);
-				}
-			}
-			else if (mat)
-			{
-				U8 mode = mat->getDiffuseAlphaMode();
+                    registerFace(group, facep, pass[mask]);
+                }
+            }
+            else if (mat)
+            {
+                U8 mode = mat->getDiffuseAlphaMode();
 
                 is_alpha = (is_alpha || (mode == LLMaterial::DIFFUSE_ALPHA_MODE_BLEND));
 
-				if (is_alpha)
-				{
-					mode = LLMaterial::DIFFUSE_ALPHA_MODE_BLEND;
-				}
-
-				if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
-				{
-					registerFace(group, facep, fullbright ? LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK : LLRenderPass::PASS_ALPHA_MASK);
-				}
-				else if (is_alpha )
-				{
-					registerFace(group, facep, LLRenderPass::PASS_ALPHA);
-				}
-				else if (gPipeline.shadersLoaded()
-					&& te->getShiny() 
-					&& can_be_shiny)
-				{
-					registerFace(group, facep, fullbright ? LLRenderPass::PASS_FULLBRIGHT_SHINY : LLRenderPass::PASS_SHINY);
-				}
-				else
-				{
-					registerFace(group, facep, fullbright ? LLRenderPass::PASS_FULLBRIGHT : LLRenderPass::PASS_SIMPLE);
-				}
-			}
-			else if (is_alpha)
-			{
-				// can we safely treat this as an alpha mask?
-				if (facep->getFaceColor().mV[3] <= 0.f)
-				{ //100% transparent, don't render unless we're highlighting transparent
-					registerFace(group, facep, LLRenderPass::PASS_ALPHA_INVISIBLE);
-				}
-				else if (facep->canRenderAsMask() && !hud_group)
-				{
-					if (te->getFullbright() || LLPipeline::sNoAlpha)
-					{
-						registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
-					}
-					else
-					{
-						registerFace(group, facep, LLRenderPass::PASS_ALPHA_MASK);
-					}
-				}
-				else
-				{
-					registerFace(group, facep, LLRenderPass::PASS_ALPHA);
-				}
-			}
-			else if (gPipeline.shadersLoaded()
-				&& te->getShiny() 
-				&& can_be_shiny)
-			{ //shiny
-				if (tex->getPrimaryFormat() == GL_ALPHA)
-				{ //invisiprim+shiny
-					registerFace(group, facep, LLRenderPass::PASS_INVISI_SHINY);
-					registerFace(group, facep, LLRenderPass::PASS_INVISIBLE);
-				}
-				else if (!hud_group)
-				{ //deferred rendering
-					if (te->getFullbright())
-					{ //register in post deferred fullbright shiny pass
-						registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_SHINY);
-						if (te->getBumpmap())
-						{ //register in post deferred bump pass
-							registerFace(group, facep, LLRenderPass::PASS_POST_BUMP);
-						}
-					}
-					else if (use_legacy_bump)
-					{ //register in deferred bump pass
+                if (is_alpha)
+                {
+                    mode = LLMaterial::DIFFUSE_ALPHA_MODE_BLEND;
+                }
+
+                if (mode == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
+                {
+                    registerFace(group, facep, fullbright ? LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK : LLRenderPass::PASS_ALPHA_MASK);
+                }
+                else if (is_alpha )
+                {
+                    registerFace(group, facep, LLRenderPass::PASS_ALPHA);
+                }
+                else if (gPipeline.shadersLoaded()
+                    && te->getShiny()
+                    && can_be_shiny)
+                {
+                    registerFace(group, facep, fullbright ? LLRenderPass::PASS_FULLBRIGHT_SHINY : LLRenderPass::PASS_SHINY);
+                }
+                else
+                {
+                    registerFace(group, facep, fullbright ? LLRenderPass::PASS_FULLBRIGHT : LLRenderPass::PASS_SIMPLE);
+                }
+            }
+            else if (is_alpha)
+            {
+                // can we safely treat this as an alpha mask?
+                if (facep->getFaceColor().mV[3] <= 0.f)
+                { //100% transparent, don't render unless we're highlighting transparent
+                    registerFace(group, facep, LLRenderPass::PASS_ALPHA_INVISIBLE);
+                }
+                else if (facep->canRenderAsMask() && !hud_group)
+                {
+                    if (te->getFullbright() || LLPipeline::sNoAlpha)
+                    {
+                        registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
+                    }
+                    else
+                    {
+                        registerFace(group, facep, LLRenderPass::PASS_ALPHA_MASK);
+                    }
+                }
+                else
+                {
+                    registerFace(group, facep, LLRenderPass::PASS_ALPHA);
+                }
+            }
+            else if (gPipeline.shadersLoaded()
+                && te->getShiny()
+                && can_be_shiny)
+            { //shiny
+                if (tex->getPrimaryFormat() == GL_ALPHA)
+                { //invisiprim+shiny
+                    registerFace(group, facep, LLRenderPass::PASS_INVISI_SHINY);
+                    registerFace(group, facep, LLRenderPass::PASS_INVISIBLE);
+                }
+                else if (!hud_group)
+                { //deferred rendering
+                    if (te->getFullbright())
+                    { //register in post deferred fullbright shiny pass
+                        registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_SHINY);
+                        if (te->getBumpmap())
+                        { //register in post deferred bump pass
+                            registerFace(group, facep, LLRenderPass::PASS_POST_BUMP);
+                        }
+                    }
+                    else if (use_legacy_bump)
+                    { //register in deferred bump pass
                         llassert(mask& LLVertexBuffer::MAP_TANGENT);
-						registerFace(group, facep, LLRenderPass::PASS_BUMP);
-					}
-					else
-					{ //register in deferred simple pass (deferred simple includes shiny)
-						llassert(mask & LLVertexBuffer::MAP_NORMAL);
-						registerFace(group, facep, LLRenderPass::PASS_SIMPLE);
-					}
-				}
-				else if (fullbright)
-				{	//not deferred, register in standard fullbright shiny pass					
-					registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_SHINY);
-				}
-				else
-				{ //not deferred or fullbright, register in standard shiny pass
-					registerFace(group, facep, LLRenderPass::PASS_SHINY);
-				}
-			}
-			else
-			{ //not alpha and not shiny
-				if (!is_alpha && tex->getPrimaryFormat() == GL_ALPHA)
-				{ //invisiprim
-					registerFace(group, facep, LLRenderPass::PASS_INVISIBLE);
-				}
-				else if (fullbright || bake_sunlight)
-				{ //fullbright
-					if (mat && mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
-					{
-						registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
-					}
-					else
-					{
-						registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT);
-					}
-					if (!hud_group && use_legacy_bump)
-					{ //if this is the deferred render and a bump map is present, register in post deferred bump
-						registerFace(group, facep, LLRenderPass::PASS_POST_BUMP);
-					}
-				}
-				else
-				{
-					if (use_legacy_bump)
-					{ //non-shiny or fullbright deferred bump
+                        registerFace(group, facep, LLRenderPass::PASS_BUMP);
+                    }
+                    else
+                    { //register in deferred simple pass (deferred simple includes shiny)
+                        llassert(mask & LLVertexBuffer::MAP_NORMAL);
+                        registerFace(group, facep, LLRenderPass::PASS_SIMPLE);
+                    }
+                }
+                else if (fullbright)
+                {   //not deferred, register in standard fullbright shiny pass
+                    registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_SHINY);
+                }
+                else
+                { //not deferred or fullbright, register in standard shiny pass
+                    registerFace(group, facep, LLRenderPass::PASS_SHINY);
+                }
+            }
+            else
+            { //not alpha and not shiny
+                if (!is_alpha && tex->getPrimaryFormat() == GL_ALPHA)
+                { //invisiprim
+                    registerFace(group, facep, LLRenderPass::PASS_INVISIBLE);
+                }
+                else if (fullbright || bake_sunlight)
+                { //fullbright
+                    if (mat && mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
+                    {
+                        registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK);
+                    }
+                    else
+                    {
+                        registerFace(group, facep, LLRenderPass::PASS_FULLBRIGHT);
+                    }
+                    if (!hud_group && use_legacy_bump)
+                    { //if this is the deferred render and a bump map is present, register in post deferred bump
+                        registerFace(group, facep, LLRenderPass::PASS_POST_BUMP);
+                    }
+                }
+                else
+                {
+                    if (use_legacy_bump)
+                    { //non-shiny or fullbright deferred bump
                         llassert(mask& LLVertexBuffer::MAP_TANGENT);
-						registerFace(group, facep, LLRenderPass::PASS_BUMP);
-					}
-					else
-					{ //all around simple
-						llassert(mask & LLVertexBuffer::MAP_NORMAL);
-						if (mat && mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
-						{ //material alpha mask can be respected in non-deferred
-							registerFace(group, facep, LLRenderPass::PASS_ALPHA_MASK);
-						}
-						else
-						{
-							registerFace(group, facep, LLRenderPass::PASS_SIMPLE);
-						}
-				    }
-				}
-				
-				
-				if (!gPipeline.shadersLoaded() && 
-					!is_alpha && 
-					te->getShiny())
-				{ //shiny as an extra pass when shaders are disabled
-					registerFace(group, facep, LLRenderPass::PASS_SHINY);
-				}
-			}
-			
-			//not sure why this is here, and looks like it might cause bump mapped objects to get rendered redundantly -- davep 5/11/2010
-			if (!is_alpha && hud_group)
-			{
-				llassert((mask & LLVertexBuffer::MAP_NORMAL) || fullbright);
-				facep->setPoolType((fullbright) ? LLDrawPool::POOL_FULLBRIGHT : LLDrawPool::POOL_SIMPLE);
-				
-				if (!force_simple && use_legacy_bump)
-				{
+                        registerFace(group, facep, LLRenderPass::PASS_BUMP);
+                    }
+                    else
+                    { //all around simple
+                        llassert(mask & LLVertexBuffer::MAP_NORMAL);
+                        if (mat && mat->getDiffuseAlphaMode() == LLMaterial::DIFFUSE_ALPHA_MODE_MASK)
+                        { //material alpha mask can be respected in non-deferred
+                            registerFace(group, facep, LLRenderPass::PASS_ALPHA_MASK);
+                        }
+                        else
+                        {
+                            registerFace(group, facep, LLRenderPass::PASS_SIMPLE);
+                        }
+                    }
+                }
+
+
+                if (!gPipeline.shadersLoaded() &&
+                    !is_alpha &&
+                    te->getShiny())
+                { //shiny as an extra pass when shaders are disabled
+                    registerFace(group, facep, LLRenderPass::PASS_SHINY);
+                }
+            }
+
+            //not sure why this is here, and looks like it might cause bump mapped objects to get rendered redundantly -- davep 5/11/2010
+            if (!is_alpha && hud_group)
+            {
+                llassert((mask & LLVertexBuffer::MAP_NORMAL) || fullbright);
+                facep->setPoolType((fullbright) ? LLDrawPool::POOL_FULLBRIGHT : LLDrawPool::POOL_SIMPLE);
+
+                if (!force_simple && use_legacy_bump)
+                {
                     llassert(mask & LLVertexBuffer::MAP_TANGENT);
-					registerFace(group, facep, LLRenderPass::PASS_BUMP);
-				}
-			}
+                    registerFace(group, facep, LLRenderPass::PASS_BUMP);
+                }
+            }
 
-			if (!is_alpha && LLPipeline::sRenderGlow && te->getGlow() > 0.f)
-			{
+            if (!is_alpha && LLPipeline::sRenderGlow && te->getGlow() > 0.f)
+            {
                 if (gltf_mat)
                 {
                     registerFace(group, facep, LLRenderPass::PASS_GLTF_GLOW);
@@ -6847,24 +6847,24 @@ U32 LLVolumeGeometryManager::genDrawInfo(LLSpatialGroup* group, U32 mask, LLFace
                 {
                     registerFace(group, facep, LLRenderPass::PASS_GLOW);
                 }
-			}
-						
-			++face_iter;
-		}
+            }
+
+            ++face_iter;
+        }
 
-		if (buffer)
-		{
-			buffer->unmapBuffer();
-		}
-	}
+        if (buffer)
+        {
+            buffer->unmapBuffer();
+        }
+    }
 
-	auto& mask_buffer_map = buffer_map[mask];
+    auto& mask_buffer_map = buffer_map[mask];
 
-	auto& group_buffer_map = group->mBufferMap[mask];
-	group_buffer_map.clear();
-	group_buffer_map.insert(mask_buffer_map.begin(), mask_buffer_map.end());
+    auto& group_buffer_map = group->mBufferMap[mask];
+    group_buffer_map.clear();
+    group_buffer_map.insert(mask_buffer_map.begin(), mask_buffer_map.end());
 
-	return geometryBytes;
+    return geometryBytes;
 }
 
 void LLVolumeGeometryManager::addGeometryCount(LLSpatialGroup* group, U32& vertex_count, U32& index_count)
@@ -6882,57 +6882,57 @@ void LLVolumeGeometryManager::addGeometryCount(LLSpatialGroup* group, U32& verte
 }
 
 void LLGeometryManager::addGeometryCount(LLSpatialGroup* group, U32 &vertex_count, U32 &index_count)
-{	
+{
     LL_PROFILE_ZONE_SCOPED_CATEGORY_VOLUME;
 
     //clear off any old faces
     mFaceList.clear();
 
-	//for each drawable
-	for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(), drawable_end = group->getDataEnd(); drawable_iter != drawable_end; ++drawable_iter)
-	{
-		LLDrawable* drawablep = (LLDrawable*)(*drawable_iter)->getDrawable();
-		
-		if (!drawablep || drawablep->isDead())
-		{
-			continue;
-		}
-	
-		//for each face
-		for (S32 i = 0, i_end = drawablep->getNumFaces(); i < i_end; ++i)
-		{
-			//sum up face verts and indices
-			drawablep->updateFaceSize(i);
-			LLFace* facep = drawablep->getFace(i);
-			if (facep)
-			{
-				if (facep->hasGeometry() && facep->getPixelArea() > FORCE_CULL_AREA && 
-					facep->getGeomCount() + vertex_count <= 65536)
-				{
-					vertex_count += facep->getGeomCount();
-					index_count += facep->getIndicesCount();
-				
-					//remember face (for sorting)
-					mFaceList.push_back(facep);
-				}
-				else
-				{
-					facep->clearVertexBuffer();
-				}
-			}
-		}
-	}
+    //for each drawable
+    for (LLSpatialGroup::element_iter drawable_iter = group->getDataBegin(), drawable_end = group->getDataEnd(); drawable_iter != drawable_end; ++drawable_iter)
+    {
+        LLDrawable* drawablep = (LLDrawable*)(*drawable_iter)->getDrawable();
+
+        if (!drawablep || drawablep->isDead())
+        {
+            continue;
+        }
+
+        //for each face
+        for (S32 i = 0, i_end = drawablep->getNumFaces(); i < i_end; ++i)
+        {
+            //sum up face verts and indices
+            drawablep->updateFaceSize(i);
+            LLFace* facep = drawablep->getFace(i);
+            if (facep)
+            {
+                if (facep->hasGeometry() && facep->getPixelArea() > FORCE_CULL_AREA &&
+                    facep->getGeomCount() + vertex_count <= 65536)
+                {
+                    vertex_count += facep->getGeomCount();
+                    index_count += facep->getIndicesCount();
+
+                    //remember face (for sorting)
+                    mFaceList.push_back(facep);
+                }
+                else
+                {
+                    facep->clearVertexBuffer();
+                }
+            }
+        }
+    }
 }
 
 LLHUDPartition::LLHUDPartition(LLViewerRegion* regionp) : LLBridgePartition(regionp)
 {
-	mPartitionType = LLViewerRegion::PARTITION_HUD;
-	mDrawableType = LLPipeline::RENDER_TYPE_HUD;
-	mSlopRatio = 0.f;
-	mLODPeriod = 1;
+    mPartitionType = LLViewerRegion::PARTITION_HUD;
+    mDrawableType = LLPipeline::RENDER_TYPE_HUD;
+    mSlopRatio = 0.f;
+    mLODPeriod = 1;
 }
 
 void LLHUDPartition::shift(const LLVector4a &offset)
 {
-	//HUD objects don't shift with region crossing.  That would be silly.
+    //HUD objects don't shift with region crossing.  That would be silly.
 }
diff --git a/indra/newview/llvovolume.h b/indra/newview/llvovolume.h
index e9088b343f8c7476224c93b8bd042d62a8dd50ab..b93baf211a193c876452275717fb1fa7a8dfc326 100644
--- a/indra/newview/llvovolume.h
+++ b/indra/newview/llvovolume.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file llvovolume.h
  * @brief LLVOVolume class header file
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -32,8 +32,8 @@
 #include "llviewermedia.h"
 #include "llframetimer.h"
 #include "lllocalbitmaps.h"
-#include "m3math.h"		// LLMatrix3
-#include "m4math.h"		// LLMatrix4
+#include "m3math.h"     // LLMatrix3
+#include "m4math.h"     // LLMatrix4
 #include <unordered_map>
 #include <unordered_set>
 
@@ -51,7 +51,7 @@ typedef std::vector<viewer_media_t> media_list_t;
 
 enum LLVolumeInterfaceType
 {
-	INTERFACE_FLEXIBLE = 1,
+    INTERFACE_FLEXIBLE = 1,
 };
 
 const F32 MAX_LOD_FACTOR = 4.0f;
@@ -60,10 +60,10 @@ const F32 MAX_LOD_FACTOR = 4.0f;
 class LLRiggedVolume final : public LLVolume
 {
 public:
-	LLRiggedVolume(const LLVolumeParams& params)
-		: LLVolume(params, 0.f)
-	{
-	}
+    LLRiggedVolume(const LLVolumeParams& params)
+        : LLVolume(params, 0.f)
+    {
+    }
 
     using FaceIndex = S32;
     static const FaceIndex UPDATE_ALL_FACES = -1;
@@ -82,222 +82,222 @@ class LLRiggedVolume final : public LLVolume
 class LLVolumeInterface
 {
 public:
-	virtual ~LLVolumeInterface() { }
-	virtual LLVolumeInterfaceType getInterfaceType() const = 0;
-	virtual void doIdleUpdate() = 0;
-	virtual BOOL doUpdateGeometry(LLDrawable *drawable) = 0;
-	virtual LLVector3 getPivotPosition() const = 0;
-	virtual void onSetVolume(const LLVolumeParams &volume_params, const S32 detail) = 0;
-	virtual void onSetScale(const LLVector3 &scale, BOOL damped) = 0;
-	virtual void onParameterChanged(U16 param_type, LLNetworkData *data, BOOL in_use, bool local_origin) = 0;
-	virtual void onShift(const LLVector4a &shift_vector) = 0;
-	virtual bool isVolumeUnique() const = 0; // Do we need a unique LLVolume instance?
-	virtual bool isVolumeGlobal() const = 0; // Are we in global space?
-	virtual bool isActive() const = 0; // Is this object currently active?
-	virtual const LLMatrix4a& getWorldMatrix(LLXformMatrix* xform) const = 0;
-	virtual void updateRelativeXform(bool force_identity = false) = 0;
-	virtual U32 getID() const = 0;
-	virtual void preRebuild() = 0;
+    virtual ~LLVolumeInterface() { }
+    virtual LLVolumeInterfaceType getInterfaceType() const = 0;
+    virtual void doIdleUpdate() = 0;
+    virtual BOOL doUpdateGeometry(LLDrawable *drawable) = 0;
+    virtual LLVector3 getPivotPosition() const = 0;
+    virtual void onSetVolume(const LLVolumeParams &volume_params, const S32 detail) = 0;
+    virtual void onSetScale(const LLVector3 &scale, BOOL damped) = 0;
+    virtual void onParameterChanged(U16 param_type, LLNetworkData *data, BOOL in_use, bool local_origin) = 0;
+    virtual void onShift(const LLVector4a &shift_vector) = 0;
+    virtual bool isVolumeUnique() const = 0; // Do we need a unique LLVolume instance?
+    virtual bool isVolumeGlobal() const = 0; // Are we in global space?
+    virtual bool isActive() const = 0; // Is this object currently active?
+    virtual const LLMatrix4a& getWorldMatrix(LLXformMatrix* xform) const = 0;
+    virtual void updateRelativeXform(bool force_identity = false) = 0;
+    virtual U32 getID() const = 0;
+    virtual void preRebuild() = 0;
 };
 
 // Class which embodies all Volume objects (with pcode LL_PCODE_VOLUME)
 class LLVOVolume final : public LLViewerObject
 {
-	LOG_CLASS(LLVOVolume);
+    LOG_CLASS(LLVOVolume);
 protected:
-	virtual				~LLVOVolume();
+    virtual             ~LLVOVolume();
 
 public:
-	static		void	initClass();
-	static		void	cleanupClass();
-	static		void	preUpdateGeom();
-	
-	enum 
-	{
-		VERTEX_DATA_MASK =	(1 << LLVertexBuffer::TYPE_VERTEX) |
-							(1 << LLVertexBuffer::TYPE_NORMAL) |
-							(1 << LLVertexBuffer::TYPE_TEXCOORD0) |
-							(1 << LLVertexBuffer::TYPE_TEXCOORD1) |
-							(1 << LLVertexBuffer::TYPE_COLOR)
-	};
+    static      void    initClass();
+    static      void    cleanupClass();
+    static      void    preUpdateGeom();
+
+    enum
+    {
+        VERTEX_DATA_MASK =  (1 << LLVertexBuffer::TYPE_VERTEX) |
+                            (1 << LLVertexBuffer::TYPE_NORMAL) |
+                            (1 << LLVertexBuffer::TYPE_TEXCOORD0) |
+                            (1 << LLVertexBuffer::TYPE_TEXCOORD1) |
+                            (1 << LLVertexBuffer::TYPE_COLOR)
+    };
 
 public:
-	LLVOVolume(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
+    LLVOVolume(const LLUUID &id, const LLPCode pcode, LLViewerRegion *regionp);
     LLVOVolume* asVolume() final;
-	void markDead() override;		// Override (and call through to parent) to clean up media references
-
-	LLDrawable* createDrawable(LLPipeline *pipeline) override;
-
-				void	deleteFaces();
-
-				void	animateTextures();
-	
-	            BOOL    isVisible() const ;
-	BOOL isActive() const override;
-	BOOL isAttachment() const override;
-	BOOL isRootEdit() const override; // overridden for sake of attachments treating themselves as a root object
-	BOOL isHUDAttachment() const override;
-
-				void	generateSilhouette(LLSelectNode* nodep, const LLVector3& view_point);
-	/*virtual*/	BOOL	setParent(LLViewerObject* parent) override;
-				S32		getLOD() const override				{ return mLOD; }
-				void	setNoLOD()							{ mLOD = NO_LOD; mLODChanged = TRUE; }
-				bool	isNoLOD() const						{ return NO_LOD == mLOD; }
-	const LLVector3		getPivotPositionAgent() const override;
-	const LLMatrix4a&	getRelativeXform() const				{ return mRelativeXform; }
-	const LLMatrix4a&	getRelativeXformInvTrans() const		{ return mRelativeXformInvTrans; }
-	/*virtual*/	const LLMatrix4a&	getRenderMatrix() const override;
-				typedef std::unordered_set<const LLViewerTexture*> texture_cost_t;
+    void markDead() override;       // Override (and call through to parent) to clean up media references
+
+    LLDrawable* createDrawable(LLPipeline *pipeline) override;
+
+                void    deleteFaces();
+
+                void    animateTextures();
+
+                BOOL    isVisible() const ;
+    BOOL isActive() const override;
+    BOOL isAttachment() const override;
+    BOOL isRootEdit() const override; // overridden for sake of attachments treating themselves as a root object
+    BOOL isHUDAttachment() const override;
+
+                void    generateSilhouette(LLSelectNode* nodep, const LLVector3& view_point);
+    /*virtual*/ BOOL    setParent(LLViewerObject* parent) override;
+                S32     getLOD() const override             { return mLOD; }
+                void    setNoLOD()                          { mLOD = NO_LOD; mLODChanged = TRUE; }
+                bool    isNoLOD() const                     { return NO_LOD == mLOD; }
+    const LLVector3     getPivotPositionAgent() const override;
+    const LLMatrix4a&   getRelativeXform() const                { return mRelativeXform; }
+    const LLMatrix4a&   getRelativeXformInvTrans() const        { return mRelativeXformInvTrans; }
+    /*virtual*/ const LLMatrix4a&   getRenderMatrix() const override;
+                typedef std::unordered_set<const LLViewerTexture*> texture_cost_t;
                 static S32 getTextureCost(const LLViewerTexture* img);
-				U32 	getRenderCost(texture_cost_t &textures) const;
-    /*virtual*/	F32		getEstTrianglesMax() const override;
-    /*virtual*/	F32		getEstTrianglesStreamingCost() const override;
-    /* virtual*/ F32	getStreamingCost() const override;
+                U32     getRenderCost(texture_cost_t &textures) const;
+    /*virtual*/ F32     getEstTrianglesMax() const override;
+    /*virtual*/ F32     getEstTrianglesStreamingCost() const override;
+    /* virtual*/ F32    getStreamingCost() const override;
     /*virtual*/ bool getCostData(LLMeshCostData& costs) const override;
 
-	/*virtual*/ U32		getTriangleCount(S32* vcount = NULL) const override;
-	/*virtual*/ U32		getHighLODTriangleCount() override;
-	/*virtual*/ BOOL lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end, 
-										  S32 face = -1,                        // which face to check, -1 = ALL_SIDES
-										  BOOL pick_transparent = FALSE,
-										  BOOL pick_rigged = FALSE,
+    /*virtual*/ U32     getTriangleCount(S32* vcount = NULL) const override;
+    /*virtual*/ U32     getHighLODTriangleCount() override;
+    /*virtual*/ BOOL lineSegmentIntersect(const LLVector4a& start, const LLVector4a& end,
+                                          S32 face = -1,                        // which face to check, -1 = ALL_SIDES
+                                          BOOL pick_transparent = FALSE,
+                                          BOOL pick_rigged = FALSE,
                                           BOOL pick_unselectable = TRUE,
-										  S32* face_hit = NULL,                 // which face was hit
-										  LLVector4a* intersection = NULL,       // return the intersection point
-										  LLVector2* tex_coord = NULL,          // return the texture coordinates of the intersection point
-										  LLVector4a* normal = NULL,             // return the surface normal at the intersection point
-										  LLVector4a* tangent = NULL           // return the surface tangent at the intersection point
-		) override;
-	
-				LLVector3 agentPositionToVolume(const LLVector3& pos) const;
-				LLVector3 agentDirectionToVolume(const LLVector3& dir) const;
-				LLVector3 volumePositionToAgent(const LLVector3& dir) const;
-				LLVector3 volumeDirectionToAgent(const LLVector3& dir) const;
-
-				
+                                          S32* face_hit = NULL,                 // which face was hit
+                                          LLVector4a* intersection = NULL,       // return the intersection point
+                                          LLVector2* tex_coord = NULL,          // return the texture coordinates of the intersection point
+                                          LLVector4a* normal = NULL,             // return the surface normal at the intersection point
+                                          LLVector4a* tangent = NULL           // return the surface tangent at the intersection point
+        ) override;
+
+                LLVector3 agentPositionToVolume(const LLVector3& pos) const;
+                LLVector3 agentDirectionToVolume(const LLVector3& dir) const;
+                LLVector3 volumePositionToAgent(const LLVector3& dir) const;
+                LLVector3 volumeDirectionToAgent(const LLVector3& dir) const;
+
+
 // [FS:Beq] - Patch: Appearance-RebuildAttachments | Checked: Catznip-5.3
-				void    forceLOD(S32 lod);
+                void    forceLOD(S32 lod);
 // [/FS]
-				BOOL	getVolumeChanged() const				{ return mVolumeChanged; }
-				
-	F32 getVObjRadius() const override				{ return mVObjRadius; };
-				const LLMatrix4a& getWorldMatrix(LLXformMatrix* xform) const override;
+                BOOL    getVolumeChanged() const                { return mVolumeChanged; }
+
+    F32 getVObjRadius() const override              { return mVObjRadius; };
+                const LLMatrix4a& getWorldMatrix(LLXformMatrix* xform) const override;
 
-				void	markForUpdate() override;
-				void    faceMappingChanged() override           { mFaceMappingChanged=TRUE; }
+                void    markForUpdate() override;
+                void    faceMappingChanged() override           { mFaceMappingChanged=TRUE; }
 
-	/*virtual*/ void	onShift(const LLVector4a &shift_vector) override; // Called when the drawable shifts
+    /*virtual*/ void    onShift(const LLVector4a &shift_vector) override; // Called when the drawable shifts
 
-	/*virtual*/ void	parameterChanged(U16 param_type, bool local_origin) override;
-	/*virtual*/ void	parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_use, bool local_origin) override;
+    /*virtual*/ void    parameterChanged(U16 param_type, bool local_origin) override;
+    /*virtual*/ void    parameterChanged(U16 param_type, LLNetworkData* data, BOOL in_use, bool local_origin) override;
 
     // update mReflectionProbe based on isReflectionProbe()
     void updateReflectionProbePtr();
 
-	/*virtual*/ U32		processUpdateMessage(LLMessageSystem *mesgsys,
-											void **user_data,
-											U32 block_num, const EObjectUpdateType update_type,
-											LLDataPacker *dp) override;
-
-	/*virtual*/ void	setSelected(BOOL sel) override;
-	/*virtual*/ BOOL	setDrawableParent(LLDrawable* parentp) override;
-
-	/*virtual*/ void	setScale(const LLVector3 &scale, BOOL damped) override;
-
-	/*virtual*/ void    changeTEImage(S32 index, LLViewerTexture* new_image) override;
-	/*virtual*/ void	setNumTEs(const U8 num_tes) override;
-	/*virtual*/ void	setTEImage(const U8 te, LLViewerTexture *imagep) override;
-	/*virtual*/ S32		setTETexture(const U8 te, const LLUUID &uuid) override;
-	/*virtual*/ S32		setTEColor(const U8 te, const LLColor3 &color) override;
-	/*virtual*/ S32		setTEColor(const U8 te, const LLColor4 &color) override;
-	/*virtual*/ S32		setTEBumpmap(const U8 te, const U8 bump) override;
-	/*virtual*/ S32		setTEShiny(const U8 te, const U8 shiny) override;
-	/*virtual*/ S32		setTEFullbright(const U8 te, const U8 fullbright) override;
-	/*virtual*/ S32		setTEBumpShinyFullbright(const U8 te, const U8 bump) override;
-	/*virtual*/ S32		setTEMediaFlags(const U8 te, const U8 media_flags) override;
-	/*virtual*/ S32		setTEGlow(const U8 te, const F32 glow) override;
-	/*virtual*/ S32		setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID) override;
-	
-	static void	setTEMaterialParamsCallbackTE(const LLUUID& objectID, const LLMaterialID& pMaterialID, const LLMaterialPtr pMaterialParams, U32 te);
-
-	/*virtual*/ S32		setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams) override;
+    /*virtual*/ U32     processUpdateMessage(LLMessageSystem *mesgsys,
+                                            void **user_data,
+                                            U32 block_num, const EObjectUpdateType update_type,
+                                            LLDataPacker *dp) override;
+
+    /*virtual*/ void    setSelected(BOOL sel) override;
+    /*virtual*/ BOOL    setDrawableParent(LLDrawable* parentp) override;
+
+    /*virtual*/ void    setScale(const LLVector3 &scale, BOOL damped) override;
+
+    /*virtual*/ void    changeTEImage(S32 index, LLViewerTexture* new_image) override;
+    /*virtual*/ void    setNumTEs(const U8 num_tes) override;
+    /*virtual*/ void    setTEImage(const U8 te, LLViewerTexture *imagep) override;
+    /*virtual*/ S32     setTETexture(const U8 te, const LLUUID &uuid) override;
+    /*virtual*/ S32     setTEColor(const U8 te, const LLColor3 &color) override;
+    /*virtual*/ S32     setTEColor(const U8 te, const LLColor4 &color) override;
+    /*virtual*/ S32     setTEBumpmap(const U8 te, const U8 bump) override;
+    /*virtual*/ S32     setTEShiny(const U8 te, const U8 shiny) override;
+    /*virtual*/ S32     setTEFullbright(const U8 te, const U8 fullbright) override;
+    /*virtual*/ S32     setTEBumpShinyFullbright(const U8 te, const U8 bump) override;
+    /*virtual*/ S32     setTEMediaFlags(const U8 te, const U8 media_flags) override;
+    /*virtual*/ S32     setTEGlow(const U8 te, const F32 glow) override;
+    /*virtual*/ S32     setTEMaterialID(const U8 te, const LLMaterialID& pMaterialID) override;
+
+    static void setTEMaterialParamsCallbackTE(const LLUUID& objectID, const LLMaterialID& pMaterialID, const LLMaterialPtr pMaterialParams, U32 te);
+
+    /*virtual*/ S32     setTEMaterialParams(const U8 te, const LLMaterialPtr pMaterialParams) override;
                 S32     setTEGLTFMaterialOverride(U8 te, LLGLTFMaterial* mat) override;
-	/*virtual*/ S32		setTEScale(const U8 te, const F32 s, const F32 t) override;
-	/*virtual*/ S32		setTEScaleS(const U8 te, const F32 s) override;
-	/*virtual*/ S32		setTEScaleT(const U8 te, const F32 t) override;
-	/*virtual*/ S32		setTETexGen(const U8 te, const U8 texgen) override;
-	/*virtual*/ S32		setTEMediaTexGen(const U8 te, const U8 media) override;
-	/*virtual*/ BOOL 	setMaterial(const U8 material) override;
-
-				void	setTexture(const S32 face);
-				S32     getIndexInTex(U32 ch) const {return mIndexInTex[ch];}
-	/*virtual*/ BOOL	setVolume(const LLVolumeParams &volume_params, const S32 detail, bool unique_volume = false) override;
-				void	updateSculptTexture();
-				void    setIndexInTex(U32 ch, S32 index) { mIndexInTex[ch] = index ;}
-				void	sculpt();
-	 static     void    rebuildMeshAssetCallback(const LLUUID& asset_uuid,
-												 LLAssetType::EType type,
-												 void* user_data, S32 status, LLExtStat ext_status);
-					
-				void	updateRelativeXform(bool force_identity = false);
-	/*virtual*/ BOOL	updateGeometry(LLDrawable *drawable) override;
-	/*virtual*/ void	updateFaceSize(S32 idx) override;
-	/*virtual*/ BOOL	updateLOD() override;
-				void	updateRadius() override;
-	/*virtual*/ void	updateTextures() override;
-				void	updateTextureVirtualSize(bool forced = false);
-
-				void	updateFaceFlags();
-				void	regenFaces();
+    /*virtual*/ S32     setTEScale(const U8 te, const F32 s, const F32 t) override;
+    /*virtual*/ S32     setTEScaleS(const U8 te, const F32 s) override;
+    /*virtual*/ S32     setTEScaleT(const U8 te, const F32 t) override;
+    /*virtual*/ S32     setTETexGen(const U8 te, const U8 texgen) override;
+    /*virtual*/ S32     setTEMediaTexGen(const U8 te, const U8 media) override;
+    /*virtual*/ BOOL    setMaterial(const U8 material) override;
+
+                void    setTexture(const S32 face);
+                S32     getIndexInTex(U32 ch) const {return mIndexInTex[ch];}
+    /*virtual*/ BOOL    setVolume(const LLVolumeParams &volume_params, const S32 detail, bool unique_volume = false) override;
+                void    updateSculptTexture();
+                void    setIndexInTex(U32 ch, S32 index) { mIndexInTex[ch] = index ;}
+                void    sculpt();
+     static     void    rebuildMeshAssetCallback(const LLUUID& asset_uuid,
+                                                 LLAssetType::EType type,
+                                                 void* user_data, S32 status, LLExtStat ext_status);
+
+                void    updateRelativeXform(bool force_identity = false);
+    /*virtual*/ BOOL    updateGeometry(LLDrawable *drawable) override;
+    /*virtual*/ void    updateFaceSize(S32 idx) override;
+    /*virtual*/ BOOL    updateLOD() override;
+                void    updateRadius() override;
+    /*virtual*/ void    updateTextures() override;
+                void    updateTextureVirtualSize(bool forced = false);
+
+                void    updateFaceFlags();
+                void    regenFaces();
                 BOOL    genBBoxes(BOOL force_global, BOOL should_update_octree_bounds = TRUE);
-				void	preRebuild();
-	virtual		void	updateSpatialExtents(LLVector4a& min, LLVector4a& max) override;
-	virtual		F32		getBinRadius() override;
-	
-	virtual U32 getPartitionType() const override;
-
-	// For Lights
-	void setIsLight(BOOL is_light);
+                void    preRebuild();
+    virtual     void    updateSpatialExtents(LLVector4a& min, LLVector4a& max) override;
+    virtual     F32     getBinRadius() override;
+
+    virtual U32 getPartitionType() const override;
+
+    // For Lights
+    void setIsLight(BOOL is_light);
     //set the gamma-corrected (sRGB) color of this light
-	void setLightSRGBColor(const LLColor3& color);
+    void setLightSRGBColor(const LLColor3& color);
     //set the linear color of this light
     void setLightLinearColor(const LLColor3& color);
 
-	void setLightIntensity(F32 intensity);
-	void setLightRadius(F32 radius);
-	void setLightFalloff(F32 falloff);
-	void setLightCutoff(F32 cutoff);
-	void setLightTextureID(LLUUID id);
-	void setSpotLightParams(LLVector3 params);
+    void setLightIntensity(F32 intensity);
+    void setLightRadius(F32 radius);
+    void setLightFalloff(F32 falloff);
+    void setLightCutoff(F32 cutoff);
+    void setLightTextureID(LLUUID id);
+    void setSpotLightParams(LLVector3 params);
 
-	BOOL getIsLight() const;
+    BOOL getIsLight() const;
     bool getIsLightFast() const;
 
 
     // Get the light color in sRGB color space NOT scaled by intensity.
-	LLColor3 getLightSRGBBaseColor() const; 
+    LLColor3 getLightSRGBBaseColor() const;
 
     // Get the light color in linear color space NOT scaled by intensity.
     LLColor3 getLightLinearBaseColor() const;
-    
-    // Get the light color in linear color space scaled by intensity 
+
+    // Get the light color in linear color space scaled by intensity
     //  this is the value that should be fed into shaders
     LLColor3 getLightLinearColor() const;
 
     // Get the light color in sRGB color space scaled by intensity.
-    LLColor3 getLightSRGBColor() const; 
+    LLColor3 getLightSRGBColor() const;
 
-	LLUUID	getLightTextureID() const;
-	bool isLightSpotlight() const;
-	LLVector3 getSpotLightParams() const;
-	void	updateSpotLightPriority();
-	F32		getSpotLightPriority() const;
+    LLUUID  getLightTextureID() const;
+    bool isLightSpotlight() const;
+    LLVector3 getSpotLightParams() const;
+    void    updateSpotLightPriority();
+    F32     getSpotLightPriority() const;
 
-	LLViewerTexture* getLightTexture();
-	F32 getLightIntensity() const;
-	F32 getLightRadius() const;
-	F32 getLightFalloff(const F32 fudge_factor = 1.f) const;
-	F32 getLightCutoff() const;
+    LLViewerTexture* getLightTexture();
+    F32 getLightIntensity() const;
+    F32 getLightRadius() const;
+    F32 getLightFalloff(const F32 fudge_factor = 1.f) const;
+    F32 getLightCutoff() const;
 
     // Reflection Probes
     bool setIsReflectionProbe(BOOL is_probe);
@@ -314,13 +314,13 @@ class LLVOVolume final : public LLViewerObject
     bool getReflectionProbeIsDynamic() const;
     bool getReflectionProbeIsMirror() const;
 
-	// Flexible Objects
-	U32 getVolumeInterfaceID() const;
-	virtual BOOL isFlexible() const override;
-	virtual BOOL isSculpted() const override;
-	virtual BOOL isMesh() const override;
-	virtual BOOL isRiggedMesh() const override;
-	virtual BOOL hasLightTexture() const override;
+    // Flexible Objects
+    U32 getVolumeInterfaceID() const;
+    virtual BOOL isFlexible() const override;
+    virtual BOOL isSculpted() const override;
+    virtual BOOL isMesh() const override;
+    virtual BOOL isRiggedMesh() const override;
+    virtual BOOL hasLightTexture() const override;
 
     // fast variants above that use state that is filled in later
     //  not reliable early in the life of an object, but should be used after
@@ -331,16 +331,16 @@ class LLVOVolume final : public LLViewerObject
     bool isRiggedMeshFast() const;
     bool isAnimatedObjectFast() const;
 
-	BOOL isVolumeGlobal() const;
-	BOOL canBeFlexible() const;
-	BOOL setIsFlexible(BOOL is_flexible);
+    BOOL isVolumeGlobal() const;
+    BOOL canBeFlexible() const;
+    BOOL setIsFlexible(BOOL is_flexible);
 
     const LLMeshSkinInfo* getSkinInfo() const;
     const bool isSkinInfoUnavaliable() const { return mSkinInfoUnavaliable; }
 
     //convenience accessor for mesh ID (which is stored in sculpt id for legacy reasons)
     const LLUUID& getMeshID() const { return getVolume()->getParams().getSculptID(); }
-    
+
     // Extended Mesh Properties
     U32 getExtendedMeshFlags() const;
     void onSetExtendedMeshFlags(U32 flags);
@@ -353,58 +353,58 @@ class LLVOVolume final : public LLViewerObject
     //virtual
     void updateRiggingInfo() override;
     S32 mLastRiggingInfoLOD;
-    
+
     // Functions that deal with media, or media navigation
-    
+
     // Update this object's media data with the given media data array
     // (typically this is only called upon a response from a server request)
-	void updateObjectMediaData(const LLSD &media_data_array, const std::string &media_version);
-    
+    void updateObjectMediaData(const LLSD &media_data_array, const std::string &media_version);
+
     // Bounce back media at the given index to its current URL (or home URL, if current URL is empty)
-	void mediaNavigateBounceBack(U8 texture_index);
-    
-    // Returns whether or not this object has permission to navigate or control 
-	// the given media entry
-	enum MediaPermType {
-		MEDIA_PERM_INTERACT, MEDIA_PERM_CONTROL
-	};
+    void mediaNavigateBounceBack(U8 texture_index);
+
+    // Returns whether or not this object has permission to navigate or control
+    // the given media entry
+    enum MediaPermType {
+        MEDIA_PERM_INTERACT, MEDIA_PERM_CONTROL
+    };
     bool hasMediaPermission(const LLMediaEntry* media_entry, MediaPermType perm_type);
-    
-	void mediaNavigated(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin, std::string new_location);
-	void mediaEvent(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin, LLViewerMediaObserver::EMediaEvent event);
-			
-
-	// Sync the given media data with the impl and the given te
-	void syncMediaData(S32 te, const LLSD &media_data, bool merge, bool ignore_agent);
-	
-	// Send media data update to the simulator.
-	void sendMediaDataUpdate();
-
-	viewer_media_t getMediaImpl(U8 face_id) const;
-	S32 getFaceIndexWithMediaImpl(const LLViewerMediaImpl* media_impl, S32 start_face_id);
-	F64 getTotalMediaInterest() const;
-   
-	bool hasMedia() const;
-	
-	LLVector3 getApproximateFaceNormal(U8 face_id);
+
+    void mediaNavigated(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin, std::string new_location);
+    void mediaEvent(LLViewerMediaImpl *impl, LLPluginClassMedia* plugin, LLViewerMediaObserver::EMediaEvent event);
+
+
+    // Sync the given media data with the impl and the given te
+    void syncMediaData(S32 te, const LLSD &media_data, bool merge, bool ignore_agent);
+
+    // Send media data update to the simulator.
+    void sendMediaDataUpdate();
+
+    viewer_media_t getMediaImpl(U8 face_id) const;
+    S32 getFaceIndexWithMediaImpl(const LLViewerMediaImpl* media_impl, S32 start_face_id);
+    F64 getTotalMediaInterest() const;
+
+    bool hasMedia() const;
+
+    LLVector3 getApproximateFaceNormal(U8 face_id);
 
     // Flag any corresponding avatars as needing update.
     void updateVisualComplexity();
-    
-	void notifyMeshLoaded();
-	void notifySkinInfoLoaded(const LLMeshSkinInfo* skin);
-	void notifySkinInfoUnavailable();
-	
-	// Returns 'true' iff the media data for this object is in flight
-	bool isMediaDataBeingFetched() const;
-
-	// Returns the "last fetched" media version, or -1 if not fetched yet
-	S32 getLastFetchedMediaVersion() const { return mLastFetchedMediaVersion; }
-
-	void addMDCImpl() { ++mMDCImplCount; }
-	void removeMDCImpl() { --mMDCImplCount; }
-	S32 getMDCImplCount() { return mMDCImplCount; }
-	
+
+    void notifyMeshLoaded();
+    void notifySkinInfoLoaded(const LLMeshSkinInfo* skin);
+    void notifySkinInfoUnavailable();
+
+    // Returns 'true' iff the media data for this object is in flight
+    bool isMediaDataBeingFetched() const;
+
+    // Returns the "last fetched" media version, or -1 if not fetched yet
+    S32 getLastFetchedMediaVersion() const { return mLastFetchedMediaVersion; }
+
+    void addMDCImpl() { ++mMDCImplCount; }
+    void removeMDCImpl() { --mMDCImplCount; }
+    S32 getMDCImplCount() { return mMDCImplCount; }
+
 
     // Rigged volume update (for raycasting)
     // By default, this updates the bounding boxes of all the faces and builds an octree for precise per-triangle raycasting
@@ -412,74 +412,74 @@ class LLVOVolume final : public LLViewerObject
         bool force_treat_as_rigged,
         LLRiggedVolume::FaceIndex face_index = LLRiggedVolume::UPDATE_ALL_FACES,
         bool rebuild_face_octrees = true);
-	LLRiggedVolume* getRiggedVolume();
+    LLRiggedVolume* getRiggedVolume();
 
-	//returns true if volume should be treated as a rigged volume
-	// - Build tools are open
-	// - object is an attachment
-	// - object is attached to self
-	// - object is rendered as rigged
-	bool treatAsRigged();
+    //returns true if volume should be treated as a rigged volume
+    // - Build tools are open
+    // - object is an attachment
+    // - object is attached to self
+    // - object is rendered as rigged
+    bool treatAsRigged();
 
-	//clear out rigged volume and revert back to non-rigged state for picking/LOD/distance updates
-	void clearRiggedVolume();
+    //clear out rigged volume and revert back to non-rigged state for picking/LOD/distance updates
+    void clearRiggedVolume();
 
 protected:
-	S32	computeLODDetail(F32 distance, F32 radius, F32 lod_factor);
-	BOOL calcLOD();
-	LLFace* addFace(S32 face_index);
-	
-	// stats tracking for render complexity
-	static S32 mRenderComplexity_last;
-	static S32 mRenderComplexity_current;
+    S32 computeLODDetail(F32 distance, F32 radius, F32 lod_factor);
+    BOOL calcLOD();
+    LLFace* addFace(S32 face_index);
+
+    // stats tracking for render complexity
+    static S32 mRenderComplexity_last;
+    static S32 mRenderComplexity_current;
 
     void onDrawableUpdateFromServer();
-	void requestMediaDataUpdate(bool isNew);
-	void cleanUpMediaImpls();
-	void addMediaImpl(LLViewerMediaImpl* media_impl, S32 texture_index) ;
-	void removeMediaImpl(S32 texture_index) ;
+    void requestMediaDataUpdate(bool isNew);
+    void cleanUpMediaImpls();
+    void addMediaImpl(LLViewerMediaImpl* media_impl, S32 texture_index) ;
+    void removeMediaImpl(S32 texture_index) ;
 
 private:
     bool lodOrSculptChanged(LLDrawable *drawable, BOOL &compiled, BOOL &shouldUpdateOctreeBounds);
 
 public:
 
-	static S32 getRenderComplexityMax() {return mRenderComplexity_last;}
-	static void updateRenderComplexity();
+    static S32 getRenderComplexityMax() {return mRenderComplexity_last;}
+    static void updateRenderComplexity();
 
-	LLViewerTextureAnim *mTextureAnimp;
-	U8 mTexAnimMode;
+    LLViewerTextureAnim *mTextureAnimp;
+    U8 mTexAnimMode;
     F32 mLODDistance;
     F32 mLODAdjustedDistance;
     F32 mLODRadius;
 
-	void incMeshCache() { mFetchingMesh++; }
-	void incSkinCache() { mFetchingSkinInfo++; }
-	void decMeshCache() { mFetchingMesh--; }
-	void decSkinCache() { mFetchingSkinInfo--; }
+    void incMeshCache() { mFetchingMesh++; }
+    void incSkinCache() { mFetchingSkinInfo++; }
+    void decMeshCache() { mFetchingMesh--; }
+    void decSkinCache() { mFetchingSkinInfo--; }
 private:
-	friend class LLDrawable;
-	friend class LLFace;
-
-	BOOL		mFaceMappingChanged;
-	LLFrameTimer mTextureUpdateTimer;
-	S32			mLOD;
-	BOOL		mLODChanged;
-	BOOL		mSculptChanged;
-    BOOL		mColorChanged;
-	F32			mSpotLightPriority;
-	LL_ALIGN_16(LLMatrix4a	mRelativeXform);
-	LL_ALIGN_16(LLMatrix4a	mRelativeXformInvTrans);
-	BOOL		mVolumeChanged;
-	F32			mVObjRadius;
-	LLVolumeInterface *mVolumeImpl;
-	LLPointer<LLViewerFetchedTexture> mSculptTexture;
-	LLPointer<LLViewerFetchedTexture> mLightTexture;
-	media_list_t mMediaImplList;
-	S32			mLastFetchedMediaVersion; // as fetched from the server, starts as -1
+    friend class LLDrawable;
+    friend class LLFace;
+
+    BOOL        mFaceMappingChanged;
+    LLFrameTimer mTextureUpdateTimer;
+    S32         mLOD;
+    BOOL        mLODChanged;
+    BOOL        mSculptChanged;
+    BOOL        mColorChanged;
+    F32         mSpotLightPriority;
+    LL_ALIGN_16(LLMatrix4a  mRelativeXform);
+    LL_ALIGN_16(LLMatrix4a  mRelativeXformInvTrans);
+    BOOL        mVolumeChanged;
+    F32         mVObjRadius;
+    LLVolumeInterface *mVolumeImpl;
+    LLPointer<LLViewerFetchedTexture> mSculptTexture;
+    LLPointer<LLViewerFetchedTexture> mLightTexture;
+    media_list_t mMediaImplList;
+    S32         mLastFetchedMediaVersion; // as fetched from the server, starts as -1
     U32         mServerDrawableUpdateCount;
-	S32 mIndexInTex[LLRender::NUM_VOLUME_TEXTURE_CHANNELS];
-	S32 mMDCImplCount;
+    S32 mIndexInTex[LLRender::NUM_VOLUME_TEXTURE_CHANNELS];
+    S32 mMDCImplCount;
 
     // cached value of getIsLight to avoid redundant map lookups
     // accessed by getIsLightFast
@@ -488,26 +488,26 @@ class LLVOVolume final : public LLViewerObject
     // cached value of getIsAnimatedObject to avoid redundant map lookups
     // accessed by getIsAnimatedObjectFast
     mutable bool mIsAnimatedObject = false;
-	bool mResetDebugText;
+    bool mResetDebugText;
 
-	LLPointer<LLRiggedVolume> mRiggedVolume;
+    LLPointer<LLRiggedVolume> mRiggedVolume;
 
-	S32 mFetchingMesh = 0;
-	S32 mFetchingSkinInfo = 0;
-	bool mSkinInfoUnavaliable;
-	LLConstPointer<LLMeshSkinInfo> mSkinInfo;
-	// statics
+    S32 mFetchingMesh = 0;
+    S32 mFetchingSkinInfo = 0;
+    bool mSkinInfoUnavaliable;
+    LLConstPointer<LLMeshSkinInfo> mSkinInfo;
+    // statics
 public:
-	static F32 sLODSlopDistanceFactor;// Changing this to zero, effectively disables the LOD transition slop
-	static F32 sLODFactor;				// LOD scale factor
-	static F32 sDistanceFactor;			// LOD distance factor
+    static F32 sLODSlopDistanceFactor;// Changing this to zero, effectively disables the LOD transition slop
+    static F32 sLODFactor;              // LOD scale factor
+    static F32 sDistanceFactor;         // LOD distance factor
 
-	static LLPointer<LLObjectMediaDataClient> sObjectMediaClient;
-	static LLPointer<LLObjectMediaNavigateClient> sObjectMediaNavigateClient;
+    static LLPointer<LLObjectMediaDataClient> sObjectMediaClient;
+    static LLPointer<LLObjectMediaNavigateClient> sObjectMediaNavigateClient;
 protected:
-	static S32 sNumLODChanges;
+    static S32 sNumLODChanges;
 
-	friend class LLVolumeImplFlexible;
+    friend class LLVolumeImplFlexible;
 };
 
 #endif // LL_LLVOVOLUME_H
diff --git a/indra/newview/llxmlrpclistener.cpp b/indra/newview/llxmlrpclistener.cpp
index ccb329359cff9edc47acf595ef8dc1367196d7ed..9323a3ebbddbab98a20c0a39d85619b3844e1303 100644
--- a/indra/newview/llxmlrpclistener.cpp
+++ b/indra/newview/llxmlrpclistener.cpp
@@ -3,25 +3,25 @@
  * @author Nat Goodspeed
  * @date   2009-03-18
  * @brief  Implementation for llxmlrpclistener.
- * 
+ *
  * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -77,13 +77,13 @@ class StatusMapper: public StatusMapperBase<LLXMLRPCTransaction::EStatus>
 public:
     StatusMapper(): StatusMapperBase<LLXMLRPCTransaction::EStatus>("Status")
     {
-		mMap[LLXMLRPCTransaction::StatusNotStarted]  = "NotStarted";
-		mMap[LLXMLRPCTransaction::StatusStarted]     = "Started";
-		mMap[LLXMLRPCTransaction::StatusDownloading] = "Downloading";
-		mMap[LLXMLRPCTransaction::StatusComplete]    = "Complete";
-		mMap[LLXMLRPCTransaction::StatusCURLError]   = "CURLError";
-		mMap[LLXMLRPCTransaction::StatusXMLRPCError] = "XMLRPCError";
-		mMap[LLXMLRPCTransaction::StatusOtherError]  = "OtherError";
+        mMap[LLXMLRPCTransaction::StatusNotStarted]  = "NotStarted";
+        mMap[LLXMLRPCTransaction::StatusStarted]     = "Started";
+        mMap[LLXMLRPCTransaction::StatusDownloading] = "Downloading";
+        mMap[LLXMLRPCTransaction::StatusComplete]    = "Complete";
+        mMap[LLXMLRPCTransaction::StatusCURLError]   = "CURLError";
+        mMap[LLXMLRPCTransaction::StatusXMLRPCError] = "XMLRPCError";
+        mMap[LLXMLRPCTransaction::StatusOtherError]  = "OtherError";
     }
 };
 
@@ -274,7 +274,7 @@ class Poller
         XMLRPC_RequestSetData(request, xparams);
 
         mTransaction.reset(new LLXMLRPCTransaction(mUri, request, true, command.has("http_params")? LLSD(command["http_params"]) : LLSD()));
-		mPreviousStatus = mTransaction->status(NULL);
+        mPreviousStatus = mTransaction->status(NULL);
 
         // Free the XMLRPC_REQUEST object and the attached data values.
         XMLRPC_RequestFree(request, 1);
@@ -312,39 +312,39 @@ class Poller
         data["error"] = "";
         data["transfer_rate"] = 0.0;
         LLEventPump& replyPump(LLEventPumps::instance().obtain(mReplyPump));
-		if (! done)
+        if (! done)
         {
             // Not done yet, carry on.
-			if (status == LLXMLRPCTransaction::StatusDownloading
-				&& status != mPreviousStatus)
-			{
-				// If a response has been received, send the 
-				// 'downloading' status if it hasn't been sent.
-				replyPump.post(data);
-			}
-
-			mPreviousStatus = status;
+            if (status == LLXMLRPCTransaction::StatusDownloading
+                && status != mPreviousStatus)
+            {
+                // If a response has been received, send the
+                // 'downloading' status if it hasn't been sent.
+                replyPump.post(data);
+            }
+
+            mPreviousStatus = status;
             return false;
         }
 
         // Here the transaction is complete. Check status.
         data["error"] = mTransaction->statusMessage();
-		data["transfer_rate"] = mTransaction->transferRate();
+        data["transfer_rate"] = mTransaction->transferRate();
         LL_INFOS("LLXMLRPCListener") << mMethod << " result from " << mUri << ": status "
                                      << data["status"].asString() << ", errorcode "
                                      << data["errorcode"].asString()
                                      << " (" << data["error"].asString() << ")"
                                      << LL_ENDL;
-		
-		switch (curlcode)
-		{
-			case CURLE_PEER_FAILED_VERIFICATION:
+
+        switch (curlcode)
+        {
+            case CURLE_PEER_FAILED_VERIFICATION:
                 data["certificate"] = mTransaction->getErrorCertData();
-				break;
+                break;
 
-			default:
-				break;
-		}
+            default:
+                break;
+        }
         // values of 'curlcode':
         // CURLE_COULDNT_RESOLVE_HOST,
         // CURLE_SSL_PEER_CERTIFICATE,
@@ -537,7 +537,7 @@ class Poller
     const std::string mReplyPump;
     LLTempBoundListener mBoundListener;
     std::unique_ptr<LLXMLRPCTransaction> mTransaction;
-	LLXMLRPCTransaction::EStatus mPreviousStatus; // To detect state changes.
+    LLXMLRPCTransaction::EStatus mPreviousStatus; // To detect state changes.
 };
 
 bool LLXMLRPCListener::process(const LLSD& command)
diff --git a/indra/newview/pipeline.cpp b/indra/newview/pipeline.cpp
index d6bc121448d26cef44514ff3c39954cd588cec0d..1563985cfc4eff0677aa87a208ff2cc55c51b00c 100644
--- a/indra/newview/pipeline.cpp
+++ b/indra/newview/pipeline.cpp
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file pipeline.cpp
  * @brief Rendering pipeline.
  *
  * $LicenseInfo:firstyear=2005&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -41,11 +41,11 @@
 #include "llvolume.h"
 #include "material_codes.h"
 #include "v3color.h"
-#include "llui.h" 
+#include "llui.h"
 #include "llglheaders.h"
 #include "llrender.h"
 #include "llstartup.h"
-#include "llwindow.h"	// swapBuffers()
+#include "llwindow.h"   // swapBuffers()
 
 // newview includes
 #include "llagent.h"
@@ -236,9 +236,9 @@ extern BOOL gDebugGL;
 extern BOOL gCubeSnapshot;
 extern BOOL gSnapshotNoPost;
 
-bool	gAvatarBacklight = false;
+bool    gAvatarBacklight = false;
 
-bool	gDebugPipeline = false;
+bool    gDebugPipeline = false;
 LLPipeline gPipeline;
 const LLMatrix4a* gGLLastMatrix = NULL;
 
@@ -261,46 +261,46 @@ LLVertexBuffer* ll_create_cube_vb(U32 type_mask);
 void display_update_camera();
 //----------------------------------------
 
-bool	LLPipeline::sPickAvatar = true;
-bool	LLPipeline::sDynamicLOD = true;
-bool	LLPipeline::sShowHUDAttachments = true;
-bool	LLPipeline::sRenderMOAPBeacons = false;
-bool	LLPipeline::sRenderPhysicalBeacons = true;
-bool	LLPipeline::sRenderScriptedBeacons = false;
-bool	LLPipeline::sRenderScriptedTouchBeacons = true;
-bool	LLPipeline::sRenderParticleBeacons = false;
-bool	LLPipeline::sRenderSoundBeacons = false;
-bool	LLPipeline::sRenderBeacons = false;
-bool	LLPipeline::sRenderHighlight = true;
+bool    LLPipeline::sPickAvatar = true;
+bool    LLPipeline::sDynamicLOD = true;
+bool    LLPipeline::sShowHUDAttachments = true;
+bool    LLPipeline::sRenderMOAPBeacons = false;
+bool    LLPipeline::sRenderPhysicalBeacons = true;
+bool    LLPipeline::sRenderScriptedBeacons = false;
+bool    LLPipeline::sRenderScriptedTouchBeacons = true;
+bool    LLPipeline::sRenderParticleBeacons = false;
+bool    LLPipeline::sRenderSoundBeacons = false;
+bool    LLPipeline::sRenderBeacons = false;
+bool    LLPipeline::sRenderHighlight = true;
 LLRender::eTexIndex LLPipeline::sRenderHighlightTextureChannel = LLRender::DIFFUSE_MAP;
-bool	LLPipeline::sForceOldBakedUpload = false;
-S32		LLPipeline::sUseOcclusion = 0;
-bool	LLPipeline::sAutoMaskAlphaDeferred = true;
-bool	LLPipeline::sAutoMaskAlphaNonDeferred = false;
-bool	LLPipeline::sRenderTransparentWater = true;
-bool	LLPipeline::sBakeSunlight = false;
-bool	LLPipeline::sNoAlpha = false;
-bool	LLPipeline::sUseFarClip = true;
-bool	LLPipeline::sShadowRender = false;
-bool	LLPipeline::sRenderGlow = false;
-bool	LLPipeline::sReflectionRender = false;
+bool    LLPipeline::sForceOldBakedUpload = false;
+S32     LLPipeline::sUseOcclusion = 0;
+bool    LLPipeline::sAutoMaskAlphaDeferred = true;
+bool    LLPipeline::sAutoMaskAlphaNonDeferred = false;
+bool    LLPipeline::sRenderTransparentWater = true;
+bool    LLPipeline::sBakeSunlight = false;
+bool    LLPipeline::sNoAlpha = false;
+bool    LLPipeline::sUseFarClip = true;
+bool    LLPipeline::sShadowRender = false;
+bool    LLPipeline::sRenderGlow = false;
+bool    LLPipeline::sReflectionRender = false;
 bool    LLPipeline::sDistortionRender = false;
-bool	LLPipeline::sImpostorRender = false;
-bool	LLPipeline::sImpostorRenderAlphaDepthPass = false;
-bool	LLPipeline::sUnderWaterRender = false;
-bool	LLPipeline::sTextureBindTest = false;
-bool	LLPipeline::sRenderAttachedLights = true;
-bool	LLPipeline::sRenderAttachedParticles = true;
-bool	LLPipeline::sRenderDeferred = false;
-bool	LLPipeline::sReflectionProbesEnabled = false;
-S32		LLPipeline::sVisibleLightCount = 0;
-bool	LLPipeline::sRenderingHUDs;
+bool    LLPipeline::sImpostorRender = false;
+bool    LLPipeline::sImpostorRenderAlphaDepthPass = false;
+bool    LLPipeline::sUnderWaterRender = false;
+bool    LLPipeline::sTextureBindTest = false;
+bool    LLPipeline::sRenderAttachedLights = true;
+bool    LLPipeline::sRenderAttachedParticles = true;
+bool    LLPipeline::sRenderDeferred = false;
+bool    LLPipeline::sReflectionProbesEnabled = false;
+S32     LLPipeline::sVisibleLightCount = 0;
+bool    LLPipeline::sRenderingHUDs;
 F32     LLPipeline::sDistortionWaterClipPlaneMargin = 1.0125f;
 // [SL:KB] - Patch: Render-TextureToggle (Catznip-4.0)
-bool	LLPipeline::sRenderTextures = true;
+bool    LLPipeline::sRenderTextures = true;
 // [/SL:KB]
 // [RLVa:KB] - @setsphere
-bool	LLPipeline::sUseDepthTexture = false;
+bool    LLPipeline::sUseDepthTexture = false;
 // [/RLVa:KB]
 
 // EventHost API LLPipeline listener.
@@ -323,61 +323,61 @@ bool addDeferredAttachments(LLRenderTarget& target, bool for_impostor = false)
 
 glh::matrix4f gl_ortho(GLfloat left, GLfloat right, GLfloat bottom, GLfloat top, GLfloat znear, GLfloat zfar)
 {
-	glh::matrix4f ret(
-		2.f/(right-left), 0.f, 0.f, -(right+left)/(right-left),
-		0.f, 2.f/(top-bottom), 0.f, -(top+bottom)/(top-bottom),
-		0.f, 0.f, -2.f/(zfar-znear),  -(zfar+znear)/(zfar-znear),
-		0.f, 0.f, 0.f, 1.f);
+    glh::matrix4f ret(
+        2.f/(right-left), 0.f, 0.f, -(right+left)/(right-left),
+        0.f, 2.f/(top-bottom), 0.f, -(top+bottom)/(top-bottom),
+        0.f, 0.f, -2.f/(zfar-znear),  -(zfar+znear)/(zfar-znear),
+        0.f, 0.f, 0.f, 1.f);
 
-	return ret;
+    return ret;
 }
 
 glh::matrix4f gl_perspective(GLfloat fovy, GLfloat aspect, GLfloat zNear, GLfloat zFar)
 {
-	GLfloat f = 1.f/tanf(DEG_TO_RAD*fovy/2.f);
+    GLfloat f = 1.f/tanf(DEG_TO_RAD*fovy/2.f);
 
-	return glh::matrix4f(f/aspect, 0, 0, 0,
-						 0, f, 0, 0,
-						 0, 0, (zFar+zNear)/(zNear-zFar), (2.f*zFar*zNear)/(zNear-zFar),
-						 0, 0, -1.f, 0);
+    return glh::matrix4f(f/aspect, 0, 0, 0,
+                         0, f, 0, 0,
+                         0, 0, (zFar+zNear)/(zNear-zFar), (2.f*zFar*zNear)/(zNear-zFar),
+                         0, 0, -1.f, 0);
 }
 
 glh::matrix4f gl_lookat(LLVector3 eye, LLVector3 center, LLVector3 up)
 {
-	LLVector3 f = center-eye;
-	f.normVec();
-	up.normVec();
-	LLVector3 s = f % up;
-	LLVector3 u = s % f;
+    LLVector3 f = center-eye;
+    f.normVec();
+    up.normVec();
+    LLVector3 s = f % up;
+    LLVector3 u = s % f;
+
+    return glh::matrix4f(s[0], s[1], s[2], 0,
+                      u[0], u[1], u[2], 0,
+                      -f[0], -f[1], -f[2], 0,
+                      0, 0, 0, 1);
 
-	return glh::matrix4f(s[0], s[1], s[2], 0,
-					  u[0], u[1], u[2], 0,
-					  -f[0], -f[1], -f[2], 0,
-					  0, 0, 0, 1);
-	
 }
 
 LLPipeline::LLPipeline() :
-	mBackfaceCull(false),
-	mMatrixOpCount(0),
-	mTextureMatrixOps(0),
-	mNumVisibleNodes(0),
-	mPoissonOffset(0),
-	mInitialized(false),
-	mShadersLoaded(false),
-	mRenderDebugFeatureMask(0),
-	mRenderDebugMask(0),
-	mOldRenderDebugMask(0),
-	mMeshDirtyQueryObject(0),
-	mGroupQ1Locked(false),
-	mResetVertexBuffers(false),
-	mLastRebuildPool(NULL),
-	mLightMask(0),
-	mLightMovingMask(0)
-{
-	mNoiseMap = 0;
-	mTrueNoiseMap = 0;
-	mLightFunc = 0;
+    mBackfaceCull(false),
+    mMatrixOpCount(0),
+    mTextureMatrixOps(0),
+    mNumVisibleNodes(0),
+    mPoissonOffset(0),
+    mInitialized(false),
+    mShadersLoaded(false),
+    mRenderDebugFeatureMask(0),
+    mRenderDebugMask(0),
+    mOldRenderDebugMask(0),
+    mMeshDirtyQueryObject(0),
+    mGroupQ1Locked(false),
+    mResetVertexBuffers(false),
+    mLastRebuildPool(NULL),
+    mLightMask(0),
+    mLightMovingMask(0)
+{
+    mNoiseMap = 0;
+    mTrueNoiseMap = 0;
+    mLightFunc = 0;
     mAreaMap      = 0;
     mSearchMap    = 0;
     mSampleMap    = 0;
@@ -390,102 +390,102 @@ LLPipeline::LLPipeline() :
 
 void LLPipeline::connectRefreshCachedSettingsSafe(const std::string name)
 {
-	LLPointer<LLControlVariable> cntrl_ptr = gSavedSettings.getControl(name);
-	if ( cntrl_ptr.isNull() )
-	{
-		LL_WARNS() << "Global setting name not found:" << name << LL_ENDL;
-	}
-	else
-	{
-		cntrl_ptr->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
-	}
+    LLPointer<LLControlVariable> cntrl_ptr = gSavedSettings.getControl(name);
+    if ( cntrl_ptr.isNull() )
+    {
+        LL_WARNS() << "Global setting name not found:" << name << LL_ENDL;
+    }
+    else
+    {
+        cntrl_ptr->getCommitSignal()->connect(boost::bind(&LLPipeline::refreshCachedSettings));
+    }
 }
 
 void LLPipeline::init()
 {
-	refreshCachedSettings();
+    refreshCachedSettings();
 
-	// Initialize Alchemy render stack
-	mALRenderUtil = std::make_unique<ALRenderUtil>();
+    // Initialize Alchemy render stack
+    mALRenderUtil = std::make_unique<ALRenderUtil>();
 
     mRT = &mMainRT;
 
-	gOctreeMaxCapacity = gSavedSettings.getU32("OctreeMaxNodeCapacity");
-	gOctreeMinSize = gSavedSettings.getF32("OctreeMinimumNodeSize");
-	sDynamicLOD = gSavedSettings.getBOOL("RenderDynamicLOD");
-	sRenderAttachedLights = gSavedSettings.getBOOL("RenderAttachedLights");
-	sRenderAttachedParticles = gSavedSettings.getBOOL("RenderAttachedParticles");
+    gOctreeMaxCapacity = gSavedSettings.getU32("OctreeMaxNodeCapacity");
+    gOctreeMinSize = gSavedSettings.getF32("OctreeMinimumNodeSize");
+    sDynamicLOD = gSavedSettings.getBOOL("RenderDynamicLOD");
+    sRenderAttachedLights = gSavedSettings.getBOOL("RenderAttachedLights");
+    sRenderAttachedParticles = gSavedSettings.getBOOL("RenderAttachedParticles");
 
     mInitialized = true;
-	
-	stop_glerror();
 
-	//create render pass pools
-	getPool(LLDrawPool::POOL_ALPHA_PRE_WATER);
+    stop_glerror();
+
+    //create render pass pools
+    getPool(LLDrawPool::POOL_ALPHA_PRE_WATER);
     getPool(LLDrawPool::POOL_ALPHA_POST_WATER);
-	getPool(LLDrawPool::POOL_SIMPLE);
-	getPool(LLDrawPool::POOL_ALPHA_MASK);
-	getPool(LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK);
-	getPool(LLDrawPool::POOL_GRASS);
-	getPool(LLDrawPool::POOL_FULLBRIGHT);
-	getPool(LLDrawPool::POOL_BUMP);
-	getPool(LLDrawPool::POOL_MATERIALS);
-	getPool(LLDrawPool::POOL_GLOW);
-	getPool(LLDrawPool::POOL_GLTF_PBR);
+    getPool(LLDrawPool::POOL_SIMPLE);
+    getPool(LLDrawPool::POOL_ALPHA_MASK);
+    getPool(LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK);
+    getPool(LLDrawPool::POOL_GRASS);
+    getPool(LLDrawPool::POOL_FULLBRIGHT);
+    getPool(LLDrawPool::POOL_BUMP);
+    getPool(LLDrawPool::POOL_MATERIALS);
+    getPool(LLDrawPool::POOL_GLOW);
+    getPool(LLDrawPool::POOL_GLTF_PBR);
     getPool(LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK);
 
-	resetFrameStats();
-
-	if (gSavedSettings.getBOOL("DisableAllRenderFeatures"))
-	{
-		clearAllRenderDebugFeatures();
-	}
-	else
-	{
-		setAllRenderDebugFeatures(); // By default, all debugging features on
-	}
-	clearAllRenderDebugDisplays(); // All debug displays off
-
-	if (gSavedSettings.getBOOL("DisableAllRenderTypes"))
-	{
-		clearAllRenderTypes();
-	}
-	else if (gNonInteractive)
-	{
-		clearAllRenderTypes();
-	}
-	else
-	{
-		setAllRenderTypes(); // By default, all rendering types start enabled
-	}
-
-	// make sure RenderPerformanceTest persists (hackity hack hack)
-	// disables non-object rendering (UI, sky, water, etc)
-	if (gSavedSettings.getBOOL("RenderPerformanceTest"))
-	{
-		gSavedSettings.setBOOL("RenderPerformanceTest", FALSE);
-		gSavedSettings.setBOOL("RenderPerformanceTest", TRUE);
-	}
-
-	mOldRenderDebugMask = mRenderDebugMask;
-
-	mBackfaceCull = true;
-
-	// Enable features
-	LLViewerShaderMgr::instance()->setShaders();
-
-	for (U32 i = 0; i < 2; ++i)
-	{
-		mSpotLightFade[i] = 1.f;
-	}
-
-	if (mCubeVB.isNull())
-	{
-		mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX);
-	}
-
-	mDeferredVB = new LLVertexBuffer(DEFERRED_VB_MASK);
-	mDeferredVB->allocateBuffer(8, 0);
+    resetFrameStats();
+
+    if (gSavedSettings.getBOOL("DisableAllRenderFeatures"))
+    {
+        clearAllRenderDebugFeatures();
+    }
+    else
+    {
+        setAllRenderDebugFeatures(); // By default, all debugging features on
+    }
+    clearAllRenderDebugDisplays(); // All debug displays off
+
+    if (gSavedSettings.getBOOL("DisableAllRenderTypes"))
+    {
+        clearAllRenderTypes();
+    }
+    else if (gNonInteractive)
+    {
+        clearAllRenderTypes();
+    }
+    else
+    {
+        setAllRenderTypes(); // By default, all rendering types start enabled
+    }
+
+    // make sure RenderPerformanceTest persists (hackity hack hack)
+    // disables non-object rendering (UI, sky, water, etc)
+    if (gSavedSettings.getBOOL("RenderPerformanceTest"))
+    {
+        gSavedSettings.setBOOL("RenderPerformanceTest", FALSE);
+        gSavedSettings.setBOOL("RenderPerformanceTest", TRUE);
+    }
+
+    mOldRenderDebugMask = mRenderDebugMask;
+
+    mBackfaceCull = true;
+
+    // Enable features
+    LLViewerShaderMgr::instance()->setShaders();
+
+    for (U32 i = 0; i < 2; ++i)
+    {
+        mSpotLightFade[i] = 1.f;
+    }
+
+    if (mCubeVB.isNull())
+    {
+        mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX);
+    }
+
+    mDeferredVB = new LLVertexBuffer(DEFERRED_VB_MASK);
+    mDeferredVB->allocateBuffer(8, 0);
 
     {
         mScreenTriangleVB = new LLVertexBuffer(LLVertexBuffer::MAP_VERTEX);
@@ -500,86 +500,86 @@ void LLPipeline::init()
         mScreenTriangleVB->unmapBuffer();
     }
 
-	//
-	// Update all settings to trigger a cached settings refresh
-	//
-	connectRefreshCachedSettingsSafe("RenderAutoMaskAlphaDeferred");
-	connectRefreshCachedSettingsSafe("RenderAutoMaskAlphaNonDeferred");
-	connectRefreshCachedSettingsSafe("RenderUseFarClip");
-	connectRefreshCachedSettingsSafe("RenderAvatarMaxNonImpostors");
-	connectRefreshCachedSettingsSafe("UseOcclusion");
-	// DEPRECATED -- connectRefreshCachedSettingsSafe("WindLightUseAtmosShaders");
-	// DEPRECATED -- connectRefreshCachedSettingsSafe("RenderDeferred");
-	connectRefreshCachedSettingsSafe("RenderDeferredSunWash");
-	connectRefreshCachedSettingsSafe("RenderFSAASamples");
-	connectRefreshCachedSettingsSafe("RenderResolutionDivisor");
+    //
+    // Update all settings to trigger a cached settings refresh
+    //
+    connectRefreshCachedSettingsSafe("RenderAutoMaskAlphaDeferred");
+    connectRefreshCachedSettingsSafe("RenderAutoMaskAlphaNonDeferred");
+    connectRefreshCachedSettingsSafe("RenderUseFarClip");
+    connectRefreshCachedSettingsSafe("RenderAvatarMaxNonImpostors");
+    connectRefreshCachedSettingsSafe("UseOcclusion");
+    // DEPRECATED -- connectRefreshCachedSettingsSafe("WindLightUseAtmosShaders");
+    // DEPRECATED -- connectRefreshCachedSettingsSafe("RenderDeferred");
+    connectRefreshCachedSettingsSafe("RenderDeferredSunWash");
+    connectRefreshCachedSettingsSafe("RenderFSAASamples");
+    connectRefreshCachedSettingsSafe("RenderResolutionDivisor");
 // [SL:KB] - Patch: Settings-RenderResolutionMultiplier | Checked: Catznip-5.4
-	connectRefreshCachedSettingsSafe("RenderResolutionMultiplier");
+    connectRefreshCachedSettingsSafe("RenderResolutionMultiplier");
 // [/SL:KB]
-	connectRefreshCachedSettingsSafe("RenderUIBuffer");
-	connectRefreshCachedSettingsSafe("RenderShadowDetail");
+    connectRefreshCachedSettingsSafe("RenderUIBuffer");
+    connectRefreshCachedSettingsSafe("RenderShadowDetail");
     connectRefreshCachedSettingsSafe("RenderShadowSplits");
-	connectRefreshCachedSettingsSafe("RenderDeferredSSAO");
-	connectRefreshCachedSettingsSafe("RenderShadowResolutionScale");
-	connectRefreshCachedSettingsSafe("RenderDelayCreation");
-	connectRefreshCachedSettingsSafe("FreezeTime");
-	connectRefreshCachedSettingsSafe("DebugBeaconLineWidth");
-	connectRefreshCachedSettingsSafe("RenderHighlightBrightness");
-	connectRefreshCachedSettingsSafe("RenderHighlightColor");
-	connectRefreshCachedSettingsSafe("RenderHighlightThickness");
-	connectRefreshCachedSettingsSafe("RenderSpotLightsInNondeferred");
-	connectRefreshCachedSettingsSafe("PreviewAmbientColor");
-	connectRefreshCachedSettingsSafe("PreviewDiffuse0");
-	connectRefreshCachedSettingsSafe("PreviewSpecular0");
-	connectRefreshCachedSettingsSafe("PreviewDiffuse1");
-	connectRefreshCachedSettingsSafe("PreviewSpecular1");
-	connectRefreshCachedSettingsSafe("PreviewDiffuse2");
-	connectRefreshCachedSettingsSafe("PreviewSpecular2");
-	connectRefreshCachedSettingsSafe("PreviewDirection0");
-	connectRefreshCachedSettingsSafe("PreviewDirection1");
-	connectRefreshCachedSettingsSafe("PreviewDirection2");
-	connectRefreshCachedSettingsSafe("RenderGlowMaxExtractAlpha");
-	connectRefreshCachedSettingsSafe("RenderGlowWarmthAmount");
-	connectRefreshCachedSettingsSafe("RenderGlowLumWeights");
-	connectRefreshCachedSettingsSafe("RenderGlowWarmthWeights");
-	connectRefreshCachedSettingsSafe("RenderGlowResolutionPow");
-	connectRefreshCachedSettingsSafe("RenderGlowIterations");
-	connectRefreshCachedSettingsSafe("RenderGlowWidth");
-	connectRefreshCachedSettingsSafe("RenderGlowStrength");
-	connectRefreshCachedSettingsSafe("RenderGlowNoise");
-	connectRefreshCachedSettingsSafe("RenderDepthOfField");
-	connectRefreshCachedSettingsSafe("RenderDepthOfFieldInEditMode");
-	connectRefreshCachedSettingsSafe("CameraFocusTransitionTime");
-	connectRefreshCachedSettingsSafe("CameraFNumber");
-	connectRefreshCachedSettingsSafe("CameraFocalLength");
-	connectRefreshCachedSettingsSafe("CameraFieldOfView");
-	connectRefreshCachedSettingsSafe("RenderShadowNoise");
-	connectRefreshCachedSettingsSafe("RenderShadowBlurSize");
-	connectRefreshCachedSettingsSafe("RenderSSAOScale");
-	connectRefreshCachedSettingsSafe("RenderSSAOMaxScale");
-	connectRefreshCachedSettingsSafe("RenderSSAOFactor");
-	connectRefreshCachedSettingsSafe("RenderSSAOEffectValue");
-	connectRefreshCachedSettingsSafe("RenderSSAOEffectSat");
-	connectRefreshCachedSettingsSafe("RenderShadowOffsetError");
-	connectRefreshCachedSettingsSafe("RenderShadowBiasError");
-	connectRefreshCachedSettingsSafe("RenderShadowOffset");
-	connectRefreshCachedSettingsSafe("RenderShadowBias");
-	connectRefreshCachedSettingsSafe("RenderSpotShadowOffset");
-	connectRefreshCachedSettingsSafe("RenderSpotShadowBias");
-	connectRefreshCachedSettingsSafe("RenderEdgeDepthCutoff");
-	connectRefreshCachedSettingsSafe("RenderEdgeNormCutoff");
-	connectRefreshCachedSettingsSafe("RenderShadowGaussian");
-	connectRefreshCachedSettingsSafe("RenderShadowBlurDistFactor");
-	connectRefreshCachedSettingsSafe("RenderDeferredAtmospheric");
-	connectRefreshCachedSettingsSafe("RenderHighlightFadeTime");
-	connectRefreshCachedSettingsSafe("RenderFarClip");
-	connectRefreshCachedSettingsSafe("RenderShadowSplitExponent");
-	connectRefreshCachedSettingsSafe("RenderShadowErrorCutoff");
-	connectRefreshCachedSettingsSafe("RenderShadowFOVCutoff");
-	connectRefreshCachedSettingsSafe("CameraOffset");
-	connectRefreshCachedSettingsSafe("CameraMaxCoF");
-	connectRefreshCachedSettingsSafe("CameraDoFResScale");
-	connectRefreshCachedSettingsSafe("RenderAutoHideSurfaceAreaLimit");
+    connectRefreshCachedSettingsSafe("RenderDeferredSSAO");
+    connectRefreshCachedSettingsSafe("RenderShadowResolutionScale");
+    connectRefreshCachedSettingsSafe("RenderDelayCreation");
+    connectRefreshCachedSettingsSafe("FreezeTime");
+    connectRefreshCachedSettingsSafe("DebugBeaconLineWidth");
+    connectRefreshCachedSettingsSafe("RenderHighlightBrightness");
+    connectRefreshCachedSettingsSafe("RenderHighlightColor");
+    connectRefreshCachedSettingsSafe("RenderHighlightThickness");
+    connectRefreshCachedSettingsSafe("RenderSpotLightsInNondeferred");
+    connectRefreshCachedSettingsSafe("PreviewAmbientColor");
+    connectRefreshCachedSettingsSafe("PreviewDiffuse0");
+    connectRefreshCachedSettingsSafe("PreviewSpecular0");
+    connectRefreshCachedSettingsSafe("PreviewDiffuse1");
+    connectRefreshCachedSettingsSafe("PreviewSpecular1");
+    connectRefreshCachedSettingsSafe("PreviewDiffuse2");
+    connectRefreshCachedSettingsSafe("PreviewSpecular2");
+    connectRefreshCachedSettingsSafe("PreviewDirection0");
+    connectRefreshCachedSettingsSafe("PreviewDirection1");
+    connectRefreshCachedSettingsSafe("PreviewDirection2");
+    connectRefreshCachedSettingsSafe("RenderGlowMaxExtractAlpha");
+    connectRefreshCachedSettingsSafe("RenderGlowWarmthAmount");
+    connectRefreshCachedSettingsSafe("RenderGlowLumWeights");
+    connectRefreshCachedSettingsSafe("RenderGlowWarmthWeights");
+    connectRefreshCachedSettingsSafe("RenderGlowResolutionPow");
+    connectRefreshCachedSettingsSafe("RenderGlowIterations");
+    connectRefreshCachedSettingsSafe("RenderGlowWidth");
+    connectRefreshCachedSettingsSafe("RenderGlowStrength");
+    connectRefreshCachedSettingsSafe("RenderGlowNoise");
+    connectRefreshCachedSettingsSafe("RenderDepthOfField");
+    connectRefreshCachedSettingsSafe("RenderDepthOfFieldInEditMode");
+    connectRefreshCachedSettingsSafe("CameraFocusTransitionTime");
+    connectRefreshCachedSettingsSafe("CameraFNumber");
+    connectRefreshCachedSettingsSafe("CameraFocalLength");
+    connectRefreshCachedSettingsSafe("CameraFieldOfView");
+    connectRefreshCachedSettingsSafe("RenderShadowNoise");
+    connectRefreshCachedSettingsSafe("RenderShadowBlurSize");
+    connectRefreshCachedSettingsSafe("RenderSSAOScale");
+    connectRefreshCachedSettingsSafe("RenderSSAOMaxScale");
+    connectRefreshCachedSettingsSafe("RenderSSAOFactor");
+    connectRefreshCachedSettingsSafe("RenderSSAOEffectValue");
+    connectRefreshCachedSettingsSafe("RenderSSAOEffectSat");
+    connectRefreshCachedSettingsSafe("RenderShadowOffsetError");
+    connectRefreshCachedSettingsSafe("RenderShadowBiasError");
+    connectRefreshCachedSettingsSafe("RenderShadowOffset");
+    connectRefreshCachedSettingsSafe("RenderShadowBias");
+    connectRefreshCachedSettingsSafe("RenderSpotShadowOffset");
+    connectRefreshCachedSettingsSafe("RenderSpotShadowBias");
+    connectRefreshCachedSettingsSafe("RenderEdgeDepthCutoff");
+    connectRefreshCachedSettingsSafe("RenderEdgeNormCutoff");
+    connectRefreshCachedSettingsSafe("RenderShadowGaussian");
+    connectRefreshCachedSettingsSafe("RenderShadowBlurDistFactor");
+    connectRefreshCachedSettingsSafe("RenderDeferredAtmospheric");
+    connectRefreshCachedSettingsSafe("RenderHighlightFadeTime");
+    connectRefreshCachedSettingsSafe("RenderFarClip");
+    connectRefreshCachedSettingsSafe("RenderShadowSplitExponent");
+    connectRefreshCachedSettingsSafe("RenderShadowErrorCutoff");
+    connectRefreshCachedSettingsSafe("RenderShadowFOVCutoff");
+    connectRefreshCachedSettingsSafe("CameraOffset");
+    connectRefreshCachedSettingsSafe("CameraMaxCoF");
+    connectRefreshCachedSettingsSafe("CameraDoFResScale");
+    connectRefreshCachedSettingsSafe("RenderAutoHideSurfaceAreaLimit");
     connectRefreshCachedSettingsSafe("RenderScreenSpaceReflections");
     connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionIterations");
     connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionRayStep");
@@ -587,16 +587,16 @@ void LLPipeline::init()
     connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionDepthRejectBias");
     connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionAdaptiveStepMultiplier");
     connectRefreshCachedSettingsSafe("RenderScreenSpaceReflectionGlossySamples");
-	connectRefreshCachedSettingsSafe("RenderBufferVisualization");
+    connectRefreshCachedSettingsSafe("RenderBufferVisualization");
     connectRefreshCachedSettingsSafe("RenderMirrors");
     connectRefreshCachedSettingsSafe("RenderHeroProbeUpdateRate");
     connectRefreshCachedSettingsSafe("RenderHeroProbeConservativeUpdateMultiplier");
-	connectRefreshCachedSettingsSafe("RenderNormalMapScale");
-	connectRefreshCachedSettingsSafe("RenderAttachedLights");
-	connectRefreshCachedSettingsSafe("RenderAttachedParticles");
-	connectRefreshCachedSettingsSafe("RenderFocusPointLocked");
-	connectRefreshCachedSettingsSafe("RenderFocusPointFollowsPointer");
-	connectRefreshCachedSettingsSafe("RenderDepthOfFieldNearBlur");
+    connectRefreshCachedSettingsSafe("RenderNormalMapScale");
+    connectRefreshCachedSettingsSafe("RenderAttachedLights");
+    connectRefreshCachedSettingsSafe("RenderAttachedParticles");
+    connectRefreshCachedSettingsSafe("RenderFocusPointLocked");
+    connectRefreshCachedSettingsSafe("RenderFocusPointFollowsPointer");
+    connectRefreshCachedSettingsSafe("RenderDepthOfFieldNearBlur");
 }
 
 LLPipeline::~LLPipeline()
@@ -605,82 +605,82 @@ LLPipeline::~LLPipeline()
 
 void LLPipeline::cleanup()
 {
-	assertInitialized();
+    assertInitialized();
 
-	mGroupQ1.clear() ;
+    mGroupQ1.clear() ;
     mGroupSaveQ1.clear();
     mMeshDirtyGroup.clear();
 
-	for(pool_set_t::iterator iter = mPools.begin();
-		iter != mPools.end(); )
-	{
-		pool_set_t::iterator curiter = iter++;
-		LLDrawPool* poolp = *curiter;
-		if (poolp->isFacePool())
-		{
-			LLFacePool* face_pool = (LLFacePool*) poolp;
-			if (face_pool->mReferences.empty())
-			{
-				mPools.erase(curiter);
-				removeFromQuickLookup( poolp );
-				delete poolp;
-			}
-		}
-		else
-		{
-			mPools.erase(curiter);
-			removeFromQuickLookup( poolp );
-			delete poolp;
-		}
-	}
-	
-	if (!mTerrainPools.empty())
-	{
-		LL_WARNS() << "Terrain Pools not cleaned up" << LL_ENDL;
-	}
-	if (!mTreePools.empty())
-	{
-		LL_WARNS() << "Tree Pools not cleaned up" << LL_ENDL;
-	}
-		
-	delete mAlphaPoolPreWater;
+    for(pool_set_t::iterator iter = mPools.begin();
+        iter != mPools.end(); )
+    {
+        pool_set_t::iterator curiter = iter++;
+        LLDrawPool* poolp = *curiter;
+        if (poolp->isFacePool())
+        {
+            LLFacePool* face_pool = (LLFacePool*) poolp;
+            if (face_pool->mReferences.empty())
+            {
+                mPools.erase(curiter);
+                removeFromQuickLookup( poolp );
+                delete poolp;
+            }
+        }
+        else
+        {
+            mPools.erase(curiter);
+            removeFromQuickLookup( poolp );
+            delete poolp;
+        }
+    }
+
+    if (!mTerrainPools.empty())
+    {
+        LL_WARNS() << "Terrain Pools not cleaned up" << LL_ENDL;
+    }
+    if (!mTreePools.empty())
+    {
+        LL_WARNS() << "Tree Pools not cleaned up" << LL_ENDL;
+    }
+
+    delete mAlphaPoolPreWater;
     mAlphaPoolPreWater = nullptr;
     delete mAlphaPoolPostWater;
     mAlphaPoolPostWater = nullptr;
-	delete mSkyPool;
-	mSkyPool = NULL;
-	delete mTerrainPool;
-	mTerrainPool = NULL;
-	delete mWaterPool;
-	mWaterPool = NULL;
-	delete mSimplePool;
-	mSimplePool = NULL;
-	delete mFullbrightPool;
-	mFullbrightPool = NULL;
-	delete mGlowPool;
-	mGlowPool = NULL;
-	delete mBumpPool;
-	mBumpPool = NULL;
-	// don't delete wl sky pool it was handled above in the for loop
-	//delete mWLSkyPool;
-	mWLSkyPool = NULL;
-
-	releaseGLBuffers();
-
-	mFaceSelectImagep = NULL;
+    delete mSkyPool;
+    mSkyPool = NULL;
+    delete mTerrainPool;
+    mTerrainPool = NULL;
+    delete mWaterPool;
+    mWaterPool = NULL;
+    delete mSimplePool;
+    mSimplePool = NULL;
+    delete mFullbrightPool;
+    mFullbrightPool = NULL;
+    delete mGlowPool;
+    mGlowPool = NULL;
+    delete mBumpPool;
+    mBumpPool = NULL;
+    // don't delete wl sky pool it was handled above in the for loop
+    //delete mWLSkyPool;
+    mWLSkyPool = NULL;
+
+    releaseGLBuffers();
+
+    mFaceSelectImagep = NULL;
 
     mMovedList.clear();
     mMovedBridge.clear();
     mShiftList.clear();
 
-	mInitialized = false;
+    mInitialized = false;
 
-	mDeferredVB = NULL;
+    mDeferredVB = NULL;
     mScreenTriangleVB = nullptr;
 
-	mCubeVB = NULL;
+    mCubeVB = NULL;
 
-	mALRenderUtil.reset();
+    mALRenderUtil.reset();
 
     mReflectionMapManager.cleanup();
     mHeroProbeManager.cleanup();
@@ -688,21 +688,21 @@ void LLPipeline::cleanup()
 
 //============================================================================
 
-void LLPipeline::destroyGL() 
+void LLPipeline::destroyGL()
 {
-	stop_glerror();
-	unloadShaders();
-	mHighlightFaces.clear();
-	
-	resetDrawOrders();
+    stop_glerror();
+    unloadShaders();
+    mHighlightFaces.clear();
 
-	releaseGLBuffers();
+    resetDrawOrders();
 
-	if (mMeshDirtyQueryObject)
-	{
-		glDeleteQueries(1, &mMeshDirtyQueryObject);
-		mMeshDirtyQueryObject = 0;
-	}
+    releaseGLBuffers();
+
+    if (mMeshDirtyQueryObject)
+    {
+        glDeleteQueries(1, &mMeshDirtyQueryObject);
+        mMeshDirtyQueryObject = 0;
+    }
 }
 
 void LLPipeline::requestResizeScreenTexture()
@@ -725,108 +725,108 @@ void LLPipeline::resizeShadowTexture()
 
 void LLPipeline::resizeScreenTexture()
 {
-	if (gPipeline.shadersLoaded())
-	{
-		GLuint resX = gViewerWindow->getWorldViewWidthRaw();
-		GLuint resY = gViewerWindow->getWorldViewHeightRaw();
-	
+    if (gPipeline.shadersLoaded())
+    {
+        GLuint resX = gViewerWindow->getWorldViewWidthRaw();
+        GLuint resY = gViewerWindow->getWorldViewHeightRaw();
+
 // [SL:KB] - Patch: Settings-RenderResolutionMultiplier | Checked: Catznip-5.4
-		GLuint scaledResX = resX;
-		GLuint scaledResY = resY;
-		if ( (RenderResolutionDivisor > 1) && (RenderResolutionDivisor < resX) && (RenderResolutionDivisor < resY) )
-		{
-			scaledResX /= RenderResolutionDivisor;
-			scaledResY /= RenderResolutionDivisor;
-		}
-		else if (RenderResolutionMultiplier != 1.f)
-		{
-			scaledResX *= RenderResolutionMultiplier;
-			scaledResY *= RenderResolutionMultiplier;
-		}
+        GLuint scaledResX = resX;
+        GLuint scaledResY = resY;
+        if ( (RenderResolutionDivisor > 1) && (RenderResolutionDivisor < resX) && (RenderResolutionDivisor < resY) )
+        {
+            scaledResX /= RenderResolutionDivisor;
+            scaledResY /= RenderResolutionDivisor;
+        }
+        else if (RenderResolutionMultiplier != 1.f)
+        {
+            scaledResX *= RenderResolutionMultiplier;
+            scaledResY *= RenderResolutionMultiplier;
+        }
 // [/SL:KB]
 
-//		if (gResizeScreenTexture || (resX != mRT->screen.getWidth()) || (resY != mRT->screen.getHeight()))
+//      if (gResizeScreenTexture || (resX != mRT->screen.getWidth()) || (resY != mRT->screen.getHeight()))
 // [SL:KB] - Patch: Settings-RenderResolutionMultiplier | Checked: Catznip-5.4
-		if (gResizeScreenTexture || (scaledResX != mRT->screen.getWidth()) || (scaledResY != mRT->screen.getHeight()))
+        if (gResizeScreenTexture || (scaledResX != mRT->screen.getWidth()) || (scaledResY != mRT->screen.getHeight()))
 // [/SL:KB]
-		{
-			releaseScreenBuffers();
+        {
+            releaseScreenBuffers();
             releaseSunShadowTargets();
             releaseSpotShadowTargets();
-		    allocateScreenBuffer(resX,resY);
+            allocateScreenBuffer(resX,resY);
             gResizeScreenTexture = FALSE;
-		}
-	}
+        }
+    }
 }
 
 bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
-	eFBOStatus ret = doAllocateScreenBuffer(resX, resY);
+    eFBOStatus ret = doAllocateScreenBuffer(resX, resY);
 
-	return ret == FBO_SUCCESS_FULLRES;
+    return ret == FBO_SUCCESS_FULLRES;
 }
 
 
 LLPipeline::eFBOStatus LLPipeline::doAllocateScreenBuffer(U32 resX, U32 resY)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
-	// try to allocate screen buffers at requested resolution and samples
-	// - on failure, shrink number of samples and try again
-	// - if not multisampled, shrink resolution and try again (favor X resolution over Y)
-	// Make sure to call "releaseScreenBuffers" after each failure to cleanup the partially loaded state
+    // try to allocate screen buffers at requested resolution and samples
+    // - on failure, shrink number of samples and try again
+    // - if not multisampled, shrink resolution and try again (favor X resolution over Y)
+    // Make sure to call "releaseScreenBuffers" after each failure to cleanup the partially loaded state
 
     // refresh cached settings here to protect against inconsistent event handling order
     refreshCachedSettings();
 
-	U32 samples = RenderFSAASamples;
-
-	eFBOStatus ret = FBO_SUCCESS_FULLRES;
-	if (!allocateScreenBuffer(resX, resY, samples))
-	{
-		//failed to allocate at requested specification, return false
-		ret = FBO_FAILURE;
-
-		releaseScreenBuffers();
-		releaseShadowBuffers();
-		//reduce number of samples 
-		while (samples > 0)
-		{
-			samples /= 2;
-			if (allocateScreenBuffer(resX, resY, samples))
-			{ //success
-				return FBO_SUCCESS_LOWRES;
-			}
-			releaseScreenBuffers();
+    U32 samples = RenderFSAASamples;
+
+    eFBOStatus ret = FBO_SUCCESS_FULLRES;
+    if (!allocateScreenBuffer(resX, resY, samples))
+    {
+        //failed to allocate at requested specification, return false
+        ret = FBO_FAILURE;
+
+        releaseScreenBuffers();
+        releaseShadowBuffers();
+        //reduce number of samples
+        while (samples > 0)
+        {
+            samples /= 2;
+            if (allocateScreenBuffer(resX, resY, samples))
+            { //success
+                return FBO_SUCCESS_LOWRES;
+            }
+            releaseScreenBuffers();
             releaseShadowBuffers();
-		}
-
-		samples = 0;
-
-		//reduce resolution
-		while (resY > 0 && resX > 0)
-		{
-			resY /= 2;
-			if (allocateScreenBuffer(resX, resY, samples))
-			{
-				return FBO_SUCCESS_LOWRES;
-			}
-			releaseScreenBuffers();
+        }
+
+        samples = 0;
+
+        //reduce resolution
+        while (resY > 0 && resX > 0)
+        {
+            resY /= 2;
+            if (allocateScreenBuffer(resX, resY, samples))
+            {
+                return FBO_SUCCESS_LOWRES;
+            }
+            releaseScreenBuffers();
             releaseShadowBuffers();
 
-			resX /= 2;
-			if (allocateScreenBuffer(resX, resY, samples))
-			{
-				return FBO_SUCCESS_LOWRES;
-			}
-			releaseScreenBuffers();
+            resX /= 2;
+            if (allocateScreenBuffer(resX, resY, samples))
+            {
+                return FBO_SUCCESS_LOWRES;
+            }
+            releaseScreenBuffers();
             releaseShadowBuffers();
-		}
+        }
 
-		LL_WARNS() << "Unable to allocate screen buffer at any resolution!" << LL_ENDL;
-	}
+        LL_WARNS() << "Unable to allocate screen buffer at any resolution!" << LL_ENDL;
+    }
 
-	return ret;
+    return ret;
 }
 
 bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
@@ -843,7 +843,7 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
         U32 res = mReflectionMapManager.mProbeResolution * 4;  //multiply by 4 because probes will be 16x super sampled
         allocateScreenBuffer(res, res, samples);
 
-		if (RenderMirrors)
+        if (RenderMirrors)
         {
             mHeroProbeManager.initReflectionMaps();
             res = mHeroProbeManager.mProbeResolution;  // We also scale the hero probe RT to the probe res since we don't super sample it.
@@ -855,74 +855,74 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
         gCubeSnapshot = FALSE;
     }
 
-	if(!gCubeSnapshot)
-	{
-		U32 res_mod = RenderResolutionDivisor;
-
-		if (res_mod > 1 && res_mod < resX && res_mod < resY)
-		{
-			resX /= res_mod;
-			resY /= res_mod;
-		}
-		// [SL:KB] - Patch: Settings-RenderResolutionMultiplier | Checked: Catznip-5.4
-		else if (RenderResolutionMultiplier != 1.f)
-		{
-			resX *= RenderResolutionMultiplier;
-			resY *= RenderResolutionMultiplier;
-		}
-		// [/SL:KB]
-
-			// remember these dimensions
-		mRT->width = resX;
-		mRT->height = resY;
-
-		if (RenderUIBuffer)
-		{
-			if (!mRT->uiScreen.allocate(resX, resY, GL_RGBA))
-			{
-				return false;
-			}
-		}
-	}
-
-	//S32 shadow_detail = RenderShadowDetail;
-	//bool ssao = RenderDeferredSSAO;
-		
-	//allocate deferred rendering color buffers
-	if (!mRT->deferredScreen.allocate(resX, resY, GL_RGBA, true)) return false;
-	if (!addDeferredAttachments(mRT->deferredScreen)) return false;
-	
-	GLuint screenFormat = GL_RGBA16F;
-        
-	if (!mRT->screen.allocate(resX, resY, screenFormat)) return false;
+    if(!gCubeSnapshot)
+    {
+        U32 res_mod = RenderResolutionDivisor;
+
+        if (res_mod > 1 && res_mod < resX && res_mod < resY)
+        {
+            resX /= res_mod;
+            resY /= res_mod;
+        }
+        // [SL:KB] - Patch: Settings-RenderResolutionMultiplier | Checked: Catznip-5.4
+        else if (RenderResolutionMultiplier != 1.f)
+        {
+            resX *= RenderResolutionMultiplier;
+            resY *= RenderResolutionMultiplier;
+        }
+        // [/SL:KB]
+
+            // remember these dimensions
+        mRT->width = resX;
+        mRT->height = resY;
+
+        if (RenderUIBuffer)
+        {
+            if (!mRT->uiScreen.allocate(resX, resY, GL_RGBA))
+            {
+                return false;
+            }
+        }
+    }
+
+    //S32 shadow_detail = RenderShadowDetail;
+    //bool ssao = RenderDeferredSSAO;
+
+    //allocate deferred rendering color buffers
+    if (!mRT->deferredScreen.allocate(resX, resY, GL_RGBA, true)) return false;
+    if (!addDeferredAttachments(mRT->deferredScreen)) return false;
+
+    GLuint screenFormat = GL_RGBA16F;
+
+    if (!mRT->screen.allocate(resX, resY, screenFormat)) return false;
 
     mRT->deferredScreen.shareDepthBuffer(mRT->screen);
 
-	if (!mRT->deferredLight.allocate(resX, resY, screenFormat)) return false;
+    if (!mRT->deferredLight.allocate(resX, resY, screenFormat)) return false;
 
     allocateShadowBuffer(resX, resY);
 
-	if (!gCubeSnapshot)
-	{
-		//water reflection texture (always needed as scratch space whether or not transparent water is enabled)
-		if (!mWaterDis.allocate(resX, resY, GL_RGBA16F, true)) return false;
+    if (!gCubeSnapshot)
+    {
+        //water reflection texture (always needed as scratch space whether or not transparent water is enabled)
+        if (!mWaterDis.allocate(resX, resY, GL_RGBA16F, true)) return false;
 
-		if (!mSceneMap.allocate(resX, resY, GL_RGB16F, true)) return false;
+        if (!mSceneMap.allocate(resX, resY, GL_RGB16F, true)) return false;
 
-		if (!mPostMap.allocate(resX, resY, GL_RGBA)) return false;
-		if (!mPostFXMap.allocate(resX, resY, GL_RGBA)) return false;
-//		if (RenderDepthOfField || samples > 0)
+        if (!mPostMap.allocate(resX, resY, GL_RGBA)) return false;
+        if (!mPostFXMap.allocate(resX, resY, GL_RGBA)) return false;
+//      if (RenderDepthOfField || samples > 0)
 // [RLVa:KB] - @setsphere
-		if (RenderDepthOfField || samples > 0 || RlvActions::hasPostProcess())
+        if (RenderDepthOfField || samples > 0 || RlvActions::hasPostProcess())
 // [/RLVa:KB]
-		{ //only need mPostHelperMap for dof OR fxaa
-			if (!mPostHelperMap.allocate(resX, resY, GL_RGBA)) return false;
-		}
-		else
-		{
-			mPostHelperMap.release();
-		}
-	}
+        { //only need mPostHelperMap for dof OR fxaa
+            if (!mPostHelperMap.allocate(resX, resY, GL_RGBA)) return false;
+        }
+        else
+        {
+            mPostHelperMap.release();
+        }
+    }
     //HACK make screenbuffer allocations start failing after 30 seconds
     if (gSavedSettings.getBOOL("SimulateFBOFailure"))
     {
@@ -931,9 +931,9 @@ bool LLPipeline::allocateScreenBuffer(U32 resX, U32 resY, U32 samples)
 
     gGL.getTexUnit(0)->disable();
 
-	stop_glerror();
+    stop_glerror();
 
-	return true;
+    return true;
 }
 
 // must be even to avoid a stripe in the horizontal shadow blur
@@ -992,7 +992,7 @@ bool LLPipeline::allocateShadowBuffer(U32 resX, U32 resY)
 
     // set up shadow map filtering and compare modes
     if (shadow_detail > 0)
-    { 
+    {
         for (U32 i = 0; i < 4; i++)
         {
             LLRenderTarget* shadow_target = getSunShadowTarget(i);
@@ -1025,7 +1025,7 @@ bool LLPipeline::allocateShadowBuffer(U32 resX, U32 resY)
         }
     }
 
-	return true;
+    return true;
 }
 
 //static
@@ -1038,93 +1038,93 @@ void LLPipeline::updateRenderTransparentWater()
 void LLPipeline::refreshCachedSettings()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_DISPLAY;
-	LLPipeline::sAutoMaskAlphaDeferred = gSavedSettings.getBOOL("RenderAutoMaskAlphaDeferred");
-	LLPipeline::sAutoMaskAlphaNonDeferred = gSavedSettings.getBOOL("RenderAutoMaskAlphaNonDeferred");
-	LLPipeline::sUseFarClip = gSavedSettings.getBOOL("RenderUseFarClip");
-	LLVOAvatar::sMaxNonImpostors = gSavedSettings.getU32("RenderAvatarMaxNonImpostors");
-	LLVOAvatar::updateImpostorRendering(LLVOAvatar::sMaxNonImpostors);
-	LLPipeline::sRenderAttachedLights = gSavedSettings.getBOOL("RenderAttachedLights");
-	LLPipeline::sRenderAttachedParticles = gSavedSettings.getBOOL("RenderAttachedParticles");
-
-	LLPipeline::sUseOcclusion = 
-			(!gUseWireframe
-			&& LLFeatureManager::getInstance()->isFeatureAvailable("UseOcclusion")
-			&& gSavedSettings.getBOOL("UseOcclusion")) ? 2 : 0;
-	
+    LLPipeline::sAutoMaskAlphaDeferred = gSavedSettings.getBOOL("RenderAutoMaskAlphaDeferred");
+    LLPipeline::sAutoMaskAlphaNonDeferred = gSavedSettings.getBOOL("RenderAutoMaskAlphaNonDeferred");
+    LLPipeline::sUseFarClip = gSavedSettings.getBOOL("RenderUseFarClip");
+    LLVOAvatar::sMaxNonImpostors = gSavedSettings.getU32("RenderAvatarMaxNonImpostors");
+    LLVOAvatar::updateImpostorRendering(LLVOAvatar::sMaxNonImpostors);
+    LLPipeline::sRenderAttachedLights = gSavedSettings.getBOOL("RenderAttachedLights");
+    LLPipeline::sRenderAttachedParticles = gSavedSettings.getBOOL("RenderAttachedParticles");
+
+    LLPipeline::sUseOcclusion =
+            (!gUseWireframe
+            && LLFeatureManager::getInstance()->isFeatureAvailable("UseOcclusion")
+            && gSavedSettings.getBOOL("UseOcclusion")) ? 2 : 0;
+
     WindLightUseAtmosShaders = TRUE; // DEPRECATED -- gSavedSettings.getBOOL("WindLightUseAtmosShaders");
     RenderDeferred = TRUE; // DEPRECATED -- gSavedSettings.getBOOL("RenderDeferred");
-	RenderDeferredSunWash = gSavedSettings.getF32("RenderDeferredSunWash");
-	RenderFSAASamples = LLFeatureManager::getInstance()->isFeatureAvailable("RenderFSAASamples") ? gSavedSettings.getU32("RenderFSAASamples") : 0;
-	RenderResolutionDivisor = gSavedSettings.getU32("RenderResolutionDivisor");
+    RenderDeferredSunWash = gSavedSettings.getF32("RenderDeferredSunWash");
+    RenderFSAASamples = LLFeatureManager::getInstance()->isFeatureAvailable("RenderFSAASamples") ? gSavedSettings.getU32("RenderFSAASamples") : 0;
+    RenderResolutionDivisor = gSavedSettings.getU32("RenderResolutionDivisor");
 // [SL:KB] - Patch: Settings-RenderResolutionMultiplier | Checked: Catznip-5.4
-	RenderResolutionMultiplier = gSavedSettings.getF32("RenderResolutionMultiplier");
+    RenderResolutionMultiplier = gSavedSettings.getF32("RenderResolutionMultiplier");
 // [/SL:KB]
-	RenderUIBuffer = gSavedSettings.getBOOL("RenderUIBuffer");
-	RenderShadowDetail = gSavedSettings.getS32("RenderShadowDetail");
+    RenderUIBuffer = gSavedSettings.getBOOL("RenderUIBuffer");
+    RenderShadowDetail = gSavedSettings.getS32("RenderShadowDetail");
     RenderShadowSplits = gSavedSettings.getS32("RenderShadowSplits");
-	RenderDeferredSSAO = gSavedSettings.getBOOL("RenderDeferredSSAO");
-	RenderShadowResolutionScale = gSavedSettings.getF32("RenderShadowResolutionScale");
-	RenderDelayCreation = gSavedSettings.getBOOL("RenderDelayCreation");
-	FreezeTime = gSavedSettings.getBOOL("FreezeTime");
-	DebugBeaconLineWidth = gSavedSettings.getS32("DebugBeaconLineWidth");
-	RenderHighlightBrightness = gSavedSettings.getF32("RenderHighlightBrightness");
-	RenderHighlightColor = gSavedSettings.getColor4("RenderHighlightColor");
-	RenderHighlightThickness = gSavedSettings.getF32("RenderHighlightThickness");
-	RenderSpotLightsInNondeferred = gSavedSettings.getBOOL("RenderSpotLightsInNondeferred");
-	PreviewAmbientColor = gSavedSettings.getColor4("PreviewAmbientColor");
-	PreviewDiffuse0 = gSavedSettings.getColor4("PreviewDiffuse0");
-	PreviewSpecular0 = gSavedSettings.getColor4("PreviewSpecular0");
-	PreviewDiffuse1 = gSavedSettings.getColor4("PreviewDiffuse1");
-	PreviewSpecular1 = gSavedSettings.getColor4("PreviewSpecular1");
-	PreviewDiffuse2 = gSavedSettings.getColor4("PreviewDiffuse2");
-	PreviewSpecular2 = gSavedSettings.getColor4("PreviewSpecular2");
-	PreviewDirection0 = gSavedSettings.getVector3("PreviewDirection0");
-	PreviewDirection1 = gSavedSettings.getVector3("PreviewDirection1");
-	PreviewDirection2 = gSavedSettings.getVector3("PreviewDirection2");
-	RenderGlowMaxExtractAlpha = gSavedSettings.getF32("RenderGlowMaxExtractAlpha");
-	RenderGlowWarmthAmount = gSavedSettings.getF32("RenderGlowWarmthAmount");
-	RenderGlowLumWeights = gSavedSettings.getVector3("RenderGlowLumWeights");
-	RenderGlowWarmthWeights = gSavedSettings.getVector3("RenderGlowWarmthWeights");
-	RenderGlowResolutionPow = gSavedSettings.getS32("RenderGlowResolutionPow");
-	RenderGlowIterations = gSavedSettings.getS32("RenderGlowIterations");
-	RenderGlowWidth = gSavedSettings.getF32("RenderGlowWidth");
-	RenderGlowStrength = gSavedSettings.getF32("RenderGlowStrength");
-	RenderGlowNoise = gSavedSettings.getBOOL("RenderGlowNoise");
-	RenderDepthOfField = gSavedSettings.getBOOL("RenderDepthOfField");
-	RenderDepthOfFieldInEditMode = gSavedSettings.getBOOL("RenderDepthOfFieldInEditMode");
-	RenderDepthOfFieldNearBlur = gSavedSettings.getBool("RenderDepthOfFieldNearBlur");
-	RenderFocusPointLocked = gSavedSettings.getBOOL("RenderFocusPointLocked");
-	RenderFocusPointFollowsPointer = gSavedSettings.getBOOL("RenderFocusPointFollowsPointer");
-	CameraFocusTransitionTime = gSavedSettings.getF32("CameraFocusTransitionTime");
-	CameraFNumber = gSavedSettings.getF32("CameraFNumber");
-	CameraFocalLength = gSavedSettings.getF32("CameraFocalLength");
-	CameraFieldOfView = gSavedSettings.getF32("CameraFieldOfView");
-	RenderShadowNoise = gSavedSettings.getF32("RenderShadowNoise");
-	RenderShadowBlurSize = gSavedSettings.getF32("RenderShadowBlurSize");
-	RenderSSAOScale = gSavedSettings.getF32("RenderSSAOScale");
-	RenderSSAOMaxScale = gSavedSettings.getU32("RenderSSAOMaxScale");
-	RenderSSAOFactor = gSavedSettings.getF32("RenderSSAOFactor");
-	RenderSSAOEffect = LLVector3(gSavedSettings.getF32("RenderSSAOEffectValue"), gSavedSettings.getF32("RenderSSAOEffectSat"), 0.0f);
-	RenderShadowOffsetError = gSavedSettings.getF32("RenderShadowOffsetError");
-	RenderShadowBiasError = gSavedSettings.getF32("RenderShadowBiasError");
-	RenderShadowOffset = gSavedSettings.getF32("RenderShadowOffset");
-	RenderShadowBias = gSavedSettings.getF32("RenderShadowBias");
-	RenderSpotShadowOffset = gSavedSettings.getF32("RenderSpotShadowOffset");
-	RenderSpotShadowBias = gSavedSettings.getF32("RenderSpotShadowBias");
-	RenderEdgeDepthCutoff = gSavedSettings.getF32("RenderEdgeDepthCutoff");
-	RenderEdgeNormCutoff = gSavedSettings.getF32("RenderEdgeNormCutoff");
-	RenderShadowGaussian = gSavedSettings.getVector3("RenderShadowGaussian");
-	RenderShadowBlurDistFactor = gSavedSettings.getF32("RenderShadowBlurDistFactor");
-	RenderDeferredAtmospheric = gSavedSettings.getBOOL("RenderDeferredAtmospheric");
-	RenderHighlightFadeTime = gSavedSettings.getF32("RenderHighlightFadeTime");
-	RenderFarClip = gSavedSettings.getF32("RenderFarClip");
-	RenderShadowSplitExponent = gSavedSettings.getVector3("RenderShadowSplitExponent");
-	RenderShadowErrorCutoff = gSavedSettings.getF32("RenderShadowErrorCutoff");
-	RenderShadowFOVCutoff = gSavedSettings.getF32("RenderShadowFOVCutoff");
-	CameraOffset = gSavedSettings.getBOOL("CameraOffset");
-	CameraMaxCoF = gSavedSettings.getF32("CameraMaxCoF");
-	CameraDoFResScale = gSavedSettings.getF32("CameraDoFResScale");
-	RenderAutoHideSurfaceAreaLimit = gSavedSettings.getF32("RenderAutoHideSurfaceAreaLimit");
+    RenderDeferredSSAO = gSavedSettings.getBOOL("RenderDeferredSSAO");
+    RenderShadowResolutionScale = gSavedSettings.getF32("RenderShadowResolutionScale");
+    RenderDelayCreation = gSavedSettings.getBOOL("RenderDelayCreation");
+    FreezeTime = gSavedSettings.getBOOL("FreezeTime");
+    DebugBeaconLineWidth = gSavedSettings.getS32("DebugBeaconLineWidth");
+    RenderHighlightBrightness = gSavedSettings.getF32("RenderHighlightBrightness");
+    RenderHighlightColor = gSavedSettings.getColor4("RenderHighlightColor");
+    RenderHighlightThickness = gSavedSettings.getF32("RenderHighlightThickness");
+    RenderSpotLightsInNondeferred = gSavedSettings.getBOOL("RenderSpotLightsInNondeferred");
+    PreviewAmbientColor = gSavedSettings.getColor4("PreviewAmbientColor");
+    PreviewDiffuse0 = gSavedSettings.getColor4("PreviewDiffuse0");
+    PreviewSpecular0 = gSavedSettings.getColor4("PreviewSpecular0");
+    PreviewDiffuse1 = gSavedSettings.getColor4("PreviewDiffuse1");
+    PreviewSpecular1 = gSavedSettings.getColor4("PreviewSpecular1");
+    PreviewDiffuse2 = gSavedSettings.getColor4("PreviewDiffuse2");
+    PreviewSpecular2 = gSavedSettings.getColor4("PreviewSpecular2");
+    PreviewDirection0 = gSavedSettings.getVector3("PreviewDirection0");
+    PreviewDirection1 = gSavedSettings.getVector3("PreviewDirection1");
+    PreviewDirection2 = gSavedSettings.getVector3("PreviewDirection2");
+    RenderGlowMaxExtractAlpha = gSavedSettings.getF32("RenderGlowMaxExtractAlpha");
+    RenderGlowWarmthAmount = gSavedSettings.getF32("RenderGlowWarmthAmount");
+    RenderGlowLumWeights = gSavedSettings.getVector3("RenderGlowLumWeights");
+    RenderGlowWarmthWeights = gSavedSettings.getVector3("RenderGlowWarmthWeights");
+    RenderGlowResolutionPow = gSavedSettings.getS32("RenderGlowResolutionPow");
+    RenderGlowIterations = gSavedSettings.getS32("RenderGlowIterations");
+    RenderGlowWidth = gSavedSettings.getF32("RenderGlowWidth");
+    RenderGlowStrength = gSavedSettings.getF32("RenderGlowStrength");
+    RenderGlowNoise = gSavedSettings.getBOOL("RenderGlowNoise");
+    RenderDepthOfField = gSavedSettings.getBOOL("RenderDepthOfField");
+    RenderDepthOfFieldInEditMode = gSavedSettings.getBOOL("RenderDepthOfFieldInEditMode");
+    RenderDepthOfFieldNearBlur = gSavedSettings.getBool("RenderDepthOfFieldNearBlur");
+    RenderFocusPointLocked = gSavedSettings.getBOOL("RenderFocusPointLocked");
+    RenderFocusPointFollowsPointer = gSavedSettings.getBOOL("RenderFocusPointFollowsPointer");
+    CameraFocusTransitionTime = gSavedSettings.getF32("CameraFocusTransitionTime");
+    CameraFNumber = gSavedSettings.getF32("CameraFNumber");
+    CameraFocalLength = gSavedSettings.getF32("CameraFocalLength");
+    CameraFieldOfView = gSavedSettings.getF32("CameraFieldOfView");
+    RenderShadowNoise = gSavedSettings.getF32("RenderShadowNoise");
+    RenderShadowBlurSize = gSavedSettings.getF32("RenderShadowBlurSize");
+    RenderSSAOScale = gSavedSettings.getF32("RenderSSAOScale");
+    RenderSSAOMaxScale = gSavedSettings.getU32("RenderSSAOMaxScale");
+    RenderSSAOFactor = gSavedSettings.getF32("RenderSSAOFactor");
+    RenderSSAOEffect = LLVector3(gSavedSettings.getF32("RenderSSAOEffectValue"), gSavedSettings.getF32("RenderSSAOEffectSat"), 0.0f);
+    RenderShadowOffsetError = gSavedSettings.getF32("RenderShadowOffsetError");
+    RenderShadowBiasError = gSavedSettings.getF32("RenderShadowBiasError");
+    RenderShadowOffset = gSavedSettings.getF32("RenderShadowOffset");
+    RenderShadowBias = gSavedSettings.getF32("RenderShadowBias");
+    RenderSpotShadowOffset = gSavedSettings.getF32("RenderSpotShadowOffset");
+    RenderSpotShadowBias = gSavedSettings.getF32("RenderSpotShadowBias");
+    RenderEdgeDepthCutoff = gSavedSettings.getF32("RenderEdgeDepthCutoff");
+    RenderEdgeNormCutoff = gSavedSettings.getF32("RenderEdgeNormCutoff");
+    RenderShadowGaussian = gSavedSettings.getVector3("RenderShadowGaussian");
+    RenderShadowBlurDistFactor = gSavedSettings.getF32("RenderShadowBlurDistFactor");
+    RenderDeferredAtmospheric = gSavedSettings.getBOOL("RenderDeferredAtmospheric");
+    RenderHighlightFadeTime = gSavedSettings.getF32("RenderHighlightFadeTime");
+    RenderFarClip = gSavedSettings.getF32("RenderFarClip");
+    RenderShadowSplitExponent = gSavedSettings.getVector3("RenderShadowSplitExponent");
+    RenderShadowErrorCutoff = gSavedSettings.getF32("RenderShadowErrorCutoff");
+    RenderShadowFOVCutoff = gSavedSettings.getF32("RenderShadowFOVCutoff");
+    CameraOffset = gSavedSettings.getBOOL("CameraOffset");
+    CameraMaxCoF = gSavedSettings.getF32("CameraMaxCoF");
+    CameraDoFResScale = gSavedSettings.getF32("CameraDoFResScale");
+    RenderAutoHideSurfaceAreaLimit = gSavedSettings.getF32("RenderAutoHideSurfaceAreaLimit");
     RenderScreenSpaceReflections = gSavedSettings.getBOOL("RenderScreenSpaceReflections");
     RenderScreenSpaceReflectionIterations = gSavedSettings.getS32("RenderScreenSpaceReflectionIterations");
     RenderScreenSpaceReflectionRayStep = gSavedSettings.getF32("RenderScreenSpaceReflectionRayStep");
@@ -1132,7 +1132,7 @@ void LLPipeline::refreshCachedSettings()
     RenderScreenSpaceReflectionDepthRejectBias = gSavedSettings.getF32("RenderScreenSpaceReflectionDepthRejectBias");
     RenderScreenSpaceReflectionAdaptiveStepMultiplier = gSavedSettings.getF32("RenderScreenSpaceReflectionAdaptiveStepMultiplier");
     RenderScreenSpaceReflectionGlossySamples = gSavedSettings.getS32("RenderScreenSpaceReflectionGlossySamples");
-	RenderBufferVisualization = gSavedSettings.getS32("RenderBufferVisualization");
+    RenderBufferVisualization = gSavedSettings.getS32("RenderBufferVisualization");
     if (gSavedSettings.getBOOL("RenderMirrors") != (BOOL)RenderMirrors)
     {
         RenderMirrors = gSavedSettings.getBOOL("RenderMirrors");
@@ -1143,33 +1143,33 @@ void LLPipeline::refreshCachedSettings()
     RenderHeroProbeConservativeUpdateMultiplier = gSavedSettings.getS32("RenderHeroProbeConservativeUpdateMultiplier");
 
     sReflectionProbesEnabled = LLFeatureManager::getInstance()->isFeatureAvailable("RenderReflectionsEnabled") && gSavedSettings.getBOOL("RenderReflectionsEnabled");
-	RenderNormalMapScale = gSavedSettings.getF32("RenderNormalMapScale");
-	RenderSpotLight = nullptr;
+    RenderNormalMapScale = gSavedSettings.getF32("RenderNormalMapScale");
+    RenderSpotLight = nullptr;
 
-	if (gNonInteractive)
-	{
-		LLVOAvatar::sMaxNonImpostors = 1;
-		LLVOAvatar::updateImpostorRendering(LLVOAvatar::sMaxNonImpostors);
-	}
+    if (gNonInteractive)
+    {
+        LLVOAvatar::sMaxNonImpostors = 1;
+        LLVOAvatar::updateImpostorRendering(LLVOAvatar::sMaxNonImpostors);
+    }
 }
 
 void LLPipeline::releaseGLBuffers()
 {
-	assertInitialized();
-	
-	if (mNoiseMap)
-	{
-		LLImageGL::deleteTextures(1, &mNoiseMap);
-		mNoiseMap = 0;
-	}
+    assertInitialized();
+
+    if (mNoiseMap)
+    {
+        LLImageGL::deleteTextures(1, &mNoiseMap);
+        mNoiseMap = 0;
+    }
 
-	if (mTrueNoiseMap)
-	{
-		LLImageGL::deleteTextures(1, &mTrueNoiseMap);
-		mTrueNoiseMap = 0;
-	}
+    if (mTrueNoiseMap)
+    {
+        LLImageGL::deleteTextures(1, &mTrueNoiseMap);
+        mTrueNoiseMap = 0;
+    }
 
-	if (mAreaMap)
+    if (mAreaMap)
     {
         LLImageGL::deleteTextures(1, &mAreaMap);
         mAreaMap = 0;
@@ -1187,33 +1187,33 @@ void LLPipeline::releaseGLBuffers()
         mSampleMap = 0;
     }
 
-	mALRenderUtil->releaseGLBuffers();
+    mALRenderUtil->releaseGLBuffers();
 
-	releaseLUTBuffers();
+    releaseLUTBuffers();
 
     mBake.release();
-	
+
     mSceneMap.release();
 
-	for (U32 i = 0; i < 3; i++)
-	{
-		mGlow[i].release();
-	}
+    for (U32 i = 0; i < 3; i++)
+    {
+        mGlow[i].release();
+    }
 
-	releaseScreenBuffers();
-	releaseShadowBuffers();
+    releaseScreenBuffers();
+    releaseShadowBuffers();
 
-	gBumpImageList.destroyGL();
-	LLVOAvatar::resetImpostors();
+    gBumpImageList.destroyGL();
+    LLVOAvatar::resetImpostors();
 }
 
 void LLPipeline::releaseLUTBuffers()
 {
-	if (mLightFunc)
-	{
-		LLImageGL::deleteTextures(1, &mLightFunc);
-		mLightFunc = 0;
-	}
+    if (mLightFunc)
+    {
+        LLImageGL::deleteTextures(1, &mLightFunc);
+        mLightFunc = 0;
+    }
 
     mPbrBrdfLut.release();
 
@@ -1235,19 +1235,19 @@ void LLPipeline::releaseScreenBuffers()
     mRT->screen.release();
     mRT->deferredScreen.release();
     mRT->deferredLight.release();
-	mAuxillaryRT.uiScreen.release();
-	mAuxillaryRT.screen.release();
-	mAuxillaryRT.deferredScreen.release();
-	mAuxillaryRT.deferredLight.release();
-	mHeroProbeRT.uiScreen.release();
-	mHeroProbeRT.screen.release();
-	mHeroProbeRT.deferredScreen.release();
-	mHeroProbeRT.deferredLight.release();
-	mPostMap.release();
-	mPostFXMap.release();
-	mPostHelperMap.release();
-	mSceneMap.release();
-	mWaterDis.release();
+    mAuxillaryRT.uiScreen.release();
+    mAuxillaryRT.screen.release();
+    mAuxillaryRT.deferredScreen.release();
+    mAuxillaryRT.deferredLight.release();
+    mHeroProbeRT.uiScreen.release();
+    mHeroProbeRT.screen.release();
+    mHeroProbeRT.deferredScreen.release();
+    mHeroProbeRT.deferredLight.release();
+    mPostMap.release();
+    mPostFXMap.release();
+    mPostHelperMap.release();
+    mSceneMap.release();
+    mWaterDis.release();
 }
 
 void LLPipeline::releaseSunShadowTarget(U32 index)
@@ -1258,10 +1258,10 @@ void LLPipeline::releaseSunShadowTarget(U32 index)
 
 void LLPipeline::releaseSunShadowTargets()
 {
-	for (U32 i = 0; i < 4; i++)
-	{
+    for (U32 i = 0; i < 4; i++)
+    {
         releaseSunShadowTarget(i);
-	}
+    }
 }
 
 void LLPipeline::releaseSpotShadowTargets()
@@ -1279,19 +1279,19 @@ void LLPipeline::createGLBuffers()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
     stop_glerror();
-	assertInitialized();
+    assertInitialized();
 
     // Use FBO for bake tex
     mBake.allocate(1024, 1024, GL_RGBA, true); // SL-12781 Build > Upload > Model; 3D Preview
 
-	stop_glerror();
+    stop_glerror();
 
-	GLuint resX = gViewerWindow->getWorldViewWidthRaw();
-	GLuint resY = gViewerWindow->getWorldViewHeightRaw();
+    GLuint resX = gViewerWindow->getWorldViewWidthRaw();
+    GLuint resY = gViewerWindow->getWorldViewHeightRaw();
 
     // allocate screen space glow buffers
     const U32 glow_res = llmax(1, llmin(512, 1 << gSavedSettings.getS32("RenderGlowResolutionPow")));
-	const bool glow_hdr = gSavedSettings.getBOOL("RenderGlowHDR");
+    const bool glow_hdr = gSavedSettings.getBOOL("RenderGlowHDR");
     const U32 glow_color_fmt = glow_hdr ? GL_RGBA16F : GL_RGBA;
     for (U32 i = 0; i < 3; i++)
     {
@@ -1302,45 +1302,45 @@ void LLPipeline::createGLBuffers()
     //mRT->width = 0;
     //mRT->height = 0;
 
-	mALRenderUtil->refreshState();
-
-    
-	if (!mNoiseMap)
-	{
-		const U32 noiseRes = 128;
-		LLVector3 noise[noiseRes*noiseRes];
-
-		F32 scaler = gSavedSettings.getF32("RenderDeferredNoise")/100.f;
-		for (U32 i = 0; i < noiseRes*noiseRes; ++i)
-		{
-			noise[i] = LLVector3(ll_frand()-0.5f, ll_frand()-0.5f, 0.f);
-			noise[i].normVec();
-			noise[i].mV[2] = ll_frand()*scaler+1.f-scaler/2.f;
-		}
-
-		LLImageGL::generateTextures(1, &mNoiseMap);
-			
-		gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap);
-		LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F, noiseRes, noiseRes, GL_RGB, GL_FLOAT, noise, false);
-		gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
-	}
-
-	if (!mTrueNoiseMap)
-	{
-		const U32 noiseRes = 128;
-		F32 noise[noiseRes*noiseRes*3];
-		for (U32 i = 0; i < noiseRes*noiseRes*3; i++)
-		{
-			noise[i] = ll_frand()*2.0-1.0;
-		}
-
-		LLImageGL::generateTextures(1, &mTrueNoiseMap);
-		gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mTrueNoiseMap);
-		LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F, noiseRes, noiseRes, GL_RGB,GL_FLOAT, noise, false);
-		gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
-	}
-
-	if (!mAreaMap)
+    mALRenderUtil->refreshState();
+
+
+    if (!mNoiseMap)
+    {
+        const U32 noiseRes = 128;
+        LLVector3 noise[noiseRes*noiseRes];
+
+        F32 scaler = gSavedSettings.getF32("RenderDeferredNoise")/100.f;
+        for (U32 i = 0; i < noiseRes*noiseRes; ++i)
+        {
+            noise[i] = LLVector3(ll_frand()-0.5f, ll_frand()-0.5f, 0.f);
+            noise[i].normVec();
+            noise[i].mV[2] = ll_frand()*scaler+1.f-scaler/2.f;
+        }
+
+        LLImageGL::generateTextures(1, &mNoiseMap);
+
+        gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap);
+        LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F, noiseRes, noiseRes, GL_RGB, GL_FLOAT, noise, false);
+        gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
+    }
+
+    if (!mTrueNoiseMap)
+    {
+        const U32 noiseRes = 128;
+        F32 noise[noiseRes*noiseRes*3];
+        for (U32 i = 0; i < noiseRes*noiseRes*3; i++)
+        {
+            noise[i] = ll_frand()*2.0-1.0;
+        }
+
+        LLImageGL::generateTextures(1, &mTrueNoiseMap);
+        gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mTrueNoiseMap);
+        LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, GL_RGB16F, noiseRes, noiseRes, GL_RGB,GL_FLOAT, noise, false);
+        gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
+    }
+
+    if (!mAreaMap)
     {
         std::vector<unsigned char> tempBuffer(AREATEX_SIZE);
         for (unsigned int y = 0; y < AREATEX_HEIGHT; y++)
@@ -1408,61 +1408,61 @@ void LLPipeline::createGLBuffers()
             gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_BILINEAR);
             gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
         }
-	}
+    }
 
-	createLUTBuffers();
+    createLUTBuffers();
 
-	gBumpImageList.restoreGL();
+    gBumpImageList.restoreGL();
 }
 
 F32 lerpf(F32 a, F32 b, F32 w)
 {
-	return a + w * (b - a);
+    return a + w * (b - a);
 }
 
 void LLPipeline::createLUTBuffers()
 {
-	if (!mLightFunc)
-	{
-		U32 lightResX = gSavedSettings.getU32("RenderSpecularResX");
-		U32 lightResY = gSavedSettings.getU32("RenderSpecularResY");
-		F32* ls = new F32[lightResX*lightResY];
-		F32 specExp = gSavedSettings.getF32("RenderSpecularExponent");
+    if (!mLightFunc)
+    {
+        U32 lightResX = gSavedSettings.getU32("RenderSpecularResX");
+        U32 lightResY = gSavedSettings.getU32("RenderSpecularResY");
+        F32* ls = new F32[lightResX*lightResY];
+        F32 specExp = gSavedSettings.getF32("RenderSpecularExponent");
         // Calculate the (normalized) blinn-phong specular lookup texture. (with a few tweaks)
-		for (U32 y = 0; y < lightResY; ++y)
-		{
-			for (U32 x = 0; x < lightResX; ++x)
-			{
-				ls[y*lightResX+x] = 0;
-				F32 sa = (F32) x/(lightResX-1);
-				F32 spec = (F32) y/(lightResY-1);
-				F32 n = spec * spec * specExp;
-					
-				// Nothing special here.  Just your typical blinn-phong term.
-				spec = powf(sa, n);
-					
-				// Apply our normalization function.
-				// Note: This is the full equation that applies the full normalization curve, not an approximation.
-				// This is fine, given we only need to create our LUT once per buffer initialization.
-				spec *= (((n + 2) * (n + 4)) / (8 * F_PI * (powf(2, -n/2) + n)));
-
-				// Since we use R16F, we no longer have a dynamic range issue we need to work around here.
-				// Though some older drivers may not like this, newer drivers shouldn't have this problem.
-				ls[y*lightResX+x] = spec;
-			}
-		}
-			
-		U32 pix_format = GL_R16F;
-		LLImageGL::generateTextures(1, &mLightFunc);
-		gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc);
-		LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, pix_format, lightResX, lightResY, GL_RED, GL_FLOAT, ls, false);
-		gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
-		gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-			
-		delete [] ls;
-	}
+        for (U32 y = 0; y < lightResY; ++y)
+        {
+            for (U32 x = 0; x < lightResX; ++x)
+            {
+                ls[y*lightResX+x] = 0;
+                F32 sa = (F32) x/(lightResX-1);
+                F32 spec = (F32) y/(lightResY-1);
+                F32 n = spec * spec * specExp;
+
+                // Nothing special here.  Just your typical blinn-phong term.
+                spec = powf(sa, n);
+
+                // Apply our normalization function.
+                // Note: This is the full equation that applies the full normalization curve, not an approximation.
+                // This is fine, given we only need to create our LUT once per buffer initialization.
+                spec *= (((n + 2) * (n + 4)) / (8 * F_PI * (powf(2, -n/2) + n)));
+
+                // Since we use R16F, we no longer have a dynamic range issue we need to work around here.
+                // Though some older drivers may not like this, newer drivers shouldn't have this problem.
+                ls[y*lightResX+x] = spec;
+            }
+        }
+
+        U32 pix_format = GL_R16F;
+        LLImageGL::generateTextures(1, &mLightFunc);
+        gGL.getTexUnit(0)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc);
+        LLImageGL::setManualImage(LLTexUnit::getInternalType(LLTexUnit::TT_TEXTURE), 0, pix_format, lightResX, lightResY, GL_RED, GL_FLOAT, ls, false);
+        gGL.getTexUnit(0)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
+        gGL.getTexUnit(0)->setTextureFilteringOption(LLTexUnit::TFO_TRILINEAR);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+
+        delete [] ls;
+    }
 
     mPbrBrdfLut.allocate(512, 512, GL_RG16F);
     mPbrBrdfLut.bindTarget();
@@ -1494,21 +1494,21 @@ void LLPipeline::createLUTBuffers()
 
 void LLPipeline::restoreGL()
 {
-	assertInitialized();
+    assertInitialized();
 
-	LLViewerShaderMgr::instance()->setShaders();
+    LLViewerShaderMgr::instance()->setShaders();
 
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
-		{
-			LLSpatialPartition* part = region->getSpatialPartition(i);
-			if (part)
-			{
-				part->restoreGL();
-		}
-		}
-	}
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
+        {
+            LLSpatialPartition* part = region->getSpatialPartition(i);
+            if (part)
+            {
+                part->restoreGL();
+        }
+        }
+    }
 }
 
 bool LLPipeline::shadersLoaded()
@@ -1523,335 +1523,335 @@ bool LLPipeline::canUseWindLightShaders() const
 
 bool LLPipeline::canUseAntiAliasing() const
 {
-	return true;
+    return true;
 }
 
 void LLPipeline::unloadShaders()
 {
-	LLViewerShaderMgr::instance()->unloadShaders();
-	mShadersLoaded = false;
+    LLViewerShaderMgr::instance()->unloadShaders();
+    mShadersLoaded = false;
 }
 
 void LLPipeline::assertInitializedDoError()
 {
-	LL_ERRS() << "LLPipeline used when uninitialized." << LL_ENDL;
+    LL_ERRS() << "LLPipeline used when uninitialized." << LL_ENDL;
 }
 
 //============================================================================
 
 void LLPipeline::enableShadows(const bool enable_shadows)
 {
-	//should probably do something here to wrangle shadows....	
+    //should probably do something here to wrangle shadows....
 }
 
 class LLOctreeDirtyTexture : public OctreeTraveler
 {
 public:
-	const std::set<LLViewerFetchedTexture*>& mTextures;
-
-	LLOctreeDirtyTexture(const std::set<LLViewerFetchedTexture*>& textures) : mTextures(textures) { }
-
-	virtual void visit(const OctreeNode* node)
-	{
-		LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
-
-		if (!group->hasState(LLSpatialGroup::GEOM_DIRTY) && !group->isEmpty())
-		{
-			for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
-			{
-				for (LLSpatialGroup::drawmap_elem_t::iterator j = i->second.begin(); j != i->second.end(); ++j) 
-				{
-					LLDrawInfo* params = *j;
-					LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(params->mTexture);
-					if (tex && mTextures.find(tex) != mTextures.end())
-					{ 
-						group->setState(LLSpatialGroup::GEOM_DIRTY);
-					}
-				}
-			}
-		}
-
-		for (LLSpatialGroup::bridge_list_t::iterator i = group->mBridgeList.begin(); i != group->mBridgeList.end(); ++i)
-		{
-			LLSpatialBridge* bridge = *i;
-			traverse(bridge->mOctree);
-		}
-	}
+    const std::set<LLViewerFetchedTexture*>& mTextures;
+
+    LLOctreeDirtyTexture(const std::set<LLViewerFetchedTexture*>& textures) : mTextures(textures) { }
+
+    virtual void visit(const OctreeNode* node)
+    {
+        LLSpatialGroup* group = (LLSpatialGroup*) node->getListener(0);
+
+        if (!group->hasState(LLSpatialGroup::GEOM_DIRTY) && !group->isEmpty())
+        {
+            for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
+            {
+                for (LLSpatialGroup::drawmap_elem_t::iterator j = i->second.begin(); j != i->second.end(); ++j)
+                {
+                    LLDrawInfo* params = *j;
+                    LLViewerFetchedTexture* tex = LLViewerTextureManager::staticCastToFetchedTexture(params->mTexture);
+                    if (tex && mTextures.find(tex) != mTextures.end())
+                    {
+                        group->setState(LLSpatialGroup::GEOM_DIRTY);
+                    }
+                }
+            }
+        }
+
+        for (LLSpatialGroup::bridge_list_t::iterator i = group->mBridgeList.begin(); i != group->mBridgeList.end(); ++i)
+        {
+            LLSpatialBridge* bridge = *i;
+            traverse(bridge->mOctree);
+        }
+    }
 };
 
 // Called when a texture changes # of channels (causes faces to move to alpha pool)
 void LLPipeline::dirtyPoolObjectTextures(const std::set<LLViewerFetchedTexture*>& textures)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	assertInitialized();
-
-	// *TODO: This is inefficient and causes frame spikes; need a better way to do this
-	//        Most of the time is spent in dirty.traverse.
-
-	for (LLDrawPool* poolp : mPools)
-	{
-		if (poolp->isFacePool())
-		{
-			((LLFacePool*) poolp)->dirtyTextures(textures);
-		}
-	}
-	
-	LLOctreeDirtyTexture dirty(textures);
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
-		{
-			LLSpatialPartition* part = region->getSpatialPartition(i);
-			if (part)
-			{
-				dirty.traverse(part->mOctree);
-			}
-		}
-	}
+    assertInitialized();
+
+    // *TODO: This is inefficient and causes frame spikes; need a better way to do this
+    //        Most of the time is spent in dirty.traverse.
+
+    for (LLDrawPool* poolp : mPools)
+    {
+        if (poolp->isFacePool())
+        {
+            ((LLFacePool*) poolp)->dirtyTextures(textures);
+        }
+    }
+
+    LLOctreeDirtyTexture dirty(textures);
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
+        {
+            LLSpatialPartition* part = region->getSpatialPartition(i);
+            if (part)
+            {
+                dirty.traverse(part->mOctree);
+            }
+        }
+    }
 }
 
 LLDrawPool *LLPipeline::findPool(const U32 type, LLViewerTexture *tex0)
 {
-	assertInitialized();
-
-	LLDrawPool *poolp = NULL;
-	switch( type )
-	{
-	case LLDrawPool::POOL_SIMPLE:
-		poolp = mSimplePool;
-		break;
-
-	case LLDrawPool::POOL_GRASS:
-		poolp = mGrassPool;
-		break;
-
-	case LLDrawPool::POOL_ALPHA_MASK:
-		poolp = mAlphaMaskPool;
-		break;
-
-	case LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK:
-		poolp = mFullbrightAlphaMaskPool;
-		break;
-
-	case LLDrawPool::POOL_FULLBRIGHT:
-		poolp = mFullbrightPool;
-		break;
-
-	case LLDrawPool::POOL_GLOW:
-		poolp = mGlowPool;
-		break;
-
-	case LLDrawPool::POOL_TREE:
-		poolp = get_if_there(mTreePools, (uintptr_t)tex0, (LLDrawPool*)0 );
-		break;
-
-	case LLDrawPool::POOL_TERRAIN:
-		poolp = get_if_there(mTerrainPools, (uintptr_t)tex0, (LLDrawPool*)0 );
-		break;
-
-	case LLDrawPool::POOL_BUMP:
-		poolp = mBumpPool;
-		break;
-	case LLDrawPool::POOL_MATERIALS:
-		poolp = mMaterialsPool;
-		break;
-	case LLDrawPool::POOL_ALPHA_PRE_WATER:
-		poolp = mAlphaPoolPreWater;
-		break;
+    assertInitialized();
+
+    LLDrawPool *poolp = NULL;
+    switch( type )
+    {
+    case LLDrawPool::POOL_SIMPLE:
+        poolp = mSimplePool;
+        break;
+
+    case LLDrawPool::POOL_GRASS:
+        poolp = mGrassPool;
+        break;
+
+    case LLDrawPool::POOL_ALPHA_MASK:
+        poolp = mAlphaMaskPool;
+        break;
+
+    case LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK:
+        poolp = mFullbrightAlphaMaskPool;
+        break;
+
+    case LLDrawPool::POOL_FULLBRIGHT:
+        poolp = mFullbrightPool;
+        break;
+
+    case LLDrawPool::POOL_GLOW:
+        poolp = mGlowPool;
+        break;
+
+    case LLDrawPool::POOL_TREE:
+        poolp = get_if_there(mTreePools, (uintptr_t)tex0, (LLDrawPool*)0 );
+        break;
+
+    case LLDrawPool::POOL_TERRAIN:
+        poolp = get_if_there(mTerrainPools, (uintptr_t)tex0, (LLDrawPool*)0 );
+        break;
+
+    case LLDrawPool::POOL_BUMP:
+        poolp = mBumpPool;
+        break;
+    case LLDrawPool::POOL_MATERIALS:
+        poolp = mMaterialsPool;
+        break;
+    case LLDrawPool::POOL_ALPHA_PRE_WATER:
+        poolp = mAlphaPoolPreWater;
+        break;
     case LLDrawPool::POOL_ALPHA_POST_WATER:
         poolp = mAlphaPoolPostWater;
         break;
 
-	case LLDrawPool::POOL_AVATAR:
-	case LLDrawPool::POOL_CONTROL_AV:
-		break; // Do nothing
+    case LLDrawPool::POOL_AVATAR:
+    case LLDrawPool::POOL_CONTROL_AV:
+        break; // Do nothing
 
-	case LLDrawPool::POOL_SKY:
-		poolp = mSkyPool;
-		break;
+    case LLDrawPool::POOL_SKY:
+        poolp = mSkyPool;
+        break;
 
-	case LLDrawPool::POOL_WATER:
-		poolp = mWaterPool;
-		break;
+    case LLDrawPool::POOL_WATER:
+        poolp = mWaterPool;
+        break;
 
-	case LLDrawPool::POOL_WL_SKY:
-		poolp = mWLSkyPool;
-		break;
+    case LLDrawPool::POOL_WL_SKY:
+        poolp = mWLSkyPool;
+        break;
 
-	case LLDrawPool::POOL_GLTF_PBR:
-		poolp = mPBROpaquePool;
-		break;
+    case LLDrawPool::POOL_GLTF_PBR:
+        poolp = mPBROpaquePool;
+        break;
     case LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK:
         poolp = mPBRAlphaMaskPool;
         break;
 
-	default:
-		llassert(0);
-		LL_ERRS() << "Invalid Pool Type in  LLPipeline::findPool() type=" << type << LL_ENDL;
-		break;
-	}
+    default:
+        llassert(0);
+        LL_ERRS() << "Invalid Pool Type in  LLPipeline::findPool() type=" << type << LL_ENDL;
+        break;
+    }
 
-	return poolp;
+    return poolp;
 }
 
 
-LLDrawPool *LLPipeline::getPool(const U32 type,	LLViewerTexture *tex0)
+LLDrawPool *LLPipeline::getPool(const U32 type, LLViewerTexture *tex0)
 {
-	LLDrawPool *poolp = findPool(type, tex0);
-	if (poolp)
-	{
-		return poolp;
-	}
+    LLDrawPool *poolp = findPool(type, tex0);
+    if (poolp)
+    {
+        return poolp;
+    }
 
-	LLDrawPool *new_poolp = LLDrawPool::createPool(type, tex0);
-	addPool( new_poolp );
+    LLDrawPool *new_poolp = LLDrawPool::createPool(type, tex0);
+    addPool( new_poolp );
 
-	return new_poolp;
+    return new_poolp;
 }
 
 
 // static
 LLDrawPool* LLPipeline::getPoolFromTE(const LLTextureEntry* te, LLViewerTexture* imagep)
 {
-	U32 type = getPoolTypeFromTE(te, imagep);
-	return gPipeline.getPool(type, imagep);
+    U32 type = getPoolTypeFromTE(te, imagep);
+    return gPipeline.getPool(type, imagep);
 }
 
-//static 
+//static
 U32 LLPipeline::getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* imagep)
 {
-	if (!te || !imagep)
-	{
-		return 0;
-	}
-		
-	LLMaterial* mat = te->getMaterialParams().get();
+    if (!te || !imagep)
+    {
+        return 0;
+    }
+
+    LLMaterial* mat = te->getMaterialParams().get();
     LLGLTFMaterial* gltf_mat = te->getGLTFRenderMaterial();
 
-	bool color_alpha = te->getColor().mV[3] < 0.999f;
-	bool alpha = color_alpha;
-	if (imagep)
-	{
-		alpha = alpha || (imagep->getComponents() == 4 && imagep->getType() != LLViewerTexture::MEDIA_TEXTURE) || (imagep->getComponents() == 2);
-	}
-
-	if (alpha && mat)
-	{
-		switch (mat->getDiffuseAlphaMode())
-		{
-			case 1:
-				alpha = true; // Material's alpha mode is set to blend.  Toss it into the alpha draw pool.
-				break;
-			case 0: //alpha mode set to none, never go to alpha pool
-			case 3: //alpha mode set to emissive, never go to alpha pool
-				alpha = color_alpha;
-				break;
-			default: //alpha mode set to "mask", go to alpha pool if fullbright
-				alpha = color_alpha; // Material's alpha mode is set to none, mask, or emissive.  Toss it into the opaque material draw pool.
-				break;
-		}
-	}
-	
-	if (alpha || (gltf_mat && gltf_mat->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_BLEND))
-	{
-		return LLDrawPool::POOL_ALPHA;
-	}
-	else if ((te->getBumpmap() || te->getShiny()) && (!mat || mat->getNormalID().isNull()))
-	{
-		return LLDrawPool::POOL_BUMP;
-	}
+    bool color_alpha = te->getColor().mV[3] < 0.999f;
+    bool alpha = color_alpha;
+    if (imagep)
+    {
+        alpha = alpha || (imagep->getComponents() == 4 && imagep->getType() != LLViewerTexture::MEDIA_TEXTURE) || (imagep->getComponents() == 2);
+    }
+
+    if (alpha && mat)
+    {
+        switch (mat->getDiffuseAlphaMode())
+        {
+            case 1:
+                alpha = true; // Material's alpha mode is set to blend.  Toss it into the alpha draw pool.
+                break;
+            case 0: //alpha mode set to none, never go to alpha pool
+            case 3: //alpha mode set to emissive, never go to alpha pool
+                alpha = color_alpha;
+                break;
+            default: //alpha mode set to "mask", go to alpha pool if fullbright
+                alpha = color_alpha; // Material's alpha mode is set to none, mask, or emissive.  Toss it into the opaque material draw pool.
+                break;
+        }
+    }
+
+    if (alpha || (gltf_mat && gltf_mat->mAlphaMode == LLGLTFMaterial::ALPHA_MODE_BLEND))
+    {
+        return LLDrawPool::POOL_ALPHA;
+    }
+    else if ((te->getBumpmap() || te->getShiny()) && (!mat || mat->getNormalID().isNull()))
+    {
+        return LLDrawPool::POOL_BUMP;
+    }
     else if (gltf_mat)
     {
         return LLDrawPool::POOL_GLTF_PBR;
     }
-	else if (mat && !alpha)
-	{
-		return LLDrawPool::POOL_MATERIALS;
-	}
-	else
-	{
-		return LLDrawPool::POOL_SIMPLE;
-	}
+    else if (mat && !alpha)
+    {
+        return LLDrawPool::POOL_MATERIALS;
+    }
+    else
+    {
+        return LLDrawPool::POOL_SIMPLE;
+    }
 }
 
 
 void LLPipeline::addPool(LLDrawPool *new_poolp)
 {
-	assertInitialized();
-	mPools.insert(new_poolp);
-	addToQuickLookup( new_poolp );
+    assertInitialized();
+    mPools.insert(new_poolp);
+    addToQuickLookup( new_poolp );
 }
 
 void LLPipeline::allocDrawable(LLViewerObject *vobj)
 {
-	LLDrawable *drawable = new LLDrawable(vobj);
-	vobj->mDrawable = drawable;
-	
-	//encompass completely sheared objects by taking 
-	//the most extreme point possible (<1,1,0.5>)
-	drawable->setRadius(LLVector3(1,1,0.5f).scaleVec(vobj->getScale()).length());
-	if (vobj->isOrphaned())
-	{
-		drawable->setState(LLDrawable::FORCE_INVISIBLE);
-	}
-	drawable->updateXform(TRUE);
-}
+    LLDrawable *drawable = new LLDrawable(vobj);
+    vobj->mDrawable = drawable;
+
+    //encompass completely sheared objects by taking
+    //the most extreme point possible (<1,1,0.5>)
+    drawable->setRadius(LLVector3(1,1,0.5f).scaleVec(vobj->getScale()).length());
+    if (vobj->isOrphaned())
+    {
+        drawable->setState(LLDrawable::FORCE_INVISIBLE);
+    }
+    drawable->updateXform(TRUE);
+}
 
 
 void LLPipeline::unlinkDrawable(LLDrawable *drawable)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
 
-	assertInitialized();
-
-	LLPointer<LLDrawable> drawablep = drawable; // make sure this doesn't get deleted before we are done
-	
-	// Based on flags, remove the drawable from the queues that it's on.
-	if (drawablep->isState(LLDrawable::ON_MOVE_LIST))
-	{
-		LLDrawable::drawable_vector_t::iterator iter = std::find(mMovedList.begin(), mMovedList.end(), drawablep);
-		if (iter != mMovedList.end())
-		{
-			mMovedList.erase(iter);
-		}
-	}
-
-	if (drawablep->getSpatialGroup())
-	{
-		if (!drawablep->getSpatialGroup()->getSpatialPartition()->remove(drawablep, drawablep->getSpatialGroup()))
-		{
+    assertInitialized();
+
+    LLPointer<LLDrawable> drawablep = drawable; // make sure this doesn't get deleted before we are done
+
+    // Based on flags, remove the drawable from the queues that it's on.
+    if (drawablep->isState(LLDrawable::ON_MOVE_LIST))
+    {
+        LLDrawable::drawable_vector_t::iterator iter = std::find(mMovedList.begin(), mMovedList.end(), drawablep);
+        if (iter != mMovedList.end())
+        {
+            mMovedList.erase(iter);
+        }
+    }
+
+    if (drawablep->getSpatialGroup())
+    {
+        if (!drawablep->getSpatialGroup()->getSpatialPartition()->remove(drawablep, drawablep->getSpatialGroup()))
+        {
 #ifdef LL_RELEASE_FOR_DOWNLOAD
-			LL_WARNS() << "Couldn't remove object from spatial group!" << LL_ENDL;
+            LL_WARNS() << "Couldn't remove object from spatial group!" << LL_ENDL;
 #else
-			LL_ERRS() << "Couldn't remove object from spatial group!" << LL_ENDL;
+            LL_ERRS() << "Couldn't remove object from spatial group!" << LL_ENDL;
 #endif
-		}
-	}
-
-	mLights.erase(drawablep);
-
-	for (light_set_t::iterator iter = mNearbyLights.begin();
-				iter != mNearbyLights.end(); iter++)
-	{
-		if (iter->drawable == drawablep)
-		{
-			mNearbyLights.erase(iter);
-			break;
-		}
-	}
-
-	for (U32 i = 0; i < 2; ++i)
-	{
-		if (mShadowSpotLight[i] == drawablep)
-		{
-			mShadowSpotLight[i] = NULL;
-		}
-
-		if (mTargetShadowSpotLight[i] == drawablep)
-		{
-			mTargetShadowSpotLight[i] = NULL;
-		}
-	}
+        }
+    }
+
+    mLights.erase(drawablep);
+
+    for (light_set_t::iterator iter = mNearbyLights.begin();
+                iter != mNearbyLights.end(); iter++)
+    {
+        if (iter->drawable == drawablep)
+        {
+            mNearbyLights.erase(iter);
+            break;
+        }
+    }
+
+    for (U32 i = 0; i < 2; ++i)
+    {
+        if (mShadowSpotLight[i] == drawablep)
+        {
+            mShadowSpotLight[i] = NULL;
+        }
+
+        if (mTargetShadowSpotLight[i] == drawablep)
+        {
+            mTargetShadowSpotLight[i] = NULL;
+        }
+    }
 }
 
 //static
@@ -1879,227 +1879,227 @@ void LLPipeline::removeMutedAVsLights(LLVOAvatar* muted_avatar)
 
 U32 LLPipeline::addObject(LLViewerObject *vobj)
 {
-	if (RenderDelayCreation)
-	{
-		mCreateQ.push_back(vobj);
-	}
-	else
-	{
-		createObject(vobj);
-	}
+    if (RenderDelayCreation)
+    {
+        mCreateQ.push_back(vobj);
+    }
+    else
+    {
+        createObject(vobj);
+    }
 
-	return 1;
+    return 1;
 }
 
 void LLPipeline::createObjects(F32 max_dtime)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
 
-	LLTimer update_timer;
+    LLTimer update_timer;
+
+    while (!mCreateQ.empty() && update_timer.getElapsedTimeF32() < max_dtime)
+    {
+        LLViewerObject* vobj = mCreateQ.front();
+        if (!vobj->isDead())
+        {
+            createObject(vobj);
+        }
+        mCreateQ.pop_front();
+    }
 
-	while (!mCreateQ.empty() && update_timer.getElapsedTimeF32() < max_dtime)
-	{
-		LLViewerObject* vobj = mCreateQ.front();
-		if (!vobj->isDead())
-		{
-			createObject(vobj);
-		}
-		mCreateQ.pop_front();
-	}
-	
-	//for (LLViewerObject::vobj_list_t::iterator iter = mCreateQ.begin(); iter != mCreateQ.end(); ++iter)
-	//{
-	//	createObject(*iter);
-	//}
+    //for (LLViewerObject::vobj_list_t::iterator iter = mCreateQ.begin(); iter != mCreateQ.end(); ++iter)
+    //{
+    //  createObject(*iter);
+    //}
 
-	//mCreateQ.clear();
+    //mCreateQ.clear();
 }
 
 void LLPipeline::createObject(LLViewerObject* vobj)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	LLDrawable* drawablep = vobj->mDrawable;
+    LLDrawable* drawablep = vobj->mDrawable;
+
+    if (!drawablep)
+    {
+        drawablep = vobj->createDrawable(this);
+    }
+    else
+    {
+        LL_ERRS() << "Redundant drawable creation!" << LL_ENDL;
+    }
 
-	if (!drawablep)
-	{
-		drawablep = vobj->createDrawable(this);
-	}
-	else
-	{
-		LL_ERRS() << "Redundant drawable creation!" << LL_ENDL;
-	}
-		
-	llassert(drawablep);
+    llassert(drawablep);
 
-	if (vobj->getParent())
-	{
-		vobj->setDrawableParent(((LLViewerObject*)vobj->getParent())->mDrawable); // LLPipeline::addObject 1
-	}
-	else
-	{
-		vobj->setDrawableParent(NULL); // LLPipeline::addObject 2
-	}
+    if (vobj->getParent())
+    {
+        vobj->setDrawableParent(((LLViewerObject*)vobj->getParent())->mDrawable); // LLPipeline::addObject 1
+    }
+    else
+    {
+        vobj->setDrawableParent(NULL); // LLPipeline::addObject 2
+    }
 
-	markRebuild(drawablep, LLDrawable::REBUILD_ALL);
+    markRebuild(drawablep, LLDrawable::REBUILD_ALL);
 }
 
 
 void LLPipeline::resetFrameStats()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	assertInitialized();
+    assertInitialized();
 
-	if (mOldRenderDebugMask != mRenderDebugMask)
-	{
-		gObjectList.clearDebugText();
-		mOldRenderDebugMask = mRenderDebugMask;
-	}
+    if (mOldRenderDebugMask != mRenderDebugMask)
+    {
+        gObjectList.clearDebugText();
+        mOldRenderDebugMask = mRenderDebugMask;
+    }
 }
 
 //external functions for asynchronous updating
 void LLPipeline::updateMoveDampedAsync(LLDrawable* drawablep)
 {
     LL_PROFILE_ZONE_SCOPED;
-	if (FreezeTime)
-	{
-		return;
-	}
-	if (!drawablep)
-	{
-		LL_ERRS() << "updateMove called with NULL drawablep" << LL_ENDL;
-		return;
-	}
-	if (drawablep->isState(LLDrawable::EARLY_MOVE))
-	{
-		return;
-	}
-
-	assertInitialized();
-
-	// update drawable now
-	drawablep->clearState(LLDrawable::MOVE_UNDAMPED); // force to DAMPED
-	drawablep->updateMove(); // returns done
-	drawablep->setState(LLDrawable::EARLY_MOVE); // flag says we already did an undamped move this frame
-	// Put on move list so that EARLY_MOVE gets cleared
-	if (!drawablep->isState(LLDrawable::ON_MOVE_LIST))
-	{
-		mMovedList.push_back(drawablep);
-		drawablep->setState(LLDrawable::ON_MOVE_LIST);
-	}
+    if (FreezeTime)
+    {
+        return;
+    }
+    if (!drawablep)
+    {
+        LL_ERRS() << "updateMove called with NULL drawablep" << LL_ENDL;
+        return;
+    }
+    if (drawablep->isState(LLDrawable::EARLY_MOVE))
+    {
+        return;
+    }
+
+    assertInitialized();
+
+    // update drawable now
+    drawablep->clearState(LLDrawable::MOVE_UNDAMPED); // force to DAMPED
+    drawablep->updateMove(); // returns done
+    drawablep->setState(LLDrawable::EARLY_MOVE); // flag says we already did an undamped move this frame
+    // Put on move list so that EARLY_MOVE gets cleared
+    if (!drawablep->isState(LLDrawable::ON_MOVE_LIST))
+    {
+        mMovedList.push_back(drawablep);
+        drawablep->setState(LLDrawable::ON_MOVE_LIST);
+    }
 }
 
 void LLPipeline::updateMoveNormalAsync(LLDrawable* drawablep)
 {
     LL_PROFILE_ZONE_SCOPED;
-	if (FreezeTime)
-	{
-		return;
-	}
-	if (!drawablep)
-	{
-		LL_ERRS() << "updateMove called with NULL drawablep" << LL_ENDL;
-		return;
-	}
-	if (drawablep->isState(LLDrawable::EARLY_MOVE))
-	{
-		return;
-	}
-
-	assertInitialized();
-
-	// update drawable now
-	drawablep->setState(LLDrawable::MOVE_UNDAMPED); // force to UNDAMPED
-	drawablep->updateMove();
-	drawablep->setState(LLDrawable::EARLY_MOVE); // flag says we already did an undamped move this frame
-	// Put on move list so that EARLY_MOVE gets cleared
-	if (!drawablep->isState(LLDrawable::ON_MOVE_LIST))
-	{
-		mMovedList.push_back(drawablep);
-		drawablep->setState(LLDrawable::ON_MOVE_LIST);
-	}
+    if (FreezeTime)
+    {
+        return;
+    }
+    if (!drawablep)
+    {
+        LL_ERRS() << "updateMove called with NULL drawablep" << LL_ENDL;
+        return;
+    }
+    if (drawablep->isState(LLDrawable::EARLY_MOVE))
+    {
+        return;
+    }
+
+    assertInitialized();
+
+    // update drawable now
+    drawablep->setState(LLDrawable::MOVE_UNDAMPED); // force to UNDAMPED
+    drawablep->updateMove();
+    drawablep->setState(LLDrawable::EARLY_MOVE); // flag says we already did an undamped move this frame
+    // Put on move list so that EARLY_MOVE gets cleared
+    if (!drawablep->isState(LLDrawable::ON_MOVE_LIST))
+    {
+        mMovedList.push_back(drawablep);
+        drawablep->setState(LLDrawable::ON_MOVE_LIST);
+    }
 }
 
 void LLPipeline::updateMovedList(LLDrawable::drawable_vector_t& moved_list)
 {
     LL_PROFILE_ZONE_SCOPED;
-	LLDrawable::drawable_vector_t newList; // removing elements in the middle of a vector is a really bad idea. I'll just create a new one and swap it at the end.
-
-	for (LLDrawable* drawablep : moved_list)
-	{
-		bool done = true;
-		if (!drawablep->isDead() && (!drawablep->isState(LLDrawable::EARLY_MOVE)))
-		{
-			done = drawablep->updateMove();
-		}
-		drawablep->clearState(LLDrawable::EARLY_MOVE | LLDrawable::MOVE_UNDAMPED);
-		if (done)
-		{
-			if (drawablep->isRoot() && !drawablep->isState(LLDrawable::ACTIVE))
-			{
-				drawablep->makeStatic();
-			}
-			drawablep->clearState(LLDrawable::ON_MOVE_LIST);
-			if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
-			{ //will likely not receive any future world matrix updates
-				// -- this keeps attachments from getting stuck in space and falling off your avatar
-				drawablep->clearState(LLDrawable::ANIMATED_CHILD);
-				markRebuild(drawablep, LLDrawable::REBUILD_VOLUME);
-				if (drawablep->getVObj())
-				{
-					drawablep->getVObj()->dirtySpatialGroup();
-				}
-			}
-		}
-		else
-		{
-			newList.push_back( drawablep );
-		}
-	}
-
-	moved_list.swap( newList );
+    LLDrawable::drawable_vector_t newList; // removing elements in the middle of a vector is a really bad idea. I'll just create a new one and swap it at the end.
+
+    for (LLDrawable* drawablep : moved_list)
+    {
+        bool done = true;
+        if (!drawablep->isDead() && (!drawablep->isState(LLDrawable::EARLY_MOVE)))
+        {
+            done = drawablep->updateMove();
+        }
+        drawablep->clearState(LLDrawable::EARLY_MOVE | LLDrawable::MOVE_UNDAMPED);
+        if (done)
+        {
+            if (drawablep->isRoot() && !drawablep->isState(LLDrawable::ACTIVE))
+            {
+                drawablep->makeStatic();
+            }
+            drawablep->clearState(LLDrawable::ON_MOVE_LIST);
+            if (drawablep->isState(LLDrawable::ANIMATED_CHILD))
+            { //will likely not receive any future world matrix updates
+                // -- this keeps attachments from getting stuck in space and falling off your avatar
+                drawablep->clearState(LLDrawable::ANIMATED_CHILD);
+                markRebuild(drawablep, LLDrawable::REBUILD_VOLUME);
+                if (drawablep->getVObj())
+                {
+                    drawablep->getVObj()->dirtySpatialGroup();
+                }
+            }
+        }
+        else
+        {
+            newList.push_back( drawablep );
+        }
+    }
+
+    moved_list.swap( newList );
 }
 
 void LLPipeline::updateMove()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
 
-	if (FreezeTime)
-	{
-		return;
-	}
-
-	assertInitialized();
-
-	for (LLDrawable* drawablep : mRetexturedList)
-	{
-		if (drawablep && !drawablep->isDead())
-		{
-			drawablep->updateTexture();
-		}
-	}
-	mRetexturedList.clear();
-
-	updateMovedList(mMovedList);
-
-	//balance octrees
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
-		{
-			LLSpatialPartition* part = region->getSpatialPartition(i);
-			if (part)
-			{
-				part->mOctree->balance();
-			}
-		}
-
-		//balance the VO Cache tree
-		LLVOCachePartition* vo_part = region->getVOCachePartition();
-		if(vo_part)
-		{
-			vo_part->mOctree->balance();
-		}
-	}
+    if (FreezeTime)
+    {
+        return;
+    }
+
+    assertInitialized();
+
+    for (LLDrawable* drawablep : mRetexturedList)
+    {
+        if (drawablep && !drawablep->isDead())
+        {
+            drawablep->updateTexture();
+        }
+    }
+    mRetexturedList.clear();
+
+    updateMovedList(mMovedList);
+
+    //balance octrees
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
+        {
+            LLSpatialPartition* part = region->getSpatialPartition(i);
+            if (part)
+            {
+                part->mOctree->balance();
+            }
+        }
+
+        //balance the VO Cache tree
+        LLVOCachePartition* vo_part = region->getVOCachePartition();
+        if(vo_part)
+        {
+            vo_part->mOctree->balance();
+        }
+    }
 }
 
 /////////////////////////////////////////////////////////////////////////////
@@ -2110,293 +2110,293 @@ void LLPipeline::updateMove()
 F32 LLPipeline::calcPixelArea(LLVector3 center, LLVector3 size, LLCamera &camera)
 {
     llassert(!gCubeSnapshot); // shouldn't be doing ANY of this during cube snap shots
-	LLVector3 lookAt = center - camera.getOrigin();
-	F32 dist = lookAt.length();
+    LLVector3 lookAt = center - camera.getOrigin();
+    F32 dist = lookAt.length();
 
-	//ramp down distance for nearby objects
-	//shrink dist by dist/16.
-	if (dist < 16.f)
-	{
-		dist /= 16.f;
-		dist *= dist;
-		dist *= 16.f;
-	}
+    //ramp down distance for nearby objects
+    //shrink dist by dist/16.
+    if (dist < 16.f)
+    {
+        dist /= 16.f;
+        dist *= dist;
+        dist *= 16.f;
+    }
 
-	//get area of circle around node
-	F32 app_angle = atanf(size.length()/dist);
-	F32 radius = app_angle*LLDrawable::sCurPixelAngle;
-	return radius*radius * F_PI;
+    //get area of circle around node
+    F32 app_angle = atanf(size.length()/dist);
+    F32 radius = app_angle*LLDrawable::sCurPixelAngle;
+    return radius*radius * F_PI;
 }
 
 //static
 F32 LLPipeline::calcPixelArea(const LLVector4a& center, const LLVector4a& size, LLCamera &camera)
 {
-	LLVector4a origin;
-	origin.load3(camera.getOrigin().mV);
+    LLVector4a origin;
+    origin.load3(camera.getOrigin().mV);
 
-	LLVector4a lookAt;
-	lookAt.setSub(center, origin);
-	F32 dist = lookAt.getLength3().getF32();
+    LLVector4a lookAt;
+    lookAt.setSub(center, origin);
+    F32 dist = lookAt.getLength3().getF32();
 
-	//ramp down distance for nearby objects
-	//shrink dist by dist/16.
-	if (dist < 16.f)
-	{
-		dist /= 16.f;
-		dist *= dist;
-		dist *= 16.f;
-	}
+    //ramp down distance for nearby objects
+    //shrink dist by dist/16.
+    if (dist < 16.f)
+    {
+        dist /= 16.f;
+        dist *= dist;
+        dist *= 16.f;
+    }
 
-	//get area of circle around node
-	F32 app_angle = atanf(size.getLength3().getF32()/dist);
-	F32 radius = app_angle*LLDrawable::sCurPixelAngle;
-	return radius*radius * F_PI;
+    //get area of circle around node
+    F32 app_angle = atanf(size.getLength3().getF32()/dist);
+    F32 radius = app_angle*LLDrawable::sCurPixelAngle;
+    return radius*radius * F_PI;
 }
 
 void LLPipeline::grabReferences(LLCullResult& result)
 {
-	sCull = &result;
+    sCull = &result;
 }
 
 void LLPipeline::clearReferences()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	sCull = NULL;
-	mGroupSaveQ1.clear();
+    sCull = NULL;
+    mGroupSaveQ1.clear();
 }
 
 void check_references(LLSpatialGroup* group, LLDrawable* drawable)
 {
-	for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
-	{
+    for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
+    {
         LLDrawable* drawablep = (LLDrawable*)(*i)->getDrawable();
-		if (drawable == drawablep)
-		{
-			LL_ERRS() << "LLDrawable deleted while actively reference by LLPipeline." << LL_ENDL;
-		}
-	}			
+        if (drawable == drawablep)
+        {
+            LL_ERRS() << "LLDrawable deleted while actively reference by LLPipeline." << LL_ENDL;
+        }
+    }
 }
 
 void check_references(LLDrawable* drawable, LLFace* face)
 {
-	for (S32 i = 0; i < drawable->getNumFaces(); ++i)
-	{
-		if (drawable->getFace(i) == face)
-		{
-			LL_ERRS() << "LLFace deleted while actively referenced by LLPipeline." << LL_ENDL;
-		}
-	}
+    for (S32 i = 0; i < drawable->getNumFaces(); ++i)
+    {
+        if (drawable->getFace(i) == face)
+        {
+            LL_ERRS() << "LLFace deleted while actively referenced by LLPipeline." << LL_ENDL;
+        }
+    }
 }
 
 void check_references(LLSpatialGroup* group, LLFace* face)
 {
-	for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
-	{
-		LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
-		if(drawable)
-		{
-		check_references(drawable, face);
-	}			
+    for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
+    {
+        LLDrawable* drawable = (LLDrawable*)(*i)->getDrawable();
+        if(drawable)
+        {
+        check_references(drawable, face);
+    }
 }
 }
 
 void LLPipeline::checkReferences(LLFace* face)
 {
 #if 0
-	if (sCull)
-	{
-		for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
-			check_references(group, face);
-		}
-
-		for (LLCullResult::sg_iterator iter = sCull->beginAlphaGroups(); iter != sCull->endAlphaGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
-			check_references(group, face);
-		}
-
-		for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(); iter != sCull->endDrawableGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
-			check_references(group, face);
-		}
-
-		for (LLCullResult::drawable_iterator iter = sCull->beginVisibleList(); iter != sCull->endVisibleList(); ++iter)
-		{
-			LLDrawable* drawable = *iter;
-			check_references(drawable, face);	
-		}
-	}
+    if (sCull)
+    {
+        for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
+            check_references(group, face);
+        }
+
+        for (LLCullResult::sg_iterator iter = sCull->beginAlphaGroups(); iter != sCull->endAlphaGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
+            check_references(group, face);
+        }
+
+        for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(); iter != sCull->endDrawableGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
+            check_references(group, face);
+        }
+
+        for (LLCullResult::drawable_iterator iter = sCull->beginVisibleList(); iter != sCull->endVisibleList(); ++iter)
+        {
+            LLDrawable* drawable = *iter;
+            check_references(drawable, face);
+        }
+    }
 #endif
 }
 
 void LLPipeline::checkReferences(LLDrawable* drawable)
 {
 #if 0
-	if (sCull)
-	{
-		for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
-			check_references(group, drawable);
-		}
-
-		for (LLCullResult::sg_iterator iter = sCull->beginAlphaGroups(); iter != sCull->endAlphaGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
-			check_references(group, drawable);
-		}
-
-		for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(); iter != sCull->endDrawableGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
-			check_references(group, drawable);
-		}
-
-		for (LLCullResult::drawable_iterator iter = sCull->beginVisibleList(); iter != sCull->endVisibleList(); ++iter)
-		{
-			if (drawable == *iter)
-			{
-				LL_ERRS() << "LLDrawable deleted while actively referenced by LLPipeline." << LL_ENDL;
-			}
-		}
-	}
+    if (sCull)
+    {
+        for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
+            check_references(group, drawable);
+        }
+
+        for (LLCullResult::sg_iterator iter = sCull->beginAlphaGroups(); iter != sCull->endAlphaGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
+            check_references(group, drawable);
+        }
+
+        for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(); iter != sCull->endDrawableGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
+            check_references(group, drawable);
+        }
+
+        for (LLCullResult::drawable_iterator iter = sCull->beginVisibleList(); iter != sCull->endVisibleList(); ++iter)
+        {
+            if (drawable == *iter)
+            {
+                LL_ERRS() << "LLDrawable deleted while actively referenced by LLPipeline." << LL_ENDL;
+            }
+        }
+    }
 #endif
 }
 
 void check_references(LLSpatialGroup* group, LLDrawInfo* draw_info)
 {
-	for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
-	{
-		LLSpatialGroup::drawmap_elem_t& draw_vec = i->second;
-		for (LLSpatialGroup::drawmap_elem_t::iterator j = draw_vec.begin(); j != draw_vec.end(); ++j)
-		{
-			LLDrawInfo* params = *j;
-			if (params == draw_info)
-			{
-				LL_ERRS() << "LLDrawInfo deleted while actively referenced by LLPipeline." << LL_ENDL;
-			}
-		}
-	}
+    for (LLSpatialGroup::draw_map_t::iterator i = group->mDrawMap.begin(); i != group->mDrawMap.end(); ++i)
+    {
+        LLSpatialGroup::drawmap_elem_t& draw_vec = i->second;
+        for (LLSpatialGroup::drawmap_elem_t::iterator j = draw_vec.begin(); j != draw_vec.end(); ++j)
+        {
+            LLDrawInfo* params = *j;
+            if (params == draw_info)
+            {
+                LL_ERRS() << "LLDrawInfo deleted while actively referenced by LLPipeline." << LL_ENDL;
+            }
+        }
+    }
 }
 
 
 void LLPipeline::checkReferences(LLDrawInfo* draw_info)
 {
 #if 0
-	if (sCull)
-	{
-		for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
-			check_references(group, draw_info);
-		}
-
-		for (LLCullResult::sg_iterator iter = sCull->beginAlphaGroups(); iter != sCull->endAlphaGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
-			check_references(group, draw_info);
-		}
-
-		for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(); iter != sCull->endDrawableGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
-			check_references(group, draw_info);
-		}
-	}
+    if (sCull)
+    {
+        for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
+            check_references(group, draw_info);
+        }
+
+        for (LLCullResult::sg_iterator iter = sCull->beginAlphaGroups(); iter != sCull->endAlphaGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
+            check_references(group, draw_info);
+        }
+
+        for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(); iter != sCull->endDrawableGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
+            check_references(group, draw_info);
+        }
+    }
 #endif
 }
 
 void LLPipeline::checkReferences(LLSpatialGroup* group)
 {
 #if CHECK_PIPELINE_REFERENCES
-	if (sCull)
-	{
-		for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
-		{
-			if (group == *iter)
-			{
-				LL_ERRS() << "LLSpatialGroup deleted while actively referenced by LLPipeline." << LL_ENDL;
-			}
-		}
-
-		for (LLCullResult::sg_iterator iter = sCull->beginAlphaGroups(); iter != sCull->endAlphaGroups(); ++iter)
-		{
-			if (group == *iter)
-			{
-				LL_ERRS() << "LLSpatialGroup deleted while actively referenced by LLPipeline." << LL_ENDL;
-			}
-		}
-
-		for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(); iter != sCull->endDrawableGroups(); ++iter)
-		{
-			if (group == *iter)
-			{
-				LL_ERRS() << "LLSpatialGroup deleted while actively referenced by LLPipeline." << LL_ENDL;
-			}
-		}
-	}
+    if (sCull)
+    {
+        for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(); iter != sCull->endVisibleGroups(); ++iter)
+        {
+            if (group == *iter)
+            {
+                LL_ERRS() << "LLSpatialGroup deleted while actively referenced by LLPipeline." << LL_ENDL;
+            }
+        }
+
+        for (LLCullResult::sg_iterator iter = sCull->beginAlphaGroups(); iter != sCull->endAlphaGroups(); ++iter)
+        {
+            if (group == *iter)
+            {
+                LL_ERRS() << "LLSpatialGroup deleted while actively referenced by LLPipeline." << LL_ENDL;
+            }
+        }
+
+        for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(); iter != sCull->endDrawableGroups(); ++iter)
+        {
+            if (group == *iter)
+            {
+                LL_ERRS() << "LLSpatialGroup deleted while actively referenced by LLPipeline." << LL_ENDL;
+            }
+        }
+    }
 #endif
 }
 
 
 bool LLPipeline::visibleObjectsInFrustum(LLCamera& camera)
 {
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
-		{
-			LLSpatialPartition* part = region->getSpatialPartition(i);
-			if (part)
-			{
-				if (hasRenderType(part->mDrawableType))
-				{
-					if (part->visibleObjectsInFrustum(camera))
-					{
-						return true;
-					}
-				}
-			}
-		}
-	}
-
-	return false;
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
+        {
+            LLSpatialPartition* part = region->getSpatialPartition(i);
+            if (part)
+            {
+                if (hasRenderType(part->mDrawableType))
+                {
+                    if (part->visibleObjectsInFrustum(camera))
+                    {
+                        return true;
+                    }
+                }
+            }
+        }
+    }
+
+    return false;
 }
 
 bool LLPipeline::getVisibleExtents(LLCamera& camera, LLVector3& min, LLVector3& max)
 {
-	const F32 X = 65536.f;
+    const F32 X = 65536.f;
 
-	min = LLVector3(X,X,X);
-	max = LLVector3(-X,-X,-X);
+    min = LLVector3(X,X,X);
+    max = LLVector3(-X,-X,-X);
 
-	LLViewerCamera::eCameraID saved_camera_id = LLViewerCamera::sCurCameraID;
-	LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
+    LLViewerCamera::eCameraID saved_camera_id = LLViewerCamera::sCurCameraID;
+    LLViewerCamera::sCurCameraID = LLViewerCamera::CAMERA_WORLD;
 
-	bool res = true;
+    bool res = true;
 
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
-		{
-			LLSpatialPartition* part = region->getSpatialPartition(i);
-			if (part)
-			{
-				if (hasRenderType(part->mDrawableType))
-				{
-					if (!part->getVisibleExtents(camera, min, max))
-					{
-						res = false;
-					}
-				}
-			}
-		}
-	}
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
+        {
+            LLSpatialPartition* part = region->getSpatialPartition(i);
+            if (part)
+            {
+                if (hasRenderType(part->mDrawableType))
+                {
+                    if (!part->getVisibleExtents(camera, min, max))
+                    {
+                        res = false;
+                    }
+                }
+            }
+        }
+    }
 
-	LLViewerCamera::sCurCameraID = saved_camera_id;
-	return res;
+    LLViewerCamera::sCurCameraID = saved_camera_id;
+    return res;
 }
 
 static LLTrace::BlockTimerStatHandle FTM_CULL("Object Culling");
@@ -2405,7 +2405,7 @@ static LLTrace::BlockTimerStatHandle FTM_CULL("Object Culling");
 bool LLPipeline::isWaterClip()
 {
     // We always pretend that we're not clipping water when rendering mirrors.
-	return (gPipeline.mHeroProbeManager.isMirrorPass()) ? false : (!sRenderTransparentWater || gCubeSnapshot) && !sRenderingHUDs;
+    return (gPipeline.mHeroProbeManager.isMirrorPass()) ? false : (!sRenderTransparentWater || gCubeSnapshot) && !sRenderingHUDs;
 }
 
 void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result)
@@ -2413,11 +2413,11 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result)
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; //LL_RECORD_BLOCK_TIME(FTM_CULL);
     LL_PROFILE_GPU_ZONE("updateCull"); // should always be zero GPU time, but drop a timer to flush stuff out
 
-	bool water_clip = isWaterClip();
+    bool water_clip = isWaterClip();
 
     if (water_clip)
     {
-        
+
         LLVector3 pnorm;
 
         F32 water_height = LLEnvironment::instance().getWaterHeight();
@@ -2432,7 +2432,7 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result)
             //camera is above water, cull below water
             pnorm = LLVector3(0, 0, -1);
         }
-        
+
         LLPlane plane;
         plane.setVec(LLVector3(0, 0, water_height), pnorm);
 
@@ -2443,48 +2443,48 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result)
         camera.disableUserClipPlane();
     }
 
-	grabReferences(result);
-
-	sCull->clear();
-
-	for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin(); 
-			iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
-	{
-		LLViewerRegion* region = *iter;
-
-		for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
-		{
-			LLSpatialPartition* part = region->getSpatialPartition(i);
-			if (part)
-			{
-				if (hasRenderType(part->mDrawableType))
-				{
-					part->cull(camera);
-				}
-			}
-		}
-
-		//scan the VO Cache tree
-		LLVOCachePartition* vo_part = region->getVOCachePartition();
-		if(vo_part)
-		{
-			vo_part->cull(camera, sUseOcclusion > 0);
-		}
-	}
-
-	if (hasRenderType(LLPipeline::RENDER_TYPE_SKY) && 
-		gSky.mVOSkyp.notNull() && 
-		gSky.mVOSkyp->mDrawable.notNull())
-	{
-		gSky.mVOSkyp->mDrawable->setVisible(camera);
-		sCull->pushDrawable(gSky.mVOSkyp->mDrawable);
-		gSky.updateCull();
-		stop_glerror();
-	}
-
-    if (hasRenderType(LLPipeline::RENDER_TYPE_WL_SKY) && 
+    grabReferences(result);
+
+    sCull->clear();
+
+    for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin();
+            iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
+    {
+        LLViewerRegion* region = *iter;
+
+        for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
+        {
+            LLSpatialPartition* part = region->getSpatialPartition(i);
+            if (part)
+            {
+                if (hasRenderType(part->mDrawableType))
+                {
+                    part->cull(camera);
+                }
+            }
+        }
+
+        //scan the VO Cache tree
+        LLVOCachePartition* vo_part = region->getVOCachePartition();
+        if(vo_part)
+        {
+            vo_part->cull(camera, sUseOcclusion > 0);
+        }
+    }
+
+    if (hasRenderType(LLPipeline::RENDER_TYPE_SKY) &&
+        gSky.mVOSkyp.notNull() &&
+        gSky.mVOSkyp->mDrawable.notNull())
+    {
+        gSky.mVOSkyp->mDrawable->setVisible(camera);
+        sCull->pushDrawable(gSky.mVOSkyp->mDrawable);
+        gSky.updateCull();
+        stop_glerror();
+    }
+
+    if (hasRenderType(LLPipeline::RENDER_TYPE_WL_SKY) &&
         gPipeline.canUseWindLightShaders() &&
-        gSky.mVOWLSkyp.notNull() && 
+        gSky.mVOWLSkyp.notNull() &&
         gSky.mVOWLSkyp->mDrawable.notNull())
     {
         gSky.mVOWLSkyp->mDrawable->setVisible(camera);
@@ -2494,28 +2494,28 @@ void LLPipeline::updateCull(LLCamera& camera, LLCullResult& result)
 
 void LLPipeline::markNotCulled(LLSpatialGroup* group, LLCamera& camera)
 {
-	if (group->isEmpty())
-	{ 
-		return;
-	}
-	
-	group->setVisible();
-
-	if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD && !gCubeSnapshot)
-	{
-		group->updateDistance(camera);
-	}
-	
-	assertInitialized();
-	
-	if (!group->getSpatialPartition()->mRenderByGroup)
-	{ //render by drawable
-		sCull->pushDrawableGroup(group);
-	}
-	else
-	{   //render by group
-		sCull->pushVisibleGroup(group);
-	}
+    if (group->isEmpty())
+    {
+        return;
+    }
+
+    group->setVisible();
+
+    if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD && !gCubeSnapshot)
+    {
+        group->updateDistance(camera);
+    }
+
+    assertInitialized();
+
+    if (!group->getSpatialPartition()->mRenderByGroup)
+    { //render by drawable
+        sCull->pushDrawableGroup(group);
+    }
+    else
+    {   //render by group
+        sCull->pushVisibleGroup(group);
+    }
 
     if (group->needsUpdate() ||
         group->getVisible(LLViewerCamera::sCurCameraID) < LLDrawable::getCurrentFrame() - 1)
@@ -2524,31 +2524,31 @@ void LLPipeline::markNotCulled(LLSpatialGroup* group, LLCamera& camera)
         // an occlusion query to find out if it's an occluder
         markOccluder(group);
     }
-	mNumVisibleNodes++;
+    mNumVisibleNodes++;
 }
 
 void LLPipeline::markOccluder(LLSpatialGroup* group)
 {
-	if (sUseOcclusion > 1 && group && !group->isOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION))
-	{
-		LLSpatialGroup* parent = group->getParent();
-
-		if (!parent || !parent->isOcclusionState(LLSpatialGroup::OCCLUDED))
-		{ //only mark top most occluders as active occlusion
-			sCull->pushOcclusionGroup(group);
-			group->setOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
-				
-			if (parent && 
-				!parent->isOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION) &&
-				parent->getElementCount() == 0 &&
-				parent->needsUpdate())
-			{
-				sCull->pushOcclusionGroup(group);
-				parent->setOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
-			}
-		}
-	}
-}
+    if (sUseOcclusion > 1 && group && !group->isOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION))
+    {
+        LLSpatialGroup* parent = group->getParent();
+
+        if (!parent || !parent->isOcclusionState(LLSpatialGroup::OCCLUDED))
+        { //only mark top most occluders as active occlusion
+            sCull->pushOcclusionGroup(group);
+            group->setOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
+
+            if (parent &&
+                !parent->isOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION) &&
+                parent->getElementCount() == 0 &&
+                parent->needsUpdate())
+            {
+                sCull->pushOcclusionGroup(group);
+                parent->setOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
+            }
+        }
+    }
+}
 
 void LLPipeline::doOcclusion(LLCamera& camera)
 {
@@ -2575,7 +2575,7 @@ void LLPipeline::doOcclusion(LLCamera& camera)
 
         gGL.setColorMask(true, true);
     }
-    
+
     if (sReflectionProbesEnabled && sUseOcclusion > 1 && !LLPipeline::sShadowRender && !gCubeSnapshot)
     {
         gGL.setColorMask(false, false);
@@ -2597,129 +2597,129 @@ void LLPipeline::doOcclusion(LLCamera& camera)
     }
 
     if (LLPipeline::sUseOcclusion > 1 &&
-		(sCull->hasOcclusionGroups() || LLVOCachePartition::sNeedsOcclusionCheck))
-	{
-		LLVertexBuffer::unbind();
+        (sCull->hasOcclusionGroups() || LLVOCachePartition::sNeedsOcclusionCheck))
+    {
+        LLVertexBuffer::unbind();
 
-		gGL.setColorMask(false, false);
+        gGL.setColorMask(false, false);
 
-		LLGLDisable blend(GL_BLEND);
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-		LLGLDepthTest depth(GL_TRUE, GL_FALSE);
+        LLGLDisable blend(GL_BLEND);
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+        LLGLDepthTest depth(GL_TRUE, GL_FALSE);
 
-		LLGLDisable cull(GL_CULL_FACE);
+        LLGLDisable cull(GL_CULL_FACE);
 
         gOcclusionCubeProgram.bind();
 
-		if (mCubeVB.isNull())
-		{ //cube VB will be used for issuing occlusion queries
-			mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX);
-		}
-		mCubeVB->setBuffer();
+        if (mCubeVB.isNull())
+        { //cube VB will be used for issuing occlusion queries
+            mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX);
+        }
+        mCubeVB->setBuffer();
 
-		for (LLCullResult::sg_iterator iter = sCull->beginOcclusionGroups(); iter != sCull->endOcclusionGroups(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
+        for (LLCullResult::sg_iterator iter = sCull->beginOcclusionGroups(); iter != sCull->endOcclusionGroups(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
             if (!group->isDead())
             {
                 group->doOcclusion(&camera);
                 group->clearOcclusionState(LLSpatialGroup::ACTIVE_OCCLUSION);
             }
-		}
-	
-		//apply occlusion culling to object cache tree
-		for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin(); 
-			iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
-		{
-			LLVOCachePartition* vo_part = (*iter)->getVOCachePartition();
-			if(vo_part)
-			{
-				vo_part->processOccluders(&camera);
-			}
-		}
-
-		gGL.setColorMask(true, true);
-	}
-}
-	
+        }
+
+        //apply occlusion culling to object cache tree
+        for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin();
+            iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
+        {
+            LLVOCachePartition* vo_part = (*iter)->getVOCachePartition();
+            if(vo_part)
+            {
+                vo_part->processOccluders(&camera);
+            }
+        }
+
+        gGL.setColorMask(true, true);
+    }
+}
+
 bool LLPipeline::updateDrawableGeom(LLDrawable* drawablep)
 {
-	bool update_complete = drawablep->updateGeometry();
-	if (update_complete && assertInitialized())
-	{
-		drawablep->setState(LLDrawable::BUILT);
-	}
-	return update_complete;
+    bool update_complete = drawablep->updateGeometry();
+    if (update_complete && assertInitialized())
+    {
+        drawablep->setState(LLDrawable::BUILT);
+    }
+    return update_complete;
 }
 
 void LLPipeline::updateGL()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	{
-		while (!LLGLUpdate::sGLQ.empty())
-		{
-			LLGLUpdate* glu = LLGLUpdate::sGLQ.front();
-			glu->updateGL();
-			glu->mInQ = FALSE;
-			LLGLUpdate::sGLQ.pop_front();
-		}
-	}
+    {
+        while (!LLGLUpdate::sGLQ.empty())
+        {
+            LLGLUpdate* glu = LLGLUpdate::sGLQ.front();
+            glu->updateGL();
+            glu->mInQ = FALSE;
+            LLGLUpdate::sGLQ.pop_front();
+        }
+    }
 }
 
 void LLPipeline::clearRebuildGroups()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	LLSpatialGroup::sg_vector_t	hudGroups;
-
-	mGroupQ1Locked = true;
-	// Iterate through all drawables on the priority build queue,
-	for (LLSpatialGroup* group : mGroupQ1)
-	{
-		// If the group contains HUD objects, save the group
-		if (group->isHUDGroup())
-		{
-			hudGroups.push_back(group);
-		}
-		// Else, no HUD objects so clear the build state
-		else
-		{
-			group->clearState(LLSpatialGroup::IN_BUILD_Q1);
-		}
-	}
-
-	// Clear the group
-	mGroupQ1.clear();
-
-	// Copy the saved HUD groups back in
-	mGroupQ1.assign(hudGroups.begin(), hudGroups.end());
-	mGroupQ1Locked = false;
+    LLSpatialGroup::sg_vector_t hudGroups;
+
+    mGroupQ1Locked = true;
+    // Iterate through all drawables on the priority build queue,
+    for (LLSpatialGroup* group : mGroupQ1)
+    {
+        // If the group contains HUD objects, save the group
+        if (group->isHUDGroup())
+        {
+            hudGroups.push_back(group);
+        }
+        // Else, no HUD objects so clear the build state
+        else
+        {
+            group->clearState(LLSpatialGroup::IN_BUILD_Q1);
+        }
+    }
+
+    // Clear the group
+    mGroupQ1.clear();
+
+    // Copy the saved HUD groups back in
+    mGroupQ1.assign(hudGroups.begin(), hudGroups.end());
+    mGroupQ1Locked = false;
 }
 
 void LLPipeline::clearRebuildDrawables()
 {
-	// Clear all drawables on the priority build queue,
-	for (LLDrawable* drawablep : mBuildQ1)
-	{
-		if (drawablep && !drawablep->isDead())
-		{
-			drawablep->clearState(LLDrawable::IN_REBUILD_Q);
-		}
-	}
-	mBuildQ1.clear();
-
-	//clear all moving bridges
-	for (LLDrawable* drawablep : mMovedBridge)
-	{
-		drawablep->clearState(LLDrawable::EARLY_MOVE | LLDrawable::MOVE_UNDAMPED | LLDrawable::ON_MOVE_LIST | LLDrawable::ANIMATED_CHILD);
-	}
-	mMovedBridge.clear();
-
-	//clear all moving drawables
-	for (LLDrawable* drawablep : mMovedList)
-	{
-		drawablep->clearState(LLDrawable::EARLY_MOVE | LLDrawable::MOVE_UNDAMPED | LLDrawable::ON_MOVE_LIST | LLDrawable::ANIMATED_CHILD);
-	}
-	mMovedList.clear();
+    // Clear all drawables on the priority build queue,
+    for (LLDrawable* drawablep : mBuildQ1)
+    {
+        if (drawablep && !drawablep->isDead())
+        {
+            drawablep->clearState(LLDrawable::IN_REBUILD_Q);
+        }
+    }
+    mBuildQ1.clear();
+
+    //clear all moving bridges
+    for (LLDrawable* drawablep : mMovedBridge)
+    {
+        drawablep->clearState(LLDrawable::EARLY_MOVE | LLDrawable::MOVE_UNDAMPED | LLDrawable::ON_MOVE_LIST | LLDrawable::ANIMATED_CHILD);
+    }
+    mMovedBridge.clear();
+
+    //clear all moving drawables
+    for (LLDrawable* drawablep : mMovedList)
+    {
+        drawablep->clearState(LLDrawable::EARLY_MOVE | LLDrawable::MOVE_UNDAMPED | LLDrawable::ON_MOVE_LIST | LLDrawable::ANIMATED_CHILD);
+    }
+    mMovedList.clear();
 
     for (LLDrawable::drawable_vector_t::iterator iter = mShiftList.begin();
         iter != mShiftList.end(); ++iter)
@@ -2735,298 +2735,298 @@ void LLPipeline::rebuildPriorityGroups()
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
     LL_PROFILE_GPU_ZONE("rebuildPriorityGroups");
 
-	LLTimer update_timer;
-	assertInitialized();
+    LLTimer update_timer;
+    assertInitialized();
 
-	gMeshRepo.notifyLoadedMeshes();
+    gMeshRepo.notifyLoadedMeshes();
 
-	mGroupQ1Locked = true;
-	// Iterate through all drawables on the priority build queue,
-	for (LLSpatialGroup* group : mGroupQ1)
-	{
-		group->rebuildGeom();
-		group->clearState(LLSpatialGroup::IN_BUILD_Q1);
-	}
+    mGroupQ1Locked = true;
+    // Iterate through all drawables on the priority build queue,
+    for (LLSpatialGroup* group : mGroupQ1)
+    {
+        group->rebuildGeom();
+        group->clearState(LLSpatialGroup::IN_BUILD_Q1);
+    }
 
-	mGroupSaveQ1 = mGroupQ1;
-	mGroupQ1.clear();
-	mGroupQ1Locked = false;
+    mGroupSaveQ1 = mGroupQ1;
+    mGroupQ1.clear();
+    mGroupQ1Locked = false;
 
 }
 
 void LLPipeline::updateGeom(F32 max_dtime)
 {
-	LLTimer update_timer;
-	LLPointer<LLDrawable> drawablep;
+    LLTimer update_timer;
+    LLPointer<LLDrawable> drawablep;
 
-	LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWABLE("updateGeom") //LL_RECORD_BLOCK_TIME(FTM_GEO_UPDATE);
+    LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWABLE("updateGeom") //LL_RECORD_BLOCK_TIME(FTM_GEO_UPDATE);
     if (gCubeSnapshot)
     {
         return;
     }
 
-	assertInitialized();
-
-	// notify various object types to reset internal cost metrics, etc.
-	// for now, only LLVOVolume does this to throttle LOD changes
-	LLVOVolume::preUpdateGeom();
-
-	// Iterate through all drawables on the priority build queue,
-	for (LLDrawable::drawable_list_t::iterator iter = mBuildQ1.begin();
-		 iter != mBuildQ1.end();)
-	{
-		LLDrawable::drawable_list_t::iterator curiter = iter++;
-		LLDrawable* drawablep = *curiter;
-		if (drawablep && !drawablep->isDead())
-		{
-			if (drawablep->isUnload())
-			{
-				drawablep->unload();
-				drawablep->clearState(LLDrawable::FOR_UNLOAD);
-			}
-
-			if (updateDrawableGeom(drawablep))
-			{
-				drawablep->clearState(LLDrawable::IN_REBUILD_Q);
-				mBuildQ1.erase(curiter);
-			}
-		}
-		else
-		{
-			mBuildQ1.erase(curiter);
-		}
-	}
-
-	updateMovedList(mMovedBridge);
+    assertInitialized();
+
+    // notify various object types to reset internal cost metrics, etc.
+    // for now, only LLVOVolume does this to throttle LOD changes
+    LLVOVolume::preUpdateGeom();
+
+    // Iterate through all drawables on the priority build queue,
+    for (LLDrawable::drawable_list_t::iterator iter = mBuildQ1.begin();
+         iter != mBuildQ1.end();)
+    {
+        LLDrawable::drawable_list_t::iterator curiter = iter++;
+        LLDrawable* drawablep = *curiter;
+        if (drawablep && !drawablep->isDead())
+        {
+            if (drawablep->isUnload())
+            {
+                drawablep->unload();
+                drawablep->clearState(LLDrawable::FOR_UNLOAD);
+            }
+
+            if (updateDrawableGeom(drawablep))
+            {
+                drawablep->clearState(LLDrawable::IN_REBUILD_Q);
+                mBuildQ1.erase(curiter);
+            }
+        }
+        else
+        {
+            mBuildQ1.erase(curiter);
+        }
+    }
+
+    updateMovedList(mMovedBridge);
 }
 
 void LLPipeline::markVisible(LLDrawable *drawablep, LLCamera& camera)
 {
-	if(drawablep && !drawablep->isDead())
-	{
-		if (drawablep->isSpatialBridge())
-		{
-			const LLDrawable* root = ((LLSpatialBridge*) drawablep)->mDrawable;
-			llassert(root); // trying to catch a bad assumption
-					
-			if (root && //  // this test may not be needed, see above
-					root->getVObj()->isAttachment())
-			{
-				LLDrawable* rootparent = root->getParent();
-				if (rootparent) // this IS sometimes NULL
-				{
-					LLViewerObject *vobj = rootparent->getVObj();
-					llassert(vobj); // trying to catch a bad assumption
-					if (vobj) // this test may not be needed, see above
-					{
-						LLVOAvatar* av = vobj->asAvatar();
-						if (av &&
-							((!sImpostorRender && av->isImpostor()) //ignore impostor flag during impostor pass
-							 || av->isInMuteList() 
-							 || (LLVOAvatar::AOA_JELLYDOLL == av->getOverallAppearance() && !av->needsImpostorUpdate()) ))
-						{
-							return;
-						}
-					}
-				}
-			}
-			sCull->pushBridge((LLSpatialBridge*) drawablep);
-		}
-		else
-		{
-		
-			sCull->pushDrawable(drawablep);
-		}
-
-		drawablep->setVisible(camera);
-	}
+    if(drawablep && !drawablep->isDead())
+    {
+        if (drawablep->isSpatialBridge())
+        {
+            const LLDrawable* root = ((LLSpatialBridge*) drawablep)->mDrawable;
+            llassert(root); // trying to catch a bad assumption
+
+            if (root && //  // this test may not be needed, see above
+                    root->getVObj()->isAttachment())
+            {
+                LLDrawable* rootparent = root->getParent();
+                if (rootparent) // this IS sometimes NULL
+                {
+                    LLViewerObject *vobj = rootparent->getVObj();
+                    llassert(vobj); // trying to catch a bad assumption
+                    if (vobj) // this test may not be needed, see above
+                    {
+                        LLVOAvatar* av = vobj->asAvatar();
+                        if (av &&
+                            ((!sImpostorRender && av->isImpostor()) //ignore impostor flag during impostor pass
+                             || av->isInMuteList()
+                             || (LLVOAvatar::AOA_JELLYDOLL == av->getOverallAppearance() && !av->needsImpostorUpdate()) ))
+                        {
+                            return;
+                        }
+                    }
+                }
+            }
+            sCull->pushBridge((LLSpatialBridge*) drawablep);
+        }
+        else
+        {
+
+            sCull->pushDrawable(drawablep);
+        }
+
+        drawablep->setVisible(camera);
+    }
 }
 
 void LLPipeline::markMoved(LLDrawable *drawablep, bool damped_motion)
 {
-	if (!drawablep)
-	{
-		//LL_ERRS() << "Sending null drawable to moved list!" << LL_ENDL;
-		return;
-	}
-	
-	if (drawablep->isDead())
-	{
-		LL_WARNS() << "Marking NULL or dead drawable moved!" << LL_ENDL;
-		return;
-	}
-	
-	if (drawablep->getParent()) 
-	{
-		//ensure that parent drawables are moved first
-		markMoved(drawablep->getParent(), damped_motion);
-	}
-
-	assertInitialized();
-
-	if (!drawablep->isState(LLDrawable::ON_MOVE_LIST))
-	{
-		if (drawablep->isSpatialBridge())
-		{
-			mMovedBridge.push_back(drawablep);
-		}
-		else
-		{
-			mMovedList.push_back(drawablep);
-		}
-		drawablep->setState(LLDrawable::ON_MOVE_LIST);
-	}
-	if (! damped_motion)
-	{
-		drawablep->setState(LLDrawable::MOVE_UNDAMPED); // UNDAMPED trumps DAMPED
-	}
-	else if (drawablep->isState(LLDrawable::MOVE_UNDAMPED))
-	{
-		drawablep->clearState(LLDrawable::MOVE_UNDAMPED);
-	}
+    if (!drawablep)
+    {
+        //LL_ERRS() << "Sending null drawable to moved list!" << LL_ENDL;
+        return;
+    }
+
+    if (drawablep->isDead())
+    {
+        LL_WARNS() << "Marking NULL or dead drawable moved!" << LL_ENDL;
+        return;
+    }
+
+    if (drawablep->getParent())
+    {
+        //ensure that parent drawables are moved first
+        markMoved(drawablep->getParent(), damped_motion);
+    }
+
+    assertInitialized();
+
+    if (!drawablep->isState(LLDrawable::ON_MOVE_LIST))
+    {
+        if (drawablep->isSpatialBridge())
+        {
+            mMovedBridge.push_back(drawablep);
+        }
+        else
+        {
+            mMovedList.push_back(drawablep);
+        }
+        drawablep->setState(LLDrawable::ON_MOVE_LIST);
+    }
+    if (! damped_motion)
+    {
+        drawablep->setState(LLDrawable::MOVE_UNDAMPED); // UNDAMPED trumps DAMPED
+    }
+    else if (drawablep->isState(LLDrawable::MOVE_UNDAMPED))
+    {
+        drawablep->clearState(LLDrawable::MOVE_UNDAMPED);
+    }
 }
 
 void LLPipeline::markShift(LLDrawable *drawablep)
 {
-	if (!drawablep || drawablep->isDead())
-	{
-		return;
-	}
+    if (!drawablep || drawablep->isDead())
+    {
+        return;
+    }
 
-	assertInitialized();
+    assertInitialized();
 
-	if (!drawablep->isState(LLDrawable::ON_SHIFT_LIST))
-	{
-		drawablep->getVObj()->setChanged(LLXform::SHIFTED | LLXform::SILHOUETTE);
-		if (drawablep->getParent()) 
-		{
-			markShift(drawablep->getParent());
-		}
-		mShiftList.push_back(drawablep);
-		drawablep->setState(LLDrawable::ON_SHIFT_LIST);
-	}
+    if (!drawablep->isState(LLDrawable::ON_SHIFT_LIST))
+    {
+        drawablep->getVObj()->setChanged(LLXform::SHIFTED | LLXform::SILHOUETTE);
+        if (drawablep->getParent())
+        {
+            markShift(drawablep->getParent());
+        }
+        mShiftList.push_back(drawablep);
+        drawablep->setState(LLDrawable::ON_SHIFT_LIST);
+    }
 }
 
 void LLPipeline::shiftObjects(const LLVector3 &offset)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	assertInitialized();
-
-	glClear(GL_DEPTH_BUFFER_BIT);
-	gDepthDirty = true;
-		
-	LLVector4a offseta;
-	offseta.load3(offset.mV);
-
-	for (LLDrawable* drawablep : mShiftList)
-	{
-		if (drawablep->isDead())
-		{
-			continue;
-		}	
-		drawablep->shiftPos(offseta);	
-		drawablep->clearState(LLDrawable::ON_SHIFT_LIST);
-	}
-	mShiftList.resize(0);
-	
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
-		{
-			LLSpatialPartition* part = region->getSpatialPartition(i);
-			if (part)
-			{
-				part->shift(offseta);
-			}
-		}
-	}
+    assertInitialized();
+
+    glClear(GL_DEPTH_BUFFER_BIT);
+    gDepthDirty = true;
+
+    LLVector4a offseta;
+    offseta.load3(offset.mV);
+
+    for (LLDrawable* drawablep : mShiftList)
+    {
+        if (drawablep->isDead())
+        {
+            continue;
+        }
+        drawablep->shiftPos(offseta);
+        drawablep->clearState(LLDrawable::ON_SHIFT_LIST);
+    }
+    mShiftList.resize(0);
+
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
+        {
+            LLSpatialPartition* part = region->getSpatialPartition(i);
+            if (part)
+            {
+                part->shift(offseta);
+            }
+        }
+    }
 
     mReflectionMapManager.shift(offseta);
 
-	LLHUDText::shiftAll(offset);
-	LLHUDNameTag::shiftAll(offset);
+    LLHUDText::shiftAll(offset);
+    LLHUDNameTag::shiftAll(offset);
 
-	display_update_camera();
+    display_update_camera();
 }
 
 void LLPipeline::markTextured(LLDrawable *drawablep)
 {
-	if (drawablep && !drawablep->isDead() && assertInitialized())
-	{
-		mRetexturedList.insert(drawablep);
-	}
+    if (drawablep && !drawablep->isDead() && assertInitialized())
+    {
+        mRetexturedList.insert(drawablep);
+    }
 }
 
 void LLPipeline::markGLRebuild(LLGLUpdate* glu)
 {
-	if (glu && !glu->mInQ)
-	{
-		LLGLUpdate::sGLQ.push_back(glu);
-		glu->mInQ = TRUE;
-	}
+    if (glu && !glu->mInQ)
+    {
+        LLGLUpdate::sGLQ.push_back(glu);
+        glu->mInQ = TRUE;
+    }
 }
 
 void LLPipeline::markPartitionMove(LLDrawable* drawable)
 {
-	if (!drawable->isState(LLDrawable::PARTITION_MOVE) && 
-		!drawable->getPositionGroup().equals3(LLVector4a::getZero()))
-	{
-		drawable->setState(LLDrawable::PARTITION_MOVE);
-		mPartitionQ.push_back(drawable);
-	}
+    if (!drawable->isState(LLDrawable::PARTITION_MOVE) &&
+        !drawable->getPositionGroup().equals3(LLVector4a::getZero()))
+    {
+        drawable->setState(LLDrawable::PARTITION_MOVE);
+        mPartitionQ.push_back(drawable);
+    }
 }
 
 void LLPipeline::processPartitionQ()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	for (LLDrawable* drawable : mPartitionQ)
-	{
-		if (!drawable->isDead())
-		{
-			drawable->updateBinRadius();
-			drawable->movePartition();
-		}
-		drawable->clearState(LLDrawable::PARTITION_MOVE);
-	}
+    for (LLDrawable* drawable : mPartitionQ)
+    {
+        if (!drawable->isDead())
+        {
+            drawable->updateBinRadius();
+            drawable->movePartition();
+        }
+        drawable->clearState(LLDrawable::PARTITION_MOVE);
+    }
 
-	mPartitionQ.clear();
+    mPartitionQ.clear();
 }
 
 void LLPipeline::markMeshDirty(LLSpatialGroup* group)
 {
-	mMeshDirtyGroup.push_back(group);
+    mMeshDirtyGroup.push_back(group);
 }
 
 void LLPipeline::markRebuild(LLSpatialGroup* group)
 {
-	if (group && !group->isDead() && group->getSpatialPartition())
-	{
-		if (!group->hasState(LLSpatialGroup::IN_BUILD_Q1))
-		{
-			llassert_always(!mGroupQ1Locked);
+    if (group && !group->isDead() && group->getSpatialPartition())
+    {
+        if (!group->hasState(LLSpatialGroup::IN_BUILD_Q1))
+        {
+            llassert_always(!mGroupQ1Locked);
 
-			mGroupQ1.push_back(group);
-			group->setState(LLSpatialGroup::IN_BUILD_Q1);
-		}
-	}
+            mGroupQ1.push_back(group);
+            group->setState(LLSpatialGroup::IN_BUILD_Q1);
+        }
+    }
 }
 
 void LLPipeline::markRebuild(LLDrawable *drawablep, LLDrawable::EDrawableFlags flag)
 {
-	if (drawablep && !drawablep->isDead() && assertInitialized())
-	{
-		if (!drawablep->isState(LLDrawable::IN_REBUILD_Q))
-		{
-			mBuildQ1.push_back(drawablep);
-			drawablep->setState(LLDrawable::IN_REBUILD_Q); // mark drawable as being in priority queue
-		}
+    if (drawablep && !drawablep->isDead() && assertInitialized())
+    {
+        if (!drawablep->isState(LLDrawable::IN_REBUILD_Q))
+        {
+            mBuildQ1.push_back(drawablep);
+            drawablep->setState(LLDrawable::IN_REBUILD_Q); // mark drawable as being in priority queue
+        }
 
-		if ((flag & (LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION)) && drawablep->getVObj().notNull())
-		{
-			drawablep->getVObj()->setChanged(LLXform::SILHOUETTE);
-		}
-		drawablep->setState(flag);
-	}
+        if ((flag & (LLDrawable::REBUILD_VOLUME | LLDrawable::REBUILD_POSITION)) && drawablep->getVObj().notNull())
+        {
+            drawablep->getVObj()->setChanged(LLXform::SILHOUETTE);
+        }
+        drawablep->setState(flag);
+    }
 }
 
 void LLPipeline::stateSort(LLCamera& camera, LLCullResult &result)
@@ -3034,313 +3034,313 @@ void LLPipeline::stateSort(LLCamera& camera, LLCullResult &result)
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
     LL_PROFILE_GPU_ZONE("stateSort");
 
-	if (hasAnyRenderType(LLPipeline::RENDER_TYPE_AVATAR,
-					  LLPipeline::RENDER_TYPE_CONTROL_AV,
-					  LLPipeline::RENDER_TYPE_TERRAIN,
-					  LLPipeline::RENDER_TYPE_TREE,
-					  LLPipeline::RENDER_TYPE_SKY,
-					  LLPipeline::RENDER_TYPE_VOIDWATER,
-					  LLPipeline::RENDER_TYPE_WATER,
-					  LLPipeline::END_RENDER_TYPES))
-	{
-		//clear faces from face pools
-		gPipeline.resetDrawOrders();
-	}
-
-	//LLVertexBuffer::unbind();
-
-	grabReferences(result);
-	for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(), iter_end = sCull->endDrawableGroups(); iter != iter_end; ++iter)
-	{
-		LLSpatialGroup* group = *iter;
+    if (hasAnyRenderType(LLPipeline::RENDER_TYPE_AVATAR,
+                      LLPipeline::RENDER_TYPE_CONTROL_AV,
+                      LLPipeline::RENDER_TYPE_TERRAIN,
+                      LLPipeline::RENDER_TYPE_TREE,
+                      LLPipeline::RENDER_TYPE_SKY,
+                      LLPipeline::RENDER_TYPE_VOIDWATER,
+                      LLPipeline::RENDER_TYPE_WATER,
+                      LLPipeline::END_RENDER_TYPES))
+    {
+        //clear faces from face pools
+        gPipeline.resetDrawOrders();
+    }
+
+    //LLVertexBuffer::unbind();
+
+    grabReferences(result);
+    for (LLCullResult::sg_iterator iter = sCull->beginDrawableGroups(), iter_end = sCull->endDrawableGroups(); iter != iter_end; ++iter)
+    {
+        LLSpatialGroup* group = *iter;
         if (group->isDead())
         {
             continue;
         }
-		group->checkOcclusion();
-		if (sUseOcclusion > 1 && group->isOcclusionState(LLSpatialGroup::OCCLUDED))
-		{
-			markOccluder(group);
-		}
-		else
-		{
-			group->setVisible();
-			for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
-			{
+        group->checkOcclusion();
+        if (sUseOcclusion > 1 && group->isOcclusionState(LLSpatialGroup::OCCLUDED))
+        {
+            markOccluder(group);
+        }
+        else
+        {
+            group->setVisible();
+            for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
+            {
                 LLDrawable* drawablep = (LLDrawable*)(*i)->getDrawable();
-				markVisible(drawablep, camera);
-			}
-
-			{ //rebuild mesh as soon as we know it's visible
-				group->rebuildMesh();
-			}
-		}
-	}
-
-	if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD && !gCubeSnapshot)
-	{
-		LLSpatialGroup* last_group = NULL;
-		BOOL fov_changed = LLViewerCamera::getInstance()->isDefaultFOVChanged();
-		for (LLCullResult::bridge_iterator i = sCull->beginVisibleBridge(), i_end = sCull->endVisibleBridge(); i != i_end; ++i)
-		{
-			LLCullResult::bridge_iterator cur_iter = i;
-			LLSpatialBridge* bridge = *cur_iter;
-			LLSpatialGroup* group = bridge->getSpatialGroup();
-
-			if (last_group == NULL)
-			{
-				last_group = group;
-			}
-
-			if (!bridge->isDead() && group && !group->isOcclusionState(LLSpatialGroup::OCCLUDED))
-			{
-				stateSort(bridge, camera, fov_changed);
-			}
-
-			if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD &&
-				last_group != group && last_group->changeLOD())
-			{
-				last_group->mLastUpdateDistance = last_group->mDistance;
-			}
-
-			last_group = group;
-		}
-
-		if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD &&
-			last_group && last_group->changeLOD())
-		{
-			last_group->mLastUpdateDistance = last_group->mDistance;
-		}
-	}
-
-	for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(), iter_end = sCull->endVisibleGroups(); iter != iter_end; ++iter)
-	{
-		LLSpatialGroup* group = *iter;
+                markVisible(drawablep, camera);
+            }
+
+            { //rebuild mesh as soon as we know it's visible
+                group->rebuildMesh();
+            }
+        }
+    }
+
+    if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD && !gCubeSnapshot)
+    {
+        LLSpatialGroup* last_group = NULL;
+        BOOL fov_changed = LLViewerCamera::getInstance()->isDefaultFOVChanged();
+        for (LLCullResult::bridge_iterator i = sCull->beginVisibleBridge(), i_end = sCull->endVisibleBridge(); i != i_end; ++i)
+        {
+            LLCullResult::bridge_iterator cur_iter = i;
+            LLSpatialBridge* bridge = *cur_iter;
+            LLSpatialGroup* group = bridge->getSpatialGroup();
+
+            if (last_group == NULL)
+            {
+                last_group = group;
+            }
+
+            if (!bridge->isDead() && group && !group->isOcclusionState(LLSpatialGroup::OCCLUDED))
+            {
+                stateSort(bridge, camera, fov_changed);
+            }
+
+            if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD &&
+                last_group != group && last_group->changeLOD())
+            {
+                last_group->mLastUpdateDistance = last_group->mDistance;
+            }
+
+            last_group = group;
+        }
+
+        if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD &&
+            last_group && last_group->changeLOD())
+        {
+            last_group->mLastUpdateDistance = last_group->mDistance;
+        }
+    }
+
+    for (LLCullResult::sg_iterator iter = sCull->beginVisibleGroups(), iter_end = sCull->endVisibleGroups(); iter != iter_end; ++iter)
+    {
+        LLSpatialGroup* group = *iter;
         if (group->isDead())
         {
             continue;
         }
-		group->checkOcclusion();
-		if (sUseOcclusion > 1 && group->isOcclusionState(LLSpatialGroup::OCCLUDED))
-		{
-			markOccluder(group);
-		}
-		else
-		{
-			group->setVisible();
-			stateSort(group, camera);
-
-			{ //rebuild mesh as soon as we know it's visible
-				group->rebuildMesh();
-			}
-		}
-	}
-	
-	{
-		LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWABLE("stateSort"); // LL_RECORD_BLOCK_TIME(FTM_STATESORT_DRAWABLE);
-		for (LLCullResult::drawable_iterator iter = sCull->beginVisibleList(), iter_end = sCull->endVisibleList();
-			 iter != iter_end; ++iter)
-		{
-			LLDrawable *drawablep = *iter;
-			if (!drawablep->isDead())
-			{
-				stateSort(drawablep, camera);
-			}
-		}
-	}
-		
-	postSort(camera);	
+        group->checkOcclusion();
+        if (sUseOcclusion > 1 && group->isOcclusionState(LLSpatialGroup::OCCLUDED))
+        {
+            markOccluder(group);
+        }
+        else
+        {
+            group->setVisible();
+            stateSort(group, camera);
+
+            { //rebuild mesh as soon as we know it's visible
+                group->rebuildMesh();
+            }
+        }
+    }
+
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWABLE("stateSort"); // LL_RECORD_BLOCK_TIME(FTM_STATESORT_DRAWABLE);
+        for (LLCullResult::drawable_iterator iter = sCull->beginVisibleList(), iter_end = sCull->endVisibleList();
+             iter != iter_end; ++iter)
+        {
+            LLDrawable *drawablep = *iter;
+            if (!drawablep->isDead())
+            {
+                stateSort(drawablep, camera);
+            }
+        }
+    }
+
+    postSort(camera);
 }
 
 void LLPipeline::stateSort(LLSpatialGroup* group, LLCamera& camera)
 {
-	if (group->changeLOD())
-	{
-		for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
-		{
-            LLDrawable* drawablep = (LLDrawable*)(*i)->getDrawable();            
-			stateSort(drawablep, camera);
-		}
+    if (group->changeLOD())
+    {
+        for (LLSpatialGroup::element_iter i = group->getDataBegin(), i_end = group->getDataEnd(); i != i_end; ++i)
+        {
+            LLDrawable* drawablep = (LLDrawable*)(*i)->getDrawable();
+            stateSort(drawablep, camera);
+        }
 
-		if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD && !gCubeSnapshot)
-		{ //avoid redundant stateSort calls
-			group->mLastUpdateDistance = group->mDistance;
-		}
-	}
+        if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD && !gCubeSnapshot)
+        { //avoid redundant stateSort calls
+            group->mLastUpdateDistance = group->mDistance;
+        }
+    }
 }
 
 void LLPipeline::stateSort(LLSpatialBridge* bridge, LLCamera& camera, BOOL fov_changed)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
     if (bridge->getSpatialGroup()->changeLOD() || fov_changed)
-	{
-		bool force_update = false;
-		bridge->updateDistance(camera, force_update);
-	}
+    {
+        bool force_update = false;
+        bridge->updateDistance(camera, force_update);
+    }
 }
 
 void LLPipeline::stateSort(LLDrawable* drawablep, LLCamera& camera)
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
     if (!drawablep
-		|| drawablep->isDead() 
-		|| !hasRenderType(drawablep->getRenderType()))
-	{
-		return;
-	}
-	
+        || drawablep->isDead()
+        || !hasRenderType(drawablep->getRenderType()))
+    {
+        return;
+    }
+
     // SL-11353
     // ignore our own geo when rendering spotlight shadowmaps...
-    // 
+    //
     if (RenderSpotLight && drawablep == RenderSpotLight)
     {
         return;
     }
 
-	if (LLSelectMgr::getInstance()->mHideSelectedObjects)
-	{
-//		if (drawablep->getVObj().notNull() &&
-//			drawablep->getVObj()->isSelected())
+    if (LLSelectMgr::getInstance()->mHideSelectedObjects)
+    {
+//      if (drawablep->getVObj().notNull() &&
+//          drawablep->getVObj()->isSelected())
 // [RLVa:KB] - Checked: 2010-09-28 (RLVa-1.2.1f) | Modified: RLVa-1.2.1f
-		const LLViewerObject* pObj = drawablep->getVObj();
-		if ( (pObj) && (pObj->isSelected()) && 
-			 ( (!RlvActions::isRlvEnabled()) || 
-			   ( ((!pObj->isHUDAttachment()) || (!gRlvAttachmentLocks.isLockedAttachment(pObj->getRootEdit()))) && 
-			     (RlvActions::canEdit(pObj)) ) ) )
+        const LLViewerObject* pObj = drawablep->getVObj();
+        if ( (pObj) && (pObj->isSelected()) &&
+             ( (!RlvActions::isRlvEnabled()) ||
+               ( ((!pObj->isHUDAttachment()) || (!gRlvAttachmentLocks.isLockedAttachment(pObj->getRootEdit()))) &&
+                 (RlvActions::canEdit(pObj)) ) ) )
 // [/RVLa:KB]
-		{
-			return;
-		}
-	}
-
-	if (drawablep->isAvatar())
-	{ //don't draw avatars beyond render distance or if we don't have a spatial group.
-		if ((drawablep->getSpatialGroup() == NULL) || 
-			(drawablep->getSpatialGroup()->mDistance > LLVOAvatar::sRenderDistance))
-		{
-			return;
-		}
-
-		LLVOAvatar* avatarp = (LLVOAvatar*) drawablep->getVObj().get();
-		if (!avatarp->isVisible())
-		{
-			return;
-		}
-	}
-
-	assertInitialized();
-
-	if (hasRenderType(drawablep->mRenderType))
-	{
-		if (!drawablep->isState(LLDrawable::INVISIBLE|LLDrawable::FORCE_INVISIBLE))
-		{
-			drawablep->setVisible(camera, NULL, FALSE);
-		}
-	}
-
-	if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD && !gCubeSnapshot)
-	{
-		//if (drawablep->isVisible()) isVisible() check here is redundant, if it wasn't visible, it wouldn't be here
-		{
-			if (!drawablep->isActive())
-			{
-				bool force_update = false;
-				drawablep->updateDistance(camera, force_update);
-			}
-			else if (drawablep->isAvatar())
-			{
-				bool force_update = false;
-				drawablep->updateDistance(camera, force_update); // calls vobj->updateLOD() which calls LLVOAvatar::updateVisibility()
-			}
-		}
-	}
-
-	if (!drawablep->getVOVolume())
-	{
-		for (LLFace* facep : drawablep->mFaces)
-		{
-			if (facep->hasGeometry())
-			{
-				if (facep->getPool())
-				{
-					facep->getPool()->enqueue(facep);
-				}
-				else
-				{
-					break;
-				}
-			}
-		}
-	}
-}
-
-
-void forAllDrawables(LLCullResult::sg_iterator begin, 
-					 LLCullResult::sg_iterator end,
-					 void (*func)(LLDrawable*))
-{
-	for (LLCullResult::sg_iterator i = begin; i != end; ++i)
-	{
-        LLSpatialGroup* group = *i;
-        if (group->isDead())
         {
-            continue;
+            return;
         }
-		for (LLSpatialGroup::element_iter j = group->getDataBegin(); j != group->getDataEnd(); ++j)
-		{
-			if((*j)->hasDrawable())
-			{
-				func((LLDrawable*)(*j)->getDrawable());	
-			}
-		}
-	}
-}
+    }
 
-void LLPipeline::forAllVisibleDrawables(void (*func)(LLDrawable*))
-{
-	forAllDrawables(sCull->beginDrawableGroups(), sCull->endDrawableGroups(), func);
-	forAllDrawables(sCull->beginVisibleGroups(), sCull->endVisibleGroups(), func);
-}
+    if (drawablep->isAvatar())
+    { //don't draw avatars beyond render distance or if we don't have a spatial group.
+        if ((drawablep->getSpatialGroup() == NULL) ||
+            (drawablep->getSpatialGroup()->mDistance > LLVOAvatar::sRenderDistance))
+        {
+            return;
+        }
 
-//function for creating scripted beacons
-void renderScriptedBeacons(LLDrawable* drawablep)
-{
-	LLViewerObject *vobj = drawablep->getVObj();
-	if (vobj 
-		&& !vobj->isAvatar() 
-		&& !vobj->getParent()
-		&& vobj->flagScripted())
-	{
-		if (gPipeline.sRenderBeacons)
-		{
-			gObjectList.addDebugBeacon(vobj->getPositionAgent(), "", LLColor4(1.f, 0.f, 0.f, 0.5f), LLColor4(1.f, 1.f, 1.f, 0.5f), LLPipeline::DebugBeaconLineWidth);
-		}
-
-		if (gPipeline.sRenderHighlight)
-		{
-			S32 face_id;
-			S32 count = drawablep->getNumFaces();
-			for (face_id = 0; face_id < count; face_id++)
-			{
-				LLFace * facep = drawablep->getFace(face_id);
-				if (facep) 
-				{
-					gPipeline.mHighlightFaces.push_back(facep);
-				}
-			}
-		}
-	}
-}
+        LLVOAvatar* avatarp = (LLVOAvatar*) drawablep->getVObj().get();
+        if (!avatarp->isVisible())
+        {
+            return;
+        }
+    }
 
-void renderScriptedTouchBeacons(LLDrawable *drawablep)
-{
-    LLViewerObject *vobj = drawablep->getVObj();
-    if (vobj && !vobj->isAvatar() && !vobj->getParent() && vobj->flagScripted() && vobj->flagHandleTouch())
+    assertInitialized();
+
+    if (hasRenderType(drawablep->mRenderType))
     {
-        if (gPipeline.sRenderBeacons)
+        if (!drawablep->isState(LLDrawable::INVISIBLE|LLDrawable::FORCE_INVISIBLE))
         {
-            gObjectList.addDebugBeacon(vobj->getPositionAgent(), "", LLColor4(1.f, 0.f, 0.f, 0.5f), LLColor4(1.f, 1.f, 1.f, 0.5f),
-                                       LLPipeline::DebugBeaconLineWidth);
+            drawablep->setVisible(camera, NULL, FALSE);
+        }
+    }
+
+    if (LLViewerCamera::sCurCameraID == LLViewerCamera::CAMERA_WORLD && !gCubeSnapshot)
+    {
+        //if (drawablep->isVisible()) isVisible() check here is redundant, if it wasn't visible, it wouldn't be here
+        {
+            if (!drawablep->isActive())
+            {
+                bool force_update = false;
+                drawablep->updateDistance(camera, force_update);
+            }
+            else if (drawablep->isAvatar())
+            {
+                bool force_update = false;
+                drawablep->updateDistance(camera, force_update); // calls vobj->updateLOD() which calls LLVOAvatar::updateVisibility()
+            }
+        }
+    }
+
+    if (!drawablep->getVOVolume())
+    {
+        for (LLFace* facep : drawablep->mFaces)
+        {
+            if (facep->hasGeometry())
+            {
+                if (facep->getPool())
+                {
+                    facep->getPool()->enqueue(facep);
+                }
+                else
+                {
+                    break;
+                }
+            }
+        }
+    }
+}
+
+
+void forAllDrawables(LLCullResult::sg_iterator begin,
+                     LLCullResult::sg_iterator end,
+                     void (*func)(LLDrawable*))
+{
+    for (LLCullResult::sg_iterator i = begin; i != end; ++i)
+    {
+        LLSpatialGroup* group = *i;
+        if (group->isDead())
+        {
+            continue;
+        }
+        for (LLSpatialGroup::element_iter j = group->getDataBegin(); j != group->getDataEnd(); ++j)
+        {
+            if((*j)->hasDrawable())
+            {
+                func((LLDrawable*)(*j)->getDrawable());
+            }
+        }
+    }
+}
+
+void LLPipeline::forAllVisibleDrawables(void (*func)(LLDrawable*))
+{
+    forAllDrawables(sCull->beginDrawableGroups(), sCull->endDrawableGroups(), func);
+    forAllDrawables(sCull->beginVisibleGroups(), sCull->endVisibleGroups(), func);
+}
+
+//function for creating scripted beacons
+void renderScriptedBeacons(LLDrawable* drawablep)
+{
+    LLViewerObject *vobj = drawablep->getVObj();
+    if (vobj
+        && !vobj->isAvatar()
+        && !vobj->getParent()
+        && vobj->flagScripted())
+    {
+        if (gPipeline.sRenderBeacons)
+        {
+            gObjectList.addDebugBeacon(vobj->getPositionAgent(), "", LLColor4(1.f, 0.f, 0.f, 0.5f), LLColor4(1.f, 1.f, 1.f, 0.5f), LLPipeline::DebugBeaconLineWidth);
+        }
+
+        if (gPipeline.sRenderHighlight)
+        {
+            S32 face_id;
+            S32 count = drawablep->getNumFaces();
+            for (face_id = 0; face_id < count; face_id++)
+            {
+                LLFace * facep = drawablep->getFace(face_id);
+                if (facep)
+                {
+                    gPipeline.mHighlightFaces.push_back(facep);
+                }
+            }
+        }
+    }
+}
+
+void renderScriptedTouchBeacons(LLDrawable *drawablep)
+{
+    LLViewerObject *vobj = drawablep->getVObj();
+    if (vobj && !vobj->isAvatar() && !vobj->getParent() && vobj->flagScripted() && vobj->flagHandleTouch())
+    {
+        if (gPipeline.sRenderBeacons)
+        {
+            gObjectList.addDebugBeacon(vobj->getPositionAgent(), "", LLColor4(1.f, 0.f, 0.f, 0.5f), LLColor4(1.f, 1.f, 1.f, 0.5f),
+                                       LLPipeline::DebugBeaconLineWidth);
         }
 
         if (gPipeline.sRenderHighlight)
@@ -3732,169 +3732,169 @@ void LLPipeline::postSort(LLCamera &camera)
 void render_hud_elements()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_UI; //LL_RECORD_BLOCK_TIME(FTM_RENDER_UI);
-	gPipeline.disableLights();
-	
-	LLGLSUIDefault gls_ui;
-
-	//LLGLEnable stencil(GL_STENCIL_TEST);
-	//glStencilFunc(GL_ALWAYS, 255, 0xFFFFFFFF);
-	//glStencilMask(0xFFFFFFFF);
-	//glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
-	
-	gUIProgram.bind();
+    gPipeline.disableLights();
+
+    LLGLSUIDefault gls_ui;
+
+    //LLGLEnable stencil(GL_STENCIL_TEST);
+    //glStencilFunc(GL_ALWAYS, 255, 0xFFFFFFFF);
+    //glStencilMask(0xFFFFFFFF);
+    //glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+
+    gUIProgram.bind();
     gGL.color4f(1, 1, 1, 1);
-	LLGLDepthTest depth(GL_TRUE, GL_FALSE);
-
-	if (!LLPipeline::sReflectionRender && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
-	{
-		gViewerWindow->renderSelections(FALSE, FALSE, FALSE); // For HUD version in render_ui_3d()
-	
-		// Draw the tracking overlays
-		LLTracker::render3D();
-		
+    LLGLDepthTest depth(GL_TRUE, GL_FALSE);
+
+    if (!LLPipeline::sReflectionRender && gPipeline.hasRenderDebugFeatureMask(LLPipeline::RENDER_DEBUG_FEATURE_UI))
+    {
+        gViewerWindow->renderSelections(FALSE, FALSE, FALSE); // For HUD version in render_ui_3d()
+
+        // Draw the tracking overlays
+        LLTracker::render3D();
+
         if (LLWorld::instanceExists())
         {
             // Show the property lines
             LLWorld::getInstance()->renderPropertyLines();
         }
-		LLViewerParcelMgr::getInstance()->render();
-		LLViewerParcelMgr::getInstance()->renderParcelCollision();
-	}
-	else if (gForceRenderLandFence)
-	{
-		// This is only set when not rendering the UI, for parcel snapshots
-		LLViewerParcelMgr::getInstance()->render();
-	}
-	else if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD))
-	{
-		LLHUDText::renderAllHUD();
-	}
+        LLViewerParcelMgr::getInstance()->render();
+        LLViewerParcelMgr::getInstance()->renderParcelCollision();
+    }
+    else if (gForceRenderLandFence)
+    {
+        // This is only set when not rendering the UI, for parcel snapshots
+        LLViewerParcelMgr::getInstance()->render();
+    }
+    else if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD))
+    {
+        LLHUDText::renderAllHUD();
+    }
 
-	gUIProgram.unbind();
+    gUIProgram.unbind();
 }
 
 void LLPipeline::renderHighlights()
 {
-	assertInitialized();
-
-	// Draw 3D UI elements here (before we clear the Z buffer in POOL_HUD)
-	// Render highlighted faces.
-	LLGLSPipelineAlpha gls_pipeline_alpha;
-	LLColor4 color(1.f, 1.f, 1.f, 0.5f);
-	disableLights();
-
-	if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
-	{
-		gHighlightProgram.bind();
-		gGL.diffuseColor4f(1,1,1,0.5f);
-	}
-	
-	if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED) && !mFaceSelectImagep)
-		{
-			mFaceSelectImagep = LLViewerTextureManager::getFetchedTexture(IMG_FACE_SELECT);
-		}
-
-	if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED) && (sRenderHighlightTextureChannel == LLRender::DIFFUSE_MAP))
-	{
-		// Make sure the selection image gets downloaded and decoded
-		mFaceSelectImagep->addTextureStats((F32)MAX_IMAGE_AREA);
-
-		U32 count = mSelectedFaces.size();
-		for (U32 i = 0; i < count; i++)
-		{
-			LLFace *facep = mSelectedFaces[i];
-			if (!facep || !facep->getDrawable() || facep->getDrawable()->isDead())
-			{
-				LL_WARNS() << "Bad face on selection" << LL_ENDL;
-				continue;
-			}
-			
-			facep->renderSelected(mFaceSelectImagep, color);
-		}
-	}
-
-	if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED))
-	{
-		// Paint 'em red!
-		color.setVec(1.f, 0.f, 0.f, 0.5f);
-		
-		int count = mHighlightFaces.size();
-		for (S32 i = 0; i < count; i++)
-		{
-			LLFace* facep = mHighlightFaces[i];
-			facep->renderSelected(LLViewerTexture::sNullImagep, color);
-		}
-	}
-
-	// Contains a list of the faces of objects that are physical or
-	// have touch-handlers.
-	mHighlightFaces.clear();
-
-	if (LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0)
-	{
-		gHighlightProgram.unbind();
-	}
-
-
-	if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED) && (sRenderHighlightTextureChannel == LLRender::NORMAL_MAP))
-	{
-		color.setVec(1.0f, 0.5f, 0.5f, 0.5f);
-		if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
-		{
-			gHighlightNormalProgram.bind();
-			gGL.diffuseColor4f(1,1,1,0.5f);
-		}
-
-		mFaceSelectImagep->addTextureStats((F32)MAX_IMAGE_AREA);
-
-		U32 count = mSelectedFaces.size();
-		for (U32 i = 0; i < count; i++)
-		{
-			LLFace *facep = mSelectedFaces[i];
-			if (!facep || !facep->getDrawable() || facep->getDrawable()->isDead())
-			{
-				LL_WARNS() << "Bad face on selection" << LL_ENDL;
-				continue;
-			}
-
-			facep->renderSelected(mFaceSelectImagep, color);
-		}
-
-		if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
-		{
-			gHighlightNormalProgram.unbind();
-		}
-	}
-
-	if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED) && (sRenderHighlightTextureChannel == LLRender::SPECULAR_MAP))
-	{
-		color.setVec(0.0f, 0.3f, 1.0f, 0.8f);
-		if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
-		{
-			gHighlightSpecularProgram.bind();
-			gGL.diffuseColor4f(1,1,1,0.5f);
-		}
-
-		mFaceSelectImagep->addTextureStats((F32)MAX_IMAGE_AREA);
-
-		U32 count = mSelectedFaces.size();
-		for (U32 i = 0; i < count; i++)
-		{
-			LLFace *facep = mSelectedFaces[i];
-			if (!facep || !facep->getDrawable() || facep->getDrawable()->isDead())
-			{
-				LL_WARNS() << "Bad face on selection" << LL_ENDL;
-				continue;
-			}
-
-			facep->renderSelected(mFaceSelectImagep, color);
-		}
-
-		if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
-		{
-			gHighlightSpecularProgram.unbind();
-		}
-	}
+    assertInitialized();
+
+    // Draw 3D UI elements here (before we clear the Z buffer in POOL_HUD)
+    // Render highlighted faces.
+    LLGLSPipelineAlpha gls_pipeline_alpha;
+    LLColor4 color(1.f, 1.f, 1.f, 0.5f);
+    disableLights();
+
+    if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
+    {
+        gHighlightProgram.bind();
+        gGL.diffuseColor4f(1,1,1,0.5f);
+    }
+
+    if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED) && !mFaceSelectImagep)
+        {
+            mFaceSelectImagep = LLViewerTextureManager::getFetchedTexture(IMG_FACE_SELECT);
+        }
+
+    if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED) && (sRenderHighlightTextureChannel == LLRender::DIFFUSE_MAP))
+    {
+        // Make sure the selection image gets downloaded and decoded
+        mFaceSelectImagep->addTextureStats((F32)MAX_IMAGE_AREA);
+
+        U32 count = mSelectedFaces.size();
+        for (U32 i = 0; i < count; i++)
+        {
+            LLFace *facep = mSelectedFaces[i];
+            if (!facep || !facep->getDrawable() || facep->getDrawable()->isDead())
+            {
+                LL_WARNS() << "Bad face on selection" << LL_ENDL;
+                continue;
+            }
+
+            facep->renderSelected(mFaceSelectImagep, color);
+        }
+    }
+
+    if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED))
+    {
+        // Paint 'em red!
+        color.setVec(1.f, 0.f, 0.f, 0.5f);
+
+        int count = mHighlightFaces.size();
+        for (S32 i = 0; i < count; i++)
+        {
+            LLFace* facep = mHighlightFaces[i];
+            facep->renderSelected(LLViewerTexture::sNullImagep, color);
+        }
+    }
+
+    // Contains a list of the faces of objects that are physical or
+    // have touch-handlers.
+    mHighlightFaces.clear();
+
+    if (LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0)
+    {
+        gHighlightProgram.unbind();
+    }
+
+
+    if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED) && (sRenderHighlightTextureChannel == LLRender::NORMAL_MAP))
+    {
+        color.setVec(1.0f, 0.5f, 0.5f, 0.5f);
+        if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
+        {
+            gHighlightNormalProgram.bind();
+            gGL.diffuseColor4f(1,1,1,0.5f);
+        }
+
+        mFaceSelectImagep->addTextureStats((F32)MAX_IMAGE_AREA);
+
+        U32 count = mSelectedFaces.size();
+        for (U32 i = 0; i < count; i++)
+        {
+            LLFace *facep = mSelectedFaces[i];
+            if (!facep || !facep->getDrawable() || facep->getDrawable()->isDead())
+            {
+                LL_WARNS() << "Bad face on selection" << LL_ENDL;
+                continue;
+            }
+
+            facep->renderSelected(mFaceSelectImagep, color);
+        }
+
+        if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
+        {
+            gHighlightNormalProgram.unbind();
+        }
+    }
+
+    if (hasRenderDebugFeatureMask(RENDER_DEBUG_FEATURE_SELECTED) && (sRenderHighlightTextureChannel == LLRender::SPECULAR_MAP))
+    {
+        color.setVec(0.0f, 0.3f, 1.0f, 0.8f);
+        if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
+        {
+            gHighlightSpecularProgram.bind();
+            gGL.diffuseColor4f(1,1,1,0.5f);
+        }
+
+        mFaceSelectImagep->addTextureStats((F32)MAX_IMAGE_AREA);
+
+        U32 count = mSelectedFaces.size();
+        for (U32 i = 0; i < count; i++)
+        {
+            LLFace *facep = mSelectedFaces[i];
+            if (!facep || !facep->getDrawable() || facep->getDrawable()->isDead())
+            {
+                LL_WARNS() << "Bad face on selection" << LL_ENDL;
+                continue;
+            }
+
+            facep->renderSelected(mFaceSelectImagep, color);
+        }
+
+        if ((LLViewerShaderMgr::instance()->getShaderLevel(LLViewerShaderMgr::SHADER_INTERFACE) > 0))
+        {
+            gHighlightSpecularProgram.unbind();
+        }
+    }
 }
 
 //debug use
@@ -3902,8 +3902,8 @@ U32 LLPipeline::sCurRenderPoolType = 0 ;
 
 void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion)
 {
-	LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderGeomDeferred");
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_GEOMETRY);
+    LLAppViewer::instance()->pingMainloopTimeout("Pipeline:RenderGeomDeferred");
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL; //LL_RECORD_BLOCK_TIME(FTM_RENDER_GEOMETRY);
     LL_PROFILE_GPU_ZONE("renderGeomDeferred");
 
     llassert(!sRenderingHUDs);
@@ -3914,17 +3914,17 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion)
     }
 
     if (&camera == LLViewerCamera::getInstance())
-    {   // a bit hacky, this is the start of the main render frame, figure out delta between last modelview matrix and 
+    {   // a bit hacky, this is the start of the main render frame, figure out delta between last modelview matrix and
         // current modelview matrix
         LLMatrix4a last_modelview(gGLLastModelView);
         LLMatrix4a cur_modelview(gGLModelView);
 
         // goal is to have a matrix here that goes from the last frame's camera space to the current frame's camera space
         last_modelview.invert();
-		last_modelview.setMul(cur_modelview, last_modelview);
+        last_modelview.setMul(cur_modelview, last_modelview);
 
         LLMatrix4a n = last_modelview;
-		n.invert();
+        n.invert();
 
         {
             gGLDeltaModelView = last_modelview;
@@ -3936,22 +3936,22 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion)
 
     setupHWLights();
 
-	{
-		LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWPOOL("deferred pools");
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWPOOL("deferred pools");
 
-		LLGLEnable cull(GL_CULL_FACE);
+        LLGLEnable cull(GL_CULL_FACE);
 
-		for (LLDrawPool* poolp : mPools)
-		{
-			if (hasRenderType(poolp->getType()))
-			{
-				poolp->prerender();
-			}
-		}
+        for (LLDrawPool* poolp : mPools)
+        {
+            if (hasRenderType(poolp->getType()))
+            {
+                poolp->prerender();
+            }
+        }
 
-		LLVertexBuffer::unbind();
+        LLVertexBuffer::unbind();
 
-		LLGLState::checkStates();
+        LLGLState::checkStates();
 
         if (LLViewerShaderMgr::instance()->mShaderLevel[LLViewerShaderMgr::SHADER_DEFERRED] > 1)
         {
@@ -3960,18 +3960,18 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion)
             mHeroProbeManager.updateUniforms();
         }
 
-		U32 cur_type = 0;
+        U32 cur_type = 0;
+
+        gGL.setColorMask(true, true);
+
+        pool_set_t::iterator iter1 = mPools.begin();
+        pool_set_t::iterator pools_end = mPools.end();
 
-		gGL.setColorMask(true, true);
-	
-		pool_set_t::iterator iter1 = mPools.begin();
-		pool_set_t::iterator pools_end = mPools.end();
+        while ( iter1 != pools_end )
+        {
+            LLDrawPool *poolp = *iter1;
 
-		while ( iter1 != pools_end )
-		{
-			LLDrawPool *poolp = *iter1;
-		
-			cur_type = poolp->getType();
+            cur_type = poolp->getType();
 
             if (occlude && cur_type >= LLDrawPool::POOL_GRASS)
             {
@@ -3982,57 +3982,57 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion)
                 doOcclusion(camera);
             }
 
-			pool_set_t::iterator iter2 = iter1;
-			if (hasRenderType(poolp->getType()) && poolp->getNumDeferredPasses() > 0)
-			{
-				LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWPOOL("deferred pool render");
-
-				gGLLastMatrix = NULL;
-				gGL.loadMatrix(gGLModelView);
-		
-				for( S32 i = 0; i < poolp->getNumDeferredPasses(); i++ )
-				{
-					LLVertexBuffer::unbind();
-					poolp->beginDeferredPass(i);
-					for (iter2 = iter1; iter2 != pools_end; ++iter2)
-					{
-						LLDrawPool *p = *iter2;
-						if (p->getType() != cur_type)
-						{
-							break;
-						}
-
-						if ( !p->getSkipRenderFlag() ) { p->renderDeferred(i); }
-					}
-					poolp->endDeferredPass(i);
-					LLVertexBuffer::unbind();
-
-					LLGLState::checkStates();
-				}
-			}
-			else
-			{
-				// Skip all pools of this type
-				for (iter2 = iter1; iter2 != pools_end; ++iter2)
-				{
-					LLDrawPool *p = *iter2;
-					if (p->getType() != cur_type)
-					{
-						break;
-					}
-				}
-			}
-			iter1 = iter2;
-			stop_glerror();
-		}
-
-		gGLLastMatrix = NULL;
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-		gGL.loadMatrix(gGLModelView);
-
-		gGL.setColorMask(true, false);
-
-	} // Tracy ZoneScoped
+            pool_set_t::iterator iter2 = iter1;
+            if (hasRenderType(poolp->getType()) && poolp->getNumDeferredPasses() > 0)
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWPOOL("deferred pool render");
+
+                gGLLastMatrix = NULL;
+                gGL.loadMatrix(gGLModelView);
+
+                for( S32 i = 0; i < poolp->getNumDeferredPasses(); i++ )
+                {
+                    LLVertexBuffer::unbind();
+                    poolp->beginDeferredPass(i);
+                    for (iter2 = iter1; iter2 != pools_end; ++iter2)
+                    {
+                        LLDrawPool *p = *iter2;
+                        if (p->getType() != cur_type)
+                        {
+                            break;
+                        }
+
+                        if ( !p->getSkipRenderFlag() ) { p->renderDeferred(i); }
+                    }
+                    poolp->endDeferredPass(i);
+                    LLVertexBuffer::unbind();
+
+                    LLGLState::checkStates();
+                }
+            }
+            else
+            {
+                // Skip all pools of this type
+                for (iter2 = iter1; iter2 != pools_end; ++iter2)
+                {
+                    LLDrawPool *p = *iter2;
+                    if (p->getType() != cur_type)
+                    {
+                        break;
+                    }
+                }
+            }
+            iter1 = iter2;
+            stop_glerror();
+        }
+
+        gGLLastMatrix = NULL;
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+        gGL.loadMatrix(gGLModelView);
+
+        gGL.setColorMask(true, false);
+
+    } // Tracy ZoneScoped
 
     if (gUseWireframe)
     {
@@ -4042,7 +4042,7 @@ void LLPipeline::renderGeomDeferred(LLCamera& camera, bool do_occlusion)
 
 void LLPipeline::renderGeomPostDeferred(LLCamera& camera)
 {
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
     LL_PROFILE_GPU_ZONE("renderGeomPostDeferred");
 
     if (gUseWireframe)
@@ -4050,9 +4050,9 @@ void LLPipeline::renderGeomPostDeferred(LLCamera& camera)
         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
     }
 
-	U32 cur_type = 0;
+    U32 cur_type = 0;
 
-	LLGLEnable cull(GL_CULL_FACE);
+    LLGLEnable cull(GL_CULL_FACE);
 
     bool done_atmospherics = LLPipeline::sRenderingHUDs; //skip atmospherics on huds
     bool done_water_haze = done_atmospherics;
@@ -4068,25 +4068,25 @@ void LLPipeline::renderGeomPostDeferred(LLCamera& camera)
     // do water haze just before pre water alpha
     U32 water_haze_pass = LLDrawPool::POOL_ALPHA_PRE_WATER;
 
-	calcNearbyLights(camera);
-	setupHWLights();
+    calcNearbyLights(camera);
+    setupHWLights();
 
     gGL.setSceneBlendType(LLRender::BT_ALPHA);
-	gGL.setColorMask(true, false);
+    gGL.setColorMask(true, false);
 
-	pool_set_t::iterator iter1 = mPools.begin();
-	pool_set_t::iterator pools_end = mPools.end();
+    pool_set_t::iterator iter1 = mPools.begin();
+    pool_set_t::iterator pools_end = mPools.end();
 
     if (gDebugGL || gDebugPipeline)
     {
         LLGLState::checkStates(GL_FALSE);
     }
 
-	while ( iter1 != pools_end)
-	{
-		LLDrawPool *poolp = *iter1;
-		
-		cur_type = poolp->getType();
+    while ( iter1 != pools_end)
+    {
+        LLDrawPool *poolp = *iter1;
+
+        cur_type = poolp->getType();
 
         if (cur_type >= atmospherics_pass && !done_atmospherics)
         { // do atmospherics against depth buffer before rendering alpha
@@ -4100,56 +4100,56 @@ void LLPipeline::renderGeomPostDeferred(LLCamera& camera)
             done_water_haze = true;
         }
 
-		pool_set_t::iterator iter2 = iter1;
-		if (hasRenderType(poolp->getType()) && poolp->getNumPostDeferredPasses() > 0)
-		{
-			LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWPOOL("deferred poolrender");
-
-			gGLLastMatrix = NULL;
-			gGL.loadMatrix(gGLModelView);
-		
-			for( S32 i = 0; i < poolp->getNumPostDeferredPasses(); i++ )
-			{
-				LLVertexBuffer::unbind();
-				poolp->beginPostDeferredPass(i);
-				for (iter2 = iter1; iter2 != pools_end; ++iter2)
-				{
-					LLDrawPool *p = *iter2;
-					if (p->getType() != cur_type)
-					{
-						break;
-					}
-										
-					if (!p->getSkipRenderFlag()) { p->renderPostDeferred(i); }
-				}
-				poolp->endPostDeferredPass(i);
-				LLVertexBuffer::unbind();
-
-				if (gDebugGL || gDebugPipeline)
-				{
-					LLGLState::checkStates(GL_FALSE);
-				}
-			}
-		}
-		else
-		{
-			// Skip all pools of this type
-			for (iter2 = iter1; iter2 != pools_end; ++iter2)
-			{
-				LLDrawPool *p = *iter2;
-				if (p->getType() != cur_type)
-				{
-					break;
-				}
-			}
-		}
-		iter1 = iter2;
-		stop_glerror();
-	}
-
-	gGLLastMatrix = NULL;
-	gGL.matrixMode(LLRender::MM_MODELVIEW);
-	gGL.loadMatrix(gGLModelView);
+        pool_set_t::iterator iter2 = iter1;
+        if (hasRenderType(poolp->getType()) && poolp->getNumPostDeferredPasses() > 0)
+        {
+            LL_PROFILE_ZONE_NAMED_CATEGORY_DRAWPOOL("deferred poolrender");
+
+            gGLLastMatrix = NULL;
+            gGL.loadMatrix(gGLModelView);
+
+            for( S32 i = 0; i < poolp->getNumPostDeferredPasses(); i++ )
+            {
+                LLVertexBuffer::unbind();
+                poolp->beginPostDeferredPass(i);
+                for (iter2 = iter1; iter2 != pools_end; ++iter2)
+                {
+                    LLDrawPool *p = *iter2;
+                    if (p->getType() != cur_type)
+                    {
+                        break;
+                    }
+
+                    if (!p->getSkipRenderFlag()) { p->renderPostDeferred(i); }
+                }
+                poolp->endPostDeferredPass(i);
+                LLVertexBuffer::unbind();
+
+                if (gDebugGL || gDebugPipeline)
+                {
+                    LLGLState::checkStates(GL_FALSE);
+                }
+            }
+        }
+        else
+        {
+            // Skip all pools of this type
+            for (iter2 = iter1; iter2 != pools_end; ++iter2)
+            {
+                LLDrawPool *p = *iter2;
+                if (p->getType() != cur_type)
+                {
+                    break;
+                }
+            }
+        }
+        iter1 = iter2;
+        stop_glerror();
+    }
+
+    gGLLastMatrix = NULL;
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.loadMatrix(gGLModelView);
 
     if (!gCubeSnapshot)
     {
@@ -4171,101 +4171,101 @@ void LLPipeline::renderGeomShadow(LLCamera& camera)
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
     LL_PROFILE_GPU_ZONE("renderGeomShadow");
     U32 cur_type = 0;
-	
-	LLGLEnable cull(GL_CULL_FACE);
-
-	LLVertexBuffer::unbind();
-
-	pool_set_t::iterator iter1 = mPools.begin();
-	pool_set_t::iterator pools_end = mPools.end();
-
-	while ( iter1 != pools_end )
-	{
-		LLDrawPool *poolp = *iter1;
-		
-		cur_type = poolp->getType();
-
-		pool_set_t::iterator iter2 = iter1;
-		if (hasRenderType(poolp->getType()) && poolp->getNumShadowPasses() > 0)
-		{
-			poolp->prerender() ;
-
-			gGLLastMatrix = NULL;
-			gGL.loadMatrix(gGLModelView);
-		
-			for( S32 i = 0; i < poolp->getNumShadowPasses(); i++ )
-			{
-				LLVertexBuffer::unbind();
-				poolp->beginShadowPass(i);
-				for (iter2 = iter1; iter2 != pools_end; ++iter2)
-				{
-					LLDrawPool *p = *iter2;
-					if (p->getType() != cur_type)
-					{
-						break;
-					}
-										
-					if ( !p->getSkipRenderFlag() ) { p->renderShadow(i); }
-				}
-				poolp->endShadowPass(i);
-				LLVertexBuffer::unbind();
-			}
-		}
-		else
-		{
-			// Skip all pools of this type
-			for (iter2 = iter1; iter2 != pools_end; ++iter2)
-			{
-				LLDrawPool *p = *iter2;
-				if (p->getType() != cur_type)
-				{
-					break;
-				}
-			}
-		}
-		iter1 = iter2;
-		stop_glerror();
-	}
-
-	gGLLastMatrix = NULL;
-	gGL.loadMatrix(gGLModelView);
-}
 
+    LLGLEnable cull(GL_CULL_FACE);
 
-static U32 sIndicesDrawnCount = 0;
+    LLVertexBuffer::unbind();
 
-void LLPipeline::addTrianglesDrawn(S32 index_count)
-{
-    sIndicesDrawnCount += index_count;
-}
+    pool_set_t::iterator iter1 = mPools.begin();
+    pool_set_t::iterator pools_end = mPools.end();
 
-void LLPipeline::recordTrianglesDrawn()
-{
-    assertInitialized();
-    U32 count = sIndicesDrawnCount / 3;
-    sIndicesDrawnCount = 0;
-    add(LLStatViewer::TRIANGLES_DRAWN, LLUnits::Triangles::fromValue(count));
-}
+    while ( iter1 != pools_end )
+    {
+        LLDrawPool *poolp = *iter1;
 
-void LLPipeline::renderPhysicsDisplay()
-{
-	if (!hasRenderDebugMask(LLPipeline::RENDER_DEBUG_PHYSICS_SHAPES))
-	{
-		return;
-	}
+        cur_type = poolp->getType();
 
-    gGL.flush();
-    gDebugProgram.bind();
+        pool_set_t::iterator iter2 = iter1;
+        if (hasRenderType(poolp->getType()) && poolp->getNumShadowPasses() > 0)
+        {
+            poolp->prerender() ;
 
-    LLGLEnable(GL_POLYGON_OFFSET_LINE);
-    glPolygonOffset(3.f, 3.f);
-    glLineWidth(3.f);
-    LLGLEnable blend(GL_BLEND);
-    gGL.setSceneBlendType(LLRender::BT_ALPHA);
+            gGLLastMatrix = NULL;
+            gGL.loadMatrix(gGLModelView);
 
-    for (int pass = 0; pass < 3; ++pass)
-    {
-        // pass 0 - depth write enabled, color write disabled, fill
+            for( S32 i = 0; i < poolp->getNumShadowPasses(); i++ )
+            {
+                LLVertexBuffer::unbind();
+                poolp->beginShadowPass(i);
+                for (iter2 = iter1; iter2 != pools_end; ++iter2)
+                {
+                    LLDrawPool *p = *iter2;
+                    if (p->getType() != cur_type)
+                    {
+                        break;
+                    }
+
+                    if ( !p->getSkipRenderFlag() ) { p->renderShadow(i); }
+                }
+                poolp->endShadowPass(i);
+                LLVertexBuffer::unbind();
+            }
+        }
+        else
+        {
+            // Skip all pools of this type
+            for (iter2 = iter1; iter2 != pools_end; ++iter2)
+            {
+                LLDrawPool *p = *iter2;
+                if (p->getType() != cur_type)
+                {
+                    break;
+                }
+            }
+        }
+        iter1 = iter2;
+        stop_glerror();
+    }
+
+    gGLLastMatrix = NULL;
+    gGL.loadMatrix(gGLModelView);
+}
+
+
+static U32 sIndicesDrawnCount = 0;
+
+void LLPipeline::addTrianglesDrawn(S32 index_count)
+{
+    sIndicesDrawnCount += index_count;
+}
+
+void LLPipeline::recordTrianglesDrawn()
+{
+    assertInitialized();
+    U32 count = sIndicesDrawnCount / 3;
+    sIndicesDrawnCount = 0;
+    add(LLStatViewer::TRIANGLES_DRAWN, LLUnits::Triangles::fromValue(count));
+}
+
+void LLPipeline::renderPhysicsDisplay()
+{
+    if (!hasRenderDebugMask(LLPipeline::RENDER_DEBUG_PHYSICS_SHAPES))
+    {
+        return;
+    }
+
+    gGL.flush();
+    gDebugProgram.bind();
+
+    LLGLEnable(GL_POLYGON_OFFSET_LINE);
+    glPolygonOffset(3.f, 3.f);
+    glLineWidth(3.f);
+    LLGLEnable blend(GL_BLEND);
+    gGL.setSceneBlendType(LLRender::BT_ALPHA);
+
+    for (int pass = 0; pass < 3; ++pass)
+    {
+        // pass 0 - depth write enabled, color write disabled, fill
         // pass 1 - depth write disabled, color write enabled, fill
         // pass 2 - depth write disabled, color write enabled, wireframe
         gGL.setColorMask(pass >= 1, false);
@@ -4302,7 +4302,7 @@ void LLPipeline::renderPhysicsDisplay()
         }
     }
     glLineWidth(1.f);
-	gDebugProgram.unbind();
+    gDebugProgram.unbind();
 
 }
 
@@ -4312,5709 +4312,5709 @@ void LLPipeline::renderDebug()
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
 
-	assertInitialized();
-
-	bool hud_only = hasRenderType(LLPipeline::RENDER_TYPE_HUD);
-
-	if (!hud_only )
-	{
-		//Render any navmesh geometry	
-		LLPathingLib *llPathingLibInstance = LLPathingLib::getInstance();
-		if ( llPathingLibInstance != NULL ) 
-		{
-			//character floater renderables
-			
-			LLHandle<LLFloaterPathfindingCharacters> pathfindingCharacterHandle = LLFloaterPathfindingCharacters::getInstanceHandle();
-			if ( !pathfindingCharacterHandle.isDead() )
-			{
-				LLFloaterPathfindingCharacters *pathfindingCharacter = pathfindingCharacterHandle.get();
-
-				if ( pathfindingCharacter->getVisible() || gAgentCamera.cameraMouselook() )			
-				{	
-					gPathfindingProgram.bind();			
-					gPathfindingProgram.uniform1f(sTint, 1.f);
-					gPathfindingProgram.uniform1f(sAmbiance, 1.f);
-					gPathfindingProgram.uniform1f(sAlphaScale, 1.f);
-
-					//Requried character physics capsule render parameters
-					LLUUID id;					
-					LLVector3 pos;
-					LLQuaternion rot;
-				
-					if ( pathfindingCharacter->isPhysicsCapsuleEnabled( id, pos, rot ) )
-					{
-						//remove blending artifacts
-						gGL.setColorMask(false, false);
-						llPathingLibInstance->renderSimpleShapeCapsuleID( gGL, id, pos, rot );				
-						gGL.setColorMask(true, false);
-						LLGLEnable blend(GL_BLEND);
-						gPathfindingProgram.uniform1f(sAlphaScale, 0.90f);
-						llPathingLibInstance->renderSimpleShapeCapsuleID( gGL, id, pos, rot );
-						gPathfindingProgram.bind();
-					}
-				}
-			}
-			
-
-			//pathing console renderables
-			LLHandle<LLFloaterPathfindingConsole> pathfindingConsoleHandle = LLFloaterPathfindingConsole::getInstanceHandle();
-			if (!pathfindingConsoleHandle.isDead())
-			{
-				LLFloaterPathfindingConsole *pathfindingConsole = pathfindingConsoleHandle.get();
-
-				if ( pathfindingConsole->getVisible() || gAgentCamera.cameraMouselook() )
-				{				
-					F32 ambiance = gSavedSettings.getF32("PathfindingAmbiance");
-
-					gPathfindingProgram.bind();
-			
-					gPathfindingProgram.uniform1f(sTint, 1.f);
-					gPathfindingProgram.uniform1f(sAmbiance, ambiance);
-					gPathfindingProgram.uniform1f(sAlphaScale, 1.f);
-
-					if ( !pathfindingConsole->isRenderWorld() )
-					{
-						const LLColor4 clearColor = gSavedSettings.getColor4("PathfindingNavMeshClear");
-						gGL.setColorMask(true, true);
-						glClearColor(clearColor.mV[0],clearColor.mV[1],clearColor.mV[2],0);
-                        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // no stencil -- deprecated | GL_STENCIL_BUFFER_BIT);
-						gGL.setColorMask(true, false);
-						glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );	
-					}
-
-					//NavMesh
-					if ( pathfindingConsole->isRenderNavMesh() )
-					{	
-						gGL.flush();
-						gGL.setLineWidth(2.0f);	
-						LLGLEnable cull(GL_CULL_FACE);
-						LLGLDisable blend(GL_BLEND);
-						
-						if ( pathfindingConsole->isRenderWorld() )
-						{					
-							LLGLEnable blend(GL_BLEND);
-							gPathfindingProgram.uniform1f(sAlphaScale, 0.66f);
-							llPathingLibInstance->renderNavMesh();
-						}
-						else
-						{
-							llPathingLibInstance->renderNavMesh();
-						}
-						
-						//render edges
-						gPathfindingNoNormalsProgram.bind();
-						gPathfindingNoNormalsProgram.uniform1f(sTint, 1.f);
-						gPathfindingNoNormalsProgram.uniform1f(sAlphaScale, 1.f);
-						llPathingLibInstance->renderNavMeshEdges();
-						gPathfindingProgram.bind();
-
-						gGL.flush();
-						glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );	
-						gGL.setLineWidth(1.0f);	
-						gGL.flush();
-					}
-					//User designated path
-					if ( LLPathfindingPathTool::getInstance()->isRenderPath() )
-					{
-						//The path
-						gUIProgram.bind();
-						gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep);
-						llPathingLibInstance->renderPath();
-						gPathfindingProgram.bind();
+    assertInitialized();
 
-                        //The bookends
-						//remove blending artifacts
-						gGL.setColorMask(false, false);
-						llPathingLibInstance->renderPathBookend( gGL, LLPathingLib::LLPL_START );
-						llPathingLibInstance->renderPathBookend( gGL, LLPathingLib::LLPL_END );
-						
-						gGL.setColorMask(true, false);
-						//render the bookends
-						LLGLEnable blend(GL_BLEND);
-						gPathfindingProgram.uniform1f(sAlphaScale, 0.90f);
-						llPathingLibInstance->renderPathBookend( gGL, LLPathingLib::LLPL_START );
-						llPathingLibInstance->renderPathBookend( gGL, LLPathingLib::LLPL_END );
-						gPathfindingProgram.bind();
-					}
-				
-					if ( pathfindingConsole->isRenderWaterPlane() )
-					{	
-						LLGLEnable blend(GL_BLEND);
-						gPathfindingProgram.uniform1f(sAlphaScale, 0.90f);
-						llPathingLibInstance->renderSimpleShapes( gGL, gAgent.getRegion()->getWaterHeight() );
-					}
-				//physics/exclusion shapes
-				if ( pathfindingConsole->isRenderAnyShapes() )
-				{					
-						U32 render_order[] = {
-							1 << LLPathingLib::LLST_ObstacleObjects,
-							1 << LLPathingLib::LLST_WalkableObjects,
-							1 << LLPathingLib::LLST_ExclusionPhantoms,	
-							1 << LLPathingLib::LLST_MaterialPhantoms,
-						};
-
-						U32 flags = pathfindingConsole->getRenderShapeFlags();
-
-						for (U32 i = 0; i < 4; i++)
-						{
-							if (!(flags & render_order[i]))
-							{
-								continue;
-							}
-
-							//turn off backface culling for volumes so they are visible when camera is inside volume
-							LLGLDisable cull(i >= 2 ? GL_CULL_FACE : 0);
-						
-							gGL.flush();
-							glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );	
-				
-							//get rid of some z-fighting
-							LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
-							glPolygonOffset(1.0f, 1.0f);
-
-							//render to depth first to avoid blending artifacts
-							gGL.setColorMask(false, false);
-							llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );		
-							gGL.setColorMask(true, false);
-
-							//get rid of some z-fighting
-							glPolygonOffset(0.f, 0.f);
-
-							LLGLEnable blend(GL_BLEND);
-				
-							{
-								gPathfindingProgram.uniform1f(sAmbiance, ambiance);
-
-								{ //draw solid overlay
-									LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_LEQUAL);
-									llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );				
-									gGL.flush();				
-								}
-				
-								LLGLEnable lineOffset(GL_POLYGON_OFFSET_LINE);
-								glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );	
-						
-								F32 offset = gSavedSettings.getF32("PathfindingLineOffset");
-
-								if (pathfindingConsole->isRenderXRay())
-								{
-									gPathfindingProgram.uniform1f(sTint, gSavedSettings.getF32("PathfindingXRayTint"));
-									gPathfindingProgram.uniform1f(sAlphaScale, gSavedSettings.getF32("PathfindingXRayOpacity"));
-									LLGLEnable blend(GL_BLEND);
-									LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_GREATER);
-								
-									glPolygonOffset(offset, -offset);
-								
-									if (gSavedSettings.getBOOL("PathfindingXRayWireframe"))
-									{ //draw hidden wireframe as darker and less opaque
-										gPathfindingProgram.uniform1f(sAmbiance, 1.f);
-										llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );				
-									}
-									else
-									{
-										glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );	
-										gPathfindingProgram.uniform1f(sAmbiance, ambiance);
-										llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );				
-										glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-									}
-								}
-
-								{ //draw visible wireframe as brighter, thicker and more opaque
-									glPolygonOffset(offset, offset);
-									gPathfindingProgram.uniform1f(sAmbiance, 1.f);
-									gPathfindingProgram.uniform1f(sTint, 1.f);
-									gPathfindingProgram.uniform1f(sAlphaScale, 1.f);
-
-									gGL.setLineWidth(gSavedSettings.getF32("PathfindingLineWidth"));
-									LLGLDisable blendOut(GL_BLEND);
-									llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );				
-									gGL.flush();
-									gGL.setLineWidth(1.f);
-								}
-				
-								glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
-							}
-						}
-					}
-
-					glPolygonOffset(0.f, 0.f);
-
-					if ( pathfindingConsole->isRenderNavMesh() && pathfindingConsole->isRenderXRay() )
-					{	//render navmesh xray
-						F32 ambiance = gSavedSettings.getF32("PathfindingAmbiance");
-
-						LLGLEnable lineOffset(GL_POLYGON_OFFSET_LINE);
-						LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
-											
-						F32 offset = gSavedSettings.getF32("PathfindingLineOffset");
-						glPolygonOffset(offset, -offset);
-
-						LLGLEnable blend(GL_BLEND);
-						LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_GREATER);
-						gGL.flush();				
-						gGL.setLineWidth(2.0f);	
-						LLGLEnable cull(GL_CULL_FACE);
-																		
-						gPathfindingProgram.uniform1f(sTint, gSavedSettings.getF32("PathfindingXRayTint"));
-						gPathfindingProgram.uniform1f(sAlphaScale, gSavedSettings.getF32("PathfindingXRayOpacity"));
-								
-						if (gSavedSettings.getBOOL("PathfindingXRayWireframe"))
-						{ //draw hidden wireframe as darker and less opaque
-							glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );	
-							gPathfindingProgram.uniform1f(sAmbiance, 1.f);
-							llPathingLibInstance->renderNavMesh();
-							glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );	
-						}	
-						else
-						{
-							gPathfindingProgram.uniform1f(sAmbiance, ambiance);
-							llPathingLibInstance->renderNavMesh();
-						}
-
-						//render edges
-						gPathfindingNoNormalsProgram.bind();
-						gPathfindingNoNormalsProgram.uniform1f(sTint, gSavedSettings.getF32("PathfindingXRayTint"));
-						gPathfindingNoNormalsProgram.uniform1f(sAlphaScale, gSavedSettings.getF32("PathfindingXRayOpacity"));
-						llPathingLibInstance->renderNavMeshEdges();
-						gPathfindingProgram.bind();
-					
-						gGL.flush();
-						gGL.setLineWidth(1.0f);	
-					}
-			
-					glPolygonOffset(0.f, 0.f);
-
-					gGL.flush();
-					gPathfindingProgram.unbind();
-				}
-			}
-		}
-	}
-
-	gGLLastMatrix = NULL;
-	gGL.loadMatrix(gGLModelView);
-	gGL.setColorMask(true, false);
-
-	
-	if (!hud_only && !mDebugBlips.empty())
-	{ //render debug blips
-		gUIProgram.bind();
-        gGL.color4f(1, 1, 1, 1);
+    bool hud_only = hasRenderType(LLPipeline::RENDER_TYPE_HUD);
 
-		gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep, true);
-
-		glPointSize(8.f);
-		LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
-
-		gGL.begin(LLRender::POINTS);
-		for (std::list<DebugBlip>::iterator iter = mDebugBlips.begin(); iter != mDebugBlips.end(); )
-		{
-			DebugBlip& blip = *iter;
-
-			blip.mAge += gFrameIntervalSeconds.value();
-			if (blip.mAge > 2.f)
-			{
-				mDebugBlips.erase(iter++);
-			}
-			else
-			{
-				iter++;
-			}
-
-			blip.mPosition.mV[2] += gFrameIntervalSeconds.value()*2.f;
-
-			gGL.color4fv(blip.mColor.mV);
-			gGL.vertex3fv(blip.mPosition.mV);
-		}
-		gGL.end();
-		gGL.flush();
-		glPointSize(1.f);
-	}
-
-	// Debug stuff.
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
-		{
-			LLSpatialPartition* part = region->getSpatialPartition(i);
-			if (part)
-			{
-				if ( (hud_only && (part->mDrawableType == RENDER_TYPE_HUD || part->mDrawableType == RENDER_TYPE_HUD_PARTICLES)) ||
-					 (!hud_only && hasRenderType(part->mDrawableType)) )
-				{
-					part->renderDebug();
-				}
-			}
-		}
-	}
-
-	for (LLCullResult::bridge_iterator i = sCull->beginVisibleBridge(), i_end = sCull->endVisibleBridge(); i != i_end; ++i)
-	{
-		LLSpatialBridge* bridge = *i;
-		if (!bridge->isDead() && hasRenderType(bridge->mDrawableType))
-		{
-			gGL.pushMatrix();
-			gGL.multMatrix(bridge->mDrawable->getRenderMatrix());
-			bridge->renderDebug();
-			gGL.popMatrix();
-		}
-	}
+    if (!hud_only )
+    {
+        //Render any navmesh geometry
+        LLPathingLib *llPathingLibInstance = LLPathingLib::getInstance();
+        if ( llPathingLibInstance != NULL )
+        {
+            //character floater renderables
 
-    LL::GLTFSceneManager::instance().renderDebug();
+            LLHandle<LLFloaterPathfindingCharacters> pathfindingCharacterHandle = LLFloaterPathfindingCharacters::getInstanceHandle();
+            if ( !pathfindingCharacterHandle.isDead() )
+            {
+                LLFloaterPathfindingCharacters *pathfindingCharacter = pathfindingCharacterHandle.get();
 
-	if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCCLUSION))
-	{ //render visible selected group occlusion geometry
-		gDebugProgram.bind();
-		LLGLDepthTest depth(GL_TRUE, GL_FALSE);
-		gGL.diffuseColor3f(1,0,1);
-		for (std::set<LLSpatialGroup*>::iterator iter = visible_selected_groups.begin(); iter != visible_selected_groups.end(); ++iter)
-		{
-			LLSpatialGroup* group = *iter;
+                if ( pathfindingCharacter->getVisible() || gAgentCamera.cameraMouselook() )
+                {
+                    gPathfindingProgram.bind();
+                    gPathfindingProgram.uniform1f(sTint, 1.f);
+                    gPathfindingProgram.uniform1f(sAmbiance, 1.f);
+                    gPathfindingProgram.uniform1f(sAlphaScale, 1.f);
 
-			LLVector4a fudge;
-			fudge.splat(0.25f); //SG_OCCLUSION_FUDGE
+                    //Requried character physics capsule render parameters
+                    LLUUID id;
+                    LLVector3 pos;
+                    LLQuaternion rot;
 
-			LLVector4a size;
-			const LLVector4a* bounds = group->getBounds();
-			size.setAdd(fudge, bounds[1]);
-			
-			drawBox(bounds[0], size);
-		}
-	}
+                    if ( pathfindingCharacter->isPhysicsCapsuleEnabled( id, pos, rot ) )
+                    {
+                        //remove blending artifacts
+                        gGL.setColorMask(false, false);
+                        llPathingLibInstance->renderSimpleShapeCapsuleID( gGL, id, pos, rot );
+                        gGL.setColorMask(true, false);
+                        LLGLEnable blend(GL_BLEND);
+                        gPathfindingProgram.uniform1f(sAlphaScale, 0.90f);
+                        llPathingLibInstance->renderSimpleShapeCapsuleID( gGL, id, pos, rot );
+                        gPathfindingProgram.bind();
+                    }
+                }
+            }
 
-	visible_selected_groups.clear();
 
-    //draw reflection probes and links between them
-    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_REFLECTION_PROBES) && !hud_only)
-    {
-        mReflectionMapManager.renderDebug();
-    }
+            //pathing console renderables
+            LLHandle<LLFloaterPathfindingConsole> pathfindingConsoleHandle = LLFloaterPathfindingConsole::getInstanceHandle();
+            if (!pathfindingConsoleHandle.isDead())
+            {
+                LLFloaterPathfindingConsole *pathfindingConsole = pathfindingConsoleHandle.get();
 
-	static LLCachedControl<bool> render_ref_probe_vol(gSavedSettings, "RenderReflectionProbeVolumes", false);
-    if (render_ref_probe_vol && !hud_only)
-    {
-        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("probe debug display");
+                if ( pathfindingConsole->getVisible() || gAgentCamera.cameraMouselook() )
+                {
+                    F32 ambiance = gSavedSettings.getF32("PathfindingAmbiance");
 
-        bindDeferredShader(gReflectionProbeDisplayProgram, NULL);
-        mScreenTriangleVB->setBuffer();
+                    gPathfindingProgram.bind();
 
-        LLGLEnable blend(GL_BLEND);
-        LLGLDepthTest depth(GL_FALSE);
+                    gPathfindingProgram.uniform1f(sTint, 1.f);
+                    gPathfindingProgram.uniform1f(sAmbiance, ambiance);
+                    gPathfindingProgram.uniform1f(sAlphaScale, 1.f);
 
-        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+                    if ( !pathfindingConsole->isRenderWorld() )
+                    {
+                        const LLColor4 clearColor = gSavedSettings.getColor4("PathfindingNavMeshClear");
+                        gGL.setColorMask(true, true);
+                        glClearColor(clearColor.mV[0],clearColor.mV[1],clearColor.mV[2],0);
+                        glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); // no stencil -- deprecated | GL_STENCIL_BUFFER_BIT);
+                        gGL.setColorMask(true, false);
+                        glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+                    }
 
-        unbindDeferredShader(gReflectionProbeDisplayProgram);
-    }
+                    //NavMesh
+                    if ( pathfindingConsole->isRenderNavMesh() )
+                    {
+                        gGL.flush();
+                        gGL.setLineWidth(2.0f);
+                        LLGLEnable cull(GL_CULL_FACE);
+                        LLGLDisable blend(GL_BLEND);
 
-	gUIProgram.bind();
-
-	if (hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST) && !hud_only)
-	{ //draw crosshairs on particle intersection
-		if (gDebugRaycastParticle)
-		{
-			gDebugProgram.bind();
-
-			gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-			LLVector3 center(gDebugRaycastParticleIntersection.getF32ptr());
-			LLVector3 size(0.1f, 0.1f, 0.1f);
-
-			LLVector3 p[6];
-
-			p[0] = center + size.scaledVec(LLVector3(1,0,0));
-			p[1] = center + size.scaledVec(LLVector3(-1,0,0));
-			p[2] = center + size.scaledVec(LLVector3(0,1,0));
-			p[3] = center + size.scaledVec(LLVector3(0,-1,0));
-			p[4] = center + size.scaledVec(LLVector3(0,0,1));
-			p[5] = center + size.scaledVec(LLVector3(0,0,-1));
-				
-			gGL.begin(LLRender::LINES);
-			gGL.diffuseColor3f(1.f, 1.f, 0.f);
-			for (U32 i = 0; i < 6; i++)
-			{
-				gGL.vertex3fv(p[i].mV);
-			}
-			gGL.end();
-			gGL.flush();
-
-			gDebugProgram.unbind();
-		}
-	}
-
-	if (hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !hud_only)
-	{
-		LLVertexBuffer::unbind();
-
-		LLGLEnable blend(GL_BLEND);
-		LLGLDepthTest depth(TRUE, FALSE);
-		LLGLDisable cull(GL_CULL_FACE);
-
-		gGL.color4f(1,1,1,1);
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-				
-		F32 a = 0.1f;
-
-		F32 col[] =
-		{
-			1,0,0,a,
-			0,1,0,a,
-			0,0,1,a,
-			1,0,1,a,
-			
-			1,1,0,a,
-			0,1,1,a,
-			1,1,1,a,
-			1,0,1,a,
-		};
-
-		for (U32 i = 0; i < 8; i++)
-		{
-			LLVector3* frust = mShadowCamera[i].mAgentFrustum;
-
-			if (i > 3)
-			{ //render shadow frusta as volumes
-				if (mShadowFrustPoints[i-4].empty())
-				{
-					continue;
-				}
-
-				gGL.color4fv(col+(i-4)*4);	
-			
-				gGL.begin(LLRender::TRIANGLE_STRIP);
-				gGL.vertex3fv(frust[0].mV); gGL.vertex3fv(frust[4].mV);
-				gGL.vertex3fv(frust[1].mV); gGL.vertex3fv(frust[5].mV);
-				gGL.vertex3fv(frust[2].mV); gGL.vertex3fv(frust[6].mV);
-				gGL.vertex3fv(frust[3].mV); gGL.vertex3fv(frust[7].mV);
-				gGL.vertex3fv(frust[0].mV); gGL.vertex3fv(frust[4].mV);
-				gGL.end();
-				
-				
-				gGL.begin(LLRender::TRIANGLE_STRIP);
-				gGL.vertex3fv(frust[0].mV);
-				gGL.vertex3fv(frust[1].mV);
-				gGL.vertex3fv(frust[3].mV);
-				gGL.vertex3fv(frust[2].mV);
-				gGL.end();
-				
-				gGL.begin(LLRender::TRIANGLE_STRIP);
-				gGL.vertex3fv(frust[4].mV);
-				gGL.vertex3fv(frust[5].mV);
-				gGL.vertex3fv(frust[7].mV);
-				gGL.vertex3fv(frust[6].mV);
-				gGL.end();		
-			}
-
-	
-			if (i < 4)
-			{
-				
-				//if (i == 0 || !mShadowFrustPoints[i].empty())
-				{
-					//render visible point cloud
-					gGL.flush();
-					glPointSize(8.f);
-					gGL.begin(LLRender::POINTS);
-					
-					F32* c = col+i*4;
-					gGL.color3fv(c);
-
-					for (U32 j = 0; j < mShadowFrustPoints[i].size(); ++j)
-						{
-							gGL.vertex3fv(mShadowFrustPoints[i][j].mV);
-						
-						}
-					gGL.end();
-
-					gGL.flush();
-					glPointSize(1.f);
-
-					LLVector3* ext = mShadowExtents[i]; 
-					LLVector3 pos = (ext[0]+ext[1])*0.5f;
-					LLVector3 size = (ext[1]-ext[0])*0.5f;
-					drawBoxOutline(pos, size);
-
-					//render camera frustum splits as outlines
-					gGL.begin(LLRender::LINES);
-					gGL.vertex3fv(frust[0].mV); gGL.vertex3fv(frust[1].mV);
-					gGL.vertex3fv(frust[1].mV); gGL.vertex3fv(frust[2].mV);
-					gGL.vertex3fv(frust[2].mV); gGL.vertex3fv(frust[3].mV);
-					gGL.vertex3fv(frust[3].mV); gGL.vertex3fv(frust[0].mV);
-					gGL.vertex3fv(frust[4].mV); gGL.vertex3fv(frust[5].mV);
-					gGL.vertex3fv(frust[5].mV); gGL.vertex3fv(frust[6].mV);
-					gGL.vertex3fv(frust[6].mV); gGL.vertex3fv(frust[7].mV);
-					gGL.vertex3fv(frust[7].mV); gGL.vertex3fv(frust[4].mV);
-					gGL.vertex3fv(frust[0].mV); gGL.vertex3fv(frust[4].mV);
-					gGL.vertex3fv(frust[1].mV); gGL.vertex3fv(frust[5].mV);
-					gGL.vertex3fv(frust[2].mV); gGL.vertex3fv(frust[6].mV);
-					gGL.vertex3fv(frust[3].mV); gGL.vertex3fv(frust[7].mV);
-					gGL.end();
-				}
-			}
-
-			/*gGL.flush();
-			gGL.setLineWidth(16-i*2);
-			for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin(); 
-					iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
-			{
-				LLViewerRegion* region = *iter;
-				for (U32 j = 0; j < LLViewerRegion::NUM_PARTITIONS; j++)
-				{
-					LLSpatialPartition* part = region->getSpatialPartition(j);
-					if (part)
-					{
-						if (hasRenderType(part->mDrawableType))
-						{
-							part->renderIntersectingBBoxes(&mShadowCamera[i]);
-						}
-					}
-				}
-			}
-			gGL.flush();
-			gGL.setLineWidth(1.f);*/
-		}
-	}
-
-	if (mRenderDebugMask & RENDER_DEBUG_WIND_VECTORS)
-	{
-		gAgent.getRegion()->mWind.renderVectors();
-	}
-	
-	if (mRenderDebugMask & RENDER_DEBUG_COMPOSITION)
-	{
-		// Debug composition layers
-		F32 x, y;
-
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-		if (gAgent.getRegion())
-		{
-			gGL.begin(LLRender::POINTS);
-			// Draw the composition layer for the region that I'm in.
-			for (x = 0; x <= 260; x++)
-			{
-				for (y = 0; y <= 260; y++)
-				{
-					if ((x > 255) || (y > 255))
-					{
-						gGL.color4f(1.f, 0.f, 0.f, 1.f);
-					}
-					else
-					{
-						gGL.color4f(0.f, 0.f, 1.f, 1.f);
-					}
-					F32 z = gAgent.getRegion()->getCompositionXY((S32)x, (S32)y);
-					z *= 5.f;
-					z += 50.f;
-					gGL.vertex3f(x, y, z);
-				}
-			}
-			gGL.end();
-		}
-	}
-
-	gGL.flush();
-	gUIProgram.unbind();
-}
+                        if ( pathfindingConsole->isRenderWorld() )
+                        {
+                            LLGLEnable blend(GL_BLEND);
+                            gPathfindingProgram.uniform1f(sAlphaScale, 0.66f);
+                            llPathingLibInstance->renderNavMesh();
+                        }
+                        else
+                        {
+                            llPathingLibInstance->renderNavMesh();
+                        }
 
-void LLPipeline::rebuildPools()
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+                        //render edges
+                        gPathfindingNoNormalsProgram.bind();
+                        gPathfindingNoNormalsProgram.uniform1f(sTint, 1.f);
+                        gPathfindingNoNormalsProgram.uniform1f(sAlphaScale, 1.f);
+                        llPathingLibInstance->renderNavMeshEdges();
+                        gPathfindingProgram.bind();
+
+                        gGL.flush();
+                        glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+                        gGL.setLineWidth(1.0f);
+                        gGL.flush();
+                    }
+                    //User designated path
+                    if ( LLPathfindingPathTool::getInstance()->isRenderPath() )
+                    {
+                        //The path
+                        gUIProgram.bind();
+                        gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep);
+                        llPathingLibInstance->renderPath();
+                        gPathfindingProgram.bind();
 
-	assertInitialized();
-
-	S32 max_count = mPools.size();
-	pool_set_t::iterator iter1 = mPools.upper_bound(mLastRebuildPool);
-	while(max_count > 0 && mPools.size() > 0) // && num_rebuilds < MAX_REBUILDS)
-	{
-		if (iter1 == mPools.end())
-		{
-			iter1 = mPools.begin();
-		}
-		LLDrawPool* poolp = *iter1;
-
-		if (poolp->isDead())
-		{
-			mPools.erase(iter1++);
-			removeFromQuickLookup( poolp );
-			if (poolp == mLastRebuildPool)
-			{
-				mLastRebuildPool = NULL;
-			}
-			delete poolp;
-		}
-		else
-		{
-			mLastRebuildPool = poolp;
-			iter1++;
-		}
-		max_count--;
-	}
-}
+                        //The bookends
+                        //remove blending artifacts
+                        gGL.setColorMask(false, false);
+                        llPathingLibInstance->renderPathBookend( gGL, LLPathingLib::LLPL_START );
+                        llPathingLibInstance->renderPathBookend( gGL, LLPathingLib::LLPL_END );
+
+                        gGL.setColorMask(true, false);
+                        //render the bookends
+                        LLGLEnable blend(GL_BLEND);
+                        gPathfindingProgram.uniform1f(sAlphaScale, 0.90f);
+                        llPathingLibInstance->renderPathBookend( gGL, LLPathingLib::LLPL_START );
+                        llPathingLibInstance->renderPathBookend( gGL, LLPathingLib::LLPL_END );
+                        gPathfindingProgram.bind();
+                    }
 
-void LLPipeline::addToQuickLookup( LLDrawPool* new_poolp )
-{
-	assertInitialized();
-
-	switch( new_poolp->getType() )
-	{
-	case LLDrawPool::POOL_SIMPLE:
-		if (mSimplePool)
-		{
-			llassert(0);
-			LL_WARNS() << "Ignoring duplicate simple pool." << LL_ENDL;
-		}
-		else
-		{
-			mSimplePool = (LLRenderPass*) new_poolp;
-		}
-		break;
-
-	case LLDrawPool::POOL_ALPHA_MASK:
-		if (mAlphaMaskPool)
-		{
-			llassert(0);
-			LL_WARNS() << "Ignoring duplicate alpha mask pool." << LL_ENDL;
-			break;
-		}
-		else
-		{
-			mAlphaMaskPool = (LLRenderPass*) new_poolp;
-		}
-		break;
-
-	case LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK:
-		if (mFullbrightAlphaMaskPool)
-		{
-			llassert(0);
-			LL_WARNS() << "Ignoring duplicate alpha mask pool." << LL_ENDL;
-			break;
-		}
-		else
-		{
-			mFullbrightAlphaMaskPool = (LLRenderPass*) new_poolp;
-		}
-		break;
-		
-	case LLDrawPool::POOL_GRASS:
-		if (mGrassPool)
-		{
-			llassert(0);
-			LL_WARNS() << "Ignoring duplicate grass pool." << LL_ENDL;
-		}
-		else
-		{
-			mGrassPool = (LLRenderPass*) new_poolp;
-		}
-		break;
-
-	case LLDrawPool::POOL_FULLBRIGHT:
-		if (mFullbrightPool)
-		{
-			llassert(0);
-			LL_WARNS() << "Ignoring duplicate simple pool." << LL_ENDL;
-		}
-		else
-		{
-			mFullbrightPool = (LLRenderPass*) new_poolp;
-		}
-		break;
-
-	case LLDrawPool::POOL_GLOW:
-		if (mGlowPool)
-		{
-			llassert(0);
-			LL_WARNS() << "Ignoring duplicate glow pool." << LL_ENDL;
-		}
-		else
-		{
-			mGlowPool = (LLRenderPass*) new_poolp;
-		}
-		break;
-
-	case LLDrawPool::POOL_TREE:
-		mTreePools[ uintptr_t(new_poolp->getTexture()) ] = new_poolp ;
-		break;
- 
-	case LLDrawPool::POOL_TERRAIN:
-		mTerrainPools[ uintptr_t(new_poolp->getTexture()) ] = new_poolp ;
-		break;
-
-	case LLDrawPool::POOL_BUMP:
-		if (mBumpPool)
-		{
-			llassert(0);
-			LL_WARNS() << "Ignoring duplicate bump pool." << LL_ENDL;
-		}
-		else
-		{
-			mBumpPool = new_poolp;
-		}
-		break;
-	case LLDrawPool::POOL_MATERIALS:
-		if (mMaterialsPool)
-		{
-			llassert(0);
-			LL_WARNS() << "Ignorning duplicate materials pool." << LL_ENDL;
-		}
-		else
-		{
-			mMaterialsPool = new_poolp;
-		}
-		break;
-	case LLDrawPool::POOL_ALPHA_PRE_WATER:
-		if( mAlphaPoolPreWater )
-		{
-			llassert(0);
-			LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate Alpha pre-water pool" << LL_ENDL;
-		}
-		else
-		{
-			mAlphaPoolPreWater = (LLDrawPoolAlpha*) new_poolp;
-		}
-		break;
-    case LLDrawPool::POOL_ALPHA_POST_WATER:
-        if (mAlphaPoolPostWater)
-        {
-            llassert(0);
-            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate Alpha post-water pool" << LL_ENDL;
-        }
-        else
-        {
-            mAlphaPoolPostWater = (LLDrawPoolAlpha*)new_poolp;
-        }
-        break;
+                    if ( pathfindingConsole->isRenderWaterPlane() )
+                    {
+                        LLGLEnable blend(GL_BLEND);
+                        gPathfindingProgram.uniform1f(sAlphaScale, 0.90f);
+                        llPathingLibInstance->renderSimpleShapes( gGL, gAgent.getRegion()->getWaterHeight() );
+                    }
+                //physics/exclusion shapes
+                if ( pathfindingConsole->isRenderAnyShapes() )
+                {
+                        U32 render_order[] = {
+                            1 << LLPathingLib::LLST_ObstacleObjects,
+                            1 << LLPathingLib::LLST_WalkableObjects,
+                            1 << LLPathingLib::LLST_ExclusionPhantoms,
+                            1 << LLPathingLib::LLST_MaterialPhantoms,
+                        };
 
-	case LLDrawPool::POOL_AVATAR:
-	case LLDrawPool::POOL_CONTROL_AV:
-		break; // Do nothing
-
-	case LLDrawPool::POOL_SKY:
-		if( mSkyPool )
-		{
-			llassert(0);
-			LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate Sky pool" << LL_ENDL;
-		}
-		else
-		{
-			mSkyPool = new_poolp;
-		}
-		break;
-	
-	case LLDrawPool::POOL_WATER:
-		if( mWaterPool )
-		{
-			llassert(0);
-			LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate Water pool" << LL_ENDL;
-		}
-		else
-		{
-			mWaterPool = new_poolp;
-		}
-		break;
-
-	case LLDrawPool::POOL_WL_SKY:
-		if( mWLSkyPool )
-		{
-			llassert(0);
-			LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate WLSky Pool" << LL_ENDL;
-		}
-		else
-		{ 
-			mWLSkyPool = new_poolp;
-		}
-		break;
+                        U32 flags = pathfindingConsole->getRenderShapeFlags();
 
-    case LLDrawPool::POOL_GLTF_PBR:
-        if( mPBROpaquePool )
-        {
-            llassert(0);
-            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate PBR Opaque Pool" << LL_ENDL;
-        }
-        else
-        {
-            mPBROpaquePool = new_poolp;
-        }
-        break;
+                        for (U32 i = 0; i < 4; i++)
+                        {
+                            if (!(flags & render_order[i]))
+                            {
+                                continue;
+                            }
 
-    case LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK:
-        if (mPBRAlphaMaskPool)
-        {
-            llassert(0);
-            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate PBR Alpha Mask Pool" << LL_ENDL;
-        }
-        else
-        {
-            mPBRAlphaMaskPool = new_poolp;
-        }
-        break;
+                            //turn off backface culling for volumes so they are visible when camera is inside volume
+                            LLGLDisable cull(i >= 2 ? GL_CULL_FACE : 0);
 
+                            gGL.flush();
+                            glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
 
-	default:
-		llassert(0);
-		LL_WARNS() << "Invalid Pool Type in  LLPipeline::addPool()" << LL_ENDL;
-		break;
-	}
-}
+                            //get rid of some z-fighting
+                            LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
+                            glPolygonOffset(1.0f, 1.0f);
 
-void LLPipeline::removePool( LLDrawPool* poolp )
-{
-	assertInitialized();
-	removeFromQuickLookup(poolp);
-	mPools.erase(poolp);
-	delete poolp;
-}
+                            //render to depth first to avoid blending artifacts
+                            gGL.setColorMask(false, false);
+                            llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );
+                            gGL.setColorMask(true, false);
 
-void LLPipeline::removeFromQuickLookup( LLDrawPool* poolp )
-{
-	assertInitialized();
-	switch( poolp->getType() )
-	{
-	case LLDrawPool::POOL_SIMPLE:
-		llassert(mSimplePool == poolp);
-		mSimplePool = NULL;
-		break;
-
-	case LLDrawPool::POOL_ALPHA_MASK:
-		llassert(mAlphaMaskPool == poolp);
-		mAlphaMaskPool = NULL;
-		break;
-
-	case LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK:
-		llassert(mFullbrightAlphaMaskPool == poolp);
-		mFullbrightAlphaMaskPool = NULL;
-		break;
-
-	case LLDrawPool::POOL_GRASS:
-		llassert(mGrassPool == poolp);
-		mGrassPool = NULL;
-		break;
-
-	case LLDrawPool::POOL_FULLBRIGHT:
-		llassert(mFullbrightPool == poolp);
-		mFullbrightPool = NULL;
-		break;
-
-	case LLDrawPool::POOL_WL_SKY:
-		llassert(mWLSkyPool == poolp);
-		mWLSkyPool = NULL;
-		break;
-
-	case LLDrawPool::POOL_GLOW:
-		llassert(mGlowPool == poolp);
-		mGlowPool = NULL;
-		break;
-
-	case LLDrawPool::POOL_TREE:
-		#ifdef _DEBUG
-			{
-				bool found = mTreePools.erase( (uintptr_t)poolp->getTexture() );
-				llassert( found );
-			}
-		#else
-			mTreePools.erase( (uintptr_t)poolp->getTexture() );
-		#endif
-		break;
-
-	case LLDrawPool::POOL_TERRAIN:
-		#ifdef _DEBUG
-			{
-				bool found = mTerrainPools.erase( (uintptr_t)poolp->getTexture() );
-				llassert( found );
-			}
-		#else
-			mTerrainPools.erase( (uintptr_t)poolp->getTexture() );
-		#endif
-		break;
-
-	case LLDrawPool::POOL_BUMP:
-		llassert( poolp == mBumpPool );
-		mBumpPool = NULL;
-		break;
-	
-	case LLDrawPool::POOL_MATERIALS:
-		llassert(poolp == mMaterialsPool);
-		mMaterialsPool = NULL;
-		break;
-			
-	case LLDrawPool::POOL_ALPHA_PRE_WATER:
-		llassert( poolp == mAlphaPoolPreWater );
-		mAlphaPoolPreWater = nullptr;
-		break;
-    
-    case LLDrawPool::POOL_ALPHA_POST_WATER:
-        llassert(poolp == mAlphaPoolPostWater);
-        mAlphaPoolPostWater = nullptr;
-        break;
+                            //get rid of some z-fighting
+                            glPolygonOffset(0.f, 0.f);
 
-	case LLDrawPool::POOL_AVATAR:
-	case LLDrawPool::POOL_CONTROL_AV:
-		break; // Do nothing
+                            LLGLEnable blend(GL_BLEND);
 
-	case LLDrawPool::POOL_SKY:
-		llassert( poolp == mSkyPool );
-		mSkyPool = NULL;
-		break;
+                            {
+                                gPathfindingProgram.uniform1f(sAmbiance, ambiance);
 
-	case LLDrawPool::POOL_WATER:
-		llassert( poolp == mWaterPool );
-		mWaterPool = NULL;
-		break;
+                                { //draw solid overlay
+                                    LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_LEQUAL);
+                                    llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );
+                                    gGL.flush();
+                                }
 
-    case LLDrawPool::POOL_GLTF_PBR:
-        llassert( poolp == mPBROpaquePool );
-        mPBROpaquePool = NULL;
-        break;
+                                LLGLEnable lineOffset(GL_POLYGON_OFFSET_LINE);
+                                glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
 
-    case LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK:
-        llassert(poolp == mPBRAlphaMaskPool);
-        mPBRAlphaMaskPool = NULL;
-        break;
+                                F32 offset = gSavedSettings.getF32("PathfindingLineOffset");
 
-	default:
-		llassert(0);
-		LL_WARNS() << "Invalid Pool Type in  LLPipeline::removeFromQuickLookup() type=" << poolp->getType() << LL_ENDL;
-		break;
-	}
-}
+                                if (pathfindingConsole->isRenderXRay())
+                                {
+                                    gPathfindingProgram.uniform1f(sTint, gSavedSettings.getF32("PathfindingXRayTint"));
+                                    gPathfindingProgram.uniform1f(sAlphaScale, gSavedSettings.getF32("PathfindingXRayOpacity"));
+                                    LLGLEnable blend(GL_BLEND);
+                                    LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_GREATER);
+
+                                    glPolygonOffset(offset, -offset);
+
+                                    if (gSavedSettings.getBOOL("PathfindingXRayWireframe"))
+                                    { //draw hidden wireframe as darker and less opaque
+                                        gPathfindingProgram.uniform1f(sAmbiance, 1.f);
+                                        llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );
+                                    }
+                                    else
+                                    {
+                                        glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+                                        gPathfindingProgram.uniform1f(sAmbiance, ambiance);
+                                        llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );
+                                        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
+                                    }
+                                }
 
-void LLPipeline::resetDrawOrders()
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	assertInitialized();
-	// Iterate through all of the draw pools and rebuild them.
-	for (LLDrawPool* poolp : mPools)
-	{
+                                { //draw visible wireframe as brighter, thicker and more opaque
+                                    glPolygonOffset(offset, offset);
+                                    gPathfindingProgram.uniform1f(sAmbiance, 1.f);
+                                    gPathfindingProgram.uniform1f(sTint, 1.f);
+                                    gPathfindingProgram.uniform1f(sAlphaScale, 1.f);
+
+                                    gGL.setLineWidth(gSavedSettings.getF32("PathfindingLineWidth"));
+                                    LLGLDisable blendOut(GL_BLEND);
+                                    llPathingLibInstance->renderNavMeshShapesVBO( render_order[i] );
+                                    gGL.flush();
+                                    gGL.setLineWidth(1.f);
+                                }
 
-		poolp->resetDrawOrders();
-	}
-}
+                                glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+                            }
+                        }
+                    }
 
-//============================================================================
-// Once-per-frame setup of hardware lights,
-// including sun/moon, avatar backlight, and up to 6 local lights
+                    glPolygonOffset(0.f, 0.f);
 
-void LLPipeline::setupAvatarLights(bool for_edit)
-{
-	assertInitialized();
+                    if ( pathfindingConsole->isRenderNavMesh() && pathfindingConsole->isRenderXRay() )
+                    {   //render navmesh xray
+                        F32 ambiance = gSavedSettings.getF32("PathfindingAmbiance");
 
-    LLEnvironment& environment = LLEnvironment::instance();
-    bool sun_up = environment.getIsSunUp();
+                        LLGLEnable lineOffset(GL_POLYGON_OFFSET_LINE);
+                        LLGLEnable polyOffset(GL_POLYGON_OFFSET_FILL);
 
-	if (for_edit)
-	{
-		LLColor4 diffuse(1.f, 1.f, 1.f, 0.f);
-		LLVector4a light_pos_cam(-8.f, 0.25f, 10.f, 0.f);  // w==0 => directional light
-		LLMatrix4a camera_rot = LLViewerCamera::getInstance()->getModelview();
-		camera_rot.extractRotation_affine();
-		camera_rot.invert();
-		LLVector4a light_pos;
-		
-		camera_rot.rotate(light_pos_cam,light_pos);
-		
-		light_pos.normalize3fast();
-
-		LLLightState* light = gGL.getLight(1);
-
-		mHWLightColors[1] = diffuse;
-
-		light->setDiffuse(diffuse);
-		light->setAmbient(LLColor4::black);
-		light->setSpecular(LLColor4::black);
-		light->setPosition(LLVector4(light_pos.getF32ptr()));
-		light->setConstantAttenuation(1.f);
-		light->setLinearAttenuation(0.f);
-		light->setQuadraticAttenuation(0.f);
-		light->setSpotExponent(0.f);
-		light->setSpotCutoff(180.f);
-	}
-    else if (gAvatarBacklight)
-	{
-        LLVector3 light_dir = sun_up ? LLVector3(mSunDir) : LLVector3(mMoonDir);
-		LLVector3 opposite_pos = -light_dir;
-		LLVector3 orthog_light_pos = light_dir % LLVector3::z_axis;
-		LLVector4 backlight_pos = LLVector4(lerp(opposite_pos, orthog_light_pos, 0.3f), 0.0f);
-		backlight_pos.normalize();
-			
-		LLColor4 light_diffuse = sun_up ? mSunDiffuse : mMoonDiffuse;
-
-		LLColor4 backlight_diffuse(1.f - light_diffuse.mV[VRED], 1.f - light_diffuse.mV[VGREEN], 1.f - light_diffuse.mV[VBLUE], 1.f);
-		F32 max_component = 0.001f;
-		for (S32 i = 0; i < 3; i++)
-		{
-			if (backlight_diffuse.mV[i] > max_component)
-			{
-				max_component = backlight_diffuse.mV[i];
-			}
-		}
-		F32 backlight_mag;
-		if (sun_up)
-		{
-			backlight_mag = BACKLIGHT_DAY_MAGNITUDE_OBJECT;
-		}
-		else
-		{
-			backlight_mag = BACKLIGHT_NIGHT_MAGNITUDE_OBJECT;
-		}
-		backlight_diffuse *= backlight_mag / max_component;
-
-		mHWLightColors[1] = backlight_diffuse;
-
-		LLLightState* light = gGL.getLight(1);
-
-		light->setPosition(backlight_pos);
-		light->setDiffuse(backlight_diffuse);
-		light->setAmbient(LLColor4::black);
-		light->setSpecular(LLColor4::black);
-		light->setConstantAttenuation(1.f);
-		light->setLinearAttenuation(0.f);
-		light->setQuadraticAttenuation(0.f);
-		light->setSpotExponent(0.f);
-		light->setSpotCutoff(180.f);
-	}
-	else
-	{
-		LLLightState* light = gGL.getLight(1);
-
-		mHWLightColors[1] = LLColor4::black;
-
-		light->setDiffuse(LLColor4::black);
-		light->setAmbient(LLColor4::black);
-		light->setSpecular(LLColor4::black);
-	}
-}
+                        F32 offset = gSavedSettings.getF32("PathfindingLineOffset");
+                        glPolygonOffset(offset, -offset);
 
-static F32 calc_light_dist(LLVOVolume* light, const LLVector3& cam_pos, F32 max_dist)
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-	F32 inten = light->getLightIntensity();
-	if (inten < .001f)
-	{
-		return max_dist;
-	}
-	bool selected = light->isSelected();
-	if (selected)
-	{
-        return 0.f; // selected lights get highest priority
-	}
-    F32 radius = light->getLightRadius();
-    F32 dist = dist_vec(light->getRenderPosition(), cam_pos);
-    dist = llmax(dist - radius, 0.f);
-	if (light->mDrawable.notNull() && light->mDrawable->isState(LLDrawable::ACTIVE))
-	{
-		// moving lights get a little higher priority (too much causes artifacts)
-        dist = llmax(dist - light->getLightRadius()*0.25f, 0.f);
-	}
-	return dist;
-}
+                        LLGLEnable blend(GL_BLEND);
+                        LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_GREATER);
+                        gGL.flush();
+                        gGL.setLineWidth(2.0f);
+                        LLGLEnable cull(GL_CULL_FACE);
 
-void LLPipeline::calcNearbyLights(LLCamera& camera)
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-	assertInitialized();
+                        gPathfindingProgram.uniform1f(sTint, gSavedSettings.getF32("PathfindingXRayTint"));
+                        gPathfindingProgram.uniform1f(sAlphaScale, gSavedSettings.getF32("PathfindingXRayOpacity"));
 
-	if (LLPipeline::sReflectionRender || gCubeSnapshot || LLPipeline::sRenderingHUDs)
-	{
-		return;
-	}
+                        if (gSavedSettings.getBOOL("PathfindingXRayWireframe"))
+                        { //draw hidden wireframe as darker and less opaque
+                            glPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
+                            gPathfindingProgram.uniform1f(sAmbiance, 1.f);
+                            llPathingLibInstance->renderNavMesh();
+                            glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
+                        }
+                        else
+                        {
+                            gPathfindingProgram.uniform1f(sAmbiance, ambiance);
+                            llPathingLibInstance->renderNavMesh();
+                        }
 
-	static LLCachedControl<S32> local_light_count(gSavedSettings, "RenderLocalLightCount", 256);
+                        //render edges
+                        gPathfindingNoNormalsProgram.bind();
+                        gPathfindingNoNormalsProgram.uniform1f(sTint, gSavedSettings.getF32("PathfindingXRayTint"));
+                        gPathfindingNoNormalsProgram.uniform1f(sAlphaScale, gSavedSettings.getF32("PathfindingXRayOpacity"));
+                        llPathingLibInstance->renderNavMeshEdges();
+                        gPathfindingProgram.bind();
 
-	if (local_light_count >= 1)
-	{
-		// mNearbyLight (and all light_set_t's) are sorted such that
-		// begin() == the closest light and rbegin() == the farthest light
-		const S32 MAX_LOCAL_LIGHTS = 6;
-        LLVector3 cam_pos = camera.getOrigin();
-		
-        F32 max_dist;
-        if (LLPipeline::sRenderDeferred)
-        {
-            max_dist = RenderFarClip;
-        }
-        else
-        {
-            max_dist = llmin(RenderFarClip, LIGHT_MAX_RADIUS * 4.f);
+                        gGL.flush();
+                        gGL.setLineWidth(1.0f);
+                    }
+
+                    glPolygonOffset(0.f, 0.f);
+
+                    gGL.flush();
+                    gPathfindingProgram.unbind();
+                }
+            }
         }
+    }
 
-		// UPDATE THE EXISTING NEARBY LIGHTS
-		light_set_t cur_nearby_lights;
-		for (const Light& light : mNearbyLights)
-		{
-			LLDrawable* drawable = light.drawable;
-			LLVOVolume* volight = drawable->getVOVolume();
-			if (!volight || !drawable->isState(LLDrawable::LIGHT))
-			{
-				drawable->clearState(LLDrawable::NEARBY_LIGHT);
-				continue;
-			}
-			if (light.fade <= -LIGHT_FADE_TIME)
-			{
-				drawable->clearState(LLDrawable::NEARBY_LIGHT);
-				continue;
-			}
-			if (!sRenderAttachedLights && volight->isAttachment())
-			{
-				drawable->clearState(LLDrawable::NEARBY_LIGHT);
-				continue;
-			}
-			else if(volight->isAttachment())
-			{
-				LLVOAvatar* avatarp = volight->getAvatar();
-				if (avatarp && avatarp->isVisuallyMuted())
-				{
-					drawable->clearState(LLDrawable::NEARBY_LIGHT);
-					continue;
-				}
-			}
+    gGLLastMatrix = NULL;
+    gGL.loadMatrix(gGLModelView);
+    gGL.setColorMask(true, false);
 
-            F32 dist = calc_light_dist(volight, cam_pos, max_dist);
-            F32 fade = light.fade;
-            // actual fade gets decreased/increased by setupHWLights
-            // light->fade value is 'time'.
-            // >=0 and light will become visible as value increases
-            // <0 and light will fade out
-            if (dist < max_dist)
+
+    if (!hud_only && !mDebugBlips.empty())
+    { //render debug blips
+        gUIProgram.bind();
+        gGL.color4f(1, 1, 1, 1);
+
+        gGL.getTexUnit(0)->bind(LLViewerFetchedTexture::sWhiteImagep, true);
+
+        glPointSize(8.f);
+        LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
+
+        gGL.begin(LLRender::POINTS);
+        for (std::list<DebugBlip>::iterator iter = mDebugBlips.begin(); iter != mDebugBlips.end(); )
+        {
+            DebugBlip& blip = *iter;
+
+            blip.mAge += gFrameIntervalSeconds.value();
+            if (blip.mAge > 2.f)
             {
-                if (fade < 0)
-                {
-                    // mark light to fade in
-                    // if fade was -LIGHT_FADE_TIME - it was fully invisible
-                    // if fade -0 - it was fully visible
-                    // visibility goes up from 0 to LIGHT_FADE_TIME.
-                    fade += LIGHT_FADE_TIME;
-                }
+                mDebugBlips.erase(iter++);
             }
             else
             {
-                // mark light to fade out
-                // visibility goes down from -0 to -LIGHT_FADE_TIME.
-                if (fade >= LIGHT_FADE_TIME)
-                {
-                    fade = -0.0001f; // was fully visible
-                }
-                else if (fade >= 0)
-                {
-                    // 0.75 visible light should stay 0.75 visible, but should reverse direction
-                    fade -= LIGHT_FADE_TIME;
-                }
+                iter++;
             }
-            cur_nearby_lights.emplace(drawable, dist, fade);
-		}
-		mNearbyLights = std::move(cur_nearby_lights);
-				
-		// FIND NEW LIGHTS THAT ARE IN RANGE
-		light_set_t new_nearby_lights;
-		for (LLDrawable::ordered_drawable_set_t::iterator iter = mLights.begin();
-			 iter != mLights.end(); ++iter)
-		{
-			LLDrawable* drawable = *iter;
-			LLVOVolume* light = drawable->getVOVolume();
-			if (!light || drawable->isState(LLDrawable::NEARBY_LIGHT))
-			{
-				continue;
-			}
-			if (light->isHUDAttachment())
-			{
-				continue; // no lighting from HUD objects
-			}
-            if (!sRenderAttachedLights && light->isAttachment())
-			{
-				continue;
-			}
-			else if (light->isAttachment())
-			{
-				LLVOAvatar* av = light->getAvatar();
-            	if (av && av->isVisuallyMuted())
-				{
-					// avatars that are already in the list will be removed by removeMutedAVsLights
-					continue;
-				}
-			}
 
-            F32 dist = calc_light_dist(light, cam_pos, max_dist);
-            if (dist >= max_dist)
-			{
-				continue;
-			}
-			new_nearby_lights.emplace(drawable, dist, 0.f);
-            if (!LLPipeline::sRenderDeferred && new_nearby_lights.size() > (U32)MAX_LOCAL_LIGHTS)
-			{
-				new_nearby_lights.erase(--new_nearby_lights.end());
-				const Light& last = *new_nearby_lights.rbegin();
-				max_dist = last.dist;
-			}
-		}
-
-		// INSERT ANY NEW LIGHTS
-		for (const Light& light : new_nearby_lights)
-		{
-            if (LLPipeline::sRenderDeferred || mNearbyLights.size() < (U32)MAX_LOCAL_LIGHTS)
-			{
-				mNearbyLights.insert(light);
-				((LLDrawable*) light.drawable)->setState(LLDrawable::NEARBY_LIGHT);
-			}
-			else
-			{
-				// crazy cast so that we can overwrite the fade value
-				// even though gcc enforces sets as const
-				// (fade value doesn't affect sort so this is safe)
-				Light* farthest_light = (const_cast<Light*>(&(*(mNearbyLights.rbegin()))));
-				if (light.dist < farthest_light->dist)
-				{
-                    // mark light to fade out
-                    // visibility goes down from -0 to -LIGHT_FADE_TIME.
-                    //
-                    // This is a mess, but for now it needs to be in sync
-                    // with fade code above. Ex: code above detects distance < max,
-                    // sets fade time to positive, this code then detects closer
-                    // lights and sets fade time negative, fully compensating
-                    // for the code above
-                    if (farthest_light->fade >= LIGHT_FADE_TIME)
-                    {
-                        farthest_light->fade = -0.0001f; // was fully visible
-                    }
-                    else if (farthest_light->fade >= 0)
-                    {
-                        farthest_light->fade -= LIGHT_FADE_TIME;
-                    }
-				}
-				else
-				{
-					break; // none of the other lights are closer
-				}
-			}
-		}
-		
-		//mark nearby lights not-removable.
-		for (const Light& light : mNearbyLights)
-		{
-			((LLViewerOctreeEntryData*) light.drawable)->setVisible();
-		}
-	}
-}
+            blip.mPosition.mV[2] += gFrameIntervalSeconds.value()*2.f;
 
-void LLPipeline::setupHWLights()
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
-	assertInitialized();
-	
-    if (LLPipeline::sRenderingHUDs)
-    {
-        return;
+            gGL.color4fv(blip.mColor.mV);
+            gGL.vertex3fv(blip.mPosition.mV);
+        }
+        gGL.end();
+        gGL.flush();
+        glPointSize(1.f);
     }
 
-    F32 light_scale = 1.f;
+    // Debug stuff.
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        for (U32 i = 0; i < LLViewerRegion::NUM_PARTITIONS; i++)
+        {
+            LLSpatialPartition* part = region->getSpatialPartition(i);
+            if (part)
+            {
+                if ( (hud_only && (part->mDrawableType == RENDER_TYPE_HUD || part->mDrawableType == RENDER_TYPE_HUD_PARTICLES)) ||
+                     (!hud_only && hasRenderType(part->mDrawableType)) )
+                {
+                    part->renderDebug();
+                }
+            }
+        }
+    }
 
-    if (gCubeSnapshot)
-    { //darken local lights when probe ambiance is above 1
-        light_scale = mReflectionMapManager.mLightScale;
+    for (LLCullResult::bridge_iterator i = sCull->beginVisibleBridge(), i_end = sCull->endVisibleBridge(); i != i_end; ++i)
+    {
+        LLSpatialBridge* bridge = *i;
+        if (!bridge->isDead() && hasRenderType(bridge->mDrawableType))
+        {
+            gGL.pushMatrix();
+            gGL.multMatrix(bridge->mDrawable->getRenderMatrix());
+            bridge->renderDebug();
+            gGL.popMatrix();
+        }
     }
-	else
-	{
-		static LLCachedControl<F32> alchemy_light_scale(gSavedSettings, "AlchemyGlobalLightScale", 1.f);
-		light_scale = alchemy_light_scale;
-	}
 
+    LL::GLTFSceneManager::instance().renderDebug();
 
-    LLEnvironment& environment = LLEnvironment::instance();
-	const LLSettingsSky::ptr_t& psky = environment.getCurrentSky();
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_OCCLUSION))
+    { //render visible selected group occlusion geometry
+        gDebugProgram.bind();
+        LLGLDepthTest depth(GL_TRUE, GL_FALSE);
+        gGL.diffuseColor3f(1,0,1);
+        for (std::set<LLSpatialGroup*>::iterator iter = visible_selected_groups.begin(); iter != visible_selected_groups.end(); ++iter)
+        {
+            LLSpatialGroup* group = *iter;
 
-    // Ambient
-    LLColor4 ambient = psky->getTotalAmbient();
+            LLVector4a fudge;
+            fudge.splat(0.25f); //SG_OCCLUSION_FUDGE
 
-	gGL.setAmbientLightColor(ambient);
+            LLVector4a size;
+            const LLVector4a* bounds = group->getBounds();
+            size.setAdd(fudge, bounds[1]);
 
-    bool sun_up  = environment.getIsSunUp();
-    bool moon_up = environment.getIsMoonUp();
+            drawBox(bounds[0], size);
+        }
+    }
 
-	// Light 0 = Sun or Moon (All objects)
-	{
-        LLVector4 sun_dir(environment.getSunDirection(), 0.0f);
-        LLVector4 moon_dir(environment.getMoonDirection(), 0.0f);
+    visible_selected_groups.clear();
 
-        mSunDir.setVec(sun_dir);
-        mMoonDir.setVec(moon_dir);
+    //draw reflection probes and links between them
+    if (gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_REFLECTION_PROBES) && !hud_only)
+    {
+        mReflectionMapManager.renderDebug();
+    }
 
-        mSunDiffuse.setVec(psky->getSunlightColor());
-        mMoonDiffuse.setVec(psky->getMoonlightColor());
+    static LLCachedControl<bool> render_ref_probe_vol(gSavedSettings, "RenderReflectionProbeVolumes", false);
+    if (render_ref_probe_vol && !hud_only)
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("probe debug display");
 
-		F32 max_color = llmax(mSunDiffuse.mV[0], mSunDiffuse.mV[1], mSunDiffuse.mV[2]);
-		if (max_color > 1.f)
-		{
-			mSunDiffuse *= 1.f/max_color;
-		}
-		mSunDiffuse.clamp();
+        bindDeferredShader(gReflectionProbeDisplayProgram, NULL);
+        mScreenTriangleVB->setBuffer();
 
-        max_color = llmax(mMoonDiffuse.mV[0], mMoonDiffuse.mV[1], mMoonDiffuse.mV[2]);
-        if (max_color > 1.f)
+        LLGLEnable blend(GL_BLEND);
+        LLGLDepthTest depth(GL_FALSE);
+
+        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+        unbindDeferredShader(gReflectionProbeDisplayProgram);
+    }
+
+    gUIProgram.bind();
+
+    if (hasRenderDebugMask(LLPipeline::RENDER_DEBUG_RAYCAST) && !hud_only)
+    { //draw crosshairs on particle intersection
+        if (gDebugRaycastParticle)
         {
-            mMoonDiffuse *= 1.f/max_color;
+            gDebugProgram.bind();
+
+            gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+
+            LLVector3 center(gDebugRaycastParticleIntersection.getF32ptr());
+            LLVector3 size(0.1f, 0.1f, 0.1f);
+
+            LLVector3 p[6];
+
+            p[0] = center + size.scaledVec(LLVector3(1,0,0));
+            p[1] = center + size.scaledVec(LLVector3(-1,0,0));
+            p[2] = center + size.scaledVec(LLVector3(0,1,0));
+            p[3] = center + size.scaledVec(LLVector3(0,-1,0));
+            p[4] = center + size.scaledVec(LLVector3(0,0,1));
+            p[5] = center + size.scaledVec(LLVector3(0,0,-1));
+
+            gGL.begin(LLRender::LINES);
+            gGL.diffuseColor3f(1.f, 1.f, 0.f);
+            for (U32 i = 0; i < 6; i++)
+            {
+                gGL.vertex3fv(p[i].mV);
+            }
+            gGL.end();
+            gGL.flush();
+
+            gDebugProgram.unbind();
         }
-        mMoonDiffuse.clamp();
+    }
 
-        // prevent underlighting from having neither lightsource facing us
-        if (!sun_up && !moon_up)
-		{
-            mSunDiffuse.setVec(LLColor4(0.0, 0.0, 0.0, 1.0));
-            mMoonDiffuse.setVec(LLColor4(0.0, 0.0, 0.0, 1.0));
-            mSunDir.setVec(LLVector4(0.0, 1.0, 0.0, 0.0));
-            mMoonDir.setVec(LLVector4(0.0, 1.0, 0.0, 0.0));
-		}
+    if (hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !hud_only)
+    {
+        LLVertexBuffer::unbind();
 
-        LLVector4 light_dir = sun_up ? mSunDir : mMoonDir;
+        LLGLEnable blend(GL_BLEND);
+        LLGLDepthTest depth(TRUE, FALSE);
+        LLGLDisable cull(GL_CULL_FACE);
 
-        mHWLightColors[0] = sun_up ? mSunDiffuse : mMoonDiffuse;
+        gGL.color4f(1,1,1,1);
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
 
-		LLLightState* light = gGL.getLight(0);
-        light->setPosition(light_dir);
+        F32 a = 0.1f;
 
-        light->setSunPrimary(sun_up);
-        light->setDiffuse(mHWLightColors[0]);
-        light->setDiffuseB(mMoonDiffuse);
-        light->setAmbient(psky->getTotalAmbient());
-		light->setSpecular(LLColor4::black);
-		light->setConstantAttenuation(1.f);
-		light->setLinearAttenuation(0.f);
-		light->setQuadraticAttenuation(0.f);
-		light->setSpotExponent(0.f);
-		light->setSpotCutoff(180.f);
-	}
-	
-	// Light 1 = Backlight (for avatars)
-	// (set by enableLightsAvatar)
-	
-	S32 cur_light = 2;
-	
-	// Nearby lights = LIGHT 2-7
-
-	mLightMovingMask = 0;
-	
-	static LLCachedControl<S32> local_light_count(gSavedSettings, "RenderLocalLightCount", 256);
-
-	if (local_light_count >= 1)
-	{
-		for (light_set_t::iterator iter = mNearbyLights.begin();
-			 iter != mNearbyLights.end(); ++iter)
-		{
-			LLDrawable* drawable = iter->drawable;
-			LLVOVolume* light = drawable->getVOVolume();
-			if (!light)
-			{
-				continue;
-			}
+        F32 col[] =
+        {
+            1,0,0,a,
+            0,1,0,a,
+            0,0,1,a,
+            1,0,1,a,
+
+            1,1,0,a,
+            0,1,1,a,
+            1,1,1,a,
+            1,0,1,a,
+        };
+
+        for (U32 i = 0; i < 8; i++)
+        {
+            LLVector3* frust = mShadowCamera[i].mAgentFrustum;
 
-            if (light->isAttachment())
-            {
-                if (!sRenderAttachedLights)
+            if (i > 3)
+            { //render shadow frusta as volumes
+                if (mShadowFrustPoints[i-4].empty())
                 {
                     continue;
                 }
+
+                gGL.color4fv(col+(i-4)*4);
+
+                gGL.begin(LLRender::TRIANGLE_STRIP);
+                gGL.vertex3fv(frust[0].mV); gGL.vertex3fv(frust[4].mV);
+                gGL.vertex3fv(frust[1].mV); gGL.vertex3fv(frust[5].mV);
+                gGL.vertex3fv(frust[2].mV); gGL.vertex3fv(frust[6].mV);
+                gGL.vertex3fv(frust[3].mV); gGL.vertex3fv(frust[7].mV);
+                gGL.vertex3fv(frust[0].mV); gGL.vertex3fv(frust[4].mV);
+                gGL.end();
+
+
+                gGL.begin(LLRender::TRIANGLE_STRIP);
+                gGL.vertex3fv(frust[0].mV);
+                gGL.vertex3fv(frust[1].mV);
+                gGL.vertex3fv(frust[3].mV);
+                gGL.vertex3fv(frust[2].mV);
+                gGL.end();
+
+                gGL.begin(LLRender::TRIANGLE_STRIP);
+                gGL.vertex3fv(frust[4].mV);
+                gGL.vertex3fv(frust[5].mV);
+                gGL.vertex3fv(frust[7].mV);
+                gGL.vertex3fv(frust[6].mV);
+                gGL.end();
             }
 
-			if (drawable->isState(LLDrawable::ACTIVE))
-			{
-				mLightMovingMask |= (1<<cur_light);
-			}
-			
-            //send linear light color to shader
-            LLColor4  light_color = light->getLightLinearColor() * light_scale;
-			light_color.mV[3] = 0.0f;
-
-			F32 fade = iter->fade;
-			if (fade < LIGHT_FADE_TIME)
-			{
-				// fade in/out light
-				if (fade >= 0.f)
-				{
-					fade = fade / LIGHT_FADE_TIME;
-					((Light*) (&(*iter)))->fade += gFrameIntervalSeconds.value();
-				}
-				else
-				{
-					fade = 1.f + fade / LIGHT_FADE_TIME;
-					((Light*) (&(*iter)))->fade -= gFrameIntervalSeconds.value();
-				}
-				fade = llclamp(fade,0.f,1.f);
-				light_color *= fade;
-			}
 
-            if (light_color.magVecSquared() < 0.001f)
+            if (i < 4)
             {
-                continue;
-            }
 
-            LLVector3 light_pos(light->getRenderPosition());
-            LLVector4 light_pos_gl(light_pos, 1.0f);
+                //if (i == 0 || !mShadowFrustPoints[i].empty())
+                {
+                    //render visible point cloud
+                    gGL.flush();
+                    glPointSize(8.f);
+                    gGL.begin(LLRender::POINTS);
 
-            F32 adjusted_radius = light->getLightRadius() * (sRenderDeferred ? 1.5f : 1.0f);
-            if (adjusted_radius <= 0.001f)
+                    F32* c = col+i*4;
+                    gGL.color3fv(c);
+
+                    for (U32 j = 0; j < mShadowFrustPoints[i].size(); ++j)
+                        {
+                            gGL.vertex3fv(mShadowFrustPoints[i][j].mV);
+
+                        }
+                    gGL.end();
+
+                    gGL.flush();
+                    glPointSize(1.f);
+
+                    LLVector3* ext = mShadowExtents[i];
+                    LLVector3 pos = (ext[0]+ext[1])*0.5f;
+                    LLVector3 size = (ext[1]-ext[0])*0.5f;
+                    drawBoxOutline(pos, size);
+
+                    //render camera frustum splits as outlines
+                    gGL.begin(LLRender::LINES);
+                    gGL.vertex3fv(frust[0].mV); gGL.vertex3fv(frust[1].mV);
+                    gGL.vertex3fv(frust[1].mV); gGL.vertex3fv(frust[2].mV);
+                    gGL.vertex3fv(frust[2].mV); gGL.vertex3fv(frust[3].mV);
+                    gGL.vertex3fv(frust[3].mV); gGL.vertex3fv(frust[0].mV);
+                    gGL.vertex3fv(frust[4].mV); gGL.vertex3fv(frust[5].mV);
+                    gGL.vertex3fv(frust[5].mV); gGL.vertex3fv(frust[6].mV);
+                    gGL.vertex3fv(frust[6].mV); gGL.vertex3fv(frust[7].mV);
+                    gGL.vertex3fv(frust[7].mV); gGL.vertex3fv(frust[4].mV);
+                    gGL.vertex3fv(frust[0].mV); gGL.vertex3fv(frust[4].mV);
+                    gGL.vertex3fv(frust[1].mV); gGL.vertex3fv(frust[5].mV);
+                    gGL.vertex3fv(frust[2].mV); gGL.vertex3fv(frust[6].mV);
+                    gGL.vertex3fv(frust[3].mV); gGL.vertex3fv(frust[7].mV);
+                    gGL.end();
+                }
+            }
+
+            /*gGL.flush();
+            gGL.setLineWidth(16-i*2);
+            for (LLWorld::region_list_t::const_iterator iter = LLWorld::getInstance()->getRegionList().begin();
+                    iter != LLWorld::getInstance()->getRegionList().end(); ++iter)
             {
-                continue;
+                LLViewerRegion* region = *iter;
+                for (U32 j = 0; j < LLViewerRegion::NUM_PARTITIONS; j++)
+                {
+                    LLSpatialPartition* part = region->getSpatialPartition(j);
+                    if (part)
+                    {
+                        if (hasRenderType(part->mDrawableType))
+                        {
+                            part->renderIntersectingBBoxes(&mShadowCamera[i]);
+                        }
+                    }
+                }
             }
+            gGL.flush();
+            gGL.setLineWidth(1.f);*/
+        }
+    }
 
-            F32 x = (3.f * (1.f + (light->getLightFalloff() * 2.0f)));  // why this magic?  probably trying to match a historic behavior.
-            F32 linatten = x / adjusted_radius;                         // % of brightness at radius
+    if (mRenderDebugMask & RENDER_DEBUG_WIND_VECTORS)
+    {
+        gAgent.getRegion()->mWind.renderVectors();
+    }
 
-            mHWLightColors[cur_light] = light_color;
-			LLLightState* light_state = gGL.getLight(cur_light);
-			
-			light_state->setPosition(light_pos_gl);
-			light_state->setDiffuse(light_color);
-			light_state->setAmbient(LLColor4::black);
-			light_state->setConstantAttenuation(0.f);
-            light_state->setSize(light->getLightRadius() * 1.5f);
-            light_state->setFalloff(light->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
+    if (mRenderDebugMask & RENDER_DEBUG_COMPOSITION)
+    {
+        // Debug composition layers
+        F32 x, y;
 
-			if (sRenderDeferred)
-			{
-				light_state->setLinearAttenuation(linatten);
-				light_state->setQuadraticAttenuation(light->getLightFalloff(DEFERRED_LIGHT_FALLOFF) + 1.f); // get falloff to match for forward deferred rendering lights
-			}
-			else
-			{
-				light_state->setLinearAttenuation(linatten);
-				light_state->setQuadraticAttenuation(0.f);
-			}
-			
-
-			if (light->isLightSpotlight() // directional (spot-)light
-			    && (LLPipeline::sRenderDeferred || RenderSpotLightsInNondeferred)) // these are only rendered as GL spotlights if we're in deferred rendering mode *or* the setting forces them on
-			{
-				LLQuaternion quat = light->getRenderRotation();
-				LLVector3 at_axis(0,0,-1); // this matches deferred rendering's object light direction
-				at_axis *= quat;
-
-				light_state->setSpotDirection(at_axis);
-				light_state->setSpotCutoff(90.f);
-				light_state->setSpotExponent(2.f);
-	
-				LLVector3 spotParams = light->getSpotLightParams();
-
-				const LLColor4 specular(0.f, 0.f, 0.f, spotParams[2]);
-				light_state->setSpecular(specular);
-			}
-			else // omnidirectional (point) light
-			{
-				light_state->setSpotExponent(0.f);
-				light_state->setSpotCutoff(180.f);
-				
-				// we use specular.z = 1.0 as a cheap hack for the shaders to know that this is omnidirectional rather than a spotlight
-				const LLColor4 specular(0.f, 0.f, 1.f, 0.f);
-				light_state->setSpecular(specular);				
-			}
-			cur_light++;
-			if (cur_light >= 8)
-			{
-				break; // safety
-			}
-		}
-	}
-	for ( ; cur_light < 8 ; cur_light++)
-	{
-		mHWLightColors[cur_light] = LLColor4::black;
-		LLLightState* light = gGL.getLight(cur_light);
-        light->setSunPrimary(true);
-		light->setDiffuse(LLColor4::black);
-		light->setAmbient(LLColor4::black);
-		light->setSpecular(LLColor4::black);
-	}
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
 
-    // Bookmark comment to allow searching for mSpecialRenderMode == 3 (avatar edit mode),
-    // prev site of forward (non-deferred) character light injection, removed by SL-13522 09/20
+        if (gAgent.getRegion())
+        {
+            gGL.begin(LLRender::POINTS);
+            // Draw the composition layer for the region that I'm in.
+            for (x = 0; x <= 260; x++)
+            {
+                for (y = 0; y <= 260; y++)
+                {
+                    if ((x > 255) || (y > 255))
+                    {
+                        gGL.color4f(1.f, 0.f, 0.f, 1.f);
+                    }
+                    else
+                    {
+                        gGL.color4f(0.f, 0.f, 1.f, 1.f);
+                    }
+                    F32 z = gAgent.getRegion()->getCompositionXY((S32)x, (S32)y);
+                    z *= 5.f;
+                    z += 50.f;
+                    gGL.vertex3f(x, y, z);
+                }
+            }
+            gGL.end();
+        }
+    }
 
-	// Init GL state
-	for (S32 i = 0; i < 8; ++i)
-	{
-		gGL.getLight(i)->disable();
-	}
-	mLightMask = 0;
+    gGL.flush();
+    gUIProgram.unbind();
 }
 
-void LLPipeline::enableLights(U32 mask)
+void LLPipeline::rebuildPools()
 {
-	assertInitialized();
-
-	if (mLightMask != mask)
-	{
-		stop_glerror();
-		if (mask)
-		{
-			stop_glerror();
-			for (S32 i=0; i<8; i++)
-			{
-				LLLightState* light = gGL.getLight(i);
-				if (mask & (1<<i))
-				{
-					light->enable();
-					light->setDiffuse(mHWLightColors[i]);
-				}
-				else
-				{
-					light->disable();
-					light->setDiffuse(LLColor4::black);
-				}
-			}
-			stop_glerror();
-		}
-		mLightMask = mask;
-		stop_glerror();
-	}
-}
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
 
-void LLPipeline::enableLightsDynamic()
-{
-	assertInitialized();
-	U32 mask = 0xff & (~2); // Local lights
-	enableLights(mask);
-	
-	if (isAgentAvatarValid())
-	{
-		if (gAgentAvatarp->mSpecialRenderMode == 0) // normal
-		{
-			gPipeline.enableLightsAvatar();
-		}
-		else if (gAgentAvatarp->mSpecialRenderMode == 2)  // anim preview
-		{
-			gPipeline.enableLightsAvatarEdit(LLColor4(0.7f, 0.6f, 0.3f, 1.f));
-		}
-	}
-}
+    assertInitialized();
 
-void LLPipeline::enableLightsAvatar()
-{
-	U32 mask = 0xff; // All lights
-	setupAvatarLights(FALSE);
-	enableLights(mask);
+    S32 max_count = mPools.size();
+    pool_set_t::iterator iter1 = mPools.upper_bound(mLastRebuildPool);
+    while(max_count > 0 && mPools.size() > 0) // && num_rebuilds < MAX_REBUILDS)
+    {
+        if (iter1 == mPools.end())
+        {
+            iter1 = mPools.begin();
+        }
+        LLDrawPool* poolp = *iter1;
+
+        if (poolp->isDead())
+        {
+            mPools.erase(iter1++);
+            removeFromQuickLookup( poolp );
+            if (poolp == mLastRebuildPool)
+            {
+                mLastRebuildPool = NULL;
+            }
+            delete poolp;
+        }
+        else
+        {
+            mLastRebuildPool = poolp;
+            iter1++;
+        }
+        max_count--;
+    }
 }
 
-void LLPipeline::enableLightsPreview()
+void LLPipeline::addToQuickLookup( LLDrawPool* new_poolp )
 {
-	disableLights();
-
-	LLColor4 ambient = PreviewAmbientColor;
-	gGL.setAmbientLightColor(ambient);
-
-	LLColor4 diffuse0 = PreviewDiffuse0;
-	LLColor4 specular0 = PreviewSpecular0;
-	LLColor4 diffuse1 = PreviewDiffuse1;
-	LLColor4 specular1 = PreviewSpecular1;
-	LLColor4 diffuse2 = PreviewDiffuse2;
-	LLColor4 specular2 = PreviewSpecular2;
-
-	LLVector3 dir0 = PreviewDirection0;
-	LLVector3 dir1 = PreviewDirection1;
-	LLVector3 dir2 = PreviewDirection2;
-
-	dir0.normVec();
-	dir1.normVec();
-	dir2.normVec();
-	
-	LLVector4 light_pos(dir0, 0.0f);
-
-	LLLightState* light = gGL.getLight(1);
-
-	light->enable();
-	light->setPosition(light_pos);
-	light->setDiffuse(diffuse0);
-	light->setAmbient(ambient);
-	light->setSpecular(specular0);
-	light->setSpotExponent(0.f);
-	light->setSpotCutoff(180.f);
-
-	light_pos = LLVector4(dir1, 0.f);
-
-	light = gGL.getLight(2);
-	light->enable();
-	light->setPosition(light_pos);
-	light->setDiffuse(diffuse1);
-	light->setAmbient(ambient);
-	light->setSpecular(specular1);
-	light->setSpotExponent(0.f);
-	light->setSpotCutoff(180.f);
-
-	light_pos = LLVector4(dir2, 0.f);
-	light = gGL.getLight(3);
-	light->enable();
-	light->setPosition(light_pos);
-	light->setDiffuse(diffuse2);
-	light->setAmbient(ambient);
-	light->setSpecular(specular2);
-	light->setSpotExponent(0.f);
-	light->setSpotCutoff(180.f);
-}
+    assertInitialized();
 
+    switch( new_poolp->getType() )
+    {
+    case LLDrawPool::POOL_SIMPLE:
+        if (mSimplePool)
+        {
+            llassert(0);
+            LL_WARNS() << "Ignoring duplicate simple pool." << LL_ENDL;
+        }
+        else
+        {
+            mSimplePool = (LLRenderPass*) new_poolp;
+        }
+        break;
 
-void LLPipeline::enableLightsAvatarEdit(const LLColor4& color)
-{
-	U32 mask = 0x2002; // Avatar backlight only, set ambient
-	setupAvatarLights(TRUE);
-	enableLights(mask);
+    case LLDrawPool::POOL_ALPHA_MASK:
+        if (mAlphaMaskPool)
+        {
+            llassert(0);
+            LL_WARNS() << "Ignoring duplicate alpha mask pool." << LL_ENDL;
+            break;
+        }
+        else
+        {
+            mAlphaMaskPool = (LLRenderPass*) new_poolp;
+        }
+        break;
 
-	gGL.setAmbientLightColor(color);
-}
+    case LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK:
+        if (mFullbrightAlphaMaskPool)
+        {
+            llassert(0);
+            LL_WARNS() << "Ignoring duplicate alpha mask pool." << LL_ENDL;
+            break;
+        }
+        else
+        {
+            mFullbrightAlphaMaskPool = (LLRenderPass*) new_poolp;
+        }
+        break;
 
-void LLPipeline::enableLightsFullbright()
-{
-	assertInitialized();
-	U32 mask = 0x1000; // Non-0 mask, set ambient
-	enableLights(mask);
-}
+    case LLDrawPool::POOL_GRASS:
+        if (mGrassPool)
+        {
+            llassert(0);
+            LL_WARNS() << "Ignoring duplicate grass pool." << LL_ENDL;
+        }
+        else
+        {
+            mGrassPool = (LLRenderPass*) new_poolp;
+        }
+        break;
 
-void LLPipeline::disableLights()
-{
-	enableLights(0); // no lighting (full bright)
-}
+    case LLDrawPool::POOL_FULLBRIGHT:
+        if (mFullbrightPool)
+        {
+            llassert(0);
+            LL_WARNS() << "Ignoring duplicate simple pool." << LL_ENDL;
+        }
+        else
+        {
+            mFullbrightPool = (LLRenderPass*) new_poolp;
+        }
+        break;
 
-//============================================================================
+    case LLDrawPool::POOL_GLOW:
+        if (mGlowPool)
+        {
+            llassert(0);
+            LL_WARNS() << "Ignoring duplicate glow pool." << LL_ENDL;
+        }
+        else
+        {
+            mGlowPool = (LLRenderPass*) new_poolp;
+        }
+        break;
 
-class LLMenuItemGL;
-class LLInvFVBridge;
-struct cat_folder_pair;
-class LLVOBranch;
-class LLVOLeaf;
+    case LLDrawPool::POOL_TREE:
+        mTreePools[ uintptr_t(new_poolp->getTexture()) ] = new_poolp ;
+        break;
 
-void LLPipeline::findReferences(LLDrawable *drawablep)
-{
-	assertInitialized();
-	if (mLights.find(drawablep) != mLights.end())
-	{
-		LL_INFOS() << "In mLights" << LL_ENDL;
-	}
-	if (std::find(mMovedList.begin(), mMovedList.end(), drawablep) != mMovedList.end())
-	{
-		LL_INFOS() << "In mMovedList" << LL_ENDL;
-	}
-	if (std::find(mShiftList.begin(), mShiftList.end(), drawablep) != mShiftList.end())
-	{
-		LL_INFOS() << "In mShiftList" << LL_ENDL;
-	}
-	if (mRetexturedList.find(drawablep) != mRetexturedList.end())
-	{
-		LL_INFOS() << "In mRetexturedList" << LL_ENDL;
-	}
-	
-	if (std::find(mBuildQ1.begin(), mBuildQ1.end(), drawablep) != mBuildQ1.end())
-	{
-		LL_INFOS() << "In mBuildQ1" << LL_ENDL;
-	}
-	
-	S32 count;
-	
-	count = gObjectList.findReferences(drawablep);
-	if (count)
-	{
-		LL_INFOS() << "In other drawables: " << count << " references" << LL_ENDL;
-	}
-}
+    case LLDrawPool::POOL_TERRAIN:
+        mTerrainPools[ uintptr_t(new_poolp->getTexture()) ] = new_poolp ;
+        break;
 
-bool LLPipeline::verify()
-{
-	bool ok = assertInitialized();
-	if (ok) 
-	{
-		for (LLDrawPool* poolp : mPools)
-		{
-			if (!poolp->verify())
-			{
-				ok = false;
-			}
-		}
-	}
-
-	if (!ok)
-	{
-		LL_WARNS() << "Pipeline verify failed!" << LL_ENDL;
-	}
-	return ok;
-}
+    case LLDrawPool::POOL_BUMP:
+        if (mBumpPool)
+        {
+            llassert(0);
+            LL_WARNS() << "Ignoring duplicate bump pool." << LL_ENDL;
+        }
+        else
+        {
+            mBumpPool = new_poolp;
+        }
+        break;
+    case LLDrawPool::POOL_MATERIALS:
+        if (mMaterialsPool)
+        {
+            llassert(0);
+            LL_WARNS() << "Ignorning duplicate materials pool." << LL_ENDL;
+        }
+        else
+        {
+            mMaterialsPool = new_poolp;
+        }
+        break;
+    case LLDrawPool::POOL_ALPHA_PRE_WATER:
+        if( mAlphaPoolPreWater )
+        {
+            llassert(0);
+            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate Alpha pre-water pool" << LL_ENDL;
+        }
+        else
+        {
+            mAlphaPoolPreWater = (LLDrawPoolAlpha*) new_poolp;
+        }
+        break;
+    case LLDrawPool::POOL_ALPHA_POST_WATER:
+        if (mAlphaPoolPostWater)
+        {
+            llassert(0);
+            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate Alpha post-water pool" << LL_ENDL;
+        }
+        else
+        {
+            mAlphaPoolPostWater = (LLDrawPoolAlpha*)new_poolp;
+        }
+        break;
 
-//////////////////////////////
-//
-// Collision detection
-//
-//
+    case LLDrawPool::POOL_AVATAR:
+    case LLDrawPool::POOL_CONTROL_AV:
+        break; // Do nothing
 
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-/**
- *	A method to compute a ray-AABB intersection.
- *	Original code by Andrew Woo, from "Graphics Gems", Academic Press, 1990
- *	Optimized code by Pierre Terdiman, 2000 (~20-30% faster on my Celeron 500)
- *	Epsilon value added by Klaus Hartmann. (discarding it saves a few cycles only)
- *
- *	Hence this version is faster as well as more robust than the original one.
- *
- *	Should work provided:
- *	1) the integer representation of 0.0f is 0x00000000
- *	2) the sign bit of the float is the most significant one
- *
- *	Report bugs: p.terdiman@codercorner.com
- *
- *	\param		aabb		[in] the axis-aligned bounding box
- *	\param		origin		[in] ray origin
- *	\param		dir			[in] ray direction
- *	\param		coord		[out] impact coordinates
- *	\return		true if ray intersects AABB
- */
-///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-//#define RAYAABB_EPSILON 0.00001f
-#define IR(x)	((U32&)x)
+    case LLDrawPool::POOL_SKY:
+        if( mSkyPool )
+        {
+            llassert(0);
+            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate Sky pool" << LL_ENDL;
+        }
+        else
+        {
+            mSkyPool = new_poolp;
+        }
+        break;
 
-bool LLRayAABB(const LLVector3 &center, const LLVector3 &size, const LLVector3& origin, const LLVector3& dir, LLVector3 &coord, F32 epsilon)
-{
-	bool Inside = true;
-	LLVector3 MinB = center - size;
-	LLVector3 MaxB = center + size;
-	LLVector3 MaxT;
-	MaxT.mV[VX]=MaxT.mV[VY]=MaxT.mV[VZ]=-1.0f;
-
-	// Find candidate planes.
-	for(U32 i=0;i<3;i++)
-	{
-		if(origin.mV[i] < MinB.mV[i])
-		{
-			coord.mV[i]	= MinB.mV[i];
-			Inside		= false;
-
-			// Calculate T distances to candidate planes
-            U32 tmp;
-            memcpy(&tmp, &dir.mV[i], sizeof(tmp));
-			if(tmp)	MaxT.mV[i] = (MinB.mV[i] - origin.mV[i]) / dir.mV[i];
-		}
-		else if(origin.mV[i] > MaxB.mV[i])
-		{
-			coord.mV[i]	= MaxB.mV[i];
-			Inside		= false;
-
-			// Calculate T distances to candidate planes
-            U32 tmp;
-            memcpy(&tmp, &dir.mV[i], sizeof(tmp));
-			if(tmp)	MaxT.mV[i] = (MaxB.mV[i] - origin.mV[i]) / dir.mV[i];
-		}
-	}
-
-	// Ray origin inside bounding box
-	if(Inside)
-	{
-		coord = origin;
-		return true;
-	}
-
-	// Get largest of the maxT's for final choice of intersection
-	U32 WhichPlane = 0;
-	if(MaxT.mV[1] > MaxT.mV[WhichPlane])	WhichPlane = 1;
-	if(MaxT.mV[2] > MaxT.mV[WhichPlane])	WhichPlane = 2;
-
-	// Check final candidate actually inside box
-    U32 tmp_val;
-    memcpy(&tmp_val, &MaxT.mV[WhichPlane], sizeof(tmp_val));
-	if(tmp_val&0x80000000) return false;
-
-	for(U32 i=0;i<3;i++)
-	{
-		if(i!=WhichPlane)
-		{
-			coord.mV[i] = origin.mV[i] + MaxT.mV[WhichPlane] * dir.mV[i];
-			if (epsilon > 0)
-			{
-				if(coord.mV[i] < MinB.mV[i] - epsilon || coord.mV[i] > MaxB.mV[i] + epsilon)	return false;
-			}
-			else
-			{
-				if(coord.mV[i] < MinB.mV[i] || coord.mV[i] > MaxB.mV[i])	return false;
-			}
-		}
-	}
-	return true;	// ray hits box
-}
+    case LLDrawPool::POOL_WATER:
+        if( mWaterPool )
+        {
+            llassert(0);
+            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate Water pool" << LL_ENDL;
+        }
+        else
+        {
+            mWaterPool = new_poolp;
+        }
+        break;
 
-//////////////////////////////
-//
-// Macros, functions, and inline methods from other classes
-//
-//
+    case LLDrawPool::POOL_WL_SKY:
+        if( mWLSkyPool )
+        {
+            llassert(0);
+            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate WLSky Pool" << LL_ENDL;
+        }
+        else
+        {
+            mWLSkyPool = new_poolp;
+        }
+        break;
 
-void LLPipeline::setLight(LLDrawable *drawablep, bool is_light)
-{
-	if (drawablep && assertInitialized())
-	{
-		if (is_light)
-		{
-			mLights.insert(drawablep);
-			drawablep->setState(LLDrawable::LIGHT);
-		}
-		else
-		{
-			drawablep->clearState(LLDrawable::LIGHT);
-			mLights.erase(drawablep);
-		}
-	}
-}
+    case LLDrawPool::POOL_GLTF_PBR:
+        if( mPBROpaquePool )
+        {
+            llassert(0);
+            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate PBR Opaque Pool" << LL_ENDL;
+        }
+        else
+        {
+            mPBROpaquePool = new_poolp;
+        }
+        break;
 
-//static
-void LLPipeline::toggleRenderType(U32 type)
-{
-	gPipeline.mRenderTypeEnabled[type] = !gPipeline.mRenderTypeEnabled[type];
-	if (type == LLPipeline::RENDER_TYPE_WATER)
-	{
-		gPipeline.mRenderTypeEnabled[LLPipeline::RENDER_TYPE_VOIDWATER] = !gPipeline.mRenderTypeEnabled[LLPipeline::RENDER_TYPE_VOIDWATER];
-	}
-}
+    case LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK:
+        if (mPBRAlphaMaskPool)
+        {
+            llassert(0);
+            LL_WARNS() << "LLPipeline::addPool(): Ignoring duplicate PBR Alpha Mask Pool" << LL_ENDL;
+        }
+        else
+        {
+            mPBRAlphaMaskPool = new_poolp;
+        }
+        break;
 
-//static
-void LLPipeline::toggleRenderTypeControl(U32 type)
-{
-	gPipeline.toggleRenderType(type);
-}
 
-//static
-bool LLPipeline::hasRenderTypeControl(U32 type)
-{
-	return gPipeline.hasRenderType(type);
+    default:
+        llassert(0);
+        LL_WARNS() << "Invalid Pool Type in  LLPipeline::addPool()" << LL_ENDL;
+        break;
+    }
 }
 
-// Allows UI items labeled "Hide foo" instead of "Show foo"
-//static
-bool LLPipeline::toggleRenderTypeControlNegated(S32 type)
+void LLPipeline::removePool( LLDrawPool* poolp )
 {
-	return !gPipeline.hasRenderType(type);
+    assertInitialized();
+    removeFromQuickLookup(poolp);
+    mPools.erase(poolp);
+    delete poolp;
 }
 
-//static
-void LLPipeline::toggleRenderDebug(U64 bit)
+void LLPipeline::removeFromQuickLookup( LLDrawPool* poolp )
 {
-	if (gPipeline.hasRenderDebugMask(bit))
-	{
-		LL_INFOS() << "Toggling render debug mask " << std::hex << bit << " off" << std::dec << LL_ENDL;
-	}
-	else
-	{
-		LL_INFOS() << "Toggling render debug mask " << std::hex << bit << " on" << std::dec << LL_ENDL;
-	}
-	gPipeline.mRenderDebugMask ^= bit;
-}
-
+    assertInitialized();
+    switch( poolp->getType() )
+    {
+    case LLDrawPool::POOL_SIMPLE:
+        llassert(mSimplePool == poolp);
+        mSimplePool = NULL;
+        break;
 
-//static
-bool LLPipeline::toggleRenderDebugControl(U64 bit)
-{
-	return gPipeline.hasRenderDebugMask(bit);
-}
+    case LLDrawPool::POOL_ALPHA_MASK:
+        llassert(mAlphaMaskPool == poolp);
+        mAlphaMaskPool = NULL;
+        break;
 
-//static
-void LLPipeline::toggleRenderDebugFeature(U32 bit)
-{
-	gPipeline.mRenderDebugFeatureMask ^= bit;
-}
+    case LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK:
+        llassert(mFullbrightAlphaMaskPool == poolp);
+        mFullbrightAlphaMaskPool = NULL;
+        break;
 
+    case LLDrawPool::POOL_GRASS:
+        llassert(mGrassPool == poolp);
+        mGrassPool = NULL;
+        break;
 
-//static
-bool LLPipeline::toggleRenderDebugFeatureControl(U32 bit)
-{
-	return gPipeline.hasRenderDebugFeatureMask(bit);
-}
+    case LLDrawPool::POOL_FULLBRIGHT:
+        llassert(mFullbrightPool == poolp);
+        mFullbrightPool = NULL;
+        break;
 
-void LLPipeline::setRenderDebugFeatureControl(U32 bit, bool value)
-{
-	if (value)
-	{
-		gPipeline.mRenderDebugFeatureMask |= bit;
-	}
-	else
-	{
-		gPipeline.mRenderDebugFeatureMask &= !bit;
-	}
-}
+    case LLDrawPool::POOL_WL_SKY:
+        llassert(mWLSkyPool == poolp);
+        mWLSkyPool = NULL;
+        break;
 
-void LLPipeline::pushRenderDebugFeatureMask()
-{
-	mRenderDebugFeatureStack.push(mRenderDebugFeatureMask);
-}
+    case LLDrawPool::POOL_GLOW:
+        llassert(mGlowPool == poolp);
+        mGlowPool = NULL;
+        break;
 
-void LLPipeline::popRenderDebugFeatureMask()
-{
-	if (mRenderDebugFeatureStack.empty())
-	{
-		LL_ERRS() << "Depleted render feature stack." << LL_ENDL;
-	}
+    case LLDrawPool::POOL_TREE:
+        #ifdef _DEBUG
+            {
+                bool found = mTreePools.erase( (uintptr_t)poolp->getTexture() );
+                llassert( found );
+            }
+        #else
+            mTreePools.erase( (uintptr_t)poolp->getTexture() );
+        #endif
+        break;
 
-	mRenderDebugFeatureMask = mRenderDebugFeatureStack.top();
-	mRenderDebugFeatureStack.pop();
-}
+    case LLDrawPool::POOL_TERRAIN:
+        #ifdef _DEBUG
+            {
+                bool found = mTerrainPools.erase( (uintptr_t)poolp->getTexture() );
+                llassert( found );
+            }
+        #else
+            mTerrainPools.erase( (uintptr_t)poolp->getTexture() );
+        #endif
+        break;
 
-// static
-void LLPipeline::setRenderScriptedBeacons(bool val)
-{
-	sRenderScriptedBeacons = val;
-}
+    case LLDrawPool::POOL_BUMP:
+        llassert( poolp == mBumpPool );
+        mBumpPool = NULL;
+        break;
 
-// static
-void LLPipeline::toggleRenderScriptedBeacons()
-{
-	sRenderScriptedBeacons = !sRenderScriptedBeacons;
-}
+    case LLDrawPool::POOL_MATERIALS:
+        llassert(poolp == mMaterialsPool);
+        mMaterialsPool = NULL;
+        break;
 
-// static
-bool LLPipeline::getRenderScriptedBeacons()
-{
-	return sRenderScriptedBeacons;
-}
+    case LLDrawPool::POOL_ALPHA_PRE_WATER:
+        llassert( poolp == mAlphaPoolPreWater );
+        mAlphaPoolPreWater = nullptr;
+        break;
 
-// static
-void LLPipeline::setRenderScriptedTouchBeacons(bool val)
-{
-	sRenderScriptedTouchBeacons = val;
-}
+    case LLDrawPool::POOL_ALPHA_POST_WATER:
+        llassert(poolp == mAlphaPoolPostWater);
+        mAlphaPoolPostWater = nullptr;
+        break;
 
-// static
-void LLPipeline::toggleRenderScriptedTouchBeacons()
-{
-	sRenderScriptedTouchBeacons = !sRenderScriptedTouchBeacons;
-}
+    case LLDrawPool::POOL_AVATAR:
+    case LLDrawPool::POOL_CONTROL_AV:
+        break; // Do nothing
 
-// static
-bool LLPipeline::getRenderScriptedTouchBeacons()
-{
-	return sRenderScriptedTouchBeacons;
-}
+    case LLDrawPool::POOL_SKY:
+        llassert( poolp == mSkyPool );
+        mSkyPool = NULL;
+        break;
 
-// static
-void LLPipeline::setRenderMOAPBeacons(bool val)
-{
-	sRenderMOAPBeacons = val;
-}
+    case LLDrawPool::POOL_WATER:
+        llassert( poolp == mWaterPool );
+        mWaterPool = NULL;
+        break;
 
-// static
-void LLPipeline::toggleRenderMOAPBeacons()
-{
-	sRenderMOAPBeacons = !sRenderMOAPBeacons;
-}
+    case LLDrawPool::POOL_GLTF_PBR:
+        llassert( poolp == mPBROpaquePool );
+        mPBROpaquePool = NULL;
+        break;
 
-// static
-bool LLPipeline::getRenderMOAPBeacons()
-{
-	return sRenderMOAPBeacons;
-}
+    case LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK:
+        llassert(poolp == mPBRAlphaMaskPool);
+        mPBRAlphaMaskPool = NULL;
+        break;
 
-// static
-void LLPipeline::setRenderPhysicalBeacons(bool val)
-{
-	sRenderPhysicalBeacons = val;
+    default:
+        llassert(0);
+        LL_WARNS() << "Invalid Pool Type in  LLPipeline::removeFromQuickLookup() type=" << poolp->getType() << LL_ENDL;
+        break;
+    }
 }
 
-// static
-void LLPipeline::toggleRenderPhysicalBeacons()
+void LLPipeline::resetDrawOrders()
 {
-	sRenderPhysicalBeacons = !sRenderPhysicalBeacons;
-}
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+    assertInitialized();
+    // Iterate through all of the draw pools and rebuild them.
+    for (LLDrawPool* poolp : mPools)
+    {
 
-// static
-bool LLPipeline::getRenderPhysicalBeacons()
-{
-	return sRenderPhysicalBeacons;
+        poolp->resetDrawOrders();
+    }
 }
 
-// static
-void LLPipeline::setRenderParticleBeacons(bool val)
-{
-	sRenderParticleBeacons = val;
-}
+//============================================================================
+// Once-per-frame setup of hardware lights,
+// including sun/moon, avatar backlight, and up to 6 local lights
 
-// static
-void LLPipeline::toggleRenderParticleBeacons()
+void LLPipeline::setupAvatarLights(bool for_edit)
 {
-	sRenderParticleBeacons = !sRenderParticleBeacons;
-}
+    assertInitialized();
 
-// static
-bool LLPipeline::getRenderParticleBeacons()
-{
-	return sRenderParticleBeacons;
-}
+    LLEnvironment& environment = LLEnvironment::instance();
+    bool sun_up = environment.getIsSunUp();
 
-// static
-void LLPipeline::setRenderSoundBeacons(bool val)
-{
-	sRenderSoundBeacons = val;
-}
-
-// static
-void LLPipeline::toggleRenderSoundBeacons()
-{
-	sRenderSoundBeacons = !sRenderSoundBeacons;
-}
-
-// static
-bool LLPipeline::getRenderSoundBeacons()
-{
-	return sRenderSoundBeacons;
-}
-
-// static
-void LLPipeline::setRenderBeacons(bool val)
-{
-	sRenderBeacons = val;
-}
-
-// static
-void LLPipeline::toggleRenderBeacons()
-{
-	sRenderBeacons = !sRenderBeacons;
-}
-
-// static
-bool LLPipeline::getRenderBeacons()
-{
-	return sRenderBeacons;
-}
-
-// static
-void LLPipeline::setRenderHighlights(bool val)
-{
-	sRenderHighlight = val;
-}
-
-// static
-void LLPipeline::toggleRenderHighlights()
-{
-	sRenderHighlight = !sRenderHighlight;
-}
-
-// static
-bool LLPipeline::getRenderHighlights()
-{
-	return sRenderHighlight;
-}
-
-// static
-void LLPipeline::setRenderHighlightTextureChannel(LLRender::eTexIndex channel)
-{
-	sRenderHighlightTextureChannel = channel;
-}
-
-LLVOPartGroup* LLPipeline::lineSegmentIntersectParticle(const LLVector4a& start, const LLVector4a& end, LLVector4a* intersection,
-														S32* face_hit)
-{
-	LLVector4a local_end = end;
-
-	LLVector4a position;
-	position.clear();
-
-	LLDrawable* drawable = NULL;
-
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		LLSpatialPartition* part = region->getSpatialPartition(LLViewerRegion::PARTITION_PARTICLE);
-		if (part && hasRenderType(part->mDrawableType))
-		{
-			LLDrawable* hit = part->lineSegmentIntersect(start, local_end, TRUE, FALSE, TRUE, FALSE, face_hit, &position, NULL, NULL, NULL);
-			if (hit)
-			{
-				drawable = hit;
-				local_end = position;						
-			}
-		}
-	}
-
-	LLVOPartGroup* ret = NULL;
-	if (drawable)
-	{
-		//make sure we're returning an LLVOPartGroup
-		llassert(drawable->getVObj()->getPCode() == LLViewerObject::LL_VO_PART_GROUP);
-		ret = (LLVOPartGroup*) drawable->getVObj().get();
-	}
-		
-	if (intersection)
-	{
-		*intersection = position;
-	}
-
-	return ret;
-}
-
-LLViewerObject* LLPipeline::lineSegmentIntersectInWorld(const LLVector4a& start, const LLVector4a& end,
-														bool pick_transparent,
-														bool pick_rigged,
-                                                        bool pick_unselectable,
-                                                        bool pick_reflection_probe,
-														S32* face_hit,
-                                                        S32* gltf_node_hit,
-                                                        S32* gltf_primitive_hit,
-														LLVector4a* intersection,         // return the intersection point
-														LLVector2* tex_coord,            // return the texture coordinates of the intersection point
-														LLVector4a* normal,               // return the surface normal at the intersection point
-														LLVector4a* tangent             // return the surface tangent at the intersection point
-	)
-{
-	LLDrawable* drawable = NULL;
-
-	LLVector4a local_end = end;
-
-	LLVector4a position;
-	position.clear();
-
-	sPickAvatar = false; //! LLToolMgr::getInstance()->inBuildMode();
-	
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		for (U32 j = 0; j < LLViewerRegion::NUM_PARTITIONS; j++)
-		{
-			if ((j == LLViewerRegion::PARTITION_VOLUME) || 
-				(j == LLViewerRegion::PARTITION_BRIDGE) ||
-				(j == LLViewerRegion::PARTITION_AVATAR) || // for attachments
-				(j == LLViewerRegion::PARTITION_CONTROL_AV) ||
-				(j == LLViewerRegion::PARTITION_TERRAIN) ||
-				(j == LLViewerRegion::PARTITION_TREE) ||
-				(j == LLViewerRegion::PARTITION_GRASS))  // only check these partitions for now
-			{
-				LLSpatialPartition* part = region->getSpatialPartition(j);
-				if (part && hasRenderType(part->mDrawableType))
-				{
-					LLDrawable* hit = part->lineSegmentIntersect(start, local_end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe, face_hit, &position, tex_coord, normal, tangent);
-					if (hit)
-					{
-						drawable = hit;
-						local_end = position;						
-					}
-				}
-			}
-		}
-	}
-
-	if (!sPickAvatar)
-	{
-		//save hit info in case we need to restore
-		//due to attachment override
-		LLVector4a local_normal;
-		LLVector4a local_tangent;
-		LLVector2 local_texcoord;
-		S32 local_face_hit = -1;
-
-		if (face_hit)
-		{ 
-			local_face_hit = *face_hit;
-		}
-		if (tex_coord)
-		{
-			local_texcoord = *tex_coord;
-		}
-		if (tangent)
-		{
-			local_tangent = *tangent;
-		}
-		else
-		{
-			local_tangent.clear();
-		}
-		if (normal)
-		{
-			local_normal = *normal;
-		}
-		else
-		{
-			local_normal.clear();
-		}
-				
-		const F32 ATTACHMENT_OVERRIDE_DIST = 0.1f;
-
-		//check against avatars
-		sPickAvatar = true;
-		for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-		{
-			LLSpatialPartition* part = region->getSpatialPartition(LLViewerRegion::PARTITION_AVATAR);
-			if (part && hasRenderType(part->mDrawableType))
-			{
-				LLDrawable* hit = part->lineSegmentIntersect(start, local_end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe, face_hit, &position, tex_coord, normal, tangent);
-				if (hit)
-				{
-					LLVector4a delta;
-					delta.setSub(position, local_end);
-
-					if (!drawable || 
-						!drawable->getVObj()->isAttachment() ||
-						delta.getLength3().getF32() > ATTACHMENT_OVERRIDE_DIST)
-					{ //avatar overrides if previously hit drawable is not an attachment or 
-					  //attachment is far enough away from detected intersection
-						drawable = hit;
-						local_end = position;						
-					}
-					else
-					{ //prioritize attachments over avatars
-						position = local_end;
-
-						if (face_hit)
-						{
-							*face_hit = local_face_hit;
-						}
-						if (tex_coord)
-						{
-							*tex_coord = local_texcoord;
-						}
-						if (tangent)
-						{
-							*tangent = local_tangent;
-						}
-						if (normal)
-						{
-							*normal = local_normal;
-						}
-					}
-				}
-			}
-		}
-	}
-
-	//check all avatar nametags (silly, isn't it?)
-	for (std::vector< LLCharacter* >::iterator iter = LLCharacter::sInstances.begin();
-		iter != LLCharacter::sInstances.end();
-		++iter)
-	{
-		LLVOAvatar* av = (LLVOAvatar*) *iter;
-		if (av->mNameText.notNull()
-			&& av->mNameText->lineSegmentIntersect(start, local_end, position))
-		{
-			drawable = av->mDrawable;
-			local_end = position;
-		}
-	}
-
-    S32 node_hit = -1;
-    S32 primitive_hit = -1;
-    LLDrawable* hit = LL::GLTFSceneManager::instance().lineSegmentIntersect(start, local_end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe, &node_hit, &primitive_hit, &position, tex_coord, normal, tangent);
-    if (hit)
-    {
-        drawable = hit;
-        local_end = position;
-    }
-
-    if (gltf_node_hit)
+    if (for_edit)
     {
-        *gltf_node_hit = node_hit;
+        LLColor4 diffuse(1.f, 1.f, 1.f, 0.f);
+        LLVector4a light_pos_cam(-8.f, 0.25f, 10.f, 0.f);  // w==0 => directional light
+        LLMatrix4a camera_rot = LLViewerCamera::getInstance()->getModelview();
+        camera_rot.extractRotation_affine();
+        camera_rot.invert();
+        LLVector4a light_pos;
+
+        camera_rot.rotate(light_pos_cam,light_pos);
+
+        light_pos.normalize3fast();
+
+        LLLightState* light = gGL.getLight(1);
+
+        mHWLightColors[1] = diffuse;
+
+        light->setDiffuse(diffuse);
+        light->setAmbient(LLColor4::black);
+        light->setSpecular(LLColor4::black);
+        light->setPosition(LLVector4(light_pos.getF32ptr()));
+        light->setConstantAttenuation(1.f);
+        light->setLinearAttenuation(0.f);
+        light->setQuadraticAttenuation(0.f);
+        light->setSpotExponent(0.f);
+        light->setSpotCutoff(180.f);
     }
-    
-    if (gltf_primitive_hit)
+    else if (gAvatarBacklight)
     {
-        *gltf_primitive_hit = primitive_hit;
-    }
-
-	if (intersection)
-	{
-		*intersection = position;
-	}
-
-	return drawable ? drawable->getVObj().get() : NULL;
-}
-
-LLViewerObject* LLPipeline::lineSegmentIntersectInHUD(const LLVector4a& start, const LLVector4a& end,
-													  bool pick_transparent,													
-													  S32* face_hit,
-													  LLVector4a* intersection,         // return the intersection point
-													  LLVector2* tex_coord,            // return the texture coordinates of the intersection point
-													  LLVector4a* normal,               // return the surface normal at the intersection point
-													  LLVector4a* tangent				// return the surface tangent at the intersection point
-	)
-{
-	LLDrawable* drawable = NULL;
-
-	for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
-	{
-		bool toggle = false;
-		if (!hasRenderType(LLPipeline::RENDER_TYPE_HUD))
-		{
-			toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
-			toggle = true;
-		}
-
-		LLSpatialPartition* part = region->getSpatialPartition(LLViewerRegion::PARTITION_HUD);
-		if (part)
-		{
-			LLDrawable* hit = part->lineSegmentIntersect(start, end, pick_transparent, FALSE, TRUE, FALSE, face_hit, intersection, tex_coord, normal, tangent);
-			if (hit)
-			{
-				drawable = hit;
-			}
-		}
-
-		if (toggle)
-		{
-			toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
-		}
-	}
-	return drawable ? drawable->getVObj().get() : NULL;
-}
+        LLVector3 light_dir = sun_up ? LLVector3(mSunDir) : LLVector3(mMoonDir);
+        LLVector3 opposite_pos = -light_dir;
+        LLVector3 orthog_light_pos = light_dir % LLVector3::z_axis;
+        LLVector4 backlight_pos = LLVector4(lerp(opposite_pos, orthog_light_pos, 0.3f), 0.0f);
+        backlight_pos.normalize();
 
-LLSpatialPartition* LLPipeline::getSpatialPartition(LLViewerObject* vobj)
-{
-	if (vobj)
-	{
-		LLViewerRegion* region = vobj->getRegion();
-		if (region)
-		{
-			return region->getSpatialPartition(vobj->getPartitionType());
-		}
-	}
-	return NULL;
-}
+        LLColor4 light_diffuse = sun_up ? mSunDiffuse : mMoonDiffuse;
 
-void LLPipeline::resetVertexBuffers(LLDrawable* drawable)
-{
-	if (!drawable)
-	{
-		return;
-	}
+        LLColor4 backlight_diffuse(1.f - light_diffuse.mV[VRED], 1.f - light_diffuse.mV[VGREEN], 1.f - light_diffuse.mV[VBLUE], 1.f);
+        F32 max_component = 0.001f;
+        for (S32 i = 0; i < 3; i++)
+        {
+            if (backlight_diffuse.mV[i] > max_component)
+            {
+                max_component = backlight_diffuse.mV[i];
+            }
+        }
+        F32 backlight_mag;
+        if (sun_up)
+        {
+            backlight_mag = BACKLIGHT_DAY_MAGNITUDE_OBJECT;
+        }
+        else
+        {
+            backlight_mag = BACKLIGHT_NIGHT_MAGNITUDE_OBJECT;
+        }
+        backlight_diffuse *= backlight_mag / max_component;
 
-	for (S32 i = 0; i < drawable->getNumFaces(); i++)
-	{
-		LLFace* facep = drawable->getFace(i);
-		if (facep)
-		{
-			facep->clearVertexBuffer();
-		}
-	}
-}
+        mHWLightColors[1] = backlight_diffuse;
 
-void LLPipeline::renderObjects(U32 type, bool texture, bool batch_texture, bool rigged)
-{
-	assertInitialized();
-	gGL.loadMatrix(gGLModelView);
-	gGLLastMatrix = NULL;
+        LLLightState* light = gGL.getLight(1);
 
-    if (rigged)
-    {
-        mSimplePool->pushRiggedBatches(type + 1, texture, batch_texture);
+        light->setPosition(backlight_pos);
+        light->setDiffuse(backlight_diffuse);
+        light->setAmbient(LLColor4::black);
+        light->setSpecular(LLColor4::black);
+        light->setConstantAttenuation(1.f);
+        light->setLinearAttenuation(0.f);
+        light->setQuadraticAttenuation(0.f);
+        light->setSpotExponent(0.f);
+        light->setSpotCutoff(180.f);
     }
     else
     {
-        mSimplePool->pushBatches(type, texture, batch_texture);
-    }
+        LLLightState* light = gGL.getLight(1);
 
-    gGL.loadMatrix(gGLModelView);
-	gGLLastMatrix = NULL;		
+        mHWLightColors[1] = LLColor4::black;
+
+        light->setDiffuse(LLColor4::black);
+        light->setAmbient(LLColor4::black);
+        light->setSpecular(LLColor4::black);
+    }
 }
 
-void LLPipeline::renderGLTFObjects(U32 type, bool texture, bool rigged)
+static F32 calc_light_dist(LLVOVolume* light, const LLVector3& cam_pos, F32 max_dist)
 {
-    assertInitialized();
-    gGL.loadMatrix(gGLModelView);
-    gGLLastMatrix = NULL;
-
-    if (rigged)
-    {
-        mSimplePool->pushRiggedGLTFBatches(type + 1, texture);
-    }
-    else
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
+    F32 inten = light->getLightIntensity();
+    if (inten < .001f)
     {
-        mSimplePool->pushGLTFBatches(type, texture);
+        return max_dist;
     }
-
-    gGL.loadMatrix(gGLModelView);
-    gGLLastMatrix = NULL;
-
-    if (!rigged)
+    bool selected = light->isSelected();
+    if (selected)
     {
-        LL::GLTFSceneManager::instance().renderOpaque();
+        return 0.f; // selected lights get highest priority
     }
-    else
+    F32 radius = light->getLightRadius();
+    F32 dist = dist_vec(light->getRenderPosition(), cam_pos);
+    dist = llmax(dist - radius, 0.f);
+    if (light->mDrawable.notNull() && light->mDrawable->isState(LLDrawable::ACTIVE))
     {
-        LL::GLTFSceneManager::instance().render(true, true);
+        // moving lights get a little higher priority (too much causes artifacts)
+        dist = llmax(dist - light->getLightRadius()*0.25f, 0.f);
     }
+    return dist;
 }
 
-// Currently only used for shadows -Cosmic,2023-04-19
-void LLPipeline::renderAlphaObjects(bool rigged)
+void LLPipeline::calcNearbyLights(LLCamera& camera)
 {
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
     assertInitialized();
-    gGL.loadMatrix(gGLModelView);
-    gGLLastMatrix = NULL;
-    S32 sun_up = LLEnvironment::instance().getIsSunUp() ? 1 : 0;
-    U32 target_width = LLRenderTarget::sCurResX;
-    U32 type = LLRenderPass::PASS_ALPHA;
-    LLVOAvatar* lastAvatar = nullptr;
-    U64 lastMeshId = 0;
-    auto* begin = gPipeline.beginRenderMap(type);
-    auto* end = gPipeline.endRenderMap(type);
 
-    for (LLCullResult::drawinfo_iterator i = begin; i != end; )
+    if (LLPipeline::sReflectionRender || gCubeSnapshot || LLPipeline::sRenderingHUDs)
     {
-        LLDrawInfo* pparams = *i;
-        LLCullResult::increment_iterator(i, end);
+        return;
+    }
 
-        if (rigged != (pparams->mAvatar != nullptr))
+    static LLCachedControl<S32> local_light_count(gSavedSettings, "RenderLocalLightCount", 256);
+
+    if (local_light_count >= 1)
+    {
+        // mNearbyLight (and all light_set_t's) are sorted such that
+        // begin() == the closest light and rbegin() == the farthest light
+        const S32 MAX_LOCAL_LIGHTS = 6;
+        LLVector3 cam_pos = camera.getOrigin();
+
+        F32 max_dist;
+        if (LLPipeline::sRenderDeferred)
         {
-            // Pool contains both rigged and non-rigged DrawInfos. Only draw
-            // the objects we're interested in in this pass.
-            continue;
+            max_dist = RenderFarClip;
+        }
+        else
+        {
+            max_dist = llmin(RenderFarClip, LIGHT_MAX_RADIUS * 4.f);
         }
 
-        if (rigged)
+        // UPDATE THE EXISTING NEARBY LIGHTS
+        light_set_t cur_nearby_lights;
+        for (const Light& light : mNearbyLights)
         {
-            if (pparams->mGLTFMaterial)
+            LLDrawable* drawable = light.drawable;
+            LLVOVolume* volight = drawable->getVOVolume();
+            if (!volight || !drawable->isState(LLDrawable::LIGHT))
             {
-                gDeferredShadowGLTFAlphaBlendProgram.bind(rigged);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
-                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
-                LLRenderPass::pushRiggedGLTFBatch(*pparams, lastAvatar, lastMeshId);
+                drawable->clearState(LLDrawable::NEARBY_LIGHT);
+                continue;
             }
-            else
+            if (light.fade <= -LIGHT_FADE_TIME)
             {
-                gDeferredShadowAlphaMaskProgram.bind(rigged);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
-                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
-                if (lastAvatar != pparams->mAvatar.get() || lastMeshId != pparams->mSkinInfo->mHash)
+                drawable->clearState(LLDrawable::NEARBY_LIGHT);
+                continue;
+            }
+            if (!sRenderAttachedLights && volight->isAttachment())
+            {
+                drawable->clearState(LLDrawable::NEARBY_LIGHT);
+                continue;
+            }
+            else if(volight->isAttachment())
+            {
+                LLVOAvatar* avatarp = volight->getAvatar();
+                if (avatarp && avatarp->isVisuallyMuted())
                 {
-                    mSimplePool->uploadMatrixPalette(*pparams);
-                    lastAvatar = pparams->mAvatar;
-                    lastMeshId = pparams->mSkinInfo->mHash;
+                    drawable->clearState(LLDrawable::NEARBY_LIGHT);
+                    continue;
                 }
+            }
 
-                mSimplePool->pushBatch(*pparams, true, true);
+            F32 dist = calc_light_dist(volight, cam_pos, max_dist);
+            F32 fade = light.fade;
+            // actual fade gets decreased/increased by setupHWLights
+            // light->fade value is 'time'.
+            // >=0 and light will become visible as value increases
+            // <0 and light will fade out
+            if (dist < max_dist)
+            {
+                if (fade < 0)
+                {
+                    // mark light to fade in
+                    // if fade was -LIGHT_FADE_TIME - it was fully invisible
+                    // if fade -0 - it was fully visible
+                    // visibility goes up from 0 to LIGHT_FADE_TIME.
+                    fade += LIGHT_FADE_TIME;
+                }
+            }
+            else
+            {
+                // mark light to fade out
+                // visibility goes down from -0 to -LIGHT_FADE_TIME.
+                if (fade >= LIGHT_FADE_TIME)
+                {
+                    fade = -0.0001f; // was fully visible
+                }
+                else if (fade >= 0)
+                {
+                    // 0.75 visible light should stay 0.75 visible, but should reverse direction
+                    fade -= LIGHT_FADE_TIME;
+                }
             }
+            cur_nearby_lights.emplace(drawable, dist, fade);
         }
-        else
+        mNearbyLights = std::move(cur_nearby_lights);
+
+        // FIND NEW LIGHTS THAT ARE IN RANGE
+        light_set_t new_nearby_lights;
+        for (LLDrawable::ordered_drawable_set_t::iterator iter = mLights.begin();
+             iter != mLights.end(); ++iter)
         {
-            if (pparams->mGLTFMaterial)
+            LLDrawable* drawable = *iter;
+            LLVOVolume* light = drawable->getVOVolume();
+            if (!light || drawable->isState(LLDrawable::NEARBY_LIGHT))
             {
-                gDeferredShadowGLTFAlphaBlendProgram.bind(rigged);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
-                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
-                LLRenderPass::pushGLTFBatch(*pparams);
+                continue;
             }
-            else
+            if (light->isHUDAttachment())
             {
-                gDeferredShadowAlphaMaskProgram.bind(rigged);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
-                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
-                mSimplePool->pushBatch(*pparams, true, true);
+                continue; // no lighting from HUD objects
+            }
+            if (!sRenderAttachedLights && light->isAttachment())
+            {
+                continue;
+            }
+            else if (light->isAttachment())
+            {
+                LLVOAvatar* av = light->getAvatar();
+                if (av && av->isVisuallyMuted())
+                {
+                    // avatars that are already in the list will be removed by removeMutedAVsLights
+                    continue;
+                }
+            }
+
+            F32 dist = calc_light_dist(light, cam_pos, max_dist);
+            if (dist >= max_dist)
+            {
+                continue;
+            }
+            new_nearby_lights.emplace(drawable, dist, 0.f);
+            if (!LLPipeline::sRenderDeferred && new_nearby_lights.size() > (U32)MAX_LOCAL_LIGHTS)
+            {
+                new_nearby_lights.erase(--new_nearby_lights.end());
+                const Light& last = *new_nearby_lights.rbegin();
+                max_dist = last.dist;
             }
         }
-    }
 
-    gGL.loadMatrix(gGLModelView);
-    gGLLastMatrix = NULL;
-}
+        // INSERT ANY NEW LIGHTS
+        for (const Light& light : new_nearby_lights)
+        {
+            if (LLPipeline::sRenderDeferred || mNearbyLights.size() < (U32)MAX_LOCAL_LIGHTS)
+            {
+                mNearbyLights.insert(light);
+                ((LLDrawable*) light.drawable)->setState(LLDrawable::NEARBY_LIGHT);
+            }
+            else
+            {
+                // crazy cast so that we can overwrite the fade value
+                // even though gcc enforces sets as const
+                // (fade value doesn't affect sort so this is safe)
+                Light* farthest_light = (const_cast<Light*>(&(*(mNearbyLights.rbegin()))));
+                if (light.dist < farthest_light->dist)
+                {
+                    // mark light to fade out
+                    // visibility goes down from -0 to -LIGHT_FADE_TIME.
+                    //
+                    // This is a mess, but for now it needs to be in sync
+                    // with fade code above. Ex: code above detects distance < max,
+                    // sets fade time to positive, this code then detects closer
+                    // lights and sets fade time negative, fully compensating
+                    // for the code above
+                    if (farthest_light->fade >= LIGHT_FADE_TIME)
+                    {
+                        farthest_light->fade = -0.0001f; // was fully visible
+                    }
+                    else if (farthest_light->fade >= 0)
+                    {
+                        farthest_light->fade -= LIGHT_FADE_TIME;
+                    }
+                }
+                else
+                {
+                    break; // none of the other lights are closer
+                }
+            }
+        }
 
-// Currently only used for shadows -Cosmic,2023-04-19
-void LLPipeline::renderMaskedObjects(U32 type, bool texture, bool batch_texture, bool rigged)
-{
-	assertInitialized();
-	gGL.loadMatrix(gGLModelView);
-	gGLLastMatrix = NULL;
-    if (rigged)
-    {
-        mAlphaMaskPool->pushRiggedMaskBatches(type+1, texture, batch_texture);
-    }
-    else
-    {
-        mAlphaMaskPool->pushMaskBatches(type, texture, batch_texture);
+        //mark nearby lights not-removable.
+        for (const Light& light : mNearbyLights)
+        {
+            ((LLViewerOctreeEntryData*) light.drawable)->setVisible();
+        }
     }
-	gGL.loadMatrix(gGLModelView);
-	gGLLastMatrix = NULL;		
 }
 
-// Currently only used for shadows -Cosmic,2023-04-19
-void LLPipeline::renderFullbrightMaskedObjects(U32 type, bool texture, bool batch_texture, bool rigged)
+void LLPipeline::setupHWLights()
 {
-	assertInitialized();
-	gGL.loadMatrix(gGLModelView);
-	gGLLastMatrix = NULL;
-    if (rigged)
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_DRAWPOOL;
+    assertInitialized();
+
+    if (LLPipeline::sRenderingHUDs)
     {
-        mFullbrightAlphaMaskPool->pushRiggedMaskBatches(type+1, texture, batch_texture);
+        return;
+    }
+
+    F32 light_scale = 1.f;
+
+    if (gCubeSnapshot)
+    { //darken local lights when probe ambiance is above 1
+        light_scale = mReflectionMapManager.mLightScale;
     }
     else
     {
-        mFullbrightAlphaMaskPool->pushMaskBatches(type, texture, batch_texture);
+        static LLCachedControl<F32> alchemy_light_scale(gSavedSettings, "AlchemyGlobalLightScale", 1.f);
+        light_scale = alchemy_light_scale;
     }
-	gGL.loadMatrix(gGLModelView);
-	gGLLastMatrix = NULL;		
-}
-
-void validate_framebuffer_object()
-{                                                           
-	GLenum status;                                            
-	status = glCheckFramebufferStatus(GL_FRAMEBUFFER); 
-	switch(status) 
-	{                                          
-		case GL_FRAMEBUFFER_COMPLETE:                       
-			//framebuffer OK, no error.
-			break;
-		case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
-			// frame buffer not OK: probably means unsupported depth buffer format
-			LL_ERRS() << "Framebuffer Incomplete Missing Attachment." << LL_ENDL;
-			break;
-		case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
-			// frame buffer not OK: probably means unsupported depth buffer format
-			LL_ERRS() << "Framebuffer Incomplete Attachment." << LL_ENDL;
-			break; 
-		case GL_FRAMEBUFFER_UNSUPPORTED:                    
-			/* choose different formats */                        
-			LL_ERRS() << "Framebuffer unsupported." << LL_ENDL;
-			break;                                                
-		default:                                                
-			LL_ERRS() << "Unknown framebuffer status." << LL_ENDL;
-			break;
-	}
-}
-
-void LLPipeline::bindScreenToTexture() 
-{
-	
-}
-
-static LLTrace::BlockTimerStatHandle FTM_RENDER_BLOOM("Bloom");
 
-void LLPipeline::visualizeBuffers(LLRenderTarget* src, LLRenderTarget* dst, U32 bufferIndex)
-{
-	dst->bindTarget();
-	gDeferredBufferVisualProgram.bind();
-	gDeferredBufferVisualProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_BILINEAR, bufferIndex);
 
-	static LLStaticHashedString mipLevel("mipLevel");
-	if (RenderBufferVisualization != 4)
-		gDeferredBufferVisualProgram.uniform1f(mipLevel, 0);
-	else
-		gDeferredBufferVisualProgram.uniform1f(mipLevel, 8);
+    LLEnvironment& environment = LLEnvironment::instance();
+    const LLSettingsSky::ptr_t& psky = environment.getCurrentSky();
 
-	mScreenTriangleVB->setBuffer();
-	mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-	gDeferredBufferVisualProgram.unbind();
-	dst->flush();
-}
+    // Ambient
+    LLColor4 ambient = psky->getTotalAmbient();
 
-void LLPipeline::generateLuminance(LLRenderTarget* src, LLRenderTarget* dst)
-{
-	// luminance sample and mipmap generation
-	{
-		LL_PROFILE_GPU_ZONE("luminance sample");
+    gGL.setAmbientLightColor(ambient);
 
-		dst->bindTarget();
+    bool sun_up  = environment.getIsSunUp();
+    bool moon_up = environment.getIsMoonUp();
 
-		LLGLDepthTest depth(GL_FALSE, GL_FALSE);
+    // Light 0 = Sun or Moon (All objects)
+    {
+        LLVector4 sun_dir(environment.getSunDirection(), 0.0f);
+        LLVector4 moon_dir(environment.getMoonDirection(), 0.0f);
 
-		gLuminanceProgram.bind();
+        mSunDir.setVec(sun_dir);
+        mMoonDir.setVec(moon_dir);
 
-        static LLCachedControl<F32> diffuse_luminance_scale(gSavedSettings, "RenderDiffuseLuminanceScale", 1.0f);
+        mSunDiffuse.setVec(psky->getSunlightColor());
+        mMoonDiffuse.setVec(psky->getMoonlightColor());
 
-		S32 channel = 0;
-		channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE);
-		if (channel > -1)
-		{
-			src->bindTexture(0, channel, LLTexUnit::TFO_POINT);
-		}
+        F32 max_color = llmax(mSunDiffuse.mV[0], mSunDiffuse.mV[1], mSunDiffuse.mV[2]);
+        if (max_color > 1.f)
+        {
+            mSunDiffuse *= 1.f/max_color;
+        }
+        mSunDiffuse.clamp();
 
-		channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE);
-		if (channel > -1)
-		{
-			mGlow[1].bindTexture(0, channel);
-		}
+        max_color = llmax(mMoonDiffuse.mV[0], mMoonDiffuse.mV[1], mMoonDiffuse.mV[2]);
+        if (max_color > 1.f)
+        {
+            mMoonDiffuse *= 1.f/max_color;
+        }
+        mMoonDiffuse.clamp();
 
-        channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_NORMAL);
-        if (channel > -1)
+        // prevent underlighting from having neither lightsource facing us
+        if (!sun_up && !moon_up)
         {
-            // bind the normal map to get the environment mask
-            mRT->deferredScreen.bindTexture(2, channel, LLTexUnit::TFO_POINT);
+            mSunDiffuse.setVec(LLColor4(0.0, 0.0, 0.0, 1.0));
+            mMoonDiffuse.setVec(LLColor4(0.0, 0.0, 0.0, 1.0));
+            mSunDir.setVec(LLVector4(0.0, 1.0, 0.0, 0.0));
+            mMoonDir.setVec(LLVector4(0.0, 1.0, 0.0, 0.0));
         }
 
-        static LLStaticHashedString diffuse_luminance_scale_s("diffuse_luminance_scale");
-        gLuminanceProgram.uniform1f(diffuse_luminance_scale_s, diffuse_luminance_scale);
+        LLVector4 light_dir = sun_up ? mSunDir : mMoonDir;
 
-		mScreenTriangleVB->setBuffer();
-		mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-		dst->flush();
+        mHWLightColors[0] = sun_up ? mSunDiffuse : mMoonDiffuse;
 
-		// note -- unbind AFTER the glGenerateMipMap so time in generatemipmap can be profiled under "Luminance"
-		// also note -- keep an eye on the performance of glGenerateMipmap, might need to replace it with a mip generation shader
-		gLuminanceProgram.unbind();
-	}
-}
+        LLLightState* light = gGL.getLight(0);
+        light->setPosition(light_dir);
 
-void LLPipeline::generateExposure(LLRenderTarget* src, LLRenderTarget* dst, bool use_history) {
-	// exposure sample
-	{
-		LL_PROFILE_GPU_ZONE("exposure sample");
-
-		if (use_history)
-		{
-			// copy last frame's exposure into mLastExposure
-			mLastExposure.bindTarget();
-			gCopyProgram.bind();
-			gGL.getTexUnit(0)->bind(dst);
-
-			mScreenTriangleVB->setBuffer();
-			mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-
-			mLastExposure.flush();
-		}
-
-		dst->bindTarget();
-
-		LLGLDepthTest depth(GL_FALSE, GL_FALSE);
-
-		LLGLSLShader* shader;
-		if (use_history)
-		{
-			shader = &gExposureProgram;
-		}
-		else
-		{
-			shader = &gExposureProgramNoFade;
-		}
-
-		shader->bind();
-
-		S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_EMISSIVE);
-		if (channel > -1)
-		{
-			src->bindTexture(0, channel, LLTexUnit::TFO_TRILINEAR);
-		}
-
-		if (use_history)
-		{
-			channel = shader->enableTexture(LLShaderMgr::EXPOSURE_MAP);
-			if (channel > -1)
-			{
-				mLastExposure.bindTexture(0, channel);
-			}
-		}
-
-		static LLStaticHashedString dt("dt");
-		static LLStaticHashedString noiseVec("noiseVec");
-		static LLStaticHashedString dynamic_exposure_params("dynamic_exposure_params");
-		static LLCachedControl<F32> dynamic_exposure_coefficient(gSavedSettings, "RenderDynamicExposureCoefficient", 0.175f);
-		static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
-
-		LLSettingsSky::ptr_t sky = LLEnvironment::instance().getCurrentSky();
-
-		F32 probe_ambiance = LLEnvironment::instance().getCurrentSky()->getReflectionProbeAmbiance(should_auto_adjust);
-		F32 exp_min = 1.f;
-		F32 exp_max = 1.f;
-
-		if (probe_ambiance > 0.f)
-		{
-			F32 hdr_scale = sqrtf(LLEnvironment::instance().getCurrentSky()->getGamma()) * 2.f;
-
-			if (hdr_scale > 1.f)
-			{
-				exp_min = 1.f / hdr_scale;
-				exp_max = hdr_scale;
-			}
-		}
-		shader->uniform1f(dt, gFrameIntervalSeconds);
-		shader->uniform2f(noiseVec, ll_frand() * 2.0 - 1.0, ll_frand() * 2.0 - 1.0);
-		shader->uniform3f(dynamic_exposure_params, dynamic_exposure_coefficient, exp_min, exp_max);
-
-		mScreenTriangleVB->setBuffer();
-		mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-
-		if (use_history)
-		{
-			gGL.getTexUnit(channel)->unbind(mLastExposure.getUsage());
-		}
-		shader->unbind();
-		dst->flush();
-	}
-}
+        light->setSunPrimary(sun_up);
+        light->setDiffuse(mHWLightColors[0]);
+        light->setDiffuseB(mMoonDiffuse);
+        light->setAmbient(psky->getTotalAmbient());
+        light->setSpecular(LLColor4::black);
+        light->setConstantAttenuation(1.f);
+        light->setLinearAttenuation(0.f);
+        light->setQuadraticAttenuation(0.f);
+        light->setSpotExponent(0.f);
+        light->setSpotCutoff(180.f);
+    }
 
-extern LLPointer<LLImageGL> gEXRImage;
+    // Light 1 = Backlight (for avatars)
+    // (set by enableLightsAvatar)
 
-void LLPipeline::gammaCorrect(LLRenderTarget* src, LLRenderTarget* dst) {
-	dst->bindTarget();
-	// gamma correct lighting
-	{
-		LL_PROFILE_GPU_ZONE("gamma correct");
+    S32 cur_light = 2;
 
-        static LLCachedControl<bool> buildNoPost(gSavedSettings, "RenderDisablePostProcessing", false);
+    // Nearby lights = LIGHT 2-7
 
-		LLGLDepthTest depth(GL_FALSE, GL_FALSE);
+    mLightMovingMask = 0;
 
-		// Apply gamma correction to the frame here.
+    static LLCachedControl<S32> local_light_count(gSavedSettings, "RenderLocalLightCount", 256);
 
-        static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
-        
-        LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
+    if (local_light_count >= 1)
+    {
+        for (light_set_t::iterator iter = mNearbyLights.begin();
+             iter != mNearbyLights.end(); ++iter)
+        {
+            LLDrawable* drawable = iter->drawable;
+            LLVOVolume* light = drawable->getVOVolume();
+            if (!light)
+            {
+                continue;
+            }
 
-        bool no_post = gSnapshotNoPost || (buildNoPost && gFloaterTools->isAvailable());
-        LLGLSLShader& shader = no_post ? gNoPostGammaCorrectProgram : // no post (no gamma, no exposure, no tonemapping)
-            psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f ? gLegacyPostGammaCorrectProgram :
-            gDeferredPostGammaCorrectProgram;
-        
-        shader.bind();
+            if (light->isAttachment())
+            {
+                if (!sRenderAttachedLights)
+                {
+                    continue;
+                }
+            }
 
-		S32 channel = 0;
+            if (drawable->isState(LLDrawable::ACTIVE))
+            {
+                mLightMovingMask |= (1<<cur_light);
+            }
 
-        shader.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
+            //send linear light color to shader
+            LLColor4  light_color = light->getLightLinearColor() * light_scale;
+            light_color.mV[3] = 0.0f;
 
-        shader.bindTexture(LLShaderMgr::EXPOSURE_MAP, &mExposureMap);
+            F32 fade = iter->fade;
+            if (fade < LIGHT_FADE_TIME)
+            {
+                // fade in/out light
+                if (fade >= 0.f)
+                {
+                    fade = fade / LIGHT_FADE_TIME;
+                    ((Light*) (&(*iter)))->fade += gFrameIntervalSeconds.value();
+                }
+                else
+                {
+                    fade = 1.f + fade / LIGHT_FADE_TIME;
+                    ((Light*) (&(*iter)))->fade -= gFrameIntervalSeconds.value();
+                }
+                fade = llclamp(fade,0.f,1.f);
+                light_color *= fade;
+            }
 
-        shader.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, src->getWidth(), src->getHeight());
+            if (light_color.magVecSquared() < 0.001f)
+            {
+                continue;
+            }
 
-		static LLCachedControl<F32> exposure(gSavedSettings, "RenderExposure", 1.f);
+            LLVector3 light_pos(light->getRenderPosition());
+            LLVector4 light_pos_gl(light_pos, 1.0f);
 
-		F32 e = llclamp(exposure(), 0.5f, 4.f);
+            F32 adjusted_radius = light->getLightRadius() * (sRenderDeferred ? 1.5f : 1.0f);
+            if (adjusted_radius <= 0.001f)
+            {
+                continue;
+            }
 
-		static LLStaticHashedString s_exposure("exposure");
-        static LLStaticHashedString aces_mix("aces_mix");
+            F32 x = (3.f * (1.f + (light->getLightFalloff() * 2.0f)));  // why this magic?  probably trying to match a historic behavior.
+            F32 linatten = x / adjusted_radius;                         // % of brightness at radius
 
-        shader.uniform1f(s_exposure, e);
-        shader.uniform1f(aces_mix, gEXRImage.notNull() ? 0.f : 0.3f);
+            mHWLightColors[cur_light] = light_color;
+            LLLightState* light_state = gGL.getLight(cur_light);
 
-		mScreenTriangleVB->setBuffer();
-		mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+            light_state->setPosition(light_pos_gl);
+            light_state->setDiffuse(light_color);
+            light_state->setAmbient(LLColor4::black);
+            light_state->setConstantAttenuation(0.f);
+            light_state->setSize(light->getLightRadius() * 1.5f);
+            light_state->setFalloff(light->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
 
-		gGL.getTexUnit(channel)->unbind(src->getUsage());
-        shader.unbind();
-	}
-	dst->flush();
-}
+            if (sRenderDeferred)
+            {
+                light_state->setLinearAttenuation(linatten);
+                light_state->setQuadraticAttenuation(light->getLightFalloff(DEFERRED_LIGHT_FALLOFF) + 1.f); // get falloff to match for forward deferred rendering lights
+            }
+            else
+            {
+                light_state->setLinearAttenuation(linatten);
+                light_state->setQuadraticAttenuation(0.f);
+            }
 
-void LLPipeline::copyScreenSpaceReflections(LLRenderTarget* src, LLRenderTarget* dst) 
-{
 
-	if (RenderScreenSpaceReflections && !gCubeSnapshot)
-	{
-		LL_PROFILE_GPU_ZONE("ssr copy");
-		LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
+            if (light->isLightSpotlight() // directional (spot-)light
+                && (LLPipeline::sRenderDeferred || RenderSpotLightsInNondeferred)) // these are only rendered as GL spotlights if we're in deferred rendering mode *or* the setting forces them on
+            {
+                LLQuaternion quat = light->getRenderRotation();
+                LLVector3 at_axis(0,0,-1); // this matches deferred rendering's object light direction
+                at_axis *= quat;
 
-		LLRenderTarget& depth_src = mRT->deferredScreen;
+                light_state->setSpotDirection(at_axis);
+                light_state->setSpotCutoff(90.f);
+                light_state->setSpotExponent(2.f);
 
-		dst->bindTarget();
-		dst->clear();
-		gCopyDepthProgram.bind();
+                LLVector3 spotParams = light->getSpotLightParams();
 
-		S32 diff_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
-		S32 depth_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
+                const LLColor4 specular(0.f, 0.f, 0.f, spotParams[2]);
+                light_state->setSpecular(specular);
+            }
+            else // omnidirectional (point) light
+            {
+                light_state->setSpotExponent(0.f);
+                light_state->setSpotCutoff(180.f);
 
-		gGL.getTexUnit(diff_map)->bind(src);
-		gGL.getTexUnit(depth_map)->bind(&depth_src, true);
+                // we use specular.z = 1.0 as a cheap hack for the shaders to know that this is omnidirectional rather than a spotlight
+                const LLColor4 specular(0.f, 0.f, 1.f, 0.f);
+                light_state->setSpecular(specular);
+            }
+            cur_light++;
+            if (cur_light >= 8)
+            {
+                break; // safety
+            }
+        }
+    }
+    for ( ; cur_light < 8 ; cur_light++)
+    {
+        mHWLightColors[cur_light] = LLColor4::black;
+        LLLightState* light = gGL.getLight(cur_light);
+        light->setSunPrimary(true);
+        light->setDiffuse(LLColor4::black);
+        light->setAmbient(LLColor4::black);
+        light->setSpecular(LLColor4::black);
+    }
 
-		mScreenTriangleVB->setBuffer();
-		mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    // Bookmark comment to allow searching for mSpecialRenderMode == 3 (avatar edit mode),
+    // prev site of forward (non-deferred) character light injection, removed by SL-13522 09/20
 
-		dst->flush();
-	}
+    // Init GL state
+    for (S32 i = 0; i < 8; ++i)
+    {
+        gGL.getLight(i)->disable();
+    }
+    mLightMask = 0;
 }
 
-void LLPipeline::generateGlow(LLRenderTarget* src) 
+void LLPipeline::enableLights(U32 mask)
 {
-	if (sRenderGlow)
-	{
-		LL_PROFILE_GPU_ZONE("glow");
-		mGlow[2].bindTarget();
-		mGlow[2].clear();
-
-		gGlowExtractProgram.bind();
-		F32 maxAlpha = RenderGlowMaxExtractAlpha;
-		F32 warmthAmount = RenderGlowWarmthAmount;
-		LLVector3 lumWeights = RenderGlowLumWeights;
-		LLVector3 warmthWeights = RenderGlowWarmthWeights;
-
-		gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_MIN_LUMINANCE, 9999);
-		gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_MAX_EXTRACT_ALPHA, maxAlpha);
-		gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_LUM_WEIGHTS, lumWeights.mV[0], lumWeights.mV[1],
-			lumWeights.mV[2]);
-		gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_WARMTH_WEIGHTS, warmthWeights.mV[0], warmthWeights.mV[1],
-			warmthWeights.mV[2]);
-		gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_WARMTH_AMOUNT, warmthAmount);
+    assertInitialized();
 
-        if (RenderGlowNoise)
+    if (mLightMask != mask)
+    {
+        stop_glerror();
+        if (mask)
         {
-            S32 channel = gGlowExtractProgram.enableTexture(LLShaderMgr::GLOW_NOISE_MAP);
-            if (channel > -1)
+            stop_glerror();
+            for (S32 i=0; i<8; i++)
             {
-                gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mTrueNoiseMap);
-                gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
+                LLLightState* light = gGL.getLight(i);
+                if (mask & (1<<i))
+                {
+                    light->enable();
+                    light->setDiffuse(mHWLightColors[i]);
+                }
+                else
+                {
+                    light->disable();
+                    light->setDiffuse(LLColor4::black);
+                }
             }
-            gGlowExtractProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
-                                          mGlow[2].getWidth(),
-                                          mGlow[2].getHeight());
+            stop_glerror();
         }
+        mLightMask = mask;
+        stop_glerror();
+    }
+}
 
-		{
-			LLGLEnable blend_on(GL_BLEND);
-
-			gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
-
-			gGlowExtractProgram.bindTexture(LLShaderMgr::DIFFUSE_MAP, src);
-
-			gGL.color4f(1, 1, 1, 1);
-			gPipeline.enableLightsFullbright();
-
-			mScreenTriangleVB->setBuffer();
-			mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-
-			mGlow[2].flush();
-			gGL.setSceneBlendType(LLRender::BT_ALPHA);
-		}
+void LLPipeline::enableLightsDynamic()
+{
+    assertInitialized();
+    U32 mask = 0xff & (~2); // Local lights
+    enableLights(mask);
 
-		gGlowExtractProgram.unbind();
+    if (isAgentAvatarValid())
+    {
+        if (gAgentAvatarp->mSpecialRenderMode == 0) // normal
+        {
+            gPipeline.enableLightsAvatar();
+        }
+        else if (gAgentAvatarp->mSpecialRenderMode == 2)  // anim preview
+        {
+            gPipeline.enableLightsAvatarEdit(LLColor4(0.7f, 0.6f, 0.3f, 1.f));
+        }
+    }
+}
 
-		// power of two between 1 and 1024
-		U32 glowResPow = RenderGlowResolutionPow;
-		const U32 glow_res = llmax(1, llmin(1024, 1 << glowResPow));
-
-		S32 kernel = RenderGlowIterations * 2;
-		F32 delta = RenderGlowWidth / glow_res;
-		// Use half the glow width if we have the res set to less than 9 so that it looks
-		// almost the same in either case.
-		if (glowResPow < 9)
-		{
-			delta *= 0.5f;
-		}
-		F32 strength = RenderGlowStrength;
-
-		gGlowProgram.bind();
-		gGlowProgram.uniform1f(LLShaderMgr::GLOW_STRENGTH, strength);
-
-		for (S32 i = 0; i < kernel; i++)
-		{
-			mGlow[i % 2].bindTarget();
-			mGlow[i % 2].clear();
-
-			if (i == 0)
-			{
-				gGlowProgram.bindTexture(LLShaderMgr::DIFFUSE_MAP, &mGlow[2]);
-			}
-			else
-			{
-				gGlowProgram.bindTexture(LLShaderMgr::DIFFUSE_MAP, &mGlow[(i - 1) % 2]);
-			}
-
-			if (i % 2 == 0)
-			{
-				gGlowProgram.uniform2f(LLShaderMgr::GLOW_DELTA, delta, 0);
-			}
-			else
-			{
-				gGlowProgram.uniform2f(LLShaderMgr::GLOW_DELTA, 0, delta);
-			}
-
-			mScreenTriangleVB->setBuffer();
-			mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-
-			mGlow[i % 2].flush();
-		}
-
-		gGlowProgram.unbind();
-
-	}
-	else // !sRenderGlow, skip the glow ping-pong and just clear the result target
-	{
-		mGlow[1].bindTarget();
-		mGlow[1].clear();
-		mGlow[1].flush();
-	}
-}
-
-void LLPipeline::applyFXAA(LLRenderTarget* src, LLRenderTarget* dst) 
-{
-	{
-		llassert(!gCubeSnapshot);
-		bool multisample = RenderFSAASamples > 1 && mPostHelperMap.isComplete();
-		LLGLSLShader* shader = &gGlowCombineProgram;
-
-		S32 width = dst->getWidth();
-		S32 height = dst->getHeight();
-
-		// Present everything.
-		if (multisample)
-		{
-			LL_PROFILE_GPU_ZONE("aa");
-			// bake out texture2D with RGBL for FXAA shader
-			mPostHelperMap.bindTarget();
-
-			shader = &gGlowCombineFXAAProgram;
-			shader->bind();
-
-			S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, src->getUsage());
-			if (channel > -1)
-			{
-				src->bindTexture(0, channel, LLTexUnit::TFO_BILINEAR);
-			}
-
-			{
-				LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
-				mScreenTriangleVB->setBuffer();
-				mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-			}
-
-			shader->disableTexture(LLShaderMgr::DEFERRED_DIFFUSE, src->getUsage());
-			shader->unbind();
-
-			mPostHelperMap.flush();
-
-			dst->bindTarget();
-
-			U32 fsaa_quality = 0;
-			switch (RenderFSAASamples)
-			{
-			case 2:
-				fsaa_quality = 0;
-				break;
-			case 4:
-				fsaa_quality = 1;
-				break;
-			default:
-			case 8:
-				fsaa_quality = 2;
-				break;
-			case 16:
-				fsaa_quality = 3;
-				break;
-			}
-			shader = &gFXAAProgram[fsaa_quality];
-			shader->bind();
-
-			channel = shader->enableTexture(LLShaderMgr::DIFFUSE_MAP, mPostHelperMap.getUsage());
-			if (channel > -1)
-			{
-				mPostHelperMap.bindTexture(0, channel, LLTexUnit::TFO_BILINEAR);
-			}
-
-			F32 scale_x = (F32)width / mPostHelperMap.getWidth();
-			F32 scale_y = (F32)height / mPostHelperMap.getHeight();
-			shader->uniform2f(LLShaderMgr::FXAA_TC_SCALE, scale_x, scale_y);
-			shader->uniform2f(LLShaderMgr::FXAA_RCP_SCREEN_RES, 1.f / width * scale_x, 1.f / height * scale_y);
-			shader->uniform4f(LLShaderMgr::FXAA_RCP_FRAME_OPT, -0.5f / width * scale_x, -0.5f / height * scale_y,
-				0.5f / width * scale_x, 0.5f / height * scale_y);
-			shader->uniform4f(LLShaderMgr::FXAA_RCP_FRAME_OPT2, -2.f / width * scale_x, -2.f / height * scale_y,
-				2.f / width * scale_x, 2.f / height * scale_y);
-
-			{
-				LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
-				S32 depth_channel = shader->getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
-				gGL.getTexUnit(depth_channel)->bind(&mRT->deferredScreen, true);
-
-				mScreenTriangleVB->setBuffer();
-				mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-			}
-
-			shader->unbind();
-			dst->flush();
-		}
-		else {
-			copyRenderTarget(src, dst);
-		}
-	}
+void LLPipeline::enableLightsAvatar()
+{
+    U32 mask = 0xff; // All lights
+    setupAvatarLights(FALSE);
+    enableLights(mask);
 }
 
-void LLPipeline::copyRenderTarget(LLRenderTarget* src, LLRenderTarget* dst)
+void LLPipeline::enableLightsPreview()
 {
+    disableLights();
 
-	LL_PROFILE_GPU_ZONE("copyRenderTarget");
-	dst->bindTarget();
+    LLColor4 ambient = PreviewAmbientColor;
+    gGL.setAmbientLightColor(ambient);
 
-	gDeferredPostNoDoFProgram.bind();
+    LLColor4 diffuse0 = PreviewDiffuse0;
+    LLColor4 specular0 = PreviewSpecular0;
+    LLColor4 diffuse1 = PreviewDiffuse1;
+    LLColor4 specular1 = PreviewSpecular1;
+    LLColor4 diffuse2 = PreviewDiffuse2;
+    LLColor4 specular2 = PreviewSpecular2;
 
-	gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src);
-	gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, &mRT->deferredScreen, true);
+    LLVector3 dir0 = PreviewDirection0;
+    LLVector3 dir1 = PreviewDirection1;
+    LLVector3 dir2 = PreviewDirection2;
 
-	{
-		mScreenTriangleVB->setBuffer();
-		mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-	}
+    dir0.normVec();
+    dir1.normVec();
+    dir2.normVec();
 
-	gDeferredPostNoDoFProgram.unbind();
+    LLVector4 light_pos(dir0, 0.0f);
 
-	dst->flush();
-}
+    LLLightState* light = gGL.getLight(1);
 
-void LLPipeline::combineGlow(LLRenderTarget* src, LLRenderTarget* dst)
-{
-	// Go ahead and do our glow combine here in our destination.  We blit this later into the front buffer.
+    light->enable();
+    light->setPosition(light_pos);
+    light->setDiffuse(diffuse0);
+    light->setAmbient(ambient);
+    light->setSpecular(specular0);
+    light->setSpotExponent(0.f);
+    light->setSpotCutoff(180.f);
 
-	dst->bindTarget();
+    light_pos = LLVector4(dir1, 0.f);
 
-	{
+    light = gGL.getLight(2);
+    light->enable();
+    light->setPosition(light_pos);
+    light->setDiffuse(diffuse1);
+    light->setAmbient(ambient);
+    light->setSpecular(specular1);
+    light->setSpotExponent(0.f);
+    light->setSpotCutoff(180.f);
 
-		gGlowCombineProgram.bind();
+    light_pos = LLVector4(dir2, 0.f);
+    light = gGL.getLight(3);
+    light->enable();
+    light->setPosition(light_pos);
+    light->setDiffuse(diffuse2);
+    light->setAmbient(ambient);
+    light->setSpecular(specular2);
+    light->setSpotExponent(0.f);
+    light->setSpotCutoff(180.f);
+}
 
-		gGlowCombineProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src);
-		gGlowCombineProgram.bindTexture(LLShaderMgr::DEFERRED_EMISSIVE, &mGlow[1]);
 
-		mScreenTriangleVB->setBuffer();
-		mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-	}
+void LLPipeline::enableLightsAvatarEdit(const LLColor4& color)
+{
+    U32 mask = 0x2002; // Avatar backlight only, set ambient
+    setupAvatarLights(TRUE);
+    enableLights(mask);
 
-	dst->flush();
+    gGL.setAmbientLightColor(color);
 }
 
-void LLPipeline::renderDoF(LLRenderTarget* src, LLRenderTarget* dst)
+void LLPipeline::enableLightsFullbright()
 {
-	{
-		bool dof_enabled =
-			(RenderDepthOfFieldInEditMode || !LLToolMgr::getInstance()->inBuildMode()) &&
-			RenderDepthOfField &&
-			!gCubeSnapshot;
-
-		gViewerWindow->setup3DViewport();
-
-		if (dof_enabled)
-		{
-			LL_PROFILE_GPU_ZONE("dof");
-			LLGLDisable blend(GL_BLEND);
-
-			// depth of field focal plane calculations
-			static F32 current_distance = 16.f;
-			static F32 start_distance = 16.f;
-			static F32 transition_time = 1.f;
-
-			LLVector3 focus_point;
-			static LLVector3 last_focus_point{};
-			if (LLPipeline::RenderFocusPointLocked && !last_focus_point.isExactlyZero())
-			{
-				focus_point = last_focus_point;
-			}
-			else
-			{
-				LLViewerObject* obj = LLViewerMediaFocus::getInstance()->getFocusedObject();
-				if (obj && obj->mDrawable && obj->isSelected())
-				{ // focus on selected media object
-					S32 face_idx = LLViewerMediaFocus::getInstance()->getFocusedFace();
-					if (obj && obj->mDrawable)
-					{
-						LLFace* face = obj->mDrawable->getFace(face_idx);
-						if (face)
-						{
-							focus_point = face->getPositionAgent();
-						}
-					}
-				}
-
-				if (focus_point.isExactlyZero())
-				{
-					if (LLViewerJoystick::getInstance()->getOverrideCamera() || LLPipeline::RenderFocusPointFollowsPointer)
-					{ // focus on point under cursor
-						focus_point.set(gDebugRaycastIntersection.getF32ptr());
-					}
-					else if (gAgentCamera.cameraMouselook())
-					{ // focus on point under mouselook crosshairs
-						LLVector4a result;
-						result.clear();
-
-						gViewerWindow->cursorIntersect(-1, -1, 512.f, NULL, -1, FALSE, FALSE, TRUE, TRUE, nullptr, nullptr, nullptr, &result);
-
-						focus_point.set(result.getF32ptr());
-					}
-					else
-					{
-						// focus on alt-zoom target
-						LLViewerRegion* region = gAgent.getRegion();
-						if (region)
-						{
-							focus_point = LLVector3(gAgentCamera.getFocusGlobal() - region->getOriginGlobal());
-						}
-					}
-				}
-			}
-			last_focus_point = focus_point;
-
-			LLVector3 eye = LLViewerCamera::getInstance()->getOrigin();
-			F32 target_distance = 16.f;
-			if (!focus_point.isExactlyZero())
-			{
-				target_distance = LLViewerCamera::getInstance()->getAtAxis() * (focus_point - eye);
-			}
-
-			if (transition_time >= 1.f && fabsf(current_distance - target_distance) / current_distance > 0.01f)
-			{ // large shift happened, interpolate smoothly to new target distance
-				transition_time = 0.f;
-				start_distance = current_distance;
-			}
-			else if (transition_time < 1.f)
-			{ // currently in a transition, continue interpolating
-				transition_time += 1.f / CameraFocusTransitionTime * gFrameIntervalSeconds.value();
-				transition_time = llmin(transition_time, 1.f);
-
-				F32 t = cosf(transition_time * F_PI + F_PI) * 0.5f + 0.5f;
-				current_distance = start_distance + (target_distance - start_distance) * t;
-			}
-			else
-			{ // small or no change, just snap to target distance
-				current_distance = target_distance;
-			}
-
-			// convert to mm
-			F32 subject_distance = current_distance * 1000.f;
-			F32 fnumber = CameraFNumber;
-			F32 default_focal_length = CameraFocalLength;
-
-			F32 fov = LLViewerCamera::getInstance()->getView();
-
-			const F32 default_fov = CameraFieldOfView * F_PI / 180.f;
-
-			// F32 aspect_ratio = (F32) mRT->screen.getWidth()/(F32)mRT->screen.getHeight();
-
-			F32 dv = 2.f * default_focal_length * tanf(default_fov / 2.f);
-
-			F32 focal_length = dv / (2 * tanf(fov / 2.f));
-
-			// F32 tan_pixel_angle = tanf(LLDrawable::sCurPixelAngle);
-
-			// from wikipedia -- c = |s2-s1|/s2 * f^2/(N(S1-f))
-			// where	 N = fnumber
-			//			 s2 = dot distance
-			//			 s1 = subject distance
-			//			 f = focal length
-			//
-
-			F32 blur_constant = focal_length * focal_length / (fnumber * (subject_distance - focal_length));
-			blur_constant /= 1000.f; // convert to meters for shader
-			F32 magnification = focal_length / (subject_distance - focal_length);
-
-			{ // build diffuse+bloom+CoF
-				mPostHelperMap.bindTarget();
-
-				gDeferredCoFProgram.bind();
-
-				gDeferredCoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, LLTexUnit::TFO_POINT);
-				gDeferredCoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, &mRT->deferredScreen, true);
-
-				gDeferredCoFProgram.uniform1f(LLShaderMgr::DEFERRED_DEPTH_CUTOFF, RenderEdgeDepthCutoff);
-				gDeferredCoFProgram.uniform1f(LLShaderMgr::DEFERRED_NORM_CUTOFF, RenderEdgeNormCutoff);
-				gDeferredCoFProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, dst->getWidth(), dst->getHeight());
-				gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_FOCAL_DISTANCE, -subject_distance / 1000.f);
-				gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_BLUR_CONSTANT, blur_constant);
-				gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_TAN_PIXEL_ANGLE, tanf(1.f / LLDrawable::sCurPixelAngle));
-				gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_MAGNIFICATION, magnification);
-				gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
-				gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
-
-				mScreenTriangleVB->setBuffer();
-				mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-				gDeferredCoFProgram.unbind();
-				mPostHelperMap.flush();
-			}
-
-			U32 dof_width = (U32)(mRT->screen.getWidth() * CameraDoFResScale);
-			U32 dof_height = (U32)(mRT->screen.getHeight() * CameraDoFResScale);
-
-			{ // perform DoF sampling at half-res (preserve alpha channel)
-				src->bindTarget();
-				glViewport(0, 0, dof_width, dof_height);
-
-				gGL.setColorMask(true, false);
-
-				LLGLSLShader& post_program = RenderDepthOfFieldNearBlur ? gDeferredPostProgram : gDeferredPostProgramNoNear;
-
-				post_program.bind();
-				post_program.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, &mPostHelperMap, LLTexUnit::TFO_POINT);
-
-				post_program.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, dst->getWidth(), dst->getHeight());
-				post_program.uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
-				post_program.uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
+    assertInitialized();
+    U32 mask = 0x1000; // Non-0 mask, set ambient
+    enableLights(mask);
+}
 
-				mScreenTriangleVB->setBuffer();
-				mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+void LLPipeline::disableLights()
+{
+    enableLights(0); // no lighting (full bright)
+}
 
-				post_program.unbind();
+//============================================================================
 
-				src->flush();
-				gGL.setColorMask(true, true);
-			}
+class LLMenuItemGL;
+class LLInvFVBridge;
+struct cat_folder_pair;
+class LLVOBranch;
+class LLVOLeaf;
 
-			{ // combine result based on alpha
-				
-				dst->bindTarget();
-
-				glViewport(0, 0, dst->getWidth(), dst->getHeight());
-
-				gDeferredDoFCombineProgram.bind();	
-				gDeferredDoFCombineProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, LLTexUnit::TFO_POINT);
-				gDeferredDoFCombineProgram.bindTexture(LLShaderMgr::DEFERRED_LIGHT, &mPostHelperMap, LLTexUnit::TFO_POINT);
-
-				gDeferredDoFCombineProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, dst->getWidth(), dst->getHeight());
-				gDeferredDoFCombineProgram.uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
-				gDeferredDoFCombineProgram.uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
-				gDeferredDoFCombineProgram.uniform1f(LLShaderMgr::DOF_WIDTH, (dof_width - 1) / (F32)src->getWidth());
-				gDeferredDoFCombineProgram.uniform1f(LLShaderMgr::DOF_HEIGHT, (dof_height - 1) / (F32)src->getHeight());
-
-				mScreenTriangleVB->setBuffer();
-				mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-
-				gDeferredDoFCombineProgram.unbind();
-
-				dst->flush();
-			}
-		}
-		else
-		{
-			copyRenderTarget(src, dst);
-		}
-	}
-}
-
-void LLPipeline::renderFinalize()
+void LLPipeline::findReferences(LLDrawable *drawablep)
 {
-    llassert(!gCubeSnapshot);
-    LLVertexBuffer::unbind();
-    LLGLState::checkStates();
-
     assertInitialized();
-
-    LL_RECORD_BLOCK_TIME(FTM_RENDER_BLOOM);
-    LL_PROFILE_GPU_ZONE("renderFinalize");
-
-    gGL.color4f(1, 1, 1, 1);
-    LLGLDepthTest depth(GL_FALSE);
-    LLGLDisable blend(GL_BLEND);
-    LLGLDisable cull(GL_CULL_FACE);
-
-    enableLightsFullbright();
-
-    gGL.setColorMask(true, true);
-    glClearColor(0, 0, 0, 0);
-
-    
-    copyScreenSpaceReflections(&mRT->screen, &mSceneMap);
-
-    generateLuminance(&mRT->screen, &mLuminanceMap);
-
-    generateExposure(&mLuminanceMap, &mExposureMap);
-
-	static LLCachedControl<bool> use_linden_gamma(gSavedSettings, "RenderLindenGamma", false);
-	if (use_linden_gamma)
-	{
-		gammaCorrect(&mRT->screen, &mPostMap);
-	}
-	else
-	{
-		if (mALRenderUtil->getSharpenMethod() != ALRenderUtil::SHARPEN_NONE)
-		{
-			mALRenderUtil->renderTonemap(&mRT->screen, &mExposureMap, &mRT->deferredLight);
-			mALRenderUtil->renderSharpen(&mRT->deferredLight, &mRT->screen);
-			mALRenderUtil->renderColorGrade(&mRT->screen, &mPostMap);
-		}
-		else
-		{
-			mALRenderUtil->renderTonemap(&mRT->screen, &mExposureMap, &mRT->deferredLight);
-			mALRenderUtil->renderColorGrade(&mRT->deferredLight, &mPostMap);
-		}
-	}
-
-    LLVertexBuffer::unbind();
-
-    generateGlow(&mPostMap);
-
-    combineGlow(&mPostMap, &mPostFXMap);
-
-	// [RLVa:KB] - @setsphere
-	LLRenderTarget* pRenderBuffer = &mPostFXMap;
-	if (RlvActions::hasBehaviour(RLV_BHVR_SETSPHERE))
-	{
-		LLShaderEffectParams params(pRenderBuffer, &mPostHelperMap, false);
-		LLVfxManager::instance().runEffect(EVisualEffect::RlvSphere, &params);
-		pRenderBuffer = params.m_pDstBuffer;
-	}
-// [/RLVa:KB]
-
-	renderDoF(pRenderBuffer, &mPostMap);
-
-	gGLViewport[0] = gViewerWindow->getWorldViewRectRaw().mLeft;
-	gGLViewport[1] = gViewerWindow->getWorldViewRectRaw().mBottom;
-	gGLViewport[2] = gViewerWindow->getWorldViewRectRaw().getWidth();
-	gGLViewport[3] = gViewerWindow->getWorldViewRectRaw().getHeight();
-	glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]);
-
-	applyFXAA(&mPostMap, &mPostFXMap);
-	LLRenderTarget* finalBuffer = &mPostFXMap;
-	if (RenderBufferVisualization > -1)
-    {
-		finalBuffer = &mPostMap;
-		switch (RenderBufferVisualization)
-		{
-		case 0:
-		case 1:
-		case 2:
-		case 3:
-			visualizeBuffers(&mRT->deferredScreen, finalBuffer, RenderBufferVisualization);
-			break;
-		case 4:
-			visualizeBuffers(&mLuminanceMap, finalBuffer, 0);
-		default:
-			break;
-		}
-	}
-
-	// Present the screen target.
-
-	gDeferredPostNoDoFProgram.bind();
-
-	// Whatever is last in the above post processing chain should _always_ be rendered directly here.  If not, expect problems.
-	gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, finalBuffer);
-	gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, &mRT->deferredScreen, true);
-
-	{
-		LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
-		mScreenTriangleVB->setBuffer();
-		mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-	}
-
-	gDeferredPostNoDoFProgram.unbind();
-
-    gGL.setSceneBlendType(LLRender::BT_ALPHA);
-
-    if (hasRenderDebugMask(LLPipeline::RENDER_DEBUG_PHYSICS_SHAPES))
+    if (mLights.find(drawablep) != mLights.end())
     {
-        renderPhysicsDisplay();
+        LL_INFOS() << "In mLights" << LL_ENDL;
+    }
+    if (std::find(mMovedList.begin(), mMovedList.end(), drawablep) != mMovedList.end())
+    {
+        LL_INFOS() << "In mMovedList" << LL_ENDL;
+    }
+    if (std::find(mShiftList.begin(), mShiftList.end(), drawablep) != mShiftList.end())
+    {
+        LL_INFOS() << "In mShiftList" << LL_ENDL;
+    }
+    if (mRetexturedList.find(drawablep) != mRetexturedList.end())
+    {
+        LL_INFOS() << "In mRetexturedList" << LL_ENDL;
     }
 
-    /*if (LLRenderTarget::sUseFBO && !gCubeSnapshot)
-    { // copy depth buffer from mRT->screen to framebuffer
-        LLRenderTarget::copyContentsToFramebuffer(mRT->screen, 0, 0, mRT->screen.getWidth(), mRT->screen.getHeight(), 0, 0,
-                                                  mRT->screen.getWidth(), mRT->screen.getHeight(),
-                                                  GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
-    }*/
-
-    LLVertexBuffer::unbind();
-
-    LLGLState::checkStates();
-
-    // flush calls made to "addTrianglesDrawn" so far to stats machinery
-    recordTrianglesDrawn();
-}
-
-void LLPipeline::bindLightFunc(LLGLSLShader& shader)
-{
-    S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHTFUNC);
-    if (channel > -1)
+    if (std::find(mBuildQ1.begin(), mBuildQ1.end(), drawablep) != mBuildQ1.end())
     {
-        gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc);
+        LL_INFOS() << "In mBuildQ1" << LL_ENDL;
     }
 
-    channel = shader.enableTexture(LLShaderMgr::DEFERRED_BRDF_LUT, LLTexUnit::TT_TEXTURE);
-    if (channel > -1)
+    S32 count;
+
+    count = gObjectList.findReferences(drawablep);
+    if (count)
     {
-        mPbrBrdfLut.bindTexture(0, channel);
+        LL_INFOS() << "In other drawables: " << count << " references" << LL_ENDL;
     }
 }
 
-void LLPipeline::bindShadowMaps(LLGLSLShader& shader)
+bool LLPipeline::verify()
 {
-    for (U32 i = 0; i < 4; i++)
+    bool ok = assertInitialized();
+    if (ok)
     {
-        LLRenderTarget* shadow_target = getSunShadowTarget(i);
-        if (shadow_target)
+        for (LLDrawPool* poolp : mPools)
         {
-            S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_SHADOW0 + i, LLTexUnit::TT_TEXTURE);
-            if (channel > -1)
+            if (!poolp->verify())
             {
-                gGL.getTexUnit(channel)->bind(getSunShadowTarget(i), TRUE);
+                ok = false;
             }
         }
     }
 
-    for (U32 i = 4; i < 6; i++)
+    if (!ok)
     {
-        S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_SHADOW0 + i);
-        if (channel > -1)
-        {
-            LLRenderTarget* shadow_target = getSpotShadowTarget(i - 4);
-            if (shadow_target)
-            {
-                gGL.getTexUnit(channel)->bind(shadow_target, TRUE);
-            }
-        }
+        LL_WARNS() << "Pipeline verify failed!" << LL_ENDL;
     }
+    return ok;
 }
 
-void LLPipeline::bindDeferredShaderFast(LLGLSLShader& shader)
-{
-    if (shader.mCanBindFast)
-    { // was previously fully bound, use fast path
-        shader.bind();
-        bindLightFunc(shader);
-        bindShadowMaps(shader);
-        bindReflectionProbes(shader);
-    }
-    else
-    { //wasn't previously bound, use slow path
-        bindDeferredShader(shader);
-        shader.mCanBindFast = true;
-    }
-}
-
-void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_target, LLRenderTarget* depth_target)
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-    LLRenderTarget* deferred_target       = &mRT->deferredScreen;
-    LLRenderTarget* deferred_light_target = &mRT->deferredLight;
-
-	shader.bind();
-	S32 channel = 0;
-    channel = shader.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, deferred_target->getUsage());
-	if (channel > -1)
-	{
-        deferred_target->bindTexture(0,channel, LLTexUnit::TFO_POINT); // frag_data[0]
-        gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
-	}
-
-    channel = shader.enableTexture(LLShaderMgr::DEFERRED_SPECULAR, deferred_target->getUsage());
-	if (channel > -1)
-	{
-        deferred_target->bindTexture(1, channel, LLTexUnit::TFO_POINT); // frag_data[1]
-        gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
-	}
+//////////////////////////////
+//
+// Collision detection
+//
+//
 
-    channel = shader.enableTexture(LLShaderMgr::DEFERRED_NORMAL, deferred_target->getUsage());
-	if (channel > -1)
-	{
-        deferred_target->bindTexture(2, channel, LLTexUnit::TFO_POINT); // frag_data[2]
-        gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
-	}
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+/**
+ *  A method to compute a ray-AABB intersection.
+ *  Original code by Andrew Woo, from "Graphics Gems", Academic Press, 1990
+ *  Optimized code by Pierre Terdiman, 2000 (~20-30% faster on my Celeron 500)
+ *  Epsilon value added by Klaus Hartmann. (discarding it saves a few cycles only)
+ *
+ *  Hence this version is faster as well as more robust than the original one.
+ *
+ *  Should work provided:
+ *  1) the integer representation of 0.0f is 0x00000000
+ *  2) the sign bit of the float is the most significant one
+ *
+ *  Report bugs: p.terdiman@codercorner.com
+ *
+ *  \param      aabb        [in] the axis-aligned bounding box
+ *  \param      origin      [in] ray origin
+ *  \param      dir         [in] ray direction
+ *  \param      coord       [out] impact coordinates
+ *  \return     true if ray intersects AABB
+ */
+///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+//#define RAYAABB_EPSILON 0.00001f
+#define IR(x)   ((U32&)x)
 
-    channel = shader.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE, deferred_target->getUsage());
-    if (channel > -1)
-    {
-        deferred_target->bindTexture(3, channel, LLTexUnit::TFO_POINT); // frag_data[3]
-        gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
-    }
+bool LLRayAABB(const LLVector3 &center, const LLVector3 &size, const LLVector3& origin, const LLVector3& dir, LLVector3 &coord, F32 epsilon)
+{
+    bool Inside = true;
+    LLVector3 MinB = center - size;
+    LLVector3 MaxB = center + size;
+    LLVector3 MaxT;
+    MaxT.mV[VX]=MaxT.mV[VY]=MaxT.mV[VZ]=-1.0f;
 
-    channel = shader.enableTexture(LLShaderMgr::DEFERRED_DEPTH, deferred_target->getUsage());
-    if (channel > -1)
+    // Find candidate planes.
+    for(U32 i=0;i<3;i++)
     {
-        if (depth_target)
+        if(origin.mV[i] < MinB.mV[i])
         {
-            gGL.getTexUnit(channel)->bind(depth_target, TRUE);
+            coord.mV[i] = MinB.mV[i];
+            Inside      = false;
+
+            // Calculate T distances to candidate planes
+            U32 tmp;
+            memcpy(&tmp, &dir.mV[i], sizeof(tmp));
+            if(tmp) MaxT.mV[i] = (MinB.mV[i] - origin.mV[i]) / dir.mV[i];
         }
-        else
+        else if(origin.mV[i] > MaxB.mV[i])
         {
-            gGL.getTexUnit(channel)->bind(deferred_target, TRUE);
+            coord.mV[i] = MaxB.mV[i];
+            Inside      = false;
+
+            // Calculate T distances to candidate planes
+            U32 tmp;
+            memcpy(&tmp, &dir.mV[i], sizeof(tmp));
+            if(tmp) MaxT.mV[i] = (MaxB.mV[i] - origin.mV[i]) / dir.mV[i];
         }
-        stop_glerror();
     }
 
-    channel = shader.enableTexture(LLShaderMgr::EXPOSURE_MAP);
-    if (channel > -1)
+    // Ray origin inside bounding box
+    if(Inside)
     {
-        gGL.getTexUnit(channel)->bind(&mExposureMap);
+        coord = origin;
+        return true;
     }
 
-    if (shader.getUniformLocation(LLShaderMgr::VIEWPORT) != -1)
-    {
-		shader.uniform4f(LLShaderMgr::VIEWPORT, (F32) gGLViewport[0],
-									(F32) gGLViewport[1],
-									(F32) gGLViewport[2],
-									(F32) gGLViewport[3]);
-	}
+    // Get largest of the maxT's for final choice of intersection
+    U32 WhichPlane = 0;
+    if(MaxT.mV[1] > MaxT.mV[WhichPlane])    WhichPlane = 1;
+    if(MaxT.mV[2] > MaxT.mV[WhichPlane])    WhichPlane = 2;
 
-    if (sReflectionRender && !shader.getUniformLocation(LLShaderMgr::MODELVIEW_MATRIX))
+    // Check final candidate actually inside box
+    U32 tmp_val;
+    memcpy(&tmp_val, &MaxT.mV[WhichPlane], sizeof(tmp_val));
+    if(tmp_val&0x80000000) return false;
+
+    for(U32 i=0;i<3;i++)
     {
-        shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_MATRIX, 1, FALSE, mReflectionModelView.m);  
+        if(i!=WhichPlane)
+        {
+            coord.mV[i] = origin.mV[i] + MaxT.mV[WhichPlane] * dir.mV[i];
+            if (epsilon > 0)
+            {
+                if(coord.mV[i] < MinB.mV[i] - epsilon || coord.mV[i] > MaxB.mV[i] + epsilon)    return false;
+            }
+            else
+            {
+                if(coord.mV[i] < MinB.mV[i] || coord.mV[i] > MaxB.mV[i])    return false;
+            }
+        }
     }
+    return true;    // ray hits box
+}
 
-	channel = shader.enableTexture(LLShaderMgr::DEFERRED_NOISE);
-	if (channel > -1)
-	{
-        gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap);
-		gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
-	}
-
-    bindLightFunc(shader);
-
-	stop_glerror();
+//////////////////////////////
+//
+// Macros, functions, and inline methods from other classes
+//
+//
 
-    light_target = light_target ? light_target : deferred_light_target;
-    channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHT, light_target->getUsage());
-	if (channel > -1)
-	{
-        if (light_target->isComplete())
+void LLPipeline::setLight(LLDrawable *drawablep, bool is_light)
+{
+    if (drawablep && assertInitialized())
+    {
+        if (is_light)
         {
-            light_target->bindTexture(0, channel, LLTexUnit::TFO_POINT);
+            mLights.insert(drawablep);
+            drawablep->setState(LLDrawable::LIGHT);
         }
         else
         {
-            gGL.getTexUnit(channel)->bindFast(LLViewerFetchedTexture::sWhiteImagep);
+            drawablep->clearState(LLDrawable::LIGHT);
+            mLights.erase(drawablep);
         }
-	}
-
-	stop_glerror();
-
-    bindShadowMaps(shader);
+    }
+}
 
-	stop_glerror();
+//static
+void LLPipeline::toggleRenderType(U32 type)
+{
+    gPipeline.mRenderTypeEnabled[type] = !gPipeline.mRenderTypeEnabled[type];
+    if (type == LLPipeline::RENDER_TYPE_WATER)
+    {
+        gPipeline.mRenderTypeEnabled[LLPipeline::RENDER_TYPE_VOIDWATER] = !gPipeline.mRenderTypeEnabled[LLPipeline::RENDER_TYPE_VOIDWATER];
+    }
+}
 
-	F32 mat[16 * 6];
-	memcpy(mat, &mSunShadowMatrix[0], (sizeof(F32) * 16) * 6);
+//static
+void LLPipeline::toggleRenderTypeControl(U32 type)
+{
+    gPipeline.toggleRenderType(type);
+}
 
-	shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_SHADOW_MATRIX, 6, FALSE, mat);
+//static
+bool LLPipeline::hasRenderTypeControl(U32 type)
+{
+    return gPipeline.hasRenderType(type);
+}
 
-	stop_glerror();
+// Allows UI items labeled "Hide foo" instead of "Show foo"
+//static
+bool LLPipeline::toggleRenderTypeControlNegated(S32 type)
+{
+    return !gPipeline.hasRenderType(type);
+}
 
-    if (!LLPipeline::sReflectionProbesEnabled)
+//static
+void LLPipeline::toggleRenderDebug(U64 bit)
+{
+    if (gPipeline.hasRenderDebugMask(bit))
     {
-        channel = shader.enableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
-        if (channel > -1)
-        {
-            LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
-            if (cube_map)
-            {
-                cube_map->enable(channel);
-                cube_map->bind();
-            }
+        LL_INFOS() << "Toggling render debug mask " << std::hex << bit << " off" << std::dec << LL_ENDL;
+    }
+    else
+    {
+        LL_INFOS() << "Toggling render debug mask " << std::hex << bit << " on" << std::dec << LL_ENDL;
+    }
+    gPipeline.mRenderDebugMask ^= bit;
+}
 
-            F32* m = gGLModelView.getF32ptr();
 
-            F32 mat[] = { m[0], m[1], m[2],
-                          m[4], m[5], m[6],
-                          m[8], m[9], m[10] };
+//static
+bool LLPipeline::toggleRenderDebugControl(U64 bit)
+{
+    return gPipeline.hasRenderDebugMask(bit);
+}
 
-            shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_ENV_MAT, 1, TRUE, mat);
-        }
-    }
+//static
+void LLPipeline::toggleRenderDebugFeature(U32 bit)
+{
+    gPipeline.mRenderDebugFeatureMask ^= bit;
+}
 
-    bindReflectionProbes(shader);
 
-    /*if (gCubeSnapshot)
-    { // we only really care about the first two values, but the shader needs increasing separation between clip planes
-        shader.uniform4f(LLShaderMgr::DEFERRED_SHADOW_CLIP, 1.f, 64.f, 128.f, 256.f);
+//static
+bool LLPipeline::toggleRenderDebugFeatureControl(U32 bit)
+{
+    return gPipeline.hasRenderDebugFeatureMask(bit);
+}
+
+void LLPipeline::setRenderDebugFeatureControl(U32 bit, bool value)
+{
+    if (value)
+    {
+        gPipeline.mRenderDebugFeatureMask |= bit;
     }
-    else*/
+    else
     {
-        shader.uniform4fv(LLShaderMgr::DEFERRED_SHADOW_CLIP, 1, mSunClipPlanes.mV);
+        gPipeline.mRenderDebugFeatureMask &= !bit;
     }
-	shader.uniform1f(LLShaderMgr::DEFERRED_SUN_WASH, RenderDeferredSunWash);
-	shader.uniform1f(LLShaderMgr::DEFERRED_SHADOW_NOISE, RenderShadowNoise);
-	shader.uniform1f(LLShaderMgr::DEFERRED_BLUR_SIZE, RenderShadowBlurSize);
-
-	shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_RADIUS, RenderSSAOScale);
-	shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_MAX_RADIUS, RenderSSAOMaxScale);
-
-	F32 ssao_factor = RenderSSAOFactor;
-	shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR, ssao_factor);
-	shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR_INV, 1.0/ssao_factor);
-
-	LLVector3 ssao_effect = RenderSSAOEffect;
-	F32 matrix_diag = (ssao_effect[0] + 2.0*ssao_effect[1])/3.0;
-	F32 matrix_nondiag = (ssao_effect[0] - ssao_effect[1])/3.0;
-	// This matrix scales (proj of color onto <1/rt(3),1/rt(3),1/rt(3)>) by
-	// value factor, and scales remainder by saturation factor
-	F32 ssao_effect_mat[] = {	matrix_diag, matrix_nondiag, matrix_nondiag,
-								matrix_nondiag, matrix_diag, matrix_nondiag,
-								matrix_nondiag, matrix_nondiag, matrix_diag};
-	shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_SSAO_EFFECT_MAT, 1, GL_FALSE, ssao_effect_mat);
-
-	//F32 shadow_offset_error = 1.f + RenderShadowOffsetError * fabsf(LLViewerCamera::getInstance()->getOrigin().mV[2]);
-	F32 shadow_bias_error = RenderShadowBiasError * fabsf(LLViewerCamera::getInstance()->getOrigin().mV[2])/3000.f;
-    F32 shadow_bias       = RenderShadowBias + shadow_bias_error;
-
-    shader.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, deferred_target->getWidth(), deferred_target->getHeight());
-	shader.uniform1f(LLShaderMgr::DEFERRED_NEAR_CLIP, LLViewerCamera::getInstance()->getNear()*2.f);
-	shader.uniform1f (LLShaderMgr::DEFERRED_SHADOW_OFFSET, RenderShadowOffset); //*shadow_offset_error);
-    shader.uniform1f(LLShaderMgr::DEFERRED_SHADOW_BIAS, shadow_bias);
-	shader.uniform1f(LLShaderMgr::DEFERRED_SPOT_SHADOW_OFFSET, RenderSpotShadowOffset);
-	shader.uniform1f(LLShaderMgr::DEFERRED_SPOT_SHADOW_BIAS, RenderSpotShadowBias);	
-
-	shader.uniform3fv(LLShaderMgr::DEFERRED_SUN_DIR, 1, mTransformedSunDir.getF32ptr());
-    shader.uniform3fv(LLShaderMgr::DEFERRED_MOON_DIR, 1, mTransformedMoonDir.getF32ptr());
-	shader.uniform2f(LLShaderMgr::DEFERRED_SHADOW_RES, mRT->shadow[0].getWidth(), mRT->shadow[0].getHeight());
-	shader.uniform2f(LLShaderMgr::DEFERRED_PROJ_SHADOW_RES, mSpotShadow[0].getWidth(), mSpotShadow[0].getHeight());
-	shader.uniform1f(LLShaderMgr::DEFERRED_DEPTH_CUTOFF, RenderEdgeDepthCutoff);
-	shader.uniform1f(LLShaderMgr::DEFERRED_NORM_CUTOFF, RenderEdgeNormCutoff);
-	
-    shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_DELTA_MATRIX, 1, GL_FALSE, gGLDeltaModelView.getF32ptr());
-    shader.uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_DELTA_MATRIX, 1, GL_FALSE, gGLInverseDeltaModelView.getF32ptr());
-
-    shader.uniform1i(LLShaderMgr::CUBE_SNAPSHOT, gCubeSnapshot ? 1 : 0);
+}
 
-	if (shader.getUniformLocation(LLShaderMgr::DEFERRED_NORM_MATRIX) >= 0)
-	{
-		LLMatrix4a norm_mat = get_current_modelview();
-		norm_mat.invert();
-		norm_mat.transpose();
-		shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, FALSE, norm_mat.getF32ptr());
-	}
+void LLPipeline::pushRenderDebugFeatureMask()
+{
+    mRenderDebugFeatureStack.push(mRenderDebugFeatureMask);
+}
 
-    // auto adjust legacy sun color if needed
-    static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
-    static LLCachedControl<F32> auto_adjust_sun_color_scale(gSavedSettings, "RenderSkyAutoAdjustSunColorScale", 1.f);
-    LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
-    LLColor3 sun_diffuse(mSunDiffuse.mV);
-    if (should_auto_adjust && psky->canAutoAdjust())
+void LLPipeline::popRenderDebugFeatureMask()
+{
+    if (mRenderDebugFeatureStack.empty())
     {
-        sun_diffuse *= auto_adjust_sun_color_scale;
+        LL_ERRS() << "Depleted render feature stack." << LL_ENDL;
     }
 
-    shader.uniform3fv(LLShaderMgr::SUNLIGHT_COLOR, 1, sun_diffuse.mV);
-    shader.uniform3fv(LLShaderMgr::MOONLIGHT_COLOR, 1, mMoonDiffuse.mV);
+    mRenderDebugFeatureMask = mRenderDebugFeatureStack.top();
+    mRenderDebugFeatureStack.pop();
+}
 
-    shader.uniform1f(LLShaderMgr::REFLECTION_PROBE_MAX_LOD, mReflectionMapManager.mMaxProbeLOD);
+// static
+void LLPipeline::setRenderScriptedBeacons(bool val)
+{
+    sRenderScriptedBeacons = val;
 }
 
+// static
+void LLPipeline::toggleRenderScriptedBeacons()
+{
+    sRenderScriptedBeacons = !sRenderScriptedBeacons;
+}
 
-LLColor3 pow3f(LLColor3 v, F32 f)
+// static
+bool LLPipeline::getRenderScriptedBeacons()
 {
-	v.mV[0] = powf(v.mV[0], f);
-	v.mV[1] = powf(v.mV[1], f);
-	v.mV[2] = powf(v.mV[2], f);
-	return v;
+    return sRenderScriptedBeacons;
 }
 
-LLVector4 pow4fsrgb(LLVector4 v, F32 f)
+// static
+void LLPipeline::setRenderScriptedTouchBeacons(bool val)
 {
-	v.mV[0] = powf(v.mV[0], f);
-	v.mV[1] = powf(v.mV[1], f);
-	v.mV[2] = powf(v.mV[2], f);
-	return v;
+    sRenderScriptedTouchBeacons = val;
 }
 
-void LLPipeline::renderDeferredLighting()
+// static
+void LLPipeline::toggleRenderScriptedTouchBeacons()
 {
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-    LL_PROFILE_GPU_ZONE("renderDeferredLighting");
-    if (!sCull)
-    {
-        return;
-    }
+    sRenderScriptedTouchBeacons = !sRenderScriptedTouchBeacons;
+}
 
-    llassert(!sRenderingHUDs);
+// static
+bool LLPipeline::getRenderScriptedTouchBeacons()
+{
+    return sRenderScriptedTouchBeacons;
+}
 
-    F32 light_scale = 1.f;
+// static
+void LLPipeline::setRenderMOAPBeacons(bool val)
+{
+    sRenderMOAPBeacons = val;
+}
 
-    if (gCubeSnapshot)
-    { //darken local lights when probe ambiance is above 1
-        light_scale = mReflectionMapManager.mLightScale;
-    }
-	else
-	{
-		static LLCachedControl<F32> alchemy_light_scale(gSavedSettings, "AlchemyGlobalLightScale", 1.f);
-		light_scale = alchemy_light_scale;
-	}
+// static
+void LLPipeline::toggleRenderMOAPBeacons()
+{
+    sRenderMOAPBeacons = !sRenderMOAPBeacons;
+}
 
-    LLRenderTarget *screen_target         = &mRT->screen;
-    LLRenderTarget* deferred_light_target = &mRT->deferredLight;
+// static
+bool LLPipeline::getRenderMOAPBeacons()
+{
+    return sRenderMOAPBeacons;
+}
 
-    {
-        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("deferred");
-        LLViewerCamera *camera = LLViewerCamera::getInstance();
-        
-        if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD))
-        {
-            gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
-        }
+// static
+void LLPipeline::setRenderPhysicalBeacons(bool val)
+{
+    sRenderPhysicalBeacons = val;
+}
 
-        gGL.setColorMask(true, true);
+// static
+void LLPipeline::toggleRenderPhysicalBeacons()
+{
+    sRenderPhysicalBeacons = !sRenderPhysicalBeacons;
+}
 
-        // draw a cube around every light
-        LLVertexBuffer::unbind();
+// static
+bool LLPipeline::getRenderPhysicalBeacons()
+{
+    return sRenderPhysicalBeacons;
+}
 
-        LLGLEnable cull(GL_CULL_FACE);
-        LLGLEnable blend(GL_BLEND);
+// static
+void LLPipeline::setRenderParticleBeacons(bool val)
+{
+    sRenderParticleBeacons = val;
+}
 
-        const LLMatrix4a& mat = get_current_modelview();
+// static
+void LLPipeline::toggleRenderParticleBeacons()
+{
+    sRenderParticleBeacons = !sRenderParticleBeacons;
+}
 
-        setupHWLights();  // to set mSun/MoonDir;
+// static
+bool LLPipeline::getRenderParticleBeacons()
+{
+    return sRenderParticleBeacons;
+}
 
-		mTransformedSunDir.loadua(mSunDir.mV);
-		mat.rotate(mTransformedSunDir, mTransformedSunDir);
+// static
+void LLPipeline::setRenderSoundBeacons(bool val)
+{
+    sRenderSoundBeacons = val;
+}
 
-		mTransformedMoonDir.loadua(mMoonDir.mV);
-		mat.rotate(mTransformedMoonDir, mTransformedMoonDir);
+// static
+void LLPipeline::toggleRenderSoundBeacons()
+{
+    sRenderSoundBeacons = !sRenderSoundBeacons;
+}
 
-        if (RenderDeferredSSAO || RenderShadowDetail > 0)
-        {
-            LL_PROFILE_GPU_ZONE("sun program");
-            deferred_light_target->bindTarget();
-            {  // paint shadow/SSAO light map (direct lighting lightmap)
-                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - sun shadow");
-                bindDeferredShader(gDeferredSunProgram, deferred_light_target);
-                mScreenTriangleVB->setBuffer();
-                glClearColor(1, 1, 1, 1);
-                deferred_light_target->clear(GL_COLOR_BUFFER_BIT);
-                glClearColor(0, 0, 0, 0);
+// static
+bool LLPipeline::getRenderSoundBeacons()
+{
+    return sRenderSoundBeacons;
+}
 
-                gDeferredSunProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
-                                              deferred_light_target->getWidth(),
-                                              deferred_light_target->getHeight());
+// static
+void LLPipeline::setRenderBeacons(bool val)
+{
+    sRenderBeacons = val;
+}
 
-                {
-                    LLGLDisable   blend(GL_BLEND);
-                    LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
-                    mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-                }
+// static
+void LLPipeline::toggleRenderBeacons()
+{
+    sRenderBeacons = !sRenderBeacons;
+}
 
-                unbindDeferredShader(gDeferredSunProgram);
-            }
-            deferred_light_target->flush();
-        }
+// static
+bool LLPipeline::getRenderBeacons()
+{
+    return sRenderBeacons;
+}
 
-		static LLCachedControl<bool> always_soften_shadows(gSavedSettings, "RenderAlwaysSoftenShadows", false);
-        if (RenderDeferredSSAO || (RenderShadowDetail > 0 && always_soften_shadows))
-        {
-            // soften direct lighting lightmap
-            LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - soften shadow");
-            LL_PROFILE_GPU_ZONE("soften shadow");
-            // blur lightmap
-            screen_target->bindTarget();
-            glClearColor(1, 1, 1, 1);
-            screen_target->clear(GL_COLOR_BUFFER_BIT);
-            glClearColor(0, 0, 0, 0);
+// static
+void LLPipeline::setRenderHighlights(bool val)
+{
+    sRenderHighlight = val;
+}
 
-            bindDeferredShader(gDeferredBlurLightProgram);
+// static
+void LLPipeline::toggleRenderHighlights()
+{
+    sRenderHighlight = !sRenderHighlight;
+}
 
-            LLVector3 go = RenderShadowGaussian;
-            const U32 kern_length = 4;
-            F32       blur_size = RenderShadowBlurSize;
-            F32       dist_factor = RenderShadowBlurDistFactor;
+// static
+bool LLPipeline::getRenderHighlights()
+{
+    return sRenderHighlight;
+}
 
-            // sample symmetrically with the middle sample falling exactly on 0.0
-            F32 x = 0.f;
+// static
+void LLPipeline::setRenderHighlightTextureChannel(LLRender::eTexIndex channel)
+{
+    sRenderHighlightTextureChannel = channel;
+}
 
-            LLVector3 gauss[kern_length];  // xweight, yweight, offset
+LLVOPartGroup* LLPipeline::lineSegmentIntersectParticle(const LLVector4a& start, const LLVector4a& end, LLVector4a* intersection,
+                                                        S32* face_hit)
+{
+    LLVector4a local_end = end;
 
-            for (U32 i = 0; i < kern_length; i++)
-            {
-                gauss[i].mV[0] = llgaussian(x, go.mV[0]);
-                gauss[i].mV[1] = llgaussian(x, go.mV[1]);
-                gauss[i].mV[2] = x;
-                x += 1.f;
-            }
+    LLVector4a position;
+    position.clear();
 
-            gDeferredBlurLightProgram.uniform2f(sDelta, 1.f, 0.f);
-            gDeferredBlurLightProgram.uniform1f(sDistFactor, dist_factor);
-            gDeferredBlurLightProgram.uniform3fv(sKern, kern_length, gauss[0].mV);
-            gDeferredBlurLightProgram.uniform1f(sKernScale, blur_size * (kern_length / 2.f - 0.5f));
+    LLDrawable* drawable = NULL;
 
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        LLSpatialPartition* part = region->getSpatialPartition(LLViewerRegion::PARTITION_PARTICLE);
+        if (part && hasRenderType(part->mDrawableType))
+        {
+            LLDrawable* hit = part->lineSegmentIntersect(start, local_end, TRUE, FALSE, TRUE, FALSE, face_hit, &position, NULL, NULL, NULL);
+            if (hit)
             {
-                LLGLDisable   blend(GL_BLEND);
-                LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
-                mScreenTriangleVB->setBuffer();
-                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+                drawable = hit;
+                local_end = position;
             }
+        }
+    }
 
-            screen_target->flush();
-            unbindDeferredShader(gDeferredBlurLightProgram);
+    LLVOPartGroup* ret = NULL;
+    if (drawable)
+    {
+        //make sure we're returning an LLVOPartGroup
+        llassert(drawable->getVObj()->getPCode() == LLViewerObject::LL_VO_PART_GROUP);
+        ret = (LLVOPartGroup*) drawable->getVObj().get();
+    }
 
-            bindDeferredShader(gDeferredBlurLightProgram, screen_target);
+    if (intersection)
+    {
+        *intersection = position;
+    }
 
-            deferred_light_target->bindTarget();
+    return ret;
+}
 
-            gDeferredBlurLightProgram.uniform2f(sDelta, 0.f, 1.f);
+LLViewerObject* LLPipeline::lineSegmentIntersectInWorld(const LLVector4a& start, const LLVector4a& end,
+                                                        bool pick_transparent,
+                                                        bool pick_rigged,
+                                                        bool pick_unselectable,
+                                                        bool pick_reflection_probe,
+                                                        S32* face_hit,
+                                                        S32* gltf_node_hit,
+                                                        S32* gltf_primitive_hit,
+                                                        LLVector4a* intersection,         // return the intersection point
+                                                        LLVector2* tex_coord,            // return the texture coordinates of the intersection point
+                                                        LLVector4a* normal,               // return the surface normal at the intersection point
+                                                        LLVector4a* tangent             // return the surface tangent at the intersection point
+    )
+{
+    LLDrawable* drawable = NULL;
 
-            {
-                LLGLDisable   blend(GL_BLEND);
-                LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
-                mScreenTriangleVB->setBuffer();
-                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-            }
-            deferred_light_target->flush();
-            unbindDeferredShader(gDeferredBlurLightProgram);
-        }
+    LLVector4a local_end = end;
 
-        screen_target->bindTarget();
-        // clear color buffer here - zeroing alpha (glow) is important or it will accumulate against sky
-        glClearColor(0, 0, 0, 0);
-        screen_target->clear(GL_COLOR_BUFFER_BIT);
+    LLVector4a position;
+    position.clear();
 
-        if (RenderDeferredAtmospheric)
-        {  // apply sunlight contribution
-            LLGLSLShader &soften_shader = gDeferredSoftenProgram;
+    sPickAvatar = false; //! LLToolMgr::getInstance()->inBuildMode();
 
-            LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - atmospherics");
-            LL_PROFILE_GPU_ZONE("atmospherics");
-            bindDeferredShader(soften_shader);
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        for (U32 j = 0; j < LLViewerRegion::NUM_PARTITIONS; j++)
+        {
+            if ((j == LLViewerRegion::PARTITION_VOLUME) ||
+                (j == LLViewerRegion::PARTITION_BRIDGE) ||
+                (j == LLViewerRegion::PARTITION_AVATAR) || // for attachments
+                (j == LLViewerRegion::PARTITION_CONTROL_AV) ||
+                (j == LLViewerRegion::PARTITION_TERRAIN) ||
+                (j == LLViewerRegion::PARTITION_TREE) ||
+                (j == LLViewerRegion::PARTITION_GRASS))  // only check these partitions for now
+            {
+                LLSpatialPartition* part = region->getSpatialPartition(j);
+                if (part && hasRenderType(part->mDrawableType))
+                {
+                    LLDrawable* hit = part->lineSegmentIntersect(start, local_end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe, face_hit, &position, tex_coord, normal, tangent);
+                    if (hit)
+                    {
+                        drawable = hit;
+                        local_end = position;
+                    }
+                }
+            }
+        }
+    }
 
-            static LLCachedControl<F32> ssao_scale(gSavedSettings, "RenderSSAOIrradianceScale", 0.5f);
-            static LLCachedControl<F32> ssao_max(gSavedSettings, "RenderSSAOIrradianceMax", 0.25f);
-            static LLStaticHashedString ssao_scale_str("ssao_irradiance_scale");
-            static LLStaticHashedString ssao_max_str("ssao_irradiance_max");
-            
-            soften_shader.uniform1f(ssao_scale_str, ssao_scale);
-            soften_shader.uniform1f(ssao_max_str, ssao_max);
+    if (!sPickAvatar)
+    {
+        //save hit info in case we need to restore
+        //due to attachment override
+        LLVector4a local_normal;
+        LLVector4a local_tangent;
+        LLVector2 local_texcoord;
+        S32 local_face_hit = -1;
+
+        if (face_hit)
+        {
+            local_face_hit = *face_hit;
+        }
+        if (tex_coord)
+        {
+            local_texcoord = *tex_coord;
+        }
+        if (tangent)
+        {
+            local_tangent = *tangent;
+        }
+        else
+        {
+            local_tangent.clear();
+        }
+        if (normal)
+        {
+            local_normal = *normal;
+        }
+        else
+        {
+            local_normal.clear();
+        }
 
-            LLEnvironment &environment = LLEnvironment::instance();
-            soften_shader.uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0);
-            soften_shader.uniform3fv(LLShaderMgr::LIGHTNORM, 1, environment.getClampedLightNorm().mV);
-            
-            soften_shader.uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, LLDrawPoolAlpha::sWaterPlane.mV);
+        const F32 ATTACHMENT_OVERRIDE_DIST = 0.1f;
 
+        //check against avatars
+        sPickAvatar = true;
+        for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+        {
+            LLSpatialPartition* part = region->getSpatialPartition(LLViewerRegion::PARTITION_AVATAR);
+            if (part && hasRenderType(part->mDrawableType))
             {
-                LLGLDepthTest depth(GL_FALSE);
-                LLGLDisable   blend(GL_BLEND);
+                LLDrawable* hit = part->lineSegmentIntersect(start, local_end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe, face_hit, &position, tex_coord, normal, tangent);
+                if (hit)
+                {
+                    LLVector4a delta;
+                    delta.setSub(position, local_end);
+
+                    if (!drawable ||
+                        !drawable->getVObj()->isAttachment() ||
+                        delta.getLength3().getF32() > ATTACHMENT_OVERRIDE_DIST)
+                    { //avatar overrides if previously hit drawable is not an attachment or
+                      //attachment is far enough away from detected intersection
+                        drawable = hit;
+                        local_end = position;
+                    }
+                    else
+                    { //prioritize attachments over avatars
+                        position = local_end;
 
-                // full screen blit
-                mScreenTriangleVB->setBuffer();
-                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+                        if (face_hit)
+                        {
+                            *face_hit = local_face_hit;
+                        }
+                        if (tex_coord)
+                        {
+                            *tex_coord = local_texcoord;
+                        }
+                        if (tangent)
+                        {
+                            *tangent = local_tangent;
+                        }
+                        if (normal)
+                        {
+                            *normal = local_normal;
+                        }
+                    }
+                }
             }
+        }
+    }
 
-            unbindDeferredShader(soften_shader);
+    //check all avatar nametags (silly, isn't it?)
+    for (std::vector< LLCharacter* >::iterator iter = LLCharacter::sInstances.begin();
+        iter != LLCharacter::sInstances.end();
+        ++iter)
+    {
+        LLVOAvatar* av = (LLVOAvatar*) *iter;
+        if (av->mNameText.notNull()
+            && av->mNameText->lineSegmentIntersect(start, local_end, position))
+        {
+            drawable = av->mDrawable;
+            local_end = position;
         }
+    }
+
+    S32 node_hit = -1;
+    S32 primitive_hit = -1;
+    LLDrawable* hit = LL::GLTFSceneManager::instance().lineSegmentIntersect(start, local_end, pick_transparent, pick_rigged, pick_unselectable, pick_reflection_probe, &node_hit, &primitive_hit, &position, tex_coord, normal, tangent);
+    if (hit)
+    {
+        drawable = hit;
+        local_end = position;
+    }
 
-		static LLCachedControl<S32> local_light_count(gSavedSettings, "RenderLocalLightCount", 256);
+    if (gltf_node_hit)
+    {
+        *gltf_node_hit = node_hit;
+    }
 
-        if (local_light_count > 0)
+    if (gltf_primitive_hit)
+    {
+        *gltf_primitive_hit = primitive_hit;
+    }
+
+    if (intersection)
+    {
+        *intersection = position;
+    }
+
+    return drawable ? drawable->getVObj().get() : NULL;
+}
+
+LLViewerObject* LLPipeline::lineSegmentIntersectInHUD(const LLVector4a& start, const LLVector4a& end,
+                                                      bool pick_transparent,
+                                                      S32* face_hit,
+                                                      LLVector4a* intersection,         // return the intersection point
+                                                      LLVector2* tex_coord,            // return the texture coordinates of the intersection point
+                                                      LLVector4a* normal,               // return the surface normal at the intersection point
+                                                      LLVector4a* tangent               // return the surface tangent at the intersection point
+    )
+{
+    LLDrawable* drawable = NULL;
+
+    for (LLViewerRegion* region : LLWorld::getInstance()->getRegionList())
+    {
+        bool toggle = false;
+        if (!hasRenderType(LLPipeline::RENDER_TYPE_HUD))
         {
-            gGL.setSceneBlendType(LLRender::BT_ADD);
-            std::list<LLVector4>        fullscreen_lights;
-            LLDrawable::drawable_list_t spot_lights;
-            LLDrawable::drawable_list_t fullscreen_spot_lights;
+            toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
+            toggle = true;
+        }
 
-            if (!gCubeSnapshot)
+        LLSpatialPartition* part = region->getSpatialPartition(LLViewerRegion::PARTITION_HUD);
+        if (part)
+        {
+            LLDrawable* hit = part->lineSegmentIntersect(start, end, pick_transparent, FALSE, TRUE, FALSE, face_hit, intersection, tex_coord, normal, tangent);
+            if (hit)
             {
-                for (U32 i = 0; i < 2; i++)
-                {
-                    mTargetShadowSpotLight[i] = NULL;
-                }
+                drawable = hit;
             }
+        }
 
-            std::list<LLVector4> light_colors;
+        if (toggle)
+        {
+            toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
+        }
+    }
+    return drawable ? drawable->getVObj().get() : NULL;
+}
 
-            LLVertexBuffer::unbind();
+LLSpatialPartition* LLPipeline::getSpatialPartition(LLViewerObject* vobj)
+{
+    if (vobj)
+    {
+        LLViewerRegion* region = vobj->getRegion();
+        if (region)
+        {
+            return region->getSpatialPartition(vobj->getPartitionType());
+        }
+    }
+    return NULL;
+}
 
-            {
-                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - local lights");
-                LL_PROFILE_GPU_ZONE("local lights");
-                bindDeferredShader(gDeferredLightProgram);
+void LLPipeline::resetVertexBuffers(LLDrawable* drawable)
+{
+    if (!drawable)
+    {
+        return;
+    }
 
-                if (mCubeVB.isNull())
+    for (S32 i = 0; i < drawable->getNumFaces(); i++)
+    {
+        LLFace* facep = drawable->getFace(i);
+        if (facep)
+        {
+            facep->clearVertexBuffer();
+        }
+    }
+}
+
+void LLPipeline::renderObjects(U32 type, bool texture, bool batch_texture, bool rigged)
+{
+    assertInitialized();
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+
+    if (rigged)
+    {
+        mSimplePool->pushRiggedBatches(type + 1, texture, batch_texture);
+    }
+    else
+    {
+        mSimplePool->pushBatches(type, texture, batch_texture);
+    }
+
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+}
+
+void LLPipeline::renderGLTFObjects(U32 type, bool texture, bool rigged)
+{
+    assertInitialized();
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+
+    if (rigged)
+    {
+        mSimplePool->pushRiggedGLTFBatches(type + 1, texture);
+    }
+    else
+    {
+        mSimplePool->pushGLTFBatches(type, texture);
+    }
+
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+
+    if (!rigged)
+    {
+        LL::GLTFSceneManager::instance().renderOpaque();
+    }
+    else
+    {
+        LL::GLTFSceneManager::instance().render(true, true);
+    }
+}
+
+// Currently only used for shadows -Cosmic,2023-04-19
+void LLPipeline::renderAlphaObjects(bool rigged)
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+    assertInitialized();
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+    S32 sun_up = LLEnvironment::instance().getIsSunUp() ? 1 : 0;
+    U32 target_width = LLRenderTarget::sCurResX;
+    U32 type = LLRenderPass::PASS_ALPHA;
+    LLVOAvatar* lastAvatar = nullptr;
+    U64 lastMeshId = 0;
+    auto* begin = gPipeline.beginRenderMap(type);
+    auto* end = gPipeline.endRenderMap(type);
+
+    for (LLCullResult::drawinfo_iterator i = begin; i != end; )
+    {
+        LLDrawInfo* pparams = *i;
+        LLCullResult::increment_iterator(i, end);
+
+        if (rigged != (pparams->mAvatar != nullptr))
+        {
+            // Pool contains both rigged and non-rigged DrawInfos. Only draw
+            // the objects we're interested in in this pass.
+            continue;
+        }
+
+        if (rigged)
+        {
+            if (pparams->mGLTFMaterial)
+            {
+                gDeferredShadowGLTFAlphaBlendProgram.bind(rigged);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
+                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
+                LLRenderPass::pushRiggedGLTFBatch(*pparams, lastAvatar, lastMeshId);
+            }
+            else
+            {
+                gDeferredShadowAlphaMaskProgram.bind(rigged);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
+                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
+                if (lastAvatar != pparams->mAvatar.get() || lastMeshId != pparams->mSkinInfo->mHash)
                 {
-                    mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX);
+                    mSimplePool->uploadMatrixPalette(*pparams);
+                    lastAvatar = pparams->mAvatar;
+                    lastMeshId = pparams->mSkinInfo->mHash;
                 }
 
-                mCubeVB->setBuffer();
+                mSimplePool->pushBatch(*pparams, true, true);
+            }
+        }
+        else
+        {
+            if (pparams->mGLTFMaterial)
+            {
+                gDeferredShadowGLTFAlphaBlendProgram.bind(rigged);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
+                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
+                LLRenderPass::pushGLTFBatch(*pparams);
+            }
+            else
+            {
+                gDeferredShadowAlphaMaskProgram.bind(rigged);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
+                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
+                mSimplePool->pushBatch(*pparams, true, true);
+            }
+        }
+    }
 
-                LLGLDepthTest depth(GL_TRUE, GL_FALSE);
-                // mNearbyLights already includes distance calculation and excludes muted avatars.
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+}
+
+// Currently only used for shadows -Cosmic,2023-04-19
+void LLPipeline::renderMaskedObjects(U32 type, bool texture, bool batch_texture, bool rigged)
+{
+    assertInitialized();
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+    if (rigged)
+    {
+        mAlphaMaskPool->pushRiggedMaskBatches(type+1, texture, batch_texture);
+    }
+    else
+    {
+        mAlphaMaskPool->pushMaskBatches(type, texture, batch_texture);
+    }
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+}
+
+// Currently only used for shadows -Cosmic,2023-04-19
+void LLPipeline::renderFullbrightMaskedObjects(U32 type, bool texture, bool batch_texture, bool rigged)
+{
+    assertInitialized();
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+    if (rigged)
+    {
+        mFullbrightAlphaMaskPool->pushRiggedMaskBatches(type+1, texture, batch_texture);
+    }
+    else
+    {
+        mFullbrightAlphaMaskPool->pushMaskBatches(type, texture, batch_texture);
+    }
+    gGL.loadMatrix(gGLModelView);
+    gGLLastMatrix = NULL;
+}
+
+void validate_framebuffer_object()
+{
+    GLenum status;
+    status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+    switch(status)
+    {
+        case GL_FRAMEBUFFER_COMPLETE:
+            //framebuffer OK, no error.
+            break;
+        case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
+            // frame buffer not OK: probably means unsupported depth buffer format
+            LL_ERRS() << "Framebuffer Incomplete Missing Attachment." << LL_ENDL;
+            break;
+        case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
+            // frame buffer not OK: probably means unsupported depth buffer format
+            LL_ERRS() << "Framebuffer Incomplete Attachment." << LL_ENDL;
+            break;
+        case GL_FRAMEBUFFER_UNSUPPORTED:
+            /* choose different formats */
+            LL_ERRS() << "Framebuffer unsupported." << LL_ENDL;
+            break;
+        default:
+            LL_ERRS() << "Unknown framebuffer status." << LL_ENDL;
+            break;
+    }
+}
+
+void LLPipeline::bindScreenToTexture()
+{
+
+}
+
+static LLTrace::BlockTimerStatHandle FTM_RENDER_BLOOM("Bloom");
+
+void LLPipeline::visualizeBuffers(LLRenderTarget* src, LLRenderTarget* dst, U32 bufferIndex)
+{
+    dst->bindTarget();
+    gDeferredBufferVisualProgram.bind();
+    gDeferredBufferVisualProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_BILINEAR, bufferIndex);
+
+    static LLStaticHashedString mipLevel("mipLevel");
+    if (RenderBufferVisualization != 4)
+        gDeferredBufferVisualProgram.uniform1f(mipLevel, 0);
+    else
+        gDeferredBufferVisualProgram.uniform1f(mipLevel, 8);
+
+    mScreenTriangleVB->setBuffer();
+    mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    gDeferredBufferVisualProgram.unbind();
+    dst->flush();
+}
+
+void LLPipeline::generateLuminance(LLRenderTarget* src, LLRenderTarget* dst)
+{
+    // luminance sample and mipmap generation
+    {
+        LL_PROFILE_GPU_ZONE("luminance sample");
+
+        dst->bindTarget();
+
+        LLGLDepthTest depth(GL_FALSE, GL_FALSE);
+
+        gLuminanceProgram.bind();
+
+        static LLCachedControl<F32> diffuse_luminance_scale(gSavedSettings, "RenderDiffuseLuminanceScale", 1.0f);
+
+        S32 channel = 0;
+        channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE);
+        if (channel > -1)
+        {
+            src->bindTexture(0, channel, LLTexUnit::TFO_POINT);
+        }
+
+        channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE);
+        if (channel > -1)
+        {
+            mGlow[1].bindTexture(0, channel);
+        }
+
+        channel = gLuminanceProgram.enableTexture(LLShaderMgr::DEFERRED_NORMAL);
+        if (channel > -1)
+        {
+            // bind the normal map to get the environment mask
+            mRT->deferredScreen.bindTexture(2, channel, LLTexUnit::TFO_POINT);
+        }
+
+        static LLStaticHashedString diffuse_luminance_scale_s("diffuse_luminance_scale");
+        gLuminanceProgram.uniform1f(diffuse_luminance_scale_s, diffuse_luminance_scale);
+
+        mScreenTriangleVB->setBuffer();
+        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+        dst->flush();
+
+        // note -- unbind AFTER the glGenerateMipMap so time in generatemipmap can be profiled under "Luminance"
+        // also note -- keep an eye on the performance of glGenerateMipmap, might need to replace it with a mip generation shader
+        gLuminanceProgram.unbind();
+    }
+}
+
+void LLPipeline::generateExposure(LLRenderTarget* src, LLRenderTarget* dst, bool use_history) {
+    // exposure sample
+    {
+        LL_PROFILE_GPU_ZONE("exposure sample");
+
+        if (use_history)
+        {
+            // copy last frame's exposure into mLastExposure
+            mLastExposure.bindTarget();
+            gCopyProgram.bind();
+            gGL.getTexUnit(0)->bind(dst);
+
+            mScreenTriangleVB->setBuffer();
+            mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+            mLastExposure.flush();
+        }
+
+        dst->bindTarget();
+
+        LLGLDepthTest depth(GL_FALSE, GL_FALSE);
+
+        LLGLSLShader* shader;
+        if (use_history)
+        {
+            shader = &gExposureProgram;
+        }
+        else
+        {
+            shader = &gExposureProgramNoFade;
+        }
+
+        shader->bind();
+
+        S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_EMISSIVE);
+        if (channel > -1)
+        {
+            src->bindTexture(0, channel, LLTexUnit::TFO_TRILINEAR);
+        }
+
+        if (use_history)
+        {
+            channel = shader->enableTexture(LLShaderMgr::EXPOSURE_MAP);
+            if (channel > -1)
+            {
+                mLastExposure.bindTexture(0, channel);
+            }
+        }
+
+        static LLStaticHashedString dt("dt");
+        static LLStaticHashedString noiseVec("noiseVec");
+        static LLStaticHashedString dynamic_exposure_params("dynamic_exposure_params");
+        static LLCachedControl<F32> dynamic_exposure_coefficient(gSavedSettings, "RenderDynamicExposureCoefficient", 0.175f);
+        static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
+
+        LLSettingsSky::ptr_t sky = LLEnvironment::instance().getCurrentSky();
+
+        F32 probe_ambiance = LLEnvironment::instance().getCurrentSky()->getReflectionProbeAmbiance(should_auto_adjust);
+        F32 exp_min = 1.f;
+        F32 exp_max = 1.f;
+
+        if (probe_ambiance > 0.f)
+        {
+            F32 hdr_scale = sqrtf(LLEnvironment::instance().getCurrentSky()->getGamma()) * 2.f;
+
+            if (hdr_scale > 1.f)
+            {
+                exp_min = 1.f / hdr_scale;
+                exp_max = hdr_scale;
+            }
+        }
+        shader->uniform1f(dt, gFrameIntervalSeconds);
+        shader->uniform2f(noiseVec, ll_frand() * 2.0 - 1.0, ll_frand() * 2.0 - 1.0);
+        shader->uniform3f(dynamic_exposure_params, dynamic_exposure_coefficient, exp_min, exp_max);
+
+        mScreenTriangleVB->setBuffer();
+        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+        if (use_history)
+        {
+            gGL.getTexUnit(channel)->unbind(mLastExposure.getUsage());
+        }
+        shader->unbind();
+        dst->flush();
+    }
+}
+
+extern LLPointer<LLImageGL> gEXRImage;
+
+void LLPipeline::gammaCorrect(LLRenderTarget* src, LLRenderTarget* dst) {
+    dst->bindTarget();
+    // gamma correct lighting
+    {
+        LL_PROFILE_GPU_ZONE("gamma correct");
+
+        static LLCachedControl<bool> buildNoPost(gSavedSettings, "RenderDisablePostProcessing", false);
+
+        LLGLDepthTest depth(GL_FALSE, GL_FALSE);
+
+        // Apply gamma correction to the frame here.
+
+        static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
+
+        LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
+
+        bool no_post = gSnapshotNoPost || (buildNoPost && gFloaterTools->isAvailable());
+        LLGLSLShader& shader = no_post ? gNoPostGammaCorrectProgram : // no post (no gamma, no exposure, no tonemapping)
+            psky->getReflectionProbeAmbiance(should_auto_adjust) == 0.f ? gLegacyPostGammaCorrectProgram :
+            gDeferredPostGammaCorrectProgram;
+
+        shader.bind();
+
+        S32 channel = 0;
+
+        shader.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, false, LLTexUnit::TFO_POINT);
+
+        shader.bindTexture(LLShaderMgr::EXPOSURE_MAP, &mExposureMap);
+
+        shader.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, src->getWidth(), src->getHeight());
+
+        static LLCachedControl<F32> exposure(gSavedSettings, "RenderExposure", 1.f);
+
+        F32 e = llclamp(exposure(), 0.5f, 4.f);
+
+        static LLStaticHashedString s_exposure("exposure");
+        static LLStaticHashedString aces_mix("aces_mix");
+
+        shader.uniform1f(s_exposure, e);
+        shader.uniform1f(aces_mix, gEXRImage.notNull() ? 0.f : 0.3f);
+
+        mScreenTriangleVB->setBuffer();
+        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+        gGL.getTexUnit(channel)->unbind(src->getUsage());
+        shader.unbind();
+    }
+    dst->flush();
+}
+
+void LLPipeline::copyScreenSpaceReflections(LLRenderTarget* src, LLRenderTarget* dst)
+{
+
+    if (RenderScreenSpaceReflections && !gCubeSnapshot)
+    {
+        LL_PROFILE_GPU_ZONE("ssr copy");
+        LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
+
+        LLRenderTarget& depth_src = mRT->deferredScreen;
+
+        dst->bindTarget();
+        dst->clear();
+        gCopyDepthProgram.bind();
+
+        S32 diff_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
+        S32 depth_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
+
+        gGL.getTexUnit(diff_map)->bind(src);
+        gGL.getTexUnit(depth_map)->bind(&depth_src, true);
+
+        mScreenTriangleVB->setBuffer();
+        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+        dst->flush();
+    }
+}
+
+void LLPipeline::generateGlow(LLRenderTarget* src)
+{
+    if (sRenderGlow)
+    {
+        LL_PROFILE_GPU_ZONE("glow");
+        mGlow[2].bindTarget();
+        mGlow[2].clear();
+
+        gGlowExtractProgram.bind();
+        F32 maxAlpha = RenderGlowMaxExtractAlpha;
+        F32 warmthAmount = RenderGlowWarmthAmount;
+        LLVector3 lumWeights = RenderGlowLumWeights;
+        LLVector3 warmthWeights = RenderGlowWarmthWeights;
+
+        gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_MIN_LUMINANCE, 9999);
+        gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_MAX_EXTRACT_ALPHA, maxAlpha);
+        gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_LUM_WEIGHTS, lumWeights.mV[0], lumWeights.mV[1],
+            lumWeights.mV[2]);
+        gGlowExtractProgram.uniform3f(LLShaderMgr::GLOW_WARMTH_WEIGHTS, warmthWeights.mV[0], warmthWeights.mV[1],
+            warmthWeights.mV[2]);
+        gGlowExtractProgram.uniform1f(LLShaderMgr::GLOW_WARMTH_AMOUNT, warmthAmount);
+
+        if (RenderGlowNoise)
+        {
+            S32 channel = gGlowExtractProgram.enableTexture(LLShaderMgr::GLOW_NOISE_MAP);
+            if (channel > -1)
+            {
+                gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mTrueNoiseMap);
+                gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
+            }
+            gGlowExtractProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
+                                          mGlow[2].getWidth(),
+                                          mGlow[2].getHeight());
+        }
+
+        {
+            LLGLEnable blend_on(GL_BLEND);
+
+            gGL.setSceneBlendType(LLRender::BT_ADD_WITH_ALPHA);
+
+            gGlowExtractProgram.bindTexture(LLShaderMgr::DIFFUSE_MAP, src);
+
+            gGL.color4f(1, 1, 1, 1);
+            gPipeline.enableLightsFullbright();
+
+            mScreenTriangleVB->setBuffer();
+            mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+            mGlow[2].flush();
+            gGL.setSceneBlendType(LLRender::BT_ALPHA);
+        }
+
+        gGlowExtractProgram.unbind();
+
+        // power of two between 1 and 1024
+        U32 glowResPow = RenderGlowResolutionPow;
+        const U32 glow_res = llmax(1, llmin(1024, 1 << glowResPow));
+
+        S32 kernel = RenderGlowIterations * 2;
+        F32 delta = RenderGlowWidth / glow_res;
+        // Use half the glow width if we have the res set to less than 9 so that it looks
+        // almost the same in either case.
+        if (glowResPow < 9)
+        {
+            delta *= 0.5f;
+        }
+        F32 strength = RenderGlowStrength;
+
+        gGlowProgram.bind();
+        gGlowProgram.uniform1f(LLShaderMgr::GLOW_STRENGTH, strength);
+
+        for (S32 i = 0; i < kernel; i++)
+        {
+            mGlow[i % 2].bindTarget();
+            mGlow[i % 2].clear();
+
+            if (i == 0)
+            {
+                gGlowProgram.bindTexture(LLShaderMgr::DIFFUSE_MAP, &mGlow[2]);
+            }
+            else
+            {
+                gGlowProgram.bindTexture(LLShaderMgr::DIFFUSE_MAP, &mGlow[(i - 1) % 2]);
+            }
+
+            if (i % 2 == 0)
+            {
+                gGlowProgram.uniform2f(LLShaderMgr::GLOW_DELTA, delta, 0);
+            }
+            else
+            {
+                gGlowProgram.uniform2f(LLShaderMgr::GLOW_DELTA, 0, delta);
+            }
+
+            mScreenTriangleVB->setBuffer();
+            mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+            mGlow[i % 2].flush();
+        }
+
+        gGlowProgram.unbind();
+
+    }
+    else // !sRenderGlow, skip the glow ping-pong and just clear the result target
+    {
+        mGlow[1].bindTarget();
+        mGlow[1].clear();
+        mGlow[1].flush();
+    }
+}
+
+void LLPipeline::applyFXAA(LLRenderTarget* src, LLRenderTarget* dst)
+{
+    {
+        llassert(!gCubeSnapshot);
+        bool multisample = RenderFSAASamples > 1 && mPostHelperMap.isComplete();
+        LLGLSLShader* shader = &gGlowCombineProgram;
+
+        S32 width = dst->getWidth();
+        S32 height = dst->getHeight();
+
+        // Present everything.
+        if (multisample)
+        {
+            LL_PROFILE_GPU_ZONE("aa");
+            // bake out texture2D with RGBL for FXAA shader
+            mPostHelperMap.bindTarget();
+
+            shader = &gGlowCombineFXAAProgram;
+            shader->bind();
+
+            S32 channel = shader->enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, src->getUsage());
+            if (channel > -1)
+            {
+                src->bindTexture(0, channel, LLTexUnit::TFO_BILINEAR);
+            }
+
+            {
+                LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
+                mScreenTriangleVB->setBuffer();
+                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+            }
+
+            shader->disableTexture(LLShaderMgr::DEFERRED_DIFFUSE, src->getUsage());
+            shader->unbind();
+
+            mPostHelperMap.flush();
+
+            dst->bindTarget();
+
+            U32 fsaa_quality = 0;
+            switch (RenderFSAASamples)
+            {
+            case 2:
+                fsaa_quality = 0;
+                break;
+            case 4:
+                fsaa_quality = 1;
+                break;
+            default:
+            case 8:
+                fsaa_quality = 2;
+                break;
+            case 16:
+                fsaa_quality = 3;
+                break;
+            }
+            shader = &gFXAAProgram[fsaa_quality];
+            shader->bind();
+
+            channel = shader->enableTexture(LLShaderMgr::DIFFUSE_MAP, mPostHelperMap.getUsage());
+            if (channel > -1)
+            {
+                mPostHelperMap.bindTexture(0, channel, LLTexUnit::TFO_BILINEAR);
+            }
+
+            F32 scale_x = (F32)width / mPostHelperMap.getWidth();
+            F32 scale_y = (F32)height / mPostHelperMap.getHeight();
+            shader->uniform2f(LLShaderMgr::FXAA_TC_SCALE, scale_x, scale_y);
+            shader->uniform2f(LLShaderMgr::FXAA_RCP_SCREEN_RES, 1.f / width * scale_x, 1.f / height * scale_y);
+            shader->uniform4f(LLShaderMgr::FXAA_RCP_FRAME_OPT, -0.5f / width * scale_x, -0.5f / height * scale_y,
+                0.5f / width * scale_x, 0.5f / height * scale_y);
+            shader->uniform4f(LLShaderMgr::FXAA_RCP_FRAME_OPT2, -2.f / width * scale_x, -2.f / height * scale_y,
+                2.f / width * scale_x, 2.f / height * scale_y);
+
+            {
+                LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
+                S32 depth_channel = shader->getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
+                gGL.getTexUnit(depth_channel)->bind(&mRT->deferredScreen, true);
+
+                mScreenTriangleVB->setBuffer();
+                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+            }
+
+            shader->unbind();
+            dst->flush();
+        }
+        else {
+            copyRenderTarget(src, dst);
+        }
+    }
+}
+
+void LLPipeline::copyRenderTarget(LLRenderTarget* src, LLRenderTarget* dst)
+{
+
+    LL_PROFILE_GPU_ZONE("copyRenderTarget");
+    dst->bindTarget();
+
+    gDeferredPostNoDoFProgram.bind();
+
+    gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src);
+    gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, &mRT->deferredScreen, true);
+
+    {
+        mScreenTriangleVB->setBuffer();
+        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    }
+
+    gDeferredPostNoDoFProgram.unbind();
+
+    dst->flush();
+}
+
+void LLPipeline::combineGlow(LLRenderTarget* src, LLRenderTarget* dst)
+{
+    // Go ahead and do our glow combine here in our destination.  We blit this later into the front buffer.
+
+    dst->bindTarget();
+
+    {
+
+        gGlowCombineProgram.bind();
+
+        gGlowCombineProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src);
+        gGlowCombineProgram.bindTexture(LLShaderMgr::DEFERRED_EMISSIVE, &mGlow[1]);
+
+        mScreenTriangleVB->setBuffer();
+        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    }
+
+    dst->flush();
+}
+
+void LLPipeline::renderDoF(LLRenderTarget* src, LLRenderTarget* dst)
+{
+    {
+        bool dof_enabled =
+            (RenderDepthOfFieldInEditMode || !LLToolMgr::getInstance()->inBuildMode()) &&
+            RenderDepthOfField &&
+            !gCubeSnapshot;
+
+        gViewerWindow->setup3DViewport();
+
+        if (dof_enabled)
+        {
+            LL_PROFILE_GPU_ZONE("dof");
+            LLGLDisable blend(GL_BLEND);
+
+            // depth of field focal plane calculations
+            static F32 current_distance = 16.f;
+            static F32 start_distance = 16.f;
+            static F32 transition_time = 1.f;
+
+            LLVector3 focus_point;
+            static LLVector3 last_focus_point{};
+            if (LLPipeline::RenderFocusPointLocked && !last_focus_point.isExactlyZero())
+            {
+                focus_point = last_focus_point;
+            }
+            else
+            {
+                LLViewerObject* obj = LLViewerMediaFocus::getInstance()->getFocusedObject();
+                if (obj && obj->mDrawable && obj->isSelected())
+                { // focus on selected media object
+                    S32 face_idx = LLViewerMediaFocus::getInstance()->getFocusedFace();
+                    if (obj && obj->mDrawable)
+                    {
+                        LLFace* face = obj->mDrawable->getFace(face_idx);
+                        if (face)
+                        {
+                            focus_point = face->getPositionAgent();
+                        }
+                    }
+                }
+
+                if (focus_point.isExactlyZero())
+                {
+                    if (LLViewerJoystick::getInstance()->getOverrideCamera() || LLPipeline::RenderFocusPointFollowsPointer)
+                    { // focus on point under cursor
+                        focus_point.set(gDebugRaycastIntersection.getF32ptr());
+                    }
+                    else if (gAgentCamera.cameraMouselook())
+                    { // focus on point under mouselook crosshairs
+                        LLVector4a result;
+                        result.clear();
+
+                        gViewerWindow->cursorIntersect(-1, -1, 512.f, NULL, -1, FALSE, FALSE, TRUE, TRUE, nullptr, nullptr, nullptr, &result);
+
+                        focus_point.set(result.getF32ptr());
+                    }
+                    else
+                    {
+                        // focus on alt-zoom target
+                        LLViewerRegion* region = gAgent.getRegion();
+                        if (region)
+                        {
+                            focus_point = LLVector3(gAgentCamera.getFocusGlobal() - region->getOriginGlobal());
+                        }
+                    }
+                }
+            }
+            last_focus_point = focus_point;
+
+            LLVector3 eye = LLViewerCamera::getInstance()->getOrigin();
+            F32 target_distance = 16.f;
+            if (!focus_point.isExactlyZero())
+            {
+                target_distance = LLViewerCamera::getInstance()->getAtAxis() * (focus_point - eye);
+            }
+
+            if (transition_time >= 1.f && fabsf(current_distance - target_distance) / current_distance > 0.01f)
+            { // large shift happened, interpolate smoothly to new target distance
+                transition_time = 0.f;
+                start_distance = current_distance;
+            }
+            else if (transition_time < 1.f)
+            { // currently in a transition, continue interpolating
+                transition_time += 1.f / CameraFocusTransitionTime * gFrameIntervalSeconds.value();
+                transition_time = llmin(transition_time, 1.f);
+
+                F32 t = cosf(transition_time * F_PI + F_PI) * 0.5f + 0.5f;
+                current_distance = start_distance + (target_distance - start_distance) * t;
+            }
+            else
+            { // small or no change, just snap to target distance
+                current_distance = target_distance;
+            }
+
+            // convert to mm
+            F32 subject_distance = current_distance * 1000.f;
+            F32 fnumber = CameraFNumber;
+            F32 default_focal_length = CameraFocalLength;
+
+            F32 fov = LLViewerCamera::getInstance()->getView();
+
+            const F32 default_fov = CameraFieldOfView * F_PI / 180.f;
+
+            // F32 aspect_ratio = (F32) mRT->screen.getWidth()/(F32)mRT->screen.getHeight();
+
+            F32 dv = 2.f * default_focal_length * tanf(default_fov / 2.f);
+
+            F32 focal_length = dv / (2 * tanf(fov / 2.f));
+
+            // F32 tan_pixel_angle = tanf(LLDrawable::sCurPixelAngle);
+
+            // from wikipedia -- c = |s2-s1|/s2 * f^2/(N(S1-f))
+            // where     N = fnumber
+            //           s2 = dot distance
+            //           s1 = subject distance
+            //           f = focal length
+            //
+
+            F32 blur_constant = focal_length * focal_length / (fnumber * (subject_distance - focal_length));
+            blur_constant /= 1000.f; // convert to meters for shader
+            F32 magnification = focal_length / (subject_distance - focal_length);
+
+            { // build diffuse+bloom+CoF
+                mPostHelperMap.bindTarget();
+
+                gDeferredCoFProgram.bind();
+
+                gDeferredCoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, LLTexUnit::TFO_POINT);
+                gDeferredCoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, &mRT->deferredScreen, true);
+
+                gDeferredCoFProgram.uniform1f(LLShaderMgr::DEFERRED_DEPTH_CUTOFF, RenderEdgeDepthCutoff);
+                gDeferredCoFProgram.uniform1f(LLShaderMgr::DEFERRED_NORM_CUTOFF, RenderEdgeNormCutoff);
+                gDeferredCoFProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, dst->getWidth(), dst->getHeight());
+                gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_FOCAL_DISTANCE, -subject_distance / 1000.f);
+                gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_BLUR_CONSTANT, blur_constant);
+                gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_TAN_PIXEL_ANGLE, tanf(1.f / LLDrawable::sCurPixelAngle));
+                gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_MAGNIFICATION, magnification);
+                gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
+                gDeferredCoFProgram.uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
+
+                mScreenTriangleVB->setBuffer();
+                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+                gDeferredCoFProgram.unbind();
+                mPostHelperMap.flush();
+            }
+
+            U32 dof_width = (U32)(mRT->screen.getWidth() * CameraDoFResScale);
+            U32 dof_height = (U32)(mRT->screen.getHeight() * CameraDoFResScale);
+
+            { // perform DoF sampling at half-res (preserve alpha channel)
+                src->bindTarget();
+                glViewport(0, 0, dof_width, dof_height);
+
+                gGL.setColorMask(true, false);
+
+                LLGLSLShader& post_program = RenderDepthOfFieldNearBlur ? gDeferredPostProgram : gDeferredPostProgramNoNear;
+
+                post_program.bind();
+                post_program.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, &mPostHelperMap, LLTexUnit::TFO_POINT);
+
+                post_program.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, dst->getWidth(), dst->getHeight());
+                post_program.uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
+                post_program.uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
+
+                mScreenTriangleVB->setBuffer();
+                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+                post_program.unbind();
+
+                src->flush();
+                gGL.setColorMask(true, true);
+            }
+
+            { // combine result based on alpha
+
+                dst->bindTarget();
+
+                glViewport(0, 0, dst->getWidth(), dst->getHeight());
+
+                gDeferredDoFCombineProgram.bind();
+                gDeferredDoFCombineProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, src, LLTexUnit::TFO_POINT);
+                gDeferredDoFCombineProgram.bindTexture(LLShaderMgr::DEFERRED_LIGHT, &mPostHelperMap, LLTexUnit::TFO_POINT);
+
+                gDeferredDoFCombineProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, dst->getWidth(), dst->getHeight());
+                gDeferredDoFCombineProgram.uniform1f(LLShaderMgr::DOF_MAX_COF, CameraMaxCoF);
+                gDeferredDoFCombineProgram.uniform1f(LLShaderMgr::DOF_RES_SCALE, CameraDoFResScale);
+                gDeferredDoFCombineProgram.uniform1f(LLShaderMgr::DOF_WIDTH, (dof_width - 1) / (F32)src->getWidth());
+                gDeferredDoFCombineProgram.uniform1f(LLShaderMgr::DOF_HEIGHT, (dof_height - 1) / (F32)src->getHeight());
+
+                mScreenTriangleVB->setBuffer();
+                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+                gDeferredDoFCombineProgram.unbind();
+
+                dst->flush();
+            }
+        }
+        else
+        {
+            copyRenderTarget(src, dst);
+        }
+    }
+}
+
+void LLPipeline::renderFinalize()
+{
+    llassert(!gCubeSnapshot);
+    LLVertexBuffer::unbind();
+    LLGLState::checkStates();
+
+    assertInitialized();
+
+    LL_RECORD_BLOCK_TIME(FTM_RENDER_BLOOM);
+    LL_PROFILE_GPU_ZONE("renderFinalize");
+
+    gGL.color4f(1, 1, 1, 1);
+    LLGLDepthTest depth(GL_FALSE);
+    LLGLDisable blend(GL_BLEND);
+    LLGLDisable cull(GL_CULL_FACE);
+
+    enableLightsFullbright();
+
+    gGL.setColorMask(true, true);
+    glClearColor(0, 0, 0, 0);
+
+
+    copyScreenSpaceReflections(&mRT->screen, &mSceneMap);
+
+    generateLuminance(&mRT->screen, &mLuminanceMap);
+
+    generateExposure(&mLuminanceMap, &mExposureMap);
+
+    static LLCachedControl<bool> use_linden_gamma(gSavedSettings, "RenderLindenGamma", false);
+    if (use_linden_gamma)
+    {
+        gammaCorrect(&mRT->screen, &mPostMap);
+    }
+    else
+    {
+        if (mALRenderUtil->getSharpenMethod() != ALRenderUtil::SHARPEN_NONE)
+        {
+            mALRenderUtil->renderTonemap(&mRT->screen, &mExposureMap, &mRT->deferredLight);
+            mALRenderUtil->renderSharpen(&mRT->deferredLight, &mRT->screen);
+            mALRenderUtil->renderColorGrade(&mRT->screen, &mPostMap);
+        }
+        else
+        {
+            mALRenderUtil->renderTonemap(&mRT->screen, &mExposureMap, &mRT->deferredLight);
+            mALRenderUtil->renderColorGrade(&mRT->deferredLight, &mPostMap);
+        }
+    }
+
+    LLVertexBuffer::unbind();
+
+    generateGlow(&mPostMap);
+
+    combineGlow(&mPostMap, &mPostFXMap);
+
+    // [RLVa:KB] - @setsphere
+    LLRenderTarget* pRenderBuffer = &mPostFXMap;
+    if (RlvActions::hasBehaviour(RLV_BHVR_SETSPHERE))
+    {
+        LLShaderEffectParams params(pRenderBuffer, &mPostHelperMap, false);
+        LLVfxManager::instance().runEffect(EVisualEffect::RlvSphere, &params);
+        pRenderBuffer = params.m_pDstBuffer;
+    }
+// [/RLVa:KB]
+
+    renderDoF(pRenderBuffer, &mPostMap);
+
+    gGLViewport[0] = gViewerWindow->getWorldViewRectRaw().mLeft;
+    gGLViewport[1] = gViewerWindow->getWorldViewRectRaw().mBottom;
+    gGLViewport[2] = gViewerWindow->getWorldViewRectRaw().getWidth();
+    gGLViewport[3] = gViewerWindow->getWorldViewRectRaw().getHeight();
+    glViewport(gGLViewport[0], gGLViewport[1], gGLViewport[2], gGLViewport[3]);
+
+    applyFXAA(&mPostMap, &mPostFXMap);
+    LLRenderTarget* finalBuffer = &mPostFXMap;
+    if (RenderBufferVisualization > -1)
+    {
+        finalBuffer = &mPostMap;
+        switch (RenderBufferVisualization)
+        {
+        case 0:
+        case 1:
+        case 2:
+        case 3:
+            visualizeBuffers(&mRT->deferredScreen, finalBuffer, RenderBufferVisualization);
+            break;
+        case 4:
+            visualizeBuffers(&mLuminanceMap, finalBuffer, 0);
+        default:
+            break;
+        }
+    }
+
+    // Present the screen target.
+
+    gDeferredPostNoDoFProgram.bind();
+
+    // Whatever is last in the above post processing chain should _always_ be rendered directly here.  If not, expect problems.
+    gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DIFFUSE, finalBuffer);
+    gDeferredPostNoDoFProgram.bindTexture(LLShaderMgr::DEFERRED_DEPTH, &mRT->deferredScreen, true);
+
+    {
+        LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_ALWAYS);
+        mScreenTriangleVB->setBuffer();
+        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    }
+
+    gDeferredPostNoDoFProgram.unbind();
+
+    gGL.setSceneBlendType(LLRender::BT_ALPHA);
+
+    if (hasRenderDebugMask(LLPipeline::RENDER_DEBUG_PHYSICS_SHAPES))
+    {
+        renderPhysicsDisplay();
+    }
+
+    /*if (LLRenderTarget::sUseFBO && !gCubeSnapshot)
+    { // copy depth buffer from mRT->screen to framebuffer
+        LLRenderTarget::copyContentsToFramebuffer(mRT->screen, 0, 0, mRT->screen.getWidth(), mRT->screen.getHeight(), 0, 0,
+                                                  mRT->screen.getWidth(), mRT->screen.getHeight(),
+                                                  GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT, GL_NEAREST);
+    }*/
+
+    LLVertexBuffer::unbind();
+
+    LLGLState::checkStates();
+
+    // flush calls made to "addTrianglesDrawn" so far to stats machinery
+    recordTrianglesDrawn();
+}
+
+void LLPipeline::bindLightFunc(LLGLSLShader& shader)
+{
+    S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHTFUNC);
+    if (channel > -1)
+    {
+        gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mLightFunc);
+    }
+
+    channel = shader.enableTexture(LLShaderMgr::DEFERRED_BRDF_LUT, LLTexUnit::TT_TEXTURE);
+    if (channel > -1)
+    {
+        mPbrBrdfLut.bindTexture(0, channel);
+    }
+}
+
+void LLPipeline::bindShadowMaps(LLGLSLShader& shader)
+{
+    for (U32 i = 0; i < 4; i++)
+    {
+        LLRenderTarget* shadow_target = getSunShadowTarget(i);
+        if (shadow_target)
+        {
+            S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_SHADOW0 + i, LLTexUnit::TT_TEXTURE);
+            if (channel > -1)
+            {
+                gGL.getTexUnit(channel)->bind(getSunShadowTarget(i), TRUE);
+            }
+        }
+    }
+
+    for (U32 i = 4; i < 6; i++)
+    {
+        S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_SHADOW0 + i);
+        if (channel > -1)
+        {
+            LLRenderTarget* shadow_target = getSpotShadowTarget(i - 4);
+            if (shadow_target)
+            {
+                gGL.getTexUnit(channel)->bind(shadow_target, TRUE);
+            }
+        }
+    }
+}
+
+void LLPipeline::bindDeferredShaderFast(LLGLSLShader& shader)
+{
+    if (shader.mCanBindFast)
+    { // was previously fully bound, use fast path
+        shader.bind();
+        bindLightFunc(shader);
+        bindShadowMaps(shader);
+        bindReflectionProbes(shader);
+    }
+    else
+    { //wasn't previously bound, use slow path
+        bindDeferredShader(shader);
+        shader.mCanBindFast = true;
+    }
+}
+
+void LLPipeline::bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_target, LLRenderTarget* depth_target)
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+    LLRenderTarget* deferred_target       = &mRT->deferredScreen;
+    LLRenderTarget* deferred_light_target = &mRT->deferredLight;
+
+    shader.bind();
+    S32 channel = 0;
+    channel = shader.enableTexture(LLShaderMgr::DEFERRED_DIFFUSE, deferred_target->getUsage());
+    if (channel > -1)
+    {
+        deferred_target->bindTexture(0,channel, LLTexUnit::TFO_POINT); // frag_data[0]
+        gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
+    }
+
+    channel = shader.enableTexture(LLShaderMgr::DEFERRED_SPECULAR, deferred_target->getUsage());
+    if (channel > -1)
+    {
+        deferred_target->bindTexture(1, channel, LLTexUnit::TFO_POINT); // frag_data[1]
+        gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
+    }
+
+    channel = shader.enableTexture(LLShaderMgr::DEFERRED_NORMAL, deferred_target->getUsage());
+    if (channel > -1)
+    {
+        deferred_target->bindTexture(2, channel, LLTexUnit::TFO_POINT); // frag_data[2]
+        gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
+    }
+
+    channel = shader.enableTexture(LLShaderMgr::DEFERRED_EMISSIVE, deferred_target->getUsage());
+    if (channel > -1)
+    {
+        deferred_target->bindTexture(3, channel, LLTexUnit::TFO_POINT); // frag_data[3]
+        gGL.getTexUnit(channel)->setTextureAddressMode(LLTexUnit::TAM_CLAMP);
+    }
+
+    channel = shader.enableTexture(LLShaderMgr::DEFERRED_DEPTH, deferred_target->getUsage());
+    if (channel > -1)
+    {
+        if (depth_target)
+        {
+            gGL.getTexUnit(channel)->bind(depth_target, TRUE);
+        }
+        else
+        {
+            gGL.getTexUnit(channel)->bind(deferred_target, TRUE);
+        }
+        stop_glerror();
+    }
+
+    channel = shader.enableTexture(LLShaderMgr::EXPOSURE_MAP);
+    if (channel > -1)
+    {
+        gGL.getTexUnit(channel)->bind(&mExposureMap);
+    }
+
+    if (shader.getUniformLocation(LLShaderMgr::VIEWPORT) != -1)
+    {
+        shader.uniform4f(LLShaderMgr::VIEWPORT, (F32) gGLViewport[0],
+                                    (F32) gGLViewport[1],
+                                    (F32) gGLViewport[2],
+                                    (F32) gGLViewport[3]);
+    }
+
+    if (sReflectionRender && !shader.getUniformLocation(LLShaderMgr::MODELVIEW_MATRIX))
+    {
+        shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_MATRIX, 1, FALSE, mReflectionModelView.m);
+    }
+
+    channel = shader.enableTexture(LLShaderMgr::DEFERRED_NOISE);
+    if (channel > -1)
+    {
+        gGL.getTexUnit(channel)->bindManual(LLTexUnit::TT_TEXTURE, mNoiseMap);
+        gGL.getTexUnit(channel)->setTextureFilteringOption(LLTexUnit::TFO_POINT);
+    }
+
+    bindLightFunc(shader);
+
+    stop_glerror();
+
+    light_target = light_target ? light_target : deferred_light_target;
+    channel = shader.enableTexture(LLShaderMgr::DEFERRED_LIGHT, light_target->getUsage());
+    if (channel > -1)
+    {
+        if (light_target->isComplete())
+        {
+            light_target->bindTexture(0, channel, LLTexUnit::TFO_POINT);
+        }
+        else
+        {
+            gGL.getTexUnit(channel)->bindFast(LLViewerFetchedTexture::sWhiteImagep);
+        }
+    }
+
+    stop_glerror();
+
+    bindShadowMaps(shader);
+
+    stop_glerror();
+
+    F32 mat[16 * 6];
+    memcpy(mat, &mSunShadowMatrix[0], (sizeof(F32) * 16) * 6);
+
+    shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_SHADOW_MATRIX, 6, FALSE, mat);
+
+    stop_glerror();
+
+    if (!LLPipeline::sReflectionProbesEnabled)
+    {
+        channel = shader.enableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
+        if (channel > -1)
+        {
+            LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
+            if (cube_map)
+            {
+                cube_map->enable(channel);
+                cube_map->bind();
+            }
+
+            F32* m = gGLModelView.getF32ptr();
+
+            F32 mat[] = { m[0], m[1], m[2],
+                          m[4], m[5], m[6],
+                          m[8], m[9], m[10] };
+
+            shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_ENV_MAT, 1, TRUE, mat);
+        }
+    }
+
+    bindReflectionProbes(shader);
+
+    /*if (gCubeSnapshot)
+    { // we only really care about the first two values, but the shader needs increasing separation between clip planes
+        shader.uniform4f(LLShaderMgr::DEFERRED_SHADOW_CLIP, 1.f, 64.f, 128.f, 256.f);
+    }
+    else*/
+    {
+        shader.uniform4fv(LLShaderMgr::DEFERRED_SHADOW_CLIP, 1, mSunClipPlanes.mV);
+    }
+    shader.uniform1f(LLShaderMgr::DEFERRED_SUN_WASH, RenderDeferredSunWash);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SHADOW_NOISE, RenderShadowNoise);
+    shader.uniform1f(LLShaderMgr::DEFERRED_BLUR_SIZE, RenderShadowBlurSize);
+
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_RADIUS, RenderSSAOScale);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_MAX_RADIUS, RenderSSAOMaxScale);
+
+    F32 ssao_factor = RenderSSAOFactor;
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR, ssao_factor);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSAO_FACTOR_INV, 1.0/ssao_factor);
+
+    LLVector3 ssao_effect = RenderSSAOEffect;
+    F32 matrix_diag = (ssao_effect[0] + 2.0*ssao_effect[1])/3.0;
+    F32 matrix_nondiag = (ssao_effect[0] - ssao_effect[1])/3.0;
+    // This matrix scales (proj of color onto <1/rt(3),1/rt(3),1/rt(3)>) by
+    // value factor, and scales remainder by saturation factor
+    F32 ssao_effect_mat[] = {   matrix_diag, matrix_nondiag, matrix_nondiag,
+                                matrix_nondiag, matrix_diag, matrix_nondiag,
+                                matrix_nondiag, matrix_nondiag, matrix_diag};
+    shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_SSAO_EFFECT_MAT, 1, GL_FALSE, ssao_effect_mat);
+
+    //F32 shadow_offset_error = 1.f + RenderShadowOffsetError * fabsf(LLViewerCamera::getInstance()->getOrigin().mV[2]);
+    F32 shadow_bias_error = RenderShadowBiasError * fabsf(LLViewerCamera::getInstance()->getOrigin().mV[2])/3000.f;
+    F32 shadow_bias       = RenderShadowBias + shadow_bias_error;
+
+    shader.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES, deferred_target->getWidth(), deferred_target->getHeight());
+    shader.uniform1f(LLShaderMgr::DEFERRED_NEAR_CLIP, LLViewerCamera::getInstance()->getNear()*2.f);
+    shader.uniform1f (LLShaderMgr::DEFERRED_SHADOW_OFFSET, RenderShadowOffset); //*shadow_offset_error);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SHADOW_BIAS, shadow_bias);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SPOT_SHADOW_OFFSET, RenderSpotShadowOffset);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SPOT_SHADOW_BIAS, RenderSpotShadowBias);
+
+    shader.uniform3fv(LLShaderMgr::DEFERRED_SUN_DIR, 1, mTransformedSunDir.getF32ptr());
+    shader.uniform3fv(LLShaderMgr::DEFERRED_MOON_DIR, 1, mTransformedMoonDir.getF32ptr());
+    shader.uniform2f(LLShaderMgr::DEFERRED_SHADOW_RES, mRT->shadow[0].getWidth(), mRT->shadow[0].getHeight());
+    shader.uniform2f(LLShaderMgr::DEFERRED_PROJ_SHADOW_RES, mSpotShadow[0].getWidth(), mSpotShadow[0].getHeight());
+    shader.uniform1f(LLShaderMgr::DEFERRED_DEPTH_CUTOFF, RenderEdgeDepthCutoff);
+    shader.uniform1f(LLShaderMgr::DEFERRED_NORM_CUTOFF, RenderEdgeNormCutoff);
+
+    shader.uniformMatrix4fv(LLShaderMgr::MODELVIEW_DELTA_MATRIX, 1, GL_FALSE, gGLDeltaModelView.getF32ptr());
+    shader.uniformMatrix4fv(LLShaderMgr::INVERSE_MODELVIEW_DELTA_MATRIX, 1, GL_FALSE, gGLInverseDeltaModelView.getF32ptr());
+
+    shader.uniform1i(LLShaderMgr::CUBE_SNAPSHOT, gCubeSnapshot ? 1 : 0);
+
+    if (shader.getUniformLocation(LLShaderMgr::DEFERRED_NORM_MATRIX) >= 0)
+    {
+        LLMatrix4a norm_mat = get_current_modelview();
+        norm_mat.invert();
+        norm_mat.transpose();
+        shader.uniformMatrix4fv(LLShaderMgr::DEFERRED_NORM_MATRIX, 1, FALSE, norm_mat.getF32ptr());
+    }
+
+    // auto adjust legacy sun color if needed
+    static LLCachedControl<bool> should_auto_adjust(gSavedSettings, "RenderSkyAutoAdjustLegacy", true);
+    static LLCachedControl<F32> auto_adjust_sun_color_scale(gSavedSettings, "RenderSkyAutoAdjustSunColorScale", 1.f);
+    LLSettingsSky::ptr_t psky = LLEnvironment::instance().getCurrentSky();
+    LLColor3 sun_diffuse(mSunDiffuse.mV);
+    if (should_auto_adjust && psky->canAutoAdjust())
+    {
+        sun_diffuse *= auto_adjust_sun_color_scale;
+    }
+
+    shader.uniform3fv(LLShaderMgr::SUNLIGHT_COLOR, 1, sun_diffuse.mV);
+    shader.uniform3fv(LLShaderMgr::MOONLIGHT_COLOR, 1, mMoonDiffuse.mV);
+
+    shader.uniform1f(LLShaderMgr::REFLECTION_PROBE_MAX_LOD, mReflectionMapManager.mMaxProbeLOD);
+}
+
+
+LLColor3 pow3f(LLColor3 v, F32 f)
+{
+    v.mV[0] = powf(v.mV[0], f);
+    v.mV[1] = powf(v.mV[1], f);
+    v.mV[2] = powf(v.mV[2], f);
+    return v;
+}
+
+LLVector4 pow4fsrgb(LLVector4 v, F32 f)
+{
+    v.mV[0] = powf(v.mV[0], f);
+    v.mV[1] = powf(v.mV[1], f);
+    v.mV[2] = powf(v.mV[2], f);
+    return v;
+}
+
+void LLPipeline::renderDeferredLighting()
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+    LL_PROFILE_GPU_ZONE("renderDeferredLighting");
+    if (!sCull)
+    {
+        return;
+    }
+
+    llassert(!sRenderingHUDs);
+
+    F32 light_scale = 1.f;
+
+    if (gCubeSnapshot)
+    { //darken local lights when probe ambiance is above 1
+        light_scale = mReflectionMapManager.mLightScale;
+    }
+    else
+    {
+        static LLCachedControl<F32> alchemy_light_scale(gSavedSettings, "AlchemyGlobalLightScale", 1.f);
+        light_scale = alchemy_light_scale;
+    }
+
+    LLRenderTarget *screen_target         = &mRT->screen;
+    LLRenderTarget* deferred_light_target = &mRT->deferredLight;
+
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("deferred");
+        LLViewerCamera *camera = LLViewerCamera::getInstance();
+
+        if (gPipeline.hasRenderType(LLPipeline::RENDER_TYPE_HUD))
+        {
+            gPipeline.toggleRenderType(LLPipeline::RENDER_TYPE_HUD);
+        }
+
+        gGL.setColorMask(true, true);
+
+        // draw a cube around every light
+        LLVertexBuffer::unbind();
+
+        LLGLEnable cull(GL_CULL_FACE);
+        LLGLEnable blend(GL_BLEND);
+
+        const LLMatrix4a& mat = get_current_modelview();
+
+        setupHWLights();  // to set mSun/MoonDir;
+
+        mTransformedSunDir.loadua(mSunDir.mV);
+        mat.rotate(mTransformedSunDir, mTransformedSunDir);
+
+        mTransformedMoonDir.loadua(mMoonDir.mV);
+        mat.rotate(mTransformedMoonDir, mTransformedMoonDir);
+
+        if (RenderDeferredSSAO || RenderShadowDetail > 0)
+        {
+            LL_PROFILE_GPU_ZONE("sun program");
+            deferred_light_target->bindTarget();
+            {  // paint shadow/SSAO light map (direct lighting lightmap)
+                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - sun shadow");
+                bindDeferredShader(gDeferredSunProgram, deferred_light_target);
+                mScreenTriangleVB->setBuffer();
+                glClearColor(1, 1, 1, 1);
+                deferred_light_target->clear(GL_COLOR_BUFFER_BIT);
+                glClearColor(0, 0, 0, 0);
+
+                gDeferredSunProgram.uniform2f(LLShaderMgr::DEFERRED_SCREEN_RES,
+                                              deferred_light_target->getWidth(),
+                                              deferred_light_target->getHeight());
+
+                {
+                    LLGLDisable   blend(GL_BLEND);
+                    LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
+                    mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+                }
+
+                unbindDeferredShader(gDeferredSunProgram);
+            }
+            deferred_light_target->flush();
+        }
+
+        static LLCachedControl<bool> always_soften_shadows(gSavedSettings, "RenderAlwaysSoftenShadows", false);
+        if (RenderDeferredSSAO || (RenderShadowDetail > 0 && always_soften_shadows))
+        {
+            // soften direct lighting lightmap
+            LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - soften shadow");
+            LL_PROFILE_GPU_ZONE("soften shadow");
+            // blur lightmap
+            screen_target->bindTarget();
+            glClearColor(1, 1, 1, 1);
+            screen_target->clear(GL_COLOR_BUFFER_BIT);
+            glClearColor(0, 0, 0, 0);
+
+            bindDeferredShader(gDeferredBlurLightProgram);
+
+            LLVector3 go = RenderShadowGaussian;
+            const U32 kern_length = 4;
+            F32       blur_size = RenderShadowBlurSize;
+            F32       dist_factor = RenderShadowBlurDistFactor;
+
+            // sample symmetrically with the middle sample falling exactly on 0.0
+            F32 x = 0.f;
+
+            LLVector3 gauss[kern_length];  // xweight, yweight, offset
+
+            for (U32 i = 0; i < kern_length; i++)
+            {
+                gauss[i].mV[0] = llgaussian(x, go.mV[0]);
+                gauss[i].mV[1] = llgaussian(x, go.mV[1]);
+                gauss[i].mV[2] = x;
+                x += 1.f;
+            }
+
+            gDeferredBlurLightProgram.uniform2f(sDelta, 1.f, 0.f);
+            gDeferredBlurLightProgram.uniform1f(sDistFactor, dist_factor);
+            gDeferredBlurLightProgram.uniform3fv(sKern, kern_length, gauss[0].mV);
+            gDeferredBlurLightProgram.uniform1f(sKernScale, blur_size * (kern_length / 2.f - 0.5f));
+
+            {
+                LLGLDisable   blend(GL_BLEND);
+                LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
+                mScreenTriangleVB->setBuffer();
+                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+            }
+
+            screen_target->flush();
+            unbindDeferredShader(gDeferredBlurLightProgram);
+
+            bindDeferredShader(gDeferredBlurLightProgram, screen_target);
+
+            deferred_light_target->bindTarget();
+
+            gDeferredBlurLightProgram.uniform2f(sDelta, 0.f, 1.f);
+
+            {
+                LLGLDisable   blend(GL_BLEND);
+                LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_ALWAYS);
+                mScreenTriangleVB->setBuffer();
+                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+            }
+            deferred_light_target->flush();
+            unbindDeferredShader(gDeferredBlurLightProgram);
+        }
+
+        screen_target->bindTarget();
+        // clear color buffer here - zeroing alpha (glow) is important or it will accumulate against sky
+        glClearColor(0, 0, 0, 0);
+        screen_target->clear(GL_COLOR_BUFFER_BIT);
+
+        if (RenderDeferredAtmospheric)
+        {  // apply sunlight contribution
+            LLGLSLShader &soften_shader = gDeferredSoftenProgram;
+
+            LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - atmospherics");
+            LL_PROFILE_GPU_ZONE("atmospherics");
+            bindDeferredShader(soften_shader);
+
+            static LLCachedControl<F32> ssao_scale(gSavedSettings, "RenderSSAOIrradianceScale", 0.5f);
+            static LLCachedControl<F32> ssao_max(gSavedSettings, "RenderSSAOIrradianceMax", 0.25f);
+            static LLStaticHashedString ssao_scale_str("ssao_irradiance_scale");
+            static LLStaticHashedString ssao_max_str("ssao_irradiance_max");
+
+            soften_shader.uniform1f(ssao_scale_str, ssao_scale);
+            soften_shader.uniform1f(ssao_max_str, ssao_max);
+
+            LLEnvironment &environment = LLEnvironment::instance();
+            soften_shader.uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0);
+            soften_shader.uniform3fv(LLShaderMgr::LIGHTNORM, 1, environment.getClampedLightNorm().mV);
+
+            soften_shader.uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, LLDrawPoolAlpha::sWaterPlane.mV);
+
+            {
+                LLGLDepthTest depth(GL_FALSE);
+                LLGLDisable   blend(GL_BLEND);
+
+                // full screen blit
+                mScreenTriangleVB->setBuffer();
+                mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+            }
+
+            unbindDeferredShader(soften_shader);
+        }
+
+        static LLCachedControl<S32> local_light_count(gSavedSettings, "RenderLocalLightCount", 256);
+
+        if (local_light_count > 0)
+        {
+            gGL.setSceneBlendType(LLRender::BT_ADD);
+            std::list<LLVector4>        fullscreen_lights;
+            LLDrawable::drawable_list_t spot_lights;
+            LLDrawable::drawable_list_t fullscreen_spot_lights;
+
+            if (!gCubeSnapshot)
+            {
+                for (U32 i = 0; i < 2; i++)
+                {
+                    mTargetShadowSpotLight[i] = NULL;
+                }
+            }
+
+            std::list<LLVector4> light_colors;
+
+            LLVertexBuffer::unbind();
+
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - local lights");
+                LL_PROFILE_GPU_ZONE("local lights");
+                bindDeferredShader(gDeferredLightProgram);
+
+                if (mCubeVB.isNull())
+                {
+                    mCubeVB = ll_create_cube_vb(LLVertexBuffer::MAP_VERTEX);
+                }
+
+                mCubeVB->setBuffer();
+
+                LLGLDepthTest depth(GL_TRUE, GL_FALSE);
+                // mNearbyLights already includes distance calculation and excludes muted avatars.
                 // It is calculated from mLights
                 // mNearbyLights also provides fade value to gracefully fade-out out of range lights
                 S32 count = 0;
                 for (light_set_t::iterator iter = mNearbyLights.begin(); iter != mNearbyLights.end(); ++iter)
                 {
                     count++;
-                    if (count > local_light_count)
-                    { //stop collecting lights once we hit the limit
-                        break;
+                    if (count > local_light_count)
+                    { //stop collecting lights once we hit the limit
+                        break;
+                    }
+
+                    LLDrawable * drawablep = iter->drawable;
+                    LLVOVolume * volume = drawablep->getVOVolume();
+                    if (!volume)
+                    {
+                        continue;
+                    }
+
+                    if (volume->isAttachment())
+                    {
+                        if (!sRenderAttachedLights)
+                        {
+                            continue;
+                        }
+                    }
+
+                    LLVector4a center;
+                    center.load3(drawablep->getPositionAgent().mV);
+                    const F32 *c = center.getF32ptr();
+                    F32        s = volume->getLightRadius() * 1.5f;
+
+                    // send light color to shader in linear space
+                    LLColor3 col = volume->getLightLinearColor() * light_scale;
+
+                    if (col.magVecSquared() < 0.001f)
+                    {
+                        continue;
+                    }
+
+                    if (s <= 0.001f)
+                    {
+                        continue;
+                    }
+
+                    LLVector4a sa;
+                    sa.splat(s);
+                    if (camera->AABBInFrustumNoFarClip(center, sa) == 0)
+                    {
+                        continue;
+                    }
+
+                    sVisibleLightCount++;
+
+                    const auto& cam_origin = camera->getOrigin();
+                    if (cam_origin.mV[0] > c[0] + s + 0.2f || cam_origin.mV[0] < c[0] - s - 0.2f ||
+                        cam_origin.mV[1] > c[1] + s + 0.2f || cam_origin.mV[1] < c[1] - s - 0.2f ||
+                        cam_origin.mV[2] > c[2] + s + 0.2f || cam_origin.mV[2] < c[2] - s - 0.2f)
+                    {  // draw box if camera is outside box
+                        if (volume->isLightSpotlight())
+                        {
+                            drawablep->getVOVolume()->updateSpotLightPriority();
+                            spot_lights.push_back(drawablep);
+                            continue;
+                        }
+
+                        gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
+                        gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
+                        gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
+                        gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
+                        gGL.syncMatrices();
+
+                        mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center));
+                    }
+                    else
+                    {
+                        if (volume->isLightSpotlight())
+                        {
+                            drawablep->getVOVolume()->updateSpotLightPriority();
+                            fullscreen_spot_lights.push_back(drawablep);
+                            continue;
+                        }
+
+                        mat.affineTransform(center,center);
+
+                        LLVector4 tc(center.getF32ptr());
+                        tc.mV[VW] = s;
+                        fullscreen_lights.push_back(tc);
+                        light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF)));
+                    }
+                }
+
+                // Bookmark comment to allow searching for mSpecialRenderMode == 3 (avatar edit mode),
+                // prev site of appended deferred character light, removed by SL-13522 09/20
+
+                unbindDeferredShader(gDeferredLightProgram);
+            }
+
+            if (!spot_lights.empty())
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - projectors");
+                LL_PROFILE_GPU_ZONE("projectors");
+                LLGLDepthTest depth(GL_TRUE, GL_FALSE);
+                bindDeferredShader(gDeferredSpotLightProgram);
+
+                mCubeVB->setBuffer();
+
+                gDeferredSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
+
+                for (LLDrawable* drawablep : spot_lights)
+                {
+
+                    LLVOVolume *volume = drawablep->getVOVolume();
+
+                    LLVector4a center;
+                    center.load3(drawablep->getPositionAgent().mV);
+                    const F32* c = center.getF32ptr();
+                    F32        s = volume->getLightRadius() * 1.5f;
+
+                    sVisibleLightCount++;
+
+                    setupSpotLight(gDeferredSpotLightProgram, drawablep);
+
+                    // send light color to shader in linear space
+                    LLColor3 col = volume->getLightLinearColor() * light_scale;
+
+                    gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
+                    gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
+                    gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
+                    gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
+                    gGL.syncMatrices();
+
+                    mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center));
+                }
+                gDeferredSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION);
+                unbindDeferredShader(gDeferredSpotLightProgram);
+            }
+
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - fullscreen lights");
+                LLGLDepthTest depth(GL_FALSE);
+                LL_PROFILE_GPU_ZONE("fullscreen lights");
+
+                U32 count = 0;
+
+                const U32 max_count = LL_DEFERRED_MULTI_LIGHT_COUNT;
+                LLVector4 light[max_count];
+                LLVector4 col[max_count];
+
+                F32 far_z = 0.f;
+
+                while (!fullscreen_lights.empty())
+                {
+                    light[count] = fullscreen_lights.front();
+                    fullscreen_lights.pop_front();
+                    col[count] = light_colors.front();
+                    light_colors.pop_front();
+
+                    far_z = llmin(light[count].mV[2] - light[count].mV[3], far_z);
+                    count++;
+                    if (count == max_count || fullscreen_lights.empty())
+                    {
+                        U32 idx = count - 1;
+                        bindDeferredShader(gDeferredMultiLightProgram[idx]);
+                        gDeferredMultiLightProgram[idx].uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count);
+                        gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*)light);
+                        gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*)col);
+                        gDeferredMultiLightProgram[idx].uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z);
+                        far_z = 0.f;
+                        count = 0;
+                        mScreenTriangleVB->setBuffer();
+                        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+                        unbindDeferredShader(gDeferredMultiLightProgram[idx]);
                     }
+                }
+
+                bindDeferredShader(gDeferredMultiSpotLightProgram);
+
+                gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
+
+                mScreenTriangleVB->setBuffer();
+
+                for (LLDrawable::drawable_list_t::iterator iter = fullscreen_spot_lights.begin(); iter != fullscreen_spot_lights.end(); ++iter)
+                {
+                    LLDrawable *drawablep           = *iter;
+                    LLVOVolume *volume              = drawablep->getVOVolume();
+                    LLVector4a center;
+                    center.load3(drawablep->getPositionAgent().mV);
+
+                    F32         light_size_final    = volume->getLightRadius() * 1.5f;
+                    F32         light_falloff_final = volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF);
+
+                    sVisibleLightCount++;
+
+                    mat.affineTransform(center,center);
+
+                    setupSpotLight(gDeferredMultiSpotLightProgram, drawablep);
+
+                    // send light color to shader in linear space
+                    LLColor3 col = volume->getLightLinearColor() * light_scale;
+
+                    gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, center.getF32ptr());
+                    gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, light_size_final);
+                    gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
+                    gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, light_falloff_final);
+                    mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+                }
+
+                gDeferredMultiSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION);
+                unbindDeferredShader(gDeferredMultiSpotLightProgram);
+            }
+        }
+
+        gGL.setColorMask(true, true);
+    }
+
+    {  // render non-deferred geometry (alpha, fullbright, glow)
+        LLGLDisable blend(GL_BLEND);
+
+        pushRenderTypeMask();
+        andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA,
+                          LLPipeline::RENDER_TYPE_ALPHA_PRE_WATER,
+                          LLPipeline::RENDER_TYPE_ALPHA_POST_WATER,
+                          LLPipeline::RENDER_TYPE_FULLBRIGHT,
+                          LLPipeline::RENDER_TYPE_VOLUME,
+                          LLPipeline::RENDER_TYPE_GLOW,
+                          LLPipeline::RENDER_TYPE_BUMP,
+                          LLPipeline::RENDER_TYPE_GLTF_PBR,
+                          LLPipeline::RENDER_TYPE_PASS_SIMPLE,
+                          LLPipeline::RENDER_TYPE_PASS_ALPHA,
+                          LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK,
+                          LLPipeline::RENDER_TYPE_PASS_BUMP,
+                          LLPipeline::RENDER_TYPE_PASS_POST_BUMP,
+                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT,
+                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
+                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
+                          LLPipeline::RENDER_TYPE_PASS_GLOW,
+                          LLPipeline::RENDER_TYPE_PASS_GLTF_GLOW,
+                          LLPipeline::RENDER_TYPE_PASS_GRASS,
+                          LLPipeline::RENDER_TYPE_PASS_SHINY,
+                          LLPipeline::RENDER_TYPE_PASS_INVISIBLE,
+                          LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY,
+                          LLPipeline::RENDER_TYPE_AVATAR,
+                          LLPipeline::RENDER_TYPE_CONTROL_AV,
+                          LLPipeline::RENDER_TYPE_ALPHA_MASK,
+                          LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK,
+                          LLPipeline::RENDER_TYPE_TERRAIN,
+                          LLPipeline::RENDER_TYPE_WATER,
+                          END_RENDER_TYPES);
+
+        renderGeomPostDeferred(*LLViewerCamera::getInstance());
+        popRenderTypeMask();
+    }
+
+    screen_target->flush();
+
+    if (!gCubeSnapshot)
+    {
+        // this is the end of the 3D scene render, grab a copy of the modelview and projection
+        // matrix for use in off-by-one-frame effects in the next frame
+        {
+            gGLLastModelView = gGLModelView;
+            gGLLastProjection = gGLProjection;
+        }
+    }
+    gGL.setColorMask(true, true);
+}
+
+void LLPipeline::doAtmospherics()
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+
+    if (sImpostorRender)
+    { // do not attempt atmospherics on impostors
+        return;
+    }
+
+    if (RenderDeferredAtmospheric)
+    {
+        {
+            // copy depth buffer for use in haze shader (use water displacement map as temp storage)
+            LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
+
+            LLRenderTarget& src = gPipeline.mRT->screen;
+            LLRenderTarget& depth_src = gPipeline.mRT->deferredScreen;
+            LLRenderTarget& dst = gPipeline.mWaterDis;
+
+            mRT->screen.flush();
+            dst.bindTarget();
+            gCopyDepthProgram.bind();
+
+            S32 diff_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
+            S32 depth_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
+
+            gGL.getTexUnit(diff_map)->bind(&src);
+            gGL.getTexUnit(depth_map)->bind(&depth_src, true);
+
+            gGL.setColorMask(false, false);
+            gPipeline.mScreenTriangleVB->setBuffer();
+            gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+            dst.flush();
+            mRT->screen.bindTarget();
+        }
+
+        LLGLEnable blend(GL_BLEND);
+        gGL.blendFunc(LLRender::BF_ONE, LLRender::BF_SOURCE_ALPHA, LLRender::BF_ZERO, LLRender::BF_SOURCE_ALPHA);
+        gGL.setColorMask(true, true);
+
+        // apply haze
+        LLGLSLShader& haze_shader = gHazeProgram;
+
+        LL_PROFILE_GPU_ZONE("haze");
+        bindDeferredShader(haze_shader, nullptr, &mWaterDis);
+
+        LLEnvironment& environment = LLEnvironment::instance();
+        haze_shader.uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0);
+        haze_shader.uniform3fv(LLShaderMgr::LIGHTNORM, 1, environment.getClampedLightNorm().mV);
+
+        haze_shader.uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, LLDrawPoolAlpha::sWaterPlane.mV);
+
+        LLGLDepthTest depth(GL_FALSE);
+
+        // full screen blit
+        mScreenTriangleVB->setBuffer();
+        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+        unbindDeferredShader(haze_shader);
+
+        gGL.setSceneBlendType(LLRender::BT_ALPHA);
+    }
+}
+
+void LLPipeline::doWaterHaze()
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+    if (sImpostorRender)
+    { // do not attempt water haze on impostors
+        return;
+    }
+
+    if (RenderDeferredAtmospheric)
+    {
+        // copy depth buffer for use in haze shader (use water displacement map as temp storage)
+        {
+            LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
+
+            LLRenderTarget& src = gPipeline.mRT->screen;
+            LLRenderTarget& depth_src = gPipeline.mRT->deferredScreen;
+            LLRenderTarget& dst = gPipeline.mWaterDis;
+
+            mRT->screen.flush();
+            dst.bindTarget();
+            gCopyDepthProgram.bind();
+
+            S32 diff_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
+            S32 depth_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
+
+            gGL.getTexUnit(diff_map)->bind(&src);
+            gGL.getTexUnit(depth_map)->bind(&depth_src, true);
+
+            gGL.setColorMask(false, false);
+            gPipeline.mScreenTriangleVB->setBuffer();
+            gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+
+            dst.flush();
+            mRT->screen.bindTarget();
+        }
+
+        LLGLEnable blend(GL_BLEND);
+        gGL.blendFunc(LLRender::BF_ONE, LLRender::BF_SOURCE_ALPHA, LLRender::BF_ZERO, LLRender::BF_SOURCE_ALPHA);
+
+        gGL.setColorMask(true, true);
+
+        // apply haze
+        LLGLSLShader& haze_shader = gHazeWaterProgram;
+
+        LL_PROFILE_GPU_ZONE("haze");
+        bindDeferredShader(haze_shader, nullptr, &mWaterDis);
+
+        haze_shader.uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, LLDrawPoolAlpha::sWaterPlane.mV);
+
+        static LLStaticHashedString above_water_str("above_water");
+        haze_shader.uniform1i(above_water_str, sUnderWaterRender ? -1 : 1);
+
+        if (LLPipeline::sUnderWaterRender)
+        {
+            LLGLDepthTest depth(GL_FALSE);
+
+            // full screen blit
+            mScreenTriangleVB->setBuffer();
+            mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+        }
+        else
+        {
+            //render water patches like LLDrawPoolWater does
+            LLGLDepthTest depth(GL_TRUE, GL_FALSE);
+            LLGLDisable   cull(GL_CULL_FACE);
+
+            gGLLastMatrix = NULL;
+            gGL.loadMatrix(gGLModelView);
+
+            if (mWaterPool)
+            {
+                mWaterPool->pushFaceGeometry();
+            }
+        }
+
+        unbindDeferredShader(haze_shader);
+
+
+        gGL.setSceneBlendType(LLRender::BT_ALPHA);
+    }
+}
+
+void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep)
+{
+    //construct frustum
+    LLVOVolume* volume = drawablep->getVOVolume();
+    LLVector3 params = volume->getSpotLightParams();
+
+    F32 fov = params.mV[0];
+    F32 focus = params.mV[1];
+
+    LLVector3 pos = drawablep->getPositionAgent();
+    LLQuaternion quat = volume->getRenderRotation();
+    LLVector3 scale = volume->getScale();
+
+    //get near clip plane
+    LLVector3 at_axis(0,0,-scale.mV[2]*0.5f);
+    at_axis *= quat;
+
+    LLVector3 np = pos+at_axis;
+    at_axis.normVec();
+
+    //get origin that has given fov for plane np, at_axis, and given scale
+    F32 dist = (scale.mV[1]*0.5f)/tanf(fov*0.5f);
+
+    LLVector3 origin = np - at_axis*dist;
+
+    //matrix from volume space to agent space
+    LLMatrix4 light_mat(quat, LLVector4(origin,1.f));
+
+    glh::matrix4f light_to_agent((F32*) light_mat.mMatrix);
+    glh::matrix4f light_to_screen = glh::matrix4f((F32*)get_current_modelview().getF32ptr()) * light_to_agent;
+
+    glh::matrix4f screen_to_light = light_to_screen.inverse();
+
+    F32 s = volume->getLightRadius()*1.5f;
+    F32 near_clip = dist;
+    F32 width = scale.mV[VX];
+    F32 height = scale.mV[VY];
+    F32 far_clip = s+dist-scale.mV[VZ];
+
+    F32 fovy = fov * RAD_TO_DEG;
+    F32 aspect = width/height;
+
+    glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f,
+                0.f, 0.5f, 0.f, 0.5f,
+                0.f, 0.f, 0.5f, 0.5f,
+                0.f, 0.f, 0.f, 1.f);
+
+    glh::vec3f p1(0, 0, -(near_clip+0.01f));
+    glh::vec3f p2(0, 0, -(near_clip+1.f));
+
+    glh::vec3f screen_origin(0, 0, 0);
+
+    light_to_screen.mult_matrix_vec(p1);
+    light_to_screen.mult_matrix_vec(p2);
+    light_to_screen.mult_matrix_vec(screen_origin);
+
+    glh::vec3f n = p2-p1;
+    n.normalize();
+
+    F32 proj_range = far_clip - near_clip;
+    glh::matrix4f light_proj = gl_perspective(fovy, aspect, near_clip, far_clip);
+    screen_to_light = trans * light_proj * screen_to_light;
+    shader.uniformMatrix4fv(LLShaderMgr::PROJECTOR_MATRIX, 1, FALSE, screen_to_light.m);
+    shader.uniform1f(LLShaderMgr::PROJECTOR_NEAR, near_clip);
+    shader.uniform3fv(LLShaderMgr::PROJECTOR_P, 1, p1.v);
+    shader.uniform3fv(LLShaderMgr::PROJECTOR_N, 1, n.v);
+    shader.uniform3fv(LLShaderMgr::PROJECTOR_ORIGIN, 1, screen_origin.v);
+    shader.uniform1f(LLShaderMgr::PROJECTOR_RANGE, proj_range);
+    shader.uniform1f(LLShaderMgr::PROJECTOR_AMBIANCE, params.mV[2]);
+    S32 s_idx = -1;
+
+    for (U32 i = 0; i < 2; i++)
+    {
+        if (mShadowSpotLight[i] == drawablep)
+        {
+            s_idx = i;
+        }
+    }
+
+    shader.uniform1i(LLShaderMgr::PROJECTOR_SHADOW_INDEX, s_idx);
+
+    if (s_idx >= 0)
+    {
+        shader.uniform1f(LLShaderMgr::PROJECTOR_SHADOW_FADE, 1.f-mSpotLightFade[s_idx]);
+    }
+    else
+    {
+        shader.uniform1f(LLShaderMgr::PROJECTOR_SHADOW_FADE, 1.f);
+    }
+
+    // make sure we're not already targeting the same spot light with both shadow maps
+    llassert(mTargetShadowSpotLight[0] != mTargetShadowSpotLight[1] || mTargetShadowSpotLight[0].isNull());
+
+    if (!gCubeSnapshot)
+    {
+        LLDrawable* potential = drawablep;
+        //determine if this light is higher priority than one of the existing spot shadows
+        F32 m_pri = volume->getSpotLightPriority();
+
+        for (U32 i = 0; i < 2; i++)
+        {
+            F32 pri = 0.f;
+
+            if (mTargetShadowSpotLight[i].notNull())
+            {
+                pri = mTargetShadowSpotLight[i]->getVOVolume()->getSpotLightPriority();
+            }
+
+            if (m_pri > pri)
+            {
+                LLDrawable* temp = mTargetShadowSpotLight[i];
+                mTargetShadowSpotLight[i] = potential;
+                potential = temp;
+                m_pri = pri;
+            }
+        }
+    }
+
+    // make sure we didn't end up targeting the same spot light with both shadow maps
+    llassert(mTargetShadowSpotLight[0] != mTargetShadowSpotLight[1] || mTargetShadowSpotLight[0].isNull());
+
+    LLViewerTexture* img = volume->getLightTexture();
+
+    if (img == NULL)
+    {
+        img = LLViewerFetchedTexture::sWhiteImagep;
+    }
+
+    S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
+
+    if (channel > -1)
+    {
+        if (img)
+        {
+            gGL.getTexUnit(channel)->bind(img);
+
+            F32 lod_range = logf(img->getWidth())/logf(2.f);
+
+            shader.uniform1f(LLShaderMgr::PROJECTOR_FOCUS, focus);
+            shader.uniform1f(LLShaderMgr::PROJECTOR_LOD, lod_range);
+            shader.uniform1f(LLShaderMgr::PROJECTOR_AMBIENT_LOD, llclamp((proj_range-focus)/proj_range*lod_range, 0.f, 1.f));
+        }
+    }
+
+}
+
+void LLPipeline::unbindDeferredShader(LLGLSLShader &shader)
+{
+    LLRenderTarget* deferred_target       = &mRT->deferredScreen;
+    LLRenderTarget* deferred_light_target = &mRT->deferredLight;
+
+    stop_glerror();
+    shader.disableTexture(LLShaderMgr::DEFERRED_NORMAL, deferred_target->getUsage());
+    shader.disableTexture(LLShaderMgr::DEFERRED_DIFFUSE, deferred_target->getUsage());
+    shader.disableTexture(LLShaderMgr::DEFERRED_SPECULAR, deferred_target->getUsage());
+    shader.disableTexture(LLShaderMgr::DEFERRED_EMISSIVE, deferred_target->getUsage());
+    shader.disableTexture(LLShaderMgr::DEFERRED_BRDF_LUT);
+    //shader.disableTexture(LLShaderMgr::DEFERRED_DEPTH, deferred_depth_target->getUsage());
+    shader.disableTexture(LLShaderMgr::DEFERRED_DEPTH, deferred_target->getUsage());
+    shader.disableTexture(LLShaderMgr::DEFERRED_LIGHT, deferred_light_target->getUsage());
+    shader.disableTexture(LLShaderMgr::DIFFUSE_MAP);
+    shader.disableTexture(LLShaderMgr::DEFERRED_BLOOM);
+
+    for (U32 i = 0; i < 4; i++)
+    {
+        if (shader.disableTexture(LLShaderMgr::DEFERRED_SHADOW0+i) > -1)
+        {
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
+        }
+    }
+
+    for (U32 i = 4; i < 6; i++)
+    {
+        if (shader.disableTexture(LLShaderMgr::DEFERRED_SHADOW0+i) > -1)
+        {
+            glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
+        }
+    }
+
+    shader.disableTexture(LLShaderMgr::DEFERRED_NOISE);
+    shader.disableTexture(LLShaderMgr::DEFERRED_LIGHTFUNC);
+
+    if (!LLPipeline::sReflectionProbesEnabled)
+    {
+        S32 channel = shader.disableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
+        if (channel > -1)
+        {
+            LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
+            if (cube_map)
+            {
+                cube_map->disable();
+            }
+        }
+    }
+
+    unbindReflectionProbes(shader);
+
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+    gGL.getTexUnit(0)->activate();
+    shader.unbind();
+}
+
+void LLPipeline::setEnvMat(LLGLSLShader& shader)
+{
+    F32* m = gGLModelView.getF32ptr();
 
-                    LLDrawable * drawablep = iter->drawable;
-                    LLVOVolume * volume = drawablep->getVOVolume();
-                    if (!volume)
-                    {
-                        continue;
-                    }
+    F32 mat[] = { m[0], m[1], m[2],
+                    m[4], m[5], m[6],
+                    m[8], m[9], m[10] };
 
-                    if (volume->isAttachment())
-                    {
-                        if (!sRenderAttachedLights)
-                        {
-                            continue;
-                        }
-                    }
+    shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_ENV_MAT, 1, TRUE, mat);
+}
 
-                    LLVector4a center;
-                    center.load3(drawablep->getPositionAgent().mV);
-                    const F32 *c = center.getF32ptr();
-                    F32        s = volume->getLightRadius() * 1.5f;
+void LLPipeline::bindReflectionProbes(LLGLSLShader& shader)
+{
+    if (!sReflectionProbesEnabled)
+    {
+        return;
+    }
 
-                    // send light color to shader in linear space
-                    LLColor3 col = volume->getLightLinearColor() * light_scale;
+    S32 channel = shader.enableTexture(LLShaderMgr::REFLECTION_PROBES, LLTexUnit::TT_CUBE_MAP_ARRAY);
+    bool bound = false;
+    if (channel > -1 && mReflectionMapManager.mTexture.notNull())
+    {
+        mReflectionMapManager.mTexture->bind(channel);
+        bound = true;
+    }
 
-                    if (col.magVecSquared() < 0.001f)
-                    {
-                        continue;
-                    }
+    channel = shader.enableTexture(LLShaderMgr::IRRADIANCE_PROBES, LLTexUnit::TT_CUBE_MAP_ARRAY);
+    if (channel > -1 && mReflectionMapManager.mIrradianceMaps.notNull())
+    {
+        mReflectionMapManager.mIrradianceMaps->bind(channel);
+        bound = true;
+    }
 
-                    if (s <= 0.001f)
-                    {
-                        continue;
-                    }
+    if (RenderMirrors)
+    {
+        channel = shader.enableTexture(LLShaderMgr::HERO_PROBE, LLTexUnit::TT_CUBE_MAP_ARRAY);
+        if (channel > -1 && mHeroProbeManager.mTexture.notNull())
+        {
+            mHeroProbeManager.mTexture->bind(channel);
+            bound = true;
+        }
+    }
 
-                    LLVector4a sa;
-                    sa.splat(s);
-                    if (camera->AABBInFrustumNoFarClip(center, sa) == 0)
-                    {
-                        continue;
-                    }
 
-                    sVisibleLightCount++;
+    if (bound)
+    {
+        mReflectionMapManager.setUniforms();
 
-					const auto& cam_origin = camera->getOrigin();
-                    if (cam_origin.mV[0] > c[0] + s + 0.2f || cam_origin.mV[0] < c[0] - s - 0.2f ||
-                        cam_origin.mV[1] > c[1] + s + 0.2f || cam_origin.mV[1] < c[1] - s - 0.2f ||
-                        cam_origin.mV[2] > c[2] + s + 0.2f || cam_origin.mV[2] < c[2] - s - 0.2f)
-                    {  // draw box if camera is outside box
-                        if (volume->isLightSpotlight())
-                        {
-                            drawablep->getVOVolume()->updateSpotLightPriority();
-                            spot_lights.push_back(drawablep);
-                            continue;
-                        }
+        setEnvMat(shader);
+    }
 
-                        gDeferredLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
-                        gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
-                        gDeferredLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
-                        gDeferredLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
-                        gGL.syncMatrices();
+    // reflection probe shaders generally sample the scene map as well for SSR
+    channel = shader.enableTexture(LLShaderMgr::SCENE_MAP);
+    if (channel > -1)
+    {
+        gGL.getTexUnit(channel)->bind(&mSceneMap);
+    }
 
-                        mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center));
-                    }
-                    else
-                    {
-                        if (volume->isLightSpotlight())
-                        {
-                            drawablep->getVOVolume()->updateSpotLightPriority();
-                            fullscreen_spot_lights.push_back(drawablep);
-                            continue;
-                        }
 
-                        mat.affineTransform(center,center);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_ITR_COUNT, RenderScreenSpaceReflectionIterations);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_DIST_BIAS, RenderScreenSpaceReflectionDistanceBias);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_RAY_STEP, RenderScreenSpaceReflectionRayStep);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_GLOSSY_SAMPLES, RenderScreenSpaceReflectionGlossySamples);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_REJECT_BIAS, RenderScreenSpaceReflectionDepthRejectBias);
+    mPoissonOffset++;
 
-						LLVector4 tc(center.getF32ptr());
-						tc.mV[VW] = s;
-                        fullscreen_lights.push_back(tc);
-                        light_colors.push_back(LLVector4(col.mV[0], col.mV[1], col.mV[2], volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF)));
-                    }
-                }
+    if (mPoissonOffset > 128 - RenderScreenSpaceReflectionGlossySamples)
+        mPoissonOffset = 0;
 
-                // Bookmark comment to allow searching for mSpecialRenderMode == 3 (avatar edit mode),
-                // prev site of appended deferred character light, removed by SL-13522 09/20
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_NOISE_SINE, mPoissonOffset);
+    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_ADAPTIVE_STEP_MULT, RenderScreenSpaceReflectionAdaptiveStepMultiplier);
 
-                unbindDeferredShader(gDeferredLightProgram);
-            }
+    channel = shader.enableTexture(LLShaderMgr::SCENE_DEPTH);
+    if (channel > -1)
+    {
+        gGL.getTexUnit(channel)->bind(&mSceneMap, true);
+    }
 
-            if (!spot_lights.empty())
-            {
-                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - projectors");
-                LL_PROFILE_GPU_ZONE("projectors");
-                LLGLDepthTest depth(GL_TRUE, GL_FALSE);
-                bindDeferredShader(gDeferredSpotLightProgram);
 
-                mCubeVB->setBuffer();
+}
 
-                gDeferredSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
+void LLPipeline::unbindReflectionProbes(LLGLSLShader& shader)
+{
+    S32 channel = shader.disableTexture(LLShaderMgr::REFLECTION_PROBES, LLTexUnit::TT_CUBE_MAP);
+    if (channel > -1 && mReflectionMapManager.mTexture.notNull())
+    {
+        mReflectionMapManager.mTexture->unbind();
+        if (channel == 0)
+        {
+            gGL.getTexUnit(channel)->enable(LLTexUnit::TT_TEXTURE);
+        }
+    }
+}
 
-				for (LLDrawable* drawablep : spot_lights)
-                {
 
-                    LLVOVolume *volume = drawablep->getVOVolume();
+inline float sgn(float a)
+{
+    if (a > 0.0F) return (1.0F);
+    if (a < 0.0F) return (-1.0F);
+    return (0.0F);
+}
 
-                    LLVector4a center;
-                    center.load3(drawablep->getPositionAgent().mV);
-                    const F32* c = center.getF32ptr();
-                    F32        s = volume->getLightRadius() * 1.5f;
+glh::matrix4f look(const LLVector3 pos, const LLVector3 dir, const LLVector3 up)
+{
+    glh::matrix4f ret;
 
-                    sVisibleLightCount++;
+    LLVector3 dirN;
+    LLVector3 upN;
+    LLVector3 lftN;
 
-                    setupSpotLight(gDeferredSpotLightProgram, drawablep);
+    lftN = dir % up;
+    lftN.normVec();
 
-                    // send light color to shader in linear space
-                    LLColor3 col = volume->getLightLinearColor() * light_scale;
+    upN = lftN % dir;
+    upN.normVec();
 
-                    gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, c);
-                    gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, s);
-                    gDeferredSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
-                    gDeferredSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF));
-                    gGL.syncMatrices();
+    dirN = dir;
+    dirN.normVec();
 
-                    mCubeVB->drawRange(LLRender::TRIANGLE_FAN, 0, 7, 8, get_box_fan_indices(camera, center));
-                }
-                gDeferredSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION);
-                unbindDeferredShader(gDeferredSpotLightProgram);
-            }
+    ret.m[ 0] = lftN[0];
+    ret.m[ 1] = upN[0];
+    ret.m[ 2] = -dirN[0];
+    ret.m[ 3] = 0.f;
 
-            {
-                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("renderDeferredLighting - fullscreen lights");
-                LLGLDepthTest depth(GL_FALSE);
-                LL_PROFILE_GPU_ZONE("fullscreen lights");
+    ret.m[ 4] = lftN[1];
+    ret.m[ 5] = upN[1];
+    ret.m[ 6] = -dirN[1];
+    ret.m[ 7] = 0.f;
 
-                U32 count = 0;
+    ret.m[ 8] = lftN[2];
+    ret.m[ 9] = upN[2];
+    ret.m[10] = -dirN[2];
+    ret.m[11] = 0.f;
 
-                const U32 max_count = LL_DEFERRED_MULTI_LIGHT_COUNT;
-                LLVector4 light[max_count];
-                LLVector4 col[max_count];
+    ret.m[12] = -(lftN*pos);
+    ret.m[13] = -(upN*pos);
+    ret.m[14] = dirN*pos;
+    ret.m[15] = 1.f;
 
-                F32 far_z = 0.f;
+    return ret;
+}
 
-                while (!fullscreen_lights.empty())
-                {
-                    light[count] = fullscreen_lights.front();
-                    fullscreen_lights.pop_front();
-                    col[count] = light_colors.front();
-                    light_colors.pop_front();
+glh::matrix4f scale_translate_to_fit(const LLVector3 min, const LLVector3 max)
+{
+    glh::matrix4f ret;
+    ret.m[ 0] = 2/(max[0]-min[0]);
+    ret.m[ 4] = 0;
+    ret.m[ 8] = 0;
+    ret.m[12] = -(max[0]+min[0])/(max[0]-min[0]);
 
-                    far_z = llmin(light[count].mV[2] - light[count].mV[3], far_z);
-                    count++;
-                    if (count == max_count || fullscreen_lights.empty())
-                    {
-                        U32 idx = count - 1;
-                        bindDeferredShader(gDeferredMultiLightProgram[idx]);
-                        gDeferredMultiLightProgram[idx].uniform1i(LLShaderMgr::MULTI_LIGHT_COUNT, count);
-                        gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT, count, (GLfloat*)light);
-                        gDeferredMultiLightProgram[idx].uniform4fv(LLShaderMgr::MULTI_LIGHT_COL, count, (GLfloat*)col);
-                        gDeferredMultiLightProgram[idx].uniform1f(LLShaderMgr::MULTI_LIGHT_FAR_Z, far_z);
-                        far_z = 0.f;
-                        count = 0;
-                        mScreenTriangleVB->setBuffer();
-                        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-                        unbindDeferredShader(gDeferredMultiLightProgram[idx]);
-                    }
-                }
+    ret.m[ 1] = 0;
+    ret.m[ 5] = 2/(max[1]-min[1]);
+    ret.m[ 9] = 0;
+    ret.m[13] = -(max[1]+min[1])/(max[1]-min[1]);
 
-                bindDeferredShader(gDeferredMultiSpotLightProgram);
+    ret.m[ 2] = 0;
+    ret.m[ 6] = 0;
+    ret.m[10] = 2/(max[2]-min[2]);
+    ret.m[14] = -(max[2]+min[2])/(max[2]-min[2]);
 
-                gDeferredMultiSpotLightProgram.enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
+    ret.m[ 3] = 0;
+    ret.m[ 7] = 0;
+    ret.m[11] = 0;
+    ret.m[15] = 1;
 
-                mScreenTriangleVB->setBuffer();
+    return ret;
+}
 
-                for (LLDrawable::drawable_list_t::iterator iter = fullscreen_spot_lights.begin(); iter != fullscreen_spot_lights.end(); ++iter)
-                {
-                    LLDrawable *drawablep           = *iter;
-                    LLVOVolume *volume              = drawablep->getVOVolume();
-					LLVector4a center;
-					center.load3(drawablep->getPositionAgent().mV);
+static LLTrace::BlockTimerStatHandle FTM_SHADOW_RENDER("Render Shadows");
+static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA("Alpha Shadow");
+static LLTrace::BlockTimerStatHandle FTM_SHADOW_SIMPLE("Simple Shadow");
+static LLTrace::BlockTimerStatHandle FTM_SHADOW_GEOM("Shadow Geom");
 
-                    F32         light_size_final    = volume->getLightRadius() * 1.5f;
-                    F32         light_falloff_final = volume->getLightFalloff(DEFERRED_LIGHT_FALLOFF);
+static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_MASKED("Alpha Masked");
+static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_BLEND("Alpha Blend");
+static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_TREE("Alpha Tree");
+static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_GRASS("Alpha Grass");
+static LLTrace::BlockTimerStatHandle FTM_SHADOW_FULLBRIGHT_ALPHA_MASKED("Fullbright Alpha Masked");
 
-                    sVisibleLightCount++;
+void LLPipeline::renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& shadow_cam, LLCullResult& result, bool depth_clamp)
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; //LL_RECORD_BLOCK_TIME(FTM_SHADOW_RENDER);
+    LL_PROFILE_GPU_ZONE("renderShadow");
 
-                    mat.affineTransform(center,center);
+    LLPipeline::sShadowRender = true;
+
+    // disable occlusion culling during shadow render
+    U32 saved_occlusion = sUseOcclusion;
+    sUseOcclusion = 0;
+
+    // List of render pass types that use the prim volume as the shadow,
+    // ignoring textures.
+    static const U32 types[] = {
+        LLRenderPass::PASS_SIMPLE,
+        LLRenderPass::PASS_FULLBRIGHT,
+        LLRenderPass::PASS_SHINY,
+        LLRenderPass::PASS_BUMP,
+        LLRenderPass::PASS_FULLBRIGHT_SHINY,
+        LLRenderPass::PASS_MATERIAL,
+        LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE,
+        LLRenderPass::PASS_SPECMAP,
+        LLRenderPass::PASS_SPECMAP_EMISSIVE,
+        LLRenderPass::PASS_NORMMAP,
+        LLRenderPass::PASS_NORMMAP_EMISSIVE,
+        LLRenderPass::PASS_NORMSPEC,
+        LLRenderPass::PASS_NORMSPEC_EMISSIVE
+    };
 
-                    setupSpotLight(gDeferredMultiSpotLightProgram, drawablep);
+    LLGLEnable cull(GL_CULL_FACE);
 
-                    // send light color to shader in linear space
-                    LLColor3 col = volume->getLightLinearColor() * light_scale;
+    //enable depth clamping if available
+    LLGLEnable clamp_depth(depth_clamp ? GL_DEPTH_CLAMP : 0);
 
-                    gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::LIGHT_CENTER, 1, center.getF32ptr());
-                    gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_SIZE, light_size_final);
-                    gDeferredMultiSpotLightProgram.uniform3fv(LLShaderMgr::DIFFUSE_COLOR, 1, col.mV);
-                    gDeferredMultiSpotLightProgram.uniform1f(LLShaderMgr::LIGHT_FALLOFF, light_falloff_final);
-                    mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-                }
+    LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_LESS);
 
-                gDeferredMultiSpotLightProgram.disableTexture(LLShaderMgr::DEFERRED_PROJECTION);
-                unbindDeferredShader(gDeferredMultiSpotLightProgram);
-            }
-        }
+    updateCull(shadow_cam, result);
 
-        gGL.setColorMask(true, true);
-    }
+    stateSort(shadow_cam, result);
 
-    {  // render non-deferred geometry (alpha, fullbright, glow)
-        LLGLDisable blend(GL_BLEND);
+    //generate shadow map
+    gGL.matrixMode(LLRender::MM_PROJECTION);
+    gGL.pushMatrix();
+    gGL.loadMatrix(LLMatrix4a(proj.m));
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.pushMatrix();
+    gGL.loadMatrix(LLMatrix4a(view.m));
 
-        pushRenderTypeMask();
-        andRenderTypeMask(LLPipeline::RENDER_TYPE_ALPHA,
-                          LLPipeline::RENDER_TYPE_ALPHA_PRE_WATER,
-                          LLPipeline::RENDER_TYPE_ALPHA_POST_WATER,
-                          LLPipeline::RENDER_TYPE_FULLBRIGHT,
-                          LLPipeline::RENDER_TYPE_VOLUME,
-                          LLPipeline::RENDER_TYPE_GLOW,
-                          LLPipeline::RENDER_TYPE_BUMP,
-                          LLPipeline::RENDER_TYPE_GLTF_PBR,
-                          LLPipeline::RENDER_TYPE_PASS_SIMPLE,
-                          LLPipeline::RENDER_TYPE_PASS_ALPHA,
-                          LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK,
-                          LLPipeline::RENDER_TYPE_PASS_BUMP,
-                          LLPipeline::RENDER_TYPE_PASS_POST_BUMP,
-                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT,
-                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
-                          LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
-                          LLPipeline::RENDER_TYPE_PASS_GLOW,
-                          LLPipeline::RENDER_TYPE_PASS_GLTF_GLOW,
-                          LLPipeline::RENDER_TYPE_PASS_GRASS,
-                          LLPipeline::RENDER_TYPE_PASS_SHINY,
-                          LLPipeline::RENDER_TYPE_PASS_INVISIBLE,
-                          LLPipeline::RENDER_TYPE_PASS_INVISI_SHINY,
-                          LLPipeline::RENDER_TYPE_AVATAR,
-                          LLPipeline::RENDER_TYPE_CONTROL_AV,
-                          LLPipeline::RENDER_TYPE_ALPHA_MASK,
-                          LLPipeline::RENDER_TYPE_FULLBRIGHT_ALPHA_MASK,
-						  LLPipeline::RENDER_TYPE_TERRAIN,
-                          LLPipeline::RENDER_TYPE_WATER,
-                          END_RENDER_TYPES);
+    stop_glerror();
+    gGLLastMatrix = NULL;
 
-        renderGeomPostDeferred(*LLViewerCamera::getInstance());
-        popRenderTypeMask();
-    }
+    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
 
-    screen_target->flush();
+    stop_glerror();
 
-    if (!gCubeSnapshot)
+    struct CompareVertexBuffer
     {
-        // this is the end of the 3D scene render, grab a copy of the modelview and projection
-        // matrix for use in off-by-one-frame effects in the next frame
+        bool operator()(const LLDrawInfo* const& lhs, const LLDrawInfo* const& rhs)
         {
-            gGLLastModelView = gGLModelView;
-            gGLLastProjection = gGLProjection;
+            return lhs->mVertexBuffer > rhs->mVertexBuffer;
         }
-    }
-    gGL.setColorMask(true, true);
-}
-
-void LLPipeline::doAtmospherics()
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+    };
 
-    if (sImpostorRender)
-    { // do not attempt atmospherics on impostors
-        return;
-    }
 
-    if (RenderDeferredAtmospheric)
+    LLVertexBuffer::unbind();
+    for (int j = 0; j < 2; ++j) // 0 -- static, 1 -- rigged
     {
+        bool rigged = j == 1;
+        gDeferredShadowProgram.bind(rigged);
+
+        gGL.diffuseColor4f(1, 1, 1, 1);
+
+        // if not using VSM, disable color writes
+        if (LLPipeline::RenderShadowDetail <= 2)
         {
-            // copy depth buffer for use in haze shader (use water displacement map as temp storage)
-            LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
+            gGL.setColorMask(false, false);
+        }
 
-            LLRenderTarget& src = gPipeline.mRT->screen;
-            LLRenderTarget& depth_src = gPipeline.mRT->deferredScreen;
-            LLRenderTarget& dst = gPipeline.mWaterDis;
+        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow simple"); //LL_RECORD_BLOCK_TIME(FTM_SHADOW_SIMPLE);
+        LL_PROFILE_GPU_ZONE("shadow simple");
+        gGL.getTexUnit(0)->disable();
 
-            mRT->screen.flush();
-            dst.bindTarget();
-            gCopyDepthProgram.bind();
+        for (U32 type : types)
+        {
+            renderObjects(type, false, false, rigged);
+        }
 
-            S32 diff_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
-            S32 depth_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
+        renderGLTFObjects(LLRenderPass::PASS_GLTF_PBR, false, rigged);
 
-            gGL.getTexUnit(diff_map)->bind(&src);
-            gGL.getTexUnit(depth_map)->bind(&depth_src, true);
+        gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
+    }
 
-            gGL.setColorMask(false, false);
-            gPipeline.mScreenTriangleVB->setBuffer();
-            gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    if (LLPipeline::sUseOcclusion > 1)
+    { // do occlusion culling against non-masked only to take advantage of hierarchical Z
+        doOcclusion(shadow_cam);
+    }
 
-            dst.flush();
-            mRT->screen.bindTarget();
-        }
 
-        LLGLEnable blend(GL_BLEND);
-        gGL.blendFunc(LLRender::BF_ONE, LLRender::BF_SOURCE_ALPHA, LLRender::BF_ZERO, LLRender::BF_SOURCE_ALPHA);
-        gGL.setColorMask(true, true);
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow geom");
+        renderGeomShadow(shadow_cam);
+    }
 
-        // apply haze
-        LLGLSLShader& haze_shader = gHazeProgram;
+    {
+        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha");
+        LL_PROFILE_GPU_ZONE("shadow alpha");
+        const S32 sun_up = LLEnvironment::instance().getIsSunUp() ? 1 : 0;
+        U32 target_width = LLRenderTarget::sCurResX;
 
-        LL_PROFILE_GPU_ZONE("haze");
-        bindDeferredShader(haze_shader, nullptr, &mWaterDis);
+        for (int i = 0; i < 2; ++i)
+        {
+            bool rigged = i == 1;
 
-        LLEnvironment& environment = LLEnvironment::instance();
-        haze_shader.uniform1i(LLShaderMgr::SUN_UP_FACTOR, environment.getIsSunUp() ? 1 : 0);
-        haze_shader.uniform3fv(LLShaderMgr::LIGHTNORM, 1, environment.getClampedLightNorm().mV);
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha masked");
+                LL_PROFILE_GPU_ZONE("shadow alpha masked");
+                gDeferredShadowAlphaMaskProgram.bind(rigged);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
+                renderMaskedObjects(LLRenderPass::PASS_ALPHA_MASK, true, true, rigged);
+            }
 
-        haze_shader.uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, LLDrawPoolAlpha::sWaterPlane.mV);
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha blend");
+                LL_PROFILE_GPU_ZONE("shadow alpha blend");
+                renderAlphaObjects(rigged);
+            }
 
-        LLGLDepthTest depth(GL_FALSE);
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow fullbright alpha masked");
+                LL_PROFILE_GPU_ZONE("shadow alpha masked");
+                gDeferredShadowFullbrightAlphaMaskProgram.bind(rigged);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
+                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
+                renderFullbrightMaskedObjects(LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK, true, true, rigged);
+            }
 
-        // full screen blit
-        mScreenTriangleVB->setBuffer();
-        mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-    
-        unbindDeferredShader(haze_shader);
+            {
+                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha grass");
+                LL_PROFILE_GPU_ZONE("shadow alpha grass");
+                gDeferredTreeShadowProgram.bind(rigged);
+                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
 
-        gGL.setSceneBlendType(LLRender::BT_ALPHA);
-    }
-}
+                if (i == 0)
+                {
+                    renderObjects(LLRenderPass::PASS_GRASS, true);
+                }
 
-void LLPipeline::doWaterHaze()
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-    if (sImpostorRender)
-    { // do not attempt water haze on impostors
-        return;
-    }
+                {
+                    LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha material");
+                    LL_PROFILE_GPU_ZONE("shadow alpha material");
+                    renderMaskedObjects(LLRenderPass::PASS_NORMSPEC_MASK, true, false, rigged);
+                    renderMaskedObjects(LLRenderPass::PASS_MATERIAL_ALPHA_MASK, true, false, rigged);
+                    renderMaskedObjects(LLRenderPass::PASS_SPECMAP_MASK, true, false, rigged);
+                    renderMaskedObjects(LLRenderPass::PASS_NORMMAP_MASK, true, false, rigged);
+                }
+            }
+        }
 
-    if (RenderDeferredAtmospheric)
-    {
-        // copy depth buffer for use in haze shader (use water displacement map as temp storage)
+        for (int i = 0; i < 2; ++i)
         {
-            LLGLDepthTest depth(GL_TRUE, GL_TRUE, GL_ALWAYS);
+            bool rigged = i == 1;
+            gDeferredShadowGLTFAlphaMaskProgram.bind(rigged);
+            LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
+            LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
 
-            LLRenderTarget& src = gPipeline.mRT->screen;
-            LLRenderTarget& depth_src = gPipeline.mRT->deferredScreen;
-            LLRenderTarget& dst = gPipeline.mWaterDis;
+            gGL.loadMatrix(gGLModelView);
+            gGLLastMatrix = NULL;
 
-            mRT->screen.flush();
-            dst.bindTarget();
-            gCopyDepthProgram.bind();
+            U32 type = LLRenderPass::PASS_GLTF_PBR_ALPHA_MASK;
 
-            S32 diff_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DIFFUSE_MAP);
-            S32 depth_map = gCopyDepthProgram.getTextureChannel(LLShaderMgr::DEFERRED_DEPTH);
+            if (rigged)
+            {
+                mAlphaMaskPool->pushRiggedGLTFBatches(type + 1);
+            }
+            else
+            {
+                mAlphaMaskPool->pushGLTFBatches(type);
+            }
 
-            gGL.getTexUnit(diff_map)->bind(&src);
-            gGL.getTexUnit(depth_map)->bind(&depth_src, true);
+            gGL.loadMatrix(gGLModelView);
+            gGLLastMatrix = NULL;
+        }
+    }
 
-            gGL.setColorMask(false, false);
-            gPipeline.mScreenTriangleVB->setBuffer();
-            gPipeline.mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
+    gDeferredShadowCubeProgram.bind();
+    gGLLastMatrix = NULL;
+    gGL.loadMatrix(gGLModelView);
+
+    gGL.setColorMask(true, true);
+
+    gGL.matrixMode(LLRender::MM_PROJECTION);
+    gGL.popMatrix();
+    gGL.matrixMode(LLRender::MM_MODELVIEW);
+    gGL.popMatrix();
+    gGLLastMatrix = NULL;
 
-            dst.flush();
-            mRT->screen.bindTarget();
-        }
+    // reset occlusion culling flag
+    sUseOcclusion = saved_occlusion;
+    LLPipeline::sShadowRender = false;
+}
 
-        LLGLEnable blend(GL_BLEND);
-        gGL.blendFunc(LLRender::BF_ONE, LLRender::BF_SOURCE_ALPHA, LLRender::BF_ZERO, LLRender::BF_SOURCE_ALPHA);
+bool LLPipeline::getVisiblePointCloud(LLCamera& camera, LLVector3& min, LLVector3& max, std::vector<LLVector3>& fp, LLVector3 light_dir)
+{
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
+    //get point cloud of intersection of frust and min, max
 
-        gGL.setColorMask(true, true);
+    if (getVisibleExtents(camera, min, max))
+    {
+        return false;
+    }
 
-        // apply haze
-        LLGLSLShader& haze_shader = gHazeWaterProgram;
+    //get set of planes on bounding box
+    LLPlane bp[] = {
+        LLPlane(min, LLVector3(-1,0,0)),
+        LLPlane(min, LLVector3(0,-1,0)),
+        LLPlane(min, LLVector3(0,0,-1)),
+        LLPlane(max, LLVector3(1,0,0)),
+        LLPlane(max, LLVector3(0,1,0)),
+        LLPlane(max, LLVector3(0,0,1))};
+
+    //potential points
+    std::vector<LLVector3> pp;
+
+    //add corners of AABB
+    pp.push_back(LLVector3(min.mV[0], min.mV[1], min.mV[2]));
+    pp.push_back(LLVector3(max.mV[0], min.mV[1], min.mV[2]));
+    pp.push_back(LLVector3(min.mV[0], max.mV[1], min.mV[2]));
+    pp.push_back(LLVector3(max.mV[0], max.mV[1], min.mV[2]));
+    pp.push_back(LLVector3(min.mV[0], min.mV[1], max.mV[2]));
+    pp.push_back(LLVector3(max.mV[0], min.mV[1], max.mV[2]));
+    pp.push_back(LLVector3(min.mV[0], max.mV[1], max.mV[2]));
+    pp.push_back(LLVector3(max.mV[0], max.mV[1], max.mV[2]));
+
+    //add corners of camera frustum
+    for (U32 i = 0; i < LLCamera::AGENT_FRUSTRUM_NUM; i++)
+    {
+        pp.push_back(camera.mAgentFrustum[i]);
+    }
 
-        LL_PROFILE_GPU_ZONE("haze");
-        bindDeferredShader(haze_shader, nullptr, &mWaterDis);
 
-        haze_shader.uniform4fv(LLShaderMgr::WATER_WATERPLANE, 1, LLDrawPoolAlpha::sWaterPlane.mV);
+    //bounding box line segments
+    U32 bs[] =
+            {
+        0,1,
+        1,3,
+        3,2,
+        2,0,
+
+        4,5,
+        5,7,
+        7,6,
+        6,4,
+
+        0,4,
+        1,5,
+        3,7,
+        2,6
+    };
 
-        static LLStaticHashedString above_water_str("above_water");
-        haze_shader.uniform1i(above_water_str, sUnderWaterRender ? -1 : 1);
+    for (U32 i = 0; i < 12; i++)
+    { //for each line segment in bounding box
+        for (U32 j = 0; j < LLCamera::AGENT_PLANE_NO_USER_CLIP_NUM; j++)
+        { //for each plane in camera frustum
+            const LLPlane& cp = camera.getAgentPlane(j);
+            const LLVector3& v1 = pp[bs[i*2+0]];
+            const LLVector3& v2 = pp[bs[i*2+1]];
+            LLVector3 n;
+            cp.getVector3(n);
 
-        if (LLPipeline::sUnderWaterRender)
-        {
-            LLGLDepthTest depth(GL_FALSE);
+            LLVector3 line = v1-v2;
 
-            // full screen blit
-            mScreenTriangleVB->setBuffer();
-            mScreenTriangleVB->drawArrays(LLRender::TRIANGLES, 0, 3);
-        }
-        else
-        {
-            //render water patches like LLDrawPoolWater does
-            LLGLDepthTest depth(GL_TRUE, GL_FALSE);
-            LLGLDisable   cull(GL_CULL_FACE);
+            F32 d1 = line*n;
+            F32 d2 = -cp.dist(v2);
 
-            gGLLastMatrix = NULL;
-            gGL.loadMatrix(gGLModelView);
+            F32 t = d2/d1;
 
-            if (mWaterPool)
+            if (t > 0.f && t < 1.f)
             {
-                mWaterPool->pushFaceGeometry();
+                LLVector3 intersect = v2+line*t;
+                pp.push_back(intersect);
             }
         }
+    }
 
-        unbindDeferredShader(haze_shader);
+    //camera frustum line segments
+    const U32 fs[] =
+    {
+        0,1,
+        1,2,
+        2,3,
+        3,0,
+
+        4,5,
+        5,6,
+        6,7,
+        7,4,
+
+        0,4,
+        1,5,
+        2,6,
+        3,7
+    };
 
+    for (U32 i = 0; i < 12; i++)
+    {
+        for (U32 j = 0; j < 6; ++j)
+        {
+            const LLVector3& v1 = pp[fs[i*2+0]+8];
+            const LLVector3& v2 = pp[fs[i*2+1]+8];
+            const LLPlane& cp = bp[j];
+            LLVector3 n;
+            cp.getVector3(n);
 
-        gGL.setSceneBlendType(LLRender::BT_ALPHA);
-    }
-}
+            LLVector3 line = v1-v2;
 
-void LLPipeline::setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep)
-{
-	//construct frustum
-	LLVOVolume* volume = drawablep->getVOVolume();
-	LLVector3 params = volume->getSpotLightParams();
-
-	F32 fov = params.mV[0];
-	F32 focus = params.mV[1];
-
-	LLVector3 pos = drawablep->getPositionAgent();
-	LLQuaternion quat = volume->getRenderRotation();
-	LLVector3 scale = volume->getScale();
-	
-	//get near clip plane
-	LLVector3 at_axis(0,0,-scale.mV[2]*0.5f);
-	at_axis *= quat;
-
-	LLVector3 np = pos+at_axis;
-	at_axis.normVec();
-
-	//get origin that has given fov for plane np, at_axis, and given scale
-	F32 dist = (scale.mV[1]*0.5f)/tanf(fov*0.5f);
-
-	LLVector3 origin = np - at_axis*dist;
-
-	//matrix from volume space to agent space
-	LLMatrix4 light_mat(quat, LLVector4(origin,1.f));
-
-	glh::matrix4f light_to_agent((F32*) light_mat.mMatrix);
-	glh::matrix4f light_to_screen = glh::matrix4f((F32*)get_current_modelview().getF32ptr()) * light_to_agent;
-
-	glh::matrix4f screen_to_light = light_to_screen.inverse();
-
-	F32 s = volume->getLightRadius()*1.5f;
-	F32 near_clip = dist;
-	F32 width = scale.mV[VX];
-	F32 height = scale.mV[VY];
-	F32 far_clip = s+dist-scale.mV[VZ];
-
-	F32 fovy = fov * RAD_TO_DEG;
-	F32 aspect = width/height;
-
-	glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f,
-				0.f, 0.5f, 0.f, 0.5f,
-				0.f, 0.f, 0.5f, 0.5f,
-				0.f, 0.f, 0.f, 1.f);
-
-	glh::vec3f p1(0, 0, -(near_clip+0.01f));
-	glh::vec3f p2(0, 0, -(near_clip+1.f));
-
-	glh::vec3f screen_origin(0, 0, 0);
-
-	light_to_screen.mult_matrix_vec(p1);
-	light_to_screen.mult_matrix_vec(p2);
-	light_to_screen.mult_matrix_vec(screen_origin);
-
-	glh::vec3f n = p2-p1;
-	n.normalize();
-	
-	F32 proj_range = far_clip - near_clip;
-	glh::matrix4f light_proj = gl_perspective(fovy, aspect, near_clip, far_clip);
-	screen_to_light = trans * light_proj * screen_to_light;
-	shader.uniformMatrix4fv(LLShaderMgr::PROJECTOR_MATRIX, 1, FALSE, screen_to_light.m);
-	shader.uniform1f(LLShaderMgr::PROJECTOR_NEAR, near_clip);
-	shader.uniform3fv(LLShaderMgr::PROJECTOR_P, 1, p1.v);
-	shader.uniform3fv(LLShaderMgr::PROJECTOR_N, 1, n.v);
-	shader.uniform3fv(LLShaderMgr::PROJECTOR_ORIGIN, 1, screen_origin.v);
-	shader.uniform1f(LLShaderMgr::PROJECTOR_RANGE, proj_range);
-	shader.uniform1f(LLShaderMgr::PROJECTOR_AMBIANCE, params.mV[2]);
-	S32 s_idx = -1;
-
-	for (U32 i = 0; i < 2; i++)
-	{
-		if (mShadowSpotLight[i] == drawablep)
-		{
-			s_idx = i;
-		}
-	}
-
-	shader.uniform1i(LLShaderMgr::PROJECTOR_SHADOW_INDEX, s_idx);
-
-	if (s_idx >= 0)
-	{
-		shader.uniform1f(LLShaderMgr::PROJECTOR_SHADOW_FADE, 1.f-mSpotLightFade[s_idx]);
-	}
-	else
-	{
-		shader.uniform1f(LLShaderMgr::PROJECTOR_SHADOW_FADE, 1.f);
-	}
+            F32 d1 = line*n;
+            F32 d2 = -cp.dist(v2);
 
-    // make sure we're not already targeting the same spot light with both shadow maps
-    llassert(mTargetShadowSpotLight[0] != mTargetShadowSpotLight[1] || mTargetShadowSpotLight[0].isNull());
+            F32 t = d2/d1;
 
-    if (!gCubeSnapshot)
-	{
-		LLDrawable* potential = drawablep;
-		//determine if this light is higher priority than one of the existing spot shadows
-		F32 m_pri = volume->getSpotLightPriority();
-
-		for (U32 i = 0; i < 2; i++)
-		{
-			F32 pri = 0.f;
-
-			if (mTargetShadowSpotLight[i].notNull())
-			{
-				pri = mTargetShadowSpotLight[i]->getVOVolume()->getSpotLightPriority();
-			}
-
-			if (m_pri > pri)
-			{
-				LLDrawable* temp = mTargetShadowSpotLight[i];
-				mTargetShadowSpotLight[i] = potential;
-				potential = temp;
-				m_pri = pri;
-			}
-		}
-	}
+            if (t > 0.f && t < 1.f)
+            {
+                LLVector3 intersect = v2+line*t;
+                pp.push_back(intersect);
+            }
+        }
+    }
 
-    // make sure we didn't end up targeting the same spot light with both shadow maps
-    llassert(mTargetShadowSpotLight[0] != mTargetShadowSpotLight[1] || mTargetShadowSpotLight[0].isNull());
+    LLVector3 ext[] = { min-LLVector3(0.05f,0.05f,0.05f),
+        max+LLVector3(0.05f,0.05f,0.05f) };
+
+    for (U32 i = 0; i < pp.size(); ++i)
+    {
+        bool found = true;
 
-	LLViewerTexture* img = volume->getLightTexture();
+        const F32* p = pp[i].mV;
 
-	if (img == NULL)
-	{
-		img = LLViewerFetchedTexture::sWhiteImagep;
-	}
+        for (U32 j = 0; j < 3; ++j)
+        {
+            if (p[j] < ext[0].mV[j] ||
+                p[j] > ext[1].mV[j])
+            {
+                found = false;
+                break;
+            }
+        }
 
-	S32 channel = shader.enableTexture(LLShaderMgr::DEFERRED_PROJECTION);
+        for (U32 j = 0; j < LLCamera::AGENT_PLANE_NO_USER_CLIP_NUM; ++j)
+        {
+            const LLPlane& cp = camera.getAgentPlane(j);
+            F32 dist = cp.dist(pp[i]);
+            if (dist > 0.05f) //point is above some plane, not contained
+            {
+                found = false;
+                break;
+            }
+        }
 
-	if (channel > -1)
-	{
-		if (img)
-		{
-			gGL.getTexUnit(channel)->bind(img);
+        if (found)
+        {
+            fp.push_back(pp[i]);
+        }
+    }
 
-			F32 lod_range = logf(img->getWidth())/logf(2.f);
+    if (fp.empty())
+    {
+        return false;
+    }
 
-			shader.uniform1f(LLShaderMgr::PROJECTOR_FOCUS, focus);
-			shader.uniform1f(LLShaderMgr::PROJECTOR_LOD, lod_range);
-			shader.uniform1f(LLShaderMgr::PROJECTOR_AMBIENT_LOD, llclamp((proj_range-focus)/proj_range*lod_range, 0.f, 1.f));
-		}
-	}
-		
+    return true;
 }
 
-void LLPipeline::unbindDeferredShader(LLGLSLShader &shader)
+void LLPipeline::renderHighlight(const LLViewerObject* obj, F32 fade)
 {
-    LLRenderTarget* deferred_target       = &mRT->deferredScreen;
-    LLRenderTarget* deferred_light_target = &mRT->deferredLight;
-
-	stop_glerror();
-    shader.disableTexture(LLShaderMgr::DEFERRED_NORMAL, deferred_target->getUsage());
-    shader.disableTexture(LLShaderMgr::DEFERRED_DIFFUSE, deferred_target->getUsage());
-    shader.disableTexture(LLShaderMgr::DEFERRED_SPECULAR, deferred_target->getUsage());
-    shader.disableTexture(LLShaderMgr::DEFERRED_EMISSIVE, deferred_target->getUsage());
-    shader.disableTexture(LLShaderMgr::DEFERRED_BRDF_LUT);
-    //shader.disableTexture(LLShaderMgr::DEFERRED_DEPTH, deferred_depth_target->getUsage());
-    shader.disableTexture(LLShaderMgr::DEFERRED_DEPTH, deferred_target->getUsage());
-    shader.disableTexture(LLShaderMgr::DEFERRED_LIGHT, deferred_light_target->getUsage());
-	shader.disableTexture(LLShaderMgr::DIFFUSE_MAP);
-	shader.disableTexture(LLShaderMgr::DEFERRED_BLOOM);
-
-	for (U32 i = 0; i < 4; i++)
-	{
-		if (shader.disableTexture(LLShaderMgr::DEFERRED_SHADOW0+i) > -1)
-		{
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
-		}
-	}
-
-	for (U32 i = 4; i < 6; i++)
-	{
-		if (shader.disableTexture(LLShaderMgr::DEFERRED_SHADOW0+i) > -1)
-		{
-			glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
-		}
-	}
-
-	shader.disableTexture(LLShaderMgr::DEFERRED_NOISE);
-	shader.disableTexture(LLShaderMgr::DEFERRED_LIGHTFUNC);
-
-    if (!LLPipeline::sReflectionProbesEnabled)
+    if (obj && obj->getVolume())
     {
-        S32 channel = shader.disableTexture(LLShaderMgr::ENVIRONMENT_MAP, LLTexUnit::TT_CUBE_MAP);
-        if (channel > -1)
+        for (LLViewerObject::child_list_t::const_iterator iter = obj->getChildren().begin(); iter != obj->getChildren().end(); ++iter)
         {
-            LLCubeMap* cube_map = gSky.mVOSkyp ? gSky.mVOSkyp->getCubeMap() : NULL;
-            if (cube_map)
+            renderHighlight(*iter, fade);
+        }
+
+        LLDrawable* drawable = obj->mDrawable;
+        if (drawable)
+        {
+            for (S32 i = 0; i < drawable->getNumFaces(); ++i)
             {
-                cube_map->disable();
+                LLFace* face = drawable->getFace(i);
+                if (face)
+                {
+                    face->renderSelected(LLViewerTexture::sNullImagep, LLColor4(1,1,1,fade));
+                }
             }
         }
     }
+}
 
-    unbindReflectionProbes(shader);
 
-	gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-	gGL.getTexUnit(0)->activate();
-	shader.unbind();
+LLRenderTarget* LLPipeline::getSunShadowTarget(U32 i)
+{
+    llassert(i < 4);
+    return &mRT->shadow[i];
 }
 
-void LLPipeline::setEnvMat(LLGLSLShader& shader)
+LLRenderTarget* LLPipeline::getSpotShadowTarget(U32 i)
 {
-    F32* m = gGLModelView.getF32ptr();
-
-    F32 mat[] = { m[0], m[1], m[2],
-                    m[4], m[5], m[6],
-                    m[8], m[9], m[10] };
-
-    shader.uniformMatrix3fv(LLShaderMgr::DEFERRED_ENV_MAT, 1, TRUE, mat);
+    llassert(i < 2);
+    return &mSpotShadow[i];
 }
 
-void LLPipeline::bindReflectionProbes(LLGLSLShader& shader)
+static LLTrace::BlockTimerStatHandle FTM_GEN_SUN_SHADOW("Gen Sun Shadow");
+static LLTrace::BlockTimerStatHandle FTM_GEN_SUN_SHADOW_SPOT_RENDER("Spot Shadow Render");
+
+// helper class for disabling occlusion culling for the current stack frame
+class LLDisableOcclusionCulling
 {
-    if (!sReflectionProbesEnabled)
+public:
+    S32 mUseOcclusion;
+
+    LLDisableOcclusionCulling()
     {
-        return;
+        mUseOcclusion = LLPipeline::sUseOcclusion;
+        LLPipeline::sUseOcclusion = 0;
     }
 
-    S32 channel = shader.enableTexture(LLShaderMgr::REFLECTION_PROBES, LLTexUnit::TT_CUBE_MAP_ARRAY);
-    bool bound = false;
-    if (channel > -1 && mReflectionMapManager.mTexture.notNull())
+    ~LLDisableOcclusionCulling()
     {
-        mReflectionMapManager.mTexture->bind(channel);
-        bound = true;
+        LLPipeline::sUseOcclusion = mUseOcclusion;
     }
+};
 
-    channel = shader.enableTexture(LLShaderMgr::IRRADIANCE_PROBES, LLTexUnit::TT_CUBE_MAP_ARRAY);
-    if (channel > -1 && mReflectionMapManager.mIrradianceMaps.notNull())
+void LLPipeline::generateSunShadow(LLCamera& camera)
+{
+    if (!sRenderDeferred || RenderShadowDetail <= 0)
     {
-        mReflectionMapManager.mIrradianceMaps->bind(channel);
-        bound = true;
+        return;
     }
-    
-	if (RenderMirrors)
+
+    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; //LL_RECORD_BLOCK_TIME(FTM_GEN_SUN_SHADOW);
+    LL_PROFILE_GPU_ZONE("generateSunShadow");
+
+    LLDisableOcclusionCulling no_occlusion;
+
+    bool skip_avatar_update = false;
+    if (!isAgentAvatarValid() || gAgentCamera.getCameraAnimating() || gAgentCamera.getCameraMode() != CAMERA_MODE_MOUSELOOK || !LLVOAvatar::sVisibleInFirstPerson)
     {
-        channel = shader.enableTexture(LLShaderMgr::HERO_PROBE, LLTexUnit::TT_CUBE_MAP_ARRAY);
-        if (channel > -1 && mHeroProbeManager.mTexture.notNull())
-        {
-            mHeroProbeManager.mTexture->bind(channel);
-            bound = true;
-        }
+        skip_avatar_update = true;
     }
-     
 
-    if (bound)
+    if (!skip_avatar_update)
     {
-        mReflectionMapManager.setUniforms();
-
-        setEnvMat(shader);
+        gAgentAvatarp->updateAttachmentVisibility(CAMERA_MODE_THIRD_PERSON);
     }
 
-    // reflection probe shaders generally sample the scene map as well for SSR
-    channel = shader.enableTexture(LLShaderMgr::SCENE_MAP);
-    if (channel > -1)
+    LLMatrix4a last_modelview = gGLLastModelView;
+    LLMatrix4a last_projection = gGLLastProjection;
+
+    pushRenderTypeMask();
+    andRenderTypeMask(LLPipeline::RENDER_TYPE_SIMPLE,
+                    LLPipeline::RENDER_TYPE_ALPHA,
+                    LLPipeline::RENDER_TYPE_ALPHA_PRE_WATER,
+                    LLPipeline::RENDER_TYPE_ALPHA_POST_WATER,
+                    LLPipeline::RENDER_TYPE_GRASS,
+                    LLPipeline::RENDER_TYPE_GLTF_PBR,
+                    LLPipeline::RENDER_TYPE_FULLBRIGHT,
+                    LLPipeline::RENDER_TYPE_BUMP,
+                    LLPipeline::RENDER_TYPE_VOLUME,
+                    LLPipeline::RENDER_TYPE_AVATAR,
+                    LLPipeline::RENDER_TYPE_CONTROL_AV,
+                    LLPipeline::RENDER_TYPE_TREE,
+                    LLPipeline::RENDER_TYPE_TERRAIN,
+                    LLPipeline::RENDER_TYPE_WATER,
+                    LLPipeline::RENDER_TYPE_VOIDWATER,
+                    LLPipeline::RENDER_TYPE_PASS_ALPHA,
+                    LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK,
+                    LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
+                    LLPipeline::RENDER_TYPE_PASS_GRASS,
+                    LLPipeline::RENDER_TYPE_PASS_SIMPLE,
+                    LLPipeline::RENDER_TYPE_PASS_BUMP,
+                    LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT,
+                    LLPipeline::RENDER_TYPE_PASS_SHINY,
+                    LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
+                    LLPipeline::RENDER_TYPE_PASS_MATERIAL,
+                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA,
+                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK,
+                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE,
+                    LLPipeline::RENDER_TYPE_PASS_SPECMAP,
+                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_BLEND,
+                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_MASK,
+                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_EMISSIVE,
+                    LLPipeline::RENDER_TYPE_PASS_NORMMAP,
+                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_BLEND,
+                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_MASK,
+                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_EMISSIVE,
+                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC,
+                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_BLEND,
+                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_MASK,
+                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_EMISSIVE,
+                    LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_SIMPLE_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_BUMP_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_SHINY_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_BLEND_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_MASK_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_EMISSIVE_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_BLEND_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_MASK_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_EMISSIVE_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_BLEND_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_MASK_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_EMISSIVE_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_GLTF_PBR,
+                    LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_RIGGED,
+                    LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_ALPHA_MASK,
+                    LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_ALPHA_MASK_RIGGED,
+                    END_RENDER_TYPES);
+
+    gGL.setColorMask(false, false);
+
+    LLEnvironment& environment = LLEnvironment::instance();
+
+    //get sun view matrix
+
+    //store current projection/modelview matrix
+    glh::matrix4f saved_proj = glh::matrix4f((F32*)get_current_projection().getF32ptr());
+    glh::matrix4f saved_view = glh::matrix4f((F32*)get_current_modelview().getF32ptr());
+    glh::matrix4f inv_view = saved_view.inverse();
+
+    glh::matrix4f view[6];
+    glh::matrix4f proj[6];
+
+    LLVector3 caster_dir(environment.getIsSunUp() ? mSunDir : mMoonDir);
+
+    //put together a universal "near clip" plane for shadow frusta
+    LLPlane shadow_near_clip;
     {
-        gGL.getTexUnit(channel)->bind(&mSceneMap);
+        LLVector3 p = camera.getOrigin(); // gAgent.getPositionAgent();
+        p += caster_dir * RenderFarClip*2.f;
+        shadow_near_clip.setVec(p, caster_dir);
     }
 
-	
-    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_ITR_COUNT, RenderScreenSpaceReflectionIterations);
-    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_DIST_BIAS, RenderScreenSpaceReflectionDistanceBias);
-    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_RAY_STEP, RenderScreenSpaceReflectionRayStep);
-    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_GLOSSY_SAMPLES, RenderScreenSpaceReflectionGlossySamples);
-    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_REJECT_BIAS, RenderScreenSpaceReflectionDepthRejectBias);
-    mPoissonOffset++;
+    LLVector3 lightDir = -caster_dir;
+    lightDir.normVec();
 
-	if (mPoissonOffset > 128 - RenderScreenSpaceReflectionGlossySamples)
-        mPoissonOffset = 0;
+    glh::vec3f light_dir(lightDir.mV);
 
-    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_NOISE_SINE, mPoissonOffset);
-    shader.uniform1f(LLShaderMgr::DEFERRED_SSR_ADAPTIVE_STEP_MULT, RenderScreenSpaceReflectionAdaptiveStepMultiplier);
+    //create light space camera matrix
 
-    channel = shader.enableTexture(LLShaderMgr::SCENE_DEPTH);
-    if (channel > -1)
+    LLVector3 at = lightDir;
+
+    LLVector3 up = camera.getAtAxis();
+
+    if (fabsf(up*lightDir) > 0.75f)
     {
-        gGL.getTexUnit(channel)->bind(&mSceneMap, true);
+        up = camera.getUpAxis();
     }
 
+    up.normVec();
+    at.normVec();
 
-}
 
-void LLPipeline::unbindReflectionProbes(LLGLSLShader& shader)
-{
-    S32 channel = shader.disableTexture(LLShaderMgr::REFLECTION_PROBES, LLTexUnit::TT_CUBE_MAP);
-    if (channel > -1 && mReflectionMapManager.mTexture.notNull())
+    LLCamera main_camera = camera;
+
+    F32 near_clip = 0.f;
     {
-        mReflectionMapManager.mTexture->unbind();
-        if (channel == 0)
+        //get visible point cloud
+        std::vector<LLVector3> fp;
+
+        main_camera.calcAgentFrustumPlanes(main_camera.mAgentFrustum);
+
+        LLVector3 min,max;
+        getVisiblePointCloud(main_camera,min,max,fp);
+
+        if (fp.empty())
         {
-            gGL.getTexUnit(channel)->enable(LLTexUnit::TT_TEXTURE);
+            if (!hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
+            {
+                mShadowCamera[0] = main_camera;
+                mShadowExtents[0][0] = min;
+                mShadowExtents[0][1] = max;
+
+                mShadowFrustPoints[0].clear();
+                mShadowFrustPoints[1].clear();
+                mShadowFrustPoints[2].clear();
+                mShadowFrustPoints[3].clear();
+            }
+            popRenderTypeMask();
+
+            if (!skip_avatar_update)
+            {
+                gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode());
+            }
+
+            return;
         }
-    }
-}
 
+        //get good split distances for frustum
+        for (U32 i = 0; i < fp.size(); ++i)
+        {
+            glh::vec3f v(fp[i].mV);
+            saved_view.mult_matrix_vec(v);
+            fp[i].setVec(v.v);
+        }
+
+        min = fp[0];
+        max = fp[0];
+
+        //get camera space bounding box
+        for (U32 i = 1; i < fp.size(); ++i)
+        {
+            update_min_max(min, max, fp[i]);
+        }
 
-inline float sgn(float a)
-{
-    if (a > 0.0F) return (1.0F);
-    if (a < 0.0F) return (-1.0F);
-    return (0.0F);
-}
+        near_clip    = llclamp(-max.mV[2], 0.01f, 4.0f);
+        F32 far_clip = llclamp(-min.mV[2]*2.f, 16.0f, 512.0f);
 
-glh::matrix4f look(const LLVector3 pos, const LLVector3 dir, const LLVector3 up)
-{
-	glh::matrix4f ret;
+        //far_clip = llmin(far_clip, 128.f);
+        far_clip = llmin(far_clip, camera.getFar());
 
-	LLVector3 dirN;
-	LLVector3 upN;
-	LLVector3 lftN;
+        F32 range = far_clip-near_clip;
 
-	lftN = dir % up;
-	lftN.normVec();
-	
-	upN = lftN % dir;
-	upN.normVec();
-	
-	dirN = dir;
-	dirN.normVec();
+        LLVector3 split_exp = RenderShadowSplitExponent;
 
-	ret.m[ 0] = lftN[0];
-	ret.m[ 1] = upN[0];
-	ret.m[ 2] = -dirN[0];
-	ret.m[ 3] = 0.f;
+        F32 da = 1.f-llmax( fabsf(lightDir*up), fabsf(lightDir*camera.getLeftAxis()) );
 
-	ret.m[ 4] = lftN[1];
-	ret.m[ 5] = upN[1];
-	ret.m[ 6] = -dirN[1];
-	ret.m[ 7] = 0.f;
+        da = powf(da, split_exp.mV[2]);
 
-	ret.m[ 8] = lftN[2];
-	ret.m[ 9] = upN[2];
-	ret.m[10] = -dirN[2];
-	ret.m[11] = 0.f;
+        F32 sxp = split_exp.mV[1] + (split_exp.mV[0]-split_exp.mV[1])*da;
 
-	ret.m[12] = -(lftN*pos);
-	ret.m[13] = -(upN*pos);
-	ret.m[14] = dirN*pos;
-	ret.m[15] = 1.f;
+        for (U32 i = 0; i < 4; ++i)
+        {
+            F32 x = (F32)(i+1)/4.f;
+            x = powf(x, sxp);
+            mSunClipPlanes.mV[i] = near_clip+range*x;
+        }
 
-	return ret;
-}
+        mSunClipPlanes.mV[0] *= 1.25f; //bump back first split for transition padding
+    }
 
-glh::matrix4f scale_translate_to_fit(const LLVector3 min, const LLVector3 max)
-{
-	glh::matrix4f ret;
-	ret.m[ 0] = 2/(max[0]-min[0]);
-	ret.m[ 4] = 0;
-	ret.m[ 8] = 0;
-	ret.m[12] = -(max[0]+min[0])/(max[0]-min[0]);
+    if (gCubeSnapshot)
+    { // stretch clip planes for reflection probe renders to reduce number of shadow passes
+        mSunClipPlanes.mV[1] = mSunClipPlanes.mV[2];
+        mSunClipPlanes.mV[2] = mSunClipPlanes.mV[3];
+        mSunClipPlanes.mV[3] *= 1.5f;
+    }
 
-	ret.m[ 1] = 0;
-	ret.m[ 5] = 2/(max[1]-min[1]);
-	ret.m[ 9] = 0;
-	ret.m[13] = -(max[1]+min[1])/(max[1]-min[1]);
 
-	ret.m[ 2] = 0;
-	ret.m[ 6] = 0;
-	ret.m[10] = 2/(max[2]-min[2]);
-	ret.m[14] = -(max[2]+min[2])/(max[2]-min[2]);
+    // convenience array of 4 near clip plane distances
+    F32 dist[] = { near_clip, mSunClipPlanes.mV[0], mSunClipPlanes.mV[1], mSunClipPlanes.mV[2], mSunClipPlanes.mV[3] };
 
-	ret.m[ 3] = 0;
-	ret.m[ 7] = 0;
-	ret.m[11] = 0;
-	ret.m[15] = 1;
+    if (mSunDiffuse == LLColor4::black)
+    { //sun diffuse is totally black shadows don't matter
+        skipRenderingShadows();
+    }
+    else
+    {
+        for (S32 j = 0; j < (gCubeSnapshot ? 2 : 4); j++)
+        {
+            if (!hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
+            {
+                mShadowFrustPoints[j].clear();
+            }
 
-	return ret;
-}
+            LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SUN_SHADOW0+j);
 
-static LLTrace::BlockTimerStatHandle FTM_SHADOW_RENDER("Render Shadows");
-static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA("Alpha Shadow");
-static LLTrace::BlockTimerStatHandle FTM_SHADOW_SIMPLE("Simple Shadow");
-static LLTrace::BlockTimerStatHandle FTM_SHADOW_GEOM("Shadow Geom");
+            //restore render matrices
+            set_current_modelview(LLMatrix4a(saved_view.m));
+            set_current_projection(LLMatrix4a(saved_proj.m));
 
-static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_MASKED("Alpha Masked");
-static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_BLEND("Alpha Blend");
-static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_TREE("Alpha Tree");
-static LLTrace::BlockTimerStatHandle FTM_SHADOW_ALPHA_GRASS("Alpha Grass");
-static LLTrace::BlockTimerStatHandle FTM_SHADOW_FULLBRIGHT_ALPHA_MASKED("Fullbright Alpha Masked");
+            LLVector3 eye = camera.getOrigin();
+            llassert(eye.isFinite());
 
-void LLPipeline::renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& shadow_cam, LLCullResult& result, bool depth_clamp)
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; //LL_RECORD_BLOCK_TIME(FTM_SHADOW_RENDER);
-    LL_PROFILE_GPU_ZONE("renderShadow");
-    
-    LLPipeline::sShadowRender = true;
+            //camera used for shadow cull/render
+            LLCamera shadow_cam;
 
-    // disable occlusion culling during shadow render
-    U32 saved_occlusion = sUseOcclusion;
-    sUseOcclusion = 0;
+            //create world space camera frustum for this split
+            shadow_cam = camera;
+            shadow_cam.setFar(16.f);
 
-    // List of render pass types that use the prim volume as the shadow,
-    // ignoring textures.
-    static const U32 types[] = {
-        LLRenderPass::PASS_SIMPLE,
-        LLRenderPass::PASS_FULLBRIGHT,
-        LLRenderPass::PASS_SHINY,
-        LLRenderPass::PASS_BUMP,
-        LLRenderPass::PASS_FULLBRIGHT_SHINY,
-        LLRenderPass::PASS_MATERIAL,
-        LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE,
-        LLRenderPass::PASS_SPECMAP,
-        LLRenderPass::PASS_SPECMAP_EMISSIVE,
-        LLRenderPass::PASS_NORMMAP,
-        LLRenderPass::PASS_NORMMAP_EMISSIVE,
-        LLRenderPass::PASS_NORMSPEC,
-        LLRenderPass::PASS_NORMSPEC_EMISSIVE
-    };
+            LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE);
 
-    LLGLEnable cull(GL_CULL_FACE);
+            LLVector3* frust = shadow_cam.mAgentFrustum;
 
-    //enable depth clamping if available
-    LLGLEnable clamp_depth(depth_clamp ? GL_DEPTH_CLAMP : 0);
+            LLVector3 pn = shadow_cam.getAtAxis();
 
-    LLGLDepthTest depth_test(GL_TRUE, GL_TRUE, GL_LESS);
+            LLVector3 min, max;
 
-    updateCull(shadow_cam, result);
+            //construct 8 corners of split frustum section
+            for (U32 i = 0; i < 4; i++)
+            {
+                LLVector3 delta = frust[i+4]-eye;
+                delta += (frust[i+4]-frust[(i+2)%4+4])*0.05f;
+                delta.normVec();
+                F32 dp = delta*pn;
+                frust[i] = eye + (delta*dist[j]*0.75f)/dp;
+                frust[i+4] = eye + (delta*dist[j+1]*1.25f)/dp;
+            }
 
-    stateSort(shadow_cam, result);
+            shadow_cam.calcAgentFrustumPlanes(frust);
+            shadow_cam.mFrustumCornerDist = 0.f;
 
-    //generate shadow map
-    gGL.matrixMode(LLRender::MM_PROJECTION);
-    gGL.pushMatrix();
-    gGL.loadMatrix(LLMatrix4a(proj.m));
-    gGL.matrixMode(LLRender::MM_MODELVIEW);
-    gGL.pushMatrix();
-    gGL.loadMatrix(LLMatrix4a(view.m));
+            if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
+            {
+                mShadowCamera[j] = shadow_cam;
+            }
 
-    stop_glerror();
-    gGLLastMatrix = NULL;
+            std::vector<LLVector3> fp;
 
-    gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+            if (!gPipeline.getVisiblePointCloud(shadow_cam, min, max, fp, lightDir)
+                || j > RenderShadowSplits)
+            {
+                //no possible shadow receivers
+                if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
+                {
+                    mShadowExtents[j][0] = LLVector3();
+                    mShadowExtents[j][1] = LLVector3();
+                    mShadowCamera[j+4] = shadow_cam;
+                }
 
-    stop_glerror();
+                mRT->shadow[j].bindTarget();
+                {
+                    LLGLDepthTest depth(GL_TRUE);
+                    mRT->shadow[j].clear();
+                }
+                mRT->shadow[j].flush();
 
-    struct CompareVertexBuffer
-    {
-        bool operator()(const LLDrawInfo* const& lhs, const LLDrawInfo* const& rhs)
-        {
-            return lhs->mVertexBuffer > rhs->mVertexBuffer;
-        }
-    };
+                mShadowError.mV[j] = 0.f;
+                mShadowFOV.mV[j] = 0.f;
 
+                continue;
+            }
 
-    LLVertexBuffer::unbind();
-    for (int j = 0; j < 2; ++j) // 0 -- static, 1 -- rigged
-    {
-        bool rigged = j == 1;
-        gDeferredShadowProgram.bind(rigged);
+            if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
+            {
+                mShadowExtents[j][0] = min;
+                mShadowExtents[j][1] = max;
+                mShadowFrustPoints[j] = fp;
+            }
 
-        gGL.diffuseColor4f(1, 1, 1, 1);
 
-        // if not using VSM, disable color writes
-        if (LLPipeline::RenderShadowDetail <= 2)
-        {
-            gGL.setColorMask(false, false);
-        }
+            //find a good origin for shadow projection
+            LLVector3 origin;
 
-        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow simple"); //LL_RECORD_BLOCK_TIME(FTM_SHADOW_SIMPLE);
-        LL_PROFILE_GPU_ZONE("shadow simple");
-        gGL.getTexUnit(0)->disable();
+            //get a temporary view projection
+            view[j] = look(camera.getOrigin(), lightDir, -up);
 
-        for (U32 type : types)
-        {
-            renderObjects(type, false, false, rigged);
-        }
+            std::vector<LLVector3> wpf;
 
-        renderGLTFObjects(LLRenderPass::PASS_GLTF_PBR, false, rigged);
+            for (U32 i = 0; i < fp.size(); i++)
+            {
+                glh::vec3f p = glh::vec3f(fp[i].mV);
+                view[j].mult_matrix_vec(p);
+                wpf.push_back(LLVector3(p.v));
+            }
 
-        gGL.getTexUnit(0)->enable(LLTexUnit::TT_TEXTURE);
-    }
+            min = wpf[0];
+            max = wpf[0];
 
-    if (LLPipeline::sUseOcclusion > 1)
-    { // do occlusion culling against non-masked only to take advantage of hierarchical Z
-        doOcclusion(shadow_cam);
-    }
+            for (U32 i = 0; i < fp.size(); ++i)
+            { //get AABB in camera space
+                update_min_max(min, max, wpf[i]);
+            }
 
+            // Construct a perspective transform with perspective along y-axis that contains
+            // points in wpf
+            //Known:
+            // - far clip plane
+            // - near clip plane
+            // - points in frustum
+            //Find:
+            // - origin
 
-    {
-        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow geom");
-        renderGeomShadow(shadow_cam);
-    }
+            //get some "interesting" points of reference
+            LLVector3 center = (min+max)*0.5f;
+            LLVector3 size = (max-min)*0.5f;
+            LLVector3 near_center = center;
+            near_center.mV[1] += size.mV[1]*2.f;
 
-    {
-        LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha");
-        LL_PROFILE_GPU_ZONE("shadow alpha");
-        const S32 sun_up = LLEnvironment::instance().getIsSunUp() ? 1 : 0;
-        U32 target_width = LLRenderTarget::sCurResX;
 
-        for (int i = 0; i < 2; ++i)
-        {
-            bool rigged = i == 1;
+            //put all points in wpf in quadrant 0, reletive to center of min/max
+            //get the best fit line using least squares
+            F32 bfm = 0.f;
+            F32 bfb = 0.f;
 
+            for (U32 i = 0; i < wpf.size(); ++i)
             {
-                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha masked");
-                LL_PROFILE_GPU_ZONE("shadow alpha masked");
-                gDeferredShadowAlphaMaskProgram.bind(rigged);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
-                renderMaskedObjects(LLRenderPass::PASS_ALPHA_MASK, true, true, rigged);
+                wpf[i] -= center;
+                wpf[i].mV[0] = fabsf(wpf[i].mV[0]);
+                wpf[i].mV[2] = fabsf(wpf[i].mV[2]);
             }
 
+            if (!wpf.empty())
             {
-                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha blend");
-                LL_PROFILE_GPU_ZONE("shadow alpha blend");
-                renderAlphaObjects(rigged);
-            }
+                F32 sx = 0.f;
+                F32 sx2 = 0.f;
+                F32 sy = 0.f;
+                F32 sxy = 0.f;
 
-            {
-                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow fullbright alpha masked");
-                LL_PROFILE_GPU_ZONE("shadow alpha masked");
-                gDeferredShadowFullbrightAlphaMaskProgram.bind(rigged);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
-                LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
-                renderFullbrightMaskedObjects(LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK, true, true, rigged);
+                for (U32 i = 0; i < wpf.size(); ++i)
+                {
+                    sx += wpf[i].mV[0];
+                    sx2 += wpf[i].mV[0]*wpf[i].mV[0];
+                    sy += wpf[i].mV[1];
+                    sxy += wpf[i].mV[0]*wpf[i].mV[1];
+                }
+
+                bfm = (sy*sx-wpf.size()*sxy)/(sx*sx-wpf.size()*sx2);
+                bfb = (sx*sxy-sy*sx2)/(sx*sx-bfm*sx2);
             }
 
             {
-                LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha grass");
-                LL_PROFILE_GPU_ZONE("shadow alpha grass");
-                gDeferredTreeShadowProgram.bind(rigged);
-                LLGLSLShader::sCurBoundShaderPtr->setMinimumAlpha(ALPHA_BLEND_CUTOFF);
+                // best fit line is y=bfm*x+bfb
 
-                if (i == 0)
+                //find point that is furthest to the right of line
+                F32 off_x = -1.f;
+                LLVector3 lp;
+
+                for (U32 i = 0; i < wpf.size(); ++i)
                 {
-                    renderObjects(LLRenderPass::PASS_GRASS, true);
+                    //y = bfm*x+bfb
+                    //x = (y-bfb)/bfm
+                    F32 lx = (wpf[i].mV[1]-bfb)/bfm;
+
+                    lx = wpf[i].mV[0]-lx;
+
+                    if (off_x < lx)
+                    {
+                        off_x = lx;
+                        lp = wpf[i];
+                    }
                 }
 
+                //get line with slope bfm through lp
+                // bfb = y-bfm*x
+                bfb = lp.mV[1]-bfm*lp.mV[0];
+
+                //calculate error
+                mShadowError.mV[j] = 0.f;
+
+                for (U32 i = 0; i < wpf.size(); ++i)
                 {
-                    LL_PROFILE_ZONE_NAMED_CATEGORY_PIPELINE("shadow alpha material");
-                    LL_PROFILE_GPU_ZONE("shadow alpha material");
-                    renderMaskedObjects(LLRenderPass::PASS_NORMSPEC_MASK, true, false, rigged);
-                    renderMaskedObjects(LLRenderPass::PASS_MATERIAL_ALPHA_MASK, true, false, rigged);
-                    renderMaskedObjects(LLRenderPass::PASS_SPECMAP_MASK, true, false, rigged);
-                    renderMaskedObjects(LLRenderPass::PASS_NORMMAP_MASK, true, false, rigged);
+                    F32 lx = (wpf[i].mV[1]-bfb)/bfm;
+                    mShadowError.mV[j] += fabsf(wpf[i].mV[0]-lx);
                 }
-            }
-        }
 
-        for (int i = 0; i < 2; ++i)
-        {
-            bool rigged = i == 1;
-            gDeferredShadowGLTFAlphaMaskProgram.bind(rigged);
-            LLGLSLShader::sCurBoundShaderPtr->uniform1i(LLShaderMgr::SUN_UP_FACTOR, sun_up);
-            LLGLSLShader::sCurBoundShaderPtr->uniform1f(LLShaderMgr::DEFERRED_SHADOW_TARGET_WIDTH, (float)target_width);
-            
-            gGL.loadMatrix(gGLModelView);
-            gGLLastMatrix = NULL;
+                mShadowError.mV[j] /= wpf.size();
+                mShadowError.mV[j] /= size.mV[0];
 
-            U32 type = LLRenderPass::PASS_GLTF_PBR_ALPHA_MASK;
+                if (mShadowError.mV[j] > RenderShadowErrorCutoff)
+                { //just use ortho projection
+                    mShadowFOV.mV[j] = -1.f;
+                    origin.clearVec();
+                    proj[j] = gl_ortho(min.mV[0], max.mV[0],
+                                        min.mV[1], max.mV[1],
+                                        -max.mV[2], -min.mV[2]);
+                }
+                else
+                {
+                    //origin is where line x = 0;
+                    origin.setVec(0,bfb,0);
 
-            if (rigged)
-            {
-                mAlphaMaskPool->pushRiggedGLTFBatches(type + 1);
-            }
-            else
-            {
-                mAlphaMaskPool->pushGLTFBatches(type);
-            }
+                    F32 fovz = 1.f;
+                    F32 fovx = 1.f;
 
-            gGL.loadMatrix(gGLModelView);
-            gGLLastMatrix = NULL;
-        }
-    }
+                    LLVector3 zp;
+                    LLVector3 xp;
 
-    gDeferredShadowCubeProgram.bind();
-    gGLLastMatrix = NULL;
-    gGL.loadMatrix(gGLModelView);
+                    for (U32 i = 0; i < wpf.size(); ++i)
+                    {
+                        LLVector3 atz = wpf[i]-origin;
+                        atz.mV[0] = 0.f;
+                        atz.normVec();
+                        if (fovz > -atz.mV[1])
+                        {
+                            zp = wpf[i];
+                            fovz = -atz.mV[1];
+                        }
 
-    gGL.setColorMask(true, true);
+                        LLVector3 atx = wpf[i]-origin;
+                        atx.mV[2] = 0.f;
+                        atx.normVec();
+                        if (fovx > -atx.mV[1])
+                        {
+                            fovx = -atx.mV[1];
+                            xp = wpf[i];
+                        }
+                    }
 
-    gGL.matrixMode(LLRender::MM_PROJECTION);
-    gGL.popMatrix();
-    gGL.matrixMode(LLRender::MM_MODELVIEW);
-    gGL.popMatrix();
-    gGLLastMatrix = NULL;
+                    fovx = acos(fovx);
+                    fovz = acos(fovz);
 
-    // reset occlusion culling flag
-    sUseOcclusion = saved_occlusion;
-    LLPipeline::sShadowRender = false;
-}
+                    F32 cutoff = llmin((F32) RenderShadowFOVCutoff, 1.4f);
 
-bool LLPipeline::getVisiblePointCloud(LLCamera& camera, LLVector3& min, LLVector3& max, std::vector<LLVector3>& fp, LLVector3 light_dir)
-{
-    LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
-	//get point cloud of intersection of frust and min, max
-
-	if (getVisibleExtents(camera, min, max))
-	{
-		return false;
-	}
-
-	//get set of planes on bounding box
-	LLPlane bp[] = { 
-		LLPlane(min, LLVector3(-1,0,0)),
-		LLPlane(min, LLVector3(0,-1,0)),
-		LLPlane(min, LLVector3(0,0,-1)),
-		LLPlane(max, LLVector3(1,0,0)),
-		LLPlane(max, LLVector3(0,1,0)),
-		LLPlane(max, LLVector3(0,0,1))};
-	
-	//potential points
-	std::vector<LLVector3> pp;
-
-	//add corners of AABB
-	pp.push_back(LLVector3(min.mV[0], min.mV[1], min.mV[2]));
-	pp.push_back(LLVector3(max.mV[0], min.mV[1], min.mV[2]));
-	pp.push_back(LLVector3(min.mV[0], max.mV[1], min.mV[2]));
-	pp.push_back(LLVector3(max.mV[0], max.mV[1], min.mV[2]));
-	pp.push_back(LLVector3(min.mV[0], min.mV[1], max.mV[2]));
-	pp.push_back(LLVector3(max.mV[0], min.mV[1], max.mV[2]));
-	pp.push_back(LLVector3(min.mV[0], max.mV[1], max.mV[2]));
-	pp.push_back(LLVector3(max.mV[0], max.mV[1], max.mV[2]));
-
-	//add corners of camera frustum
-	for (U32 i = 0; i < LLCamera::AGENT_FRUSTRUM_NUM; i++)
-	{
-		pp.push_back(camera.mAgentFrustum[i]);
-	}
-
-
-	//bounding box line segments
-	U32 bs[] = 
-			{
-		0,1,
-		1,3,
-		3,2,
-		2,0,
-
-		4,5,
-		5,7,
-		7,6,
-		6,4,
-
-		0,4,
-		1,5,
-		3,7,
-		2,6
-	};
-
-	for (U32 i = 0; i < 12; i++)
-	{ //for each line segment in bounding box
-		for (U32 j = 0; j < LLCamera::AGENT_PLANE_NO_USER_CLIP_NUM; j++) 
-		{ //for each plane in camera frustum
-			const LLPlane& cp = camera.getAgentPlane(j);
-			const LLVector3& v1 = pp[bs[i*2+0]];
-			const LLVector3& v2 = pp[bs[i*2+1]];
-			LLVector3 n;
-			cp.getVector3(n);
-
-			LLVector3 line = v1-v2;
-
-			F32 d1 = line*n;
-			F32 d2 = -cp.dist(v2);
-
-			F32 t = d2/d1;
-
-			if (t > 0.f && t < 1.f)
-			{
-				LLVector3 intersect = v2+line*t;
-				pp.push_back(intersect);
-			}
-		}
-	}
-			
-	//camera frustum line segments
-	const U32 fs[] =
-	{
-		0,1,
-		1,2,
-		2,3,
-		3,0,
-
-		4,5,
-		5,6,
-		6,7,
-		7,4,
-	
-		0,4,
-		1,5,
-		2,6,
-		3,7	
-	};
-
-	for (U32 i = 0; i < 12; i++)
-	{
-		for (U32 j = 0; j < 6; ++j)
-		{
-			const LLVector3& v1 = pp[fs[i*2+0]+8];
-			const LLVector3& v2 = pp[fs[i*2+1]+8];
-			const LLPlane& cp = bp[j];
-			LLVector3 n;
-			cp.getVector3(n);
-
-			LLVector3 line = v1-v2;
-
-			F32 d1 = line*n;
-			F32 d2 = -cp.dist(v2);
-
-			F32 t = d2/d1;
-
-			if (t > 0.f && t < 1.f)
-			{
-				LLVector3 intersect = v2+line*t;
-				pp.push_back(intersect);
-			}	
-		}
-	}
-
-	LLVector3 ext[] = { min-LLVector3(0.05f,0.05f,0.05f),
-		max+LLVector3(0.05f,0.05f,0.05f) };
-
-	for (U32 i = 0; i < pp.size(); ++i)
-	{
-		bool found = true;
-
-		const F32* p = pp[i].mV;
-			
-		for (U32 j = 0; j < 3; ++j)
-		{
-			if (p[j] < ext[0].mV[j] ||
-				p[j] > ext[1].mV[j])
-			{
-				found = false;
-				break;
-			}
-		}
-				
-		for (U32 j = 0; j < LLCamera::AGENT_PLANE_NO_USER_CLIP_NUM; ++j)
-		{
-			const LLPlane& cp = camera.getAgentPlane(j);
-			F32 dist = cp.dist(pp[i]);
-			if (dist > 0.05f) //point is above some plane, not contained
-			{
-				found = false;
-				break;
-			}
-		}
-
-		if (found)
-		{
-			fp.push_back(pp[i]);
-		}
-	}
-	
-	if (fp.empty())
-	{
-		return false;
-	}
-	
-	return true;
-}
+                    mShadowFOV.mV[j] = fovx;
 
-void LLPipeline::renderHighlight(const LLViewerObject* obj, F32 fade)
-{
-	if (obj && obj->getVolume())
-	{
-		for (LLViewerObject::child_list_t::const_iterator iter = obj->getChildren().begin(); iter != obj->getChildren().end(); ++iter)
-		{
-			renderHighlight(*iter, fade);
-		}
-
-		LLDrawable* drawable = obj->mDrawable;
-		if (drawable)
-		{
-			for (S32 i = 0; i < drawable->getNumFaces(); ++i)
-			{
-				LLFace* face = drawable->getFace(i);
-				if (face)
-				{
-					face->renderSelected(LLViewerTexture::sNullImagep, LLColor4(1,1,1,fade));
-				}
-			}
-		}
-	}
-}
+                    if (fovx < cutoff && fovz > cutoff)
+                    {
+                        //x is a good fit, but z is too big, move away from zp enough so that fovz matches cutoff
+                        F32 d = zp.mV[2]/tan(cutoff);
+                        F32 ny = zp.mV[1] + fabsf(d);
 
+                        origin.mV[1] = ny;
 
-LLRenderTarget* LLPipeline::getSunShadowTarget(U32 i)
-{
-    llassert(i < 4);
-    return &mRT->shadow[i];
-}
+                        fovz = 1.f;
+                        fovx = 1.f;
 
-LLRenderTarget* LLPipeline::getSpotShadowTarget(U32 i)
-{
-    llassert(i < 2);
-    return &mSpotShadow[i];
-}
+                        for (U32 i = 0; i < wpf.size(); ++i)
+                        {
+                            LLVector3 atz = wpf[i]-origin;
+                            atz.mV[0] = 0.f;
+                            atz.normVec();
+                            fovz = llmin(fovz, -atz.mV[1]);
+
+                            LLVector3 atx = wpf[i]-origin;
+                            atx.mV[2] = 0.f;
+                            atx.normVec();
+                            fovx = llmin(fovx, -atx.mV[1]);
+                        }
 
-static LLTrace::BlockTimerStatHandle FTM_GEN_SUN_SHADOW("Gen Sun Shadow");
-static LLTrace::BlockTimerStatHandle FTM_GEN_SUN_SHADOW_SPOT_RENDER("Spot Shadow Render");
+                        fovx = acos(fovx);
+                        fovz = acos(fovz);
+
+                        mShadowFOV.mV[j] = cutoff;
+                    }
+
+
+                    origin += center;
+
+                    F32 ynear = -(max.mV[1]-origin.mV[1]);
+                    F32 yfar = -(min.mV[1]-origin.mV[1]);
 
-// helper class for disabling occlusion culling for the current stack frame
-class LLDisableOcclusionCulling
-{
-public:
-    S32 mUseOcclusion;
+                    if (ynear < 0.1f) //keep a sensible near clip plane
+                    {
+                        F32 diff = 0.1f-ynear;
+                        origin.mV[1] += diff;
+                        ynear += diff;
+                        yfar += diff;
+                    }
 
-    LLDisableOcclusionCulling()
-    {
-        mUseOcclusion = LLPipeline::sUseOcclusion;
-        LLPipeline::sUseOcclusion = 0;
-    }
+                    if (fovx > cutoff)
+                    { //just use ortho projection
+                        origin.clearVec();
+                        mShadowError.mV[j] = -1.f;
+                        proj[j] = gl_ortho(min.mV[0], max.mV[0],
+                                min.mV[1], max.mV[1],
+                                -max.mV[2], -min.mV[2]);
+                    }
+                    else
+                    {
+                        //get perspective projection
+                        view[j] = view[j].inverse();
+                        //llassert(origin.isFinite());
 
-    ~LLDisableOcclusionCulling()
-    {
-        LLPipeline::sUseOcclusion = mUseOcclusion;
-    }
-};
+                        glh::vec3f origin_agent(origin.mV);
 
-void LLPipeline::generateSunShadow(LLCamera& camera)
-{
-	if (!sRenderDeferred || RenderShadowDetail <= 0)
-	{
-		return;
-	}
+                        //translate view to origin
+                        view[j].mult_matrix_vec(origin_agent);
 
-	LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE; //LL_RECORD_BLOCK_TIME(FTM_GEN_SUN_SHADOW);
-    LL_PROFILE_GPU_ZONE("generateSunShadow");
+                        eye = LLVector3(origin_agent.v);
+                        //llassert(eye.isFinite());
+                        if (!hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
+                        {
+                            mShadowFrustOrigin[j] = eye;
+                        }
 
-    LLDisableOcclusionCulling no_occlusion;
+                        view[j] = look(LLVector3(origin_agent.v), lightDir, -up);
 
-	bool skip_avatar_update = false;
-	if (!isAgentAvatarValid() || gAgentCamera.getCameraAnimating() || gAgentCamera.getCameraMode() != CAMERA_MODE_MOUSELOOK || !LLVOAvatar::sVisibleInFirstPerson)
-	{
-		skip_avatar_update = true;
-	}
+                        F32 fx = 1.f/tanf(fovx);
+                        F32 fz = 1.f/tanf(fovz);
 
-	if (!skip_avatar_update)
-	{
-		gAgentAvatarp->updateAttachmentVisibility(CAMERA_MODE_THIRD_PERSON);
-	}
+                        proj[j] = glh::matrix4f(-fx, 0, 0, 0,
+                                                0, (yfar+ynear)/(ynear-yfar), 0, (2.f*yfar*ynear)/(ynear-yfar),
+                                                0, 0, -fz, 0,
+                                                0, -1.f, 0, 0);
+                    }
+                }
+            }
 
-	LLMatrix4a last_modelview = gGLLastModelView;
-	LLMatrix4a last_projection = gGLLastProjection;
+            //shadow_cam.setFar(128.f);
+            shadow_cam.setOriginAndLookAt(eye, up, center);
 
-	pushRenderTypeMask();
-	andRenderTypeMask(LLPipeline::RENDER_TYPE_SIMPLE,
-					LLPipeline::RENDER_TYPE_ALPHA,
-                    LLPipeline::RENDER_TYPE_ALPHA_PRE_WATER,
-                    LLPipeline::RENDER_TYPE_ALPHA_POST_WATER,
-					LLPipeline::RENDER_TYPE_GRASS,
-                    LLPipeline::RENDER_TYPE_GLTF_PBR,
-					LLPipeline::RENDER_TYPE_FULLBRIGHT,
-					LLPipeline::RENDER_TYPE_BUMP,
-					LLPipeline::RENDER_TYPE_VOLUME,
-					LLPipeline::RENDER_TYPE_AVATAR,
-					LLPipeline::RENDER_TYPE_CONTROL_AV,
-					LLPipeline::RENDER_TYPE_TREE, 
-					LLPipeline::RENDER_TYPE_TERRAIN,
-					LLPipeline::RENDER_TYPE_WATER,
-					LLPipeline::RENDER_TYPE_VOIDWATER,
-					LLPipeline::RENDER_TYPE_PASS_ALPHA,
-					LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK,
-					LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK,
-					LLPipeline::RENDER_TYPE_PASS_GRASS,
-					LLPipeline::RENDER_TYPE_PASS_SIMPLE,
-					LLPipeline::RENDER_TYPE_PASS_BUMP,
-					LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT,
-					LLPipeline::RENDER_TYPE_PASS_SHINY,
-					LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY,
-					LLPipeline::RENDER_TYPE_PASS_MATERIAL,
-					LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA,
-					LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK,
-					LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE,
-					LLPipeline::RENDER_TYPE_PASS_SPECMAP,
-					LLPipeline::RENDER_TYPE_PASS_SPECMAP_BLEND,
-					LLPipeline::RENDER_TYPE_PASS_SPECMAP_MASK,
-					LLPipeline::RENDER_TYPE_PASS_SPECMAP_EMISSIVE,
-					LLPipeline::RENDER_TYPE_PASS_NORMMAP,
-					LLPipeline::RENDER_TYPE_PASS_NORMMAP_BLEND,
-					LLPipeline::RENDER_TYPE_PASS_NORMMAP_MASK,
-					LLPipeline::RENDER_TYPE_PASS_NORMMAP_EMISSIVE,
-					LLPipeline::RENDER_TYPE_PASS_NORMSPEC,
-					LLPipeline::RENDER_TYPE_PASS_NORMSPEC_BLEND,
-					LLPipeline::RENDER_TYPE_PASS_NORMSPEC_MASK,
-					LLPipeline::RENDER_TYPE_PASS_NORMSPEC_EMISSIVE,
-                    LLPipeline::RENDER_TYPE_PASS_ALPHA_MASK_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_SIMPLE_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_BUMP_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_SHINY_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_FULLBRIGHT_SHINY_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_BLEND_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_MASK_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_SPECMAP_EMISSIVE_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_BLEND_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_MASK_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_NORMMAP_EMISSIVE_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_BLEND_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_MASK_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_NORMSPEC_EMISSIVE_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_GLTF_PBR,
-                    LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_RIGGED,
-                    LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_ALPHA_MASK,
-                    LLPipeline::RENDER_TYPE_PASS_GLTF_PBR_ALPHA_MASK_RIGGED,
-					END_RENDER_TYPES);
+            shadow_cam.setOrigin(0,0,0);
 
-	gGL.setColorMask(false, false);
+            set_current_modelview(LLMatrix4a(view[j].m));
+            set_current_projection(LLMatrix4a(proj[j].m));
 
-    LLEnvironment& environment = LLEnvironment::instance();
+            LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE);
 
-	//get sun view matrix
-	
-	//store current projection/modelview matrix
-	glh::matrix4f saved_proj = glh::matrix4f((F32*)get_current_projection().getF32ptr());
-	glh::matrix4f saved_view = glh::matrix4f((F32*)get_current_modelview().getF32ptr());
-	glh::matrix4f inv_view = saved_view.inverse();
+            //shadow_cam.ignoreAgentFrustumPlane(LLCamera::AGENT_PLANE_NEAR);
+            shadow_cam.getAgentPlane(LLCamera::AGENT_PLANE_NEAR).set(shadow_near_clip);
 
-	glh::matrix4f view[6];
-	glh::matrix4f proj[6];
-	
-    LLVector3 caster_dir(environment.getIsSunUp() ? mSunDir : mMoonDir);
+            //translate and scale to from [-1, 1] to [0, 1]
+            glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f,
+                            0.f, 0.5f, 0.f, 0.5f,
+                            0.f, 0.f, 0.5f, 0.5f,
+                            0.f, 0.f, 0.f, 1.f);
 
-	//put together a universal "near clip" plane for shadow frusta
-	LLPlane shadow_near_clip;
-	{
-        LLVector3 p = camera.getOrigin(); // gAgent.getPositionAgent();
-		p += caster_dir * RenderFarClip*2.f;
-		shadow_near_clip.setVec(p, caster_dir);
-	}
-
-	LLVector3 lightDir = -caster_dir;
-	lightDir.normVec();
-
-	glh::vec3f light_dir(lightDir.mV);
-
-	//create light space camera matrix
-	
-	LLVector3 at = lightDir;
-
-	LLVector3 up = camera.getAtAxis();
-
-	if (fabsf(up*lightDir) > 0.75f)
-	{
-		up = camera.getUpAxis();
-	}
-
-	up.normVec();
-	at.normVec();
-	
-	
-	LLCamera main_camera = camera;
-	
-	F32 near_clip = 0.f;
-	{
-		//get visible point cloud
-		std::vector<LLVector3> fp;
-
-		main_camera.calcAgentFrustumPlanes(main_camera.mAgentFrustum);
-		
-		LLVector3 min,max;
-		getVisiblePointCloud(main_camera,min,max,fp);
-
-		if (fp.empty())
-		{
-			if (!hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
-			{
-				mShadowCamera[0] = main_camera;
-				mShadowExtents[0][0] = min;
-				mShadowExtents[0][1] = max;
-
-				mShadowFrustPoints[0].clear();
-				mShadowFrustPoints[1].clear();
-				mShadowFrustPoints[2].clear();
-				mShadowFrustPoints[3].clear();
-			}
-			popRenderTypeMask();
-
-			if (!skip_avatar_update)
-			{
-				gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode());
-			}
-
-			return;
-		}
-
-		//get good split distances for frustum
-		for (U32 i = 0; i < fp.size(); ++i)
-		{
-			glh::vec3f v(fp[i].mV);
-			saved_view.mult_matrix_vec(v);
-			fp[i].setVec(v.v);
-		}
-
-		min = fp[0];
-		max = fp[0];
-
-		//get camera space bounding box
-		for (U32 i = 1; i < fp.size(); ++i)
-		{
-			update_min_max(min, max, fp[i]);
-		}
-
-		near_clip    = llclamp(-max.mV[2], 0.01f, 4.0f);
-		F32 far_clip = llclamp(-min.mV[2]*2.f, 16.0f, 512.0f);
-
-		//far_clip = llmin(far_clip, 128.f);
-		far_clip = llmin(far_clip, camera.getFar());
-
-		F32 range = far_clip-near_clip;
-
-		LLVector3 split_exp = RenderShadowSplitExponent;
-
-		F32 da = 1.f-llmax( fabsf(lightDir*up), fabsf(lightDir*camera.getLeftAxis()) );
-		
-		da = powf(da, split_exp.mV[2]);
-
-		F32 sxp = split_exp.mV[1] + (split_exp.mV[0]-split_exp.mV[1])*da;
-		
-		for (U32 i = 0; i < 4; ++i)
-		{
-			F32 x = (F32)(i+1)/4.f;
-			x = powf(x, sxp);
-			mSunClipPlanes.mV[i] = near_clip+range*x;
-		}
-
-		mSunClipPlanes.mV[0] *= 1.25f; //bump back first split for transition padding
-	}
+            set_current_modelview(LLMatrix4a(view[j].m));
+            set_current_projection(LLMatrix4a(proj[j].m));
 
-    if (gCubeSnapshot)
-    { // stretch clip planes for reflection probe renders to reduce number of shadow passes
-        mSunClipPlanes.mV[1] = mSunClipPlanes.mV[2];
-        mSunClipPlanes.mV[2] = mSunClipPlanes.mV[3];
-        mSunClipPlanes.mV[3] *= 1.5f;
-    }
+            set_last_modelview(LLMatrix4a(mShadowModelview[j].m));
+            set_last_projection(LLMatrix4a(mShadowProjection[j].m));
 
+            mShadowModelview[j] = view[j];
+            mShadowProjection[j] = proj[j];
+            mSunShadowMatrix[j] = trans*proj[j]*view[j]*inv_view;
 
-	// convenience array of 4 near clip plane distances
-	F32 dist[] = { near_clip, mSunClipPlanes.mV[0], mSunClipPlanes.mV[1], mSunClipPlanes.mV[2], mSunClipPlanes.mV[3] };
-	
-	if (mSunDiffuse == LLColor4::black)
-	{ //sun diffuse is totally black shadows don't matter
-        skipRenderingShadows();
-	}
-	else
-	{
-        for (S32 j = 0; j < (gCubeSnapshot ? 2 : 4); j++)
-		{
-			if (!hasRenderDebugMask(RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
-			{
-				mShadowFrustPoints[j].clear();
-			}
+            stop_glerror();
 
-			LLViewerCamera::sCurCameraID = (LLViewerCamera::eCameraID)(LLViewerCamera::CAMERA_SUN_SHADOW0+j);
+            mRT->shadow[j].bindTarget();
+            mRT->shadow[j].getViewport(gGLViewport);
+            mRT->shadow[j].clear();
 
-			//restore render matrices
-			set_current_modelview(LLMatrix4a(saved_view.m));
-			set_current_projection(LLMatrix4a(saved_proj.m));
+            {
+                static LLCullResult result[4];
+                renderShadow(view[j], proj[j], shadow_cam, result[j], true);
+            }
 
-			LLVector3 eye = camera.getOrigin();
-            llassert(eye.isFinite());
+            mRT->shadow[j].flush();
 
-			//camera used for shadow cull/render
-			LLCamera shadow_cam;
-		
-			//create world space camera frustum for this split
-			shadow_cam = camera;
-			shadow_cam.setFar(16.f);
-	
-			LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE);
-
-			LLVector3* frust = shadow_cam.mAgentFrustum;
-
-			LLVector3 pn = shadow_cam.getAtAxis();
-		
-			LLVector3 min, max;
-
-			//construct 8 corners of split frustum section
-			for (U32 i = 0; i < 4; i++)
-			{
-				LLVector3 delta = frust[i+4]-eye;
-				delta += (frust[i+4]-frust[(i+2)%4+4])*0.05f;
-				delta.normVec();
-				F32 dp = delta*pn;
-				frust[i] = eye + (delta*dist[j]*0.75f)/dp;
-				frust[i+4] = eye + (delta*dist[j+1]*1.25f)/dp;
-			}
-						
-			shadow_cam.calcAgentFrustumPlanes(frust);
-			shadow_cam.mFrustumCornerDist = 0.f;
-		
-			if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
-			{
-				mShadowCamera[j] = shadow_cam;
-			}
-
-			std::vector<LLVector3> fp;
-
-			if (!gPipeline.getVisiblePointCloud(shadow_cam, min, max, fp, lightDir)
-                || j > RenderShadowSplits)
-			{
-				//no possible shadow receivers
-                if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
-				{
-					mShadowExtents[j][0] = LLVector3();
-					mShadowExtents[j][1] = LLVector3();
-					mShadowCamera[j+4] = shadow_cam;
-				}
-
-				mRT->shadow[j].bindTarget();
-				{
-					LLGLDepthTest depth(GL_TRUE);
-					mRT->shadow[j].clear();
-				}
-				mRT->shadow[j].flush();
-
-				mShadowError.mV[j] = 0.f;
-				mShadowFOV.mV[j] = 0.f;
-
-				continue;
-			}
-
-			if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
-			{
-				mShadowExtents[j][0] = min;
-				mShadowExtents[j][1] = max;
-				mShadowFrustPoints[j] = fp;
-			}
-				
-
-			//find a good origin for shadow projection
-			LLVector3 origin;
-
-			//get a temporary view projection
-			view[j] = look(camera.getOrigin(), lightDir, -up);
-
-			std::vector<LLVector3> wpf;
-
-			for (U32 i = 0; i < fp.size(); i++)
-			{
-				glh::vec3f p = glh::vec3f(fp[i].mV);
-				view[j].mult_matrix_vec(p);
-				wpf.push_back(LLVector3(p.v));
-			}
-
-			min = wpf[0];
-			max = wpf[0];
-
-			for (U32 i = 0; i < fp.size(); ++i)
-			{ //get AABB in camera space
-				update_min_max(min, max, wpf[i]);
-			}
-
-			// Construct a perspective transform with perspective along y-axis that contains
-			// points in wpf
-			//Known:
-			// - far clip plane
-			// - near clip plane
-			// - points in frustum
-			//Find:
-			// - origin
-
-			//get some "interesting" points of reference
-			LLVector3 center = (min+max)*0.5f;
-			LLVector3 size = (max-min)*0.5f;
-			LLVector3 near_center = center;
-			near_center.mV[1] += size.mV[1]*2.f;
-		
-		
-			//put all points in wpf in quadrant 0, reletive to center of min/max
-			//get the best fit line using least squares
-			F32 bfm = 0.f;
-			F32 bfb = 0.f;
-
-			for (U32 i = 0; i < wpf.size(); ++i)
-			{
-				wpf[i] -= center;
-				wpf[i].mV[0] = fabsf(wpf[i].mV[0]);
-				wpf[i].mV[2] = fabsf(wpf[i].mV[2]);
-			}
-
-			if (!wpf.empty())
-			{ 
-				F32 sx = 0.f;
-				F32 sx2 = 0.f;
-				F32 sy = 0.f;
-				F32 sxy = 0.f;
-			
-				for (U32 i = 0; i < wpf.size(); ++i)
-				{		
-					sx += wpf[i].mV[0];
-					sx2 += wpf[i].mV[0]*wpf[i].mV[0];
-					sy += wpf[i].mV[1];
-					sxy += wpf[i].mV[0]*wpf[i].mV[1]; 
-				}
-
-				bfm = (sy*sx-wpf.size()*sxy)/(sx*sx-wpf.size()*sx2);
-				bfb = (sx*sxy-sy*sx2)/(sx*sx-bfm*sx2);
-			}
-		
-			{
-				// best fit line is y=bfm*x+bfb
-		
-				//find point that is furthest to the right of line
-				F32 off_x = -1.f;
-				LLVector3 lp;
-
-				for (U32 i = 0; i < wpf.size(); ++i)
-				{
-					//y = bfm*x+bfb
-					//x = (y-bfb)/bfm
-					F32 lx = (wpf[i].mV[1]-bfb)/bfm;
-
-					lx = wpf[i].mV[0]-lx;
-				
-					if (off_x < lx)
-					{
-						off_x = lx;
-						lp = wpf[i];
-					}
-				}
-
-				//get line with slope bfm through lp
-				// bfb = y-bfm*x
-				bfb = lp.mV[1]-bfm*lp.mV[0];
-
-				//calculate error
-				mShadowError.mV[j] = 0.f;
-
-				for (U32 i = 0; i < wpf.size(); ++i)
-				{
-					F32 lx = (wpf[i].mV[1]-bfb)/bfm;
-					mShadowError.mV[j] += fabsf(wpf[i].mV[0]-lx);
-				}
-
-				mShadowError.mV[j] /= wpf.size();
-				mShadowError.mV[j] /= size.mV[0];
-
-				if (mShadowError.mV[j] > RenderShadowErrorCutoff)
-				{ //just use ortho projection
-					mShadowFOV.mV[j] = -1.f;
-					origin.clearVec();
-					proj[j] = gl_ortho(min.mV[0], max.mV[0],
-										min.mV[1], max.mV[1],
-										-max.mV[2], -min.mV[2]);
-				}
-				else
-				{
-					//origin is where line x = 0;
-					origin.setVec(0,bfb,0);
-
-					F32 fovz = 1.f;
-					F32 fovx = 1.f;
-				
-					LLVector3 zp;
-					LLVector3 xp;
-
-					for (U32 i = 0; i < wpf.size(); ++i)
-					{
-						LLVector3 atz = wpf[i]-origin;
-						atz.mV[0] = 0.f;
-						atz.normVec();
-						if (fovz > -atz.mV[1])
-						{
-							zp = wpf[i];
-							fovz = -atz.mV[1];
-						}
-					
-						LLVector3 atx = wpf[i]-origin;
-						atx.mV[2] = 0.f;
-						atx.normVec();
-						if (fovx > -atx.mV[1])
-						{
-							fovx = -atx.mV[1];
-							xp = wpf[i];
-						}
-					}
-
-					fovx = acos(fovx);
-					fovz = acos(fovz);
-
-					F32 cutoff = llmin((F32) RenderShadowFOVCutoff, 1.4f);
-				
-					mShadowFOV.mV[j] = fovx;
-				
-					if (fovx < cutoff && fovz > cutoff)
-					{
-						//x is a good fit, but z is too big, move away from zp enough so that fovz matches cutoff
-						F32 d = zp.mV[2]/tan(cutoff);
-						F32 ny = zp.mV[1] + fabsf(d);
-
-						origin.mV[1] = ny;
-
-						fovz = 1.f;
-						fovx = 1.f;
-
-						for (U32 i = 0; i < wpf.size(); ++i)
-						{
-							LLVector3 atz = wpf[i]-origin;
-							atz.mV[0] = 0.f;
-							atz.normVec();
-							fovz = llmin(fovz, -atz.mV[1]);
-
-							LLVector3 atx = wpf[i]-origin;
-							atx.mV[2] = 0.f;
-							atx.normVec();
-							fovx = llmin(fovx, -atx.mV[1]);
-						}
-
-						fovx = acos(fovx);
-						fovz = acos(fovz);
-
-						mShadowFOV.mV[j] = cutoff;
-					}
-
-				
-					origin += center;
-			
-					F32 ynear = -(max.mV[1]-origin.mV[1]);
-					F32 yfar = -(min.mV[1]-origin.mV[1]);
-				
-					if (ynear < 0.1f) //keep a sensible near clip plane
-					{
-						F32 diff = 0.1f-ynear;
-						origin.mV[1] += diff;
-						ynear += diff;
-						yfar += diff;
-					}
-								
-					if (fovx > cutoff)
-					{ //just use ortho projection
-						origin.clearVec();
-						mShadowError.mV[j] = -1.f;
-						proj[j] = gl_ortho(min.mV[0], max.mV[0],
-								min.mV[1], max.mV[1],
-								-max.mV[2], -min.mV[2]);
-					}
-					else
-					{
-						//get perspective projection
-						view[j] = view[j].inverse();
-                        //llassert(origin.isFinite());
+            if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
+            {
+                mShadowCamera[j+4] = shadow_cam;
+            }
+        }
+    }
 
-						glh::vec3f origin_agent(origin.mV);
-					
-						//translate view to origin
-						view[j].mult_matrix_vec(origin_agent);
+    //hack to disable projector shadows
+    bool gen_shadow = RenderShadowDetail > 1;
 
-						eye = LLVector3(origin_agent.v);
-                        //llassert(eye.isFinite());
-						if (!hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
-						{
-							mShadowFrustOrigin[j] = eye;
-						}
-				
-						view[j] = look(LLVector3(origin_agent.v), lightDir, -up);
-
-						F32 fx = 1.f/tanf(fovx);
-						F32 fz = 1.f/tanf(fovz);
-
-						proj[j] = glh::matrix4f(-fx, 0, 0, 0,
-												0, (yfar+ynear)/(ynear-yfar), 0, (2.f*yfar*ynear)/(ynear-yfar),
-												0, 0, -fz, 0,
-												0, -1.f, 0, 0);
-					}
-				}
-			}
-
-			//shadow_cam.setFar(128.f);
-			shadow_cam.setOriginAndLookAt(eye, up, center);
-
-			shadow_cam.setOrigin(0,0,0);
-
-			set_current_modelview(LLMatrix4a(view[j].m));
-			set_current_projection(LLMatrix4a(proj[j].m));
-
-			LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE);
-
-			//shadow_cam.ignoreAgentFrustumPlane(LLCamera::AGENT_PLANE_NEAR);
-			shadow_cam.getAgentPlane(LLCamera::AGENT_PLANE_NEAR).set(shadow_near_clip);
-
-			//translate and scale to from [-1, 1] to [0, 1]
-			glh::matrix4f trans(0.5f, 0.f, 0.f, 0.5f,
-							0.f, 0.5f, 0.f, 0.5f,
-							0.f, 0.f, 0.5f, 0.5f,
-							0.f, 0.f, 0.f, 1.f);
-
-			set_current_modelview(LLMatrix4a(view[j].m));
-			set_current_projection(LLMatrix4a(proj[j].m));
-
-			set_last_modelview(LLMatrix4a(mShadowModelview[j].m));
-			set_last_projection(LLMatrix4a(mShadowProjection[j].m));
-
-			mShadowModelview[j] = view[j];
-			mShadowProjection[j] = proj[j];
-			mSunShadowMatrix[j] = trans*proj[j]*view[j]*inv_view;
-		
-			stop_glerror();
-
-			mRT->shadow[j].bindTarget();
-			mRT->shadow[j].getViewport(gGLViewport);
-			mRT->shadow[j].clear();
-		
-			{
-				static LLCullResult result[4];
-				renderShadow(view[j], proj[j], shadow_cam, result[j], true);
-			}
-
-			mRT->shadow[j].flush();
- 
-			if (!gPipeline.hasRenderDebugMask(LLPipeline::RENDER_DEBUG_SHADOW_FRUSTA) && !gCubeSnapshot)
-			{
-				mShadowCamera[j+4] = shadow_cam;
-			}
-		}
-	}
-
-	//hack to disable projector shadows 
-	bool gen_shadow = RenderShadowDetail > 1;
-
-	if (gen_shadow)
-	{
+    if (gen_shadow)
+    {
         if (!gCubeSnapshot) //skip updating spot shadow maps during cubemap updates
         {
             LLTrace::CountStatHandle<>* velocity_stat = LLViewerCamera::getVelocityStat();
@@ -10126,7 +10126,7 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
             mSunShadowMatrix[i + 4] = trans * proj[i + 4] * view[i + 4] * inv_view;
 
             gGLLastModelView = LLMatrix4a(mShadowModelview[i + 4].m);
-			gGLLastProjection = LLMatrix4a(mShadowProjection[i + 4].m);
+            gGLLastProjection = LLMatrix4a(mShadowProjection[i + 4].m);
 
             mShadowModelview[i + 4] = view[i + 4];
             mShadowProjection[i + 4] = proj[i + 4];
@@ -10140,7 +10140,7 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
                 LLViewerCamera::updateFrustumPlanes(shadow_cam, FALSE, FALSE, TRUE);
 
                 //
-                
+
                 mSpotShadow[i].bindTarget();
                 mSpotShadow[i].getViewport(gGLViewport);
                 mSpotShadow[i].clear();
@@ -10158,55 +10158,55 @@ void LLPipeline::generateSunShadow(LLCamera& camera)
                 mSpotShadow[i].flush();
             }
         }
-	}
-	else
-	{ //no spotlight shadows
-		mShadowSpotLight[0] = mShadowSpotLight[1] = NULL;
-	}
+    }
+    else
+    { //no spotlight shadows
+        mShadowSpotLight[0] = mShadowSpotLight[1] = NULL;
+    }
 
 
-	if (!CameraOffset)
-	{
-		set_current_modelview(LLMatrix4a(saved_view.m));
-		set_current_projection(LLMatrix4a(saved_proj.m));
-	}
-	else
-	{
-		set_current_modelview(LLMatrix4a(view[1].m));
-		set_current_projection(LLMatrix4a(proj[1].m));
-		gGL.loadMatrix(view[1].m);
-		gGL.matrixMode(LLRender::MM_PROJECTION);
-		gGL.loadMatrix(proj[1].m);
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-	}
-	gGL.setColorMask(true, true);
+    if (!CameraOffset)
+    {
+        set_current_modelview(LLMatrix4a(saved_view.m));
+        set_current_projection(LLMatrix4a(saved_proj.m));
+    }
+    else
+    {
+        set_current_modelview(LLMatrix4a(view[1].m));
+        set_current_projection(LLMatrix4a(proj[1].m));
+        gGL.loadMatrix(view[1].m);
+        gGL.matrixMode(LLRender::MM_PROJECTION);
+        gGL.loadMatrix(proj[1].m);
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+    }
+    gGL.setColorMask(true, true);
 
-	{
-		gGLLastModelView = last_modelview;
-		gGLLastProjection = last_projection;
-	}
+    {
+        gGLLastModelView = last_modelview;
+        gGLLastProjection = last_projection;
+    }
 
-	popRenderTypeMask();
+    popRenderTypeMask();
 
-	if (!skip_avatar_update)
-	{
-		gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode());
-	}
+    if (!skip_avatar_update)
+    {
+        gAgentAvatarp->updateAttachmentVisibility(gAgentCamera.getCameraMode());
+    }
 }
 
 void LLPipeline::renderGroups(LLRenderPass* pass, U32 type, bool texture)
 {
-	for (LLCullResult::sg_iterator i = sCull->beginVisibleGroups(); i != sCull->endVisibleGroups(); ++i)
-	{
-		LLSpatialGroup* group = *i;
-		if (!group->isDead() &&
-			(!sUseOcclusion || !group->isOcclusionState(LLSpatialGroup::OCCLUDED)) &&
-			gPipeline.hasRenderType(group->getSpatialPartition()->mDrawableType) &&
-			group->mDrawMap.find(type) != group->mDrawMap.end())
-		{
-			pass->renderGroup(group,type,texture);
-		}
-	}
+    for (LLCullResult::sg_iterator i = sCull->beginVisibleGroups(); i != sCull->endVisibleGroups(); ++i)
+    {
+        LLSpatialGroup* group = *i;
+        if (!group->isDead() &&
+            (!sUseOcclusion || !group->isOcclusionState(LLSpatialGroup::OCCLUDED)) &&
+            gPipeline.hasRenderType(group->getSpatialPartition()->mDrawableType) &&
+            group->mDrawMap.find(type) != group->mDrawMap.end())
+        {
+            pass->renderGroup(group,type,texture);
+        }
+    }
 }
 
 void LLPipeline::renderRiggedGroups(LLRenderPass* pass, U32 type, bool texture)
@@ -10254,8 +10254,8 @@ void LLPipeline::profileAvatar(LLVOAvatar* avatar, bool profile_attachments)
 
         avatar->readProfileQuery(5); // allow up to 5 frames of latency
     }
-    else 
-    { 
+    else
+    {
         // profile attachments one at a time
         LLVOAvatar::attachment_map_t::iterator iter;
         LLVOAvatar::attachment_map_t::iterator begin = avatar->mAttachmentPoints.begin();
@@ -10298,37 +10298,37 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar, bool preview_avatar, bool
 {
     LL_PROFILE_ZONE_SCOPED_CATEGORY_PIPELINE;
     LL_PROFILE_GPU_ZONE("generateImpostor");
-	LLGLState::checkStates();
-
-	static LLCullResult result;
-	result.clear();
-	grabReferences(result);
-	
-	if (!avatar || !avatar->mDrawable)
-	{
+    LLGLState::checkStates();
+
+    static LLCullResult result;
+    result.clear();
+    grabReferences(result);
+
+    if (!avatar || !avatar->mDrawable)
+    {
         LL_WARNS_ONCE("AvatarRenderPipeline") << "Avatar is " << (avatar ? "not drawable" : "null") << LL_ENDL;
-		return;
-	}
+        return;
+    }
     LL_DEBUGS_ONCE("AvatarRenderPipeline") << "Avatar " << avatar->getID() << " is drawable" << LL_ENDL;
 
-	assertInitialized();
+    assertInitialized();
 
     // previews can't be muted or impostered
-	bool visually_muted = !for_profile && !preview_avatar && avatar->isVisuallyMuted();
+    bool visually_muted = !for_profile && !preview_avatar && avatar->isVisuallyMuted();
     LL_DEBUGS_ONCE("AvatarRenderPipeline") << "Avatar " << avatar->getID()
                               << " is " << ( visually_muted ? "" : "not ") << "visually muted"
                               << LL_ENDL;
     pushRenderTypeMask();
 
     if (visually_muted)
-	{
+    {
         // only show jelly doll geometry
-		andRenderTypeMask(LLPipeline::RENDER_TYPE_AVATAR,
-							LLPipeline::RENDER_TYPE_CONTROL_AV,
-							END_RENDER_TYPES);
-	}
-	else
-	{
+        andRenderTypeMask(LLPipeline::RENDER_TYPE_AVATAR,
+                            LLPipeline::RENDER_TYPE_CONTROL_AV,
+                            END_RENDER_TYPES);
+    }
+    else
+    {
         //hide world geometry
         clearRenderTypeMask(
             RENDER_TYPE_SKY,
@@ -10347,25 +10347,25 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar, bool preview_avatar, bool
             RENDER_TYPE_HUD_PARTICLES,
             END_RENDER_TYPES
          );
-	}
-	
+    }
+
     if (specific_attachment && specific_attachment->isHUDAttachment())
     { //enable HUD rendering
         setRenderTypeMask(RENDER_TYPE_HUD, END_RENDER_TYPES);
     }
 
-	S32 occlusion = sUseOcclusion;
-	sUseOcclusion = 0;
+    S32 occlusion = sUseOcclusion;
+    sUseOcclusion = 0;
 
-	sReflectionRender = ! sRenderDeferred;
+    sReflectionRender = ! sRenderDeferred;
 
-	sShadowRender = true;
-	sImpostorRender = true;
+    sShadowRender = true;
+    sImpostorRender = true;
 
-	LLViewerCamera* viewer_camera = LLViewerCamera::getInstance();
+    LLViewerCamera* viewer_camera = LLViewerCamera::getInstance();
 
-	{
-		markVisible(avatar->mDrawable, *viewer_camera);
+    {
+        markVisible(avatar->mDrawable, *viewer_camera);
 
         if (preview_avatar)
         {
@@ -10438,70 +10438,70 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar, bool preview_avatar, bool
                 }
             }
         }
-	}
+    }
+
+    stateSort(*LLViewerCamera::getInstance(), result);
 
-	stateSort(*LLViewerCamera::getInstance(), result);
-	
-	LLCamera camera = *viewer_camera;
-	LLVector2 tdim;
-	U32 resY = 0;
-	U32 resX = 0;
+    LLCamera camera = *viewer_camera;
+    LLVector2 tdim;
+    U32 resY = 0;
+    U32 resX = 0;
 
     if (!preview_avatar)
-	{
-		const LLVector4a* ext = avatar->mDrawable->getSpatialExtents();
-		LLVector3 pos(avatar->getRenderPosition()+avatar->getImpostorOffset());
-
-		camera.lookAt(viewer_camera->getOrigin(), pos, viewer_camera->getUpAxis());
-	
-		LLVector4a half_height;
-		half_height.setSub(ext[1], ext[0]);
-		half_height.mul(0.5f);
-
-		LLVector4a left;
-		left.load3(camera.getLeftAxis().mV);
-		left.mul(left);
-		llassert(left.dot3(left).getF32() > F_APPROXIMATELY_ZERO);
-		left.normalize3fast();
-
-		LLVector4a up;
-		up.load3(camera.getUpAxis().mV);
-		up.mul(up);
-		llassert(up.dot3(up).getF32() > F_APPROXIMATELY_ZERO);
-		up.normalize3fast();
-
-		tdim.mV[0] = fabsf(half_height.dot3(left).getF32());
-		tdim.mV[1] = fabsf(half_height.dot3(up).getF32());
-
-		gGL.matrixMode(LLRender::MM_PROJECTION);
-		gGL.pushMatrix();
-	
-		F32 distance = (pos-camera.getOrigin()).length();
-		F32 fov = atanf(tdim.mV[1]/distance)*2.f*RAD_TO_DEG;
-		F32 aspect = tdim.mV[0]/tdim.mV[1];
-		LLMatrix4a persp = ALGLMath::genPersp(fov, aspect, 1.f, 256.f);
-		set_current_projection(persp);
-		gGL.loadMatrix(persp);
-
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-		gGL.pushMatrix();
-		LLMatrix4a mat;
-		camera.getOpenGLTransform(mat.getF32ptr());
-
-		mat.setMul(OGL_TO_CFR_ROTATION_4A, mat);
-
-		gGL.loadMatrix(mat);
-		set_current_modelview(mat);
-
-		glClearColor(0.0f,0.0f,0.0f,0.0f);
-		gGL.setColorMask(true, true);
-	
-		// get the number of pixels per angle
-		F32 pa = gViewerWindow->getWindowHeightRaw() / (RAD_TO_DEG * viewer_camera->getView());
-
-		//get resolution based on angle width and height of impostor (double desired resolution to prevent aliasing)
-		resY = llmin(nhpo2((U32) (fov*pa)), (U32) 512);
-		resX = llmin(nhpo2((U32) (atanf(tdim.mV[0]/distance)*2.f*RAD_TO_DEG*pa)), (U32) 512);
+    {
+        const LLVector4a* ext = avatar->mDrawable->getSpatialExtents();
+        LLVector3 pos(avatar->getRenderPosition()+avatar->getImpostorOffset());
+
+        camera.lookAt(viewer_camera->getOrigin(), pos, viewer_camera->getUpAxis());
+
+        LLVector4a half_height;
+        half_height.setSub(ext[1], ext[0]);
+        half_height.mul(0.5f);
+
+        LLVector4a left;
+        left.load3(camera.getLeftAxis().mV);
+        left.mul(left);
+        llassert(left.dot3(left).getF32() > F_APPROXIMATELY_ZERO);
+        left.normalize3fast();
+
+        LLVector4a up;
+        up.load3(camera.getUpAxis().mV);
+        up.mul(up);
+        llassert(up.dot3(up).getF32() > F_APPROXIMATELY_ZERO);
+        up.normalize3fast();
+
+        tdim.mV[0] = fabsf(half_height.dot3(left).getF32());
+        tdim.mV[1] = fabsf(half_height.dot3(up).getF32());
+
+        gGL.matrixMode(LLRender::MM_PROJECTION);
+        gGL.pushMatrix();
+
+        F32 distance = (pos-camera.getOrigin()).length();
+        F32 fov = atanf(tdim.mV[1]/distance)*2.f*RAD_TO_DEG;
+        F32 aspect = tdim.mV[0]/tdim.mV[1];
+        LLMatrix4a persp = ALGLMath::genPersp(fov, aspect, 1.f, 256.f);
+        set_current_projection(persp);
+        gGL.loadMatrix(persp);
+
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+        gGL.pushMatrix();
+        LLMatrix4a mat;
+        camera.getOpenGLTransform(mat.getF32ptr());
+
+        mat.setMul(OGL_TO_CFR_ROTATION_4A, mat);
+
+        gGL.loadMatrix(mat);
+        set_current_modelview(mat);
+
+        glClearColor(0.0f,0.0f,0.0f,0.0f);
+        gGL.setColorMask(true, true);
+
+        // get the number of pixels per angle
+        F32 pa = gViewerWindow->getWindowHeightRaw() / (RAD_TO_DEG * viewer_camera->getView());
+
+        //get resolution based on angle width and height of impostor (double desired resolution to prevent aliasing)
+        resY = llmin(nhpo2((U32) (fov*pa)), (U32) 512);
+        resX = llmin(nhpo2((U32) (atanf(tdim.mV[0]/distance)*2.f*RAD_TO_DEG*pa)), (U32) 512);
 
         if (!for_profile)
         {
@@ -10525,14 +10525,14 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar, bool preview_avatar, bool
 
             avatar->mImpostor.bindTarget();
         }
-	}
+    }
 
-	F32 old_alpha = LLDrawPoolAvatar::sMinimumAlpha;
+    F32 old_alpha = LLDrawPoolAvatar::sMinimumAlpha;
 
-	if (visually_muted)
-	{ //disable alpha masking for muted avatars (get whole skin silhouette)
-		LLDrawPoolAvatar::sMinimumAlpha = 0.f;
-	}
+    if (visually_muted)
+    { //disable alpha masking for muted avatars (get whole skin silhouette)
+        LLDrawPoolAvatar::sMinimumAlpha = 0.f;
+    }
 
     if (preview_avatar || for_profile)
     {
@@ -10541,91 +10541,91 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar, bool preview_avatar, bool
         renderGeomPostDeferred(camera);
     }
     else
-	{
-		avatar->mImpostor.clear();
-		renderGeomDeferred(camera);
+    {
+        avatar->mImpostor.clear();
+        renderGeomDeferred(camera);
 
-		renderGeomPostDeferred(camera);		
+        renderGeomPostDeferred(camera);
 
-		// Shameless hack time: render it all again,
-		// this time writing the depth
-		// values we need to generate the alpha mask below
-		// while preserving the alpha-sorted color rendering
-		// from the previous pass
-		//
-		sImpostorRenderAlphaDepthPass = true;
-		// depth-only here...
-		//
-		gGL.setColorMask(false,false);
-		renderGeomPostDeferred(camera);
+        // Shameless hack time: render it all again,
+        // this time writing the depth
+        // values we need to generate the alpha mask below
+        // while preserving the alpha-sorted color rendering
+        // from the previous pass
+        //
+        sImpostorRenderAlphaDepthPass = true;
+        // depth-only here...
+        //
+        gGL.setColorMask(false,false);
+        renderGeomPostDeferred(camera);
 
-		sImpostorRenderAlphaDepthPass = false;
+        sImpostorRenderAlphaDepthPass = false;
 
-	}
+    }
 
-	LLDrawPoolAvatar::sMinimumAlpha = old_alpha;
+    LLDrawPoolAvatar::sMinimumAlpha = old_alpha;
 
     if (!for_profile)
-	{ //create alpha mask based on depth buffer (grey out if muted)
-		if (LLPipeline::sRenderDeferred)
-		{
-			GLuint buff = GL_COLOR_ATTACHMENT0;
-			glDrawBuffers(1, &buff);
-		}
-
-		LLGLDisable blend(GL_BLEND);
-
-		if (visually_muted)
-		{
-			gGL.setColorMask(true, true);
-		}
-		else
-		{
-			gGL.setColorMask(false, true);
-		}
-		
-		gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
-
-		LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_GREATER);
-
-		gGL.flush();
-
-		gGL.pushMatrix();
-		gGL.loadIdentity();
-		gGL.matrixMode(LLRender::MM_PROJECTION);
-		gGL.pushMatrix();
-		gGL.loadIdentity();
-
-		static const F32 clip_plane = 0.99999f;
-
-		gDebugProgram.bind();
-
-		if (visually_muted)
-		{	// Visually muted avatar
+    { //create alpha mask based on depth buffer (grey out if muted)
+        if (LLPipeline::sRenderDeferred)
+        {
+            GLuint buff = GL_COLOR_ATTACHMENT0;
+            glDrawBuffers(1, &buff);
+        }
+
+        LLGLDisable blend(GL_BLEND);
+
+        if (visually_muted)
+        {
+            gGL.setColorMask(true, true);
+        }
+        else
+        {
+            gGL.setColorMask(false, true);
+        }
+
+        gGL.getTexUnit(0)->unbind(LLTexUnit::TT_TEXTURE);
+
+        LLGLDepthTest depth(GL_TRUE, GL_FALSE, GL_GREATER);
+
+        gGL.flush();
+
+        gGL.pushMatrix();
+        gGL.loadIdentity();
+        gGL.matrixMode(LLRender::MM_PROJECTION);
+        gGL.pushMatrix();
+        gGL.loadIdentity();
+
+        static const F32 clip_plane = 0.99999f;
+
+        gDebugProgram.bind();
+
+        if (visually_muted)
+        {   // Visually muted avatar
             LLColor4 muted_color(avatar->getMutedAVColor());
             LL_DEBUGS_ONCE("AvatarRenderPipeline") << "Avatar " << avatar->getID() << " MUTED set solid color " << muted_color << LL_ENDL;
-			gGL.diffuseColor4fv( muted_color.mV );
-		}
-		else if (!preview_avatar)
-		{ //grey muted avatar
+            gGL.diffuseColor4fv( muted_color.mV );
+        }
+        else if (!preview_avatar)
+        { //grey muted avatar
             LL_DEBUGS_ONCE("AvatarRenderPipeline") << "Avatar " << avatar->getID() << " MUTED set grey" << LL_ENDL;
-			gGL.diffuseColor4fv(LLColor4::pink.mV );
-		}
+            gGL.diffuseColor4fv(LLColor4::pink.mV );
+        }
 
-		gGL.begin(LLRender::TRIANGLE_STRIP);
-		gGL.vertex3f(-1, -1, clip_plane);
-		gGL.vertex3f(1, -1, clip_plane);
-		gGL.vertex3f(-1, 1, clip_plane);
-		gGL.vertex3f(1, 1, clip_plane);
-		gGL.end();
-		gGL.flush();
+        gGL.begin(LLRender::TRIANGLE_STRIP);
+        gGL.vertex3f(-1, -1, clip_plane);
+        gGL.vertex3f(1, -1, clip_plane);
+        gGL.vertex3f(-1, 1, clip_plane);
+        gGL.vertex3f(1, 1, clip_plane);
+        gGL.end();
+        gGL.flush();
 
-		gDebugProgram.unbind();
+        gDebugProgram.unbind();
 
-		gGL.popMatrix();
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-		gGL.popMatrix();
-	}
+        gGL.popMatrix();
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+        gGL.popMatrix();
+    }
 
     if (!preview_avatar && !for_profile)
     {
@@ -10633,19 +10633,19 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar, bool preview_avatar, bool
         avatar->setImpostorDim(tdim);
     }
 
-	sUseOcclusion = occlusion;
-	sReflectionRender = false;
-	sImpostorRender = false;
-	sShadowRender = false;
-	popRenderTypeMask();
+    sUseOcclusion = occlusion;
+    sReflectionRender = false;
+    sImpostorRender = false;
+    sShadowRender = false;
+    popRenderTypeMask();
 
-	if (!preview_avatar)
-	{
-		gGL.matrixMode(LLRender::MM_PROJECTION);
-		gGL.popMatrix();
-		gGL.matrixMode(LLRender::MM_MODELVIEW);
-		gGL.popMatrix();
-	}
+    if (!preview_avatar)
+    {
+        gGL.matrixMode(LLRender::MM_PROJECTION);
+        gGL.popMatrix();
+        gGL.matrixMode(LLRender::MM_MODELVIEW);
+        gGL.popMatrix();
+    }
 
     if (!preview_avatar && !for_profile)
     {
@@ -10654,62 +10654,62 @@ void LLPipeline::generateImpostor(LLVOAvatar* avatar, bool preview_avatar, bool
         avatar->mLastImpostorUpdateFrameTime = gFrameTimeSeconds;
     }
 
-	LLVertexBuffer::unbind();
-	LLGLState::checkStates();
+    LLVertexBuffer::unbind();
+    LLGLState::checkStates();
 }
 
 bool LLPipeline::hasRenderBatches(const U32 type) const
 {
-	if( !sCull )
-		return {};
+    if( !sCull )
+        return {};
 
-	return sCull->getRenderMapSize(type) > 0;
+    return sCull->getRenderMapSize(type) > 0;
 }
 
 LLCullResult::drawinfo_iterator LLPipeline::beginRenderMap(U32 type)
 {
-	if( !sCull )
-		return {};
+    if( !sCull )
+        return {};
 
-	return sCull->beginRenderMap(type);
+    return sCull->beginRenderMap(type);
 }
 
 LLCullResult::drawinfo_iterator LLPipeline::endRenderMap(U32 type)
 {
-	if( !sCull )
-		return {};
+    if( !sCull )
+        return {};
 
-	return sCull->endRenderMap(type);
+    return sCull->endRenderMap(type);
 }
 
 LLCullResult::sg_iterator LLPipeline::beginAlphaGroups()
 {
-	if( !sCull )
-		return {};
+    if( !sCull )
+        return {};
 
-	return sCull->beginAlphaGroups();
+    return sCull->beginAlphaGroups();
 }
 
 LLCullResult::sg_iterator LLPipeline::endAlphaGroups()
 {
-	if( !sCull )
-		return {};
+    if( !sCull )
+        return {};
 
-	return sCull->endAlphaGroups();
+    return sCull->endAlphaGroups();
 }
 
 LLCullResult::sg_iterator LLPipeline::beginRiggedAlphaGroups()
 {
-	if( !sCull )
-		return {};
+    if( !sCull )
+        return {};
 
     return sCull->beginRiggedAlphaGroups();
 }
 
 LLCullResult::sg_iterator LLPipeline::endRiggedAlphaGroups()
 {
-	if( !sCull )
-		return {};
+    if( !sCull )
+        return {};
 
     return sCull->endRiggedAlphaGroups();
 }
@@ -10719,279 +10719,279 @@ bool LLPipeline::hasRenderType(const U32 type) const
     // STORM-365 : LLViewerJointAttachment::setAttachmentVisibility() is setting type to 0 to actually mean "do not render"
     // We then need to test that value here and return false to prevent attachment to render (in mouselook for instance)
     // TODO: reintroduce RENDER_TYPE_NONE in LLRenderTypeMask and initialize its mRenderTypeEnabled[RENDER_TYPE_NONE] to false explicitely
-	return (type == 0 ? false : mRenderTypeEnabled[type]);
+    return (type == 0 ? false : mRenderTypeEnabled[type]);
 }
 
 void LLPipeline::setRenderTypeMask(U32 type, ...)
 {
-	va_list args;
+    va_list args;
 
-	va_start(args, type);
-	while (type < END_RENDER_TYPES)
-	{
-		mRenderTypeEnabled[type] = true;
-		type = va_arg(args, U32);
-	}
-	va_end(args);
+    va_start(args, type);
+    while (type < END_RENDER_TYPES)
+    {
+        mRenderTypeEnabled[type] = true;
+        type = va_arg(args, U32);
+    }
+    va_end(args);
 
-	if (type > END_RENDER_TYPES)
-	{
-		LL_ERRS() << "Invalid render type." << LL_ENDL;
-	}
+    if (type > END_RENDER_TYPES)
+    {
+        LL_ERRS() << "Invalid render type." << LL_ENDL;
+    }
 }
 
 bool LLPipeline::hasAnyRenderType(U32 type, ...) const
 {
-	va_list args;
+    va_list args;
 
-	va_start(args, type);
-	while (type < END_RENDER_TYPES)
-	{
-		if (mRenderTypeEnabled[type])
-		{
-			va_end(args);
-			return true;
-		}
-		type = va_arg(args, U32);
-	}
-	va_end(args);
+    va_start(args, type);
+    while (type < END_RENDER_TYPES)
+    {
+        if (mRenderTypeEnabled[type])
+        {
+            va_end(args);
+            return true;
+        }
+        type = va_arg(args, U32);
+    }
+    va_end(args);
 
-	if (type > END_RENDER_TYPES)
-	{
-		LL_ERRS() << "Invalid render type." << LL_ENDL;
-	}
+    if (type > END_RENDER_TYPES)
+    {
+        LL_ERRS() << "Invalid render type." << LL_ENDL;
+    }
 
-	return false;
+    return false;
 }
 
 void LLPipeline::pushRenderTypeMask()
 {
-	std::string cur_mask;
-	cur_mask.assign((const char*) mRenderTypeEnabled, sizeof(mRenderTypeEnabled));
-	mRenderTypeEnableStack.push(cur_mask);
+    std::string cur_mask;
+    cur_mask.assign((const char*) mRenderTypeEnabled, sizeof(mRenderTypeEnabled));
+    mRenderTypeEnableStack.push(cur_mask);
 }
 
 void LLPipeline::popRenderTypeMask()
 {
-	if (mRenderTypeEnableStack.empty())
-	{
-		LL_ERRS() << "Depleted render type stack." << LL_ENDL;
-	}
+    if (mRenderTypeEnableStack.empty())
+    {
+        LL_ERRS() << "Depleted render type stack." << LL_ENDL;
+    }
 
-	memcpy(mRenderTypeEnabled, mRenderTypeEnableStack.top().data(), sizeof(mRenderTypeEnabled));
-	mRenderTypeEnableStack.pop();
+    memcpy(mRenderTypeEnabled, mRenderTypeEnableStack.top().data(), sizeof(mRenderTypeEnabled));
+    mRenderTypeEnableStack.pop();
 }
 
 void LLPipeline::andRenderTypeMask(U32 type, ...)
 {
-	va_list args;
+    va_list args;
 
-	bool tmp[NUM_RENDER_TYPES];
-	for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
-	{
-		tmp[i] = false;
-	}
+    bool tmp[NUM_RENDER_TYPES];
+    for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
+    {
+        tmp[i] = false;
+    }
 
-	va_start(args, type);
-	while (type < END_RENDER_TYPES)
-	{
-		if (mRenderTypeEnabled[type]) 
-		{
-			tmp[type] = true;
-		}
+    va_start(args, type);
+    while (type < END_RENDER_TYPES)
+    {
+        if (mRenderTypeEnabled[type])
+        {
+            tmp[type] = true;
+        }
 
-		type = va_arg(args, U32);
-	}
-	va_end(args);
+        type = va_arg(args, U32);
+    }
+    va_end(args);
 
-	if (type > END_RENDER_TYPES)
-	{
-		LL_ERRS() << "Invalid render type." << LL_ENDL;
-	}
+    if (type > END_RENDER_TYPES)
+    {
+        LL_ERRS() << "Invalid render type." << LL_ENDL;
+    }
 
-	for (U32 i = 0; i < LLPipeline::NUM_RENDER_TYPES; ++i)
-	{
-		mRenderTypeEnabled[i] = tmp[i];
-	}
+    for (U32 i = 0; i < LLPipeline::NUM_RENDER_TYPES; ++i)
+    {
+        mRenderTypeEnabled[i] = tmp[i];
+    }
 
 }
 
 void LLPipeline::clearRenderTypeMask(U32 type, ...)
 {
-	va_list args;
+    va_list args;
+
+    va_start(args, type);
+    while (type < END_RENDER_TYPES)
+    {
+        mRenderTypeEnabled[type] = false;
 
-	va_start(args, type);
-	while (type < END_RENDER_TYPES)
-	{
-		mRenderTypeEnabled[type] = false;
-		
-		type = va_arg(args, U32);
-	}
-	va_end(args);
+        type = va_arg(args, U32);
+    }
+    va_end(args);
 
-	if (type > END_RENDER_TYPES)
-	{
-		LL_ERRS() << "Invalid render type." << LL_ENDL;
-	}
+    if (type > END_RENDER_TYPES)
+    {
+        LL_ERRS() << "Invalid render type." << LL_ENDL;
+    }
 }
 
 void LLPipeline::setAllRenderTypes()
 {
-	for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
-	{
-		mRenderTypeEnabled[i] = true;
-	}
+    for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
+    {
+        mRenderTypeEnabled[i] = true;
+    }
 }
 
 void LLPipeline::clearAllRenderTypes()
 {
-	for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
-	{
-		mRenderTypeEnabled[i] = false;
-	}
+    for (U32 i = 0; i < NUM_RENDER_TYPES; ++i)
+    {
+        mRenderTypeEnabled[i] = false;
+    }
 }
 
 void LLPipeline::addDebugBlip(const LLVector3& position, const LLColor4& color)
 {
-	DebugBlip blip(position, color);
-	mDebugBlips.push_back(blip);
+    DebugBlip blip(position, color);
+    mDebugBlips.push_back(blip);
 }
 
 void LLPipeline::hidePermanentObjects( std::vector<U32>& restoreList )
 {
-	//This method is used to hide any vo's from the object list that may have
-	//the permanent flag set.
-	
-	U32 objCnt = gObjectList.getNumObjects();
-	for (U32 i = 0; i < objCnt; ++i)
-	{
-		LLViewerObject* pObject = gObjectList.getObject(i);
-		if ( pObject && pObject->flagObjectPermanent() )
-		{
-			LLDrawable *pDrawable = pObject->mDrawable;
-		
-			if ( pDrawable )
-			{
-				restoreList.push_back( i );
-				hideDrawable( pDrawable );			
-			}
-		}
-	}
-
-	skipRenderingOfTerrain( true );
+    //This method is used to hide any vo's from the object list that may have
+    //the permanent flag set.
+
+    U32 objCnt = gObjectList.getNumObjects();
+    for (U32 i = 0; i < objCnt; ++i)
+    {
+        LLViewerObject* pObject = gObjectList.getObject(i);
+        if ( pObject && pObject->flagObjectPermanent() )
+        {
+            LLDrawable *pDrawable = pObject->mDrawable;
+
+            if ( pDrawable )
+            {
+                restoreList.push_back( i );
+                hideDrawable( pDrawable );
+            }
+        }
+    }
+
+    skipRenderingOfTerrain( true );
 }
 
 void LLPipeline::restorePermanentObjects( const std::vector<U32>& restoreList )
 {
-	//This method is used to restore(unhide) any vo's from the object list that may have
-	//been hidden because their permanency flag was set.
-
-	std::vector<U32>::const_iterator itCurrent	= restoreList.begin();
-	std::vector<U32>::const_iterator itEnd		= restoreList.end();
-	
-	U32 objCnt = gObjectList.getNumObjects();
-
-	while ( itCurrent != itEnd )
-	{
-		U32 index = *itCurrent;
-		LLViewerObject* pObject = NULL;
-		if ( index < objCnt ) 
-		{
-			pObject = gObjectList.getObject( index );
-		}
-		if ( pObject )
-		{
-			LLDrawable *pDrawable = pObject->mDrawable;
-			if ( pDrawable )
-			{
-				pDrawable->clearState( LLDrawable::FORCE_INVISIBLE );
-				unhideDrawable( pDrawable );				
-			}
-		}
-		++itCurrent;
-	}
-	
-	skipRenderingOfTerrain( false );
+    //This method is used to restore(unhide) any vo's from the object list that may have
+    //been hidden because their permanency flag was set.
+
+    std::vector<U32>::const_iterator itCurrent  = restoreList.begin();
+    std::vector<U32>::const_iterator itEnd      = restoreList.end();
+
+    U32 objCnt = gObjectList.getNumObjects();
+
+    while ( itCurrent != itEnd )
+    {
+        U32 index = *itCurrent;
+        LLViewerObject* pObject = NULL;
+        if ( index < objCnt )
+        {
+            pObject = gObjectList.getObject( index );
+        }
+        if ( pObject )
+        {
+            LLDrawable *pDrawable = pObject->mDrawable;
+            if ( pDrawable )
+            {
+                pDrawable->clearState( LLDrawable::FORCE_INVISIBLE );
+                unhideDrawable( pDrawable );
+            }
+        }
+        ++itCurrent;
+    }
+
+    skipRenderingOfTerrain( false );
 }
 
 void LLPipeline::skipRenderingOfTerrain( bool flag )
 {
-	pool_set_t::iterator iter = mPools.begin();
-	while ( iter != mPools.end() )
-	{
-		LLDrawPool* pPool = *iter;		
-		U32 poolType = pPool->getType();					
-		if ( hasRenderType( pPool->getType() ) && poolType == LLDrawPool::POOL_TERRAIN )
-		{
-			pPool->setSkipRenderFlag( flag );			
-		}
-		++iter;
-	}
+    pool_set_t::iterator iter = mPools.begin();
+    while ( iter != mPools.end() )
+    {
+        LLDrawPool* pPool = *iter;
+        U32 poolType = pPool->getType();
+        if ( hasRenderType( pPool->getType() ) && poolType == LLDrawPool::POOL_TERRAIN )
+        {
+            pPool->setSkipRenderFlag( flag );
+        }
+        ++iter;
+    }
 }
 
 void LLPipeline::hideObject( const LLUUID& id )
 {
-	LLViewerObject *pVO = gObjectList.findObject( id );
-	
-	if ( pVO )
-	{
-		LLDrawable *pDrawable = pVO->mDrawable;
-		
-		if ( pDrawable )
-		{
-			hideDrawable( pDrawable );		
-		}		
-	}
+    LLViewerObject *pVO = gObjectList.findObject( id );
+
+    if ( pVO )
+    {
+        LLDrawable *pDrawable = pVO->mDrawable;
+
+        if ( pDrawable )
+        {
+            hideDrawable( pDrawable );
+        }
+    }
 }
 
 void LLPipeline::hideDrawable( LLDrawable *pDrawable )
 {
-	pDrawable->setState( LLDrawable::FORCE_INVISIBLE );
-	markRebuild( pDrawable, LLDrawable::REBUILD_ALL);
-	//hide the children
-	LLViewerObject::const_child_list_t& child_list = pDrawable->getVObj()->getChildren();
-	for ( LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
-		  iter != child_list.end(); iter++ )
-	{
-		LLViewerObject* child = *iter;
-		LLDrawable* drawable = child->mDrawable;					
-		if ( drawable )
-		{
-			drawable->setState( LLDrawable::FORCE_INVISIBLE );
-			markRebuild( drawable, LLDrawable::REBUILD_ALL);
-		}
-	}
+    pDrawable->setState( LLDrawable::FORCE_INVISIBLE );
+    markRebuild( pDrawable, LLDrawable::REBUILD_ALL);
+    //hide the children
+    LLViewerObject::const_child_list_t& child_list = pDrawable->getVObj()->getChildren();
+    for ( LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
+          iter != child_list.end(); iter++ )
+    {
+        LLViewerObject* child = *iter;
+        LLDrawable* drawable = child->mDrawable;
+        if ( drawable )
+        {
+            drawable->setState( LLDrawable::FORCE_INVISIBLE );
+            markRebuild( drawable, LLDrawable::REBUILD_ALL);
+        }
+    }
 }
 void LLPipeline::unhideDrawable( LLDrawable *pDrawable )
 {
-	pDrawable->clearState( LLDrawable::FORCE_INVISIBLE );
-	markRebuild( pDrawable, LLDrawable::REBUILD_ALL);
-	//restore children
-	LLViewerObject::const_child_list_t& child_list = pDrawable->getVObj()->getChildren();
-	for ( LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
-		  iter != child_list.end(); iter++)
-	{
-		LLViewerObject* child = *iter;
-		LLDrawable* drawable = child->mDrawable;					
-		if ( drawable )
-		{
-			drawable->clearState( LLDrawable::FORCE_INVISIBLE );
-			markRebuild( drawable, LLDrawable::REBUILD_ALL);
-		}
-	}
+    pDrawable->clearState( LLDrawable::FORCE_INVISIBLE );
+    markRebuild( pDrawable, LLDrawable::REBUILD_ALL);
+    //restore children
+    LLViewerObject::const_child_list_t& child_list = pDrawable->getVObj()->getChildren();
+    for ( LLViewerObject::child_list_t::const_iterator iter = child_list.begin();
+          iter != child_list.end(); iter++)
+    {
+        LLViewerObject* child = *iter;
+        LLDrawable* drawable = child->mDrawable;
+        if ( drawable )
+        {
+            drawable->clearState( LLDrawable::FORCE_INVISIBLE );
+            markRebuild( drawable, LLDrawable::REBUILD_ALL);
+        }
+    }
 }
 void LLPipeline::restoreHiddenObject( const LLUUID& id )
 {
-	LLViewerObject *pVO = gObjectList.findObject( id );
-	
-	if ( pVO )
-	{
-		LLDrawable *pDrawable = pVO->mDrawable;
-		if ( pDrawable )
-		{
-			unhideDrawable( pDrawable );			
-		}
-	}
+    LLViewerObject *pVO = gObjectList.findObject( id );
+
+    if ( pVO )
+    {
+        LLDrawable *pDrawable = pVO->mDrawable;
+        if ( pDrawable )
+        {
+            unhideDrawable( pDrawable );
+        }
+    }
 }
 
 void LLPipeline::skipRenderingShadows()
diff --git a/indra/newview/pipeline.h b/indra/newview/pipeline.h
index d27d1dc93ef1dc0e81fb6020f2abdf92d05b9d1b..2c71cd7d7a8986c02d7307b755d08fdc869bd16a 100644
--- a/indra/newview/pipeline.h
+++ b/indra/newview/pipeline.h
@@ -1,25 +1,25 @@
-/** 
+/**
  * @file pipeline.h
  * @brief Rendering pipeline definitions
  *
  * $LicenseInfo:firstyear=2001&license=viewerlgpl$
  * Second Life Viewer Source Code
  * Copyright (C) 2010, Linden Research, Inc.
- * 
+ *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation;
  * version 2.1 of the License only.
- * 
+ *
  * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
- * 
+ *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
- * 
+ *
  * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
  * $/LicenseInfo$
  */
@@ -60,8 +60,8 @@ class LLSettingsSky;
 
 typedef enum e_avatar_skinning_method
 {
-	SKIN_METHOD_SOFTWARE,
-	SKIN_METHOD_VERTEX_PROGRAM
+    SKIN_METHOD_SOFTWARE,
+    SKIN_METHOD_VERTEX_PROGRAM
 } EAvatarSkinningMethod;
 
 bool compute_min_max(LLMatrix4& box, LLVector2& min, LLVector2& max); // Shouldn't be defined here!
@@ -72,43 +72,43 @@ bool setup_hud_matrices(const LLRect& screen_region); // specify portion of scre
 class LLPipeline
 {
 public:
-	LLPipeline();
-	~LLPipeline();
+    LLPipeline();
+    ~LLPipeline();
 
-	void destroyGL();
-	void restoreGL();
-	void requestResizeScreenTexture(); // set flag only, no work, safer for callbacks...
+    void destroyGL();
+    void restoreGL();
+    void requestResizeScreenTexture(); // set flag only, no work, safer for callbacks...
     void requestResizeShadowTexture(); // set flag only, no work, safer for callbacks...
 
-	void resizeScreenTexture();
+    void resizeScreenTexture();
     void resizeShadowTexture();
 
-	void releaseGLBuffers();
-	void releaseLUTBuffers();
-	void releaseScreenBuffers();
+    void releaseGLBuffers();
+    void releaseLUTBuffers();
+    void releaseScreenBuffers();
     void releaseShadowBuffers();
 
-	void createGLBuffers();
-	void createLUTBuffers();
+    void createGLBuffers();
+    void createLUTBuffers();
 
-	//allocate the largest screen buffer possible up to resX, resY
-	//returns true if full size buffer allocated, false if some other size is allocated
-	bool allocateScreenBuffer(U32 resX, U32 resY);
+    //allocate the largest screen buffer possible up to resX, resY
+    //returns true if full size buffer allocated, false if some other size is allocated
+    bool allocateScreenBuffer(U32 resX, U32 resY);
 
-	typedef enum {
-		FBO_SUCCESS_FULLRES = 0,
-		FBO_SUCCESS_LOWRES,
-		FBO_FAILURE
-	} eFBOStatus;
+    typedef enum {
+        FBO_SUCCESS_FULLRES = 0,
+        FBO_SUCCESS_LOWRES,
+        FBO_FAILURE
+    } eFBOStatus;
 
 private:
-	//implementation of above, wrapped for easy error handling
-	eFBOStatus doAllocateScreenBuffer(U32 resX, U32 resY);
+    //implementation of above, wrapped for easy error handling
+    eFBOStatus doAllocateScreenBuffer(U32 resX, U32 resY);
 public:
 
-	//attempt to allocate screen buffers at resX, resY
-	//returns true if allocation successful, false otherwise
-	bool allocateScreenBuffer(U32 resX, U32 resY, U32 samples);
+    //attempt to allocate screen buffers at resX, resY
+    //returns true if allocation successful, false otherwise
+    bool allocateScreenBuffer(U32 resX, U32 resY, U32 samples);
     bool allocateShadowBuffer(U32 resX, U32 resY);
 
     // rebuild all LLVOVolume render batches
@@ -117,7 +117,7 @@ class LLPipeline
     void rebuildTerrain();
 
     // Clear LLFace mVertexBuffer pointers
-	void resetVertexBuffers(LLDrawable* drawable);
+    void resetVertexBuffers(LLDrawable* drawable);
 
     // perform a profile of the given avatar
     // if profile_attachments is true, run a profile for each attachment
@@ -127,173 +127,173 @@ class LLPipeline
     //  preview_avatar - if true, a preview window render is being performed
     //  for_profile - if true, a profile is being performed, do not update actual impostor
     //  specific_attachment - specific attachment to profile, or nullptr to profile entire avatar
-	void generateImpostor(LLVOAvatar* avatar, bool preview_avatar = false, bool for_profile = false, LLViewerObject* specific_attachment = nullptr);
-
-	void bindScreenToTexture();
-	void renderFinalize();
-	void copyScreenSpaceReflections(LLRenderTarget* src, LLRenderTarget* dst);
-	void generateLuminance(LLRenderTarget* src, LLRenderTarget* dst);
-	void generateExposure(LLRenderTarget* src, LLRenderTarget* dst, bool use_history = true);
-	void gammaCorrect(LLRenderTarget* src, LLRenderTarget* dst);
-	void generateGlow(LLRenderTarget* src);
-	void applyFXAA(LLRenderTarget* src, LLRenderTarget* dst);
-	void renderDoF(LLRenderTarget* src, LLRenderTarget* dst);
-	void copyRenderTarget(LLRenderTarget* src, LLRenderTarget* dst);
-	void combineGlow(LLRenderTarget* src, LLRenderTarget* dst);
-	void visualizeBuffers(LLRenderTarget* src, LLRenderTarget* dst, U32 bufferIndex);
-
-	void init();
-	void cleanup();
-	bool isInit() { return mInitialized; };
-
-	/// @brief Get a draw pool from pool type (POOL_SIMPLE, POOL_MEDIA) and texture.
-	/// @return Draw pool, or NULL if not found.
-	LLDrawPool *findPool(const U32 pool_type, LLViewerTexture *tex0 = NULL);
-
-	/// @brief Get a draw pool for faces of the appropriate type and texture.  Create if necessary.
-	/// @return Always returns a draw pool.
-	LLDrawPool *getPool(const U32 pool_type, LLViewerTexture *tex0 = NULL);
-
-	/// @brief Figures out draw pool type from texture entry. Creates pool if necessary.
-	static LLDrawPool* getPoolFromTE(const LLTextureEntry* te, LLViewerTexture* te_image);
-	static U32 getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* imagep);
-
-	void		 addPool(LLDrawPool *poolp);	// Only to be used by LLDrawPool classes for splitting pools!
-	void		 removePool( LLDrawPool* poolp );
-
-	void		 allocDrawable(LLViewerObject *obj);
-
-	void		 unlinkDrawable(LLDrawable*);
-
-	static void removeMutedAVsLights(LLVOAvatar*);
-
-	// Object related methods
-	void        markVisible(LLDrawable *drawablep, LLCamera& camera);
-	void		markOccluder(LLSpatialGroup* group);
-
-	void		doOcclusion(LLCamera& camera);
-	void		markNotCulled(LLSpatialGroup* group, LLCamera &camera);
-	void        markMoved(LLDrawable *drawablep, bool damped_motion = false);
-	void        markShift(LLDrawable *drawablep);
-	void        markTextured(LLDrawable *drawablep);
-	void		markGLRebuild(LLGLUpdate* glu);
-	void		markRebuild(LLSpatialGroup* group);
-	void        markRebuild(LLDrawable *drawablep, LLDrawable::EDrawableFlags flag = LLDrawable::REBUILD_ALL);
-	void		markPartitionMove(LLDrawable* drawablep);
-	void		markMeshDirty(LLSpatialGroup* group);
-
-	//get the object between start and end that's closest to start.
-	LLViewerObject* lineSegmentIntersectInWorld(const LLVector4a& start, const LLVector4a& end,
-												bool pick_transparent,
-												bool pick_rigged,
+    void generateImpostor(LLVOAvatar* avatar, bool preview_avatar = false, bool for_profile = false, LLViewerObject* specific_attachment = nullptr);
+
+    void bindScreenToTexture();
+    void renderFinalize();
+    void copyScreenSpaceReflections(LLRenderTarget* src, LLRenderTarget* dst);
+    void generateLuminance(LLRenderTarget* src, LLRenderTarget* dst);
+    void generateExposure(LLRenderTarget* src, LLRenderTarget* dst, bool use_history = true);
+    void gammaCorrect(LLRenderTarget* src, LLRenderTarget* dst);
+    void generateGlow(LLRenderTarget* src);
+    void applyFXAA(LLRenderTarget* src, LLRenderTarget* dst);
+    void renderDoF(LLRenderTarget* src, LLRenderTarget* dst);
+    void copyRenderTarget(LLRenderTarget* src, LLRenderTarget* dst);
+    void combineGlow(LLRenderTarget* src, LLRenderTarget* dst);
+    void visualizeBuffers(LLRenderTarget* src, LLRenderTarget* dst, U32 bufferIndex);
+
+    void init();
+    void cleanup();
+    bool isInit() { return mInitialized; };
+
+    /// @brief Get a draw pool from pool type (POOL_SIMPLE, POOL_MEDIA) and texture.
+    /// @return Draw pool, or NULL if not found.
+    LLDrawPool *findPool(const U32 pool_type, LLViewerTexture *tex0 = NULL);
+
+    /// @brief Get a draw pool for faces of the appropriate type and texture.  Create if necessary.
+    /// @return Always returns a draw pool.
+    LLDrawPool *getPool(const U32 pool_type, LLViewerTexture *tex0 = NULL);
+
+    /// @brief Figures out draw pool type from texture entry. Creates pool if necessary.
+    static LLDrawPool* getPoolFromTE(const LLTextureEntry* te, LLViewerTexture* te_image);
+    static U32 getPoolTypeFromTE(const LLTextureEntry* te, LLViewerTexture* imagep);
+
+    void         addPool(LLDrawPool *poolp);    // Only to be used by LLDrawPool classes for splitting pools!
+    void         removePool( LLDrawPool* poolp );
+
+    void         allocDrawable(LLViewerObject *obj);
+
+    void         unlinkDrawable(LLDrawable*);
+
+    static void removeMutedAVsLights(LLVOAvatar*);
+
+    // Object related methods
+    void        markVisible(LLDrawable *drawablep, LLCamera& camera);
+    void        markOccluder(LLSpatialGroup* group);
+
+    void        doOcclusion(LLCamera& camera);
+    void        markNotCulled(LLSpatialGroup* group, LLCamera &camera);
+    void        markMoved(LLDrawable *drawablep, bool damped_motion = false);
+    void        markShift(LLDrawable *drawablep);
+    void        markTextured(LLDrawable *drawablep);
+    void        markGLRebuild(LLGLUpdate* glu);
+    void        markRebuild(LLSpatialGroup* group);
+    void        markRebuild(LLDrawable *drawablep, LLDrawable::EDrawableFlags flag = LLDrawable::REBUILD_ALL);
+    void        markPartitionMove(LLDrawable* drawablep);
+    void        markMeshDirty(LLSpatialGroup* group);
+
+    //get the object between start and end that's closest to start.
+    LLViewerObject* lineSegmentIntersectInWorld(const LLVector4a& start, const LLVector4a& end,
+                                                bool pick_transparent,
+                                                bool pick_rigged,
                                                 bool pick_unselectable,
                                                 bool pick_reflection_probe,
-												S32* face_hit,                          // return the face hit
+                                                S32* face_hit,                          // return the face hit
                                                 S32* gltf_node_hit = nullptr,           // return the gltf node hit
                                                 S32* gltf_primitive_hit = nullptr,      // return the gltf primitive hit
-												LLVector4a* intersection = NULL,         // return the intersection point
-												LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
-												LLVector4a* normal = NULL,               // return the surface normal at the intersection point
-												LLVector4a* tangent = NULL             // return the surface tangent at the intersection point  
-		);
+                                                LLVector4a* intersection = NULL,         // return the intersection point
+                                                LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
+                                                LLVector4a* normal = NULL,               // return the surface normal at the intersection point
+                                                LLVector4a* tangent = NULL             // return the surface tangent at the intersection point
+        );
 
-	//get the closest particle to start between start and end, returns the LLVOPartGroup and particle index
-	LLVOPartGroup* lineSegmentIntersectParticle(const LLVector4a& start, const LLVector4a& end, LLVector4a* intersection,
-														S32* face_hit);
+    //get the closest particle to start between start and end, returns the LLVOPartGroup and particle index
+    LLVOPartGroup* lineSegmentIntersectParticle(const LLVector4a& start, const LLVector4a& end, LLVector4a* intersection,
+                                                        S32* face_hit);
 
 
-	LLViewerObject* lineSegmentIntersectInHUD(const LLVector4a& start, const LLVector4a& end,
-											  bool pick_transparent,
-											  S32* face_hit,                          // return the face hit
-											  LLVector4a* intersection = NULL,         // return the intersection point
-											  LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
-											  LLVector4a* normal = NULL,               // return the surface normal at the intersection point
-											  LLVector4a* tangent = NULL             // return the surface tangent at the intersection point
-		);
+    LLViewerObject* lineSegmentIntersectInHUD(const LLVector4a& start, const LLVector4a& end,
+                                              bool pick_transparent,
+                                              S32* face_hit,                          // return the face hit
+                                              LLVector4a* intersection = NULL,         // return the intersection point
+                                              LLVector2* tex_coord = NULL,            // return the texture coordinates of the intersection point
+                                              LLVector4a* normal = NULL,               // return the surface normal at the intersection point
+                                              LLVector4a* tangent = NULL             // return the surface tangent at the intersection point
+        );
 
-	// Something about these textures has changed.  Dirty them.
-	void        dirtyPoolObjectTextures(const std::set<LLViewerFetchedTexture*>& textures);
+    // Something about these textures has changed.  Dirty them.
+    void        dirtyPoolObjectTextures(const std::set<LLViewerFetchedTexture*>& textures);
 
-	void        resetDrawOrders();
+    void        resetDrawOrders();
 
-	U32         addObject(LLViewerObject *obj);
+    U32         addObject(LLViewerObject *obj);
 
-	void		enableShadows(const bool enable_shadows);
+    void        enableShadows(const bool enable_shadows);
     void        releaseSpotShadowTargets();
     void        releaseSunShadowTargets();
     void        releaseSunShadowTarget(U32 index);
 
-	bool		shadersLoaded();
-	bool		canUseWindLightShaders() const;
-	bool		canUseAntiAliasing() const;
+    bool        shadersLoaded();
+    bool        canUseWindLightShaders() const;
+    bool        canUseAntiAliasing() const;
 
-	// phases
-	void resetFrameStats();
+    // phases
+    void resetFrameStats();
 
-	void updateMoveDampedAsync(LLDrawable* drawablep);
-	void updateMoveNormalAsync(LLDrawable* drawablep);
-	void updateMovedList(LLDrawable::drawable_vector_t& move_list);
-	void updateMove();
-	bool visibleObjectsInFrustum(LLCamera& camera);
-	bool getVisibleExtents(LLCamera& camera, LLVector3 &min, LLVector3& max);
-	bool getVisiblePointCloud(LLCamera& camera, LLVector3 &min, LLVector3& max, std::vector<LLVector3>& fp, LLVector3 light_dir = LLVector3(0,0,0));
+    void updateMoveDampedAsync(LLDrawable* drawablep);
+    void updateMoveNormalAsync(LLDrawable* drawablep);
+    void updateMovedList(LLDrawable::drawable_vector_t& move_list);
+    void updateMove();
+    bool visibleObjectsInFrustum(LLCamera& camera);
+    bool getVisibleExtents(LLCamera& camera, LLVector3 &min, LLVector3& max);
+    bool getVisiblePointCloud(LLCamera& camera, LLVector3 &min, LLVector3& max, std::vector<LLVector3>& fp, LLVector3 light_dir = LLVector3(0,0,0));
 
     // Populate given LLCullResult with results of a frustum cull of the entire scene against the given LLCamera
-	void updateCull(LLCamera& camera, LLCullResult& result);
-	void createObjects(F32 max_dtime);
-	void createObject(LLViewerObject* vobj);
-	void processPartitionQ();
-	void updateGeom(F32 max_dtime);
-	void updateGL();
-	void rebuildPriorityGroups();
-	void rebuildGroups();
-	void clearRebuildGroups();
-	void clearRebuildDrawables();
-
-	//calculate pixel area of given box from vantage point of given camera
-	static F32 calcPixelArea(LLVector3 center, LLVector3 size, LLCamera& camera);
-	static F32 calcPixelArea(const LLVector4a& center, const LLVector4a& size, LLCamera &camera);
-
-	void stateSort(LLCamera& camera, LLCullResult& result);
-	void stateSort(LLSpatialGroup* group, LLCamera& camera);
-	void stateSort(LLSpatialBridge* bridge, LLCamera& camera, BOOL fov_changed = FALSE);
-	void stateSort(LLDrawable* drawablep, LLCamera& camera);
-	void postSort(LLCamera& camera);
-    
-	void forAllVisibleDrawables(void (*func)(LLDrawable*));
+    void updateCull(LLCamera& camera, LLCullResult& result);
+    void createObjects(F32 max_dtime);
+    void createObject(LLViewerObject* vobj);
+    void processPartitionQ();
+    void updateGeom(F32 max_dtime);
+    void updateGL();
+    void rebuildPriorityGroups();
+    void rebuildGroups();
+    void clearRebuildGroups();
+    void clearRebuildDrawables();
+
+    //calculate pixel area of given box from vantage point of given camera
+    static F32 calcPixelArea(LLVector3 center, LLVector3 size, LLCamera& camera);
+    static F32 calcPixelArea(const LLVector4a& center, const LLVector4a& size, LLCamera &camera);
+
+    void stateSort(LLCamera& camera, LLCullResult& result);
+    void stateSort(LLSpatialGroup* group, LLCamera& camera);
+    void stateSort(LLSpatialBridge* bridge, LLCamera& camera, BOOL fov_changed = FALSE);
+    void stateSort(LLDrawable* drawablep, LLCamera& camera);
+    void postSort(LLCamera& camera);
+
+    void forAllVisibleDrawables(void (*func)(LLDrawable*));
 
     void renderObjects(U32 type, bool texture = true, bool batch_texture = false, bool rigged = false);
     void renderGLTFObjects(U32 type, bool texture = true, bool rigged = false);
-    
+
     void renderAlphaObjects(bool rigged = false);
-	void renderMaskedObjects(U32 type, bool texture = true, bool batch_texture = false, bool rigged = false);
+    void renderMaskedObjects(U32 type, bool texture = true, bool batch_texture = false, bool rigged = false);
     void renderFullbrightMaskedObjects(U32 type, bool texture = true, bool batch_texture = false, bool rigged = false);
 
-	void renderGroups(LLRenderPass* pass, U32 type, bool texture);
+    void renderGroups(LLRenderPass* pass, U32 type, bool texture);
     void renderRiggedGroups(LLRenderPass* pass, U32 type, bool texture);
 
-	void grabReferences(LLCullResult& result);
-	void clearReferences();
-
-	//check references will assert that there are no references in sCullResult to the provided data
-	void checkReferences(LLFace* face);
-	void checkReferences(LLDrawable* drawable);
-	void checkReferences(LLDrawInfo* draw_info);
-	void checkReferences(LLSpatialGroup* group);
-	
-	void renderGeomDeferred(LLCamera& camera, bool do_occlusion = false);
-	void renderGeomPostDeferred(LLCamera& camera);
-	void renderGeomShadow(LLCamera& camera);
+    void grabReferences(LLCullResult& result);
+    void clearReferences();
+
+    //check references will assert that there are no references in sCullResult to the provided data
+    void checkReferences(LLFace* face);
+    void checkReferences(LLDrawable* drawable);
+    void checkReferences(LLDrawInfo* draw_info);
+    void checkReferences(LLSpatialGroup* group);
+
+    void renderGeomDeferred(LLCamera& camera, bool do_occlusion = false);
+    void renderGeomPostDeferred(LLCamera& camera);
+    void renderGeomShadow(LLCamera& camera);
     void bindLightFunc(LLGLSLShader& shader);
 
     // bind shadow maps
     // if setup is true, wil lset texture compare mode function and filtering options
     void bindShadowMaps(LLGLSLShader& shader);
     void bindDeferredShaderFast(LLGLSLShader& shader);
-	void bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_target = nullptr, LLRenderTarget* depth_target = nullptr);
-	void setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep);
+    void bindDeferredShader(LLGLSLShader& shader, LLRenderTarget* light_target = nullptr, LLRenderTarget* depth_target = nullptr);
+    void setupSpotLight(LLGLSLShader& shader, LLDrawable* drawablep);
 
-	void unbindDeferredShader(LLGLSLShader& shader);
+    void unbindDeferredShader(LLGLSLShader& shader);
 
     // set env_mat parameter in given shader
     void setEnvMat(LLGLSLShader& shader);
@@ -301,10 +301,10 @@ class LLPipeline
     void bindReflectionProbes(LLGLSLShader& shader);
     void unbindReflectionProbes(LLGLSLShader& shader);
 
-	void renderDeferredLighting();
+    void renderDeferredLighting();
 
     // apply atmospheric haze based on contents of color and depth buffer
-    // should be called just before rendering water when camera is under water 
+    // should be called just before rendering water when camera is under water
     // and just before rendering alpha when camera is above water
     void doAtmospherics();
 
@@ -312,369 +312,369 @@ class LLPipeline
     // should be called just before rendering pre-water alpha objects
     void doWaterHaze();
 
-	void postDeferredGammaCorrect(LLRenderTarget* screen_target);
+    void postDeferredGammaCorrect(LLRenderTarget* screen_target);
 
-	void generateSunShadow(LLCamera& camera);
+    void generateSunShadow(LLCamera& camera);
     LLRenderTarget* getSunShadowTarget(U32 i);
     LLRenderTarget* getSpotShadowTarget(U32 i);
 
-	void renderHighlight(const LLViewerObject* obj, F32 fade);
-	
-	void renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& camera, LLCullResult& result, bool depth_clamp);
-	void renderHighlights();
-	void renderDebug();
-	void renderPhysicsDisplay();
-
-	void rebuildPools(); // Rebuild pools
-
-	void findReferences(LLDrawable *drawablep);	// Find the lists which have references to this object
-	bool verify();						// Verify that all data in the pipeline is "correct"
-
-	S32  getLightCount() const { return mLights.size(); }
-
-	void calcNearbyLights(LLCamera& camera);
-	void setupHWLights();
-	void setupAvatarLights(bool for_edit = false);
-	void enableLights(U32 mask);
-	void enableLightsDynamic();
-	void enableLightsAvatar();
-	void enableLightsPreview();
-	void enableLightsAvatarEdit(const LLColor4& color);
-	void enableLightsFullbright();
-	void disableLights();
-
-	void shiftObjects(const LLVector3 &offset);
-
-	void setLight(LLDrawable *drawablep, bool is_light);
-	
-	bool hasRenderBatches(const U32 type) const;
-	LLCullResult::drawinfo_iterator beginRenderMap(U32 type);
-	LLCullResult::drawinfo_iterator endRenderMap(U32 type);
-	LLCullResult::sg_iterator beginAlphaGroups();
-	LLCullResult::sg_iterator endAlphaGroups();
+    void renderHighlight(const LLViewerObject* obj, F32 fade);
+
+    void renderShadow(glh::matrix4f& view, glh::matrix4f& proj, LLCamera& camera, LLCullResult& result, bool depth_clamp);
+    void renderHighlights();
+    void renderDebug();
+    void renderPhysicsDisplay();
+
+    void rebuildPools(); // Rebuild pools
+
+    void findReferences(LLDrawable *drawablep); // Find the lists which have references to this object
+    bool verify();                      // Verify that all data in the pipeline is "correct"
+
+    S32  getLightCount() const { return mLights.size(); }
+
+    void calcNearbyLights(LLCamera& camera);
+    void setupHWLights();
+    void setupAvatarLights(bool for_edit = false);
+    void enableLights(U32 mask);
+    void enableLightsDynamic();
+    void enableLightsAvatar();
+    void enableLightsPreview();
+    void enableLightsAvatarEdit(const LLColor4& color);
+    void enableLightsFullbright();
+    void disableLights();
+
+    void shiftObjects(const LLVector3 &offset);
+
+    void setLight(LLDrawable *drawablep, bool is_light);
+
+    bool hasRenderBatches(const U32 type) const;
+    LLCullResult::drawinfo_iterator beginRenderMap(U32 type);
+    LLCullResult::drawinfo_iterator endRenderMap(U32 type);
+    LLCullResult::sg_iterator beginAlphaGroups();
+    LLCullResult::sg_iterator endAlphaGroups();
     LLCullResult::sg_iterator beginRiggedAlphaGroups();
     LLCullResult::sg_iterator endRiggedAlphaGroups();
-	
-	void addTrianglesDrawn(S32 index_count);
+
+    void addTrianglesDrawn(S32 index_count);
     void recordTrianglesDrawn();
 
-	bool hasRenderDebugFeatureMask(const U32 mask) const	{ return bool(mRenderDebugFeatureMask & mask); }
-	bool hasRenderDebugMask(const U64 mask) const			{ return bool(mRenderDebugMask & mask); }
-	void setAllRenderDebugFeatures() { mRenderDebugFeatureMask = 0xffffffff; }
-	void clearAllRenderDebugFeatures() { mRenderDebugFeatureMask = 0x0; }
-	void setAllRenderDebugDisplays() { mRenderDebugMask = 0xffffffffffffffff; }
-	void clearAllRenderDebugDisplays() { mRenderDebugMask = 0x0; }
-
-	bool hasRenderType(const U32 type) const;
-	bool hasAnyRenderType(const U32 type, ...) const;
-
-	static bool isWaterClip();
-
-	void setRenderTypeMask(U32 type, ...);
-	// This is equivalent to 'setRenderTypeMask'
-	//void orRenderTypeMask(U32 type, ...);
-	void andRenderTypeMask(U32 type, ...);
-	void clearRenderTypeMask(U32 type, ...);
-	void setAllRenderTypes();
-	void clearAllRenderTypes();
-	
-	void pushRenderTypeMask();
-	void popRenderTypeMask();
-
-	void pushRenderDebugFeatureMask();
-	void popRenderDebugFeatureMask();
-
-	static void toggleRenderType(U32 type);
-
-	// For UI control of render features
-	static bool hasRenderTypeControl(U32 data);
-	static void toggleRenderDebug(U64 data);
-	static void toggleRenderDebugFeature(U32 data);
-	static void toggleRenderTypeControl(U32 data);
-	static bool toggleRenderTypeControlNegated(S32 data);
-	static bool toggleRenderDebugControl(U64 data);
-	static bool toggleRenderDebugFeatureControl(U32 data);
-	static void setRenderDebugFeatureControl(U32 bit, bool value);
-
-	static void setRenderParticleBeacons(bool val);
-	static void toggleRenderParticleBeacons();
-	static bool getRenderParticleBeacons();
-
-	static void setRenderSoundBeacons(bool val);
-	static void toggleRenderSoundBeacons();
-	static bool getRenderSoundBeacons();
-
-	static void setRenderMOAPBeacons(bool val);
-	static void toggleRenderMOAPBeacons();
-	static bool getRenderMOAPBeacons();
-
-	static void setRenderPhysicalBeacons(bool val);
-	static void toggleRenderPhysicalBeacons();
-	static bool getRenderPhysicalBeacons();
-
-	static void setRenderScriptedBeacons(bool val);
-	static void toggleRenderScriptedBeacons();
-	static bool getRenderScriptedBeacons();
-
-	static void setRenderScriptedTouchBeacons(bool val);
-	static void toggleRenderScriptedTouchBeacons();
-	static bool getRenderScriptedTouchBeacons();
-
-	static void setRenderBeacons(bool val);
-	static void toggleRenderBeacons();
-	static bool getRenderBeacons();
-
-	static void setRenderHighlights(bool val);
-	static void toggleRenderHighlights();
-	static bool getRenderHighlights();
-	static void setRenderHighlightTextureChannel(LLRender::eTexIndex channel); // sets which UV setup to display in highlight overlay
-
-	static void updateRenderTransparentWater();
-	static void refreshCachedSettings();
-
-	void addDebugBlip(const LLVector3& position, const LLColor4& color);
-
-	void hidePermanentObjects( std::vector<U32>& restoreList );
-	void restorePermanentObjects( const std::vector<U32>& restoreList );
-	void skipRenderingOfTerrain( bool flag );
-	void hideObject( const LLUUID& id );
-	void restoreHiddenObject( const LLUUID& id );
+    bool hasRenderDebugFeatureMask(const U32 mask) const    { return bool(mRenderDebugFeatureMask & mask); }
+    bool hasRenderDebugMask(const U64 mask) const           { return bool(mRenderDebugMask & mask); }
+    void setAllRenderDebugFeatures() { mRenderDebugFeatureMask = 0xffffffff; }
+    void clearAllRenderDebugFeatures() { mRenderDebugFeatureMask = 0x0; }
+    void setAllRenderDebugDisplays() { mRenderDebugMask = 0xffffffffffffffff; }
+    void clearAllRenderDebugDisplays() { mRenderDebugMask = 0x0; }
+
+    bool hasRenderType(const U32 type) const;
+    bool hasAnyRenderType(const U32 type, ...) const;
+
+    static bool isWaterClip();
+
+    void setRenderTypeMask(U32 type, ...);
+    // This is equivalent to 'setRenderTypeMask'
+    //void orRenderTypeMask(U32 type, ...);
+    void andRenderTypeMask(U32 type, ...);
+    void clearRenderTypeMask(U32 type, ...);
+    void setAllRenderTypes();
+    void clearAllRenderTypes();
+
+    void pushRenderTypeMask();
+    void popRenderTypeMask();
+
+    void pushRenderDebugFeatureMask();
+    void popRenderDebugFeatureMask();
+
+    static void toggleRenderType(U32 type);
+
+    // For UI control of render features
+    static bool hasRenderTypeControl(U32 data);
+    static void toggleRenderDebug(U64 data);
+    static void toggleRenderDebugFeature(U32 data);
+    static void toggleRenderTypeControl(U32 data);
+    static bool toggleRenderTypeControlNegated(S32 data);
+    static bool toggleRenderDebugControl(U64 data);
+    static bool toggleRenderDebugFeatureControl(U32 data);
+    static void setRenderDebugFeatureControl(U32 bit, bool value);
+
+    static void setRenderParticleBeacons(bool val);
+    static void toggleRenderParticleBeacons();
+    static bool getRenderParticleBeacons();
+
+    static void setRenderSoundBeacons(bool val);
+    static void toggleRenderSoundBeacons();
+    static bool getRenderSoundBeacons();
+
+    static void setRenderMOAPBeacons(bool val);
+    static void toggleRenderMOAPBeacons();
+    static bool getRenderMOAPBeacons();
+
+    static void setRenderPhysicalBeacons(bool val);
+    static void toggleRenderPhysicalBeacons();
+    static bool getRenderPhysicalBeacons();
+
+    static void setRenderScriptedBeacons(bool val);
+    static void toggleRenderScriptedBeacons();
+    static bool getRenderScriptedBeacons();
+
+    static void setRenderScriptedTouchBeacons(bool val);
+    static void toggleRenderScriptedTouchBeacons();
+    static bool getRenderScriptedTouchBeacons();
+
+    static void setRenderBeacons(bool val);
+    static void toggleRenderBeacons();
+    static bool getRenderBeacons();
+
+    static void setRenderHighlights(bool val);
+    static void toggleRenderHighlights();
+    static bool getRenderHighlights();
+    static void setRenderHighlightTextureChannel(LLRender::eTexIndex channel); // sets which UV setup to display in highlight overlay
+
+    static void updateRenderTransparentWater();
+    static void refreshCachedSettings();
+
+    void addDebugBlip(const LLVector3& position, const LLColor4& color);
+
+    void hidePermanentObjects( std::vector<U32>& restoreList );
+    void restorePermanentObjects( const std::vector<U32>& restoreList );
+    void skipRenderingOfTerrain( bool flag );
+    void hideObject( const LLUUID& id );
+    void restoreHiddenObject( const LLUUID& id );
     void handleShadowDetailChanged();
 
     LLReflectionMapManager mReflectionMapManager;
     LLHeroProbeManager mHeroProbeManager;
 
 private:
-	void unloadShaders();
-	void addToQuickLookup( LLDrawPool* new_poolp );
-	void removeFromQuickLookup( LLDrawPool* poolp );
-	bool updateDrawableGeom(LLDrawable* drawable);
-	void assertInitializedDoError();
-	bool assertInitialized() { const bool is_init = isInit(); if (!is_init) assertInitializedDoError(); return is_init; };
-	void connectRefreshCachedSettingsSafe(const std::string name);
-	void hideDrawable( LLDrawable *pDrawable );
-	void unhideDrawable( LLDrawable *pDrawable );
+    void unloadShaders();
+    void addToQuickLookup( LLDrawPool* new_poolp );
+    void removeFromQuickLookup( LLDrawPool* poolp );
+    bool updateDrawableGeom(LLDrawable* drawable);
+    void assertInitializedDoError();
+    bool assertInitialized() { const bool is_init = isInit(); if (!is_init) assertInitializedDoError(); return is_init; };
+    void connectRefreshCachedSettingsSafe(const std::string name);
+    void hideDrawable( LLDrawable *pDrawable );
+    void unhideDrawable( LLDrawable *pDrawable );
     void skipRenderingShadows();
 public:
-	enum {GPU_CLASS_MAX = 3 };
-
-	enum LLRenderTypeMask
-	{
-		// Following are pool types (some are also object types)
-		RENDER_TYPE_SKY							= LLDrawPool::POOL_SKY,
-		RENDER_TYPE_WL_SKY						= LLDrawPool::POOL_WL_SKY,
-		RENDER_TYPE_TERRAIN						= LLDrawPool::POOL_TERRAIN,
-		RENDER_TYPE_SIMPLE						= LLDrawPool::POOL_SIMPLE,
-		RENDER_TYPE_GRASS						= LLDrawPool::POOL_GRASS,
-		RENDER_TYPE_ALPHA_MASK					= LLDrawPool::POOL_ALPHA_MASK,
-		RENDER_TYPE_FULLBRIGHT_ALPHA_MASK		= LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK,
-		RENDER_TYPE_FULLBRIGHT					= LLDrawPool::POOL_FULLBRIGHT,
-		RENDER_TYPE_BUMP						= LLDrawPool::POOL_BUMP,
-		RENDER_TYPE_MATERIALS					= LLDrawPool::POOL_MATERIALS,
-		RENDER_TYPE_AVATAR						= LLDrawPool::POOL_AVATAR,
-		RENDER_TYPE_CONTROL_AV					= LLDrawPool::POOL_CONTROL_AV, // Animesh
-		RENDER_TYPE_TREE						= LLDrawPool::POOL_TREE,
-		RENDER_TYPE_VOIDWATER					= LLDrawPool::POOL_VOIDWATER,
-		RENDER_TYPE_WATER						= LLDrawPool::POOL_WATER,
+    enum {GPU_CLASS_MAX = 3 };
+
+    enum LLRenderTypeMask
+    {
+        // Following are pool types (some are also object types)
+        RENDER_TYPE_SKY                         = LLDrawPool::POOL_SKY,
+        RENDER_TYPE_WL_SKY                      = LLDrawPool::POOL_WL_SKY,
+        RENDER_TYPE_TERRAIN                     = LLDrawPool::POOL_TERRAIN,
+        RENDER_TYPE_SIMPLE                      = LLDrawPool::POOL_SIMPLE,
+        RENDER_TYPE_GRASS                       = LLDrawPool::POOL_GRASS,
+        RENDER_TYPE_ALPHA_MASK                  = LLDrawPool::POOL_ALPHA_MASK,
+        RENDER_TYPE_FULLBRIGHT_ALPHA_MASK       = LLDrawPool::POOL_FULLBRIGHT_ALPHA_MASK,
+        RENDER_TYPE_FULLBRIGHT                  = LLDrawPool::POOL_FULLBRIGHT,
+        RENDER_TYPE_BUMP                        = LLDrawPool::POOL_BUMP,
+        RENDER_TYPE_MATERIALS                   = LLDrawPool::POOL_MATERIALS,
+        RENDER_TYPE_AVATAR                      = LLDrawPool::POOL_AVATAR,
+        RENDER_TYPE_CONTROL_AV                  = LLDrawPool::POOL_CONTROL_AV, // Animesh
+        RENDER_TYPE_TREE                        = LLDrawPool::POOL_TREE,
+        RENDER_TYPE_VOIDWATER                   = LLDrawPool::POOL_VOIDWATER,
+        RENDER_TYPE_WATER                       = LLDrawPool::POOL_WATER,
         RENDER_TYPE_GLTF_PBR                    = LLDrawPool::POOL_GLTF_PBR,
         RENDER_TYPE_GLTF_PBR_ALPHA_MASK         = LLDrawPool::POOL_GLTF_PBR_ALPHA_MASK,
- 		RENDER_TYPE_ALPHA						= LLDrawPool::POOL_ALPHA,
+        RENDER_TYPE_ALPHA                       = LLDrawPool::POOL_ALPHA,
         RENDER_TYPE_ALPHA_PRE_WATER             = LLDrawPool::POOL_ALPHA_PRE_WATER,
         RENDER_TYPE_ALPHA_POST_WATER            = LLDrawPool::POOL_ALPHA_POST_WATER,
-		RENDER_TYPE_GLOW						= LLDrawPool::POOL_GLOW,
-		RENDER_TYPE_PASS_SIMPLE 				= LLRenderPass::PASS_SIMPLE,
+        RENDER_TYPE_GLOW                        = LLDrawPool::POOL_GLOW,
+        RENDER_TYPE_PASS_SIMPLE                 = LLRenderPass::PASS_SIMPLE,
         RENDER_TYPE_PASS_SIMPLE_RIGGED = LLRenderPass::PASS_SIMPLE_RIGGED,
-		RENDER_TYPE_PASS_GRASS					= LLRenderPass::PASS_GRASS,
-		RENDER_TYPE_PASS_FULLBRIGHT				= LLRenderPass::PASS_FULLBRIGHT,
+        RENDER_TYPE_PASS_GRASS                  = LLRenderPass::PASS_GRASS,
+        RENDER_TYPE_PASS_FULLBRIGHT             = LLRenderPass::PASS_FULLBRIGHT,
         RENDER_TYPE_PASS_FULLBRIGHT_RIGGED = LLRenderPass::PASS_FULLBRIGHT_RIGGED,
-		RENDER_TYPE_PASS_INVISIBLE				= LLRenderPass::PASS_INVISIBLE,
+        RENDER_TYPE_PASS_INVISIBLE              = LLRenderPass::PASS_INVISIBLE,
         RENDER_TYPE_PASS_INVISIBLE_RIGGED = LLRenderPass::PASS_INVISIBLE_RIGGED,
-		RENDER_TYPE_PASS_INVISI_SHINY			= LLRenderPass::PASS_INVISI_SHINY,
+        RENDER_TYPE_PASS_INVISI_SHINY           = LLRenderPass::PASS_INVISI_SHINY,
         RENDER_TYPE_PASS_INVISI_SHINY_RIGGED = LLRenderPass::PASS_INVISI_SHINY_RIGGED,
-		RENDER_TYPE_PASS_FULLBRIGHT_SHINY		= LLRenderPass::PASS_FULLBRIGHT_SHINY,
+        RENDER_TYPE_PASS_FULLBRIGHT_SHINY       = LLRenderPass::PASS_FULLBRIGHT_SHINY,
         RENDER_TYPE_PASS_FULLBRIGHT_SHINY_RIGGED = LLRenderPass::PASS_FULLBRIGHT_SHINY_RIGGED,
-		RENDER_TYPE_PASS_SHINY					= LLRenderPass::PASS_SHINY,
+        RENDER_TYPE_PASS_SHINY                  = LLRenderPass::PASS_SHINY,
         RENDER_TYPE_PASS_SHINY_RIGGED = LLRenderPass::PASS_SHINY_RIGGED,
-		RENDER_TYPE_PASS_BUMP					= LLRenderPass::PASS_BUMP,
+        RENDER_TYPE_PASS_BUMP                   = LLRenderPass::PASS_BUMP,
         RENDER_TYPE_PASS_BUMP_RIGGED = LLRenderPass::PASS_BUMP_RIGGED,
-		RENDER_TYPE_PASS_POST_BUMP				= LLRenderPass::PASS_POST_BUMP,
+        RENDER_TYPE_PASS_POST_BUMP              = LLRenderPass::PASS_POST_BUMP,
         RENDER_TYPE_PASS_POST_BUMP_RIGGED = LLRenderPass::PASS_POST_BUMP_RIGGED,
-		RENDER_TYPE_PASS_GLOW					= LLRenderPass::PASS_GLOW,
+        RENDER_TYPE_PASS_GLOW                   = LLRenderPass::PASS_GLOW,
         RENDER_TYPE_PASS_GLOW_RIGGED = LLRenderPass::PASS_GLOW_RIGGED,
         RENDER_TYPE_PASS_GLTF_GLOW = LLRenderPass::PASS_GLTF_GLOW,
         RENDER_TYPE_PASS_GLTF_GLOW_RIGGED = LLRenderPass::PASS_GLTF_GLOW_RIGGED,
-		RENDER_TYPE_PASS_ALPHA					= LLRenderPass::PASS_ALPHA,
-		RENDER_TYPE_PASS_ALPHA_MASK				= LLRenderPass::PASS_ALPHA_MASK,
+        RENDER_TYPE_PASS_ALPHA                  = LLRenderPass::PASS_ALPHA,
+        RENDER_TYPE_PASS_ALPHA_MASK             = LLRenderPass::PASS_ALPHA_MASK,
         RENDER_TYPE_PASS_ALPHA_MASK_RIGGED = LLRenderPass::PASS_ALPHA_MASK_RIGGED,
-		RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK	= LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK,
+        RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK  = LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK,
         RENDER_TYPE_PASS_FULLBRIGHT_ALPHA_MASK_RIGGED = LLRenderPass::PASS_FULLBRIGHT_ALPHA_MASK_RIGGED,
-		RENDER_TYPE_PASS_MATERIAL				= LLRenderPass::PASS_MATERIAL,
+        RENDER_TYPE_PASS_MATERIAL               = LLRenderPass::PASS_MATERIAL,
         RENDER_TYPE_PASS_MATERIAL_RIGGED = LLRenderPass::PASS_MATERIAL_RIGGED,
-		RENDER_TYPE_PASS_MATERIAL_ALPHA			= LLRenderPass::PASS_MATERIAL_ALPHA,
+        RENDER_TYPE_PASS_MATERIAL_ALPHA         = LLRenderPass::PASS_MATERIAL_ALPHA,
         RENDER_TYPE_PASS_MATERIAL_ALPHA_RIGGED = LLRenderPass::PASS_MATERIAL_ALPHA_RIGGED,
-		RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK	= LLRenderPass::PASS_MATERIAL_ALPHA_MASK,
+        RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK    = LLRenderPass::PASS_MATERIAL_ALPHA_MASK,
         RENDER_TYPE_PASS_MATERIAL_ALPHA_MASK_RIGGED = LLRenderPass::PASS_MATERIAL_ALPHA_MASK_RIGGED,
-		RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE= LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE,
+        RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE= LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE,
         RENDER_TYPE_PASS_MATERIAL_ALPHA_EMISSIVE_RIGGED = LLRenderPass::PASS_MATERIAL_ALPHA_EMISSIVE_RIGGED,
-		RENDER_TYPE_PASS_SPECMAP				= LLRenderPass::PASS_SPECMAP,
+        RENDER_TYPE_PASS_SPECMAP                = LLRenderPass::PASS_SPECMAP,
         RENDER_TYPE_PASS_SPECMAP_RIGGED = LLRenderPass::PASS_SPECMAP_RIGGED,
-		RENDER_TYPE_PASS_SPECMAP_BLEND			= LLRenderPass::PASS_SPECMAP_BLEND,
+        RENDER_TYPE_PASS_SPECMAP_BLEND          = LLRenderPass::PASS_SPECMAP_BLEND,
         RENDER_TYPE_PASS_SPECMAP_BLEND_RIGGED = LLRenderPass::PASS_SPECMAP_BLEND_RIGGED,
-		RENDER_TYPE_PASS_SPECMAP_MASK			= LLRenderPass::PASS_SPECMAP_MASK,
+        RENDER_TYPE_PASS_SPECMAP_MASK           = LLRenderPass::PASS_SPECMAP_MASK,
         RENDER_TYPE_PASS_SPECMAP_MASK_RIGGED = LLRenderPass::PASS_SPECMAP_MASK_RIGGED,
-		RENDER_TYPE_PASS_SPECMAP_EMISSIVE		= LLRenderPass::PASS_SPECMAP_EMISSIVE,
+        RENDER_TYPE_PASS_SPECMAP_EMISSIVE       = LLRenderPass::PASS_SPECMAP_EMISSIVE,
         RENDER_TYPE_PASS_SPECMAP_EMISSIVE_RIGGED = LLRenderPass::PASS_SPECMAP_EMISSIVE_RIGGED,
-		RENDER_TYPE_PASS_NORMMAP				= LLRenderPass::PASS_NORMMAP,
+        RENDER_TYPE_PASS_NORMMAP                = LLRenderPass::PASS_NORMMAP,
         RENDER_TYPE_PASS_NORMMAP_RIGGED = LLRenderPass::PASS_NORMMAP_RIGGED,
-		RENDER_TYPE_PASS_NORMMAP_BLEND			= LLRenderPass::PASS_NORMMAP_BLEND,
+        RENDER_TYPE_PASS_NORMMAP_BLEND          = LLRenderPass::PASS_NORMMAP_BLEND,
         RENDER_TYPE_PASS_NORMMAP_BLEND_RIGGED = LLRenderPass::PASS_NORMMAP_BLEND_RIGGED,
-		RENDER_TYPE_PASS_NORMMAP_MASK			= LLRenderPass::PASS_NORMMAP_MASK,
+        RENDER_TYPE_PASS_NORMMAP_MASK           = LLRenderPass::PASS_NORMMAP_MASK,
         RENDER_TYPE_PASS_NORMMAP_MASK_RIGGED = LLRenderPass::PASS_NORMMAP_MASK_RIGGED,
-		RENDER_TYPE_PASS_NORMMAP_EMISSIVE		= LLRenderPass::PASS_NORMMAP_EMISSIVE,
+        RENDER_TYPE_PASS_NORMMAP_EMISSIVE       = LLRenderPass::PASS_NORMMAP_EMISSIVE,
         RENDER_TYPE_PASS_NORMMAP_EMISSIVE_RIGGED = LLRenderPass::PASS_NORMMAP_EMISSIVE_RIGGED,
-		RENDER_TYPE_PASS_NORMSPEC				= LLRenderPass::PASS_NORMSPEC,
+        RENDER_TYPE_PASS_NORMSPEC               = LLRenderPass::PASS_NORMSPEC,
         RENDER_TYPE_PASS_NORMSPEC_RIGGED = LLRenderPass::PASS_NORMSPEC_RIGGED,
-		RENDER_TYPE_PASS_NORMSPEC_BLEND			= LLRenderPass::PASS_NORMSPEC_BLEND,
+        RENDER_TYPE_PASS_NORMSPEC_BLEND         = LLRenderPass::PASS_NORMSPEC_BLEND,
         RENDER_TYPE_PASS_NORMSPEC_BLEND_RIGGED = LLRenderPass::PASS_NORMSPEC_BLEND_RIGGED,
-		RENDER_TYPE_PASS_NORMSPEC_MASK			= LLRenderPass::PASS_NORMSPEC_MASK,
+        RENDER_TYPE_PASS_NORMSPEC_MASK          = LLRenderPass::PASS_NORMSPEC_MASK,
         RENDER_TYPE_PASS_NORMSPEC_MASK_RIGGED = LLRenderPass::PASS_NORMSPEC_MASK_RIGGED,
-		RENDER_TYPE_PASS_NORMSPEC_EMISSIVE		= LLRenderPass::PASS_NORMSPEC_EMISSIVE,
+        RENDER_TYPE_PASS_NORMSPEC_EMISSIVE      = LLRenderPass::PASS_NORMSPEC_EMISSIVE,
         RENDER_TYPE_PASS_NORMSPEC_EMISSIVE_RIGGED = LLRenderPass::PASS_NORMSPEC_EMISSIVE_RIGGED,
         RENDER_TYPE_PASS_GLTF_PBR                 = LLRenderPass::PASS_GLTF_PBR,
         RENDER_TYPE_PASS_GLTF_PBR_RIGGED         = LLRenderPass::PASS_GLTF_PBR_RIGGED,
         RENDER_TYPE_PASS_GLTF_PBR_ALPHA_MASK        = LLRenderPass::PASS_GLTF_PBR_ALPHA_MASK,
         RENDER_TYPE_PASS_GLTF_PBR_ALPHA_MASK_RIGGED = LLRenderPass::PASS_GLTF_PBR_ALPHA_MASK_RIGGED,
-		// Following are object types (only used in drawable mRenderType)
-		RENDER_TYPE_HUD = LLRenderPass::NUM_RENDER_TYPES,
-		RENDER_TYPE_VOLUME,
-		RENDER_TYPE_PARTICLES,
-		RENDER_TYPE_CLOUDS,
-		RENDER_TYPE_HUD_PARTICLES,
-		NUM_RENDER_TYPES,
-		END_RENDER_TYPES = NUM_RENDER_TYPES
-	};
-
-	enum LLRenderDebugFeatureMask
-	{
-		RENDER_DEBUG_FEATURE_UI					= 0x0001,
-		RENDER_DEBUG_FEATURE_SELECTED			= 0x0002,
-		RENDER_DEBUG_FEATURE_HIGHLIGHTED		= 0x0004,
-		RENDER_DEBUG_FEATURE_DYNAMIC_TEXTURES	= 0x0008,
-// 		RENDER_DEBUG_FEATURE_HW_LIGHTING		= 0x0010,
-		RENDER_DEBUG_FEATURE_FLEXIBLE			= 0x0010,
-		RENDER_DEBUG_FEATURE_FOG				= 0x0020,
-		RENDER_DEBUG_FEATURE_FR_INFO			= 0x0080,
-		RENDER_DEBUG_FEATURE_FOOT_SHADOWS		= 0x0100,
-	};
-
-	enum LLRenderDebugMask: U64
-	{
-		RENDER_DEBUG_COMPOSITION		=  0x00000001,
-		RENDER_DEBUG_VERIFY				=  0x00000002,
-		RENDER_DEBUG_BBOXES				=  0x00000004,
-		RENDER_DEBUG_OCTREE				=  0x00000008,
-		RENDER_DEBUG_WIND_VECTORS		=  0x00000010,
-		RENDER_DEBUG_OCCLUSION			=  0x00000020,
-		RENDER_DEBUG_POINTS				=  0x00000040,
-		RENDER_DEBUG_TEXTURE_PRIORITY	=  0x00000080,
-		RENDER_DEBUG_TEXTURE_AREA		=  0x00000100,
-		RENDER_DEBUG_FACE_AREA			=  0x00000200,
-		RENDER_DEBUG_PARTICLES			=  0x00000400,
-		RENDER_DEBUG_GLOW				=  0x00000800, // not used
-		RENDER_DEBUG_TEXTURE_ANIM		=  0x00001000,
-		RENDER_DEBUG_LIGHTS				=  0x00002000,
-		RENDER_DEBUG_BATCH_SIZE			=  0x00004000,
-		RENDER_DEBUG_ALPHA_BINS			=  0x00008000, // not used
-		RENDER_DEBUG_RAYCAST            =  0x00010000,
-		RENDER_DEBUG_AVATAR_DRAW_INFO	=  0x00020000,
-		RENDER_DEBUG_SHADOW_FRUSTA		=  0x00040000,
-		RENDER_DEBUG_SCULPTED           =  0x00080000,
-		RENDER_DEBUG_AVATAR_VOLUME      =  0x00100000,
-		RENDER_DEBUG_AVATAR_JOINTS      =  0x00200000,
-		RENDER_DEBUG_AGENT_TARGET       =  0x00800000,
-		RENDER_DEBUG_UPDATE_TYPE		=  0x01000000,
-		RENDER_DEBUG_PHYSICS_SHAPES     =  0x02000000,
-		RENDER_DEBUG_NORMALS	        =  0x04000000,
-		RENDER_DEBUG_LOD_INFO	        =  0x08000000,
+        // Following are object types (only used in drawable mRenderType)
+        RENDER_TYPE_HUD = LLRenderPass::NUM_RENDER_TYPES,
+        RENDER_TYPE_VOLUME,
+        RENDER_TYPE_PARTICLES,
+        RENDER_TYPE_CLOUDS,
+        RENDER_TYPE_HUD_PARTICLES,
+        NUM_RENDER_TYPES,
+        END_RENDER_TYPES = NUM_RENDER_TYPES
+    };
+
+    enum LLRenderDebugFeatureMask
+    {
+        RENDER_DEBUG_FEATURE_UI                 = 0x0001,
+        RENDER_DEBUG_FEATURE_SELECTED           = 0x0002,
+        RENDER_DEBUG_FEATURE_HIGHLIGHTED        = 0x0004,
+        RENDER_DEBUG_FEATURE_DYNAMIC_TEXTURES   = 0x0008,
+//      RENDER_DEBUG_FEATURE_HW_LIGHTING        = 0x0010,
+        RENDER_DEBUG_FEATURE_FLEXIBLE           = 0x0010,
+        RENDER_DEBUG_FEATURE_FOG                = 0x0020,
+        RENDER_DEBUG_FEATURE_FR_INFO            = 0x0080,
+        RENDER_DEBUG_FEATURE_FOOT_SHADOWS       = 0x0100,
+    };
+
+    enum LLRenderDebugMask: U64
+    {
+        RENDER_DEBUG_COMPOSITION        =  0x00000001,
+        RENDER_DEBUG_VERIFY             =  0x00000002,
+        RENDER_DEBUG_BBOXES             =  0x00000004,
+        RENDER_DEBUG_OCTREE             =  0x00000008,
+        RENDER_DEBUG_WIND_VECTORS       =  0x00000010,
+        RENDER_DEBUG_OCCLUSION          =  0x00000020,
+        RENDER_DEBUG_POINTS             =  0x00000040,
+        RENDER_DEBUG_TEXTURE_PRIORITY   =  0x00000080,
+        RENDER_DEBUG_TEXTURE_AREA       =  0x00000100,
+        RENDER_DEBUG_FACE_AREA          =  0x00000200,
+        RENDER_DEBUG_PARTICLES          =  0x00000400,
+        RENDER_DEBUG_GLOW               =  0x00000800, // not used
+        RENDER_DEBUG_TEXTURE_ANIM       =  0x00001000,
+        RENDER_DEBUG_LIGHTS             =  0x00002000,
+        RENDER_DEBUG_BATCH_SIZE         =  0x00004000,
+        RENDER_DEBUG_ALPHA_BINS         =  0x00008000, // not used
+        RENDER_DEBUG_RAYCAST            =  0x00010000,
+        RENDER_DEBUG_AVATAR_DRAW_INFO   =  0x00020000,
+        RENDER_DEBUG_SHADOW_FRUSTA      =  0x00040000,
+        RENDER_DEBUG_SCULPTED           =  0x00080000,
+        RENDER_DEBUG_AVATAR_VOLUME      =  0x00100000,
+        RENDER_DEBUG_AVATAR_JOINTS      =  0x00200000,
+        RENDER_DEBUG_AGENT_TARGET       =  0x00800000,
+        RENDER_DEBUG_UPDATE_TYPE        =  0x01000000,
+        RENDER_DEBUG_PHYSICS_SHAPES     =  0x02000000,
+        RENDER_DEBUG_NORMALS            =  0x04000000,
+        RENDER_DEBUG_LOD_INFO           =  0x08000000,
         RENDER_DEBUG_NODES              =  0x20000000,
-		RENDER_DEBUG_TEXEL_DENSITY		=  0x40000000,
-		RENDER_DEBUG_TRIANGLE_COUNT		=  0x80000000,
-		RENDER_DEBUG_IMPOSTORS			= 0x100000000,
+        RENDER_DEBUG_TEXEL_DENSITY      =  0x40000000,
+        RENDER_DEBUG_TRIANGLE_COUNT     =  0x80000000,
+        RENDER_DEBUG_IMPOSTORS          = 0x100000000,
         RENDER_DEBUG_REFLECTION_PROBES  = 0x200000000,
         RENDER_DEBUG_PROBE_UPDATES      = 0x400000000,
-	};
+    };
 
 public:
-	
-	LLSpatialPartition* getSpatialPartition(LLViewerObject* vobj);
-
-	void updateCamera(bool reset = false);
-	
-	LLVector3				mFlyCamPosition;
-	LLQuaternion			mFlyCamRotation;
-
-	bool					 mBackfaceCull;
-	S32						 mMatrixOpCount;
-	S32						 mTextureMatrixOps;
-	S32						 mNumVisibleNodes;
-
-	S32						 mDebugTextureUploadCost;
-	S32						 mDebugSculptUploadCost;
-	S32						 mDebugMeshUploadCost;
-
-	S32						mPoissonOffset;
-
-	static bool				sShowHUDAttachments;
-	static bool				sForceOldBakedUpload; // If true will not use capabilities to upload baked textures.
-	static S32				sUseOcclusion;  // 0 = no occlusion, 1 = read only, 2 = read/write
-	static bool				sAutoMaskAlphaDeferred;
-	static bool				sAutoMaskAlphaNonDeferred;
-	static bool				sRenderTransparentWater;
-	static bool				sBakeSunlight;
-	static bool				sNoAlpha;
-	static bool				sUseFarClip;
-	static bool				sShadowRender;
-	static bool				sDynamicLOD;
-	static bool				sPickAvatar;
-	static bool				sReflectionRender;
-    static bool				sDistortionRender;
-	static bool				sImpostorRender;
-	static bool				sImpostorRenderAlphaDepthPass;
-	static bool				sUnderWaterRender;
-	static bool				sRenderGlow;
-	static bool				sTextureBindTest;
-	static bool				sRenderAttachedLights;
-	static bool				sRenderAttachedParticles;
-	static bool				sRenderDeferred;
-    static bool				sReflectionProbesEnabled;
-	static S32				sVisibleLightCount;
-	static bool				sRenderingHUDs;
+
+    LLSpatialPartition* getSpatialPartition(LLViewerObject* vobj);
+
+    void updateCamera(bool reset = false);
+
+    LLVector3               mFlyCamPosition;
+    LLQuaternion            mFlyCamRotation;
+
+    bool                     mBackfaceCull;
+    S32                      mMatrixOpCount;
+    S32                      mTextureMatrixOps;
+    S32                      mNumVisibleNodes;
+
+    S32                      mDebugTextureUploadCost;
+    S32                      mDebugSculptUploadCost;
+    S32                      mDebugMeshUploadCost;
+
+    S32                     mPoissonOffset;
+
+    static bool             sShowHUDAttachments;
+    static bool             sForceOldBakedUpload; // If true will not use capabilities to upload baked textures.
+    static S32              sUseOcclusion;  // 0 = no occlusion, 1 = read only, 2 = read/write
+    static bool             sAutoMaskAlphaDeferred;
+    static bool             sAutoMaskAlphaNonDeferred;
+    static bool             sRenderTransparentWater;
+    static bool             sBakeSunlight;
+    static bool             sNoAlpha;
+    static bool             sUseFarClip;
+    static bool             sShadowRender;
+    static bool             sDynamicLOD;
+    static bool             sPickAvatar;
+    static bool             sReflectionRender;
+    static bool             sDistortionRender;
+    static bool             sImpostorRender;
+    static bool             sImpostorRenderAlphaDepthPass;
+    static bool             sUnderWaterRender;
+    static bool             sRenderGlow;
+    static bool             sTextureBindTest;
+    static bool             sRenderAttachedLights;
+    static bool             sRenderAttachedParticles;
+    static bool             sRenderDeferred;
+    static bool             sReflectionProbesEnabled;
+    static S32              sVisibleLightCount;
+    static bool             sRenderingHUDs;
     static F32              sDistortionWaterClipPlaneMargin;
 // [SL:KB] - Patch: Render-TextureToggle (Catznip-4.0)
-	static bool				sRenderTextures;
+    static bool             sRenderTextures;
 // [/SL:KB]
 // [RLVa:KB] - @setsphere
-	static bool				sUseDepthTexture;
+    static bool             sUseDepthTexture;
 // [/RLVa:KB]
 
-	static LLTrace::EventStatHandle<S64> sStatBatchSize;
+    static LLTrace::EventStatHandle<S64> sStatBatchSize;
 
-	std::unique_ptr<ALRenderUtil> mALRenderUtil;
+    std::unique_ptr<ALRenderUtil> mALRenderUtil;
 
     class RenderTargetPack
     {
     public:
-        U32 					width = 0;
-        U32 					height = 0;
+        U32                     width = 0;
+        U32                     height = 0;
 
         //screen texture
-        LLRenderTarget			screen;
-        LLRenderTarget			uiScreen;
-        LLRenderTarget			deferredScreen;
-        LLRenderTarget			deferredLight;
+        LLRenderTarget          screen;
+        LLRenderTarget          uiScreen;
+        LLRenderTarget          deferredScreen;
+        LLRenderTarget          deferredLight;
 
         //sun shadow map
-        LLRenderTarget			shadow[4];
+        LLRenderTarget          shadow[4];
     };
 
     // main full resoltuion render target
@@ -684,7 +684,7 @@ class LLPipeline
     // used by reflection probes and dynamic texture bakes
     RenderTargetPack mAuxillaryRT;
 
-	// Auxillary render target pack scaled to the hero probe's per-face size.
+    // Auxillary render target pack scaled to the hero probe's per-face size.
     RenderTargetPack mHeroProbeRT;
 
     // currently used render target pack
@@ -705,356 +705,356 @@ class LLPipeline
 
     // tonemapped and gamma corrected render ready for post
     LLRenderTarget          mPostMap;
-	LLRenderTarget          mPostFXMap;
-	 LLRenderTarget			mPostHelperMap;
+    LLRenderTarget          mPostFXMap;
+     LLRenderTarget         mPostHelperMap;
 
     LLCullResult            mSky;
     LLCullResult            mReflectedObjects;
     LLCullResult            mRefractedObjects;
 
-	//utility buffers for rendering post effects
-	LLPointer<LLVertexBuffer> mDeferredVB;
+    //utility buffers for rendering post effects
+    LLPointer<LLVertexBuffer> mDeferredVB;
 
     // a single triangle that covers the whole screen
     LLPointer<LLVertexBuffer> mScreenTriangleVB;
 
-	//utility buffer for rendering cubes, 8 vertices are corners of a cube [-1, 1]
-	LLPointer<LLVertexBuffer> mCubeVB;
+    //utility buffer for rendering cubes, 8 vertices are corners of a cube [-1, 1]
+    LLPointer<LLVertexBuffer> mCubeVB;
 
     //list of currently bound reflection maps
     std::vector<LLReflectionMap*> mReflectionMaps;
 
-	std::vector<LLVector3>	mShadowFrustPoints[4];
-	LLVector4				mShadowError;
-	LLVector4				mShadowFOV;
-	LLVector3				mShadowFrustOrigin[4];
-	LLCamera				mShadowCamera[8];
-	LLVector3				mShadowExtents[4][2];
+    std::vector<LLVector3>  mShadowFrustPoints[4];
+    LLVector4               mShadowError;
+    LLVector4               mShadowFOV;
+    LLVector3               mShadowFrustOrigin[4];
+    LLCamera                mShadowCamera[8];
+    LLVector3               mShadowExtents[4][2];
     // TODO : separate Sun Shadow and Spot Shadow matrices
-	glh::matrix4f			mSunShadowMatrix[6];
-	glh::matrix4f			mShadowModelview[6];
-	glh::matrix4f			mShadowProjection[6];
+    glh::matrix4f           mSunShadowMatrix[6];
+    glh::matrix4f           mShadowModelview[6];
+    glh::matrix4f           mShadowProjection[6];
     glh::matrix4f           mReflectionModelView;
 
-	LLPointer<LLDrawable>	mShadowSpotLight[2];
-	F32						mSpotLightFade[2];
-	LLPointer<LLDrawable>	mTargetShadowSpotLight[2];
+    LLPointer<LLDrawable>   mShadowSpotLight[2];
+    F32                     mSpotLightFade[2];
+    LLPointer<LLDrawable>   mTargetShadowSpotLight[2];
 
-	LLVector4				mSunClipPlanes;
-	LLVector4				mSunOrthoClipPlanes;
-	LLVector2				mScreenScale;
+    LLVector4               mSunClipPlanes;
+    LLVector4               mSunOrthoClipPlanes;
+    LLVector2               mScreenScale;
 
-	//water distortion texture (refraction)
-	LLRenderTarget				mWaterDis;
+    //water distortion texture (refraction)
+    LLRenderTarget              mWaterDis;
 
     static const U32 MAX_BAKE_WIDTH;
-	LLRenderTarget				mBake;
-
-	//texture for making the glow
-	LLRenderTarget				mGlow[3];
-
-	//noise map
-	U32					mNoiseMap;
-	U32					mTrueNoiseMap;
-	U32					mLightFunc;
-    U32					mAreaMap;
-    U32					mSearchMap;
-    U32					mSampleMap;
+    LLRenderTarget              mBake;
+
+    //texture for making the glow
+    LLRenderTarget              mGlow[3];
+
+    //noise map
+    U32                 mNoiseMap;
+    U32                 mTrueNoiseMap;
+    U32                 mLightFunc;
+    U32                 mAreaMap;
+    U32                 mSearchMap;
+    U32                 mSampleMap;
     U32                 mStencilMap;
 
-	LLColor4			mSunDiffuse;
-    LLColor4			mMoonDiffuse;
-	LLVector4			mSunDir;
-    LLVector4			mMoonDir;
+    LLColor4            mSunDiffuse;
+    LLColor4            mMoonDiffuse;
+    LLVector4           mSunDir;
+    LLVector4           mMoonDir;
     bool                mNeedsShadowTargetClear;
 
-	LLVector4a			mTransformedSunDir;
-    LLVector4a			mTransformedMoonDir;
+    LLVector4a          mTransformedSunDir;
+    LLVector4a          mTransformedMoonDir;
 
-	bool					mInitialized;
-	bool					mShadersLoaded;
+    bool                    mInitialized;
+    bool                    mShadersLoaded;
 
-	U32						mTransformFeedbackPrimitives; //number of primitives expected to be generated by transform feedback
+    U32                     mTransformFeedbackPrimitives; //number of primitives expected to be generated by transform feedback
 protected:
-	bool					mRenderTypeEnabled[NUM_RENDER_TYPES];
-	std::stack<std::string> mRenderTypeEnableStack;
-
-	U32						mRenderDebugFeatureMask;
-	U64						mRenderDebugMask;
-	U64						mOldRenderDebugMask;
-	std::stack<U32>			mRenderDebugFeatureStack;
-
-	/////////////////////////////////////////////
-	//
-	//
-	LLDrawable::drawable_vector_t	mMovedList;
-	LLDrawable::drawable_vector_t mMovedBridge;
-	LLDrawable::drawable_vector_t	mShiftList;
-
-	/////////////////////////////////////////////
-	//
-	//
-	struct Light
-	{
-		Light(LLDrawable* ptr, F32 d, F32 f = 0.0f)
-			: drawable(ptr),
-			  dist(d),
-			  fade(f)
-		{}
-		LLPointer<LLDrawable> drawable;
-		F32 dist;
-		F32 fade;
-		struct compare
-		{
-			bool operator()(const Light& a, const Light& b) const
-			{
-				if ( a.dist < b.dist )
-					return true;
-				else if ( a.dist > b.dist )
-					return false;
-				else
-					return a.drawable < b.drawable;
-			}
-		};
-	};
-	typedef std::set< Light, Light::compare > light_set_t;
-	
-	LLDrawable::ordered_drawable_set_t	mLights;
-	light_set_t						mNearbyLights; // lights near camera
-	LLColor4						mHWLightColors[8];
-	
-	/////////////////////////////////////////////
-	//
-	// Different queues of drawables being processed.
-	//
-	LLDrawable::drawable_list_t 	mBuildQ1; // priority
-	LLSpatialGroup::sg_vector_t		mGroupQ1; //priority
-
-	LLSpatialGroup::sg_vector_t		mGroupSaveQ1; // a place to save mGroupQ1 until it is safe to unref
-
-	LLSpatialGroup::sg_vector_t		mMeshDirtyGroup; //groups that need rebuildMesh called
-	U32 mMeshDirtyQueryObject;
-
-	LLDrawable::drawable_vector_t	mPartitionQ; //drawables that need to update their spatial partition radius 
-
-	bool mGroupQ1Locked;
-
-	bool mResetVertexBuffers; //if true, clear vertex buffers on next update
-
-	LLViewerObject::vobj_list_t		mCreateQ;
-		
-	LLDrawable::drawable_set_t		mRetexturedList;
-
-	class HighlightItem
-	{
-	public:
-		const LLPointer<LLDrawable> mItem;
-		mutable F32 mFade;
-
-		HighlightItem(LLDrawable* item)
-		: mItem(item), mFade(0)
-		{
-		}
-
-		bool operator<(const HighlightItem& rhs) const
-		{
-			return mItem < rhs.mItem;
-		}
-
-		bool operator==(const HighlightItem& rhs) const
-		{
-			return mItem == rhs.mItem;
-		}
-
-		void incrFade(F32 val) const
-		{
-			mFade = llclamp(mFade+val, 0.f, 1.f);
-		}
-	};
-
-	//////////////////////////////////////////////////
-	//
-	// Draw pools are responsible for storing all rendered data,
-	// and performing the actual rendering of objects.
-	//
-	struct compare_pools
-	{
-		bool operator()(const LLDrawPool* a, const LLDrawPool* b) const
-		{
-			if (!a)
-				return true;
-			else if (!b)
-				return false;
-			else
-			{
-				S32 atype = a->getType();
-				S32 btype = b->getType();
-				if (atype < btype)
-					return true;
-				else if (atype > btype)
-					return false;
-				else
-					return a->getId() < b->getId();
-			}
-		}
-	};
- 	typedef std::set<LLDrawPool*, compare_pools > pool_set_t;
-	pool_set_t mPools;
-	LLDrawPool*	mLastRebuildPool;
-	
-	// For quick-lookups into mPools (mapped by texture pointer)
-	std::map<uintptr_t, LLDrawPool*>	mTerrainPools;
-	std::map<uintptr_t, LLDrawPool*>	mTreePools;
-	LLDrawPoolAlpha*			mAlphaPoolPreWater = nullptr;
+    bool                    mRenderTypeEnabled[NUM_RENDER_TYPES];
+    std::stack<std::string> mRenderTypeEnableStack;
+
+    U32                     mRenderDebugFeatureMask;
+    U64                     mRenderDebugMask;
+    U64                     mOldRenderDebugMask;
+    std::stack<U32>         mRenderDebugFeatureStack;
+
+    /////////////////////////////////////////////
+    //
+    //
+    LLDrawable::drawable_vector_t   mMovedList;
+    LLDrawable::drawable_vector_t mMovedBridge;
+    LLDrawable::drawable_vector_t   mShiftList;
+
+    /////////////////////////////////////////////
+    //
+    //
+    struct Light
+    {
+        Light(LLDrawable* ptr, F32 d, F32 f = 0.0f)
+            : drawable(ptr),
+              dist(d),
+              fade(f)
+        {}
+        LLPointer<LLDrawable> drawable;
+        F32 dist;
+        F32 fade;
+        struct compare
+        {
+            bool operator()(const Light& a, const Light& b) const
+            {
+                if ( a.dist < b.dist )
+                    return true;
+                else if ( a.dist > b.dist )
+                    return false;
+                else
+                    return a.drawable < b.drawable;
+            }
+        };
+    };
+    typedef std::set< Light, Light::compare > light_set_t;
+
+    LLDrawable::ordered_drawable_set_t  mLights;
+    light_set_t                     mNearbyLights; // lights near camera
+    LLColor4                        mHWLightColors[8];
+
+    /////////////////////////////////////////////
+    //
+    // Different queues of drawables being processed.
+    //
+    LLDrawable::drawable_list_t     mBuildQ1; // priority
+    LLSpatialGroup::sg_vector_t     mGroupQ1; //priority
+
+    LLSpatialGroup::sg_vector_t     mGroupSaveQ1; // a place to save mGroupQ1 until it is safe to unref
+
+    LLSpatialGroup::sg_vector_t     mMeshDirtyGroup; //groups that need rebuildMesh called
+    U32 mMeshDirtyQueryObject;
+
+    LLDrawable::drawable_vector_t   mPartitionQ; //drawables that need to update their spatial partition radius
+
+    bool mGroupQ1Locked;
+
+    bool mResetVertexBuffers; //if true, clear vertex buffers on next update
+
+    LLViewerObject::vobj_list_t     mCreateQ;
+
+    LLDrawable::drawable_set_t      mRetexturedList;
+
+    class HighlightItem
+    {
+    public:
+        const LLPointer<LLDrawable> mItem;
+        mutable F32 mFade;
+
+        HighlightItem(LLDrawable* item)
+        : mItem(item), mFade(0)
+        {
+        }
+
+        bool operator<(const HighlightItem& rhs) const
+        {
+            return mItem < rhs.mItem;
+        }
+
+        bool operator==(const HighlightItem& rhs) const
+        {
+            return mItem == rhs.mItem;
+        }
+
+        void incrFade(F32 val) const
+        {
+            mFade = llclamp(mFade+val, 0.f, 1.f);
+        }
+    };
+
+    //////////////////////////////////////////////////
+    //
+    // Draw pools are responsible for storing all rendered data,
+    // and performing the actual rendering of objects.
+    //
+    struct compare_pools
+    {
+        bool operator()(const LLDrawPool* a, const LLDrawPool* b) const
+        {
+            if (!a)
+                return true;
+            else if (!b)
+                return false;
+            else
+            {
+                S32 atype = a->getType();
+                S32 btype = b->getType();
+                if (atype < btype)
+                    return true;
+                else if (atype > btype)
+                    return false;
+                else
+                    return a->getId() < b->getId();
+            }
+        }
+    };
+    typedef std::set<LLDrawPool*, compare_pools > pool_set_t;
+    pool_set_t mPools;
+    LLDrawPool* mLastRebuildPool;
+
+    // For quick-lookups into mPools (mapped by texture pointer)
+    std::map<uintptr_t, LLDrawPool*>    mTerrainPools;
+    std::map<uintptr_t, LLDrawPool*>    mTreePools;
+    LLDrawPoolAlpha*            mAlphaPoolPreWater = nullptr;
     LLDrawPoolAlpha*            mAlphaPoolPostWater = nullptr;
-	LLDrawPool*					mSkyPool = nullptr;
-	LLDrawPool*					mTerrainPool = nullptr;
-	LLDrawPool*					mWaterPool = nullptr;
-	LLRenderPass*				mSimplePool = nullptr;
-	LLRenderPass*				mGrassPool = nullptr;
-	LLRenderPass*				mAlphaMaskPool = nullptr;
-	LLRenderPass*				mFullbrightAlphaMaskPool = nullptr;
-	LLRenderPass*				mFullbrightPool = nullptr;
-	LLDrawPool*					mGlowPool = nullptr;
-	LLDrawPool*					mBumpPool = nullptr;
-	LLDrawPool*					mMaterialsPool = nullptr;
-	LLDrawPool*					mWLSkyPool = nullptr;
-	LLDrawPool*					mPBROpaquePool = nullptr;
+    LLDrawPool*                 mSkyPool = nullptr;
+    LLDrawPool*                 mTerrainPool = nullptr;
+    LLDrawPool*                 mWaterPool = nullptr;
+    LLRenderPass*               mSimplePool = nullptr;
+    LLRenderPass*               mGrassPool = nullptr;
+    LLRenderPass*               mAlphaMaskPool = nullptr;
+    LLRenderPass*               mFullbrightAlphaMaskPool = nullptr;
+    LLRenderPass*               mFullbrightPool = nullptr;
+    LLDrawPool*                 mGlowPool = nullptr;
+    LLDrawPool*                 mBumpPool = nullptr;
+    LLDrawPool*                 mMaterialsPool = nullptr;
+    LLDrawPool*                 mWLSkyPool = nullptr;
+    LLDrawPool*                 mPBROpaquePool = nullptr;
     LLDrawPool*                 mPBRAlphaMaskPool = nullptr;
 
-	// Note: no need to keep an quick-lookup to avatar pools, since there's only one per avatar
-	
+    // Note: no need to keep an quick-lookup to avatar pools, since there's only one per avatar
+
 public:
-	std::vector<LLFace*>		mHighlightFaces;	// highlight faces on physical objects
+    std::vector<LLFace*>        mHighlightFaces;    // highlight faces on physical objects
 protected:
-	std::vector<LLFace*>		mSelectedFaces;
-
-	class DebugBlip
-	{
-	public:
-		LLColor4 mColor;
-		LLVector3 mPosition;
-		F32 mAge;
-
-		DebugBlip(const LLVector3& position, const LLColor4& color)
-			: mColor(color), mPosition(position), mAge(0.f)
-		{ }
-	};
-
-	std::list<DebugBlip> mDebugBlips;
-
-	LLPointer<LLViewerFetchedTexture>	mFaceSelectImagep;
-	
-	U32						mLightMask;
-	U32						mLightMovingMask;
-		
-	static bool				sRenderPhysicalBeacons;
-	static bool				sRenderMOAPBeacons;
-	static bool				sRenderScriptedTouchBeacons;
-	static bool				sRenderScriptedBeacons;
-	static bool				sRenderParticleBeacons;
-	static bool				sRenderSoundBeacons;
+    std::vector<LLFace*>        mSelectedFaces;
+
+    class DebugBlip
+    {
+    public:
+        LLColor4 mColor;
+        LLVector3 mPosition;
+        F32 mAge;
+
+        DebugBlip(const LLVector3& position, const LLColor4& color)
+            : mColor(color), mPosition(position), mAge(0.f)
+        { }
+    };
+
+    std::list<DebugBlip> mDebugBlips;
+
+    LLPointer<LLViewerFetchedTexture>   mFaceSelectImagep;
+
+    U32                     mLightMask;
+    U32                     mLightMovingMask;
+
+    static bool             sRenderPhysicalBeacons;
+    static bool             sRenderMOAPBeacons;
+    static bool             sRenderScriptedTouchBeacons;
+    static bool             sRenderScriptedBeacons;
+    static bool             sRenderParticleBeacons;
+    static bool             sRenderSoundBeacons;
 public:
-	static bool				sRenderBeacons;
-	static bool				sRenderHighlight;
-
-	// Determines which set of UVs to use in highlight display
-	//
-	static LLRender::eTexIndex sRenderHighlightTextureChannel;
-
-	//debug use
-	static U32              sCurRenderPoolType ;
-
-	//cached settings
-	static bool WindLightUseAtmosShaders;
-	static bool RenderDeferred;
-	static F32 RenderDeferredSunWash;
-	static U32 RenderFSAASamples;
-	static U32 RenderResolutionDivisor;
+    static bool             sRenderBeacons;
+    static bool             sRenderHighlight;
+
+    // Determines which set of UVs to use in highlight display
+    //
+    static LLRender::eTexIndex sRenderHighlightTextureChannel;
+
+    //debug use
+    static U32              sCurRenderPoolType ;
+
+    //cached settings
+    static bool WindLightUseAtmosShaders;
+    static bool RenderDeferred;
+    static F32 RenderDeferredSunWash;
+    static U32 RenderFSAASamples;
+    static U32 RenderResolutionDivisor;
 // [SL:KB] - Patch: Settings-RenderResolutionMultiplier | Checked: Catznip-5.4
-	static F32 RenderResolutionMultiplier;
+    static F32 RenderResolutionMultiplier;
 // [/SL:KB]
-	static bool RenderUIBuffer;
-	static S32 RenderShadowDetail;
+    static bool RenderUIBuffer;
+    static S32 RenderShadowDetail;
     static S32 RenderShadowSplits;
-	static bool RenderDeferredSSAO;
-	static F32 RenderShadowResolutionScale;
-	static bool RenderDelayCreation;
-	static bool RenderAnimateRes;
-	static bool FreezeTime;
-	static S32 DebugBeaconLineWidth;
-	static F32 RenderHighlightBrightness;
-	static LLColor4 RenderHighlightColor;
-	static F32 RenderHighlightThickness;
-	static bool RenderSpotLightsInNondeferred;
-	static LLColor4 PreviewAmbientColor;
-	static LLColor4 PreviewDiffuse0;
-	static LLColor4 PreviewSpecular0;
-	static LLColor4 PreviewDiffuse1;
-	static LLColor4 PreviewSpecular1;
-	static LLColor4 PreviewDiffuse2;
-	static LLColor4 PreviewSpecular2;
-	static LLVector3 PreviewDirection0;
-	static LLVector3 PreviewDirection1;
-	static LLVector3 PreviewDirection2;
-	static F32 RenderGlowMinLuminance;
-	static F32 RenderGlowMaxExtractAlpha;
-	static F32 RenderGlowWarmthAmount;
-	static LLVector3 RenderGlowLumWeights;
-	static LLVector3 RenderGlowWarmthWeights;
-	static S32 RenderGlowResolutionPow;
-	static S32 RenderGlowIterations;
-	static F32 RenderGlowWidth;
-	static F32 RenderGlowStrength;
-	static bool RenderGlowNoise;
-	static bool RenderDepthOfField;
-	static bool RenderDepthOfFieldInEditMode;
-	static bool RenderDepthOfFieldNearBlur;
-	static bool RenderFocusPointLocked;
-	static bool RenderFocusPointFollowsPointer;
-	static F32 CameraFocusTransitionTime;
-	static F32 CameraFNumber;
-	static F32 CameraFocalLength;
-	static F32 CameraFieldOfView;
-	static F32 RenderShadowNoise;
-	static F32 RenderShadowBlurSize;
-	static F32 RenderSSAOScale;
-	static U32 RenderSSAOMaxScale;
-	static F32 RenderSSAOFactor;
-	static LLVector3 RenderSSAOEffect;
-	static F32 RenderShadowOffsetError;
-	static F32 RenderShadowBiasError;
-	static F32 RenderShadowOffset;
-	static F32 RenderShadowBias;
-	static F32 RenderSpotShadowOffset;
-	static F32 RenderSpotShadowBias;
+    static bool RenderDeferredSSAO;
+    static F32 RenderShadowResolutionScale;
+    static bool RenderDelayCreation;
+    static bool RenderAnimateRes;
+    static bool FreezeTime;
+    static S32 DebugBeaconLineWidth;
+    static F32 RenderHighlightBrightness;
+    static LLColor4 RenderHighlightColor;
+    static F32 RenderHighlightThickness;
+    static bool RenderSpotLightsInNondeferred;
+    static LLColor4 PreviewAmbientColor;
+    static LLColor4 PreviewDiffuse0;
+    static LLColor4 PreviewSpecular0;
+    static LLColor4 PreviewDiffuse1;
+    static LLColor4 PreviewSpecular1;
+    static LLColor4 PreviewDiffuse2;
+    static LLColor4 PreviewSpecular2;
+    static LLVector3 PreviewDirection0;
+    static LLVector3 PreviewDirection1;
+    static LLVector3 PreviewDirection2;
+    static F32 RenderGlowMinLuminance;
+    static F32 RenderGlowMaxExtractAlpha;
+    static F32 RenderGlowWarmthAmount;
+    static LLVector3 RenderGlowLumWeights;
+    static LLVector3 RenderGlowWarmthWeights;
+    static S32 RenderGlowResolutionPow;
+    static S32 RenderGlowIterations;
+    static F32 RenderGlowWidth;
+    static F32 RenderGlowStrength;
+    static bool RenderGlowNoise;
+    static bool RenderDepthOfField;
+    static bool RenderDepthOfFieldInEditMode;
+    static bool RenderDepthOfFieldNearBlur;
+    static bool RenderFocusPointLocked;
+    static bool RenderFocusPointFollowsPointer;
+    static F32 CameraFocusTransitionTime;
+    static F32 CameraFNumber;
+    static F32 CameraFocalLength;
+    static F32 CameraFieldOfView;
+    static F32 RenderShadowNoise;
+    static F32 RenderShadowBlurSize;
+    static F32 RenderSSAOScale;
+    static U32 RenderSSAOMaxScale;
+    static F32 RenderSSAOFactor;
+    static LLVector3 RenderSSAOEffect;
+    static F32 RenderShadowOffsetError;
+    static F32 RenderShadowBiasError;
+    static F32 RenderShadowOffset;
+    static F32 RenderShadowBias;
+    static F32 RenderSpotShadowOffset;
+    static F32 RenderSpotShadowBias;
     static LLDrawable* RenderSpotLight;
-	static F32 RenderEdgeDepthCutoff;
-	static F32 RenderEdgeNormCutoff;
-	static LLVector3 RenderShadowGaussian;
-	static F32 RenderShadowBlurDistFactor;
-	static bool RenderDeferredAtmospheric;
-	static F32 RenderHighlightFadeTime;
-	static F32 RenderFarClip;
-	static LLVector3 RenderShadowSplitExponent;
-	static F32 RenderShadowErrorCutoff;
-	static F32 RenderShadowFOVCutoff;
-	static bool CameraOffset;
-	static F32 CameraMaxCoF;
-	static F32 CameraDoFResScale;
-	static F32 RenderAutoHideSurfaceAreaLimit;
-	static bool RenderScreenSpaceReflections;
+    static F32 RenderEdgeDepthCutoff;
+    static F32 RenderEdgeNormCutoff;
+    static LLVector3 RenderShadowGaussian;
+    static F32 RenderShadowBlurDistFactor;
+    static bool RenderDeferredAtmospheric;
+    static F32 RenderHighlightFadeTime;
+    static F32 RenderFarClip;
+    static LLVector3 RenderShadowSplitExponent;
+    static F32 RenderShadowErrorCutoff;
+    static F32 RenderShadowFOVCutoff;
+    static bool CameraOffset;
+    static F32 CameraMaxCoF;
+    static F32 CameraDoFResScale;
+    static F32 RenderAutoHideSurfaceAreaLimit;
+    static bool RenderScreenSpaceReflections;
     static S32 RenderScreenSpaceReflectionIterations;
-	static F32 RenderScreenSpaceReflectionRayStep;
-	static F32 RenderScreenSpaceReflectionDistanceBias;
-	static F32 RenderScreenSpaceReflectionDepthRejectBias;
-	static F32 RenderScreenSpaceReflectionAdaptiveStepMultiplier;
-	static S32 RenderScreenSpaceReflectionGlossySamples;
-	static S32 RenderBufferVisualization;
-	static bool RenderMirrors;
-	static S32 RenderHeroProbeUpdateRate;
+    static F32 RenderScreenSpaceReflectionRayStep;
+    static F32 RenderScreenSpaceReflectionDistanceBias;
+    static F32 RenderScreenSpaceReflectionDepthRejectBias;
+    static F32 RenderScreenSpaceReflectionAdaptiveStepMultiplier;
+    static S32 RenderScreenSpaceReflectionGlossySamples;
+    static S32 RenderBufferVisualization;
+    static bool RenderMirrors;
+    static S32 RenderHeroProbeUpdateRate;
     static S32 RenderHeroProbeConservativeUpdateMultiplier;
-	static F32 RenderNormalMapScale;
+    static F32 RenderNormalMapScale;
 };
 
 void render_bbox(const LLVector3 &min, const LLVector3 &max);